diff --git a/.gitignore b/.gitignore index c9a2d35..e920e17 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,4 @@ out??? *.out tags TAGS -markdown \ No newline at end of file +markdown diff --git a/.helix/ignore b/.helix/ignore deleted file mode 100644 index ed43ad4..0000000 --- a/.helix/ignore +++ /dev/null @@ -1,10 +0,0 @@ -00/* -01/* -02/* -03/* -04/* -04a -# 05/musl* -05/tcc-0* -05/musl-0* - diff --git a/00/Makefile b/00/Makefile index 3dd4a18..b882d3e 100644 --- a/00/Makefile +++ b/00/Makefile @@ -1,4 +1,4 @@ -all: out00 +all: README.html out00 out00: in00 ./hexcompile %.html: %.md ../markdown diff --git a/01/Makefile b/01/Makefile index 585706d..f40b401 100644 --- a/01/Makefile +++ b/01/Makefile @@ -1,7 +1,9 @@ -all: out01 +all: out01 README.html out01: in01 out00 ./out00 out00: in00 ../00/hexcompile +%.html: %.md ../markdown + ../markdown $< clean: - rm -f out00 out01 + rm -f out00 out01 README.html diff --git a/02/Makefile b/02/Makefile index 8e9a823..17b0b0e 100644 --- a/02/Makefile +++ b/02/Makefile @@ -1,7 +1,9 @@ -all: out01 out02 +all: out01 out02 README.html out01: in01 ../01/out00 out02: out01 in02 ./out01 +%.html: %.md ../markdown + ../markdown $< clean: - rm -f out01 out02 + rm -f out01 out02 README.html diff --git a/03/Makefile b/03/Makefile index 5443e6e..2a50640 100644 --- a/03/Makefile +++ b/03/Makefile @@ -1,7 +1,9 @@ -all: out02 out03 +all: out02 out03 README.html out02: in02 ../02/out01 ../02/out01 out03: out02 in03 ./out02 +%.html: %.md ../markdown + ../markdown $< clean: - rm -f out* + rm -f out* README.html diff --git a/04/Makefile b/04/Makefile index 28e2dc8..ae9568c 100644 --- a/04/Makefile +++ b/04/Makefile @@ -1,9 +1,11 @@ -all: out03 guessing_game.out out04 +all: out03 guessing_game.out out04 README.html out03: in03 ../03/out02 ../03/out02 +%.html: %.md ../markdown + ../markdown $< out04: in04 out03 ./out03 %.out: % out03 ./out03 $< $@ clean: - rm -f out* *.out + rm -f out* README.html *.out diff --git a/04a/Makefile b/04a/Makefile index b8df194..f88d708 100644 --- a/04a/Makefile +++ b/04a/Makefile @@ -1,7 +1,9 @@ -all: out04 out04a +all: out04 out04a README.html out04: in04 ../04/out03 ../04/out03 out04a: in04a out04 ./out04 +%.html: %.md ../markdown + ../markdown $< clean: - rm -f out* + rm -f out* README.html diff --git a/05/.gitignore b/05/.gitignore index 317ef82..022bae2 100644 --- a/05/.gitignore +++ b/05/.gitignore @@ -4,4 +4,3 @@ address_map.txt *.d tcc-bootstrap musl-bootstrap -musl-bootstrap-final diff --git a/05/Makefile b/05/Makefile index 0b31d5e..74765e1 100644 --- a/05/Makefile +++ b/05/Makefile @@ -2,7 +2,7 @@ TCCDIR=tcc-0.9.27 TCC=$(TCCDIR)/tcc TCC0=$(TCC)0 TCCINST=tcc-bootstrap -all: testapp +all: out04 a.out $(TCCDIR)/lib/libtcc1.a in04: *.b ../04a/out04 ../04a/out04 main.b in04 out04: in04 ../04/out03 @@ -13,6 +13,12 @@ out04: in04 ../04/out03 ./out04 $< $@ a.out: main.c *.h out04 ./out04 +test.out: test.s.o test.c.o + $(TCC0) -static -nostdlib test.s.o test.c.o -o test.out +test.s.o: $(TCC0) test.s + $(TCC0) -static -nostdlib -c test.s -o test.s.o +test.c.o: $(TCC0) test.c + $(TCC0) -static -nostdlib -c test.c -o test.c.o $(TCC0): $(TCCDIR)/*.c $(TCCDIR)/*.h out04 cd $(TCCDIR) && ../out04 tcc.c tcc0 $(TCCDIR)/lib/libtcc1.a: $(TCC0) $(TCCDIR)/lib/*.[cS] @@ -22,9 +28,6 @@ $(TCCDIR)/lib/libtcc1.a: $(TCC0) $(TCCDIR)/lib/*.[cS] $(TCC0) -c $(TCCDIR)/lib/libtcc1.c -o $(TCCDIR)/lib/libtcc1.o $(TCC0) -ar $(TCCDIR)/lib/libtcc1.a $(TCCDIR)/lib/*.o musl: tcc-files - mkdir -p musl-bootstrap/include - mkdir -p musl-bootstrap/bin - mkdir -p musl-bootstrap/lib $(MAKE) -j8 -C musl-0.6.0 $(MAKE) -C musl-0.6.0 install tcc-files: $(TCCDIR)/lib/libtcc1.a $(TCCDIR)/include/*.h @@ -32,17 +35,8 @@ tcc-files: $(TCCDIR)/lib/libtcc1.a $(TCCDIR)/include/*.h cp -r $(TCCDIR)/include/*.h $(TCCINST)/include/ cp -r $(TCCDIR)/lib/libtcc1.a $(TCCINST)/ $(TCC): $(TCC0) musl - cd $(TCCDIR) && ./tcc0 -nostdinc -nostdlib -B ../tcc-bootstrap -I ../musl-bootstrap/include tcc.c ../musl-bootstrap/lib/*.[oa] -o tcc + cd $(TCCDIR) && ./tcc0 -nostdinc -nostdlib -B ../tcc-boostrap -I ../musl-bootstrap/include tcc.c ../musl-bootstrap/lib/*.[oa] -o tcc tcc: $(TCC) -musl-final: tcc - mkdir -p musl-bootstrap-final/include - mkdir -p musl-bootstrap-final/bin - mkdir -p musl-bootstrap-final/lib - $(MAKE) -C musl-final -tcc-final: tcc musl-final - cd tcc-final && ../$(TCCDIR)/tcc -Wall -g -static -nostdinc -nostdlib -B ../tcc-bootstrap -I ../musl-final/include tcc.c ../musl-final/lib/*.[oa] -o tcc -testapp: tcc musl-final - ./tcc-final/tcc -Wall -g -static -nostdinc -nostdlib -I ./tcc-final/include -I ./musl-final/include test.c ./musl-final/lib/*.[oa] -o test $(TCC)2: $(TCC)1 cd $(TCCDIR) && ./tcc1 tcc.c -o tcc2 @@ -51,9 +45,6 @@ $(TCC)0a: $(TCCDIR)/*.c $(TCCDIR)/*.h $(TCC)1a: $(TCCDIR)/*.c $(TCCDIR)/*.h cd $(TCCDIR) && ./tcc0a tcc.c -o tcc1a clean: - $(MAKE) -C musl-final clean - $(MAKE) -C musl-0.6.0 clean rm -rf musl-bootstrap - rm -rf musl-bootstrap-final rm -rf tcc-bootstrap - rm -f out* *.out *.o $(TCCDIR)/tcc[0123456] $(TCCDIR)/tcc[0123456]a $(TCCDIR)/lib/*.[oa] + rm -f out* README.html *.out *.o $(TCCDIR)/tcc[0123456] $(TCCDIR)/tcc[0123456]a $(TCCDIR)/lib/*.[oa] diff --git a/05/musl-0.6.0/config.mak b/05/musl-0.6.0/config.mak index 6c1acde..81b8052 100644 --- a/05/musl-0.6.0/config.mak +++ b/05/musl-0.6.0/config.mak @@ -14,7 +14,7 @@ exec_prefix = ../musl-bootstrap # Uncomment if you want to build i386 musl on a 64-bit host #CFLAGS += -m32 -CFLAGS += -g +#CFLAGS += -g # Uncomment for smaller code size. #CFLAGS += -fomit-frame-pointer -mno-accumulate-outgoing-args diff --git a/05/musl-final/.gitignore b/05/musl-final/.gitignore deleted file mode 100644 index 16b8a37..0000000 --- a/05/musl-final/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -*.o -*.a -musl-gcc diff --git a/05/musl-final/COPYING b/05/musl-final/COPYING deleted file mode 100644 index 223ede7..0000000 --- a/05/musl-final/COPYING +++ /dev/null @@ -1,504 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 2.1, February 1999 - - Copyright (C) 1991, 1999 Free Software Foundation, Inc. - 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -[This is the first released version of the Lesser GPL. It also counts - as the successor of the GNU Library Public License, version 2, hence - the version number 2.1.] - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Lesser General Public License, applies to some -specially designated software packages--typically libraries--of the -Free Software Foundation and other authors who decide to use it. You -can use it too, but we suggest you first think carefully about whether -this license or the ordinary General Public License is the better -strategy to use in any particular case, based on the explanations below. - - When we speak of free software, we are referring to freedom of use, -not price. Our General Public Licenses are designed to make sure that -you have the freedom to distribute copies of free software (and charge -for this service if you wish); that you receive source code or can get -it if you want it; that you can change the software and use pieces of -it in new free programs; and that you are informed that you can do -these things. - - To protect your rights, we need to make restrictions that forbid -distributors to deny you these rights or to ask you to surrender these -rights. These restrictions translate to certain responsibilities for -you if you distribute copies of the library or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link other code with the library, you must provide -complete object files to the recipients, so that they can relink them -with the library after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - We protect your rights with a two-step method: (1) we copyright the -library, and (2) we offer you this license, which gives you legal -permission to copy, distribute and/or modify the library. - - To protect each distributor, we want to make it very clear that -there is no warranty for the free library. Also, if the library is -modified by someone else and passed on, the recipients should know -that what they have is not the original version, so that the original -author's reputation will not be affected by problems that might be -introduced by others. - - Finally, software patents pose a constant threat to the existence of -any free program. We wish to make sure that a company cannot -effectively restrict the users of a free program by obtaining a -restrictive license from a patent holder. Therefore, we insist that -any patent license obtained for a version of the library must be -consistent with the full freedom of use specified in this license. - - Most GNU software, including some libraries, is covered by the -ordinary GNU General Public License. This license, the GNU Lesser -General Public License, applies to certain designated libraries, and -is quite different from the ordinary General Public License. We use -this license for certain libraries in order to permit linking those -libraries into non-free programs. - - When a program is linked with a library, whether statically or using -a shared library, the combination of the two is legally speaking a -combined work, a derivative of the original library. The ordinary -General Public License therefore permits such linking only if the -entire combination fits its criteria of freedom. The Lesser General -Public License permits more lax criteria for linking other code with -the library. - - We call this license the "Lesser" General Public License because it -does Less to protect the user's freedom than the ordinary General -Public License. It also provides other free software developers Less -of an advantage over competing non-free programs. These disadvantages -are the reason we use the ordinary General Public License for many -libraries. However, the Lesser license provides advantages in certain -special circumstances. - - For example, on rare occasions, there may be a special need to -encourage the widest possible use of a certain library, so that it becomes -a de-facto standard. To achieve this, non-free programs must be -allowed to use the library. A more frequent case is that a free -library does the same job as widely used non-free libraries. In this -case, there is little to gain by limiting the free library to free -software only, so we use the Lesser General Public License. - - In other cases, permission to use a particular library in non-free -programs enables a greater number of people to use a large body of -free software. For example, permission to use the GNU C Library in -non-free programs enables many more people to use the whole GNU -operating system, as well as its variant, the GNU/Linux operating -system. - - Although the Lesser General Public License is Less protective of the -users' freedom, it does ensure that the user of a program that is -linked with the Library has the freedom and the wherewithal to run -that program using a modified version of the Library. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, whereas the latter must -be combined with the library in order to run. - - GNU LESSER GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library or other -program which contains a notice placed by the copyright holder or -other authorized party saying it may be distributed under the terms of -this Lesser General Public License (also called "this License"). -Each licensee is addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also combine or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (1) uses at run time a - copy of the library already present on the user's computer system, - rather than copying library functions into the executable, and (2) - will operate properly with a modified version of the library, if - the user installs one, as long as the modified version is - interface-compatible with the version that the work was made with. - - c) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - d) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - e) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the materials to be distributed need not include anything that is -normally distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties with -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Lesser General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Libraries - - If you develop a new library, and you want it to be of the greatest -possible use to the public, we recommend making it free software that -everyone can redistribute and change. You can do so by permitting -redistribution under these terms (or, alternatively, under the terms of the -ordinary General Public License). - - To apply these terms, attach the following notices to the library. It is -safest to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least the -"copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -Also add information on how to contact you by electronic and paper mail. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the library, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the - library `Frob' (a library for tweaking knobs) written by James Random Hacker. - - , 1 April 1990 - Ty Coon, President of Vice - -That's all there is to it! - - diff --git a/05/musl-final/COPYRIGHT b/05/musl-final/COPYRIGHT deleted file mode 100644 index 92d8992..0000000 --- a/05/musl-final/COPYRIGHT +++ /dev/null @@ -1,40 +0,0 @@ -musl as a whole is licensed under the GNU LGPL version 2.1 or later. -See the file COPYING for the text of this license. - -See below for the copyright status on all code included in musl: - -The TRE regular expression implementation (src/regex/reg* and -src/regex/tre*) is Copyright © 2001-2006 Ville Laurikari and licensed -under the terms of the GNU LGPL version 2.1 or later. The included -version was heavily modified in Spring 2006 by Rich Felker in the -interests of size, simplicity, and namespace cleanliness. - -Most of the math library code (src/math/*) is Copyright © 1993 Sun -Microsystems, Inc. Some files are Copyright © 2003 Steven G. Kargl and -labelled as such. All have been licensed under extremely permissive -terms which are compatible with the GNU LGPL. See the comments in the -individual files for details. - -The implementation of DES for crypt (src/misc/crypt.c) is Copyright © -1994 David Burren. It is licensed under a BSD license compatible with -the GNU LGPL. - -The x86_64 port was written by Nicholas J. Kain. See individual files -for their copyright status. - -All files which have no copyright comments are original works -Copyright © 2005-2011 Rich Felker, the main author of this library. -The decision to exclude such comments is intentional, as it should be -possible to carry around the complete source code on tiny storage -media. All public header files (include/*) should be treated as Public -Domain as they intentionally contain no content which can be covered -by copyright. Some source modules may fall in this category as well. -If you believe that a file is so trivial that it should be in the -Public Domain, please contact me and, if I agree, I will explicitly -release it from copyright. - -The following files are trivial, in my opinion not copyrightable in -the first place, and hereby explicitly released to the Public Domain: - -All public headers: include/* -Startup files: crt/* diff --git a/05/musl-final/INSTALL b/05/musl-final/INSTALL deleted file mode 100644 index 5dd7b67..0000000 --- a/05/musl-final/INSTALL +++ /dev/null @@ -1,58 +0,0 @@ - -A quick-and-simple guide to installing musl: - - -STEP 1: Configuration - -Edit config.mak to override installation prefix, compiler options, -target architecture, etc. as needed. Currently supported archs are -i386 and x86_64. Otherwise, the defaults should be okay for trying out -musl with static linking only. - -DO NOT set the prefix to /, /usr, or even /usr/local unless you really -know what you're doing! You'll probably break your system such that -you'll no longer be able to compile and link programs against glibc! -This kind of setup should only be used if you're building a system -where musl is the default/primary/only libc. - -The default prefix is /usr/local/musl for a reason, but some people -may prefer /opt/musl or $HOME/musl. - - -STEP 2: Compiling - -Run "make". (GNU make is required.) - - -STEP 3: Installation - -With appropriate privileges, run "make install". - - -STEP 4: Using the gcc wrapper. - -musl comes with a script "musl-gcc" (installed in /usr/local/bin by -default) that can be used to compile and link C programs against musl. -It requires a version of gcc with the -wrapper option (gcc 4.x should -work). For example: - -cat > hello.c < -int main() -{ - printf("hello, world!\n"); - return 0; -} -EOF -musl-gcc hello.c -./a.out - -For compiling programs that use autoconf, you'll need to configure -them with a command like this: - -CC=musl-gcc ./configure - -Be aware that (at present) libraries linked against glibc are unlikely -to be usable, and the musl-gcc wrapper inhibits search of the system -library paths in any case. You'll need to compile any prerequisite -libraries (like ncurses, glib, etc.) yourself. diff --git a/05/musl-final/Makefile b/05/musl-final/Makefile deleted file mode 100644 index 6c89eb1..0000000 --- a/05/musl-final/Makefile +++ /dev/null @@ -1,113 +0,0 @@ -# -# Makefile for musl (requires GNU make) -# -# This is how simple every makefile should be... -# No, I take that back - actually most should be less than half this size. -# -# Use config.mak to override any of the following variables. -# Do not make changes here. -# - -CC = ../tcc-0.9.27/tcc -exec_prefix = ../musl-bootstrap-final -bindir = $(exec_prefix)/bin - -prefix = /usr/local/musl-bootstrap -includedir = $(prefix)/include -libdir = $(prefix)/lib - -SRCS = $(sort $(wildcard src/*/*.c)) -OBJS = $(SRCS:.c=.o) src/alloca86_64-bt.o src/alloca86_64.o src/libtcc1.o src/va_list.o src/syscall.o -LOBJS = $(OBJS:.o=.lo) -GENH = include/bits/alltypes.h - -CFLAGS = -Os -nostdinc -ffreestanding -std=c99 -D_XOPEN_SOURCE=700 -pipe -LDFLAGS = -nostdlib -shared -Wl,-Bsymbolic -INC = -I./include -I./src/internal -I./arch/$(ARCH) -PIC = -fPIC -AR = $(CC) -ar -RANLIB = -OBJCOPY = - -ALL_INCLUDES = $(sort $(wildcard include/*.h include/*/*.h) $(GENH)) - -EMPTY_LIB_NAMES = m rt pthread crypt util xnet resolv -EMPTY_LIBS = $(EMPTY_LIB_NAMES:%=lib/lib%.a) -CRT_LIBS = lib/crt1.o lib/crti.o lib/crtn.o -LIBC_LIBS = lib/libc.a -ALL_LIBS = $(LIBC_LIBS) $(CRT_LIBS) - -ALL_TOOLS = tools/musl-gcc - --include config.mak - -all: $(ALL_LIBS) $(ALL_TOOLS) - -install: $(ALL_LIBS:lib/%=$(DESTDIR)$(libdir)/%) $(ALL_INCLUDES:include/%=$(DESTDIR)$(includedir)/%) $(ALL_TOOLS:tools/%=$(DESTDIR)$(bindir)/%) - -src/syscall.o: src/syscall.s - $(CC) -c -o $@ $< -src/%.o: ../tcc-0.9.27/lib/%.o - cp $< $@ -clean: - rm -f crt/*.o - rm -f $(OBJS) - rm -f $(LOBJS) - rm -f $(ALL_LIBS) lib/*.[ao] lib/*.so - rm -f $(ALL_TOOLS) - rm -f $(GENH) - rm -f include/bits - -include/bits: - @test "$(ARCH)" || { echo "Please set ARCH in config.mak before running make." ; exit 1 ; } - ln -sf ../arch/$(ARCH)/bits $@ - -include/bits/alltypes.h.sh: include/bits - -include/bits/alltypes.h: include/bits/alltypes.h.sh - sh $< > $@ - -%.o: $(ARCH)/%.s - $(CC) $(CFLAGS) $(INC) -c -o $@ $< - -%.o: $(ARCH)/%.s - $(CC) $(CFLAGS) $(INC) -c -o $@ $< - -%.o: %.c $(GENH) - $(CC) $(CFLAGS) $(INC) -c -o $@ $< - -%.lo: $(ARCH)/%.s - $(CC) $(CFLAGS) $(INC) $(PIC) -c -o $@ $< - -%.lo: %.c $(GENH) - $(CC) $(CFLAGS) $(INC) $(PIC) -c -o $@ $< - -lib/libc.so: $(LOBJS) - $(CC) $(LDFLAGS) -o $@ $(LOBJS) -lgcc - $(OBJCOPY) --weaken $@ - -lib/libc.a: $(OBJS) - mkdir -p lib - $(AR) rc $@ $(OBJS) - # $(RANLIB) $@ - -$(EMPTY_LIBS): - rm -f $@ - $(AR) rc $@ - -lib/%.o: crt/%.o - cp $< $@ - -tools/musl-gcc: tools/gen-musl-gcc.sh config.mak - sh $< "$(prefix)" > $@ || { rm -f $@ ; exit 1 ; } - chmod +x $@ - -$(DESTDIR)$(bindir)/%: tools/% - install -D $< $@ - -$(DESTDIR)$(prefix)/%: % - install -D -m 644 $< $@ - -.PRECIOUS: $(CRT_LIBS:lib/%=crt/%) - -.PHONY: all clean install diff --git a/05/musl-final/README b/05/musl-final/README deleted file mode 100644 index a57541c..0000000 --- a/05/musl-final/README +++ /dev/null @@ -1,44 +0,0 @@ - -musl libc - a new standard library to power a new generation of -Linux-based devices. musl is lightweight, fast, simple, free, and -strives to be correct in the sense of standards-conformance and -safety. - -musl is an alternative to glibc, eglibc, uClibc, dietlibc, and klibc. -For reasons why one might prefer musl, please see the FAQ and libc -comparison chart on the project website, - - http://www.etalabs.net/musl/ - -For installation instructions, see the INSTALL file. - -Please refer to the COPYRIGHT file for details on the copyright status -of code included in musl, and the COPYING file for the license (LGPL) -under which the library as a whole is distributed. - - - -Greetings libc hackers! - -This package is an _alpha_ release of musl, intended for the curious -and the adventurous. While it can be used to build a complete small -Linux system (musl is self-hosted on the system I use to develop it), -at this point doing so requires a lot of manual effort. Nonetheless, I -hope low-level Linux enthusiasts will try out building some compact -static binaries with musl using the provided gcc wrapper (which allows -you to link programs with musl on a "standard" glibc Linux system), -find whatever embarassing bugs I've let slip through, and provide -feedback on issues encountered building various software against musl. - -Please visit #musl on Freenode IRC or contact me via email at dalias -AT etalabs DOT net for bug reports, support requests, or to get -involved in development. As this has been a one-person project so far, -mailing lists will be setup in due time on an as-needed basis. - -Thank you for trying out musl. - -Cheers, - -Rich Felker / dalias - - diff --git a/05/musl-final/WHATSNEW b/05/musl-final/WHATSNEW deleted file mode 100644 index 360d467..0000000 --- a/05/musl-final/WHATSNEW +++ /dev/null @@ -1,40 +0,0 @@ -0.5.0 - initial release - -0.5.9 - signal ABI bugfix, various cleanup and fixes: - -sigset_t was wrongly defined as 1024 bytes instead of 1024 bits, -breaking the intended ABI compatibility with the LSB/glibc sigaction -structure. users should upgrade immediately and rebuild any libraries -or object files that might be using the incorrect definitions. - -improved security against DoS with tcb shadow passwords by checking -that the file opened was really an ordinary file. - -fixed a bug in the implementation of atomic ops that could have -allowed the compiler to incorrectly reorder them (in practice, gcc -with the default settings on i386 was not reordering them). - -greatly improved conformance to the C and POSIX standards regarding -what the standard header files make visible. _POSIX_C_SOURCE is now -needed to get POSIX functions in standard C headers, and _XOPEN_SOURCE -or _GNU_SOURCE are required to get XSI interfaces or GNU extensions, -respectively. - -many internal improvements have been made to the syscall-related code -in preparation for porting to x86_64 and other archs. - -0.6.0 - x86_64 port, various important bugs fixed - -new x86_64 (amd64) architecture port, contributed by Nicholas J. Kain, -along with PORTING guide. source tree layout and build system have -been improved to accommodate further ports. - -various bugs that were introduced while making the headers respect C -and POSIX namespace standards have been fixed. conformance to the -standards has been improved. - -fixed an inefficiency in qsort that triggered a bug (occasionaly -internal compiler error) in some versions of gcc. - -fixed a major bug in the printf %n specifier that prevented it from -working and caused memory corruption. diff --git a/05/musl-final/arch/i386/atomic.h b/05/musl-final/arch/i386/atomic.h deleted file mode 100644 index e74e453..0000000 --- a/05/musl-final/arch/i386/atomic.h +++ /dev/null @@ -1,110 +0,0 @@ -#ifndef _INTERNAA_ATOMIC_H -#define _INTERNAA_ATOMIC_H - -#include - -static inline int a_ctz_64(uint64_t x) -{ - int r; - __asm__( "bsf %1,%0 ; jnz 1f ; bsf %2,%0 ; addl $32,%0\n1:" - : "=r"(r) : "r"((unsigned)x), "r"((unsigned)(x>>32)) ); - return r; -} - - -static inline void a_and_64(volatile uint64_t *p, uint64_t v) -{ - __asm__( "lock ; andl %1, (%0) ; lock ; andl %2, 4(%0)" - : : "r"((long *)p), "r"((unsigned)v), "r"((unsigned)(v>>32)) : "memory" ); -} - -static inline void a_or_64(volatile uint64_t *p, uint64_t v) -{ - __asm__( "lock ; orl %1, (%0) ; lock ; orl %2, 4(%0)" - : : "r"((long *)p), "r"((unsigned)v), "r"((unsigned)(v>>32)) : "memory" ); -} - -static inline void a_store_l(volatile void *p, long x) -{ - __asm__( "movl %1, %0" : "=m"(*(long *)p) : "r"(x) : "memory" ); -} - -static inline void a_or_l(volatile void *p, long v) -{ - __asm__( "lock ; orl %1, %0" - : "=m"(*(long *)p) : "r"(v) : "memory" ); -} - -static inline void *a_cas_p(volatile void *p, void *t, void *s) -{ - __asm__( "lock ; cmpxchg %3, %1" - : "=a"(t), "=m"(*(long *)p) : "a"(t), "r"(s) : "memory" ); - return t; -} - -static inline long a_cas_l(volatile void *p, long t, long s) -{ - __asm__( "lock ; cmpxchg %3, %1" - : "=a"(t), "=m"(*(long *)p) : "a"(t), "r"(s) : "memory" ); - return t; -} - -static inline void *a_swap_p(void *volatile *x, void *v) -{ - __asm__( "xchg %0, %1" : "=r"(v), "=m"(*(void **)x) : "0"(v) : "memory" ); - return v; -} -static inline long a_swap_l(volatile void *x, long v) -{ - __asm__( "xchg %0, %1" : "=r"(v), "=m"(*(long *)x) : "0"(v) : "memory" ); - return v; -} - -static inline void a_or(volatile void *p, int v) -{ - __asm__( "lock ; orl %1, %0" - : "=m"(*(int *)p) : "r"(v) : "memory" ); -} - -static inline void a_and(volatile void *p, int v) -{ - __asm__( "lock ; andl %1, %0" - : "=m"(*(int *)p) : "r"(v) : "memory" ); -} - -static inline int a_swap(volatile int *x, int v) -{ - __asm__( "xchg %0, %1" : "=r"(v), "=m"(*x) : "0"(v) : "memory" ); - return v; -} - -#define a_xchg a_swap - -static inline int a_fetch_add(volatile int *x, int v) -{ - __asm__( "lock ; xadd %0, %1" : "=r"(v), "=m"(*x) : "0"(v) : "memory" ); - return v; -} - -static inline void a_inc(volatile int *x) -{ - __asm__( "lock ; incl %0" : "=m"(*x) : "m"(*x) : "memory" ); -} - -static inline void a_dec(volatile int *x) -{ - __asm__( "lock ; decl %0" : "=m"(*x) : "m"(*x) : "memory" ); -} - -static inline void a_store(volatile int *p, int x) -{ - __asm__( "movl %1, %0" : "=m"(*p) : "r"(x) : "memory" ); -} - -static inline void a_spin() -{ - __asm__ __volatile__( "pause" : : : "memory" ); -} - - -#endif diff --git a/05/musl-final/arch/i386/bits/alltypes.h.sh b/05/musl-final/arch/i386/bits/alltypes.h.sh deleted file mode 100755 index 27289ea..0000000 --- a/05/musl-final/arch/i386/bits/alltypes.h.sh +++ /dev/null @@ -1,131 +0,0 @@ -#!/bin/sh -sed -e << EOF \ -'/^TYPEDEF/s/TYPEDEF \(.*\) \([^ ]*\);$/#if defined(__NEED_\2) \&\& !defined(__DEFINED_\2)\ -typedef \1 \2;\ -#define __DEFINED_\2\ -#endif\ -/ -/^STRUCT/s/STRUCT * \([^ ]*\) \(.*\);$/#if defined(__NEED_struct_\1) \&\& !defined(__DEFINED_struct_\1)\ -struct \1 \2;\ -#define __DEFINED_struct_\1\ -#endif\ -/ -/^UNION/s/UNION * \([^ ]*\) \(.*\);$/#if defined(__NEED_union_\1) \&\& !defined(__DEFINED_union_\1)\ -union \1 \2;\ -#define __DEFINED_union_\1\ -#endif\ -/' - -TYPEDEF unsigned size_t; -TYPEDEF int ssize_t; -TYPEDEF long ptrdiff_t; -TYPEDEF struct __va_list * va_list; - -TYPEDEF long wchar_t; -TYPEDEF long wint_t; -TYPEDEF long wctrans_t; -TYPEDEF long wctype_t; - -TYPEDEF char int8_t; -TYPEDEF short int16_t; -TYPEDEF int int32_t; -TYPEDEF long long int64_t; - -TYPEDEF unsigned char uint8_t; -TYPEDEF unsigned short uint16_t; -TYPEDEF unsigned int uint32_t; -TYPEDEF unsigned long long uint64_t; - -TYPEDEF unsigned char __uint8_t; -TYPEDEF unsigned short __uint16_t; -TYPEDEF unsigned int __uint32_t; -TYPEDEF unsigned long long __uint64_t; - -TYPEDEF int8_t int_least8_t; -TYPEDEF int16_t int_least16_t; -TYPEDEF int32_t int_least32_t; -TYPEDEF int64_t int_least64_t; - -TYPEDEF uint8_t uint_least8_t; -TYPEDEF uint16_t uint_least16_t; -TYPEDEF uint32_t uint_least32_t; -TYPEDEF uint64_t uint_least64_t; - -TYPEDEF int8_t int_fast8_t; -TYPEDEF int int_fast16_t; -TYPEDEF int int_fast32_t; -TYPEDEF int64_t int_fast64_t; - -TYPEDEF unsigned char uint_fast8_t; -TYPEDEF unsigned int uint_fast16_t; -TYPEDEF unsigned int uint_fast32_t; -TYPEDEF uint64_t uint_fast64_t; - -TYPEDEF long intptr_t; -TYPEDEF unsigned long uintptr_t; - -TYPEDEF long long intmax_t; -TYPEDEF unsigned long long uintmax_t; - -TYPEDEF long time_t; -TYPEDEF unsigned useconds_t; -TYPEDEF int suseconds_t; -STRUCT timeval { time_t tv_sec; int tv_usec; }; -STRUCT timespec { time_t tv_sec; long tv_nsec; }; - -TYPEDEF int pid_t; -TYPEDEF int id_t; -TYPEDEF int uid_t; -TYPEDEF int gid_t; -TYPEDEF int key_t; - -TYPEDEF struct __pthread * pthread_t; -TYPEDEF int pthread_once_t; -TYPEDEF int pthread_key_t; -TYPEDEF int pthread_spinlock_t; - -TYPEDEF struct { union { int __i[9]; size_t __s[2]; } __u; } pthread_attr_t; -TYPEDEF unsigned pthread_mutexattr_t; -TYPEDEF unsigned pthread_condattr_t; -TYPEDEF unsigned pthread_barrierattr_t; -TYPEDEF struct { unsigned __attr[2]; } pthread_rwlockattr_t; - -TYPEDEF struct { union { int __i[6]; void *__p[1]; } __u; } pthread_mutex_t; -TYPEDEF struct { union { int __i[12]; void *__p[1]; } __u; } pthread_cond_t; -TYPEDEF struct { union { int __i[8]; void *__p[1]; } __u; } pthread_rwlock_t; -TYPEDEF struct { union { int __i[5]; void *__p[1]; } __u; } pthread_barrier_t; - -TYPEDEF long long off_t; - -TYPEDEF unsigned int mode_t; - -TYPEDEF unsigned int nlink_t; -TYPEDEF unsigned long long ino_t; -TYPEDEF long long dev_t; -TYPEDEF long blksize_t; -TYPEDEF long long blkcnt_t; -TYPEDEF unsigned long long fsblkcnt_t; -TYPEDEF unsigned long long fsfilcnt_t; - -TYPEDEF void * timer_t; -TYPEDEF int clockid_t; -TYPEDEF unsigned long clock_t; - -TYPEDEF struct { unsigned long __bits[128/sizeof(long)]; } sigset_t; -TYPEDEF struct __siginfo siginfo_t; - -TYPEDEF unsigned int socklen_t; -TYPEDEF unsigned short sa_family_t; -TYPEDEF unsigned short in_port_t; -TYPEDEF unsigned int in_addr_t; -STRUCT in_addr { in_addr_t s_addr; }; - -TYPEDEF struct __FILE_s FILE; - -TYPEDEF int nl_item; - -TYPEDEF struct __locale * locale_t; - -STRUCT iovec { void *iov_base; size_t iov_len; }; - -EOF diff --git a/05/musl-final/arch/i386/bits/endian.h b/05/musl-final/arch/i386/bits/endian.h deleted file mode 100644 index 172c338..0000000 --- a/05/musl-final/arch/i386/bits/endian.h +++ /dev/null @@ -1 +0,0 @@ -#define __BYTE_ORDER __LITTLE_ENDIAN diff --git a/05/musl-final/arch/i386/bits/errno.h b/05/musl-final/arch/i386/bits/errno.h deleted file mode 100644 index ec3d363..0000000 --- a/05/musl-final/arch/i386/bits/errno.h +++ /dev/null @@ -1,132 +0,0 @@ -#define EPERM 1 -#define ENOENT 2 -#define ESRCH 3 -#define EINTR 4 -#define EIO 5 -#define ENXIO 6 -#define E2BIG 7 -#define ENOEXEC 8 -#define EBADF 9 -#define ECHILD 10 -#define EAGAIN 11 -#define ENOMEM 12 -#define EACCES 13 -#define EFAULT 14 -#define ENOTBLK 15 -#define EBUSY 16 -#define EEXIST 17 -#define EXDEV 18 -#define ENODEV 19 -#define ENOTDIR 20 -#define EISDIR 21 -#define EINVAL 22 -#define ENFILE 23 -#define EMFILE 24 -#define ENOTTY 25 -#define ETXTBSY 26 -#define EFBIG 27 -#define ENOSPC 28 -#define ESPIPE 29 -#define EROFS 30 -#define EMLINK 31 -#define EPIPE 32 -#define EDOM 33 -#define ERANGE 34 -#define EDEADLK 35 -#define ENAMETOOLONG 36 -#define ENOLCK 37 -#define ENOSYS 38 -#define ENOTEMPTY 39 -#define ELOOP 40 -#define EWOULDBLOCK EAGAIN -#define ENOMSG 42 -#define EIDRM 43 -#define ECHRNG 44 -#define EL2NSYNC 45 -#define EL3HLT 46 -#define EL3RST 47 -#define ELNRNG 48 -#define EUNATCH 49 -#define ENOCSI 50 -#define EL2HLT 51 -#define EBADE 52 -#define EBADR 53 -#define EXFULL 54 -#define ENOANO 55 -#define EBADRQC 56 -#define EBADSLT 57 -#define EDEADLOCK EDEADLK -#define EBFONT 59 -#define ENOSTR 60 -#define ENODATA 61 -#define ETIME 62 -#define ENOSR 63 -#define ENONET 64 -#define ENOPKG 65 -#define EREMOTE 66 -#define ENOLINK 67 -#define EADV 68 -#define ESRMNT 69 -#define ECOMM 70 -#define EPROTO 71 -#define EMULTIHOP 72 -#define EDOTDOT 73 -#define EBADMSG 74 -#define EOVERFLOW 75 -#define ENOTUNIQ 76 -#define EBADFD 77 -#define EREMCHG 78 -#define ELIBACC 79 -#define ELIBBAD 80 -#define ELIBSCN 81 -#define ELIBMAX 82 -#define ELIBEXEC 83 -#define EILSEQ 84 -#define ERESTART 85 -#define ESTRPIPE 86 -#define EUSERS 87 -#define ENOTSOCK 88 -#define EDESTADDRREQ 89 -#define EMSGSIZE 90 -#define EPROTOTYPE 91 -#define ENOPROTOOPT 92 -#define EPROTONOSUPPORT 93 -#define ESOCKTNOSUPPORT 94 -#define EOPNOTSUPP 95 -#define EPFNOSUPPORT 96 -#define EAFNOSUPPORT 97 -#define EADDRINUSE 98 -#define EADDRNOTAVAIL 99 -#define ENETDOWN 100 -#define ENETUNREACH 101 -#define ENETRESET 102 -#define ECONNABORTED 103 -#define ECONNRESET 104 -#define ENOBUFS 105 -#define EISCONN 106 -#define ENOTCONN 107 -#define ESHUTDOWN 108 -#define ETOOMANYREFS 109 -#define ETIMEDOUT 110 -#define ECONNREFUSED 111 -#define EHOSTDOWN 112 -#define EHOSTUNREACH 113 -#define EALREADY 114 -#define EINPROGRESS 115 -#define ESTALE 116 -#define EUCLEAN 117 -#define ENOTNAM 118 -#define ENAVAIL 119 -#define EISNAM 120 -#define EREMOTEIO 121 -#define EDQUOT 122 -#define ENOMEDIUM 123 -#define EMEDIUMTYPE 124 -#define ECANCELED 125 -#define ENOKEY 126 -#define EKEYEXPIRED 127 -#define EKEYREVOKED 128 -#define EKEYREJECTED 129 -#define EOWNERDEAD 130 -#define ENOTRECOVERABLE 131 -#define ERFKILL 132 diff --git a/05/musl-final/arch/i386/bits/fcntl.h b/05/musl-final/arch/i386/bits/fcntl.h deleted file mode 100644 index 802c3d1..0000000 --- a/05/musl-final/arch/i386/bits/fcntl.h +++ /dev/null @@ -1,60 +0,0 @@ -#define O_ACCMODE 03 -#define O_RDONLY 00 -#define O_WRONLY 01 -#define O_RDWR 02 - -#define O_CREAT 0100 -#define O_EXCL 0200 -#define O_NOCTTY 0400 -#define O_TRUNC 01000 -#define O_APPEND 02000 -#define O_NONBLOCK 04000 -#define O_SYNC 010000 -#define O_DIRECTORY 0200000 -#define O_NOFOLLOW 0400000 -#define O_CLOEXEC 02000000 - -#ifdef _GNU_SOURCE -#define O_NDELAY O_NONBLOCK -#define O_ASYNC 020000 -#define O_DIRECT 040000 -#define O_NOATIME 01000000 -#define F_DUPFD_CLOEXEC 1030 -#define FAPPENT O_APPEND -#define FFSYNC O_FSYNC -#define FASYNC O_ASYNC -#define FNONBLOCK O_NONBLOCK -#define FNDELAY O_NDELAY -#endif - -#define F_DUPFD 0 -#define F_GETFD 1 -#define F_SETFD 2 -#define F_GETFL 3 -#define F_SETFL 4 - -#define F_SETOWN 8 -#define F_GETOWN 9 - -#define F_GETLK 12 -#define F_SETLK 13 -#define F_SETLKW 14 - -#define FD_CLOEXEC 1 - -#define F_RDLCK 0 -#define F_WRLCK 1 -#define F_UNLCK 2 - -#define AT_FDCWD (-100) -#define AT_SYMLINK_NOFOLLOW 0x100 -#define AT_REMOVEDIR 0x200 -#define AT_SYMLINK_FOLLOW 0x400 -#define AT_EACCESS 0x200 - -#define POSIX_FADV_NORMAL 0 -#define POSIX_FADV_RANDOM 1 -#define POSIX_FADV_SEQUENTIAL 2 -#define POSIX_FADV_WILLNEED 3 -#define POSIX_FADV_DONTNEED 4 -#define POSIX_FADV_NOREUSE 5 diff --git a/05/musl-final/arch/i386/bits/fenv.h b/05/musl-final/arch/i386/bits/fenv.h deleted file mode 100644 index 24df041..0000000 --- a/05/musl-final/arch/i386/bits/fenv.h +++ /dev/null @@ -1,34 +0,0 @@ -#define FE_INVALID 1 -#define __FE_DENORM 2 -#define FE_DIVBYZERO 4 -#define FE_OVERFLOW 8 -#define FE_UNDERFLOW 16 -#define FE_INEXACT 32 - -#define FE_ALL_EXCEPT 63 - -#define FE_TONEAREST 0 -#define FE_DOWNWARD 0x400 -#define FE_UPWARD 0x800 -#define FE_TOWARDZERO 0xc00 - -typedef unsigned short fexcept_t; - -typedef struct { - unsigned short __control_word; - unsigned short __unused1; - unsigned short __status_word; - unsigned short __unused2; - unsigned short __tags; - unsigned short __unused3; - unsigned int __eip; - unsigned short __cs_selector; - unsigned int __opcode:11; - unsigned int __unused4:5; - unsigned int __data_offset; - unsigned short __data_selector; - unsigned short __unused5; - unsigned int __mxcsr; -} fenv_t; - -#define FE_DFL_ENV ((const fenv_t *) -1) diff --git a/05/musl-final/arch/i386/bits/float.h b/05/musl-final/arch/i386/bits/float.h deleted file mode 100644 index 162b3e4..0000000 --- a/05/musl-final/arch/i386/bits/float.h +++ /dev/null @@ -1,11 +0,0 @@ -#define LDBL_MIN 3.3621031431120935063e-4932L -#define LDBL_MAX 1.1897314953572317650e+4932L -#define LDBL_EPSILON 1.0842021724855044340e-19L - -#define LDBL_MANT_DIG 64 -#define LDBL_MIN_EXP (-16381) -#define LDBL_MAX_EXP 16384 - -#define LDBL_DIG 18 -#define LDBL_MIN_10_EXP (-4931) -#define LDBL_MAX_10_EXP 4932 diff --git a/05/musl-final/arch/i386/bits/in.h b/05/musl-final/arch/i386/bits/in.h deleted file mode 100644 index b233706..0000000 --- a/05/musl-final/arch/i386/bits/in.h +++ /dev/null @@ -1,133 +0,0 @@ -#define IP_TOS 1 -#define IP_TTL 2 -#define IP_HDRINCL 3 -#define IP_OPTIONS 4 -#define IP_ROUTER_ALERT 5 -#define IP_RECVOPTS 6 -#define IP_RETOPTS 7 -//#define IP_PKTINFO 8 -#define IP_PKTOPTIONS 9 -#define IP_PMTUDISC 10 -#define IP_MTU_DISCOVER 10 -#define IP_RECVERR 11 -#define IP_RECVTTL 12 -#define IP_RECVTOS 13 -#define IP_MTU 14 -#define IP_FREEBIND 15 -#define IP_IPSEC_POLICY 16 -#define IP_XFRM_POLICY 17 -#define IP_PASSSEC 18 -#define IP_TRANSPARENT 19 -#define IP_ORIGDSTADDR 20 -#define IP_RECVORIGDSTADDR IP_ORIGDSTADDR -#define IP_MINTTL 21 -#define IP_MULTICAST_IF 32 -#define IP_MULTICAST_TTL 33 -#define IP_MULTICAST_LOOP 34 -#define IP_ADD_MEMBERSHIP 35 -#define IP_DROP_MEMBERSHIP 36 -#define IP_UNBLOCK_SOURCE 37 -#define IP_BLOCK_SOURCE 38 -#define IP_ADD_SOURCE_MEMBERSHIP 39 -#define IP_DROP_SOURCE_MEMBERSHIP 40 -#define IP_MSFILTER 41 - -#define IP_RECVRETOPTS IP_RETOPTS - -#define IP_PMTUDISC_DONT 0 -#define IP_PMTUDISC_WANT 1 -#define IP_PMTUDISC_DO 2 -#define IP_PMTUDISC_PROBE 3 - -#define SOL_IP 0 - -#define IP_DEFAULT_MULTICAST_TTL 1 -#define IP_DEFAULT_MULTICAST_LOOP 1 -#define IP_MAX_MEMBERSHIPS 20 - -struct ip_opts -{ - struct in_addr ip_dst; - char ip_opts[40]; -}; - -struct ip_mreq -{ - struct in_addr imr_multiaddr; - struct in_addr imr_interface; -}; - -struct ip_mreqn -{ - struct in_addr imr_multiaddr; - struct in_addr imr_address; - int imr_ifindex; -}; - -struct in_pktinfo -{ - int ipi_ifindex; - struct in_addr ipi_spec_dst; - struct in_addr ipi_addr; -}; - -#define IPV6_ADDRFORM 1 -#define IPV6_2292PKTINFO 2 -#define IPV6_2292HOPOPTS 3 -#define IPV6_2292DSTOPTS 4 -#define IPV6_2292RTHDR 5 -#define IPV6_2292PKTOPTIONS 6 -#define IPV6_CHECKSUM 7 -#define IPV6_2292HOPLIMIT 8 -#define SCM_SRCRT IPV6_RXSRCRT -#define IPV6_NEXTHOP 9 -#define IPV6_AUTHHDR 10 -#define IPV6_UNICAST_HOPS 16 -#define IPV6_MULTICAST_IF 17 -#define IPV6_MULTICAST_HOPS 18 -#define IPV6_MULTICAST_LOOP 19 -#define IPV6_JOIN_GROUP 20 -#define IPV6_LEAVE_GROUP 21 -#define IPV6_ROUTER_ALERT 22 -#define IPV6_MTU_DISCOVER 23 -#define IPV6_MTU 24 -#define IPV6_RECVERR 25 -#define IPV6_V6ONLY 26 -#define IPV6_JOIN_ANYCAST 27 -#define IPV6_LEAVE_ANYCAST 28 -#define IPV6_IPSEC_POLICY 34 -#define IPV6_XFRM_POLICY 35 - -#define IPV6_RECVPKTINFO 49 -#define IPV6_PKTINFO 50 -#define IPV6_RECVHOPLIMIT 51 -#define IPV6_HOPLIMIT 52 -#define IPV6_RECVHOPOPTS 53 -#define IPV6_HOPOPTS 54 -#define IPV6_RTHDRDSTOPTS 55 -#define IPV6_RECVRTHDR 56 -#define IPV6_RTHDR 57 -#define IPV6_RECVDSTOPTS 58 -#define IPV6_DSTOPTS 59 - -#define IPV6_RECVTCLASS 66 -#define IPV6_TCLASS 67 - -#define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP -#define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP -#define IPV6_RXHOPOPTS IPV6_HOPOPTS -#define IPV6_RXDSTOPTS IPV6_DSTOPTS - - -#define IPV6_PMTUDISC_DONT 0 -#define IPV6_PMTUDISC_WANT 1 -#define IPV6_PMTUDISC_DO 2 -#define IPV6_PMTUDISC_PROBE 3 - -#define SOL_IPV6 41 -#define SOL_ICMPV6 58 - -#define IPV6_RTHDR_LOOSE 0 -#define IPV6_RTHDR_STRICT 1 - -#define IPV6_RTHDR_TYPE_0 0 diff --git a/05/musl-final/arch/i386/bits/ioctl.h b/05/musl-final/arch/i386/bits/ioctl.h deleted file mode 100644 index 336c71c..0000000 --- a/05/musl-final/arch/i386/bits/ioctl.h +++ /dev/null @@ -1,197 +0,0 @@ -#define _IOC(a,b,c,d) ( ((a)<<30) | ((b)<<8) | (c) | ((d)<<16) ) -#define _IOC_NONE 0U -#define _IOC_WRITE 1U -#define _IOC_READ 2U - -#define _IO(a,b) _IOC(_IOC_NONE,(a),(b),0) -#define _IOW(a,b,c) _IOC(1,(a),(b),sizeof(c)) -#define _IOR(a,b,c) _IOC(2,(a),(b),sizeof(c)) -#define _IOWR(a,b,c) _IOC(3,(a),(b),sizeof(c)) - -#define TCGETS 0x5401 -#define TCSETS 0x5402 -#define TCSETSW 0x5403 -#define TCSETSF 0x5404 -#define TCGETA 0x5405 -#define TCSETA 0x5406 -#define TCSETAW 0x5407 -#define TCSETAF 0x5408 -#define TCSBRK 0x5409 -#define TCXONC 0x540A -#define TCFLSH 0x540B -#define TIOCEXCL 0x540C -#define TIOCNXCL 0x540D -#define TIOCSCTTY 0x540E -#define TIOCGPGRP 0x540F -#define TIOCSPGRP 0x5410 -#define TIOCOUTQ 0x5411 -#define TIOCSTI 0x5412 -#define TIOCGWINSZ 0x5413 -#define TIOCSWINSZ 0x5414 -#define TIOCMGET 0x5415 -#define TIOCMBIS 0x5416 -#define TIOCMBIC 0x5417 -#define TIOCMSET 0x5418 -#define TIOCGSOFTCAR 0x5419 -#define TIOCSSOFTCAR 0x541A -#define FIONREAD 0x541B -#define TIOCINQ FIONREAD -#define TIOCLINUX 0x541C -#define TIOCCONS 0x541D -#define TIOCGSERIAL 0x541E -#define TIOCSSERIAL 0x541F -#define TIOCPKT 0x5420 -#define FIONBIO 0x5421 -#define TIOCNOTTY 0x5422 -#define TIOCSETD 0x5423 -#define TIOCGETD 0x5424 -#define TCSBRKP 0x5425 -#define TIOCTTYGSTRUCT 0x5426 -#define TIOCSBRK 0x5427 -#define TIOCCBRK 0x5428 -#define TIOCGSID 0x5429 -#define TIOCGPTN 0x80045430 -#define TIOCSPTLCK 0x40045431 -#define TCGETX 0x5432 -#define TCSETX 0x5433 -#define TCSETXF 0x5434 -#define TCSETXW 0x5435 - -#define FIONCLEX 0x5450 -#define FIOCLEX 0x5451 -#define FIOASYNC 0x5452 -#define TIOCSERCONFIG 0x5453 -#define TIOCSERGWILD 0x5454 -#define TIOCSERSWILD 0x5455 -#define TIOCGLCKTRMIOS 0x5456 -#define TIOCSLCKTRMIOS 0x5457 -#define TIOCSERGSTRUCT 0x5458 -#define TIOCSERGETLSR 0x5459 -#define TIOCSERGETMULTI 0x545A -#define TIOCSERSETMULTI 0x545B - -#define TIOCMIWAIT 0x545C -#define TIOCGICOUNT 0x545D -#define TIOCGHAYESESP 0x545E -#define TIOCSHAYESESP 0x545F -#define FIOQSIZE 0x5460 - -#define TIOCPKT_DATA 0 -#define TIOCPKT_FLUSHREAD 1 -#define TIOCPKT_FLUSHWRITE 2 -#define TIOCPKT_STOP 4 -#define TIOCPKT_START 8 -#define TIOCPKT_NOSTOP 16 -#define TIOCPKT_DOSTOP 32 -#define TIOCPKT_IOCTL 64 - -#define TIOCSER_TEMT 0x01 - -struct winsize { - unsigned short ws_row; - unsigned short ws_col; - unsigned short ws_xpixel; - unsigned short ws_ypixel; -}; - -#define TIOCM_LE 0x001 -#define TIOCM_DTR 0x002 -#define TIOCM_RTS 0x004 -#define TIOCM_ST 0x008 -#define TIOCM_SR 0x010 -#define TIOCM_CTS 0x020 -#define TIOCM_CAR 0x040 -#define TIOCM_RNG 0x080 -#define TIOCM_DSR 0x100 -#define TIOCM_CD TIOCM_CAR -#define TIOCM_RI TIOCM_RNG -#define TIOCM_OUT1 0x2000 -#define TIOCM_OUT2 0x4000 -#define TIOCM_LOOP 0x8000 -#define TIOCM_MODEM_BITS TIOCM_OUT2 - -#define N_TTY 0 -#define N_SLIP 1 -#define N_MOUSE 2 -#define N_PPP 3 -#define N_STRIP 4 -#define N_AX25 5 -#define N_X25 6 -#define N_6PACK 7 -#define N_MASC 8 -#define N_R3964 9 -#define N_PROFIBUS_FDL 10 -#define N_IRDA 11 -#define N_SMSBLOCK 12 -#define N_HDLC 13 -#define N_SYNC_PPP 14 -#define N_HCI 15 - -#define FIOSETOWN 0x8901 -#define SIOCSPGRP 0x8902 -#define FIOGETOWN 0x8903 -#define SIOCGPGRP 0x8904 -#define SIOCATMARK 0x8905 -#define SIOCGSTAMP 0x8906 - -#define SIOCADDRT 0x890B -#define SIOCDELRT 0x890C -#define SIOCRTMSG 0x890D - -#define SIOCGIFNAME 0x8910 -#define SIOCSIFLINK 0x8911 -#define SIOCGIFCONF 0x8912 -#define SIOCGIFFLAGS 0x8913 -#define SIOCSIFFLAGS 0x8914 -#define SIOCGIFADDR 0x8915 -#define SIOCSIFADDR 0x8916 -#define SIOCGIFDSTADDR 0x8917 -#define SIOCSIFDSTADDR 0x8918 -#define SIOCGIFBRDADDR 0x8919 -#define SIOCSIFBRDADDR 0x891a -#define SIOCGIFNETMASK 0x891b -#define SIOCSIFNETMASK 0x891c -#define SIOCGIFMETRIC 0x891d -#define SIOCSIFMETRIC 0x891e -#define SIOCGIFMEM 0x891f -#define SIOCSIFMEM 0x8920 -#define SIOCGIFMTU 0x8921 -#define SIOCSIFMTU 0x8922 -#define SIOCSIFHWADDR 0x8924 -#define SIOCGIFENCAP 0x8925 -#define SIOCSIFENCAP 0x8926 -#define SIOCGIFHWADDR 0x8927 -#define SIOCGIFSLAVE 0x8929 -#define SIOCSIFSLAVE 0x8930 -#define SIOCADDMULTI 0x8931 -#define SIOCDELMULTI 0x8932 -#define SIOCGIFINDEX 0x8933 -#define SIOGIFINDEX SIOCGIFINDEX -#define SIOCSIFPFLAGS 0x8934 -#define SIOCGIFPFLAGS 0x8935 -#define SIOCDIFADDR 0x8936 -#define SIOCSIFHWBROADCAST 0x8937 -#define SIOCGIFCOUNT 0x8938 - -#define SIOCGIFBR 0x8940 -#define SIOCSIFBR 0x8941 - -#define SIOCGIFTXQLEN 0x8942 -#define SIOCSIFTXQLEN 0x8943 - -#define SIOCDARP 0x8953 -#define SIOCGARP 0x8954 -#define SIOCSARP 0x8955 - -#define SIOCDRARP 0x8960 -#define SIOCGRARP 0x8961 -#define SIOCSRARP 0x8962 - -#define SIOCGIFMAP 0x8970 -#define SIOCSIFMAP 0x8971 - -#define SIOCADDDLCI 0x8980 -#define SIOCDELDLCI 0x8981 - -#define SIOCDEVPRIVATE 0x89F0 -#define SIOCPROTOPRIVATE 0x89E0 diff --git a/05/musl-final/arch/i386/bits/ipc.h b/05/musl-final/arch/i386/bits/ipc.h deleted file mode 100644 index 08316a3..0000000 --- a/05/musl-final/arch/i386/bits/ipc.h +++ /dev/null @@ -1,25 +0,0 @@ -#define IPC_CREAT 01000 -#define IPC_EXCL 02000 -#define IPC_NOWAIT 04000 - -#define IPC_RMID 0 -#define IPC_SET 1 -#define IPC_STAT 2 -#ifdef _GNU_SOURCE -#define IPC_INFO 3 -#endif - -#define IPC_PRIVATE ((key_t) 0) - -struct ipc_perm -{ - key_t key; - uid_t uid; - gid_t gid; - uid_t cuid; - gid_t cgid; - mode_t mode; - int seq; - long __pad1; - long __pad2; -}; diff --git a/05/musl-final/arch/i386/bits/limits.h b/05/musl-final/arch/i386/bits/limits.h deleted file mode 100644 index 4e99245..0000000 --- a/05/musl-final/arch/i386/bits/limits.h +++ /dev/null @@ -1,33 +0,0 @@ -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) -#define PIPE_BUF 4096 -#define PAGESIZE 4096 -#define PAGE_SIZE PAGESIZE -#define FILESIZEBITS 64 -#define NAME_MAX 255 -#define SYMLINK_MAX 255 -#define PATH_MAX 4096 -#define NZERO 20 -#define NGROUPS_MAX 32 -#define ARG_MAX 131072 -#define IOV_MAX 1024 -#define SYMLOOP_MAX 40 -#define WORD_BIT 32 -#define LONG_BIT 32 -#endif - -#define SHRT_MIN (-1-0x7fff) -#define SHRT_MAX 0x7fff -#define USHRT_MAX 0xffff - -#define INT_MIN (-1-0x7fffffff) -#define INT_MAX 0x7fffffff -#define UINT_MAX 0xffffffffU - -#define LONG_MIN (-1-0x7fffffffL) -#define LONG_MAX 0x7fffffffL -#define ULONG_MAX 0xffffffffUL - -#define LLONG_MIN (-1-0x7fffffffffffffffLL) -#define LLONG_MAX 0x7fffffffffffffffLL -#define ULLONG_MAX 0xffffffffffffffffULL diff --git a/05/musl-final/arch/i386/bits/mman.h b/05/musl-final/arch/i386/bits/mman.h deleted file mode 100644 index d133fa2..0000000 --- a/05/musl-final/arch/i386/bits/mman.h +++ /dev/null @@ -1,50 +0,0 @@ -#define MAP_FAILED ((void *) -1) - -#define PROT_NONE 0 -#define PROT_READ 1 -#define PROT_WRITE 2 -#define PROT_EXEC 4 -#define PROT_GROWSDOWN 0x01000000 -#define PROT_GROWSUP 0x02000000 - -#define MAP_SHARED 0x01 -#define MAP_PRIVATE 0x02 -#define MAP_FIXED 0x10 - -/* linux extensions */ -#define MAP_TYPE 0x0f -#define MAP_FILE 0x00 -#define MAP_ANON 0x20 -#define MAP_ANONYMOUS MAP_ANON -#define MAP_32BIT 0x40 - -#define MADV_NORMAL 0 -#define MADV_RANDOM 1 -#define MADV_SEQUENTIAL 2 -#define MADV_WILLNEED 3 -#define MADV_DONTNEED 4 -#define MADV_REMOVE 9 -#define MADV_DONTFORK 10 -#define MADV_DOFORK 11 -#define MADV_MERGEABLE 12 -#define MADV_UNMERGEABLE 13 -#define MADV_HUGEPAGE 14 -#define MADV_NOHUGEPAGE 15 -#define MADV_HWPOISON 100 - -#define POSIX_MADV_NORMAL 0 -#define POSIX_MADV_RANDOM 1 -#define POSIX_MADV_SEQUENTIAL 2 -#define POSIX_MADV_WILLNEED 3 -#define POSIX_MADV_DONTNEED 0 - -#define MS_ASYNC 1 -#define MS_INVALIDATE 2 -#define MS_SYNC 4 - -#define MCL_CURRENT 1 -#define MCL_FUTURE 2 - -/* linux extensions */ -#define MREMAP_MAYMOVE 1 -#define MREMAP_FIXED 2 diff --git a/05/musl-final/arch/i386/bits/posix.h b/05/musl-final/arch/i386/bits/posix.h deleted file mode 100644 index 30a3871..0000000 --- a/05/musl-final/arch/i386/bits/posix.h +++ /dev/null @@ -1,2 +0,0 @@ -#define _POSIX_V6_ILP32_OFFBIG 1 -#define _POSIX_V7_ILP32_OFFBIG 1 diff --git a/05/musl-final/arch/i386/bits/pthread.h b/05/musl-final/arch/i386/bits/pthread.h deleted file mode 100644 index 7d19065..0000000 --- a/05/musl-final/arch/i386/bits/pthread.h +++ /dev/null @@ -1,6 +0,0 @@ -struct __ptcb { - long __jb[7]; - int __dummy; - struct __ptcb *__next; - void *__ptrs[3]; -}; diff --git a/05/musl-final/arch/i386/bits/reg.h b/05/musl-final/arch/i386/bits/reg.h deleted file mode 100644 index 8bc2582..0000000 --- a/05/musl-final/arch/i386/bits/reg.h +++ /dev/null @@ -1,19 +0,0 @@ -#undef __WORDSIZE -#define __WORDSIZE 32 -#define EBX 0 -#define ECX 1 -#define EDX 2 -#define ESI 3 -#define EDI 4 -#define EBP 5 -#define EAX 6 -#define DS 7 -#define ES 8 -#define FS 9 -#define GS 10 -#define ORIG_EAX 11 -#define EIP 12 -#define CS 13 -#define EFL 14 -#define UESP 15 -#define SS 16 diff --git a/05/musl-final/arch/i386/bits/setjmp.h b/05/musl-final/arch/i386/bits/setjmp.h deleted file mode 100644 index b6595bd..0000000 --- a/05/musl-final/arch/i386/bits/setjmp.h +++ /dev/null @@ -1 +0,0 @@ -typedef unsigned long jmp_buf [7]; diff --git a/05/musl-final/arch/i386/bits/shm.h b/05/musl-final/arch/i386/bits/shm.h deleted file mode 100644 index bc95a1c..0000000 --- a/05/musl-final/arch/i386/bits/shm.h +++ /dev/null @@ -1,24 +0,0 @@ -#define SHMLBA 4096 - -#define SHM_RDONLY 010000 -#define SHM_RND 020000 -#define SHM_REMAP 040000 -#define SHM_EXEC 0100000 - -/* linux extensions */ -#define SHM_LOCK 11 -#define SHM_UNLOCK 12 - -struct shmid_ds -{ - struct ipc_perm shm_perm; - size_t shm_segsz; - time_t shm_atime; - time_t shm_dtime; - time_t shm_ctime; - pid_t shm_cpid; - pid_t shm_lpid; - unsigned long shm_nattch; - unsigned long __pad1; - unsigned long __pad2; -}; diff --git a/05/musl-final/arch/i386/bits/signal.h b/05/musl-final/arch/i386/bits/signal.h deleted file mode 100644 index 8827efd..0000000 --- a/05/musl-final/arch/i386/bits/signal.h +++ /dev/null @@ -1,107 +0,0 @@ -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) - -struct __siginfo -{ - int si_signo; - int si_errno; - int si_code; - union - { - char __pad[128 - 3*sizeof(int)]; - struct { - pid_t si_pid; - uid_t si_uid; - union sigval si_sigval; - } __rt; - struct { - unsigned int si_timer1; - unsigned int si_timer2; - } __timer; - struct { - pid_t si_pid; - uid_t si_uid; - int si_status; - clock_t si_utime; - clock_t si_stime; - } __sigchld; - struct { - void *si_addr; - } __sigfault; - struct { - long int si_band; - int si_fd; - } __sigpoll; - } __si_fields; -}; - -#define si_pid __si_fields.__sigchld.si_pid -#define si_uid __si_fields.__sigchld.si_uid -#define si_status __si_fields.__sigchld.si_status -#define si_utime __si_fields.__sigchld.si_utime -#define si_stime __si_fields.__sigchld.si_stime -#define si_value __si_fields.__rt.si_sigval -#define si_addr __si_fields.__sigfault.si_addr -#define si_band __si_fields.__sigpoll.si_band - -#define SA_NOCLDSTOP 1 -#define SA_NOCLDWAIT 2 -#define SA_SIGINFO 4 -#define SA_ONSTACK 0x08000000 -#define SA_RESTART 0x10000000 -#define SA_NODEFER 0x40000000 -#define SA_RESETHAND 0x80000000 -#define SA_RESTORER 0x04000000 - -#define SS_ONSTACK 1 -#define SS_DISABLE 2 - -#define SIG_BLOCK 0 -#define SIG_UNBLOCK 1 -#define SIG_SETMASK 2 - -#define SIG_HOLD ((void (*)(int)) 2) - -#endif - -#ifdef _GNU_SOURCE -#define NSIG 64 -#endif - -#define SIG_ERR ((void (*)(int))-1) -#define SIG_DFL ((void (*)(int)) 0) -#define SIG_IGN ((void (*)(int)) 1) - -#define SIGHUP 1 -#define SIGINT 2 -#define SIGQUIT 3 -#define SIGILL 4 -#define SIGTRAP 5 -#define SIGABRT 6 -#define SIGBUS 7 -#define SIGFPE 8 -#define SIGKILL 9 -#define SIGUSR1 10 -#define SIGSEGV 11 -#define SIGUSR2 12 -#define SIGPIPE 13 -#define SIGALRM 14 -#define SIGTERM 15 -#define SIGSTKFLT 16 -#define SIGCHLD 17 -#define SIGCONT 18 -#define SIGSTOP 19 -#define SIGTSTP 20 -#define SIGTTIN 21 -#define SIGTTOU 22 -#define SIGURG 23 -#define SIGXCPU 24 -#define SIGXFSZ 25 -#define SIGVTALRM 26 -#define SIGPROF 27 -#define SIGWINCH 28 -#define SIGIO 29 -#define SIGPOLL 29 -#define SIGPWR 30 -#define SIGSYS 31 -#define SIGUNUSED SIGSYS diff --git a/05/musl-final/arch/i386/bits/socket.h b/05/musl-final/arch/i386/bits/socket.h deleted file mode 100644 index b323062..0000000 --- a/05/musl-final/arch/i386/bits/socket.h +++ /dev/null @@ -1,210 +0,0 @@ -struct msghdr -{ - void *msg_name; - socklen_t msg_namelen; - struct iovec *msg_iov; - int msg_iovlen; - void *msg_control; - socklen_t msg_controllen; - int msg_flags; -}; - -struct cmsghdr -{ - socklen_t cmsg_len; - int cmsg_level; - int cmsg_type; -}; - -struct ucred -{ - pid_t pid; - uid_t uid; - gid_t gid; -}; - -struct linger -{ - int l_onoff; - int l_linger; -}; - -#define SHUT_RD 0 -#define SHUT_WD 1 -#define SHUT_RDWR 2 - -#define SOCK_STREAM 1 -#define SOCK_DGRAM 2 -#define SOCK_RAW 3 -#define SOCK_RDM 4 -#define SOCK_SEQPACKET 5 -#define SOCK_DCCP 6 -#define SOCK_PACKET 10 - -/* linux extensions */ -#define SOCK_CLOEXEC 02000000 -#define SOCK_NONBLOCK 04000 - -#define PF_UNSPEC 0 -#define PF_LOCAL 1 -#define PF_UNIX PF_LOCAL -#define PF_FILE PF_LOCAL -#define PF_INET 2 -#define PF_AX25 3 -#define PF_IPX 4 -#define PF_APPLETALK 5 -#define PF_NETROM 6 -#define PF_BRIDGE 7 -#define PF_ATMPVC 8 -#define PF_X25 9 -#define PF_INET6 10 -#define PF_ROSE 11 -#define PF_DECnet 12 -#define PF_NETBEUI 13 -#define PF_SECURITY 14 -#define PF_KEY 15 -#define PF_NETLINK 16 -#define PF_ROUTE PF_NETLINK -#define PF_PACKET 17 -#define PF_ASH 18 -#define PF_ECONET 19 -#define PF_ATMSVC 20 -#define PF_SNA 22 -#define PF_IRDA 23 -#define PF_PPPOX 24 -#define PF_WANPIPE 25 -#define PF_BLUETOOTH 31 -#define PF_IUCV 32 -#define PF_RXRPC 33 -#define PF_ISDN 34 -#define PF_PHONET 35 -#define PF_IEEE802154 36 -#define PF_CAIF 37 -#define PF_ALG 38 -#define PF_MAX 39 - -#define AF_UNSPEC PF_UNSPEC -#define AF_LOCAL PF_LOCAL -#define AF_UNIX AF_LOCAL -#define AF_FILE AF_LOCAL -#define AF_INET PF_INET -#define AF_AX25 PF_AX25 -#define AF_IPX PF_IPX -#define AF_APPLETALK PF_APPLETALK -#define AF_NETROM PF_NETROM -#define AF_BRIDGE PF_BRIDGE -#define AF_ATMPVC PF_ATMPVC -#define AF_X25 PF_X25 -#define AF_INET6 PF_INET6 -#define AF_ROSE PF_ROSE -#define AF_DECnet PF_DECnet -#define AF_NETBEUI PF_NETBEUI -#define AF_SECURITY PF_SECURITY -#define AF_KEY PF_KEY -#define AF_NETLINK PF_NETLINK -#define AF_ROUTE AF_NETLINK -#define AF_PACKET PF_PACKET -#define AF_ASH PF_ASH -#define AF_ECONET PF_ECONET -#define AF_ATMSVC PF_ATMSVC -#define AF_SNA PF_SNA -#define AF_IRDA PF_IRDA -#define AF_PPPOX PF_PPPOX -#define AF_WANPIPE PF_WANPIPE -#define AF_BLUETOOTH PF_BLUETOOTH -#define AF_IUCV PF_IUCV -#define AF_RXRPC PF_RXRPC -#define AF_ISDN PF_ISDN -#define AF_PHONET PF_PHONET -#define AF_IEEE802154 PF_IEEE802154 -#define AF_CAIF PF_CAIF -#define AF_ALG PF_ALG -#define AF_MAX PF_MAX - -#define SO_DEBUG 1 -#define SO_REUSEADDR 2 -#define SO_TYPE 3 -#define SO_ERROR 4 -#define SO_DONTROUTE 5 -#define SO_BROADCAST 6 -#define SO_SNDBUF 7 -#define SO_RCVBUF 8 -#define SO_KEEPALIVE 9 -#define SO_OOBINLINE 10 -#define SO_NO_CHECK 11 -#define SO_PRIORITY 12 -#define SO_LINGER 13 -#define SO_BSDCOMPAT 14 -#define SO_REUSEPORT 15 -#define SO_PASSCRED 16 -#define SO_PEERCRED 17 -#define SO_RCVLOWAT 18 -#define SO_SNDLOWAT 19 -#define SO_RCVTIMEO 20 -#define SO_SNDTIMEO 21 - -#define SO_SECURITY_AUTHENTICATION 22 -#define SO_SECURITY_ENCRYPTION_TRANSPORT 23 -#define SO_SECURITY_ENCRYPTION_NETWORK 24 - -#define SO_BINDTODEVICE 25 - -#define SO_ATTACH_FILTER 26 -#define SO_DETACH_FILTER 27 - -#define SO_PEERNAME 28 -#define SO_TIMESTAMP 29 -#define SCM_TIMESTAMP SO_TIMESTAMP - -#define SO_ACCEPTCONN 30 - -#define SOL_SOCKET 1 - -/* ??? */ -#define SOL_RAW 255 -#define SOL_DECNET 261 -#define SOL_X25 262 -#define SOL_PACKET 263 -#define SOL_ATM 264 -#define SOL_AAL 265 -#define SOL_IRDA 266 - -#define SOMAXCONN 128 - -#define MSG_OOB 0x0001 -#define MSG_PEEK 0x0002 -#define MSG_DONTROUTE 0x0004 -#define MSG_CTRUNC 0x0008 -#define MSG_PROXY 0x0010 -#define MSG_TRUNC 0x0020 -#define MSG_DONTWAIT 0x0040 -#define MSG_EOR 0x0080 -#define MSG_WAITALL 0x0100 -#define MSG_FIN 0x0200 -#define MSD_SYN 0x0400 -#define MSG_CONFIRM 0x0800 -#define MSG_RST 0x1000 -#define MSG_ERRQUEUE 0x2000 -#define MSG_NOSIGNAL 0x4000 -#define MSG_MORE 0x8000 -#define MSG_WAITFORONE 0x10000 -#define MSG_CMSG_CLOEXEC 0x40000000 - -/* Internal use only!! to make CMSG_NXTHDR definition readable by mortals */ -#define __CMSG_LEN(cmsg) (((cmsg)->cmsg_len + sizeof(long) - 1) & ~(long)(sizeof(long) - 1)) -#define __CMSG_NEXT(cmsg) ((unsigned char *)(cmsg) + __CMSG_LEN(cmsg)) -#define __MHDR_END(mhdr) ((unsigned char *)(mhdr)->msg_control + (mhdr)->msg_controllen) - -#define CMSG_DATA(cmsg) ((unsigned char *) (((struct cmsghdr *)(cmsg)) + 1)) -#define CMSG_NXTHDR(mhdr, cmsg) ((cmsg)->cmsg_len < sizeof (struct cmsghdr) ? (struct cmsghdr *)0 : \ - (__CMSG_NEXT(cmsg) + sizeof (struct cmsghdr) >= __MHDR_END(mhdr) ? (struct cmsghdr *)0 : \ - ((struct cmsghdr *)__CMSG_NEXT(cmsg)))) -#define CMSG_FIRSTHDR(mhdr) ((size_t) (mhdr)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (mhdr)->msg_control : (struct cmsghdr *) 0) - -/* Are these valid? */ -#define CMSG_ALIGN(len) (((len) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)) -#define CMSG_SPACE(len) (CMSG_ALIGN (len) + CMSG_ALIGN (sizeof (struct cmsghdr))) -#define CMSG_LEN(len) (CMSG_ALIGN (sizeof (struct cmsghdr)) + (len)) - -#define SCM_RIGHTS 0x01 -#define SCM_CREDENTIALS 0x02 diff --git a/05/musl-final/arch/i386/bits/stat.h b/05/musl-final/arch/i386/bits/stat.h deleted file mode 100644 index bb9314a..0000000 --- a/05/musl-final/arch/i386/bits/stat.h +++ /dev/null @@ -1,22 +0,0 @@ -/* copied from kernel definition, but with padding replaced - * by the corresponding correctly-sized userspace types. */ - -struct stat -{ - dev_t st_dev; - int __st_dev_padding; - long __st_ino_truncated; - mode_t st_mode; - nlink_t st_nlink; - uid_t st_uid; - gid_t st_gid; - dev_t st_rdev; - int __st_rdev_padding; - off_t st_size; - blksize_t st_blksize; - blkcnt_t st_blocks; - struct timespec st_atim; - struct timespec st_mtim; - struct timespec st_ctim; - ino_t st_ino; -}; diff --git a/05/musl-final/arch/i386/bits/statfs.h b/05/musl-final/arch/i386/bits/statfs.h deleted file mode 100644 index 9dda440..0000000 --- a/05/musl-final/arch/i386/bits/statfs.h +++ /dev/null @@ -1,16 +0,0 @@ -struct statvfs { - unsigned long f_type; - unsigned long f_bsize; - fsblkcnt_t f_blocks; - fsblkcnt_t f_bfree; - fsblkcnt_t f_bavail; - fsfilcnt_t f_files; - fsfilcnt_t f_ffree; - unsigned long f_fsid; - unsigned long __unused; - unsigned long f_namemax; - unsigned long f_frsize; - fsfilcnt_t f_favail; - unsigned long f_flag; - unsigned long __reserved[2]; -}; diff --git a/05/musl-final/arch/i386/bits/stdarg.h b/05/musl-final/arch/i386/bits/stdarg.h deleted file mode 100644 index 6b1830d..0000000 --- a/05/musl-final/arch/i386/bits/stdarg.h +++ /dev/null @@ -1,9 +0,0 @@ -#define __VA_ALIGNED_SIZE(x) ((sizeof(x) + sizeof(int) - 1) & ~(sizeof(int) - 1)) - -#define va_start(ap, last) ((ap) = (void *)(((char *)&(last)) + __VA_ALIGNED_SIZE(last))) -#define va_end(ap) ((void)0) -#define va_copy(dest, src) ((dest) = (src)) - -#define va_arg(ap, type) \ - ( ((ap) = (va_list)((char *)(ap) + __VA_ALIGNED_SIZE(type))), \ - *(type *)(void *)((char *)(ap) - __VA_ALIGNED_SIZE(type)) ) diff --git a/05/musl-final/arch/i386/bits/stdint.h b/05/musl-final/arch/i386/bits/stdint.h deleted file mode 100644 index 8e21a8c..0000000 --- a/05/musl-final/arch/i386/bits/stdint.h +++ /dev/null @@ -1,23 +0,0 @@ -#define INT_FAST8_MIN INT8_MIN -#define INT_FAST16_MIN INT32_MIN -#define INT_FAST32_MIN INT32_MIN -#define INT_FAST64_MIN INT64_MIN - -#define INT_FAST8_MAX INT8_MAX -#define INT_FAST16_MAX INT32_MAX -#define INT_FAST32_MAX INT32_MAX -#define INT_FAST64_MAX INT64_MAX - -#define UINT_FAST8_MAX UINT8_MAX -#define UINT_FAST16_MAX UINT32_MAX -#define UINT_FAST32_MAX UINT32_MAX -#define UINT_FAST64_MAX UINT64_MAX - -#define INTPTR_MIN INT32_MIN -#define INTPTR_MAX INT32_MAX -#define UINTPTR_MAX UINT32_MAX -#define PTRDIFF_MIN INT32_MIN -#define PTRDIFF_MAX INT32_MAX -#define SIG_ATOMIC_MIN INT32_MIN -#define SIG_ATOMIC_MAX INT32_MAX -#define SIZE_MAX UINT32_MAX diff --git a/05/musl-final/arch/i386/bits/sysmacros.h b/05/musl-final/arch/i386/bits/sysmacros.h deleted file mode 100644 index da29022..0000000 --- a/05/musl-final/arch/i386/bits/sysmacros.h +++ /dev/null @@ -1,7 +0,0 @@ -#define major(x) (((x) >> 8) & 0xff) -#define minor(x) ((x) & 0xff) -#define makedev(x,y) (((x)<<8)|((y)&0xff)) - -//#define makedev(x,y) \ -// ((x)*0x100000001ULL)&(0xfffffffffff0) -// ((y)*0x1001 & 0xffff0ff) diff --git a/05/musl-final/arch/i386/bits/tcp.h b/05/musl-final/arch/i386/bits/tcp.h deleted file mode 100644 index 923231b..0000000 --- a/05/musl-final/arch/i386/bits/tcp.h +++ /dev/null @@ -1 +0,0 @@ -#define TCP_NODELAY 1 diff --git a/05/musl-final/arch/i386/bits/termios.h b/05/musl-final/arch/i386/bits/termios.h deleted file mode 100644 index 316baeb..0000000 --- a/05/musl-final/arch/i386/bits/termios.h +++ /dev/null @@ -1,158 +0,0 @@ -struct termios -{ - tcflag_t c_iflag; - tcflag_t c_oflag; - tcflag_t c_cflag; - tcflag_t c_lflag; - cc_t c_line; - cc_t c_cc[NCCS]; - speed_t __c_ispeed; - speed_t __c_ospeed; -}; - -#define VINTR 0 -#define VQUIT 1 -#define VERASE 2 -#define VKILL 3 -#define VEOF 4 -#define VTIME 5 -#define VMIN 6 -#define VSWTC 7 -#define VSTART 8 -#define VSTOP 9 -#define VSUSP 10 -#define VEOL 11 -#define VREPRINT 12 -#define VDISCARD 13 -#define VWERASE 14 -#define VLNEXT 15 -#define VEOL2 16 - -#define IGNBRK 0000001 -#define BRKINT 0000002 -#define IGNPAR 0000004 -#define PARMRK 0000010 -#define INPCK 0000020 -#define ISTRIP 0000040 -#define INLCR 0000100 -#define IGNCR 0000200 -#define ICRNL 0000400 -#define IUCLC 0001000 -#define IXON 0002000 -#define IXANY 0004000 -#define IXOFF 0010000 -#define IMAXBEL 0020000 - -#define OPOST 0000001 -#define OLCUC 0000002 -#define ONLCR 0000004 -#define OCRNL 0000010 -#define ONOCR 0000020 -#define ONLRET 0000040 -#define OFILL 0000100 -#define OFDEL 0000200 -#define NLDLY 0000400 -#define NL0 0000000 -#define NL1 0000400 -#define CRDLY 0003000 -#define CR0 0000000 -#define CR1 0001000 -#define CR2 0002000 -#define CR3 0003000 -#define TABDLY 0014000 -#define TAB0 0000000 -#define TAB1 0004000 -#define TAB2 0010000 -#define TAB3 0014000 -#define BSDLY 0020000 -#define BS0 0000000 -#define BS1 0020000 -#define FFDLY 0100000 -#define FF0 0000000 -#define FF1 0100000 - -#define VTDLY 0040000 -#define VT0 0000000 -#define VT1 0040000 - -/* ?? */ -#define XTABS 0014000 - -#define B0 0000000 -#define B50 0000001 -#define B75 0000002 -#define B110 0000003 -#define B134 0000004 -#define B150 0000005 -#define B200 0000006 -#define B300 0000007 -#define B600 0000010 -#define B1200 0000011 -#define B1800 0000012 -#define B2400 0000013 -#define B4800 0000014 -#define B9600 0000015 -#define B19200 0000016 -#define B38400 0000017 - -#define B57600 0010001 -#define B115200 0010002 -#define B230400 0010003 -#define B460800 0010004 -#define B500000 0010005 -#define B576000 0010006 -#define B921600 0010007 -#define B1000000 0010010 -#define B1152000 0010011 -#define B1500000 0010012 -#define B2000000 0010013 -#define B2500000 0010014 -#define B3000000 0010015 -#define B3500000 0010016 -#define B4000000 0010017 - -#define CBAUD 0010017 - -#define CSIZE 0000060 -#define CS5 0000000 -#define CS6 0000020 -#define CS7 0000040 -#define CS8 0000060 -#define CSTOPB 0000100 -#define CREAD 0000200 -#define PARENB 0000400 -#define PARODD 0001000 -#define HUPCL 0002000 -#define CLOCAL 0004000 - -#define CRTSCTS 020000000000 - -#define ISIG 0000001 -#define ICANON 0000002 -#define ECHO 0000010 -#define ECHOE 0000020 -#define ECHOK 0000040 -#define ECHONL 0000100 -#define NOFLSH 0000200 -#define TOSTOP 0000400 -#define IEXTEN 0100000 - -/* Extensions? */ -#define ECHOCTL 0001000 -#define ECHOPRT 0002000 -#define ECHOKE 0004000 -#define FLUSHO 0010000 -#define PENDIN 0040000 - -#define TCOOFF 0 -#define TCOON 1 -#define TCIOFF 2 -#define TCION 3 - -#define TCIFLUSH 0 -#define TCOFLUSH 1 -#define TCIOFLUSH 2 - -#define TCSANOW 0 -#define TCSADRAIN 1 -#define TCSAFLUSH 2 diff --git a/05/musl-final/arch/i386/bits/user.h b/05/musl-final/arch/i386/bits/user.h deleted file mode 100644 index 13ff027..0000000 --- a/05/musl-final/arch/i386/bits/user.h +++ /dev/null @@ -1,77 +0,0 @@ -#undef __WORDSIZE -#define __WORDSIZE 32 - -struct user_fpregs_struct -{ - long int cwd; - long int swd; - long int twd; - long int fip; - long int fcs; - long int foo; - long int fos; - long int st_space[20]; -}; - -struct user_fpxregs_struct -{ - unsigned short int cwd; - unsigned short int swd; - unsigned short int twd; - unsigned short int fop; - long int fip; - long int fcs; - long int foo; - long int fos; - long int mxcsr; - long int reserved; - long int st_space[32]; - long int xmm_space[32]; - long int padding[56]; -}; - -struct user_regs_struct -{ - long int ebx; - long int ecx; - long int edx; - long int esi; - long int edi; - long int ebp; - long int eax; - long int xds; - long int xes; - long int xfs; - long int xgs; - long int orig_eax; - long int eip; - long int xcs; - long int eflags; - long int esp; - long int xss; -}; - -struct user -{ - struct user_regs_struct regs; - int u_fpvalid; - struct user_fpregs_struct i387; - unsigned long int u_tsize; - unsigned long int u_dsize; - unsigned long int u_ssize; - unsigned long start_code; - unsigned long start_stack; - long int signal; - int reserved; - struct user_regs_struct *u_ar0; - struct user_fpregs_struct *u_fpstate; - unsigned long int magic; - char u_comm[32]; - int u_debugreg[8]; -}; - -#define PAGE_MASK (~(PAGE_SIZE-1)) -#define NBPG PAGE_SIZE -#define UPAGES 1 -#define HOST_TEXT_START_ADDR (u.start_code) -#define HOST_STACK_END_ADDR (u.start_stack + u.u_ssize * NBPG) diff --git a/05/musl-final/arch/i386/bits/wait.h b/05/musl-final/arch/i386/bits/wait.h deleted file mode 100644 index ae3f101..0000000 --- a/05/musl-final/arch/i386/bits/wait.h +++ /dev/null @@ -1,13 +0,0 @@ -#define WNOHANG 1 -#define WUNTRACED 2 - -#define WSTOPPED 2 -#define WEXITED 4 -#define WCONTINUED 8 -#define WNOWAIT 0x1000000 - -#if defined(__XOPEN_SOURCE) || defined(__GNU_SOURCE) -#define P_ALL 0 -#define P_PID 1 -#define P_PGID 2 -#endif diff --git a/05/musl-final/arch/i386/bits/wexitstatus.h b/05/musl-final/arch/i386/bits/wexitstatus.h deleted file mode 100644 index 34a8023..0000000 --- a/05/musl-final/arch/i386/bits/wexitstatus.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef WEXITSTATUS -#define WEXITSTATUS(s) (((s) & 0xff00) >> 8) -#define WTERMSIG(s) ((s) & 0x7f) -#define WSTOPSIG(s) WEXITSTATUS(s) -#define WCOREDUMP(s) ((s) & 0x80) -#define WIFEXITED(s) (!WTERMSIG(s)) -#define WIFSTOPPED(s) (((s) & 0xff) == 0x7f) -#define WIFSIGNALED(s) (!WIFSTOPPED(s) && !WIFEXITED(s)) -#endif diff --git a/05/musl-final/arch/i386/pthread_arch.h b/05/musl-final/arch/i386/pthread_arch.h deleted file mode 100644 index 155b484..0000000 --- a/05/musl-final/arch/i386/pthread_arch.h +++ /dev/null @@ -1,6 +0,0 @@ -static inline struct pthread *__pthread_self() -{ - struct pthread *self; - __asm__ ("movl %%gs:0,%0" : "=r" (self) ); - return self; -} diff --git a/05/musl-final/arch/i386/syscall.h b/05/musl-final/arch/i386/syscall.h deleted file mode 100644 index ee871a9..0000000 --- a/05/musl-final/arch/i386/syscall.h +++ /dev/null @@ -1,541 +0,0 @@ -#ifndef _SYSCALL_H -#define _SYSCALL_H - -#define SYSCALL_LL(x) \ -((union { long long ll; long l[2]; }){ .ll = x }).l[0], \ -((union { long long ll; long l[2]; }){ .ll = x }).l[1] - -#define SYSCALL_SIGSET_SIZE 8 - -#if defined(SYSCALL_NORETURN) -static inline long __syscall_ret(unsigned long r) -{ - for(;;); - return 0; -} -#elif defined(SYSCALL_RETURN_ERRNO) -static inline long __syscall_ret(unsigned long r) -{ - return -r; -} -#else -extern long __syscall_ret(unsigned long); -#endif - -#define SYSCALL0 "int $128" - -#ifdef __PIC__ -#define SYSCALL "xchgl %%ebx,%2\n\t" SYSCALL0 "\n\txchgl %%ebx,%2" -#define EBX "m" -#else -#define SYSCALL SYSCALL0 -#define EBX "b" -#endif - -static inline long syscall0(long n) -{ - unsigned long ret; - __asm__ __volatile__ (SYSCALL0 : "=a"(ret) : "a"(n) : "memory"); - return __syscall_ret(ret); -} - -static inline long syscall1(long n, long a1) -{ - unsigned long ret; - __asm__ __volatile__ (SYSCALL : "=a"(ret) : "a"(n), EBX(a1) : "memory"); - return __syscall_ret(ret); -} - -static inline long syscall2(long n, long a1, long a2) -{ - unsigned long ret; - __asm__ __volatile__ (SYSCALL : "=a"(ret) : "a"(n), EBX(a1), "c"(a2) : "memory"); - return __syscall_ret(ret); -} - -static inline long syscall3(long n, long a1, long a2, long a3) -{ - unsigned long ret; - __asm__ __volatile__ (SYSCALL : "=a"(ret) : "a"(n), EBX(a1), "c"(a2), "d"(a3) : "memory"); - return __syscall_ret(ret); -} - -static inline long syscall4(long n, long a1, long a2, long a3, long a4) -{ - unsigned long ret; - __asm__ __volatile__ (SYSCALL : "=a"(ret) : "a"(n), EBX(a1), "c"(a2), "d"(a3), "S"(a4) : "memory"); - return __syscall_ret(ret); -} - -static inline long syscall5(long n, long a1, long a2, long a3, long a4, long a5) -{ - unsigned long ret; - __asm__ __volatile__ (SYSCALL : "=a"(ret) : "a"(n), EBX(a1), "c"(a2), "d"(a3), "S"(a4), "D"(a5) : "memory"); - return __syscall_ret(ret); -} - -#ifdef __PIC__ -/* note: it's probably only safe to use this when a6 is on the stack */ -static inline long syscall6(long n, long a1, long a2, long a3, long a4, long a5, long a6) -{ - unsigned long ret; - __asm__ __volatile__ ("xchgl %%ebx,%2 ; pushl %1 ; pushl %%ebp ; movl %%eax,%%ebp ; movl 4(%%esp),%%eax ; int $128 ; popl %%ebp ; popl %%ecx ; xchgl %%ebx,%2" - : "=a"(ret) : "g"(n), EBX(a1), "c"(a2), "d"(a3), "S"(a4), "D"(a5), "a"(a6) : "memory"); - return __syscall_ret(ret); -} -#else -static inline long syscall6(long n, long a1, long a2, long a3, long a4, long a5, long a6) -{ - unsigned long ret; - __asm__ __volatile__ ("pushl %%ebp ; mov %1, %%ebp ; xchg %%ebp, %7 ; int $128 ; popl %%ebp" - : "=a"(ret) : "g"(n), EBX(a1), "c"(a2), "d"(a3), "S"(a4), "D"(a5), "a"(a6) : "memory"); - return __syscall_ret(ret); -} -#endif - -#define __NR_restart_syscall 0 -#define __NR_exit 1 -#define __NR_fork 2 -#define __NR_read 3 -#define __NR_write 4 -#define __NR_open 5 -#define __NR_close 6 -#define __NR_waitpid 7 -#define __NR_creat 8 -#define __NR_link 9 -#define __NR_unlink 10 -#define __NR_execve 11 -#define __NR_chdir 12 -#define __NR_time 13 -#define __NR_mknod 14 -#define __NR_chmod 15 -#define __NR_lchown 16 -#define __NR_break 17 -#define __NR_oldstat 18 -#define __NR_lseek 19 -#define __NR_getpid 20 -#define __NR_mount 21 -#define __NR_umount 22 -#define __NR_setuid 23 -#define __NR_getuid 24 -#define __NR_stime 25 -#define __NR_ptrace 26 -#define __NR_alarm 27 -#define __NR_oldfstat 28 -#define __NR_pause 29 -#define __NR_utime 30 -#define __NR_stty 31 -#define __NR_gtty 32 -#define __NR_access 33 -#define __NR_nice 34 -#define __NR_ftime 35 -#define __NR_sync 36 -#define __NR_kill 37 -#define __NR_rename 38 -#define __NR_mkdir 39 -#define __NR_rmdir 40 -#define __NR_dup 41 -#define __NR_pipe 42 -#define __NR_times 43 -#define __NR_prof 44 -#define __NR_brk 45 -#define __NR_setgid 46 -#define __NR_getgid 47 -#define __NR_signal 48 -#define __NR_geteuid 49 -#define __NR_getegid 50 -#define __NR_acct 51 -#define __NR_umount2 52 -#define __NR_lock 53 -#define __NR_ioctl 54 -#define __NR_fcntl 55 -#define __NR_mpx 56 -#define __NR_setpgid 57 -#define __NR_ulimit 58 -#define __NR_oldolduname 59 -#define __NR_umask 60 -#define __NR_chroot 61 -#define __NR_ustat 62 -#define __NR_dup2 63 -#define __NR_getppid 64 -#define __NR_getpgrp 65 -#define __NR_setsid 66 -#define __NR_sigaction 67 -#define __NR_sgetmask 68 -#define __NR_ssetmask 69 -#define __NR_setreuid 70 -#define __NR_setregid 71 -#define __NR_sigsuspend 72 -#define __NR_sigpending 73 -#define __NR_sethostname 74 -#define __NR_setrlimit 75 -#define __NR_getrlimit 76 /* Back compatible 2Gig limited rlimit */ -#define __NR_getrusage 77 -#define __NR_gettimeofday 78 -#define __NR_settimeofday 79 -#define __NR_getgroups 80 -#define __NR_setgroups 81 -#define __NR_select 82 -#define __NR_symlink 83 -#define __NR_oldlstat 84 -#define __NR_readlink 85 -#define __NR_uselib 86 -#define __NR_swapon 87 -#define __NR_reboot 88 -#define __NR_readdir 89 -#define __NR_mmap 90 -#define __NR_munmap 91 -#define __NR_truncate 92 -#define __NR_ftruncate 93 -#define __NR_fchmod 94 -#define __NR_fchown 95 -#define __NR_getpriority 96 -#define __NR_setpriority 97 -#define __NR_profil 98 -#define __NR_statfs 99 -#define __NR_fstatfs 100 -#define __NR_ioperm 101 -#define __NR_socketcall 102 -#define __NR_syslog 103 -#define __NR_setitimer 104 -#define __NR_getitimer 105 -#define __NR_stat 106 -#define __NR_lstat 107 -#define __NR_fstat 108 -#define __NR_olduname 109 -#define __NR_iopl 110 -#define __NR_vhangup 111 -#define __NR_idle 112 -#define __NR_vm86old 113 -#define __NR_wait4 114 -#define __NR_swapoff 115 -#define __NR_sysinfo 116 -#define __NR_ipc 117 -#define __NR_fsync 118 -#define __NR_sigreturn 119 -#define __NR_clone 120 -#define __NR_setdomainname 121 -#define __NR_uname 122 -#define __NR_modify_ldt 123 -#define __NR_adjtimex 124 -#define __NR_mprotect 125 -#define __NR_sigprocmask 126 -#define __NR_create_module 127 -#define __NR_init_module 128 -#define __NR_delete_module 129 -#define __NR_get_kernel_syms 130 -#define __NR_quotactl 131 -#define __NR_getpgid 132 -#define __NR_fchdir 133 -#define __NR_bdflush 134 -#define __NR_sysfs 135 -#define __NR_personality 136 -#define __NR_afs_syscall 137 -#define __NR_setfsuid 138 -#define __NR_setfsgid 139 -#define __NR__llseek 140 -#define __NR_getdents 141 -#define __NR__newselect 142 -#define __NR_flock 143 -#define __NR_msync 144 -#define __NR_readv 145 -#define __NR_writev 146 -#define __NR_getsid 147 -#define __NR_fdatasync 148 -#define __NR__sysctl 149 -#define __NR_mlock 150 -#define __NR_munlock 151 -#define __NR_mlockall 152 -#define __NR_munlockall 153 -#define __NR_sched_setparam 154 -#define __NR_sched_getparam 155 -#define __NR_sched_setscheduler 156 -#define __NR_sched_getscheduler 157 -#define __NR_sched_yield 158 -#define __NR_sched_get_priority_max 159 -#define __NR_sched_get_priority_min 160 -#define __NR_sched_rr_get_interval 161 -#define __NR_nanosleep 162 -#define __NR_mremap 163 -#define __NR_setresuid 164 -#define __NR_getresuid 165 -#define __NR_vm86 166 -#define __NR_query_module 167 -#define __NR_poll 168 -#define __NR_nfsservctl 169 -#define __NR_setresgid 170 -#define __NR_getresgid 171 -#define __NR_prctl 172 -#define __NR_rt_sigreturn 173 -#define __NR_rt_sigaction 174 -#define __NR_rt_sigprocmask 175 -#define __NR_rt_sigpending 176 -#define __NR_rt_sigtimedwait 177 -#define __NR_rt_sigqueueinfo 178 -#define __NR_rt_sigsuspend 179 -#define __NR_pread64 180 -#define __NR_pwrite64 181 -#define __NR_chown 182 -#define __NR_getcwd 183 -#define __NR_capget 184 -#define __NR_capset 185 -#define __NR_sigaltstack 186 -#define __NR_sendfile 187 -#define __NR_getpmsg 188 -#define __NR_putpmsg 189 -#define __NR_vfork 190 -#define __NR_ugetrlimit 191 -#define __NR_mmap2 192 -#define __NR_truncate64 193 -#define __NR_ftruncate64 194 -#define __NR_stat64 195 -#define __NR_lstat64 196 -#define __NR_fstat64 197 -#define __NR_lchown32 198 -#define __NR_getuid32 199 -#define __NR_getgid32 200 -#define __NR_geteuid32 201 -#define __NR_getegid32 202 -#define __NR_setreuid32 203 -#define __NR_setregid32 204 -#define __NR_getgroups32 205 -#define __NR_setgroups32 206 -#define __NR_fchown32 207 -#define __NR_setresuid32 208 -#define __NR_getresuid32 209 -#define __NR_setresgid32 210 -#define __NR_getresgid32 211 -#define __NR_chown32 212 -#define __NR_setuid32 213 -#define __NR_setgid32 214 -#define __NR_setfsuid32 215 -#define __NR_setfsgid32 216 -#define __NR_pivot_root 217 -#define __NR_mincore 218 -#define __NR_madvise 219 -#define __NR_madvise1 219 -#define __NR_getdents64 220 -#define __NR_fcntl64 221 -/* 223 is unused */ -#define __NR_gettid 224 -#define __NR_readahead 225 -#define __NR_setxattr 226 -#define __NR_lsetxattr 227 -#define __NR_fsetxattr 228 -#define __NR_getxattr 229 -#define __NR_lgetxattr 230 -#define __NR_fgetxattr 231 -#define __NR_listxattr 232 -#define __NR_llistxattr 233 -#define __NR_flistxattr 234 -#define __NR_removexattr 235 -#define __NR_lremovexattr 236 -#define __NR_fremovexattr 237 -#define __NR_tkill 238 -#define __NR_sendfile64 239 -#define __NR_futex 240 -#define __NR_sched_setaffinity 241 -#define __NR_sched_getaffinity 242 -#define __NR_set_thread_area 243 -#define __NR_get_thread_area 244 -#define __NR_io_setup 245 -#define __NR_io_destroy 246 -#define __NR_io_getevents 247 -#define __NR_io_submit 248 -#define __NR_io_cancel 249 -#define __NR_fadvise64 250 -/* 251 is available for reuse (was briefly sys_set_zone_reclaim) */ -#define __NR_exit_group 252 -#define __NR_lookup_dcookie 253 -#define __NR_epoll_create 254 -#define __NR_epoll_ctl 255 -#define __NR_epoll_wait 256 -#define __NR_remap_file_pages 257 -#define __NR_set_tid_address 258 -#define __NR_timer_create 259 -#define __NR_timer_settime (__NR_timer_create+1) -#define __NR_timer_gettime (__NR_timer_create+2) -#define __NR_timer_getoverrun (__NR_timer_create+3) -#define __NR_timer_delete (__NR_timer_create+4) -#define __NR_clock_settime (__NR_timer_create+5) -#define __NR_clock_gettime (__NR_timer_create+6) -#define __NR_clock_getres (__NR_timer_create+7) -#define __NR_clock_nanosleep (__NR_timer_create+8) -#define __NR_statfs64 268 -#define __NR_fstatfs64 269 -#define __NR_tgkill 270 -#define __NR_utimes 271 -#define __NR_fadvise64_64 272 -#define __NR_vserver 273 -#define __NR_mbind 274 -#define __NR_get_mempolicy 275 -#define __NR_set_mempolicy 276 -#define __NR_mq_open 277 -#define __NR_mq_unlink (__NR_mq_open+1) -#define __NR_mq_timedsend (__NR_mq_open+2) -#define __NR_mq_timedreceive (__NR_mq_open+3) -#define __NR_mq_notify (__NR_mq_open+4) -#define __NR_mq_getsetattr (__NR_mq_open+5) -#define __NR_kexec_load 283 -#define __NR_waitid 284 -/* #define __NR_sys_setaltroot 285 */ -#define __NR_add_key 286 -#define __NR_request_key 287 -#define __NR_keyctl 288 -#define __NR_ioprio_set 289 -#define __NR_ioprio_get 290 -#define __NR_inotify_init 291 -#define __NR_inotify_add_watch 292 -#define __NR_inotify_rm_watch 293 -#define __NR_migrate_pages 294 -#define __NR_openat 295 -#define __NR_mkdirat 296 -#define __NR_mknodat 297 -#define __NR_fchownat 298 -#define __NR_futimesat 299 -#define __NR_fstatat64 300 -#define __NR_unlinkat 301 -#define __NR_renameat 302 -#define __NR_linkat 303 -#define __NR_symlinkat 304 -#define __NR_readlinkat 305 -#define __NR_fchmodat 306 -#define __NR_faccessat 307 -#define __NR_pselect6 308 -#define __NR_ppoll 309 -#define __NR_unshare 310 -#define __NR_set_robust_list 311 -#define __NR_get_robust_list 312 -#define __NR_splice 313 -#define __NR_sync_file_range 314 -#define __NR_tee 315 -#define __NR_vmsplice 316 -#define __NR_move_pages 317 -#define __NR_getcpu 318 -#define __NR_epoll_pwait 319 -#define __NR_utimensat 320 -#define __NR_signalfd 321 -#define __NR_timerfd_create 322 -#define __NR_eventfd 323 -#define __NR_fallocate 324 -#define __NR_timerfd_settime 325 -#define __NR_timerfd_gettime 326 -#define __NR_signalfd4 327 -#define __NR_eventfd2 328 -#define __NR_epoll_create1 329 -#define __NR_dup3 330 -#define __NR_pipe2 331 -#define __NR_inotify_init1 332 -#define __NR_preadv 333 -#define __NR_pwritev 334 - -/* fixup legacy 16-bit junk */ -#undef __NR_lchown -#undef __NR_getuid -#undef __NR_getgid -#undef __NR_geteuid -#undef __NR_getegid -#undef __NR_setreuid -#undef __NR_setregid -#undef __NR_getgroups -#undef __NR_setgroups -#undef __NR_fchown -#undef __NR_setresuid -#undef __NR_getresuid -#undef __NR_setresgid -#undef __NR_getresgid -#undef __NR_chown -#undef __NR_setuid -#undef __NR_setgid -#undef __NR_setfsuid -#undef __NR_setfsgid -#define __NR_lchown __NR_lchown32 -#define __NR_getuid __NR_getuid32 -#define __NR_getgid __NR_getgid32 -#define __NR_geteuid __NR_geteuid32 -#define __NR_getegid __NR_getegid32 -#define __NR_setreuid __NR_setreuid32 -#define __NR_setregid __NR_setregid32 -#define __NR_getgroups __NR_getgroups32 -#define __NR_setgroups __NR_setgroups32 -#define __NR_fchown __NR_fchown32 -#define __NR_setresuid __NR_setresuid32 -#define __NR_getresuid __NR_getresuid32 -#define __NR_setresgid __NR_setresgid32 -#define __NR_getresgid __NR_getresgid32 -#define __NR_chown __NR_chown32 -#define __NR_setuid __NR_setuid32 -#define __NR_setgid __NR_setgid32 -#define __NR_setfsuid __NR_setfsuid32 -#define __NR_setfsgid __NR_setfsgid32 - - -/* fixup legacy 32-bit-vs-lfs64 junk */ -#undef __NR_getdents -#undef __NR_ftruncate -#undef __NR_truncate -#undef __NR_stat -#undef __NR_fstat -#undef __NR_lstat -#undef __NR_statfs -#undef __NR_fstatfs -#define __NR_getdents __NR_getdents64 -#define __NR_ftruncate __NR_ftruncate64 -#define __NR_truncate __NR_truncate64 -#define __NR_stat __NR_stat64 -#define __NR_fstat __NR_fstat64 -#define __NR_lstat __NR_lstat64 -#define __NR_statfs __NR_statfs64 -#define __NR_fstatfs __NR_fstatfs64 -#define __NR_fstatat __NR_fstatat64 -#define __NR_pread __NR_pread64 -#define __NR_pwrite __NR_pwrite64 - -#undef __NR_getrlimit -#define __NR_getrlimit __NR_ugetrlimit - -#undef __NR_select -#define __NR_select __NR__newselect - - -#define __SC_socket 1 -#define __SC_bind 2 -#define __SC_connect 3 -#define __SC_listen 4 -#define __SC_accept 5 -#define __SC_getsockname 6 -#define __SC_getpeername 7 -#define __SC_socketpair 8 -#define __SC_send 9 -#define __SC_recv 10 -#define __SC_sendto 11 -#define __SC_recvfrom 12 -#define __SC_shutdown 13 -#define __SC_setsockopt 14 -#define __SC_getsockopt 15 -#define __SC_sendmsg 16 -#define __SC_recvmsg 17 - - -#define socketcall(nm, a, b, c, d, e, f) syscall2(__NR_socketcall, __SC_##nm, \ - (long)(long [6]){ (long)a, (long)b, (long)c, (long)d, (long)e, (long)f }) - - -#undef O_LARGEFILE -#define O_LARGEFILE 0100000 - -/* the following are needed for iso c functions to use */ -#define __syscall_open(filename, flags, mode) syscall3(__NR_open, (long)(filename), (flags)|O_LARGEFILE, (mode)) -#define __syscall_read(fd, buf, len) syscall3(__NR_read, (fd), (long)(buf), (len)) -#define __syscall_write(fd, buf, len) syscall3(__NR_write, (fd), (long)(buf), (len)) -#define __syscall_close(fd) syscall1(__NR_close, (fd)) -#define __syscall_fcntl(fd, cmd, arg) syscall3(__NR_fcntl64, (fd), (cmd), (long)(arg)) -#define __syscall_dup2(old, new) syscall2(__NR_dup2, (old), (new)) -#define __syscall_unlink(path) syscall1(__NR_unlink, (long)(path)) -#define __syscall_getpid() syscall0(__NR_getpid) -#define __syscall_kill(pid,sig) syscall2(__NR_kill, (pid), (sig)) -#define __syscall_sigaction(sig,new,old) syscall4(__NR_rt_sigaction, (sig), (long)(new), (long)(old), SYSCALL_SIGSET_SIZE) -#define __syscall_ioctl(fd,ioc,arg) syscall3(__NR_ioctl, (fd), (ioc), (long)(arg)) -#define __syscall_exit(code) syscall1(__NR_exit, code) - -#endif diff --git a/05/musl-final/arch/x86_64/atomic.h b/05/musl-final/arch/x86_64/atomic.h deleted file mode 100644 index 7a665c1..0000000 --- a/05/musl-final/arch/x86_64/atomic.h +++ /dev/null @@ -1,109 +0,0 @@ -#ifndef _INTERNAA_ATOMIC_H -#define _INTERNAA_ATOMIC_H - -#include - -static inline int a_ctz_64(uint64_t x) -{ - long r; - __asm__( "bsf %1,%0" : "=r"(r) : "r"(x) ); - return r; -} - - -static inline void a_and_64(volatile uint64_t *p, uint64_t v) -{ - __asm__( "lock ; andq %1, %0" - : "=m"(*(long *)p) : "r"(v) : "memory" ); -} - -static inline void a_or_64(volatile uint64_t *p, uint64_t v) -{ - __asm__( "lock ; orq %1, %0" - : "=m"(*(long *)p) : "r"(v) : "memory" ); -} - -static inline void a_store_l(volatile void *p, long x) -{ - __asm__( "movq %1, %0" : "=m"(*(long *)p) : "r"(x) : "memory" ); -} - -static inline void a_or_l(volatile void *p, long v) -{ - __asm__( "lock ; orq %1, %0" - : "=m"(*(long *)p) : "r"(v) : "memory" ); -} - -static inline void *a_cas_p(volatile void *p, void *t, void *s) -{ - __asm__( "lock ; cmpxchg %3, %1" - : "=a"(t), "=m"(*(long *)p) : "a"(t), "r"(s) : "memory" ); - return t; -} - -static inline long a_cas_l(volatile void *p, long t, long s) -{ - __asm__( "lock ; cmpxchg %3, %1" - : "=a"(t), "=m"(*(long *)p) : "a"(t), "r"(s) : "memory" ); - return t; -} - -static inline void *a_swap_p(void *volatile *x, void *v) -{ - __asm__( "xchg %0, %1" : "=r"(v), "=m"(*(void **)x) : "0"(v) : "memory" ); - return v; -} -static inline long a_swap_l(volatile void *x, long v) -{ - __asm__( "xchg %0, %1" : "=r"(v), "=m"(*(long *)x) : "0"(v) : "memory" ); - return v; -} - -static inline void a_or(volatile void *p, int v) -{ - __asm__( "lock ; orl %1, %0" - : "=m"(*(int *)p) : "r"(v) : "memory" ); -} - -static inline void a_and(volatile void *p, int v) -{ - __asm__( "lock ; andl %1, %0" - : "=m"(*(int *)p) : "r"(v) : "memory" ); -} - -static inline int a_swap(volatile int *x, int v) -{ - __asm__( "xchg %0, %1" : "=r"(v), "=m"(*x) : "0"(v) : "memory" ); - return v; -} - -#define a_xchg a_swap - -static inline int a_fetch_add(volatile int *x, int v) -{ - __asm__( "lock ; xadd %0, %1" : "=r"(v), "=m"(*x) : "0"(v) : "memory" ); - return v; -} - -static inline void a_inc(volatile int *x) -{ - __asm__( "lock ; incl %0" : "=m"(*x) : "m"(*x) : "memory" ); -} - -static inline void a_dec(volatile int *x) -{ - __asm__( "lock ; decl %0" : "=m"(*x) : "m"(*x) : "memory" ); -} - -static inline void a_store(volatile int *p, int x) -{ - __asm__( "movl %1, %0" : "=m"(*p) : "r"(x) : "memory" ); -} - -static inline void a_spin() -{ - __asm__ __volatile__( "pause" : : : "memory" ); -} - - -#endif diff --git a/05/musl-final/arch/x86_64/bits/alltypes.h b/05/musl-final/arch/x86_64/bits/alltypes.h deleted file mode 100644 index f07dc5c..0000000 --- a/05/musl-final/arch/x86_64/bits/alltypes.h +++ /dev/null @@ -1,468 +0,0 @@ - -#include - -#if defined(__NEED_size_t) && !defined(__DEFINED_size_t) -typedef unsigned long size_t; -#define __DEFINED_size_t -#endif - -#if defined(__NEED_ssize_t) && !defined(__DEFINED_ssize_t) -typedef long ssize_t; -#define __DEFINED_ssize_t -#endif - -#if defined(__NEED_ptrdiff_t) && !defined(__DEFINED_ptrdiff_t) -typedef long ptrdiff_t; -#define __DEFINED_ptrdiff_t -#endif - -#if 0 -#if defined(__NEED_va_list) && !defined(__DEFINED_va_list) -typedef __builtin_va_list va_list; -#define __DEFINED_va_list -#endif - -#endif - -#if defined(__NEED_wchar_t) && !defined(__DEFINED_wchar_t) -typedef int wchar_t; -#define __DEFINED_wchar_t -#endif - -#if defined(__NEED_wint_t) && !defined(__DEFINED_wint_t) -typedef int wint_t; -#define __DEFINED_wint_t -#endif - -#if defined(__NEED_wctrans_t) && !defined(__DEFINED_wctrans_t) -typedef int wctrans_t; -#define __DEFINED_wctrans_t -#endif - -#if defined(__NEED_wctype_t) && !defined(__DEFINED_wctype_t) -typedef int wctype_t; -#define __DEFINED_wctype_t -#endif - - -#if defined(__NEED_int8_t) && !defined(__DEFINED_int8_t) -typedef char int8_t; -#define __DEFINED_int8_t -#endif - -#if defined(__NEED_int16_t) && !defined(__DEFINED_int16_t) -typedef short int16_t; -#define __DEFINED_int16_t -#endif - -#if defined(__NEED_int32_t) && !defined(__DEFINED_int32_t) -typedef int int32_t; -#define __DEFINED_int32_t -#endif - -#if defined(__NEED_int64_t) && !defined(__DEFINED_int64_t) -typedef long int64_t; -#define __DEFINED_int64_t -#endif - - -#if defined(__NEED_uint8_t) && !defined(__DEFINED_uint8_t) -typedef unsigned char uint8_t; -#define __DEFINED_uint8_t -#endif - -#if defined(__NEED_uint16_t) && !defined(__DEFINED_uint16_t) -typedef unsigned short uint16_t; -#define __DEFINED_uint16_t -#endif - -#if defined(__NEED_uint32_t) && !defined(__DEFINED_uint32_t) -typedef unsigned int uint32_t; -#define __DEFINED_uint32_t -#endif - -#if defined(__NEED_uint64_t) && !defined(__DEFINED_uint64_t) -typedef unsigned long uint64_t; -#define __DEFINED_uint64_t -#endif - - -#if defined(__NEED___uint8_t) && !defined(__DEFINED___uint8_t) -typedef unsigned char __uint8_t; -#define __DEFINED___uint8_t -#endif - -#if defined(__NEED___uint16_t) && !defined(__DEFINED___uint16_t) -typedef unsigned short __uint16_t; -#define __DEFINED___uint16_t -#endif - -#if defined(__NEED___uint32_t) && !defined(__DEFINED___uint32_t) -typedef unsigned int __uint32_t; -#define __DEFINED___uint32_t -#endif - -#if defined(__NEED___uint64_t) && !defined(__DEFINED___uint64_t) -typedef unsigned long __uint64_t; -#define __DEFINED___uint64_t -#endif - - -#if defined(__NEED_int_least8_t) && !defined(__DEFINED_int_least8_t) -typedef int8_t int_least8_t; -#define __DEFINED_int_least8_t -#endif - -#if defined(__NEED_int_least16_t) && !defined(__DEFINED_int_least16_t) -typedef int16_t int_least16_t; -#define __DEFINED_int_least16_t -#endif - -#if defined(__NEED_int_least32_t) && !defined(__DEFINED_int_least32_t) -typedef int32_t int_least32_t; -#define __DEFINED_int_least32_t -#endif - -#if defined(__NEED_int_least64_t) && !defined(__DEFINED_int_least64_t) -typedef int64_t int_least64_t; -#define __DEFINED_int_least64_t -#endif - - -#if defined(__NEED_uint_least8_t) && !defined(__DEFINED_uint_least8_t) -typedef uint8_t uint_least8_t; -#define __DEFINED_uint_least8_t -#endif - -#if defined(__NEED_uint_least16_t) && !defined(__DEFINED_uint_least16_t) -typedef uint16_t uint_least16_t; -#define __DEFINED_uint_least16_t -#endif - -#if defined(__NEED_uint_least32_t) && !defined(__DEFINED_uint_least32_t) -typedef uint32_t uint_least32_t; -#define __DEFINED_uint_least32_t -#endif - -#if defined(__NEED_uint_least64_t) && !defined(__DEFINED_uint_least64_t) -typedef uint64_t uint_least64_t; -#define __DEFINED_uint_least64_t -#endif - - -#if defined(__NEED_int_fast8_t) && !defined(__DEFINED_int_fast8_t) -typedef int8_t int_fast8_t; -#define __DEFINED_int_fast8_t -#endif - -#if defined(__NEED_int_fast16_t) && !defined(__DEFINED_int_fast16_t) -typedef int int_fast16_t; -#define __DEFINED_int_fast16_t -#endif - -#if defined(__NEED_int_fast32_t) && !defined(__DEFINED_int_fast32_t) -typedef int int_fast32_t; -#define __DEFINED_int_fast32_t -#endif - -#if defined(__NEED_int_fast64_t) && !defined(__DEFINED_int_fast64_t) -typedef int64_t int_fast64_t; -#define __DEFINED_int_fast64_t -#endif - - -#if defined(__NEED_uint_fast8_t) && !defined(__DEFINED_uint_fast8_t) -typedef unsigned char uint_fast8_t; -#define __DEFINED_uint_fast8_t -#endif - -#if defined(__NEED_uint_fast16_t) && !defined(__DEFINED_uint_fast16_t) -typedef unsigned int uint_fast16_t; -#define __DEFINED_uint_fast16_t -#endif - -#if defined(__NEED_uint_fast32_t) && !defined(__DEFINED_uint_fast32_t) -typedef unsigned int uint_fast32_t; -#define __DEFINED_uint_fast32_t -#endif - -#if defined(__NEED_uint_fast64_t) && !defined(__DEFINED_uint_fast64_t) -typedef uint64_t uint_fast64_t; -#define __DEFINED_uint_fast64_t -#endif - - -#if defined(__NEED_intptr_t) && !defined(__DEFINED_intptr_t) -typedef long intptr_t; -#define __DEFINED_intptr_t -#endif - -#if defined(__NEED_uintptr_t) && !defined(__DEFINED_uintptr_t) -typedef unsigned long uintptr_t; -#define __DEFINED_uintptr_t -#endif - - -#if defined(__NEED_intmax_t) && !defined(__DEFINED_intmax_t) -typedef long long intmax_t; -#define __DEFINED_intmax_t -#endif - -#if defined(__NEED_uintmax_t) && !defined(__DEFINED_uintmax_t) -typedef unsigned long long uintmax_t; -#define __DEFINED_uintmax_t -#endif - - -#if defined(__NEED_time_t) && !defined(__DEFINED_time_t) -typedef long time_t; -#define __DEFINED_time_t -#endif - -#if defined(__NEED_useconds_t) && !defined(__DEFINED_useconds_t) -typedef long useconds_t; -#define __DEFINED_useconds_t -#endif - -#if defined(__NEED_suseconds_t) && !defined(__DEFINED_suseconds_t) -typedef long suseconds_t; -#define __DEFINED_suseconds_t -#endif - -#if defined(__NEED_struct_timeval) && !defined(__DEFINED_struct_timeval) -struct timeval { time_t tv_sec; int tv_usec; }; -#define __DEFINED_struct_timeval -#endif - -#if defined(__NEED_struct_timespec) && !defined(__DEFINED_struct_timespec) -struct timespec { time_t tv_sec; unsigned long tv_nsec; }; -#define __DEFINED_struct_timespec -#endif - - -#if defined(__NEED_pid_t) && !defined(__DEFINED_pid_t) -typedef int pid_t; -#define __DEFINED_pid_t -#endif - -#if defined(__NEED_id_t) && !defined(__DEFINED_id_t) -typedef int id_t; -#define __DEFINED_id_t -#endif - -#if defined(__NEED_uid_t) && !defined(__DEFINED_uid_t) -typedef unsigned int uid_t; -#define __DEFINED_uid_t -#endif - -#if defined(__NEED_gid_t) && !defined(__DEFINED_gid_t) -typedef unsigned int gid_t; -#define __DEFINED_gid_t -#endif - -#if defined(__NEED_key_t) && !defined(__DEFINED_key_t) -typedef int key_t; -#define __DEFINED_key_t -#endif - - -#if defined(__NEED_pthread_t) && !defined(__DEFINED_pthread_t) -typedef struct __pthread * pthread_t; -#define __DEFINED_pthread_t -#endif - -#if defined(__NEED_pthread_once_t) && !defined(__DEFINED_pthread_once_t) -typedef int pthread_once_t; -#define __DEFINED_pthread_once_t -#endif - -#if defined(__NEED_pthread_key_t) && !defined(__DEFINED_pthread_key_t) -typedef int pthread_key_t; -#define __DEFINED_pthread_key_t -#endif - -#if defined(__NEED_pthread_spinlock_t) && !defined(__DEFINED_pthread_spinlock_t) -typedef int pthread_spinlock_t; -#define __DEFINED_pthread_spinlock_t -#endif - - -#if defined(__NEED_pthread_attr_t) && !defined(__DEFINED_pthread_attr_t) -typedef struct { union { int __i[14]; size_t __s[2]; } __u; } pthread_attr_t; -#define __DEFINED_pthread_attr_t -#endif - -#if defined(__NEED_pthread_mutexattr_t) && !defined(__DEFINED_pthread_mutexattr_t) -typedef unsigned pthread_mutexattr_t; -#define __DEFINED_pthread_mutexattr_t -#endif - -#if defined(__NEED_pthread_condattr_t) && !defined(__DEFINED_pthread_condattr_t) -typedef unsigned pthread_condattr_t; -#define __DEFINED_pthread_condattr_t -#endif - -#if defined(__NEED_pthread_barrierattr_t) && !defined(__DEFINED_pthread_barrierattr_t) -typedef unsigned pthread_barrierattr_t; -#define __DEFINED_pthread_barrierattr_t -#endif - -#if defined(__NEED_pthread_rwlockattr_t) && !defined(__DEFINED_pthread_rwlockattr_t) -typedef struct { unsigned __attr[2]; } pthread_rwlockattr_t; -#define __DEFINED_pthread_rwlockattr_t -#endif - - -#if defined(__NEED_pthread_mutex_t) && !defined(__DEFINED_pthread_mutex_t) -typedef struct { union { int __i[10]; void *__p[1]; } __u; } pthread_mutex_t; -#define __DEFINED_pthread_mutex_t -#endif - -#if defined(__NEED_pthread_cond_t) && !defined(__DEFINED_pthread_cond_t) -typedef struct { union { int __i[12]; void *__p[1]; } __u; } pthread_cond_t; -#define __DEFINED_pthread_cond_t -#endif - -#if defined(__NEED_pthread_rwlock_t) && !defined(__DEFINED_pthread_rwlock_t) -typedef struct { union { int __i[14]; void *__p[1]; } __u; } pthread_rwlock_t; -#define __DEFINED_pthread_rwlock_t -#endif - -#if defined(__NEED_pthread_barrier_t) && !defined(__DEFINED_pthread_barrier_t) -typedef struct { union { int __i[8]; void *__p[1]; } __u; } pthread_barrier_t; -#define __DEFINED_pthread_barrier_t -#endif - - -#if defined(__NEED_off_t) && !defined(__DEFINED_off_t) -typedef long off_t; -#define __DEFINED_off_t -#endif - - -#if defined(__NEED_mode_t) && !defined(__DEFINED_mode_t) -typedef unsigned int mode_t; -#define __DEFINED_mode_t -#endif - - -#if defined(__NEED_nlink_t) && !defined(__DEFINED_nlink_t) -typedef unsigned long nlink_t; -#define __DEFINED_nlink_t -#endif - -#if defined(__NEED_ino_t) && !defined(__DEFINED_ino_t) -typedef unsigned long long ino_t; -#define __DEFINED_ino_t -#endif - -#if defined(__NEED_dev_t) && !defined(__DEFINED_dev_t) -typedef unsigned long dev_t; -#define __DEFINED_dev_t -#endif - -#if defined(__NEED_blksize_t) && !defined(__DEFINED_blksize_t) -typedef long blksize_t; -#define __DEFINED_blksize_t -#endif - -#if defined(__NEED_blkcnt_t) && !defined(__DEFINED_blkcnt_t) -typedef long long blkcnt_t; -#define __DEFINED_blkcnt_t -#endif - -#if defined(__NEED_fsblkcnt_t) && !defined(__DEFINED_fsblkcnt_t) -typedef unsigned long long fsblkcnt_t; -#define __DEFINED_fsblkcnt_t -#endif - -#if defined(__NEED_fsfilcnt_t) && !defined(__DEFINED_fsfilcnt_t) -typedef unsigned long long fsfilcnt_t; -#define __DEFINED_fsfilcnt_t -#endif - - -#if defined(__NEED_timer_t) && !defined(__DEFINED_timer_t) -typedef void * timer_t; -#define __DEFINED_timer_t -#endif - -#if defined(__NEED_clockid_t) && !defined(__DEFINED_clockid_t) -typedef int clockid_t; -#define __DEFINED_clockid_t -#endif - -#if defined(__NEED_clock_t) && !defined(__DEFINED_clock_t) -typedef long clock_t; -#define __DEFINED_clock_t -#endif - - -#if defined(__NEED_sigset_t) && !defined(__DEFINED_sigset_t) -typedef struct { unsigned long __bits[128/sizeof(long)]; } sigset_t; -#define __DEFINED_sigset_t -#endif - -#if 1 -#if defined(__NEED_siginfo_t) && !defined(__DEFINED_siginfo_t) -typedef struct __siginfo siginfo_t; -#define __DEFINED_siginfo_t -#endif - -#else -#if defined(__NEED_siginfo_t) && !defined(__DEFINED_siginfo_t) -#define siginfo_t struct __siginfo -#define __DEFINED_siginfo_t -#endif -#endif - -#if defined(__NEED_socklen_t) && !defined(__DEFINED_socklen_t) -typedef unsigned int socklen_t; -#define __DEFINED_socklen_t -#endif - -#if defined(__NEED_sa_family_t) && !defined(__DEFINED_sa_family_t) -typedef unsigned short sa_family_t; -#define __DEFINED_sa_family_t -#endif - -#if defined(__NEED_in_port_t) && !defined(__DEFINED_in_port_t) -typedef unsigned short in_port_t; -#define __DEFINED_in_port_t -#endif - -#if defined(__NEED_in_addr_t) && !defined(__DEFINED_in_addr_t) -typedef unsigned int in_addr_t; -#define __DEFINED_in_addr_t -#endif - -#if defined(__NEED_struct_in_addr) && !defined(__DEFINED_struct_in_addr) -struct in_addr { in_addr_t s_addr; }; -#define __DEFINED_struct_in_addr -#endif - - -#if defined(__NEED_FILE) && !defined(__DEFINED_FILE) -typedef struct __FILE_s FILE; -#define __DEFINED_FILE -#endif - - -#if defined(__NEED_nl_item) && !defined(__DEFINED_nl_item) -typedef int nl_item; -#define __DEFINED_nl_item -#endif - - -#if defined(__NEED_locale_t) && !defined(__DEFINED_locale_t) -typedef struct __locale * locale_t; -#define __DEFINED_locale_t -#endif - - -#if defined(__NEED_struct_iovec) && !defined(__DEFINED_struct_iovec) -struct iovec { void *iov_base; size_t iov_len; }; -#define __DEFINED_struct_iovec -#endif - - diff --git a/05/musl-final/arch/x86_64/bits/alltypes.h.sh b/05/musl-final/arch/x86_64/bits/alltypes.h.sh deleted file mode 100755 index d9f4f7d..0000000 --- a/05/musl-final/arch/x86_64/bits/alltypes.h.sh +++ /dev/null @@ -1,142 +0,0 @@ -#!/bin/sh -sed -e << EOF \ -'/^TYPEDEF/s/TYPEDEF \(.*\) \([^ ]*\);$/#if defined(__NEED_\2) \&\& !defined(__DEFINED_\2)\ -typedef \1 \2;\ -#define __DEFINED_\2\ -#endif\ -/ -/^STRUCT/s/STRUCT * \([^ ]*\) \(.*\);$/#if defined(__NEED_struct_\1) \&\& !defined(__DEFINED_struct_\1)\ -struct \1 \2;\ -#define __DEFINED_struct_\1\ -#endif\ -/ -/^UNION/s/UNION * \([^ ]*\) \(.*\);$/#if defined(__NEED_union_\1) \&\& !defined(__DEFINED_union_\1)\ -union \1 \2;\ -#define __DEFINED_union_\1\ -#endif\ -/' - -#include - -TYPEDEF unsigned long size_t; -TYPEDEF long ssize_t; -TYPEDEF long ptrdiff_t; -#if 0 -TYPEDEF __builtin_va_list va_list; -#endif - -TYPEDEF int wchar_t; -TYPEDEF int wint_t; -TYPEDEF int wctrans_t; -TYPEDEF int wctype_t; - -TYPEDEF char int8_t; -TYPEDEF short int16_t; -TYPEDEF int int32_t; -TYPEDEF long int64_t; - -TYPEDEF unsigned char uint8_t; -TYPEDEF unsigned short uint16_t; -TYPEDEF unsigned int uint32_t; -TYPEDEF unsigned long uint64_t; - -TYPEDEF unsigned char __uint8_t; -TYPEDEF unsigned short __uint16_t; -TYPEDEF unsigned int __uint32_t; -TYPEDEF unsigned long __uint64_t; - -TYPEDEF int8_t int_least8_t; -TYPEDEF int16_t int_least16_t; -TYPEDEF int32_t int_least32_t; -TYPEDEF int64_t int_least64_t; - -TYPEDEF uint8_t uint_least8_t; -TYPEDEF uint16_t uint_least16_t; -TYPEDEF uint32_t uint_least32_t; -TYPEDEF uint64_t uint_least64_t; - -TYPEDEF int8_t int_fast8_t; -TYPEDEF int int_fast16_t; -TYPEDEF int int_fast32_t; -TYPEDEF int64_t int_fast64_t; - -TYPEDEF unsigned char uint_fast8_t; -TYPEDEF unsigned int uint_fast16_t; -TYPEDEF unsigned int uint_fast32_t; -TYPEDEF uint64_t uint_fast64_t; - -TYPEDEF long intptr_t; -TYPEDEF unsigned long uintptr_t; - -TYPEDEF long long intmax_t; -TYPEDEF unsigned long long uintmax_t; - -TYPEDEF long time_t; -TYPEDEF long useconds_t; -TYPEDEF long suseconds_t; -STRUCT timeval { time_t tv_sec; int tv_usec; }; -STRUCT timespec { time_t tv_sec; unsigned long tv_nsec; }; - -TYPEDEF int pid_t; -TYPEDEF int id_t; -TYPEDEF unsigned int uid_t; -TYPEDEF unsigned int gid_t; -TYPEDEF int key_t; - -TYPEDEF struct __pthread * pthread_t; -TYPEDEF int pthread_once_t; -TYPEDEF int pthread_key_t; -TYPEDEF int pthread_spinlock_t; - -TYPEDEF struct { union { int __i[14]; size_t __s[2]; } __u; } pthread_attr_t; -TYPEDEF unsigned pthread_mutexattr_t; -TYPEDEF unsigned pthread_condattr_t; -TYPEDEF unsigned pthread_barrierattr_t; -TYPEDEF struct { unsigned __attr[2]; } pthread_rwlockattr_t; - -TYPEDEF struct { union { int __i[10]; void *__p[1]; } __u; } pthread_mutex_t; -TYPEDEF struct { union { int __i[12]; void *__p[1]; } __u; } pthread_cond_t; -TYPEDEF struct { union { int __i[14]; void *__p[1]; } __u; } pthread_rwlock_t; -TYPEDEF struct { union { int __i[8]; void *__p[1]; } __u; } pthread_barrier_t; - -TYPEDEF long off_t; - -TYPEDEF unsigned int mode_t; - -TYPEDEF unsigned long nlink_t; -TYPEDEF unsigned long long ino_t; -TYPEDEF unsigned long dev_t; -TYPEDEF long blksize_t; -TYPEDEF long long blkcnt_t; -TYPEDEF unsigned long long fsblkcnt_t; -TYPEDEF unsigned long long fsfilcnt_t; - -TYPEDEF void * timer_t; -TYPEDEF int clockid_t; -TYPEDEF long clock_t; - -TYPEDEF struct { unsigned long __bits[128/sizeof(long)]; } sigset_t; -#if 1 -TYPEDEF struct __siginfo siginfo_t; -#else -#if defined(__NEED_siginfo_t) && !defined(__DEFINED_siginfo_t) -#define siginfo_t struct __siginfo -#define __DEFINED_siginfo_t -#endif -#endif - -TYPEDEF unsigned int socklen_t; -TYPEDEF unsigned short sa_family_t; -TYPEDEF unsigned short in_port_t; -TYPEDEF unsigned int in_addr_t; -STRUCT in_addr { in_addr_t s_addr; }; - -TYPEDEF struct __FILE_s FILE; - -TYPEDEF int nl_item; - -TYPEDEF struct __locale * locale_t; - -STRUCT iovec { void *iov_base; size_t iov_len; }; - -EOF diff --git a/05/musl-final/arch/x86_64/bits/endian.h b/05/musl-final/arch/x86_64/bits/endian.h deleted file mode 100644 index 172c338..0000000 --- a/05/musl-final/arch/x86_64/bits/endian.h +++ /dev/null @@ -1 +0,0 @@ -#define __BYTE_ORDER __LITTLE_ENDIAN diff --git a/05/musl-final/arch/x86_64/bits/errno.h b/05/musl-final/arch/x86_64/bits/errno.h deleted file mode 100644 index ec3d363..0000000 --- a/05/musl-final/arch/x86_64/bits/errno.h +++ /dev/null @@ -1,132 +0,0 @@ -#define EPERM 1 -#define ENOENT 2 -#define ESRCH 3 -#define EINTR 4 -#define EIO 5 -#define ENXIO 6 -#define E2BIG 7 -#define ENOEXEC 8 -#define EBADF 9 -#define ECHILD 10 -#define EAGAIN 11 -#define ENOMEM 12 -#define EACCES 13 -#define EFAULT 14 -#define ENOTBLK 15 -#define EBUSY 16 -#define EEXIST 17 -#define EXDEV 18 -#define ENODEV 19 -#define ENOTDIR 20 -#define EISDIR 21 -#define EINVAL 22 -#define ENFILE 23 -#define EMFILE 24 -#define ENOTTY 25 -#define ETXTBSY 26 -#define EFBIG 27 -#define ENOSPC 28 -#define ESPIPE 29 -#define EROFS 30 -#define EMLINK 31 -#define EPIPE 32 -#define EDOM 33 -#define ERANGE 34 -#define EDEADLK 35 -#define ENAMETOOLONG 36 -#define ENOLCK 37 -#define ENOSYS 38 -#define ENOTEMPTY 39 -#define ELOOP 40 -#define EWOULDBLOCK EAGAIN -#define ENOMSG 42 -#define EIDRM 43 -#define ECHRNG 44 -#define EL2NSYNC 45 -#define EL3HLT 46 -#define EL3RST 47 -#define ELNRNG 48 -#define EUNATCH 49 -#define ENOCSI 50 -#define EL2HLT 51 -#define EBADE 52 -#define EBADR 53 -#define EXFULL 54 -#define ENOANO 55 -#define EBADRQC 56 -#define EBADSLT 57 -#define EDEADLOCK EDEADLK -#define EBFONT 59 -#define ENOSTR 60 -#define ENODATA 61 -#define ETIME 62 -#define ENOSR 63 -#define ENONET 64 -#define ENOPKG 65 -#define EREMOTE 66 -#define ENOLINK 67 -#define EADV 68 -#define ESRMNT 69 -#define ECOMM 70 -#define EPROTO 71 -#define EMULTIHOP 72 -#define EDOTDOT 73 -#define EBADMSG 74 -#define EOVERFLOW 75 -#define ENOTUNIQ 76 -#define EBADFD 77 -#define EREMCHG 78 -#define ELIBACC 79 -#define ELIBBAD 80 -#define ELIBSCN 81 -#define ELIBMAX 82 -#define ELIBEXEC 83 -#define EILSEQ 84 -#define ERESTART 85 -#define ESTRPIPE 86 -#define EUSERS 87 -#define ENOTSOCK 88 -#define EDESTADDRREQ 89 -#define EMSGSIZE 90 -#define EPROTOTYPE 91 -#define ENOPROTOOPT 92 -#define EPROTONOSUPPORT 93 -#define ESOCKTNOSUPPORT 94 -#define EOPNOTSUPP 95 -#define EPFNOSUPPORT 96 -#define EAFNOSUPPORT 97 -#define EADDRINUSE 98 -#define EADDRNOTAVAIL 99 -#define ENETDOWN 100 -#define ENETUNREACH 101 -#define ENETRESET 102 -#define ECONNABORTED 103 -#define ECONNRESET 104 -#define ENOBUFS 105 -#define EISCONN 106 -#define ENOTCONN 107 -#define ESHUTDOWN 108 -#define ETOOMANYREFS 109 -#define ETIMEDOUT 110 -#define ECONNREFUSED 111 -#define EHOSTDOWN 112 -#define EHOSTUNREACH 113 -#define EALREADY 114 -#define EINPROGRESS 115 -#define ESTALE 116 -#define EUCLEAN 117 -#define ENOTNAM 118 -#define ENAVAIL 119 -#define EISNAM 120 -#define EREMOTEIO 121 -#define EDQUOT 122 -#define ENOMEDIUM 123 -#define EMEDIUMTYPE 124 -#define ECANCELED 125 -#define ENOKEY 126 -#define EKEYEXPIRED 127 -#define EKEYREVOKED 128 -#define EKEYREJECTED 129 -#define EOWNERDEAD 130 -#define ENOTRECOVERABLE 131 -#define ERFKILL 132 diff --git a/05/musl-final/arch/x86_64/bits/fcntl.h b/05/musl-final/arch/x86_64/bits/fcntl.h deleted file mode 100644 index 802c3d1..0000000 --- a/05/musl-final/arch/x86_64/bits/fcntl.h +++ /dev/null @@ -1,60 +0,0 @@ -#define O_ACCMODE 03 -#define O_RDONLY 00 -#define O_WRONLY 01 -#define O_RDWR 02 - -#define O_CREAT 0100 -#define O_EXCL 0200 -#define O_NOCTTY 0400 -#define O_TRUNC 01000 -#define O_APPEND 02000 -#define O_NONBLOCK 04000 -#define O_SYNC 010000 -#define O_DIRECTORY 0200000 -#define O_NOFOLLOW 0400000 -#define O_CLOEXEC 02000000 - -#ifdef _GNU_SOURCE -#define O_NDELAY O_NONBLOCK -#define O_ASYNC 020000 -#define O_DIRECT 040000 -#define O_NOATIME 01000000 -#define F_DUPFD_CLOEXEC 1030 -#define FAPPENT O_APPEND -#define FFSYNC O_FSYNC -#define FASYNC O_ASYNC -#define FNONBLOCK O_NONBLOCK -#define FNDELAY O_NDELAY -#endif - -#define F_DUPFD 0 -#define F_GETFD 1 -#define F_SETFD 2 -#define F_GETFL 3 -#define F_SETFL 4 - -#define F_SETOWN 8 -#define F_GETOWN 9 - -#define F_GETLK 12 -#define F_SETLK 13 -#define F_SETLKW 14 - -#define FD_CLOEXEC 1 - -#define F_RDLCK 0 -#define F_WRLCK 1 -#define F_UNLCK 2 - -#define AT_FDCWD (-100) -#define AT_SYMLINK_NOFOLLOW 0x100 -#define AT_REMOVEDIR 0x200 -#define AT_SYMLINK_FOLLOW 0x400 -#define AT_EACCESS 0x200 - -#define POSIX_FADV_NORMAL 0 -#define POSIX_FADV_RANDOM 1 -#define POSIX_FADV_SEQUENTIAL 2 -#define POSIX_FADV_WILLNEED 3 -#define POSIX_FADV_DONTNEED 4 -#define POSIX_FADV_NOREUSE 5 diff --git a/05/musl-final/arch/x86_64/bits/fenv.h b/05/musl-final/arch/x86_64/bits/fenv.h deleted file mode 100644 index 24df041..0000000 --- a/05/musl-final/arch/x86_64/bits/fenv.h +++ /dev/null @@ -1,34 +0,0 @@ -#define FE_INVALID 1 -#define __FE_DENORM 2 -#define FE_DIVBYZERO 4 -#define FE_OVERFLOW 8 -#define FE_UNDERFLOW 16 -#define FE_INEXACT 32 - -#define FE_ALL_EXCEPT 63 - -#define FE_TONEAREST 0 -#define FE_DOWNWARD 0x400 -#define FE_UPWARD 0x800 -#define FE_TOWARDZERO 0xc00 - -typedef unsigned short fexcept_t; - -typedef struct { - unsigned short __control_word; - unsigned short __unused1; - unsigned short __status_word; - unsigned short __unused2; - unsigned short __tags; - unsigned short __unused3; - unsigned int __eip; - unsigned short __cs_selector; - unsigned int __opcode:11; - unsigned int __unused4:5; - unsigned int __data_offset; - unsigned short __data_selector; - unsigned short __unused5; - unsigned int __mxcsr; -} fenv_t; - -#define FE_DFL_ENV ((const fenv_t *) -1) diff --git a/05/musl-final/arch/x86_64/bits/float.h b/05/musl-final/arch/x86_64/bits/float.h deleted file mode 100644 index 162b3e4..0000000 --- a/05/musl-final/arch/x86_64/bits/float.h +++ /dev/null @@ -1,11 +0,0 @@ -#define LDBL_MIN 3.3621031431120935063e-4932L -#define LDBL_MAX 1.1897314953572317650e+4932L -#define LDBL_EPSILON 1.0842021724855044340e-19L - -#define LDBL_MANT_DIG 64 -#define LDBL_MIN_EXP (-16381) -#define LDBL_MAX_EXP 16384 - -#define LDBL_DIG 18 -#define LDBL_MIN_10_EXP (-4931) -#define LDBL_MAX_10_EXP 4932 diff --git a/05/musl-final/arch/x86_64/bits/in.h b/05/musl-final/arch/x86_64/bits/in.h deleted file mode 100644 index b233706..0000000 --- a/05/musl-final/arch/x86_64/bits/in.h +++ /dev/null @@ -1,133 +0,0 @@ -#define IP_TOS 1 -#define IP_TTL 2 -#define IP_HDRINCL 3 -#define IP_OPTIONS 4 -#define IP_ROUTER_ALERT 5 -#define IP_RECVOPTS 6 -#define IP_RETOPTS 7 -//#define IP_PKTINFO 8 -#define IP_PKTOPTIONS 9 -#define IP_PMTUDISC 10 -#define IP_MTU_DISCOVER 10 -#define IP_RECVERR 11 -#define IP_RECVTTL 12 -#define IP_RECVTOS 13 -#define IP_MTU 14 -#define IP_FREEBIND 15 -#define IP_IPSEC_POLICY 16 -#define IP_XFRM_POLICY 17 -#define IP_PASSSEC 18 -#define IP_TRANSPARENT 19 -#define IP_ORIGDSTADDR 20 -#define IP_RECVORIGDSTADDR IP_ORIGDSTADDR -#define IP_MINTTL 21 -#define IP_MULTICAST_IF 32 -#define IP_MULTICAST_TTL 33 -#define IP_MULTICAST_LOOP 34 -#define IP_ADD_MEMBERSHIP 35 -#define IP_DROP_MEMBERSHIP 36 -#define IP_UNBLOCK_SOURCE 37 -#define IP_BLOCK_SOURCE 38 -#define IP_ADD_SOURCE_MEMBERSHIP 39 -#define IP_DROP_SOURCE_MEMBERSHIP 40 -#define IP_MSFILTER 41 - -#define IP_RECVRETOPTS IP_RETOPTS - -#define IP_PMTUDISC_DONT 0 -#define IP_PMTUDISC_WANT 1 -#define IP_PMTUDISC_DO 2 -#define IP_PMTUDISC_PROBE 3 - -#define SOL_IP 0 - -#define IP_DEFAULT_MULTICAST_TTL 1 -#define IP_DEFAULT_MULTICAST_LOOP 1 -#define IP_MAX_MEMBERSHIPS 20 - -struct ip_opts -{ - struct in_addr ip_dst; - char ip_opts[40]; -}; - -struct ip_mreq -{ - struct in_addr imr_multiaddr; - struct in_addr imr_interface; -}; - -struct ip_mreqn -{ - struct in_addr imr_multiaddr; - struct in_addr imr_address; - int imr_ifindex; -}; - -struct in_pktinfo -{ - int ipi_ifindex; - struct in_addr ipi_spec_dst; - struct in_addr ipi_addr; -}; - -#define IPV6_ADDRFORM 1 -#define IPV6_2292PKTINFO 2 -#define IPV6_2292HOPOPTS 3 -#define IPV6_2292DSTOPTS 4 -#define IPV6_2292RTHDR 5 -#define IPV6_2292PKTOPTIONS 6 -#define IPV6_CHECKSUM 7 -#define IPV6_2292HOPLIMIT 8 -#define SCM_SRCRT IPV6_RXSRCRT -#define IPV6_NEXTHOP 9 -#define IPV6_AUTHHDR 10 -#define IPV6_UNICAST_HOPS 16 -#define IPV6_MULTICAST_IF 17 -#define IPV6_MULTICAST_HOPS 18 -#define IPV6_MULTICAST_LOOP 19 -#define IPV6_JOIN_GROUP 20 -#define IPV6_LEAVE_GROUP 21 -#define IPV6_ROUTER_ALERT 22 -#define IPV6_MTU_DISCOVER 23 -#define IPV6_MTU 24 -#define IPV6_RECVERR 25 -#define IPV6_V6ONLY 26 -#define IPV6_JOIN_ANYCAST 27 -#define IPV6_LEAVE_ANYCAST 28 -#define IPV6_IPSEC_POLICY 34 -#define IPV6_XFRM_POLICY 35 - -#define IPV6_RECVPKTINFO 49 -#define IPV6_PKTINFO 50 -#define IPV6_RECVHOPLIMIT 51 -#define IPV6_HOPLIMIT 52 -#define IPV6_RECVHOPOPTS 53 -#define IPV6_HOPOPTS 54 -#define IPV6_RTHDRDSTOPTS 55 -#define IPV6_RECVRTHDR 56 -#define IPV6_RTHDR 57 -#define IPV6_RECVDSTOPTS 58 -#define IPV6_DSTOPTS 59 - -#define IPV6_RECVTCLASS 66 -#define IPV6_TCLASS 67 - -#define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP -#define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP -#define IPV6_RXHOPOPTS IPV6_HOPOPTS -#define IPV6_RXDSTOPTS IPV6_DSTOPTS - - -#define IPV6_PMTUDISC_DONT 0 -#define IPV6_PMTUDISC_WANT 1 -#define IPV6_PMTUDISC_DO 2 -#define IPV6_PMTUDISC_PROBE 3 - -#define SOL_IPV6 41 -#define SOL_ICMPV6 58 - -#define IPV6_RTHDR_LOOSE 0 -#define IPV6_RTHDR_STRICT 1 - -#define IPV6_RTHDR_TYPE_0 0 diff --git a/05/musl-final/arch/x86_64/bits/ioctl.h b/05/musl-final/arch/x86_64/bits/ioctl.h deleted file mode 100644 index 7f3c038..0000000 --- a/05/musl-final/arch/x86_64/bits/ioctl.h +++ /dev/null @@ -1,197 +0,0 @@ -#define _IOC(a,b,c,d) ( ((a)<<30) | ((b)<<8) | (c) | ((d)<<16) ) -#define _IOC_NONE 0U -#define _IOC_WRITE 1U -#define _IOC_READ 2U - -#define _IO(a,b) _IOC(_IOC_NONE,(a),(b),0) -#define _IOW(a,b,c) _IOC(1,(a),(b),sizeof(c)) -#define _IOR(a,b,c) _IOC(2,(a),(b),sizeof(c)) -#define _IOWR(a,b,c) _IOC(3,(a),(b),sizeof(c)) - -#define TCGETS 0x5401 -#define TCSETS 0x5402 -#define TCSETSW 0x5403 -#define TCSETSF 0x5404 -#define TCGETA 0x5405 -#define TCSETA 0x5406 -#define TCSETAW 0x5407 -#define TCSETAF 0x5408 -#define TCSBRK 0x5409 -#define TCXONC 0x540A -#define TCFLSH 0x540B -#define TIOCEXCL 0x540C -#define TIOCNXCL 0x540D -#define TIOCSCTTY 0x540E -#define TIOCGPGRP 0x540F -#define TIOCSPGRP 0x5410 -#define TIOCOUTQ 0x5411 -#define TIOCSTI 0x5412 -#define TIOCGWINSZ 0x5413 -#define TIOCSWINSZ 0x5414 -#define TIOCMGET 0x5415 -#define TIOCMBIS 0x5416 -#define TIOCMBIC 0x5417 -#define TIOCMSET 0x5418 -#define TIOCGSOFTCAR 0x5419 -#define TIOCSSOFTCAR 0x541A -#define FIONREAD 0x541B -#define TIOCINQ FIONREAD -#define TIOCLINUX 0x541C -#define TIOCCONS 0x541D -#define TIOCGSERIAL 0x541E -#define TIOCSSERIAL 0x541F -#define TIOCPKT 0x5420 -#define FIONBIO 0x5421 -#define TIOCNOTTY 0x5422 -#define TIOCSETD 0x5423 -#define TIOCGETD 0x5424 -#define TCSBRKP 0x5425 -#define TIOCTTYGSTRUCT 0x5426 -#define TIOCSBRK 0x5427 -#define TIOCCBRK 0x5428 -#define TIOCGSID 0x5429 -#define TIOCGPTN 0x80045430 -#define TIOCSPTLCK 0x40045431 -#define TCGETX 0x5432 -#define TCSETX 0x5433 -#define TCSETXF 0x5434 -#define TCSETXW 0x5435 - -#define FIONCLEX 0x5450 -#define FIOCLEX 0x5451 -#define FIOASYNC 0x5452 -#define TIOCSERCONFIG 0x5453 -#define TIOCSERGWILD 0x5454 -#define TIOCSERSWILD 0x5455 -#define TIOCGLCKTRMIOS 0x5456 -#define TIOCSLCKTRMIOS 0x5457 -#define TIOCSERGSTRUCT 0x5458 -#define TIOCSERGETLSR 0x5459 -#define TIOCSERGETMULTI 0x545A -#define TIOCSERSETMULTI 0x545B - -#define TIOCMIWAIT 0x545C -#define TIOCGICOUNT 0x545D -#define TIOCGHAYESESP 0x545E -#define TIOCSHAYESESP 0x545F -#define FIOQSIZE 0x5460 - -#define TIOCPKT_DATA 0 -#define TIOCPKT_FLUSHREAD 1 -#define TIOCPKT_FLUSHWRITE 2 -#define TIOCPKT_STOP 4 -#define TIOCPKT_START 8 -#define TIOCPKT_NOSTOP 16 -#define TIOCPKT_DOSTOP 32 -#define TIOCPKT_IOCTL 64 - -#define TIOCSER_TEMT 0x01 - -struct winsize { - unsigned short ws_row; - unsigned short ws_col; - unsigned short ws_xpixel; - unsigned short ws_ypixel; -}; - -#define TIOCM_LE 0x001 -#define TIOCM_DTR 0x002 -#define TIOCM_RTS 0x004 -#define TIOCM_ST 0x008 -#define TIOCM_SR 0x010 -#define TIOCM_CTS 0x020 -#define TIOCM_CAR 0x040 -#define TIOCM_RNG 0x080 -#define TIOCM_DSR 0x100 -#define TIOCM_CD TIOCM_CAR -#define TIOCM_RI TIOCM_RNG -#define TIOCM_OUT1 0x2000 -#define TIOCM_OUT2 0x4000 -#define TIOCM_LOOP 0x8000 -#define TIOCM_MODEM_BITS TIOCM_OUT2 - -#define N_TTY 0 -#define N_SLIP 1 -#define N_MOUSE 2 -#define N_PPP 3 -#define N_STRIP 4 -#define N_AX25 5 -#define N_X25 6 -#define N_6PACK 7 -#define N_MASC 8 -#define N_R3964 9 -#define N_PROFIBUS_FDL 10 -#define N_IRDA 11 -#define N_SMSBLOCK 12 -#define N_HDLC 13 -#define N_SYNC_PPP 14 -#define N_HCI 15 - -#define FIOSETOWN 0x8901 -#define SIOCSPGRP 0x8902 -#define FIOGETOWN 0x8903 -#define SIOCGPGRP 0x8904 -#define SIOCATMARK 0x8905 -#define SIOCGSTAMP 0x8906 - -#define SIOCADDRT 0x890B -#define SIOCDELRT 0x890C -#define SIOCRTMSG 0x890D - -#define SIOCGIFNAME 0x8910 -#define SIOCSIFLINK 0x8911 -#define SIOCGIFCONF 0x8912 -#define SIOCGIFFLAGS 0x8913 -#define SIOCSIFFLAGS 0x8914 -#define SIOCGIFADDR 0x8915 -#define SIOCSIFADDR 0x8916 -#define SIOCGIFDSTADDR 0x8917 -#define SIOCSIFDSTADDR 0x8918 -#define SIOCGIFBRDADDR 0x8919 -#define SIOCSIFBRDADDR 0x891a -#define SIOCGIFNETMASK 0x891b -#define SIOCSIFNETMASK 0x891c -#define SIOCGIFMETRIC 0x891d -#define SIOCSIFMETRIC 0x891e -#define SIOCGIFMEM 0x891f -#define SIOCSIFMEM 0x8920 -#define SIOCGIFMTU 0x8921 -#define SIOCSIFMTU 0x8922 -#define SIOCSIFHWADDR 0x8924 -#define SIOCGIFENCAP 0x8925 -#define SIOCSIFENCAP 0x8926 -#define SIOCGIFHWADDR 0x8927 -#define SIOCGIFSLAVE 0x8929 -#define SIOCSIFSLAVE 0x8930 -#define SIOCADDMULTI 0x8931 -#define SIOCDELMULTI 0x8932 -#define SIOCGIFINDEX 0x8933 -#define SIOGIFINDEX SIOCGIFINDEX -#define SIOCSIFPFLAGS 0x8934 -#define SIOCGIFPFLAGS 0x8935 -#define SIOCDIFADDR 0x8936 -#define SIOCSIFHWBROADCAST 0x8937 -#define SIOCGIFCOUNT 0x8938 - -#define SIOCGIFBR 0x8940 -#define SIOCSIFBR 0x8941 - -#define SIOCGIFTXQLEN 0x8942 -#define SIOCSIFTXQLEN 0x8943 - -#define SIOCDARP 0x8953 -#define SIOCGARP 0x8954 -#define SIOCSARP 0x8955 - -#define SIOCDRARP 0x8960 -#define SIOCGRARP 0x8961 -#define SIOCSRARP 0x8962 - -#define SIOCGIFMAP 0x8970 -#define SIOCSIFMAP 0x8971 - -#define SIOCADDDLCI 0x8980 -#define SIOCDELDLCI 0x8981 - -#define SIOCDEVPRIVATE 0x89F0 -#define SIOCPROTOPRIVATE 0x89E0 diff --git a/05/musl-final/arch/x86_64/bits/ipc.h b/05/musl-final/arch/x86_64/bits/ipc.h deleted file mode 100644 index 04fbefe..0000000 --- a/05/musl-final/arch/x86_64/bits/ipc.h +++ /dev/null @@ -1,25 +0,0 @@ -#define IPC_CREAT 01000 -#define IPC_EXCL 02000 -#define IPC_NOWAIT 04000 - -#define IPC_RMID 0 -#define IPC_SET 1 -#define IPC_STAT 2 -#ifdef _GNU_SOURCE -# define IPC_INFO 3 /* See ipcs. */ -#endif - -#define IPC_PRIVATE ((key_t) 0) - -struct ipc_perm -{ - key_t key; - uid_t uid; - gid_t gid; - uid_t cuid; - gid_t cgid; - mode_t mode; - int seq; - long __pad1; - long __pad2; -}; diff --git a/05/musl-final/arch/x86_64/bits/limits.h b/05/musl-final/arch/x86_64/bits/limits.h deleted file mode 100644 index 4654489..0000000 --- a/05/musl-final/arch/x86_64/bits/limits.h +++ /dev/null @@ -1,34 +0,0 @@ -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) -#define PIPE_BUF 4096 -#define PAGESIZE 4096 -#define PAGE_SIZE PAGESIZE -#define FILESIZEBITS 64 -#define NAME_MAX 255 -#define SYMLINK_MAX 255 -#define PATH_MAX 4096 -#define NZERO 20 -#define NGROUPS_MAX 32 -#define ARG_MAX 131072 -#define IOV_MAX 1024 -#define SYMLOOP_MAX 40 -#define WORD_BIT 64 -#define LONG_BIT 64 -#endif - -#define SHRT_MIN (-1-0x7fff) -#define SHRT_MAX 0x7fff -#define USHRT_MAX 0xffff - -#define INT_MIN (-1-0x7fffffff) -#define INT_MAX 0x7fffffff -#define UINT_MAX 0xffffffffU - -#define LONG_MIN (-1-0x7fffffffffffffffL) -#define LONG_MAX 0x7fffffffffffffffL -#define ULONG_MAX 0xffffffffffffffffUL - -#define LLONG_MIN (-1-0x7fffffffffffffffLL) -#define LLONG_MAX 0x7fffffffffffffffLL -#define ULLONG_MAX 0xffffffffffffffffULL - diff --git a/05/musl-final/arch/x86_64/bits/mman.h b/05/musl-final/arch/x86_64/bits/mman.h deleted file mode 100644 index cd6cb84..0000000 --- a/05/musl-final/arch/x86_64/bits/mman.h +++ /dev/null @@ -1,50 +0,0 @@ -#define MAP_FAILED ((void *) -1) - -#define PROT_NONE 0 -#define PROT_READ 1 -#define PROT_WRITE 2 -#define PROT_EXEC 4 -#define PROT_GROWSDOWN 0x01000000 -#define PROT_GROWSUP 0x02000000 - -#define MAP_SHARED 0x01 -#define MAP_PRIVATE 0x02 -#define MAP_FIXED 0x10 - -/* linux extensions */ -#define MAP_TYPE 0x0f -#define MAP_FILE 0x00 -#define MAP_ANON 0x20 -#define MAP_ANONYMOUS MAP_ANON -#define MAP_32BIT 0x40 - -#define MADV_NORMAL 0 -#define MADV_RANDOM 1 -#define MADV_SEQUENTIAL 2 -#define MADV_WILLNEED 3 -#define MADV_DONTNEED 4 -#define MADV_REMOVE 9 -#define MADV_DONTFORK 10 -#define MADV_DOFORK 11 -#define MADV_MERGEABLE 12 -#define MADV_UNMERGEABLE 13 -#define MADV_HUGEPAGE 14 -#define MADV_NOHUGEPAGE 15 -#define MADV_HWPOISON 100 - -#define POSIX_MADV_NORMAL 0 -#define POSIX_MADV_RANDOM 1 -#define POSIX_MADV_SEQUENTIAL 2 -#define POSIX_MADV_WILLNEED 3 -#define POSIX_MADV_DONTNEED 0 - -#define MS_ASYNC 1 -#define MS_INVALIDATE 2 -#define MS_SYNC 4 - -#define MCL_CURRENT 1 -#define MCL_FUTURE 2 - -/* linux extensions */ -#define MREMAP_MAYMOVE 1 -#define MREMAP_FIXED 2 diff --git a/05/musl-final/arch/x86_64/bits/posix.h b/05/musl-final/arch/x86_64/bits/posix.h deleted file mode 100644 index d9f01fd..0000000 --- a/05/musl-final/arch/x86_64/bits/posix.h +++ /dev/null @@ -1,2 +0,0 @@ -#define _POSIX_V6_LP64_OFF64 1 -#define _POSIX_V6_LP64_OFF64 1 diff --git a/05/musl-final/arch/x86_64/bits/pthread.h b/05/musl-final/arch/x86_64/bits/pthread.h deleted file mode 100644 index 7d19065..0000000 --- a/05/musl-final/arch/x86_64/bits/pthread.h +++ /dev/null @@ -1,6 +0,0 @@ -struct __ptcb { - long __jb[7]; - int __dummy; - struct __ptcb *__next; - void *__ptrs[3]; -}; diff --git a/05/musl-final/arch/x86_64/bits/reg.h b/05/musl-final/arch/x86_64/bits/reg.h deleted file mode 100644 index a4df04c..0000000 --- a/05/musl-final/arch/x86_64/bits/reg.h +++ /dev/null @@ -1,29 +0,0 @@ -#undef __WORDSIZE -#define __WORDSIZE 64 -#define R15 0 -#define R14 1 -#define R13 2 -#define R12 3 -#define RBP 4 -#define RBX 5 -#define R11 6 -#define R10 7 -#define R9 8 -#define R8 9 -#define RAX 10 -#define RCX 11 -#define RDX 12 -#define RSI 13 -#define RDI 14 -#define ORIG_RAX 15 -#define RIP 16 -#define CS 17 -#define EFLAGS 18 -#define RSP 19 -#define SS 20 -#define FS_BASE 21 -#define GS_BASE 22 -#define DS 23 -#define ES 24 -#define FS 25 -#define GS 26 diff --git a/05/musl-final/arch/x86_64/bits/setjmp.h b/05/musl-final/arch/x86_64/bits/setjmp.h deleted file mode 100644 index c5b9e4a..0000000 --- a/05/musl-final/arch/x86_64/bits/setjmp.h +++ /dev/null @@ -1 +0,0 @@ -typedef unsigned long jmp_buf [9]; diff --git a/05/musl-final/arch/x86_64/bits/shm.h b/05/musl-final/arch/x86_64/bits/shm.h deleted file mode 100644 index bc95a1c..0000000 --- a/05/musl-final/arch/x86_64/bits/shm.h +++ /dev/null @@ -1,24 +0,0 @@ -#define SHMLBA 4096 - -#define SHM_RDONLY 010000 -#define SHM_RND 020000 -#define SHM_REMAP 040000 -#define SHM_EXEC 0100000 - -/* linux extensions */ -#define SHM_LOCK 11 -#define SHM_UNLOCK 12 - -struct shmid_ds -{ - struct ipc_perm shm_perm; - size_t shm_segsz; - time_t shm_atime; - time_t shm_dtime; - time_t shm_ctime; - pid_t shm_cpid; - pid_t shm_lpid; - unsigned long shm_nattch; - unsigned long __pad1; - unsigned long __pad2; -}; diff --git a/05/musl-final/arch/x86_64/bits/signal.h b/05/musl-final/arch/x86_64/bits/signal.h deleted file mode 100644 index 64ece19..0000000 --- a/05/musl-final/arch/x86_64/bits/signal.h +++ /dev/null @@ -1,115 +0,0 @@ -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) - -struct __siginfo -{ - int si_signo; - int si_errno; - int si_code; - union - { - int __pad[(128 - 4*sizeof(int)) / sizeof(int)]; - struct { - pid_t si_pid; - uid_t si_uid; - } __kill; - struct { - void *si_timerid; - int si_overrun; - char __pad[sizeof(uid_t) - sizeof(int)]; - union sigval si_sigval; - int si_private; - } __timer; - struct { - pid_t si_pid; - uid_t si_uid; - union sigval si_sigval; - } __rt; - struct { - pid_t si_pid; - uid_t si_uid; - int si_status; - clock_t si_utime; - clock_t si_stime; - } __sigchld; - struct { - void *si_addr; - short addr_lsb; - } __sigfault; - struct { - long si_band; - int si_fd; - } __sigpoll; - } __si_fields; -}; - -#define si_pid __si_fields.__sigchld.si_pid -#define si_uid __si_fields.__sigchld.si_uid -#define si_status __si_fields.__sigchld.si_status -#define si_utime __si_fields.__sigchld.si_utime -#define si_stime __si_fields.__sigchld.si_stime -#define si_value __si_fields.__rt.si_sigval -#define si_addr __si_fields.__sigfault.si_addr -#define si_band __si_fields.__sigpoll.si_band - -#define SA_NOCLDSTOP 1 -#define SA_NOCLDWAIT 2 -#define SA_SIGINFO 4 -#define SA_ONSTACK 0x08000000 -#define SA_RESTART 0x10000000 -#define SA_NODEFER 0x40000000 -#define SA_RESETHAND 0x80000000 -#define SA_RESTORER 0x04000000 - -#define SS_ONSTACK 1 -#define SS_DISABLE 2 - -#define SIG_BLOCK 0 -#define SIG_UNBLOCK 1 -#define SIG_SETMASK 2 - -#define SIG_HOLD ((void (*)(int)) 2) - -#endif - -#ifdef _GNU_SOURCE -#define NSIG 64 -#endif - -#define SIG_ERR ((void (*)(int))-1) -#define SIG_DFL ((void (*)(int)) 0) -#define SIG_IGN ((void (*)(int)) 1) - -#define SIGHUP 1 -#define SIGINT 2 -#define SIGQUIT 3 -#define SIGILL 4 -#define SIGTRAP 5 -#define SIGABRT 6 -#define SIGBUS 7 -#define SIGFPE 8 -#define SIGKILL 9 -#define SIGUSR1 10 -#define SIGSEGV 11 -#define SIGUSR2 12 -#define SIGPIPE 13 -#define SIGALRM 14 -#define SIGTERM 15 -#define SIGSTKFLT 16 -#define SIGCHLD 17 -#define SIGCONT 18 -#define SIGSTOP 19 -#define SIGTSTP 20 -#define SIGTTIN 21 -#define SIGTTOU 22 -#define SIGURG 23 -#define SIGXCPU 24 -#define SIGXFSZ 25 -#define SIGVTALRM 26 -#define SIGPROF 27 -#define SIGWINCH 28 -#define SIGIO 29 -#define SIGPOLL 29 -#define SIGPWR 30 -#define SIGSYS 31 -#define SIGUNUSED SIGSYS diff --git a/05/musl-final/arch/x86_64/bits/socket.h b/05/musl-final/arch/x86_64/bits/socket.h deleted file mode 100644 index b323062..0000000 --- a/05/musl-final/arch/x86_64/bits/socket.h +++ /dev/null @@ -1,210 +0,0 @@ -struct msghdr -{ - void *msg_name; - socklen_t msg_namelen; - struct iovec *msg_iov; - int msg_iovlen; - void *msg_control; - socklen_t msg_controllen; - int msg_flags; -}; - -struct cmsghdr -{ - socklen_t cmsg_len; - int cmsg_level; - int cmsg_type; -}; - -struct ucred -{ - pid_t pid; - uid_t uid; - gid_t gid; -}; - -struct linger -{ - int l_onoff; - int l_linger; -}; - -#define SHUT_RD 0 -#define SHUT_WD 1 -#define SHUT_RDWR 2 - -#define SOCK_STREAM 1 -#define SOCK_DGRAM 2 -#define SOCK_RAW 3 -#define SOCK_RDM 4 -#define SOCK_SEQPACKET 5 -#define SOCK_DCCP 6 -#define SOCK_PACKET 10 - -/* linux extensions */ -#define SOCK_CLOEXEC 02000000 -#define SOCK_NONBLOCK 04000 - -#define PF_UNSPEC 0 -#define PF_LOCAL 1 -#define PF_UNIX PF_LOCAL -#define PF_FILE PF_LOCAL -#define PF_INET 2 -#define PF_AX25 3 -#define PF_IPX 4 -#define PF_APPLETALK 5 -#define PF_NETROM 6 -#define PF_BRIDGE 7 -#define PF_ATMPVC 8 -#define PF_X25 9 -#define PF_INET6 10 -#define PF_ROSE 11 -#define PF_DECnet 12 -#define PF_NETBEUI 13 -#define PF_SECURITY 14 -#define PF_KEY 15 -#define PF_NETLINK 16 -#define PF_ROUTE PF_NETLINK -#define PF_PACKET 17 -#define PF_ASH 18 -#define PF_ECONET 19 -#define PF_ATMSVC 20 -#define PF_SNA 22 -#define PF_IRDA 23 -#define PF_PPPOX 24 -#define PF_WANPIPE 25 -#define PF_BLUETOOTH 31 -#define PF_IUCV 32 -#define PF_RXRPC 33 -#define PF_ISDN 34 -#define PF_PHONET 35 -#define PF_IEEE802154 36 -#define PF_CAIF 37 -#define PF_ALG 38 -#define PF_MAX 39 - -#define AF_UNSPEC PF_UNSPEC -#define AF_LOCAL PF_LOCAL -#define AF_UNIX AF_LOCAL -#define AF_FILE AF_LOCAL -#define AF_INET PF_INET -#define AF_AX25 PF_AX25 -#define AF_IPX PF_IPX -#define AF_APPLETALK PF_APPLETALK -#define AF_NETROM PF_NETROM -#define AF_BRIDGE PF_BRIDGE -#define AF_ATMPVC PF_ATMPVC -#define AF_X25 PF_X25 -#define AF_INET6 PF_INET6 -#define AF_ROSE PF_ROSE -#define AF_DECnet PF_DECnet -#define AF_NETBEUI PF_NETBEUI -#define AF_SECURITY PF_SECURITY -#define AF_KEY PF_KEY -#define AF_NETLINK PF_NETLINK -#define AF_ROUTE AF_NETLINK -#define AF_PACKET PF_PACKET -#define AF_ASH PF_ASH -#define AF_ECONET PF_ECONET -#define AF_ATMSVC PF_ATMSVC -#define AF_SNA PF_SNA -#define AF_IRDA PF_IRDA -#define AF_PPPOX PF_PPPOX -#define AF_WANPIPE PF_WANPIPE -#define AF_BLUETOOTH PF_BLUETOOTH -#define AF_IUCV PF_IUCV -#define AF_RXRPC PF_RXRPC -#define AF_ISDN PF_ISDN -#define AF_PHONET PF_PHONET -#define AF_IEEE802154 PF_IEEE802154 -#define AF_CAIF PF_CAIF -#define AF_ALG PF_ALG -#define AF_MAX PF_MAX - -#define SO_DEBUG 1 -#define SO_REUSEADDR 2 -#define SO_TYPE 3 -#define SO_ERROR 4 -#define SO_DONTROUTE 5 -#define SO_BROADCAST 6 -#define SO_SNDBUF 7 -#define SO_RCVBUF 8 -#define SO_KEEPALIVE 9 -#define SO_OOBINLINE 10 -#define SO_NO_CHECK 11 -#define SO_PRIORITY 12 -#define SO_LINGER 13 -#define SO_BSDCOMPAT 14 -#define SO_REUSEPORT 15 -#define SO_PASSCRED 16 -#define SO_PEERCRED 17 -#define SO_RCVLOWAT 18 -#define SO_SNDLOWAT 19 -#define SO_RCVTIMEO 20 -#define SO_SNDTIMEO 21 - -#define SO_SECURITY_AUTHENTICATION 22 -#define SO_SECURITY_ENCRYPTION_TRANSPORT 23 -#define SO_SECURITY_ENCRYPTION_NETWORK 24 - -#define SO_BINDTODEVICE 25 - -#define SO_ATTACH_FILTER 26 -#define SO_DETACH_FILTER 27 - -#define SO_PEERNAME 28 -#define SO_TIMESTAMP 29 -#define SCM_TIMESTAMP SO_TIMESTAMP - -#define SO_ACCEPTCONN 30 - -#define SOL_SOCKET 1 - -/* ??? */ -#define SOL_RAW 255 -#define SOL_DECNET 261 -#define SOL_X25 262 -#define SOL_PACKET 263 -#define SOL_ATM 264 -#define SOL_AAL 265 -#define SOL_IRDA 266 - -#define SOMAXCONN 128 - -#define MSG_OOB 0x0001 -#define MSG_PEEK 0x0002 -#define MSG_DONTROUTE 0x0004 -#define MSG_CTRUNC 0x0008 -#define MSG_PROXY 0x0010 -#define MSG_TRUNC 0x0020 -#define MSG_DONTWAIT 0x0040 -#define MSG_EOR 0x0080 -#define MSG_WAITALL 0x0100 -#define MSG_FIN 0x0200 -#define MSD_SYN 0x0400 -#define MSG_CONFIRM 0x0800 -#define MSG_RST 0x1000 -#define MSG_ERRQUEUE 0x2000 -#define MSG_NOSIGNAL 0x4000 -#define MSG_MORE 0x8000 -#define MSG_WAITFORONE 0x10000 -#define MSG_CMSG_CLOEXEC 0x40000000 - -/* Internal use only!! to make CMSG_NXTHDR definition readable by mortals */ -#define __CMSG_LEN(cmsg) (((cmsg)->cmsg_len + sizeof(long) - 1) & ~(long)(sizeof(long) - 1)) -#define __CMSG_NEXT(cmsg) ((unsigned char *)(cmsg) + __CMSG_LEN(cmsg)) -#define __MHDR_END(mhdr) ((unsigned char *)(mhdr)->msg_control + (mhdr)->msg_controllen) - -#define CMSG_DATA(cmsg) ((unsigned char *) (((struct cmsghdr *)(cmsg)) + 1)) -#define CMSG_NXTHDR(mhdr, cmsg) ((cmsg)->cmsg_len < sizeof (struct cmsghdr) ? (struct cmsghdr *)0 : \ - (__CMSG_NEXT(cmsg) + sizeof (struct cmsghdr) >= __MHDR_END(mhdr) ? (struct cmsghdr *)0 : \ - ((struct cmsghdr *)__CMSG_NEXT(cmsg)))) -#define CMSG_FIRSTHDR(mhdr) ((size_t) (mhdr)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (mhdr)->msg_control : (struct cmsghdr *) 0) - -/* Are these valid? */ -#define CMSG_ALIGN(len) (((len) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)) -#define CMSG_SPACE(len) (CMSG_ALIGN (len) + CMSG_ALIGN (sizeof (struct cmsghdr))) -#define CMSG_LEN(len) (CMSG_ALIGN (sizeof (struct cmsghdr)) + (len)) - -#define SCM_RIGHTS 0x01 -#define SCM_CREDENTIALS 0x02 diff --git a/05/musl-final/arch/x86_64/bits/stat.h b/05/musl-final/arch/x86_64/bits/stat.h deleted file mode 100644 index 64dab33..0000000 --- a/05/musl-final/arch/x86_64/bits/stat.h +++ /dev/null @@ -1,42 +0,0 @@ -/* copied from kernel definition, but with padding replaced - * by the corresponding correctly-sized userspace types. */ - -struct stat { - unsigned long st_dev; - ino_t st_ino; - nlink_t st_nlink; - - mode_t st_mode; - uid_t st_uid; - gid_t st_gid; - unsigned int __pad0; - dev_t st_rdev; - off_t st_size; - blksize_t st_blksize; - blkcnt_t st_blocks; - - struct timespec st_atim; - struct timespec st_mtim; - struct timespec st_ctim; - long __unused[3]; -}; - -struct stat64 { - unsigned long st_dev; - ino_t st_ino; - nlink_t st_nlink; - - mode_t st_mode; - uid_t st_uid; - gid_t st_gid; - unsigned int __pad0; - dev_t st_rdev; - off_t st_size; - blksize_t st_blksize; - blkcnt_t st_blocks; - - struct timespec st_atim; - struct timespec st_mtim; - struct timespec st_ctim; - long __unused[3]; -}; diff --git a/05/musl-final/arch/x86_64/bits/statfs.h b/05/musl-final/arch/x86_64/bits/statfs.h deleted file mode 100644 index 51bf8a5..0000000 --- a/05/musl-final/arch/x86_64/bits/statfs.h +++ /dev/null @@ -1,15 +0,0 @@ -struct statvfs { - unsigned long f_type; - unsigned long f_bsize; - fsblkcnt_t f_blocks; - fsblkcnt_t f_bfree; - fsblkcnt_t f_bavail; - fsfilcnt_t f_files; - fsfilcnt_t f_ffree; - unsigned long f_fsid; - unsigned long f_namemax; - unsigned long f_frsize; - fsfilcnt_t f_favail; - unsigned long f_flag; - unsigned long __reserved[2]; -}; diff --git a/05/musl-final/arch/x86_64/bits/stdarg.h b/05/musl-final/arch/x86_64/bits/stdarg.h deleted file mode 100644 index 10ce733..0000000 --- a/05/musl-final/arch/x86_64/bits/stdarg.h +++ /dev/null @@ -1,79 +0,0 @@ -#ifndef _STDARG_H -#define _STDARG_H - -#ifdef __x86_64__ -#ifndef _WIN64 - -//This should be in sync with the declaration on our lib/libtcc1.c -/* GCC compatible definition of va_list. */ -typedef struct { - unsigned int gp_offset; - unsigned int fp_offset; - union { - unsigned int overflow_offset; - char *overflow_arg_area; - }; - char *reg_save_area; -} __va_list_struct; - -typedef __va_list_struct va_list[1]; - -void __va_start(__va_list_struct *ap, void *fp); -void *__va_arg(__va_list_struct *ap, int arg_type, int size, int align); - -#define va_start(ap, last) __va_start(ap, __builtin_frame_address(0)) -#define va_arg(ap, type) \ - (*(type *)(__va_arg(ap, __builtin_va_arg_types(type), sizeof(type), __alignof__(type)))) -#define va_copy(dest, src) (*(dest) = *(src)) -#define va_end(ap) - -/* avoid conflicting definition for va_list on Macs. */ -#define _VA_LIST_T - -#else /* _WIN64 */ -typedef char *va_list; -#define va_start(ap,last) __builtin_va_start(ap,last) -#define va_arg(ap, t) ((sizeof(t) > 8 || (sizeof(t) & (sizeof(t) - 1))) \ - ? **(t **)((ap += 8) - 8) : *(t *)((ap += 8) - 8)) -#define va_copy(dest, src) ((dest) = (src)) -#define va_end(ap) -#endif - -#elif __arm__ -typedef char *va_list; -#define _tcc_alignof(type) ((int)&((struct {char c;type x;} *)0)->x) -#define _tcc_align(addr,type) (((unsigned)addr + _tcc_alignof(type) - 1) \ - & ~(_tcc_alignof(type) - 1)) -#define va_start(ap,last) ap = ((char *)&(last)) + ((sizeof(last)+3)&~3) -#define va_arg(ap,type) (ap = (void *) ((_tcc_align(ap,type)+sizeof(type)+3) \ - &~3), *(type *)(ap - ((sizeof(type)+3)&~3))) -#define va_copy(dest, src) (dest) = (src) -#define va_end(ap) - -#elif defined(__aarch64__) -typedef struct { - void *__stack; - void *__gr_top; - void *__vr_top; - int __gr_offs; - int __vr_offs; -} va_list; -#define va_start(ap, last) __va_start(ap, last) -#define va_arg(ap, type) __va_arg(ap, type) -#define va_end(ap) -#define va_copy(dest, src) ((dest) = (src)) - -#else /* __i386__ */ -typedef char *va_list; -/* only correct for i386 */ -#define va_start(ap,last) ap = ((char *)&(last)) + ((sizeof(last)+3)&~3) -#define va_arg(ap,type) (ap += (sizeof(type)+3)&~3, *(type *)(ap - ((sizeof(type)+3)&~3))) -#define va_copy(dest, src) (dest) = (src) -#define va_end(ap) -#endif - -/* fix a buggy dependency on GCC in libio.h */ -typedef va_list __gnuc_va_list; -#define _VA_LIST_DEFINED - -#endif /* _STDARG_H */ diff --git a/05/musl-final/arch/x86_64/bits/stdint.h b/05/musl-final/arch/x86_64/bits/stdint.h deleted file mode 100644 index 878e4de..0000000 --- a/05/musl-final/arch/x86_64/bits/stdint.h +++ /dev/null @@ -1,23 +0,0 @@ -#define INT_FAST8_MIN INT8_MIN -#define INT_FAST16_MIN INT32_MIN -#define INT_FAST32_MIN INT32_MIN -#define INT_FAST64_MIN INT64_MIN - -#define INT_FAST8_MAX INT8_MAX -#define INT_FAST16_MAX INT32_MAX -#define INT_FAST32_MAX INT32_MAX -#define INT_FAST64_MAX INT64_MAX - -#define UINT_FAST8_MAX UINT8_MAX -#define UINT_FAST16_MAX UINT32_MAX -#define UINT_FAST32_MAX UINT32_MAX -#define UINT_FAST64_MAX UINT64_MAX - -#define INTPTR_MIN INT64_MIN -#define INTPTR_MAX INT64_MAX -#define UINTPTR_MAX UINT64_MAX -#define PTRDIFF_MIN INT64_MIN -#define PTRDIFF_MAX INT64_MAX -#define SIG_ATOMIC_MIN INT64_MIN -#define SIG_ATOMIC_MAX INT64_MAX -#define SIZE_MAX UINT64_MAX diff --git a/05/musl-final/arch/x86_64/bits/sysmacros.h b/05/musl-final/arch/x86_64/bits/sysmacros.h deleted file mode 100644 index da29022..0000000 --- a/05/musl-final/arch/x86_64/bits/sysmacros.h +++ /dev/null @@ -1,7 +0,0 @@ -#define major(x) (((x) >> 8) & 0xff) -#define minor(x) ((x) & 0xff) -#define makedev(x,y) (((x)<<8)|((y)&0xff)) - -//#define makedev(x,y) \ -// ((x)*0x100000001ULL)&(0xfffffffffff0) -// ((y)*0x1001 & 0xffff0ff) diff --git a/05/musl-final/arch/x86_64/bits/tcp.h b/05/musl-final/arch/x86_64/bits/tcp.h deleted file mode 100644 index 923231b..0000000 --- a/05/musl-final/arch/x86_64/bits/tcp.h +++ /dev/null @@ -1 +0,0 @@ -#define TCP_NODELAY 1 diff --git a/05/musl-final/arch/x86_64/bits/termios.h b/05/musl-final/arch/x86_64/bits/termios.h deleted file mode 100644 index 316baeb..0000000 --- a/05/musl-final/arch/x86_64/bits/termios.h +++ /dev/null @@ -1,158 +0,0 @@ -struct termios -{ - tcflag_t c_iflag; - tcflag_t c_oflag; - tcflag_t c_cflag; - tcflag_t c_lflag; - cc_t c_line; - cc_t c_cc[NCCS]; - speed_t __c_ispeed; - speed_t __c_ospeed; -}; - -#define VINTR 0 -#define VQUIT 1 -#define VERASE 2 -#define VKILL 3 -#define VEOF 4 -#define VTIME 5 -#define VMIN 6 -#define VSWTC 7 -#define VSTART 8 -#define VSTOP 9 -#define VSUSP 10 -#define VEOL 11 -#define VREPRINT 12 -#define VDISCARD 13 -#define VWERASE 14 -#define VLNEXT 15 -#define VEOL2 16 - -#define IGNBRK 0000001 -#define BRKINT 0000002 -#define IGNPAR 0000004 -#define PARMRK 0000010 -#define INPCK 0000020 -#define ISTRIP 0000040 -#define INLCR 0000100 -#define IGNCR 0000200 -#define ICRNL 0000400 -#define IUCLC 0001000 -#define IXON 0002000 -#define IXANY 0004000 -#define IXOFF 0010000 -#define IMAXBEL 0020000 - -#define OPOST 0000001 -#define OLCUC 0000002 -#define ONLCR 0000004 -#define OCRNL 0000010 -#define ONOCR 0000020 -#define ONLRET 0000040 -#define OFILL 0000100 -#define OFDEL 0000200 -#define NLDLY 0000400 -#define NL0 0000000 -#define NL1 0000400 -#define CRDLY 0003000 -#define CR0 0000000 -#define CR1 0001000 -#define CR2 0002000 -#define CR3 0003000 -#define TABDLY 0014000 -#define TAB0 0000000 -#define TAB1 0004000 -#define TAB2 0010000 -#define TAB3 0014000 -#define BSDLY 0020000 -#define BS0 0000000 -#define BS1 0020000 -#define FFDLY 0100000 -#define FF0 0000000 -#define FF1 0100000 - -#define VTDLY 0040000 -#define VT0 0000000 -#define VT1 0040000 - -/* ?? */ -#define XTABS 0014000 - -#define B0 0000000 -#define B50 0000001 -#define B75 0000002 -#define B110 0000003 -#define B134 0000004 -#define B150 0000005 -#define B200 0000006 -#define B300 0000007 -#define B600 0000010 -#define B1200 0000011 -#define B1800 0000012 -#define B2400 0000013 -#define B4800 0000014 -#define B9600 0000015 -#define B19200 0000016 -#define B38400 0000017 - -#define B57600 0010001 -#define B115200 0010002 -#define B230400 0010003 -#define B460800 0010004 -#define B500000 0010005 -#define B576000 0010006 -#define B921600 0010007 -#define B1000000 0010010 -#define B1152000 0010011 -#define B1500000 0010012 -#define B2000000 0010013 -#define B2500000 0010014 -#define B3000000 0010015 -#define B3500000 0010016 -#define B4000000 0010017 - -#define CBAUD 0010017 - -#define CSIZE 0000060 -#define CS5 0000000 -#define CS6 0000020 -#define CS7 0000040 -#define CS8 0000060 -#define CSTOPB 0000100 -#define CREAD 0000200 -#define PARENB 0000400 -#define PARODD 0001000 -#define HUPCL 0002000 -#define CLOCAL 0004000 - -#define CRTSCTS 020000000000 - -#define ISIG 0000001 -#define ICANON 0000002 -#define ECHO 0000010 -#define ECHOE 0000020 -#define ECHOK 0000040 -#define ECHONL 0000100 -#define NOFLSH 0000200 -#define TOSTOP 0000400 -#define IEXTEN 0100000 - -/* Extensions? */ -#define ECHOCTL 0001000 -#define ECHOPRT 0002000 -#define ECHOKE 0004000 -#define FLUSHO 0010000 -#define PENDIN 0040000 - -#define TCOOFF 0 -#define TCOON 1 -#define TCIOFF 2 -#define TCION 3 - -#define TCIFLUSH 0 -#define TCOFLUSH 1 -#define TCIOFLUSH 2 - -#define TCSANOW 0 -#define TCSADRAIN 1 -#define TCSAFLUSH 2 diff --git a/05/musl-final/arch/x86_64/bits/user.h b/05/musl-final/arch/x86_64/bits/user.h deleted file mode 100644 index 13ff027..0000000 --- a/05/musl-final/arch/x86_64/bits/user.h +++ /dev/null @@ -1,77 +0,0 @@ -#undef __WORDSIZE -#define __WORDSIZE 32 - -struct user_fpregs_struct -{ - long int cwd; - long int swd; - long int twd; - long int fip; - long int fcs; - long int foo; - long int fos; - long int st_space[20]; -}; - -struct user_fpxregs_struct -{ - unsigned short int cwd; - unsigned short int swd; - unsigned short int twd; - unsigned short int fop; - long int fip; - long int fcs; - long int foo; - long int fos; - long int mxcsr; - long int reserved; - long int st_space[32]; - long int xmm_space[32]; - long int padding[56]; -}; - -struct user_regs_struct -{ - long int ebx; - long int ecx; - long int edx; - long int esi; - long int edi; - long int ebp; - long int eax; - long int xds; - long int xes; - long int xfs; - long int xgs; - long int orig_eax; - long int eip; - long int xcs; - long int eflags; - long int esp; - long int xss; -}; - -struct user -{ - struct user_regs_struct regs; - int u_fpvalid; - struct user_fpregs_struct i387; - unsigned long int u_tsize; - unsigned long int u_dsize; - unsigned long int u_ssize; - unsigned long start_code; - unsigned long start_stack; - long int signal; - int reserved; - struct user_regs_struct *u_ar0; - struct user_fpregs_struct *u_fpstate; - unsigned long int magic; - char u_comm[32]; - int u_debugreg[8]; -}; - -#define PAGE_MASK (~(PAGE_SIZE-1)) -#define NBPG PAGE_SIZE -#define UPAGES 1 -#define HOST_TEXT_START_ADDR (u.start_code) -#define HOST_STACK_END_ADDR (u.start_stack + u.u_ssize * NBPG) diff --git a/05/musl-final/arch/x86_64/bits/wait.h b/05/musl-final/arch/x86_64/bits/wait.h deleted file mode 100644 index ae3f101..0000000 --- a/05/musl-final/arch/x86_64/bits/wait.h +++ /dev/null @@ -1,13 +0,0 @@ -#define WNOHANG 1 -#define WUNTRACED 2 - -#define WSTOPPED 2 -#define WEXITED 4 -#define WCONTINUED 8 -#define WNOWAIT 0x1000000 - -#if defined(__XOPEN_SOURCE) || defined(__GNU_SOURCE) -#define P_ALL 0 -#define P_PID 1 -#define P_PGID 2 -#endif diff --git a/05/musl-final/arch/x86_64/bits/wexitstatus.h b/05/musl-final/arch/x86_64/bits/wexitstatus.h deleted file mode 100644 index 34a8023..0000000 --- a/05/musl-final/arch/x86_64/bits/wexitstatus.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef WEXITSTATUS -#define WEXITSTATUS(s) (((s) & 0xff00) >> 8) -#define WTERMSIG(s) ((s) & 0x7f) -#define WSTOPSIG(s) WEXITSTATUS(s) -#define WCOREDUMP(s) ((s) & 0x80) -#define WIFEXITED(s) (!WTERMSIG(s)) -#define WIFSTOPPED(s) (((s) & 0xff) == 0x7f) -#define WIFSIGNALED(s) (!WIFSTOPPED(s) && !WIFEXITED(s)) -#endif diff --git a/05/musl-final/arch/x86_64/pthread_arch.h b/05/musl-final/arch/x86_64/pthread_arch.h deleted file mode 100644 index 40d2679..0000000 --- a/05/musl-final/arch/x86_64/pthread_arch.h +++ /dev/null @@ -1,6 +0,0 @@ -static inline struct pthread *__pthread_self() -{ - struct pthread *self; - __asm__ ("movq %%fs:0,%0" : "=r" (self) ); - return self; -} diff --git a/05/musl-final/arch/x86_64/syscall.h b/05/musl-final/arch/x86_64/syscall.h deleted file mode 100644 index acebd76..0000000 --- a/05/musl-final/arch/x86_64/syscall.h +++ /dev/null @@ -1,433 +0,0 @@ -#ifndef _SYSCALL_H -#define _SYSCALL_H - -#define SYSCALL_LL(x) x, 0 -#define SYSCALL_SIGSET_SIZE 8 - -#if defined(SYSCALL_NORETURN) -static inline long __syscall_ret(unsigned long r) -{ - for(;;); - return 0; -} -#elif defined(SYSCALL_RETURN_ERRNO) -static inline long __syscall_ret(unsigned long r) -{ - return -r; -} -#else -extern long __syscall_ret(unsigned long); -#endif - -// 64: di, si, dx, r10, r8, r9 -// 32: ebx, ecx, edx, esi, edi, ebp - -#define SYSCALL "syscall" - -#if 0 -static inline long syscall0(long n) -{ - unsigned long ret; - __asm__ __volatile__ (SYSCALL : "=a"(ret) : "a"(n) : "rcx", "r11", "memory"); - return __syscall_ret(ret); -} - -static inline long syscall1(long n, long a1) -{ - unsigned long ret; - __asm__ __volatile__ (SYSCALL : "=a"(ret) : "a"(n), "D"(a1) : "rcx", "r11", "memory"); - return __syscall_ret(ret); -} - -static inline long syscall2(long n, long a1, long a2) -{ - unsigned long ret; - __asm__ __volatile__ (SYSCALL : "=a"(ret) : "a"(n), "D"(a1), "S"(a2) - : "rcx", "r11", "memory"); - return __syscall_ret(ret); -} - -static inline long syscall3(long n, long a1, long a2, long a3) -{ - unsigned long ret; - __asm__ __volatile__ (SYSCALL : "=a"(ret) : "a"(n), "D"(a1), "S"(a2), - "d"(a3) : "rcx", "r11", "memory"); - return __syscall_ret(ret); -} - -static inline long syscall4(long n, long a1, long a2, long a3, long a4) -{ - unsigned long ret; - register long r10 __asm__("r10") = a4; - __asm__ __volatile__ (SYSCALL : "=a"(ret) : "a"(n), "D"(a1), "S"(a2), - "d"(a3), "r"(r10): "rcx", "r11", "memory"); - return __syscall_ret(ret); -} - -static inline long syscall5(long n, long a1, long a2, long a3, long a4, - long a5) -{ - unsigned long ret; - register long r10 __asm__("r10") = a4; - register long r8 __asm__("r8") = a5; - __asm__ __volatile__ (SYSCALL : "=a"(ret) : "a"(n), "D"(a1), "S"(a2), - "d"(a3), "r"(r10), "r"(r8) : "rcx", "r11", "memory"); - return __syscall_ret(ret); -} - - -static inline long syscall6(long n, long a1, long a2, long a3, long a4, - long a5, long a6) -{ - unsigned long ret; - register long r10 __asm__("r10") = a4; - register long r8 __asm__("r8") = a5; - register long r9 __asm__("r9") = a6; - __asm__ __volatile__ (SYSCALL : "=a"(ret) : "a"(n), "D"(a1), "S"(a2), - "d"(a3), "r"(r10), "r"(r8), "r"(r9) : "rcx", "r11", "memory"); - return __syscall_ret(ret); -} -#else -extern long syscall0(long); -extern long syscall1(long, long); -extern long syscall2(long, long, long); -extern long syscall3(long, long, long, long); -extern long syscall4(long, long, long, long, long); -extern long syscall5(long, long, long, long, long, long); -extern long syscall6(long, long, long, long, long, long, long); -#endif - -#define __NR_read 0 -#define __NR_write 1 -#define __NR_open 2 -#define __NR_close 3 -#define __NR_stat 4 -#define __NR_fstat 5 -#define __NR_lstat 6 -#define __NR_poll 7 -#define __NR_lseek 8 -#define __NR_mmap 9 -#define __NR_mprotect 10 -#define __NR_munmap 11 -#define __NR_brk 12 -#define __NR_rt_sigaction 13 -#define __NR_rt_sigprocmask 14 -#define __NR_rt_sigreturn 15 -#define __NR_ioctl 16 -#define __NR_pread64 17 -#define __NR_pwrite64 18 -#define __NR_readv 19 -#define __NR_writev 20 -#define __NR_access 21 -#define __NR_pipe 22 -#define __NR_select 23 -#define __NR_sched_yield 24 -#define __NR_mremap 25 -#define __NR_msync 26 -#define __NR_mincore 27 -#define __NR_madvise 28 -#define __NR_shmget 29 -#define __NR_shmat 30 -#define __NR_shmctl 31 -#define __NR_dup 32 -#define __NR_dup2 33 -#define __NR_pause 34 -#define __NR_nanosleep 35 -#define __NR_getitimer 36 -#define __NR_alarm 37 -#define __NR_setitimer 38 -#define __NR_getpid 39 -#define __NR_sendfile 40 -#define __NR_socket 41 -#define __NR_connect 42 -#define __NR_accept 43 -#define __NR_sendto 44 -#define __NR_recvfrom 45 -#define __NR_sendmsg 46 -#define __NR_recvmsg 47 -#define __NR_shutdown 48 -#define __NR_bind 49 -#define __NR_listen 50 -#define __NR_getsockname 51 -#define __NR_getpeername 52 -#define __NR_socketpair 53 -#define __NR_setsockopt 54 -#define __NR_getsockopt 55 -#define __NR_clone 56 -#define __NR_fork 57 -#define __NR_vfork 58 -#define __NR_execve 59 -#define __NR_exit 60 -#define __NR_wait4 61 -#define __NR_kill 62 -#define __NR_uname 63 -#define __NR_semget 64 -#define __NR_semop 65 -#define __NR_semctl 66 -#define __NR_shmdt 67 -#define __NR_msgget 68 -#define __NR_msgsnd 69 -#define __NR_msgrcv 70 -#define __NR_msgctl 71 -#define __NR_fcntl 72 -#define __NR_flock 73 -#define __NR_fsync 74 -#define __NR_fdatasync 75 -#define __NR_truncate 76 -#define __NR_ftruncate 77 -#define __NR_getdents 78 -#define __NR_getcwd 79 -#define __NR_chdir 80 -#define __NR_fchdir 81 -#define __NR_rename 82 -#define __NR_mkdir 83 -#define __NR_rmdir 84 -#define __NR_creat 85 -#define __NR_link 86 -#define __NR_unlink 87 -#define __NR_symlink 88 -#define __NR_readlink 89 -#define __NR_chmod 90 -#define __NR_fchmod 91 -#define __NR_chown 92 -#define __NR_fchown 93 -#define __NR_lchown 94 -#define __NR_umask 95 -#define __NR_gettimeofday 96 -#define __NR_getrlimit 97 -#define __NR_getrusage 98 -#define __NR_sysinfo 99 -#define __NR_times 100 -#define __NR_ptrace 101 -#define __NR_getuid 102 -#define __NR_syslog 103 -#define __NR_getgid 104 -#define __NR_setuid 105 -#define __NR_setgid 106 -#define __NR_geteuid 107 -#define __NR_getegid 108 -#define __NR_setpgid 109 -#define __NR_getppid 110 -#define __NR_getpgrp 111 -#define __NR_setsid 112 -#define __NR_setreuid 113 -#define __NR_setregid 114 -#define __NR_getgroups 115 -#define __NR_setgroups 116 -#define __NR_setresuid 117 -#define __NR_getresuid 118 -#define __NR_setresgid 119 -#define __NR_getresgid 120 -#define __NR_getpgid 121 -#define __NR_setfsuid 122 -#define __NR_setfsgid 123 -#define __NR_getsid 124 -#define __NR_capget 125 -#define __NR_capset 126 -#define __NR_rt_sigpending 127 -#define __NR_rt_sigtimedwait 128 -#define __NR_rt_sigqueueinfo 129 -#define __NR_rt_sigsuspend 130 -#define __NR_sigaltstack 131 -#define __NR_utime 132 -#define __NR_mknod 133 -#define __NR_uselib 134 -#define __NR_personality 135 -#define __NR_ustat 136 -#define __NR_statfs 137 -#define __NR_fstatfs 138 -#define __NR_sysfs 139 -#define __NR_getpriority 140 -#define __NR_setpriority 141 -#define __NR_sched_setparam 142 -#define __NR_sched_getparam 143 -#define __NR_sched_setscheduler 144 -#define __NR_sched_getscheduler 145 -#define __NR_sched_get_priority_max 146 -#define __NR_sched_get_priority_min 147 -#define __NR_sched_rr_get_interval 148 -#define __NR_mlock 149 -#define __NR_munlock 150 -#define __NR_mlockall 151 -#define __NR_munlockall 152 -#define __NR_vhangup 153 -#define __NR_modify_ldt 154 -#define __NR_pivot_root 155 -#define __NR__sysctl 156 -#define __NR_prctl 157 -#define __NR_arch_prctl 158 -#define __NR_adjtimex 159 -#define __NR_setrlimit 160 -#define __NR_chroot 161 -#define __NR_sync 162 -#define __NR_acct 163 -#define __NR_settimeofday 164 -#define __NR_mount 165 -#define __NR_umount2 166 -#define __NR_swapon 167 -#define __NR_swapoff 168 -#define __NR_reboot 169 -#define __NR_sethostname 170 -#define __NR_setdomainname 171 -#define __NR_iopl 172 -#define __NR_ioperm 173 -#define __NR_create_module 174 -#define __NR_init_module 175 -#define __NR_delete_module 176 -#define __NR_get_kernel_syms 177 -#define __NR_query_module 178 -#define __NR_quotactl 179 -#define __NR_nfsservctl 180 -#define __NR_getpmsg 181 -#define __NR_putpmsg 182 -#define __NR_afs_syscall 183 -#define __NR_tuxcall 184 -#define __NR_security 185 -#define __NR_gettid 186 -#define __NR_readahead 187 -#define __NR_setxattr 188 -#define __NR_lsetxattr 189 -#define __NR_fsetxattr 190 -#define __NR_getxattr 191 -#define __NR_lgetxattr 192 -#define __NR_fgetxattr 193 -#define __NR_listxattr 194 -#define __NR_llistxattr 195 -#define __NR_flistxattr 196 -#define __NR_removexattr 197 -#define __NR_lremovexattr 198 -#define __NR_fremovexattr 199 -#define __NR_tkill 200 -#define __NR_time 201 -#define __NR_futex 202 -#define __NR_sched_setaffinity 203 -#define __NR_sched_getaffinity 204 -#define __NR_set_thread_area 205 -#define __NR_io_setup 206 -#define __NR_io_destroy 207 -#define __NR_io_getevents 208 -#define __NR_io_submit 209 -#define __NR_io_cancel 210 -#define __NR_get_thread_area 211 -#define __NR_lookup_dcookie 212 -#define __NR_epoll_create 213 -#define __NR_epoll_ctl_old 214 -#define __NR_epoll_wait_old 215 -#define __NR_remap_file_pages 216 -#define __NR_getdents64 217 -#define __NR_set_tid_address 218 -#define __NR_restart_syscall 219 -#define __NR_semtimedop 220 -#define __NR_fadvise64 221 -#define __NR_timer_create 222 -#define __NR_timer_settime 223 -#define __NR_timer_gettime 224 -#define __NR_timer_getoverrun 225 -#define __NR_timer_delete 226 -#define __NR_clock_settime 227 -#define __NR_clock_gettime 228 -#define __NR_clock_getres 229 -#define __NR_clock_nanosleep 230 -#define __NR_exit_group 231 -#define __NR_epoll_wait 232 -#define __NR_epoll_ctl 233 -#define __NR_tgkill 234 -#define __NR_utimes 235 -#define __NR_vserver 236 -#define __NR_mbind 237 -#define __NR_set_mempolicy 238 -#define __NR_get_mempolicy 239 -#define __NR_mq_open 240 -#define __NR_mq_unlink 241 -#define __NR_mq_timedsend 242 -#define __NR_mq_timedreceive 243 -#define __NR_mq_notify 244 -#define __NR_mq_getsetattr 245 -#define __NR_kexec_load 246 -#define __NR_waitid 247 -#define __NR_add_key 248 -#define __NR_request_key 249 -#define __NR_keyctl 250 -#define __NR_ioprio_set 251 -#define __NR_ioprio_get 252 -#define __NR_inotify_init 253 -#define __NR_inotify_add_watch 254 -#define __NR_inotify_rm_watch 255 -#define __NR_migrate_pages 256 -#define __NR_openat 257 -#define __NR_mkdirat 258 -#define __NR_mknodat 259 -#define __NR_fchownat 260 -#define __NR_futimesat 261 -#define __NR_newfstatat 262 -#define __NR_unlinkat 263 -#define __NR_renameat 264 -#define __NR_linkat 265 -#define __NR_symlinkat 266 -#define __NR_readlinkat 267 -#define __NR_fchmodat 268 -#define __NR_faccessat 269 -#define __NR_pselect6 270 -#define __NR_ppoll 271 -#define __NR_unshare 272 -#define __NR_set_robust_list 273 -#define __NR_get_robust_list 274 -#define __NR_splice 275 -#define __NR_tee 276 -#define __NR_sync_file_range 277 -#define __NR_vmsplice 278 -#define __NR_move_pages 279 -#define __NR_utimensat 280 -#define __NR_epoll_pwait 281 -#define __NR_signalfd 282 -#define __NR_timerfd_create 283 -#define __NR_eventfd 284 -#define __NR_fallocate 285 -#define __NR_timerfd_settime 286 -#define __NR_timerfd_gettime 287 -#define __NR_accept4 288 -#define __NR_signalfd4 289 -#define __NR_eventfd2 290 -#define __NR_epoll_create1 291 -#define __NR_dup3 292 -#define __NR_pipe2 293 -#define __NR_inotify_init1 294 -#define __NR_preadv 295 -#define __NR_pwritev 296 -#define __NR_rt_tgsigqueueinfo 297 -#define __NR_perf_event_open 298 -#define __NR_recvmmsg 299 -#define __NR_fanotify_init 300 -#define __NR_fanotify_mark 301 -#define __NR_prlimit64 302 - -#undef __NR_fstatat -#undef __NR_pread -#undef __NR_pwrite -#undef __NR_getdents -#define __NR_fstatat __NR_newfstatat -#define __NR_pread __NR_pread64 -#define __NR_pwrite __NR_pwrite64 -#define __NR_getdents __NR_getdents64 - -#undef O_LARGEFILE -#define O_LARGEFILE 0100000 - -#define socketcall(nm, a, b, c, d, e, f) syscall6(__NR_##nm, \ - (long)a, (long)b, (long)c, (long)d, (long)e, (long)f) - -/* the following are needed for iso c functions to use */ -#define __syscall_open(filename, flags, mode) syscall3(__NR_open, (long)(filename), (flags)|O_LARGEFILE, (mode)) -#define __syscall_read(fd, buf, len) syscall3(__NR_read, (fd), (long)(buf), (len)) -#define __syscall_write(fd, buf, len) syscall3(__NR_write, (fd), (long)(buf), (len)) -#define __syscall_close(fd) syscall1(__NR_close, (fd)) -#define __syscall_fcntl(fd, cmd, arg) syscall3(__NR_fcntl, (fd), (cmd), (long)(arg)) -#define __syscall_dup2(old, new) syscall2(__NR_dup2, (old), (new)) -#define __syscall_unlink(path) syscall1(__NR_unlink, (long)(path)) -#define __syscall_getpid() syscall0(__NR_getpid) -#define __syscall_kill(pid,sig) syscall2(__NR_kill, (pid), (sig)) -#define __syscall_sigaction(sig,new,old) syscall4(__NR_rt_sigaction, (sig), (long)(new), (long)(old), SYSCALL_SIGSET_SIZE) -#define __syscall_ioctl(fd,ioc,arg) syscall3(__NR_ioctl, (fd), (ioc), (long)(arg)) -#define __syscall_exit(code) syscall1(__NR_exit, code) - -#endif diff --git a/05/musl-final/config.mak b/05/musl-final/config.mak deleted file mode 100644 index 16a8e73..0000000 --- a/05/musl-final/config.mak +++ /dev/null @@ -1,27 +0,0 @@ -# -# musl config.mak template (original in dist/config.mak) -# - -# Target CPU architecture. Supported values: i386, x86_64 -ARCH = x86_64 - -# Installation prefix. DO NOT use /, /usr, or /usr/local ! -prefix = ../musl-bootstrap-final - -# Installation prefix for musl-gcc compiler wrapper. -exec_prefix = ../musl-bootstrap-final - -# Uncomment if you want to build i386 musl on a 64-bit host -#CFLAGS += -m32 - -CFLAGS += -g - -# Uncomment for smaller code size. -#CFLAGS += -fomit-frame-pointer -mno-accumulate-outgoing-args - -# Uncomment for warnings (as errors). Might need tuning to your gcc version. -#CFLAGS += -Werror -Wall -Wpointer-arith -Wcast-align -Wno-parentheses -Wno-char-subscripts -Wno-uninitialized -Wno-sequence-point -Wno-missing-braces -Wno-unused-value -#CFLAGS += -Wno-pointer-sign - -# Uncomment if you want to build a shared library (experimental). -#LIBC_LIBS += lib/libc.so diff --git a/05/musl-final/crt/crt1.c b/05/musl-final/crt/crt1.c deleted file mode 100644 index e69de29..0000000 diff --git a/05/musl-final/crt/crti.c b/05/musl-final/crt/crti.c deleted file mode 100644 index e69de29..0000000 diff --git a/05/musl-final/crt/crtn.c b/05/musl-final/crt/crtn.c deleted file mode 100644 index e69de29..0000000 diff --git a/05/musl-final/crt/i386/crt1.s b/05/musl-final/crt/i386/crt1.s deleted file mode 100644 index 050adec..0000000 --- a/05/musl-final/crt/i386/crt1.s +++ /dev/null @@ -1,17 +0,0 @@ -.text -.global _start -_start: - xorl %ebp,%ebp - popl %ecx - movl %esp,%eax - andl $-16,%esp - pushl %esp - pushl %esp - pushl %edx - pushl $0 - pushl $0 - pushl %eax - pushl %ecx - pushl $main - call __libc_start_main -.L0: jmp .L0 diff --git a/05/musl-final/crt/x86_64/crt1.s b/05/musl-final/crt/x86_64/crt1.s deleted file mode 100644 index 45cbb9d..0000000 --- a/05/musl-final/crt/x86_64/crt1.s +++ /dev/null @@ -1,16 +0,0 @@ -/* Written 2011 Nicholas J. Kain, released as Public Domain */ -.text -.global _start -_start: - xor %rbp,%rbp /* rbp:undefined -> mark as zero 0 (ABI) */ - mov %rdx,%r9 /* 6th arg: ptr to register with atexit() */ - pop %rsi /* 2nd arg: argc */ - mov %rsp,%rdx /* 3rd arg: argv */ - andq $-16,%rsp /* align stack pointer */ - push %rax /* 8th arg: glibc ABI compatible */ - push %rsp /* 7th arg: glibc ABI compatible */ - xor %r8,%r8 /* 5th arg: always 0 */ - xor %rcx,%rcx /* 4th arg: always 0 */ - mov $main,%rdi /* 1st arg: application entry ip */ - call __libc_start_main /* musl init will run the program */ -.L0: jmp .L0 diff --git a/05/musl-final/dist/config.mak b/05/musl-final/dist/config.mak deleted file mode 100644 index 452a93a..0000000 --- a/05/musl-final/dist/config.mak +++ /dev/null @@ -1,25 +0,0 @@ -# -# musl config.mak template (original in dist/config.mak) -# - -# Target CPU architecture. Supported values: i386, x86_64 -ARCH = i386 - -# Installation prefix. DO NOT use /, /usr, or /usr/local ! -prefix = /usr/local/musl - -# Installation prefix for musl-gcc compiler wrapper. -exec_prefix = /usr/local - -# Uncomment if you want to build i386 musl on a 64-bit host -#CFLAGS += -m32 - -# Uncomment for smaller code size. -#CFLAGS += -fomit-frame-pointer -mno-accumulate-outgoing-args - -# Uncomment for warnings (as errors). Might need tuning to your gcc version. -#CFLAGS += -Werror -Wall -Wpointer-arith -Wcast-align -Wno-parentheses -Wno-char-subscripts -Wno-uninitialized -Wno-sequence-point -Wno-missing-braces -Wno-unused-value -#CFLAGS += -Wno-pointer-sign - -# Uncomment if you want to build a shared library (experimental). -#LIBC_LIBS += lib/libc.so diff --git a/05/musl-final/include/alloca.h b/05/musl-final/include/alloca.h deleted file mode 100644 index ac78e46..0000000 --- a/05/musl-final/include/alloca.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef _ALLOCA_H -#define _ALLOCA_H - -#define __NEED_size_t -#include - -void *alloca(size_t); - -#endif diff --git a/05/musl-final/include/arpa/inet.h b/05/musl-final/include/arpa/inet.h deleted file mode 100644 index 9342713..0000000 --- a/05/musl-final/include/arpa/inet.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef _ARPA_INET_H -#define _ARPA_INET_H - -#include -#include - -#define __NEED_socklen_t -#define __NEED_in_addr_t -#define __NEED_in_port_t -#define __NEED_uint16_t -#define __NEED_uint32_t -#define __NEED_struct_in_addr - -#include - -uint32_t htonl(uint32_t); -uint16_t htons(uint16_t); -uint32_t ntohl(uint32_t); -uint16_t ntohs(uint16_t); - -in_addr_t inet_addr (const char *); -char *inet_ntoa (struct in_addr); -int inet_pton (int, const char *, void *); -const char *inet_ntop (int, const void *, char *, socklen_t); - -int inet_aton (const char *, struct in_addr *); /* nonstandard but widely used */ - -#undef INET_ADDRSTRLEN -#undef INET6_ADDRSTRLEN -#define INET_ADDRSTRLEN 16 -#define INET6_ADDRSTRLEN 46 - -#endif diff --git a/05/musl-final/include/arpa/nameser.h b/05/musl-final/include/arpa/nameser.h deleted file mode 100644 index 0f85460..0000000 --- a/05/musl-final/include/arpa/nameser.h +++ /dev/null @@ -1,465 +0,0 @@ -#ifndef _ARPA_NAMESER_H_ -#define _ARPA_NAMESER_H_ - -#define __NAMESER 19991006 -#define NS_PACKETSZ 512 -#define NS_MAXDNAME 1025 -#define NS_MAXMSG 65535 -#define NS_MAXCDNAME 255 -#define NS_MAXLABEL 63 -#define NS_HFIXEDSZ 12 -#define NS_QFIXEDSZ 4 -#define NS_RRFIXEDSZ 10 -#define NS_INT32SZ 4 -#define NS_INT16SZ 2 -#define NS_INT8SZ 1 -#define NS_INADDRSZ 4 -#define NS_IN6ADDRSZ 16 -#define NS_CMPRSFLGS 0xc0 -#define NS_DEFAULTPORT 53 - -typedef enum __ns_sect { - ns_s_qd = 0, - ns_s_zn = 0, - ns_s_an = 1, - ns_s_pr = 1, - ns_s_ns = 2, - ns_s_ud = 2, - ns_s_ar = 3, - ns_s_max = 4 -} ns_sect; - -typedef struct __ns_msg { - const unsigned char *_msg, *_eom; - uint16_t _id, _flags, _counts[ns_s_max]; - const unsigned char *_sections[ns_s_max]; - ns_sect _sect; - int _rrnum; - const unsigned char *_msg_ptr; -} ns_msg; - -struct _ns_flagdata { int mask, shift; }; -extern const struct _ns_flagdata _ns_flagdata[]; - -#define ns_msg_id(handle) ((handle)._id + 0) -#define ns_msg_base(handle) ((handle)._msg + 0) -#define ns_msg_end(handle) ((handle)._eom + 0) -#define ns_msg_size(handle) ((handle)._eom - (handle)._msg) -#define ns_msg_count(handle, section) ((handle)._counts[section] + 0) - -typedef struct __ns_rr { - char name[NS_MAXDNAME]; - uint16_t type; - uint16_t rr_class; - uint32_t ttl; - uint16_t rdlength; - const unsigned char *rdata; -} ns_rr; - -#define ns_rr_name(rr) (((rr).name[0] != '\0') ? (rr).name : ".") -#define ns_rr_type(rr) ((ns_type)((rr).type + 0)) -#define ns_rr_class(rr) ((ns_class)((rr).rr_class + 0)) -#define ns_rr_ttl(rr) ((rr).ttl + 0) -#define ns_rr_rdlen(rr) ((rr).rdlength + 0) -#define ns_rr_rdata(rr) ((rr).rdata + 0) - -typedef enum __ns_flag { - ns_f_qr, - ns_f_opcode, - ns_f_aa, - ns_f_tc, - ns_f_rd, - ns_f_ra, - ns_f_z, - ns_f_ad, - ns_f_cd, - ns_f_rcode, - ns_f_max -} ns_flag; - -typedef enum __ns_opcode { - ns_o_query = 0, - ns_o_iquery = 1, - ns_o_status = 2, - ns_o_notify = 4, - ns_o_update = 5, - ns_o_max = 6 -} ns_opcode; - -typedef enum __ns_rcode { - ns_r_noerror = 0, - ns_r_formerr = 1, - ns_r_servfail = 2, - ns_r_nxdomain = 3, - ns_r_notimpl = 4, - ns_r_refused = 5, - ns_r_yxdomain = 6, - ns_r_yxrrset = 7, - ns_r_nxrrset = 8, - ns_r_notauth = 9, - ns_r_notzone = 10, - ns_r_max = 11, - ns_r_badvers = 16, - ns_r_badsig = 16, - ns_r_badkey = 17, - ns_r_badtime = 18 -} ns_rcode; - -typedef enum __ns_update_operation { - ns_uop_delete = 0, - ns_uop_add = 1, - ns_uop_max = 2 -} ns_update_operation; - -struct ns_tsig_key { - char name[NS_MAXDNAME], alg[NS_MAXDNAME]; - unsigned char *data; - int len; -}; -typedef struct ns_tsig_key ns_tsig_key; - -struct ns_tcp_tsig_state { - int counter; - struct dst_key *key; - void *ctx; - unsigned char sig[NS_PACKETSZ]; - int siglen; -}; -typedef struct ns_tcp_tsig_state ns_tcp_tsig_state; - -#define NS_TSIG_FUDGE 300 -#define NS_TSIG_TCP_COUNT 100 -#define NS_TSIG_ALG_HMAC_MD5 "HMAC-MD5.SIG-ALG.REG.INT" - -#define NS_TSIG_ERROR_NO_TSIG -10 -#define NS_TSIG_ERROR_NO_SPACE -11 -#define NS_TSIG_ERROR_FORMERR -12 - -typedef enum __ns_type { - ns_t_invalid = 0, - ns_t_a = 1, - ns_t_ns = 2, - ns_t_md = 3, - ns_t_mf = 4, - ns_t_cname = 5, - ns_t_soa = 6, - ns_t_mb = 7, - ns_t_mg = 8, - ns_t_mr = 9, - ns_t_null = 10, - ns_t_wks = 11, - ns_t_ptr = 12, - ns_t_hinfo = 13, - ns_t_minfo = 14, - ns_t_mx = 15, - ns_t_txt = 16, - ns_t_rp = 17, - ns_t_afsdb = 18, - ns_t_x25 = 19, - ns_t_isdn = 20, - ns_t_rt = 21, - ns_t_nsap = 22, - ns_t_nsap_ptr = 23, - ns_t_sig = 24, - ns_t_key = 25, - ns_t_px = 26, - ns_t_gpos = 27, - ns_t_aaaa = 28, - ns_t_loc = 29, - ns_t_nxt = 30, - ns_t_eid = 31, - ns_t_nimloc = 32, - ns_t_srv = 33, - ns_t_atma = 34, - ns_t_naptr = 35, - ns_t_kx = 36, - ns_t_cert = 37, - ns_t_a6 = 38, - ns_t_dname = 39, - ns_t_sink = 40, - ns_t_opt = 41, - ns_t_apl = 42, - ns_t_tkey = 249, - ns_t_tsig = 250, - ns_t_ixfr = 251, - ns_t_axfr = 252, - ns_t_mailb = 253, - ns_t_maila = 254, - ns_t_any = 255, - ns_t_zxfr = 256, - ns_t_max = 65536 -} ns_type; - -#define ns_t_qt_p(t) (ns_t_xfr_p(t) || (t) == ns_t_any || \ - (t) == ns_t_mailb || (t) == ns_t_maila) -#define ns_t_mrr_p(t) ((t) == ns_t_tsig || (t) == ns_t_opt) -#define ns_t_rr_p(t) (!ns_t_qt_p(t) && !ns_t_mrr_p(t)) -#define ns_t_udp_p(t) ((t) != ns_t_axfr && (t) != ns_t_zxfr) -#define ns_t_xfr_p(t) ((t) == ns_t_axfr || (t) == ns_t_ixfr || \ - (t) == ns_t_zxfr) - -typedef enum __ns_class { - ns_c_invalid = 0, - ns_c_in = 1, - ns_c_2 = 2, - ns_c_chaos = 3, - ns_c_hs = 4, - ns_c_none = 254, - ns_c_any = 255, - ns_c_max = 65536 -} ns_class; - -typedef enum __ns_key_types { - ns_kt_rsa = 1, - ns_kt_dh = 2, - ns_kt_dsa = 3, - ns_kt_private = 254 -} ns_key_types; - -typedef enum __ns_cert_types { - cert_t_pkix = 1, - cert_t_spki = 2, - cert_t_pgp = 3, - cert_t_url = 253, - cert_t_oid = 254 -} ns_cert_types; - -#define NS_KEY_TYPEMASK 0xC000 -#define NS_KEY_TYPE_AUTH_CONF 0x0000 -#define NS_KEY_TYPE_CONF_ONLY 0x8000 -#define NS_KEY_TYPE_AUTH_ONLY 0x4000 -#define NS_KEY_TYPE_NO_KEY 0xC000 -#define NS_KEY_NO_AUTH 0x8000 -#define NS_KEY_NO_CONF 0x4000 -#define NS_KEY_RESERVED2 0x2000 -#define NS_KEY_EXTENDED_FLAGS 0x1000 -#define NS_KEY_RESERVED4 0x0800 -#define NS_KEY_RESERVED5 0x0400 -#define NS_KEY_NAME_TYPE 0x0300 -#define NS_KEY_NAME_USER 0x0000 -#define NS_KEY_NAME_ENTITY 0x0200 -#define NS_KEY_NAME_ZONE 0x0100 -#define NS_KEY_NAME_RESERVED 0x0300 -#define NS_KEY_RESERVED8 0x0080 -#define NS_KEY_RESERVED9 0x0040 -#define NS_KEY_RESERVED10 0x0020 -#define NS_KEY_RESERVED11 0x0010 -#define NS_KEY_SIGNATORYMASK 0x000F -#define NS_KEY_RESERVED_BITMASK ( NS_KEY_RESERVED2 | \ - NS_KEY_RESERVED4 | \ - NS_KEY_RESERVED5 | \ - NS_KEY_RESERVED8 | \ - NS_KEY_RESERVED9 | \ - NS_KEY_RESERVED10 | \ - NS_KEY_RESERVED11 ) -#define NS_KEY_RESERVED_BITMASK2 0xFFFF -#define NS_ALG_MD5RSA 1 -#define NS_ALG_DH 2 -#define NS_ALG_DSA 3 -#define NS_ALG_DSS NS_ALG_DSA -#define NS_ALG_EXPIRE_ONLY 253 -#define NS_ALG_PRIVATE_OID 254 - -#define NS_KEY_PROT_TLS 1 -#define NS_KEY_PROT_EMAIL 2 -#define NS_KEY_PROT_DNSSEC 3 -#define NS_KEY_PROT_IPSEC 4 -#define NS_KEY_PROT_ANY 255 - -#define NS_MD5RSA_MIN_BITS 512 -#define NS_MD5RSA_MAX_BITS 4096 -#define NS_MD5RSA_MAX_BYTES ((NS_MD5RSA_MAX_BITS+7/8)*2+3) -#define NS_MD5RSA_MAX_BASE64 (((NS_MD5RSA_MAX_BYTES+2)/3)*4) -#define NS_MD5RSA_MIN_SIZE ((NS_MD5RSA_MIN_BITS+7)/8) -#define NS_MD5RSA_MAX_SIZE ((NS_MD5RSA_MAX_BITS+7)/8) - -#define NS_DSA_SIG_SIZE 41 -#define NS_DSA_MIN_SIZE 213 -#define NS_DSA_MAX_BYTES 405 - -#define NS_SIG_TYPE 0 -#define NS_SIG_ALG 2 -#define NS_SIG_LABELS 3 -#define NS_SIG_OTTL 4 -#define NS_SIG_EXPIR 8 -#define NS_SIG_SIGNED 12 -#define NS_SIG_FOOT 16 -#define NS_SIG_SIGNER 18 -#define NS_NXT_BITS 8 -#define NS_NXT_BIT_SET( n,p) (p[(n)/NS_NXT_BITS] |= (0x80>>((n)%NS_NXT_BITS))) -#define NS_NXT_BIT_CLEAR(n,p) (p[(n)/NS_NXT_BITS] &= ~(0x80>>((n)%NS_NXT_BITS))) -#define NS_NXT_BIT_ISSET(n,p) (p[(n)/NS_NXT_BITS] & (0x80>>((n)%NS_NXT_BITS))) -#define NS_NXT_MAX 127 - -#define NS_OPT_DNSSEC_OK 0x8000U -#define NS_OPT_NSID 3 - -#define NS_GET16(s, cp) do { \ - register const unsigned char *t_cp = (const unsigned char *)(cp); \ - (s) = ((uint16_t)t_cp[0] << 8) \ - | ((uint16_t)t_cp[1]) \ - ; \ - (cp) += NS_INT16SZ; \ -} while (0) - -#define NS_GET32(l, cp) do { \ - register const unsigned char *t_cp = (const unsigned char *)(cp); \ - (l) = ((uint32_t)t_cp[0] << 24) \ - | ((uint32_t)t_cp[1] << 16) \ - | ((uint32_t)t_cp[2] << 8) \ - | ((uint32_t)t_cp[3]) \ - ; \ - (cp) += NS_INT32SZ; \ -} while (0) - -#define NS_PUT16(s, cp) do { \ - register uint16_t t_s = (uint16_t)(s); \ - register unsigned char *t_cp = (unsigned char *)(cp); \ - *t_cp++ = t_s >> 8; \ - *t_cp = t_s; \ - (cp) += NS_INT16SZ; \ -} while (0) - -#define NS_PUT32(l, cp) do { \ - register uint32_t t_l = (uint32_t)(l); \ - register unsigned char *t_cp = (unsigned char *)(cp); \ - *t_cp++ = t_l >> 24; \ - *t_cp++ = t_l >> 16; \ - *t_cp++ = t_l >> 8; \ - *t_cp = t_l; \ - (cp) += NS_INT32SZ; \ -} while (0) - - - - -#define __BIND 19950621 - -typedef struct { - unsigned id :16; -#if __BYTE_ORDER == __BIG_ENDIAN - unsigned qr: 1; - unsigned opcode: 4; - unsigned aa: 1; - unsigned tc: 1; - unsigned rd: 1; - unsigned ra: 1; - unsigned unused :1; - unsigned ad: 1; - unsigned cd: 1; - unsigned rcode :4; -#else - unsigned rd :1; - unsigned tc :1; - unsigned aa :1; - unsigned opcode :4; - unsigned qr :1; - unsigned rcode :4; - unsigned cd: 1; - unsigned ad: 1; - unsigned unused :1; - unsigned ra :1; -#endif - unsigned qdcount :16; - unsigned ancount :16; - unsigned nscount :16; - unsigned arcount :16; -} HEADER; - -#define PACKETSZ NS_PACKETSZ -#define MAXDNAME NS_MAXDNAME -#define MAXCDNAME NS_MAXCDNAME -#define MAXLABEL NS_MAXLABEL -#define HFIXEDSZ NS_HFIXEDSZ -#define QFIXEDSZ NS_QFIXEDSZ -#define RRFIXEDSZ NS_RRFIXEDSZ -#define INT32SZ NS_INT32SZ -#define INT16SZ NS_INT16SZ -#define INT8SZ NS_INT8SZ -#define INADDRSZ NS_INADDRSZ -#define IN6ADDRSZ NS_IN6ADDRSZ -#define INDIR_MASK NS_CMPRSFLGS -#define NAMESERVER_PORT NS_DEFAULTPORT - -#define S_ZONE ns_s_zn -#define S_PREREQ ns_s_pr -#define S_UPDATE ns_s_ud -#define S_ADDT ns_s_ar - -#define QUERY ns_o_query -#define IQUERY ns_o_iquery -#define STATUS ns_o_status -#define NS_NOTIFY_OP ns_o_notify -#define NS_UPDATE_OP ns_o_update - -#define NOERROR ns_r_noerror -#define FORMERR ns_r_formerr -#define SERVFAIL ns_r_servfail -#define NXDOMAIN ns_r_nxdomain -#define NOTIMP ns_r_notimpl -#define REFUSED ns_r_refused -#define YXDOMAIN ns_r_yxdomain -#define YXRRSET ns_r_yxrrset -#define NXRRSET ns_r_nxrrset -#define NOTAUTH ns_r_notauth -#define NOTZONE ns_r_notzone - -#define DELETE ns_uop_delete -#define ADD ns_uop_add - -#define T_A ns_t_a -#define T_NS ns_t_ns -#define T_MD ns_t_md -#define T_MF ns_t_mf -#define T_CNAME ns_t_cname -#define T_SOA ns_t_soa -#define T_MB ns_t_mb -#define T_MG ns_t_mg -#define T_MR ns_t_mr -#define T_NULL ns_t_null -#define T_WKS ns_t_wks -#define T_PTR ns_t_ptr -#define T_HINFO ns_t_hinfo -#define T_MINFO ns_t_minfo -#define T_MX ns_t_mx -#define T_TXT ns_t_txt -#define T_RP ns_t_rp -#define T_AFSDB ns_t_afsdb -#define T_X25 ns_t_x25 -#define T_ISDN ns_t_isdn -#define T_RT ns_t_rt -#define T_NSAP ns_t_nsap -#define T_NSAP_PTR ns_t_nsap_ptr -#define T_SIG ns_t_sig -#define T_KEY ns_t_key -#define T_PX ns_t_px -#define T_GPOS ns_t_gpos -#define T_AAAA ns_t_aaaa -#define T_LOC ns_t_loc -#define T_NXT ns_t_nxt -#define T_EID ns_t_eid -#define T_NIMLOC ns_t_nimloc -#define T_SRV ns_t_srv -#define T_ATMA ns_t_atma -#define T_NAPTR ns_t_naptr -#define T_A6 ns_t_a6 -#define T_DNAME ns_t_dname -#define T_TSIG ns_t_tsig -#define T_IXFR ns_t_ixfr -#define T_AXFR ns_t_axfr -#define T_MAILB ns_t_mailb -#define T_MAILA ns_t_maila -#define T_ANY ns_t_any - -#define C_IN ns_c_in -#define C_CHAOS ns_c_chaos -#define C_HS ns_c_hs -#define C_NONE ns_c_none -#define C_ANY ns_c_any - -#define GETSHORT NS_GET16 -#define GETLONG NS_GET32 -#define PUTSHORT NS_PUT16 -#define PUTLONG NS_PUT32 - -#endif diff --git a/05/musl-final/include/arpa/telnet.h b/05/musl-final/include/arpa/telnet.h deleted file mode 100644 index e2ad974..0000000 --- a/05/musl-final/include/arpa/telnet.h +++ /dev/null @@ -1,251 +0,0 @@ -#ifndef _ARPA_TELNET_H -#define _ARPA_TELNET_H - -#define IAC 255 -#define DONT 254 -#define DO 253 -#define WONT 252 -#define WILL 251 -#define SB 250 -#define GA 249 -#define EL 248 -#define EC 247 -#define AYT 246 -#define AO 245 -#define IP 244 -#define BREAK 243 -#define DM 242 -#define NOP 241 -#define SE 240 -#define EOR 239 -#define ABORT 238 -#define SUSP 237 -#define xEOF 236 - -#define SYNCH 242 - -#define telcmds ((char [][6]){ "EOF", "SUSP", "ABORT", "EOR", "SE", "NOP", "DMARK", "BRK", "IP", "AO", "AYT", "EC", "EL", "GA", "SB", "WILL", "WONT", "DO", "DONT", "IAC", 0 }) - -#define TELCMD_FIRST xEOF -#define TELCMD_LAST IAC -#define TELCMD_OK(x) ((unsigned int)(x) <= TELCMD_LAST && \ - (unsigned int)(x) >= TELCMD_FIRST) -#define TELCMD(x) telcmds[(x)-TELCMD_FIRST] - -#define TELOPT_BINARY 0 -#define TELOPT_ECHO 1 -#define TELOPT_RCP 2 -#define TELOPT_SGA 3 -#define TELOPT_NAMS 4 -#define TELOPT_STATUS 5 -#define TELOPT_TM 6 -#define TELOPT_RCTE 7 -#define TELOPT_NAOL 8 -#define TELOPT_NAOP 9 -#define TELOPT_NAOCRD 10 -#define TELOPT_NAOHTS 11 -#define TELOPT_NAOHTD 12 -#define TELOPT_NAOFFD 13 -#define TELOPT_NAOVTS 14 -#define TELOPT_NAOVTD 15 -#define TELOPT_NAOLFD 16 -#define TELOPT_XASCII 17 -#define TELOPT_LOGOUT 18 -#define TELOPT_BM 19 -#define TELOPT_DET 20 -#define TELOPT_SUPDUP 21 -#define TELOPT_SUPDUPOUTPUT 22 -#define TELOPT_SNDLOC 23 -#define TELOPT_TTYPE 24 -#define TELOPT_EOR 25 -#define TELOPT_TUID 26 -#define TELOPT_OUTMRK 27 -#define TELOPT_TTYLOC 28 -#define TELOPT_3270REGIME 29 -#define TELOPT_X3PAD 30 -#define TELOPT_NAWS 31 -#define TELOPT_TSPEED 32 -#define TELOPT_LFLOW 33 -#define TELOPT_LINEMODE 34 -#define TELOPT_XDISPLOC 35 -#define TELOPT_OLD_ENVIRON 36 -#define TELOPT_AUTHENTICATION 37/* Authenticate */ -#define TELOPT_ENCRYPT 38 -#define TELOPT_NEW_ENVIRON 39 -#define TELOPT_EXOPL 255 - - -#define NTELOPTS (1+TELOPT_NEW_ENVIRON) -#ifdef TELOPTS -char *telopts[NTELOPTS+1] = { - "BINARY", "ECHO", "RCP", "SUPPRESS GO AHEAD", "NAME", - "STATUS", "TIMING MARK", "RCTE", "NAOL", "NAOP", - "NAOCRD", "NAOHTS", "NAOHTD", "NAOFFD", "NAOVTS", - "NAOVTD", "NAOLFD", "EXTEND ASCII", "LOGOUT", "BYTE MACRO", - "DATA ENTRY TERMINAL", "SUPDUP", "SUPDUP OUTPUT", - "SEND LOCATION", "TERMINAL TYPE", "END OF RECORD", - "TACACS UID", "OUTPUT MARKING", "TTYLOC", - "3270 REGIME", "X.3 PAD", "NAWS", "TSPEED", "LFLOW", - "LINEMODE", "XDISPLOC", "OLD-ENVIRON", "AUTHENTICATION", - "ENCRYPT", "NEW-ENVIRON", - 0, -}; -#define TELOPT_FIRST TELOPT_BINARY -#define TELOPT_LAST TELOPT_NEW_ENVIRON -#define TELOPT_OK(x) ((unsigned int)(x) <= TELOPT_LAST) -#define TELOPT(x) telopts[(x)-TELOPT_FIRST] -#endif - -#define TELQUAL_IS 0 -#define TELQUAL_SEND 1 -#define TELQUAL_INFO 2 -#define TELQUAL_REPLY 2 -#define TELQUAL_NAME 3 - -#define LFLOW_OFF 0 -#define LFLOW_ON 1 -#define LFLOW_RESTART_ANY 2 -#define LFLOW_RESTART_XON 3 - - -#define LM_MODE 1 -#define LM_FORWARDMASK 2 -#define LM_SLC 3 - -#define MODE_EDIT 0x01 -#define MODE_TRAPSIG 0x02 -#define MODE_ACK 0x04 -#define MODE_SOFT_TAB 0x08 -#define MODE_LIT_ECHO 0x10 - -#define MODE_MASK 0x1f - -#define MODE_FLOW 0x0100 -#define MODE_ECHO 0x0200 -#define MODE_INBIN 0x0400 -#define MODE_OUTBIN 0x0800 -#define MODE_FORCE 0x1000 - -#define SLC_SYNCH 1 -#define SLC_BRK 2 -#define SLC_IP 3 -#define SLC_AO 4 -#define SLC_AYT 5 -#define SLC_EOR 6 -#define SLC_ABORT 7 -#define SLC_EOF 8 -#define SLC_SUSP 9 -#define SLC_EC 10 -#define SLC_EL 11 -#define SLC_EW 12 -#define SLC_RP 13 -#define SLC_LNEXT 14 -#define SLC_XON 15 -#define SLC_XOFF 16 -#define SLC_FORW1 17 -#define SLC_FORW2 18 - -#define NSLC 18 - -#define SLC_NAMELIST "0", "SYNCH", "BRK", "IP", "AO", "AYT", "EOR", \ - "ABORT", "EOF", "SUSP", "EC", "EL", "EW", "RP", \ - "LNEXT", "XON", "XOFF", "FORW1", "FORW2", 0, -#ifdef SLC_NAMES -char *slc_names[] = { - SLC_NAMELIST -}; -#else -extern char *slc_names[]; -#define SLC_NAMES SLC_NAMELIST -#endif - -#define SLC_NAME_OK(x) ((unsigned int)(x) <= NSLC) -#define SLC_NAME(x) slc_names[x] - -#define SLC_NOSUPPORT 0 -#define SLC_CANTCHANGE 1 -#define SLC_VARIABLE 2 -#define SLC_DEFAULT 3 -#define SLC_LEVELBITS 0x03 - -#define SLC_FUNC 0 -#define SLC_FLAGS 1 -#define SLC_VALUE 2 - -#define SLC_ACK 0x80 -#define SLC_FLUSHIN 0x40 -#define SLC_FLUSHOUT 0x20 - -#define OLD_ENV_VAR 1 -#define OLD_ENV_VALUE 0 -#define NEW_ENV_VAR 0 -#define NEW_ENV_VALUE 1 -#define ENV_ESC 2 -#define ENV_USERVAR 3 - -#define AUTH_WHO_CLIENT 0 -#define AUTH_WHO_SERVER 1 -#define AUTH_WHO_MASK 1 - -#define AUTH_HOW_ONE_WAY 0 -#define AUTH_HOW_MUTUAL 2 -#define AUTH_HOW_MASK 2 - -#define AUTHTYPE_NULL 0 -#define AUTHTYPE_KERBEROS_V4 1 -#define AUTHTYPE_KERBEROS_V5 2 -#define AUTHTYPE_SPX 3 -#define AUTHTYPE_MINK 4 -#define AUTHTYPE_CNT 5 - -#define AUTHTYPE_TEST 99 - -#ifdef AUTH_NAMES -char *authtype_names[] = { - "NULL", "KERBEROS_V4", "KERBEROS_V5", "SPX", "MINK", 0, -}; -#else -extern char *authtype_names[]; -#endif - -#define AUTHTYPE_NAME_OK(x) ((unsigned int)(x) < AUTHTYPE_CNT) -#define AUTHTYPE_NAME(x) authtype_names[x] - -#define ENCRYPT_IS 0 -#define ENCRYPT_SUPPORT 1 -#define ENCRYPT_REPLY 2 -#define ENCRYPT_START 3 -#define ENCRYPT_END 4 -#define ENCRYPT_REQSTART 5 -#define ENCRYPT_REQEND 6 -#define ENCRYPT_ENC_KEYID 7 -#define ENCRYPT_DEC_KEYID 8 -#define ENCRYPT_CNT 9 - -#define ENCTYPE_ANY 0 -#define ENCTYPE_DES_CFB64 1 -#define ENCTYPE_DES_OFB64 2 -#define ENCTYPE_CNT 3 - -#ifdef ENCRYPT_NAMES -char *encrypt_names[] = { - "IS", "SUPPORT", "REPLY", "START", "END", - "REQUEST-START", "REQUEST-END", "ENC-KEYID", "DEC-KEYID", - 0, -}; -char *enctype_names[] = { - "ANY", "DES_CFB64", "DES_OFB64", 0, -}; -#else -extern char *encrypt_names[]; -extern char *enctype_names[]; -#endif - - -#define ENCRYPT_NAME_OK(x) ((unsigned int)(x) < ENCRYPT_CNT) -#define ENCRYPT_NAME(x) encrypt_names[x] - -#define ENCTYPE_NAME_OK(x) ((unsigned int)(x) < ENCTYPE_CNT) -#define ENCTYPE_NAME(x) enctype_names[x] - -#endif diff --git a/05/musl-final/include/assert.h b/05/musl-final/include/assert.h deleted file mode 100644 index bad2ccd..0000000 --- a/05/musl-final/include/assert.h +++ /dev/null @@ -1,17 +0,0 @@ -#undef assert - -#ifdef NDEBUG -#define assert(x) (void)0 -#else -#define assert(x) ((x) || (__assert_fail(#x, __FILE__, __LINE__, __func__),0)) -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -void __assert_fail (const char *, const char *, int, const char *); - -#ifdef __cplusplus -} -#endif diff --git a/05/musl-final/include/bits b/05/musl-final/include/bits deleted file mode 120000 index ed2f0a7..0000000 --- a/05/musl-final/include/bits +++ /dev/null @@ -1 +0,0 @@ -../arch/x86_64/bits \ No newline at end of file diff --git a/05/musl-final/include/byteswap.h b/05/musl-final/include/byteswap.h deleted file mode 100644 index e69de29..0000000 diff --git a/05/musl-final/include/cpio.h b/05/musl-final/include/cpio.h deleted file mode 100644 index 39a1f8b..0000000 --- a/05/musl-final/include/cpio.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef _CPIO_H -#define _CPIO_H - -#define MAGIC "070707" - -#define C_IRUSR 000400 -#define C_IWUSR 000200 -#define C_IXUSR 000100 -#define C_IRGRP 000040 -#define C_IWGRP 000020 -#define C_IXGRP 000010 -#define C_IROTH 000004 -#define C_IWOTH 000002 -#define C_IXOTH 000001 - -#define C_ISUID 004000 -#define C_ISGID 002000 -#define C_ISVTX 001000 - -#define C_ISBLK 060000 -#define C_ISCHR 020000 -#define C_ISDIR 040000 -#define C_ISFIFO 010000 -#define C_ISSOCK 0140000 -#define C_ISLNK 0120000 -#define C_ISCTG 0110000 -#define C_ISREG 0100000 - -#endif diff --git a/05/musl-final/include/ctype.h b/05/musl-final/include/ctype.h deleted file mode 100644 index 97b9737..0000000 --- a/05/musl-final/include/ctype.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef _CTYPE_H -#define _CTYPE_H - -int isalnum(int); -int isalpha(int); -int isblank(int); -int iscntrl(int); -int isdigit(int); -int isgraph(int); -int islower(int); -int isprint(int); -int ispunct(int); -int isspace(int); -int isupper(int); -int isxdigit(int); -int tolower(int); -int toupper(int); - -#define isalpha(a) ((unsigned)(((a)|32)-'a') < 26) -#define isdigit(a) ((unsigned)((a)-'0') < 10) -#define islower(a) ((unsigned)((a)-'a') < 26) -#define isupper(a) ((unsigned)((a)-'A') < 26) -#define isprint(a) ((unsigned)((a)-0x20) < 0x5f) -#define isgraph(a) ((unsigned)((a)-0x21) < 0x5e) - - - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) - -#define __NEED_locale_t -#include - -int isalnum_l(int, locale_t); -int isalpha_l(int, locale_t); -int isblank_l(int, locale_t); -int iscntrl_l(int, locale_t); -int isdigit_l(int, locale_t); -int isgraph_l(int, locale_t); -int islower_l(int, locale_t); -int isprint_l(int, locale_t); -int ispunct_l(int, locale_t); -int isspace_l(int, locale_t); -int isupper_l(int, locale_t); -int isxdigit_l(int, locale_t); -int tolower_l(int, locale_t); -int toupper_l(int, locale_t); - -int isascii(int); -int toascii(int); -#define _tolower(a) ((a)|0x20) -#define _toupper(a) ((a)&0x5f) - -#endif - -#endif diff --git a/05/musl-final/include/dirent.h b/05/musl-final/include/dirent.h deleted file mode 100644 index 2e8c996..0000000 --- a/05/musl-final/include/dirent.h +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef _DIRENT_H -#define _DIRENT_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define __NEED_ino_t -#define __NEED_off_t - -#include - -typedef struct __DIR_s DIR; - -struct dirent -{ - ino_t d_ino; - off_t d_off; - unsigned short d_reclen; - unsigned char d_type; - char d_name[1]; -}; - -int closedir(DIR *); -DIR *fdopendir(int); -DIR *opendir(const char *); -struct dirent *readdir(DIR *); -int readdir_r(DIR *, struct dirent *, struct dirent **); -void rewinddir(DIR *); -void seekdir(DIR *, long); -long telldir(DIR *); -int dirfd(DIR *); - -int alphasort(const struct dirent **, const struct dirent **); -int scandir(const char *, struct dirent ***, int (*)(const struct dirent *), int (*)(const struct dirent **, const struct dirent **)); - -/* File types for `d_type'. */ -enum - { - DT_UNKNOWN = 0, -# define DT_UNKNOWN DT_UNKNOWN - DT_FIFO = 1, -# define DT_FIFO DT_FIFO - DT_CHR = 2, -# define DT_CHR DT_CHR - DT_DIR = 4, -# define DT_DIR DT_DIR - DT_BLK = 6, -# define DT_BLK DT_BLK - DT_REG = 8, -# define DT_REG DT_REG - DT_LNK = 10, -# define DT_LNK DT_LNK - DT_SOCK = 12, -# define DT_SOCK DT_SOCK - DT_WHT = 14 -# define DT_WHT DT_WHT - }; - -/* Convert between stat structure types and directory types. */ -# define IFTODT(mode) (((mode) & 0170000) >> 12) -# define DTTOIF(dirtype) ((dirtype) << 12) - -#ifdef __cplusplus -extern } -#endif - -#endif diff --git a/05/musl-final/include/elf.h b/05/musl-final/include/elf.h deleted file mode 100644 index b011e78..0000000 --- a/05/musl-final/include/elf.h +++ /dev/null @@ -1,2524 +0,0 @@ -#ifndef _ELF_H -#define _ELF_H 1 - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -typedef uint16_t Elf32_Half; -typedef uint16_t Elf64_Half; - -typedef uint32_t Elf32_Word; -typedef int32_t Elf32_Sword; -typedef uint32_t Elf64_Word; -typedef int32_t Elf64_Sword; - -typedef uint64_t Elf32_Xword; -typedef int64_t Elf32_Sxword; -typedef uint64_t Elf64_Xword; -typedef int64_t Elf64_Sxword; - -typedef uint32_t Elf32_Addr; -typedef uint64_t Elf64_Addr; - -typedef uint32_t Elf32_Off; -typedef uint64_t Elf64_Off; - -typedef uint16_t Elf32_Section; -typedef uint16_t Elf64_Section; - -typedef Elf32_Half Elf32_Versym; -typedef Elf64_Half Elf64_Versym; - -#define EI_NIDENT (16) - -typedef struct { - unsigned char e_ident[EI_NIDENT]; - Elf32_Half e_type; - Elf32_Half e_machine; - Elf32_Word e_version; - Elf32_Addr e_entry; - Elf32_Off e_phoff; - Elf32_Off e_shoff; - Elf32_Word e_flags; - Elf32_Half e_ehsize; - Elf32_Half e_phentsize; - Elf32_Half e_phnum; - Elf32_Half e_shentsize; - Elf32_Half e_shnum; - Elf32_Half e_shstrndx; -} Elf32_Ehdr; - -typedef struct { - unsigned char e_ident[EI_NIDENT]; - Elf64_Half e_type; - Elf64_Half e_machine; - Elf64_Word e_version; - Elf64_Addr e_entry; - Elf64_Off e_phoff; - Elf64_Off e_shoff; - Elf64_Word e_flags; - Elf64_Half e_ehsize; - Elf64_Half e_phentsize; - Elf64_Half e_phnum; - Elf64_Half e_shentsize; - Elf64_Half e_shnum; - Elf64_Half e_shstrndx; -} Elf64_Ehdr; - -#define EI_MAG0 0 -#define ELFMAG0 0x7f - -#define EI_MAG1 1 -#define ELFMAG1 'E' - -#define EI_MAG2 2 -#define ELFMAG2 'L' - -#define EI_MAG3 3 -#define ELFMAG3 'F' - - -#define ELFMAG "\177ELF" -#define SELFMAG 4 - -#define EI_CLASS 4 -#define ELFCLASSNONE 0 -#define ELFCLASS32 1 -#define ELFCLASS64 2 -#define ELFCLASSNUM 3 - -#define EI_DATA 5 -#define ELFDATANONE 0 -#define ELFDATA2LSB 1 -#define ELFDATA2MSB 2 -#define ELFDATANUM 3 - -#define EI_VERSION 6 - - -#define EI_OSABI 7 -#define ELFOSABI_NONE 0 -#define ELFOSABI_SYSV 0 -#define ELFOSABI_HPUX 1 -#define ELFOSABI_NETBSD 2 -#define ELFOSABI_LINUX 3 -#define ELFOSABI_SOLARIS 6 -#define ELFOSABI_AIX 7 -#define ELFOSABI_IRIX 8 -#define ELFOSABI_FREEBSD 9 -#define ELFOSABI_TRU64 10 -#define ELFOSABI_MODESTO 11 -#define ELFOSABI_OPENBSD 12 -#define ELFOSABI_ARM 97 -#define ELFOSABI_STANDALONE 255 - -#define EI_ABIVERSION 8 - -#define EI_PAD 9 - - - -#define ET_NONE 0 -#define ET_REL 1 -#define ET_EXEC 2 -#define ET_DYN 3 -#define ET_CORE 4 -#define ET_NUM 5 -#define ET_LOOS 0xfe00 -#define ET_HIOS 0xfeff -#define ET_LOPROC 0xff00 -#define ET_HIPROC 0xffff - - - -#define EM_NONE 0 -#define EM_M32 1 -#define EM_SPARC 2 -#define EM_386 3 -#define EM_68K 4 -#define EM_88K 5 -#define EM_860 7 -#define EM_MIPS 8 -#define EM_S370 9 -#define EM_MIPS_RS3_LE 10 - -#define EM_PARISC 15 -#define EM_VPP500 17 -#define EM_SPARC32PLUS 18 -#define EM_960 19 -#define EM_PPC 20 -#define EM_PPC64 21 -#define EM_S390 22 - -#define EM_V800 36 -#define EM_FR20 37 -#define EM_RH32 38 -#define EM_RCE 39 -#define EM_ARM 40 -#define EM_FAKE_ALPHA 41 -#define EM_SH 42 -#define EM_SPARCV9 43 -#define EM_TRICORE 44 -#define EM_ARC 45 -#define EM_H8_300 46 -#define EM_H8_300H 47 -#define EM_H8S 48 -#define EM_H8_500 49 -#define EM_IA_64 50 -#define EM_MIPS_X 51 -#define EM_COLDFIRE 52 -#define EM_68HC12 53 -#define EM_MMA 54 -#define EM_PCP 55 -#define EM_NCPU 56 -#define EM_NDR1 57 -#define EM_STARCORE 58 -#define EM_ME16 59 -#define EM_ST100 60 -#define EM_TINYJ 61 -#define EM_X86_64 62 -#define EM_PDSP 63 - -#define EM_FX66 66 -#define EM_ST9PLUS 67 -#define EM_ST7 68 -#define EM_68HC16 69 -#define EM_68HC11 70 -#define EM_68HC08 71 -#define EM_68HC05 72 -#define EM_SVX 73 -#define EM_ST19 74 -#define EM_VAX 75 -#define EM_CRIS 76 -#define EM_JAVELIN 77 -#define EM_FIREPATH 78 -#define EM_ZSP 79 -#define EM_MMIX 80 -#define EM_HUANY 81 -#define EM_PRISM 82 -#define EM_AVR 83 -#define EM_FR30 84 -#define EM_D10V 85 -#define EM_D30V 86 -#define EM_V850 87 -#define EM_M32R 88 -#define EM_MN10300 89 -#define EM_MN10200 90 -#define EM_PJ 91 -#define EM_OPENRISC 92 -#define EM_ARC_A5 93 -#define EM_XTENSA 94 -#define EM_NUM 95 -#define EM_ALPHA 0x9026 - -#define EV_NONE 0 -#define EV_CURRENT 1 -#define EV_NUM 2 - -typedef struct { - Elf32_Word sh_name; - Elf32_Word sh_type; - Elf32_Word sh_flags; - Elf32_Addr sh_addr; - Elf32_Off sh_offset; - Elf32_Word sh_size; - Elf32_Word sh_link; - Elf32_Word sh_info; - Elf32_Word sh_addralign; - Elf32_Word sh_entsize; -} Elf32_Shdr; - -typedef struct { - Elf64_Word sh_name; - Elf64_Word sh_type; - Elf64_Xword sh_flags; - Elf64_Addr sh_addr; - Elf64_Off sh_offset; - Elf64_Xword sh_size; - Elf64_Word sh_link; - Elf64_Word sh_info; - Elf64_Xword sh_addralign; - Elf64_Xword sh_entsize; -} Elf64_Shdr; - - - -#define SHN_UNDEF 0 -#define SHN_LORESERVE 0xff00 -#define SHN_LOPROC 0xff00 -#define SHN_BEFORE 0xff00 - -#define SHN_AFTER 0xff01 - -#define SHN_HIPROC 0xff1f -#define SHN_LOOS 0xff20 -#define SHN_HIOS 0xff3f -#define SHN_ABS 0xfff1 -#define SHN_COMMON 0xfff2 -#define SHN_XINDEX 0xffff -#define SHN_HIRESERVE 0xffff - - - -#define SHT_NULL 0 -#define SHT_PROGBITS 1 -#define SHT_SYMTAB 2 -#define SHT_STRTAB 3 -#define SHT_RELA 4 -#define SHT_HASH 5 -#define SHT_DYNAMIC 6 -#define SHT_NOTE 7 -#define SHT_NOBITS 8 -#define SHT_REL 9 -#define SHT_SHLIB 10 -#define SHT_DYNSYM 11 -#define SHT_INIT_ARRAY 14 -#define SHT_FINI_ARRAY 15 -#define SHT_PREINIT_ARRAY 16 -#define SHT_GROUP 17 -#define SHT_SYMTAB_SHNDX 18 -#define SHT_NUM 19 -#define SHT_LOOS 0x60000000 -#define SHT_GNU_ATTRIBUTES 0x6ffffff5 -#define SHT_GNU_HASH 0x6ffffff6 -#define SHT_GNU_LIBLIST 0x6ffffff7 -#define SHT_CHECKSUM 0x6ffffff8 -#define SHT_LOSUNW 0x6ffffffa -#define SHT_SUNW_move 0x6ffffffa -#define SHT_SUNW_COMDAT 0x6ffffffb -#define SHT_SUNW_syminfo 0x6ffffffc -#define SHT_GNU_verdef 0x6ffffffd -#define SHT_GNU_verneed 0x6ffffffe -#define SHT_GNU_versym 0x6fffffff -#define SHT_HISUNW 0x6fffffff -#define SHT_HIOS 0x6fffffff -#define SHT_LOPROC 0x70000000 -#define SHT_HIPROC 0x7fffffff -#define SHT_LOUSER 0x80000000 -#define SHT_HIUSER 0x8fffffff - -#define SHF_WRITE (1 << 0) -#define SHF_ALLOC (1 << 1) -#define SHF_EXECINSTR (1 << 2) -#define SHF_MERGE (1 << 4) -#define SHF_STRINGS (1 << 5) -#define SHF_INFO_LINK (1 << 6) -#define SHF_LINK_ORDER (1 << 7) -#define SHF_OS_NONCONFORMING (1 << 8) - -#define SHF_GROUP (1 << 9) -#define SHF_TLS (1 << 10) -#define SHF_MASKOS 0x0ff00000 -#define SHF_MASKPROC 0xf0000000 -#define SHF_ORDERED (1 << 30) -#define SHF_EXCLUDE (1 << 31) - -#define GRP_COMDAT 0x1 - -typedef struct { - Elf32_Word st_name; - Elf32_Addr st_value; - Elf32_Word st_size; - unsigned char st_info; - unsigned char st_other; - Elf32_Section st_shndx; -} Elf32_Sym; - -typedef struct { - Elf64_Word st_name; - unsigned char st_info; - unsigned char st_other; - Elf64_Section st_shndx; - Elf64_Addr st_value; - Elf64_Xword st_size; -} Elf64_Sym; - -typedef struct { - Elf32_Half si_boundto; - Elf32_Half si_flags; -} Elf32_Syminfo; - -typedef struct { - Elf64_Half si_boundto; - Elf64_Half si_flags; -} Elf64_Syminfo; - -#define SYMINFO_BT_SELF 0xffff -#define SYMINFO_BT_PARENT 0xfffe -#define SYMINFO_BT_LOWRESERVE 0xff00 - -#define SYMINFO_FLG_DIRECT 0x0001 -#define SYMINFO_FLG_PASSTHRU 0x0002 -#define SYMINFO_FLG_COPY 0x0004 -#define SYMINFO_FLG_LAZYLOAD 0x0008 - -#define SYMINFO_NONE 0 -#define SYMINFO_CURRENT 1 -#define SYMINFO_NUM 2 - -#define ELF32_ST_BIND(val) (((unsigned char) (val)) >> 4) -#define ELF32_ST_TYPE(val) ((val) & 0xf) -#define ELF32_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf)) - -#define ELF64_ST_BIND(val) ELF32_ST_BIND (val) -#define ELF64_ST_TYPE(val) ELF32_ST_TYPE (val) -#define ELF64_ST_INFO(bind, type) ELF32_ST_INFO ((bind), (type)) - -#define STB_LOCAL 0 -#define STB_GLOBAL 1 -#define STB_WEAK 2 -#define STB_NUM 3 -#define STB_LOOS 10 -#define STB_GNU_UNIQUE 10 -#define STB_HIOS 12 -#define STB_LOPROC 13 -#define STB_HIPROC 15 - -#define STT_NOTYPE 0 -#define STT_OBJECT 1 -#define STT_FUNC 2 -#define STT_SECTION 3 -#define STT_FILE 4 -#define STT_COMMON 5 -#define STT_TLS 6 -#define STT_NUM 7 -#define STT_LOOS 10 -#define STT_GNU_IFUNC 10 -#define STT_HIOS 12 -#define STT_LOPROC 13 -#define STT_HIPROC 15 - -#define STN_UNDEF 0 - -#define ELF32_ST_VISIBILITY(o) ((o) & 0x03) -#define ELF64_ST_VISIBILITY(o) ELF32_ST_VISIBILITY (o) - -#define STV_DEFAULT 0 -#define STV_INTERNAL 1 -#define STV_HIDDEN 2 -#define STV_PROTECTED 3 - - - - -typedef struct -{ - Elf32_Addr r_offset; - Elf32_Word r_info; -} Elf32_Rel; - -typedef struct { - Elf64_Addr r_offset; - Elf64_Xword r_info; -} Elf64_Rel; - - - -typedef struct { - Elf32_Addr r_offset; - Elf32_Word r_info; - Elf32_Sword r_addend; -} Elf32_Rela; - -typedef struct { - Elf64_Addr r_offset; - Elf64_Xword r_info; - Elf64_Sxword r_addend; -} Elf64_Rela; - - - -#define ELF32_R_SYM(val) ((val) >> 8) -#define ELF32_R_TYPE(val) ((val) & 0xff) -#define ELF32_R_INFO(sym, type) (((sym) << 8) + ((type) & 0xff)) - -#define ELF64_R_SYM(i) ((i) >> 32) -#define ELF64_R_TYPE(i) ((i) & 0xffffffff) -#define ELF64_R_INFO(sym,type) ((((Elf64_Xword) (sym)) << 32) + (type)) - - - -typedef struct { - Elf32_Word p_type; - Elf32_Off p_offset; - Elf32_Addr p_vaddr; - Elf32_Addr p_paddr; - Elf32_Word p_filesz; - Elf32_Word p_memsz; - Elf32_Word p_flags; - Elf32_Word p_align; -} Elf32_Phdr; - -typedef struct { - Elf64_Word p_type; - Elf64_Word p_flags; - Elf64_Off p_offset; - Elf64_Addr p_vaddr; - Elf64_Addr p_paddr; - Elf64_Xword p_filesz; - Elf64_Xword p_memsz; - Elf64_Xword p_align; -} Elf64_Phdr; - - - -#define PT_NULL 0 -#define PT_LOAD 1 -#define PT_DYNAMIC 2 -#define PT_INTERP 3 -#define PT_NOTE 4 -#define PT_SHLIB 5 -#define PT_PHDR 6 -#define PT_TLS 7 -#define PT_NUM 8 -#define PT_LOOS 0x60000000 -#define PT_GNU_EH_FRAME 0x6474e550 -#define PT_GNU_STACK 0x6474e551 -#define PT_GNU_RELRO 0x6474e552 -#define PT_LOSUNW 0x6ffffffa -#define PT_SUNWBSS 0x6ffffffa -#define PT_SUNWSTACK 0x6ffffffb -#define PT_HISUNW 0x6fffffff -#define PT_HIOS 0x6fffffff -#define PT_LOPROC 0x70000000 -#define PT_HIPROC 0x7fffffff - - - -#define PF_X (1 << 0) -#define PF_W (1 << 1) -#define PF_R (1 << 2) -#define PF_MASKOS 0x0ff00000 -#define PF_MASKPROC 0xf0000000 - - - -#define NT_PRSTATUS 1 -#define NT_FPREGSET 2 -#define NT_PRPSINFO 3 -#define NT_PRXREG 4 -#define NT_TASKSTRUCT 4 -#define NT_PLATFORM 5 -#define NT_AUXV 6 -#define NT_GWINDOWS 7 -#define NT_ASRS 8 -#define NT_PSTATUS 10 -#define NT_PSINFO 13 -#define NT_PRCRED 14 -#define NT_UTSNAME 15 -#define NT_LWPSTATUS 16 -#define NT_LWPSINFO 17 -#define NT_PRFPXREG 20 -#define NT_PRXFPREG 0x46e62b7f -#define NT_PPC_VMX 0x100 -#define NT_PPC_SPE 0x101 -#define NT_PPC_VSX 0x102 -#define NT_386_TLS 0x200 -#define NT_386_IOPERM 0x201 -#define NT_VERSION 1 - - - - -typedef struct { - Elf32_Sword d_tag; - union { - Elf32_Word d_val; - Elf32_Addr d_ptr; - } d_un; -} Elf32_Dyn; - -typedef struct { - Elf64_Sxword d_tag; - union { - Elf64_Xword d_val; - Elf64_Addr d_ptr; - } d_un; -} Elf64_Dyn; - - - -#define DT_NULL 0 -#define DT_NEEDED 1 -#define DT_PLTRELSZ 2 -#define DT_PLTGOT 3 -#define DT_HASH 4 -#define DT_STRTAB 5 -#define DT_SYMTAB 6 -#define DT_RELA 7 -#define DT_RELASZ 8 -#define DT_RELAENT 9 -#define DT_STRSZ 10 -#define DT_SYMENT 11 -#define DT_INIT 12 -#define DT_FINI 13 -#define DT_SONAME 14 -#define DT_RPATH 15 -#define DT_SYMBOLIC 16 -#define DT_REL 17 -#define DT_RELSZ 18 -#define DT_RELENT 19 -#define DT_PLTREL 20 -#define DT_DEBUG 21 -#define DT_TEXTREL 22 -#define DT_JMPREL 23 -#define DT_BIND_NOW 24 -#define DT_INIT_ARRAY 25 -#define DT_FINI_ARRAY 26 -#define DT_INIT_ARRAYSZ 27 -#define DT_FINI_ARRAYSZ 28 -#define DT_RUNPATH 29 -#define DT_FLAGS 30 -#define DT_ENCODING 32 -#define DT_PREINIT_ARRAY 32 -#define DT_PREINIT_ARRAYSZ 33 -#define DT_NUM 34 -#define DT_LOOS 0x6000000d -#define DT_HIOS 0x6ffff000 -#define DT_LOPROC 0x70000000 -#define DT_HIPROC 0x7fffffff -#define DT_PROCNUM DT_MIPS_NUM - -#define DT_VALRNGLO 0x6ffffd00 -#define DT_GNU_PRELINKED 0x6ffffdf5 -#define DT_GNU_CONFLICTSZ 0x6ffffdf6 -#define DT_GNU_LIBLISTSZ 0x6ffffdf7 -#define DT_CHECKSUM 0x6ffffdf8 -#define DT_PLTPADSZ 0x6ffffdf9 -#define DT_MOVEENT 0x6ffffdfa -#define DT_MOVESZ 0x6ffffdfb -#define DT_FEATURE_1 0x6ffffdfc -#define DT_POSFLAG_1 0x6ffffdfd - -#define DT_SYMINSZ 0x6ffffdfe -#define DT_SYMINENT 0x6ffffdff -#define DT_VALRNGHI 0x6ffffdff -#define DT_VALTAGIDX(tag) (DT_VALRNGHI - (tag)) -#define DT_VALNUM 12 - -#define DT_ADDRRNGLO 0x6ffffe00 -#define DT_GNU_HASH 0x6ffffef5 -#define DT_TLSDESC_PLT 0x6ffffef6 -#define DT_TLSDESC_GOT 0x6ffffef7 -#define DT_GNU_CONFLICT 0x6ffffef8 -#define DT_GNU_LIBLIST 0x6ffffef9 -#define DT_CONFIG 0x6ffffefa -#define DT_DEPAUDIT 0x6ffffefb -#define DT_AUDIT 0x6ffffefc -#define DT_PLTPAD 0x6ffffefd -#define DT_MOVETAB 0x6ffffefe -#define DT_SYMINFO 0x6ffffeff -#define DT_ADDRRNGHI 0x6ffffeff -#define DT_ADDRTAGIDX(tag) (DT_ADDRRNGHI - (tag)) -#define DT_ADDRNUM 11 - - - -#define DT_VERSYM 0x6ffffff0 - -#define DT_RELACOUNT 0x6ffffff9 -#define DT_RELCOUNT 0x6ffffffa - - -#define DT_FLAGS_1 0x6ffffffb -#define DT_VERDEF 0x6ffffffc - -#define DT_VERDEFNUM 0x6ffffffd -#define DT_VERNEED 0x6ffffffe - -#define DT_VERNEEDNUM 0x6fffffff -#define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) -#define DT_VERSIONTAGNUM 16 - - - -#define DT_AUXILIARY 0x7ffffffd -#define DT_FILTER 0x7fffffff -#define DT_EXTRATAGIDX(tag) ((Elf32_Word)-((Elf32_Sword) (tag) <<1>>1)-1) -#define DT_EXTRANUM 3 - - -#define DF_ORIGIN 0x00000001 -#define DF_SYMBOLIC 0x00000002 -#define DF_TEXTREL 0x00000004 -#define DF_BIND_NOW 0x00000008 -#define DF_STATIC_TLS 0x00000010 - - - -#define DF_1_NOW 0x00000001 -#define DF_1_GLOBAL 0x00000002 -#define DF_1_GROUP 0x00000004 -#define DF_1_NODELETE 0x00000008 -#define DF_1_LOADFLTR 0x00000010 -#define DF_1_INITFIRST 0x00000020 -#define DF_1_NOOPEN 0x00000040 -#define DF_1_ORIGIN 0x00000080 -#define DF_1_DIRECT 0x00000100 -#define DF_1_TRANS 0x00000200 -#define DF_1_INTERPOSE 0x00000400 -#define DF_1_NODEFLIB 0x00000800 -#define DF_1_NODUMP 0x00001000 -#define DF_1_CONFALT 0x00002000 -#define DF_1_ENDFILTEE 0x00004000 -#define DF_1_DISPRELDNE 0x00008000 -#define DF_1_DISPRELPND 0x00010000 - - -#define DTF_1_PARINIT 0x00000001 -#define DTF_1_CONFEXP 0x00000002 - - -#define DF_P1_LAZYLOAD 0x00000001 -#define DF_P1_GROUPPERM 0x00000002 - - - - -typedef struct { - Elf32_Half vd_version; - Elf32_Half vd_flags; - Elf32_Half vd_ndx; - Elf32_Half vd_cnt; - Elf32_Word vd_hash; - Elf32_Word vd_aux; - Elf32_Word vd_next; -} Elf32_Verdef; - -typedef struct { - Elf64_Half vd_version; - Elf64_Half vd_flags; - Elf64_Half vd_ndx; - Elf64_Half vd_cnt; - Elf64_Word vd_hash; - Elf64_Word vd_aux; - Elf64_Word vd_next; -} Elf64_Verdef; - - - -#define VER_DEF_NONE 0 -#define VER_DEF_CURRENT 1 -#define VER_DEF_NUM 2 - - -#define VER_FLG_BASE 0x1 -#define VER_FLG_WEAK 0x2 - - -#define VER_NDX_LOCAL 0 -#define VER_NDX_GLOBAL 1 -#define VER_NDX_LORESERVE 0xff00 -#define VER_NDX_ELIMINATE 0xff01 - - - -typedef struct { - Elf32_Word vda_name; - Elf32_Word vda_next; -} Elf32_Verdaux; - -typedef struct { - Elf64_Word vda_name; - Elf64_Word vda_next; -} Elf64_Verdaux; - - - - -typedef struct { - Elf32_Half vn_version; - Elf32_Half vn_cnt; - Elf32_Word vn_file; - Elf32_Word vn_aux; - Elf32_Word vn_next; -} Elf32_Verneed; - -typedef struct { - Elf64_Half vn_version; - Elf64_Half vn_cnt; - Elf64_Word vn_file; - Elf64_Word vn_aux; - Elf64_Word vn_next; -} Elf64_Verneed; - - - -#define VER_NEED_NONE 0 -#define VER_NEED_CURRENT 1 -#define VER_NEED_NUM 2 - - - -typedef struct { - Elf32_Word vna_hash; - Elf32_Half vna_flags; - Elf32_Half vna_other; - Elf32_Word vna_name; - Elf32_Word vna_next; -} Elf32_Vernaux; - -typedef struct { - Elf64_Word vna_hash; - Elf64_Half vna_flags; - Elf64_Half vna_other; - Elf64_Word vna_name; - Elf64_Word vna_next; -} Elf64_Vernaux; - - - -#define VER_FLG_WEAK 0x2 - - - -typedef struct { - uint32_t a_type; - union { - uint32_t a_val; - } a_un; -} Elf32_auxv_t; - -typedef struct { - uint64_t a_type; - union { - uint64_t a_val; - } a_un; -} Elf64_auxv_t; - - - -#define AT_NULL 0 -#define AT_IGNORE 1 -#define AT_EXECFD 2 -#define AT_PHDR 3 -#define AT_PHENT 4 -#define AT_PHNUM 5 -#define AT_PAGESZ 6 -#define AT_BASE 7 -#define AT_FLAGS 8 -#define AT_ENTRY 9 -#define AT_NOTELF 10 -#define AT_UID 11 -#define AT_EUID 12 -#define AT_GID 13 -#define AT_EGID 14 -#define AT_CLKTCK 17 - - -#define AT_PLATFORM 15 -#define AT_HWCAP 16 - - - - -#define AT_FPUCW 18 - - -#define AT_DCACHEBSIZE 19 -#define AT_ICACHEBSIZE 20 -#define AT_UCACHEBSIZE 21 - - - -#define AT_IGNOREPPC 22 - -#define AT_SECURE 23 - -#define AT_BASE_PLATFORM 24 - -#define AT_RANDOM 25 - -#define AT_EXECFN 31 - - - -#define AT_SYSINFO 32 -#define AT_SYSINFO_EHDR 33 - - - -#define AT_L1I_CACHESHAPE 34 -#define AT_L1D_CACHESHAPE 35 -#define AT_L2_CACHESHAPE 36 -#define AT_L3_CACHESHAPE 37 - - - - -typedef struct { - Elf32_Word n_namesz; - Elf32_Word n_descsz; - Elf32_Word n_type; -} Elf32_Nhdr; - -typedef struct { - Elf64_Word n_namesz; - Elf64_Word n_descsz; - Elf64_Word n_type; -} Elf64_Nhdr; - - - - -#define ELF_NOTE_SOLARIS "SUNW Solaris" - - -#define ELF_NOTE_GNU "GNU" - - - - - -#define ELF_NOTE_PAGESIZE_HINT 1 - - -#define NT_GNU_ABI_TAG 1 -#define ELF_NOTE_ABI NT_GNU_ABI_TAG - - - -#define ELF_NOTE_OS_LINUX 0 -#define ELF_NOTE_OS_GNU 1 -#define ELF_NOTE_OS_SOLARIS2 2 -#define ELF_NOTE_OS_FREEBSD 3 - -#define NT_GNU_BUILD_ID 3 -#define NT_GNU_GOLD_VERSION 4 - - - -typedef struct { - Elf32_Xword m_value; - Elf32_Word m_info; - Elf32_Word m_poffset; - Elf32_Half m_repeat; - Elf32_Half m_stride; -} Elf32_Move; - -typedef struct { - Elf64_Xword m_value; - Elf64_Xword m_info; - Elf64_Xword m_poffset; - Elf64_Half m_repeat; - Elf64_Half m_stride; -} Elf64_Move; - - -#define ELF32_M_SYM(info) ((info) >> 8) -#define ELF32_M_SIZE(info) ((unsigned char) (info)) -#define ELF32_M_INFO(sym, size) (((sym) << 8) + (unsigned char) (size)) - -#define ELF64_M_SYM(info) ELF32_M_SYM (info) -#define ELF64_M_SIZE(info) ELF32_M_SIZE (info) -#define ELF64_M_INFO(sym, size) ELF32_M_INFO (sym, size) - -#define EF_CPU32 0x00810000 - -#define R_68K_NONE 0 -#define R_68K_32 1 -#define R_68K_16 2 -#define R_68K_8 3 -#define R_68K_PC32 4 -#define R_68K_PC16 5 -#define R_68K_PC8 6 -#define R_68K_GOT32 7 -#define R_68K_GOT16 8 -#define R_68K_GOT8 9 -#define R_68K_GOT32O 10 -#define R_68K_GOT16O 11 -#define R_68K_GOT8O 12 -#define R_68K_PLT32 13 -#define R_68K_PLT16 14 -#define R_68K_PLT8 15 -#define R_68K_PLT32O 16 -#define R_68K_PLT16O 17 -#define R_68K_PLT8O 18 -#define R_68K_COPY 19 -#define R_68K_GLOB_DAT 20 -#define R_68K_JMP_SLOT 21 -#define R_68K_RELATIVE 22 -#define R_68K_NUM 23 - -#define R_386_NONE 0 -#define R_386_32 1 -#define R_386_PC32 2 -#define R_386_GOT32 3 -#define R_386_PLT32 4 -#define R_386_COPY 5 -#define R_386_GLOB_DAT 6 -#define R_386_JMP_SLOT 7 -#define R_386_RELATIVE 8 -#define R_386_GOTOFF 9 -#define R_386_GOTPC 10 -#define R_386_32PLT 11 -#define R_386_TLS_TPOFF 14 -#define R_386_TLS_IE 15 -#define R_386_TLS_GOTIE 16 -#define R_386_TLS_LE 17 -#define R_386_TLS_GD 18 -#define R_386_TLS_LDM 19 -#define R_386_16 20 -#define R_386_PC16 21 -#define R_386_8 22 -#define R_386_PC8 23 -#define R_386_TLS_GD_32 24 -#define R_386_TLS_GD_PUSH 25 -#define R_386_TLS_GD_CALL 26 -#define R_386_TLS_GD_POP 27 -#define R_386_TLS_LDM_32 28 -#define R_386_TLS_LDM_PUSH 29 -#define R_386_TLS_LDM_CALL 30 -#define R_386_TLS_LDM_POP 31 -#define R_386_TLS_LDO_32 32 -#define R_386_TLS_IE_32 33 -#define R_386_TLS_LE_32 34 -#define R_386_TLS_DTPMOD32 35 -#define R_386_TLS_DTPOFF32 36 -#define R_386_TLS_TPOFF32 37 -#define R_386_TLS_GOTDESC 39 -#define R_386_TLS_DESC_CALL 40 -#define R_386_TLS_DESC 41 -#define R_386_IRELATIVE 42 -#define R_386_NUM 43 - - - - - -#define STT_SPARC_REGISTER 13 - - - -#define EF_SPARCV9_MM 3 -#define EF_SPARCV9_TSO 0 -#define EF_SPARCV9_PSO 1 -#define EF_SPARCV9_RMO 2 -#define EF_SPARC_LEDATA 0x800000 -#define EF_SPARC_EXT_MASK 0xFFFF00 -#define EF_SPARC_32PLUS 0x000100 -#define EF_SPARC_SUN_US1 0x000200 -#define EF_SPARC_HAL_R1 0x000400 -#define EF_SPARC_SUN_US3 0x000800 - - - -#define R_SPARC_NONE 0 -#define R_SPARC_8 1 -#define R_SPARC_16 2 -#define R_SPARC_32 3 -#define R_SPARC_DISP8 4 -#define R_SPARC_DISP16 5 -#define R_SPARC_DISP32 6 -#define R_SPARC_WDISP30 7 -#define R_SPARC_WDISP22 8 -#define R_SPARC_HI22 9 -#define R_SPARC_22 10 -#define R_SPARC_13 11 -#define R_SPARC_LO10 12 -#define R_SPARC_GOT10 13 -#define R_SPARC_GOT13 14 -#define R_SPARC_GOT22 15 -#define R_SPARC_PC10 16 -#define R_SPARC_PC22 17 -#define R_SPARC_WPLT30 18 -#define R_SPARC_COPY 19 -#define R_SPARC_GLOB_DAT 20 -#define R_SPARC_JMP_SLOT 21 -#define R_SPARC_RELATIVE 22 -#define R_SPARC_UA32 23 - - - -#define R_SPARC_PLT32 24 -#define R_SPARC_HIPLT22 25 -#define R_SPARC_LOPLT10 26 -#define R_SPARC_PCPLT32 27 -#define R_SPARC_PCPLT22 28 -#define R_SPARC_PCPLT10 29 -#define R_SPARC_10 30 -#define R_SPARC_11 31 -#define R_SPARC_64 32 -#define R_SPARC_OLO10 33 -#define R_SPARC_HH22 34 -#define R_SPARC_HM10 35 -#define R_SPARC_LM22 36 -#define R_SPARC_PC_HH22 37 -#define R_SPARC_PC_HM10 38 -#define R_SPARC_PC_LM22 39 -#define R_SPARC_WDISP16 40 -#define R_SPARC_WDISP19 41 -#define R_SPARC_GLOB_JMP 42 -#define R_SPARC_7 43 -#define R_SPARC_5 44 -#define R_SPARC_6 45 -#define R_SPARC_DISP64 46 -#define R_SPARC_PLT64 47 -#define R_SPARC_HIX22 48 -#define R_SPARC_LOX10 49 -#define R_SPARC_H44 50 -#define R_SPARC_M44 51 -#define R_SPARC_L44 52 -#define R_SPARC_REGISTER 53 -#define R_SPARC_UA64 54 -#define R_SPARC_UA16 55 -#define R_SPARC_TLS_GD_HI22 56 -#define R_SPARC_TLS_GD_LO10 57 -#define R_SPARC_TLS_GD_ADD 58 -#define R_SPARC_TLS_GD_CALL 59 -#define R_SPARC_TLS_LDM_HI22 60 -#define R_SPARC_TLS_LDM_LO10 61 -#define R_SPARC_TLS_LDM_ADD 62 -#define R_SPARC_TLS_LDM_CALL 63 -#define R_SPARC_TLS_LDO_HIX22 64 -#define R_SPARC_TLS_LDO_LOX10 65 -#define R_SPARC_TLS_LDO_ADD 66 -#define R_SPARC_TLS_IE_HI22 67 -#define R_SPARC_TLS_IE_LO10 68 -#define R_SPARC_TLS_IE_LD 69 -#define R_SPARC_TLS_IE_LDX 70 -#define R_SPARC_TLS_IE_ADD 71 -#define R_SPARC_TLS_LE_HIX22 72 -#define R_SPARC_TLS_LE_LOX10 73 -#define R_SPARC_TLS_DTPMOD32 74 -#define R_SPARC_TLS_DTPMOD64 75 -#define R_SPARC_TLS_DTPOFF32 76 -#define R_SPARC_TLS_DTPOFF64 77 -#define R_SPARC_TLS_TPOFF32 78 -#define R_SPARC_TLS_TPOFF64 79 -#define R_SPARC_GOTDATA_HIX22 80 -#define R_SPARC_GOTDATA_LOX10 81 -#define R_SPARC_GOTDATA_OP_HIX22 82 -#define R_SPARC_GOTDATA_OP_LOX10 83 -#define R_SPARC_GOTDATA_OP 84 -#define R_SPARC_H34 85 -#define R_SPARC_SIZE32 86 -#define R_SPARC_SIZE64 87 -#define R_SPARC_GNU_VTINHERIT 250 -#define R_SPARC_GNU_VTENTRY 251 -#define R_SPARC_REV32 252 - -#define R_SPARC_NUM 253 - - - -#define DT_SPARC_REGISTER 0x70000001 -#define DT_SPARC_NUM 2 - - - -#define HWCAP_SPARC_FLUSH 1 -#define HWCAP_SPARC_STBAR 2 -#define HWCAP_SPARC_SWAP 4 -#define HWCAP_SPARC_MULDIV 8 -#define HWCAP_SPARC_V9 16 -#define HWCAP_SPARC_ULTRA3 32 -#define HWCAP_SPARC_BLKINIT 64 -#define HWCAP_SPARC_N2 128 - - - - - -#define EF_MIPS_NOREORDER 1 -#define EF_MIPS_PIC 2 -#define EF_MIPS_CPIC 4 -#define EF_MIPS_XGOT 8 -#define EF_MIPS_64BIT_WHIRL 16 -#define EF_MIPS_ABI2 32 -#define EF_MIPS_ABI_ON32 64 -#define EF_MIPS_ARCH 0xf0000000 - - - -#define EF_MIPS_ARCH_1 0x00000000 -#define EF_MIPS_ARCH_2 0x10000000 -#define EF_MIPS_ARCH_3 0x20000000 -#define EF_MIPS_ARCH_4 0x30000000 -#define EF_MIPS_ARCH_5 0x40000000 -#define EF_MIPS_ARCH_32 0x60000000 -#define EF_MIPS_ARCH_64 0x70000000 - - - -#define E_MIPS_ARCH_1 0x00000000 -#define E_MIPS_ARCH_2 0x10000000 -#define E_MIPS_ARCH_3 0x20000000 -#define E_MIPS_ARCH_4 0x30000000 -#define E_MIPS_ARCH_5 0x40000000 -#define E_MIPS_ARCH_32 0x60000000 -#define E_MIPS_ARCH_64 0x70000000 - - - -#define SHN_MIPS_ACOMMON 0xff00 -#define SHN_MIPS_TEXT 0xff01 -#define SHN_MIPS_DATA 0xff02 -#define SHN_MIPS_SCOMMON 0xff03 -#define SHN_MIPS_SUNDEFINED 0xff04 - - - -#define SHT_MIPS_LIBLIST 0x70000000 -#define SHT_MIPS_MSYM 0x70000001 -#define SHT_MIPS_CONFLICT 0x70000002 -#define SHT_MIPS_GPTAB 0x70000003 -#define SHT_MIPS_UCODE 0x70000004 -#define SHT_MIPS_DEBUG 0x70000005 -#define SHT_MIPS_REGINFO 0x70000006 -#define SHT_MIPS_PACKAGE 0x70000007 -#define SHT_MIPS_PACKSYM 0x70000008 -#define SHT_MIPS_RELD 0x70000009 -#define SHT_MIPS_IFACE 0x7000000b -#define SHT_MIPS_CONTENT 0x7000000c -#define SHT_MIPS_OPTIONS 0x7000000d -#define SHT_MIPS_SHDR 0x70000010 -#define SHT_MIPS_FDESC 0x70000011 -#define SHT_MIPS_EXTSYM 0x70000012 -#define SHT_MIPS_DENSE 0x70000013 -#define SHT_MIPS_PDESC 0x70000014 -#define SHT_MIPS_LOCSYM 0x70000015 -#define SHT_MIPS_AUXSYM 0x70000016 -#define SHT_MIPS_OPTSYM 0x70000017 -#define SHT_MIPS_LOCSTR 0x70000018 -#define SHT_MIPS_LINE 0x70000019 -#define SHT_MIPS_RFDESC 0x7000001a -#define SHT_MIPS_DELTASYM 0x7000001b -#define SHT_MIPS_DELTAINST 0x7000001c -#define SHT_MIPS_DELTACLASS 0x7000001d -#define SHT_MIPS_DWARF 0x7000001e -#define SHT_MIPS_DELTADECL 0x7000001f -#define SHT_MIPS_SYMBOL_LIB 0x70000020 -#define SHT_MIPS_EVENTS 0x70000021 -#define SHT_MIPS_TRANSLATE 0x70000022 -#define SHT_MIPS_PIXIE 0x70000023 -#define SHT_MIPS_XLATE 0x70000024 -#define SHT_MIPS_XLATE_DEBUG 0x70000025 -#define SHT_MIPS_WHIRL 0x70000026 -#define SHT_MIPS_EH_REGION 0x70000027 -#define SHT_MIPS_XLATE_OLD 0x70000028 -#define SHT_MIPS_PDR_EXCEPTION 0x70000029 - - - -#define SHF_MIPS_GPREL 0x10000000 -#define SHF_MIPS_MERGE 0x20000000 -#define SHF_MIPS_ADDR 0x40000000 -#define SHF_MIPS_STRINGS 0x80000000 -#define SHF_MIPS_NOSTRIP 0x08000000 -#define SHF_MIPS_LOCAL 0x04000000 -#define SHF_MIPS_NAMES 0x02000000 -#define SHF_MIPS_NODUPE 0x01000000 - - - - - -#define STO_MIPS_DEFAULT 0x0 -#define STO_MIPS_INTERNAL 0x1 -#define STO_MIPS_HIDDEN 0x2 -#define STO_MIPS_PROTECTED 0x3 -#define STO_MIPS_PLT 0x8 -#define STO_MIPS_SC_ALIGN_UNUSED 0xff - - -#define STB_MIPS_SPLIT_COMMON 13 - - - -typedef union { - struct { - Elf32_Word gt_current_g_value; - Elf32_Word gt_unused; - } gt_header; - struct { - Elf32_Word gt_g_value; - Elf32_Word gt_bytes; - } gt_entry; -} Elf32_gptab; - - - -typedef struct { - Elf32_Word ri_gprmask; - Elf32_Word ri_cprmask[4]; - Elf32_Sword ri_gp_value; -} Elf32_RegInfo; - - - -typedef struct { - unsigned char kind; - - unsigned char size; - Elf32_Section section; - - Elf32_Word info; -} Elf_Options; - - - -#define ODK_NULL 0 -#define ODK_REGINFO 1 -#define ODK_EXCEPTIONS 2 -#define ODK_PAD 3 -#define ODK_HWPATCH 4 -#define ODK_FILL 5 -#define ODK_TAGS 6 -#define ODK_HWAND 7 -#define ODK_HWOR 8 - - - -#define OEX_FPU_MIN 0x1f -#define OEX_FPU_MAX 0x1f00 -#define OEX_PAGE0 0x10000 -#define OEX_SMM 0x20000 -#define OEX_FPDBUG 0x40000 -#define OEX_PRECISEFP OEX_FPDBUG -#define OEX_DISMISS 0x80000 - -#define OEX_FPU_INVAL 0x10 -#define OEX_FPU_DIV0 0x08 -#define OEX_FPU_OFLO 0x04 -#define OEX_FPU_UFLO 0x02 -#define OEX_FPU_INEX 0x01 - - - -#define OHW_R4KEOP 0x1 -#define OHW_R8KPFETCH 0x2 -#define OHW_R5KEOP 0x4 -#define OHW_R5KCVTL 0x8 - -#define OPAD_PREFIX 0x1 -#define OPAD_POSTFIX 0x2 -#define OPAD_SYMBOL 0x4 - - - -typedef struct { - Elf32_Word hwp_flags1; - Elf32_Word hwp_flags2; -} Elf_Options_Hw; - - - -#define OHWA0_R4KEOP_CHECKED 0x00000001 -#define OHWA1_R4KEOP_CLEAN 0x00000002 - - - -#define R_MIPS_NONE 0 -#define R_MIPS_16 1 -#define R_MIPS_32 2 -#define R_MIPS_REL32 3 -#define R_MIPS_26 4 -#define R_MIPS_HI16 5 -#define R_MIPS_LO16 6 -#define R_MIPS_GPREL16 7 -#define R_MIPS_LITERAL 8 -#define R_MIPS_GOT16 9 -#define R_MIPS_PC16 10 -#define R_MIPS_CALL16 11 -#define R_MIPS_GPREL32 12 - -#define R_MIPS_SHIFT5 16 -#define R_MIPS_SHIFT6 17 -#define R_MIPS_64 18 -#define R_MIPS_GOT_DISP 19 -#define R_MIPS_GOT_PAGE 20 -#define R_MIPS_GOT_OFST 21 -#define R_MIPS_GOT_HI16 22 -#define R_MIPS_GOT_LO16 23 -#define R_MIPS_SUB 24 -#define R_MIPS_INSERT_A 25 -#define R_MIPS_INSERT_B 26 -#define R_MIPS_DELETE 27 -#define R_MIPS_HIGHER 28 -#define R_MIPS_HIGHEST 29 -#define R_MIPS_CALL_HI16 30 -#define R_MIPS_CALL_LO16 31 -#define R_MIPS_SCN_DISP 32 -#define R_MIPS_REL16 33 -#define R_MIPS_ADD_IMMEDIATE 34 -#define R_MIPS_PJUMP 35 -#define R_MIPS_RELGOT 36 -#define R_MIPS_JALR 37 -#define R_MIPS_TLS_DTPMOD32 38 -#define R_MIPS_TLS_DTPREL32 39 -#define R_MIPS_TLS_DTPMOD64 40 -#define R_MIPS_TLS_DTPREL64 41 -#define R_MIPS_TLS_GD 42 -#define R_MIPS_TLS_LDM 43 -#define R_MIPS_TLS_DTPREL_HI16 44 -#define R_MIPS_TLS_DTPREL_LO16 45 -#define R_MIPS_TLS_GOTTPREL 46 -#define R_MIPS_TLS_TPREL32 47 -#define R_MIPS_TLS_TPREL64 48 -#define R_MIPS_TLS_TPREL_HI16 49 -#define R_MIPS_TLS_TPREL_LO16 50 -#define R_MIPS_GLOB_DAT 51 -#define R_MIPS_COPY 126 -#define R_MIPS_JUMP_SLOT 127 - -#define R_MIPS_NUM 128 - - - -#define PT_MIPS_REGINFO 0x70000000 -#define PT_MIPS_RTPROC 0x70000001 -#define PT_MIPS_OPTIONS 0x70000002 - - - -#define PF_MIPS_LOCAL 0x10000000 - - - -#define DT_MIPS_RLD_VERSION 0x70000001 -#define DT_MIPS_TIME_STAMP 0x70000002 -#define DT_MIPS_ICHECKSUM 0x70000003 -#define DT_MIPS_IVERSION 0x70000004 -#define DT_MIPS_FLAGS 0x70000005 -#define DT_MIPS_BASE_ADDRESS 0x70000006 -#define DT_MIPS_MSYM 0x70000007 -#define DT_MIPS_CONFLICT 0x70000008 -#define DT_MIPS_LIBLIST 0x70000009 -#define DT_MIPS_LOCAL_GOTNO 0x7000000a -#define DT_MIPS_CONFLICTNO 0x7000000b -#define DT_MIPS_LIBLISTNO 0x70000010 -#define DT_MIPS_SYMTABNO 0x70000011 -#define DT_MIPS_UNREFEXTNO 0x70000012 -#define DT_MIPS_GOTSYM 0x70000013 -#define DT_MIPS_HIPAGENO 0x70000014 -#define DT_MIPS_RLD_MAP 0x70000016 -#define DT_MIPS_DELTA_CLASS 0x70000017 -#define DT_MIPS_DELTA_CLASS_NO 0x70000018 - -#define DT_MIPS_DELTA_INSTANCE 0x70000019 -#define DT_MIPS_DELTA_INSTANCE_NO 0x7000001a - -#define DT_MIPS_DELTA_RELOC 0x7000001b -#define DT_MIPS_DELTA_RELOC_NO 0x7000001c - -#define DT_MIPS_DELTA_SYM 0x7000001d - -#define DT_MIPS_DELTA_SYM_NO 0x7000001e - -#define DT_MIPS_DELTA_CLASSSYM 0x70000020 - -#define DT_MIPS_DELTA_CLASSSYM_NO 0x70000021 - -#define DT_MIPS_CXX_FLAGS 0x70000022 -#define DT_MIPS_PIXIE_INIT 0x70000023 -#define DT_MIPS_SYMBOL_LIB 0x70000024 -#define DT_MIPS_LOCALPAGE_GOTIDX 0x70000025 -#define DT_MIPS_LOCAL_GOTIDX 0x70000026 -#define DT_MIPS_HIDDEN_GOTIDX 0x70000027 -#define DT_MIPS_PROTECTED_GOTIDX 0x70000028 -#define DT_MIPS_OPTIONS 0x70000029 -#define DT_MIPS_INTERFACE 0x7000002a -#define DT_MIPS_DYNSTR_ALIGN 0x7000002b -#define DT_MIPS_INTERFACE_SIZE 0x7000002c -#define DT_MIPS_RLD_TEXT_RESOLVE_ADDR 0x7000002d - -#define DT_MIPS_PERF_SUFFIX 0x7000002e - -#define DT_MIPS_COMPACT_SIZE 0x7000002f -#define DT_MIPS_GP_VALUE 0x70000030 -#define DT_MIPS_AUX_DYNAMIC 0x70000031 - -#define DT_MIPS_PLTGOT 0x70000032 - -#define DT_MIPS_RWPLT 0x70000034 -#define DT_MIPS_NUM 0x35 - - - -#define RHF_NONE 0 -#define RHF_QUICKSTART (1 << 0) -#define RHF_NOTPOT (1 << 1) -#define RHF_NO_LIBRARY_REPLACEMENT (1 << 2) -#define RHF_NO_MOVE (1 << 3) -#define RHF_SGI_ONLY (1 << 4) -#define RHF_GUARANTEE_INIT (1 << 5) -#define RHF_DELTA_C_PLUS_PLUS (1 << 6) -#define RHF_GUARANTEE_START_INIT (1 << 7) -#define RHF_PIXIE (1 << 8) -#define RHF_DEFAULT_DELAY_LOAD (1 << 9) -#define RHF_REQUICKSTART (1 << 10) -#define RHF_REQUICKSTARTED (1 << 11) -#define RHF_CORD (1 << 12) -#define RHF_NO_UNRES_UNDEF (1 << 13) -#define RHF_RLD_ORDER_SAFE (1 << 14) - - - -typedef struct -{ - Elf32_Word l_name; - Elf32_Word l_time_stamp; - Elf32_Word l_checksum; - Elf32_Word l_version; - Elf32_Word l_flags; -} Elf32_Lib; - -typedef struct -{ - Elf64_Word l_name; - Elf64_Word l_time_stamp; - Elf64_Word l_checksum; - Elf64_Word l_version; - Elf64_Word l_flags; -} Elf64_Lib; - - - - -#define LL_NONE 0 -#define LL_EXACT_MATCH (1 << 0) -#define LL_IGNORE_INT_VER (1 << 1) -#define LL_REQUIRE_MINOR (1 << 2) -#define LL_EXPORTS (1 << 3) -#define LL_DELAY_LOAD (1 << 4) -#define LL_DELTA (1 << 5) - - - -typedef Elf32_Addr Elf32_Conflict; - - - - - - -#define EF_PARISC_TRAPNIL 0x00010000 -#define EF_PARISC_EXT 0x00020000 -#define EF_PARISC_LSB 0x00040000 -#define EF_PARISC_WIDE 0x00080000 -#define EF_PARISC_NO_KABP 0x00100000 - -#define EF_PARISC_LAZYSWAP 0x00400000 -#define EF_PARISC_ARCH 0x0000ffff - - - -#define EFA_PARISC_1_0 0x020b -#define EFA_PARISC_1_1 0x0210 -#define EFA_PARISC_2_0 0x0214 - - - -#define SHN_PARISC_ANSI_COMMON 0xff00 - -#define SHN_PARISC_HUGE_COMMON 0xff01 - - - -#define SHT_PARISC_EXT 0x70000000 -#define SHT_PARISC_UNWIND 0x70000001 -#define SHT_PARISC_DOC 0x70000002 - - - -#define SHF_PARISC_SHORT 0x20000000 -#define SHF_PARISC_HUGE 0x40000000 -#define SHF_PARISC_SBP 0x80000000 - - - -#define STT_PARISC_MILLICODE 13 - -#define STT_HP_OPAQUE (STT_LOOS + 0x1) -#define STT_HP_STUB (STT_LOOS + 0x2) - - - -#define R_PARISC_NONE 0 -#define R_PARISC_DIR32 1 -#define R_PARISC_DIR21L 2 -#define R_PARISC_DIR17R 3 -#define R_PARISC_DIR17F 4 -#define R_PARISC_DIR14R 6 -#define R_PARISC_PCREL32 9 -#define R_PARISC_PCREL21L 10 -#define R_PARISC_PCREL17R 11 -#define R_PARISC_PCREL17F 12 -#define R_PARISC_PCREL14R 14 -#define R_PARISC_DPREL21L 18 -#define R_PARISC_DPREL14R 22 -#define R_PARISC_GPREL21L 26 -#define R_PARISC_GPREL14R 30 -#define R_PARISC_LTOFF21L 34 -#define R_PARISC_LTOFF14R 38 -#define R_PARISC_SECREL32 41 -#define R_PARISC_SEGBASE 48 -#define R_PARISC_SEGREL32 49 -#define R_PARISC_PLTOFF21L 50 -#define R_PARISC_PLTOFF14R 54 -#define R_PARISC_LTOFF_FPTR32 57 -#define R_PARISC_LTOFF_FPTR21L 58 -#define R_PARISC_LTOFF_FPTR14R 62 -#define R_PARISC_FPTR64 64 -#define R_PARISC_PLABEL32 65 -#define R_PARISC_PLABEL21L 66 -#define R_PARISC_PLABEL14R 70 -#define R_PARISC_PCREL64 72 -#define R_PARISC_PCREL22F 74 -#define R_PARISC_PCREL14WR 75 -#define R_PARISC_PCREL14DR 76 -#define R_PARISC_PCREL16F 77 -#define R_PARISC_PCREL16WF 78 -#define R_PARISC_PCREL16DF 79 -#define R_PARISC_DIR64 80 -#define R_PARISC_DIR14WR 83 -#define R_PARISC_DIR14DR 84 -#define R_PARISC_DIR16F 85 -#define R_PARISC_DIR16WF 86 -#define R_PARISC_DIR16DF 87 -#define R_PARISC_GPREL64 88 -#define R_PARISC_GPREL14WR 91 -#define R_PARISC_GPREL14DR 92 -#define R_PARISC_GPREL16F 93 -#define R_PARISC_GPREL16WF 94 -#define R_PARISC_GPREL16DF 95 -#define R_PARISC_LTOFF64 96 -#define R_PARISC_LTOFF14WR 99 -#define R_PARISC_LTOFF14DR 100 -#define R_PARISC_LTOFF16F 101 -#define R_PARISC_LTOFF16WF 102 -#define R_PARISC_LTOFF16DF 103 -#define R_PARISC_SECREL64 104 -#define R_PARISC_SEGREL64 112 -#define R_PARISC_PLTOFF14WR 115 -#define R_PARISC_PLTOFF14DR 116 -#define R_PARISC_PLTOFF16F 117 -#define R_PARISC_PLTOFF16WF 118 -#define R_PARISC_PLTOFF16DF 119 -#define R_PARISC_LTOFF_FPTR64 120 -#define R_PARISC_LTOFF_FPTR14WR 123 -#define R_PARISC_LTOFF_FPTR14DR 124 -#define R_PARISC_LTOFF_FPTR16F 125 -#define R_PARISC_LTOFF_FPTR16WF 126 -#define R_PARISC_LTOFF_FPTR16DF 127 -#define R_PARISC_LORESERVE 128 -#define R_PARISC_COPY 128 -#define R_PARISC_IPLT 129 -#define R_PARISC_EPLT 130 -#define R_PARISC_TPREL32 153 -#define R_PARISC_TPREL21L 154 -#define R_PARISC_TPREL14R 158 -#define R_PARISC_LTOFF_TP21L 162 -#define R_PARISC_LTOFF_TP14R 166 -#define R_PARISC_LTOFF_TP14F 167 -#define R_PARISC_TPREL64 216 -#define R_PARISC_TPREL14WR 219 -#define R_PARISC_TPREL14DR 220 -#define R_PARISC_TPREL16F 221 -#define R_PARISC_TPREL16WF 222 -#define R_PARISC_TPREL16DF 223 -#define R_PARISC_LTOFF_TP64 224 -#define R_PARISC_LTOFF_TP14WR 227 -#define R_PARISC_LTOFF_TP14DR 228 -#define R_PARISC_LTOFF_TP16F 229 -#define R_PARISC_LTOFF_TP16WF 230 -#define R_PARISC_LTOFF_TP16DF 231 -#define R_PARISC_GNU_VTENTRY 232 -#define R_PARISC_GNU_VTINHERIT 233 -#define R_PARISC_TLS_GD21L 234 -#define R_PARISC_TLS_GD14R 235 -#define R_PARISC_TLS_GDCALL 236 -#define R_PARISC_TLS_LDM21L 237 -#define R_PARISC_TLS_LDM14R 238 -#define R_PARISC_TLS_LDMCALL 239 -#define R_PARISC_TLS_LDO21L 240 -#define R_PARISC_TLS_LDO14R 241 -#define R_PARISC_TLS_DTPMOD32 242 -#define R_PARISC_TLS_DTPMOD64 243 -#define R_PARISC_TLS_DTPOFF32 244 -#define R_PARISC_TLS_DTPOFF64 245 -#define R_PARISC_TLS_LE21L R_PARISC_TPREL21L -#define R_PARISC_TLS_LE14R R_PARISC_TPREL14R -#define R_PARISC_TLS_IE21L R_PARISC_LTOFF_TP21L -#define R_PARISC_TLS_IE14R R_PARISC_LTOFF_TP14R -#define R_PARISC_TLS_TPREL32 R_PARISC_TPREL32 -#define R_PARISC_TLS_TPREL64 R_PARISC_TPREL64 -#define R_PARISC_HIRESERVE 255 - - - -#define PT_HP_TLS (PT_LOOS + 0x0) -#define PT_HP_CORE_NONE (PT_LOOS + 0x1) -#define PT_HP_CORE_VERSION (PT_LOOS + 0x2) -#define PT_HP_CORE_KERNEL (PT_LOOS + 0x3) -#define PT_HP_CORE_COMM (PT_LOOS + 0x4) -#define PT_HP_CORE_PROC (PT_LOOS + 0x5) -#define PT_HP_CORE_LOADABLE (PT_LOOS + 0x6) -#define PT_HP_CORE_STACK (PT_LOOS + 0x7) -#define PT_HP_CORE_SHM (PT_LOOS + 0x8) -#define PT_HP_CORE_MMF (PT_LOOS + 0x9) -#define PT_HP_PARALLEL (PT_LOOS + 0x10) -#define PT_HP_FASTBIND (PT_LOOS + 0x11) -#define PT_HP_OPT_ANNOT (PT_LOOS + 0x12) -#define PT_HP_HSL_ANNOT (PT_LOOS + 0x13) -#define PT_HP_STACK (PT_LOOS + 0x14) - -#define PT_PARISC_ARCHEXT 0x70000000 -#define PT_PARISC_UNWIND 0x70000001 - - - -#define PF_PARISC_SBP 0x08000000 - -#define PF_HP_PAGE_SIZE 0x00100000 -#define PF_HP_FAR_SHARED 0x00200000 -#define PF_HP_NEAR_SHARED 0x00400000 -#define PF_HP_CODE 0x01000000 -#define PF_HP_MODIFY 0x02000000 -#define PF_HP_LAZYSWAP 0x04000000 -#define PF_HP_SBP 0x08000000 - - - - - - -#define EF_ALPHA_32BIT 1 -#define EF_ALPHA_CANRELAX 2 - - - - -#define SHT_ALPHA_DEBUG 0x70000001 -#define SHT_ALPHA_REGINFO 0x70000002 - - - -#define SHF_ALPHA_GPREL 0x10000000 - - -#define STO_ALPHA_NOPV 0x80 -#define STO_ALPHA_STD_GPLOAD 0x88 - - - -#define R_ALPHA_NONE 0 -#define R_ALPHA_REFLONG 1 -#define R_ALPHA_REFQUAD 2 -#define R_ALPHA_GPREL32 3 -#define R_ALPHA_LITERAL 4 -#define R_ALPHA_LITUSE 5 -#define R_ALPHA_GPDISP 6 -#define R_ALPHA_BRADDR 7 -#define R_ALPHA_HINT 8 -#define R_ALPHA_SREL16 9 -#define R_ALPHA_SREL32 10 -#define R_ALPHA_SREL64 11 -#define R_ALPHA_GPRELHIGH 17 -#define R_ALPHA_GPRELLOW 18 -#define R_ALPHA_GPREL16 19 -#define R_ALPHA_COPY 24 -#define R_ALPHA_GLOB_DAT 25 -#define R_ALPHA_JMP_SLOT 26 -#define R_ALPHA_RELATIVE 27 -#define R_ALPHA_TLS_GD_HI 28 -#define R_ALPHA_TLSGD 29 -#define R_ALPHA_TLS_LDM 30 -#define R_ALPHA_DTPMOD64 31 -#define R_ALPHA_GOTDTPREL 32 -#define R_ALPHA_DTPREL64 33 -#define R_ALPHA_DTPRELHI 34 -#define R_ALPHA_DTPRELLO 35 -#define R_ALPHA_DTPREL16 36 -#define R_ALPHA_GOTTPREL 37 -#define R_ALPHA_TPREL64 38 -#define R_ALPHA_TPRELHI 39 -#define R_ALPHA_TPRELLO 40 -#define R_ALPHA_TPREL16 41 - -#define R_ALPHA_NUM 46 - - -#define LITUSE_ALPHA_ADDR 0 -#define LITUSE_ALPHA_BASE 1 -#define LITUSE_ALPHA_BYTOFF 2 -#define LITUSE_ALPHA_JSR 3 -#define LITUSE_ALPHA_TLS_GD 4 -#define LITUSE_ALPHA_TLS_LDM 5 - - -#define DT_ALPHA_PLTRO (DT_LOPROC + 0) -#define DT_ALPHA_NUM 1 - - - - -#define EF_PPC_EMB 0x80000000 - - -#define EF_PPC_RELOCATABLE 0x00010000 -#define EF_PPC_RELOCATABLE_LIB 0x00008000 - - - -#define R_PPC_NONE 0 -#define R_PPC_ADDR32 1 -#define R_PPC_ADDR24 2 -#define R_PPC_ADDR16 3 -#define R_PPC_ADDR16_LO 4 -#define R_PPC_ADDR16_HI 5 -#define R_PPC_ADDR16_HA 6 -#define R_PPC_ADDR14 7 -#define R_PPC_ADDR14_BRTAKEN 8 -#define R_PPC_ADDR14_BRNTAKEN 9 -#define R_PPC_REL24 10 -#define R_PPC_REL14 11 -#define R_PPC_REL14_BRTAKEN 12 -#define R_PPC_REL14_BRNTAKEN 13 -#define R_PPC_GOT16 14 -#define R_PPC_GOT16_LO 15 -#define R_PPC_GOT16_HI 16 -#define R_PPC_GOT16_HA 17 -#define R_PPC_PLTREL24 18 -#define R_PPC_COPY 19 -#define R_PPC_GLOB_DAT 20 -#define R_PPC_JMP_SLOT 21 -#define R_PPC_RELATIVE 22 -#define R_PPC_LOCAL24PC 23 -#define R_PPC_UADDR32 24 -#define R_PPC_UADDR16 25 -#define R_PPC_REL32 26 -#define R_PPC_PLT32 27 -#define R_PPC_PLTREL32 28 -#define R_PPC_PLT16_LO 29 -#define R_PPC_PLT16_HI 30 -#define R_PPC_PLT16_HA 31 -#define R_PPC_SDAREL16 32 -#define R_PPC_SECTOFF 33 -#define R_PPC_SECTOFF_LO 34 -#define R_PPC_SECTOFF_HI 35 -#define R_PPC_SECTOFF_HA 36 - - -#define R_PPC_TLS 67 -#define R_PPC_DTPMOD32 68 -#define R_PPC_TPREL16 69 -#define R_PPC_TPREL16_LO 70 -#define R_PPC_TPREL16_HI 71 -#define R_PPC_TPREL16_HA 72 -#define R_PPC_TPREL32 73 -#define R_PPC_DTPREL16 74 -#define R_PPC_DTPREL16_LO 75 -#define R_PPC_DTPREL16_HI 76 -#define R_PPC_DTPREL16_HA 77 -#define R_PPC_DTPREL32 78 -#define R_PPC_GOT_TLSGD16 79 -#define R_PPC_GOT_TLSGD16_LO 80 -#define R_PPC_GOT_TLSGD16_HI 81 -#define R_PPC_GOT_TLSGD16_HA 82 -#define R_PPC_GOT_TLSLD16 83 -#define R_PPC_GOT_TLSLD16_LO 84 -#define R_PPC_GOT_TLSLD16_HI 85 -#define R_PPC_GOT_TLSLD16_HA 86 -#define R_PPC_GOT_TPREL16 87 -#define R_PPC_GOT_TPREL16_LO 88 -#define R_PPC_GOT_TPREL16_HI 89 -#define R_PPC_GOT_TPREL16_HA 90 -#define R_PPC_GOT_DTPREL16 91 -#define R_PPC_GOT_DTPREL16_LO 92 -#define R_PPC_GOT_DTPREL16_HI 93 -#define R_PPC_GOT_DTPREL16_HA 94 - - - -#define R_PPC_EMB_NADDR32 101 -#define R_PPC_EMB_NADDR16 102 -#define R_PPC_EMB_NADDR16_LO 103 -#define R_PPC_EMB_NADDR16_HI 104 -#define R_PPC_EMB_NADDR16_HA 105 -#define R_PPC_EMB_SDAI16 106 -#define R_PPC_EMB_SDA2I16 107 -#define R_PPC_EMB_SDA2REL 108 -#define R_PPC_EMB_SDA21 109 -#define R_PPC_EMB_MRKREF 110 -#define R_PPC_EMB_RELSEC16 111 -#define R_PPC_EMB_RELST_LO 112 -#define R_PPC_EMB_RELST_HI 113 -#define R_PPC_EMB_RELST_HA 114 -#define R_PPC_EMB_BIT_FLD 115 -#define R_PPC_EMB_RELSDA 116 - - -#define R_PPC_DIAB_SDA21_LO 180 -#define R_PPC_DIAB_SDA21_HI 181 -#define R_PPC_DIAB_SDA21_HA 182 -#define R_PPC_DIAB_RELSDA_LO 183 -#define R_PPC_DIAB_RELSDA_HI 184 -#define R_PPC_DIAB_RELSDA_HA 185 - - -#define R_PPC_IRELATIVE 248 - - -#define R_PPC_REL16 249 -#define R_PPC_REL16_LO 250 -#define R_PPC_REL16_HI 251 -#define R_PPC_REL16_HA 252 - - - -#define R_PPC_TOC16 255 - - -#define DT_PPC_GOT (DT_LOPROC + 0) -#define DT_PPC_NUM 1 - - -#define R_PPC64_NONE R_PPC_NONE -#define R_PPC64_ADDR32 R_PPC_ADDR32 -#define R_PPC64_ADDR24 R_PPC_ADDR24 -#define R_PPC64_ADDR16 R_PPC_ADDR16 -#define R_PPC64_ADDR16_LO R_PPC_ADDR16_LO -#define R_PPC64_ADDR16_HI R_PPC_ADDR16_HI -#define R_PPC64_ADDR16_HA R_PPC_ADDR16_HA -#define R_PPC64_ADDR14 R_PPC_ADDR14 -#define R_PPC64_ADDR14_BRTAKEN R_PPC_ADDR14_BRTAKEN -#define R_PPC64_ADDR14_BRNTAKEN R_PPC_ADDR14_BRNTAKEN -#define R_PPC64_REL24 R_PPC_REL24 -#define R_PPC64_REL14 R_PPC_REL14 -#define R_PPC64_REL14_BRTAKEN R_PPC_REL14_BRTAKEN -#define R_PPC64_REL14_BRNTAKEN R_PPC_REL14_BRNTAKEN -#define R_PPC64_GOT16 R_PPC_GOT16 -#define R_PPC64_GOT16_LO R_PPC_GOT16_LO -#define R_PPC64_GOT16_HI R_PPC_GOT16_HI -#define R_PPC64_GOT16_HA R_PPC_GOT16_HA - -#define R_PPC64_COPY R_PPC_COPY -#define R_PPC64_GLOB_DAT R_PPC_GLOB_DAT -#define R_PPC64_JMP_SLOT R_PPC_JMP_SLOT -#define R_PPC64_RELATIVE R_PPC_RELATIVE - -#define R_PPC64_UADDR32 R_PPC_UADDR32 -#define R_PPC64_UADDR16 R_PPC_UADDR16 -#define R_PPC64_REL32 R_PPC_REL32 -#define R_PPC64_PLT32 R_PPC_PLT32 -#define R_PPC64_PLTREL32 R_PPC_PLTREL32 -#define R_PPC64_PLT16_LO R_PPC_PLT16_LO -#define R_PPC64_PLT16_HI R_PPC_PLT16_HI -#define R_PPC64_PLT16_HA R_PPC_PLT16_HA - -#define R_PPC64_SECTOFF R_PPC_SECTOFF -#define R_PPC64_SECTOFF_LO R_PPC_SECTOFF_LO -#define R_PPC64_SECTOFF_HI R_PPC_SECTOFF_HI -#define R_PPC64_SECTOFF_HA R_PPC_SECTOFF_HA -#define R_PPC64_ADDR30 37 -#define R_PPC64_ADDR64 38 -#define R_PPC64_ADDR16_HIGHER 39 -#define R_PPC64_ADDR16_HIGHERA 40 -#define R_PPC64_ADDR16_HIGHEST 41 -#define R_PPC64_ADDR16_HIGHESTA 42 -#define R_PPC64_UADDR64 43 -#define R_PPC64_REL64 44 -#define R_PPC64_PLT64 45 -#define R_PPC64_PLTREL64 46 -#define R_PPC64_TOC16 47 -#define R_PPC64_TOC16_LO 48 -#define R_PPC64_TOC16_HI 49 -#define R_PPC64_TOC16_HA 50 -#define R_PPC64_TOC 51 -#define R_PPC64_PLTGOT16 52 -#define R_PPC64_PLTGOT16_LO 53 -#define R_PPC64_PLTGOT16_HI 54 -#define R_PPC64_PLTGOT16_HA 55 - -#define R_PPC64_ADDR16_DS 56 -#define R_PPC64_ADDR16_LO_DS 57 -#define R_PPC64_GOT16_DS 58 -#define R_PPC64_GOT16_LO_DS 59 -#define R_PPC64_PLT16_LO_DS 60 -#define R_PPC64_SECTOFF_DS 61 -#define R_PPC64_SECTOFF_LO_DS 62 -#define R_PPC64_TOC16_DS 63 -#define R_PPC64_TOC16_LO_DS 64 -#define R_PPC64_PLTGOT16_DS 65 -#define R_PPC64_PLTGOT16_LO_DS 66 - - -#define R_PPC64_TLS 67 -#define R_PPC64_DTPMOD64 68 -#define R_PPC64_TPREL16 69 -#define R_PPC64_TPREL16_LO 70 -#define R_PPC64_TPREL16_HI 71 -#define R_PPC64_TPREL16_HA 72 -#define R_PPC64_TPREL64 73 -#define R_PPC64_DTPREL16 74 -#define R_PPC64_DTPREL16_LO 75 -#define R_PPC64_DTPREL16_HI 76 -#define R_PPC64_DTPREL16_HA 77 -#define R_PPC64_DTPREL64 78 -#define R_PPC64_GOT_TLSGD16 79 -#define R_PPC64_GOT_TLSGD16_LO 80 -#define R_PPC64_GOT_TLSGD16_HI 81 -#define R_PPC64_GOT_TLSGD16_HA 82 -#define R_PPC64_GOT_TLSLD16 83 -#define R_PPC64_GOT_TLSLD16_LO 84 -#define R_PPC64_GOT_TLSLD16_HI 85 -#define R_PPC64_GOT_TLSLD16_HA 86 -#define R_PPC64_GOT_TPREL16_DS 87 -#define R_PPC64_GOT_TPREL16_LO_DS 88 -#define R_PPC64_GOT_TPREL16_HI 89 -#define R_PPC64_GOT_TPREL16_HA 90 -#define R_PPC64_GOT_DTPREL16_DS 91 -#define R_PPC64_GOT_DTPREL16_LO_DS 92 -#define R_PPC64_GOT_DTPREL16_HI 93 -#define R_PPC64_GOT_DTPREL16_HA 94 -#define R_PPC64_TPREL16_DS 95 -#define R_PPC64_TPREL16_LO_DS 96 -#define R_PPC64_TPREL16_HIGHER 97 -#define R_PPC64_TPREL16_HIGHERA 98 -#define R_PPC64_TPREL16_HIGHEST 99 -#define R_PPC64_TPREL16_HIGHESTA 100 -#define R_PPC64_DTPREL16_DS 101 -#define R_PPC64_DTPREL16_LO_DS 102 -#define R_PPC64_DTPREL16_HIGHER 103 -#define R_PPC64_DTPREL16_HIGHERA 104 -#define R_PPC64_DTPREL16_HIGHEST 105 -#define R_PPC64_DTPREL16_HIGHESTA 106 - - -#define R_PPC64_JMP_IREL 247 -#define R_PPC64_IRELATIVE 248 -#define R_PPC64_REL16 249 -#define R_PPC64_REL16_LO 250 -#define R_PPC64_REL16_HI 251 -#define R_PPC64_REL16_HA 252 - - -#define DT_PPC64_GLINK (DT_LOPROC + 0) -#define DT_PPC64_OPD (DT_LOPROC + 1) -#define DT_PPC64_OPDSZ (DT_LOPROC + 2) -#define DT_PPC64_NUM 3 - - - - - -#define EF_ARM_RELEXEC 0x01 -#define EF_ARM_HASENTRY 0x02 -#define EF_ARM_INTERWORK 0x04 -#define EF_ARM_APCS_26 0x08 -#define EF_ARM_APCS_FLOAT 0x10 -#define EF_ARM_PIC 0x20 -#define EF_ARM_ALIGN8 0x40 -#define EF_ARM_NEW_ABI 0x80 -#define EF_ARM_OLD_ABI 0x100 -#define EF_ARM_SOFT_FLOAT 0x200 -#define EF_ARM_VFP_FLOAT 0x400 -#define EF_ARM_MAVERICK_FLOAT 0x800 - - - - -#define EF_ARM_SYMSARESORTED 0x04 -#define EF_ARM_DYNSYMSUSESEGIDX 0x08 -#define EF_ARM_MAPSYMSFIRST 0x10 -#define EF_ARM_EABIMASK 0XFF000000 - - -#define EF_ARM_BE8 0x00800000 -#define EF_ARM_LE8 0x00400000 - -#define EF_ARM_EABI_VERSION(flags) ((flags) & EF_ARM_EABIMASK) -#define EF_ARM_EABI_UNKNOWN 0x00000000 -#define EF_ARM_EABI_VER1 0x01000000 -#define EF_ARM_EABI_VER2 0x02000000 -#define EF_ARM_EABI_VER3 0x03000000 -#define EF_ARM_EABI_VER4 0x04000000 -#define EF_ARM_EABI_VER5 0x05000000 - - -#define STT_ARM_TFUNC STT_LOPROC -#define STT_ARM_16BIT STT_HIPROC - - -#define SHF_ARM_ENTRYSECT 0x10000000 -#define SHF_ARM_COMDEF 0x80000000 - - - -#define PF_ARM_SB 0x10000000 - -#define PF_ARM_PI 0x20000000 -#define PF_ARM_ABS 0x40000000 - - -#define PT_ARM_EXIDX (PT_LOPROC + 1) - - -#define SHT_ARM_EXIDX (SHT_LOPROC + 1) -#define SHT_ARM_PREEMPTMAP (SHT_LOPROC + 2) -#define SHT_ARM_ATTRIBUTES (SHT_LOPROC + 3) - - - - -#define R_ARM_NONE 0 -#define R_ARM_PC24 1 -#define R_ARM_ABS32 2 -#define R_ARM_REL32 3 -#define R_ARM_PC13 4 -#define R_ARM_ABS16 5 -#define R_ARM_ABS12 6 -#define R_ARM_THM_ABS5 7 -#define R_ARM_ABS8 8 -#define R_ARM_SBREL32 9 -#define R_ARM_THM_PC22 10 -#define R_ARM_THM_PC8 11 -#define R_ARM_AMP_VCALL9 12 -#define R_ARM_SWI24 13 -#define R_ARM_THM_SWI8 14 -#define R_ARM_XPC25 15 -#define R_ARM_THM_XPC22 16 -#define R_ARM_TLS_DTPMOD32 17 -#define R_ARM_TLS_DTPOFF32 18 -#define R_ARM_TLS_TPOFF32 19 -#define R_ARM_COPY 20 -#define R_ARM_GLOB_DAT 21 -#define R_ARM_JUMP_SLOT 22 -#define R_ARM_RELATIVE 23 -#define R_ARM_GOTOFF 24 -#define R_ARM_GOTPC 25 -#define R_ARM_GOT32 26 -#define R_ARM_PLT32 27 -#define R_ARM_ALU_PCREL_7_0 32 -#define R_ARM_ALU_PCREL_15_8 33 -#define R_ARM_ALU_PCREL_23_15 34 -#define R_ARM_LDR_SBREL_11_0 35 -#define R_ARM_ALU_SBREL_19_12 36 -#define R_ARM_ALU_SBREL_27_20 37 -#define R_ARM_GNU_VTENTRY 100 -#define R_ARM_GNU_VTINHERIT 101 -#define R_ARM_THM_PC11 102 -#define R_ARM_THM_PC9 103 -#define R_ARM_TLS_GD32 104 - -#define R_ARM_TLS_LDM32 105 - -#define R_ARM_TLS_LDO32 106 - -#define R_ARM_TLS_IE32 107 - -#define R_ARM_TLS_LE32 108 - -#define R_ARM_RXPC25 249 -#define R_ARM_RSBREL32 250 -#define R_ARM_THM_RPC22 251 -#define R_ARM_RREL32 252 -#define R_ARM_RABS22 253 -#define R_ARM_RPC24 254 -#define R_ARM_RBASE 255 - -#define R_ARM_NUM 256 - - - - -#define EF_IA_64_MASKOS 0x0000000f -#define EF_IA_64_ABI64 0x00000010 -#define EF_IA_64_ARCH 0xff000000 - - -#define PT_IA_64_ARCHEXT (PT_LOPROC + 0) -#define PT_IA_64_UNWIND (PT_LOPROC + 1) -#define PT_IA_64_HP_OPT_ANOT (PT_LOOS + 0x12) -#define PT_IA_64_HP_HSL_ANOT (PT_LOOS + 0x13) -#define PT_IA_64_HP_STACK (PT_LOOS + 0x14) - - -#define PF_IA_64_NORECOV 0x80000000 - - -#define SHT_IA_64_EXT (SHT_LOPROC + 0) -#define SHT_IA_64_UNWIND (SHT_LOPROC + 1) - - -#define SHF_IA_64_SHORT 0x10000000 -#define SHF_IA_64_NORECOV 0x20000000 - - -#define DT_IA_64_PLT_RESERVE (DT_LOPROC + 0) -#define DT_IA_64_NUM 1 - - -#define R_IA64_NONE 0x00 -#define R_IA64_IMM14 0x21 -#define R_IA64_IMM22 0x22 -#define R_IA64_IMM64 0x23 -#define R_IA64_DIR32MSB 0x24 -#define R_IA64_DIR32LSB 0x25 -#define R_IA64_DIR64MSB 0x26 -#define R_IA64_DIR64LSB 0x27 -#define R_IA64_GPREL22 0x2a -#define R_IA64_GPREL64I 0x2b -#define R_IA64_GPREL32MSB 0x2c -#define R_IA64_GPREL32LSB 0x2d -#define R_IA64_GPREL64MSB 0x2e -#define R_IA64_GPREL64LSB 0x2f -#define R_IA64_LTOFF22 0x32 -#define R_IA64_LTOFF64I 0x33 -#define R_IA64_PLTOFF22 0x3a -#define R_IA64_PLTOFF64I 0x3b -#define R_IA64_PLTOFF64MSB 0x3e -#define R_IA64_PLTOFF64LSB 0x3f -#define R_IA64_FPTR64I 0x43 -#define R_IA64_FPTR32MSB 0x44 -#define R_IA64_FPTR32LSB 0x45 -#define R_IA64_FPTR64MSB 0x46 -#define R_IA64_FPTR64LSB 0x47 -#define R_IA64_PCREL60B 0x48 -#define R_IA64_PCREL21B 0x49 -#define R_IA64_PCREL21M 0x4a -#define R_IA64_PCREL21F 0x4b -#define R_IA64_PCREL32MSB 0x4c -#define R_IA64_PCREL32LSB 0x4d -#define R_IA64_PCREL64MSB 0x4e -#define R_IA64_PCREL64LSB 0x4f -#define R_IA64_LTOFF_FPTR22 0x52 -#define R_IA64_LTOFF_FPTR64I 0x53 -#define R_IA64_LTOFF_FPTR32MSB 0x54 -#define R_IA64_LTOFF_FPTR32LSB 0x55 -#define R_IA64_LTOFF_FPTR64MSB 0x56 -#define R_IA64_LTOFF_FPTR64LSB 0x57 -#define R_IA64_SEGREL32MSB 0x5c -#define R_IA64_SEGREL32LSB 0x5d -#define R_IA64_SEGREL64MSB 0x5e -#define R_IA64_SEGREL64LSB 0x5f -#define R_IA64_SECREL32MSB 0x64 -#define R_IA64_SECREL32LSB 0x65 -#define R_IA64_SECREL64MSB 0x66 -#define R_IA64_SECREL64LSB 0x67 -#define R_IA64_REL32MSB 0x6c -#define R_IA64_REL32LSB 0x6d -#define R_IA64_REL64MSB 0x6e -#define R_IA64_REL64LSB 0x6f -#define R_IA64_LTV32MSB 0x74 -#define R_IA64_LTV32LSB 0x75 -#define R_IA64_LTV64MSB 0x76 -#define R_IA64_LTV64LSB 0x77 -#define R_IA64_PCREL21BI 0x79 -#define R_IA64_PCREL22 0x7a -#define R_IA64_PCREL64I 0x7b -#define R_IA64_IPLTMSB 0x80 -#define R_IA64_IPLTLSB 0x81 -#define R_IA64_COPY 0x84 -#define R_IA64_SUB 0x85 -#define R_IA64_LTOFF22X 0x86 -#define R_IA64_LDXMOV 0x87 -#define R_IA64_TPREL14 0x91 -#define R_IA64_TPREL22 0x92 -#define R_IA64_TPREL64I 0x93 -#define R_IA64_TPREL64MSB 0x96 -#define R_IA64_TPREL64LSB 0x97 -#define R_IA64_LTOFF_TPREL22 0x9a -#define R_IA64_DTPMOD64MSB 0xa6 -#define R_IA64_DTPMOD64LSB 0xa7 -#define R_IA64_LTOFF_DTPMOD22 0xaa -#define R_IA64_DTPREL14 0xb1 -#define R_IA64_DTPREL22 0xb2 -#define R_IA64_DTPREL64I 0xb3 -#define R_IA64_DTPREL32MSB 0xb4 -#define R_IA64_DTPREL32LSB 0xb5 -#define R_IA64_DTPREL64MSB 0xb6 -#define R_IA64_DTPREL64LSB 0xb7 -#define R_IA64_LTOFF_DTPREL22 0xba - - - - -#define R_SH_NONE 0 -#define R_SH_DIR32 1 -#define R_SH_REL32 2 -#define R_SH_DIR8WPN 3 -#define R_SH_IND12W 4 -#define R_SH_DIR8WPL 5 -#define R_SH_DIR8WPZ 6 -#define R_SH_DIR8BP 7 -#define R_SH_DIR8W 8 -#define R_SH_DIR8L 9 -#define R_SH_SWITCH16 25 -#define R_SH_SWITCH32 26 -#define R_SH_USES 27 -#define R_SH_COUNT 28 -#define R_SH_ALIGN 29 -#define R_SH_CODE 30 -#define R_SH_DATA 31 -#define R_SH_LABEL 32 -#define R_SH_SWITCH8 33 -#define R_SH_GNU_VTINHERIT 34 -#define R_SH_GNU_VTENTRY 35 -#define R_SH_TLS_GD_32 144 -#define R_SH_TLS_LD_32 145 -#define R_SH_TLS_LDO_32 146 -#define R_SH_TLS_IE_32 147 -#define R_SH_TLS_LE_32 148 -#define R_SH_TLS_DTPMOD32 149 -#define R_SH_TLS_DTPOFF32 150 -#define R_SH_TLS_TPOFF32 151 -#define R_SH_GOT32 160 -#define R_SH_PLT32 161 -#define R_SH_COPY 162 -#define R_SH_GLOB_DAT 163 -#define R_SH_JMP_SLOT 164 -#define R_SH_RELATIVE 165 -#define R_SH_GOTOFF 166 -#define R_SH_GOTPC 167 - -#define R_SH_NUM 256 - - - -#define R_390_NONE 0 -#define R_390_8 1 -#define R_390_12 2 -#define R_390_16 3 -#define R_390_32 4 -#define R_390_PC32 5 -#define R_390_GOT12 6 -#define R_390_GOT32 7 -#define R_390_PLT32 8 -#define R_390_COPY 9 -#define R_390_GLOB_DAT 10 -#define R_390_JMP_SLOT 11 -#define R_390_RELATIVE 12 -#define R_390_GOTOFF32 13 -#define R_390_GOTPC 14 -#define R_390_GOT16 15 -#define R_390_PC16 16 -#define R_390_PC16DBL 17 -#define R_390_PLT16DBL 18 -#define R_390_PC32DBL 19 -#define R_390_PLT32DBL 20 -#define R_390_GOTPCDBL 21 -#define R_390_64 22 -#define R_390_PC64 23 -#define R_390_GOT64 24 -#define R_390_PLT64 25 -#define R_390_GOTENT 26 -#define R_390_GOTOFF16 27 -#define R_390_GOTOFF64 28 -#define R_390_GOTPLT12 29 -#define R_390_GOTPLT16 30 -#define R_390_GOTPLT32 31 -#define R_390_GOTPLT64 32 -#define R_390_GOTPLTENT 33 -#define R_390_PLTOFF16 34 -#define R_390_PLTOFF32 35 -#define R_390_PLTOFF64 36 -#define R_390_TLS_LOAD 37 -#define R_390_TLS_GDCALL 38 - -#define R_390_TLS_LDCALL 39 - -#define R_390_TLS_GD32 40 - -#define R_390_TLS_GD64 41 - -#define R_390_TLS_GOTIE12 42 - -#define R_390_TLS_GOTIE32 43 - -#define R_390_TLS_GOTIE64 44 - -#define R_390_TLS_LDM32 45 - -#define R_390_TLS_LDM64 46 - -#define R_390_TLS_IE32 47 - -#define R_390_TLS_IE64 48 - -#define R_390_TLS_IEENT 49 - -#define R_390_TLS_LE32 50 - -#define R_390_TLS_LE64 51 - -#define R_390_TLS_LDO32 52 - -#define R_390_TLS_LDO64 53 - -#define R_390_TLS_DTPMOD 54 -#define R_390_TLS_DTPOFF 55 -#define R_390_TLS_TPOFF 56 - -#define R_390_20 57 -#define R_390_GOT20 58 -#define R_390_GOTPLT20 59 -#define R_390_TLS_GOTIE20 60 - - -#define R_390_NUM 61 - - - -#define R_CRIS_NONE 0 -#define R_CRIS_8 1 -#define R_CRIS_16 2 -#define R_CRIS_32 3 -#define R_CRIS_8_PCREL 4 -#define R_CRIS_16_PCREL 5 -#define R_CRIS_32_PCREL 6 -#define R_CRIS_GNU_VTINHERIT 7 -#define R_CRIS_GNU_VTENTRY 8 -#define R_CRIS_COPY 9 -#define R_CRIS_GLOB_DAT 10 -#define R_CRIS_JUMP_SLOT 11 -#define R_CRIS_RELATIVE 12 -#define R_CRIS_16_GOT 13 -#define R_CRIS_32_GOT 14 -#define R_CRIS_16_GOTPLT 15 -#define R_CRIS_32_GOTPLT 16 -#define R_CRIS_32_GOTREL 17 -#define R_CRIS_32_PLT_GOTREL 18 -#define R_CRIS_32_PLT_PCREL 19 - -#define R_CRIS_NUM 20 - - - -#define R_X86_64_NONE 0 -#define R_X86_64_64 1 -#define R_X86_64_PC32 2 -#define R_X86_64_GOT32 3 -#define R_X86_64_PLT32 4 -#define R_X86_64_COPY 5 -#define R_X86_64_GLOB_DAT 6 -#define R_X86_64_JUMP_SLOT 7 -#define R_X86_64_RELATIVE 8 -#define R_X86_64_GOTPCREL 9 - -#define R_X86_64_32 10 -#define R_X86_64_32S 11 -#define R_X86_64_16 12 -#define R_X86_64_PC16 13 -#define R_X86_64_8 14 -#define R_X86_64_PC8 15 -#define R_X86_64_DTPMOD64 16 -#define R_X86_64_DTPOFF64 17 -#define R_X86_64_TPOFF64 18 -#define R_X86_64_TLSGD 19 - -#define R_X86_64_TLSLD 20 - -#define R_X86_64_DTPOFF32 21 -#define R_X86_64_GOTTPOFF 22 - -#define R_X86_64_TPOFF32 23 -#define R_X86_64_PC64 24 -#define R_X86_64_GOTOFF64 25 -#define R_X86_64_GOTPC32 26 - - -#define R_X86_64_GOTPC32_TLSDESC 34 -#define R_X86_64_TLSDESC_CALL 35 - -#define R_X86_64_TLSDESC 36 -#define R_X86_64_IRELATIVE 37 - -#define R_X86_64_NUM 38 - - - -#define R_MN10300_NONE 0 -#define R_MN10300_32 1 -#define R_MN10300_16 2 -#define R_MN10300_8 3 -#define R_MN10300_PCREL32 4 -#define R_MN10300_PCREL16 5 -#define R_MN10300_PCREL8 6 -#define R_MN10300_GNU_VTINHERIT 7 -#define R_MN10300_GNU_VTENTRY 8 -#define R_MN10300_24 9 -#define R_MN10300_GOTPC32 10 -#define R_MN10300_GOTPC16 11 -#define R_MN10300_GOTOFF32 12 -#define R_MN10300_GOTOFF24 13 -#define R_MN10300_GOTOFF16 14 -#define R_MN10300_PLT32 15 -#define R_MN10300_PLT16 16 -#define R_MN10300_GOT32 17 -#define R_MN10300_GOT24 18 -#define R_MN10300_GOT16 19 -#define R_MN10300_COPY 20 -#define R_MN10300_GLOB_DAT 21 -#define R_MN10300_JMP_SLOT 22 -#define R_MN10300_RELATIVE 23 - -#define R_MN10300_NUM 24 - - - -#define R_M32R_NONE 0 -#define R_M32R_16 1 -#define R_M32R_32 2 -#define R_M32R_24 3 -#define R_M32R_10_PCREL 4 -#define R_M32R_18_PCREL 5 -#define R_M32R_26_PCREL 6 -#define R_M32R_HI16_ULO 7 -#define R_M32R_HI16_SLO 8 -#define R_M32R_LO16 9 -#define R_M32R_SDA16 10 -#define R_M32R_GNU_VTINHERIT 11 -#define R_M32R_GNU_VTENTRY 12 - -#define R_M32R_16_RELA 33 -#define R_M32R_32_RELA 34 -#define R_M32R_24_RELA 35 -#define R_M32R_10_PCREL_RELA 36 -#define R_M32R_18_PCREL_RELA 37 -#define R_M32R_26_PCREL_RELA 38 -#define R_M32R_HI16_ULO_RELA 39 -#define R_M32R_HI16_SLO_RELA 40 -#define R_M32R_LO16_RELA 41 -#define R_M32R_SDA16_RELA 42 -#define R_M32R_RELA_GNU_VTINHERIT 43 -#define R_M32R_RELA_GNU_VTENTRY 44 -#define R_M32R_REL32 45 - -#define R_M32R_GOT24 48 -#define R_M32R_26_PLTREL 49 -#define R_M32R_COPY 50 -#define R_M32R_GLOB_DAT 51 -#define R_M32R_JMP_SLOT 52 -#define R_M32R_RELATIVE 53 -#define R_M32R_GOTOFF 54 -#define R_M32R_GOTPC24 55 -#define R_M32R_GOT16_HI_ULO 56 - -#define R_M32R_GOT16_HI_SLO 57 - -#define R_M32R_GOT16_LO 58 -#define R_M32R_GOTPC_HI_ULO 59 - -#define R_M32R_GOTPC_HI_SLO 60 - -#define R_M32R_GOTPC_LO 61 - -#define R_M32R_GOTOFF_HI_ULO 62 - -#define R_M32R_GOTOFF_HI_SLO 63 - -#define R_M32R_GOTOFF_LO 64 -#define R_M32R_NUM 256 - -#ifdef __cplusplus -} -#endif - - -#endif diff --git a/05/musl-final/include/endian.h b/05/musl-final/include/endian.h deleted file mode 100644 index bcf6766..0000000 --- a/05/musl-final/include/endian.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef _ENDIAN_H -#define _ENDIAN_H - -#define __LITTLE_ENDIAN 1234 -#define __BIG_ENDIAN 4321 -#define __PDP_ENDIAN 3412 - -#include - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define BIG_ENDIAN __BIG_ENDIAN -#define LITTLE_ENDIAN __LITTLE_ENDIAN -#define PDP_ENDIAN __PDP_ENDIAN -#define BYTE_ORDER __BYTE_ORDER -#endif - -#endif diff --git a/05/musl-final/include/errno.h b/05/musl-final/include/errno.h deleted file mode 100644 index d9c2c9c..0000000 --- a/05/musl-final/include/errno.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef _ERRNO_H -#define _ERRNO_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -extern int *__errno_location(void); -#define errno (*__errno_location()) - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/05/musl-final/include/fcntl.h b/05/musl-final/include/fcntl.h deleted file mode 100644 index 61a6cb5..0000000 --- a/05/musl-final/include/fcntl.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef _FCNTL_H -#define _FCNTL_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define __NEED_off_t -#define __NEED_pid_t -#define __NEED_mode_t - -#include - -#include - -struct flock -{ - short l_type; - short l_whence; - off_t l_start; - off_t l_len; - pid_t l_pid; -}; - -int creat(const char *, mode_t); -int fcntl(int, int, ...); -int open(const char *, int, ...); -int openat(int, const char *, int, ...); -int posix_fadvise(int, off_t, off_t, int); -int posix_fallocate(int, off_t, off_t); - -#undef SEEK_SET -#undef SEEK_CUR -#undef SEEK_END -#define SEEK_SET 0 -#define SEEK_CUR 1 -#define SEEK_END 2 - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/05/musl-final/include/features.h b/05/musl-final/include/features.h deleted file mode 100644 index 851afb6..0000000 --- a/05/musl-final/include/features.h +++ /dev/null @@ -1 +0,0 @@ -#warning "features.h is bogus" diff --git a/05/musl-final/include/fenv.h b/05/musl-final/include/fenv.h deleted file mode 100644 index 05de990..0000000 --- a/05/musl-final/include/fenv.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef _FENV_H -#define _FENV_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -int feclearexcept(int); -int fegetexceptflag(fexcept_t *, int); -int feraiseexcept(int); -int fesetexceptflag(const fexcept_t *, int); -int fetestexcept(int); - -int fegetround(void); -int fesetround(int); - -int fegetenv(fenv_t *); -int feholdexcept(fenv_t *); -int fesetenv(const fenv_t *); -int feupdateenv(const fenv_t *); - -#ifdef __cplusplus -} -#endif -#endif - diff --git a/05/musl-final/include/float.h b/05/musl-final/include/float.h deleted file mode 100644 index ef91f37..0000000 --- a/05/musl-final/include/float.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef _FLOAT_H -#define _FLOAT_H - -#define FLT_RADIX 2 - -#define FLT_MIN 1.17549435e-38F -#define FLT_MAX 3.40282347e+38F -#define FLT_EPSILON 1.19209290e-07F - -#define FLT_MANT_DIG 24 -#define FLT_MIN_EXP (-125) -#define FLT_MAX_EXP 128 - -#define FLT_DIG 6 -#define FLT_MIN_10_EXP (-37) -#define FLT_MAX_10_EXP 38 - -#define DBL_MIN 2.2250738585072014e-308 -#define DBL_MAX 1.7976931348623157e+308 -#define DBL_EPSILON 2.2204460492503131e-16 - -#define DBL_MANT_DIG 53 -#define DBL_MIN_EXP (-1021) -#define DBL_MAX_EXP 1024 - -#define DBL_DIG 15 -#define DBL_MIN_10_EXP (-307) -#define DBL_MAX_10_EXP 308 - -#include - -#define DECIMAL_DIG LDBL_DIG - -#endif diff --git a/05/musl-final/include/fnmatch.h b/05/musl-final/include/fnmatch.h deleted file mode 100644 index b7aee50..0000000 --- a/05/musl-final/include/fnmatch.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef _FNMATCH_H -#define _FNMATCH_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define FNM_PATHNAME 0x1 -#define FNM_NOESCAPE 0x2 -#define FNM_PERIOD 0x4 - -#ifdef _GNU_SOURCE -#define FNM_CASEFOLD 0x10 -#endif - -#define FNM_NOMATCH 1 -#define FNM_NOSYS (-1) - -int fnmatch(const char *, const char *, int); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/05/musl-final/include/ftw.h b/05/musl-final/include/ftw.h deleted file mode 100644 index 8d31c6d..0000000 --- a/05/musl-final/include/ftw.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef _FTW_H -#define _FTW_H - -/* Normally we do not nest header includes. However useless bloat - * like ftw may be treated as a special case. Otherwise we would - * have to deal with duplicating all the stat.h mess. */ -#include - -#define FTW_F 1 -#define FTW_D 2 -#define FTW_DNR 3 -#define FTW_NS 4 -#define FTW_SL 5 -#define FTW_DP 6 -#define FTW_SLN 7 - -#define FTW_PHYS 1 -#define FTW_MOUNT 2 -#define FTW_CHDIR 4 -#define FTW_DEPTH 8 - -struct FTW -{ - int base; - int level; -}; - -int ftw(const char *, int (*)(const char *, const struct stat *, int), int); -int nftw(const char *, int (*)(const char *, const struct stat *, int, struct FTW *), int, int); - -#endif diff --git a/05/musl-final/include/getopt.h b/05/musl-final/include/getopt.h deleted file mode 100644 index 0de05ae..0000000 --- a/05/musl-final/include/getopt.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef _GETOPT_H -#define _GETOPT_H - -#ifdef __cplusplus -extern "C" { -#endif - -int getopt(int, char * const [], const char *); -extern char *optarg; -extern int optind, opterr, optopt; - -#ifdef _GNU_SOURCE -struct option -{ - const char *name; - int has_arg; - int *flag; - int val; -}; - -int getopt_long(int, char *const *, const char *, const struct option *, int *); -int getopt_long_only(int, char *const *, const char *, const struct option *, int *); - -#define no_argument 0 -#define required_argument 1 -#define optional_argument 2 -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/05/musl-final/include/glob.h b/05/musl-final/include/glob.h deleted file mode 100644 index 185912d..0000000 --- a/05/musl-final/include/glob.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef _GLOB_H -#define _GLOB_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define __NEED_size_t - -#include - -typedef struct { - size_t gl_pathc; - char **gl_pathv; - size_t gl_offs; - int __dummy1; - void *__dummy2[5]; -} glob_t; - -int glob(const char *, int, int (*)(const char *, int), glob_t *); -void globfree(glob_t *); - -#define GLOB_ERR 0x01 -#define GLOB_MARK 0x02 -#define GLOB_NOSORT 0x04 -#define GLOB_DOOFFS 0x08 -#define GLOB_NOCHECK 0x10 -#define GLOB_APPEND 0x20 -#define GLOB_NOESCAPE 0x40 -#define GLOB_PERIOD 0x80 - -#define GLOB_NOSPACE 1 -#define GLOB_ABORTED 2 -#define GLOB_NOMATCH 3 -#define GLOB_NOSYS 4 - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/05/musl-final/include/grp.h b/05/musl-final/include/grp.h deleted file mode 100644 index d4a3526..0000000 --- a/05/musl-final/include/grp.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef _GRP_H -#define _GRP_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define __NEED_size_t -#define __NEED_gid_t - -#include - -struct group -{ - char *gr_name; - char *gr_passwd; - gid_t gr_gid; - char **gr_mem; -}; - -struct group *getgrgid(gid_t); -struct group *getgrnam(const char *); - -int getgrgid_r(gid_t, struct group *, char *, size_t, struct group **); -int getgrnam_r(const char *, struct group *, char *, size_t, struct group **); - -struct group *getgrent(void); -void endgrent(void); -void setgrent(void); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/05/musl-final/include/iconv.h b/05/musl-final/include/iconv.h deleted file mode 100644 index f2ccaf8..0000000 --- a/05/musl-final/include/iconv.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef _ICONV_H -#define _ICONV_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define __NEED_size_t - -#include - -typedef void *iconv_t; - -iconv_t iconv_open(const char *, const char *); -size_t iconv(iconv_t, char **, size_t *, char **, size_t *); -int iconv_close(iconv_t); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/05/musl-final/include/inttypes.h b/05/musl-final/include/inttypes.h deleted file mode 100644 index 13ba6e0..0000000 --- a/05/musl-final/include/inttypes.h +++ /dev/null @@ -1,227 +0,0 @@ -#ifndef _INTTYPES_H -#define _INTTYPES_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_wchar_t -#include - -typedef struct { intmax_t quot, rem; } imaxdiv_t; - -intmax_t imaxabs(intmax_t); -imaxdiv_t imaxdiv(intmax_t, intmax_t); - -intmax_t strtoimax(const char *, char **, int); -uintmax_t strtoumax(const char *, char **, int); - -intmax_t wcstoimax(const wchar_t *, wchar_t **, int); -uintmax_t wcstoumax(const wchar_t *, wchar_t **, int); - -#if !defined __cplusplus || defined __STDC_FORMAT_MACROS - -#define __PRI64 "ll" -#define __PRIPTR "l" - -#define PRId8 "d" -#define PRId16 "d" -#define PRId32 "d" -#define PRId64 __PRI64 "d" - -#define PRIdLEAST8 "d" -#define PRIdLEAST16 "d" -#define PRIdLEAST32 "d" -#define PRIdLEAST64 __PRI64 "d" - -#define PRIdFAST8 "d" -#define PRIdFAST16 "d" -#define PRIdFAST32 "d" -#define PRIdFAST64 __PRI64 "d" - -#define PRIi8 "i" -#define PRIi16 "i" -#define PRIi32 "i" -#define PRIi64 __PRI64 "i" - -#define PRIiLEAST8 "i" -#define PRIiLEAST16 "i" -#define PRIiLEAST32 "i" -#define PRIiLEAST64 __PRI64 "i" - -#define PRIiFAST8 "i" -#define PRIiFAST16 "i" -#define PRIiFAST32 "i" -#define PRIiFAST64 __PRI64 "i" - -#define PRIo8 "o" -#define PRIo16 "o" -#define PRIo32 "o" -#define PRIo64 __PRI64 "o" - -#define PRIoLEAST8 "o" -#define PRIoLEAST16 "o" -#define PRIoLEAST32 "o" -#define PRIoLEAST64 __PRI64 "o" - -#define PRIoFAST8 "o" -#define PRIoFAST16 "o" -#define PRIoFAST32 "o" -#define PRIoFAST64 __PRI64 "o" - -#define PRIu8 "u" -#define PRIu16 "u" -#define PRIu32 "u" -#define PRIu64 __PRI64 "u" - -#define PRIuLEAST8 "u" -#define PRIuLEAST16 "u" -#define PRIuLEAST32 "u" -#define PRIuLEAST64 __PRI64 "u" - -#define PRIuFAST8 "u" -#define PRIuFAST16 "u" -#define PRIuFAST32 "u" -#define PRIuFAST64 __PRI64 "u" - -#define PRIx8 "x" -#define PRIx16 "x" -#define PRIx32 "x" -#define PRIx64 __PRI64 "x" - -#define PRIxLEAST8 "x" -#define PRIxLEAST16 "x" -#define PRIxLEAST32 "x" -#define PRIxLEAST64 __PRI64 "x" - -#define PRIxFAST8 "x" -#define PRIxFAST16 "x" -#define PRIxFAST32 "x" -#define PRIxFAST64 __PRI64 "x" - -#define PRIX8 "X" -#define PRIX16 "X" -#define PRIX32 "X" -#define PRIX64 __PRI64 "X" - -#define PRIXLEAST8 "X" -#define PRIXLEAST16 "X" -#define PRIXLEAST32 "X" -#define PRIXLEAST64 __PRI64 "X" - -#define PRIXFAST8 "X" -#define PRIXFAST16 "X" -#define PRIXFAST32 "X" -#define PRIXFAST64 __PRI64 "X" - -#define PRIdMAX __PRI64 "d" -#define PRIiMAX __PRI64 "i" -#define PRIoMAX __PRI64 "o" -#define PRIuMAX __PRI64 "u" -#define PRIxMAX __PRI64 "x" -#define PRIXMAX __PRI64 "X" - -#define PRIdPTR __PRIPTR "d" -#define PRIiPTR __PRIPTR "i" -#define PRIoPTR __PRIPTR "o" -#define PRIuPTR __PRIPTR "u" -#define PRIxPTR __PRIPTR "x" -#define PRIXPTR __PRIPTR "X" - -#define SCNd8 "hhd" -#define SCNd16 "hd" -#define SCNd32 "d" -#define SCNd64 __PRI64 "d" - -#define SCNdLEAST8 "hhd" -#define SCNdLEAST16 "hd" -#define SCNdLEAST32 "d" -#define SCNdLEAST64 __PRI64 "d" - -#define SCNdFAST8 "hhd" -#define SCNdFAST16 __PRIPTR "d" -#define SCNdFAST32 __PRIPTR "d" -#define SCNdFAST64 __PRI64 "d" - -#define SCNi8 "hhi" -#define SCNi16 "hi" -#define SCNi32 "i" -#define SCNi64 __PRI64 "i" - -#define SCNiLEAST8 "hhi" -#define SCNiLEAST16 "hi" -#define SCNiLEAST32 "i" -#define SCNiLEAST64 __PRI64 "i" - -#define SCNiFAST8 "hhi" -#define SCNiFAST16 __PRIPTR "i" -#define SCNiFAST32 __PRIPTR "i" -#define SCNiFAST64 __PRI64 "i" - -#define SCNu8 "hhu" -#define SCNu16 "hu" -#define SCNu32 "u" -#define SCNu64 __PRI64 "u" - -#define SCNuLEAST8 "hhu" -#define SCNuLEAST16 "hu" -#define SCNuLEAST32 "u" -#define SCNuLEAST64 __PRI64 "u" - -#define SCNuFAST8 "hhu" -#define SCNuFAST16 __PRIPTR "u" -#define SCNuFAST32 __PRIPTR "u" -#define SCNuFAST64 __PRI64 "u" - -#define SCNo8 "hho" -#define SCNo16 "ho" -#define SCNo32 "o" -#define SCNo64 __PRI64 "o" - -#define SCNoLEAST8 "hho" -#define SCNoLEAST16 "ho" -#define SCNoLEAST32 "o" -#define SCNoLEAST64 __PRI64 "o" - -#define SCNoFAST8 "hho" -#define SCNoFAST16 __PRIPTR "o" -#define SCNoFAST32 __PRIPTR "o" -#define SCNoFAST64 __PRI64 "o" - -#define SCNx8 "hhx" -#define SCNx16 "hx" -#define SCNx32 "x" -#define SCNx64 __PRI64 "x" - -#define SCNxLEAST8 "hhx" -#define SCNxLEAST16 "hx" -#define SCNxLEAST32 "x" -#define SCNxLEAST64 __PRI64 "x" - -#define SCNxFAST8 "hhx" -#define SCNxFAST16 __PRIPTR "x" -#define SCNxFAST32 __PRIPTR "x" -#define SCNxFAST64 __PRI64 "x" - -#define SCNdMAX __PRI64 "d" -#define SCNiMAX __PRI64 "i" -#define SCNoMAX __PRI64 "o" -#define SCNuMAX __PRI64 "u" -#define SCNxMAX __PRI64 "x" - -#define SCNdPTR __PRIPTR "d" -#define SCNiPTR __PRIPTR "i" -#define SCNoPTR __PRIPTR "o" -#define SCNuPTR __PRIPTR "u" -#define SCNxPTR __PRIPTR "x" - -#endif - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/05/musl-final/include/iso646.h b/05/musl-final/include/iso646.h deleted file mode 100644 index 88ff53d..0000000 --- a/05/musl-final/include/iso646.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef _ISO646_H -#define _ISO646_H - -#ifndef __cplusplus - -#define and && -#define and_eq &= -#define bitand & -#define bitor | -#define compl ~ -#define not ! -#define not_eq != -#define or || -#define or_eq |= -#define xor ^ -#define xor_eq ^= - -#endif - -#endif diff --git a/05/musl-final/include/langinfo.h b/05/musl-final/include/langinfo.h deleted file mode 100644 index b9c5569..0000000 --- a/05/musl-final/include/langinfo.h +++ /dev/null @@ -1,87 +0,0 @@ -#ifndef _LANGINFO_H -#define _LANGINFO_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define __NEED_nl_item -#define __NEED_locale_t - -#include - -#define ABDAY_1 0x20000 -#define ABDAY_2 0x20001 -#define ABDAY_3 0x20002 -#define ABDAY_4 0x20003 -#define ABDAY_5 0x20004 -#define ABDAY_6 0x20005 -#define ABDAY_7 0x20006 - -#define DAY_1 0x20007 -#define DAY_2 0x20008 -#define DAY_3 0x20009 -#define DAY_4 0x2000A -#define DAY_5 0x2000B -#define DAY_6 0x2000C -#define DAY_7 0x2000D - -#define ABMON_1 0x2000E -#define ABMON_2 0x2000F -#define ABMON_3 0x20010 -#define ABMON_4 0x20011 -#define ABMON_5 0x20012 -#define ABMON_6 0x20013 -#define ABMON_7 0x20014 -#define ABMON_8 0x20015 -#define ABMON_9 0x20016 -#define ABMON_10 0x20017 -#define ABMON_11 0x20018 -#define ABMON_12 0x20019 - -#define MON_1 0x2001A -#define MON_2 0x2001B -#define MON_3 0x2001C -#define MON_4 0x2001D -#define MON_5 0x2001E -#define MON_6 0x2001F -#define MON_7 0x20020 -#define MON_8 0x20021 -#define MON_9 0x20022 -#define MON_10 0x20023 -#define MON_11 0x20024 -#define MON_12 0x20025 - -#define AM_STR 0x20026 -#define PM_STR 0x20027 - -#define D_T_FMT 0x20028 -#define D_FMT 0x20029 -#define T_FMT 0x2002A -#define T_FMT_AMPM 0x2002B - -#define ERA 0x2002C -#define ERA_D_FMT 0x2002E -#define ALT_DIGITS 0x2002F -#define ERA_D_T_FMT 0x20030 -#define ERA_T_FMT 0x20031 - -#define CODESET 14 - -#define CRNCYSTR 0x4000F - -#define RADIXCHAR 0x10000 -#define THOUSEP 0x10001 -#define YESEXPR 0x50000 -#define NOEXPR 0x50001 -#define YESSTR 0x50002 -#define NOSTR 0x50003 - -char *nl_langinfo(nl_item); -char *nl_langinfo_l(nl_item, locale_t); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/05/musl-final/include/libgen.h b/05/musl-final/include/libgen.h deleted file mode 100644 index 7c7fd9c..0000000 --- a/05/musl-final/include/libgen.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef _LIBGEN_H -#define _LIBGEN_H - -#ifdef __cplusplus -extern "C" { -#endif - -char *dirname(char *); -char *basename(char *); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/05/musl-final/include/libintl.h b/05/musl-final/include/libintl.h deleted file mode 100644 index a2dada6..0000000 --- a/05/musl-final/include/libintl.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef _LIBINTL_H -#define _LIBINTL_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define __USE_GNU_GETTEXT 1 -#define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 1 : -1) - -char *gettext(const char *); -char *dgettext(const char *, const char *); -char *dcgettext(const char *, const char *, int); -char *ngettext(const char *, const char *, unsigned long); -char *dngettext(const char *, const char *, const char *, unsigned long); -char *dcngettext(const char *, const char *, const char *, unsigned long, int); -char *textdomain(const char *); -char *bindtextdomain (const char *, const char *); -char *bind_textdomain_codeset(const char *, const char *); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/05/musl-final/include/limits.h b/05/musl-final/include/limits.h deleted file mode 100644 index 6757012..0000000 --- a/05/musl-final/include/limits.h +++ /dev/null @@ -1,109 +0,0 @@ -#ifndef _LIMITS_H -#define _LIMITS_H - -/* Most limits are system-specific */ - -#include - -/* Some universal constants... */ - -#define CHAR_BIT 8 -#define SCHAR_MIN (-128) -#define SCHAR_MAX 127 -#define UCHAR_MAX 255 -#define CHAR_MIN (-128) -#define CHAR_MAX 127 - -#define MB_LEN_MAX 4 - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) - -#define SSIZE_MAX LONG_MAX -#define TZNAME_MAX 6 -#define TTY_NAME_MAX 20 -#define HOST_NAME_MAX 255 - -/* Implementation choices... */ - -#define PTHREAD_KEYS_MAX 1024 -#define PTHREAD_STACK_MIN PAGE_SIZE -#define PTHREAD_DESTRUCTOR_ITERATIONS 4 - -/* Arbitrary numbers... */ - -#define BC_BASE_MAX 99 -#define BC_DIM_MAX 2048 -#define BC_SCALE_MAX 99 -#define BC_STRING_MAX 1000 -#define CHARCLASS_NAME_MAX 14 -#define COLL_WEIGHTS_MAX 2 -#define EXPR_NEST_MAX 32 -#define LINE_MAX 4096 -#define RE_DUP_MAX 255 - -#define NL_ARGMAX 9 -#define NL_LANGMAX 32 -#define NL_MSGMAX 32767 -#define NL_NMAX (MB_LEN_MAX*4) -#define NL_SETMAX 255 -#define NL_TEXTMAX 2048 - -#endif - -/* POSIX/SUS requirements follow. These numbers come directly - * from SUS and have nothing to do with the host system. */ - -#define _POSIX_AIO_LISTIO_MAX 2 -#define _POSIX_AIO_MAX 1 -#define _POSIX_ARG_MAX 4096 -#define _POSIX_CHILD_MAX 25 -#define _POSIX_CLOCKRES_MIN 20000000 -#define _POSIX_DELAYTIMER_MAX 32 -#define _POSIX_HOST_NAME_MAX 255 -#define _POSIX_LINK_MAX 8 -#define _POSIX_LOGIN_NAME_MAX 9 -#define _POSIX_MAX_CANON 255 -#define _POSIX_MAX_INPUT 255 -#define _POSIX_MQ_OPEN_MAX 8 -#define _POSIX_MQ_PRIO_MAX 32 -#define _POSIX_NAME_MAX 14 -#define _POSIX_NGROUPS_MAX 8 -#define _POSIX_OPEN_MAX 20 -#define _POSIX_PATH_MAX 256 -#define _POSIX_PIPE_BUF 512 -#define _POSIX_RE_DUP_MAX 255 -#define _POSIX_RTSIG_MAX 8 -#define _POSIX_SEM_NSEMS_MAX 256 -#define _POSIX_SEM_VALUE_MAX 32767 -#define _POSIX_SIGQUEUE_MAX 32 -#define _POSIX_SSIZE_MAX 32767 -#define _POSIX_STREAM_MAX 8 -#define _POSIX_SS_REPL_MAX 4 -#define _POSIX_SYMLINK_MAX 255 -#define _POSIX_SYMLOOP_MAX 8 -#define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4 -#define _POSIX_THREAD_KEYS_MAX 128 -#define _POSIX_THREAD_THREADS_MAX 64 -#define _POSIX_TIMER_MAX 32 -#define _POSIX_TRACE_EVENT_NAME_MAX 30 -#define _POSIX_TRACE_NAME_MAX 8 -#define _POSIX_TRACE_SYS_MAX 8 -#define _POSIX_TRACE_USER_EVENT_MAX 32 -#define _POSIX_TTY_NAME_MAX 9 -#define _POSIX_TZNAME_MAX 6 -#define _POSIX2_BC_BASE_MAX 99 -#define _POSIX2_BC_DIM_MAX 2048 -#define _POSIX2_BC_SCALE_MAX 99 -#define _POSIX2_BC_STRING_MAX 1000 -#define _POSIX2_CHARCLASS_NAME_MAX 14 -#define _POSIX2_COLL_WEIGHTS_MAX 2 -#define _POSIX2_EXPR_NEST_MAX 32 -#define _POSIX2_LINE_MAX 2048 -#define _POSIX2_RE_DUP_MAX 255 - -#define _XOPEN_IOV_MAX 16 -#define _XOPEN_NAME_MAX 255 -#define _XOPEN_PATH_MAX 1024 - -#endif diff --git a/05/musl-final/include/linux/loop.h b/05/musl-final/include/linux/loop.h deleted file mode 100644 index 41aad40..0000000 --- a/05/musl-final/include/linux/loop.h +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef _LINUX_LOOP_H -#define _LINUX_LOOP_H - -#include - -#define LO_NAME_SIZE 64 -#define LO_KEY_SIZE 32 - -enum { - LO_FLAGS_READ_ONLY = 1, - LO_FLAGS_USE_AOPS = 2, - LO_FLAGS_AUTOCLEAR = 4, -}; - -struct loop_info { - int lo_number; - long lo_device; - unsigned long lo_inode; - long lo_rdevice; - int lo_offset; - int lo_encrypt_type; - int lo_encrypt_key_size; - int lo_flags; - char lo_name[LO_NAME_SIZE]; - unsigned char lo_encrypt_key[LO_KEY_SIZE]; - unsigned long lo_init[2]; - char reserved[4]; -}; - -struct loop_info64 { - uint64_t lo_device; - uint64_t lo_inode; - uint64_t lo_rdevice; - uint64_t lo_offset; - uint64_t lo_sizelimit; - uint32_t lo_number; - uint32_t lo_encrypt_type; - uint32_t lo_encrypt_key_size; - uint32_t lo_flags; - uint8_t lo_file_name[LO_NAME_SIZE]; - uint8_t lo_crypt_name[LO_NAME_SIZE]; - uint8_t lo_encrypt_key[LO_KEY_SIZE]; - uint64_t lo_init[2]; -}; - - -#define LO_CRYPT_NONE 0 -#define LO_CRYPT_XOR 1 -#define LO_CRYPT_DES 2 -#define LO_CRYPT_FISH2 3 -#define LO_CRYPT_BLOW 4 -#define LO_CRYPT_CAST128 5 -#define LO_CRYPT_IDEA 6 -#define LO_CRYPT_DUMMY 9 -#define LO_CRYPT_SKIPJACK 10 -#define LO_CRYPT_CRYPTOAPI 18 -#define MAX_LO_CRYPT 20 - - -#define LOOP_SET_FD 0x4C00 -#define LOOP_CLR_FD 0x4C01 -#define LOOP_SET_STATUS 0x4C02 -#define LOOP_GET_STATUS 0x4C03 -#define LOOP_SET_STATUS64 0x4C04 -#define LOOP_GET_STATUS64 0x4C05 -#define LOOP_CHANGE_FD 0x4C06 -#define LOOP_SET_CAPACITY 0x4C07 - -#endif diff --git a/05/musl-final/include/linux/version.h b/05/musl-final/include/linux/version.h deleted file mode 100644 index e6a89ef..0000000 --- a/05/musl-final/include/linux/version.h +++ /dev/null @@ -1,2 +0,0 @@ -#define LINUX_VERSION_CODE 132638 -#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c)) diff --git a/05/musl-final/include/locale.h b/05/musl-final/include/locale.h deleted file mode 100644 index 9da4726..0000000 --- a/05/musl-final/include/locale.h +++ /dev/null @@ -1,85 +0,0 @@ -#ifndef _LOCALE_H -#define _LOCALE_H - -#ifdef __cplusplus -extern "C" { -#endif - -#undef NULL -#ifdef __cplusplus -#define NULL 0 -#else -#define NULL ((void*)0) -#endif - -#define LC_CTYPE 0 -#define LC_NUMERIC 1 -#define LC_TIME 2 -#define LC_COLLATE 3 -#define LC_MONETARY 4 -#define LC_MESSAGES 5 -#define LC_ALL 6 - -struct lconv { - char *decimal_point; - char *thousands_sep; - char *grouping; - - char *int_curr_symbol; - char *currency_symbol; - char *mon_decimal_point; - char *mon_thousands_sep; - char *mon_grouping; - char *positive_sign; - char *negative_sign; - char int_frac_digits; - char frac_digits; - char p_cs_precedes; - char p_sep_by_space; - char n_cs_precedes; - char n_sep_by_space; - char p_sign_posn; - char n_sign_posn; - char int_p_cs_precedes; - char int_p_sep_by_space; - char int_n_cs_precedes; - char int_n_sep_by_space; - char int_p_sign_posn; - char int_n_sign_posn; -}; - - -char *setlocale (int, const char *); -struct lconv *localeconv(void); - - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) - -#define __NEED_locale_t - -#include - -#define LC_GLOBAL_LOCALE ((locale_t)-1) - -#define LC_CTYPE_MASK (1< - -#define __MAKE_FLOAT(i) (((union { int __i; float __f; }){ .__i = i }).__f) - -#define NAN __MAKE_FLOAT(0x7fc00000) -#define INFINITY __MAKE_FLOAT(0x7f800000) - -#define HUGE_VALF INFINITY -#define HUGE_VAL ((double)INFINITY) -#define HUGE_VALL ((long double)INFINITY) - -#define MAXFLOAT __MAKE_FLOAT(0x7f7fffff) - -#define MATH_ERRNO 1 -#define MATH_EXCEPT 2 -#define math_errhandling 2 - -#define FP_ILOGBNAN (((unsigned)-1)>>1) -#define FP_ILOGB0 (~FP_ILOGBNAN) - -#define FP_NAN 0 -#define FP_INFINITE 1 -#define FP_ZERO 2 -#define FP_SUBNORMAL 3 -#define FP_NORMAL 4 - -int __fpclassifyf(float); -int __fpclassify(double); -int __fpclassifyl(long double); - -#define fpclassify(x) ( \ - sizeof(x) == sizeof(float) ? __fpclassifyf(x) : \ - sizeof(x) == sizeof(double) ? __fpclassify(x) : \ - __fpclassifyl(x) ) - -#define isinf(x) (fpclassify(x) == FP_INFINITE) -#define isnan(x) (fpclassify(x) == FP_NAN) -#define isnormal(x) (fpclassify(x) == FP_NORMAL) -#define isfinite(x) (fpclassify(x) > FP_INFINITE) - -double acos(double); -float acosf(float); -long double acosl(long double); - -double acosh(double); -float acoshf(float); -long double acoshl(long double); - -double asin(double); -float asinf(float); -long double asinl(long double); - -double asinh(double); -float asinhf(float); -long double asinhl(long double); - -double atan(double); -float atanf(float); -long double atanl(long double); - -double atan2(double, double); -float atan2f(float, float); -long double atan2l(long double, long double); - -double atanh(double); -float atanhf(float); -long double atanhl(long double); - -double cbrt(double); -float cbrtf(float); -long double cbrtl(long double); - -double ceil(double); -float ceilf(float); -long double ceill(long double); - -double copysign(double, double); -float copysignf(float, float); -long double copysignl(long double, long double); - -double cos(double); -float cosf(float); -long double cosl(long double); - -double cosh(double); -float coshf(float); -long double coshl(long double); - -double erf(double); -float erff(float); -long double erfl(long double); - -double erfc(double); -float erfcf(float); -long double erfcl(long double); - -double exp(double); -float expf(float); -long double expl(long double); - -double exp2(double); -float exp2f(float); -long double exp2l(long double); - -double expm1(double); -float expm1f(float); -long double expm1l(long double); - -double fabs(double); -float fabsf(float); -long double fabsl(long double); - -double fdim(double, double); -float fdimf(float, float); -long double fdiml(long double, long double); - -double floor(double); -float floorf(float); -long double floorl(long double); - -double fma(double, double, double); -float fmaf(float, float, float); -long double fmal(long double, long double, long double); - -double fmax(double, double); -float fmaxf(float, float); -long double fmaxl(long double, long double); - -double fmin(double, double); -float fminf(float, float); -long double fminl(long double, long double); - -double fmod(double, double); -float fmodf(float, float); -long double fmodl(long double, long double); - -double frexp(double, int *); -float frexpf(float value, int *); -long double frexpl(long double value, int *); - -double hypot(double, double); -float hypotf(float, float); -long double hypotl(long double, long double); - -int ilogb(double); -int ilogbf(float); -int ilogbl(long double); - -double ldexp(double, int); -float ldexpf(float, int); -long double ldexpl(long double, int); - -double lgamma(double); -float lgammaf(float); -long double lgammal(long double); - -long long llrint(double); -long long llrintf(float); -long long llrintl(long double); - -long long llround(double); -long long llroundf(float); -long long llroundl(long double); - -double log(double); -float logf(float); -long double logl(long double); - -double log10(double); -float log10f(float); -long double log10l(long double); - -double log1p(double); -float log1pf(float); -long double log1pl(long double); - -double log2(double); -float log2f(float); -long double log2l(long double); - -double logb(double); -float logbf(float); -long double logbl(long double); - -long lrint(double); -long lrintf(float); -long lrintl(long double); - -long lround(double); -long lroundf(float); -long lroundl(long double); - -double modf(double, double *); -float modff(float, float *); -long double modfl(long double, long double *); - -double nan(const char *); -float nanf(const char *); -long double nanl(const char *); - -double nearbyint(double); -float nearbyintf(float); -long double nearbyintl(long double); - -double nextafter(double, double); -float nextafterf(float, float); -long double nextafterl(long double, long double); - -double nexttoward(double, long double); -float nexttowardf(float, long double); -long double nexttowardl(long double, long double); - -double pow(double, double); -float powf(float, float); -long double powl(long double, long double); - -double remainder(double, double); -float remainderf(float, float); -long double remainderl(long double, long double); - -double remquo(double, double, int *); -float remquof(float, float, int *); -long double remquol(long double, long double, int *); - -double rint(double); -float rintf(float); -long double rintl(long double); - -double round(double); -float roundf(float); -long double roundl(long double); - -double scalbln(double, long); -float scalblnf(float, long); -long double scalblnl(long double, long); - -double scalbn(double, int); -float scalbnf(float, int); -long double scalbnl(long double, int); - -double sin(double); -float sinf(float); -long double sinl(long double); - -double sinh(double); -float sinhf(float); -long double sinhl(long double); - -double sqrt(double); -float sqrtf(float); -long double sqrtl(long double); - -double tan(double); -float tanf(float); -long double tanl(long double); - -double tanh(double); -float tanhf(float); -long double tanhl(long double); - -double tgamma(double); -float tgammaf(float); -long double tgammal(long double); - -double trunc(double); -float truncf(float); -long double truncl(long double); - -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) -#define M_E 2.7182818284590452354 /* e */ -#define M_LOG2E 1.4426950408889634074 /* log_2 e */ -#define M_LOG10E 0.43429448190325182765 /* log_10 e */ -#define M_LN2 0.69314718055994530942 /* log_e 2 */ -#define M_LN10 2.30258509299404568402 /* log_e 10 */ -#define M_PI 3.14159265358979323846 /* pi */ -#define M_PI_2 1.57079632679489661923 /* pi/2 */ -#define M_PI_4 0.78539816339744830962 /* pi/4 */ -#define M_1_PI 0.31830988618379067154 /* 1/pi */ -#define M_2_PI 0.63661977236758134308 /* 2/pi */ -#define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */ -#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ -#define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ -double j0(double); -double j1(double); -double jn(int, double); -double y0(double); -double y1(double); -double yn(int, double); -extern int signgam; -#endif - -#ifdef _GNU_SOURCE -double scalb(double, double); -#endif - -#endif diff --git a/05/musl-final/include/mntent.h b/05/musl-final/include/mntent.h deleted file mode 100644 index c0fed7f..0000000 --- a/05/musl-final/include/mntent.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef _MNTENT_H -#define _MNTENT_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define __NEED_FILE -#include - -#define MOUNTED "/etc/mtab" - -#define MNTTYPE_IGNORE "ignore" -#define MNTTYPE_NFS "nfs" -#define MNTTYPE_SWAP "swap" -#define MNTOPT_DEFAULTS "defaults" -#define MNTOPT_RO "ro" -#define MNTOPT_RW "rw" -#define MNTOPT_SUID "suid" -#define MNTOPT_NOSUID "nosuid" -#define MNTOPT_NOAUTO "noauto" - -struct mntent -{ - char *mnt_fsname; - char *mnt_dir; - char *mnt_type; - char *mnt_opts; - int mnt_freq; - int mnt_passno; -}; - -FILE *setmntent(const char *, const char *); -int endmntent(FILE *); -struct mntent *getmntent(FILE *); -int addmntent(FILE *, const struct mntent *); -char *hasmntopt(const struct mntent *, const char *); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/05/musl-final/include/net/ethernet.h b/05/musl-final/include/net/ethernet.h deleted file mode 100644 index a536502..0000000 --- a/05/musl-final/include/net/ethernet.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef __NET_ETHERNET_H -#define __NET_ETHERNET_H 1 - -#include -#include -#include - -struct ether_addr { - uint8_t ether_addr_octet[ETH_ALEN]; -}; - -struct ether_header { - uint8_t ether_dhost[ETH_ALEN]; - uint8_t ether_shost[ETH_ALEN]; - uint16_t ether_type; -}; - -#define ETHERTYPE_PUP 0x0200 -#define ETHERTYPE_SPRITE 0x0500 -#define ETHERTYPE_IP 0x0800 -#define ETHERTYPE_ARP 0x0806 -#define ETHERTYPE_REVARP 0x8035 -#define ETHERTYPE_AT 0x809B -#define ETHERTYPE_AARP 0x80F3 -#define ETHERTYPE_VLAN 0x8100 -#define ETHERTYPE_IPX 0x8137 -#define ETHERTYPE_IPV6 0x86dd -#define ETHERTYPE_LOOPBACK 0x9000 - - -#define ETHER_ADDR_LEN ETH_ALEN -#define ETHER_TYPE_LEN 2 -#define ETHER_CRC_LEN 4 -#define ETHER_HDR_LEN ETH_HLEN -#define ETHER_MIN_LEN (ETH_ZLEN + ETHER_CRC_LEN) -#define ETHER_MAX_LEN (ETH_FRAME_LEN + ETHER_CRC_LEN) - -#define ETHER_IS_VALID_LEN(foo) \ - ((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN) - -#define ETHERTYPE_TRAIL 0x1000 -#define ETHERTYPE_NTRAILER 16 - -#define ETHERMTU ETH_DATA_LEN -#define ETHERMIN (ETHER_MIN_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN) - -#endif diff --git a/05/musl-final/include/net/if.h b/05/musl-final/include/net/if.h deleted file mode 100644 index 2ae5f89..0000000 --- a/05/musl-final/include/net/if.h +++ /dev/null @@ -1,122 +0,0 @@ -#ifndef _NET_IF_H -#define _NET_IF_H - -#define IF_NAMESIZE 16 - -struct if_nameindex -{ - unsigned int if_index; - char *if_name; -}; - -unsigned int if_nametoindex (const char *); -char *if_indextoname (unsigned int, char *); -struct if_nameindex *if_nameindex (void); -void if_freenameindex (struct if_nameindex *); - - - - -#ifdef _GNU_SOURCE - -#include - -#define IFF_UP 0x1 -#define IFF_BROADCAST 0x2 -#define IFF_DEBUG 0x4 -#define IFF_LOOPBACK 0x8 -#define IFF_POINTOPOINT 0x10 -#define IFF_NOTRAILERS 0x20 -#define IFF_RUNNING 0x40 -#define IFF_NOARP 0x80 -#define IFF_PROMISC 0x100 -#define IFF_ALLMULTI 0x200 -#define IFF_MASTER 0x400 -#define IFF_SLAVE 0x800 -#define IFF_MULTICAST 0x1000 -#define IFF_PORTSEL 0x2000 -#define IFF_AUTOMEDIA 0x4000 -#define IFF_DYNAMIC 0x8000 - -struct ifaddr { - struct sockaddr ifa_addr; - union { - struct sockaddr ifu_broadaddr; - struct sockaddr ifu_dstaddr; - } ifa_ifu; - struct iface *ifa_ifp; - struct ifaddr *ifa_next; -}; - -#define ifa_broadaddr ifa_ifu.ifu_broadaddr -#define ifa_dstaddr ifa_ifu.ifu_dstaddr - -struct ifmap { - unsigned long int mem_start; - unsigned long int mem_end; - unsigned short int base_addr; - unsigned char irq; - unsigned char dma; - unsigned char port; -}; - -#define IFHWADDRLEN 6 -#define IFNAMSIZ IF_NAMESIZE - -struct ifreq { - union { - char ifrn_name[IFNAMSIZ]; - } ifr_ifrn; - union { - struct sockaddr ifru_addr; - struct sockaddr ifru_dstaddr; - struct sockaddr ifru_broadaddr; - struct sockaddr ifru_netmask; - struct sockaddr ifru_hwaddr; - short int ifru_flags; - int ifru_ivalue; - int ifru_mtu; - struct ifmap ifru_map; - char ifru_slave[IFNAMSIZ]; - char ifru_newname[IFNAMSIZ]; - void *ifru_data; - } ifr_ifru; -}; - -#define ifr_name ifr_ifrn.ifrn_name -#define ifr_hwaddr ifr_ifru.ifru_hwaddr -#define ifr_addr ifr_ifru.ifru_addr -#define ifr_dstaddr ifr_ifru.ifru_dstaddr -#define ifr_broadaddr ifr_ifru.ifru_broadaddr -#define ifr_netmask ifr_ifru.ifru_netmask -#define ifr_flags ifr_ifru.ifru_flags -#define ifr_metric ifr_ifru.ifru_ivalue -#define ifr_mtu ifr_ifru.ifru_mtu -#define ifr_map ifr_ifru.ifru_map -#define ifr_slave ifr_ifru.ifru_slave -#define ifr_data ifr_ifru.ifru_data -#define ifr_ifindex ifr_ifru.ifru_ivalue -#define ifr_bandwidth ifr_ifru.ifru_ivalue -#define ifr_qlen ifr_ifru.ifru_ivalue -#define ifr_newname ifr_ifru.ifru_newname -#define _IOT_ifreq _IOT(_IOTS(char),IFNAMSIZ,_IOTS(char),16,0,0) -#define _IOT_ifreq_short _IOT(_IOTS(char),IFNAMSIZ,_IOTS(short),1,0,0) -#define _IOT_ifreq_int _IOT(_IOTS(char),IFNAMSIZ,_IOTS(int),1,0,0) - -struct ifconf { - int ifc_len; - union { - void *ifcu_buf; - struct ifreq *ifcu_req; - } ifc_ifcu; -}; - -#define ifc_buf ifc_ifcu.ifcu_buf -#define ifc_req ifc_ifcu.ifcu_req -#define _IOT_ifconf _IOT(_IOTS(struct ifconf),1,0,0,0,0) - -#endif - - - -#endif diff --git a/05/musl-final/include/net/if_arp.h b/05/musl-final/include/net/if_arp.h deleted file mode 100644 index bb5eadf..0000000 --- a/05/musl-final/include/net/if_arp.h +++ /dev/null @@ -1,133 +0,0 @@ -/* Nonstandard header */ -#ifndef _NET_IF_ARP_H -#define _NET_IF_ARP_H -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include - -#define MAX_ADDR_LEN 7 - -#define ARPOP_REQUEST 1 -#define ARPOP_REPLY 2 -#define ARPOP_RREQUEST 3 -#define ARPOP_RREPLY 4 -#define ARPOP_InREQUEST 8 -#define ARPOP_InREPLY 9 -#define ARPOP_NAK 10 - -struct arphdr { - uint16_t ar_hrd; - uint16_t ar_pro; - uint8_t ar_hln; - uint8_t ar_pln; - uint16_t ar_op; -}; - - -#define ARPHRD_NETROM 0 -#define ARPHRD_ETHER 1 -#define ARPHRD_EETHER 2 -#define ARPHRD_AX25 3 -#define ARPHRD_PRONET 4 -#define ARPHRD_CHAOS 5 -#define ARPHRD_IEEE802 6 -#define ARPHRD_ARCNET 7 -#define ARPHRD_APPLETLK 8 -#define ARPHRD_DLCI 15 -#define ARPHRD_ATM 19 -#define ARPHRD_METRICOM 23 -#define ARPHRD_IEEE1394 24 -#define ARPHRD_EUI64 27 -#define ARPHRD_INFINIBAND 32 -#define ARPHRD_SLIP 256 -#define ARPHRD_CSLIP 257 -#define ARPHRD_SLIP6 258 -#define ARPHRD_CSLIP6 259 -#define ARPHRD_RSRVD 260 -#define ARPHRD_ADAPT 264 -#define ARPHRD_ROSE 270 -#define ARPHRD_X25 271 -#define ARPHRD_HWX25 272 -#define ARPHRD_PPP 512 -#define ARPHRD_CISCO 513 -#define ARPHRD_HDLC ARPHRD_CISCO -#define ARPHRD_LAPB 516 -#define ARPHRD_DDCMP 517 -#define ARPHRD_RAWHDLC 518 - -#define ARPHRD_TUNNEL 768 -#define ARPHRD_TUNNEL6 769 -#define ARPHRD_FRAD 770 -#define ARPHRD_SKIP 771 -#define ARPHRD_LOOPBACK 772 -#define ARPHRD_LOCALTLK 773 -#define ARPHRD_FDDI 774 -#define ARPHRD_BIF 775 -#define ARPHRD_SIT 776 -#define ARPHRD_IPDDP 777 -#define ARPHRD_IPGRE 778 -#define ARPHRD_PIMREG 779 -#define ARPHRD_HIPPI 780 -#define ARPHRD_ASH 781 -#define ARPHRD_ECONET 782 -#define ARPHRD_IRDA 783 -#define ARPHRD_FCPP 784 -#define ARPHRD_FCAL 785 -#define ARPHRD_FCPL 786 -#define ARPHRD_FCFABRIC 787 -#define ARPHRD_IEEE802_TR 800 -#define ARPHRD_IEEE80211 801 -#define ARPHRD_IEEE80211_PRISM 802 -#define ARPHRD_IEEE80211_RADIOTAP 803 -#define ARPHRD_IEEE802154 804 -#define ARPHRD_IEEE802154_PHY 805 - -#define ARPHRD_VOID 0xFFFF -#define ARPHRD_NONE 0xFFFE - -struct arpreq { - struct sockaddr arp_pa; - struct sockaddr arp_ha; - int arp_flags; - struct sockaddr arp_netmask; - char arp_dev[16]; -}; - -struct arpreq_old { - struct sockaddr arp_pa; - struct sockaddr arp_ha; - int arp_flags; - struct sockaddr arp_netmask; -}; - -#define ATF_COM 0x02 -#define ATF_PERM 0x04 -#define ATF_PUBL 0x08 -#define ATF_USETRAILERS 0x10 -#define ATF_NETMASK 0x20 -#define ATF_DONTPUB 0x40 -#define ATF_MAGIC 0x80 - -#define ARPD_UPDATE 0x01 -#define ARPD_LOOKUP 0x02 -#define ARPD_FLUSH 0x03 - -struct arpd_request { - uint16_t req; - uint32_t ip; - uint32_t dev; - uint32_t stamp; - uint32_t updated; - uint8_t ha[MAX_ADDR_LEN]; -}; - - - -#ifdef __cplusplus -} -#endif -#endif diff --git a/05/musl-final/include/net/route.h b/05/musl-final/include/net/route.h deleted file mode 100644 index 3aaab97..0000000 --- a/05/musl-final/include/net/route.h +++ /dev/null @@ -1,116 +0,0 @@ -#ifndef _NET_ROUTE_H -#define _NET_ROUTE_H - -#include -#include -#include -#include - - -struct rtentry { - unsigned long int rt_pad1; - struct sockaddr rt_dst; - struct sockaddr rt_gateway; - struct sockaddr rt_genmask; - unsigned short int rt_flags; - short int rt_pad2; - unsigned long int rt_pad3; - unsigned char rt_tos; - unsigned char rt_class; - short int rt_pad4[sizeof(long)/2-1]; - short int rt_metric; - char *rt_dev; - unsigned long int rt_mtu; - unsigned long int rt_window; - unsigned short int rt_irtt; -}; - -#define rt_mss rt_mtu - - -struct in6_rtmsg { - struct in6_addr rtmsg_dst; - struct in6_addr rtmsg_src; - struct in6_addr rtmsg_gateway; - uint32_t rtmsg_type; - uint16_t rtmsg_dst_len; - uint16_t rtmsg_src_len; - uint32_t rtmsg_metric; - unsigned long int rtmsg_info; - uint32_t rtmsg_flags; - int rtmsg_ifindex; -}; - - -#define RTF_UP 0x0001 -#define RTF_GATEWAY 0x0002 - -#define RTF_HOST 0x0004 -#define RTF_REINSTATE 0x0008 -#define RTF_DYNAMIC 0x0010 -#define RTF_MODIFIED 0x0020 -#define RTF_MTU 0x0040 -#define RTF_MSS RTF_MTU -#define RTF_WINDOW 0x0080 -#define RTF_IRTT 0x0100 -#define RTF_REJECT 0x0200 -#define RTF_STATIC 0x0400 -#define RTF_XRESOLVE 0x0800 -#define RTF_NOFORWARD 0x1000 -#define RTF_THROW 0x2000 -#define RTF_NOPMTUDISC 0x4000 - -#define RTF_DEFAULT 0x00010000 -#define RTF_ALLONLINK 0x00020000 -#define RTF_ADDRCONF 0x00040000 - -#define RTF_LINKRT 0x00100000 -#define RTF_NONEXTHOP 0x00200000 - -#define RTF_CACHE 0x01000000 -#define RTF_FLOW 0x02000000 -#define RTF_POLICY 0x04000000 - -#define RTCF_VALVE 0x00200000 -#define RTCF_MASQ 0x00400000 -#define RTCF_NAT 0x00800000 -#define RTCF_DOREDIRECT 0x01000000 -#define RTCF_LOG 0x02000000 -#define RTCF_DIRECTSRC 0x04000000 - -#define RTF_LOCAL 0x80000000 -#define RTF_INTERFACE 0x40000000 -#define RTF_MULTICAST 0x20000000 -#define RTF_BROADCAST 0x10000000 -#define RTF_NAT 0x08000000 - -#define RTF_ADDRCLASSMASK 0xF8000000 -#define RT_ADDRCLASS(flags) ((uint32_t) flags >> 23) - -#define RT_TOS(tos) ((tos) & IPTOS_TOS_MASK) - -#define RT_LOCALADDR(flags) ((flags & RTF_ADDRCLASSMASK) \ - == (RTF_LOCAL|RTF_INTERFACE)) - -#define RT_CLASS_UNSPEC 0 -#define RT_CLASS_DEFAULT 253 - -#define RT_CLASS_MAIN 254 -#define RT_CLASS_LOCAL 255 -#define RT_CLASS_MAX 255 - - -#define RTMSG_ACK NLMSG_ACK -#define RTMSG_OVERRUN NLMSG_OVERRUN - -#define RTMSG_NEWDEVICE 0x11 -#define RTMSG_DELDEVICE 0x12 -#define RTMSG_NEWROUTE 0x21 -#define RTMSG_DELROUTE 0x22 -#define RTMSG_NEWRULE 0x31 -#define RTMSG_DELRULE 0x32 -#define RTMSG_CONTROL 0x40 - -#define RTMSG_AR_FAILED 0x51 - -#endif diff --git a/05/musl-final/include/netdb.h b/05/musl-final/include/netdb.h deleted file mode 100644 index 5f1dd3f..0000000 --- a/05/musl-final/include/netdb.h +++ /dev/null @@ -1,148 +0,0 @@ -#ifndef _NETDB_H -#define _NETDB_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef _GNU_SOURCE -#define __NEED_size_t -#endif - -#define __NEED_socklen_t -#define __NEED_uint32_t - -#include - -struct addrinfo -{ - int ai_flags; - int ai_family; - int ai_socktype; - int ai_protocol; - socklen_t ai_addrlen; - struct sockaddr *ai_addr; - char *ai_canonname; - struct addrinfo *ai_next; -}; - -#define IPPORT_RESERVED 1024 - -#define AI_PASSIVE 0x01 -#define AI_CANONNAME 0x02 -#define AI_NUMERICHOST 0x04 -#define AI_V4MAPPED 0x08 -#define AI_ALL 0x10 -#define AI_ADDRCONFIG 0x20 -#define AI_NUMERICSERV 0x400 - - -#define NI_NUMERICHOST 0x01 -#define NI_NUMERICSERV 0x02 -#define NI_NOFQDN 0x04 -#define NI_NAMEREQD 0x08 -#define NI_DGRAM 0x10 -/*#define NI_NUMERICSCOPE */ - -#define NI_MAXHOST 255 -#define NI_MAXSERV 32 - -#define EAI_BADFLAGS -1 -#define EAI_NONAME -2 -#define EAI_AGAIN -3 -#define EAI_FAIL -4 -#define EAI_FAMILY -6 -#define EAI_SOCKTYPE -7 -#define EAI_SERVICE -8 -#define EAI_MEMORY -10 -#define EAI_SYSTEM -11 -#define EAI_OVERFLOW -12 - -int getaddrinfo (const char *, const char *, const struct addrinfo *, struct addrinfo **); -void freeaddrinfo (struct addrinfo *); -int getnameinfo (const struct sockaddr *, socklen_t, char *, socklen_t, char *, socklen_t, int); -const char *gai_strerror(int); - - -/* Legacy functions follow (marked OBsolete in SUS) */ - -struct netent -{ - char *n_name; - char **n_aliases; - int n_addrtype; - uint32_t n_net; -}; - -struct hostent -{ - char *h_name; - char **h_aliases; - int h_addrtype; - int h_length; - char **h_addr_list; -}; -#define h_addr h_addr_list[0] - -struct servent -{ - char *s_name; - char **s_aliases; - int s_port; - char *s_proto; -}; - -struct protoent -{ - char *p_name; - char **p_aliases; - int p_proto; -}; - -extern int h_errno; - -#define HOST_NOT_FOUND 1 -#define TRY_AGAIN 2 -#define NO_RECOVERY 3 -#define NO_DATA 4 - -void sethostent (int); -void endhostent (void); -struct hostent *gethostent (void); -struct hostent *gethostbyaddr (const void *, socklen_t, int); -struct hostent *gethostbyname (const char *); - -void setnetent (int); -void endnetent (void); -struct netent *getnetent (void); -struct netent *getnetbyaddr (uint32_t, int); -struct netent *getnetbyname (const char *); - -void setservent (int); -void endservent (void); -struct servent *getservent (void); -struct servent *getservbyname (const char *, const char *); -struct servent *getservbyport (int, const char *); - -void setprotoent (int); -void endprotoent (void); -struct protoent *getprotoent (void); -struct protoent *getprotobyname (const char *); -struct protoent *getprotobynumber (int); - -#ifdef _GNU_SOURCE -const char *hstrerror(int); -int gethostbyname_r(const char *, struct hostent *, char *, size_t, struct hostent **, int *); -int gethostbyname2_r(const char *, int, struct hostent *, char *, size_t, struct hostent **, int *); -struct hostent *gethostbyname2(const char *, int); -int gethostbyaddr_r(const void *, socklen_t, int, struct hostent *, char *, size_t, struct hostent **, int *); -int getservbyport_r(int, const char *, struct servent *, char *, size_t, struct servent **); -int getservbyname_r(const char *, const char *, struct servent *, char *, size_t, struct servent **); -#endif - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/05/musl-final/include/netinet/icmp6.h b/05/musl-final/include/netinet/icmp6.h deleted file mode 100644 index 01269e7..0000000 --- a/05/musl-final/include/netinet/icmp6.h +++ /dev/null @@ -1,305 +0,0 @@ -#ifndef _NETINET_ICMP6_H -#define _NETINET_ICMP6_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include -#include - -#define ICMP6_FILTER 1 - -#define ICMP6_FILTER_BLOCK 1 -#define ICMP6_FILTER_PASS 2 -#define ICMP6_FILTER_BLOCKOTHERS 3 -#define ICMP6_FILTER_PASSONLY 4 - -struct icmp6_filter { - uint32_t icmp6_filt[8]; -}; - -struct icmp6_hdr { - uint8_t icmp6_type; - uint8_t icmp6_code; - uint16_t icmp6_cksum; - union { - uint32_t icmp6_un_data32[1]; - uint16_t icmp6_un_data16[2]; - uint8_t icmp6_un_data8[4]; - } icmp6_dataun; -}; - -#define icmp6_data32 icmp6_dataun.icmp6_un_data32 -#define icmp6_data16 icmp6_dataun.icmp6_un_data16 -#define icmp6_data8 icmp6_dataun.icmp6_un_data8 -#define icmp6_pptr icmp6_data32[0] -#define icmp6_mtu icmp6_data32[0] -#define icmp6_id icmp6_data16[0] -#define icmp6_seq icmp6_data16[1] -#define icmp6_maxdelay icmp6_data16[0] - -#define ICMP6_DST_UNREACH 1 -#define ICMP6_PACKET_TOO_BIG 2 -#define ICMP6_TIME_EXCEEDED 3 -#define ICMP6_PARAM_PROB 4 - -#define ICMP6_INFOMSG_MASK 0x80 - -#define ICMP6_ECHO_REQUEST 128 -#define ICMP6_ECHO_REPLY 129 -#define MLD_LISTENER_QUERY 130 -#define MLD_LISTENER_REPORT 131 -#define MLD_LISTENER_REDUCTION 132 - -#define ICMP6_DST_UNREACH_NOROUTE 0 -#define ICMP6_DST_UNREACH_ADMIN 1 -#define ICMP6_DST_UNREACH_BEYONDSCOPE 2 -#define ICMP6_DST_UNREACH_ADDR 3 -#define ICMP6_DST_UNREACH_NOPORT 4 - -#define ICMP6_TIME_EXCEED_TRANSIT 0 -#define ICMP6_TIME_EXCEED_REASSEMBLY 1 - -#define ICMP6_PARAMPROB_HEADER 0 -#define ICMP6_PARAMPROB_NEXTHEADER 1 -#define ICMP6_PARAMPROB_OPTION 2 - -#define ICMP6_FILTER_WILLPASS(type, filterp) \ - ((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) == 0) - -#define ICMP6_FILTER_WILLBLOCK(type, filterp) \ - ((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) != 0) - -#define ICMP6_FILTER_SETPASS(type, filterp) \ - ((((filterp)->icmp6_filt[(type) >> 5]) &= ~(1 << ((type) & 31)))) - -#define ICMP6_FILTER_SETBLOCK(type, filterp) \ - ((((filterp)->icmp6_filt[(type) >> 5]) |= (1 << ((type) & 31)))) - -#define ICMP6_FILTER_SETPASSALL(filterp) \ - memset (filterp, 0, sizeof (struct icmp6_filter)); - -#define ICMP6_FILTER_SETBLOCKALL(filterp) \ - memset (filterp, 0xFF, sizeof (struct icmp6_filter)); - -#define ND_ROUTER_SOLICIT 133 -#define ND_ROUTER_ADVERT 134 -#define ND_NEIGHBOR_SOLICIT 135 -#define ND_NEIGHBOR_ADVERT 136 -#define ND_REDIRECT 137 - -struct nd_router_solicit { - struct icmp6_hdr nd_rs_hdr; -}; - -#define nd_rs_type nd_rs_hdr.icmp6_type -#define nd_rs_code nd_rs_hdr.icmp6_code -#define nd_rs_cksum nd_rs_hdr.icmp6_cksum -#define nd_rs_reserved nd_rs_hdr.icmp6_data32[0] - -struct nd_router_advert { - struct icmp6_hdr nd_ra_hdr; - uint32_t nd_ra_reachable; - uint32_t nd_ra_retransmit; -}; - -#define nd_ra_type nd_ra_hdr.icmp6_type -#define nd_ra_code nd_ra_hdr.icmp6_code -#define nd_ra_cksum nd_ra_hdr.icmp6_cksum -#define nd_ra_curhoplimit nd_ra_hdr.icmp6_data8[0] -#define nd_ra_flags_reserved nd_ra_hdr.icmp6_data8[1] -#define ND_RA_FLAG_MANAGED 0x80 -#define ND_RA_FLAG_OTHER 0x40 -#define ND_RA_FLAG_HOME_AGENT 0x20 -#define nd_ra_router_lifetime nd_ra_hdr.icmp6_data16[1] - -struct nd_neighbor_solicit { - struct icmp6_hdr nd_ns_hdr; - struct in6_addr nd_ns_target; -}; - -#define nd_ns_type nd_ns_hdr.icmp6_type -#define nd_ns_code nd_ns_hdr.icmp6_code -#define nd_ns_cksum nd_ns_hdr.icmp6_cksum -#define nd_ns_reserved nd_ns_hdr.icmp6_data32[0] - -struct nd_neighbor_advert { - struct icmp6_hdr nd_na_hdr; - struct in6_addr nd_na_target; -}; - -#define nd_na_type nd_na_hdr.icmp6_type -#define nd_na_code nd_na_hdr.icmp6_code -#define nd_na_cksum nd_na_hdr.icmp6_cksum -#define nd_na_flags_reserved nd_na_hdr.icmp6_data32[0] -#if __BYTE_ORDER == __BIG_ENDIAN -#define ND_NA_FLAG_ROUTER 0x80000000 -#define ND_NA_FLAG_SOLICITED 0x40000000 -#define ND_NA_FLAG_OVERRIDE 0x20000000 -#else -#define ND_NA_FLAG_ROUTER 0x00000080 -#define ND_NA_FLAG_SOLICITED 0x00000040 -#define ND_NA_FLAG_OVERRIDE 0x00000020 -#endif - -struct nd_redirect { - struct icmp6_hdr nd_rd_hdr; - struct in6_addr nd_rd_target; - struct in6_addr nd_rd_dst; -}; - -#define nd_rd_type nd_rd_hdr.icmp6_type -#define nd_rd_code nd_rd_hdr.icmp6_code -#define nd_rd_cksum nd_rd_hdr.icmp6_cksum -#define nd_rd_reserved nd_rd_hdr.icmp6_data32[0] - -struct nd_opt_hdr { - uint8_t nd_opt_type; - uint8_t nd_opt_len; -}; - -#define ND_OPT_SOURCE_LINKADDR 1 -#define ND_OPT_TARGET_LINKADDR 2 -#define ND_OPT_PREFIX_INFORMATION 3 -#define ND_OPT_REDIRECTED_HEADER 4 -#define ND_OPT_MTU 5 -#define ND_OPT_RTR_ADV_INTERVAL 7 -#define ND_OPT_HOME_AGENT_INFO 8 - -struct nd_opt_prefix_info { - uint8_t nd_opt_pi_type; - uint8_t nd_opt_pi_len; - uint8_t nd_opt_pi_prefix_len; - uint8_t nd_opt_pi_flags_reserved; - uint32_t nd_opt_pi_valid_time; - uint32_t nd_opt_pi_preferred_time; - uint32_t nd_opt_pi_reserved2; - struct in6_addr nd_opt_pi_prefix; -}; - -#define ND_OPT_PI_FLAG_ONLINK 0x80 -#define ND_OPT_PI_FLAG_AUTO 0x40 -#define ND_OPT_PI_FLAG_RADDR 0x20 - -struct nd_opt_rd_hdr { - uint8_t nd_opt_rh_type; - uint8_t nd_opt_rh_len; - uint16_t nd_opt_rh_reserved1; - uint32_t nd_opt_rh_reserved2; -}; - -struct nd_opt_mtu { - uint8_t nd_opt_mtu_type; - uint8_t nd_opt_mtu_len; - uint16_t nd_opt_mtu_reserved; - uint32_t nd_opt_mtu_mtu; -}; - -struct mld_hdr { - struct icmp6_hdr mld_icmp6_hdr; - struct in6_addr mld_addr; -}; - -#define mld_type mld_icmp6_hdr.icmp6_type -#define mld_code mld_icmp6_hdr.icmp6_code -#define mld_cksum mld_icmp6_hdr.icmp6_cksum -#define mld_maxdelay mld_icmp6_hdr.icmp6_data16[0] -#define mld_reserved mld_icmp6_hdr.icmp6_data16[1] - -#define ICMP6_ROUTER_RENUMBERING 138 - -struct icmp6_router_renum { - struct icmp6_hdr rr_hdr; - uint8_t rr_segnum; - uint8_t rr_flags; - uint16_t rr_maxdelay; - uint32_t rr_reserved; -}; - -#define rr_type rr_hdr.icmp6_type -#define rr_code rr_hdr.icmp6_code -#define rr_cksum rr_hdr.icmp6_cksum -#define rr_seqnum rr_hdr.icmp6_data32[0] - -#define ICMP6_RR_FLAGS_TEST 0x80 -#define ICMP6_RR_FLAGS_REQRESULT 0x40 -#define ICMP6_RR_FLAGS_FORCEAPPLY 0x20 -#define ICMP6_RR_FLAGS_SPECSITE 0x10 -#define ICMP6_RR_FLAGS_PREVDONE 0x08 - -struct rr_pco_match { - uint8_t rpm_code; - uint8_t rpm_len; - uint8_t rpm_ordinal; - uint8_t rpm_matchlen; - uint8_t rpm_minlen; - uint8_t rpm_maxlen; - uint16_t rpm_reserved; - struct in6_addr rpm_prefix; -}; - -#define RPM_PCO_ADD 1 -#define RPM_PCO_CHANGE 2 -#define RPM_PCO_SETGLOBAL 3 - -struct rr_pco_use { - uint8_t rpu_uselen; - uint8_t rpu_keeplen; - uint8_t rpu_ramask; - uint8_t rpu_raflags; - uint32_t rpu_vltime; - uint32_t rpu_pltime; - uint32_t rpu_flags; - struct in6_addr rpu_prefix; -}; - -#define ICMP6_RR_PCOUSE_RAFLAGS_ONLINK 0x20 -#define ICMP6_RR_PCOUSE_RAFLAGS_AUTO 0x10 - -#if __BYTE_ORDER == __BIG_ENDIAN -#define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME 0x80000000 -#define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME 0x40000000 -#else -#define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME 0x80 -#define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME 0x40 -#endif - -struct rr_result { - uint16_t rrr_flags; - uint8_t rrr_ordinal; - uint8_t rrr_matchedlen; - uint32_t rrr_ifid; - struct in6_addr rrr_prefix; -}; - -#if __BYTE_ORDER == __BIG_ENDIAN -#define ICMP6_RR_RESULT_FLAGS_OOB 0x0002 -#define ICMP6_RR_RESULT_FLAGS_FORBIDDEN 0x0001 -#else -#define ICMP6_RR_RESULT_FLAGS_OOB 0x0200 -#define ICMP6_RR_RESULT_FLAGS_FORBIDDEN 0x0100 -#endif - -struct nd_opt_adv_interval { - uint8_t nd_opt_adv_interval_type; - uint8_t nd_opt_adv_interval_len; - uint16_t nd_opt_adv_interval_reserved; - uint32_t nd_opt_adv_interval_ival; -}; - -struct nd_opt_home_agent_info { - uint8_t nd_opt_home_agent_info_type; - uint8_t nd_opt_home_agent_info_len; - uint16_t nd_opt_home_agent_info_reserved; - uint16_t nd_opt_home_agent_info_preference; - uint16_t nd_opt_home_agent_info_lifetime; -}; - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/05/musl-final/include/netinet/if_ether.h b/05/musl-final/include/netinet/if_ether.h deleted file mode 100644 index 65a838a..0000000 --- a/05/musl-final/include/netinet/if_ether.h +++ /dev/null @@ -1,108 +0,0 @@ -#ifndef _NETINET_IF_ETHER_H -#define _NETINET_IF_ETHER_H - -#include -#include - -#define ETH_ALEN 6 -#define ETH_HLEN 14 -#define ETH_ZLEN 60 -#define ETH_DATA_LEN 1500 -#define ETH_FRAME_LEN 1514 -#define ETH_FCS_LEN 4 - -#define ETH_P_LOOP 0x0060 -#define ETH_P_PUP 0x0200 -#define ETH_P_PUPAT 0x0201 -#define ETH_P_IP 0x0800 -#define ETH_P_X25 0x0805 -#define ETH_P_ARP 0x0806 -#define ETH_P_BPQ 0x08FF -#define ETH_P_IEEEPUP 0x0a00 -#define ETH_P_IEEEPUPAT 0x0a01 -#define ETH_P_DEC 0x6000 -#define ETH_P_DNA_DL 0x6001 -#define ETH_P_DNA_RC 0x6002 -#define ETH_P_DNA_RT 0x6003 -#define ETH_P_LAT 0x6004 -#define ETH_P_DIAG 0x6005 -#define ETH_P_CUST 0x6006 -#define ETH_P_SCA 0x6007 -#define ETH_P_TEB 0x6558 -#define ETH_P_RARP 0x8035 -#define ETH_P_ATALK 0x809B -#define ETH_P_AARP 0x80F3 -#define ETH_P_8021Q 0x8100 -#define ETH_P_IPX 0x8137 -#define ETH_P_IPV6 0x86DD -#define ETH_P_PAUSE 0x8808 -#define ETH_P_SLOW 0x8809 -#define ETH_P_WCCP 0x883E -#define ETH_P_PPP_DISC 0x8863 -#define ETH_P_PPP_SES 0x8864 -#define ETH_P_MPLS_UC 0x8847 -#define ETH_P_MPLS_MC 0x8848 -#define ETH_P_ATMMPOA 0x884c -#define ETH_P_ATMFATE 0x8884 -#define ETH_P_PAE 0x888E -#define ETH_P_AOE 0x88A2 -#define ETH_P_TIPC 0x88CA -#define ETH_P_FCOE 0x8906 -#define ETH_P_EDSA 0xDADA - -#define ETH_P_802_3 0x0001 -#define ETH_P_AX25 0x0002 -#define ETH_P_ALL 0x0003 -#define ETH_P_802_2 0x0004 -#define ETH_P_SNAP 0x0005 -#define ETH_P_DDCMP 0x0006 -#define ETH_P_WAN_PPP 0x0007 -#define ETH_P_PPP_MP 0x0008 -#define ETH_P_LOCALTALK 0x0009 -#define ETH_P_CAN 0x000C -#define ETH_P_PPPTALK 0x0010 -#define ETH_P_TR_802_2 0x0011 -#define ETH_P_MOBITEX 0x0015 -#define ETH_P_CONTROL 0x0016 -#define ETH_P_IRDA 0x0017 -#define ETH_P_ECONET 0x0018 -#define ETH_P_HDLC 0x0019 -#define ETH_P_ARCNET 0x001A -#define ETH_P_DSA 0x001B -#define ETH_P_TRAILER 0x001C -#define ETH_P_PHONET 0x00F5 - -struct ethhdr { - uint8_t h_dest[ETH_ALEN]; - uint8_t h_source[ETH_ALEN]; - uint16_t h_proto; -}; - -#include -#include - -struct ether_arp { - struct arphdr ea_hdr; - uint8_t arp_sha[ETH_ALEN]; - uint8_t arp_spa[4]; - uint8_t arp_tha[ETH_ALEN]; - uint8_t arp_tpa[4]; -}; -#define arp_hrd ea_hdr.ar_hrd -#define arp_pro ea_hdr.ar_pro -#define arp_hln ea_hdr.ar_hln -#define arp_pln ea_hdr.ar_pln -#define arp_op ea_hdr.ar_op - -#define ETHER_MAP_IP_MULTICAST(ipaddr, enaddr) \ -do { \ - (enaddr)[0] = 0x01; \ - (enaddr)[1] = 0x00; \ - (enaddr)[2] = 0x5e; \ - (enaddr)[3] = ((uint8_t *)ipaddr)[1] & 0x7f; \ - (enaddr)[4] = ((uint8_t *)ipaddr)[2]; \ - (enaddr)[5] = ((uint8_t *)ipaddr)[3]; \ -} while(0) - - -#endif diff --git a/05/musl-final/include/netinet/in.h b/05/musl-final/include/netinet/in.h deleted file mode 100644 index a641f6a..0000000 --- a/05/musl-final/include/netinet/in.h +++ /dev/null @@ -1,158 +0,0 @@ -#ifndef _NETINET_IN_H -#define _NETINET_IN_H - -#define __NEED_in_addr_t -#define __NEED_in_port_t -#define __NEED_sa_family_t -#define __NEED_struct_in_addr -#define __NEED_uint8_t -#define __NEED_uint16_t -#define __NEED_uint32_t - -#include - -struct sockaddr_in -{ - sa_family_t sin_family; - in_port_t sin_port; - struct in_addr sin_addr; - uint8_t sin_zero[8]; -}; - -struct in6_addr -{ - union { - uint8_t __s6_addr[16]; - uint32_t __s6_addr32[4]; - } __in6_union; -}; -#define s6_addr __in6_union.__s6_addr -#define s6_addr32 __in6_union.__s6_addr32 - -struct sockaddr_in6 -{ - sa_family_t sin6_family; - in_port_t sin6_port; - uint32_t sin6_flowinfo; - struct in6_addr sin6_addr; - uint32_t sin6_scope_id; -}; - -struct ipv6_mreq -{ - struct in6_addr ipv6mr_multiaddr; - unsigned ipv6mr_interface; -}; - -#define INADDR_ANY ((in_addr_t) 0x00000000) -#define INADDR_BROADCAST ((in_addr_t) 0xffffffff) -#define INADDR_NONE ((in_addr_t) 0xffffffff) -#define INADDR_LOOPBACK ((in_addr_t) 0x7f000001) - -#define IN6ADDR_ANY_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } } -#define IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } } - -extern const struct in6_addr in6addr_any, in6addr_loopback; - -#undef INET_ADDRSTRLEN -#undef INET6_ADDRSTRLEN -#define INET_ADDRSTRLEN 16 -#define INET6_ADDRSTRLEN 46 - -uint32_t htonl(uint32_t); -uint16_t htons(uint16_t); -uint32_t ntohl(uint32_t); -uint16_t ntohs(uint16_t); - -#define IPPROTO_IP 0 -#define IPPROTO_ICMP 1 -#define IPPROTO_IGMP 2 -#define IPPROTO_IPIP 4 -#define IPPROTO_TCP 6 -#define IPPROTO_EGP 8 -#define IPPROTO_PUP 12 -#define IPPROTO_UDP 17 -#define IPPROTO_IDP 22 -#define IPPROTO_TP 29 -#define IPPROTO_IPV6 41 -#define IPPROTO_ROUTING 43 -#define IPPROTO_FRAGMENT 44 -#define IPPROTO_RSVP 46 -#define IPPROTO_GRE 47 -#define IPPROTO_ESP 50 -#define IPPROTO_AH 51 -#define IPPROTO_ICMPV6 58 -#define IPPROTO_NONE 59 -#define IPPROTO_DSTOPTS 60 -#define IPPROTO_MTP 92 -#define IPPROTO_ENCAP 98 -#define IPPROTO_PIM 103 -#define IPPROTO_COMP 108 -#define IPPROTO_RAW 255 - -#define IN6_IS_ADDR_UNSPECIFIED(a) \ - (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \ - ((uint32_t *) (a))[2] == 0 && ((uint32_t *) (a))[3] == 0) - -#define IN6_IS_ADDR_LOOPBACK(a) \ - (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \ - ((uint32_t *) (a))[2] == 0 && \ - ((uint8_t *) (a))[12] == 0 && ((uint8_t *) (a))[13] == 0 && \ - ((uint8_t *) (a))[14] == 0 && ((uint8_t *) (a))[15] == 1 ) - -#define IN6_IS_ADDR_MULTICAST(a) (((uint8_t *) (a))[0] == 0xff) - -#define IN6_IS_ADDR_LINKLOCAL(a) \ - ((((uint8_t *) (a))[0]) == 0xfe && (((uint8_t *) (a))[1] & 0xc0) == 0x80) - -#define IN6_IS_ADDR_SITELOCAL(a) \ - ((((uint8_t *) (a))[0]) == 0xfe && (((uint8_t *) (a))[1] & 0xc0) == 0xc0) - -#define IN6_IS_ADDR_V4MAPPED(a) \ - (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \ - ((uint8_t *) (a))[8] == 0 && ((uint8_t *) (a))[9] == 0 && \ - ((uint8_t *) (a))[10] == 0xff && ((uint8_t *) (a))[11] == 0xff) - -#define IN6_IS_ADDR_V4COMPAT(a) \ - (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \ - ((uint32_t *) (a))[2] == 0 && ((uint8_t *) (a))[15] > 1) - -#define IN6_IS_ADDR_MC_NODELOCAL(a) \ - (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x1)) - -#define IN6_IS_ADDR_MC_LINKLOCAL(a) \ - (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x2)) - -#define IN6_IS_ADDR_MC_SITELOCAL(a) \ - (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x5)) - -#define IN6_IS_ADDR_MC_ORGLOCAL(a) \ - (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x8)) - -#define IN6_IS_ADDR_MC_GLOBAL(a) \ - (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0xe)) - -#include - -#if 1 /* FIXME: namespace violation */ -#define IN_CLASSA(a) ((((in_addr_t)(a)) & 0x80000000) == 0) -#define IN_CLASSA_NET 0xff000000 -#define IN_CLASSA_NSHIFT 24 -#define IN_CLASSA_HOST (0xffffffff & ~IN_CLASSA_NET) -#define IN_CLASSA_MAX 128 -#define IN_CLASSB(a) ((((in_addr_t)(a)) & 0xc0000000) == 0x80000000) -#define IN_CLASSB_NET 0xffff0000 -#define IN_CLASSB_NSHIFT 16 -#define IN_CLASSB_HOST (0xffffffff & ~IN_CLASSB_NET) -#define IN_CLASSB_MAX 65536 -#define IN_CLASSC(a) ((((in_addr_t)(a)) & 0xe0000000) == 0xc0000000) -#define IN_CLASSC_NET 0xffffff00 -#define IN_CLASSC_NSHIFT 8 -#define IN_CLASSC_HOST (0xffffffff & ~IN_CLASSC_NET) -#define IN_CLASSD(a) ((((in_addr_t)(a)) & 0xf0000000) == 0xe0000000) -#define IN_MULTICAST(a) IN_CLASSD(a) -#define IN_EXPERIMENTAL(a) ((((in_addr_t)(a)) & 0xe0000000) == 0xe0000000) -#define IN_BADCLASS(a) ((((in_addr_t)(a)) & 0xf0000000) == 0xf0000000) -#endif - -#endif diff --git a/05/musl-final/include/netinet/ip.h b/05/musl-final/include/netinet/ip.h deleted file mode 100644 index 4118741..0000000 --- a/05/musl-final/include/netinet/ip.h +++ /dev/null @@ -1,186 +0,0 @@ -#ifndef _NETINET_IP_H -#define _NETINET_IP_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include - -struct timestamp { - uint8_t len; - uint8_t ptr; -#if __BYTE_ORDER == __LITTLE_ENDIAN - unsigned int flags:4; - unsigned int overflow:4; -#else - unsigned int overflow:4; - unsigned int flags:4; -#endif - uint32_t data[9]; - }; - -struct iphdr { -#if __BYTE_ORDER == __LITTLE_ENDIAN - unsigned int ihl:4; - unsigned int version:4; -#else - unsigned int version:4; - unsigned int ihl:4; -#endif - uint8_t tos; - uint16_t tot_len; - uint16_t id; - uint16_t frag_off; - uint8_t ttl; - uint8_t protocol; - uint16_t check; - uint32_t saddr; - uint32_t daddr; -}; - -struct ip { -#if __BYTE_ORDER == __LITTLE_ENDIAN - unsigned int ip_hl:4; - unsigned int ip_v:4; -#else - unsigned int ip_v:4; - unsigned int ip_hl:4; -#endif - uint8_t ip_tos; - uint16_t ip_len; - uint16_t ip_id; - uint16_t ip_off; - uint8_t ip_ttl; - uint8_t ip_p; - uint16_t ip_sum; - struct in_addr ip_src, ip_dst; -}; - -#define IP_RF 0x8000 -#define IP_DF 0x4000 -#define IP_MF 0x2000 -#define IP_OFFMASK 0x1fff - -struct ip_timestamp { - uint8_t ipt_code; - uint8_t ipt_len; - uint8_t ipt_ptr; -#if __BYTE_ORDER == __LITTLE_ENDIAN - unsigned int ipt_flg:4; - unsigned int ipt_oflw:4; -#else - unsigned int ipt_oflw:4; - unsigned int ipt_flg:4; -#endif - uint32_t data[9]; -}; - -#define IPVERSION 4 -#define IP_MAXPACKET 65535 - -#define IPTOS_ECN_MASK 0x03 -#define IPTOS_ECN(x) ((x) & IPTOS_ECN_MASK) -#define IPTOS_ECN_NOT_ECT 0x00 -#define IPTOS_ECN_ECT1 0x01 -#define IPTOS_ECN_ECT0 0x02 -#define IPTOS_ECN_CE 0x03 - -#define IPTOS_DSCP_MASK 0xfc -#define IPTOS_DSCP(x) ((x) & IPTOS_DSCP_MASK) -#define IPTOS_DSCP_AF11 0x28 -#define IPTOS_DSCP_AF12 0x30 -#define IPTOS_DSCP_AF13 0x38 -#define IPTOS_DSCP_AF21 0x48 -#define IPTOS_DSCP_AF22 0x50 -#define IPTOS_DSCP_AF23 0x58 -#define IPTOS_DSCP_AF31 0x68 -#define IPTOS_DSCP_AF32 0x70 -#define IPTOS_DSCP_AF33 0x78 -#define IPTOS_DSCP_AF41 0x88 -#define IPTOS_DSCP_AF42 0x90 -#define IPTOS_DSCP_AF43 0x98 -#define IPTOS_DSCP_EF 0xb8 - -#define IPTOS_TOS_MASK 0x1E -#define IPTOS_TOS(tos) ((tos) & IPTOS_TOS_MASK) -#define IPTOS_LOWDELAY 0x10 -#define IPTOS_THROUGHPUT 0x08 -#define IPTOS_RELIABILITY 0x04 -#define IPTOS_LOWCOST 0x02 -#define IPTOS_MINCOST IPTOS_LOWCOST - -#define IPTOS_PREC_MASK 0xe0 -#define IPTOS_PREC(tos) ((tos) & IPTOS_PREC_MASK) -#define IPTOS_PREC_NETCONTROL 0xe0 -#define IPTOS_PREC_INTERNETCONTROL 0xc0 -#define IPTOS_PREC_CRITIC_ECP 0xa0 -#define IPTOS_PREC_FLASHOVERRIDE 0x80 -#define IPTOS_PREC_FLASH 0x60 -#define IPTOS_PREC_IMMEDIATE 0x40 -#define IPTOS_PREC_PRIORITY 0x20 -#define IPTOS_PREC_ROUTINE 0x00 - -#define IPOPT_COPY 0x80 -#define IPOPT_CLASS_MASK 0x60 -#define IPOPT_NUMBER_MASK 0x1f - -#define IPOPT_COPIED(o) ((o) & IPOPT_COPY) -#define IPOPT_CLASS(o) ((o) & IPOPT_CLASS_MASK) -#define IPOPT_NUMBER(o) ((o) & IPOPT_NUMBER_MASK) - -#define IPOPT_CONTROL 0x00 -#define IPOPT_RESERVED1 0x20 -#define IPOPT_DEBMEAS 0x40 -#define IPOPT_MEASUREMENT IPOPT_DEBMEAS -#define IPOPT_RESERVED2 0x60 - -#define IPOPT_EOL 0 -#define IPOPT_END IPOPT_EOL -#define IPOPT_NOP 1 -#define IPOPT_NOOP IPOPT_NOP - -#define IPOPT_RR 7 -#define IPOPT_TS 68 -#define IPOPT_TIMESTAMP IPOPT_TS -#define IPOPT_SECURITY 130 -#define IPOPT_SEC IPOPT_SECURITY -#define IPOPT_LSRR 131 -#define IPOPT_SATID 136 -#define IPOPT_SID IPOPT_SATID -#define IPOPT_SSRR 137 -#define IPOPT_RA 148 - -#define IPOPT_OPTVAL 0 -#define IPOPT_OLEN 1 -#define IPOPT_OFFSET 2 -#define IPOPT_MINOFF 4 - -#define MAX_IPOPTLEN 40 - -#define IPOPT_TS_TSONLY 0 -#define IPOPT_TS_TSANDADDR 1 -#define IPOPT_TS_PRESPEC 3 - -#define IPOPT_SECUR_UNCLASS 0x0000 -#define IPOPT_SECUR_CONFID 0xf135 -#define IPOPT_SECUR_EFTO 0x789a -#define IPOPT_SECUR_MMMM 0xbc4d -#define IPOPT_SECUR_RESTR 0xaf13 -#define IPOPT_SECUR_SECRET 0xd788 -#define IPOPT_SECUR_TOPSECRET 0x6bc5 - -#define MAXTTL 255 -#define IPDEFTTL 64 -#define IPFRAGTTL 60 -#define IPTTLDEC 1 - -#define IP_MSS 576 - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/05/musl-final/include/netinet/ip6.h b/05/musl-final/include/netinet/ip6.h deleted file mode 100644 index a4347a5..0000000 --- a/05/musl-final/include/netinet/ip6.h +++ /dev/null @@ -1,142 +0,0 @@ -#ifndef _NETINET_IP6_H -#define _NETINET_IP6_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include - -struct ip6_hdr { - union { - struct ip6_hdrctl { - uint32_t ip6_un1_flow; - uint16_t ip6_un1_plen; - uint8_t ip6_un1_nxt; - uint8_t ip6_un1_hlim; - } ip6_un1; - uint8_t ip6_un2_vfc; - } ip6_ctlun; - struct in6_addr ip6_src; - struct in6_addr ip6_dst; -}; - -#define ip6_vfc ip6_ctlun.ip6_un2_vfc -#define ip6_flow ip6_ctlun.ip6_un1.ip6_un1_flow -#define ip6_plen ip6_ctlun.ip6_un1.ip6_un1_plen -#define ip6_nxt ip6_ctlun.ip6_un1.ip6_un1_nxt -#define ip6_hlim ip6_ctlun.ip6_un1.ip6_un1_hlim -#define ip6_hops ip6_ctlun.ip6_un1.ip6_un1_hlim - -struct ip6_ext { - uint8_t ip6e_nxt; - uint8_t ip6e_len; -}; - -struct ip6_hbh { - uint8_t ip6h_nxt; - uint8_t ip6h_len; -}; - -struct ip6_dest { - uint8_t ip6d_nxt; - uint8_t ip6d_len; -}; - -struct ip6_rthdr { - uint8_t ip6r_nxt; - uint8_t ip6r_len; - uint8_t ip6r_type; - uint8_t ip6r_segleft; -}; - -struct ip6_rthdr0 { - uint8_t ip6r0_nxt; - uint8_t ip6r0_len; - uint8_t ip6r0_type; - uint8_t ip6r0_segleft; - uint8_t ip6r0_reserved; - uint8_t ip6r0_slmap[3]; - struct in6_addr ip6r0_addr[]; -}; - -struct ip6_frag { - uint8_t ip6f_nxt; - uint8_t ip6f_reserved; - uint16_t ip6f_offlg; - uint32_t ip6f_ident; -}; - -#if __BYTE_ORDER == __BIG_ENDIAN -#define IP6F_OFF_MASK 0xfff8 -#define IP6F_RESERVED_MASK 0x0006 -#define IP6F_MORE_FRAG 0x0001 -#else -#define IP6F_OFF_MASK 0xf8ff -#define IP6F_RESERVED_MASK 0x0600 -#define IP6F_MORE_FRAG 0x0100 -#endif - -struct ip6_opt { - uint8_t ip6o_type; - uint8_t ip6o_len; -}; - -#define IP6OPT_TYPE(o) ((o) & 0xc0) -#define IP6OPT_TYPE_SKIP 0x00 -#define IP6OPT_TYPE_DISCARD 0x40 -#define IP6OPT_TYPE_FORCEICMP 0x80 -#define IP6OPT_TYPE_ICMP 0xc0 -#define IP6OPT_TYPE_MUTABLE 0x20 - -#define IP6OPT_PAD1 0 -#define IP6OPT_PADN 1 - -#define IP6OPT_JUMBO 0xc2 -#define IP6OPT_NSAP_ADDR 0xc3 -#define IP6OPT_TUNNEL_LIMIT 0x04 -#define IP6OPT_ROUTER_ALERT 0x05 - -struct ip6_opt_jumbo { - uint8_t ip6oj_type; - uint8_t ip6oj_len; - uint8_t ip6oj_jumbo_len[4]; -}; -#define IP6OPT_JUMBO_LEN 6 - -struct ip6_opt_nsap { - uint8_t ip6on_type; - uint8_t ip6on_len; - uint8_t ip6on_src_nsap_len; - uint8_t ip6on_dst_nsap_len; -}; - -struct ip6_opt_tunnel { - uint8_t ip6ot_type; - uint8_t ip6ot_len; - uint8_t ip6ot_encap_limit; -}; - -struct ip6_opt_router { - uint8_t ip6or_type; - uint8_t ip6or_len; - uint8_t ip6or_value[2]; -}; - -#if __BYTE_ORDER == __BIG_ENDIAN -#define IP6_ALERT_MLD 0x0000 -#define IP6_ALERT_RSVP 0x0001 -#define IP6_ALERT_AN 0x0002 -#else -#define IP6_ALERT_MLD 0x0000 -#define IP6_ALERT_RSVP 0x0100 -#define IP6_ALERT_AN 0x0200 -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/05/musl-final/include/netinet/ip_icmp.h b/05/musl-final/include/netinet/ip_icmp.h deleted file mode 100644 index 2f4a86d..0000000 --- a/05/musl-final/include/netinet/ip_icmp.h +++ /dev/null @@ -1,192 +0,0 @@ -#ifndef _NETINET_IP_ICMP_H -#define _NETINET_IP_ICMP_H - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -struct icmphdr { - uint8_t type; - uint8_t code; - uint16_t checksum; - union { - struct { - uint16_t id; - uint16_t sequence; - } echo; - uint32_t gateway; - struct { - uint16_t __unused; - uint16_t mtu; - } frag; - } un; -}; - -#define ICMP_ECHOREPLY 0 -#define ICMP_DEST_UNREACH 3 -#define ICMP_SOURCE_QUENCH 4 -#define ICMP_REDIRECT 5 -#define ICMP_ECHO 8 -#define ICMP_TIME_EXCEEDED 11 -#define ICMP_PARAMETERPROB 12 -#define ICMP_TIMESTAMP 13 -#define ICMP_TIMESTAMPREPLY 14 -#define ICMP_INFO_REQUEST 15 -#define ICMP_INFO_REPLY 16 -#define ICMP_ADDRESS 17 -#define ICMP_ADDRESSREPLY 18 -#define NR_ICMP_TYPES 18 - - -#define ICMP_NET_UNREACH 0 -#define ICMP_HOST_UNREACH 1 -#define ICMP_PROT_UNREACH 2 -#define ICMP_PORT_UNREACH 3 -#define ICMP_FRAG_NEEDED 4 -#define ICMP_SR_FAILED 5 -#define ICMP_NET_UNKNOWN 6 -#define ICMP_HOST_UNKNOWN 7 -#define ICMP_HOST_ISOLATED 8 -#define ICMP_NET_ANO 9 -#define ICMP_HOST_ANO 10 -#define ICMP_NET_UNR_TOS 11 -#define ICMP_HOST_UNR_TOS 12 -#define ICMP_PKT_FILTERED 13 -#define ICMP_PREC_VIOLATION 14 -#define ICMP_PREC_CUTOFF 15 -#define NR_ICMP_UNREACH 15 - -#define ICMP_REDIR_NET 0 -#define ICMP_REDIR_HOST 1 -#define ICMP_REDIR_NETTOS 2 -#define ICMP_REDIR_HOSTTOS 3 - -#define ICMP_EXC_TTL 0 -#define ICMP_EXC_FRAGTIME 1 - - -struct icmp_ra_addr { - uint32_t ira_addr; - uint32_t ira_preference; -}; - -struct icmp { - uint8_t icmp_type; - uint8_t icmp_code; - uint16_t icmp_cksum; - union { - uint8_t ih_pptr; - struct in_addr ih_gwaddr; - struct ih_idseq { - uint16_t icd_id; - uint16_t icd_seq; - } ih_idseq; - uint32_t ih_void; - - struct ih_pmtu { - uint16_t ipm_void; - uint16_t ipm_nextmtu; - } ih_pmtu; - - struct ih_rtradv { - uint8_t irt_num_addrs; - uint8_t irt_wpa; - uint16_t irt_lifetime; - } ih_rtradv; - } icmp_hun; - union { - struct { - uint32_t its_otime; - uint32_t its_rtime; - uint32_t its_ttime; - } id_ts; - struct { - struct ip idi_ip; - } id_ip; - struct icmp_ra_addr id_radv; - uint32_t id_mask; - uint8_t id_data[1]; - } icmp_dun; -}; - -#define icmp_pptr icmp_hun.ih_pptr -#define icmp_gwaddr icmp_hun.ih_gwaddr -#define icmp_id icmp_hun.ih_idseq.icd_id -#define icmp_seq icmp_hun.ih_idseq.icd_seq -#define icmp_void icmp_hun.ih_void -#define icmp_pmvoid icmp_hun.ih_pmtu.ipm_void -#define icmp_nextmtu icmp_hun.ih_pmtu.ipm_nextmtu -#define icmp_num_addrs icmp_hun.ih_rtradv.irt_num_addrs -#define icmp_wpa icmp_hun.ih_rtradv.irt_wpa -#define icmp_lifetime icmp_hun.ih_rtradv.irt_lifetime -#define icmp_otime icmp_dun.id_ts.its_otime -#define icmp_rtime icmp_dun.id_ts.its_rtime -#define icmp_ttime icmp_dun.id_ts.its_ttime -#define icmp_ip icmp_dun.id_ip.idi_ip -#define icmp_radv icmp_dun.id_radv -#define icmp_mask icmp_dun.id_mask -#define icmp_data icmp_dun.id_data - -#define ICMP_MINLEN 8 -#define ICMP_TSLEN (8 + 3 * sizeof (n_time)) -#define ICMP_MASKLEN 12 -#define ICMP_ADVLENMIN (8 + sizeof (struct ip) + 8) -#define ICMP_ADVLEN(p) (8 + ((p)->icmp_ip.ip_hl << 2) + 8) - -#define ICMP_UNREACH 3 -#define ICMP_SOURCEQUENCH 4 -#define ICMP_ROUTERADVERT 9 -#define ICMP_ROUTERSOLICIT 10 -#define ICMP_TIMXCEED 11 -#define ICMP_PARAMPROB 12 -#define ICMP_TSTAMP 13 -#define ICMP_TSTAMPREPLY 14 -#define ICMP_IREQ 15 -#define ICMP_IREQREPLY 16 -#define ICMP_MASKREQ 17 -#define ICMP_MASKREPLY 18 -#define ICMP_MAXTYPE 18 - -#define ICMP_UNREACH_NET 0 -#define ICMP_UNREACH_HOST 1 -#define ICMP_UNREACH_PROTOCOL 2 -#define ICMP_UNREACH_PORT 3 -#define ICMP_UNREACH_NEEDFRAG 4 -#define ICMP_UNREACH_SRCFAIL 5 -#define ICMP_UNREACH_NET_UNKNOWN 6 -#define ICMP_UNREACH_HOST_UNKNOWN 7 -#define ICMP_UNREACH_ISOLATED 8 -#define ICMP_UNREACH_NET_PROHIB 9 -#define ICMP_UNREACH_HOST_PROHIB 10 -#define ICMP_UNREACH_TOSNET 11 -#define ICMP_UNREACH_TOSHOST 12 -#define ICMP_UNREACH_FILTER_PROHIB 13 -#define ICMP_UNREACH_HOST_PRECEDENCE 14 -#define ICMP_UNREACH_PRECEDENCE_CUTOFF 15 - -#define ICMP_REDIRECT_NET 0 -#define ICMP_REDIRECT_HOST 1 -#define ICMP_REDIRECT_TOSNET 2 -#define ICMP_REDIRECT_TOSHOST 3 - -#define ICMP_TIMXCEED_INTRANS 0 -#define ICMP_TIMXCEED_REASS 1 - -#define ICMP_PARAMPROB_OPTABSENT 1 - -#define ICMP_INFOTYPE(type) \ - ((type) == ICMP_ECHOREPLY || (type) == ICMP_ECHO || \ - (type) == ICMP_ROUTERADVERT || (type) == ICMP_ROUTERSOLICIT || \ - (type) == ICMP_TSTAMP || (type) == ICMP_TSTAMPREPLY || \ - (type) == ICMP_IREQ || (type) == ICMP_IREQREPLY || \ - (type) == ICMP_MASKREQ || (type) == ICMP_MASKREPLY) - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/05/musl-final/include/netinet/tcp.h b/05/musl-final/include/netinet/tcp.h deleted file mode 100644 index ea32ca0..0000000 --- a/05/musl-final/include/netinet/tcp.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef _NETINET_TCP_H -#define _NETINET_TCP_H - -#include - -#endif diff --git a/05/musl-final/include/netinet/udp.h b/05/musl-final/include/netinet/udp.h deleted file mode 100644 index 15b9145..0000000 --- a/05/musl-final/include/netinet/udp.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef _NETINET_UDP_H -#define _NETINET_UDP_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -struct udphdr { - uint16_t source; - uint16_t dest; - uint16_t len; - uint16_t check; -}; - -#define uh_sport source -#define uh_dport dest -#define uh_ulen len -#define uh_sum check - -#define UDP_CORK 1 -#define UDP_ENCAP 100 - -#define UDP_ENCAP_ESPINUDP_NON_IKE 1 -#define UDP_ENCAP_ESPINUDP 2 -#define UDP_ENCAP_L2TPINUDP 3 - -#define SOL_UDP 17 - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/05/musl-final/include/nl_types.h b/05/musl-final/include/nl_types.h deleted file mode 100644 index ca61efb..0000000 --- a/05/musl-final/include/nl_types.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef _NL_TYPES_H -#define _NL_TYPES_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define NL_SETD 1 -#define NL_CAT_LOCALE 1 - -#define __NEED_nl_item -#include - -typedef long nl_catd; - -nl_catd catopen (const char *, int); -char *catgets (nl_catd, int, int, const char *); -int catclose (nl_catd); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/05/musl-final/include/paths.h b/05/musl-final/include/paths.h deleted file mode 100644 index 8a38ba7..0000000 --- a/05/musl-final/include/paths.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef _PATHS_H_ -#define _PATHS_H_ - -#define _PATH_DEFPATH "/usr/local/bin:/bin:/usr/bin" -#define _PATH_STDPATH "/bin:/usr/bin:/sbin:/usr/sbin" - -#define _PATH_BSHELL "/bin/sh" -#define _PATH_CONSOLE "/dev/console" -#define _PATH_CSHELL "/bin/csh" -#define _PATH_DEVDB "/var/run/dev.db" -#define _PATH_DEVNULL "/dev/null" -#define _PATH_DRUM "/dev/drum" -#define _PATH_GSHADOW "/etc/gshadow" -#define _PATH_KLOG "/proc/kmsg" -#define _PATH_KMEM "/dev/kmem" -#define _PATH_LASTLOG "/var/log/lastlog" -#define _PATH_MAILDIR "/var/mail" -#define _PATH_MAN "/usr/share/man" -#define _PATH_MEM "/dev/mem" -#define _PATH_MNTTAB "/etc/fstab" -#define _PATH_MOUNTED "/etc/mtab" -#define _PATH_NOLOGIN "/etc/nologin" -#define _PATH_PRESERVE "/var/lib" -#define _PATH_RWHODIR "/var/spool/rwho" -#define _PATH_SENDMAIL "/usr/sbin/sendmail" -#define _PATH_SHADOW "/etc/shadow" -#define _PATH_SHELLS "/etc/shells" -#define _PATH_TTY "/dev/tty" -#define _PATH_UNIX "/boot/vmlinux" -#define _PATH_UTMP "/var/run/utmp" -#define _PATH_VI "/usr/bin/vi" -#define _PATH_WTMP "/var/log/wtmp" - -#define _PATH_DEV "/dev/" -#define _PATH_TMP "/tmp/" -#define _PATH_VARDB "/var/lib/misc/" -#define _PATH_VARRUN "/var/run/" -#define _PATH_VARTMP "/var/tmp/" - -#endif diff --git a/05/musl-final/include/poll.h b/05/musl-final/include/poll.h deleted file mode 100644 index f868ab5..0000000 --- a/05/musl-final/include/poll.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef _POLL_H -#define _POLL_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define POLLIN 0x001 -#define POLLPRI 0x002 -#define POLLOUT 0x004 -#define POLLERR 0x008 -#define POLLHUP 0x010 -#define POLLNVAL 0x020 -#define POLLRDNORM 0x040 -#define POLLRDBAND 0x080 -#define POLLWRNORM 0x100 -#define POLLWRBAND 0x200 -#define POLLMSG 0x400 - -typedef unsigned int nfds_t; - -struct pollfd -{ - int fd; - short events; - short revents; -}; - -int poll (struct pollfd *, nfds_t, int); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/05/musl-final/include/pthread.h b/05/musl-final/include/pthread.h deleted file mode 100644 index 749a0e8..0000000 --- a/05/musl-final/include/pthread.h +++ /dev/null @@ -1,185 +0,0 @@ -#ifndef _PTHREAD_H -#define _PTHREAD_H -#ifdef __cplusplus -extern "C" { -#endif - -#define __NEED_time_t -#define __NEED_struct_timespec -#define __NEED_sigset_t -#define __NEED_pthread_t -#define __NEED_pthread_attr_t -#define __NEED_pthread_mutexattr_t -#define __NEED_pthread_condattr_t -#define __NEED_pthread_rwlockattr_t -#define __NEED_pthread_barrierattr_t -#define __NEED_pthread_mutex_t -#define __NEED_pthread_cond_t -#define __NEED_pthread_rwlock_t -#define __NEED_pthread_barrier_t -#define __NEED_pthread_spinlock_t -#define __NEED_pthread_key_t -#define __NEED_pthread_once_t -#define __NEED_size_t - -#include - -#include -#include - -#define PTHREAD_CREATE_JOINABLE 0 -#define PTHREAD_CREATE_DETACHED 1 - -#define PTHREAD_MUTEX_NORMAL 0 -#define PTHREAD_MUTEX_DEFAULT 0 -#define PTHREAD_MUTEX_RECURSIVE 1 -#define PTHREAD_MUTEX_ERRORCHECK 2 - -#define PTHREAD_MUTEX_STALLED 0 -#define PTHREAD_MUTEX_ROBUST 1 - -#define PTHREAD_PRIO_NONE 0 -#define PTHREAD_PRIO_INHERIT 1 -#define PTHREAD_PRIO_PROTECT 2 - -#define PTHREAD_INHERIT_SCHED 0 -#define PTHREAD_EXPLICIT_SCHED 1 - -#define PTHREAD_SCOPE_SYSTEM 0 -#define PTHREAD_SCOPE_PROCESS 1 - -#define PTHREAD_PROCESS_PRIVATE 0 -#define PTHREAD_PROCESS_SHARED 1 - - -#define PTHREAD_MUTEX_INITIALIZER {0} -#define PTHREAD_RWLOCK_INITIALIZER {0} -#define PTHREAD_COND_INITIALIZER {0} -#define PTHREAD_ONCE_INIT 0 - - -#define PTHREAD_CANCEL_ENABLE 0 -#define PTHREAD_CANCEL_DISABLE 1 - -#define PTHREAD_CANCEL_DEFERRED 0 -#define PTHREAD_CANCEL_ASYNCHRONOUS 1 - -#define PTHREAD_CANCELLED ((void *)-1) - - -#define PTHREAD_BARRIER_SERIAL_THREAD (-1) - - -int pthread_create(pthread_t *, const pthread_attr_t *, void *(*)(void *), void *); -int pthread_detach(pthread_t); -void pthread_exit(void *); -int pthread_join(pthread_t, void **); - -pthread_t pthread_self(void); -int pthread_equal(pthread_t, pthread_t); - -int pthread_setcancelstate(int, int *); -int pthread_setcanceltype(int, int *); -void pthread_testcancel(void); -int pthread_cancel(pthread_t); - -int pthread_once(pthread_once_t *, void (*)(void)); - -int pthread_mutex_init(pthread_mutex_t *, const pthread_mutexattr_t *); -int pthread_mutex_lock(pthread_mutex_t *); -int pthread_mutex_unlock(pthread_mutex_t *); -int pthread_mutex_trylock(pthread_mutex_t *); -int pthread_mutex_timedlock(pthread_mutex_t *, const struct timespec *); -int pthread_mutex_destroy(pthread_mutex_t *); - -int pthread_cond_init(pthread_cond_t *, const pthread_condattr_t *); -int pthread_cond_destroy(pthread_cond_t *); -int pthread_cond_wait(pthread_cond_t *, pthread_mutex_t *); -int pthread_cond_timedwait(pthread_cond_t *, pthread_mutex_t *, const struct timespec *); -int pthread_cond_broadcast(pthread_cond_t *); -int pthread_cond_signal(pthread_cond_t *); - -int pthread_rwlock_init(pthread_rwlock_t *, const pthread_rwlockattr_t *); -int pthread_rwlock_destroy(pthread_rwlock_t *); -int pthread_rwlock_rdlock(pthread_rwlock_t *); -int pthread_rwlock_tryrdlock(pthread_rwlock_t *); -int pthread_rwlock_timedrdlock(pthread_rwlock_t *, const struct timespec *); -int pthread_rwlock_wrlock(pthread_rwlock_t *); -int pthread_rwlock_trywrlock(pthread_rwlock_t *); -int pthread_rwlock_timedwrlock(pthread_rwlock_t *, const struct timespec *); -int pthread_rwlock_unlock(pthread_rwlock_t *); - -int pthread_spin_init(pthread_spinlock_t *, int); -int pthread_spin_destroy(pthread_spinlock_t *); -int pthread_spin_lock(pthread_spinlock_t *); -int pthread_spin_trylock(pthread_spinlock_t *); -int pthread_spin_unlock(pthread_spinlock_t *); - -int pthread_barrier_init(pthread_barrier_t *, const pthread_barrierattr_t *, unsigned); -int pthread_barrier_destroy(pthread_barrier_t *); -int pthread_barrier_wait(pthread_barrier_t *); - -int pthread_key_create(pthread_key_t *, void (*)(void *)); -int pthread_key_delete(pthread_key_t); -void *pthread_getspecific(pthread_key_t); -int pthread_setspecific(pthread_key_t, const void *); - -int pthread_attr_init(pthread_attr_t *); -int pthread_attr_destroy(pthread_attr_t *); - -int pthread_attr_getguardsize(pthread_attr_t *, size_t *); -int pthread_attr_setguardsize(pthread_attr_t *, size_t); -int pthread_attr_getstacksize(pthread_attr_t *, size_t *); -int pthread_attr_setstacksize(pthread_attr_t *, size_t); -int pthread_attr_getdetachstate(pthread_attr_t *, int *); -int pthread_attr_setdetachstate(pthread_attr_t *, int); -int pthread_attr_getstack(pthread_attr_t *, void **, size_t *); -int pthread_attr_setstack(pthread_attr_t *, void *, size_t); -int pthread_attr_getscope(pthread_attr_t *, int *); -int pthread_attr_setscope(pthread_attr_t *, int); -int pthread_attr_getschedpolicy(pthread_attr_t *, int *); -int pthread_attr_setschedpolicy(pthread_attr_t *, int); -int pthread_attr_getschedparam(pthread_attr_t *, struct sched_param *); -int pthread_attr_setschedparam(pthread_attr_t *, const struct sched_param *); -int pthread_attr_getinheritsched(pthread_attr_t *, int *); -int pthread_attr_setinheritsched(pthread_attr_t *, int); - -int pthread_mutexattr_destroy(pthread_mutexattr_t *); -int pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *, int *); -int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *, int *); -int pthread_mutexattr_getpshared(const pthread_mutexattr_t *, int *); -int pthread_mutexattr_getrobust(const pthread_mutexattr_t *, int *); -int pthread_mutexattr_gettype(const pthread_mutexattr_t *, int *); -int pthread_mutexattr_init(pthread_mutexattr_t *); -int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *, int); -int pthread_mutexattr_setprotocol(pthread_mutexattr_t *, int); -int pthread_mutexattr_setpshared(pthread_mutexattr_t *, int); -int pthread_mutexattr_setrobust(pthread_mutexattr_t *, int); -int pthread_mutexattr_settype(pthread_mutexattr_t *, int); - -int pthread_barrierattr_destroy(pthread_barrierattr_t *); -int pthread_barrierattr_getpshared(const pthread_barrierattr_t *, int *); -int pthread_barrierattr_init(pthread_barrierattr_t *); -int pthread_barrierattr_setpshared(pthread_barrierattr_t *, int); - -#include - -int __setjmp(void *); -void __pthread_register_cancel(struct __ptcb *); -void __pthread_unregister_cancel(struct __ptcb *); -void __pthread_unwind_next(struct __ptcb *); - -#define pthread_cleanup_push(f, x) \ -do { struct __ptcb __cb; void (*__f)(void *) = (f); void *__x = (x); \ -if (__setjmp(__cb.__jb)) __f(__x), __pthread_unwind_next(&__cb); \ -__pthread_register_cancel(&__cb); { - -#define pthread_cleanup_pop(r) ; } \ -__pthread_unregister_cancel(&__cb); \ -if (r) __f(__x); } while (0) - - -#ifdef __cplusplus -} -#endif -#endif diff --git a/05/musl-final/include/pty.h b/05/musl-final/include/pty.h deleted file mode 100644 index 9444e5e..0000000 --- a/05/musl-final/include/pty.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef _PTY_H -#define _PTY_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -int openpty(int *, int *, char *, const struct termios *, const struct winsize *); - -#ifdef __cplusplus -extern } -#endif - -#endif diff --git a/05/musl-final/include/pwd.h b/05/musl-final/include/pwd.h deleted file mode 100644 index 5abfbfd..0000000 --- a/05/musl-final/include/pwd.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef _PWD_H -#define _PWD_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define __NEED_size_t -#define __NEED_uid_t -#define __NEED_gid_t - -#include - -struct passwd -{ - char *pw_name; - char *pw_passwd; - uid_t pw_uid; - gid_t pw_gid; - char *pw_gecos; - char *pw_dir; - char *pw_shell; -}; - -void setpwent (void); -void endpwent (void); -struct passwd *getpwent (void); - -struct passwd *getpwuid (uid_t); -struct passwd *getpwnam (const char *); -int getpwuid_r (uid_t, struct passwd *, char *, size_t, struct passwd **); -int getpwnam_r (const char *, struct passwd *, char *, size_t, struct passwd **); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/05/musl-final/include/regex.h b/05/musl-final/include/regex.h deleted file mode 100644 index 3673bfa..0000000 --- a/05/musl-final/include/regex.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef _REGEX_H -#define _REGEX_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define __NEED_size_t - -#include - -typedef long regoff_t; - -typedef struct { - size_t re_nsub; - void *__opaque; -} regex_t; - -typedef struct { - regoff_t rm_so; - regoff_t rm_eo; -} regmatch_t; - -#define REG_EXTENDED 1 -#define REG_ICASE 2 -#define REG_NEWLINE 4 -#define REG_NOSUB 8 - -#define REG_NOTBOL 1 -#define REG_NOTEOL 2 - -#define REG_OK 0 -#define REG_NOMATCH 1 -#define REG_BADPAT 2 -#define REG_ECOLLATE 3 -#define REG_ECTYPE 4 -#define REG_EESCAPE 5 -#define REG_ESUBREG 6 -#define REG_EBRACK 7 -#define REG_EPAREN 8 -#define REG_EBRACE 9 -#define REG_BADBR 10 -#define REG_ERANGE 11 -#define REG_ESPACE 12 -#define REG_BADRPT 13 - -#define REG_ENOSYS -1 - -int regcomp(regex_t *, const char *, int); -int regexec(const regex_t *, const char *, size_t, regmatch_t [], int); -void regfree(regex_t *); - -size_t regerror(int, const regex_t *, char *, size_t); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/05/musl-final/include/resolv.h b/05/musl-final/include/resolv.h deleted file mode 100644 index 3b77fc7..0000000 --- a/05/musl-final/include/resolv.h +++ /dev/null @@ -1,143 +0,0 @@ -#ifndef _RESOLV_H_ -#define _RESOLV_H_ - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define MAXNS 3 -#define MAXDFLSRCH 3 -#define MAXDNSRCH 6 -#define LOCALDOMAINPARTS 2 - -#define RES_TIMEOUT 5 -#define MAXRESOLVSORT 10 -#define RES_MAXNDOTS 15 -#define RES_MAXRETRANS 30 -#define RES_MAXRETRY 5 -#define RES_DFLRETRY 2 -#define RES_MAXTIME 65535 - -/* unused; purely for broken apps */ -typedef struct __res_state { - int retrans; - int retry; - unsigned long options; - int nscount; - struct sockaddr_in nsaddr_list[MAXNS]; -# define nsaddr nsaddr_list[0] - unsigned short id; - char *dnsrch[MAXDNSRCH+1]; - char defdname[256]; - unsigned long pfcode; - unsigned ndots:4; - unsigned nsort:4; - unsigned ipv6_unavail:1; - unsigned unused:23; - struct { - struct in_addr addr; - uint32_t mask; - } sort_list[MAXRESOLVSORT]; - void *qhook; - void *rhook; - int res_h_errno; - int _vcsock; - unsigned _flags; - union { - char pad[52]; - struct { - uint16_t nscount; - uint16_t nsmap[MAXNS]; - int nssocks[MAXNS]; - uint16_t nscount6; - uint16_t nsinit; - struct sockaddr_in6 *nsaddrs[MAXNS]; - unsigned int _initstamp[2]; - } _ext; - } _u; -} *res_state; - -#define __RES 19991006 - -#ifndef _PATH_RESCONF -#define _PATH_RESCONF "/etc/resolv.conf" -#endif - -struct res_sym { - int number; - char *name; - char *humanname; -}; - -#define RES_F_VC 0x00000001 -#define RES_F_CONN 0x00000002 -#define RES_F_EDNS0ERR 0x00000004 - -#define RES_EXHAUSTIVE 0x00000001 - -#define RES_INIT 0x00000001 -#define RES_DEBUG 0x00000002 -#define RES_AAONLY 0x00000004 -#define RES_USEVC 0x00000008 -#define RES_PRIMARY 0x00000010 -#define RES_IGNTC 0x00000020 -#define RES_RECURSE 0x00000040 -#define RES_DEFNAMES 0x00000080 -#define RES_STAYOPEN 0x00000100 -#define RES_DNSRCH 0x00000200 -#define RES_INSECURE1 0x00000400 -#define RES_INSECURE2 0x00000800 -#define RES_NOALIASES 0x00001000 -#define RES_USE_INET6 0x00002000 -#define RES_ROTATE 0x00004000 -#define RES_NOCHECKNAME 0x00008000 -#define RES_KEEPTSIG 0x00010000 -#define RES_BLAST 0x00020000 -#define RES_USEBSTRING 0x00040000 -#define RES_NOIP6DOTINT 0x00080000 -#define RES_USE_EDNS0 0x00100000 -#define RES_SNGLKUP 0x00200000 -#define RES_SNGLKUPREOP 0x00400000 -#define RES_USE_DNSSEC 0x00800000 - -#define RES_DEFAULT (RES_RECURSE|RES_DEFNAMES|RES_DNSRCH|RES_NOIP6DOTINT) - -#define RES_PRF_STATS 0x00000001 -#define RES_PRF_UPDATE 0x00000002 -#define RES_PRF_CLASS 0x00000004 -#define RES_PRF_CMD 0x00000008 -#define RES_PRF_QUES 0x00000010 -#define RES_PRF_ANS 0x00000020 -#define RES_PRF_AUTH 0x00000040 -#define RES_PRF_ADD 0x00000080 -#define RES_PRF_HEAD1 0x00000100 -#define RES_PRF_HEAD2 0x00000200 -#define RES_PRF_TTLID 0x00000400 -#define RES_PRF_HEADX 0x00000800 -#define RES_PRF_QUERY 0x00001000 -#define RES_PRF_REPLY 0x00002000 -#define RES_PRF_INIT 0x00004000 - -extern struct __res_state *__res_state(void); -#define _res (*__res_state()) - -struct rrec; - -int res_init(void); -int res_query(const char *, int, int, unsigned char *, int); -int res_querydomain(const char *, const char *, int, int, unsigned char *, int); -int res_search(const char *, int, int, unsigned char *, int); -int res_mkquery(int, const char *, int, int, char *, int, struct rrec *, char *, int); -int res_send(const char *, int, char *, int); -int dn_comp(unsigned char *, unsigned char *, int, unsigned char **, unsigned char *, unsigned char **); -int dn_expand(unsigned char *, unsigned char *, unsigned char *, unsigned char *, int); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/05/musl-final/include/sched.h b/05/musl-final/include/sched.h deleted file mode 100644 index 4d8bd3d..0000000 --- a/05/musl-final/include/sched.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef _SCHED_H -#define _SCHED_H -#ifdef __cplusplus -extern "C" { -#endif - -#define __NEED_struct_timespec -#define __NEED_pid_t -#define __NEED_time_t - -#include - -struct sched_param { - int sched_priority; - int sched_ss_low_priority; - struct timespec sched_ss_repl_period; - struct timespec sched_ss_init_budget; - int sched_ss_max_repl; -}; - -int sched_get_priority_max(int); -int sched_get_priority_min(int); -int sched_getparam(pid_t, struct sched_param *); -int sched_getscheduler(pid_t); -int sched_rr_get_interval(pid_t, struct timespec *); -int sched_setparam(pid_t, const struct sched_param *); -int sched_setscheduler(pid_t, int, const struct sched_param *); -int sched_yield(void); - -#define SCHED_OTHER 0 -#define SCHED_FIFO 1 -#define SCHED_RR 2 - -#ifdef __cplusplus -} -#endif -#endif diff --git a/05/musl-final/include/search.h b/05/musl-final/include/search.h deleted file mode 100644 index 9254ed0..0000000 --- a/05/musl-final/include/search.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef _SEARCH_H -#define _SEARCH_H - -// FIXME!!! - -#endif diff --git a/05/musl-final/include/semaphore.h b/05/musl-final/include/semaphore.h deleted file mode 100644 index 5b68986..0000000 --- a/05/musl-final/include/semaphore.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef _SEMAPHORE_H -#define _SEMAPHORE_H -#ifdef __cplusplus -extern "C" { -#endif - -#define SEM_FAILED ((sem_t *)0) - -typedef struct { - long __val[4]; -} sem_t; - -int sem_close(sem_t *); -int sem_destroy(sem_t *); -int sem_getvalue(sem_t *, int *); -int sem_init(sem_t *, int, unsigned); -sem_t *sem_open(const char *, int, ...); -int sem_post(sem_t *); -int sem_timedwait(sem_t *, const struct timespec *); -int sem_trywait(sem_t *); -int sem_unlink(const char *); -int sem_wait(sem_t *); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/05/musl-final/include/setjmp.h b/05/musl-final/include/setjmp.h deleted file mode 100644 index b024c44..0000000 --- a/05/musl-final/include/setjmp.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef _SETJMP_H -#define _SETJMP_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) -typedef unsigned long sigjmp_buf[(128+sizeof(jmp_buf))/sizeof(long)]; -#ifdef _GNU_SOURCE -#define jmp_buf sigjmp_buf -#endif -int sigsetjmp (sigjmp_buf, int); -void siglongjmp (sigjmp_buf, int); -#endif - - -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) -int _setjmp (jmp_buf); -void _longjmp (jmp_buf, int); -#endif - - -int setjmp (jmp_buf); -void longjmp (jmp_buf, int); - -#define setjmp setjmp -#define longjmp longjmp - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/05/musl-final/include/shadow.h b/05/musl-final/include/shadow.h deleted file mode 100644 index 2b1be41..0000000 --- a/05/musl-final/include/shadow.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef _SHADOW_H -#define _SHADOW_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define __NEED_FILE -#define __NEED_size_t - -#include - -#define SHADOW "/etc/shadow" - -struct spwd { - char *sp_namp; - char *sp_pwdp; - long sp_lstchg; - long sp_min; - long sp_max; - long sp_warn; - long sp_inact; - long sp_expire; - unsigned long sp_flag; -}; - -void setspent(void); -void endspent(void); -struct spwd *getspent(void); -struct spwd *fgetspent(FILE *); -struct spwd *sgetspent(const char *); -int putspent(const struct spwd *, FILE *); - -struct spwd *getspnam(const char *); -int getspnam_r(const char *, struct spwd *, char *, size_t, struct spwd **); - -int lckpwdf(void); -int ulckpwdf(void); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/05/musl-final/include/signal.h b/05/musl-final/include/signal.h deleted file mode 100644 index 9db7b2e..0000000 --- a/05/musl-final/include/signal.h +++ /dev/null @@ -1,105 +0,0 @@ -#ifndef _SIGNAL_H -#define _SIGNAL_H - -#ifdef __cplusplus -extern "C" { -#endif - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) - -#define __NEED_size_t -#define __NEED_pid_t -#define __NEED_uid_t -#define __NEED_struct_timespec -#define __NEED_pthread_t -#define __NEED_time_t -#define __NEED_clock_t -#define __NEED_sigset_t -#define __NEED_siginfo_t - -#include - -struct sigaction -{ - union { - void (*sa_handler)(int); - void (*sa_sigaction)(int, siginfo_t *, void *); - } __sa_handler; - sigset_t sa_mask; - int sa_flags; - void (*__sa_restorer)(void); -}; -#define sa_handler __sa_handler.sa_handler -#define sa_sigaction __sa_handler.sa_sigaction - -typedef struct -{ - void *ss_sp; - int ss_flags; - size_t ss_size; -} stack_t; - -union sigval -{ - int sival_int; - void *sival_ptr; -}; - -int __libc_current_sigrtmin(void); -int __libc_current_sigrtmax(void); - -#define SIGRTMIN (__libc_current_sigrtmin()) -#define SIGRTMAX (__libc_current_sigrtmax()) - -int kill(pid_t, int); - -int sigemptyset(sigset_t *); -int sigfillset(sigset_t *); -int sigaddset(sigset_t *, int); -int sigdelset(sigset_t *, int); -int sigismember(const sigset_t *, int); - -int sigprocmask(int, const sigset_t *, sigset_t *); -int sigsuspend(const sigset_t *); -int sigaction(int, const struct sigaction *, struct sigaction *); -int sigpending(sigset_t *); -int sigwait(const sigset_t *, int *); -int sigwaitinfo(const sigset_t *, siginfo_t *); -int sigtimedwait(const sigset_t *, siginfo_t *, const struct timespec *); -int sigqueue(pid_t, int, const union sigval); - -int pthread_sigmask(int, const sigset_t *, sigset_t *); -int pthread_kill(pthread_t, int); - -#endif - -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) -int killpg(pid_t, int); -int sigaltstack(const stack_t *, stack_t *); -int sighold(int); -int sigignore(int); -int siginterrupt(int, int); -int sigpause(int); -int sigrelse(int); -void (*sigset(int, void (*)(int)))(int); -#endif - -#ifdef _GNU_SOURCE -typedef int (*sighandler_t)(int); -void (*bsd_signal(int, void (*)(int)))(int); -#define __siginfo siginfo -#endif - -#include - -typedef int sig_atomic_t; - -void (*signal(int, void (*)(int)))(int); -int raise(int); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/05/musl-final/include/stdarg.h b/05/musl-final/include/stdarg.h deleted file mode 100644 index 1a455d2..0000000 --- a/05/musl-final/include/stdarg.h +++ /dev/null @@ -1,87 +0,0 @@ -#ifndef _STDARG_H -#define _STDARG_H - -#ifdef __GNUC__ -#define va_list __builtin_va_list -#define va_arg __builtin_va_arg -#define va_start __builtin_va_start -#define va_end __builtin_va_end -#define va_copy __builtin_va_copy -#else -#ifdef __x86_64__ -#ifndef _WIN64 - -//This should be in sync with the declaration on our lib/libtcc1.c -/* GCC compatible definition of va_list. */ -typedef struct { - unsigned int gp_offset; - unsigned int fp_offset; - union { - unsigned int overflow_offset; - char *overflow_arg_area; - }; - char *reg_save_area; -} __va_list_struct; - -typedef __va_list_struct va_list[1]; - -void __va_start(__va_list_struct *ap, void *fp); -void *__va_arg(__va_list_struct *ap, int arg_type, int size, int align); - -#define va_start(ap, last) __va_start(ap, __builtin_frame_address(0)) -#define va_arg(ap, type) \ - (*(type *)(__va_arg(ap, __builtin_va_arg_types(type), sizeof(type), __alignof__(type)))) -#define va_copy(dest, src) (*(dest) = *(src)) -#define va_end(ap) - -/* avoid conflicting definition for va_list on Macs. */ -#define _VA_LIST_T - -#else /* _WIN64 */ -typedef char *va_list; -#define va_start(ap,last) __builtin_va_start(ap,last) -#define va_arg(ap, t) ((sizeof(t) > 8 || (sizeof(t) & (sizeof(t) - 1))) \ - ? **(t **)((ap += 8) - 8) : *(t *)((ap += 8) - 8)) -#define va_copy(dest, src) ((dest) = (src)) -#define va_end(ap) -#endif - -#elif __arm__ -typedef char *va_list; -#define _tcc_alignof(type) ((int)&((struct {char c;type x;} *)0)->x) -#define _tcc_align(addr,type) (((unsigned)addr + _tcc_alignof(type) - 1) \ - & ~(_tcc_alignof(type) - 1)) -#define va_start(ap,last) ap = ((char *)&(last)) + ((sizeof(last)+3)&~3) -#define va_arg(ap,type) (ap = (void *) ((_tcc_align(ap,type)+sizeof(type)+3) \ - &~3), *(type *)(ap - ((sizeof(type)+3)&~3))) -#define va_copy(dest, src) (dest) = (src) -#define va_end(ap) - -#elif defined(__aarch64__) -typedef struct { - void *__stack; - void *__gr_top; - void *__vr_top; - int __gr_offs; - int __vr_offs; -} va_list; -#define va_start(ap, last) __va_start(ap, last) -#define va_arg(ap, type) __va_arg(ap, type) -#define va_end(ap) -#define va_copy(dest, src) ((dest) = (src)) - -#else /* __i386__ */ -typedef char *va_list; -/* only correct for i386 */ -#define va_start(ap,last) ap = ((char *)&(last)) + ((sizeof(last)+3)&~3) -#define va_arg(ap,type) (ap += (sizeof(type)+3)&~3, *(type *)(ap - ((sizeof(type)+3)&~3))) -#define va_copy(dest, src) (dest) = (src) -#define va_end(ap) -#endif - -/* fix a buggy dependency on GCC in libio.h */ -typedef va_list __gnuc_va_list; -#define _VA_LIST_DEFINED -#endif - -#endif /* _STDARG_H */ diff --git a/05/musl-final/include/stdbool.h b/05/musl-final/include/stdbool.h deleted file mode 100644 index 3d8fbf2..0000000 --- a/05/musl-final/include/stdbool.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef _STDBOOL_H -#define _STDBOOL_H - -#ifndef __cplusplus - -#define true 1 -#define false 0 - -typedef _Bool bool; - -#endif - -#endif diff --git a/05/musl-final/include/stddef.h b/05/musl-final/include/stddef.h deleted file mode 100644 index dbf5a4a..0000000 --- a/05/musl-final/include/stddef.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef _STDDEF_H -#define _STDDEF_H - -#undef NULL -#ifdef __cplusplus -#define NULL 0 -#else -#define NULL ((void*)0) -#endif - -#define __NEED_ptrdiff_t -#define __NEED_size_t -#define __NEED_wchar_t - -#include - -#define offsetof(type, member) ((size_t)( (char *)&(((type *)0)->member) - (char *)0 )) - -#endif diff --git a/05/musl-final/include/stdint.h b/05/musl-final/include/stdint.h deleted file mode 100644 index 4d24fd2..0000000 --- a/05/musl-final/include/stdint.h +++ /dev/null @@ -1,107 +0,0 @@ -#ifndef _STDINT_H -#define _STDINT_H - -#define __NEED_int8_t -#define __NEED_int16_t -#define __NEED_int32_t -#define __NEED_int64_t - -#define __NEED_uint8_t -#define __NEED_uint16_t -#define __NEED_uint32_t -#define __NEED_uint64_t - -#define __NEED_int_least8_t -#define __NEED_int_least16_t -#define __NEED_int_least32_t -#define __NEED_int_least64_t - -#define __NEED_uint_least8_t -#define __NEED_uint_least16_t -#define __NEED_uint_least32_t -#define __NEED_uint_least64_t - -#define __NEED_int_fast8_t -#define __NEED_int_fast16_t -#define __NEED_int_fast32_t -#define __NEED_int_fast64_t - -#define __NEED_uint_fast8_t -#define __NEED_uint_fast16_t -#define __NEED_uint_fast32_t -#define __NEED_uint_fast64_t - -#define __NEED_intptr_t -#define __NEED_uintptr_t -#define __NEED_intmax_t -#define __NEED_uintmax_t - -#include - -#if !defined __cplusplus || defined __STDC_LIMIT_MACROS - -#define INT8_MIN (-1-0x7f) -#define INT16_MIN (-1-0x7fff) -#define INT32_MIN (-1-0x7fffffff) -#define INT64_MIN (-1-0x7fffffffffffffffLL) - -#define INT8_MAX (0x7f) -#define INT16_MAX (0x7fff) -#define INT32_MAX (0x7fffffff) -#define INT64_MAX (0x7fffffffffffffffLL) - -#define UINT8_MAX (0xff) -#define UINT16_MAX (0xffff) -#define UINT32_MAX (0xffffffff) -#define UINT64_MAX (0xffffffffffffffffULL) - -#define INT_LEAST8_MIN INT8_MIN -#define INT_LEAST16_MIN INT16_MIN -#define INT_LEAST32_MIN INT32_MIN -#define INT_LEAST64_MIN INT64_MIN - -#define INT_LEAST8_MAX INT8_MAX -#define INT_LEAST16_MAX INT16_MAX -#define INT_LEAST32_MAX INT32_MAX -#define INT_LEAST64_MAX INT64_MAX - -#define UINT_LEAST8_MAX UINT8_MAX -#define UINT_LEAST16_MAX UINT16_MAX -#define UINT_LEAST32_MAX UINT32_MAX -#define UINT_LEAST64_MAX UINT64_MAX - -#undef WCHAR_MIN -#undef WCHAR_MAX -#undef WINT_MIN -#undef WINT_MAX -#define WCHAR_MIN INT32_MIN -#define WCHAR_MAX INT32_MAX -#define WINT_MIN INT32_MIN -#define WINT_MAX INT32_MAX - -#define INTMAX_MIN INT64_MIN -#define INTMAX_MAX INT64_MAX -#define UINTMAX_MAX UINT64_MAX - -#include - -#endif - -#if !defined __cplusplus || defined __STDC_CONSTANT_MACROS - -#define INT8_C(c) c -#define INT16_C(c) c -#define INT32_C(c) c -#define INT64_C(c) c ## LL - -#define UINT8_C(c) c ## U -#define UINT16_C(c) c ## U -#define UINT32_C(c) c ## U -#define UINT64_C(c) c ## ULL - -#define INTMAX_C(c) c ## LL -#define UINTMAX_C(c) c ## ULL - -#endif - -#endif diff --git a/05/musl-final/include/stdio.h b/05/musl-final/include/stdio.h deleted file mode 100644 index 4abb1e6..0000000 --- a/05/musl-final/include/stdio.h +++ /dev/null @@ -1,163 +0,0 @@ -#ifndef _STDIO_H -#define _STDIO_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define __NEED_FILE -#define __NEED_va_list -#define __NEED_size_t - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) -#define __NEED_ssize_t -#define __NEED_off_t -#endif - -#include - -#undef NULL -#ifdef __cplusplus -#define NULL 0 -#else -#define NULL ((void*)0) -#endif - -#undef EOF -#define EOF (-1) - -#undef SEEK_SET -#undef SEEK_CUR -#undef SEEK_END -#define SEEK_SET 0 -#define SEEK_CUR 1 -#define SEEK_END 2 - -#define _IOFBF 0 -#define _IOLBF 1 -#define _IONBF 2 - -#define BUFSIZ 1024 -#define FILENAME_MAX 4095 -#define FOPEN_MAX 1000 -#define TMP_MAX 10000 -#define L_tmpnam 20 - -typedef union { - char __opaque[16]; - double __align; -} fpos_t; - -extern FILE *const stdin; -extern FILE *const stdout; -extern FILE *const stderr; - -#define stdin (stdin) -#define stdout (stdout) -#define stderr (stderr) - -FILE *fopen(const char *, const char *); -FILE *freopen(const char *, const char *, FILE *); -int fclose(FILE *); - -int remove(const char *); -int rename(const char *, const char *); - -int feof(FILE *); -int ferror(FILE *); -int fflush(FILE *); -void clearerr(FILE *); - -int fseek(FILE *, long, int); -long ftell(FILE *); -void rewind(FILE *); - -int fgetpos(FILE *, fpos_t *); -int fsetpos(FILE *, const fpos_t *); - -size_t fread(void *, size_t, size_t, FILE *); -size_t fwrite(const void *, size_t, size_t, FILE *); - -int fgetc(FILE *); -int getc(FILE *); -int getchar(void); -int ungetc(int, FILE *); - -int fputc(int, FILE *); -int putc(int, FILE *); -int putchar(int); - -char *fgets(char *, int, FILE *); -char *gets(char *); - -int fputs(const char *, FILE *); -int puts(const char *); - -int printf(const char *, ...); -int fprintf(FILE *, const char *, ...); -int sprintf(char *, const char *, ...); -int snprintf(char *, size_t, const char *, ...); - -int vprintf(const char *, va_list); -int vfprintf(FILE *, const char *, va_list); -int vsprintf(char *, const char *, va_list); -int vsnprintf(char *, size_t, const char *, va_list); - -int scanf(const char *, ...); -int fscanf(FILE *, const char *, ...); -int sscanf(const char *, const char *, ...); -int vscanf(const char *, va_list); -int vfscanf(FILE *, const char *, va_list); -int vsscanf(const char *, const char *, va_list); - -void perror(const char *); - -int setvbuf(FILE *, char *, int, size_t); -void setbuf(FILE *, char *); - -char *tmpnam(char *); -FILE *tmpfile(void); - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) -FILE *fdopen(int, const char *); -FILE *popen(const char *, const char *); -int pclose(FILE *); -int fileno(FILE *); -int fseeko(FILE *, off_t, int); -off_t ftello(FILE *); -int dprintf(int, const char *, ...); -int vdprintf(int, const char *, va_list); -void flockfile(FILE *); -int ftrylockfile(FILE *); -void funlockfile(FILE *); -int getc_unlocked(FILE *); -int getchar_unlocked(void); -int putc_unlocked(int, FILE *); -int putchar_unlocked(int); -ssize_t getdelim(char **, size_t *, int, FILE *); -ssize_t getline(char **, size_t *, FILE *); -int renameat(int, const char *, int, const char *); -char *ctermid(char *); -#define L_ctermid 20 -#endif - - -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) -#define P_tmpdir "/tmp" -char *tempnam(const char *, const char *); -#endif - -#if defined(_GNU_SOURCE) -#define L_cuserid 20 -char *cuserid(char *); -#undef off64_t -#define off64_t off_t -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/05/musl-final/include/stdlib.h b/05/musl-final/include/stdlib.h deleted file mode 100644 index 047a5f3..0000000 --- a/05/musl-final/include/stdlib.h +++ /dev/null @@ -1,134 +0,0 @@ -#ifndef _STDLIB_H -#define _STDLIB_H - -#ifdef __cplusplus -extern "C" { -#endif - -#undef NULL -#ifdef __cplusplus -#define NULL 0 -#else -#define NULL ((void*)0) -#endif - -#define __NEED_size_t -#define __NEED_wchar_t - -#include - -int atoi (const char *); -long atol (const char *); -long long atoll (const char *); -double atof (const char *); - -float strtof (const char *, char **); -double strtod (const char *, char **); -long double strtold (const char *, char **); - -long strtol (const char *, char **, int); -unsigned long strtoul (const char *, char **, int); -long long strtoll (const char *, char **, int); -unsigned long long strtoull (const char *, char **, int); - -int rand (void); -void srand (unsigned); - -void *malloc (size_t); -void *calloc (size_t, size_t); -void *realloc (void *, size_t); -void free (void *); - -void abort (void); -int atexit (void (*) (void)); -void exit (int); -void _Exit (int); - -char *getenv (const char *); - -int system (const char *); - -void *bsearch (const void *, const void *, size_t, size_t, int (*)(const void *, const void *)); -void qsort (void *, size_t, size_t, int (*)(const void *, const void *)); - -int abs (int); -long labs (long); -long long llabs (long long); - -typedef struct { int quot, rem; } div_t; -typedef struct { long quot, rem; } ldiv_t; -typedef struct { long long quot, rem; } lldiv_t; - -div_t div (int, int); -ldiv_t ldiv (long, long); -lldiv_t lldiv (long long, long long); - -int mblen (const char *, size_t); -int mbtowc (wchar_t *, const char *, size_t); -int wctomb (char *, wchar_t); -size_t mbstowcs (wchar_t *, const char *, size_t); -size_t wcstombs (char *, const wchar_t *, size_t); - -#define EXIT_FAILURE 1 -#define EXIT_SUCCESS 0 - -#define MB_CUR_MAX ((size_t)+4) - -#define RAND_MAX (0x7fffffff) - - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) - -#ifndef WEXITSTATUS -#include -#endif - -int posix_memalign (void **, size_t, size_t); -int setenv (const char *, const char *, int); -int unsetenv (const char *); -int mkstemp (char *); -char *mkdtemp (char *); -int getsubopt (char **, char *const *, char **); -int rand_r (unsigned *); - -#endif - - -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) -int putenv (char *); -int posix_openpt (int); -int grantpt (int); -int unlockpt (int); -char *ptsname (int); -char *realpath (const char *, char *); -char *l64a (long); -long a64l (const char *); -void setkey (const char *); -long int random (void); -void srandom (unsigned int); -char *initstate (unsigned int, char *, size_t); -char *setstate (char *); -double drand48 (void); -double erand48 (unsigned short [3]); -long int lrand48 (void); -long int nrand48 (unsigned short [3]); -long mrand48 (void); -long jrand48 (unsigned short [3]); -void srand48 (long); -unsigned short *seed48 (unsigned short [3]); -void lcong48 (unsigned short [7]); -#endif - -#if defined(_GNU_SOURCE) -char *mktemp (char *); -void *valloc (size_t); -void *memalign(size_t, size_t); -#endif - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/05/musl-final/include/string.h b/05/musl-final/include/string.h deleted file mode 100644 index fb18537..0000000 --- a/05/musl-final/include/string.h +++ /dev/null @@ -1,78 +0,0 @@ -#ifndef _STRING_H -#define _STRING_H - -#ifdef __cplusplus -extern "C" { -#endif - -#undef NULL -#ifdef __cplusplus -#define NULL 0 -#else -#define NULL ((void*)0) -#endif - -#define __NEED_size_t -#include - -void *memcpy (void *, const void *, size_t); -void *memmove (void *, const void *, size_t); -void *memccpy (void *, const void *, int, size_t); -void *memset (void *, int, size_t); -int memcmp (const void *, const void *, size_t); -void *memchr (const void *, int, size_t); - -char *strcpy (char *, const char *); -char *strncpy (char *, const char *, size_t); - -char *strcat (char *, const char *); -char *strncat (char *, const char *, size_t); - -int strcmp (const char *, const char *); -int strncmp (const char *, const char *, size_t); - -int strcoll (const char *, const char *); -size_t strxfrm (char *, const char *, size_t); - -char *strchr (const char *, int); -char *strrchr (const char *, int); - -size_t strcspn (const char *, const char *); -size_t strspn (const char *, const char *); -char *strpbrk (const char *, const char *); -char *strstr (const char *, const char *); -char *strtok (char *, const char *); - -size_t strlen (const char *); - -char *strerror (int); - - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) -char *strtok_r (char *, const char *, char **); -int strerror_r (int, char *, size_t); -char *stpcpy(char *, const char *); -char *stpncpy(char *, const char *, size_t); -size_t strnlen (const char *, size_t); -char *strdup (const char *); -char *strndup (const char *, size_t); -#endif - -#ifdef _BSD_SOURCE -size_t strlcat (char *, const char *, size_t); -size_t strlcpy (char *, const char *, size_t); -#endif - -#ifdef _GNU_SOURCE -int strcasecmp (const char *, const char *); -int strncasecmp (const char *, const char *, size_t); -char *strchrnul(const char *, int); -char *strcasestr(const char *, const char *); -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/05/musl-final/include/strings.h b/05/musl-final/include/strings.h deleted file mode 100644 index aa35668..0000000 --- a/05/musl-final/include/strings.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef _STRINGS_H -#define _STRINGS_H - -#ifdef __cplusplus -extern "C" { -#endif - - -#define __NEED_size_t -#include - - -int bcmp (const void *, const void *, size_t); -void bcopy (const void *, void *, size_t); -void bzero (void *, size_t); - -int ffs (int); - -char *index (const char *, int); -char *rindex (const char *, int); - -int strcasecmp (const char *, const char *); -int strncasecmp (const char *, const char *, size_t); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/05/musl-final/include/stropts.h b/05/musl-final/include/stropts.h deleted file mode 100644 index 80776ba..0000000 --- a/05/musl-final/include/stropts.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef _STROPTS_H -#define _STROPTS_H - -#ifdef __cplusplus -extern "C" { -#endif - -// FIXME - -int ioctl (int, int, ...); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/05/musl-final/include/sys/epoll.h b/05/musl-final/include/sys/epoll.h deleted file mode 100644 index 3530a9a..0000000 --- a/05/musl-final/include/sys/epoll.h +++ /dev/null @@ -1,61 +0,0 @@ -#ifndef _SYS_EPOLL_H -#define _SYS_EPOLL_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -#define __NEED_sigset_t - -#include - -#define EPOLL_CLOEXEC 02000000 -#define EPOLL_NONBLOCK 04000 - -enum EPOLL_EVENTS { __EPOLL_DUMMY }; -#define EPOLLIN 0x001 -#define EPOLLPRI 0x002 -#define EPOLLOUT 0x004 -#define EPOLLRDNORM 0x040 -#define EPOLLRDBAND 0x080 -#define EPOLLWRNORM 0x100 -#define EPOLLWRBAND 0x200 -#define EPOLLMSG 0x400 -#define EPOLLERR 0x008 -#define EPOLLHUP 0x010 -#define EPOLLRDHUP 0x2000 -#define EPOLLONESHOT (1U<<30) -#define EPOLLET (1U<<31) - -#define EPOLL_CTL_ADD 1 -#define EPOLL_CTL_DEL 2 -#define EPOLL_CTL_MOD 3 - -typedef union epoll_data { - void *ptr; - int fd; - uint32_t u32; - uint64_t u64; -} epoll_data_t; - -struct epoll_event { - uint32_t events; - epoll_data_t data; -} __attribute__ ((__packed__)); - - -int epoll_create(int); -int epoll_create1(int); -int epoll_ctl(int, int, int, struct epoll_event *); -int epoll_wait(int, struct epoll_event *, int, int); -int epoll_pwait(int, struct epoll_event *, int, int, const sigset_t *); - - -#ifdef __cplusplus -} -#endif - -#endif /* sys/epoll.h */ diff --git a/05/musl-final/include/sys/file.h b/05/musl-final/include/sys/file.h deleted file mode 100644 index 8b2eb01..0000000 --- a/05/musl-final/include/sys/file.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef _SYS_FILE_H -#define _SYS_FILE_H -#ifdef __cplusplus -extern "C" { -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) - -#define LOCK_SH 1 -#define LOCK_EX 2 -#define LOCK_NB 4 -#define LOCK_UN 8 - -extern int flock(int, int); - -#endif - -#ifdef __cplusplus -} -#endif -#endif diff --git a/05/musl-final/include/sys/ioctl.h b/05/musl-final/include/sys/ioctl.h deleted file mode 100644 index d0415b3..0000000 --- a/05/musl-final/include/sys/ioctl.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef _SYS_IOCTL_H -#define _SYS_IOCTL_H -#ifdef __cplusplus -extern "C" { -#endif - -#include - -int ioctl (int, int, ...); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/05/musl-final/include/sys/ipc.h b/05/musl-final/include/sys/ipc.h deleted file mode 100644 index 9de9f3e..0000000 --- a/05/musl-final/include/sys/ipc.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef _SYS_IPC_H -#define _SYS_IPC_H -#ifdef __cplusplus -extern "C" { -#endif - -#define __NEED_uid_t -#define __NEED_gid_t -#define __NEED_mode_t -#define __NEED_key_t - -#include - -#include - -key_t ftok (const char *, int); - -#ifdef __cplusplus -} -#endif -#endif - - diff --git a/05/musl-final/include/sys/kd.h b/05/musl-final/include/sys/kd.h deleted file mode 100644 index 793fd59..0000000 --- a/05/musl-final/include/sys/kd.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef _SYS_KD_H -#define _SYS_KD_H - -#define _LINUX_TYPES_H -#include -#undef _LINUX_TYPES_H - -#endif diff --git a/05/musl-final/include/sys/klog.h b/05/musl-final/include/sys/klog.h deleted file mode 100644 index aa66684..0000000 --- a/05/musl-final/include/sys/klog.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef _SYS_KLOG_H -#define _SYS_KLOG_H - -#ifdef __cplusplus -extern "C" { -#endif - -int klogctl (int, char *, int); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/05/musl-final/include/sys/mman.h b/05/musl-final/include/sys/mman.h deleted file mode 100644 index 6aede8b..0000000 --- a/05/musl-final/include/sys/mman.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef _SYS_MMAN_H -#define _SYS_MMAN_H -#ifdef __cplusplus -extern "C" { -#endif - -#define __NEED_mode_t -#define __NEED_size_t -#define __NEED_off_t - -#include - -#include - -void *mmap (void *, size_t, int, int, int, off_t); -int munmap (void *, size_t); - -int mprotect (void *, size_t, int); -int msync (void *, size_t, int); - -int posix_madvise (void *, size_t, int); - -int mlock (const void *, size_t); -int munlock (const void *, size_t); -int mlockall (int); -int munlockall (void); - -/* linux extension */ -void *mremap (void *, size_t, size_t, int, ...); - -int shm_open (const char *, int, mode_t); -int shm_unlink (const char *); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/05/musl-final/include/sys/mount.h b/05/musl-final/include/sys/mount.h deleted file mode 100644 index 2c685f6..0000000 --- a/05/musl-final/include/sys/mount.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef _SYS_MOUNT_H -#define _SYS_MOUNT_H - -#define MS_RDONLY 1 -#define MS_NOSUID 2 -#define MS_NODEV 4 -#define MS_NOEXEC 8 -#define MS_SYNCHRONOUS 16 -#define MS_REMOUNT 32 -#define MS_MANDLOCK 64 -#define S_WRITE 128 -#define S_APPEND 256 -#define S_IMMUTABLE 512 -#define MS_NOATIME 1024 -#define MS_NODIRATIME 2048 -#define MS_BIND 4096 -#define MS_MOVE 8192 -#define MS_SILENT 32768 - -#define MS_MGC_VAL 0xc0ed0000 - -#define MNT_FORCE 1 - -int mount(const char *, const char *, const char *, unsigned long, const void *); -int umount(const char *); -int umount2(const char *, int); - -#endif diff --git a/05/musl-final/include/sys/msg.h b/05/musl-final/include/sys/msg.h deleted file mode 100644 index 9fc42bc..0000000 --- a/05/musl-final/include/sys/msg.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef _SYS_MSG_H -#define _SYS_MSG_H - -#include - -#define __NEED_pid_t -#define __NEED_key_t -#define __NEED_time_t -#define __NEED_size_t -#define __NEED_ssize_t - -#include - -typedef unsigned long msgqnum_t; -typedef unsigned long msglen_t; - -struct msqid_ds -{ - struct ipc_perm msg_perm; - time_t msg_stime; - time_t msg_rtime; - time_t msg_ctime; - msgqnum_t msg_qnum; - msglen_t msg_qbytes; - pid_t msg_lspid; - pid_t msd_lrpid; -}; - -#define MSG_NOERROR 010000 - -int msgctl (int, int, struct msqid_ds *); -int msgget (key_t, int); -int msgrcv (int, void *, size_t, long, int); -int msgsnd (int, const void *, size_t, int); - -#endif diff --git a/05/musl-final/include/sys/mtio.h b/05/musl-final/include/sys/mtio.h deleted file mode 100644 index b77b7e7..0000000 --- a/05/musl-final/include/sys/mtio.h +++ /dev/null @@ -1,276 +0,0 @@ -/* Structures and definitions for magnetic tape I/O control commands. - Copyright (C) 1996-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -/* Written by H. Bergman . */ - -#ifndef _SYS_MTIO_H -#define _SYS_MTIO_H 1 - -/* Get necessary definitions from system and kernel headers. */ -#include -#include - - -/* Structure for MTIOCTOP - magnetic tape operation command. */ -struct mtop - { - short int mt_op; /* Operations defined below. */ - int mt_count; /* How many of them. */ - }; -#define _IOT_mtop /* Hurd ioctl type field. */ \ - _IOT (_IOTS (short), 1, _IOTS (int), 1, 0, 0) - -/* Magnetic Tape operations [Not all operations supported by all drivers]. */ -#define MTRESET 0 /* +reset drive in case of problems. */ -#define MTFSF 1 /* Forward space over FileMark, - * position at first record of next file. */ -#define MTBSF 2 /* Backward space FileMark (position before FM). */ -#define MTFSR 3 /* Forward space record. */ -#define MTBSR 4 /* Backward space record. */ -#define MTWEOF 5 /* Write an end-of-file record (mark). */ -#define MTREW 6 /* Rewind. */ -#define MTOFFL 7 /* Rewind and put the drive offline (eject?). */ -#define MTNOP 8 /* No op, set status only (read with MTIOCGET). */ -#define MTRETEN 9 /* Retension tape. */ -#define MTBSFM 10 /* +backward space FileMark, position at FM. */ -#define MTFSFM 11 /* +forward space FileMark, position at FM. */ -#define MTEOM 12 /* Goto end of recorded media (for appending files). - MTEOM positions after the last FM, ready for - appending another file. */ -#define MTERASE 13 /* Erase tape -- be careful! */ - -#define MTRAS1 14 /* Run self test 1 (nondestructive). */ -#define MTRAS2 15 /* Run self test 2 (destructive). */ -#define MTRAS3 16 /* Reserved for self test 3. */ - -#define MTSETBLK 20 /* Set block length (SCSI). */ -#define MTSETDENSITY 21 /* Set tape density (SCSI). */ -#define MTSEEK 22 /* Seek to block (Tandberg, etc.). */ -#define MTTELL 23 /* Tell block (Tandberg, etc.). */ -#define MTSETDRVBUFFER 24 /* Set the drive buffering according to SCSI-2. - Ordinary buffered operation with code 1. */ -#define MTFSS 25 /* Space forward over setmarks. */ -#define MTBSS 26 /* Space backward over setmarks. */ -#define MTWSM 27 /* Write setmarks. */ - -#define MTLOCK 28 /* Lock the drive door. */ -#define MTUNLOCK 29 /* Unlock the drive door. */ -#define MTLOAD 30 /* Execute the SCSI load command. */ -#define MTUNLOAD 31 /* Execute the SCSI unload command. */ -#define MTCOMPRESSION 32/* Control compression with SCSI mode page 15. */ -#define MTSETPART 33 /* Change the active tape partition. */ -#define MTMKPART 34 /* Format the tape with one or two partitions. */ - -/* structure for MTIOCGET - mag tape get status command */ - -struct mtget - { - long int mt_type; /* Type of magtape device. */ - long int mt_resid; /* Residual count: (not sure) - number of bytes ignored, or - number of files not skipped, or - number of records not skipped. */ - /* The following registers are device dependent. */ - long int mt_dsreg; /* Status register. */ - long int mt_gstat; /* Generic (device independent) status. */ - long int mt_erreg; /* Error register. */ - /* The next two fields are not always used. */ - int mt_fileno; /* Number of current file on tape. */ - int mt_blkno; /* Current block number. */ - }; -#define _IOT_mtget /* Hurd ioctl type field. */ \ - _IOT (_IOTS (long), 7, 0, 0, 0, 0) - - -/* Constants for mt_type. Not all of these are supported, and - these are not all of the ones that are supported. */ -#define MT_ISUNKNOWN 0x01 -#define MT_ISQIC02 0x02 /* Generic QIC-02 tape streamer. */ -#define MT_ISWT5150 0x03 /* Wangtek 5150EQ, QIC-150, QIC-02. */ -#define MT_ISARCHIVE_5945L2 0x04 /* Archive 5945L-2, QIC-24, QIC-02?. */ -#define MT_ISCMSJ500 0x05 /* CMS Jumbo 500 (QIC-02?). */ -#define MT_ISTDC3610 0x06 /* Tandberg 6310, QIC-24. */ -#define MT_ISARCHIVE_VP60I 0x07 /* Archive VP60i, QIC-02. */ -#define MT_ISARCHIVE_2150L 0x08 /* Archive Viper 2150L. */ -#define MT_ISARCHIVE_2060L 0x09 /* Archive Viper 2060L. */ -#define MT_ISARCHIVESC499 0x0A /* Archive SC-499 QIC-36 controller. */ -#define MT_ISQIC02_ALL_FEATURES 0x0F /* Generic QIC-02 with all features. */ -#define MT_ISWT5099EEN24 0x11 /* Wangtek 5099-een24, 60MB, QIC-24. */ -#define MT_ISTEAC_MT2ST 0x12 /* Teac MT-2ST 155mb drive, - Teac DC-1 card (Wangtek type). */ -#define MT_ISEVEREX_FT40A 0x32 /* Everex FT40A (QIC-40). */ -#define MT_ISDDS1 0x51 /* DDS device without partitions. */ -#define MT_ISDDS2 0x52 /* DDS device with partitions. */ -#define MT_ISSCSI1 0x71 /* Generic ANSI SCSI-1 tape unit. */ -#define MT_ISSCSI2 0x72 /* Generic ANSI SCSI-2 tape unit. */ - -/* QIC-40/80/3010/3020 ftape supported drives. - 20bit vendor ID + 0x800000 (see vendors.h in ftape distribution). */ -#define MT_ISFTAPE_UNKNOWN 0x800000 /* obsolete */ -#define MT_ISFTAPE_FLAG 0x800000 - -struct mt_tape_info - { - long int t_type; /* Device type id (mt_type). */ - char *t_name; /* Descriptive name. */ - }; - -#define MT_TAPE_INFO \ - { \ - {MT_ISUNKNOWN, "Unknown type of tape device"}, \ - {MT_ISQIC02, "Generic QIC-02 tape streamer"}, \ - {MT_ISWT5150, "Wangtek 5150, QIC-150"}, \ - {MT_ISARCHIVE_5945L2, "Archive 5945L-2"}, \ - {MT_ISCMSJ500, "CMS Jumbo 500"}, \ - {MT_ISTDC3610, "Tandberg TDC 3610, QIC-24"}, \ - {MT_ISARCHIVE_VP60I, "Archive VP60i, QIC-02"}, \ - {MT_ISARCHIVE_2150L, "Archive Viper 2150L"}, \ - {MT_ISARCHIVE_2060L, "Archive Viper 2060L"}, \ - {MT_ISARCHIVESC499, "Archive SC-499 QIC-36 controller"}, \ - {MT_ISQIC02_ALL_FEATURES, "Generic QIC-02 tape, all features"}, \ - {MT_ISWT5099EEN24, "Wangtek 5099-een24, 60MB"}, \ - {MT_ISTEAC_MT2ST, "Teac MT-2ST 155mb data cassette drive"}, \ - {MT_ISEVEREX_FT40A, "Everex FT40A, QIC-40"}, \ - {MT_ISSCSI1, "Generic SCSI-1 tape"}, \ - {MT_ISSCSI2, "Generic SCSI-2 tape"}, \ - {0, NULL} \ - } - - -/* Structure for MTIOCPOS - mag tape get position command. */ - -struct mtpos - { - long int mt_blkno; /* Current block number. */ - }; -#define _IOT_mtpos /* Hurd ioctl type field. */ \ - _IOT_SIMPLE (long) - - -/* Structure for MTIOCGETCONFIG/MTIOCSETCONFIG primarily intended - as an interim solution for QIC-02 until DDI is fully implemented. */ -struct mtconfiginfo - { - long int mt_type; /* Drive type. */ - long int ifc_type; /* Interface card type. */ - unsigned short int irqnr; /* IRQ number to use. */ - unsigned short int dmanr; /* DMA channel to use. */ - unsigned short int port; /* IO port base address. */ - - unsigned long int debug; /* Debugging flags. */ - - unsigned have_dens:1; - unsigned have_bsf:1; - unsigned have_fsr:1; - unsigned have_bsr:1; - unsigned have_eod:1; - unsigned have_seek:1; - unsigned have_tell:1; - unsigned have_ras1:1; - unsigned have_ras2:1; - unsigned have_ras3:1; - unsigned have_qfa:1; - - unsigned pad1:5; - char reserved[10]; - }; -#define _IOT_mtconfiginfo /* Hurd ioctl type field. */ \ - _IOT (_IOTS (long), 2, _IOTS (short), 3, _IOTS (long), 1) /* XXX wrong */ - - -/* Magnetic tape I/O control commands. */ -#define MTIOCTOP _IOW('m', 1, struct mtop) /* Do a mag tape op. */ -#define MTIOCGET _IOR('m', 2, struct mtget) /* Get tape status. */ -#define MTIOCPOS _IOR('m', 3, struct mtpos) /* Get tape position.*/ - -/* The next two are used by the QIC-02 driver for runtime reconfiguration. - See tpqic02.h for struct mtconfiginfo. */ -#define MTIOCGETCONFIG _IOR('m', 4, struct mtconfiginfo) /* Get tape config.*/ -#define MTIOCSETCONFIG _IOW('m', 5, struct mtconfiginfo) /* Set tape config.*/ - -/* Generic Mag Tape (device independent) status macros for examining - mt_gstat -- HP-UX compatible. - There is room for more generic status bits here, but I don't - know which of them are reserved. At least three or so should - be added to make this really useful. */ -#define GMT_EOF(x) ((x) & 0x80000000) -#define GMT_BOT(x) ((x) & 0x40000000) -#define GMT_EOT(x) ((x) & 0x20000000) -#define GMT_SM(x) ((x) & 0x10000000) /* DDS setmark */ -#define GMT_EOD(x) ((x) & 0x08000000) /* DDS EOD */ -#define GMT_WR_PROT(x) ((x) & 0x04000000) -/* #define GMT_ ? ((x) & 0x02000000) */ -#define GMT_ONLINE(x) ((x) & 0x01000000) -#define GMT_D_6250(x) ((x) & 0x00800000) -#define GMT_D_1600(x) ((x) & 0x00400000) -#define GMT_D_800(x) ((x) & 0x00200000) -/* #define GMT_ ? ((x) & 0x00100000) */ -/* #define GMT_ ? ((x) & 0x00080000) */ -#define GMT_DR_OPEN(x) ((x) & 0x00040000) /* Door open (no tape). */ -/* #define GMT_ ? ((x) & 0x00020000) */ -#define GMT_IM_REP_EN(x) ((x) & 0x00010000) /* Immediate report mode.*/ -/* 16 generic status bits unused. */ - - -/* SCSI-tape specific definitions. Bitfield shifts in the status */ -#define MT_ST_BLKSIZE_SHIFT 0 -#define MT_ST_BLKSIZE_MASK 0xffffff -#define MT_ST_DENSITY_SHIFT 24 -#define MT_ST_DENSITY_MASK 0xff000000 - -#define MT_ST_SOFTERR_SHIFT 0 -#define MT_ST_SOFTERR_MASK 0xffff - -/* Bitfields for the MTSETDRVBUFFER ioctl. */ -#define MT_ST_OPTIONS 0xf0000000 -#define MT_ST_BOOLEANS 0x10000000 -#define MT_ST_SETBOOLEANS 0x30000000 -#define MT_ST_CLEARBOOLEANS 0x40000000 -#define MT_ST_WRITE_THRESHOLD 0x20000000 -#define MT_ST_DEF_BLKSIZE 0x50000000 -#define MT_ST_DEF_OPTIONS 0x60000000 - -#define MT_ST_BUFFER_WRITES 0x1 -#define MT_ST_ASYNC_WRITES 0x2 -#define MT_ST_READ_AHEAD 0x4 -#define MT_ST_DEBUGGING 0x8 -#define MT_ST_TWO_FM 0x10 -#define MT_ST_FAST_MTEOM 0x20 -#define MT_ST_AUTO_LOCK 0x40 -#define MT_ST_DEF_WRITES 0x80 -#define MT_ST_CAN_BSR 0x100 -#define MT_ST_NO_BLKLIMS 0x200 -#define MT_ST_CAN_PARTITIONS 0x400 -#define MT_ST_SCSI2LOGICAL 0x800 - -/* The mode parameters to be controlled. Parameter chosen with bits 20-28. */ -#define MT_ST_CLEAR_DEFAULT 0xfffff -#define MT_ST_DEF_DENSITY (MT_ST_DEF_OPTIONS | 0x100000) -#define MT_ST_DEF_COMPRESSION (MT_ST_DEF_OPTIONS | 0x200000) -#define MT_ST_DEF_DRVBUFFER (MT_ST_DEF_OPTIONS | 0x300000) - -/* The offset for the arguments for the special HP changer load command. */ -#define MT_ST_HPLOADER_OFFSET 10000 - - -/* Specify default tape device. */ -#ifndef DEFTAPE -# define DEFTAPE "/dev/tape" -#endif - -#endif /* mtio.h */ diff --git a/05/musl-final/include/sys/param.h b/05/musl-final/include/sys/param.h deleted file mode 100644 index ded4a16..0000000 --- a/05/musl-final/include/sys/param.h +++ /dev/null @@ -1,15 +0,0 @@ -#undef MAXSYMLINKS -#define MAXSYMLINKS 20 - -#undef MAXHOSTNAMELEN -#define MAXHOSTNAMELEN 64 - -#undef MAXNAMLEN -#define MAXNAMLEN NAME_MAX - -#undef MAXPATHLEN -#define MAXPATHLEN PATH_MAX - -#include -#include -#include diff --git a/05/musl-final/include/sys/poll.h b/05/musl-final/include/sys/poll.h deleted file mode 100644 index 779ec77..0000000 --- a/05/musl-final/include/sys/poll.h +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/05/musl-final/include/sys/prctl.h b/05/musl-final/include/sys/prctl.h deleted file mode 100644 index cd34848..0000000 --- a/05/musl-final/include/sys/prctl.h +++ /dev/null @@ -1,64 +0,0 @@ -#ifndef _SYS_PRCTL_H -#define _SYS_PRCTL_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define PR_SET_PDEATHSIG 1 -#define PR_GET_PDEATHSIG 2 -#define PR_GET_DUMPABLE 3 -#define PR_SET_DUMPABLE 4 -#define PR_GET_UNALIGN 5 -#define PR_SET_UNALIGN 6 -#define PR_UNALIGN_NOPRINT 1 -#define PR_UNALIGN_SIGBUS 2 -#define PR_GET_KEEPCAPS 7 -#define PR_SET_KEEPCAPS 8 -#define PR_GET_FPEMU 9 -#define PR_SET_FPEMU 10 -#define PR_FPEMU_NOPRINT 1 -#define PR_FPEMU_SIGFPE 2 -#define PR_GET_FPEXC 11 -#define PR_SET_FPEXC 12 -#define PR_FP_EXC_SW_ENABLE 0x80 -#define PR_FP_EXC_DIV 0x010000 -#define PR_FP_EXC_OVF 0x020000 -#define PR_FP_EXC_UND 0x040000 -#define PR_FP_EXC_RES 0x080000 -#define PR_FP_EXC_INV 0x100000 -#define PR_FP_EXC_DISABLED 0 -#define PR_FP_EXC_NONRECOV 1 -#define PR_FP_EXC_ASYNC 2 -#define PR_FP_EXC_PRECISE 3 -#define PR_GET_TIMING 13 -#define PR_SET_TIMING 14 -#define PR_TIMING_STATISTICAL 0 -#define PR_TIMING_TIMESTAMP 1 -#define PR_SET_NAME 15 -#define PR_GET_NAME 16 -#define PR_GET_ENDIAN 19 -#define PR_SET_ENDIAN 20 -#define PR_ENDIAN_BIG -#define PR_ENDIAN_LITTLE -#define PR_ENDIAN_PPC_LITTLE -#define PR_GET_SECCOMP 21 -#define PR_SET_SECCOMP 22 -#define PR_CAPBSET_READ 23 -#define PR_CAPBSET_DROP 24 -#define PR_GET_TSC 25 -#define PR_SET_TSC 26 -#define PR_TSC_ENABLE 1 -#define PR_TSC_SIGSEGV 2 -#define PR_GET_SECUREBITS 27 -#define PR_SET_SECUREBITS 28 -#define PR_SET_TIMERSLACK 29 -#define PR_GET_TIMERSLACK 30 - -int prctl (int, ...); - -#ifdef __cplusplus -extern "C" { -#endif - -#endif diff --git a/05/musl-final/include/sys/procfs.h b/05/musl-final/include/sys/procfs.h deleted file mode 100644 index 20b4847..0000000 --- a/05/musl-final/include/sys/procfs.h +++ /dev/null @@ -1,81 +0,0 @@ -#ifndef _SYS_PROCFS_H -#define _SYS_PROCFS_H -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include - -typedef unsigned long elf_greg_t; -#define ELF_NGREG (sizeof (struct user_regs_struct) / sizeof(elf_greg_t)) -typedef elf_greg_t elf_gregset_t[ELF_NGREG]; - -#if __WORDSIZE == 32 -typedef struct user_fpregs_struct elf_fpregset_t; -typedef struct user_fpxregs_struct elf_fpxregset_t; -#else -typedef struct user_fpregs_struct elf_fpregset_t; -#endif - -struct elf_siginfo { - int si_signo; - int si_code; - int si_errno; -}; - -struct elf_prstatus { - struct elf_siginfo pr_info; - short int pr_cursig; - unsigned long int pr_sigpend; - unsigned long int pr_sighold; - pid_t pr_pid; - pid_t pr_ppid; - pid_t pr_pgrp; - pid_t pr_sid; - struct timeval pr_utime; - struct timeval pr_stime; - struct timeval pr_cutime; - struct timeval pr_cstime; - elf_gregset_t pr_reg; - int pr_fpvalid; -}; - - -#define ELF_PRARGSZ 80 - -struct elf_prpsinfo - { - char pr_state; - char pr_sname; - char pr_zomb; - char pr_nice; - unsigned long int pr_flag; -#if __WORDSIZE == 32 - unsigned short int pr_uid; - unsigned short int pr_gid; -#else - unsigned int pr_uid; - unsigned int pr_gid; -#endif - int pr_pid, pr_ppid, pr_pgrp, pr_sid; - char pr_fname[16]; - char pr_psargs[ELF_PRARGSZ]; -}; - - -typedef void *psaddr_t; -typedef elf_gregset_t prgregset_t; -typedef elf_fpregset_t prfpregset_t; -typedef pid_t lwpid_t; -typedef struct elf_prstatus prstatus_t; -typedef struct elf_prpsinfo prpsinfo_t; - - - - -#ifdef __cplusplus -} -#endif -#endif diff --git a/05/musl-final/include/sys/ptrace.h b/05/musl-final/include/sys/ptrace.h deleted file mode 100644 index 0459d1b..0000000 --- a/05/musl-final/include/sys/ptrace.h +++ /dev/null @@ -1,77 +0,0 @@ -#ifndef _SYS_PTRACE_H -#define _SYS_PTRACE_H -#ifdef __cplusplus -extern "C" { -#endif - -#define PTRACE_TRACEME 0 -#define PT_TRACE_ME PTRACE_TRACEME - -#define PTRACE_PEEKTEXT 1 -#define PTRACE_PEEKDATA 2 -#define PTRACE_PEEKUSER 3 -#define PTRACE_POKETEXT 4 -#define PTRACE_POKEDATA 5 -#define PTRACE_POKEUSER 6 -#define PTRACE_CONT 7 -#define PTRACE_KILL 8 -#define PTRACE_SINGLESTEP 9 -#define PTRACE_GETREGS 12 -#define PTRACE_SETREGS 13 -#define PTRACE_GETFPREGS 14 -#define PTRACE_SETFPREGS 15 -#define PTRACE_ATTACH 16 -#define PTRACE_DETACH 17 -#define PTRACE_GETFPXREGS 18 -#define PTRACE_SETFPXREGS 19 -#define PTRACE_SYSCALL 24 -#define PTRACE_SETOPTIONS 0x4200 -#define PTRACE_GETEVENTMSG 0x4201 -#define PTRACE_GETSIGINFO 0x4202 -#define PTRACE_SETSIGINFO 0x4203 - -#define PT_READ_I PTRACE_PEEKTEXT -#define PT_READ_D PTRACE_PEEKDATA -#define PT_READ_U PTRACE_PEEKUSER -#define PT_WRITE_I PTRACE_POKETEXT -#define PT_WRITE_D PTRACE_POKEDATA -#define PT_WRITE_U PTRACE_POKEUSER -#define PT_CONTINUE PTRACE_CONT -#define PT_KILL PTRACE_KILL -#define PT_STEP PTRACE_SINGLESTEP -#define PT_GETREGS PTRACE_GETREGS -#define PT_SETREGS PTRACE_SETREGS -#define PT_GETFPREGS PTRACE_GETFPREGS -#define PT_SETFPREGS PTRACE_SETFPREGS -#define PT_ATTACH PTRACE_ATTACH -#define PT_DETACH PTRACE_DETACH -#define PT_GETFPXREGS PTRACE_GETFPXREGS -#define PT_SETFPXREGS PTRACE_SETFPXREGS -#define PT_SYSCALL PTRACE_SYSCALL -#define PT_SETOPTIONS PTRACE_SETOPTIONS -#define PT_GETEVENTMSG PTRACE_GETEVENTMSG -#define PT_GETSIGINFO PTRACE_GETSIGINFO -#define PT_SETSIGINFO PTRACE_SETSIGINFO - -#define PTRACE_O_TRACESYSGOOD 0x00000001 -#define PTRACE_O_TRACEFORK 0x00000002 -#define PTRACE_O_TRACEVFORK 0x00000004 -#define PTRACE_O_TRACECLONE 0x00000008 -#define PTRACE_O_TRACEEXEC 0x00000010 -#define PTRACE_O_TRACEVFORKDONE 0x00000020 -#define PTRACE_O_TRACEEXIT 0x00000040 -#define PTRACE_O_MASK 0x0000007f - -#define PTRACE_EVENT_FORK 1 -#define PTRACE_EVENT_VFORK 2 -#define PTRACE_EVENT_CLONE 3 -#define PTRACE_EVENT_EXEC 4 -#define PTRACE_EVENT_VFORK_DONE 5 -#define PTRACE_EVENT_EXIT 6 - -long int ptrace(int, ...); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/05/musl-final/include/sys/reboot.h b/05/musl-final/include/sys/reboot.h deleted file mode 100644 index 26cc308..0000000 --- a/05/musl-final/include/sys/reboot.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef _SYS_REBOOT_H -#define _SYS_REBOOT_H -#ifdef __cplusplus -extern "C" { -#endif - -#define RB_AUTOBOOT 0x01234567 -#define RB_HALT_SYSTEM 0xcdef0123 -#define RB_ENABLE_CAD 0x89abcdef -#define RB_DISABLE_CAD 0 -#define RB_POWER_OFF 0x4321fedc - -int reboot(int); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/05/musl-final/include/sys/reg.h b/05/musl-final/include/sys/reg.h deleted file mode 100644 index ebf3fff..0000000 --- a/05/musl-final/include/sys/reg.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef _SYS_USER_H -#define _SYS_USER_H - -#include -#include - -#include - -#endif diff --git a/05/musl-final/include/sys/resource.h b/05/musl-final/include/sys/resource.h deleted file mode 100644 index 99e383c..0000000 --- a/05/musl-final/include/sys/resource.h +++ /dev/null @@ -1,74 +0,0 @@ -#ifndef _SYS_RESOURCE_H -#define _SYS_RESOURCE_H - -#define __NEED_id_t -#define __NEED_time_t -#define __NEED_struct_timeval -#define __NEED_struct_rusage - -#include - -typedef unsigned long long rlim_t; - -struct rlimit -{ - rlim_t rlim_cur; - rlim_t rlim_max; -}; - -struct rusage -{ - struct timeval ru_utime; - struct timeval ru_stime; - /* linux extentions, but useful */ - long ru_maxrss; - long ru_ixrss; - long ru_idrss; - long ru_isrss; - long ru_minflt; - long ru_majflt; - long ru_nswap; - long ru_inblock; - long ru_oublock; - long ru_msgsnd; - long ru_msgrcv; - long ru_nsignals; - long ru_nvcsw; - long ru_nivcsw; - /* room for more... */ - long __reserved[16]; -}; - -int getrlimit (int, struct rlimit *); -int setrlimit (int, const struct rlimit *); -int getrusage (int, struct rusage *); - -int getpriority (int, id_t); -int setpriority (int, id_t, int); - -#define PRIO_PROCESS 0 -#define PRIO_PGRP 1 -#define PRIO_USER 2 - -#define RUSAGE_SELF 0 -#define RUSAGE_CHILDREN 1 - -#define RLIM_INFINITY (~0ULL) -#define RLIM_SAVED_CUR RLIM_INFINITY -#define RLIM_SAVED_MAX RLIM_INFINITY - -#define RLIMIT_CPU 0 -#define RLIMIT_FSIZE 1 -#define RLIMIT_DATA 2 -#define RLIMIT_STACK 3 -#define RLIMIT_CORE 4 -#define RLIMIT_RSS 5 -#define RLIMIT_NOFILE 7 -#define RLIMIT_AS 9 -#define RLIMIT_NPROC 6 -#define RLIMIT_MEMLOCK 8 -#define RLIMIT_LOCKS 10 - - - -#endif diff --git a/05/musl-final/include/sys/select.h b/05/musl-final/include/sys/select.h deleted file mode 100644 index c44eada..0000000 --- a/05/musl-final/include/sys/select.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef _SYS_SELECT_H -#define _SYS_SELECT_H -#ifdef __cplusplus -extern "C" { -#endif - -#define __NEED_size_t -#define __NEED_time_t -#define __NEED_struct_timeval -#define __NEED_struct_timespec -#define __NEED_sigset_t - -#include - -#define FD_SETSIZE 1024 - -typedef struct -{ - unsigned long fds_bits[FD_SETSIZE / 8 / sizeof(long)]; -} fd_set; - -#define FD_ZERO(s) do { int __i; unsigned long *__b=(s)->fds_bits; for(__i=sizeof (fd_set)/sizeof (long); __i; __i--) *__b++=0; } while(0) -#define FD_SET(d, s) ((s)->fds_bits[(d)/(8*sizeof(long))] |= (1<<((d)%(8*sizeof(long))))) -#define FD_CLR(d, s) ((s)->fds_bits[(d)/(8*sizeof(long))] &= ~(1<<((d)%(8*sizeof(long))))) -#define FD_ISSET(d, s) ((s)->fds_bits[(d)/(8*sizeof(long))] & (1<<((d)%(8*sizeof(long))))) - -int select (int, fd_set *, fd_set *, fd_set *, struct timeval *); -int pselect (int, fd_set *, fd_set *, fd_set *, const struct timespec *, const sigset_t *); - - -#ifdef __cplusplus -} -#endif -#endif diff --git a/05/musl-final/include/sys/sem.h b/05/musl-final/include/sys/sem.h deleted file mode 100644 index 15d8b68..0000000 --- a/05/musl-final/include/sys/sem.h +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef _SYS_SEM_H -#define _SYS_SEM_H -#ifdef __cplusplus -extern "C" { -#endif - -#define __NEED_size_t -#include - -#include - -#define SEM_UNDO 0x1000 -#define GETPID 11 -#define GETVAL 12 -#define GETALL 13 -#define GETNCNT 14 -#define GETZCNT 15 -#define SETVAL 16 -#define SETALL 17 - -struct semid_ds { - struct ipc_perm sem_perm; - long sem_otime; - unsigned long __unused1; - long sem_ctime; - unsigned long __unused2; - unsigned long sem_nsems; - unsigned long __unused3; - unsigned long __unused4; -}; - -#define _SEM_SEMUN_UNDEFINED 1 - -#define SEM_STAT 18 -#define SEM_INFO 19 - -struct seminfo { - int semmap; - int semmni; - int semmns; - int semmnu; - int semmsl; - int semopm; - int semume; - int semusz; - int semvmx; - int semaem; -}; - -struct sembuf { - unsigned short sem_num; - short sem_op; - short sem_flg; -}; - -int semctl(int, int, int, ...); -int semget(key_t, int, int); -int semop(int, struct sembuf *, size_t); - -#ifdef _GNU_SOURCE -#define __NEED_struct_timespec -#include -int semtimedop(int, struct sembuf *, size_t, const struct timespec *); -#endif - -#ifdef __cplusplus -} -#endif -#endif diff --git a/05/musl-final/include/sys/shm.h b/05/musl-final/include/sys/shm.h deleted file mode 100644 index 6ebb941..0000000 --- a/05/musl-final/include/sys/shm.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef _SYS_SHM_H -#define _SYS_SHM_H - -#define __NEED_time_t -#define __NEED_size_t -#define __NEED_pid_t - -#include - -#include -#include - -void *shmat(int, const void *, int); -int shmctl(int, int, struct shmid_ds *); -int shmdt(const void *); -int shmget(key_t, size_t, int); - -#endif diff --git a/05/musl-final/include/sys/signalfd.h b/05/musl-final/include/sys/signalfd.h deleted file mode 100644 index 895664b..0000000 --- a/05/musl-final/include/sys/signalfd.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef _SYS_SIGNALFD_H -#define _SYS_SIGNALFD_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_sigset_t - -#include - -int signalfd(int, const sigset_t *, int); - -struct signalfd_siginfo { - uint32_t ssi_signo; - int32_t ssi_errno; - int32_t ssi_code; - uint32_t ssi_pid; - uint32_t ssi_uid; - int32_t ssi_fd; - uint32_t ssi_tid; - uint32_t ssi_band; - uint32_t ssi_overrun; - uint32_t ssi_trapno; - int32_t ssi_status; - int32_t ssi_int; - uintptr_t ssi_ptr; - uint64_t ssi_utime; - uint64_t ssi_stime; - uint64_t ssi_addr; - uint8_t pad[128-12*4-sizeof(void *)-3*8]; -}; - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/05/musl-final/include/sys/socket.h b/05/musl-final/include/sys/socket.h deleted file mode 100644 index 4005eb6..0000000 --- a/05/musl-final/include/sys/socket.h +++ /dev/null @@ -1,65 +0,0 @@ -#ifndef _SYS_SOCKET_H -#define _SYS_SOCKET_H -#ifdef __cplusplus -extern "C" { -#endif - -#define __NEED_socklen_t -#define __NEED_sa_family_t -#define __NEED_size_t -#define __NEED_ssize_t -#define __NEED_uid_t -#define __NEED_pid_t -#define __NEED_gid_t -#define __NEED_struct_iovec - -#include - -#include - -struct sockaddr -{ - sa_family_t sa_family; - char sa_data[14]; -}; - -struct sockaddr_storage -{ - sa_family_t ss_family; - long long __ss_align; - char __ss_padding[128 - sizeof(sa_family_t) - sizeof(long long)]; -}; - -int socket (int, int, int); -int socketpair (int, int, int, int [2]); - -int shutdown (int, int); - -int bind (int, const struct sockaddr *, socklen_t); -int connect (int, const struct sockaddr *, socklen_t); -int listen (int, int); -int accept (int, struct sockaddr *, socklen_t *); - -int getsockname (int, struct sockaddr *, socklen_t *); -int getpeername (int, struct sockaddr *, socklen_t *); - -ssize_t send (int, const void *, size_t, int); -ssize_t recv (int, void *, size_t, int); -ssize_t sendto (int, const void *, size_t, int, const struct sockaddr *, socklen_t); -ssize_t recvfrom (int, void *, size_t, int, struct sockaddr *, socklen_t *); -ssize_t sendmsg (int, const struct msghdr *, int); -ssize_t recvmsg (int, struct msghdr *, int); - -int getsockopt (int, int, int, void *, socklen_t *); -int setsockopt (int, int, int, const void *, socklen_t); - -int sockatmark (int); - -#define SHUT_RD 0 -#define SHUT_WR 1 -#define SHUT_RDWR 2 - -#ifdef __cplusplus -} -#endif -#endif diff --git a/05/musl-final/include/sys/soundcard.h b/05/musl-final/include/sys/soundcard.h deleted file mode 100644 index fade986..0000000 --- a/05/musl-final/include/sys/soundcard.h +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/05/musl-final/include/sys/stat.h b/05/musl-final/include/sys/stat.h deleted file mode 100644 index 627890f..0000000 --- a/05/musl-final/include/sys/stat.h +++ /dev/null @@ -1,95 +0,0 @@ -#ifndef _SYS_STAT_H -#define _SYS_STAT_H -#ifdef __cplusplus -extern "C" { -#endif - -#define __NEED_dev_t -#define __NEED_ino_t -#define __NEED_mode_t -#define __NEED_nlink_t -#define __NEED_uid_t -#define __NEED_gid_t -#define __NEED_off_t -#define __NEED_time_t -#define __NEED_blksize_t -#define __NEED_blkcnt_t -#define __NEED_struct_timespec - -#include - -#include - -#define st_atime st_atim.tv_sec -#define st_mtime st_mtim.tv_sec -#define st_ctime st_ctim.tv_sec - -#define S_IFMT 0170000 - -#define S_IFDIR 0040000 -#define S_IFCHR 0020000 -#define S_IFBLK 0060000 -#define S_IFREG 0100000 -#define S_IFIFO 0010000 -#define S_IFLNK 0120000 -#define S_IFSOCK 0140000 - -#define S_TYPEISMQ(buf) 0 -#define S_TYPEISSEM(buf) 0 -#define S_TYPEISSHM(buf) 0 -#define S_TYPEISTMO(buf) 0 - -#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) -#define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR) -#define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK) -#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) -#define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO) -#define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK) -#define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK) - -#define S_ISUID 04000 -#define S_ISGID 02000 -#define S_ISVTX 01000 - -#define S_IREAD 0400 -#define S_IWRITE 0200 -#define S_IEXEC 0100 - -#define S_IRUSR 0400 -#define S_IWUSR 0200 -#define S_IXUSR 0100 -#define S_IRWXU 0700 - -#define S_IRGRP 0040 -#define S_IWGRP 0020 -#define S_IXGRP 0010 -#define S_IRWXG 0070 - -#define S_IROTH 0004 -#define S_IWOTH 0002 -#define S_IXOTH 0001 -#define S_IRWXO 0007 - - -int stat(const char *, struct stat *); -int fstat(int, struct stat *); -int lstat(const char *, struct stat *); -int fstatat(int, const char *, struct stat *, int); -int chmod(const char *, mode_t); -int fchmod(int, mode_t); -int fchmodat(int, const char *, mode_t, int); -mode_t umask(mode_t); -int mkdir(const char *, mode_t); -int mknod(const char *, mode_t, dev_t); -int mkfifo(const char *, mode_t); -int mkdirat(int, const char *, mode_t); -int mknodat(int, const char *, mode_t, dev_t); -int mkfifoat(int, const char *, mode_t); - - -#ifdef __cplusplus -} -#endif -#endif - - diff --git a/05/musl-final/include/sys/statfs.h b/05/musl-final/include/sys/statfs.h deleted file mode 100644 index 7eaa7e7..0000000 --- a/05/musl-final/include/sys/statfs.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef _SYS_STATFS_H -#define _SYS_STATFS_H - -#include - -#define statfs statvfs -#define fstatfs fstatvfs -#define f_namelen f_namemax - -#endif diff --git a/05/musl-final/include/sys/statvfs.h b/05/musl-final/include/sys/statvfs.h deleted file mode 100644 index 6479be6..0000000 --- a/05/musl-final/include/sys/statvfs.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef _SYS_STATVFS_H -#define _SYS_STATVFS_H - - -#define __NEED_fsblkcnt_t -#define __NEED_fsfilcnt_t -#include - -#include - -int statvfs (const char *, struct statvfs *); -int fstatvfs (int, struct statvfs *); - -#define ST_RDONLY 1 -#define ST_NOSUID 2 - -#if 0 -#define ST_NODEV 4 -#define ST_NOEXEC 8 -#define ST_SYNCHRONOUS 16 -#define ST_MANDLOCK 64 -#define ST_WRITE 128 -#define ST_APPEND 256 -#define ST_IMMUTABLE 512 -#define ST_NOATIME 1024 -#define ST_NODIRATIME 2048 -#endif - - -#endif diff --git a/05/musl-final/include/sys/stropts.h b/05/musl-final/include/sys/stropts.h deleted file mode 100644 index 5b5bc02..0000000 --- a/05/musl-final/include/sys/stropts.h +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/05/musl-final/include/sys/swap.h b/05/musl-final/include/sys/swap.h deleted file mode 100644 index c5824f1..0000000 --- a/05/musl-final/include/sys/swap.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef _SYS_SWAP_H -#define _SYS_SWAP_H - -#define SWAP_FLAG_PREFER 0x8000 -#define SWAP_FLAG_PRIO_MASK 0x7fff -#define SWAP_FLAG_PRIO_SHIFT 0 - -int swapon (const char *, int); -int swapoff (const char *); - -#endif diff --git a/05/musl-final/include/sys/sysctl.h b/05/musl-final/include/sys/sysctl.h deleted file mode 100644 index af5ca8b..0000000 --- a/05/musl-final/include/sys/sysctl.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef _SYS_SYSCTL_H -#define _SYS_SYSCTL_H - -#define __NEED_size_t -#include - -int sysctl (int *, int, void *, size_t *, void *, size_t); - -#endif diff --git a/05/musl-final/include/sys/sysinfo.h b/05/musl-final/include/sys/sysinfo.h deleted file mode 100644 index ca52088..0000000 --- a/05/musl-final/include/sys/sysinfo.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef _SYS_SYSINFO_H -#define _SYS_SYSINFO_H - -/* ?? */ -#define SI_LOAD_SHIFT 16 - -struct sysinfo { - unsigned long long uptime; - unsigned long loads[3]; - unsigned long procs; - unsigned long long totalram; - unsigned long long freeram; - unsigned long long sharedram; - unsigned long long bufferram; - unsigned long long totalswap; - unsigned long long freeswap; - unsigned long long totalhigh; - unsigned long long freehigh; - unsigned long mem_unit; - char __reserved[256]; -}; - -int sysinfo (struct sysinfo *); -int get_nprocs_conf (void); -int get_nprocs (void); -long long get_phys_pages (void); -long long get_avphys_pages (void); - -#endif diff --git a/05/musl-final/include/sys/sysmacros.h b/05/musl-final/include/sys/sysmacros.h deleted file mode 100644 index 79eba3b..0000000 --- a/05/musl-final/include/sys/sysmacros.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef _SYSMACROS_H -#define _SYSMACROS_H - -#include - -#endif diff --git a/05/musl-final/include/sys/time.h b/05/musl-final/include/sys/time.h deleted file mode 100644 index edaf6af..0000000 --- a/05/musl-final/include/sys/time.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef _SYS_TIME_H -#define _SYS_TIME_H -#ifdef __cplusplus -extern "C" { -#endif - -/* All symbols from select.h except pselect are required anyway... */ -#include - -#define __NEED_time_t -#define __NEED_suseconds_t -#define __NEED_struct_timeval - -#include - - - -int gettimeofday (struct timeval *, void *); - -/* extensions */ -int settimeofday (const struct timeval *, void *); -int adjtime (const struct timeval *, struct timeval *); - - -#define ITIMER_REAL 0 -#define ITIMER_VIRTUAL 1 -#define ITIMER_PROF 2 - -struct itimerval -{ - struct timeval it_interval; - struct timeval it_value; -}; - -int getitimer (int, struct itimerval *); -int setitimer (int, const struct itimerval *, struct itimerval *); -int utimes (const char *, const struct timeval [2]); - -#ifdef _GNU_SOURCE -struct timezone { - int tz_minuteswest; - int tz_dsttime; -}; -#endif - -#ifdef __cplusplus -} -#endif -#endif diff --git a/05/musl-final/include/sys/times.h b/05/musl-final/include/sys/times.h deleted file mode 100644 index aca743d..0000000 --- a/05/musl-final/include/sys/times.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef _SYS_TIMES_H -#define _SYS_TIMES_H - -#define __NEED_clock_t -#include - -struct tms -{ - clock_t tms_utime; - clock_t tms_stime; - clock_t tms_cutime; - clock_t tms_cstime; -}; - -clock_t times (struct tms *); - -#endif diff --git a/05/musl-final/include/sys/types.h b/05/musl-final/include/sys/types.h deleted file mode 100644 index 7a126b0..0000000 --- a/05/musl-final/include/sys/types.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef _SYS_TYPES_H -#define _SYS_TYPES_H -#ifdef __cplusplus -extern "C" { -#endif - -#define __NEED_loff_t -#define __NEED_ino_t -#define __NEED_dev_t -#define __NEED_uid_t -#define __NEED_gid_t -#define __NEED_mode_t -#define __NEED_nlink_t -#define __NEED_off_t -#define __NEED_pid_t -#define __NEED_size_t -#define __NEED_ssize_t -#define __NEED_time_t -#define __NEED_timer_t -#define __NEED_clockid_t - -#define __NEED_int8_t -#define __NEED_int16_t -#define __NEED_int32_t -#define __NEED_int64_t - -#define __NEED_u_int8_t -#define __NEED_u_int16_t -#define __NEED_u_int32_t -#define __NEED_u_int64_t - -#define __NEED_register_t - -#define __NEED_blkcnt_t -#define __NEED_fsblkcnt_t -#define __NEED_fsfilcnt_t - -#define __NEED_id_t -#define __NEED_key_t -#define __NEED_clock_t -#define __NEED_useconds_t -#define __NEED_suseconds_t -#define __NEED_blksize_t - -#define __NEED_pthread_t -#define __NEED_pthread_attr_t -#define __NEED_pthread_mutexattr_t -#define __NEED_pthread_condattr_t -#define __NEED_pthread_rwlockattr_t -#define __NEED_pthread_barrierattr_t -#define __NEED_pthread_mutex_t -#define __NEED_pthread_cond_t -#define __NEED_pthread_rwlock_t -#define __NEED_pthread_barrier_t -#define __NEED_pthread_spinlock_t -#define __NEED_pthread_key_t -#define __NEED_pthread_once_t - -#include - -#ifdef _GNU_SOURCE -typedef unsigned long caddr_t; -#endif - -#ifdef __cplusplus -} -#endif -#endif - - diff --git a/05/musl-final/include/sys/ucontext.h b/05/musl-final/include/sys/ucontext.h deleted file mode 100644 index 5fdbd63..0000000 --- a/05/musl-final/include/sys/ucontext.h +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/05/musl-final/include/sys/uio.h b/05/musl-final/include/sys/uio.h deleted file mode 100644 index 11b6bd2..0000000 --- a/05/musl-final/include/sys/uio.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef _SYS_UIO_H -#define _SYS_UIO_H - -#define __NEED_size_t -#define __NEED_ssize_t -#define __NEED_struct_iovec - -#include - -ssize_t readv (int, const struct iovec *, int); -ssize_t writev (int, const struct iovec *, int); - -#endif diff --git a/05/musl-final/include/sys/un.h b/05/musl-final/include/sys/un.h deleted file mode 100644 index 769dac6..0000000 --- a/05/musl-final/include/sys/un.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef _SYS_UN_H -#define _SYS_UN_H - -#define __NEED_sa_family_t -#include - -struct sockaddr_un -{ - sa_family_t sun_family; - char sun_path[108]; -}; - -#endif diff --git a/05/musl-final/include/sys/user.h b/05/musl-final/include/sys/user.h deleted file mode 100644 index 24ac940..0000000 --- a/05/musl-final/include/sys/user.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef _SYS_USER_H -#define _SYS_USER_H -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -#include - -#ifdef __cplusplus -} -#endif -#endif diff --git a/05/musl-final/include/sys/utsname.h b/05/musl-final/include/sys/utsname.h deleted file mode 100644 index 383e825..0000000 --- a/05/musl-final/include/sys/utsname.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef _SYS_UTSNAME_H -#define _SYS_UTSNAME_H - -struct utsname -{ - char sysname[65]; - char nodename[65]; - char release[65]; - char version[65]; - char machine[65]; -#ifdef _GNU_SOURCE - char domainname[65]; -#else - char __domainname[65]; -#endif -}; - -int uname (struct utsname *); - - -#endif diff --git a/05/musl-final/include/sys/vfs.h b/05/musl-final/include/sys/vfs.h deleted file mode 100644 index a899db2..0000000 --- a/05/musl-final/include/sys/vfs.h +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/05/musl-final/include/sys/vt.h b/05/musl-final/include/sys/vt.h deleted file mode 100644 index 834abfb..0000000 --- a/05/musl-final/include/sys/vt.h +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/05/musl-final/include/sys/wait.h b/05/musl-final/include/sys/wait.h deleted file mode 100644 index a185153..0000000 --- a/05/musl-final/include/sys/wait.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef _SYS_WAIT_H -#define _SYS_WAIT_H -#ifdef __cplusplus -extern "C" { -#endif - -#define __NEED_pid_t -#define __NEED_id_t -#define __NEED_time_t -#define __NEED_struct_timeval -#define __NEED_siginfo_t -#include - -typedef int idtype_t; - -pid_t wait (int *); -int waitid (idtype_t, id_t, siginfo_t *, int); -pid_t waitpid (pid_t, int *, int ); -//pid_t wait3 (int *, int, struct rusage *); -//pid_t wait4 (pid_t, int *, int, struct rusage *); - -#include -#include - -#ifdef __cplusplus -} -#endif -#endif diff --git a/05/musl-final/include/syslog.h b/05/musl-final/include/syslog.h deleted file mode 100644 index 119c9bc..0000000 --- a/05/musl-final/include/syslog.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef _SYS_SYSLOG_H -#define _SYS_SYSLOG_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define LOG_EMERG 0 -#define LOG_ALERT 1 -#define LOG_CRIT 2 -#define LOG_ERR 3 -#define LOG_WARNING 4 -#define LOG_NOTICE 5 -#define LOG_INFO 6 -#define LOG_DEBUG 7 - -#define LOG_MASK(p) (1<<(p)) - -#define LOG_KERN (0<<3) -#define LOG_USER (1<<3) -#define LOG_MAIL (2<<3) -#define LOG_DAEMON (3<<3) -#define LOG_AUTH (4<<3) -#define LOG_SYSLOG (5<<3) -#define LOG_LPR (6<<3) -#define LOG_NEWS (7<<3) -#define LOG_UUCP (8<<3) -#define LOG_CRON (9<<3) - -#define LOG_LOCAL0 (16<<3) -#define LOG_LOCAL1 (17<<3) -#define LOG_LOCAL2 (18<<3) -#define LOG_LOCAL3 (19<<3) -#define LOG_LOCAL4 (20<<3) -#define LOG_LOCAL5 (21<<3) -#define LOG_LOCAL6 (22<<3) -#define LOG_LOCAL7 (23<<3) - -#define LOG_PID 0x01 -#define LOG_CONS 0x02 -#define LOG_ODELAY 0x04 -#define LOG_NDELAY 0x08 -#define LOG_NOWAIT 0x10 - -void closelog (void); -void openlog (const char *, int, int); -int setlogmask (int); -void syslog (int, const char *, ...); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/05/musl-final/include/tar.h b/05/musl-final/include/tar.h deleted file mode 100644 index be58984..0000000 --- a/05/musl-final/include/tar.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef _TAR_H -#define _TAR_H - -#define TSUID 04000 -#define TSGID 02000 -#define TSVTX 01000 -#define TUREAD 00400 -#define TUWRITE 00200 -#define TUEXEC 00100 -#define TGREAD 00040 -#define TGWRITE 00020 -#define TGEXEC 00010 -#define TOREAD 00004 -#define TOWRITE 00002 -#define TOEXEC 00001 - -#define REGTYPE '0' -#define AREGTYPE '\0' -#define LNKTYPE '1' -#define SYMTYPE '2' -#define CHRTYPE '3' -#define BLKTYPE '4' -#define DIRTYPE '5' -#define FIFOTYPE '6' -#define CONTTYPE '7' - -#define TMAGIC "ustar" -#define TMAGLEN 6 - -#define TVERSION "00" -#define TVERSLEN 2 - -#endif diff --git a/05/musl-final/include/termios.h b/05/musl-final/include/termios.h deleted file mode 100644 index 4c46562..0000000 --- a/05/musl-final/include/termios.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef _TERMIOS_H -#define _TERMIOS_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define __NEED_pid_t - -#include - -typedef unsigned char cc_t; -typedef unsigned int speed_t; -typedef unsigned int tcflag_t; - -#define NCCS 32 - -#include - -speed_t cfgetospeed (const struct termios *); -speed_t cfgetispeed (const struct termios *); -int cfsetospeed (struct termios *, speed_t); -int cfsetispeed (struct termios *, speed_t); - -int tcgetattr (int, struct termios *); -int tcsetattr (int, int, const struct termios *); - -int tcsendbreak (int, int); -int tcdrain (int); -int tcflush (int, int); -int tcflow (int, int); - -pid_t tcgetsid (int); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/05/musl-final/include/time.h b/05/musl-final/include/time.h deleted file mode 100644 index 4cec647..0000000 --- a/05/musl-final/include/time.h +++ /dev/null @@ -1,114 +0,0 @@ -#ifndef _TIME_H -#define _TIME_H - -#ifdef __cplusplus -extern "C" { -#endif - -#undef NULL -#ifdef __cplusplus -#define NULL 0 -#else -#define NULL ((void*)0) -#endif - - -#define __NEED_size_t -#define __NEED_time_t -#define __NEED_clock_t - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) -#define __NEED_struct_timespec -#define __NEED_clockid_t -#define __NEED_timer_t -#define __NEED_pid_t -#endif - -#include - -struct tm -{ - int tm_sec; - int tm_min; - int tm_hour; - int tm_mday; - int tm_mon; - int tm_year; - int tm_wday; - int tm_yday; - int tm_isdst; - long __tm_gmtoff; - const char *__tm_zone; -}; - -clock_t clock (void); -time_t time (time_t *); -double difftime (time_t, time_t); -time_t mktime (struct tm *); -size_t strftime (char *, size_t, const char *, const struct tm *); -struct tm *gmtime (const time_t *); -struct tm *localtime (const time_t *); -char *asctime (const struct tm *); -char *ctime (const time_t *); - -#define CLOCKS_PER_SEC 1000000UL - - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) - -struct tm *gmtime_r (const time_t *, struct tm *); -struct tm *localtime_r (const time_t *, struct tm *); -char *asctime_r (const struct tm *, char *); -char *ctime_r (const time_t *, char *); - -void tzset (void); - -struct itimerspec -{ - struct timespec it_interval; - struct timespec it_value; -}; - -#define CLOCK_REALTIME 0 -#define CLOCK_MONOTONIC 1 -#define CLOCK_PROCESS_CPUTIME_ID 2 -#define CLOCK_THREAD_CPUTIME_ID 3 - -#define TIMER_ABSTIME 1 - -int nanosleep (const struct timespec *, struct timespec *); -int clock_getres (clockid_t, struct timespec *); -int clock_gettime (clockid_t, struct timespec *); -int clock_settime (clockid_t, const struct timespec *); -int clock_nanosleep (clockid_t, int, const struct timespec *, struct timespec *); -int clock_getcpuclockid (pid_t, clockid_t *); - -/* FIXME..?? */ -struct sigevent; -int timer_create (clockid_t, struct sigevent *, timer_t *); -int timer_delete (timer_t); -int timer_settime (timer_t, int, const struct itimerspec *, struct itimerspec *); -int timer_gettime (timer_t, struct itimerspec *); -int timer_getoverrun (timer_t); - -#endif - - -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) -char *strptime (const char *, const char *, struct tm *); -extern int daylight; -extern long timezone; -extern char *tzname[2]; -extern int getdate_err; -extern struct tm *getdate (const char *); -#endif - - -#ifdef __cplusplus -} -#endif - - -#endif diff --git a/05/musl-final/include/ucontext.h b/05/musl-final/include/ucontext.h deleted file mode 100644 index 96c27cb..0000000 --- a/05/musl-final/include/ucontext.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef _UCONTEXT_H -#define _UCONTEXT_H -#ifdef __cplusplus -extern "C" { -#endif - -#include - -struct __fpstate { - unsigned long __x[7]; - unsigned char __y[80]; - unsigned long __z; -}; - -typedef struct { - unsigned long __gregs[19]; - void *__fpregs; - unsigned long __oldmask, __cr2; -} mcontext_t; - -typedef struct ucontext { - unsigned long uc_flags; - struct ucontext *uc_link; - stack_t uc_stack; - mcontext_t uc_mcontext; - sigset_t uc_sigmask; - struct __fpstate __fpregs_mem; -} ucontext_t; - -int getcontext(ucontext_t *); -void makecontext(ucontext_t *, void (*)(void), int, ...); -int setcontext(const ucontext_t *); -int swapcontext(ucontext_t *, const ucontext_t *); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/05/musl-final/include/ulimit.h b/05/musl-final/include/ulimit.h deleted file mode 100644 index efdcd31..0000000 --- a/05/musl-final/include/ulimit.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef _ULIMIT_H -#define _ULIMIT_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define UL_GETFSIZE 1 -#define UL_SETFSIZE 2 - -long ulimit (int, ...); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/05/musl-final/include/unistd.h b/05/musl-final/include/unistd.h deleted file mode 100644 index b9e4814..0000000 --- a/05/musl-final/include/unistd.h +++ /dev/null @@ -1,468 +0,0 @@ -#ifndef _UNISTD_H -#define _UNISTD_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define STDIN_FILENO 0 -#define STDOUT_FILENO 1 -#define STDERR_FILENO 2 - -#undef SEEK_SET -#undef SEEK_CUR -#undef SEEK_END -#define SEEK_SET 0 -#define SEEK_CUR 1 -#define SEEK_END 2 - -#undef NULL -#ifdef __cplusplus -#define NULL 0 -#else -#define NULL ((void*)0) -#endif - -#define __NEED_size_t -#define __NEED_ssize_t -#define __NEED_uid_t -#define __NEED_gid_t -#define __NEED_off_t -#define __NEED_pid_t -#define __NEED_useconds_t -#define __NEED_intptr_t - -#include - -int pipe(int [2]); -int close(int); -int dup(int); -int dup2(int, int); -off_t lseek(int, off_t, int); -int fsync(int); -int fdatasync(int); - -ssize_t read(int, void *, size_t); -ssize_t write(int, const void *, size_t); -ssize_t pread(int, void *, size_t, off_t); -ssize_t pwrite(int, const void *, size_t, off_t); - -int chown(const char *, uid_t, gid_t); -int fchown(int, uid_t, gid_t); -int lchown(const char *, uid_t, gid_t); -int fchownat(int, const char *, uid_t, gid_t, int); - -int link(const char *, const char *); -int linkat(int, const char *, int, const char *, int); -int symlink(const char *, const char *); -int symlinkat(const char *, int, const char *); -int readlink(const char *, char *, size_t); -int readlinkat(int, const char *, char *, size_t); -int unlink(const char *); -int unlinkat(int, const char *, int); -int rmdir(const char *); -int truncate(const char *, off_t); -int ftruncate(int, off_t); - -#define F_OK 0 -#define R_OK 4 -#define W_OK 2 -#define X_OK 1 -int access(const char *, int); -int faccessat(int, const char *, int, int); - -int chdir(const char *); -int fchdir(int); -char *getcwd(char *, size_t); - -unsigned alarm(unsigned); -unsigned sleep(unsigned); -int pause(void); - -pid_t fork(void); -int execve(const char *, char *const [], char *const []); -int execv(const char *, char *const []); -int execle(const char *, ...); -int execl(const char *, ...); -int execvp(const char *, char *const []); -int execlp(const char *, ...); -void _exit(int); - -pid_t getpid(void); -pid_t getppid(void); -pid_t getpgrp(void); -pid_t getpgid(pid_t); -int setpgid(pid_t, pid_t); -pid_t setsid(void); -pid_t getsid(pid_t); -char *ttyname(int); -int ttyname_r(int, char *, size_t); -int isatty(int); -pid_t tcgetpgrp(int); -int tcsetpgrp(int, pid_t); - -uid_t getuid(void); -uid_t geteuid(void); -gid_t getgid(void); -gid_t getegid(void); -int getgroups(int, gid_t []); -int setuid(uid_t); -int setreuid(uid_t, uid_t); -int seteuid(uid_t); -int setgid(gid_t); -int setregid(gid_t, gid_t); -int setegid(gid_t); - -char *getlogin(void); -int getlogin_r(char *, size_t); -int gethostname(char *, size_t); -char *ctermid(char *); - -int getopt(int, char * const [], const char *); -extern char *optarg; -extern int optind, opterr, optopt; - -long pathconf(const char *, int); -long fpathconf(int, int); -long sysconf(int); -size_t confstr(int, char *, size_t); - -#define F_ULOCK 0 -#define F_LOCK 1 -#define F_TLOCK 2 -#define F_TEST 3 - -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) -int lockf(int, int, off_t); -int setpgrp(void); -char *crypt(const char *, const char *); -void encrypt(char *, int); -void swab(const void *, void *, ssize_t); -long gethostid(void); -int nice(int); -void sync(void); -#endif - -#ifdef _GNU_SOURCE -pid_t vfork(void); -int vhangup(void); -int chroot(const char *); -int getpagesize(void); -int sethostname(const char *, size_t); -int usleep(useconds_t); -useconds_t ualarm(useconds_t, useconds_t); -int setgroups(int, const gid_t []); -#endif - -#define _XOPEN_VERSION 700 -#define _XOPEN_UNIX 1 -#define _XOPEN_ENH_I18N 1 - -#define _POSIX_VERSION 200809L -#define _POSIX2_VERSION _POSIX_VERSION - -#define _POSIX_CHOWN_RESTRICTED 1 -#define _POSIX_IPV6 _POSIX_VERSION -#define _POSIX_JOB_CONTROL 1 -#define _POSIX_MAPPED_FILES _POSIX_VERSION -#define _POSIX_MEMLOCK _POSIX_VERSION -#define _POSIX_MEMLOCK_RANGE _POSIX_VERSION -#define _POSIX_MEMORY_PROTECTION _POSIX_VERSION -#define _POSIX_NO_TRUNC 1 -#define _POSIX_RAW_SOCKETS _POSIX_VERSION -#define _POSIX_REALTIME_SIGNALS _POSIX_VERSION -#define _POSIX_REGEXP 1 -#define _POSIX_SAVED_IDS 1 -#define _POSIX_SHELL 1 -#define _POSIX_VDISABLE 0 - -#define _POSIX_THREADS _POSIX_VERSION -#define _POSIX_THREAD_PROCESS_SHARED _POSIX_VERSION -#define _POSIX_THREAD_SAFE_FUNCTIONS _POSIX_VERSION -#define _POSIX_TIMERS _POSIX_VERSION -#define _POSIX_TIMEOUTS _POSIX_VERSION -#define _POSIX_MONOTONIC_CLOCK _POSIX_VERSION -#define _POSIX_CPUTIME _POSIX_VERSION -#define _POSIX_CLOCK_SELECTION _POSIX_VERSION -#define _POSIX_BARRIERS _POSIX_VERSION -#define _POSIX_SPIN_LOCKS _POSIX_VERSION -#define _POSIX_READER_WRITER_LOCKS _POSIX_VERSION -#define _POSIX_ASYNCHRONOUS_IO _POSIX_VERSION -#define _POSIX_SEMAPHORES _POSIX_VERSION - -#define _POSIX2_C_BIND _POSIX_VERSION - -#include - - - -#define _PC_LINK_MAX 0 -#define _PC_MAX_CANON 1 -#define _PC_MAX_INPUT 2 -#define _PC_NAME_MAX 3 -#define _PC_PATH_MAX 4 -#define _PC_PIPE_BUF 5 -#define _PC_CHOWN_RESTRICTED 6 -#define _PC_NO_TRUNC 7 -#define _PC_VDISABLE 8 -#define _PC_SYNC_IO 9 -#define _PC_ASYNC_IO 10 -#define _PC_PRIO_IO 11 -#define _PC_SOCK_MAXBUF 12 -#define _PC_FILESIZEBITS 13 -#define _PC_REC_INCR_XFER_SIZE 14 -#define _PC_REC_MAX_XFER_SIZE 15 -#define _PC_REC_MIN_XFER_SIZE 16 -#define _PC_REC_XFER_ALIGN 17 -#define _PC_ALLOC_SIZE_MIN 18 -#define _PC_SYMLINK_MAX 19 -#define _PC_2_SYMLINKS 20 - -#define _SC_ARG_MAX 0 -#define _SC_CHILD_MAX 1 -#define _SC_CLK_TCK 2 -#define _SC_NGROUPS_MAX 3 -#define _SC_OPEN_MAX 4 -#define _SC_STREAM_MAX 5 -#define _SC_TZNAME_MAX 6 -#define _SC_JOB_CONTROL 7 -#define _SC_SAVED_IDS 8 -#define _SC_REALTIME_SIGNALS 9 -#define _SC_PRIORITY_SCHEDULING 10 -#define _SC_TIMERS 11 -#define _SC_ASYNCHRONOUS_IO 12 -#define _SC_PRIORITIZED_IO 13 -#define _SC_SYNCHRONIZED_IO 14 -#define _SC_FSYNC 15 -#define _SC_MAPPED_FILES 16 -#define _SC_MEMLOCK 17 -#define _SC_MEMLOCK_RANGE 18 -#define _SC_MEMORY_PROTECTION 19 -#define _SC_MESSAGE_PASSING 20 -#define _SC_SEMAPHORES 21 -#define _SC_SHARED_MEMORY_OBJECTS 22 -#define _SC_AIO_LISTIO_MAX 23 -#define _SC_AIO_MAX 24 -#define _SC_AIO_PRIO_DELTA_MAX 25 -#define _SC_DELAYTIMER_MAX 26 -#define _SC_MQ_OPEN_MAX 27 -#define _SC_MQ_PRIO_MAX 28 -#define _SC_VERSION 29 -#define _SC_PAGE_SIZE 30 -#define _SC_PAGESIZE 30 /* !! */ -#define _SC_RTSIG_MAX 31 -#define _SC_SEM_NSEMS_MAX 32 -#define _SC_SEM_VALUE_MAX 33 -#define _SC_SIGQUEUE_MAX 34 -#define _SC_TIMER_MAX 35 -#define _SC_BC_BASE_MAX 36 -#define _SC_BC_DIM_MAX 37 -#define _SC_BC_SCALE_MAX 38 -#define _SC_BC_STRING_MAX 39 -#define _SC_COLL_WEIGHTS_MAX 40 -#define _SC_EQUIV_CLASS_MAX 41 -#define _SC_EXPR_NEST_MAX 42 -#define _SC_LINE_MAX 43 -#define _SC_RE_DUP_MAX 44 -#define _SC_CHARCLASS_NAME_MAX 45 -#define _SC_2_VERSION 46 -#define _SC_2_C_BIND 47 -#define _SC_2_C_DEV 48 -#define _SC_2_FORT_DEV 49 -#define _SC_2_FORT_RUN 50 -#define _SC_2_SW_DEV 51 -#define _SC_2_LOCALEDEF 52 -#define _SC_PII 53 -#define _SC_PII_XTI 54 -#define _SC_PII_SOCKET 55 -#define _SC_PII_INTERNET 56 -#define _SC_PII_OSI 57 -#define _SC_POLL 58 -#define _SC_SELECT 59 -#define _SC_UIO_MAXIOV 60 /* !! */ -#define _SC_IOV_MAX 60 -#define _SC_PII_INTERNET_STREAM 61 -#define _SC_PII_INTERNET_DGRAM 62 -#define _SC_PII_OSI_COTS 63 -#define _SC_PII_OSI_CLTS 64 -#define _SC_PII_OSI_M 65 -#define _SC_T_IOV_MAX 66 -#define _SC_THREADS 67 -#define _SC_THREAD_SAFE_FUNCTIONS 68 -#define _SC_GETGR_R_SIZE_MAX 69 -#define _SC_GETPW_R_SIZE_MAX 70 -#define _SC_LOGIN_NAME_MAX 71 -#define _SC_TTY_NAME_MAX 72 -#define _SC_THREAD_DESTRUCTOR_ITERATIONS 73 -#define _SC_THREAD_KEYS_MAX 74 -#define _SC_THREAD_STACK_MIN 75 -#define _SC_THREAD_THREADS_MAX 76 -#define _SC_THREAD_ATTR_STACKADDR 77 -#define _SC_THREAD_ATTR_STACKSIZE 78 -#define _SC_THREAD_PRIORITY_SCHEDULING 79 -#define _SC_THREAD_PRIO_INHERIT 80 -#define _SC_THREAD_PRIO_PROTECT 81 -#define _SC_THREAD_PROCESS_SHARED 82 -#define _SC_NPROCESSORS_CONF 83 -#define _SC_NPROCESSORS_ONLN 84 -#define _SC_PHYS_PAGES 85 -#define _SC_AVPHYS_PAGES 86 -#define _SC_ATEXIT_MAX 87 -#define _SC_PASS_MAX 88 -#define _SC_XOPEN_VERSION 89 -#define _SC_XOPEN_XCU_VERSION 90 -#define _SC_XOPEN_UNIX 91 -#define _SC_XOPEN_CRYPT 92 -#define _SC_XOPEN_ENH_I18N 93 -#define _SC_XOPEN_SHM 94 -#define _SC_2_CHAR_TERM 95 -#define _SC_2_C_VERSION 96 -#define _SC_2_UPE 97 -#define _SC_XOPEN_XPG2 98 -#define _SC_XOPEN_XPG3 99 -#define _SC_XOPEN_XPG4 100 -#define _SC_CHAR_BIT 101 -#define _SC_CHAR_MAX 102 -#define _SC_CHAR_MIN 103 -#define _SC_INT_MAX 104 -#define _SC_INT_MIN 105 -#define _SC_LONG_BIT 106 -#define _SC_WORD_BIT 107 -#define _SC_MB_LEN_MAX 108 -#define _SC_NZERO 109 -#define _SC_SSIZE_MAX 110 -#define _SC_SCHAR_MAX 111 -#define _SC_SCHAR_MIN 112 -#define _SC_SHRT_MAX 113 -#define _SC_SHRT_MIN 114 -#define _SC_UCHAR_MAX 115 -#define _SC_UINT_MAX 116 -#define _SC_ULONG_MAX 117 -#define _SC_USHRT_MAX 118 -#define _SC_NL_ARGMAX 119 -#define _SC_NL_LANGMAX 120 -#define _SC_NL_MSGMAX 121 -#define _SC_NL_NMAX 122 -#define _SC_NL_SETMAX 123 -#define _SC_NL_TEXTMAX 124 -#define _SC_XBS5_ILP32_OFF32 125 -#define _SC_XBS5_ILP32_OFFBIG 126 -#define _SC_XBS5_LP64_OFF64 127 -#define _SC_XBS5_LPBIG_OFFBIG 128 -#define _SC_XOPEN_LEGACY 129 -#define _SC_XOPEN_REALTIME 130 -#define _SC_XOPEN_REALTIME_THREADS 131 -#define _SC_ADVISORY_INFO 132 -#define _SC_BARRIERS 133 -#define _SC_BASE 134 -#define _SC_C_LANG_SUPPORT 135 -#define _SC_C_LANG_SUPPORT_R 136 -#define _SC_CLOCK_SELECTION 137 -#define _SC_CPUTIME 138 -#define _SC_THREAD_CPUTIME 139 -#define _SC_DEVICE_IO 140 -#define _SC_DEVICE_SPECIFIC 141 -#define _SC_DEVICE_SPECIFIC_R 142 -#define _SC_FD_MGMT 143 -#define _SC_FIFO 144 -#define _SC_PIPE 145 -#define _SC_FILE_ATTRIBUTES 146 -#define _SC_FILE_LOCKING 147 -#define _SC_FILE_SYSTEM 148 -#define _SC_MONOTONIC_CLOCK 149 -#define _SC_MULTI_PROCESS 150 -#define _SC_SINGLE_PROCESS 151 -#define _SC_NETWORKING 152 -#define _SC_READER_WRITER_LOCKS 153 -#define _SC_SPIN_LOCKS 154 -#define _SC_REGEXP 155 -#define _SC_REGEX_VERSION 156 -#define _SC_SHELL 157 -#define _SC_SIGNALS 158 -#define _SC_SPAWN 159 -#define _SC_SPORADIC_SERVER 160 -#define _SC_THREAD_SPORADIC_SERVER 161 -#define _SC_SYSTEM_DATABASE 162 -#define _SC_SYSTEM_DATABASE_R 163 -#define _SC_TIMEOUTS 164 -#define _SC_TYPED_MEMORY_OBJECTS 165 -#define _SC_USER_GROUPS 166 -#define _SC_USER_GROUPS_R 167 -#define _SC_2_PBS 168 -#define _SC_2_PBS_ACCOUNTING 169 -#define _SC_2_PBS_LOCATE 170 -#define _SC_2_PBS_MESSAGE 171 -#define _SC_2_PBS_TRACK 172 -#define _SC_SYMLOOP_MAX 173 -#define _SC_STREAMS 174 -#define _SC_2_PBS_CHECKPOINT 175 -#define _SC_V6_ILP32_OFF32 176 -#define _SC_V6_ILP32_OFFBIG 177 -#define _SC_V6_LP64_OFF64 178 -#define _SC_V6_LPBIG_OFFBIG 179 -#define _SC_HOST_NAME_MAX 180 -#define _SC_TRACE 181 -#define _SC_TRACE_EVENT_FILTER 182 -#define _SC_TRACE_INHERIT 183 -#define _SC_TRACE_LOG 184 - -#define _SC_IPV6 235 -#define _SC_RAW_SOCKETS 236 -#define _SC_V7_ILP32_OFF32 237 -#define _SC_V7_ILP32_OFFBIG 238 -#define _SC_V7_LP64_OFF64 239 -#define _SC_V7_LPBIG_OFFBIG 240 -#define _SC_SS_REPL_MAX 241 -#define _SC_TRACE_EVENT_NAME_MAX 242 -#define _SC_TRACE_NAME_MAX 243 -#define _SC_TRACE_SYS_MAX 244 -#define _SC_TRACE_USER_EVENT_MAX 245 -#define _SC_XOPEN_STREAMS 246 -#define _SC_THREAD_ROBUST_PRIO_INHERIT 247 -#define _SC_THREAD_ROBUST_PRIO_PROTECT 248 - -#define _CS_PATH 0 -#define _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS 1 -#define _CS_GNU_LIBC_VERSION 2 -#define _CS_GNU_LIBPTHREAD_VERSION 3 -#define _CS_POSIX_V5_WIDTH_RESTRICTED_ENVS 4 -#define _CS_POSIX_V7_WIDTH_RESTRICTED_ENVS 5 - -#define _CS_POSIX_V6_ILP32_OFF32_CFLAGS 1116 -#define _CS_POSIX_V6_ILP32_OFF32_LDFLAGS 1117 -#define _CS_POSIX_V6_ILP32_OFF32_LIBS 1118 -#define _CS_POSIX_V6_ILP32_OFF32_LINTFLAGS 1119 -#define _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS 1120 -#define _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS 1121 -#define _CS_POSIX_V6_ILP32_OFFBIG_LIBS 1122 -#define _CS_POSIX_V6_ILP32_OFFBIG_LINTFLAGS 1123 -#define _CS_POSIX_V6_LP64_OFF64_CFLAGS 1124 -#define _CS_POSIX_V6_LP64_OFF64_LDFLAGS 1125 -#define _CS_POSIX_V6_LP64_OFF64_LIBS 1126 -#define _CS_POSIX_V6_LP64_OFF64_LINTFLAGS 1127 -#define _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS 1128 -#define _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS 1129 -#define _CS_POSIX_V6_LPBIG_OFFBIG_LIBS 1130 -#define _CS_POSIX_V6_LPBIG_OFFBIG_LINTFLAGS 1131 -#define _CS_POSIX_V7_ILP32_OFF32_CFLAGS 1132 -#define _CS_POSIX_V7_ILP32_OFF32_LDFLAGS 1133 -#define _CS_POSIX_V7_ILP32_OFF32_LIBS 1134 -#define _CS_POSIX_V7_ILP32_OFF32_LINTFLAGS 1135 -#define _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS 1136 -#define _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS 1137 -#define _CS_POSIX_V7_ILP32_OFFBIG_LIBS 1138 -#define _CS_POSIX_V7_ILP32_OFFBIG_LINTFLAGS 1139 -#define _CS_POSIX_V7_LP64_OFF64_CFLAGS 1140 -#define _CS_POSIX_V7_LP64_OFF64_LDFLAGS 1141 -#define _CS_POSIX_V7_LP64_OFF64_LIBS 1142 -#define _CS_POSIX_V7_LP64_OFF64_LINTFLAGS 1143 -#define _CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS 1144 -#define _CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS 1145 -#define _CS_POSIX_V7_LPBIG_OFFBIG_LIBS 1146 -#define _CS_POSIX_V7_LPBIG_OFFBIG_LINTFLAGS 1147 - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/05/musl-final/include/utime.h b/05/musl-final/include/utime.h deleted file mode 100644 index ec82e0f..0000000 --- a/05/musl-final/include/utime.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef _UTIME_H -#define _UTIME_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define __NEED_time_t - -#include - -struct utimbuf -{ - time_t actime; - time_t modtime; -}; - -int utime (const char *, const struct utimbuf *); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/05/musl-final/include/utmp.h b/05/musl-final/include/utmp.h deleted file mode 100644 index f60ff88..0000000 --- a/05/musl-final/include/utmp.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef _UTMP_H -#define _UTMP_H - -#include - -#define ut_time ut_tv.tv_sec -#define ut_name ut_user -#define ut_exit __ut_exit -#define e_termination __e_termination -#define e_exit __e_exit -#define utmp utmpx -#define endutent endutxent -#define getutent getutxent -#define setutent setutxent -#define getutid getutxid -#define getutline getutxline -#define pututline pututxline -#define utmpname(x) (-1) - -#define _PATH_UTMP "/dev/null" -#define _PATH_WTMP "/dev/null" - -#endif diff --git a/05/musl-final/include/utmpx.h b/05/musl-final/include/utmpx.h deleted file mode 100644 index 9a2e307..0000000 --- a/05/musl-final/include/utmpx.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef _UTMPX_H -#define _UTMPX_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define __NEED_pid_t -#define __NEED_time_t -#define __NEED_struct_timeval - -#include - -struct utmpx -{ - short ut_type; - pid_t ut_pid; - char ut_line[32]; - char ut_id[4]; - char ut_user[32]; - char ut_host[256]; - struct { - short __e_termination; - short __e_exit; - } __ut_exit; - long ut_session; - struct timeval ut_tv; - unsigned ut_addr_v6[4]; - char __unused[20]; -}; - -void endutxent(void); -struct utmpx *getutxent(void); -struct utmpx *getutxid(const struct utmpx *); -struct utmpx *getutxline(const struct utmpx *); -struct utmpx *pututxline(const struct utmpx *); -void setutxent(void); - -#define EMPTY 0 -#define BOOT_TIME 2 -#define NEW_TIME 3 -#define OLD_TIME 4 -#define INIT_PROCESS 5 -#define LOGIN_PROCESS 6 -#define USER_PROCESS 7 -#define DEAD_PROCESS 8 - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/05/musl-final/include/wchar.h b/05/musl-final/include/wchar.h deleted file mode 100644 index 53d619b..0000000 --- a/05/musl-final/include/wchar.h +++ /dev/null @@ -1,160 +0,0 @@ -#ifndef _WCHAR_H -#define _WCHAR_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define __NEED_FILE -#define __NEED_va_list -#define __NEED_size_t -#define __NEED_wchar_t -#define __NEED_wint_t - -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) -#define __NEED_wctype_t -#endif - -#include - -#undef NULL -#ifdef __cplusplus -#define NULL 0 -#else -#define NULL ((void*)0) -#endif - -#undef WCHAR_MIN -#undef WCHAR_MAX -#define WCHAR_MIN (-1-0x7fffffff) -#define WCHAR_MAX (0x7fffffff) - -#undef WEOF -#define WEOF (-1) - - -typedef struct -{ - unsigned __opaque1, __opaque2; -} mbstate_t; - -wchar_t *wcscpy (wchar_t *, const wchar_t *); -wchar_t *wcsncpy (wchar_t *, const wchar_t *, size_t); - -wchar_t *wcscat (wchar_t *, const wchar_t *); -wchar_t *wcsncat (wchar_t *, const wchar_t *, size_t); - -int wcscmp (const wchar_t *, const wchar_t *); -int wcsncmp (const wchar_t *, const wchar_t *, size_t); - -size_t wcsxfrm (wchar_t *, const wchar_t *, size_t n); - -wchar_t *wcschr (const wchar_t *, wchar_t); -wchar_t *wcsrchr (const wchar_t *, wchar_t); - -size_t wcscspn (const wchar_t *, const wchar_t *); -size_t wcsspn (const wchar_t *, const wchar_t *); -wchar_t *wcspbrk (const wchar_t *, const wchar_t *); - -wchar_t *wcstok (wchar_t *, const wchar_t *, wchar_t **); - -size_t wcslen (const wchar_t *); - -wchar_t *wcsstr (const wchar_t *, const wchar_t *); -wchar_t *wcswcs (const wchar_t *, const wchar_t *); - -wchar_t *wmemchr (const wchar_t *, wchar_t, size_t); -int wmemcmp (const wchar_t *, const wchar_t *, size_t); -wchar_t *wmemcpy (wchar_t *, const wchar_t *, size_t); -wchar_t *wmemmove (wchar_t *, const wchar_t *, size_t); -wchar_t *wmemset (wchar_t *, wchar_t, size_t); - -wint_t btowc (int); -int wctob (wint_t); - -int mbsinit (const mbstate_t *); -size_t mbrtowc (wchar_t *, const char *, size_t, mbstate_t *); -size_t wcrtomb (char *, wchar_t, mbstate_t *); - -size_t mbrlen (const char *, size_t, mbstate_t *); - -size_t mbsrtowcs (wchar_t *, const char **, size_t, mbstate_t *); -size_t wcsrtombs (char *, const wchar_t **, size_t, mbstate_t *); - -float wcstof (const wchar_t *, wchar_t **); -double wcstod (const wchar_t *, wchar_t **); -long double wcstold (const wchar_t *, wchar_t **); - -long wcstol (const wchar_t *, wchar_t **, int); -unsigned long wcstoul (const wchar_t *, wchar_t **, int); - -long long wcstoll (const wchar_t *, wchar_t **, int); -unsigned long long wcstoull (const wchar_t *, wchar_t **, int); - - - -int fwide (FILE *, int); - - -int wprintf (const wchar_t *, ...); -int fwprintf (FILE *, const wchar_t *, ...); -int swprintf (wchar_t *, const wchar_t *, ...); - -int vwprintf (const wchar_t *, va_list); -int vfwprintf (FILE *, const wchar_t *, va_list); -int vswprintf (wchar_t *, const wchar_t *, va_list); - -int wscanf (const wchar_t *, ...); -int fwscanf (FILE *, const wchar_t *, ...); -int swscanf (const wchar_t *, const wchar_t *, ...); - -int vwscanf (const wchar_t *, va_list); -int vfwscanf (FILE *, const wchar_t *, va_list); -int vswscanf (const wchar_t *, const wchar_t *, va_list); - -wint_t fgetwc (FILE *); -wint_t getwc (FILE *); -wint_t getwchar (void); - -wint_t fputwc (wchar_t, FILE *); -wint_t putwc (wchar_t, FILE *); -wint_t putwchar (wchar_t); - -wchar_t *fgetws (wchar_t *, int, FILE *); -int fputws (const wchar_t *, FILE *); - -wint_t ungetwc (wint_t, FILE *); - -struct tm; -size_t wcsftime (wchar_t *, size_t, const wchar_t *, const struct tm *); - -#undef iswdigit - -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) -int wcwidth (wchar_t); -int wcswidth (const wchar_t *, size_t); -int iswalnum(wint_t); -int iswalpha(wint_t); -int iswblank(wint_t); -int iswcntrl(wint_t); -int iswdigit(wint_t); -int iswgraph(wint_t); -int iswlower(wint_t); -int iswprint(wint_t); -int iswpunct(wint_t); -int iswspace(wint_t); -int iswupper(wint_t); -int iswxdigit(wint_t); -int iswctype(wint_t, wctype_t); -wint_t towlower(wint_t); -wint_t towupper(wint_t); -wctype_t wctype(const char *); -#undef iswdigit -#define iswdigit(a) ((unsigned)(a)-'0' < 10) -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/05/musl-final/include/wctype.h b/05/musl-final/include/wctype.h deleted file mode 100644 index af9be06..0000000 --- a/05/musl-final/include/wctype.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef _WCTYPE_H -#define _WCTYPE_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define __NEED_wint_t -#define __NEED_wctrans_t -#define __NEED_wctype_t - -#include - -#undef WEOF -#define WEOF (-1) - -#undef iswdigit - -int iswalnum(wint_t); -int iswalpha(wint_t); -int iswblank(wint_t); -int iswcntrl(wint_t); -int iswdigit(wint_t); -int iswgraph(wint_t); -int iswlower(wint_t); -int iswprint(wint_t); -int iswpunct(wint_t); -int iswspace(wint_t); -int iswupper(wint_t); -int iswxdigit(wint_t); -int iswctype(wint_t, wctype_t); -wint_t towctrans(wint_t, wctrans_t); -wint_t towlower(wint_t); -wint_t towupper(wint_t); -wctrans_t wctrans(const char *); -wctype_t wctype(const char *); - -#undef iswdigit -#define iswdigit(a) ((unsigned)((a)-L'0') < 10) - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/05/musl-final/include/wordexp.h b/05/musl-final/include/wordexp.h deleted file mode 100644 index 91995c4..0000000 --- a/05/musl-final/include/wordexp.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef _WORDEXP_H -#define _WORDEXP_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define __NEED_size_t - -#include - -#define WRDE_DOOFFS 1 -#define WRDE_APPEND 2 -#define WRDE_NOCMD 4 -#define WRDE_REUSE 8 -#define WRDE_SHOWERR 16 -#define WRDE_UNDEF 32 - -typedef struct -{ - size_t we_wordc; - char **wc_wordv; - size_t we_offs; -} wordexp_t; - -#define WRDE_NOSYS -1 -#define WRDE_NOSPACE 1 -#define WRDE_BADCHAR 2 -#define WRDE_BADVAL 3 -#define WRDE_CMDSUB 4 -#define WRDE_SYNTAX 5 - -int wordexp (const char *, wordexp_t *, int); -void wordfree (wordexp_t *); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/05/musl-final/src/conf/confstr.c b/05/musl-final/src/conf/confstr.c deleted file mode 100644 index 4332f72..0000000 --- a/05/musl-final/src/conf/confstr.c +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include -#include - -size_t confstr(int name, char *buf, size_t len) -{ - const char *s = ""; - if (!name) { - s = "/bin:/usr/bin"; - } else if ((name&~4U)!=1 && name-_CS_POSIX_V6_ILP32_OFF32_CFLAGS>31U) { - errno = EINVAL; - return 0; - } - // snprintf is overkill but avoid wasting code size to implement - // this completely useless function and its truncation semantics - return snprintf(buf, len, "%s", s); -} diff --git a/05/musl-final/src/conf/fpathconf.c b/05/musl-final/src/conf/fpathconf.c deleted file mode 100644 index af7e4d3..0000000 --- a/05/musl-final/src/conf/fpathconf.c +++ /dev/null @@ -1,35 +0,0 @@ -#include -#include -#include - -long fpathconf(int fd, int name) -{ - static const short values[] = { - [_PC_LINK_MAX] = _POSIX_LINK_MAX, - [_PC_MAX_CANON] = _POSIX_MAX_CANON, - [_PC_MAX_INPUT] = _POSIX_MAX_INPUT, - [_PC_NAME_MAX] = NAME_MAX, - [_PC_PATH_MAX] = PATH_MAX, - [_PC_PIPE_BUF] = PIPE_BUF, - [_PC_CHOWN_RESTRICTED] = 1, - [_PC_NO_TRUNC] = 1, - [_PC_VDISABLE] = 0, - [_PC_SYNC_IO] = 0, - [_PC_ASYNC_IO] = 0, - [_PC_PRIO_IO] = 0, - [_PC_SOCK_MAXBUF] = -1, - [_PC_FILESIZEBITS] = sizeof(off_t), - [_PC_REC_INCR_XFER_SIZE] = PAGE_SIZE, - [_PC_REC_MAX_XFER_SIZE] = PAGE_SIZE, - [_PC_REC_MIN_XFER_SIZE] = PAGE_SIZE, - [_PC_REC_XFER_ALIGN] = PAGE_SIZE, - [_PC_ALLOC_SIZE_MIN] = PAGE_SIZE, - [_PC_SYMLINK_MAX] = SYMLINK_MAX, - [_PC_2_SYMLINKS] = 1 - }; - if (name > sizeof(values)/sizeof(values[0])) { - errno = EINVAL; - return -1; - } - return values[name]; -} diff --git a/05/musl-final/src/conf/pathconf.c b/05/musl-final/src/conf/pathconf.c deleted file mode 100644 index 01e19c5..0000000 --- a/05/musl-final/src/conf/pathconf.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -long pathconf(const char *path, int name) -{ - return fpathconf(-1, name); -} diff --git a/05/musl-final/src/conf/sysconf.c b/05/musl-final/src/conf/sysconf.c deleted file mode 100644 index cdaeb2a..0000000 --- a/05/musl-final/src/conf/sysconf.c +++ /dev/null @@ -1,222 +0,0 @@ -#include -#include -#include - -#define VER (-2) -#define OFLOW (-3) - -long sysconf(int name) -{ - static const short values[] = { - [_SC_ARG_MAX] = OFLOW, - [_SC_CHILD_MAX] = -1, - [_SC_CLK_TCK] = 100, - [_SC_NGROUPS_MAX] = 32, - [_SC_OPEN_MAX] = 1024, - [_SC_STREAM_MAX] = -1, - [_SC_TZNAME_MAX] = TZNAME_MAX, - [_SC_JOB_CONTROL] = 1, - [_SC_SAVED_IDS] = 1, - [_SC_REALTIME_SIGNALS] = 1, - [_SC_PRIORITY_SCHEDULING] = -1, - [_SC_TIMERS] = VER, - [_SC_ASYNCHRONOUS_IO] = VER, - [_SC_PRIORITIZED_IO] = -1, - [_SC_SYNCHRONIZED_IO] = -1, - [_SC_FSYNC] = -1, - [_SC_MAPPED_FILES] = VER, - [_SC_MEMLOCK] = VER, - [_SC_MEMLOCK_RANGE] = VER, - [_SC_MEMORY_PROTECTION] = VER, - [_SC_MESSAGE_PASSING] = -1, - [_SC_SEMAPHORES] = VER, - [_SC_SHARED_MEMORY_OBJECTS] = -1, - [_SC_AIO_LISTIO_MAX] = -1, - [_SC_AIO_MAX] = -1, - [_SC_AIO_PRIO_DELTA_MAX] = 0, /* ?? */ - [_SC_DELAYTIMER_MAX] = _POSIX_DELAYTIMER_MAX, - [_SC_MQ_OPEN_MAX] = -1, - [_SC_MQ_PRIO_MAX] = _POSIX_MQ_PRIO_MAX, - [_SC_VERSION] = VER, - [_SC_PAGE_SIZE] = PAGE_SIZE, - [_SC_RTSIG_MAX] = 63, /* ?? */ - [_SC_SEM_NSEMS_MAX] = _POSIX_SEM_NSEMS_MAX, - [_SC_SEM_VALUE_MAX] = _POSIX_SEM_VALUE_MAX, - [_SC_SIGQUEUE_MAX] = -1, - [_SC_TIMER_MAX] = -1, - [_SC_BC_BASE_MAX] = _POSIX2_BC_BASE_MAX, - [_SC_BC_DIM_MAX] = _POSIX2_BC_DIM_MAX, - [_SC_BC_SCALE_MAX] = _POSIX2_BC_SCALE_MAX, - [_SC_BC_STRING_MAX] = _POSIX2_BC_STRING_MAX, - [_SC_COLL_WEIGHTS_MAX] = COLL_WEIGHTS_MAX, - [_SC_EQUIV_CLASS_MAX] = -1, /* ?? */ - [_SC_EXPR_NEST_MAX] = -1, - [_SC_LINE_MAX] = -1, - [_SC_RE_DUP_MAX] = RE_DUP_MAX, - [_SC_CHARCLASS_NAME_MAX] = -1, /* ?? */ - [_SC_2_VERSION] = VER, - [_SC_2_C_BIND] = VER, - [_SC_2_C_DEV] = -1, - [_SC_2_FORT_DEV] = -1, - [_SC_2_FORT_RUN] = -1, - [_SC_2_SW_DEV] = -1, - [_SC_2_LOCALEDEF] = -1, - [_SC_PII] = -1, /* ????????? */ - [_SC_PII_XTI] = -1, - [_SC_PII_SOCKET] = -1, - [_SC_PII_INTERNET] = -1, - [_SC_PII_OSI] = -1, - [_SC_POLL] = 1, - [_SC_SELECT] = 1, - [_SC_IOV_MAX] = IOV_MAX, - [_SC_PII_INTERNET_STREAM] = -1, - [_SC_PII_INTERNET_DGRAM] = -1, - [_SC_PII_OSI_COTS] = -1, - [_SC_PII_OSI_CLTS] = -1, - [_SC_PII_OSI_M] = -1, - [_SC_T_IOV_MAX] = -1, - [_SC_THREADS] = VER, - [_SC_THREAD_SAFE_FUNCTIONS] = VER, - [_SC_GETGR_R_SIZE_MAX] = -1, - [_SC_GETPW_R_SIZE_MAX] = -1, - [_SC_LOGIN_NAME_MAX] = 256, - [_SC_TTY_NAME_MAX] = TTY_NAME_MAX, - [_SC_THREAD_DESTRUCTOR_ITERATIONS] = _POSIX_THREAD_DESTRUCTOR_ITERATIONS, - [_SC_THREAD_KEYS_MAX] = -1, - [_SC_THREAD_STACK_MIN] = 2*PAGE_SIZE, - [_SC_THREAD_THREADS_MAX] = -1, - [_SC_THREAD_ATTR_STACKADDR] = -1, - [_SC_THREAD_ATTR_STACKSIZE] = VER, - [_SC_THREAD_PRIORITY_SCHEDULING] = -1, - [_SC_THREAD_PRIO_INHERIT] = -1, - [_SC_THREAD_PRIO_PROTECT] = -1, - [_SC_THREAD_PROCESS_SHARED] = VER, - [_SC_NPROCESSORS_CONF] = -1, - [_SC_NPROCESSORS_ONLN] = -1, - [_SC_PHYS_PAGES] = -1, - [_SC_AVPHYS_PAGES] = -1, - [_SC_ATEXIT_MAX] = -1, - [_SC_PASS_MAX] = -1, - [_SC_XOPEN_VERSION] = _XOPEN_VERSION, - [_SC_XOPEN_XCU_VERSION] = _XOPEN_VERSION, - [_SC_XOPEN_UNIX] = -1, - [_SC_XOPEN_CRYPT] = -1, - [_SC_XOPEN_ENH_I18N] = 1, - [_SC_XOPEN_SHM] = 1, - [_SC_2_CHAR_TERM] = -1, - [_SC_2_C_VERSION] = -1, - [_SC_2_UPE] = -1, - [_SC_XOPEN_XPG2] = -1, - [_SC_XOPEN_XPG3] = -1, - [_SC_XOPEN_XPG4] = -1, - [_SC_CHAR_BIT] = -1, - [_SC_CHAR_MAX] = -1, - [_SC_CHAR_MIN] = -1, - [_SC_INT_MAX] = -1, - [_SC_INT_MIN] = -1, - [_SC_LONG_BIT] = -1, - [_SC_WORD_BIT] = -1, - [_SC_MB_LEN_MAX] = -1, - [_SC_NZERO] = NZERO, - [_SC_SSIZE_MAX] = -1, - [_SC_SCHAR_MAX] = -1, - [_SC_SCHAR_MIN] = -1, - [_SC_SHRT_MAX] = -1, - [_SC_SHRT_MIN] = -1, - [_SC_UCHAR_MAX] = -1, - [_SC_UINT_MAX] = -1, - [_SC_ULONG_MAX] = -1, - [_SC_USHRT_MAX] = -1, - [_SC_NL_ARGMAX] = -1, - [_SC_NL_LANGMAX] = -1, - [_SC_NL_MSGMAX] = -1, - [_SC_NL_NMAX] = -1, - [_SC_NL_SETMAX] = -1, - [_SC_NL_TEXTMAX] = -1, - [_SC_XBS5_ILP32_OFF32] = -1, - [_SC_XBS5_ILP32_OFFBIG] = 2*(sizeof(long)==4)-1, - [_SC_XBS5_LP64_OFF64] = 2*(sizeof(long)==8)-1, - [_SC_XBS5_LPBIG_OFFBIG] = 2*(sizeof(long)>=8)-1, - [_SC_XOPEN_LEGACY] = -1, - [_SC_XOPEN_REALTIME] = -1, - [_SC_XOPEN_REALTIME_THREADS] = -1, - [_SC_ADVISORY_INFO] = -1, - [_SC_BARRIERS] = VER, - [_SC_BASE] = -1, - [_SC_C_LANG_SUPPORT] = -1, - [_SC_C_LANG_SUPPORT_R] = -1, - [_SC_CLOCK_SELECTION] = VER, - [_SC_CPUTIME] = VER, - [_SC_THREAD_CPUTIME] = -1, - [_SC_DEVICE_IO] = -1, - [_SC_DEVICE_SPECIFIC] = -1, - [_SC_DEVICE_SPECIFIC_R] = -1, - [_SC_FD_MGMT] = -1, - [_SC_FIFO] = -1, - [_SC_PIPE] = -1, - [_SC_FILE_ATTRIBUTES] = -1, - [_SC_FILE_LOCKING] = -1, - [_SC_FILE_SYSTEM] = -1, - [_SC_MONOTONIC_CLOCK] = VER, - [_SC_MULTI_PROCESS] = -1, - [_SC_SINGLE_PROCESS] = -1, - [_SC_NETWORKING] = -1, - [_SC_READER_WRITER_LOCKS] = VER, - [_SC_SPIN_LOCKS] = VER, - [_SC_REGEXP] = 1, - [_SC_REGEX_VERSION] = -1, - [_SC_SHELL] = 1, - [_SC_SIGNALS] = -1, - [_SC_SPAWN] = -1, - [_SC_SPORADIC_SERVER] = -1, - [_SC_THREAD_SPORADIC_SERVER] = -1, - [_SC_SYSTEM_DATABASE] = -1, - [_SC_SYSTEM_DATABASE_R] = -1, - [_SC_TIMEOUTS] = VER, - [_SC_TYPED_MEMORY_OBJECTS] = -1, - [_SC_USER_GROUPS] = -1, - [_SC_USER_GROUPS_R] = -1, - [_SC_2_PBS] = -1, - [_SC_2_PBS_ACCOUNTING] = -1, - [_SC_2_PBS_LOCATE] = -1, - [_SC_2_PBS_MESSAGE] = -1, - [_SC_2_PBS_TRACK] = -1, - [_SC_SYMLOOP_MAX] = SYMLOOP_MAX, - [_SC_STREAMS] = 0, - [_SC_2_PBS_CHECKPOINT] = -1, - [_SC_V6_ILP32_OFF32] = -1, - [_SC_V6_ILP32_OFFBIG] = 2*(sizeof(long)==4)-1, - [_SC_V6_LP64_OFF64] = 2*(sizeof(long)==8)-1, - [_SC_V6_LPBIG_OFFBIG] = 2*(sizeof(long)>=8)-1, - [_SC_HOST_NAME_MAX] = HOST_NAME_MAX, - [_SC_TRACE] = -1, - [_SC_TRACE_EVENT_FILTER] = -1, - [_SC_TRACE_INHERIT] = -1, - [_SC_TRACE_LOG] = -1, - - [_SC_IPV6] = VER, - [_SC_RAW_SOCKETS] = VER, - [_SC_V7_ILP32_OFF32] = -1, - [_SC_V7_ILP32_OFFBIG] = 2*(sizeof(long)==4)-1, - [_SC_V7_LP64_OFF64] = 2*(sizeof(long)==8)-1, - [_SC_V7_LPBIG_OFFBIG] = 2*(sizeof(long)>=8)-1, - [_SC_SS_REPL_MAX] = -1, - [_SC_TRACE_EVENT_NAME_MAX] = -1, - [_SC_TRACE_NAME_MAX] = -1, - [_SC_TRACE_SYS_MAX] = -1, - [_SC_TRACE_USER_EVENT_MAX] = -1, - [_SC_XOPEN_STREAMS] = 0, - [_SC_THREAD_ROBUST_PRIO_INHERIT] = -1, - [_SC_THREAD_ROBUST_PRIO_PROTECT] = -1, - }; - if (name > sizeof(values)/sizeof(values[0])) { - errno = EINVAL; - return -1; - } else if (values[name] == VER) { - return _POSIX_VERSION; - } else if (values[name] == OFLOW) { - return ARG_MAX; - } else { - return values[name]; - } -} diff --git a/05/musl-final/src/ctype/__ctype_get_mb_cur_max.c b/05/musl-final/src/ctype/__ctype_get_mb_cur_max.c deleted file mode 100644 index 42e4ee7..0000000 --- a/05/musl-final/src/ctype/__ctype_get_mb_cur_max.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -size_t __ctype_get_mb_cur_max() -{ - return 4; -} diff --git a/05/musl-final/src/ctype/isalnum.c b/05/musl-final/src/ctype/isalnum.c deleted file mode 100644 index e3d2cf0..0000000 --- a/05/musl-final/src/ctype/isalnum.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int isalnum(int c) -{ - return isalpha(c) || isdigit(c); -} diff --git a/05/musl-final/src/ctype/isalpha.c b/05/musl-final/src/ctype/isalpha.c deleted file mode 100644 index 53e115c..0000000 --- a/05/musl-final/src/ctype/isalpha.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#undef isalpha - -int isalpha(int c) -{ - return ((unsigned)c|32)-'a' < 26; -} diff --git a/05/musl-final/src/ctype/isascii.c b/05/musl-final/src/ctype/isascii.c deleted file mode 100644 index 3af0a10..0000000 --- a/05/musl-final/src/ctype/isascii.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int isascii(int c) -{ - return !(c&~0x7f); -} diff --git a/05/musl-final/src/ctype/isblank.c b/05/musl-final/src/ctype/isblank.c deleted file mode 100644 index 957400b..0000000 --- a/05/musl-final/src/ctype/isblank.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int isblank(int c) -{ - return (c == ' ' || c == '\t'); -} diff --git a/05/musl-final/src/ctype/iscntrl.c b/05/musl-final/src/ctype/iscntrl.c deleted file mode 100644 index 92ed7f0..0000000 --- a/05/musl-final/src/ctype/iscntrl.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int iscntrl(int c) -{ - return (unsigned)c < 0x20 || c == 0x7f; -} diff --git a/05/musl-final/src/ctype/isdigit.c b/05/musl-final/src/ctype/isdigit.c deleted file mode 100644 index 0bc82a6..0000000 --- a/05/musl-final/src/ctype/isdigit.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#undef isdigit - -int isdigit(int c) -{ - return (unsigned)c-'0' < 10; -} diff --git a/05/musl-final/src/ctype/isgraph.c b/05/musl-final/src/ctype/isgraph.c deleted file mode 100644 index 98979d1..0000000 --- a/05/musl-final/src/ctype/isgraph.c +++ /dev/null @@ -1,4 +0,0 @@ -int isgraph(int c) -{ - return (unsigned)c-0x21 < 0x5e; -} diff --git a/05/musl-final/src/ctype/islower.c b/05/musl-final/src/ctype/islower.c deleted file mode 100644 index d72fb21..0000000 --- a/05/musl-final/src/ctype/islower.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#undef islower - -int islower(int c) -{ - return (unsigned)c-'a' < 26; -} diff --git a/05/musl-final/src/ctype/isprint.c b/05/musl-final/src/ctype/isprint.c deleted file mode 100644 index 504e66e..0000000 --- a/05/musl-final/src/ctype/isprint.c +++ /dev/null @@ -1,4 +0,0 @@ -int isprint(int c) -{ - return (unsigned)c-0x20 < 0x5f; -} diff --git a/05/musl-final/src/ctype/ispunct.c b/05/musl-final/src/ctype/ispunct.c deleted file mode 100644 index fc45535..0000000 --- a/05/musl-final/src/ctype/ispunct.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int ispunct(int c) -{ - return isgraph(c) && !isalnum(c); -} diff --git a/05/musl-final/src/ctype/isspace.c b/05/musl-final/src/ctype/isspace.c deleted file mode 100644 index 8e535aa..0000000 --- a/05/musl-final/src/ctype/isspace.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int isspace(int c) -{ - return c == ' ' || (unsigned)c-'\t' < 5; -} diff --git a/05/musl-final/src/ctype/isupper.c b/05/musl-final/src/ctype/isupper.c deleted file mode 100644 index f09d88c..0000000 --- a/05/musl-final/src/ctype/isupper.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#undef isupper - -int isupper(int c) -{ - return (unsigned)c-'A' < 26; -} diff --git a/05/musl-final/src/ctype/iswalnum.c b/05/musl-final/src/ctype/iswalnum.c deleted file mode 100644 index d3b5667..0000000 --- a/05/musl-final/src/ctype/iswalnum.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include - -#undef iswalnum - -int iswalnum(wint_t wc) -{ - return (unsigned)wc-'0' < 10 || iswalpha(wc); -} diff --git a/05/musl-final/src/ctype/iswalpha.c b/05/musl-final/src/ctype/iswalpha.c deleted file mode 100644 index 0f031ea..0000000 --- a/05/musl-final/src/ctype/iswalpha.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int iswalpha(wint_t wc) -{ - return (32U|wc)-'a'<26; -} diff --git a/05/musl-final/src/ctype/iswblank.c b/05/musl-final/src/ctype/iswblank.c deleted file mode 100644 index bc6196f..0000000 --- a/05/musl-final/src/ctype/iswblank.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include -#include - -int iswblank(wint_t wc) -{ - return isblank(wc); -} diff --git a/05/musl-final/src/ctype/iswcntrl.c b/05/musl-final/src/ctype/iswcntrl.c deleted file mode 100644 index 93942b0..0000000 --- a/05/musl-final/src/ctype/iswcntrl.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include - -int iswcntrl(wint_t wc) -{ - return (unsigned)wc < 32 - || (unsigned)(wc-0x7f) < 33 - || (unsigned)(wc-0x2028) < 2 - || (unsigned)(wc-0xfff9) < 3; -} diff --git a/05/musl-final/src/ctype/iswctype.c b/05/musl-final/src/ctype/iswctype.c deleted file mode 100644 index d917975..0000000 --- a/05/musl-final/src/ctype/iswctype.c +++ /dev/null @@ -1,63 +0,0 @@ -#include -#include -#include - -#define WCTYPE_ALNUM 1 -#define WCTYPE_ALPHA 2 -#define WCTYPE_BLANK 3 -#define WCTYPE_CNTRL 4 -#define WCTYPE_DIGIT 5 -#define WCTYPE_GRAPH 6 -#define WCTYPE_LOWER 7 -#define WCTYPE_PRINT 8 -#define WCTYPE_PUNCT 9 -#define WCTYPE_SPACE 10 -#define WCTYPE_UPPER 11 -#define WCTYPE_XDIGIT 12 - -int iswctype(wint_t wc, wctype_t type) -{ - switch (type) { - case WCTYPE_ALNUM: - return iswalnum(wc); - case WCTYPE_ALPHA: - return iswalpha(wc); - case WCTYPE_BLANK: - return iswblank(wc); - case WCTYPE_CNTRL: - return iswcntrl(wc); - case WCTYPE_DIGIT: - return iswdigit(wc); - case WCTYPE_GRAPH: - return iswgraph(wc); - case WCTYPE_LOWER: - return iswlower(wc); - case WCTYPE_PRINT: - return iswprint(wc); - case WCTYPE_PUNCT: - return iswpunct(wc); - case WCTYPE_SPACE: - return iswspace(wc); - case WCTYPE_UPPER: - return iswupper(wc); - case WCTYPE_XDIGIT: - return iswxdigit(wc); - } - return 0; -} - -wctype_t wctype(const char *s) -{ - int i; - const char *p; - /* order must match! */ - static const char names[] = - "alnum\0" "alpha\0" "blank\0" - "cntrl\0" "digit\0" "graph\0" - "lower\0" "print\0" "punct\0" - "space\0" "upper\0" "xdigit"; - for (i=1, p=names; *p; i++, p+=6) - if (*s == *p && !strcmp(s, p)) - return i; - return 0; -} diff --git a/05/musl-final/src/ctype/iswdigit.c b/05/musl-final/src/ctype/iswdigit.c deleted file mode 100644 index 0487145..0000000 --- a/05/musl-final/src/ctype/iswdigit.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include - -#undef iswdigit - -int iswdigit(wint_t wc) -{ - return (unsigned)wc-'0' < 10; -} diff --git a/05/musl-final/src/ctype/iswgraph.c b/05/musl-final/src/ctype/iswgraph.c deleted file mode 100644 index fdc9785..0000000 --- a/05/musl-final/src/ctype/iswgraph.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int iswgraph(wint_t wc) -{ - /* ISO C defines this function as: */ - return !iswspace(wc) && iswprint(wc); -} diff --git a/05/musl-final/src/ctype/iswlower.c b/05/musl-final/src/ctype/iswlower.c deleted file mode 100644 index 0a568e7..0000000 --- a/05/musl-final/src/ctype/iswlower.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int iswlower(wint_t wc) -{ - return towupper(wc) != wc; -} diff --git a/05/musl-final/src/ctype/iswprint.c b/05/musl-final/src/ctype/iswprint.c deleted file mode 100644 index 7717671..0000000 --- a/05/musl-final/src/ctype/iswprint.c +++ /dev/null @@ -1,10 +0,0 @@ -#include - -int iswprint(wint_t wc) -{ - unsigned c = wc; - /* assume any non-control, non-illegal codepoint is printable */ - if (c>0x10ffff || c-0xd800<0x800 || (c&0xfffe)==0xfffe || iswcntrl(c)) - return 0; - return 1; -} diff --git a/05/musl-final/src/ctype/iswpunct.c b/05/musl-final/src/ctype/iswpunct.c deleted file mode 100644 index 1414c30..0000000 --- a/05/musl-final/src/ctype/iswpunct.c +++ /dev/null @@ -1,138 +0,0 @@ -#include -#include - -/* The below data is derived from classes (P.|Sm) plus Pattern_Syntax */ - -#define R(a,b) { (b), (b)-(a) } - -static const struct range { - uint32_t base:20; - uint32_t len:12; -} ranges[] = { -R(0x21, 0x2f), -R(0x3a, 0x40), -R(0x5b, 0x60), -R(0x7b, 0x7e), -R(0xa1, 0xa7), -R(0xa9, 0xa9), -R(0xab, 0xac), -R(0xae, 0xae), -R(0xb0, 0xb1), -R(0xb6, 0xb7), -R(0xbb, 0xbb), -R(0xbf, 0xbf), -R(0xd7, 0xd7), -R(0xf7, 0xf7), -R(0x37e, 0x37e), -R(0x387, 0x387), -R(0x3f6, 0x3f6), -R(0x55a, 0x55f), -R(0x589, 0x58a), -R(0x5be, 0x5be), -R(0x5c0, 0x5c0), -R(0x5c3, 0x5c3), -R(0x5c6, 0x5c6), -R(0x5f3, 0x5f4), -R(0x606, 0x60a), -R(0x60c, 0x60d), -R(0x61b, 0x61b), -R(0x61e, 0x61f), -R(0x66a, 0x66d), -R(0x6d4, 0x6d4), -R(0x700, 0x70d), -R(0x7f7, 0x7f9), -R(0x964, 0x965), -R(0x970, 0x970), -R(0xdf4, 0xdf4), -R(0xe4f, 0xe4f), -R(0xe5a, 0xe5b), -R(0xf04, 0xf12), -R(0xf3a, 0xf3d), -R(0xf85, 0xf85), -R(0xfd0, 0xfd4), -R(0x104a, 0x104f), -R(0x10fb, 0x10fb), -R(0x1361, 0x1368), -R(0x166d, 0x166e), -R(0x1680, 0x1680), -R(0x169b, 0x169c), -R(0x16eb, 0x16ed), -R(0x1735, 0x1736), -R(0x17d4, 0x17d6), -R(0x17d8, 0x17da), -R(0x1800, 0x180a), -R(0x180e, 0x180e), -R(0x1944, 0x1945), -R(0x19de, 0x19df), -R(0x1a1e, 0x1a1f), -R(0x1b5a, 0x1b60), -R(0x1c3b, 0x1c3f), -R(0x1c7e, 0x1c7f), -R(0x2010, 0x2027), -R(0x2030, 0x205e), -R(0x207a, 0x207e), -R(0x208a, 0x208e), -R(0x2140, 0x2144), -R(0x214b, 0x214b), -R(0x2190, 0x245f), -R(0x2500, 0x2775), -R(0x2794, 0x2bff), -R(0x2cf9, 0x2cfc), -R(0x2cfe, 0x2cff), -R(0x2e00, 0x2e7f), -R(0x3001, 0x3003), -R(0x3008, 0x3020), -R(0x3030, 0x3030), -R(0x303d, 0x303d), -R(0x30a0, 0x30a0), -R(0x30fb, 0x30fb), -R(0xa60d, 0xa60f), -R(0xa874, 0xa877), -R(0xa8ce, 0xa8cf), -R(0xa92e, 0xa92f), -R(0xa95f, 0xa95f), -R(0xfb29, 0xfb29), -R(0xfd3e, 0xfd3f), -R(0xfe10, 0xfe19), -R(0xfe30, 0xfe52), -R(0xfe54, 0xfe66), -R(0xfe68, 0xfe68), -R(0xfe6a, 0xfe6b), -R(0xff01, 0xff03), -R(0xff05, 0xff0f), -R(0xff1a, 0xff20), -R(0xff3b, 0xff3d), -R(0xff3f, 0xff3f), -R(0xff5b, 0xff65), -R(0xffe2, 0xffe2), -R(0xffe9, 0xffec), -R(0x10100, 0x10101), -R(0x1039f, 0x1039f), -R(0x103d0, 0x103d0), -R(0x1091f, 0x1091f), -R(0x1093f, 0x1093f), -R(0x10a50, 0x10a58), -R(0x12470, 0x12473), -R(0x1d6c1, 0x1d6c1), -R(0x1d6db, 0x1d6db), -R(0x1d6fb, 0x1d6fb), -R(0x1d715, 0x1d715), -R(0x1d735, 0x1d735), -R(0x1d74f, 0x1d74f), -R(0x1d76f, 0x1d76f), -R(0x1d789, 0x1d789), -R(0x1d7a9, 0x1d7a9), -R(0x1d7c3, 0x1d7c3), -}; - -int iswpunct(wint_t wc) -{ - unsigned c = wc; - int a = 0; - int n = sizeof ranges / sizeof ranges[0]; - do { - n >>= 1; - a += n+1 & (signed)(ranges[a+n].base-c)>>31; - } while (n); - return ranges[a].base-c <= ranges[a].len; -} diff --git a/05/musl-final/src/ctype/iswspace.c b/05/musl-final/src/ctype/iswspace.c deleted file mode 100644 index 68a1743..0000000 --- a/05/musl-final/src/ctype/iswspace.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include -#include - -int iswspace(wint_t wc) -{ - static const wchar_t spaces[] = { - ' ', '\t', '\n', '\r', 11, 12, 0x0085, - 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, - 0x2006, 0x2008, 0x2009, 0x200a, 0x200b, - 0x2028, 0x2029, 0x2050, 0x3000, 0 - }; - if (wcschr(spaces, wc)) return 1; - return 0; -} diff --git a/05/musl-final/src/ctype/iswupper.c b/05/musl-final/src/ctype/iswupper.c deleted file mode 100644 index eae59a7..0000000 --- a/05/musl-final/src/ctype/iswupper.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int iswupper(wint_t wc) -{ - return towlower(wc) != wc; -} diff --git a/05/musl-final/src/ctype/iswxdigit.c b/05/musl-final/src/ctype/iswxdigit.c deleted file mode 100644 index 229a469..0000000 --- a/05/musl-final/src/ctype/iswxdigit.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include - -int iswxdigit(wint_t wc) -{ - return (unsigned)(wc-'0') < 10 || (unsigned)((wc|32)-'a') < 6; -} diff --git a/05/musl-final/src/ctype/isxdigit.c b/05/musl-final/src/ctype/isxdigit.c deleted file mode 100644 index ae68a3d..0000000 --- a/05/musl-final/src/ctype/isxdigit.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int isxdigit(int c) -{ - return isdigit(c) || ((unsigned)c|32)-'a' < 6; -} diff --git a/05/musl-final/src/ctype/toascii.c b/05/musl-final/src/ctype/toascii.c deleted file mode 100644 index f0e48e8..0000000 --- a/05/musl-final/src/ctype/toascii.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -/* nonsense function that should NEVER be used! */ -int toascii(int c) -{ - return c & 0x7f; -} diff --git a/05/musl-final/src/ctype/tolower.c b/05/musl-final/src/ctype/tolower.c deleted file mode 100644 index b56f3c5..0000000 --- a/05/musl-final/src/ctype/tolower.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int tolower(int c) -{ - if (isupper(c)) return c | 32; - return c; -} diff --git a/05/musl-final/src/ctype/toupper.c b/05/musl-final/src/ctype/toupper.c deleted file mode 100644 index 1799f03..0000000 --- a/05/musl-final/src/ctype/toupper.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int toupper(int c) -{ - if (islower(c)) return c & 0x5f; - return c; -} diff --git a/05/musl-final/src/ctype/towctrans.c b/05/musl-final/src/ctype/towctrans.c deleted file mode 100644 index 0b1eed0..0000000 --- a/05/musl-final/src/ctype/towctrans.c +++ /dev/null @@ -1,246 +0,0 @@ -#include -#include -#include - -#define CASEMAP(u1,u2,l) { (u1), (l)-(u1), (u2)-(u1)+1 } -#define CASELACE(u1,u2) CASEMAP((u1),(u2),(u1)+1) - -static const struct { - unsigned short upper; - signed char lower; - unsigned char len; -} casemaps[] = { - CASEMAP('A','Z','a'), - CASEMAP(0xc0,0xde,0xe0), - - CASELACE(0x0100,0x012e), - CASELACE(0x0132,0x0136), - CASELACE(0x0139,0x0147), - CASELACE(0x014a,0x0176), - CASELACE(0x0179,0x017d), - - CASELACE(0x370,0x372), - CASEMAP(0x391,0x3a1,0x3b1), - CASEMAP(0x3a3,0x3ab,0x3c3), - CASEMAP(0x400,0x40f,0x450), - CASEMAP(0x410,0x42f,0x430), - - CASELACE(0x460,0x480), - CASELACE(0x48a,0x4be), - CASELACE(0x4c1,0x4cd), - CASELACE(0x4d0,0x50e), - - CASEMAP(0x531,0x556,0x561), - - CASELACE(0x01a0,0x01a4), - CASELACE(0x01b3,0x01b5), - CASELACE(0x01cd,0x01db), - CASELACE(0x01de,0x01ee), - CASELACE(0x01f8,0x021e), - CASELACE(0x0222,0x0232), - CASELACE(0x03d8,0x03ee), - - CASELACE(0x1e00,0x1e94), - CASELACE(0x1ea0,0x1efe), - - CASEMAP(0x1f08,0x1f0f,0x1f00), - CASEMAP(0x1f18,0x1f1d,0x1f10), - CASEMAP(0x1f28,0x1f2f,0x1f20), - CASEMAP(0x1f38,0x1f3f,0x1f30), - CASEMAP(0x1f48,0x1f4d,0x1f40), - - CASEMAP(0x1f68,0x1f6f,0x1f60), - CASEMAP(0x1f88,0x1f8f,0x1f80), - CASEMAP(0x1f98,0x1f9f,0x1f90), - CASEMAP(0x1fa8,0x1faf,0x1fa0), - CASEMAP(0x1fb8,0x1fb9,0x1fb0), - CASEMAP(0x1fba,0x1fbb,0x1f70), - CASEMAP(0x1fc8,0x1fcb,0x1f72), - CASEMAP(0x1fd8,0x1fd9,0x1fd0), - CASEMAP(0x1fda,0x1fdb,0x1f76), - CASEMAP(0x1fe8,0x1fe9,0x1fe0), - CASEMAP(0x1fea,0x1feb,0x1f7a), - CASEMAP(0x1ff8,0x1ff9,0x1f78), - CASEMAP(0x1ffa,0x1ffb,0x1f7c), - - CASELACE(0x246,0x24e), - CASELACE(0x510,0x512), - CASEMAP(0x2160,0x216f,0x2170), - CASEMAP(0x2c00,0x2c2e,0x2c30), - CASELACE(0x2c67,0x2c6b), - CASELACE(0x2c80,0x2ce2), - - CASELACE(0xa722,0xa72e), - CASELACE(0xa732,0xa76e), - CASELACE(0xa779,0xa77b), - CASELACE(0xa77e,0xa786), - - CASEMAP(0xff21,0xff3a,0xff41), - { 0,0,0 } -}; - -static const unsigned short pairs[][2] = { - { 'I', 0x0131 }, - { 'S', 0x017f }, - { 0x0130, 'i' }, - { 0x0178, 0x00ff }, - { 0x0181, 0x0253 }, - { 0x0182, 0x0183 }, - { 0x0184, 0x0185 }, - { 0x0186, 0x0254 }, - { 0x0187, 0x0188 }, - { 0x0189, 0x0256 }, - { 0x018a, 0x0257 }, - { 0x018b, 0x018c }, - { 0x018e, 0x01dd }, - { 0x018f, 0x0259 }, - { 0x0190, 0x025b }, - { 0x0191, 0x0192 }, - { 0x0193, 0x0260 }, - { 0x0194, 0x0263 }, - { 0x0196, 0x0269 }, - { 0x0197, 0x0268 }, - { 0x0198, 0x0199 }, - { 0x019c, 0x026f }, - { 0x019d, 0x0272 }, - { 0x019f, 0x0275 }, - { 0x01a6, 0x0280 }, - { 0x01a7, 0x01a8 }, - { 0x01a9, 0x0283 }, - { 0x01ac, 0x01ad }, - { 0x01ae, 0x0288 }, - { 0x01af, 0x01b0 }, - { 0x01b1, 0x028a }, - { 0x01b2, 0x028b }, - { 0x01b7, 0x0292 }, - { 0x01b8, 0x01b9 }, - { 0x01bc, 0x01bd }, - { 0x01c4, 0x01c6 }, - { 0x01c4, 0x01c5 }, - { 0x01c5, 0x01c6 }, - { 0x01c7, 0x01c9 }, - { 0x01c7, 0x01c8 }, - { 0x01c8, 0x01c9 }, - { 0x01ca, 0x01cc }, - { 0x01ca, 0x01cb }, - { 0x01cb, 0x01cc }, - { 0x01f1, 0x01f3 }, - { 0x01f1, 0x01f2 }, - { 0x01f2, 0x01f3 }, - { 0x01f4, 0x01f5 }, - { 0x01f6, 0x0195 }, - { 0x01f7, 0x01bf }, - { 0x0220, 0x019e }, - { 0x0386, 0x03ac }, - { 0x0388, 0x03ad }, - { 0x0389, 0x03ae }, - { 0x038a, 0x03af }, - { 0x038c, 0x03cc }, - { 0x038e, 0x03cd }, - { 0x038f, 0x03ce }, - { 0x0399, 0x0345 }, - { 0x0399, 0x1fbe }, - { 0x03a3, 0x03c2 }, - { 0x03f7, 0x03f8 }, - { 0x03fa, 0x03fb }, - { 0x1e60, 0x1e9b }, - - { 0x1f59, 0x1f51 }, - { 0x1f5b, 0x1f53 }, - { 0x1f5d, 0x1f55 }, - { 0x1f5f, 0x1f57 }, - { 0x1fbc, 0x1fb3 }, - { 0x1fcc, 0x1fc3 }, - { 0x1fec, 0x1fe5 }, - { 0x1ffc, 0x1ff3 }, - - { 0x23a, 0x2c65 }, - { 0x23b, 0x23c }, - { 0x23d, 0x19a }, - { 0x23e, 0x2c66 }, - { 0x241, 0x242 }, - { 0x243, 0x180 }, - { 0x244, 0x289 }, - { 0x245, 0x28c }, - { 0x3f4, 0x3b8 }, - { 0x3f9, 0x3f2 }, - { 0x3fd, 0x37b }, - { 0x3fe, 0x37c }, - { 0x3ff, 0x37d }, - { 0x4c0, 0x4cf }, - - { 0x2126, 0x3c9 }, - { 0x212a, 'k' }, - { 0x212b, 0xe5 }, - { 0x2132, 0x214e }, - { 0x2183, 0x2184 }, - { 0x2c60, 0x2c61 }, - { 0x2c62, 0x26b }, - { 0x2c63, 0x1d7d }, - { 0x2c64, 0x27d }, - { 0x2c6d, 0x251 }, - { 0x2c6e, 0x271 }, - { 0x2c6f, 0x250 }, - { 0x2c72, 0x2c73 }, - { 0x2c75, 0x2c76 }, - - { 0xa77d, 0x1d79 }, - - /* bogus greek 'symbol' letters */ - { 0x376, 0x377 }, - { 0x39c, 0xb5 }, - { 0x392, 0x3d0 }, - { 0x398, 0x3d1 }, - { 0x3a6, 0x3d5 }, - { 0x3a0, 0x3d6 }, - { 0x39a, 0x3f0 }, - { 0x3a1, 0x3f1 }, - { 0x395, 0x3f5 }, - { 0x3cf, 0x3d7 }, - - { 0,0 } -}; - - -static wchar_t __towcase(wchar_t wc, int lower) -{ - int i; - int lmul = 2*lower-1; - int lmask = lower-1; - if ((unsigned)wc - 0x10400 < 0x50) - return wc + lmul*0x28; - /* no letters with case in these large ranges */ - if (!iswalpha(wc) - || (unsigned)wc - 0x0600 <= 0x0fff-0x0600 - || (unsigned)wc - 0x2e00 <= 0xa6ff-0x2e00 - || (unsigned)wc - 0xa800 <= 0xfeff-0xa800) - return wc; - /* special case because the diff between upper/lower is too big */ - if ((unsigned)wc - 0x10a0 < 0x26 || (unsigned)wc - 0x2d00 < 0x26) - return wc + lmul*(0x2d00-0x10a0); - for (i=0; casemaps[i].len; i++) { - int base = casemaps[i].upper + (lmask & casemaps[i].lower); - if ((unsigned)wc-base < casemaps[i].len) { - if (casemaps[i].lower == 1) - return wc + lower - ((wc-casemaps[i].upper)&1); - return wc + lmul*casemaps[i].lower; - } - } - for (i=0; pairs[i][1-lower]; i++) { - if (pairs[i][1-lower] == wc) - return pairs[i][lower]; - } - if ((unsigned)wc - 0x10428 + (lower<<5) + (lower<<3) < 0x28) - return wc - 0x28 + (lower<<10) + (lower<<6); - return wc; -} - -wint_t towupper(wint_t wc) -{ - return __towcase(wc, 0); -} - -wint_t towlower(wint_t wc) -{ - return __towcase(wc, 1); -} diff --git a/05/musl-final/src/ctype/wcswidth.c b/05/musl-final/src/ctype/wcswidth.c deleted file mode 100644 index 5c8a5a4..0000000 --- a/05/musl-final/src/ctype/wcswidth.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -int wcswidth(const wchar_t *wcs, size_t n) -{ - int l=0, k=0; - for (; n-- && *wcs && (k = wcwidth(*wcs)) >= 0; l+=k, wcs++); - return (k < 0) ? k : l; -} diff --git a/05/musl-final/src/ctype/wctrans.c b/05/musl-final/src/ctype/wctrans.c deleted file mode 100644 index 03e9fd6..0000000 --- a/05/musl-final/src/ctype/wctrans.c +++ /dev/null @@ -1,16 +0,0 @@ -#include -#include - -wctrans_t wctrans(const char *class) -{ - if (!strcmp(class, "toupper")) return 1; - if (!strcmp(class, "tolower")) return 2; - return 0; -} - -wint_t towctrans(wint_t wc, wctrans_t trans) -{ - if (trans == 1) return towupper(wc); - if (trans == 2) return towlower(wc); - return wc; -} diff --git a/05/musl-final/src/ctype/wcwidth.c b/05/musl-final/src/ctype/wcwidth.c deleted file mode 100644 index eaafd7c..0000000 --- a/05/musl-final/src/ctype/wcwidth.c +++ /dev/null @@ -1,186 +0,0 @@ -#include -#include -#include - -#define R(a,b,w) { (b), (w)/2, (b)-(a) } - -static const struct range { - uint32_t base:20; - uint32_t width:1; - uint32_t len:11; -} ranges[] = { - R(0x0300, 0x036F, 0), - R(0x0483, 0x0486, 0), - R(0x0488, 0x0489, 0), - R(0x0591, 0x05BD, 0), - R(0x05BF, 0x05BF, 0), - R(0x05C1, 0x05C2, 0), - R(0x05C4, 0x05C5, 0), - R(0x05C7, 0x05C7, 0), - R(0x0600, 0x0603, 0), - R(0x0610, 0x0615, 0), - R(0x064B, 0x065E, 0), - R(0x0670, 0x0670, 0), - R(0x06D6, 0x06E4, 0), - R(0x06E7, 0x06E8, 0), - R(0x06EA, 0x06ED, 0), - R(0x070F, 0x070F, 0), - R(0x0711, 0x0711, 0), - R(0x0730, 0x074A, 0), - R(0x07A6, 0x07B0, 0), - R(0x07EB, 0x07F3, 0), - R(0x0901, 0x0902, 0), - R(0x093C, 0x093C, 0), - R(0x0941, 0x0948, 0), - R(0x094D, 0x094D, 0), - R(0x0951, 0x0954, 0), - R(0x0962, 0x0963, 0), - R(0x0981, 0x0981, 0), - R(0x09BC, 0x09BC, 0), - R(0x09C1, 0x09C4, 0), - R(0x09CD, 0x09CD, 0), - R(0x09E2, 0x09E3, 0), - R(0x0A01, 0x0A02, 0), - R(0x0A3C, 0x0A3C, 0), - R(0x0A41, 0x0A42, 0), - R(0x0A47, 0x0A48, 0), - R(0x0A4B, 0x0A4D, 0), - R(0x0A70, 0x0A71, 0), - R(0x0A81, 0x0A82, 0), - R(0x0ABC, 0x0ABC, 0), - R(0x0AC1, 0x0AC5, 0), - R(0x0AC7, 0x0AC8, 0), - R(0x0ACD, 0x0ACD, 0), - R(0x0AE2, 0x0AE3, 0), - R(0x0B01, 0x0B01, 0), - R(0x0B3C, 0x0B3C, 0), - R(0x0B3F, 0x0B3F, 0), - R(0x0B41, 0x0B43, 0), - R(0x0B4D, 0x0B4D, 0), - R(0x0B56, 0x0B56, 0), - R(0x0B82, 0x0B82, 0), - R(0x0BC0, 0x0BC0, 0), - R(0x0BCD, 0x0BCD, 0), - R(0x0C3E, 0x0C40, 0), - R(0x0C46, 0x0C48, 0), - R(0x0C4A, 0x0C4D, 0), - R(0x0C55, 0x0C56, 0), - R(0x0CBC, 0x0CBC, 0), - R(0x0CBF, 0x0CBF, 0), - R(0x0CC6, 0x0CC6, 0), - R(0x0CCC, 0x0CCD, 0), - R(0x0CE2, 0x0CE3, 0), - R(0x0D41, 0x0D43, 0), - R(0x0D4D, 0x0D4D, 0), - R(0x0DCA, 0x0DCA, 0), - R(0x0DD2, 0x0DD4, 0), - R(0x0DD6, 0x0DD6, 0), - R(0x0E31, 0x0E31, 0), - R(0x0E34, 0x0E3A, 0), - R(0x0E47, 0x0E4E, 0), - R(0x0EB1, 0x0EB1, 0), - R(0x0EB4, 0x0EB9, 0), - R(0x0EBB, 0x0EBC, 0), - R(0x0EC8, 0x0ECD, 0), - R(0x0F18, 0x0F19, 0), - R(0x0F35, 0x0F35, 0), - R(0x0F37, 0x0F37, 0), - R(0x0F39, 0x0F39, 0), - R(0x0F71, 0x0F7E, 0), - R(0x0F80, 0x0F84, 0), - R(0x0F86, 0x0F87, 0), - R(0x0F90, 0x0F97, 0), - R(0x0F99, 0x0FBC, 0), - R(0x0FC6, 0x0FC6, 0), - R(0x102D, 0x1030, 0), - R(0x1032, 0x1032, 0), - R(0x1036, 0x1037, 0), - R(0x1039, 0x1039, 0), - R(0x1058, 0x1059, 0), - R(0x1100, 0x115F, 2), - R(0x1160, 0x11FF, 0), - R(0x135F, 0x135F, 0), - R(0x1712, 0x1714, 0), - R(0x1732, 0x1734, 0), - R(0x1752, 0x1753, 0), - R(0x1772, 0x1773, 0), - R(0x17B4, 0x17B5, 0), - R(0x17B7, 0x17BD, 0), - R(0x17C6, 0x17C6, 0), - R(0x17C9, 0x17D3, 0), - R(0x17DD, 0x17DD, 0), - R(0x180B, 0x180D, 0), - R(0x18A9, 0x18A9, 0), - R(0x1920, 0x1922, 0), - R(0x1927, 0x1928, 0), - R(0x1932, 0x1932, 0), - R(0x1939, 0x193B, 0), - R(0x1A17, 0x1A18, 0), - R(0x1B00, 0x1B03, 0), - R(0x1B34, 0x1B34, 0), - R(0x1B36, 0x1B3A, 0), - R(0x1B3C, 0x1B3C, 0), - R(0x1B42, 0x1B42, 0), - R(0x1B6B, 0x1B73, 0), - R(0x1DC0, 0x1DCA, 0), - R(0x1DFE, 0x1DFF, 0), - R(0x200B, 0x200F, 0), - R(0x202A, 0x202E, 0), - R(0x2060, 0x2063, 0), - R(0x206A, 0x206F, 0), - R(0x20D0, 0x20EF, 0), - R(0x2329, 0x232A, 2), - R(0x2E80, 0x3029, 2), - R(0x302A, 0x302F, 0), - R(0x3030, 0x303E, 2), - R(0x3099, 0x309A, 0), - R(0xA806, 0xA806, 0), - R(0xA80B, 0xA80B, 0), - R(0xA825, 0xA826, 0), - R(0xF900, 0xFAFF, 2), - R(0xFB1E, 0xFB1E, 0), - R(0xFE00, 0xFE0F, 0), - R(0xFE20, 0xFE23, 0), - R(0xFE30, 0xFE6F, 2), - R(0xFEFF, 0xFEFF, 0), - R(0xFF00, 0xFF60, 2), - R(0xFFE0, 0xFFE6, 2), - R(0x10A01, 0x10A03, 0), - R(0x10A05, 0x10A06, 0), - R(0x10A0C, 0x10A0F, 0), - R(0x10A38, 0x10A3A, 0), - R(0x10A3F, 0x10A3F, 0), - R(0x1D167, 0x1D169, 0), - R(0x1D173, 0x1D182, 0), - R(0x1D185, 0x1D18B, 0), - R(0x1D1AA, 0x1D1AD, 0), - R(0x1D242, 0x1D244, 0), - R(0xE0001, 0xE0001, 0), - R(0xE0020, 0xE007F, 0), - R(0xE0100, 0xE01EF, 0), -}; - -/* Note: because the len field is only 10 bits, we must special-case - * the two huge ranges of full width characters and exclude them - * from the binary search table. */ - -int wcwidth(wchar_t wc) -{ - int a, n; - uint32_t c = wc; - - if (c-0x20 < 0x5f) return 1; - if (!iswprint(c)) return wc ? -1 : 0; - if (c-0x20000 < 0x20000) return 2; - - /* The following code is a branchless binary search. */ - a = 0; - n = sizeof ranges / sizeof ranges[0]; - do { - n >>= 1; - a += n+1 & (signed)(ranges[a+n].base-c)>>31; - } while (n); - if (ranges[a].base-c <= ranges[a].len) - return 2*ranges[a].width; - return 1 + (c-0x3040 < 0xd800-0x3040); -} diff --git a/05/musl-final/src/dirent/__dirent.h b/05/musl-final/src/dirent/__dirent.h deleted file mode 100644 index 07b3ee6..0000000 --- a/05/musl-final/src/dirent/__dirent.h +++ /dev/null @@ -1,9 +0,0 @@ -struct __DIR_s -{ - int lock; - int fd; - off_t tell; - int buf_pos; - int buf_end; - char buf[2048]; -}; diff --git a/05/musl-final/src/dirent/__getdents.c b/05/musl-final/src/dirent/__getdents.c deleted file mode 100644 index dc37344..0000000 --- a/05/musl-final/src/dirent/__getdents.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -int __getdents(int fd, struct dirent *buf, size_t len) -{ - return syscall3(__NR_getdents, fd, (long)buf, len); -} - -weak_alias(__getdents, getdents); - -LFS64(getdents); diff --git a/05/musl-final/src/dirent/alphasort.c b/05/musl-final/src/dirent/alphasort.c deleted file mode 100644 index 42050fb..0000000 --- a/05/musl-final/src/dirent/alphasort.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include -#include "libc.h" - -int alphasort(const struct dirent **a, const struct dirent **b) -{ - return strcoll((*a)->d_name, (*b)->d_name); -} - -LFS64(alphasort); diff --git a/05/musl-final/src/dirent/closedir.c b/05/musl-final/src/dirent/closedir.c deleted file mode 100644 index 81e9591..0000000 --- a/05/musl-final/src/dirent/closedir.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include -#include "__dirent.h" -#include "libc.h" - -int closedir(DIR *dir) -{ - int ret = close(dir->fd); - free(dir); - return ret; -} diff --git a/05/musl-final/src/dirent/dirfd.c b/05/musl-final/src/dirent/dirfd.c deleted file mode 100644 index 6c86007..0000000 --- a/05/musl-final/src/dirent/dirfd.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "__dirent.h" - -int dirfd(DIR *d) -{ - return d->fd; -} diff --git a/05/musl-final/src/dirent/fdopendir.c b/05/musl-final/src/dirent/fdopendir.c deleted file mode 100644 index c4b8e61..0000000 --- a/05/musl-final/src/dirent/fdopendir.c +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include "__dirent.h" - -DIR *fdopendir(int fd) -{ - DIR *dir; - struct stat st; - - if (fstat(fd, &st) < 0 || !S_ISDIR(st.st_mode)) { - errno = ENOTDIR; - return 0; - } - if (!(dir = calloc(1, sizeof *dir))) { - return 0; - } - - fcntl(fd, F_SETFD, FD_CLOEXEC); - dir->fd = fd; - return dir; -} diff --git a/05/musl-final/src/dirent/opendir.c b/05/musl-final/src/dirent/opendir.c deleted file mode 100644 index cefe6ce..0000000 --- a/05/musl-final/src/dirent/opendir.c +++ /dev/null @@ -1,25 +0,0 @@ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include "__dirent.h" - -DIR *opendir(const char *name) -{ - int fd; - DIR *dir; - - if ((fd = open(name, O_RDONLY|O_DIRECTORY)) < 0) - return 0; - fcntl(fd, F_SETFD, FD_CLOEXEC); - if (!(dir = calloc(1, sizeof *dir))) { - close(fd); - return 0; - } - dir->fd = fd; - return dir; -} diff --git a/05/musl-final/src/dirent/readdir.c b/05/musl-final/src/dirent/readdir.c deleted file mode 100644 index 1aeb25a..0000000 --- a/05/musl-final/src/dirent/readdir.c +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include "__dirent.h" -#include "syscall.h" -#include "libc.h" - -int __getdents(int, struct dirent *, size_t); - -struct dirent *readdir(DIR *dir) -{ - struct dirent *de; - - if (dir->buf_pos >= dir->buf_end) { - int len = __getdents(dir->fd, (void *)dir->buf, sizeof dir->buf); - if (len < 0) { - dir->lock = 0; - return NULL; - } else if (len == 0) return 0; - dir->buf_end = len; - dir->buf_pos = 0; - } - de = (void *)(dir->buf + dir->buf_pos); - dir->buf_pos += de->d_reclen; - dir->tell = de->d_off; - return de; -} - -LFS64(readdir); diff --git a/05/musl-final/src/dirent/readdir_r.c b/05/musl-final/src/dirent/readdir_r.c deleted file mode 100644 index 58f6032..0000000 --- a/05/musl-final/src/dirent/readdir_r.c +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include -#include -#include -#include "__dirent.h" -#include "libc.h" - -int readdir_r(DIR *dir, struct dirent *buf, struct dirent **result) -{ - struct dirent *de; - int errno_save = errno; - int ret; - - LOCK(&dir->lock); - errno = 0; - de = readdir(dir); - if ((ret = errno)) { - UNLOCK(&dir->lock); - return ret; - } - errno = errno_save; - if (de) memcpy(buf, de, de->d_reclen); - else buf = NULL; - - UNLOCK(&dir->lock); - *result = buf; - return 0; -} - -LFS64_2(readdir_r, readdir64_r); diff --git a/05/musl-final/src/dirent/rewinddir.c b/05/musl-final/src/dirent/rewinddir.c deleted file mode 100644 index c6138f7..0000000 --- a/05/musl-final/src/dirent/rewinddir.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include -#include "__dirent.h" -#include "libc.h" - -void rewinddir(DIR *dir) -{ - LOCK(&dir->lock); - lseek(dir->fd, 0, SEEK_SET); - dir->buf_pos = dir->buf_end = 0; - dir->tell = 0; - UNLOCK(&dir->lock); -} diff --git a/05/musl-final/src/dirent/scandir.c b/05/musl-final/src/dirent/scandir.c deleted file mode 100644 index 6a0a999..0000000 --- a/05/musl-final/src/dirent/scandir.c +++ /dev/null @@ -1,50 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -int scandir(const char *path, struct dirent ***res, - int (*sel)(const struct dirent *), - int (*cmp)(const struct dirent **, const struct dirent **)) -{ - DIR *d = opendir(path); - struct dirent *de, **names=0, **tmp; - size_t cnt=0, len=0, size; - int old_errno = errno; - - if (!d) return -1; - - while ((errno=0), (de = readdir(d))) { - if (sel && !sel(de)) continue; - if (cnt >= len) { - len = 2*len+1; - if (len > SIZE_MAX/sizeof *names) break; - tmp = realloc(names, len * sizeof *names); - if (!tmp) break; - names = tmp; - } - size = offsetof(struct dirent,d_name) + strlen(de->d_name) + 1; - names[cnt] = malloc(size); - if (!names[cnt]) break; - memcpy(names[cnt++], de, size); - } - - closedir(d); - - if (errno) { - old_errno = errno; - if (names) while (cnt-->0) free(names[cnt]); - free(names); - errno = old_errno; - return -1; - } - - if (cmp) qsort(names, cnt, sizeof *names, (int (*)(const void *, const void *))cmp); - *res = names; - return cnt; -} - -LFS64(scandir); diff --git a/05/musl-final/src/dirent/seekdir.c b/05/musl-final/src/dirent/seekdir.c deleted file mode 100644 index 81a0e33..0000000 --- a/05/musl-final/src/dirent/seekdir.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include -#include "__dirent.h" -#include "libc.h" - -void seekdir(DIR *dir, long off) -{ - LOCK(&dir->lock); - dir->tell = lseek(dir->fd, off, SEEK_SET); - dir->buf_pos = dir->buf_end = 0; - UNLOCK(&dir->lock); -} diff --git a/05/musl-final/src/dirent/telldir.c b/05/musl-final/src/dirent/telldir.c deleted file mode 100644 index cf25acf..0000000 --- a/05/musl-final/src/dirent/telldir.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "__dirent.h" - -long telldir(DIR *dir) -{ - return dir->tell; -} diff --git a/05/musl-final/src/env/__environ.c b/05/musl-final/src/env/__environ.c deleted file mode 100644 index 8c32952..0000000 --- a/05/musl-final/src/env/__environ.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "libc.h" - -#undef environ -char **___environ; -weak_alias(___environ, __environ); -weak_alias(___environ, _environ); -weak_alias(___environ, environ); diff --git a/05/musl-final/src/env/__libc_start_main.c b/05/musl-final/src/env/__libc_start_main.c deleted file mode 100644 index d4f360e..0000000 --- a/05/musl-final/src/env/__libc_start_main.c +++ /dev/null @@ -1,30 +0,0 @@ -#include "libc.h" - -#if 0 -/* Any use of __environ/environ will override this symbol. */ -char **__dummy_environ = (void *)-1; -weak_alias(__dummy_environ, ___environ); -#else -extern char **___environ; -#endif - -int __libc_start_main( - int (*main)(int, char **, char **), int argc, char **argv, - int (*init)(int, char **, char **), void (*fini)(void), - void (*ldso_fini)(void)) -{ - /* Save the environment if it may be used by libc/application */ - char **envp = argv+argc+1; - if (___environ != (void *)-1) ___environ = envp; - - /* Avoid writing 0 and triggering unnecessary COW */ - if (ldso_fini) libc.ldso_fini = ldso_fini; - if (fini) libc.fini = fini; - - /* Execute constructors (static) linked into the application */ - if (init) init(argc, argv, envp); - - /* Pass control to to application */ - exit(main(argc, argv, envp)); - return 0; -} diff --git a/05/musl-final/src/env/clearenv.c b/05/musl-final/src/env/clearenv.c deleted file mode 100644 index a2475ce..0000000 --- a/05/musl-final/src/env/clearenv.c +++ /dev/null @@ -1,9 +0,0 @@ -#include - -extern char **__environ; - -int clearenv() -{ - __environ[0] = 0; - return 0; -} diff --git a/05/musl-final/src/env/getenv.c b/05/musl-final/src/env/getenv.c deleted file mode 100644 index 00c1bce..0000000 --- a/05/musl-final/src/env/getenv.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include -#include "libc.h" - -char *getenv(const char *name) -{ - int i; - size_t l = strlen(name); - if (!__environ || !*name || strchr(name, '=')) return NULL; - for (i=0; __environ[i] && (strncmp(name, __environ[i], l) - || __environ[i][l] != '='); i++); - if (__environ[i]) return __environ[i] + l+1; - return NULL; -} diff --git a/05/musl-final/src/env/putenv.c b/05/musl-final/src/env/putenv.c deleted file mode 100644 index 181a418..0000000 --- a/05/musl-final/src/env/putenv.c +++ /dev/null @@ -1,59 +0,0 @@ -#include -#include -#include -#include - -extern char **__environ; -char **__env_map; - -int __putenv(char *s, int a) -{ - int i=0, j=0; - char *end = strchr(s, '='); - size_t l = end-s+1; - char **newenv = 0; - char **newmap = 0; - static char **oldenv; - - if (!end || l == 1) return -1; - for (; __environ[i] && memcmp(s, __environ[i], l); i++); - if (a) { - if (!__env_map) { - __env_map = calloc(2, sizeof(char *)); - if (__env_map) __env_map[0] = s; - } else { - for (; __env_map[j] && __env_map[j] != __environ[i]; j++); - if (!__env_map[j]) { - newmap = realloc(__env_map, sizeof(char *)*(j+2)); - if (newmap) { - __env_map = newmap; - __env_map[j] = s; - __env_map[j+1] = NULL; - } - } else { - free(__env_map[j]); - } - } - } - if (!__environ[i]) { - newenv = malloc(sizeof(char *)*(i+2)); - if (!newenv) { - if (a && __env_map) __env_map[j] = 0; - return -1; - } - memcpy(newenv, __environ, sizeof(char *)*i); - newenv[i] = s; - newenv[i+1] = 0; - __environ = newenv; - free(oldenv); - oldenv = __environ; - } - - __environ[i] = s; - return 0; -} - -int putenv(char *s) -{ - return __putenv(s, 0); -} diff --git a/05/musl-final/src/env/setenv.c b/05/musl-final/src/env/setenv.c deleted file mode 100644 index 03e165c..0000000 --- a/05/musl-final/src/env/setenv.c +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include -#include - -int __putenv(char *s, int a); - -int setenv(const char *var, const char *value, int overwrite) -{ - char *s; - int l1, l2; - - if (strchr(var, '=')) { - errno = EINVAL; - return -1; - } - if (!overwrite && getenv(var)) return 0; - - l1 = strlen(var); - l2 = strlen(value); - s = malloc(l1+l2+2); - memcpy(s, var, l1); - s[l1] = '='; - memcpy(s+l1+1, value, l2); - s[l1+l2+1] = 0; - if (__putenv(s, 1)) { - free(s); - errno = ENOMEM; - return -1; - } - return 0; -} diff --git a/05/musl-final/src/env/unsetenv.c b/05/musl-final/src/env/unsetenv.c deleted file mode 100644 index 7493d97..0000000 --- a/05/musl-final/src/env/unsetenv.c +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include -#include -#include - -extern char **__environ; -extern char **__env_map; - -int unsetenv(const char *name) -{ - int i, j; - size_t l = strlen(name); - - if (!*name || strchr(name, '=')) { - errno = EINVAL; - return -1; - } -again: - for (i=0; __environ[i] && (memcmp(name, __environ[i], l) || __environ[i][l] != '='); i++); - if (__environ[i]) { - if (__env_map) { - for (j=0; __env_map[j] && __env_map[j] != __environ[i]; j++); - free (__env_map[j]); - for (; __env_map[j]; j++) - __env_map[j] = __env_map[j+1]; - } - for (; __environ[i]; i++) - __environ[i] = __environ[i+1]; - goto again; - } - return 0; -} diff --git a/05/musl-final/src/errno/__errno_location.c b/05/musl-final/src/errno/__errno_location.c deleted file mode 100644 index 0a220b6..0000000 --- a/05/musl-final/src/errno/__errno_location.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include "libc.h" - -#undef errno -int errno; - -int *__errno_location(void) -{ - if (libc.errno_location) return libc.errno_location(); - return &errno; -} diff --git a/05/musl-final/src/errno/__strerror.h b/05/musl-final/src/errno/__strerror.h deleted file mode 100644 index 00eaf93..0000000 --- a/05/musl-final/src/errno/__strerror.h +++ /dev/null @@ -1,101 +0,0 @@ -/* This file is sorted such that 'errors' which represent exceptional - * conditions under which a correct program may fail come first, followed - * by messages that indicate an incorrect program or system failure. The - * macro E() along with double-inclusion is used to ensure that ordering - * of the strings remains synchronized. */ - -E(EILSEQ, "Illegal byte sequence") -E(EDOM, "Argument outside domain") -E(ERANGE, "Result not representable") - -E(ENOTTY, "Not a tty") -E(EACCES, "Permission denied") -E(EPERM, "Operation not permitted") -E(ENOENT, "No such file or directory") -E(ESRCH, "No such process") -E(EEXIST, "File exists") - -E(EOVERFLOW, "Value too large for defined data type") -E(ENOSPC, "No space left on device") -E(ENOMEM, "Out of memory") - -E(EBUSY, "Device or resource busy") -E(EINTR, "Interrupted system call") -E(EAGAIN, "Operation would block") -E(ESPIPE, "Illegal seek") - -E(EXDEV, "Cross-device link") -E(EROFS, "Read-only file system") -E(ENOTEMPTY, "Directory not empty") - -E(ECONNRESET, "Connection reset by peer") -E(ETIMEDOUT, "Connection timed out") -E(ECONNREFUSED, "Connection refused") -E(EHOSTDOWN, "Host is down") -E(EHOSTUNREACH, "No route to host") -E(EADDRINUSE, "Address already in use") - -E(EPIPE, "Broken pipe") -E(EIO, "I/O error") -E(ENXIO, "No such device or address") -E(ENOTBLK, "Block device required") -E(ENODEV, "No such device") -E(ENOTDIR, "Not a directory") -E(EISDIR, "Is a directory") -E(ETXTBSY, "Text file busy") -E(ENOEXEC, "Exec format error") - -E(EINVAL, "Invalid argument") - -E(E2BIG, "Argument list too long") -E(ELOOP, "Too many levels of symbolic links") -E(ENAMETOOLONG, "Filename too long") -E(ENFILE, "File table overflow") -E(EMFILE, "Too many open files") -E(EBADF, "Bad file number") -E(ECHILD, "No child processes") -E(EFAULT, "Bad address") -E(EFBIG, "File too large") -E(EMLINK, "Too many links") -E(ENOLCK, "No record locks available") - -E(EDEADLK, "Resource deadlock would occur") -E(ENOSYS, "Function not supported") -E(ENOMSG, "No message of desired type") -E(EIDRM, "Identifier removed") -E(ENOSTR, "Device not a stream") -E(ENODATA, "No data available") -E(ETIME, "Timer expired") -E(ENOSR, "Out of streams resources") -E(ENOLINK, "Link has been severed") -E(EPROTO, "Protocol error") -E(EBADMSG, "Not a data message") -E(EBADFD, "File descriptor in bad state") -E(ENOTSOCK, "Socket operation on non-socket") -E(EDESTADDRREQ, "Destination address required") -E(EMSGSIZE, "Message too long") -E(EPROTOTYPE, "Protocol wrong type for socket") -E(ENOPROTOOPT, "Protocol not available") -E(EPROTONOSUPPORT,"Protocol not supported") -E(ESOCKTNOSUPPORT,"Socket type not supported") -E(EOPNOTSUPP, "Operation not supported on socket") -E(EPFNOSUPPORT, "Protocol family not supported") -E(EAFNOSUPPORT, "Address family not supported by protocol") -E(EADDRNOTAVAIL,"Cannot assign requested address") -E(ENETDOWN, "Network is down") -E(ENETUNREACH, "Network is unreachable") -E(ENETRESET, "Network dropped connection because of reset") -E(ECONNABORTED, "Software caused connection abort") -E(ENOBUFS, "No buffer space available") -E(EISCONN, "Socket is connected") -E(ENOTCONN, "Socket is not connected") -E(ESHUTDOWN, "Cannot send after socket shutdown") -E(EALREADY, "Operation already in progress") -E(EINPROGRESS, "Operation now in progress") -E(ESTALE, "Stale NFS file handle") -E(EREMOTEIO, "Remote I/O error") -E(EDQUOT, "Quota exceeded") -E(ENOMEDIUM, "No medium found") -E(EMEDIUMTYPE, "Wrong medium type") - -E(0, "Invalid error number") diff --git a/05/musl-final/src/errno/strerror.c b/05/musl-final/src/errno/strerror.c deleted file mode 100644 index b8fbc6d..0000000 --- a/05/musl-final/src/errno/strerror.c +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include - -#define E(a,b) a, -static const unsigned char errid[] = { -#include "__strerror.h" -}; - -#undef E -#define E(a,b) b "\0" -static const char errmsg[] = -#include "__strerror.h" -; - -char *strerror(int e) -{ - const char *s; - int i; - for (i=0; errid[i] && errid[i] != e; i++); - for (s=errmsg; i; s++, i--) for (; *s; s++); - return (char *)s; -} diff --git a/05/musl-final/src/exit/_Exit.c b/05/musl-final/src/exit/_Exit.c deleted file mode 100644 index 8ef85a8..0000000 --- a/05/musl-final/src/exit/_Exit.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#define SYSCALL_NORETURN -#include "syscall.h" - -void _Exit(int ec) -{ - syscall1(__NR_exit_group, ec); - syscall1(__NR_exit, ec); -} diff --git a/05/musl-final/src/exit/abort.c b/05/musl-final/src/exit/abort.c deleted file mode 100644 index 9a1c3d4..0000000 --- a/05/musl-final/src/exit/abort.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include - -void abort(void) -{ - raise(SIGABRT); - for (;;); -} diff --git a/05/musl-final/src/exit/assert.c b/05/musl-final/src/exit/assert.c deleted file mode 100644 index e87442a..0000000 --- a/05/musl-final/src/exit/assert.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include - -void __assert_fail(const char *expr, const char *file, int line, const char *func) -{ - fprintf(stderr, "Assertion failed: %s (%s: %s: %d)\n", expr, file, func, line); - fflush(NULL); - abort(); -} diff --git a/05/musl-final/src/exit/atexit.c b/05/musl-final/src/exit/atexit.c deleted file mode 100644 index 49c060e..0000000 --- a/05/musl-final/src/exit/atexit.c +++ /dev/null @@ -1,57 +0,0 @@ -#include -#include -#include -#include "libc.h" - -/* Ensure that at least 32 atexit handlers can be registered without malloc */ -#define COUNT 32 - -static struct fl -{ - struct fl *next; - void (*f[COUNT])(void); -} builtin, *head; - -static int run_atexit_functions(void) -{ - int i; - for (; head; head=head->next) { - for (i=COUNT-1; i>=0 && !head->f[i]; i--); - for (; i>=0; i--) head->f[i](); - } - return 0; -} - -int (*const __funcs_on_exit)(void) = run_atexit_functions; - -int atexit(void (*func)(void)) -{ - static int lock; - int i; - - /* Hook for atexit extensions */ - if (libc.atexit) return libc.atexit(func); - - LOCK(&lock); - - /* Defer initialization of head so it can be in BSS */ - if (!head) head = &builtin; - - /* If the current function list is full, add a new one */ - if (head->f[COUNT-1]) { - struct fl *new_fl = calloc(sizeof(struct fl), 1); - if (!new_fl) { - UNLOCK(&lock); - return -1; - } - new_fl->next = head; - head = new_fl; - } - - /* Append function to the list. */ - for (i=0; if[i]; i++); - head->f[i] = func; - - UNLOCK(&lock); - return 0; -} diff --git a/05/musl-final/src/exit/exit.c b/05/musl-final/src/exit/exit.c deleted file mode 100644 index 2e4fa68..0000000 --- a/05/musl-final/src/exit/exit.c +++ /dev/null @@ -1,33 +0,0 @@ -#include -#include -#include -#include "libc.h" - -#if 0 -/* __overflow.c and atexit.c override these */ -static int (*const dummy)() = 0; -weak_alias(dummy, __funcs_on_exit); -weak_alias(dummy, __fflush_on_exit); -#else -extern int (*const __funcs_on_exit)(void); -extern int (*const __fflush_on_exit)(FILE *); -#endif - -void exit(int code) -{ - static int lock; - - /* If more than one thread calls exit, hang until _Exit ends it all */ - LOCK(&lock); - - /* Only do atexit & stdio flush if they were actually used */ - if (__funcs_on_exit) __funcs_on_exit(); - if (__fflush_on_exit) __fflush_on_exit(0); - - /* Destructor s**t is kept separate from atexit to avoid bloat */ - if (libc.fini) libc.fini(); - if (libc.ldso_fini) libc.ldso_fini(); - - _Exit(code); - for(;;); -} diff --git a/05/musl-final/src/fcntl/creat.c b/05/musl-final/src/fcntl/creat.c deleted file mode 100644 index be05faa..0000000 --- a/05/musl-final/src/fcntl/creat.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include "libc.h" - -int creat(const char *filename, mode_t mode) -{ - return open(filename, O_CREAT|O_WRONLY|O_TRUNC, mode); -} - -LFS64(creat); diff --git a/05/musl-final/src/fcntl/fcntl.c b/05/musl-final/src/fcntl/fcntl.c deleted file mode 100644 index 464dbf0..0000000 --- a/05/musl-final/src/fcntl/fcntl.c +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include -#include -#include "syscall.h" -#include "libc.h" - -int fcntl(int fd, int cmd, ...) -{ - int r; - long arg; - va_list ap; - va_start(ap, cmd); - arg = va_arg(ap, long); - va_end(ap); - if (cmd == F_SETFL) arg |= O_LARGEFILE; - if (cmd == F_SETLKW) CANCELPT_BEGIN; - r = __syscall_fcntl(fd, cmd, arg); - if (cmd == F_SETLKW) CANCELPT_END; - return r; -} - -LFS64(fcntl); diff --git a/05/musl-final/src/fcntl/open.c b/05/musl-final/src/fcntl/open.c deleted file mode 100644 index 4c1a591..0000000 --- a/05/musl-final/src/fcntl/open.c +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include -#include -#include "syscall.h" -#include "libc.h" - -int open(const char *filename, int flags, ...) -{ - int r; - mode_t mode; - va_list ap; - va_start(ap, flags); - mode = va_arg(ap, mode_t); - va_end(ap); - CANCELPT_BEGIN; - r = __syscall_open(filename, flags, mode); - CANCELPT_END; - return r; -} - -LFS64(open); diff --git a/05/musl-final/src/fcntl/openat.c b/05/musl-final/src/fcntl/openat.c deleted file mode 100644 index eefa090..0000000 --- a/05/musl-final/src/fcntl/openat.c +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include -#include -#include "syscall.h" -#include "libc.h" - -int openat(int fd, const char *filename, int flags, ...) -{ - int r; - mode_t mode; - va_list ap; - va_start(ap, flags); - mode = va_arg(ap, mode_t); - va_end(ap); - CANCELPT_BEGIN; - r = syscall4(__NR_openat, fd, (long)filename, flags|O_LARGEFILE, mode); - CANCELPT_END; - return r; -} - -LFS64(openat); diff --git a/05/musl-final/src/internal/futex.h b/05/musl-final/src/internal/futex.h deleted file mode 100644 index c045382..0000000 --- a/05/musl-final/src/internal/futex.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef _INTERNAL_FUTEX_H -#define _INTERNAL_FUTEX_H - -#define FUTEX_WAIT 0 -#define FUTEX_WAKE 1 -#define FUTEX_FD 2 -#define FUTEX_REQUEUE 3 -#define FUTEX_CMP_REQUEUE 4 -#define FUTEX_WAKE_OP 5 -#define FUTEX_LOCK_PI 6 -#define FUTEX_UNLOCK_PI 7 -#define FUTEX_TRYLOCK_PI 8 - -int __futex(volatile int *, int, int, void *); - -#endif diff --git a/05/musl-final/src/internal/libc.c b/05/musl-final/src/internal/libc.c deleted file mode 100644 index 5e8e9d9..0000000 --- a/05/musl-final/src/internal/libc.c +++ /dev/null @@ -1,3 +0,0 @@ -#include "libc.h" - -struct libc libc; diff --git a/05/musl-final/src/internal/libc.h b/05/musl-final/src/internal/libc.h deleted file mode 100644 index e353f36..0000000 --- a/05/musl-final/src/internal/libc.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef LIBC_H -#define LIBC_H - -#include -#include - -#define libc __libc -extern struct libc { - void (*lock)(volatile int *); - void (*cancelpt)(int); - int (*atexit)(void (*)(void)); - void (*fini)(void); - void (*ldso_fini)(void); - int *(*errno_location)(void); - volatile int threads_minus_1; - int (*rsyscall)(int, long, long, long, long, long, long); - void (**tsd_keys)(void *); -} libc; - - -/* Designed to avoid any overhead in non-threaded processes */ -void __lock(volatile int *); -#define LOCK(x) (libc.threads_minus_1 ? (__lock(x),1) : ((void)(x),1)) -#define UNLOCK(x) (*(x)=0) -#define CANCELPT(x) (libc.cancelpt ? libc.cancelpt((x)),0 : (void)(x),0) -#define CANCELPT_BEGIN CANCELPT(1) -#define CANCELPT_END CANCELPT(0) - -extern char **__environ; -#define environ __environ - -#undef weak_alias -#define weak_alias(old, new) \ - extern __typeof(old) new __attribute__((weak, alias(#old))) - -#undef LFS64_2 -//#define LFS64_2(x, y) weak_alias(x, y) -#define LFS64_2(x, y) extern __typeof(x) y - -#undef LFS64 -#define LFS64(x) LFS64_2(x, x##64) - -#endif diff --git a/05/musl-final/src/internal/locale_impl.h b/05/musl-final/src/internal/locale_impl.h deleted file mode 100644 index c268124..0000000 --- a/05/musl-final/src/internal/locale_impl.h +++ /dev/null @@ -1,5 +0,0 @@ -#include - -struct __locale { - int dummy; -}; diff --git a/05/musl-final/src/internal/pthread_impl.h b/05/musl-final/src/internal/pthread_impl.h deleted file mode 100644 index 615af70..0000000 --- a/05/musl-final/src/internal/pthread_impl.h +++ /dev/null @@ -1,79 +0,0 @@ -#ifndef _PTHREAD_IMPL_H -#define _PTHREAD_IMPL_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "libc.h" -#include "syscall.h" -#include "atomic.h" -#include "futex.h" - -#define pthread __pthread - -struct pthread { - struct pthread *self; - unsigned long tlsdesc[4]; - pid_t tid, pid; - int tsd_used, errno_val, *errno_ptr; - volatile int canceldisable, cancelasync, cancelpoint, cancel; - unsigned char *map_base; - size_t map_size; - void *start_arg; - void *(*start)(void *); - void *result; - jmp_buf exit_jmp_buf; - int detached; - int exitlock; - struct __ptcb *cancelbuf; - void **tsd; - pthread_attr_t attr; -}; - -#define __SU (sizeof(size_t)/sizeof(int)) - -#define _a_stacksize __u.__s[0] -#define _a_guardsize __u.__s[1] -#define _a_detach __u.__i[2*__SU+0] -#define _m_type __u.__i[0] -#define _m_lock __u.__i[1] -#define _m_waiters __u.__i[2] -#define _m_owner __u.__i[3] -#define _c_block __u.__i[0] -#define _rw_wrlock __u.__i[0] -#define _rw_readers __u.__i[1] -#define _rw_waiters __u.__i[2] -#define _rw_owner __u.__i[3] -#define _b_count __u.__i[0] -#define _b_limit __u.__i[1] -#define _b_left __u.__i[2] -#define _b_waiters __u.__i[3] - -#include "pthread_arch.h" - -#define SIGCANCEL 32 -#define SIGSYSCALL 33 -#define SIGTIMER 32 /* ?? */ - -int __set_thread_area(void *); -int __libc_sigaction(int, const struct sigaction *, struct sigaction *); -int __libc_sigprocmask(int, const sigset_t *, sigset_t *); -void __lock(volatile int *); -void __unmapself(void *, size_t); - -int __timedwait(volatile int *, int, clockid_t, const struct timespec *, int); -void __wait(volatile int *, volatile int *, int, int); -void __wake(volatile int *, int, int); - -#define DEFAULT_STACK_SIZE (16384-PAGE_SIZE) -#define DEFAULT_GUARD_SIZE PAGE_SIZE - -#endif diff --git a/05/musl-final/src/internal/stdio_impl.h b/05/musl-final/src/internal/stdio_impl.h deleted file mode 100644 index 1e9159f..0000000 --- a/05/musl-final/src/internal/stdio_impl.h +++ /dev/null @@ -1,100 +0,0 @@ -#ifndef _STDIO_IMPL_H -#define _STDIO_IMPL_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "syscall.h" -#include "libc.h" - -#define UNGET 4 - -#define FLOCK(f) LOCK(&f->lock) -#define FUNLOCK(f) UNLOCK(&f->lock) - -#define F_PERM 1 -#define F_NORD 4 -#define F_NOWR 8 -#define F_EOF 16 -#define F_ERR 32 - -struct __FILE_s { - unsigned flags; - unsigned char *rpos, *rstop; - unsigned char *rend, *wend; - unsigned char *wpos, *wstop; - unsigned char *wbase; - unsigned char *dummy01[3]; - unsigned char *buf; - size_t buf_size; - FILE *prev, *next; - int fd; - int pipe_pid; - long dummy2; - short dummy3; - char dummy4; - signed char lbf; - int lock; - int lockcount; - void *owner; - off_t off; - int (*flush)(FILE *); - void **wide_data; /* must be NULL */ - size_t (*read)(FILE *, unsigned char *, size_t); - size_t (*write)(FILE *, const unsigned char *, size_t); - off_t (*seek)(FILE *, off_t, int); - int mode; - int (*close)(FILE *); -}; - -size_t __stdio_read(FILE *, unsigned char *, size_t); -size_t __stdio_write(FILE *, const unsigned char *, size_t); -off_t __stdio_seek(FILE *, off_t, int); -int __stdio_close(FILE *); - -int __overflow(FILE *, int); -int __oflow(FILE *); -int __uflow(FILE *); -int __underflow(FILE *); - -int __fseeko(FILE *, off_t, int); -int __fseeko_unlocked(FILE *, off_t, int); -off_t __ftello(FILE *); -off_t __ftello_unlocked(FILE *); -size_t __fwritex(const unsigned char *, size_t, FILE *); -int __putc_unlocked(int, FILE *); - -FILE *__fdopen(int, const char *); - -extern struct ofl -{ - FILE *head; - int lock; -} __ofl; - -#define OFLLOCK() LOCK(&__ofl.lock) -#define OFLUNLOCK() UNLOCK(&__ofl.lock) -#define ofl_head (__ofl.head) - -#define feof(f) ((f)->flags & F_EOF) -#define ferror(f) ((f)->flags & F_ERR) - -/* Caller-allocated FILE * operations */ -FILE *__fopen_rb_ca(const char *, FILE *, unsigned char *, size_t); -int __fclose_ca(FILE *); - -#endif diff --git a/05/musl-final/src/internal/syscall.c b/05/musl-final/src/internal/syscall.c deleted file mode 100644 index 4f159e0..0000000 --- a/05/musl-final/src/internal/syscall.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include - -long __syscall_ret(unsigned long r) -{ - if (r >= (unsigned long)-1 - 4096) { - errno = -(long)r; - return -1; - } - return (long)r; -} diff --git a/05/musl-final/src/ipc/ftok.c b/05/musl-final/src/ipc/ftok.c deleted file mode 100644 index cd6002e..0000000 --- a/05/musl-final/src/ipc/ftok.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include - -key_t ftok(const char *path, int id) -{ - struct stat st; - if (stat(path, &st) < 0) return -1; - - return ((st.st_ino & 0xffff) | ((st.st_dev & 0xff) << 16) | ((id & 0xff) << 24)); -} diff --git a/05/musl-final/src/ipc/ipc.h b/05/musl-final/src/ipc/ipc.h deleted file mode 100644 index 9edd5ec..0000000 --- a/05/musl-final/src/ipc/ipc.h +++ /dev/null @@ -1,13 +0,0 @@ -#define IPCOP_semop 1 -#define IPCOP_semget 2 -#define IPCOP_semctl 3 -#define IPCOP_msgsnd 11 -#define IPCOP_msgrcv 12 -#define IPCOP_msgget 13 -#define IPCOP_msgctl 14 -#define IPCOP_shmat 21 -#define IPCOP_shmdt 22 -#define IPCOP_shmget 23 -#define IPCOP_shmctl 24 - -#define IPC_MODERN 0x100 diff --git a/05/musl-final/src/ipc/semctl.c b/05/musl-final/src/ipc/semctl.c deleted file mode 100644 index 7ada116..0000000 --- a/05/musl-final/src/ipc/semctl.c +++ /dev/null @@ -1,18 +0,0 @@ -#include -#include -#include "syscall.h" -#include "ipc.h" - -int semctl(int id, int num, int cmd, ...) -{ - long arg; - va_list ap; - va_start(ap, cmd); - arg = va_arg(ap, long); - va_end(ap); -#ifdef __NR_semctl - return syscall4(__NR_semctl, id, num, cmd, arg); -#else - return syscall5(__NR_ipc, IPCOP_semctl, id, num, cmd | 0x100, (long)&arg); -#endif -} diff --git a/05/musl-final/src/ipc/semget.c b/05/musl-final/src/ipc/semget.c deleted file mode 100644 index 2dcf6ea..0000000 --- a/05/musl-final/src/ipc/semget.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include "syscall.h" -#include "ipc.h" - -int semget(key_t key, int n, int fl) -{ -#ifdef __NR_semget - return syscall3(__NR_semget, key, n, fl); -#else - return syscall4(__NR_ipc, IPCOP_semget, key, n, fl); -#endif -} diff --git a/05/musl-final/src/ipc/semop.c b/05/musl-final/src/ipc/semop.c deleted file mode 100644 index 48d8a65..0000000 --- a/05/musl-final/src/ipc/semop.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include "syscall.h" -#include "ipc.h" - -int semop(int id, struct sembuf *buf, size_t n) -{ -#ifdef __NR_semop - return syscall3(__NR_semop, id, (long)buf, n); -#else - return syscall5(__NR_ipc, IPCOP_semop, id, n, 0, (long)buf); -#endif -} diff --git a/05/musl-final/src/ipc/shmat.c b/05/musl-final/src/ipc/shmat.c deleted file mode 100644 index 98a2cd4..0000000 --- a/05/musl-final/src/ipc/shmat.c +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include "syscall.h" -#include "ipc.h" - -#ifdef __NR_shmat -void *shmat(int id, const void *addr, int flag) -{ - return (void *)syscall3(__NR_shmat, id, (long)addr, flag); -} -#else -void *shmat(int id, const void *addr, int flag) -{ - unsigned long ret; - ret = syscall5(__NR_ipc, IPCOP_shmat, id, flag, (long)&addr, (long)addr); - return (ret > -(unsigned long)SHMLBA) ? (void *)ret : (void *)addr; -} -#endif diff --git a/05/musl-final/src/ipc/shmctl.c b/05/musl-final/src/ipc/shmctl.c deleted file mode 100644 index da357fa..0000000 --- a/05/musl-final/src/ipc/shmctl.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include "syscall.h" -#include "ipc.h" - -int shmctl(int id, int cmd, struct shmid_ds *buf) -{ -#ifdef __NR_shmctl - return syscall3(__NR_shmctl, id, cmd, (long)buf); -#else - return syscall4(__NR_ipc, IPCOP_shmctl, id, cmd | IPC_MODERN, (long)buf); -#endif -} diff --git a/05/musl-final/src/ipc/shmdt.c b/05/musl-final/src/ipc/shmdt.c deleted file mode 100644 index e04188f..0000000 --- a/05/musl-final/src/ipc/shmdt.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include "syscall.h" -#include "ipc.h" - -int shmdt(const void *addr) -{ -#ifdef __NR_shmdt - return syscall1(__NR_shmdt, (long)addr); -#else - return syscall2(__NR_ipc, IPCOP_shmdt, (long)addr); -#endif -} diff --git a/05/musl-final/src/ipc/shmget.c b/05/musl-final/src/ipc/shmget.c deleted file mode 100644 index 86e254a..0000000 --- a/05/musl-final/src/ipc/shmget.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include "syscall.h" -#include "ipc.h" - -int shmget(key_t key, size_t size, int flag) -{ -#ifdef __NR_shmget - return syscall3(__NR_shmget, key, size, flag); -#else - return syscall4(__NR_ipc, IPCOP_shmget, key, size, flag); -#endif -} diff --git a/05/musl-final/src/linux/brk.c b/05/musl-final/src/linux/brk.c deleted file mode 100644 index 3c2982c..0000000 --- a/05/musl-final/src/linux/brk.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "syscall.h" - -int brk(void *end) -{ - return -(syscall1(__NR_brk, (long)end) == -1); -} diff --git a/05/musl-final/src/linux/chroot.c b/05/musl-final/src/linux/chroot.c deleted file mode 100644 index 81363a6..0000000 --- a/05/musl-final/src/linux/chroot.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int chroot(const char *path) -{ - return syscall1(__NR_chroot, (long)path); -} diff --git a/05/musl-final/src/linux/daemon.c b/05/musl-final/src/linux/daemon.c deleted file mode 100644 index afb8019..0000000 --- a/05/musl-final/src/linux/daemon.c +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include - -int daemon(int nochdir, int noclose) -{ - if (!nochdir && chdir("/")) - return -1; - if (!noclose) { - int fd, failed = 0; - if ((fd = open("/dev/null", O_RDWR)) < 0) return -1; - if (dup2(fd, 0) < 0 || dup2(fd, 1) < 0 || dup2(fd, 2) < 0) - failed++; - if (fd > 2) close(fd); - if (failed) return -1; - } - - switch(fork()) { - case 0: break; - case -1: return -1; - default: _exit(0); - } - - if (setsid() < 0) return -1; - - switch(fork()) { - case 0: break; - case -1: return -1; - default: _exit(0); - } - - return 0; -} diff --git a/05/musl-final/src/linux/epoll_create.c b/05/musl-final/src/linux/epoll_create.c deleted file mode 100644 index c9dea8c..0000000 --- a/05/musl-final/src/linux/epoll_create.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int epoll_create(int size) -{ - return syscall1(__NR_epoll_create, size); -} diff --git a/05/musl-final/src/linux/epoll_create1.c b/05/musl-final/src/linux/epoll_create1.c deleted file mode 100644 index 2e82e99..0000000 --- a/05/musl-final/src/linux/epoll_create1.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int epoll_create1(int flags) -{ - return syscall1(__NR_epoll_create1, flags); -} diff --git a/05/musl-final/src/linux/epoll_ctl.c b/05/musl-final/src/linux/epoll_ctl.c deleted file mode 100644 index 4214f40..0000000 --- a/05/musl-final/src/linux/epoll_ctl.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int epoll_ctl(int fd, int op, int fd2, struct epoll_event *ev) -{ - return syscall4(__NR_epoll_ctl, fd, op, fd2, (long)ev); -} diff --git a/05/musl-final/src/linux/epoll_pwait.c b/05/musl-final/src/linux/epoll_pwait.c deleted file mode 100644 index 5aaacba..0000000 --- a/05/musl-final/src/linux/epoll_pwait.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int epoll_pwait(int fd, struct epoll_event *ev, int cnt, int to, const sigset_t *sigs) -{ - return syscall6(__NR_epoll_pwait, fd, (long)ev, cnt, to, (long)sigs, 8); -} diff --git a/05/musl-final/src/linux/epoll_wait.c b/05/musl-final/src/linux/epoll_wait.c deleted file mode 100644 index 8a68ebd..0000000 --- a/05/musl-final/src/linux/epoll_wait.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int epoll_wait(int fd, struct epoll_event *ev, int cnt, int to) -{ - return syscall4(__NR_epoll_wait, fd, (long)ev, cnt, to); -} diff --git a/05/musl-final/src/linux/getdtablesize.c b/05/musl-final/src/linux/getdtablesize.c deleted file mode 100644 index 623a6af..0000000 --- a/05/musl-final/src/linux/getdtablesize.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include - -int getdtablesize(void) -{ - struct rlimit rl; - getrlimit(RLIMIT_NOFILE, &rl); - return rl.rlim_max < INT_MAX ? rl.rlim_max : INT_MAX; -} diff --git a/05/musl-final/src/linux/gethostid.c b/05/musl-final/src/linux/gethostid.c deleted file mode 100644 index ea65611..0000000 --- a/05/musl-final/src/linux/gethostid.c +++ /dev/null @@ -1,4 +0,0 @@ -long gethostid() -{ - return 0; -} diff --git a/05/musl-final/src/linux/getopt_long.c b/05/musl-final/src/linux/getopt_long.c deleted file mode 100644 index d80cd1b..0000000 --- a/05/musl-final/src/linux/getopt_long.c +++ /dev/null @@ -1,52 +0,0 @@ -#define _GNU_SOURCE -#include -#include -#include - -static int __getopt_long(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx, int longonly) -{ - if (optind >= argc || !argv[optind] || argv[optind][0] != '-') return -1; - if ((longonly && argv[optind][1]) || - (argv[optind][1] == '-' && argv[optind][2])) - { - int i; - for (i=0; longopts[i].name; i++) { - const char *name = longopts[i].name; - char *opt = argv[optind]+1; - if (*opt == '-') opt++; - while (*name && *name++ == *opt++); - if (*name || (*opt && *opt != '=')) continue; - if (*opt == '=') { - if (!longopts[i].has_arg) continue; - optarg = opt+1; - } else { - if (longopts[i].has_arg == required_argument) { - if (!(optarg = argv[++optind])) - return ':'; - } else optarg = NULL; - } - optind++; - if (idx) *idx = i; - if (longopts[i].flag) { - *longopts[i].flag = longopts[i].val; - return 0; - } - return longopts[i].val; - } - if (argv[optind][1] == '-') { - optind++; - return '?'; - } - } - return getopt(argc, argv, optstring); -} - -int getopt_long(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx) -{ - return __getopt_long(argc, argv, optstring, longopts, idx, 0); -} - -int getopt_long_only(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx) -{ - return __getopt_long(argc, argv, optstring, longopts, idx, 1); -} diff --git a/05/musl-final/src/linux/getpagesize.c b/05/musl-final/src/linux/getpagesize.c deleted file mode 100644 index 5ede652..0000000 --- a/05/musl-final/src/linux/getpagesize.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include - -int getpagesize(void) -{ - return PAGE_SIZE; -} diff --git a/05/musl-final/src/linux/getpass.c b/05/musl-final/src/linux/getpass.c deleted file mode 100644 index d439a2a..0000000 --- a/05/musl-final/src/linux/getpass.c +++ /dev/null @@ -1,39 +0,0 @@ -#include -#include -#include -#include -#include - -char *getpass(const char *prompt) -{ - int fd; - struct termios s, t; - ssize_t l; - static char password[128]; - - if ((fd = open("/dev/tty", O_RDONLY|O_NOCTTY)) < 0) fd = 0; - - tcgetattr(fd, &t); - s = t; - t.c_lflag &= ~(ECHO|ISIG); - t.c_lflag |= ICANON; - t.c_iflag &= ~(INLCR|IGNCR); - t.c_iflag |= ICRNL; - tcsetattr(fd, TCSAFLUSH, &t); - tcdrain(fd); - - fputs(prompt, stderr); - fflush(stderr); - - l = read(fd, password, sizeof password); - if (l >= 0) { - if (l > 0 && password[l-1] == '\n') l--; - password[l] = 0; - } - - tcsetattr(fd, TCSAFLUSH, &s); - - if (fd > 2) close(fd); - - return password; -} diff --git a/05/musl-final/src/linux/initgroups.c b/05/musl-final/src/linux/initgroups.c deleted file mode 100644 index ef9bc10..0000000 --- a/05/musl-final/src/linux/initgroups.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include -#include -#include - -int getgrouplist(const char *, gid_t, gid_t *, int *); -int setgroups(size_t, const gid_t *); - -int initgroups(const char *user, gid_t gid) -{ - gid_t groups[NGROUPS_MAX]; - int count; - if (getgrouplist(user, gid, groups, &count) < 0) return -1; - return setgroups(count, groups); -} diff --git a/05/musl-final/src/linux/klogctl.c b/05/musl-final/src/linux/klogctl.c deleted file mode 100644 index 976f29e..0000000 --- a/05/musl-final/src/linux/klogctl.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "syscall.h" - -int klogctl (int type, char *buf, int len) -{ - return syscall3(__NR_syslog, type, (long)buf, len); -} diff --git a/05/musl-final/src/linux/mntent.c b/05/musl-final/src/linux/mntent.c deleted file mode 100644 index e373566..0000000 --- a/05/musl-final/src/linux/mntent.c +++ /dev/null @@ -1,57 +0,0 @@ -#include -#include -#include - -FILE *setmntent(const char *name, const char *mode) -{ - return fopen(name, mode); -} - -int endmntent(FILE *f) -{ - fclose(f); - return 1; -} - -struct mntent *getmntent(FILE *f) -{ - static char linebuf[256]; - static struct mntent mnt; - int cnt, n[8]; - - mnt.mnt_freq = 0; - mnt.mnt_passno = 0; - - do { - fgets(linebuf, sizeof linebuf, f); - if (feof(f)) return NULL; - cnt = sscanf(linebuf, " %n%*s%n %n%*s%n %n%*s%n %n%*s%n %d %d", - n, n+1, n+2, n+3, n+4, n+5, n+6, n+7, - &mnt.mnt_freq, &mnt.mnt_passno); - } while (cnt >= 8 && linebuf[n[0]] != '#'); - - linebuf[n[1]] = 0; - linebuf[n[3]] = 0; - linebuf[n[5]] = 0; - linebuf[n[7]] = 0; - - mnt.mnt_fsname = linebuf+n[0]; - mnt.mnt_dir = linebuf+n[2]; - mnt.mnt_type = linebuf+n[4]; - mnt.mnt_opts = linebuf+n[6]; - - return &mnt; -} - -int addmntent(FILE *f, const struct mntent *mnt) -{ - fseek(f, 0, SEEK_END); - return fprintf(f, "%s\t%s\t%s\t%s\t%d\t%d\n", - mnt->mnt_fsname, mnt->mnt_dir, mnt->mnt_type, mnt->mnt_opts, - mnt->mnt_freq, mnt->mnt_passno) < 0; -} - -char *hasmntopt(const struct mntent *mnt, const char *opt) -{ - return strstr(mnt->mnt_opts, opt); -} diff --git a/05/musl-final/src/linux/mount.c b/05/musl-final/src/linux/mount.c deleted file mode 100644 index 8e3cc12..0000000 --- a/05/musl-final/src/linux/mount.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int mount(const char *special, const char *dir, const char *fstype, unsigned long flags, const void *data) -{ - return syscall5(__NR_mount, (long)special, (long)dir, (long)fstype, flags, (long)data); -} diff --git a/05/musl-final/src/linux/prctl.c b/05/musl-final/src/linux/prctl.c deleted file mode 100644 index d551683..0000000 --- a/05/musl-final/src/linux/prctl.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include -#include "syscall.h" - -int prctl(int op, ...) -{ - unsigned long x[4]; - int i; - va_list ap; - va_start(ap, op); - for (i=0; i<4; i++) x[i] = va_arg(ap, unsigned long); - return syscall5(__NR_prctl, op, x[0], x[1], x[2], x[3]); -} diff --git a/05/musl-final/src/linux/reboot.c b/05/musl-final/src/linux/reboot.c deleted file mode 100644 index 68830d8..0000000 --- a/05/musl-final/src/linux/reboot.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include - -int reboot(int type) -{ - errno = ENOSYS; - return -1; -} diff --git a/05/musl-final/src/linux/sbrk.c b/05/musl-final/src/linux/sbrk.c deleted file mode 100644 index 56f60d1..0000000 --- a/05/musl-final/src/linux/sbrk.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -void *sbrk(ptrdiff_t inc) -{ - return (void *)syscall1(__NR_brk, syscall1(__NR_brk, 0)+inc); -} diff --git a/05/musl-final/src/linux/sendfile.c b/05/musl-final/src/linux/sendfile.c deleted file mode 100644 index bfbc40a..0000000 --- a/05/musl-final/src/linux/sendfile.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -ssize_t sendfile(int out_fd, int in_fd, off_t *ofs, size_t count) -{ - return syscall4(__NR_sendfile, out_fd, in_fd, (long)ofs, count); -} - -LFS64(sendfile); diff --git a/05/musl-final/src/linux/setgroups.c b/05/musl-final/src/linux/setgroups.c deleted file mode 100644 index 4d57801..0000000 --- a/05/musl-final/src/linux/setgroups.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int setgroups(int count, const gid_t list[]) -{ - return syscall2(__NR_setgroups, count, (long)list); -} diff --git a/05/musl-final/src/linux/sethostname.c b/05/musl-final/src/linux/sethostname.c deleted file mode 100644 index c94325e..0000000 --- a/05/musl-final/src/linux/sethostname.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int sethostname(const char *name, size_t len) -{ - return syscall2(__NR_sethostname, (long)name, len); -} diff --git a/05/musl-final/src/linux/settimeofday.c b/05/musl-final/src/linux/settimeofday.c deleted file mode 100644 index bd7e410..0000000 --- a/05/musl-final/src/linux/settimeofday.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int settimeofday(const struct timeval *tv, void *tz) -{ - return syscall2(__NR_settimeofday, (long)tv, 0); -} diff --git a/05/musl-final/src/linux/signalfd.c b/05/musl-final/src/linux/signalfd.c deleted file mode 100644 index ecda263..0000000 --- a/05/musl-final/src/linux/signalfd.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int signalfd(int fd, const sigset_t *sigs, int flags) -{ - return syscall3(__NR_signalfd, fd, (long)sigs, 8); -} diff --git a/05/musl-final/src/linux/stime.c b/05/musl-final/src/linux/stime.c deleted file mode 100644 index ec3ba82..0000000 --- a/05/musl-final/src/linux/stime.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int stime(time_t *t) -{ - struct timeval tv = { .tv_sec = *t, .tv_usec = 0 }; - return settimeofday(&tv, (void *)0); -} diff --git a/05/musl-final/src/linux/swapoff.c b/05/musl-final/src/linux/swapoff.c deleted file mode 100644 index 4f19823..0000000 --- a/05/musl-final/src/linux/swapoff.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int swapoff(const char *path) -{ - return syscall1(__NR_swapoff, (long)path); -} diff --git a/05/musl-final/src/linux/swapon.c b/05/musl-final/src/linux/swapon.c deleted file mode 100644 index 5c75247..0000000 --- a/05/musl-final/src/linux/swapon.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int swapon(const char *path, int flags) -{ - return syscall2(__NR_swapon, (long)path, flags); -} diff --git a/05/musl-final/src/linux/sysinfo.c b/05/musl-final/src/linux/sysinfo.c deleted file mode 100644 index c61b7aa..0000000 --- a/05/musl-final/src/linux/sysinfo.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "syscall.h" - -struct sysinfo; - -int sysinfo(struct sysinfo *info) -{ - return syscall1(__NR_sysinfo, (long)info); -} diff --git a/05/musl-final/src/linux/umount.c b/05/musl-final/src/linux/umount.c deleted file mode 100644 index f709b33..0000000 --- a/05/musl-final/src/linux/umount.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int umount(const char *special) -{ - return syscall2(__NR_umount2, (long)special, 0); -} diff --git a/05/musl-final/src/linux/umount2.c b/05/musl-final/src/linux/umount2.c deleted file mode 100644 index ff0803c..0000000 --- a/05/musl-final/src/linux/umount2.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int umount2(const char *special, int flags) -{ - return syscall2(__NR_umount2, (long)special, flags); -} diff --git a/05/musl-final/src/linux/utimes.c b/05/musl-final/src/linux/utimes.c deleted file mode 100644 index 59ee1a8..0000000 --- a/05/musl-final/src/linux/utimes.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include "syscall.h" - -int utimes(const char *path, const struct timeval times[2]) -{ - long ktimes[2]; - if (times) { - ktimes[0] = times[0].tv_sec; - ktimes[1] = times[1].tv_sec; - } - return syscall2(__NR_utime, (long)path, times ? (long)ktimes : 0); -} diff --git a/05/musl-final/src/linux/wait3.c b/05/musl-final/src/linux/wait3.c deleted file mode 100644 index d1d91b0..0000000 --- a/05/musl-final/src/linux/wait3.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include -#include "syscall.h" - -pid_t wait4(pid_t, int *, int, struct rusage *); - -pid_t wait3(int *status, int options, struct rusage *usage) -{ - return wait4(-1, status, options, usage); -} diff --git a/05/musl-final/src/linux/wait4.c b/05/musl-final/src/linux/wait4.c deleted file mode 100644 index 5dd505a..0000000 --- a/05/musl-final/src/linux/wait4.c +++ /dev/null @@ -1,18 +0,0 @@ -#include -#include -#include -#include "syscall.h" - -pid_t wait4(pid_t pid, int *status, int options, struct rusage *usage) -{ - pid_t ret = syscall4(__NR_wait4, pid, (long)status, options, (long)usage); - /* Fixup kernel time_t... */ - if (usage) { - long kusage[4]; - memcpy(kusage, usage, sizeof kusage); - memmove((struct timeval *)usage + 2, (long *)usage + 4, sizeof *usage - 2*sizeof(struct timeval)); - usage->ru_utime = (struct timeval){ kusage[0], kusage[1] }; - usage->ru_stime = (struct timeval){ kusage[2], kusage[3] }; - } - return ret; -} diff --git a/05/musl-final/src/locale/catclose.c b/05/musl-final/src/locale/catclose.c deleted file mode 100644 index 02cd3e5..0000000 --- a/05/musl-final/src/locale/catclose.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int catclose (nl_catd catd) -{ - return 0; -} diff --git a/05/musl-final/src/locale/catgets.c b/05/musl-final/src/locale/catgets.c deleted file mode 100644 index bbee898..0000000 --- a/05/musl-final/src/locale/catgets.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -char *catgets (nl_catd catd, int set_id, int msg_id, const char *s) -{ - return (char *)s; -} diff --git a/05/musl-final/src/locale/catopen.c b/05/musl-final/src/locale/catopen.c deleted file mode 100644 index 4423c4d..0000000 --- a/05/musl-final/src/locale/catopen.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -nl_catd catopen (const char *name, int oflag) -{ - return (nl_catd)-1; -} diff --git a/05/musl-final/src/locale/duplocale.c b/05/musl-final/src/locale/duplocale.c deleted file mode 100644 index dd445d4..0000000 --- a/05/musl-final/src/locale/duplocale.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include -#include "locale_impl.h" - -locale_t duplocale(locale_t old) -{ - locale_t new; - new = calloc(1, sizeof *new); - if (new) memcpy(new, old, sizeof *new); - return new; -} diff --git a/05/musl-final/src/locale/freelocale.c b/05/musl-final/src/locale/freelocale.c deleted file mode 100644 index 4e089f2..0000000 --- a/05/musl-final/src/locale/freelocale.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "locale_impl.h" - -void freelocale(locale_t l) -{ - free(l); -} diff --git a/05/musl-final/src/locale/iconv.c b/05/musl-final/src/locale/iconv.c deleted file mode 100644 index ce2c364..0000000 --- a/05/musl-final/src/locale/iconv.c +++ /dev/null @@ -1,568 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#define UTF_32BE 000 -#define UTF_16LE 001 -#define UTF_16BE 002 -#define UTF_32LE 003 -#define UCS2BE 004 -#define UCS2LE 005 -#define WCHAR_T 007 - -#define US_ASCII 021 -#define UTF_8 022 -#define LATIN_9 024 -#define TIS_620 025 -#define JIS_0201 026 - -#define EUC 031 -#define EUC_TW 032 -#define SHIFT_JIS 033 -#define BIG5 034 -#define GBK 035 - -/* FIXME: these are not implemented yet - * EUC: A1-FE A1-FE - * GBK: 81-FE 40-7E,80-FE - * Big5: A1-FE 40-7E,A1-FE - */ - -/* Definitions of charmaps. Each charmap consists of: - * 1. Empty-string-terminated list of null-terminated aliases. - * 2. Special type code or bits per character. - * 3. Number of elided entries (128 for specials). - * 4. Character table (size determined by fields 2 and 3). */ - -static const unsigned char charmaps[] = -"utf8\0\0\022\x80" -"wchart\0\0\007\x80" - -"ucs2\0ucs2be\0\0\004\x80" -"ucs2le\0\0\005\x80" - -"utf16\0utf16be\0\0\002\x80" -"utf16le\0\0\001\x80" - -"ucs4\0ucs4be\0utf32\0utf32be\0\0\000\x80" -"ucs4le\0utf32le\0\0\003\x80" - -"ascii\0iso646\0usascii\0\0\021\x80" -"latin1\0iso88591\0\0\x09\x80" -"latin9\0iso885915\0\0\024\x80" -"tis620\0iso885911\0\0\025\x80" -"jis0201\0\0\026\x80" - -"iso88592\0\0\x0a\x21" -"\x04\x61\x1b\x14\x29\x3d\x69\x75\x0a\x2a" -"\x60\x79\x45\x56\x5e\xad\xf4\xb5\x17\x2c" -"\x05\x6d\x2b\x14\x2d\x3e\x6d\x75\x2c\x2e" -"\x61\x7d\x55\x96\x5e\xdd\xfa\xc5\x17\x55" -"\xc1\x08\x23\x10\x31\x39\x19\x74\x0c\x43" -"\xc9\x60\xb4\x8c\x46\xcd\x38\xe3\x10\x44" -"\x43\x1d\x35\x0d\x35\x50\x59\x73\x0d\x56" -"\x6e\x69\x03\x17\x37\xdd\x88\xf5\x4d\x55" -"\xe1\x88\x33\x10\x39\x3a\x1d\x74\x4e\x43" -"\xe9\x64\xb4\xce\x46\xed\xb8\xf3\x50\x44" -"\x44\x21\x35\x0f\x3d\x51\xd9\x73\x4f\x56" -"\x6f\xe9\x13\x17\x3f\xfd\x8c\x95\x2d" - -"iso88593\0\0\x0a\x21" -"\x26\x61\x3b\x0a\x29\x00\x90\x74\x0a\x2a" -"\x30\x79\xe5\x11\x4d\xad\x00\xb0\x17\x2c" -"\x27\xc9\x32\x0b\x2d\xb5\x94\x74\x0b\x2e" -"\x31\x7d\xf5\x51\x4d\xbd\x00\xc0\x17\x30" -"\xc1\x08\x03\x00\x31\x0a\x21\x74\x0c\x32" -"\xc9\x28\xb3\x0c\x33\xcd\x38\xf3\x0c\x00" -"\xd1\x48\x33\x0d\x35\x20\x59\x73\x0d\x47" -"\xd9\x68\xb3\x0d\x37\x6c\x71\xf5\x0d\x38" -"\xe1\x88\x03\x00\x39\x0b\x25\x74\x0e\x3a" -"\xe9\xa8\xb3\x0e\x3b\xed\xb8\xf3\x0e\x00" -"\xf1\xc8\x33\x0f\x3d\x21\xd9\x73\x4f\x47" -"\xf9\xe8\xb3\x0f\x3f\x6d\x75\x95\x2d" - -"iso88594\0\0\x0a\x21" -"\x04\xe1\x64\x15\x29\x28\xed\x74\x0a\x2a" -"\x60\x49\x24\x92\x59\xad\xf4\xf5\x0a\x2c" -"\x05\x6d\x7b\x15\x2d\x29\xf1\x74\x2c\x2e" -"\x61\x4d\x34\xd2\x59\x4a\xf9\xb5\x14\x40" -"\xc1\x08\x33\x0c\x31\xc5\x18\xe3\x12\x43" -"\xc9\x60\xb4\x8c\x45\xcd\x38\xa3\x12\x44" -"\x45\x31\x65\x13\x35\xd5\x58\x73\x0d\x36" -"\x72\x69\xb3\x0d\x37\x68\xa9\xf5\x4d\x40" -"\xe1\x88\x33\x0e\x39\xe5\x98\xf3\x52\x43" -"\xe9\x64\xb4\xce\x45\xed\xb8\xb3\x52\x44" -"\x46\x35\x75\x13\x3d\xf5\xd8\x73\x0f\x3e" -"\x73\xe9\xb3\x0f\x3f\x69\xad\x95\x2d" - -"iso88595\0\0\x0e\x21" -"\x01\x84\x00\x31\x40\x10\x10\x05\x84\x01" -"\x71\x40\x20\x10\x09\x84\x02\xb1\x40\x30" -"\x10\xad\x80\x03\xf1\x40\x40\x10\x11\x84" -"\x04\x31\x41\x50\x10\x15\x84\x05\x71\x41" -"\x60\x10\x19\x84\x06\xb1\x41\x70\x10\x1d" -"\x84\x07\xf1\x41\x80\x10\x21\x84\x08\x31" -"\x42\x90\x10\x25\x84\x09\x71\x42\xa0\x10" -"\x29\x84\x0a\xb1\x42\xb0\x10\x2d\x84\x0b" -"\xf1\x42\xc0\x10\x31\x84\x0c\x31\x43\xd0" -"\x10\x35\x84\x0d\x71\x43\xe0\x10\x39\x84" -"\x0e\xb1\x43\xf0\x10\x3d\x84\x0f\xf1\x43" -"\x00\x11\x41\x84\x10\x31\x44\x10\x11\x45" -"\x84\x11\x71\x44\x20\x11\x49\x84\x12\xb1" -"\x44\x30\x11\x4d\x84\x13\xf1\x44\x58\x84" -"\x51\x84\x14\x31\x45\x50\x11\x55\x84\x15" -"\x71\x45\x60\x11\x59\x84\x16\xb1\x45\x70" -"\x11\xa7\x80\x17\xf1\x45\x00" - -"iso88596\0\0\x0b\x21" -"\x00\x00\x00\x00\x48\x01\x00\x00\x00\x00" -"\x00\x00\x00\x00\x00\x18\xdc\x0a\x00\x00" -"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -"\x00\x00\x00\x00\x00\xc0\x86\x01\x00\x00" -"\x00\x7c\x18\x00\x21\x16\xf1\x88\x49\x5c" -"\x62\x13\x9f\x18\xc5\x29\x56\xf1\x8a\x59" -"\xdc\x62\x17\xbf\x18\xc6\x31\x96\xf1\x8c" -"\x69\x5c\x63\x1b\xdf\x18\xc7\x39\xd6\x31" -"\x00\x00\x00\x00\x00\x00\x00\xc8\x41\x16" -"\xf2\x90\x89\x5c\x64\x23\x1f\x19\xc9\x49" -"\x56\xf2\x92\x99\xdc\x64\x27\x3f\x19\xca" -"\x51\x96\x32\x00\x00\x00\x00\x00\x00\x00" -"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -"\x00" - -"iso88597\0\0\x0e\x21" -"\x18\x60\x06\x38\x0a\xb0\x82\xaf\xa0\x29" -"\x70\x0a\xa0\x02\xa9\x80\xde\xb0\x0a\xb0" -"\x02\xad\x00\x00\x50\x01\xc2\x02\xb1\x80" -"\x2c\x30\x0b\x10\x0e\x85\x83\xe1\x70\x0b" -"\x20\x0e\x89\x83\xe2\xb0\x0b\x30\x0e\xbd" -"\x80\xe3\xf0\x38\x40\x0e\x91\x83\xe4\x30" -"\x39\x50\x0e\x95\x83\xe5\x70\x39\x60\x0e" -"\x99\x83\xe6\xb0\x39\x70\x0e\x9d\x83\xe7" -"\xf0\x39\x80\x0e\xa1\x03\x00\x30\x3a\x90" -"\x0e\xa5\x83\xe9\x70\x3a\xa0\x0e\xa9\x83" -"\xea\xb0\x3a\xb0\x0e\xad\x83\xeb\xf0\x3a" -"\xc0\x0e\xb1\x83\xec\x30\x3b\xd0\x0e\xb5" -"\x83\xed\x70\x3b\xe0\x0e\xb9\x83\xee\xb0" -"\x3b\xf0\x0e\xbd\x83\xef\xf0\x3b\x00\x0f" -"\xc1\x83\xf0\x30\x3c\x10\x0f\xc5\x83\xf1" -"\x70\x3c\x20\x0f\xc9\x83\xf2\xb0\x3c\x30" -"\x0f\xcd\x83\xf3\x00\x00\x00" - -"iso88598\0\0\x0e\x21" -"\x00\x80\x28\x30\x0a\x90\x02\xa5\x80\x29" -"\x70\x0a\xa0\x02\xa9\xc0\x35\xb0\x0a\xb0" -"\x02\xad\x80\x2b\xf0\x0a\xc0\x02\xb1\x80" -"\x2c\x30\x0b\xd0\x02\xb5\x80\x2d\x70\x0b" -"\xe0\x02\xb9\xc0\x3d\xb0\x0b\xf0\x02\xbd" -"\x80\x2f\x00\x00\x00\x00\x00\x00\x00\x00" -"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -"\x00\x00\x00\x00\x00\x00\x00\x00\x70\x01" -"\x42\x17\xd1\x85\x74\x31\x5d\x50\x17\xd5" -"\x85\x75\x71\x5d\x60\x17\xd9\x85\x76\xb1" -"\x5d\x70\x17\xdd\x85\x77\xf1\x5d\x80\x17" -"\xe1\x85\x78\x31\x5e\x90\x17\xe5\x85\x79" -"\x71\x5e\xa0\x17\xe9\x85\x7a\x01\x00\x00" -"\x00\x0e\xe0\x03\x08\x00\x00" - -"iso88599\0\0\x09\x50" -"\x1e\xa3\x49\x9b\x46\xad\x9a\xb5\x6b\xd8" -"\xb2\x69\xdb\xc6\x0d\xa6\xd7\x6f\xe0\xc2" -"\x89\x1b\x47\xae\x9c\xb9\x73\xe8\xd2\xa9" -"\x5b\xc7\xae\x9d\xbb\x77\x1f\xe3\xc9\x9b" -"\x47\xaf\x9e\xbd\x7b\xf8\xf2\xe9\xdb\xc7" -"\x2f\xe6\xd7\x7f" - -"iso885910\0\0\x0e\x21" -"\x04\x81\x44\x20\x12\xa8\x04\x28\x81\x4d" -"\x70\x0a\xec\x04\x10\x01\x58\x60\x16\xf4" -"\x05\xad\x80\x5a\xa0\x14\xc0\x02\x05\xc1" -"\x44\x30\x12\xac\x04\x29\xc1\x4d\x70\x0b" -"\xf0\x04\x11\x41\x58\x70\x16\xf8\x05\x15" -"\xe0\x5a\xb0\x14\x00\x04\xc1\x80\x30\x30" -"\x0c\x10\x03\xc5\x80\x31\xe0\x12\x30\x04" -"\xc9\x00\x46\xb0\x0c\x58\x04\xcd\x80\x33" -"\xf0\x0c\x40\x03\x45\x01\x53\x30\x0d\x50" -"\x03\xd5\x80\x35\x80\x16\x60\x03\x72\x81" -"\x36\xb0\x0d\x70\x03\xdd\x80\x37\xf0\x0d" -"\x04\x04\xe1\x80\x38\x30\x0e\x90\x03\xe5" -"\x80\x39\xf0\x12\x34\x04\xe9\x40\x46\xb0" -"\x0e\x5c\x04\xed\x80\x3b\xf0\x0e\xc0\x03" -"\x46\x41\x53\x30\x0f\xd0\x03\xf5\x80\x3d" -"\x90\x16\xe0\x03\x73\x81\x3e\xb0\x0f\xf0" -"\x03\xfd\x80\x3f\x80\x13\x00" - -"iso885913\0\0\x0e\x21" -"\x1d\xa0\x28\x30\x0a\x90\x02\x1e\xa0\x29" -"\x70\x0a\x60\x03\xa9\x80\x55\xb0\x0a\xb0" -"\x02\xad\x80\x2b\x60\x0c\xc0\x02\xb1\x80" -"\x2c\x30\x0b\x70\x80\xb5\x80\x2d\x70\x0b" -"\xe0\x03\xb9\xc0\x55\xb0\x0b\xf0\x02\xbd" -"\x80\x2f\x60\x0e\x10\x04\x2e\x01\x40\x60" -"\x10\x10\x03\xc5\x00\x46\x20\x11\x30\x04" -"\xc9\x40\x5e\x60\x11\x88\x04\x36\x81\x4a" -"\xb0\x13\x80\x05\x43\x41\x51\x30\x0d\x30" -"\x05\xd5\x80\x35\x70\x0d\xc8\x05\x41\x81" -"\x56\xa0\x16\x70\x03\x7b\x41\x5f\xf0\x0d" -"\x14\x04\x2f\x41\x40\x70\x10\x90\x03\xe5" -"\x40\x46\x30\x11\x34\x04\xe9\x80\x5e\x70" -"\x11\x8c\x04\x37\xc1\x4a\xc0\x13\x84\x05" -"\x44\x81\x51\x30\x0f\x34\x05\xf5\x80\x3d" -"\x70\x0f\xcc\x05\x42\xc1\x56\xb0\x16\xf0" -"\x03\x7c\x81\x5f\x90\x01\x02" - -"iso885914\0\0\x0d\x21" -"\x02\x7e\xc0\x8f\x02\x85\xb0\x10\x14\xfc" -"\x29\x00\xf4\xa9\x40\xd0\x2f\x78\x79\xdf" -"\x0a\x5c\x01\x5e\xf0\xf0\x1f\x1e\x24\x84" -"\x04\x20\x1f\xe4\x6d\x81\x95\x0f\xf4\x57" -"\x7e\xd0\x83\xf9\x79\x4f\xe8\x0b\x7d\x98" -"\x07\x06\xc1\x40\x18\x0c\x03\x62\x50\x0c" -"\x8c\xc1\x31\x40\x06\xc9\x40\x19\x2c\x03" -"\x66\xd0\x0c\x9c\xc1\x33\xa0\x0b\xd1\x40" -"\x1a\x4c\x03\x6a\x50\x0d\xac\x81\x9a\xc7" -"\x06\xd9\x40\x1b\x6c\x03\x6e\xd0\x0d\xec" -"\xc2\x37\x00\x07\xe1\x40\x1c\x8c\x03\x72" -"\x50\x0e\xcc\xc1\x39\x40\x07\xe9\x40\x1d" -"\xac\x03\x76\xd0\x0e\xdc\xc1\x3b\xa8\x0b" -"\xf1\x40\x1e\xcc\x03\x7a\x50\x0f\xec\xc1" -"\x9a\xc7\x07\xf9\x40\x1f\xec\x03\x7e\xd0" -"\x0f\xee\xc2\x3f\x00" - -"iso885916\0\0\x0e\x21" -"\x04\x41\x41\x10\x14\xb0\x82\x1e\x20\x58" -"\x70\x0a\x84\x05\xa9\x00\x86\xb0\x0a\xe4" -"\x05\xad\x80\x5e\xb0\x17\xc0\x02\xb1\x00" -"\x43\x20\x14\xf4\x05\x1d\xa0\x2d\x70\x0b" -"\xf8\x05\x0d\x41\x86\xb0\x0b\x48\x05\x53" -"\x01\x5e\xc0\x17\x00\x03\xc1\x80\x30\x20" -"\x10\x10\x03\x06\x81\x31\x70\x0c\x20\x03" -"\xc9\x80\x32\xb0\x0c\x30\x03\xcd\x80\x33" -"\xf0\x0c\x40\x04\x43\x81\x34\x30\x0d\x50" -"\x03\x50\x81\x35\xa0\x15\xc0\x05\xd9\x80" -"\x36\xb0\x0d\x70\x03\x18\x81\x86\xf0\x0d" -"\x80\x03\xe1\x80\x38\x30\x10\x90\x03\x07" -"\x81\x39\x70\x0e\xa0\x03\xe9\x80\x3a\xb0" -"\x0e\xb0\x03\xed\x80\x3b\xf0\x0e\x44\x04" -"\x44\x81\x3c\x30\x0f\xd0\x03\x51\x81\x3d" -"\xb0\x15\xc4\x05\xf9\x80\x3e\xb0\x0f\xf0" -"\x03\x19\xc1\x86\xf0\x0f\x00" - -"windows1252\0\0\x0e\x00" -"\xac\x20\x00\xa0\x01\x4a\x06\x1e\xa0\x09" -"\x08\x02\x86\x80\xc6\x02\x0c\x08\x16\xe4" -"\x80\x52\x01\x00\xd0\x17\x00\x00\x00\x00" -"\x06\x98\x01\x72\x80\x1d\xa0\x08\x38\x01" -"\x52\x80\xdc\x82\x48\x18\x16\xe8\x80\x53" -"\x01\x00\xe0\x17\xe0\x05\xa0\x40\x28\x20" -"\x0a\x8c\x02\xa4\x40\x29\x60\x0a\x9c\x02" -"\xa8\x40\x2a\xa0\x0a\xac\x02\xac\x40\x2b" -"\xe0\x0a\xbc\x02\xb0\x40\x2c\x20\x0b\xcc" -"\x02\xb4\x40\x2d\x60\x0b\xdc\x02\xb8\x40" -"\x2e\xa0\x0b\xec\x02\xbc\x40\x2f\xe0\x0b" -"\xfc\x02\xc0\x40\x30\x20\x0c\x0c\x03\xc4" -"\x40\x31\x60\x0c\x1c\x03\xc8\x40\x32\xa0" -"\x0c\x2c\x03\xcc\x40\x33\xe0\x0c\x3c\x03" -"\xd0\x40\x34\x20\x0d\x4c\x03\xd4\x40\x35" -"\x60\x0d\x5c\x03\xd8\x40\x36\xa0\x0d\x6c" -"\x03\xdc\x40\x37\xe0\x0d\x7c\x03\xe0\x40" -"\x38\x20\x0e\x8c\x03\xe4\x40\x39\x60\x0e" -"\x9c\x03\xe8\x40\x3a\xa0\x0e\xac\x03\xec" -"\x40\x3b\xe0\x0e\xbc\x03\xf0\x40\x3c\x20" -"\x0f\xcc\x03\xf4\x40\x3d\x60\x0f\xdc\x03" -"\xf8\x40\x3e\xa0\x0f\xec\x03\xfc\x40\x3f" -"\xe0\x0f\xfc\x03" -; - - - -static int fuzzycmp(const char *a, const char *b) -{ - for (; *a && *b; a++, b++) { - while (*a && (*a|32U)-'a'>26 && *a-'0'>10U) a++; - if ((*a|32U) != *b) return 1; - } - return *a != *b; -} - -static size_t find_charmap(const char *name) -{ - const unsigned char *s; - for (s=charmaps; *s; ) { - if (!fuzzycmp(name, s)) { - for (; *s; s+=strlen(s)+1); - return s+1-charmaps; - } - s += strlen(s)+1; - if (!*s) s += ((128-s[2])*s[1]+7)/8 + 3; - } - return -1; -} - -iconv_t iconv_open(const char *to, const char *from) -{ - size_t f, t; - - if ((t = find_charmap(to)) < 0 || (f = find_charmap(from)) < 0) { - errno = EINVAL; - return (iconv_t)-1; - } - - return (void *)(f<<16 | t); -} - -int iconv_close(iconv_t cd) -{ - return 0; -} - -static unsigned get_16(const unsigned char *s, int e) -{ - e &= 1; - return s[e]<<8 | s[1-e]; -} - -static void put_16(unsigned char *s, unsigned c, int e) -{ - e &= 1; - s[e] = c>>8; - s[1-e] = c; -} - -static unsigned get_32(const unsigned char *s, int e) -{ - return s[e]+0U<<24 | s[e^1]<<16 | s[e^2]<<8 | s[e^3]; -} - -static void put_32(unsigned char *s, unsigned c, int e) -{ - s[e^0] = c>>24; - s[e^1] = c>>16; - s[e^2] = c>>8; - s[e^3] = c; -} - - - -#define GET_MAPPING(m, i, n) ( (1<<(n))-1 & ( \ - (m)[(i)*(n)/8] >> ((n)%8*(i)%8) | \ - (m)[(i)*(n)/8+1] << 8-((n)%8*(i)%8) | \ - (m)[(i)*(n)/8+2] << 16-((n)%8*(i)%8) ) ) - -static unsigned get_mapping(const unsigned char *m, unsigned c, unsigned n) -{ - switch (n) { - default: - case 9: return m[c*9/8]>>c%8 | m[c*9/8+1]<<8-c%8 & (1<>2*c%8 | m[c*10/8+1]<<8-2*c%8 & (1< -size_t iconv(iconv_t cd0, char **in, size_t *inb, char **out, size_t *outb) -{ - size_t x=0; - unsigned long cd = (unsigned long)cd0; - unsigned to = cd & 0xffff; - unsigned from = cd >> 16; - const unsigned char *map = charmaps+from+2; - const unsigned char *tomap = charmaps+to+2; - mbstate_t st = {0}; - wchar_t wc; - unsigned c, d; - size_t k, l; - int err; - unsigned elide = map[-1] + 128; - unsigned toelide = tomap[-1] + 128; - unsigned char type = map[-2]; - unsigned char totype = tomap[-2]; - - if (!in || !*in || !*inb) return 0; - - for (; *inb; *in+=l, *inb-=l) { - c = *(unsigned char *)*in; - l = 1; - if (type < 8 || c >= 0x80) switch (type) { - case UTF_8: - l = mbrtowc_utf8(&wc, *in, *inb, &st); - if (!l) l++; - else if (l == (size_t)-1) goto ilseq; - else if (l == (size_t)-2) goto starved; - c = wc; - break; - case LATIN_9: - if ((unsigned)c - 0xa4 <= 0xbe - 0xa4) { - static const unsigned char map[] = { - 0, 0x60, 0, 0x61, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0x7d, 0, 0, 0, 0x7e, 0, 0, 0, - 0x52, 0x53, 0x78 - }; - if (c == 0xa4) c = 0x20ac; - else if (map[c-0xa5]) c = 0x100 | map[c-0xa5]; - } - break; - case TIS_620: - if (c >= 0xa1) c += 0x0e01-0xa1; - break; - case JIS_0201: - if (c >= 0xa1) - if (c <= 0xdf) c += 0xff61-0xa1; - else goto ilseq; - break; - case 9: case 10: case 11: case 13: case 14: - if (c < elide) break; - c = get_mapping(map, c-elide, type); - if (!c) { - case US_ASCII: - goto ilseq; - } - break; - case WCHAR_T: - l = sizeof(wchar_t); - if (*inb < l) goto starved; - c = *(wchar_t *)*in; - if (0) { - case UTF_32BE: - case UTF_32LE: - l = 4; - if (*inb < 4) goto starved; - c = get_32(*in, type); - } - if (c-0xd800u < 0x800u || c >= 0x110000u) goto ilseq; - break; - case UCS2BE: - case UCS2LE: - case UTF_16BE: - case UTF_16LE: - l = 2; - if (*inb < 2) goto starved; - c = get_16(*in, type); - if ((unsigned)(c-0xdc00) < 0x400) goto ilseq; - if ((unsigned)(c-0xd800) < 0x400) { - if (type-UCS2BE < 2U) goto ilseq; - l = 4; - if (*inb < 4) goto starved; - d = get_16(*in + 2, from); - if ((unsigned)(c-0xdc00) >= 0x400) goto ilseq; - c = ((c-0xd800)<<10) | (d-0xdc00); - } - break; - } - - switch (totype) { - case WCHAR_T: - if (*outb < sizeof(wchar_t)) goto toobig; - *(wchar_t *)*out = c; - *out += sizeof(wchar_t); - *outb -= sizeof(wchar_t); - break; - case UTF_8: - if (*outb < 4) { - char tmp[4]; - k = wctomb_utf8(tmp, c); - if (*outb < k) goto toobig; - memcpy(*out, tmp, k); - } else k = wctomb_utf8(*out, c); - *out += k; - *outb -= k; - break; - case TIS_620: - if (c-0xe01u <= 0xff-0xa1) - c -= 0xe01-0xa1; - else if (c >= 0xa1) - goto ascii; - goto revout; - case JIS_0201: - if (c-0xff61u <= 0xdf-0xa1) - c -= 0xff61-0xa1; - else if (c >= 0xa1) - goto ascii; - goto revout; - case LATIN_9: - if (c == 0x20ac) { - c=0xa4; - } else if (c-0x150u<=0x12 && (1<0x100 || - c-0xa5u<=0xbeu-0xa5 - && (1< 0x7f) x++, c='*'; - case 9: case 10: case 11: case 13: case 14: - if (*outb < 1) goto toobig; - if (c < toelide) { - revout: - *(*out)++ = c; - *outb -= 1; - break; - } - for (d=0; d<256-toelide; d++) { - if (c == get_mapping(tomap, d, totype)) { - c = d + toelide; - goto revout; - } - } - x++; - c = '*'; - goto revout; - case UCS2BE: - case UCS2LE: - case UTF_16BE: - case UTF_16LE: - if (c < 0x10000) { - if (*outb < 2) goto toobig; - put_16(*out, c, totype); - *out += 2; - *outb -= 2; - break; - } - if (type-UCS2BE < 2U) goto ilseq; - if (*outb < 4) goto toobig; - put_16(*out, (c>>10)|0xd800, totype); - put_16(*out + 2, (c&0x3ff)|0xdc00, totype); - *out += 4; - *outb -= 4; - break; - case UTF_32BE: - case UTF_32LE: - if (*outb < 4) goto toobig; - put_32(*out, c, totype); - *out += 4; - *outb -= 4; - break; - } - } - return x; -ilseq: - err = EILSEQ; - x = -1; - goto end; -toobig: - err = E2BIG; - goto end; -starved: - err = EINVAL; -end: - errno = err; - return x; -} diff --git a/05/musl-final/src/locale/intl.c b/05/musl-final/src/locale/intl.c deleted file mode 100644 index 964f7da..0000000 --- a/05/musl-final/src/locale/intl.c +++ /dev/null @@ -1,67 +0,0 @@ -#include -#include -#include -#include - -char *gettext(const char *msgid) -{ - return (char *) msgid; -} - -char *dgettext(const char *domainname, const char *msgid) -{ - return (char *) msgid; -} - -char *dcgettext(const char *domainname, const char *msgid, int category) -{ - return (char *) msgid; -} - -char *ngettext(const char *msgid1, const char *msgid2, unsigned long int n) -{ - return (char *) ((n == 1) ? msgid1 : msgid2); -} - -char *dngettext(const char *domainname, const char *msgid1, const char *msgid2, unsigned long int n) -{ - return (char *) ((n == 1) ? msgid1 : msgid2); -} - -char *dcngettext(const char *domainname, const char *msgid1, const char *msgid2, unsigned long int n, int category) -{ - return (char *) ((n == 1) ? msgid1 : msgid2); -} - -char *textdomain(const char *domainname) -{ - static const char default_str[] = "messages"; - - if (domainname && *domainname && strcmp(domainname, default_str)) { - errno = EINVAL; - return NULL; - } - return (char *) default_str; -} - -char *bindtextdomain(const char *domainname, const char *dirname) -{ - static const char dir[] = "/"; - - if (!domainname || !*domainname - || (dirname && ((dirname[0] != '/') || dirname[1])) - ) { - errno = EINVAL; - return NULL; - } - - return (char *) dir; -} - -char *bind_textdomain_codeset(const char *domainname, const char *codeset) -{ - if (!domainname || !*domainname || (codeset && strcasecmp(codeset, "UTF-8"))) { - errno = EINVAL; - } - return NULL; -} diff --git a/05/musl-final/src/locale/isalnum_l.c b/05/musl-final/src/locale/isalnum_l.c deleted file mode 100644 index b8a6eef..0000000 --- a/05/musl-final/src/locale/isalnum_l.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int isalnum_l(int c, locale_t l) -{ - return isalnum(c); -} diff --git a/05/musl-final/src/locale/isalpha_l.c b/05/musl-final/src/locale/isalpha_l.c deleted file mode 100644 index 2e1205c..0000000 --- a/05/musl-final/src/locale/isalpha_l.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int isalpha_l(int c, locale_t l) -{ - return isalpha(c); -} diff --git a/05/musl-final/src/locale/isblank_l.c b/05/musl-final/src/locale/isblank_l.c deleted file mode 100644 index 27479aa..0000000 --- a/05/musl-final/src/locale/isblank_l.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int isblank_l(int c, locale_t l) -{ - return isblank(c); -} diff --git a/05/musl-final/src/locale/iscntrl_l.c b/05/musl-final/src/locale/iscntrl_l.c deleted file mode 100644 index ca596fa..0000000 --- a/05/musl-final/src/locale/iscntrl_l.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int iscntrl_l(int c, locale_t l) -{ - return iscntrl(c); -} diff --git a/05/musl-final/src/locale/isdigit_l.c b/05/musl-final/src/locale/isdigit_l.c deleted file mode 100644 index c8ae7bd..0000000 --- a/05/musl-final/src/locale/isdigit_l.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int isdigit_l(int c, locale_t l) -{ - return isdigit(c); -} diff --git a/05/musl-final/src/locale/isgraph_l.c b/05/musl-final/src/locale/isgraph_l.c deleted file mode 100644 index 713a86e..0000000 --- a/05/musl-final/src/locale/isgraph_l.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int isgraph_l(int c, locale_t l) -{ - return isgraph(c); -} diff --git a/05/musl-final/src/locale/islower_l.c b/05/musl-final/src/locale/islower_l.c deleted file mode 100644 index 25ec97a..0000000 --- a/05/musl-final/src/locale/islower_l.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int islower_l(int c, locale_t l) -{ - return islower(c); -} diff --git a/05/musl-final/src/locale/isprint_l.c b/05/musl-final/src/locale/isprint_l.c deleted file mode 100644 index 79ef351..0000000 --- a/05/musl-final/src/locale/isprint_l.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int isprint_l(int c, locale_t l) -{ - return isprint(c); -} diff --git a/05/musl-final/src/locale/ispunct_l.c b/05/musl-final/src/locale/ispunct_l.c deleted file mode 100644 index 1c0bd04..0000000 --- a/05/musl-final/src/locale/ispunct_l.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int ispunct_l(int c, locale_t l) -{ - return ispunct(c); -} diff --git a/05/musl-final/src/locale/isspace_l.c b/05/musl-final/src/locale/isspace_l.c deleted file mode 100644 index e1a0efe..0000000 --- a/05/musl-final/src/locale/isspace_l.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int isspace_l(int c, locale_t l) -{ - return isspace(c); -} diff --git a/05/musl-final/src/locale/isupper_l.c b/05/musl-final/src/locale/isupper_l.c deleted file mode 100644 index 11ba703..0000000 --- a/05/musl-final/src/locale/isupper_l.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int isupper_l(int c, locale_t l) -{ - return isupper(c); -} diff --git a/05/musl-final/src/locale/isxdigit_l.c b/05/musl-final/src/locale/isxdigit_l.c deleted file mode 100644 index 68649d0..0000000 --- a/05/musl-final/src/locale/isxdigit_l.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int isxdigit_l(int c, locale_t l) -{ - return isxdigit(c); -} diff --git a/05/musl-final/src/locale/langinfo.c b/05/musl-final/src/locale/langinfo.c deleted file mode 100644 index f7f5601..0000000 --- a/05/musl-final/src/locale/langinfo.c +++ /dev/null @@ -1,58 +0,0 @@ -#include -#include - -static const char c_time[] = - "Sun\0" "Mon\0" "Tue\0" "Wed\0" "Thu\0" "Fri\0" "Sat\0" - "Sunday\0" "Monday\0" "Tuesday\0" "Wednesday\0" - "Thursday\0" "Friday\0" "Saturday\0" - "Jan\0" "Feb\0" "Mar\0" "Apr\0" "May\0" "Jun\0" - "Jul\0" "Aug\0" "Sep\0" "Oct\0" "Nov\0" "Dec\0" - "January\0" "February\0" "March\0" "April\0" - "May\0" "June\0" "July\0" "August\0" - "September\0" "October\0" "November\0" "December\0" - "AM\0" "PM\0" - "%a %b %e %T %Y\0" - "%m/%d/%y\0" - "%H:%M:%S\0" - "%I:%M:%S %p\0" - "\0" - "%m/%d/%y\0" - "0123456789" - "%a %b %e %T %Y\0" - "%H:%M:%S"; - -static const char c_messages[] = "^[yY]\0" "^[nN]"; -static const char c_numeric[] = ".\0" ""; - -const char *__langinfo(nl_item item) -{ - int cat = item >> 16; - int idx = item & 65535; - const char *str; - - if (item == CODESET) return "UTF-8"; - - switch (cat) { - case LC_NUMERIC: - if (idx > 1) return NULL; - str = c_numeric; - break; - case LC_TIME: - if (idx > 0x31) return NULL; - str = c_time; - break; - case LC_MONETARY: - if (idx > 0) return NULL; - str = ""; - break; - case LC_MESSAGES: - if (idx > 1) return NULL; - str = c_messages; - break; - default: - return NULL; - } - - for (; idx; idx--, str++) for (; *str; str++); - return str; -} diff --git a/05/musl-final/src/locale/localeconv.c b/05/musl-final/src/locale/localeconv.c deleted file mode 100644 index d79d1c0..0000000 --- a/05/musl-final/src/locale/localeconv.c +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include -#include - -struct lconv *localeconv(void) -{ - static struct lconv *posix_lconv; - if (posix_lconv) return posix_lconv; - posix_lconv = malloc(sizeof *posix_lconv); - memset(posix_lconv, -1, sizeof *posix_lconv); - posix_lconv->decimal_point = "."; - posix_lconv->thousands_sep = ""; - posix_lconv->grouping = "\xff"; - posix_lconv->int_curr_symbol = ""; //"\xc2\xa4"; - posix_lconv->currency_symbol = ""; - posix_lconv->mon_decimal_point = ""; - posix_lconv->mon_thousands_sep = ""; - posix_lconv->mon_grouping = "\xff"; - posix_lconv->positive_sign = ""; // "+"; - posix_lconv->negative_sign = ""; // "-"; - return posix_lconv; -} diff --git a/05/musl-final/src/locale/newlocale.c b/05/musl-final/src/locale/newlocale.c deleted file mode 100644 index 986e796..0000000 --- a/05/musl-final/src/locale/newlocale.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include -#include "locale_impl.h" - -locale_t newlocale(int mask, const char *name, locale_t base) -{ - if (*name && strcmp(name, "C") && strcmp(name, "POSIX")) - return 0; - if (!base) base = calloc(1, sizeof *base); - return base; -} diff --git a/05/musl-final/src/locale/nl_langinfo.c b/05/musl-final/src/locale/nl_langinfo.c deleted file mode 100644 index bb3a2c4..0000000 --- a/05/musl-final/src/locale/nl_langinfo.c +++ /dev/null @@ -1,13 +0,0 @@ -#include - -// FIXME: other items - -char *nl_langinfo(nl_item item) -{ - switch (item) { - case CODESET: - return "UTF-8"; - default: - return ""; - } -} diff --git a/05/musl-final/src/locale/setlocale.c b/05/musl-final/src/locale/setlocale.c deleted file mode 100644 index 28f29b8..0000000 --- a/05/musl-final/src/locale/setlocale.c +++ /dev/null @@ -1,9 +0,0 @@ -#include - -char *setlocale(int category, const char *locale) -{ - /* Note: plain "C" would be better, but puts some broken - * software into legacy 8-bit-codepage mode, ignoring - * the standard library's multibyte encoding */ - return "C.UTF-8"; -} diff --git a/05/musl-final/src/locale/strcoll.c b/05/musl-final/src/locale/strcoll.c deleted file mode 100644 index 30bccd6..0000000 --- a/05/musl-final/src/locale/strcoll.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int strcoll(const char *l, const char *r) -{ - return strcmp(l, r); -} diff --git a/05/musl-final/src/locale/strxfrm.c b/05/musl-final/src/locale/strxfrm.c deleted file mode 100644 index 8f12339..0000000 --- a/05/musl-final/src/locale/strxfrm.c +++ /dev/null @@ -1,9 +0,0 @@ -#include - -/* collate only by code points */ -size_t strxfrm(char *dest, const char *src, size_t n) -{ - size_t l = strlen(src); - if (n > l) strcpy(dest, src); - return l; -} diff --git a/05/musl-final/src/locale/tmp b/05/musl-final/src/locale/tmp deleted file mode 100644 index aa71779..0000000 --- a/05/musl-final/src/locale/tmp +++ /dev/null @@ -1,390 +0,0 @@ -"iso88591\0\x08\x80" -"iso88592\0\x0a\x21" -"\x04\x61\x1b\x14\x29\x3d\x69\x75\x0a\x2a" -"\x60\x79\x45\x56\x5e\xad\xf4\xb5\x17\x2c" -"\x05\x6d\x2b\x14\x2d\x3e\x6d\x75\x2c\x2e" -"\x61\x7d\x55\x96\x5e\xdd\xfa\xc5\x17\x55" -"\xc1\x08\x23\x10\x31\x39\x19\x74\x0c\x43" -"\xc9\x60\xb4\x8c\x46\xcd\x38\xe3\x10\x44" -"\x43\x1d\x35\x0d\x35\x50\x59\x73\x0d\x56" -"\x6e\x69\x03\x17\x37\xdd\x88\xf5\x4d\x55" -"\xe1\x88\x33\x10\x39\x3a\x1d\x74\x4e\x43" -"\xe9\x64\xb4\xce\x46\xed\xb8\xf3\x50\x44" -"\x44\x21\x35\x0f\x3d\x51\xd9\x73\x4f\x56" -"\x6f\xe9\x13\x17\x3f\xfd\x8c\x95\x2d" -"iso88593\0\x0a0x21" -"\x26\x61\x3b\x0a\x29\x00\x90\x74\x0a\x2a" -"\x30\x79\xe5\x11\x4d\xad\x00\xb0\x17\x2c" -"\x27\xc9\x32\x0b\x2d\xb5\x94\x74\x0b\x2e" -"\x31\x7d\xf5\x51\x4d\xbd\x00\xc0\x17\x30" -"\xc1\x08\x03\x00\x31\x0a\x21\x74\x0c\x32" -"\xc9\x28\xb3\x0c\x33\xcd\x38\xf3\x0c\x00" -"\xd1\x48\x33\x0d\x35\x20\x59\x73\x0d\x47" -"\xd9\x68\xb3\x0d\x37\x6c\x71\xf5\x0d\x38" -"\xe1\x88\x03\x00\x39\x0b\x25\x74\x0e\x3a" -"\xe9\xa8\xb3\x0e\x3b\xed\xb8\xf3\x0e\x00" -"\xf1\xc8\x33\x0f\x3d\x21\xd9\x73\x4f\x47" -"\xf9\xe8\xb3\x0f\x3f\x6d\x75\x95\x2d" -"iso88594\0\x0a\x21" -"\x04\xe1\x64\x15\x29\x28\xed\x74\x0a\x2a" -"\x60\x49\x24\x92\x59\xad\xf4\xf5\x0a\x2c" -"\x05\x6d\x7b\x15\x2d\x29\xf1\x74\x2c\x2e" -"\x61\x4d\x34\xd2\x59\x4a\xf9\xb5\x14\x40" -"\xc1\x08\x33\x0c\x31\xc5\x18\xe3\x12\x43" -"\xc9\x60\xb4\x8c\x45\xcd\x38\xa3\x12\x44" -"\x45\x31\x65\x13\x35\xd5\x58\x73\x0d\x36" -"\x72\x69\xb3\x0d\x37\x68\xa9\xf5\x4d\x40" -"\xe1\x88\x33\x0e\x39\xe5\x98\xf3\x52\x43" -"\xe9\x64\xb4\xce\x45\xed\xb8\xb3\x52\x44" -"\x46\x35\x75\x13\x3d\xf5\xd8\x73\x0f\x3e" -"\x73\xe9\xb3\x0f\x3f\x69\xad\x95\x2d" -"iso88595\0\x0d\x21" -"\x01\x84\x00\x30\x40\x10\x10\x05\x84\x01" -"\x70\x40\x20\x10\x09\x84\x02\xb0\x40\x30" -"\x10\xad\x80\x03\xf0\x40\x40\x10\x11\x84" -"\x04\x30\x41\x50\x10\x15\x84\x05\x70\x41" -"\x60\x10\x19\x84\x06\xb0\x41\x70\x10\x1d" -"\x84\x07\xf0\x41\x80\x10\x21\x84\x08\x30" -"\x42\x90\x10\x25\x84\x09\x70\x42\xa0\x10" -"\x29\x84\x0a\xb0\x42\xb0\x10\x2d\x84\x0b" -"\xf0\x42\xc0\x10\x31\x84\x0c\x30\x43\xd0" -"\x10\x35\x84\x0d\x70\x43\xe0\x10\x39\x84" -"\x0e\xb0\x43\xf0\x10\x3d\x84\x0f\xf0\x43" -"\x00\x11\x41\x84\x10\x30\x44\x10\x11\x45" -"\x84\x11\x70\x44\x20\x11\x49\x84\x12\xb0" -"\x44\x30\x11\x4d\x84\x13\xf0\x44\x58\x84" -"\x51\x84\x14\x30\x45\x50\x11\x55\x84\x15" -"\x70\x45\x60\x11\x59\x84\x16\xb0\x45\x70" -"\x11\xa7\x80\x17\xf0\x45\x00" -"iso88596\0\x0b\x21" -"\x00\x00\x00\x00\x48\x01\x00\x00\x00\x00" -"\x00\x00\x00\x00\x00\x18\xdc\x0a\x00\x00" -"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -"\x00\x00\x00\x00\x00\xc0\x86\x00\x00\x00" -"\x00\x7c\x18\x00\x21\x16\xf1\x88\x48\x5c" -"\x62\x13\x9c\x18\xc5\x29\x56\xf1\x8a\x58" -"\xdc\x62\x17\xbc\x18\xc6\x31\x96\xf1\x8c" -"\x68\x5c\x63\x1b\xdc\x18\xc7\x39\xd6\x31" -"\x00\x00\x00\x00\x00\x00\x00\xc8\x41\x16" -"\xf2\x90\x88\x5c\x64\x23\x1c\x19\xc9\x49" -"\x56\xf2\x92\x98\xdc\x64\x27\x3c\x19\xca" -"\x51\x96\x32\x00\x00\x00\x00\x00\x00\x00" -"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -"\x00" -"iso88597\0\x0d\x21" -"\x18\x60\x06\x30\x0a\xb0\x82\xaf\xa0\x29" -"\x70\x0a\xa0\x02\xa9\x80\xde\xb0\x0a\xb0" -"\x02\xad\x00\x00\x50\x01\xc0\x02\xb1\x80" -"\x2c\x30\x0b\x10\x0e\x85\x83\xe1\x70\x0b" -"\x20\x0e\x89\x83\xe2\xb0\x0b\x30\x0e\xbd" -"\x80\xe3\xf0\x38\x40\x0e\x91\x83\xe4\x30" -"\x39\x50\x0e\x95\x83\xe5\x70\x39\x60\x0e" -"\x99\x83\xe6\xb0\x39\x70\x0e\x9d\x83\xe7" -"\xf0\x39\x80\x0e\xa1\x03\x00\x30\x3a\x90" -"\x0e\xa5\x83\xe9\x70\x3a\xa0\x0e\xa9\x83" -"\xea\xb0\x3a\xb0\x0e\xad\x83\xeb\xf0\x3a" -"\xc0\x0e\xb1\x83\xec\x30\x3b\xd0\x0e\xb5" -"\x83\xed\x70\x3b\xe0\x0e\xb9\x83\xee\xb0" -"\x3b\xf0\x0e\xbd\x83\xef\xf0\x3b\x00\x0f" -"\xc1\x83\xf0\x30\x3c\x10\x0f\xc5\x83\xf1" -"\x70\x3c\x20\x0f\xc9\x83\xf2\xb0\x3c\x30" -"\x0f\xcd\x83\xf3\x00\x00\x00" -"iso88598\0\x0d\x21" -"\x00\x80\x28\x30\x0a\x90\x02\xa5\x80\x29" -"\x70\x0a\xa0\x02\xa9\xc0\x35\xb0\x0a\xb0" -"\x02\xad\x80\x2b\xf0\x0a\xc0\x02\xb1\x80" -"\x2c\x30\x0b\xd0\x02\xb5\x80\x2d\x70\x0b" -"\xe0\x02\xb9\xc0\x3d\xb0\x0b\xf0\x02\xbd" -"\x80\x2f\x00\x00\x00\x00\x00\x00\x00\x00" -"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -"\x00\x00\x00\x00\x00\x00\x00\x00\x70\x01" -"\x40\x17\xd1\x85\x74\x30\x5d\x50\x17\xd5" -"\x85\x75\x70\x5d\x60\x17\xd9\x85\x76\xb0" -"\x5d\x70\x17\xdd\x85\x77\xf0\x5d\x80\x17" -"\xe1\x85\x78\x30\x5e\x90\x17\xe5\x85\x79" -"\x70\x5e\xa0\x17\xe9\x85\x7a\x00\x00\x00" -"\x00\x0e\xe0\x03\x00\x00\x00" -"iso88599\0\x09\x50" -"\x1e\xa3\x49\x9b\x46\xad\x9a\xb5\x6b\xd8" -"\xb2\x69\xdb\xc6\x0d\xa6\xd7\x6f\xe0\xc2" -"\x89\x1b\x47\xae\x9c\xb9\x73\xe8\xd2\xa9" -"\x5b\xc7\xae\x9d\xbb\x77\x1f\xe3\xc9\x9b" -"\x47\xaf\x9e\xbd\x7b\xf8\xf2\xe9\xdb\xc7" -"\x2f\xe6\xd7\x7f" -"iso885910\0\x0d\x21" -"\x04\x81\x44\x20\x12\xa8\x04\x28\x81\x4d" -"\x70\x0a\xec\x04\x10\x01\x58\x60\x16\xf4" -"\x05\xad\x80\x5a\xa0\x14\xc0\x02\x05\xc1" -"\x44\x30\x12\xac\x04\x29\xc1\x4d\x70\x0b" -"\xf0\x04\x11\x41\x58\x70\x16\xf8\x05\x15" -"\xe0\x5a\xb0\x14\x00\x04\xc1\x80\x30\x30" -"\x0c\x10\x03\xc5\x80\x31\xe0\x12\x30\x04" -"\xc9\x00\x46\xb0\x0c\x58\x04\xcd\x80\x33" -"\xf0\x0c\x40\x03\x45\x01\x53\x30\x0d\x50" -"\x03\xd5\x80\x35\x80\x16\x60\x03\x72\x81" -"\x36\xb0\x0d\x70\x03\xdd\x80\x37\xf0\x0d" -"\x04\x04\xe1\x80\x38\x30\x0e\x90\x03\xe5" -"\x80\x39\xf0\x12\x34\x04\xe9\x40\x46\xb0" -"\x0e\x5c\x04\xed\x80\x3b\xf0\x0e\xc0\x03" -"\x46\x41\x53\x30\x0f\xd0\x03\xf5\x80\x3d" -"\x90\x16\xe0\x03\x73\x81\x3e\xb0\x0f\xf0" -"\x03\xfd\x80\x3f\x80\x13\x00" -"iso885913\0\x0d\x21" -"\x1d\xa0\x28\x30\x0a\x90\x02\x1e\xa0\x29" -"\x70\x0a\x60\x03\xa9\x80\x55\xb0\x0a\xb0" -"\x02\xad\x80\x2b\x60\x0c\xc0\x02\xb1\x80" -"\x2c\x30\x0b\x70\x80\xb5\x80\x2d\x70\x0b" -"\xe0\x03\xb9\xc0\x55\xb0\x0b\xf0\x02\xbd" -"\x80\x2f\x60\x0e\x10\x04\x2e\x01\x40\x60" -"\x10\x10\x03\xc5\x00\x46\x20\x11\x30\x04" -"\xc9\x40\x5e\x60\x11\x88\x04\x36\x81\x4a" -"\xb0\x13\x80\x05\x43\x41\x51\x30\x0d\x30" -"\x05\xd5\x80\x35\x70\x0d\xc8\x05\x41\x81" -"\x56\xa0\x16\x70\x03\x7b\x41\x5f\xf0\x0d" -"\x14\x04\x2f\x41\x40\x70\x10\x90\x03\xe5" -"\x40\x46\x30\x11\x34\x04\xe9\x80\x5e\x70" -"\x11\x8c\x04\x37\xc1\x4a\xc0\x13\x84\x05" -"\x44\x81\x51\x30\x0f\x34\x05\xf5\x80\x3d" -"\x70\x0f\xcc\x05\x42\xc1\x56\xb0\x16\xf0" -"\x03\x7c\x81\x5f\x90\x01\x00" -"iso885914\0\x0c\x21" -"\x02\x7e\xc0\x8c\x02\x85\xb0\x10\x14\xfc" -"\x29\x00\xf4\xa9\x40\xd0\x2c\x78\x79\xd0" -"\x0a\x5c\x01\x5e\xf0\xf0\x1f\x1e\x24\x84" -"\x04\x20\x10\xe4\x6c\x81\x95\x08\xf4\x57" -"\x7e\xd0\x80\xf9\x79\x40\xe8\x0a\x7d\x98" -"\x00\x06\xc1\x40\x18\x0c\x03\x62\x50\x0c" -"\x8c\xc1\x31\x40\x06\xc9\x40\x19\x2c\x03" -"\x66\xd0\x0c\x9c\xc1\x33\xa0\x0b\xd1\x40" -"\x1a\x4c\x03\x6a\x50\x0d\xac\x81\x9a\xc0" -"\x06\xd9\x40\x1b\x6c\x03\x6e\xd0\x0d\xec" -"\xc2\x37\x00\x07\xe1\x40\x1c\x8c\x03\x72" -"\x50\x0e\xcc\xc1\x39\x40\x07\xe9\x40\x1d" -"\xac\x03\x76\xd0\x0e\xdc\xc1\x3b\xa8\x0b" -"\xf1\x40\x1e\xcc\x03\x7a\x50\x0f\xec\xc1" -"\x9a\xc0\x07\xf9\x40\x1f\xec\x03\x7e\xd0" -"\x0f\xee\xc2\x3f\x00" -"iso885916\0\x0d\x21" -"\x04\x41\x41\x10\x14\xb0\x82\x1e\x20\x58" -"\x70\x0a\x84\x05\xa9\x00\x86\xb0\x0a\xe4" -"\x05\xad\x80\x5e\xb0\x17\xc0\x02\xb1\x00" -"\x43\x20\x14\xf4\x05\x1d\xa0\x2d\x70\x0b" -"\xf8\x05\x0d\x41\x86\xb0\x0b\x48\x05\x53" -"\x01\x5e\xc0\x17\x00\x03\xc1\x80\x30\x20" -"\x10\x10\x03\x06\x81\x31\x70\x0c\x20\x03" -"\xc9\x80\x32\xb0\x0c\x30\x03\xcd\x80\x33" -"\xf0\x0c\x40\x04\x43\x81\x34\x30\x0d\x50" -"\x03\x50\x81\x35\xa0\x15\xc0\x05\xd9\x80" -"\x36\xb0\x0d\x70\x03\x18\x81\x86\xf0\x0d" -"\x80\x03\xe1\x80\x38\x30\x10\x90\x03\x07" -"\x81\x39\x70\x0e\xa0\x03\xe9\x80\x3a\xb0" -"\x0e\xb0\x03\xed\x80\x3b\xf0\x0e\x44\x04" -"\x44\x81\x3c\x30\x0f\xd0\x03\x51\x81\x3d" -"\xb0\x15\xc4\x05\xf9\x80\x3e\xb0\x0f\xf0" -"\x03\x19\xc1\x86\xf0\x0f\x00" -; - - -'i','s','o','8','8','5','9','1',0, -8,128, -'i','s','o','8','8','5','9','2',0, -10, 33, -0x04, 0x61, 0x1b, 0x14, 0x29, 0x3d, 0x69, 0x75, 0x0a, 0x2a, -0x60, 0x79, 0x45, 0x56, 0x5e, 0xad, 0xf4, 0xb5, 0x17, 0x2c, -0x05, 0x6d, 0x2b, 0x14, 0x2d, 0x3e, 0x6d, 0x75, 0x2c, 0x2e, -0x61, 0x7d, 0x55, 0x96, 0x5e, 0xdd, 0xfa, 0xc5, 0x17, 0x55, -0xc1, 0x08, 0x23, 0x10, 0x31, 0x39, 0x19, 0x74, 0x0c, 0x43, -0xc9, 0x60, 0xb4, 0x8c, 0x46, 0xcd, 0x38, 0xe3, 0x10, 0x44, -0x43, 0x1d, 0x35, 0x0d, 0x35, 0x50, 0x59, 0x73, 0x0d, 0x56, -0x6e, 0x69, 0x03, 0x17, 0x37, 0xdd, 0x88, 0xf5, 0x4d, 0x55, -0xe1, 0x88, 0x33, 0x10, 0x39, 0x3a, 0x1d, 0x74, 0x4e, 0x43, -0xe9, 0x64, 0xb4, 0xce, 0x46, 0xed, 0xb8, 0xf3, 0x50, 0x44, -0x44, 0x21, 0x35, 0x0f, 0x3d, 0x51, 0xd9, 0x73, 0x4f, 0x56, -0x6f, 0xe9, 0x13, 0x17, 0x3f, 0xfd, 0x8c, 0x95, 0x2d, -'i','s','o','8','8','5','9','3',0, -10, 33, -0x26, 0x61, 0x3b, 0x0a, 0x29, 0x00, 0x90, 0x74, 0x0a, 0x2a, -0x30, 0x79, 0xe5, 0x11, 0x4d, 0xad, 0x00, 0xb0, 0x17, 0x2c, -0x27, 0xc9, 0x32, 0x0b, 0x2d, 0xb5, 0x94, 0x74, 0x0b, 0x2e, -0x31, 0x7d, 0xf5, 0x51, 0x4d, 0xbd, 0x00, 0xc0, 0x17, 0x30, -0xc1, 0x08, 0x03, 0x00, 0x31, 0x0a, 0x21, 0x74, 0x0c, 0x32, -0xc9, 0x28, 0xb3, 0x0c, 0x33, 0xcd, 0x38, 0xf3, 0x0c, 0x00, -0xd1, 0x48, 0x33, 0x0d, 0x35, 0x20, 0x59, 0x73, 0x0d, 0x47, -0xd9, 0x68, 0xb3, 0x0d, 0x37, 0x6c, 0x71, 0xf5, 0x0d, 0x38, -0xe1, 0x88, 0x03, 0x00, 0x39, 0x0b, 0x25, 0x74, 0x0e, 0x3a, -0xe9, 0xa8, 0xb3, 0x0e, 0x3b, 0xed, 0xb8, 0xf3, 0x0e, 0x00, -0xf1, 0xc8, 0x33, 0x0f, 0x3d, 0x21, 0xd9, 0x73, 0x4f, 0x47, -0xf9, 0xe8, 0xb3, 0x0f, 0x3f, 0x6d, 0x75, 0x95, 0x2d, -'i','s','o','8','8','5','9','4',0, -10, 33, -0x04, 0xe1, 0x64, 0x15, 0x29, 0x28, 0xed, 0x74, 0x0a, 0x2a, -0x60, 0x49, 0x24, 0x92, 0x59, 0xad, 0xf4, 0xf5, 0x0a, 0x2c, -0x05, 0x6d, 0x7b, 0x15, 0x2d, 0x29, 0xf1, 0x74, 0x2c, 0x2e, -0x61, 0x4d, 0x34, 0xd2, 0x59, 0x4a, 0xf9, 0xb5, 0x14, 0x40, -0xc1, 0x08, 0x33, 0x0c, 0x31, 0xc5, 0x18, 0xe3, 0x12, 0x43, -0xc9, 0x60, 0xb4, 0x8c, 0x45, 0xcd, 0x38, 0xa3, 0x12, 0x44, -0x45, 0x31, 0x65, 0x13, 0x35, 0xd5, 0x58, 0x73, 0x0d, 0x36, -0x72, 0x69, 0xb3, 0x0d, 0x37, 0x68, 0xa9, 0xf5, 0x4d, 0x40, -0xe1, 0x88, 0x33, 0x0e, 0x39, 0xe5, 0x98, 0xf3, 0x52, 0x43, -0xe9, 0x64, 0xb4, 0xce, 0x45, 0xed, 0xb8, 0xb3, 0x52, 0x44, -0x46, 0x35, 0x75, 0x13, 0x3d, 0xf5, 0xd8, 0x73, 0x0f, 0x3e, -0x73, 0xe9, 0xb3, 0x0f, 0x3f, 0x69, 0xad, 0x95, 0x2d, -'i','s','o','8','8','5','9','5',0, -14, 33, -0x01, 0x84, 0x00, 0x30, 0x40, 0x10, 0x10, 0x05, 0x84, 0x01, -0x70, 0x40, 0x20, 0x10, 0x09, 0x84, 0x02, 0xb0, 0x40, 0x30, -0x10, 0xad, 0x80, 0x03, 0xf0, 0x40, 0x40, 0x10, 0x11, 0x84, -0x04, 0x30, 0x41, 0x50, 0x10, 0x15, 0x84, 0x05, 0x70, 0x41, -0x60, 0x10, 0x19, 0x84, 0x06, 0xb0, 0x41, 0x70, 0x10, 0x1d, -0x84, 0x07, 0xf0, 0x41, 0x80, 0x10, 0x21, 0x84, 0x08, 0x30, -0x42, 0x90, 0x10, 0x25, 0x84, 0x09, 0x70, 0x42, 0xa0, 0x10, -0x29, 0x84, 0x0a, 0xb0, 0x42, 0xb0, 0x10, 0x2d, 0x84, 0x0b, -0xf0, 0x42, 0xc0, 0x10, 0x31, 0x84, 0x0c, 0x30, 0x43, 0xd0, -0x10, 0x35, 0x84, 0x0d, 0x70, 0x43, 0xe0, 0x10, 0x39, 0x84, -0x0e, 0xb0, 0x43, 0xf0, 0x10, 0x3d, 0x84, 0x0f, 0xf0, 0x43, -0x00, 0x11, 0x41, 0x84, 0x10, 0x30, 0x44, 0x10, 0x11, 0x45, -0x84, 0x11, 0x70, 0x44, 0x20, 0x11, 0x49, 0x84, 0x12, 0xb0, -0x44, 0x30, 0x11, 0x4d, 0x84, 0x13, 0xf0, 0x44, 0x58, 0x84, -0x51, 0x84, 0x14, 0x30, 0x45, 0x50, 0x11, 0x55, 0x84, 0x15, -0x70, 0x45, 0x60, 0x11, 0x59, 0x84, 0x16, 0xb0, 0x45, 0x70, -0x11, 0xa7, 0x80, 0x17, 0xf0, 0x45, 0x00, -'i','s','o','8','8','5','9','6',0, -11, 33, -0x00, 0x00, 0x00, 0x00, 0x48, 0x01, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0xdc, 0x0a, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x86, 0x00, 0x00, 0x00, -0x00, 0x7c, 0x18, 0x00, 0x21, 0x16, 0xf1, 0x88, 0x48, 0x5c, -0x62, 0x13, 0x9c, 0x18, 0xc5, 0x29, 0x56, 0xf1, 0x8a, 0x58, -0xdc, 0x62, 0x17, 0xbc, 0x18, 0xc6, 0x31, 0x96, 0xf1, 0x8c, -0x68, 0x5c, 0x63, 0x1b, 0xdc, 0x18, 0xc7, 0x39, 0xd6, 0x31, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8, 0x41, 0x16, -0xf2, 0x90, 0x88, 0x5c, 0x64, 0x23, 0x1c, 0x19, 0xc9, 0x49, -0x56, 0xf2, 0x92, 0x98, 0xdc, 0x64, 0x27, 0x3c, 0x19, 0xca, -0x51, 0x96, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, -'i','s','o','8','8','5','9','7',0, -14, 33, -0x18, 0x60, 0x06, 0x30, 0x0a, 0xb0, 0x82, 0xaf, 0xa0, 0x29, -0x70, 0x0a, 0xa0, 0x02, 0xa9, 0x80, 0xde, 0xb0, 0x0a, 0xb0, -0x02, 0xad, 0x00, 0x00, 0x50, 0x01, 0xc0, 0x02, 0xb1, 0x80, -0x2c, 0x30, 0x0b, 0x10, 0x0e, 0x85, 0x83, 0xe1, 0x70, 0x0b, -0x20, 0x0e, 0x89, 0x83, 0xe2, 0xb0, 0x0b, 0x30, 0x0e, 0xbd, -0x80, 0xe3, 0xf0, 0x38, 0x40, 0x0e, 0x91, 0x83, 0xe4, 0x30, -0x39, 0x50, 0x0e, 0x95, 0x83, 0xe5, 0x70, 0x39, 0x60, 0x0e, -0x99, 0x83, 0xe6, 0xb0, 0x39, 0x70, 0x0e, 0x9d, 0x83, 0xe7, -0xf0, 0x39, 0x80, 0x0e, 0xa1, 0x03, 0x00, 0x30, 0x3a, 0x90, -0x0e, 0xa5, 0x83, 0xe9, 0x70, 0x3a, 0xa0, 0x0e, 0xa9, 0x83, -0xea, 0xb0, 0x3a, 0xb0, 0x0e, 0xad, 0x83, 0xeb, 0xf0, 0x3a, -0xc0, 0x0e, 0xb1, 0x83, 0xec, 0x30, 0x3b, 0xd0, 0x0e, 0xb5, -0x83, 0xed, 0x70, 0x3b, 0xe0, 0x0e, 0xb9, 0x83, 0xee, 0xb0, -0x3b, 0xf0, 0x0e, 0xbd, 0x83, 0xef, 0xf0, 0x3b, 0x00, 0x0f, -0xc1, 0x83, 0xf0, 0x30, 0x3c, 0x10, 0x0f, 0xc5, 0x83, 0xf1, -0x70, 0x3c, 0x20, 0x0f, 0xc9, 0x83, 0xf2, 0xb0, 0x3c, 0x30, -0x0f, 0xcd, 0x83, 0xf3, 0x00, 0x00, 0x00, -'i','s','o','8','8','5','9','8',0, -14, 33, -0x00, 0x80, 0x28, 0x30, 0x0a, 0x90, 0x02, 0xa5, 0x80, 0x29, -0x70, 0x0a, 0xa0, 0x02, 0xa9, 0xc0, 0x35, 0xb0, 0x0a, 0xb0, -0x02, 0xad, 0x80, 0x2b, 0xf0, 0x0a, 0xc0, 0x02, 0xb1, 0x80, -0x2c, 0x30, 0x0b, 0xd0, 0x02, 0xb5, 0x80, 0x2d, 0x70, 0x0b, -0xe0, 0x02, 0xb9, 0xc0, 0x3d, 0xb0, 0x0b, 0xf0, 0x02, 0xbd, -0x80, 0x2f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x01, -0x40, 0x17, 0xd1, 0x85, 0x74, 0x30, 0x5d, 0x50, 0x17, 0xd5, -0x85, 0x75, 0x70, 0x5d, 0x60, 0x17, 0xd9, 0x85, 0x76, 0xb0, -0x5d, 0x70, 0x17, 0xdd, 0x85, 0x77, 0xf0, 0x5d, 0x80, 0x17, -0xe1, 0x85, 0x78, 0x30, 0x5e, 0x90, 0x17, 0xe5, 0x85, 0x79, -0x70, 0x5e, 0xa0, 0x17, 0xe9, 0x85, 0x7a, 0x00, 0x00, 0x00, -0x00, 0x0e, 0xe0, 0x03, 0x00, 0x00, 0x00, -'i','s','o','8','8','5','9','9',0, -9, 80, -0x1e, 0xa3, 0x49, 0x9b, 0x46, 0xad, 0x9a, 0xb5, 0x6b, 0xd8, -0xb2, 0x69, 0xdb, 0xc6, 0x0d, 0xa6, 0xd7, 0x6f, 0xe0, 0xc2, -0x89, 0x1b, 0x47, 0xae, 0x9c, 0xb9, 0x73, 0xe8, 0xd2, 0xa9, -0x5b, 0xc7, 0xae, 0x9d, 0xbb, 0x77, 0x1f, 0xe3, 0xc9, 0x9b, -0x47, 0xaf, 0x9e, 0xbd, 0x7b, 0xf8, 0xf2, 0xe9, 0xdb, 0xc7, -0x2f, 0xe6, 0xd7, 0x7f, -'i','s','o','8','8','5','9','1','0',0, -14, 33, -0x04, 0x81, 0x44, 0x20, 0x12, 0xa8, 0x04, 0x28, 0x81, 0x4d, -0x70, 0x0a, 0xec, 0x04, 0x10, 0x01, 0x58, 0x60, 0x16, 0xf4, -0x05, 0xad, 0x80, 0x5a, 0xa0, 0x14, 0xc0, 0x02, 0x05, 0xc1, -0x44, 0x30, 0x12, 0xac, 0x04, 0x29, 0xc1, 0x4d, 0x70, 0x0b, -0xf0, 0x04, 0x11, 0x41, 0x58, 0x70, 0x16, 0xf8, 0x05, 0x15, -0xe0, 0x5a, 0xb0, 0x14, 0x00, 0x04, 0xc1, 0x80, 0x30, 0x30, -0x0c, 0x10, 0x03, 0xc5, 0x80, 0x31, 0xe0, 0x12, 0x30, 0x04, -0xc9, 0x00, 0x46, 0xb0, 0x0c, 0x58, 0x04, 0xcd, 0x80, 0x33, -0xf0, 0x0c, 0x40, 0x03, 0x45, 0x01, 0x53, 0x30, 0x0d, 0x50, -0x03, 0xd5, 0x80, 0x35, 0x80, 0x16, 0x60, 0x03, 0x72, 0x81, -0x36, 0xb0, 0x0d, 0x70, 0x03, 0xdd, 0x80, 0x37, 0xf0, 0x0d, -0x04, 0x04, 0xe1, 0x80, 0x38, 0x30, 0x0e, 0x90, 0x03, 0xe5, -0x80, 0x39, 0xf0, 0x12, 0x34, 0x04, 0xe9, 0x40, 0x46, 0xb0, -0x0e, 0x5c, 0x04, 0xed, 0x80, 0x3b, 0xf0, 0x0e, 0xc0, 0x03, -0x46, 0x41, 0x53, 0x30, 0x0f, 0xd0, 0x03, 0xf5, 0x80, 0x3d, -0x90, 0x16, 0xe0, 0x03, 0x73, 0x81, 0x3e, 0xb0, 0x0f, 0xf0, -0x03, 0xfd, 0x80, 0x3f, 0x80, 0x13, 0x00, -'i','s','o','8','8','5','9','1','3',0, -14, 33, -0x1d, 0xa0, 0x28, 0x30, 0x0a, 0x90, 0x02, 0x1e, 0xa0, 0x29, -0x70, 0x0a, 0x60, 0x03, 0xa9, 0x80, 0x55, 0xb0, 0x0a, 0xb0, -0x02, 0xad, 0x80, 0x2b, 0x60, 0x0c, 0xc0, 0x02, 0xb1, 0x80, -0x2c, 0x30, 0x0b, 0x70, 0x80, 0xb5, 0x80, 0x2d, 0x70, 0x0b, -0xe0, 0x03, 0xb9, 0xc0, 0x55, 0xb0, 0x0b, 0xf0, 0x02, 0xbd, -0x80, 0x2f, 0x60, 0x0e, 0x10, 0x04, 0x2e, 0x01, 0x40, 0x60, -0x10, 0x10, 0x03, 0xc5, 0x00, 0x46, 0x20, 0x11, 0x30, 0x04, -0xc9, 0x40, 0x5e, 0x60, 0x11, 0x88, 0x04, 0x36, 0x81, 0x4a, -0xb0, 0x13, 0x80, 0x05, 0x43, 0x41, 0x51, 0x30, 0x0d, 0x30, -0x05, 0xd5, 0x80, 0x35, 0x70, 0x0d, 0xc8, 0x05, 0x41, 0x81, -0x56, 0xa0, 0x16, 0x70, 0x03, 0x7b, 0x41, 0x5f, 0xf0, 0x0d, -0x14, 0x04, 0x2f, 0x41, 0x40, 0x70, 0x10, 0x90, 0x03, 0xe5, -0x40, 0x46, 0x30, 0x11, 0x34, 0x04, 0xe9, 0x80, 0x5e, 0x70, -0x11, 0x8c, 0x04, 0x37, 0xc1, 0x4a, 0xc0, 0x13, 0x84, 0x05, -0x44, 0x81, 0x51, 0x30, 0x0f, 0x34, 0x05, 0xf5, 0x80, 0x3d, -0x70, 0x0f, 0xcc, 0x05, 0x42, 0xc1, 0x56, 0xb0, 0x16, 0xf0, -0x03, 0x7c, 0x81, 0x5f, 0x90, 0x01, 0x00, -'i','s','o','8','8','5','9','1','4',0, -13, 33, -0x02, 0x7e, 0xc0, 0x8c, 0x02, 0x85, 0xb0, 0x10, 0x14, 0xfc, -0x29, 0x00, 0xf4, 0xa9, 0x40, 0xd0, 0x2c, 0x78, 0x79, 0xd0, -0x0a, 0x5c, 0x01, 0x5e, 0xf0, 0xf0, 0x1f, 0x1e, 0x24, 0x84, -0x04, 0x20, 0x10, 0xe4, 0x6c, 0x81, 0x95, 0x08, 0xf4, 0x57, -0x7e, 0xd0, 0x80, 0xf9, 0x79, 0x40, 0xe8, 0x0a, 0x7d, 0x98, -0x00, 0x06, 0xc1, 0x40, 0x18, 0x0c, 0x03, 0x62, 0x50, 0x0c, -0x8c, 0xc1, 0x31, 0x40, 0x06, 0xc9, 0x40, 0x19, 0x2c, 0x03, -0x66, 0xd0, 0x0c, 0x9c, 0xc1, 0x33, 0xa0, 0x0b, 0xd1, 0x40, -0x1a, 0x4c, 0x03, 0x6a, 0x50, 0x0d, 0xac, 0x81, 0x9a, 0xc0, -0x06, 0xd9, 0x40, 0x1b, 0x6c, 0x03, 0x6e, 0xd0, 0x0d, 0xec, -0xc2, 0x37, 0x00, 0x07, 0xe1, 0x40, 0x1c, 0x8c, 0x03, 0x72, -0x50, 0x0e, 0xcc, 0xc1, 0x39, 0x40, 0x07, 0xe9, 0x40, 0x1d, -0xac, 0x03, 0x76, 0xd0, 0x0e, 0xdc, 0xc1, 0x3b, 0xa8, 0x0b, -0xf1, 0x40, 0x1e, 0xcc, 0x03, 0x7a, 0x50, 0x0f, 0xec, 0xc1, -0x9a, 0xc0, 0x07, 0xf9, 0x40, 0x1f, 0xec, 0x03, 0x7e, 0xd0, -0x0f, 0xee, 0xc2, 0x3f, 0x00, -'i','s','o','8','8','5','9','1','6',0, -14, 33, -0x04, 0x41, 0x41, 0x10, 0x14, 0xb0, 0x82, 0x1e, 0x20, 0x58, -0x70, 0x0a, 0x84, 0x05, 0xa9, 0x00, 0x86, 0xb0, 0x0a, 0xe4, -0x05, 0xad, 0x80, 0x5e, 0xb0, 0x17, 0xc0, 0x02, 0xb1, 0x00, -0x43, 0x20, 0x14, 0xf4, 0x05, 0x1d, 0xa0, 0x2d, 0x70, 0x0b, -0xf8, 0x05, 0x0d, 0x41, 0x86, 0xb0, 0x0b, 0x48, 0x05, 0x53, -0x01, 0x5e, 0xc0, 0x17, 0x00, 0x03, 0xc1, 0x80, 0x30, 0x20, -0x10, 0x10, 0x03, 0x06, 0x81, 0x31, 0x70, 0x0c, 0x20, 0x03, -0xc9, 0x80, 0x32, 0xb0, 0x0c, 0x30, 0x03, 0xcd, 0x80, 0x33, -0xf0, 0x0c, 0x40, 0x04, 0x43, 0x81, 0x34, 0x30, 0x0d, 0x50, -0x03, 0x50, 0x81, 0x35, 0xa0, 0x15, 0xc0, 0x05, 0xd9, 0x80, -0x36, 0xb0, 0x0d, 0x70, 0x03, 0x18, 0x81, 0x86, 0xf0, 0x0d, -0x80, 0x03, 0xe1, 0x80, 0x38, 0x30, 0x10, 0x90, 0x03, 0x07, -0x81, 0x39, 0x70, 0x0e, 0xa0, 0x03, 0xe9, 0x80, 0x3a, 0xb0, -0x0e, 0xb0, 0x03, 0xed, 0x80, 0x3b, 0xf0, 0x0e, 0x44, 0x04, -0x44, 0x81, 0x3c, 0x30, 0x0f, 0xd0, 0x03, 0x51, 0x81, 0x3d, -0xb0, 0x15, 0xc4, 0x05, 0xf9, 0x80, 0x3e, 0xb0, 0x0f, 0xf0, -0x03, 0x19, 0xc1, 0x86, 0xf0, 0x0f, 0x00, diff --git a/05/musl-final/src/locale/tolower_l.c b/05/musl-final/src/locale/tolower_l.c deleted file mode 100644 index ba27791..0000000 --- a/05/musl-final/src/locale/tolower_l.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int tolower_l(int c, locale_t l) -{ - return tolower(c); -} diff --git a/05/musl-final/src/locale/toupper_l.c b/05/musl-final/src/locale/toupper_l.c deleted file mode 100644 index 73f2f39..0000000 --- a/05/musl-final/src/locale/toupper_l.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int toupper_l(int c, locale_t l) -{ - return toupper(c); -} diff --git a/05/musl-final/src/locale/wcscoll.c b/05/musl-final/src/locale/wcscoll.c deleted file mode 100644 index cdbce1c..0000000 --- a/05/musl-final/src/locale/wcscoll.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -/* FIXME: stub */ -int wcscoll(const wchar_t *l, const wchar_t *r) -{ - return wcscmp(l, r); -} diff --git a/05/musl-final/src/locale/wcsxfrm.c b/05/musl-final/src/locale/wcsxfrm.c deleted file mode 100644 index 5f76e5a..0000000 --- a/05/musl-final/src/locale/wcsxfrm.c +++ /dev/null @@ -1,12 +0,0 @@ -#include - -/* collate only by code points */ -size_t wcsxfrm(wchar_t *dest, const wchar_t *src, size_t n) -{ - size_t l = wcslen(src); - if (l >= n) { - wmemcpy(dest, src, n-1); - dest[n-1] = 0; - } else wcscpy(dest, src); - return l; -} diff --git a/05/musl-final/src/malloc/DESIGN b/05/musl-final/src/malloc/DESIGN deleted file mode 100644 index 58b0523..0000000 --- a/05/musl-final/src/malloc/DESIGN +++ /dev/null @@ -1,22 +0,0 @@ - - -In principle, this memory allocator is roughly equivalent to Doug -Lea's dlmalloc with fine-grained locking. - - - -malloc: - -Uses a freelist binned by chunk size, with a bitmap to optimize -searching for the smallest non-empty bin which can satisfy an -allocation. If no free chunks are available, it creates a new chunk of -the requested size and attempts to merge it with any existing free -chunk immediately below the newly created chunk. - -Whether the chunk was obtained from a bin or newly created, it's -likely to be larger than the requested allocation. malloc always -finishes its work by passing the new chunk to realloc, which will -split it into two chunks and free the tail portion. - - - diff --git a/05/musl-final/src/malloc/__brk.c b/05/musl-final/src/malloc/__brk.c deleted file mode 100644 index e3b3af3..0000000 --- a/05/musl-final/src/malloc/__brk.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -uintptr_t __brk(uintptr_t newbrk) -{ - return syscall1(__NR_brk, newbrk); -} diff --git a/05/musl-final/src/malloc/__simple_malloc.c b/05/musl-final/src/malloc/__simple_malloc.c deleted file mode 100644 index 49b74c8..0000000 --- a/05/musl-final/src/malloc/__simple_malloc.c +++ /dev/null @@ -1,44 +0,0 @@ -#include -#include -#include -#include -#include "libc.h" - -uintptr_t __brk(uintptr_t); - -#define ALIGN 16 - -void *__simple_malloc(size_t n) -{ - static uintptr_t cur, brk; - uintptr_t base, new; - static int lock; - size_t align=1; - - if (n < SIZE_MAX - ALIGN) - while (align SIZE_MAX - brk) goto fail; - - base = cur + align-1 & -align; - if (base+n > brk) { - new = base+n + PAGE_SIZE-1 & -PAGE_SIZE; - if (__brk(new) != new) goto fail; - brk = new; - } - cur = base+n; - UNLOCK(&lock); - - return (void *)base; - -fail: - UNLOCK(&lock); - errno = ENOMEM; - return 0; -} - -weak_alias(__simple_malloc, malloc); diff --git a/05/musl-final/src/malloc/calloc.c b/05/musl-final/src/malloc/calloc.c deleted file mode 100644 index 9d57456..0000000 --- a/05/musl-final/src/malloc/calloc.c +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include -#include - -void *calloc(size_t m, size_t n) -{ - void *p; - size_t *z; - if (n && m > (size_t)-1/n) { - errno = ENOMEM; - return 0; - } - n *= m; - p = malloc(n); - if (!p) return 0; - /* Only do this for non-mmapped chunks */ - if (((size_t *)p)[-1] & 7) { - /* Only write words that are not already zero */ - m = (n + sizeof *z - 1)/sizeof *z; - for (z=p; m; m--, z++) if (*z) *z=0; - } - return p; -} diff --git a/05/musl-final/src/malloc/malloc.c b/05/musl-final/src/malloc/malloc.c deleted file mode 100644 index 29f9760..0000000 --- a/05/musl-final/src/malloc/malloc.c +++ /dev/null @@ -1,515 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include "libc.h" -#include "atomic.h" -#include "pthread_impl.h" - -uintptr_t __brk(uintptr_t); -void *__mmap(void *, size_t, int, int, int, off_t); -int __munmap(void *, size_t); -void *__mremap(void *, size_t, size_t, int, ...); -int __madvise(void *, size_t, int); - -struct chunk { - size_t data[1]; - struct chunk *next; - struct chunk *prev; -}; - -struct bin { - int lock[2]; - struct chunk *head; - struct chunk *tail; -}; - -static struct { - uintptr_t brk; - size_t *heap; - uint64_t binmap; - struct bin bins[64]; - int brk_lock[2]; - int free_lock[2]; -} mal; - - -#define SIZE_ALIGN (4*sizeof(size_t)) -#define SIZE_MASK (-SIZE_ALIGN) -#define OVERHEAD (2*sizeof(size_t)) -#define MMAP_THRESHOLD (0x1c00*SIZE_ALIGN) -#define DONTCARE 16 -#define RECLAIM 163840 - -#define CHUNK_SIZE(c) ((c)->data[0] & SIZE_MASK) -#define CHUNK_PSIZE(c) ((c)->data[-1] & SIZE_MASK) -#define PREV_CHUNK(c) ((struct chunk *)((char *)(c) - CHUNK_PSIZE(c))) -#define NEXT_CHUNK(c) ((struct chunk *)((char *)(c) + CHUNK_SIZE(c))) -#define MEM_TO_CHUNK(p) (struct chunk *)((size_t *)p - 1) -#define CHUNK_TO_MEM(c) (void *)((c)->data+1) -#define BIN_TO_CHUNK(i) (MEM_TO_CHUNK(&mal.bins[i].head)) - -#define C_INUSE ((size_t)1) -#define C_FLAGS ((size_t)3) -#define C_SIZE SIZE_MASK - -#define IS_MMAPPED(c) !((c)->data[0] & (C_INUSE)) - - -/* Synchronization tools */ - -static void lock(volatile int *lk) -{ - if (!libc.threads_minus_1) return; - while(a_swap(lk, 1)) __wait(lk, lk+1, 1, 1); -} - -static void unlock(volatile int *lk) -{ - if (!libc.threads_minus_1) return; - a_store(lk, 0); - if (lk[1]) __wake(lk, 1, 1); -} - -static void lock_bin(int i) -{ - if (libc.threads_minus_1) - lock(mal.bins[i].lock); - if (!mal.bins[i].head) - mal.bins[i].head = mal.bins[i].tail = BIN_TO_CHUNK(i); -} - -static void unlock_bin(int i) -{ - if (!libc.threads_minus_1) return; - unlock(mal.bins[i].lock); -} - -static int first_set(uint64_t x) -{ -#if 1 - return a_ctz_64(x); -#else - static const char debruijn64[64] = { - 0, 1, 2, 53, 3, 7, 54, 27, 4, 38, 41, 8, 34, 55, 48, 28, - 62, 5, 39, 46, 44, 42, 22, 9, 24, 35, 59, 56, 49, 18, 29, 11, - 63, 52, 6, 26, 37, 40, 33, 47, 61, 45, 43, 21, 23, 58, 17, 10, - 51, 25, 36, 32, 60, 20, 57, 16, 50, 31, 19, 15, 30, 14, 13, 12 - }; - static const char debruijn32[32] = { - 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13, - 31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14 - }; - if (sizeof(long) < 8) { - uint32_t y = x; - if (!y) { - y = x>>32; - return 32 + debruijn32[(y&-y)*0x076be629 >> 27]; - } - return debruijn32[(y&-y)*0x076be629 >> 27]; - } - return debruijn64[(x&-x)*0x022fdd63cc95386dull >> 58]; -#endif -} - -static int bin_index(size_t x) -{ - x = x / SIZE_ALIGN - 1; - if (x <= 32) return x; - if (x > 0x1c00) return 63; - return ((union { float v; uint32_t r; }){ x }.r>>21) - 496; -} - -static int bin_index_up(size_t x) -{ - x = x / SIZE_ALIGN - 1; - if (x <= 32) return x; - return ((union { float v; uint32_t r; }){ x }.r+0x1fffff>>21) - 496; -} - -#if 0 -void __dump_heap(int x) -{ - struct chunk *c; - int i; - for (c = (void *)mal.heap; CHUNK_SIZE(c); c = NEXT_CHUNK(c)) - fprintf(stderr, "base %p size %zu (%d) flags %d/%d\n", - c, CHUNK_SIZE(c), bin_index(CHUNK_SIZE(c)), - c->data[0] & 15, - NEXT_CHUNK(c)->data[-1] & 15); - for (i=0; i<64; i++) { - if (mal.bins[i].head != BIN_TO_CHUNK(i) && mal.bins[i].head) { - fprintf(stderr, "bin %d: %p\n", i, mal.bins[i].head); - if (!(mal.binmap & 1ULL< SIZE_MAX - mal.brk - 2*PAGE_SIZE) goto fail; - new = mal.brk + n + SIZE_ALIGN + PAGE_SIZE - 1 & -PAGE_SIZE; - n = new - mal.brk; - - if (__brk(new) != new) goto fail; - - w = MEM_TO_CHUNK(new); - w->data[-1] = n | C_INUSE; - w->data[0] = 0 | C_INUSE; - - w = MEM_TO_CHUNK(mal.brk); - w->data[0] = n | C_INUSE; - mal.brk = new; - - unlock(mal.brk_lock); - - return w; -fail: - unlock(mal.brk_lock); - return 0; -} - -static int init_malloc() -{ - static int init, waiters; - int state; - struct chunk *c; - - if (init == 2) return 0; - - while ((state=a_swap(&init, 1)) == 1) - __wait(&init, &waiters, 1, 1); - if (state) { - a_store(&init, 2); - return 0; - } - - mal.brk = __brk(0) + 2*SIZE_ALIGN-1 & -SIZE_ALIGN; - - c = expand_heap(1); - - if (!c) { - a_store(&init, 0); - if (waiters) __wake(&init, 1, 1); - return -1; - } - - mal.heap = (void *)c; - c->data[-1] = 0 | C_INUSE; - free(CHUNK_TO_MEM(c)); - - a_store(&init, 2); - if (waiters) __wake(&init, -1, 1); - return 0; -} - -static int adjust_size(size_t *n) -{ - /* Result of pointer difference must fit in ptrdiff_t. */ - if (*n > PTRDIFF_MAX - SIZE_ALIGN - PAGE_SIZE) { - errno = ENOMEM; - return -1; - } - *n = (*n + OVERHEAD + SIZE_ALIGN - 1) & SIZE_MASK; - return 0; -} - -static void unbin(struct chunk *c, int i) -{ - if (c->prev == c->next) - a_and_64(&mal.binmap, ~(1ULL<prev->next = c->next; - c->next->prev = c->prev; - c->data[0] |= C_INUSE; - NEXT_CHUNK(c)->data[-1] |= C_INUSE; -} - -static int alloc_fwd(struct chunk *c) -{ - int i; - size_t k; - while (!((k=c->data[0]) & C_INUSE)) { - i = bin_index(k); - lock_bin(i); - if (c->data[0] == k) { - unbin(c, i); - unlock_bin(i); - return 1; - } - unlock_bin(i); - } - return 0; -} - -static int alloc_rev(struct chunk *c) -{ - int i; - size_t k; - while (!((k=c->data[-1]) & C_INUSE)) { - i = bin_index(k); - lock_bin(i); - if (c->data[-1] == k) { - unbin(PREV_CHUNK(c), i); - unlock_bin(i); - return 1; - } - unlock_bin(i); - } - return 0; -} - - -/* pretrim - trims a chunk _prior_ to removing it from its bin. - * Must be called with i as the ideal bin for size n, j the bin - * for the _free_ chunk self, and bin j locked. */ -static int pretrim(struct chunk *self, size_t n, int i, int j) -{ - size_t n1; - struct chunk *next, *split; - - /* We cannot pretrim if it would require re-binning. */ - if (j < 40) return 0; - if (j < i+3) { - if (j != 63) return 0; - n1 = CHUNK_SIZE(self); - if (n1-n <= MMAP_THRESHOLD) return 0; - } else { - n1 = CHUNK_SIZE(self); - } - if (bin_index(n1-n) != j) return 0; - - next = NEXT_CHUNK(self); - split = (void *)((char *)self + n); - - split->prev = self->prev; - split->next = self->next; - split->prev->next = split; - split->next->prev = split; - split->data[-1] = n | C_INUSE; - split->data[0] = n1-n; - next->data[-1] = n1-n; - self->data[0] = n | C_INUSE; - return 1; -} - -static void trim(struct chunk *self, size_t n) -{ - size_t n1 = CHUNK_SIZE(self); - struct chunk *next, *split; - - if (n >= n1 - DONTCARE) return; - - next = NEXT_CHUNK(self); - split = (void *)((char *)self + n); - - split->data[-1] = n | C_INUSE; - split->data[0] = n1-n | C_INUSE; - next->data[-1] = n1-n | C_INUSE; - self->data[0] = n | C_INUSE; - - free(CHUNK_TO_MEM(split)); -} - -void *malloc(size_t n) -{ - struct chunk *c; - int i, j; -if (n == 0) n = 1;/* everyone depends on this behavior for some fucking reason */ - if (!n || adjust_size(&n) < 0) return 0; - - if (n > MMAP_THRESHOLD) { - size_t len = n + PAGE_SIZE - 1 & -PAGE_SIZE; - char *base = __mmap(0, len, PROT_READ|PROT_WRITE, - MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); - if (base == (void *)-1) return 0; - c = (void *)(base + SIZE_ALIGN - sizeof(size_t)); - c->data[0] = len - (SIZE_ALIGN - sizeof(size_t)); - c->data[-1] = SIZE_ALIGN - sizeof(size_t); - return CHUNK_TO_MEM(c); - } - - i = bin_index_up(n); - for (;;) { - uint64_t mask = mal.binmap & -(1ULL<data[-1] = c->data[0] = - x->data[0] + CHUNK_SIZE(c); - } - break; - } - j = first_set(mask); - lock_bin(j); - c = mal.bins[j].head; - if (c != BIN_TO_CHUNK(j) && j == bin_index(c->data[0])) { - if (!pretrim(c, n, i, j)) unbin(c, j); - unlock_bin(j); - break; - } - unlock_bin(j); - } - - /* Now patch up in case we over-allocated */ - trim(c, n); - - return CHUNK_TO_MEM(c); -} - -void *realloc(void *p, size_t n) -{ - struct chunk *self, *next; - size_t n0, n1; - void *new; - - if (!p) return malloc(n); - else if (!n) return free(p), (void *)0; - - if (adjust_size(&n) < 0) return 0; - - self = MEM_TO_CHUNK(p); - n1 = n0 = CHUNK_SIZE(self); - - if (IS_MMAPPED(self)) { - size_t extra = self->data[-1]; - char *base = (char *)self - extra; - size_t oldlen = n0 + extra; - size_t newlen = n + extra; - if (newlen < PAGE_SIZE && (new = malloc(n))) { - memcpy(new, p, n-OVERHEAD); - free(p); - return new; - } - newlen = (newlen + PAGE_SIZE-1) & -PAGE_SIZE; - if (oldlen == newlen) return p; - base = __mremap(base, oldlen, newlen, MREMAP_MAYMOVE); - if (base == (void *)-1) - return newlen < oldlen ? p : 0; - self = (void *)(base + extra); - self->data[0] = newlen - extra; - return CHUNK_TO_MEM(self); - } - - next = NEXT_CHUNK(self); - - /* Merge adjacent chunks if we need more space. This is not - * a waste of time even if we fail to get enough space, because our - * subsequent call to free would otherwise have to do the merge. */ - if (n > n1 && alloc_fwd(next)) { - n1 += CHUNK_SIZE(next); - next = NEXT_CHUNK(next); - } - /* FIXME: find what's wrong here and reenable it..? */ - if (0 && n > n1 && alloc_rev(self)) { - self = PREV_CHUNK(self); - n1 += CHUNK_SIZE(self); - } - self->data[0] = n1 | C_INUSE; - next->data[-1] = n1 | C_INUSE; - - /* If we got enough space, split off the excess and return */ - if (n <= n1) { - //memmove(CHUNK_TO_MEM(self), p, n0-OVERHEAD); - trim(self, n); - return CHUNK_TO_MEM(self); - } - - /* As a last resort, allocate a new chunk and copy to it. */ - new = malloc(n-OVERHEAD); - if (!new) return 0; - memcpy(new, p, n0-OVERHEAD); - free(CHUNK_TO_MEM(self)); - return new; -} - -void free(void *p) -{ - struct chunk *self = MEM_TO_CHUNK(p); - struct chunk *next; - size_t final_size, new_size, size; - int reclaim=0; - int i; - - if (!p) return; - - if (IS_MMAPPED(self)) { - size_t extra = self->data[-1]; - char *base = (char *)self - extra; - size_t len = CHUNK_SIZE(self) + extra; - __munmap(base, len); - return; - } - - final_size = new_size = CHUNK_SIZE(self); - next = NEXT_CHUNK(self); - - for (;;) { - /* Replace middle of large chunks with fresh zero pages */ - if (reclaim && (self->data[-1] & next->data[0] & C_INUSE)) { - uintptr_t a = (uintptr_t)self + SIZE_ALIGN+PAGE_SIZE-1 & -PAGE_SIZE; - uintptr_t b = (uintptr_t)next - SIZE_ALIGN & -PAGE_SIZE; -#if 1 - __madvise((void *)a, b-a, MADV_DONTNEED); -#else - __mmap((void *)a, b-a, PROT_READ|PROT_WRITE, - MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED, -1, 0); -#endif - } - - if (self->data[-1] & next->data[0] & C_INUSE) { - self->data[0] = final_size | C_INUSE; - next->data[-1] = final_size | C_INUSE; - i = bin_index(final_size); - lock_bin(i); - lock(mal.free_lock); - if (self->data[-1] & next->data[0] & C_INUSE) - break; - unlock(mal.free_lock); - unlock_bin(i); - } - - if (alloc_rev(self)) { - self = PREV_CHUNK(self); - size = CHUNK_SIZE(self); - final_size += size; - if (new_size+size > RECLAIM && (new_size+size^size) > size) - reclaim = 1; - } - - if (alloc_fwd(next)) { - size = CHUNK_SIZE(next); - final_size += size; - if (new_size+size > RECLAIM && (new_size+size^size) > size) - reclaim = 1; - next = NEXT_CHUNK(next); - } - } - - self->data[0] = final_size; - next->data[-1] = final_size; - unlock(mal.free_lock); - - self->next = BIN_TO_CHUNK(i); - self->prev = mal.bins[i].tail; - self->next->prev = self; - self->prev->next = self; - - if (!(mal.binmap & 1ULL< -#include - -void *memalign(size_t align, size_t len) -{ - void *mem; - int ret; - if ((ret = posix_memalign(&mem, align, len))) { - errno = ret; - return 0; - } - return mem; -} diff --git a/05/musl-final/src/malloc/posix_memalign.c b/05/musl-final/src/malloc/posix_memalign.c deleted file mode 100644 index ef86260..0000000 --- a/05/musl-final/src/malloc/posix_memalign.c +++ /dev/null @@ -1,47 +0,0 @@ -#include -#include -#include - -/* This function should work with most dlmalloc-like chunk bookkeeping - * systems, but it's only guaranteed to work with the native implementation - * used in this library. */ - -int posix_memalign(void **res, size_t align, size_t len) -{ - unsigned char *mem, *new, *end; - size_t header, footer; - - if ((align & -align) != align) return EINVAL; - if (len > SIZE_MAX - align) return ENOMEM; - - if (align <= 4*sizeof(size_t)) { - if (!(mem = malloc(len))) - return errno; - *res = mem; - return 0; - } - - if (!(mem = malloc(len + align-1))) - return errno; - - header = ((size_t *)mem)[-1]; - end = mem + (header & -8); - footer = ((size_t *)end)[-2]; - new = (void *)((uintptr_t)mem + align-1 & -align); - - if (!(header & 7)) { - ((size_t *)new)[-2] = ((size_t *)mem)[-2] + (new-mem); - ((size_t *)new)[-1] = ((size_t *)mem)[-1] - (new-mem); - *res = new; - return 0; - } - - ((size_t *)mem)[-1] = header&7 | new-mem; - ((size_t *)new)[-2] = footer&7 | new-mem; - ((size_t *)new)[-1] = header&7 | end-new; - ((size_t *)end)[-2] = footer&7 | end-new; - - if (new != mem) free(mem); - *res = new; - return 0; -} diff --git a/05/musl-final/src/math/__fpclassify.c b/05/musl-final/src/math/__fpclassify.c deleted file mode 100644 index 1605110..0000000 --- a/05/musl-final/src/math/__fpclassify.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include - -int __fpclassify(double __x) -{ - union { - double __d; - __uint64_t __i; - } __y = { __x }; - int __ee = __y.__i>>52 & 0x7ff; - if (!__ee) return __y.__i<<1 ? FP_SUBNORMAL : FP_ZERO; - if (__ee==0x7ff) return __y.__i<<12 ? FP_NAN : FP_INFINITE; - return FP_NORMAL; -} diff --git a/05/musl-final/src/math/__fpclassifyf.c b/05/musl-final/src/math/__fpclassifyf.c deleted file mode 100644 index bf59d0d..0000000 --- a/05/musl-final/src/math/__fpclassifyf.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include - -int __fpclassifyf(float __x) -{ - union { - float __f; - __uint32_t __i; - } __y = { __x }; - int __ee = __y.__i>>23 & 0xff; - if (!__ee) return __y.__i<<1 ? FP_SUBNORMAL : FP_ZERO; - if (__ee==0xff) return __y.__i<<9 ? FP_NAN : FP_INFINITE; - return FP_NORMAL; -} diff --git a/05/musl-final/src/math/__fpclassifyl.c b/05/musl-final/src/math/__fpclassifyl.c deleted file mode 100644 index 4f93bef..0000000 --- a/05/musl-final/src/math/__fpclassifyl.c +++ /dev/null @@ -1,16 +0,0 @@ -#include -#include - -/* FIXME: move this to arch-specific file */ -int __fpclassifyl(long double __x) -{ - union { - long double __ld; - __uint16_t __hw[5]; - __uint64_t __m; - } __y = { __x }; - int __ee = __y.__hw[4]&0x7fff; - if (!__ee) return __y.__m ? FP_SUBNORMAL : FP_ZERO; - if (__ee==0x7fff) return __y.__m ? FP_NAN : FP_INFINITE; - return FP_NORMAL; -} diff --git a/05/musl-final/src/math/__log1p.h b/05/musl-final/src/math/__log1p.h deleted file mode 100644 index ec2c77b..0000000 --- a/05/musl-final/src/math/__log1p.h +++ /dev/null @@ -1,94 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/k_log.h */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ -/* - * __log1p(f): - * Return log(1+f) - f for 1+f in ~[sqrt(2)/2, sqrt(2)]. - * - * The following describes the overall strategy for computing - * logarithms in base e. The argument reduction and adding the final - * term of the polynomial are done by the caller for increased accuracy - * when different bases are used. - * - * Method : - * 1. Argument Reduction: find k and f such that - * x = 2^k * (1+f), - * where sqrt(2)/2 < 1+f < sqrt(2) . - * - * 2. Approximation of log(1+f). - * Let s = f/(2+f) ; based on log(1+f) = log(1+s) - log(1-s) - * = 2s + 2/3 s**3 + 2/5 s**5 + ....., - * = 2s + s*R - * We use a special Reme algorithm on [0,0.1716] to generate - * a polynomial of degree 14 to approximate R The maximum error - * of this polynomial approximation is bounded by 2**-58.45. In - * other words, - * 2 4 6 8 10 12 14 - * R(z) ~ Lg1*s +Lg2*s +Lg3*s +Lg4*s +Lg5*s +Lg6*s +Lg7*s - * (the values of Lg1 to Lg7 are listed in the program) - * and - * | 2 14 | -58.45 - * | Lg1*s +...+Lg7*s - R(z) | <= 2 - * | | - * Note that 2s = f - s*f = f - hfsq + s*hfsq, where hfsq = f*f/2. - * In order to guarantee error in log below 1ulp, we compute log - * by - * log(1+f) = f - s*(f - R) (if f is not too large) - * log(1+f) = f - (hfsq - s*(hfsq+R)). (better accuracy) - * - * 3. Finally, log(x) = k*ln2 + log(1+f). - * = k*ln2_hi+(f-(hfsq-(s*(hfsq+R)+k*ln2_lo))) - * Here ln2 is split into two floating point number: - * ln2_hi + ln2_lo, - * where n*ln2_hi is always exact for |n| < 2000. - * - * Special cases: - * log(x) is NaN with signal if x < 0 (including -INF) ; - * log(+INF) is +INF; log(0) is -INF with signal; - * log(NaN) is that NaN with no signal. - * - * Accuracy: - * according to an error analysis, the error is always less than - * 1 ulp (unit in the last place). - * - * Constants: - * The hexadecimal values are the intended ones for the following - * constants. The decimal values may be used, provided that the - * compiler will convert from decimal to binary accurately enough - * to produce the hexadecimal values shown. - */ - -static const double -Lg1 = 6.666666666666735130e-01, /* 3FE55555 55555593 */ -Lg2 = 3.999999999940941908e-01, /* 3FD99999 9997FA04 */ -Lg3 = 2.857142874366239149e-01, /* 3FD24924 94229359 */ -Lg4 = 2.222219843214978396e-01, /* 3FCC71C5 1D8E78AF */ -Lg5 = 1.818357216161805012e-01, /* 3FC74664 96CB03DE */ -Lg6 = 1.531383769920937332e-01, /* 3FC39A09 D078C69F */ -Lg7 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */ - -/* - * We always inline __log1p(), since doing so produces a - * substantial performance improvement (~40% on amd64). - */ -static inline double __log1p(double f) -{ - double hfsq,s,z,R,w,t1,t2; - - s = f/(2.0+f); - z = s*s; - w = z*z; - t1= w*(Lg2+w*(Lg4+w*Lg6)); - t2= z*(Lg1+w*(Lg3+w*(Lg5+w*Lg7))); - R = t2+t1; - hfsq = 0.5*f*f; - return s*(hfsq+R); -} diff --git a/05/musl-final/src/math/__log1pf.h b/05/musl-final/src/math/__log1pf.h deleted file mode 100644 index 99492c5..0000000 --- a/05/musl-final/src/math/__log1pf.h +++ /dev/null @@ -1,35 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/k_logf.h */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ -/* - * See comments in __log1p.h. - */ - -/* |(log(1+s)-log(1-s))/s - Lg(s)| < 2**-34.24 (~[-4.95e-11, 4.97e-11]). */ -static const float -Lg1 = 0xaaaaaa.0p-24, /* 0.66666662693 */ -Lg2 = 0xccce13.0p-25, /* 0.40000972152 */ -Lg3 = 0x91e9ee.0p-25, /* 0.28498786688 */ -Lg4 = 0xf89e26.0p-26; /* 0.24279078841 */ - -static inline float __log1pf(float f) -{ - float hfsq,s,z,R,w,t1,t2; - - s = f/(2.0f + f); - z = s*s; - w = z*z; - t1 = w*(Lg2+w*Lg4); - t2 = z*(Lg1+w*Lg3); - R = t2+t1; - hfsq = 0.5f * f * f; - return s*(hfsq+R); -} diff --git a/05/musl-final/src/math/__x86_64/e_sqrt.s b/05/musl-final/src/math/__x86_64/e_sqrt.s deleted file mode 100644 index 64de7d6..0000000 --- a/05/musl-final/src/math/__x86_64/e_sqrt.s +++ /dev/null @@ -1,3 +0,0 @@ -.global sqrt -sqrt: sqrtsd %xmm0, %xmm0 - ret diff --git a/05/musl-final/src/math/__x86_64/e_sqrtf.s b/05/musl-final/src/math/__x86_64/e_sqrtf.s deleted file mode 100644 index 2c77076..0000000 --- a/05/musl-final/src/math/__x86_64/e_sqrtf.s +++ /dev/null @@ -1,3 +0,0 @@ -.global sqrtf -sqrtf: sqrtss %xmm0, %xmm0 - ret diff --git a/05/musl-final/src/math/e_acos.c b/05/musl-final/src/math/e_acos.c deleted file mode 100644 index e023639..0000000 --- a/05/musl-final/src/math/e_acos.c +++ /dev/null @@ -1,99 +0,0 @@ -/* @(#)e_acos.c 1.3 95/01/18 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* acos(x) - * Method : - * acos(x) = pi/2 - asin(x) - * acos(-x) = pi/2 + asin(x) - * For |x|<=0.5 - * acos(x) = pi/2 - (x + x*x^2*R(x^2)) (see asin.c) - * For x>0.5 - * acos(x) = pi/2 - (pi/2 - 2asin(sqrt((1-x)/2))) - * = 2asin(sqrt((1-x)/2)) - * = 2s + 2s*z*R(z) ...z=(1-x)/2, s=sqrt(z) - * = 2f + (2c + 2s*z*R(z)) - * where f=hi part of s, and c = (z-f*f)/(s+f) is the correction term - * for f so that f+c ~ sqrt(z). - * For x<-0.5 - * acos(x) = pi - 2asin(sqrt((1-|x|)/2)) - * = pi - 0.5*(s+s*z*R(z)), where z=(1-|x|)/2,s=sqrt(z) - * - * Special cases: - * if x is NaN, return x itself; - * if |x|>1, return NaN with invalid signal. - * - * Function needed: sqrt - */ - -#include -#include "math_private.h" - -static const double -one= 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */ -pi = 3.14159265358979311600e+00, /* 0x400921FB, 0x54442D18 */ -pio2_hi = 1.57079632679489655800e+00, /* 0x3FF921FB, 0x54442D18 */ -pio2_lo = 6.12323399573676603587e-17, /* 0x3C91A626, 0x33145C07 */ -pS0 = 1.66666666666666657415e-01, /* 0x3FC55555, 0x55555555 */ -pS1 = -3.25565818622400915405e-01, /* 0xBFD4D612, 0x03EB6F7D */ -pS2 = 2.01212532134862925881e-01, /* 0x3FC9C155, 0x0E884455 */ -pS3 = -4.00555345006794114027e-02, /* 0xBFA48228, 0xB5688F3B */ -pS4 = 7.91534994289814532176e-04, /* 0x3F49EFE0, 0x7501B288 */ -pS5 = 3.47933107596021167570e-05, /* 0x3F023DE1, 0x0DFDF709 */ -qS1 = -2.40339491173441421878e+00, /* 0xC0033A27, 0x1C8A2D4B */ -qS2 = 2.02094576023350569471e+00, /* 0x40002AE5, 0x9C598AC8 */ -qS3 = -6.88283971605453293030e-01, /* 0xBFE6066C, 0x1B8D0159 */ -qS4 = 7.70381505559019352791e-02; /* 0x3FB3B8C5, 0xB12E9282 */ - -double -acos(double x) -{ - double z,p,q,r,w,s,c,df; - int32_t hx,ix; - GET_HIGH_WORD(hx,x); - ix = hx&0x7fffffff; - if(ix>=0x3ff00000) { /* |x| >= 1 */ - uint32_t lx; - GET_LOW_WORD(lx,x); - if(((ix-0x3ff00000)|lx)==0) { /* |x|==1 */ - if(hx>0) return 0.0; /* acos(1) = 0 */ - else return pi+2.0*pio2_lo; /* acos(-1)= pi */ - } - return (x-x)/(x-x); /* acos(|x|>1) is NaN */ - } - if(ix<0x3fe00000) { /* |x| < 0.5 */ - if(ix<=0x3c600000) return pio2_hi+pio2_lo;/*if|x|<2**-57*/ - z = x*x; - p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5))))); - q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4))); - r = p/q; - return pio2_hi - (x - (pio2_lo-x*r)); - } else if (hx<0) { /* x < -0.5 */ - z = (one+x)*0.5; - p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5))))); - q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4))); - s = sqrt(z); - r = p/q; - w = r*s-pio2_lo; - return pi - 2.0*(s+w); - } else { /* x > 0.5 */ - z = (one-x)*0.5; - s = sqrt(z); - df = s; - SET_LOW_WORD(df,0); - c = (z-df*df)/(s+df); - p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5))))); - q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4))); - r = p/q; - w = r*s+c; - return 2.0*(df+w); - } -} diff --git a/05/musl-final/src/math/e_acosf.c b/05/musl-final/src/math/e_acosf.c deleted file mode 100644 index 4c59781..0000000 --- a/05/musl-final/src/math/e_acosf.c +++ /dev/null @@ -1,77 +0,0 @@ -/* e_acosf.c -- float version of e_acos.c. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include -#include "math_private.h" - -static const float -one = 1.0000000000e+00, /* 0x3F800000 */ -pi = 3.1415925026e+00, /* 0x40490fda */ -pio2_hi = 1.5707962513e+00, /* 0x3fc90fda */ -pio2_lo = 7.5497894159e-08, /* 0x33a22168 */ -pS0 = 1.6666667163e-01, /* 0x3e2aaaab */ -pS1 = -3.2556581497e-01, /* 0xbea6b090 */ -pS2 = 2.0121252537e-01, /* 0x3e4e0aa8 */ -pS3 = -4.0055535734e-02, /* 0xbd241146 */ -pS4 = 7.9153501429e-04, /* 0x3a4f7f04 */ -pS5 = 3.4793309169e-05, /* 0x3811ef08 */ -qS1 = -2.4033949375e+00, /* 0xc019d139 */ -qS2 = 2.0209457874e+00, /* 0x4001572d */ -qS3 = -6.8828397989e-01, /* 0xbf303361 */ -qS4 = 7.7038154006e-02; /* 0x3d9dc62e */ - -float -acosf(float x) -{ - float z,p,q,r,w,s,c,df; - int32_t hx,ix; - GET_FLOAT_WORD(hx,x); - ix = hx&0x7fffffff; - if(ix==0x3f800000) { /* |x|==1 */ - if(hx>0) return 0.0; /* acos(1) = 0 */ - else return pi+(float)2.0*pio2_lo; /* acos(-1)= pi */ - } else if(ix>0x3f800000) { /* |x| >= 1 */ - return (x-x)/(x-x); /* acos(|x|>1) is NaN */ - } - if(ix<0x3f000000) { /* |x| < 0.5 */ - if(ix<=0x23000000) return pio2_hi+pio2_lo;/*if|x|<2**-57*/ - z = x*x; - p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5))))); - q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4))); - r = p/q; - return pio2_hi - (x - (pio2_lo-x*r)); - } else if (hx<0) { /* x < -0.5 */ - z = (one+x)*(float)0.5; - p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5))))); - q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4))); - s = sqrtf(z); - r = p/q; - w = r*s-pio2_lo; - return pi - (float)2.0*(s+w); - } else { /* x > 0.5 */ - int32_t idf; - z = (one-x)*(float)0.5; - s = sqrtf(z); - df = s; - GET_FLOAT_WORD(idf,df); - SET_FLOAT_WORD(df,idf&0xfffff000); - c = (z-df*df)/(s+df); - p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5))))); - q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4))); - r = p/q; - w = r*s+c; - return (float)2.0*(df+w); - } -} diff --git a/05/musl-final/src/math/e_acosh.c b/05/musl-final/src/math/e_acosh.c deleted file mode 100644 index 8b454e7..0000000 --- a/05/musl-final/src/math/e_acosh.c +++ /dev/null @@ -1,59 +0,0 @@ - -/* @(#)e_acosh.c 1.3 95/01/18 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - * - */ - -/* acosh(x) - * Method : - * Based on - * acosh(x) = log [ x + sqrt(x*x-1) ] - * we have - * acosh(x) := log(x)+ln2, if x is large; else - * acosh(x) := log(2x-1/(sqrt(x*x-1)+x)) if x>2; else - * acosh(x) := log1p(t+sqrt(2.0*t+t*t)); where t=x-1. - * - * Special cases: - * acosh(x) is NaN with signal if x<1. - * acosh(NaN) is NaN without signal. - */ - -#include -#include "math_private.h" - -static const double -one = 1.0, -ln2 = 6.93147180559945286227e-01; /* 0x3FE62E42, 0xFEFA39EF */ - -double -acosh(double x) -{ - double t; - int32_t hx; - uint32_t lx; - EXTRACT_WORDS(hx,lx,x); - if(hx<0x3ff00000) { /* x < 1 */ - return (x-x)/(x-x); - } else if(hx >=0x41b00000) { /* x > 2**28 */ - if(hx >=0x7ff00000) { /* x is inf of NaN */ - return x+x; - } else - return log(x)+ln2; /* acosh(huge)=log(2x) */ - } else if(((hx-0x3ff00000)|lx)==0) { - return 0.0; /* acosh(1) = 0 */ - } else if (hx > 0x40000000) { /* 2**28 > x > 2 */ - t=x*x; - return log(2.0*x-one/(x+sqrt(t-one))); - } else { /* 1 -#include "math_private.h" - -static const float -one = 1.0, -ln2 = 6.9314718246e-01; /* 0x3f317218 */ - -float -acoshf(float x) -{ - float t; - int32_t hx; - GET_FLOAT_WORD(hx,x); - if(hx<0x3f800000) { /* x < 1 */ - return (x-x)/(x-x); - } else if(hx >=0x4d800000) { /* x > 2**28 */ - if(hx >=0x7f800000) { /* x is inf of NaN */ - return x+x; - } else - return logf(x)+ln2; /* acosh(huge)=log(2x) */ - } else if (hx==0x3f800000) { - return 0.0; /* acosh(1) = 0 */ - } else if (hx > 0x40000000) { /* 2**28 > x > 2 */ - t=x*x; - return logf((float)2.0*x-one/(x+sqrtf(t-one))); - } else { /* 10.98 - * asin(x) = pi/2 - 2*(s+s*z*R(z)) - * = pio2_hi - (2*(s+s*z*R(z)) - pio2_lo) - * For x<=0.98, let pio4_hi = pio2_hi/2, then - * f = hi part of s; - * c = sqrt(z) - f = (z-f*f)/(s+f) ...f+c=sqrt(z) - * and - * asin(x) = pi/2 - 2*(s+s*z*R(z)) - * = pio4_hi+(pio4-2s)-(2s*z*R(z)-pio2_lo) - * = pio4_hi+(pio4-2f)-(2s*z*R(z)-(pio2_lo+2c)) - * - * Special cases: - * if x is NaN, return x itself; - * if |x|>1, return NaN with invalid signal. - * - */ - - -#include -#include "math_private.h" - -static const double -one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */ -huge = 1.000e+300, -pio2_hi = 1.57079632679489655800e+00, /* 0x3FF921FB, 0x54442D18 */ -pio2_lo = 6.12323399573676603587e-17, /* 0x3C91A626, 0x33145C07 */ -pio4_hi = 7.85398163397448278999e-01, /* 0x3FE921FB, 0x54442D18 */ - /* coefficient for R(x^2) */ -pS0 = 1.66666666666666657415e-01, /* 0x3FC55555, 0x55555555 */ -pS1 = -3.25565818622400915405e-01, /* 0xBFD4D612, 0x03EB6F7D */ -pS2 = 2.01212532134862925881e-01, /* 0x3FC9C155, 0x0E884455 */ -pS3 = -4.00555345006794114027e-02, /* 0xBFA48228, 0xB5688F3B */ -pS4 = 7.91534994289814532176e-04, /* 0x3F49EFE0, 0x7501B288 */ -pS5 = 3.47933107596021167570e-05, /* 0x3F023DE1, 0x0DFDF709 */ -qS1 = -2.40339491173441421878e+00, /* 0xC0033A27, 0x1C8A2D4B */ -qS2 = 2.02094576023350569471e+00, /* 0x40002AE5, 0x9C598AC8 */ -qS3 = -6.88283971605453293030e-01, /* 0xBFE6066C, 0x1B8D0159 */ -qS4 = 7.70381505559019352791e-02; /* 0x3FB3B8C5, 0xB12E9282 */ - -double -asin(double x) -{ - double t=0.0,w,p,q,c,r,s; - int32_t hx,ix; - GET_HIGH_WORD(hx,x); - ix = hx&0x7fffffff; - if(ix>= 0x3ff00000) { /* |x|>= 1 */ - uint32_t lx; - GET_LOW_WORD(lx,x); - if(((ix-0x3ff00000)|lx)==0) - /* asin(1)=+-pi/2 with inexact */ - return x*pio2_hi+x*pio2_lo; - return (x-x)/(x-x); /* asin(|x|>1) is NaN */ - } else if (ix<0x3fe00000) { /* |x|<0.5 */ - if(ix<0x3e400000) { /* if |x| < 2**-27 */ - if(huge+x>one) return x;/* return x with inexact if x!=0*/ - } else - t = x*x; - p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5))))); - q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4))); - w = p/q; - return x+x*w; - } - /* 1> |x|>= 0.5 */ - w = one-fabs(x); - t = w*0.5; - p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5))))); - q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4))); - s = sqrt(t); - if(ix>=0x3FEF3333) { /* if |x| > 0.975 */ - w = p/q; - t = pio2_hi-(2.0*(s+s*w)-pio2_lo); - } else { - w = s; - SET_LOW_WORD(w,0); - c = (t-w*w)/(s+w); - r = p/q; - p = 2.0*s*r-(pio2_lo-2.0*c); - q = pio4_hi-2.0*w; - t = pio4_hi-(p-q); - } - if(hx>0) return t; else return -t; -} diff --git a/05/musl-final/src/math/e_asinf.c b/05/musl-final/src/math/e_asinf.c deleted file mode 100644 index 9c69397..0000000 --- a/05/musl-final/src/math/e_asinf.c +++ /dev/null @@ -1,80 +0,0 @@ -/* e_asinf.c -- float version of e_asin.c. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include -#include "math_private.h" - -static const float -one = 1.0000000000e+00, /* 0x3F800000 */ -huge = 1.000e+30, -pio2_hi = 1.5707962513e+00, /* 0x3fc90fda */ -pio2_lo = 7.5497894159e-08, /* 0x33a22168 */ -pio4_hi = 7.8539818525e-01, /* 0x3f490fdb */ - /* coefficient for R(x^2) */ -pS0 = 1.6666667163e-01, /* 0x3e2aaaab */ -pS1 = -3.2556581497e-01, /* 0xbea6b090 */ -pS2 = 2.0121252537e-01, /* 0x3e4e0aa8 */ -pS3 = -4.0055535734e-02, /* 0xbd241146 */ -pS4 = 7.9153501429e-04, /* 0x3a4f7f04 */ -pS5 = 3.4793309169e-05, /* 0x3811ef08 */ -qS1 = -2.4033949375e+00, /* 0xc019d139 */ -qS2 = 2.0209457874e+00, /* 0x4001572d */ -qS3 = -6.8828397989e-01, /* 0xbf303361 */ -qS4 = 7.7038154006e-02; /* 0x3d9dc62e */ - -float -asinf(float x) -{ - float t=0.0,w,p,q,c,r,s; - int32_t hx,ix; - GET_FLOAT_WORD(hx,x); - ix = hx&0x7fffffff; - if(ix==0x3f800000) { - /* asin(1)=+-pi/2 with inexact */ - return x*pio2_hi+x*pio2_lo; - } else if(ix> 0x3f800000) { /* |x|>= 1 */ - return (x-x)/(x-x); /* asin(|x|>1) is NaN */ - } else if (ix<0x3f000000) { /* |x|<0.5 */ - if(ix<0x32000000) { /* if |x| < 2**-27 */ - if(huge+x>one) return x;/* return x with inexact if x!=0*/ - } else - t = x*x; - p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5))))); - q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4))); - w = p/q; - return x+x*w; - } - /* 1> |x|>= 0.5 */ - w = one-fabsf(x); - t = w*(float)0.5; - p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5))))); - q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4))); - s = sqrtf(t); - if(ix>=0x3F79999A) { /* if |x| > 0.975 */ - w = p/q; - t = pio2_hi-((float)2.0*(s+s*w)-pio2_lo); - } else { - int32_t iw; - w = s; - GET_FLOAT_WORD(iw,w); - SET_FLOAT_WORD(w,iw&0xfffff000); - c = (t-w*w)/(s+w); - r = p/q; - p = (float)2.0*s*r-(pio2_lo-(float)2.0*c); - q = pio4_hi-(float)2.0*w; - t = pio4_hi-(p-q); - } - if(hx>0) return t; else return -t; -} diff --git a/05/musl-final/src/math/e_atan2.c b/05/musl-final/src/math/e_atan2.c deleted file mode 100644 index dd02116..0000000 --- a/05/musl-final/src/math/e_atan2.c +++ /dev/null @@ -1,120 +0,0 @@ - -/* @(#)e_atan2.c 1.3 95/01/18 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - * - */ - -/* atan2(y,x) - * Method : - * 1. Reduce y to positive by atan2(y,x)=-atan2(-y,x). - * 2. Reduce x to positive by (if x and y are unexceptional): - * ARG (x+iy) = arctan(y/x) ... if x > 0, - * ARG (x+iy) = pi - arctan[y/(-x)] ... if x < 0, - * - * Special cases: - * - * ATAN2((anything), NaN ) is NaN; - * ATAN2(NAN , (anything) ) is NaN; - * ATAN2(+-0, +(anything but NaN)) is +-0 ; - * ATAN2(+-0, -(anything but NaN)) is +-pi ; - * ATAN2(+-(anything but 0 and NaN), 0) is +-pi/2; - * ATAN2(+-(anything but INF and NaN), +INF) is +-0 ; - * ATAN2(+-(anything but INF and NaN), -INF) is +-pi; - * ATAN2(+-INF,+INF ) is +-pi/4 ; - * ATAN2(+-INF,-INF ) is +-3pi/4; - * ATAN2(+-INF, (anything but,0,NaN, and INF)) is +-pi/2; - * - * Constants: - * The hexadecimal values are the intended ones for the following - * constants. The decimal values may be used, provided that the - * compiler will convert from decimal to binary accurately enough - * to produce the hexadecimal values shown. - */ - -#include -#include "math_private.h" - -static const double -tiny = 1.0e-300, -zero = 0.0, -pi_o_4 = 7.8539816339744827900E-01, /* 0x3FE921FB, 0x54442D18 */ -pi_o_2 = 1.5707963267948965580E+00, /* 0x3FF921FB, 0x54442D18 */ -pi = 3.1415926535897931160E+00, /* 0x400921FB, 0x54442D18 */ -pi_lo = 1.2246467991473531772E-16; /* 0x3CA1A626, 0x33145C07 */ - -double -atan2(double y, double x) -{ - double z; - int32_t k,m,hx,hy,ix,iy; - uint32_t lx,ly; - - EXTRACT_WORDS(hx,lx,x); - ix = hx&0x7fffffff; - EXTRACT_WORDS(hy,ly,y); - iy = hy&0x7fffffff; - if(((ix|((lx|-lx)>>31))>0x7ff00000)|| - ((iy|((ly|-ly)>>31))>0x7ff00000)) /* x or y is NaN */ - return x+y; - if(((hx-0x3ff00000)|lx)==0) return atan(y); /* x=1.0 */ - m = ((hy>>31)&1)|((hx>>30)&2); /* 2*sign(x)+sign(y) */ - - /* when y = 0 */ - if((iy|ly)==0) { - switch(m) { - case 0: - case 1: return y; /* atan(+-0,+anything)=+-0 */ - case 2: return pi+tiny;/* atan(+0,-anything) = pi */ - case 3: return -pi-tiny;/* atan(-0,-anything) =-pi */ - } - } - /* when x = 0 */ - if((ix|lx)==0) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny; - - /* when x is INF */ - if(ix==0x7ff00000) { - if(iy==0x7ff00000) { - switch(m) { - case 0: return pi_o_4+tiny;/* atan(+INF,+INF) */ - case 1: return -pi_o_4-tiny;/* atan(-INF,+INF) */ - case 2: return 3.0*pi_o_4+tiny;/*atan(+INF,-INF)*/ - case 3: return -3.0*pi_o_4-tiny;/*atan(-INF,-INF)*/ - } - } else { - switch(m) { - case 0: return zero ; /* atan(+...,+INF) */ - case 1: return -zero ; /* atan(-...,+INF) */ - case 2: return pi+tiny ; /* atan(+...,-INF) */ - case 3: return -pi-tiny ; /* atan(-...,-INF) */ - } - } - } - /* when y is INF */ - if(iy==0x7ff00000) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny; - - /* compute y/x */ - k = (iy-ix)>>20; - if(k > 60) z=pi_o_2+0.5*pi_lo; /* |y/x| > 2**60 */ - else if(hx<0&&k<-60) z=0.0; /* |y|/x < -2**60 */ - else z=atan(fabs(y/x)); /* safe to do y/x */ - switch (m) { - case 0: return z ; /* atan(+,+) */ - case 1: { - uint32_t zh; - GET_HIGH_WORD(zh,z); - SET_HIGH_WORD(z,zh ^ 0x80000000); - } - return z ; /* atan(-,+) */ - case 2: return pi-(z-pi_lo);/* atan(+,-) */ - default: /* case 3 */ - return (z-pi_lo)-pi;/* atan(-,-) */ - } -} diff --git a/05/musl-final/src/math/e_atan2f.c b/05/musl-final/src/math/e_atan2f.c deleted file mode 100644 index 535e10a..0000000 --- a/05/musl-final/src/math/e_atan2f.c +++ /dev/null @@ -1,93 +0,0 @@ -/* e_atan2f.c -- float version of e_atan2.c. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include -#include "math_private.h" - -static const float -tiny = 1.0e-30, -zero = 0.0, -pi_o_4 = 7.8539818525e-01, /* 0x3f490fdb */ -pi_o_2 = 1.5707963705e+00, /* 0x3fc90fdb */ -pi = 3.1415927410e+00, /* 0x40490fdb */ -pi_lo = -8.7422776573e-08; /* 0xb3bbbd2e */ - -float -atan2f(float y, float x) -{ - float z; - int32_t k,m,hx,hy,ix,iy; - - GET_FLOAT_WORD(hx,x); - ix = hx&0x7fffffff; - GET_FLOAT_WORD(hy,y); - iy = hy&0x7fffffff; - if((ix>0x7f800000)|| - (iy>0x7f800000)) /* x or y is NaN */ - return x+y; - if(hx==0x3f800000) return atanf(y); /* x=1.0 */ - m = ((hy>>31)&1)|((hx>>30)&2); /* 2*sign(x)+sign(y) */ - - /* when y = 0 */ - if(iy==0) { - switch(m) { - case 0: - case 1: return y; /* atan(+-0,+anything)=+-0 */ - case 2: return pi+tiny;/* atan(+0,-anything) = pi */ - case 3: return -pi-tiny;/* atan(-0,-anything) =-pi */ - } - } - /* when x = 0 */ - if(ix==0) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny; - - /* when x is INF */ - if(ix==0x7f800000) { - if(iy==0x7f800000) { - switch(m) { - case 0: return pi_o_4+tiny;/* atan(+INF,+INF) */ - case 1: return -pi_o_4-tiny;/* atan(-INF,+INF) */ - case 2: return (float)3.0*pi_o_4+tiny;/*atan(+INF,-INF)*/ - case 3: return (float)-3.0*pi_o_4-tiny;/*atan(-INF,-INF)*/ - } - } else { - switch(m) { - case 0: return zero ; /* atan(+...,+INF) */ - case 1: return -zero ; /* atan(-...,+INF) */ - case 2: return pi+tiny ; /* atan(+...,-INF) */ - case 3: return -pi-tiny ; /* atan(-...,-INF) */ - } - } - } - /* when y is INF */ - if(iy==0x7f800000) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny; - - /* compute y/x */ - k = (iy-ix)>>23; - if(k > 60) z=pi_o_2+(float)0.5*pi_lo; /* |y/x| > 2**60 */ - else if(hx<0&&k<-60) z=0.0; /* |y|/x < -2**60 */ - else z=atanf(fabsf(y/x)); /* safe to do y/x */ - switch (m) { - case 0: return z ; /* atan(+,+) */ - case 1: { - uint32_t zh; - GET_FLOAT_WORD(zh,z); - SET_FLOAT_WORD(z,zh ^ 0x80000000); - } - return z ; /* atan(-,+) */ - case 2: return pi-(z-pi_lo);/* atan(+,-) */ - default: /* case 3 */ - return (z-pi_lo)-pi;/* atan(-,-) */ - } -} diff --git a/05/musl-final/src/math/e_atanh.c b/05/musl-final/src/math/e_atanh.c deleted file mode 100644 index 45f1c96..0000000 --- a/05/musl-final/src/math/e_atanh.c +++ /dev/null @@ -1,59 +0,0 @@ - -/* @(#)e_atanh.c 1.3 95/01/18 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - * - */ - -/* atanh(x) - * Method : - * 1.Reduced x to positive by atanh(-x) = -atanh(x) - * 2.For x>=0.5 - * 1 2x x - * atanh(x) = --- * log(1 + -------) = 0.5 * log1p(2 * --------) - * 2 1 - x 1 - x - * - * For x<0.5 - * atanh(x) = 0.5*log1p(2x+2x*x/(1-x)) - * - * Special cases: - * atanh(x) is NaN if |x| > 1 with signal; - * atanh(NaN) is that NaN with no signal; - * atanh(+-1) is +-INF with signal. - * - */ - -#include -#include "math_private.h" - -static const double one = 1.0, huge = 1e300; -static const double zero = 0.0; - -double -atanh(double x) -{ - double t; - int32_t hx,ix; - uint32_t lx; - EXTRACT_WORDS(hx,lx,x); - ix = hx&0x7fffffff; - if ((ix|((lx|(-lx))>>31))>0x3ff00000) /* |x|>1 */ - return (x-x)/(x-x); - if(ix==0x3ff00000) - return x/zero; - if(ix<0x3e300000&&(huge+x)>zero) return x; /* x<2**-28 */ - SET_HIGH_WORD(x,ix); - if(ix<0x3fe00000) { /* x < 0.5 */ - t = x+x; - t = 0.5*log1p(t+t*x/(one-x)); - } else - t = 0.5*log1p((x+x)/(one-x)); - if(hx>=0) return t; else return -t; -} diff --git a/05/musl-final/src/math/e_atanhf.c b/05/musl-final/src/math/e_atanhf.c deleted file mode 100644 index 7356cfc..0000000 --- a/05/musl-final/src/math/e_atanhf.c +++ /dev/null @@ -1,42 +0,0 @@ -/* e_atanhf.c -- float version of e_atanh.c. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include -#include "math_private.h" - -static const float one = 1.0, huge = 1e30; - -static const float zero = 0.0; - -float -atanhf(float x) -{ - float t; - int32_t hx,ix; - GET_FLOAT_WORD(hx,x); - ix = hx&0x7fffffff; - if (ix>0x3f800000) /* |x|>1 */ - return (x-x)/(x-x); - if(ix==0x3f800000) - return x/zero; - if(ix<0x31800000&&(huge+x)>zero) return x; /* x<2**-28 */ - SET_FLOAT_WORD(x,ix); - if(ix<0x3f000000) { /* x < 0.5 */ - t = x+x; - t = (float)0.5*log1pf(t+t*x/(one-x)); - } else - t = (float)0.5*log1pf((x+x)/(one-x)); - if(hx>=0) return t; else return -t; -} diff --git a/05/musl-final/src/math/e_cosh.c b/05/musl-final/src/math/e_cosh.c deleted file mode 100644 index ad425bd..0000000 --- a/05/musl-final/src/math/e_cosh.c +++ /dev/null @@ -1,82 +0,0 @@ - -/* @(#)e_cosh.c 1.3 95/01/18 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* cosh(x) - * Method : - * mathematically cosh(x) if defined to be (exp(x)+exp(-x))/2 - * 1. Replace x by |x| (cosh(x) = cosh(-x)). - * 2. - * [ exp(x) - 1 ]^2 - * 0 <= x <= ln2/2 : cosh(x) := 1 + ------------------- - * 2*exp(x) - * - * exp(x) + 1/exp(x) - * ln2/2 <= x <= 22 : cosh(x) := ------------------- - * 2 - * 22 <= x <= lnovft : cosh(x) := exp(x)/2 - * lnovft <= x <= ln2ovft: cosh(x) := exp(x/2)/2 * exp(x/2) - * ln2ovft < x : cosh(x) := huge*huge (overflow) - * - * Special cases: - * cosh(x) is |x| if x is +INF, -INF, or NaN. - * only cosh(0)=1 is exact for finite x. - */ - -#include -#include "math_private.h" - -static const double one = 1.0, half=0.5, huge = 1.0e300; - -double -cosh(double x) -{ - double t,w; - int32_t ix; - uint32_t lx; - - /* High word of |x|. */ - GET_HIGH_WORD(ix,x); - ix &= 0x7fffffff; - - /* x is INF or NaN */ - if(ix>=0x7ff00000) return x*x; - - /* |x| in [0,0.5*ln2], return 1+expm1(|x|)^2/(2*exp(|x|)) */ - if(ix<0x3fd62e43) { - t = expm1(fabs(x)); - w = one+t; - if (ix<0x3c800000) return w; /* cosh(tiny) = 1 */ - return one+(t*t)/(w+w); - } - - /* |x| in [0.5*ln2,22], return (exp(|x|)+1/exp(|x|)/2; */ - if (ix < 0x40360000) { - t = exp(fabs(x)); - return half*t+half/t; - } - - /* |x| in [22, log(maxdouble)] return half*exp(|x|) */ - if (ix < 0x40862E42) return half*exp(fabs(x)); - - /* |x| in [log(maxdouble), overflowthresold] */ - GET_LOW_WORD(lx,x); - if (ix<0x408633CE || - ((ix==0x408633ce)&&(lx<=(uint32_t)0x8fb9f87d))) { - w = exp(half*fabs(x)); - t = half*w; - return t*w; - } - - /* |x| > overflowthresold, cosh(x) overflow */ - return huge*huge; -} diff --git a/05/musl-final/src/math/e_coshf.c b/05/musl-final/src/math/e_coshf.c deleted file mode 100644 index 6db1088..0000000 --- a/05/musl-final/src/math/e_coshf.c +++ /dev/null @@ -1,59 +0,0 @@ -/* e_coshf.c -- float version of e_cosh.c. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include -#include "math_private.h" - -static const float one = 1.0, half=0.5, huge = 1.0e30; - -float -coshf(float x) -{ - float t,w; - int32_t ix; - - GET_FLOAT_WORD(ix,x); - ix &= 0x7fffffff; - - /* x is INF or NaN */ - if(ix>=0x7f800000) return x*x; - - /* |x| in [0,0.5*ln2], return 1+expm1(|x|)^2/(2*exp(|x|)) */ - if(ix<0x3eb17218) { - t = expm1f(fabsf(x)); - w = one+t; - if (ix<0x24000000) return w; /* cosh(tiny) = 1 */ - return one+(t*t)/(w+w); - } - - /* |x| in [0.5*ln2,22], return (exp(|x|)+1/exp(|x|)/2; */ - if (ix < 0x41b00000) { - t = expf(fabsf(x)); - return half*t+half/t; - } - - /* |x| in [22, log(maxdouble)] return half*exp(|x|) */ - if (ix < 0x42b17180) return half*expf(fabsf(x)); - - /* |x| in [log(maxdouble), overflowthresold] */ - if (ix<=0x42b2d4fc) { - w = expf(half*fabsf(x)); - t = half*w; - return t*w; - } - - /* |x| > overflowthresold, cosh(x) overflow */ - return huge*huge; -} diff --git a/05/musl-final/src/math/e_exp.c b/05/musl-final/src/math/e_exp.c deleted file mode 100644 index 66107b9..0000000 --- a/05/musl-final/src/math/e_exp.c +++ /dev/null @@ -1,155 +0,0 @@ - -/* @(#)e_exp.c 1.6 04/04/22 */ -/* - * ==================================================== - * Copyright (C) 2004 by Sun Microsystems, Inc. All rights reserved. - * - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* exp(x) - * Returns the exponential of x. - * - * Method - * 1. Argument reduction: - * Reduce x to an r so that |r| <= 0.5*ln2 ~ 0.34658. - * Given x, find r and integer k such that - * - * x = k*ln2 + r, |r| <= 0.5*ln2. - * - * Here r will be represented as r = hi-lo for better - * accuracy. - * - * 2. Approximation of exp(r) by a special rational function on - * the interval [0,0.34658]: - * Write - * R(r**2) = r*(exp(r)+1)/(exp(r)-1) = 2 + r*r/6 - r**4/360 + ... - * We use a special Remes algorithm on [0,0.34658] to generate - * a polynomial of degree 5 to approximate R. The maximum error - * of this polynomial approximation is bounded by 2**-59. In - * other words, - * R(z) ~ 2.0 + P1*z + P2*z**2 + P3*z**3 + P4*z**4 + P5*z**5 - * (where z=r*r, and the values of P1 to P5 are listed below) - * and - * | 5 | -59 - * | 2.0+P1*z+...+P5*z - R(z) | <= 2 - * | | - * The computation of exp(r) thus becomes - * 2*r - * exp(r) = 1 + ------- - * R - r - * r*R1(r) - * = 1 + r + ----------- (for better accuracy) - * 2 - R1(r) - * where - * 2 4 10 - * R1(r) = r - (P1*r + P2*r + ... + P5*r ). - * - * 3. Scale back to obtain exp(x): - * From step 1, we have - * exp(x) = 2^k * exp(r) - * - * Special cases: - * exp(INF) is INF, exp(NaN) is NaN; - * exp(-INF) is 0, and - * for finite argument, only exp(0)=1 is exact. - * - * Accuracy: - * according to an error analysis, the error is always less than - * 1 ulp (unit in the last place). - * - * Misc. info. - * For IEEE double - * if x > 7.09782712893383973096e+02 then exp(x) overflow - * if x < -7.45133219101941108420e+02 then exp(x) underflow - * - * Constants: - * The hexadecimal values are the intended ones for the following - * constants. The decimal values may be used, provided that the - * compiler will convert from decimal to binary accurately enough - * to produce the hexadecimal values shown. - */ - -#include -#include "math_private.h" - -static const double -one = 1.0, -halF[2] = {0.5,-0.5,}, -huge = 1.0e+300, -twom1000= 9.33263618503218878990e-302, /* 2**-1000=0x01700000,0*/ -o_threshold= 7.09782712893383973096e+02, /* 0x40862E42, 0xFEFA39EF */ -u_threshold= -7.45133219101941108420e+02, /* 0xc0874910, 0xD52D3051 */ -ln2HI[2] ={ 6.93147180369123816490e-01, /* 0x3fe62e42, 0xfee00000 */ - -6.93147180369123816490e-01,},/* 0xbfe62e42, 0xfee00000 */ -ln2LO[2] ={ 1.90821492927058770002e-10, /* 0x3dea39ef, 0x35793c76 */ - -1.90821492927058770002e-10,},/* 0xbdea39ef, 0x35793c76 */ -invln2 = 1.44269504088896338700e+00, /* 0x3ff71547, 0x652b82fe */ -P1 = 1.66666666666666019037e-01, /* 0x3FC55555, 0x5555553E */ -P2 = -2.77777777770155933842e-03, /* 0xBF66C16C, 0x16BEBD93 */ -P3 = 6.61375632143793436117e-05, /* 0x3F11566A, 0xAF25DE2C */ -P4 = -1.65339022054652515390e-06, /* 0xBEBBBD41, 0xC5D26BF1 */ -P5 = 4.13813679705723846039e-08; /* 0x3E663769, 0x72BEA4D0 */ - - -double -exp(double x) /* default IEEE double exp */ -{ - double y,hi=0.0,lo=0.0,c,t; - int32_t k=0,xsb; - uint32_t hx; - - GET_HIGH_WORD(hx,x); - xsb = (hx>>31)&1; /* sign bit of x */ - hx &= 0x7fffffff; /* high word of |x| */ - - /* filter out non-finite argument */ - if(hx >= 0x40862E42) { /* if |x|>=709.78... */ - if(hx>=0x7ff00000) { - uint32_t lx; - GET_LOW_WORD(lx,x); - if(((hx&0xfffff)|lx)!=0) - return x+x; /* NaN */ - else return (xsb==0)? x:0.0; /* exp(+-inf)={inf,0} */ - } - if(x > o_threshold) return huge*huge; /* overflow */ - if(x < u_threshold) return twom1000*twom1000; /* underflow */ - } - - /* argument reduction */ - if(hx > 0x3fd62e42) { /* if |x| > 0.5 ln2 */ - if(hx < 0x3FF0A2B2) { /* and |x| < 1.5 ln2 */ - hi = x-ln2HI[xsb]; lo=ln2LO[xsb]; k = 1-xsb-xsb; - } else { - k = (int)(invln2*x+halF[xsb]); - t = k; - hi = x - t*ln2HI[0]; /* t*ln2HI is exact here */ - lo = t*ln2LO[0]; - } - x = hi - lo; - } - else if(hx < 0x3e300000) { /* when |x|<2**-28 */ - if(huge+x>one) return one+x;/* trigger inexact */ - } - else k = 0; - - /* x is now in primary range */ - t = x*x; - c = x - t*(P1+t*(P2+t*(P3+t*(P4+t*P5)))); - if(k==0) return one-((x*c)/(c-2.0)-x); - else y = one-((lo-(x*c)/(2.0-c))-hi); - if(k >= -1021) { - uint32_t hy; - GET_HIGH_WORD(hy,y); - SET_HIGH_WORD(y,hy+(k<<20)); /* add k to y's exponent */ - return y; - } else { - uint32_t hy; - GET_HIGH_WORD(hy,y); - SET_HIGH_WORD(y,hy+((k+1000)<<20)); /* add k to y's exponent */ - return y*twom1000; - } -} diff --git a/05/musl-final/src/math/e_expf.c b/05/musl-final/src/math/e_expf.c deleted file mode 100644 index 99818ed..0000000 --- a/05/musl-final/src/math/e_expf.c +++ /dev/null @@ -1,91 +0,0 @@ -/* e_expf.c -- float version of e_exp.c. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include -#include "math_private.h" - -static const float -one = 1.0, -halF[2] = {0.5,-0.5,}, -huge = 1.0e+30, -twom100 = 7.8886090522e-31, /* 2**-100=0x0d800000 */ -o_threshold= 8.8721679688e+01, /* 0x42b17180 */ -u_threshold= -1.0397208405e+02, /* 0xc2cff1b5 */ -ln2HI[2] ={ 6.9313812256e-01, /* 0x3f317180 */ - -6.9313812256e-01,}, /* 0xbf317180 */ -ln2LO[2] ={ 9.0580006145e-06, /* 0x3717f7d1 */ - -9.0580006145e-06,}, /* 0xb717f7d1 */ -invln2 = 1.4426950216e+00, /* 0x3fb8aa3b */ -P1 = 1.6666667163e-01, /* 0x3e2aaaab */ -P2 = -2.7777778450e-03, /* 0xbb360b61 */ -P3 = 6.6137559770e-05, /* 0x388ab355 */ -P4 = -1.6533901999e-06, /* 0xb5ddea0e */ -P5 = 4.1381369442e-08; /* 0x3331bb4c */ - -float -expf(float x) /* default IEEE double exp */ -{ - float y,hi=0.0,lo=0.0,c,t; - int32_t k=0,xsb; - uint32_t hx; - - GET_FLOAT_WORD(hx,x); - xsb = (hx>>31)&1; /* sign bit of x */ - hx &= 0x7fffffff; /* high word of |x| */ - - /* filter out non-finite argument */ - if(hx >= 0x42b17218) { /* if |x|>=88.721... */ - if(hx>0x7f800000) - return x+x; /* NaN */ - if(hx==0x7f800000) - return (xsb==0)? x:0.0; /* exp(+-inf)={inf,0} */ - if(x > o_threshold) return huge*huge; /* overflow */ - if(x < u_threshold) return twom100*twom100; /* underflow */ - } - - /* argument reduction */ - if(hx > 0x3eb17218) { /* if |x| > 0.5 ln2 */ - if(hx < 0x3F851592) { /* and |x| < 1.5 ln2 */ - hi = x-ln2HI[xsb]; lo=ln2LO[xsb]; k = 1-xsb-xsb; - } else { - k = invln2*x+halF[xsb]; - t = k; - hi = x - t*ln2HI[0]; /* t*ln2HI is exact here */ - lo = t*ln2LO[0]; - } - x = hi - lo; - } - else if(hx < 0x31800000) { /* when |x|<2**-28 */ - if(huge+x>one) return one+x;/* trigger inexact */ - } - else k = 0; - - /* x is now in primary range */ - t = x*x; - c = x - t*(P1+t*(P2+t*(P3+t*(P4+t*P5)))); - if(k==0) return one-((x*c)/(c-(float)2.0)-x); - else y = one-((lo-(x*c)/((float)2.0-c))-hi); - if(k >= -125) { - uint32_t hy; - GET_FLOAT_WORD(hy,y); - SET_FLOAT_WORD(y,hy+(k<<23)); /* add k to y's exponent */ - return y; - } else { - uint32_t hy; - GET_FLOAT_WORD(hy,y); - SET_FLOAT_WORD(y,hy+((k+100)<<23)); /* add k to y's exponent */ - return y*twom100; - } -} diff --git a/05/musl-final/src/math/e_fmod.c b/05/musl-final/src/math/e_fmod.c deleted file mode 100644 index 99afe48..0000000 --- a/05/musl-final/src/math/e_fmod.c +++ /dev/null @@ -1,129 +0,0 @@ - -/* @(#)e_fmod.c 1.3 95/01/18 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* - * fmod(x,y) - * Return x mod y in exact arithmetic - * Method: shift and subtract - */ - -#include -#include "math_private.h" - -static const double one = 1.0, Zero[] = {0.0, -0.0,}; - -double -fmod(double x, double y) -{ - int32_t n,hx,hy,hz,ix,iy,sx,i; - uint32_t lx,ly,lz; - - EXTRACT_WORDS(hx,lx,x); - EXTRACT_WORDS(hy,ly,y); - sx = hx&0x80000000; /* sign of x */ - hx ^=sx; /* |x| */ - hy &= 0x7fffffff; /* |y| */ - - /* purge off exception values */ - if((hy|ly)==0||(hx>=0x7ff00000)|| /* y=0,or x not finite */ - ((hy|((ly|-ly)>>31))>0x7ff00000)) /* or y is NaN */ - return (x*y)/(x*y); - if(hx<=hy) { - if((hx>31]; /* |x|=|y| return x*0*/ - } - - /* determine ix = ilogb(x) */ - if(hx<0x00100000) { /* subnormal x */ - if(hx==0) { - for (ix = -1043, i=lx; i>0; i<<=1) ix -=1; - } else { - for (ix = -1022,i=(hx<<11); i>0; i<<=1) ix -=1; - } - } else ix = (hx>>20)-1023; - - /* determine iy = ilogb(y) */ - if(hy<0x00100000) { /* subnormal y */ - if(hy==0) { - for (iy = -1043, i=ly; i>0; i<<=1) iy -=1; - } else { - for (iy = -1022,i=(hy<<11); i>0; i<<=1) iy -=1; - } - } else iy = (hy>>20)-1023; - - /* set up {hx,lx}, {hy,ly} and align y to x */ - if(ix >= -1022) - hx = 0x00100000|(0x000fffff&hx); - else { /* subnormal x, shift x to normal */ - n = -1022-ix; - if(n<=31) { - hx = (hx<>(32-n)); - lx <<= n; - } else { - hx = lx<<(n-32); - lx = 0; - } - } - if(iy >= -1022) - hy = 0x00100000|(0x000fffff&hy); - else { /* subnormal y, shift y to normal */ - n = -1022-iy; - if(n<=31) { - hy = (hy<>(32-n)); - ly <<= n; - } else { - hy = ly<<(n-32); - ly = 0; - } - } - - /* fix point fmod */ - n = ix - iy; - while(n--) { - hz=hx-hy;lz=lx-ly; if(lx>31); lx = lx+lx;} - else { - if((hz|lz)==0) /* return sign(x)*0 */ - return Zero[(uint32_t)sx>>31]; - hx = hz+hz+(lz>>31); lx = lz+lz; - } - } - hz=hx-hy;lz=lx-ly; if(lx=0) {hx=hz;lx=lz;} - - /* convert back to floating value and restore the sign */ - if((hx|lx)==0) /* return sign(x)*0 */ - return Zero[(uint32_t)sx>>31]; - while(hx<0x00100000) { /* normalize x */ - hx = hx+hx+(lx>>31); lx = lx+lx; - iy -= 1; - } - if(iy>= -1022) { /* normalize output */ - hx = ((hx-0x00100000)|((iy+1023)<<20)); - INSERT_WORDS(x,hx|sx,lx); - } else { /* subnormal output */ - n = -1022 - iy; - if(n<=20) { - lx = (lx>>n)|((uint32_t)hx<<(32-n)); - hx >>= n; - } else if (n<=31) { - lx = (hx<<(32-n))|(lx>>n); hx = sx; - } else { - lx = hx>>(n-32); hx = sx; - } - INSERT_WORDS(x,hx|sx,lx); - x *= one; /* create necessary signal */ - } - return x; /* exact output */ -} diff --git a/05/musl-final/src/math/e_fmodf.c b/05/musl-final/src/math/e_fmodf.c deleted file mode 100644 index fe86cb0..0000000 --- a/05/musl-final/src/math/e_fmodf.c +++ /dev/null @@ -1,101 +0,0 @@ -/* e_fmodf.c -- float version of e_fmod.c. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* - * fmodf(x,y) - * Return x mod y in exact arithmetic - * Method: shift and subtract - */ - -#include -#include "math_private.h" - -static const float one = 1.0, Zero[] = {0.0, -0.0,}; - -float -fmodf(float x, float y) -{ - int32_t n,hx,hy,hz,ix,iy,sx,i; - - GET_FLOAT_WORD(hx,x); - GET_FLOAT_WORD(hy,y); - sx = hx&0x80000000; /* sign of x */ - hx ^=sx; /* |x| */ - hy &= 0x7fffffff; /* |y| */ - - /* purge off exception values */ - if(hy==0||(hx>=0x7f800000)|| /* y=0,or x not finite */ - (hy>0x7f800000)) /* or y is NaN */ - return (x*y)/(x*y); - if(hx>31]; /* |x|=|y| return x*0*/ - - /* determine ix = ilogb(x) */ - if(hx<0x00800000) { /* subnormal x */ - for (ix = -126,i=(hx<<8); i>0; i<<=1) ix -=1; - } else ix = (hx>>23)-127; - - /* determine iy = ilogb(y) */ - if(hy<0x00800000) { /* subnormal y */ - for (iy = -126,i=(hy<<8); i>=0; i<<=1) iy -=1; - } else iy = (hy>>23)-127; - - /* set up {hx,lx}, {hy,ly} and align y to x */ - if(ix >= -126) - hx = 0x00800000|(0x007fffff&hx); - else { /* subnormal x, shift x to normal */ - n = -126-ix; - hx = hx<= -126) - hy = 0x00800000|(0x007fffff&hy); - else { /* subnormal y, shift y to normal */ - n = -126-iy; - hy = hy<>31]; - hx = hz+hz; - } - } - hz=hx-hy; - if(hz>=0) {hx=hz;} - - /* convert back to floating value and restore the sign */ - if(hx==0) /* return sign(x)*0 */ - return Zero[(uint32_t)sx>>31]; - while(hx<0x00800000) { /* normalize x */ - hx = hx+hx; - iy -= 1; - } - if(iy>= -126) { /* normalize output */ - hx = ((hx-0x00800000)|((iy+127)<<23)); - SET_FLOAT_WORD(x,hx|sx); - } else { /* subnormal output */ - n = -126 - iy; - hx >>= n; - SET_FLOAT_WORD(x,hx|sx); - x *= one; /* create necessary signal */ - } - return x; /* exact output */ -} diff --git a/05/musl-final/src/math/e_hypot.c b/05/musl-final/src/math/e_hypot.c deleted file mode 100644 index e925adc..0000000 --- a/05/musl-final/src/math/e_hypot.c +++ /dev/null @@ -1,121 +0,0 @@ - -/* @(#)e_hypot.c 1.3 95/01/18 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* hypot(x,y) - * - * Method : - * If (assume round-to-nearest) z=x*x+y*y - * has error less than sqrt(2)/2 ulp, than - * sqrt(z) has error less than 1 ulp (exercise). - * - * So, compute sqrt(x*x+y*y) with some care as - * follows to get the error below 1 ulp: - * - * Assume x>y>0; - * (if possible, set rounding to round-to-nearest) - * 1. if x > 2y use - * x1*x1+(y*y+(x2*(x+x1))) for x*x+y*y - * where x1 = x with lower 32 bits cleared, x2 = x-x1; else - * 2. if x <= 2y use - * t1*y1+((x-y)*(x-y)+(t1*y2+t2*y)) - * where t1 = 2x with lower 32 bits cleared, t2 = 2x-t1, - * y1= y with lower 32 bits chopped, y2 = y-y1. - * - * NOTE: scaling may be necessary if some argument is too - * large or too tiny - * - * Special cases: - * hypot(x,y) is INF if x or y is +INF or -INF; else - * hypot(x,y) is NAN if x or y is NAN. - * - * Accuracy: - * hypot(x,y) returns sqrt(x^2+y^2) with error less - * than 1 ulps (units in the last place) - */ - -#include -#include "math_private.h" - -double -hypot(double x, double y) -{ - double a=x,b=y,t1,t2,y1,y2,w; - int32_t j,k,ha,hb; - - GET_HIGH_WORD(ha,x); - ha &= 0x7fffffff; - GET_HIGH_WORD(hb,y); - hb &= 0x7fffffff; - if(hb > ha) {a=y;b=x;j=ha; ha=hb;hb=j;} else {a=x;b=y;} - SET_HIGH_WORD(a,ha); /* a <- |a| */ - SET_HIGH_WORD(b,hb); /* b <- |b| */ - if((ha-hb)>0x3c00000) {return a+b;} /* x/y > 2**60 */ - k=0; - if(ha > 0x5f300000) { /* a>2**500 */ - if(ha >= 0x7ff00000) { /* Inf or NaN */ - uint32_t low; - w = a+b; /* for sNaN */ - GET_LOW_WORD(low,a); - if(((ha&0xfffff)|low)==0) w = a; - GET_LOW_WORD(low,b); - if(((hb^0x7ff00000)|low)==0) w = b; - return w; - } - /* scale a and b by 2**-600 */ - ha -= 0x25800000; hb -= 0x25800000; k += 600; - SET_HIGH_WORD(a,ha); - SET_HIGH_WORD(b,hb); - } - if(hb < 0x20b00000) { /* b < 2**-500 */ - if(hb <= 0x000fffff) { /* subnormal b or 0 */ - uint32_t low; - GET_LOW_WORD(low,b); - if((hb|low)==0) return a; - t1=0; - SET_HIGH_WORD(t1,0x7fd00000); /* t1=2^1022 */ - b *= t1; - a *= t1; - k -= 1022; - } else { /* scale a and b by 2^600 */ - ha += 0x25800000; /* a *= 2^600 */ - hb += 0x25800000; /* b *= 2^600 */ - k -= 600; - SET_HIGH_WORD(a,ha); - SET_HIGH_WORD(b,hb); - } - } - /* medium size a and b */ - w = a-b; - if (w>b) { - t1 = 0; - SET_HIGH_WORD(t1,ha); - t2 = a-t1; - w = sqrt(t1*t1-(b*(-b)-t2*(a+t1))); - } else { - a = a+a; - y1 = 0; - SET_HIGH_WORD(y1,hb); - y2 = b - y1; - t1 = 0; - SET_HIGH_WORD(t1,ha+0x00100000); - t2 = a - t1; - w = sqrt(t1*y1-(w*(-w)-(t1*y2+t2*b))); - } - if(k!=0) { - uint32_t high; - t1 = 1.0; - GET_HIGH_WORD(high,t1); - SET_HIGH_WORD(t1,high+(k<<20)); - return t1*w; - } else return w; -} diff --git a/05/musl-final/src/math/e_hypotf.c b/05/musl-final/src/math/e_hypotf.c deleted file mode 100644 index 1377355..0000000 --- a/05/musl-final/src/math/e_hypotf.c +++ /dev/null @@ -1,79 +0,0 @@ -/* e_hypotf.c -- float version of e_hypot.c. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include -#include "math_private.h" - -float -hypotf(float x, float y) -{ - float a=x,b=y,t1,t2,y1,y2,w; - int32_t j,k,ha,hb; - - GET_FLOAT_WORD(ha,x); - ha &= 0x7fffffff; - GET_FLOAT_WORD(hb,y); - hb &= 0x7fffffff; - if(hb > ha) {a=y;b=x;j=ha; ha=hb;hb=j;} else {a=x;b=y;} - SET_FLOAT_WORD(a,ha); /* a <- |a| */ - SET_FLOAT_WORD(b,hb); /* b <- |b| */ - if((ha-hb)>0xf000000) {return a+b;} /* x/y > 2**30 */ - k=0; - if(ha > 0x58800000) { /* a>2**50 */ - if(ha >= 0x7f800000) { /* Inf or NaN */ - w = a+b; /* for sNaN */ - if(ha == 0x7f800000) w = a; - if(hb == 0x7f800000) w = b; - return w; - } - /* scale a and b by 2**-68 */ - ha -= 0x22000000; hb -= 0x22000000; k += 68; - SET_FLOAT_WORD(a,ha); - SET_FLOAT_WORD(b,hb); - } - if(hb < 0x26800000) { /* b < 2**-50 */ - if(hb <= 0x007fffff) { /* subnormal b or 0 */ - if(hb==0) return a; - SET_FLOAT_WORD(t1,0x7e800000); /* t1=2^126 */ - b *= t1; - a *= t1; - k -= 126; - } else { /* scale a and b by 2^68 */ - ha += 0x22000000; /* a *= 2^68 */ - hb += 0x22000000; /* b *= 2^68 */ - k -= 68; - SET_FLOAT_WORD(a,ha); - SET_FLOAT_WORD(b,hb); - } - } - /* medium size a and b */ - w = a-b; - if (w>b) { - SET_FLOAT_WORD(t1,ha&0xfffff000); - t2 = a-t1; - w = sqrtf(t1*t1-(b*(-b)-t2*(a+t1))); - } else { - a = a+a; - SET_FLOAT_WORD(y1,hb&0xfffff000); - y2 = b - y1; - SET_FLOAT_WORD(t1,ha+0x00800000); - t2 = a - t1; - w = sqrtf(t1*y1-(w*(-w)-(t1*y2+t2*b))); - } - if(k!=0) { - SET_FLOAT_WORD(t1,0x3f800000+(k<<23)); - return t1*w; - } else return w; -} diff --git a/05/musl-final/src/math/e_log.c b/05/musl-final/src/math/e_log.c deleted file mode 100644 index 9eb0e44..0000000 --- a/05/musl-final/src/math/e_log.c +++ /dev/null @@ -1,131 +0,0 @@ - -/* @(#)e_log.c 1.3 95/01/18 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* log(x) - * Return the logrithm of x - * - * Method : - * 1. Argument Reduction: find k and f such that - * x = 2^k * (1+f), - * where sqrt(2)/2 < 1+f < sqrt(2) . - * - * 2. Approximation of log(1+f). - * Let s = f/(2+f) ; based on log(1+f) = log(1+s) - log(1-s) - * = 2s + 2/3 s**3 + 2/5 s**5 + ....., - * = 2s + s*R - * We use a special Reme algorithm on [0,0.1716] to generate - * a polynomial of degree 14 to approximate R The maximum error - * of this polynomial approximation is bounded by 2**-58.45. In - * other words, - * 2 4 6 8 10 12 14 - * R(z) ~ Lg1*s +Lg2*s +Lg3*s +Lg4*s +Lg5*s +Lg6*s +Lg7*s - * (the values of Lg1 to Lg7 are listed in the program) - * and - * | 2 14 | -58.45 - * | Lg1*s +...+Lg7*s - R(z) | <= 2 - * | | - * Note that 2s = f - s*f = f - hfsq + s*hfsq, where hfsq = f*f/2. - * In order to guarantee error in log below 1ulp, we compute log - * by - * log(1+f) = f - s*(f - R) (if f is not too large) - * log(1+f) = f - (hfsq - s*(hfsq+R)). (better accuracy) - * - * 3. Finally, log(x) = k*ln2 + log(1+f). - * = k*ln2_hi+(f-(hfsq-(s*(hfsq+R)+k*ln2_lo))) - * Here ln2 is split into two floating point number: - * ln2_hi + ln2_lo, - * where n*ln2_hi is always exact for |n| < 2000. - * - * Special cases: - * log(x) is NaN with signal if x < 0 (including -INF) ; - * log(+INF) is +INF; log(0) is -INF with signal; - * log(NaN) is that NaN with no signal. - * - * Accuracy: - * according to an error analysis, the error is always less than - * 1 ulp (unit in the last place). - * - * Constants: - * The hexadecimal values are the intended ones for the following - * constants. The decimal values may be used, provided that the - * compiler will convert from decimal to binary accurately enough - * to produce the hexadecimal values shown. - */ - -#include -#include "math_private.h" - -static const double -ln2_hi = 6.93147180369123816490e-01, /* 3fe62e42 fee00000 */ -ln2_lo = 1.90821492927058770002e-10, /* 3dea39ef 35793c76 */ -two54 = 1.80143985094819840000e+16, /* 43500000 00000000 */ -Lg1 = 6.666666666666735130e-01, /* 3FE55555 55555593 */ -Lg2 = 3.999999999940941908e-01, /* 3FD99999 9997FA04 */ -Lg3 = 2.857142874366239149e-01, /* 3FD24924 94229359 */ -Lg4 = 2.222219843214978396e-01, /* 3FCC71C5 1D8E78AF */ -Lg5 = 1.818357216161805012e-01, /* 3FC74664 96CB03DE */ -Lg6 = 1.531383769920937332e-01, /* 3FC39A09 D078C69F */ -Lg7 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */ - -static const double zero = 0.0; - -double -log(double x) -{ - double hfsq,f,s,z,R,w,t1,t2,dk; - int32_t k,hx,i,j; - uint32_t lx; - - EXTRACT_WORDS(hx,lx,x); - - k=0; - if (hx < 0x00100000) { /* x < 2**-1022 */ - if (((hx&0x7fffffff)|lx)==0) - return -two54/zero; /* log(+-0)=-inf */ - if (hx<0) return (x-x)/zero; /* log(-#) = NaN */ - k -= 54; x *= two54; /* subnormal number, scale up x */ - GET_HIGH_WORD(hx,x); - } - if (hx >= 0x7ff00000) return x+x; - k += (hx>>20)-1023; - hx &= 0x000fffff; - i = (hx+0x95f64)&0x100000; - SET_HIGH_WORD(x,hx|(i^0x3ff00000)); /* normalize x or x/2 */ - k += (i>>20); - f = x-1.0; - if((0x000fffff&(2+hx))<3) { /* |f| < 2**-20 */ - if(f==zero) { if(k==0) return zero; else {dk=(double)k; - return dk*ln2_hi+dk*ln2_lo;} } - R = f*f*(0.5-0.33333333333333333*f); - if(k==0) return f-R; else {dk=(double)k; - return dk*ln2_hi-((R-dk*ln2_lo)-f);} - } - s = f/(2.0+f); - dk = (double)k; - z = s*s; - i = hx-0x6147a; - w = z*z; - j = 0x6b851-hx; - t1= w*(Lg2+w*(Lg4+w*Lg6)); - t2= z*(Lg1+w*(Lg3+w*(Lg5+w*Lg7))); - i |= j; - R = t2+t1; - if(i>0) { - hfsq=0.5*f*f; - if(k==0) return f-(hfsq-s*(hfsq+R)); else - return dk*ln2_hi-((hfsq-(s*(hfsq+R)+dk*ln2_lo))-f); - } else { - if(k==0) return f-s*(f-R); else - return dk*ln2_hi-((s*(f-R)-dk*ln2_lo)-f); - } -} diff --git a/05/musl-final/src/math/e_log10.c b/05/musl-final/src/math/e_log10.c deleted file mode 100644 index 3be179f..0000000 --- a/05/musl-final/src/math/e_log10.c +++ /dev/null @@ -1,83 +0,0 @@ - -/* @(#)e_log10.c 1.3 95/01/18 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* log10(x) - * Return the base 10 logarithm of x - * - * Method : - * Let log10_2hi = leading 40 bits of log10(2) and - * log10_2lo = log10(2) - log10_2hi, - * ivln10 = 1/log(10) rounded. - * Then - * n = ilogb(x), - * if(n<0) n = n+1; - * x = scalbn(x,-n); - * log10(x) := n*log10_2hi + (n*log10_2lo + ivln10*log(x)) - * - * Note 1: - * To guarantee log10(10**n)=n, where 10**n is normal, the rounding - * mode must set to Round-to-Nearest. - * Note 2: - * [1/log(10)] rounded to 53 bits has error .198 ulps; - * log10 is monotonic at all binary break points. - * - * Special cases: - * log10(x) is NaN with signal if x < 0; - * log10(+INF) is +INF with no signal; log10(0) is -INF with signal; - * log10(NaN) is that NaN with no signal; - * log10(10**N) = N for N=0,1,...,22. - * - * Constants: - * The hexadecimal values are the intended ones for the following constants. - * The decimal values may be used, provided that the compiler will convert - * from decimal to binary accurately enough to produce the hexadecimal values - * shown. - */ - -#include -#include "math_private.h" - -static const double -two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */ -ivln10 = 4.34294481903251816668e-01, /* 0x3FDBCB7B, 0x1526E50E */ -log10_2hi = 3.01029995663611771306e-01, /* 0x3FD34413, 0x509F6000 */ -log10_2lo = 3.69423907715893078616e-13; /* 0x3D59FEF3, 0x11F12B36 */ - -static const double zero = 0.0; - -double -log10(double x) -{ - double y,z; - int32_t i,k,hx; - uint32_t lx; - - EXTRACT_WORDS(hx,lx,x); - - k=0; - if (hx < 0x00100000) { /* x < 2**-1022 */ - if (((hx&0x7fffffff)|lx)==0) - return -two54/zero; /* log(+-0)=-inf */ - if (hx<0) return (x-x)/zero; /* log(-#) = NaN */ - k -= 54; x *= two54; /* subnormal number, scale up x */ - GET_HIGH_WORD(hx,x); - } - if (hx >= 0x7ff00000) return x+x; - k += (hx>>20)-1023; - i = ((uint32_t)k&0x80000000)>>31; - hx = (hx&0x000fffff)|((0x3ff-i)<<20); - y = (double)(k+i); - SET_HIGH_WORD(x,hx); - z = y*log10_2lo + ivln10*log(x); - return z+y*log10_2hi; -} diff --git a/05/musl-final/src/math/e_log10f.c b/05/musl-final/src/math/e_log10f.c deleted file mode 100644 index 8fc5c5c..0000000 --- a/05/musl-final/src/math/e_log10f.c +++ /dev/null @@ -1,51 +0,0 @@ -/* e_log10f.c -- float version of e_log10.c. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include -#include "math_private.h" - -static const float -two25 = 3.3554432000e+07, /* 0x4c000000 */ -ivln10 = 4.3429449201e-01, /* 0x3ede5bd9 */ -log10_2hi = 3.0102920532e-01, /* 0x3e9a2080 */ -log10_2lo = 7.9034151668e-07; /* 0x355427db */ - -static const float zero = 0.0; - -float -log10f(float x) -{ - float y,z; - int32_t i,k,hx; - - GET_FLOAT_WORD(hx,x); - - k=0; - if (hx < 0x00800000) { /* x < 2**-126 */ - if ((hx&0x7fffffff)==0) - return -two25/zero; /* log(+-0)=-inf */ - if (hx<0) return (x-x)/zero; /* log(-#) = NaN */ - k -= 25; x *= two25; /* subnormal number, scale up x */ - GET_FLOAT_WORD(hx,x); - } - if (hx >= 0x7f800000) return x+x; - k += (hx>>23)-127; - i = ((uint32_t)k&0x80000000)>>31; - hx = (hx&0x007fffff)|((0x7f-i)<<23); - y = (float)(k+i); - SET_FLOAT_WORD(x,hx); - z = y*log10_2lo + ivln10*logf(x); - return z+y*log10_2hi; -} diff --git a/05/musl-final/src/math/e_logf.c b/05/musl-final/src/math/e_logf.c deleted file mode 100644 index 46a8b8c..0000000 --- a/05/musl-final/src/math/e_logf.c +++ /dev/null @@ -1,81 +0,0 @@ -/* e_logf.c -- float version of e_log.c. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include -#include "math_private.h" - -static const float -ln2_hi = 6.9313812256e-01, /* 0x3f317180 */ -ln2_lo = 9.0580006145e-06, /* 0x3717f7d1 */ -two25 = 3.355443200e+07, /* 0x4c000000 */ -Lg1 = 6.6666668653e-01, /* 3F2AAAAB */ -Lg2 = 4.0000000596e-01, /* 3ECCCCCD */ -Lg3 = 2.8571429849e-01, /* 3E924925 */ -Lg4 = 2.2222198546e-01, /* 3E638E29 */ -Lg5 = 1.8183572590e-01, /* 3E3A3325 */ -Lg6 = 1.5313838422e-01, /* 3E1CD04F */ -Lg7 = 1.4798198640e-01; /* 3E178897 */ - -static const float zero = 0.0; - -float -logf(float x) -{ - float hfsq,f,s,z,R,w,t1,t2,dk; - int32_t k,ix,i,j; - - GET_FLOAT_WORD(ix,x); - - k=0; - if (ix < 0x00800000) { /* x < 2**-126 */ - if ((ix&0x7fffffff)==0) - return -two25/zero; /* log(+-0)=-inf */ - if (ix<0) return (x-x)/zero; /* log(-#) = NaN */ - k -= 25; x *= two25; /* subnormal number, scale up x */ - GET_FLOAT_WORD(ix,x); - } - if (ix >= 0x7f800000) return x+x; - k += (ix>>23)-127; - ix &= 0x007fffff; - i = (ix+(0x95f64<<3))&0x800000; - SET_FLOAT_WORD(x,ix|(i^0x3f800000)); /* normalize x or x/2 */ - k += (i>>23); - f = x-(float)1.0; - if((0x007fffff&(15+ix))<16) { /* |f| < 2**-20 */ - if(f==zero) { if(k==0) return zero; else {dk=(float)k; - return dk*ln2_hi+dk*ln2_lo;} } - R = f*f*((float)0.5-(float)0.33333333333333333*f); - if(k==0) return f-R; else {dk=(float)k; - return dk*ln2_hi-((R-dk*ln2_lo)-f);} - } - s = f/((float)2.0+f); - dk = (float)k; - z = s*s; - i = ix-(0x6147a<<3); - w = z*z; - j = (0x6b851<<3)-ix; - t1= w*(Lg2+w*(Lg4+w*Lg6)); - t2= z*(Lg1+w*(Lg3+w*(Lg5+w*Lg7))); - i |= j; - R = t2+t1; - if(i>0) { - hfsq=(float)0.5*f*f; - if(k==0) return f-(hfsq-s*(hfsq+R)); else - return dk*ln2_hi-((hfsq-(s*(hfsq+R)+dk*ln2_lo))-f); - } else { - if(k==0) return f-s*(f-R); else - return dk*ln2_hi-((s*(f-R)-dk*ln2_lo)-f); - } -} diff --git a/05/musl-final/src/math/e_pow.c b/05/musl-final/src/math/e_pow.c deleted file mode 100644 index aad2428..0000000 --- a/05/musl-final/src/math/e_pow.c +++ /dev/null @@ -1,300 +0,0 @@ -/* @(#)e_pow.c 1.5 04/04/22 SMI */ -/* - * ==================================================== - * Copyright (C) 2004 by Sun Microsystems, Inc. All rights reserved. - * - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* pow(x,y) return x**y - * - * n - * Method: Let x = 2 * (1+f) - * 1. Compute and return log2(x) in two pieces: - * log2(x) = w1 + w2, - * where w1 has 53-24 = 29 bit trailing zeros. - * 2. Perform y*log2(x) = n+y' by simulating muti-precision - * arithmetic, where |y'|<=0.5. - * 3. Return x**y = 2**n*exp(y'*log2) - * - * Special cases: - * 1. (anything) ** 0 is 1 - * 2. (anything) ** 1 is itself - * 3. (anything) ** NAN is NAN - * 4. NAN ** (anything except 0) is NAN - * 5. +-(|x| > 1) ** +INF is +INF - * 6. +-(|x| > 1) ** -INF is +0 - * 7. +-(|x| < 1) ** +INF is +0 - * 8. +-(|x| < 1) ** -INF is +INF - * 9. +-1 ** +-INF is NAN - * 10. +0 ** (+anything except 0, NAN) is +0 - * 11. -0 ** (+anything except 0, NAN, odd integer) is +0 - * 12. +0 ** (-anything except 0, NAN) is +INF - * 13. -0 ** (-anything except 0, NAN, odd integer) is +INF - * 14. -0 ** (odd integer) = -( +0 ** (odd integer) ) - * 15. +INF ** (+anything except 0,NAN) is +INF - * 16. +INF ** (-anything except 0,NAN) is +0 - * 17. -INF ** (anything) = -0 ** (-anything) - * 18. (-anything) ** (integer) is (-1)**(integer)*(+anything**integer) - * 19. (-anything except 0 and inf) ** (non-integer) is NAN - * - * Accuracy: - * pow(x,y) returns x**y nearly rounded. In particular - * pow(integer,integer) - * always returns the correct integer provided it is - * representable. - * - * Constants : - * The hexadecimal values are the intended ones for the following - * constants. The decimal values may be used, provided that the - * compiler will convert from decimal to binary accurately enough - * to produce the hexadecimal values shown. - */ - -#include -#include "math_private.h" - -static const double -bp[] = {1.0, 1.5,}, -dp_h[] = { 0.0, 5.84962487220764160156e-01,}, /* 0x3FE2B803, 0x40000000 */ -dp_l[] = { 0.0, 1.35003920212974897128e-08,}, /* 0x3E4CFDEB, 0x43CFD006 */ -zero = 0.0, -one = 1.0, -two = 2.0, -two53 = 9007199254740992.0, /* 0x43400000, 0x00000000 */ -huge = 1.0e300, -tiny = 1.0e-300, - /* poly coefs for (3/2)*(log(x)-2s-2/3*s**3 */ -L1 = 5.99999999999994648725e-01, /* 0x3FE33333, 0x33333303 */ -L2 = 4.28571428578550184252e-01, /* 0x3FDB6DB6, 0xDB6FABFF */ -L3 = 3.33333329818377432918e-01, /* 0x3FD55555, 0x518F264D */ -L4 = 2.72728123808534006489e-01, /* 0x3FD17460, 0xA91D4101 */ -L5 = 2.30660745775561754067e-01, /* 0x3FCD864A, 0x93C9DB65 */ -L6 = 2.06975017800338417784e-01, /* 0x3FCA7E28, 0x4A454EEF */ -P1 = 1.66666666666666019037e-01, /* 0x3FC55555, 0x5555553E */ -P2 = -2.77777777770155933842e-03, /* 0xBF66C16C, 0x16BEBD93 */ -P3 = 6.61375632143793436117e-05, /* 0x3F11566A, 0xAF25DE2C */ -P4 = -1.65339022054652515390e-06, /* 0xBEBBBD41, 0xC5D26BF1 */ -P5 = 4.13813679705723846039e-08, /* 0x3E663769, 0x72BEA4D0 */ -lg2 = 6.93147180559945286227e-01, /* 0x3FE62E42, 0xFEFA39EF */ -lg2_h = 6.93147182464599609375e-01, /* 0x3FE62E43, 0x00000000 */ -lg2_l = -1.90465429995776804525e-09, /* 0xBE205C61, 0x0CA86C39 */ -ovt = 8.0085662595372944372e-0017, /* -(1024-log2(ovfl+.5ulp)) */ -cp = 9.61796693925975554329e-01, /* 0x3FEEC709, 0xDC3A03FD =2/(3ln2) */ -cp_h = 9.61796700954437255859e-01, /* 0x3FEEC709, 0xE0000000 =(float)cp */ -cp_l = -7.02846165095275826516e-09, /* 0xBE3E2FE0, 0x145B01F5 =tail of cp_h*/ -ivln2 = 1.44269504088896338700e+00, /* 0x3FF71547, 0x652B82FE =1/ln2 */ -ivln2_h = 1.44269502162933349609e+00, /* 0x3FF71547, 0x60000000 =24b 1/ln2*/ -ivln2_l = 1.92596299112661746887e-08; /* 0x3E54AE0B, 0xF85DDF44 =1/ln2 tail*/ - -double -pow(double x, double y) -{ - double z,ax,z_h,z_l,p_h,p_l; - double y1,t1,t2,r,s,t,u,v,w; - int32_t i,j,k,yisint,n; - int32_t hx,hy,ix,iy; - uint32_t lx,ly; - - EXTRACT_WORDS(hx,lx,x); - EXTRACT_WORDS(hy,ly,y); - ix = hx&0x7fffffff; iy = hy&0x7fffffff; - - /* y==zero: x**0 = 1 */ - if((iy|ly)==0) return one; - - /* +-NaN return x+y */ - if(ix > 0x7ff00000 || ((ix==0x7ff00000)&&(lx!=0)) || - iy > 0x7ff00000 || ((iy==0x7ff00000)&&(ly!=0))) - return x+y; - - /* determine if y is an odd int when x < 0 - * yisint = 0 ... y is not an integer - * yisint = 1 ... y is an odd int - * yisint = 2 ... y is an even int - */ - yisint = 0; - if(hx<0) { - if(iy>=0x43400000) yisint = 2; /* even integer y */ - else if(iy>=0x3ff00000) { - k = (iy>>20)-0x3ff; /* exponent */ - if(k>20) { - j = ly>>(52-k); - if((j<<(52-k))==ly) yisint = 2-(j&1); - } else if(ly==0) { - j = iy>>(20-k); - if((j<<(20-k))==iy) yisint = 2-(j&1); - } - } - } - - /* special value of y */ - if(ly==0) { - if (iy==0x7ff00000) { /* y is +-inf */ - if(((ix-0x3ff00000)|lx)==0) - return y - y; /* inf**+-1 is NaN */ - else if (ix >= 0x3ff00000)/* (|x|>1)**+-inf = inf,0 */ - return (hy>=0)? y: zero; - else /* (|x|<1)**-,+inf = inf,0 */ - return (hy<0)?-y: zero; - } - if(iy==0x3ff00000) { /* y is +-1 */ - if(hy<0) return one/x; else return x; - } - if(hy==0x40000000) return x*x; /* y is 2 */ - if(hy==0x3fe00000) { /* y is 0.5 */ - if(hx>=0) /* x >= +0 */ - return sqrt(x); - } - } - - ax = fabs(x); - /* special value of x */ - if(lx==0) { - if(ix==0x7ff00000||ix==0||ix==0x3ff00000){ - z = ax; /*x is +-0,+-inf,+-1*/ - if(hy<0) z = one/z; /* z = (1/|x|) */ - if(hx<0) { - if(((ix-0x3ff00000)|yisint)==0) { - z = (z-z)/(z-z); /* (-1)**non-int is NaN */ - } else if(yisint==1) - z = -z; /* (x<0)**odd = -(|x|**odd) */ - } - return z; - } - } - - /* CYGNUS LOCAL + fdlibm-5.3 fix: This used to be - n = (hx>>31)+1; - but ANSI C says a right shift of a signed negative quantity is - implementation defined. */ - n = ((uint32_t)hx>>31)-1; - - /* (x<0)**(non-int) is NaN */ - if((n|yisint)==0) return (x-x)/(x-x); - - s = one; /* s (sign of result -ve**odd) = -1 else = 1 */ - if((n|(yisint-1))==0) s = -one;/* (-ve)**(odd int) */ - - /* |y| is huge */ - if(iy>0x41e00000) { /* if |y| > 2**31 */ - if(iy>0x43f00000){ /* if |y| > 2**64, must o/uflow */ - if(ix<=0x3fefffff) return (hy<0)? huge*huge:tiny*tiny; - if(ix>=0x3ff00000) return (hy>0)? huge*huge:tiny*tiny; - } - /* over/underflow if x is not close to one */ - if(ix<0x3fefffff) return (hy<0)? s*huge*huge:s*tiny*tiny; - if(ix>0x3ff00000) return (hy>0)? s*huge*huge:s*tiny*tiny; - /* now |1-x| is tiny <= 2**-20, suffice to compute - log(x) by x-x^2/2+x^3/3-x^4/4 */ - t = ax-one; /* t has 20 trailing zeros */ - w = (t*t)*(0.5-t*(0.3333333333333333333333-t*0.25)); - u = ivln2_h*t; /* ivln2_h has 21 sig. bits */ - v = t*ivln2_l-w*ivln2; - t1 = u+v; - SET_LOW_WORD(t1,0); - t2 = v-(t1-u); - } else { - double ss,s2,s_h,s_l,t_h,t_l; - n = 0; - /* take care subnormal number */ - if(ix<0x00100000) - {ax *= two53; n -= 53; GET_HIGH_WORD(ix,ax); } - n += ((ix)>>20)-0x3ff; - j = ix&0x000fffff; - /* determine interval */ - ix = j|0x3ff00000; /* normalize ix */ - if(j<=0x3988E) k=0; /* |x|>1)|0x20000000)+0x00080000+(k<<18)); - t_l = ax - (t_h-bp[k]); - s_l = v*((u-s_h*t_h)-s_h*t_l); - /* compute log(ax) */ - s2 = ss*ss; - r = s2*s2*(L1+s2*(L2+s2*(L3+s2*(L4+s2*(L5+s2*L6))))); - r += s_l*(s_h+ss); - s2 = s_h*s_h; - t_h = 3.0+s2+r; - SET_LOW_WORD(t_h,0); - t_l = r-((t_h-3.0)-s2); - /* u+v = ss*(1+...) */ - u = s_h*t_h; - v = s_l*t_h+t_l*ss; - /* 2/(3log2)*(ss+...) */ - p_h = u+v; - SET_LOW_WORD(p_h,0); - p_l = v-(p_h-u); - z_h = cp_h*p_h; /* cp_h+cp_l = 2/(3*log2) */ - z_l = cp_l*p_h+p_l*cp+dp_l[k]; - /* log2(ax) = (ss+..)*2/(3*log2) = n + dp_h + z_h + z_l */ - t = (double)n; - t1 = (((z_h+z_l)+dp_h[k])+t); - SET_LOW_WORD(t1,0); - t2 = z_l-(((t1-t)-dp_h[k])-z_h); - } - - /* split up y into y1+y2 and compute (y1+y2)*(t1+t2) */ - y1 = y; - SET_LOW_WORD(y1,0); - p_l = (y-y1)*t1+y*t2; - p_h = y1*t1; - z = p_l+p_h; - EXTRACT_WORDS(j,i,z); - if (j>=0x40900000) { /* z >= 1024 */ - if(((j-0x40900000)|i)!=0) /* if z > 1024 */ - return s*huge*huge; /* overflow */ - else { - if(p_l+ovt>z-p_h) return s*huge*huge; /* overflow */ - } - } else if((j&0x7fffffff)>=0x4090cc00 ) { /* z <= -1075 */ - if(((j-0xc090cc00)|i)!=0) /* z < -1075 */ - return s*tiny*tiny; /* underflow */ - else { - if(p_l<=z-p_h) return s*tiny*tiny; /* underflow */ - } - } - /* - * compute 2**(p_h+p_l) - */ - i = j&0x7fffffff; - k = (i>>20)-0x3ff; - n = 0; - if(i>0x3fe00000) { /* if |z| > 0.5, set n = [z+0.5] */ - n = j+(0x00100000>>(k+1)); - k = ((n&0x7fffffff)>>20)-0x3ff; /* new k for n */ - t = zero; - SET_HIGH_WORD(t,n&~(0x000fffff>>k)); - n = ((n&0x000fffff)|0x00100000)>>(20-k); - if(j<0) n = -n; - p_h -= t; - } - t = p_l+p_h; - SET_LOW_WORD(t,0); - u = t*lg2_h; - v = (p_l-(t-p_h))*lg2+t*lg2_l; - z = u+v; - w = v-(z-u); - t = z*z; - t1 = z - t*(P1+t*(P2+t*(P3+t*(P4+t*P5)))); - r = (z*t1)/(t1-two)-(w+z*w); - z = one-(r-z); - GET_HIGH_WORD(j,z); - j += (n<<20); - if((j>>20)<=0) z = scalbn(z,n); /* subnormal output */ - else SET_HIGH_WORD(z,j); - return s*z; -} diff --git a/05/musl-final/src/math/e_powf.c b/05/musl-final/src/math/e_powf.c deleted file mode 100644 index ae61c24..0000000 --- a/05/musl-final/src/math/e_powf.c +++ /dev/null @@ -1,243 +0,0 @@ -/* e_powf.c -- float version of e_pow.c. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include -#include "math_private.h" - -static const float -bp[] = {1.0, 1.5,}, -dp_h[] = { 0.0, 5.84960938e-01,}, /* 0x3f15c000 */ -dp_l[] = { 0.0, 1.56322085e-06,}, /* 0x35d1cfdc */ -zero = 0.0, -one = 1.0, -two = 2.0, -two24 = 16777216.0, /* 0x4b800000 */ -huge = 1.0e30, -tiny = 1.0e-30, - /* poly coefs for (3/2)*(log(x)-2s-2/3*s**3 */ -L1 = 6.0000002384e-01, /* 0x3f19999a */ -L2 = 4.2857143283e-01, /* 0x3edb6db7 */ -L3 = 3.3333334327e-01, /* 0x3eaaaaab */ -L4 = 2.7272811532e-01, /* 0x3e8ba305 */ -L5 = 2.3066075146e-01, /* 0x3e6c3255 */ -L6 = 2.0697501302e-01, /* 0x3e53f142 */ -P1 = 1.6666667163e-01, /* 0x3e2aaaab */ -P2 = -2.7777778450e-03, /* 0xbb360b61 */ -P3 = 6.6137559770e-05, /* 0x388ab355 */ -P4 = -1.6533901999e-06, /* 0xb5ddea0e */ -P5 = 4.1381369442e-08, /* 0x3331bb4c */ -lg2 = 6.9314718246e-01, /* 0x3f317218 */ -lg2_h = 6.93145752e-01, /* 0x3f317200 */ -lg2_l = 1.42860654e-06, /* 0x35bfbe8c */ -ovt = 4.2995665694e-08, /* -(128-log2(ovfl+.5ulp)) */ -cp = 9.6179670095e-01, /* 0x3f76384f =2/(3ln2) */ -cp_h = 9.6179199219e-01, /* 0x3f763800 =head of cp */ -cp_l = 4.7017383622e-06, /* 0x369dc3a0 =tail of cp_h */ -ivln2 = 1.4426950216e+00, /* 0x3fb8aa3b =1/ln2 */ -ivln2_h = 1.4426879883e+00, /* 0x3fb8aa00 =16b 1/ln2*/ -ivln2_l = 7.0526075433e-06; /* 0x36eca570 =1/ln2 tail*/ - -float -powf(float x, float y) -{ - float z,ax,z_h,z_l,p_h,p_l; - float y1,t1,t2,r,s,sn,t,u,v,w; - int32_t i,j,k,yisint,n; - int32_t hx,hy,ix,iy,is; - - GET_FLOAT_WORD(hx,x); - GET_FLOAT_WORD(hy,y); - ix = hx&0x7fffffff; iy = hy&0x7fffffff; - - /* y==zero: x**0 = 1 */ - if(iy==0) return one; - - /* +-NaN return x+y */ - if(ix > 0x7f800000 || - iy > 0x7f800000) - return x+y; - - /* determine if y is an odd int when x < 0 - * yisint = 0 ... y is not an integer - * yisint = 1 ... y is an odd int - * yisint = 2 ... y is an even int - */ - yisint = 0; - if(hx<0) { - if(iy>=0x4b800000) yisint = 2; /* even integer y */ - else if(iy>=0x3f800000) { - k = (iy>>23)-0x7f; /* exponent */ - j = iy>>(23-k); - if((j<<(23-k))==iy) yisint = 2-(j&1); - } - } - - /* special value of y */ - if (iy==0x7f800000) { /* y is +-inf */ - if (ix==0x3f800000) - return y - y; /* inf**+-1 is NaN */ - else if (ix > 0x3f800000)/* (|x|>1)**+-inf = inf,0 */ - return (hy>=0)? y: zero; - else /* (|x|<1)**-,+inf = inf,0 */ - return (hy<0)?-y: zero; - } - if(iy==0x3f800000) { /* y is +-1 */ - if(hy<0) return one/x; else return x; - } - if(hy==0x40000000) return x*x; /* y is 2 */ - if(hy==0x3f000000) { /* y is 0.5 */ - if(hx>=0) /* x >= +0 */ - return sqrtf(x); - } - - ax = fabsf(x); - /* special value of x */ - if(ix==0x7f800000||ix==0||ix==0x3f800000){ - z = ax; /*x is +-0,+-inf,+-1*/ - if(hy<0) z = one/z; /* z = (1/|x|) */ - if(hx<0) { - if(((ix-0x3f800000)|yisint)==0) { - z = (z-z)/(z-z); /* (-1)**non-int is NaN */ - } else if(yisint==1) - z = -z; /* (x<0)**odd = -(|x|**odd) */ - } - return z; - } - - n = ((uint32_t)hx>>31)-1; - - /* (x<0)**(non-int) is NaN */ - if((n|yisint)==0) return (x-x)/(x-x); - - sn = one; /* s (sign of result -ve**odd) = -1 else = 1 */ - if((n|(yisint-1))==0) sn = -one;/* (-ve)**(odd int) */ - - /* |y| is huge */ - if(iy>0x4d000000) { /* if |y| > 2**27 */ - /* over/underflow if x is not close to one */ - if(ix<0x3f7ffff8) return (hy<0)? sn*huge*huge:sn*tiny*tiny; - if(ix>0x3f800007) return (hy>0)? sn*huge*huge:sn*tiny*tiny; - /* now |1-x| is tiny <= 2**-20, suffice to compute - log(x) by x-x^2/2+x^3/3-x^4/4 */ - t = ax-1; /* t has 20 trailing zeros */ - w = (t*t)*((float)0.5-t*((float)0.333333333333-t*(float)0.25)); - u = ivln2_h*t; /* ivln2_h has 16 sig. bits */ - v = t*ivln2_l-w*ivln2; - t1 = u+v; - GET_FLOAT_WORD(is,t1); - SET_FLOAT_WORD(t1,is&0xfffff000); - t2 = v-(t1-u); - } else { - float s2,s_h,s_l,t_h,t_l; - n = 0; - /* take care subnormal number */ - if(ix<0x00800000) - {ax *= two24; n -= 24; GET_FLOAT_WORD(ix,ax); } - n += ((ix)>>23)-0x7f; - j = ix&0x007fffff; - /* determine interval */ - ix = j|0x3f800000; /* normalize ix */ - if(j<=0x1cc471) k=0; /* |x|>1)&0xfffff000)|0x20000000; - SET_FLOAT_WORD(t_h,is+0x00400000+(k<<21)); - t_l = ax - (t_h-bp[k]); - s_l = v*((u-s_h*t_h)-s_h*t_l); - /* compute log(ax) */ - s2 = s*s; - r = s2*s2*(L1+s2*(L2+s2*(L3+s2*(L4+s2*(L5+s2*L6))))); - r += s_l*(s_h+s); - s2 = s_h*s_h; - t_h = (float)3.0+s2+r; - GET_FLOAT_WORD(is,t_h); - SET_FLOAT_WORD(t_h,is&0xfffff000); - t_l = r-((t_h-(float)3.0)-s2); - /* u+v = s*(1+...) */ - u = s_h*t_h; - v = s_l*t_h+t_l*s; - /* 2/(3log2)*(s+...) */ - p_h = u+v; - GET_FLOAT_WORD(is,p_h); - SET_FLOAT_WORD(p_h,is&0xfffff000); - p_l = v-(p_h-u); - z_h = cp_h*p_h; /* cp_h+cp_l = 2/(3*log2) */ - z_l = cp_l*p_h+p_l*cp+dp_l[k]; - /* log2(ax) = (s+..)*2/(3*log2) = n + dp_h + z_h + z_l */ - t = (float)n; - t1 = (((z_h+z_l)+dp_h[k])+t); - GET_FLOAT_WORD(is,t1); - SET_FLOAT_WORD(t1,is&0xfffff000); - t2 = z_l-(((t1-t)-dp_h[k])-z_h); - } - - /* split up y into y1+y2 and compute (y1+y2)*(t1+t2) */ - GET_FLOAT_WORD(is,y); - SET_FLOAT_WORD(y1,is&0xfffff000); - p_l = (y-y1)*t1+y*t2; - p_h = y1*t1; - z = p_l+p_h; - GET_FLOAT_WORD(j,z); - if (j>0x43000000) /* if z > 128 */ - return sn*huge*huge; /* overflow */ - else if (j==0x43000000) { /* if z == 128 */ - if(p_l+ovt>z-p_h) return sn*huge*huge; /* overflow */ - } - else if ((j&0x7fffffff)>0x43160000) /* z <= -150 */ - return sn*tiny*tiny; /* underflow */ - else if (j==0xc3160000){ /* z == -150 */ - if(p_l<=z-p_h) return sn*tiny*tiny; /* underflow */ - } - /* - * compute 2**(p_h+p_l) - */ - i = j&0x7fffffff; - k = (i>>23)-0x7f; - n = 0; - if(i>0x3f000000) { /* if |z| > 0.5, set n = [z+0.5] */ - n = j+(0x00800000>>(k+1)); - k = ((n&0x7fffffff)>>23)-0x7f; /* new k for n */ - SET_FLOAT_WORD(t,n&~(0x007fffff>>k)); - n = ((n&0x007fffff)|0x00800000)>>(23-k); - if(j<0) n = -n; - p_h -= t; - } - t = p_l+p_h; - GET_FLOAT_WORD(is,t); - SET_FLOAT_WORD(t,is&0xffff8000); - u = t*lg2_h; - v = (p_l-(t-p_h))*lg2+t*lg2_l; - z = u+v; - w = v-(z-u); - t = z*z; - t1 = z - t*(P1+t*(P2+t*(P3+t*(P4+t*P5)))); - r = (z*t1)/(t1-two)-(w+z*w); - z = one-(r-z); - GET_FLOAT_WORD(j,z); - j += (n<<23); - if((j>>23)<=0) z = scalbnf(z,n); /* subnormal output */ - else SET_FLOAT_WORD(z,j); - return sn*z; -} diff --git a/05/musl-final/src/math/e_rem_pio2.c b/05/musl-final/src/math/e_rem_pio2.c deleted file mode 100644 index 9eee36a..0000000 --- a/05/musl-final/src/math/e_rem_pio2.c +++ /dev/null @@ -1,163 +0,0 @@ - -/* @(#)e_rem_pio2.c 1.4 95/01/18 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - * - */ - -/* __ieee754_rem_pio2(x,y) - * - * return the remainder of x rem pi/2 in y[0]+y[1] - * use __kernel_rem_pio2() - */ - -#include -#include "math_private.h" - -/* - * Table of constants for 2/pi, 396 Hex digits (476 decimal) of 2/pi - */ -static const int32_t two_over_pi[] = { -0xA2F983, 0x6E4E44, 0x1529FC, 0x2757D1, 0xF534DD, 0xC0DB62, -0x95993C, 0x439041, 0xFE5163, 0xABDEBB, 0xC561B7, 0x246E3A, -0x424DD2, 0xE00649, 0x2EEA09, 0xD1921C, 0xFE1DEB, 0x1CB129, -0xA73EE8, 0x8235F5, 0x2EBB44, 0x84E99C, 0x7026B4, 0x5F7E41, -0x3991D6, 0x398353, 0x39F49C, 0x845F8B, 0xBDF928, 0x3B1FF8, -0x97FFDE, 0x05980F, 0xEF2F11, 0x8B5A0A, 0x6D1F6D, 0x367ECF, -0x27CB09, 0xB74F46, 0x3F669E, 0x5FEA2D, 0x7527BA, 0xC7EBE5, -0xF17B3D, 0x0739F7, 0x8A5292, 0xEA6BFB, 0x5FB11F, 0x8D5D08, -0x560330, 0x46FC7B, 0x6BABF0, 0xCFBC20, 0x9AF436, 0x1DA9E3, -0x91615E, 0xE61B08, 0x659985, 0x5F14A0, 0x68408D, 0xFFD880, -0x4D7327, 0x310606, 0x1556CA, 0x73A8C9, 0x60E27B, 0xC08C6B, -}; - -static const int32_t npio2_hw[] = { -0x3FF921FB, 0x400921FB, 0x4012D97C, 0x401921FB, 0x401F6A7A, 0x4022D97C, -0x4025FDBB, 0x402921FB, 0x402C463A, 0x402F6A7A, 0x4031475C, 0x4032D97C, -0x40346B9C, 0x4035FDBB, 0x40378FDB, 0x403921FB, 0x403AB41B, 0x403C463A, -0x403DD85A, 0x403F6A7A, 0x40407E4C, 0x4041475C, 0x4042106C, 0x4042D97C, -0x4043A28C, 0x40446B9C, 0x404534AC, 0x4045FDBB, 0x4046C6CB, 0x40478FDB, -0x404858EB, 0x404921FB, -}; - -/* - * invpio2: 53 bits of 2/pi - * pio2_1: first 33 bit of pi/2 - * pio2_1t: pi/2 - pio2_1 - * pio2_2: second 33 bit of pi/2 - * pio2_2t: pi/2 - (pio2_1+pio2_2) - * pio2_3: third 33 bit of pi/2 - * pio2_3t: pi/2 - (pio2_1+pio2_2+pio2_3) - */ - -static const double -zero = 0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */ -half = 5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */ -two24 = 1.67772160000000000000e+07, /* 0x41700000, 0x00000000 */ -invpio2 = 6.36619772367581382433e-01, /* 0x3FE45F30, 0x6DC9C883 */ -pio2_1 = 1.57079632673412561417e+00, /* 0x3FF921FB, 0x54400000 */ -pio2_1t = 6.07710050650619224932e-11, /* 0x3DD0B461, 0x1A626331 */ -pio2_2 = 6.07710050630396597660e-11, /* 0x3DD0B461, 0x1A600000 */ -pio2_2t = 2.02226624879595063154e-21, /* 0x3BA3198A, 0x2E037073 */ -pio2_3 = 2.02226624871116645580e-21, /* 0x3BA3198A, 0x2E000000 */ -pio2_3t = 8.47842766036889956997e-32; /* 0x397B839A, 0x252049C1 */ - -int32_t __ieee754_rem_pio2(double x, double *y) -{ - double z,w,t,r,fn; - double tx[3]; - int32_t e0,i,j,nx,n,ix,hx; - uint32_t low; - - GET_HIGH_WORD(hx,x); /* high word of x */ - ix = hx&0x7fffffff; - if(ix<=0x3fe921fb) /* |x| ~<= pi/4 , no need for reduction */ - {y[0] = x; y[1] = 0; return 0;} - if(ix<0x4002d97c) { /* |x| < 3pi/4, special case with n=+-1 */ - if(hx>0) { - z = x - pio2_1; - if(ix!=0x3ff921fb) { /* 33+53 bit pi is good enough */ - y[0] = z - pio2_1t; - y[1] = (z-y[0])-pio2_1t; - } else { /* near pi/2, use 33+33+53 bit pi */ - z -= pio2_2; - y[0] = z - pio2_2t; - y[1] = (z-y[0])-pio2_2t; - } - return 1; - } else { /* negative x */ - z = x + pio2_1; - if(ix!=0x3ff921fb) { /* 33+53 bit pi is good enough */ - y[0] = z + pio2_1t; - y[1] = (z-y[0])+pio2_1t; - } else { /* near pi/2, use 33+33+53 bit pi */ - z += pio2_2; - y[0] = z + pio2_2t; - y[1] = (z-y[0])+pio2_2t; - } - return -1; - } - } - if(ix<=0x413921fb) { /* |x| ~<= 2^19*(pi/2), medium size */ - t = fabs(x); - n = (int32_t) (t*invpio2+half); - fn = (double)n; - r = t-fn*pio2_1; - w = fn*pio2_1t; /* 1st round good to 85 bit */ - if(n<32&&ix!=npio2_hw[n-1]) { - y[0] = r-w; /* quick check no cancellation */ - } else { - uint32_t high; - j = ix>>20; - y[0] = r-w; - GET_HIGH_WORD(high,y[0]); - i = j-((high>>20)&0x7ff); - if(i>16) { /* 2nd iteration needed, good to 118 */ - t = r; - w = fn*pio2_2; - r = t-w; - w = fn*pio2_2t-((t-r)-w); - y[0] = r-w; - GET_HIGH_WORD(high,y[0]); - i = j-((high>>20)&0x7ff); - if(i>49) { /* 3rd iteration need, 151 bits acc */ - t = r; /* will cover all possible cases */ - w = fn*pio2_3; - r = t-w; - w = fn*pio2_3t-((t-r)-w); - y[0] = r-w; - } - } - } - y[1] = (r-y[0])-w; - if(hx<0) {y[0] = -y[0]; y[1] = -y[1]; return -n;} - else return n; - } - /* - * all other (large) arguments - */ - if(ix>=0x7ff00000) { /* x is inf or NaN */ - y[0]=y[1]=x-x; return 0; - } - /* set z = scalbn(|x|,ilogb(x)-23) */ - GET_LOW_WORD(low,x); - e0 = (ix>>20)-1046; /* e0 = ilogb(z)-23; */ - INSERT_WORDS(z, ix - ((int32_t)(e0<<20)), low); - for(i=0;i<2;i++) { - tx[i] = (double)((int32_t)(z)); - z = (z-tx[i])*two24; - } - tx[2] = z; - nx = 3; - while(tx[nx-1]==zero) nx--; /* skip zero term */ - n = __kernel_rem_pio2(tx,y,e0,nx,2,two_over_pi); - if(hx<0) {y[0] = -y[0]; y[1] = -y[1]; return -n;} - return n; -} diff --git a/05/musl-final/src/math/e_rem_pio2f.c b/05/musl-final/src/math/e_rem_pio2f.c deleted file mode 100644 index 4992ea0..0000000 --- a/05/musl-final/src/math/e_rem_pio2f.c +++ /dev/null @@ -1,175 +0,0 @@ -/* e_rem_pio2f.c -- float version of e_rem_pio2.c - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* __ieee754_rem_pio2f(x,y) - * - * return the remainder of x rem pi/2 in y[0]+y[1] - * use __kernel_rem_pio2f() - */ - -#include -#include "math_private.h" - -/* - * Table of constants for 2/pi, 396 Hex digits (476 decimal) of 2/pi - */ -static const int32_t two_over_pi[] = { -0xA2, 0xF9, 0x83, 0x6E, 0x4E, 0x44, 0x15, 0x29, 0xFC, -0x27, 0x57, 0xD1, 0xF5, 0x34, 0xDD, 0xC0, 0xDB, 0x62, -0x95, 0x99, 0x3C, 0x43, 0x90, 0x41, 0xFE, 0x51, 0x63, -0xAB, 0xDE, 0xBB, 0xC5, 0x61, 0xB7, 0x24, 0x6E, 0x3A, -0x42, 0x4D, 0xD2, 0xE0, 0x06, 0x49, 0x2E, 0xEA, 0x09, -0xD1, 0x92, 0x1C, 0xFE, 0x1D, 0xEB, 0x1C, 0xB1, 0x29, -0xA7, 0x3E, 0xE8, 0x82, 0x35, 0xF5, 0x2E, 0xBB, 0x44, -0x84, 0xE9, 0x9C, 0x70, 0x26, 0xB4, 0x5F, 0x7E, 0x41, -0x39, 0x91, 0xD6, 0x39, 0x83, 0x53, 0x39, 0xF4, 0x9C, -0x84, 0x5F, 0x8B, 0xBD, 0xF9, 0x28, 0x3B, 0x1F, 0xF8, -0x97, 0xFF, 0xDE, 0x05, 0x98, 0x0F, 0xEF, 0x2F, 0x11, -0x8B, 0x5A, 0x0A, 0x6D, 0x1F, 0x6D, 0x36, 0x7E, 0xCF, -0x27, 0xCB, 0x09, 0xB7, 0x4F, 0x46, 0x3F, 0x66, 0x9E, -0x5F, 0xEA, 0x2D, 0x75, 0x27, 0xBA, 0xC7, 0xEB, 0xE5, -0xF1, 0x7B, 0x3D, 0x07, 0x39, 0xF7, 0x8A, 0x52, 0x92, -0xEA, 0x6B, 0xFB, 0x5F, 0xB1, 0x1F, 0x8D, 0x5D, 0x08, -0x56, 0x03, 0x30, 0x46, 0xFC, 0x7B, 0x6B, 0xAB, 0xF0, -0xCF, 0xBC, 0x20, 0x9A, 0xF4, 0x36, 0x1D, 0xA9, 0xE3, -0x91, 0x61, 0x5E, 0xE6, 0x1B, 0x08, 0x65, 0x99, 0x85, -0x5F, 0x14, 0xA0, 0x68, 0x40, 0x8D, 0xFF, 0xD8, 0x80, -0x4D, 0x73, 0x27, 0x31, 0x06, 0x06, 0x15, 0x56, 0xCA, -0x73, 0xA8, 0xC9, 0x60, 0xE2, 0x7B, 0xC0, 0x8C, 0x6B, -}; - -/* This array is like the one in e_rem_pio2.c, but the numbers are - single precision and the last 8 bits are forced to 0. */ -static const int32_t npio2_hw[] = { -0x3fc90f00, 0x40490f00, 0x4096cb00, 0x40c90f00, 0x40fb5300, 0x4116cb00, -0x412fed00, 0x41490f00, 0x41623100, 0x417b5300, 0x418a3a00, 0x4196cb00, -0x41a35c00, 0x41afed00, 0x41bc7e00, 0x41c90f00, 0x41d5a000, 0x41e23100, -0x41eec200, 0x41fb5300, 0x4203f200, 0x420a3a00, 0x42108300, 0x4216cb00, -0x421d1400, 0x42235c00, 0x4229a500, 0x422fed00, 0x42363600, 0x423c7e00, -0x4242c700, 0x42490f00 -}; - -/* - * invpio2: 24 bits of 2/pi - * pio2_1: first 17 bit of pi/2 - * pio2_1t: pi/2 - pio2_1 - * pio2_2: second 17 bit of pi/2 - * pio2_2t: pi/2 - (pio2_1+pio2_2) - * pio2_3: third 17 bit of pi/2 - * pio2_3t: pi/2 - (pio2_1+pio2_2+pio2_3) - */ - -static const float -zero = 0.0000000000e+00, /* 0x00000000 */ -half = 5.0000000000e-01, /* 0x3f000000 */ -two8 = 2.5600000000e+02, /* 0x43800000 */ -invpio2 = 6.3661980629e-01, /* 0x3f22f984 */ -pio2_1 = 1.5707855225e+00, /* 0x3fc90f80 */ -pio2_1t = 1.0804334124e-05, /* 0x37354443 */ -pio2_2 = 1.0804273188e-05, /* 0x37354400 */ -pio2_2t = 6.0770999344e-11, /* 0x2e85a308 */ -pio2_3 = 6.0770943833e-11, /* 0x2e85a300 */ -pio2_3t = 6.1232342629e-17; /* 0x248d3132 */ - -int32_t __ieee754_rem_pio2f(float x, float *y) -{ - float z,w,t,r,fn; - float tx[3]; - int32_t e0,i,j,nx,n,ix,hx; - - GET_FLOAT_WORD(hx,x); - ix = hx&0x7fffffff; - if(ix<=0x3f490fd8) /* |x| ~<= pi/4 , no need for reduction */ - {y[0] = x; y[1] = 0; return 0;} - if(ix<0x4016cbe4) { /* |x| < 3pi/4, special case with n=+-1 */ - if(hx>0) { - z = x - pio2_1; - if((ix&0xfffffff0)!=0x3fc90fd0) { /* 24+24 bit pi OK */ - y[0] = z - pio2_1t; - y[1] = (z-y[0])-pio2_1t; - } else { /* near pi/2, use 24+24+24 bit pi */ - z -= pio2_2; - y[0] = z - pio2_2t; - y[1] = (z-y[0])-pio2_2t; - } - return 1; - } else { /* negative x */ - z = x + pio2_1; - if((ix&0xfffffff0)!=0x3fc90fd0) { /* 24+24 bit pi OK */ - y[0] = z + pio2_1t; - y[1] = (z-y[0])+pio2_1t; - } else { /* near pi/2, use 24+24+24 bit pi */ - z += pio2_2; - y[0] = z + pio2_2t; - y[1] = (z-y[0])+pio2_2t; - } - return -1; - } - } - if(ix<=0x43490f80) { /* |x| ~<= 2^7*(pi/2), medium size */ - t = fabsf(x); - n = (int32_t) (t*invpio2+half); - fn = (float)n; - r = t-fn*pio2_1; - w = fn*pio2_1t; /* 1st round good to 40 bit */ - if(n<32&&(ix&0xffffff00)!=npio2_hw[n-1]) { - y[0] = r-w; /* quick check no cancellation */ - } else { - uint32_t high; - j = ix>>23; - y[0] = r-w; - GET_FLOAT_WORD(high,y[0]); - i = j-((high>>23)&0xff); - if(i>8) { /* 2nd iteration needed, good to 57 */ - t = r; - w = fn*pio2_2; - r = t-w; - w = fn*pio2_2t-((t-r)-w); - y[0] = r-w; - GET_FLOAT_WORD(high,y[0]); - i = j-((high>>23)&0xff); - if(i>25) { /* 3rd iteration need, 74 bits acc */ - t = r; /* will cover all possible cases */ - w = fn*pio2_3; - r = t-w; - w = fn*pio2_3t-((t-r)-w); - y[0] = r-w; - } - } - } - y[1] = (r-y[0])-w; - if(hx<0) {y[0] = -y[0]; y[1] = -y[1]; return -n;} - else return n; - } - /* - * all other (large) arguments - */ - if(ix>=0x7f800000) { /* x is inf or NaN */ - y[0]=y[1]=x-x; return 0; - } - /* set z = scalbn(|x|,ilogb(x)-7) */ - e0 = (ix>>23)-134; /* e0 = ilogb(z)-7; */ - SET_FLOAT_WORD(z, ix - ((int32_t)(e0<<23))); - for(i=0;i<2;i++) { - tx[i] = (float)((int32_t)(z)); - z = (z-tx[i])*two8; - } - tx[2] = z; - nx = 3; - while(tx[nx-1]==zero) nx--; /* skip zero term */ - n = __kernel_rem_pio2f(tx,y,e0,nx,2,two_over_pi); - if(hx<0) {y[0] = -y[0]; y[1] = -y[1]; return -n;} - return n; -} diff --git a/05/musl-final/src/math/e_remainder.c b/05/musl-final/src/math/e_remainder.c deleted file mode 100644 index 9cb5691..0000000 --- a/05/musl-final/src/math/e_remainder.c +++ /dev/null @@ -1,69 +0,0 @@ - -/* @(#)e_remainder.c 1.3 95/01/18 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* remainder(x,p) - * Return : - * returns x REM p = x - [x/p]*p as if in infinite - * precise arithmetic, where [x/p] is the (infinite bit) - * integer nearest x/p (in half way case choose the even one). - * Method : - * Based on fmod() return x-[x/p]chopped*p exactlp. - */ - -#include -#include "math_private.h" - -static const double zero = 0.0; - - -double -remainder(double x, double p) -{ - int32_t hx,hp; - uint32_t sx,lx,lp; - double p_half; - - EXTRACT_WORDS(hx,lx,x); - EXTRACT_WORDS(hp,lp,p); - sx = hx&0x80000000; - hp &= 0x7fffffff; - hx &= 0x7fffffff; - - /* purge off exception values */ - if((hp|lp)==0) return (x*p)/(x*p); /* p = 0 */ - if((hx>=0x7ff00000)|| /* x not finite */ - ((hp>=0x7ff00000)&& /* p is NaN */ - (((hp-0x7ff00000)|lp)!=0))) - return (x*p)/(x*p); - - - if (hp<=0x7fdfffff) x = fmod(x,p+p); /* now x < 2p */ - if (((hx-hp)|(lx-lp))==0) return zero*x; - x = fabs(x); - p = fabs(p); - if (hp<0x00200000) { - if(x+x>p) { - x-=p; - if(x+x>=p) x -= p; - } - } else { - p_half = 0.5*p; - if(x>p_half) { - x-=p; - if(x>=p_half) x -= p; - } - } - GET_HIGH_WORD(hx,x); - SET_HIGH_WORD(x,hx^sx); - return x; -} diff --git a/05/musl-final/src/math/e_remainderf.c b/05/musl-final/src/math/e_remainderf.c deleted file mode 100644 index c292367..0000000 --- a/05/musl-final/src/math/e_remainderf.c +++ /dev/null @@ -1,61 +0,0 @@ -/* e_remainderf.c -- float version of e_remainder.c. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include -#include "math_private.h" - -static const float zero = 0.0; - - -float -remainderf(float x, float p) -{ - int32_t hx,hp; - uint32_t sx; - float p_half; - - GET_FLOAT_WORD(hx,x); - GET_FLOAT_WORD(hp,p); - sx = hx&0x80000000; - hp &= 0x7fffffff; - hx &= 0x7fffffff; - - /* purge off exception values */ - if(hp==0) return (x*p)/(x*p); /* p = 0 */ - if((hx>=0x7f800000)|| /* x not finite */ - ((hp>0x7f800000))) /* p is NaN */ - return (x*p)/(x*p); - - - if (hp<=0x7effffff) x = fmodf(x,p+p); /* now x < 2p */ - if ((hx-hp)==0) return zero*x; - x = fabsf(x); - p = fabsf(p); - if (hp<0x01000000) { - if(x+x>p) { - x-=p; - if(x+x>=p) x -= p; - } - } else { - p_half = (float)0.5*p; - if(x>p_half) { - x-=p; - if(x>=p_half) x -= p; - } - } - GET_FLOAT_WORD(hx,x); - SET_FLOAT_WORD(x,hx^sx); - return x; -} diff --git a/05/musl-final/src/math/e_scalb.c b/05/musl-final/src/math/e_scalb.c deleted file mode 100644 index cee2b44..0000000 --- a/05/musl-final/src/math/e_scalb.c +++ /dev/null @@ -1,35 +0,0 @@ - -/* @(#)e_scalb.c 1.3 95/01/18 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* - * scalb(x, fn) is provide for - * passing various standard test suite. One - * should use scalbn() instead. - */ - -#include -#include "math_private.h" - -double -scalb(double x, double fn) -{ - if (isnan(x)||isnan(fn)) return x*fn; - if (!isfinite(fn)) { - if(fn>0.0) return x*fn; - else return x/(-fn); - } - if (rint(fn)!=fn) return (fn-fn)/(fn-fn); - if ( fn > 65000.0) return scalbn(x, 65000); - if (-fn > 65000.0) return scalbn(x,-65000); - return scalbn(x,(int)fn); -} diff --git a/05/musl-final/src/math/e_scalbf.c b/05/musl-final/src/math/e_scalbf.c deleted file mode 100644 index de7d7f6..0000000 --- a/05/musl-final/src/math/e_scalbf.c +++ /dev/null @@ -1,31 +0,0 @@ -/* e_scalbf.c -- float version of e_scalb.c. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include -#include "math_private.h" - -float -scalbf(float x, float fn) -{ - if (isnan(x)||isnan(fn)) return x*fn; - if (!isfinite(fn)) { - if(fn>(float)0.0) return x*fn; - else return x/(-fn); - } - if (rintf(fn)!=fn) return (fn-fn)/(fn-fn); - if ( fn > (float)65000.0) return scalbnf(x, 65000); - if (-fn > (float)65000.0) return scalbnf(x,-65000); - return scalbnf(x,(int)fn); -} diff --git a/05/musl-final/src/math/e_sinh.c b/05/musl-final/src/math/e_sinh.c deleted file mode 100644 index 3a57427..0000000 --- a/05/musl-final/src/math/e_sinh.c +++ /dev/null @@ -1,75 +0,0 @@ - -/* @(#)e_sinh.c 1.3 95/01/18 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* sinh(x) - * Method : - * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2 - * 1. Replace x by |x| (sinh(-x) = -sinh(x)). - * 2. - * E + E/(E+1) - * 0 <= x <= 22 : sinh(x) := --------------, E=expm1(x) - * 2 - * - * 22 <= x <= lnovft : sinh(x) := exp(x)/2 - * lnovft <= x <= ln2ovft: sinh(x) := exp(x/2)/2 * exp(x/2) - * ln2ovft < x : sinh(x) := x*shuge (overflow) - * - * Special cases: - * sinh(x) is |x| if x is +INF, -INF, or NaN. - * only sinh(0)=0 is exact for finite x. - */ - -#include -#include "math_private.h" - -static const double one = 1.0, shuge = 1.0e307; - -double -sinh(double x) -{ - double t,w,h; - int32_t ix,jx; - uint32_t lx; - - /* High word of |x|. */ - GET_HIGH_WORD(jx,x); - ix = jx&0x7fffffff; - - /* x is INF or NaN */ - if(ix>=0x7ff00000) return x+x; - - h = 0.5; - if (jx<0) h = -h; - /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */ - if (ix < 0x40360000) { /* |x|<22 */ - if (ix<0x3e300000) /* |x|<2**-28 */ - if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */ - t = expm1(fabs(x)); - if(ix<0x3ff00000) return h*(2.0*t-t*t/(t+one)); - return h*(t+t/(t+one)); - } - - /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */ - if (ix < 0x40862E42) return h*exp(fabs(x)); - - /* |x| in [log(maxdouble), overflowthresold] */ - GET_LOW_WORD(lx,x); - if (ix<0x408633CE || ((ix==0x408633ce)&&(lx<=(uint32_t)0x8fb9f87d))) { - w = exp(0.5*fabs(x)); - t = h*w; - return t*w; - } - - /* |x| > overflowthresold, sinh(x) overflow */ - return x*shuge; -} diff --git a/05/musl-final/src/math/e_sinhf.c b/05/musl-final/src/math/e_sinhf.c deleted file mode 100644 index fe60608..0000000 --- a/05/musl-final/src/math/e_sinhf.c +++ /dev/null @@ -1,56 +0,0 @@ -/* e_sinhf.c -- float version of e_sinh.c. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include -#include "math_private.h" - -static const float one = 1.0, shuge = 1.0e37; - -float -sinhf(float x) -{ - float t,w,h; - int32_t ix,jx; - - GET_FLOAT_WORD(jx,x); - ix = jx&0x7fffffff; - - /* x is INF or NaN */ - if(ix>=0x7f800000) return x+x; - - h = 0.5; - if (jx<0) h = -h; - /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */ - if (ix < 0x41b00000) { /* |x|<22 */ - if (ix<0x31800000) /* |x|<2**-28 */ - if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */ - t = expm1f(fabsf(x)); - if(ix<0x3f800000) return h*((float)2.0*t-t*t/(t+one)); - return h*(t+t/(t+one)); - } - - /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */ - if (ix < 0x42b17180) return h*expf(fabsf(x)); - - /* |x| in [log(maxdouble), overflowthresold] */ - if (ix<=0x42b2d4fc) { - w = expf((float)0.5*fabsf(x)); - t = h*w; - return t*w; - } - - /* |x| > overflowthresold, sinh(x) overflow */ - return x*shuge; -} diff --git a/05/musl-final/src/math/e_sqrt.c b/05/musl-final/src/math/e_sqrt.c deleted file mode 100644 index 2bc6874..0000000 --- a/05/musl-final/src/math/e_sqrt.c +++ /dev/null @@ -1,442 +0,0 @@ - -/* @(#)e_sqrt.c 1.3 95/01/18 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* sqrt(x) - * Return correctly rounded sqrt. - * ------------------------------------------ - * | Use the hardware sqrt if you have one | - * ------------------------------------------ - * Method: - * Bit by bit method using integer arithmetic. (Slow, but portable) - * 1. Normalization - * Scale x to y in [1,4) with even powers of 2: - * find an integer k such that 1 <= (y=x*2^(2k)) < 4, then - * sqrt(x) = 2^k * sqrt(y) - * 2. Bit by bit computation - * Let q = sqrt(y) truncated to i bit after binary point (q = 1), - * i 0 - * i+1 2 - * s = 2*q , and y = 2 * ( y - q ). (1) - * i i i i - * - * To compute q from q , one checks whether - * i+1 i - * - * -(i+1) 2 - * (q + 2 ) <= y. (2) - * i - * -(i+1) - * If (2) is false, then q = q ; otherwise q = q + 2 . - * i+1 i i+1 i - * - * With some algebric manipulation, it is not difficult to see - * that (2) is equivalent to - * -(i+1) - * s + 2 <= y (3) - * i i - * - * The advantage of (3) is that s and y can be computed by - * i i - * the following recurrence formula: - * if (3) is false - * - * s = s , y = y ; (4) - * i+1 i i+1 i - * - * otherwise, - * -i -(i+1) - * s = s + 2 , y = y - s - 2 (5) - * i+1 i i+1 i i - * - * One may easily use induction to prove (4) and (5). - * Note. Since the left hand side of (3) contain only i+2 bits, - * it does not necessary to do a full (53-bit) comparison - * in (3). - * 3. Final rounding - * After generating the 53 bits result, we compute one more bit. - * Together with the remainder, we can decide whether the - * result is exact, bigger than 1/2ulp, or less than 1/2ulp - * (it will never equal to 1/2ulp). - * The rounding mode can be detected by checking whether - * huge + tiny is equal to huge, and whether huge - tiny is - * equal to huge for some floating point number "huge" and "tiny". - * - * Special cases: - * sqrt(+-0) = +-0 ... exact - * sqrt(inf) = inf - * sqrt(-ve) = NaN ... with invalid signal - * sqrt(NaN) = NaN ... with invalid signal for signaling NaN - * - * Other methods : see the appended file at the end of the program below. - *--------------- - */ - -#include -#include "math_private.h" - -static const double one = 1.0, tiny=1.0e-300; - -double -sqrt(double x) -{ - double z; - int32_t sign = (int)0x80000000; - int32_t ix0,s0,q,m,t,i; - uint32_t r,t1,s1,ix1,q1; - - EXTRACT_WORDS(ix0,ix1,x); - - /* take care of Inf and NaN */ - if((ix0&0x7ff00000)==0x7ff00000) { - return x*x+x; /* sqrt(NaN)=NaN, sqrt(+inf)=+inf - sqrt(-inf)=sNaN */ - } - /* take care of zero */ - if(ix0<=0) { - if(((ix0&(~sign))|ix1)==0) return x;/* sqrt(+-0) = +-0 */ - else if(ix0<0) - return (x-x)/(x-x); /* sqrt(-ve) = sNaN */ - } - /* normalize x */ - m = (ix0>>20); - if(m==0) { /* subnormal x */ - while(ix0==0) { - m -= 21; - ix0 |= (ix1>>11); ix1 <<= 21; - } - for(i=0;(ix0&0x00100000)==0;i++) ix0<<=1; - m -= i-1; - ix0 |= (ix1>>(32-i)); - ix1 <<= i; - } - m -= 1023; /* unbias exponent */ - ix0 = (ix0&0x000fffff)|0x00100000; - if(m&1){ /* odd m, double x to make it even */ - ix0 += ix0 + ((ix1&sign)>>31); - ix1 += ix1; - } - m >>= 1; /* m = [m/2] */ - - /* generate sqrt(x) bit by bit */ - ix0 += ix0 + ((ix1&sign)>>31); - ix1 += ix1; - q = q1 = s0 = s1 = 0; /* [q,q1] = sqrt(x) */ - r = 0x00200000; /* r = moving bit from right to left */ - - while(r!=0) { - t = s0+r; - if(t<=ix0) { - s0 = t+r; - ix0 -= t; - q += r; - } - ix0 += ix0 + ((ix1&sign)>>31); - ix1 += ix1; - r>>=1; - } - - r = sign; - while(r!=0) { - t1 = s1+r; - t = s0; - if((t>31); - ix1 += ix1; - r>>=1; - } - - /* use floating add to find out rounding direction */ - if((ix0|ix1)!=0) { - z = one-tiny; /* trigger inexact flag */ - if (z>=one) { - z = one+tiny; - if (q1==(uint32_t)0xffffffff) { q1=0; q += 1;} - else if (z>one) { - if (q1==(uint32_t)0xfffffffe) q+=1; - q1+=2; - } else - q1 += (q1&1); - } - } - ix0 = (q>>1)+0x3fe00000; - ix1 = q1>>1; - if ((q&1)==1) ix1 |= sign; - ix0 += (m <<20); - INSERT_WORDS(z,ix0,ix1); - return z; -} - -/* -Other methods (use floating-point arithmetic) -------------- -(This is a copy of a drafted paper by Prof W. Kahan -and K.C. Ng, written in May, 1986) - - Two algorithms are given here to implement sqrt(x) - (IEEE double precision arithmetic) in software. - Both supply sqrt(x) correctly rounded. The first algorithm (in - Section A) uses newton iterations and involves four divisions. - The second one uses reciproot iterations to avoid division, but - requires more multiplications. Both algorithms need the ability - to chop results of arithmetic operations instead of round them, - and the INEXACT flag to indicate when an arithmetic operation - is executed exactly with no roundoff error, all part of the - standard (IEEE 754-1985). The ability to perform shift, add, - subtract and logical AND operations upon 32-bit words is needed - too, though not part of the standard. - -A. sqrt(x) by Newton Iteration - - (1) Initial approximation - - Let x0 and x1 be the leading and the trailing 32-bit words of - a floating point number x (in IEEE double format) respectively - - 1 11 52 ...widths - ------------------------------------------------------ - x: |s| e | f | - ------------------------------------------------------ - msb lsb msb lsb ...order - - - ------------------------ ------------------------ - x0: |s| e | f1 | x1: | f2 | - ------------------------ ------------------------ - - By performing shifts and subtracts on x0 and x1 (both regarded - as integers), we obtain an 8-bit approximation of sqrt(x) as - follows. - - k := (x0>>1) + 0x1ff80000; - y0 := k - T1[31&(k>>15)]. ... y ~ sqrt(x) to 8 bits - Here k is a 32-bit integer and T1[] is an integer array containing - correction terms. Now magically the floating value of y (y's - leading 32-bit word is y0, the value of its trailing word is 0) - approximates sqrt(x) to almost 8-bit. - - Value of T1: - static int T1[32]= { - 0, 1024, 3062, 5746, 9193, 13348, 18162, 23592, - 29598, 36145, 43202, 50740, 58733, 67158, 75992, 85215, - 83599, 71378, 60428, 50647, 41945, 34246, 27478, 21581, - 16499, 12183, 8588, 5674, 3403, 1742, 661, 130,}; - - (2) Iterative refinement - - Apply Heron's rule three times to y, we have y approximates - sqrt(x) to within 1 ulp (Unit in the Last Place): - - y := (y+x/y)/2 ... almost 17 sig. bits - y := (y+x/y)/2 ... almost 35 sig. bits - y := y-(y-x/y)/2 ... within 1 ulp - - - Remark 1. - Another way to improve y to within 1 ulp is: - - y := (y+x/y) ... almost 17 sig. bits to 2*sqrt(x) - y := y - 0x00100006 ... almost 18 sig. bits to sqrt(x) - - 2 - (x-y )*y - y := y + 2* ---------- ...within 1 ulp - 2 - 3y + x - - - This formula has one division fewer than the one above; however, - it requires more multiplications and additions. Also x must be - scaled in advance to avoid spurious overflow in evaluating the - expression 3y*y+x. Hence it is not recommended uless division - is slow. If division is very slow, then one should use the - reciproot algorithm given in section B. - - (3) Final adjustment - - By twiddling y's last bit it is possible to force y to be - correctly rounded according to the prevailing rounding mode - as follows. Let r and i be copies of the rounding mode and - inexact flag before entering the square root program. Also we - use the expression y+-ulp for the next representable floating - numbers (up and down) of y. Note that y+-ulp = either fixed - point y+-1, or multiply y by nextafter(1,+-inf) in chopped - mode. - - I := FALSE; ... reset INEXACT flag I - R := RZ; ... set rounding mode to round-toward-zero - z := x/y; ... chopped quotient, possibly inexact - If(not I) then { ... if the quotient is exact - if(z=y) { - I := i; ... restore inexact flag - R := r; ... restore rounded mode - return sqrt(x):=y. - } else { - z := z - ulp; ... special rounding - } - } - i := TRUE; ... sqrt(x) is inexact - If (r=RN) then z=z+ulp ... rounded-to-nearest - If (r=RP) then { ... round-toward-+inf - y = y+ulp; z=z+ulp; - } - y := y+z; ... chopped sum - y0:=y0-0x00100000; ... y := y/2 is correctly rounded. - I := i; ... restore inexact flag - R := r; ... restore rounded mode - return sqrt(x):=y. - - (4) Special cases - - Square root of +inf, +-0, or NaN is itself; - Square root of a negative number is NaN with invalid signal. - - -B. sqrt(x) by Reciproot Iteration - - (1) Initial approximation - - Let x0 and x1 be the leading and the trailing 32-bit words of - a floating point number x (in IEEE double format) respectively - (see section A). By performing shifs and subtracts on x0 and y0, - we obtain a 7.8-bit approximation of 1/sqrt(x) as follows. - - k := 0x5fe80000 - (x0>>1); - y0:= k - T2[63&(k>>14)]. ... y ~ 1/sqrt(x) to 7.8 bits - - Here k is a 32-bit integer and T2[] is an integer array - containing correction terms. Now magically the floating - value of y (y's leading 32-bit word is y0, the value of - its trailing word y1 is set to zero) approximates 1/sqrt(x) - to almost 7.8-bit. - - Value of T2: - static int T2[64]= { - 0x1500, 0x2ef8, 0x4d67, 0x6b02, 0x87be, 0xa395, 0xbe7a, 0xd866, - 0xf14a, 0x1091b,0x11fcd,0x13552,0x14999,0x15c98,0x16e34,0x17e5f, - 0x18d03,0x19a01,0x1a545,0x1ae8a,0x1b5c4,0x1bb01,0x1bfde,0x1c28d, - 0x1c2de,0x1c0db,0x1ba73,0x1b11c,0x1a4b5,0x1953d,0x18266,0x16be0, - 0x1683e,0x179d8,0x18a4d,0x19992,0x1a789,0x1b445,0x1bf61,0x1c989, - 0x1d16d,0x1d77b,0x1dddf,0x1e2ad,0x1e5bf,0x1e6e8,0x1e654,0x1e3cd, - 0x1df2a,0x1d635,0x1cb16,0x1be2c,0x1ae4e,0x19bde,0x1868e,0x16e2e, - 0x1527f,0x1334a,0x11051,0xe951, 0xbe01, 0x8e0d, 0x5924, 0x1edd,}; - - (2) Iterative refinement - - Apply Reciproot iteration three times to y and multiply the - result by x to get an approximation z that matches sqrt(x) - to about 1 ulp. To be exact, we will have - -1ulp < sqrt(x)-z<1.0625ulp. - - ... set rounding mode to Round-to-nearest - y := y*(1.5-0.5*x*y*y) ... almost 15 sig. bits to 1/sqrt(x) - y := y*((1.5-2^-30)+0.5*x*y*y)... about 29 sig. bits to 1/sqrt(x) - ... special arrangement for better accuracy - z := x*y ... 29 bits to sqrt(x), with z*y<1 - z := z + 0.5*z*(1-z*y) ... about 1 ulp to sqrt(x) - - Remark 2. The constant 1.5-2^-30 is chosen to bias the error so that - (a) the term z*y in the final iteration is always less than 1; - (b) the error in the final result is biased upward so that - -1 ulp < sqrt(x) - z < 1.0625 ulp - instead of |sqrt(x)-z|<1.03125ulp. - - (3) Final adjustment - - By twiddling y's last bit it is possible to force y to be - correctly rounded according to the prevailing rounding mode - as follows. Let r and i be copies of the rounding mode and - inexact flag before entering the square root program. Also we - use the expression y+-ulp for the next representable floating - numbers (up and down) of y. Note that y+-ulp = either fixed - point y+-1, or multiply y by nextafter(1,+-inf) in chopped - mode. - - R := RZ; ... set rounding mode to round-toward-zero - switch(r) { - case RN: ... round-to-nearest - if(x<= z*(z-ulp)...chopped) z = z - ulp; else - if(x<= z*(z+ulp)...chopped) z = z; else z = z+ulp; - break; - case RZ:case RM: ... round-to-zero or round-to--inf - R:=RP; ... reset rounding mod to round-to-+inf - if(x=(z+ulp)*(z+ulp) ...rounded up) z = z+ulp; - break; - case RP: ... round-to-+inf - if(x>(z+ulp)*(z+ulp)...chopped) z = z+2*ulp; else - if(x>z*z ...chopped) z = z+ulp; - break; - } - - Remark 3. The above comparisons can be done in fixed point. For - example, to compare x and w=z*z chopped, it suffices to compare - x1 and w1 (the trailing parts of x and w), regarding them as - two's complement integers. - - ...Is z an exact square root? - To determine whether z is an exact square root of x, let z1 be the - trailing part of z, and also let x0 and x1 be the leading and - trailing parts of x. - - If ((z1&0x03ffffff)!=0) ... not exact if trailing 26 bits of z!=0 - I := 1; ... Raise Inexact flag: z is not exact - else { - j := 1 - [(x0>>20)&1] ... j = logb(x) mod 2 - k := z1 >> 26; ... get z's 25-th and 26-th - fraction bits - I := i or (k&j) or ((k&(j+j+1))!=(x1&3)); - } - R:= r ... restore rounded mode - return sqrt(x):=z. - - If multiplication is cheaper then the foregoing red tape, the - Inexact flag can be evaluated by - - I := i; - I := (z*z!=x) or I. - - Note that z*z can overwrite I; this value must be sensed if it is - True. - - Remark 4. If z*z = x exactly, then bit 25 to bit 0 of z1 must be - zero. - - -------------------- - z1: | f2 | - -------------------- - bit 31 bit 0 - - Further more, bit 27 and 26 of z1, bit 0 and 1 of x1, and the odd - or even of logb(x) have the following relations: - - ------------------------------------------------- - bit 27,26 of z1 bit 1,0 of x1 logb(x) - ------------------------------------------------- - 00 00 odd and even - 01 01 even - 10 10 odd - 10 00 even - 11 01 even - ------------------------------------------------- - - (4) Special cases (see (4) of Section A). - - */ - diff --git a/05/musl-final/src/math/e_sqrtf.c b/05/musl-final/src/math/e_sqrtf.c deleted file mode 100644 index 03a15be..0000000 --- a/05/musl-final/src/math/e_sqrtf.c +++ /dev/null @@ -1,85 +0,0 @@ -/* e_sqrtf.c -- float version of e_sqrt.c. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include -#include "math_private.h" - -static const float one = 1.0, tiny=1.0e-30; - -float -sqrtf(float x) -{ - float z; - int32_t sign = (int)0x80000000; - int32_t ix,s,q,m,t,i; - uint32_t r; - - GET_FLOAT_WORD(ix,x); - - /* take care of Inf and NaN */ - if((ix&0x7f800000)==0x7f800000) { - return x*x+x; /* sqrt(NaN)=NaN, sqrt(+inf)=+inf - sqrt(-inf)=sNaN */ - } - /* take care of zero */ - if(ix<=0) { - if((ix&(~sign))==0) return x;/* sqrt(+-0) = +-0 */ - else if(ix<0) - return (x-x)/(x-x); /* sqrt(-ve) = sNaN */ - } - /* normalize x */ - m = (ix>>23); - if(m==0) { /* subnormal x */ - for(i=0;(ix&0x00800000)==0;i++) ix<<=1; - m -= i-1; - } - m -= 127; /* unbias exponent */ - ix = (ix&0x007fffff)|0x00800000; - if(m&1) /* odd m, double x to make it even */ - ix += ix; - m >>= 1; /* m = [m/2] */ - - /* generate sqrt(x) bit by bit */ - ix += ix; - q = s = 0; /* q = sqrt(x) */ - r = 0x01000000; /* r = moving bit from right to left */ - - while(r!=0) { - t = s+r; - if(t<=ix) { - s = t+r; - ix -= t; - q += r; - } - ix += ix; - r>>=1; - } - - /* use floating add to find out rounding direction */ - if(ix!=0) { - z = one-tiny; /* trigger inexact flag */ - if (z>=one) { - z = one+tiny; - if (z>one) - q += 2; - else - q += (q&1); - } - } - ix = (q>>1)+0x3f000000; - ix += (m <<23); - SET_FLOAT_WORD(z,ix); - return z; -} diff --git a/05/musl-final/src/math/i386/e_exp.s b/05/musl-final/src/math/i386/e_exp.s deleted file mode 100644 index d6c54a3..0000000 --- a/05/musl-final/src/math/i386/e_exp.s +++ /dev/null @@ -1,36 +0,0 @@ -.global expf -expf: - mov 4(%esp),%eax - flds 4(%esp) - shr $23,%eax - inc %al - jz 1f - jmp 0f - -.global exp -exp: - mov 8(%esp),%eax - fldl 4(%esp) - shl %eax - cmp $0xffe00000,%eax - jae 1f - -0: fldl2e - fmulp - fst %st(1) - frndint - fst %st(2) - fsubrp - f2xm1 - fld1 - faddp - fscale - fstp %st(1) - ret - -1: fsts 4(%esp) - cmpl $0xff800000,4(%esp) - jnz 1f - fstp %st(0) - fldz -1: ret diff --git a/05/musl-final/src/math/i386/e_expf.s b/05/musl-final/src/math/i386/e_expf.s deleted file mode 100644 index 8b13789..0000000 --- a/05/musl-final/src/math/i386/e_expf.s +++ /dev/null @@ -1 +0,0 @@ - diff --git a/05/musl-final/src/math/i386/e_log.s b/05/musl-final/src/math/i386/e_log.s deleted file mode 100644 index 34b8d38..0000000 --- a/05/musl-final/src/math/i386/e_log.s +++ /dev/null @@ -1,6 +0,0 @@ -.global log -log: - fldln2 - fldl 4(%esp) - fyl2x - ret diff --git a/05/musl-final/src/math/i386/e_log10.s b/05/musl-final/src/math/i386/e_log10.s deleted file mode 100644 index 7f48941..0000000 --- a/05/musl-final/src/math/i386/e_log10.s +++ /dev/null @@ -1,6 +0,0 @@ -.global log10 -log10: - fldlg2 - fldl 4(%esp) - fyl2x - ret diff --git a/05/musl-final/src/math/i386/e_log10f.s b/05/musl-final/src/math/i386/e_log10f.s deleted file mode 100644 index 311486e..0000000 --- a/05/musl-final/src/math/i386/e_log10f.s +++ /dev/null @@ -1,6 +0,0 @@ -.global log10f -log10f: - fldlg2 - flds 4(%esp) - fyl2x - ret diff --git a/05/musl-final/src/math/i386/e_logf.s b/05/musl-final/src/math/i386/e_logf.s deleted file mode 100644 index b8beec0..0000000 --- a/05/musl-final/src/math/i386/e_logf.s +++ /dev/null @@ -1,6 +0,0 @@ -.global logf -logf: - fldln2 - flds 4(%esp) - fyl2x - ret diff --git a/05/musl-final/src/math/i386/e_remainder.s b/05/musl-final/src/math/i386/e_remainder.s deleted file mode 100644 index b7ff3ef..0000000 --- a/05/musl-final/src/math/i386/e_remainder.s +++ /dev/null @@ -1,16 +0,0 @@ -.global remainderf -remainderf: - flds 8(%esp) - flds 4(%esp) - jmp 1f - -.global remainder -remainder: - fldl 12(%esp) - fldl 4(%esp) -1: fprem1 - fstsw %ax - sahf - jp 1b - fstp %st(1) - ret diff --git a/05/musl-final/src/math/i386/e_remainderf.s b/05/musl-final/src/math/i386/e_remainderf.s deleted file mode 100644 index e69de29..0000000 diff --git a/05/musl-final/src/math/i386/e_sqrt.s b/05/musl-final/src/math/i386/e_sqrt.s deleted file mode 100644 index 11314dc..0000000 --- a/05/musl-final/src/math/i386/e_sqrt.s +++ /dev/null @@ -1,4 +0,0 @@ -.global sqrt -sqrt: fldl 4(%esp) - fsqrt - ret diff --git a/05/musl-final/src/math/i386/e_sqrtf.s b/05/musl-final/src/math/i386/e_sqrtf.s deleted file mode 100644 index 015e24c..0000000 --- a/05/musl-final/src/math/i386/e_sqrtf.s +++ /dev/null @@ -1,4 +0,0 @@ -.global sqrtf -sqrtf: flds 4(%esp) - fsqrt - ret diff --git a/05/musl-final/src/math/i386/s_ceil.s b/05/musl-final/src/math/i386/s_ceil.s deleted file mode 100644 index e69de29..0000000 diff --git a/05/musl-final/src/math/i386/s_ceilf.s b/05/musl-final/src/math/i386/s_ceilf.s deleted file mode 100644 index e69de29..0000000 diff --git a/05/musl-final/src/math/i386/s_fabs.s b/05/musl-final/src/math/i386/s_fabs.s deleted file mode 100644 index 10c70f3..0000000 --- a/05/musl-final/src/math/i386/s_fabs.s +++ /dev/null @@ -1,5 +0,0 @@ -.global fabs -fabs: - fldl 4(%esp) - fabs - ret diff --git a/05/musl-final/src/math/i386/s_fabsf.s b/05/musl-final/src/math/i386/s_fabsf.s deleted file mode 100644 index 4544269..0000000 --- a/05/musl-final/src/math/i386/s_fabsf.s +++ /dev/null @@ -1,5 +0,0 @@ -.global fabsf -fabsf: - flds 4(%esp) - fabs - ret diff --git a/05/musl-final/src/math/i386/s_floor.s b/05/musl-final/src/math/i386/s_floor.s deleted file mode 100644 index e69de29..0000000 diff --git a/05/musl-final/src/math/i386/s_floorf.s b/05/musl-final/src/math/i386/s_floorf.s deleted file mode 100644 index e69de29..0000000 diff --git a/05/musl-final/src/math/i386/s_ldexp.s b/05/musl-final/src/math/i386/s_ldexp.s deleted file mode 100644 index e69de29..0000000 diff --git a/05/musl-final/src/math/i386/s_ldexpf.s b/05/musl-final/src/math/i386/s_ldexpf.s deleted file mode 100644 index e69de29..0000000 diff --git a/05/musl-final/src/math/i386/s_rint.s b/05/musl-final/src/math/i386/s_rint.s deleted file mode 100644 index 5ba4ab4..0000000 --- a/05/musl-final/src/math/i386/s_rint.s +++ /dev/null @@ -1,5 +0,0 @@ -.global rint -rint: - fldl 4(%esp) - frndint - ret diff --git a/05/musl-final/src/math/i386/s_rintf.s b/05/musl-final/src/math/i386/s_rintf.s deleted file mode 100644 index d7aacd8..0000000 --- a/05/musl-final/src/math/i386/s_rintf.s +++ /dev/null @@ -1,5 +0,0 @@ -.global rintf -rintf: - flds 4(%esp) - frndint - ret diff --git a/05/musl-final/src/math/i386/s_scalbln.s b/05/musl-final/src/math/i386/s_scalbln.s deleted file mode 100644 index bd022b4..0000000 --- a/05/musl-final/src/math/i386/s_scalbln.s +++ /dev/null @@ -1,11 +0,0 @@ -.global ldexp -.global scalbn -.global scalbln -ldexp: -scalbn: -scalbln: - fildl 12(%esp) - fldl 4(%esp) - fscale - fstp %st(1) - ret diff --git a/05/musl-final/src/math/i386/s_scalblnf.s b/05/musl-final/src/math/i386/s_scalblnf.s deleted file mode 100644 index 379ec91..0000000 --- a/05/musl-final/src/math/i386/s_scalblnf.s +++ /dev/null @@ -1,11 +0,0 @@ -.global ldexpf -.global scalbnf -.global scalblnf -ldexpf: -scalbnf: -scalblnf: - fildl 8(%esp) - flds 4(%esp) - fscale - fstp %st(1) - ret diff --git a/05/musl-final/src/math/i386/s_trunc.s b/05/musl-final/src/math/i386/s_trunc.s deleted file mode 100644 index 0773891..0000000 --- a/05/musl-final/src/math/i386/s_trunc.s +++ /dev/null @@ -1,36 +0,0 @@ -.global ceilf -ceilf: flds 4(%esp) - jmp 1f - -.global ceil -ceil: fldl 4(%esp) -1: mov $0x08fb,%edx - jmp 0f - -.global floorf -floorf: flds 4(%esp) - jmp 1f - -.global floor -floor: fldl 4(%esp) -1: mov $0x04f7,%edx - jmp 0f - -.global truncf -truncf: flds 4(%esp) - jmp 1f - -.global trunc -trunc: fldl 4(%esp) -1: mov $0x0cff,%edx - -0: fstcw 4(%esp) - mov 5(%esp),%ah - or %dh,%ah - and %dl,%ah - xchg %ah,5(%esp) - fldcw 4(%esp) - frndint - mov %ah,5(%esp) - fldcw 4(%esp) - ret diff --git a/05/musl-final/src/math/i386/s_truncf.s b/05/musl-final/src/math/i386/s_truncf.s deleted file mode 100644 index e69de29..0000000 diff --git a/05/musl-final/src/math/k_cos.c b/05/musl-final/src/math/k_cos.c deleted file mode 100644 index 22e9841..0000000 --- a/05/musl-final/src/math/k_cos.c +++ /dev/null @@ -1,85 +0,0 @@ - -/* @(#)k_cos.c 1.3 95/01/18 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* - * __kernel_cos( x, y ) - * kernel cos function on [-pi/4, pi/4], pi/4 ~ 0.785398164 - * Input x is assumed to be bounded by ~pi/4 in magnitude. - * Input y is the tail of x. - * - * Algorithm - * 1. Since cos(-x) = cos(x), we need only to consider positive x. - * 2. if x < 2^-27 (hx<0x3e400000 0), return 1 with inexact if x!=0. - * 3. cos(x) is approximated by a polynomial of degree 14 on - * [0,pi/4] - * 4 14 - * cos(x) ~ 1 - x*x/2 + C1*x + ... + C6*x - * where the remez error is - * - * | 2 4 6 8 10 12 14 | -58 - * |cos(x)-(1-.5*x +C1*x +C2*x +C3*x +C4*x +C5*x +C6*x )| <= 2 - * | | - * - * 4 6 8 10 12 14 - * 4. let r = C1*x +C2*x +C3*x +C4*x +C5*x +C6*x , then - * cos(x) = 1 - x*x/2 + r - * since cos(x+y) ~ cos(x) - sin(x)*y - * ~ cos(x) - x*y, - * a correction term is necessary in cos(x) and hence - * cos(x+y) = 1 - (x*x/2 - (r - x*y)) - * For better accuracy when x > 0.3, let qx = |x|/4 with - * the last 32 bits mask off, and if x > 0.78125, let qx = 0.28125. - * Then - * cos(x+y) = (1-qx) - ((x*x/2-qx) - (r-x*y)). - * Note that 1-qx and (x*x/2-qx) is EXACT here, and the - * magnitude of the latter is at least a quarter of x*x/2, - * thus, reducing the rounding error in the subtraction. - */ - -#include -#include "math_private.h" - -static const double -one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */ -C1 = 4.16666666666666019037e-02, /* 0x3FA55555, 0x5555554C */ -C2 = -1.38888888888741095749e-03, /* 0xBF56C16C, 0x16C15177 */ -C3 = 2.48015872894767294178e-05, /* 0x3EFA01A0, 0x19CB1590 */ -C4 = -2.75573143513906633035e-07, /* 0xBE927E4F, 0x809C52AD */ -C5 = 2.08757232129817482790e-09, /* 0x3E21EE9E, 0xBDB4B1C4 */ -C6 = -1.13596475577881948265e-11; /* 0xBDA8FAE9, 0xBE8838D4 */ - -double -__kernel_cos(double x, double y) -{ - double a,hz,z,r,qx; - int32_t ix; - GET_HIGH_WORD(ix,x); - ix &= 0x7fffffff; /* ix = |x|'s high word*/ - if(ix<0x3e400000) { /* if x < 2**27 */ - if(((int)x)==0) return one; /* generate inexact */ - } - z = x*x; - r = z*(C1+z*(C2+z*(C3+z*(C4+z*(C5+z*C6))))); - if(ix < 0x3FD33333) /* if |x| < 0.3 */ - return one - (0.5*z - (z*r - x*y)); - else { - if(ix > 0x3fe90000) { /* x > 0.78125 */ - qx = 0.28125; - } else { - INSERT_WORDS(qx,ix-0x00200000,0); /* x/4 */ - } - hz = 0.5*z-qx; - a = one-qx; - return a - (hz - (z*r-x*y)); - } -} diff --git a/05/musl-final/src/math/k_cosf.c b/05/musl-final/src/math/k_cosf.c deleted file mode 100644 index 61dc374..0000000 --- a/05/musl-final/src/math/k_cosf.c +++ /dev/null @@ -1,52 +0,0 @@ -/* k_cosf.c -- float version of k_cos.c - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include -#include "math_private.h" - -static const float -one = 1.0000000000e+00, /* 0x3f800000 */ -C1 = 4.1666667908e-02, /* 0x3d2aaaab */ -C2 = -1.3888889225e-03, /* 0xbab60b61 */ -C3 = 2.4801587642e-05, /* 0x37d00d01 */ -C4 = -2.7557314297e-07, /* 0xb493f27c */ -C5 = 2.0875723372e-09, /* 0x310f74f6 */ -C6 = -1.1359647598e-11; /* 0xad47d74e */ - -float -__kernel_cosf(float x, float y) -{ - float a,hz,z,r,qx; - int32_t ix; - GET_FLOAT_WORD(ix,x); - ix &= 0x7fffffff; /* ix = |x|'s high word*/ - if(ix<0x32000000) { /* if x < 2**27 */ - if(((int)x)==0) return one; /* generate inexact */ - } - z = x*x; - r = z*(C1+z*(C2+z*(C3+z*(C4+z*(C5+z*C6))))); - if(ix < 0x3e99999a) /* if |x| < 0.3 */ - return one - ((float)0.5*z - (z*r - x*y)); - else { - if(ix > 0x3f480000) { /* x > 0.78125 */ - qx = (float)0.28125; - } else { - SET_FLOAT_WORD(qx,ix-0x01000000); /* x/4 */ - } - hz = (float)0.5*z-qx; - a = one-qx; - return a - (hz - (z*r-x*y)); - } -} diff --git a/05/musl-final/src/math/k_rem_pio2.c b/05/musl-final/src/math/k_rem_pio2.c deleted file mode 100644 index d993e4f..0000000 --- a/05/musl-final/src/math/k_rem_pio2.c +++ /dev/null @@ -1,300 +0,0 @@ - -/* @(#)k_rem_pio2.c 1.3 95/01/18 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* - * __kernel_rem_pio2(x,y,e0,nx,prec,ipio2) - * double x[],y[]; int e0,nx,prec; int ipio2[]; - * - * __kernel_rem_pio2 return the last three digits of N with - * y = x - N*pi/2 - * so that |y| < pi/2. - * - * The method is to compute the integer (mod 8) and fraction parts of - * (2/pi)*x without doing the full multiplication. In general we - * skip the part of the product that are known to be a huge integer ( - * more accurately, = 0 mod 8 ). Thus the number of operations are - * independent of the exponent of the input. - * - * (2/pi) is represented by an array of 24-bit integers in ipio2[]. - * - * Input parameters: - * x[] The input value (must be positive) is broken into nx - * pieces of 24-bit integers in double precision format. - * x[i] will be the i-th 24 bit of x. The scaled exponent - * of x[0] is given in input parameter e0 (i.e., x[0]*2^e0 - * match x's up to 24 bits. - * - * Example of breaking a double positive z into x[0]+x[1]+x[2]: - * e0 = ilogb(z)-23 - * z = scalbn(z,-e0) - * for i = 0,1,2 - * x[i] = floor(z) - * z = (z-x[i])*2**24 - * - * - * y[] ouput result in an array of double precision numbers. - * The dimension of y[] is: - * 24-bit precision 1 - * 53-bit precision 2 - * 64-bit precision 2 - * 113-bit precision 3 - * The actual value is the sum of them. Thus for 113-bit - * precison, one may have to do something like: - * - * long double t,w,r_head, r_tail; - * t = (long double)y[2] + (long double)y[1]; - * w = (long double)y[0]; - * r_head = t+w; - * r_tail = w - (r_head - t); - * - * e0 The exponent of x[0] - * - * nx dimension of x[] - * - * prec an integer indicating the precision: - * 0 24 bits (single) - * 1 53 bits (double) - * 2 64 bits (extended) - * 3 113 bits (quad) - * - * ipio2[] - * integer array, contains the (24*i)-th to (24*i+23)-th - * bit of 2/pi after binary point. The corresponding - * floating value is - * - * ipio2[i] * 2^(-24(i+1)). - * - * External function: - * double scalbn(), floor(); - * - * - * Here is the description of some local variables: - * - * jk jk+1 is the initial number of terms of ipio2[] needed - * in the computation. The recommended value is 2,3,4, - * 6 for single, double, extended,and quad. - * - * jz local integer variable indicating the number of - * terms of ipio2[] used. - * - * jx nx - 1 - * - * jv index for pointing to the suitable ipio2[] for the - * computation. In general, we want - * ( 2^e0*x[0] * ipio2[jv-1]*2^(-24jv) )/8 - * is an integer. Thus - * e0-3-24*jv >= 0 or (e0-3)/24 >= jv - * Hence jv = max(0,(e0-3)/24). - * - * jp jp+1 is the number of terms in PIo2[] needed, jp = jk. - * - * q[] double array with integral value, representing the - * 24-bits chunk of the product of x and 2/pi. - * - * q0 the corresponding exponent of q[0]. Note that the - * exponent for q[i] would be q0-24*i. - * - * PIo2[] double precision array, obtained by cutting pi/2 - * into 24 bits chunks. - * - * f[] ipio2[] in floating point - * - * iq[] integer array by breaking up q[] in 24-bits chunk. - * - * fq[] final product of x*(2/pi) in fq[0],..,fq[jk] - * - * ih integer. If >0 it indicates q[] is >= 0.5, hence - * it also indicates the *sign* of the result. - * - */ - - -/* - * Constants: - * The hexadecimal values are the intended ones for the following - * constants. The decimal values may be used, provided that the - * compiler will convert from decimal to binary accurately enough - * to produce the hexadecimal values shown. - */ - -#include -#include "math_private.h" - -static const int init_jk[] = {2,3,4,6}; /* initial value for jk */ - -static const double PIo2[] = { - 1.57079625129699707031e+00, /* 0x3FF921FB, 0x40000000 */ - 7.54978941586159635335e-08, /* 0x3E74442D, 0x00000000 */ - 5.39030252995776476554e-15, /* 0x3CF84698, 0x80000000 */ - 3.28200341580791294123e-22, /* 0x3B78CC51, 0x60000000 */ - 1.27065575308067607349e-29, /* 0x39F01B83, 0x80000000 */ - 1.22933308981111328932e-36, /* 0x387A2520, 0x40000000 */ - 2.73370053816464559624e-44, /* 0x36E38222, 0x80000000 */ - 2.16741683877804819444e-51, /* 0x3569F31D, 0x00000000 */ -}; - -static const double -zero = 0.0, -one = 1.0, -two24 = 1.67772160000000000000e+07, /* 0x41700000, 0x00000000 */ -twon24 = 5.96046447753906250000e-08; /* 0x3E700000, 0x00000000 */ - - int __kernel_rem_pio2(double *x, double *y, int e0, int nx, int prec, const int32_t *ipio2) -{ - int32_t jz,jx,jv,jp,jk,carry,n,iq[20],i,j,k,m,q0,ih; - double z,fw,f[20],fq[20],q[20]; - - /* initialize jk*/ - jk = init_jk[prec]; - jp = jk; - - /* determine jx,jv,q0, note that 3>q0 */ - jx = nx-1; - jv = (e0-3)/24; if(jv<0) jv=0; - q0 = e0-24*(jv+1); - - /* set up f[0] to f[jx+jk] where f[jx+jk] = ipio2[jv+jk] */ - j = jv-jx; m = jx+jk; - for(i=0;i<=m;i++,j++) f[i] = (j<0)? zero : (double) ipio2[j]; - - /* compute q[0],q[1],...q[jk] */ - for (i=0;i<=jk;i++) { - for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j]; q[i] = fw; - } - - jz = jk; -recompute: - /* distill q[] into iq[] reversingly */ - for(i=0,j=jz,z=q[jz];j>0;i++,j--) { - fw = (double)((int32_t)(twon24* z)); - iq[i] = (int32_t)(z-two24*fw); - z = q[j-1]+fw; - } - - /* compute n */ - z = scalbn(z,q0); /* actual value of z */ - z -= 8.0*floor(z*0.125); /* trim off integer >= 8 */ - n = (int32_t) z; - z -= (double)n; - ih = 0; - if(q0>0) { /* need iq[jz-1] to determine n */ - i = (iq[jz-1]>>(24-q0)); n += i; - iq[jz-1] -= i<<(24-q0); - ih = iq[jz-1]>>(23-q0); - } - else if(q0==0) ih = iq[jz-1]>>23; - else if(z>=0.5) ih=2; - - if(ih>0) { /* q > 0.5 */ - n += 1; carry = 0; - for(i=0;i0) { /* rare case: chance is 1 in 12 */ - switch(q0) { - case 1: - iq[jz-1] &= 0x7fffff; break; - case 2: - iq[jz-1] &= 0x3fffff; break; - } - } - if(ih==2) { - z = one - z; - if(carry!=0) z -= scalbn(one,q0); - } - } - - /* check if recomputation is needed */ - if(z==zero) { - j = 0; - for (i=jz-1;i>=jk;i--) j |= iq[i]; - if(j==0) { /* need recomputation */ - for(k=1;iq[jk-k]==0;k++); /* k = no. of terms needed */ - - for(i=jz+1;i<=jz+k;i++) { /* add q[jz+1] to q[jz+k] */ - f[jx+i] = (double) ipio2[jv+i]; - for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j]; - q[i] = fw; - } - jz += k; - goto recompute; - } - } - - /* chop off zero terms */ - if(z==0.0) { - jz -= 1; q0 -= 24; - while(iq[jz]==0) { jz--; q0-=24;} - } else { /* break z into 24-bit if necessary */ - z = scalbn(z,-q0); - if(z>=two24) { - fw = (double)((int32_t)(twon24*z)); - iq[jz] = (int32_t)(z-two24*fw); - jz += 1; q0 += 24; - iq[jz] = (int32_t) fw; - } else iq[jz] = (int32_t) z ; - } - - /* convert integer "bit" chunk to floating-point value */ - fw = scalbn(one,q0); - for(i=jz;i>=0;i--) { - q[i] = fw*(double)iq[i]; fw*=twon24; - } - - /* compute PIo2[0,...,jp]*q[jz,...,0] */ - for(i=jz;i>=0;i--) { - for(fw=0.0,k=0;k<=jp&&k<=jz-i;k++) fw += PIo2[k]*q[i+k]; - fq[jz-i] = fw; - } - - /* compress fq[] into y[] */ - switch(prec) { - case 0: - fw = 0.0; - for (i=jz;i>=0;i--) fw += fq[i]; - y[0] = (ih==0)? fw: -fw; - break; - case 1: - case 2: - fw = 0.0; - for (i=jz;i>=0;i--) fw += fq[i]; - y[0] = (ih==0)? fw: -fw; - fw = fq[0]-fw; - for (i=1;i<=jz;i++) fw += fq[i]; - y[1] = (ih==0)? fw: -fw; - break; - case 3: /* painful */ - for (i=jz;i>0;i--) { - fw = fq[i-1]+fq[i]; - fq[i] += fq[i-1]-fw; - fq[i-1] = fw; - } - for (i=jz;i>1;i--) { - fw = fq[i-1]+fq[i]; - fq[i] += fq[i-1]-fw; - fq[i-1] = fw; - } - for (fw=0.0,i=jz;i>=2;i--) fw += fq[i]; - if(ih==0) { - y[0] = fq[0]; y[1] = fq[1]; y[2] = fw; - } else { - y[0] = -fq[0]; y[1] = -fq[1]; y[2] = -fw; - } - } - return n&7; -} diff --git a/05/musl-final/src/math/k_rem_pio2f.c b/05/musl-final/src/math/k_rem_pio2f.c deleted file mode 100644 index b543f08..0000000 --- a/05/musl-final/src/math/k_rem_pio2f.c +++ /dev/null @@ -1,192 +0,0 @@ -/* k_rem_pio2f.c -- float version of k_rem_pio2.c - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include -#include "math_private.h" - -/* In the float version, the input parameter x contains 8 bit - integers, not 24 bit integers. 113 bit precision is not supported. */ - -static const int init_jk[] = {4,7,9}; /* initial value for jk */ - -static const float PIo2[] = { - 1.5703125000e+00, /* 0x3fc90000 */ - 4.5776367188e-04, /* 0x39f00000 */ - 2.5987625122e-05, /* 0x37da0000 */ - 7.5437128544e-08, /* 0x33a20000 */ - 6.0026650317e-11, /* 0x2e840000 */ - 7.3896444519e-13, /* 0x2b500000 */ - 5.3845816694e-15, /* 0x27c20000 */ - 5.6378512969e-18, /* 0x22d00000 */ - 8.3009228831e-20, /* 0x1fc40000 */ - 3.2756352257e-22, /* 0x1bc60000 */ - 6.3331015649e-25, /* 0x17440000 */ -}; - -static const float -zero = 0.0, -one = 1.0, -two8 = 2.5600000000e+02, /* 0x43800000 */ -twon8 = 3.9062500000e-03; /* 0x3b800000 */ - - int __kernel_rem_pio2f(float *x, float *y, int e0, int nx, int prec, const int32_t *ipio2) -{ - int32_t jz,jx,jv,jp,jk,carry,n,iq[20],i,j,k,m,q0,ih; - float z,fw,f[20],fq[20],q[20]; - - /* initialize jk*/ - jk = init_jk[prec]; - jp = jk; - - /* determine jx,jv,q0, note that 3>q0 */ - jx = nx-1; - jv = (e0-3)/8; if(jv<0) jv=0; - q0 = e0-8*(jv+1); - - /* set up f[0] to f[jx+jk] where f[jx+jk] = ipio2[jv+jk] */ - j = jv-jx; m = jx+jk; - for(i=0;i<=m;i++,j++) f[i] = (j<0)? zero : (float) ipio2[j]; - - /* compute q[0],q[1],...q[jk] */ - for (i=0;i<=jk;i++) { - for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j]; q[i] = fw; - } - - jz = jk; -recompute: - /* distill q[] into iq[] reversingly */ - for(i=0,j=jz,z=q[jz];j>0;i++,j--) { - fw = (float)((int32_t)(twon8* z)); - iq[i] = (int32_t)(z-two8*fw); - z = q[j-1]+fw; - } - - /* compute n */ - z = scalbnf(z,q0); /* actual value of z */ - z -= (float)8.0*floorf(z*(float)0.125); /* trim off integer >= 8 */ - n = (int32_t) z; - z -= (float)n; - ih = 0; - if(q0>0) { /* need iq[jz-1] to determine n */ - i = (iq[jz-1]>>(8-q0)); n += i; - iq[jz-1] -= i<<(8-q0); - ih = iq[jz-1]>>(7-q0); - } - else if(q0==0) ih = iq[jz-1]>>7; - else if(z>=(float)0.5) ih=2; - - if(ih>0) { /* q > 0.5 */ - n += 1; carry = 0; - for(i=0;i0) { /* rare case: chance is 1 in 12 */ - switch(q0) { - case 1: - iq[jz-1] &= 0x7f; break; - case 2: - iq[jz-1] &= 0x3f; break; - } - } - if(ih==2) { - z = one - z; - if(carry!=0) z -= scalbnf(one,q0); - } - } - - /* check if recomputation is needed */ - if(z==zero) { - j = 0; - for (i=jz-1;i>=jk;i--) j |= iq[i]; - if(j==0) { /* need recomputation */ - for(k=1;iq[jk-k]==0;k++); /* k = no. of terms needed */ - - for(i=jz+1;i<=jz+k;i++) { /* add q[jz+1] to q[jz+k] */ - f[jx+i] = (float) ipio2[jv+i]; - for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j]; - q[i] = fw; - } - jz += k; - goto recompute; - } - } - - /* chop off zero terms */ - if(z==(float)0.0) { - jz -= 1; q0 -= 8; - while(iq[jz]==0) { jz--; q0-=8;} - } else { /* break z into 8-bit if necessary */ - z = scalbnf(z,-q0); - if(z>=two8) { - fw = (float)((int32_t)(twon8*z)); - iq[jz] = (int32_t)(z-two8*fw); - jz += 1; q0 += 8; - iq[jz] = (int32_t) fw; - } else iq[jz] = (int32_t) z ; - } - - /* convert integer "bit" chunk to floating-point value */ - fw = scalbnf(one,q0); - for(i=jz;i>=0;i--) { - q[i] = fw*(float)iq[i]; fw*=twon8; - } - - /* compute PIo2[0,...,jp]*q[jz,...,0] */ - for(i=jz;i>=0;i--) { - for(fw=0.0,k=0;k<=jp&&k<=jz-i;k++) fw += PIo2[k]*q[i+k]; - fq[jz-i] = fw; - } - - /* compress fq[] into y[] */ - switch(prec) { - case 0: - fw = 0.0; - for (i=jz;i>=0;i--) fw += fq[i]; - y[0] = (ih==0)? fw: -fw; - break; - case 1: - case 2: - fw = 0.0; - for (i=jz;i>=0;i--) fw += fq[i]; - y[0] = (ih==0)? fw: -fw; - fw = fq[0]-fw; - for (i=1;i<=jz;i++) fw += fq[i]; - y[1] = (ih==0)? fw: -fw; - break; - case 3: /* painful */ - for (i=jz;i>0;i--) { - fw = fq[i-1]+fq[i]; - fq[i] += fq[i-1]-fw; - fq[i-1] = fw; - } - for (i=jz;i>1;i--) { - fw = fq[i-1]+fq[i]; - fq[i] += fq[i-1]-fw; - fq[i-1] = fw; - } - for (fw=0.0,i=jz;i>=2;i--) fw += fq[i]; - if(ih==0) { - y[0] = fq[0]; y[1] = fq[1]; y[2] = fw; - } else { - y[0] = -fq[0]; y[1] = -fq[1]; y[2] = -fw; - } - } - return n&7; -} diff --git a/05/musl-final/src/math/k_sin.c b/05/musl-final/src/math/k_sin.c deleted file mode 100644 index 9def258..0000000 --- a/05/musl-final/src/math/k_sin.c +++ /dev/null @@ -1,68 +0,0 @@ - -/* @(#)k_sin.c 1.3 95/01/18 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* __kernel_sin( x, y, iy) - * kernel sin function on [-pi/4, pi/4], pi/4 ~ 0.7854 - * Input x is assumed to be bounded by ~pi/4 in magnitude. - * Input y is the tail of x. - * Input iy indicates whether y is 0. (if iy=0, y assume to be 0). - * - * Algorithm - * 1. Since sin(-x) = -sin(x), we need only to consider positive x. - * 2. if x < 2^-27 (hx<0x3e400000 0), return x with inexact if x!=0. - * 3. sin(x) is approximated by a polynomial of degree 13 on - * [0,pi/4] - * 3 13 - * sin(x) ~ x + S1*x + ... + S6*x - * where - * - * |sin(x) 2 4 6 8 10 12 | -58 - * |----- - (1+S1*x +S2*x +S3*x +S4*x +S5*x +S6*x )| <= 2 - * | x | - * - * 4. sin(x+y) = sin(x) + sin'(x')*y - * ~ sin(x) + (1-x*x/2)*y - * For better accuracy, let - * 3 2 2 2 2 - * r = x *(S2+x *(S3+x *(S4+x *(S5+x *S6)))) - * then 3 2 - * sin(x) = x + (S1*x + (x *(r-y/2)+y)) - */ - -#include -#include "math_private.h" - -static const double -half = 5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */ -S1 = -1.66666666666666324348e-01, /* 0xBFC55555, 0x55555549 */ -S2 = 8.33333333332248946124e-03, /* 0x3F811111, 0x1110F8A6 */ -S3 = -1.98412698298579493134e-04, /* 0xBF2A01A0, 0x19C161D5 */ -S4 = 2.75573137070700676789e-06, /* 0x3EC71DE3, 0x57B1FE7D */ -S5 = -2.50507602534068634195e-08, /* 0xBE5AE5E6, 0x8A2B9CEB */ -S6 = 1.58969099521155010221e-10; /* 0x3DE5D93A, 0x5ACFD57C */ - -double -__kernel_sin(double x, double y, int iy) -{ - double z,r,v; - int32_t ix; - GET_HIGH_WORD(ix,x); - ix &= 0x7fffffff; /* high word of x */ - if(ix<0x3e400000) /* |x| < 2**-27 */ - {if((int)x==0) return x;} /* generate inexact */ - z = x*x; - v = z*x; - r = S2+z*(S3+z*(S4+z*(S5+z*S6))); - if(iy==0) return x+v*(S1+z*r); - else return x-((z*(half*y-v*r)-y)-v*S1); -} diff --git a/05/musl-final/src/math/k_sinf.c b/05/musl-final/src/math/k_sinf.c deleted file mode 100644 index 617f614..0000000 --- a/05/musl-final/src/math/k_sinf.c +++ /dev/null @@ -1,42 +0,0 @@ -/* k_sinf.c -- float version of k_sin.c - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include -#include "math_private.h" - -static const float -half = 5.0000000000e-01,/* 0x3f000000 */ -S1 = -1.6666667163e-01, /* 0xbe2aaaab */ -S2 = 8.3333337680e-03, /* 0x3c088889 */ -S3 = -1.9841270114e-04, /* 0xb9500d01 */ -S4 = 2.7557314297e-06, /* 0x3638ef1b */ -S5 = -2.5050759689e-08, /* 0xb2d72f34 */ -S6 = 1.5896910177e-10; /* 0x2f2ec9d3 */ - -float -__kernel_sinf(float x, float y, int iy) -{ - float z,r,v; - int32_t ix; - GET_FLOAT_WORD(ix,x); - ix &= 0x7fffffff; /* high word of x */ - if(ix<0x32000000) /* |x| < 2**-27 */ - {if((int)x==0) return x;} /* generate inexact */ - z = x*x; - v = z*x; - r = S2+z*(S3+z*(S4+z*(S5+z*S6))); - if(iy==0) return x+v*(S1+z*r); - else return x-((z*(half*y-v*r)-y)-v*S1); -} diff --git a/05/musl-final/src/math/k_tan.c b/05/musl-final/src/math/k_tan.c deleted file mode 100644 index f721ae6..0000000 --- a/05/musl-final/src/math/k_tan.c +++ /dev/null @@ -1,149 +0,0 @@ -/* @(#)k_tan.c 1.5 04/04/22 SMI */ - -/* - * ==================================================== - * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved. - * - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* __kernel_tan( x, y, k ) - * kernel tan function on [-pi/4, pi/4], pi/4 ~ 0.7854 - * Input x is assumed to be bounded by ~pi/4 in magnitude. - * Input y is the tail of x. - * Input k indicates whether tan (if k = 1) or -1/tan (if k = -1) is returned. - * - * Algorithm - * 1. Since tan(-x) = -tan(x), we need only to consider positive x. - * 2. if x < 2^-28 (hx<0x3e300000 0), return x with inexact if x!=0. - * 3. tan(x) is approximated by a odd polynomial of degree 27 on - * [0,0.67434] - * 3 27 - * tan(x) ~ x + T1*x + ... + T13*x - * where - * - * |tan(x) 2 4 26 | -59.2 - * |----- - (1+T1*x +T2*x +.... +T13*x )| <= 2 - * | x | - * - * Note: tan(x+y) = tan(x) + tan'(x)*y - * ~ tan(x) + (1+x*x)*y - * Therefore, for better accuracy in computing tan(x+y), let - * 3 2 2 2 2 - * r = x *(T2+x *(T3+x *(...+x *(T12+x *T13)))) - * then - * 3 2 - * tan(x+y) = x + (T1*x + (x *(r+y)+y)) - * - * 4. For x in [0.67434,pi/4], let y = pi/4 - x, then - * tan(x) = tan(pi/4-y) = (1-tan(y))/(1+tan(y)) - * = 1 - 2*(tan(y) - (tan(y)^2)/(1+tan(y))) - */ - -#include -#include "math_private.h" -static const double xxx[] = { - 3.33333333333334091986e-01, /* 3FD55555, 55555563 */ - 1.33333333333201242699e-01, /* 3FC11111, 1110FE7A */ - 5.39682539762260521377e-02, /* 3FABA1BA, 1BB341FE */ - 2.18694882948595424599e-02, /* 3F9664F4, 8406D637 */ - 8.86323982359930005737e-03, /* 3F8226E3, E96E8493 */ - 3.59207910759131235356e-03, /* 3F6D6D22, C9560328 */ - 1.45620945432529025516e-03, /* 3F57DBC8, FEE08315 */ - 5.88041240820264096874e-04, /* 3F4344D8, F2F26501 */ - 2.46463134818469906812e-04, /* 3F3026F7, 1A8D1068 */ - 7.81794442939557092300e-05, /* 3F147E88, A03792A6 */ - 7.14072491382608190305e-05, /* 3F12B80F, 32F0A7E9 */ - -1.85586374855275456654e-05, /* BEF375CB, DB605373 */ - 2.59073051863633712884e-05, /* 3EFB2A70, 74BF7AD4 */ -/* one */ 1.00000000000000000000e+00, /* 3FF00000, 00000000 */ -/* pio4 */ 7.85398163397448278999e-01, /* 3FE921FB, 54442D18 */ -/* pio4lo */ 3.06161699786838301793e-17 /* 3C81A626, 33145C07 */ -}; -#define one xxx[13] -#define pio4 xxx[14] -#define pio4lo xxx[15] -#define T xxx -/* INDENT ON */ - -double -__kernel_tan(double x, double y, int iy) { - double z, r, v, w, s; - int32_t ix, hx; - - GET_HIGH_WORD(hx,x); - ix = hx & 0x7fffffff; /* high word of |x| */ - if (ix < 0x3e300000) { /* x < 2**-28 */ - if ((int) x == 0) { /* generate inexact */ - uint32_t low; - GET_LOW_WORD(low,x); - if (((ix | low) | (iy + 1)) == 0) - return one / fabs(x); - else { - if (iy == 1) - return x; - else { /* compute -1 / (x+y) carefully */ - double a, t; - - z = w = x + y; - SET_LOW_WORD(z, 0); - v = y - (z - x); - t = a = -one / w; - SET_LOW_WORD(t, 0); - s = one + t * z; - return t + a * (s + t * v); - } - } - } - } - if (ix >= 0x3FE59428) { /* |x| >= 0.6744 */ - if (hx < 0) { - x = -x; - y = -y; - } - z = pio4 - x; - w = pio4lo - y; - x = z + w; - y = 0.0; - } - z = x * x; - w = z * z; - /* - * Break x^5*(T[1]+x^2*T[2]+...) into - * x^5(T[1]+x^4*T[3]+...+x^20*T[11]) + - * x^5(x^2*(T[2]+x^4*T[4]+...+x^22*[T12])) - */ - r = T[1] + w * (T[3] + w * (T[5] + w * (T[7] + w * (T[9] + - w * T[11])))); - v = z * (T[2] + w * (T[4] + w * (T[6] + w * (T[8] + w * (T[10] + - w * T[12]))))); - s = z * x; - r = y + z * (s * (r + v) + y); - r += T[0] * s; - w = x + r; - if (ix >= 0x3FE59428) { - v = (double) iy; - return (double) (1 - ((hx >> 30) & 2)) * - (v - 2.0 * (x - (w * w / (w + v) - r))); - } - if (iy == 1) - return w; - else { - /* - * if allow error up to 2 ulp, simply return - * -1.0 / (x+r) here - */ - /* compute -1.0 / (x+r) accurately */ - double a, t; - z = w; - SET_LOW_WORD(z,0); - v = r - (z - x); /* z+v = r+x */ - t = a = -1.0 / w; /* a = -1.0/w */ - SET_LOW_WORD(t,0); - s = 1.0 + t * z; - return t + a * (s + t * v); - } -} diff --git a/05/musl-final/src/math/k_tanf.c b/05/musl-final/src/math/k_tanf.c deleted file mode 100644 index 99ede58..0000000 --- a/05/musl-final/src/math/k_tanf.c +++ /dev/null @@ -1,105 +0,0 @@ -/* k_tanf.c -- float version of k_tan.c - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved. - * - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include -#include "math_private.h" -static const float -one = 1.0000000000e+00, /* 0x3f800000 */ -pio4 = 7.8539812565e-01, /* 0x3f490fda */ -pio4lo= 3.7748947079e-08, /* 0x33222168 */ -T[] = { - 3.3333334327e-01, /* 0x3eaaaaab */ - 1.3333334029e-01, /* 0x3e088889 */ - 5.3968254477e-02, /* 0x3d5d0dd1 */ - 2.1869488060e-02, /* 0x3cb327a4 */ - 8.8632395491e-03, /* 0x3c11371f */ - 3.5920790397e-03, /* 0x3b6b6916 */ - 1.4562094584e-03, /* 0x3abede48 */ - 5.8804126456e-04, /* 0x3a1a26c8 */ - 2.4646313977e-04, /* 0x398137b9 */ - 7.8179444245e-05, /* 0x38a3f445 */ - 7.1407252108e-05, /* 0x3895c07a */ - -1.8558637748e-05, /* 0xb79bae5f */ - 2.5907305826e-05, /* 0x37d95384 */ -}; - -float -__kernel_tanf(float x, float y, int iy) -{ - float z,r,v,w,s; - int32_t ix,hx; - GET_FLOAT_WORD(hx,x); - ix = hx&0x7fffffff; /* high word of |x| */ - if(ix<0x31800000) { /* x < 2**-28 */ - if ((int) x == 0) { /* generate inexact */ - if ((ix | (iy + 1)) == 0) - return one / fabsf(x); - else { - if (iy == 1) - return x; - else { /* compute -1 / (x+y) carefully */ - double a, t; - - z = w = x + y; - GET_FLOAT_WORD(ix, z); - SET_FLOAT_WORD(z, ix & 0xfffff000); - v = y - (z - x); - t = a = -one / w; - GET_FLOAT_WORD(ix, t); - SET_FLOAT_WORD(t, ix & 0xfffff000); - s = one + t * z; - return t + a * (s + t * v); - } - } - } - } - if(ix>=0x3f2ca140) { /* |x|>=0.6744 */ - if(hx<0) {x = -x; y = -y;} - z = pio4-x; - w = pio4lo-y; - x = z+w; y = 0.0; - } - z = x*x; - w = z*z; - /* Break x^5*(T[1]+x^2*T[2]+...) into - * x^5(T[1]+x^4*T[3]+...+x^20*T[11]) + - * x^5(x^2*(T[2]+x^4*T[4]+...+x^22*[T12])) - */ - r = T[1]+w*(T[3]+w*(T[5]+w*(T[7]+w*(T[9]+w*T[11])))); - v = z*(T[2]+w*(T[4]+w*(T[6]+w*(T[8]+w*(T[10]+w*T[12]))))); - s = z*x; - r = y + z*(s*(r+v)+y); - r += T[0]*s; - w = x+r; - if(ix>=0x3f2ca140) { - v = (float)iy; - return (float)(1-((hx>>30)&2))*(v-(float)2.0*(x-(w*w/(w+v)-r))); - } - if(iy==1) return w; - else { /* if allow error up to 2 ulp, - simply return -1.0/(x+r) here */ - /* compute -1.0/(x+r) accurately */ - float a,t; - int32_t i; - z = w; - GET_FLOAT_WORD(i,z); - SET_FLOAT_WORD(z,i&0xfffff000); - v = r-(z - x); /* z+v = r+x */ - t = a = -(float)1.0/w; /* a = -1.0/w */ - GET_FLOAT_WORD(i,t); - SET_FLOAT_WORD(t,i&0xfffff000); - s = (float)1.0+t*z; - return t+a*(s+t*v); - } -} diff --git a/05/musl-final/src/math/log.c b/05/musl-final/src/math/log.c deleted file mode 100644 index 71ad73d..0000000 --- a/05/musl-final/src/math/log.c +++ /dev/null @@ -1,142 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/e_log.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ -/* log(x) - * Return the logrithm of x - * - * Method : - * 1. Argument Reduction: find k and f such that - * x = 2^k * (1+f), - * where sqrt(2)/2 < 1+f < sqrt(2) . - * - * 2. Approximation of log(1+f). - * Let s = f/(2+f) ; based on log(1+f) = log(1+s) - log(1-s) - * = 2s + 2/3 s**3 + 2/5 s**5 + ....., - * = 2s + s*R - * We use a special Remez algorithm on [0,0.1716] to generate - * a polynomial of degree 14 to approximate R The maximum error - * of this polynomial approximation is bounded by 2**-58.45. In - * other words, - * 2 4 6 8 10 12 14 - * R(z) ~ Lg1*s +Lg2*s +Lg3*s +Lg4*s +Lg5*s +Lg6*s +Lg7*s - * (the values of Lg1 to Lg7 are listed in the program) - * and - * | 2 14 | -58.45 - * | Lg1*s +...+Lg7*s - R(z) | <= 2 - * | | - * Note that 2s = f - s*f = f - hfsq + s*hfsq, where hfsq = f*f/2. - * In order to guarantee error in log below 1ulp, we compute log - * by - * log(1+f) = f - s*(f - R) (if f is not too large) - * log(1+f) = f - (hfsq - s*(hfsq+R)). (better accuracy) - * - * 3. Finally, log(x) = k*ln2 + log(1+f). - * = k*ln2_hi+(f-(hfsq-(s*(hfsq+R)+k*ln2_lo))) - * Here ln2 is split into two floating point number: - * ln2_hi + ln2_lo, - * where n*ln2_hi is always exact for |n| < 2000. - * - * Special cases: - * log(x) is NaN with signal if x < 0 (including -INF) ; - * log(+INF) is +INF; log(0) is -INF with signal; - * log(NaN) is that NaN with no signal. - * - * Accuracy: - * according to an error analysis, the error is always less than - * 1 ulp (unit in the last place). - * - * Constants: - * The hexadecimal values are the intended ones for the following - * constants. The decimal values may be used, provided that the - * compiler will convert from decimal to binary accurately enough - * to produce the hexadecimal values shown. - */ - -#include "math_private.h" -#include "math.h" -#include - -static const double -ln2_hi = 6.93147180369123816490e-01, /* 3fe62e42 fee00000 */ -ln2_lo = 1.90821492927058770002e-10, /* 3dea39ef 35793c76 */ -two54 = 1.80143985094819840000e+16, /* 43500000 00000000 */ -Lg1 = 6.666666666666735130e-01, /* 3FE55555 55555593 */ -Lg2 = 3.999999999940941908e-01, /* 3FD99999 9997FA04 */ -Lg3 = 2.857142874366239149e-01, /* 3FD24924 94229359 */ -Lg4 = 2.222219843214978396e-01, /* 3FCC71C5 1D8E78AF */ -Lg5 = 1.818357216161805012e-01, /* 3FC74664 96CB03DE */ -Lg6 = 1.531383769920937332e-01, /* 3FC39A09 D078C69F */ -Lg7 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */ - -static const double zero = 0.0; - -double log(double x) -{ - double hfsq,f,s,z,R,w,t1,t2,dk; - int32_t k,hx,i,j; - uint32_t lx; - - EXTRACT_WORDS(hx, lx, x); - - k = 0; - if (hx < 0x00100000) { /* x < 2**-1022 */ - if (((hx&0x7fffffff)|lx) == 0) - return -two54/zero; /* log(+-0)=-inf */ - if (hx < 0) - return (x-x)/zero; /* log(-#) = NaN */ - /* subnormal number, scale up x */ - k -= 54; - x *= two54; - GET_HIGH_WORD(hx,x); - } - if (hx >= 0x7ff00000) - return x+x; - k += (hx>>20) - 1023; - hx &= 0x000fffff; - i = (hx+0x95f64)&0x100000; - SET_HIGH_WORD(x, hx|(i^0x3ff00000)); /* normalize x or x/2 */ - k += i>>20; - f = x - 1.0; - if ((0x000fffff&(2+hx)) < 3) { /* -2**-20 <= f < 2**-20 */ - if (f == zero) { - if (k == 0) { - return zero; - } - dk = (double)k; - return dk*ln2_hi + dk*ln2_lo; - } - R = f*f*(0.5-0.33333333333333333*f); - if (k == 0) - return f - R; - dk = (double)k; - return dk*ln2_hi - ((R-dk*ln2_lo)-f); - } - s = f/(2.0+f); - dk = (double)k; - z = s*s; - i = hx - 0x6147a; - w = z*z; - j = 0x6b851 - hx; - t1 = w*(Lg2+w*(Lg4+w*Lg6)); - t2 = z*(Lg1+w*(Lg3+w*(Lg5+w*Lg7))); - i |= j; - R = t2 + t1; - if (i > 0) { - hfsq = 0.5*f*f; - if (k == 0) - return f - (hfsq-s*(hfsq+R)); - return dk*ln2_hi - ((hfsq-(s*(hfsq+R)+dk*ln2_lo))-f); - } else { - if (k == 0) - return f - s*(f-R); - return dk*ln2_hi - ((s*(f-R)-dk*ln2_lo)-f); - } -} diff --git a/05/musl-final/src/math/log10.c b/05/musl-final/src/math/log10.c deleted file mode 100644 index fa2b1e3..0000000 --- a/05/musl-final/src/math/log10.c +++ /dev/null @@ -1,86 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/e_log10.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ -/* - * Return the base 10 logarithm of x. See e_log.c and k_log.h for most - * comments. - * - * log10(x) = (f - 0.5*f*f + k_log1p(f)) / ln10 + k * log10(2) - * in not-quite-routine extra precision. - */ - -#include "math_private.h" -#include "math.h" -#include "__log1p.h" -#include - -static const double -two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */ -ivln10hi = 4.34294481878168880939e-01, /* 0x3fdbcb7b, 0x15200000 */ -ivln10lo = 2.50829467116452752298e-11, /* 0x3dbb9438, 0xca9aadd5 */ -log10_2hi = 3.01029995663611771306e-01, /* 0x3FD34413, 0x509F6000 */ -log10_2lo = 3.69423907715893078616e-13; /* 0x3D59FEF3, 0x11F12B36 */ - -static const double zero = 0.0; - -double log10(double x) -{ - double f,hfsq,hi,lo,r,val_hi,val_lo,w,y,y2; - int32_t i,k,hx; - uint32_t lx; - - EXTRACT_WORDS(hx, lx, x); - - k = 0; - if (hx < 0x00100000) { /* x < 2**-1022 */ - if (((hx&0x7fffffff)|lx) == 0) - return -two54/zero; /* log(+-0)=-inf */ - if (hx<0) - return (x-x)/zero; /* log(-#) = NaN */ - /* subnormal number, scale up x */ - k -= 54; - x *= two54; - GET_HIGH_WORD(hx, x); - } - if (hx >= 0x7ff00000) - return x+x; - if (hx == 0x3ff00000 && lx == 0) - return zero; /* log(1) = +0 */ - k += (hx>>20) - 1023; - hx &= 0x000fffff; - i = (hx+0x95f64)&0x100000; - SET_HIGH_WORD(x, hx|(i^0x3ff00000)); /* normalize x or x/2 */ - k += i>>20; - y = (double)k; - f = x - 1.0; - hfsq = 0.5*f*f; - r = __log1p(f); - - /* See log2.c for details. */ - hi = f - hfsq; - SET_LOW_WORD(hi, 0); - lo = (f - hi) - hfsq + r; - val_hi = hi*ivln10hi; - y2 = y*log10_2hi; - val_lo = y*log10_2lo + (lo+hi)*ivln10lo + lo*ivln10hi; - - /* - * Extra precision in for adding y*log10_2hi is not strictly needed - * since there is no very large cancellation near x = sqrt(2) or - * x = 1/sqrt(2), but we do it anyway since it costs little on CPUs - * with some parallelism and it reduces the error for many args. - */ - w = y2 + val_hi; - val_lo += (y2 - w) + val_hi; - val_hi = w; - - return val_lo + val_hi; -} diff --git a/05/musl-final/src/math/log10f.c b/05/musl-final/src/math/log10f.c deleted file mode 100644 index 804359f..0000000 --- a/05/musl-final/src/math/log10f.c +++ /dev/null @@ -1,72 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/e_log10f.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ -/* - * See comments in log10.c. - */ - -#include "math.h" -#include "__log1pf.h" -#include - -static const float -two25 = 3.3554432000e+07, /* 0x4c000000 */ -ivln10hi = 4.3432617188e-01, /* 0x3ede6000 */ -ivln10lo = -3.1689971365e-05, /* 0xb804ead9 */ -log10_2hi = 3.0102920532e-01, /* 0x3e9a2080 */ -log10_2lo = 7.9034151668e-07; /* 0x355427db */ - -static const float zero = 0.0; - -float log10f(float x) -{ - float f,hfsq,hi,lo,r,y; - int32_t i,k,hx; - - GET_FLOAT_WORD(hx, x); - - k = 0; - if (hx < 0x00800000) { /* x < 2**-126 */ - if ((hx&0x7fffffff) == 0) - return -two25/zero; /* log(+-0)=-inf */ - if (hx < 0) - return (x-x)/zero; /* log(-#) = NaN */ - /* subnormal number, scale up x */ - k -= 25; - x *= two25; - GET_FLOAT_WORD(hx, x); - } - if (hx >= 0x7f800000) - return x+x; - if (hx == 0x3f800000) - return zero; /* log(1) = +0 */ - k += (hx>>23) - 127; - hx &= 0x007fffff; - i = (hx+(0x4afb0d))&0x800000; - SET_FLOAT_WORD(x, hx|(i^0x3f800000)); /* normalize x or x/2 */ - k += i>>23; - y = (float)k; - f = x - 1.0f; - hfsq = 0.5f * f * f; - r = __log1pf(f); - -// FIXME -// /* See log2f.c and log2.c for details. */ -// if (sizeof(float_t) > sizeof(float)) -// return (r - hfsq + f) * ((float_t)ivln10lo + ivln10hi) + -// y * ((float_t)log10_2lo + log10_2hi); - hi = f - hfsq; - GET_FLOAT_WORD(hx, hi); - SET_FLOAT_WORD(hi, hx&0xfffff000); - lo = (f - hi) - hfsq + r; - return y*log10_2lo + (lo+hi)*ivln10lo + lo*ivln10hi + - hi*ivln10hi + y*log10_2hi; -} diff --git a/05/musl-final/src/math/log10l.c b/05/musl-final/src/math/log10l.c deleted file mode 100644 index a378fbb..0000000 --- a/05/musl-final/src/math/log10l.c +++ /dev/null @@ -1,186 +0,0 @@ -/* origin: OpenBSD /usr/src/lib/libm/src/ld80/e_log10l.c */ -/* - * Copyright (c) 2008 Stephen L. Moshier - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ -/* - * Common logarithm, long double precision - * - * - * SYNOPSIS: - * - * long double x, y, log10l(); - * - * y = log10l( x ); - * - * - * DESCRIPTION: - * - * Returns the base 10 logarithm of x. - * - * The argument is separated into its exponent and fractional - * parts. If the exponent is between -1 and +1, the logarithm - * of the fraction is approximated by - * - * log(1+x) = x - 0.5 x**2 + x**3 P(x)/Q(x). - * - * Otherwise, setting z = 2(x-1)/x+1), - * - * log(x) = z + z**3 P(z)/Q(z). - * - * - * ACCURACY: - * - * Relative error: - * arithmetic domain # trials peak rms - * IEEE 0.5, 2.0 30000 9.0e-20 2.6e-20 - * IEEE exp(+-10000) 30000 6.0e-20 2.3e-20 - * - * In the tests over the interval exp(+-10000), the logarithms - * of the random arguments were uniformly distributed over - * [-10000, +10000]. - * - * ERROR MESSAGES: - * - * log singularity: x = 0; returns MINLOG - * log domain: x < 0; returns MINLOG - */ - -#include "math.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double log10l(long double x) -{ - return log10(x); -} -#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 -/* Coefficients for log(1+x) = x - x**2/2 + x**3 P(x)/Q(x) - * 1/sqrt(2) <= x < sqrt(2) - * Theoretical peak relative error = 6.2e-22 - */ -static long double P[] = { - 4.9962495940332550844739E-1L, - 1.0767376367209449010438E1L, - 7.7671073698359539859595E1L, - 2.5620629828144409632571E2L, - 4.2401812743503691187826E2L, - 3.4258224542413922935104E2L, - 1.0747524399916215149070E2L, -}; -static long double Q[] = { -/* 1.0000000000000000000000E0,*/ - 2.3479774160285863271658E1L, - 1.9444210022760132894510E2L, - 7.7952888181207260646090E2L, - 1.6911722418503949084863E3L, - 2.0307734695595183428202E3L, - 1.2695660352705325274404E3L, - 3.2242573199748645407652E2L, -}; - -/* Coefficients for log(x) = z + z^3 P(z^2)/Q(z^2), - * where z = 2(x-1)/(x+1) - * 1/sqrt(2) <= x < sqrt(2) - * Theoretical peak relative error = 6.16e-22 - */ -static long double R[4] = { - 1.9757429581415468984296E-3L, --7.1990767473014147232598E-1L, - 1.0777257190312272158094E1L, --3.5717684488096787370998E1L, -}; -static long double S[4] = { -/* 1.00000000000000000000E0L,*/ --2.6201045551331104417768E1L, - 1.9361891836232102174846E2L, --4.2861221385716144629696E2L, -}; -/* log10(2) */ -#define L102A 0.3125L -#define L102B -1.1470004336018804786261e-2L -/* log10(e) */ -#define L10EA 0.5L -#define L10EB -6.5705518096748172348871e-2L - -#define SQRTH 0.70710678118654752440L - -long double log10l(long double x) -{ - long double y; - volatile long double z; - int e; - - if (isnan(x)) - return x; - if(x <= 0.0L) { - if(x == 0.0L) - return -1.0L / (x - x); - return (x - x) / (x - x); - } - if (x == INFINITY) - return INFINITY; - /* separate mantissa from exponent */ - /* Note, frexp is used so that denormal numbers - * will be handled properly. - */ - x = frexpl(x, &e); - - /* logarithm using log(x) = z + z**3 P(z)/Q(z), - * where z = 2(x-1)/x+1) - */ - if (e > 2 || e < -2) { - if (x < SQRTH) { /* 2(2x-1)/(2x+1) */ - e -= 1; - z = x - 0.5L; - y = 0.5L * z + 0.5L; - } else { /* 2 (x-1)/(x+1) */ - z = x - 0.5L; - z -= 0.5L; - y = 0.5L * x + 0.5L; - } - x = z / y; - z = x*x; - y = x * (z * __polevll(z, R, 3) / __p1evll(z, S, 3)); - goto done; - } - - /* logarithm using log(1+x) = x - .5x**2 + x**3 P(x)/Q(x) */ - if (x < SQRTH) { - e -= 1; - x = ldexpl(x, 1) - 1.0L; /* 2x - 1 */ - } else { - x = x - 1.0L; - } - z = x*x; - y = x * (z * __polevll(x, P, 6) / __p1evll(x, Q, 7)); - y = y - ldexpl(z, -1); /* -0.5x^2 + ... */ - -done: - /* Multiply log of fraction by log10(e) - * and base 2 exponent by log10(2). - * - * ***CAUTION*** - * - * This sequence of operations is critical and it may - * be horribly defeated by some compiler optimizers. - */ - z = y * (L10EB); - z += x * (L10EB); - z += e * (L102B); - z += y * (L10EA); - z += x * (L10EA); - z += e * (L102A); - return z; -} -#endif diff --git a/05/musl-final/src/math/log1p.c b/05/musl-final/src/math/log1p.c deleted file mode 100644 index 8f22e87..0000000 --- a/05/musl-final/src/math/log1p.c +++ /dev/null @@ -1,172 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/s_log1p.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ -/* double log1p(double x) - * - * Method : - * 1. Argument Reduction: find k and f such that - * 1+x = 2^k * (1+f), - * where sqrt(2)/2 < 1+f < sqrt(2) . - * - * Note. If k=0, then f=x is exact. However, if k!=0, then f - * may not be representable exactly. In that case, a correction - * term is need. Let u=1+x rounded. Let c = (1+x)-u, then - * log(1+x) - log(u) ~ c/u. Thus, we proceed to compute log(u), - * and add back the correction term c/u. - * (Note: when x > 2**53, one can simply return log(x)) - * - * 2. Approximation of log1p(f). - * Let s = f/(2+f) ; based on log(1+f) = log(1+s) - log(1-s) - * = 2s + 2/3 s**3 + 2/5 s**5 + ....., - * = 2s + s*R - * We use a special Reme algorithm on [0,0.1716] to generate - * a polynomial of degree 14 to approximate R The maximum error - * of this polynomial approximation is bounded by 2**-58.45. In - * other words, - * 2 4 6 8 10 12 14 - * R(z) ~ Lp1*s +Lp2*s +Lp3*s +Lp4*s +Lp5*s +Lp6*s +Lp7*s - * (the values of Lp1 to Lp7 are listed in the program) - * and - * | 2 14 | -58.45 - * | Lp1*s +...+Lp7*s - R(z) | <= 2 - * | | - * Note that 2s = f - s*f = f - hfsq + s*hfsq, where hfsq = f*f/2. - * In order to guarantee error in log below 1ulp, we compute log - * by - * log1p(f) = f - (hfsq - s*(hfsq+R)). - * - * 3. Finally, log1p(x) = k*ln2 + log1p(f). - * = k*ln2_hi+(f-(hfsq-(s*(hfsq+R)+k*ln2_lo))) - * Here ln2 is split into two floating point number: - * ln2_hi + ln2_lo, - * where n*ln2_hi is always exact for |n| < 2000. - * - * Special cases: - * log1p(x) is NaN with signal if x < -1 (including -INF) ; - * log1p(+INF) is +INF; log1p(-1) is -INF with signal; - * log1p(NaN) is that NaN with no signal. - * - * Accuracy: - * according to an error analysis, the error is always less than - * 1 ulp (unit in the last place). - * - * Constants: - * The hexadecimal values are the intended ones for the following - * constants. The decimal values may be used, provided that the - * compiler will convert from decimal to binary accurately enough - * to produce the hexadecimal values shown. - * - * Note: Assuming log() return accurate answer, the following - * algorithm can be used to compute log1p(x) to within a few ULP: - * - * u = 1+x; - * if(u==1.0) return x ; else - * return log(u)*(x/(u-1.0)); - * - * See HP-15C Advanced Functions Handbook, p.193. - */ - -#include "math.h" -#include - -static const double -ln2_hi = 6.93147180369123816490e-01, /* 3fe62e42 fee00000 */ -ln2_lo = 1.90821492927058770002e-10, /* 3dea39ef 35793c76 */ -two54 = 1.80143985094819840000e+16, /* 43500000 00000000 */ -Lp1 = 6.666666666666735130e-01, /* 3FE55555 55555593 */ -Lp2 = 3.999999999940941908e-01, /* 3FD99999 9997FA04 */ -Lp3 = 2.857142874366239149e-01, /* 3FD24924 94229359 */ -Lp4 = 2.222219843214978396e-01, /* 3FCC71C5 1D8E78AF */ -Lp5 = 1.818357216161805012e-01, /* 3FC74664 96CB03DE */ -Lp6 = 1.531383769920937332e-01, /* 3FC39A09 D078C69F */ -Lp7 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */ - -static const double zero = 0.0; - -// double log1p(double x) -// { -// double hfsq,f,c,s,z,R,u; -// int32_t k,hx,hu,ax; - -// GET_HIGH_WORD(hx, x); -// ax = hx & 0x7fffffff; - -// k = 1; -// if (hx < 0x3FDA827A) { /* 1+x < sqrt(2)+ */ -// if (ax >= 0x3ff00000) { /* x <= -1.0 */ -// if (x == -1.0) -// return -two54/zero; /* log1p(-1)=+inf */ -// return (x-x)/(x-x); /* log1p(x<-1)=NaN */ -// } -// if (ax < 0x3e200000) { /* |x| < 2**-29 */ -// /* raise inexact */ -// if (two54 + x > zero && ax < 0x3c900000) /* |x| < 2**-54 */ -// return x; -// return x - x*x*0.5; -// } -// if (hx > 0 || hx <= (int32_t)0xbfd2bec4) { /* sqrt(2)/2- <= 1+x < sqrt(2)+ */ -// k = 0; -// f = x; -// hu = 1; -// } -// } -// if (hx >= 0x7ff00000) -// return x+x; -// if (k != 0) { -// if (hx < 0x43400000) { -// STRICT_ASSIGN(double, u, 1.0 + x); -// GET_HIGH_WORD(hu, u); -// k = (hu>>20) - 1023; -// c = k > 0 ? 1.0-(u-x) : x-(u-1.0); /* correction term */ -// c /= u; -// } else { -// u = x; -// GET_HIGH_WORD(hu,u); -// k = (hu>>20) - 1023; -// c = 0; -// } -// hu &= 0x000fffff; -// /* -// * The approximation to sqrt(2) used in thresholds is not -// * critical. However, the ones used above must give less -// * strict bounds than the one here so that the k==0 case is -// * never reached from here, since here we have committed to -// * using the correction term but don't use it if k==0. -// */ -// if (hu < 0x6a09e) { /* u ~< sqrt(2) */ -// SET_HIGH_WORD(u, hu|0x3ff00000); /* normalize u */ -// } else { -// k += 1; -// SET_HIGH_WORD(u, hu|0x3fe00000); /* normalize u/2 */ -// hu = (0x00100000-hu)>>2; -// } -// f = u - 1.0; -// } -// hfsq = 0.5*f*f; -// if (hu == 0) { /* |f| < 2**-20 */ -// if (f == zero) { -// if(k == 0) -// return zero; -// c += k*ln2_lo; -// return k*ln2_hi + c; -// } -// R = hfsq*(1.0 - 0.66666666666666666*f); -// if (k == 0) -// return f - R; -// return k*ln2_hi - ((R-(k*ln2_lo+c))-f); -// } -// s = f/(2.0+f); -// z = s*s; -// R = z*(Lp1+z*(Lp2+z*(Lp3+z*(Lp4+z*(Lp5+z*(Lp6+z*Lp7)))))); -// if (k == 0) -// return f - (hfsq-s*(hfsq+R)); -// return k*ln2_hi - ((hfsq-(s*(hfsq+R)+(k*ln2_lo+c)))-f); -// } diff --git a/05/musl-final/src/math/log1pf.c b/05/musl-final/src/math/log1pf.c deleted file mode 100644 index d746e67..0000000 --- a/05/musl-final/src/math/log1pf.c +++ /dev/null @@ -1,112 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/s_log1pf.c */ -/* - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include "math.h" -#include - -static const float -ln2_hi = 6.9313812256e-01, /* 0x3f317180 */ -ln2_lo = 9.0580006145e-06, /* 0x3717f7d1 */ -two25 = 3.355443200e+07, /* 0x4c000000 */ -Lp1 = 6.6666668653e-01, /* 3F2AAAAB */ -Lp2 = 4.0000000596e-01, /* 3ECCCCCD */ -Lp3 = 2.8571429849e-01, /* 3E924925 */ -Lp4 = 2.2222198546e-01, /* 3E638E29 */ -Lp5 = 1.8183572590e-01, /* 3E3A3325 */ -Lp6 = 1.5313838422e-01, /* 3E1CD04F */ -Lp7 = 1.4798198640e-01; /* 3E178897 */ - -static const float zero = 0.0; - -// float log1pf(float x) -// { -// float hfsq,f,c,s,z,R,u; -// int32_t k,hx,hu,ax; - -// GET_FLOAT_WORD(hx, x); -// ax = hx & 0x7fffffff; - -// k = 1; -// if (hx < 0x3ed413d0) { /* 1+x < sqrt(2)+ */ -// if (ax >= 0x3f800000) { /* x <= -1.0 */ -// if (x == -1.0f) -// return -two25/zero; /* log1p(-1)=+inf */ -// return (x-x)/(x-x); /* log1p(x<-1)=NaN */ -// } -// if (ax < 0x38000000) { /* |x| < 2**-15 */ -// /* raise inexact */ -// if (two25 + x > zero && ax < 0x33800000) /* |x| < 2**-24 */ -// return x; -// return x - x*x*0.5f; -// } -// if (hx > 0 || hx <= (int32_t)0xbe95f619) { /* sqrt(2)/2- <= 1+x < sqrt(2)+ */ -// k = 0; -// f = x; -// hu = 1; -// } -// } -// if (hx >= 0x7f800000) -// return x+x; -// if (k != 0) { -// if (hx < 0x5a000000) { -// STRICT_ASSIGN(float, u, 1.0f + x); -// GET_FLOAT_WORD(hu, u); -// k = (hu>>23) - 127; -// /* correction term */ -// c = k > 0 ? 1.0f-(u-x) : x-(u-1.0f); -// c /= u; -// } else { -// u = x; -// GET_FLOAT_WORD(hu,u); -// k = (hu>>23) - 127; -// c = 0; -// } -// hu &= 0x007fffff; -// /* -// * The approximation to sqrt(2) used in thresholds is not -// * critical. However, the ones used above must give less -// * strict bounds than the one here so that the k==0 case is -// * never reached from here, since here we have committed to -// * using the correction term but don't use it if k==0. -// */ -// if (hu < 0x3504f4) { /* u < sqrt(2) */ -// SET_FLOAT_WORD(u, hu|0x3f800000); /* normalize u */ -// } else { -// k += 1; -// SET_FLOAT_WORD(u, hu|0x3f000000); /* normalize u/2 */ -// hu = (0x00800000-hu)>>2; -// } -// f = u - 1.0f; -// } -// hfsq = 0.5f * f * f; -// if (hu == 0) { /* |f| < 2**-20 */ -// if (f == zero) { -// if (k == 0) -// return zero; -// c += k*ln2_lo; -// return k*ln2_hi+c; -// } -// R = hfsq*(1.0f - 0.66666666666666666f * f); -// if (k == 0) -// return f - R; -// return k*ln2_hi - ((R-(k*ln2_lo+c))-f); -// } -// s = f/(2.0f + f); -// z = s*s; -// R = z*(Lp1+z*(Lp2+z*(Lp3+z*(Lp4+z*(Lp5+z*(Lp6+z*Lp7)))))); -// if (k == 0) -// return f - (hfsq-s*(hfsq+R)); -// return k*ln2_hi - ((hfsq-(s*(hfsq+R)+(k*ln2_lo+c)))-f); -// } diff --git a/05/musl-final/src/math/log1pl.c b/05/musl-final/src/math/log1pl.c deleted file mode 100644 index 2eda3a6..0000000 --- a/05/musl-final/src/math/log1pl.c +++ /dev/null @@ -1,176 +0,0 @@ -/* origin: OpenBSD /usr/src/lib/libm/src/ld80/s_log1pl.c */ -/* - * Copyright (c) 2008 Stephen L. Moshier - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ -/* - * Relative error logarithm - * Natural logarithm of 1+x, long double precision - * - * - * SYNOPSIS: - * - * long double x, y, log1pl(); - * - * y = log1pl( x ); - * - * - * DESCRIPTION: - * - * Returns the base e (2.718...) logarithm of 1+x. - * - * The argument 1+x is separated into its exponent and fractional - * parts. If the exponent is between -1 and +1, the logarithm - * of the fraction is approximated by - * - * log(1+x) = x - 0.5 x^2 + x^3 P(x)/Q(x). - * - * Otherwise, setting z = 2(x-1)/x+1), - * - * log(x) = z + z^3 P(z)/Q(z). - * - * - * ACCURACY: - * - * Relative error: - * arithmetic domain # trials peak rms - * IEEE -1.0, 9.0 100000 8.2e-20 2.5e-20 - * - * ERROR MESSAGES: - * - * log singularity: x-1 = 0; returns -INFINITY - * log domain: x-1 < 0; returns NAN - */ - -#include "math.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double log1pl(long double x) -{ - return log1p(x); -} -#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 -/* Coefficients for log(1+x) = x - x^2 / 2 + x^3 P(x)/Q(x) - * 1/sqrt(2) <= x < sqrt(2) - * Theoretical peak relative error = 2.32e-20 - */ -static long double P[] = { - 4.5270000862445199635215E-5L, - 4.9854102823193375972212E-1L, - 6.5787325942061044846969E0L, - 2.9911919328553073277375E1L, - 6.0949667980987787057556E1L, - 5.7112963590585538103336E1L, - 2.0039553499201281259648E1L, -}; -static long double Q[] = { -/* 1.0000000000000000000000E0,*/ - 1.5062909083469192043167E1L, - 8.3047565967967209469434E1L, - 2.2176239823732856465394E2L, - 3.0909872225312059774938E2L, - 2.1642788614495947685003E2L, - 6.0118660497603843919306E1L, -}; - -/* Coefficients for log(x) = z + z^3 P(z^2)/Q(z^2), - * where z = 2(x-1)/(x+1) - * 1/sqrt(2) <= x < sqrt(2) - * Theoretical peak relative error = 6.16e-22 - */ -static long double R[4] = { - 1.9757429581415468984296E-3L, --7.1990767473014147232598E-1L, - 1.0777257190312272158094E1L, --3.5717684488096787370998E1L, -}; -static long double S[4] = { -/* 1.00000000000000000000E0L,*/ --2.6201045551331104417768E1L, - 1.9361891836232102174846E2L, --4.2861221385716144629696E2L, -}; -static const long double C1 = 6.9314575195312500000000E-1L; -static const long double C2 = 1.4286068203094172321215E-6L; - -#define SQRTH 0.70710678118654752440L - -long double log1pl(long double xm1) -{ - long double x, y, z; - int e; - - if (isnan(xm1)) - return xm1; - if (xm1 == INFINITY) - return xm1; - if (xm1 == 0.0) - return xm1; - - x = xm1 + 1.0L; - - /* Test for domain errors. */ - if (x <= 0.0L) { - if (x == 0.0L) - return -INFINITY; - return NAN; - } - - /* Separate mantissa from exponent. - Use frexp so that denormal numbers will be handled properly. */ - x = frexpl(x, &e); - - /* logarithm using log(x) = z + z^3 P(z)/Q(z), - where z = 2(x-1)/x+1) */ - if (e > 2 || e < -2) { - if (x < SQRTH) { /* 2(2x-1)/(2x+1) */ - e -= 1; - z = x - 0.5L; - y = 0.5L * z + 0.5L; - } else { /* 2 (x-1)/(x+1) */ - z = x - 0.5L; - z -= 0.5L; - y = 0.5L * x + 0.5L; - } - x = z / y; - z = x*x; - z = x * (z * __polevll(z, R, 3) / __p1evll(z, S, 3)); - z = z + e * C2; - z = z + x; - z = z + e * C1; - return z; - } - - /* logarithm using log(1+x) = x - .5x**2 + x**3 P(x)/Q(x) */ - if (x < SQRTH) { - e -= 1; - if (e != 0) - x = 2.0 * x - 1.0L; - else - x = xm1; - } else { - if (e != 0) - x = x - 1.0L; - else - x = xm1; - } - z = x*x; - y = x * (z * __polevll(x, P, 6) / __p1evll(x, Q, 6)); - y = y + e * C2; - z = y - 0.5 * z; - z = z + x; - z = z + e * C1; - return z; -} -#endif diff --git a/05/musl-final/src/math/log2.c b/05/musl-final/src/math/log2.c deleted file mode 100644 index 21290d2..0000000 --- a/05/musl-final/src/math/log2.c +++ /dev/null @@ -1,109 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/e_log2.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ -/* - * Return the base 2 logarithm of x. See log.c and __log1p.h for most - * comments. - * - * This reduces x to {k, 1+f} exactly as in e_log.c, then calls the kernel, - * then does the combining and scaling steps - * log2(x) = (f - 0.5*f*f + k_log1p(f)) / ln2 + k - * in not-quite-routine extra precision. - */ - -#include "math_private.h" -#include "math.h" -#include "__log1p.h" -#include - -static const double -two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */ -ivln2hi = 1.44269504072144627571e+00, /* 0x3ff71547, 0x65200000 */ -ivln2lo = 1.67517131648865118353e-10; /* 0x3de705fc, 0x2eefa200 */ - -static const double zero = 0.0; - -double log2(double x) -{ - double f,hfsq,hi,lo,r,val_hi,val_lo,w,y; - int32_t i,k,hx; - uint32_t lx; - - EXTRACT_WORDS(hx, lx, x); - - k = 0; - if (hx < 0x00100000) { /* x < 2**-1022 */ - if (((hx&0x7fffffff)|lx) == 0) - return -two54/zero; /* log(+-0)=-inf */ - if (hx < 0) - return (x-x)/zero; /* log(-#) = NaN */ - /* subnormal number, scale up x */ - k -= 54; - x *= two54; - GET_HIGH_WORD(hx, x); - } - if (hx >= 0x7ff00000) - return x+x; - if (hx == 0x3ff00000 && lx == 0) - return zero; /* log(1) = +0 */ - k += (hx>>20) - 1023; - hx &= 0x000fffff; - i = (hx+0x95f64) & 0x100000; - SET_HIGH_WORD(x, hx|(i^0x3ff00000)); /* normalize x or x/2 */ - k += i>>20; - y = (double)k; - f = x - 1.0; - hfsq = 0.5*f*f; - r = __log1p(f); - - /* - * f-hfsq must (for args near 1) be evaluated in extra precision - * to avoid a large cancellation when x is near sqrt(2) or 1/sqrt(2). - * This is fairly efficient since f-hfsq only depends on f, so can - * be evaluated in parallel with R. Not combining hfsq with R also - * keeps R small (though not as small as a true `lo' term would be), - * so that extra precision is not needed for terms involving R. - * - * Compiler bugs involving extra precision used to break Dekker's - * theorem for spitting f-hfsq as hi+lo, unless double_t was used - * or the multi-precision calculations were avoided when double_t - * has extra precision. These problems are now automatically - * avoided as a side effect of the optimization of combining the - * Dekker splitting step with the clear-low-bits step. - * - * y must (for args near sqrt(2) and 1/sqrt(2)) be added in extra - * precision to avoid a very large cancellation when x is very near - * these values. Unlike the above cancellations, this problem is - * specific to base 2. It is strange that adding +-1 is so much - * harder than adding +-ln2 or +-log10_2. - * - * This uses Dekker's theorem to normalize y+val_hi, so the - * compiler bugs are back in some configurations, sigh. And I - * don't want to used double_t to avoid them, since that gives a - * pessimization and the support for avoiding the pessimization - * is not yet available. - * - * The multi-precision calculations for the multiplications are - * routine. - */ - hi = f - hfsq; - SET_LOW_WORD(hi, 0); - lo = (f - hi) - hfsq + r; - val_hi = hi*ivln2hi; - val_lo = (lo+hi)*ivln2lo + lo*ivln2hi; - - /* spadd(val_hi, val_lo, y), except for not using double_t: */ - w = y + val_hi; - val_lo += (y - w) + val_hi; - val_hi = w; - - return val_lo + val_hi; -} diff --git a/05/musl-final/src/math/log2f.c b/05/musl-final/src/math/log2f.c deleted file mode 100644 index 81c017f..0000000 --- a/05/musl-final/src/math/log2f.c +++ /dev/null @@ -1,82 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/e_log2f.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ -/* - * See comments in log2.c. - */ - -#include "math.h" -#include "__log1pf.h" -#include - -static const float -two25 = 3.3554432000e+07, /* 0x4c000000 */ -ivln2hi = 1.4428710938e+00, /* 0x3fb8b000 */ -ivln2lo = -1.7605285393e-04; /* 0xb9389ad4 */ - -static const float zero = 0.0; - -float log2f(float x) -{ - float f,hfsq,hi,lo,r,y; - int32_t i,k,hx; - - GET_FLOAT_WORD(hx, x); - - k = 0; - if (hx < 0x00800000) { /* x < 2**-126 */ - if ((hx&0x7fffffff) == 0) - return -two25/zero; /* log(+-0)=-inf */ - if (hx < 0) - return (x-x)/zero; /* log(-#) = NaN */ - /* subnormal number, scale up x */ - k -= 25; - x *= two25; - GET_FLOAT_WORD(hx, x); - } - if (hx >= 0x7f800000) - return x+x; - if (hx == 0x3f800000) - return zero; /* log(1) = +0 */ - k += (hx>>23) - 127; - hx &= 0x007fffff; - i = (hx+(0x4afb0d))&0x800000; - SET_FLOAT_WORD(x, hx|(i^0x3f800000)); /* normalize x or x/2 */ - k += i>>23; - y = (float)k; - f = x - 1.0f; - hfsq = 0.5f * f * f; - r = __log1pf(f); - - /* - * We no longer need to avoid falling into the multi-precision - * calculations due to compiler bugs breaking Dekker's theorem. - * Keep avoiding this as an optimization. See log2.c for more - * details (some details are here only because the optimization - * is not yet available in double precision). - * - * Another compiler bug turned up. With gcc on i386, - * (ivln2lo + ivln2hi) would be evaluated in float precision - * despite runtime evaluations using double precision. So we - * must cast one of its terms to float_t. This makes the whole - * expression have type float_t, so return is forced to waste - * time clobbering its extra precision. - */ -// FIXME -// if (sizeof(float_t) > sizeof(float)) -// return (r - hfsq + f) * ((float_t)ivln2lo + ivln2hi) + y; - - hi = f - hfsq; - GET_FLOAT_WORD(hx,hi); - SET_FLOAT_WORD(hi,hx&0xfffff000); - lo = (f - hi) - hfsq + r; - return (lo+hi)*ivln2lo + lo*ivln2hi + hi*ivln2hi + y; -} diff --git a/05/musl-final/src/math/log2l.c b/05/musl-final/src/math/log2l.c deleted file mode 100644 index f490500..0000000 --- a/05/musl-final/src/math/log2l.c +++ /dev/null @@ -1,182 +0,0 @@ -/* origin: OpenBSD /usr/src/lib/libm/src/ld80/e_log2l.c */ -/* - * Copyright (c) 2008 Stephen L. Moshier - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ -/* - * Base 2 logarithm, long double precision - * - * - * SYNOPSIS: - * - * long double x, y, log2l(); - * - * y = log2l( x ); - * - * - * DESCRIPTION: - * - * Returns the base 2 logarithm of x. - * - * The argument is separated into its exponent and fractional - * parts. If the exponent is between -1 and +1, the (natural) - * logarithm of the fraction is approximated by - * - * log(1+x) = x - 0.5 x**2 + x**3 P(x)/Q(x). - * - * Otherwise, setting z = 2(x-1)/x+1), - * - * log(x) = z + z**3 P(z)/Q(z). - * - * - * ACCURACY: - * - * Relative error: - * arithmetic domain # trials peak rms - * IEEE 0.5, 2.0 30000 9.8e-20 2.7e-20 - * IEEE exp(+-10000) 70000 5.4e-20 2.3e-20 - * - * In the tests over the interval exp(+-10000), the logarithms - * of the random arguments were uniformly distributed over - * [-10000, +10000]. - * - * ERROR MESSAGES: - * - * log singularity: x = 0; returns -INFINITY - * log domain: x < 0; returns NAN - */ - -#include "math.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double log2l(long double x) -{ - return log2(x); -} -#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 -/* Coefficients for ln(1+x) = x - x**2/2 + x**3 P(x)/Q(x) - * 1/sqrt(2) <= x < sqrt(2) - * Theoretical peak relative error = 6.2e-22 - */ -static long double P[] = { - 4.9962495940332550844739E-1L, - 1.0767376367209449010438E1L, - 7.7671073698359539859595E1L, - 2.5620629828144409632571E2L, - 4.2401812743503691187826E2L, - 3.4258224542413922935104E2L, - 1.0747524399916215149070E2L, -}; -static long double Q[] = { -/* 1.0000000000000000000000E0,*/ - 2.3479774160285863271658E1L, - 1.9444210022760132894510E2L, - 7.7952888181207260646090E2L, - 1.6911722418503949084863E3L, - 2.0307734695595183428202E3L, - 1.2695660352705325274404E3L, - 3.2242573199748645407652E2L, -}; - -/* Coefficients for log(x) = z + z^3 P(z^2)/Q(z^2), - * where z = 2(x-1)/(x+1) - * 1/sqrt(2) <= x < sqrt(2) - * Theoretical peak relative error = 6.16e-22 - */ -static long double R[4] = { - 1.9757429581415468984296E-3L, --7.1990767473014147232598E-1L, - 1.0777257190312272158094E1L, --3.5717684488096787370998E1L, -}; -static long double S[4] = { -/* 1.00000000000000000000E0L,*/ --2.6201045551331104417768E1L, - 1.9361891836232102174846E2L, --4.2861221385716144629696E2L, -}; -/* log2(e) - 1 */ -#define LOG2EA 4.4269504088896340735992e-1L - -#define SQRTH 0.70710678118654752440L - -long double log2l(long double x) -{ - volatile long double z; - long double y; - int e; - - if (isnan(x)) - return x; - if (x == INFINITY) - return x; - if (x <= 0.0L) { - if (x == 0.0L) - return -INFINITY; - return NAN; - } - - /* separate mantissa from exponent */ - /* Note, frexp is used so that denormal numbers - * will be handled properly. - */ - x = frexpl(x, &e); - - /* logarithm using log(x) = z + z**3 P(z)/Q(z), - * where z = 2(x-1)/x+1) - */ - if (e > 2 || e < -2) { - if (x < SQRTH) { /* 2(2x-1)/(2x+1) */ - e -= 1; - z = x - 0.5L; - y = 0.5L * z + 0.5L; - } else { /* 2 (x-1)/(x+1) */ - z = x - 0.5L; - z -= 0.5L; - y = 0.5L * x + 0.5L; - } - x = z / y; - z = x*x; - y = x * (z * __polevll(z, R, 3) / __p1evll(z, S, 3)); - goto done; - } - - /* logarithm using log(1+x) = x - .5x**2 + x**3 P(x)/Q(x) */ - if (x < SQRTH) { - e -= 1; - x = ldexpl(x, 1) - 1.0L; /* 2x - 1 */ - } else { - x = x - 1.0L; - } - z = x*x; - y = x * (z * __polevll(x, P, 6) / __p1evll(x, Q, 7)); - y = y - ldexpl(z, -1); /* -0.5x^2 + ... */ - -done: - /* Multiply log of fraction by log2(e) - * and base 2 exponent by 1 - * - * ***CAUTION*** - * - * This sequence of operations is critical and it may - * be horribly defeated by some compiler optimizers. - */ - z = y * LOG2EA; - z += x * LOG2EA; - z += y; - z += x; - z += e; - return z; -} -#endif diff --git a/05/musl-final/src/math/logb.c b/05/musl-final/src/math/logb.c deleted file mode 100644 index 2eb81f4..0000000 --- a/05/musl-final/src/math/logb.c +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include "math.h" - -/* -special cases: - logb(+-0) = -inf - logb(+-inf) = +inf - logb(nan) = nan -these are calculated at runtime to raise fp exceptions -*/ - -double logb(double x) { - int i = ilogb(x); - - if (i == FP_ILOGB0) - return -1.0/fabs(x); - if (i == FP_ILOGBNAN || i == INT_MAX) - return x * x; - return i; -} diff --git a/05/musl-final/src/math/logbf.c b/05/musl-final/src/math/logbf.c deleted file mode 100644 index c04eb29..0000000 --- a/05/musl-final/src/math/logbf.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include "math.h" - -float logbf(float x) { - int i = ilogbf(x); - - if (i == FP_ILOGB0) - return -1.0f/fabsf(x); - if (i == FP_ILOGBNAN || i == INT_MAX) - return x * x; - return i; -} diff --git a/05/musl-final/src/math/logbl.c b/05/musl-final/src/math/logbl.c deleted file mode 100644 index 704c853..0000000 --- a/05/musl-final/src/math/logbl.c +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include "math.h" -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double logbl(long double x) -{ - return logb(x); -} -#else -long double logbl(long double x) -{ - int i = ilogbl(x); - - if (i == FP_ILOGB0) - return -1.0/fabsl(x); - if (i == FP_ILOGBNAN || i == INT_MAX) - return x * x; - return i; -} -#endif diff --git a/05/musl-final/src/math/logf.c b/05/musl-final/src/math/logf.c deleted file mode 100644 index 9e49b7a..0000000 --- a/05/musl-final/src/math/logf.c +++ /dev/null @@ -1,90 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/e_logf.c */ -/* - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include "math.h" -#include - -static const float -ln2_hi = 6.9313812256e-01, /* 0x3f317180 */ -ln2_lo = 9.0580006145e-06, /* 0x3717f7d1 */ -two25 = 3.355443200e+07, /* 0x4c000000 */ -/* |(log(1+s)-log(1-s))/s - Lg(s)| < 2**-34.24 (~[-4.95e-11, 4.97e-11]). */ -Lg1 = 0xaaaaaa.0p-24, /* 0.66666662693 */ -Lg2 = 0xccce13.0p-25, /* 0.40000972152 */ -Lg3 = 0x91e9ee.0p-25, /* 0.28498786688 */ -Lg4 = 0xf89e26.0p-26; /* 0.24279078841 */ - -static const float zero = 0.0; - -float logf(float x) -{ - float hfsq,f,s,z,R,w,t1,t2,dk; - int32_t k,ix,i,j; - - GET_FLOAT_WORD(ix, x); - - k = 0; - if (ix < 0x00800000) { /* x < 2**-126 */ - if ((ix & 0x7fffffff) == 0) - return -two25/zero; /* log(+-0)=-inf */ - if (ix < 0) - return (x-x)/zero; /* log(-#) = NaN */ - /* subnormal number, scale up x */ - k -= 25; - x *= two25; - GET_FLOAT_WORD(ix, x); - } - if (ix >= 0x7f800000) - return x+x; - k += (ix>>23) - 127; - ix &= 0x007fffff; - i = (ix + (0x95f64<<3)) & 0x800000; - SET_FLOAT_WORD(x, ix|(i^0x3f800000)); /* normalize x or x/2 */ - k += i>>23; - f = x - 1.0f; - if ((0x007fffff & (0x8000 + ix)) < 0xc000) { /* -2**-9 <= f < 2**-9 */ - if (f == zero) { - if (k == 0) - return zero; - dk = (float)k; - return dk*ln2_hi + dk*ln2_lo; - } - R = f*f*(0.5f - 0.33333333333333333f*f); - if (k == 0) - return f-R; - dk = (float)k; - return dk*ln2_hi - ((R-dk*ln2_lo)-f); - } - s = f/(2.0f + f); - dk = (float)k; - z = s*s; - i = ix-(0x6147a<<3); - w = z*z; - j = (0x6b851<<3)-ix; - t1= w*(Lg2+w*Lg4); - t2= z*(Lg1+w*Lg3); - i |= j; - R = t2 + t1; - if (i > 0) { - hfsq = 0.5f * f * f; - if (k == 0) - return f - (hfsq-s*(hfsq+R)); - return dk*ln2_hi - ((hfsq-(s*(hfsq+R)+dk*ln2_lo))-f); - } else { - if (k == 0) - return f - s*(f-R); - return dk*ln2_hi - ((s*(f-R)-dk*ln2_lo)-f); - } -} diff --git a/05/musl-final/src/math/logl.c b/05/musl-final/src/math/logl.c deleted file mode 100644 index 15d7083..0000000 --- a/05/musl-final/src/math/logl.c +++ /dev/null @@ -1,174 +0,0 @@ -/* origin: OpenBSD /usr/src/lib/libm/src/ld80/e_logl.c */ -/* - * Copyright (c) 2008 Stephen L. Moshier - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ -/* - * Natural logarithm, long double precision - * - * - * SYNOPSIS: - * - * long double x, y, logl(); - * - * y = logl( x ); - * - * - * DESCRIPTION: - * - * Returns the base e (2.718...) logarithm of x. - * - * The argument is separated into its exponent and fractional - * parts. If the exponent is between -1 and +1, the logarithm - * of the fraction is approximated by - * - * log(1+x) = x - 0.5 x**2 + x**3 P(x)/Q(x). - * - * Otherwise, setting z = 2(x-1)/x+1), - * - * log(x) = z + z**3 P(z)/Q(z). - * - * - * ACCURACY: - * - * Relative error: - * arithmetic domain # trials peak rms - * IEEE 0.5, 2.0 150000 8.71e-20 2.75e-20 - * IEEE exp(+-10000) 100000 5.39e-20 2.34e-20 - * - * In the tests over the interval exp(+-10000), the logarithms - * of the random arguments were uniformly distributed over - * [-10000, +10000]. - * - * ERROR MESSAGES: - * - * log singularity: x = 0; returns -INFINITY - * log domain: x < 0; returns NAN - */ - -#include "math.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double logl(long double x) -{ - return log(x); -} -#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 -/* Coefficients for log(1+x) = x - x**2/2 + x**3 P(x)/Q(x) - * 1/sqrt(2) <= x < sqrt(2) - * Theoretical peak relative error = 2.32e-20 - */ -static long double P[] = { - 4.5270000862445199635215E-5L, - 4.9854102823193375972212E-1L, - 6.5787325942061044846969E0L, - 2.9911919328553073277375E1L, - 6.0949667980987787057556E1L, - 5.7112963590585538103336E1L, - 2.0039553499201281259648E1L, -}; -static long double Q[] = { -/* 1.0000000000000000000000E0,*/ - 1.5062909083469192043167E1L, - 8.3047565967967209469434E1L, - 2.2176239823732856465394E2L, - 3.0909872225312059774938E2L, - 2.1642788614495947685003E2L, - 6.0118660497603843919306E1L, -}; - -/* Coefficients for log(x) = z + z^3 P(z^2)/Q(z^2), - * where z = 2(x-1)/(x+1) - * 1/sqrt(2) <= x < sqrt(2) - * Theoretical peak relative error = 6.16e-22 - */ -static long double R[4] = { - 1.9757429581415468984296E-3L, --7.1990767473014147232598E-1L, - 1.0777257190312272158094E1L, --3.5717684488096787370998E1L, -}; -static long double S[4] = { -/* 1.00000000000000000000E0L,*/ --2.6201045551331104417768E1L, - 1.9361891836232102174846E2L, --4.2861221385716144629696E2L, -}; -static const long double C1 = 6.9314575195312500000000E-1L; -static const long double C2 = 1.4286068203094172321215E-6L; - -#define SQRTH 0.70710678118654752440L - -long double logl(long double x) -{ - long double y, z; - int e; - - if (isnan(x)) - return x; - if (x == INFINITY) - return x; - if (x <= 0.0L) { - if (x == 0.0L) - return -INFINITY; - return NAN; - } - - /* separate mantissa from exponent */ - /* Note, frexp is used so that denormal numbers - * will be handled properly. - */ - x = frexpl(x, &e); - - /* logarithm using log(x) = z + z**3 P(z)/Q(z), - * where z = 2(x-1)/x+1) - */ - if (e > 2 || e < -2) { - if (x < SQRTH) { /* 2(2x-1)/(2x+1) */ - e -= 1; - z = x - 0.5L; - y = 0.5L * z + 0.5L; - } else { /* 2 (x-1)/(x+1) */ - z = x - 0.5L; - z -= 0.5L; - y = 0.5L * x + 0.5L; - } - x = z / y; - z = x*x; - z = x * (z * __polevll(z, R, 3) / __p1evll(z, S, 3)); - z = z + e * C2; - z = z + x; - z = z + e * C1; - return z; - } - - /* logarithm using log(1+x) = x - .5x**2 + x**3 P(x)/Q(x) */ - if (x < SQRTH) { - e -= 1; - x = ldexpl(x, 1) - 1.0L; /* 2x - 1 */ - } else { - x = x - 1.0L; - } - z = x*x; - y = x * (z * __polevll(x, P, 6) / __p1evll(x, Q, 6)); - y = y + e * C2; - z = y - ldexpl(z, -1); /* y - 0.5 * z */ - /* Note, the sum of above terms does not exceed x/4, - * so it contributes at most about 1/4 lsb to the error. - */ - z = z + x; - z = z + e * C1; /* This sum has an error of 1/2 lsb. */ - return z; -} -#endif diff --git a/05/musl-final/src/math/math_private.h b/05/musl-final/src/math/math_private.h deleted file mode 100644 index 28a6a19..0000000 --- a/05/musl-final/src/math/math_private.h +++ /dev/null @@ -1,143 +0,0 @@ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#ifndef _MATH_PRIVATE_H_ -#define _MATH_PRIVATE_H_ - -#include - -/* - * The original fdlibm code used statements like: - * n0 = ((*(int*)&one)>>29)^1; * index of high word * - * ix0 = *(n0+(int*)&x); * high word of x * - * ix1 = *((1-n0)+(int*)&x); * low word of x * - * to dig two 32 bit words out of the 64 bit IEEE floating point - * value. That is non-ANSI, and, moreover, the gcc instruction - * scheduler gets it wrong. We instead use the following macros. - * Unlike the original code, we determine the endianness at compile - * time, not at run time; I don't see much benefit to selecting - * endianness at run time. - */ - -/* - * A union which permits us to convert between a double and two 32 bit - * ints. - */ - -typedef union -{ - double value; - uint64_t words; -} ieee_double_shape_type; - -/* Get two 32 bit ints from a double. */ - -#define EXTRACT_WORDS(ix0,ix1,d) \ -do { \ - ieee_double_shape_type ew_u; \ - ew_u.value = (d); \ - (ix0) = ew_u.words >> 32; \ - (ix1) = (uint32_t)ew_u.words; \ -} while (0) - -/* Get the more significant 32 bit int from a double. */ - -#define GET_HIGH_WORD(i,d) \ -do { \ - ieee_double_shape_type gh_u; \ - gh_u.value = (d); \ - (i) = gh_u.words >> 32; \ -} while (0) - -/* Get the less significant 32 bit int from a double. */ - -#define GET_LOW_WORD(i,d) \ -do { \ - ieee_double_shape_type gl_u; \ - gl_u.value = (d); \ - (i) = (uint32_t)gl_u.words; \ -} while (0) - -/* Set a double from two 32 bit ints. */ - -#define INSERT_WORDS(d,ix0,ix1) \ -do { \ - ieee_double_shape_type iw_u; \ - iw_u.words = ((uint64_t)(ix0) << 32) | (ix1); \ - (d) = iw_u.value; \ -} while (0) - -/* Set the more significant 32 bits of a double from an int. */ - -#define SET_HIGH_WORD(d,v) \ -do { \ - ieee_double_shape_type sh_u; \ - sh_u.value = (d); \ - sh_u.words &= 0xffffffff; \ - sh_u.words |= ((uint64_t)(v) << 32); \ - (d) = sh_u.value; \ -} while (0) - -/* Set the less significant 32 bits of a double from an int. */ - -#define SET_LOW_WORD(d,v) \ -do { \ - ieee_double_shape_type sl_u; \ - sl_u.value = (d); \ - sl_u.words &= 0xffffffff00000000ull; \ - sl_u.words |= (uint32_t)(v); \ - (d) = sl_u.value; \ -} while (0) - -/* - * A union which permits us to convert between a float and a 32 bit - * int. - */ - -typedef union -{ - float value; - uint32_t word; -} ieee_float_shape_type; - -/* Get a 32 bit int from a float. */ - -#define GET_FLOAT_WORD(i,d) \ -do { \ - ieee_float_shape_type gf_u; \ - gf_u.value = (d); \ - (i) = gf_u.word; \ -} while (0) - -/* Set a float from a 32 bit int. */ - -#define SET_FLOAT_WORD(d,i) \ -do { \ - ieee_float_shape_type sf_u; \ - sf_u.word = (i); \ - (d) = sf_u.value; \ -} while (0) - -/* fdlibm kernel function */ -int __ieee754_rem_pio2(double,double*); -double __kernel_sin(double,double,int); -double __kernel_cos(double,double); -double __kernel_tan(double,double,int); -int __kernel_rem_pio2(double*,double*,int,int,int,const int*); - -/* float versions of fdlibm kernel functions */ -int __ieee754_rem_pio2f(float,float*); -float __kernel_sinf(float,float,int); -float __kernel_cosf(float,float); -float __kernel_tanf(float,float,int); -int __kernel_rem_pio2f(float*,float*,int,int,int,const int*); - -#endif /* !_MATH_PRIVATE_H_ */ diff --git a/05/musl-final/src/math/s_asinh.c b/05/musl-final/src/math/s_asinh.c deleted file mode 100644 index 2601609..0000000 --- a/05/musl-final/src/math/s_asinh.c +++ /dev/null @@ -1,53 +0,0 @@ -/* @(#)s_asinh.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* asinh(x) - * Method : - * Based on - * asinh(x) = sign(x) * log [ |x| + sqrt(x*x+1) ] - * we have - * asinh(x) := x if 1+x*x=1, - * := sign(x)*(log(x)+ln2)) for large |x|, else - * := sign(x)*log(2|x|+1/(|x|+sqrt(x*x+1))) if|x|>2, else - * := sign(x)*log1p(|x| + x^2/(1 + sqrt(1+x^2))) - */ - -#include -#include "math_private.h" - -static const double -one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */ -ln2 = 6.93147180559945286227e-01, /* 0x3FE62E42, 0xFEFA39EF */ -huge= 1.00000000000000000000e+300; - -double -asinh(double x) -{ - double t,w; - int32_t hx,ix; - GET_HIGH_WORD(hx,x); - ix = hx&0x7fffffff; - if(ix>=0x7ff00000) return x+x; /* x is inf or NaN */ - if(ix< 0x3e300000) { /* |x|<2**-28 */ - if(huge+x>one) return x; /* return x inexact except 0 */ - } - if(ix>0x41b00000) { /* |x| > 2**28 */ - w = log(fabs(x))+ln2; - } else if (ix>0x40000000) { /* 2**28 > |x| > 2.0 */ - t = fabs(x); - w = log(2.0*t+one/(sqrt(x*x+one)+t)); - } else { /* 2.0 > |x| > 2**-28 */ - t = x*x; - w =log1p(fabs(x)+t/(one+sqrt(one+t))); - } - if(hx>0) return w; else return -w; -} diff --git a/05/musl-final/src/math/s_asinhf.c b/05/musl-final/src/math/s_asinhf.c deleted file mode 100644 index 04f8d07..0000000 --- a/05/musl-final/src/math/s_asinhf.c +++ /dev/null @@ -1,45 +0,0 @@ -/* s_asinhf.c -- float version of s_asinh.c. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include -#include "math_private.h" - -static const float -one = 1.0000000000e+00, /* 0x3F800000 */ -ln2 = 6.9314718246e-01, /* 0x3f317218 */ -huge= 1.0000000000e+30; - -float -asinhf(float x) -{ - float t,w; - int32_t hx,ix; - GET_FLOAT_WORD(hx,x); - ix = hx&0x7fffffff; - if(ix>=0x7f800000) return x+x; /* x is inf or NaN */ - if(ix< 0x31800000) { /* |x|<2**-28 */ - if(huge+x>one) return x; /* return x inexact except 0 */ - } - if(ix>0x4d800000) { /* |x| > 2**28 */ - w = logf(fabsf(x))+ln2; - } else if (ix>0x40000000) { /* 2**28 > |x| > 2.0 */ - t = fabsf(x); - w = logf((float)2.0*t+one/(sqrtf(x*x+one)+t)); - } else { /* 2.0 > |x| > 2**-28 */ - t = x*x; - w =log1pf(fabsf(x)+t/(one+sqrtf(one+t))); - } - if(hx>0) return w; else return -w; -} diff --git a/05/musl-final/src/math/s_atan.c b/05/musl-final/src/math/s_atan.c deleted file mode 100644 index 1faac02..0000000 --- a/05/musl-final/src/math/s_atan.c +++ /dev/null @@ -1,115 +0,0 @@ -/* @(#)s_atan.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* atan(x) - * Method - * 1. Reduce x to positive by atan(x) = -atan(-x). - * 2. According to the integer k=4t+0.25 chopped, t=x, the argument - * is further reduced to one of the following intervals and the - * arctangent of t is evaluated by the corresponding formula: - * - * [0,7/16] atan(x) = t-t^3*(a1+t^2*(a2+...(a10+t^2*a11)...) - * [7/16,11/16] atan(x) = atan(1/2) + atan( (t-0.5)/(1+t/2) ) - * [11/16.19/16] atan(x) = atan( 1 ) + atan( (t-1)/(1+t) ) - * [19/16,39/16] atan(x) = atan(3/2) + atan( (t-1.5)/(1+1.5t) ) - * [39/16,INF] atan(x) = atan(INF) + atan( -1/t ) - * - * Constants: - * The hexadecimal values are the intended ones for the following - * constants. The decimal values may be used, provided that the - * compiler will convert from decimal to binary accurately enough - * to produce the hexadecimal values shown. - */ - -#include -#include "math_private.h" - -static const double atanhi[] = { - 4.63647609000806093515e-01, /* atan(0.5)hi 0x3FDDAC67, 0x0561BB4F */ - 7.85398163397448278999e-01, /* atan(1.0)hi 0x3FE921FB, 0x54442D18 */ - 9.82793723247329054082e-01, /* atan(1.5)hi 0x3FEF730B, 0xD281F69B */ - 1.57079632679489655800e+00, /* atan(inf)hi 0x3FF921FB, 0x54442D18 */ -}; - -static const double atanlo[] = { - 2.26987774529616870924e-17, /* atan(0.5)lo 0x3C7A2B7F, 0x222F65E2 */ - 3.06161699786838301793e-17, /* atan(1.0)lo 0x3C81A626, 0x33145C07 */ - 1.39033110312309984516e-17, /* atan(1.5)lo 0x3C700788, 0x7AF0CBBD */ - 6.12323399573676603587e-17, /* atan(inf)lo 0x3C91A626, 0x33145C07 */ -}; - -static const double aT[] = { - 3.33333333333329318027e-01, /* 0x3FD55555, 0x5555550D */ - -1.99999999998764832476e-01, /* 0xBFC99999, 0x9998EBC4 */ - 1.42857142725034663711e-01, /* 0x3FC24924, 0x920083FF */ - -1.11111104054623557880e-01, /* 0xBFBC71C6, 0xFE231671 */ - 9.09088713343650656196e-02, /* 0x3FB745CD, 0xC54C206E */ - -7.69187620504482999495e-02, /* 0xBFB3B0F2, 0xAF749A6D */ - 6.66107313738753120669e-02, /* 0x3FB10D66, 0xA0D03D51 */ - -5.83357013379057348645e-02, /* 0xBFADDE2D, 0x52DEFD9A */ - 4.97687799461593236017e-02, /* 0x3FA97B4B, 0x24760DEB */ - -3.65315727442169155270e-02, /* 0xBFA2B444, 0x2C6A6C2F */ - 1.62858201153657823623e-02, /* 0x3F90AD3A, 0xE322DA11 */ -}; - - static const double -one = 1.0, -huge = 1.0e300; - -double -atan(double x) -{ - double w,s1,s2,z; - int32_t ix,hx,id; - - GET_HIGH_WORD(hx,x); - ix = hx&0x7fffffff; - if(ix>=0x44100000) { /* if |x| >= 2^66 */ - uint32_t low; - GET_LOW_WORD(low,x); - if(ix>0x7ff00000|| - (ix==0x7ff00000&&(low!=0))) - return x+x; /* NaN */ - if(hx>0) return atanhi[3]+atanlo[3]; - else return -atanhi[3]-atanlo[3]; - } if (ix < 0x3fdc0000) { /* |x| < 0.4375 */ - if (ix < 0x3e200000) { /* |x| < 2^-29 */ - if(huge+x>one) return x; /* raise inexact */ - } - id = -1; - } else { - x = fabs(x); - if (ix < 0x3ff30000) { /* |x| < 1.1875 */ - if (ix < 0x3fe60000) { /* 7/16 <=|x|<11/16 */ - id = 0; x = (2.0*x-one)/(2.0+x); - } else { /* 11/16<=|x|< 19/16 */ - id = 1; x = (x-one)/(x+one); - } - } else { - if (ix < 0x40038000) { /* |x| < 2.4375 */ - id = 2; x = (x-1.5)/(one+1.5*x); - } else { /* 2.4375 <= |x| < 2^66 */ - id = 3; x = -1.0/x; - } - }} - /* end of argument reduction */ - z = x*x; - w = z*z; - /* break sum from i=0 to 10 aT[i]z**(i+1) into odd and even poly */ - s1 = z*(aT[0]+w*(aT[2]+w*(aT[4]+w*(aT[6]+w*(aT[8]+w*aT[10]))))); - s2 = w*(aT[1]+w*(aT[3]+w*(aT[5]+w*(aT[7]+w*aT[9])))); - if (id<0) return x - x*(s1+s2); - else { - z = atanhi[id] - ((x*(s1+s2) - atanlo[id]) - x); - return (hx<0)? -z:z; - } -} diff --git a/05/musl-final/src/math/s_atanf.c b/05/musl-final/src/math/s_atanf.c deleted file mode 100644 index 03067e1..0000000 --- a/05/musl-final/src/math/s_atanf.c +++ /dev/null @@ -1,95 +0,0 @@ -/* s_atanf.c -- float version of s_atan.c. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include -#include "math_private.h" - -static const float atanhi[] = { - 4.6364760399e-01, /* atan(0.5)hi 0x3eed6338 */ - 7.8539812565e-01, /* atan(1.0)hi 0x3f490fda */ - 9.8279368877e-01, /* atan(1.5)hi 0x3f7b985e */ - 1.5707962513e+00, /* atan(inf)hi 0x3fc90fda */ -}; - -static const float atanlo[] = { - 5.0121582440e-09, /* atan(0.5)lo 0x31ac3769 */ - 3.7748947079e-08, /* atan(1.0)lo 0x33222168 */ - 3.4473217170e-08, /* atan(1.5)lo 0x33140fb4 */ - 7.5497894159e-08, /* atan(inf)lo 0x33a22168 */ -}; - -static const float aT[] = { - 3.3333334327e-01, /* 0x3eaaaaaa */ - -2.0000000298e-01, /* 0xbe4ccccd */ - 1.4285714924e-01, /* 0x3e124925 */ - -1.1111110449e-01, /* 0xbde38e38 */ - 9.0908870101e-02, /* 0x3dba2e6e */ - -7.6918758452e-02, /* 0xbd9d8795 */ - 6.6610731184e-02, /* 0x3d886b35 */ - -5.8335702866e-02, /* 0xbd6ef16b */ - 4.9768779427e-02, /* 0x3d4bda59 */ - -3.6531571299e-02, /* 0xbd15a221 */ - 1.6285819933e-02, /* 0x3c8569d7 */ -}; - - static const float -one = 1.0, -huge = 1.0e30; - -float -atanf(float x) -{ - float w,s1,s2,z; - int32_t ix,hx,id; - - GET_FLOAT_WORD(hx,x); - ix = hx&0x7fffffff; - if(ix>=0x50800000) { /* if |x| >= 2^34 */ - if(ix>0x7f800000) - return x+x; /* NaN */ - if(hx>0) return atanhi[3]+atanlo[3]; - else return -atanhi[3]-atanlo[3]; - } if (ix < 0x3ee00000) { /* |x| < 0.4375 */ - if (ix < 0x31000000) { /* |x| < 2^-29 */ - if(huge+x>one) return x; /* raise inexact */ - } - id = -1; - } else { - x = fabsf(x); - if (ix < 0x3f980000) { /* |x| < 1.1875 */ - if (ix < 0x3f300000) { /* 7/16 <=|x|<11/16 */ - id = 0; x = ((float)2.0*x-one)/((float)2.0+x); - } else { /* 11/16<=|x|< 19/16 */ - id = 1; x = (x-one)/(x+one); - } - } else { - if (ix < 0x401c0000) { /* |x| < 2.4375 */ - id = 2; x = (x-(float)1.5)/(one+(float)1.5*x); - } else { /* 2.4375 <= |x| < 2^66 */ - id = 3; x = -(float)1.0/x; - } - }} - /* end of argument reduction */ - z = x*x; - w = z*z; - /* break sum from i=0 to 10 aT[i]z**(i+1) into odd and even poly */ - s1 = z*(aT[0]+w*(aT[2]+w*(aT[4]+w*(aT[6]+w*(aT[8]+w*aT[10]))))); - s2 = w*(aT[1]+w*(aT[3]+w*(aT[5]+w*(aT[7]+w*aT[9])))); - if (id<0) return x - x*(s1+s2); - else { - z = atanhi[id] - ((x*(s1+s2) - atanlo[id]) - x); - return (hx<0)? -z:z; - } -} diff --git a/05/musl-final/src/math/s_cbrt.c b/05/musl-final/src/math/s_cbrt.c deleted file mode 100644 index 8adcb19..0000000 --- a/05/musl-final/src/math/s_cbrt.c +++ /dev/null @@ -1,77 +0,0 @@ -/* @(#)s_cbrt.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include -#include "math_private.h" - -/* cbrt(x) - * Return cube root of x - */ -static const uint32_t - B1 = 715094163, /* B1 = (682-0.03306235651)*2**20 */ - B2 = 696219795; /* B2 = (664-0.03306235651)*2**20 */ - -static const double -C = 5.42857142857142815906e-01, /* 19/35 = 0x3FE15F15, 0xF15F15F1 */ -D = -7.05306122448979611050e-01, /* -864/1225 = 0xBFE691DE, 0x2532C834 */ -E = 1.41428571428571436819e+00, /* 99/70 = 0x3FF6A0EA, 0x0EA0EA0F */ -F = 1.60714285714285720630e+00, /* 45/28 = 0x3FF9B6DB, 0x6DB6DB6E */ -G = 3.57142857142857150787e-01; /* 5/14 = 0x3FD6DB6D, 0xB6DB6DB7 */ - -double -cbrt(double x) -{ - int32_t hx; - double r,s,t=0.0,w; - uint32_t sign; - uint32_t high,low; - - GET_HIGH_WORD(hx,x); - sign=hx&0x80000000; /* sign= sign(x) */ - hx ^=sign; - if(hx>=0x7ff00000) return(x+x); /* cbrt(NaN,INF) is itself */ - GET_LOW_WORD(low,x); - if((hx|low)==0) - return(x); /* cbrt(0) is itself */ - - SET_HIGH_WORD(x,hx); /* x <- |x| */ - /* rough cbrt to 5 bits */ - if(hx<0x00100000) /* subnormal number */ - {SET_HIGH_WORD(t,0x43500000); /* set t= 2**54 */ - t*=x; GET_HIGH_WORD(high,t); SET_HIGH_WORD(t,high/3+B2); - } - else - SET_HIGH_WORD(t,hx/3+B1); - - - /* new cbrt to 23 bits, may be implemented in single precision */ - r=t*t/x; - s=C+r*t; - t*=G+F/(s+E+D/s); - - /* chopped to 20 bits and make it larger than cbrt(x) */ - GET_HIGH_WORD(high,t); - INSERT_WORDS(t,high+0x00000001,0); - - - /* one step newton iteration to 53 bits with error less than 0.667 ulps */ - s=t*t; /* t*t is exact */ - r=x/s; - w=t+t; - r=(r-t)/(w+r); /* r-s is exact */ - t=t+t*r; - - /* retore the sign bit */ - GET_HIGH_WORD(high,t); - SET_HIGH_WORD(t,high|sign); - return(t); -} diff --git a/05/musl-final/src/math/s_cbrtf.c b/05/musl-final/src/math/s_cbrtf.c deleted file mode 100644 index e7b46de..0000000 --- a/05/musl-final/src/math/s_cbrtf.c +++ /dev/null @@ -1,67 +0,0 @@ -/* s_cbrtf.c -- float version of s_cbrt.c. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include -#include "math_private.h" - -/* cbrtf(x) - * Return cube root of x - */ -static const unsigned - B1 = 709958130, /* B1 = (84+2/3-0.03306235651)*2**23 */ - B2 = 642849266; /* B2 = (76+2/3-0.03306235651)*2**23 */ - -static const float -C = 5.4285717010e-01, /* 19/35 = 0x3f0af8b0 */ -D = -7.0530611277e-01, /* -864/1225 = 0xbf348ef1 */ -E = 1.4142856598e+00, /* 99/70 = 0x3fb50750 */ -F = 1.6071428061e+00, /* 45/28 = 0x3fcdb6db */ -G = 3.5714286566e-01; /* 5/14 = 0x3eb6db6e */ - -float -cbrtf(float x) -{ - float r,s,t; - int32_t hx; - uint32_t sign; - uint32_t high; - - GET_FLOAT_WORD(hx,x); - sign=hx&0x80000000; /* sign= sign(x) */ - hx ^=sign; - if(hx>=0x7f800000) return(x+x); /* cbrt(NaN,INF) is itself */ - if(hx==0) - return(x); /* cbrt(0) is itself */ - - SET_FLOAT_WORD(x,hx); /* x <- |x| */ - /* rough cbrt to 5 bits */ - if(hx<0x00800000) /* subnormal number */ - {SET_FLOAT_WORD(t,0x4b800000); /* set t= 2**24 */ - t*=x; GET_FLOAT_WORD(high,t); SET_FLOAT_WORD(t,high/3+B2); - } - else - SET_FLOAT_WORD(t,hx/3+B1); - - - /* new cbrt to 23 bits */ - r=t*t/x; - s=C+r*t; - t*=G+F/(s+E+D/s); - - /* retore the sign bit */ - GET_FLOAT_WORD(high,t); - SET_FLOAT_WORD(t,high|sign); - return(t); -} diff --git a/05/musl-final/src/math/s_ceil.c b/05/musl-final/src/math/s_ceil.c deleted file mode 100644 index 1670cad..0000000 --- a/05/musl-final/src/math/s_ceil.c +++ /dev/null @@ -1,68 +0,0 @@ -/* @(#)s_ceil.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* - * ceil(x) - * Return x rounded toward -inf to integral value - * Method: - * Bit twiddling. - * Exception: - * Inexact flag raised if x not equal to ceil(x). - */ - -#include -#include "math_private.h" - -static const double huge = 1.0e300; - -double -ceil(double x) -{ - int32_t i0,i1,j0; - uint32_t i,j; - EXTRACT_WORDS(i0,i1,x); - j0 = ((i0>>20)&0x7ff)-0x3ff; - if(j0<20) { - if(j0<0) { /* raise inexact if x != 0 */ - if(huge+x>0.0) {/* return 0*sign(x) if |x|<1 */ - if(i0<0) {i0=0x80000000;i1=0;} - else if((i0|i1)!=0) { i0=0x3ff00000;i1=0;} - } - } else { - i = (0x000fffff)>>j0; - if(((i0&i)|i1)==0) return x; /* x is integral */ - if(huge+x>0.0) { /* raise inexact flag */ - if(i0>0) i0 += (0x00100000)>>j0; - i0 &= (~i); i1=0; - } - } - } else if (j0>51) { - if(j0==0x400) return x+x; /* inf or NaN */ - else return x; /* x is integral */ - } else { - i = ((uint32_t)(0xffffffff))>>(j0-20); - if((i1&i)==0) return x; /* x is integral */ - if(huge+x>0.0) { /* raise inexact flag */ - if(i0>0) { - if(j0==20) i0+=1; - else { - j = i1 + (1<<(52-j0)); - if(j -#include "math_private.h" - -static const float huge = 1.0e30; - -float -ceilf(float x) -{ - int32_t i0,j0; - uint32_t i; - - GET_FLOAT_WORD(i0,x); - j0 = ((i0>>23)&0xff)-0x7f; - if(j0<23) { - if(j0<0) { /* raise inexact if x != 0 */ - if(huge+x>(float)0.0) {/* return 0*sign(x) if |x|<1 */ - if(i0<0) {i0=0x80000000;} - else if(i0!=0) { i0=0x3f800000;} - } - } else { - i = (0x007fffff)>>j0; - if((i0&i)==0) return x; /* x is integral */ - if(huge+x>(float)0.0) { /* raise inexact flag */ - if(i0>0) i0 += (0x00800000)>>j0; - i0 &= (~i); - } - } - } else { - if(j0==0x80) return x+x; /* inf or NaN */ - else return x; /* x is integral */ - } - SET_FLOAT_WORD(x,i0); - return x; -} diff --git a/05/musl-final/src/math/s_copysign.c b/05/musl-final/src/math/s_copysign.c deleted file mode 100644 index 59d3877..0000000 --- a/05/musl-final/src/math/s_copysign.c +++ /dev/null @@ -1,30 +0,0 @@ -/* @(#)s_copysign.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* - * copysign(double x, double y) - * copysign(x,y) returns a value with the magnitude of x and - * with the sign bit of y. - */ - -#include -#include "math_private.h" - -double -copysign(double x, double y) -{ - uint32_t hx,hy; - GET_HIGH_WORD(hx,x); - GET_HIGH_WORD(hy,y); - SET_HIGH_WORD(x,(hx&0x7fffffff)|(hy&0x80000000)); - return x; -} diff --git a/05/musl-final/src/math/s_copysignf.c b/05/musl-final/src/math/s_copysignf.c deleted file mode 100644 index d650e8e..0000000 --- a/05/musl-final/src/math/s_copysignf.c +++ /dev/null @@ -1,33 +0,0 @@ -/* s_copysignf.c -- float version of s_copysign.c. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* - * copysignf(float x, float y) - * copysignf(x,y) returns a value with the magnitude of x and - * with the sign bit of y. - */ - -#include -#include "math_private.h" - -float -copysignf(float x, float y) -{ - uint32_t ix,iy; - GET_FLOAT_WORD(ix,x); - GET_FLOAT_WORD(iy,y); - SET_FLOAT_WORD(x,(ix&0x7fffffff)|(iy&0x80000000)); - return x; -} diff --git a/05/musl-final/src/math/s_cos.c b/05/musl-final/src/math/s_cos.c deleted file mode 100644 index 1893ab1..0000000 --- a/05/musl-final/src/math/s_cos.c +++ /dev/null @@ -1,74 +0,0 @@ -/* @(#)s_cos.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* cos(x) - * Return cosine function of x. - * - * kernel function: - * __kernel_sin ... sine function on [-pi/4,pi/4] - * __kernel_cos ... cosine function on [-pi/4,pi/4] - * __ieee754_rem_pio2 ... argument reduction routine - * - * Method. - * Let S,C and T denote the sin, cos and tan respectively on - * [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2 - * in [-pi/4 , +pi/4], and let n = k mod 4. - * We have - * - * n sin(x) cos(x) tan(x) - * ---------------------------------------------------------- - * 0 S C T - * 1 C -S -1/T - * 2 -S -C T - * 3 -C S -1/T - * ---------------------------------------------------------- - * - * Special cases: - * Let trig be any of sin, cos, or tan. - * trig(+-INF) is NaN, with signals; - * trig(NaN) is that NaN; - * - * Accuracy: - * TRIG(x) returns trig(x) nearly rounded - */ - -#include -#include "math_private.h" - -double -cos(double x) -{ - double y[2],z=0.0; - int32_t n, ix; - - /* High word of x. */ - GET_HIGH_WORD(ix,x); - - /* |x| ~< pi/4 */ - ix &= 0x7fffffff; - if(ix <= 0x3fe921fb) return __kernel_cos(x,z); - - /* cos(Inf or NaN) is NaN */ - else if (ix>=0x7ff00000) return x-x; - - /* argument reduction needed */ - else { - n = __ieee754_rem_pio2(x,y); - switch(n&3) { - case 0: return __kernel_cos(y[0],y[1]); - case 1: return -__kernel_sin(y[0],y[1],1); - case 2: return -__kernel_cos(y[0],y[1]); - default: - return __kernel_sin(y[0],y[1],1); - } - } -} diff --git a/05/musl-final/src/math/s_cosf.c b/05/musl-final/src/math/s_cosf.c deleted file mode 100644 index 14b8e98..0000000 --- a/05/musl-final/src/math/s_cosf.c +++ /dev/null @@ -1,47 +0,0 @@ -/* s_cosf.c -- float version of s_cos.c. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include -#include "math_private.h" - -static const float one=1.0; - -float -cosf(float x) -{ - float y[2],z=0.0; - int32_t n,ix; - - GET_FLOAT_WORD(ix,x); - - /* |x| ~< pi/4 */ - ix &= 0x7fffffff; - if(ix <= 0x3f490fd8) return __kernel_cosf(x,z); - - /* cos(Inf or NaN) is NaN */ - else if (ix>=0x7f800000) return x-x; - - /* argument reduction needed */ - else { - n = __ieee754_rem_pio2f(x,y); - switch(n&3) { - case 0: return __kernel_cosf(y[0],y[1]); - case 1: return -__kernel_sinf(y[0],y[1],1); - case 2: return -__kernel_cosf(y[0],y[1]); - default: - return __kernel_sinf(y[0],y[1],1); - } - } -} diff --git a/05/musl-final/src/math/s_erf.c b/05/musl-final/src/math/s_erf.c deleted file mode 100644 index e321fee..0000000 --- a/05/musl-final/src/math/s_erf.c +++ /dev/null @@ -1,298 +0,0 @@ -/* @(#)s_erf.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* double erf(double x) - * double erfc(double x) - * x - * 2 |\ - * erf(x) = --------- | exp(-t*t)dt - * sqrt(pi) \| - * 0 - * - * erfc(x) = 1-erf(x) - * Note that - * erf(-x) = -erf(x) - * erfc(-x) = 2 - erfc(x) - * - * Method: - * 1. For |x| in [0, 0.84375] - * erf(x) = x + x*R(x^2) - * erfc(x) = 1 - erf(x) if x in [-.84375,0.25] - * = 0.5 + ((0.5-x)-x*R) if x in [0.25,0.84375] - * where R = P/Q where P is an odd poly of degree 8 and - * Q is an odd poly of degree 10. - * -57.90 - * | R - (erf(x)-x)/x | <= 2 - * - * - * Remark. The formula is derived by noting - * erf(x) = (2/sqrt(pi))*(x - x^3/3 + x^5/10 - x^7/42 + ....) - * and that - * 2/sqrt(pi) = 1.128379167095512573896158903121545171688 - * is close to one. The interval is chosen because the fix - * point of erf(x) is near 0.6174 (i.e., erf(x)=x when x is - * near 0.6174), and by some experiment, 0.84375 is chosen to - * guarantee the error is less than one ulp for erf. - * - * 2. For |x| in [0.84375,1.25], let s = |x| - 1, and - * c = 0.84506291151 rounded to single (24 bits) - * erf(x) = sign(x) * (c + P1(s)/Q1(s)) - * erfc(x) = (1-c) - P1(s)/Q1(s) if x > 0 - * 1+(c+P1(s)/Q1(s)) if x < 0 - * |P1/Q1 - (erf(|x|)-c)| <= 2**-59.06 - * Remark: here we use the taylor series expansion at x=1. - * erf(1+s) = erf(1) + s*Poly(s) - * = 0.845.. + P1(s)/Q1(s) - * That is, we use rational approximation to approximate - * erf(1+s) - (c = (single)0.84506291151) - * Note that |P1/Q1|< 0.078 for x in [0.84375,1.25] - * where - * P1(s) = degree 6 poly in s - * Q1(s) = degree 6 poly in s - * - * 3. For x in [1.25,1/0.35(~2.857143)], - * erfc(x) = (1/x)*exp(-x*x-0.5625+R1/S1) - * erf(x) = 1 - erfc(x) - * where - * R1(z) = degree 7 poly in z, (z=1/x^2) - * S1(z) = degree 8 poly in z - * - * 4. For x in [1/0.35,28] - * erfc(x) = (1/x)*exp(-x*x-0.5625+R2/S2) if x > 0 - * = 2.0 - (1/x)*exp(-x*x-0.5625+R2/S2) if -6 x >= 28 - * erf(x) = sign(x) *(1 - tiny) (raise inexact) - * erfc(x) = tiny*tiny (raise underflow) if x > 0 - * = 2 - tiny if x<0 - * - * 7. Special case: - * erf(0) = 0, erf(inf) = 1, erf(-inf) = -1, - * erfc(0) = 1, erfc(inf) = 0, erfc(-inf) = 2, - * erfc/erf(NaN) is NaN - */ - - -#include -#include "math_private.h" - -static const double -tiny = 1e-300, -half= 5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */ -one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */ -two = 2.00000000000000000000e+00, /* 0x40000000, 0x00000000 */ - /* c = (float)0.84506291151 */ -erx = 8.45062911510467529297e-01, /* 0x3FEB0AC1, 0x60000000 */ -/* - * Coefficients for approximation to erf on [0,0.84375] - */ -efx = 1.28379167095512586316e-01, /* 0x3FC06EBA, 0x8214DB69 */ -efx8= 1.02703333676410069053e+00, /* 0x3FF06EBA, 0x8214DB69 */ -pp0 = 1.28379167095512558561e-01, /* 0x3FC06EBA, 0x8214DB68 */ -pp1 = -3.25042107247001499370e-01, /* 0xBFD4CD7D, 0x691CB913 */ -pp2 = -2.84817495755985104766e-02, /* 0xBF9D2A51, 0xDBD7194F */ -pp3 = -5.77027029648944159157e-03, /* 0xBF77A291, 0x236668E4 */ -pp4 = -2.37630166566501626084e-05, /* 0xBEF8EAD6, 0x120016AC */ -qq1 = 3.97917223959155352819e-01, /* 0x3FD97779, 0xCDDADC09 */ -qq2 = 6.50222499887672944485e-02, /* 0x3FB0A54C, 0x5536CEBA */ -qq3 = 5.08130628187576562776e-03, /* 0x3F74D022, 0xC4D36B0F */ -qq4 = 1.32494738004321644526e-04, /* 0x3F215DC9, 0x221C1A10 */ -qq5 = -3.96022827877536812320e-06, /* 0xBED09C43, 0x42A26120 */ -/* - * Coefficients for approximation to erf in [0.84375,1.25] - */ -pa0 = -2.36211856075265944077e-03, /* 0xBF6359B8, 0xBEF77538 */ -pa1 = 4.14856118683748331666e-01, /* 0x3FDA8D00, 0xAD92B34D */ -pa2 = -3.72207876035701323847e-01, /* 0xBFD7D240, 0xFBB8C3F1 */ -pa3 = 3.18346619901161753674e-01, /* 0x3FD45FCA, 0x805120E4 */ -pa4 = -1.10894694282396677476e-01, /* 0xBFBC6398, 0x3D3E28EC */ -pa5 = 3.54783043256182359371e-02, /* 0x3FA22A36, 0x599795EB */ -pa6 = -2.16637559486879084300e-03, /* 0xBF61BF38, 0x0A96073F */ -qa1 = 1.06420880400844228286e-01, /* 0x3FBB3E66, 0x18EEE323 */ -qa2 = 5.40397917702171048937e-01, /* 0x3FE14AF0, 0x92EB6F33 */ -qa3 = 7.18286544141962662868e-02, /* 0x3FB2635C, 0xD99FE9A7 */ -qa4 = 1.26171219808761642112e-01, /* 0x3FC02660, 0xE763351F */ -qa5 = 1.36370839120290507362e-02, /* 0x3F8BEDC2, 0x6B51DD1C */ -qa6 = 1.19844998467991074170e-02, /* 0x3F888B54, 0x5735151D */ -/* - * Coefficients for approximation to erfc in [1.25,1/0.35] - */ -ra0 = -9.86494403484714822705e-03, /* 0xBF843412, 0x600D6435 */ -ra1 = -6.93858572707181764372e-01, /* 0xBFE63416, 0xE4BA7360 */ -ra2 = -1.05586262253232909814e+01, /* 0xC0251E04, 0x41B0E726 */ -ra3 = -6.23753324503260060396e+01, /* 0xC04F300A, 0xE4CBA38D */ -ra4 = -1.62396669462573470355e+02, /* 0xC0644CB1, 0x84282266 */ -ra5 = -1.84605092906711035994e+02, /* 0xC067135C, 0xEBCCABB2 */ -ra6 = -8.12874355063065934246e+01, /* 0xC0545265, 0x57E4D2F2 */ -ra7 = -9.81432934416914548592e+00, /* 0xC023A0EF, 0xC69AC25C */ -sa1 = 1.96512716674392571292e+01, /* 0x4033A6B9, 0xBD707687 */ -sa2 = 1.37657754143519042600e+02, /* 0x4061350C, 0x526AE721 */ -sa3 = 4.34565877475229228821e+02, /* 0x407B290D, 0xD58A1A71 */ -sa4 = 6.45387271733267880336e+02, /* 0x40842B19, 0x21EC2868 */ -sa5 = 4.29008140027567833386e+02, /* 0x407AD021, 0x57700314 */ -sa6 = 1.08635005541779435134e+02, /* 0x405B28A3, 0xEE48AE2C */ -sa7 = 6.57024977031928170135e+00, /* 0x401A47EF, 0x8E484A93 */ -sa8 = -6.04244152148580987438e-02, /* 0xBFAEEFF2, 0xEE749A62 */ -/* - * Coefficients for approximation to erfc in [1/.35,28] - */ -rb0 = -9.86494292470009928597e-03, /* 0xBF843412, 0x39E86F4A */ -rb1 = -7.99283237680523006574e-01, /* 0xBFE993BA, 0x70C285DE */ -rb2 = -1.77579549177547519889e+01, /* 0xC031C209, 0x555F995A */ -rb3 = -1.60636384855821916062e+02, /* 0xC064145D, 0x43C5ED98 */ -rb4 = -6.37566443368389627722e+02, /* 0xC083EC88, 0x1375F228 */ -rb5 = -1.02509513161107724954e+03, /* 0xC0900461, 0x6A2E5992 */ -rb6 = -4.83519191608651397019e+02, /* 0xC07E384E, 0x9BDC383F */ -sb1 = 3.03380607434824582924e+01, /* 0x403E568B, 0x261D5190 */ -sb2 = 3.25792512996573918826e+02, /* 0x40745CAE, 0x221B9F0A */ -sb3 = 1.53672958608443695994e+03, /* 0x409802EB, 0x189D5118 */ -sb4 = 3.19985821950859553908e+03, /* 0x40A8FFB7, 0x688C246A */ -sb5 = 2.55305040643316442583e+03, /* 0x40A3F219, 0xCEDF3BE6 */ -sb6 = 4.74528541206955367215e+02, /* 0x407DA874, 0xE79FE763 */ -sb7 = -2.24409524465858183362e+01; /* 0xC03670E2, 0x42712D62 */ - -double -erf(double x) -{ - int32_t hx,ix,i; - double R,S,P,Q,s,y,z,r; - GET_HIGH_WORD(hx,x); - ix = hx&0x7fffffff; - if(ix>=0x7ff00000) { /* erf(nan)=nan */ - i = ((uint32_t)hx>>31)<<1; - return (double)(1-i)+one/x; /* erf(+-inf)=+-1 */ - } - - if(ix < 0x3feb0000) { /* |x|<0.84375 */ - if(ix < 0x3e300000) { /* |x|<2**-28 */ - if (ix < 0x00800000) - return 0.125*(8.0*x+efx8*x); /*avoid underflow */ - return x + efx*x; - } - z = x*x; - r = pp0+z*(pp1+z*(pp2+z*(pp3+z*pp4))); - s = one+z*(qq1+z*(qq2+z*(qq3+z*(qq4+z*qq5)))); - y = r/s; - return x + x*y; - } - if(ix < 0x3ff40000) { /* 0.84375 <= |x| < 1.25 */ - s = fabs(x)-one; - P = pa0+s*(pa1+s*(pa2+s*(pa3+s*(pa4+s*(pa5+s*pa6))))); - Q = one+s*(qa1+s*(qa2+s*(qa3+s*(qa4+s*(qa5+s*qa6))))); - if(hx>=0) return erx + P/Q; else return -erx - P/Q; - } - if (ix >= 0x40180000) { /* inf>|x|>=6 */ - if(hx>=0) return one-tiny; else return tiny-one; - } - x = fabs(x); - s = one/(x*x); - if(ix< 0x4006DB6E) { /* |x| < 1/0.35 */ - R=ra0+s*(ra1+s*(ra2+s*(ra3+s*(ra4+s*( - ra5+s*(ra6+s*ra7)))))); - S=one+s*(sa1+s*(sa2+s*(sa3+s*(sa4+s*( - sa5+s*(sa6+s*(sa7+s*sa8))))))); - } else { /* |x| >= 1/0.35 */ - R=rb0+s*(rb1+s*(rb2+s*(rb3+s*(rb4+s*( - rb5+s*rb6))))); - S=one+s*(sb1+s*(sb2+s*(sb3+s*(sb4+s*( - sb5+s*(sb6+s*sb7)))))); - } - z = x; - SET_LOW_WORD(z,0); - r = exp(-z*z-0.5625)*exp((z-x)*(z+x)+R/S); - if(hx>=0) return one-r/x; else return r/x-one; -} - -double -erfc(double x) -{ - int32_t hx,ix; - double R,S,P,Q,s,y,z,r; - GET_HIGH_WORD(hx,x); - ix = hx&0x7fffffff; - if(ix>=0x7ff00000) { /* erfc(nan)=nan */ - /* erfc(+-inf)=0,2 */ - return (double)(((uint32_t)hx>>31)<<1)+one/x; - } - - if(ix < 0x3feb0000) { /* |x|<0.84375 */ - if(ix < 0x3c700000) /* |x|<2**-56 */ - return one-x; - z = x*x; - r = pp0+z*(pp1+z*(pp2+z*(pp3+z*pp4))); - s = one+z*(qq1+z*(qq2+z*(qq3+z*(qq4+z*qq5)))); - y = r/s; - if(hx < 0x3fd00000) { /* x<1/4 */ - return one-(x+x*y); - } else { - r = x*y; - r += (x-half); - return half - r ; - } - } - if(ix < 0x3ff40000) { /* 0.84375 <= |x| < 1.25 */ - s = fabs(x)-one; - P = pa0+s*(pa1+s*(pa2+s*(pa3+s*(pa4+s*(pa5+s*pa6))))); - Q = one+s*(qa1+s*(qa2+s*(qa3+s*(qa4+s*(qa5+s*qa6))))); - if(hx>=0) { - z = one-erx; return z - P/Q; - } else { - z = erx+P/Q; return one+z; - } - } - if (ix < 0x403c0000) { /* |x|<28 */ - x = fabs(x); - s = one/(x*x); - if(ix< 0x4006DB6D) { /* |x| < 1/.35 ~ 2.857143*/ - R=ra0+s*(ra1+s*(ra2+s*(ra3+s*(ra4+s*( - ra5+s*(ra6+s*ra7)))))); - S=one+s*(sa1+s*(sa2+s*(sa3+s*(sa4+s*( - sa5+s*(sa6+s*(sa7+s*sa8))))))); - } else { /* |x| >= 1/.35 ~ 2.857143 */ - if(hx<0&&ix>=0x40180000) return two-tiny;/* x < -6 */ - R=rb0+s*(rb1+s*(rb2+s*(rb3+s*(rb4+s*( - rb5+s*rb6))))); - S=one+s*(sb1+s*(sb2+s*(sb3+s*(sb4+s*( - sb5+s*(sb6+s*sb7)))))); - } - z = x; - SET_LOW_WORD(z,0); - r = exp(-z*z-0.5625)* - exp((z-x)*(z+x)+R/S); - if(hx>0) return r/x; else return two-r/x; - } else { - if(hx>0) return tiny*tiny; else return two-tiny; - } -} diff --git a/05/musl-final/src/math/s_erff.c b/05/musl-final/src/math/s_erff.c deleted file mode 100644 index 28e2f7b..0000000 --- a/05/musl-final/src/math/s_erff.c +++ /dev/null @@ -1,207 +0,0 @@ -/* s_erff.c -- float version of s_erf.c. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include -#include "math_private.h" - -static const float -tiny = 1e-30, -half= 5.0000000000e-01, /* 0x3F000000 */ -one = 1.0000000000e+00, /* 0x3F800000 */ -two = 2.0000000000e+00, /* 0x40000000 */ - /* c = (subfloat)0.84506291151 */ -erx = 8.4506291151e-01, /* 0x3f58560b */ -/* - * Coefficients for approximation to erf on [0,0.84375] - */ -efx = 1.2837916613e-01, /* 0x3e0375d4 */ -efx8= 1.0270333290e+00, /* 0x3f8375d4 */ -pp0 = 1.2837916613e-01, /* 0x3e0375d4 */ -pp1 = -3.2504209876e-01, /* 0xbea66beb */ -pp2 = -2.8481749818e-02, /* 0xbce9528f */ -pp3 = -5.7702702470e-03, /* 0xbbbd1489 */ -pp4 = -2.3763017452e-05, /* 0xb7c756b1 */ -qq1 = 3.9791721106e-01, /* 0x3ecbbbce */ -qq2 = 6.5022252500e-02, /* 0x3d852a63 */ -qq3 = 5.0813062117e-03, /* 0x3ba68116 */ -qq4 = 1.3249473704e-04, /* 0x390aee49 */ -qq5 = -3.9602282413e-06, /* 0xb684e21a */ -/* - * Coefficients for approximation to erf in [0.84375,1.25] - */ -pa0 = -2.3621185683e-03, /* 0xbb1acdc6 */ -pa1 = 4.1485610604e-01, /* 0x3ed46805 */ -pa2 = -3.7220788002e-01, /* 0xbebe9208 */ -pa3 = 3.1834661961e-01, /* 0x3ea2fe54 */ -pa4 = -1.1089469492e-01, /* 0xbde31cc2 */ -pa5 = 3.5478305072e-02, /* 0x3d1151b3 */ -pa6 = -2.1663755178e-03, /* 0xbb0df9c0 */ -qa1 = 1.0642088205e-01, /* 0x3dd9f331 */ -qa2 = 5.4039794207e-01, /* 0x3f0a5785 */ -qa3 = 7.1828655899e-02, /* 0x3d931ae7 */ -qa4 = 1.2617121637e-01, /* 0x3e013307 */ -qa5 = 1.3637083583e-02, /* 0x3c5f6e13 */ -qa6 = 1.1984500103e-02, /* 0x3c445aa3 */ -/* - * Coefficients for approximation to erfc in [1.25,1/0.35] - */ -ra0 = -9.8649440333e-03, /* 0xbc21a093 */ -ra1 = -6.9385856390e-01, /* 0xbf31a0b7 */ -ra2 = -1.0558626175e+01, /* 0xc128f022 */ -ra3 = -6.2375331879e+01, /* 0xc2798057 */ -ra4 = -1.6239666748e+02, /* 0xc322658c */ -ra5 = -1.8460508728e+02, /* 0xc3389ae7 */ -ra6 = -8.1287437439e+01, /* 0xc2a2932b */ -ra7 = -9.8143291473e+00, /* 0xc11d077e */ -sa1 = 1.9651271820e+01, /* 0x419d35ce */ -sa2 = 1.3765776062e+02, /* 0x4309a863 */ -sa3 = 4.3456588745e+02, /* 0x43d9486f */ -sa4 = 6.4538726807e+02, /* 0x442158c9 */ -sa5 = 4.2900814819e+02, /* 0x43d6810b */ -sa6 = 1.0863500214e+02, /* 0x42d9451f */ -sa7 = 6.5702495575e+00, /* 0x40d23f7c */ -sa8 = -6.0424413532e-02, /* 0xbd777f97 */ -/* - * Coefficients for approximation to erfc in [1/.35,28] - */ -rb0 = -9.8649431020e-03, /* 0xbc21a092 */ -rb1 = -7.9928326607e-01, /* 0xbf4c9dd4 */ -rb2 = -1.7757955551e+01, /* 0xc18e104b */ -rb3 = -1.6063638306e+02, /* 0xc320a2ea */ -rb4 = -6.3756646729e+02, /* 0xc41f6441 */ -rb5 = -1.0250950928e+03, /* 0xc480230b */ -rb6 = -4.8351919556e+02, /* 0xc3f1c275 */ -sb1 = 3.0338060379e+01, /* 0x41f2b459 */ -sb2 = 3.2579251099e+02, /* 0x43a2e571 */ -sb3 = 1.5367296143e+03, /* 0x44c01759 */ -sb4 = 3.1998581543e+03, /* 0x4547fdbb */ -sb5 = 2.5530502930e+03, /* 0x451f90ce */ -sb6 = 4.7452853394e+02, /* 0x43ed43a7 */ -sb7 = -2.2440952301e+01; /* 0xc1b38712 */ - -float -erff(float x) -{ - int32_t hx,ix,i; - float R,S,P,Q,s,y,z,r; - GET_FLOAT_WORD(hx,x); - ix = hx&0x7fffffff; - if(ix>=0x7f800000) { /* erf(nan)=nan */ - i = ((uint32_t)hx>>31)<<1; - return (float)(1-i)+one/x; /* erf(+-inf)=+-1 */ - } - - if(ix < 0x3f580000) { /* |x|<0.84375 */ - if(ix < 0x31800000) { /* |x|<2**-28 */ - if (ix < 0x04000000) - /*avoid underflow */ - return (float)0.125*((float)8.0*x+efx8*x); - return x + efx*x; - } - z = x*x; - r = pp0+z*(pp1+z*(pp2+z*(pp3+z*pp4))); - s = one+z*(qq1+z*(qq2+z*(qq3+z*(qq4+z*qq5)))); - y = r/s; - return x + x*y; - } - if(ix < 0x3fa00000) { /* 0.84375 <= |x| < 1.25 */ - s = fabsf(x)-one; - P = pa0+s*(pa1+s*(pa2+s*(pa3+s*(pa4+s*(pa5+s*pa6))))); - Q = one+s*(qa1+s*(qa2+s*(qa3+s*(qa4+s*(qa5+s*qa6))))); - if(hx>=0) return erx + P/Q; else return -erx - P/Q; - } - if (ix >= 0x40c00000) { /* inf>|x|>=6 */ - if(hx>=0) return one-tiny; else return tiny-one; - } - x = fabsf(x); - s = one/(x*x); - if(ix< 0x4036DB6E) { /* |x| < 1/0.35 */ - R=ra0+s*(ra1+s*(ra2+s*(ra3+s*(ra4+s*( - ra5+s*(ra6+s*ra7)))))); - S=one+s*(sa1+s*(sa2+s*(sa3+s*(sa4+s*( - sa5+s*(sa6+s*(sa7+s*sa8))))))); - } else { /* |x| >= 1/0.35 */ - R=rb0+s*(rb1+s*(rb2+s*(rb3+s*(rb4+s*( - rb5+s*rb6))))); - S=one+s*(sb1+s*(sb2+s*(sb3+s*(sb4+s*( - sb5+s*(sb6+s*sb7)))))); - } - GET_FLOAT_WORD(ix,x); - SET_FLOAT_WORD(z,ix&0xfffff000); - r = expf(-z*z-(float)0.5625)*expf((z-x)*(z+x)+R/S); - if(hx>=0) return one-r/x; else return r/x-one; -} - -float -erfcf(float x) -{ - int32_t hx,ix; - float R,S,P,Q,s,y,z,r; - GET_FLOAT_WORD(hx,x); - ix = hx&0x7fffffff; - if(ix>=0x7f800000) { /* erfc(nan)=nan */ - /* erfc(+-inf)=0,2 */ - return (float)(((uint32_t)hx>>31)<<1)+one/x; - } - - if(ix < 0x3f580000) { /* |x|<0.84375 */ - if(ix < 0x23800000) /* |x|<2**-56 */ - return one-x; - z = x*x; - r = pp0+z*(pp1+z*(pp2+z*(pp3+z*pp4))); - s = one+z*(qq1+z*(qq2+z*(qq3+z*(qq4+z*qq5)))); - y = r/s; - if(hx < 0x3e800000) { /* x<1/4 */ - return one-(x+x*y); - } else { - r = x*y; - r += (x-half); - return half - r ; - } - } - if(ix < 0x3fa00000) { /* 0.84375 <= |x| < 1.25 */ - s = fabsf(x)-one; - P = pa0+s*(pa1+s*(pa2+s*(pa3+s*(pa4+s*(pa5+s*pa6))))); - Q = one+s*(qa1+s*(qa2+s*(qa3+s*(qa4+s*(qa5+s*qa6))))); - if(hx>=0) { - z = one-erx; return z - P/Q; - } else { - z = erx+P/Q; return one+z; - } - } - if (ix < 0x41e00000) { /* |x|<28 */ - x = fabsf(x); - s = one/(x*x); - if(ix< 0x4036DB6D) { /* |x| < 1/.35 ~ 2.857143*/ - R=ra0+s*(ra1+s*(ra2+s*(ra3+s*(ra4+s*( - ra5+s*(ra6+s*ra7)))))); - S=one+s*(sa1+s*(sa2+s*(sa3+s*(sa4+s*( - sa5+s*(sa6+s*(sa7+s*sa8))))))); - } else { /* |x| >= 1/.35 ~ 2.857143 */ - if(hx<0&&ix>=0x40c00000) return two-tiny;/* x < -6 */ - R=rb0+s*(rb1+s*(rb2+s*(rb3+s*(rb4+s*( - rb5+s*rb6))))); - S=one+s*(sb1+s*(sb2+s*(sb3+s*(sb4+s*( - sb5+s*(sb6+s*sb7)))))); - } - GET_FLOAT_WORD(ix,x); - SET_FLOAT_WORD(z,ix&0xfffff000); - r = expf(-z*z-(float)0.5625)* - expf((z-x)*(z+x)+R/S); - if(hx>0) return r/x; else return two-r/x; - } else { - if(hx>0) return tiny*tiny; else return two-tiny; - } -} diff --git a/05/musl-final/src/math/s_expm1.c b/05/musl-final/src/math/s_expm1.c deleted file mode 100644 index 6f1f667..0000000 --- a/05/musl-final/src/math/s_expm1.c +++ /dev/null @@ -1,217 +0,0 @@ -/* @(#)s_expm1.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* expm1(x) - * Returns exp(x)-1, the exponential of x minus 1. - * - * Method - * 1. Argument reduction: - * Given x, find r and integer k such that - * - * x = k*ln2 + r, |r| <= 0.5*ln2 ~ 0.34658 - * - * Here a correction term c will be computed to compensate - * the error in r when rounded to a floating-point number. - * - * 2. Approximating expm1(r) by a special rational function on - * the interval [0,0.34658]: - * Since - * r*(exp(r)+1)/(exp(r)-1) = 2+ r^2/6 - r^4/360 + ... - * we define R1(r*r) by - * r*(exp(r)+1)/(exp(r)-1) = 2+ r^2/6 * R1(r*r) - * That is, - * R1(r**2) = 6/r *((exp(r)+1)/(exp(r)-1) - 2/r) - * = 6/r * ( 1 + 2.0*(1/(exp(r)-1) - 1/r)) - * = 1 - r^2/60 + r^4/2520 - r^6/100800 + ... - * We use a special Reme algorithm on [0,0.347] to generate - * a polynomial of degree 5 in r*r to approximate R1. The - * maximum error of this polynomial approximation is bounded - * by 2**-61. In other words, - * R1(z) ~ 1.0 + Q1*z + Q2*z**2 + Q3*z**3 + Q4*z**4 + Q5*z**5 - * where Q1 = -1.6666666666666567384E-2, - * Q2 = 3.9682539681370365873E-4, - * Q3 = -9.9206344733435987357E-6, - * Q4 = 2.5051361420808517002E-7, - * Q5 = -6.2843505682382617102E-9; - * (where z=r*r, and the values of Q1 to Q5 are listed below) - * with error bounded by - * | 5 | -61 - * | 1.0+Q1*z+...+Q5*z - R1(z) | <= 2 - * | | - * - * expm1(r) = exp(r)-1 is then computed by the following - * specific way which minimize the accumulation rounding error: - * 2 3 - * r r [ 3 - (R1 + R1*r/2) ] - * expm1(r) = r + --- + --- * [--------------------] - * 2 2 [ 6 - r*(3 - R1*r/2) ] - * - * To compensate the error in the argument reduction, we use - * expm1(r+c) = expm1(r) + c + expm1(r)*c - * ~ expm1(r) + c + r*c - * Thus c+r*c will be added in as the correction terms for - * expm1(r+c). Now rearrange the term to avoid optimization - * screw up: - * ( 2 2 ) - * ({ ( r [ R1 - (3 - R1*r/2) ] ) } r ) - * expm1(r+c)~r - ({r*(--- * [--------------------]-c)-c} - --- ) - * ({ ( 2 [ 6 - r*(3 - R1*r/2) ] ) } 2 ) - * ( ) - * - * = r - E - * 3. Scale back to obtain expm1(x): - * From step 1, we have - * expm1(x) = either 2^k*[expm1(r)+1] - 1 - * = or 2^k*[expm1(r) + (1-2^-k)] - * 4. Implementation notes: - * (A). To save one multiplication, we scale the coefficient Qi - * to Qi*2^i, and replace z by (x^2)/2. - * (B). To achieve maximum accuracy, we compute expm1(x) by - * (i) if x < -56*ln2, return -1.0, (raise inexact if x!=inf) - * (ii) if k=0, return r-E - * (iii) if k=-1, return 0.5*(r-E)-0.5 - * (iv) if k=1 if r < -0.25, return 2*((r+0.5)- E) - * else return 1.0+2.0*(r-E); - * (v) if (k<-2||k>56) return 2^k(1-(E-r)) - 1 (or exp(x)-1) - * (vi) if k <= 20, return 2^k((1-2^-k)-(E-r)), else - * (vii) return 2^k(1-((E+2^-k)-r)) - * - * Special cases: - * expm1(INF) is INF, expm1(NaN) is NaN; - * expm1(-INF) is -1, and - * for finite argument, only expm1(0)=0 is exact. - * - * Accuracy: - * according to an error analysis, the error is always less than - * 1 ulp (unit in the last place). - * - * Misc. info. - * For IEEE double - * if x > 7.09782712893383973096e+02 then expm1(x) overflow - * - * Constants: - * The hexadecimal values are the intended ones for the following - * constants. The decimal values may be used, provided that the - * compiler will convert from decimal to binary accurately enough - * to produce the hexadecimal values shown. - */ - -#include -#include "math_private.h" - -static const double -one = 1.0, -huge = 1.0e+300, -tiny = 1.0e-300, -o_threshold = 7.09782712893383973096e+02,/* 0x40862E42, 0xFEFA39EF */ -ln2_hi = 6.93147180369123816490e-01,/* 0x3fe62e42, 0xfee00000 */ -ln2_lo = 1.90821492927058770002e-10,/* 0x3dea39ef, 0x35793c76 */ -invln2 = 1.44269504088896338700e+00,/* 0x3ff71547, 0x652b82fe */ - /* scaled coefficients related to expm1 */ -Q1 = -3.33333333333331316428e-02, /* BFA11111 111110F4 */ -Q2 = 1.58730158725481460165e-03, /* 3F5A01A0 19FE5585 */ -Q3 = -7.93650757867487942473e-05, /* BF14CE19 9EAADBB7 */ -Q4 = 4.00821782732936239552e-06, /* 3ED0CFCA 86E65239 */ -Q5 = -2.01099218183624371326e-07; /* BE8AFDB7 6E09C32D */ - -double -expm1(double x) -{ - double y,hi,lo,c=0.0,t,e,hxs,hfx,r1; - int32_t k,xsb; - uint32_t hx; - - GET_HIGH_WORD(hx,x); - xsb = hx&0x80000000; /* sign bit of x */ - if(xsb==0) y=x; else y= -x; /* y = |x| */ - hx &= 0x7fffffff; /* high word of |x| */ - - /* filter out huge and non-finite argument */ - if(hx >= 0x4043687A) { /* if |x|>=56*ln2 */ - if(hx >= 0x40862E42) { /* if |x|>=709.78... */ - if(hx>=0x7ff00000) { - uint32_t low; - GET_LOW_WORD(low,x); - if(((hx&0xfffff)|low)!=0) - return x+x; /* NaN */ - else return (xsb==0)? x:-1.0;/* exp(+-inf)={inf,-1} */ - } - if(x > o_threshold) return huge*huge; /* overflow */ - } - if(xsb!=0) { /* x < -56*ln2, return -1.0 with inexact */ - if(x+tiny<0.0) /* raise inexact */ - return tiny-one; /* return -1 */ - } - } - - /* argument reduction */ - if(hx > 0x3fd62e42) { /* if |x| > 0.5 ln2 */ - if(hx < 0x3FF0A2B2) { /* and |x| < 1.5 ln2 */ - if(xsb==0) - {hi = x - ln2_hi; lo = ln2_lo; k = 1;} - else - {hi = x + ln2_hi; lo = -ln2_lo; k = -1;} - } else { - k = invln2*x+((xsb==0)?0.5:-0.5); - t = k; - hi = x - t*ln2_hi; /* t*ln2_hi is exact here */ - lo = t*ln2_lo; - } - x = hi - lo; - c = (hi-x)-lo; - } - else if(hx < 0x3c900000) { /* when |x|<2**-54, return x */ - t = huge+x; /* return x with inexact flags when x!=0 */ - return x - (t-(huge+x)); - } - else k = 0; - - /* x is now in primary range */ - hfx = 0.5*x; - hxs = x*hfx; - r1 = one+hxs*(Q1+hxs*(Q2+hxs*(Q3+hxs*(Q4+hxs*Q5)))); - t = 3.0-r1*hfx; - e = hxs*((r1-t)/(6.0 - x*t)); - if(k==0) return x - (x*e-hxs); /* c is 0 */ - else { - e = (x*(e-c)-c); - e -= hxs; - if(k== -1) return 0.5*(x-e)-0.5; - if(k==1) { - if(x < -0.25) return -2.0*(e-(x+0.5)); - else return one+2.0*(x-e); - } - if (k <= -2 || k>56) { /* suffice to return exp(x)-1 */ - uint32_t high; - y = one-(e-x); - GET_HIGH_WORD(high,y); - SET_HIGH_WORD(y,high+(k<<20)); /* add k to y's exponent */ - return y-one; - } - t = one; - if(k<20) { - uint32_t high; - SET_HIGH_WORD(t,0x3ff00000 - (0x200000>>k)); /* t=1-2^-k */ - y = t-(e-x); - GET_HIGH_WORD(high,y); - SET_HIGH_WORD(y,high+(k<<20)); /* add k to y's exponent */ - } else { - uint32_t high; - SET_HIGH_WORD(t,((0x3ff-k)<<20)); /* 2^-k */ - y = x-(e+t); - y += one; - GET_HIGH_WORD(high,y); - SET_HIGH_WORD(y,high+(k<<20)); /* add k to y's exponent */ - } - } - return y; -} diff --git a/05/musl-final/src/math/s_expm1f.c b/05/musl-final/src/math/s_expm1f.c deleted file mode 100644 index b22cf0f..0000000 --- a/05/musl-final/src/math/s_expm1f.c +++ /dev/null @@ -1,122 +0,0 @@ -/* s_expm1f.c -- float version of s_expm1.c. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include -#include "math_private.h" - -static const float -one = 1.0, -huge = 1.0e+30, -tiny = 1.0e-30, -o_threshold = 8.8721679688e+01,/* 0x42b17180 */ -ln2_hi = 6.9313812256e-01,/* 0x3f317180 */ -ln2_lo = 9.0580006145e-06,/* 0x3717f7d1 */ -invln2 = 1.4426950216e+00,/* 0x3fb8aa3b */ - /* scaled coefficients related to expm1 */ -Q1 = -3.3333335072e-02, /* 0xbd088889 */ -Q2 = 1.5873016091e-03, /* 0x3ad00d01 */ -Q3 = -7.9365076090e-05, /* 0xb8a670cd */ -Q4 = 4.0082177293e-06, /* 0x36867e54 */ -Q5 = -2.0109921195e-07; /* 0xb457edbb */ - -float -expm1f(float x) -{ - float y,hi,lo,c=0.0,t,e,hxs,hfx,r1; - int32_t k,xsb; - uint32_t hx; - - GET_FLOAT_WORD(hx,x); - xsb = hx&0x80000000; /* sign bit of x */ - if(xsb==0) y=x; else y= -x; /* y = |x| */ - hx &= 0x7fffffff; /* high word of |x| */ - - /* filter out huge and non-finite argument */ - if(hx >= 0x4195b844) { /* if |x|>=27*ln2 */ - if(hx >= 0x42b17218) { /* if |x|>=88.721... */ - if(hx>0x7f800000) - return x+x; /* NaN */ - if(hx==0x7f800000) - return (xsb==0)? x:-1.0;/* exp(+-inf)={inf,-1} */ - if(x > o_threshold) return huge*huge; /* overflow */ - } - if(xsb!=0) { /* x < -27*ln2, return -1.0 with inexact */ - if(x+tiny<(float)0.0) /* raise inexact */ - return tiny-one; /* return -1 */ - } - } - - /* argument reduction */ - if(hx > 0x3eb17218) { /* if |x| > 0.5 ln2 */ - if(hx < 0x3F851592) { /* and |x| < 1.5 ln2 */ - if(xsb==0) - {hi = x - ln2_hi; lo = ln2_lo; k = 1;} - else - {hi = x + ln2_hi; lo = -ln2_lo; k = -1;} - } else { - k = invln2*x+((xsb==0)?(float)0.5:(float)-0.5); - t = k; - hi = x - t*ln2_hi; /* t*ln2_hi is exact here */ - lo = t*ln2_lo; - } - x = hi - lo; - c = (hi-x)-lo; - } - else if(hx < 0x33000000) { /* when |x|<2**-25, return x */ - t = huge+x; /* return x with inexact flags when x!=0 */ - return x - (t-(huge+x)); - } - else k = 0; - - /* x is now in primary range */ - hfx = (float)0.5*x; - hxs = x*hfx; - r1 = one+hxs*(Q1+hxs*(Q2+hxs*(Q3+hxs*(Q4+hxs*Q5)))); - t = (float)3.0-r1*hfx; - e = hxs*((r1-t)/((float)6.0 - x*t)); - if(k==0) return x - (x*e-hxs); /* c is 0 */ - else { - e = (x*(e-c)-c); - e -= hxs; - if(k== -1) return (float)0.5*(x-e)-(float)0.5; - if(k==1) { - if(x < (float)-0.25) return -(float)2.0*(e-(x+(float)0.5)); - else return one+(float)2.0*(x-e); - } - if (k <= -2 || k>56) { /* suffice to return exp(x)-1 */ - int32_t i; - y = one-(e-x); - GET_FLOAT_WORD(i,y); - SET_FLOAT_WORD(y,i+(k<<23)); /* add k to y's exponent */ - return y-one; - } - t = one; - if(k<23) { - int32_t i; - SET_FLOAT_WORD(t,0x3f800000 - (0x1000000>>k)); /* t=1-2^-k */ - y = t-(e-x); - GET_FLOAT_WORD(i,y); - SET_FLOAT_WORD(y,i+(k<<23)); /* add k to y's exponent */ - } else { - int32_t i; - SET_FLOAT_WORD(t,((0x7f-k)<<23)); /* 2^-k */ - y = x-(e+t); - y += one; - GET_FLOAT_WORD(i,y); - SET_FLOAT_WORD(y,i+(k<<23)); /* add k to y's exponent */ - } - } - return y; -} diff --git a/05/musl-final/src/math/s_fabs.c b/05/musl-final/src/math/s_fabs.c deleted file mode 100644 index 7443325..0000000 --- a/05/musl-final/src/math/s_fabs.c +++ /dev/null @@ -1,27 +0,0 @@ -/* @(#)s_fabs.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* - * fabs(x) returns the absolute value of x. - */ - -#include -#include "math_private.h" - -double -fabs(double x) -{ - uint32_t high; - GET_HIGH_WORD(high,x); - SET_HIGH_WORD(x,high&0x7fffffff); - return x; -} diff --git a/05/musl-final/src/math/s_fabsf.c b/05/musl-final/src/math/s_fabsf.c deleted file mode 100644 index 655d57d..0000000 --- a/05/musl-final/src/math/s_fabsf.c +++ /dev/null @@ -1,30 +0,0 @@ -/* s_fabsf.c -- float version of s_fabs.c. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* - * fabsf(x) returns the absolute value of x. - */ - -#include -#include "math_private.h" - -float -fabsf(float x) -{ - uint32_t ix; - GET_FLOAT_WORD(ix,x); - SET_FLOAT_WORD(x,ix&0x7fffffff); - return x; -} diff --git a/05/musl-final/src/math/s_floor.c b/05/musl-final/src/math/s_floor.c deleted file mode 100644 index 273cf6f..0000000 --- a/05/musl-final/src/math/s_floor.c +++ /dev/null @@ -1,69 +0,0 @@ -/* @(#)s_floor.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* - * floor(x) - * Return x rounded toward -inf to integral value - * Method: - * Bit twiddling. - * Exception: - * Inexact flag raised if x not equal to floor(x). - */ - -#include -#include "math_private.h" - -static const double huge = 1.0e300; - -double -floor(double x) -{ - int32_t i0,i1,j0; - uint32_t i,j; - EXTRACT_WORDS(i0,i1,x); - j0 = ((i0>>20)&0x7ff)-0x3ff; - if(j0<20) { - if(j0<0) { /* raise inexact if x != 0 */ - if(huge+x>0.0) {/* return 0*sign(x) if |x|<1 */ - if(i0>=0) {i0=i1=0;} - else if(((i0&0x7fffffff)|i1)!=0) - { i0=0xbff00000;i1=0;} - } - } else { - i = (0x000fffff)>>j0; - if(((i0&i)|i1)==0) return x; /* x is integral */ - if(huge+x>0.0) { /* raise inexact flag */ - if(i0<0) i0 += (0x00100000)>>j0; - i0 &= (~i); i1=0; - } - } - } else if (j0>51) { - if(j0==0x400) return x+x; /* inf or NaN */ - else return x; /* x is integral */ - } else { - i = ((uint32_t)(0xffffffff))>>(j0-20); - if((i1&i)==0) return x; /* x is integral */ - if(huge+x>0.0) { /* raise inexact flag */ - if(i0<0) { - if(j0==20) i0+=1; - else { - j = i1+(1<<(52-j0)); - if(j -#include "math_private.h" - -static const float huge = 1.0e30; - -float -floorf(float x) -{ - int32_t i0,j0; - uint32_t i; - GET_FLOAT_WORD(i0,x); - j0 = ((i0>>23)&0xff)-0x7f; - if(j0<23) { - if(j0<0) { /* raise inexact if x != 0 */ - if(huge+x>(float)0.0) {/* return 0*sign(x) if |x|<1 */ - if(i0>=0) {i0=0;} - else if((i0&0x7fffffff)!=0) - { i0=0xbf800000;} - } - } else { - i = (0x007fffff)>>j0; - if((i0&i)==0) return x; /* x is integral */ - if(huge+x>(float)0.0) { /* raise inexact flag */ - if(i0<0) i0 += (0x00800000)>>j0; - i0 &= (~i); - } - } - } else { - if(j0==0x80) return x+x; /* inf or NaN */ - else return x; /* x is integral */ - } - SET_FLOAT_WORD(x,i0); - return x; -} diff --git a/05/musl-final/src/math/s_ilogb.c b/05/musl-final/src/math/s_ilogb.c deleted file mode 100644 index f1ac498..0000000 --- a/05/musl-final/src/math/s_ilogb.c +++ /dev/null @@ -1,45 +0,0 @@ -/* @(#)s_ilogb.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* ilogb(double x) - * return the binary exponent of non-zero x - * ilogb(0) = FP_ILOGB0 - * ilogb(NaN) = FP_ILOGBNAN (no signal is raised) - * ilogb(inf) = INT_MAX (no signal is raised) - */ - -#include - -#include -#include "math_private.h" - -int ilogb(double x) -{ - int32_t hx,lx,ix; - - EXTRACT_WORDS(hx,lx,x); - hx &= 0x7fffffff; - if(hx<0x00100000) { - if((hx|lx)==0) - return FP_ILOGB0; - else /* subnormal x */ - if(hx==0) { - for (ix = -1043; lx>0; lx<<=1) ix -=1; - } else { - for (ix = -1022,hx<<=11; hx>0; hx<<=1) ix -=1; - } - return ix; - } - else if (hx<0x7ff00000) return (hx>>20)-1023; - else if (hx>0x7ff00000 || lx!=0) return FP_ILOGBNAN; - else return INT_MAX; -} diff --git a/05/musl-final/src/math/s_ilogbf.c b/05/musl-final/src/math/s_ilogbf.c deleted file mode 100644 index 30359fe..0000000 --- a/05/musl-final/src/math/s_ilogbf.c +++ /dev/null @@ -1,37 +0,0 @@ -/* s_ilogbf.c -- float version of s_ilogb.c. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include - -#include -#include "math_private.h" - -int ilogbf(float x) -{ - int32_t hx,ix; - - GET_FLOAT_WORD(hx,x); - hx &= 0x7fffffff; - if(hx<0x00800000) { - if(hx==0) - return FP_ILOGB0; - else /* subnormal x */ - for (ix = -126,hx<<=8; hx>0; hx<<=1) ix -=1; - return ix; - } - else if (hx<0x7f800000) return (hx>>23)-127; - else if (hx>0x7f800000) return FP_ILOGBNAN; - else return INT_MAX; -} diff --git a/05/musl-final/src/math/s_ldexp.c b/05/musl-final/src/math/s_ldexp.c deleted file mode 100644 index f4d1cd6..0000000 --- a/05/musl-final/src/math/s_ldexp.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -double ldexp(double x, int n) -{ - return scalbn(x, n); -} diff --git a/05/musl-final/src/math/s_ldexpf.c b/05/musl-final/src/math/s_ldexpf.c deleted file mode 100644 index 3bad5f3..0000000 --- a/05/musl-final/src/math/s_ldexpf.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -float ldexpf(float x, int n) -{ - return scalbnf(x, n); -} diff --git a/05/musl-final/src/math/s_llrint.c b/05/musl-final/src/math/s_llrint.c deleted file mode 100644 index 2b1e00d..0000000 --- a/05/musl-final/src/math/s_llrint.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -// FIXME: incorrect exception behavior - -long long llrint(double x) -{ - return rint(x); -} diff --git a/05/musl-final/src/math/s_log1p.c b/05/musl-final/src/math/s_log1p.c deleted file mode 100644 index 886d5ab..0000000 --- a/05/musl-final/src/math/s_log1p.c +++ /dev/null @@ -1,157 +0,0 @@ -/* @(#)s_log1p.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* double log1p(double x) - * - * Method : - * 1. Argument Reduction: find k and f such that - * 1+x = 2^k * (1+f), - * where sqrt(2)/2 < 1+f < sqrt(2) . - * - * Note. If k=0, then f=x is exact. However, if k!=0, then f - * may not be representable exactly. In that case, a correction - * term is need. Let u=1+x rounded. Let c = (1+x)-u, then - * log(1+x) - log(u) ~ c/u. Thus, we proceed to compute log(u), - * and add back the correction term c/u. - * (Note: when x > 2**53, one can simply return log(x)) - * - * 2. Approximation of log1p(f). - * Let s = f/(2+f) ; based on log(1+f) = log(1+s) - log(1-s) - * = 2s + 2/3 s**3 + 2/5 s**5 + ....., - * = 2s + s*R - * We use a special Reme algorithm on [0,0.1716] to generate - * a polynomial of degree 14 to approximate R The maximum error - * of this polynomial approximation is bounded by 2**-58.45. In - * other words, - * 2 4 6 8 10 12 14 - * R(z) ~ Lp1*s +Lp2*s +Lp3*s +Lp4*s +Lp5*s +Lp6*s +Lp7*s - * (the values of Lp1 to Lp7 are listed in the program) - * and - * | 2 14 | -58.45 - * | Lp1*s +...+Lp7*s - R(z) | <= 2 - * | | - * Note that 2s = f - s*f = f - hfsq + s*hfsq, where hfsq = f*f/2. - * In order to guarantee error in log below 1ulp, we compute log - * by - * log1p(f) = f - (hfsq - s*(hfsq+R)). - * - * 3. Finally, log1p(x) = k*ln2 + log1p(f). - * = k*ln2_hi+(f-(hfsq-(s*(hfsq+R)+k*ln2_lo))) - * Here ln2 is split into two floating point number: - * ln2_hi + ln2_lo, - * where n*ln2_hi is always exact for |n| < 2000. - * - * Special cases: - * log1p(x) is NaN with signal if x < -1 (including -INF) ; - * log1p(+INF) is +INF; log1p(-1) is -INF with signal; - * log1p(NaN) is that NaN with no signal. - * - * Accuracy: - * according to an error analysis, the error is always less than - * 1 ulp (unit in the last place). - * - * Constants: - * The hexadecimal values are the intended ones for the following - * constants. The decimal values may be used, provided that the - * compiler will convert from decimal to binary accurately enough - * to produce the hexadecimal values shown. - * - * Note: Assuming log() return accurate answer, the following - * algorithm can be used to compute log1p(x) to within a few ULP: - * - * u = 1+x; - * if(u==1.0) return x ; else - * return log(u)*(x/(u-1.0)); - * - * See HP-15C Advanced Functions Handbook, p.193. - */ - -#include -#include "math_private.h" - -static const double -ln2_hi = 6.93147180369123816490e-01, /* 3fe62e42 fee00000 */ -ln2_lo = 1.90821492927058770002e-10, /* 3dea39ef 35793c76 */ -two54 = 1.80143985094819840000e+16, /* 43500000 00000000 */ -Lp1 = 6.666666666666735130e-01, /* 3FE55555 55555593 */ -Lp2 = 3.999999999940941908e-01, /* 3FD99999 9997FA04 */ -Lp3 = 2.857142874366239149e-01, /* 3FD24924 94229359 */ -Lp4 = 2.222219843214978396e-01, /* 3FCC71C5 1D8E78AF */ -Lp5 = 1.818357216161805012e-01, /* 3FC74664 96CB03DE */ -Lp6 = 1.531383769920937332e-01, /* 3FC39A09 D078C69F */ -Lp7 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */ - -static const double zero = 0.0; - -double -log1p(double x) -{ - double hfsq,f=0,c=0,s,z,R,u; - int32_t k,hx,hu=0,ax; - - GET_HIGH_WORD(hx,x); - ax = hx&0x7fffffff; - - k = 1; - if (hx < 0x3FDA827A) { /* x < 0.41422 */ - if(ax>=0x3ff00000) { /* x <= -1.0 */ - if(x==-1.0) return -two54/zero; /* log1p(-1)=+inf */ - else return (x-x)/(x-x); /* log1p(x<-1)=NaN */ - } - if(ax<0x3e200000) { /* |x| < 2**-29 */ - if(two54+x>zero /* raise inexact */ - &&ax<0x3c900000) /* |x| < 2**-54 */ - return x; - else - return x - x*x*0.5; - } - if(hx>0||hx<=((int32_t)0xbfd2bec3)) { - k=0;f=x;hu=1;} /* -0.2929= 0x7ff00000) return x+x; - if(k!=0) { - if(hx<0x43400000) { - u = 1.0+x; - GET_HIGH_WORD(hu,u); - k = (hu>>20)-1023; - c = (k>0)? 1.0-(u-x):x-(u-1.0);/* correction term */ - c /= u; - } else { - u = x; - GET_HIGH_WORD(hu,u); - k = (hu>>20)-1023; - c = 0; - } - hu &= 0x000fffff; - if(hu<0x6a09e) { - SET_HIGH_WORD(u,hu|0x3ff00000); /* normalize u */ - } else { - k += 1; - SET_HIGH_WORD(u,hu|0x3fe00000); /* normalize u/2 */ - hu = (0x00100000-hu)>>2; - } - f = u-1.0; - } - hfsq=0.5*f*f; - if(hu==0) { /* |f| < 2**-20 */ - if(f==zero) { if(k==0) return zero; - else {c += k*ln2_lo; return k*ln2_hi+c;} } - R = hfsq*(1.0-0.66666666666666666*f); - if(k==0) return f-R; else - return k*ln2_hi-((R-(k*ln2_lo+c))-f); - } - s = f/(2.0+f); - z = s*s; - R = z*(Lp1+z*(Lp2+z*(Lp3+z*(Lp4+z*(Lp5+z*(Lp6+z*Lp7)))))); - if(k==0) return f-(hfsq-s*(hfsq+R)); else - return k*ln2_hi-((hfsq-(s*(hfsq+R)+(k*ln2_lo+c)))-f); -} diff --git a/05/musl-final/src/math/s_log1pf.c b/05/musl-final/src/math/s_log1pf.c deleted file mode 100644 index dcdd6bb..0000000 --- a/05/musl-final/src/math/s_log1pf.c +++ /dev/null @@ -1,96 +0,0 @@ -/* s_log1pf.c -- float version of s_log1p.c. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include -#include "math_private.h" - -static const float -ln2_hi = 6.9313812256e-01, /* 0x3f317180 */ -ln2_lo = 9.0580006145e-06, /* 0x3717f7d1 */ -two25 = 3.355443200e+07, /* 0x4c000000 */ -Lp1 = 6.6666668653e-01, /* 3F2AAAAB */ -Lp2 = 4.0000000596e-01, /* 3ECCCCCD */ -Lp3 = 2.8571429849e-01, /* 3E924925 */ -Lp4 = 2.2222198546e-01, /* 3E638E29 */ -Lp5 = 1.8183572590e-01, /* 3E3A3325 */ -Lp6 = 1.5313838422e-01, /* 3E1CD04F */ -Lp7 = 1.4798198640e-01; /* 3E178897 */ - -static const float zero = 0.0; - -float -log1pf(float x) -{ - float hfsq,f=0,c=0,s,z,R,u; - int32_t k,hx,hu=0,ax; - - GET_FLOAT_WORD(hx,x); - ax = hx&0x7fffffff; - - k = 1; - if (hx < 0x3ed413d7) { /* x < 0.41422 */ - if(ax>=0x3f800000) { /* x <= -1.0 */ - if(x==(float)-1.0) return -two25/zero; /* log1p(-1)=+inf */ - else return (x-x)/(x-x); /* log1p(x<-1)=NaN */ - } - if(ax<0x31000000) { /* |x| < 2**-29 */ - if(two25+x>zero /* raise inexact */ - &&ax<0x24800000) /* |x| < 2**-54 */ - return x; - else - return x - x*x*(float)0.5; - } - if(hx>0||hx<=((int32_t)0xbe95f61f)) { - k=0;f=x;hu=1;} /* -0.2929= 0x7f800000) return x+x; - if(k!=0) { - if(hx<0x5a000000) { - u = (float)1.0+x; - GET_FLOAT_WORD(hu,u); - k = (hu>>23)-127; - /* correction term */ - c = (k>0)? (float)1.0-(u-x):x-(u-(float)1.0); - c /= u; - } else { - u = x; - GET_FLOAT_WORD(hu,u); - k = (hu>>23)-127; - c = 0; - } - hu &= 0x007fffff; - if(hu<0x3504f7) { - SET_FLOAT_WORD(u,hu|0x3f800000);/* normalize u */ - } else { - k += 1; - SET_FLOAT_WORD(u,hu|0x3f000000); /* normalize u/2 */ - hu = (0x00800000-hu)>>2; - } - f = u-(float)1.0; - } - hfsq=(float)0.5*f*f; - if(hu==0) { /* |f| < 2**-20 */ - if(f==zero) { if(k==0) return zero; - else {c += k*ln2_lo; return k*ln2_hi+c;} } - R = hfsq*((float)1.0-(float)0.66666666666666666*f); - if(k==0) return f-R; else - return k*ln2_hi-((R-(k*ln2_lo+c))-f); - } - s = f/((float)2.0+f); - z = s*s; - R = z*(Lp1+z*(Lp2+z*(Lp3+z*(Lp4+z*(Lp5+z*(Lp6+z*Lp7)))))); - if(k==0) return f-(hfsq-s*(hfsq+R)); else - return k*ln2_hi-((hfsq-(s*(hfsq+R)+(k*ln2_lo+c)))-f); -} diff --git a/05/musl-final/src/math/s_logb.c b/05/musl-final/src/math/s_logb.c deleted file mode 100644 index be399c7..0000000 --- a/05/musl-final/src/math/s_logb.c +++ /dev/null @@ -1,34 +0,0 @@ -/* @(#)s_logb.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* - * double logb(x) - * IEEE 754 logb. Included to pass IEEE test suite. Not recommend. - * Use ilogb instead. - */ - -#include -#include "math_private.h" - -double -logb(double x) -{ - int32_t lx,ix; - EXTRACT_WORDS(ix,lx,x); - ix &= 0x7fffffff; /* high |x| */ - if((ix|lx)==0) return -1.0/fabs(x); - if(ix>=0x7ff00000) return x*x; - if((ix>>=20)==0) /* IEEE 754 logb */ - return -1022.0; - else - return (double) (ix-1023); -} diff --git a/05/musl-final/src/math/s_logbf.c b/05/musl-final/src/math/s_logbf.c deleted file mode 100644 index 747664d..0000000 --- a/05/musl-final/src/math/s_logbf.c +++ /dev/null @@ -1,31 +0,0 @@ -/* s_logbf.c -- float version of s_logb.c. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include -#include "math_private.h" - -float -logbf(float x) -{ - int32_t ix; - GET_FLOAT_WORD(ix,x); - ix &= 0x7fffffff; /* high |x| */ - if(ix==0) return (float)-1.0/fabsf(x); - if(ix>=0x7f800000) return x*x; - if((ix>>=23)==0) /* IEEE 754 logb */ - return -126.0; - else - return (float) (ix-127); -} diff --git a/05/musl-final/src/math/s_lrint.c b/05/musl-final/src/math/s_lrint.c deleted file mode 100644 index da8e198..0000000 --- a/05/musl-final/src/math/s_lrint.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -// FIXME: incorrect exception behavior - -long lrint(double x) -{ - return rint(x); -} diff --git a/05/musl-final/src/math/s_lrintf.c b/05/musl-final/src/math/s_lrintf.c deleted file mode 100644 index d0b469b..0000000 --- a/05/musl-final/src/math/s_lrintf.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -// FIXME: incorrect exception behavior - -long lrintf(float x) -{ - return rintf(x); -} diff --git a/05/musl-final/src/math/s_modf.c b/05/musl-final/src/math/s_modf.c deleted file mode 100644 index a5528d6..0000000 --- a/05/musl-final/src/math/s_modf.c +++ /dev/null @@ -1,71 +0,0 @@ -/* @(#)s_modf.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* - * modf(double x, double *iptr) - * return fraction part of x, and return x's integral part in *iptr. - * Method: - * Bit twiddling. - * - * Exception: - * No exception. - */ - -#include -#include "math_private.h" - -static const double one = 1.0; - -double -modf(double x, double *iptr) -{ - int32_t i0,i1,j0; - uint32_t i; - EXTRACT_WORDS(i0,i1,x); - j0 = ((i0>>20)&0x7ff)-0x3ff; /* exponent of x */ - if(j0<20) { /* integer part in high x */ - if(j0<0) { /* |x|<1 */ - INSERT_WORDS(*iptr,i0&0x80000000,0); /* *iptr = +-0 */ - return x; - } else { - i = (0x000fffff)>>j0; - if(((i0&i)|i1)==0) { /* x is integral */ - uint32_t high; - *iptr = x; - GET_HIGH_WORD(high,x); - INSERT_WORDS(x,high&0x80000000,0); /* return +-0 */ - return x; - } else { - INSERT_WORDS(*iptr,i0&(~i),0); - return x - *iptr; - } - } - } else if (j0>51) { /* no fraction part */ - uint32_t high; - *iptr = x*one; - GET_HIGH_WORD(high,x); - INSERT_WORDS(x,high&0x80000000,0); /* return +-0 */ - return x; - } else { /* fraction part in low x */ - i = ((uint32_t)(0xffffffff))>>(j0-20); - if((i1&i)==0) { /* x is integral */ - uint32_t high; - *iptr = x; - GET_HIGH_WORD(high,x); - INSERT_WORDS(x,high&0x80000000,0); /* return +-0 */ - return x; - } else { - INSERT_WORDS(*iptr,i0,i1&(~i)); - return x - *iptr; - } - } -} diff --git a/05/musl-final/src/math/s_modff.c b/05/musl-final/src/math/s_modff.c deleted file mode 100644 index de4dfd2..0000000 --- a/05/musl-final/src/math/s_modff.c +++ /dev/null @@ -1,52 +0,0 @@ -/* s_modff.c -- float version of s_modf.c. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include -#include "math_private.h" - -static const float one = 1.0; - -float -modff(float x, float *iptr) -{ - int32_t i0,j0; - uint32_t i; - GET_FLOAT_WORD(i0,x); - j0 = ((i0>>23)&0xff)-0x7f; /* exponent of x */ - if(j0<23) { /* integer part in x */ - if(j0<0) { /* |x|<1 */ - SET_FLOAT_WORD(*iptr,i0&0x80000000); /* *iptr = +-0 */ - return x; - } else { - i = (0x007fffff)>>j0; - if((i0&i)==0) { /* x is integral */ - uint32_t ix; - *iptr = x; - GET_FLOAT_WORD(ix,x); - SET_FLOAT_WORD(x,ix&0x80000000); /* return +-0 */ - return x; - } else { - SET_FLOAT_WORD(*iptr,i0&(~i)); - return x - *iptr; - } - } - } else { /* no fraction part */ - uint32_t ix; - *iptr = x*one; - GET_FLOAT_WORD(ix,x); - SET_FLOAT_WORD(x,ix&0x80000000); /* return +-0 */ - return x; - } -} diff --git a/05/musl-final/src/math/s_nextafter.c b/05/musl-final/src/math/s_nextafter.c deleted file mode 100644 index 46d298e..0000000 --- a/05/musl-final/src/math/s_nextafter.c +++ /dev/null @@ -1,72 +0,0 @@ -/* @(#)s_nextafter.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* IEEE functions - * nextafter(x,y) - * return the next machine floating-point number of x in the - * direction toward y. - * Special cases: - */ - -#include -#include "math_private.h" - -double -nextafter(double x, double y) -{ - volatile double t; - int32_t hx,hy,ix,iy; - uint32_t lx,ly; - - EXTRACT_WORDS(hx,lx,x); - EXTRACT_WORDS(hy,ly,y); - ix = hx&0x7fffffff; /* |x| */ - iy = hy&0x7fffffff; /* |y| */ - - if(((ix>=0x7ff00000)&&((ix-0x7ff00000)|lx)!=0) || /* x is nan */ - ((iy>=0x7ff00000)&&((iy-0x7ff00000)|ly)!=0)) /* y is nan */ - return x+y; - if(x==y) return y; /* x=y, return y */ - if((ix|lx)==0) { /* x == 0 */ - INSERT_WORDS(x,hy&0x80000000,1); /* return +-minsubnormal */ - t = x*x; - if(t==x) return t; else return x; /* raise underflow flag */ - } - if(hx>=0) { /* x > 0 */ - if(hx>hy||((hx==hy)&&(lx>ly))) { /* x > y, x -= ulp */ - if(lx==0) hx -= 1; - lx -= 1; - } else { /* x < y, x += ulp */ - lx += 1; - if(lx==0) hx += 1; - } - } else { /* x < 0 */ - if(hy>=0||hx>hy||((hx==hy)&&(lx>ly))){/* x < y, x -= ulp */ - if(lx==0) hx -= 1; - lx -= 1; - } else { /* x > y, x += ulp */ - lx += 1; - if(lx==0) hx += 1; - } - } - hy = hx&0x7ff00000; - if(hy>=0x7ff00000) return x+x; /* overflow */ - if(hy<0x00100000) { /* underflow */ - t = x*x; - if(t!=x) { /* raise underflow flag */ - INSERT_WORDS(y,hx,lx); - return y; - } - } - INSERT_WORDS(x,hx,lx); - return x; -} diff --git a/05/musl-final/src/math/s_nextafterf.c b/05/musl-final/src/math/s_nextafterf.c deleted file mode 100644 index 7ce0883..0000000 --- a/05/musl-final/src/math/s_nextafterf.c +++ /dev/null @@ -1,63 +0,0 @@ -/* s_nextafterf.c -- float version of s_nextafter.c. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include -#include "math_private.h" - -float -nextafterf(float x, float y) -{ - volatile float t; - int32_t hx,hy,ix,iy; - - GET_FLOAT_WORD(hx,x); - GET_FLOAT_WORD(hy,y); - ix = hx&0x7fffffff; /* |x| */ - iy = hy&0x7fffffff; /* |y| */ - - if((ix>0x7f800000) || /* x is nan */ - (iy>0x7f800000)) /* y is nan */ - return x+y; - if(x==y) return y; /* x=y, return y */ - if(ix==0) { /* x == 0 */ - SET_FLOAT_WORD(x,(hy&0x80000000)|1);/* return +-minsubnormal */ - t = x*x; - if(t==x) return t; else return x; /* raise underflow flag */ - } - if(hx>=0) { /* x > 0 */ - if(hx>hy) { /* x > y, x -= ulp */ - hx -= 1; - } else { /* x < y, x += ulp */ - hx += 1; - } - } else { /* x < 0 */ - if(hy>=0||hx>hy){ /* x < y, x -= ulp */ - hx -= 1; - } else { /* x > y, x += ulp */ - hx += 1; - } - } - hy = hx&0x7f800000; - if(hy>=0x7f800000) return x+x; /* overflow */ - if(hy<0x00800000) { /* underflow */ - t = x*x; - if(t!=x) { /* raise underflow flag */ - SET_FLOAT_WORD(y,hx); - return y; - } - } - SET_FLOAT_WORD(x,hx); - return x; -} diff --git a/05/musl-final/src/math/s_remquo.c b/05/musl-final/src/math/s_remquo.c deleted file mode 100644 index 1a2992d..0000000 --- a/05/musl-final/src/math/s_remquo.c +++ /dev/null @@ -1,149 +0,0 @@ -/* @(#)e_fmod.c 1.3 95/01/18 */ -/*- - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include -#include "math_private.h" - -static const double Zero[] = {0.0, -0.0,}; - -/* - * Return the IEEE remainder and set *quo to the last n bits of the - * quotient, rounded to the nearest integer. We choose n=31 because - * we wind up computing all the integer bits of the quotient anyway as - * a side-effect of computing the remainder by the shift and subtract - * method. In practice, this is far more bits than are needed to use - * remquo in reduction algorithms. - */ -double -remquo(double x, double y, int *quo) -{ - int32_t n,hx,hy,hz,ix,iy,sx,i; - uint32_t lx,ly,lz,q,sxy; - - EXTRACT_WORDS(hx,lx,x); - EXTRACT_WORDS(hy,ly,y); - sxy = (hx ^ hy) & 0x80000000; - sx = hx&0x80000000; /* sign of x */ - hx ^=sx; /* |x| */ - hy &= 0x7fffffff; /* |y| */ - - /* purge off exception values */ - if((hy|ly)==0||(hx>=0x7ff00000)|| /* y=0,or x not finite */ - ((hy|((ly|-ly)>>31))>0x7ff00000)) /* or y is NaN */ - return (x*y)/(x*y); - if(hx<=hy) { - if((hx>31]; /* |x|=|y| return x*0*/ - } - } - - /* determine ix = ilogb(x) */ - if(hx<0x00100000) { /* subnormal x */ - if(hx==0) { - for (ix = -1043, i=lx; i>0; i<<=1) ix -=1; - } else { - for (ix = -1022,i=(hx<<11); i>0; i<<=1) ix -=1; - } - } else ix = (hx>>20)-1023; - - /* determine iy = ilogb(y) */ - if(hy<0x00100000) { /* subnormal y */ - if(hy==0) { - for (iy = -1043, i=ly; i>0; i<<=1) iy -=1; - } else { - for (iy = -1022,i=(hy<<11); i>0; i<<=1) iy -=1; - } - } else iy = (hy>>20)-1023; - - /* set up {hx,lx}, {hy,ly} and align y to x */ - if(ix >= -1022) - hx = 0x00100000|(0x000fffff&hx); - else { /* subnormal x, shift x to normal */ - n = -1022-ix; - if(n<=31) { - hx = (hx<>(32-n)); - lx <<= n; - } else { - hx = lx<<(n-32); - lx = 0; - } - } - if(iy >= -1022) - hy = 0x00100000|(0x000fffff&hy); - else { /* subnormal y, shift y to normal */ - n = -1022-iy; - if(n<=31) { - hy = (hy<>(32-n)); - ly <<= n; - } else { - hy = ly<<(n-32); - ly = 0; - } - } - - /* fix point fmod */ - n = ix - iy; - q = 0; - while(n--) { - hz=hx-hy;lz=lx-ly; if(lx>31); lx = lx+lx;} - else {hx = hz+hz+(lz>>31); lx = lz+lz; q++;} - q <<= 1; - } - hz=hx-hy;lz=lx-ly; if(lx=0) {hx=hz;lx=lz;q++;} - - /* convert back to floating value and restore the sign */ - if((hx|lx)==0) { /* return sign(x)*0 */ - *quo = (sxy ? -q : q); - return Zero[(uint32_t)sx>>31]; - } - while(hx<0x00100000) { /* normalize x */ - hx = hx+hx+(lx>>31); lx = lx+lx; - iy -= 1; - } - if(iy>= -1022) { /* normalize output */ - hx = ((hx-0x00100000)|((iy+1023)<<20)); - } else { /* subnormal output */ - n = -1022 - iy; - if(n<=20) { - lx = (lx>>n)|((uint32_t)hx<<(32-n)); - hx >>= n; - } else if (n<=31) { - lx = (hx<<(32-n))|(lx>>n); hx = sx; - } else { - lx = hx>>(n-32); hx = sx; - } - } -fixup: - INSERT_WORDS(x,hx,lx); - y = fabs(y); - if (y < 0x1p-1021) { - if (x+x>y || (x+x==y && (q & 1))) { - q++; - x-=y; - } - } else if (x>0.5*y || (x==0.5*y && (q & 1))) { - q++; - x-=y; - } - GET_HIGH_WORD(hx,x); - SET_HIGH_WORD(x,hx^sx); - q &= 0x7fffffff; - *quo = (sxy ? -q : q); - return x; -} diff --git a/05/musl-final/src/math/s_remquof.c b/05/musl-final/src/math/s_remquof.c deleted file mode 100644 index be2a561..0000000 --- a/05/musl-final/src/math/s_remquof.c +++ /dev/null @@ -1,118 +0,0 @@ -/* @(#)e_fmod.c 1.3 95/01/18 */ -/*- - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include -#include "math_private.h" - -static const float Zero[] = {0.0, -0.0,}; - -/* - * Return the IEEE remainder and set *quo to the last n bits of the - * quotient, rounded to the nearest integer. We choose n=31 because - * we wind up computing all the integer bits of the quotient anyway as - * a side-effect of computing the remainder by the shift and subtract - * method. In practice, this is far more bits than are needed to use - * remquo in reduction algorithms. - */ -float -remquof(float x, float y, int *quo) -{ - int32_t n,hx,hy,hz,ix,iy,sx,i; - uint32_t q,sxy; - - GET_FLOAT_WORD(hx,x); - GET_FLOAT_WORD(hy,y); - sxy = (hx ^ hy) & 0x80000000; - sx = hx&0x80000000; /* sign of x */ - hx ^=sx; /* |x| */ - hy &= 0x7fffffff; /* |y| */ - - /* purge off exception values */ - if(hy==0||hx>=0x7f800000||hy>0x7f800000) /* y=0,NaN;or x not finite */ - return (x*y)/(x*y); - if(hx>31]; /* |x|=|y| return x*0*/ - } - - /* determine ix = ilogb(x) */ - if(hx<0x00800000) { /* subnormal x */ - for (ix = -126,i=(hx<<8); i>0; i<<=1) ix -=1; - } else ix = (hx>>23)-127; - - /* determine iy = ilogb(y) */ - if(hy<0x00800000) { /* subnormal y */ - for (iy = -126,i=(hy<<8); i>0; i<<=1) iy -=1; - } else iy = (hy>>23)-127; - - /* set up {hx,lx}, {hy,ly} and align y to x */ - if(ix >= -126) - hx = 0x00800000|(0x007fffff&hx); - else { /* subnormal x, shift x to normal */ - n = -126-ix; - hx <<= n; - } - if(iy >= -126) - hy = 0x00800000|(0x007fffff&hy); - else { /* subnormal y, shift y to normal */ - n = -126-iy; - hy <<= n; - } - - /* fix point fmod */ - n = ix - iy; - q = 0; - while(n--) { - hz=hx-hy; - if(hz<0) hx = hx << 1; - else {hx = hz << 1; q++;} - q <<= 1; - } - hz=hx-hy; - if(hz>=0) {hx=hz;q++;} - - /* convert back to floating value and restore the sign */ - if(hx==0) { /* return sign(x)*0 */ - *quo = (sxy ? -q : q); - return Zero[(uint32_t)sx>>31]; - } - while(hx<0x00800000) { /* normalize x */ - hx <<= 1; - iy -= 1; - } - if(iy>= -126) { /* normalize output */ - hx = ((hx-0x00800000)|((iy+127)<<23)); - } else { /* subnormal output */ - n = -126 - iy; - hx >>= n; - } -fixup: - SET_FLOAT_WORD(x,hx); - y = fabsf(y); - if (y < 0x1p-125f) { - if (x+x>y || (x+x==y && (q & 1))) { - q++; - x-=y; - } - } else if (x>0.5f*y || (x==0.5f*y && (q & 1))) { - q++; - x-=y; - } - GET_FLOAT_WORD(hx,x); - SET_FLOAT_WORD(x,hx^sx); - q &= 0x7fffffff; - *quo = (sxy ? -q : q); - return x; -} diff --git a/05/musl-final/src/math/s_rint.c b/05/musl-final/src/math/s_rint.c deleted file mode 100644 index c80e01e..0000000 --- a/05/musl-final/src/math/s_rint.c +++ /dev/null @@ -1,80 +0,0 @@ -/* @(#)s_rint.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* - * rint(x) - * Return x rounded to integral value according to the prevailing - * rounding mode. - * Method: - * Using floating addition. - * Exception: - * Inexact flag raised if x not equal to rint(x). - */ - -#include -#include "math_private.h" - -/* - * TWO23 is long double instead of double to avoid a bug in gcc. Without - * this, gcc thinks that TWO23[sx]+x and w-TWO23[sx] already have double - * precision and doesn't clip them to double precision when they are - * assigned and returned. - */ -static const /*long*/ double -TWO52[2]={ - 4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */ - -4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */ -}; - -double -rint(double x) -{ - int32_t i0,j0,sx; - uint32_t i,i1; - double w,t; - EXTRACT_WORDS(i0,i1,x); - sx = (i0>>31)&1; - j0 = ((i0>>20)&0x7ff)-0x3ff; - if(j0<20) { - if(j0<0) { - if(((i0&0x7fffffff)|i1)==0) return x; - i1 |= (i0&0x0fffff); - i0 &= 0xfffe0000; - i0 |= ((i1|-i1)>>12)&0x80000; - SET_HIGH_WORD(x,i0); - w = TWO52[sx]+x; - t = w-TWO52[sx]; - GET_HIGH_WORD(i0,t); - SET_HIGH_WORD(t,(i0&0x7fffffff)|(sx<<31)); - return t; - } else { - i = (0x000fffff)>>j0; - if(((i0&i)|i1)==0) return x; /* x is integral */ - i>>=1; - if(((i0&i)|i1)!=0) { - if(j0==19) i1 = 0x40000000; else - i0 = (i0&(~i))|((0x20000)>>j0); - } - } - } else if (j0>51) { - if(j0==0x400) return x+x; /* inf or NaN */ - else return x; /* x is integral */ - } else { - i = ((uint32_t)(0xffffffff))>>(j0-20); - if((i1&i)==0) return x; /* x is integral */ - i>>=1; - if((i1&i)!=0) i1 = (i1&(~i))|((0x40000000)>>(j0-20)); - } - INSERT_WORDS(x,i0,i1); - w = TWO52[sx]+x; - return w-TWO52[sx]; -} diff --git a/05/musl-final/src/math/s_rintf.c b/05/musl-final/src/math/s_rintf.c deleted file mode 100644 index c441870..0000000 --- a/05/musl-final/src/math/s_rintf.c +++ /dev/null @@ -1,45 +0,0 @@ -/* s_rintf.c -- float version of s_rint.c. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include -#include "math_private.h" - -static const float -TWO23[2]={ - 8.3886080000e+06, /* 0x4b000000 */ - -8.3886080000e+06, /* 0xcb000000 */ -}; - -float -rintf(float x) -{ - int32_t i0,j0,sx; - volatile float w,t; /* volatile works around gcc bug */ - GET_FLOAT_WORD(i0,x); - sx = (i0>>31)&1; - j0 = ((i0>>23)&0xff)-0x7f; - if(j0<23) { - if(j0<0) { - if((i0&0x7fffffff)==0) return x; - w = TWO23[sx]+x; - t = w-TWO23[sx]; - return t; - } - w = TWO23[sx]+x; - return w-TWO23[sx]; - } - if(j0==0x80) return x+x; /* inf or NaN */ - else return x; /* x is integral */ -} diff --git a/05/musl-final/src/math/s_round.c b/05/musl-final/src/math/s_round.c deleted file mode 100644 index d5bea7a..0000000 --- a/05/musl-final/src/math/s_round.c +++ /dev/null @@ -1,48 +0,0 @@ -/*- - * Copyright (c) 2003, Steven G. Kargl - * 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 unmodified, 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. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. - */ - -#include - -double -round(double x) -{ - double t; - - if (!isfinite(x)) - return (x); - - if (x >= 0.0) { - t = ceil(x); - if (t - x > 0.5) - t -= 1.0; - return (t); - } else { - t = ceil(-x); - if (t + x > 0.5) - t -= 1.0; - return (-t); - } -} diff --git a/05/musl-final/src/math/s_roundf.c b/05/musl-final/src/math/s_roundf.c deleted file mode 100644 index c4fc3e1..0000000 --- a/05/musl-final/src/math/s_roundf.c +++ /dev/null @@ -1,48 +0,0 @@ -/*- - * Copyright (c) 2003, Steven G. Kargl - * 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 unmodified, 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. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. - */ - -#include - -float -roundf(float x) -{ - float t; - - if (!isfinite(x)) - return (x); - - if (x >= 0.0) { - t = ceilf(x); - if (t - x > 0.5) - t -= 1.0; - return (t); - } else { - t = ceilf(-x); - if (t + x > 0.5) - t -= 1.0; - return (-t); - } -} diff --git a/05/musl-final/src/math/s_scalbln.c b/05/musl-final/src/math/s_scalbln.c deleted file mode 100644 index 12b9391..0000000 --- a/05/musl-final/src/math/s_scalbln.c +++ /dev/null @@ -1,61 +0,0 @@ -/* @(#)s_scalbn.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* - * scalbn (double x, int n) - * scalbn(x,n) returns x* 2**n computed by exponent - * manipulation rather than by actually performing an - * exponentiation or a multiplication. - */ - -#include -#include "math_private.h" - -static const double -two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */ -twom54 = 5.55111512312578270212e-17, /* 0x3C900000, 0x00000000 */ -huge = 1.0e+300, -tiny = 1.0e-300; - -double -scalbln (double x, long n) -{ - int32_t k,hx,lx; - EXTRACT_WORDS(hx,lx,x); - k = (hx&0x7ff00000)>>20; /* extract exponent */ - if (k==0) { /* 0 or subnormal x */ - if ((lx|(hx&0x7fffffff))==0) return x; /* +-0 */ - x *= two54; - GET_HIGH_WORD(hx,x); - k = ((hx&0x7ff00000)>>20) - 54; - if (n< -50000) return tiny*x; /*underflow*/ - } - if (k==0x7ff) return x+x; /* NaN or Inf */ - k = k+n; - if (k > 0x7fe) return huge*copysign(huge,x); /* overflow */ - if (k > 0) /* normal result */ - {SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20)); return x;} - if (k <= -54) { - if (n > 50000) /* in case integer overflow in n+k */ - return huge*copysign(huge,x); /*overflow*/ - else return tiny*copysign(tiny,x); /*underflow*/ - } - k += 54; /* subnormal result */ - SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20)); - return x*twom54; -} - -double -scalbn (double x, int n) -{ - return scalbln(x, n); -} diff --git a/05/musl-final/src/math/s_scalblnf.c b/05/musl-final/src/math/s_scalblnf.c deleted file mode 100644 index 21e7641..0000000 --- a/05/musl-final/src/math/s_scalblnf.c +++ /dev/null @@ -1,57 +0,0 @@ -/* s_scalbnf.c -- float version of s_scalbn.c. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include -#include "math_private.h" - -static const float -two25 = 3.355443200e+07, /* 0x4c000000 */ -twom25 = 2.9802322388e-08, /* 0x33000000 */ -huge = 1.0e+30, -tiny = 1.0e-30; - -float -scalblnf (float x, long n) -{ - int32_t k,ix; - GET_FLOAT_WORD(ix,x); - k = (ix&0x7f800000)>>23; /* extract exponent */ - if (k==0) { /* 0 or subnormal x */ - if ((ix&0x7fffffff)==0) return x; /* +-0 */ - x *= two25; - GET_FLOAT_WORD(ix,x); - k = ((ix&0x7f800000)>>23) - 25; - if (n< -50000) return tiny*x; /*underflow*/ - } - if (k==0xff) return x+x; /* NaN or Inf */ - k = k+n; - if (k > 0xfe) return huge*copysignf(huge,x); /* overflow */ - if (k > 0) /* normal result */ - {SET_FLOAT_WORD(x,(ix&0x807fffff)|(k<<23)); return x;} - if (k <= -25) { - if (n > 50000) /* in case integer overflow in n+k */ - return huge*copysignf(huge,x); /*overflow*/ - else return tiny*copysignf(tiny,x); /*underflow*/ - } - k += 25; /* subnormal result */ - SET_FLOAT_WORD(x,(ix&0x807fffff)|(k<<23)); - return x*twom25; -} - -float -scalbnf (float x, int n) -{ - return scalblnf(x, n); -} diff --git a/05/musl-final/src/math/s_sin.c b/05/musl-final/src/math/s_sin.c deleted file mode 100644 index 2a2774e..0000000 --- a/05/musl-final/src/math/s_sin.c +++ /dev/null @@ -1,74 +0,0 @@ -/* @(#)s_sin.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* sin(x) - * Return sine function of x. - * - * kernel function: - * __kernel_sin ... sine function on [-pi/4,pi/4] - * __kernel_cos ... cose function on [-pi/4,pi/4] - * __ieee754_rem_pio2 ... argument reduction routine - * - * Method. - * Let S,C and T denote the sin, cos and tan respectively on - * [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2 - * in [-pi/4 , +pi/4], and let n = k mod 4. - * We have - * - * n sin(x) cos(x) tan(x) - * ---------------------------------------------------------- - * 0 S C T - * 1 C -S -1/T - * 2 -S -C T - * 3 -C S -1/T - * ---------------------------------------------------------- - * - * Special cases: - * Let trig be any of sin, cos, or tan. - * trig(+-INF) is NaN, with signals; - * trig(NaN) is that NaN; - * - * Accuracy: - * TRIG(x) returns trig(x) nearly rounded - */ - -#include -#include "math_private.h" - -double -sin(double x) -{ - double y[2],z=0.0; - int32_t n, ix; - - /* High word of x. */ - GET_HIGH_WORD(ix,x); - - /* |x| ~< pi/4 */ - ix &= 0x7fffffff; - if(ix <= 0x3fe921fb) return __kernel_sin(x,z,0); - - /* sin(Inf or NaN) is NaN */ - else if (ix>=0x7ff00000) return x-x; - - /* argument reduction needed */ - else { - n = __ieee754_rem_pio2(x,y); - switch(n&3) { - case 0: return __kernel_sin(y[0],y[1],1); - case 1: return __kernel_cos(y[0],y[1]); - case 2: return -__kernel_sin(y[0],y[1],1); - default: - return -__kernel_cos(y[0],y[1]); - } - } -} diff --git a/05/musl-final/src/math/s_sinf.c b/05/musl-final/src/math/s_sinf.c deleted file mode 100644 index d2b8e80..0000000 --- a/05/musl-final/src/math/s_sinf.c +++ /dev/null @@ -1,45 +0,0 @@ -/* s_sinf.c -- float version of s_sin.c. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include -#include "math_private.h" - -float -sinf(float x) -{ - float y[2],z=0.0; - int32_t n, ix; - - GET_FLOAT_WORD(ix,x); - - /* |x| ~< pi/4 */ - ix &= 0x7fffffff; - if(ix <= 0x3f490fd8) return __kernel_sinf(x,z,0); - - /* sin(Inf or NaN) is NaN */ - else if (ix>=0x7f800000) return x-x; - - /* argument reduction needed */ - else { - n = __ieee754_rem_pio2f(x,y); - switch(n&3) { - case 0: return __kernel_sinf(y[0],y[1],1); - case 1: return __kernel_cosf(y[0],y[1]); - case 2: return -__kernel_sinf(y[0],y[1],1); - default: - return -__kernel_cosf(y[0],y[1]); - } - } -} diff --git a/05/musl-final/src/math/s_tan.c b/05/musl-final/src/math/s_tan.c deleted file mode 100644 index 3333cb3..0000000 --- a/05/musl-final/src/math/s_tan.c +++ /dev/null @@ -1,68 +0,0 @@ -/* @(#)s_tan.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* tan(x) - * Return tangent function of x. - * - * kernel function: - * __kernel_tan ... tangent function on [-pi/4,pi/4] - * __ieee754_rem_pio2 ... argument reduction routine - * - * Method. - * Let S,C and T denote the sin, cos and tan respectively on - * [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2 - * in [-pi/4 , +pi/4], and let n = k mod 4. - * We have - * - * n sin(x) cos(x) tan(x) - * ---------------------------------------------------------- - * 0 S C T - * 1 C -S -1/T - * 2 -S -C T - * 3 -C S -1/T - * ---------------------------------------------------------- - * - * Special cases: - * Let trig be any of sin, cos, or tan. - * trig(+-INF) is NaN, with signals; - * trig(NaN) is that NaN; - * - * Accuracy: - * TRIG(x) returns trig(x) nearly rounded - */ - -#include -#include "math_private.h" - -double -tan(double x) -{ - double y[2],z=0.0; - int32_t n, ix; - - /* High word of x. */ - GET_HIGH_WORD(ix,x); - - /* |x| ~< pi/4 */ - ix &= 0x7fffffff; - if(ix <= 0x3fe921fb) return __kernel_tan(x,z,1); - - /* tan(Inf or NaN) is NaN */ - else if (ix>=0x7ff00000) return x-x; /* NaN */ - - /* argument reduction needed */ - else { - n = __ieee754_rem_pio2(x,y); - return __kernel_tan(y[0],y[1],1-((n&1)<<1)); /* 1 -- n even - -1 -- n odd */ - } -} diff --git a/05/musl-final/src/math/s_tanf.c b/05/musl-final/src/math/s_tanf.c deleted file mode 100644 index 660dd9c..0000000 --- a/05/musl-final/src/math/s_tanf.c +++ /dev/null @@ -1,40 +0,0 @@ -/* s_tanf.c -- float version of s_tan.c. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include -#include "math_private.h" - -float -tanf(float x) -{ - float y[2],z=0.0; - int32_t n, ix; - - GET_FLOAT_WORD(ix,x); - - /* |x| ~< pi/4 */ - ix &= 0x7fffffff; - if(ix <= 0x3f490fda) return __kernel_tanf(x,z,1); - - /* tan(Inf or NaN) is NaN */ - else if (ix>=0x7f800000) return x-x; /* NaN */ - - /* argument reduction needed */ - else { - n = __ieee754_rem_pio2f(x,y); - return __kernel_tanf(y[0],y[1],1-((n&1)<<1)); /* 1 -- n even - -1 -- n odd */ - } -} diff --git a/05/musl-final/src/math/s_tanh.c b/05/musl-final/src/math/s_tanh.c deleted file mode 100644 index 78b8e84..0000000 --- a/05/musl-final/src/math/s_tanh.c +++ /dev/null @@ -1,74 +0,0 @@ -/* @(#)s_tanh.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* Tanh(x) - * Return the Hyperbolic Tangent of x - * - * Method : - * x -x - * e - e - * 0. tanh(x) is defined to be ----------- - * x -x - * e + e - * 1. reduce x to non-negative by tanh(-x) = -tanh(x). - * 2. 0 <= x <= 2**-55 : tanh(x) := x*(one+x) - * -t - * 2**-55 < x <= 1 : tanh(x) := -----; t = expm1(-2x) - * t + 2 - * 2 - * 1 <= x <= 22.0 : tanh(x) := 1- ----- ; t=expm1(2x) - * t + 2 - * 22.0 < x <= INF : tanh(x) := 1. - * - * Special cases: - * tanh(NaN) is NaN; - * only tanh(0)=0 is exact for finite argument. - */ - -#include -#include "math_private.h" - -static const double one=1.0, two=2.0, tiny = 1.0e-300; - -double -tanh(double x) -{ - double t,z; - int32_t jx,ix; - - /* High word of |x|. */ - GET_HIGH_WORD(jx,x); - ix = jx&0x7fffffff; - - /* x is INF or NaN */ - if(ix>=0x7ff00000) { - if (jx>=0) return one/x+one; /* tanh(+-inf)=+-1 */ - else return one/x-one; /* tanh(NaN) = NaN */ - } - - /* |x| < 22 */ - if (ix < 0x40360000) { /* |x|<22 */ - if (ix<0x3c800000) /* |x|<2**-55 */ - return x*(one+x); /* tanh(small) = small */ - if (ix>=0x3ff00000) { /* |x|>=1 */ - t = expm1(two*fabs(x)); - z = one - two/(t+two); - } else { - t = expm1(-two*fabs(x)); - z= -t/(t+two); - } - /* |x| > 22, return +-1 */ - } else { - z = one - tiny; /* raised inexact flag */ - } - return (jx>=0)? z: -z; -} diff --git a/05/musl-final/src/math/s_tanhf.c b/05/musl-final/src/math/s_tanhf.c deleted file mode 100644 index a082040..0000000 --- a/05/musl-final/src/math/s_tanhf.c +++ /dev/null @@ -1,52 +0,0 @@ -/* s_tanhf.c -- float version of s_tanh.c. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include -#include "math_private.h" - -static const float one=1.0, two=2.0, tiny = 1.0e-30; - -float -tanhf(float x) -{ - float t,z; - int32_t jx,ix; - - GET_FLOAT_WORD(jx,x); - ix = jx&0x7fffffff; - - /* x is INF or NaN */ - if(ix>=0x7f800000) { - if (jx>=0) return one/x+one; /* tanh(+-inf)=+-1 */ - else return one/x-one; /* tanh(NaN) = NaN */ - } - - /* |x| < 22 */ - if (ix < 0x41b00000) { /* |x|<22 */ - if (ix<0x24000000) /* |x|<2**-55 */ - return x*(one+x); /* tanh(small) = small */ - if (ix>=0x3f800000) { /* |x|>=1 */ - t = expm1f(two*fabsf(x)); - z = one - two/(t+two); - } else { - t = expm1f(-two*fabsf(x)); - z= -t/(t+two); - } - /* |x| > 22, return +-1 */ - } else { - z = one - tiny; /* raised inexact flag */ - } - return (jx>=0)? z: -z; -} diff --git a/05/musl-final/src/math/s_trunc.c b/05/musl-final/src/math/s_trunc.c deleted file mode 100644 index 02c6556..0000000 --- a/05/musl-final/src/math/s_trunc.c +++ /dev/null @@ -1,58 +0,0 @@ -/* @(#)s_floor.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* - * trunc(x) - * Return x rounded toward 0 to integral value - * Method: - * Bit twiddling. - * Exception: - * Inexact flag raised if x not equal to trunc(x). - */ - -#include -#include "math_private.h" - -static const double huge = 1.0e300; - -double -trunc(double x) -{ - int32_t i0,i1,j0; - uint32_t i,j; - EXTRACT_WORDS(i0,i1,x); - j0 = ((i0>>20)&0x7ff)-0x3ff; - if(j0<20) { - if(j0<0) { /* raise inexact if x != 0 */ - if(huge+x>0.0) {/* |x|<1, so return 0*sign(x) */ - i0 &= 0x80000000U; - i1 = 0; - } - } else { - i = (0x000fffff)>>j0; - if(((i0&i)|i1)==0) return x; /* x is integral */ - if(huge+x>0.0) { /* raise inexact flag */ - i0 &= (~i); i1=0; - } - } - } else if (j0>51) { - if(j0==0x400) return x+x; /* inf or NaN */ - else return x; /* x is integral */ - } else { - i = ((uint32_t)(0xffffffff))>>(j0-20); - if((i1&i)==0) return x; /* x is integral */ - if(huge+x>0.0) /* raise inexact flag */ - i1 &= (~i); - } - INSERT_WORDS(x,i0,i1); - return x; -} diff --git a/05/musl-final/src/math/s_truncf.c b/05/musl-final/src/math/s_truncf.c deleted file mode 100644 index c253e62..0000000 --- a/05/musl-final/src/math/s_truncf.c +++ /dev/null @@ -1,50 +0,0 @@ -/* @(#)s_floor.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* - * truncf(x) - * Return x rounded toward 0 to integral value - * Method: - * Bit twiddling. - * Exception: - * Inexact flag raised if x not equal to truncf(x). - */ - -#include -#include "math_private.h" - -static const float huge = 1.0e30F; - -float -truncf(float x) -{ - int32_t i0,j0; - uint32_t i; - GET_FLOAT_WORD(i0,x); - j0 = ((i0>>23)&0xff)-0x7f; - if(j0<23) { - if(j0<0) { /* raise inexact if x != 0 */ - if(huge+x>0.0F) /* |x|<1, so return 0*sign(x) */ - i0 &= 0x80000000; - } else { - i = (0x007fffff)>>j0; - if((i0&i)==0) return x; /* x is integral */ - if(huge+x>0.0F) /* raise inexact flag */ - i0 &= (~i); - } - } else { - if(j0==0x80) return x+x; /* inf or NaN */ - else return x; /* x is integral */ - } - SET_FLOAT_WORD(x,i0); - return x; -} diff --git a/05/musl-final/src/misc/basename.c b/05/musl-final/src/misc/basename.c deleted file mode 100644 index c87e00c..0000000 --- a/05/musl-final/src/misc/basename.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -char *basename(char *s) -{ - size_t i; - if (!s || !*s) return "."; - i = strlen(s)-1; - for (; i&&s[i]=='/'; i--) s[i] = 0; - for (; i&&s[i-1]!='/'; i--); - return s+i; -} diff --git a/05/musl-final/src/misc/bswap_32.c b/05/musl-final/src/misc/bswap_32.c deleted file mode 100644 index a2418ca..0000000 --- a/05/musl-final/src/misc/bswap_32.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include - -uint32_t bswap_32(uint32_t x) -{ - return x>>24 | x>>16&0xff00 | x<<16&0xff0000 | x<<24; -} diff --git a/05/musl-final/src/misc/bswap_64.c b/05/musl-final/src/misc/bswap_64.c deleted file mode 100644 index 961300b..0000000 --- a/05/musl-final/src/misc/bswap_64.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include - -uint32_t bswap_32(uint32_t); - -uint64_t bswap_64(uint64_t x) -{ - return bswap_32(x)+0LL<<32 | bswap_32(x>>32); -} diff --git a/05/musl-final/src/misc/crypt.c b/05/musl-final/src/misc/crypt.c deleted file mode 100644 index 42918ef..0000000 --- a/05/musl-final/src/misc/crypt.c +++ /dev/null @@ -1,2578 +0,0 @@ -/* - * FreeSec: libcrypt for NetBSD - * - * Copyright (c) 1994 David Burren - * 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. Neither the name of the author nor the names of other contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. - * - * This is an original implementation of the DES and the crypt(3) interfaces - * by David Burren . - * - * An excellent reference on the underlying algorithm (and related - * algorithms) is: - * - * B. Schneier, Applied Cryptography: protocols, algorithms, - * and source code in C, John Wiley & Sons, 1994. - * - * Note that in that book's description of DES the lookups for the initial, - * pbox, and final permutations are inverted (this has been brought to the - * attention of the author). A list of errata for this book has been - * posted to the sci.crypt newsgroup by the author and is available for FTP. - * - * ARCHITECTURE ASSUMPTIONS: - * It is assumed that the 8-byte arrays passed by reference can be - * addressed as arrays of uint32_t's (ie. the CPU is not picky about - * alignment). - */ - -#include -#include "libc.h" - -static int i64c(int i) -{ - i &= 0x3f; - if (i == 0) - return '.'; - if (i == 1) - return '/'; - if (i < 12) - return ('0' - 2 + i); - if (i < 38) - return ('A' - 12 + i); - return ('a' - 38 + i); -} - -/* Generated by const_des_init() (removed) */ - -static const uint8_t final_perm[64] = { - 0x39, 0x31, 0x29, 0x21, 0x19, 0x11, 0x09, 0x01, 0x3b, 0x33, 0x2b, 0x23, 0x1b, 0x13, 0x0b, 0x03, - 0x3d, 0x35, 0x2d, 0x25, 0x1d, 0x15, 0x0d, 0x05, 0x3f, 0x37, 0x2f, 0x27, 0x1f, 0x17, 0x0f, 0x07, - 0x38, 0x30, 0x28, 0x20, 0x18, 0x10, 0x08, 0x00, 0x3a, 0x32, 0x2a, 0x22, 0x1a, 0x12, 0x0a, 0x02, - 0x3c, 0x34, 0x2c, 0x24, 0x1c, 0x14, 0x0c, 0x04, 0x3e, 0x36, 0x2e, 0x26, 0x1e, 0x16, 0x0e, 0x06, -}; -static const uint8_t m_sbox[4][4096] = { - { - 0xef, 0xe3, 0xe1, 0xed, 0xe8, 0xe4, 0xee, 0xe7, - 0xe6, 0xef, 0xeb, 0xe2, 0xe3, 0xe8, 0xe4, 0xee, - 0xe9, 0xec, 0xe7, 0xe0, 0xe2, 0xe1, 0xed, 0xea, - 0xec, 0xe6, 0xe0, 0xe9, 0xe5, 0xeb, 0xea, 0xe5, - 0xe0, 0xed, 0xee, 0xe8, 0xe7, 0xea, 0xeb, 0xe1, - 0xea, 0xe3, 0xe4, 0xef, 0xed, 0xe4, 0xe1, 0xe2, - 0xe5, 0xeb, 0xe8, 0xe6, 0xec, 0xe7, 0xe6, 0xec, - 0xe9, 0xe0, 0xe3, 0xe5, 0xe2, 0xee, 0xef, 0xe9, - 0x0f, 0x03, 0x01, 0x0d, 0x08, 0x04, 0x0e, 0x07, - 0x06, 0x0f, 0x0b, 0x02, 0x03, 0x08, 0x04, 0x0e, - 0x09, 0x0c, 0x07, 0x00, 0x02, 0x01, 0x0d, 0x0a, - 0x0c, 0x06, 0x00, 0x09, 0x05, 0x0b, 0x0a, 0x05, - 0x00, 0x0d, 0x0e, 0x08, 0x07, 0x0a, 0x0b, 0x01, - 0x0a, 0x03, 0x04, 0x0f, 0x0d, 0x04, 0x01, 0x02, - 0x05, 0x0b, 0x08, 0x06, 0x0c, 0x07, 0x06, 0x0c, - 0x09, 0x00, 0x03, 0x05, 0x02, 0x0e, 0x0f, 0x09, - 0x4f, 0x43, 0x41, 0x4d, 0x48, 0x44, 0x4e, 0x47, - 0x46, 0x4f, 0x4b, 0x42, 0x43, 0x48, 0x44, 0x4e, - 0x49, 0x4c, 0x47, 0x40, 0x42, 0x41, 0x4d, 0x4a, - 0x4c, 0x46, 0x40, 0x49, 0x45, 0x4b, 0x4a, 0x45, - 0x40, 0x4d, 0x4e, 0x48, 0x47, 0x4a, 0x4b, 0x41, - 0x4a, 0x43, 0x44, 0x4f, 0x4d, 0x44, 0x41, 0x42, - 0x45, 0x4b, 0x48, 0x46, 0x4c, 0x47, 0x46, 0x4c, - 0x49, 0x40, 0x43, 0x45, 0x42, 0x4e, 0x4f, 0x49, - 0xff, 0xf3, 0xf1, 0xfd, 0xf8, 0xf4, 0xfe, 0xf7, - 0xf6, 0xff, 0xfb, 0xf2, 0xf3, 0xf8, 0xf4, 0xfe, - 0xf9, 0xfc, 0xf7, 0xf0, 0xf2, 0xf1, 0xfd, 0xfa, - 0xfc, 0xf6, 0xf0, 0xf9, 0xf5, 0xfb, 0xfa, 0xf5, - 0xf0, 0xfd, 0xfe, 0xf8, 0xf7, 0xfa, 0xfb, 0xf1, - 0xfa, 0xf3, 0xf4, 0xff, 0xfd, 0xf4, 0xf1, 0xf2, - 0xf5, 0xfb, 0xf8, 0xf6, 0xfc, 0xf7, 0xf6, 0xfc, - 0xf9, 0xf0, 0xf3, 0xf5, 0xf2, 0xfe, 0xff, 0xf9, - 0xdf, 0xd3, 0xd1, 0xdd, 0xd8, 0xd4, 0xde, 0xd7, - 0xd6, 0xdf, 0xdb, 0xd2, 0xd3, 0xd8, 0xd4, 0xde, - 0xd9, 0xdc, 0xd7, 0xd0, 0xd2, 0xd1, 0xdd, 0xda, - 0xdc, 0xd6, 0xd0, 0xd9, 0xd5, 0xdb, 0xda, 0xd5, - 0xd0, 0xdd, 0xde, 0xd8, 0xd7, 0xda, 0xdb, 0xd1, - 0xda, 0xd3, 0xd4, 0xdf, 0xdd, 0xd4, 0xd1, 0xd2, - 0xd5, 0xdb, 0xd8, 0xd6, 0xdc, 0xd7, 0xd6, 0xdc, - 0xd9, 0xd0, 0xd3, 0xd5, 0xd2, 0xde, 0xdf, 0xd9, - 0x7f, 0x73, 0x71, 0x7d, 0x78, 0x74, 0x7e, 0x77, - 0x76, 0x7f, 0x7b, 0x72, 0x73, 0x78, 0x74, 0x7e, - 0x79, 0x7c, 0x77, 0x70, 0x72, 0x71, 0x7d, 0x7a, - 0x7c, 0x76, 0x70, 0x79, 0x75, 0x7b, 0x7a, 0x75, - 0x70, 0x7d, 0x7e, 0x78, 0x77, 0x7a, 0x7b, 0x71, - 0x7a, 0x73, 0x74, 0x7f, 0x7d, 0x74, 0x71, 0x72, - 0x75, 0x7b, 0x78, 0x76, 0x7c, 0x77, 0x76, 0x7c, - 0x79, 0x70, 0x73, 0x75, 0x72, 0x7e, 0x7f, 0x79, - 0x1f, 0x13, 0x11, 0x1d, 0x18, 0x14, 0x1e, 0x17, - 0x16, 0x1f, 0x1b, 0x12, 0x13, 0x18, 0x14, 0x1e, - 0x19, 0x1c, 0x17, 0x10, 0x12, 0x11, 0x1d, 0x1a, - 0x1c, 0x16, 0x10, 0x19, 0x15, 0x1b, 0x1a, 0x15, - 0x10, 0x1d, 0x1e, 0x18, 0x17, 0x1a, 0x1b, 0x11, - 0x1a, 0x13, 0x14, 0x1f, 0x1d, 0x14, 0x11, 0x12, - 0x15, 0x1b, 0x18, 0x16, 0x1c, 0x17, 0x16, 0x1c, - 0x19, 0x10, 0x13, 0x15, 0x12, 0x1e, 0x1f, 0x19, - 0x4f, 0x43, 0x41, 0x4d, 0x48, 0x44, 0x4e, 0x47, - 0x46, 0x4f, 0x4b, 0x42, 0x43, 0x48, 0x44, 0x4e, - 0x49, 0x4c, 0x47, 0x40, 0x42, 0x41, 0x4d, 0x4a, - 0x4c, 0x46, 0x40, 0x49, 0x45, 0x4b, 0x4a, 0x45, - 0x40, 0x4d, 0x4e, 0x48, 0x47, 0x4a, 0x4b, 0x41, - 0x4a, 0x43, 0x44, 0x4f, 0x4d, 0x44, 0x41, 0x42, - 0x45, 0x4b, 0x48, 0x46, 0x4c, 0x47, 0x46, 0x4c, - 0x49, 0x40, 0x43, 0x45, 0x42, 0x4e, 0x4f, 0x49, - 0x2f, 0x23, 0x21, 0x2d, 0x28, 0x24, 0x2e, 0x27, - 0x26, 0x2f, 0x2b, 0x22, 0x23, 0x28, 0x24, 0x2e, - 0x29, 0x2c, 0x27, 0x20, 0x22, 0x21, 0x2d, 0x2a, - 0x2c, 0x26, 0x20, 0x29, 0x25, 0x2b, 0x2a, 0x25, - 0x20, 0x2d, 0x2e, 0x28, 0x27, 0x2a, 0x2b, 0x21, - 0x2a, 0x23, 0x24, 0x2f, 0x2d, 0x24, 0x21, 0x22, - 0x25, 0x2b, 0x28, 0x26, 0x2c, 0x27, 0x26, 0x2c, - 0x29, 0x20, 0x23, 0x25, 0x22, 0x2e, 0x2f, 0x29, - 0xef, 0xe3, 0xe1, 0xed, 0xe8, 0xe4, 0xee, 0xe7, - 0xe6, 0xef, 0xeb, 0xe2, 0xe3, 0xe8, 0xe4, 0xee, - 0xe9, 0xec, 0xe7, 0xe0, 0xe2, 0xe1, 0xed, 0xea, - 0xec, 0xe6, 0xe0, 0xe9, 0xe5, 0xeb, 0xea, 0xe5, - 0xe0, 0xed, 0xee, 0xe8, 0xe7, 0xea, 0xeb, 0xe1, - 0xea, 0xe3, 0xe4, 0xef, 0xed, 0xe4, 0xe1, 0xe2, - 0xe5, 0xeb, 0xe8, 0xe6, 0xec, 0xe7, 0xe6, 0xec, - 0xe9, 0xe0, 0xe3, 0xe5, 0xe2, 0xee, 0xef, 0xe9, - 0xff, 0xf3, 0xf1, 0xfd, 0xf8, 0xf4, 0xfe, 0xf7, - 0xf6, 0xff, 0xfb, 0xf2, 0xf3, 0xf8, 0xf4, 0xfe, - 0xf9, 0xfc, 0xf7, 0xf0, 0xf2, 0xf1, 0xfd, 0xfa, - 0xfc, 0xf6, 0xf0, 0xf9, 0xf5, 0xfb, 0xfa, 0xf5, - 0xf0, 0xfd, 0xfe, 0xf8, 0xf7, 0xfa, 0xfb, 0xf1, - 0xfa, 0xf3, 0xf4, 0xff, 0xfd, 0xf4, 0xf1, 0xf2, - 0xf5, 0xfb, 0xf8, 0xf6, 0xfc, 0xf7, 0xf6, 0xfc, - 0xf9, 0xf0, 0xf3, 0xf5, 0xf2, 0xfe, 0xff, 0xf9, - 0x2f, 0x23, 0x21, 0x2d, 0x28, 0x24, 0x2e, 0x27, - 0x26, 0x2f, 0x2b, 0x22, 0x23, 0x28, 0x24, 0x2e, - 0x29, 0x2c, 0x27, 0x20, 0x22, 0x21, 0x2d, 0x2a, - 0x2c, 0x26, 0x20, 0x29, 0x25, 0x2b, 0x2a, 0x25, - 0x20, 0x2d, 0x2e, 0x28, 0x27, 0x2a, 0x2b, 0x21, - 0x2a, 0x23, 0x24, 0x2f, 0x2d, 0x24, 0x21, 0x22, - 0x25, 0x2b, 0x28, 0x26, 0x2c, 0x27, 0x26, 0x2c, - 0x29, 0x20, 0x23, 0x25, 0x22, 0x2e, 0x2f, 0x29, - 0xbf, 0xb3, 0xb1, 0xbd, 0xb8, 0xb4, 0xbe, 0xb7, - 0xb6, 0xbf, 0xbb, 0xb2, 0xb3, 0xb8, 0xb4, 0xbe, - 0xb9, 0xbc, 0xb7, 0xb0, 0xb2, 0xb1, 0xbd, 0xba, - 0xbc, 0xb6, 0xb0, 0xb9, 0xb5, 0xbb, 0xba, 0xb5, - 0xb0, 0xbd, 0xbe, 0xb8, 0xb7, 0xba, 0xbb, 0xb1, - 0xba, 0xb3, 0xb4, 0xbf, 0xbd, 0xb4, 0xb1, 0xb2, - 0xb5, 0xbb, 0xb8, 0xb6, 0xbc, 0xb7, 0xb6, 0xbc, - 0xb9, 0xb0, 0xb3, 0xb5, 0xb2, 0xbe, 0xbf, 0xb9, - 0xdf, 0xd3, 0xd1, 0xdd, 0xd8, 0xd4, 0xde, 0xd7, - 0xd6, 0xdf, 0xdb, 0xd2, 0xd3, 0xd8, 0xd4, 0xde, - 0xd9, 0xdc, 0xd7, 0xd0, 0xd2, 0xd1, 0xdd, 0xda, - 0xdc, 0xd6, 0xd0, 0xd9, 0xd5, 0xdb, 0xda, 0xd5, - 0xd0, 0xdd, 0xde, 0xd8, 0xd7, 0xda, 0xdb, 0xd1, - 0xda, 0xd3, 0xd4, 0xdf, 0xdd, 0xd4, 0xd1, 0xd2, - 0xd5, 0xdb, 0xd8, 0xd6, 0xdc, 0xd7, 0xd6, 0xdc, - 0xd9, 0xd0, 0xd3, 0xd5, 0xd2, 0xde, 0xdf, 0xd9, - 0x8f, 0x83, 0x81, 0x8d, 0x88, 0x84, 0x8e, 0x87, - 0x86, 0x8f, 0x8b, 0x82, 0x83, 0x88, 0x84, 0x8e, - 0x89, 0x8c, 0x87, 0x80, 0x82, 0x81, 0x8d, 0x8a, - 0x8c, 0x86, 0x80, 0x89, 0x85, 0x8b, 0x8a, 0x85, - 0x80, 0x8d, 0x8e, 0x88, 0x87, 0x8a, 0x8b, 0x81, - 0x8a, 0x83, 0x84, 0x8f, 0x8d, 0x84, 0x81, 0x82, - 0x85, 0x8b, 0x88, 0x86, 0x8c, 0x87, 0x86, 0x8c, - 0x89, 0x80, 0x83, 0x85, 0x82, 0x8e, 0x8f, 0x89, - 0x1f, 0x13, 0x11, 0x1d, 0x18, 0x14, 0x1e, 0x17, - 0x16, 0x1f, 0x1b, 0x12, 0x13, 0x18, 0x14, 0x1e, - 0x19, 0x1c, 0x17, 0x10, 0x12, 0x11, 0x1d, 0x1a, - 0x1c, 0x16, 0x10, 0x19, 0x15, 0x1b, 0x1a, 0x15, - 0x10, 0x1d, 0x1e, 0x18, 0x17, 0x1a, 0x1b, 0x11, - 0x1a, 0x13, 0x14, 0x1f, 0x1d, 0x14, 0x11, 0x12, - 0x15, 0x1b, 0x18, 0x16, 0x1c, 0x17, 0x16, 0x1c, - 0x19, 0x10, 0x13, 0x15, 0x12, 0x1e, 0x1f, 0x19, - 0x3f, 0x33, 0x31, 0x3d, 0x38, 0x34, 0x3e, 0x37, - 0x36, 0x3f, 0x3b, 0x32, 0x33, 0x38, 0x34, 0x3e, - 0x39, 0x3c, 0x37, 0x30, 0x32, 0x31, 0x3d, 0x3a, - 0x3c, 0x36, 0x30, 0x39, 0x35, 0x3b, 0x3a, 0x35, - 0x30, 0x3d, 0x3e, 0x38, 0x37, 0x3a, 0x3b, 0x31, - 0x3a, 0x33, 0x34, 0x3f, 0x3d, 0x34, 0x31, 0x32, - 0x35, 0x3b, 0x38, 0x36, 0x3c, 0x37, 0x36, 0x3c, - 0x39, 0x30, 0x33, 0x35, 0x32, 0x3e, 0x3f, 0x39, - 0xaf, 0xa3, 0xa1, 0xad, 0xa8, 0xa4, 0xae, 0xa7, - 0xa6, 0xaf, 0xab, 0xa2, 0xa3, 0xa8, 0xa4, 0xae, - 0xa9, 0xac, 0xa7, 0xa0, 0xa2, 0xa1, 0xad, 0xaa, - 0xac, 0xa6, 0xa0, 0xa9, 0xa5, 0xab, 0xaa, 0xa5, - 0xa0, 0xad, 0xae, 0xa8, 0xa7, 0xaa, 0xab, 0xa1, - 0xaa, 0xa3, 0xa4, 0xaf, 0xad, 0xa4, 0xa1, 0xa2, - 0xa5, 0xab, 0xa8, 0xa6, 0xac, 0xa7, 0xa6, 0xac, - 0xa9, 0xa0, 0xa3, 0xa5, 0xa2, 0xae, 0xaf, 0xa9, - 0xaf, 0xa3, 0xa1, 0xad, 0xa8, 0xa4, 0xae, 0xa7, - 0xa6, 0xaf, 0xab, 0xa2, 0xa3, 0xa8, 0xa4, 0xae, - 0xa9, 0xac, 0xa7, 0xa0, 0xa2, 0xa1, 0xad, 0xaa, - 0xac, 0xa6, 0xa0, 0xa9, 0xa5, 0xab, 0xaa, 0xa5, - 0xa0, 0xad, 0xae, 0xa8, 0xa7, 0xaa, 0xab, 0xa1, - 0xaa, 0xa3, 0xa4, 0xaf, 0xad, 0xa4, 0xa1, 0xa2, - 0xa5, 0xab, 0xa8, 0xa6, 0xac, 0xa7, 0xa6, 0xac, - 0xa9, 0xa0, 0xa3, 0xa5, 0xa2, 0xae, 0xaf, 0xa9, - 0x6f, 0x63, 0x61, 0x6d, 0x68, 0x64, 0x6e, 0x67, - 0x66, 0x6f, 0x6b, 0x62, 0x63, 0x68, 0x64, 0x6e, - 0x69, 0x6c, 0x67, 0x60, 0x62, 0x61, 0x6d, 0x6a, - 0x6c, 0x66, 0x60, 0x69, 0x65, 0x6b, 0x6a, 0x65, - 0x60, 0x6d, 0x6e, 0x68, 0x67, 0x6a, 0x6b, 0x61, - 0x6a, 0x63, 0x64, 0x6f, 0x6d, 0x64, 0x61, 0x62, - 0x65, 0x6b, 0x68, 0x66, 0x6c, 0x67, 0x66, 0x6c, - 0x69, 0x60, 0x63, 0x65, 0x62, 0x6e, 0x6f, 0x69, - 0x6f, 0x63, 0x61, 0x6d, 0x68, 0x64, 0x6e, 0x67, - 0x66, 0x6f, 0x6b, 0x62, 0x63, 0x68, 0x64, 0x6e, - 0x69, 0x6c, 0x67, 0x60, 0x62, 0x61, 0x6d, 0x6a, - 0x6c, 0x66, 0x60, 0x69, 0x65, 0x6b, 0x6a, 0x65, - 0x60, 0x6d, 0x6e, 0x68, 0x67, 0x6a, 0x6b, 0x61, - 0x6a, 0x63, 0x64, 0x6f, 0x6d, 0x64, 0x61, 0x62, - 0x65, 0x6b, 0x68, 0x66, 0x6c, 0x67, 0x66, 0x6c, - 0x69, 0x60, 0x63, 0x65, 0x62, 0x6e, 0x6f, 0x69, - 0xcf, 0xc3, 0xc1, 0xcd, 0xc8, 0xc4, 0xce, 0xc7, - 0xc6, 0xcf, 0xcb, 0xc2, 0xc3, 0xc8, 0xc4, 0xce, - 0xc9, 0xcc, 0xc7, 0xc0, 0xc2, 0xc1, 0xcd, 0xca, - 0xcc, 0xc6, 0xc0, 0xc9, 0xc5, 0xcb, 0xca, 0xc5, - 0xc0, 0xcd, 0xce, 0xc8, 0xc7, 0xca, 0xcb, 0xc1, - 0xca, 0xc3, 0xc4, 0xcf, 0xcd, 0xc4, 0xc1, 0xc2, - 0xc5, 0xcb, 0xc8, 0xc6, 0xcc, 0xc7, 0xc6, 0xcc, - 0xc9, 0xc0, 0xc3, 0xc5, 0xc2, 0xce, 0xcf, 0xc9, - 0xcf, 0xc3, 0xc1, 0xcd, 0xc8, 0xc4, 0xce, 0xc7, - 0xc6, 0xcf, 0xcb, 0xc2, 0xc3, 0xc8, 0xc4, 0xce, - 0xc9, 0xcc, 0xc7, 0xc0, 0xc2, 0xc1, 0xcd, 0xca, - 0xcc, 0xc6, 0xc0, 0xc9, 0xc5, 0xcb, 0xca, 0xc5, - 0xc0, 0xcd, 0xce, 0xc8, 0xc7, 0xca, 0xcb, 0xc1, - 0xca, 0xc3, 0xc4, 0xcf, 0xcd, 0xc4, 0xc1, 0xc2, - 0xc5, 0xcb, 0xc8, 0xc6, 0xcc, 0xc7, 0xc6, 0xcc, - 0xc9, 0xc0, 0xc3, 0xc5, 0xc2, 0xce, 0xcf, 0xc9, - 0xbf, 0xb3, 0xb1, 0xbd, 0xb8, 0xb4, 0xbe, 0xb7, - 0xb6, 0xbf, 0xbb, 0xb2, 0xb3, 0xb8, 0xb4, 0xbe, - 0xb9, 0xbc, 0xb7, 0xb0, 0xb2, 0xb1, 0xbd, 0xba, - 0xbc, 0xb6, 0xb0, 0xb9, 0xb5, 0xbb, 0xba, 0xb5, - 0xb0, 0xbd, 0xbe, 0xb8, 0xb7, 0xba, 0xbb, 0xb1, - 0xba, 0xb3, 0xb4, 0xbf, 0xbd, 0xb4, 0xb1, 0xb2, - 0xb5, 0xbb, 0xb8, 0xb6, 0xbc, 0xb7, 0xb6, 0xbc, - 0xb9, 0xb0, 0xb3, 0xb5, 0xb2, 0xbe, 0xbf, 0xb9, - 0x5f, 0x53, 0x51, 0x5d, 0x58, 0x54, 0x5e, 0x57, - 0x56, 0x5f, 0x5b, 0x52, 0x53, 0x58, 0x54, 0x5e, - 0x59, 0x5c, 0x57, 0x50, 0x52, 0x51, 0x5d, 0x5a, - 0x5c, 0x56, 0x50, 0x59, 0x55, 0x5b, 0x5a, 0x55, - 0x50, 0x5d, 0x5e, 0x58, 0x57, 0x5a, 0x5b, 0x51, - 0x5a, 0x53, 0x54, 0x5f, 0x5d, 0x54, 0x51, 0x52, - 0x55, 0x5b, 0x58, 0x56, 0x5c, 0x57, 0x56, 0x5c, - 0x59, 0x50, 0x53, 0x55, 0x52, 0x5e, 0x5f, 0x59, - 0x9f, 0x93, 0x91, 0x9d, 0x98, 0x94, 0x9e, 0x97, - 0x96, 0x9f, 0x9b, 0x92, 0x93, 0x98, 0x94, 0x9e, - 0x99, 0x9c, 0x97, 0x90, 0x92, 0x91, 0x9d, 0x9a, - 0x9c, 0x96, 0x90, 0x99, 0x95, 0x9b, 0x9a, 0x95, - 0x90, 0x9d, 0x9e, 0x98, 0x97, 0x9a, 0x9b, 0x91, - 0x9a, 0x93, 0x94, 0x9f, 0x9d, 0x94, 0x91, 0x92, - 0x95, 0x9b, 0x98, 0x96, 0x9c, 0x97, 0x96, 0x9c, - 0x99, 0x90, 0x93, 0x95, 0x92, 0x9e, 0x9f, 0x99, - 0x9f, 0x93, 0x91, 0x9d, 0x98, 0x94, 0x9e, 0x97, - 0x96, 0x9f, 0x9b, 0x92, 0x93, 0x98, 0x94, 0x9e, - 0x99, 0x9c, 0x97, 0x90, 0x92, 0x91, 0x9d, 0x9a, - 0x9c, 0x96, 0x90, 0x99, 0x95, 0x9b, 0x9a, 0x95, - 0x90, 0x9d, 0x9e, 0x98, 0x97, 0x9a, 0x9b, 0x91, - 0x9a, 0x93, 0x94, 0x9f, 0x9d, 0x94, 0x91, 0x92, - 0x95, 0x9b, 0x98, 0x96, 0x9c, 0x97, 0x96, 0x9c, - 0x99, 0x90, 0x93, 0x95, 0x92, 0x9e, 0x9f, 0x99, - 0x5f, 0x53, 0x51, 0x5d, 0x58, 0x54, 0x5e, 0x57, - 0x56, 0x5f, 0x5b, 0x52, 0x53, 0x58, 0x54, 0x5e, - 0x59, 0x5c, 0x57, 0x50, 0x52, 0x51, 0x5d, 0x5a, - 0x5c, 0x56, 0x50, 0x59, 0x55, 0x5b, 0x5a, 0x55, - 0x50, 0x5d, 0x5e, 0x58, 0x57, 0x5a, 0x5b, 0x51, - 0x5a, 0x53, 0x54, 0x5f, 0x5d, 0x54, 0x51, 0x52, - 0x55, 0x5b, 0x58, 0x56, 0x5c, 0x57, 0x56, 0x5c, - 0x59, 0x50, 0x53, 0x55, 0x52, 0x5e, 0x5f, 0x59, - 0x0f, 0x03, 0x01, 0x0d, 0x08, 0x04, 0x0e, 0x07, - 0x06, 0x0f, 0x0b, 0x02, 0x03, 0x08, 0x04, 0x0e, - 0x09, 0x0c, 0x07, 0x00, 0x02, 0x01, 0x0d, 0x0a, - 0x0c, 0x06, 0x00, 0x09, 0x05, 0x0b, 0x0a, 0x05, - 0x00, 0x0d, 0x0e, 0x08, 0x07, 0x0a, 0x0b, 0x01, - 0x0a, 0x03, 0x04, 0x0f, 0x0d, 0x04, 0x01, 0x02, - 0x05, 0x0b, 0x08, 0x06, 0x0c, 0x07, 0x06, 0x0c, - 0x09, 0x00, 0x03, 0x05, 0x02, 0x0e, 0x0f, 0x09, - 0x3f, 0x33, 0x31, 0x3d, 0x38, 0x34, 0x3e, 0x37, - 0x36, 0x3f, 0x3b, 0x32, 0x33, 0x38, 0x34, 0x3e, - 0x39, 0x3c, 0x37, 0x30, 0x32, 0x31, 0x3d, 0x3a, - 0x3c, 0x36, 0x30, 0x39, 0x35, 0x3b, 0x3a, 0x35, - 0x30, 0x3d, 0x3e, 0x38, 0x37, 0x3a, 0x3b, 0x31, - 0x3a, 0x33, 0x34, 0x3f, 0x3d, 0x34, 0x31, 0x32, - 0x35, 0x3b, 0x38, 0x36, 0x3c, 0x37, 0x36, 0x3c, - 0x39, 0x30, 0x33, 0x35, 0x32, 0x3e, 0x3f, 0x39, - 0x7f, 0x73, 0x71, 0x7d, 0x78, 0x74, 0x7e, 0x77, - 0x76, 0x7f, 0x7b, 0x72, 0x73, 0x78, 0x74, 0x7e, - 0x79, 0x7c, 0x77, 0x70, 0x72, 0x71, 0x7d, 0x7a, - 0x7c, 0x76, 0x70, 0x79, 0x75, 0x7b, 0x7a, 0x75, - 0x70, 0x7d, 0x7e, 0x78, 0x77, 0x7a, 0x7b, 0x71, - 0x7a, 0x73, 0x74, 0x7f, 0x7d, 0x74, 0x71, 0x72, - 0x75, 0x7b, 0x78, 0x76, 0x7c, 0x77, 0x76, 0x7c, - 0x79, 0x70, 0x73, 0x75, 0x72, 0x7e, 0x7f, 0x79, - 0x8f, 0x83, 0x81, 0x8d, 0x88, 0x84, 0x8e, 0x87, - 0x86, 0x8f, 0x8b, 0x82, 0x83, 0x88, 0x84, 0x8e, - 0x89, 0x8c, 0x87, 0x80, 0x82, 0x81, 0x8d, 0x8a, - 0x8c, 0x86, 0x80, 0x89, 0x85, 0x8b, 0x8a, 0x85, - 0x80, 0x8d, 0x8e, 0x88, 0x87, 0x8a, 0x8b, 0x81, - 0x8a, 0x83, 0x84, 0x8f, 0x8d, 0x84, 0x81, 0x82, - 0x85, 0x8b, 0x88, 0x86, 0x8c, 0x87, 0x86, 0x8c, - 0x89, 0x80, 0x83, 0x85, 0x82, 0x8e, 0x8f, 0x89, - 0x4f, 0x43, 0x41, 0x4d, 0x48, 0x44, 0x4e, 0x47, - 0x46, 0x4f, 0x4b, 0x42, 0x43, 0x48, 0x44, 0x4e, - 0x49, 0x4c, 0x47, 0x40, 0x42, 0x41, 0x4d, 0x4a, - 0x4c, 0x46, 0x40, 0x49, 0x45, 0x4b, 0x4a, 0x45, - 0x40, 0x4d, 0x4e, 0x48, 0x47, 0x4a, 0x4b, 0x41, - 0x4a, 0x43, 0x44, 0x4f, 0x4d, 0x44, 0x41, 0x42, - 0x45, 0x4b, 0x48, 0x46, 0x4c, 0x47, 0x46, 0x4c, - 0x49, 0x40, 0x43, 0x45, 0x42, 0x4e, 0x4f, 0x49, - 0xff, 0xf3, 0xf1, 0xfd, 0xf8, 0xf4, 0xfe, 0xf7, - 0xf6, 0xff, 0xfb, 0xf2, 0xf3, 0xf8, 0xf4, 0xfe, - 0xf9, 0xfc, 0xf7, 0xf0, 0xf2, 0xf1, 0xfd, 0xfa, - 0xfc, 0xf6, 0xf0, 0xf9, 0xf5, 0xfb, 0xfa, 0xf5, - 0xf0, 0xfd, 0xfe, 0xf8, 0xf7, 0xfa, 0xfb, 0xf1, - 0xfa, 0xf3, 0xf4, 0xff, 0xfd, 0xf4, 0xf1, 0xf2, - 0xf5, 0xfb, 0xf8, 0xf6, 0xfc, 0xf7, 0xf6, 0xfc, - 0xf9, 0xf0, 0xf3, 0xf5, 0xf2, 0xfe, 0xff, 0xf9, - 0x1f, 0x13, 0x11, 0x1d, 0x18, 0x14, 0x1e, 0x17, - 0x16, 0x1f, 0x1b, 0x12, 0x13, 0x18, 0x14, 0x1e, - 0x19, 0x1c, 0x17, 0x10, 0x12, 0x11, 0x1d, 0x1a, - 0x1c, 0x16, 0x10, 0x19, 0x15, 0x1b, 0x1a, 0x15, - 0x10, 0x1d, 0x1e, 0x18, 0x17, 0x1a, 0x1b, 0x11, - 0x1a, 0x13, 0x14, 0x1f, 0x1d, 0x14, 0x11, 0x12, - 0x15, 0x1b, 0x18, 0x16, 0x1c, 0x17, 0x16, 0x1c, - 0x19, 0x10, 0x13, 0x15, 0x12, 0x1e, 0x1f, 0x19, - 0xcf, 0xc3, 0xc1, 0xcd, 0xc8, 0xc4, 0xce, 0xc7, - 0xc6, 0xcf, 0xcb, 0xc2, 0xc3, 0xc8, 0xc4, 0xce, - 0xc9, 0xcc, 0xc7, 0xc0, 0xc2, 0xc1, 0xcd, 0xca, - 0xcc, 0xc6, 0xc0, 0xc9, 0xc5, 0xcb, 0xca, 0xc5, - 0xc0, 0xcd, 0xce, 0xc8, 0xc7, 0xca, 0xcb, 0xc1, - 0xca, 0xc3, 0xc4, 0xcf, 0xcd, 0xc4, 0xc1, 0xc2, - 0xc5, 0xcb, 0xc8, 0xc6, 0xcc, 0xc7, 0xc6, 0xcc, - 0xc9, 0xc0, 0xc3, 0xc5, 0xc2, 0xce, 0xcf, 0xc9, - 0xef, 0xe3, 0xe1, 0xed, 0xe8, 0xe4, 0xee, 0xe7, - 0xe6, 0xef, 0xeb, 0xe2, 0xe3, 0xe8, 0xe4, 0xee, - 0xe9, 0xec, 0xe7, 0xe0, 0xe2, 0xe1, 0xed, 0xea, - 0xec, 0xe6, 0xe0, 0xe9, 0xe5, 0xeb, 0xea, 0xe5, - 0xe0, 0xed, 0xee, 0xe8, 0xe7, 0xea, 0xeb, 0xe1, - 0xea, 0xe3, 0xe4, 0xef, 0xed, 0xe4, 0xe1, 0xe2, - 0xe5, 0xeb, 0xe8, 0xe6, 0xec, 0xe7, 0xe6, 0xec, - 0xe9, 0xe0, 0xe3, 0xe5, 0xe2, 0xee, 0xef, 0xe9, - 0x8f, 0x83, 0x81, 0x8d, 0x88, 0x84, 0x8e, 0x87, - 0x86, 0x8f, 0x8b, 0x82, 0x83, 0x88, 0x84, 0x8e, - 0x89, 0x8c, 0x87, 0x80, 0x82, 0x81, 0x8d, 0x8a, - 0x8c, 0x86, 0x80, 0x89, 0x85, 0x8b, 0x8a, 0x85, - 0x80, 0x8d, 0x8e, 0x88, 0x87, 0x8a, 0x8b, 0x81, - 0x8a, 0x83, 0x84, 0x8f, 0x8d, 0x84, 0x81, 0x82, - 0x85, 0x8b, 0x88, 0x86, 0x8c, 0x87, 0x86, 0x8c, - 0x89, 0x80, 0x83, 0x85, 0x82, 0x8e, 0x8f, 0x89, - 0x8f, 0x83, 0x81, 0x8d, 0x88, 0x84, 0x8e, 0x87, - 0x86, 0x8f, 0x8b, 0x82, 0x83, 0x88, 0x84, 0x8e, - 0x89, 0x8c, 0x87, 0x80, 0x82, 0x81, 0x8d, 0x8a, - 0x8c, 0x86, 0x80, 0x89, 0x85, 0x8b, 0x8a, 0x85, - 0x80, 0x8d, 0x8e, 0x88, 0x87, 0x8a, 0x8b, 0x81, - 0x8a, 0x83, 0x84, 0x8f, 0x8d, 0x84, 0x81, 0x82, - 0x85, 0x8b, 0x88, 0x86, 0x8c, 0x87, 0x86, 0x8c, - 0x89, 0x80, 0x83, 0x85, 0x82, 0x8e, 0x8f, 0x89, - 0x2f, 0x23, 0x21, 0x2d, 0x28, 0x24, 0x2e, 0x27, - 0x26, 0x2f, 0x2b, 0x22, 0x23, 0x28, 0x24, 0x2e, - 0x29, 0x2c, 0x27, 0x20, 0x22, 0x21, 0x2d, 0x2a, - 0x2c, 0x26, 0x20, 0x29, 0x25, 0x2b, 0x2a, 0x25, - 0x20, 0x2d, 0x2e, 0x28, 0x27, 0x2a, 0x2b, 0x21, - 0x2a, 0x23, 0x24, 0x2f, 0x2d, 0x24, 0x21, 0x22, - 0x25, 0x2b, 0x28, 0x26, 0x2c, 0x27, 0x26, 0x2c, - 0x29, 0x20, 0x23, 0x25, 0x22, 0x2e, 0x2f, 0x29, - 0xdf, 0xd3, 0xd1, 0xdd, 0xd8, 0xd4, 0xde, 0xd7, - 0xd6, 0xdf, 0xdb, 0xd2, 0xd3, 0xd8, 0xd4, 0xde, - 0xd9, 0xdc, 0xd7, 0xd0, 0xd2, 0xd1, 0xdd, 0xda, - 0xdc, 0xd6, 0xd0, 0xd9, 0xd5, 0xdb, 0xda, 0xd5, - 0xd0, 0xdd, 0xde, 0xd8, 0xd7, 0xda, 0xdb, 0xd1, - 0xda, 0xd3, 0xd4, 0xdf, 0xdd, 0xd4, 0xd1, 0xd2, - 0xd5, 0xdb, 0xd8, 0xd6, 0xdc, 0xd7, 0xd6, 0xdc, - 0xd9, 0xd0, 0xd3, 0xd5, 0xd2, 0xde, 0xdf, 0xd9, - 0x4f, 0x43, 0x41, 0x4d, 0x48, 0x44, 0x4e, 0x47, - 0x46, 0x4f, 0x4b, 0x42, 0x43, 0x48, 0x44, 0x4e, - 0x49, 0x4c, 0x47, 0x40, 0x42, 0x41, 0x4d, 0x4a, - 0x4c, 0x46, 0x40, 0x49, 0x45, 0x4b, 0x4a, 0x45, - 0x40, 0x4d, 0x4e, 0x48, 0x47, 0x4a, 0x4b, 0x41, - 0x4a, 0x43, 0x44, 0x4f, 0x4d, 0x44, 0x41, 0x42, - 0x45, 0x4b, 0x48, 0x46, 0x4c, 0x47, 0x46, 0x4c, - 0x49, 0x40, 0x43, 0x45, 0x42, 0x4e, 0x4f, 0x49, - 0x6f, 0x63, 0x61, 0x6d, 0x68, 0x64, 0x6e, 0x67, - 0x66, 0x6f, 0x6b, 0x62, 0x63, 0x68, 0x64, 0x6e, - 0x69, 0x6c, 0x67, 0x60, 0x62, 0x61, 0x6d, 0x6a, - 0x6c, 0x66, 0x60, 0x69, 0x65, 0x6b, 0x6a, 0x65, - 0x60, 0x6d, 0x6e, 0x68, 0x67, 0x6a, 0x6b, 0x61, - 0x6a, 0x63, 0x64, 0x6f, 0x6d, 0x64, 0x61, 0x62, - 0x65, 0x6b, 0x68, 0x66, 0x6c, 0x67, 0x66, 0x6c, - 0x69, 0x60, 0x63, 0x65, 0x62, 0x6e, 0x6f, 0x69, - 0x9f, 0x93, 0x91, 0x9d, 0x98, 0x94, 0x9e, 0x97, - 0x96, 0x9f, 0x9b, 0x92, 0x93, 0x98, 0x94, 0x9e, - 0x99, 0x9c, 0x97, 0x90, 0x92, 0x91, 0x9d, 0x9a, - 0x9c, 0x96, 0x90, 0x99, 0x95, 0x9b, 0x9a, 0x95, - 0x90, 0x9d, 0x9e, 0x98, 0x97, 0x9a, 0x9b, 0x91, - 0x9a, 0x93, 0x94, 0x9f, 0x9d, 0x94, 0x91, 0x92, - 0x95, 0x9b, 0x98, 0x96, 0x9c, 0x97, 0x96, 0x9c, - 0x99, 0x90, 0x93, 0x95, 0x92, 0x9e, 0x9f, 0x99, - 0x2f, 0x23, 0x21, 0x2d, 0x28, 0x24, 0x2e, 0x27, - 0x26, 0x2f, 0x2b, 0x22, 0x23, 0x28, 0x24, 0x2e, - 0x29, 0x2c, 0x27, 0x20, 0x22, 0x21, 0x2d, 0x2a, - 0x2c, 0x26, 0x20, 0x29, 0x25, 0x2b, 0x2a, 0x25, - 0x20, 0x2d, 0x2e, 0x28, 0x27, 0x2a, 0x2b, 0x21, - 0x2a, 0x23, 0x24, 0x2f, 0x2d, 0x24, 0x21, 0x22, - 0x25, 0x2b, 0x28, 0x26, 0x2c, 0x27, 0x26, 0x2c, - 0x29, 0x20, 0x23, 0x25, 0x22, 0x2e, 0x2f, 0x29, - 0x1f, 0x13, 0x11, 0x1d, 0x18, 0x14, 0x1e, 0x17, - 0x16, 0x1f, 0x1b, 0x12, 0x13, 0x18, 0x14, 0x1e, - 0x19, 0x1c, 0x17, 0x10, 0x12, 0x11, 0x1d, 0x1a, - 0x1c, 0x16, 0x10, 0x19, 0x15, 0x1b, 0x1a, 0x15, - 0x10, 0x1d, 0x1e, 0x18, 0x17, 0x1a, 0x1b, 0x11, - 0x1a, 0x13, 0x14, 0x1f, 0x1d, 0x14, 0x11, 0x12, - 0x15, 0x1b, 0x18, 0x16, 0x1c, 0x17, 0x16, 0x1c, - 0x19, 0x10, 0x13, 0x15, 0x12, 0x1e, 0x1f, 0x19, - 0xbf, 0xb3, 0xb1, 0xbd, 0xb8, 0xb4, 0xbe, 0xb7, - 0xb6, 0xbf, 0xbb, 0xb2, 0xb3, 0xb8, 0xb4, 0xbe, - 0xb9, 0xbc, 0xb7, 0xb0, 0xb2, 0xb1, 0xbd, 0xba, - 0xbc, 0xb6, 0xb0, 0xb9, 0xb5, 0xbb, 0xba, 0xb5, - 0xb0, 0xbd, 0xbe, 0xb8, 0xb7, 0xba, 0xbb, 0xb1, - 0xba, 0xb3, 0xb4, 0xbf, 0xbd, 0xb4, 0xb1, 0xb2, - 0xb5, 0xbb, 0xb8, 0xb6, 0xbc, 0xb7, 0xb6, 0xbc, - 0xb9, 0xb0, 0xb3, 0xb5, 0xb2, 0xbe, 0xbf, 0xb9, - 0x7f, 0x73, 0x71, 0x7d, 0x78, 0x74, 0x7e, 0x77, - 0x76, 0x7f, 0x7b, 0x72, 0x73, 0x78, 0x74, 0x7e, - 0x79, 0x7c, 0x77, 0x70, 0x72, 0x71, 0x7d, 0x7a, - 0x7c, 0x76, 0x70, 0x79, 0x75, 0x7b, 0x7a, 0x75, - 0x70, 0x7d, 0x7e, 0x78, 0x77, 0x7a, 0x7b, 0x71, - 0x7a, 0x73, 0x74, 0x7f, 0x7d, 0x74, 0x71, 0x72, - 0x75, 0x7b, 0x78, 0x76, 0x7c, 0x77, 0x76, 0x7c, - 0x79, 0x70, 0x73, 0x75, 0x72, 0x7e, 0x7f, 0x79, - 0xff, 0xf3, 0xf1, 0xfd, 0xf8, 0xf4, 0xfe, 0xf7, - 0xf6, 0xff, 0xfb, 0xf2, 0xf3, 0xf8, 0xf4, 0xfe, - 0xf9, 0xfc, 0xf7, 0xf0, 0xf2, 0xf1, 0xfd, 0xfa, - 0xfc, 0xf6, 0xf0, 0xf9, 0xf5, 0xfb, 0xfa, 0xf5, - 0xf0, 0xfd, 0xfe, 0xf8, 0xf7, 0xfa, 0xfb, 0xf1, - 0xfa, 0xf3, 0xf4, 0xff, 0xfd, 0xf4, 0xf1, 0xf2, - 0xf5, 0xfb, 0xf8, 0xf6, 0xfc, 0xf7, 0xf6, 0xfc, - 0xf9, 0xf0, 0xf3, 0xf5, 0xf2, 0xfe, 0xff, 0xf9, - 0x5f, 0x53, 0x51, 0x5d, 0x58, 0x54, 0x5e, 0x57, - 0x56, 0x5f, 0x5b, 0x52, 0x53, 0x58, 0x54, 0x5e, - 0x59, 0x5c, 0x57, 0x50, 0x52, 0x51, 0x5d, 0x5a, - 0x5c, 0x56, 0x50, 0x59, 0x55, 0x5b, 0x5a, 0x55, - 0x50, 0x5d, 0x5e, 0x58, 0x57, 0x5a, 0x5b, 0x51, - 0x5a, 0x53, 0x54, 0x5f, 0x5d, 0x54, 0x51, 0x52, - 0x55, 0x5b, 0x58, 0x56, 0x5c, 0x57, 0x56, 0x5c, - 0x59, 0x50, 0x53, 0x55, 0x52, 0x5e, 0x5f, 0x59, - 0xcf, 0xc3, 0xc1, 0xcd, 0xc8, 0xc4, 0xce, 0xc7, - 0xc6, 0xcf, 0xcb, 0xc2, 0xc3, 0xc8, 0xc4, 0xce, - 0xc9, 0xcc, 0xc7, 0xc0, 0xc2, 0xc1, 0xcd, 0xca, - 0xcc, 0xc6, 0xc0, 0xc9, 0xc5, 0xcb, 0xca, 0xc5, - 0xc0, 0xcd, 0xce, 0xc8, 0xc7, 0xca, 0xcb, 0xc1, - 0xca, 0xc3, 0xc4, 0xcf, 0xcd, 0xc4, 0xc1, 0xc2, - 0xc5, 0xcb, 0xc8, 0xc6, 0xcc, 0xc7, 0xc6, 0xcc, - 0xc9, 0xc0, 0xc3, 0xc5, 0xc2, 0xce, 0xcf, 0xc9, - 0xbf, 0xb3, 0xb1, 0xbd, 0xb8, 0xb4, 0xbe, 0xb7, - 0xb6, 0xbf, 0xbb, 0xb2, 0xb3, 0xb8, 0xb4, 0xbe, - 0xb9, 0xbc, 0xb7, 0xb0, 0xb2, 0xb1, 0xbd, 0xba, - 0xbc, 0xb6, 0xb0, 0xb9, 0xb5, 0xbb, 0xba, 0xb5, - 0xb0, 0xbd, 0xbe, 0xb8, 0xb7, 0xba, 0xbb, 0xb1, - 0xba, 0xb3, 0xb4, 0xbf, 0xbd, 0xb4, 0xb1, 0xb2, - 0xb5, 0xbb, 0xb8, 0xb6, 0xbc, 0xb7, 0xb6, 0xbc, - 0xb9, 0xb0, 0xb3, 0xb5, 0xb2, 0xbe, 0xbf, 0xb9, - 0x9f, 0x93, 0x91, 0x9d, 0x98, 0x94, 0x9e, 0x97, - 0x96, 0x9f, 0x9b, 0x92, 0x93, 0x98, 0x94, 0x9e, - 0x99, 0x9c, 0x97, 0x90, 0x92, 0x91, 0x9d, 0x9a, - 0x9c, 0x96, 0x90, 0x99, 0x95, 0x9b, 0x9a, 0x95, - 0x90, 0x9d, 0x9e, 0x98, 0x97, 0x9a, 0x9b, 0x91, - 0x9a, 0x93, 0x94, 0x9f, 0x9d, 0x94, 0x91, 0x92, - 0x95, 0x9b, 0x98, 0x96, 0x9c, 0x97, 0x96, 0x9c, - 0x99, 0x90, 0x93, 0x95, 0x92, 0x9e, 0x9f, 0x99, - 0x3f, 0x33, 0x31, 0x3d, 0x38, 0x34, 0x3e, 0x37, - 0x36, 0x3f, 0x3b, 0x32, 0x33, 0x38, 0x34, 0x3e, - 0x39, 0x3c, 0x37, 0x30, 0x32, 0x31, 0x3d, 0x3a, - 0x3c, 0x36, 0x30, 0x39, 0x35, 0x3b, 0x3a, 0x35, - 0x30, 0x3d, 0x3e, 0x38, 0x37, 0x3a, 0x3b, 0x31, - 0x3a, 0x33, 0x34, 0x3f, 0x3d, 0x34, 0x31, 0x32, - 0x35, 0x3b, 0x38, 0x36, 0x3c, 0x37, 0x36, 0x3c, - 0x39, 0x30, 0x33, 0x35, 0x32, 0x3e, 0x3f, 0x39, - 0x7f, 0x73, 0x71, 0x7d, 0x78, 0x74, 0x7e, 0x77, - 0x76, 0x7f, 0x7b, 0x72, 0x73, 0x78, 0x74, 0x7e, - 0x79, 0x7c, 0x77, 0x70, 0x72, 0x71, 0x7d, 0x7a, - 0x7c, 0x76, 0x70, 0x79, 0x75, 0x7b, 0x7a, 0x75, - 0x70, 0x7d, 0x7e, 0x78, 0x77, 0x7a, 0x7b, 0x71, - 0x7a, 0x73, 0x74, 0x7f, 0x7d, 0x74, 0x71, 0x72, - 0x75, 0x7b, 0x78, 0x76, 0x7c, 0x77, 0x76, 0x7c, - 0x79, 0x70, 0x73, 0x75, 0x72, 0x7e, 0x7f, 0x79, - 0xef, 0xe3, 0xe1, 0xed, 0xe8, 0xe4, 0xee, 0xe7, - 0xe6, 0xef, 0xeb, 0xe2, 0xe3, 0xe8, 0xe4, 0xee, - 0xe9, 0xec, 0xe7, 0xe0, 0xe2, 0xe1, 0xed, 0xea, - 0xec, 0xe6, 0xe0, 0xe9, 0xe5, 0xeb, 0xea, 0xe5, - 0xe0, 0xed, 0xee, 0xe8, 0xe7, 0xea, 0xeb, 0xe1, - 0xea, 0xe3, 0xe4, 0xef, 0xed, 0xe4, 0xe1, 0xe2, - 0xe5, 0xeb, 0xe8, 0xe6, 0xec, 0xe7, 0xe6, 0xec, - 0xe9, 0xe0, 0xe3, 0xe5, 0xe2, 0xee, 0xef, 0xe9, - 0x3f, 0x33, 0x31, 0x3d, 0x38, 0x34, 0x3e, 0x37, - 0x36, 0x3f, 0x3b, 0x32, 0x33, 0x38, 0x34, 0x3e, - 0x39, 0x3c, 0x37, 0x30, 0x32, 0x31, 0x3d, 0x3a, - 0x3c, 0x36, 0x30, 0x39, 0x35, 0x3b, 0x3a, 0x35, - 0x30, 0x3d, 0x3e, 0x38, 0x37, 0x3a, 0x3b, 0x31, - 0x3a, 0x33, 0x34, 0x3f, 0x3d, 0x34, 0x31, 0x32, - 0x35, 0x3b, 0x38, 0x36, 0x3c, 0x37, 0x36, 0x3c, - 0x39, 0x30, 0x33, 0x35, 0x32, 0x3e, 0x3f, 0x39, - 0xaf, 0xa3, 0xa1, 0xad, 0xa8, 0xa4, 0xae, 0xa7, - 0xa6, 0xaf, 0xab, 0xa2, 0xa3, 0xa8, 0xa4, 0xae, - 0xa9, 0xac, 0xa7, 0xa0, 0xa2, 0xa1, 0xad, 0xaa, - 0xac, 0xa6, 0xa0, 0xa9, 0xa5, 0xab, 0xaa, 0xa5, - 0xa0, 0xad, 0xae, 0xa8, 0xa7, 0xaa, 0xab, 0xa1, - 0xaa, 0xa3, 0xa4, 0xaf, 0xad, 0xa4, 0xa1, 0xa2, - 0xa5, 0xab, 0xa8, 0xa6, 0xac, 0xa7, 0xa6, 0xac, - 0xa9, 0xa0, 0xa3, 0xa5, 0xa2, 0xae, 0xaf, 0xa9, - 0xaf, 0xa3, 0xa1, 0xad, 0xa8, 0xa4, 0xae, 0xa7, - 0xa6, 0xaf, 0xab, 0xa2, 0xa3, 0xa8, 0xa4, 0xae, - 0xa9, 0xac, 0xa7, 0xa0, 0xa2, 0xa1, 0xad, 0xaa, - 0xac, 0xa6, 0xa0, 0xa9, 0xa5, 0xab, 0xaa, 0xa5, - 0xa0, 0xad, 0xae, 0xa8, 0xa7, 0xaa, 0xab, 0xa1, - 0xaa, 0xa3, 0xa4, 0xaf, 0xad, 0xa4, 0xa1, 0xa2, - 0xa5, 0xab, 0xa8, 0xa6, 0xac, 0xa7, 0xa6, 0xac, - 0xa9, 0xa0, 0xa3, 0xa5, 0xa2, 0xae, 0xaf, 0xa9, - 0x0f, 0x03, 0x01, 0x0d, 0x08, 0x04, 0x0e, 0x07, - 0x06, 0x0f, 0x0b, 0x02, 0x03, 0x08, 0x04, 0x0e, - 0x09, 0x0c, 0x07, 0x00, 0x02, 0x01, 0x0d, 0x0a, - 0x0c, 0x06, 0x00, 0x09, 0x05, 0x0b, 0x0a, 0x05, - 0x00, 0x0d, 0x0e, 0x08, 0x07, 0x0a, 0x0b, 0x01, - 0x0a, 0x03, 0x04, 0x0f, 0x0d, 0x04, 0x01, 0x02, - 0x05, 0x0b, 0x08, 0x06, 0x0c, 0x07, 0x06, 0x0c, - 0x09, 0x00, 0x03, 0x05, 0x02, 0x0e, 0x0f, 0x09, - 0x5f, 0x53, 0x51, 0x5d, 0x58, 0x54, 0x5e, 0x57, - 0x56, 0x5f, 0x5b, 0x52, 0x53, 0x58, 0x54, 0x5e, - 0x59, 0x5c, 0x57, 0x50, 0x52, 0x51, 0x5d, 0x5a, - 0x5c, 0x56, 0x50, 0x59, 0x55, 0x5b, 0x5a, 0x55, - 0x50, 0x5d, 0x5e, 0x58, 0x57, 0x5a, 0x5b, 0x51, - 0x5a, 0x53, 0x54, 0x5f, 0x5d, 0x54, 0x51, 0x52, - 0x55, 0x5b, 0x58, 0x56, 0x5c, 0x57, 0x56, 0x5c, - 0x59, 0x50, 0x53, 0x55, 0x52, 0x5e, 0x5f, 0x59, - 0x6f, 0x63, 0x61, 0x6d, 0x68, 0x64, 0x6e, 0x67, - 0x66, 0x6f, 0x6b, 0x62, 0x63, 0x68, 0x64, 0x6e, - 0x69, 0x6c, 0x67, 0x60, 0x62, 0x61, 0x6d, 0x6a, - 0x6c, 0x66, 0x60, 0x69, 0x65, 0x6b, 0x6a, 0x65, - 0x60, 0x6d, 0x6e, 0x68, 0x67, 0x6a, 0x6b, 0x61, - 0x6a, 0x63, 0x64, 0x6f, 0x6d, 0x64, 0x61, 0x62, - 0x65, 0x6b, 0x68, 0x66, 0x6c, 0x67, 0x66, 0x6c, - 0x69, 0x60, 0x63, 0x65, 0x62, 0x6e, 0x6f, 0x69, - 0x0f, 0x03, 0x01, 0x0d, 0x08, 0x04, 0x0e, 0x07, - 0x06, 0x0f, 0x0b, 0x02, 0x03, 0x08, 0x04, 0x0e, - 0x09, 0x0c, 0x07, 0x00, 0x02, 0x01, 0x0d, 0x0a, - 0x0c, 0x06, 0x00, 0x09, 0x05, 0x0b, 0x0a, 0x05, - 0x00, 0x0d, 0x0e, 0x08, 0x07, 0x0a, 0x0b, 0x01, - 0x0a, 0x03, 0x04, 0x0f, 0x0d, 0x04, 0x01, 0x02, - 0x05, 0x0b, 0x08, 0x06, 0x0c, 0x07, 0x06, 0x0c, - 0x09, 0x00, 0x03, 0x05, 0x02, 0x0e, 0x0f, 0x09, - 0xdf, 0xd3, 0xd1, 0xdd, 0xd8, 0xd4, 0xde, 0xd7, - 0xd6, 0xdf, 0xdb, 0xd2, 0xd3, 0xd8, 0xd4, 0xde, - 0xd9, 0xdc, 0xd7, 0xd0, 0xd2, 0xd1, 0xdd, 0xda, - 0xdc, 0xd6, 0xd0, 0xd9, 0xd5, 0xdb, 0xda, 0xd5, - 0xd0, 0xdd, 0xde, 0xd8, 0xd7, 0xda, 0xdb, 0xd1, - 0xda, 0xd3, 0xd4, 0xdf, 0xdd, 0xd4, 0xd1, 0xd2, - 0xd5, 0xdb, 0xd8, 0xd6, 0xdc, 0xd7, 0xd6, 0xdc, - 0xd9, 0xd0, 0xd3, 0xd5, 0xd2, 0xde, 0xdf, 0xd9, - },{ - 0xa7, 0xad, 0xad, 0xa8, 0xae, 0xab, 0xa3, 0xa5, - 0xa0, 0xa6, 0xa6, 0xaf, 0xa9, 0xa0, 0xaa, 0xa3, - 0xa1, 0xa4, 0xa2, 0xa7, 0xa8, 0xa2, 0xa5, 0xac, - 0xab, 0xa1, 0xac, 0xaa, 0xa4, 0xae, 0xaf, 0xa9, - 0xaa, 0xa3, 0xa6, 0xaf, 0xa9, 0xa0, 0xa0, 0xa6, - 0xac, 0xaa, 0xab, 0xa1, 0xa7, 0xad, 0xad, 0xa8, - 0xaf, 0xa9, 0xa1, 0xa4, 0xa3, 0xa5, 0xae, 0xab, - 0xa5, 0xac, 0xa2, 0xa7, 0xa8, 0xa2, 0xa4, 0xae, - 0xd7, 0xdd, 0xdd, 0xd8, 0xde, 0xdb, 0xd3, 0xd5, - 0xd0, 0xd6, 0xd6, 0xdf, 0xd9, 0xd0, 0xda, 0xd3, - 0xd1, 0xd4, 0xd2, 0xd7, 0xd8, 0xd2, 0xd5, 0xdc, - 0xdb, 0xd1, 0xdc, 0xda, 0xd4, 0xde, 0xdf, 0xd9, - 0xda, 0xd3, 0xd6, 0xdf, 0xd9, 0xd0, 0xd0, 0xd6, - 0xdc, 0xda, 0xdb, 0xd1, 0xd7, 0xdd, 0xdd, 0xd8, - 0xdf, 0xd9, 0xd1, 0xd4, 0xd3, 0xd5, 0xde, 0xdb, - 0xd5, 0xdc, 0xd2, 0xd7, 0xd8, 0xd2, 0xd4, 0xde, - 0x07, 0x0d, 0x0d, 0x08, 0x0e, 0x0b, 0x03, 0x05, - 0x00, 0x06, 0x06, 0x0f, 0x09, 0x00, 0x0a, 0x03, - 0x01, 0x04, 0x02, 0x07, 0x08, 0x02, 0x05, 0x0c, - 0x0b, 0x01, 0x0c, 0x0a, 0x04, 0x0e, 0x0f, 0x09, - 0x0a, 0x03, 0x06, 0x0f, 0x09, 0x00, 0x00, 0x06, - 0x0c, 0x0a, 0x0b, 0x01, 0x07, 0x0d, 0x0d, 0x08, - 0x0f, 0x09, 0x01, 0x04, 0x03, 0x05, 0x0e, 0x0b, - 0x05, 0x0c, 0x02, 0x07, 0x08, 0x02, 0x04, 0x0e, - 0x77, 0x7d, 0x7d, 0x78, 0x7e, 0x7b, 0x73, 0x75, - 0x70, 0x76, 0x76, 0x7f, 0x79, 0x70, 0x7a, 0x73, - 0x71, 0x74, 0x72, 0x77, 0x78, 0x72, 0x75, 0x7c, - 0x7b, 0x71, 0x7c, 0x7a, 0x74, 0x7e, 0x7f, 0x79, - 0x7a, 0x73, 0x76, 0x7f, 0x79, 0x70, 0x70, 0x76, - 0x7c, 0x7a, 0x7b, 0x71, 0x77, 0x7d, 0x7d, 0x78, - 0x7f, 0x79, 0x71, 0x74, 0x73, 0x75, 0x7e, 0x7b, - 0x75, 0x7c, 0x72, 0x77, 0x78, 0x72, 0x74, 0x7e, - 0x97, 0x9d, 0x9d, 0x98, 0x9e, 0x9b, 0x93, 0x95, - 0x90, 0x96, 0x96, 0x9f, 0x99, 0x90, 0x9a, 0x93, - 0x91, 0x94, 0x92, 0x97, 0x98, 0x92, 0x95, 0x9c, - 0x9b, 0x91, 0x9c, 0x9a, 0x94, 0x9e, 0x9f, 0x99, - 0x9a, 0x93, 0x96, 0x9f, 0x99, 0x90, 0x90, 0x96, - 0x9c, 0x9a, 0x9b, 0x91, 0x97, 0x9d, 0x9d, 0x98, - 0x9f, 0x99, 0x91, 0x94, 0x93, 0x95, 0x9e, 0x9b, - 0x95, 0x9c, 0x92, 0x97, 0x98, 0x92, 0x94, 0x9e, - 0x07, 0x0d, 0x0d, 0x08, 0x0e, 0x0b, 0x03, 0x05, - 0x00, 0x06, 0x06, 0x0f, 0x09, 0x00, 0x0a, 0x03, - 0x01, 0x04, 0x02, 0x07, 0x08, 0x02, 0x05, 0x0c, - 0x0b, 0x01, 0x0c, 0x0a, 0x04, 0x0e, 0x0f, 0x09, - 0x0a, 0x03, 0x06, 0x0f, 0x09, 0x00, 0x00, 0x06, - 0x0c, 0x0a, 0x0b, 0x01, 0x07, 0x0d, 0x0d, 0x08, - 0x0f, 0x09, 0x01, 0x04, 0x03, 0x05, 0x0e, 0x0b, - 0x05, 0x0c, 0x02, 0x07, 0x08, 0x02, 0x04, 0x0e, - 0xe7, 0xed, 0xed, 0xe8, 0xee, 0xeb, 0xe3, 0xe5, - 0xe0, 0xe6, 0xe6, 0xef, 0xe9, 0xe0, 0xea, 0xe3, - 0xe1, 0xe4, 0xe2, 0xe7, 0xe8, 0xe2, 0xe5, 0xec, - 0xeb, 0xe1, 0xec, 0xea, 0xe4, 0xee, 0xef, 0xe9, - 0xea, 0xe3, 0xe6, 0xef, 0xe9, 0xe0, 0xe0, 0xe6, - 0xec, 0xea, 0xeb, 0xe1, 0xe7, 0xed, 0xed, 0xe8, - 0xef, 0xe9, 0xe1, 0xe4, 0xe3, 0xe5, 0xee, 0xeb, - 0xe5, 0xec, 0xe2, 0xe7, 0xe8, 0xe2, 0xe4, 0xee, - 0x97, 0x9d, 0x9d, 0x98, 0x9e, 0x9b, 0x93, 0x95, - 0x90, 0x96, 0x96, 0x9f, 0x99, 0x90, 0x9a, 0x93, - 0x91, 0x94, 0x92, 0x97, 0x98, 0x92, 0x95, 0x9c, - 0x9b, 0x91, 0x9c, 0x9a, 0x94, 0x9e, 0x9f, 0x99, - 0x9a, 0x93, 0x96, 0x9f, 0x99, 0x90, 0x90, 0x96, - 0x9c, 0x9a, 0x9b, 0x91, 0x97, 0x9d, 0x9d, 0x98, - 0x9f, 0x99, 0x91, 0x94, 0x93, 0x95, 0x9e, 0x9b, - 0x95, 0x9c, 0x92, 0x97, 0x98, 0x92, 0x94, 0x9e, - 0x67, 0x6d, 0x6d, 0x68, 0x6e, 0x6b, 0x63, 0x65, - 0x60, 0x66, 0x66, 0x6f, 0x69, 0x60, 0x6a, 0x63, - 0x61, 0x64, 0x62, 0x67, 0x68, 0x62, 0x65, 0x6c, - 0x6b, 0x61, 0x6c, 0x6a, 0x64, 0x6e, 0x6f, 0x69, - 0x6a, 0x63, 0x66, 0x6f, 0x69, 0x60, 0x60, 0x66, - 0x6c, 0x6a, 0x6b, 0x61, 0x67, 0x6d, 0x6d, 0x68, - 0x6f, 0x69, 0x61, 0x64, 0x63, 0x65, 0x6e, 0x6b, - 0x65, 0x6c, 0x62, 0x67, 0x68, 0x62, 0x64, 0x6e, - 0x37, 0x3d, 0x3d, 0x38, 0x3e, 0x3b, 0x33, 0x35, - 0x30, 0x36, 0x36, 0x3f, 0x39, 0x30, 0x3a, 0x33, - 0x31, 0x34, 0x32, 0x37, 0x38, 0x32, 0x35, 0x3c, - 0x3b, 0x31, 0x3c, 0x3a, 0x34, 0x3e, 0x3f, 0x39, - 0x3a, 0x33, 0x36, 0x3f, 0x39, 0x30, 0x30, 0x36, - 0x3c, 0x3a, 0x3b, 0x31, 0x37, 0x3d, 0x3d, 0x38, - 0x3f, 0x39, 0x31, 0x34, 0x33, 0x35, 0x3e, 0x3b, - 0x35, 0x3c, 0x32, 0x37, 0x38, 0x32, 0x34, 0x3e, - 0x37, 0x3d, 0x3d, 0x38, 0x3e, 0x3b, 0x33, 0x35, - 0x30, 0x36, 0x36, 0x3f, 0x39, 0x30, 0x3a, 0x33, - 0x31, 0x34, 0x32, 0x37, 0x38, 0x32, 0x35, 0x3c, - 0x3b, 0x31, 0x3c, 0x3a, 0x34, 0x3e, 0x3f, 0x39, - 0x3a, 0x33, 0x36, 0x3f, 0x39, 0x30, 0x30, 0x36, - 0x3c, 0x3a, 0x3b, 0x31, 0x37, 0x3d, 0x3d, 0x38, - 0x3f, 0x39, 0x31, 0x34, 0x33, 0x35, 0x3e, 0x3b, - 0x35, 0x3c, 0x32, 0x37, 0x38, 0x32, 0x34, 0x3e, - 0x47, 0x4d, 0x4d, 0x48, 0x4e, 0x4b, 0x43, 0x45, - 0x40, 0x46, 0x46, 0x4f, 0x49, 0x40, 0x4a, 0x43, - 0x41, 0x44, 0x42, 0x47, 0x48, 0x42, 0x45, 0x4c, - 0x4b, 0x41, 0x4c, 0x4a, 0x44, 0x4e, 0x4f, 0x49, - 0x4a, 0x43, 0x46, 0x4f, 0x49, 0x40, 0x40, 0x46, - 0x4c, 0x4a, 0x4b, 0x41, 0x47, 0x4d, 0x4d, 0x48, - 0x4f, 0x49, 0x41, 0x44, 0x43, 0x45, 0x4e, 0x4b, - 0x45, 0x4c, 0x42, 0x47, 0x48, 0x42, 0x44, 0x4e, - 0xf7, 0xfd, 0xfd, 0xf8, 0xfe, 0xfb, 0xf3, 0xf5, - 0xf0, 0xf6, 0xf6, 0xff, 0xf9, 0xf0, 0xfa, 0xf3, - 0xf1, 0xf4, 0xf2, 0xf7, 0xf8, 0xf2, 0xf5, 0xfc, - 0xfb, 0xf1, 0xfc, 0xfa, 0xf4, 0xfe, 0xff, 0xf9, - 0xfa, 0xf3, 0xf6, 0xff, 0xf9, 0xf0, 0xf0, 0xf6, - 0xfc, 0xfa, 0xfb, 0xf1, 0xf7, 0xfd, 0xfd, 0xf8, - 0xff, 0xf9, 0xf1, 0xf4, 0xf3, 0xf5, 0xfe, 0xfb, - 0xf5, 0xfc, 0xf2, 0xf7, 0xf8, 0xf2, 0xf4, 0xfe, - 0x67, 0x6d, 0x6d, 0x68, 0x6e, 0x6b, 0x63, 0x65, - 0x60, 0x66, 0x66, 0x6f, 0x69, 0x60, 0x6a, 0x63, - 0x61, 0x64, 0x62, 0x67, 0x68, 0x62, 0x65, 0x6c, - 0x6b, 0x61, 0x6c, 0x6a, 0x64, 0x6e, 0x6f, 0x69, - 0x6a, 0x63, 0x66, 0x6f, 0x69, 0x60, 0x60, 0x66, - 0x6c, 0x6a, 0x6b, 0x61, 0x67, 0x6d, 0x6d, 0x68, - 0x6f, 0x69, 0x61, 0x64, 0x63, 0x65, 0x6e, 0x6b, - 0x65, 0x6c, 0x62, 0x67, 0x68, 0x62, 0x64, 0x6e, - 0x57, 0x5d, 0x5d, 0x58, 0x5e, 0x5b, 0x53, 0x55, - 0x50, 0x56, 0x56, 0x5f, 0x59, 0x50, 0x5a, 0x53, - 0x51, 0x54, 0x52, 0x57, 0x58, 0x52, 0x55, 0x5c, - 0x5b, 0x51, 0x5c, 0x5a, 0x54, 0x5e, 0x5f, 0x59, - 0x5a, 0x53, 0x56, 0x5f, 0x59, 0x50, 0x50, 0x56, - 0x5c, 0x5a, 0x5b, 0x51, 0x57, 0x5d, 0x5d, 0x58, - 0x5f, 0x59, 0x51, 0x54, 0x53, 0x55, 0x5e, 0x5b, - 0x55, 0x5c, 0x52, 0x57, 0x58, 0x52, 0x54, 0x5e, - 0xa7, 0xad, 0xad, 0xa8, 0xae, 0xab, 0xa3, 0xa5, - 0xa0, 0xa6, 0xa6, 0xaf, 0xa9, 0xa0, 0xaa, 0xa3, - 0xa1, 0xa4, 0xa2, 0xa7, 0xa8, 0xa2, 0xa5, 0xac, - 0xab, 0xa1, 0xac, 0xaa, 0xa4, 0xae, 0xaf, 0xa9, - 0xaa, 0xa3, 0xa6, 0xaf, 0xa9, 0xa0, 0xa0, 0xa6, - 0xac, 0xaa, 0xab, 0xa1, 0xa7, 0xad, 0xad, 0xa8, - 0xaf, 0xa9, 0xa1, 0xa4, 0xa3, 0xa5, 0xae, 0xab, - 0xa5, 0xac, 0xa2, 0xa7, 0xa8, 0xa2, 0xa4, 0xae, - 0x17, 0x1d, 0x1d, 0x18, 0x1e, 0x1b, 0x13, 0x15, - 0x10, 0x16, 0x16, 0x1f, 0x19, 0x10, 0x1a, 0x13, - 0x11, 0x14, 0x12, 0x17, 0x18, 0x12, 0x15, 0x1c, - 0x1b, 0x11, 0x1c, 0x1a, 0x14, 0x1e, 0x1f, 0x19, - 0x1a, 0x13, 0x16, 0x1f, 0x19, 0x10, 0x10, 0x16, - 0x1c, 0x1a, 0x1b, 0x11, 0x17, 0x1d, 0x1d, 0x18, - 0x1f, 0x19, 0x11, 0x14, 0x13, 0x15, 0x1e, 0x1b, - 0x15, 0x1c, 0x12, 0x17, 0x18, 0x12, 0x14, 0x1e, - 0x27, 0x2d, 0x2d, 0x28, 0x2e, 0x2b, 0x23, 0x25, - 0x20, 0x26, 0x26, 0x2f, 0x29, 0x20, 0x2a, 0x23, - 0x21, 0x24, 0x22, 0x27, 0x28, 0x22, 0x25, 0x2c, - 0x2b, 0x21, 0x2c, 0x2a, 0x24, 0x2e, 0x2f, 0x29, - 0x2a, 0x23, 0x26, 0x2f, 0x29, 0x20, 0x20, 0x26, - 0x2c, 0x2a, 0x2b, 0x21, 0x27, 0x2d, 0x2d, 0x28, - 0x2f, 0x29, 0x21, 0x24, 0x23, 0x25, 0x2e, 0x2b, - 0x25, 0x2c, 0x22, 0x27, 0x28, 0x22, 0x24, 0x2e, - 0xd7, 0xdd, 0xdd, 0xd8, 0xde, 0xdb, 0xd3, 0xd5, - 0xd0, 0xd6, 0xd6, 0xdf, 0xd9, 0xd0, 0xda, 0xd3, - 0xd1, 0xd4, 0xd2, 0xd7, 0xd8, 0xd2, 0xd5, 0xdc, - 0xdb, 0xd1, 0xdc, 0xda, 0xd4, 0xde, 0xdf, 0xd9, - 0xda, 0xd3, 0xd6, 0xdf, 0xd9, 0xd0, 0xd0, 0xd6, - 0xdc, 0xda, 0xdb, 0xd1, 0xd7, 0xdd, 0xdd, 0xd8, - 0xdf, 0xd9, 0xd1, 0xd4, 0xd3, 0xd5, 0xde, 0xdb, - 0xd5, 0xdc, 0xd2, 0xd7, 0xd8, 0xd2, 0xd4, 0xde, - 0x87, 0x8d, 0x8d, 0x88, 0x8e, 0x8b, 0x83, 0x85, - 0x80, 0x86, 0x86, 0x8f, 0x89, 0x80, 0x8a, 0x83, - 0x81, 0x84, 0x82, 0x87, 0x88, 0x82, 0x85, 0x8c, - 0x8b, 0x81, 0x8c, 0x8a, 0x84, 0x8e, 0x8f, 0x89, - 0x8a, 0x83, 0x86, 0x8f, 0x89, 0x80, 0x80, 0x86, - 0x8c, 0x8a, 0x8b, 0x81, 0x87, 0x8d, 0x8d, 0x88, - 0x8f, 0x89, 0x81, 0x84, 0x83, 0x85, 0x8e, 0x8b, - 0x85, 0x8c, 0x82, 0x87, 0x88, 0x82, 0x84, 0x8e, - 0xc7, 0xcd, 0xcd, 0xc8, 0xce, 0xcb, 0xc3, 0xc5, - 0xc0, 0xc6, 0xc6, 0xcf, 0xc9, 0xc0, 0xca, 0xc3, - 0xc1, 0xc4, 0xc2, 0xc7, 0xc8, 0xc2, 0xc5, 0xcc, - 0xcb, 0xc1, 0xcc, 0xca, 0xc4, 0xce, 0xcf, 0xc9, - 0xca, 0xc3, 0xc6, 0xcf, 0xc9, 0xc0, 0xc0, 0xc6, - 0xcc, 0xca, 0xcb, 0xc1, 0xc7, 0xcd, 0xcd, 0xc8, - 0xcf, 0xc9, 0xc1, 0xc4, 0xc3, 0xc5, 0xce, 0xcb, - 0xc5, 0xcc, 0xc2, 0xc7, 0xc8, 0xc2, 0xc4, 0xce, - 0x57, 0x5d, 0x5d, 0x58, 0x5e, 0x5b, 0x53, 0x55, - 0x50, 0x56, 0x56, 0x5f, 0x59, 0x50, 0x5a, 0x53, - 0x51, 0x54, 0x52, 0x57, 0x58, 0x52, 0x55, 0x5c, - 0x5b, 0x51, 0x5c, 0x5a, 0x54, 0x5e, 0x5f, 0x59, - 0x5a, 0x53, 0x56, 0x5f, 0x59, 0x50, 0x50, 0x56, - 0x5c, 0x5a, 0x5b, 0x51, 0x57, 0x5d, 0x5d, 0x58, - 0x5f, 0x59, 0x51, 0x54, 0x53, 0x55, 0x5e, 0x5b, - 0x55, 0x5c, 0x52, 0x57, 0x58, 0x52, 0x54, 0x5e, - 0x77, 0x7d, 0x7d, 0x78, 0x7e, 0x7b, 0x73, 0x75, - 0x70, 0x76, 0x76, 0x7f, 0x79, 0x70, 0x7a, 0x73, - 0x71, 0x74, 0x72, 0x77, 0x78, 0x72, 0x75, 0x7c, - 0x7b, 0x71, 0x7c, 0x7a, 0x74, 0x7e, 0x7f, 0x79, - 0x7a, 0x73, 0x76, 0x7f, 0x79, 0x70, 0x70, 0x76, - 0x7c, 0x7a, 0x7b, 0x71, 0x77, 0x7d, 0x7d, 0x78, - 0x7f, 0x79, 0x71, 0x74, 0x73, 0x75, 0x7e, 0x7b, - 0x75, 0x7c, 0x72, 0x77, 0x78, 0x72, 0x74, 0x7e, - 0xe7, 0xed, 0xed, 0xe8, 0xee, 0xeb, 0xe3, 0xe5, - 0xe0, 0xe6, 0xe6, 0xef, 0xe9, 0xe0, 0xea, 0xe3, - 0xe1, 0xe4, 0xe2, 0xe7, 0xe8, 0xe2, 0xe5, 0xec, - 0xeb, 0xe1, 0xec, 0xea, 0xe4, 0xee, 0xef, 0xe9, - 0xea, 0xe3, 0xe6, 0xef, 0xe9, 0xe0, 0xe0, 0xe6, - 0xec, 0xea, 0xeb, 0xe1, 0xe7, 0xed, 0xed, 0xe8, - 0xef, 0xe9, 0xe1, 0xe4, 0xe3, 0xe5, 0xee, 0xeb, - 0xe5, 0xec, 0xe2, 0xe7, 0xe8, 0xe2, 0xe4, 0xee, - 0xb7, 0xbd, 0xbd, 0xb8, 0xbe, 0xbb, 0xb3, 0xb5, - 0xb0, 0xb6, 0xb6, 0xbf, 0xb9, 0xb0, 0xba, 0xb3, - 0xb1, 0xb4, 0xb2, 0xb7, 0xb8, 0xb2, 0xb5, 0xbc, - 0xbb, 0xb1, 0xbc, 0xba, 0xb4, 0xbe, 0xbf, 0xb9, - 0xba, 0xb3, 0xb6, 0xbf, 0xb9, 0xb0, 0xb0, 0xb6, - 0xbc, 0xba, 0xbb, 0xb1, 0xb7, 0xbd, 0xbd, 0xb8, - 0xbf, 0xb9, 0xb1, 0xb4, 0xb3, 0xb5, 0xbe, 0xbb, - 0xb5, 0xbc, 0xb2, 0xb7, 0xb8, 0xb2, 0xb4, 0xbe, - 0xc7, 0xcd, 0xcd, 0xc8, 0xce, 0xcb, 0xc3, 0xc5, - 0xc0, 0xc6, 0xc6, 0xcf, 0xc9, 0xc0, 0xca, 0xc3, - 0xc1, 0xc4, 0xc2, 0xc7, 0xc8, 0xc2, 0xc5, 0xcc, - 0xcb, 0xc1, 0xcc, 0xca, 0xc4, 0xce, 0xcf, 0xc9, - 0xca, 0xc3, 0xc6, 0xcf, 0xc9, 0xc0, 0xc0, 0xc6, - 0xcc, 0xca, 0xcb, 0xc1, 0xc7, 0xcd, 0xcd, 0xc8, - 0xcf, 0xc9, 0xc1, 0xc4, 0xc3, 0xc5, 0xce, 0xcb, - 0xc5, 0xcc, 0xc2, 0xc7, 0xc8, 0xc2, 0xc4, 0xce, - 0x47, 0x4d, 0x4d, 0x48, 0x4e, 0x4b, 0x43, 0x45, - 0x40, 0x46, 0x46, 0x4f, 0x49, 0x40, 0x4a, 0x43, - 0x41, 0x44, 0x42, 0x47, 0x48, 0x42, 0x45, 0x4c, - 0x4b, 0x41, 0x4c, 0x4a, 0x44, 0x4e, 0x4f, 0x49, - 0x4a, 0x43, 0x46, 0x4f, 0x49, 0x40, 0x40, 0x46, - 0x4c, 0x4a, 0x4b, 0x41, 0x47, 0x4d, 0x4d, 0x48, - 0x4f, 0x49, 0x41, 0x44, 0x43, 0x45, 0x4e, 0x4b, - 0x45, 0x4c, 0x42, 0x47, 0x48, 0x42, 0x44, 0x4e, - 0xb7, 0xbd, 0xbd, 0xb8, 0xbe, 0xbb, 0xb3, 0xb5, - 0xb0, 0xb6, 0xb6, 0xbf, 0xb9, 0xb0, 0xba, 0xb3, - 0xb1, 0xb4, 0xb2, 0xb7, 0xb8, 0xb2, 0xb5, 0xbc, - 0xbb, 0xb1, 0xbc, 0xba, 0xb4, 0xbe, 0xbf, 0xb9, - 0xba, 0xb3, 0xb6, 0xbf, 0xb9, 0xb0, 0xb0, 0xb6, - 0xbc, 0xba, 0xbb, 0xb1, 0xb7, 0xbd, 0xbd, 0xb8, - 0xbf, 0xb9, 0xb1, 0xb4, 0xb3, 0xb5, 0xbe, 0xbb, - 0xb5, 0xbc, 0xb2, 0xb7, 0xb8, 0xb2, 0xb4, 0xbe, - 0x27, 0x2d, 0x2d, 0x28, 0x2e, 0x2b, 0x23, 0x25, - 0x20, 0x26, 0x26, 0x2f, 0x29, 0x20, 0x2a, 0x23, - 0x21, 0x24, 0x22, 0x27, 0x28, 0x22, 0x25, 0x2c, - 0x2b, 0x21, 0x2c, 0x2a, 0x24, 0x2e, 0x2f, 0x29, - 0x2a, 0x23, 0x26, 0x2f, 0x29, 0x20, 0x20, 0x26, - 0x2c, 0x2a, 0x2b, 0x21, 0x27, 0x2d, 0x2d, 0x28, - 0x2f, 0x29, 0x21, 0x24, 0x23, 0x25, 0x2e, 0x2b, - 0x25, 0x2c, 0x22, 0x27, 0x28, 0x22, 0x24, 0x2e, - 0xf7, 0xfd, 0xfd, 0xf8, 0xfe, 0xfb, 0xf3, 0xf5, - 0xf0, 0xf6, 0xf6, 0xff, 0xf9, 0xf0, 0xfa, 0xf3, - 0xf1, 0xf4, 0xf2, 0xf7, 0xf8, 0xf2, 0xf5, 0xfc, - 0xfb, 0xf1, 0xfc, 0xfa, 0xf4, 0xfe, 0xff, 0xf9, - 0xfa, 0xf3, 0xf6, 0xff, 0xf9, 0xf0, 0xf0, 0xf6, - 0xfc, 0xfa, 0xfb, 0xf1, 0xf7, 0xfd, 0xfd, 0xf8, - 0xff, 0xf9, 0xf1, 0xf4, 0xf3, 0xf5, 0xfe, 0xfb, - 0xf5, 0xfc, 0xf2, 0xf7, 0xf8, 0xf2, 0xf4, 0xfe, - 0x87, 0x8d, 0x8d, 0x88, 0x8e, 0x8b, 0x83, 0x85, - 0x80, 0x86, 0x86, 0x8f, 0x89, 0x80, 0x8a, 0x83, - 0x81, 0x84, 0x82, 0x87, 0x88, 0x82, 0x85, 0x8c, - 0x8b, 0x81, 0x8c, 0x8a, 0x84, 0x8e, 0x8f, 0x89, - 0x8a, 0x83, 0x86, 0x8f, 0x89, 0x80, 0x80, 0x86, - 0x8c, 0x8a, 0x8b, 0x81, 0x87, 0x8d, 0x8d, 0x88, - 0x8f, 0x89, 0x81, 0x84, 0x83, 0x85, 0x8e, 0x8b, - 0x85, 0x8c, 0x82, 0x87, 0x88, 0x82, 0x84, 0x8e, - 0x17, 0x1d, 0x1d, 0x18, 0x1e, 0x1b, 0x13, 0x15, - 0x10, 0x16, 0x16, 0x1f, 0x19, 0x10, 0x1a, 0x13, - 0x11, 0x14, 0x12, 0x17, 0x18, 0x12, 0x15, 0x1c, - 0x1b, 0x11, 0x1c, 0x1a, 0x14, 0x1e, 0x1f, 0x19, - 0x1a, 0x13, 0x16, 0x1f, 0x19, 0x10, 0x10, 0x16, - 0x1c, 0x1a, 0x1b, 0x11, 0x17, 0x1d, 0x1d, 0x18, - 0x1f, 0x19, 0x11, 0x14, 0x13, 0x15, 0x1e, 0x1b, - 0x15, 0x1c, 0x12, 0x17, 0x18, 0x12, 0x14, 0x1e, - 0xd7, 0xdd, 0xdd, 0xd8, 0xde, 0xdb, 0xd3, 0xd5, - 0xd0, 0xd6, 0xd6, 0xdf, 0xd9, 0xd0, 0xda, 0xd3, - 0xd1, 0xd4, 0xd2, 0xd7, 0xd8, 0xd2, 0xd5, 0xdc, - 0xdb, 0xd1, 0xdc, 0xda, 0xd4, 0xde, 0xdf, 0xd9, - 0xda, 0xd3, 0xd6, 0xdf, 0xd9, 0xd0, 0xd0, 0xd6, - 0xdc, 0xda, 0xdb, 0xd1, 0xd7, 0xdd, 0xdd, 0xd8, - 0xdf, 0xd9, 0xd1, 0xd4, 0xd3, 0xd5, 0xde, 0xdb, - 0xd5, 0xdc, 0xd2, 0xd7, 0xd8, 0xd2, 0xd4, 0xde, - 0x17, 0x1d, 0x1d, 0x18, 0x1e, 0x1b, 0x13, 0x15, - 0x10, 0x16, 0x16, 0x1f, 0x19, 0x10, 0x1a, 0x13, - 0x11, 0x14, 0x12, 0x17, 0x18, 0x12, 0x15, 0x1c, - 0x1b, 0x11, 0x1c, 0x1a, 0x14, 0x1e, 0x1f, 0x19, - 0x1a, 0x13, 0x16, 0x1f, 0x19, 0x10, 0x10, 0x16, - 0x1c, 0x1a, 0x1b, 0x11, 0x17, 0x1d, 0x1d, 0x18, - 0x1f, 0x19, 0x11, 0x14, 0x13, 0x15, 0x1e, 0x1b, - 0x15, 0x1c, 0x12, 0x17, 0x18, 0x12, 0x14, 0x1e, - 0x67, 0x6d, 0x6d, 0x68, 0x6e, 0x6b, 0x63, 0x65, - 0x60, 0x66, 0x66, 0x6f, 0x69, 0x60, 0x6a, 0x63, - 0x61, 0x64, 0x62, 0x67, 0x68, 0x62, 0x65, 0x6c, - 0x6b, 0x61, 0x6c, 0x6a, 0x64, 0x6e, 0x6f, 0x69, - 0x6a, 0x63, 0x66, 0x6f, 0x69, 0x60, 0x60, 0x66, - 0x6c, 0x6a, 0x6b, 0x61, 0x67, 0x6d, 0x6d, 0x68, - 0x6f, 0x69, 0x61, 0x64, 0x63, 0x65, 0x6e, 0x6b, - 0x65, 0x6c, 0x62, 0x67, 0x68, 0x62, 0x64, 0x6e, - 0xa7, 0xad, 0xad, 0xa8, 0xae, 0xab, 0xa3, 0xa5, - 0xa0, 0xa6, 0xa6, 0xaf, 0xa9, 0xa0, 0xaa, 0xa3, - 0xa1, 0xa4, 0xa2, 0xa7, 0xa8, 0xa2, 0xa5, 0xac, - 0xab, 0xa1, 0xac, 0xaa, 0xa4, 0xae, 0xaf, 0xa9, - 0xaa, 0xa3, 0xa6, 0xaf, 0xa9, 0xa0, 0xa0, 0xa6, - 0xac, 0xaa, 0xab, 0xa1, 0xa7, 0xad, 0xad, 0xa8, - 0xaf, 0xa9, 0xa1, 0xa4, 0xa3, 0xa5, 0xae, 0xab, - 0xa5, 0xac, 0xa2, 0xa7, 0xa8, 0xa2, 0xa4, 0xae, - 0x47, 0x4d, 0x4d, 0x48, 0x4e, 0x4b, 0x43, 0x45, - 0x40, 0x46, 0x46, 0x4f, 0x49, 0x40, 0x4a, 0x43, - 0x41, 0x44, 0x42, 0x47, 0x48, 0x42, 0x45, 0x4c, - 0x4b, 0x41, 0x4c, 0x4a, 0x44, 0x4e, 0x4f, 0x49, - 0x4a, 0x43, 0x46, 0x4f, 0x49, 0x40, 0x40, 0x46, - 0x4c, 0x4a, 0x4b, 0x41, 0x47, 0x4d, 0x4d, 0x48, - 0x4f, 0x49, 0x41, 0x44, 0x43, 0x45, 0x4e, 0x4b, - 0x45, 0x4c, 0x42, 0x47, 0x48, 0x42, 0x44, 0x4e, - 0xd7, 0xdd, 0xdd, 0xd8, 0xde, 0xdb, 0xd3, 0xd5, - 0xd0, 0xd6, 0xd6, 0xdf, 0xd9, 0xd0, 0xda, 0xd3, - 0xd1, 0xd4, 0xd2, 0xd7, 0xd8, 0xd2, 0xd5, 0xdc, - 0xdb, 0xd1, 0xdc, 0xda, 0xd4, 0xde, 0xdf, 0xd9, - 0xda, 0xd3, 0xd6, 0xdf, 0xd9, 0xd0, 0xd0, 0xd6, - 0xdc, 0xda, 0xdb, 0xd1, 0xd7, 0xdd, 0xdd, 0xd8, - 0xdf, 0xd9, 0xd1, 0xd4, 0xd3, 0xd5, 0xde, 0xdb, - 0xd5, 0xdc, 0xd2, 0xd7, 0xd8, 0xd2, 0xd4, 0xde, - 0x97, 0x9d, 0x9d, 0x98, 0x9e, 0x9b, 0x93, 0x95, - 0x90, 0x96, 0x96, 0x9f, 0x99, 0x90, 0x9a, 0x93, - 0x91, 0x94, 0x92, 0x97, 0x98, 0x92, 0x95, 0x9c, - 0x9b, 0x91, 0x9c, 0x9a, 0x94, 0x9e, 0x9f, 0x99, - 0x9a, 0x93, 0x96, 0x9f, 0x99, 0x90, 0x90, 0x96, - 0x9c, 0x9a, 0x9b, 0x91, 0x97, 0x9d, 0x9d, 0x98, - 0x9f, 0x99, 0x91, 0x94, 0x93, 0x95, 0x9e, 0x9b, - 0x95, 0x9c, 0x92, 0x97, 0x98, 0x92, 0x94, 0x9e, - 0x07, 0x0d, 0x0d, 0x08, 0x0e, 0x0b, 0x03, 0x05, - 0x00, 0x06, 0x06, 0x0f, 0x09, 0x00, 0x0a, 0x03, - 0x01, 0x04, 0x02, 0x07, 0x08, 0x02, 0x05, 0x0c, - 0x0b, 0x01, 0x0c, 0x0a, 0x04, 0x0e, 0x0f, 0x09, - 0x0a, 0x03, 0x06, 0x0f, 0x09, 0x00, 0x00, 0x06, - 0x0c, 0x0a, 0x0b, 0x01, 0x07, 0x0d, 0x0d, 0x08, - 0x0f, 0x09, 0x01, 0x04, 0x03, 0x05, 0x0e, 0x0b, - 0x05, 0x0c, 0x02, 0x07, 0x08, 0x02, 0x04, 0x0e, - 0x87, 0x8d, 0x8d, 0x88, 0x8e, 0x8b, 0x83, 0x85, - 0x80, 0x86, 0x86, 0x8f, 0x89, 0x80, 0x8a, 0x83, - 0x81, 0x84, 0x82, 0x87, 0x88, 0x82, 0x85, 0x8c, - 0x8b, 0x81, 0x8c, 0x8a, 0x84, 0x8e, 0x8f, 0x89, - 0x8a, 0x83, 0x86, 0x8f, 0x89, 0x80, 0x80, 0x86, - 0x8c, 0x8a, 0x8b, 0x81, 0x87, 0x8d, 0x8d, 0x88, - 0x8f, 0x89, 0x81, 0x84, 0x83, 0x85, 0x8e, 0x8b, - 0x85, 0x8c, 0x82, 0x87, 0x88, 0x82, 0x84, 0x8e, - 0x67, 0x6d, 0x6d, 0x68, 0x6e, 0x6b, 0x63, 0x65, - 0x60, 0x66, 0x66, 0x6f, 0x69, 0x60, 0x6a, 0x63, - 0x61, 0x64, 0x62, 0x67, 0x68, 0x62, 0x65, 0x6c, - 0x6b, 0x61, 0x6c, 0x6a, 0x64, 0x6e, 0x6f, 0x69, - 0x6a, 0x63, 0x66, 0x6f, 0x69, 0x60, 0x60, 0x66, - 0x6c, 0x6a, 0x6b, 0x61, 0x67, 0x6d, 0x6d, 0x68, - 0x6f, 0x69, 0x61, 0x64, 0x63, 0x65, 0x6e, 0x6b, - 0x65, 0x6c, 0x62, 0x67, 0x68, 0x62, 0x64, 0x6e, - 0xf7, 0xfd, 0xfd, 0xf8, 0xfe, 0xfb, 0xf3, 0xf5, - 0xf0, 0xf6, 0xf6, 0xff, 0xf9, 0xf0, 0xfa, 0xf3, - 0xf1, 0xf4, 0xf2, 0xf7, 0xf8, 0xf2, 0xf5, 0xfc, - 0xfb, 0xf1, 0xfc, 0xfa, 0xf4, 0xfe, 0xff, 0xf9, - 0xfa, 0xf3, 0xf6, 0xff, 0xf9, 0xf0, 0xf0, 0xf6, - 0xfc, 0xfa, 0xfb, 0xf1, 0xf7, 0xfd, 0xfd, 0xf8, - 0xff, 0xf9, 0xf1, 0xf4, 0xf3, 0xf5, 0xfe, 0xfb, - 0xf5, 0xfc, 0xf2, 0xf7, 0xf8, 0xf2, 0xf4, 0xfe, - 0x97, 0x9d, 0x9d, 0x98, 0x9e, 0x9b, 0x93, 0x95, - 0x90, 0x96, 0x96, 0x9f, 0x99, 0x90, 0x9a, 0x93, - 0x91, 0x94, 0x92, 0x97, 0x98, 0x92, 0x95, 0x9c, - 0x9b, 0x91, 0x9c, 0x9a, 0x94, 0x9e, 0x9f, 0x99, - 0x9a, 0x93, 0x96, 0x9f, 0x99, 0x90, 0x90, 0x96, - 0x9c, 0x9a, 0x9b, 0x91, 0x97, 0x9d, 0x9d, 0x98, - 0x9f, 0x99, 0x91, 0x94, 0x93, 0x95, 0x9e, 0x9b, - 0x95, 0x9c, 0x92, 0x97, 0x98, 0x92, 0x94, 0x9e, - 0x37, 0x3d, 0x3d, 0x38, 0x3e, 0x3b, 0x33, 0x35, - 0x30, 0x36, 0x36, 0x3f, 0x39, 0x30, 0x3a, 0x33, - 0x31, 0x34, 0x32, 0x37, 0x38, 0x32, 0x35, 0x3c, - 0x3b, 0x31, 0x3c, 0x3a, 0x34, 0x3e, 0x3f, 0x39, - 0x3a, 0x33, 0x36, 0x3f, 0x39, 0x30, 0x30, 0x36, - 0x3c, 0x3a, 0x3b, 0x31, 0x37, 0x3d, 0x3d, 0x38, - 0x3f, 0x39, 0x31, 0x34, 0x33, 0x35, 0x3e, 0x3b, - 0x35, 0x3c, 0x32, 0x37, 0x38, 0x32, 0x34, 0x3e, - 0x87, 0x8d, 0x8d, 0x88, 0x8e, 0x8b, 0x83, 0x85, - 0x80, 0x86, 0x86, 0x8f, 0x89, 0x80, 0x8a, 0x83, - 0x81, 0x84, 0x82, 0x87, 0x88, 0x82, 0x85, 0x8c, - 0x8b, 0x81, 0x8c, 0x8a, 0x84, 0x8e, 0x8f, 0x89, - 0x8a, 0x83, 0x86, 0x8f, 0x89, 0x80, 0x80, 0x86, - 0x8c, 0x8a, 0x8b, 0x81, 0x87, 0x8d, 0x8d, 0x88, - 0x8f, 0x89, 0x81, 0x84, 0x83, 0x85, 0x8e, 0x8b, - 0x85, 0x8c, 0x82, 0x87, 0x88, 0x82, 0x84, 0x8e, - 0x07, 0x0d, 0x0d, 0x08, 0x0e, 0x0b, 0x03, 0x05, - 0x00, 0x06, 0x06, 0x0f, 0x09, 0x00, 0x0a, 0x03, - 0x01, 0x04, 0x02, 0x07, 0x08, 0x02, 0x05, 0x0c, - 0x0b, 0x01, 0x0c, 0x0a, 0x04, 0x0e, 0x0f, 0x09, - 0x0a, 0x03, 0x06, 0x0f, 0x09, 0x00, 0x00, 0x06, - 0x0c, 0x0a, 0x0b, 0x01, 0x07, 0x0d, 0x0d, 0x08, - 0x0f, 0x09, 0x01, 0x04, 0x03, 0x05, 0x0e, 0x0b, - 0x05, 0x0c, 0x02, 0x07, 0x08, 0x02, 0x04, 0x0e, - 0x77, 0x7d, 0x7d, 0x78, 0x7e, 0x7b, 0x73, 0x75, - 0x70, 0x76, 0x76, 0x7f, 0x79, 0x70, 0x7a, 0x73, - 0x71, 0x74, 0x72, 0x77, 0x78, 0x72, 0x75, 0x7c, - 0x7b, 0x71, 0x7c, 0x7a, 0x74, 0x7e, 0x7f, 0x79, - 0x7a, 0x73, 0x76, 0x7f, 0x79, 0x70, 0x70, 0x76, - 0x7c, 0x7a, 0x7b, 0x71, 0x77, 0x7d, 0x7d, 0x78, - 0x7f, 0x79, 0x71, 0x74, 0x73, 0x75, 0x7e, 0x7b, - 0x75, 0x7c, 0x72, 0x77, 0x78, 0x72, 0x74, 0x7e, - 0xb7, 0xbd, 0xbd, 0xb8, 0xbe, 0xbb, 0xb3, 0xb5, - 0xb0, 0xb6, 0xb6, 0xbf, 0xb9, 0xb0, 0xba, 0xb3, - 0xb1, 0xb4, 0xb2, 0xb7, 0xb8, 0xb2, 0xb5, 0xbc, - 0xbb, 0xb1, 0xbc, 0xba, 0xb4, 0xbe, 0xbf, 0xb9, - 0xba, 0xb3, 0xb6, 0xbf, 0xb9, 0xb0, 0xb0, 0xb6, - 0xbc, 0xba, 0xbb, 0xb1, 0xb7, 0xbd, 0xbd, 0xb8, - 0xbf, 0xb9, 0xb1, 0xb4, 0xb3, 0xb5, 0xbe, 0xbb, - 0xb5, 0xbc, 0xb2, 0xb7, 0xb8, 0xb2, 0xb4, 0xbe, - 0x47, 0x4d, 0x4d, 0x48, 0x4e, 0x4b, 0x43, 0x45, - 0x40, 0x46, 0x46, 0x4f, 0x49, 0x40, 0x4a, 0x43, - 0x41, 0x44, 0x42, 0x47, 0x48, 0x42, 0x45, 0x4c, - 0x4b, 0x41, 0x4c, 0x4a, 0x44, 0x4e, 0x4f, 0x49, - 0x4a, 0x43, 0x46, 0x4f, 0x49, 0x40, 0x40, 0x46, - 0x4c, 0x4a, 0x4b, 0x41, 0x47, 0x4d, 0x4d, 0x48, - 0x4f, 0x49, 0x41, 0x44, 0x43, 0x45, 0x4e, 0x4b, - 0x45, 0x4c, 0x42, 0x47, 0x48, 0x42, 0x44, 0x4e, - 0x17, 0x1d, 0x1d, 0x18, 0x1e, 0x1b, 0x13, 0x15, - 0x10, 0x16, 0x16, 0x1f, 0x19, 0x10, 0x1a, 0x13, - 0x11, 0x14, 0x12, 0x17, 0x18, 0x12, 0x15, 0x1c, - 0x1b, 0x11, 0x1c, 0x1a, 0x14, 0x1e, 0x1f, 0x19, - 0x1a, 0x13, 0x16, 0x1f, 0x19, 0x10, 0x10, 0x16, - 0x1c, 0x1a, 0x1b, 0x11, 0x17, 0x1d, 0x1d, 0x18, - 0x1f, 0x19, 0x11, 0x14, 0x13, 0x15, 0x1e, 0x1b, - 0x15, 0x1c, 0x12, 0x17, 0x18, 0x12, 0x14, 0x1e, - 0xf7, 0xfd, 0xfd, 0xf8, 0xfe, 0xfb, 0xf3, 0xf5, - 0xf0, 0xf6, 0xf6, 0xff, 0xf9, 0xf0, 0xfa, 0xf3, - 0xf1, 0xf4, 0xf2, 0xf7, 0xf8, 0xf2, 0xf5, 0xfc, - 0xfb, 0xf1, 0xfc, 0xfa, 0xf4, 0xfe, 0xff, 0xf9, - 0xfa, 0xf3, 0xf6, 0xff, 0xf9, 0xf0, 0xf0, 0xf6, - 0xfc, 0xfa, 0xfb, 0xf1, 0xf7, 0xfd, 0xfd, 0xf8, - 0xff, 0xf9, 0xf1, 0xf4, 0xf3, 0xf5, 0xfe, 0xfb, - 0xf5, 0xfc, 0xf2, 0xf7, 0xf8, 0xf2, 0xf4, 0xfe, - 0x27, 0x2d, 0x2d, 0x28, 0x2e, 0x2b, 0x23, 0x25, - 0x20, 0x26, 0x26, 0x2f, 0x29, 0x20, 0x2a, 0x23, - 0x21, 0x24, 0x22, 0x27, 0x28, 0x22, 0x25, 0x2c, - 0x2b, 0x21, 0x2c, 0x2a, 0x24, 0x2e, 0x2f, 0x29, - 0x2a, 0x23, 0x26, 0x2f, 0x29, 0x20, 0x20, 0x26, - 0x2c, 0x2a, 0x2b, 0x21, 0x27, 0x2d, 0x2d, 0x28, - 0x2f, 0x29, 0x21, 0x24, 0x23, 0x25, 0x2e, 0x2b, - 0x25, 0x2c, 0x22, 0x27, 0x28, 0x22, 0x24, 0x2e, - 0xe7, 0xed, 0xed, 0xe8, 0xee, 0xeb, 0xe3, 0xe5, - 0xe0, 0xe6, 0xe6, 0xef, 0xe9, 0xe0, 0xea, 0xe3, - 0xe1, 0xe4, 0xe2, 0xe7, 0xe8, 0xe2, 0xe5, 0xec, - 0xeb, 0xe1, 0xec, 0xea, 0xe4, 0xee, 0xef, 0xe9, - 0xea, 0xe3, 0xe6, 0xef, 0xe9, 0xe0, 0xe0, 0xe6, - 0xec, 0xea, 0xeb, 0xe1, 0xe7, 0xed, 0xed, 0xe8, - 0xef, 0xe9, 0xe1, 0xe4, 0xe3, 0xe5, 0xee, 0xeb, - 0xe5, 0xec, 0xe2, 0xe7, 0xe8, 0xe2, 0xe4, 0xee, - 0xc7, 0xcd, 0xcd, 0xc8, 0xce, 0xcb, 0xc3, 0xc5, - 0xc0, 0xc6, 0xc6, 0xcf, 0xc9, 0xc0, 0xca, 0xc3, - 0xc1, 0xc4, 0xc2, 0xc7, 0xc8, 0xc2, 0xc5, 0xcc, - 0xcb, 0xc1, 0xcc, 0xca, 0xc4, 0xce, 0xcf, 0xc9, - 0xca, 0xc3, 0xc6, 0xcf, 0xc9, 0xc0, 0xc0, 0xc6, - 0xcc, 0xca, 0xcb, 0xc1, 0xc7, 0xcd, 0xcd, 0xc8, - 0xcf, 0xc9, 0xc1, 0xc4, 0xc3, 0xc5, 0xce, 0xcb, - 0xc5, 0xcc, 0xc2, 0xc7, 0xc8, 0xc2, 0xc4, 0xce, - 0x37, 0x3d, 0x3d, 0x38, 0x3e, 0x3b, 0x33, 0x35, - 0x30, 0x36, 0x36, 0x3f, 0x39, 0x30, 0x3a, 0x33, - 0x31, 0x34, 0x32, 0x37, 0x38, 0x32, 0x35, 0x3c, - 0x3b, 0x31, 0x3c, 0x3a, 0x34, 0x3e, 0x3f, 0x39, - 0x3a, 0x33, 0x36, 0x3f, 0x39, 0x30, 0x30, 0x36, - 0x3c, 0x3a, 0x3b, 0x31, 0x37, 0x3d, 0x3d, 0x38, - 0x3f, 0x39, 0x31, 0x34, 0x33, 0x35, 0x3e, 0x3b, - 0x35, 0x3c, 0x32, 0x37, 0x38, 0x32, 0x34, 0x3e, - 0x57, 0x5d, 0x5d, 0x58, 0x5e, 0x5b, 0x53, 0x55, - 0x50, 0x56, 0x56, 0x5f, 0x59, 0x50, 0x5a, 0x53, - 0x51, 0x54, 0x52, 0x57, 0x58, 0x52, 0x55, 0x5c, - 0x5b, 0x51, 0x5c, 0x5a, 0x54, 0x5e, 0x5f, 0x59, - 0x5a, 0x53, 0x56, 0x5f, 0x59, 0x50, 0x50, 0x56, - 0x5c, 0x5a, 0x5b, 0x51, 0x57, 0x5d, 0x5d, 0x58, - 0x5f, 0x59, 0x51, 0x54, 0x53, 0x55, 0x5e, 0x5b, - 0x55, 0x5c, 0x52, 0x57, 0x58, 0x52, 0x54, 0x5e, - 0xb7, 0xbd, 0xbd, 0xb8, 0xbe, 0xbb, 0xb3, 0xb5, - 0xb0, 0xb6, 0xb6, 0xbf, 0xb9, 0xb0, 0xba, 0xb3, - 0xb1, 0xb4, 0xb2, 0xb7, 0xb8, 0xb2, 0xb5, 0xbc, - 0xbb, 0xb1, 0xbc, 0xba, 0xb4, 0xbe, 0xbf, 0xb9, - 0xba, 0xb3, 0xb6, 0xbf, 0xb9, 0xb0, 0xb0, 0xb6, - 0xbc, 0xba, 0xbb, 0xb1, 0xb7, 0xbd, 0xbd, 0xb8, - 0xbf, 0xb9, 0xb1, 0xb4, 0xb3, 0xb5, 0xbe, 0xbb, - 0xb5, 0xbc, 0xb2, 0xb7, 0xb8, 0xb2, 0xb4, 0xbe, - 0xa7, 0xad, 0xad, 0xa8, 0xae, 0xab, 0xa3, 0xa5, - 0xa0, 0xa6, 0xa6, 0xaf, 0xa9, 0xa0, 0xaa, 0xa3, - 0xa1, 0xa4, 0xa2, 0xa7, 0xa8, 0xa2, 0xa5, 0xac, - 0xab, 0xa1, 0xac, 0xaa, 0xa4, 0xae, 0xaf, 0xa9, - 0xaa, 0xa3, 0xa6, 0xaf, 0xa9, 0xa0, 0xa0, 0xa6, - 0xac, 0xaa, 0xab, 0xa1, 0xa7, 0xad, 0xad, 0xa8, - 0xaf, 0xa9, 0xa1, 0xa4, 0xa3, 0xa5, 0xae, 0xab, - 0xa5, 0xac, 0xa2, 0xa7, 0xa8, 0xa2, 0xa4, 0xae, - 0x57, 0x5d, 0x5d, 0x58, 0x5e, 0x5b, 0x53, 0x55, - 0x50, 0x56, 0x56, 0x5f, 0x59, 0x50, 0x5a, 0x53, - 0x51, 0x54, 0x52, 0x57, 0x58, 0x52, 0x55, 0x5c, - 0x5b, 0x51, 0x5c, 0x5a, 0x54, 0x5e, 0x5f, 0x59, - 0x5a, 0x53, 0x56, 0x5f, 0x59, 0x50, 0x50, 0x56, - 0x5c, 0x5a, 0x5b, 0x51, 0x57, 0x5d, 0x5d, 0x58, - 0x5f, 0x59, 0x51, 0x54, 0x53, 0x55, 0x5e, 0x5b, - 0x55, 0x5c, 0x52, 0x57, 0x58, 0x52, 0x54, 0x5e, - 0xe7, 0xed, 0xed, 0xe8, 0xee, 0xeb, 0xe3, 0xe5, - 0xe0, 0xe6, 0xe6, 0xef, 0xe9, 0xe0, 0xea, 0xe3, - 0xe1, 0xe4, 0xe2, 0xe7, 0xe8, 0xe2, 0xe5, 0xec, - 0xeb, 0xe1, 0xec, 0xea, 0xe4, 0xee, 0xef, 0xe9, - 0xea, 0xe3, 0xe6, 0xef, 0xe9, 0xe0, 0xe0, 0xe6, - 0xec, 0xea, 0xeb, 0xe1, 0xe7, 0xed, 0xed, 0xe8, - 0xef, 0xe9, 0xe1, 0xe4, 0xe3, 0xe5, 0xee, 0xeb, - 0xe5, 0xec, 0xe2, 0xe7, 0xe8, 0xe2, 0xe4, 0xee, - 0x27, 0x2d, 0x2d, 0x28, 0x2e, 0x2b, 0x23, 0x25, - 0x20, 0x26, 0x26, 0x2f, 0x29, 0x20, 0x2a, 0x23, - 0x21, 0x24, 0x22, 0x27, 0x28, 0x22, 0x25, 0x2c, - 0x2b, 0x21, 0x2c, 0x2a, 0x24, 0x2e, 0x2f, 0x29, - 0x2a, 0x23, 0x26, 0x2f, 0x29, 0x20, 0x20, 0x26, - 0x2c, 0x2a, 0x2b, 0x21, 0x27, 0x2d, 0x2d, 0x28, - 0x2f, 0x29, 0x21, 0x24, 0x23, 0x25, 0x2e, 0x2b, - 0x25, 0x2c, 0x22, 0x27, 0x28, 0x22, 0x24, 0x2e, - 0x77, 0x7d, 0x7d, 0x78, 0x7e, 0x7b, 0x73, 0x75, - 0x70, 0x76, 0x76, 0x7f, 0x79, 0x70, 0x7a, 0x73, - 0x71, 0x74, 0x72, 0x77, 0x78, 0x72, 0x75, 0x7c, - 0x7b, 0x71, 0x7c, 0x7a, 0x74, 0x7e, 0x7f, 0x79, - 0x7a, 0x73, 0x76, 0x7f, 0x79, 0x70, 0x70, 0x76, - 0x7c, 0x7a, 0x7b, 0x71, 0x77, 0x7d, 0x7d, 0x78, - 0x7f, 0x79, 0x71, 0x74, 0x73, 0x75, 0x7e, 0x7b, - 0x75, 0x7c, 0x72, 0x77, 0x78, 0x72, 0x74, 0x7e, - 0xc7, 0xcd, 0xcd, 0xc8, 0xce, 0xcb, 0xc3, 0xc5, - 0xc0, 0xc6, 0xc6, 0xcf, 0xc9, 0xc0, 0xca, 0xc3, - 0xc1, 0xc4, 0xc2, 0xc7, 0xc8, 0xc2, 0xc5, 0xcc, - 0xcb, 0xc1, 0xcc, 0xca, 0xc4, 0xce, 0xcf, 0xc9, - 0xca, 0xc3, 0xc6, 0xcf, 0xc9, 0xc0, 0xc0, 0xc6, - 0xcc, 0xca, 0xcb, 0xc1, 0xc7, 0xcd, 0xcd, 0xc8, - 0xcf, 0xc9, 0xc1, 0xc4, 0xc3, 0xc5, 0xce, 0xcb, - 0xc5, 0xcc, 0xc2, 0xc7, 0xc8, 0xc2, 0xc4, 0xce, - },{ - 0x2c, 0x2a, 0x21, 0x2f, 0x2a, 0x24, 0x2f, 0x22, - 0x29, 0x27, 0x22, 0x2c, 0x26, 0x29, 0x28, 0x25, - 0x20, 0x26, 0x2d, 0x21, 0x23, 0x2d, 0x24, 0x2e, - 0x2e, 0x20, 0x27, 0x2b, 0x25, 0x23, 0x2b, 0x28, - 0x29, 0x24, 0x2e, 0x23, 0x2f, 0x22, 0x25, 0x2c, - 0x22, 0x29, 0x28, 0x25, 0x2c, 0x2f, 0x23, 0x2a, - 0x27, 0x2b, 0x20, 0x2e, 0x24, 0x21, 0x2a, 0x27, - 0x21, 0x26, 0x2d, 0x20, 0x2b, 0x28, 0x26, 0x2d, - 0xec, 0xea, 0xe1, 0xef, 0xea, 0xe4, 0xef, 0xe2, - 0xe9, 0xe7, 0xe2, 0xec, 0xe6, 0xe9, 0xe8, 0xe5, - 0xe0, 0xe6, 0xed, 0xe1, 0xe3, 0xed, 0xe4, 0xee, - 0xee, 0xe0, 0xe7, 0xeb, 0xe5, 0xe3, 0xeb, 0xe8, - 0xe9, 0xe4, 0xee, 0xe3, 0xef, 0xe2, 0xe5, 0xec, - 0xe2, 0xe9, 0xe8, 0xe5, 0xec, 0xef, 0xe3, 0xea, - 0xe7, 0xeb, 0xe0, 0xee, 0xe4, 0xe1, 0xea, 0xe7, - 0xe1, 0xe6, 0xed, 0xe0, 0xeb, 0xe8, 0xe6, 0xed, - 0xcc, 0xca, 0xc1, 0xcf, 0xca, 0xc4, 0xcf, 0xc2, - 0xc9, 0xc7, 0xc2, 0xcc, 0xc6, 0xc9, 0xc8, 0xc5, - 0xc0, 0xc6, 0xcd, 0xc1, 0xc3, 0xcd, 0xc4, 0xce, - 0xce, 0xc0, 0xc7, 0xcb, 0xc5, 0xc3, 0xcb, 0xc8, - 0xc9, 0xc4, 0xce, 0xc3, 0xcf, 0xc2, 0xc5, 0xcc, - 0xc2, 0xc9, 0xc8, 0xc5, 0xcc, 0xcf, 0xc3, 0xca, - 0xc7, 0xcb, 0xc0, 0xce, 0xc4, 0xc1, 0xca, 0xc7, - 0xc1, 0xc6, 0xcd, 0xc0, 0xcb, 0xc8, 0xc6, 0xcd, - 0xbc, 0xba, 0xb1, 0xbf, 0xba, 0xb4, 0xbf, 0xb2, - 0xb9, 0xb7, 0xb2, 0xbc, 0xb6, 0xb9, 0xb8, 0xb5, - 0xb0, 0xb6, 0xbd, 0xb1, 0xb3, 0xbd, 0xb4, 0xbe, - 0xbe, 0xb0, 0xb7, 0xbb, 0xb5, 0xb3, 0xbb, 0xb8, - 0xb9, 0xb4, 0xbe, 0xb3, 0xbf, 0xb2, 0xb5, 0xbc, - 0xb2, 0xb9, 0xb8, 0xb5, 0xbc, 0xbf, 0xb3, 0xba, - 0xb7, 0xbb, 0xb0, 0xbe, 0xb4, 0xb1, 0xba, 0xb7, - 0xb1, 0xb6, 0xbd, 0xb0, 0xbb, 0xb8, 0xb6, 0xbd, - 0x4c, 0x4a, 0x41, 0x4f, 0x4a, 0x44, 0x4f, 0x42, - 0x49, 0x47, 0x42, 0x4c, 0x46, 0x49, 0x48, 0x45, - 0x40, 0x46, 0x4d, 0x41, 0x43, 0x4d, 0x44, 0x4e, - 0x4e, 0x40, 0x47, 0x4b, 0x45, 0x43, 0x4b, 0x48, - 0x49, 0x44, 0x4e, 0x43, 0x4f, 0x42, 0x45, 0x4c, - 0x42, 0x49, 0x48, 0x45, 0x4c, 0x4f, 0x43, 0x4a, - 0x47, 0x4b, 0x40, 0x4e, 0x44, 0x41, 0x4a, 0x47, - 0x41, 0x46, 0x4d, 0x40, 0x4b, 0x48, 0x46, 0x4d, - 0x2c, 0x2a, 0x21, 0x2f, 0x2a, 0x24, 0x2f, 0x22, - 0x29, 0x27, 0x22, 0x2c, 0x26, 0x29, 0x28, 0x25, - 0x20, 0x26, 0x2d, 0x21, 0x23, 0x2d, 0x24, 0x2e, - 0x2e, 0x20, 0x27, 0x2b, 0x25, 0x23, 0x2b, 0x28, - 0x29, 0x24, 0x2e, 0x23, 0x2f, 0x22, 0x25, 0x2c, - 0x22, 0x29, 0x28, 0x25, 0x2c, 0x2f, 0x23, 0x2a, - 0x27, 0x2b, 0x20, 0x2e, 0x24, 0x21, 0x2a, 0x27, - 0x21, 0x26, 0x2d, 0x20, 0x2b, 0x28, 0x26, 0x2d, - 0x1c, 0x1a, 0x11, 0x1f, 0x1a, 0x14, 0x1f, 0x12, - 0x19, 0x17, 0x12, 0x1c, 0x16, 0x19, 0x18, 0x15, - 0x10, 0x16, 0x1d, 0x11, 0x13, 0x1d, 0x14, 0x1e, - 0x1e, 0x10, 0x17, 0x1b, 0x15, 0x13, 0x1b, 0x18, - 0x19, 0x14, 0x1e, 0x13, 0x1f, 0x12, 0x15, 0x1c, - 0x12, 0x19, 0x18, 0x15, 0x1c, 0x1f, 0x13, 0x1a, - 0x17, 0x1b, 0x10, 0x1e, 0x14, 0x11, 0x1a, 0x17, - 0x11, 0x16, 0x1d, 0x10, 0x1b, 0x18, 0x16, 0x1d, - 0xcc, 0xca, 0xc1, 0xcf, 0xca, 0xc4, 0xcf, 0xc2, - 0xc9, 0xc7, 0xc2, 0xcc, 0xc6, 0xc9, 0xc8, 0xc5, - 0xc0, 0xc6, 0xcd, 0xc1, 0xc3, 0xcd, 0xc4, 0xce, - 0xce, 0xc0, 0xc7, 0xcb, 0xc5, 0xc3, 0xcb, 0xc8, - 0xc9, 0xc4, 0xce, 0xc3, 0xcf, 0xc2, 0xc5, 0xcc, - 0xc2, 0xc9, 0xc8, 0xc5, 0xcc, 0xcf, 0xc3, 0xca, - 0xc7, 0xcb, 0xc0, 0xce, 0xc4, 0xc1, 0xca, 0xc7, - 0xc1, 0xc6, 0xcd, 0xc0, 0xcb, 0xc8, 0xc6, 0xcd, - 0x7c, 0x7a, 0x71, 0x7f, 0x7a, 0x74, 0x7f, 0x72, - 0x79, 0x77, 0x72, 0x7c, 0x76, 0x79, 0x78, 0x75, - 0x70, 0x76, 0x7d, 0x71, 0x73, 0x7d, 0x74, 0x7e, - 0x7e, 0x70, 0x77, 0x7b, 0x75, 0x73, 0x7b, 0x78, - 0x79, 0x74, 0x7e, 0x73, 0x7f, 0x72, 0x75, 0x7c, - 0x72, 0x79, 0x78, 0x75, 0x7c, 0x7f, 0x73, 0x7a, - 0x77, 0x7b, 0x70, 0x7e, 0x74, 0x71, 0x7a, 0x77, - 0x71, 0x76, 0x7d, 0x70, 0x7b, 0x78, 0x76, 0x7d, - 0x4c, 0x4a, 0x41, 0x4f, 0x4a, 0x44, 0x4f, 0x42, - 0x49, 0x47, 0x42, 0x4c, 0x46, 0x49, 0x48, 0x45, - 0x40, 0x46, 0x4d, 0x41, 0x43, 0x4d, 0x44, 0x4e, - 0x4e, 0x40, 0x47, 0x4b, 0x45, 0x43, 0x4b, 0x48, - 0x49, 0x44, 0x4e, 0x43, 0x4f, 0x42, 0x45, 0x4c, - 0x42, 0x49, 0x48, 0x45, 0x4c, 0x4f, 0x43, 0x4a, - 0x47, 0x4b, 0x40, 0x4e, 0x44, 0x41, 0x4a, 0x47, - 0x41, 0x46, 0x4d, 0x40, 0x4b, 0x48, 0x46, 0x4d, - 0xac, 0xaa, 0xa1, 0xaf, 0xaa, 0xa4, 0xaf, 0xa2, - 0xa9, 0xa7, 0xa2, 0xac, 0xa6, 0xa9, 0xa8, 0xa5, - 0xa0, 0xa6, 0xad, 0xa1, 0xa3, 0xad, 0xa4, 0xae, - 0xae, 0xa0, 0xa7, 0xab, 0xa5, 0xa3, 0xab, 0xa8, - 0xa9, 0xa4, 0xae, 0xa3, 0xaf, 0xa2, 0xa5, 0xac, - 0xa2, 0xa9, 0xa8, 0xa5, 0xac, 0xaf, 0xa3, 0xaa, - 0xa7, 0xab, 0xa0, 0xae, 0xa4, 0xa1, 0xaa, 0xa7, - 0xa1, 0xa6, 0xad, 0xa0, 0xab, 0xa8, 0xa6, 0xad, - 0x7c, 0x7a, 0x71, 0x7f, 0x7a, 0x74, 0x7f, 0x72, - 0x79, 0x77, 0x72, 0x7c, 0x76, 0x79, 0x78, 0x75, - 0x70, 0x76, 0x7d, 0x71, 0x73, 0x7d, 0x74, 0x7e, - 0x7e, 0x70, 0x77, 0x7b, 0x75, 0x73, 0x7b, 0x78, - 0x79, 0x74, 0x7e, 0x73, 0x7f, 0x72, 0x75, 0x7c, - 0x72, 0x79, 0x78, 0x75, 0x7c, 0x7f, 0x73, 0x7a, - 0x77, 0x7b, 0x70, 0x7e, 0x74, 0x71, 0x7a, 0x77, - 0x71, 0x76, 0x7d, 0x70, 0x7b, 0x78, 0x76, 0x7d, - 0xbc, 0xba, 0xb1, 0xbf, 0xba, 0xb4, 0xbf, 0xb2, - 0xb9, 0xb7, 0xb2, 0xbc, 0xb6, 0xb9, 0xb8, 0xb5, - 0xb0, 0xb6, 0xbd, 0xb1, 0xb3, 0xbd, 0xb4, 0xbe, - 0xbe, 0xb0, 0xb7, 0xbb, 0xb5, 0xb3, 0xbb, 0xb8, - 0xb9, 0xb4, 0xbe, 0xb3, 0xbf, 0xb2, 0xb5, 0xbc, - 0xb2, 0xb9, 0xb8, 0xb5, 0xbc, 0xbf, 0xb3, 0xba, - 0xb7, 0xbb, 0xb0, 0xbe, 0xb4, 0xb1, 0xba, 0xb7, - 0xb1, 0xb6, 0xbd, 0xb0, 0xbb, 0xb8, 0xb6, 0xbd, - 0xdc, 0xda, 0xd1, 0xdf, 0xda, 0xd4, 0xdf, 0xd2, - 0xd9, 0xd7, 0xd2, 0xdc, 0xd6, 0xd9, 0xd8, 0xd5, - 0xd0, 0xd6, 0xdd, 0xd1, 0xd3, 0xdd, 0xd4, 0xde, - 0xde, 0xd0, 0xd7, 0xdb, 0xd5, 0xd3, 0xdb, 0xd8, - 0xd9, 0xd4, 0xde, 0xd3, 0xdf, 0xd2, 0xd5, 0xdc, - 0xd2, 0xd9, 0xd8, 0xd5, 0xdc, 0xdf, 0xd3, 0xda, - 0xd7, 0xdb, 0xd0, 0xde, 0xd4, 0xd1, 0xda, 0xd7, - 0xd1, 0xd6, 0xdd, 0xd0, 0xdb, 0xd8, 0xd6, 0xdd, - 0x6c, 0x6a, 0x61, 0x6f, 0x6a, 0x64, 0x6f, 0x62, - 0x69, 0x67, 0x62, 0x6c, 0x66, 0x69, 0x68, 0x65, - 0x60, 0x66, 0x6d, 0x61, 0x63, 0x6d, 0x64, 0x6e, - 0x6e, 0x60, 0x67, 0x6b, 0x65, 0x63, 0x6b, 0x68, - 0x69, 0x64, 0x6e, 0x63, 0x6f, 0x62, 0x65, 0x6c, - 0x62, 0x69, 0x68, 0x65, 0x6c, 0x6f, 0x63, 0x6a, - 0x67, 0x6b, 0x60, 0x6e, 0x64, 0x61, 0x6a, 0x67, - 0x61, 0x66, 0x6d, 0x60, 0x6b, 0x68, 0x66, 0x6d, - 0x1c, 0x1a, 0x11, 0x1f, 0x1a, 0x14, 0x1f, 0x12, - 0x19, 0x17, 0x12, 0x1c, 0x16, 0x19, 0x18, 0x15, - 0x10, 0x16, 0x1d, 0x11, 0x13, 0x1d, 0x14, 0x1e, - 0x1e, 0x10, 0x17, 0x1b, 0x15, 0x13, 0x1b, 0x18, - 0x19, 0x14, 0x1e, 0x13, 0x1f, 0x12, 0x15, 0x1c, - 0x12, 0x19, 0x18, 0x15, 0x1c, 0x1f, 0x13, 0x1a, - 0x17, 0x1b, 0x10, 0x1e, 0x14, 0x11, 0x1a, 0x17, - 0x11, 0x16, 0x1d, 0x10, 0x1b, 0x18, 0x16, 0x1d, - 0x8c, 0x8a, 0x81, 0x8f, 0x8a, 0x84, 0x8f, 0x82, - 0x89, 0x87, 0x82, 0x8c, 0x86, 0x89, 0x88, 0x85, - 0x80, 0x86, 0x8d, 0x81, 0x83, 0x8d, 0x84, 0x8e, - 0x8e, 0x80, 0x87, 0x8b, 0x85, 0x83, 0x8b, 0x88, - 0x89, 0x84, 0x8e, 0x83, 0x8f, 0x82, 0x85, 0x8c, - 0x82, 0x89, 0x88, 0x85, 0x8c, 0x8f, 0x83, 0x8a, - 0x87, 0x8b, 0x80, 0x8e, 0x84, 0x81, 0x8a, 0x87, - 0x81, 0x86, 0x8d, 0x80, 0x8b, 0x88, 0x86, 0x8d, - 0x5c, 0x5a, 0x51, 0x5f, 0x5a, 0x54, 0x5f, 0x52, - 0x59, 0x57, 0x52, 0x5c, 0x56, 0x59, 0x58, 0x55, - 0x50, 0x56, 0x5d, 0x51, 0x53, 0x5d, 0x54, 0x5e, - 0x5e, 0x50, 0x57, 0x5b, 0x55, 0x53, 0x5b, 0x58, - 0x59, 0x54, 0x5e, 0x53, 0x5f, 0x52, 0x55, 0x5c, - 0x52, 0x59, 0x58, 0x55, 0x5c, 0x5f, 0x53, 0x5a, - 0x57, 0x5b, 0x50, 0x5e, 0x54, 0x51, 0x5a, 0x57, - 0x51, 0x56, 0x5d, 0x50, 0x5b, 0x58, 0x56, 0x5d, - 0x5c, 0x5a, 0x51, 0x5f, 0x5a, 0x54, 0x5f, 0x52, - 0x59, 0x57, 0x52, 0x5c, 0x56, 0x59, 0x58, 0x55, - 0x50, 0x56, 0x5d, 0x51, 0x53, 0x5d, 0x54, 0x5e, - 0x5e, 0x50, 0x57, 0x5b, 0x55, 0x53, 0x5b, 0x58, - 0x59, 0x54, 0x5e, 0x53, 0x5f, 0x52, 0x55, 0x5c, - 0x52, 0x59, 0x58, 0x55, 0x5c, 0x5f, 0x53, 0x5a, - 0x57, 0x5b, 0x50, 0x5e, 0x54, 0x51, 0x5a, 0x57, - 0x51, 0x56, 0x5d, 0x50, 0x5b, 0x58, 0x56, 0x5d, - 0x0c, 0x0a, 0x01, 0x0f, 0x0a, 0x04, 0x0f, 0x02, - 0x09, 0x07, 0x02, 0x0c, 0x06, 0x09, 0x08, 0x05, - 0x00, 0x06, 0x0d, 0x01, 0x03, 0x0d, 0x04, 0x0e, - 0x0e, 0x00, 0x07, 0x0b, 0x05, 0x03, 0x0b, 0x08, - 0x09, 0x04, 0x0e, 0x03, 0x0f, 0x02, 0x05, 0x0c, - 0x02, 0x09, 0x08, 0x05, 0x0c, 0x0f, 0x03, 0x0a, - 0x07, 0x0b, 0x00, 0x0e, 0x04, 0x01, 0x0a, 0x07, - 0x01, 0x06, 0x0d, 0x00, 0x0b, 0x08, 0x06, 0x0d, - 0x3c, 0x3a, 0x31, 0x3f, 0x3a, 0x34, 0x3f, 0x32, - 0x39, 0x37, 0x32, 0x3c, 0x36, 0x39, 0x38, 0x35, - 0x30, 0x36, 0x3d, 0x31, 0x33, 0x3d, 0x34, 0x3e, - 0x3e, 0x30, 0x37, 0x3b, 0x35, 0x33, 0x3b, 0x38, - 0x39, 0x34, 0x3e, 0x33, 0x3f, 0x32, 0x35, 0x3c, - 0x32, 0x39, 0x38, 0x35, 0x3c, 0x3f, 0x33, 0x3a, - 0x37, 0x3b, 0x30, 0x3e, 0x34, 0x31, 0x3a, 0x37, - 0x31, 0x36, 0x3d, 0x30, 0x3b, 0x38, 0x36, 0x3d, - 0xfc, 0xfa, 0xf1, 0xff, 0xfa, 0xf4, 0xff, 0xf2, - 0xf9, 0xf7, 0xf2, 0xfc, 0xf6, 0xf9, 0xf8, 0xf5, - 0xf0, 0xf6, 0xfd, 0xf1, 0xf3, 0xfd, 0xf4, 0xfe, - 0xfe, 0xf0, 0xf7, 0xfb, 0xf5, 0xf3, 0xfb, 0xf8, - 0xf9, 0xf4, 0xfe, 0xf3, 0xff, 0xf2, 0xf5, 0xfc, - 0xf2, 0xf9, 0xf8, 0xf5, 0xfc, 0xff, 0xf3, 0xfa, - 0xf7, 0xfb, 0xf0, 0xfe, 0xf4, 0xf1, 0xfa, 0xf7, - 0xf1, 0xf6, 0xfd, 0xf0, 0xfb, 0xf8, 0xf6, 0xfd, - 0xfc, 0xfa, 0xf1, 0xff, 0xfa, 0xf4, 0xff, 0xf2, - 0xf9, 0xf7, 0xf2, 0xfc, 0xf6, 0xf9, 0xf8, 0xf5, - 0xf0, 0xf6, 0xfd, 0xf1, 0xf3, 0xfd, 0xf4, 0xfe, - 0xfe, 0xf0, 0xf7, 0xfb, 0xf5, 0xf3, 0xfb, 0xf8, - 0xf9, 0xf4, 0xfe, 0xf3, 0xff, 0xf2, 0xf5, 0xfc, - 0xf2, 0xf9, 0xf8, 0xf5, 0xfc, 0xff, 0xf3, 0xfa, - 0xf7, 0xfb, 0xf0, 0xfe, 0xf4, 0xf1, 0xfa, 0xf7, - 0xf1, 0xf6, 0xfd, 0xf0, 0xfb, 0xf8, 0xf6, 0xfd, - 0xac, 0xaa, 0xa1, 0xaf, 0xaa, 0xa4, 0xaf, 0xa2, - 0xa9, 0xa7, 0xa2, 0xac, 0xa6, 0xa9, 0xa8, 0xa5, - 0xa0, 0xa6, 0xad, 0xa1, 0xa3, 0xad, 0xa4, 0xae, - 0xae, 0xa0, 0xa7, 0xab, 0xa5, 0xa3, 0xab, 0xa8, - 0xa9, 0xa4, 0xae, 0xa3, 0xaf, 0xa2, 0xa5, 0xac, - 0xa2, 0xa9, 0xa8, 0xa5, 0xac, 0xaf, 0xa3, 0xaa, - 0xa7, 0xab, 0xa0, 0xae, 0xa4, 0xa1, 0xaa, 0xa7, - 0xa1, 0xa6, 0xad, 0xa0, 0xab, 0xa8, 0xa6, 0xad, - 0xdc, 0xda, 0xd1, 0xdf, 0xda, 0xd4, 0xdf, 0xd2, - 0xd9, 0xd7, 0xd2, 0xdc, 0xd6, 0xd9, 0xd8, 0xd5, - 0xd0, 0xd6, 0xdd, 0xd1, 0xd3, 0xdd, 0xd4, 0xde, - 0xde, 0xd0, 0xd7, 0xdb, 0xd5, 0xd3, 0xdb, 0xd8, - 0xd9, 0xd4, 0xde, 0xd3, 0xdf, 0xd2, 0xd5, 0xdc, - 0xd2, 0xd9, 0xd8, 0xd5, 0xdc, 0xdf, 0xd3, 0xda, - 0xd7, 0xdb, 0xd0, 0xde, 0xd4, 0xd1, 0xda, 0xd7, - 0xd1, 0xd6, 0xdd, 0xd0, 0xdb, 0xd8, 0xd6, 0xdd, - 0x3c, 0x3a, 0x31, 0x3f, 0x3a, 0x34, 0x3f, 0x32, - 0x39, 0x37, 0x32, 0x3c, 0x36, 0x39, 0x38, 0x35, - 0x30, 0x36, 0x3d, 0x31, 0x33, 0x3d, 0x34, 0x3e, - 0x3e, 0x30, 0x37, 0x3b, 0x35, 0x33, 0x3b, 0x38, - 0x39, 0x34, 0x3e, 0x33, 0x3f, 0x32, 0x35, 0x3c, - 0x32, 0x39, 0x38, 0x35, 0x3c, 0x3f, 0x33, 0x3a, - 0x37, 0x3b, 0x30, 0x3e, 0x34, 0x31, 0x3a, 0x37, - 0x31, 0x36, 0x3d, 0x30, 0x3b, 0x38, 0x36, 0x3d, - 0x0c, 0x0a, 0x01, 0x0f, 0x0a, 0x04, 0x0f, 0x02, - 0x09, 0x07, 0x02, 0x0c, 0x06, 0x09, 0x08, 0x05, - 0x00, 0x06, 0x0d, 0x01, 0x03, 0x0d, 0x04, 0x0e, - 0x0e, 0x00, 0x07, 0x0b, 0x05, 0x03, 0x0b, 0x08, - 0x09, 0x04, 0x0e, 0x03, 0x0f, 0x02, 0x05, 0x0c, - 0x02, 0x09, 0x08, 0x05, 0x0c, 0x0f, 0x03, 0x0a, - 0x07, 0x0b, 0x00, 0x0e, 0x04, 0x01, 0x0a, 0x07, - 0x01, 0x06, 0x0d, 0x00, 0x0b, 0x08, 0x06, 0x0d, - 0x9c, 0x9a, 0x91, 0x9f, 0x9a, 0x94, 0x9f, 0x92, - 0x99, 0x97, 0x92, 0x9c, 0x96, 0x99, 0x98, 0x95, - 0x90, 0x96, 0x9d, 0x91, 0x93, 0x9d, 0x94, 0x9e, - 0x9e, 0x90, 0x97, 0x9b, 0x95, 0x93, 0x9b, 0x98, - 0x99, 0x94, 0x9e, 0x93, 0x9f, 0x92, 0x95, 0x9c, - 0x92, 0x99, 0x98, 0x95, 0x9c, 0x9f, 0x93, 0x9a, - 0x97, 0x9b, 0x90, 0x9e, 0x94, 0x91, 0x9a, 0x97, - 0x91, 0x96, 0x9d, 0x90, 0x9b, 0x98, 0x96, 0x9d, - 0xec, 0xea, 0xe1, 0xef, 0xea, 0xe4, 0xef, 0xe2, - 0xe9, 0xe7, 0xe2, 0xec, 0xe6, 0xe9, 0xe8, 0xe5, - 0xe0, 0xe6, 0xed, 0xe1, 0xe3, 0xed, 0xe4, 0xee, - 0xee, 0xe0, 0xe7, 0xeb, 0xe5, 0xe3, 0xeb, 0xe8, - 0xe9, 0xe4, 0xee, 0xe3, 0xef, 0xe2, 0xe5, 0xec, - 0xe2, 0xe9, 0xe8, 0xe5, 0xec, 0xef, 0xe3, 0xea, - 0xe7, 0xeb, 0xe0, 0xee, 0xe4, 0xe1, 0xea, 0xe7, - 0xe1, 0xe6, 0xed, 0xe0, 0xeb, 0xe8, 0xe6, 0xed, - 0x8c, 0x8a, 0x81, 0x8f, 0x8a, 0x84, 0x8f, 0x82, - 0x89, 0x87, 0x82, 0x8c, 0x86, 0x89, 0x88, 0x85, - 0x80, 0x86, 0x8d, 0x81, 0x83, 0x8d, 0x84, 0x8e, - 0x8e, 0x80, 0x87, 0x8b, 0x85, 0x83, 0x8b, 0x88, - 0x89, 0x84, 0x8e, 0x83, 0x8f, 0x82, 0x85, 0x8c, - 0x82, 0x89, 0x88, 0x85, 0x8c, 0x8f, 0x83, 0x8a, - 0x87, 0x8b, 0x80, 0x8e, 0x84, 0x81, 0x8a, 0x87, - 0x81, 0x86, 0x8d, 0x80, 0x8b, 0x88, 0x86, 0x8d, - 0x9c, 0x9a, 0x91, 0x9f, 0x9a, 0x94, 0x9f, 0x92, - 0x99, 0x97, 0x92, 0x9c, 0x96, 0x99, 0x98, 0x95, - 0x90, 0x96, 0x9d, 0x91, 0x93, 0x9d, 0x94, 0x9e, - 0x9e, 0x90, 0x97, 0x9b, 0x95, 0x93, 0x9b, 0x98, - 0x99, 0x94, 0x9e, 0x93, 0x9f, 0x92, 0x95, 0x9c, - 0x92, 0x99, 0x98, 0x95, 0x9c, 0x9f, 0x93, 0x9a, - 0x97, 0x9b, 0x90, 0x9e, 0x94, 0x91, 0x9a, 0x97, - 0x91, 0x96, 0x9d, 0x90, 0x9b, 0x98, 0x96, 0x9d, - 0x6c, 0x6a, 0x61, 0x6f, 0x6a, 0x64, 0x6f, 0x62, - 0x69, 0x67, 0x62, 0x6c, 0x66, 0x69, 0x68, 0x65, - 0x60, 0x66, 0x6d, 0x61, 0x63, 0x6d, 0x64, 0x6e, - 0x6e, 0x60, 0x67, 0x6b, 0x65, 0x63, 0x6b, 0x68, - 0x69, 0x64, 0x6e, 0x63, 0x6f, 0x62, 0x65, 0x6c, - 0x62, 0x69, 0x68, 0x65, 0x6c, 0x6f, 0x63, 0x6a, - 0x67, 0x6b, 0x60, 0x6e, 0x64, 0x61, 0x6a, 0x67, - 0x61, 0x66, 0x6d, 0x60, 0x6b, 0x68, 0x66, 0x6d, - 0x4c, 0x4a, 0x41, 0x4f, 0x4a, 0x44, 0x4f, 0x42, - 0x49, 0x47, 0x42, 0x4c, 0x46, 0x49, 0x48, 0x45, - 0x40, 0x46, 0x4d, 0x41, 0x43, 0x4d, 0x44, 0x4e, - 0x4e, 0x40, 0x47, 0x4b, 0x45, 0x43, 0x4b, 0x48, - 0x49, 0x44, 0x4e, 0x43, 0x4f, 0x42, 0x45, 0x4c, - 0x42, 0x49, 0x48, 0x45, 0x4c, 0x4f, 0x43, 0x4a, - 0x47, 0x4b, 0x40, 0x4e, 0x44, 0x41, 0x4a, 0x47, - 0x41, 0x46, 0x4d, 0x40, 0x4b, 0x48, 0x46, 0x4d, - 0xbc, 0xba, 0xb1, 0xbf, 0xba, 0xb4, 0xbf, 0xb2, - 0xb9, 0xb7, 0xb2, 0xbc, 0xb6, 0xb9, 0xb8, 0xb5, - 0xb0, 0xb6, 0xbd, 0xb1, 0xb3, 0xbd, 0xb4, 0xbe, - 0xbe, 0xb0, 0xb7, 0xbb, 0xb5, 0xb3, 0xbb, 0xb8, - 0xb9, 0xb4, 0xbe, 0xb3, 0xbf, 0xb2, 0xb5, 0xbc, - 0xb2, 0xb9, 0xb8, 0xb5, 0xbc, 0xbf, 0xb3, 0xba, - 0xb7, 0xbb, 0xb0, 0xbe, 0xb4, 0xb1, 0xba, 0xb7, - 0xb1, 0xb6, 0xbd, 0xb0, 0xbb, 0xb8, 0xb6, 0xbd, - 0x2c, 0x2a, 0x21, 0x2f, 0x2a, 0x24, 0x2f, 0x22, - 0x29, 0x27, 0x22, 0x2c, 0x26, 0x29, 0x28, 0x25, - 0x20, 0x26, 0x2d, 0x21, 0x23, 0x2d, 0x24, 0x2e, - 0x2e, 0x20, 0x27, 0x2b, 0x25, 0x23, 0x2b, 0x28, - 0x29, 0x24, 0x2e, 0x23, 0x2f, 0x22, 0x25, 0x2c, - 0x22, 0x29, 0x28, 0x25, 0x2c, 0x2f, 0x23, 0x2a, - 0x27, 0x2b, 0x20, 0x2e, 0x24, 0x21, 0x2a, 0x27, - 0x21, 0x26, 0x2d, 0x20, 0x2b, 0x28, 0x26, 0x2d, - 0x8c, 0x8a, 0x81, 0x8f, 0x8a, 0x84, 0x8f, 0x82, - 0x89, 0x87, 0x82, 0x8c, 0x86, 0x89, 0x88, 0x85, - 0x80, 0x86, 0x8d, 0x81, 0x83, 0x8d, 0x84, 0x8e, - 0x8e, 0x80, 0x87, 0x8b, 0x85, 0x83, 0x8b, 0x88, - 0x89, 0x84, 0x8e, 0x83, 0x8f, 0x82, 0x85, 0x8c, - 0x82, 0x89, 0x88, 0x85, 0x8c, 0x8f, 0x83, 0x8a, - 0x87, 0x8b, 0x80, 0x8e, 0x84, 0x81, 0x8a, 0x87, - 0x81, 0x86, 0x8d, 0x80, 0x8b, 0x88, 0x86, 0x8d, - 0x1c, 0x1a, 0x11, 0x1f, 0x1a, 0x14, 0x1f, 0x12, - 0x19, 0x17, 0x12, 0x1c, 0x16, 0x19, 0x18, 0x15, - 0x10, 0x16, 0x1d, 0x11, 0x13, 0x1d, 0x14, 0x1e, - 0x1e, 0x10, 0x17, 0x1b, 0x15, 0x13, 0x1b, 0x18, - 0x19, 0x14, 0x1e, 0x13, 0x1f, 0x12, 0x15, 0x1c, - 0x12, 0x19, 0x18, 0x15, 0x1c, 0x1f, 0x13, 0x1a, - 0x17, 0x1b, 0x10, 0x1e, 0x14, 0x11, 0x1a, 0x17, - 0x11, 0x16, 0x1d, 0x10, 0x1b, 0x18, 0x16, 0x1d, - 0xcc, 0xca, 0xc1, 0xcf, 0xca, 0xc4, 0xcf, 0xc2, - 0xc9, 0xc7, 0xc2, 0xcc, 0xc6, 0xc9, 0xc8, 0xc5, - 0xc0, 0xc6, 0xcd, 0xc1, 0xc3, 0xcd, 0xc4, 0xce, - 0xce, 0xc0, 0xc7, 0xcb, 0xc5, 0xc3, 0xcb, 0xc8, - 0xc9, 0xc4, 0xce, 0xc3, 0xcf, 0xc2, 0xc5, 0xcc, - 0xc2, 0xc9, 0xc8, 0xc5, 0xcc, 0xcf, 0xc3, 0xca, - 0xc7, 0xcb, 0xc0, 0xce, 0xc4, 0xc1, 0xca, 0xc7, - 0xc1, 0xc6, 0xcd, 0xc0, 0xcb, 0xc8, 0xc6, 0xcd, - 0xbc, 0xba, 0xb1, 0xbf, 0xba, 0xb4, 0xbf, 0xb2, - 0xb9, 0xb7, 0xb2, 0xbc, 0xb6, 0xb9, 0xb8, 0xb5, - 0xb0, 0xb6, 0xbd, 0xb1, 0xb3, 0xbd, 0xb4, 0xbe, - 0xbe, 0xb0, 0xb7, 0xbb, 0xb5, 0xb3, 0xbb, 0xb8, - 0xb9, 0xb4, 0xbe, 0xb3, 0xbf, 0xb2, 0xb5, 0xbc, - 0xb2, 0xb9, 0xb8, 0xb5, 0xbc, 0xbf, 0xb3, 0xba, - 0xb7, 0xbb, 0xb0, 0xbe, 0xb4, 0xb1, 0xba, 0xb7, - 0xb1, 0xb6, 0xbd, 0xb0, 0xbb, 0xb8, 0xb6, 0xbd, - 0x7c, 0x7a, 0x71, 0x7f, 0x7a, 0x74, 0x7f, 0x72, - 0x79, 0x77, 0x72, 0x7c, 0x76, 0x79, 0x78, 0x75, - 0x70, 0x76, 0x7d, 0x71, 0x73, 0x7d, 0x74, 0x7e, - 0x7e, 0x70, 0x77, 0x7b, 0x75, 0x73, 0x7b, 0x78, - 0x79, 0x74, 0x7e, 0x73, 0x7f, 0x72, 0x75, 0x7c, - 0x72, 0x79, 0x78, 0x75, 0x7c, 0x7f, 0x73, 0x7a, - 0x77, 0x7b, 0x70, 0x7e, 0x74, 0x71, 0x7a, 0x77, - 0x71, 0x76, 0x7d, 0x70, 0x7b, 0x78, 0x76, 0x7d, - 0xac, 0xaa, 0xa1, 0xaf, 0xaa, 0xa4, 0xaf, 0xa2, - 0xa9, 0xa7, 0xa2, 0xac, 0xa6, 0xa9, 0xa8, 0xa5, - 0xa0, 0xa6, 0xad, 0xa1, 0xa3, 0xad, 0xa4, 0xae, - 0xae, 0xa0, 0xa7, 0xab, 0xa5, 0xa3, 0xab, 0xa8, - 0xa9, 0xa4, 0xae, 0xa3, 0xaf, 0xa2, 0xa5, 0xac, - 0xa2, 0xa9, 0xa8, 0xa5, 0xac, 0xaf, 0xa3, 0xaa, - 0xa7, 0xab, 0xa0, 0xae, 0xa4, 0xa1, 0xaa, 0xa7, - 0xa1, 0xa6, 0xad, 0xa0, 0xab, 0xa8, 0xa6, 0xad, - 0x1c, 0x1a, 0x11, 0x1f, 0x1a, 0x14, 0x1f, 0x12, - 0x19, 0x17, 0x12, 0x1c, 0x16, 0x19, 0x18, 0x15, - 0x10, 0x16, 0x1d, 0x11, 0x13, 0x1d, 0x14, 0x1e, - 0x1e, 0x10, 0x17, 0x1b, 0x15, 0x13, 0x1b, 0x18, - 0x19, 0x14, 0x1e, 0x13, 0x1f, 0x12, 0x15, 0x1c, - 0x12, 0x19, 0x18, 0x15, 0x1c, 0x1f, 0x13, 0x1a, - 0x17, 0x1b, 0x10, 0x1e, 0x14, 0x11, 0x1a, 0x17, - 0x11, 0x16, 0x1d, 0x10, 0x1b, 0x18, 0x16, 0x1d, - 0xdc, 0xda, 0xd1, 0xdf, 0xda, 0xd4, 0xdf, 0xd2, - 0xd9, 0xd7, 0xd2, 0xdc, 0xd6, 0xd9, 0xd8, 0xd5, - 0xd0, 0xd6, 0xdd, 0xd1, 0xd3, 0xdd, 0xd4, 0xde, - 0xde, 0xd0, 0xd7, 0xdb, 0xd5, 0xd3, 0xdb, 0xd8, - 0xd9, 0xd4, 0xde, 0xd3, 0xdf, 0xd2, 0xd5, 0xdc, - 0xd2, 0xd9, 0xd8, 0xd5, 0xdc, 0xdf, 0xd3, 0xda, - 0xd7, 0xdb, 0xd0, 0xde, 0xd4, 0xd1, 0xda, 0xd7, - 0xd1, 0xd6, 0xdd, 0xd0, 0xdb, 0xd8, 0xd6, 0xdd, - 0xec, 0xea, 0xe1, 0xef, 0xea, 0xe4, 0xef, 0xe2, - 0xe9, 0xe7, 0xe2, 0xec, 0xe6, 0xe9, 0xe8, 0xe5, - 0xe0, 0xe6, 0xed, 0xe1, 0xe3, 0xed, 0xe4, 0xee, - 0xee, 0xe0, 0xe7, 0xeb, 0xe5, 0xe3, 0xeb, 0xe8, - 0xe9, 0xe4, 0xee, 0xe3, 0xef, 0xe2, 0xe5, 0xec, - 0xe2, 0xe9, 0xe8, 0xe5, 0xec, 0xef, 0xe3, 0xea, - 0xe7, 0xeb, 0xe0, 0xee, 0xe4, 0xe1, 0xea, 0xe7, - 0xe1, 0xe6, 0xed, 0xe0, 0xeb, 0xe8, 0xe6, 0xed, - 0x7c, 0x7a, 0x71, 0x7f, 0x7a, 0x74, 0x7f, 0x72, - 0x79, 0x77, 0x72, 0x7c, 0x76, 0x79, 0x78, 0x75, - 0x70, 0x76, 0x7d, 0x71, 0x73, 0x7d, 0x74, 0x7e, - 0x7e, 0x70, 0x77, 0x7b, 0x75, 0x73, 0x7b, 0x78, - 0x79, 0x74, 0x7e, 0x73, 0x7f, 0x72, 0x75, 0x7c, - 0x72, 0x79, 0x78, 0x75, 0x7c, 0x7f, 0x73, 0x7a, - 0x77, 0x7b, 0x70, 0x7e, 0x74, 0x71, 0x7a, 0x77, - 0x71, 0x76, 0x7d, 0x70, 0x7b, 0x78, 0x76, 0x7d, - 0x2c, 0x2a, 0x21, 0x2f, 0x2a, 0x24, 0x2f, 0x22, - 0x29, 0x27, 0x22, 0x2c, 0x26, 0x29, 0x28, 0x25, - 0x20, 0x26, 0x2d, 0x21, 0x23, 0x2d, 0x24, 0x2e, - 0x2e, 0x20, 0x27, 0x2b, 0x25, 0x23, 0x2b, 0x28, - 0x29, 0x24, 0x2e, 0x23, 0x2f, 0x22, 0x25, 0x2c, - 0x22, 0x29, 0x28, 0x25, 0x2c, 0x2f, 0x23, 0x2a, - 0x27, 0x2b, 0x20, 0x2e, 0x24, 0x21, 0x2a, 0x27, - 0x21, 0x26, 0x2d, 0x20, 0x2b, 0x28, 0x26, 0x2d, - 0x8c, 0x8a, 0x81, 0x8f, 0x8a, 0x84, 0x8f, 0x82, - 0x89, 0x87, 0x82, 0x8c, 0x86, 0x89, 0x88, 0x85, - 0x80, 0x86, 0x8d, 0x81, 0x83, 0x8d, 0x84, 0x8e, - 0x8e, 0x80, 0x87, 0x8b, 0x85, 0x83, 0x8b, 0x88, - 0x89, 0x84, 0x8e, 0x83, 0x8f, 0x82, 0x85, 0x8c, - 0x82, 0x89, 0x88, 0x85, 0x8c, 0x8f, 0x83, 0x8a, - 0x87, 0x8b, 0x80, 0x8e, 0x84, 0x81, 0x8a, 0x87, - 0x81, 0x86, 0x8d, 0x80, 0x8b, 0x88, 0x86, 0x8d, - 0xdc, 0xda, 0xd1, 0xdf, 0xda, 0xd4, 0xdf, 0xd2, - 0xd9, 0xd7, 0xd2, 0xdc, 0xd6, 0xd9, 0xd8, 0xd5, - 0xd0, 0xd6, 0xdd, 0xd1, 0xd3, 0xdd, 0xd4, 0xde, - 0xde, 0xd0, 0xd7, 0xdb, 0xd5, 0xd3, 0xdb, 0xd8, - 0xd9, 0xd4, 0xde, 0xd3, 0xdf, 0xd2, 0xd5, 0xdc, - 0xd2, 0xd9, 0xd8, 0xd5, 0xdc, 0xdf, 0xd3, 0xda, - 0xd7, 0xdb, 0xd0, 0xde, 0xd4, 0xd1, 0xda, 0xd7, - 0xd1, 0xd6, 0xdd, 0xd0, 0xdb, 0xd8, 0xd6, 0xdd, - 0xfc, 0xfa, 0xf1, 0xff, 0xfa, 0xf4, 0xff, 0xf2, - 0xf9, 0xf7, 0xf2, 0xfc, 0xf6, 0xf9, 0xf8, 0xf5, - 0xf0, 0xf6, 0xfd, 0xf1, 0xf3, 0xfd, 0xf4, 0xfe, - 0xfe, 0xf0, 0xf7, 0xfb, 0xf5, 0xf3, 0xfb, 0xf8, - 0xf9, 0xf4, 0xfe, 0xf3, 0xff, 0xf2, 0xf5, 0xfc, - 0xf2, 0xf9, 0xf8, 0xf5, 0xfc, 0xff, 0xf3, 0xfa, - 0xf7, 0xfb, 0xf0, 0xfe, 0xf4, 0xf1, 0xfa, 0xf7, - 0xf1, 0xf6, 0xfd, 0xf0, 0xfb, 0xf8, 0xf6, 0xfd, - 0x6c, 0x6a, 0x61, 0x6f, 0x6a, 0x64, 0x6f, 0x62, - 0x69, 0x67, 0x62, 0x6c, 0x66, 0x69, 0x68, 0x65, - 0x60, 0x66, 0x6d, 0x61, 0x63, 0x6d, 0x64, 0x6e, - 0x6e, 0x60, 0x67, 0x6b, 0x65, 0x63, 0x6b, 0x68, - 0x69, 0x64, 0x6e, 0x63, 0x6f, 0x62, 0x65, 0x6c, - 0x62, 0x69, 0x68, 0x65, 0x6c, 0x6f, 0x63, 0x6a, - 0x67, 0x6b, 0x60, 0x6e, 0x64, 0x61, 0x6a, 0x67, - 0x61, 0x66, 0x6d, 0x60, 0x6b, 0x68, 0x66, 0x6d, - 0x9c, 0x9a, 0x91, 0x9f, 0x9a, 0x94, 0x9f, 0x92, - 0x99, 0x97, 0x92, 0x9c, 0x96, 0x99, 0x98, 0x95, - 0x90, 0x96, 0x9d, 0x91, 0x93, 0x9d, 0x94, 0x9e, - 0x9e, 0x90, 0x97, 0x9b, 0x95, 0x93, 0x9b, 0x98, - 0x99, 0x94, 0x9e, 0x93, 0x9f, 0x92, 0x95, 0x9c, - 0x92, 0x99, 0x98, 0x95, 0x9c, 0x9f, 0x93, 0x9a, - 0x97, 0x9b, 0x90, 0x9e, 0x94, 0x91, 0x9a, 0x97, - 0x91, 0x96, 0x9d, 0x90, 0x9b, 0x98, 0x96, 0x9d, - 0xfc, 0xfa, 0xf1, 0xff, 0xfa, 0xf4, 0xff, 0xf2, - 0xf9, 0xf7, 0xf2, 0xfc, 0xf6, 0xf9, 0xf8, 0xf5, - 0xf0, 0xf6, 0xfd, 0xf1, 0xf3, 0xfd, 0xf4, 0xfe, - 0xfe, 0xf0, 0xf7, 0xfb, 0xf5, 0xf3, 0xfb, 0xf8, - 0xf9, 0xf4, 0xfe, 0xf3, 0xff, 0xf2, 0xf5, 0xfc, - 0xf2, 0xf9, 0xf8, 0xf5, 0xfc, 0xff, 0xf3, 0xfa, - 0xf7, 0xfb, 0xf0, 0xfe, 0xf4, 0xf1, 0xfa, 0xf7, - 0xf1, 0xf6, 0xfd, 0xf0, 0xfb, 0xf8, 0xf6, 0xfd, - 0xcc, 0xca, 0xc1, 0xcf, 0xca, 0xc4, 0xcf, 0xc2, - 0xc9, 0xc7, 0xc2, 0xcc, 0xc6, 0xc9, 0xc8, 0xc5, - 0xc0, 0xc6, 0xcd, 0xc1, 0xc3, 0xcd, 0xc4, 0xce, - 0xce, 0xc0, 0xc7, 0xcb, 0xc5, 0xc3, 0xcb, 0xc8, - 0xc9, 0xc4, 0xce, 0xc3, 0xcf, 0xc2, 0xc5, 0xcc, - 0xc2, 0xc9, 0xc8, 0xc5, 0xcc, 0xcf, 0xc3, 0xca, - 0xc7, 0xcb, 0xc0, 0xce, 0xc4, 0xc1, 0xca, 0xc7, - 0xc1, 0xc6, 0xcd, 0xc0, 0xcb, 0xc8, 0xc6, 0xcd, - 0x0c, 0x0a, 0x01, 0x0f, 0x0a, 0x04, 0x0f, 0x02, - 0x09, 0x07, 0x02, 0x0c, 0x06, 0x09, 0x08, 0x05, - 0x00, 0x06, 0x0d, 0x01, 0x03, 0x0d, 0x04, 0x0e, - 0x0e, 0x00, 0x07, 0x0b, 0x05, 0x03, 0x0b, 0x08, - 0x09, 0x04, 0x0e, 0x03, 0x0f, 0x02, 0x05, 0x0c, - 0x02, 0x09, 0x08, 0x05, 0x0c, 0x0f, 0x03, 0x0a, - 0x07, 0x0b, 0x00, 0x0e, 0x04, 0x01, 0x0a, 0x07, - 0x01, 0x06, 0x0d, 0x00, 0x0b, 0x08, 0x06, 0x0d, - 0x5c, 0x5a, 0x51, 0x5f, 0x5a, 0x54, 0x5f, 0x52, - 0x59, 0x57, 0x52, 0x5c, 0x56, 0x59, 0x58, 0x55, - 0x50, 0x56, 0x5d, 0x51, 0x53, 0x5d, 0x54, 0x5e, - 0x5e, 0x50, 0x57, 0x5b, 0x55, 0x53, 0x5b, 0x58, - 0x59, 0x54, 0x5e, 0x53, 0x5f, 0x52, 0x55, 0x5c, - 0x52, 0x59, 0x58, 0x55, 0x5c, 0x5f, 0x53, 0x5a, - 0x57, 0x5b, 0x50, 0x5e, 0x54, 0x51, 0x5a, 0x57, - 0x51, 0x56, 0x5d, 0x50, 0x5b, 0x58, 0x56, 0x5d, - 0x9c, 0x9a, 0x91, 0x9f, 0x9a, 0x94, 0x9f, 0x92, - 0x99, 0x97, 0x92, 0x9c, 0x96, 0x99, 0x98, 0x95, - 0x90, 0x96, 0x9d, 0x91, 0x93, 0x9d, 0x94, 0x9e, - 0x9e, 0x90, 0x97, 0x9b, 0x95, 0x93, 0x9b, 0x98, - 0x99, 0x94, 0x9e, 0x93, 0x9f, 0x92, 0x95, 0x9c, - 0x92, 0x99, 0x98, 0x95, 0x9c, 0x9f, 0x93, 0x9a, - 0x97, 0x9b, 0x90, 0x9e, 0x94, 0x91, 0x9a, 0x97, - 0x91, 0x96, 0x9d, 0x90, 0x9b, 0x98, 0x96, 0x9d, - 0x6c, 0x6a, 0x61, 0x6f, 0x6a, 0x64, 0x6f, 0x62, - 0x69, 0x67, 0x62, 0x6c, 0x66, 0x69, 0x68, 0x65, - 0x60, 0x66, 0x6d, 0x61, 0x63, 0x6d, 0x64, 0x6e, - 0x6e, 0x60, 0x67, 0x6b, 0x65, 0x63, 0x6b, 0x68, - 0x69, 0x64, 0x6e, 0x63, 0x6f, 0x62, 0x65, 0x6c, - 0x62, 0x69, 0x68, 0x65, 0x6c, 0x6f, 0x63, 0x6a, - 0x67, 0x6b, 0x60, 0x6e, 0x64, 0x61, 0x6a, 0x67, - 0x61, 0x66, 0x6d, 0x60, 0x6b, 0x68, 0x66, 0x6d, - 0xac, 0xaa, 0xa1, 0xaf, 0xaa, 0xa4, 0xaf, 0xa2, - 0xa9, 0xa7, 0xa2, 0xac, 0xa6, 0xa9, 0xa8, 0xa5, - 0xa0, 0xa6, 0xad, 0xa1, 0xa3, 0xad, 0xa4, 0xae, - 0xae, 0xa0, 0xa7, 0xab, 0xa5, 0xa3, 0xab, 0xa8, - 0xa9, 0xa4, 0xae, 0xa3, 0xaf, 0xa2, 0xa5, 0xac, - 0xa2, 0xa9, 0xa8, 0xa5, 0xac, 0xaf, 0xa3, 0xaa, - 0xa7, 0xab, 0xa0, 0xae, 0xa4, 0xa1, 0xaa, 0xa7, - 0xa1, 0xa6, 0xad, 0xa0, 0xab, 0xa8, 0xa6, 0xad, - 0x3c, 0x3a, 0x31, 0x3f, 0x3a, 0x34, 0x3f, 0x32, - 0x39, 0x37, 0x32, 0x3c, 0x36, 0x39, 0x38, 0x35, - 0x30, 0x36, 0x3d, 0x31, 0x33, 0x3d, 0x34, 0x3e, - 0x3e, 0x30, 0x37, 0x3b, 0x35, 0x33, 0x3b, 0x38, - 0x39, 0x34, 0x3e, 0x33, 0x3f, 0x32, 0x35, 0x3c, - 0x32, 0x39, 0x38, 0x35, 0x3c, 0x3f, 0x33, 0x3a, - 0x37, 0x3b, 0x30, 0x3e, 0x34, 0x31, 0x3a, 0x37, - 0x31, 0x36, 0x3d, 0x30, 0x3b, 0x38, 0x36, 0x3d, - 0x4c, 0x4a, 0x41, 0x4f, 0x4a, 0x44, 0x4f, 0x42, - 0x49, 0x47, 0x42, 0x4c, 0x46, 0x49, 0x48, 0x45, - 0x40, 0x46, 0x4d, 0x41, 0x43, 0x4d, 0x44, 0x4e, - 0x4e, 0x40, 0x47, 0x4b, 0x45, 0x43, 0x4b, 0x48, - 0x49, 0x44, 0x4e, 0x43, 0x4f, 0x42, 0x45, 0x4c, - 0x42, 0x49, 0x48, 0x45, 0x4c, 0x4f, 0x43, 0x4a, - 0x47, 0x4b, 0x40, 0x4e, 0x44, 0x41, 0x4a, 0x47, - 0x41, 0x46, 0x4d, 0x40, 0x4b, 0x48, 0x46, 0x4d, - 0x0c, 0x0a, 0x01, 0x0f, 0x0a, 0x04, 0x0f, 0x02, - 0x09, 0x07, 0x02, 0x0c, 0x06, 0x09, 0x08, 0x05, - 0x00, 0x06, 0x0d, 0x01, 0x03, 0x0d, 0x04, 0x0e, - 0x0e, 0x00, 0x07, 0x0b, 0x05, 0x03, 0x0b, 0x08, - 0x09, 0x04, 0x0e, 0x03, 0x0f, 0x02, 0x05, 0x0c, - 0x02, 0x09, 0x08, 0x05, 0x0c, 0x0f, 0x03, 0x0a, - 0x07, 0x0b, 0x00, 0x0e, 0x04, 0x01, 0x0a, 0x07, - 0x01, 0x06, 0x0d, 0x00, 0x0b, 0x08, 0x06, 0x0d, - 0x5c, 0x5a, 0x51, 0x5f, 0x5a, 0x54, 0x5f, 0x52, - 0x59, 0x57, 0x52, 0x5c, 0x56, 0x59, 0x58, 0x55, - 0x50, 0x56, 0x5d, 0x51, 0x53, 0x5d, 0x54, 0x5e, - 0x5e, 0x50, 0x57, 0x5b, 0x55, 0x53, 0x5b, 0x58, - 0x59, 0x54, 0x5e, 0x53, 0x5f, 0x52, 0x55, 0x5c, - 0x52, 0x59, 0x58, 0x55, 0x5c, 0x5f, 0x53, 0x5a, - 0x57, 0x5b, 0x50, 0x5e, 0x54, 0x51, 0x5a, 0x57, - 0x51, 0x56, 0x5d, 0x50, 0x5b, 0x58, 0x56, 0x5d, - 0xec, 0xea, 0xe1, 0xef, 0xea, 0xe4, 0xef, 0xe2, - 0xe9, 0xe7, 0xe2, 0xec, 0xe6, 0xe9, 0xe8, 0xe5, - 0xe0, 0xe6, 0xed, 0xe1, 0xe3, 0xed, 0xe4, 0xee, - 0xee, 0xe0, 0xe7, 0xeb, 0xe5, 0xe3, 0xeb, 0xe8, - 0xe9, 0xe4, 0xee, 0xe3, 0xef, 0xe2, 0xe5, 0xec, - 0xe2, 0xe9, 0xe8, 0xe5, 0xec, 0xef, 0xe3, 0xea, - 0xe7, 0xeb, 0xe0, 0xee, 0xe4, 0xe1, 0xea, 0xe7, - 0xe1, 0xe6, 0xed, 0xe0, 0xeb, 0xe8, 0xe6, 0xed, - 0x3c, 0x3a, 0x31, 0x3f, 0x3a, 0x34, 0x3f, 0x32, - 0x39, 0x37, 0x32, 0x3c, 0x36, 0x39, 0x38, 0x35, - 0x30, 0x36, 0x3d, 0x31, 0x33, 0x3d, 0x34, 0x3e, - 0x3e, 0x30, 0x37, 0x3b, 0x35, 0x33, 0x3b, 0x38, - 0x39, 0x34, 0x3e, 0x33, 0x3f, 0x32, 0x35, 0x3c, - 0x32, 0x39, 0x38, 0x35, 0x3c, 0x3f, 0x33, 0x3a, - 0x37, 0x3b, 0x30, 0x3e, 0x34, 0x31, 0x3a, 0x37, - 0x31, 0x36, 0x3d, 0x30, 0x3b, 0x38, 0x36, 0x3d, - },{ - 0x4d, 0x41, 0x42, 0x4f, 0x48, 0x4d, 0x44, 0x48, - 0x46, 0x4a, 0x4f, 0x43, 0x4b, 0x47, 0x41, 0x44, - 0x4a, 0x4c, 0x49, 0x45, 0x43, 0x46, 0x4e, 0x4b, - 0x45, 0x40, 0x40, 0x4e, 0x4c, 0x49, 0x47, 0x42, - 0x47, 0x42, 0x4b, 0x41, 0x44, 0x4e, 0x41, 0x47, - 0x49, 0x44, 0x4c, 0x4a, 0x4e, 0x48, 0x42, 0x4d, - 0x40, 0x4f, 0x46, 0x4c, 0x4a, 0x49, 0x4d, 0x40, - 0x4f, 0x43, 0x43, 0x45, 0x45, 0x46, 0x48, 0x4b, - 0xdd, 0xd1, 0xd2, 0xdf, 0xd8, 0xdd, 0xd4, 0xd8, - 0xd6, 0xda, 0xdf, 0xd3, 0xdb, 0xd7, 0xd1, 0xd4, - 0xda, 0xdc, 0xd9, 0xd5, 0xd3, 0xd6, 0xde, 0xdb, - 0xd5, 0xd0, 0xd0, 0xde, 0xdc, 0xd9, 0xd7, 0xd2, - 0xd7, 0xd2, 0xdb, 0xd1, 0xd4, 0xde, 0xd1, 0xd7, - 0xd9, 0xd4, 0xdc, 0xda, 0xde, 0xd8, 0xd2, 0xdd, - 0xd0, 0xdf, 0xd6, 0xdc, 0xda, 0xd9, 0xdd, 0xd0, - 0xdf, 0xd3, 0xd3, 0xd5, 0xd5, 0xd6, 0xd8, 0xdb, - 0xbd, 0xb1, 0xb2, 0xbf, 0xb8, 0xbd, 0xb4, 0xb8, - 0xb6, 0xba, 0xbf, 0xb3, 0xbb, 0xb7, 0xb1, 0xb4, - 0xba, 0xbc, 0xb9, 0xb5, 0xb3, 0xb6, 0xbe, 0xbb, - 0xb5, 0xb0, 0xb0, 0xbe, 0xbc, 0xb9, 0xb7, 0xb2, - 0xb7, 0xb2, 0xbb, 0xb1, 0xb4, 0xbe, 0xb1, 0xb7, - 0xb9, 0xb4, 0xbc, 0xba, 0xbe, 0xb8, 0xb2, 0xbd, - 0xb0, 0xbf, 0xb6, 0xbc, 0xba, 0xb9, 0xbd, 0xb0, - 0xbf, 0xb3, 0xb3, 0xb5, 0xb5, 0xb6, 0xb8, 0xbb, - 0x0d, 0x01, 0x02, 0x0f, 0x08, 0x0d, 0x04, 0x08, - 0x06, 0x0a, 0x0f, 0x03, 0x0b, 0x07, 0x01, 0x04, - 0x0a, 0x0c, 0x09, 0x05, 0x03, 0x06, 0x0e, 0x0b, - 0x05, 0x00, 0x00, 0x0e, 0x0c, 0x09, 0x07, 0x02, - 0x07, 0x02, 0x0b, 0x01, 0x04, 0x0e, 0x01, 0x07, - 0x09, 0x04, 0x0c, 0x0a, 0x0e, 0x08, 0x02, 0x0d, - 0x00, 0x0f, 0x06, 0x0c, 0x0a, 0x09, 0x0d, 0x00, - 0x0f, 0x03, 0x03, 0x05, 0x05, 0x06, 0x08, 0x0b, - 0x2d, 0x21, 0x22, 0x2f, 0x28, 0x2d, 0x24, 0x28, - 0x26, 0x2a, 0x2f, 0x23, 0x2b, 0x27, 0x21, 0x24, - 0x2a, 0x2c, 0x29, 0x25, 0x23, 0x26, 0x2e, 0x2b, - 0x25, 0x20, 0x20, 0x2e, 0x2c, 0x29, 0x27, 0x22, - 0x27, 0x22, 0x2b, 0x21, 0x24, 0x2e, 0x21, 0x27, - 0x29, 0x24, 0x2c, 0x2a, 0x2e, 0x28, 0x22, 0x2d, - 0x20, 0x2f, 0x26, 0x2c, 0x2a, 0x29, 0x2d, 0x20, - 0x2f, 0x23, 0x23, 0x25, 0x25, 0x26, 0x28, 0x2b, - 0xbd, 0xb1, 0xb2, 0xbf, 0xb8, 0xbd, 0xb4, 0xb8, - 0xb6, 0xba, 0xbf, 0xb3, 0xbb, 0xb7, 0xb1, 0xb4, - 0xba, 0xbc, 0xb9, 0xb5, 0xb3, 0xb6, 0xbe, 0xbb, - 0xb5, 0xb0, 0xb0, 0xbe, 0xbc, 0xb9, 0xb7, 0xb2, - 0xb7, 0xb2, 0xbb, 0xb1, 0xb4, 0xbe, 0xb1, 0xb7, - 0xb9, 0xb4, 0xbc, 0xba, 0xbe, 0xb8, 0xb2, 0xbd, - 0xb0, 0xbf, 0xb6, 0xbc, 0xba, 0xb9, 0xbd, 0xb0, - 0xbf, 0xb3, 0xb3, 0xb5, 0xb5, 0xb6, 0xb8, 0xbb, - 0xed, 0xe1, 0xe2, 0xef, 0xe8, 0xed, 0xe4, 0xe8, - 0xe6, 0xea, 0xef, 0xe3, 0xeb, 0xe7, 0xe1, 0xe4, - 0xea, 0xec, 0xe9, 0xe5, 0xe3, 0xe6, 0xee, 0xeb, - 0xe5, 0xe0, 0xe0, 0xee, 0xec, 0xe9, 0xe7, 0xe2, - 0xe7, 0xe2, 0xeb, 0xe1, 0xe4, 0xee, 0xe1, 0xe7, - 0xe9, 0xe4, 0xec, 0xea, 0xee, 0xe8, 0xe2, 0xed, - 0xe0, 0xef, 0xe6, 0xec, 0xea, 0xe9, 0xed, 0xe0, - 0xef, 0xe3, 0xe3, 0xe5, 0xe5, 0xe6, 0xe8, 0xeb, - 0x7d, 0x71, 0x72, 0x7f, 0x78, 0x7d, 0x74, 0x78, - 0x76, 0x7a, 0x7f, 0x73, 0x7b, 0x77, 0x71, 0x74, - 0x7a, 0x7c, 0x79, 0x75, 0x73, 0x76, 0x7e, 0x7b, - 0x75, 0x70, 0x70, 0x7e, 0x7c, 0x79, 0x77, 0x72, - 0x77, 0x72, 0x7b, 0x71, 0x74, 0x7e, 0x71, 0x77, - 0x79, 0x74, 0x7c, 0x7a, 0x7e, 0x78, 0x72, 0x7d, - 0x70, 0x7f, 0x76, 0x7c, 0x7a, 0x79, 0x7d, 0x70, - 0x7f, 0x73, 0x73, 0x75, 0x75, 0x76, 0x78, 0x7b, - 0xfd, 0xf1, 0xf2, 0xff, 0xf8, 0xfd, 0xf4, 0xf8, - 0xf6, 0xfa, 0xff, 0xf3, 0xfb, 0xf7, 0xf1, 0xf4, - 0xfa, 0xfc, 0xf9, 0xf5, 0xf3, 0xf6, 0xfe, 0xfb, - 0xf5, 0xf0, 0xf0, 0xfe, 0xfc, 0xf9, 0xf7, 0xf2, - 0xf7, 0xf2, 0xfb, 0xf1, 0xf4, 0xfe, 0xf1, 0xf7, - 0xf9, 0xf4, 0xfc, 0xfa, 0xfe, 0xf8, 0xf2, 0xfd, - 0xf0, 0xff, 0xf6, 0xfc, 0xfa, 0xf9, 0xfd, 0xf0, - 0xff, 0xf3, 0xf3, 0xf5, 0xf5, 0xf6, 0xf8, 0xfb, - 0x4d, 0x41, 0x42, 0x4f, 0x48, 0x4d, 0x44, 0x48, - 0x46, 0x4a, 0x4f, 0x43, 0x4b, 0x47, 0x41, 0x44, - 0x4a, 0x4c, 0x49, 0x45, 0x43, 0x46, 0x4e, 0x4b, - 0x45, 0x40, 0x40, 0x4e, 0x4c, 0x49, 0x47, 0x42, - 0x47, 0x42, 0x4b, 0x41, 0x44, 0x4e, 0x41, 0x47, - 0x49, 0x44, 0x4c, 0x4a, 0x4e, 0x48, 0x42, 0x4d, - 0x40, 0x4f, 0x46, 0x4c, 0x4a, 0x49, 0x4d, 0x40, - 0x4f, 0x43, 0x43, 0x45, 0x45, 0x46, 0x48, 0x4b, - 0x0d, 0x01, 0x02, 0x0f, 0x08, 0x0d, 0x04, 0x08, - 0x06, 0x0a, 0x0f, 0x03, 0x0b, 0x07, 0x01, 0x04, - 0x0a, 0x0c, 0x09, 0x05, 0x03, 0x06, 0x0e, 0x0b, - 0x05, 0x00, 0x00, 0x0e, 0x0c, 0x09, 0x07, 0x02, - 0x07, 0x02, 0x0b, 0x01, 0x04, 0x0e, 0x01, 0x07, - 0x09, 0x04, 0x0c, 0x0a, 0x0e, 0x08, 0x02, 0x0d, - 0x00, 0x0f, 0x06, 0x0c, 0x0a, 0x09, 0x0d, 0x00, - 0x0f, 0x03, 0x03, 0x05, 0x05, 0x06, 0x08, 0x0b, - 0x9d, 0x91, 0x92, 0x9f, 0x98, 0x9d, 0x94, 0x98, - 0x96, 0x9a, 0x9f, 0x93, 0x9b, 0x97, 0x91, 0x94, - 0x9a, 0x9c, 0x99, 0x95, 0x93, 0x96, 0x9e, 0x9b, - 0x95, 0x90, 0x90, 0x9e, 0x9c, 0x99, 0x97, 0x92, - 0x97, 0x92, 0x9b, 0x91, 0x94, 0x9e, 0x91, 0x97, - 0x99, 0x94, 0x9c, 0x9a, 0x9e, 0x98, 0x92, 0x9d, - 0x90, 0x9f, 0x96, 0x9c, 0x9a, 0x99, 0x9d, 0x90, - 0x9f, 0x93, 0x93, 0x95, 0x95, 0x96, 0x98, 0x9b, - 0x8d, 0x81, 0x82, 0x8f, 0x88, 0x8d, 0x84, 0x88, - 0x86, 0x8a, 0x8f, 0x83, 0x8b, 0x87, 0x81, 0x84, - 0x8a, 0x8c, 0x89, 0x85, 0x83, 0x86, 0x8e, 0x8b, - 0x85, 0x80, 0x80, 0x8e, 0x8c, 0x89, 0x87, 0x82, - 0x87, 0x82, 0x8b, 0x81, 0x84, 0x8e, 0x81, 0x87, - 0x89, 0x84, 0x8c, 0x8a, 0x8e, 0x88, 0x82, 0x8d, - 0x80, 0x8f, 0x86, 0x8c, 0x8a, 0x89, 0x8d, 0x80, - 0x8f, 0x83, 0x83, 0x85, 0x85, 0x86, 0x88, 0x8b, - 0x1d, 0x11, 0x12, 0x1f, 0x18, 0x1d, 0x14, 0x18, - 0x16, 0x1a, 0x1f, 0x13, 0x1b, 0x17, 0x11, 0x14, - 0x1a, 0x1c, 0x19, 0x15, 0x13, 0x16, 0x1e, 0x1b, - 0x15, 0x10, 0x10, 0x1e, 0x1c, 0x19, 0x17, 0x12, - 0x17, 0x12, 0x1b, 0x11, 0x14, 0x1e, 0x11, 0x17, - 0x19, 0x14, 0x1c, 0x1a, 0x1e, 0x18, 0x12, 0x1d, - 0x10, 0x1f, 0x16, 0x1c, 0x1a, 0x19, 0x1d, 0x10, - 0x1f, 0x13, 0x13, 0x15, 0x15, 0x16, 0x18, 0x1b, - 0xdd, 0xd1, 0xd2, 0xdf, 0xd8, 0xdd, 0xd4, 0xd8, - 0xd6, 0xda, 0xdf, 0xd3, 0xdb, 0xd7, 0xd1, 0xd4, - 0xda, 0xdc, 0xd9, 0xd5, 0xd3, 0xd6, 0xde, 0xdb, - 0xd5, 0xd0, 0xd0, 0xde, 0xdc, 0xd9, 0xd7, 0xd2, - 0xd7, 0xd2, 0xdb, 0xd1, 0xd4, 0xde, 0xd1, 0xd7, - 0xd9, 0xd4, 0xdc, 0xda, 0xde, 0xd8, 0xd2, 0xdd, - 0xd0, 0xdf, 0xd6, 0xdc, 0xda, 0xd9, 0xdd, 0xd0, - 0xdf, 0xd3, 0xd3, 0xd5, 0xd5, 0xd6, 0xd8, 0xdb, - 0xad, 0xa1, 0xa2, 0xaf, 0xa8, 0xad, 0xa4, 0xa8, - 0xa6, 0xaa, 0xaf, 0xa3, 0xab, 0xa7, 0xa1, 0xa4, - 0xaa, 0xac, 0xa9, 0xa5, 0xa3, 0xa6, 0xae, 0xab, - 0xa5, 0xa0, 0xa0, 0xae, 0xac, 0xa9, 0xa7, 0xa2, - 0xa7, 0xa2, 0xab, 0xa1, 0xa4, 0xae, 0xa1, 0xa7, - 0xa9, 0xa4, 0xac, 0xaa, 0xae, 0xa8, 0xa2, 0xad, - 0xa0, 0xaf, 0xa6, 0xac, 0xaa, 0xa9, 0xad, 0xa0, - 0xaf, 0xa3, 0xa3, 0xa5, 0xa5, 0xa6, 0xa8, 0xab, - 0x3d, 0x31, 0x32, 0x3f, 0x38, 0x3d, 0x34, 0x38, - 0x36, 0x3a, 0x3f, 0x33, 0x3b, 0x37, 0x31, 0x34, - 0x3a, 0x3c, 0x39, 0x35, 0x33, 0x36, 0x3e, 0x3b, - 0x35, 0x30, 0x30, 0x3e, 0x3c, 0x39, 0x37, 0x32, - 0x37, 0x32, 0x3b, 0x31, 0x34, 0x3e, 0x31, 0x37, - 0x39, 0x34, 0x3c, 0x3a, 0x3e, 0x38, 0x32, 0x3d, - 0x30, 0x3f, 0x36, 0x3c, 0x3a, 0x39, 0x3d, 0x30, - 0x3f, 0x33, 0x33, 0x35, 0x35, 0x36, 0x38, 0x3b, - 0xed, 0xe1, 0xe2, 0xef, 0xe8, 0xed, 0xe4, 0xe8, - 0xe6, 0xea, 0xef, 0xe3, 0xeb, 0xe7, 0xe1, 0xe4, - 0xea, 0xec, 0xe9, 0xe5, 0xe3, 0xe6, 0xee, 0xeb, - 0xe5, 0xe0, 0xe0, 0xee, 0xec, 0xe9, 0xe7, 0xe2, - 0xe7, 0xe2, 0xeb, 0xe1, 0xe4, 0xee, 0xe1, 0xe7, - 0xe9, 0xe4, 0xec, 0xea, 0xee, 0xe8, 0xe2, 0xed, - 0xe0, 0xef, 0xe6, 0xec, 0xea, 0xe9, 0xed, 0xe0, - 0xef, 0xe3, 0xe3, 0xe5, 0xe5, 0xe6, 0xe8, 0xeb, - 0xcd, 0xc1, 0xc2, 0xcf, 0xc8, 0xcd, 0xc4, 0xc8, - 0xc6, 0xca, 0xcf, 0xc3, 0xcb, 0xc7, 0xc1, 0xc4, - 0xca, 0xcc, 0xc9, 0xc5, 0xc3, 0xc6, 0xce, 0xcb, - 0xc5, 0xc0, 0xc0, 0xce, 0xcc, 0xc9, 0xc7, 0xc2, - 0xc7, 0xc2, 0xcb, 0xc1, 0xc4, 0xce, 0xc1, 0xc7, - 0xc9, 0xc4, 0xcc, 0xca, 0xce, 0xc8, 0xc2, 0xcd, - 0xc0, 0xcf, 0xc6, 0xcc, 0xca, 0xc9, 0xcd, 0xc0, - 0xcf, 0xc3, 0xc3, 0xc5, 0xc5, 0xc6, 0xc8, 0xcb, - 0x3d, 0x31, 0x32, 0x3f, 0x38, 0x3d, 0x34, 0x38, - 0x36, 0x3a, 0x3f, 0x33, 0x3b, 0x37, 0x31, 0x34, - 0x3a, 0x3c, 0x39, 0x35, 0x33, 0x36, 0x3e, 0x3b, - 0x35, 0x30, 0x30, 0x3e, 0x3c, 0x39, 0x37, 0x32, - 0x37, 0x32, 0x3b, 0x31, 0x34, 0x3e, 0x31, 0x37, - 0x39, 0x34, 0x3c, 0x3a, 0x3e, 0x38, 0x32, 0x3d, - 0x30, 0x3f, 0x36, 0x3c, 0x3a, 0x39, 0x3d, 0x30, - 0x3f, 0x33, 0x33, 0x35, 0x35, 0x36, 0x38, 0x3b, - 0x9d, 0x91, 0x92, 0x9f, 0x98, 0x9d, 0x94, 0x98, - 0x96, 0x9a, 0x9f, 0x93, 0x9b, 0x97, 0x91, 0x94, - 0x9a, 0x9c, 0x99, 0x95, 0x93, 0x96, 0x9e, 0x9b, - 0x95, 0x90, 0x90, 0x9e, 0x9c, 0x99, 0x97, 0x92, - 0x97, 0x92, 0x9b, 0x91, 0x94, 0x9e, 0x91, 0x97, - 0x99, 0x94, 0x9c, 0x9a, 0x9e, 0x98, 0x92, 0x9d, - 0x90, 0x9f, 0x96, 0x9c, 0x9a, 0x99, 0x9d, 0x90, - 0x9f, 0x93, 0x93, 0x95, 0x95, 0x96, 0x98, 0x9b, - 0x5d, 0x51, 0x52, 0x5f, 0x58, 0x5d, 0x54, 0x58, - 0x56, 0x5a, 0x5f, 0x53, 0x5b, 0x57, 0x51, 0x54, - 0x5a, 0x5c, 0x59, 0x55, 0x53, 0x56, 0x5e, 0x5b, - 0x55, 0x50, 0x50, 0x5e, 0x5c, 0x59, 0x57, 0x52, - 0x57, 0x52, 0x5b, 0x51, 0x54, 0x5e, 0x51, 0x57, - 0x59, 0x54, 0x5c, 0x5a, 0x5e, 0x58, 0x52, 0x5d, - 0x50, 0x5f, 0x56, 0x5c, 0x5a, 0x59, 0x5d, 0x50, - 0x5f, 0x53, 0x53, 0x55, 0x55, 0x56, 0x58, 0x5b, - 0x7d, 0x71, 0x72, 0x7f, 0x78, 0x7d, 0x74, 0x78, - 0x76, 0x7a, 0x7f, 0x73, 0x7b, 0x77, 0x71, 0x74, - 0x7a, 0x7c, 0x79, 0x75, 0x73, 0x76, 0x7e, 0x7b, - 0x75, 0x70, 0x70, 0x7e, 0x7c, 0x79, 0x77, 0x72, - 0x77, 0x72, 0x7b, 0x71, 0x74, 0x7e, 0x71, 0x77, - 0x79, 0x74, 0x7c, 0x7a, 0x7e, 0x78, 0x72, 0x7d, - 0x70, 0x7f, 0x76, 0x7c, 0x7a, 0x79, 0x7d, 0x70, - 0x7f, 0x73, 0x73, 0x75, 0x75, 0x76, 0x78, 0x7b, - 0xcd, 0xc1, 0xc2, 0xcf, 0xc8, 0xcd, 0xc4, 0xc8, - 0xc6, 0xca, 0xcf, 0xc3, 0xcb, 0xc7, 0xc1, 0xc4, - 0xca, 0xcc, 0xc9, 0xc5, 0xc3, 0xc6, 0xce, 0xcb, - 0xc5, 0xc0, 0xc0, 0xce, 0xcc, 0xc9, 0xc7, 0xc2, - 0xc7, 0xc2, 0xcb, 0xc1, 0xc4, 0xce, 0xc1, 0xc7, - 0xc9, 0xc4, 0xcc, 0xca, 0xce, 0xc8, 0xc2, 0xcd, - 0xc0, 0xcf, 0xc6, 0xcc, 0xca, 0xc9, 0xcd, 0xc0, - 0xcf, 0xc3, 0xc3, 0xc5, 0xc5, 0xc6, 0xc8, 0xcb, - 0x5d, 0x51, 0x52, 0x5f, 0x58, 0x5d, 0x54, 0x58, - 0x56, 0x5a, 0x5f, 0x53, 0x5b, 0x57, 0x51, 0x54, - 0x5a, 0x5c, 0x59, 0x55, 0x53, 0x56, 0x5e, 0x5b, - 0x55, 0x50, 0x50, 0x5e, 0x5c, 0x59, 0x57, 0x52, - 0x57, 0x52, 0x5b, 0x51, 0x54, 0x5e, 0x51, 0x57, - 0x59, 0x54, 0x5c, 0x5a, 0x5e, 0x58, 0x52, 0x5d, - 0x50, 0x5f, 0x56, 0x5c, 0x5a, 0x59, 0x5d, 0x50, - 0x5f, 0x53, 0x53, 0x55, 0x55, 0x56, 0x58, 0x5b, - 0x2d, 0x21, 0x22, 0x2f, 0x28, 0x2d, 0x24, 0x28, - 0x26, 0x2a, 0x2f, 0x23, 0x2b, 0x27, 0x21, 0x24, - 0x2a, 0x2c, 0x29, 0x25, 0x23, 0x26, 0x2e, 0x2b, - 0x25, 0x20, 0x20, 0x2e, 0x2c, 0x29, 0x27, 0x22, - 0x27, 0x22, 0x2b, 0x21, 0x24, 0x2e, 0x21, 0x27, - 0x29, 0x24, 0x2c, 0x2a, 0x2e, 0x28, 0x22, 0x2d, - 0x20, 0x2f, 0x26, 0x2c, 0x2a, 0x29, 0x2d, 0x20, - 0x2f, 0x23, 0x23, 0x25, 0x25, 0x26, 0x28, 0x2b, - 0xad, 0xa1, 0xa2, 0xaf, 0xa8, 0xad, 0xa4, 0xa8, - 0xa6, 0xaa, 0xaf, 0xa3, 0xab, 0xa7, 0xa1, 0xa4, - 0xaa, 0xac, 0xa9, 0xa5, 0xa3, 0xa6, 0xae, 0xab, - 0xa5, 0xa0, 0xa0, 0xae, 0xac, 0xa9, 0xa7, 0xa2, - 0xa7, 0xa2, 0xab, 0xa1, 0xa4, 0xae, 0xa1, 0xa7, - 0xa9, 0xa4, 0xac, 0xaa, 0xae, 0xa8, 0xa2, 0xad, - 0xa0, 0xaf, 0xa6, 0xac, 0xaa, 0xa9, 0xad, 0xa0, - 0xaf, 0xa3, 0xa3, 0xa5, 0xa5, 0xa6, 0xa8, 0xab, - 0xfd, 0xf1, 0xf2, 0xff, 0xf8, 0xfd, 0xf4, 0xf8, - 0xf6, 0xfa, 0xff, 0xf3, 0xfb, 0xf7, 0xf1, 0xf4, - 0xfa, 0xfc, 0xf9, 0xf5, 0xf3, 0xf6, 0xfe, 0xfb, - 0xf5, 0xf0, 0xf0, 0xfe, 0xfc, 0xf9, 0xf7, 0xf2, - 0xf7, 0xf2, 0xfb, 0xf1, 0xf4, 0xfe, 0xf1, 0xf7, - 0xf9, 0xf4, 0xfc, 0xfa, 0xfe, 0xf8, 0xf2, 0xfd, - 0xf0, 0xff, 0xf6, 0xfc, 0xfa, 0xf9, 0xfd, 0xf0, - 0xff, 0xf3, 0xf3, 0xf5, 0xf5, 0xf6, 0xf8, 0xfb, - 0x6d, 0x61, 0x62, 0x6f, 0x68, 0x6d, 0x64, 0x68, - 0x66, 0x6a, 0x6f, 0x63, 0x6b, 0x67, 0x61, 0x64, - 0x6a, 0x6c, 0x69, 0x65, 0x63, 0x66, 0x6e, 0x6b, - 0x65, 0x60, 0x60, 0x6e, 0x6c, 0x69, 0x67, 0x62, - 0x67, 0x62, 0x6b, 0x61, 0x64, 0x6e, 0x61, 0x67, - 0x69, 0x64, 0x6c, 0x6a, 0x6e, 0x68, 0x62, 0x6d, - 0x60, 0x6f, 0x66, 0x6c, 0x6a, 0x69, 0x6d, 0x60, - 0x6f, 0x63, 0x63, 0x65, 0x65, 0x66, 0x68, 0x6b, - 0x8d, 0x81, 0x82, 0x8f, 0x88, 0x8d, 0x84, 0x88, - 0x86, 0x8a, 0x8f, 0x83, 0x8b, 0x87, 0x81, 0x84, - 0x8a, 0x8c, 0x89, 0x85, 0x83, 0x86, 0x8e, 0x8b, - 0x85, 0x80, 0x80, 0x8e, 0x8c, 0x89, 0x87, 0x82, - 0x87, 0x82, 0x8b, 0x81, 0x84, 0x8e, 0x81, 0x87, - 0x89, 0x84, 0x8c, 0x8a, 0x8e, 0x88, 0x82, 0x8d, - 0x80, 0x8f, 0x86, 0x8c, 0x8a, 0x89, 0x8d, 0x80, - 0x8f, 0x83, 0x83, 0x85, 0x85, 0x86, 0x88, 0x8b, - 0x1d, 0x11, 0x12, 0x1f, 0x18, 0x1d, 0x14, 0x18, - 0x16, 0x1a, 0x1f, 0x13, 0x1b, 0x17, 0x11, 0x14, - 0x1a, 0x1c, 0x19, 0x15, 0x13, 0x16, 0x1e, 0x1b, - 0x15, 0x10, 0x10, 0x1e, 0x1c, 0x19, 0x17, 0x12, - 0x17, 0x12, 0x1b, 0x11, 0x14, 0x1e, 0x11, 0x17, - 0x19, 0x14, 0x1c, 0x1a, 0x1e, 0x18, 0x12, 0x1d, - 0x10, 0x1f, 0x16, 0x1c, 0x1a, 0x19, 0x1d, 0x10, - 0x1f, 0x13, 0x13, 0x15, 0x15, 0x16, 0x18, 0x1b, - 0x6d, 0x61, 0x62, 0x6f, 0x68, 0x6d, 0x64, 0x68, - 0x66, 0x6a, 0x6f, 0x63, 0x6b, 0x67, 0x61, 0x64, - 0x6a, 0x6c, 0x69, 0x65, 0x63, 0x66, 0x6e, 0x6b, - 0x65, 0x60, 0x60, 0x6e, 0x6c, 0x69, 0x67, 0x62, - 0x67, 0x62, 0x6b, 0x61, 0x64, 0x6e, 0x61, 0x67, - 0x69, 0x64, 0x6c, 0x6a, 0x6e, 0x68, 0x62, 0x6d, - 0x60, 0x6f, 0x66, 0x6c, 0x6a, 0x69, 0x6d, 0x60, - 0x6f, 0x63, 0x63, 0x65, 0x65, 0x66, 0x68, 0x6b, - 0x1d, 0x11, 0x12, 0x1f, 0x18, 0x1d, 0x14, 0x18, - 0x16, 0x1a, 0x1f, 0x13, 0x1b, 0x17, 0x11, 0x14, - 0x1a, 0x1c, 0x19, 0x15, 0x13, 0x16, 0x1e, 0x1b, - 0x15, 0x10, 0x10, 0x1e, 0x1c, 0x19, 0x17, 0x12, - 0x17, 0x12, 0x1b, 0x11, 0x14, 0x1e, 0x11, 0x17, - 0x19, 0x14, 0x1c, 0x1a, 0x1e, 0x18, 0x12, 0x1d, - 0x10, 0x1f, 0x16, 0x1c, 0x1a, 0x19, 0x1d, 0x10, - 0x1f, 0x13, 0x13, 0x15, 0x15, 0x16, 0x18, 0x1b, - 0x6d, 0x61, 0x62, 0x6f, 0x68, 0x6d, 0x64, 0x68, - 0x66, 0x6a, 0x6f, 0x63, 0x6b, 0x67, 0x61, 0x64, - 0x6a, 0x6c, 0x69, 0x65, 0x63, 0x66, 0x6e, 0x6b, - 0x65, 0x60, 0x60, 0x6e, 0x6c, 0x69, 0x67, 0x62, - 0x67, 0x62, 0x6b, 0x61, 0x64, 0x6e, 0x61, 0x67, - 0x69, 0x64, 0x6c, 0x6a, 0x6e, 0x68, 0x62, 0x6d, - 0x60, 0x6f, 0x66, 0x6c, 0x6a, 0x69, 0x6d, 0x60, - 0x6f, 0x63, 0x63, 0x65, 0x65, 0x66, 0x68, 0x6b, - 0x4d, 0x41, 0x42, 0x4f, 0x48, 0x4d, 0x44, 0x48, - 0x46, 0x4a, 0x4f, 0x43, 0x4b, 0x47, 0x41, 0x44, - 0x4a, 0x4c, 0x49, 0x45, 0x43, 0x46, 0x4e, 0x4b, - 0x45, 0x40, 0x40, 0x4e, 0x4c, 0x49, 0x47, 0x42, - 0x47, 0x42, 0x4b, 0x41, 0x44, 0x4e, 0x41, 0x47, - 0x49, 0x44, 0x4c, 0x4a, 0x4e, 0x48, 0x42, 0x4d, - 0x40, 0x4f, 0x46, 0x4c, 0x4a, 0x49, 0x4d, 0x40, - 0x4f, 0x43, 0x43, 0x45, 0x45, 0x46, 0x48, 0x4b, - 0xbd, 0xb1, 0xb2, 0xbf, 0xb8, 0xbd, 0xb4, 0xb8, - 0xb6, 0xba, 0xbf, 0xb3, 0xbb, 0xb7, 0xb1, 0xb4, - 0xba, 0xbc, 0xb9, 0xb5, 0xb3, 0xb6, 0xbe, 0xbb, - 0xb5, 0xb0, 0xb0, 0xbe, 0xbc, 0xb9, 0xb7, 0xb2, - 0xb7, 0xb2, 0xbb, 0xb1, 0xb4, 0xbe, 0xb1, 0xb7, - 0xb9, 0xb4, 0xbc, 0xba, 0xbe, 0xb8, 0xb2, 0xbd, - 0xb0, 0xbf, 0xb6, 0xbc, 0xba, 0xb9, 0xbd, 0xb0, - 0xbf, 0xb3, 0xb3, 0xb5, 0xb5, 0xb6, 0xb8, 0xbb, - 0xbd, 0xb1, 0xb2, 0xbf, 0xb8, 0xbd, 0xb4, 0xb8, - 0xb6, 0xba, 0xbf, 0xb3, 0xbb, 0xb7, 0xb1, 0xb4, - 0xba, 0xbc, 0xb9, 0xb5, 0xb3, 0xb6, 0xbe, 0xbb, - 0xb5, 0xb0, 0xb0, 0xbe, 0xbc, 0xb9, 0xb7, 0xb2, - 0xb7, 0xb2, 0xbb, 0xb1, 0xb4, 0xbe, 0xb1, 0xb7, - 0xb9, 0xb4, 0xbc, 0xba, 0xbe, 0xb8, 0xb2, 0xbd, - 0xb0, 0xbf, 0xb6, 0xbc, 0xba, 0xb9, 0xbd, 0xb0, - 0xbf, 0xb3, 0xb3, 0xb5, 0xb5, 0xb6, 0xb8, 0xbb, - 0xdd, 0xd1, 0xd2, 0xdf, 0xd8, 0xdd, 0xd4, 0xd8, - 0xd6, 0xda, 0xdf, 0xd3, 0xdb, 0xd7, 0xd1, 0xd4, - 0xda, 0xdc, 0xd9, 0xd5, 0xd3, 0xd6, 0xde, 0xdb, - 0xd5, 0xd0, 0xd0, 0xde, 0xdc, 0xd9, 0xd7, 0xd2, - 0xd7, 0xd2, 0xdb, 0xd1, 0xd4, 0xde, 0xd1, 0xd7, - 0xd9, 0xd4, 0xdc, 0xda, 0xde, 0xd8, 0xd2, 0xdd, - 0xd0, 0xdf, 0xd6, 0xdc, 0xda, 0xd9, 0xdd, 0xd0, - 0xdf, 0xd3, 0xd3, 0xd5, 0xd5, 0xd6, 0xd8, 0xdb, - 0xdd, 0xd1, 0xd2, 0xdf, 0xd8, 0xdd, 0xd4, 0xd8, - 0xd6, 0xda, 0xdf, 0xd3, 0xdb, 0xd7, 0xd1, 0xd4, - 0xda, 0xdc, 0xd9, 0xd5, 0xd3, 0xd6, 0xde, 0xdb, - 0xd5, 0xd0, 0xd0, 0xde, 0xdc, 0xd9, 0xd7, 0xd2, - 0xd7, 0xd2, 0xdb, 0xd1, 0xd4, 0xde, 0xd1, 0xd7, - 0xd9, 0xd4, 0xdc, 0xda, 0xde, 0xd8, 0xd2, 0xdd, - 0xd0, 0xdf, 0xd6, 0xdc, 0xda, 0xd9, 0xdd, 0xd0, - 0xdf, 0xd3, 0xd3, 0xd5, 0xd5, 0xd6, 0xd8, 0xdb, - 0x8d, 0x81, 0x82, 0x8f, 0x88, 0x8d, 0x84, 0x88, - 0x86, 0x8a, 0x8f, 0x83, 0x8b, 0x87, 0x81, 0x84, - 0x8a, 0x8c, 0x89, 0x85, 0x83, 0x86, 0x8e, 0x8b, - 0x85, 0x80, 0x80, 0x8e, 0x8c, 0x89, 0x87, 0x82, - 0x87, 0x82, 0x8b, 0x81, 0x84, 0x8e, 0x81, 0x87, - 0x89, 0x84, 0x8c, 0x8a, 0x8e, 0x88, 0x82, 0x8d, - 0x80, 0x8f, 0x86, 0x8c, 0x8a, 0x89, 0x8d, 0x80, - 0x8f, 0x83, 0x83, 0x85, 0x85, 0x86, 0x88, 0x8b, - 0xcd, 0xc1, 0xc2, 0xcf, 0xc8, 0xcd, 0xc4, 0xc8, - 0xc6, 0xca, 0xcf, 0xc3, 0xcb, 0xc7, 0xc1, 0xc4, - 0xca, 0xcc, 0xc9, 0xc5, 0xc3, 0xc6, 0xce, 0xcb, - 0xc5, 0xc0, 0xc0, 0xce, 0xcc, 0xc9, 0xc7, 0xc2, - 0xc7, 0xc2, 0xcb, 0xc1, 0xc4, 0xce, 0xc1, 0xc7, - 0xc9, 0xc4, 0xcc, 0xca, 0xce, 0xc8, 0xc2, 0xcd, - 0xc0, 0xcf, 0xc6, 0xcc, 0xca, 0xc9, 0xcd, 0xc0, - 0xcf, 0xc3, 0xc3, 0xc5, 0xc5, 0xc6, 0xc8, 0xcb, - 0x1d, 0x11, 0x12, 0x1f, 0x18, 0x1d, 0x14, 0x18, - 0x16, 0x1a, 0x1f, 0x13, 0x1b, 0x17, 0x11, 0x14, - 0x1a, 0x1c, 0x19, 0x15, 0x13, 0x16, 0x1e, 0x1b, - 0x15, 0x10, 0x10, 0x1e, 0x1c, 0x19, 0x17, 0x12, - 0x17, 0x12, 0x1b, 0x11, 0x14, 0x1e, 0x11, 0x17, - 0x19, 0x14, 0x1c, 0x1a, 0x1e, 0x18, 0x12, 0x1d, - 0x10, 0x1f, 0x16, 0x1c, 0x1a, 0x19, 0x1d, 0x10, - 0x1f, 0x13, 0x13, 0x15, 0x15, 0x16, 0x18, 0x1b, - 0x3d, 0x31, 0x32, 0x3f, 0x38, 0x3d, 0x34, 0x38, - 0x36, 0x3a, 0x3f, 0x33, 0x3b, 0x37, 0x31, 0x34, - 0x3a, 0x3c, 0x39, 0x35, 0x33, 0x36, 0x3e, 0x3b, - 0x35, 0x30, 0x30, 0x3e, 0x3c, 0x39, 0x37, 0x32, - 0x37, 0x32, 0x3b, 0x31, 0x34, 0x3e, 0x31, 0x37, - 0x39, 0x34, 0x3c, 0x3a, 0x3e, 0x38, 0x32, 0x3d, - 0x30, 0x3f, 0x36, 0x3c, 0x3a, 0x39, 0x3d, 0x30, - 0x3f, 0x33, 0x33, 0x35, 0x35, 0x36, 0x38, 0x3b, - 0x4d, 0x41, 0x42, 0x4f, 0x48, 0x4d, 0x44, 0x48, - 0x46, 0x4a, 0x4f, 0x43, 0x4b, 0x47, 0x41, 0x44, - 0x4a, 0x4c, 0x49, 0x45, 0x43, 0x46, 0x4e, 0x4b, - 0x45, 0x40, 0x40, 0x4e, 0x4c, 0x49, 0x47, 0x42, - 0x47, 0x42, 0x4b, 0x41, 0x44, 0x4e, 0x41, 0x47, - 0x49, 0x44, 0x4c, 0x4a, 0x4e, 0x48, 0x42, 0x4d, - 0x40, 0x4f, 0x46, 0x4c, 0x4a, 0x49, 0x4d, 0x40, - 0x4f, 0x43, 0x43, 0x45, 0x45, 0x46, 0x48, 0x4b, - 0x7d, 0x71, 0x72, 0x7f, 0x78, 0x7d, 0x74, 0x78, - 0x76, 0x7a, 0x7f, 0x73, 0x7b, 0x77, 0x71, 0x74, - 0x7a, 0x7c, 0x79, 0x75, 0x73, 0x76, 0x7e, 0x7b, - 0x75, 0x70, 0x70, 0x7e, 0x7c, 0x79, 0x77, 0x72, - 0x77, 0x72, 0x7b, 0x71, 0x74, 0x7e, 0x71, 0x77, - 0x79, 0x74, 0x7c, 0x7a, 0x7e, 0x78, 0x72, 0x7d, - 0x70, 0x7f, 0x76, 0x7c, 0x7a, 0x79, 0x7d, 0x70, - 0x7f, 0x73, 0x73, 0x75, 0x75, 0x76, 0x78, 0x7b, - 0xad, 0xa1, 0xa2, 0xaf, 0xa8, 0xad, 0xa4, 0xa8, - 0xa6, 0xaa, 0xaf, 0xa3, 0xab, 0xa7, 0xa1, 0xa4, - 0xaa, 0xac, 0xa9, 0xa5, 0xa3, 0xa6, 0xae, 0xab, - 0xa5, 0xa0, 0xa0, 0xae, 0xac, 0xa9, 0xa7, 0xa2, - 0xa7, 0xa2, 0xab, 0xa1, 0xa4, 0xae, 0xa1, 0xa7, - 0xa9, 0xa4, 0xac, 0xaa, 0xae, 0xa8, 0xa2, 0xad, - 0xa0, 0xaf, 0xa6, 0xac, 0xaa, 0xa9, 0xad, 0xa0, - 0xaf, 0xa3, 0xa3, 0xa5, 0xa5, 0xa6, 0xa8, 0xab, - 0xed, 0xe1, 0xe2, 0xef, 0xe8, 0xed, 0xe4, 0xe8, - 0xe6, 0xea, 0xef, 0xe3, 0xeb, 0xe7, 0xe1, 0xe4, - 0xea, 0xec, 0xe9, 0xe5, 0xe3, 0xe6, 0xee, 0xeb, - 0xe5, 0xe0, 0xe0, 0xee, 0xec, 0xe9, 0xe7, 0xe2, - 0xe7, 0xe2, 0xeb, 0xe1, 0xe4, 0xee, 0xe1, 0xe7, - 0xe9, 0xe4, 0xec, 0xea, 0xee, 0xe8, 0xe2, 0xed, - 0xe0, 0xef, 0xe6, 0xec, 0xea, 0xe9, 0xed, 0xe0, - 0xef, 0xe3, 0xe3, 0xe5, 0xe5, 0xe6, 0xe8, 0xeb, - 0x7d, 0x71, 0x72, 0x7f, 0x78, 0x7d, 0x74, 0x78, - 0x76, 0x7a, 0x7f, 0x73, 0x7b, 0x77, 0x71, 0x74, - 0x7a, 0x7c, 0x79, 0x75, 0x73, 0x76, 0x7e, 0x7b, - 0x75, 0x70, 0x70, 0x7e, 0x7c, 0x79, 0x77, 0x72, - 0x77, 0x72, 0x7b, 0x71, 0x74, 0x7e, 0x71, 0x77, - 0x79, 0x74, 0x7c, 0x7a, 0x7e, 0x78, 0x72, 0x7d, - 0x70, 0x7f, 0x76, 0x7c, 0x7a, 0x79, 0x7d, 0x70, - 0x7f, 0x73, 0x73, 0x75, 0x75, 0x76, 0x78, 0x7b, - 0xad, 0xa1, 0xa2, 0xaf, 0xa8, 0xad, 0xa4, 0xa8, - 0xa6, 0xaa, 0xaf, 0xa3, 0xab, 0xa7, 0xa1, 0xa4, - 0xaa, 0xac, 0xa9, 0xa5, 0xa3, 0xa6, 0xae, 0xab, - 0xa5, 0xa0, 0xa0, 0xae, 0xac, 0xa9, 0xa7, 0xa2, - 0xa7, 0xa2, 0xab, 0xa1, 0xa4, 0xae, 0xa1, 0xa7, - 0xa9, 0xa4, 0xac, 0xaa, 0xae, 0xa8, 0xa2, 0xad, - 0xa0, 0xaf, 0xa6, 0xac, 0xaa, 0xa9, 0xad, 0xa0, - 0xaf, 0xa3, 0xa3, 0xa5, 0xa5, 0xa6, 0xa8, 0xab, - 0x9d, 0x91, 0x92, 0x9f, 0x98, 0x9d, 0x94, 0x98, - 0x96, 0x9a, 0x9f, 0x93, 0x9b, 0x97, 0x91, 0x94, - 0x9a, 0x9c, 0x99, 0x95, 0x93, 0x96, 0x9e, 0x9b, - 0x95, 0x90, 0x90, 0x9e, 0x9c, 0x99, 0x97, 0x92, - 0x97, 0x92, 0x9b, 0x91, 0x94, 0x9e, 0x91, 0x97, - 0x99, 0x94, 0x9c, 0x9a, 0x9e, 0x98, 0x92, 0x9d, - 0x90, 0x9f, 0x96, 0x9c, 0x9a, 0x99, 0x9d, 0x90, - 0x9f, 0x93, 0x93, 0x95, 0x95, 0x96, 0x98, 0x9b, - 0xfd, 0xf1, 0xf2, 0xff, 0xf8, 0xfd, 0xf4, 0xf8, - 0xf6, 0xfa, 0xff, 0xf3, 0xfb, 0xf7, 0xf1, 0xf4, - 0xfa, 0xfc, 0xf9, 0xf5, 0xf3, 0xf6, 0xfe, 0xfb, - 0xf5, 0xf0, 0xf0, 0xfe, 0xfc, 0xf9, 0xf7, 0xf2, - 0xf7, 0xf2, 0xfb, 0xf1, 0xf4, 0xfe, 0xf1, 0xf7, - 0xf9, 0xf4, 0xfc, 0xfa, 0xfe, 0xf8, 0xf2, 0xfd, - 0xf0, 0xff, 0xf6, 0xfc, 0xfa, 0xf9, 0xfd, 0xf0, - 0xff, 0xf3, 0xf3, 0xf5, 0xf5, 0xf6, 0xf8, 0xfb, - 0x5d, 0x51, 0x52, 0x5f, 0x58, 0x5d, 0x54, 0x58, - 0x56, 0x5a, 0x5f, 0x53, 0x5b, 0x57, 0x51, 0x54, - 0x5a, 0x5c, 0x59, 0x55, 0x53, 0x56, 0x5e, 0x5b, - 0x55, 0x50, 0x50, 0x5e, 0x5c, 0x59, 0x57, 0x52, - 0x57, 0x52, 0x5b, 0x51, 0x54, 0x5e, 0x51, 0x57, - 0x59, 0x54, 0x5c, 0x5a, 0x5e, 0x58, 0x52, 0x5d, - 0x50, 0x5f, 0x56, 0x5c, 0x5a, 0x59, 0x5d, 0x50, - 0x5f, 0x53, 0x53, 0x55, 0x55, 0x56, 0x58, 0x5b, - 0x6d, 0x61, 0x62, 0x6f, 0x68, 0x6d, 0x64, 0x68, - 0x66, 0x6a, 0x6f, 0x63, 0x6b, 0x67, 0x61, 0x64, - 0x6a, 0x6c, 0x69, 0x65, 0x63, 0x66, 0x6e, 0x6b, - 0x65, 0x60, 0x60, 0x6e, 0x6c, 0x69, 0x67, 0x62, - 0x67, 0x62, 0x6b, 0x61, 0x64, 0x6e, 0x61, 0x67, - 0x69, 0x64, 0x6c, 0x6a, 0x6e, 0x68, 0x62, 0x6d, - 0x60, 0x6f, 0x66, 0x6c, 0x6a, 0x69, 0x6d, 0x60, - 0x6f, 0x63, 0x63, 0x65, 0x65, 0x66, 0x68, 0x6b, - 0x0d, 0x01, 0x02, 0x0f, 0x08, 0x0d, 0x04, 0x08, - 0x06, 0x0a, 0x0f, 0x03, 0x0b, 0x07, 0x01, 0x04, - 0x0a, 0x0c, 0x09, 0x05, 0x03, 0x06, 0x0e, 0x0b, - 0x05, 0x00, 0x00, 0x0e, 0x0c, 0x09, 0x07, 0x02, - 0x07, 0x02, 0x0b, 0x01, 0x04, 0x0e, 0x01, 0x07, - 0x09, 0x04, 0x0c, 0x0a, 0x0e, 0x08, 0x02, 0x0d, - 0x00, 0x0f, 0x06, 0x0c, 0x0a, 0x09, 0x0d, 0x00, - 0x0f, 0x03, 0x03, 0x05, 0x05, 0x06, 0x08, 0x0b, - 0x8d, 0x81, 0x82, 0x8f, 0x88, 0x8d, 0x84, 0x88, - 0x86, 0x8a, 0x8f, 0x83, 0x8b, 0x87, 0x81, 0x84, - 0x8a, 0x8c, 0x89, 0x85, 0x83, 0x86, 0x8e, 0x8b, - 0x85, 0x80, 0x80, 0x8e, 0x8c, 0x89, 0x87, 0x82, - 0x87, 0x82, 0x8b, 0x81, 0x84, 0x8e, 0x81, 0x87, - 0x89, 0x84, 0x8c, 0x8a, 0x8e, 0x88, 0x82, 0x8d, - 0x80, 0x8f, 0x86, 0x8c, 0x8a, 0x89, 0x8d, 0x80, - 0x8f, 0x83, 0x83, 0x85, 0x85, 0x86, 0x88, 0x8b, - 0xfd, 0xf1, 0xf2, 0xff, 0xf8, 0xfd, 0xf4, 0xf8, - 0xf6, 0xfa, 0xff, 0xf3, 0xfb, 0xf7, 0xf1, 0xf4, - 0xfa, 0xfc, 0xf9, 0xf5, 0xf3, 0xf6, 0xfe, 0xfb, - 0xf5, 0xf0, 0xf0, 0xfe, 0xfc, 0xf9, 0xf7, 0xf2, - 0xf7, 0xf2, 0xfb, 0xf1, 0xf4, 0xfe, 0xf1, 0xf7, - 0xf9, 0xf4, 0xfc, 0xfa, 0xfe, 0xf8, 0xf2, 0xfd, - 0xf0, 0xff, 0xf6, 0xfc, 0xfa, 0xf9, 0xfd, 0xf0, - 0xff, 0xf3, 0xf3, 0xf5, 0xf5, 0xf6, 0xf8, 0xfb, - 0x0d, 0x01, 0x02, 0x0f, 0x08, 0x0d, 0x04, 0x08, - 0x06, 0x0a, 0x0f, 0x03, 0x0b, 0x07, 0x01, 0x04, - 0x0a, 0x0c, 0x09, 0x05, 0x03, 0x06, 0x0e, 0x0b, - 0x05, 0x00, 0x00, 0x0e, 0x0c, 0x09, 0x07, 0x02, - 0x07, 0x02, 0x0b, 0x01, 0x04, 0x0e, 0x01, 0x07, - 0x09, 0x04, 0x0c, 0x0a, 0x0e, 0x08, 0x02, 0x0d, - 0x00, 0x0f, 0x06, 0x0c, 0x0a, 0x09, 0x0d, 0x00, - 0x0f, 0x03, 0x03, 0x05, 0x05, 0x06, 0x08, 0x0b, - 0xed, 0xe1, 0xe2, 0xef, 0xe8, 0xed, 0xe4, 0xe8, - 0xe6, 0xea, 0xef, 0xe3, 0xeb, 0xe7, 0xe1, 0xe4, - 0xea, 0xec, 0xe9, 0xe5, 0xe3, 0xe6, 0xee, 0xeb, - 0xe5, 0xe0, 0xe0, 0xee, 0xec, 0xe9, 0xe7, 0xe2, - 0xe7, 0xe2, 0xeb, 0xe1, 0xe4, 0xee, 0xe1, 0xe7, - 0xe9, 0xe4, 0xec, 0xea, 0xee, 0xe8, 0xe2, 0xed, - 0xe0, 0xef, 0xe6, 0xec, 0xea, 0xe9, 0xed, 0xe0, - 0xef, 0xe3, 0xe3, 0xe5, 0xe5, 0xe6, 0xe8, 0xeb, - 0x5d, 0x51, 0x52, 0x5f, 0x58, 0x5d, 0x54, 0x58, - 0x56, 0x5a, 0x5f, 0x53, 0x5b, 0x57, 0x51, 0x54, - 0x5a, 0x5c, 0x59, 0x55, 0x53, 0x56, 0x5e, 0x5b, - 0x55, 0x50, 0x50, 0x5e, 0x5c, 0x59, 0x57, 0x52, - 0x57, 0x52, 0x5b, 0x51, 0x54, 0x5e, 0x51, 0x57, - 0x59, 0x54, 0x5c, 0x5a, 0x5e, 0x58, 0x52, 0x5d, - 0x50, 0x5f, 0x56, 0x5c, 0x5a, 0x59, 0x5d, 0x50, - 0x5f, 0x53, 0x53, 0x55, 0x55, 0x56, 0x58, 0x5b, - 0x2d, 0x21, 0x22, 0x2f, 0x28, 0x2d, 0x24, 0x28, - 0x26, 0x2a, 0x2f, 0x23, 0x2b, 0x27, 0x21, 0x24, - 0x2a, 0x2c, 0x29, 0x25, 0x23, 0x26, 0x2e, 0x2b, - 0x25, 0x20, 0x20, 0x2e, 0x2c, 0x29, 0x27, 0x22, - 0x27, 0x22, 0x2b, 0x21, 0x24, 0x2e, 0x21, 0x27, - 0x29, 0x24, 0x2c, 0x2a, 0x2e, 0x28, 0x22, 0x2d, - 0x20, 0x2f, 0x26, 0x2c, 0x2a, 0x29, 0x2d, 0x20, - 0x2f, 0x23, 0x23, 0x25, 0x25, 0x26, 0x28, 0x2b, - 0x9d, 0x91, 0x92, 0x9f, 0x98, 0x9d, 0x94, 0x98, - 0x96, 0x9a, 0x9f, 0x93, 0x9b, 0x97, 0x91, 0x94, - 0x9a, 0x9c, 0x99, 0x95, 0x93, 0x96, 0x9e, 0x9b, - 0x95, 0x90, 0x90, 0x9e, 0x9c, 0x99, 0x97, 0x92, - 0x97, 0x92, 0x9b, 0x91, 0x94, 0x9e, 0x91, 0x97, - 0x99, 0x94, 0x9c, 0x9a, 0x9e, 0x98, 0x92, 0x9d, - 0x90, 0x9f, 0x96, 0x9c, 0x9a, 0x99, 0x9d, 0x90, - 0x9f, 0x93, 0x93, 0x95, 0x95, 0x96, 0x98, 0x9b, - 0x3d, 0x31, 0x32, 0x3f, 0x38, 0x3d, 0x34, 0x38, - 0x36, 0x3a, 0x3f, 0x33, 0x3b, 0x37, 0x31, 0x34, - 0x3a, 0x3c, 0x39, 0x35, 0x33, 0x36, 0x3e, 0x3b, - 0x35, 0x30, 0x30, 0x3e, 0x3c, 0x39, 0x37, 0x32, - 0x37, 0x32, 0x3b, 0x31, 0x34, 0x3e, 0x31, 0x37, - 0x39, 0x34, 0x3c, 0x3a, 0x3e, 0x38, 0x32, 0x3d, - 0x30, 0x3f, 0x36, 0x3c, 0x3a, 0x39, 0x3d, 0x30, - 0x3f, 0x33, 0x33, 0x35, 0x35, 0x36, 0x38, 0x3b, - 0x2d, 0x21, 0x22, 0x2f, 0x28, 0x2d, 0x24, 0x28, - 0x26, 0x2a, 0x2f, 0x23, 0x2b, 0x27, 0x21, 0x24, - 0x2a, 0x2c, 0x29, 0x25, 0x23, 0x26, 0x2e, 0x2b, - 0x25, 0x20, 0x20, 0x2e, 0x2c, 0x29, 0x27, 0x22, - 0x27, 0x22, 0x2b, 0x21, 0x24, 0x2e, 0x21, 0x27, - 0x29, 0x24, 0x2c, 0x2a, 0x2e, 0x28, 0x22, 0x2d, - 0x20, 0x2f, 0x26, 0x2c, 0x2a, 0x29, 0x2d, 0x20, - 0x2f, 0x23, 0x23, 0x25, 0x25, 0x26, 0x28, 0x2b, - 0xcd, 0xc1, 0xc2, 0xcf, 0xc8, 0xcd, 0xc4, 0xc8, - 0xc6, 0xca, 0xcf, 0xc3, 0xcb, 0xc7, 0xc1, 0xc4, - 0xca, 0xcc, 0xc9, 0xc5, 0xc3, 0xc6, 0xce, 0xcb, - 0xc5, 0xc0, 0xc0, 0xce, 0xcc, 0xc9, 0xc7, 0xc2, - 0xc7, 0xc2, 0xcb, 0xc1, 0xc4, 0xce, 0xc1, 0xc7, - 0xc9, 0xc4, 0xcc, 0xca, 0xce, 0xc8, 0xc2, 0xcd, - 0xc0, 0xcf, 0xc6, 0xcc, 0xca, 0xc9, 0xcd, 0xc0, - 0xcf, 0xc3, 0xc3, 0xc5, 0xc5, 0xc6, 0xc8, 0xcb, - }, -}; - -static const uint8_t key_perm[56] = { - 57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, - 10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36, - 63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22, - 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4 -}; - -static const uint8_t key_shifts[16] = { - 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1 -}; - -static const uint8_t comp_perm[48] = { - 14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10, - 23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2, - 41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48, - 44, 49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32 -}; - -static const uint8_t pbox[32] = { - 16, 7, 20, 21, 29, 12, 28, 17, 1, 15, 23, 26, 5, 18, 31, 10, - 2, 8, 24, 14, 32, 27, 3, 9, 19, 13, 30, 6, 22, 11, 4, 25 -}; - -static int -ascii_to_bin(char ch) -{ - if (ch > 'z') - return 0; - if (ch >= 'a') - return (ch - 'a' + 38); - if (ch > 'Z') - return 0; - if (ch >= 'A') - return (ch - 'A' + 12); - if (ch > '9') - return 0; - if (ch >= '.') - return (ch - '.'); - return 0; -} - - - -struct des_ctx { - uint32_t saltbits; /* referenced 5 times */ - uint8_t un_pbox[32]; /* 2 times */ - uint8_t inv_comp_perm[56]; /* 3 times */ - uint8_t inv_key_perm[64]; /* 3 times */ - uint32_t en_keysl[16], en_keysr[16]; /* 2 times each */ - uint32_t fp_maskl[8][256], fp_maskr[8][256]; /* 9 times each */ - uint32_t key_perm_maskl[8][128], key_perm_maskr[8][128]; /* 9 times */ - uint32_t comp_maskl[8][128], comp_maskr[8][128]; /* 9 times each */ - uint32_t psbox[4][256]; /* 5 times */ -}; -#define D (*ctx) -#define saltbits (D.saltbits ) -#define old_salt (D.old_salt ) -#define old_rawkey0 (D.old_rawkey0 ) -#define old_rawkey1 (D.old_rawkey1 ) -#define un_pbox (D.un_pbox ) -#define inv_comp_perm (D.inv_comp_perm ) -#define inv_key_perm (D.inv_key_perm ) -#define en_keysl (D.en_keysl ) -#define en_keysr (D.en_keysr ) -#define de_keysl (D.de_keysl ) -#define de_keysr (D.de_keysr ) -#define ip_maskl (D.ip_maskl ) -#define ip_maskr (D.ip_maskr ) -#define fp_maskl (D.fp_maskl ) -#define fp_maskr (D.fp_maskr ) -#define key_perm_maskl (D.key_perm_maskl ) -#define key_perm_maskr (D.key_perm_maskr ) -#define comp_maskl (D.comp_maskl ) -#define comp_maskr (D.comp_maskr ) -#define psbox (D.psbox ) - -static struct des_ctx *des_init(struct des_ctx *ctx) -{ - int i, j, b, k, inbit, obit; - uint32_t p; - - saltbits = 0; - - /* Initialise the inverted key permutation. */ - for (i = 0; i < 64; i++) { - inv_key_perm[i] = 255; - } - - /* - * Invert the key permutation and initialise the inverted key - * compression permutation. - */ - for (i = 0; i < 56; i++) { - inv_key_perm[key_perm[i] - 1] = (uint8_t)i; - inv_comp_perm[i] = 255; - } - - /* Invert the key compression permutation. */ - for (i = 0; i < 48; i++) { - inv_comp_perm[comp_perm[i] - 1] = (uint8_t)i; - } - - /* - * Set up the OR-mask arrays for the initial and final permutations, - * and for the key initial and compression permutations. - */ - for (k = 0; k < 8; k++) { - uint32_t il, ir; - uint32_t fl, fr; - for (i = 0; i < 256; i++) { - fl = 0; - fr = 0; - for (j = 0; j < 8; j++) { - inbit = 8 * k + j; - if (i & (0x80>>j)) { - obit = final_perm[inbit]; - if (obit < 32) - fl |= 0x80000000UL >> obit; - else - fr |= 0x80000000UL >> obit-32; - } - } - fp_maskl[k][i] = fl; - fp_maskr[k][i] = fr; - } - for (i = 0; i < 128; i++) { - il = 0; - ir = 0; - for (j = 0; j < 7; j++) { - inbit = 8 * k + j; - if (i & (0x80 >> j + 1)) { - obit = inv_key_perm[inbit]; - if (obit == 255) - continue; - if (obit < 28) - il |= 0x8000000UL >> obit; - else - ir |= 0x8000000UL >> obit-28; - } - } - key_perm_maskl[k][i] = il; - key_perm_maskr[k][i] = ir; - il = 0; - ir = 0; - for (j = 0; j < 7; j++) { - inbit = 7 * k + j; - if (i & (0x80 >> j + 1)) { - obit = inv_comp_perm[inbit]; - if (obit == 255) - continue; - if (obit < 24) - il |= 0x800000UL >> obit; - else - ir |= 0x800000UL >> obit-24; - } - } - comp_maskl[k][i] = il; - comp_maskr[k][i] = ir; - } - } - - /* - * Invert the P-box permutation, and convert into OR-masks for - * handling the output of the S-box arrays setup above. - */ - for (i = 0; i < 32; i++) - un_pbox[pbox[i] - 1] = (uint8_t)i; - - for (b = 0; b < 4; b++) { - for (i = 0; i < 256; i++) { - p = 0; - for (j = 0; j < 8; j++) { - if (i & (0x80 >> j)) - p |= 0x80000000>>un_pbox[8 * b + j]; - } - psbox[b][i] = p; - } - } - - return ctx; -} - - -static void setup_salt(struct des_ctx *ctx, uint32_t salt) -{ - uint32_t obit, saltbit; - int i; - - saltbits = 0; - saltbit = 1; - obit = 0x800000; - for (i = 0; i < 24; i++) { - if (salt & saltbit) - saltbits |= obit; - saltbit <<= 1; - obit >>= 1; - } -} - -static void des_setkey(struct des_ctx *ctx, const unsigned char *key) -{ - uint32_t k0, k1, rawkey0, rawkey1; - int shifts, round; - - rawkey0 = key[0]<<24 | key[1]<<16 | key[2]<<8 | key[3]; - rawkey1 = key[4]<<24 | key[5]<<16 | key[6]<<8 | key[7]; - - /* - * Do key permutation and split into two 28-bit subkeys. - */ - k0 = key_perm_maskl[0][rawkey0 >> 25] - | key_perm_maskl[1][(rawkey0 >> 17) & 0x7f] - | key_perm_maskl[2][(rawkey0 >> 9) & 0x7f] - | key_perm_maskl[3][(rawkey0 >> 1) & 0x7f] - | key_perm_maskl[4][rawkey1 >> 25] - | key_perm_maskl[5][(rawkey1 >> 17) & 0x7f] - | key_perm_maskl[6][(rawkey1 >> 9) & 0x7f] - | key_perm_maskl[7][(rawkey1 >> 1) & 0x7f]; - k1 = key_perm_maskr[0][rawkey0 >> 25] - | key_perm_maskr[1][(rawkey0 >> 17) & 0x7f] - | key_perm_maskr[2][(rawkey0 >> 9) & 0x7f] - | key_perm_maskr[3][(rawkey0 >> 1) & 0x7f] - | key_perm_maskr[4][rawkey1 >> 25] - | key_perm_maskr[5][(rawkey1 >> 17) & 0x7f] - | key_perm_maskr[6][(rawkey1 >> 9) & 0x7f] - | key_perm_maskr[7][(rawkey1 >> 1) & 0x7f]; - /* - * Rotate subkeys and do compression permutation. - */ - shifts = 0; - for (round = 0; round < 16; round++) { - uint32_t t0, t1; - - shifts += key_shifts[round]; - - t0 = (k0 << shifts) | (k0 >> (28 - shifts)); - t1 = (k1 << shifts) | (k1 >> (28 - shifts)); - - en_keysl[round] = comp_maskl[0][(t0 >> 21) & 0x7f] - | comp_maskl[1][(t0 >> 14) & 0x7f] - | comp_maskl[2][(t0 >> 7) & 0x7f] - | comp_maskl[3][t0 & 0x7f] - | comp_maskl[4][(t1 >> 21) & 0x7f] - | comp_maskl[5][(t1 >> 14) & 0x7f] - | comp_maskl[6][(t1 >> 7) & 0x7f] - | comp_maskl[7][t1 & 0x7f]; - - en_keysr[round] = comp_maskr[0][(t0 >> 21) & 0x7f] - | comp_maskr[1][(t0 >> 14) & 0x7f] - | comp_maskr[2][(t0 >> 7) & 0x7f] - | comp_maskr[3][t0 & 0x7f] - | comp_maskr[4][(t1 >> 21) & 0x7f] - | comp_maskr[5][(t1 >> 14) & 0x7f] - | comp_maskr[6][(t1 >> 7) & 0x7f] - | comp_maskr[7][t1 & 0x7f]; - } -} - - -static void do_des(struct des_ctx *ctx, uint32_t *l_out, uint32_t *r_out, int count) -{ - uint32_t l, r, *kl, *kr; - uint32_t f = f; /* silence gcc */ - uint32_t r48l, r48r; - int round; - - /* Do initial permutation (IP). */ - l = r = 0; - - do { - /* Do each round. */ - kl = en_keysl; - kr = en_keysr; - round = 16; - do { - /* Expand R to 48 bits (simulate the E-box). */ - r48l = ((r & 0x00000001) << 23) - | ((r & 0xf8000000) >> 9) - | ((r & 0x1f800000) >> 11) - | ((r & 0x01f80000) >> 13) - | ((r & 0x001f8000) >> 15); - - r48r = ((r & 0x0001f800) << 7) - | ((r & 0x00001f80) << 5) - | ((r & 0x000001f8) << 3) - | ((r & 0x0000001f) << 1) - | ((r & 0x80000000) >> 31); - /* - * Do salting for crypt() and friends, and - * XOR with the permuted key. - */ - f = (r48l ^ r48r) & saltbits; - r48l ^= f ^ *kl++; - r48r ^= f ^ *kr++; - /* - * Do sbox lookups (which shrink it back to 32 bits) - * and do the pbox permutation at the same time. - */ - f = psbox[0][m_sbox[0][r48l >> 12]] - | psbox[1][m_sbox[1][r48l & 0xfff]] - | psbox[2][m_sbox[2][r48r >> 12]] - | psbox[3][m_sbox[3][r48r & 0xfff]]; - /* Now that we've permuted things, complete f(). */ - f ^= l; - l = r; - r = f; - } while (--round); - r = l; - l = f; - } while (--count); - - /* Do final permutation (inverse of IP). */ - *l_out = fp_maskl[0][l >> 24] - | fp_maskl[1][(l >> 16) & 0xff] - | fp_maskl[2][(l >> 8) & 0xff] - | fp_maskl[3][l & 0xff] - | fp_maskl[4][r >> 24] - | fp_maskl[5][(r >> 16) & 0xff] - | fp_maskl[6][(r >> 8) & 0xff] - | fp_maskl[7][r & 0xff]; - *r_out = fp_maskr[0][l >> 24] - | fp_maskr[1][(l >> 16) & 0xff] - | fp_maskr[2][(l >> 8) & 0xff] - | fp_maskr[3][l & 0xff] - | fp_maskr[4][r >> 24] - | fp_maskr[5][(r >> 16) & 0xff] - | fp_maskr[6][(r >> 8) & 0xff] - | fp_maskr[7][r & 0xff]; -} - -#define DES_OUT_BUFSIZE 21 - -static void -to64_msb_first(char *s, unsigned v) -{ - *s++ = i64c(v >> 18); /* bits 23..18 */ - *s++ = i64c(v >> 12); /* bits 17..12 */ - *s++ = i64c(v >> 6); /* bits 11..6 */ - *s = i64c(v); /* bits 5..0 */ -} - -static char * -des_crypt(struct des_ctx *ctx, char output[DES_OUT_BUFSIZE], - const unsigned char *key, const unsigned char *setting) -{ - uint32_t salt, r0, r1, keybuf[2]; - uint8_t *q; - - /* - * Copy the key, shifting each character up by one bit - * and padding with zeros. - */ - q = (uint8_t *)keybuf; - while (q - (uint8_t *)keybuf != 8) { - *q = *key << 1; - if (*q) - key++; - q++; - } - des_setkey(ctx, (char *)keybuf); - - /* - * setting - 2 bytes of salt - * key - up to 8 characters - */ - salt = (ascii_to_bin(setting[1]) << 6) - | ascii_to_bin(setting[0]); - - output[0] = setting[0]; - /* - * If the encrypted password that the salt was extracted from - * is only 1 character long, the salt will be corrupted. We - * need to ensure that the output string doesn't have an extra - * NUL in it! - */ - output[1] = setting[1] ? setting[1] : output[0]; - - setup_salt(ctx, salt); - /* Do it. */ - do_des(ctx, /*0, 0,*/ &r0, &r1, 25 /* count */); - - /* Now encode the result. */ - /* Each call takes low-order 24 bits and stores 4 chars */ - /* bits 31..8 of r0 */ - to64_msb_first(output + 2, (r0 >> 8)); - /* bits 7..0 of r0 and 31..16 of r1 */ - to64_msb_first(output + 6, (r0 << 16) | (r1 >> 16)); - /* bits 15..0 of r1 and two zero bits (plus extra zero byte) */ - to64_msb_first(output + 10, (r1 << 8)); - /* extra zero byte is encoded as '.', fixing it */ - output[13] = '\0'; - - return output; -} - -#undef C -#undef init_perm -#undef final_perm -#undef m_sbox -#undef D -#undef const_ctx -#undef saltbits -#undef old_salt -#undef old_rawkey0 -#undef old_rawkey1 -#undef un_pbox -#undef inv_comp_perm -#undef inv_key_perm -#undef en_keysl -#undef en_keysr -#undef de_keysl -#undef de_keysr -#undef ip_maskl -#undef ip_maskr -#undef fp_maskl -#undef fp_maskr -#undef key_perm_maskl -#undef key_perm_maskr -#undef comp_maskl -#undef comp_maskr -#undef psbox - -struct crypt_data; - -char *__crypt_r(const char *clear, const char *salt, struct crypt_data *data) -{ - struct des_ctx des_ctx = { 0 }; - -#if 0 - /* MD5 or SHA? */ - if (salt[0] == '$' && salt[1] && salt[2] == '$') { - if (salt[1] == '1') - return md5_crypt((char *)data, clear, salt); - } -#endif - - des_init(&des_ctx); - return des_crypt(&des_ctx, (char *)data, clear, salt); -} - -weak_alias(__crypt_r, crypt_r); - -char *crypt(const char *clear, const char *salt) -{ - static char buf[128]; - return __crypt_r(clear, salt, (void *)buf); -} diff --git a/05/musl-final/src/misc/cuserid.c b/05/musl-final/src/misc/cuserid.c deleted file mode 100644 index 4e78798..0000000 --- a/05/musl-final/src/misc/cuserid.c +++ /dev/null @@ -1,14 +0,0 @@ -#define _GNU_SOURCE -#include -#include -#include - -char *cuserid(char *buf) -{ - struct passwd pw, *ppw; - long pwb[256]; - if (getpwuid_r(geteuid(), &pw, (void *)pwb, sizeof pwb, &ppw)) - return 0; - snprintf(buf, L_cuserid, "%s", pw.pw_name); - return buf; -} diff --git a/05/musl-final/src/misc/dirname.c b/05/musl-final/src/misc/dirname.c deleted file mode 100644 index 8f70dbb..0000000 --- a/05/musl-final/src/misc/dirname.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include - -char *dirname(char *s) -{ - size_t i; - if (!s || !*s || !strchr(s, '/')) return "."; - i = strlen(s)-1; - for (; i&&s[i]=='/'; i--); - for (; i&&s[i-1]!='/'; i--); - for (; i&&s[i-1]=='/'; i--); - if (!i && *s=='/') i++; - s[i] = 0; - return s; -} diff --git a/05/musl-final/src/misc/ffs.c b/05/musl-final/src/misc/ffs.c deleted file mode 100644 index 2f7cb32..0000000 --- a/05/musl-final/src/misc/ffs.c +++ /dev/null @@ -1,9 +0,0 @@ -#include - -int ffs(int i) -{ - unsigned int j = i; - for (i=1; j && !(j&1); j>>=1, i++); - if (j) return i; - return 0; -} diff --git a/05/musl-final/src/misc/ftw.c b/05/musl-final/src/misc/ftw.c deleted file mode 100644 index de01e39..0000000 --- a/05/musl-final/src/misc/ftw.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include "libc.h" - -int ftw(const char *path, int (*fn)(const char *, const struct stat *, int), int fd_limit) -{ - return nftw(path, (void *)fn, fd_limit, FTW_PHYS); -} - -LFS64(ftw); diff --git a/05/musl-final/src/misc/getdomainname.c b/05/musl-final/src/misc/getdomainname.c deleted file mode 100644 index 7eb113d..0000000 --- a/05/musl-final/src/misc/getdomainname.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include -#include - -int getdomainname(char *name, size_t len) -{ - *name = 0; - return 0; -} diff --git a/05/musl-final/src/misc/getgrouplist.c b/05/musl-final/src/misc/getgrouplist.c deleted file mode 100644 index 88f273d..0000000 --- a/05/musl-final/src/misc/getgrouplist.c +++ /dev/null @@ -1,11 +0,0 @@ -#include - -/* FIXME */ - -int getgrouplist(const char *user, gid_t gid, gid_t *groups, int *ngroups) -{ - if (*ngroups<1) return -1; - *groups = gid; - *ngroups = 1; - return 0; -} diff --git a/05/musl-final/src/misc/getopt.c b/05/musl-final/src/misc/getopt.c deleted file mode 100644 index abf0e84..0000000 --- a/05/musl-final/src/misc/getopt.c +++ /dev/null @@ -1,63 +0,0 @@ -#include -#include -#include -#include -#include - -char *optarg; -int optind=1, opterr=1, optopt; -static int optpos; - -int getopt(int argc, char * const argv[], const char *optstring) -{ - int i; - wchar_t c, d; - int k, l; - char *optchar; - - if (optind >= argc || !argv[optind] || argv[optind][0] != '-' || !argv[optind][1]) - return -1; - if (argv[optind][1] == '-' && !argv[optind][2]) - return optind++, -1; - - if (!optpos) optpos++; - if ((k = mbtowc(&c, argv[optind]+optpos, MB_LEN_MAX)) < 0) { - k = 1; - c = 0xfffd; /* replacement char */ - } - optchar = argv[optind]+optpos; - optopt = c; - optpos += k; - - if (!argv[optind][optpos]) { - optind++; - optpos = 0; - } - - for (i=0; (l = mbtowc(&d, optstring+i, MB_LEN_MAX)) && d!=c; i+=l>0?l:1); - - if (d != c) { - if (optstring[0] != ':' && opterr) { - write(2, argv[0], strlen(argv[0])); - write(2, ": illegal option: ", 18); - write(2, optchar, k); - write(2, "\n", 1); - } - return '?'; - } - if (optstring[i+1] == ':') { - if (optind >= argc) { - if (optstring[0] == ':') return ':'; - if (opterr) { - write(2, argv[0], strlen(argv[0])); - write(2, ": option requires an argument: ", 31); - write(2, optchar, k); - write(2, "\n", 1); - } - return '?'; - } - optarg = argv[optind++] + optpos; - optpos = 0; - } - return c; -} diff --git a/05/musl-final/src/misc/getpriority.c b/05/musl-final/src/misc/getpriority.c deleted file mode 100644 index 2fb26b2..0000000 --- a/05/musl-final/src/misc/getpriority.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include "syscall.h" - -int getpriority(int which, id_t who) -{ - int ret = syscall2(__NR_getpriority, which, who); - if (ret < 0) return ret; - return 20-ret; -} diff --git a/05/musl-final/src/misc/getrlimit.c b/05/musl-final/src/misc/getrlimit.c deleted file mode 100644 index 84a659d..0000000 --- a/05/musl-final/src/misc/getrlimit.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -int getrlimit(int resource, struct rlimit *rlim) -{ - long k_rlim[2]; - if (syscall2(__NR_getrlimit, resource, (long)k_rlim) < 0) - return -1; - rlim->rlim_cur = k_rlim[0] == -1 ? -1 : (unsigned long)k_rlim[0]; - rlim->rlim_max = k_rlim[1] == -1 ? -1 : (unsigned long)k_rlim[1]; - return 0; -} - -LFS64(getrlimit); diff --git a/05/musl-final/src/misc/getrusage.c b/05/musl-final/src/misc/getrusage.c deleted file mode 100644 index 1b8850f..0000000 --- a/05/musl-final/src/misc/getrusage.c +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include -#include "syscall.h" - -/* this is a huge hack to make up for the kernel's stupid 32bit time_t - * without having to recopy the whole rusage structure ourselves.. */ - -int getrusage(int who, struct rusage *ru) -{ - struct { long tv_sec, tv_usec; } ktv[2]; - char *fakeaddr = ((char *)ru + sizeof(struct timeval [2]) - sizeof ktv); - if (syscall2(__NR_getrusage, who, (long)fakeaddr) < 0) - return -1; - memcpy(ktv, fakeaddr, sizeof ktv); - ru->ru_utime.tv_sec = ktv[0].tv_sec; - ru->ru_utime.tv_usec = ktv[0].tv_usec; - ru->ru_stime.tv_sec = ktv[1].tv_sec; - ru->ru_stime.tv_usec = ktv[1].tv_usec; - return 0; -} diff --git a/05/musl-final/src/misc/getsubopt.c b/05/musl-final/src/misc/getsubopt.c deleted file mode 100644 index dac9bf9..0000000 --- a/05/musl-final/src/misc/getsubopt.c +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include - -int getsubopt(char **opt, char *const *keys, char **val) -{ - char *s = *opt; - int i; - - *val = NULL; - *opt = strchr(s, ','); - if (*opt) *(*opt)++ = 0; - else *opt = s + strlen(s); - - for (i=0; keys[i]; i++) { - size_t l = strlen(keys[i]); - if (strncmp(keys[i], s, l)) continue; - if (s[l] == '=') - *val = s + l; - else if (s[l]) continue; - return i; - } - return -1; -} diff --git a/05/musl-final/src/misc/ioctl.c b/05/musl-final/src/misc/ioctl.c deleted file mode 100644 index 808b7c9..0000000 --- a/05/musl-final/src/misc/ioctl.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include -#include "syscall.h" - -int ioctl(int fd, int req, ...) -{ - void *arg; - va_list ap; - va_start(ap, req); - arg = va_arg(ap, void *); - va_end(ap); - return syscall3(__NR_ioctl, fd, req, (long)arg); -} diff --git a/05/musl-final/src/misc/lockf.c b/05/musl-final/src/misc/lockf.c deleted file mode 100644 index d8f82ef..0000000 --- a/05/musl-final/src/misc/lockf.c +++ /dev/null @@ -1,33 +0,0 @@ -#include -#include -#include -#include "libc.h" - -int lockf(int fd, int op, off_t size) -{ - struct flock l = { - .l_type = F_WRLCK, - .l_whence = SEEK_CUR, - .l_len = size, - }; - switch (op) { - case F_TEST: - l.l_type = F_RDLCK; - if (fcntl(fd, F_GETLK, &l) < 0) - return -1; - if (l.l_type == F_UNLCK || l.l_pid == getpid()) - return 0; - errno = EACCES; - return -1; - case F_ULOCK: - l.l_type = F_UNLCK; - case F_TLOCK: - return fcntl(fd, F_SETLK, &l); - case F_LOCK: - return fcntl(fd, F_SETLKW, &l); - } - errno = EINVAL; - return -1; -} - -LFS64(lockf); diff --git a/05/musl-final/src/misc/nftw.c b/05/musl-final/src/misc/nftw.c deleted file mode 100644 index 1b94ac1..0000000 --- a/05/musl-final/src/misc/nftw.c +++ /dev/null @@ -1,121 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "libc.h" - -struct history -{ - struct history *chain; - dev_t dev; - ino_t ino; - int level; - int base; -}; - -#undef dirfd -#define dirfd(d) (*(int *)d) - -static int do_nftw(char *path, int (*fn)(const char *, const struct stat *, int, struct FTW *), int fd_limit, int flags, struct history *h) -{ - size_t l = strlen(path), j = l && path[l-1]=='/' ? l-1 : l; - struct stat st; - struct history new; - int type; - int r; - struct FTW lev; - char *name; - - if ((flags & FTW_PHYS) ? lstat(path, &st) : stat(path, &st) < 0) { - if (!(flags & FTW_PHYS) && errno==ENOENT && !lstat(path, &st)) - type = FTW_SLN; - else if (errno != EACCES) return -1; - else type = FTW_NS; - } else if (S_ISDIR(st.st_mode)) { - if (access(path, R_OK) < 0) type = FTW_DNR; - else if (flags & FTW_DEPTH) type = FTW_DP; - else type = FTW_D; - } else if (S_ISLNK(st.st_mode)) { - if (flags & FTW_PHYS) type = FTW_SL; - else type = FTW_SLN; - } else { - type = FTW_F; - } - - if ((flags & FTW_MOUNT) && h - && (st.st_dev != h->dev || st.st_ino != h->ino)) - return 0; - - new.chain = h; - new.dev = st.st_dev; - new.ino = st.st_ino; - new.level = h ? h->level+1 : 0; - new.base = l+1; - - lev.level = new.level; - lev.base = h ? h->base : (name=strrchr(path, '/')) ? name-path : 0; - - if (!(flags & FTW_DEPTH) && (r=fn(path, &st, type, &lev))) - return r; - - for (; h; h = h->chain) - if (h->dev == st.st_dev && h->ino == st.st_ino) - return 0; - - if ((type == FTW_D || type == FTW_DP) && fd_limit) { - DIR *d = opendir(path); - if (d) { - struct dirent *de; - while ((de = readdir(d))) { - if (de->d_name[0] == '.' - && (!de->d_name[1] - || (de->d_name[1]=='.' - && !de->d_name[2]))) continue; - if (strlen(de->d_name) >= PATH_MAX-l) { - errno = ENAMETOOLONG; - closedir(d); - return -1; - } - path[j]='/'; - strcpy(path+j+1, de->d_name); - if ((r=do_nftw(path, fn, fd_limit-1, flags, &new))) { - closedir(d); - return r; - } - } - closedir(d); - } else if (errno != EACCES) { - return -1; - } - } - - path[l] = 0; - if ((flags & FTW_DEPTH) && (r=fn(path, &st, type, &lev))) - return r; - - return 0; -} - -int nftw(const char *path, int (*fn)(const char *, const struct stat *, int, struct FTW *), int fd_limit, int flags) -{ - size_t l; - char pathbuf[PATH_MAX+1]; - - if (fd_limit <= 0) return 0; - - l = strlen(path); - if (l > PATH_MAX) { - errno = ENAMETOOLONG; - return -1; - } - memcpy(pathbuf, path, l+1); - - return do_nftw(pathbuf, fn, fd_limit, flags, NULL); -} - -LFS64(nftw); diff --git a/05/musl-final/src/misc/openpty.c b/05/musl-final/src/misc/openpty.c deleted file mode 100644 index 0b4eb22..0000000 --- a/05/musl-final/src/misc/openpty.c +++ /dev/null @@ -1,33 +0,0 @@ -#include -#include -#include -#include -#include - -/* Nonstandard, but vastly superior to the standard functions */ - -int openpty(int *m, int *s, char *name, const struct termios *tio, const struct winsize *ws) -{ - int n=0; - char buf[20]; - - *m = open("/dev/ptmx", O_RDWR|O_NOCTTY); - if (!*m) return -1; - - if (ioctl(*m, TIOCSPTLCK, &n) || ioctl (*m, TIOCGPTN, &n)) { - close(*m); - return -1; - } - - if (!name) name = buf; - snprintf(name, sizeof buf, "/dev/pts/%d", n); - if ((*s = open(name, O_RDWR|O_NOCTTY)) < 0) { - close(*m); - return -1; - } - - if (tio) tcsetattr(*s, TCSANOW, tio); - if (ws) ioctl(*s, TIOCSWINSZ, ws); - - return 0; -} diff --git a/05/musl-final/src/misc/pty.c b/05/musl-final/src/misc/pty.c deleted file mode 100644 index 0d25a83..0000000 --- a/05/musl-final/src/misc/pty.c +++ /dev/null @@ -1,35 +0,0 @@ -#include -#include -#include -#include - -int posix_openpt(int flags) -{ - return open("/dev/ptmx", flags); -} - -int grantpt(int fd) -{ - return 0; -} - -int unlockpt(int fd) -{ - int unlock = 0; - return ioctl(fd, TIOCSPTLCK, &unlock); -} - -char *ptsname(int fd) -{ - static char buf[9 + sizeof(int)*3 + 1]; - char *s = buf+sizeof(buf)-1; - int pty; - if (ioctl (fd, TIOCGPTN, &pty)) - return NULL; - if (pty) for (; pty; pty/=10) *--s = '0' + pty%10; - else *--s = '0'; - s -= 9; - s[0] = '/'; s[1] = 'd'; s[2] = 'e'; s[3] = 'v'; - s[4] = '/'; s[5] = 'p'; s[6] = 't'; s[7] = 's'; s[8] = '/'; - return s; -} diff --git a/05/musl-final/src/misc/realpath.c b/05/musl-final/src/misc/realpath.c deleted file mode 100644 index f6b5549..0000000 --- a/05/musl-final/src/misc/realpath.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -char *realpath(const char *filename, char *resolved) -{ - return 0; -} diff --git a/05/musl-final/src/misc/sched_yield.c b/05/musl-final/src/misc/sched_yield.c deleted file mode 100644 index 8a68519..0000000 --- a/05/musl-final/src/misc/sched_yield.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -int __yield() -{ - return syscall0(__NR_sched_yield); -} - -weak_alias(__yield, sched_yield); diff --git a/05/musl-final/src/misc/setpriority.c b/05/musl-final/src/misc/setpriority.c deleted file mode 100644 index 26da4b8..0000000 --- a/05/musl-final/src/misc/setpriority.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int setpriority(int which, id_t who, int prio) -{ - return syscall3(__NR_getpriority, which, who, prio); -} diff --git a/05/musl-final/src/misc/setrlimit.c b/05/musl-final/src/misc/setrlimit.c deleted file mode 100644 index 7fdfc4e..0000000 --- a/05/musl-final/src/misc/setrlimit.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -int setrlimit(int resource, const struct rlimit *rlim) -{ - long k_rlim[2] = { rlim->rlim_cur, rlim->rlim_max }; - return syscall2(__NR_setrlimit, resource, (long)k_rlim); -} - -LFS64(setrlimit); diff --git a/05/musl-final/src/misc/syslog.c b/05/musl-final/src/misc/syslog.c deleted file mode 100644 index 4809d2d..0000000 --- a/05/musl-final/src/misc/syslog.c +++ /dev/null @@ -1,115 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "libc.h" - -static int lock; -static const char *log_ident; -static int log_opt; -static int log_facility = LOG_USER; -static int log_mask = 0xff; -static FILE *log_f; - -int setlogmask(int maskpri) -{ - int old = log_mask; - if (maskpri) log_mask = maskpri; - return old; -} - -static const struct { - short sun_family; - char sun_path[9]; -} log_addr = { - AF_UNIX, - "/dev/log" -}; - -void closelog(void) -{ - LOCK(&lock); - if (log_f) fclose(log_f); - log_f = NULL; - UNLOCK(&lock); -} - -static void __openlog(const char *ident, int opt, int facility) -{ - int fd; - - log_ident = ident; - log_opt = opt; - log_facility = facility; - - if (!(opt & LOG_NDELAY) || log_f) return; - - fd = socket(AF_UNIX, SOCK_STREAM, 0); - fcntl(fd, F_SETFD, FD_CLOEXEC); - if (connect(fd, (void *)&log_addr, sizeof(short) + sizeof "/dev/log") < 0) - close(fd); - else log_f = fdopen(fd, "wb"); -} - -void openlog(const char *ident, int opt, int facility) -{ - LOCK(&lock); - __openlog(ident, opt, facility); - UNLOCK(&lock); -} - -void syslog(int priority, const char *message, ...) -{ - struct sigaction sa; - va_list ap; - char timebuf[16]; - time_t now; - struct tm tm; - //const char *fmt, *ident, *sep; - //int i; - - if (!(log_mask & LOG_MASK(priority&7)) || (priority&~0x3ff)) return; - - LOCK(&lock); - - if (!log_f) __openlog(log_ident, log_opt | LOG_NDELAY, log_facility); - if (!log_f) { - UNLOCK(&lock); - return; - } - - memset(&sa, 0, sizeof sa); - sa.sa_handler = SIG_IGN; - if (sigaction(SIGPIPE, &sa, &sa) < 0) { - // we must abandon logging or we might cause SIGPIPE - UNLOCK(&lock); - return; - } - - now = time(NULL); - gmtime_r(&now, &tm); - strftime(timebuf, sizeof timebuf, "%b %e %T", &tm); - - fprintf(log_f, "<%d>%s ", priority, timebuf); - if (log_ident) fprintf(log_f, "%s", log_ident); - if (log_opt & LOG_PID) fprintf(log_f, "[%d]", getpid()); - if (log_ident) fprintf(log_f, ": "); - - va_start(ap, message); - vfprintf(log_f, message, ap); - va_end(ap); - fputc(0, log_f); - fflush(log_f); - - // Note: LOG_CONS is not supported because it is annoying!! - // syslogd will send messages to console if it deems them appropriate! - - sigaction(SIGPIPE, &sa, NULL); - - UNLOCK(&lock); -} diff --git a/05/musl-final/src/misc/uname.c b/05/musl-final/src/misc/uname.c deleted file mode 100644 index fbe8664..0000000 --- a/05/musl-final/src/misc/uname.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include -#include "syscall.h" - -int uname(struct utsname *uts) -{ - return syscall1(__NR_uname, (long)uts); -} diff --git a/05/musl-final/src/mman/madvise.c b/05/musl-final/src/mman/madvise.c deleted file mode 100644 index c4ef799..0000000 --- a/05/musl-final/src/mman/madvise.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -int __madvise(void *addr, size_t len, int advice) -{ - return syscall3(__NR_madvise, (long)addr, len, advice); -} - -int madvise(void *addr, size_t len, int advice) -{ - return syscall3(__NR_madvise, (long)addr, len, advice); -} diff --git a/05/musl-final/src/mman/mlock.c b/05/musl-final/src/mman/mlock.c deleted file mode 100644 index 3c7c653..0000000 --- a/05/musl-final/src/mman/mlock.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int mlock(const void *addr, size_t len) -{ - return syscall2(__NR_mlock, (long)addr, len); -} diff --git a/05/musl-final/src/mman/mlockall.c b/05/musl-final/src/mman/mlockall.c deleted file mode 100644 index 782fc9d..0000000 --- a/05/musl-final/src/mman/mlockall.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int mlockall(int flags) -{ - return syscall1(__NR_mlockall, flags); -} diff --git a/05/musl-final/src/mman/mmap.c b/05/musl-final/src/mman/mmap.c deleted file mode 100644 index 665e2ec..0000000 --- a/05/musl-final/src/mman/mmap.c +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include -#include -#include -#include "syscall.h" -#include "libc.h" - -void *__mmap(void *start, size_t len, int prot, int flags, int fd, off_t off) -{ - if (sizeof(off_t) > sizeof(long)) - if (((long)off & 0xfff) | ((long)((unsigned long long)off>>(12 + 8*(sizeof(off_t)-sizeof(long)))))) - start = (void *)-1; -#ifdef __NR_mmap2 - return (void *)syscall6(__NR_mmap2, (long)start, len, prot, flags, fd, off>>12); -#else - return (void *)syscall6(__NR_mmap, (long)start, len, prot, flags, fd, off); -#endif -} - -void *mmap(void *start, size_t len, int prot, int flags, int fd, off_t off) -{ - if (sizeof(off_t) > sizeof(long)) - if (((long)off & 0xfff) | ((long)((unsigned long long)off>>(12 + 8*(sizeof(off_t)-sizeof(long)))))) - start = (void *)-1; -#ifdef __NR_mmap2 - return (void *)syscall6(__NR_mmap2, (long)start, len, prot, flags, fd, off>>12); -#else - return (void *)syscall6(__NR_mmap, (long)start, len, prot, flags, fd, off); -#endif -} - -LFS64(mmap); diff --git a/05/musl-final/src/mman/mprotect.c b/05/musl-final/src/mman/mprotect.c deleted file mode 100644 index 11d5e23..0000000 --- a/05/musl-final/src/mman/mprotect.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int mprotect(void *addr, size_t len, int prot) -{ - return syscall3(__NR_mprotect, (long)addr, len, prot); -} diff --git a/05/musl-final/src/mman/mremap.c b/05/musl-final/src/mman/mremap.c deleted file mode 100644 index 78491ef..0000000 --- a/05/musl-final/src/mman/mremap.c +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include -#include -#include "syscall.h" -#include "libc.h" - -void *__mremap(void *old_addr, size_t old_len, size_t new_len, int flags, ...) -{ - va_list ap; - void *new_addr; - - va_start(ap, flags); - new_addr = va_arg(ap, void *); - va_end(ap); - - return (void *)syscall5(__NR_mremap, (long)old_addr, old_len, new_len, flags, (long)new_addr); -} - -weak_alias(__mremap, mremap); diff --git a/05/musl-final/src/mman/msync.c b/05/musl-final/src/mman/msync.c deleted file mode 100644 index e092647..0000000 --- a/05/musl-final/src/mman/msync.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include -#include "syscall.h" - -int msync(void *start, size_t len, int flags) -{ - return syscall3(__NR_msync, (long)start, len, flags); -} diff --git a/05/musl-final/src/mman/munlock.c b/05/musl-final/src/mman/munlock.c deleted file mode 100644 index 0db5981..0000000 --- a/05/musl-final/src/mman/munlock.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int munlock(const void *addr, size_t len) -{ - return syscall2(__NR_munlock, (long)addr, len); -} diff --git a/05/musl-final/src/mman/munlockall.c b/05/musl-final/src/mman/munlockall.c deleted file mode 100644 index ce3e86c..0000000 --- a/05/musl-final/src/mman/munlockall.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int munlockall(void) -{ - return syscall0(__NR_munlockall); -} diff --git a/05/musl-final/src/mman/munmap.c b/05/musl-final/src/mman/munmap.c deleted file mode 100644 index d1777e3..0000000 --- a/05/musl-final/src/mman/munmap.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include -#include "syscall.h" -#include "libc.h" - -int __munmap(void *start, size_t len) -{ - return syscall2(__NR_munmap, (long)start, len); -} - -int munmap(void *start, size_t len) -{ - return syscall2(__NR_munmap, (long)start, len); -} diff --git a/05/musl-final/src/mman/posix_madvise.c b/05/musl-final/src/mman/posix_madvise.c deleted file mode 100644 index 4727ad7..0000000 --- a/05/musl-final/src/mman/posix_madvise.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int posix_madvise(void *addr, size_t len, int advice) -{ - return 0; -} diff --git a/05/musl-final/src/multibyte/btowc.c b/05/musl-final/src/multibyte/btowc.c deleted file mode 100644 index 9d2c3b1..0000000 --- a/05/musl-final/src/multibyte/btowc.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include - -wint_t btowc(int c) -{ - return c<128U ? c : EOF; -} diff --git a/05/musl-final/src/multibyte/decode.c b/05/musl-final/src/multibyte/decode.c deleted file mode 100644 index 8d3d3c0..0000000 --- a/05/musl-final/src/multibyte/decode.c +++ /dev/null @@ -1,47 +0,0 @@ -/* - * This code was written by Rich Felker in 2010; no copyright is claimed. - * This code is in the public domain. Attribution is appreciated but - * unnecessary. - */ - -#include -#include -#include -#include - -#include "internal.h" - -/* Decodes UTF-8 byte-by-byte. The c argument must be initialized to 0 - * to begin decoding; when finished it will contain the Unicode scalar - * value decoded. Return value is 1 if finished, 0 if in-progress, and - * -1 if an invalid sequence was encountered. After an invalid sequence, - * the state (in c) automatically resets to 0 if a continuation byte was - * expected to facilitate a calling idiom of immediately retrying a - * failed decode call after processing the invalid sequence. If the - * second try fails, the byte is invalid as a starter as well. - * - * A trivial usage idiom is: - * while (src=0) 1[dst+=n]=0, src++; - */ - -int decode(unsigned *c, unsigned b) -{ - if (!*c) { - if (b < 0x80) { - *c = b; - return 1; - } else if (b-SA >= SB-SA) { - *c = FAILSTATE; - return -1; - } - *c = bittab[b-SA]; - return 0; - } - - if (OOB(*c,b)) { - *c = 0; - return -1; - } - *c = *c<<6 | b-0x80; - return !(*c&(1U<<31)); -} diff --git a/05/musl-final/src/multibyte/internal.c b/05/musl-final/src/multibyte/internal.c deleted file mode 100644 index e9b938d..0000000 --- a/05/musl-final/src/multibyte/internal.c +++ /dev/null @@ -1,60 +0,0 @@ -/* - * This code was written by Rich Felker in 2010; no copyright is claimed. - * This code is in the public domain. Attribution is appreciated but - * unnecessary. - */ - -#include - -#include "internal.h" - -#define C(x) ( x<2 ? -1 : ( R(0x80,0xc0) | x ) ) -#define D(x) C((x+16)) -#define E(x) ( ( x==0 ? R(0xa0,0xc0) : \ - x==0xd ? R(0x80,0xa0) : \ - R(0x80,0xc0) ) \ - | ( R(0x80,0xc0) >> 6 ) \ - | x ) -#ifdef I_FAILED_TO_RTFM_RFC3629 -#define F0(x) (( x==0 ? R(0x90,0xc0) : \ - R(0x80,0xc0) ) \ - | ( R(0x80,0xc0) >> 6 ) \ - | ( R(0x80,0xc0) >> 12 ) \ - | x ) -#define F8(x) (( x==0 ? R(0xa0,0xc0) : \ - R(0x80,0xc0) ) \ - | ( R(0x80,0xc0) >> 6 ) \ - | ( R(0x80,0xc0) >> 12 ) \ - | ( R(0x80,0xc0) >> 18 ) \ - | x ) -#define FC(x) (( x==0 ? R(0x88,0xc0) : \ - R(0x80,0xc0) ) \ - | ( R(0x80,0xc0) >> 6 ) \ - | ( R(0x80,0xc0) >> 12 ) \ - | ( R(0x80,0xc0) >> 18 ) \ - | ( R(0x80,0xc0) >> 24 ) \ - | x ) -#define F(x) ( x<8 ? F0(x) : x<12 ? F8((x&3)) : x<14 ? FC((x&1)) : -1 ) -#else -#define F(x) ( ( x>=5 ? 0 : \ - x==0 ? R(0x90,0xc0) : \ - x==4 ? R(0x80,0xa0) : \ - R(0x80,0xc0) ) \ - | ( R(0x80,0xc0) >> 6 ) \ - | ( R(0x80,0xc0) >> 12 ) \ - | x ) -#endif - -const uint32_t bittab[] = { - C(0x2),C(0x3),C(0x4),C(0x5),C(0x6),C(0x7), - C(0x8),C(0x9),C(0xa),C(0xb),C(0xc),C(0xd),C(0xe),C(0xf), - D(0x0),D(0x1),D(0x2),D(0x3),D(0x4),D(0x5),D(0x6),D(0x7), - D(0x8),D(0x9),D(0xa),D(0xb),D(0xc),D(0xd),D(0xe),D(0xf), - E(0x0),E(0x1),E(0x2),E(0x3),E(0x4),E(0x5),E(0x6),E(0x7), - E(0x8),E(0x9),E(0xa),E(0xb),E(0xc),E(0xd),E(0xe),E(0xf), - F(0x0),F(0x1),F(0x2),F(0x3),F(0x4), -#ifdef I_FAILED_TO_RTFM_RFC3629 - F(0x5),F(0x6),F(0x7), - F(0x8),F(0x9),F(0xa),F(0xb),F(0xc),F(0xd) -#endif -}; diff --git a/05/musl-final/src/multibyte/internal.h b/05/musl-final/src/multibyte/internal.h deleted file mode 100644 index ec52bdf..0000000 --- a/05/musl-final/src/multibyte/internal.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * This code was written by Rich Felker in 2010; no copyright is claimed. - * This code is in the public domain. Attribution is appreciated but - * unnecessary. - */ - -#define LIBC -#ifndef LIBC -/* rename functions not to conflict with libc */ -#ifndef myprefix -#define myprefix fsmu8_ -#endif -#define concat2(a,b) a ## b -#define concat(a,b) concat2(a,b) -#define prefix(b) concat(myprefix,b) - -#undef mblen -#undef mbrlen -#undef mbrtowc -#undef mbsinit -#undef mbsnrtowcs -#undef mbsrtowcs -#undef wcrtomb -#undef wcsrtombs -#undef wcstombs -#undef wctomb -#define mblen prefix(mblen) -#define mbrlen prefix(mbrlen) -#define mbrtowc prefix(mbrtowc) -#define mbsinit prefix(mbsinit) -#define mbsnrtowcs prefix(mbsnrtowcs) -#define mbsrtowcs prefix(mbsrtowcs) -#define mbstowcs prefix(mbstowcs) -#define wcrtomb prefix(wcrtomb) -#define wcsnrtombs prefix(wcsnrtombs) -#define wcsrtombs prefix(wcsrtombs) -#define wcstombs prefix(wcstombs) -#define wctomb prefix(wctomb) - -#define bittab prefix(bittab) -#else -#define bittab __fsmu8 -#endif - -extern const uint32_t bittab[]; - -/* Upper 6 state bits are a negative integer offset to bound-check next byte */ -/* equivalent to: ( (b-0x80) | (b+offset) ) & ~0x3f */ -#define OOB(c,b) (((((b)>>3)-0x10)|(((b)>>3)+((int32_t)(c)>>26))) & ~7) - -/* Interval [a,b). Either a must be 80 or b must be c0, lower 3 bits clear. */ -#define R(a,b) ((uint32_t)((a==0x80 ? 0x40-b : -a) << 23)) -#define FAILSTATE R(0x80,0x80) - -#ifdef I_FAILED_TO_RTFM_RFC3629 -#define SA 0xc2u -#define SB 0xfeu -#else -#define SA 0xc2u -#define SB 0xf5u -#endif diff --git a/05/musl-final/src/multibyte/mblen.c b/05/musl-final/src/multibyte/mblen.c deleted file mode 100644 index 26d3564..0000000 --- a/05/musl-final/src/multibyte/mblen.c +++ /dev/null @@ -1,17 +0,0 @@ -/* - * This code was written by Rich Felker in 2010; no copyright is claimed. - * This code is in the public domain. Attribution is appreciated but - * unnecessary. - */ - -#include -#include -#include -#include - -#include "internal.h" - -int mblen(const char *s, size_t n) -{ - return mbtowc(0, s, n); -} diff --git a/05/musl-final/src/multibyte/mbrlen.c b/05/musl-final/src/multibyte/mbrlen.c deleted file mode 100644 index c9a9f03..0000000 --- a/05/musl-final/src/multibyte/mbrlen.c +++ /dev/null @@ -1,18 +0,0 @@ -/* - * This code was written by Rich Felker in 2010; no copyright is claimed. - * This code is in the public domain. Attribution is appreciated but - * unnecessary. - */ - -#include -#include -#include -#include - -#include "internal.h" - -size_t mbrlen(const char *s, size_t n, mbstate_t *st) -{ - static unsigned internal; - return mbrtowc(0, s, n, st ? st : (mbstate_t *)&internal); -} diff --git a/05/musl-final/src/multibyte/mbrtowc.c b/05/musl-final/src/multibyte/mbrtowc.c deleted file mode 100644 index a354573..0000000 --- a/05/musl-final/src/multibyte/mbrtowc.c +++ /dev/null @@ -1,58 +0,0 @@ -/* - * This code was written by Rich Felker in 2010; no copyright is claimed. - * This code is in the public domain. Attribution is appreciated but - * unnecessary. - */ - -#include -#include -#include -#include - -#include "internal.h" - -size_t mbrtowc(wchar_t *wc, const char *src, size_t n, mbstate_t *st) -{ - static unsigned internal_state; - unsigned c; - const unsigned char *s = (const void *)src; - const unsigned N = n; - - if (!st) st = (void *)&internal_state; - c = *(unsigned *)st; - - if (!s) { - s = ""; - wc = (void *)&wc; - n = 1; - } else if (!wc) wc = (void *)&wc; - - if (!n) return -2; - if (!c) { - if (*s < 0x80) return !!(*wc = *s); - if (*s-SA > SB-SA) goto ilseq; - c = bittab[*s++-SA]; n--; - } - - if (n) { - if (OOB(c,*s)) goto ilseq; -loop: - c = c<<6 | *s++-0x80; n--; - if (!(c&(1U<<31))) { - *(unsigned *)st = 0; - *wc = c; - return N-n; - } - if (n) { - if (*s-0x80u >= 0x40) goto ilseq; - goto loop; - } - } - - *(unsigned *)st = c; - return -2; -ilseq: - *(unsigned *)st = FAILSTATE; - errno = EILSEQ; - return -1; -} diff --git a/05/musl-final/src/multibyte/mbsinit.c b/05/musl-final/src/multibyte/mbsinit.c deleted file mode 100644 index d307e5a..0000000 --- a/05/musl-final/src/multibyte/mbsinit.c +++ /dev/null @@ -1,17 +0,0 @@ -/* - * This code was written by Rich Felker in 2010; no copyright is claimed. - * This code is in the public domain. Attribution is appreciated but - * unnecessary. - */ - -#include -#include -#include -#include - -#include "internal.h" - -int mbsinit(const mbstate_t *st) -{ - return !*(unsigned *)st; -} diff --git a/05/musl-final/src/multibyte/mbsnrtowcs.c b/05/musl-final/src/multibyte/mbsnrtowcs.c deleted file mode 100644 index c6f0207..0000000 --- a/05/musl-final/src/multibyte/mbsnrtowcs.c +++ /dev/null @@ -1,61 +0,0 @@ -/* - * This code was written by Rich Felker in 2010; no copyright is claimed. - * This code is in the public domain. Attribution is appreciated but - * unnecessary. - */ - -#include -#include -#include -#include -#include - -#include "internal.h" - -size_t mbsnrtowcs(wchar_t *wcs, const char **src, size_t n, size_t wn, mbstate_t *st) -{ - size_t l, cnt=0, n2; - wchar_t *ws, wbuf[256]; - const char *s = *src; - - if (!wcs) ws = wbuf, wn = sizeof wbuf / sizeof *wbuf; - else ws = wcs; - - /* making sure output buffer size is at most n/4 will ensure - * that mbsrtowcs never reads more than n input bytes. thus - * we can use mbsrtowcs as long as it's practical.. */ - - while ( s && wn && ( (n2=n/4)>=wn || n2>32 ) ) { - if (n2>=wn) n2=wn; - n -= n2; - l = mbsrtowcs(ws, &s, n2, st); - if (!(l+1)) { - cnt = l; - wn = 0; - break; - } - if (ws != wbuf) { - ws += l; - wn -= l; - } - cnt += l; - } - if (s) while (wn && n) { - l = mbrtowc(ws, s, n, st); - if (l+2<=2) { - if (!(l+1)) { - cnt = l; - break; - } - /* have to roll back partial character */ - *(unsigned *)st = 0; - break; - } - s += l; n -= l; - /* safe - this loop runs fewer than sizeof(wbuf)/8 times */ - ws++; wn--; - cnt++; - } - if (wcs) *src = s; - return cnt; -} diff --git a/05/musl-final/src/multibyte/mbsrtowcs.c b/05/musl-final/src/multibyte/mbsrtowcs.c deleted file mode 100644 index 64399cf..0000000 --- a/05/musl-final/src/multibyte/mbsrtowcs.c +++ /dev/null @@ -1,121 +0,0 @@ -/* - * This code was written by Rich Felker in 2010; no copyright is claimed. - * This code is in the public domain. Attribution is appreciated but - * unnecessary. - */ - -#include -#include -#include -#include - -#include "internal.h" - -size_t mbsrtowcs(wchar_t *ws, const char **src, size_t wn, mbstate_t *st) -{ - unsigned c; - const unsigned char *s = (const void *)*src; - const wchar_t *wsorig = ws; - - if (!st) st = (void *)&c, c = 0; - else c = *(unsigned *)st; - - if (c) { - *(unsigned *)st = 0; - if (!ws) { - wn = 0; - goto resume0; - } - goto resume; - } - - if (!ws) for (wn=0;;) { - if (*s-SA >= SB-SA) { - while (((uintptr_t)s&3) && *s-1u<0x7f) s++, wn++; - while (!(( *(uint32_t*)s | *(uint32_t*)s-0x01010101) & 0x80808080)) s+=4, wn+=4; - while (*s-1u<0x7f) s++, wn++; - if (!*s) return wn; - if (*s-SA >= SB-SA) goto ilseq2; - } - c = bittab[*s++-SA]; - do { -resume0: - if (OOB(c,*s)) goto ilseq2; s++; - c <<= 6; if (!(c&(1U<<31))) break; -#ifdef I_FAILED_TO_RTFM_RFC3629 - if (*s++-0x80u >= 0x40) goto ilseq2; - c <<= 6; if (!(c&(1U<<31))) break; - if (*s++-0x80u >= 0x40) goto ilseq2; - c <<= 6; if (!(c&(1U<<31))) break; -#endif - if (*s++-0x80u >= 0x40) goto ilseq2; - c <<= 6; if (!(c&(1U<<31))) break; - if (*s++-0x80u >= 0x40) goto ilseq2; - } while (0); - wn++; c = 0; - } - - while (wn) { - if (*s-SA >= SB-SA) { - if (wn >= 7) { - while (((uintptr_t)s&3) && *s-1u<0x7f) { - *ws++ = *s++; - wn--; - } - while (wn>=4 && !(( *(uint32_t*)s | *(uint32_t*)s-0x01010101) & 0x80808080)) { - *ws++ = *s++; - *ws++ = *s++; - *ws++ = *s++; - *ws++ = *s++; - wn -= 4; - } - } - while (wn && *s-1u<0x7f) { - *ws++ = *s++; - wn--; - } - if (!wn) break; - if (!*s) { - *ws = 0; - *src = 0; - return ws-wsorig; - } - if (*s-SA >= SB-SA) goto ilseq; - } - c = bittab[*s++-SA]; - do { -resume: - if (OOB(c,*s)) goto ilseq; - c = (c<<6) | *s++-0x80; - if (!(c&(1U<<31))) break; - -#ifdef I_FAILED_TO_RTFM_RFC3629 - if (*s-0x80u >= 0x40) goto ilseq; - c = (c<<6) | *s++-0x80; - if (!(c&(1U<<31))) break; - - if (*s-0x80u >= 0x40) goto ilseq; - c = (c<<6) | *s++-0x80; - if (!(c&(1U<<31))) break; -#endif - - if (*s-0x80u >= 0x40) goto ilseq; - c = (c<<6) | *s++-0x80; - if (!(c&(1U<<31))) break; - - if (*s-0x80u >= 0x40) goto ilseq; - c = (c<<6) | *s++-0x80; - } while (0); - - *ws++ = c; wn--; c = 0; - } - *src = (const void *)s; - return ws-wsorig; -ilseq: - *src = (const void *)s; -ilseq2: - /* enter permanently failing state */ - *(unsigned *)st = FAILSTATE; - errno = EILSEQ; - return -1; -} diff --git a/05/musl-final/src/multibyte/mbstowcs.c b/05/musl-final/src/multibyte/mbstowcs.c deleted file mode 100644 index 23e1d92..0000000 --- a/05/musl-final/src/multibyte/mbstowcs.c +++ /dev/null @@ -1,18 +0,0 @@ -/* - * This code was written by Rich Felker in 2010; no copyright is claimed. - * This code is in the public domain. Attribution is appreciated but - * unnecessary. - */ - -#include -#include -#include -#include - -#include "internal.h" - -size_t mbstowcs(wchar_t *ws, const char *s, size_t wn) -{ - mbstate_t st = { 0 }; - return mbsrtowcs(ws, (void*)&s, wn, &st); -} diff --git a/05/musl-final/src/multibyte/mbtowc.c b/05/musl-final/src/multibyte/mbtowc.c deleted file mode 100644 index bdcaeb3..0000000 --- a/05/musl-final/src/multibyte/mbtowc.c +++ /dev/null @@ -1,19 +0,0 @@ -/* - * This code was written by Rich Felker in 2010; no copyright is claimed. - * This code is in the public domain. Attribution is appreciated but - * unnecessary. - */ - -#include -#include -#include -#include - -#include "internal.h" - -int mbtowc(wchar_t *wc, const char *s, size_t n) -{ - mbstate_t st = { 0 }; - n = mbrtowc(wc, s, n, &st); - return n+2 ? n : -1; -} diff --git a/05/musl-final/src/multibyte/wcrtomb.c b/05/musl-final/src/multibyte/wcrtomb.c deleted file mode 100644 index 36180c8..0000000 --- a/05/musl-final/src/multibyte/wcrtomb.c +++ /dev/null @@ -1,38 +0,0 @@ -/* - * This code was written by Rich Felker in 2010; no copyright is claimed. - * This code is in the public domain. Attribution is appreciated but - * unnecessary. - */ - -#include -#include -#include -#include - -#include "internal.h" - -size_t wcrtomb(char *s, wchar_t wc, mbstate_t *st) -{ - if (!s) return 1; - if ((unsigned)wc < 0x80) { - *s = wc; - return 1; - } else if ((unsigned)wc < 0x800) { - *s++ = 0xc0 | (wc>>6); - *s = 0x80 | (wc&0x3f); - return 2; - } else if ((unsigned)wc < 0xd800 || (unsigned)wc-0xe000 < 0x2000) { - *s++ = 0xe0 | (wc>>12); - *s++ = 0x80 | ((wc>>6)&0x3f); - *s = 0x80 | (wc&0x3f); - return 3; - } else if ((unsigned)wc-0x10000 < 0x100000) { - *s++ = 0xf0 | (wc>>18); - *s++ = 0x80 | ((wc>>12)&0x3f); - *s++ = 0x80 | ((wc>>6)&0x3f); - *s = 0x80 | (wc&0x3f); - return 4; - } - errno = EILSEQ; - return -1; -} diff --git a/05/musl-final/src/multibyte/wcsnrtombs.c b/05/musl-final/src/multibyte/wcsnrtombs.c deleted file mode 100644 index 666f6f3..0000000 --- a/05/musl-final/src/multibyte/wcsnrtombs.c +++ /dev/null @@ -1,51 +0,0 @@ -/* - * This code was written by Rich Felker in 2010; no copyright is claimed. - * This code is in the public domain. Attribution is appreciated but - * unnecessary. - */ - -#include -#include -#include -#include - -#include "internal.h" - -size_t wcsnrtombs(char *dst, const wchar_t **wcs, size_t wn, size_t n, mbstate_t *st) -{ - size_t l, cnt=0, n2; - char *s, buf[256]; - const wchar_t *ws = *wcs; - - if (!dst) s = buf, n = sizeof buf; - else s = dst; - - while ( n && ( (n2=wn)>=n || n2>32 ) ) { - if (n2>=n) n2=n; - wn -= n2; - l = wcsrtombs(s, &ws, n2, 0); - if (!(l+1)) { - cnt = l; - n = 0; - break; - } - if (s != buf) { - s += l; - n -= l; - } - cnt += l; - } - while (n && wn) { - l = wcrtomb(s, *ws, 0); - if (!(l+1)) { - cnt = l; - break; - } - ws++; wn--; - /* safe - this loop runs fewer than sizeof(buf) times */ - s+=l; n-=l; - cnt++; - } - if (dst) *wcs = ws; - return cnt; -} diff --git a/05/musl-final/src/multibyte/wcsrtombs.c b/05/musl-final/src/multibyte/wcsrtombs.c deleted file mode 100644 index 3c48d65..0000000 --- a/05/musl-final/src/multibyte/wcsrtombs.c +++ /dev/null @@ -1,58 +0,0 @@ -/* - * This code was written by Rich Felker in 2010; no copyright is claimed. - * This code is in the public domain. Attribution is appreciated but - * unnecessary. - */ - -#include -#include -#include -#include - -#include "internal.h" - -size_t wcsrtombs(char *s, const wchar_t **ws, size_t n, mbstate_t *st) -{ - const wchar_t *ws2; - char buf[4]; - size_t N = n, l; - if (!s) { - for (n=0, ws2=*ws; *ws2; ws2++) { - if (*ws2 >= 0x80) { - l = wcrtomb(buf, *ws2, 0); - if (!(l+1)) return -1; - n += l; - } else n++; - } - return n; - } - while (n>=4 && **ws) { - if (**ws >= 0x80) { - l = wcrtomb(s, **ws, 0); - if (!(l+1)) return -1; - s += l; - n -= l; - } else { - *s++ = **ws; - n--; - } - (*ws)++; - } - while (n && **ws) { - if (**ws >= 0x80) { - l = wcrtomb(buf, **ws, 0); - if (!(l+1)) return -1; - if (l>n) return N-n; - wcrtomb(s, **ws, 0); - s += l; - n -= l; - } else { - *s++ = **ws; - n--; - } - (*ws)++; - } - if (n) *s = 0; - *ws = 0; - return N-n; -} diff --git a/05/musl-final/src/multibyte/wcstombs.c b/05/musl-final/src/multibyte/wcstombs.c deleted file mode 100644 index b9c1b18..0000000 --- a/05/musl-final/src/multibyte/wcstombs.c +++ /dev/null @@ -1,17 +0,0 @@ -/* - * This code was written by Rich Felker in 2010; no copyright is claimed. - * This code is in the public domain. Attribution is appreciated but - * unnecessary. - */ - -#include -#include -#include -#include - -#include "internal.h" - -size_t wcstombs(char *s, const wchar_t *ws, size_t n) -{ - return wcsrtombs(s, &ws, n, 0); -} diff --git a/05/musl-final/src/multibyte/wctob.c b/05/musl-final/src/multibyte/wctob.c deleted file mode 100644 index d6353ee..0000000 --- a/05/musl-final/src/multibyte/wctob.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include - -int wctob(wint_t c) -{ - if (c < 128U) return c; - return EOF; -} diff --git a/05/musl-final/src/multibyte/wctomb.c b/05/musl-final/src/multibyte/wctomb.c deleted file mode 100644 index 6910ef3..0000000 --- a/05/musl-final/src/multibyte/wctomb.c +++ /dev/null @@ -1,18 +0,0 @@ -/* - * This code was written by Rich Felker in 2010; no copyright is claimed. - * This code is in the public domain. Attribution is appreciated but - * unnecessary. - */ - -#include -#include -#include -#include - -#include "internal.h" - -int wctomb(char *s, wchar_t wc) -{ - if (!s) return 0; - return wcrtomb(s, wc, 0); -} diff --git a/05/musl-final/src/network/__dns.c b/05/musl-final/src/network/__dns.c deleted file mode 100644 index b8547bb..0000000 --- a/05/musl-final/src/network/__dns.c +++ /dev/null @@ -1,267 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "__dns.h" -#include "stdio_impl.h" - -#define TIMEOUT 5 -#define RETRY 1 -#define PACKET_MAX 512 -#define PTR_MAX (64 + sizeof ".in-addr.arpa") - -int __dns_doqueries(unsigned char *dest, const char *name, int *rr, int rrcnt) -{ - time_t t0 = time(0); - int fd; - FILE *f, _f; - unsigned char _buf[64]; - char line[64], *s, *z; - union { - struct sockaddr_in sin; - struct sockaddr_in6 sin6; - } sa = {0}, ns[3] = {{0}}; - socklen_t sl; - int nns; - int family; - unsigned char q[280] = "", *r = dest; - int ql; - int rlen; - int got = 0, failed = 0; - int errcode = EAI_AGAIN; - int i, j; - struct timeval tv; - fd_set fds; - int id; - - /* Construct query template - RR and ID will be filled later */ - if (strlen(name)-1 >= 254U) return -1; - q[2] = q[5] = 1; - strcpy((char *)q+13, name); - for (i=13; q[i]; i=j+1) { - for (j=i; q[j] && q[j] != '.'; j++); - if (j-i-1u > 62u) return -1; - q[i-1] = j-i; - } - q[i+3] = 1; - ql = i+4; - - /* Make a reasonably unpredictable id */ - gettimeofday(&tv, 0); - id = tv.tv_usec + tv.tv_usec/256 & 0xffff; - - /* Get nameservers from resolv.conf, fallback to localhost */ - f = __fopen_rb_ca("/etc/resolv.conf", &_f, _buf, sizeof _buf); - if (f) for (nns=0; nns<3 && fgets(line, sizeof line, f); ) { - if (strncmp(line, "nameserver", 10) || !isspace(line[10])) - continue; - for (s=line+11; isspace(*s); s++); - for (z=s; *z && !isspace(*z); z++); - *z=0; - if (__ipparse(ns+nns, family, s) < 0) continue; - ns[nns].sin.sin_port = htons(53); - family = ns[nns++].sin.sin_family; - sl = family==AF_INET6 ? sizeof sa.sin6 : sizeof sa.sin; - } - if (f) __fclose_ca(f); - if (!nns) { - ns[0].sin.sin_family = AF_INET; - ns[0].sin.sin_port = htons(53); - nns=1; - sl = sizeof sa.sin; - } - - /* Get local address and open/bind a socket */ - sa.sin.sin_family = family; - fd = socket(family, SOCK_DGRAM, 0); - if (bind(fd, (void *)&sa, sl) < 0) { - close(fd); - return -1; - } - /* Nonblocking to work around Linux UDP select bug */ - fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK); - - /* Loop until we timeout; break early on success */ - for (; time(0)-t0 < TIMEOUT; ) { - - /* Query all configured namservers in parallel */ - for (i=0; i> 8; - q[1] = id+i; - q[ql-3] = rr[i]; - sendto(fd, q, ql, MSG_NOSIGNAL, (void *)&ns[j], sl); - } - - /* Wait for a response, or until time to retry */ - FD_ZERO(&fds); - FD_SET(fd, &fds); - tv.tv_sec = RETRY; - tv.tv_usec = 0; - if (select(fd+1, &fds, 0, 0, &tv) <= 0) continue; - - /* Process any and all replies */ - while (got+failed < rrcnt && (rlen = recvfrom(fd, r, 512, 0, - (void *)&sa, (socklen_t[1]){sl})) >= 2) - { - /* Ignore replies from addresses we didn't send to */ - for (i=0; i= rrcnt || !rr[i]) continue; - - /* Interpret the result code */ - switch (r[3] & 15) { - case 0: - got++; - break; - case 3: - if (1) errcode = EAI_NONAME; else - default: - errcode = EAI_FAIL; - failed++; - } - - /* Mark this record as answered */ - rr[i] = 0; - r += 512; - } - - /* Check to see if we have answers to all queries */ - if (got+failed == rrcnt) break; - } - close(fd); - - /* Return the number of results, or an error code if none */ - if (got) return got; - return errcode; -} - -static void mkptr4(char *s, const unsigned char *ip) -{ - sprintf(s, "%d.%d.%d.%d.in-addr.arpa", - ip[3], ip[2], ip[1], ip[0]); -} - -static void mkptr6(char *s, const unsigned char *ip) -{ - static const char xdigits[] = "0123456789abcdef"; - int i; - for (i=15; i>=0; i--) { - *s++ = xdigits[ip[i]&15]; *s++ = '.'; - *s++ = xdigits[ip[i]>>4]; *s++ = '.'; - } - strcpy(s, "ip6.arpa"); -} - -int __dns_query(unsigned char *r, const void *a, int family, int ptr) -{ - char buf[PTR_MAX]; - int rr[2], rrcnt = 1; - - if (ptr) { - if (family == AF_INET6) mkptr6(buf, a); - else mkptr4(buf, a); - rr[0] = RR_PTR; - a = buf; - } else if (family == AF_INET6) { - rr[0] = RR_AAAA; - } else { - rr[0] = RR_A; - if (family != AF_INET) rr[rrcnt++] = RR_AAAA; - } - - return __dns_doqueries(r, a, rr, rrcnt); -} - - -#define BITOP(a,b,op) \ - ((a)[(size_t)(b)/(8*sizeof *(a))] op (size_t)1<<((size_t)(b)%(8*sizeof *(a)))) - -static int decname(char *s, const unsigned char *b, const unsigned char *p) -{ - /* Remember jump destinations to detect loops and abort */ - size_t seen[PACKET_MAX/8/sizeof(size_t)] = { 0 }; - char *sz = s + HOST_NAME_MAX; - const unsigned char *pz = b+512; - for (;;) { - if (p>=pz) return -1; - else if (*p&0xc0) { - int j = (p[0]&1) | p[1]; - if (BITOP(seen, j, &)) return -1; - BITOP(seen, j, |=); - p = b + j; - } else if (*p) { - if (p+*p+1>=pz || s+*p>=sz) return -1; - memcpy(s, p+1, *p); - s += *p+1; - p += *p+1; - s[-1] = *p ? '.' : 0; - } else return 0; - } -} - -int __dns_get_rr(void *dest, size_t stride, size_t maxlen, size_t limit, const unsigned char *r, int rr, int dec) -{ - int qdcount, ancount; - const unsigned char *p; - char tmp[256]; - int found = 0; - int len; - - if ((r[3]&15)) return 0; - p = r+12; - qdcount = r[4]*256 + r[5]; - ancount = r[6]*256 + r[7]; - if (qdcount+ancount > 64) return -1; - while (qdcount--) { - while (p-r < 512 && *p-1U < 127) p++; - if (*p>193 || (*p==193 && p[1]>254) || p>r+506) - return -1; - p += 5 + !!*p; - } - while (ancount--) { - while (p-r < 512 && *p-1U < 127) p++; - if (*p>193 || (*p==193 && p[1]>254) || p>r+506) - return -1; - p += 1 + !!*p; - len = p[8]*256 + p[9]; - if (p+len > r+512) return -1; - if (p[1]==rr && len <= maxlen) { - if (dec && decname(tmp, r, p+10)<0) return -1; - if (dest && limit) { - if (dec) strcpy(dest, tmp); - else memcpy(dest, p+10, len); - dest = (char *)dest + stride; - limit--; - } - found++; - } - p += 10 + len; - } - return found; -} - -int __dns_count_addrs(const unsigned char *r, int cnt) -{ - int found=0, res, i; - static const int p[2][2] = { { 4, RR_A }, { 16, RR_AAAA } }; - - while (cnt--) for (i=0; i<2; i++) { - res = __dns_get_rr(0, 0, p[i][0], -1, r, p[i][1], 0); - if (res < 0) return res; - found += res; - r += 512; - } - return found; -} diff --git a/05/musl-final/src/network/__dns.h b/05/musl-final/src/network/__dns.h deleted file mode 100644 index 9a3f740..0000000 --- a/05/musl-final/src/network/__dns.h +++ /dev/null @@ -1,14 +0,0 @@ -#include - -#define RR_A 1 -#define RR_CNAME 5 -#define RR_PTR 12 -#define RR_AAAA 28 - -int __dns_count_addrs(const unsigned char *, int); -int __dns_get_rr(void *, size_t, size_t, size_t, const unsigned char *, int, int); - -int __dns_query(unsigned char *, const void *, int, int); -int __ipparse(void *, int, const char *); - -int __dns_doqueries(unsigned char *, const char *, int *, int); diff --git a/05/musl-final/src/network/__ipparse.c b/05/musl-final/src/network/__ipparse.c deleted file mode 100644 index ca9e589..0000000 --- a/05/musl-final/src/network/__ipparse.c +++ /dev/null @@ -1,40 +0,0 @@ -#include -#include -#include -#include -#include "__dns.h" -#include - -int __ipparse(void *dest, int family, const char *s) -{ - unsigned char *d = dest; - unsigned long a[16] = { 0 }; - const char *z; - int i; - - if (family == AF_INET6) goto not_v4; - - for (i=0; i<4 && *s; i++) { - a[i] = strtoul(s, (char **)&z, 0); - if (z==s || (*z && *z != '.')) goto not_v4; - s=z+1; - } - switch (i) { - case 0: - a[1] = a[0] & 0xffffff; - a[0] >>= 24; - case 1: - a[2] = a[1] & 0xffff; - a[1] >>= 16; - case 2: - a[3] = a[2] & 0xff; - a[2] >>= 8; - } - ((struct sockaddr_in *)d)->sin_family = AF_INET; - d = (void *)&((struct sockaddr_in *)d)->sin_addr; - for (i=0; i<4; i++) d[i] = a[i]; - return 0; - -not_v4: - return -1; -} diff --git a/05/musl-final/src/network/accept.c b/05/musl-final/src/network/accept.c deleted file mode 100644 index 46adff5..0000000 --- a/05/musl-final/src/network/accept.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -int accept(int fd, struct sockaddr *addr, socklen_t *len) -{ - int ret; - CANCELPT_BEGIN; - ret = socketcall(accept, fd, addr, len, 0, 0, 0); - CANCELPT_END; - return ret; -} diff --git a/05/musl-final/src/network/bind.c b/05/musl-final/src/network/bind.c deleted file mode 100644 index 07bb669..0000000 --- a/05/musl-final/src/network/bind.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int bind(int fd, const struct sockaddr *addr, socklen_t len) -{ - return socketcall(bind, fd, addr, len, 0, 0, 0); -} diff --git a/05/musl-final/src/network/connect.c b/05/musl-final/src/network/connect.c deleted file mode 100644 index 29bffbc..0000000 --- a/05/musl-final/src/network/connect.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -int connect(int fd, const struct sockaddr *addr, socklen_t len) -{ - int ret; - CANCELPT_BEGIN; - ret = socketcall(connect, fd, addr, len, 0, 0, 0); - CANCELPT_END; - return ret; -} diff --git a/05/musl-final/src/network/dn_expand.c b/05/musl-final/src/network/dn_expand.c deleted file mode 100644 index 01b449b..0000000 --- a/05/musl-final/src/network/dn_expand.c +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include - -#define BITOP(a,b,op) \ - ((a)[(size_t)(b)/(8*sizeof *(a))] op (size_t)1<<((size_t)(b)%(8*sizeof *(a)))) - -int dn_expand(unsigned char *b, unsigned char *pz, unsigned char *p, unsigned char *s, int outlen) -{ - /* Remember jump destinations to detect loops and abort */ - size_t seen[512/8/sizeof(size_t)] = { 0 }; - unsigned char *sz = s + outlen; - if (pz-b > 512) return -1; - for (;;) { - if (p>=pz) return -1; - else if (*p&0xc0) { - int j = (p[0]&1) | p[1]; - if (BITOP(seen, j, &)) return -1; - BITOP(seen, j, |=); - p = b + j; - } else if (*p) { - if (p+*p+1>=pz || s+*p>=sz) return -1; - memcpy(s, p+1, *p); - s += *p+1; - p += *p+1; - s[-1] = *p ? '.' : 0; - } else return 0; - } -} diff --git a/05/musl-final/src/network/ent.c b/05/musl-final/src/network/ent.c deleted file mode 100644 index 4c2f24b..0000000 --- a/05/musl-final/src/network/ent.c +++ /dev/null @@ -1,26 +0,0 @@ -#include "libc.h" - -void sethostent(int x) -{ -} - -void *gethostent() -{ - return 0; -} - -void endhostent(void) -{ -} - -weak_alias(sethostent, setnetent); -weak_alias(gethostent, getnetent); -weak_alias(endhostent, endnetent); - -weak_alias(sethostent, setservent); -weak_alias(gethostent, getservent); -weak_alias(endhostent, endservent); - -weak_alias(sethostent, setprotoent); -weak_alias(gethostent, getprotoent); -weak_alias(endhostent, endprotoent); diff --git a/05/musl-final/src/network/freeaddrinfo.c b/05/musl-final/src/network/freeaddrinfo.c deleted file mode 100644 index df3798a..0000000 --- a/05/musl-final/src/network/freeaddrinfo.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include - -void freeaddrinfo(struct addrinfo *p) -{ - free(p); -} diff --git a/05/musl-final/src/network/gai_strerror.c b/05/musl-final/src/network/gai_strerror.c deleted file mode 100644 index ea00bed..0000000 --- a/05/musl-final/src/network/gai_strerror.c +++ /dev/null @@ -1,21 +0,0 @@ -#include - -static const char msgs[] = - "Invalid flags\0" - "Name does not resolve\0" - "Try again\0" - "Non-recoverable error\0" - "Unrecognized address family or invalid length\0" - "Unrecognized socket type\0" - "Unrecognized service\0" - "Out of memory\0" - "System error\0" - "Overflow\0" - "\0Unknown error"; - -const char *gai_strerror(int ecode) -{ - const char *s; - for (s=msgs, ecode++; ecode && *s; ecode++, s++) for (; *s; s++); - return *s ? s : s+1; -} diff --git a/05/musl-final/src/network/getaddrinfo.c b/05/musl-final/src/network/getaddrinfo.c deleted file mode 100644 index 90e85f6..0000000 --- a/05/musl-final/src/network/getaddrinfo.c +++ /dev/null @@ -1,224 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include "__dns.h" -#include "stdio_impl.h" - -static int is_valid(const char *host) -{ - const unsigned char *s; - if (strlen(host)-1 > 254 || mbstowcs(0, host, 0) > 255) return 0; - for (s=host; *s>=0x80 || *s=='.' || *s=='-' || isalnum(*s); s++); - return !*s; -} - -#if 0 -static int have_af(int family) -{ - struct sockaddr_in6 sin6 = { .sin6_family = family }; - socklen_t sl = family == AF_INET - ? sizeof(struct sockaddr_in) - : sizeof(struct sockaddr_in6); - int sock = socket(family, SOCK_STREAM, 0); - int have = !bind(sock, (void *)&sin6, sl); - close(sock); - return have; -} -#endif - -#include -#include - -union sa { - struct sockaddr_in sin; - struct sockaddr_in6 sin6; -}; - -struct aibuf { - struct addrinfo ai; - union sa sa; -}; - -/* Extra slots needed for storing canonical name */ -#define EXTRA ((256+sizeof(struct aibuf)-1)/sizeof(struct aibuf)) - -int getaddrinfo(const char *host, const char *serv, const struct addrinfo *hint, struct addrinfo **res) -{ - int flags = hint ? hint->ai_flags : 0; - int family = hint ? hint->ai_family : AF_UNSPEC; - int type = hint ? hint->ai_socktype : 0; - int proto = hint ? hint->ai_protocol : 0; - unsigned long port = 0; - struct aibuf *buf; - union sa sa = {{0}}; - unsigned char reply[1024]; - int i, j; - //char hostbuf[256]; - char line[512]; - FILE *f, _f; - unsigned char _buf[64]; - char *z; - int result; - int cnt; - - if (host && strlen(host)>255) return EAI_NONAME; - if (serv && strlen(serv)>32) return EAI_SERVICE; - - if (type && !proto) - proto = type==SOCK_DGRAM ? IPPROTO_UDP : IPPROTO_TCP; - if (!type && proto) - type = proto==IPPROTO_UDP ? SOCK_DGRAM : SOCK_STREAM; - - if (serv) { - port = strtoul(serv, &z, 0); - if (!*z && port > 65535) return EAI_SERVICE; - if (!port) { - if (flags & AI_NUMERICSERV) return EAI_SERVICE; - - //f = fopen("/etc/services", "rb"); - return EAI_SERVICE; - } - port = htons(port); - } - - if (!host) { - if (family == AF_UNSPEC) family = AF_INET; - buf = calloc(sizeof *buf, 1+EXTRA); - if (!buf) return EAI_MEMORY; - buf->ai.ai_protocol = proto; - buf->ai.ai_socktype = type; - buf->ai.ai_addr = (void *)&buf->sa; - buf->ai.ai_addrlen = family==AF_INET6 ? sizeof sa.sin6 : sizeof sa.sin; - buf->ai.ai_family = family; - buf->sa.sin.sin_family = family; - buf->sa.sin.sin_port = port; - if (!(flags & AI_PASSIVE)) { - if (family == AF_INET) { - 0[(uint8_t*)&buf->sa.sin.sin_addr.s_addr]=127; - 3[(uint8_t*)&buf->sa.sin.sin_addr.s_addr]=1; - } else buf[0].sa.sin6.sin6_addr.s6_addr[15] = 1; - } - *res = &buf->ai; - return 0; - } - - /* Try as a numeric address */ - if (__ipparse(&sa, family, host) >= 0) { - buf = calloc(sizeof *buf, 1+EXTRA); - if (!buf) return EAI_MEMORY; - family = sa.sin.sin_family; - buf->ai.ai_protocol = proto; - buf->ai.ai_socktype = type; - buf->ai.ai_addr = (void *)&buf->sa; - buf->ai.ai_addrlen = family==AF_INET6 ? sizeof sa.sin6 : sizeof sa.sin; - buf->ai.ai_family = family; - buf->sa = sa; - buf->sa.sin.sin_port = port; - *res = &buf->ai; - return 0; - } - - if (flags & AI_NUMERICHOST) return EAI_NONAME; - - f = __fopen_rb_ca("/etc/hosts", &_f, _buf, sizeof _buf); - if (f) while (fgets(line, sizeof line, f)) { - char *p; - size_t l = strlen(host); - - if ((p=strchr(line, '#'))) *p++='\n', *p=0; - for(p=line+1; (p=strstr(p, host)) && - (!isspace(p[-1]) || !isspace(p[l])); p++); - if (!p) continue; - __fclose_ca(f); - - /* Isolate IP address to parse */ - for (p=line; *p && !isspace(*p); p++); - *p++ = 0; - if (__ipparse(&sa, family, line) < 0) return EAI_NONAME; - - /* Allocate and fill result buffer */ - buf = calloc(sizeof *buf, 1+EXTRA); - if (!buf) return EAI_MEMORY; - family = sa.sin.sin_family; - buf->ai.ai_protocol = proto; - buf->ai.ai_socktype = type; - buf->ai.ai_addr = (void *)&buf->sa; - buf->ai.ai_addrlen = family==AF_INET6 ? sizeof sa.sin6 : sizeof sa.sin; - buf->ai.ai_family = family; - buf->sa = sa; - buf->sa.sin.sin_port = port; - - /* Extract first name as canonical name */ - for (; *p && isspace(*p); p++); - buf->ai.ai_canonname = (void *)(buf+1); - snprintf(buf->ai.ai_canonname, 256, "%s", p); - for (p=buf->ai.ai_canonname; *p && !isspace(*p); p++); - *p = 0; - if (!is_valid(buf->ai.ai_canonname)) - buf->ai.ai_canonname = 0; - - *res = &buf->ai; - return 0; - } - if (f) __fclose_ca(f); - -#if 0 - f = __fopen_rb_ca("/etc/resolv.conf", &_f, _buf, sizeof _buf); - if (f) while (fgets(line, sizeof line, f)) { - if (!isspace(line[10]) || (strncmp(line, "search", 6) - && strncmp(line, "domain", 6))) continue; - } - if (f) __fclose_ca(f); -#endif - - /* Perform one or more DNS queries for host */ - memset(reply, 0, sizeof reply); - result = __dns_query(reply, host, family, 0); - if (result < 0) return result; - - cnt = __dns_count_addrs(reply, result); - if (cnt <= 0) return EAI_NONAME; - - buf = calloc(sizeof *buf, cnt+EXTRA); - if (!buf) return EAI_MEMORY; - - i = 0; - if (family != AF_INET6) { - j = __dns_get_rr(&buf[i].sa.sin.sin_addr, sizeof *buf, 4, cnt-i, reply, RR_A, 0); - while (j--) buf[i++].sa.sin.sin_family = AF_INET; - } - if (family != AF_INET) { - j = __dns_get_rr(&buf[i].sa.sin6.sin6_addr, sizeof *buf, 16, cnt-i, reply, RR_AAAA, 0); - while (j--) buf[i++].sa.sin.sin_family = AF_INET6; - } - if (result>1) { - j = __dns_get_rr(&buf[i].sa.sin.sin_addr, sizeof *buf, 4, cnt-i, reply+512, RR_A, 0); - while (j--) buf[i++].sa.sin.sin_family = AF_INET; - j = __dns_get_rr(&buf[i].sa.sin6.sin6_addr, sizeof *buf, 16, cnt-i, reply+512, RR_AAAA, 0); - while (j--) buf[i++].sa.sin.sin_family = AF_INET6; - } - - if (__dns_get_rr((void *)&buf[cnt], 0, 256, 1, reply, RR_CNAME, 1) < 0) - strcpy((void *)&buf[cnt], host); - - for (i=0; iai; - - return 0; -} diff --git a/05/musl-final/src/network/gethostbyaddr.c b/05/musl-final/src/network/gethostbyaddr.c deleted file mode 100644 index 51e1c56..0000000 --- a/05/musl-final/src/network/gethostbyaddr.c +++ /dev/null @@ -1,15 +0,0 @@ -#define _GNU_SOURCE - -#include -#include -#include - -struct hostent *gethostbyaddr(const void *a, socklen_t l, int af) -{ - static struct hostent h; - static long buf[512/sizeof(long)]; - struct hostent *res; - if (gethostbyaddr_r(a, l, af, &h, - (void *)buf, sizeof buf, &res, &h_errno)) return 0; - return &h; -} diff --git a/05/musl-final/src/network/gethostbyaddr_r.c b/05/musl-final/src/network/gethostbyaddr_r.c deleted file mode 100644 index cdb1d50..0000000 --- a/05/musl-final/src/network/gethostbyaddr_r.c +++ /dev/null @@ -1,71 +0,0 @@ -#define _GNU_SOURCE - -#include -#include -#include -#include -#include -#include - -int gethostbyaddr_r(const void *a, socklen_t l, int af, - struct hostent *h, char *buf, size_t buflen, - struct hostent **res, int *err) -{ - union { - struct sockaddr_in sin; - struct sockaddr_in6 sin6; - } sa = { .sin.sin_family = af }; - socklen_t sl = af==AF_INET6 ? sizeof sa.sin6 : sizeof sa.sin; - int i; - - /* Load address argument into sockaddr structure */ - if (af==AF_INET6 && l==16) memcpy(&sa.sin6.sin6_addr, a, 16); - else if (af==AF_INET && l==4) memcpy(&sa.sin.sin_addr, a, 4); - else { - *err = NO_RECOVERY; - return -1; - } - - /* Align buffer and check for space for pointers and ip address */ - i = (uintptr_t)buf & sizeof(char *)-1; - if (!i) i = sizeof(char *); - if (buflen <= 5*sizeof(char *)-i + l) { - errno = ERANGE; - return -1; - } - buf += sizeof(char *)-i; - buflen -= 5*sizeof(char *)-i + l; - - h->h_addr_list = (void *)buf; - buf += 2*sizeof(char *); - h->h_aliases = (void *)buf; - buf += 2*sizeof(char *); - - h->h_addr_list[0] = buf; - memcpy(h->h_addr_list[0], a, l); - buf += l; - h->h_addr_list[1] = 0; - h->h_aliases[0] = buf; - h->h_aliases[1] = 0; - - switch (getnameinfo((void *)&sa, sl, buf, buflen, 0, 0, 0)) { - case EAI_AGAIN: - *err = TRY_AGAIN; - return -1; - case EAI_OVERFLOW: - errno = ERANGE; - default: - case EAI_MEMORY: - case EAI_SYSTEM: - case EAI_FAIL: - *err = NO_RECOVERY; - return -1; - case 0: - break; - } - - h->h_addrtype = af; - h->h_name = h->h_aliases[0]; - *res = h; - return 0; -} diff --git a/05/musl-final/src/network/gethostbyname.c b/05/musl-final/src/network/gethostbyname.c deleted file mode 100644 index 5088a51..0000000 --- a/05/musl-final/src/network/gethostbyname.c +++ /dev/null @@ -1,63 +0,0 @@ -#define _GNU_SOURCE - -#include -#include -#include -#include - -struct hostent *gethostbyname(const char *name) -{ - return gethostbyname2(name, AF_INET); -} - -#if 0 -struct hostent *gethostbyname(const char *name) -{ - static struct hostent h; - static char *h_aliases[3]; - static char h_canon[256]; - static char *h_addr_list[10]; - static char h_addr_data[10][4]; - static const struct addrinfo hint = { - .ai_family = AF_INET, .ai_flags = AI_CANONNAME - }; - struct addrinfo *ai, *p; - int i; - - switch (getaddrinfo(name, 0, &hint, &ai)) { - case EAI_NONAME: - h_errno = HOST_NOT_FOUND; - break; - case EAI_AGAIN: - h_errno = TRY_AGAIN; - break; - case EAI_FAIL: - h_errno = NO_RECOVERY; - break; - default: - case EAI_MEMORY: - case EAI_SYSTEM: - h_errno = NO_DATA; - break; - case 0: - break; - } - - strcpy(h_canon, ai->ai_canonname); - h.h_name = h_canon; - h.h_aliases = h_aliases; - h.h_aliases[0] = h_canon; - h.h_aliases[1] = strcmp(h_canon, name) ? (char *)name : 0; - h.h_length = 4; - h.h_addr_list = h_addr_list; - for (i=0, p=ai; iai_next) { - h.h_addr_list[i] = h_addr_data[i]; - memcpy(h.h_addr_list[i], - &((struct sockaddr_in *)p->ai_addr)->sin_addr, 4); - } - h.h_addr_list[i] = 0; - h.h_addrtype = AF_INET; - freeaddrinfo(ai); - return &h; -} -#endif diff --git a/05/musl-final/src/network/gethostbyname2.c b/05/musl-final/src/network/gethostbyname2.c deleted file mode 100644 index 9fbe264..0000000 --- a/05/musl-final/src/network/gethostbyname2.c +++ /dev/null @@ -1,16 +0,0 @@ -#define _GNU_SOURCE - -#include -#include -#include -#include - -struct hostent *gethostbyname2(const char *name, int af) -{ - static struct hostent h; - static long buf[512/sizeof(long)]; - struct hostent *res; - if (gethostbyname2_r(name, af, &h, - (void *)buf, sizeof buf, &res, &h_errno)) return 0; - return &h; -} diff --git a/05/musl-final/src/network/gethostbyname2_r.c b/05/musl-final/src/network/gethostbyname2_r.c deleted file mode 100644 index c2ed75b..0000000 --- a/05/musl-final/src/network/gethostbyname2_r.c +++ /dev/null @@ -1,99 +0,0 @@ -#define _GNU_SOURCE - -#include -#include -#include -#include -#include -#include - -int gethostbyname2_r(const char *name, int af, - struct hostent *h, char *buf, size_t buflen, - struct hostent **res, int *err) -{ - struct addrinfo hint = { - .ai_family = af==AF_INET6 ? af : AF_INET, - .ai_flags = AI_CANONNAME - }; - struct addrinfo *ai, *p; - int i; - size_t need; - const char *canon; - - af = hint.ai_family; - - /* Align buffer */ - i = (uintptr_t)buf & sizeof(char *)-1; - if (i) { - if (buflen < sizeof(char *)-i) { - errno = ERANGE; - return -1; - } - buf += sizeof(char *)-i; - buflen -= sizeof(char *)-i; - } - - getaddrinfo(name, 0, &hint, &ai); - switch (getaddrinfo(name, 0, &hint, &ai)) { - case EAI_NONAME: - *err = HOST_NOT_FOUND; - return -1; - case EAI_AGAIN: - *err = TRY_AGAIN; - return -1; - default: - case EAI_MEMORY: - case EAI_SYSTEM: - case EAI_FAIL: - *err = NO_RECOVERY; - return -1; - case 0: - break; - } - - h->h_addrtype = af; - h->h_length = af==AF_INET6 ? 16 : 4; - - canon = ai->ai_canonname ? ai->ai_canonname : name; - need = 4*sizeof(char *); - for (i=0, p=ai; p; i++, p=p->ai_next) - need += sizeof(char *) + h->h_length; - need += strlen(name)+1; - need += strlen(canon)+1; - - if (need > buflen) { - freeaddrinfo(ai); - errno = ERANGE; - return -1; - } - - h->h_aliases = (void *)buf; - buf += 3*sizeof(char *); - h->h_addr_list = (void *)buf; - buf += (i+1)*sizeof(char *); - - h->h_name = h->h_aliases[0] = buf; - strcpy(h->h_name, canon); - buf += strlen(h->h_name)+1; - - if (strcmp(h->h_name, name)) { - h->h_aliases[1] = buf; - strcpy(h->h_aliases[1], name); - buf += strlen(h->h_aliases[1])+1; - } else h->h_aliases[1] = 0; - - h->h_aliases[2] = 0; - - for (i=0, p=ai; p; i++, p=p->ai_next) { - h->h_addr_list[i] = (void *)buf; - buf += h->h_length; - memcpy(h->h_addr_list[i], - &((struct sockaddr_in *)p->ai_addr)->sin_addr, - h->h_length); - } - h->h_addr_list[i] = 0; - - *res = h; - freeaddrinfo(ai); - return 0; -} diff --git a/05/musl-final/src/network/gethostbyname_r.c b/05/musl-final/src/network/gethostbyname_r.c deleted file mode 100644 index cd87254..0000000 --- a/05/musl-final/src/network/gethostbyname_r.c +++ /dev/null @@ -1,11 +0,0 @@ -#define _GNU_SOURCE - -#include -#include - -int gethostbyname_r(const char *name, - struct hostent *h, char *buf, size_t buflen, - struct hostent **res, int *err) -{ - return gethostbyname2_r(name, AF_INET, h, buf, buflen, res, err); -} diff --git a/05/musl-final/src/network/getnameinfo.c b/05/musl-final/src/network/getnameinfo.c deleted file mode 100644 index 0763ca8..0000000 --- a/05/musl-final/src/network/getnameinfo.c +++ /dev/null @@ -1,54 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include "__dns.h" - -int getnameinfo(const struct sockaddr *sa, socklen_t sl, - char *node, socklen_t nodelen, - char *serv, socklen_t servlen, - int flags) -{ - char buf[256]; - unsigned char reply[512]; - int af = sa->sa_family; - unsigned char *a; - - switch (af) { - case AF_INET: - a = (void *)&((struct sockaddr_in *)sa)->sin_addr; - if (sl != sizeof(struct sockaddr_in)) return EAI_FAMILY; - break; - case AF_INET6: - a = (void *)&((struct sockaddr_in6 *)sa)->sin6_addr; - if (sl != sizeof(struct sockaddr_in6)) return EAI_FAMILY; - break; - default: - return EAI_FAMILY; - } - - if (node && nodelen) { - if ((flags & NI_NUMERICHOST) - || __dns_query(reply, a, af, 1) <= 0 - || __dns_get_rr(buf, 0, 256, 1, reply, RR_PTR, 1) <= 0) - { - if (flags & NI_NAMEREQD) return EAI_NONAME; - inet_ntop(af, a, buf, sizeof buf); - } - if (strlen(buf) >= nodelen) return EAI_OVERFLOW; - strcpy(node, buf); - } - - if (serv && servlen) { - if (snprintf(buf, sizeof buf, "%d", - ntohs(((struct sockaddr_in *)sa)->sin_port))>=servlen) - return EAI_OVERFLOW; - strcpy(serv, buf); - } - - return 0; -} diff --git a/05/musl-final/src/network/getpeername.c b/05/musl-final/src/network/getpeername.c deleted file mode 100644 index 22effda..0000000 --- a/05/musl-final/src/network/getpeername.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int getpeername(int fd, struct sockaddr *addr, socklen_t *len) -{ - return socketcall(getpeername, fd, addr, len, 0, 0, 0); -} diff --git a/05/musl-final/src/network/getservbyname.c b/05/musl-final/src/network/getservbyname.c deleted file mode 100644 index 0b00ce1..0000000 --- a/05/musl-final/src/network/getservbyname.c +++ /dev/null @@ -1,12 +0,0 @@ -#define _GNU_SOURCE -#include - -struct servent *getservbyname(const char *name, const char *prots) -{ - static struct servent se; - static long buf[32/sizeof(long)]; - struct servent *res; - if (getservbyname_r(name, prots, &se, (void *)buf, sizeof buf, &res)) - return 0; - return &se; -} diff --git a/05/musl-final/src/network/getservbyname_r.c b/05/musl-final/src/network/getservbyname_r.c deleted file mode 100644 index 5c02515..0000000 --- a/05/musl-final/src/network/getservbyname_r.c +++ /dev/null @@ -1,41 +0,0 @@ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include - -int getservbyname_r(const char *name, const char *prots, - struct servent *se, char *buf, size_t buflen, struct servent **res) -{ - struct addrinfo *ai, hint = { .ai_family = AF_INET }; - int i; - - /* Align buffer */ - i = (uintptr_t)buf & sizeof(char *)-1; - if (!i) i = sizeof(char *); - if (buflen < 3*sizeof(char *)-i) { - errno = ERANGE; - return -1; - } - buf += sizeof(char *)-i; - buflen -= sizeof(char *)-i; - - if (!strcmp(prots, "tcp")) hint.ai_protocol = IPPROTO_TCP; - else if (!strcmp(prots, "udp")) hint.ai_protocol = IPPROTO_UDP; - else return -1; - - if (getaddrinfo(0, name, &hint, &ai) < 0) return -1; - - se->s_name = (char *)name; - se->s_aliases = (void *)buf; - se->s_aliases[0] = se->s_name; - se->s_aliases[1] = 0; - se->s_port = ((struct sockaddr_in *)ai->ai_addr)->sin_port; - se->s_proto = (char *)prots; - - freeaddrinfo(ai); - *res = se; - return 0; -} diff --git a/05/musl-final/src/network/getservbyport.c b/05/musl-final/src/network/getservbyport.c deleted file mode 100644 index c9ecbb1..0000000 --- a/05/musl-final/src/network/getservbyport.c +++ /dev/null @@ -1,12 +0,0 @@ -#define _GNU_SOURCE -#include - -struct servent *getservbyport(int port, const char *prots) -{ - static struct servent se; - static long buf[32/sizeof(long)]; - struct servent *res; - if (getservbyport_r(port, prots, &se, (void *)buf, sizeof buf, &res)) - return 0; - return &se; -} diff --git a/05/musl-final/src/network/getservbyport_r.c b/05/musl-final/src/network/getservbyport_r.c deleted file mode 100644 index 004a616..0000000 --- a/05/musl-final/src/network/getservbyport_r.c +++ /dev/null @@ -1,43 +0,0 @@ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include - -int getservbyport_r(int port, const char *prots, - struct servent *se, char *buf, size_t buflen, struct servent **res) -{ - int i; - struct sockaddr_in sin = { - .sin_family = AF_INET, - .sin_port = port, - }; - - /* Align buffer */ - i = (uintptr_t)buf & sizeof(char *)-1; - if (!i) i = sizeof(char *); - if (buflen < 3*sizeof(char *)-i) { - errno = ERANGE; - return -1; - } - buf += sizeof(char *)-i; - buflen -= sizeof(char *)-i; - - if (strcmp(prots, "tcp") && strcmp(prots, "udp")) return -1; - - se->s_port = port; - se->s_proto = (char *)prots; - se->s_aliases = (void *)buf; - buf += 2*sizeof(char *); - buflen -= 2*sizeof(char *); - se->s_aliases[1] = 0; - se->s_aliases[0] = se->s_name = buf; - - if (getnameinfo((void *)&sin, sizeof sin, 0, 0, buf, buflen, - strcmp(prots, "udp") ? 0 : NI_DGRAM) < 0) return -1; - - *res = se; - return 0; -} diff --git a/05/musl-final/src/network/getsockname.c b/05/musl-final/src/network/getsockname.c deleted file mode 100644 index 271e3b4..0000000 --- a/05/musl-final/src/network/getsockname.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int getsockname(int fd, struct sockaddr *addr, socklen_t *len) -{ - return socketcall(getsockname, fd, addr, len, 0, 0, 0); -} diff --git a/05/musl-final/src/network/getsockopt.c b/05/musl-final/src/network/getsockopt.c deleted file mode 100644 index a9e0a72..0000000 --- a/05/musl-final/src/network/getsockopt.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int getsockopt(int fd, int level, int optname, void *optval, socklen_t *optlen) -{ - return socketcall(getsockopt, fd, level, optname, optval, optlen, 0); -} diff --git a/05/musl-final/src/network/h_errno.c b/05/musl-final/src/network/h_errno.c deleted file mode 100644 index 73ead04..0000000 --- a/05/musl-final/src/network/h_errno.c +++ /dev/null @@ -1 +0,0 @@ -int h_errno; diff --git a/05/musl-final/src/network/hstrerror.c b/05/musl-final/src/network/hstrerror.c deleted file mode 100644 index b7a6ab6..0000000 --- a/05/musl-final/src/network/hstrerror.c +++ /dev/null @@ -1,16 +0,0 @@ -#define _GNU_SOURCE -#include - -static const char msgs[] = - "Host not found\0" - "Try again\0" - "Non-recoverable error\0" - "Address not available\0" - "\0Unknown error"; - -const char *hstrerror(int ecode) -{ - const char *s; - for (s=msgs, ecode--; ecode && *s; ecode--, s++) for (; *s; s++); - return *s ? s : s+1; -} diff --git a/05/musl-final/src/network/htonl.c b/05/musl-final/src/network/htonl.c deleted file mode 100644 index b21dace..0000000 --- a/05/musl-final/src/network/htonl.c +++ /dev/null @@ -1,10 +0,0 @@ -#include - -uint32_t htonl(uint32_t n) -{ - union { - uint8_t b[4]; - uint32_t i; - } u = { { n>>24, n>>16, n>>8, n } }; - return u.i; -} diff --git a/05/musl-final/src/network/htons.c b/05/musl-final/src/network/htons.c deleted file mode 100644 index 522504a..0000000 --- a/05/musl-final/src/network/htons.c +++ /dev/null @@ -1,10 +0,0 @@ -#include - -uint16_t htons(uint16_t n) -{ - union { - uint8_t b[2]; - uint16_t s; - } u = { { n>>8, n } }; - return u.s; -} diff --git a/05/musl-final/src/network/in6addr_any.c b/05/musl-final/src/network/in6addr_any.c deleted file mode 100644 index 995387f..0000000 --- a/05/musl-final/src/network/in6addr_any.c +++ /dev/null @@ -1,3 +0,0 @@ -#include - -const struct in6_addr in6addr_any = IN6ADDR_ANY_INIT; diff --git a/05/musl-final/src/network/in6addr_loopback.c b/05/musl-final/src/network/in6addr_loopback.c deleted file mode 100644 index b96005b..0000000 --- a/05/musl-final/src/network/in6addr_loopback.c +++ /dev/null @@ -1,3 +0,0 @@ -#include - -const struct in6_addr in6addr_loopback = IN6ADDR_LOOPBACK_INIT; diff --git a/05/musl-final/src/network/inet_addr.c b/05/musl-final/src/network/inet_addr.c deleted file mode 100644 index 8413728..0000000 --- a/05/musl-final/src/network/inet_addr.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include -#include -#include "__dns.h" - -in_addr_t inet_addr(const char *p) -{ - struct sockaddr_in sin; - if (__ipparse(&sin, AF_INET, p)) return -1; - return sin.sin_addr.s_addr; -} diff --git a/05/musl-final/src/network/inet_aton.c b/05/musl-final/src/network/inet_aton.c deleted file mode 100644 index ea4ee16..0000000 --- a/05/musl-final/src/network/inet_aton.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include - -int inet_aton(const char *cp, struct in_addr *inp) -{ - return inet_pton(AF_INET, cp, (void *)inp) > 0; -} diff --git a/05/musl-final/src/network/inet_ntoa.c b/05/musl-final/src/network/inet_ntoa.c deleted file mode 100644 index 71411e0..0000000 --- a/05/musl-final/src/network/inet_ntoa.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include - -char *inet_ntoa(struct in_addr in) -{ - static char buf[16]; - unsigned char *a = (void *)∈ - snprintf(buf, sizeof buf, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]); - return buf; -} diff --git a/05/musl-final/src/network/inet_ntop.c b/05/musl-final/src/network/inet_ntop.c deleted file mode 100644 index 3e8a6db..0000000 --- a/05/musl-final/src/network/inet_ntop.c +++ /dev/null @@ -1,48 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -const char *inet_ntop(int af, const void *a0, char *s, socklen_t l) -{ - const unsigned char *a = a0; - int i, j, max, best; - char buf[100]; - - switch (af) { - case AF_INET: - if (snprintf(s, l, "%d.%d.%d.%d", a[0],a[1],a[2],a[3]) < l) - return s; - break; - case AF_INET6: - memset(buf, 'x', sizeof buf); - buf[sizeof buf-1]=0; - snprintf(buf, sizeof buf, - "%.0x%x:%.0x%x:%.0x%x:%.0x%x:%.0x%x:%.0x%x:%.0x%x:%.0x%x", - a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7], - a[8],a[9],a[10],a[11],a[12],a[13],a[14],a[15]); - /* Replace longest /(^0|:)[:0]{2,}/ with "::" */ - for (i=best=0, max=2; buf[i]; i++) { - if (i && buf[i] != ':') continue; - j = strspn(buf+i, ":0"); - if (j>max) best=i, max=j; - } - if (max>2) { - buf[best] = buf[best+1] = ':'; - strcpy(buf+best+2, buf+best+max); - } - if (strlen(buf) < l) { - strcpy(s, buf); - return s; - } - break; - default: - errno = EAFNOSUPPORT; - return 0; - } - errno = ENOSPC; - return 0; -} diff --git a/05/musl-final/src/network/inet_pton.c b/05/musl-final/src/network/inet_pton.c deleted file mode 100644 index 349c402..0000000 --- a/05/musl-final/src/network/inet_pton.c +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include "__dns.h" - -int inet_pton(int af, const char *s, void *a0) -{ - unsigned char *a = a0; - const char *z; - unsigned long x; - int i; - - /* Reimplement this because inet_pton cannot accept special v4 forms */ - if (af==AF_INET) { - for (i=0; i<4 && *s; i++) { - a[i] = x = strtoul(s, (char **)&z, 10); - if (!isdigit(*s) || z==s || (*z && *z != '.') || x>255) - return 0; - s=z+1; - } - return 0; - } else if (af==AF_INET6) { - return !__ipparse(a, AF_INET6, s); - } - - errno = EAFNOSUPPORT; - return 0; -} diff --git a/05/musl-final/src/network/listen.c b/05/musl-final/src/network/listen.c deleted file mode 100644 index f84ad03..0000000 --- a/05/musl-final/src/network/listen.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int listen(int fd, int backlog) -{ - return socketcall(listen, fd, backlog, 0, 0, 0, 0); -} diff --git a/05/musl-final/src/network/ntohl.c b/05/musl-final/src/network/ntohl.c deleted file mode 100644 index 6437919..0000000 --- a/05/musl-final/src/network/ntohl.c +++ /dev/null @@ -1,10 +0,0 @@ -#include - -uint32_t ntohl(uint32_t n) -{ - union { - uint32_t i; - uint8_t b[4]; - } u = { n }; - return (u.b[0]<<24) | (u.b[1]<<16) | (u.b[2]<<8) | u.b[3]; -} diff --git a/05/musl-final/src/network/ntohs.c b/05/musl-final/src/network/ntohs.c deleted file mode 100644 index 3544a47..0000000 --- a/05/musl-final/src/network/ntohs.c +++ /dev/null @@ -1,10 +0,0 @@ -#include - -uint16_t ntohs(uint16_t n) -{ - union { - uint16_t s; - uint8_t b[2]; - } u = { n }; - return (u.b[0]<<8) | u.b[1]; -} diff --git a/05/musl-final/src/network/proto.c b/05/musl-final/src/network/proto.c deleted file mode 100644 index 8c25c53..0000000 --- a/05/musl-final/src/network/proto.c +++ /dev/null @@ -1,58 +0,0 @@ -#include -#include -#include - -/* do we really need all these?? */ - -static int idx; -static const unsigned char protos[][6] = { - "\000ip", - "\001icmp", - "\002igmp", - "\003ggp", - "\006tcp", - "\014pup", - "\021udp", - "\026idp", - "\377raw" - "\0\0" -}; - -void endprotoent(void) -{ - idx = 0; -} - -void setprotoent(int stayopen) -{ - idx = 0; -} - -struct protoent *getprotoent(void) -{ - static struct protoent p; - static const char *aliases; - if (!protos[idx][1]) return NULL; - p.p_proto = protos[idx][0]; - p.p_name = (char *)protos[idx++]+1; - p.p_aliases = (char **)&aliases; - return &p; -} - -struct protoent *getprotobyname(const char *name) -{ - struct protoent *p; - endprotoent(); - do p = getprotoent(); - while (p && strcmp(name, p->p_name)); - return p; -} - -struct protoent *getprotobynumber(int num) -{ - struct protoent *p; - endprotoent(); - do p = getprotoent(); - while (p && p->p_proto != num); - return p; -} diff --git a/05/musl-final/src/network/recv.c b/05/musl-final/src/network/recv.c deleted file mode 100644 index d04a54a..0000000 --- a/05/musl-final/src/network/recv.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -ssize_t recv(int fd, void *buf, size_t len, int flags) -{ - return recvfrom(fd, buf, len, flags, 0, 0); -} diff --git a/05/musl-final/src/network/recvfrom.c b/05/musl-final/src/network/recvfrom.c deleted file mode 100644 index d522293..0000000 --- a/05/musl-final/src/network/recvfrom.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -ssize_t recvfrom(int fd, void *buf, size_t len, int flags, struct sockaddr *addr, socklen_t *alen) -{ - ssize_t r; - CANCELPT_BEGIN; - r = socketcall(recvfrom, fd, buf, len, flags, addr, alen); - CANCELPT_END; - return r; -} diff --git a/05/musl-final/src/network/recvmsg.c b/05/musl-final/src/network/recvmsg.c deleted file mode 100644 index edc5f24..0000000 --- a/05/musl-final/src/network/recvmsg.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -ssize_t recvmsg(int fd, struct msghdr *msg, int flags) -{ - ssize_t r; - CANCELPT_BEGIN; - r = socketcall(recvmsg, fd, msg, flags, 0, 0, 0); - CANCELPT_END; - return r; -} diff --git a/05/musl-final/src/network/res_init.c b/05/musl-final/src/network/res_init.c deleted file mode 100644 index cbd5b15..0000000 --- a/05/musl-final/src/network/res_init.c +++ /dev/null @@ -1,4 +0,0 @@ -int res_init() -{ - return 0; -} diff --git a/05/musl-final/src/network/res_query.c b/05/musl-final/src/network/res_query.c deleted file mode 100644 index 4ebeb10..0000000 --- a/05/musl-final/src/network/res_query.c +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include "__dns.h" - -int res_query(const char *name, int class, int type, unsigned char *dest, int len) -{ - if (class != 1 || len < 512) - return -1; - switch(__dns_doqueries(dest, name, &type, 1)) { - case EAI_NONAME: - h_errno = HOST_NOT_FOUND; - return -1; - case EAI_AGAIN: - h_errno = TRY_AGAIN; - return -1; - case EAI_FAIL: - h_errno = NO_RECOVERY; - return -1; - } - return 512; -} diff --git a/05/musl-final/src/network/send.c b/05/musl-final/src/network/send.c deleted file mode 100644 index b6ec310..0000000 --- a/05/musl-final/src/network/send.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -ssize_t send(int fd, const void *buf, size_t len, int flags) -{ - return sendto(fd, buf, len, flags, 0, 0); -} diff --git a/05/musl-final/src/network/sendmsg.c b/05/musl-final/src/network/sendmsg.c deleted file mode 100644 index 5d1123f..0000000 --- a/05/musl-final/src/network/sendmsg.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -ssize_t sendmsg(int fd, const struct msghdr *msg, int flags) -{ - ssize_t r; - CANCELPT_BEGIN; - r = socketcall(sendmsg, fd, msg, flags, 0, 0, 0); - CANCELPT_END; - return r; -} diff --git a/05/musl-final/src/network/sendto.c b/05/musl-final/src/network/sendto.c deleted file mode 100644 index 1cfc621..0000000 --- a/05/musl-final/src/network/sendto.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -ssize_t sendto(int fd, const void *buf, size_t len, int flags, const struct sockaddr *addr, socklen_t alen) -{ - ssize_t r; - CANCELPT_BEGIN; - r = socketcall(sendto, fd, buf, len, flags, addr, alen); - CANCELPT_END; - return r; -} diff --git a/05/musl-final/src/network/serv.c b/05/musl-final/src/network/serv.c deleted file mode 100644 index 5ade6ad..0000000 --- a/05/musl-final/src/network/serv.c +++ /dev/null @@ -1,16 +0,0 @@ -#include -#include -#include - -void endservent(void) -{ -} - -void setservent(int stayopen) -{ -} - -struct servent *getservent(void) -{ - return 0; -} diff --git a/05/musl-final/src/network/setsockopt.c b/05/musl-final/src/network/setsockopt.c deleted file mode 100644 index c960c9c..0000000 --- a/05/musl-final/src/network/setsockopt.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int setsockopt(int fd, int level, int optname, const void *optval, socklen_t optlen) -{ - return socketcall(setsockopt, fd, level, optname, optval, optlen, 0); -} diff --git a/05/musl-final/src/network/shutdown.c b/05/musl-final/src/network/shutdown.c deleted file mode 100644 index 10ca21a..0000000 --- a/05/musl-final/src/network/shutdown.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int shutdown(int fd, int how) -{ - return socketcall(shutdown, fd, how, 0, 0, 0, 0); -} diff --git a/05/musl-final/src/network/sockatmark.c b/05/musl-final/src/network/sockatmark.c deleted file mode 100644 index f474551..0000000 --- a/05/musl-final/src/network/sockatmark.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include - -int sockatmark(int s) -{ - int ret; - if (ioctl(s, SIOCATMARK, &ret) < 0) - return -1; - return ret; -} diff --git a/05/musl-final/src/network/socket.c b/05/musl-final/src/network/socket.c deleted file mode 100644 index 4f1e86d..0000000 --- a/05/musl-final/src/network/socket.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int socket(int domain, int type, int protocol) -{ - return socketcall(socket, domain, type, protocol, 0, 0, 0); -} diff --git a/05/musl-final/src/network/socketpair.c b/05/musl-final/src/network/socketpair.c deleted file mode 100644 index b15f846..0000000 --- a/05/musl-final/src/network/socketpair.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int socketpair(int domain, int type, int protocol, int fd[2]) -{ - return socketcall(socketpair, domain, type, protocol, fd, 0, 0); -} diff --git a/05/musl-final/src/passwd/getgr_r.c b/05/musl-final/src/passwd/getgr_r.c deleted file mode 100644 index 5b1333e..0000000 --- a/05/musl-final/src/passwd/getgr_r.c +++ /dev/null @@ -1,53 +0,0 @@ -#include "pwf.h" - -#define FIX(x) (gr->gr_##x = gr->gr_##x-line+buf) - -static int getgr_r(const char *name, gid_t gid, struct group *gr, char *buf, size_t size, struct group **res) -{ - FILE *f; - char *line = 0; - size_t len = 0; - char **mem = 0; - size_t nmem = 0; - int rv = 0; - size_t i; - - f = fopen("/etc/group", "rb"); - if (!f) return errno; - - *res = 0; - while (__getgrent_a(f, gr, &line, &len, &mem, &nmem)) { - if (name && !strcmp(name, gr->gr_name) - || !name && gr->gr_gid == gid) { - if (size < len + nmem*sizeof(char *) + 32) { - rv = ERANGE; - break; - } - *res = gr; - buf += (16-(uintptr_t)buf)%16; - gr->gr_mem = (void *)buf; - buf += nmem*sizeof(char *); - memcpy(buf, line, len); - FIX(name); - FIX(passwd); - for (i=0; mem[i]; i++) - gr->gr_mem[i] = mem[i]-line+buf; - gr->gr_mem[i] = 0; - break; - } - } - free(mem); - free(line); - fclose(f); - return rv; -} - -int getgrnam_r(const char *name, struct group *gr, char *buf, size_t size, struct group **res) -{ - return getgr_r(name, 0, gr, buf, size, res); -} - -int getgruid_r(gid_t gid, struct group *gr, char *buf, size_t size, struct group **res) -{ - return getgr_r(0, gid, gr, buf, size, res); -} diff --git a/05/musl-final/src/passwd/getgrent.c b/05/musl-final/src/passwd/getgrent.c deleted file mode 100644 index e9d25eb..0000000 --- a/05/musl-final/src/passwd/getgrent.c +++ /dev/null @@ -1,39 +0,0 @@ -#include "pwf.h" - -static FILE *f; - -void setgrent() -{ - if (f) fclose(f); - f = 0; -} - -weak_alias(setgrent, endgrent); - -struct group *getgrent() -{ - static char *line, **mem; - static struct group gr; - size_t size=0, nmem=0; - if (!f) f = fopen("/etc/group", "rb"); - if (!f) return 0; - return __getgrent_a(f, &gr, &line, &size, &mem, &nmem); -} - -struct group *getgrgid(gid_t gid) -{ - struct group *gr; - setgrent(); - while ((gr=getgrent()) && gr->gr_gid != gid); - endgrent(); - return gr; -} - -struct group *getgrnam(const char *name) -{ - struct group *gr; - setgrent(); - while ((gr=getgrent()) && strcmp(gr->gr_name, name)); - endgrent(); - return gr; -} diff --git a/05/musl-final/src/passwd/getgrent_a.c b/05/musl-final/src/passwd/getgrent_a.c deleted file mode 100644 index ccb51d5..0000000 --- a/05/musl-final/src/passwd/getgrent_a.c +++ /dev/null @@ -1,46 +0,0 @@ -#include "pwf.h" - -struct group *__getgrent_a(FILE *f, struct group *gr, char **line, size_t *size, char ***mem, size_t *nmem) -{ - ssize_t l; - char *s, *mems; - size_t i; - - for (;;) { - if ((l=getline(line, size, f)) < 0) { - free(*line); - *line = 0; - return 0; - } - line[0][l-1] = 0; - - s = line[0]; - gr->gr_name = s++; - if (!(s = strchr(s, ':'))) continue; - - *s++ = 0; gr->gr_passwd = s; - if (!(s = strchr(s, ':'))) continue; - - *s++ = 0; gr->gr_gid = atoi(s); - if (!(s = strchr(s, ':'))) continue; - - *s++ = 0; mems = s; - break; - } - - for (*nmem=!!*s; *s; s++) - if (*s==',') ++*nmem; - free(*mem); - *mem = calloc(sizeof(char *), *nmem+1); - if (!*mem) { - free(*line); - *line = 0; - return 0; - } - mem[0][0] = mems; - for (s=mems, i=0; *s; s++) - if (*s==',') *s++ = 0, mem[0][++i] = s; - mem[0][++i] = 0; - gr->gr_mem = *mem; - return gr; -} diff --git a/05/musl-final/src/passwd/getpw_r.c b/05/musl-final/src/passwd/getpw_r.c deleted file mode 100644 index 7b331e8..0000000 --- a/05/musl-final/src/passwd/getpw_r.c +++ /dev/null @@ -1,46 +0,0 @@ -#include "pwf.h" - -#define FIX(x) (pw->pw_##x = pw->pw_##x-line+buf) - -static int getpw_r(const char *name, uid_t uid, struct passwd *pw, char *buf, size_t size, struct passwd **res) -{ - FILE *f; - char *line = 0; - size_t len = 0; - int rv = 0; - - f = fopen("/etc/passwd", "rb"); - if (!f) return errno; - - *res = 0; - while (__getpwent_a(f, pw, &line, &len)) { - if (name && !strcmp(name, pw->pw_name) - || !name && pw->pw_uid == uid) { - if (size < len) { - rv = ERANGE; - break; - } - *res = pw; - memcpy(buf, line, len); - FIX(name); - FIX(passwd); - FIX(gecos); - FIX(dir); - FIX(shell); - break; - } - } - free(line); - fclose(f); - return rv; -} - -int getpwnam_r(const char *name, struct passwd *pw, char *buf, size_t size, struct passwd **res) -{ - return getpw_r(name, 0, pw, buf, size, res); -} - -int getpwuid_r(uid_t uid, struct passwd *pw, char *buf, size_t size, struct passwd **res) -{ - return getpw_r(0, uid, pw, buf, size, res); -} diff --git a/05/musl-final/src/passwd/getpwent.c b/05/musl-final/src/passwd/getpwent.c deleted file mode 100644 index dabd411..0000000 --- a/05/musl-final/src/passwd/getpwent.c +++ /dev/null @@ -1,39 +0,0 @@ -#include "pwf.h" - -static FILE *f; - -void setpwent() -{ - if (f) fclose(f); - f = 0; -} - -weak_alias(setpwent, endpwent); - -struct passwd *getpwent() -{ - static char *line; - static struct passwd pw; - size_t size=0; - if (!f) f = fopen("/etc/passwd", "rb"); - if (!f) return 0; - return __getpwent_a(f, &pw, &line, &size); -} - -struct passwd *getpwuid(uid_t uid) -{ - struct passwd *pw; - setpwent(); - while ((pw=getpwent()) && pw->pw_uid != uid); - endpwent(); - return pw; -} - -struct passwd *getpwnam(const char *name) -{ - struct passwd *pw; - setpwent(); - while ((pw=getpwent()) && strcmp(pw->pw_name, name)); - endpwent(); - return pw; -} diff --git a/05/musl-final/src/passwd/getpwent_a.c b/05/musl-final/src/passwd/getpwent_a.c deleted file mode 100644 index aaf84ed..0000000 --- a/05/musl-final/src/passwd/getpwent_a.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "pwf.h" - -struct passwd *__getpwent_a(FILE *f, struct passwd *pw, char **line, size_t *size) -{ - ssize_t l; - char *s; - for (;;) { - if ((l=getline(line, size, f)) < 0) { - free(*line); - *line = 0; - return 0; - } - line[0][l-1] = 0; - - s = line[0]; - pw->pw_name = s++; - if (!(s = strchr(s, ':'))) continue; - - *s++ = 0; pw->pw_passwd = s; - if (!(s = strchr(s, ':'))) continue; - - *s++ = 0; pw->pw_uid = atoi(s); - if (!(s = strchr(s, ':'))) continue; - - *s++ = 0; pw->pw_gid = atoi(s); - if (!(s = strchr(s, ':'))) continue; - - *s++ = 0; pw->pw_gecos = s; - if (!(s = strchr(s, ':'))) continue; - - *s++ = 0; pw->pw_dir = s; - if (!(s = strchr(s, ':'))) continue; - - *s++ = 0; pw->pw_shell = s; - return pw; - } -} diff --git a/05/musl-final/src/passwd/getspent.c b/05/musl-final/src/passwd/getspent.c deleted file mode 100644 index 8574a48..0000000 --- a/05/musl-final/src/passwd/getspent.c +++ /dev/null @@ -1,14 +0,0 @@ -#include "pwf.h" - -void setspent() -{ -} - -void endspent() -{ -} - -struct spwd *getspent() -{ - return 0; -} diff --git a/05/musl-final/src/passwd/getspnam.c b/05/musl-final/src/passwd/getspnam.c deleted file mode 100644 index 041f896..0000000 --- a/05/musl-final/src/passwd/getspnam.c +++ /dev/null @@ -1,17 +0,0 @@ -#include "pwf.h" - -#define LINE_LIM 256 - -struct spwd *getspnam(const char *name) -{ - static struct spwd sp; - static char *line; - struct spwd *res; - int e; - - if (!line) line = malloc(LINE_LIM); - if (!line) return 0; - e = getspnam_r(name, &sp, line, LINE_LIM, &res); - if (e) errno = e; - return res; -} diff --git a/05/musl-final/src/passwd/getspnam_r.c b/05/musl-final/src/passwd/getspnam_r.c deleted file mode 100644 index d21ca81..0000000 --- a/05/musl-final/src/passwd/getspnam_r.c +++ /dev/null @@ -1,91 +0,0 @@ -#include -#include -#include -#include "pwf.h" - -/* This implementation support Openwall-style TCB passwords in place of - * traditional shadow, if the appropriate directories and files exist. - * Thus, it is careful to avoid following symlinks or blocking on fifos - * which a malicious user might create in place of his or her TCB shadow - * file. It also avoids any allocation to prevent memory-exhaustion - * attacks via huge TCB shadow files. */ - -int getspnam_r(const char *name, struct spwd *sp, char *buf, size_t size, struct spwd **res) -{ - char path[20+NAME_MAX]; - FILE *f = 0; - int rv = 0; - int fd; - size_t k, l = strlen(name); - char *s; - int skip = 0; - - *res = 0; - - /* Disallow potentially-malicious user names */ - if (*name=='.' || strchr(name, '/') || !l) - return EINVAL; - - /* Buffer size must at least be able to hold name, plus some.. */ - if (size < l+100) return ERANGE; - - /* Protect against truncation */ - if (snprintf(path, sizeof path, "/etc/tcb/%s/shadow", name) >= sizeof path) - return EINVAL; - - fd = open(path, O_RDONLY|O_NOFOLLOW|O_NONBLOCK); - if (fd >= 0) { - struct stat st = { 0 }; - errno = EINVAL; - if (fstat(fd, &st) || !S_ISREG(st.st_mode) || !(f = fdopen(fd, "rb"))) { - close(fd); - return errno; - } - } else { - f = fopen("/etc/shadow", "rb"); - if (!f) return errno; - } - - while (fgets(buf, size, f) && (k=strlen(buf))>0) { - if (skip || strncmp(name, buf, l)) { - skip = buf[k-1] != '\n'; - continue; - } - if (buf[k-1] != '\n') { - rv = ERANGE; - break; - } - buf[k-1] = 0; - - s = buf; - sp->sp_namp = s; - if (!(s = strchr(s, ':'))) continue; - - *s++ = 0; sp->sp_pwdp = s; - if (!(s = strchr(s, ':'))) continue; - - *s++ = 0; sp->sp_lstchg = atol(s); - if (!(s = strchr(s, ':'))) continue; - - *s++ = 0; sp->sp_min = atol(s); - if (!(s = strchr(s, ':'))) continue; - - *s++ = 0; sp->sp_max = atol(s); - if (!(s = strchr(s, ':'))) continue; - - *s++ = 0; sp->sp_warn = atol(s); - if (!(s = strchr(s, ':'))) continue; - - *s++ = 0; sp->sp_inact = atol(s); - if (!(s = strchr(s, ':'))) continue; - - *s++ = 0; sp->sp_expire = atol(s); - if (!(s = strchr(s, ':'))) continue; - - *s++ = 0; sp->sp_flag = atol(s); - *res = sp; - break; - } - fclose(f); - return rv; -} diff --git a/05/musl-final/src/passwd/lckpwdf.c b/05/musl-final/src/passwd/lckpwdf.c deleted file mode 100644 index 2feda61..0000000 --- a/05/musl-final/src/passwd/lckpwdf.c +++ /dev/null @@ -1,11 +0,0 @@ -#include - -int lckpwdf() -{ - return 0; -} - -int ulckpwdf() -{ - return 0; -} diff --git a/05/musl-final/src/passwd/pwf.h b/05/musl-final/src/passwd/pwf.h deleted file mode 100644 index 0a76ef8..0000000 --- a/05/musl-final/src/passwd/pwf.h +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include "libc.h" - -struct passwd *__getpwent_a(FILE *f, struct passwd *pw, char **line, size_t *size); -struct spwd *__getspent_a(FILE *f, struct spwd *sp, char **line, size_t *size); -struct group *__getgrent_a(FILE *f, struct group *gr, char **line, size_t *size, char ***mem, size_t *nmem); diff --git a/05/musl-final/src/prng/__rand48_step.c b/05/musl-final/src/prng/__rand48_step.c deleted file mode 100644 index 755b4f2..0000000 --- a/05/musl-final/src/prng/__rand48_step.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include - -uint64_t __rand48_step(unsigned short *xi, unsigned short *lc) -{ - uint64_t a, x; - x = xi[0] | xi[1]<<16 | xi[2]+0ULL<<32; - a = lc[0] | lc[1]<<16 | lc[2]+0ULL<<32; - x = a*x + lc[3]; - xi[0] = x; - xi[1] = x>>16; - xi[2] = x>>32; - return x & 0xffffffffffffull; -} diff --git a/05/musl-final/src/prng/__seed48.c b/05/musl-final/src/prng/__seed48.c deleted file mode 100644 index 05a4539..0000000 --- a/05/musl-final/src/prng/__seed48.c +++ /dev/null @@ -1 +0,0 @@ -unsigned short __seed48[7] = { 0, 0, 0, 0xe66d, 0xdeec, 0x5, 0xb }; diff --git a/05/musl-final/src/prng/drand48.c b/05/musl-final/src/prng/drand48.c deleted file mode 100644 index d808353..0000000 --- a/05/musl-final/src/prng/drand48.c +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include - -uint64_t __rand48_step(unsigned short *xi, unsigned short *lc); -extern unsigned short __seed48[7]; - -double erand48(unsigned short s[3]) -{ - union { - uint64_t u; - double f; - } x = { 0x3ff0000000000000ULL | __rand48_step(s, __seed48+3)<<4 }; - return x.f - 1.0; -} - -double drand48(void) -{ - return erand48(__seed48); -} diff --git a/05/musl-final/src/prng/lcong48.c b/05/musl-final/src/prng/lcong48.c deleted file mode 100644 index 32b27d4..0000000 --- a/05/musl-final/src/prng/lcong48.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include - -extern unsigned short __seed48[7]; - -void lcong48(unsigned short p[7]) -{ - memcpy(__seed48, p, sizeof __seed48); -} diff --git a/05/musl-final/src/prng/lrand48.c b/05/musl-final/src/prng/lrand48.c deleted file mode 100644 index a3c4e4e..0000000 --- a/05/musl-final/src/prng/lrand48.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include - -uint64_t __rand48_step(unsigned short *xi, unsigned short *lc); -extern unsigned short __seed48[7]; - -long nrand48(unsigned short s[3]) -{ - return __rand48_step(s, __seed48+3) >> 17; -} - -long lrand48(void) -{ - return nrand48(__seed48); -} diff --git a/05/musl-final/src/prng/mrand48.c b/05/musl-final/src/prng/mrand48.c deleted file mode 100644 index ee650fc..0000000 --- a/05/musl-final/src/prng/mrand48.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include - -uint64_t __rand48_step(unsigned short *xi, unsigned short *lc); -extern unsigned short __seed48[7]; - -long jrand48(unsigned short s[3]) -{ - return __rand48_step(s, __seed48+3) >> 16; -} - -long mrand48(void) -{ - return jrand48(__seed48); -} diff --git a/05/musl-final/src/prng/rand.c b/05/musl-final/src/prng/rand.c deleted file mode 100644 index e3ce634..0000000 --- a/05/musl-final/src/prng/rand.c +++ /dev/null @@ -1,13 +0,0 @@ -#include - -static unsigned seed; - -void srand(unsigned s) -{ - seed = s-1; -} - -int rand(void) -{ - return (seed = (seed+1) * 1103515245 + 12345 - 1)+1 & 0x7fffffff; -} diff --git a/05/musl-final/src/prng/rand_r.c b/05/musl-final/src/prng/rand_r.c deleted file mode 100644 index e96cfba..0000000 --- a/05/musl-final/src/prng/rand_r.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int rand_r(unsigned *seed) -{ - return (*seed = *seed * 1103515245 + 12345) & 0x7fffffff; -} diff --git a/05/musl-final/src/prng/random.c b/05/musl-final/src/prng/random.c deleted file mode 100644 index e6b7fd1..0000000 --- a/05/musl-final/src/prng/random.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -/* FIXME */ - -long random() -{ - return rand(); -} diff --git a/05/musl-final/src/prng/seed48.c b/05/musl-final/src/prng/seed48.c deleted file mode 100644 index e0699c0..0000000 --- a/05/musl-final/src/prng/seed48.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -extern unsigned short __seed48[7]; - -unsigned short *seed48(unsigned short *s) -{ - static unsigned short p[3]; - memcpy(p, __seed48, sizeof p); - memcpy(__seed48, s, sizeof p); - return p; -} diff --git a/05/musl-final/src/prng/srand48.c b/05/musl-final/src/prng/srand48.c deleted file mode 100644 index 0a56f6a..0000000 --- a/05/musl-final/src/prng/srand48.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -void srand48(long seed) -{ - seed48((unsigned short [3]){ 0x330e, seed, seed>>16 }); -} diff --git a/05/musl-final/src/prng/srandom.c b/05/musl-final/src/prng/srandom.c deleted file mode 100644 index 77f4dcb..0000000 --- a/05/musl-final/src/prng/srandom.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -/* FIXME */ - -void srandom(unsigned seed) -{ - return srand(seed); -} diff --git a/05/musl-final/src/process/execl.c b/05/musl-final/src/process/execl.c deleted file mode 100644 index 4c6eaa9..0000000 --- a/05/musl-final/src/process/execl.c +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include - -int execl(const char *path, ...) -{ - int argc; - va_list ap; - va_start(ap, path); - for (argc=0; va_arg(ap, const char *); argc++); - va_end(ap); - { - int i; - char *argv[argc+1]; - va_start(ap, path); - for (i=0; i -#include - -int execle(const char *path, ...) -{ - int argc; - va_list ap; - va_start(ap, path); - for (argc=0; va_arg(ap, const char *); argc++); - va_end(ap); - { - int i; - char *argv[argc+1]; - char **envp; - va_start(ap, path); - for (i=0; i -#include - -int execlp(const char *file, ...) -{ - int argc; - va_list ap; - va_start(ap, file); - for (argc=0; va_arg(ap, const char *); argc++); - va_end(ap); - { - int i; - char *argv[argc+1]; - va_start(ap, file); - for (i=0; i - -extern char **__environ; - -int execv(const char *path, char *const argv[]) -{ - return execve(path, argv, __environ); -} diff --git a/05/musl-final/src/process/execve.c b/05/musl-final/src/process/execve.c deleted file mode 100644 index 2a0b62d..0000000 --- a/05/musl-final/src/process/execve.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include "syscall.h" - -int execve(const char *path, char *const argv[], char *const envp[]) -{ - /* do we need to use environ if envp is null? */ - return syscall3(__NR_execve, (long)path, (long)argv, (long)envp); -} diff --git a/05/musl-final/src/process/execvp.c b/05/musl-final/src/process/execvp.c deleted file mode 100644 index d799dda..0000000 --- a/05/musl-final/src/process/execvp.c +++ /dev/null @@ -1,34 +0,0 @@ -#include -#include -#include -#include - -extern char **__environ; - -int execvp(const char *file, char *const argv[]) -{ - const char *p, *z, *path = getenv("PATH"); - int l; - - if (strchr(file, '/')) - return execve(file, argv, __environ); - - /* FIXME: integer overflows */ - if (!path) path = "/usr/local/bin:/bin:/usr/bin"; - l = strlen(file) + strlen(path) + 2; - - for(p=path; p && *p; p=z) { - char b[l]; - z = strchr(p, ':'); - if (z) { - memcpy(b, p, z-p); - b[z++-p] = 0; - } else strcpy(b, p); - strcat(b, "/"); - strcat(b, file); - if (!access(b, X_OK)) - return execve(b, argv, __environ); - } - errno = ENOENT; - return -1; -} diff --git a/05/musl-final/src/process/fork.c b/05/musl-final/src/process/fork.c deleted file mode 100644 index 1213f0f..0000000 --- a/05/musl-final/src/process/fork.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include "syscall.h" - -/* FIXME: add support for atfork stupidity */ - -pid_t fork(void) -{ - return syscall0(__NR_fork); -} diff --git a/05/musl-final/src/process/system.c b/05/musl-final/src/process/system.c deleted file mode 100644 index 0f1c07b..0000000 --- a/05/musl-final/src/process/system.c +++ /dev/null @@ -1,45 +0,0 @@ -#include -#include -#include -#include -#include - -int system(const char *cmd) -{ - pid_t pid; - sigset_t old, new; - struct sigaction sa, oldint, oldquit; - int status; - - if (!cmd) return 1; - - sa.sa_handler = SIG_IGN; - sigemptyset(&sa.sa_mask); - sa.sa_flags = 0; - - sigaction(SIGINT, &sa, &oldint); - sigaction(SIGQUIT, &sa, &oldquit); - sigaddset(&sa.sa_mask, SIGCHLD); - sigprocmask(SIG_BLOCK, &new, &old); - - pid = fork(); - if (pid <= 0) { - sigaction(SIGINT, &oldint, NULL); - sigaction(SIGQUIT, &oldquit, NULL); - sigprocmask(SIG_SETMASK, &old, NULL); - if (pid == 0) { - execl("/bin/sh", "sh", "-c", cmd, (char *)0); - _exit(127); - } - return -1; - } - while (waitpid(pid, &status, 0) == -1) - if (errno != EINTR) { - status = -1; - break; - } - sigaction(SIGINT, &oldint, NULL); - sigaction(SIGQUIT, &oldquit, NULL); - sigprocmask(SIG_SETMASK, &old, NULL); - return status; -} diff --git a/05/musl-final/src/process/vfork.c b/05/musl-final/src/process/vfork.c deleted file mode 100644 index 32a7a6e..0000000 --- a/05/musl-final/src/process/vfork.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include "syscall.h" - -pid_t vfork(void) -{ - /* vfork syscall cannot be made from C code */ - return syscall0(__NR_fork); -} diff --git a/05/musl-final/src/process/wait.c b/05/musl-final/src/process/wait.c deleted file mode 100644 index 34da102..0000000 --- a/05/musl-final/src/process/wait.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -pid_t wait(int *status) -{ - return waitpid((pid_t)-1, status, 0); -} diff --git a/05/musl-final/src/process/waitid.c b/05/musl-final/src/process/waitid.c deleted file mode 100644 index 0ec0d55..0000000 --- a/05/musl-final/src/process/waitid.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int waitid(idtype_t type, id_t id, siginfo_t *info, int options) -{ - return syscall5(__NR_waitid, type, id, (long)info, options, 0); -} diff --git a/05/musl-final/src/process/waitpid.c b/05/musl-final/src/process/waitpid.c deleted file mode 100644 index 0ddcd15..0000000 --- a/05/musl-final/src/process/waitpid.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -pid_t waitpid(pid_t pid, int *status, int options) -{ - return syscall4(__NR_wait4, pid, (long)status, options, 0); -} diff --git a/05/musl-final/src/regex/fnmatch.c b/05/musl-final/src/regex/fnmatch.c deleted file mode 100644 index 5f2fccd..0000000 --- a/05/musl-final/src/regex/fnmatch.c +++ /dev/null @@ -1,150 +0,0 @@ -#include -#include -#include -#include -#include -#include - -static int next(const char **s) -{ - wchar_t c; - int l = mbtowc(&c, *s, MB_LEN_MAX); - /* hack to allow literal matches of invalid byte sequences */ - if (l < 0) return (unsigned char)*(*s)++ - 0x100; - *s += l; - return c; -} - -#define BRACKET_ERROR -0x100 -#define BRACKET_NOCHAR -0x101 - -static int bracket_next(const char **s) -{ - int c; - int type; - if (**s == '[') { - type = *(*s+1); - if (type == '.' || type == '=') { - *s += 2; - c = next(s); - if (c <= 0) return BRACKET_ERROR; - if (**s == type && *(*s+1) == ']') { - *s += 2; - return c; - } - for (; **s && (**s != type || *(*s+1) != ']'); (*s)++); - if (!**s) return BRACKET_ERROR; - *s += 2; - return BRACKET_NOCHAR; - } - } - c = next(s); - if (c <= 0) return BRACKET_ERROR; - return c; -} - -#define __FNM_CONT 0x8000 - -int fnmatch(const char *p, const char *s, int flags) -{ - int c, d, k; - int not; - int match; - int first; - int no_slash = (flags & FNM_PATHNAME) ? '/' : 0; - int no_period = (flags & FNM_PERIOD) && !(flags & __FNM_CONT) ? '.' : 0x100; - - flags |= __FNM_CONT; - - while ((c = *p++)) { - switch (c) { - case '?': - k = next(&s); - if (!k || k == no_period || k == no_slash) - return FNM_NOMATCH; - break; - case '\\': - if (!(flags & FNM_NOESCAPE)) { - c = *p++; - goto literal; - } - if (*s++ != c) return FNM_NOMATCH; - break; - case '*': - for (; *p == '*'; p++); - if (*p && !*s) return FNM_NOMATCH; - if (*s == no_period) - return FNM_NOMATCH; - if (!*p && (!no_slash || !strchr(s, no_slash))) - return 0; - for (; *s; s++) - if (!fnmatch(p, s, flags)) - return 0; - else if (*s == no_slash) - break; - return FNM_NOMATCH; - case '[': - not = (*p == '!' || *p == '^'); - if (not) p++; - k = next(&s); - if (!k || k == no_slash || k == no_period) - return FNM_NOMATCH; - match = 0; - first = 1; - for (;;) { - if (!*p) return FNM_NOMATCH; - if (*p == ']' && !first) break; - first = 0; - if (*p == '[' && *(p+1) == ':') { - const char *z; - p += 2; - for (z=p; *z && (*z != ':' || *(z+1) != ']'); z++); - if (!*z || z-p > 32) { /* FIXME: symbolic const? */ - return FNM_NOMATCH; - } else { - char class[z-p+1]; - memcpy(class, p, z-p); - class[z-p] = 0; - if (iswctype(k, wctype(class))) - match = 1; - } - p = z+2; - continue; - } - c = bracket_next(&p); - if (c == BRACKET_ERROR) - return FNM_NOMATCH; - if (c == BRACKET_NOCHAR) - continue; - if (*p == '-' && *(p+1) != ']') { - p++; - d = bracket_next(&p); - if (d == BRACKET_ERROR) - return FNM_NOMATCH; - if (d == BRACKET_NOCHAR) - continue; - if (k >= c && k <= d) - match = 1; - continue; - } - if (k == c) match = 1; - } - p++; - if (not == match) - return FNM_NOMATCH; - break; - default: - literal: - if (*s++ != c) - return FNM_NOMATCH; - if (c == no_slash && (flags & FNM_PERIOD)) { - no_period = '.'; - continue; - } - break; - } - no_period = 0x100; - } - if (*s) return FNM_NOMATCH; - return 0; -} diff --git a/05/musl-final/src/regex/glob.c b/05/musl-final/src/regex/glob.c deleted file mode 100644 index 9a70f0b..0000000 --- a/05/musl-final/src/regex/glob.c +++ /dev/null @@ -1,238 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "libc.h" - -struct match -{ - struct match *next; - char name[1]; -}; - -static int is_literal(const char *p, int useesc) -{ - int bracket = 0; - for (; *p; p++) { - switch (*p) { - case '\\': - if (!useesc) break; - case '?': - case '*': - return 0; - case '[': - bracket = 1; - break; - case ']': - if (bracket) return 0; - break; - } - } - return 1; -} - -static int append(struct match **tail, const char *name, size_t len, int mark) -{ - struct match *new = malloc(sizeof(struct match) + len + 1); - if (!new) return -1; - (*tail)->next = new; - new->next = NULL; - strcpy(new->name, name); - if (mark) strcat(new->name, "/"); - *tail = new; - return 0; -} - -static int match_in_dir(const char *d, const char *p, int flags, int (*errfunc)(const char *path, int err), struct match **tail) -{ - DIR *dir; - long long de_buf[(sizeof(struct dirent) + NAME_MAX + sizeof(long long))/sizeof(long long)]; - struct dirent *de; - char pat[strlen(p)+1]; - char *p2; - size_t l = strlen(d); - int literal; - int fnm_flags= ((flags & GLOB_NOESCAPE) ? FNM_NOESCAPE : 0) | FNM_PERIOD; - int error; - - if ((p2 = strchr(p, '/'))) { - strcpy(pat, p); - pat[p2-p] = 0; - for (; *p2 == '/'; p2++); - p = pat; - } - literal = is_literal(p, !(flags & GLOB_NOESCAPE)); - if (*d == '/' && !*(d+1)) l = 0; - - /* rely on opendir failing for nondirectory objects */ - dir = opendir(*d ? d : "."); - error = errno; - if (!dir) { - /* this is not an error -- we let opendir call stat for us */ - if (error == ENOTDIR) return 0; - if (error == EACCES && !*p) { - struct stat st; - if (!stat(d, &st) && S_ISDIR(st.st_mode)) { - if (append(tail, d, l, l)) - return GLOB_NOSPACE; - return 0; - } - } - if (errfunc(d, error) || (flags & GLOB_ERR)) - return GLOB_ABORTED; - return 0; - } - if (!*p) { - error = append(tail, d, l, l) ? GLOB_NOSPACE : 0; - closedir(dir); - return error; - } - while (!(error = readdir_r(dir, (void *)de_buf, &de)) && de) { - char namebuf[l+de->d_reclen+2], *name = namebuf; - if (!literal && fnmatch(p, de->d_name, fnm_flags)) - continue; - if (literal && strcmp(p, de->d_name)) - continue; - if (p2 && de->d_type && !S_ISDIR(de->d_type<<12) && !S_ISLNK(de->d_type<<12)) - continue; - if (*d) { - memcpy(name, d, l); - name[l] = '/'; - strcpy(name+l+1, de->d_name); - } else { - name = de->d_name; - } - if (p2) { - if ((error = match_in_dir(name, p2, flags, errfunc, tail))) { - closedir(dir); - return error; - } - } else { - int mark = 0; - if (flags & GLOB_MARK) { - if (de->d_type) - mark = S_ISDIR(de->d_type<<12); - else { - struct stat st; - stat(name, &st); - mark = S_ISDIR(st.st_mode); - } - } - if (append(tail, name, l+de->d_reclen+1, mark)) { - closedir(dir); - return GLOB_NOSPACE; - } - } - } - closedir(dir); - if (error && (errfunc(d, error) || (flags & GLOB_ERR))) - return GLOB_ABORTED; - return 0; -} - -static int ignore_err(const char *path, int err) -{ - return 0; -} - -static void freelist(struct match *head) -{ - struct match *match, *next; - for (match=head->next; match; match=next) { - next = match->next; - free(match); - } -} - -static int sort(const void *a, const void *b) -{ - return strcmp(*(const char **)a, *(const char **)b); -} - -int glob(const char *pat, int flags, int (*errfunc)(const char *path, int err), glob_t *g) -{ - const char *p=pat, *d; - struct match head = { .next = NULL }, *tail = &head; - size_t cnt, i; - size_t offs = (flags & GLOB_DOOFFS) ? g->gl_offs : 0; - int error = 0; - - if (*p == '/') { - for (; *p == '/'; p++); - d = "/"; - } else { - d = ""; - } - - if (!errfunc) errfunc = ignore_err; - - if (!(flags & GLOB_APPEND)) { - g->gl_offs = offs; - g->gl_pathc = 0; - g->gl_pathv = NULL; - } - - if (*p) error = match_in_dir(d, p, flags, errfunc, &tail); - if (error == GLOB_NOSPACE) { - freelist(&head); - return error; - } - - for (cnt=0, tail=head.next; tail; tail=tail->next, cnt++); - if (!cnt) { - if (flags & GLOB_NOCHECK) { - tail = &head; - if (append(&tail, pat, strlen(pat), 0)) - return GLOB_NOSPACE; - cnt++; - } else - return GLOB_NOMATCH; - } - - if (flags & GLOB_APPEND) { - char **pathv = realloc(g->gl_pathv, (offs + g->gl_pathc + cnt + 1) * sizeof(char *)); - if (!pathv) { - freelist(&head); - return GLOB_NOSPACE; - } - g->gl_pathv = pathv; - offs += g->gl_pathc; - } else { - g->gl_pathv = malloc((offs + cnt + 1) * sizeof(char *)); - if (!g->gl_pathv) { - freelist(&head); - return GLOB_NOSPACE; - } - for (i=0; igl_pathv[i] = NULL; - } - for (i=0, tail=head.next; inext, i++) - g->gl_pathv[offs + i] = tail->name; - g->gl_pathv[offs + i] = NULL; - g->gl_pathc += cnt; - - if (!(flags & GLOB_NOSORT)) - qsort(g->gl_pathv+offs, cnt, sizeof(char *), sort); - - return error; -} - -void globfree(glob_t *g) -{ - size_t i; - for (i=0; igl_pathc; i++) - free(g->gl_pathv[g->gl_offs + i] - offsetof(struct match, name)); - free(g->gl_pathv); - g->gl_pathc = 0; - g->gl_pathv = NULL; -} - -LFS64(glob); -LFS64(globfree); diff --git a/05/musl-final/src/regex/regcomp.c b/05/musl-final/src/regex/regcomp.c deleted file mode 100644 index 3307942..0000000 --- a/05/musl-final/src/regex/regcomp.c +++ /dev/null @@ -1,3362 +0,0 @@ -/* - regcomp.c - TRE POSIX compatible regex compilation functions. - - Copyright (c) 2001-2006 Ville Laurikari - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -*/ - -#include -#include -#include -#include -#include -#include - -#include "tre.h" - -#include - -/*********************************************************************** - from tre-ast.c and tre-ast.h -***********************************************************************/ - -/* The different AST node types. */ -typedef enum { - LITERAL, - CATENATION, - ITERATION, - UNION -} tre_ast_type_t; - -/* Special subtypes of TRE_LITERAL. */ -#define EMPTY -1 /* Empty leaf (denotes empty string). */ -#define ASSERTION -2 /* Assertion leaf. */ -#define TAG -3 /* Tag leaf. */ -#define BACKREF -4 /* Back reference leaf. */ - -#define IS_SPECIAL(x) ((x)->code_min < 0) -#define IS_EMPTY(x) ((x)->code_min == EMPTY) -#define IS_ASSERTION(x) ((x)->code_min == ASSERTION) -#define IS_TAG(x) ((x)->code_min == TAG) -#define IS_BACKREF(x) ((x)->code_min == BACKREF) - -/* Taken from tre-compile.h */ -typedef struct { - int position; - int code_min; - int code_max; - int *tags; - int assertions; - tre_ctype_t class; - tre_ctype_t *neg_classes; - int backref; -} tre_pos_and_tags_t; - -/* A generic AST node. All AST nodes consist of this node on the top - level with `obj' pointing to the actual content. */ -typedef struct { - tre_ast_type_t type; /* Type of the node. */ - void *obj; /* Pointer to actual node. */ - int nullable; - int submatch_id; - int num_submatches; - int num_tags; - tre_pos_and_tags_t *firstpos; - tre_pos_and_tags_t *lastpos; -} tre_ast_node_t; - - -/* A "literal" node. These are created for assertions, back references, - tags, matching parameter settings, and all expressions that match one - character. */ -typedef struct { - long code_min; - long code_max; - int position; - tre_ctype_t class; - tre_ctype_t *neg_classes; -} tre_literal_t; - -/* A "catenation" node. These are created when two regexps are concatenated. - If there are more than one subexpressions in sequence, the `left' part - holds all but the last, and `right' part holds the last subexpression - (catenation is left associative). */ -typedef struct { - tre_ast_node_t *left; - tre_ast_node_t *right; -} tre_catenation_t; - -/* An "iteration" node. These are created for the "*", "+", "?", and "{m,n}" - operators. */ -typedef struct { - /* Subexpression to match. */ - tre_ast_node_t *arg; - /* Minimum number of consecutive matches. */ - int min; - /* Maximum number of consecutive matches. */ - int max; -} tre_iteration_t; - -/* An "union" node. These are created for the "|" operator. */ -typedef struct { - tre_ast_node_t *left; - tre_ast_node_t *right; -} tre_union_t; - -static tre_ast_node_t * -tre_ast_new_node(tre_mem_t mem, tre_ast_type_t type, size_t size) -{ - tre_ast_node_t *node; - - node = tre_mem_calloc(mem, sizeof(*node)); - if (!node) - return NULL; - node->obj = tre_mem_calloc(mem, size); - if (!node->obj) - return NULL; - node->type = type; - node->nullable = -1; - node->submatch_id = -1; - - return node; -} - -static tre_ast_node_t * -tre_ast_new_literal(tre_mem_t mem, int code_min, int code_max, int position) -{ - tre_ast_node_t *node; - tre_literal_t *lit; - - node = tre_ast_new_node(mem, LITERAL, sizeof(tre_literal_t)); - if (!node) - return NULL; - lit = node->obj; - lit->code_min = code_min; - lit->code_max = code_max; - lit->position = position; - - return node; -} - -static tre_ast_node_t * -tre_ast_new_iter(tre_mem_t mem, tre_ast_node_t *arg, int min, int max) -{ - tre_ast_node_t *node; - tre_iteration_t *iter; - - node = tre_ast_new_node(mem, ITERATION, sizeof(tre_iteration_t)); - if (!node) - return NULL; - iter = node->obj; - iter->arg = arg; - iter->min = min; - iter->max = max; - node->num_submatches = arg->num_submatches; - - return node; -} - -static tre_ast_node_t * -tre_ast_new_union(tre_mem_t mem, tre_ast_node_t *left, tre_ast_node_t *right) -{ - tre_ast_node_t *node; - - node = tre_ast_new_node(mem, UNION, sizeof(tre_union_t)); - if (node == NULL) - return NULL; - ((tre_union_t *)node->obj)->left = left; - ((tre_union_t *)node->obj)->right = right; - node->num_submatches = left->num_submatches + right->num_submatches; - - return node; -} - -static tre_ast_node_t * -tre_ast_new_catenation(tre_mem_t mem, tre_ast_node_t *left, - tre_ast_node_t *right) -{ - tre_ast_node_t *node; - - node = tre_ast_new_node(mem, CATENATION, sizeof(tre_catenation_t)); - if (node == NULL) - return NULL; - ((tre_catenation_t *)node->obj)->left = left; - ((tre_catenation_t *)node->obj)->right = right; - node->num_submatches = left->num_submatches + right->num_submatches; - - return node; -} - -/*********************************************************************** - from tre-stack.c and tre-stack.h -***********************************************************************/ - -/* Just to save some typing. */ -#define STACK_PUSH(s, value) \ - do \ - { \ - status = tre_stack_push(s, (void *)(value)); \ - } \ - while (0) - -#define STACK_PUSHX(s, value) \ - { \ - status = tre_stack_push(s, (void *)(value)); \ - if (status != REG_OK) \ - break; \ - } - -#define STACK_PUSHR(s, value) \ - { \ - reg_errcode_t status; \ - status = tre_stack_push(s, (void *)(value)); \ - if (status != REG_OK) \ - return status; \ - } - -typedef struct tre_stack_rec { - int size; - int max_size; - int increment; - int ptr; - void **stack; -} tre_stack_t; - - -static tre_stack_t * -tre_stack_new(int size, int max_size, int increment) -{ - tre_stack_t *s; - - s = xmalloc(sizeof(*s)); - if (s != NULL) - { - s->stack = xmalloc(sizeof(*s->stack) * size); - if (s->stack == NULL) - { - xfree(s); - return NULL; - } - s->size = size; - s->max_size = max_size; - s->increment = increment; - s->ptr = 0; - } - return s; -} - -static void -tre_stack_destroy(tre_stack_t *s) -{ - xfree(s->stack); - xfree(s); -} - -static int -tre_stack_num_objects(tre_stack_t *s) -{ - return s->ptr; -} - -static reg_errcode_t -tre_stack_push(tre_stack_t *s, void *value) -{ - if (s->ptr < s->size) - { - s->stack[s->ptr] = value; - s->ptr++; - } - else - { - if (s->size >= s->max_size) - { - DPRINT(("tre_stack_push: stack full\n")); - return REG_ESPACE; - } - else - { - void **new_buffer; - int new_size; - DPRINT(("tre_stack_push: trying to realloc more space\n")); - new_size = s->size + s->increment; - if (new_size > s->max_size) - new_size = s->max_size; - new_buffer = xrealloc(s->stack, sizeof(*new_buffer) * new_size); - if (new_buffer == NULL) - { - DPRINT(("tre_stack_push: realloc failed.\n")); - return REG_ESPACE; - } - DPRINT(("tre_stack_push: realloc succeeded.\n")); - assert(new_size > s->size); - s->size = new_size; - s->stack = new_buffer; - tre_stack_push(s, value); - } - } - return REG_OK; -} - -static void * -tre_stack_pop(tre_stack_t *s) -{ - return s->stack[--s->ptr]; -} - - -/*********************************************************************** - from tre-parse.c and tre-parse.h -***********************************************************************/ - -/* Parse context. */ -typedef struct { - /* Memory allocator. The AST is allocated using this. */ - tre_mem_t mem; - /* Stack used for keeping track of regexp syntax. */ - tre_stack_t *stack; - /* The parse result. */ - tre_ast_node_t *result; - /* The regexp to parse and its length. */ - const tre_char_t *re; - /* The first character of the entire regexp. */ - const tre_char_t *re_start; - /* The first character after the end of the regexp. */ - const tre_char_t *re_end; - int len; - /* Current submatch ID. */ - int submatch_id; - /* Current position (number of literal). */ - int position; - /* The highest back reference or -1 if none seen so far. */ - int max_backref; - /* Compilation flags. */ - int cflags; - /* If this flag is set the top-level submatch is not captured. */ - int nofirstsub; -} tre_parse_ctx_t; - -static reg_errcode_t -tre_new_item(tre_mem_t mem, int min, int max, int *i, int *max_i, - tre_ast_node_t ***items) -{ - reg_errcode_t status; - tre_ast_node_t **array = *items; - /* Allocate more space if necessary. */ - if (*i >= *max_i) - { - tre_ast_node_t **new_items; - DPRINT(("out of array space, i = %d\n", *i)); - /* If the array is already 1024 items large, give up -- there's - probably an error in the regexp (e.g. not a '\0' terminated - string and missing ']') */ - if (*max_i > 1024) - return REG_ESPACE; - *max_i *= 2; - new_items = xrealloc(array, sizeof(*items) * *max_i); - if (new_items == NULL) - return REG_ESPACE; - *items = array = new_items; - } - array[*i] = tre_ast_new_literal(mem, min, max, -1); - status = array[*i] == NULL ? REG_ESPACE : REG_OK; - (*i)++; - return status; -} - - -/* Expands a character class to character ranges. */ -static reg_errcode_t -tre_expand_ctype(tre_mem_t mem, tre_ctype_t class, tre_ast_node_t ***items, - int *i, int *max_i, int cflags) -{ - reg_errcode_t status = REG_OK; - tre_cint_t c; - int j, min = -1, max = 0; - assert(TRE_MB_CUR_MAX == 1); - - DPRINT((" expanding class to character ranges\n")); - for (j = 0; (j < 256) && (status == REG_OK); j++) - { - c = j; - if (tre_isctype(c, class) - || ((cflags & REG_ICASE) - && (tre_isctype(tre_tolower(c), class) - || tre_isctype(tre_toupper(c), class)))) -{ - if (min < 0) - min = c; - max = c; - } - else if (min >= 0) - { - DPRINT((" range %c (%d) to %c (%d)\n", min, min, max, max)); - status = tre_new_item(mem, min, max, i, max_i, items); - min = -1; - } - } - if (min >= 0 && status == REG_OK) - status = tre_new_item(mem, min, max, i, max_i, items); - return status; -} - - -static int -tre_compare_items(const void *a, const void *b) -{ - tre_ast_node_t *node_a = *(tre_ast_node_t **)a; - tre_ast_node_t *node_b = *(tre_ast_node_t **)b; - tre_literal_t *l_a = node_a->obj, *l_b = node_b->obj; - int a_min = l_a->code_min, b_min = l_b->code_min; - - if (a_min < b_min) - return -1; - else if (a_min > b_min) - return 1; - else - return 0; -} - -/* Maximum number of character classes that can occur in a negated bracket - expression. */ -#define MAX_NEG_CLASSES 64 - -/* Maximum length of character class names. */ -#define MAX_CLASS_NAME - -static reg_errcode_t -tre_parse_bracket_items(tre_parse_ctx_t *ctx, int negate, - tre_ctype_t neg_classes[], int *num_neg_classes, - tre_ast_node_t ***items, int *num_items, - int *items_size) -{ - const tre_char_t *re = ctx->re; - reg_errcode_t status = REG_OK; - tre_ctype_t class = (tre_ctype_t)0; - int i = *num_items; - int max_i = *items_size; - int skip; - - /* Build an array of the items in the bracket expression. */ - while (status == REG_OK) - { - skip = 0; - if (re == ctx->re_end) - { - status = REG_EBRACK; - } - else if (*re == ']' && re > ctx->re) - { - DPRINT(("tre_parse_bracket: done: '%.*" STRF "'\n", - ctx->re_end - re, re)); - re++; - break; - } - else - { - tre_cint_t min = 0, max = 0; - - class = (tre_ctype_t)0; - if (re + 2 < ctx->re_end - && *(re + 1) == '-' && *(re + 2) != ']') - { - DPRINT(("tre_parse_bracket: range: '%.*" STRF "'\n", - ctx->re_end - re, re)); - min = *re; - max = *(re + 2); - re += 3; - /* XXX - Should use collation order instead of encoding values - in character ranges. */ - if (min > max) - status = REG_ERANGE; - } - else if (re + 1 < ctx->re_end - && *re == '[' && *(re + 1) == '.') - status = REG_ECOLLATE; - else if (re + 1 < ctx->re_end - && *re == '[' && *(re + 1) == '=') - status = REG_ECOLLATE; - else if (re + 1 < ctx->re_end - && *re == '[' && *(re + 1) == ':') - { - char tmp_str[64]; - const tre_char_t *endptr = re + 2; - int len; - DPRINT(("tre_parse_bracket: class: '%.*" STRF "'\n", - ctx->re_end - re, re)); - while (endptr < ctx->re_end && *endptr != ':') - endptr++; - if (endptr != ctx->re_end) - { - len = MIN(endptr - re - 2, 63); -#ifdef TRE_WCHAR - { - tre_char_t tmp_wcs[64]; - wcsncpy(tmp_wcs, re + 2, len); - tmp_wcs[len] = '\0'; -#if defined HAVE_WCSRTOMBS - { - mbstate_t state; - const tre_char_t *src = tmp_wcs; - memset(&state, '\0', sizeof(state)); - len = wcsrtombs(tmp_str, &src, sizeof(tmp_str), &state); - } -#elif defined HAVE_WCSTOMBS - len = wcstombs(tmp_str, tmp_wcs, 63); -#endif /* defined HAVE_WCSTOMBS */ - } -#else /* !TRE_WCHAR */ - strncpy(tmp_str, re + 2, len); -#endif /* !TRE_WCHAR */ - tmp_str[len] = '\0'; - DPRINT((" class name: %s\n", tmp_str)); - class = tre_ctype(tmp_str); - if (!class) - status = REG_ECTYPE; - /* Optimize character classes for 8 bit character sets. */ - if (status == REG_OK && TRE_MB_CUR_MAX == 1) - { - status = tre_expand_ctype(ctx->mem, class, items, - &i, &max_i, ctx->cflags); - class = (tre_ctype_t)0; - skip = 1; - } - re = endptr + 2; - } - else - status = REG_ECTYPE; - min = 0; - max = TRE_CHAR_MAX; - } - else - { - DPRINT(("tre_parse_bracket: char: '%.*" STRF "'\n", - ctx->re_end - re, re)); - if (*re == '-' && *(re + 1) != ']' - && ctx->re != re) - /* Two ranges are not allowed to share and endpoint. */ - status = REG_ERANGE; - min = max = *re++; - } - - if (status != REG_OK) - break; - - if (class && negate) - if (*num_neg_classes >= MAX_NEG_CLASSES) - status = REG_ESPACE; - else - neg_classes[(*num_neg_classes)++] = class; - else if (!skip) - { - status = tre_new_item(ctx->mem, min, max, &i, &max_i, items); - if (status != REG_OK) - break; - ((tre_literal_t*)((*items)[i-1])->obj)->class = class; - } - - /* Add opposite-case counterpoints if REG_ICASE is present. - This is broken if there are more than two "same" characters. */ - if (ctx->cflags & REG_ICASE && !class && status == REG_OK && !skip) - { - int cmin, ccurr; - - DPRINT(("adding opposite-case counterpoints\n")); - while (min <= max) - { - if (tre_islower(min)) - { - cmin = ccurr = tre_toupper(min++); - while (tre_islower(min) && tre_toupper(min) == ccurr + 1 - && min <= max) - ccurr = tre_toupper(min++); - status = tre_new_item(ctx->mem, cmin, ccurr, - &i, &max_i, items); - } - else if (tre_isupper(min)) - { - cmin = ccurr = tre_tolower(min++); - while (tre_isupper(min) && tre_tolower(min) == ccurr + 1 - && min <= max) - ccurr = tre_tolower(min++); - status = tre_new_item(ctx->mem, cmin, ccurr, - &i, &max_i, items); - } - else min++; - if (status != REG_OK) - break; - } - if (status != REG_OK) - break; - } - } - } - *num_items = i; - *items_size = max_i; - ctx->re = re; - return status; -} - -static reg_errcode_t -tre_parse_bracket(tre_parse_ctx_t *ctx, tre_ast_node_t **result) -{ - tre_ast_node_t *node = NULL; - int negate = 0; - reg_errcode_t status = REG_OK; - tre_ast_node_t **items, *u, *n; - int i = 0, j, max_i = 32, curr_max, curr_min; - tre_ctype_t neg_classes[MAX_NEG_CLASSES]; - int num_neg_classes = 0; - - /* Start off with an array of `max_i' elements. */ - items = xmalloc(sizeof(*items) * max_i); - if (items == NULL) - return REG_ESPACE; - - if (*ctx->re == '^') - { - DPRINT(("tre_parse_bracket: negate: '%.*" STRF "'\n", - ctx->re_end - ctx->re, ctx->re)); - negate = 1; - ctx->re++; - } - - status = tre_parse_bracket_items(ctx, negate, neg_classes, &num_neg_classes, - &items, &i, &max_i); - - if (status != REG_OK) - goto parse_bracket_done; - - /* Sort the array if we need to negate it. */ - if (negate) - qsort(items, i, sizeof(*items), tre_compare_items); - - curr_max = curr_min = 0; - /* Build a union of the items in the array, negated if necessary. */ - for (j = 0; j < i && status == REG_OK; j++) - { - int min, max; - tre_literal_t *l = items[j]->obj; - min = l->code_min; - max = l->code_max; - - DPRINT(("item: %d - %d, class %ld, curr_max = %d\n", - (int)l->code_min, (int)l->code_max, (long)l->class, curr_max)); - - if (negate) - { - if (min < curr_max) - { - /* Overlap. */ - curr_max = MAX(max + 1, curr_max); - DPRINT(("overlap, curr_max = %d\n", curr_max)); - l = NULL; - } - else - { - /* No overlap. */ - curr_max = min - 1; - if (curr_max >= curr_min) - { - DPRINT(("no overlap\n")); - l->code_min = curr_min; - l->code_max = curr_max; - } - else - { - DPRINT(("no overlap, zero room\n")); - l = NULL; - } - curr_min = curr_max = max + 1; - } - } - - if (l != NULL) - { - int k; - DPRINT(("creating %d - %d\n", (int)l->code_min, (int)l->code_max)); - l->position = ctx->position; - if (num_neg_classes > 0) - { - l->neg_classes = tre_mem_alloc(ctx->mem, - (sizeof(l->neg_classes) - * (num_neg_classes + 1))); - if (l->neg_classes == NULL) - { - status = REG_ESPACE; - break; - } - for (k = 0; k < num_neg_classes; k++) - l->neg_classes[k] = neg_classes[k]; - l->neg_classes[k] = (tre_ctype_t)0; - } - else - l->neg_classes = NULL; - if (node == NULL) - node = items[j]; - else - { - u = tre_ast_new_union(ctx->mem, node, items[j]); - if (u == NULL) - status = REG_ESPACE; - node = u; - } - } - } - - if (status != REG_OK) - goto parse_bracket_done; - - if (negate) - { - int k; - DPRINT(("final: creating %d - %d\n", curr_min, (int)TRE_CHAR_MAX)); - n = tre_ast_new_literal(ctx->mem, curr_min, TRE_CHAR_MAX, ctx->position); - if (n == NULL) - status = REG_ESPACE; - else - { - tre_literal_t *l = n->obj; - if (num_neg_classes > 0) - { - l->neg_classes = tre_mem_alloc(ctx->mem, - (sizeof(l->neg_classes) - * (num_neg_classes + 1))); - if (l->neg_classes == NULL) - { - status = REG_ESPACE; - goto parse_bracket_done; - } - for (k = 0; k < num_neg_classes; k++) - l->neg_classes[k] = neg_classes[k]; - l->neg_classes[k] = (tre_ctype_t)0; - } - else - l->neg_classes = NULL; - if (node == NULL) - node = n; - else - { - u = tre_ast_new_union(ctx->mem, node, n); - if (u == NULL) - status = REG_ESPACE; - node = u; - } - } - } - - if (status != REG_OK) - goto parse_bracket_done; - -#ifdef TRE_DEBUG - tre_ast_print(node); -#endif /* TRE_DEBUG */ - - parse_bracket_done: - xfree(items); - ctx->position++; - *result = node; - return status; -} - - -/* Parses a positive decimal integer. Returns -1 if the string does not - contain a valid number. */ -static int -tre_parse_int(const tre_char_t **regex, const tre_char_t *regex_end) -{ - int num = -1; - const tre_char_t *r = *regex; - while (r < regex_end && *r >= '0' && *r <= '9') - { - if (num < 0) - num = 0; - num = num * 10 + *r - '0'; - r++; - } - *regex = r; - return num; -} - - -static reg_errcode_t -tre_parse_bound(tre_parse_ctx_t *ctx, tre_ast_node_t **result) -{ - int min, max; - const tre_char_t *r = ctx->re; - const tre_char_t *start; - int counts_set = 0; - - /* Parse number (minimum repetition count). */ - min = -1; - if (r < ctx->re_end && *r >= '0' && *r <= '9') { - DPRINT(("tre_parse: min count: '%.*" STRF "'\n", ctx->re_end - r, r)); - min = tre_parse_int(&r, ctx->re_end); - } - - /* Parse comma and second number (maximum repetition count). */ - max = min; - if (r < ctx->re_end && *r == ',') - { - r++; - DPRINT(("tre_parse: max count: '%.*" STRF "'\n", ctx->re_end - r, r)); - max = tre_parse_int(&r, ctx->re_end); - } - - /* Check that the repeat counts are sane. */ - if ((max >= 0 && min > max) || max > RE_DUP_MAX) - return REG_BADBR; - - - /* - '{' - optionally followed immediately by a number == minimum repcount - optionally followed by , then a number == maximum repcount - */ - - - do { - int done; - start = r; - - /* Parse count limit settings */ - done = 0; - if (!counts_set) - while (r + 1 < ctx->re_end && !done) - { - switch (*r) - { - case ',': - r++; - break; - case ' ': - r++; - break; - case '}': - done = 1; - break; - default: - done = 1; - break; - } - } - } while (start != r); - - /* Missing }. */ - if (r >= ctx->re_end) - return REG_EBRACE; - - /* Empty contents of {}. */ - if (r == ctx->re) - return REG_BADBR; - - /* Parse the ending '}' or '\}'.*/ - if (ctx->cflags & REG_EXTENDED) - { - if (r >= ctx->re_end || *r != '}') - return REG_BADBR; - r++; - } - else - { - if (r + 1 >= ctx->re_end - || *r != '\\' - || *(r + 1) != '}') - return REG_BADBR; - r += 2; - } - - - /* Create the AST node(s). */ - if (min == 0 && max == 0) - { - *result = tre_ast_new_literal(ctx->mem, EMPTY, -1, -1); - if (*result == NULL) - return REG_ESPACE; - } - else - { - if (min < 0 && max < 0) - /* Only approximate parameters set, no repetitions. */ - min = max = 1; - - *result = tre_ast_new_iter(ctx->mem, *result, min, max); - if (!*result) - return REG_ESPACE; - } - - ctx->re = r; - return REG_OK; -} - -typedef enum { - PARSE_RE = 0, - PARSE_ATOM, - PARSE_MARK_FOR_SUBMATCH, - PARSE_BRANCH, - PARSE_PIECE, - PARSE_CATENATION, - PARSE_POST_CATENATION, - PARSE_UNION, - PARSE_POST_UNION, - PARSE_POSTFIX, - PARSE_RESTORE_CFLAGS -} tre_parse_re_stack_symbol_t; - - -static reg_errcode_t -tre_parse(tre_parse_ctx_t *ctx) -{ - tre_ast_node_t *result = NULL; - tre_parse_re_stack_symbol_t symbol; - reg_errcode_t status = REG_OK; - tre_stack_t *stack = ctx->stack; - int bottom = tre_stack_num_objects(stack); - int depth = 0; - - DPRINT(("tre_parse: parsing '%.*" STRF "', len = %d\n", - ctx->len, ctx->re, ctx->len)); - - if (!ctx->nofirstsub) - { - STACK_PUSH(stack, ctx->re); - STACK_PUSH(stack, ctx->submatch_id); - STACK_PUSH(stack, PARSE_MARK_FOR_SUBMATCH); - ctx->submatch_id++; - } - STACK_PUSH(stack, PARSE_RE); - ctx->re_start = ctx->re; - ctx->re_end = ctx->re + ctx->len; - - - /* The following is basically just a recursive descent parser. I use - an explicit stack instead of recursive functions mostly because of - two reasons: compatibility with systems which have an overflowable - call stack, and efficiency (both in lines of code and speed). */ - while (tre_stack_num_objects(stack) > bottom && status == REG_OK) - { - if (status != REG_OK) - break; - symbol = (tre_parse_re_stack_symbol_t)tre_stack_pop(stack); - switch (symbol) - { - case PARSE_RE: - /* Parse a full regexp. A regexp is one or more branches, - separated by the union operator `|'. */ - if (ctx->cflags & REG_EXTENDED) - STACK_PUSHX(stack, PARSE_UNION); - STACK_PUSHX(stack, PARSE_BRANCH); - break; - - case PARSE_BRANCH: - /* Parse a branch. A branch is one or more pieces, concatenated. - A piece is an atom possibly followed by a postfix operator. */ - STACK_PUSHX(stack, PARSE_CATENATION); - STACK_PUSHX(stack, PARSE_PIECE); - break; - - case PARSE_PIECE: - /* Parse a piece. A piece is an atom possibly followed by one - or more postfix operators. */ - STACK_PUSHX(stack, PARSE_POSTFIX); - STACK_PUSHX(stack, PARSE_ATOM); - break; - - case PARSE_CATENATION: - /* If the expression has not ended, parse another piece. */ - { - tre_char_t c; - if (ctx->re >= ctx->re_end) - break; - c = *ctx->re; - if (ctx->cflags & REG_EXTENDED && c == '|') - break; - if ((ctx->cflags & REG_EXTENDED - && c == ')' && depth > 0) - || (!(ctx->cflags & REG_EXTENDED) - && (c == '\\' - && *(ctx->re + 1) == ')'))) - { - if (!(ctx->cflags & REG_EXTENDED) && depth == 0) - status = REG_EPAREN; - DPRINT(("tre_parse: group end: '%.*" STRF "'\n", - ctx->re_end - ctx->re, ctx->re)); - depth--; - if (!(ctx->cflags & REG_EXTENDED)) - ctx->re += 2; - break; - } - - /* Left associative concatenation. */ - STACK_PUSHX(stack, PARSE_CATENATION); - STACK_PUSHX(stack, result); - STACK_PUSHX(stack, PARSE_POST_CATENATION); - STACK_PUSHX(stack, PARSE_PIECE); - break; - } - - case PARSE_POST_CATENATION: - { - tre_ast_node_t *tree = tre_stack_pop(stack); - tre_ast_node_t *tmp_node; - tmp_node = tre_ast_new_catenation(ctx->mem, tree, result); - if (!tmp_node) - return REG_ESPACE; - result = tmp_node; - break; - } - - case PARSE_UNION: - if (ctx->re >= ctx->re_end) - break; - switch (*ctx->re) - { - case '|': - DPRINT(("tre_parse: union: '%.*" STRF "'\n", - ctx->re_end - ctx->re, ctx->re)); - STACK_PUSHX(stack, PARSE_UNION); - STACK_PUSHX(stack, result); - STACK_PUSHX(stack, PARSE_POST_UNION); - STACK_PUSHX(stack, PARSE_BRANCH); - ctx->re++; - break; - - case ')': - ctx->re++; - break; - - default: - break; - } - break; - - case PARSE_POST_UNION: - { - tre_ast_node_t *tmp_node; - tre_ast_node_t *tree = tre_stack_pop(stack); - tmp_node = tre_ast_new_union(ctx->mem, tree, result); - if (!tmp_node) - return REG_ESPACE; - result = tmp_node; - break; - } - - case PARSE_POSTFIX: - /* Parse postfix operators. */ - if (ctx->re >= ctx->re_end) - break; - switch (*ctx->re) - { - case '+': - case '?': - if (!(ctx->cflags & REG_EXTENDED)) - break; - case '*': - { - tre_ast_node_t *tmp_node; - int rep_min = 0; - int rep_max = -1; - if (*ctx->re == '+') - rep_min = 1; - if (*ctx->re == '?') - rep_max = 1; - - ctx->re++; - tmp_node = tre_ast_new_iter(ctx->mem, result, rep_min, rep_max); - if (tmp_node == NULL) - return REG_ESPACE; - result = tmp_node; - STACK_PUSHX(stack, PARSE_POSTFIX); - break; - } - - case '\\': - /* "\{" is special without REG_EXTENDED */ - if (!(ctx->cflags & REG_EXTENDED) - && ctx->re + 1 < ctx->re_end - && *(ctx->re + 1) == '{') - { - ctx->re++; - goto parse_brace; - } - else - break; - - case '{': - /* "{" is literal without REG_EXTENDED */ - if (!(ctx->cflags & REG_EXTENDED)) - break; - - parse_brace: - DPRINT(("tre_parse: bound: '%.*" STRF "'\n", - ctx->re_end - ctx->re, ctx->re)); - ctx->re++; - - status = tre_parse_bound(ctx, &result); - if (status != REG_OK) - return status; - STACK_PUSHX(stack, PARSE_POSTFIX); - break; - } - break; - - case PARSE_ATOM: - /* Parse an atom. An atom is a regular expression enclosed in `()', - an empty set of `()', a bracket expression, `.', `^', `$', - a `\' followed by a character, or a single character. */ - - /* End of regexp? (empty string). */ - if (ctx->re >= ctx->re_end) - goto parse_literal; - - switch (*ctx->re) - { - case '(': /* parenthesized subexpression */ - - if (ctx->cflags & REG_EXTENDED - || (ctx->re > ctx->re_start - && *(ctx->re - 1) == '\\')) - { - depth++; - { - DPRINT(("tre_parse: group begin: '%.*" STRF - "', submatch %d\n", - ctx->re_end - ctx->re, ctx->re, - ctx->submatch_id)); - ctx->re++; - /* First parse a whole RE, then mark the resulting tree - for submatching. */ - STACK_PUSHX(stack, ctx->submatch_id); - STACK_PUSHX(stack, PARSE_MARK_FOR_SUBMATCH); - STACK_PUSHX(stack, PARSE_RE); - ctx->submatch_id++; - } - } - else - goto parse_literal; - break; - - case ')': /* end of current subexpression */ - if ((ctx->cflags & REG_EXTENDED && depth > 0) - || (ctx->re > ctx->re_start - && *(ctx->re - 1) == '\\')) - { - DPRINT(("tre_parse: empty: '%.*" STRF "'\n", - ctx->re_end - ctx->re, ctx->re)); - /* We were expecting an atom, but instead the current - subexpression was closed. POSIX leaves the meaning of - this to be implementation-defined. We interpret this as - an empty expression (which matches an empty string). */ - result = tre_ast_new_literal(ctx->mem, EMPTY, -1, -1); - if (result == NULL) - return REG_ESPACE; - if (!(ctx->cflags & REG_EXTENDED)) - ctx->re--; - } - else - goto parse_literal; - break; - - case '[': /* bracket expression */ - DPRINT(("tre_parse: bracket: '%.*" STRF "'\n", - ctx->re_end - ctx->re, ctx->re)); - ctx->re++; - status = tre_parse_bracket(ctx, &result); - if (status != REG_OK) - return status; - break; - - case '\\': - /* If this is "\(" or "\)" chew off the backslash and - try again. */ - if (!(ctx->cflags & REG_EXTENDED) - && ctx->re + 1 < ctx->re_end - && (*(ctx->re + 1) == '(' - || *(ctx->re + 1) == ')')) - { - ctx->re++; - STACK_PUSHX(stack, PARSE_ATOM); - break; - } - - if (ctx->re + 1 >= ctx->re_end) - /* Trailing backslash. */ - return REG_EESCAPE; - - DPRINT(("tre_parse: bleep: '%.*" STRF "'\n", - ctx->re_end - ctx->re, ctx->re)); - ctx->re++; - switch (*ctx->re) - { - default: - if (!(ctx->cflags & REG_EXTENDED) && tre_isdigit(*ctx->re)) - { - /* Back reference. */ - int val = *ctx->re - '0'; - DPRINT(("tre_parse: backref: '%.*" STRF "'\n", - ctx->re_end - ctx->re + 1, ctx->re - 1)); - result = tre_ast_new_literal(ctx->mem, BACKREF, val, - ctx->position); - if (result == NULL) - return REG_ESPACE; - ctx->position++; - ctx->max_backref = MAX(val, ctx->max_backref); - ctx->re++; - } - else - { - /* Escaped character. */ - DPRINT(("tre_parse: escaped: '%.*" STRF "'\n", - ctx->re_end - ctx->re + 1, ctx->re - 1)); - result = tre_ast_new_literal(ctx->mem, *ctx->re, *ctx->re, - ctx->position); - ctx->position++; - ctx->re++; - } - break; - } - if (result == NULL) - return REG_ESPACE; - break; - - case '.': /* the any-symbol */ - DPRINT(("tre_parse: any: '%.*" STRF "'\n", - ctx->re_end - ctx->re, ctx->re)); - if (ctx->cflags & REG_NEWLINE) - { - tre_ast_node_t *tmp1; - tre_ast_node_t *tmp2; - tmp1 = tre_ast_new_literal(ctx->mem, 0, '\n' - 1, - ctx->position); - if (!tmp1) - return REG_ESPACE; - tmp2 = tre_ast_new_literal(ctx->mem, '\n' + 1, TRE_CHAR_MAX, - ctx->position + 1); - if (!tmp2) - return REG_ESPACE; - result = tre_ast_new_union(ctx->mem, tmp1, tmp2); - if (!result) - return REG_ESPACE; - ctx->position += 2; - } - else - { - result = tre_ast_new_literal(ctx->mem, 0, TRE_CHAR_MAX, - ctx->position); - if (!result) - return REG_ESPACE; - ctx->position++; - } - ctx->re++; - break; - - case '^': /* beginning of line assertion */ - /* '^' has a special meaning everywhere in EREs, and in the - beginning of the RE and after \( is BREs. */ - if (ctx->cflags & REG_EXTENDED - || (ctx->re - 2 >= ctx->re_start - && *(ctx->re - 2) == '\\' - && *(ctx->re - 1) == '(') - || ctx->re == ctx->re_start) - { - DPRINT(("tre_parse: BOL: '%.*" STRF "'\n", - ctx->re_end - ctx->re, ctx->re)); - result = tre_ast_new_literal(ctx->mem, ASSERTION, - ASSERT_AT_BOL, -1); - if (result == NULL) - return REG_ESPACE; - ctx->re++; - } - else - goto parse_literal; - break; - - case '$': /* end of line assertion. */ - /* '$' is special everywhere in EREs, and in the end of the - string and before \) is BREs. */ - if (ctx->cflags & REG_EXTENDED - || (ctx->re + 2 < ctx->re_end - && *(ctx->re + 1) == '\\' - && *(ctx->re + 2) == ')') - || ctx->re + 1 == ctx->re_end) - { - DPRINT(("tre_parse: EOL: '%.*" STRF "'\n", - ctx->re_end - ctx->re, ctx->re)); - result = tre_ast_new_literal(ctx->mem, ASSERTION, - ASSERT_AT_EOL, -1); - if (result == NULL) - return REG_ESPACE; - ctx->re++; - } - else - goto parse_literal; - break; - - default: - parse_literal: - - /* We are expecting an atom. If the subexpression (or the whole - regexp ends here, we interpret it as an empty expression - (which matches an empty string). */ - if ( - (ctx->re >= ctx->re_end - || *ctx->re == '*' - || (ctx->cflags & REG_EXTENDED - && (*ctx->re == '|' - || *ctx->re == '{' - || *ctx->re == '+' - || *ctx->re == '?')) - /* Test for "\)" in BRE mode. */ - || (!(ctx->cflags & REG_EXTENDED) - && ctx->re + 1 < ctx->re_end - && *ctx->re == '\\' - && *(ctx->re + 1) == '{'))) - { - DPRINT(("tre_parse: empty: '%.*" STRF "'\n", - ctx->re_end - ctx->re, ctx->re)); - result = tre_ast_new_literal(ctx->mem, EMPTY, -1, -1); - if (!result) - return REG_ESPACE; - break; - } - - DPRINT(("tre_parse: literal: '%.*" STRF "'\n", - ctx->re_end - ctx->re, ctx->re)); - /* Note that we can't use an tre_isalpha() test here, since there - may be characters which are alphabetic but neither upper or - lower case. */ - if (ctx->cflags & REG_ICASE - && (tre_isupper(*ctx->re) || tre_islower(*ctx->re))) - { - tre_ast_node_t *tmp1; - tre_ast_node_t *tmp2; - - /* XXX - Can there be more than one opposite-case - counterpoints for some character in some locale? Or - more than two characters which all should be regarded - the same character if case is ignored? If yes, there - does not seem to be a portable way to detect it. I guess - that at least for multi-character collating elements there - could be several opposite-case counterpoints, but they - cannot be supported portably anyway. */ - tmp1 = tre_ast_new_literal(ctx->mem, tre_toupper(*ctx->re), - tre_toupper(*ctx->re), - ctx->position); - if (!tmp1) - return REG_ESPACE; - tmp2 = tre_ast_new_literal(ctx->mem, tre_tolower(*ctx->re), - tre_tolower(*ctx->re), - ctx->position); - if (!tmp2) - return REG_ESPACE; - result = tre_ast_new_union(ctx->mem, tmp1, tmp2); - if (!result) - return REG_ESPACE; - } - else - { - result = tre_ast_new_literal(ctx->mem, *ctx->re, *ctx->re, - ctx->position); - if (!result) - return REG_ESPACE; - } - ctx->position++; - ctx->re++; - break; - } - break; - - case PARSE_MARK_FOR_SUBMATCH: - { - int submatch_id = (int)tre_stack_pop(stack); - - if (result->submatch_id >= 0) - { - tre_ast_node_t *n, *tmp_node; - n = tre_ast_new_literal(ctx->mem, EMPTY, -1, -1); - if (n == NULL) - return REG_ESPACE; - tmp_node = tre_ast_new_catenation(ctx->mem, n, result); - if (tmp_node == NULL) - return REG_ESPACE; - tmp_node->num_submatches = result->num_submatches; - result = tmp_node; - } - result->submatch_id = submatch_id; - result->num_submatches++; - break; - } - - case PARSE_RESTORE_CFLAGS: - ctx->cflags = (int)tre_stack_pop(stack); - break; - } - } - - /* Check for missing closing parentheses. */ - if (depth > 0) - return REG_EPAREN; - - if (status == REG_OK) - ctx->result = result; - - return status; -} - - -/*********************************************************************** - from tre-compile.c -***********************************************************************/ - -/* - Algorithms to setup tags so that submatch addressing can be done. -*/ - - -/* Inserts a catenation node to the root of the tree given in `node'. - As the left child a new tag with number `tag_id' to `node' is added, - and the right child is the old root. */ -/* OR */ -/* Inserts a catenation node to the root of the tree given in `node'. - As the right child a new tag with number `tag_id' to `node' is added, - and the left child is the old root. */ -static reg_errcode_t -tre_add_tag(tre_mem_t mem, tre_ast_node_t *node, int tag_id, int right) -{ - tre_catenation_t *c; - tre_ast_node_t *child_tag, *child_old; - - DPRINT(("add_tag_%s: tag %d\n", right ? "right" : "left", tag_id)); - - c = tre_mem_alloc(mem, sizeof(*c)); - if (c == NULL) - return REG_ESPACE; - child_tag = tre_ast_new_literal(mem, TAG, tag_id, -1); - if (child_tag == NULL) - return REG_ESPACE; - child_old = tre_mem_alloc(mem, sizeof(tre_ast_node_t)); - if (child_old == NULL) - return REG_ESPACE; - - child_old->obj = node->obj; - child_old->type = node->type; - child_old->nullable = -1; - child_old->submatch_id = -1; - child_old->firstpos = NULL; - child_old->lastpos = NULL; - child_old->num_tags = 0; - node->obj = c; - node->type = CATENATION; - - c->right = c->left = child_old; - if (right) c->right = child_tag; - else c->left = child_tag; - - return REG_OK; -} - -typedef enum { - ADDTAGS_RECURSE, - ADDTAGS_AFTER_ITERATION, - ADDTAGS_AFTER_UNION_LEFT, - ADDTAGS_AFTER_UNION_RIGHT, - ADDTAGS_AFTER_CAT_LEFT, - ADDTAGS_AFTER_CAT_RIGHT, - ADDTAGS_SET_SUBMATCH_END -} tre_addtags_symbol_t; - - -typedef struct { - int tag; - int next_tag; -} tre_tag_states_t; - -/* Adds tags to appropriate locations in the parse tree in `tree', so that - subexpressions marked for submatch addressing can be traced. */ -static reg_errcode_t -tre_add_tags(tre_mem_t mem, tre_stack_t *stack, tre_ast_node_t *tree, - tre_tnfa_t *tnfa) -{ - reg_errcode_t status = REG_OK; - tre_addtags_symbol_t symbol; - tre_ast_node_t *node = tree; /* Tree node we are currently looking at. */ - int bottom = tre_stack_num_objects(stack); - /* True for first pass (counting number of needed tags) */ - int first_pass = (mem == NULL || tnfa == NULL); - int *regset, *orig_regset; - int num_tags = 0; /* Total number of tags. */ - int tag = 0; /* The tag that is to be added next. */ - int next_tag = 1; /* Next tag to use after this one. */ - int *parents; /* Stack of submatches the current submatch is - contained in. */ - tre_tag_states_t *saved_states; - - tre_tag_direction_t direction = TRE_TAG_MINIMIZE; - if (!first_pass) - tnfa->end_tag = 0; - - regset = xmalloc(sizeof(*regset) * ((tnfa->num_submatches + 1) * 2)); - if (regset == NULL) - return REG_ESPACE; - regset[0] = -1; - orig_regset = regset; - - parents = xmalloc(sizeof(*parents) * (tnfa->num_submatches + 1)); - if (parents == NULL) - { - xfree(regset); - return REG_ESPACE; - } - parents[0] = -1; - - saved_states = xmalloc(sizeof(*saved_states) * (tnfa->num_submatches + 1)); - if (saved_states == NULL) - { - xfree(regset); - xfree(parents); - return REG_ESPACE; - } - else - { - unsigned int i; - for (i = 0; i <= tnfa->num_submatches; i++) - saved_states[i].tag = -1; - } - - STACK_PUSH(stack, node); - STACK_PUSH(stack, ADDTAGS_RECURSE); - - while (tre_stack_num_objects(stack) > bottom) - { - if (status != REG_OK) - break; - - symbol = (tre_addtags_symbol_t)tre_stack_pop(stack); - switch (symbol) - { - - case ADDTAGS_SET_SUBMATCH_END: - { - int id = (int)tre_stack_pop(stack); - int i; - - /* Add end of this submatch to regset. */ - for (i = 0; regset[i] >= 0; i++); - regset[i] = id * 2 + 1; - regset[i + 1] = -1; - - /* Pop this submatch from the parents stack. */ - for (i = 0; parents[i] >= 0; i++); - parents[i - 1] = -1; - break; - } - - case ADDTAGS_RECURSE: - node = tre_stack_pop(stack); - - if (node->submatch_id >= 0) - { - int id = node->submatch_id; - int i; - - - /* Add start of this submatch to regset. */ - for (i = 0; regset[i] >= 0; i++); - regset[i] = id * 2; - regset[i + 1] = -1; - - if (!first_pass) - { - for (i = 0; parents[i] >= 0; i++); - tnfa->submatch_data[id].parents = NULL; - if (i > 0) - { - int *p = xmalloc(sizeof(*p) * (i + 1)); - if (p == NULL) - { - status = REG_ESPACE; - break; - } - assert(tnfa->submatch_data[id].parents == NULL); - tnfa->submatch_data[id].parents = p; - for (i = 0; parents[i] >= 0; i++) - p[i] = parents[i]; - p[i] = -1; - } - } - - /* Add end of this submatch to regset after processing this - node. */ - STACK_PUSHX(stack, node->submatch_id); - STACK_PUSHX(stack, ADDTAGS_SET_SUBMATCH_END); - } - - switch (node->type) - { - case LITERAL: - { - tre_literal_t *lit = node->obj; - - if (!IS_SPECIAL(lit) || IS_BACKREF(lit)) - { - int i; - DPRINT(("Literal %d-%d\n", - (int)lit->code_min, (int)lit->code_max)); - if (regset[0] >= 0) - { - /* Regset is not empty, so add a tag before the - literal or backref. */ - if (!first_pass) - { - status = tre_add_tag(mem, node, tag, 0 /*left*/); - tnfa->tag_directions[tag] = direction; - /* Go through the regset and set submatch data for - submatches that are using this tag. */ - for (i = 0; regset[i] >= 0; i++) - { - int id = regset[i] >> 1; - int start = !(regset[i] & 1); - DPRINT((" Using tag %d for %s offset of " - "submatch %d\n", tag, - start ? "start" : "end", id)); - if (start) - tnfa->submatch_data[id].so_tag = tag; - else - tnfa->submatch_data[id].eo_tag = tag; - } - } - else - { - DPRINT((" num_tags = 1\n")); - node->num_tags = 1; - } - - DPRINT((" num_tags++\n")); - regset[0] = -1; - tag = next_tag; - num_tags++; - next_tag++; - } - } - else - { - assert(!IS_TAG(lit)); - } - break; - } - case CATENATION: - { - tre_catenation_t *cat = node->obj; - tre_ast_node_t *left = cat->left; - tre_ast_node_t *right = cat->right; - int reserved_tag = -1; - DPRINT(("Catenation, next_tag = %d\n", next_tag)); - - - /* After processing right child. */ - STACK_PUSHX(stack, node); - STACK_PUSHX(stack, ADDTAGS_AFTER_CAT_RIGHT); - - /* Process right child. */ - STACK_PUSHX(stack, right); - STACK_PUSHX(stack, ADDTAGS_RECURSE); - - /* After processing left child. */ - STACK_PUSHX(stack, next_tag + left->num_tags); - DPRINT((" Pushing %d for after left\n", - next_tag + left->num_tags)); - if (left->num_tags > 0 && right->num_tags > 0) - { - /* Reserve the next tag to the right child. */ - DPRINT((" Reserving next_tag %d to right child\n", - next_tag)); - reserved_tag = next_tag; - next_tag++; - } - STACK_PUSHX(stack, reserved_tag); - STACK_PUSHX(stack, ADDTAGS_AFTER_CAT_LEFT); - - /* Process left child. */ - STACK_PUSHX(stack, left); - STACK_PUSHX(stack, ADDTAGS_RECURSE); - - } - break; - case ITERATION: - { - tre_iteration_t *iter = node->obj; - DPRINT(("Iteration\n")); - - if (first_pass) - { - STACK_PUSHX(stack, regset[0] >= 0); - } - else - { - STACK_PUSHX(stack, tag); - } - STACK_PUSHX(stack, node); - STACK_PUSHX(stack, ADDTAGS_AFTER_ITERATION); - - STACK_PUSHX(stack, iter->arg); - STACK_PUSHX(stack, ADDTAGS_RECURSE); - - /* Regset is not empty, so add a tag here. */ - if (regset[0] >= 0) - { - if (!first_pass) - { - int i; - status = tre_add_tag(mem, node, tag, 0 /*left*/); - tnfa->tag_directions[tag] = direction; - /* Go through the regset and set submatch data for - submatches that are using this tag. */ - for (i = 0; regset[i] >= 0; i++) - { - int id = regset[i] >> 1; - int start = !(regset[i] & 1); - DPRINT((" Using tag %d for %s offset of " - "submatch %d\n", tag, - start ? "start" : "end", id)); - if (start) - tnfa->submatch_data[id].so_tag = tag; - else - tnfa->submatch_data[id].eo_tag = tag; - } - } - - DPRINT((" num_tags++\n")); - regset[0] = -1; - tag = next_tag; - num_tags++; - next_tag++; - } - direction = TRE_TAG_MINIMIZE; - } - break; - case UNION: - { - tre_union_t *uni = node->obj; - tre_ast_node_t *left = uni->left; - tre_ast_node_t *right = uni->right; - int left_tag; - int right_tag; - - if (regset[0] >= 0) - { - left_tag = next_tag; - right_tag = next_tag + 1; - } - else - { - left_tag = tag; - right_tag = next_tag; - } - - DPRINT(("Union\n")); - - /* After processing right child. */ - STACK_PUSHX(stack, right_tag); - STACK_PUSHX(stack, left_tag); - STACK_PUSHX(stack, regset); - STACK_PUSHX(stack, regset[0] >= 0); - STACK_PUSHX(stack, node); - STACK_PUSHX(stack, right); - STACK_PUSHX(stack, left); - STACK_PUSHX(stack, ADDTAGS_AFTER_UNION_RIGHT); - - /* Process right child. */ - STACK_PUSHX(stack, right); - STACK_PUSHX(stack, ADDTAGS_RECURSE); - - /* After processing left child. */ - STACK_PUSHX(stack, ADDTAGS_AFTER_UNION_LEFT); - - /* Process left child. */ - STACK_PUSHX(stack, left); - STACK_PUSHX(stack, ADDTAGS_RECURSE); - - /* Regset is not empty, so add a tag here. */ - if (regset[0] >= 0) - { - if (!first_pass) - { - int i; - status = tre_add_tag(mem, node, tag, 0 /*left*/); - tnfa->tag_directions[tag] = direction; - /* Go through the regset and set submatch data for - submatches that are using this tag. */ - for (i = 0; regset[i] >= 0; i++) - { - int id = regset[i] >> 1; - int start = !(regset[i] & 1); - DPRINT((" Using tag %d for %s offset of " - "submatch %d\n", tag, - start ? "start" : "end", id)); - if (start) - tnfa->submatch_data[id].so_tag = tag; - else - tnfa->submatch_data[id].eo_tag = tag; - } - } - - DPRINT((" num_tags++\n")); - regset[0] = -1; - tag = next_tag; - num_tags++; - next_tag++; - } - - if (node->num_submatches > 0) - { - /* The next two tags are reserved for markers. */ - next_tag++; - tag = next_tag; - next_tag++; - } - - break; - } - } - - if (node->submatch_id >= 0) - { - int i; - /* Push this submatch on the parents stack. */ - for (i = 0; parents[i] >= 0; i++); - parents[i] = node->submatch_id; - parents[i + 1] = -1; - } - - break; /* end case: ADDTAGS_RECURSE */ - - case ADDTAGS_AFTER_ITERATION: - { - int enter_tag; - node = tre_stack_pop(stack); - if (first_pass) - node->num_tags = ((tre_iteration_t *)node->obj)->arg->num_tags - + (int)tre_stack_pop(stack); - else - enter_tag = (int)tre_stack_pop(stack); - - DPRINT(("After iteration\n")); - direction = TRE_TAG_MAXIMIZE; - break; - } - - case ADDTAGS_AFTER_CAT_LEFT: - { - int new_tag = (int)tre_stack_pop(stack); - next_tag = (int)tre_stack_pop(stack); - DPRINT(("After cat left, tag = %d, next_tag = %d\n", - tag, next_tag)); - if (new_tag >= 0) - { - DPRINT((" Setting tag to %d\n", new_tag)); - tag = new_tag; - } - break; - } - - case ADDTAGS_AFTER_CAT_RIGHT: - DPRINT(("After cat right\n")); - node = tre_stack_pop(stack); - if (first_pass) - node->num_tags = ((tre_catenation_t *)node->obj)->left->num_tags - + ((tre_catenation_t *)node->obj)->right->num_tags; - break; - - case ADDTAGS_AFTER_UNION_LEFT: - DPRINT(("After union left\n")); - /* Lift the bottom of the `regset' array so that when processing - the right operand the items currently in the array are - invisible. The original bottom was saved at ADDTAGS_UNION and - will be restored at ADDTAGS_AFTER_UNION_RIGHT below. */ - while (*regset >= 0) - regset++; - break; - - case ADDTAGS_AFTER_UNION_RIGHT: - { - int added_tags, tag_left, tag_right; - tre_ast_node_t *left = tre_stack_pop(stack); - tre_ast_node_t *right = tre_stack_pop(stack); - DPRINT(("After union right\n")); - node = tre_stack_pop(stack); - added_tags = (int)tre_stack_pop(stack); - if (first_pass) - { - node->num_tags = ((tre_union_t *)node->obj)->left->num_tags - + ((tre_union_t *)node->obj)->right->num_tags + added_tags - + ((node->num_submatches > 0) ? 2 : 0); - } - regset = tre_stack_pop(stack); - tag_left = (int)tre_stack_pop(stack); - tag_right = (int)tre_stack_pop(stack); - - /* Add tags after both children, the left child gets a smaller - tag than the right child. This guarantees that we prefer - the left child over the right child. */ - /* XXX - This is not always necessary (if the children have - tags which must be seen for every match of that child). */ - /* XXX - Check if this is the only place where tre_add_tag_right - is used. If so, use tre_add_tag_left (putting the tag before - the child as opposed after the child) and throw away - tre_add_tag_right. */ - if (node->num_submatches > 0) - { - if (!first_pass) - { - status = tre_add_tag(mem, left, tag_left, 1 /*right*/); - tnfa->tag_directions[tag] = TRE_TAG_MAXIMIZE; - status = tre_add_tag(mem, right, tag_right, 1 /*right*/); - tnfa->tag_directions[tag] = TRE_TAG_MAXIMIZE; - } - DPRINT((" num_tags += 2\n")); - num_tags += 2; - } - direction = TRE_TAG_MAXIMIZE; - break; - } - - default: - assert(0); - break; - - } /* end switch(symbol) */ - } /* end while(tre_stack_num_objects(stack) > bottom) */ - - if (!first_pass) - { - int i; - /* Go through the regset and set submatch data for - submatches that are using this tag. */ - for (i = 0; regset[i] >= 0; i++) - { - int id = regset[i] >> 1; - int start = !(regset[i] & 1); - DPRINT((" Using tag %d for %s offset of " - "submatch %d\n", num_tags, - start ? "start" : "end", id)); - if (start) - tnfa->submatch_data[id].so_tag = num_tags; - else - tnfa->submatch_data[id].eo_tag = num_tags; - } - } - - DPRINT(("tre_add_tags: %s complete. Number of tags %d.\n", - first_pass? "First pass" : "Second pass", num_tags)); - - assert(tree->num_tags == num_tags); - tnfa->end_tag = num_tags; - tnfa->num_tags = num_tags; - xfree(orig_regset); - xfree(parents); - xfree(saved_states); - return status; -} - - - -/* - AST to TNFA compilation routines. -*/ - -typedef enum { - COPY_RECURSE, - COPY_SET_RESULT_PTR -} tre_copyast_symbol_t; - -/* Flags for tre_copy_ast(). */ -#define COPY_REMOVE_TAGS 1 -#define COPY_MAXIMIZE_FIRST_TAG 2 - -static reg_errcode_t -tre_copy_ast(tre_mem_t mem, tre_stack_t *stack, tre_ast_node_t *ast, - int flags, int *pos_add, tre_tag_direction_t *tag_directions, - tre_ast_node_t **copy, int *max_pos) -{ - reg_errcode_t status = REG_OK; - int bottom = tre_stack_num_objects(stack); - int num_copied = 0; - int first_tag = 1; - tre_ast_node_t **result = copy; - tre_copyast_symbol_t symbol; - - STACK_PUSH(stack, ast); - STACK_PUSH(stack, COPY_RECURSE); - - while (status == REG_OK && tre_stack_num_objects(stack) > bottom) - { - tre_ast_node_t *node; - if (status != REG_OK) - break; - - symbol = (tre_copyast_symbol_t)tre_stack_pop(stack); - switch (symbol) - { - case COPY_SET_RESULT_PTR: - result = tre_stack_pop(stack); - break; - case COPY_RECURSE: - node = tre_stack_pop(stack); - switch (node->type) - { - case LITERAL: - { - tre_literal_t *lit = node->obj; - int pos = lit->position; - int min = lit->code_min; - int max = lit->code_max; - if (!IS_SPECIAL(lit) || IS_BACKREF(lit)) - { - /* XXX - e.g. [ab] has only one position but two - nodes, so we are creating holes in the state space - here. Not fatal, just wastes memory. */ - pos += *pos_add; - num_copied++; - } - else if (IS_TAG(lit) && (flags & COPY_REMOVE_TAGS)) - { - /* Change this tag to empty. */ - min = EMPTY; - max = pos = -1; - } - else if (IS_TAG(lit) && (flags & COPY_MAXIMIZE_FIRST_TAG) - && first_tag) - { - /* Maximize the first tag. */ - tag_directions[max] = TRE_TAG_MAXIMIZE; - first_tag = 0; - } - *result = tre_ast_new_literal(mem, min, max, pos); - if (*result == NULL) - status = REG_ESPACE; - - if (pos > *max_pos) - *max_pos = pos; - break; - } - case UNION: - { - tre_union_t *uni = node->obj; - tre_union_t *copy; - *result = tre_ast_new_union(mem, uni->left, uni->right); - if (*result == NULL) - { - status = REG_ESPACE; - break; - } - copy = (*result)->obj; - result = ©->left; - STACK_PUSHX(stack, uni->right); - STACK_PUSHX(stack, COPY_RECURSE); - STACK_PUSHX(stack, ©->right); - STACK_PUSHX(stack, COPY_SET_RESULT_PTR); - STACK_PUSHX(stack, uni->left); - STACK_PUSHX(stack, COPY_RECURSE); - break; - } - case CATENATION: - { - tre_catenation_t *cat = node->obj; - tre_catenation_t *copy; - *result = tre_ast_new_catenation(mem, cat->left, cat->right); - if (*result == NULL) - { - status = REG_ESPACE; - break; - } - copy = (*result)->obj; - copy->left = NULL; - copy->right = NULL; - result = ©->left; - - STACK_PUSHX(stack, cat->right); - STACK_PUSHX(stack, COPY_RECURSE); - STACK_PUSHX(stack, ©->right); - STACK_PUSHX(stack, COPY_SET_RESULT_PTR); - STACK_PUSHX(stack, cat->left); - STACK_PUSHX(stack, COPY_RECURSE); - break; - } - case ITERATION: - { - tre_iteration_t *iter = node->obj; - STACK_PUSHX(stack, iter->arg); - STACK_PUSHX(stack, COPY_RECURSE); - *result = tre_ast_new_iter(mem, iter->arg, iter->min, iter->max); - if (*result == NULL) - { - status = REG_ESPACE; - break; - } - iter = (*result)->obj; - result = &iter->arg; - break; - } - default: - assert(0); - break; - } - break; - } - } - *pos_add += num_copied; - return status; -} - -typedef enum { - EXPAND_RECURSE, - EXPAND_AFTER_ITER -} tre_expand_ast_symbol_t; - -/* Expands each iteration node that has a finite nonzero minimum or maximum - iteration count to a catenated sequence of copies of the node. */ -static reg_errcode_t -tre_expand_ast(tre_mem_t mem, tre_stack_t *stack, tre_ast_node_t *ast, - int *position, tre_tag_direction_t *tag_directions, - int *max_depth) -{ - reg_errcode_t status = REG_OK; - int bottom = tre_stack_num_objects(stack); - int pos_add = 0; - int pos_add_total = 0; - int max_pos = 0; - /* Approximate parameter nesting level. */ - int iter_depth = 0; - - STACK_PUSHR(stack, ast); - STACK_PUSHR(stack, EXPAND_RECURSE); - while (status == REG_OK && tre_stack_num_objects(stack) > bottom) - { - tre_ast_node_t *node; - tre_expand_ast_symbol_t symbol; - - if (status != REG_OK) - break; - - DPRINT(("pos_add %d\n", pos_add)); - - symbol = (tre_expand_ast_symbol_t)tre_stack_pop(stack); - node = tre_stack_pop(stack); - switch (symbol) - { - case EXPAND_RECURSE: - switch (node->type) - { - case LITERAL: - { - tre_literal_t *lit= node->obj; - if (!IS_SPECIAL(lit) || IS_BACKREF(lit)) - { - lit->position += pos_add; - if (lit->position > max_pos) - max_pos = lit->position; - } - break; - } - case UNION: - { - tre_union_t *uni = node->obj; - STACK_PUSHX(stack, uni->right); - STACK_PUSHX(stack, EXPAND_RECURSE); - STACK_PUSHX(stack, uni->left); - STACK_PUSHX(stack, EXPAND_RECURSE); - break; - } - case CATENATION: - { - tre_catenation_t *cat = node->obj; - STACK_PUSHX(stack, cat->right); - STACK_PUSHX(stack, EXPAND_RECURSE); - STACK_PUSHX(stack, cat->left); - STACK_PUSHX(stack, EXPAND_RECURSE); - break; - } - case ITERATION: - { - tre_iteration_t *iter = node->obj; - STACK_PUSHX(stack, pos_add); - STACK_PUSHX(stack, node); - STACK_PUSHX(stack, EXPAND_AFTER_ITER); - STACK_PUSHX(stack, iter->arg); - STACK_PUSHX(stack, EXPAND_RECURSE); - /* If we are going to expand this node at EXPAND_AFTER_ITER - then don't increase the `pos' fields of the nodes now, it - will get done when expanding. */ - if (iter->min > 1 || iter->max > 1) - pos_add = 0; - iter_depth++; - DPRINT(("iter\n")); - break; - } - default: - assert(0); - break; - } - break; - case EXPAND_AFTER_ITER: - { - tre_iteration_t *iter = node->obj; - int pos_add_last; - pos_add = (int)tre_stack_pop(stack); - pos_add_last = pos_add; - if (iter->min > 1 || iter->max > 1) - { - tre_ast_node_t *seq1 = NULL, *seq2 = NULL; - int i; - int pos_add_save = pos_add; - - /* Create a catenated sequence of copies of the node. */ - for (i = 0; i < iter->min; i++) - { - tre_ast_node_t *copy; - /* Remove tags from all but the last copy. */ - int flags = ((i + 1 < iter->min) - ? COPY_REMOVE_TAGS - : COPY_MAXIMIZE_FIRST_TAG); - DPRINT((" pos_add %d\n", pos_add)); - pos_add_save = pos_add; - status = tre_copy_ast(mem, stack, iter->arg, flags, - &pos_add, tag_directions, ©, - &max_pos); - if (status != REG_OK) - return status; - if (seq1 != NULL) - seq1 = tre_ast_new_catenation(mem, seq1, copy); - else - seq1 = copy; - if (seq1 == NULL) - return REG_ESPACE; - } - - if (iter->max == -1) - { - /* No upper limit. */ - pos_add_save = pos_add; - status = tre_copy_ast(mem, stack, iter->arg, 0, - &pos_add, NULL, &seq2, &max_pos); - if (status != REG_OK) - return status; - seq2 = tre_ast_new_iter(mem, seq2, 0, -1); - if (seq2 == NULL) - return REG_ESPACE; - } - else - { - for (i = iter->min; i < iter->max; i++) - { - tre_ast_node_t *tmp, *copy; - pos_add_save = pos_add; - status = tre_copy_ast(mem, stack, iter->arg, 0, - &pos_add, NULL, ©, &max_pos); - if (status != REG_OK) - return status; - if (seq2 != NULL) - seq2 = tre_ast_new_catenation(mem, copy, seq2); - else - seq2 = copy; - if (seq2 == NULL) - return REG_ESPACE; - tmp = tre_ast_new_literal(mem, EMPTY, -1, -1); - if (tmp == NULL) - return REG_ESPACE; - seq2 = tre_ast_new_union(mem, tmp, seq2); - if (seq2 == NULL) - return REG_ESPACE; - } - } - - pos_add = pos_add_save; - if (seq1 == NULL) - seq1 = seq2; - else if (seq2 != NULL) - seq1 = tre_ast_new_catenation(mem, seq1, seq2); - if (seq1 == NULL) - return REG_ESPACE; - node->obj = seq1->obj; - node->type = seq1->type; - } - - iter_depth--; - pos_add_total += pos_add - pos_add_last; - if (iter_depth == 0) - pos_add = pos_add_total; - - break; - } - default: - assert(0); - break; - } - } - - *position += pos_add_total; - - /* `max_pos' should never be larger than `*position' if the above - code works, but just an extra safeguard let's make sure - `*position' is set large enough so enough memory will be - allocated for the transition table. */ - if (max_pos > *position) - *position = max_pos; - -#ifdef TRE_DEBUG - DPRINT(("Expanded AST:\n")); - tre_ast_print(ast); - DPRINT(("*position %d, max_pos %d\n", *position, max_pos)); -#endif - - return status; -} - -static tre_pos_and_tags_t * -tre_set_empty(tre_mem_t mem) -{ - tre_pos_and_tags_t *new_set; - - new_set = tre_mem_calloc(mem, sizeof(*new_set)); - if (new_set == NULL) - return NULL; - - new_set[0].position = -1; - new_set[0].code_min = -1; - new_set[0].code_max = -1; - - return new_set; -} - -static tre_pos_and_tags_t * -tre_set_one(tre_mem_t mem, int position, int code_min, int code_max, - tre_ctype_t class, tre_ctype_t *neg_classes, int backref) -{ - tre_pos_and_tags_t *new_set; - - new_set = tre_mem_calloc(mem, sizeof(*new_set) * 2); - if (new_set == NULL) - return NULL; - - new_set[0].position = position; - new_set[0].code_min = code_min; - new_set[0].code_max = code_max; - new_set[0].class = class; - new_set[0].neg_classes = neg_classes; - new_set[0].backref = backref; - new_set[1].position = -1; - new_set[1].code_min = -1; - new_set[1].code_max = -1; - - return new_set; -} - -static tre_pos_and_tags_t * -tre_set_union(tre_mem_t mem, tre_pos_and_tags_t *set1, tre_pos_and_tags_t *set2, - int *tags, int assertions) -{ - int s1, s2, i, j; - tre_pos_and_tags_t *new_set; - int *new_tags; - int num_tags; - - for (num_tags = 0; tags != NULL && tags[num_tags] >= 0; num_tags++); - for (s1 = 0; set1[s1].position >= 0; s1++); - for (s2 = 0; set2[s2].position >= 0; s2++); - new_set = tre_mem_calloc(mem, sizeof(*new_set) * (s1 + s2 + 1)); - if (!new_set ) - return NULL; - - for (s1 = 0; set1[s1].position >= 0; s1++) - { - new_set[s1].position = set1[s1].position; - new_set[s1].code_min = set1[s1].code_min; - new_set[s1].code_max = set1[s1].code_max; - new_set[s1].assertions = set1[s1].assertions | assertions; - new_set[s1].class = set1[s1].class; - new_set[s1].neg_classes = set1[s1].neg_classes; - new_set[s1].backref = set1[s1].backref; - if (set1[s1].tags == NULL && tags == NULL) - new_set[s1].tags = NULL; - else - { - for (i = 0; set1[s1].tags != NULL && set1[s1].tags[i] >= 0; i++); - new_tags = tre_mem_alloc(mem, (sizeof(*new_tags) - * (i + num_tags + 1))); - if (new_tags == NULL) - return NULL; - for (j = 0; j < i; j++) - new_tags[j] = set1[s1].tags[j]; - for (i = 0; i < num_tags; i++) - new_tags[j + i] = tags[i]; - new_tags[j + i] = -1; - new_set[s1].tags = new_tags; - } - } - - for (s2 = 0; set2[s2].position >= 0; s2++) - { - new_set[s1 + s2].position = set2[s2].position; - new_set[s1 + s2].code_min = set2[s2].code_min; - new_set[s1 + s2].code_max = set2[s2].code_max; - /* XXX - why not | assertions here as well? */ - new_set[s1 + s2].assertions = set2[s2].assertions; - new_set[s1 + s2].class = set2[s2].class; - new_set[s1 + s2].neg_classes = set2[s2].neg_classes; - new_set[s1 + s2].backref = set2[s2].backref; - if (set2[s2].tags == NULL) - new_set[s1 + s2].tags = NULL; - else - { - for (i = 0; set2[s2].tags[i] >= 0; i++); - new_tags = tre_mem_alloc(mem, sizeof(*new_tags) * (i + 1)); - if (new_tags == NULL) - return NULL; - for (j = 0; j < i; j++) - new_tags[j] = set2[s2].tags[j]; - new_tags[j] = -1; - new_set[s1 + s2].tags = new_tags; - } - } - new_set[s1 + s2].position = -1; - return new_set; -} - -/* Finds the empty path through `node' which is the one that should be - taken according to POSIX.2 rules, and adds the tags on that path to - `tags'. `tags' may be NULL. If `num_tags_seen' is not NULL, it is - set to the number of tags seen on the path. */ -static reg_errcode_t -tre_match_empty(tre_stack_t *stack, tre_ast_node_t *node, int *tags, - int *assertions, int *num_tags_seen) -{ - tre_literal_t *lit; - tre_union_t *uni; - tre_catenation_t *cat; - tre_iteration_t *iter; - int i; - int bottom = tre_stack_num_objects(stack); - reg_errcode_t status = REG_OK; - if (num_tags_seen) - *num_tags_seen = 0; - - status = tre_stack_push(stack, node); - - /* Walk through the tree recursively. */ - while (status == REG_OK && tre_stack_num_objects(stack) > bottom) - { - node = tre_stack_pop(stack); - - switch (node->type) - { - case LITERAL: - lit = (tre_literal_t *)node->obj; - switch (lit->code_min) - { - case TAG: - if (lit->code_max >= 0) - { - if (tags != NULL) - { - /* Add the tag to `tags'. */ - for (i = 0; tags[i] >= 0; i++) - if (tags[i] == lit->code_max) - break; - if (tags[i] < 0) - { - tags[i] = lit->code_max; - tags[i + 1] = -1; - } - } - if (num_tags_seen) - (*num_tags_seen)++; - } - break; - case ASSERTION: - assert(lit->code_max >= 1 - || lit->code_max <= ASSERT_LAST); - if (assertions != NULL) - *assertions |= lit->code_max; - break; - case EMPTY: - break; - default: - assert(0); - break; - } - break; - - case UNION: - /* Subexpressions starting earlier take priority over ones - starting later, so we prefer the left subexpression over the - right subexpression. */ - uni = (tre_union_t *)node->obj; - if (uni->left->nullable) - STACK_PUSHX(stack, uni->left) - else if (uni->right->nullable) - STACK_PUSHX(stack, uni->right) - else - assert(0); - break; - - case CATENATION: - /* The path must go through both children. */ - cat = (tre_catenation_t *)node->obj; - assert(cat->left->nullable); - assert(cat->right->nullable); - STACK_PUSHX(stack, cat->left); - STACK_PUSHX(stack, cat->right); - break; - - case ITERATION: - /* A match with an empty string is preferred over no match at - all, so we go through the argument if possible. */ - iter = (tre_iteration_t *)node->obj; - if (iter->arg->nullable) - STACK_PUSHX(stack, iter->arg); - break; - - default: - assert(0); - break; - } - } - - return status; -} - - -typedef enum { - NFL_RECURSE, - NFL_POST_UNION, - NFL_POST_CATENATION, - NFL_POST_ITERATION -} tre_nfl_stack_symbol_t; - - -/* Computes and fills in the fields `nullable', `firstpos', and `lastpos' for - the nodes of the AST `tree'. */ -static reg_errcode_t -tre_compute_nfl(tre_mem_t mem, tre_stack_t *stack, tre_ast_node_t *tree) -{ - int bottom = tre_stack_num_objects(stack); - - STACK_PUSHR(stack, tree); - STACK_PUSHR(stack, NFL_RECURSE); - - while (tre_stack_num_objects(stack) > bottom) - { - tre_nfl_stack_symbol_t symbol; - tre_ast_node_t *node; - - symbol = (tre_nfl_stack_symbol_t) tre_stack_pop(stack); - node = tre_stack_pop(stack); - switch (symbol) - { - case NFL_RECURSE: - switch (node->type) - { - case LITERAL: - { - tre_literal_t *lit = (tre_literal_t *)node->obj; - if (IS_BACKREF(lit)) - { - /* Back references: nullable = false, firstpos = {i}, - lastpos = {i}. */ - node->nullable = 0; - node->firstpos = tre_set_one(mem, lit->position, 0, - TRE_CHAR_MAX, 0, NULL, -1); - if (!node->firstpos) - return REG_ESPACE; - node->lastpos = tre_set_one(mem, lit->position, 0, - TRE_CHAR_MAX, 0, NULL, - lit->code_max); - if (!node->lastpos) - return REG_ESPACE; - } - else if (lit->code_min < 0) - { - /* Tags, empty strings and zero width assertions: - nullable = true, firstpos = {}, and lastpos = {}. */ - node->nullable = 1; - node->firstpos = tre_set_empty(mem); - if (!node->firstpos) - return REG_ESPACE; - node->lastpos = tre_set_empty(mem); - if (!node->lastpos) - return REG_ESPACE; - } - else - { - /* Literal at position i: nullable = false, firstpos = {i}, - lastpos = {i}. */ - node->nullable = 0; - node->firstpos = - tre_set_one(mem, lit->position, lit->code_min, - lit->code_max, 0, NULL, -1); - if (!node->firstpos) - return REG_ESPACE; - node->lastpos = tre_set_one(mem, lit->position, - lit->code_min, lit->code_max, - lit->class, lit->neg_classes, - -1); - if (!node->lastpos) - return REG_ESPACE; - } - break; - } - - case UNION: - /* Compute the attributes for the two subtrees, and after that - for this node. */ - STACK_PUSHR(stack, node); - STACK_PUSHR(stack, NFL_POST_UNION); - STACK_PUSHR(stack, ((tre_union_t *)node->obj)->right); - STACK_PUSHR(stack, NFL_RECURSE); - STACK_PUSHR(stack, ((tre_union_t *)node->obj)->left); - STACK_PUSHR(stack, NFL_RECURSE); - break; - - case CATENATION: - /* Compute the attributes for the two subtrees, and after that - for this node. */ - STACK_PUSHR(stack, node); - STACK_PUSHR(stack, NFL_POST_CATENATION); - STACK_PUSHR(stack, ((tre_catenation_t *)node->obj)->right); - STACK_PUSHR(stack, NFL_RECURSE); - STACK_PUSHR(stack, ((tre_catenation_t *)node->obj)->left); - STACK_PUSHR(stack, NFL_RECURSE); - break; - - case ITERATION: - /* Compute the attributes for the subtree, and after that for - this node. */ - STACK_PUSHR(stack, node); - STACK_PUSHR(stack, NFL_POST_ITERATION); - STACK_PUSHR(stack, ((tre_iteration_t *)node->obj)->arg); - STACK_PUSHR(stack, NFL_RECURSE); - break; - } - break; /* end case: NFL_RECURSE */ - - case NFL_POST_UNION: - { - tre_union_t *uni = (tre_union_t *)node->obj; - node->nullable = uni->left->nullable || uni->right->nullable; - node->firstpos = tre_set_union(mem, uni->left->firstpos, - uni->right->firstpos, NULL, 0); - if (!node->firstpos) - return REG_ESPACE; - node->lastpos = tre_set_union(mem, uni->left->lastpos, - uni->right->lastpos, NULL, 0); - if (!node->lastpos) - return REG_ESPACE; - break; - } - - case NFL_POST_ITERATION: - { - tre_iteration_t *iter = (tre_iteration_t *)node->obj; - - if (iter->min == 0 || iter->arg->nullable) - node->nullable = 1; - else - node->nullable = 0; - node->firstpos = iter->arg->firstpos; - node->lastpos = iter->arg->lastpos; - break; - } - - case NFL_POST_CATENATION: - { - int num_tags, *tags, assertions; - reg_errcode_t status; - tre_catenation_t *cat = node->obj; - node->nullable = cat->left->nullable && cat->right->nullable; - - /* Compute firstpos. */ - if (cat->left->nullable) - { - /* The left side matches the empty string. Make a first pass - with tre_match_empty() to get the number of tags. */ - status = tre_match_empty(stack, cat->left, - NULL, NULL, &num_tags); - if (status != REG_OK) - return status; - /* Allocate arrays for the tags and parameters. */ - tags = xmalloc(sizeof(*tags) * (num_tags + 1)); - if (!tags) - return REG_ESPACE; - tags[0] = -1; - assertions = 0; - /* Second pass with tre_mach_empty() to get the list of - tags. */ - status = tre_match_empty(stack, cat->left, tags, - &assertions, NULL); - if (status != REG_OK) - { - xfree(tags); - return status; - } - node->firstpos = - tre_set_union(mem, cat->right->firstpos, cat->left->firstpos, - tags, assertions); - xfree(tags); - if (!node->firstpos) - return REG_ESPACE; - } - else - { - node->firstpos = cat->left->firstpos; - } - - /* Compute lastpos. */ - if (cat->right->nullable) - { - /* The right side matches the empty string. Make a first pass - with tre_match_empty() to get the number of tags. */ - status = tre_match_empty(stack, cat->right, - NULL, NULL, &num_tags); - if (status != REG_OK) - return status; - /* Allocate arrays for the tags and parameters. */ - tags = xmalloc(sizeof(int) * (num_tags + 1)); - if (!tags) - return REG_ESPACE; - tags[0] = -1; - assertions = 0; - /* Second pass with tre_mach_empty() to get the list of - tags. */ - status = tre_match_empty(stack, cat->right, tags, - &assertions, NULL); - if (status != REG_OK) - { - xfree(tags); - return status; - } - node->lastpos = - tre_set_union(mem, cat->left->lastpos, cat->right->lastpos, - tags, assertions); - xfree(tags); - if (!node->lastpos) - return REG_ESPACE; - } - else - { - node->lastpos = cat->right->lastpos; - } - break; - } - - default: - assert(0); - break; - } - } - - return REG_OK; -} - - -/* Adds a transition from each position in `p1' to each position in `p2'. */ -static reg_errcode_t -tre_make_trans(tre_pos_and_tags_t *p1, tre_pos_and_tags_t *p2, - tre_tnfa_transition_t *transitions, - int *counts, int *offs) -{ - tre_pos_and_tags_t *orig_p2 = p2; - tre_tnfa_transition_t *trans; - int i, j, k, l, dup, prev_p2_pos; - - if (transitions != NULL) - while (p1->position >= 0) - { - p2 = orig_p2; - prev_p2_pos = -1; - while (p2->position >= 0) - { - /* Optimization: if this position was already handled, skip it. */ - if (p2->position == prev_p2_pos) - { - p2++; - continue; - } - prev_p2_pos = p2->position; - /* Set `trans' to point to the next unused transition from - position `p1->position'. */ - trans = transitions + offs[p1->position]; - while (trans->state != NULL) - { -#if 0 - /* If we find a previous transition from `p1->position' to - `p2->position', it is overwritten. This can happen only - if there are nested loops in the regexp, like in "((a)*)*". - In POSIX.2 repetition using the outer loop is always - preferred over using the inner loop. Therefore the - transition for the inner loop is useless and can be thrown - away. */ - /* XXX - The same position is used for all nodes in a bracket - expression, so this optimization cannot be used (it will - break bracket expressions) unless I figure out a way to - detect it here. */ - if (trans->state_id == p2->position) - { - DPRINT(("*")); - break; - } -#endif - trans++; - } - - if (trans->state == NULL) - (trans + 1)->state = NULL; - /* Use the character ranges, assertions, etc. from `p1' for - the transition from `p1' to `p2'. */ - trans->code_min = p1->code_min; - trans->code_max = p1->code_max; - trans->state = transitions + offs[p2->position]; - trans->state_id = p2->position; - trans->assertions = p1->assertions | p2->assertions - | (p1->class ? ASSERT_CHAR_CLASS : 0) - | (p1->neg_classes != NULL ? ASSERT_CHAR_CLASS_NEG : 0); - if (p1->backref >= 0) - { - assert((trans->assertions & ASSERT_CHAR_CLASS) == 0); - assert(p2->backref < 0); - trans->u.backref = p1->backref; - trans->assertions |= ASSERT_BACKREF; - } - else - trans->u.class = p1->class; - if (p1->neg_classes != NULL) - { - for (i = 0; p1->neg_classes[i] != (tre_ctype_t)0; i++); - trans->neg_classes = - xmalloc(sizeof(*trans->neg_classes) * (i + 1)); - if (trans->neg_classes == NULL) - return REG_ESPACE; - for (i = 0; p1->neg_classes[i] != (tre_ctype_t)0; i++) - trans->neg_classes[i] = p1->neg_classes[i]; - trans->neg_classes[i] = (tre_ctype_t)0; - } - else - trans->neg_classes = NULL; - - /* Find out how many tags this transition has. */ - i = 0; - if (p1->tags != NULL) - while(p1->tags[i] >= 0) - i++; - j = 0; - if (p2->tags != NULL) - while(p2->tags[j] >= 0) - j++; - - /* If we are overwriting a transition, free the old tag array. */ - if (trans->tags != NULL) - xfree(trans->tags); - trans->tags = NULL; - - /* If there were any tags, allocate an array and fill it. */ - if (i + j > 0) - { - trans->tags = xmalloc(sizeof(*trans->tags) * (i + j + 1)); - if (!trans->tags) - return REG_ESPACE; - i = 0; - if (p1->tags != NULL) - while(p1->tags[i] >= 0) - { - trans->tags[i] = p1->tags[i]; - i++; - } - l = i; - j = 0; - if (p2->tags != NULL) - while (p2->tags[j] >= 0) - { - /* Don't add duplicates. */ - dup = 0; - for (k = 0; k < i; k++) - if (trans->tags[k] == p2->tags[j]) - { - dup = 1; - break; - } - if (!dup) - trans->tags[l++] = p2->tags[j]; - j++; - } - trans->tags[l] = -1; - } - - -#ifdef TRE_DEBUG - { - int *tags; - - DPRINT((" %2d -> %2d on %3d", p1->position, p2->position, - p1->code_min)); - if (p1->code_max != p1->code_min) - DPRINT(("-%3d", p1->code_max)); - tags = trans->tags; - if (tags) - { - DPRINT((", tags [")); - while (*tags >= 0) - { - DPRINT(("%d", *tags)); - tags++; - if (*tags >= 0) - DPRINT((",")); - } - DPRINT(("]")); - } - if (trans->assertions) - DPRINT((", assert %d", trans->assertions)); - if (trans->assertions & ASSERT_BACKREF) - DPRINT((", backref %d", trans->u.backref)); - else if (trans->class) - DPRINT((", class %ld", (long)trans->class)); - if (trans->neg_classes) - DPRINT((", neg_classes %p", trans->neg_classes)); - DPRINT(("\n")); - } -#endif /* TRE_DEBUG */ - p2++; - } - p1++; - } - else - /* Compute a maximum limit for the number of transitions leaving - from each state. */ - while (p1->position >= 0) - { - p2 = orig_p2; - while (p2->position >= 0) - { - counts[p1->position]++; - p2++; - } - p1++; - } - return REG_OK; -} - -/* Converts the syntax tree to a TNFA. All the transitions in the TNFA are - labelled with one character range (there are no transitions on empty - strings). The TNFA takes O(n^2) space in the worst case, `n' is size of - the regexp. */ -static reg_errcode_t -tre_ast_to_tnfa(tre_ast_node_t *node, tre_tnfa_transition_t *transitions, - int *counts, int *offs) -{ - tre_union_t *uni; - tre_catenation_t *cat; - tre_iteration_t *iter; - reg_errcode_t errcode = REG_OK; - - /* XXX - recurse using a stack!. */ - switch (node->type) - { - case LITERAL: - break; - case UNION: - uni = (tre_union_t *)node->obj; - errcode = tre_ast_to_tnfa(uni->left, transitions, counts, offs); - if (errcode != REG_OK) - return errcode; - errcode = tre_ast_to_tnfa(uni->right, transitions, counts, offs); - break; - - case CATENATION: - cat = (tre_catenation_t *)node->obj; - /* Add a transition from each position in cat->left->lastpos - to each position in cat->right->firstpos. */ - errcode = tre_make_trans(cat->left->lastpos, cat->right->firstpos, - transitions, counts, offs); - if (errcode != REG_OK) - return errcode; - errcode = tre_ast_to_tnfa(cat->left, transitions, counts, offs); - if (errcode != REG_OK) - return errcode; - errcode = tre_ast_to_tnfa(cat->right, transitions, counts, offs); - break; - - case ITERATION: - iter = (tre_iteration_t *)node->obj; - assert(iter->max == -1 || iter->max == 1); - - if (iter->max == -1) - { - assert(iter->min == 0 || iter->min == 1); - /* Add a transition from each last position in the iterated - expression to each first position. */ - errcode = tre_make_trans(iter->arg->lastpos, iter->arg->firstpos, - transitions, counts, offs); - if (errcode != REG_OK) - return errcode; - } - errcode = tre_ast_to_tnfa(iter->arg, transitions, counts, offs); - break; - } - return errcode; -} - - -static void -tre_free(regex_t *preg) -{ - tre_tnfa_t *tnfa; - unsigned int i; - tre_tnfa_transition_t *trans; - - tnfa = (void *)preg->TRE_REGEX_T_FIELD; - if (!tnfa) - return; - - for (i = 0; i < tnfa->num_transitions; i++) - if (tnfa->transitions[i].state) - { - if (tnfa->transitions[i].tags) - xfree(tnfa->transitions[i].tags); - if (tnfa->transitions[i].neg_classes) - xfree(tnfa->transitions[i].neg_classes); - } - if (tnfa->transitions) - xfree(tnfa->transitions); - - if (tnfa->initial) - { - for (trans = tnfa->initial; trans->state; trans++) - { - if (trans->tags) - xfree(trans->tags); - } - xfree(tnfa->initial); - } - - if (tnfa->submatch_data) - { - for (i = 0; i < tnfa->num_submatches; i++) - if (tnfa->submatch_data[i].parents) - xfree(tnfa->submatch_data[i].parents); - xfree(tnfa->submatch_data); - } - - if (tnfa->tag_directions) - xfree(tnfa->tag_directions); - xfree(tnfa); -} - - -#define ERROR_EXIT(err) \ - do \ - { \ - errcode = err; \ - if (1) goto error_exit; \ - } \ - while (0) - - -static int -tre_compile(regex_t *preg, const tre_char_t *regex, size_t n, int cflags) -{ - tre_stack_t *stack; - tre_ast_node_t *tree, *tmp_ast_l, *tmp_ast_r; - tre_pos_and_tags_t *p; - int *counts = NULL, *offs = NULL; - int i, add = 0; - tre_tnfa_transition_t *transitions, *initial; - tre_tnfa_t *tnfa = NULL; - tre_submatch_data_t *submatch_data; - tre_tag_direction_t *tag_directions = NULL; - reg_errcode_t errcode; - tre_mem_t mem; - - /* Parse context. */ - tre_parse_ctx_t parse_ctx; - - /* Allocate a stack used throughout the compilation process for various - purposes. */ - stack = tre_stack_new(512, 10240, 128); - if (!stack) - return REG_ESPACE; - /* Allocate a fast memory allocator. */ - mem = tre_mem_new(); - if (!mem) - { - tre_stack_destroy(stack); - return REG_ESPACE; - } - - /* Parse the regexp. */ - memset(&parse_ctx, 0, sizeof(parse_ctx)); - parse_ctx.mem = mem; - parse_ctx.stack = stack; - parse_ctx.re = regex; - parse_ctx.len = n; - parse_ctx.cflags = cflags; - parse_ctx.max_backref = -1; - DPRINT(("tre_compile: parsing '%.*" STRF "'\n", n, regex)); - errcode = tre_parse(&parse_ctx); - if (errcode != REG_OK) - ERROR_EXIT(errcode); - preg->re_nsub = parse_ctx.submatch_id - 1; - tree = parse_ctx.result; - -#ifdef TRE_DEBUG - tre_ast_print(tree); -#endif /* TRE_DEBUG */ - - /* Referring to nonexistent subexpressions is illegal. */ - if (parse_ctx.max_backref > (int)preg->re_nsub) - ERROR_EXIT(REG_ESUBREG); - - /* Allocate the TNFA struct. */ - tnfa = xcalloc(1, sizeof(tre_tnfa_t)); - if (tnfa == NULL) - ERROR_EXIT(REG_ESPACE); - tnfa->have_backrefs = parse_ctx.max_backref >= 0; - tnfa->num_submatches = parse_ctx.submatch_id; - - /* Set up tags for submatch addressing. If REG_NOSUB is set and the - regexp does not have back references, this can be skipped. */ - if (tnfa->have_backrefs || !(cflags & REG_NOSUB)) - { - DPRINT(("tre_compile: setting up tags\n")); - - /* Figure out how many tags we will need. */ - errcode = tre_add_tags(NULL, stack, tree, tnfa); - if (errcode != REG_OK) - ERROR_EXIT(errcode); -#ifdef TRE_DEBUG - tre_ast_print(tree); -#endif /* TRE_DEBUG */ - - if (tnfa->num_tags > 0) - { - tag_directions = xmalloc(sizeof(*tag_directions) - * (tnfa->num_tags + 1)); - if (tag_directions == NULL) - ERROR_EXIT(REG_ESPACE); - tnfa->tag_directions = tag_directions; - memset(tag_directions, -1, - sizeof(*tag_directions) * (tnfa->num_tags + 1)); - } - - submatch_data = xcalloc(parse_ctx.submatch_id, sizeof(*submatch_data)); - if (submatch_data == NULL) - ERROR_EXIT(REG_ESPACE); - tnfa->submatch_data = submatch_data; - - errcode = tre_add_tags(mem, stack, tree, tnfa); - if (errcode != REG_OK) - ERROR_EXIT(errcode); - -#ifdef TRE_DEBUG - for (i = 0; i < parse_ctx.submatch_id; i++) - DPRINT(("pmatch[%d] = {t%d, t%d}\n", - i, submatch_data[i].so_tag, submatch_data[i].eo_tag)); - for (i = 0; i < tnfa->num_tags; i++) - DPRINT(("t%d is %s\n", i, - tag_directions[i] == TRE_TAG_MINIMIZE ? - "minimized" : "maximized")); -#endif /* TRE_DEBUG */ - } - - /* Expand iteration nodes. */ - errcode = tre_expand_ast(mem, stack, tree, &parse_ctx.position, - tag_directions, NULL); - if (errcode != REG_OK) - ERROR_EXIT(errcode); - - /* Add a dummy node for the final state. - XXX - For certain patterns this dummy node can be optimized away, - for example "a*" or "ab*". Figure out a simple way to detect - this possibility. */ - tmp_ast_l = tree; - tmp_ast_r = tre_ast_new_literal(mem, 0, 0, parse_ctx.position++); - if (tmp_ast_r == NULL) - ERROR_EXIT(REG_ESPACE); - - tree = tre_ast_new_catenation(mem, tmp_ast_l, tmp_ast_r); - if (tree == NULL) - ERROR_EXIT(REG_ESPACE); - -#ifdef TRE_DEBUG - tre_ast_print(tree); - DPRINT(("Number of states: %d\n", parse_ctx.position)); -#endif /* TRE_DEBUG */ - - errcode = tre_compute_nfl(mem, stack, tree); - if (errcode != REG_OK) - ERROR_EXIT(errcode); - - counts = xmalloc(sizeof(int) * parse_ctx.position); - if (counts == NULL) - ERROR_EXIT(REG_ESPACE); - - offs = xmalloc(sizeof(int) * parse_ctx.position); - if (offs == NULL) - ERROR_EXIT(REG_ESPACE); - - for (i = 0; i < parse_ctx.position; i++) - counts[i] = 0; - tre_ast_to_tnfa(tree, NULL, counts, NULL); - - add = 0; - for (i = 0; i < parse_ctx.position; i++) - { - offs[i] = add; - add += counts[i] + 1; - counts[i] = 0; - } - transitions = xcalloc(add + 1, sizeof(*transitions)); - if (transitions == NULL) - ERROR_EXIT(REG_ESPACE); - tnfa->transitions = transitions; - tnfa->num_transitions = add; - - DPRINT(("Converting to TNFA:\n")); - errcode = tre_ast_to_tnfa(tree, transitions, counts, offs); - if (errcode != REG_OK) - ERROR_EXIT(errcode); - - p = tree->firstpos; - i = 0; - while (p->position >= 0) - { - i++; - -#ifdef TRE_DEBUG - { - int *tags; - DPRINT(("initial: %d", p->position)); - tags = p->tags; - if (tags != NULL) - { - if (*tags >= 0) - DPRINT(("/")); - while (*tags >= 0) - { - DPRINT(("%d", *tags)); - tags++; - if (*tags >= 0) - DPRINT((",")); - } - } - DPRINT((", assert %d", p->assertions)); - DPRINT(("\n")); - } -#endif /* TRE_DEBUG */ - - p++; - } - - initial = xcalloc(i + 1, sizeof(tre_tnfa_transition_t)); - if (initial == NULL) - ERROR_EXIT(REG_ESPACE); - tnfa->initial = initial; - - i = 0; - for (p = tree->firstpos; p->position >= 0; p++) - { - initial[i].state = transitions + offs[p->position]; - initial[i].state_id = p->position; - initial[i].tags = NULL; - /* Copy the arrays p->tags, they are allocated - from a tre_mem object. */ - if (p->tags) - { - int j; - for (j = 0; p->tags[j] >= 0; j++); - initial[i].tags = xmalloc(sizeof(*p->tags) * (j + 1)); - if (!initial[i].tags) - ERROR_EXIT(REG_ESPACE); - memcpy(initial[i].tags, p->tags, sizeof(*p->tags) * (j + 1)); - } - initial[i].assertions = p->assertions; - i++; - } - initial[i].state = NULL; - - tnfa->num_transitions = add; - tnfa->final = transitions + offs[tree->lastpos[0].position]; - tnfa->num_states = parse_ctx.position; - tnfa->cflags = cflags; - - DPRINT(("final state %p\n", (void *)tnfa->final)); - - tre_mem_destroy(mem); - tre_stack_destroy(stack); - xfree(counts); - xfree(offs); - - preg->TRE_REGEX_T_FIELD = (void *)tnfa; - return REG_OK; - - error_exit: - /* Free everything that was allocated and return the error code. */ - tre_mem_destroy(mem); - if (stack != NULL) - tre_stack_destroy(stack); - if (counts != NULL) - xfree(counts); - if (offs != NULL) - xfree(offs); - preg->TRE_REGEX_T_FIELD = (void *)tnfa; - tre_free(preg); - return errcode; -} - - -/*********************************************************************** - from regcomp.c -***********************************************************************/ - -int -regcomp(regex_t *preg, const char *regex, int cflags) -{ - int ret; - tre_char_t *wregex; - size_t n = strlen(regex); - - if (n+1 > SIZE_MAX/sizeof(tre_char_t)) - return REG_ESPACE; - wregex = xmalloc(sizeof(tre_char_t) * (n + 1)); - if (wregex == NULL) - return REG_ESPACE; - - n = mbstowcs(wregex, regex, n+1); - if (n == (size_t)-1) { - xfree(wregex); - return REG_BADPAT; - } - - ret = tre_compile(preg, wregex, n, cflags); - xfree(wregex); - - return ret; -} - -void -regfree(regex_t *preg) -{ - tre_free(preg); -} - -/* EOF */ diff --git a/05/musl-final/src/regex/regerror.c b/05/musl-final/src/regex/regerror.c deleted file mode 100644 index 39d70b2..0000000 --- a/05/musl-final/src/regex/regerror.c +++ /dev/null @@ -1,75 +0,0 @@ -/* - regerror.c - POSIX regerror() implementation for TRE. - - Copyright (c) 2001-2006 Ville Laurikari . - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -*/ - -#include -#include - -/* Error message strings for error codes listed in `regex.h'. This list - needs to be in sync with the codes listed there, naturally. */ - -/* Converted to single string by Rich Felker to remove the need for - * data relocations at runtime, 27 Feb 2006. */ - -static const char tre_error_messages[] = { - "No error\0" - "No match\0" - "Invalid regexp\0" - "Unknown collating element\0" - "Unknown character class name\0" - "Trailing backslash\0" - "Invalid back reference\0" - "Missing ']'\0" - "Missing ')'\0" - "Missing '}'\0" - "Invalid contents of {}\0" - "Invalid character range\0" - "Out of memory\0" - "XXX\0" -}; - -size_t -regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size) -{ - const char *err; - size_t err_len; - - if (errcode >= 0 && errcode <= REG_BADRPT) - for (err=tre_error_messages; errcode; errcode--, err+=strlen(err)+1); - else - err = "Unknown error"; - - err_len = strlen(err) + 1; - if (errbuf_size > 0 && errbuf != NULL) - { - if (err_len > errbuf_size) - { - memcpy(errbuf, err, errbuf_size - 1); - errbuf[errbuf_size - 1] = '\0'; - } - else - { - strcpy(errbuf, err); - } - } - return err_len; -} - -/* EOF */ diff --git a/05/musl-final/src/regex/regexec.c b/05/musl-final/src/regex/regexec.c deleted file mode 100644 index 0c3d283..0000000 --- a/05/musl-final/src/regex/regexec.c +++ /dev/null @@ -1,1107 +0,0 @@ -/* - regexec.c - TRE POSIX compatible matching functions (and more). - - Copyright (c) 2001-2006 Ville Laurikari . - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -*/ - -#include -#include -#include -#include -#include - -#include - -#include "tre.h" - -#include - -static void -tre_fill_pmatch(size_t nmatch, regmatch_t pmatch[], int cflags, - const tre_tnfa_t *tnfa, int *tags, int match_eo); - -/*********************************************************************** - from tre-match-utils.h -***********************************************************************/ - -#define GET_NEXT_WCHAR() do { \ - prev_c = next_c; pos += pos_add_next; \ - if ((pos_add_next = mbtowc(&next_c, str_byte, MB_LEN_MAX)) <= 0) { \ - if (pos_add_next < 0) return REG_NOMATCH; \ - else pos_add_next++; \ - } \ - str_byte += pos_add_next; \ - } while (0) - -#define CHECK_ASSERTIONS(assertions) \ - (((assertions & ASSERT_AT_BOL) \ - && (pos > 0 || reg_notbol) \ - && (prev_c != L'\n' || !reg_newline)) \ - || ((assertions & ASSERT_AT_EOL) \ - && (next_c != L'\0' || reg_noteol) \ - && (next_c != L'\n' || !reg_newline))) - -/* Returns 1 if `t1' wins `t2', 0 otherwise. */ -static int -tre_tag_order(int num_tags, tre_tag_direction_t *tag_directions, - int *t1, int *t2) -{ - int i; - for (i = 0; i < num_tags; i++) - { - if (tag_directions[i] == TRE_TAG_MINIMIZE) - { - if (t1[i] < t2[i]) - return 1; - if (t1[i] > t2[i]) - return 0; - } - else - { - if (t1[i] > t2[i]) - return 1; - if (t1[i] < t2[i]) - return 0; - } - } - /* assert(0);*/ - return 0; -} - -static int -tre_neg_char_classes_match(tre_ctype_t *classes, tre_cint_t wc, int icase) -{ - DPRINT(("neg_char_classes_test: %p, %d, %d\n", classes, wc, icase)); - while (*classes != (tre_ctype_t)0) - if ((!icase && tre_isctype(wc, *classes)) - || (icase && (tre_isctype(tre_toupper(wc), *classes) - || tre_isctype(tre_tolower(wc), *classes)))) - return 1; /* Match. */ - else - classes++; - return 0; /* No match. */ -} - - -/*********************************************************************** - from tre-match-parallel.c -***********************************************************************/ - -/* - This algorithm searches for matches basically by reading characters - in the searched string one by one, starting at the beginning. All - matching paths in the TNFA are traversed in parallel. When two or - more paths reach the same state, exactly one is chosen according to - tag ordering rules; if returning submatches is not required it does - not matter which path is chosen. - - The worst case time required for finding the leftmost and longest - match, or determining that there is no match, is always linearly - dependent on the length of the text being searched. - - This algorithm cannot handle TNFAs with back referencing nodes. - See `tre-match-backtrack.c'. -*/ - - -typedef struct { - tre_tnfa_transition_t *state; - int *tags; -} tre_tnfa_reach_t; - -typedef struct { - int pos; - int **tags; -} tre_reach_pos_t; - - -#ifdef TRE_DEBUG -static void -tre_print_reach(const tre_tnfa_t *tnfa, tre_tnfa_reach_t *reach, int num_tags) -{ - int i; - - while (reach->state != NULL) - { - DPRINT((" %p", (void *)reach->state)); - if (num_tags > 0) - { - DPRINT(("/")); - for (i = 0; i < num_tags; i++) - { - DPRINT(("%d:%d", i, reach->tags[i])); - if (i < (num_tags-1)) - DPRINT((",")); - } - } - reach++; - } - DPRINT(("\n")); - -} -#endif /* TRE_DEBUG */ - -static reg_errcode_t -tre_tnfa_run_parallel(const tre_tnfa_t *tnfa, const void *string, int len, - int *match_tags, int eflags, int *match_end_ofs) -{ - /* State variables required by GET_NEXT_WCHAR. */ - tre_char_t prev_c = 0, next_c = 0; - const char *str_byte = string; - int pos = -1; - int pos_add_next = 1; -#ifdef TRE_MBSTATE - mbstate_t mbstate; -#endif /* TRE_MBSTATE */ - int reg_notbol = eflags & REG_NOTBOL; - int reg_noteol = eflags & REG_NOTEOL; - int reg_newline = tnfa->cflags & REG_NEWLINE; - - char *buf; - tre_tnfa_transition_t *trans_i; - tre_tnfa_reach_t *reach, *reach_next, *reach_i, *reach_next_i; - tre_reach_pos_t *reach_pos; - int *tag_i; - int num_tags, i; - - int match_eo = -1; /* end offset of match (-1 if no match found yet) */ - int new_match = 0; - int *tmp_tags = NULL; - int *tmp_iptr; - -#ifdef TRE_MBSTATE - memset(&mbstate, '\0', sizeof(mbstate)); -#endif /* TRE_MBSTATE */ - - if (!match_tags) - num_tags = 0; - else - num_tags = tnfa->num_tags; - - /* Allocate memory for temporary data required for matching. This needs to - be done for every matching operation to be thread safe. This allocates - everything in a single large block from the stack frame using alloca() - or with malloc() if alloca is unavailable. */ - { - int tbytes, rbytes, pbytes, xbytes, total_bytes; - char *tmp_buf; - /* Compute the length of the block we need. */ - tbytes = sizeof(*tmp_tags) * num_tags; - rbytes = sizeof(*reach_next) * (tnfa->num_states + 1); - pbytes = sizeof(*reach_pos) * tnfa->num_states; - xbytes = sizeof(int) * num_tags; - total_bytes = - (sizeof(long) - 1) * 4 /* for alignment paddings */ - + (rbytes + xbytes * tnfa->num_states) * 2 + tbytes + pbytes; - - /* Allocate the memory. */ -#ifdef TRE_USE_ALLOCA - buf = alloca(total_bytes); -#else /* !TRE_USE_ALLOCA */ - buf = xmalloc(total_bytes); -#endif /* !TRE_USE_ALLOCA */ - if (buf == NULL) - return REG_ESPACE; - memset(buf, 0, total_bytes); - - /* Get the various pointers within tmp_buf (properly aligned). */ - tmp_tags = (void *)buf; - tmp_buf = buf + tbytes; - tmp_buf += ALIGN(tmp_buf, long); - reach_next = (void *)tmp_buf; - tmp_buf += rbytes; - tmp_buf += ALIGN(tmp_buf, long); - reach = (void *)tmp_buf; - tmp_buf += rbytes; - tmp_buf += ALIGN(tmp_buf, long); - reach_pos = (void *)tmp_buf; - tmp_buf += pbytes; - tmp_buf += ALIGN(tmp_buf, long); - for (i = 0; i < tnfa->num_states; i++) - { - reach[i].tags = (void *)tmp_buf; - tmp_buf += xbytes; - reach_next[i].tags = (void *)tmp_buf; - tmp_buf += xbytes; - } - } - - for (i = 0; i < tnfa->num_states; i++) - reach_pos[i].pos = -1; - - GET_NEXT_WCHAR(); - pos = 0; - - DPRINT(("length: %d\n", len)); - DPRINT(("pos:chr/code | states and tags\n")); - DPRINT(("-------------+------------------------------------------------\n")); - - reach_next_i = reach_next; - while (1) - { - /* If no match found yet, add the initial states to `reach_next'. */ - if (match_eo < 0) - { - DPRINT((" init >")); - trans_i = tnfa->initial; - while (trans_i->state != NULL) - { - if (reach_pos[trans_i->state_id].pos < pos) - { - if (trans_i->assertions - && CHECK_ASSERTIONS(trans_i->assertions)) - { - DPRINT(("assertion failed\n")); - trans_i++; - continue; - } - - DPRINT((" %p", (void *)trans_i->state)); - reach_next_i->state = trans_i->state; - for (i = 0; i < num_tags; i++) - reach_next_i->tags[i] = -1; - tag_i = trans_i->tags; - if (tag_i) - while (*tag_i >= 0) - { - if (*tag_i < num_tags) - reach_next_i->tags[*tag_i] = pos; - tag_i++; - } - if (reach_next_i->state == tnfa->final) - { - DPRINT((" found empty match\n")); - match_eo = pos; - new_match = 1; - for (i = 0; i < num_tags; i++) - match_tags[i] = reach_next_i->tags[i]; - } - reach_pos[trans_i->state_id].pos = pos; - reach_pos[trans_i->state_id].tags = &reach_next_i->tags; - reach_next_i++; - } - trans_i++; - } - DPRINT(("\n")); - reach_next_i->state = NULL; - } - else - { - if (num_tags == 0 || reach_next_i == reach_next) - /* We have found a match. */ - break; - } - - /* Check for end of string. */ - if (!next_c) break; - - GET_NEXT_WCHAR(); - -#ifdef TRE_DEBUG - DPRINT(("%3d:%2lc/%05d |", pos - 1, (tre_cint_t)prev_c, (int)prev_c)); - tre_print_reach(tnfa, reach_next, num_tags); - DPRINT(("%3d:%2lc/%05d |", pos, (tre_cint_t)next_c, (int)next_c)); - tre_print_reach(tnfa, reach_next, num_tags); -#endif /* TRE_DEBUG */ - - /* Swap `reach' and `reach_next'. */ - reach_i = reach; - reach = reach_next; - reach_next = reach_i; - - /* For each state in `reach' see if there is a transition leaving with - the current input symbol to a state not yet in `reach_next', and - add the destination states to `reach_next'. */ - reach_next_i = reach_next; - for (reach_i = reach; reach_i->state; reach_i++) - { - for (trans_i = reach_i->state; trans_i->state; trans_i++) - { - /* Does this transition match the input symbol? */ - if (trans_i->code_min <= prev_c && - trans_i->code_max >= prev_c) - { - if (trans_i->assertions - && (CHECK_ASSERTIONS(trans_i->assertions) - /* Handle character class transitions. */ - || ((trans_i->assertions & ASSERT_CHAR_CLASS) - && !(tnfa->cflags & REG_ICASE) - && !tre_isctype((tre_cint_t)prev_c, - trans_i->u.class)) - || ((trans_i->assertions & ASSERT_CHAR_CLASS) - && (tnfa->cflags & REG_ICASE) - && (!tre_isctype(tre_tolower((tre_cint_t)prev_c), - trans_i->u.class) - && !tre_isctype(tre_toupper((tre_cint_t)prev_c), - trans_i->u.class))) - || ((trans_i->assertions & ASSERT_CHAR_CLASS_NEG) - && tre_neg_char_classes_match(trans_i->neg_classes, - (tre_cint_t)prev_c, - tnfa->cflags & REG_ICASE)))) - { - DPRINT(("assertion failed\n")); - continue; - } - - /* Compute the tags after this transition. */ - for (i = 0; i < num_tags; i++) - tmp_tags[i] = reach_i->tags[i]; - tag_i = trans_i->tags; - if (tag_i != NULL) - while (*tag_i >= 0) - { - if (*tag_i < num_tags) - tmp_tags[*tag_i] = pos; - tag_i++; - } - - if (reach_pos[trans_i->state_id].pos < pos) - { - /* Found an unvisited node. */ - reach_next_i->state = trans_i->state; - tmp_iptr = reach_next_i->tags; - reach_next_i->tags = tmp_tags; - tmp_tags = tmp_iptr; - reach_pos[trans_i->state_id].pos = pos; - reach_pos[trans_i->state_id].tags = &reach_next_i->tags; - - if (reach_next_i->state == tnfa->final - && (match_eo == -1 - || (num_tags > 0 - && reach_next_i->tags[0] <= match_tags[0]))) - { - DPRINT((" found match %p\n", trans_i->state)); - match_eo = pos; - new_match = 1; - for (i = 0; i < num_tags; i++) - match_tags[i] = reach_next_i->tags[i]; - } - reach_next_i++; - - } - else - { - assert(reach_pos[trans_i->state_id].pos == pos); - /* Another path has also reached this state. We choose - the winner by examining the tag values for both - paths. */ - if (tre_tag_order(num_tags, tnfa->tag_directions, - tmp_tags, - *reach_pos[trans_i->state_id].tags)) - { - /* The new path wins. */ - tmp_iptr = *reach_pos[trans_i->state_id].tags; - *reach_pos[trans_i->state_id].tags = tmp_tags; - if (trans_i->state == tnfa->final) - { - DPRINT((" found better match\n")); - match_eo = pos; - new_match = 1; - for (i = 0; i < num_tags; i++) - match_tags[i] = tmp_tags[i]; - } - tmp_tags = tmp_iptr; - } - } - } - } - } - reach_next_i->state = NULL; - } - - DPRINT(("match end offset = %d\n", match_eo)); - -#ifndef TRE_USE_ALLOCA - if (buf) - xfree(buf); -#endif /* !TRE_USE_ALLOCA */ - - *match_end_ofs = match_eo; - return match_eo >= 0 ? REG_OK : REG_NOMATCH; -} - - -/*********************************************************************** - from tre-match-backtrack.c -***********************************************************************/ - -/* - This matcher is for regexps that use back referencing. Regexp matching - with back referencing is an NP-complete problem on the number of back - references. The easiest way to match them is to use a backtracking - routine which basically goes through all possible paths in the TNFA - and chooses the one which results in the best (leftmost and longest) - match. This can be spectacularly expensive and may run out of stack - space, but there really is no better known generic algorithm. Quoting - Henry Spencer from comp.compilers: - - - POSIX.2 REs require longest match, which is really exciting to - implement since the obsolete ("basic") variant also includes - \. I haven't found a better way of tackling this than doing - a preliminary match using a DFA (or simulation) on a modified RE - that just replicates subREs for \, and then doing a - backtracking match to determine whether the subRE matches were - right. This can be rather slow, but I console myself with the - thought that people who use \ deserve very slow execution. - (Pun unintentional but very appropriate.) - -*/ - -typedef struct { - int pos; - const char *str_byte; - tre_tnfa_transition_t *state; - int state_id; - int next_c; - int *tags; -#ifdef TRE_MBSTATE - mbstate_t mbstate; -#endif /* TRE_MBSTATE */ -} tre_backtrack_item_t; - -typedef struct tre_backtrack_struct { - tre_backtrack_item_t item; - struct tre_backtrack_struct *prev; - struct tre_backtrack_struct *next; -} *tre_backtrack_t; - -#ifdef TRE_MBSTATE -#define BT_STACK_MBSTATE_IN stack->item.mbstate = (mbstate) -#define BT_STACK_MBSTATE_OUT (mbstate) = stack->item.mbstate -#else /* !TRE_MBSTATE */ -#define BT_STACK_MBSTATE_IN -#define BT_STACK_MBSTATE_OUT -#endif /* !TRE_MBSTATE */ - - -#ifdef TRE_USE_ALLOCA -#define tre_bt_mem_new tre_mem_newa -#define tre_bt_mem_alloc tre_mem_alloca -#define tre_bt_mem_destroy(obj) do { } while (0) -#else /* !TRE_USE_ALLOCA */ -#define tre_bt_mem_new tre_mem_new -#define tre_bt_mem_alloc tre_mem_alloc -#define tre_bt_mem_destroy tre_mem_destroy -#endif /* !TRE_USE_ALLOCA */ - - -#define BT_STACK_PUSH(_pos, _str_byte, _str_wide, _state, _state_id, _next_c, _tags, _mbstate) \ - do \ - { \ - int i; \ - if (!stack->next) \ - { \ - tre_backtrack_t s; \ - s = tre_bt_mem_alloc(mem, sizeof(*s)); \ - if (!s) \ - { \ - tre_bt_mem_destroy(mem); \ - if (tags) \ - xfree(tags); \ - if (pmatch) \ - xfree(pmatch); \ - if (states_seen) \ - xfree(states_seen); \ - return REG_ESPACE; \ - } \ - s->prev = stack; \ - s->next = NULL; \ - s->item.tags = tre_bt_mem_alloc(mem, \ - sizeof(*tags) * tnfa->num_tags); \ - if (!s->item.tags) \ - { \ - tre_bt_mem_destroy(mem); \ - if (tags) \ - xfree(tags); \ - if (pmatch) \ - xfree(pmatch); \ - if (states_seen) \ - xfree(states_seen); \ - return REG_ESPACE; \ - } \ - stack->next = s; \ - stack = s; \ - } \ - else \ - stack = stack->next; \ - stack->item.pos = (_pos); \ - stack->item.str_byte = (_str_byte); \ - stack->item.state = (_state); \ - stack->item.state_id = (_state_id); \ - stack->item.next_c = (_next_c); \ - for (i = 0; i < tnfa->num_tags; i++) \ - stack->item.tags[i] = (_tags)[i]; \ - BT_STACK_MBSTATE_IN; \ - } \ - while (0) - -#define BT_STACK_POP() \ - do \ - { \ - int i; \ - assert(stack->prev); \ - pos = stack->item.pos; \ - str_byte = stack->item.str_byte; \ - state = stack->item.state; \ - next_c = stack->item.next_c; \ - for (i = 0; i < tnfa->num_tags; i++) \ - tags[i] = stack->item.tags[i]; \ - BT_STACK_MBSTATE_OUT; \ - stack = stack->prev; \ - } \ - while (0) - -#undef MIN -#define MIN(a, b) ((a) <= (b) ? (a) : (b)) - -static reg_errcode_t -tre_tnfa_run_backtrack(const tre_tnfa_t *tnfa, const void *string, - int len, int *match_tags, - int eflags, int *match_end_ofs) -{ - /* State variables required by GET_NEXT_WCHAR. */ - tre_char_t prev_c = 0, next_c = 0; - const char *str_byte = string; - int pos = 0; - int pos_add_next = 1; -#ifdef TRE_MBSTATE - mbstate_t mbstate; -#endif /* TRE_MBSTATE */ - int reg_notbol = eflags & REG_NOTBOL; - int reg_noteol = eflags & REG_NOTEOL; - int reg_newline = tnfa->cflags & REG_NEWLINE; - - /* These are used to remember the necessary values of the above - variables to return to the position where the current search - started from. */ - int next_c_start; - const char *str_byte_start; - int pos_start = -1; -#ifdef TRE_MBSTATE - mbstate_t mbstate_start; -#endif /* TRE_MBSTATE */ - - /* Compilation flags for this regexp. */ - int cflags = tnfa->cflags; - - /* End offset of best match so far, or -1 if no match found yet. */ - int match_eo = -1; - /* Tag arrays. */ - int *next_tags, *tags = NULL; - /* Current TNFA state. */ - tre_tnfa_transition_t *state; - int *states_seen = NULL; - - /* Memory allocator to for allocating the backtracking stack. */ - tre_mem_t mem = tre_bt_mem_new(); - - /* The backtracking stack. */ - tre_backtrack_t stack; - - tre_tnfa_transition_t *trans_i; - regmatch_t *pmatch = NULL; - int ret; - -#ifdef TRE_MBSTATE - memset(&mbstate, '\0', sizeof(mbstate)); -#endif /* TRE_MBSTATE */ - - if (!mem) - return REG_ESPACE; - stack = tre_bt_mem_alloc(mem, sizeof(*stack)); - if (!stack) - { - ret = REG_ESPACE; - goto error_exit; - } - stack->prev = NULL; - stack->next = NULL; - -#ifdef TRE_USE_ALLOCA - tags = alloca(sizeof(*tags) * tnfa->num_tags); - pmatch = alloca(sizeof(*pmatch) * tnfa->num_submatches); - states_seen = alloca(sizeof(*states_seen) * tnfa->num_states); -#else /* !TRE_USE_ALLOCA */ - tags = xmalloc(sizeof(*tags) * tnfa->num_tags); - if (!tags) - { - ret = REG_ESPACE; - goto error_exit; - } - pmatch = xmalloc(sizeof(*pmatch) * tnfa->num_submatches); - if (!pmatch) - { - ret = REG_ESPACE; - goto error_exit; - } - states_seen = xmalloc(sizeof(*states_seen) * tnfa->num_states); - if (!states_seen) - { - ret = REG_ESPACE; - goto error_exit; - } -#endif /* !TRE_USE_ALLOCA */ - - retry: - { - int i; - for (i = 0; i < tnfa->num_tags; i++) - { - tags[i] = -1; - if (match_tags) - match_tags[i] = -1; - } - for (i = 0; i < tnfa->num_states; i++) - states_seen[i] = 0; - } - - state = NULL; - pos = pos_start; - GET_NEXT_WCHAR(); - pos_start = pos; - next_c_start = next_c; - str_byte_start = str_byte; -#ifdef TRE_MBSTATE - mbstate_start = mbstate; -#endif /* TRE_MBSTATE */ - - /* Handle initial states. */ - next_tags = NULL; - for (trans_i = tnfa->initial; trans_i->state; trans_i++) - { - DPRINT(("> init %p, prev_c %lc\n", trans_i->state, (tre_cint_t)prev_c)); - if (trans_i->assertions && CHECK_ASSERTIONS(trans_i->assertions)) - { - DPRINT(("assert failed\n")); - continue; - } - if (state == NULL) - { - /* Start from this state. */ - state = trans_i->state; - next_tags = trans_i->tags; - } - else - { - /* Backtrack to this state. */ - DPRINT(("saving state %d for backtracking\n", trans_i->state_id)); - BT_STACK_PUSH(pos, str_byte, str_wide, trans_i->state, - trans_i->state_id, next_c, tags, mbstate); - { - int *tmp = trans_i->tags; - if (tmp) - while (*tmp >= 0) - stack->item.tags[*tmp++] = pos; - } - } - } - - if (next_tags) - for (; *next_tags >= 0; next_tags++) - tags[*next_tags] = pos; - - - DPRINT(("entering match loop, pos %d, str_byte %p\n", pos, str_byte)); - DPRINT(("pos:chr/code | state and tags\n")); - DPRINT(("-------------+------------------------------------------------\n")); - - if (state == NULL) - goto backtrack; - - while (1) - { - tre_tnfa_transition_t *trans_i, *next_state; - int empty_br_match; - - DPRINT(("start loop\n")); - if (state == tnfa->final) - { - DPRINT((" match found, %d %d\n", match_eo, pos)); - if (match_eo < pos - || (match_eo == pos - && match_tags - && tre_tag_order(tnfa->num_tags, tnfa->tag_directions, - tags, match_tags))) - { - int i; - /* This match wins the previous match. */ - DPRINT((" win previous\n")); - match_eo = pos; - if (match_tags) - for (i = 0; i < tnfa->num_tags; i++) - match_tags[i] = tags[i]; - } - /* Our TNFAs never have transitions leaving from the final state, - so we jump right to backtracking. */ - goto backtrack; - } - -#ifdef TRE_DEBUG - DPRINT(("%3d:%2lc/%05d | %p ", pos, (tre_cint_t)next_c, (int)next_c, - state)); - { - int i; - for (i = 0; i < tnfa->num_tags; i++) - DPRINT(("%d%s", tags[i], i < tnfa->num_tags - 1 ? ", " : "")); - DPRINT(("\n")); - } -#endif /* TRE_DEBUG */ - - /* Go to the next character in the input string. */ - empty_br_match = 0; - trans_i = state; - if (trans_i->state && trans_i->assertions & ASSERT_BACKREF) - { - /* This is a back reference state. All transitions leaving from - this state have the same back reference "assertion". Instead - of reading the next character, we match the back reference. */ - int so, eo, bt = trans_i->u.backref; - int bt_len; - int result; - - DPRINT((" should match back reference %d\n", bt)); - /* Get the substring we need to match against. Remember to - turn off REG_NOSUB temporarily. */ - tre_fill_pmatch(bt + 1, pmatch, tnfa->cflags & !REG_NOSUB, - tnfa, tags, pos); - so = pmatch[bt].rm_so; - eo = pmatch[bt].rm_eo; - bt_len = eo - so; - - if (len < 0) - { - result = strncmp((char*)string + so, str_byte - 1, bt_len); - } - else if (len - pos < bt_len) - result = 1; - else - result = memcmp((char*)string + so, str_byte - 1, bt_len); - - /* We can ignore multibyte characters here because the backref - string is already aligned at character boundaries. */ - if (result == 0) - { - /* Back reference matched. Check for infinite loop. */ - if (bt_len == 0) - empty_br_match = 1; - if (empty_br_match && states_seen[trans_i->state_id]) - { - DPRINT((" avoid loop\n")); - goto backtrack; - } - - states_seen[trans_i->state_id] = empty_br_match; - - /* Advance in input string and resync `prev_c', `next_c' - and pos. */ - DPRINT((" back reference matched\n")); - str_byte += bt_len - 1; - pos += bt_len - 1; - GET_NEXT_WCHAR(); - DPRINT((" pos now %d\n", pos)); - } - else - { - DPRINT((" back reference did not match\n")); - goto backtrack; - } - } - else - { - /* Check for end of string. */ - if (len < 0) - { - if (next_c == L'\0') - goto backtrack; - } - else - { - if (pos >= len) - goto backtrack; - } - - /* Read the next character. */ - GET_NEXT_WCHAR(); - } - - next_state = NULL; - for (trans_i = state; trans_i->state; trans_i++) - { - DPRINT((" transition %d-%d (%c-%c) %d to %d\n", - trans_i->code_min, trans_i->code_max, - trans_i->code_min, trans_i->code_max, - trans_i->assertions, trans_i->state_id)); - if (trans_i->code_min <= prev_c && trans_i->code_max >= prev_c) - { - if (trans_i->assertions - && (CHECK_ASSERTIONS(trans_i->assertions) - /* Handle character class transitions. */ - || ((trans_i->assertions & ASSERT_CHAR_CLASS) - && !(cflags & REG_ICASE) - && !tre_isctype((tre_cint_t)prev_c, trans_i->u.class)) - || ((trans_i->assertions & ASSERT_CHAR_CLASS) - && (cflags & REG_ICASE) - && (!tre_isctype(tre_tolower((tre_cint_t)prev_c), - trans_i->u.class) - && !tre_isctype(tre_toupper((tre_cint_t)prev_c), - trans_i->u.class))) - || ((trans_i->assertions & ASSERT_CHAR_CLASS_NEG) - && tre_neg_char_classes_match(trans_i->neg_classes, - (tre_cint_t)prev_c, - cflags & REG_ICASE)))) - { - DPRINT((" assertion failed\n")); - continue; - } - - if (next_state == NULL) - { - /* First matching transition. */ - DPRINT((" Next state is %d\n", trans_i->state_id)); - next_state = trans_i->state; - next_tags = trans_i->tags; - } - else - { - /* Second mathing transition. We may need to backtrack here - to take this transition instead of the first one, so we - push this transition in the backtracking stack so we can - jump back here if needed. */ - DPRINT((" saving state %d for backtracking\n", - trans_i->state_id)); - BT_STACK_PUSH(pos, str_byte, str_wide, trans_i->state, - trans_i->state_id, next_c, tags, mbstate); - { - int *tmp; - for (tmp = trans_i->tags; tmp && *tmp >= 0; tmp++) - stack->item.tags[*tmp] = pos; - } -#if 0 /* XXX - it's important not to look at all transitions here to keep - the stack small! */ - break; -#endif - } - } - } - - if (next_state != NULL) - { - /* Matching transitions were found. Take the first one. */ - state = next_state; - - /* Update the tag values. */ - if (next_tags) - while (*next_tags >= 0) - tags[*next_tags++] = pos; - } - else - { - backtrack: - /* A matching transition was not found. Try to backtrack. */ - if (stack->prev) - { - DPRINT((" backtracking\n")); - if (stack->item.state->assertions && ASSERT_BACKREF) - { - DPRINT((" states_seen[%d] = 0\n", - stack->item.state_id)); - states_seen[stack->item.state_id] = 0; - } - - BT_STACK_POP(); - } - else if (match_eo < 0) - { - /* Try starting from a later position in the input string. */ - /* Check for end of string. */ - if (len < 0) - { - if (next_c == L'\0') - { - DPRINT(("end of string.\n")); - break; - } - } - else - { - if (pos >= len) - { - DPRINT(("end of string.\n")); - break; - } - } - DPRINT(("restarting from next start position\n")); - next_c = next_c_start; -#ifdef TRE_MBSTATE - mbstate = mbstate_start; -#endif /* TRE_MBSTATE */ - str_byte = str_byte_start; - goto retry; - } - else - { - DPRINT(("finished\n")); - break; - } - } - } - - ret = match_eo >= 0 ? REG_OK : REG_NOMATCH; - *match_end_ofs = match_eo; - - error_exit: - tre_bt_mem_destroy(mem); -#ifndef TRE_USE_ALLOCA - if (tags) - xfree(tags); - if (pmatch) - xfree(pmatch); - if (states_seen) - xfree(states_seen); -#endif /* !TRE_USE_ALLOCA */ - - return ret; -} - - -/*********************************************************************** - from regexec.c -***********************************************************************/ - -/* Fills the POSIX.2 regmatch_t array according to the TNFA tag and match - endpoint values. */ -static void -tre_fill_pmatch(size_t nmatch, regmatch_t pmatch[], int cflags, - const tre_tnfa_t *tnfa, int *tags, int match_eo) -{ - tre_submatch_data_t *submatch_data; - unsigned int i, j; - int *parents; - - i = 0; - if (match_eo >= 0 && !(cflags & REG_NOSUB)) - { - /* Construct submatch offsets from the tags. */ - DPRINT(("end tag = t%d = %d\n", tnfa->end_tag, match_eo)); - submatch_data = tnfa->submatch_data; - while (i < tnfa->num_submatches && i < nmatch) - { - if (submatch_data[i].so_tag == tnfa->end_tag) - pmatch[i].rm_so = match_eo; - else - pmatch[i].rm_so = tags[submatch_data[i].so_tag]; - - if (submatch_data[i].eo_tag == tnfa->end_tag) - pmatch[i].rm_eo = match_eo; - else - pmatch[i].rm_eo = tags[submatch_data[i].eo_tag]; - - /* If either of the endpoints were not used, this submatch - was not part of the match. */ - if (pmatch[i].rm_so == -1 || pmatch[i].rm_eo == -1) - pmatch[i].rm_so = pmatch[i].rm_eo = -1; - - DPRINT(("pmatch[%d] = {t%d = %d, t%d = %d}\n", i, - submatch_data[i].so_tag, pmatch[i].rm_so, - submatch_data[i].eo_tag, pmatch[i].rm_eo)); - i++; - } - /* Reset all submatches that are not within all of their parent - submatches. */ - i = 0; - while (i < tnfa->num_submatches && i < nmatch) - { - if (pmatch[i].rm_eo == -1) - assert(pmatch[i].rm_so == -1); - assert(pmatch[i].rm_so <= pmatch[i].rm_eo); - - parents = submatch_data[i].parents; - if (parents != NULL) - for (j = 0; parents[j] >= 0; j++) - { - DPRINT(("pmatch[%d] parent %d\n", i, parents[j])); - if (pmatch[i].rm_so < pmatch[parents[j]].rm_so - || pmatch[i].rm_eo > pmatch[parents[j]].rm_eo) - pmatch[i].rm_so = pmatch[i].rm_eo = -1; - } - i++; - } - } - - while (i < nmatch) - { - pmatch[i].rm_so = -1; - pmatch[i].rm_eo = -1; - i++; - } -} - - -/* - Wrapper functions for POSIX compatible regexp matching. -*/ - -static int -tre_match(const tre_tnfa_t *tnfa, const void *string, size_t len, - size_t nmatch, regmatch_t pmatch[], int eflags) -{ - reg_errcode_t status; - int *tags = NULL, eo; - if (tnfa->num_tags > 0 && nmatch > 0) - { -#ifdef TRE_USE_ALLOCA - tags = alloca(sizeof(*tags) * tnfa->num_tags); -#else /* !TRE_USE_ALLOCA */ - tags = xmalloc(sizeof(*tags) * tnfa->num_tags); -#endif /* !TRE_USE_ALLOCA */ - if (tags == NULL) - return REG_ESPACE; - } - - /* Dispatch to the appropriate matcher. */ - if (tnfa->have_backrefs) - { - /* The regex has back references, use the backtracking matcher. */ - status = tre_tnfa_run_backtrack(tnfa, string, len, tags, eflags, &eo); - } - else - { - /* Exact matching, no back references, use the parallel matcher. */ - status = tre_tnfa_run_parallel(tnfa, string, len, tags, eflags, &eo); - } - - if (status == REG_OK) - /* A match was found, so fill the submatch registers. */ - tre_fill_pmatch(nmatch, pmatch, tnfa->cflags, tnfa, tags, eo); -#ifndef TRE_USE_ALLOCA - if (tags) - xfree(tags); -#endif /* !TRE_USE_ALLOCA */ - return status; -} - -int -regexec(const regex_t *preg, const char *str, - size_t nmatch, regmatch_t pmatch[], int eflags) -{ - return tre_match((void *)preg->TRE_REGEX_T_FIELD, str, -1, - nmatch, pmatch, eflags); -} - -/* EOF */ diff --git a/05/musl-final/src/regex/tre-mem.c b/05/musl-final/src/regex/tre-mem.c deleted file mode 100644 index d7bdd3d..0000000 --- a/05/musl-final/src/regex/tre-mem.c +++ /dev/null @@ -1,163 +0,0 @@ -/* - tre-mem.c - TRE memory allocator - - Copyright (c) 2001-2006 Ville Laurikari - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -*/ - -/* - This memory allocator is for allocating small memory blocks efficiently - in terms of memory overhead and execution speed. The allocated blocks - cannot be freed individually, only all at once. There can be multiple - allocators, though. -*/ - -#include -#include - -#include "tre.h" - - -/* Returns a new memory allocator or NULL if out of memory. */ -tre_mem_t -tre_mem_new_impl(int provided, void *provided_block) -{ - tre_mem_t mem; - if (provided) - { - mem = provided_block; - memset(mem, 0, sizeof(*mem)); - } - else - mem = xcalloc(1, sizeof(*mem)); - if (mem == NULL) - return NULL; - return mem; -} - - -/* Frees the memory allocator and all memory allocated with it. */ -void -tre_mem_destroy(tre_mem_t mem) -{ - tre_list_t *tmp, *l = mem->blocks; - - while (l != NULL) - { - xfree(l->data); - tmp = l->next; - xfree(l); - l = tmp; - } - xfree(mem); -} - - -/* Allocates a block of `size' bytes from `mem'. Returns a pointer to the - allocated block or NULL if an underlying malloc() failed. */ -void * -tre_mem_alloc_impl(tre_mem_t mem, int provided, void *provided_block, - int zero, size_t size) -{ - void *ptr; - - if (mem->failed) - { - DPRINT(("tre_mem_alloc: oops, called after failure?!\n")); - return NULL; - } - -#ifdef MALLOC_DEBUGGING - if (!provided) - { - ptr = xmalloc(1); - if (ptr == NULL) - { - DPRINT(("tre_mem_alloc: xmalloc forced failure\n")); - mem->failed = 1; - return NULL; - } - xfree(ptr); - } -#endif /* MALLOC_DEBUGGING */ - - if (mem->n < size) - { - /* We need more memory than is available in the current block. - Allocate a new block. */ - tre_list_t *l; - if (provided) - { - DPRINT(("tre_mem_alloc: using provided block\n")); - if (provided_block == NULL) - { - DPRINT(("tre_mem_alloc: provided block was NULL\n")); - mem->failed = 1; - return NULL; - } - mem->ptr = provided_block; - mem->n = TRE_MEM_BLOCK_SIZE; - } - else - { - int block_size; - if (size * 8 > TRE_MEM_BLOCK_SIZE) - block_size = size * 8; - else - block_size = TRE_MEM_BLOCK_SIZE; - DPRINT(("tre_mem_alloc: allocating new %d byte block\n", - block_size)); - l = xmalloc(sizeof(*l)); - if (l == NULL) - { - mem->failed = 1; - return NULL; - } - l->data = xmalloc(block_size); - if (l->data == NULL) - { - xfree(l); - mem->failed = 1; - return NULL; - } - l->next = NULL; - if (mem->current != NULL) - mem->current->next = l; - if (mem->blocks == NULL) - mem->blocks = l; - mem->current = l; - mem->ptr = l->data; - mem->n = block_size; - } - } - - /* Make sure the next pointer will be aligned. */ - size += ALIGN(mem->ptr + size, long); - - /* Allocate from current block. */ - ptr = mem->ptr; - mem->ptr += size; - mem->n -= size; - - /* Set to zero if needed. */ - if (zero) - memset(ptr, 0, size); - - return ptr; -} - -/* EOF */ diff --git a/05/musl-final/src/regex/tre.h b/05/musl-final/src/regex/tre.h deleted file mode 100644 index bfd171f..0000000 --- a/05/musl-final/src/regex/tre.h +++ /dev/null @@ -1,269 +0,0 @@ -/* - tre-internal.h - TRE internal definitions - - Copyright (c) 2001-2006 Ville Laurikari . - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -*/ - -#include -#include -#include - -#define TRE_MULTIBYTE 1 -#undef TRE_MBSTATE -#define TRE_WCHAR 1 -#define TRE_USE_SYSTEM_WCTYPE 1 -#define HAVE_WCSTOMBS 1 -#define TRE_MB_CUR_MAX MB_CUR_MAX - -#define NDEBUG - -#define TRE_REGEX_T_FIELD __opaque -typedef int reg_errcode_t; - -typedef wchar_t tre_char_t; - - -#ifdef TRE_DEBUG -#include -#define DPRINT(msg) do {printf msg; fflush(stdout);} while(0) -#else /* !TRE_DEBUG */ -#define DPRINT(msg) do { } while(0) -#endif /* !TRE_DEBUG */ - -#define elementsof(x) ( sizeof(x) / sizeof(x[0]) ) - -#if 1 -int __mbtowc(wchar_t *, const char *); -#define tre_mbrtowc(pwc, s, n, ps) (__mbtowc((pwc), (s))) -#else -#define tre_mbrtowc(pwc, s, n, ps) (mbtowc((pwc), (s), (n))) -#endif - -/* Wide characters. */ -typedef wint_t tre_cint_t; -#define TRE_CHAR_MAX WCHAR_MAX - -#ifdef TRE_MULTIBYTE -#define TRE_MB_CUR_MAX MB_CUR_MAX -#else /* !TRE_MULTIBYTE */ -#define TRE_MB_CUR_MAX 1 -#endif /* !TRE_MULTIBYTE */ - -#define tre_isalnum iswalnum -#define tre_isalpha iswalpha -#define tre_isblank iswblank -#define tre_iscntrl iswcntrl -#define tre_isdigit iswdigit -#define tre_isgraph iswgraph -#define tre_islower iswlower -#define tre_isprint iswprint -#define tre_ispunct iswpunct -#define tre_isspace iswspace -#define tre_isupper iswupper -#define tre_isxdigit iswxdigit - -#define tre_tolower towlower -#define tre_toupper towupper -#define tre_strlen wcslen - -/* Use system provided iswctype() and wctype(). */ -typedef wctype_t tre_ctype_t; -#define tre_isctype iswctype -#define tre_ctype wctype - -/* Returns number of bytes to add to (char *)ptr to make it - properly aligned for the type. */ -#define ALIGN(ptr, type) \ - ((((long)ptr) % sizeof(type)) \ - ? (sizeof(type) - (((long)ptr) % sizeof(type))) \ - : 0) - -#undef MAX -#undef MIN -#define MAX(a, b) (((a) >= (b)) ? (a) : (b)) -#define MIN(a, b) (((a) <= (b)) ? (a) : (b)) - -/* Define STRF to the correct printf formatter for strings. */ -#define STRF "ls" - -/* TNFA transition type. A TNFA state is an array of transitions, - the terminator is a transition with NULL `state'. */ -typedef struct tnfa_transition tre_tnfa_transition_t; - -struct tnfa_transition { - /* Range of accepted characters. */ - tre_cint_t code_min; - tre_cint_t code_max; - /* Pointer to the destination state. */ - tre_tnfa_transition_t *state; - /* ID number of the destination state. */ - int state_id; - /* -1 terminated array of tags (or NULL). */ - int *tags; - /* Assertion bitmap. */ - int assertions; - /* Assertion parameters. */ - union { - /* Character class assertion. */ - tre_ctype_t class; - /* Back reference assertion. */ - int backref; - } u; - /* Negative character class assertions. */ - tre_ctype_t *neg_classes; -}; - - -/* Assertions. */ -#define ASSERT_AT_BOL 1 /* Beginning of line. */ -#define ASSERT_AT_EOL 2 /* End of line. */ -#define ASSERT_CHAR_CLASS 4 /* Character class in `class'. */ -#define ASSERT_CHAR_CLASS_NEG 8 /* Character classes in `neg_classes'. */ -#define ASSERT_AT_BOW 16 /* Beginning of word. */ -#define ASSERT_AT_EOW 32 /* End of word. */ -#define ASSERT_AT_WB 64 /* Word boundary. */ -#define ASSERT_AT_WB_NEG 128 /* Not a word boundary. */ -#define ASSERT_BACKREF 256 /* A back reference in `backref'. */ -#define ASSERT_LAST 256 - -/* Tag directions. */ -typedef enum { - TRE_TAG_MINIMIZE = 0, - TRE_TAG_MAXIMIZE = 1 -} tre_tag_direction_t; - -/* Instructions to compute submatch register values from tag values - after a successful match. */ -struct tre_submatch_data { - /* Tag that gives the value for rm_so (submatch start offset). */ - int so_tag; - /* Tag that gives the value for rm_eo (submatch end offset). */ - int eo_tag; - /* List of submatches this submatch is contained in. */ - int *parents; -}; - -typedef struct tre_submatch_data tre_submatch_data_t; - - -/* TNFA definition. */ -typedef struct tnfa tre_tnfa_t; - -struct tnfa { - tre_tnfa_transition_t *transitions; - unsigned int num_transitions; - tre_tnfa_transition_t *initial; - tre_tnfa_transition_t *final; - tre_submatch_data_t *submatch_data; - unsigned int num_submatches; - tre_tag_direction_t *tag_directions; - int num_tags; - int end_tag; - int num_states; - int cflags; - int have_backrefs; -}; - -#if 0 -static int -tre_compile(regex_t *preg, const tre_char_t *regex, size_t n, int cflags); - -static void -tre_free(regex_t *preg); - -static void -tre_fill_pmatch(size_t nmatch, regmatch_t pmatch[], int cflags, - const tre_tnfa_t *tnfa, int *tags, int match_eo); - -static reg_errcode_t -tre_tnfa_run_parallel(const tre_tnfa_t *tnfa, const void *string, int len, - tre_str_type_t type, int *match_tags, int eflags, - int *match_end_ofs); - -static reg_errcode_t -tre_tnfa_run_parallel(const tre_tnfa_t *tnfa, const void *string, int len, - tre_str_type_t type, int *match_tags, int eflags, - int *match_end_ofs); - -static reg_errcode_t -tre_tnfa_run_backtrack(const tre_tnfa_t *tnfa, const void *string, - int len, tre_str_type_t type, int *match_tags, - int eflags, int *match_end_ofs); -#endif - -/* from tre-mem.h: */ - -#define TRE_MEM_BLOCK_SIZE 1024 - -typedef struct tre_list { - void *data; - struct tre_list *next; -} tre_list_t; - -typedef struct tre_mem_struct { - tre_list_t *blocks; - tre_list_t *current; - char *ptr; - size_t n; - int failed; - void **provided; -} *tre_mem_t; - -#define tre_mem_new_impl __tre_mem_new_impl -#define tre_mem_alloc_impl __tre_mem_alloc_impl -#define tre_mem_destroy __tre_mem_destroy - -tre_mem_t tre_mem_new_impl(int provided, void *provided_block); -void *tre_mem_alloc_impl(tre_mem_t mem, int provided, void *provided_block, - int zero, size_t size); - -/* Returns a new memory allocator or NULL if out of memory. */ -#define tre_mem_new() tre_mem_new_impl(0, NULL) - -/* Allocates a block of `size' bytes from `mem'. Returns a pointer to the - allocated block or NULL if an underlying malloc() failed. */ -#define tre_mem_alloc(mem, size) tre_mem_alloc_impl(mem, 0, NULL, 0, size) - -/* Allocates a block of `size' bytes from `mem'. Returns a pointer to the - allocated block or NULL if an underlying malloc() failed. The memory - is set to zero. */ -#define tre_mem_calloc(mem, size) tre_mem_alloc_impl(mem, 0, NULL, 1, size) - -#ifdef TRE_USE_ALLOCA -/* alloca() versions. Like above, but memory is allocated with alloca() - instead of malloc(). */ - -#define tre_mem_newa() \ - tre_mem_new_impl(1, alloca(sizeof(struct tre_mem_struct))) - -#define tre_mem_alloca(mem, size) \ - ((mem)->n >= (size) \ - ? tre_mem_alloc_impl((mem), 1, NULL, 0, (size)) \ - : tre_mem_alloc_impl((mem), 1, alloca(TRE_MEM_BLOCK_SIZE), 0, (size))) -#endif /* TRE_USE_ALLOCA */ - - -/* Frees the memory allocator and all memory allocated with it. */ -void tre_mem_destroy(tre_mem_t mem); - -#define xmalloc malloc -#define xcalloc calloc -#define xfree free -#define xrealloc realloc - -/* EOF */ diff --git a/05/musl-final/src/select/poll.c b/05/musl-final/src/select/poll.c deleted file mode 100644 index e92943e..0000000 --- a/05/musl-final/src/select/poll.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -int poll(struct pollfd *fds, nfds_t n, int timeout) -{ - int r; - CANCELPT_BEGIN; - r = syscall3(__NR_poll, (long)fds, n, timeout); - CANCELPT_END; - return r; -} diff --git a/05/musl-final/src/select/pselect.c b/05/musl-final/src/select/pselect.c deleted file mode 100644 index 795c5b0..0000000 --- a/05/musl-final/src/select/pselect.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -int pselect(int n, fd_set *rfds, fd_set *wfds, fd_set *efds, const struct timespec *ts, const sigset_t *mask) -{ - int r; - long data[2] = { (long)mask, 8 }; - struct timespec ts_tmp; - if (ts) ts_tmp = *ts; - CANCELPT_BEGIN; - r = syscall6(__NR_pselect6, n, (long)rfds, (long)wfds, (long)efds, ts ? (long)&ts_tmp : 0, (long)data); - CANCELPT_END; - return r; -} diff --git a/05/musl-final/src/select/select.c b/05/musl-final/src/select/select.c deleted file mode 100644 index b394663..0000000 --- a/05/musl-final/src/select/select.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -int select(int n, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tv) -{ - int r; - CANCELPT_BEGIN; - r = syscall5(__NR_select, n, (long)rfds, (long)wfds, (long)efds, (long)tv); - CANCELPT_END; - return r; -} diff --git a/05/musl-final/src/setjmp/i386/longjmp.s b/05/musl-final/src/setjmp/i386/longjmp.s deleted file mode 100644 index c1a956c..0000000 --- a/05/musl-final/src/setjmp/i386/longjmp.s +++ /dev/null @@ -1,22 +0,0 @@ -.global _longjmp -.global longjmp -.type _longjmp,%function -.type longjmp,%function -_longjmp: -longjmp: - movl 4(%esp),%edx - movl 8(%esp),%eax - testl %eax,%eax - jnz .L0 - incl %eax -.L0: - movl (%edx),%ebx - movl 4(%edx),%esi - movl 8(%edx),%edi - movl 12(%edx),%ebp - movl 16(%edx),%ecx - movl %ecx,%esp - movl 20(%edx),%ecx - jmp *%ecx -.size _longjmp,.-_longjmp -.size longjmp,.-longjmp diff --git a/05/musl-final/src/setjmp/i386/setjmp.s b/05/musl-final/src/setjmp/i386/setjmp.s deleted file mode 100644 index 6c078b1..0000000 --- a/05/musl-final/src/setjmp/i386/setjmp.s +++ /dev/null @@ -1,23 +0,0 @@ -.global __setjmp -.global _setjmp -.global setjmp -.type __setjmp,%function -.type _setjmp,%function -.type setjmp,%function -__setjmp: -_setjmp: -setjmp: - movl 4(%esp), %eax - movl %ebx, (%eax) - movl %esi, 4(%eax) - movl %edi, 8(%eax) - movl %ebp, 12(%eax) - leal 4(%esp), %ecx - movl %ecx, 16(%eax) - movl (%esp), %ecx - movl %ecx, 20(%eax) - xorl %eax, %eax - ret -.size __setjmp,.-__setjmp -.size _setjmp,.-_setjmp -.size setjmp,.-setjmp diff --git a/05/musl-final/src/setjmp/longjmp.c b/05/musl-final/src/setjmp/longjmp.c deleted file mode 100644 index e69de29..0000000 diff --git a/05/musl-final/src/setjmp/setjmp.c b/05/musl-final/src/setjmp/setjmp.c deleted file mode 100644 index e69de29..0000000 diff --git a/05/musl-final/src/setjmp/x86_64/longjmp.s b/05/musl-final/src/setjmp/x86_64/longjmp.s deleted file mode 100644 index c63b0c9..0000000 --- a/05/musl-final/src/setjmp/x86_64/longjmp.s +++ /dev/null @@ -1,24 +0,0 @@ -/* Copyright 2011 Nicholas J. Kain, licensed GNU LGPL 2.1 or later */ -.global _longjmp -.global longjmp -.type _longjmp,%function -.type longjmp,%function -_longjmp: -longjmp: - mov %rsi,%rax /* val will be longjmp return */ - test %rax,%rax - jnz .L0 - inc %rax /* if val==0, val=1 per longjmp semantics */ -.L0: - movq (%rdi),%rbx /* rdi is the jmp_buf, restore regs from it */ - movq 8(%rdi),%rbp - movq 16(%rdi),%r12 - movq 24(%rdi),%r13 - movq 32(%rdi),%r14 - movq 40(%rdi),%r15 - movq 48(%rdi),%rdx /* this ends up being the stack pointer */ - mov %rdx,%rsp - movq 56(%rdi),%rdx /* this is the instruction pointer */ - jmp *%rdx /* goto saved address without altering rsp */ -.size _longjmp,.-_longjmp -.size longjmp,.-longjmp diff --git a/05/musl-final/src/setjmp/x86_64/setjmp.s b/05/musl-final/src/setjmp/x86_64/setjmp.s deleted file mode 100644 index 8f29fa8..0000000 --- a/05/musl-final/src/setjmp/x86_64/setjmp.s +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright 2011 Nicholas J. Kain, licensed GNU LGPL 2.1 or later */ -.global __setjmp -.global _setjmp -.global setjmp -.type __setjmp,%function -.type _setjmp,%function -.type setjmp,%function -__setjmp: -_setjmp: -setjmp: - mov %rbx,(%rdi) /* rdi is jmp_buf, move registers onto it */ - mov %rbp,8(%rdi) - mov %r12,16(%rdi) - mov %r13,24(%rdi) - mov %r14,32(%rdi) - mov %r15,40(%rdi) - leaq 8(%rsp),%rdx /* this is our rsp WITHOUT current ret addr */ - mov %rdx,48(%rdi) - movq (%rsp),%rdx /* save return addr ptr for new rip */ - mov %rdx,56(%rdi) - xor %rax,%rax /* always return 0 */ - ret -.size __setjmp,.-__setjmp -.size _setjmp,.-_setjmp -.size setjmp,.-setjmp diff --git a/05/musl-final/src/signal/getitimer.c b/05/musl-final/src/signal/getitimer.c deleted file mode 100644 index 222d113..0000000 --- a/05/musl-final/src/signal/getitimer.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include "syscall.h" - -int getitimer(int which, struct itimerval *old) -{ - int ret; - long kold[4]; - - if (!(ret = syscall2(__NR_getitimer, which, (long)&kold))) - *old = (struct itimerval){ { kold[0], kold[1] }, { kold[2], kold[3] } }; - return ret; -} diff --git a/05/musl-final/src/signal/i386/restore.s b/05/musl-final/src/signal/i386/restore.s deleted file mode 100644 index e0c4ab6..0000000 --- a/05/musl-final/src/signal/i386/restore.s +++ /dev/null @@ -1,15 +0,0 @@ -.global __restore -.type __restore,%function -__restore: - popl %eax - movl $119, %eax - int $0x80 -.size __restore,.-__restore - -.global __restore_rt -.type __restore_rt,%function -__restore_rt: - movl $173, %eax - int $0x80 -.size __restore_rt,.-__restore_rt - diff --git a/05/musl-final/src/signal/i386/sigsetjmp.s b/05/musl-final/src/signal/i386/sigsetjmp.s deleted file mode 100644 index 0e7eefb..0000000 --- a/05/musl-final/src/signal/i386/sigsetjmp.s +++ /dev/null @@ -1,13 +0,0 @@ -.global sigsetjmp -sigsetjmp: - mov 4(%esp),%eax - mov 8(%esp),%ecx - mov %ecx,24(%eax) - jecxz 1f - add $28,%eax - push %eax - push $0 - push $2 - call sigprocmask - add $12,%esp -1: jmp setjmp diff --git a/05/musl-final/src/signal/kill.c b/05/musl-final/src/signal/kill.c deleted file mode 100644 index cc4b51e..0000000 --- a/05/musl-final/src/signal/kill.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int kill(pid_t pid, int sig) -{ - return syscall2(__NR_kill, pid, sig); -} diff --git a/05/musl-final/src/signal/killpg.c b/05/musl-final/src/signal/killpg.c deleted file mode 100644 index 315ed44..0000000 --- a/05/musl-final/src/signal/killpg.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include - -int killpg(pid_t pgid, int sig) -{ - if (pgid < 0) { - errno = EINVAL; - return -1; - } - return kill(-pgid, sig); -} diff --git a/05/musl-final/src/signal/raise.c b/05/musl-final/src/signal/raise.c deleted file mode 100644 index 52f8b42..0000000 --- a/05/musl-final/src/signal/raise.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int raise(int sig) -{ - return __syscall_kill(__syscall_getpid(), sig); -} diff --git a/05/musl-final/src/signal/restore.c b/05/musl-final/src/signal/restore.c deleted file mode 100644 index e69de29..0000000 diff --git a/05/musl-final/src/signal/setitimer.c b/05/musl-final/src/signal/setitimer.c deleted file mode 100644 index cacab03..0000000 --- a/05/musl-final/src/signal/setitimer.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include "syscall.h" - -int setitimer(int which, const struct itimerval *new, struct itimerval *old) -{ - int ret; - long knew[4] = { - new->it_interval.tv_sec, new->it_interval.tv_usec, - new->it_value.tv_sec, new->it_value.tv_usec - }, kold[4]; - - if (!(ret = syscall3(__NR_setitimer, which, (long)&knew, old ? (long)&kold : 0)) && old) - *old = (struct itimerval){ { kold[0], kold[1] }, { kold[2], kold[3] } }; - return ret; -} diff --git a/05/musl-final/src/signal/sigaction.c b/05/musl-final/src/signal/sigaction.c deleted file mode 100644 index 1c35e34..0000000 --- a/05/musl-final/src/signal/sigaction.c +++ /dev/null @@ -1,53 +0,0 @@ -#include -#include -#include -#include "syscall.h" -#include "pthread_impl.h" - -void __restore(), __restore_rt(); - -int __libc_sigaction(int sig, const struct sigaction *sa, struct sigaction *old) -{ - struct { - void *handler; - unsigned long flags; - void (*restorer)(void); - sigset_t mask; - } ksa, kold; - long pksa=0, pkold=0; - if (sa) { - ksa.handler = sa->sa_handler; - ksa.flags = sa->sa_flags | SA_RESTORER; - ksa.restorer = (sa->sa_flags & SA_SIGINFO) ? __restore_rt : __restore; - ksa.mask = sa->sa_mask; - pksa = (long)&ksa; - } - if (old) pkold = (long)&kold; - if (syscall4(__NR_rt_sigaction, sig, pksa, pkold, 8)) - return -1; - if (old) { - old->sa_handler = kold.handler; - old->sa_flags = kold.flags; - old->sa_mask = kold.mask; - } - return 0; -} - -int __sigaction(int sig, const struct sigaction *sa, struct sigaction *old) -{ - if (sig == SIGCANCEL || sig == SIGSYSCALL) { - errno = EINVAL; - return -1; - } - return __libc_sigaction(sig, sa, old); -} - -int sigaction(int sig, const struct sigaction *sa, struct sigaction *old) -{ - if (sig == SIGCANCEL || sig == SIGSYSCALL) { - errno = EINVAL; - return -1; - } - return __libc_sigaction(sig, sa, old); -} - diff --git a/05/musl-final/src/signal/sigaddset.c b/05/musl-final/src/signal/sigaddset.c deleted file mode 100644 index 23e655d..0000000 --- a/05/musl-final/src/signal/sigaddset.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include - -int sigaddset(sigset_t *set, int sig) -{ - unsigned s = sig-1; - if (s >= 8*sizeof(sigset_t)) { - errno = EINVAL; - return -1; - } - set->__bits[s/8/sizeof *set->__bits] |= 1UL<<(s&8*sizeof *set->__bits-1); - return 0; -} diff --git a/05/musl-final/src/signal/sigaltstack.c b/05/musl-final/src/signal/sigaltstack.c deleted file mode 100644 index 3cc2d45..0000000 --- a/05/musl-final/src/signal/sigaltstack.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include "syscall.h" - -int sigaltstack(const stack_t *ss, stack_t *old) -{ - /* depends on kernel struct matching */ - return syscall2(__NR_sigaltstack, (long)ss, (long)old); -} diff --git a/05/musl-final/src/signal/sigdelset.c b/05/musl-final/src/signal/sigdelset.c deleted file mode 100644 index 14042fb..0000000 --- a/05/musl-final/src/signal/sigdelset.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include - -int sigdelset(sigset_t *set, int sig) -{ - unsigned s = sig-1; - if (s >= 8*sizeof(sigset_t)) { - errno = EINVAL; - return -1; - } - set->__bits[s/8/sizeof *set->__bits] &=~(1UL<<(s&8*sizeof *set->__bits-1)); - return 0; -} diff --git a/05/musl-final/src/signal/sigemptyset.c b/05/musl-final/src/signal/sigemptyset.c deleted file mode 100644 index 91f77ad..0000000 --- a/05/musl-final/src/signal/sigemptyset.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include - -int sigemptyset(sigset_t *set) -{ - memset(set, 0, sizeof *set); - return 0; -} diff --git a/05/musl-final/src/signal/sigfillset.c b/05/musl-final/src/signal/sigfillset.c deleted file mode 100644 index fab50a5..0000000 --- a/05/musl-final/src/signal/sigfillset.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include - -int sigfillset(sigset_t *set) -{ - memset(set, -1, sizeof *set); - return 0; -} diff --git a/05/musl-final/src/signal/sighold.c b/05/musl-final/src/signal/sighold.c deleted file mode 100644 index 5b0f6b1..0000000 --- a/05/musl-final/src/signal/sighold.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include - -int sighold(int sig) -{ - sigset_t mask; - - sigemptyset(&mask); - if (sigaddset(&mask, sig) < 0) return -1; - return sigprocmask(SIG_BLOCK, &mask, NULL); -} diff --git a/05/musl-final/src/signal/sigignore.c b/05/musl-final/src/signal/sigignore.c deleted file mode 100644 index 98dff61..0000000 --- a/05/musl-final/src/signal/sigignore.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -int sigignore(int sig) -{ - struct sigaction sa; - - sigemptyset(&sa.sa_mask); - sa.sa_handler = SIG_IGN; - sa.sa_flags = 0; - return sigaction(sig, &sa, NULL); -} diff --git a/05/musl-final/src/signal/siginterrupt.c b/05/musl-final/src/signal/siginterrupt.c deleted file mode 100644 index 60b3405..0000000 --- a/05/musl-final/src/signal/siginterrupt.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include - -int siginterrupt(int sig, int flag) -{ - struct sigaction sa; - - sigaction(sig, NULL, &sa); - if (flag) sa.sa_flags &= ~SA_RESTART; - else sa.sa_flags |= SA_RESTART; - - return sigaction(sig, &sa, NULL); -} diff --git a/05/musl-final/src/signal/sigismember.c b/05/musl-final/src/signal/sigismember.c deleted file mode 100644 index afd29e5..0000000 --- a/05/musl-final/src/signal/sigismember.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -int sigismember(const sigset_t *set, int sig) -{ - unsigned s = sig-1; - if (s >= 8*sizeof(sigset_t)) { - errno = EINVAL; - return -1; - } - return !!(set->__bits[s/8/sizeof *set->__bits] & 1UL<<(s&8*sizeof *set->__bits-1)); -} diff --git a/05/musl-final/src/signal/siglongjmp.c b/05/musl-final/src/signal/siglongjmp.c deleted file mode 100644 index 33ac30e..0000000 --- a/05/musl-final/src/signal/siglongjmp.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include -#include - -void siglongjmp(sigjmp_buf buf, int ret) -{ - long *flag = buf + sizeof(jmp_buf)/sizeof(long); - sigset_t *mask = (void *)(flag + 1); - if (*flag) - sigprocmask (SIG_SETMASK, mask, NULL); - longjmp((void *)buf, ret); -} diff --git a/05/musl-final/src/signal/signal.c b/05/musl-final/src/signal/signal.c deleted file mode 100644 index 07346a8..0000000 --- a/05/musl-final/src/signal/signal.c +++ /dev/null @@ -1,16 +0,0 @@ -#include -#include -#include "syscall.h" -#include "libc.h" - -int __sigaction(int, const struct sigaction *, struct sigaction *); - -void (*signal(int sig, void (*func)(int)))(int) -{ - struct sigaction sa = { .sa_handler = func, .sa_flags = SA_RESTART }; - if (__sigaction(sig, &sa, &sa) < 0) - return SIG_ERR; - return sa.sa_handler; -} - -weak_alias(signal, bsd_signal); diff --git a/05/musl-final/src/signal/sigpause.c b/05/musl-final/src/signal/sigpause.c deleted file mode 100644 index 263c00f..0000000 --- a/05/musl-final/src/signal/sigpause.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include - -int sigpause(int sig) -{ - sigset_t mask; - - if (sigprocmask(0, NULL, &mask) < 0 || sigdelset(&mask, sig) < 0) - return -1; - return sigsuspend(&mask); -} diff --git a/05/musl-final/src/signal/sigpending.c b/05/musl-final/src/signal/sigpending.c deleted file mode 100644 index 7deda25..0000000 --- a/05/musl-final/src/signal/sigpending.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int sigpending(sigset_t *set) -{ - return syscall2(__NR_rt_sigpending, (long)set, SYSCALL_SIGSET_SIZE); -} diff --git a/05/musl-final/src/signal/sigprocmask.c b/05/musl-final/src/signal/sigprocmask.c deleted file mode 100644 index a8a4a87..0000000 --- a/05/musl-final/src/signal/sigprocmask.c +++ /dev/null @@ -1,44 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -int __libc_sigprocmask(int how, const sigset_t *set, sigset_t *old) -{ - return syscall4(__NR_rt_sigprocmask, how, (long)set, (long)old, 8); -} - -int __sigprocmask(int how, const sigset_t *set, sigset_t *old) -{ - sigset_t tmp; - /* Quickly mask out bits 32 and 33 (thread control signals) */ - if (0 && how != SIG_UNBLOCK && (set->__bits[4/sizeof *set->__bits] & 3UL<<(32&8*sizeof *set->__bits-1))) { - tmp = *set; - set = &tmp; - tmp.__bits[4/sizeof *set->__bits] &= ~(3UL<<(32&8*sizeof *set->__bits-1)); - } - return __libc_sigprocmask(how, set, old); -} - -int sigprocmask(int how, const sigset_t *set, sigset_t *old) -{ - sigset_t tmp; - /* Quickly mask out bits 32 and 33 (thread control signals) */ - if (0 && how != SIG_UNBLOCK && (set->__bits[4/sizeof *set->__bits] & 3UL<<(32&8*sizeof *set->__bits-1))) { - tmp = *set; - set = &tmp; - tmp.__bits[4/sizeof *set->__bits] &= ~(3UL<<(32&8*sizeof *set->__bits-1)); - } - return __libc_sigprocmask(how, set, old); -} - -int pthread_sigmask(int how, const sigset_t *set, sigset_t *old) -{ - sigset_t tmp; - /* Quickly mask out bits 32 and 33 (thread control signals) */ - if (0 && how != SIG_UNBLOCK && (set->__bits[4/sizeof *set->__bits] & 3UL<<(32&8*sizeof *set->__bits-1))) { - tmp = *set; - set = &tmp; - tmp.__bits[4/sizeof *set->__bits] &= ~(3UL<<(32&8*sizeof *set->__bits-1)); - } - return __libc_sigprocmask(how, set, old); -} diff --git a/05/musl-final/src/signal/sigqueue.c b/05/musl-final/src/signal/sigqueue.c deleted file mode 100644 index ce3abf6..0000000 --- a/05/musl-final/src/signal/sigqueue.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include -#include -#include "syscall.h" - -int sigqueue(pid_t pid, int sig, const union sigval value) -{ - siginfo_t si = { - .si_signo = sig, - .si_code = -1, - .si_value = value, - }; - return syscall3(__NR_rt_sigqueueinfo, pid, sig, (long)&si); -} diff --git a/05/musl-final/src/signal/sigrelse.c b/05/musl-final/src/signal/sigrelse.c deleted file mode 100644 index b0b3024..0000000 --- a/05/musl-final/src/signal/sigrelse.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include - -int sigrelse(int sig) -{ - sigset_t mask; - - sigemptyset(&mask); - if (sigaddset(&mask, sig) < 0) return -1; - return sigprocmask(SIG_UNBLOCK, &mask, NULL); -} diff --git a/05/musl-final/src/signal/sigrtmax.c b/05/musl-final/src/signal/sigrtmax.c deleted file mode 100644 index 0ef2987..0000000 --- a/05/musl-final/src/signal/sigrtmax.c +++ /dev/null @@ -1,4 +0,0 @@ -int __libc_current_sigrtmax() -{ - return 64; -} diff --git a/05/musl-final/src/signal/sigrtmin.c b/05/musl-final/src/signal/sigrtmin.c deleted file mode 100644 index 7ad06d2..0000000 --- a/05/musl-final/src/signal/sigrtmin.c +++ /dev/null @@ -1,4 +0,0 @@ -int __libc_current_sigrtmin() -{ - return 34; -} diff --git a/05/musl-final/src/signal/sigset.c b/05/musl-final/src/signal/sigset.c deleted file mode 100644 index 1b6b38f..0000000 --- a/05/musl-final/src/signal/sigset.c +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include - -void (*sigset(int sig, void (*handler)(int)))(int) -{ - struct sigaction sa, sa_old; - sigset_t mask; - - sigemptyset(&mask); - if (sigaddset(&mask, sig) < 0) - return SIG_ERR; - - if (handler == SIG_HOLD) { - if (sigaction(sig, NULL, &sa_old) < 0) - return SIG_ERR; - if (sigprocmask(SIG_BLOCK, &mask, &mask) < 0) - return SIG_ERR; - } else { - sa.sa_handler = handler; - sa.sa_flags = 0; - sigemptyset(&sa.sa_mask); - if (sigaction(sig, &sa, &sa_old) < 0) - return SIG_ERR; - if (sigprocmask(SIG_UNBLOCK, &mask, &mask) < 0) - return SIG_ERR; - } - return sigismember(&mask, sig) ? SIG_HOLD : sa_old.sa_handler; -} diff --git a/05/musl-final/src/signal/sigsetjmp.c b/05/musl-final/src/signal/sigsetjmp.c deleted file mode 100644 index a6667a2..0000000 --- a/05/musl-final/src/signal/sigsetjmp.c +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include -#include - -/* !!! This function will not work unless the compiler performs - * tail call optimization. Machine-specific asm versions should - * be created instead even though the workaround (tail call) - * is entirely non-machine-specific... */ - -int sigsetjmp(sigjmp_buf buf, int save) -{ - long *flag = buf + sizeof(jmp_buf)/sizeof(long); - sigset_t *mask = (void *)(flag + 1); - if ((*flag = save)) - sigprocmask (SIG_SETMASK, NULL, mask); - return setjmp((void *)buf); -} diff --git a/05/musl-final/src/signal/sigsuspend.c b/05/musl-final/src/signal/sigsuspend.c deleted file mode 100644 index 1acdab0..0000000 --- a/05/musl-final/src/signal/sigsuspend.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int sigsuspend(const sigset_t *mask) -{ - return syscall2(__NR_rt_sigsuspend, (long)mask, sizeof(sigset_t)); -} diff --git a/05/musl-final/src/signal/sigtimedwait.c b/05/musl-final/src/signal/sigtimedwait.c deleted file mode 100644 index 155185d..0000000 --- a/05/musl-final/src/signal/sigtimedwait.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include "syscall.h" - -int sigtimedwait(const sigset_t *mask, siginfo_t *si, const struct timespec *timeout) -{ - long k_timeout[2]; - if (timeout) { - k_timeout[0] = timeout->tv_sec; - k_timeout[1] = timeout->tv_nsec; - } - return syscall4(__NR_rt_sigtimedwait, (long)mask, (long)si, timeout ? (long)k_timeout : 0, SYSCALL_SIGSET_SIZE); -} diff --git a/05/musl-final/src/signal/sigwait.c b/05/musl-final/src/signal/sigwait.c deleted file mode 100644 index 9569d6b..0000000 --- a/05/musl-final/src/signal/sigwait.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include - -int sigwait(const sigset_t *mask, int *sig) -{ - siginfo_t si; - if (sigtimedwait(mask, &si, NULL) < 0) - return -1; - *sig = si.si_signo; - return 0; -} diff --git a/05/musl-final/src/signal/sigwaitinfo.c b/05/musl-final/src/signal/sigwaitinfo.c deleted file mode 100644 index e79feb9..0000000 --- a/05/musl-final/src/signal/sigwaitinfo.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include - -int sigwaitinfo(const sigset_t *mask, siginfo_t *si) -{ - return sigtimedwait(mask, si, NULL); -} diff --git a/05/musl-final/src/signal/x86_64/restore.s b/05/musl-final/src/signal/x86_64/restore.s deleted file mode 100644 index bc5e0d7..0000000 --- a/05/musl-final/src/signal/x86_64/restore.s +++ /dev/null @@ -1,11 +0,0 @@ -.global __restore_rt -.global __restore -.type __restore_rt,%function -.type __restore,%function -__restore_rt: -__restore: - movl $15, %eax - syscall -.size __restore_rt,.-__restore_rt -.size __restore,.-__restore - diff --git a/05/musl-final/src/signal/x86_64/sigsetjmp.s b/05/musl-final/src/signal/x86_64/sigsetjmp.s deleted file mode 100644 index 0a45078..0000000 --- a/05/musl-final/src/signal/x86_64/sigsetjmp.s +++ /dev/null @@ -1,11 +0,0 @@ -/* Copyright 2011 Nicholas J. Kain, licensed GNU LGPL 2.1 or later */ -.global sigsetjmp -sigsetjmp: - test %rsi,%rsi - jz 1f /* if save == 0, just goto setjmp */ - movq %rsi,64(%rdi) /* move save -> jmp_buf[8] */ - addq $72,%rdi /* add sizeof(jmp_buf) to rdi */ - movl $0,%esi /* arg2 = 0 */ - movl $2,%edx /* arg3 = 2 */ - call sigprocmask /* sigprocmask(jmp_buf, 0, 2) */ -1: jmp setjmp diff --git a/05/musl-final/src/stat/chmod.c b/05/musl-final/src/stat/chmod.c deleted file mode 100644 index cb310fe..0000000 --- a/05/musl-final/src/stat/chmod.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int chmod(const char *path, mode_t mode) -{ - return syscall2(__NR_chmod, (long)path, mode); -} diff --git a/05/musl-final/src/stat/fchmod.c b/05/musl-final/src/stat/fchmod.c deleted file mode 100644 index 9189738..0000000 --- a/05/musl-final/src/stat/fchmod.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int fchmod(int fd, mode_t mode) -{ - return syscall2(__NR_fchmod, fd, mode); -} diff --git a/05/musl-final/src/stat/fchmodat.c b/05/musl-final/src/stat/fchmodat.c deleted file mode 100644 index f4f22b2..0000000 --- a/05/musl-final/src/stat/fchmodat.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int fchmodat(int fd, const char *path, mode_t mode, int flag) -{ - return syscall4(__NR_fchmodat, fd, (long)path, mode, flag); -} diff --git a/05/musl-final/src/stat/fstat.c b/05/musl-final/src/stat/fstat.c deleted file mode 100644 index 88ac6f3..0000000 --- a/05/musl-final/src/stat/fstat.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -int fstat(int fd, struct stat *buf) -{ - return syscall2(__NR_fstat, fd, (long)buf); -} - -LFS64(fstat); diff --git a/05/musl-final/src/stat/fstatat.c b/05/musl-final/src/stat/fstatat.c deleted file mode 100644 index e39f833..0000000 --- a/05/musl-final/src/stat/fstatat.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -int fstatat(int fd, const char *path, struct stat *buf, int flag) -{ - return syscall4(__NR_fstatat, fd, (long)path, (long)buf, flag); -} - -LFS64(fstatat); diff --git a/05/musl-final/src/stat/fstatvfs.c b/05/musl-final/src/stat/fstatvfs.c deleted file mode 100644 index 4a8bfe2..0000000 --- a/05/musl-final/src/stat/fstatvfs.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -int fstatvfs(int fd, struct statvfs *buf) -{ - return syscall2(__NR_fstatfs, fd, (long)buf); -} - -weak_alias(fstatvfs, fstatfs); - -LFS64(fstatvfs); -LFS64(fstatfs); diff --git a/05/musl-final/src/stat/lstat.c b/05/musl-final/src/stat/lstat.c deleted file mode 100644 index 3b22e62..0000000 --- a/05/musl-final/src/stat/lstat.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -int lstat(const char *path, struct stat *buf) -{ - return syscall2(__NR_lstat, (long)path, (long)buf); -} - -LFS64(lstat); diff --git a/05/musl-final/src/stat/mkdir.c b/05/musl-final/src/stat/mkdir.c deleted file mode 100644 index 8295cad..0000000 --- a/05/musl-final/src/stat/mkdir.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int mkdir(const char *path, mode_t mode) -{ - return syscall2(__NR_mkdir, (long)path, mode); -} diff --git a/05/musl-final/src/stat/mkdirat.c b/05/musl-final/src/stat/mkdirat.c deleted file mode 100644 index 1fb3825..0000000 --- a/05/musl-final/src/stat/mkdirat.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int mkdirat(int fd, const char *path, mode_t mode) -{ - return syscall3(__NR_mkdirat, fd, (long)path, mode); -} diff --git a/05/musl-final/src/stat/mkfifo.c b/05/musl-final/src/stat/mkfifo.c deleted file mode 100644 index 60efcf7..0000000 --- a/05/musl-final/src/stat/mkfifo.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int mkfifo(const char *path, mode_t mode) -{ - return mknod(path, mode | S_IFIFO, 0); -} diff --git a/05/musl-final/src/stat/mkfifoat.c b/05/musl-final/src/stat/mkfifoat.c deleted file mode 100644 index d3a1f97..0000000 --- a/05/musl-final/src/stat/mkfifoat.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int mkfifoat(int fd, const char *path, mode_t mode) -{ - return mknodat(fd, path, mode | S_IFIFO, 0); -} diff --git a/05/musl-final/src/stat/mknod.c b/05/musl-final/src/stat/mknod.c deleted file mode 100644 index 0123eee..0000000 --- a/05/musl-final/src/stat/mknod.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include "syscall.h" - -int mknod(const char *path, mode_t mode, dev_t dev) -{ - /* since dev_t is system-specific anyway we defer to the idiotic - * legacy-compatible bitfield mapping of the type.. at least we've - * made it large enough to leave space for future expansion.. */ - return syscall3(__NR_mknod, (long)path, mode, dev & 0xffff); -} diff --git a/05/musl-final/src/stat/mknodat.c b/05/musl-final/src/stat/mknodat.c deleted file mode 100644 index b5687e4..0000000 --- a/05/musl-final/src/stat/mknodat.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int mknodat(int fd, const char *path, mode_t mode, dev_t dev) -{ - return syscall4(__NR_mknodat, fd, (long)path, mode, dev & 0xffff); -} diff --git a/05/musl-final/src/stat/stat.c b/05/musl-final/src/stat/stat.c deleted file mode 100644 index 9847552..0000000 --- a/05/musl-final/src/stat/stat.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -int stat(const char *path, struct stat *buf) -{ - return syscall2(__NR_stat, (long)path, (long)buf); -} - -LFS64(stat); diff --git a/05/musl-final/src/stat/statvfs.c b/05/musl-final/src/stat/statvfs.c deleted file mode 100644 index ebf14b4..0000000 --- a/05/musl-final/src/stat/statvfs.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -int statvfs(const char *path, struct statvfs *buf) -{ - return syscall2(__NR_statfs, (long)path, (long)buf); -} - -weak_alias(statvfs, statfs); - -LFS64(statvfs); -LFS64(statfs); diff --git a/05/musl-final/src/stat/umask.c b/05/musl-final/src/stat/umask.c deleted file mode 100644 index 49cb48a..0000000 --- a/05/musl-final/src/stat/umask.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -mode_t umask(mode_t mode) -{ - return syscall1(__NR_umask, mode); -} diff --git a/05/musl-final/src/stdio/__fclose_ca.c b/05/musl-final/src/stdio/__fclose_ca.c deleted file mode 100644 index e0b12a1..0000000 --- a/05/musl-final/src/stdio/__fclose_ca.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "stdio_impl.h" - -int __fclose_ca(FILE *f) -{ - return f->close(f); -} diff --git a/05/musl-final/src/stdio/__fdopen.c b/05/musl-final/src/stdio/__fdopen.c deleted file mode 100644 index 6ad7c57..0000000 --- a/05/musl-final/src/stdio/__fdopen.c +++ /dev/null @@ -1,52 +0,0 @@ -#include "stdio_impl.h" - -FILE *__fdopen(int fd, const char *mode) -{ - FILE *f; - struct termios tio; - int plus = !!strchr(mode, '+'); - - /* Check for valid initial mode character */ - if (!strchr("rwa", *mode)) return 0; - - /* Allocate FILE+buffer or fail */ - if (!(f=malloc(sizeof *f + UNGET + BUFSIZ))) return 0; - - /* Zero-fill only the struct, not the buffer */ - memset(f, 0, sizeof *f); - - /* Impose mode restrictions */ - if (!plus) f->flags = (*mode == 'r') ? F_NOWR : F_NORD; - - /* Set append mode on fd if opened for append */ - if (*mode == 'a') { - int flags = __syscall_fcntl(fd, F_GETFL, 0); - __syscall_fcntl(fd, F_SETFL, flags | O_APPEND); - } - - f->fd = fd; - f->buf = (unsigned char *)f + sizeof *f + UNGET; - f->buf_size = BUFSIZ; - - /* Activate line buffered mode for terminals */ - f->lbf = EOF; - if (!(f->flags & F_NOWR) && !__syscall_ioctl(fd, TCGETS, &tio)) - f->lbf = '\n'; - - /* Initialize op ptrs. No problem if some are unneeded. */ - f->read = __stdio_read; - f->write = __stdio_write; - f->seek = __stdio_seek; - f->close = __stdio_close; - - /* Add new FILE to open file list */ - OFLLOCK(); - f->next = ofl_head; - if (ofl_head) ofl_head->prev = f; - ofl_head = f; - OFLUNLOCK(); - - return f; -} - -weak_alias(__fdopen, fdopen); diff --git a/05/musl-final/src/stdio/__fopen_rb_ca.c b/05/musl-final/src/stdio/__fopen_rb_ca.c deleted file mode 100644 index 57d9b73..0000000 --- a/05/musl-final/src/stdio/__fopen_rb_ca.c +++ /dev/null @@ -1,18 +0,0 @@ -#include "stdio_impl.h" - -FILE *__fopen_rb_ca(const char *filename, FILE *f, unsigned char *buf, size_t len) -{ - memset(f, 0, sizeof *f); - - f->fd = __syscall_open(filename, O_RDONLY, 0); - if (f->fd < 0) return 0; - - f->flags = F_NOWR | F_PERM; - f->buf = buf + UNGET; - f->buf_size = len - UNGET; - f->read = __stdio_read; - f->seek = __stdio_seek; - f->close = __stdio_close; - - return f; -} diff --git a/05/musl-final/src/stdio/__fpending.c b/05/musl-final/src/stdio/__fpending.c deleted file mode 100644 index a4334e2..0000000 --- a/05/musl-final/src/stdio/__fpending.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "stdio_impl.h" - -size_t __fpending(FILE *f) -{ - return f->wend ? f->wpos - f->wbase : 0; -} diff --git a/05/musl-final/src/stdio/__ofl.c b/05/musl-final/src/stdio/__ofl.c deleted file mode 100644 index 7d9652c..0000000 --- a/05/musl-final/src/stdio/__ofl.c +++ /dev/null @@ -1,3 +0,0 @@ -#include "stdio_impl.h" - -struct ofl __ofl; diff --git a/05/musl-final/src/stdio/__overflow.c b/05/musl-final/src/stdio/__overflow.c deleted file mode 100644 index e35104d..0000000 --- a/05/musl-final/src/stdio/__overflow.c +++ /dev/null @@ -1,52 +0,0 @@ -#include "stdio_impl.h" - -static int overflow(FILE *f, int c) -{ - /* Initialize if we're not already writing */ - if (!f->wend) { - /* Fail if we're in error state or unwritable. */ - if (f->flags & (F_ERR|F_NOWR)) return EOF; - - /* Set byte orientation -1,0=>-1; 1=>1 */ - f->mode |= f->mode-1; - - /* Clear read buffer (easier than summoning nasal demons) */ - f->rpos = f->rend = f->rstop = 0; - - /* Activate write through the buffer */ - f->wpos = f->wbase = f->buf; - f->wend = f->buf + f->buf_size; - f->wstop = (f->lbf < 0) ? f->wend - 1 : 0; - } - - /* Buffer can always hold at least 1 byte... */ - if (c != EOF) { - *f->wpos++ = c; - if (f->wpos <= f->wstop && c != f->lbf) return c; - } - /* ...since if the next call fails, buffer is empty. */ - if (f->write(f, f->wbase, f->wpos - f->wbase) < 0) { - f->flags |= F_ERR; - f->wpos = f->wbase = f->wend = f->wstop = 0; - return EOF; - } - - /* Buffer is empty so reset position to beginning */ - f->wpos = f->wbase; - - return c; -} - -int __overflow(FILE *f, int c) -{ - return overflow(f, c & 0xff); -} - -int __oflow(FILE *f) -{ - overflow(f, EOF); - return (f->flags & F_ERR) ? EOF : 0; -} - -/* Link flush-on-exit code iff any stdio write functions are linked. */ -int (*const __fflush_on_exit)(FILE *) = fflush; diff --git a/05/musl-final/src/stdio/__scanf.c b/05/musl-final/src/stdio/__scanf.c deleted file mode 100644 index 185615d..0000000 --- a/05/musl-final/src/stdio/__scanf.c +++ /dev/null @@ -1,487 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "__scanf.h" - -static int read(rctx_t *r) -{ - if (--r->w < 0) return r->w = -1; - if (r->u) r->u = 0; - else r->read(r); - return r->c; -} - -static void unread(rctx_t *r) -{ - //if (r->u || r->w < 0) return; - if (r->w < 0) return; - r->w++; - r->u = 1; -} - -#define SIZE_hh -2 -#define SIZE_h -1 -#define SIZE_def 0 -#define SIZE_l 1 -#define SIZE_ll 2 -#define SIZE_L 3 - -static void store_int(void *dest, int size, int neg, unsigned long long i) -{ - if (!dest) return; - if (neg) i = -i; - switch (size) { - case SIZE_hh: - *(char *)dest = i; - break; - case SIZE_h: - *(short *)dest = i; - break; - case SIZE_def: - *(int *)dest = i; - break; - case SIZE_l: - *(long *)dest = i; - break; - case SIZE_ll: - *(long long *)dest = i; - break; - } -} - -static void *arg_n(va_list ap, unsigned int n) -{ - void *p; - unsigned int i; - va_list ap2; - va_copy(ap2, ap); - for (i=n; i>1; i--) va_arg(ap2, void *); - p = va_arg(ap2, void *); - va_end(ap2); - return p; -} - -int __scanf(rctx_t *r, const wchar_t *fmt, va_list ap) -{ - int mode=0; - int width; - int size; - const wchar_t *p, *z; - int c, l, t, m; - long long dummy; - char *s; - wchar_t *wcs; - mbstate_t st; - int wide = r->wide; - void *dest=NULL; - int invert; - unsigned long long i=0; - int neg=0; - int matches=0; - long double f; - int (*is_space)(int) = r->is_space; - - for (p=fmt; *p; ) { - if (is_space(*p)) { - do p++; while (is_space(*p)); - do r->w=1; while (is_space(read(r))); - unread(r); - continue; - } else if (*p != '%' || p[1] == '%') { - if (*p == '%') p++; - r->w = 1; - if (*p++ != read(r)) - goto match_fail; - continue; - } - p++; - if (mode != 1) { - for (z=p; isdigit(*z); z++); - if (*z != '$' && *z != '*') { - if (mode == 0) mode = 1; - else goto fmt_fail; - } else if (*z != '*') { - int pos = 0; - mode = 2; - for (; pw = width; - - if (t != 'n') { - if (read(r) < 0) goto input_fail; - unread(r); - } - - switch (t) { - case 'n': - store_int(dest, size, 0, r->l - r->u); - /* do not increment match count, etc! */ - continue; - case 'C': - wcs = dest ? dest : (void *)&dummy; - st = (mbstate_t){ 0 }; - while ((c=read(r)) >= 0) { - if (wide) { - if (dest) *wcs++ = c; - } else { - char ch = c; - switch (mbrtowc(wcs, &ch, 1, &st)) { - case -1: - goto enc_fail; - case -2: - break; - default: - if (dest) wcs++; - } - } - } - if (r->w > 0) goto match_fail; - break; - case 'c': - s = dest ? dest : (void *)&dummy; - while ((c=read(r)) >= 0) { - if (wide) { - if ((l=wctomb(s, c)) < 0) - goto enc_fail; - if (dest) s += l; - } else { - if (dest) *s++ = c; - } - } - if (r->w > 0) goto match_fail; - break; - case '[': - wcs = dest ? dest : (void *)&dummy; - s = dest ? dest : (void *)&dummy; - if (!wide && size == SIZE_l) st = (mbstate_t){ 0 }; - - if (*p == '^') p++, invert = 1; - else invert = 0; - - if (wide) { - for (m=0; (c=read(r)) >= 0; m=1) { - for (z=p; *z && *z != c && (*z != ']' || z==p); z++); - if (!*z) goto fmt_fail; - if (*z == c && (*z != ']' || z==p)) { - if (invert) break; - } else { - if (!invert) break; - } - if (size == SIZE_l) { - if (dest) *wcs++ = c; - } else { - if ((l=wctomb(s, c)) < 0) - goto enc_fail; - if (dest) s += l; - } - } - for (p++; *p && *p != ']'; p++); - p++; - } else { - unsigned char scanset[257]; - memset(scanset, invert, sizeof scanset); - scanset[0] = 0; - for (z=p; *z && (*z != ']' || z==p); z++) - scanset[1+*z] = 1-invert; - if (!*z) goto fmt_fail; - p=z+1; - c=0; - for (m=0; scanset[(c=read(r))+1]; m=1) { - if (size == SIZE_l) { - char ch = c; - switch (mbrtowc(wcs, &ch, 1, &st)) { - case -1: - goto enc_fail; - case -2: - break; - default: - if (dest) wcs++; - } - } else { - if (dest) *s++ = c; - } - } - } - if (!m) goto match_fail; - if (dest) { - if (size == SIZE_l) *wcs++ = 0; - else *s++ = 0; - } - break; - default: - /* read unlimited number of spaces, then reset width */ - do r->w = 1; while (is_space(c = read(r))); - if (c < 0) goto input_fail; - unread(r); - r->w = width; - } - - switch (t) { - case 'p': - case 'X': - t = 'x'; - case 'd': - case 'i': - case 'o': - case 'u': - case 'x': - i = m = neg = 0; - if ((c=read(r)) == '-') neg=1; - else if (c != '+') unread(r); - switch (t) { - case 'i': - case 'x': - if ((c=read(r)) != '0') { - if (t == 'i') t = 'd'; - unread(r); - break; - } - if (((c=read(r))|0x20) != 'x') { - if (t == 'i') { - t = 'o'; - /* lone 0 is valid octal */ - if ((unsigned)(c-'0') >= 8) { - m = 1; - goto int_finish; - } - } - unread(r); - break; - } - t = 'x'; - } - } - - switch (t) { - case 'd': - case 'u': - for (m=0; isdigit(c=read(r)); m=1) - i = 10*i + c-'0'; - goto int_finish; - case 'o': - for (m=0; (unsigned)(c=read(r))-'0' < 8; m=1) - i = (i<<3) + c-'0'; - goto int_finish; - case 'x': - for (m=0; ; m=1) { - if (isdigit(c=read(r))) { - i = (i<<4) + c-'0'; - } else if ((unsigned)(c|0x20)-'a' < 6) { - i = (i<<4) + (c|0x20)-'a'+10; - } else break; - } - int_finish: - if (!m) goto match_fail; - store_int(dest, size, neg, i); - break; - case 'a': - case 'e': - case 'f': - case 'g': - f = 0.0; - neg = m = 0; - if ((c=read(r)) == '-') neg=1; - else if (c != '+') unread(r); - /* FIXME: check for INF/NAN strings here */ - if (read(r)=='0' && (m=1, (read(r)|0x20) == 'x')) - goto hexfloat; - else unread(r); - for (; isdigit(c=read(r)); m=1) - f = 10.0 * f + (c-'0'); - if (c=='.') { - double mag = 10.0; - for (; isdigit(c=read(r)); mag*=10.0) - f += (c-'0')/mag; - } - if ((c|0x20)=='e') { - int ex=0, en=0; - m = 0; - if ((c=read(r))=='-') en=1; - else if (c!='+') unread(r); - for (; isdigit(c=read(r)); m=1) - if (ex < LDBL_MAX_10_EXP) - ex = 10 * ex + (c-'0'); - if (ex > LDBL_MAX_10_EXP) - f = en ? 0 : INFINITY; - else { - if (en) while (ex--) f/=10.0; - else while (ex--) f*=10.0; - } - } - goto writefloat; -hexfloat: - m = 0; - for (; isxdigit(c=read(r)); m=1) - if (isdigit(c)) f = 16.0*f + (c-'0'); - else f = 16.0*f + ((c|32)-'a'+10); - if (c=='.') { - double mag = 1/16.0; - for (; isxdigit(c=read(r)); mag*=1/16.0) - if (isdigit(c)) f += (c-'0')*mag; - else f += ((c|32)-'a'+10)*mag; - } - if ((c|0x20)=='p') { - int ex=0, en=0; - m = 0; - if ((c=read(r))=='-') en=1; - else if (c!='+') unread(r); - for (; isdigit(c=read(r)); m=1) - if (ex < LDBL_MAX_EXP) - ex = 10 * ex + (c-'0'); - if (ex > LDBL_MAX_EXP) - f = en ? 0 : INFINITY; - else { - if (en) while (ex--) f*=0.5; - else while (ex--) f*=2.0; - } - } -writefloat: - if (!m) goto match_fail; - if (neg) f *= -1.0; - if (dest) switch (size) { - case SIZE_def: - *(float *)dest = f; - break; - case SIZE_l: - *(double *)dest = f; - break; - case SIZE_L: - *(long double *)dest = f; - break; - } - break; - case 'S': - wcs = dest ? dest : (void *)&dummy; - st = (mbstate_t){ 0 }; - while((c=read(r)) >= 0) { - if (wide) { - if (is_space(c)) break; - if (dest) *wcs++ = c; - } else { - char ch = c; - if (is_space(c)) break; - switch (mbrtowc(wcs, &ch, 1, &st)) { - case -1: - goto enc_fail; - case -2: - break; - default: - if (dest) wcs++; - } - } - } - if (dest) *wcs++ = 0; - break; - case 's': - s = dest ? dest : (void *)&dummy; - while((c=read(r)) >= 0) { - if (wide) { - if (is_space(c)) break; - if ((l=wctomb(s, c)) < 0) - goto enc_fail; - if (dest) s += l; - } else { - if (is_space(c)) break; - if (dest) *s++ = c; - } - } - if (dest) *s++ = 0; - break; - } - - /* unread will do nothing if field width was exhausted */ - unread(r); - if (dest) matches++; - } - return matches; -enc_fail: - errno = EILSEQ; -fmt_fail: -input_fail: - if (!matches) matches--; -match_fail: - unread(r); - return matches; -} diff --git a/05/musl-final/src/stdio/__scanf.h b/05/musl-final/src/stdio/__scanf.h deleted file mode 100644 index e549b97..0000000 --- a/05/musl-final/src/stdio/__scanf.h +++ /dev/null @@ -1,16 +0,0 @@ -#include - -typedef struct rctx -{ - void (*read)(struct rctx *); - void *opaque; - int wide; - int (*is_space)(); - int l; - int e; - int c; - int u; - int w; -} rctx_t; - -int __scanf(rctx_t *, const wchar_t *, va_list); diff --git a/05/musl-final/src/stdio/__stdio_close.c b/05/musl-final/src/stdio/__stdio_close.c deleted file mode 100644 index 24fef33..0000000 --- a/05/musl-final/src/stdio/__stdio_close.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "stdio_impl.h" - -int __stdio_close(FILE *f) -{ - return __syscall_close(f->fd); -} diff --git a/05/musl-final/src/stdio/__stdio_read.c b/05/musl-final/src/stdio/__stdio_read.c deleted file mode 100644 index ee7e125..0000000 --- a/05/musl-final/src/stdio/__stdio_read.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "stdio_impl.h" - -size_t __stdio_read(FILE *f, unsigned char *buf, size_t len) -{ - return __syscall_read(f->fd, buf, len); -} diff --git a/05/musl-final/src/stdio/__stdio_seek.c b/05/musl-final/src/stdio/__stdio_seek.c deleted file mode 100644 index c7a5b73..0000000 --- a/05/musl-final/src/stdio/__stdio_seek.c +++ /dev/null @@ -1,21 +0,0 @@ -#include "stdio_impl.h" - -static off_t retneg1(FILE *f, off_t off, int whence) -{ - return -1; -} - -off_t __stdio_seek(FILE *f, off_t off, int whence) -{ - off_t ret; -#ifdef __NR__llseek - if (syscall5(__NR__llseek, f->fd, off>>32, off, (long)&ret, whence)<0) - ret = -1; -#else - ret = syscall3(__NR_lseek, f->fd, off, whence); -#endif - /* Detect unseekable files and optimize future failures out */ - if (ret < 0 && off == 0 && whence == SEEK_CUR) - f->seek = retneg1; - return ret; -} diff --git a/05/musl-final/src/stdio/__stdio_write.c b/05/musl-final/src/stdio/__stdio_write.c deleted file mode 100644 index 7854562..0000000 --- a/05/musl-final/src/stdio/__stdio_write.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "stdio_impl.h" - -size_t __stdio_write(FILE *f, const unsigned char *buf, size_t len) -{ - const unsigned char *stop = buf+len; - ssize_t cnt = 1; - for (; buffd, buf, len))>0; buf+=cnt); - return len-(stop-buf); -} diff --git a/05/musl-final/src/stdio/__uflow.c b/05/musl-final/src/stdio/__uflow.c deleted file mode 100644 index 5a51d61..0000000 --- a/05/musl-final/src/stdio/__uflow.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "stdio_impl.h" - -int __uflow(FILE *f) -{ - if (__underflow(f) < 0) return EOF; - else return *f->rpos++; -} diff --git a/05/musl-final/src/stdio/__underflow.c b/05/musl-final/src/stdio/__underflow.c deleted file mode 100644 index b769f4e..0000000 --- a/05/musl-final/src/stdio/__underflow.c +++ /dev/null @@ -1,38 +0,0 @@ -#include "stdio_impl.h" - -int __underflow(FILE *f) -{ - ssize_t cnt; - - /* Read from buffer (Do we ever get called when this is true??) */ - if (f->rpos < f->rstop) return *f->rpos; - - /* Initialize if we're not already reading */ - if (!f->rstop) { - /* Fail immediately if unreadable, eof, or error state. */ - if (f->flags & (F_EOF|F_ERR|F_NORD)) return EOF; - - /* Set byte orientation -1,0=>-1; 1=>1 */ - f->mode |= f->mode-1; - - /* Flush any unwritten output; fail on error. */ - if (f->wpos > f->buf && __oflow(f)) return EOF; - - /* Disallow writes to buffer. */ - f->wstop = 0; - } - - /* Perform the underlying read operation */ - if ((cnt=f->read(f, f->buf, f->buf_size)) + 1 <= 1) { - /* Set flags and leave read mode */ - f->flags |= F_EOF | (cnt & F_ERR); - f->rpos = f->rend = f->rstop = 0; - return EOF; - } - - /* Setup buffer pointers for reading from buffer */ - f->rpos = f->buf; - f->rend = f->rstop = f->buf + cnt; - - return *f->rpos; -} diff --git a/05/musl-final/src/stdio/asprintf.c b/05/musl-final/src/stdio/asprintf.c deleted file mode 100644 index 79e59c2..0000000 --- a/05/musl-final/src/stdio/asprintf.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include - -int vasprintf(char **, const char *, va_list); - -int asprintf(char **s, const char *fmt, ...) -{ - int ret; - va_list ap; - va_start(ap, fmt); - ret = vasprintf(s, fmt, ap); - va_end(ap); - return ret; -} diff --git a/05/musl-final/src/stdio/clearerr.c b/05/musl-final/src/stdio/clearerr.c deleted file mode 100644 index a409120..0000000 --- a/05/musl-final/src/stdio/clearerr.c +++ /dev/null @@ -1,16 +0,0 @@ -#include "stdio_impl.h" - -void clearerr(FILE *f) -{ - FLOCK(f); - f->flags &= ~(F_EOF|F_ERR); - FUNLOCK(f); -} - -void clearerr_unlocked(FILE *f) -{ - FLOCK(f); - f->flags &= ~(F_EOF|F_ERR); - FUNLOCK(f); -} - diff --git a/05/musl-final/src/stdio/dprintf.c b/05/musl-final/src/stdio/dprintf.c deleted file mode 100644 index fa28322..0000000 --- a/05/musl-final/src/stdio/dprintf.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -int dprintf(int fd, const char *fmt, ...) -{ - int ret; - va_list ap; - va_start(ap, fmt); - ret = vdprintf(fd, fmt, ap); - va_end(ap); - return ret; -} diff --git a/05/musl-final/src/stdio/fclose.c b/05/musl-final/src/stdio/fclose.c deleted file mode 100644 index 26bc37e..0000000 --- a/05/musl-final/src/stdio/fclose.c +++ /dev/null @@ -1,21 +0,0 @@ -#include "stdio_impl.h" - -int fclose(FILE *f) -{ - int r; - int perm = f->flags & F_PERM; - - if (!perm) { - OFLLOCK(); - if (f->prev) f->prev->next = f->next; - if (f->next) f->next->prev = f->prev; - if (ofl_head == f) ofl_head = f->next; - OFLUNLOCK(); - } - - r = fflush(f) | f->close(f); - - if (!perm) free(f); - - return r; -} diff --git a/05/musl-final/src/stdio/feof.c b/05/musl-final/src/stdio/feof.c deleted file mode 100644 index 9038a7c..0000000 --- a/05/musl-final/src/stdio/feof.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "stdio_impl.h" - -#undef feof - -int feof(FILE *f) -{ - return !!(f->flags & F_EOF); -} - -int feof_unlocked(FILE *f) -{ - return !!(f->flags & F_EOF); -} diff --git a/05/musl-final/src/stdio/ferror.c b/05/musl-final/src/stdio/ferror.c deleted file mode 100644 index 2c59172..0000000 --- a/05/musl-final/src/stdio/ferror.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "stdio_impl.h" - -#undef ferror - -int ferror(FILE *f) -{ - return !!(f->flags & F_ERR); -} - -int ferror_unlocked(FILE *f) -{ - return !!(f->flags & F_ERR); -} diff --git a/05/musl-final/src/stdio/fflush.c b/05/musl-final/src/stdio/fflush.c deleted file mode 100644 index 5b79fa8..0000000 --- a/05/musl-final/src/stdio/fflush.c +++ /dev/null @@ -1,54 +0,0 @@ -#include "stdio_impl.h" - -static int __fflush_unlocked(FILE *f) -{ - /* If writing, flush output. */ - if (f->wpos > f->buf && __oflow(f)) return -1; - - /* If reading, sync position, per POSIX */ - if (f->rpos < f->rend) f->seek(f, f->rpos-f->rend, SEEK_CUR); - f->rpos = f->rend; - - /* Hook for special behavior on flush */ - if (f->flush) f->flush(f); - - return (f->flags & F_ERR) ? EOF : 0; -} - -#if 0 -/* stdout.c will override this if linked */ -static FILE *const __dummy = 0; -weak_alias(__dummy, __stdout_to_flush); -#else -extern FILE *const __stdout_to_flush; -#endif - -int fflush(FILE *f) -{ - int r; - FILE *next; - - if (f) { - FLOCK(f); - r = __fflush_unlocked(f); - FUNLOCK(f); - return r; - } - - r = __stdout_to_flush ? fflush(__stdout_to_flush) : 0; - - OFLLOCK(); - for (f=ofl_head; f; f=next) { - FLOCK(f); - OFLUNLOCK(); - r |= __fflush_unlocked(f); - OFLLOCK(); - next = f->next; - FUNLOCK(f); - } - OFLUNLOCK(); - - return r; -} - -weak_alias(__fflush_unlocked, fflush_unlocked); diff --git a/05/musl-final/src/stdio/fgetc.c b/05/musl-final/src/stdio/fgetc.c deleted file mode 100644 index 8810f35..0000000 --- a/05/musl-final/src/stdio/fgetc.c +++ /dev/null @@ -1,19 +0,0 @@ -#include "stdio_impl.h" - -int fgetc(FILE *f) -{ - int c; - FLOCK(f); - c = f->rpos < f->rstop ? *f->rpos++ : __uflow(f); - FUNLOCK(f); - return c; -} - -int fgetc_unlocked(FILE *f) -{ - int c; - FLOCK(f); - c = f->rpos < f->rstop ? *f->rpos++ : __uflow(f); - FUNLOCK(f); - return c; -} diff --git a/05/musl-final/src/stdio/fgetpos.c b/05/musl-final/src/stdio/fgetpos.c deleted file mode 100644 index 5b663d1..0000000 --- a/05/musl-final/src/stdio/fgetpos.c +++ /dev/null @@ -1,11 +0,0 @@ -#include "stdio_impl.h" - -int fgetpos(FILE *f, fpos_t *pos) -{ - off_t off = __ftello(f); - if (off < 0) return -1; - *(off_t *)pos = off; - return 0; -} - -LFS64(fgetpos); diff --git a/05/musl-final/src/stdio/fgets.c b/05/musl-final/src/stdio/fgets.c deleted file mode 100644 index 22dab95..0000000 --- a/05/musl-final/src/stdio/fgets.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "stdio_impl.h" - -#define MIN(a,b) ((a)<(b) ? (a) : (b)) - -char *fgets(char *s, int n, FILE *f) -{ - char *p = s; - unsigned char *z; - size_t k; - - if (!n--) return 0; - - FLOCK(f); - - while (n && !feof(f)) { - z = memchr(f->rpos, '\n', f->rend - f->rpos); - k = z ? z - f->rpos + 1 : f->rend - f->rpos; - k = MIN(k, n); - memcpy(p, f->rpos, k); - f->rpos += k; - p += k; - n -= k; - if (z) break; - __underflow(f); - } - *p = 0; - if (ferror(f)) p = s; - - FUNLOCK(f); - - return (p == s) ? 0 : s; -} - - -char *fgets_unlocked(char *s, int n, FILE *f) { - return fgets(s, n, f); -} diff --git a/05/musl-final/src/stdio/fgetwc.c b/05/musl-final/src/stdio/fgetwc.c deleted file mode 100644 index 77b30fd..0000000 --- a/05/musl-final/src/stdio/fgetwc.c +++ /dev/null @@ -1,51 +0,0 @@ -#include "stdio_impl.h" - -wint_t __fgetwc_unlocked(FILE *f) -{ - mbstate_t st = { 0 }; - wchar_t wc; - int c; - unsigned char b; - size_t l; - - f->mode |= f->mode+1; - - /* Convert character from buffer if possible */ - if (f->rpos < f->rend) { - l = mbrtowc(&wc, (void *)f->rpos, f->rend - f->rpos, &st); - if (l+2 >= 2) { - f->rpos += l + !l; /* l==0 means 1 byte, null */ - return wc; - } - if (l == -1) { - f->rpos++; - return WEOF; - } - } else l = -2; - - /* Convert character byte-by-byte from __uflow */ - while (l == -2) { - b = c = __uflow(f); - if (c < 0) { - if (!mbsinit(&st)) errno = EILSEQ; - return WEOF; - } - l = mbrtowc(&wc, (void *)&b, 1, &st); - if (l == -1) return WEOF; - } - - FUNLOCK(f); - return wc; -} - -wint_t fgetwc(FILE *f) -{ - wint_t c; - FLOCK(f); - c = __fgetwc_unlocked(f); - FUNLOCK(f); - return c; -} - -weak_alias(__fgetwc_unlocked, fgetwc_unlocked); -weak_alias(__fgetwc_unlocked, getwc_unlocked); diff --git a/05/musl-final/src/stdio/fgetws.c b/05/musl-final/src/stdio/fgetws.c deleted file mode 100644 index 2e76b56..0000000 --- a/05/musl-final/src/stdio/fgetws.c +++ /dev/null @@ -1,27 +0,0 @@ -#include "stdio_impl.h" - -wint_t __fgetwc_unlocked(FILE *); - -wchar_t *fgetws(wchar_t *s, int n, FILE *f) -{ - wchar_t *p = s; - - if (!n--) return s; - - FLOCK(f); - - for (; n; n--) { - wint_t c = __fgetwc_unlocked(f); - if (c == WEOF) break; - *p++ = c; - if (c == '\n') break; - } - *p = 0; - if (ferror(f)) p = s; - - FUNLOCK(f); - - return (p == s) ? NULL : s; -} - -weak_alias(fgetws, fgetws_unlocked); diff --git a/05/musl-final/src/stdio/fileno.c b/05/musl-final/src/stdio/fileno.c deleted file mode 100644 index 38bc8e8..0000000 --- a/05/musl-final/src/stdio/fileno.c +++ /dev/null @@ -1,11 +0,0 @@ -#include "stdio_impl.h" - -int fileno(FILE *f) -{ - return f->fd; -} - -int fileno_unlocked(FILE *f) -{ - return f->fd; -} diff --git a/05/musl-final/src/stdio/fmemopen.c b/05/musl-final/src/stdio/fmemopen.c deleted file mode 100644 index 77a6074..0000000 --- a/05/musl-final/src/stdio/fmemopen.c +++ /dev/null @@ -1,16 +0,0 @@ -#if 0 -#include "stdio_impl.h" - -static ssize_t mread(FILE *f, unsigned char *buf, size_t len) -{ - memcpy(buf, -} - -FILE *fmemopen(void *buf, size_t size, const char *mode) -{ - FILE *f = calloc(sizeof(FILE), 1); - if (!f) return 0; - - // -} -#endif diff --git a/05/musl-final/src/stdio/fopen.c b/05/musl-final/src/stdio/fopen.c deleted file mode 100644 index 670cf5f..0000000 --- a/05/musl-final/src/stdio/fopen.c +++ /dev/null @@ -1,34 +0,0 @@ -#include "stdio_impl.h" - -FILE *fopen(const char *filename, const char *mode) -{ - FILE *f; - int fd; - int flags; - int plus = !!strchr(mode, '+'); - - /* Check for valid initial mode character */ - if (!strchr("rwa", *mode)) { - errno = EINVAL; - return 0; - } - - /* Compute the flags to pass to open() */ - if (plus) flags = O_RDWR; - else if (*mode == 'r') flags = O_RDONLY; - else flags = O_WRONLY; - if (*mode != 'r') flags |= O_CREAT; - if (*mode == 'w') flags |= O_TRUNC; - if (*mode == 'a') flags |= O_APPEND; - - fd = __syscall_open(filename, flags, 0666); - if (fd < 0) return 0; - - f = __fdopen(fd, mode); - if (f) return f; - - __syscall_close(fd); - return 0; -} - -LFS64(fopen); diff --git a/05/musl-final/src/stdio/fprintf.c b/05/musl-final/src/stdio/fprintf.c deleted file mode 100644 index a220cc1..0000000 --- a/05/musl-final/src/stdio/fprintf.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -int fprintf(FILE *f, const char *fmt, ...) -{ - int ret; - va_list ap; - va_start(ap, fmt); - ret = vfprintf(f, fmt, ap); - va_end(ap); - return ret; -} diff --git a/05/musl-final/src/stdio/fputc.c b/05/musl-final/src/stdio/fputc.c deleted file mode 100644 index 3e0f738..0000000 --- a/05/musl-final/src/stdio/fputc.c +++ /dev/null @@ -1,19 +0,0 @@ -#include "stdio_impl.h" - -int fputc(int c, FILE *f) -{ - FLOCK(f); - if (c != f->lbf && f->wpos + 1 < f->wend) *f->wpos++ = c; - else c = __overflow(f, c); - FUNLOCK(f); - return c; -} - -int fputc_unlocked(int c, FILE *f) -{ - FLOCK(f); - if (c != f->lbf && f->wpos + 1 < f->wend) *f->wpos++ = c; - else c = __overflow(f, c); - FUNLOCK(f); - return c; -} diff --git a/05/musl-final/src/stdio/fputs.c b/05/musl-final/src/stdio/fputs.c deleted file mode 100644 index 5f78ca7..0000000 --- a/05/musl-final/src/stdio/fputs.c +++ /dev/null @@ -1,15 +0,0 @@ -#include "stdio_impl.h" - -int fputs(const char *s, FILE *f) -{ - size_t l = strlen(s); - if (!l) return 0; - return (int)fwrite(s, l, 1, f) - 1; -} - -int fputs_unlocked(const char *s, FILE *f) -{ - size_t l = strlen(s); - if (!l) return 0; - return (int)fwrite(s, l, 1, f) - 1; -} diff --git a/05/musl-final/src/stdio/fputwc.c b/05/musl-final/src/stdio/fputwc.c deleted file mode 100644 index b48bb74..0000000 --- a/05/musl-final/src/stdio/fputwc.c +++ /dev/null @@ -1,33 +0,0 @@ -#include "stdio_impl.h" - -wint_t __fputwc_unlocked(wchar_t c, FILE *f) -{ - char mbc[MB_LEN_MAX]; - int l; - - f->mode |= f->mode+1; - - if (isascii(c)) { - if (c != f->lbf && f->wpos + 1 < f->wend) *f->wpos++ = c; - else c = __overflow(f, c); - } else if (f->wpos + MB_LEN_MAX < f->wend) { - l = wctomb(f->wpos, c); - if (l < 0) c = WEOF; - else f->wpos += l; - } else { - l = wctomb(mbc, c); - if (l < 0 || __fwritex(mbc, l, f) < l) c = WEOF; - } - return c; -} - -wint_t fputwc(wchar_t c, FILE *f) -{ - FLOCK(f); - c = __fputwc_unlocked(c, f); - FUNLOCK(f); - return 0; -} - -weak_alias(__fputwc_unlocked, fputwc_unlocked); -weak_alias(__fputwc_unlocked, putwc_unlocked); diff --git a/05/musl-final/src/stdio/fputws.c b/05/musl-final/src/stdio/fputws.c deleted file mode 100644 index b75f95b..0000000 --- a/05/musl-final/src/stdio/fputws.c +++ /dev/null @@ -1,23 +0,0 @@ -#include "stdio_impl.h" - -int fputws(const wchar_t *ws, FILE *f) -{ - unsigned char buf[BUFSIZ]; - size_t l=0; - - FLOCK(f); - - f->mode |= f->mode+1; - - while (ws && (l = wcsrtombs((void *)buf, (void*)&ws, sizeof buf, 0))+1 > 1) - if (__fwritex(buf, l, f) < l) { - FUNLOCK(f); - return -1; - } - - FUNLOCK(f); - - return l; /* 0 or -1 */ -} - -weak_alias(fputws, fputws_unlocked); diff --git a/05/musl-final/src/stdio/fread.c b/05/musl-final/src/stdio/fread.c deleted file mode 100644 index 8b9ca55..0000000 --- a/05/musl-final/src/stdio/fread.c +++ /dev/null @@ -1,51 +0,0 @@ -#include "stdio_impl.h" - -#define MIN(a,b) ((a)<(b) ? (a) : (b)) - -size_t fread(void *destv, size_t size, size_t nmemb, FILE *f) -{ - unsigned char *dest = destv; - size_t len = size*nmemb, l = len, k; - - /* Never touch the file if length is zero.. */ - if (!l) return 0; - - FLOCK(f); - - for (;;) { - /* First exhaust the buffer. */ - k = MIN(f->rend - f->rpos, l); - memcpy(dest, f->rpos, k); - f->rpos += k; - dest += k; - l -= k; - - /* Stop on EOF or errors */ - if (f->flags & (F_EOF|F_ERR|F_NORD)) goto eof; - - /* Done? Or going unbuffered? */ - if (!l || l > f->buf_size/2) break; - - /* Otherwise, refill & read thru buffer. */ - __underflow(f); - } - - /* Read the remainder directly */ - for (; l; l-=k, dest+=k) { - k = f->read(f, dest, l); - if (k+1<=1) { - f->flags |= F_EOF | (F_ERR & k); - goto eof; - } - } - - FUNLOCK(f); - return nmemb; -eof: - FUNLOCK(f); - return (len-l)/size; -} - -size_t fread_unlocked(void *destv, size_t size, size_t nmemb, FILE *f) { - return fread(destv, size, nmemb, f); -} diff --git a/05/musl-final/src/stdio/freopen.c b/05/musl-final/src/stdio/freopen.c deleted file mode 100644 index 8d3af9f..0000000 --- a/05/musl-final/src/stdio/freopen.c +++ /dev/null @@ -1,47 +0,0 @@ -#include "stdio_impl.h" - -/* The basic idea of this implementation is to open a new FILE, - * hack the necessary parts of the new FILE into the old one, then - * close the new FILE. */ - -/* Locking is not necessary because, in the event of failure, the stream - * passed to freopen is invalid as soon as freopen is called. */ - -FILE *freopen(const char *filename, const char *mode, FILE *f) -{ - int fl; - FILE *f2; - - fflush(f); - - if (!filename) { - f2 = fopen("/dev/null", mode); - if (!f2) goto fail; - fl = __syscall_fcntl(f2->fd, F_GETFL, 0); - if (fl < 0 || __syscall_fcntl(f->fd, F_SETFL, fl) < 0) - goto fail2; - } else { - f2 = fopen(filename, mode); - if (!f2) goto fail; - if (__syscall_dup2(f2->fd, f->fd) < 0) - goto fail2; - } - - f->flags = (f->flags & F_PERM) | f2->flags; - f->read = f2->read; - f->write = f2->write; - f->seek = f2->seek; - f->close = f2->close; - f->flush = f2->flush; - - fclose(f2); - return f; - -fail2: - fclose(f2); -fail: - fclose(f); - return NULL; -} - -LFS64(freopen); diff --git a/05/musl-final/src/stdio/fscanf.c b/05/musl-final/src/stdio/fscanf.c deleted file mode 100644 index 51fc9b3..0000000 --- a/05/musl-final/src/stdio/fscanf.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -int fscanf(FILE *f, const char *fmt, ...) -{ - int ret; - va_list ap; - va_start(ap, fmt); - ret = vfscanf(f, fmt, ap); - va_end(ap); - return ret; -} diff --git a/05/musl-final/src/stdio/fseek.c b/05/musl-final/src/stdio/fseek.c deleted file mode 100644 index bfaad37..0000000 --- a/05/musl-final/src/stdio/fseek.c +++ /dev/null @@ -1,38 +0,0 @@ -#include "stdio_impl.h" - -int __fseeko_unlocked(FILE *f, off_t off, int whence) -{ - /* Adjust relative offset for unread data in buffer, if any. */ - if (whence == SEEK_CUR) off -= f->rend - f->rpos; - - /* If writing, flush output. */ - if (f->wpos > f->buf && __oflow(f)) return -1; - - /* Perform the underlying seek operation. */ - if (f->seek(f, off, whence) < 0) return -1; - - /* If seek succeeded, file is seekable and we discard read buffer. */ - f->rpos = f->rend = f->rstop = 0; - f->flags &= ~F_EOF; - - FUNLOCK(f); - return 0; -} - -int __fseeko(FILE *f, off_t off, int whence) -{ - int result; - FLOCK(f); - result = __fseeko_unlocked(f, off, whence); - FUNLOCK(f); - return result; -} - -int fseek(FILE *f, long off, int whence) -{ - return __fseeko(f, off, whence); -} - -weak_alias(__fseeko, fseeko); - -LFS64(fseeko); diff --git a/05/musl-final/src/stdio/fsetpos.c b/05/musl-final/src/stdio/fsetpos.c deleted file mode 100644 index 5d76c8c..0000000 --- a/05/musl-final/src/stdio/fsetpos.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "stdio_impl.h" - -int fsetpos(FILE *f, const fpos_t *pos) -{ - return __fseeko(f, *(const off_t *)pos, SEEK_SET); -} - -LFS64(fsetpos); diff --git a/05/musl-final/src/stdio/ftell.c b/05/musl-final/src/stdio/ftell.c deleted file mode 100644 index aa1f538..0000000 --- a/05/musl-final/src/stdio/ftell.c +++ /dev/null @@ -1,35 +0,0 @@ -#include "stdio_impl.h" - -off_t __ftello_unlocked(FILE *f) -{ - off_t pos = f->seek(f, 0, SEEK_CUR); - if (pos < 0) { - FUNLOCK(f); - return pos; - } - /* Adjust for data in buffer. */ - return pos - (f->rend - f->rpos) + (f->wpos - f->wbase); -} - -off_t __ftello(FILE *f) -{ - off_t pos; - FLOCK(f); - pos = __ftello_unlocked(f); - FUNLOCK(f); - return pos; -} - -long ftell(FILE *f) -{ - off_t pos = __ftello(f); - if (pos > LONG_MAX) { - errno = EOVERFLOW; - return -1; - } - return pos; -} - -weak_alias(__ftello, ftello); - -LFS64(ftello); diff --git a/05/musl-final/src/stdio/fwide.c b/05/musl-final/src/stdio/fwide.c deleted file mode 100644 index f4da47f..0000000 --- a/05/musl-final/src/stdio/fwide.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "stdio_impl.h" - -#define SH (8*sizeof(int)-1) -#define NORMALIZE(x) ((x)>>SH | -((-(x))>>SH)) - -int fwide(FILE *f, int mode) -{ - if (!f->mode) f->mode = NORMALIZE(mode); - return f->mode; -} diff --git a/05/musl-final/src/stdio/fwrite.c b/05/musl-final/src/stdio/fwrite.c deleted file mode 100644 index d6bf314..0000000 --- a/05/musl-final/src/stdio/fwrite.c +++ /dev/null @@ -1,59 +0,0 @@ -#include "stdio_impl.h" - -size_t __fwritex(const unsigned char *s, size_t l, FILE *f) -{ - size_t i = 0; - size_t k = f->wend - f->wpos; - - /* Handle line-buffered mode by breaking into 2 parts */ - if (f->lbf >= 0) { - /* Match /^(.*\n|)/ */ - for (i=l; i && s[i-1] != '\n'; i--); - if (i) { - f->lbf = EOF; - __fwritex(s, i, f); - f->lbf = '\n'; - __oflow(f); - return ferror(f) ? 0 : i + __fwritex(s+i, l-i, f); - } - } - - /* Buffer initial segment */ - if (k > l) k = l; - memcpy(f->wpos, s, k); - f->wpos += k; - if (f->wpos < f->wend) return l; - - /* If there's work left to do, flush buffer */ - __oflow(f); - if (ferror(f)) return 0; - - /* If the remainder will not fit in buffer, write it directly */ - if (l - k >= f->wend - f->wpos) - return k + f->write(f, s+k, l-k); - - /* Otherwise, buffer the remainder */ - memcpy(f->wpos, s+k, l-k); - f->wpos += l-k; - return l; -} - -size_t fwrite(const void *src, size_t size, size_t nmemb, FILE *f) -{ - size_t l = size*nmemb; - if (!l) return l; - FLOCK(f); - l = __fwritex(src, l, f); - FUNLOCK(f); - return l/size; -} - -size_t fwrite_unlocked(const void *src, size_t size, size_t nmemb, FILE *f) -{ - size_t l = size*nmemb; - if (!l) return l; - FLOCK(f); - l = __fwritex(src, l, f); - FUNLOCK(f); - return l/size; -} diff --git a/05/musl-final/src/stdio/fwscanf.c b/05/musl-final/src/stdio/fwscanf.c deleted file mode 100644 index a6892cf..0000000 --- a/05/musl-final/src/stdio/fwscanf.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include -#include - -int fwscanf(FILE *f, const wchar_t *fmt, ...) -{ - int ret; - va_list ap; - va_start(ap, fmt); - ret = vfwscanf(f, fmt, ap); - va_end(ap); - return ret; -} diff --git a/05/musl-final/src/stdio/getc.c b/05/musl-final/src/stdio/getc.c deleted file mode 100644 index b739b0a..0000000 --- a/05/musl-final/src/stdio/getc.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "stdio_impl.h" - -int getc(FILE *f) -{ - return fgetc(f); -} diff --git a/05/musl-final/src/stdio/getc_unlocked.c b/05/musl-final/src/stdio/getc_unlocked.c deleted file mode 100644 index 629223e..0000000 --- a/05/musl-final/src/stdio/getc_unlocked.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "stdio_impl.h" - -int getc_unlocked(FILE *f) -{ - return f->rpos < f->rstop ? *f->rpos++ : __uflow(f); -} - -weak_alias (getc_unlocked, fgetc_unlocked); diff --git a/05/musl-final/src/stdio/getchar.c b/05/musl-final/src/stdio/getchar.c deleted file mode 100644 index c101265..0000000 --- a/05/musl-final/src/stdio/getchar.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int getchar(void) -{ - return fgetc(stdin); -} diff --git a/05/musl-final/src/stdio/getchar_unlocked.c b/05/musl-final/src/stdio/getchar_unlocked.c deleted file mode 100644 index 299cb95..0000000 --- a/05/musl-final/src/stdio/getchar_unlocked.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "stdio_impl.h" - -int getchar_unlocked(void) -{ - return stdin->rpos < stdin->rstop ? *stdin->rpos++ : __uflow(stdin); -} diff --git a/05/musl-final/src/stdio/getdelim.c b/05/musl-final/src/stdio/getdelim.c deleted file mode 100644 index f770d20..0000000 --- a/05/musl-final/src/stdio/getdelim.c +++ /dev/null @@ -1,59 +0,0 @@ -#include "stdio_impl.h" - -#define MIN(a,b) ((a)<(b) ? (a) : (b)) - -ssize_t getdelim(char **s, size_t *n, int delim, FILE *f) -{ - char *tmp; - unsigned char *z; - size_t k; - size_t i=0; - - if (!n || !s) { - errno = EINVAL; - return -1; - } - - if (!*s) *n=0; - - FLOCK(f); - - while (!feof(f)) { - z = memchr(f->rpos, delim, f->rend - f->rpos); - k = z ? z - f->rpos + 1 : f->rend - f->rpos; - if (i+k >= *n) { - if (k >= SIZE_MAX-i) goto oom; - *n = i+k+1; - if (*n < SIZE_MAX/2) *n *= 2; - tmp = realloc(*s, *n); - if (!tmp) { - *n = i+k+1; - tmp = realloc(*s, *n); - if (!tmp) goto oom; - } - *s = tmp; - } - memcpy(*s+i, f->rpos, k); - f->rpos += k; - i += k; - if (z) break; - __underflow(f); - } - (*s)[i] = 0; - if (feof(f) || ferror(f)) { - FUNLOCK(f); - return -1; - } - - FUNLOCK(f); - - if (i > SSIZE_MAX) { - errno = EOVERFLOW; - return -1; - } - - return i; -oom: - errno = ENOMEM; - return -1; -} diff --git a/05/musl-final/src/stdio/getline.c b/05/musl-final/src/stdio/getline.c deleted file mode 100644 index a3a6651..0000000 --- a/05/musl-final/src/stdio/getline.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -ssize_t getline(char **s, size_t *n, FILE *f) -{ - return getdelim(s, n, '\n', f); -} diff --git a/05/musl-final/src/stdio/gets.c b/05/musl-final/src/stdio/gets.c deleted file mode 100644 index 24319eb..0000000 --- a/05/musl-final/src/stdio/gets.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "stdio_impl.h" - -char *gets(char *s) -{ - char *ret = fgets(s, INT_MAX, stdin); - if (ret && s[strlen(s)-1] == '\n') s[strlen(s)-1] = 0; - return ret; -} diff --git a/05/musl-final/src/stdio/getw.c b/05/musl-final/src/stdio/getw.c deleted file mode 100644 index de9e985..0000000 --- a/05/musl-final/src/stdio/getw.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int getw(FILE *f) -{ - int x; - return fread(&x, sizeof x, 1, f) ? x : EOF; -} diff --git a/05/musl-final/src/stdio/getwc.c b/05/musl-final/src/stdio/getwc.c deleted file mode 100644 index a2818bc..0000000 --- a/05/musl-final/src/stdio/getwc.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "stdio_impl.h" - -wint_t getwc(FILE *f) -{ - return fgetwc(f); -} diff --git a/05/musl-final/src/stdio/getwchar.c b/05/musl-final/src/stdio/getwchar.c deleted file mode 100644 index 2295bd4..0000000 --- a/05/musl-final/src/stdio/getwchar.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "stdio_impl.h" - -wint_t getwchar(void) -{ - return fgetwc(stdin); -} - -weak_alias(getwchar, getwchar_unlocked); diff --git a/05/musl-final/src/stdio/pclose.c b/05/musl-final/src/stdio/pclose.c deleted file mode 100644 index c2fe7a2..0000000 --- a/05/musl-final/src/stdio/pclose.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "stdio_impl.h" - -int pclose(FILE *f) -{ - int status; - fclose(f); - while (waitpid(f->pipe_pid, &status, 0) == -1) - if (errno != EINTR) return -1; - return status; -} diff --git a/05/musl-final/src/stdio/perror.c b/05/musl-final/src/stdio/perror.c deleted file mode 100644 index e4637c8..0000000 --- a/05/musl-final/src/stdio/perror.c +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include -#include -#include "stdio_impl.h" - -void perror(const char *msg) -{ -#if 1 - if (msg) fprintf(stderr, "%s: %m\n", msg, strerror(errno)); - else fprintf(stderr, "%m\n"); -#else - FILE *f = stderr; - char *errstr = strerror(errno); - - FLOCK(f); - - if (msg) { - __fwritex(msg, strlen(msg), f); - __putc_unlocked(':', f); - __putc_unlocked(' ', f); - } - __fwritex(errstr, strlen(errstr), f); - __putc_unlocked('\n', f); - - FUNLOCK(f); -#endif -} diff --git a/05/musl-final/src/stdio/popen.c b/05/musl-final/src/stdio/popen.c deleted file mode 100644 index 1d33e9d..0000000 --- a/05/musl-final/src/stdio/popen.c +++ /dev/null @@ -1,43 +0,0 @@ -#include "stdio_impl.h" - -FILE *popen(const char *cmd, const char *mode) -{ - int p[2]; - int op; - pid_t pid; - FILE *f; - const char *modes = "rw", *mi = strchr(modes, *mode); - - if (mi) { - op = mi-modes; - } else { - errno = EINVAL; - return 0; - } - - if (pipe(p)) return NULL; - f = fdopen(p[op], mode); - if (!f) { - close(p[0]); - close(p[1]); - return NULL; - } - - pid = fork(); - switch (pid) { - case -1: - fclose(f); - close(p[0]); - close(p[1]); - return NULL; - case 0: - dup2(p[1-op], 1-op); - close(p[0]); - close(p[1]); - execl("/bin/sh", "sh", "-c", cmd, (char *)0); - _exit(127); - } - close(p[1-op]); - f->pipe_pid = pid; - return f; -} diff --git a/05/musl-final/src/stdio/printf.c b/05/musl-final/src/stdio/printf.c deleted file mode 100644 index efeb8b3..0000000 --- a/05/musl-final/src/stdio/printf.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -int printf(const char *fmt, ...) -{ - int ret; - va_list ap; - va_start(ap, fmt); - ret = vprintf(fmt, ap); - va_end(ap); - return ret; -} diff --git a/05/musl-final/src/stdio/putc.c b/05/musl-final/src/stdio/putc.c deleted file mode 100644 index 3c9dc11..0000000 --- a/05/musl-final/src/stdio/putc.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "stdio_impl.h" - -int putc(int c, FILE *f) -{ - return fputc(c, f); -} - -weak_alias(putc, _IO_putc); diff --git a/05/musl-final/src/stdio/putc_unlocked.c b/05/musl-final/src/stdio/putc_unlocked.c deleted file mode 100644 index f01da71..0000000 --- a/05/musl-final/src/stdio/putc_unlocked.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "stdio_impl.h" - -int putc_unlocked(int c, FILE *f) -{ - return f->wpos < f->wstop ? (*f->wpos++ = c) : __overflow(f, c); -} - -weak_alias(putc_unlocked, fputc_unlocked); diff --git a/05/musl-final/src/stdio/putchar.c b/05/musl-final/src/stdio/putchar.c deleted file mode 100644 index 945636d..0000000 --- a/05/musl-final/src/stdio/putchar.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int putchar(int c) -{ - return fputc(c, stdout); -} diff --git a/05/musl-final/src/stdio/putchar_unlocked.c b/05/musl-final/src/stdio/putchar_unlocked.c deleted file mode 100644 index 72d47d1..0000000 --- a/05/musl-final/src/stdio/putchar_unlocked.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "stdio_impl.h" - -int putchar_unlocked(int c) -{ - return stdout->wpos < stdout->wstop ? - (*stdout->wpos++ = c) : __overflow(stdout, c); -} diff --git a/05/musl-final/src/stdio/puts.c b/05/musl-final/src/stdio/puts.c deleted file mode 100644 index eb70efd..0000000 --- a/05/musl-final/src/stdio/puts.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "stdio_impl.h" - -int puts(const char *s) -{ - return -(fputs(s, stdout) < 0 || putchar('\n') < 0); -} diff --git a/05/musl-final/src/stdio/putw.c b/05/musl-final/src/stdio/putw.c deleted file mode 100644 index 137832e..0000000 --- a/05/musl-final/src/stdio/putw.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int putw(int x, FILE *f) -{ - return fwrite(&x, sizeof x, 1, f) ? x : EOF; -} diff --git a/05/musl-final/src/stdio/putwc.c b/05/musl-final/src/stdio/putwc.c deleted file mode 100644 index 80b54a4..0000000 --- a/05/musl-final/src/stdio/putwc.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "stdio_impl.h" - -wint_t putwc(wchar_t c, FILE *f) -{ - return fputwc(c, f); -} diff --git a/05/musl-final/src/stdio/putwchar.c b/05/musl-final/src/stdio/putwchar.c deleted file mode 100644 index 3aacc1c..0000000 --- a/05/musl-final/src/stdio/putwchar.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "stdio_impl.h" - -wint_t putwchar(wchar_t c) -{ - return fputwc(c, stdout); -} - -weak_alias(putwchar, putwchar_unlocked); diff --git a/05/musl-final/src/stdio/remove.c b/05/musl-final/src/stdio/remove.c deleted file mode 100644 index 8e33827..0000000 --- a/05/musl-final/src/stdio/remove.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int remove(const char *path) -{ - return __syscall_unlink(path); -} diff --git a/05/musl-final/src/stdio/rename.c b/05/musl-final/src/stdio/rename.c deleted file mode 100644 index 4eced08..0000000 --- a/05/musl-final/src/stdio/rename.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int rename(const char *old, const char *new) -{ - return syscall2(__NR_rename, (long)old, (long)new); -} diff --git a/05/musl-final/src/stdio/rewind.c b/05/musl-final/src/stdio/rewind.c deleted file mode 100644 index 7944b43..0000000 --- a/05/musl-final/src/stdio/rewind.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -void rewind(FILE *f) -{ - fseek(f, 0, SEEK_SET); -} diff --git a/05/musl-final/src/stdio/scanf.c b/05/musl-final/src/stdio/scanf.c deleted file mode 100644 index a04a440..0000000 --- a/05/musl-final/src/stdio/scanf.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -int scanf(const char *fmt, ...) -{ - int ret; - va_list ap; - va_start(ap, fmt); - ret = vscanf(fmt, ap); - va_end(ap); - return ret; -} diff --git a/05/musl-final/src/stdio/setbuf.c b/05/musl-final/src/stdio/setbuf.c deleted file mode 100644 index 205afcf..0000000 --- a/05/musl-final/src/stdio/setbuf.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "stdio_impl.h" - -void setbuf(FILE *f, char *buf) -{ - setvbuf(f, buf, buf ? _IOFBF : _IONBF, BUFSIZ); -} diff --git a/05/musl-final/src/stdio/setvbuf.c b/05/musl-final/src/stdio/setvbuf.c deleted file mode 100644 index 2985d3f..0000000 --- a/05/musl-final/src/stdio/setvbuf.c +++ /dev/null @@ -1,22 +0,0 @@ -#include "stdio_impl.h" - -/* This function makes no attempt to protect the user from his/her own - * stupidity. If called any time but when then ISO C standard specifically - * allows it, all hell can and will break loose, especially with threads! - * - * This implementation ignores all arguments except the buffering type, - * and uses the existing buffer allocated alongside the FILE object. - * In the case of stderr where the preexisting buffer is length 1, it - * is not possible to set line buffering or full buffering. */ - -int setvbuf(FILE *f, char *buf, int type, size_t size) -{ - f->lbf = EOF; - - if (type == _IONBF) - f->buf_size = 1; - else if (type == _IOLBF) - f->lbf = '\n'; - - return 0; -} diff --git a/05/musl-final/src/stdio/snprintf.c b/05/musl-final/src/stdio/snprintf.c deleted file mode 100644 index 4071c2f..0000000 --- a/05/musl-final/src/stdio/snprintf.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include - -int snprintf(char *s, size_t n, const char *fmt, ...) -{ - int ret; - va_list ap; - va_start(ap, fmt); - ret = vsnprintf(s, n, fmt, ap); - va_end(ap); - return ret; -} - diff --git a/05/musl-final/src/stdio/sprintf.c b/05/musl-final/src/stdio/sprintf.c deleted file mode 100644 index 6b22540..0000000 --- a/05/musl-final/src/stdio/sprintf.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -int sprintf(char *s, const char *fmt, ...) -{ - int ret; - va_list ap; - va_start(ap, fmt); - ret = vsprintf(s, fmt, ap); - va_end(ap); - return ret; -} diff --git a/05/musl-final/src/stdio/sscanf.c b/05/musl-final/src/stdio/sscanf.c deleted file mode 100644 index a1cea69..0000000 --- a/05/musl-final/src/stdio/sscanf.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -int sscanf(const char *s, const char *fmt, ...) -{ - int ret; - va_list ap; - va_start(ap, fmt); - ret = vsscanf(s, fmt, ap); - va_end(ap); - return ret; -} diff --git a/05/musl-final/src/stdio/stderr.c b/05/musl-final/src/stdio/stderr.c deleted file mode 100644 index 4a79d4e..0000000 --- a/05/musl-final/src/stdio/stderr.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "stdio_impl.h" - -static unsigned char buf[1+UNGET]; -static FILE f = { - .buf = buf+UNGET, - .buf_size = 1, - .fd = 2, - .flags = F_PERM | F_NORD, - .write = __stdio_write, - .seek = __stdio_seek, - .close = __stdio_close, -}; -FILE *const stderr = &f; diff --git a/05/musl-final/src/stdio/stdin.c b/05/musl-final/src/stdio/stdin.c deleted file mode 100644 index 51c9923..0000000 --- a/05/musl-final/src/stdio/stdin.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "stdio_impl.h" - -static unsigned char buf[BUFSIZ+UNGET]; -static FILE f = { - .buf = buf+UNGET, - .buf_size = sizeof buf-UNGET, - .fd = 0, - .flags = F_PERM | F_NOWR, - .read = __stdio_read, - .seek = __stdio_seek, - .close = __stdio_close, -}; -FILE *const stdin = &f; diff --git a/05/musl-final/src/stdio/stdout.c b/05/musl-final/src/stdio/stdout.c deleted file mode 100644 index bf6eea6..0000000 --- a/05/musl-final/src/stdio/stdout.c +++ /dev/null @@ -1,17 +0,0 @@ -#include "stdio_impl.h" - -static unsigned char buf[BUFSIZ+UNGET]; -static FILE f = { - .buf = buf+UNGET, - .buf_size = sizeof buf-UNGET, - .fd = 1, - .flags = F_PERM | F_NORD, - .lbf = '\n', - .write = __stdio_write, - .seek = __stdio_seek, - .close = __stdio_close, -}; -FILE *const stdout = &f; - -/* overrides symbol in fflush.c, used for flushing NULL */ -FILE *const __stdout_to_flush = &f; diff --git a/05/musl-final/src/stdio/swscanf.c b/05/musl-final/src/stdio/swscanf.c deleted file mode 100644 index b66ad03..0000000 --- a/05/musl-final/src/stdio/swscanf.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include -#include - -int swscanf(const wchar_t *s, const wchar_t *fmt, ...) -{ - int ret; - va_list ap; - va_start(ap, fmt); - ret = vswscanf(s, fmt, ap); - va_end(ap); - return ret; -} diff --git a/05/musl-final/src/stdio/tempnam.c b/05/musl-final/src/stdio/tempnam.c deleted file mode 100644 index 2cbcb86..0000000 --- a/05/musl-final/src/stdio/tempnam.c +++ /dev/null @@ -1,42 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include "libc.h" - -char *tempnam(const char *dir, const char *pfx) -{ - static int lock; - static int index; - char *s; - int pid = getpid(); - int l; - - if (!dir) dir = P_tmpdir; - if (!pfx) pfx = "temp"; - - if (access(dir, R_OK|W_OK|X_OK) != 0) - return NULL; - - l = strlen(dir) + 1 + strlen(pfx) + 2 + sizeof(int)*3*2 + 1; - s = malloc(l); - if (!s) { - errno = ENOMEM; - return NULL; - } - - LOCK(&lock); - for (; index < TMP_MAX; index++) { - snprintf(s, l, "%s/%s-%d-%d", dir, pfx, pid, index); - if (access(s, F_OK) != 0) { - UNLOCK(&lock); - return s; - } - } - UNLOCK(&lock); - free(s); - return NULL; -} diff --git a/05/musl-final/src/stdio/tmpfile.c b/05/musl-final/src/stdio/tmpfile.c deleted file mode 100644 index 185025f..0000000 --- a/05/musl-final/src/stdio/tmpfile.c +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include -#include -#include "stdio_impl.h" - -FILE *tmpfile(void) -{ - char buf[L_tmpnam], *s; - int fd; - FILE *f; - for (;;) { - s = tmpnam(buf); - if (!s) return NULL; - fd = __syscall_open(s, O_RDWR | O_CREAT | O_EXCL, 0600); - if (fd >= 0) { - f = __fdopen(fd, "w+"); - remove(s); - return f; - } - } -} - -LFS64(tmpfile); diff --git a/05/musl-final/src/stdio/tmpnam.c b/05/musl-final/src/stdio/tmpnam.c deleted file mode 100644 index 14d5922..0000000 --- a/05/musl-final/src/stdio/tmpnam.c +++ /dev/null @@ -1,38 +0,0 @@ -#include -#include -#include -#include -#include -#include "libc.h" - -char *tmpnam(char *s) -{ - static int lock; - static int index; - static char *s2; - int pid = getpid(); - char *dir = getenv("TMPDIR"); - - if (!s) { - if (!s2) s2 = malloc(L_tmpnam); - s = s2; - } - - /* this interface is insecure anyway but at least we can try.. */ - if (!dir || strlen(dir) > L_tmpnam-32) - dir = P_tmpdir; - - if (access(dir, R_OK|W_OK|X_OK) != 0) - return NULL; - - LOCK(&lock); - for (index++; index < TMP_MAX; index++) { - snprintf(s, L_tmpnam, "%s/temp%d-%d", dir, pid, index); - if (access(s, F_OK) != 0) { - UNLOCK(&lock); - return s; - } - } - UNLOCK(&lock); - return NULL; -} diff --git a/05/musl-final/src/stdio/ungetc.c b/05/musl-final/src/stdio/ungetc.c deleted file mode 100644 index 0718168..0000000 --- a/05/musl-final/src/stdio/ungetc.c +++ /dev/null @@ -1,33 +0,0 @@ -#include "stdio_impl.h" - -int ungetc(int c, FILE *f) -{ - if (c == EOF) return c; - - FLOCK(f); - - /* Fail if unreadable or writing and unable to flush */ - if ((f->flags & (F_ERR|F_NORD)) || (f->wpos && __oflow(f))) { - FUNLOCK(f); - return EOF; - } - - /* Clear write mode */ - f->wbase = f->wpos = f->wstop = f->wend = 0; - - /* Put the file in read mode */ - if (!f->rpos) f->rpos = f->rend = f->buf; - - /* If unget buffer is already full, fail. */ - if (f->rpos <= f->buf - UNGET) { - FUNLOCK(f); - return EOF; - } - - /* Put a byte back into the buffer */ - *--f->rpos = c; - f->flags &= ~F_EOF; - - FUNLOCK(f); - return c; -} diff --git a/05/musl-final/src/stdio/ungetwc.c b/05/musl-final/src/stdio/ungetwc.c deleted file mode 100644 index f7cde2e..0000000 --- a/05/musl-final/src/stdio/ungetwc.c +++ /dev/null @@ -1,45 +0,0 @@ -#include "stdio_impl.h" - -wint_t ungetwc(wint_t c, FILE *f) -{ - unsigned char mbc[MB_LEN_MAX]; - int l=1; - - if (c == WEOF) return c; - - /* Try conversion early so we can fail without locking if invalid */ - if (!isascii(c) && (l = wctomb(mbc, c)) < 0) - return WEOF; - - FLOCK(f); - - f->mode |= f->mode+1; - - /* Fail if unreadable or writing and unable to flush */ - if ((f->flags & (F_ERR|F_NORD)) || (f->wpos && __oflow(f))) { - FUNLOCK(f); - return EOF; - } - - /* Clear write mode */ - f->wpos = f->wstop = f->wend = 0; - - /* Put the file in read mode */ - if (!f->rpos) f->rpos = f->rend = f->buf; - - /* If unget buffer is nonempty, fail. */ - if (f->rpos < f->buf) { - FUNLOCK(f); - return WEOF; - } - - /* Put character back into the buffer */ - if (isascii(c)) *--f->rpos = c; - else memcpy(f->rpos -= l, mbc, l); - - /* Clear EOF */ - f->flags &= ~F_EOF; - - FUNLOCK(f); - return c; -} diff --git a/05/musl-final/src/stdio/vasprintf.c b/05/musl-final/src/stdio/vasprintf.c deleted file mode 100644 index f2bbc7a..0000000 --- a/05/musl-final/src/stdio/vasprintf.c +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include -#include - -#define GUESS 240U - -int vasprintf(char **s, const char *fmt, va_list ap) -{ - va_list ap2; - char *a; - int l=GUESS; - - if (!(a=malloc(GUESS))) return -1; - - va_copy(ap2, ap); - l=vsnprintf(a, GUESS, fmt, ap2); - va_end(ap2); - - if (l(b) ? (a) : (b)) -#define MIN(a,b) ((a)<(b) ? (a) : (b)) -#define CONCAT2(x,y) x ## y -#define CONCAT(x,y) CONCAT2(x,y) - -/* Convenient bit representation for modifier flags, which all fall - * within 31 codepoints of the space character. */ - -#define ALT_FORM (1U<<'#'-' ') -#define ZERO_PAD (1U<<'0'-' ') -#define LEFT_ADJ (1U<<'-'-' ') -#define PAD_POS (1U<<' '-' ') -#define MARK_POS (1U<<'+'-' ') -#define GROUPED (1U<<'\''-' ') - -#define FLAGMASK (ALT_FORM|ZERO_PAD|LEFT_ADJ|PAD_POS|MARK_POS|GROUPED) - -#if UINT_MAX == ULONG_MAX -#define LONG_IS_INT -#endif - -#if SIZE_MAX != ULONG_MAX || UINTMAX_MAX != ULLONG_MAX -#define ODD_TYPES -#endif - -/* State machine to accept length modifiers + conversion specifiers. - * Result is 0 on failure, or an argument type to pop on success. */ - -enum { - BARE, LPRE, LLPRE, HPRE, HHPRE, BIGLPRE, - ZTPRE, JPRE, - STOP, - PTR, INT, UINT, ULLONG, -#ifndef LONG_IS_INT - LONG, ULONG, -#else -#define LONG INT -#define ULONG UINT -#endif - SHORT, USHORT, CHAR, UCHAR, -#ifdef ODD_TYPES - LLONG, SIZET, IMAX, UMAX, PDIFF, UIPTR, -#else -#define LLONG ULLONG -#define SIZET ULONG -#define IMAX LLONG -#define UMAX ULLONG -#define PDIFF LONG -#define UIPTR ULONG -#endif - DBL, LDBL, - NOARG, - MAXSTATE -}; - -#define S(x) [(x)-'A'] - -static const unsigned char states[]['z'-'A'+1] = { - { /* 0: bare types */ - S('d') = INT, S('i') = INT, - S('o') = UINT, S('u') = UINT, S('x') = UINT, S('X') = UINT, - S('e') = DBL, S('f') = DBL, S('g') = DBL, S('a') = DBL, - S('E') = DBL, S('F') = DBL, S('G') = DBL, S('A') = DBL, - S('c') = CHAR, S('C') = INT, - S('s') = PTR, S('S') = PTR, S('p') = UIPTR, S('n') = PTR, - S('m') = NOARG, - S('l') = LPRE, S('h') = HPRE, S('L') = BIGLPRE, - S('z') = ZTPRE, S('j') = JPRE, S('t') = ZTPRE, - }, { /* 1: l-prefixed */ - S('d') = LONG, S('i') = LONG, - S('o') = ULONG, S('u') = ULONG, S('x') = ULONG, S('X') = ULONG, - S('c') = INT, S('s') = PTR, S('n') = PTR, - S('l') = LLPRE, - }, { /* 2: ll-prefixed */ - S('d') = LLONG, S('i') = LLONG, - S('o') = ULLONG, S('u') = ULLONG, - S('x') = ULLONG, S('X') = ULLONG, - S('n') = PTR, - }, { /* 3: h-prefixed */ - S('d') = SHORT, S('i') = SHORT, - S('o') = USHORT, S('u') = USHORT, - S('x') = USHORT, S('X') = USHORT, - S('n') = PTR, - S('h') = HHPRE, - }, { /* 4: hh-prefixed */ - S('d') = CHAR, S('i') = CHAR, - S('o') = UCHAR, S('u') = UCHAR, - S('x') = UCHAR, S('X') = UCHAR, - S('n') = PTR, - }, { /* 5: L-prefixed */ - S('e') = LDBL, S('f') = LDBL, S('g') = LDBL, S('a') = LDBL, - S('E') = LDBL, S('F') = LDBL, S('G') = LDBL, S('A') = LDBL, - S('n') = PTR, - }, { /* 6: z- or t-prefixed (assumed to be same size) */ - S('d') = PDIFF, S('i') = PDIFF, - S('o') = SIZET, S('u') = SIZET, - S('x') = SIZET, S('X') = SIZET, - S('n') = PTR, - }, { /* 7: j-prefixed */ - S('d') = IMAX, S('i') = IMAX, - S('o') = UMAX, S('u') = UMAX, - S('x') = UMAX, S('X') = UMAX, - S('n') = PTR, - } -}; - -#define OOB(x) ((unsigned)(x)-'A' > 'z'-'A') - -union arg -{ - uintmax_t i; - long double f; - void *p; -}; - -static void pop_arg(union arg *arg, int type, va_list *ap) -{ - /* Give the compiler a hint for optimizing the switch. */ - if ((unsigned)type > MAXSTATE) return; - switch (type) { - case PTR: arg->p = va_arg(*ap, void *); - break; case INT: arg->i = va_arg(*ap, int); - break; case UINT: arg->i = va_arg(*ap, unsigned int); -#ifndef LONG_IS_INT - break; case LONG: arg->i = va_arg(*ap, long); - break; case ULONG: arg->i = va_arg(*ap, unsigned long); -#endif - break; case ULLONG: arg->i = va_arg(*ap, unsigned long long); - break; case SHORT: arg->i = (short)va_arg(*ap, int); - break; case USHORT: arg->i = (unsigned short)va_arg(*ap, int); - break; case CHAR: arg->i = (signed char)va_arg(*ap, int); - break; case UCHAR: arg->i = (unsigned char)va_arg(*ap, int); -#ifdef ODD_TYPES - break; case LLONG: arg->i = va_arg(*ap, long long); - break; case SIZET: arg->i = va_arg(*ap, size_t); - break; case IMAX: arg->i = va_arg(*ap, intmax_t); - break; case UMAX: arg->i = va_arg(*ap, uintmax_t); - break; case PDIFF: arg->i = va_arg(*ap, ptrdiff_t); - break; case UIPTR: arg->i = (uintptr_t)va_arg(*ap, void *); -#endif - break; case DBL: arg->f = va_arg(*ap, double); - break; case LDBL: arg->f = va_arg(*ap, long double); - } -} - -static void out(FILE *f, const char *s, size_t l) -{ - __fwritex(s, l, f); -} - -static void pad(FILE *f, char c, int w, int l, int fl) -{ - char pad[256]; - if (fl & (LEFT_ADJ | ZERO_PAD) || l >= w) return; - l = w - l; - memset(pad, c, l>sizeof pad ? sizeof pad : l); - for (; l >= sizeof pad; l -= sizeof pad) - out(f, pad, sizeof pad); - out(f, pad, l); -} - -static const char xdigits[16] = { - "0123456789ABCDEF" -}; - -static char *fmt_x(uintmax_t x, char *s, int lower) -{ - for (; x; x>>=4) *--s = xdigits[(x&15)]|lower; - return s; -} - -static char *fmt_o(uintmax_t x, char *s) -{ - for (; x; x>>=3) *--s = '0' + (x&7); - return s; -} - -static char *fmt_u(uintmax_t x, char *s) -{ - unsigned long y; - for ( ; x>ULONG_MAX; x/=10) *--s = '0' + x%10; - for (y=x; y; y/=10) *--s = '0' + y%10; - return s; -} - -static long double negate_ld(long double d) { - register unsigned long long *p = (unsigned long long *)&d; - p[1] ^= 1ul<<15; - return *(long double *)p; -} - -static int fmt_fp(FILE *f, long double y, int w, int p, int fl, int t) -{ - uint32_t big[(LDBL_MAX_EXP+LDBL_MANT_DIG)/9+1]; - uint32_t *a, *d, *r, *z; - int e2=0, e, i, j, l; - char buf[9+LDBL_MANT_DIG/4], *s; - const char *prefix="-+ "; - int pl; - char ebuf0[3*sizeof(int)], *ebuf=&ebuf0[3*sizeof(int)], *estr; - - pl=1; - if (y<0 || 1/y<0) { - y=negate_ld(y); - } else if (fl & MARK_POS) { - prefix++; - } else if (fl & PAD_POS) { - prefix+=2; - } else pl=0; - - if (!isfinite(y)) { - char *s = (t&32)?"inf":"INF"; - if (y!=y) s=(t&32)?"nan":"NAN", pl=0; - pad(f, ' ', w, 3+pl, fl&~ZERO_PAD); - out(f, prefix, pl); - out(f, s, 3); - pad(f, ' ', w, 3+pl, fl^LEFT_ADJ); - return MAX(w, 3+pl); - } - - y = frexpl(y, &e2) * 2; - if (y) e2--; - - if ((t|32)=='a') { - long double round = 8.0; - int re; - - if (p<0 || p>=LDBL_MANT_DIG/4-1) re=0; - else re=LDBL_MANT_DIG/4-1-p; - - if (re) { - if (pl && *prefix=='-') y=negate_ld(y); - while (re--) round*=16; - y+=round; - y-=round; - if (y<0) y=negate_ld(y); - } - - estr=fmt_u(e2<0 ? -e2 : e2, ebuf); - if (estr==ebuf) *--estr='0'; - *--estr = (e2<0 ? '-' : '+'); - *--estr = t+('p'-'a'); - - s=buf; - *s++='0'; - *s++=t+('x'-'a'); - do { - int x=y; - *s++=xdigits[x]|(t&32); - y=16*(y-x); - if (s-buf==3 && (y||p>0||(fl&ALT_FORM))) *s++='.'; - } while (y); - - if (p<0) p = s-buf-4; - l = 1 + p + (p || (fl&ALT_FORM)) + ebuf-estr; - - pad(f, ' ', w, pl+l, fl); - out(f, prefix, pl); - pad(f, '0', w, pl+l, fl^ZERO_PAD); - out(f, buf, s-buf); - pad(f, '0', l-(ebuf-estr)-(s-buf), 0, 0); - out(f, estr, ebuf-estr); - pad(f, '0', w, pl+l, fl^LEFT_ADJ); - return MAX(w, pl+l); - } - if (p<0) p=6; - - y *= 0x1p28; e2-=28; - - if (e2<0) a=r=z=big; - else a=r=z=big+sizeof(big)/sizeof(*big) - LDBL_MANT_DIG - 1; - - do { - *z = y; - y = 1000000000*(y-*z++); - } while (y); - - while (e2>0) { - uint32_t carry=0; - int sh=MIN(29,e2); - for (d=z-1; d>=a; d--) { - uint64_t x = ((uint64_t)*d<a) z--; - if (carry) *--a = carry; - e2-=sh; - } - while (e2<0) { - uint32_t carry=0, *z2; - int sh=MIN(9,-e2); - for (d=a; d>sh) + carry; - carry = (1000000000>>sh) * rm; - } - if (!*a) a++; - if (carry) *z++ = carry; - /* Avoid (slow!) computation past requested precision */ - z2 = ((t|32)=='f' ? r : a) + 2 + p/9; - z = MIN(z, z2); - e2+=sh; - } - - if (a=i; i*=10, e++); - else e=0; - - /* Perform rounding: j is precision after the radix (possibly neg) */ - j = p - ((t|32)!='f')*e - ((t|32)=='g'); - if (j < 9*(z-r-1)) { - uint32_t x; - /* We avoid C's broken division of negative numbers */ - d = r + 1 + (j+9*LDBL_MAX_EXP)/9 - LDBL_MAX_EXP; - j += 9*LDBL_MAX_EXP; - j %= 9; - for (i=10, j++; j<9; i*=10, j++); - x = *d % i; - /* Are there any significant digits past j? */ - if (x || d+1!=z) { - long double round = CONCAT(0x1p,LDBL_MANT_DIG); - long double small; - if (x 999999999) { - *d--=0; - (*d)++; - } - if (d=i; i*=10, e++); - } - } - for (; !z[-1] && z>a; z--); - } - - if ((t|32)=='g') { - if (!p) p++; - if (p>e && e>=-4) { - t--; - p-=e+1; - } else { - t-=2; - p--; - } - if (!(fl&ALT_FORM)) { - /* Count trailing zeros in last place */ - if (z>a) for (i=10, j=0; z[-1]%i==0; i*=10, j++); - else j=9; - if ((t|32)=='f') - p = MIN(p,MAX(0,9*(z-r-1)-j)); - else - p = MIN(p,MAX(0,9*(z-r-1)+e-j)); - } - } - l = 1 + p + (p || (fl&ALT_FORM)); - if ((t|32)=='f') { - if (e>0) l+=e; - } else { - estr=fmt_u(e<0 ? -e : e, ebuf); - while(ebuf-estr<2) *--estr='0'; - *--estr = (e<0 ? '-' : '+'); - *--estr = t; - l += ebuf-estr; - } - - pad(f, ' ', w, pl+l, fl); - out(f, prefix, pl); - pad(f, '0', w, pl+l, fl^ZERO_PAD); - - if ((t|32)=='f') { - if (a>r) a=r; - for (d=a; d<=r; d++) { - char *s = fmt_u(*d, buf+9); - if (d!=a) while (s>buf) *--s='0'; - else if (s==buf+9) *--s='0'; - out(f, s, buf+9-s); - } - if (p || (fl&ALT_FORM)) out(f, ".", 1); - for (; d0; d++, p-=9) { - char *s = fmt_u(*d, buf+9); - while (s>buf) *--s='0'; - out(f, s, MIN(9,p)); - } - pad(f, '0', p+9, 9, 0); - } else { - if (z<=a) z=a+1; - for (d=a; d=0; d++) { - char *s = fmt_u(*d, buf+9); - if (s==buf+9) *--s='0'; - if (d!=a) while (s>buf) *--s='0'; - else { - out(f, s++, 1); - if (p>0||(fl&ALT_FORM)) out(f, ".", 1); - } - out(f, s, MIN(buf+9-s, p)); - p -= buf+9-s; - } - pad(f, '0', p+18, 18, 0); - out(f, estr, ebuf-estr); - } - - pad(f, ' ', w, pl+l, fl^LEFT_ADJ); - - return MAX(w, pl+l); -} - -static int getint(char **s) { - int i; - for (i=0; isdigit(**s); (*s)++) - i = 10*i + (**s-'0'); - return i; -} - -static int printf_core(FILE *f, const char *fmt, va_list *ap, union arg *nl_arg, int *nl_type) -{ - char *a, *z, *s=(char *)fmt; - unsigned l10n=0, litpct, fl; - int w, p; - union arg arg; - int argpos; - unsigned st, ps; - int cnt=0, l=0; - int i; - char buf[sizeof(uintmax_t)*3+3+LDBL_MANT_DIG/4]; - const char *prefix; - int t, pl; - wchar_t wc[2], *ws; - char mb[4]; - - for (;;) { - /* Update output count, end loop when fmt is exhausted */ - if (cnt >= 0) { - if (l > INT_MAX - cnt) { - if (!ferror(f)) errno = EOVERFLOW; - cnt = -1; - } else cnt += l; - } - if (!*s) break; - - /* Handle literal text and %% format specifiers */ - for (a=s; *s && *s!='%'; s++); - litpct = strspn(s, "%")/2; /* Optimize %%%% runs */ - z = s+litpct; - s += 2*litpct; - l = z-a; - if (f) out(f, a, l); - if (l) continue; - - if (isdigit(s[1]) && s[2]=='$') { - l10n=1; - argpos = s[1]-'0'; - s+=3; - } else { - argpos = -1; - s++; - } - - /* Read modifier flags */ - for (fl=0; (unsigned)*s-' '<32 && (FLAGMASK&(1U<<*s-' ')); s++) - fl |= 1U<<*s-' '; - - /* Read field width */ - if (*s=='*') { - if (isdigit(s[1]) && s[2]=='$') { - l10n=1; - nl_type[s[1]-'0'] = INT; - w = nl_arg[s[1]-'0'].i; - s+=3; - } else if (!l10n) { - w = f ? va_arg(*ap, int) : 0; - s++; - } else return -1; - if (w<0) fl|=LEFT_ADJ, w=-w; - } else if ((w=getint(&s))<0) return -1; - - /* Read precision */ - if (*s=='.' && s[1]=='*') { - if (isdigit(s[2]) && s[3]=='$') { - nl_type[s[2]-'0'] = INT; - p = nl_arg[s[2]-'0'].i; - s+=4; - } else if (!l10n) { - p = f ? va_arg(*ap, int) : 0; - s+=2; - } else return -1; - } else if (*s=='.') { - s++; - p = getint(&s); - } else p = -1; - - /* Format specifier state machine */ - st=0; - do { - if (OOB(*s)) return -1; - ps=st; - st=states[st]S(*s++); - } while (st-1=0) return -1; - else if (!f) continue; - } else { - if (argpos>=0) nl_type[argpos]=st, arg=nl_arg[argpos]; - else if (f) pop_arg(&arg, st, ap); - else return 0; - } - - if (!f) continue; - - z = buf + sizeof(buf); - prefix = "-+ 0X0x"; - pl = 0; - t = s[-1]; - - /* Transform ls,lc -> S,C */ - if (ps && (t&15)==3) t&=~32; - - /* - and 0 flags are mutually exclusive */ - if (fl & LEFT_ADJ) fl &= ~ZERO_PAD; - - switch(t) { - case 'n': - switch(ps) { - case BARE: *(int *)arg.p = l; break; - case LPRE: *(long *)arg.p = l; break; - case LLPRE: *(long long *)arg.p = l; break; - case HPRE: *(unsigned short *)arg.p = l; break; - case HHPRE: *(unsigned char *)arg.p = l; break; - case ZTPRE: *(size_t *)arg.p = l; break; - case JPRE: *(uintmax_t *)arg.p = l; break; - } - continue; - case 'p': - p = MAX(p, 2*sizeof(void*)); - t = 'x'; - fl |= ALT_FORM; - case 'x': case 'X': - a = fmt_x(arg.i, z, t&32); - if (fl & ALT_FORM) prefix+=(t>>4), pl=2; - if (0) { - case 'o': - a = fmt_o(arg.i, z); - if ((fl&ALT_FORM) && arg.i) prefix+=5, pl=1; - } if (0) { - case 'd': case 'i': - pl=1; - if (arg.i>INTMAX_MAX) { - arg.i=-arg.i; - } else if (fl & MARK_POS) { - prefix++; - } else if (fl & PAD_POS) { - prefix+=2; - } else pl=0; - case 'u': - a = fmt_u(arg.i, z); - } - if (!arg.i && !p) continue; - if (p>=0) fl &= ~ZERO_PAD; - p = MAX(p, z-a + !arg.i); - break; - case 'c': - *(a=z-(p=1))=arg.i; - fl &= ~ZERO_PAD; - break; - case 'm': - if (1) a = strerror(errno); else - case 's': - a = arg.p; - z = memchr(a, 0, p); - if (!z) z=a+p; - else p=z-a; - fl &= ~ZERO_PAD; - break; - case 'C': - wc[0] = arg.i; - wc[1] = 0; - arg.p = wc; - p = -1; - case 'S': - ws = arg.p; - for (i=0; *ws && (l=wctomb(mb, *ws++))>=0 && l<=0U+p-i; i+=l); - if (l<0) return -1; - p = i; - pad(f, ' ', w, p, fl); - ws = arg.p; - for (i=0; *ws && i+(l=wctomb(mb, *ws++))<=p; i+=l) - out(f, mb, l); - pad(f, ' ', w, p, fl^LEFT_ADJ); - l = w>p ? w : p; - continue; - case 'e': case 'f': case 'g': case 'a': - case 'E': case 'F': case 'G': case 'A': - l = fmt_fp(f, arg.f, w, p, fl, t); - continue; - } - - if (p < z-a) p = z-a; - if (w < pl+p) w = pl+p; - - pad(f, ' ', w, pl+p, fl); - out(f, prefix, pl); - pad(f, '0', w, pl+p, fl^ZERO_PAD); - pad(f, '0', p, z-a, 0); - out(f, a, z-a); - pad(f, ' ', w, pl+p, fl^LEFT_ADJ); - - l = w; - } - - if (f) return cnt; - if (!l10n) return 0; - - for (i=1; i<=NL_ARGMAX && nl_type[i]; i++) - pop_arg(nl_arg+i, nl_type[i], ap); - for (; i<=NL_ARGMAX && !nl_type[i]; i++); - if (i<=NL_ARGMAX) return -1; - return 1; -} - -int vfprintf(FILE *f, const char *fmt, va_list ap) -{ - va_list ap2; - int nl_type[NL_ARGMAX] = {0}; - union arg nl_arg[NL_ARGMAX]; - int ret; - - va_copy(ap2, ap); - if (printf_core(0, fmt, &ap2, nl_arg, nl_type) < 0) return -1; - - FLOCK(f); - ret = printf_core(f, fmt, &ap2, nl_arg, nl_type); - FUNLOCK(f); - va_end(ap2); - return ret; -} diff --git a/05/musl-final/src/stdio/vfscanf.c b/05/musl-final/src/stdio/vfscanf.c deleted file mode 100644 index 69f4508..0000000 --- a/05/musl-final/src/stdio/vfscanf.c +++ /dev/null @@ -1,43 +0,0 @@ -#include -#include -#include -#include - -#include "stdio_impl.h" -#include "__scanf.h" - -static void f_read(rctx_t *r) -{ - FILE *f = r->opaque; - if ((r->c = __uflow(f)) >= 0) r->l++; -} - -int vfscanf(FILE *f, const char *fmt, va_list ap) -{ - size_t l = strlen(fmt), i, result; - rctx_t r = { f_read, (void *)f, 0, isspace }; - wchar_t fmt2[l+1]; - - if (l > 0x100000) { - errno = ENOMEM; - return -1; - } - for (i=0; i<=l; i++) fmt2[i] = (unsigned char)fmt[i]; - - FLOCK(f); - - result = __scanf(&r, fmt2, ap); - - if (r.u && r.c >= 0) { - /* This code takes care of the case where the caller performs - * a nonmatching scanf to leave a character in the unscan - * buffer, followed by an unget, followed by a scanf that - * matches zero characters. In this case the final 'unread' - * character must be returned to the unget buffer rather than - * the unscan buffer. */ - f->rpos--; - } - - FUNLOCK(f); - return result; -} diff --git a/05/musl-final/src/stdio/vfwscanf.c b/05/musl-final/src/stdio/vfwscanf.c deleted file mode 100644 index 491c140..0000000 --- a/05/musl-final/src/stdio/vfwscanf.c +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include -#include -#include -#include - -#include "stdio_impl.h" -#include "__scanf.h" - -static void f_read(rctx_t *r) -{ - FILE *f = r->opaque; - if ((r->c = fgetwc(f)) >= 0) r->l++; -} - -int vfwscanf(FILE *f, const wchar_t *fmt, va_list ap) -{ - rctx_t r = { f_read, (void *)f, 1, iswspace }; - int result; - - result = __scanf(&r, fmt, ap); - - if (r.u && r.c >= 0) { - ungetwc(r.c, f); - } - - return result; -} diff --git a/05/musl-final/src/stdio/vprintf.c b/05/musl-final/src/stdio/vprintf.c deleted file mode 100644 index 67b38da..0000000 --- a/05/musl-final/src/stdio/vprintf.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int vprintf(const char *fmt, va_list ap) -{ - return vfprintf(stdout, fmt, ap); -} diff --git a/05/musl-final/src/stdio/vscanf.c b/05/musl-final/src/stdio/vscanf.c deleted file mode 100644 index 6f55b1c..0000000 --- a/05/musl-final/src/stdio/vscanf.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include - -int vscanf(const char *fmt, va_list ap) -{ - return vfscanf(stdin, fmt, ap); -} diff --git a/05/musl-final/src/stdio/vsnprintf.c b/05/musl-final/src/stdio/vsnprintf.c deleted file mode 100644 index bda6b49..0000000 --- a/05/musl-final/src/stdio/vsnprintf.c +++ /dev/null @@ -1,33 +0,0 @@ -#include "stdio_impl.h" - -static size_t sn_write(FILE *f, const unsigned char *s, size_t l) -{ - /* pretend to succeed, but discard data */ - return l; -} - -int vsnprintf(char *s, size_t n, const char *fmt, va_list ap) -{ - int r; - FILE f; - unsigned char buf[1]; - - memset(&f, 0, sizeof(FILE)); - f.lbf = EOF; - f.write = sn_write; - f.buf_size = 1; - f.buf = buf; - if (n > INT_MAX) { - errno = EOVERFLOW; - return -1; - } else if (n > 0) { - if (n > (char *)0+SIZE_MAX-s) n = (char *)0+SIZE_MAX-s; - f.wpos = s; - f.wbase = f.wend = s+n-1; - f.wstop = f.wend - 1; - } - r = vfprintf(&f, fmt, ap); - /* wpos points just after last byte written, or to s+n-1 (wbase) */ - *f.wpos = 0; - return r; -} diff --git a/05/musl-final/src/stdio/vsprintf.c b/05/musl-final/src/stdio/vsprintf.c deleted file mode 100644 index 7836ccb..0000000 --- a/05/musl-final/src/stdio/vsprintf.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include - -int vsprintf(char *s, const char *fmt, va_list ap) -{ - return vsnprintf(s, INT_MAX, fmt, ap); -} diff --git a/05/musl-final/src/stdio/vsscanf.c b/05/musl-final/src/stdio/vsscanf.c deleted file mode 100644 index fd48f70..0000000 --- a/05/musl-final/src/stdio/vsscanf.c +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include -#include - -#include "__scanf.h" - -static void s_read(rctx_t *r) -{ - unsigned char *s = r->opaque; - if (!s[r->l]) r->c = -1; - else r->c = s[r->l++]; -} - -int vsscanf(const char *s, const char *fmt, va_list ap) -{ - size_t l = strlen(fmt), i; - wchar_t fmt2[l+1]; - rctx_t r = { s_read, (void *)s, 0, isspace }; - for (i=0; i<=l; i++) fmt2[i] = (unsigned char)fmt[i]; - return __scanf(&r, fmt2, ap); -} diff --git a/05/musl-final/src/stdio/vswscanf.c b/05/musl-final/src/stdio/vswscanf.c deleted file mode 100644 index 2c4ffbe..0000000 --- a/05/musl-final/src/stdio/vswscanf.c +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include -#include -#include - -#include "__scanf.h" - -static void s_read(rctx_t *r) -{ - wchar_t *s = r->opaque; - if (!s[r->l]) r->c = -1; - else r->c = s[r->l++]; -} - -int vswscanf(const wchar_t *s, const wchar_t *fmt, va_list ap) -{ - rctx_t r = { s_read, (void *)s, 1, iswspace }; - return __scanf(&r, fmt, ap); -} diff --git a/05/musl-final/src/stdio/vwscanf.c b/05/musl-final/src/stdio/vwscanf.c deleted file mode 100644 index 86da045..0000000 --- a/05/musl-final/src/stdio/vwscanf.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include -#include - -int vwscanf(const wchar_t *fmt, va_list ap) -{ - return vfwscanf(stdin, fmt, ap); -} diff --git a/05/musl-final/src/stdio/wscanf.c b/05/musl-final/src/stdio/wscanf.c deleted file mode 100644 index 34b5884..0000000 --- a/05/musl-final/src/stdio/wscanf.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include -#include - -int wscanf(const wchar_t *fmt, ...) -{ - int ret; - va_list ap; - va_start(ap, fmt); - ret = vwscanf(fmt, ap); - va_end(ap); - return ret; -} diff --git a/05/musl-final/src/stdlib/abs.c b/05/musl-final/src/stdlib/abs.c deleted file mode 100644 index 4806d62..0000000 --- a/05/musl-final/src/stdlib/abs.c +++ /dev/null @@ -1,4 +0,0 @@ -int abs(int a) -{ - return a>0 ? a : -a; -} diff --git a/05/musl-final/src/stdlib/atof.c b/05/musl-final/src/stdlib/atof.c deleted file mode 100644 index f7fcd82..0000000 --- a/05/musl-final/src/stdlib/atof.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -double atof(const char *s) -{ - return strtod(s, 0); -} diff --git a/05/musl-final/src/stdlib/atoi.c b/05/musl-final/src/stdlib/atoi.c deleted file mode 100644 index 648b154..0000000 --- a/05/musl-final/src/stdlib/atoi.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include - -int atoi(const char *s) -{ - int n=0, neg=0; - while (isspace(*s)) s++; - switch (*s) { - case '-': neg=1; - case '+': s++; - } - while (isdigit(*s)) - n = 10*n + *s++ - '0'; - return neg ? -n : n; -} diff --git a/05/musl-final/src/stdlib/atol.c b/05/musl-final/src/stdlib/atol.c deleted file mode 100644 index 9c91bba..0000000 --- a/05/musl-final/src/stdlib/atol.c +++ /dev/null @@ -1,16 +0,0 @@ -#include -#include - -long atol(const char *s) -{ - long n=0; - int neg=0; - while (isspace(*s)) s++; - switch (*s) { - case '-': neg=1; - case '+': s++; - } - while (isdigit(*s)) - n = 10*n + *s++ - '0'; - return neg ? -n : n; -} diff --git a/05/musl-final/src/stdlib/atoll.c b/05/musl-final/src/stdlib/atoll.c deleted file mode 100644 index 0e03e0a..0000000 --- a/05/musl-final/src/stdlib/atoll.c +++ /dev/null @@ -1,16 +0,0 @@ -#include -#include - -long long atoll(const char *s) -{ - long long n=0; - int neg=0; - while (isspace(*s)) s++; - switch (*s) { - case '-': neg=1; - case '+': s++; - } - while (isdigit(*s)) - n = 10*n + *s++ - '0'; - return neg ? -n : n; -} diff --git a/05/musl-final/src/stdlib/bsearch.c b/05/musl-final/src/stdlib/bsearch.c deleted file mode 100644 index 61d8936..0000000 --- a/05/musl-final/src/stdlib/bsearch.c +++ /dev/null @@ -1,20 +0,0 @@ -#include - -void *bsearch(const void *key, const void *base, size_t nel, size_t width, int (*cmp)(const void *, const void *)) -{ - void *try; - int sign; - while (nel > 0) { - try = (char *)base + width*(nel/2); - sign = cmp(key, try); - if (!sign) return try; - else if (nel == 1) break; - else if (sign < 0) - nel /= 2; - else { - base = try; - nel -= nel/2; - } - } - return NULL; -} diff --git a/05/musl-final/src/stdlib/div.c b/05/musl-final/src/stdlib/div.c deleted file mode 100644 index e42c1f1..0000000 --- a/05/musl-final/src/stdlib/div.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -div_t div(int num, int den) -{ - return (div_t){ num/den, num%den }; -} diff --git a/05/musl-final/src/stdlib/frexp.c b/05/musl-final/src/stdlib/frexp.c deleted file mode 100644 index ae82cb3..0000000 --- a/05/musl-final/src/stdlib/frexp.c +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include - -double frexp(double x, int *e) -{ - union { double d; uint64_t i; } y = { x }; - int ee = y.i>>52 & 0x7ff; - - if (!ee) { - if (x) { - x = frexp(x*0x1p64, e); - *e -= 64; - } else *e = 0; - return x; - } else if (ee == 0x7ff) { - return x; - } - - *e = ee - 0x3fe; - y.i &= 0x800fffffffffffffull; - y.i |= 0x3fe0000000000000ull; - return y.d; -} diff --git a/05/musl-final/src/stdlib/frexpf.c b/05/musl-final/src/stdlib/frexpf.c deleted file mode 100644 index ee5e910..0000000 --- a/05/musl-final/src/stdlib/frexpf.c +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include - -float frexpf(float x, int *e) -{ - union { float f; uint32_t i; } y = { x }; - int ee = y.i>>23 & 0xff; - - if (!ee) { - if (x) { - x = frexpf(x*0x1p64, e); - *e -= 64; - } else *e = 0; - return x; - } else if (ee == 0xff) { - return x; - } - - *e = ee - 0x7e; - y.i &= 0x807ffffful; - y.i |= 0x3f000000ul; - return y.f; -} diff --git a/05/musl-final/src/stdlib/frexpl.c b/05/musl-final/src/stdlib/frexpl.c deleted file mode 100644 index ecfff00..0000000 --- a/05/musl-final/src/stdlib/frexpl.c +++ /dev/null @@ -1,25 +0,0 @@ -#include -#include - -/* This version is for 80-bit little endian long double */ - -long double frexpl(long double x, int *e) -{ - union { long double ld; uint16_t hw[5]; } y = { x }; - int ee = y.hw[4]&0x7fff; - - if (!ee) { - if (x) { - x = frexpl(x*0x1p64, e); - *e -= 64; - } else *e = 0; - return x; - } else if (ee == 0x7fff) { - return x; - } - - *e = ee - 0x3ffe; - y.hw[4] &= 0x8000; - y.hw[4] |= 0x3ffe; - return y.ld; -} diff --git a/05/musl-final/src/stdlib/imaxabs.c b/05/musl-final/src/stdlib/imaxabs.c deleted file mode 100644 index 8100181..0000000 --- a/05/musl-final/src/stdlib/imaxabs.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -intmax_t imaxabs(intmax_t a) -{ - return a>0 ? a : -a; -} diff --git a/05/musl-final/src/stdlib/imaxdiv.c b/05/musl-final/src/stdlib/imaxdiv.c deleted file mode 100644 index b2ce821..0000000 --- a/05/musl-final/src/stdlib/imaxdiv.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -imaxdiv_t imaxdiv(intmax_t num, intmax_t den) -{ - return (imaxdiv_t){ num/den, num%den }; -} diff --git a/05/musl-final/src/stdlib/labs.c b/05/musl-final/src/stdlib/labs.c deleted file mode 100644 index 675b95b..0000000 --- a/05/musl-final/src/stdlib/labs.c +++ /dev/null @@ -1,4 +0,0 @@ -long labs(long a) -{ - return a>0 ? a : -a; -} diff --git a/05/musl-final/src/stdlib/ldiv.c b/05/musl-final/src/stdlib/ldiv.c deleted file mode 100644 index 36eb960..0000000 --- a/05/musl-final/src/stdlib/ldiv.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -ldiv_t ldiv(long num, long den) -{ - return (ldiv_t){ num/den, num%den }; -} diff --git a/05/musl-final/src/stdlib/llabs.c b/05/musl-final/src/stdlib/llabs.c deleted file mode 100644 index bec4a03..0000000 --- a/05/musl-final/src/stdlib/llabs.c +++ /dev/null @@ -1,4 +0,0 @@ -long long llabs(long long a) -{ - return a>0 ? a : -a; -} diff --git a/05/musl-final/src/stdlib/lldiv.c b/05/musl-final/src/stdlib/lldiv.c deleted file mode 100644 index 7aaf7a0..0000000 --- a/05/musl-final/src/stdlib/lldiv.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -lldiv_t lldiv(long long num, long long den) -{ - return (lldiv_t){ num/den, num%den }; -} diff --git a/05/musl-final/src/stdlib/qsort.c b/05/musl-final/src/stdlib/qsort.c deleted file mode 100644 index 91a3361..0000000 --- a/05/musl-final/src/stdlib/qsort.c +++ /dev/null @@ -1,50 +0,0 @@ -#include -#include - -/* A simple heap sort implementation.. only in-place O(nlogn) sort I know. */ - -#define MIN(a, b) ((a)<(b) ? (a) : (b)) - -static void swap(char *a, char *b, size_t len) -{ - char tmp[256]; - size_t l; - while (len) { - l = MIN(sizeof tmp, len); - memcpy(tmp, a, l); - memcpy(a, b, l); - memcpy(b, tmp, l); - a += l; - b += l; - len -= l; - } -} - -static void sift(char *base, size_t root, size_t nel, size_t width, int (*cmp)(const void *, const void *)) -{ - size_t max; - - while (2*root <= nel) { - max = 2*root; - if (max < nel && cmp(base+max*width, base+(max+1)*width) < 0) - max++; - if (max && cmp(base+root*width, base+max*width) < 0) { - swap(base+root*width, base+max*width, width); - root = max; - } else break; - } -} - -void qsort(void *_base, size_t nel, size_t width, int (*cmp)(const void *, const void *)) -{ - char *base = _base; - size_t i; - - if (!nel) return; - for (i=(nel+1)/2; i; i--) - sift(base, i-1, nel-1, width, cmp); - for (i=nel-1; i; i--) { - swap(base, base+i*width, width); - sift(base, 0, i-1, width, cmp); - } -} diff --git a/05/musl-final/src/stdlib/strtod.c b/05/musl-final/src/stdlib/strtod.c deleted file mode 100644 index 388058f..0000000 --- a/05/musl-final/src/stdlib/strtod.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -double strtod(const char *s, char **p) -{ - return strtold(s, p); -} diff --git a/05/musl-final/src/stdlib/strtof.c b/05/musl-final/src/stdlib/strtof.c deleted file mode 100644 index 07b32df..0000000 --- a/05/musl-final/src/stdlib/strtof.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -float strtof(const char *s, char **p) -{ - return strtold(s, p); -} diff --git a/05/musl-final/src/stdlib/strtoimax.c b/05/musl-final/src/stdlib/strtoimax.c deleted file mode 100644 index aeb0397..0000000 --- a/05/musl-final/src/stdlib/strtoimax.c +++ /dev/null @@ -1,25 +0,0 @@ -#include -#include -#include - -intmax_t strtoimax(const char *s1, char **p, int base) -{ - const unsigned char *s = (const void *)s1; - int sign = 0; - uintmax_t x; - - /* Initial whitespace */ - for (; isspace(*s); s++); - - /* Optional sign */ - if (*s == '-') sign = *s++; - else if (*s == '+') s++; - - x = strtoumax((const void *)s, p, base); - if (x > INTMAX_MAX) { - if (!sign || -x != INTMAX_MIN) - errno = ERANGE; - return sign ? INTMAX_MIN : INTMAX_MAX; - } - return sign ? -x : x; -} diff --git a/05/musl-final/src/stdlib/strtol.c b/05/musl-final/src/stdlib/strtol.c deleted file mode 100644 index ace820a..0000000 --- a/05/musl-final/src/stdlib/strtol.c +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include -#include -#include - -long strtol(const char *s, char **p, int base) -{ - intmax_t x = strtoimax(s, p, base); - if (x > LONG_MAX) { - errno = ERANGE; - return LONG_MAX; - } else if (x < LONG_MIN) { - errno = ERANGE; - return LONG_MIN; - } - return x; -} diff --git a/05/musl-final/src/stdlib/strtold.c b/05/musl-final/src/stdlib/strtold.c deleted file mode 100644 index a504147..0000000 --- a/05/musl-final/src/stdlib/strtold.c +++ /dev/null @@ -1,99 +0,0 @@ -#include -#include -#include - -static long double negate_ld(long double d) { - register unsigned long long *p = (unsigned long long *)&d; - p[1] ^= 1ul<<15; - return *(long double *)p; -} - -long double strtold(const char *s1, char **p) -{ - const unsigned char *s = s1; - long double x = 0; - long double frac; - int sign = 0; - int nonzero = 0; - int radix = '.'; - long e; - - if (!p) p = (char **)&s1; - - /* Initial whitespace */ - for (; isspace(*s); s++); - - /* Optional sign */ - if (*s == '-') sign = *s++; - else if (*s == '+') s++; - - /* Handle infinities and NaNs. */ - if ((s[0]|32)=='i' && (s[1]|32)=='n' && (s[2]|32)=='f') { - *p = (char *)s + 3; - return sign ? -1.0/0.0 : 1.0/0.0; - } else if ((s[0]|32)=='n' && (s[1]|32)=='a' && (s[2]|32)=='n') { - *p = (char *)s + 3; - return 0.0/0.0; - } - - /* Possible hex float */ - if (s[0]=='0' && (s[1]|32)=='x') { - /* Mantissa must be non-degenerate */ - if (!isxdigit(s[2]) && (s[2]!=radix || !isxdigit(s[3]))) { - /* Decimal float 0, 'x' extraneous */ - *p = (char *)++s; - return 0; - } - /* We have a real hex float */ - s += 2; - for (; isxdigit(*s); s++) { - x = 16*x + (isdigit(*s)?*s-'0':(*s|32)-'a'); - if (*s!='0') nonzero=1; - } - if (*s == radix) { - frac = 1.0/16.0; - for (s++; isxdigit(*s); s++) { - x += frac * (isdigit(*s)?*s-'0':(*s|32)-'a'); - frac *= 1.0/16.0; - if (*s!='0') nonzero=1; - } - } - if ((*s|32) == 'p') { - e = strtol(s+1, (void *)&s, 10); - for (; e>0; e--) x *= 2.0; - for (; e<0; e++) x *= 0.5; - } - if ((nonzero && !x) || !(1.0/x)) - errno = ERANGE; - *p = (char *)s; - return sign ? negate_ld(x) : x; - } - - /* Mantissa must be non-degenerate */ - if (!isdigit(s[0]) && (s[0]!=radix || !isdigit(s[1]))) { - *p = (char *)s1; - return 0; - } - - for (; isdigit(*s); s++) { - x = 10*x + *s-'0'; - if (*s!='0') nonzero=1; - } - if (*s == radix) { - frac = 10.0; - for (s++; isdigit(*s); s++) { - x += (*s-'0') / frac; - frac *= 10.0; - if (*s!='0') nonzero=1; - } - } - if ((*s|32)=='e') { - e = strtol(++s, (void *)&s, 10); - for (; e>0; e--) x *= 10.0; - for (; e<0; e++) x /= 10.0; - } - if ((nonzero && !x) || !(1.0/x)) - errno = ERANGE; - *p = (char*)s; - return sign ? negate_ld(x) : x; -} diff --git a/05/musl-final/src/stdlib/strtoll.c b/05/musl-final/src/stdlib/strtoll.c deleted file mode 100644 index 9ab66fd..0000000 --- a/05/musl-final/src/stdlib/strtoll.c +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include -#include -#include - -long long strtoll(const char *s, char **p, int base) -{ - intmax_t x = strtoimax(s, p, base); - if (x > LLONG_MAX) { - errno = ERANGE; - return LLONG_MAX; - } else if (x < LLONG_MIN) { - errno = ERANGE; - return LLONG_MIN; - } - return x; -} diff --git a/05/musl-final/src/stdlib/strtoul.c b/05/musl-final/src/stdlib/strtoul.c deleted file mode 100644 index 951d5e8..0000000 --- a/05/musl-final/src/stdlib/strtoul.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include -#include -#include - -unsigned long strtoul(const char *s, char **p, int base) -{ - uintmax_t x = strtoumax(s, p, base); - if (x > ULONG_MAX) { - errno = ERANGE; - return ULONG_MAX; - } - return x; -} diff --git a/05/musl-final/src/stdlib/strtoull.c b/05/musl-final/src/stdlib/strtoull.c deleted file mode 100644 index 20aa7bd..0000000 --- a/05/musl-final/src/stdlib/strtoull.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include -#include -#include - -unsigned long long strtoull(const char *s, char **p, int base) -{ - uintmax_t x = strtoumax(s, p, base); - if (x > ULLONG_MAX) { - errno = ERANGE; - return ULLONG_MAX; - } - return x; -} diff --git a/05/musl-final/src/stdlib/strtoumax.c b/05/musl-final/src/stdlib/strtoumax.c deleted file mode 100644 index a529f6e..0000000 --- a/05/musl-final/src/stdlib/strtoumax.c +++ /dev/null @@ -1,123 +0,0 @@ -#include -#include -#include -#include -#include - -/* Lookup table for digit values. -1==255>=36 -> invalid */ -static const unsigned char digits[] = { --1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, --1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, --1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1,-1,-1,-1,-1, --1,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24, -25,26,27,28,29,30,31,32,33,34,35,-1,-1,-1,-1,-1, --1,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24, -25,26,27,28,29,30,31,32,33,34,35,-1,-1,-1,-1,-1, --1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, --1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, --1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, --1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, --1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, --1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, --1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, --1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -}; - -uintmax_t strtoumax(const char *s1, char **p, int base) -{ - const unsigned char *s = s1; - size_t x1, z1; - uintmax_t x, z=0; - int sign = 0; - int shift; - - if (!p) p = (char **)&s1; - - /* Initial whitespace */ - for (; isspace(*s); s++); - - /* Optional sign */ - if (*s == '-') sign = *s++; - else if (*s == '+') s++; - - /* Default base 8, 10, or 16 depending on prefix */ - if (base == 0) { - if (s[0] == '0') { - if ((s[1]|32) == 'x') base = 16; - else base = 8; - } else { - base = 10; - } - } - - if ((unsigned)base-2 > 36-2 || digits[*s]>=base) { - *p = (char *)s1; - errno = EINVAL; - return 0; - } - - /* Main loops. Only use big types if we have to. */ - if (base == 10) { - for (x1=0; isdigit(*s) && x1<=SIZE_MAX/10-10; s++) - x1 = 10*x1 + *s-'0'; - for (x=x1; isdigit(*s) && x<=UINTMAX_MAX/10-10; s++) - x = 10*x + *s-'0'; - if (isdigit(*s)) { - if (isdigit(s[1]) || 10*x>UINTMAX_MAX-(*s-'0')) - goto overflow; - x = 10*x + *s-'0'; - } - } else if (!(base & base/2)) { - if (base == 16) { - if (s[0]=='0' && (s[1]|32)=='x' && digits[s[2]]<16) - s+=2; - shift=4; - z1 = SIZE_MAX/16; - z = UINTMAX_MAX/16; - } else if (base == 8) { - shift=3; - z1 = SIZE_MAX/8; - z = UINTMAX_MAX/8; - } else if (base == 2) { - shift=1; - z1 = SIZE_MAX/2; - z = UINTMAX_MAX/2; - } else if (base == 4) { - shift=2; - z1 = SIZE_MAX/4; - z = UINTMAX_MAX/4; - } else /* if (base == 32) */ { - shift=5; - z1 = SIZE_MAX/32; - z = UINTMAX_MAX/32; - } - for (x1=0; digits[*s]UINTMAX_MAX-digits[*s]) - goto overflow; - x = x*base + digits[*s]; - } - } - - *p = (char *)s; - return sign ? -x : x; - -overflow: - for (; digits[*s] < base; s++); - *p = (char *)s; - errno = ERANGE; - return UINTMAX_MAX; -} diff --git a/05/musl-final/src/stdlib/wcstoimax.c b/05/musl-final/src/stdlib/wcstoimax.c deleted file mode 100644 index 59894f6..0000000 --- a/05/musl-final/src/stdlib/wcstoimax.c +++ /dev/null @@ -1,25 +0,0 @@ -#include -#include -#include -#include - -intmax_t wcstoimax(const wchar_t *s, wchar_t **p, int base) -{ - int sign = 0; - uintmax_t x; - - /* Initial whitespace */ - for (; iswspace(*s); s++); - - /* Optional sign */ - if (*s == '-') sign = *s++; - else if (*s == '+') s++; - - x = wcstoumax(s, p, base); - if (x > INTMAX_MAX) { - if (!sign || -x != INTMAX_MIN) - errno = ERANGE; - return sign ? INTMAX_MIN : INTMAX_MAX; - } - return sign ? -x : x; -} diff --git a/05/musl-final/src/stdlib/wcstol.c b/05/musl-final/src/stdlib/wcstol.c deleted file mode 100644 index aad62e5..0000000 --- a/05/musl-final/src/stdlib/wcstol.c +++ /dev/null @@ -1,18 +0,0 @@ -#include -#include -#include -#include -#include - -long wcstol(const wchar_t *s, wchar_t **p, int base) -{ - intmax_t x = wcstoimax(s, p, base); - if (x > LONG_MAX) { - errno = ERANGE; - return LONG_MAX; - } else if (x < LONG_MIN) { - errno = ERANGE; - return LONG_MIN; - } - return x; -} diff --git a/05/musl-final/src/stdlib/wcstoll.c b/05/musl-final/src/stdlib/wcstoll.c deleted file mode 100644 index ddfea74..0000000 --- a/05/musl-final/src/stdlib/wcstoll.c +++ /dev/null @@ -1,18 +0,0 @@ -#include -#include -#include -#include -#include - -long long wcstoll(const wchar_t *s, wchar_t **p, int base) -{ - intmax_t x = wcstoimax(s, p, base); - if (x > LLONG_MAX) { - errno = ERANGE; - return LLONG_MAX; - } else if (x < LLONG_MIN) { - errno = ERANGE; - return LLONG_MIN; - } - return x; -} diff --git a/05/musl-final/src/stdlib/wcstoul.c b/05/musl-final/src/stdlib/wcstoul.c deleted file mode 100644 index e39faaf..0000000 --- a/05/musl-final/src/stdlib/wcstoul.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include -#include -#include -#include - -unsigned long wcstoul(const wchar_t *s, wchar_t **p, int base) -{ - uintmax_t x = wcstoumax(s, p, base); - if (x > ULONG_MAX) { - errno = ERANGE; - return ULONG_MAX; - } - return x; -} diff --git a/05/musl-final/src/stdlib/wcstoull.c b/05/musl-final/src/stdlib/wcstoull.c deleted file mode 100644 index e324dfb..0000000 --- a/05/musl-final/src/stdlib/wcstoull.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include -#include -#include -#include - -unsigned long long wcstoull(const wchar_t *s, wchar_t **p, int base) -{ - uintmax_t x = wcstoumax(s, p, base); - if (x > ULLONG_MAX) { - errno = ERANGE; - return ULLONG_MAX; - } - return x; -} diff --git a/05/musl-final/src/stdlib/wcstoumax.c b/05/musl-final/src/stdlib/wcstoumax.c deleted file mode 100644 index 456dded..0000000 --- a/05/musl-final/src/stdlib/wcstoumax.c +++ /dev/null @@ -1,48 +0,0 @@ -#include -#include -#include -#include -#include - -uintmax_t wcstoumax(const wchar_t *s, wchar_t **p, int base) -{ - /* Large enough for largest value in binary */ - char buf[sizeof(uintmax_t)*8+2]; - int sign = 0, skipped=0; - - if (!p) p = (wchar_t **)&s; - - if (base && (unsigned)base-2 > 36-2) { - *p = (wchar_t *)s; - errno = EINVAL; - return 0; - } - - /* Initial whitespace */ - for (; iswspace(*s); s++); - - /* Optional sign */ - if (*s == '-') sign = *s++; - else if (*s == '+') s++; - - /* Skip leading zeros but don't allow leading zeros before "0x". */ - for (; s[0]=='0' && s[1]=='0'; s++) skipped=1; - if (skipped && (base==0 || base==16) && (s[1]|32)=='x') { - *p = (wchar_t *)(s+1); - return 0; - } - - /* Convert to normal char string so we can use strtoumax */ - buf[0] = sign; - if (wcstombs(buf+!!sign, s, sizeof buf-1) < 0) return 0; - buf[sizeof buf-1]=0; - - /* Compute final position */ - if (p) { - if ((base==0 || base==16) && s[0]=='0' && (s[1]|32)=='x' && iswxdigit(s[2])) s+=2; - for(;*s&&((unsigned)*s-'0' -#include - -int bcmp(const void *s1, const void *s2, size_t n) -{ - return memcmp(s1, s2, n); -} diff --git a/05/musl-final/src/string/bcopy.c b/05/musl-final/src/string/bcopy.c deleted file mode 100644 index e76272f..0000000 --- a/05/musl-final/src/string/bcopy.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include - -void bcopy(const void *s1, void *s2, size_t n) -{ - memmove(s2, s1, n); -} diff --git a/05/musl-final/src/string/bzero.c b/05/musl-final/src/string/bzero.c deleted file mode 100644 index 0f98b4a..0000000 --- a/05/musl-final/src/string/bzero.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include - -void bzero(void *s, size_t n) -{ - memset(s, 0, n); -} diff --git a/05/musl-final/src/string/index.c b/05/musl-final/src/string/index.c deleted file mode 100644 index dd61125..0000000 --- a/05/musl-final/src/string/index.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include - -char *index(const char *s, int c) -{ - return strchr(s, c); -} diff --git a/05/musl-final/src/string/memchr.c b/05/musl-final/src/string/memchr.c deleted file mode 100644 index a0472f7..0000000 --- a/05/musl-final/src/string/memchr.c +++ /dev/null @@ -1,24 +0,0 @@ -#include -#include -#include -#include - -#define SS (sizeof(size_t)) -#define ALIGN (sizeof(size_t)-1) -#define ONES ((size_t)-1/UCHAR_MAX) -#define HIGHS (ONES * (UCHAR_MAX/2+1)) -#define HASZERO(x) ((x)-ONES & ~(x) & HIGHS) - -void *memchr(const void *src, int c, size_t n) -{ - const unsigned char *s = src; - c = (unsigned char)c; - for (; ((uintptr_t)s & ALIGN) && n && *s != c; s++, n--); - if (n && *s != c) { - const size_t *w; - size_t k = ONES * c; - for (w = (const void *)s; n>=SS && !HASZERO(*w^k); w++, n-=SS); - for (s = (const void *)w; n && *s != c; s++, n--); - } - return n ? (void *)s : 0; -} diff --git a/05/musl-final/src/string/memcmp.c b/05/musl-final/src/string/memcmp.c deleted file mode 100644 index bdbce9f..0000000 --- a/05/musl-final/src/string/memcmp.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -int memcmp(const void *vl, const void *vr, size_t n) -{ - const unsigned char *l=vl, *r=vr; - for (; n && *l == *r; n--, l++, r++); - return n ? *l-*r : 0; -} diff --git a/05/musl-final/src/string/memcpy.c b/05/musl-final/src/string/memcpy.c deleted file mode 100644 index 02cb469..0000000 --- a/05/musl-final/src/string/memcpy.c +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include -#include - -#define SS (sizeof(size_t)) -#define ALIGN (sizeof(size_t)-1) -#define ONES ((size_t)-1/UCHAR_MAX) - -void *memcpy(void *dest, const void *src, size_t n) -{ - unsigned char *d = dest; - const unsigned char *s = src; - - if (((uintptr_t)d & ALIGN) != ((uintptr_t)s & ALIGN)) - goto misaligned; - - for (; ((uintptr_t)d & ALIGN) && n; n--) *d++ = *s++; - if (n) { - size_t *wd = (void *)d; - const size_t *ws = (const void *)s; - - for (; n>=SS; n-=SS) *wd++ = *ws++; - d = (void *)wd; - s = (const void *)ws; -misaligned: - for (; n; n--) *d++ = *s++; - } - return dest; -} diff --git a/05/musl-final/src/string/memmove.c b/05/musl-final/src/string/memmove.c deleted file mode 100644 index 22bb4b3..0000000 --- a/05/musl-final/src/string/memmove.c +++ /dev/null @@ -1,14 +0,0 @@ -#include - -void *memmove(void *dest, const void *src, size_t n) -{ - char *d = dest; - const char *s = src; - if (d==s) return d; - if ((size_t)(d-s) < n) { - while (n--) d[n] = s[n]; - return dest; - } - /* Assumes memcpy is overlap-safe when dest < src */ - return memcpy(d, s, n); -} diff --git a/05/musl-final/src/string/mempcpy.c b/05/musl-final/src/string/mempcpy.c deleted file mode 100644 index e54251c..0000000 --- a/05/musl-final/src/string/mempcpy.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -void *mempcpy(void *dest, void *src, size_t n) -{ - memcpy(dest, src, n); - return (char *)dest + n; -} diff --git a/05/musl-final/src/string/memset.c b/05/musl-final/src/string/memset.c deleted file mode 100644 index 20e47c4..0000000 --- a/05/musl-final/src/string/memset.c +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include -#include -#include - -#define SS (sizeof(size_t)) -#define ALIGN (sizeof(size_t)-1) -#define ONES ((size_t)-1/UCHAR_MAX) - -void *memset(void *dest, int c, size_t n) -{ - unsigned char *s = dest; - c = (unsigned char)c; - for (; ((uintptr_t)s & ALIGN) && n; n--) *s++ = c; - if (n) { - size_t *w, k = ONES * c; - for (w = (void *)s; n>=SS; n-=SS, w++) *w = k; - for (s = (void *)w; n; n--, s++) *s = c; - } - return dest; -} diff --git a/05/musl-final/src/string/rindex.c b/05/musl-final/src/string/rindex.c deleted file mode 100644 index 17df2bf..0000000 --- a/05/musl-final/src/string/rindex.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include - -char *rindex(const char *s, int c) -{ - return strrchr(s, c); -} diff --git a/05/musl-final/src/string/stpcpy.c b/05/musl-final/src/string/stpcpy.c deleted file mode 100644 index 10ca493..0000000 --- a/05/musl-final/src/string/stpcpy.c +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include -#include -#include -#include "libc.h" - -#define ALIGN (sizeof(size_t)-1) -#define ONES ((size_t)-1/UCHAR_MAX) -#define HIGHS (ONES * (UCHAR_MAX/2+1)) -#define HASZERO(x) ((x)-ONES & ~(x) & HIGHS) - -char *__stpcpy(char *d, const char *s) -{ - size_t *wd; - const size_t *ws; - - if (((uintptr_t)s & ALIGN) == ((uintptr_t)d & ALIGN)) { - for (; (*d=*s) && ((uintptr_t)s & ALIGN); s++, d++); - if (!*s) return d; - wd=(void *)d; ws=(const void *)s; - for (; !HASZERO(*ws); *wd++ = *ws++); - d=(void *)wd; s=(const void *)ws; - } - for (; (*d=*s); s++, d++); - - return d; -} - -weak_alias(__stpcpy, stpcpy); diff --git a/05/musl-final/src/string/stpncpy.c b/05/musl-final/src/string/stpncpy.c deleted file mode 100644 index a877f5f..0000000 --- a/05/musl-final/src/string/stpncpy.c +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include -#include -#include -#include "libc.h" - -#define ALIGN (sizeof(size_t)-1) -#define ONES ((size_t)-1/UCHAR_MAX) -#define HIGHS (ONES * (UCHAR_MAX/2+1)) -#define HASZERO(x) ((x)-ONES & ~(x) & HIGHS) - -char *__stpncpy(char *d, const char *s, size_t n) -{ - size_t *wd; - const size_t *ws; - - if (((uintptr_t)s & ALIGN) != ((uintptr_t)d & ALIGN)) { - for (; ((uintptr_t)s & ALIGN) && n && (*d=*s); n--, s++, d++); - if (!n || !*s) goto tail; - wd=(void *)d; ws=(const void *)s; - for (; n>=sizeof(size_t) && !HASZERO(*ws); - n-=sizeof(size_t), ws++, *wd++) *wd = *ws; - d=(void *)wd; s=(const void *)ws; - } - for (; n && (*d=*s); n--, s++, d++); -tail: - memset(d, 0, n); - return d; -} - -weak_alias(__stpncpy, stpncpy); - diff --git a/05/musl-final/src/string/strcasecmp.c b/05/musl-final/src/string/strcasecmp.c deleted file mode 100644 index dd87905..0000000 --- a/05/musl-final/src/string/strcasecmp.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include - -int strcasecmp(const char *_l, const char *_r) -{ - const unsigned char *l=_l, *r=_r; - for (; *l && *r && (*l == *r || tolower(*l) == tolower(*r)); l++, r++); - return tolower(*l) - tolower(*r); -} diff --git a/05/musl-final/src/string/strcasestr.c b/05/musl-final/src/string/strcasestr.c deleted file mode 100644 index f1cb0e8..0000000 --- a/05/musl-final/src/string/strcasestr.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -char *strcasestr(const char *h, const char *n) -{ - //FIXME! - return strstr(h, n); -} diff --git a/05/musl-final/src/string/strcat.c b/05/musl-final/src/string/strcat.c deleted file mode 100644 index 29fdb61..0000000 --- a/05/musl-final/src/string/strcat.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -char *strcat(char *dest, const char *src) -{ - strcpy(dest + strlen(dest), src); - return dest; -} diff --git a/05/musl-final/src/string/strchr.c b/05/musl-final/src/string/strchr.c deleted file mode 100644 index e606f4f..0000000 --- a/05/musl-final/src/string/strchr.c +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include -#include -#include - -#define ALIGN (sizeof(size_t)-1) -#define ONES ((size_t)-1/UCHAR_MAX) -#define HIGHS (ONES * (UCHAR_MAX/2+1)) -#define HASZERO(x) ((x)-ONES & ~(x) & HIGHS) - -char *strchr(const char *s, int c) -{ - c = (char)c; - if (!c) return (char *)s + strlen(s); - for (; ((uintptr_t)s & ALIGN) && *s && *s != c; s++); - if (*s && *s != c) { - const size_t *w; - size_t k = ONES * c; - for (w = (const void *)s; !HASZERO(*w) && !HASZERO(*w^k); w++); - for (s = (const void *)w; *s && *s != c; s++); - } - return *s ? (char *)s : 0; -} diff --git a/05/musl-final/src/string/strchrnul.c b/05/musl-final/src/string/strchrnul.c deleted file mode 100644 index 5e0c1a1..0000000 --- a/05/musl-final/src/string/strchrnul.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -char *strchrnul(const char *s, int c) -{ - char *p = strchr(s, c); - return p ? p : (char *)s + strlen(s); -} diff --git a/05/musl-final/src/string/strcmp.c b/05/musl-final/src/string/strcmp.c deleted file mode 100644 index 91eb740..0000000 --- a/05/musl-final/src/string/strcmp.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int strcmp(const char *l, const char *r) -{ - for (; *l==*r && *l && *r; l++, r++); - return *(unsigned char *)l - *(unsigned char *)r; -} diff --git a/05/musl-final/src/string/strcpy.c b/05/musl-final/src/string/strcpy.c deleted file mode 100644 index 7675e9c..0000000 --- a/05/musl-final/src/string/strcpy.c +++ /dev/null @@ -1,16 +0,0 @@ -#include - -char *__stpcpy(char *, const char *); - -char *strcpy(char *dest, const char *src) -{ -#if 1 - __stpcpy(dest, src); - return dest; -#else - const unsigned char *s = src; - unsigned char *d = dest; - while ((*d++ = *s++)); - return dest; -#endif -} diff --git a/05/musl-final/src/string/strcspn.c b/05/musl-final/src/string/strcspn.c deleted file mode 100644 index 439b7be..0000000 --- a/05/musl-final/src/string/strcspn.c +++ /dev/null @@ -1,20 +0,0 @@ -#include - -#define BITOP(a,b,op) \ - ((a)[(size_t)(b)/(8*sizeof *(a))] op (size_t)1<<((size_t)(b)%(8*sizeof *(a)))) - -size_t strcspn(const char *_s, const char *_c) -{ - const unsigned char *s = _s; - const unsigned char *c = _c; - const unsigned char *a = s; - size_t byteset[32/sizeof(size_t)]; - - if (!c[0]) return strlen(s); - if (!c[1]) return (s=strchr(s, *c)) ? s-a : strlen(a); - - memset(byteset, 0, sizeof byteset); - for (; *c && BITOP(byteset, *c, |=); c++); - for (; *s && !BITOP(byteset, *s, &); s++); - return s-a; -} diff --git a/05/musl-final/src/string/strdup.c b/05/musl-final/src/string/strdup.c deleted file mode 100644 index defd559..0000000 --- a/05/musl-final/src/string/strdup.c +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include -#include "libc.h" - -char *__strdup(const char *s) -{ - size_t l = strlen(s); - char *d = malloc(l+1); - if (!d) return NULL; - return memcpy(d, s, l+1); -} - -char *strdup(const char *s) -{ - size_t l = strlen(s); - char *d = malloc(l+1); - if (!d) return NULL; - return memcpy(d, s, l+1); -} diff --git a/05/musl-final/src/string/strerror_r.c b/05/musl-final/src/string/strerror_r.c deleted file mode 100644 index 6fdd4ce..0000000 --- a/05/musl-final/src/string/strerror_r.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include - -int strerror_r(int err, char *buf, size_t buflen) -{ - char *msg = strerror(err); - if (strlen(msg) >= buflen) - return ERANGE; - strcpy(buf, msg); - return 0; -} diff --git a/05/musl-final/src/string/strlcat.c b/05/musl-final/src/string/strlcat.c deleted file mode 100644 index ef81209..0000000 --- a/05/musl-final/src/string/strlcat.c +++ /dev/null @@ -1,9 +0,0 @@ -#define _BSD_SOURCE -#include - -size_t strlcat(char *d, const char *s, size_t n) -{ - size_t l = strnlen(d, n); - if (l == n) return l + strlen(s); - return l + strlcpy(d+l, s, n-l); -} diff --git a/05/musl-final/src/string/strlcpy.c b/05/musl-final/src/string/strlcpy.c deleted file mode 100644 index bbebf1d..0000000 --- a/05/musl-final/src/string/strlcpy.c +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include -#include -#include -#include "libc.h" - -#define ALIGN (sizeof(size_t)-1) -#define ONES ((size_t)-1/UCHAR_MAX) -#define HIGHS (ONES * (UCHAR_MAX/2+1)) -#define HASZERO(x) ((x)-ONES & ~(x) & HIGHS) - -size_t strlcpy(char *d, const char *s, size_t n) -{ - char *d0 = d; - size_t *wd; - const size_t *ws; - - if (!n--) goto finish; - if (((uintptr_t)s & ALIGN) != ((uintptr_t)d & ALIGN)) { - for (; ((uintptr_t)s & ALIGN) && n && (*d=*s); n--, s++, d++); - if (n && *s) { - wd=(void *)d; ws=(const void *)s; - for (; n>=sizeof(size_t) && !HASZERO(*ws); - n-=sizeof(size_t), ws++, *wd++) *wd = *ws; - d=(void *)wd; s=(const void *)ws; - } - } - for (; n && (*d=*s); n--, s++, d++); - *d = 0; -finish: - return d-d0 + strlen(s); -} diff --git a/05/musl-final/src/string/strlen.c b/05/musl-final/src/string/strlen.c deleted file mode 100644 index 936fb5c..0000000 --- a/05/musl-final/src/string/strlen.c +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include -#include -#include - -#define ALIGN (sizeof(size_t)-1) -#define ONES ((size_t)-1/UCHAR_MAX) -#define HIGHS (ONES * (UCHAR_MAX/2+1)) -#define HASZERO(x) ((x)-ONES & ~(x) & HIGHS) - -size_t strlen(const char *s) -{ - const char *a = s; - const size_t *w; - for (; ((uintptr_t)s & ALIGN) && *s; s++); - if (*s) { - for (w = (const void *)s; !HASZERO(*w); w++); - for (s = (const void *)w; *s; s++); - } - return s-a; -} diff --git a/05/musl-final/src/string/strncasecmp.c b/05/musl-final/src/string/strncasecmp.c deleted file mode 100644 index 4f9230e..0000000 --- a/05/musl-final/src/string/strncasecmp.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include - -int strncasecmp(const char *_l, const char *_r, size_t n) -{ - const unsigned char *l=_l, *r=_r; - if (!n--) return 0; - for (; *l && *r && n && (*l == *r || tolower(*l) == tolower(*r)); l++, r++, n--); - return tolower(*l) - tolower(*r); -} diff --git a/05/musl-final/src/string/strncat.c b/05/musl-final/src/string/strncat.c deleted file mode 100644 index 255b7a7..0000000 --- a/05/musl-final/src/string/strncat.c +++ /dev/null @@ -1,10 +0,0 @@ -#include - -char *strncat(char *d, const char *s, size_t n) -{ - char *a = d; - d += strlen(d); - while (n && (*d++ = *s++)) n--; - *d++ = 0; - return a; -} diff --git a/05/musl-final/src/string/strncmp.c b/05/musl-final/src/string/strncmp.c deleted file mode 100644 index 52ba032..0000000 --- a/05/musl-final/src/string/strncmp.c +++ /dev/null @@ -1,9 +0,0 @@ -#include - -int strncmp(const char *_l, const char *_r, size_t n) -{ - const unsigned char *l=_l, *r=_r; - if (!n--) return 0; - for (; *l && *r && n && *l == *r ; l++, r++, n--); - return *l - *r; -} diff --git a/05/musl-final/src/string/strncpy.c b/05/musl-final/src/string/strncpy.c deleted file mode 100644 index c0cd797..0000000 --- a/05/musl-final/src/string/strncpy.c +++ /dev/null @@ -1,9 +0,0 @@ -#include - -char *__stpncpy(char *, const char *, size_t); - -char *strncpy(char *d, const char *s, size_t n) -{ - __stpncpy(d, s, n); - return d; -} diff --git a/05/musl-final/src/string/strndup.c b/05/musl-final/src/string/strndup.c deleted file mode 100644 index 617d27b..0000000 --- a/05/musl-final/src/string/strndup.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -char *strndup(const char *s, size_t n) -{ - size_t l = strnlen(s, n); - char *d = malloc(l+1); - if (!d) return NULL; - memcpy(d, s, l); - d[l] = 0; - return d; -} diff --git a/05/musl-final/src/string/strnlen.c b/05/musl-final/src/string/strnlen.c deleted file mode 100644 index 6442eb7..0000000 --- a/05/musl-final/src/string/strnlen.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -size_t strnlen(const char *s, size_t n) -{ - const char *p = memchr(s, 0, n); - return p ? p-s : n; -} diff --git a/05/musl-final/src/string/strpbrk.c b/05/musl-final/src/string/strpbrk.c deleted file mode 100644 index 55947c6..0000000 --- a/05/musl-final/src/string/strpbrk.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -char *strpbrk(const char *s, const char *b) -{ - s += strcspn(s, b); - return *s ? (char *)s : 0; -} diff --git a/05/musl-final/src/string/strrchr.c b/05/musl-final/src/string/strrchr.c deleted file mode 100644 index 31c8e0b..0000000 --- a/05/musl-final/src/string/strrchr.c +++ /dev/null @@ -1,9 +0,0 @@ -#include - -char *strrchr(const char *s, int c) -{ - const char *p; - c = (char)c; - for (p=s+strlen(s); p>=s && *p!=c; p--); - return p>=s ? (char *)p : 0; -} diff --git a/05/musl-final/src/string/strsep.c b/05/musl-final/src/string/strsep.c deleted file mode 100644 index 1bfe1db..0000000 --- a/05/musl-final/src/string/strsep.c +++ /dev/null @@ -1,12 +0,0 @@ -#include - -char *strsep(char **str, const char *sep) -{ - char *s = *str, *end; - if (!s) return NULL; - end = s + strcspn(s, sep); - if (*end) *end++ = 0; - else end = 0; - *str = end; - return s; -} diff --git a/05/musl-final/src/string/strsignal.c b/05/musl-final/src/string/strsignal.c deleted file mode 100644 index 72fba8d..0000000 --- a/05/musl-final/src/string/strsignal.c +++ /dev/null @@ -1,98 +0,0 @@ -#include - -#if (SIGHUP == 1) && (SIGINT == 2) && (SIGQUIT == 3) && (SIGILL == 4) \ - && (SIGTRAP == 5) && (SIGABRT == 6) && (SIGBUS == 7) && (SIGFPE == 8) \ - && (SIGKILL == 9) && (SIGUSR1 == 10) && (SIGSEGV == 11) && (SIGUSR2 == 12) \ - && (SIGPIPE == 13) && (SIGALRM == 14) && (SIGTERM == 15) && (SIGSTKFLT == 16) \ - && (SIGCHLD == 17) && (SIGCONT == 18) && (SIGSTOP == 19) && (SIGTSTP == 20) \ - && (SIGTTIN == 21) && (SIGTTOU == 22) && (SIGURG == 23) && (SIGXCPU == 24) \ - && (SIGXFSZ == 25) && (SIGVTALRM == 26) && (SIGPROF == 27) && (SIGWINCH == 28) \ - && (SIGPOLL == 29) && (SIGPWR == 30) && (SIGSYS == 31) - -#define sigmap(x) x - -#else - -static const char map[] = { - [SIGHUP] = 1, - [SIGINT] = 2, - [SIGQUIT] = 3, - [SIGILL] = 4, - [SIGTRAP] = 5, - [SIGABRT] = 6, - [SIGBUS] = 7, - [SIGFPE] = 8, - [SIGKILL] = 9, - [SIGUSR1] = 10, - [SIGSEGV] = 11, - [SIGUSR2] = 12, - [SIGPIPE] = 13, - [SIGALRM] = 14, - [SIGTERM] = 15, - [SIGSTKFLT] = 16, - [SIGCHLD] = 17, - [SIGCONT] = 18, - [SIGSTOP] = 19, - [SIGTSTP] = 20, - [SIGTTIN] = 21, - [SIGTTOU] = 22, - [SIGURG] = 23, - [SIGXCPU] = 24, - [SIGXFSZ] = 25, - [SIGVTALRM] = 26, - [SIGPROF] = 27, - [SIGWINCH] = 28, - [SIGPOLL] = 29, - [SIGPWR] = 30, - [SIGSYS] = 31 -}; - -#define sigmap(x) ((unsigned)(x) > sizeof map ? 0 : map[(unsigned)(x)]) - -#endif - -static const char strings[] = - "Unknown signal\0" - "Hangup\0" - "Interrupt\0" - "Quit\0" - "Illegal instruction\0" - "Trace/breakpoint trap\0" - "Aborted\0" - "Bus error\0" - "Floating point exception\0" - "Killed\0" - "User defined signal 1\0" - "Segmentation fault\0" - "User defined signal 2\0" - "Broken pipe\0" - "Alarm clock\0" - "Terminated\0" - "Stack fault\0" - "Child exited\0" - "Continued\0" - "Stopped (signal)\0" - "Stopped\0" - "Stopped (tty input)\0" - "Stopped (tty output)\0" - "Urgent I/O condition\0" - "CPU time limit exceeded\0" - "File size limit exceeded\0" - "Virtual timer expired\0" - "Profiling timer expired\0" - "Window changed\0" - "I/O possible\0" - "Power failure\0" - "Bad system call"; - -char *strsignal(int signum) -{ - char *s = (char *)strings; - - signum = sigmap(signum); - if ((unsigned)signum - 1 > 31) signum = 0; - - for (; signum--; s++) for (; *s; s++); - - return s; -} diff --git a/05/musl-final/src/string/strspn.c b/05/musl-final/src/string/strspn.c deleted file mode 100644 index 59b063e..0000000 --- a/05/musl-final/src/string/strspn.c +++ /dev/null @@ -1,22 +0,0 @@ -#include - -#define BITOP(a,b,op) \ - ((a)[(size_t)(b)/(8*sizeof *(a))] op (size_t)1<<((size_t)(b)%(8*sizeof *(a)))) - -size_t strspn(const char *_s, const char *_c) -{ - const unsigned char *s = _s; - const unsigned char *c = _c; - const unsigned char *a = s; - size_t byteset[32/sizeof(size_t)] = { 0 }; - - if (!c[0]) return 0; - if (!c[1]) { - for (; *s == *c; s++); - return s-a; - } - - for (; *c && BITOP(byteset, *c, |=); c++); - for (; *s && BITOP(byteset, *s, &); s++); - return s-a; -} diff --git a/05/musl-final/src/string/strstr.c b/05/musl-final/src/string/strstr.c deleted file mode 100644 index 4d536a7..0000000 --- a/05/musl-final/src/string/strstr.c +++ /dev/null @@ -1,166 +0,0 @@ -#include -#include -#include - -static char *twobyte_strstr(const unsigned char *h, const unsigned char *n) -{ - uint16_t nw = n[0]<<8 | n[1], hw = h[0]<<8 | h[1]; - for (h++; *h && hw != nw; hw = hw<<8 | *++h); - return *h ? (char *)h-1 : 0; -} - -static char *threebyte_strstr(const unsigned char *h, const unsigned char *n) -{ - uint32_t nw = n[0]<<24 | n[1]<<16 | n[2]<<8; - uint32_t hw = h[0]<<24 | h[1]<<16 | h[2]<<8; - for (h+=2; *h && hw != nw; hw = (hw|*++h)<<8); - return *h ? (char *)h-2 : 0; -} - -static char *fourbyte_strstr(const unsigned char *h, const unsigned char *n) -{ - uint32_t nw = n[0]<<24 | n[1]<<16 | n[2]<<8 | n[3]; - uint32_t hw = h[0]<<24 | h[1]<<16 | h[2]<<8 | h[3]; - for (h+=3; *h && hw != nw; hw = hw<<8 | *++h); - return *h ? (char *)h-3 : 0; -} - -#if 0 -static char *naive_strstr(const char *h, const char *n) -{ - size_t i; - for (i=0; n[i] && h[i]; i++) - for ( ; n[i] != h[i]; h++, i=0); - return n[i] ? 0 : (char *)h; -} -#endif - -#define MAX(a,b) ((a)>(b)?(a):(b)) -#define MIN(a,b) ((a)<(b)?(a):(b)) - -#define BITOP(a,b,op) \ - ((a)[(size_t)(b)/(8*sizeof *(a))] op (size_t)1<<((size_t)(b)%(8*sizeof *(a)))) - -static char *twoway_strstr(const unsigned char *h, const unsigned char *n) -{ - const unsigned char *z; - size_t l, ip, jp, k, p, ms, p0, mem, mem0; - size_t byteset[32 / sizeof(size_t)] = { 0 }; - size_t shift[256]; - - /* Computing length of needle and fill shift table */ - for (l=0; n[l] && h[l]; l++) - BITOP(byteset, n[l], |=), shift[n[l]] = l+1; - if (n[l]) return 0; /* hit the end of h */ - - /* Compute maximal suffix */ - ip = -1; jp = 0; k = p = 1; - while (jp+k n[jp+k]) { - jp += k; - k = 1; - p = jp - ip; - } else { - ip = jp++; - k = p = 1; - } - } - ms = ip; - p0 = p; - - /* And with the opposite comparison */ - ip = -1; jp = 0; k = p = 1; - while (jp+k ms+1) ms = ip; - else p = p0; - - /* Periodic needle? */ - if (memcmp(n, n+p, ms+1)) { - mem0 = 0; - p = MAX(ms, l-ms-1) + 1; - } else mem0 = l-p; - mem = 0; - - /* Initialize incremental end-of-haystack pointer */ - z = h; - - /* Search loop */ - for (;;) { - /* Update incremental end-of-haystack pointer */ - if (z-h < l) { - /* Fast estimate for MIN(l,63) */ - size_t grow = l | 63; - const char *z2 = memchr(z, 0, grow); - if (z2) { - z = z2; - if (z-h < l) return 0; - } else z += grow; - } - - /* Check last byte first; advance by shift on mismatch */ - if (BITOP(byteset, h[l-1], &)) { - k = l-shift[h[l-1]]; - //printf("adv by %zu (on %c) at [%s] (%zu;l=%zu)\n", k, h[l-1], h, shift[h[l-1]], l); - if (k) { - if (mem0 && mem && k < p) k = l-p; - h += k; - mem = 0; - continue; - } - } else { - h += l; - mem = 0; - continue; - } - - /* Compare right half */ - for (k=MAX(ms+1,mem); n[k] && n[k] == h[k]; k++); - if (n[k]) { - h += k-ms; - mem = 0; - continue; - } - /* Compare left half */ - for (k=ms+1; k>mem && n[k-1] == h[k-1]; k--); - if (k == mem) return (char *)h; - h += p; - mem = mem0; - } -} - -char *strstr(const char *h, const char *n) -{ - /* Return immediately on empty needle */ - if (!n[0]) return (char *)h; - - /* Use faster algorithms for short needles */ - h = strchr(h, *n); - if (!h || !n[1]) return (char *)h; - if (!h[1]) return 0; - if (!n[2]) return twobyte_strstr(h, n); - if (!h[2]) return 0; - if (!n[3]) return threebyte_strstr(h, n); - if (!h[3]) return 0; - if (!n[4]) return fourbyte_strstr(h, n); - - return twoway_strstr(h, n); -} diff --git a/05/musl-final/src/string/strtok.c b/05/musl-final/src/string/strtok.c deleted file mode 100644 index 1ba221c..0000000 --- a/05/musl-final/src/string/strtok.c +++ /dev/null @@ -1,13 +0,0 @@ -#include - -char *strtok(char *s, const char *sep) -{ - static char *p; - if (!s && !(s = p)) return NULL; - s += strspn(s, sep); - if (!*s) return p = 0; - p = s + strcspn(s, sep); - if (*p) *p++ = 0; - else p = 0; - return s; -} diff --git a/05/musl-final/src/string/strtok_r.c b/05/musl-final/src/string/strtok_r.c deleted file mode 100644 index c763897..0000000 --- a/05/musl-final/src/string/strtok_r.c +++ /dev/null @@ -1,12 +0,0 @@ -#include - -char *strtok_r(char *s, const char *sep, char **p) -{ - if (!s && !(s = *p)) return NULL; - s += strspn(s, sep); - if (!*s) return *p = 0; - *p = s + strcspn(s, sep); - if (**p) *(*p)++ = 0; - else *p = 0; - return s; -} diff --git a/05/musl-final/src/string/swab.c b/05/musl-final/src/string/swab.c deleted file mode 100644 index b213288..0000000 --- a/05/musl-final/src/string/swab.c +++ /dev/null @@ -1,13 +0,0 @@ -#include - -void swab(const void *_src, void *_dest, ssize_t n) -{ - const char *src = _src; - char *dest = _dest; - for (; n>0; n-=2) { - dest[0] = src[1]; - dest[1] = src[0]; - dest += 2; - src += 2; - } -} diff --git a/05/musl-final/src/string/wcscat.c b/05/musl-final/src/string/wcscat.c deleted file mode 100644 index 946f16e..0000000 --- a/05/musl-final/src/string/wcscat.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -wchar_t *wcscat(wchar_t *dest, const wchar_t *src) -{ - wcscpy(dest + wcslen(dest), src); - return dest; -} diff --git a/05/musl-final/src/string/wcschr.c b/05/musl-final/src/string/wcschr.c deleted file mode 100644 index 8dfc2f3..0000000 --- a/05/musl-final/src/string/wcschr.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -wchar_t *wcschr(const wchar_t *s, wchar_t c) -{ - if (!c) return (wchar_t *)s + wcslen(s); - for (; *s && *s != c; s++); - return *s ? (wchar_t *)s : 0; -} diff --git a/05/musl-final/src/string/wcscmp.c b/05/musl-final/src/string/wcscmp.c deleted file mode 100644 index 26eeee7..0000000 --- a/05/musl-final/src/string/wcscmp.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int wcscmp(const wchar_t *l, const wchar_t *r) -{ - for (; *l==*r && *l && *r; l++, r++); - return *l - *r; -} diff --git a/05/musl-final/src/string/wcscpy.c b/05/musl-final/src/string/wcscpy.c deleted file mode 100644 index e0ac194..0000000 --- a/05/musl-final/src/string/wcscpy.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -wchar_t *wcscpy(wchar_t *d, const wchar_t *s) -{ - wchar_t *a = d; - while ((*d++ = *s++)); - return a; -} diff --git a/05/musl-final/src/string/wcscspn.c b/05/musl-final/src/string/wcscspn.c deleted file mode 100644 index c4e5272..0000000 --- a/05/musl-final/src/string/wcscspn.c +++ /dev/null @@ -1,10 +0,0 @@ -#include - -size_t wcscspn(const wchar_t *s, const wchar_t *c) -{ - const wchar_t *a; - if (!c[0]) return wcslen(s); - if (!c[1]) return (s=wcschr(a=s, *c)) ? s-a : wcslen(a); - for (a=s; *s && !wcschr(c, *s); s++); - return s-a; -} diff --git a/05/musl-final/src/string/wcslen.c b/05/musl-final/src/string/wcslen.c deleted file mode 100644 index 1b7b665..0000000 --- a/05/musl-final/src/string/wcslen.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -size_t wcslen(const wchar_t *s) -{ - const wchar_t *a; - for (a=s; *s; s++); - return s-a; -} diff --git a/05/musl-final/src/string/wcsncat.c b/05/musl-final/src/string/wcsncat.c deleted file mode 100644 index b07abe4..0000000 --- a/05/musl-final/src/string/wcsncat.c +++ /dev/null @@ -1,10 +0,0 @@ -#include - -wchar_t *wcsncat(wchar_t *d, const wchar_t *s, size_t n) -{ - wchar_t *a = d; - d += wcslen(d); - while (n && (*d++ = *s++)) n--; - *d++ = 0; - return a; -} diff --git a/05/musl-final/src/string/wcsncmp.c b/05/musl-final/src/string/wcsncmp.c deleted file mode 100644 index 1b159f4..0000000 --- a/05/musl-final/src/string/wcsncmp.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int wcsncmp(const wchar_t *l, const wchar_t *r, size_t n) -{ - for (; n && *l==*r && *l && *r; l++, r++); - return n ? *l - *r : 0; -} diff --git a/05/musl-final/src/string/wcsncpy.c b/05/musl-final/src/string/wcsncpy.c deleted file mode 100644 index 0164208..0000000 --- a/05/musl-final/src/string/wcsncpy.c +++ /dev/null @@ -1,9 +0,0 @@ -#include - -wchar_t *wcsncpy(wchar_t *d, const wchar_t *s, size_t n) -{ - wchar_t *a = d; - while (n && (*d++ = *s++)) n--; - wmemset(d, 0, n); - return a; -} diff --git a/05/musl-final/src/string/wcspbrk.c b/05/musl-final/src/string/wcspbrk.c deleted file mode 100644 index 0c72c19..0000000 --- a/05/musl-final/src/string/wcspbrk.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -wchar_t *wcspbrk(const wchar_t *s, const wchar_t *b) -{ - s += wcscspn(s, b); - return *s ? (wchar_t *)s : NULL; -} diff --git a/05/musl-final/src/string/wcsrchr.c b/05/musl-final/src/string/wcsrchr.c deleted file mode 100644 index 7503475..0000000 --- a/05/musl-final/src/string/wcsrchr.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -wchar_t *wcsrchr(const wchar_t *s, wint_t c) -{ - const wchar_t *p; - for (p=s+wcslen(s); p>=s && *p!=c; p--); - return p>=s ? (wchar_t *)p : 0; -} diff --git a/05/musl-final/src/string/wcsspn.c b/05/musl-final/src/string/wcsspn.c deleted file mode 100644 index 4320d8f..0000000 --- a/05/musl-final/src/string/wcsspn.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -size_t wcsspn(const wchar_t *s, const wchar_t *c) -{ - const wchar_t *a; - for (a=s; *s && wcschr(c, *s); s++); - return s-a; -} diff --git a/05/musl-final/src/string/wcsstr.c b/05/musl-final/src/string/wcsstr.c deleted file mode 100644 index 966174f..0000000 --- a/05/musl-final/src/string/wcsstr.c +++ /dev/null @@ -1,117 +0,0 @@ -#include -#include -#include -#include - -static wchar_t *naive_wcsstr(const wchar_t *h, const wchar_t *n) -{ - size_t i; - for (i=0; n[i] && h[i]; i++) - for ( ; n[i] != h[i]; h++, i=0); - return n[i] ? 0 : (wchar_t *)h; -} - -#define MAX(a,b) ((a)>(b)?(a):(b)) -#define MIN(a,b) ((a)<(b)?(a):(b)) - -static wchar_t *twoway_wcsstr(const wchar_t *h, const wchar_t *n) -{ - const wchar_t *z; - size_t l, ip, jp, k, p, ms, p0, mem, mem0; - - /* Computing length of needle */ - for (l=0; n[l] && h[l]; l++); - if (n[l]) return 0; /* hit the end of h */ - - /* Compute maximal suffix */ - ip = -1; jp = 0; k = p = 1; - while (jp+k n[jp+k]) { - jp += k; - k = 1; - p = jp - ip; - } else { - ip = jp++; - k = p = 1; - } - } - ms = ip; - p0 = p; - - /* And with the opposite comparison */ - ip = -1; jp = 0; k = p = 1; - while (jp+k ms+1) ms = ip; - else p = p0; - - /* Periodic needle? */ - if (wmemcmp(n, n+p, ms+1)) { - mem0 = 0; - p = MAX(ms, l-ms-1) + 1; - } else mem0 = l-p; - mem = 0; - - /* Initialize incremental end-of-haystack pointer */ - z = h; - - /* Search loop */ - for (;;) { - /* Update incremental end-of-haystack pointer */ - if (z-h < l) { - /* Fast estimate for MIN(l,63) */ - size_t grow = l | 63; - const wchar_t *z2 = wmemchr(z, 0, grow); - if (z2) { - z = z2; - if (z-h < l) return 0; - } else z += grow; - } - - /* Compare right half */ - for (k=MAX(ms+1,mem); n[k] && n[k] == h[k]; k++); - if (n[k]) { - h += k-ms; - mem = 0; - continue; - } - /* Compare left half */ - for (k=ms+1; k>mem && n[k-1] == h[k-1]; k--); - if (k == mem) return (wchar_t *)h; - h += p; - mem = mem0; - } -} - -wchar_t *wcsstr(const wchar_t *h, const wchar_t *n) -{ - /* Return immediately on empty needle or haystack */ - if (!n[0]) return (wchar_t *)h; - if (!h[0]) return 0; - - /* Use faster algorithms for short needles */ - h = wcschr(h, *n); - if (!h || !n[1]) return (wchar_t *)h; - if (!h[1]) return 0; - if (!n[2] || !n[3] || !n[4]) return naive_wcsstr(h, n); - - return twoway_wcsstr(h, n); -} diff --git a/05/musl-final/src/string/wcswcs.c b/05/musl-final/src/string/wcswcs.c deleted file mode 100644 index 9cfe4ac..0000000 --- a/05/musl-final/src/string/wcswcs.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -wchar_t *wcswcs(const wchar_t *haystack, const wchar_t *needle) -{ - return wcsstr(haystack, needle); -} diff --git a/05/musl-final/src/string/wmemchr.c b/05/musl-final/src/string/wmemchr.c deleted file mode 100644 index a3ee0e6..0000000 --- a/05/musl-final/src/string/wmemchr.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include - -wchar_t *wmemchr(const wchar_t *s, wchar_t c, size_t n) -{ - for (; n && *s != c; s++); - return n ? (wchar_t *)s : 0; -} diff --git a/05/musl-final/src/string/wmemcmp.c b/05/musl-final/src/string/wmemcmp.c deleted file mode 100644 index 6788a38..0000000 --- a/05/musl-final/src/string/wmemcmp.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include - -int wmemcmp(const wchar_t *l, const wchar_t *r, size_t n) -{ - for (; n && *l==*r; n--, l++, r++); - return n ? *l-*r : 0; -} diff --git a/05/musl-final/src/string/wmemcpy.c b/05/musl-final/src/string/wmemcpy.c deleted file mode 100644 index 330e37c..0000000 --- a/05/musl-final/src/string/wmemcpy.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include - -wchar_t *wmemcpy(wchar_t *d, const wchar_t *s, size_t n) -{ - wchar_t *a = d; - while (n--) *d++ = *s++; - return a; -} diff --git a/05/musl-final/src/string/wmemmove.c b/05/musl-final/src/string/wmemmove.c deleted file mode 100644 index 49608ca..0000000 --- a/05/musl-final/src/string/wmemmove.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include - -wchar_t *wmemmove(wchar_t *d, const wchar_t *s, size_t n) -{ - if ((size_t)(d-s) < n) { - while (n--) d[n] = s[n]; - return d; - } - return wmemcpy(d, s, n); -} diff --git a/05/musl-final/src/string/wmemset.c b/05/musl-final/src/string/wmemset.c deleted file mode 100644 index 1a2a861..0000000 --- a/05/musl-final/src/string/wmemset.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include - -wchar_t *wmemset(wchar_t *d, wchar_t c, size_t n) -{ - wchar_t *ret = d; - while (n--) *d++ = c; - return ret; -} diff --git a/05/musl-final/src/stub/utmpx.c b/05/musl-final/src/stub/utmpx.c deleted file mode 100644 index 3200396..0000000 --- a/05/musl-final/src/stub/utmpx.c +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include - -void endutxent(void) -{ -} - -void setutxent(void) -{ -} - -struct utmpx *getutxent(void) -{ - return NULL; -} - -struct utmpx *getutxid(const struct utmpx *ut) -{ - return NULL; -} - -struct utmpx *getutxline(const struct utmpx *ut) -{ - return NULL; -} - -struct utmpx *pututxline(const struct utmpx *ut) -{ - return NULL; -} diff --git a/05/musl-final/src/syscall.s b/05/musl-final/src/syscall.s deleted file mode 100644 index 67af412..0000000 --- a/05/musl-final/src/syscall.s +++ /dev/null @@ -1,30 +0,0 @@ -# this file is necessary because tcc doesn't like musl's inline-assembly implementation -# of syscall -.global syscall0 -.global syscall1 -.global syscall2 -.global syscall3 -.global syscall4 -.global syscall5 -.global syscall6 - -syscall0: -syscall1: -syscall2: -syscall3: -syscall4: -syscall5: -syscall6: - # SysV calling convention: RDI, RSI, RDX, RCX, R8, R9, 8(%rsp) - # Linux syscall calling convention: RAX, RDI, RSI, RDX, R10, R8, R9 - mov %rdi, %rax - mov %rsi, %rdi - mov %rdx, %rsi - mov %rcx, %rdx - mov %r8, %r10 - mov %r9, %r8 - mov 8(%rsp), %r9 - syscall - mov %rax, %rdi - call __syscall_ret - ret diff --git a/05/musl-final/src/temp/mkdtemp.c b/05/musl-final/src/temp/mkdtemp.c deleted file mode 100644 index 162d98b..0000000 --- a/05/musl-final/src/temp/mkdtemp.c +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include "libc.h" - -char *__mktemp(char *); - -char *mkdtemp(char *template) -{ - for (;;) { - if (!__mktemp(template)) return 0; - if (!mkdir(template, 0700)) return template; - if (errno != EEXIST) return 0; - /* this is safe because mktemp verified - * that we have a valid template string */ - strcpy(template+strlen(template)-6, "XXXXXX"); - } -} diff --git a/05/musl-final/src/temp/mkstemp.c b/05/musl-final/src/temp/mkstemp.c deleted file mode 100644 index 5e8bb93..0000000 --- a/05/musl-final/src/temp/mkstemp.c +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include "libc.h" - -char *__mktemp(char *); - -int mkstemp(char *template) -{ - int fd; -retry: - if (!__mktemp(template)) return -1; - fd = open(template, O_RDWR | O_CREAT | O_EXCL, 0600); - if (fd >= 0) return fd; - if (errno == EEXIST) { - /* this is safe because mktemp verified - * that we have a valid template string */ - strcpy(template+strlen(template)-6, "XXXXXX"); - goto retry; - } - return -1; -} - -LFS64(mkstemp); diff --git a/05/musl-final/src/temp/mktemp.c b/05/musl-final/src/temp/mktemp.c deleted file mode 100644 index 1078b9d..0000000 --- a/05/musl-final/src/temp/mktemp.c +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include "libc.h" - -char *__mktemp(char *template) -{ - static int lock; - static int index; - int l = strlen(template); - - if (l < 6 || strcmp(template+l-6, "XXXXXX")) { - errno = EINVAL; - return NULL; - } - LOCK(&lock); - for (; index < 1000000; index++) { - snprintf(template+l-6, 6, "%06d", index); - if (access(template, F_OK) != 0) { - UNLOCK(&lock); - return template; - } - } - UNLOCK(&lock); - return NULL; -} - -weak_alias(__mktemp, mktemp); diff --git a/05/musl-final/src/termios/cfgetospeed.c b/05/musl-final/src/termios/cfgetospeed.c deleted file mode 100644 index 0ebc198..0000000 --- a/05/musl-final/src/termios/cfgetospeed.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -speed_t cfgetospeed(const struct termios *tio) -{ - return tio->c_cflag & CBAUD; -} - -speed_t cfgetispeed(const struct termios *tio) -{ - return cfgetospeed(tio); -} diff --git a/05/musl-final/src/termios/cfsetospeed.c b/05/musl-final/src/termios/cfsetospeed.c deleted file mode 100644 index 80c790f..0000000 --- a/05/musl-final/src/termios/cfsetospeed.c +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include -#include -#include "libc.h" - -int cfsetospeed(struct termios *tio, speed_t speed) -{ - if (speed & ~CBAUD) { - errno = EINVAL; - return -1; - } - tio->c_cflag &= ~CBAUD; - tio->c_cflag |= speed; - return 0; -} - -int cfsetispeed(struct termios *tio, speed_t speed) -{ - return speed ? cfsetospeed(tio, speed) : 0; -} - -weak_alias(cfsetospeed, cfsetspeed); diff --git a/05/musl-final/src/termios/tcdrain.c b/05/musl-final/src/termios/tcdrain.c deleted file mode 100644 index c51dd40..0000000 --- a/05/musl-final/src/termios/tcdrain.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include - -int tcdrain(int fd) -{ - return ioctl(fd, TCSBRK, 1); -} diff --git a/05/musl-final/src/termios/tcflow.c b/05/musl-final/src/termios/tcflow.c deleted file mode 100644 index c7fc3fe..0000000 --- a/05/musl-final/src/termios/tcflow.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include - -int tcflow(int fd, int action) -{ - return ioctl(fd, TCXONC, action); -} diff --git a/05/musl-final/src/termios/tcflush.c b/05/musl-final/src/termios/tcflush.c deleted file mode 100644 index 5022266..0000000 --- a/05/musl-final/src/termios/tcflush.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include - -int tcflush(int fd, int queue) -{ - return ioctl(fd, TCFLSH, queue); -} diff --git a/05/musl-final/src/termios/tcgetattr.c b/05/musl-final/src/termios/tcgetattr.c deleted file mode 100644 index d9ce786..0000000 --- a/05/musl-final/src/termios/tcgetattr.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include -#include - -int tcgetattr(int fd, struct termios *tio) -{ - if (ioctl(fd, TCGETS, tio)) - return -1; - return 0; -} diff --git a/05/musl-final/src/termios/tcgetsid.c b/05/musl-final/src/termios/tcgetsid.c deleted file mode 100644 index 1053fd6..0000000 --- a/05/musl-final/src/termios/tcgetsid.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include - -pid_t tcgetsid(int fd) -{ - int sid; - if (ioctl(fd, TIOCGSID, &sid) < 0) - return -1; - return sid; -} diff --git a/05/musl-final/src/termios/tcsendbreak.c b/05/musl-final/src/termios/tcsendbreak.c deleted file mode 100644 index b6df0a2..0000000 --- a/05/musl-final/src/termios/tcsendbreak.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include - -int tcsendbreak(int fd, int dur) -{ - /* nonzero duration is implementation-defined, so ignore it */ - return ioctl(fd, TCSBRK, 0); -} diff --git a/05/musl-final/src/termios/tcsetattr.c b/05/musl-final/src/termios/tcsetattr.c deleted file mode 100644 index e9a168f..0000000 --- a/05/musl-final/src/termios/tcsetattr.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include -#include -#include - -int tcsetattr(int fd, int act, const struct termios *tio) -{ - if (act < 0 || act > 2) { - errno = EINVAL; - return -1; - } - return ioctl(fd, TCSETS+act, tio); -} diff --git a/05/musl-final/src/thread/__futex.c b/05/musl-final/src/thread/__futex.c deleted file mode 100644 index 93352fa..0000000 --- a/05/musl-final/src/thread/__futex.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "futex.h" -#include "syscall.h" - -int __futex(volatile int *addr, int op, int val, void *ts) -{ - return syscall4(__NR_futex, (long)addr, op, val, (long)ts); -} - diff --git a/05/musl-final/src/thread/__lock.c b/05/musl-final/src/thread/__lock.c deleted file mode 100644 index 557c6a6..0000000 --- a/05/musl-final/src/thread/__lock.c +++ /dev/null @@ -1,12 +0,0 @@ -#define SYSCALL_RETURN_ERRNO -#include "pthread_impl.h" - -void __lock(volatile int *l) -{ - int spins=100000; - /* Do not use futexes because we insist that unlocking is a simple - * assignment to optimize non-pathological code with no contention. */ - while (a_xchg(l, 1)) - if (spins) spins--, a_spin(); - else syscall0(__NR_sched_yield); -} diff --git a/05/musl-final/src/thread/__set_thread_area.c b/05/musl-final/src/thread/__set_thread_area.c deleted file mode 100644 index e69de29..0000000 diff --git a/05/musl-final/src/thread/__timedwait.c b/05/musl-final/src/thread/__timedwait.c deleted file mode 100644 index 354def2..0000000 --- a/05/musl-final/src/thread/__timedwait.c +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include -#include "futex.h" -#define SYSCALL_RETURN_ERRNO -#include "syscall.h" -#include -int __timedwait(volatile int *addr, int val, clockid_t clk, const struct timespec *at, int priv) -{ - struct timespec to; - if (at) { - clock_gettime(clk, &to); - to.tv_sec = at->tv_sec - to.tv_sec; - if ((to.tv_nsec = at->tv_nsec - to.tv_nsec) < 0) { - to.tv_sec--; - to.tv_nsec += 1000000000; - } - if (to.tv_sec < 0) return ETIMEDOUT; - } - if (priv) priv = 128; priv=0; - return syscall4(__NR_futex, (long)addr, FUTEX_WAIT | priv, val, at ? (long)&to : 0); -} diff --git a/05/musl-final/src/thread/__unmapself.c b/05/musl-final/src/thread/__unmapself.c deleted file mode 100644 index e69de29..0000000 diff --git a/05/musl-final/src/thread/__wait.c b/05/musl-final/src/thread/__wait.c deleted file mode 100644 index 8c249cd..0000000 --- a/05/musl-final/src/thread/__wait.c +++ /dev/null @@ -1,16 +0,0 @@ -#define SYSCALL_RETURN_ERRNO -#include "pthread_impl.h" - -void __wait(volatile int *addr, volatile int *waiters, int val, int priv) -{ - int spins=50000; - if (priv) priv = 128; priv=0; - while (spins--) { - if (*addr==val) a_spin(); - else return; - } - if (waiters) a_inc(waiters); - while (*addr==val) - syscall4(__NR_futex, (long)addr, FUTEX_WAIT|priv, val, 0); - if (waiters) a_dec(waiters); -} diff --git a/05/musl-final/src/thread/__wake.c b/05/musl-final/src/thread/__wake.c deleted file mode 100644 index 048ddcc..0000000 --- a/05/musl-final/src/thread/__wake.c +++ /dev/null @@ -1,9 +0,0 @@ -#define SYSCALL_RETURN_ERRNO -#include "pthread_impl.h" - -void __wake(volatile int *addr, int cnt, int priv) -{ - if (priv) priv = 128; priv=0; - if (cnt<0) cnt = INT_MAX; - syscall3(__NR_futex, (long)addr, FUTEX_WAKE | priv, cnt); -} diff --git a/05/musl-final/src/thread/cancellation.c b/05/musl-final/src/thread/cancellation.c deleted file mode 100644 index ac1af30..0000000 --- a/05/musl-final/src/thread/cancellation.c +++ /dev/null @@ -1,14 +0,0 @@ -#include "pthread_impl.h" - -void __pthread_register_cancel(struct __ptcb *cb) -{ - struct pthread *self = pthread_self(); - cb->__next = self->cancelbuf; - self->cancelbuf = cb; -} - -void __pthread_unregister_cancel(struct __ptcb *cb) -{ - struct pthread *self = __pthread_self(); - self->cancelbuf = self->cancelbuf->__next; -} diff --git a/05/musl-final/src/thread/clone.c b/05/musl-final/src/thread/clone.c deleted file mode 100644 index e69de29..0000000 diff --git a/05/musl-final/src/thread/i386/__set_thread_area.s b/05/musl-final/src/thread/i386/__set_thread_area.s deleted file mode 100644 index 9bf698b..0000000 --- a/05/musl-final/src/thread/i386/__set_thread_area.s +++ /dev/null @@ -1,22 +0,0 @@ -.text -.global __set_thread_area -.type __set_thread_area,%function -__set_thread_area: - pushl %ebx - movl 8(%esp),%ecx - movl $-1,4(%ecx) - movl %ecx,8(%ecx) - movl $0xfffff,12(%ecx) - movl $0x51,16(%ecx) - leal 4(%ecx),%ebx - movl $243,%eax - int $128 - popl %ebx - testl %eax,%eax - jnz 1f - movl 4(%ecx),%ecx - leal 3(,%ecx,8),%ecx - movw %cx,%gs -1: - ret -.size __set_thread_area,.-__set_thread_area diff --git a/05/musl-final/src/thread/i386/__unmapself.s b/05/musl-final/src/thread/i386/__unmapself.s deleted file mode 100644 index 5c67496..0000000 --- a/05/musl-final/src/thread/i386/__unmapself.s +++ /dev/null @@ -1,22 +0,0 @@ -.text -.global __unmapself -.type __unmapself,%function -__unmapself: - call 1f - .long -1 - .long -1 -1: popl %ecx - xorl %ebx,%ebx - xorl %edx,%edx - movl $8,%esi - movl $175,%eax - int $128 - movl $91,%eax - movl 4(%esp),%ebx - movl 8(%esp),%ecx - int $128 - xorl %ebx,%ebx - movl $1,%eax - int $128 - -.size __unmapself,.-__unmapself diff --git a/05/musl-final/src/thread/i386/clone.s b/05/musl-final/src/thread/i386/clone.s deleted file mode 100644 index 53405cf..0000000 --- a/05/musl-final/src/thread/i386/clone.s +++ /dev/null @@ -1,27 +0,0 @@ -.text -.global __uniclone -.type __uniclone,%function -__uniclone: - movl 4(%esp),%ecx - subl $24,%ecx - movl 8(%esp),%eax - movl %eax,16(%ecx) - movl 12(%esp),%eax - movl %eax,24(%ecx) - pushl %ebx - pushl %esi - pushl %edi - pushl %ebp - movl %eax,8(%eax) - leal 20(%eax),%edx - leal 4(%eax),%esi - movl %edx,%edi - movl $0x7d0f00,%ebx - movl $120,%eax - int $128 - popl %ebp - popl %edi - popl %esi - popl %ebx - ret -.size __uniclone,.-__uniclone diff --git a/05/musl-final/src/thread/pthread_attr_destroy.c b/05/musl-final/src/thread/pthread_attr_destroy.c deleted file mode 100644 index b5845dd..0000000 --- a/05/musl-final/src/thread/pthread_attr_destroy.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "pthread_impl.h" - -int pthread_attr_destroy(pthread_attr_t *a) -{ - return 0; -} diff --git a/05/musl-final/src/thread/pthread_attr_getdetachstate.c b/05/musl-final/src/thread/pthread_attr_getdetachstate.c deleted file mode 100644 index de65c25..0000000 --- a/05/musl-final/src/thread/pthread_attr_getdetachstate.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "pthread_impl.h" - -int pthread_attr_getdetachstate(pthread_attr_t *a, int *state) -{ - *state = a->_a_detach; - return 0; -} diff --git a/05/musl-final/src/thread/pthread_attr_getguardsize.c b/05/musl-final/src/thread/pthread_attr_getguardsize.c deleted file mode 100644 index e6b9ee2..0000000 --- a/05/musl-final/src/thread/pthread_attr_getguardsize.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "pthread_impl.h" - -int pthread_attr_getguardsize(pthread_attr_t *a, size_t *size) -{ - *size = a->_a_guardsize + DEFAULT_GUARD_SIZE; - return 0; -} diff --git a/05/musl-final/src/thread/pthread_attr_getscope.c b/05/musl-final/src/thread/pthread_attr_getscope.c deleted file mode 100644 index 0cb224d..0000000 --- a/05/musl-final/src/thread/pthread_attr_getscope.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "pthread_impl.h" - -int pthread_attr_getscope(pthread_attr_t *a, int *scope) -{ - return 0; -} diff --git a/05/musl-final/src/thread/pthread_attr_getstacksize.c b/05/musl-final/src/thread/pthread_attr_getstacksize.c deleted file mode 100644 index 900dc9f..0000000 --- a/05/musl-final/src/thread/pthread_attr_getstacksize.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "pthread_impl.h" - -int pthread_attr_getstacksize(pthread_attr_t *a, size_t *size) -{ - *size = a->_a_stacksize + DEFAULT_STACK_SIZE; - return 0; -} diff --git a/05/musl-final/src/thread/pthread_attr_init.c b/05/musl-final/src/thread/pthread_attr_init.c deleted file mode 100644 index d91bf15..0000000 --- a/05/musl-final/src/thread/pthread_attr_init.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "pthread_impl.h" - -int pthread_attr_init(pthread_attr_t *a) -{ - memset(a, 0, sizeof *a); - return 0; -} diff --git a/05/musl-final/src/thread/pthread_attr_setdetachstate.c b/05/musl-final/src/thread/pthread_attr_setdetachstate.c deleted file mode 100644 index bfffba8..0000000 --- a/05/musl-final/src/thread/pthread_attr_setdetachstate.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "pthread_impl.h" - -int pthread_attr_setdetachstate(pthread_attr_t *a, int state) -{ - a->_a_detach = state; - return 0; -} diff --git a/05/musl-final/src/thread/pthread_attr_setguardsize.c b/05/musl-final/src/thread/pthread_attr_setguardsize.c deleted file mode 100644 index 9f21d24..0000000 --- a/05/musl-final/src/thread/pthread_attr_setguardsize.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "pthread_impl.h" - -int pthread_attr_setguardsize(pthread_attr_t *a, size_t size) -{ - if (size > SIZE_MAX/8) return EINVAL; - a->_a_guardsize = size - DEFAULT_GUARD_SIZE; - return 0; -} diff --git a/05/musl-final/src/thread/pthread_attr_setscope.c b/05/musl-final/src/thread/pthread_attr_setscope.c deleted file mode 100644 index a970a81..0000000 --- a/05/musl-final/src/thread/pthread_attr_setscope.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "pthread_impl.h" - -int pthread_attr_setscope(pthread_attr_t *a, int scope) -{ - return 0; -} diff --git a/05/musl-final/src/thread/pthread_attr_setstacksize.c b/05/musl-final/src/thread/pthread_attr_setstacksize.c deleted file mode 100644 index df16b98..0000000 --- a/05/musl-final/src/thread/pthread_attr_setstacksize.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "pthread_impl.h" - -int pthread_attr_setstacksize(pthread_attr_t *a, size_t size) -{ - if (size-PAGE_SIZE > SIZE_MAX/4) return EINVAL; - a->_a_stacksize = size - DEFAULT_STACK_SIZE; - return 0; -} diff --git a/05/musl-final/src/thread/pthread_barrier_destroy.c b/05/musl-final/src/thread/pthread_barrier_destroy.c deleted file mode 100644 index 2898c41..0000000 --- a/05/musl-final/src/thread/pthread_barrier_destroy.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "pthread_impl.h" - -int pthread_barrier_destroy(pthread_barrier_t *b) -{ - return 0; -} diff --git a/05/musl-final/src/thread/pthread_barrier_init.c b/05/musl-final/src/thread/pthread_barrier_init.c deleted file mode 100644 index 736d101..0000000 --- a/05/musl-final/src/thread/pthread_barrier_init.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "pthread_impl.h" - -int pthread_barrier_init(pthread_barrier_t *b, const pthread_barrierattr_t *a, unsigned count) -{ - if (!count) return EINVAL; - *b = (pthread_barrier_t){ ._b_limit = count-1 }; - return 0; -} diff --git a/05/musl-final/src/thread/pthread_barrier_wait.c b/05/musl-final/src/thread/pthread_barrier_wait.c deleted file mode 100644 index 7bfadb9..0000000 --- a/05/musl-final/src/thread/pthread_barrier_wait.c +++ /dev/null @@ -1,31 +0,0 @@ -#include "pthread_impl.h" - -int pthread_barrier_wait(pthread_barrier_t *b) -{ - int cur; - - /* Trivial case: count was set at 1 */ - if (!b->_b_limit) return PTHREAD_BARRIER_SERIAL_THREAD; - - /* Wait for anyone still suspended at previous use of barrier */ - while ((cur=b->_b_left)) - __wait(&b->_b_left, &b->_b_waiters, cur, 0); - - /* If we are the last to reach barrier, reset it and wake others */ - if (a_fetch_add(&b->_b_count, 1) == b->_b_limit) { - b->_b_left = b->_b_limit; - b->_b_count = 0; - __wake(&b->_b_count, -1, 0); - return PTHREAD_BARRIER_SERIAL_THREAD; - } - - /* Wait for our peers to reach the barrier */ - while ((cur=b->_b_count)) - __wait(&b->_b_count, 0, cur, 0); - - /* If we're the last to wake up and barrier is awaiting reuse */ - if (a_fetch_add(&b->_b_left, -1) == 1 && b->_b_waiters) - __wake(&b->_b_left, -1, 0); - - return 0; -} diff --git a/05/musl-final/src/thread/pthread_cancel.c b/05/musl-final/src/thread/pthread_cancel.c deleted file mode 100644 index 9397ffe..0000000 --- a/05/musl-final/src/thread/pthread_cancel.c +++ /dev/null @@ -1,7 +0,0 @@ -#define SYSCALL_RETURN_ERRNO -#include "pthread_impl.h" - -int pthread_cancel(pthread_t t) -{ - return syscall3(__NR_tgkill, t->pid, t->tid, SIGCANCEL); -} diff --git a/05/musl-final/src/thread/pthread_cond_broadcast.c b/05/musl-final/src/thread/pthread_cond_broadcast.c deleted file mode 100644 index 1d378c0..0000000 --- a/05/musl-final/src/thread/pthread_cond_broadcast.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "pthread_impl.h" - -int pthread_cond_broadcast(pthread_cond_t *c) -{ - c->_c_block = 0; - __wake(&c->_c_block, -1, 0); - return 0; -} diff --git a/05/musl-final/src/thread/pthread_cond_destroy.c b/05/musl-final/src/thread/pthread_cond_destroy.c deleted file mode 100644 index 1d21a5a..0000000 --- a/05/musl-final/src/thread/pthread_cond_destroy.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "pthread_impl.h" - -int pthread_cond_destroy(pthread_cond_t *c) -{ - return 0; -} diff --git a/05/musl-final/src/thread/pthread_cond_init.c b/05/musl-final/src/thread/pthread_cond_init.c deleted file mode 100644 index 3394860..0000000 --- a/05/musl-final/src/thread/pthread_cond_init.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "pthread_impl.h" - -int pthread_cond_init(pthread_cond_t *c, const pthread_condattr_t *a) -{ - memset(c, 0, sizeof *c); - return 0; -} diff --git a/05/musl-final/src/thread/pthread_cond_signal.c b/05/musl-final/src/thread/pthread_cond_signal.c deleted file mode 100644 index 574f5c7..0000000 --- a/05/musl-final/src/thread/pthread_cond_signal.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "pthread_impl.h" - -int pthread_cond_signal(pthread_cond_t *c) -{ - c->_c_block = 0; - __wake(&c->_c_block, 1, 0); - return 0; -} diff --git a/05/musl-final/src/thread/pthread_cond_timedwait.c b/05/musl-final/src/thread/pthread_cond_timedwait.c deleted file mode 100644 index b0214b4..0000000 --- a/05/musl-final/src/thread/pthread_cond_timedwait.c +++ /dev/null @@ -1,26 +0,0 @@ -#include "pthread_impl.h" - -static void relock(void *m) -{ - pthread_mutex_lock(m); -} - -int pthread_cond_timedwait(pthread_cond_t *c, pthread_mutex_t *m, const struct timespec *ts) -{ - int r, e=0; - CANCELPT(0); - - pthread_cleanup_push(relock, m); - c->_c_block = 1; - if ((r=pthread_mutex_unlock(m))) return r; - - CANCELPT(1); - e = __timedwait(&c->_c_block, 1, CLOCK_REALTIME, ts, 0); - CANCELPT(0); - - pthread_cleanup_pop(0); - if ((r=pthread_mutex_lock(m))) return r; - - CANCELPT(0); - return e; -} diff --git a/05/musl-final/src/thread/pthread_cond_wait.c b/05/musl-final/src/thread/pthread_cond_wait.c deleted file mode 100644 index eb70e5f..0000000 --- a/05/musl-final/src/thread/pthread_cond_wait.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "pthread_impl.h" - -int pthread_cond_wait(pthread_cond_t *c, pthread_mutex_t *m) -{ - return pthread_cond_timedwait(c, m, 0); -} diff --git a/05/musl-final/src/thread/pthread_create.c b/05/musl-final/src/thread/pthread_create.c deleted file mode 100644 index 06d554b..0000000 --- a/05/musl-final/src/thread/pthread_create.c +++ /dev/null @@ -1,228 +0,0 @@ -#include "pthread_impl.h" - -void __pthread_unwind_next(struct __ptcb *cb) -{ - int i, j, not_finished; - pthread_t self; - - if (cb->__next) longjmp((void *)cb->__next->__jb, 1); - - self = pthread_self(); - if (self->cancel) self->result = PTHREAD_CANCELLED; - - if (!a_fetch_add(&libc.threads_minus_1, -1)) - exit(0); - - LOCK(&self->exitlock); - - not_finished = self->tsd_used; - for (j=0; not_finished && jtsd[i] && libc.tsd_keys[i]) { - void *tmp = self->tsd[i]; - self->tsd[i] = 0; - libc.tsd_keys[i](tmp); - not_finished = 1; - } - } - } - - if (self->detached && self->map_base) - __unmapself(self->map_base, self->map_size); - - __syscall_exit(0); -} - -static void docancel(struct pthread *self) -{ - struct __ptcb cb = { .__next = self->cancelbuf }; - __pthread_unwind_next(&cb); -} - -static void cancel_handler(int sig, siginfo_t *si, void *ctx) -{ - struct pthread *self = __pthread_self(); - self->cancel = 1; - if (self->canceldisable || (!self->cancelasync && !self->cancelpoint)) - return; - docancel(self); -} - -static void cancelpt(int x) -{ - struct pthread *self = __pthread_self(); - if (self->canceldisable) return; - self->cancelpoint = x; - if (self->cancel) docancel(self); -} - -/* "rsyscall" is a mechanism by which a thread can synchronously force all - * other threads to perform an arbitrary syscall. It is necessary to work - * around the non-conformant implementation of setuid() et al on Linux, - * which affect only the calling thread and not the whole process. This - * implementation performs some tricks with signal delivery to work around - * the fact that it does not keep any list of threads in userspace. */ - -static struct { - volatile int lock, hold, blocks, cnt; - unsigned long arg[6]; - int nr; - int err; -} rs; - -static void rsyscall_handler(int sig, siginfo_t *si, void *ctx) -{ - if (rs.cnt == libc.threads_minus_1) return; - - if (syscall6(rs.nr, rs.arg[0], rs.arg[1], rs.arg[2], - rs.arg[3], rs.arg[4], rs.arg[5]) < 0 && !rs.err) rs.err=errno; - - a_inc(&rs.cnt); - __wake(&rs.cnt, 1, 1); - while(rs.hold) - __wait(&rs.hold, 0, 1, 1); - a_dec(&rs.cnt); - if (!rs.cnt) __wake(&rs.cnt, 1, 1); -} - -static int rsyscall(int nr, long a, long b, long c, long d, long e, long f) -{ - int i, ret; - sigset_t set = { 0 }; - struct pthread *self = __pthread_self(); - sigaddset(&set, SIGSYSCALL); - - LOCK(&rs.lock); - while ((i=rs.blocks)) - __wait(&rs.blocks, 0, i, 1); - - __libc_sigprocmask(SIG_BLOCK, &set, 0); - - rs.nr = nr; - rs.arg[0] = a; rs.arg[1] = b; - rs.arg[2] = c; rs.arg[3] = d; - rs.arg[4] = d; rs.arg[5] = f; - rs.hold = 1; - rs.err = 0; - rs.cnt = 0; - - /* Dispatch signals until all threads respond */ - for (i=libc.threads_minus_1; i; i--) - sigqueue(self->pid, SIGSYSCALL, (union sigval){0}); - while ((i=rs.cnt) < libc.threads_minus_1) { - sigqueue(self->pid, SIGSYSCALL, (union sigval){0}); - __wait(&rs.cnt, 0, i, 1); - } - - /* Handle any lingering signals with no-op */ - __libc_sigprocmask(SIG_UNBLOCK, &set, 0); - - /* Resume other threads' signal handlers and wait for them */ - rs.hold = 0; - __wake(&rs.hold, -1, 0); - while((i=rs.cnt)) __wait(&rs.cnt, 0, i, 1); - - if (rs.err) errno = rs.err, ret = -1; - else ret = syscall6(nr, a, b, c, d, e, f); - - UNLOCK(&rs.lock); - return ret; -} - -static void init_threads() -{ - struct sigaction sa = { .sa_flags = SA_SIGINFO | SA_RESTART }; - libc.lock = __lock; - libc.cancelpt = cancelpt; - libc.rsyscall = rsyscall; - sa.sa_sigaction = cancel_handler; - __libc_sigaction(SIGCANCEL, &sa, 0); - sigaddset(&sa.sa_mask, SIGSYSCALL); - sigaddset(&sa.sa_mask, SIGCANCEL); - sa.sa_sigaction = rsyscall_handler; - __libc_sigaction(SIGSYSCALL, &sa, 0); - sigprocmask(SIG_UNBLOCK, &sa.sa_mask, 0); -} - -static int start(void *p) -{ - struct pthread *self = p; - pthread_exit(self->start(self->start_arg)); - return 0; -} - -int __uniclone(void *, int (*)(), void *); - -#define ROUND(x) (((x)+PAGE_SIZE-1)&-PAGE_SIZE) - -#if 0 -/* pthread_key_create.c overrides this */ -static const size_t dummy = 0; -weak_alias(dummy, __pthread_tsd_size); -#else -extern size_t __pthread_tsd_size; -#endif - -int pthread_create(pthread_t *res, const pthread_attr_t *attr, void *(*entry)(void *), void *arg) -{ - static int init; - int ret; - size_t size, guard; - struct pthread *self = pthread_self(), *new; - unsigned char *map, *stack, *tsd; - static const pthread_attr_t default_attr; - - if (!self) return errno = ENOSYS; - if (!init && ++init) init_threads(); - - if (!attr) attr = &default_attr; - guard = ROUND(attr->_a_guardsize + DEFAULT_GUARD_SIZE); - size = guard + ROUND(attr->_a_stacksize + DEFAULT_STACK_SIZE); - size += __pthread_tsd_size; - map = mmap(0, size, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANON, -1, 0); - if (!map) return EAGAIN; - mprotect(map, guard, PROT_NONE); - - tsd = map + size - __pthread_tsd_size; - new = (void *)(tsd - sizeof *new - PAGE_SIZE%sizeof *new); - new->map_base = map; - new->map_size = size; - new->pid = self->pid; - new->errno_ptr = &new->errno_val; - new->start = entry; - new->start_arg = arg; - new->self = new; - new->tsd = (void *)tsd; - new->detached = attr->_a_detach; - new->attr = *attr; - memcpy(new->tlsdesc, self->tlsdesc, sizeof new->tlsdesc); - new->tlsdesc[1] = (uintptr_t)new; - stack = (void *)((uintptr_t)new-1 & ~(uintptr_t)15); - - /* We must synchronize new thread creation with rsyscall - * delivery. This looks to be the least expensive way: */ - a_inc(&rs.blocks); - while (rs.lock) __wait(&rs.lock, 0, 1, 1); - - a_inc(&libc.threads_minus_1); - ret = __uniclone(stack, start, new); - - a_dec(&rs.blocks); - if (rs.lock) __wake(&rs.blocks, 1, 1); - - if (ret < 0) { - a_dec(&libc.threads_minus_1); - munmap(map, size); - return EAGAIN; - } - *res = new; - return 0; -} - -void pthread_exit(void *result) -{ - struct pthread *self = pthread_self(); - self->result = result; - docancel(self); -} diff --git a/05/musl-final/src/thread/pthread_detach.c b/05/musl-final/src/thread/pthread_detach.c deleted file mode 100644 index f0eae3e..0000000 --- a/05/musl-final/src/thread/pthread_detach.c +++ /dev/null @@ -1,11 +0,0 @@ -#include "pthread_impl.h" - -int pthread_detach(pthread_t t) -{ - /* Cannot detach a thread that's already exiting */ - if (a_xchg(&t->exitlock, 1)) - return pthread_join(t, 0); - t->detached = 1; - t->exitlock = 0; - return 0; -} diff --git a/05/musl-final/src/thread/pthread_equal.c b/05/musl-final/src/thread/pthread_equal.c deleted file mode 100644 index a55d280..0000000 --- a/05/musl-final/src/thread/pthread_equal.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int pthread_equal(pthread_t a, pthread_t b) -{ - return a==b; -} diff --git a/05/musl-final/src/thread/pthread_getspecific.c b/05/musl-final/src/thread/pthread_getspecific.c deleted file mode 100644 index a6ca27d..0000000 --- a/05/musl-final/src/thread/pthread_getspecific.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "pthread_impl.h" - -void *pthread_getspecific(pthread_key_t k) -{ - struct pthread *self = pthread_self(); - if (!self->tsd) return 0; - return self->tsd[k]; -} diff --git a/05/musl-final/src/thread/pthread_join.c b/05/musl-final/src/thread/pthread_join.c deleted file mode 100644 index 5210ed4..0000000 --- a/05/musl-final/src/thread/pthread_join.c +++ /dev/null @@ -1,12 +0,0 @@ -#include "pthread_impl.h" - -int pthread_join(pthread_t t, void **res) -{ - int tmp = t->tid; - CANCELPT_BEGIN; - if (tmp) __wait(&t->tid, 0, tmp, 1); - CANCELPT_END; - if (res) *res = t->result; - if (t->map_base) munmap(t->map_base, t->map_size); - return 0; -} diff --git a/05/musl-final/src/thread/pthread_key_create.c b/05/musl-final/src/thread/pthread_key_create.c deleted file mode 100644 index efc3804..0000000 --- a/05/musl-final/src/thread/pthread_key_create.c +++ /dev/null @@ -1,25 +0,0 @@ -#include "pthread_impl.h" - -const size_t __pthread_tsd_size = sizeof(void *) * PTHREAD_KEYS_MAX; - -static void nodtor(void *dummy) -{ -} - -int pthread_key_create(pthread_key_t *k, void (*dtor)(void *)) -{ - static void (*keys[PTHREAD_KEYS_MAX])(void *); - int i = (uintptr_t)&k / 16 % PTHREAD_KEYS_MAX; - int j = i; - - libc.tsd_keys = keys; - if (!dtor) dtor = nodtor; - /* Cheap trick - &k cannot match any destructor pointer */ - while (a_cas_p(keys+j, 0, &k) - && (j=(j+1)%PTHREAD_KEYS_MAX) != i); - if (keys[j] != (void (*)(void *))&k) - return EAGAIN; - keys[j] = dtor; - *k = j; - return 0; -} diff --git a/05/musl-final/src/thread/pthread_key_delete.c b/05/musl-final/src/thread/pthread_key_delete.c deleted file mode 100644 index 4914ebb..0000000 --- a/05/musl-final/src/thread/pthread_key_delete.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "pthread_impl.h" - -int pthread_key_delete(pthread_key_t k) -{ - if (libc.tsd_keys) libc.tsd_keys[k] = 0; - return 0; -} diff --git a/05/musl-final/src/thread/pthread_kill.c b/05/musl-final/src/thread/pthread_kill.c deleted file mode 100644 index 9d85fa5..0000000 --- a/05/musl-final/src/thread/pthread_kill.c +++ /dev/null @@ -1,7 +0,0 @@ -#define SYSCALL_RETURN_ERRNO -#include "pthread_impl.h" - -int pthread_kill(pthread_t t, int sig) -{ - return syscall3(__NR_tgkill, t->pid, t->tid, sig); -} diff --git a/05/musl-final/src/thread/pthread_mutex_destroy.c b/05/musl-final/src/thread/pthread_mutex_destroy.c deleted file mode 100644 index 6d49e68..0000000 --- a/05/musl-final/src/thread/pthread_mutex_destroy.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int pthread_mutex_destroy(pthread_mutex_t *mutex) -{ - return 0; -} diff --git a/05/musl-final/src/thread/pthread_mutex_init.c b/05/musl-final/src/thread/pthread_mutex_init.c deleted file mode 100644 index d453543..0000000 --- a/05/musl-final/src/thread/pthread_mutex_init.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "pthread_impl.h" - -int pthread_mutex_init(pthread_mutex_t *m, const pthread_mutexattr_t *a) -{ - memset(m, 0, sizeof *m); - if (a) { - } - return 0; -} diff --git a/05/musl-final/src/thread/pthread_mutex_lock.c b/05/musl-final/src/thread/pthread_mutex_lock.c deleted file mode 100644 index 15ede3f..0000000 --- a/05/musl-final/src/thread/pthread_mutex_lock.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "pthread_impl.h" - -int pthread_mutex_lock(pthread_mutex_t *m) -{ - int r; - while ((r=pthread_mutex_trylock(m)) == EBUSY) - __wait(&m->_m_lock, &m->_m_waiters, 1, 0); - return r; -} diff --git a/05/musl-final/src/thread/pthread_mutex_timedlock.c b/05/musl-final/src/thread/pthread_mutex_timedlock.c deleted file mode 100644 index 20ce012..0000000 --- a/05/musl-final/src/thread/pthread_mutex_timedlock.c +++ /dev/null @@ -1,15 +0,0 @@ -#include "pthread_impl.h" - -int pthread_mutex_timedlock(pthread_mutex_t *m, const struct timespec *at) -{ - int r, w=0; - while ((r=pthread_mutex_trylock(m)) == EBUSY) { - if (!w) a_inc(&m->_m_waiters), w++; - if (__timedwait(&m->_m_lock, 1, CLOCK_REALTIME, at, 0) == ETIMEDOUT) { - if (w) a_dec(&m->_m_waiters); - return ETIMEDOUT; - } - } - if (w) a_dec(&m->_m_waiters); - return r; -} diff --git a/05/musl-final/src/thread/pthread_mutex_trylock.c b/05/musl-final/src/thread/pthread_mutex_trylock.c deleted file mode 100644 index 29268fd..0000000 --- a/05/musl-final/src/thread/pthread_mutex_trylock.c +++ /dev/null @@ -1,28 +0,0 @@ -#include "pthread_impl.h" - -int pthread_mutex_trylock(pthread_mutex_t *m) -{ - if (m->_m_type == PTHREAD_MUTEX_RECURSIVE) { - pthread_t self = pthread_self(); - if (m->_m_owner == self->tid) { - if ((unsigned)m->_m_lock >= INT_MAX) return EAGAIN; - a_inc(&m->_m_lock); - return 0; - } - if (a_fetch_add(&m->_m_lock, 1)) { - if (a_fetch_add(&m->_m_lock, -1)==1 && m->_m_waiters) - __wake(&m->_m_lock, 1, 0); - return EBUSY; - } - m->_m_owner = self->tid; - return 0; - } - - if (a_xchg(&m->_m_lock, 1)) - if (m->_m_type == PTHREAD_MUTEX_ERRORCHECK - && m->_m_owner == pthread_self()->tid) return EDEADLK; - else return EBUSY; - if (m->_m_type == PTHREAD_MUTEX_ERRORCHECK) - m->_m_owner = pthread_self()->tid; - return 0; -} diff --git a/05/musl-final/src/thread/pthread_mutex_unlock.c b/05/musl-final/src/thread/pthread_mutex_unlock.c deleted file mode 100644 index 0275eb5..0000000 --- a/05/musl-final/src/thread/pthread_mutex_unlock.c +++ /dev/null @@ -1,19 +0,0 @@ -#include "pthread_impl.h" - -int pthread_mutex_unlock(pthread_mutex_t *m) -{ - if (m->_m_type == PTHREAD_MUTEX_RECURSIVE) { - if (a_fetch_add(&m->_m_lock, -1)==1 && m->_m_waiters) - __wake(&m->_m_lock, 1, 0); - return 0; - } - - if (m->_m_type == PTHREAD_MUTEX_ERRORCHECK - && m->_m_owner != pthread_self()->tid) - return EPERM; - - m->_m_owner = 0; - m->_m_lock = 0; - if (m->_m_waiters) __wake(&m->_m_lock, 1, 0); - return 0; -} diff --git a/05/musl-final/src/thread/pthread_mutexattr_destroy.c b/05/musl-final/src/thread/pthread_mutexattr_destroy.c deleted file mode 100644 index 9fd6974..0000000 --- a/05/musl-final/src/thread/pthread_mutexattr_destroy.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "pthread_impl.h" - -int pthread_mutexattr_destroy(pthread_mutexattr_t *a) -{ - return 0; -} diff --git a/05/musl-final/src/thread/pthread_mutexattr_gettype.c b/05/musl-final/src/thread/pthread_mutexattr_gettype.c deleted file mode 100644 index 9edb16c..0000000 --- a/05/musl-final/src/thread/pthread_mutexattr_gettype.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "pthread_impl.h" - -int pthread_mutexattr_gettype(const pthread_mutexattr_t *a, int *type) -{ - *type = *a & 3; - return 0; -} diff --git a/05/musl-final/src/thread/pthread_mutexattr_init.c b/05/musl-final/src/thread/pthread_mutexattr_init.c deleted file mode 100644 index ea63106..0000000 --- a/05/musl-final/src/thread/pthread_mutexattr_init.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "pthread_impl.h" - -int pthread_mutexattr_init(pthread_mutexattr_t *a) -{ - memset(a, 0, sizeof *a); - return 0; -} diff --git a/05/musl-final/src/thread/pthread_mutexattr_settype.c b/05/musl-final/src/thread/pthread_mutexattr_settype.c deleted file mode 100644 index 4e85950..0000000 --- a/05/musl-final/src/thread/pthread_mutexattr_settype.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "pthread_impl.h" - -int pthread_mutexattr_settype(pthread_mutexattr_t *a, int type) -{ - if ((unsigned)type > 2) return EINVAL; - *a = (*a & ~3) | type; - return 0; -} diff --git a/05/musl-final/src/thread/pthread_once.c b/05/musl-final/src/thread/pthread_once.c deleted file mode 100644 index 7223005..0000000 --- a/05/musl-final/src/thread/pthread_once.c +++ /dev/null @@ -1,38 +0,0 @@ -#include "pthread_impl.h" - -static void undo(void *control) -{ - a_store(control, 0); - __wake(control, 1, 0); -} - -int pthread_once(pthread_once_t *control, void (*init)(void)) -{ - static int waiters; - - /* Return immediately if init finished before */ - if (*control == 2) return 0; - - /* Try to enter initializing state. Three possibilities: - * 0 - we're the first or the other cancelled; run init - * 1 - another thread is running init; wait - * 2 - another thread finished running init; just return */ - - for (;;) switch (a_swap(control, 1)) { - case 0: - break; - case 1: - __wait(control, &waiters, 1, 0); - continue; - case 2: - a_store(control, 2); - return 0; - } - - pthread_cleanup_push(undo, control); - init(); - pthread_cleanup_pop(0); - - if (waiters) __wake(control, -1, 0); - return 0; -} diff --git a/05/musl-final/src/thread/pthread_rwlock_destroy.c b/05/musl-final/src/thread/pthread_rwlock_destroy.c deleted file mode 100644 index 49ecfbd..0000000 --- a/05/musl-final/src/thread/pthread_rwlock_destroy.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "pthread_impl.h" - -int pthread_rwlock_destroy(pthread_rwlock_t *rw) -{ - return 0; -} diff --git a/05/musl-final/src/thread/pthread_rwlock_init.c b/05/musl-final/src/thread/pthread_rwlock_init.c deleted file mode 100644 index f87d566..0000000 --- a/05/musl-final/src/thread/pthread_rwlock_init.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "pthread_impl.h" - -int pthread_rwlock_init(pthread_rwlock_t *rw, const pthread_rwlockattr_t *a) -{ - memset(rw, 0, sizeof *rw); - if (a) { - } - return 0; -} diff --git a/05/musl-final/src/thread/pthread_rwlock_rdlock.c b/05/musl-final/src/thread/pthread_rwlock_rdlock.c deleted file mode 100644 index 2986350..0000000 --- a/05/musl-final/src/thread/pthread_rwlock_rdlock.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "pthread_impl.h" - -int pthread_rwlock_rdlock(pthread_rwlock_t *rw) -{ - while (pthread_rwlock_tryrdlock(rw)) - __wait(&rw->_rw_wrlock, &rw->_rw_waiters, 1, 0); - return 0; -} diff --git a/05/musl-final/src/thread/pthread_rwlock_timedrdlock.c b/05/musl-final/src/thread/pthread_rwlock_timedrdlock.c deleted file mode 100644 index 1e76a8e..0000000 --- a/05/musl-final/src/thread/pthread_rwlock_timedrdlock.c +++ /dev/null @@ -1,15 +0,0 @@ -#include "pthread_impl.h" - -int pthread_rwlock_timedrdlock(pthread_rwlock_t *rw, const struct timespec *at) -{ - int w=0; - while (pthread_rwlock_tryrdlock(rw)) { - if (!w) a_inc(&rw->_rw_waiters), w++; - if (__timedwait(&rw->_rw_wrlock, 1, CLOCK_REALTIME, at, 0)==ETIMEDOUT) { - if (w) a_dec(&rw->_rw_waiters); - return ETIMEDOUT; - } - } - if (w) a_dec(&rw->_rw_waiters); - return 0; -} diff --git a/05/musl-final/src/thread/pthread_rwlock_timedwrlock.c b/05/musl-final/src/thread/pthread_rwlock_timedwrlock.c deleted file mode 100644 index 9682774..0000000 --- a/05/musl-final/src/thread/pthread_rwlock_timedwrlock.c +++ /dev/null @@ -1,17 +0,0 @@ -#include "pthread_impl.h" - -int pthread_rwlock_timedwrlock(pthread_rwlock_t *rw, const struct timespec *at) -{ - int nr, *p, w=0; - while (pthread_rwlock_trywrlock(rw)==EAGAIN) { - if (!w) a_inc(&rw->_rw_waiters), w++; - if ((nr=rw->_rw_readers)) p = &rw->_rw_readers; - else nr=1, p = &rw->_rw_wrlock; - if (__timedwait(p, nr, CLOCK_REALTIME, at, 0)==ETIMEDOUT) { - if (w) a_dec(&rw->_rw_waiters); - return ETIMEDOUT; - } - } - if (w) a_dec(&rw->_rw_waiters); - return 0; -} diff --git a/05/musl-final/src/thread/pthread_rwlock_tryrdlock.c b/05/musl-final/src/thread/pthread_rwlock_tryrdlock.c deleted file mode 100644 index fc1d532..0000000 --- a/05/musl-final/src/thread/pthread_rwlock_tryrdlock.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "pthread_impl.h" - -int pthread_rwlock_tryrdlock(pthread_rwlock_t *rw) -{ - a_inc(&rw->_rw_readers); - if (rw->_rw_wrlock) { - a_dec(&rw->_rw_readers); - if (rw->_rw_waiters && !rw->_rw_readers) - __wake(&rw->_rw_readers, 1, 0); - return EAGAIN; - } - return 0; -} diff --git a/05/musl-final/src/thread/pthread_rwlock_trywrlock.c b/05/musl-final/src/thread/pthread_rwlock_trywrlock.c deleted file mode 100644 index 1bcf7c9..0000000 --- a/05/musl-final/src/thread/pthread_rwlock_trywrlock.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "pthread_impl.h" - -int pthread_rwlock_trywrlock(pthread_rwlock_t *rw) -{ - if (a_xchg(&rw->_rw_wrlock, 1)) - return EAGAIN; - if (rw->_rw_readers) { - a_store(&rw->_rw_wrlock, 0); - return EAGAIN; - } - rw->_rw_owner = pthread_self()->tid; - return 0; -} diff --git a/05/musl-final/src/thread/pthread_rwlock_unlock.c b/05/musl-final/src/thread/pthread_rwlock_unlock.c deleted file mode 100644 index 060e3fe..0000000 --- a/05/musl-final/src/thread/pthread_rwlock_unlock.c +++ /dev/null @@ -1,17 +0,0 @@ -#include "pthread_impl.h" - -int pthread_rwlock_unlock(pthread_rwlock_t *rw) -{ - struct pthread *self = pthread_self(); - if (rw->_rw_owner == self->tid) { - rw->_rw_owner = 0; - a_store(&rw->_rw_wrlock, 0); - if (rw->_rw_waiters) - __wake(&rw->_rw_wrlock, -1, 0); - return 0; - } - a_dec(&rw->_rw_readers); - if (rw->_rw_waiters && !rw->_rw_readers) - __wake(&rw->_rw_readers, 1, 0); - return 0; -} diff --git a/05/musl-final/src/thread/pthread_rwlock_wrlock.c b/05/musl-final/src/thread/pthread_rwlock_wrlock.c deleted file mode 100644 index 8fd9ad1..0000000 --- a/05/musl-final/src/thread/pthread_rwlock_wrlock.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "pthread_impl.h" - -int pthread_rwlock_wrlock(pthread_rwlock_t *rw) -{ - int nr; - while (pthread_rwlock_trywrlock(rw)==EAGAIN) { - if ((nr=rw->_rw_readers)) - __wait(&rw->_rw_readers, &rw->_rw_waiters, nr, 0); - else - __wait(&rw->_rw_wrlock, &rw->_rw_waiters, 1, 0); - } - return 0; -} diff --git a/05/musl-final/src/thread/pthread_self.c b/05/musl-final/src/thread/pthread_self.c deleted file mode 100644 index 3a4d4c5..0000000 --- a/05/musl-final/src/thread/pthread_self.c +++ /dev/null @@ -1,33 +0,0 @@ -#include "pthread_impl.h" - -static struct pthread main_thread; - -#undef errno -static int *errno_location() -{ - return __pthread_self()->errno_ptr; -} - -static int init_main_thread() -{ - main_thread.self = &main_thread; - if (__set_thread_area(&main_thread) < 0) - return -1; - syscall1(__NR_set_tid_address, (long)&main_thread.tid); - main_thread.errno_ptr = __errno_location(); - libc.errno_location = errno_location; - main_thread.tid = main_thread.pid = getpid(); - return 0; -} - -pthread_t pthread_self() -{ - static int init, failed; - if (!init) { - if (failed) return 0; - if (init_main_thread() < 0) failed = 1; - if (failed) return 0; - init = 1; - } - return __pthread_self(); -} diff --git a/05/musl-final/src/thread/pthread_setcancelstate.c b/05/musl-final/src/thread/pthread_setcancelstate.c deleted file mode 100644 index 23c3885..0000000 --- a/05/musl-final/src/thread/pthread_setcancelstate.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "pthread_impl.h" - -int pthread_setcancelstate(int new, int *old) -{ - struct pthread *self = pthread_self(); - if (old) *old = self->canceldisable; - if ((unsigned)new > 1) return EINVAL; - self->canceldisable = new; - return 0; -} diff --git a/05/musl-final/src/thread/pthread_setcanceltype.c b/05/musl-final/src/thread/pthread_setcanceltype.c deleted file mode 100644 index c73db22..0000000 --- a/05/musl-final/src/thread/pthread_setcanceltype.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "pthread_impl.h" - -int pthread_setcanceltype(int new, int *old) -{ - struct pthread *self = pthread_self(); - if (old) *old = self->cancelasync; - if ((unsigned)new > 1) return EINVAL; - self->cancelasync = new; - return 0; -} diff --git a/05/musl-final/src/thread/pthread_setspecific.c b/05/musl-final/src/thread/pthread_setspecific.c deleted file mode 100644 index 171cef4..0000000 --- a/05/musl-final/src/thread/pthread_setspecific.c +++ /dev/null @@ -1,18 +0,0 @@ -#include "pthread_impl.h" - -int pthread_setspecific(pthread_key_t k, const void *x) -{ - struct pthread *self = pthread_self(); - /* Handle the case of the main thread */ - if (!self->tsd) { - if (!x) return 0; - if (!(self->tsd = calloc(sizeof(void *), PTHREAD_KEYS_MAX))) - return ENOMEM; - } - /* Avoid unnecessary COW */ - if (self->tsd[k] != x) { - self->tsd[k] = (void *)x; - self->tsd_used = 1; - } - return 0; -} diff --git a/05/musl-final/src/thread/pthread_spin_destroy.c b/05/musl-final/src/thread/pthread_spin_destroy.c deleted file mode 100644 index e65a820..0000000 --- a/05/musl-final/src/thread/pthread_spin_destroy.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "pthread_impl.h" - -int pthread_spin_destroy(pthread_spinlock_t *s) -{ - return 0; -} diff --git a/05/musl-final/src/thread/pthread_spin_init.c b/05/musl-final/src/thread/pthread_spin_init.c deleted file mode 100644 index 681881c..0000000 --- a/05/musl-final/src/thread/pthread_spin_init.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "pthread_impl.h" - -int pthread_spin_init(pthread_spinlock_t *s, int shared) -{ - return *s = 0; -} diff --git a/05/musl-final/src/thread/pthread_spin_lock.c b/05/musl-final/src/thread/pthread_spin_lock.c deleted file mode 100644 index 59fa6ea..0000000 --- a/05/musl-final/src/thread/pthread_spin_lock.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "pthread_impl.h" - -int pthread_spin_lock(pthread_spinlock_t *s) -{ - while (a_xchg(s, 1)); - return 0; -} diff --git a/05/musl-final/src/thread/pthread_spin_trylock.c b/05/musl-final/src/thread/pthread_spin_trylock.c deleted file mode 100644 index c12696b..0000000 --- a/05/musl-final/src/thread/pthread_spin_trylock.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "pthread_impl.h" - -int pthread_spin_trylock(pthread_spinlock_t *s) -{ - return -a_xchg(s, 1) & EBUSY; -} diff --git a/05/musl-final/src/thread/pthread_spin_unlock.c b/05/musl-final/src/thread/pthread_spin_unlock.c deleted file mode 100644 index a7eab33..0000000 --- a/05/musl-final/src/thread/pthread_spin_unlock.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "pthread_impl.h" - -int pthread_spin_unlock(pthread_spinlock_t *s) -{ - return *s = 0; -} diff --git a/05/musl-final/src/thread/pthread_testcancel.c b/05/musl-final/src/thread/pthread_testcancel.c deleted file mode 100644 index 774b706..0000000 --- a/05/musl-final/src/thread/pthread_testcancel.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "pthread_impl.h" - -void pthread_testcancel() -{ - CANCELPT_BEGIN; - CANCELPT_END; -} diff --git a/05/musl-final/src/thread/x86_64/__set_thread_area.s b/05/musl-final/src/thread/x86_64/__set_thread_area.s deleted file mode 100644 index faf73ec..0000000 --- a/05/musl-final/src/thread/x86_64/__set_thread_area.s +++ /dev/null @@ -1,11 +0,0 @@ -/* Copyright 2011 Nicholas J. Kain, licensed GNU LGPL 2.1 or later */ -.text -.global __set_thread_area -.type __set_thread_area,%function -__set_thread_area: - mov %rdi,%rsi /* shift for syscall */ - movl $0x1002,%edi /* SET_FS register */ - movl $158,%eax /* set fs segment to */ - syscall /* arch_prctl(SET_FS, arg)*/ - ret -.size __set_thread_area,.-__set_thread_area diff --git a/05/musl-final/src/thread/x86_64/__unmapself.s b/05/musl-final/src/thread/x86_64/__unmapself.s deleted file mode 100644 index 59092ea..0000000 --- a/05/musl-final/src/thread/x86_64/__unmapself.s +++ /dev/null @@ -1,24 +0,0 @@ -/* Copyright 2011 Nicholas J. Kain, licensed GNU LGPL 2.1 or later */ -.text -.global __unmapself -.type __unmapself,%function -__unmapself: - call 1f /* glibc ABI compat */ - .long -1 - .long -1 -1: push %rsi /* save arg2 for munmap */ - push %rdx /* save arg3 for munmap */ - mov %rdi,%rsi /* rt_sigprocmask() args: move arg1 to rsi */ - xor %rdi,%rdi - xor %rdx,%rdx - movq $8,%r10 - movl $14,%eax /* __NR_rt_sigprocmask */ - syscall /* call rt_sigprocmask(0,arg1,0,8) */ - pop %rsi /* munmap() args: reload from stack */ - pop %rdi - movl $11,%eax /* __NR_munmap */ - syscall /* munmap(arg2,arg3) */ - xor %rdi,%rdi /* exit() args: always return success */ - movl $60,%eax /* __NR_exit */ - syscall /* exit(0) */ -.size __unmapself,.-__unmapself diff --git a/05/musl-final/src/thread/x86_64/clone.s b/05/musl-final/src/thread/x86_64/clone.s deleted file mode 100644 index 3cefd93..0000000 --- a/05/musl-final/src/thread/x86_64/clone.s +++ /dev/null @@ -1,22 +0,0 @@ -/* Copyright 2011 Nicholas J. Kain, licensed GNU LGPL 2.1 or later */ -.text -.global __uniclone -.type __uniclone,%function -/* rdi = child_stack, rsi = start, rdx = pthread_struct */ -__uniclone: - subq $8,%rsp /* pad parent stack to prevent branch later */ - subq $16,%rdi /* grow child_stack */ - mov %rsi,8(%rdi) /* push start onto child_stack as return ptr */ - mov %rdx,0(%rdi) /* push pthread_struct onto child_stack */ - mov %rdx,%r8 /* r8 = tls */ - mov %rdi,%rsi /* rsi = child_stack */ - leaq 40(%rdx),%r10 /* r10 = child_id */ - movl $56,%eax /* clone syscall number */ - movl $0x7d0f00,%edi /* rdi = flags */ - mov %r10,%rdx /* rdx = parent_id */ - syscall /* clone(flags, child_stack, parent_id, - * child_id, tls) */ - pop %rdi /* child stack: restore pthread_struct - * parent stack: undo rsp displacement */ - ret -.size __uniclone,.-__uniclone diff --git a/05/musl-final/src/time/__asctime.c b/05/musl-final/src/time/__asctime.c deleted file mode 100644 index 1853580..0000000 --- a/05/musl-final/src/time/__asctime.c +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include -#include - -const char *__langinfo(nl_item); - -char *__asctime(const struct tm *tm, char *buf) -{ - /* FIXME: change __langinfo to __C_langinfo once we have locales */ - if (snprintf(buf, 26, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n", - __langinfo(ABDAY_1+tm->tm_wday), - __langinfo(ABMON_1+tm->tm_mon), - tm->tm_mday, tm->tm_hour, - tm->tm_min, tm->tm_sec, - 1900 + tm->tm_year) >= 26) - { - /* ISO C requires us to use the above format string, - * even if it will not fit in the buffer. Thus asctime_r - * is _supposed_ to crash if the fields in tm are too large. - * We follow this behavior and crash "gracefully" to warn - * application developers that they may not be so lucky - * on other implementations (e.g. stack smashing..). - */ - *(int*)0 = 0; - } - return buf; -} diff --git a/05/musl-final/src/time/__time.h b/05/musl-final/src/time/__time.h deleted file mode 100644 index 967e518..0000000 --- a/05/musl-final/src/time/__time.h +++ /dev/null @@ -1,9 +0,0 @@ -time_t __tm_to_time(struct tm *); -struct tm *__time_to_tm(time_t, struct tm *); -void __tzset(void); -struct tm *__dst_adjust(struct tm *tm); - -extern long __timezone; -extern int __daylight; -extern int __dst_offset; -extern char *__tzname[2]; diff --git a/05/musl-final/src/time/__time_to_tm.c b/05/musl-final/src/time/__time_to_tm.c deleted file mode 100644 index a1ebc45..0000000 --- a/05/musl-final/src/time/__time_to_tm.c +++ /dev/null @@ -1,81 +0,0 @@ -#include - -/* C defines the rounding for division in a nonsensical way */ -#define Q(a,b) ((a)>0 ? (a)/(b) : -(((b)-(a)-1)/(b))) - -#define DAYS_PER_400Y (365*400 + 97) -#define DAYS_PER_100Y (365*100 + 24) -#define DAYS_PER_4Y (365*4 + 1) - -/* FIXME: use lldiv once it's fixed to compute quot,rem together */ -struct tm *__time_to_tm(time_t t, struct tm *tm) -{ - /* months are march-based */ - static const int days_thru_month[] = {31,61,92,122,153,184,214,245,275,306,337,366}; - long long bigday; - unsigned int day, year4, year100; - int year, year400; - int month; - int leap; - int hour, min, sec; - int wday, mday, yday; - - /* start from 2000-03-01 (multiple of 400 years) */ - t += -946684800 - 86400*(31+29); - - bigday = Q(t, 86400); - sec = t-bigday*86400; - - hour = sec/3600; - sec -= hour*3600; - min = sec/60; - sec -= min*60; - - /* 2000-03-01 was a wednesday */ - wday = (3+bigday)%7; - if (wday < 0) wday += 7; - - t = -946684800LL - 86400*(31+29) + 9000000; - - year400 = Q(bigday, DAYS_PER_400Y); - day = bigday-year400*DAYS_PER_400Y; - - year100 = day/DAYS_PER_100Y; - if (year100 == 4) year100--; - day -= year100*DAYS_PER_100Y; - - year4 = day/DAYS_PER_4Y; - if (year4 == 25) year4--; - day -= year4*DAYS_PER_4Y; - - year = day/365; - if (year == 4) year--; - day -= year*365; - - leap = !year && (year4 || !year100); - yday = day + 31+28 + leap; - if (yday >= 365+leap) yday -= 365+leap; - - year += 4*year4 + 100*year100 + 400*year400 + 2000-1900; - - for (month=0; days_thru_month[month] <= day; month++); - if (month) day -= days_thru_month[month-1]; - month += 2; - if (month >= 12) { - month -= 12; - year++; - } - - mday = day+1; - - tm->tm_sec = sec; - tm->tm_min = min; - tm->tm_hour= hour; - tm->tm_mday= mday; - tm->tm_mon = month; - tm->tm_year= year; - tm->tm_wday= wday; - tm->tm_yday= yday; - - return tm; -} diff --git a/05/musl-final/src/time/__tm_to_time.c b/05/musl-final/src/time/__tm_to_time.c deleted file mode 100644 index 3fa15fa..0000000 --- a/05/musl-final/src/time/__tm_to_time.c +++ /dev/null @@ -1,33 +0,0 @@ -#include - -/* C defines the rounding for division in a nonsensical way */ -#define Q(a,b) ((a)>0 ? (a)/(b) : -(((b)-(a)-1)/(b))) - -time_t __tm_to_time(struct tm *tm) -{ - time_t year = tm->tm_year + -100; - int month = tm->tm_mon; - int day = tm->tm_mday; - int z4, z100, z400; - - /* normalize month */ - if (month >= 12) { - year += month/12; - month %= 12; - } else if (month < 0) { - year += month/12; - month %= 12; - if (month) { - month += 12; - year--; - } - } - z4 = Q(year - (month < 2), 4); - z100 = Q(z4, 25); - z400 = Q(z100, 4); - day += year*365 + z4 - z100 + z400 + - month[(int []){0,31,59,90,120,151,181,212,243,273,304,335}]; - return (long long)day*86400 - + tm->tm_hour*3600 + tm->tm_min*60 + tm->tm_sec - - -946684800; /* the dawn of time :) */ -} diff --git a/05/musl-final/src/time/asctime.c b/05/musl-final/src/time/asctime.c deleted file mode 100644 index 3102eb8..0000000 --- a/05/musl-final/src/time/asctime.c +++ /dev/null @@ -1,9 +0,0 @@ -#include - -char *__asctime(const struct tm *, char *); - -char *asctime(const struct tm *tm) -{ - static char buf[26]; - return __asctime(tm, buf); -} diff --git a/05/musl-final/src/time/asctime_r.c b/05/musl-final/src/time/asctime_r.c deleted file mode 100644 index e51b880..0000000 --- a/05/musl-final/src/time/asctime_r.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -char *__asctime(const struct tm *, char *); - -char *asctime_r(const struct tm *tm, char *buf) -{ - return __asctime(tm, buf); -} diff --git a/05/musl-final/src/time/clock.c b/05/musl-final/src/time/clock.c deleted file mode 100644 index 2feddb3..0000000 --- a/05/musl-final/src/time/clock.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include - -/* this function assumes 100 hz linux and corrects for it */ -clock_t clock() -{ - struct tms tms; - return (unsigned long)times(&tms)*10000; -} diff --git a/05/musl-final/src/time/clock_gettime.c b/05/musl-final/src/time/clock_gettime.c deleted file mode 100644 index 67a05ba..0000000 --- a/05/musl-final/src/time/clock_gettime.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include "syscall.h" - -int clock_gettime(clockid_t clk, struct timespec *ts) -{ - return syscall2(__NR_clock_gettime, clk, (long)ts); -} - -int clock_settime(clockid_t clk, const struct timespec *ts) -{ - return syscall2(__NR_clock_settime, clk, (long)ts); -} diff --git a/05/musl-final/src/time/ctime.c b/05/musl-final/src/time/ctime.c deleted file mode 100644 index 185ec55..0000000 --- a/05/musl-final/src/time/ctime.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -char *ctime(const time_t *t) -{ - return asctime(localtime(t)); -} diff --git a/05/musl-final/src/time/ctime_r.c b/05/musl-final/src/time/ctime_r.c deleted file mode 100644 index d2260a1..0000000 --- a/05/musl-final/src/time/ctime_r.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -char *ctime_r(const time_t *t, char *buf) -{ - struct tm tm; - localtime_r(t, &tm); - return asctime_r(&tm, buf); -} diff --git a/05/musl-final/src/time/difftime.c b/05/musl-final/src/time/difftime.c deleted file mode 100644 index 80a18cc..0000000 --- a/05/musl-final/src/time/difftime.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -double difftime(time_t t1, time_t t0) -{ - return t1-t0; -} diff --git a/05/musl-final/src/time/gettimeofday.c b/05/musl-final/src/time/gettimeofday.c deleted file mode 100644 index 2b8a287..0000000 --- a/05/musl-final/src/time/gettimeofday.c +++ /dev/null @@ -1,9 +0,0 @@ -#define SYSCALL_RETURN_ERRNO -#include -#include "syscall.h" - -int gettimeofday(struct timeval *tv, void *tz) -{ - syscall2(__NR_gettimeofday, (long)tv, 0); - return 0; -} diff --git a/05/musl-final/src/time/gmtime.c b/05/musl-final/src/time/gmtime.c deleted file mode 100644 index d4d5d1f..0000000 --- a/05/musl-final/src/time/gmtime.c +++ /dev/null @@ -1,11 +0,0 @@ -#include - -#include "__time.h" - -struct tm *gmtime(const time_t *t) -{ - static struct tm tm; - __time_to_tm(*t, &tm); - tm.tm_isdst = 0; - return &tm; -} diff --git a/05/musl-final/src/time/gmtime_r.c b/05/musl-final/src/time/gmtime_r.c deleted file mode 100644 index 5b565a6..0000000 --- a/05/musl-final/src/time/gmtime_r.c +++ /dev/null @@ -1,10 +0,0 @@ -#include - -#include "__time.h" - -struct tm *gmtime_r(const time_t *t, struct tm *result) -{ - __time_to_tm(*t, result); - result->tm_isdst = 0; - return result; -} diff --git a/05/musl-final/src/time/localtime.c b/05/musl-final/src/time/localtime.c deleted file mode 100644 index abd5e84..0000000 --- a/05/musl-final/src/time/localtime.c +++ /dev/null @@ -1,12 +0,0 @@ -#include - -#include "__time.h" - -struct tm *localtime(const time_t *t) -{ - static struct tm tm; - __tzset(); - __time_to_tm(*t - __timezone, &tm); - tm.tm_isdst = -1; - return __dst_adjust(&tm); -} diff --git a/05/musl-final/src/time/localtime_r.c b/05/musl-final/src/time/localtime_r.c deleted file mode 100644 index 2bf1037..0000000 --- a/05/musl-final/src/time/localtime_r.c +++ /dev/null @@ -1,11 +0,0 @@ -#include - -#include "__time.h" - -struct tm *localtime_r(const time_t *t, struct tm *result) -{ - __tzset(); - __time_to_tm(*t - __timezone, result); - result->tm_isdst = -1; - return __dst_adjust(result); -} diff --git a/05/musl-final/src/time/mktime.c b/05/musl-final/src/time/mktime.c deleted file mode 100644 index 858cd50..0000000 --- a/05/musl-final/src/time/mktime.c +++ /dev/null @@ -1,24 +0,0 @@ -#include - -#include "__time.h" - -time_t mktime(struct tm *tm) -{ - int isdst = tm->tm_isdst; - time_t t, lt; - - __tzset(); - - tm->tm_sec += __timezone; - if (isdst > 0) tm->tm_sec += __dst_offset; - - t = __tm_to_time(tm); - - lt = t - __timezone; - if (isdst > 0) lt -= __dst_offset; - __time_to_tm(lt, tm); - - __dst_adjust(tm); - - return t; -} diff --git a/05/musl-final/src/time/nanosleep.c b/05/musl-final/src/time/nanosleep.c deleted file mode 100644 index 5ac4c35..0000000 --- a/05/musl-final/src/time/nanosleep.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include -#include "syscall.h" -#include "libc.h" - -int nanosleep(const struct timespec *req, struct timespec *rem) -{ - int ret; - CANCELPT_BEGIN; - ret = syscall2(__NR_nanosleep, (long)req, (long)rem); - CANCELPT_END; - return ret; -} diff --git a/05/musl-final/src/time/strftime.c b/05/musl-final/src/time/strftime.c deleted file mode 100644 index f1b9463..0000000 --- a/05/musl-final/src/time/strftime.c +++ /dev/null @@ -1,172 +0,0 @@ -#include -#include -#include -#include -#include "__time.h" - -// FIXME: integer overflows - -const char *__langinfo(nl_item); - -size_t strftime(char *s, size_t n, const char *f, const struct tm *tm) -{ - nl_item item; - int val; - const char *fmt; - size_t l; - for (l=0; *f && ltm_wday; - goto nl_strcat; - case 'A': - item = DAY_1 + tm->tm_wday; - goto nl_strcat; - case 'h': - case 'b': - item = ABMON_1 + tm->tm_mon; - goto nl_strcat; - case 'B': - item = MON_1 + tm->tm_mon; - goto nl_strcat; - case 'c': - item = D_T_FMT; - goto nl_strftime; - case 'C': - val = (1900+tm->tm_year) / 100; - fmt = "%02d"; - goto number; - case 'd': - val = tm->tm_mday; - fmt = "%02d"; - goto number; - case 'D': - fmt = "%m/%d/%y"; - goto recu_strftime; - case 'e': - val = tm->tm_mday; - fmt = "%2d"; - goto number; - case 'F': - fmt = "%Y-%m-%d"; - goto recu_strftime; - case 'g': - // FIXME - val = 0; //week_based_year(tm)%100; - fmt = "%02d"; - goto number; - case 'G': - // FIXME - val = 0; //week_based_year(tm); - fmt = "%04d"; - goto number; - case 'H': - val = tm->tm_hour; - fmt = "%02d"; - goto number; - case 'I': - val = tm->tm_hour; - if (!val) val = 12; - else if (val > 12) val -= 12; - fmt = "%02d"; - goto number; - case 'j': - val = tm->tm_yday+1; - fmt = "%03d"; - goto number; - case 'm': - val = tm->tm_mon+1; - fmt = "%02d"; - goto number; - case 'M': - val = tm->tm_min; - fmt = "%02d"; - goto number; - case 'n': - s[l++] = '\n'; - continue; - case 'p': - item = tm->tm_hour >= 12 ? PM_STR : AM_STR; - goto nl_strcat; - case 'r': - item = T_FMT_AMPM; - goto nl_strftime; - case 'R': - fmt = "%H:%M"; - goto recu_strftime; - case 'S': - val = tm->tm_sec; - fmt = "%02d"; - goto number; - case 't': - s[l++] = '\t'; - continue; - case 'T': - fmt = "%H:%M:%S"; - goto recu_strftime; - case 'u': - val = tm->tm_wday ? tm->tm_wday : 7; - fmt = "%d"; - goto number; - case 'U': - case 'V': - case 'W': - // FIXME: week number mess.. - continue; - case 'w': - val = tm->tm_wday; - fmt = "%d"; - goto number; - case 'x': - item = D_FMT; - goto nl_strftime; - case 'X': - item = T_FMT; - goto nl_strftime; - case 'y': - val = tm->tm_year % 100; - fmt = "%02d"; - goto number; - case 'Y': - val = tm->tm_year + 1900; - fmt = "%04d"; - goto number; - case 'z': - if (tm->tm_isdst < 0) continue; - val = -__timezone - (tm->tm_isdst ? __dst_offset : 0); - l += snprintf(s+l, n-l, "%+.2d%.2d", val/3600, abs(val%3600)/60); - continue; - case 'Z': - if (tm->tm_isdst < 0 || !__tzname[0] || !__tzname[0][0]) - continue; - l += snprintf(s+l, n-l, "%s", __tzname[!!tm->tm_isdst]); - continue; - default: - return 0; - } - } -literal: - s[l++] = *f; - continue; -number: - l += snprintf(s+l, n-l, fmt, val); - continue; -nl_strcat: - l += snprintf(s+l, n-l, "%s", __langinfo(item)); - continue; -nl_strftime: - fmt = __langinfo(item); -recu_strftime: - l += strftime(s+l, n-l, fmt, tm); - } - if (l >= n) return 0; - s[l] = 0; - return l; -} diff --git a/05/musl-final/src/time/strptime.c b/05/musl-final/src/time/strptime.c deleted file mode 100644 index db72e61..0000000 --- a/05/musl-final/src/time/strptime.c +++ /dev/null @@ -1,178 +0,0 @@ -#include -#include -#include -#include - -const char *__langinfo(nl_item); - -char *strptime(const char *s, const char *f, struct tm *tm) -{ - return NULL; -} - -#if 0 - -char *strptime(const char *s, const char *f, struct tm *tm) -{ - nl_item item; - int *dest; - const char *fmt; - for (; *f; f++) { - if (isspace(*f)) goto whitespace; - if (*f == '%') { -do_fmt: - switch (*++f) { - case '%': - goto literal; - case 'E': - case 'O': - goto do_fmt; - case 'a': - item = ABDAY_1 + tm->tm_wday; - goto nl_strcat; - case 'A': - item = DAY_1 + tm->tm_wday; - goto nl_strcat; - case 'h': - case 'b': - item = ABMON_1 + tm->tm_mon; - goto nl_strcat; - case 'B': - item = MON_1 + tm->tm_mon; - goto nl_strcat; - case 'c': - item = D_T_FMT; - goto nl_strftime; - case 'C': - val = (1900+tm->tm_year) / 100; - fmt = "%02d"; - goto number; - case 'd': - val = tm->tm_mday; - fmt = "%02d"; - goto number; - case 'D': - fmt = "%m/%d/%y"; - goto recu_strftime; - case 'e': - val = tm->tm_mday; - fmt = "%2d"; - goto number; - case 'F': - fmt = "%Y-%m-%d"; - goto recu_strftime; - case 'g': - // FIXME - val = 0; //week_based_year(tm)%100; - fmt = "%02d"; - goto number; - case 'G': - // FIXME - val = 0; //week_based_year(tm); - fmt = "%04d"; - goto number; - case 'H': - val = tm->tm_hour; - fmt = "%02d"; - goto number; - case 'I': - val = tm->tm_hour; - if (!val) val = 12; - else if (val > 12) val -= 12; - fmt = "%02d"; - goto number; - case 'j': - val = tm->tm_yday+1; - fmt = "%03d"; - goto number; - case 'm': - val = tm->tm_mon+1; - fmt = "%02d"; - goto number; - case 'M': - val = tm->tm_min; - fmt = "%02d"; - goto number; - case 'n': - case 't': - goto whitespace; - case 'p': - item = tm->tm_hour >= 12 ? PM_STR : AM_STR; - goto nl_strcat; - case 'r': - item = T_FMT_AMPM; - goto nl_strftime; - case 'R': - fmt = "%H:%M"; - goto recu_strftime; - case 'S': - val = tm->tm_sec; - fmt = "%02d"; - goto number; - case 'T': - fmt = "%H:%M:%S"; - goto recu_strftime; - case 'u': - val = tm->tm_wday ? tm->tm_wday : 7; - fmt = "%d"; - goto number; - case 'U': - case 'V': - case 'W': - // FIXME: week number mess.. - continue; - case 'w': - val = tm->tm_wday; - fmt = "%d"; - goto number; - case 'x': - item = D_FMT; - goto nl_strftime; - case 'X': - item = T_FMT; - goto nl_strftime; - case 'y': - val = tm->tm_year % 100; - fmt = "%02d"; - goto number; - case 'Y': - val = tm->tm_year + 1900; - fmt = "%04d"; - goto number; - case 'z': - if (tm->tm_isdst < 0) continue; - val = timezone + (tm->tm_isdst) ? __dst_offset : 0; - l += snprintf(s+l, n-l, "%+02d%02d", val/60, abs(val%60)); - continue; - case 'Z': - if (tm->tm_isdst < 0 || !tzname[0] || !tzname[0][0]) - continue; - l += snprintf(s+l, n-l, "%s", tzname[!!tm->tm_isdst]); - continue; - } - default: - return NULL; - } -literal: - if (*s++ != *f) return NULL; - continue; -whitespace: - while(isspace(*s)) s++; - continue; -number: - l += snprintf(s+l, n-l, fmt, val); - continue; -nl_strcat: - l += snprintf(s+l, n-l, "%s", __langinfo(item)); - continue; -nl_strftime: - fmt = __langinfo(item); -recu_strftime: - l += strftime(s+l, n-l, fmt, tm); - } - if (l >= n) return 0; - s[l] = 0; - return l; -} - -#endif diff --git a/05/musl-final/src/time/time.c b/05/musl-final/src/time/time.c deleted file mode 100644 index 3457dad..0000000 --- a/05/musl-final/src/time/time.c +++ /dev/null @@ -1,12 +0,0 @@ -#define SYSCALL_RETURN_ERRNO -#include -#include -#include "syscall.h" - -time_t time(time_t *t) -{ - struct timeval tv; - syscall2(__NR_gettimeofday, (long)&tv, 0); - if (t) *t = tv.tv_sec; - return tv.tv_sec; -} diff --git a/05/musl-final/src/time/times.c b/05/musl-final/src/time/times.c deleted file mode 100644 index e9b5a82..0000000 --- a/05/musl-final/src/time/times.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -clock_t times(struct tms *tms) -{ - return syscall1(__NR_times, (long)&tms); -} diff --git a/05/musl-final/src/time/timezone.s b/05/musl-final/src/time/timezone.s deleted file mode 100644 index 4e167b0..0000000 --- a/05/musl-final/src/time/timezone.s +++ /dev/null @@ -1,27 +0,0 @@ -.data - -.global timezone -.global __timezone -.global daylight -.global __daylight -.global tzname -.global __tzname - -__timezone: -timezone: - .long 0 -.size timezone,.-timezone -.size __timezone,.-__timezone - -__daylight: -daylight: - .long 0 -.size daylight,.-daylight -.size __daylight,.-__daylight - -__tzname: -tzname: - .long 0 - .long 0 -.size tzname,.-tzname -.size __tzname,.-__tzname diff --git a/05/musl-final/src/time/tzset.c b/05/musl-final/src/time/tzset.c deleted file mode 100644 index 6d69957..0000000 --- a/05/musl-final/src/time/tzset.c +++ /dev/null @@ -1,173 +0,0 @@ -#include -#include -#include -#include -#include -#include "libc.h" - -#include "__time.h" - -long __timezone = 0; -int __daylight = 0; -char *__tzname[2] = { 0, 0 }; -int __dst_offset = 0; - -weak_alias(__timezone, timezone); -weak_alias(__daylight, daylight); -weak_alias(__tzname, tzname); -weak_alias(__dst_offset, dst_offset); - -static char std_name[TZNAME_MAX+1]; -static char dst_name[TZNAME_MAX+1]; - -/* all elements are zero-based */ -static struct rule { - char month; - char week; - short day; - int time; -} __dst_start, __dst_end; - -static void zname(char *d, char **s) -{ - int i; - for (i=0; i= 0) { - if (**s == ':') ofs += strtol(*s+1, s, 10)*60; - if (**s == ':') ofs += strtol(*s+1, s, 10); - } else { - if (**s == ':') ofs -= strtol(*s+1, s, 10)*60; - if (**s == ':') ofs -= strtol(*s+1, s, 10); - } - return ofs; -} - -static int dstrule(struct rule *rule, char **s) -{ - if (**s != ',') return -1; - switch (*++*s) { - case 'J': - rule->month = 'J'; - rule->day = strtol(*s+1, s, 10)-1; - break; - case 'M': - rule->month = strtol(*s+1, s, 10)-1; - if (**s != '.' || rule->month < 0 || rule->month > 11) - return -1; - rule->week = strtol(*s+1, s, 10)-1; - if (**s != '.' || rule->week < 0 || rule->week > 4) - return -1; - rule->day = strtol(*s+1, s, 10); - if (rule->day < 0 || rule->day > 6) - return -1; - break; - default: - rule->month = 'L'; - rule->day = strtol(*s+1, s, 10); - break; - } - if (**s == '/') { - (*s)++; - rule->time = hhmmss(s); - } else rule->time = 7200; - return 0; -} - -void tzset(void) -{ - char *z, *a; - - strcpy(std_name, "GMT"); - strcpy(dst_name, "GMT"); - __tzname[0] = std_name; - __tzname[1] = dst_name; - __timezone = 0; - __daylight = 0; - - if (!(z = getenv("TZ")) || !isalpha(*z)) return; - - zname(std_name, &z); - __timezone = hhmmss(&z); - - zname(dst_name, &z); - if (dst_name[0]) __daylight=1; - a = z; - __dst_offset = hhmmss(&z) - __timezone; - if (z==a) __dst_offset = -3600; - - if (dstrule(&__dst_start, &z) || dstrule(&__dst_end, &z)) - __daylight = 0; -} - -void __tzset(void) -{ - static int lock, init; - if (init) return; - LOCK(&lock); - if (!init) tzset(); - init=1; - UNLOCK(&lock); -} - -static int is_leap(int year) -{ - year -= 100; - return !(year&3) && ((year%100) || !(year%400)); -} - -static int cutoff_yday(struct tm *tm, struct rule *rule) -{ - static const char days_in_month[] = {31,28,31,30,31,30,31,31,30,31,30,31}; - static const int first_day[] = {0,31,59,90,120,151,181,212,243,273,304,335}; - int yday, mday, leap; - - switch (rule->month) { - case 'J': - return rule->day + (tm->tm_mon > 1 && is_leap(tm->tm_year)); - case 'L': - return rule->day; - default: - yday = first_day[rule->month]; - leap = is_leap(tm->tm_year); - if (rule->month > 1 && leap) yday++; - mday = (rule->day - (yday + tm->tm_wday - tm->tm_yday) + 1400)%7 + 7*rule->week; - if (mday >= days_in_month[rule->month] + (leap && rule->month == 1)) - mday -= 7; - return mday + yday; - } -} - -struct tm *__dst_adjust(struct tm *tm) -{ - time_t t; - int start, end, secs; - int after_start, before_end; - - if (tm->tm_isdst >= 0) return tm; - if (!__daylight) { - tm->tm_isdst = 0; - return tm; - } - - secs = tm->tm_hour*3600 + tm->tm_min*60 + tm->tm_sec; - start = cutoff_yday(tm, &__dst_start); - end = cutoff_yday(tm, &__dst_end); - - after_start = (tm->tm_yday > start || (tm->tm_yday == start && secs >= __dst_start.time)); - before_end = (tm->tm_yday < end || (tm->tm_yday == end && secs < __dst_end.time)); - - if ((after_start && before_end) || ((end < start) && (after_start || before_end))) { - tm->tm_sec -= __dst_offset; - tm->tm_isdst = 1; - t = __tm_to_time(tm); - return __time_to_tm(t, tm); - } else tm->tm_isdst = 0; - - return tm; -} diff --git a/05/musl-final/src/time/utime.c b/05/musl-final/src/time/utime.c deleted file mode 100644 index 56e9e13..0000000 --- a/05/musl-final/src/time/utime.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include "syscall.h" - -int utime(const char *path, const struct utimbuf *times) -{ - long ktimes[2]; - if (times) { - ktimes[0] = times->actime; - ktimes[1] = times->modtime; - } - return syscall2(__NR_utime, (long)path, times ? (long)ktimes : 0); -} diff --git a/05/musl-final/src/unistd/_exit.c b/05/musl-final/src/unistd/_exit.c deleted file mode 100644 index d2e84c4..0000000 --- a/05/musl-final/src/unistd/_exit.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include - -void _exit(int status) -{ - _Exit(status); -} diff --git a/05/musl-final/src/unistd/access.c b/05/musl-final/src/unistd/access.c deleted file mode 100644 index 2c10e58..0000000 --- a/05/musl-final/src/unistd/access.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int access(const char *filename, int amode) -{ - return syscall2(__NR_access, (long)filename, amode); -} diff --git a/05/musl-final/src/unistd/alarm.c b/05/musl-final/src/unistd/alarm.c deleted file mode 100644 index bba444d..0000000 --- a/05/musl-final/src/unistd/alarm.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -unsigned alarm(unsigned seconds) -{ - return syscall1(__NR_alarm, seconds); -} diff --git a/05/musl-final/src/unistd/chdir.c b/05/musl-final/src/unistd/chdir.c deleted file mode 100644 index c89bda3..0000000 --- a/05/musl-final/src/unistd/chdir.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int chdir(const char *path) -{ - return syscall1(__NR_chdir, (long)path); -} diff --git a/05/musl-final/src/unistd/chown.c b/05/musl-final/src/unistd/chown.c deleted file mode 100644 index b89b173..0000000 --- a/05/musl-final/src/unistd/chown.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int chown(const char *path, uid_t uid, gid_t gid) -{ - return syscall3(__NR_chown, (long)path, uid, gid); -} diff --git a/05/musl-final/src/unistd/close.c b/05/musl-final/src/unistd/close.c deleted file mode 100644 index 97302f6..0000000 --- a/05/musl-final/src/unistd/close.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -int close(int fd) -{ - int ret = __syscall_close(fd); - CANCELPT_BEGIN; - CANCELPT_END; - return ret; -} diff --git a/05/musl-final/src/unistd/ctermid.c b/05/musl-final/src/unistd/ctermid.c deleted file mode 100644 index 21b44ec..0000000 --- a/05/musl-final/src/unistd/ctermid.c +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include -#include -#include -#include -#include - -char *ctermid(char *s) -{ - static char *s2; - int fd; - if (!s) { - if (!s2) s2 = malloc(L_ctermid); - s = s2; - } - fd = open("/dev/tty", O_WRONLY | O_NOCTTY); - if (fd < 0) - return strcpy(s, ""); - if (ttyname_r(fd, s, L_ctermid)) - strcpy(s, ""); - close(fd); - return s; -} diff --git a/05/musl-final/src/unistd/dup.c b/05/musl-final/src/unistd/dup.c deleted file mode 100644 index b11cd71..0000000 --- a/05/musl-final/src/unistd/dup.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int dup(int fd) -{ - return syscall1(__NR_dup, fd); -} diff --git a/05/musl-final/src/unistd/dup2.c b/05/musl-final/src/unistd/dup2.c deleted file mode 100644 index 9332544..0000000 --- a/05/musl-final/src/unistd/dup2.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int dup2(int old, int new) -{ - return __syscall_dup2(old, new); -} diff --git a/05/musl-final/src/unistd/faccessat.c b/05/musl-final/src/unistd/faccessat.c deleted file mode 100644 index 99a9378..0000000 --- a/05/musl-final/src/unistd/faccessat.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int faccessat(int fd, const char *filename, int amode, int flag) -{ - return syscall4(__NR_faccessat, fd, (long)filename, amode, flag); -} diff --git a/05/musl-final/src/unistd/fchdir.c b/05/musl-final/src/unistd/fchdir.c deleted file mode 100644 index b2acbc2..0000000 --- a/05/musl-final/src/unistd/fchdir.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int fchdir(int fd) -{ - return syscall1(__NR_fchdir, fd); -} diff --git a/05/musl-final/src/unistd/fchown.c b/05/musl-final/src/unistd/fchown.c deleted file mode 100644 index 6050b77..0000000 --- a/05/musl-final/src/unistd/fchown.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int fchown(int fd, uid_t uid, gid_t gid) -{ - return syscall3(__NR_fchown, fd, uid, gid); -} diff --git a/05/musl-final/src/unistd/fchownat.c b/05/musl-final/src/unistd/fchownat.c deleted file mode 100644 index 7062642..0000000 --- a/05/musl-final/src/unistd/fchownat.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int fchownat(int fd, const char *path, uid_t uid, gid_t gid, int flag) -{ - return syscall5(__NR_fchownat, fd, (long)path, uid, gid, flag); -} diff --git a/05/musl-final/src/unistd/fdatasync.c b/05/musl-final/src/unistd/fdatasync.c deleted file mode 100644 index ef7c9a9..0000000 --- a/05/musl-final/src/unistd/fdatasync.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int fdatasync(int fd) -{ - return 0; -} diff --git a/05/musl-final/src/unistd/fsync.c b/05/musl-final/src/unistd/fsync.c deleted file mode 100644 index 7cfedc9..0000000 --- a/05/musl-final/src/unistd/fsync.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include "syscall.h" - -int fsync(int fd) -{ - //return syscall1(__NR_fsync, fd); - return 0; -} diff --git a/05/musl-final/src/unistd/ftruncate.c b/05/musl-final/src/unistd/ftruncate.c deleted file mode 100644 index db5da84..0000000 --- a/05/musl-final/src/unistd/ftruncate.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -int ftruncate(int fd, off_t length) -{ - return syscall3(__NR_ftruncate, fd, SYSCALL_LL(length)); -} - -LFS64(ftruncate); diff --git a/05/musl-final/src/unistd/getcwd.c b/05/musl-final/src/unistd/getcwd.c deleted file mode 100644 index 4910f42..0000000 --- a/05/musl-final/src/unistd/getcwd.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include -#include "syscall.h" - -char *getcwd(char *buf, size_t size) -{ - return syscall2(__NR_getcwd, (long)buf, size) < 0 ? NULL : buf; -} diff --git a/05/musl-final/src/unistd/getegid.c b/05/musl-final/src/unistd/getegid.c deleted file mode 100644 index 33ee205..0000000 --- a/05/musl-final/src/unistd/getegid.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -gid_t getegid(void) -{ - return syscall0(__NR_getegid); -} diff --git a/05/musl-final/src/unistd/geteuid.c b/05/musl-final/src/unistd/geteuid.c deleted file mode 100644 index cdec631..0000000 --- a/05/musl-final/src/unistd/geteuid.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -uid_t geteuid(void) -{ - return syscall0(__NR_geteuid); -} diff --git a/05/musl-final/src/unistd/getgid.c b/05/musl-final/src/unistd/getgid.c deleted file mode 100644 index 8a4590b..0000000 --- a/05/musl-final/src/unistd/getgid.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -gid_t getgid(void) -{ - return syscall0(__NR_getgid); -} diff --git a/05/musl-final/src/unistd/getgroups.c b/05/musl-final/src/unistd/getgroups.c deleted file mode 100644 index 37619b9..0000000 --- a/05/musl-final/src/unistd/getgroups.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int getgroups(int count, gid_t list[]) -{ - return syscall2(__NR_getgroups, count, (long)list); -} diff --git a/05/musl-final/src/unistd/gethostname.c b/05/musl-final/src/unistd/gethostname.c deleted file mode 100644 index a406c4e..0000000 --- a/05/musl-final/src/unistd/gethostname.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include -#include - -int gethostname(char *name, size_t len) -{ - size_t i; - struct utsname uts; - if (uname(&uts)) return -1; - if (len > sizeof uts.nodename) len = sizeof uts.nodename; - for (i=0; i -#include - -char *getlogin(void) -{ - return getenv("LOGNAME"); -} diff --git a/05/musl-final/src/unistd/getlogin_r.c b/05/musl-final/src/unistd/getlogin_r.c deleted file mode 100644 index f04f71e..0000000 --- a/05/musl-final/src/unistd/getlogin_r.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include -#include -#include - -int getlogin_r(char *name, size_t size) -{ - char *logname = getlogin(); - if (!logname) return ENXIO; /* or...? */ - if (strlen(name) >= size) return ERANGE; - strcpy(name, logname); - return 0; -} diff --git a/05/musl-final/src/unistd/getpgid.c b/05/musl-final/src/unistd/getpgid.c deleted file mode 100644 index 50d716b..0000000 --- a/05/musl-final/src/unistd/getpgid.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -pid_t getpgid(pid_t pid) -{ - return syscall1(__NR_getpgid, pid); -} diff --git a/05/musl-final/src/unistd/getpgrp.c b/05/musl-final/src/unistd/getpgrp.c deleted file mode 100644 index 2004630..0000000 --- a/05/musl-final/src/unistd/getpgrp.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -pid_t getpgrp(void) -{ - return syscall0(__NR_getpgrp); -} diff --git a/05/musl-final/src/unistd/getpid.c b/05/musl-final/src/unistd/getpid.c deleted file mode 100644 index 31cbe1c..0000000 --- a/05/musl-final/src/unistd/getpid.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -pid_t getpid(void) -{ - return syscall0(__NR_getpid); -} diff --git a/05/musl-final/src/unistd/getppid.c b/05/musl-final/src/unistd/getppid.c deleted file mode 100644 index a324182..0000000 --- a/05/musl-final/src/unistd/getppid.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -pid_t getppid(void) -{ - return syscall0(__NR_getppid); -} diff --git a/05/musl-final/src/unistd/getsid.c b/05/musl-final/src/unistd/getsid.c deleted file mode 100644 index 064229c..0000000 --- a/05/musl-final/src/unistd/getsid.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -pid_t getsid(pid_t pid) -{ - return syscall1(__NR_getsid, pid); -} diff --git a/05/musl-final/src/unistd/getuid.c b/05/musl-final/src/unistd/getuid.c deleted file mode 100644 index cd7233d..0000000 --- a/05/musl-final/src/unistd/getuid.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -uid_t getuid(void) -{ - return syscall0(__NR_getuid); -} diff --git a/05/musl-final/src/unistd/isatty.c b/05/musl-final/src/unistd/isatty.c deleted file mode 100644 index cff6e9f..0000000 --- a/05/musl-final/src/unistd/isatty.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include - -int isatty(int fd) -{ - struct termios t; - return tcgetattr(fd, &t) == 0; -} diff --git a/05/musl-final/src/unistd/lchown.c b/05/musl-final/src/unistd/lchown.c deleted file mode 100644 index a840213..0000000 --- a/05/musl-final/src/unistd/lchown.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int lchown(const char *path, uid_t uid, gid_t gid) -{ - return syscall3(__NR_lchown, (long)path, uid, gid); -} diff --git a/05/musl-final/src/unistd/link.c b/05/musl-final/src/unistd/link.c deleted file mode 100644 index f121bb9..0000000 --- a/05/musl-final/src/unistd/link.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int link(const char *existing, const char *new) -{ - return syscall2(__NR_link, (long)existing, (long)new); -} diff --git a/05/musl-final/src/unistd/linkat.c b/05/musl-final/src/unistd/linkat.c deleted file mode 100644 index 0eb5122..0000000 --- a/05/musl-final/src/unistd/linkat.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int linkat(int fd1, const char *existing, int fd2, const char *new, int flag) -{ - return syscall5(__NR_linkat, fd1, (long)existing, fd2, (long)new, flag); -} diff --git a/05/musl-final/src/unistd/lseek.c b/05/musl-final/src/unistd/lseek.c deleted file mode 100644 index 0152866..0000000 --- a/05/musl-final/src/unistd/lseek.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -off_t lseek(int fd, off_t offset, int whence) -{ -#ifdef __NR__llseek - off_t result; - return syscall5(__NR__llseek, fd, offset>>32, offset, (long)&result, whence) ? -1 : result; -#else - return syscall3(__NR_lseek, fd, offset, whence); -#endif -} - -LFS64(lseek); diff --git a/05/musl-final/src/unistd/nice.c b/05/musl-final/src/unistd/nice.c deleted file mode 100644 index f38db67..0000000 --- a/05/musl-final/src/unistd/nice.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include -#include "syscall.h" - -int nice(int inc) -{ -#ifdef __NR_nice - return syscall1(__NR_nice, inc); -#else - return setpriority(PRIO_PROCESS, 0, getpriority(PRIO_PROCESS, 0)+inc); -#endif -} diff --git a/05/musl-final/src/unistd/pause.c b/05/musl-final/src/unistd/pause.c deleted file mode 100644 index 1472065..0000000 --- a/05/musl-final/src/unistd/pause.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -int pause(void) -{ - int r; - CANCELPT_BEGIN; - r = syscall0(__NR_pause); - CANCELPT_END; - return r; -} diff --git a/05/musl-final/src/unistd/pipe.c b/05/musl-final/src/unistd/pipe.c deleted file mode 100644 index 2dfc9c9..0000000 --- a/05/musl-final/src/unistd/pipe.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int pipe(int fd[2]) -{ - return syscall1(__NR_pipe, (long)fd); -} diff --git a/05/musl-final/src/unistd/pread.c b/05/musl-final/src/unistd/pread.c deleted file mode 100644 index 534215a..0000000 --- a/05/musl-final/src/unistd/pread.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -ssize_t pread(int fd, void *buf, size_t size, off_t ofs) -{ - ssize_t r; - CANCELPT_BEGIN; - r = syscall5(__NR_pread, fd, (long)buf, size, SYSCALL_LL(ofs)); - CANCELPT_END; - return r; -} - -LFS64(pread); diff --git a/05/musl-final/src/unistd/pwrite.c b/05/musl-final/src/unistd/pwrite.c deleted file mode 100644 index 56ed6b4..0000000 --- a/05/musl-final/src/unistd/pwrite.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -ssize_t pwrite(int fd, const void *buf, size_t size, off_t ofs) -{ - ssize_t r; - CANCELPT_BEGIN; - r = syscall5(__NR_pwrite, fd, (long)buf, size, SYSCALL_LL(ofs)); - CANCELPT_END; - return r; -} - -LFS64(pwrite); diff --git a/05/musl-final/src/unistd/read.c b/05/musl-final/src/unistd/read.c deleted file mode 100644 index 87ff1f1..0000000 --- a/05/musl-final/src/unistd/read.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -ssize_t read(int fd, void *buf, size_t count) -{ - ssize_t r; - CANCELPT_BEGIN; - r = __syscall_read(fd, buf, count); - CANCELPT_END; - return r; -} diff --git a/05/musl-final/src/unistd/readlink.c b/05/musl-final/src/unistd/readlink.c deleted file mode 100644 index f6b1635..0000000 --- a/05/musl-final/src/unistd/readlink.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int readlink(const char *path, char *buf, size_t bufsize) -{ - return syscall3(__NR_readlink, (long)path, (long)buf, bufsize); -} diff --git a/05/musl-final/src/unistd/readlinkat.c b/05/musl-final/src/unistd/readlinkat.c deleted file mode 100644 index 8171050..0000000 --- a/05/musl-final/src/unistd/readlinkat.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int readlinkat(int fd, const char *path, char *buf, size_t bufsize) -{ - return syscall4(__NR_readlinkat, fd, (long)path, (long)buf, bufsize); -} diff --git a/05/musl-final/src/unistd/readv.c b/05/musl-final/src/unistd/readv.c deleted file mode 100644 index e311f9d..0000000 --- a/05/musl-final/src/unistd/readv.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -ssize_t readv(int fd, const struct iovec *iov, int count) -{ - ssize_t r; - CANCELPT_BEGIN; - r = syscall3(__NR_readv, fd, (long)iov, count); - CANCELPT_END; - return r; -} diff --git a/05/musl-final/src/unistd/renameat.c b/05/musl-final/src/unistd/renameat.c deleted file mode 100644 index 0dae9f1..0000000 --- a/05/musl-final/src/unistd/renameat.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int renameat(int oldfd, const char *old, int newfd, const char *new) -{ - return syscall4(__NR_renameat, oldfd, (long)old, newfd, (long)new); -} diff --git a/05/musl-final/src/unistd/rmdir.c b/05/musl-final/src/unistd/rmdir.c deleted file mode 100644 index 8e18c7a..0000000 --- a/05/musl-final/src/unistd/rmdir.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int rmdir(const char *path) -{ - return syscall1(__NR_rmdir, (long)path); -} diff --git a/05/musl-final/src/unistd/setegid.c b/05/musl-final/src/unistd/setegid.c deleted file mode 100644 index 8534884..0000000 --- a/05/musl-final/src/unistd/setegid.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int setegid(gid_t egid) -{ - return setregid(-1, egid); -} diff --git a/05/musl-final/src/unistd/seteuid.c b/05/musl-final/src/unistd/seteuid.c deleted file mode 100644 index 0aaa86e..0000000 --- a/05/musl-final/src/unistd/seteuid.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int seteuid(uid_t euid) -{ - return setreuid(-1, euid); -} diff --git a/05/musl-final/src/unistd/setgid.c b/05/musl-final/src/unistd/setgid.c deleted file mode 100644 index 42976d9..0000000 --- a/05/musl-final/src/unistd/setgid.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -int setgid(gid_t gid) -{ - if (libc.rsyscall) return libc.rsyscall(__NR_setgid, gid, 0, 0, 0, 0, 0); - return syscall1(__NR_setgid, gid); -} diff --git a/05/musl-final/src/unistd/setpgid.c b/05/musl-final/src/unistd/setpgid.c deleted file mode 100644 index 748d290..0000000 --- a/05/musl-final/src/unistd/setpgid.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -pid_t setpgid(pid_t pid, pid_t pgid) -{ - return syscall2(__NR_setpgid, pid, pgid); -} diff --git a/05/musl-final/src/unistd/setpgrp.c b/05/musl-final/src/unistd/setpgrp.c deleted file mode 100644 index a2a37f6..0000000 --- a/05/musl-final/src/unistd/setpgrp.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -pid_t setpgrp(void) -{ - return setpgid(0, 0); -} diff --git a/05/musl-final/src/unistd/setregid.c b/05/musl-final/src/unistd/setregid.c deleted file mode 100644 index 158753b..0000000 --- a/05/musl-final/src/unistd/setregid.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -int setregid(gid_t rgid, gid_t egid) -{ - if (libc.rsyscall) return libc.rsyscall(__NR_setregid, rgid, egid, 0, 0, 0, 0); - return syscall2(__NR_setregid, rgid, egid); -} diff --git a/05/musl-final/src/unistd/setreuid.c b/05/musl-final/src/unistd/setreuid.c deleted file mode 100644 index 47c6730..0000000 --- a/05/musl-final/src/unistd/setreuid.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -int setreuid(uid_t ruid, uid_t euid) -{ - if (libc.rsyscall) return libc.rsyscall(__NR_setreuid, ruid, euid, 0, 0, 0, 0); - return syscall2(__NR_setreuid, ruid, euid); -} diff --git a/05/musl-final/src/unistd/setsid.c b/05/musl-final/src/unistd/setsid.c deleted file mode 100644 index e2c5690..0000000 --- a/05/musl-final/src/unistd/setsid.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -pid_t setsid(void) -{ - return syscall0(__NR_setsid); -} diff --git a/05/musl-final/src/unistd/setuid.c b/05/musl-final/src/unistd/setuid.c deleted file mode 100644 index 9e9da61..0000000 --- a/05/musl-final/src/unistd/setuid.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -int setuid(uid_t uid) -{ - if (libc.rsyscall) return libc.rsyscall(__NR_setuid, uid, 0, 0, 0, 0, 0); - return syscall1(__NR_setuid, uid); -} diff --git a/05/musl-final/src/unistd/sleep.c b/05/musl-final/src/unistd/sleep.c deleted file mode 100644 index d645094..0000000 --- a/05/musl-final/src/unistd/sleep.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include - -unsigned sleep(unsigned seconds) -{ - struct timespec tv = { .tv_sec = seconds, .tv_nsec = 0 }; - if (nanosleep(&tv, &tv)) - return tv.tv_sec; - return 0; -} diff --git a/05/musl-final/src/unistd/symlink.c b/05/musl-final/src/unistd/symlink.c deleted file mode 100644 index 8d380d8..0000000 --- a/05/musl-final/src/unistd/symlink.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int symlink(const char *existing, const char *new) -{ - return syscall2(__NR_symlink, (long)existing, (long)new); -} diff --git a/05/musl-final/src/unistd/symlinkat.c b/05/musl-final/src/unistd/symlinkat.c deleted file mode 100644 index 9693b22..0000000 --- a/05/musl-final/src/unistd/symlinkat.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int symlinkat(const char *existing, int fd, const char *new) -{ - return syscall3(__NR_symlinkat, (long)existing, fd, (long)new); -} diff --git a/05/musl-final/src/unistd/sync.c b/05/musl-final/src/unistd/sync.c deleted file mode 100644 index a49808f..0000000 --- a/05/musl-final/src/unistd/sync.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -void sync(void) -{ - syscall0(__NR_sync); -} diff --git a/05/musl-final/src/unistd/tcgetpgrp.c b/05/musl-final/src/unistd/tcgetpgrp.c deleted file mode 100644 index 50080c7..0000000 --- a/05/musl-final/src/unistd/tcgetpgrp.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include -#include - -pid_t tcgetpgrp(int fd) -{ - int pgrp; - if (ioctl(fd, TIOCGPGRP, &pgrp) < 0) - return -1; - return pgrp; -} diff --git a/05/musl-final/src/unistd/tcsetpgrp.c b/05/musl-final/src/unistd/tcsetpgrp.c deleted file mode 100644 index 67c38cb..0000000 --- a/05/musl-final/src/unistd/tcsetpgrp.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include -#include - -int tcsetpgrp(int fd, pid_t pgrp) -{ - int pgrp_int = pgrp; - return ioctl(fd, TIOCSPGRP, &pgrp_int); -} diff --git a/05/musl-final/src/unistd/truncate.c b/05/musl-final/src/unistd/truncate.c deleted file mode 100644 index 322349d..0000000 --- a/05/musl-final/src/unistd/truncate.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -int truncate(const char *path, off_t length) -{ - return syscall3(__NR_truncate, (long)path, SYSCALL_LL(length)); -} - -LFS64(truncate); diff --git a/05/musl-final/src/unistd/ttyname.c b/05/musl-final/src/unistd/ttyname.c deleted file mode 100644 index 0f3e114..0000000 --- a/05/musl-final/src/unistd/ttyname.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include -#include - -char *ttyname(int fd) -{ - static char buf[TTY_NAME_MAX]; - int result; - if ((result = ttyname_r(fd, buf, sizeof buf))) { - errno = result; - return NULL; - } - return buf; -} diff --git a/05/musl-final/src/unistd/ttyname_r.c b/05/musl-final/src/unistd/ttyname_r.c deleted file mode 100644 index f86fbd9..0000000 --- a/05/musl-final/src/unistd/ttyname_r.c +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include -#include -#include - -int ttyname_r(int fd, char *name, size_t size) -{ - char procname[sizeof "/proc/self/fd/" + 3*sizeof(int) + 2]; - ssize_t l; - - if (!isatty(fd)) return ENOTTY; - - snprintf(procname, sizeof procname, "/proc/self/fd/%d", fd); - l = readlink(procname, name, size); - - if (l < 0) return errno; - else if (l == size) return ERANGE; - else return 0; -} diff --git a/05/musl-final/src/unistd/ualarm.c b/05/musl-final/src/unistd/ualarm.c deleted file mode 100644 index be85303..0000000 --- a/05/musl-final/src/unistd/ualarm.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include "syscall.h" - -/* FIXME: ?? */ -useconds_t ualarm(useconds_t useconds, useconds_t interval) -{ - return -1; -} diff --git a/05/musl-final/src/unistd/unlink.c b/05/musl-final/src/unistd/unlink.c deleted file mode 100644 index fb57792..0000000 --- a/05/musl-final/src/unistd/unlink.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int unlink(const char *path) -{ - return __syscall_unlink(path); -} diff --git a/05/musl-final/src/unistd/unlinkat.c b/05/musl-final/src/unistd/unlinkat.c deleted file mode 100644 index 47fccc1..0000000 --- a/05/musl-final/src/unistd/unlinkat.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int unlinkat(int fd, const char *path, int flag) -{ - return syscall3(__NR_unlinkat, fd, (long)path, flag); -} diff --git a/05/musl-final/src/unistd/usleep.c b/05/musl-final/src/unistd/usleep.c deleted file mode 100644 index e386901..0000000 --- a/05/musl-final/src/unistd/usleep.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include - -int usleep(useconds_t useconds) -{ - struct timespec tv = { - .tv_sec = useconds/1000000, - .tv_nsec = (useconds%1000000)*1000 - }; - return nanosleep(&tv, &tv); -} diff --git a/05/musl-final/src/unistd/write.c b/05/musl-final/src/unistd/write.c deleted file mode 100644 index 426cfc5..0000000 --- a/05/musl-final/src/unistd/write.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -ssize_t write(int fd, const void *buf, size_t count) -{ - int r; - CANCELPT_BEGIN; - r = __syscall_write(fd, buf, count); - CANCELPT_END; - return r; -} diff --git a/05/musl-final/src/unistd/writev.c b/05/musl-final/src/unistd/writev.c deleted file mode 100644 index a6a118a..0000000 --- a/05/musl-final/src/unistd/writev.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -ssize_t writev(int fd, const struct iovec *iov, int count) -{ - ssize_t r; - CANCELPT_BEGIN; - r = syscall3(__NR_writev, fd, (long)iov, count); - CANCELPT_END; - return r; -} diff --git a/05/musl-final/tools/gen-musl-gcc.sh b/05/musl-final/tools/gen-musl-gcc.sh deleted file mode 100644 index 89f7f4d..0000000 --- a/05/musl-final/tools/gen-musl-gcc.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/sh - -printf '#!/bin/sh\n\nlibc_prefix="%s"\n' "$1" - -cat <<"EOF" -libc_lib=$libc_prefix/lib -libc_inc=$libc_prefix/include -libc_crt="$libc_lib/crt1.o" -libc_start="$libc_lib/crti.o" -libc_end="$libc_lib/crtn.o" - -gcc_inc=$libc_inc -libgcc="`gcc \"$@\" -print-file-name=libgcc.a`" - -gcc -wrapper sh,-c,' -x= ; y= ; z= ; s= ; for i ; do - [ "$z" ] || set -- ; z=1 - case "$i" in - -shared) s=1 ; set -- "$@" -shared ;; - -Lxxxxxx) x=1 ;; - -xxxxxx) x= ; [ "$s" ] || set -- "$@" "'"$libc_start"'" "'"$libc_crt"'" ;; - -l*) [ "$y" ] || set -- "$@" '"$libc_end"' ; set -- "$@" "$i" ; y=1 ;; - *) [ "$x" ] || set -- "$@" "$i" ;; - esac -done -exec "$0" "$@" -' -std=gnu99 -nostdinc -nostdlib \ - -isystem "$libc_inc" -isystem "$gcc_inc" \ - -Wl,-xxxxxx "$@" -L"$libc_lib" -lc "$libgcc" -Lxxxxxx -Wl,-nostdlib -EOF diff --git a/05/tcc-final-old/.gitignore b/05/tcc-final-old/.gitignore deleted file mode 100644 index 024af76..0000000 --- a/05/tcc-final-old/.gitignore +++ /dev/null @@ -1,55 +0,0 @@ -*~ -\#* -.#* -*.o -*.a -*.exe -*.dll -*.obj -*.pdb -*.lib -*.exp -*.log -*.bz2 -*.zip -.gdb_history -a.out -tcc_g -tcc -*-tcc -libtcc*.def - -config.texi -conftest* -tags -TAGS -tcc.1 -tcc.pod -tcc-doc.html -tcc-doc.info - -win32/doc -win32/libtcc -win32/lib/32 -win32/lib/64 -win32/include/float.h -win32/include/stdarg.h -win32/include/stdbool.h -win32/include/stddef.h -win32/include/varargs.h -win32/include/tcclib.h - -tests/tcctest[1234] -tests/tcctest.gcc -tests/*.out* -tests/*.ref -tests/*.txt -tests/*.gcc -tests/*-cc* -tests/*-tcc* -tests/libtcc_test -tests/asm-c-connect -tests/asm-c-connect-sep -tests/vla_test -tests/hello -tests/tests2/fred.txt diff --git a/05/tcc-final-old/COPYING b/05/tcc-final-old/COPYING deleted file mode 100644 index 223ede7..0000000 --- a/05/tcc-final-old/COPYING +++ /dev/null @@ -1,504 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 2.1, February 1999 - - Copyright (C) 1991, 1999 Free Software Foundation, Inc. - 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -[This is the first released version of the Lesser GPL. It also counts - as the successor of the GNU Library Public License, version 2, hence - the version number 2.1.] - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Lesser General Public License, applies to some -specially designated software packages--typically libraries--of the -Free Software Foundation and other authors who decide to use it. You -can use it too, but we suggest you first think carefully about whether -this license or the ordinary General Public License is the better -strategy to use in any particular case, based on the explanations below. - - When we speak of free software, we are referring to freedom of use, -not price. Our General Public Licenses are designed to make sure that -you have the freedom to distribute copies of free software (and charge -for this service if you wish); that you receive source code or can get -it if you want it; that you can change the software and use pieces of -it in new free programs; and that you are informed that you can do -these things. - - To protect your rights, we need to make restrictions that forbid -distributors to deny you these rights or to ask you to surrender these -rights. These restrictions translate to certain responsibilities for -you if you distribute copies of the library or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link other code with the library, you must provide -complete object files to the recipients, so that they can relink them -with the library after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - We protect your rights with a two-step method: (1) we copyright the -library, and (2) we offer you this license, which gives you legal -permission to copy, distribute and/or modify the library. - - To protect each distributor, we want to make it very clear that -there is no warranty for the free library. Also, if the library is -modified by someone else and passed on, the recipients should know -that what they have is not the original version, so that the original -author's reputation will not be affected by problems that might be -introduced by others. - - Finally, software patents pose a constant threat to the existence of -any free program. We wish to make sure that a company cannot -effectively restrict the users of a free program by obtaining a -restrictive license from a patent holder. Therefore, we insist that -any patent license obtained for a version of the library must be -consistent with the full freedom of use specified in this license. - - Most GNU software, including some libraries, is covered by the -ordinary GNU General Public License. This license, the GNU Lesser -General Public License, applies to certain designated libraries, and -is quite different from the ordinary General Public License. We use -this license for certain libraries in order to permit linking those -libraries into non-free programs. - - When a program is linked with a library, whether statically or using -a shared library, the combination of the two is legally speaking a -combined work, a derivative of the original library. The ordinary -General Public License therefore permits such linking only if the -entire combination fits its criteria of freedom. The Lesser General -Public License permits more lax criteria for linking other code with -the library. - - We call this license the "Lesser" General Public License because it -does Less to protect the user's freedom than the ordinary General -Public License. It also provides other free software developers Less -of an advantage over competing non-free programs. These disadvantages -are the reason we use the ordinary General Public License for many -libraries. However, the Lesser license provides advantages in certain -special circumstances. - - For example, on rare occasions, there may be a special need to -encourage the widest possible use of a certain library, so that it becomes -a de-facto standard. To achieve this, non-free programs must be -allowed to use the library. A more frequent case is that a free -library does the same job as widely used non-free libraries. In this -case, there is little to gain by limiting the free library to free -software only, so we use the Lesser General Public License. - - In other cases, permission to use a particular library in non-free -programs enables a greater number of people to use a large body of -free software. For example, permission to use the GNU C Library in -non-free programs enables many more people to use the whole GNU -operating system, as well as its variant, the GNU/Linux operating -system. - - Although the Lesser General Public License is Less protective of the -users' freedom, it does ensure that the user of a program that is -linked with the Library has the freedom and the wherewithal to run -that program using a modified version of the Library. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, whereas the latter must -be combined with the library in order to run. - - GNU LESSER GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library or other -program which contains a notice placed by the copyright holder or -other authorized party saying it may be distributed under the terms of -this Lesser General Public License (also called "this License"). -Each licensee is addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also combine or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (1) uses at run time a - copy of the library already present on the user's computer system, - rather than copying library functions into the executable, and (2) - will operate properly with a modified version of the library, if - the user installs one, as long as the modified version is - interface-compatible with the version that the work was made with. - - c) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - d) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - e) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the materials to be distributed need not include anything that is -normally distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties with -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Lesser General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Libraries - - If you develop a new library, and you want it to be of the greatest -possible use to the public, we recommend making it free software that -everyone can redistribute and change. You can do so by permitting -redistribution under these terms (or, alternatively, under the terms of the -ordinary General Public License). - - To apply these terms, attach the following notices to the library. It is -safest to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least the -"copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -Also add information on how to contact you by electronic and paper mail. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the library, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the - library `Frob' (a library for tweaking knobs) written by James Random Hacker. - - , 1 April 1990 - Ty Coon, President of Vice - -That's all there is to it! - - diff --git a/05/tcc-final-old/Changelog b/05/tcc-final-old/Changelog deleted file mode 100644 index 17f5bde..0000000 --- a/05/tcc-final-old/Changelog +++ /dev/null @@ -1,439 +0,0 @@ -Version 0.9.27: - -User interface: -- -x[c|a|n] filetype option (Sergey Korshunoff) -- -P[1], -dD, -dM preprocessor options (Sergey Korshunoff) -- -Wl,-(no-)whole-archive linker option (Reuben Thomas) -- -mms-bitfields option (David Mertens) -- -include option (Michael Matz) -- -mno-sse on x86-64 disables use of SSE instructions -- @listfile support (Vlad Vissoultchev) -- tcc -ar/-impdef - formerly tiny_xxx tools integrated (grischka) -- CPATH, C_INCLUDE_PATH and LIBRARY_PATH environment variables support - (Andrew Aladjev, Urs Janssen) - -Platforms: -- new AARCH64 (arm64) target (Edmund Grimley Evans) -- vastly improved support for ARM hard float calling convention - (Thomas Preud'homme, Daniel Glöckner) -- provide a runtime library for ARM (Thomas Preud'homme) -- many x86_64 ABI fixes incl. XMM register passing and tests (James Lyon) -- ABI tests with native compiler using libtcc (James Lyon) -- UNICODE startup code supports wmain and wWinMain (YX Hao) -- shared libraries for x86_64 (Michael Matz) -- Bootstrap native Windows 32/64 compiler using Cygwin+gcc (Christian Jullien) - -Features: -- VLA (variable length array) improved (James Lyon, Pip Cet) -- import functions by ordinal in .def files on windows (YX Hao) -- x86/x86_64 assembler much improved (Michael Matz) -- simple dead code suppression (Edmund Grimley Evans, Michael Matz, grischka) -- implement round/fmin/fmax etc. math on windows (Avi Halachmi) -- #pragma once support (Sergey Korshunoff, Vlad Vissoultchev, ...) -- switch/case code improved (Zdenek Pavlas) -- ~15% faster by TinyAlloc fast memory allocator (Vlad Vissoultchev) -- standard conforming (and GCC compatible) struct initialization - (Michael Matz) -- bit-field layout made compatible with GCC (Michael Matz) -- UTF8 in string literals supported (Zdenek Pavlas) -_ _Generic(...) supported (Matthias Gatto) - -Licensing: -- TinyCC partly relicensed to MIT license (See RELICENSING file). - -version 0.9.26: - -User interface: -- -MD/-MF (automatically generate dependencies for make) -- -pthread option (same as -D_REENTRANT -lpthread) (Henry Kroll III) -- -m32/-m64 to re-exec cross compiler (Henry Kroll III) -- -Wl, Mimic all GNU -option forms supported by ld (Kirill Smelkov) -- new LIBTCCAPI tcc_set_options() (grischka) - -Platforms: -- Many improvements for x86-64 target (Shinichiro Hamaji, Michael Matz, grischka) -- x86-64 assembler (Frederic Feret) -- Many improvements for ARM target (Daniel Glöckner, Thomas Preud'homme) -- Support WinCE PE ARM (Timo VJ Lahde) -- Support ARM hardfloat calling convention (Thomas Preud'homme) -- Support SELinux (Security-Enhanced Linux) (Henry Kroll III) -- Support Debian GNU/kFreeBSD kernels (Pierre Chifflier) -- Support GNU/Hurd kernels (Thomas Preud'homme) -- Support OSX (tcc -run only) (Milutin Jovanovic) -- Support multiarch configuration (Thomas Preud'homme) -- Support out-of-tree build (Akim Demaille) - -Features: -- C99 variable length arrays (Thomas Preud'homme & Joe Soroka) -- Asm labels for variables and functions (Thomas Preud'homme) -- STT_GNU_IFUNC (Indirect functions as externals) (Thomas Preud'homme) -- More tests (tests2) (Milutin Jovanovic) - -version 0.9.25: - -- first support for x86-64 target (Shinichiro Hamaji) -- support µClibc -- split tcc.c into tcc.h libtcc.c tccpp.c tccgen.c tcc.c -- improved preprocess output with linenumbers and spaces preserved -- tcc_relocate now copies code into user buffer -- fix bitfields with non-int types and in unions -- improve ARM cross-compiling (Daniel Glöckner) -- link stabstr sections from multiple objects -- better (still limited) support for multiple TCCStates - -version 0.9.24: - -- added verbosity levels -v, -vv, -vvv -- Accept standard input as an inputstream (Hanzac Chen) -- Support c89 compilers other than gcc (Hanzac Chen) -- -soname linker option (Marc Andre Tanner) -- Just warn about unknown directives, ignore quotes in #error/#warning -- Define __STDC_VERSION__=199901L (477) -- Switch to newer tccpe.c (includes support for resources) -- Handle backslashes within #include/#error/#warning -- Import changesets (part 4) 428,457,460,467: defines for openbsd etc. -- Use _WIN32 for a windows hosted tcc and define it for the PE target, - otherwise define __unix / __linux (Detlef Riekenberg) -- Import changesets (part 3) 409,410: ARM EABI by Daniel Glöckner -- Some in-between fixes: - TCC -E no longer hangs with macro calls involving newlines. - (next_nomacro1 now advances the read-pointer with TOK_LINEFEED) - Global cast (int g_i = 1LL;) no longer crashes tcc. - (nocode_wanted is initially 1, and only 0 for gen_function) - On win32 now tcc.exe finds 'include' & 'lib' even if itself is in 'bin'. - (new function w32_tcc_lib_path removes 'bin' if detected) - Added quick build batch file for mingw (win32/build-tcc.bat) - Last added case label optimization (455) produced wrong code. Reverted. - -- Import more changesets from Rob Landley's fork (part 2): - 487: Handle long long constants in gen_opic() (Rob Landley) - 484: Handle parentheses within __attribute__((...)) (Rob Landley) - 480: Remove a goto in decl_initializer_alloc (Rob Landley) - 475: Fix dereferences in inline assembly output (Joshua Phillips) - 474: Cast ptrs to ints of different sizes correctly (Joshua Phillips) - 473: Fix size of structs with empty array member (Joshua Phillips) - 470: No warning for && and || with mixed pointers/integers (Rob Landley) - 469: Fix symbol visibility problems in the linker (Vincent Pit) - 468: Allow && and || involving pointer arguments (Rob Landley) - 455: Optimize case labels with no code in between (Zdenek Pavlas) - 450: Implement alloca for x86 (grischka) - 415: Parse unicode escape sequences (Axel Liljencrantz) - 407: Add a simple va_copy() in stdarg.h (Hasso Tepper) - 400: Allow typedef names as symbols (Dave Dodge) - -- Import some changesets from Rob Landley's fork (part 1): - 462: Use LGPL with bcheck.c and il-gen.c - 458: Fix global compound literals (in unary: case '&':) (Andrew Johnson) - 456: Use return code from tcc_output_file in main() (Michael Somos) - 442: Fix indirections with function pointers (***fn)() (grischka) - 441: Fix LL left shift in libtcc1.c:__shldi3 (grischka) - 440: Pass structures and function ptrs through ?: (grischka) - 439: Keep rvalue in bit assignment (bit2 = bit1 = x) (grischka) - 438: Degrade nonportable pointer assignment to warning (grischka) - 437: Call 'saveregs()' before jumping with logical and/or/not (grischka) - 435: Put local static variables into global memory (grischka) - 432/434: Cast double and ptr to bool (grischka) - 420: Zero pad x87 tenbyte long doubles (Felix Nawothnig) - 417: Make 'sizeof' unsigned (Rob Landley) - 397: Fix save_reg for longlongs (Daniel Glöckner) - 396: Fix "invalid relocation entry" problem on ubuntu - (Bernhard Fischer) - -- ignore AS_NEEDED ld command -- mark executable sections as executable when running in memory -- added support for win32 wchar_t (Filip Navara) -- segment override prefix support (Filip Navara) -- normalized slashes in paths (Filip Navara) -- windows style fastcall (Filip Navara) -- support for empty input register section in asm (Filip Navara) -- anonymous union/struct support (Filip Navara) -- fixed parsing of function parameters -- workaround for function pointers in conditional expressions (Dave Dodge) -- initial '-E' option support to use the C preprocessor alone -- discard type qualifiers when comparing function parameters (Dave Dodge) -- Bug fix: A long long value used as a test expression ignores the - upper 32 bits at runtime (Dave Dodge) -- fixed multiple concatenation of PPNUM tokens (initial patch by Dave Dodge) -- fixed multiple typedef specifiers handling -- fixed sign extension in some type conversions (Dave Dodge) - -version 0.9.23: - -- initial PE executable format for windows version (grischka) -- '#pragma pack' support (grischka) -- '#include_next' support (Bernhard Fischer) -- ignore '-pipe' option -- added -f[no-]leading-underscore -- preprocessor function macro parsing fix (grischka) - -version 0.9.22: - -- simple memory optimisations: kernel compilation is 30% faster -- linker symbol definitions fixes -- gcc 3.4 fixes -- fixed value stack full error -- 'packed' attribute support for variables and structure fields -- ignore 'const' and 'volatile' in function prototypes -- allow '_Bool' in bit fields - -version 0.9.21: - -- ARM target support (Daniel Glöckner) -- added '-funsigned-char, '-fsigned-char' and - '-Wimplicit-function-declaration' -- fixed assignment of const struct in struct -- line comment fix (reported by Bertram Felgenhauer) -- initial TMS320C67xx target support (TK) -- win32 configure -- regparm() attribute -- many built-in assembler fixes -- added '.org', '.fill' and '.previous' assembler directives -- '-fno-common' option -- '-Ttext' linker option -- section alignment fixes -- bit fields fixes -- do not generate code for unused inline functions -- '-oformat' linker option. -- added 'binary' output format. - -version 0.9.20: - -- added '-w' option -- added '.gnu.linkonce' ELF sections support -- fixed libc linking when running in memory (avoid 'stat' function - errors). -- extended '-run' option to be able to give several arguments to a C - script. - -version 0.9.19: - -- "alacarte" linking (Dave Long) -- simpler function call -- more strict type checks -- added 'const' and 'volatile' support and associated warnings -- added -Werror, -Wunsupported, -Wwrite-strings, -Wall. -- added __builtin_types_compatible_p() and __builtin_constant_p() -- chars support in assembler (Dave Long) -- .string, .globl, .section, .text, .data and .bss asm directive - support (Dave Long) -- man page generated from tcc-doc.texi -- fixed macro argument substitution -- fixed zero argument macro parsing -- changed license to LGPL -- added -rdynamic option support - -version 0.9.18: - -- header fix (time.h) -- fixed inline asm without operand case -- fixed 'default:' or 'case x:' with '}' after (incorrect C construct accepted - by gcc) -- added 'A' inline asm constraint. - -version 0.9.17: - -- PLT generation fix -- tcc doc fixes (Peter Lund) -- struct parse fix (signaled by Pedro A. Aranda Gutierrez) -- better _Bool lvalue support (signaled by Alex Measday) -- function parameters must be converted to pointers (signaled by Neil Brown) -- sanitized string and character constant parsing -- fixed comment parse (signaled by Damian M Gryski) -- fixed macro function bug (signaled by Philippe Ribet) -- added configure (initial patch by Mitchell N Charity) -- added '-run' and '-v' options (initial patch by vlindos) -- added real date report in __DATE__ and __TIME__ macros - -version 0.9.16: - -- added assembler language support -- added GCC inline asm() support -- fixed multiple variable definitions : uninitialized variables are - created as COMMON symbols. -- optimized macro processing -- added GCC statement expressions support -- added GCC local labels support -- fixed array declaration in old style function parameters -- support casts in static structure initializations -- added various __xxx[__] keywords for GCC compatibility -- ignore __extension__ GCC in an expression or in a type (still not perfect) -- added '? :' GCC extension support - -version 0.9.15: - -- compilation fixes for glibc 2.2, gcc 2.95.3 and gcc 3.2. -- FreeBSD compile fixes. Makefile patches still missing (Carl Drougge). -- fixed file type guessing if '.' is in the path. -- fixed tcc_compile_string() -- add a dummy page in ELF files to fix RX/RW accesses (pageexec at - freemail dot hu). - -version 0.9.14: - -- added #warning. error message if invalid preprocessing directive. -- added CType structure to ease typing (faster parse). -- suppressed secondary hash tables (faster parse). -- rewrote parser by optimizing common cases (faster parse). -- fixed signed long long comparisons. -- fixed 'int a(), b();' declaration case. -- fixed structure init without '{}'. -- correct alignment support in structures. -- empty structures support. -- gcc testsuite now supported. -- output only warning if implicit integer/pointer conversions. -- added static bitfield init. - -version 0.9.13: - -- correct preprocessing token pasting (## operator) in all cases (added - preprocessing number token). -- fixed long long register spill. -- fixed signed long long '>>'. -- removed memory leaks. -- better error handling : processing can continue on link errors. A - custom callback can be added to display error messages. Most - errors do not call exit() now. -- ignore -O, -W, -m and -f options -- added old style function declarations -- added GCC __alignof__ support. -- added GCC typeof support. -- added GCC computed gotos support. -- added stack backtrace in runtime error message. Improved runtime - error position display. - -version 0.9.12: - -- more fixes for || and && handling. -- improved '? :' type handling. -- fixed bound checking generation with structures -- force '#endif' to be in same file as matching '#if' -- #include file optimization with '#ifndef #endif' construct detection -- macro handling optimization -- added tcc_relocate() and tcc_get_symbol() in libtcc. - -version 0.9.11: - -- stdarg.h fix for double type (thanks to Philippe Ribet). -- correct white space characters and added MSDOS newline support. -- fixed invalid implicit function call type declaration. -- special macros such as __LINE__ are defined if tested with defined(). -- fixed '!' operator with relocated address. -- added symbol + offset relocation (fixes some static variable initializers) -- '-l' option can be specified anywhere. '-c' option yields default - output name. added '-r' option for relocatable output. -- fixed '\nnn' octal parsing. -- fixed local extern variables declarations. - -version 0.9.10: - -- fixed lvalue type when saved in local stack. -- fixed '#include' syntax when using macros. -- fixed '#line' bug. -- removed size limit on strings. Unified string constants handling - with variable declarations. -- added correct support for '\xX' in wchar_t strings. -- added support for bound checking in generated executables -- fixed -I include order. -- fixed incorrect function displayed in runtime error. - -version 0.9.9: - -- fixed preprocessor expression parsing for #if/#elif. -- relocated debug info (.stab section). -- relocated bounds info (.bounds section). -- fixed cast to char of char constants ('\377' is -1 instead of 255) -- fixed implicit cast for unary plus. -- strings and '__func__' have now 'char[]' type instead of 'char *' - (fixes sizeof() return value). -- added __start_xxx and __stop_xxx symbols in linker. -- better DLL creation support (option -shared begins to work). -- ELF sections and hash tables are resized dynamically. -- executables and DLLs are stripped by default. - -version 0.9.8: - -- First version of full ELF linking support (generate objects, static - executable, dynamic executable, dynamic libraries). Dynamic library - support is not finished (need PIC support in compiler and some - patches in symbol exporting). -- First version of ELF loader for object (.o) and archive (.a) files. -- Support of simple GNU ld scripts (GROUP and FILE commands) -- Separated runtime library and bound check code from TCC (smaller - compiler core). -- fixed register reload in float compare. -- fixed implicit char/short to int casting. -- allow array type for address of ('&') operator. -- fixed unused || or && result. -- added GCC style variadic macro support. -- optimized bound checking code for array access. -- tcc includes are now in $(prefix)/lib/tcc/include. -- more command line options - more consistent handling of multiple - input files. -- added tcc man page (thanks to Cyril Bouthors). -- uClibc Makefile update -- converted documentation to texinfo format. -- added developper's guide in documentation. - -version 0.9.7: - -- added library API for easy dynamic compilation (see libtcc.h - first - draft). -- fixed long long register spill bug. -- fixed '? :' register spill bug. - -version 0.9.6: - -- added floating point constant propagation (fixes negative floating - point constants bug). - -version 0.9.5: - - - uClibc patches (submitted by Alfonso Martone). - - error reporting fix - - added CONFIG_TCC_BCHECK to get smaller code if needed. - -version 0.9.4: - - - windows port (currently cannot use -g, -b and dll functions). - - faster and simpler I/O handling. - - '-D' option works in all cases. - - preprocessor fixes (#elif and empty macro args) - - floating point fixes - - first code for CIL generation (does not work yet) - -version 0.9.3: - - - better and smaller code generator. - - full ISOC99 64 bit 'long long' support. - - full 32 bit 'float', 64 bit 'double' and 96 bit 'long double' support. - - added '-U' option. - - added assembly sections support. - - even faster startup time by mmaping sections instead of mallocing them. - - added GNUC __attribute__ keyword support (currently supports - 'section' and 'aligned' attributes). - - added ELF file output (only usable for debugging now) - - added debug symbol generation (STAB format). - - added integrated runtime error analysis ('-g' option: print clear - run time error messages instead of "Segmentation fault"). - - added first version of tiny memory and bound checker ('-b' option). - -version 0.9.2: - - - even faster parsing. - - various syntax parsing fixes. - - fixed external relocation handling for variables or functions pointers. - - better function pointers type handling. - - can compile multiple files (-i option). - - ANSI C bit fields are supported. - - beginning of float/double/long double support. - - beginning of long long support. - -version 0.9.1: - - - full ISOC99 initializers handling. - - compound literals. - - structures handle in assignments and as function param or return value. - - wide chars and strings. - - macro bug fix - -version 0.9: - - initial version. diff --git a/05/tcc-final-old/CodingStyle b/05/tcc-final-old/CodingStyle deleted file mode 100644 index 93d1324..0000000 --- a/05/tcc-final-old/CodingStyle +++ /dev/null @@ -1,71 +0,0 @@ - -In general, use the same coding style as the surrounding code. - -However, do not make any unnecessary changes as that complicates -the VCS (git) history and makes it harder to merge patches. So -do not modify code just to make it conform to a coding style. - - Indentation - -Turn on a "fill tabs with spaces" option in your editor. - -Remove tabs and trailing spaces from any lines that are modified. - -Note that some files are indented with 2 spaces (when they -have large indentation) while most are indented with 4 spaces. - - Language - -TCC is mostly implemented in C90. Do not use any non-C90 features -that are not already in use. - -Non-C90 features currently in use, as revealed by -./configure --extra-cflags="-std=c90 -Wpedantic": - -- long long (including "LL" constants) -- inline -- very long string constants -- assignment between function pointer and 'void *' -- "//" comments -- empty macro arguments (DEF_ASMTEST in i386-tok.h) -- unnamed struct and union fields (in struct Sym), a C11 feature - - Testing - -A simple "make test" is sufficient for some simple changes. However, -before committing a change consider performing some of the following -additional tests: - -- Build and run "make test" on several architectures. - -- Build with ./configure --enable-cross. - -- If the generation of relocations has been changed, try compiling - with TCC and linking with GCC/Clang. If the linker has been - modified, try compiling with GCC/Clang and linking with TCC. - -- Test with ASan/UBSan to detect memory corruption and undefined behaviour: - -make clean -./configure -make -make test -cp libtcc.a libtcc.a.hide - -make clean -./configure --extra-cflags="-fsanitize=address,undefined -g" -make -cp libtcc.a.hide libtcc.a -make test - -- Test with Valgrind to detect some uses of uninitialised values: - -make clean -./configure -make -# On Intel, because Valgrind does floating-point arithmetic differently: -( cd tests && gcc -I.. tcctest.c && valgrind -q ./a.out > test.ref ) -make test TCC="valgrind -q --leak-check=full `pwd`/tcc -B`pwd` -I`pwd`" - - (Because of how VLAs are implemented, invalid reads are expected - with 79_vla_continue.) diff --git a/05/tcc-final-old/Makefile b/05/tcc-final-old/Makefile deleted file mode 100644 index 3ae466f..0000000 --- a/05/tcc-final-old/Makefile +++ /dev/null @@ -1,403 +0,0 @@ -# -------------------------------------------------------------------------- -# -# Tiny C Compiler Makefile -# - -ifndef TOP - TOP = . - INCLUDED = no -endif - -include $(TOP)/config.mak - -ifeq (-$(CC)-$(GCC_MAJOR)-$(findstring $(GCC_MINOR),56789)-,-gcc-4--) - CFLAGS += -D_FORTIFY_SOURCE=0 -endif - -LIBTCC = libtcc.a -LIBTCC1 = libtcc1.a -LINK_LIBTCC = -LIBS = -CFLAGS += -I$(TOP) -CFLAGS += $(CPPFLAGS) -VPATH = $(TOPSRC) - -ifdef CONFIG_WIN32 - ifneq ($(CONFIG_static),yes) - LIBTCC = libtcc$(DLLSUF) - LIBTCCDEF = libtcc.def - endif - CFGWIN = -win - NATIVE_TARGET = $(ARCH)-win$(if $(findstring arm,$(ARCH)),ce,32) -else - LIBS=-lm - ifneq ($(CONFIG_ldl),no) - LIBS+=-ldl - endif - # make libtcc as static or dynamic library? - ifeq ($(CONFIG_static),no) - LIBTCC=libtcc$(DLLSUF) - export LD_LIBRARY_PATH := $(CURDIR)/$(TOP) - ifneq ($(CONFIG_rpath),no) - LINK_LIBTCC += -Wl,-rpath,"$(libdir)" - endif - endif - CFGWIN =-unx - NATIVE_TARGET = $(ARCH) - ifdef CONFIG_OSX - NATIVE_TARGET = $(ARCH)-osx - LDFLAGS += -flat_namespace -undefined warning - export MACOSX_DEPLOYMENT_TARGET := 10.2 - endif -endif - -# run local version of tcc with local libraries and includes -TCCFLAGS-unx = -B$(TOP) -I$(TOPSRC)/include -I$(TOPSRC) -I$(TOP) -TCCFLAGS-win = -B$(TOPSRC)/win32 -I$(TOPSRC)/include -I$(TOPSRC) -I$(TOP) -L$(TOP) -TCCFLAGS = $(TCCFLAGS$(CFGWIN)) -TCC = $(TOP)/tcc$(EXESUF) $(TCCFLAGS) -ifdef CONFIG_OSX - TCCFLAGS += -D_ANSI_SOURCE -endif - -CFLAGS_P = $(CFLAGS) -pg -static -DCONFIG_TCC_STATIC -DTCC_PROFILE -LIBS_P = $(LIBS) -LDFLAGS_P = $(LDFLAGS) - -CONFIG_$(ARCH) = yes -NATIVE_DEFINES_$(CONFIG_i386) += -DTCC_TARGET_I386 -NATIVE_DEFINES_$(CONFIG_x86_64) += -DTCC_TARGET_X86_64 -NATIVE_DEFINES_$(CONFIG_WIN32) += -DTCC_TARGET_PE -NATIVE_DEFINES_$(CONFIG_OSX) += -DTCC_TARGET_MACHO -NATIVE_DEFINES_$(CONFIG_uClibc) += -DTCC_UCLIBC -NATIVE_DEFINES_$(CONFIG_musl) += -DTCC_MUSL -NATIVE_DEFINES_$(CONFIG_libgcc) += -DCONFIG_USE_LIBGCC -NATIVE_DEFINES_$(CONFIG_selinux) += -DHAVE_SELINUX -NATIVE_DEFINES_$(CONFIG_arm) += -DTCC_TARGET_ARM -NATIVE_DEFINES_$(CONFIG_arm_eabihf) += -DTCC_ARM_EABI -DTCC_ARM_HARDFLOAT -NATIVE_DEFINES_$(CONFIG_arm_eabi) += -DTCC_ARM_EABI -NATIVE_DEFINES_$(CONFIG_arm_vfp) += -DTCC_ARM_VFP -NATIVE_DEFINES_$(CONFIG_arm64) += -DTCC_TARGET_ARM64 -NATIVE_DEFINES += $(NATIVE_DEFINES_yes) - -ifeq ($(INCLUDED),no) -# -------------------------------------------------------------------------- -# running top Makefile - -PROGS = tcc$(EXESUF) -TCCLIBS = $(LIBTCC1) $(LIBTCC) $(LIBTCCDEF) -TCCDOCS = tcc.1 tcc-doc.html tcc-doc.info - -all: $(PROGS) $(TCCLIBS) $(TCCDOCS) - -# cross compiler targets to build -TCC_X = i386 x86_64 i386-win32 x86_64-win32 x86_64-osx arm arm64 arm-wince c67 -# TCC_X += arm-fpa arm-fpa-ld arm-vfp arm-eabi - -# cross libtcc1.a targets to build -LIBTCC1_X = i386 x86_64 i386-win32 x86_64-win32 x86_64-osx arm arm64 arm-wince - -PROGS_CROSS = $(foreach X,$(TCC_X),$X-tcc$(EXESUF)) -LIBTCC1_CROSS = $(foreach X,$(LIBTCC1_X),$X-libtcc1.a) - -# build cross compilers & libs -cross: $(LIBTCC1_CROSS) $(PROGS_CROSS) - -# build specific cross compiler & lib -cross-%: %-tcc$(EXESUF) %-libtcc1.a ; - -install: ; @$(MAKE) --no-print-directory install$(CFGWIN) -install-strip: ; @$(MAKE) --no-print-directory install$(CFGWIN) CONFIG_strip=yes -uninstall: ; @$(MAKE) --no-print-directory uninstall$(CFGWIN) - -ifdef CONFIG_cross -all : cross -endif - -# -------------------------------------------- - -T = $(or $(CROSS_TARGET),$(NATIVE_TARGET),unknown) -X = $(if $(CROSS_TARGET),$(CROSS_TARGET)-) - -DEF-i386 = -DTCC_TARGET_I386 -DEF-x86_64 = -DTCC_TARGET_X86_64 -DEF-i386-win32 = -DTCC_TARGET_PE -DTCC_TARGET_I386 -DEF-x86_64-win32= -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -DEF-x86_64-osx = -DTCC_TARGET_MACHO -DTCC_TARGET_X86_64 -DEF-arm-wince = -DTCC_TARGET_PE -DTCC_TARGET_ARM -DTCC_ARM_EABI -DTCC_ARM_VFP -DTCC_ARM_HARDFLOAT -DEF-arm64 = -DTCC_TARGET_ARM64 -DEF-c67 = -DTCC_TARGET_C67 -w # disable warnigs -DEF-arm-fpa = -DTCC_TARGET_ARM -DEF-arm-fpa-ld = -DTCC_TARGET_ARM -DLDOUBLE_SIZE=12 -DEF-arm-vfp = -DTCC_TARGET_ARM -DTCC_ARM_VFP -DEF-arm-eabi = -DTCC_TARGET_ARM -DTCC_ARM_VFP -DTCC_ARM_EABI -DEF-arm-eabihf = -DTCC_TARGET_ARM -DTCC_ARM_VFP -DTCC_ARM_EABI -DTCC_ARM_HARDFLOAT -DEF-arm = $(DEF-arm-eabihf) -DEF-$(NATIVE_TARGET) = $(NATIVE_DEFINES) - -DEFINES += $(DEF-$T) $(DEF-all) -DEFINES += $(if $(ROOT-$T),-DCONFIG_SYSROOT="\"$(ROOT-$T)\"") -DEFINES += $(if $(CRT-$T),-DCONFIG_TCC_CRTPREFIX="\"$(CRT-$T)\"") -DEFINES += $(if $(LIB-$T),-DCONFIG_TCC_LIBPATHS="\"$(LIB-$T)\"") -DEFINES += $(if $(INC-$T),-DCONFIG_TCC_SYSINCLUDEPATHS="\"$(INC-$T)\"") -DEFINES += $(DEF-$(or $(findstring win,$T),unx)) - -ifneq ($(X),) -ifeq ($(CONFIG_WIN32),yes) -DEF-win += -DTCC_LIBTCC1="\"$(X)libtcc1.a\"" -DEF-unx += -DTCC_LIBTCC1="\"lib/$(X)libtcc1.a\"" -else -DEF-all += -DTCC_LIBTCC1="\"$(X)libtcc1.a\"" -DEF-win += -DCONFIG_TCCDIR="\"$(tccdir)/win32\"" -endif -endif - -# include custom configuration (see make help) --include config-extra.mak - -CORE_FILES = tcc.c tcctools.c libtcc.c tccpp.c tccgen.c tccelf.c tccasm.c tccrun.c -CORE_FILES += tcc.h config.h libtcc.h tcctok.h -i386_FILES = $(CORE_FILES) i386-gen.c i386-link.c i386-asm.c i386-asm.h i386-tok.h -i386-win32_FILES = $(i386_FILES) tccpe.c -x86_64_FILES = $(CORE_FILES) x86_64-gen.c x86_64-link.c i386-asm.c x86_64-asm.h -x86_64-win32_FILES = $(x86_64_FILES) tccpe.c -x86_64-osx_FILES = $(x86_64_FILES) -arm_FILES = $(CORE_FILES) arm-gen.c arm-link.c arm-asm.c -arm-wince_FILES = $(arm_FILES) tccpe.c -arm64_FILES = $(CORE_FILES) arm64-gen.c arm64-link.c -c67_FILES = $(CORE_FILES) c67-gen.c c67-link.c tcccoff.c - -# libtcc sources -LIBTCC_SRC = $(filter-out tcc.c tcctools.c,$(filter %.c,$($T_FILES))) - -ifeq ($(ONE_SOURCE),yes) -LIBTCC_OBJ = $(X)libtcc.o -LIBTCC_INC = $($T_FILES) -TCC_FILES = $(X)tcc.o -tcc.o : DEFINES += -DONE_SOURCE=0 -else -LIBTCC_OBJ = $(patsubst %.c,$(X)%.o,$(LIBTCC_SRC)) -LIBTCC_INC = $(filter %.h %-gen.c %-link.c,$($T_FILES)) -TCC_FILES = $(X)tcc.o $(LIBTCC_OBJ) -$(TCC_FILES) : DEFINES += -DONE_SOURCE=0 -endif - -# target specific object rule -$(X)%.o : %.c $(LIBTCC_INC) - $(CC) -o $@ -c $< $(DEFINES) $(CFLAGS) - -# additional dependencies -$(X)tcc.o : tcctools.c - -# Host Tiny C Compiler -tcc$(EXESUF): tcc.o $(LIBTCC) - $(CC) -o $@ $^ $(LIBS) $(LDFLAGS) $(LINK_LIBTCC) - -# Cross Tiny C Compilers -%-tcc$(EXESUF): FORCE - @$(MAKE) --no-print-directory $@ CROSS_TARGET=$* ONE_SOURCE=$(or $(ONE_SOURCE),yes) - -$(CROSS_TARGET)-tcc$(EXESUF): $(TCC_FILES) - $(CC) -o $@ $^ $(LIBS) $(LDFLAGS) - -# profiling version -tcc_p$(EXESUF): $($T_FILES) - $(CC) -o $@ $< $(DEFINES) $(CFLAGS_P) $(LIBS_P) $(LDFLAGS_P) - -# static libtcc library -libtcc.a: $(LIBTCC_OBJ) - $(AR) rcs $@ $^ - -# dynamic libtcc library -libtcc.so: $(LIBTCC_OBJ) - $(CC) -shared -Wl,-soname,$@ -o $@ $^ $(LDFLAGS) - -libtcc.so: CFLAGS+=-fPIC -libtcc.so: LDFLAGS+=-fPIC - -# windows dynamic libtcc library -libtcc.dll : $(LIBTCC_OBJ) - $(CC) -shared -o $@ $^ $(LDFLAGS) -libtcc.dll : DEFINES += -DLIBTCC_AS_DLL - -# import file for windows libtcc.dll -libtcc.def : libtcc.dll tcc$(EXESUF) - $(XTCC) -impdef $< -o $@ -XTCC ?= ./tcc$(EXESUF) - -# TinyCC runtime libraries -libtcc1.a : tcc$(EXESUF) FORCE - @$(MAKE) -C lib DEFINES='$(DEF-$T)' - -# Cross libtcc1.a -%-libtcc1.a : %-tcc$(EXESUF) FORCE - @$(MAKE) -C lib DEFINES='$(DEF-$*)' CROSS_TARGET=$* - -.PRECIOUS: %-libtcc1.a -FORCE: - -# -------------------------------------------------------------------------- -# documentation and man page -tcc-doc.html: tcc-doc.texi - makeinfo --no-split --html --number-sections -o $@ $< || true - -tcc.1: tcc-doc.texi - $(TOPSRC)/texi2pod.pl $< tcc.pod \ - && pod2man --section=1 --center="Tiny C Compiler" --release="$(VERSION)" tcc.pod >tmp.1 \ - && mv tmp.1 $@ || rm -f tmp.1 - -tcc-doc.info: tcc-doc.texi - makeinfo $< || true - -# -------------------------------------------------------------------------- -# install - -INSTALL = install -m644 -INSTALLBIN = install -m755 $(STRIP_$(CONFIG_strip)) -STRIP_yes = -s - -LIBTCC1_W = $(filter %-win32-libtcc1.a %-wince-libtcc1.a,$(LIBTCC1_CROSS)) -LIBTCC1_U = $(filter-out $(LIBTCC1_W),$(LIBTCC1_CROSS)) -IB = $(if $1,mkdir -p $2 && $(INSTALLBIN) $1 $2) -IBw = $(call IB,$(wildcard $1),$2) -IF = $(if $1,mkdir -p $2 && $(INSTALL) $1 $2) -IFw = $(call IF,$(wildcard $1),$2) -IR = mkdir -p $2 && cp -r $1/. $2 - -# install progs & libs -install-unx: - $(call IBw,$(PROGS) $(PROGS_CROSS),"$(bindir)") - $(call IFw,$(LIBTCC1) $(LIBTCC1_U),"$(tccdir)") - $(call IF,$(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h,"$(tccdir)/include") - $(call $(if $(findstring .so,$(LIBTCC)),IBw,IFw),$(LIBTCC),"$(libdir)") - $(call IF,$(TOPSRC)/libtcc.h,"$(includedir)") - $(call IFw,tcc.1,"$(mandir)/man1") - $(call IFw,tcc-doc.info,"$(infodir)") - $(call IFw,tcc-doc.html,"$(docdir)") -ifneq "$(wildcard $(LIBTCC1_W))" "" - $(call IFw,$(TOPSRC)/win32/lib/*.def $(LIBTCC1_W),"$(tccdir)/win32/lib") - $(call IR,$(TOPSRC)/win32/include,"$(tccdir)/win32/include") - $(call IF,$(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h,"$(tccdir)/win32/include") -endif - -# uninstall -uninstall-unx: - @rm -fv $(foreach P,$(PROGS) $(PROGS_CROSS),"$(bindir)/$P") - @rm -fv "$(libdir)/libtcc.a" "$(libdir)/libtcc.so" "$(includedir)/libtcc.h" - @rm -fv "$(mandir)/man1/tcc.1" "$(infodir)/tcc-doc.info" - @rm -fv "$(docdir)/tcc-doc.html" - rm -r "$(tccdir)" - -# install progs & libs on windows -install-win: - $(call IBw,$(PROGS) $(PROGS_CROSS) $(subst libtcc.a,,$(LIBTCC)),"$(bindir)") - $(call IF,$(TOPSRC)/win32/lib/*.def,"$(tccdir)/lib") - $(call IFw,libtcc1.a $(LIBTCC1_W),"$(tccdir)/lib") - $(call IF,$(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h,"$(tccdir)/include") - $(call IR,$(TOPSRC)/win32/include,"$(tccdir)/include") - $(call IR,$(TOPSRC)/win32/examples,"$(tccdir)/examples") - $(call IF,$(TOPSRC)/tests/libtcc_test.c,"$(tccdir)/examples") - $(call IFw,$(TOPSRC)/libtcc.h $(subst .dll,.def,$(LIBTCC)),"$(libdir)") - $(call IFw,$(TOPSRC)/win32/tcc-win32.txt tcc-doc.html,"$(docdir)") -ifneq "$(wildcard $(LIBTCC1_U))" "" - $(call IFw,$(LIBTCC1_U),"$(tccdir)/lib") - $(call IF,$(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h,"$(tccdir)/lib/include") -endif - -# the msys-git shell works to configure && make except it does not have install -ifeq "$(and $(CONFIG_WIN32),$(shell which install >/dev/null 2>&1 || echo no))" "no" -install-win : INSTALL = cp -install-win : INSTALLBIN = cp -endif - -# uninstall on windows -uninstall-win: - @rm -fv $(foreach P,$(PROGS) $(PROGS_CROSS) libtcc.dll,"$(bindir)/$P") - @rm -fv $(foreach F,tcc-doc.html tcc-win32.txt,"$(docdir)/$F") - @rm -fv $(foreach F,libtcc.h libtcc.def libtcc.a,"$(libdir)/$F") - rm -r "$(tccdir)" - -# -------------------------------------------------------------------------- -# other stuff - -TAGFILES = *.[ch] include/*.h lib/*.[chS] -tags : ; ctags $(TAGFILES) -# cannot have both tags and TAGS on windows -ETAGS : ; etags $(TAGFILES) - -# create release tarball from *current* git branch (including tcc-doc.html -# and converting two files to CRLF) -TCC-VERSION = tcc-$(VERSION) -tar: tcc-doc.html - mkdir $(TCC-VERSION) - ( cd $(TCC-VERSION) && git --git-dir ../.git checkout -f ) - cp tcc-doc.html $(TCC-VERSION) - for f in tcc-win32.txt build-tcc.bat ; do \ - cat win32/$$f | sed 's,\(.*\),\1\r,g' > $(TCC-VERSION)/win32/$$f ; \ - done - tar cjf $(TCC-VERSION).tar.bz2 $(TCC-VERSION) - rm -rf $(TCC-VERSION) - git reset - -config.mak: - $(if $(wildcard $@),,@echo "Please run ./configure." && exit 1) - -# run all tests -test: - $(MAKE) -C tests -# run test(s) from tests2 subdir (see make help) -tests2.%: - $(MAKE) -C tests/tests2 $@ - -clean: - rm -f tcc$(EXESUF) tcc_p$(EXESUF) *-tcc$(EXESUF) tcc.pod - rm -f *~ *.o *.a *.so* *.out *.log lib*.def *.exe *.dll a.out tags TAGS - @$(MAKE) -C lib $@ - @$(MAKE) -C tests $@ - -distclean: clean - rm -f config.h config.mak config.texi tcc.1 tcc-doc.info tcc-doc.html - -.PHONY: all clean test tar tags ETAGS distclean install uninstall FORCE - -help: - @echo "make" - @echo " build native compiler (from separate objects)" - @echo "" - @echo "make cross" - @echo " build cross compilers (from one source)" - @echo "" - @echo "make ONE_SOURCE=yes / no" - @echo " force building from one source / separate objects" - @echo "" - @echo "make cross-TARGET" - @echo " build one specific cross compiler for 'TARGET', as in" - @echo " $(TCC_X)" - @echo "" - @echo "Custom configuration:" - @echo " The makefile includes a file 'config-extra.mak' if it is present." - @echo " This file may contain some custom configuration. For example:" - @echo "" - @echo " NATIVE_DEFINES += -D..." - @echo "" - @echo " Or for example to configure the search paths for a cross-compiler" - @echo " that expects the linux files in /i386-linux:" - @echo "" - @echo " ROOT-i386 = {B}/i386-linux" - @echo " CRT-i386 = {B}/i386-linux/usr/lib" - @echo " LIB-i386 = {B}/i386-linux/lib:{B}/i386-linux/usr/lib" - @echo " INC-i386 = {B}/lib/include:{B}/i386-linux/usr/include" - @echo " DEF-i386 += -D__linux__" - @echo "" - @echo "make test" - @echo " run all tests" - @echo "" - @echo "make tests2.all / make tests2.37 / make tests2.37+" - @echo " run all/single test(s) from tests2, optionally update .expect" - @echo "" - @echo "Other supported make targets:" - @echo " install install-strip tags ETAGS tar clean distclean help" - @echo "" - -# -------------------------------------------------------------------------- -endif # ($(INCLUDED),no) diff --git a/05/tcc-final-old/README b/05/tcc-final-old/README deleted file mode 100644 index 3a3f90b..0000000 --- a/05/tcc-final-old/README +++ /dev/null @@ -1,95 +0,0 @@ -Tiny C Compiler - C Scripting Everywhere - The Smallest ANSI C compiler ------------------------------------------------------------------------ - -Features: --------- - -- SMALL! You can compile and execute C code everywhere, for example on - rescue disks. - -- FAST! tcc generates optimized x86 code. No byte code - overhead. Compile, assemble and link about 7 times faster than 'gcc - -O0'. - -- UNLIMITED! Any C dynamic library can be used directly. TCC is - heading torward full ISOC99 compliance. TCC can of course compile - itself. - -- SAFE! tcc includes an optional memory and bound checker. Bound - checked code can be mixed freely with standard code. - -- Compile and execute C source directly. No linking or assembly - necessary. Full C preprocessor included. - -- C script supported : just add '#!/usr/local/bin/tcc -run' at the first - line of your C source, and execute it directly from the command - line. - -Documentation: -------------- - -1) Installation on a i386/x86_64/arm Linux/OSX/FreeBSD host - - ./configure - make - make test - make install - - Notes: For OSX and FreeBSD, gmake should be used instead of make. - For Windows read tcc-win32.txt. - -makeinfo must be installed to compile the doc. By default, tcc is -installed in /usr/local/bin. ./configure --help shows configuration -options. - - -2) Introduction - -We assume here that you know ANSI C. Look at the example ex1.c to know -what the programs look like. - -The include file can be used if you want a small basic libc -include support (especially useful for floppy disks). Of course, you -can also use standard headers, although they are slower to compile. - -You can begin your C script with '#!/usr/local/bin/tcc -run' on the first -line and set its execute bits (chmod a+x your_script). Then, you can -launch the C code as a shell or perl script :-) The command line -arguments are put in 'argc' and 'argv' of the main functions, as in -ANSI C. - -3) Examples - -ex1.c: simplest example (hello world). Can also be launched directly -as a script: './ex1.c'. - -ex2.c: more complicated example: find a number with the four -operations given a list of numbers (benchmark). - -ex3.c: compute fibonacci numbers (benchmark). - -ex4.c: more complicated: X11 program. Very complicated test in fact -because standard headers are being used ! As for ex1.c, can also be launched -directly as a script: './ex4.c'. - -ex5.c: 'hello world' with standard glibc headers. - -tcc.c: TCC can of course compile itself. Used to check the code -generator. - -tcctest.c: auto test for TCC which tests many subtle possible bugs. Used -when doing 'make test'. - -4) Full Documentation - -Please read tcc-doc.html to have all the features of TCC. - -Additional information is available for the Windows port in tcc-win32.txt. - -License: -------- - -TCC is distributed under the GNU Lesser General Public License (see -COPYING file). - -Fabrice Bellard. diff --git a/05/tcc-final-old/RELICENSING b/05/tcc-final-old/RELICENSING deleted file mode 100644 index 20841a7..0000000 --- a/05/tcc-final-old/RELICENSING +++ /dev/null @@ -1,60 +0,0 @@ - - Relicensing TinyCC - ------------------ - - The authors listed below hereby confirm their agreement to relicense TinyCC - including their past contributions under the following terms: - - - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - - - Author (name) I agree (YES/NO) Files/Features (optional) - ------------------------------------------------------------------------------ - Adam Sampson YES makefiles - Daniel Glöckner NO arm-gen.c - Daniel Glöckner YES not arm-gen.c - Edmund Grimley Evans YES arm64 - Fabrice Bellard YES original author - Frédéric Féret YES x86 64/16 bit asm - grischka YES tccpe.c - Henry Kroll YES - Joe Soroka YES - Kirill Smelkov YES - mingodad YES - Pip Cet YES - Shinichiro Hamaji YES x86_64-gen.c - Vincent Lefèvre YES - Thomas Preud'homme YES arm-gen.c - Timo VJ Lähde (Timppa) ? tiny_libmaker.c - TK ? tcccoff.c c67-gen.c - Urs Janssen YES - waddlesplash YES - Christian Jullien YES Windows Cygwin build and tests - - - ------------------------------------------------------------------------------ - - Please add yourself to the list above (rsp. replace the question mark) - and (after fetching the latest version) commit to the "mob" branch with - commit message: - - Relicensing TinyCC - - Thanks. diff --git a/05/tcc-final-old/TODO b/05/tcc-final-old/TODO deleted file mode 100644 index d810088..0000000 --- a/05/tcc-final-old/TODO +++ /dev/null @@ -1,100 +0,0 @@ -TODO list: - -Bugs: - -- i386 fastcall is mostly wrong -- FPU st(0) is left unclean (kwisatz haderach). Incompatible with - optimized gcc/msc code -- see transparent union pb in /urs/include/sys/socket.h -- precise behaviour of typeof with arrays ? (__put_user macro) - but should suffice for most cases) -- handle '? x, y : z' in unsized variable initialization (',' is - considered incorrectly as separator in preparser) -- transform functions to function pointers in function parameters - (net/ipv4/ip_output.c) -- fix function pointer type display -- check section alignment in C -- fix invalid cast in comparison 'if (v == (int8_t)v)' -- finish varargs.h support (gcc 3.2 testsuite issue) -- fix static functions declared inside block -- fix multiple unions init -- make libtcc fully reentrant (except for the compilation stage itself). -- struct/union/enum definitions in nested scopes (see also Debian bug #770657) -- __STDC_IEC_559__: float f(void) { static float x = 0.0 / 0.0; return x; } -- memory may be leaked after errors (longjmp). - -Portability: - -- it is assumed that int is 32-bit and sizeof(int) == 4 -- int is used when host or target size_t would make more sense -- TCC handles target floating-point (fp) values using the host's fp - arithmetic, which is simple and fast but may lead to exceptions - and inaccuracy and wrong representations when cross-compiling - -Linking: - -- static linking (-static) does not work - -Bound checking: - -- fix bound exit on RedHat 7.3 -- setjmp is not supported properly in bound checking. -- fix bound check code with '&' on local variables (currently done - only for local arrays). -- bound checking and float/long long/struct copy code. bound - checking and symbol + offset optimization - -Missing features: - -- disable-asm and disable-bcheck options -- __builtin_expect() -- atexit (Nigel Horne) -- C99: add complex types (gcc 3.2 testsuite issue) -- postfix compound literals (see 20010124-1.c) -- interactive mode / integrated debugger - -Optimizations: - -- suppress specific anonymous symbol handling -- more parse optimizations (=even faster compilation) -- memory alloc optimizations (=even faster compilation) -- optimize VT_LOCAL + const -- better local variables handling (needed for other targets) - -Not critical: - -- C99: fix multiple compound literals inits in blocks (ISOC99 - normative example - only relevant when using gotos! -> must add - boolean variable to tell if compound literal was already - initialized). -- add PowerPC generator and improve codegen for RISC (need - to suppress VT_LOCAL and use a base register instead). -- fix preprocessor symbol redefinition -- add portable byte code generator and interpreter for other - unsupported architectures. -- C++: variable declaration in for, minimal 'class' support. -- win32: __intxx. use resolve for bchecked malloc et al. - check exception code (exception filter func). -- handle void (__attribute__() *ptr)() -- VLAs are implemented in a way that is not compatible with signals: - http://lists.gnu.org/archive/html/tinycc-devel/2015-11/msg00018.html - -Fixed (probably): - -- bug with defines: - #define spin_lock(lock) do { } while (0) - #define wq_spin_lock spin_lock - #define TEST() wq_spin_lock(a) -- typedefs can be structure fields -- see bugfixes.diff + improvement.diff from Daniel Glockner -- long long constant evaluation -- add alloca() -- gcc '-E' option. -- #include_next support for /usr/include/limits ? -- function pointers/lvalues in ? : (linux kernel net/core/dev.c) -- win32: add __stdcall, check GetModuleHandle for dlls. -- macro substitution with nested definitions (ShangHongzhang) -- with "-run" and libtcc, a PLT is now built. -- '-E' option was improved -- packed attribute is now supported -- ARM and ARM64 code generators have been added. diff --git a/05/tcc-final-old/VERSION b/05/tcc-final-old/VERSION deleted file mode 100644 index 9a54223..0000000 --- a/05/tcc-final-old/VERSION +++ /dev/null @@ -1 +0,0 @@ -0.9.27 diff --git a/05/tcc-final-old/arm-asm.c b/05/tcc-final-old/arm-asm.c deleted file mode 100644 index 3b5ae66..0000000 --- a/05/tcc-final-old/arm-asm.c +++ /dev/null @@ -1,94 +0,0 @@ -/*************************************************************/ -/* - * ARM dummy assembler for TCC - * - */ - -#ifdef TARGET_DEFS_ONLY - -#define CONFIG_TCC_ASM -#define NB_ASM_REGS 16 - -ST_FUNC void g(int c); -ST_FUNC void gen_le16(int c); -ST_FUNC void gen_le32(int c); - -/*************************************************************/ -#else -/*************************************************************/ - -#include "tcc.h" - -static void asm_error(void) -{ - tcc_error("ARM asm not implemented."); -} - -/* XXX: make it faster ? */ -ST_FUNC void g(int c) -{ - int ind1; - if (nocode_wanted) - return; - ind1 = ind + 1; - if (ind1 > cur_text_section->data_allocated) - section_realloc(cur_text_section, ind1); - cur_text_section->data[ind] = c; - ind = ind1; -} - -ST_FUNC void gen_le16 (int i) -{ - g(i); - g(i>>8); -} - -ST_FUNC void gen_le32 (int i) -{ - gen_le16(i); - gen_le16(i>>16); -} - -ST_FUNC void gen_expr32(ExprValue *pe) -{ - gen_le32(pe->v); -} - -ST_FUNC void asm_opcode(TCCState *s1, int opcode) -{ - asm_error(); -} - -ST_FUNC void subst_asm_operand(CString *add_str, SValue *sv, int modifier) -{ - asm_error(); -} - -/* generate prolog and epilog code for asm statement */ -ST_FUNC void asm_gen_code(ASMOperand *operands, int nb_operands, - int nb_outputs, int is_output, - uint8_t *clobber_regs, - int out_reg) -{ -} - -ST_FUNC void asm_compute_constraints(ASMOperand *operands, - int nb_operands, int nb_outputs, - const uint8_t *clobber_regs, - int *pout_reg) -{ -} - -ST_FUNC void asm_clobber(uint8_t *clobber_regs, const char *str) -{ - asm_error(); -} - -ST_FUNC int asm_parse_regvar (int t) -{ - asm_error(); - return -1; -} - -/*************************************************************/ -#endif /* ndef TARGET_DEFS_ONLY */ diff --git a/05/tcc-final-old/arm-gen.c b/05/tcc-final-old/arm-gen.c deleted file mode 100644 index f535a09..0000000 --- a/05/tcc-final-old/arm-gen.c +++ /dev/null @@ -1,2151 +0,0 @@ -/* - * ARMv4 code generator for TCC - * - * Copyright (c) 2003 Daniel Glöckner - * Copyright (c) 2012 Thomas Preud'homme - * - * Based on i386-gen.c by Fabrice Bellard - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifdef TARGET_DEFS_ONLY - -#if defined(TCC_ARM_EABI) && !defined(TCC_ARM_VFP) -#error "Currently TinyCC only supports float computation with VFP instructions" -#endif - -/* number of available registers */ -#ifdef TCC_ARM_VFP -#define NB_REGS 13 -#else -#define NB_REGS 9 -#endif - -#ifndef TCC_CPU_VERSION -# define TCC_CPU_VERSION 5 -#endif - -/* a register can belong to several classes. The classes must be - sorted from more general to more precise (see gv2() code which does - assumptions on it). */ -#define RC_INT 0x0001 /* generic integer register */ -#define RC_FLOAT 0x0002 /* generic float register */ -#define RC_R0 0x0004 -#define RC_R1 0x0008 -#define RC_R2 0x0010 -#define RC_R3 0x0020 -#define RC_R12 0x0040 -#define RC_F0 0x0080 -#define RC_F1 0x0100 -#define RC_F2 0x0200 -#define RC_F3 0x0400 -#ifdef TCC_ARM_VFP -#define RC_F4 0x0800 -#define RC_F5 0x1000 -#define RC_F6 0x2000 -#define RC_F7 0x4000 -#endif -#define RC_IRET RC_R0 /* function return: integer register */ -#define RC_LRET RC_R1 /* function return: second integer register */ -#define RC_FRET RC_F0 /* function return: float register */ - -/* pretty names for the registers */ -enum { - TREG_R0 = 0, - TREG_R1, - TREG_R2, - TREG_R3, - TREG_R12, - TREG_F0, - TREG_F1, - TREG_F2, - TREG_F3, -#ifdef TCC_ARM_VFP - TREG_F4, - TREG_F5, - TREG_F6, - TREG_F7, -#endif - TREG_SP = 13, - TREG_LR, -}; - -#ifdef TCC_ARM_VFP -#define T2CPR(t) (((t) & VT_BTYPE) != VT_FLOAT ? 0x100 : 0) -#endif - -/* return registers for function */ -#define REG_IRET TREG_R0 /* single word int return register */ -#define REG_LRET TREG_R1 /* second word return register (for long long) */ -#define REG_FRET TREG_F0 /* float return register */ - -#ifdef TCC_ARM_EABI -#define TOK___divdi3 TOK___aeabi_ldivmod -#define TOK___moddi3 TOK___aeabi_ldivmod -#define TOK___udivdi3 TOK___aeabi_uldivmod -#define TOK___umoddi3 TOK___aeabi_uldivmod -#endif - -/* defined if function parameters must be evaluated in reverse order */ -#define INVERT_FUNC_PARAMS - -/* defined if structures are passed as pointers. Otherwise structures - are directly pushed on stack. */ -/* #define FUNC_STRUCT_PARAM_AS_PTR */ - -/* pointer size, in bytes */ -#define PTR_SIZE 4 - -/* long double size and alignment, in bytes */ -#ifdef TCC_ARM_VFP -#define LDOUBLE_SIZE 8 -#endif - -#ifndef LDOUBLE_SIZE -#define LDOUBLE_SIZE 8 -#endif - -#ifdef TCC_ARM_EABI -#define LDOUBLE_ALIGN 8 -#else -#define LDOUBLE_ALIGN 4 -#endif - -/* maximum alignment (for aligned attribute support) */ -#define MAX_ALIGN 8 - -#define CHAR_IS_UNSIGNED - -/******************************************************/ -#else /* ! TARGET_DEFS_ONLY */ -/******************************************************/ -#include "tcc.h" - -enum float_abi float_abi; - -ST_DATA const int reg_classes[NB_REGS] = { - /* r0 */ RC_INT | RC_R0, - /* r1 */ RC_INT | RC_R1, - /* r2 */ RC_INT | RC_R2, - /* r3 */ RC_INT | RC_R3, - /* r12 */ RC_INT | RC_R12, - /* f0 */ RC_FLOAT | RC_F0, - /* f1 */ RC_FLOAT | RC_F1, - /* f2 */ RC_FLOAT | RC_F2, - /* f3 */ RC_FLOAT | RC_F3, -#ifdef TCC_ARM_VFP - /* d4/s8 */ RC_FLOAT | RC_F4, -/* d5/s10 */ RC_FLOAT | RC_F5, -/* d6/s12 */ RC_FLOAT | RC_F6, -/* d7/s14 */ RC_FLOAT | RC_F7, -#endif -}; - -static int func_sub_sp_offset, last_itod_magic; -static int leaffunc; - -#if defined(TCC_ARM_EABI) && defined(TCC_ARM_VFP) -static CType float_type, double_type, func_float_type, func_double_type; -ST_FUNC void arm_init(struct TCCState *s) -{ - float_type.t = VT_FLOAT; - double_type.t = VT_DOUBLE; - func_float_type.t = VT_FUNC; - func_float_type.ref = sym_push(SYM_FIELD, &float_type, FUNC_CDECL, FUNC_OLD); - func_double_type.t = VT_FUNC; - func_double_type.ref = sym_push(SYM_FIELD, &double_type, FUNC_CDECL, FUNC_OLD); - - float_abi = s->float_abi; -#ifndef TCC_ARM_HARDFLOAT - tcc_warning("soft float ABI currently not supported: default to softfp"); -#endif -} -#else -#define func_float_type func_old_type -#define func_double_type func_old_type -#define func_ldouble_type func_old_type -ST_FUNC void arm_init(struct TCCState *s) -{ -#if 0 -#if !defined (TCC_ARM_VFP) - tcc_warning("Support for FPA is deprecated and will be removed in next" - " release"); -#endif -#if !defined (TCC_ARM_EABI) - tcc_warning("Support for OABI is deprecated and will be removed in next" - " release"); -#endif -#endif -} -#endif - -static int two2mask(int a,int b) { - return (reg_classes[a]|reg_classes[b])&~(RC_INT|RC_FLOAT); -} - -static int regmask(int r) { - return reg_classes[r]&~(RC_INT|RC_FLOAT); -} - -/******************************************************/ - -#if defined(TCC_ARM_EABI) && !defined(CONFIG_TCC_ELFINTERP) -const char *default_elfinterp(struct TCCState *s) -{ - if (s->float_abi == ARM_HARD_FLOAT) - return "/lib/ld-linux-armhf.so.3"; - else - return "/lib/ld-linux.so.3"; -} -#endif - -void o(uint32_t i) -{ - /* this is a good place to start adding big-endian support*/ - int ind1; - if (nocode_wanted) - return; - ind1 = ind + 4; - if (!cur_text_section) - tcc_error("compiler error! This happens f.ex. if the compiler\n" - "can't evaluate constant expressions outside of a function."); - if (ind1 > cur_text_section->data_allocated) - section_realloc(cur_text_section, ind1); - cur_text_section->data[ind++] = i&255; - i>>=8; - cur_text_section->data[ind++] = i&255; - i>>=8; - cur_text_section->data[ind++] = i&255; - i>>=8; - cur_text_section->data[ind++] = i; -} - -static uint32_t stuff_const(uint32_t op, uint32_t c) -{ - int try_neg=0; - uint32_t nc = 0, negop = 0; - - switch(op&0x1F00000) - { - case 0x800000: //add - case 0x400000: //sub - try_neg=1; - negop=op^0xC00000; - nc=-c; - break; - case 0x1A00000: //mov - case 0x1E00000: //mvn - try_neg=1; - negop=op^0x400000; - nc=~c; - break; - case 0x200000: //xor - if(c==~0) - return (op&0xF010F000)|((op>>16)&0xF)|0x1E00000; - break; - case 0x0: //and - if(c==~0) - return (op&0xF010F000)|((op>>16)&0xF)|0x1A00000; - case 0x1C00000: //bic - try_neg=1; - negop=op^0x1C00000; - nc=~c; - break; - case 0x1800000: //orr - if(c==~0) - return (op&0xFFF0FFFF)|0x1E00000; - break; - } - do { - uint32_t m; - int i; - if(c<256) /* catch undefined <<32 */ - return op|c; - for(i=2;i<32;i+=2) { - m=(0xff>>i)|(0xff<<(32-i)); - if(!(c&~m)) - return op|(i<<7)|(c<>(32-i)); - } - op=negop; - c=nc; - } while(try_neg--); - return 0; -} - - -//only add,sub -void stuff_const_harder(uint32_t op, uint32_t v) { - uint32_t x; - x=stuff_const(op,v); - if(x) - o(x); - else { - uint32_t a[16], nv, no, o2, n2; - int i,j,k; - a[0]=0xff; - o2=(op&0xfff0ffff)|((op&0xf000)<<4);; - for(i=1;i<16;i++) - a[i]=(a[i-1]>>2)|(a[i-1]<<30); - for(i=0;i<12;i++) - for(j=i<4?i+12:15;j>=i+4;j--) - if((v&(a[i]|a[j]))==v) { - o(stuff_const(op,v&a[i])); - o(stuff_const(o2,v&a[j])); - return; - } - no=op^0xC00000; - n2=o2^0xC00000; - nv=-v; - for(i=0;i<12;i++) - for(j=i<4?i+12:15;j>=i+4;j--) - if((nv&(a[i]|a[j]))==nv) { - o(stuff_const(no,nv&a[i])); - o(stuff_const(n2,nv&a[j])); - return; - } - for(i=0;i<8;i++) - for(j=i+4;j<12;j++) - for(k=i<4?i+12:15;k>=j+4;k--) - if((v&(a[i]|a[j]|a[k]))==v) { - o(stuff_const(op,v&a[i])); - o(stuff_const(o2,v&a[j])); - o(stuff_const(o2,v&a[k])); - return; - } - no=op^0xC00000; - nv=-v; - for(i=0;i<8;i++) - for(j=i+4;j<12;j++) - for(k=i<4?i+12:15;k>=j+4;k--) - if((nv&(a[i]|a[j]|a[k]))==nv) { - o(stuff_const(no,nv&a[i])); - o(stuff_const(n2,nv&a[j])); - o(stuff_const(n2,nv&a[k])); - return; - } - o(stuff_const(op,v&a[0])); - o(stuff_const(o2,v&a[4])); - o(stuff_const(o2,v&a[8])); - o(stuff_const(o2,v&a[12])); - } -} - -uint32_t encbranch(int pos, int addr, int fail) -{ - addr-=pos+8; - addr/=4; - if(addr>=0x1000000 || addr<-0x1000000) { - if(fail) - tcc_error("FIXME: function bigger than 32MB"); - return 0; - } - return 0x0A000000|(addr&0xffffff); -} - -int decbranch(int pos) -{ - int x; - x=*(uint32_t *)(cur_text_section->data + pos); - x&=0x00ffffff; - if(x&0x800000) - x-=0x1000000; - return x*4+pos+8; -} - -/* output a symbol and patch all calls to it */ -void gsym_addr(int t, int a) -{ - uint32_t *x; - int lt; - while(t) { - x=(uint32_t *)(cur_text_section->data + t); - t=decbranch(lt=t); - if(a==lt+4) - *x=0xE1A00000; // nop - else { - *x &= 0xff000000; - *x |= encbranch(lt,a,1); - } - } -} - -void gsym(int t) -{ - gsym_addr(t, ind); -} - -#ifdef TCC_ARM_VFP -static uint32_t vfpr(int r) -{ - if(rTREG_F7) - tcc_error("compiler error! register %i is no vfp register",r); - return r - TREG_F0; -} -#else -static uint32_t fpr(int r) -{ - if(rTREG_F3) - tcc_error("compiler error! register %i is no fpa register",r); - return r - TREG_F0; -} -#endif - -static uint32_t intr(int r) -{ - if(r == TREG_R12) - return 12; - if(r >= TREG_R0 && r <= TREG_R3) - return r - TREG_R0; - if (r >= TREG_SP && r <= TREG_LR) - return r + (13 - TREG_SP); - tcc_error("compiler error! register %i is no int register",r); -} - -static void calcaddr(uint32_t *base, int *off, int *sgn, int maxoff, unsigned shift) -{ - if(*off>maxoff || *off&((1<r; - ft = sv->type.t; - fc = sv->c.i; - - if(fc>=0) - sign=0; - else { - sign=1; - fc=-fc; - } - - v = fr & VT_VALMASK; - if (fr & VT_LVAL) { - uint32_t base = 0xB; // fp - if(v == VT_LLOCAL) { - v1.type.t = VT_PTR; - v1.r = VT_LOCAL | VT_LVAL; - v1.c.i = sv->c.i; - load(TREG_LR, &v1); - base = 14; /* lr */ - fc=sign=0; - v=VT_LOCAL; - } else if(v == VT_CONST) { - v1.type.t = VT_PTR; - v1.r = fr&~VT_LVAL; - v1.c.i = sv->c.i; - v1.sym=sv->sym; - load(TREG_LR, &v1); - base = 14; /* lr */ - fc=sign=0; - v=VT_LOCAL; - } else if(v < VT_CONST) { - base=intr(v); - fc=sign=0; - v=VT_LOCAL; - } - if(v == VT_LOCAL) { - if(is_float(ft)) { - calcaddr(&base,&fc,&sign,1020,2); -#ifdef TCC_ARM_VFP - op=0xED100A00; /* flds */ - if(!sign) - op|=0x800000; - if ((ft & VT_BTYPE) != VT_FLOAT) - op|=0x100; /* flds -> fldd */ - o(op|(vfpr(r)<<12)|(fc>>2)|(base<<16)); -#else - op=0xED100100; - if(!sign) - op|=0x800000; -#if LDOUBLE_SIZE == 8 - if ((ft & VT_BTYPE) != VT_FLOAT) - op|=0x8000; -#else - if ((ft & VT_BTYPE) == VT_DOUBLE) - op|=0x8000; - else if ((ft & VT_BTYPE) == VT_LDOUBLE) - op|=0x400000; -#endif - o(op|(fpr(r)<<12)|(fc>>2)|(base<<16)); -#endif - } else if((ft & (VT_BTYPE|VT_UNSIGNED)) == VT_BYTE - || (ft & VT_BTYPE) == VT_SHORT) { - calcaddr(&base,&fc,&sign,255,0); - op=0xE1500090; - if ((ft & VT_BTYPE) == VT_SHORT) - op|=0x20; - if ((ft & VT_UNSIGNED) == 0) - op|=0x40; - if(!sign) - op|=0x800000; - o(op|(intr(r)<<12)|(base<<16)|((fc&0xf0)<<4)|(fc&0xf)); - } else { - calcaddr(&base,&fc,&sign,4095,0); - op=0xE5100000; - if(!sign) - op|=0x800000; - if ((ft & VT_BTYPE) == VT_BYTE || (ft & VT_BTYPE) == VT_BOOL) - op|=0x400000; - o(op|(intr(r)<<12)|fc|(base<<16)); - } - return; - } - } else { - if (v == VT_CONST) { - op=stuff_const(0xE3A00000|(intr(r)<<12),sv->c.i); - if (fr & VT_SYM || !op) { - o(0xE59F0000|(intr(r)<<12)); - o(0xEA000000); - if(fr & VT_SYM) - greloc(cur_text_section, sv->sym, ind, R_ARM_ABS32); - o(sv->c.i); - } else - o(op); - return; - } else if (v == VT_LOCAL) { - op=stuff_const(0xE28B0000|(intr(r)<<12),sv->c.i); - if (fr & VT_SYM || !op) { - o(0xE59F0000|(intr(r)<<12)); - o(0xEA000000); - if(fr & VT_SYM) // needed ? - greloc(cur_text_section, sv->sym, ind, R_ARM_ABS32); - o(sv->c.i); - o(0xE08B0000|(intr(r)<<12)|intr(r)); - } else - o(op); - return; - } else if(v == VT_CMP) { - o(mapcc(sv->c.i)|0x3A00001|(intr(r)<<12)); - o(mapcc(negcc(sv->c.i))|0x3A00000|(intr(r)<<12)); - return; - } else if (v == VT_JMP || v == VT_JMPI) { - int t; - t = v & 1; - o(0xE3A00000|(intr(r)<<12)|t); - o(0xEA000000); - gsym(sv->c.i); - o(0xE3A00000|(intr(r)<<12)|(t^1)); - return; - } else if (v < VT_CONST) { - if(is_float(ft)) -#ifdef TCC_ARM_VFP - o(0xEEB00A40|(vfpr(r)<<12)|vfpr(v)|T2CPR(ft)); /* fcpyX */ -#else - o(0xEE008180|(fpr(r)<<12)|fpr(v)); -#endif - else - o(0xE1A00000|(intr(r)<<12)|intr(v)); - return; - } - } - tcc_error("load unimplemented!"); -} - -/* store register 'r' in lvalue 'v' */ -void store(int r, SValue *sv) -{ - SValue v1; - int v, ft, fc, fr, sign; - uint32_t op; - - fr = sv->r; - ft = sv->type.t; - fc = sv->c.i; - - if(fc>=0) - sign=0; - else { - sign=1; - fc=-fc; - } - - v = fr & VT_VALMASK; - if (fr & VT_LVAL || fr == VT_LOCAL) { - uint32_t base = 0xb; /* fp */ - if(v < VT_CONST) { - base=intr(v); - v=VT_LOCAL; - fc=sign=0; - } else if(v == VT_CONST) { - v1.type.t = ft; - v1.r = fr&~VT_LVAL; - v1.c.i = sv->c.i; - v1.sym=sv->sym; - load(TREG_LR, &v1); - base = 14; /* lr */ - fc=sign=0; - v=VT_LOCAL; - } - if(v == VT_LOCAL) { - if(is_float(ft)) { - calcaddr(&base,&fc,&sign,1020,2); -#ifdef TCC_ARM_VFP - op=0xED000A00; /* fsts */ - if(!sign) - op|=0x800000; - if ((ft & VT_BTYPE) != VT_FLOAT) - op|=0x100; /* fsts -> fstd */ - o(op|(vfpr(r)<<12)|(fc>>2)|(base<<16)); -#else - op=0xED000100; - if(!sign) - op|=0x800000; -#if LDOUBLE_SIZE == 8 - if ((ft & VT_BTYPE) != VT_FLOAT) - op|=0x8000; -#else - if ((ft & VT_BTYPE) == VT_DOUBLE) - op|=0x8000; - if ((ft & VT_BTYPE) == VT_LDOUBLE) - op|=0x400000; -#endif - o(op|(fpr(r)<<12)|(fc>>2)|(base<<16)); -#endif - return; - } else if((ft & VT_BTYPE) == VT_SHORT) { - calcaddr(&base,&fc,&sign,255,0); - op=0xE14000B0; - if(!sign) - op|=0x800000; - o(op|(intr(r)<<12)|(base<<16)|((fc&0xf0)<<4)|(fc&0xf)); - } else { - calcaddr(&base,&fc,&sign,4095,0); - op=0xE5000000; - if(!sign) - op|=0x800000; - if ((ft & VT_BTYPE) == VT_BYTE || (ft & VT_BTYPE) == VT_BOOL) - op|=0x400000; - o(op|(intr(r)<<12)|fc|(base<<16)); - } - return; - } - } - tcc_error("store unimplemented"); -} - -static void gadd_sp(int val) -{ - stuff_const_harder(0xE28DD000,val); -} - -/* 'is_jmp' is '1' if it is a jump */ -static void gcall_or_jmp(int is_jmp) -{ - int r; - if ((vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST) { - uint32_t x; - /* constant case */ - x=encbranch(ind,ind+vtop->c.i,0); - if(x) { - if (vtop->r & VT_SYM) { - /* relocation case */ - greloc(cur_text_section, vtop->sym, ind, R_ARM_PC24); - } else - put_elf_reloc(symtab_section, cur_text_section, ind, R_ARM_PC24, 0); - o(x|(is_jmp?0xE0000000:0xE1000000)); - } else { - if(!is_jmp) - o(0xE28FE004); // add lr,pc,#4 - o(0xE51FF004); // ldr pc,[pc,#-4] - if (vtop->r & VT_SYM) - greloc(cur_text_section, vtop->sym, ind, R_ARM_ABS32); - o(vtop->c.i); - } - } else { - /* otherwise, indirect call */ - r = gv(RC_INT); - if(!is_jmp) - o(0xE1A0E00F); // mov lr,pc - o(0xE1A0F000|intr(r)); // mov pc,r - } -} - -static int unalias_ldbl(int btype) -{ -#if LDOUBLE_SIZE == 8 - if (btype == VT_LDOUBLE) - btype = VT_DOUBLE; -#endif - return btype; -} - -/* Return whether a structure is an homogeneous float aggregate or not. - The answer is true if all the elements of the structure are of the same - primitive float type and there is less than 4 elements. - - type: the type corresponding to the structure to be tested */ -static int is_hgen_float_aggr(CType *type) -{ - if ((type->t & VT_BTYPE) == VT_STRUCT) { - struct Sym *ref; - int btype, nb_fields = 0; - - ref = type->ref->next; - btype = unalias_ldbl(ref->type.t & VT_BTYPE); - if (btype == VT_FLOAT || btype == VT_DOUBLE) { - for(; ref && btype == unalias_ldbl(ref->type.t & VT_BTYPE); ref = ref->next, nb_fields++); - return !ref && nb_fields <= 4; - } - } - return 0; -} - -struct avail_regs { - signed char avail[3]; /* 3 holes max with only float and double alignments */ - int first_hole; /* first available hole */ - int last_hole; /* last available hole (none if equal to first_hole) */ - int first_free_reg; /* next free register in the sequence, hole excluded */ -}; - -#define AVAIL_REGS_INITIALIZER (struct avail_regs) { { 0, 0, 0}, 0, 0, 0 } - -/* Find suitable registers for a VFP Co-Processor Register Candidate (VFP CPRC - param) according to the rules described in the procedure call standard for - the ARM architecture (AAPCS). If found, the registers are assigned to this - VFP CPRC parameter. Registers are allocated in sequence unless a hole exists - and the parameter is a single float. - - avregs: opaque structure to keep track of available VFP co-processor regs - align: alignment constraints for the param, as returned by type_size() - size: size of the parameter, as returned by type_size() */ -int assign_vfpreg(struct avail_regs *avregs, int align, int size) -{ - int first_reg = 0; - - if (avregs->first_free_reg == -1) - return -1; - if (align >> 3) { /* double alignment */ - first_reg = avregs->first_free_reg; - /* alignment constraint not respected so use next reg and record hole */ - if (first_reg & 1) - avregs->avail[avregs->last_hole++] = first_reg++; - } else { /* no special alignment (float or array of float) */ - /* if single float and a hole is available, assign the param to it */ - if (size == 4 && avregs->first_hole != avregs->last_hole) - return avregs->avail[avregs->first_hole++]; - else - first_reg = avregs->first_free_reg; - } - if (first_reg + size / 4 <= 16) { - avregs->first_free_reg = first_reg + size / 4; - return first_reg; - } - avregs->first_free_reg = -1; - return -1; -} - -/* Returns whether all params need to be passed in core registers or not. - This is the case for function part of the runtime ABI. */ -int floats_in_core_regs(SValue *sval) -{ - if (!sval->sym) - return 0; - - switch (sval->sym->v) { - case TOK___floatundisf: - case TOK___floatundidf: - case TOK___fixunssfdi: - case TOK___fixunsdfdi: -#ifndef TCC_ARM_VFP - case TOK___fixunsxfdi: -#endif - case TOK___floatdisf: - case TOK___floatdidf: - case TOK___fixsfdi: - case TOK___fixdfdi: - return 1; - - default: - return 0; - } -} - -/* Return the number of registers needed to return the struct, or 0 if - returning via struct pointer. */ -ST_FUNC int gfunc_sret(CType *vt, int variadic, CType *ret, int *ret_align, int *regsize) { -#ifdef TCC_ARM_EABI - int size, align; - size = type_size(vt, &align); - if (float_abi == ARM_HARD_FLOAT && !variadic && - (is_float(vt->t) || is_hgen_float_aggr(vt))) { - *ret_align = 8; - *regsize = 8; - ret->ref = NULL; - ret->t = VT_DOUBLE; - return (size + 7) >> 3; - } else if (size <= 4) { - *ret_align = 4; - *regsize = 4; - ret->ref = NULL; - ret->t = VT_INT; - return 1; - } else - return 0; -#else - return 0; -#endif -} - -/* Parameters are classified according to how they are copied to their final - destination for the function call. Because the copying is performed class - after class according to the order in the union below, it is important that - some constraints about the order of the members of this union are respected: - - CORE_STRUCT_CLASS must come after STACK_CLASS; - - CORE_CLASS must come after STACK_CLASS, CORE_STRUCT_CLASS and - VFP_STRUCT_CLASS; - - VFP_STRUCT_CLASS must come after VFP_CLASS. - See the comment for the main loop in copy_params() for the reason. */ -enum reg_class { - STACK_CLASS = 0, - CORE_STRUCT_CLASS, - VFP_CLASS, - VFP_STRUCT_CLASS, - CORE_CLASS, - NB_CLASSES -}; - -struct param_plan { - int start; /* first reg or addr used depending on the class */ - int end; /* last reg used or next free addr depending on the class */ - SValue *sval; /* pointer to SValue on the value stack */ - struct param_plan *prev; /* previous element in this class */ -}; - -struct plan { - struct param_plan *pplans; /* array of all the param plans */ - struct param_plan *clsplans[NB_CLASSES]; /* per class lists of param plans */ -}; - -#define add_param_plan(plan,pplan,class) \ - do { \ - pplan.prev = plan->clsplans[class]; \ - plan->pplans[plan ## _nb] = pplan; \ - plan->clsplans[class] = &plan->pplans[plan ## _nb++]; \ - } while(0) - -/* Assign parameters to registers and stack with alignment according to the - rules in the procedure call standard for the ARM architecture (AAPCS). - The overall assignment is recorded in an array of per parameter structures - called parameter plans. The parameter plans are also further organized in a - number of linked lists, one per class of parameter (see the comment for the - definition of union reg_class). - - nb_args: number of parameters of the function for which a call is generated - float_abi: float ABI in use for this function call - plan: the structure where the overall assignment is recorded - todo: a bitmap that record which core registers hold a parameter - - Returns the amount of stack space needed for parameter passing - - Note: this function allocated an array in plan->pplans with tcc_malloc. It - is the responsibility of the caller to free this array once used (ie not - before copy_params). */ -static int assign_regs(int nb_args, int float_abi, struct plan *plan, int *todo) -{ - int i, size, align; - int ncrn /* next core register number */, nsaa /* next stacked argument address*/; - int plan_nb = 0; - struct param_plan pplan; - struct avail_regs avregs = AVAIL_REGS_INITIALIZER; - - ncrn = nsaa = 0; - *todo = 0; - plan->pplans = tcc_malloc(nb_args * sizeof(*plan->pplans)); - memset(plan->clsplans, 0, sizeof(plan->clsplans)); - for(i = nb_args; i-- ;) { - int j, start_vfpreg = 0; - CType type = vtop[-i].type; - type.t &= ~VT_ARRAY; - size = type_size(&type, &align); - size = (size + 3) & ~3; - align = (align + 3) & ~3; - switch(vtop[-i].type.t & VT_BTYPE) { - case VT_STRUCT: - case VT_FLOAT: - case VT_DOUBLE: - case VT_LDOUBLE: - if (float_abi == ARM_HARD_FLOAT) { - int is_hfa = 0; /* Homogeneous float aggregate */ - - if (is_float(vtop[-i].type.t) - || (is_hfa = is_hgen_float_aggr(&vtop[-i].type))) { - int end_vfpreg; - - start_vfpreg = assign_vfpreg(&avregs, align, size); - end_vfpreg = start_vfpreg + ((size - 1) >> 2); - if (start_vfpreg >= 0) { - pplan = (struct param_plan) {start_vfpreg, end_vfpreg, &vtop[-i]}; - if (is_hfa) - add_param_plan(plan, pplan, VFP_STRUCT_CLASS); - else - add_param_plan(plan, pplan, VFP_CLASS); - continue; - } else - break; - } - } - ncrn = (ncrn + (align-1)/4) & ~((align/4) - 1); - if (ncrn + size/4 <= 4 || (ncrn < 4 && start_vfpreg != -1)) { - /* The parameter is allocated both in core register and on stack. As - * such, it can be of either class: it would either be the last of - * CORE_STRUCT_CLASS or the first of STACK_CLASS. */ - for (j = ncrn; j < 4 && j < ncrn + size / 4; j++) - *todo|=(1< 4) - nsaa = (ncrn - 4) * 4; - } else { - ncrn = 4; - break; - } - continue; - default: - if (ncrn < 4) { - int is_long = (vtop[-i].type.t & VT_BTYPE) == VT_LLONG; - - if (is_long) { - ncrn = (ncrn + 1) & -2; - if (ncrn == 4) - break; - } - pplan = (struct param_plan) {ncrn, ncrn, &vtop[-i]}; - ncrn++; - if (is_long) - pplan.end = ncrn++; - add_param_plan(plan, pplan, CORE_CLASS); - continue; - } - } - nsaa = (nsaa + (align - 1)) & ~(align - 1); - pplan = (struct param_plan) {nsaa, nsaa + size, &vtop[-i]}; - add_param_plan(plan, pplan, STACK_CLASS); - nsaa += size; /* size already rounded up before */ - } - return nsaa; -} - -#undef add_param_plan - -/* Copy parameters to their final destination (core reg, VFP reg or stack) for - function call. - - nb_args: number of parameters the function take - plan: the overall assignment plan for parameters - todo: a bitmap indicating what core reg will hold a parameter - - Returns the number of SValue added by this function on the value stack */ -static int copy_params(int nb_args, struct plan *plan, int todo) -{ - int size, align, r, i, nb_extra_sval = 0; - struct param_plan *pplan; - int pass = 0; - - /* Several constraints require parameters to be copied in a specific order: - - structures are copied to the stack before being loaded in a reg; - - floats loaded to an odd numbered VFP reg are first copied to the - preceding even numbered VFP reg and then moved to the next VFP reg. - - It is thus important that: - - structures assigned to core regs must be copied after parameters - assigned to the stack but before structures assigned to VFP regs because - a structure can lie partly in core registers and partly on the stack; - - parameters assigned to the stack and all structures be copied before - parameters assigned to a core reg since copying a parameter to the stack - require using a core reg; - - parameters assigned to VFP regs be copied before structures assigned to - VFP regs as the copy might use an even numbered VFP reg that already - holds part of a structure. */ -again: - for(i = 0; i < NB_CLASSES; i++) { - for(pplan = plan->clsplans[i]; pplan; pplan = pplan->prev) { - - if (pass - && (i != CORE_CLASS || pplan->sval->r < VT_CONST)) - continue; - - vpushv(pplan->sval); - pplan->sval->r = pplan->sval->r2 = VT_CONST; /* disable entry */ - switch(i) { - case STACK_CLASS: - case CORE_STRUCT_CLASS: - case VFP_STRUCT_CLASS: - if ((pplan->sval->type.t & VT_BTYPE) == VT_STRUCT) { - int padding = 0; - size = type_size(&pplan->sval->type, &align); - /* align to stack align size */ - size = (size + 3) & ~3; - if (i == STACK_CLASS && pplan->prev) - padding = pplan->start - pplan->prev->end; - size += padding; /* Add padding if any */ - /* allocate the necessary size on stack */ - gadd_sp(-size); - /* generate structure store */ - r = get_reg(RC_INT); - o(0xE28D0000|(intr(r)<<12)|padding); /* add r, sp, padding */ - vset(&vtop->type, r | VT_LVAL, 0); - vswap(); - vstore(); /* memcpy to current sp + potential padding */ - - /* Homogeneous float aggregate are loaded to VFP registers - immediately since there is no way of loading data in multiple - non consecutive VFP registers as what is done for other - structures (see the use of todo). */ - if (i == VFP_STRUCT_CLASS) { - int first = pplan->start, nb = pplan->end - first + 1; - /* vpop.32 {pplan->start, ..., pplan->end} */ - o(0xECBD0A00|(first&1)<<22|(first>>1)<<12|nb); - /* No need to write the register used to a SValue since VFP regs - cannot be used for gcall_or_jmp */ - } - } else { - if (is_float(pplan->sval->type.t)) { -#ifdef TCC_ARM_VFP - r = vfpr(gv(RC_FLOAT)) << 12; - if ((pplan->sval->type.t & VT_BTYPE) == VT_FLOAT) - size = 4; - else { - size = 8; - r |= 0x101; /* vpush.32 -> vpush.64 */ - } - o(0xED2D0A01 + r); /* vpush */ -#else - r = fpr(gv(RC_FLOAT)) << 12; - if ((pplan->sval->type.t & VT_BTYPE) == VT_FLOAT) - size = 4; - else if ((pplan->sval->type.t & VT_BTYPE) == VT_DOUBLE) - size = 8; - else - size = LDOUBLE_SIZE; - - if (size == 12) - r |= 0x400000; - else if(size == 8) - r|=0x8000; - - o(0xED2D0100|r|(size>>2)); /* some kind of vpush for FPA */ -#endif - } else { - /* simple type (currently always same size) */ - /* XXX: implicit cast ? */ - size=4; - if ((pplan->sval->type.t & VT_BTYPE) == VT_LLONG) { - lexpand_nr(); - size = 8; - r = gv(RC_INT); - o(0xE52D0004|(intr(r)<<12)); /* push r */ - vtop--; - } - r = gv(RC_INT); - o(0xE52D0004|(intr(r)<<12)); /* push r */ - } - if (i == STACK_CLASS && pplan->prev) - gadd_sp(pplan->prev->end - pplan->start); /* Add padding if any */ - } - break; - - case VFP_CLASS: - gv(regmask(TREG_F0 + (pplan->start >> 1))); - if (pplan->start & 1) { /* Must be in upper part of double register */ - o(0xEEF00A40|((pplan->start>>1)<<12)|(pplan->start>>1)); /* vmov.f32 s(n+1), sn */ - vtop->r = VT_CONST; /* avoid being saved on stack by gv for next float */ - } - break; - - case CORE_CLASS: - if ((pplan->sval->type.t & VT_BTYPE) == VT_LLONG) { - lexpand_nr(); - gv(regmask(pplan->end)); - pplan->sval->r2 = vtop->r; - vtop--; - } - gv(regmask(pplan->start)); - /* Mark register as used so that gcall_or_jmp use another one - (regs >=4 are free as never used to pass parameters) */ - pplan->sval->r = vtop->r; - break; - } - vtop--; - } - } - - /* second pass to restore registers that were saved on stack by accident. - Maybe redundant after the "lvalue_save" patch in tccgen.c:gv() */ - if (++pass < 2) - goto again; - - /* Manually free remaining registers since next parameters are loaded - * manually, without the help of gv(int). */ - save_regs(nb_args); - - if(todo) { - o(0xE8BD0000|todo); /* pop {todo} */ - for(pplan = plan->clsplans[CORE_STRUCT_CLASS]; pplan; pplan = pplan->prev) { - int r; - pplan->sval->r = pplan->start; - /* An SValue can only pin 2 registers at best (r and r2) but a structure - can occupy more than 2 registers. Thus, we need to push on the value - stack some fake parameter to have on SValue for each registers used - by a structure (r2 is not used). */ - for (r = pplan->start + 1; r <= pplan->end; r++) { - if (todo & (1 << r)) { - nb_extra_sval++; - vpushi(0); - vtop->r = r; - } - } - } - } - return nb_extra_sval; -} - -/* Generate function call. The function address is pushed first, then - all the parameters in call order. This functions pops all the - parameters and the function address. */ -void gfunc_call(int nb_args) -{ - int r, args_size; - int def_float_abi = float_abi; - int todo; - struct plan plan; - -#ifdef TCC_ARM_EABI - int variadic; - - if (float_abi == ARM_HARD_FLOAT) { - variadic = (vtop[-nb_args].type.ref->f.func_type == FUNC_ELLIPSIS); - if (variadic || floats_in_core_regs(&vtop[-nb_args])) - float_abi = ARM_SOFTFP_FLOAT; - } -#endif - /* cannot let cpu flags if other instruction are generated. Also avoid leaving - VT_JMP anywhere except on the top of the stack because it would complicate - the code generator. */ - r = vtop->r & VT_VALMASK; - if (r == VT_CMP || (r & ~1) == VT_JMP) - gv(RC_INT); - - args_size = assign_regs(nb_args, float_abi, &plan, &todo); - -#ifdef TCC_ARM_EABI - if (args_size & 7) { /* Stack must be 8 byte aligned at fct call for EABI */ - args_size = (args_size + 7) & ~7; - o(0xE24DD004); /* sub sp, sp, #4 */ - } -#endif - - nb_args += copy_params(nb_args, &plan, todo); - tcc_free(plan.pplans); - - /* Move fct SValue on top as required by gcall_or_jmp */ - vrotb(nb_args + 1); - gcall_or_jmp(0); - if (args_size) - gadd_sp(args_size); /* pop all parameters passed on the stack */ -#if defined(TCC_ARM_EABI) && defined(TCC_ARM_VFP) - if(float_abi == ARM_SOFTFP_FLOAT && is_float(vtop->type.ref->type.t)) { - if((vtop->type.ref->type.t & VT_BTYPE) == VT_FLOAT) { - o(0xEE000A10); /*vmov s0, r0 */ - } else { - o(0xEE000B10); /* vmov.32 d0[0], r0 */ - o(0xEE201B10); /* vmov.32 d0[1], r1 */ - } - } -#endif - vtop -= nb_args + 1; /* Pop all params and fct address from value stack */ - leaffunc = 0; /* we are calling a function, so we aren't in a leaf function */ - float_abi = def_float_abi; -} - -/* generate function prolog of type 't' */ -void gfunc_prolog(CType *func_type) -{ - Sym *sym,*sym2; - int n, nf, size, align, rs, struct_ret = 0; - int addr, pn, sn; /* pn=core, sn=stack */ - CType ret_type; - -#ifdef TCC_ARM_EABI - struct avail_regs avregs = AVAIL_REGS_INITIALIZER; -#endif - - sym = func_type->ref; - func_vt = sym->type; - func_var = (func_type->ref->f.func_type == FUNC_ELLIPSIS); - - n = nf = 0; - if ((func_vt.t & VT_BTYPE) == VT_STRUCT && - !gfunc_sret(&func_vt, func_var, &ret_type, &align, &rs)) - { - n++; - struct_ret = 1; - func_vc = 12; /* Offset from fp of the place to store the result */ - } - for(sym2 = sym->next; sym2 && (n < 4 || nf < 16); sym2 = sym2->next) { - size = type_size(&sym2->type, &align); -#ifdef TCC_ARM_EABI - if (float_abi == ARM_HARD_FLOAT && !func_var && - (is_float(sym2->type.t) || is_hgen_float_aggr(&sym2->type))) { - int tmpnf = assign_vfpreg(&avregs, align, size); - tmpnf += (size + 3) / 4; - nf = (tmpnf > nf) ? tmpnf : nf; - } else -#endif - if (n < 4) - n += (size + 3) / 4; - } - o(0xE1A0C00D); /* mov ip,sp */ - if (func_var) - n=4; - if (n) { - if(n>4) - n=4; -#ifdef TCC_ARM_EABI - n=(n+1)&-2; -#endif - o(0xE92D0000|((1<16) - nf=16; - nf=(nf+1)&-2; /* nf => HARDFLOAT => EABI */ - o(0xED2D0A00|nf); /* save s0-s15 on stack if needed */ - } - o(0xE92D5800); /* save fp, ip, lr */ - o(0xE1A0B00D); /* mov fp, sp */ - func_sub_sp_offset = ind; - o(0xE1A00000); /* nop, leave space for stack adjustment in epilog */ - -#ifdef TCC_ARM_EABI - if (float_abi == ARM_HARD_FLOAT) { - func_vc += nf * 4; - avregs = AVAIL_REGS_INITIALIZER; - } -#endif - pn = struct_ret, sn = 0; - while ((sym = sym->next)) { - CType *type; - type = &sym->type; - size = type_size(type, &align); - size = (size + 3) >> 2; - align = (align + 3) & ~3; -#ifdef TCC_ARM_EABI - if (float_abi == ARM_HARD_FLOAT && !func_var && (is_float(sym->type.t) - || is_hgen_float_aggr(&sym->type))) { - int fpn = assign_vfpreg(&avregs, align, size << 2); - if (fpn >= 0) - addr = fpn * 4; - else - goto from_stack; - } else -#endif - if (pn < 4) { -#ifdef TCC_ARM_EABI - pn = (pn + (align-1)/4) & -(align/4); -#endif - addr = (nf + pn) * 4; - pn += size; - if (!sn && pn > 4) - sn = (pn - 4); - } else { -#ifdef TCC_ARM_EABI -from_stack: - sn = (sn + (align-1)/4) & -(align/4); -#endif - addr = (n + nf + sn) * 4; - sn += size; - } - sym_push(sym->v & ~SYM_FIELD, type, VT_LOCAL | lvalue_type(type->t), - addr + 12); - } - last_itod_magic=0; - leaffunc = 1; - loc = 0; -} - -/* generate function epilog */ -void gfunc_epilog(void) -{ - uint32_t x; - int diff; - /* Copy float return value to core register if base standard is used and - float computation is made with VFP */ -#if defined(TCC_ARM_EABI) && defined(TCC_ARM_VFP) - if ((float_abi == ARM_SOFTFP_FLOAT || func_var) && is_float(func_vt.t)) { - if((func_vt.t & VT_BTYPE) == VT_FLOAT) - o(0xEE100A10); /* fmrs r0, s0 */ - else { - o(0xEE100B10); /* fmrdl r0, d0 */ - o(0xEE301B10); /* fmrdh r1, d0 */ - } - } -#endif - o(0xE89BA800); /* restore fp, sp, pc */ - diff = (-loc + 3) & -4; -#ifdef TCC_ARM_EABI - if(!leaffunc) - diff = ((diff + 11) & -8) - 4; -#endif - if(diff > 0) { - x=stuff_const(0xE24BD000, diff); /* sub sp,fp,# */ - if(x) - *(uint32_t *)(cur_text_section->data + func_sub_sp_offset) = x; - else { - int addr; - addr=ind; - o(0xE59FC004); /* ldr ip,[pc+4] */ - o(0xE04BD00C); /* sub sp,fp,ip */ - o(0xE1A0F00E); /* mov pc,lr */ - o(diff); - *(uint32_t *)(cur_text_section->data + func_sub_sp_offset) = 0xE1000000|encbranch(func_sub_sp_offset,addr,1); - } - } -} - -/* generate a jump to a label */ -int gjmp(int t) -{ - int r; - if (nocode_wanted) - return t; - r=ind; - o(0xE0000000|encbranch(r,t,1)); - return r; -} - -/* generate a jump to a fixed address */ -void gjmp_addr(int a) -{ - gjmp(a); -} - -/* generate a test. set 'inv' to invert test. Stack entry is popped */ -int gtst(int inv, int t) -{ - int v, r; - uint32_t op; - - v = vtop->r & VT_VALMASK; - r=ind; - - if (nocode_wanted) { - ; - } else if (v == VT_CMP) { - op=mapcc(inv?negcc(vtop->c.i):vtop->c.i); - op|=encbranch(r,t,1); - o(op); - t=r; - } else if (v == VT_JMP || v == VT_JMPI) { - if ((v & 1) == inv) { - if(!vtop->c.i) - vtop->c.i=t; - else { - uint32_t *x; - int p,lp; - if(t) { - p = vtop->c.i; - do { - p = decbranch(lp=p); - } while(p); - x = (uint32_t *)(cur_text_section->data + lp); - *x &= 0xff000000; - *x |= encbranch(lp,t,1); - } - t = vtop->c.i; - } - } else { - t = gjmp(t); - gsym(vtop->c.i); - } - } - vtop--; - return t; -} - -/* generate an integer binary operation */ -void gen_opi(int op) -{ - int c, func = 0; - uint32_t opc = 0, r, fr; - unsigned short retreg = REG_IRET; - - c=0; - switch(op) { - case '+': - opc = 0x8; - c=1; - break; - case TOK_ADDC1: /* add with carry generation */ - opc = 0x9; - c=1; - break; - case '-': - opc = 0x4; - c=1; - break; - case TOK_SUBC1: /* sub with carry generation */ - opc = 0x5; - c=1; - break; - case TOK_ADDC2: /* add with carry use */ - opc = 0xA; - c=1; - break; - case TOK_SUBC2: /* sub with carry use */ - opc = 0xC; - c=1; - break; - case '&': - opc = 0x0; - c=1; - break; - case '^': - opc = 0x2; - c=1; - break; - case '|': - opc = 0x18; - c=1; - break; - case '*': - gv2(RC_INT, RC_INT); - r = vtop[-1].r; - fr = vtop[0].r; - vtop--; - o(0xE0000090|(intr(r)<<16)|(intr(r)<<8)|intr(fr)); - return; - case TOK_SHL: - opc = 0; - c=2; - break; - case TOK_SHR: - opc = 1; - c=2; - break; - case TOK_SAR: - opc = 2; - c=2; - break; - case '/': - case TOK_PDIV: - func=TOK___divsi3; - c=3; - break; - case TOK_UDIV: - func=TOK___udivsi3; - c=3; - break; - case '%': -#ifdef TCC_ARM_EABI - func=TOK___aeabi_idivmod; - retreg=REG_LRET; -#else - func=TOK___modsi3; -#endif - c=3; - break; - case TOK_UMOD: -#ifdef TCC_ARM_EABI - func=TOK___aeabi_uidivmod; - retreg=REG_LRET; -#else - func=TOK___umodsi3; -#endif - c=3; - break; - case TOK_UMULL: - gv2(RC_INT, RC_INT); - r=intr(vtop[-1].r2=get_reg(RC_INT)); - c=vtop[-1].r; - vtop[-1].r=get_reg_ex(RC_INT,regmask(c)); - vtop--; - o(0xE0800090|(r<<16)|(intr(vtop->r)<<12)|(intr(c)<<8)|intr(vtop[1].r)); - return; - default: - opc = 0x15; - c=1; - break; - } - switch(c) { - case 1: - if((vtop[-1].r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) { - if(opc == 4 || opc == 5 || opc == 0xc) { - vswap(); - opc|=2; // sub -> rsb - } - } - if ((vtop->r & VT_VALMASK) == VT_CMP || - (vtop->r & (VT_VALMASK & ~1)) == VT_JMP) - gv(RC_INT); - vswap(); - c=intr(gv(RC_INT)); - vswap(); - opc=0xE0000000|(opc<<20)|(c<<16); - if((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) { - uint32_t x; - x=stuff_const(opc|0x2000000,vtop->c.i); - if(x) { - r=intr(vtop[-1].r=get_reg_ex(RC_INT,regmask(vtop[-1].r))); - o(x|(r<<12)); - goto done; - } - } - fr=intr(gv(RC_INT)); - r=intr(vtop[-1].r=get_reg_ex(RC_INT,two2mask(vtop->r,vtop[-1].r))); - o(opc|(r<<12)|fr); -done: - vtop--; - if (op >= TOK_ULT && op <= TOK_GT) { - vtop->r = VT_CMP; - vtop->c.i = op; - } - break; - case 2: - opc=0xE1A00000|(opc<<5); - if ((vtop->r & VT_VALMASK) == VT_CMP || - (vtop->r & (VT_VALMASK & ~1)) == VT_JMP) - gv(RC_INT); - vswap(); - r=intr(gv(RC_INT)); - vswap(); - opc|=r; - if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) { - fr=intr(vtop[-1].r=get_reg_ex(RC_INT,regmask(vtop[-1].r))); - c = vtop->c.i & 0x1f; - o(opc|(c<<7)|(fr<<12)); - } else { - fr=intr(gv(RC_INT)); - c=intr(vtop[-1].r=get_reg_ex(RC_INT,two2mask(vtop->r,vtop[-1].r))); - o(opc|(c<<12)|(fr<<8)|0x10); - } - vtop--; - break; - case 3: - vpush_global_sym(&func_old_type, func); - vrott(3); - gfunc_call(2); - vpushi(0); - vtop->r = retreg; - break; - default: - tcc_error("gen_opi %i unimplemented!",op); - } -} - -#ifdef TCC_ARM_VFP -static int is_zero(int i) -{ - if((vtop[i].r & (VT_VALMASK | VT_LVAL | VT_SYM)) != VT_CONST) - return 0; - if (vtop[i].type.t == VT_FLOAT) - return (vtop[i].c.f == 0.f); - else if (vtop[i].type.t == VT_DOUBLE) - return (vtop[i].c.d == 0.0); - return (vtop[i].c.ld == 0.l); -} - -/* generate a floating point operation 'v = t1 op t2' instruction. The - * two operands are guaranteed to have the same floating point type */ -void gen_opf(int op) -{ - uint32_t x; - int fneg=0,r; - x=0xEE000A00|T2CPR(vtop->type.t); - switch(op) { - case '+': - if(is_zero(-1)) - vswap(); - if(is_zero(0)) { - vtop--; - return; - } - x|=0x300000; - break; - case '-': - x|=0x300040; - if(is_zero(0)) { - vtop--; - return; - } - if(is_zero(-1)) { - x|=0x810000; /* fsubX -> fnegX */ - vswap(); - vtop--; - fneg=1; - } - break; - case '*': - x|=0x200000; - break; - case '/': - x|=0x800000; - break; - default: - if(op < TOK_ULT || op > TOK_GT) { - tcc_error("unknown fp op %x!",op); - return; - } - if(is_zero(-1)) { - vswap(); - switch(op) { - case TOK_LT: op=TOK_GT; break; - case TOK_GE: op=TOK_ULE; break; - case TOK_LE: op=TOK_GE; break; - case TOK_GT: op=TOK_ULT; break; - } - } - x|=0xB40040; /* fcmpX */ - if(op!=TOK_EQ && op!=TOK_NE) - x|=0x80; /* fcmpX -> fcmpeX */ - if(is_zero(0)) { - vtop--; - o(x|0x10000|(vfpr(gv(RC_FLOAT))<<12)); /* fcmp(e)X -> fcmp(e)zX */ - } else { - x|=vfpr(gv(RC_FLOAT)); - vswap(); - o(x|(vfpr(gv(RC_FLOAT))<<12)); - vtop--; - } - o(0xEEF1FA10); /* fmstat */ - - switch(op) { - case TOK_LE: op=TOK_ULE; break; - case TOK_LT: op=TOK_ULT; break; - case TOK_UGE: op=TOK_GE; break; - case TOK_UGT: op=TOK_GT; break; - } - - vtop->r = VT_CMP; - vtop->c.i = op; - return; - } - r=gv(RC_FLOAT); - x|=vfpr(r); - r=regmask(r); - if(!fneg) { - int r2; - vswap(); - r2=gv(RC_FLOAT); - x|=vfpr(r2)<<16; - r|=regmask(r2); - } - vtop->r=get_reg_ex(RC_FLOAT,r); - if(!fneg) - vtop--; - o(x|(vfpr(vtop->r)<<12)); -} - -#else -static uint32_t is_fconst() -{ - long double f; - uint32_t r; - if((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) != VT_CONST) - return 0; - if (vtop->type.t == VT_FLOAT) - f = vtop->c.f; - else if (vtop->type.t == VT_DOUBLE) - f = vtop->c.d; - else - f = vtop->c.ld; - if(!ieee_finite(f)) - return 0; - r=0x8; - if(f<0.0) { - r=0x18; - f=-f; - } - if(f==0.0) - return r; - if(f==1.0) - return r|1; - if(f==2.0) - return r|2; - if(f==3.0) - return r|3; - if(f==4.0) - return r|4; - if(f==5.0) - return r|5; - if(f==0.5) - return r|6; - if(f==10.0) - return r|7; - return 0; -} - -/* generate a floating point operation 'v = t1 op t2' instruction. The - two operands are guaranteed to have the same floating point type */ -void gen_opf(int op) -{ - uint32_t x, r, r2, c1, c2; - //fputs("gen_opf\n",stderr); - vswap(); - c1 = is_fconst(); - vswap(); - c2 = is_fconst(); - x=0xEE000100; -#if LDOUBLE_SIZE == 8 - if ((vtop->type.t & VT_BTYPE) != VT_FLOAT) - x|=0x80; -#else - if ((vtop->type.t & VT_BTYPE) == VT_DOUBLE) - x|=0x80; - else if ((vtop->type.t & VT_BTYPE) == VT_LDOUBLE) - x|=0x80000; -#endif - switch(op) - { - case '+': - if(!c2) { - vswap(); - c2=c1; - } - vswap(); - r=fpr(gv(RC_FLOAT)); - vswap(); - if(c2) { - if(c2>0xf) - x|=0x200000; // suf - r2=c2&0xf; - } else { - r2=fpr(gv(RC_FLOAT)); - } - break; - case '-': - if(c2) { - if(c2<=0xf) - x|=0x200000; // suf - r2=c2&0xf; - vswap(); - r=fpr(gv(RC_FLOAT)); - vswap(); - } else if(c1 && c1<=0xf) { - x|=0x300000; // rsf - r2=c1; - r=fpr(gv(RC_FLOAT)); - vswap(); - } else { - x|=0x200000; // suf - vswap(); - r=fpr(gv(RC_FLOAT)); - vswap(); - r2=fpr(gv(RC_FLOAT)); - } - break; - case '*': - if(!c2 || c2>0xf) { - vswap(); - c2=c1; - } - vswap(); - r=fpr(gv(RC_FLOAT)); - vswap(); - if(c2 && c2<=0xf) - r2=c2; - else - r2=fpr(gv(RC_FLOAT)); - x|=0x100000; // muf - break; - case '/': - if(c2 && c2<=0xf) { - x|=0x400000; // dvf - r2=c2; - vswap(); - r=fpr(gv(RC_FLOAT)); - vswap(); - } else if(c1 && c1<=0xf) { - x|=0x500000; // rdf - r2=c1; - r=fpr(gv(RC_FLOAT)); - vswap(); - } else { - x|=0x400000; // dvf - vswap(); - r=fpr(gv(RC_FLOAT)); - vswap(); - r2=fpr(gv(RC_FLOAT)); - } - break; - default: - if(op >= TOK_ULT && op <= TOK_GT) { - x|=0xd0f110; // cmfe -/* bug (intention?) in Linux FPU emulator - doesn't set carry if equal */ - switch(op) { - case TOK_ULT: - case TOK_UGE: - case TOK_ULE: - case TOK_UGT: - tcc_error("unsigned comparison on floats?"); - break; - case TOK_LT: - op=TOK_Nset; - break; - case TOK_LE: - op=TOK_ULE; /* correct in unordered case only if AC bit in FPSR set */ - break; - case TOK_EQ: - case TOK_NE: - x&=~0x400000; // cmfe -> cmf - break; - } - if(c1 && !c2) { - c2=c1; - vswap(); - switch(op) { - case TOK_Nset: - op=TOK_GT; - break; - case TOK_GE: - op=TOK_ULE; - break; - case TOK_ULE: - op=TOK_GE; - break; - case TOK_GT: - op=TOK_Nset; - break; - } - } - vswap(); - r=fpr(gv(RC_FLOAT)); - vswap(); - if(c2) { - if(c2>0xf) - x|=0x200000; - r2=c2&0xf; - } else { - r2=fpr(gv(RC_FLOAT)); - } - vtop[-1].r = VT_CMP; - vtop[-1].c.i = op; - } else { - tcc_error("unknown fp op %x!",op); - return; - } - } - if(vtop[-1].r == VT_CMP) - c1=15; - else { - c1=vtop->r; - if(r2&0x8) - c1=vtop[-1].r; - vtop[-1].r=get_reg_ex(RC_FLOAT,two2mask(vtop[-1].r,c1)); - c1=fpr(vtop[-1].r); - } - vtop--; - o(x|(r<<16)|(c1<<12)|r2); -} -#endif - -/* convert integers to fp 't' type. Must handle 'int', 'unsigned int' - and 'long long' cases. */ -ST_FUNC void gen_cvt_itof1(int t) -{ - uint32_t r, r2; - int bt; - bt=vtop->type.t & VT_BTYPE; - if(bt == VT_INT || bt == VT_SHORT || bt == VT_BYTE) { -#ifndef TCC_ARM_VFP - uint32_t dsize = 0; -#endif - r=intr(gv(RC_INT)); -#ifdef TCC_ARM_VFP - r2=vfpr(vtop->r=get_reg(RC_FLOAT)); - o(0xEE000A10|(r<<12)|(r2<<16)); /* fmsr */ - r2|=r2<<12; - if(!(vtop->type.t & VT_UNSIGNED)) - r2|=0x80; /* fuitoX -> fsituX */ - o(0xEEB80A40|r2|T2CPR(t)); /* fYitoX*/ -#else - r2=fpr(vtop->r=get_reg(RC_FLOAT)); - if((t & VT_BTYPE) != VT_FLOAT) - dsize=0x80; /* flts -> fltd */ - o(0xEE000110|dsize|(r2<<16)|(r<<12)); /* flts */ - if((vtop->type.t & (VT_UNSIGNED|VT_BTYPE)) == (VT_UNSIGNED|VT_INT)) { - uint32_t off = 0; - o(0xE3500000|(r<<12)); /* cmp */ - r=fpr(get_reg(RC_FLOAT)); - if(last_itod_magic) { - off=ind+8-last_itod_magic; - off/=4; - if(off>255) - off=0; - } - o(0xBD1F0100|(r<<12)|off); /* ldflts */ - if(!off) { - o(0xEA000000); /* b */ - last_itod_magic=ind; - o(0x4F800000); /* 4294967296.0f */ - } - o(0xBE000100|dsize|(r2<<16)|(r2<<12)|r); /* adflt */ - } -#endif - return; - } else if(bt == VT_LLONG) { - int func; - CType *func_type = 0; - if((t & VT_BTYPE) == VT_FLOAT) { - func_type = &func_float_type; - if(vtop->type.t & VT_UNSIGNED) - func=TOK___floatundisf; - else - func=TOK___floatdisf; -#if LDOUBLE_SIZE != 8 - } else if((t & VT_BTYPE) == VT_LDOUBLE) { - func_type = &func_ldouble_type; - if(vtop->type.t & VT_UNSIGNED) - func=TOK___floatundixf; - else - func=TOK___floatdixf; - } else if((t & VT_BTYPE) == VT_DOUBLE) { -#else - } else if((t & VT_BTYPE) == VT_DOUBLE || (t & VT_BTYPE) == VT_LDOUBLE) { -#endif - func_type = &func_double_type; - if(vtop->type.t & VT_UNSIGNED) - func=TOK___floatundidf; - else - func=TOK___floatdidf; - } - if(func_type) { - vpush_global_sym(func_type, func); - vswap(); - gfunc_call(1); - vpushi(0); - vtop->r=TREG_F0; - return; - } - } - tcc_error("unimplemented gen_cvt_itof %x!",vtop->type.t); -} - -/* convert fp to int 't' type */ -void gen_cvt_ftoi(int t) -{ - uint32_t r, r2; - int u, func = 0; - u=t&VT_UNSIGNED; - t&=VT_BTYPE; - r2=vtop->type.t & VT_BTYPE; - if(t==VT_INT) { -#ifdef TCC_ARM_VFP - r=vfpr(gv(RC_FLOAT)); - u=u?0:0x10000; - o(0xEEBC0AC0|(r<<12)|r|T2CPR(r2)|u); /* ftoXizY */ - r2=intr(vtop->r=get_reg(RC_INT)); - o(0xEE100A10|(r<<16)|(r2<<12)); - return; -#else - if(u) { - if(r2 == VT_FLOAT) - func=TOK___fixunssfsi; -#if LDOUBLE_SIZE != 8 - else if(r2 == VT_LDOUBLE) - func=TOK___fixunsxfsi; - else if(r2 == VT_DOUBLE) -#else - else if(r2 == VT_LDOUBLE || r2 == VT_DOUBLE) -#endif - func=TOK___fixunsdfsi; - } else { - r=fpr(gv(RC_FLOAT)); - r2=intr(vtop->r=get_reg(RC_INT)); - o(0xEE100170|(r2<<12)|r); - return; - } -#endif - } else if(t == VT_LLONG) { // unsigned handled in gen_cvt_ftoi1 - if(r2 == VT_FLOAT) - func=TOK___fixsfdi; -#if LDOUBLE_SIZE != 8 - else if(r2 == VT_LDOUBLE) - func=TOK___fixxfdi; - else if(r2 == VT_DOUBLE) -#else - else if(r2 == VT_LDOUBLE || r2 == VT_DOUBLE) -#endif - func=TOK___fixdfdi; - } - if(func) { - vpush_global_sym(&func_old_type, func); - vswap(); - gfunc_call(1); - vpushi(0); - if(t == VT_LLONG) - vtop->r2 = REG_LRET; - vtop->r = REG_IRET; - return; - } - tcc_error("unimplemented gen_cvt_ftoi!"); -} - -/* convert from one floating point type to another */ -void gen_cvt_ftof(int t) -{ -#ifdef TCC_ARM_VFP - if(((vtop->type.t & VT_BTYPE) == VT_FLOAT) != ((t & VT_BTYPE) == VT_FLOAT)) { - uint32_t r = vfpr(gv(RC_FLOAT)); - o(0xEEB70AC0|(r<<12)|r|T2CPR(vtop->type.t)); - } -#else - /* all we have to do on i386 and FPA ARM is to put the float in a register */ - gv(RC_FLOAT); -#endif -} - -/* computed goto support */ -void ggoto(void) -{ - gcall_or_jmp(1); - vtop--; -} - -/* Save the stack pointer onto the stack and return the location of its address */ -ST_FUNC void gen_vla_sp_save(int addr) { - SValue v; - v.type.t = VT_PTR; - v.r = VT_LOCAL | VT_LVAL; - v.c.i = addr; - store(TREG_SP, &v); -} - -/* Restore the SP from a location on the stack */ -ST_FUNC void gen_vla_sp_restore(int addr) { - SValue v; - v.type.t = VT_PTR; - v.r = VT_LOCAL | VT_LVAL; - v.c.i = addr; - load(TREG_SP, &v); -} - -/* Subtract from the stack pointer, and push the resulting value onto the stack */ -ST_FUNC void gen_vla_alloc(CType *type, int align) { - int r = intr(gv(RC_INT)); - o(0xE04D0000|(r<<12)|r); /* sub r, sp, r */ -#ifdef TCC_ARM_EABI - if (align < 8) - align = 8; -#else - if (align < 4) - align = 4; -#endif - if (align & (align - 1)) - tcc_error("alignment is not a power of 2: %i", align); - o(stuff_const(0xE3C0D000|(r<<16), align - 1)); /* bic sp, r, #align-1 */ - vpop(); -} - -/* end of ARM code generator */ -/*************************************************************/ -#endif -/*************************************************************/ diff --git a/05/tcc-final-old/arm-link.c b/05/tcc-final-old/arm-link.c deleted file mode 100644 index 92a24eb..0000000 --- a/05/tcc-final-old/arm-link.c +++ /dev/null @@ -1,398 +0,0 @@ -#ifdef TARGET_DEFS_ONLY - -#define EM_TCC_TARGET EM_ARM - -/* relocation type for 32 bit data relocation */ -#define R_DATA_32 R_ARM_ABS32 -#define R_DATA_PTR R_ARM_ABS32 -#define R_JMP_SLOT R_ARM_JUMP_SLOT -#define R_GLOB_DAT R_ARM_GLOB_DAT -#define R_COPY R_ARM_COPY -#define R_RELATIVE R_ARM_RELATIVE - -#define R_NUM R_ARM_NUM - -#define ELF_START_ADDR 0x00008000 -#define ELF_PAGE_SIZE 0x1000 - -#define PCRELATIVE_DLLPLT 1 -#define RELOCATE_DLLPLT 0 - -enum float_abi { - ARM_SOFTFP_FLOAT, - ARM_HARD_FLOAT, -}; - -#else /* !TARGET_DEFS_ONLY */ - -#include "tcc.h" - -/* Returns 1 for a code relocation, 0 for a data relocation. For unknown - relocations, returns -1. */ -int code_reloc (int reloc_type) -{ - switch (reloc_type) { - case R_ARM_MOVT_ABS: - case R_ARM_MOVW_ABS_NC: - case R_ARM_THM_MOVT_ABS: - case R_ARM_THM_MOVW_ABS_NC: - case R_ARM_ABS32: - case R_ARM_REL32: - case R_ARM_GOTPC: - case R_ARM_GOTOFF: - case R_ARM_GOT32: - case R_ARM_COPY: - case R_ARM_GLOB_DAT: - case R_ARM_NONE: - return 0; - - case R_ARM_PC24: - case R_ARM_CALL: - case R_ARM_JUMP24: - case R_ARM_PLT32: - case R_ARM_THM_PC22: - case R_ARM_THM_JUMP24: - case R_ARM_PREL31: - case R_ARM_V4BX: - case R_ARM_JUMP_SLOT: - return 1; - } - - tcc_error ("Unknown relocation type: %d", reloc_type); - return -1; -} - -/* Returns an enumerator to describe whether and when the relocation needs a - GOT and/or PLT entry to be created. See tcc.h for a description of the - different values. */ -int gotplt_entry_type (int reloc_type) -{ - switch (reloc_type) { - case R_ARM_NONE: - case R_ARM_COPY: - case R_ARM_GLOB_DAT: - case R_ARM_JUMP_SLOT: - return NO_GOTPLT_ENTRY; - - case R_ARM_PC24: - case R_ARM_CALL: - case R_ARM_JUMP24: - case R_ARM_PLT32: - case R_ARM_THM_PC22: - case R_ARM_THM_JUMP24: - case R_ARM_MOVT_ABS: - case R_ARM_MOVW_ABS_NC: - case R_ARM_THM_MOVT_ABS: - case R_ARM_THM_MOVW_ABS_NC: - case R_ARM_PREL31: - case R_ARM_ABS32: - case R_ARM_REL32: - case R_ARM_V4BX: - return AUTO_GOTPLT_ENTRY; - - case R_ARM_GOTPC: - case R_ARM_GOTOFF: - return BUILD_GOT_ONLY; - - case R_ARM_GOT32: - return ALWAYS_GOTPLT_ENTRY; - } - - tcc_error ("Unknown relocation type: %d", reloc_type); - return -1; -} - -ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr) -{ - Section *plt = s1->plt; - uint8_t *p; - unsigned plt_offset; - - /* when building a DLL, GOT entry accesses must be done relative to - start of GOT (see x86_64 example above) */ - if (s1->output_type == TCC_OUTPUT_DLL) - tcc_error("DLLs unimplemented!"); - - /* empty PLT: create PLT0 entry that push address of call site and - jump to ld.so resolution routine (GOT + 8) */ - if (plt->data_offset == 0) { - p = section_ptr_add(plt, 20); - write32le(p, 0xe52de004); /* push {lr} */ - write32le(p+4, 0xe59fe004); /* ldr lr, [pc, #4] */ - write32le(p+8, 0xe08fe00e); /* add lr, pc, lr */ - write32le(p+12, 0xe5bef008); /* ldr pc, [lr, #8]! */ - /* p+16 is set in relocate_plt */ - } - plt_offset = plt->data_offset; - - if (attr->plt_thumb_stub) { - p = section_ptr_add(plt, 4); - write32le(p, 0x4778); /* bx pc */ - write32le(p+2, 0x46c0); /* nop */ - } - p = section_ptr_add(plt, 16); - /* Jump to GOT entry where ld.so initially put address of PLT0 */ - write32le(p, 0xe59fc004); /* ldr ip, [pc, #4] */ - write32le(p+4, 0xe08fc00c); /* add ip, pc, ip */ - write32le(p+8, 0xe59cf000); /* ldr pc, [ip] */ - /* p + 12 contains offset to GOT entry once patched by relocate_plt */ - write32le(p+12, got_offset); - return plt_offset; -} - -/* relocate the PLT: compute addresses and offsets in the PLT now that final - address for PLT and GOT are known (see fill_program_header) */ -ST_FUNC void relocate_plt(TCCState *s1) -{ - uint8_t *p, *p_end; - - if (!s1->plt) - return; - - p = s1->plt->data; - p_end = p + s1->plt->data_offset; - - if (p < p_end) { - int x = s1->got->sh_addr - s1->plt->sh_addr - 12; - write32le(s1->plt->data + 16, x - 16); - p += 20; - while (p < p_end) { - if (read32le(p) == 0x46c04778) /* PLT Thumb stub present */ - p += 4; - add32le(p + 12, x + s1->plt->data - p); - p += 16; - } - } -} - -void relocate_init(Section *sr) {} - -void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val) -{ - ElfW(Sym) *sym; - int sym_index; - - sym_index = ELFW(R_SYM)(rel->r_info); - sym = &((ElfW(Sym) *)symtab_section->data)[sym_index]; - - switch(type) { - case R_ARM_PC24: - case R_ARM_CALL: - case R_ARM_JUMP24: - case R_ARM_PLT32: - { - int x, is_thumb, is_call, h, blx_avail, is_bl, th_ko; - x = (*(int *) ptr) & 0xffffff; -#ifdef DEBUG_RELOC - printf ("reloc %d: x=0x%x val=0x%x ", type, x, val); -#endif - (*(int *)ptr) &= 0xff000000; - if (x & 0x800000) - x -= 0x1000000; - x <<= 2; - blx_avail = (TCC_CPU_VERSION >= 5); - is_thumb = val & 1; - is_bl = (*(unsigned *) ptr) >> 24 == 0xeb; - is_call = (type == R_ARM_CALL || (type == R_ARM_PC24 && is_bl)); - x += val - addr; -#ifdef DEBUG_RELOC - printf (" newx=0x%x name=%s\n", x, - (char *) symtab_section->link->data + sym->st_name); -#endif - h = x & 2; - th_ko = (x & 3) && (!blx_avail || !is_call); - if (th_ko || x >= 0x2000000 || x < -0x2000000) - tcc_error("can't relocate value at %x,%d",addr, type); - x >>= 2; - x &= 0xffffff; - /* Only reached if blx is avail and it is a call */ - if (is_thumb) { - x |= h << 24; - (*(int *)ptr) = 0xfa << 24; /* bl -> blx */ - } - (*(int *) ptr) |= x; - } - return; - /* Since these relocations only concern Thumb-2 and blx instruction was - introduced before Thumb-2, we can assume blx is available and not - guard its use */ - case R_ARM_THM_PC22: - case R_ARM_THM_JUMP24: - { - int x, hi, lo, s, j1, j2, i1, i2, imm10, imm11; - int to_thumb, is_call, to_plt, blx_bit = 1 << 12; - Section *plt; - - /* weak reference */ - if (sym->st_shndx == SHN_UNDEF && - ELFW(ST_BIND)(sym->st_info) == STB_WEAK) - return; - - /* Get initial offset */ - hi = (*(uint16_t *)ptr); - lo = (*(uint16_t *)(ptr+2)); - s = (hi >> 10) & 1; - j1 = (lo >> 13) & 1; - j2 = (lo >> 11) & 1; - i1 = (j1 ^ s) ^ 1; - i2 = (j2 ^ s) ^ 1; - imm10 = hi & 0x3ff; - imm11 = lo & 0x7ff; - x = (s << 24) | (i1 << 23) | (i2 << 22) | - (imm10 << 12) | (imm11 << 1); - if (x & 0x01000000) - x -= 0x02000000; - - /* Relocation infos */ - to_thumb = val & 1; - plt = s1->plt; - to_plt = (val >= plt->sh_addr) && - (val < plt->sh_addr + plt->data_offset); - is_call = (type == R_ARM_THM_PC22); - - if (!to_thumb && !to_plt && !is_call) { - int index; - uint8_t *p; - char *name, buf[1024]; - Section *text_section; - - name = (char *) symtab_section->link->data + sym->st_name; - text_section = s1->sections[sym->st_shndx]; - /* Modify reloc to target a thumb stub to switch to ARM */ - snprintf(buf, sizeof(buf), "%s_from_thumb", name); - index = put_elf_sym(symtab_section, - text_section->data_offset + 1, - sym->st_size, sym->st_info, 0, - sym->st_shndx, buf); - to_thumb = 1; - val = text_section->data_offset + 1; - rel->r_info = ELFW(R_INFO)(index, type); - /* Create a thumb stub function to switch to ARM mode */ - put_elf_reloc(symtab_section, text_section, - text_section->data_offset + 4, R_ARM_JUMP24, - sym_index); - p = section_ptr_add(text_section, 8); - write32le(p, 0x4778); /* bx pc */ - write32le(p+2, 0x46c0); /* nop */ - write32le(p+4, 0xeafffffe); /* b $sym */ - } - - /* Compute final offset */ - x += val - addr; - if (!to_thumb && is_call) { - blx_bit = 0; /* bl -> blx */ - x = (x + 3) & -4; /* Compute offset from aligned PC */ - } - - /* Check that relocation is possible - * offset must not be out of range - * if target is to be entered in arm mode: - - bit 1 must not set - - instruction must be a call (bl) or a jump to PLT */ - if (!to_thumb || x >= 0x1000000 || x < -0x1000000) - if (to_thumb || (val & 2) || (!is_call && !to_plt)) - tcc_error("can't relocate value at %x,%d",addr, type); - - /* Compute and store final offset */ - s = (x >> 24) & 1; - i1 = (x >> 23) & 1; - i2 = (x >> 22) & 1; - j1 = s ^ (i1 ^ 1); - j2 = s ^ (i2 ^ 1); - imm10 = (x >> 12) & 0x3ff; - imm11 = (x >> 1) & 0x7ff; - (*(uint16_t *)ptr) = (uint16_t) ((hi & 0xf800) | - (s << 10) | imm10); - (*(uint16_t *)(ptr+2)) = (uint16_t) ((lo & 0xc000) | - (j1 << 13) | blx_bit | (j2 << 11) | - imm11); - } - return; - case R_ARM_MOVT_ABS: - case R_ARM_MOVW_ABS_NC: - { - int x, imm4, imm12; - if (type == R_ARM_MOVT_ABS) - val >>= 16; - imm12 = val & 0xfff; - imm4 = (val >> 12) & 0xf; - x = (imm4 << 16) | imm12; - if (type == R_ARM_THM_MOVT_ABS) - *(int *)ptr |= x; - else - *(int *)ptr += x; - } - return; - case R_ARM_THM_MOVT_ABS: - case R_ARM_THM_MOVW_ABS_NC: - { - int x, i, imm4, imm3, imm8; - if (type == R_ARM_THM_MOVT_ABS) - val >>= 16; - imm8 = val & 0xff; - imm3 = (val >> 8) & 0x7; - i = (val >> 11) & 1; - imm4 = (val >> 12) & 0xf; - x = (imm3 << 28) | (imm8 << 16) | (i << 10) | imm4; - if (type == R_ARM_THM_MOVT_ABS) - *(int *)ptr |= x; - else - *(int *)ptr += x; - } - return; - case R_ARM_PREL31: - { - int x; - x = (*(int *)ptr) & 0x7fffffff; - (*(int *)ptr) &= 0x80000000; - x = (x * 2) / 2; - x += val - addr; - if((x^(x>>1))&0x40000000) - tcc_error("can't relocate value at %x,%d",addr, type); - (*(int *)ptr) |= x & 0x7fffffff; - } - case R_ARM_ABS32: - *(int *)ptr += val; - return; - case R_ARM_REL32: - *(int *)ptr += val - addr; - return; - case R_ARM_GOTPC: - *(int *)ptr += s1->got->sh_addr - addr; - return; - case R_ARM_GOTOFF: - *(int *)ptr += val - s1->got->sh_addr; - return; - case R_ARM_GOT32: - /* we load the got offset */ - *(int *)ptr += s1->sym_attrs[sym_index].got_offset; - return; - case R_ARM_COPY: - return; - case R_ARM_V4BX: - /* trade Thumb support for ARMv4 support */ - if ((0x0ffffff0 & *(int*)ptr) == 0x012FFF10) - *(int*)ptr ^= 0xE12FFF10 ^ 0xE1A0F000; /* BX Rm -> MOV PC, Rm */ - return; - case R_ARM_GLOB_DAT: - case R_ARM_JUMP_SLOT: - *(addr_t *)ptr = val; - return; - case R_ARM_NONE: - /* Nothing to do. Normally used to indicate a dependency - on a certain symbol (like for exception handling under EABI). */ - return; - case R_ARM_RELATIVE: -#ifdef TCC_TARGET_PE - add32le(ptr, val - s1->pe_imagebase); -#endif - /* do nothing */ - return; - default: - fprintf(stderr,"FIXME: handle reloc type %x at %x [%p] to %x\n", - type, (unsigned)addr, ptr, (unsigned)val); - return; - } -} - -#endif /* !TARGET_DEFS_ONLY */ diff --git a/05/tcc-final-old/arm64-gen.c b/05/tcc-final-old/arm64-gen.c deleted file mode 100644 index 86b3af7..0000000 --- a/05/tcc-final-old/arm64-gen.c +++ /dev/null @@ -1,1837 +0,0 @@ -/* - * A64 code generator for TCC - * - * Copyright (c) 2014-2015 Edmund Grimley Evans - * - * Copying and distribution of this file, with or without modification, - * are permitted in any medium without royalty provided the copyright - * notice and this notice are preserved. This file is offered as-is, - * without any warranty. - */ - -#ifdef TARGET_DEFS_ONLY - -// Number of registers available to allocator: -#define NB_REGS 28 // x0-x18, x30, v0-v7 - -#define TREG_R(x) (x) // x = 0..18 -#define TREG_R30 19 -#define TREG_F(x) (x + 20) // x = 0..7 - -// Register classes sorted from more general to more precise: -#define RC_INT (1 << 0) -#define RC_FLOAT (1 << 1) -#define RC_R(x) (1 << (2 + (x))) // x = 0..18 -#define RC_R30 (1 << 21) -#define RC_F(x) (1 << (22 + (x))) // x = 0..7 - -#define RC_IRET (RC_R(0)) // int return register class -#define RC_FRET (RC_F(0)) // float return register class - -#define REG_IRET (TREG_R(0)) // int return register number -#define REG_FRET (TREG_F(0)) // float return register number - -#define PTR_SIZE 8 - -#define LDOUBLE_SIZE 16 -#define LDOUBLE_ALIGN 16 - -#define MAX_ALIGN 16 - -#define CHAR_IS_UNSIGNED - -/******************************************************/ -#else /* ! TARGET_DEFS_ONLY */ -/******************************************************/ -#include "tcc.h" -#include - -ST_DATA const int reg_classes[NB_REGS] = { - RC_INT | RC_R(0), - RC_INT | RC_R(1), - RC_INT | RC_R(2), - RC_INT | RC_R(3), - RC_INT | RC_R(4), - RC_INT | RC_R(5), - RC_INT | RC_R(6), - RC_INT | RC_R(7), - RC_INT | RC_R(8), - RC_INT | RC_R(9), - RC_INT | RC_R(10), - RC_INT | RC_R(11), - RC_INT | RC_R(12), - RC_INT | RC_R(13), - RC_INT | RC_R(14), - RC_INT | RC_R(15), - RC_INT | RC_R(16), - RC_INT | RC_R(17), - RC_INT | RC_R(18), - RC_R30, // not in RC_INT as we make special use of x30 - RC_FLOAT | RC_F(0), - RC_FLOAT | RC_F(1), - RC_FLOAT | RC_F(2), - RC_FLOAT | RC_F(3), - RC_FLOAT | RC_F(4), - RC_FLOAT | RC_F(5), - RC_FLOAT | RC_F(6), - RC_FLOAT | RC_F(7) -}; - -#define IS_FREG(x) ((x) >= TREG_F(0)) - -static uint32_t intr(int r) -{ - assert(TREG_R(0) <= r && r <= TREG_R30); - return r < TREG_R30 ? r : 30; -} - -static uint32_t fltr(int r) -{ - assert(TREG_F(0) <= r && r <= TREG_F(7)); - return r - TREG_F(0); -} - -// Add an instruction to text section: -ST_FUNC void o(unsigned int c) -{ - int ind1 = ind + 4; - if (nocode_wanted) - return; - if (ind1 > cur_text_section->data_allocated) - section_realloc(cur_text_section, ind1); - write32le(cur_text_section->data + ind, c); - ind = ind1; -} - -static int arm64_encode_bimm64(uint64_t x) -{ - int neg = x & 1; - int rep, pos, len; - - if (neg) - x = ~x; - if (!x) - return -1; - - if (x >> 2 == (x & (((uint64_t)1 << (64 - 2)) - 1))) - rep = 2, x &= ((uint64_t)1 << 2) - 1; - else if (x >> 4 == (x & (((uint64_t)1 << (64 - 4)) - 1))) - rep = 4, x &= ((uint64_t)1 << 4) - 1; - else if (x >> 8 == (x & (((uint64_t)1 << (64 - 8)) - 1))) - rep = 8, x &= ((uint64_t)1 << 8) - 1; - else if (x >> 16 == (x & (((uint64_t)1 << (64 - 16)) - 1))) - rep = 16, x &= ((uint64_t)1 << 16) - 1; - else if (x >> 32 == (x & (((uint64_t)1 << (64 - 32)) - 1))) - rep = 32, x &= ((uint64_t)1 << 32) - 1; - else - rep = 64; - - pos = 0; - if (!(x & (((uint64_t)1 << 32) - 1))) x >>= 32, pos += 32; - if (!(x & (((uint64_t)1 << 16) - 1))) x >>= 16, pos += 16; - if (!(x & (((uint64_t)1 << 8) - 1))) x >>= 8, pos += 8; - if (!(x & (((uint64_t)1 << 4) - 1))) x >>= 4, pos += 4; - if (!(x & (((uint64_t)1 << 2) - 1))) x >>= 2, pos += 2; - if (!(x & (((uint64_t)1 << 1) - 1))) x >>= 1, pos += 1; - - len = 0; - if (!(~x & (((uint64_t)1 << 32) - 1))) x >>= 32, len += 32; - if (!(~x & (((uint64_t)1 << 16) - 1))) x >>= 16, len += 16; - if (!(~x & (((uint64_t)1 << 8) - 1))) x >>= 8, len += 8; - if (!(~x & (((uint64_t)1 << 4) - 1))) x >>= 4, len += 4; - if (!(~x & (((uint64_t)1 << 2) - 1))) x >>= 2, len += 2; - if (!(~x & (((uint64_t)1 << 1) - 1))) x >>= 1, len += 1; - - if (x) - return -1; - if (neg) { - pos = (pos + len) & (rep - 1); - len = rep - len; - } - return ((0x1000 & rep << 6) | (((rep - 1) ^ 31) << 1 & 63) | - ((rep - pos) & (rep - 1)) << 6 | (len - 1)); -} - -static uint32_t arm64_movi(int r, uint64_t x) -{ - uint64_t m = 0xffff; - int e; - if (!(x & ~m)) - return 0x52800000 | r | x << 5; // movz w(r),#(x) - if (!(x & ~(m << 16))) - return 0x52a00000 | r | x >> 11; // movz w(r),#(x >> 16),lsl #16 - if (!(x & ~(m << 32))) - return 0xd2c00000 | r | x >> 27; // movz x(r),#(x >> 32),lsl #32 - if (!(x & ~(m << 48))) - return 0xd2e00000 | r | x >> 43; // movz x(r),#(x >> 48),lsl #48 - if ((x & ~m) == m << 16) - return (0x12800000 | r | - (~x << 5 & 0x1fffe0)); // movn w(r),#(~x) - if ((x & ~(m << 16)) == m) - return (0x12a00000 | r | - (~x >> 11 & 0x1fffe0)); // movn w(r),#(~x >> 16),lsl #16 - if (!~(x | m)) - return (0x92800000 | r | - (~x << 5 & 0x1fffe0)); // movn x(r),#(~x) - if (!~(x | m << 16)) - return (0x92a00000 | r | - (~x >> 11 & 0x1fffe0)); // movn x(r),#(~x >> 16),lsl #16 - if (!~(x | m << 32)) - return (0x92c00000 | r | - (~x >> 27 & 0x1fffe0)); // movn x(r),#(~x >> 32),lsl #32 - if (!~(x | m << 48)) - return (0x92e00000 | r | - (~x >> 43 & 0x1fffe0)); // movn x(r),#(~x >> 32),lsl #32 - if (!(x >> 32) && (e = arm64_encode_bimm64(x | x << 32)) >= 0) - return 0x320003e0 | r | (uint32_t)e << 10; // movi w(r),#(x) - if ((e = arm64_encode_bimm64(x)) >= 0) - return 0xb20003e0 | r | (uint32_t)e << 10; // movi x(r),#(x) - return 0; -} - -static void arm64_movimm(int r, uint64_t x) -{ - uint32_t i; - if ((i = arm64_movi(r, x))) - o(i); // a single MOV - else { - // MOVZ/MOVN and 1-3 MOVKs - int z = 0, m = 0; - uint32_t mov1 = 0xd2800000; // movz - uint64_t x1 = x; - for (i = 0; i < 64; i += 16) { - z += !(x >> i & 0xffff); - m += !(~x >> i & 0xffff); - } - if (m > z) { - x1 = ~x; - mov1 = 0x92800000; // movn - } - for (i = 0; i < 64; i += 16) - if (x1 >> i & 0xffff) { - o(mov1 | r | (x1 >> i & 0xffff) << 5 | i << 17); - // movz/movn x(r),#(*),lsl #(i) - break; - } - for (i += 16; i < 64; i += 16) - if (x1 >> i & 0xffff) - o(0xf2800000 | r | (x >> i & 0xffff) << 5 | i << 17); - // movk x(r),#(*),lsl #(i) - } -} - -// Patch all branches in list pointed to by t to branch to a: -ST_FUNC void gsym_addr(int t_, int a_) -{ - uint32_t t = t_; - uint32_t a = a_; - while (t) { - unsigned char *ptr = cur_text_section->data + t; - uint32_t next = read32le(ptr); - if (a - t + 0x8000000 >= 0x10000000) - tcc_error("branch out of range"); - write32le(ptr, (a - t == 4 ? 0xd503201f : // nop - 0x14000000 | ((a - t) >> 2 & 0x3ffffff))); // b - t = next; - } -} - -// Patch all branches in list pointed to by t to branch to current location: -ST_FUNC void gsym(int t) -{ - gsym_addr(t, ind); -} - -static int arm64_type_size(int t) -{ - switch (t & VT_BTYPE) { - case VT_INT: return 2; - case VT_BYTE: return 0; - case VT_SHORT: return 1; - case VT_PTR: return 3; - case VT_FUNC: return 3; - case VT_FLOAT: return 2; - case VT_DOUBLE: return 3; - case VT_LDOUBLE: return 4; - case VT_BOOL: return 0; - case VT_LLONG: return 3; - } - assert(0); - return 0; -} - -static void arm64_spoff(int reg, uint64_t off) -{ - uint32_t sub = off >> 63; - if (sub) - off = -off; - if (off < 4096) - o(0x910003e0 | sub << 30 | reg | off << 10); - // (add|sub) x(reg),sp,#(off) - else { - arm64_movimm(30, off); // use x30 for offset - o(0x8b3e63e0 | sub << 30 | reg); // (add|sub) x(reg),sp,x30 - } -} - -static void arm64_ldrx(int sg, int sz_, int dst, int bas, uint64_t off) -{ - uint32_t sz = sz_; - if (sz >= 2) - sg = 0; - if (!(off & ~((uint32_t)0xfff << sz))) - o(0x39400000 | dst | bas << 5 | off << (10 - sz) | - (uint32_t)!!sg << 23 | sz << 30); // ldr(*) x(dst),[x(bas),#(off)] - else if (off < 256 || -off <= 256) - o(0x38400000 | dst | bas << 5 | (off & 511) << 12 | - (uint32_t)!!sg << 23 | sz << 30); // ldur(*) x(dst),[x(bas),#(off)] - else { - arm64_movimm(30, off); // use x30 for offset - o(0x38206800 | dst | bas << 5 | (uint32_t)30 << 16 | - (uint32_t)(!!sg + 1) << 22 | sz << 30); // ldr(*) x(dst),[x(bas),x30] - } -} - -static void arm64_ldrv(int sz_, int dst, int bas, uint64_t off) -{ - uint32_t sz = sz_; - if (!(off & ~((uint32_t)0xfff << sz))) - o(0x3d400000 | dst | bas << 5 | off << (10 - sz) | - (sz & 4) << 21 | (sz & 3) << 30); // ldr (s|d|q)(dst),[x(bas),#(off)] - else if (off < 256 || -off <= 256) - o(0x3c400000 | dst | bas << 5 | (off & 511) << 12 | - (sz & 4) << 21 | (sz & 3) << 30); // ldur (s|d|q)(dst),[x(bas),#(off)] - else { - arm64_movimm(30, off); // use x30 for offset - o(0x3c606800 | dst | bas << 5 | (uint32_t)30 << 16 | - sz << 30 | (sz & 4) << 21); // ldr (s|d|q)(dst),[x(bas),x30] - } -} - -static void arm64_ldrs(int reg_, int size) -{ - uint32_t reg = reg_; - // Use x30 for intermediate value in some cases. - switch (size) { - default: assert(0); break; - case 1: - arm64_ldrx(0, 0, reg, reg, 0); - break; - case 2: - arm64_ldrx(0, 1, reg, reg, 0); - break; - case 3: - arm64_ldrx(0, 1, 30, reg, 0); - arm64_ldrx(0, 0, reg, reg, 2); - o(0x2a0043c0 | reg | reg << 16); // orr x(reg),x30,x(reg),lsl #16 - break; - case 4: - arm64_ldrx(0, 2, reg, reg, 0); - break; - case 5: - arm64_ldrx(0, 2, 30, reg, 0); - arm64_ldrx(0, 0, reg, reg, 4); - o(0xaa0083c0 | reg | reg << 16); // orr x(reg),x30,x(reg),lsl #32 - break; - case 6: - arm64_ldrx(0, 2, 30, reg, 0); - arm64_ldrx(0, 1, reg, reg, 4); - o(0xaa0083c0 | reg | reg << 16); // orr x(reg),x30,x(reg),lsl #32 - break; - case 7: - arm64_ldrx(0, 2, 30, reg, 0); - arm64_ldrx(0, 2, reg, reg, 3); - o(0x53087c00 | reg | reg << 5); // lsr w(reg), w(reg), #8 - o(0xaa0083c0 | reg | reg << 16); // orr x(reg),x30,x(reg),lsl #32 - break; - case 8: - arm64_ldrx(0, 3, reg, reg, 0); - break; - case 9: - arm64_ldrx(0, 0, reg + 1, reg, 8); - arm64_ldrx(0, 3, reg, reg, 0); - break; - case 10: - arm64_ldrx(0, 1, reg + 1, reg, 8); - arm64_ldrx(0, 3, reg, reg, 0); - break; - case 11: - arm64_ldrx(0, 2, reg + 1, reg, 7); - o(0x53087c00 | (reg+1) | (reg+1) << 5); // lsr w(reg+1), w(reg+1), #8 - arm64_ldrx(0, 3, reg, reg, 0); - break; - case 12: - arm64_ldrx(0, 2, reg + 1, reg, 8); - arm64_ldrx(0, 3, reg, reg, 0); - break; - case 13: - arm64_ldrx(0, 3, reg + 1, reg, 5); - o(0xd358fc00 | (reg+1) | (reg+1) << 5); // lsr x(reg+1), x(reg+1), #24 - arm64_ldrx(0, 3, reg, reg, 0); - break; - case 14: - arm64_ldrx(0, 3, reg + 1, reg, 6); - o(0xd350fc00 | (reg+1) | (reg+1) << 5); // lsr x(reg+1), x(reg+1), #16 - arm64_ldrx(0, 3, reg, reg, 0); - break; - case 15: - arm64_ldrx(0, 3, reg + 1, reg, 7); - o(0xd348fc00 | (reg+1) | (reg+1) << 5); // lsr x(reg+1), x(reg+1), #8 - arm64_ldrx(0, 3, reg, reg, 0); - break; - case 16: - o(0xa9400000 | reg | (reg+1) << 10 | reg << 5); - // ldp x(reg),x(reg+1),[x(reg)] - break; - } -} - -static void arm64_strx(int sz_, int dst, int bas, uint64_t off) -{ - uint32_t sz = sz_; - if (!(off & ~((uint32_t)0xfff << sz))) - o(0x39000000 | dst | bas << 5 | off << (10 - sz) | sz << 30); - // str(*) x(dst),[x(bas],#(off)] - else if (off < 256 || -off <= 256) - o(0x38000000 | dst | bas << 5 | (off & 511) << 12 | sz << 30); - // stur(*) x(dst),[x(bas],#(off)] - else { - arm64_movimm(30, off); // use x30 for offset - o(0x38206800 | dst | bas << 5 | (uint32_t)30 << 16 | sz << 30); - // str(*) x(dst),[x(bas),x30] - } -} - -static void arm64_strv(int sz_, int dst, int bas, uint64_t off) -{ - uint32_t sz = sz_; - if (!(off & ~((uint32_t)0xfff << sz))) - o(0x3d000000 | dst | bas << 5 | off << (10 - sz) | - (sz & 4) << 21 | (sz & 3) << 30); // str (s|d|q)(dst),[x(bas),#(off)] - else if (off < 256 || -off <= 256) - o(0x3c000000 | dst | bas << 5 | (off & 511) << 12 | - (sz & 4) << 21 | (sz & 3) << 30); // stur (s|d|q)(dst),[x(bas),#(off)] - else { - arm64_movimm(30, off); // use x30 for offset - o(0x3c206800 | dst | bas << 5 | (uint32_t)30 << 16 | - sz << 30 | (sz & 4) << 21); // str (s|d|q)(dst),[x(bas),x30] - } -} - -static void arm64_sym(int r, Sym *sym, unsigned long addend) -{ - // Currently TCC's linker does not generate COPY relocations for - // STT_OBJECTs when tcc is invoked with "-run". This typically - // results in "R_AARCH64_ADR_PREL_PG_HI21 relocation failed" when - // a program refers to stdin. A workaround is to avoid that - // relocation and use only relocations with unlimited range. - int avoid_adrp = 1; - - if (avoid_adrp || sym->a.weak) { - // (GCC uses a R_AARCH64_ABS64 in this case.) - greloca(cur_text_section, sym, ind, R_AARCH64_MOVW_UABS_G0_NC, addend); - o(0xd2800000 | r); // mov x(rt),#0,lsl #0 - greloca(cur_text_section, sym, ind, R_AARCH64_MOVW_UABS_G1_NC, addend); - o(0xf2a00000 | r); // movk x(rt),#0,lsl #16 - greloca(cur_text_section, sym, ind, R_AARCH64_MOVW_UABS_G2_NC, addend); - o(0xf2c00000 | r); // movk x(rt),#0,lsl #32 - greloca(cur_text_section, sym, ind, R_AARCH64_MOVW_UABS_G3, addend); - o(0xf2e00000 | r); // movk x(rt),#0,lsl #48 - } - else { - greloca(cur_text_section, sym, ind, R_AARCH64_ADR_PREL_PG_HI21, addend); - o(0x90000000 | r); - greloca(cur_text_section, sym, ind, R_AARCH64_ADD_ABS_LO12_NC, addend); - o(0x91000000 | r | r << 5); - } -} - -ST_FUNC void load(int r, SValue *sv) -{ - int svtt = sv->type.t; - int svr = sv->r & ~VT_LVAL_TYPE; - int svrv = svr & VT_VALMASK; - uint64_t svcul = (uint32_t)sv->c.i; - svcul = svcul >> 31 & 1 ? svcul - ((uint64_t)1 << 32) : svcul; - - if (svr == (VT_LOCAL | VT_LVAL)) { - if (IS_FREG(r)) - arm64_ldrv(arm64_type_size(svtt), fltr(r), 29, svcul); - else - arm64_ldrx(!(svtt & VT_UNSIGNED), arm64_type_size(svtt), - intr(r), 29, svcul); - return; - } - - if ((svr & ~VT_VALMASK) == VT_LVAL && svrv < VT_CONST) { - if (IS_FREG(r)) - arm64_ldrv(arm64_type_size(svtt), fltr(r), intr(svrv), 0); - else - arm64_ldrx(!(svtt & VT_UNSIGNED), arm64_type_size(svtt), - intr(r), intr(svrv), 0); - return; - } - - if (svr == (VT_CONST | VT_LVAL | VT_SYM)) { - arm64_sym(30, sv->sym, svcul); // use x30 for address - if (IS_FREG(r)) - arm64_ldrv(arm64_type_size(svtt), fltr(r), 30, 0); - else - arm64_ldrx(!(svtt & VT_UNSIGNED), arm64_type_size(svtt), - intr(r), 30, 0); - return; - } - - if (svr == (VT_CONST | VT_SYM)) { - arm64_sym(intr(r), sv->sym, svcul); - return; - } - - if (svr == VT_CONST) { - if ((svtt & VT_BTYPE) != VT_VOID) - arm64_movimm(intr(r), arm64_type_size(svtt) == 3 ? - sv->c.i : (uint32_t)svcul); - return; - } - - if (svr < VT_CONST) { - if (IS_FREG(r) && IS_FREG(svr)) - if (svtt == VT_LDOUBLE) - o(0x4ea01c00 | fltr(r) | fltr(svr) << 5); - // mov v(r).16b,v(svr).16b - else - o(0x1e604000 | fltr(r) | fltr(svr) << 5); // fmov d(r),d(svr) - else if (!IS_FREG(r) && !IS_FREG(svr)) - o(0xaa0003e0 | intr(r) | intr(svr) << 16); // mov x(r),x(svr) - else - assert(0); - return; - } - - if (svr == VT_LOCAL) { - if (-svcul < 0x1000) - o(0xd10003a0 | intr(r) | -svcul << 10); // sub x(r),x29,#... - else { - arm64_movimm(30, -svcul); // use x30 for offset - o(0xcb0003a0 | intr(r) | (uint32_t)30 << 16); // sub x(r),x29,x30 - } - return; - } - - if (svr == VT_JMP || svr == VT_JMPI) { - int t = (svr == VT_JMPI); - arm64_movimm(intr(r), t); - o(0x14000002); // b .+8 - gsym(svcul); - arm64_movimm(intr(r), t ^ 1); - return; - } - - if (svr == (VT_LLOCAL | VT_LVAL)) { - arm64_ldrx(0, 3, 30, 29, svcul); // use x30 for offset - if (IS_FREG(r)) - arm64_ldrv(arm64_type_size(svtt), fltr(r), 30, 0); - else - arm64_ldrx(!(svtt & VT_UNSIGNED), arm64_type_size(svtt), - intr(r), 30, 0); - return; - } - - printf("load(%x, (%x, %x, %llx))\n", r, svtt, sv->r, (long long)svcul); - assert(0); -} - -ST_FUNC void store(int r, SValue *sv) -{ - int svtt = sv->type.t; - int svr = sv->r & ~VT_LVAL_TYPE; - int svrv = svr & VT_VALMASK; - uint64_t svcul = (uint32_t)sv->c.i; - svcul = svcul >> 31 & 1 ? svcul - ((uint64_t)1 << 32) : svcul; - - if (svr == (VT_LOCAL | VT_LVAL)) { - if (IS_FREG(r)) - arm64_strv(arm64_type_size(svtt), fltr(r), 29, svcul); - else - arm64_strx(arm64_type_size(svtt), intr(r), 29, svcul); - return; - } - - if ((svr & ~VT_VALMASK) == VT_LVAL && svrv < VT_CONST) { - if (IS_FREG(r)) - arm64_strv(arm64_type_size(svtt), fltr(r), intr(svrv), 0); - else - arm64_strx(arm64_type_size(svtt), intr(r), intr(svrv), 0); - return; - } - - if (svr == (VT_CONST | VT_LVAL | VT_SYM)) { - arm64_sym(30, sv->sym, svcul); // use x30 for address - if (IS_FREG(r)) - arm64_strv(arm64_type_size(svtt), fltr(r), 30, 0); - else - arm64_strx(arm64_type_size(svtt), intr(r), 30, 0); - return; - } - - printf("store(%x, (%x, %x, %llx))\n", r, svtt, sv->r, (long long)svcul); - assert(0); -} - -static void arm64_gen_bl_or_b(int b) -{ - if ((vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST) { - assert(!b && (vtop->r & VT_SYM)); - greloca(cur_text_section, vtop->sym, ind, R_AARCH64_CALL26, 0); - o(0x94000000); // bl . - } - else - o(0xd61f0000 | (uint32_t)!b << 21 | intr(gv(RC_R30)) << 5); // br/blr -} - -static int arm64_hfa_aux(CType *type, int *fsize, int num) -{ - if (is_float(type->t)) { - int a, n = type_size(type, &a); - if (num >= 4 || (*fsize && *fsize != n)) - return -1; - *fsize = n; - return num + 1; - } - else if ((type->t & VT_BTYPE) == VT_STRUCT) { - int is_struct = 0; // rather than union - Sym *field; - for (field = type->ref->next; field; field = field->next) - if (field->c) { - is_struct = 1; - break; - } - if (is_struct) { - int num0 = num; - for (field = type->ref->next; field; field = field->next) { - if (field->c != (num - num0) * *fsize) - return -1; - num = arm64_hfa_aux(&field->type, fsize, num); - if (num == -1) - return -1; - } - if (type->ref->c != (num - num0) * *fsize) - return -1; - return num; - } - else { // union - int num0 = num; - for (field = type->ref->next; field; field = field->next) { - int num1 = arm64_hfa_aux(&field->type, fsize, num0); - if (num1 == -1) - return -1; - num = num1 < num ? num : num1; - } - if (type->ref->c != (num - num0) * *fsize) - return -1; - return num; - } - } - else if (type->t & VT_ARRAY) { - int num1; - if (!type->ref->c) - return num; - num1 = arm64_hfa_aux(&type->ref->type, fsize, num); - if (num1 == -1 || (num1 != num && type->ref->c > 4)) - return -1; - num1 = num + type->ref->c * (num1 - num); - if (num1 > 4) - return -1; - return num1; - } - return -1; -} - -static int arm64_hfa(CType *type, int *fsize) -{ - if ((type->t & VT_BTYPE) == VT_STRUCT || (type->t & VT_ARRAY)) { - int sz = 0; - int n = arm64_hfa_aux(type, &sz, 0); - if (0 < n && n <= 4) { - if (fsize) - *fsize = sz; - return n; - } - } - return 0; -} - -static unsigned long arm64_pcs_aux(int n, CType **type, unsigned long *a) -{ - int nx = 0; // next integer register - int nv = 0; // next vector register - unsigned long ns = 32; // next stack offset - int i; - - for (i = 0; i < n; i++) { - int hfa = arm64_hfa(type[i], 0); - int size, align; - - if ((type[i]->t & VT_ARRAY) || - (type[i]->t & VT_BTYPE) == VT_FUNC) - size = align = 8; - else - size = type_size(type[i], &align); - - if (hfa) - // B.2 - ; - else if (size > 16) { - // B.3: replace with pointer - if (nx < 8) - a[i] = nx++ << 1 | 1; - else { - ns = (ns + 7) & ~7; - a[i] = ns | 1; - ns += 8; - } - continue; - } - else if ((type[i]->t & VT_BTYPE) == VT_STRUCT) - // B.4 - size = (size + 7) & ~7; - - // C.1 - if (is_float(type[i]->t) && nv < 8) { - a[i] = 16 + (nv++ << 1); - continue; - } - - // C.2 - if (hfa && nv + hfa <= 8) { - a[i] = 16 + (nv << 1); - nv += hfa; - continue; - } - - // C.3 - if (hfa) { - nv = 8; - size = (size + 7) & ~7; - } - - // C.4 - if (hfa || (type[i]->t & VT_BTYPE) == VT_LDOUBLE) { - ns = (ns + 7) & ~7; - ns = (ns + align - 1) & -align; - } - - // C.5 - if ((type[i]->t & VT_BTYPE) == VT_FLOAT) - size = 8; - - // C.6 - if (hfa || is_float(type[i]->t)) { - a[i] = ns; - ns += size; - continue; - } - - // C.7 - if ((type[i]->t & VT_BTYPE) != VT_STRUCT && size <= 8 && nx < 8) { - a[i] = nx++ << 1; - continue; - } - - // C.8 - if (align == 16) - nx = (nx + 1) & ~1; - - // C.9 - if ((type[i]->t & VT_BTYPE) != VT_STRUCT && size == 16 && nx < 7) { - a[i] = nx << 1; - nx += 2; - continue; - } - - // C.10 - if ((type[i]->t & VT_BTYPE) == VT_STRUCT && size <= (8 - nx) * 8) { - a[i] = nx << 1; - nx += (size + 7) >> 3; - continue; - } - - // C.11 - nx = 8; - - // C.12 - ns = (ns + 7) & ~7; - ns = (ns + align - 1) & -align; - - // C.13 - if ((type[i]->t & VT_BTYPE) == VT_STRUCT) { - a[i] = ns; - ns += size; - continue; - } - - // C.14 - if (size < 8) - size = 8; - - // C.15 - a[i] = ns; - ns += size; - } - - return ns - 32; -} - -static unsigned long arm64_pcs(int n, CType **type, unsigned long *a) -{ - unsigned long stack; - - // Return type: - if ((type[0]->t & VT_BTYPE) == VT_VOID) - a[0] = -1; - else { - arm64_pcs_aux(1, type, a); - assert(a[0] == 0 || a[0] == 1 || a[0] == 16); - } - - // Argument types: - stack = arm64_pcs_aux(n, type + 1, a + 1); - - if (0) { - int i; - for (i = 0; i <= n; i++) { - if (!i) - printf("arm64_pcs return: "); - else - printf("arm64_pcs arg %d: ", i); - if (a[i] == (unsigned long)-1) - printf("void\n"); - else if (a[i] == 1 && !i) - printf("X8 pointer\n"); - else if (a[i] < 16) - printf("X%lu%s\n", a[i] / 2, a[i] & 1 ? " pointer" : ""); - else if (a[i] < 32) - printf("V%lu\n", a[i] / 2 - 8); - else - printf("stack %lu%s\n", - (a[i] - 32) & ~1, a[i] & 1 ? " pointer" : ""); - } - } - - return stack; -} - -ST_FUNC void gfunc_call(int nb_args) -{ - CType *return_type; - CType **t; - unsigned long *a, *a1; - unsigned long stack; - int i; - - return_type = &vtop[-nb_args].type.ref->type; - if ((return_type->t & VT_BTYPE) == VT_STRUCT) - --nb_args; - - t = tcc_malloc((nb_args + 1) * sizeof(*t)); - a = tcc_malloc((nb_args + 1) * sizeof(*a)); - a1 = tcc_malloc((nb_args + 1) * sizeof(*a1)); - - t[0] = return_type; - for (i = 0; i < nb_args; i++) - t[nb_args - i] = &vtop[-i].type; - - stack = arm64_pcs(nb_args, t, a); - - // Allocate space for structs replaced by pointer: - for (i = nb_args; i; i--) - if (a[i] & 1) { - SValue *arg = &vtop[i - nb_args]; - int align, size = type_size(&arg->type, &align); - assert((arg->type.t & VT_BTYPE) == VT_STRUCT); - stack = (stack + align - 1) & -align; - a1[i] = stack; - stack += size; - } - - stack = (stack + 15) >> 4 << 4; - - assert(stack < 0x1000); - if (stack) - o(0xd10003ff | stack << 10); // sub sp,sp,#(n) - - // First pass: set all values on stack - for (i = nb_args; i; i--) { - vpushv(vtop - nb_args + i); - - if (a[i] & 1) { - // struct replaced by pointer - int r = get_reg(RC_INT); - arm64_spoff(intr(r), a1[i]); - vset(&vtop->type, r | VT_LVAL, 0); - vswap(); - vstore(); - if (a[i] >= 32) { - // pointer on stack - r = get_reg(RC_INT); - arm64_spoff(intr(r), a1[i]); - arm64_strx(3, intr(r), 31, (a[i] - 32) >> 1 << 1); - } - } - else if (a[i] >= 32) { - // value on stack - if ((vtop->type.t & VT_BTYPE) == VT_STRUCT) { - int r = get_reg(RC_INT); - arm64_spoff(intr(r), a[i] - 32); - vset(&vtop->type, r | VT_LVAL, 0); - vswap(); - vstore(); - } - else if (is_float(vtop->type.t)) { - gv(RC_FLOAT); - arm64_strv(arm64_type_size(vtop[0].type.t), - fltr(vtop[0].r), 31, a[i] - 32); - } - else { - gv(RC_INT); - arm64_strx(arm64_type_size(vtop[0].type.t), - intr(vtop[0].r), 31, a[i] - 32); - } - } - - --vtop; - } - - // Second pass: assign values to registers - for (i = nb_args; i; i--, vtop--) { - if (a[i] < 16 && !(a[i] & 1)) { - // value in general-purpose registers - if ((vtop->type.t & VT_BTYPE) == VT_STRUCT) { - int align, size = type_size(&vtop->type, &align); - vtop->type.t = VT_PTR; - gaddrof(); - gv(RC_R(a[i] / 2)); - arm64_ldrs(a[i] / 2, size); - } - else - gv(RC_R(a[i] / 2)); - } - else if (a[i] < 16) - // struct replaced by pointer in register - arm64_spoff(a[i] / 2, a1[i]); - else if (a[i] < 32) { - // value in floating-point registers - if ((vtop->type.t & VT_BTYPE) == VT_STRUCT) { - uint32_t j, sz, n = arm64_hfa(&vtop->type, &sz); - vtop->type.t = VT_PTR; - gaddrof(); - gv(RC_R30); - for (j = 0; j < n; j++) - o(0x3d4003c0 | - (sz & 16) << 19 | -(sz & 8) << 27 | (sz & 4) << 29 | - (a[i] / 2 - 8 + j) | - j << 10); // ldr ([sdq])(*),[x30,#(j * sz)] - } - else - gv(RC_F(a[i] / 2 - 8)); - } - } - - if ((return_type->t & VT_BTYPE) == VT_STRUCT) { - if (a[0] == 1) { - // indirect return: set x8 and discard the stack value - gv(RC_R(8)); - --vtop; - } - else - // return in registers: keep the address for after the call - vswap(); - } - - save_regs(0); - arm64_gen_bl_or_b(0); - --vtop; - if (stack) - o(0x910003ff | stack << 10); // add sp,sp,#(n) - - { - int rt = return_type->t; - int bt = rt & VT_BTYPE; - if (bt == VT_BYTE || bt == VT_SHORT) - // Promote small integers: - o(0x13001c00 | (bt == VT_SHORT) << 13 | - (uint32_t)!!(rt & VT_UNSIGNED) << 30); // [su]xt[bh] w0,w0 - else if (bt == VT_STRUCT && !(a[0] & 1)) { - // A struct was returned in registers, so write it out: - gv(RC_R(8)); - --vtop; - if (a[0] == 0) { - int align, size = type_size(return_type, &align); - assert(size <= 16); - if (size > 8) - o(0xa9000500); // stp x0,x1,[x8] - else if (size) - arm64_strx(size > 4 ? 3 : size > 2 ? 2 : size > 1, 0, 8, 0); - - } - else if (a[0] == 16) { - uint32_t j, sz, n = arm64_hfa(return_type, &sz); - for (j = 0; j < n; j++) - o(0x3d000100 | - (sz & 16) << 19 | -(sz & 8) << 27 | (sz & 4) << 29 | - (a[i] / 2 - 8 + j) | - j << 10); // str ([sdq])(*),[x8,#(j * sz)] - } - } - } - - tcc_free(a1); - tcc_free(a); - tcc_free(t); -} - -static unsigned long arm64_func_va_list_stack; -static int arm64_func_va_list_gr_offs; -static int arm64_func_va_list_vr_offs; -static int arm64_func_sub_sp_offset; - -ST_FUNC void gfunc_prolog(CType *func_type) -{ - int n = 0; - int i = 0; - Sym *sym; - CType **t; - unsigned long *a; - - // Why doesn't the caller (gen_function) set func_vt? - func_vt = func_type->ref->type; - func_vc = 144; // offset of where x8 is stored - - for (sym = func_type->ref; sym; sym = sym->next) - ++n; - t = tcc_malloc(n * sizeof(*t)); - a = tcc_malloc(n * sizeof(*a)); - - for (sym = func_type->ref; sym; sym = sym->next) - t[i++] = &sym->type; - - arm64_func_va_list_stack = arm64_pcs(n - 1, t, a); - - o(0xa9b27bfd); // stp x29,x30,[sp,#-224]! - o(0xad0087e0); // stp q0,q1,[sp,#16] - o(0xad018fe2); // stp q2,q3,[sp,#48] - o(0xad0297e4); // stp q4,q5,[sp,#80] - o(0xad039fe6); // stp q6,q7,[sp,#112] - o(0xa90923e8); // stp x8,x8,[sp,#144] - o(0xa90a07e0); // stp x0,x1,[sp,#160] - o(0xa90b0fe2); // stp x2,x3,[sp,#176] - o(0xa90c17e4); // stp x4,x5,[sp,#192] - o(0xa90d1fe6); // stp x6,x7,[sp,#208] - - arm64_func_va_list_gr_offs = -64; - arm64_func_va_list_vr_offs = -128; - - for (i = 1, sym = func_type->ref->next; sym; i++, sym = sym->next) { - int off = (a[i] < 16 ? 160 + a[i] / 2 * 8 : - a[i] < 32 ? 16 + (a[i] - 16) / 2 * 16 : - 224 + ((a[i] - 32) >> 1 << 1)); - sym_push(sym->v & ~SYM_FIELD, &sym->type, - (a[i] & 1 ? VT_LLOCAL : VT_LOCAL) | lvalue_type(sym->type.t), - off); - - if (a[i] < 16) { - int align, size = type_size(&sym->type, &align); - arm64_func_va_list_gr_offs = (a[i] / 2 - 7 + - (!(a[i] & 1) && size > 8)) * 8; - } - else if (a[i] < 32) { - uint32_t hfa = arm64_hfa(&sym->type, 0); - arm64_func_va_list_vr_offs = (a[i] / 2 - 16 + - (hfa ? hfa : 1)) * 16; - } - - // HFAs of float and double need to be written differently: - if (16 <= a[i] && a[i] < 32 && (sym->type.t & VT_BTYPE) == VT_STRUCT) { - uint32_t j, sz, k = arm64_hfa(&sym->type, &sz); - if (sz < 16) - for (j = 0; j < k; j++) { - o(0x3d0003e0 | -(sz & 8) << 27 | (sz & 4) << 29 | - ((a[i] - 16) / 2 + j) | (off / sz + j) << 10); - // str ([sdq])(*),[sp,#(j * sz)] - } - } - } - - tcc_free(a); - tcc_free(t); - - o(0x910003fd); // mov x29,sp - arm64_func_sub_sp_offset = ind; - // In gfunc_epilog these will be replaced with code to decrement SP: - o(0xd503201f); // nop - o(0xd503201f); // nop - loc = 0; -} - -ST_FUNC void gen_va_start(void) -{ - int r; - --vtop; // we don't need the "arg" - gaddrof(); - r = intr(gv(RC_INT)); - - if (arm64_func_va_list_stack) { - //xx could use add (immediate) here - arm64_movimm(30, arm64_func_va_list_stack + 224); - o(0x8b1e03be); // add x30,x29,x30 - } - else - o(0x910383be); // add x30,x29,#224 - o(0xf900001e | r << 5); // str x30,[x(r)] - - if (arm64_func_va_list_gr_offs) { - if (arm64_func_va_list_stack) - o(0x910383be); // add x30,x29,#224 - o(0xf900041e | r << 5); // str x30,[x(r),#8] - } - - if (arm64_func_va_list_vr_offs) { - o(0x910243be); // add x30,x29,#144 - o(0xf900081e | r << 5); // str x30,[x(r),#16] - } - - arm64_movimm(30, arm64_func_va_list_gr_offs); - o(0xb900181e | r << 5); // str w30,[x(r),#24] - - arm64_movimm(30, arm64_func_va_list_vr_offs); - o(0xb9001c1e | r << 5); // str w30,[x(r),#28] - - --vtop; -} - -ST_FUNC void gen_va_arg(CType *t) -{ - int align, size = type_size(t, &align); - int fsize, hfa = arm64_hfa(t, &fsize); - uint32_t r0, r1; - - if (is_float(t->t)) { - hfa = 1; - fsize = size; - } - - gaddrof(); - r0 = intr(gv(RC_INT)); - r1 = get_reg(RC_INT); - vtop[0].r = r1 | lvalue_type(t->t); - r1 = intr(r1); - - if (!hfa) { - uint32_t n = size > 16 ? 8 : (size + 7) & -8; - o(0xb940181e | r0 << 5); // ldr w30,[x(r0),#24] // __gr_offs - if (align == 16) { - assert(0); // this path untested but needed for __uint128_t - o(0x11003fde); // add w30,w30,#15 - o(0x121c6fde); // and w30,w30,#-16 - } - o(0x310003c0 | r1 | n << 10); // adds w(r1),w30,#(n) - o(0x540000ad); // b.le .+20 - o(0xf9400000 | r1 | r0 << 5); // ldr x(r1),[x(r0)] // __stack - o(0x9100001e | r1 << 5 | n << 10); // add x30,x(r1),#(n) - o(0xf900001e | r0 << 5); // str x30,[x(r0)] // __stack - o(0x14000004); // b .+16 - o(0xb9001800 | r1 | r0 << 5); // str w(r1),[x(r0),#24] // __gr_offs - o(0xf9400400 | r1 | r0 << 5); // ldr x(r1),[x(r0),#8] // __gr_top - o(0x8b3ec000 | r1 | r1 << 5); // add x(r1),x(r1),w30,sxtw - if (size > 16) - o(0xf9400000 | r1 | r1 << 5); // ldr x(r1),[x(r1)] - } - else { - uint32_t rsz = hfa << 4; - uint32_t ssz = (size + 7) & -(uint32_t)8; - uint32_t b1, b2; - o(0xb9401c1e | r0 << 5); // ldr w30,[x(r0),#28] // __vr_offs - o(0x310003c0 | r1 | rsz << 10); // adds w(r1),w30,#(rsz) - b1 = ind; o(0x5400000d); // b.le lab1 - o(0xf9400000 | r1 | r0 << 5); // ldr x(r1),[x(r0)] // __stack - if (fsize == 16) { - o(0x91003c00 | r1 | r1 << 5); // add x(r1),x(r1),#15 - o(0x927cec00 | r1 | r1 << 5); // and x(r1),x(r1),#-16 - } - o(0x9100001e | r1 << 5 | ssz << 10); // add x30,x(r1),#(ssz) - o(0xf900001e | r0 << 5); // str x30,[x(r0)] // __stack - b2 = ind; o(0x14000000); // b lab2 - // lab1: - write32le(cur_text_section->data + b1, 0x5400000d | (ind - b1) << 3); - o(0xb9001c00 | r1 | r0 << 5); // str w(r1),[x(r0),#28] // __vr_offs - o(0xf9400800 | r1 | r0 << 5); // ldr x(r1),[x(r0),#16] // __vr_top - if (hfa == 1 || fsize == 16) - o(0x8b3ec000 | r1 | r1 << 5); // add x(r1),x(r1),w30,sxtw - else { - // We need to change the layout of this HFA. - // Get some space on the stack using global variable "loc": - loc = (loc - size) & -(uint32_t)align; - o(0x8b3ec000 | 30 | r1 << 5); // add x30,x(r1),w30,sxtw - arm64_movimm(r1, loc); - o(0x8b0003a0 | r1 | r1 << 16); // add x(r1),x29,x(r1) - o(0x4c402bdc | (uint32_t)fsize << 7 | - (uint32_t)(hfa == 2) << 15 | - (uint32_t)(hfa == 3) << 14); // ld1 {v28.(4s|2d),...},[x30] - o(0x0d00801c | r1 << 5 | (fsize == 8) << 10 | - (uint32_t)(hfa != 2) << 13 | - (uint32_t)(hfa != 3) << 21); // st(hfa) {v28.(s|d),...}[0],[x(r1)] - } - // lab2: - write32le(cur_text_section->data + b2, 0x14000000 | (ind - b2) >> 2); - } -} - -ST_FUNC int gfunc_sret(CType *vt, int variadic, CType *ret, - int *align, int *regsize) -{ - return 0; -} - -ST_FUNC void gfunc_return(CType *func_type) -{ - CType *t = func_type; - unsigned long a; - - arm64_pcs(0, &t, &a); - switch (a) { - case -1: - break; - case 0: - if ((func_type->t & VT_BTYPE) == VT_STRUCT) { - int align, size = type_size(func_type, &align); - gaddrof(); - gv(RC_R(0)); - arm64_ldrs(0, size); - } - else - gv(RC_IRET); - break; - case 1: { - CType type = *func_type; - mk_pointer(&type); - vset(&type, VT_LOCAL | VT_LVAL, func_vc); - indir(); - vswap(); - vstore(); - break; - } - case 16: - if ((func_type->t & VT_BTYPE) == VT_STRUCT) { - uint32_t j, sz, n = arm64_hfa(&vtop->type, &sz); - gaddrof(); - gv(RC_R(0)); - for (j = 0; j < n; j++) - o(0x3d400000 | - (sz & 16) << 19 | -(sz & 8) << 27 | (sz & 4) << 29 | - j | j << 10); // ldr ([sdq])(*),[x0,#(j * sz)] - } - else - gv(RC_FRET); - break; - default: - assert(0); - } - vtop--; -} - -ST_FUNC void gfunc_epilog(void) -{ - if (loc) { - // Insert instructions to subtract size of stack frame from SP. - unsigned char *ptr = cur_text_section->data + arm64_func_sub_sp_offset; - uint64_t diff = (-loc + 15) & ~15; - if (!(diff >> 24)) { - if (diff & 0xfff) // sub sp,sp,#(diff & 0xfff) - write32le(ptr, 0xd10003ff | (diff & 0xfff) << 10); - if (diff >> 12) // sub sp,sp,#(diff >> 12),lsl #12 - write32le(ptr + 4, 0xd14003ff | (diff >> 12) << 10); - } - else { - // In this case we may subtract more than necessary, - // but always less than 17/16 of what we were aiming for. - int i = 0; - int j = 0; - while (diff >> 20) { - diff = (diff + 0xffff) >> 16; - ++i; - } - while (diff >> 16) { - diff = (diff + 1) >> 1; - ++j; - } - write32le(ptr, 0xd2800010 | diff << 5 | i << 21); - // mov x16,#(diff),lsl #(16 * i) - write32le(ptr + 4, 0xcb3063ff | j << 10); - // sub sp,sp,x16,lsl #(j) - } - } - o(0x910003bf); // mov sp,x29 - o(0xa8ce7bfd); // ldp x29,x30,[sp],#224 - - o(0xd65f03c0); // ret -} - -// Generate forward branch to label: -ST_FUNC int gjmp(int t) -{ - int r = ind; - if (nocode_wanted) - return t; - o(t); - return r; -} - -// Generate branch to known address: -ST_FUNC void gjmp_addr(int a) -{ - assert(a - ind + 0x8000000 < 0x10000000); - o(0x14000000 | ((a - ind) >> 2 & 0x3ffffff)); -} - -ST_FUNC int gtst(int inv, int t) -{ - int bt = vtop->type.t & VT_BTYPE; - if (bt == VT_LDOUBLE) { - uint32_t a, b, f = fltr(gv(RC_FLOAT)); - a = get_reg(RC_INT); - vpushi(0); - vtop[0].r = a; - b = get_reg(RC_INT); - a = intr(a); - b = intr(b); - o(0x4e083c00 | a | f << 5); // mov x(a),v(f).d[0] - o(0x4e183c00 | b | f << 5); // mov x(b),v(f).d[1] - o(0xaa000400 | a | a << 5 | b << 16); // orr x(a),x(a),x(b),lsl #1 - o(0xb4000040 | a | !!inv << 24); // cbz/cbnz x(a),.+8 - --vtop; - } - else if (bt == VT_FLOAT || bt == VT_DOUBLE) { - uint32_t a = fltr(gv(RC_FLOAT)); - o(0x1e202008 | a << 5 | (bt != VT_FLOAT) << 22); // fcmp - o(0x54000040 | !!inv); // b.eq/b.ne .+8 - } - else { - uint32_t ll = (bt == VT_PTR || bt == VT_LLONG); - uint32_t a = intr(gv(RC_INT)); - o(0x34000040 | a | !!inv << 24 | ll << 31); // cbz/cbnz wA,.+8 - } - --vtop; - return gjmp(t); -} - -static int arm64_iconst(uint64_t *val, SValue *sv) -{ - if ((sv->r & (VT_VALMASK | VT_LVAL | VT_SYM)) != VT_CONST) - return 0; - if (val) { - int t = sv->type.t; - int bt = t & VT_BTYPE; - *val = ((bt == VT_LLONG || bt == VT_PTR) ? sv->c.i : - (uint32_t)sv->c.i | - (t & VT_UNSIGNED ? 0 : -(sv->c.i & 0x80000000))); - } - return 1; -} - -static int arm64_gen_opic(int op, uint32_t l, int rev, uint64_t val, - uint32_t x, uint32_t a) -{ - if (op == '-' && !rev) { - val = -val; - op = '+'; - } - val = l ? val : (uint32_t)val; - - switch (op) { - - case '+': { - uint32_t s = l ? val >> 63 : val >> 31; - val = s ? -val : val; - val = l ? val : (uint32_t)val; - if (!(val & ~(uint64_t)0xfff)) - o(0x11000000 | l << 31 | s << 30 | x | a << 5 | val << 10); - else if (!(val & ~(uint64_t)0xfff000)) - o(0x11400000 | l << 31 | s << 30 | x | a << 5 | val >> 12 << 10); - else { - arm64_movimm(30, val); // use x30 - o(0x0b1e0000 | l << 31 | s << 30 | x | a << 5); - } - return 1; - } - - case '-': - if (!val) - o(0x4b0003e0 | l << 31 | x | a << 16); // neg - else if (val == (l ? (uint64_t)-1 : (uint32_t)-1)) - o(0x2a2003e0 | l << 31 | x | a << 16); // mvn - else { - arm64_movimm(30, val); // use x30 - o(0x4b0003c0 | l << 31 | x | a << 16); // sub - } - return 1; - - case '^': - if (val == -1 || (val == 0xffffffff && !l)) { - o(0x2a2003e0 | l << 31 | x | a << 16); // mvn - return 1; - } - // fall through - case '&': - case '|': { - int e = arm64_encode_bimm64(l ? val : val | val << 32); - if (e < 0) - return 0; - o((op == '&' ? 0x12000000 : - op == '|' ? 0x32000000 : 0x52000000) | - l << 31 | x | a << 5 | (uint32_t)e << 10); - return 1; - } - - case TOK_SAR: - case TOK_SHL: - case TOK_SHR: { - uint32_t n = 32 << l; - val = val & (n - 1); - if (rev) - return 0; - if (!val) - assert(0); - else if (op == TOK_SHL) - o(0x53000000 | l << 31 | l << 22 | x | a << 5 | - (n - val) << 16 | (n - 1 - val) << 10); // lsl - else - o(0x13000000 | (op == TOK_SHR) << 30 | l << 31 | l << 22 | - x | a << 5 | val << 16 | (n - 1) << 10); // lsr/asr - return 1; - } - - } - return 0; -} - -static void arm64_gen_opil(int op, uint32_t l) -{ - uint32_t x, a, b; - - // Special treatment for operations with a constant operand: - { - uint64_t val; - int rev = 1; - - if (arm64_iconst(0, &vtop[0])) { - vswap(); - rev = 0; - } - if (arm64_iconst(&val, &vtop[-1])) { - gv(RC_INT); - a = intr(vtop[0].r); - --vtop; - x = get_reg(RC_INT); - ++vtop; - if (arm64_gen_opic(op, l, rev, val, intr(x), a)) { - vtop[0].r = x; - vswap(); - --vtop; - return; - } - } - if (!rev) - vswap(); - } - - gv2(RC_INT, RC_INT); - assert(vtop[-1].r < VT_CONST && vtop[0].r < VT_CONST); - a = intr(vtop[-1].r); - b = intr(vtop[0].r); - vtop -= 2; - x = get_reg(RC_INT); - ++vtop; - vtop[0].r = x; - x = intr(x); - - switch (op) { - case '%': - // Use x30 for quotient: - o(0x1ac00c00 | l << 31 | 30 | a << 5 | b << 16); // sdiv - o(0x1b008000 | l << 31 | x | (uint32_t)30 << 5 | - b << 16 | a << 10); // msub - break; - case '&': - o(0x0a000000 | l << 31 | x | a << 5 | b << 16); // and - break; - case '*': - o(0x1b007c00 | l << 31 | x | a << 5 | b << 16); // mul - break; - case '+': - o(0x0b000000 | l << 31 | x | a << 5 | b << 16); // add - break; - case '-': - o(0x4b000000 | l << 31 | x | a << 5 | b << 16); // sub - break; - case '/': - o(0x1ac00c00 | l << 31 | x | a << 5 | b << 16); // sdiv - break; - case '^': - o(0x4a000000 | l << 31 | x | a << 5 | b << 16); // eor - break; - case '|': - o(0x2a000000 | l << 31 | x | a << 5 | b << 16); // orr - break; - case TOK_EQ: - o(0x6b00001f | l << 31 | a << 5 | b << 16); // cmp - o(0x1a9f17e0 | x); // cset wA,eq - break; - case TOK_GE: - o(0x6b00001f | l << 31 | a << 5 | b << 16); // cmp - o(0x1a9fb7e0 | x); // cset wA,ge - break; - case TOK_GT: - o(0x6b00001f | l << 31 | a << 5 | b << 16); // cmp - o(0x1a9fd7e0 | x); // cset wA,gt - break; - case TOK_LE: - o(0x6b00001f | l << 31 | a << 5 | b << 16); // cmp - o(0x1a9fc7e0 | x); // cset wA,le - break; - case TOK_LT: - o(0x6b00001f | l << 31 | a << 5 | b << 16); // cmp - o(0x1a9fa7e0 | x); // cset wA,lt - break; - case TOK_NE: - o(0x6b00001f | l << 31 | a << 5 | b << 16); // cmp - o(0x1a9f07e0 | x); // cset wA,ne - break; - case TOK_SAR: - o(0x1ac02800 | l << 31 | x | a << 5 | b << 16); // asr - break; - case TOK_SHL: - o(0x1ac02000 | l << 31 | x | a << 5 | b << 16); // lsl - break; - case TOK_SHR: - o(0x1ac02400 | l << 31 | x | a << 5 | b << 16); // lsr - break; - case TOK_UDIV: - case TOK_PDIV: - o(0x1ac00800 | l << 31 | x | a << 5 | b << 16); // udiv - break; - case TOK_UGE: - o(0x6b00001f | l << 31 | a << 5 | b << 16); // cmp - o(0x1a9f37e0 | x); // cset wA,cs - break; - case TOK_UGT: - o(0x6b00001f | l << 31 | a << 5 | b << 16); // cmp - o(0x1a9f97e0 | x); // cset wA,hi - break; - case TOK_ULT: - o(0x6b00001f | l << 31 | a << 5 | b << 16); // cmp - o(0x1a9f27e0 | x); // cset wA,cc - break; - case TOK_ULE: - o(0x6b00001f | l << 31 | a << 5 | b << 16); // cmp - o(0x1a9f87e0 | x); // cset wA,ls - break; - case TOK_UMOD: - // Use x30 for quotient: - o(0x1ac00800 | l << 31 | 30 | a << 5 | b << 16); // udiv - o(0x1b008000 | l << 31 | x | (uint32_t)30 << 5 | - b << 16 | a << 10); // msub - break; - default: - assert(0); - } -} - -ST_FUNC void gen_opi(int op) -{ - arm64_gen_opil(op, 0); -} - -ST_FUNC void gen_opl(int op) -{ - arm64_gen_opil(op, 1); -} - -ST_FUNC void gen_opf(int op) -{ - uint32_t x, a, b, dbl; - - if (vtop[0].type.t == VT_LDOUBLE) { - CType type = vtop[0].type; - int func = 0; - int cond = -1; - switch (op) { - case '*': func = TOK___multf3; break; - case '+': func = TOK___addtf3; break; - case '-': func = TOK___subtf3; break; - case '/': func = TOK___divtf3; break; - case TOK_EQ: func = TOK___eqtf2; cond = 1; break; - case TOK_NE: func = TOK___netf2; cond = 0; break; - case TOK_LT: func = TOK___lttf2; cond = 10; break; - case TOK_GE: func = TOK___getf2; cond = 11; break; - case TOK_LE: func = TOK___letf2; cond = 12; break; - case TOK_GT: func = TOK___gttf2; cond = 13; break; - default: assert(0); break; - } - vpush_global_sym(&func_old_type, func); - vrott(3); - gfunc_call(2); - vpushi(0); - vtop->r = cond < 0 ? REG_FRET : REG_IRET; - if (cond < 0) - vtop->type = type; - else { - o(0x7100001f); // cmp w0,#0 - o(0x1a9f07e0 | (uint32_t)cond << 12); // cset w0,(cond) - } - return; - } - - dbl = vtop[0].type.t != VT_FLOAT; - gv2(RC_FLOAT, RC_FLOAT); - assert(vtop[-1].r < VT_CONST && vtop[0].r < VT_CONST); - a = fltr(vtop[-1].r); - b = fltr(vtop[0].r); - vtop -= 2; - switch (op) { - case TOK_EQ: case TOK_NE: - case TOK_LT: case TOK_GE: case TOK_LE: case TOK_GT: - x = get_reg(RC_INT); - ++vtop; - vtop[0].r = x; - x = intr(x); - break; - default: - x = get_reg(RC_FLOAT); - ++vtop; - vtop[0].r = x; - x = fltr(x); - break; - } - - switch (op) { - case '*': - o(0x1e200800 | dbl << 22 | x | a << 5 | b << 16); // fmul - break; - case '+': - o(0x1e202800 | dbl << 22 | x | a << 5 | b << 16); // fadd - break; - case '-': - o(0x1e203800 | dbl << 22 | x | a << 5 | b << 16); // fsub - break; - case '/': - o(0x1e201800 | dbl << 22 | x | a << 5 | b << 16); // fdiv - break; - case TOK_EQ: - o(0x1e202000 | dbl << 22 | a << 5 | b << 16); // fcmp - o(0x1a9f17e0 | x); // cset w(x),eq - break; - case TOK_GE: - o(0x1e202000 | dbl << 22 | a << 5 | b << 16); // fcmp - o(0x1a9fb7e0 | x); // cset w(x),ge - break; - case TOK_GT: - o(0x1e202000 | dbl << 22 | a << 5 | b << 16); // fcmp - o(0x1a9fd7e0 | x); // cset w(x),gt - break; - case TOK_LE: - o(0x1e202000 | dbl << 22 | a << 5 | b << 16); // fcmp - o(0x1a9f87e0 | x); // cset w(x),ls - break; - case TOK_LT: - o(0x1e202000 | dbl << 22 | a << 5 | b << 16); // fcmp - o(0x1a9f57e0 | x); // cset w(x),mi - break; - case TOK_NE: - o(0x1e202000 | dbl << 22 | a << 5 | b << 16); // fcmp - o(0x1a9f07e0 | x); // cset w(x),ne - break; - default: - assert(0); - } -} - -// Generate sign extension from 32 to 64 bits: -ST_FUNC void gen_cvt_sxtw(void) -{ - uint32_t r = intr(gv(RC_INT)); - o(0x93407c00 | r | r << 5); // sxtw x(r),w(r) -} - -ST_FUNC void gen_cvt_itof(int t) -{ - if (t == VT_LDOUBLE) { - int f = vtop->type.t; - int func = (f & VT_BTYPE) == VT_LLONG ? - (f & VT_UNSIGNED ? TOK___floatunditf : TOK___floatditf) : - (f & VT_UNSIGNED ? TOK___floatunsitf : TOK___floatsitf); - vpush_global_sym(&func_old_type, func); - vrott(2); - gfunc_call(1); - vpushi(0); - vtop->type.t = t; - vtop->r = REG_FRET; - return; - } - else { - int d, n = intr(gv(RC_INT)); - int s = !(vtop->type.t & VT_UNSIGNED); - uint32_t l = ((vtop->type.t & VT_BTYPE) == VT_LLONG); - --vtop; - d = get_reg(RC_FLOAT); - ++vtop; - vtop[0].r = d; - o(0x1e220000 | (uint32_t)!s << 16 | - (uint32_t)(t != VT_FLOAT) << 22 | fltr(d) | - l << 31 | n << 5); // [us]cvtf [sd](d),[wx](n) - } -} - -ST_FUNC void gen_cvt_ftoi(int t) -{ - if ((vtop->type.t & VT_BTYPE) == VT_LDOUBLE) { - int func = (t & VT_BTYPE) == VT_LLONG ? - (t & VT_UNSIGNED ? TOK___fixunstfdi : TOK___fixtfdi) : - (t & VT_UNSIGNED ? TOK___fixunstfsi : TOK___fixtfsi); - vpush_global_sym(&func_old_type, func); - vrott(2); - gfunc_call(1); - vpushi(0); - vtop->type.t = t; - vtop->r = REG_IRET; - return; - } - else { - int d, n = fltr(gv(RC_FLOAT)); - uint32_t l = ((vtop->type.t & VT_BTYPE) != VT_FLOAT); - --vtop; - d = get_reg(RC_INT); - ++vtop; - vtop[0].r = d; - o(0x1e380000 | - (uint32_t)!!(t & VT_UNSIGNED) << 16 | - (uint32_t)((t & VT_BTYPE) == VT_LLONG) << 31 | intr(d) | - l << 22 | n << 5); // fcvtz[su] [wx](d),[sd](n) - } -} - -ST_FUNC void gen_cvt_ftof(int t) -{ - int f = vtop[0].type.t; - assert(t == VT_FLOAT || t == VT_DOUBLE || t == VT_LDOUBLE); - assert(f == VT_FLOAT || f == VT_DOUBLE || f == VT_LDOUBLE); - if (t == f) - return; - - if (t == VT_LDOUBLE || f == VT_LDOUBLE) { - int func = (t == VT_LDOUBLE) ? - (f == VT_FLOAT ? TOK___extendsftf2 : TOK___extenddftf2) : - (t == VT_FLOAT ? TOK___trunctfsf2 : TOK___trunctfdf2); - vpush_global_sym(&func_old_type, func); - vrott(2); - gfunc_call(1); - vpushi(0); - vtop->type.t = t; - vtop->r = REG_FRET; - } - else { - int x, a; - gv(RC_FLOAT); - assert(vtop[0].r < VT_CONST); - a = fltr(vtop[0].r); - --vtop; - x = get_reg(RC_FLOAT); - ++vtop; - vtop[0].r = x; - x = fltr(x); - - if (f == VT_FLOAT) - o(0x1e22c000 | x | a << 5); // fcvt d(x),s(a) - else - o(0x1e624000 | x | a << 5); // fcvt s(x),d(a) - } -} - -ST_FUNC void ggoto(void) -{ - arm64_gen_bl_or_b(1); - --vtop; -} - -ST_FUNC void gen_clear_cache(void) -{ - uint32_t beg, end, dsz, isz, p, lab1, b1; - gv2(RC_INT, RC_INT); - vpushi(0); - vtop->r = get_reg(RC_INT); - vpushi(0); - vtop->r = get_reg(RC_INT); - vpushi(0); - vtop->r = get_reg(RC_INT); - beg = intr(vtop[-4].r); // x0 - end = intr(vtop[-3].r); // x1 - dsz = intr(vtop[-2].r); // x2 - isz = intr(vtop[-1].r); // x3 - p = intr(vtop[0].r); // x4 - vtop -= 5; - - o(0xd53b0020 | isz); // mrs x(isz),ctr_el0 - o(0x52800080 | p); // mov w(p),#4 - o(0x53104c00 | dsz | isz << 5); // ubfx w(dsz),w(isz),#16,#4 - o(0x1ac02000 | dsz | p << 5 | dsz << 16); // lsl w(dsz),w(p),w(dsz) - o(0x12000c00 | isz | isz << 5); // and w(isz),w(isz),#15 - o(0x1ac02000 | isz | p << 5 | isz << 16); // lsl w(isz),w(p),w(isz) - o(0x51000400 | p | dsz << 5); // sub w(p),w(dsz),#1 - o(0x8a240004 | p | beg << 5 | p << 16); // bic x(p),x(beg),x(p) - b1 = ind; o(0x14000000); // b - lab1 = ind; - o(0xd50b7b20 | p); // dc cvau,x(p) - o(0x8b000000 | p | p << 5 | dsz << 16); // add x(p),x(p),x(dsz) - write32le(cur_text_section->data + b1, 0x14000000 | (ind - b1) >> 2); - o(0xeb00001f | p << 5 | end << 16); // cmp x(p),x(end) - o(0x54ffffa3 | ((lab1 - ind) << 3 & 0xffffe0)); // b.cc lab1 - o(0xd5033b9f); // dsb ish - o(0x51000400 | p | isz << 5); // sub w(p),w(isz),#1 - o(0x8a240004 | p | beg << 5 | p << 16); // bic x(p),x(beg),x(p) - b1 = ind; o(0x14000000); // b - lab1 = ind; - o(0xd50b7520 | p); // ic ivau,x(p) - o(0x8b000000 | p | p << 5 | isz << 16); // add x(p),x(p),x(isz) - write32le(cur_text_section->data + b1, 0x14000000 | (ind - b1) >> 2); - o(0xeb00001f | p << 5 | end << 16); // cmp x(p),x(end) - o(0x54ffffa3 | ((lab1 - ind) << 3 & 0xffffe0)); // b.cc lab1 - o(0xd5033b9f); // dsb ish - o(0xd5033fdf); // isb -} - -ST_FUNC void gen_vla_sp_save(int addr) { - uint32_t r = intr(get_reg(RC_INT)); - o(0x910003e0 | r); // mov x(r),sp - arm64_strx(3, r, 29, addr); -} - -ST_FUNC void gen_vla_sp_restore(int addr) { - // Use x30 because this function can be called when there - // is a live return value in x0 but there is nothing on - // the value stack to prevent get_reg from returning x0. - uint32_t r = 30; - arm64_ldrx(0, 3, r, 29, addr); - o(0x9100001f | r << 5); // mov sp,x(r) -} - -ST_FUNC void gen_vla_alloc(CType *type, int align) { - uint32_t r = intr(gv(RC_INT)); - o(0x91003c00 | r | r << 5); // add x(r),x(r),#15 - o(0x927cec00 | r | r << 5); // bic x(r),x(r),#15 - o(0xcb2063ff | r << 16); // sub sp,sp,x(r) - vpop(); -} - -/* end of A64 code generator */ -/*************************************************************/ -#endif -/*************************************************************/ diff --git a/05/tcc-final-old/arm64-link.c b/05/tcc-final-old/arm64-link.c deleted file mode 100644 index 59322c5..0000000 --- a/05/tcc-final-old/arm64-link.c +++ /dev/null @@ -1,256 +0,0 @@ -#ifdef TARGET_DEFS_ONLY - -#define EM_TCC_TARGET EM_AARCH64 - -#define R_DATA_32 R_AARCH64_ABS32 -#define R_DATA_PTR R_AARCH64_ABS64 -#define R_JMP_SLOT R_AARCH64_JUMP_SLOT -#define R_GLOB_DAT R_AARCH64_GLOB_DAT -#define R_COPY R_AARCH64_COPY -#define R_RELATIVE R_AARCH64_RELATIVE - -#define R_NUM R_AARCH64_NUM - -#define ELF_START_ADDR 0x00400000 -#define ELF_PAGE_SIZE 0x1000 - -#define PCRELATIVE_DLLPLT 1 -#define RELOCATE_DLLPLT 1 - -#else /* !TARGET_DEFS_ONLY */ - -#include "tcc.h" - -/* Returns 1 for a code relocation, 0 for a data relocation. For unknown - relocations, returns -1. */ -int code_reloc (int reloc_type) -{ - switch (reloc_type) { - case R_AARCH64_ABS32: - case R_AARCH64_ABS64: - case R_AARCH64_PREL32: - case R_AARCH64_MOVW_UABS_G0_NC: - case R_AARCH64_MOVW_UABS_G1_NC: - case R_AARCH64_MOVW_UABS_G2_NC: - case R_AARCH64_MOVW_UABS_G3: - case R_AARCH64_ADR_PREL_PG_HI21: - case R_AARCH64_ADD_ABS_LO12_NC: - case R_AARCH64_ADR_GOT_PAGE: - case R_AARCH64_LD64_GOT_LO12_NC: - case R_AARCH64_GLOB_DAT: - case R_AARCH64_COPY: - return 0; - - case R_AARCH64_JUMP26: - case R_AARCH64_CALL26: - case R_AARCH64_JUMP_SLOT: - return 1; - } - - tcc_error ("Unknown relocation type: %d", reloc_type); - return -1; -} - -/* Returns an enumerator to describe whether and when the relocation needs a - GOT and/or PLT entry to be created. See tcc.h for a description of the - different values. */ -int gotplt_entry_type (int reloc_type) -{ - switch (reloc_type) { - case R_AARCH64_PREL32: - case R_AARCH64_MOVW_UABS_G0_NC: - case R_AARCH64_MOVW_UABS_G1_NC: - case R_AARCH64_MOVW_UABS_G2_NC: - case R_AARCH64_MOVW_UABS_G3: - case R_AARCH64_ADR_PREL_PG_HI21: - case R_AARCH64_ADD_ABS_LO12_NC: - case R_AARCH64_GLOB_DAT: - case R_AARCH64_JUMP_SLOT: - case R_AARCH64_COPY: - return NO_GOTPLT_ENTRY; - - case R_AARCH64_ABS32: - case R_AARCH64_ABS64: - case R_AARCH64_JUMP26: - case R_AARCH64_CALL26: - return AUTO_GOTPLT_ENTRY; - - case R_AARCH64_ADR_GOT_PAGE: - case R_AARCH64_LD64_GOT_LO12_NC: - return ALWAYS_GOTPLT_ENTRY; - } - - tcc_error ("Unknown relocation type: %d", reloc_type); - return -1; -} - -ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr) -{ - Section *plt = s1->plt; - uint8_t *p; - unsigned plt_offset; - - if (s1->output_type == TCC_OUTPUT_DLL) - tcc_error("DLLs unimplemented!"); - - if (plt->data_offset == 0) { - section_ptr_add(plt, 32); - } - plt_offset = plt->data_offset; - - p = section_ptr_add(plt, 16); - write32le(p, got_offset); - write32le(p + 4, (uint64_t) got_offset >> 32); - return plt_offset; -} - -/* relocate the PLT: compute addresses and offsets in the PLT now that final - address for PLT and GOT are known (see fill_program_header) */ -ST_FUNC void relocate_plt(TCCState *s1) -{ - uint8_t *p, *p_end; - - if (!s1->plt) - return; - - p = s1->plt->data; - p_end = p + s1->plt->data_offset; - - if (p < p_end) { - uint64_t plt = s1->plt->sh_addr; - uint64_t got = s1->got->sh_addr; - uint64_t off = (got >> 12) - (plt >> 12); - if ((off + ((uint32_t)1 << 20)) >> 21) - tcc_error("Failed relocating PLT (off=0x%lx, got=0x%lx, plt=0x%lx)", off, got, plt); - write32le(p, 0xa9bf7bf0); // stp x16,x30,[sp,#-16]! - write32le(p + 4, (0x90000010 | // adrp x16,... - (off & 0x1ffffc) << 3 | (off & 3) << 29)); - write32le(p + 8, (0xf9400211 | // ldr x17,[x16,#...] - (got & 0xff8) << 7)); - write32le(p + 12, (0x91000210 | // add x16,x16,#... - (got & 0xfff) << 10)); - write32le(p + 16, 0xd61f0220); // br x17 - write32le(p + 20, 0xd503201f); // nop - write32le(p + 24, 0xd503201f); // nop - write32le(p + 28, 0xd503201f); // nop - p += 32; - while (p < p_end) { - uint64_t pc = plt + (p - s1->plt->data); - uint64_t addr = got + read64le(p); - uint64_t off = (addr >> 12) - (pc >> 12); - if ((off + ((uint32_t)1 << 20)) >> 21) - tcc_error("Failed relocating PLT (off=0x%lx, addr=0x%lx, pc=0x%lx)", off, addr, pc); - write32le(p, (0x90000010 | // adrp x16,... - (off & 0x1ffffc) << 3 | (off & 3) << 29)); - write32le(p + 4, (0xf9400211 | // ldr x17,[x16,#...] - (addr & 0xff8) << 7)); - write32le(p + 8, (0x91000210 | // add x16,x16,#... - (addr & 0xfff) << 10)); - write32le(p + 12, 0xd61f0220); // br x17 - p += 16; - } - } -} - -void relocate_init(Section *sr) {} - -void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val) -{ - int sym_index = ELFW(R_SYM)(rel->r_info); -#ifdef DEBUG_RELOC - ElfW(Sym) *sym = &((ElfW(Sym) *)symtab_section->data)[sym_index]; -#endif - - switch(type) { - case R_AARCH64_ABS64: - write64le(ptr, val); - return; - case R_AARCH64_ABS32: - write32le(ptr, val); - return; - case R_AARCH64_PREL32: - write32le(ptr, val - addr); - return; - case R_AARCH64_MOVW_UABS_G0_NC: - write32le(ptr, ((read32le(ptr) & 0xffe0001f) | - (val & 0xffff) << 5)); - return; - case R_AARCH64_MOVW_UABS_G1_NC: - write32le(ptr, ((read32le(ptr) & 0xffe0001f) | - (val >> 16 & 0xffff) << 5)); - return; - case R_AARCH64_MOVW_UABS_G2_NC: - write32le(ptr, ((read32le(ptr) & 0xffe0001f) | - (val >> 32 & 0xffff) << 5)); - return; - case R_AARCH64_MOVW_UABS_G3: - write32le(ptr, ((read32le(ptr) & 0xffe0001f) | - (val >> 48 & 0xffff) << 5)); - return; - case R_AARCH64_ADR_PREL_PG_HI21: { - uint64_t off = (val >> 12) - (addr >> 12); - if ((off + ((uint64_t)1 << 20)) >> 21) - tcc_error("R_AARCH64_ADR_PREL_PG_HI21 relocation failed"); - write32le(ptr, ((read32le(ptr) & 0x9f00001f) | - (off & 0x1ffffc) << 3 | (off & 3) << 29)); - return; - } - case R_AARCH64_ADD_ABS_LO12_NC: - write32le(ptr, ((read32le(ptr) & 0xffc003ff) | - (val & 0xfff) << 10)); - return; - case R_AARCH64_JUMP26: - case R_AARCH64_CALL26: -#ifdef DEBUG_RELOC - printf ("reloc %d @ 0x%lx: val=0x%lx name=%s\n", type, addr, val, - (char *) symtab_section->link->data + sym->st_name); -#endif - if (((val - addr) + ((uint64_t)1 << 27)) & ~(uint64_t)0xffffffc) - tcc_error("R_AARCH64_(JUMP|CALL)26 relocation failed" - " (val=%lx, addr=%lx)", val, addr); - write32le(ptr, (0x14000000 | - (uint32_t)(type == R_AARCH64_CALL26) << 31 | - ((val - addr) >> 2 & 0x3ffffff))); - return; - case R_AARCH64_ADR_GOT_PAGE: { - uint64_t off = - (((s1->got->sh_addr + - s1->sym_attrs[sym_index].got_offset) >> 12) - (addr >> 12)); - if ((off + ((uint64_t)1 << 20)) >> 21) - tcc_error("R_AARCH64_ADR_GOT_PAGE relocation failed"); - write32le(ptr, ((read32le(ptr) & 0x9f00001f) | - (off & 0x1ffffc) << 3 | (off & 3) << 29)); - return; - } - case R_AARCH64_LD64_GOT_LO12_NC: - write32le(ptr, - ((read32le(ptr) & 0xfff803ff) | - ((s1->got->sh_addr + - s1->sym_attrs[sym_index].got_offset) & 0xff8) << 7)); - return; - case R_AARCH64_COPY: - return; - case R_AARCH64_GLOB_DAT: - case R_AARCH64_JUMP_SLOT: - /* They don't need addend */ -#ifdef DEBUG_RELOC - printf ("reloc %d @ 0x%lx: val=0x%lx name=%s\n", type, addr, - val - rel->r_addend, - (char *) symtab_section->link->data + sym->st_name); -#endif - write64le(ptr, val - rel->r_addend); - return; - case R_AARCH64_RELATIVE: -#ifdef TCC_TARGET_PE - add32le(ptr, val - s1->pe_imagebase); -#endif - /* do nothing */ - return; - default: - fprintf(stderr, "FIXME: handle reloc type %x at %x [%p] to %x\n", - type, (unsigned)addr, ptr, (unsigned)val); - return; - } -} - -#endif /* !TARGET_DEFS_ONLY */ diff --git a/05/tcc-final-old/c67-gen.c b/05/tcc-final-old/c67-gen.c deleted file mode 100644 index bcb4b0e..0000000 --- a/05/tcc-final-old/c67-gen.c +++ /dev/null @@ -1,2540 +0,0 @@ -/* - * TMS320C67xx code generator for TCC - * - * Copyright (c) 2001, 2002 Fabrice Bellard - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifdef TARGET_DEFS_ONLY - -/* #define ASSEMBLY_LISTING_C67 */ - -/* number of available registers */ -#define NB_REGS 24 - -/* a register can belong to several classes. The classes must be - sorted from more general to more precise (see gv2() code which does - assumptions on it). */ -#define RC_INT 0x0001 /* generic integer register */ -#define RC_FLOAT 0x0002 /* generic float register */ -#define RC_EAX 0x0004 -#define RC_ST0 0x0008 -#define RC_ECX 0x0010 -#define RC_EDX 0x0020 -#define RC_INT_BSIDE 0x00000040 /* generic integer register on b side */ -#define RC_C67_A4 0x00000100 -#define RC_C67_A5 0x00000200 -#define RC_C67_B4 0x00000400 -#define RC_C67_B5 0x00000800 -#define RC_C67_A6 0x00001000 -#define RC_C67_A7 0x00002000 -#define RC_C67_B6 0x00004000 -#define RC_C67_B7 0x00008000 -#define RC_C67_A8 0x00010000 -#define RC_C67_A9 0x00020000 -#define RC_C67_B8 0x00040000 -#define RC_C67_B9 0x00080000 -#define RC_C67_A10 0x00100000 -#define RC_C67_A11 0x00200000 -#define RC_C67_B10 0x00400000 -#define RC_C67_B11 0x00800000 -#define RC_C67_A12 0x01000000 -#define RC_C67_A13 0x02000000 -#define RC_C67_B12 0x04000000 -#define RC_C67_B13 0x08000000 -#define RC_IRET RC_C67_A4 /* function return: integer register */ -#define RC_LRET RC_C67_A5 /* function return: second integer register */ -#define RC_FRET RC_C67_A4 /* function return: float register */ - -/* pretty names for the registers */ -enum { - TREG_EAX = 0, // really A2 - TREG_ECX, // really A3 - TREG_EDX, // really B0 - TREG_ST0, // really B1 - TREG_C67_A4, - TREG_C67_A5, - TREG_C67_B4, - TREG_C67_B5, - TREG_C67_A6, - TREG_C67_A7, - TREG_C67_B6, - TREG_C67_B7, - TREG_C67_A8, - TREG_C67_A9, - TREG_C67_B8, - TREG_C67_B9, - TREG_C67_A10, - TREG_C67_A11, - TREG_C67_B10, - TREG_C67_B11, - TREG_C67_A12, - TREG_C67_A13, - TREG_C67_B12, - TREG_C67_B13, -}; - -/* return registers for function */ -#define REG_IRET TREG_C67_A4 /* single word int return register */ -#define REG_LRET TREG_C67_A5 /* second word return register (for long long) */ -#define REG_FRET TREG_C67_A4 /* float return register */ - -/* defined if function parameters must be evaluated in reverse order */ -/* #define INVERT_FUNC_PARAMS */ - -/* defined if structures are passed as pointers. Otherwise structures - are directly pushed on stack. */ -/* #define FUNC_STRUCT_PARAM_AS_PTR */ - -/* pointer size, in bytes */ -#define PTR_SIZE 4 - -/* long double size and alignment, in bytes */ -#define LDOUBLE_SIZE 12 -#define LDOUBLE_ALIGN 4 -/* maximum alignment (for aligned attribute support) */ -#define MAX_ALIGN 8 - -/******************************************************/ -#else /* ! TARGET_DEFS_ONLY */ -/******************************************************/ -#include "tcc.h" - -ST_DATA const int reg_classes[NB_REGS] = { - /* eax */ RC_INT | RC_FLOAT | RC_EAX, - // only allow even regs for floats (allow for doubles) - /* ecx */ RC_INT | RC_ECX, - /* edx */ RC_INT | RC_INT_BSIDE | RC_FLOAT | RC_EDX, - // only allow even regs for floats (allow for doubles) - /* st0 */ RC_INT | RC_INT_BSIDE | RC_ST0, - /* A4 */ RC_C67_A4, - /* A5 */ RC_C67_A5, - /* B4 */ RC_C67_B4, - /* B5 */ RC_C67_B5, - /* A6 */ RC_C67_A6, - /* A7 */ RC_C67_A7, - /* B6 */ RC_C67_B6, - /* B7 */ RC_C67_B7, - /* A8 */ RC_C67_A8, - /* A9 */ RC_C67_A9, - /* B8 */ RC_C67_B8, - /* B9 */ RC_C67_B9, - /* A10 */ RC_C67_A10, - /* A11 */ RC_C67_A11, - /* B10 */ RC_C67_B10, - /* B11 */ RC_C67_B11, - /* A12 */ RC_C67_A10, - /* A13 */ RC_C67_A11, - /* B12 */ RC_C67_B10, - /* B13 */ RC_C67_B11 -}; - -// although tcc thinks it is passing parameters on the stack, -// the C67 really passes up to the first 10 params in special -// regs or regs pairs (for 64 bit params). So keep track of -// the stack offsets so we can translate to the appropriate -// reg (pair) - -#define NoCallArgsPassedOnStack 10 -int NoOfCurFuncArgs; -int TranslateStackToReg[NoCallArgsPassedOnStack]; -int ParamLocOnStack[NoCallArgsPassedOnStack]; -int TotalBytesPushedOnStack; - -#ifndef FALSE -# define FALSE 0 -# define TRUE 1 -#endif - -#undef BOOL -#define BOOL int - -#define ALWAYS_ASSERT(x) \ -do {\ - if (!(x))\ - tcc_error("internal compiler error file at %s:%d", __FILE__, __LINE__);\ -} while (0) - -/******************************************************/ -static unsigned long func_sub_sp_offset; -static int func_ret_sub; - -static BOOL C67_invert_test; -static int C67_compare_reg; - -#ifdef ASSEMBLY_LISTING_C67 -FILE *f = NULL; -#endif - -void C67_g(int c) -{ - int ind1; - if (nocode_wanted) - return; -#ifdef ASSEMBLY_LISTING_C67 - fprintf(f, " %08X", c); -#endif - ind1 = ind + 4; - if (ind1 > (int) cur_text_section->data_allocated) - section_realloc(cur_text_section, ind1); - cur_text_section->data[ind] = c & 0xff; - cur_text_section->data[ind + 1] = (c >> 8) & 0xff; - cur_text_section->data[ind + 2] = (c >> 16) & 0xff; - cur_text_section->data[ind + 3] = (c >> 24) & 0xff; - ind = ind1; -} - - -/* output a symbol and patch all calls to it */ -void gsym_addr(int t, int a) -{ - int n, *ptr; - while (t) { - ptr = (int *) (cur_text_section->data + t); - { - Sym *sym; - - // extract 32 bit address from MVKH/MVKL - n = ((*ptr >> 7) & 0xffff); - n |= ((*(ptr + 1) >> 7) & 0xffff) << 16; - - // define a label that will be relocated - - sym = get_sym_ref(&char_pointer_type, cur_text_section, a, 0); - greloc(cur_text_section, sym, t, R_C60LO16); - greloc(cur_text_section, sym, t + 4, R_C60HI16); - - // clear out where the pointer was - - *ptr &= ~(0xffff << 7); - *(ptr + 1) &= ~(0xffff << 7); - } - t = n; - } -} - -void gsym(int t) -{ - gsym_addr(t, ind); -} - -// these are regs that tcc doesn't really know about, -// but assign them unique values so the mapping routines -// can distinguish them - -#define C67_A0 105 -#define C67_SP 106 -#define C67_B3 107 -#define C67_FP 108 -#define C67_B2 109 -#define C67_CREG_ZERO -1 /* Special code for no condition reg test */ - - -int ConvertRegToRegClass(int r) -{ - // only works for A4-B13 - - return RC_C67_A4 << (r - TREG_C67_A4); -} - - -// map TCC reg to C67 reg number - -int C67_map_regn(int r) -{ - if (r == 0) // normal tcc regs - return 0x2; // A2 - else if (r == 1) // normal tcc regs - return 3; // A3 - else if (r == 2) // normal tcc regs - return 0; // B0 - else if (r == 3) // normal tcc regs - return 1; // B1 - else if (r >= TREG_C67_A4 && r <= TREG_C67_B13) // these form a pattern of alt pairs - return (((r & 0xfffffffc) >> 1) | (r & 1)) + 2; - else if (r == C67_A0) - return 0; // set to A0 (offset reg) - else if (r == C67_B2) - return 2; // set to B2 (offset reg) - else if (r == C67_B3) - return 3; // set to B3 (return address reg) - else if (r == C67_SP) - return 15; // set to SP (B15) (offset reg) - else if (r == C67_FP) - return 15; // set to FP (A15) (offset reg) - else if (r == C67_CREG_ZERO) - return 0; // Special code for no condition reg test - else - ALWAYS_ASSERT(FALSE); - - return 0; -} - -// mapping from tcc reg number to -// C67 register to condition code field -// -// valid condition code regs are: -// -// tcc reg 2 ->B0 -> 1 -// tcc reg 3 ->B1 -> 2 -// tcc reg 0 -> A2 -> 5 -// tcc reg 1 -> A3 -> X -// tcc reg B2 -> 3 - -int C67_map_regc(int r) -{ - if (r == 0) // normal tcc regs - return 0x5; - else if (r == 2) // normal tcc regs - return 0x1; - else if (r == 3) // normal tcc regs - return 0x2; - else if (r == C67_B2) // normal tcc regs - return 0x3; - else if (r == C67_CREG_ZERO) - return 0; // Special code for no condition reg test - else - ALWAYS_ASSERT(FALSE); - - return 0; -} - - -// map TCC reg to C67 reg side A or B - -int C67_map_regs(int r) -{ - if (r == 0) // normal tcc regs - return 0x0; - else if (r == 1) // normal tcc regs - return 0x0; - else if (r == 2) // normal tcc regs - return 0x1; - else if (r == 3) // normal tcc regs - return 0x1; - else if (r >= TREG_C67_A4 && r <= TREG_C67_B13) // these form a pattern of alt pairs - return (r & 2) >> 1; - else if (r == C67_A0) - return 0; // set to A side - else if (r == C67_B2) - return 1; // set to B side - else if (r == C67_B3) - return 1; // set to B side - else if (r == C67_SP) - return 0x1; // set to SP (B15) B side - else if (r == C67_FP) - return 0x0; // set to FP (A15) A side - else - ALWAYS_ASSERT(FALSE); - - return 0; -} - -int C67_map_S12(char *s) -{ - if (strstr(s, ".S1") != NULL) - return 0; - else if (strcmp(s, ".S2")) - return 1; - else - ALWAYS_ASSERT(FALSE); - - return 0; -} - -int C67_map_D12(char *s) -{ - if (strstr(s, ".D1") != NULL) - return 0; - else if (strcmp(s, ".D2")) - return 1; - else - ALWAYS_ASSERT(FALSE); - - return 0; -} - - - -void C67_asm(char *s, int a, int b, int c) -{ - BOOL xpath; - -#ifdef ASSEMBLY_LISTING_C67 - if (!f) { - f = fopen("TCC67_out.txt", "wt"); - } - fprintf(f, "%04X ", ind); -#endif - - if (strstr(s, "MVKL") == s) { - C67_g((C67_map_regn(b) << 23) | - ((a & 0xffff) << 7) | (0x0a << 2) | (C67_map_regs(b) << 1)); - } else if (strstr(s, "MVKH") == s) { - C67_g((C67_map_regn(b) << 23) | - (((a >> 16) & 0xffff) << 7) | - (0x1a << 2) | (C67_map_regs(b) << 1)); - } else if (strstr(s, "STW.D SP POST DEC") == s) { - C67_g((C67_map_regn(a) << 23) | //src - (15 << 18) | //SP B15 - (2 << 13) | //ucst5 (must keep 8 byte boundary !!) - (0xa << 9) | //mode a = post dec ucst - (0 << 8) | //r (LDDW bit 0) - (1 << 7) | //y D1/D2 use B side - (7 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(a) << 1) | //side of src - (0 << 0)); //parallel - } else if (strstr(s, "STB.D *+SP[A0]") == s) { - C67_g((C67_map_regn(a) << 23) | //src - (15 << 18) | //base reg A15 - (0 << 13) | //offset reg A0 - (5 << 9) | //mode 5 = pos offset, base reg + off reg - (0 << 8) | //r (LDDW bit 0) - (0 << 7) | //y D1/D2 A side - (3 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(a) << 1) | //side of src - (0 << 0)); //parallel - } else if (strstr(s, "STH.D *+SP[A0]") == s) { - C67_g((C67_map_regn(a) << 23) | //src - (15 << 18) | //base reg A15 - (0 << 13) | //offset reg A0 - (5 << 9) | //mode 5 = pos offset, base reg + off reg - (0 << 8) | //r (LDDW bit 0) - (0 << 7) | //y D1/D2 A side - (5 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(a) << 1) | //side of src - (0 << 0)); //parallel - } else if (strstr(s, "STB.D *+SP[A0]") == s) { - C67_g((C67_map_regn(a) << 23) | //src - (15 << 18) | //base reg A15 - (0 << 13) | //offset reg A0 - (5 << 9) | //mode 5 = pos offset, base reg + off reg - (0 << 8) | //r (LDDW bit 0) - (0 << 7) | //y D1/D2 A side - (3 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(a) << 1) | //side of src - (0 << 0)); //parallel - } else if (strstr(s, "STH.D *+SP[A0]") == s) { - C67_g((C67_map_regn(a) << 23) | //src - (15 << 18) | //base reg A15 - (0 << 13) | //offset reg A0 - (5 << 9) | //mode 5 = pos offset, base reg + off reg - (0 << 8) | //r (LDDW bit 0) - (0 << 7) | //y D1/D2 A side - (5 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(a) << 1) | //side of src - (0 << 0)); //parallel - } else if (strstr(s, "STW.D *+SP[A0]") == s) { - C67_g((C67_map_regn(a) << 23) | //src - (15 << 18) | //base reg A15 - (0 << 13) | //offset reg A0 - (5 << 9) | //mode 5 = pos offset, base reg + off reg - (0 << 8) | //r (LDDW bit 0) - (0 << 7) | //y D1/D2 A side - (7 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(a) << 1) | //side of src - (0 << 0)); //parallel - } else if (strstr(s, "STW.D *") == s) { - C67_g((C67_map_regn(a) << 23) | //src - (C67_map_regn(b) << 18) | //base reg A0 - (0 << 13) | //cst5 - (1 << 9) | //mode 1 = pos cst offset - (0 << 8) | //r (LDDW bit 0) - (C67_map_regs(b) << 7) | //y D1/D2 base reg side - (7 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(a) << 1) | //side of src - (0 << 0)); //parallel - } else if (strstr(s, "STH.D *") == s) { - C67_g((C67_map_regn(a) << 23) | //src - (C67_map_regn(b) << 18) | //base reg A0 - (0 << 13) | //cst5 - (1 << 9) | //mode 1 = pos cst offset - (0 << 8) | //r (LDDW bit 0) - (C67_map_regs(b) << 7) | //y D1/D2 base reg side - (5 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(a) << 1) | //side of src - (0 << 0)); //parallel - } else if (strstr(s, "STB.D *") == s) { - C67_g((C67_map_regn(a) << 23) | //src - (C67_map_regn(b) << 18) | //base reg A0 - (0 << 13) | //cst5 - (1 << 9) | //mode 1 = pos cst offset - (0 << 8) | //r (LDDW bit 0) - (C67_map_regs(b) << 7) | //y D1/D2 base reg side - (3 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(a) << 1) | //side of src - (0 << 0)); //parallel - } else if (strstr(s, "STW.D +*") == s) { - ALWAYS_ASSERT(c < 32); - C67_g((C67_map_regn(a) << 23) | //src - (C67_map_regn(b) << 18) | //base reg A0 - (c << 13) | //cst5 - (1 << 9) | //mode 1 = pos cst offset - (0 << 8) | //r (LDDW bit 0) - (C67_map_regs(b) << 7) | //y D1/D2 base reg side - (7 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(a) << 1) | //side of src - (0 << 0)); //parallel - } else if (strstr(s, "LDW.D SP PRE INC") == s) { - C67_g((C67_map_regn(a) << 23) | //dst - (15 << 18) | //base reg B15 - (2 << 13) | //ucst5 (must keep 8 byte boundary) - (9 << 9) | //mode 9 = pre inc ucst5 - (0 << 8) | //r (LDDW bit 0) - (1 << 7) | //y D1/D2 B side - (6 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(a) << 1) | //side of dst - (0 << 0)); //parallel - } else if (strstr(s, "LDDW.D SP PRE INC") == s) { - C67_g((C67_map_regn(a) << 23) | //dst - (15 << 18) | //base reg B15 - (1 << 13) | //ucst5 (must keep 8 byte boundary) - (9 << 9) | //mode 9 = pre inc ucst5 - (1 << 8) | //r (LDDW bit 1) - (1 << 7) | //y D1/D2 B side - (6 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(a) << 1) | //side of dst - (0 << 0)); //parallel - } else if (strstr(s, "LDW.D *+SP[A0]") == s) { - C67_g((C67_map_regn(a) << 23) | //dst - (15 << 18) | //base reg A15 - (0 << 13) | //offset reg A0 - (5 << 9) | //mode 5 = pos offset, base reg + off reg - (0 << 8) | //r (LDDW bit 0) - (0 << 7) | //y D1/D2 A side - (6 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(a) << 1) | //side of dst - (0 << 0)); //parallel - } else if (strstr(s, "LDDW.D *+SP[A0]") == s) { - C67_g((C67_map_regn(a) << 23) | //dst - (15 << 18) | //base reg A15 - (0 << 13) | //offset reg A0 - (5 << 9) | //mode 5 = pos offset, base reg + off reg - (1 << 8) | //r (LDDW bit 1) - (0 << 7) | //y D1/D2 A side - (6 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(a) << 1) | //side of dst - (0 << 0)); //parallel - } else if (strstr(s, "LDH.D *+SP[A0]") == s) { - C67_g((C67_map_regn(a) << 23) | //dst - (15 << 18) | //base reg A15 - (0 << 13) | //offset reg A0 - (5 << 9) | //mode 5 = pos offset, base reg + off reg - (0 << 8) | //r (LDDW bit 0) - (0 << 7) | //y D1/D2 A side - (4 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(a) << 1) | //side of dst - (0 << 0)); //parallel - } else if (strstr(s, "LDB.D *+SP[A0]") == s) { - C67_g((C67_map_regn(a) << 23) | //dst - (15 << 18) | //base reg A15 - (0 << 13) | //offset reg A0 - (5 << 9) | //mode 5 = pos offset, base reg + off reg - (0 << 8) | //r (LDDW bit 0) - (0 << 7) | //y D1/D2 A side - (2 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(a) << 1) | //side of dst - (0 << 0)); //parallel - } else if (strstr(s, "LDHU.D *+SP[A0]") == s) { - C67_g((C67_map_regn(a) << 23) | //dst - (15 << 18) | //base reg A15 - (0 << 13) | //offset reg A0 - (5 << 9) | //mode 5 = pos offset, base reg + off reg - (0 << 8) | //r (LDDW bit 0) - (0 << 7) | //y D1/D2 A side - (0 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(a) << 1) | //side of dst - (0 << 0)); //parallel - } else if (strstr(s, "LDBU.D *+SP[A0]") == s) { - C67_g((C67_map_regn(a) << 23) | //dst - (15 << 18) | //base reg A15 - (0 << 13) | //offset reg A0 - (5 << 9) | //mode 5 = pos offset, base reg + off reg - (0 << 8) | //r (LDDW bit 0) - (0 << 7) | //y D1/D2 A side - (1 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(a) << 1) | //side of dst - (0 << 0)); //parallel - } else if (strstr(s, "LDW.D *") == s) { - C67_g((C67_map_regn(b) << 23) | //dst - (C67_map_regn(a) << 18) | //base reg A15 - (0 << 13) | //cst5 - (1 << 9) | //mode 1 = pos cst offset - (0 << 8) | //r (LDDW bit 0) - (C67_map_regs(a) << 7) | //y D1/D2 src side - (6 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(b) << 1) | //side of dst - (0 << 0)); //parallel - } else if (strstr(s, "LDDW.D *") == s) { - C67_g((C67_map_regn(b) << 23) | //dst - (C67_map_regn(a) << 18) | //base reg A15 - (0 << 13) | //cst5 - (1 << 9) | //mode 1 = pos cst offset - (1 << 8) | //r (LDDW bit 1) - (C67_map_regs(a) << 7) | //y D1/D2 src side - (6 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(b) << 1) | //side of dst - (0 << 0)); //parallel - } else if (strstr(s, "LDH.D *") == s) { - C67_g((C67_map_regn(b) << 23) | //dst - (C67_map_regn(a) << 18) | //base reg A15 - (0 << 13) | //cst5 - (1 << 9) | //mode 1 = pos cst offset - (0 << 8) | //r (LDDW bit 0) - (C67_map_regs(a) << 7) | //y D1/D2 src side - (4 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(b) << 1) | //side of dst - (0 << 0)); //parallel - } else if (strstr(s, "LDB.D *") == s) { - C67_g((C67_map_regn(b) << 23) | //dst - (C67_map_regn(a) << 18) | //base reg A15 - (0 << 13) | //cst5 - (1 << 9) | //mode 1 = pos cst offset - (0 << 8) | //r (LDDW bit 0) - (C67_map_regs(a) << 7) | //y D1/D2 src side - (2 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(b) << 1) | //side of dst - (0 << 0)); //parallel - } else if (strstr(s, "LDHU.D *") == s) { - C67_g((C67_map_regn(b) << 23) | //dst - (C67_map_regn(a) << 18) | //base reg A15 - (0 << 13) | //cst5 - (1 << 9) | //mode 1 = pos cst offset - (0 << 8) | //r (LDDW bit 0) - (C67_map_regs(a) << 7) | //y D1/D2 src side - (0 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(b) << 1) | //side of dst - (0 << 0)); //parallel - } else if (strstr(s, "LDBU.D *") == s) { - C67_g((C67_map_regn(b) << 23) | //dst - (C67_map_regn(a) << 18) | //base reg A15 - (0 << 13) | //cst5 - (1 << 9) | //mode 1 = pos cst offset - (0 << 8) | //r (LDDW bit 0) - (C67_map_regs(a) << 7) | //y D1/D2 src side - (1 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(b) << 1) | //side of dst - (0 << 0)); //parallel - } else if (strstr(s, "LDW.D +*") == s) { - C67_g((C67_map_regn(b) << 23) | //dst - (C67_map_regn(a) << 18) | //base reg A15 - (1 << 13) | //cst5 - (1 << 9) | //mode 1 = pos cst offset - (0 << 8) | //r (LDDW bit 0) - (C67_map_regs(a) << 7) | //y D1/D2 src side - (6 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(b) << 1) | //side of dst - (0 << 0)); //parallel - } else if (strstr(s, "CMPLTSP") == s) { - xpath = C67_map_regs(a) ^ C67_map_regs(b); - ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a)); - - C67_g((C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x use cross path for src2 - (0x3a << 6) | //opcode - (0x8 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side for reg c - (0 << 0)); //parallel - } else if (strstr(s, "CMPGTSP") == s) { - xpath = C67_map_regs(a) ^ C67_map_regs(b); - ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a)); - - C67_g((C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x use cross path for src2 - (0x39 << 6) | //opcode - (0x8 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side for reg c - (0 << 0)); //parallel - } else if (strstr(s, "CMPEQSP") == s) { - xpath = C67_map_regs(a) ^ C67_map_regs(b); - ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a)); - - C67_g((C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x use cross path for src2 - (0x38 << 6) | //opcode - (0x8 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side for reg c - (0 << 0)); //parallel - } - - else if (strstr(s, "CMPLTDP") == s) { - xpath = C67_map_regs(a) ^ C67_map_regs(b); - ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a)); - - C67_g((C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x use cross path for src2 - (0x2a << 6) | //opcode - (0x8 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side for reg c - (0 << 0)); //parallel - } else if (strstr(s, "CMPGTDP") == s) { - xpath = C67_map_regs(a) ^ C67_map_regs(b); - ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a)); - - C67_g((C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x use cross path for src2 - (0x29 << 6) | //opcode - (0x8 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side for reg c - (0 << 0)); //parallel - } else if (strstr(s, "CMPEQDP") == s) { - xpath = C67_map_regs(a) ^ C67_map_regs(b); - ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a)); - - C67_g((C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x use cross path for src2 - (0x28 << 6) | //opcode - (0x8 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side for reg c - (0 << 0)); //parallel - } else if (strstr(s, "CMPLT") == s) { - xpath = C67_map_regs(a) ^ C67_map_regs(b); - ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a)); - - C67_g((C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x use cross path for src2 - (0x57 << 5) | //opcode - (0x6 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side for reg c - (0 << 0)); //parallel - } else if (strstr(s, "CMPGT") == s) { - xpath = C67_map_regs(a) ^ C67_map_regs(b); - ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a)); - - C67_g((C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x use cross path for src2 - (0x47 << 5) | //opcode - (0x6 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side for reg c - (0 << 0)); //parallel - } else if (strstr(s, "CMPEQ") == s) { - xpath = C67_map_regs(a) ^ C67_map_regs(b); - ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a)); - - C67_g((C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x use cross path for src2 - (0x53 << 5) | //opcode - (0x6 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side for reg c - (0 << 0)); //parallel - } else if (strstr(s, "CMPLTU") == s) { - xpath = C67_map_regs(a) ^ C67_map_regs(b); - ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a)); - - C67_g((C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x use cross path for src2 - (0x5f << 5) | //opcode - (0x6 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side for reg c - (0 << 0)); //parallel - } else if (strstr(s, "CMPGTU") == s) { - xpath = C67_map_regs(a) ^ C67_map_regs(b); - ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a)); - - C67_g((C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x use cross path for src2 - (0x4f << 5) | //opcode - (0x6 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side for reg c - (0 << 0)); //parallel - } else if (strstr(s, "B DISP") == s) { - C67_g((0 << 29) | //creg - (0 << 28) | //z - (a << 7) | //cnst - (0x4 << 2) | //opcode fixed - (0 << 1) | //S0/S1 - (0 << 0)); //parallel - } else if (strstr(s, "B.") == s) { - xpath = C67_map_regs(c) ^ 1; - - C67_g((C67_map_regc(b) << 29) | //creg - (a << 28) | //inv - (0 << 23) | //dst - (C67_map_regn(c) << 18) | //src2 - (0 << 13) | // - (xpath << 12) | //x cross path if !B side - (0xd << 6) | //opcode - (0x8 << 2) | //opcode fixed - (1 << 1) | //must be S2 - (0 << 0)); //parallel - } else if (strstr(s, "MV.L") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 - (0 << 13) | //src1 (cst5) - (xpath << 12) | //x cross path if opposite sides - (0x2 << 5) | //opcode - (0x6 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "SPTRUNC.L") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 - (0 << 13) | //src1 NA - (xpath << 12) | //x cross path if opposite sides - (0xb << 5) | //opcode - (0x6 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "DPTRUNC.L") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - ((C67_map_regn(b) + 1) << 18) | //src2 WEIRD CPU must specify odd reg for some reason - (0 << 13) | //src1 NA - (xpath << 12) | //x cross path if opposite sides - (0x1 << 5) | //opcode - (0x6 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "INTSP.L") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 - (0 << 13) | //src1 NA - (xpath << 12) | //x cross path if opposite sides - (0x4a << 5) | //opcode - (0x6 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "INTSPU.L") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 - (0 << 13) | //src1 NA - (xpath << 12) | //x cross path if opposite sides - (0x49 << 5) | //opcode - (0x6 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "INTDP.L") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 - (0 << 13) | //src1 NA - (xpath << 12) | //x cross path if opposite sides - (0x39 << 5) | //opcode - (0x6 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "INTDPU.L") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - ((C67_map_regn(b) + 1) << 18) | //src2 WEIRD CPU must specify odd reg for some reason - (0 << 13) | //src1 NA - (xpath << 12) | //x cross path if opposite sides - (0x3b << 5) | //opcode - (0x6 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "SPDP.L") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 - (0 << 13) | //src1 NA - (xpath << 12) | //x cross path if opposite sides - (0x2 << 6) | //opcode - (0x8 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "DPSP.L") == s) { - ALWAYS_ASSERT(C67_map_regs(b) == C67_map_regs(c)); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - ((C67_map_regn(b) + 1) << 18) | //src2 WEIRD CPU must specify odd reg for some reason - (0 << 13) | //src1 NA - (0 << 12) | //x cross path if opposite sides - (0x9 << 5) | //opcode - (0x6 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "ADD.L") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c)); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 (possible x path) - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x cross path if opposite sides - (0x3 << 5) | //opcode - (0x6 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "SUB.L") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c)); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 (possible x path) - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x cross path if opposite sides - (0x7 << 5) | //opcode - (0x6 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "OR.L") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c)); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 (possible x path) - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x cross path if opposite sides - (0x7f << 5) | //opcode - (0x6 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "AND.L") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c)); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 (possible x path) - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x cross path if opposite sides - (0x7b << 5) | //opcode - (0x6 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "XOR.L") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c)); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 (possible x path) - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x cross path if opposite sides - (0x6f << 5) | //opcode - (0x6 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "ADDSP.L") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c)); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 (possible x path) - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x cross path if opposite sides - (0x10 << 5) | //opcode - (0x6 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "ADDDP.L") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c)); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 (possible x path) - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x cross path if opposite sides - (0x18 << 5) | //opcode - (0x6 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "SUBSP.L") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c)); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 (possible x path) - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x cross path if opposite sides - (0x11 << 5) | //opcode - (0x6 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "SUBDP.L") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c)); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 (possible x path) - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x cross path if opposite sides - (0x19 << 5) | //opcode - (0x6 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "MPYSP.M") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c)); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 (possible x path) - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x cross path if opposite sides - (0x1c << 7) | //opcode - (0x0 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "MPYDP.M") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c)); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 (possible x path) - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x cross path if opposite sides - (0x0e << 7) | //opcode - (0x0 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "MPYI.M") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c)); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 - (C67_map_regn(a) << 13) | //src1 (cst5) - (xpath << 12) | //x cross path if opposite sides - (0x4 << 7) | //opcode - (0x0 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "SHR.S") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a)); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x cross path if opposite sides - (0x37 << 6) | //opcode - (0x8 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "SHRU.S") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a)); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x cross path if opposite sides - (0x27 << 6) | //opcode - (0x8 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "SHL.S") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a)); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x cross path if opposite sides - (0x33 << 6) | //opcode - (0x8 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "||ADDK") == s) { - xpath = 0; // no xpath required just use the side of the src/dst - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(b) << 23) | //dst - (a << 07) | //scst16 - (0x14 << 2) | //opcode fixed - (C67_map_regs(b) << 1) | //side of dst - (1 << 0)); //parallel - } else if (strstr(s, "ADDK") == s) { - xpath = 0; // no xpath required just use the side of the src/dst - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(b) << 23) | //dst - (a << 07) | //scst16 - (0x14 << 2) | //opcode fixed - (C67_map_regs(b) << 1) | //side of dst - (0 << 0)); //parallel - } else if (strstr(s, "NOP") == s) { - C67_g(((a - 1) << 13) | //no of cycles - (0 << 0)); //parallel - } else - ALWAYS_ASSERT(FALSE); - -#ifdef ASSEMBLY_LISTING_C67 - fprintf(f, " %s %d %d %d\n", s, a, b, c); -#endif - -} - -//r=reg to load, fr=from reg, symbol for relocation, constant - -void C67_MVKL(int r, int fc) -{ - C67_asm("MVKL.", fc, r, 0); -} - -void C67_MVKH(int r, int fc) -{ - C67_asm("MVKH.", fc, r, 0); -} - -void C67_STB_SP_A0(int r) -{ - C67_asm("STB.D *+SP[A0]", r, 0, 0); // STB r,*+SP[A0] -} - -void C67_STH_SP_A0(int r) -{ - C67_asm("STH.D *+SP[A0]", r, 0, 0); // STH r,*+SP[A0] -} - -void C67_STW_SP_A0(int r) -{ - C67_asm("STW.D *+SP[A0]", r, 0, 0); // STW r,*+SP[A0] -} - -void C67_STB_PTR(int r, int r2) -{ - C67_asm("STB.D *", r, r2, 0); // STB r, *r2 -} - -void C67_STH_PTR(int r, int r2) -{ - C67_asm("STH.D *", r, r2, 0); // STH r, *r2 -} - -void C67_STW_PTR(int r, int r2) -{ - C67_asm("STW.D *", r, r2, 0); // STW r, *r2 -} - -void C67_STW_PTR_PRE_INC(int r, int r2, int n) -{ - C67_asm("STW.D +*", r, r2, n); // STW r, *+r2 -} - -void C67_PUSH(int r) -{ - C67_asm("STW.D SP POST DEC", r, 0, 0); // STW r,*SP-- -} - -void C67_LDW_SP_A0(int r) -{ - C67_asm("LDW.D *+SP[A0]", r, 0, 0); // LDW *+SP[A0],r -} - -void C67_LDDW_SP_A0(int r) -{ - C67_asm("LDDW.D *+SP[A0]", r, 0, 0); // LDDW *+SP[A0],r -} - -void C67_LDH_SP_A0(int r) -{ - C67_asm("LDH.D *+SP[A0]", r, 0, 0); // LDH *+SP[A0],r -} - -void C67_LDB_SP_A0(int r) -{ - C67_asm("LDB.D *+SP[A0]", r, 0, 0); // LDB *+SP[A0],r -} - -void C67_LDHU_SP_A0(int r) -{ - C67_asm("LDHU.D *+SP[A0]", r, 0, 0); // LDHU *+SP[A0],r -} - -void C67_LDBU_SP_A0(int r) -{ - C67_asm("LDBU.D *+SP[A0]", r, 0, 0); // LDBU *+SP[A0],r -} - -void C67_LDW_PTR(int r, int r2) -{ - C67_asm("LDW.D *", r, r2, 0); // LDW *r,r2 -} - -void C67_LDDW_PTR(int r, int r2) -{ - C67_asm("LDDW.D *", r, r2, 0); // LDDW *r,r2 -} - -void C67_LDH_PTR(int r, int r2) -{ - C67_asm("LDH.D *", r, r2, 0); // LDH *r,r2 -} - -void C67_LDB_PTR(int r, int r2) -{ - C67_asm("LDB.D *", r, r2, 0); // LDB *r,r2 -} - -void C67_LDHU_PTR(int r, int r2) -{ - C67_asm("LDHU.D *", r, r2, 0); // LDHU *r,r2 -} - -void C67_LDBU_PTR(int r, int r2) -{ - C67_asm("LDBU.D *", r, r2, 0); // LDBU *r,r2 -} - -void C67_LDW_PTR_PRE_INC(int r, int r2) -{ - C67_asm("LDW.D +*", r, r2, 0); // LDW *+r,r2 -} - -void C67_POP(int r) -{ - C67_asm("LDW.D SP PRE INC", r, 0, 0); // LDW *++SP,r -} - -void C67_POP_DW(int r) -{ - C67_asm("LDDW.D SP PRE INC", r, 0, 0); // LDDW *++SP,r -} - -void C67_CMPLT(int s1, int s2, int dst) -{ - C67_asm("CMPLT.L1", s1, s2, dst); -} - -void C67_CMPGT(int s1, int s2, int dst) -{ - C67_asm("CMPGT.L1", s1, s2, dst); -} - -void C67_CMPEQ(int s1, int s2, int dst) -{ - C67_asm("CMPEQ.L1", s1, s2, dst); -} - -void C67_CMPLTU(int s1, int s2, int dst) -{ - C67_asm("CMPLTU.L1", s1, s2, dst); -} - -void C67_CMPGTU(int s1, int s2, int dst) -{ - C67_asm("CMPGTU.L1", s1, s2, dst); -} - - -void C67_CMPLTSP(int s1, int s2, int dst) -{ - C67_asm("CMPLTSP.S1", s1, s2, dst); -} - -void C67_CMPGTSP(int s1, int s2, int dst) -{ - C67_asm("CMPGTSP.S1", s1, s2, dst); -} - -void C67_CMPEQSP(int s1, int s2, int dst) -{ - C67_asm("CMPEQSP.S1", s1, s2, dst); -} - -void C67_CMPLTDP(int s1, int s2, int dst) -{ - C67_asm("CMPLTDP.S1", s1, s2, dst); -} - -void C67_CMPGTDP(int s1, int s2, int dst) -{ - C67_asm("CMPGTDP.S1", s1, s2, dst); -} - -void C67_CMPEQDP(int s1, int s2, int dst) -{ - C67_asm("CMPEQDP.S1", s1, s2, dst); -} - - -void C67_IREG_B_REG(int inv, int r1, int r2) // [!R] B r2 -{ - C67_asm("B.S2", inv, r1, r2); -} - - -// call with how many 32 bit words to skip -// (0 would branch to the branch instruction) - -void C67_B_DISP(int disp) // B +2 Branch with constant displacement -{ - // Branch point is relative to the 8 word fetch packet - // - // we will assume the text section always starts on an 8 word (32 byte boundary) - // - // so add in how many words into the fetch packet the branch is - - - C67_asm("B DISP", disp + ((ind & 31) >> 2), 0, 0); -} - -void C67_NOP(int n) -{ - C67_asm("NOP", n, 0, 0); -} - -void C67_ADDK(int n, int r) -{ - ALWAYS_ASSERT(abs(n) < 32767); - - C67_asm("ADDK", n, r, 0); -} - -void C67_ADDK_PARALLEL(int n, int r) -{ - ALWAYS_ASSERT(abs(n) < 32767); - - C67_asm("||ADDK", n, r, 0); -} - -void C67_Adjust_ADDK(int *inst, int n) -{ - ALWAYS_ASSERT(abs(n) < 32767); - - *inst = (*inst & (~(0xffff << 7))) | ((n & 0xffff) << 7); -} - -void C67_MV(int r, int v) -{ - C67_asm("MV.L", 0, r, v); -} - - -void C67_DPTRUNC(int r, int v) -{ - C67_asm("DPTRUNC.L", 0, r, v); -} - -void C67_SPTRUNC(int r, int v) -{ - C67_asm("SPTRUNC.L", 0, r, v); -} - -void C67_INTSP(int r, int v) -{ - C67_asm("INTSP.L", 0, r, v); -} - -void C67_INTDP(int r, int v) -{ - C67_asm("INTDP.L", 0, r, v); -} - -void C67_INTSPU(int r, int v) -{ - C67_asm("INTSPU.L", 0, r, v); -} - -void C67_INTDPU(int r, int v) -{ - C67_asm("INTDPU.L", 0, r, v); -} - -void C67_SPDP(int r, int v) -{ - C67_asm("SPDP.L", 0, r, v); -} - -void C67_DPSP(int r, int v) // note regs must be on the same side -{ - C67_asm("DPSP.L", 0, r, v); -} - -void C67_ADD(int r, int v) -{ - C67_asm("ADD.L", v, r, v); -} - -void C67_SUB(int r, int v) -{ - C67_asm("SUB.L", v, r, v); -} - -void C67_AND(int r, int v) -{ - C67_asm("AND.L", v, r, v); -} - -void C67_OR(int r, int v) -{ - C67_asm("OR.L", v, r, v); -} - -void C67_XOR(int r, int v) -{ - C67_asm("XOR.L", v, r, v); -} - -void C67_ADDSP(int r, int v) -{ - C67_asm("ADDSP.L", v, r, v); -} - -void C67_SUBSP(int r, int v) -{ - C67_asm("SUBSP.L", v, r, v); -} - -void C67_MPYSP(int r, int v) -{ - C67_asm("MPYSP.M", v, r, v); -} - -void C67_ADDDP(int r, int v) -{ - C67_asm("ADDDP.L", v, r, v); -} - -void C67_SUBDP(int r, int v) -{ - C67_asm("SUBDP.L", v, r, v); -} - -void C67_MPYDP(int r, int v) -{ - C67_asm("MPYDP.M", v, r, v); -} - -void C67_MPYI(int r, int v) -{ - C67_asm("MPYI.M", v, r, v); -} - -void C67_SHL(int r, int v) -{ - C67_asm("SHL.S", r, v, v); -} - -void C67_SHRU(int r, int v) -{ - C67_asm("SHRU.S", r, v, v); -} - -void C67_SHR(int r, int v) -{ - C67_asm("SHR.S", r, v, v); -} - - - -/* load 'r' from value 'sv' */ -void load(int r, SValue * sv) -{ - int v, t, ft, fc, fr, size = 0, element; - BOOL Unsigned = FALSE; - SValue v1; - - fr = sv->r; - ft = sv->type.t; - fc = sv->c.i; - - v = fr & VT_VALMASK; - if (fr & VT_LVAL) { - if (v == VT_LLOCAL) { - v1.type.t = VT_INT; - v1.r = VT_LOCAL | VT_LVAL; - v1.c.i = fc; - load(r, &v1); - fr = r; - } else if ((ft & VT_BTYPE) == VT_LDOUBLE) { - tcc_error("long double not supported"); - } else if ((ft & VT_TYPE) == VT_BYTE) { - size = 1; - } else if ((ft & VT_TYPE) == (VT_BYTE | VT_UNSIGNED)) { - size = 1; - Unsigned = TRUE; - } else if ((ft & VT_TYPE) == VT_SHORT) { - size = 2; - } else if ((ft & VT_TYPE) == (VT_SHORT | VT_UNSIGNED)) { - size = 2; - Unsigned = TRUE; - } else if ((ft & VT_BTYPE) == VT_DOUBLE) { - size = 8; - } else { - size = 4; - } - - // check if fc is a positive reference on the stack, - // if it is tcc is referencing what it thinks is a parameter - // on the stack, so check if it is really in a register. - - - if (v == VT_LOCAL && fc > 0) { - int stack_pos = 8; - - for (t = 0; t < NoCallArgsPassedOnStack; t++) { - if (fc == stack_pos) - break; - - stack_pos += TranslateStackToReg[t]; - } - - // param has been pushed on stack, get it like a local var - - fc = ParamLocOnStack[t] - 8; - } - - if ((fr & VT_VALMASK) < VT_CONST) // check for pure indirect - { - if (size == 1) { - if (Unsigned) - C67_LDBU_PTR(v, r); // LDBU *v,r - else - C67_LDB_PTR(v, r); // LDB *v,r - } else if (size == 2) { - if (Unsigned) - C67_LDHU_PTR(v, r); // LDHU *v,r - else - C67_LDH_PTR(v, r); // LDH *v,r - } else if (size == 4) { - C67_LDW_PTR(v, r); // LDW *v,r - } else if (size == 8) { - C67_LDDW_PTR(v, r); // LDDW *v,r - } - - C67_NOP(4); // NOP 4 - return; - } else if (fr & VT_SYM) { - greloc(cur_text_section, sv->sym, ind, R_C60LO16); // rem the inst need to be patched - greloc(cur_text_section, sv->sym, ind + 4, R_C60HI16); - - - C67_MVKL(C67_A0, fc); //r=reg to load, constant - C67_MVKH(C67_A0, fc); //r=reg to load, constant - - - if (size == 1) { - if (Unsigned) - C67_LDBU_PTR(C67_A0, r); // LDBU *A0,r - else - C67_LDB_PTR(C67_A0, r); // LDB *A0,r - } else if (size == 2) { - if (Unsigned) - C67_LDHU_PTR(C67_A0, r); // LDHU *A0,r - else - C67_LDH_PTR(C67_A0, r); // LDH *A0,r - } else if (size == 4) { - C67_LDW_PTR(C67_A0, r); // LDW *A0,r - } else if (size == 8) { - C67_LDDW_PTR(C67_A0, r); // LDDW *A0,r - } - - C67_NOP(4); // NOP 4 - return; - } else { - element = size; - - // divide offset in bytes to create element index - C67_MVKL(C67_A0, (fc / element) + 8 / element); //r=reg to load, constant - C67_MVKH(C67_A0, (fc / element) + 8 / element); //r=reg to load, constant - - if (size == 1) { - if (Unsigned) - C67_LDBU_SP_A0(r); // LDBU r, SP[A0] - else - C67_LDB_SP_A0(r); // LDB r, SP[A0] - } else if (size == 2) { - if (Unsigned) - C67_LDHU_SP_A0(r); // LDHU r, SP[A0] - else - C67_LDH_SP_A0(r); // LDH r, SP[A0] - } else if (size == 4) { - C67_LDW_SP_A0(r); // LDW r, SP[A0] - } else if (size == 8) { - C67_LDDW_SP_A0(r); // LDDW r, SP[A0] - } - - - C67_NOP(4); // NOP 4 - return; - } - } else { - if (v == VT_CONST) { - if (fr & VT_SYM) { - greloc(cur_text_section, sv->sym, ind, R_C60LO16); // rem the inst need to be patched - greloc(cur_text_section, sv->sym, ind + 4, R_C60HI16); - } - C67_MVKL(r, fc); //r=reg to load, constant - C67_MVKH(r, fc); //r=reg to load, constant - } else if (v == VT_LOCAL) { - C67_MVKL(r, fc + 8); //r=reg to load, constant C67 stack points to next free - C67_MVKH(r, fc + 8); //r=reg to load, constant - C67_ADD(C67_FP, r); // MV v,r v -> r - } else if (v == VT_CMP) { - C67_MV(C67_compare_reg, r); // MV v,r v -> r - } else if (v == VT_JMP || v == VT_JMPI) { - t = v & 1; - C67_B_DISP(4); // Branch with constant displacement, skip over this branch, load, nop, load - C67_MVKL(r, t); // r=reg to load, 0 or 1 (do this while branching) - C67_NOP(4); // NOP 4 - gsym(fc); // modifies other branches to branch here - C67_MVKL(r, t ^ 1); // r=reg to load, 0 or 1 - } else if (v != r) { - C67_MV(v, r); // MV v,r v -> r - - if ((ft & VT_BTYPE) == VT_DOUBLE) - C67_MV(v + 1, r + 1); // MV v,r v -> r - } - } -} - - -/* store register 'r' in lvalue 'v' */ -void store(int r, SValue * v) -{ - int fr, bt, ft, fc, size, t, element; - - ft = v->type.t; - fc = v->c.i; - fr = v->r & VT_VALMASK; - bt = ft & VT_BTYPE; - /* XXX: incorrect if float reg to reg */ - - if (bt == VT_LDOUBLE) { - tcc_error("long double not supported"); - } else { - if (bt == VT_SHORT) - size = 2; - else if (bt == VT_BYTE) - size = 1; - else if (bt == VT_DOUBLE) - size = 8; - else - size = 4; - - if ((v->r & VT_VALMASK) == VT_CONST) { - /* constant memory reference */ - - if (v->r & VT_SYM) { - greloc(cur_text_section, v->sym, ind, R_C60LO16); // rem the inst need to be patched - greloc(cur_text_section, v->sym, ind + 4, R_C60HI16); - } - C67_MVKL(C67_A0, fc); //r=reg to load, constant - C67_MVKH(C67_A0, fc); //r=reg to load, constant - - if (size == 1) - C67_STB_PTR(r, C67_A0); // STB r, *A0 - else if (size == 2) - C67_STH_PTR(r, C67_A0); // STH r, *A0 - else if (size == 4 || size == 8) - C67_STW_PTR(r, C67_A0); // STW r, *A0 - - if (size == 8) - C67_STW_PTR_PRE_INC(r + 1, C67_A0, 1); // STW r, *+A0[1] - } else if ((v->r & VT_VALMASK) == VT_LOCAL) { - // check case of storing to passed argument that - // tcc thinks is on the stack but for C67 is - // passed as a reg. However it may have been - // saved to the stack, if that reg was required - // for a call to a child function - - if (fc > 0) // argument ?? - { - // walk through sizes and figure which param - - int stack_pos = 8; - - for (t = 0; t < NoCallArgsPassedOnStack; t++) { - if (fc == stack_pos) - break; - - stack_pos += TranslateStackToReg[t]; - } - - // param has been pushed on stack, get it like a local var - fc = ParamLocOnStack[t] - 8; - } - - if (size == 8) - element = 4; - else - element = size; - - // divide offset in bytes to create word index - C67_MVKL(C67_A0, (fc / element) + 8 / element); //r=reg to load, constant - C67_MVKH(C67_A0, (fc / element) + 8 / element); //r=reg to load, constant - - - - if (size == 1) - C67_STB_SP_A0(r); // STB r, SP[A0] - else if (size == 2) - C67_STH_SP_A0(r); // STH r, SP[A0] - else if (size == 4 || size == 8) - C67_STW_SP_A0(r); // STW r, SP[A0] - - if (size == 8) { - C67_ADDK(1, C67_A0); // ADDK 1,A0 - C67_STW_SP_A0(r + 1); // STW r, SP[A0] - } - } else { - if (size == 1) - C67_STB_PTR(r, fr); // STB r, *fr - else if (size == 2) - C67_STH_PTR(r, fr); // STH r, *fr - else if (size == 4 || size == 8) - C67_STW_PTR(r, fr); // STW r, *fr - - if (size == 8) { - C67_STW_PTR_PRE_INC(r + 1, fr, 1); // STW r, *+fr[1] - } - } - } -} - -/* 'is_jmp' is '1' if it is a jump */ -static void gcall_or_jmp(int is_jmp) -{ - int r; - Sym *sym; - - if ((vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST) { - /* constant case */ - if (vtop->r & VT_SYM) { - /* relocation case */ - - // get add into A0, then start the jump B3 - - greloc(cur_text_section, vtop->sym, ind, R_C60LO16); // rem the inst need to be patched - greloc(cur_text_section, vtop->sym, ind + 4, R_C60HI16); - - C67_MVKL(C67_A0, 0); //r=reg to load, constant - C67_MVKH(C67_A0, 0); //r=reg to load, constant - C67_IREG_B_REG(0, C67_CREG_ZERO, C67_A0); // B.S2x A0 - - if (is_jmp) { - C67_NOP(5); // simple jump, just put NOP - } else { - // Call, must load return address into B3 during delay slots - - sym = get_sym_ref(&char_pointer_type, cur_text_section, ind + 12, 0); // symbol for return address - greloc(cur_text_section, sym, ind, R_C60LO16); // rem the inst need to be patched - greloc(cur_text_section, sym, ind + 4, R_C60HI16); - C67_MVKL(C67_B3, 0); //r=reg to load, constant - C67_MVKH(C67_B3, 0); //r=reg to load, constant - C67_NOP(3); // put remaining NOPs - } - } else { - /* put an empty PC32 relocation */ - ALWAYS_ASSERT(FALSE); - } - } else { - /* otherwise, indirect call */ - r = gv(RC_INT); - C67_IREG_B_REG(0, C67_CREG_ZERO, r); // B.S2x r - - if (is_jmp) { - C67_NOP(5); // simple jump, just put NOP - } else { - // Call, must load return address into B3 during delay slots - - sym = get_sym_ref(&char_pointer_type, cur_text_section, ind + 12, 0); // symbol for return address - greloc(cur_text_section, sym, ind, R_C60LO16); // rem the inst need to be patched - greloc(cur_text_section, sym, ind + 4, R_C60HI16); - C67_MVKL(C67_B3, 0); //r=reg to load, constant - C67_MVKH(C67_B3, 0); //r=reg to load, constant - C67_NOP(3); // put remaining NOPs - } - } -} - -/* Return the number of registers needed to return the struct, or 0 if - returning via struct pointer. */ -ST_FUNC int gfunc_sret(CType *vt, int variadic, CType *ret, int *ret_align, int *regsize) { - *ret_align = 1; // Never have to re-align return values for x86-64 - return 0; -} - -/* generate function call with address in (vtop->t, vtop->c) and free function - context. Stack entry is popped */ -void gfunc_call(int nb_args) -{ - int i, r, size = 0; - int args_sizes[NoCallArgsPassedOnStack]; - - if (nb_args > NoCallArgsPassedOnStack) { - tcc_error("more than 10 function params not currently supported"); - // handle more than 10, put some on the stack - } - - for (i = 0; i < nb_args; i++) { - if ((vtop->type.t & VT_BTYPE) == VT_STRUCT) { - ALWAYS_ASSERT(FALSE); - } else { - /* simple type (currently always same size) */ - /* XXX: implicit cast ? */ - - - if ((vtop->type.t & VT_BTYPE) == VT_LLONG) { - tcc_error("long long not supported"); - } else if ((vtop->type.t & VT_BTYPE) == VT_LDOUBLE) { - tcc_error("long double not supported"); - } else if ((vtop->type.t & VT_BTYPE) == VT_DOUBLE) { - size = 8; - } else { - size = 4; - } - - // put the parameter into the corresponding reg (pair) - - r = gv(RC_C67_A4 << (2 * i)); - - // must put on stack because with 1 pass compiler , no way to tell - // if an up coming nested call might overwrite these regs - - C67_PUSH(r); - - if (size == 8) { - C67_STW_PTR_PRE_INC(r + 1, C67_SP, 3); // STW r, *+SP[3] (go back and put the other) - } - args_sizes[i] = size; - } - vtop--; - } - // POP all the params on the stack into registers for the - // immediate call (in reverse order) - - for (i = nb_args - 1; i >= 0; i--) { - - if (args_sizes[i] == 8) - C67_POP_DW(TREG_C67_A4 + i * 2); - else - C67_POP(TREG_C67_A4 + i * 2); - } - gcall_or_jmp(0); - vtop--; -} - - -// to be compatible with Code Composer for the C67 -// the first 10 parameters must be passed in registers -// (pairs for 64 bits) starting wit; A4:A5, then B4:B5 and -// ending with B12:B13. -// -// When a call is made, if the caller has its parameters -// in regs A4-B13 these must be saved before/as the call -// parameters are loaded and restored upon return (or if/when needed). - -/* generate function prolog of type 't' */ -void gfunc_prolog(CType * func_type) -{ - int addr, align, size, func_call, i; - Sym *sym; - CType *type; - - sym = func_type->ref; - func_call = sym->f.func_call; - addr = 8; - /* if the function returns a structure, then add an - implicit pointer parameter */ - func_vt = sym->type; - func_var = (sym->f.func_type == FUNC_ELLIPSIS); - if ((func_vt.t & VT_BTYPE) == VT_STRUCT) { - func_vc = addr; - addr += 4; - } - - NoOfCurFuncArgs = 0; - - /* define parameters */ - while ((sym = sym->next) != NULL) { - type = &sym->type; - sym_push(sym->v & ~SYM_FIELD, type, VT_LOCAL | lvalue_type(type->t), addr); - size = type_size(type, &align); - size = (size + 3) & ~3; - - // keep track of size of arguments so - // we can translate where tcc thinks they - // are on the stack into the appropriate reg - - TranslateStackToReg[NoOfCurFuncArgs] = size; - NoOfCurFuncArgs++; - -#ifdef FUNC_STRUCT_PARAM_AS_PTR - /* structs are passed as pointer */ - if ((type->t & VT_BTYPE) == VT_STRUCT) { - size = 4; - } -#endif - addr += size; - } - func_ret_sub = 0; - /* pascal type call ? */ - if (func_call == FUNC_STDCALL) - func_ret_sub = addr - 8; - - C67_MV(C67_FP, C67_A0); // move FP -> A0 - C67_MV(C67_SP, C67_FP); // move SP -> FP - - // place all the args passed in regs onto the stack - - loc = 0; - for (i = 0; i < NoOfCurFuncArgs; i++) { - - ParamLocOnStack[i] = loc; // remember where the param is - loc += -8; - - C67_PUSH(TREG_C67_A4 + i * 2); - - if (TranslateStackToReg[i] == 8) { - C67_STW_PTR_PRE_INC(TREG_C67_A4 + i * 2 + 1, C67_SP, 3); // STW r, *+SP[1] (go back and put the other) - } - } - - TotalBytesPushedOnStack = -loc; - - func_sub_sp_offset = ind; // remember where we put the stack instruction - C67_ADDK(0, C67_SP); // ADDK.L2 loc,SP (just put zero temporarily) - - C67_PUSH(C67_A0); - C67_PUSH(C67_B3); -} - -/* generate function epilog */ -void gfunc_epilog(void) -{ - { - int local = (-loc + 7) & -8; // stack must stay aligned to 8 bytes for LDDW instr - C67_POP(C67_B3); - C67_NOP(4); // NOP wait for load - C67_IREG_B_REG(0, C67_CREG_ZERO, C67_B3); // B.S2 B3 - C67_POP(C67_FP); - C67_ADDK(local, C67_SP); // ADDK.L2 loc,SP - C67_Adjust_ADDK((int *) (cur_text_section->data + - func_sub_sp_offset), - -local + TotalBytesPushedOnStack); - C67_NOP(3); // NOP - } -} - -/* generate a jump to a label */ -int gjmp(int t) -{ - int ind1 = ind; - if (nocode_wanted) - return t; - - C67_MVKL(C67_A0, t); //r=reg to load, constant - C67_MVKH(C67_A0, t); //r=reg to load, constant - C67_IREG_B_REG(0, C67_CREG_ZERO, C67_A0); // [!R] B.S2x A0 - C67_NOP(5); - return ind1; -} - -/* generate a jump to a fixed address */ -void gjmp_addr(int a) -{ - Sym *sym; - // I guess this routine is used for relative short - // local jumps, for now just handle it as the general - // case - - // define a label that will be relocated - - sym = get_sym_ref(&char_pointer_type, cur_text_section, a, 0); - greloc(cur_text_section, sym, ind, R_C60LO16); - greloc(cur_text_section, sym, ind + 4, R_C60HI16); - - gjmp(0); // place a zero there later the symbol will be added to it -} - -/* generate a test. set 'inv' to invert test. Stack entry is popped */ -int gtst(int inv, int t) -{ - int ind1, n; - int v, *p; - - v = vtop->r & VT_VALMASK; - if (nocode_wanted) { - ; - } else if (v == VT_CMP) { - /* fast case : can jump directly since flags are set */ - // C67 uses B2 sort of as flags register - ind1 = ind; - C67_MVKL(C67_A0, t); //r=reg to load, constant - C67_MVKH(C67_A0, t); //r=reg to load, constant - - if (C67_compare_reg != TREG_EAX && // check if not already in a conditional test reg - C67_compare_reg != TREG_EDX && - C67_compare_reg != TREG_ST0 && C67_compare_reg != C67_B2) { - C67_MV(C67_compare_reg, C67_B2); - C67_compare_reg = C67_B2; - } - - C67_IREG_B_REG(C67_invert_test ^ inv, C67_compare_reg, C67_A0); // [!R] B.S2x A0 - C67_NOP(5); - t = ind1; //return where we need to patch - - } else if (v == VT_JMP || v == VT_JMPI) { - /* && or || optimization */ - if ((v & 1) == inv) { - /* insert vtop->c jump list in t */ - - // I guess the idea is to traverse to the - // null at the end of the list and store t - // there - - n = vtop->c.i; - while (n != 0) { - p = (int *) (cur_text_section->data + n); - - // extract 32 bit address from MVKH/MVKL - n = ((*p >> 7) & 0xffff); - n |= ((*(p + 1) >> 7) & 0xffff) << 16; - } - *p |= (t & 0xffff) << 7; - *(p + 1) |= ((t >> 16) & 0xffff) << 7; - t = vtop->c.i; - - } else { - t = gjmp(t); - gsym(vtop->c.i); - } - } - vtop--; - return t; -} - -/* generate an integer binary operation */ -void gen_opi(int op) -{ - int r, fr, opc, t; - - switch (op) { - case '+': - case TOK_ADDC1: /* add with carry generation */ - opc = 0; - gen_op8: - - -// C67 can't do const compares, must load into a reg -// so just go to gv2 directly - tktk - - - - if (op >= TOK_ULT && op <= TOK_GT) - gv2(RC_INT_BSIDE, RC_INT); // make sure r (src1) is on the B Side of CPU - else - gv2(RC_INT, RC_INT); - - r = vtop[-1].r; - fr = vtop[0].r; - - C67_compare_reg = C67_B2; - - - if (op == TOK_LT) { - C67_CMPLT(r, fr, C67_B2); - C67_invert_test = FALSE; - } else if (op == TOK_GE) { - C67_CMPLT(r, fr, C67_B2); - C67_invert_test = TRUE; - } else if (op == TOK_GT) { - C67_CMPGT(r, fr, C67_B2); - C67_invert_test = FALSE; - } else if (op == TOK_LE) { - C67_CMPGT(r, fr, C67_B2); - C67_invert_test = TRUE; - } else if (op == TOK_EQ) { - C67_CMPEQ(r, fr, C67_B2); - C67_invert_test = FALSE; - } else if (op == TOK_NE) { - C67_CMPEQ(r, fr, C67_B2); - C67_invert_test = TRUE; - } else if (op == TOK_ULT) { - C67_CMPLTU(r, fr, C67_B2); - C67_invert_test = FALSE; - } else if (op == TOK_UGE) { - C67_CMPLTU(r, fr, C67_B2); - C67_invert_test = TRUE; - } else if (op == TOK_UGT) { - C67_CMPGTU(r, fr, C67_B2); - C67_invert_test = FALSE; - } else if (op == TOK_ULE) { - C67_CMPGTU(r, fr, C67_B2); - C67_invert_test = TRUE; - } else if (op == '+') - C67_ADD(fr, r); // ADD r,fr,r - else if (op == '-') - C67_SUB(fr, r); // SUB r,fr,r - else if (op == '&') - C67_AND(fr, r); // AND r,fr,r - else if (op == '|') - C67_OR(fr, r); // OR r,fr,r - else if (op == '^') - C67_XOR(fr, r); // XOR r,fr,r - else - ALWAYS_ASSERT(FALSE); - - vtop--; - if (op >= TOK_ULT && op <= TOK_GT) { - vtop->r = VT_CMP; - vtop->c.i = op; - } - break; - case '-': - case TOK_SUBC1: /* sub with carry generation */ - opc = 5; - goto gen_op8; - case TOK_ADDC2: /* add with carry use */ - opc = 2; - goto gen_op8; - case TOK_SUBC2: /* sub with carry use */ - opc = 3; - goto gen_op8; - case '&': - opc = 4; - goto gen_op8; - case '^': - opc = 6; - goto gen_op8; - case '|': - opc = 1; - goto gen_op8; - case '*': - case TOK_UMULL: - gv2(RC_INT, RC_INT); - r = vtop[-1].r; - fr = vtop[0].r; - vtop--; - C67_MPYI(fr, r); // 32 bit multiply fr,r,fr - C67_NOP(8); // NOP 8 for worst case - break; - case TOK_SHL: - gv2(RC_INT_BSIDE, RC_INT_BSIDE); // shift amount must be on same side as dst - r = vtop[-1].r; - fr = vtop[0].r; - vtop--; - C67_SHL(fr, r); // arithmetic/logical shift - break; - - case TOK_SHR: - gv2(RC_INT_BSIDE, RC_INT_BSIDE); // shift amount must be on same side as dst - r = vtop[-1].r; - fr = vtop[0].r; - vtop--; - C67_SHRU(fr, r); // logical shift - break; - - case TOK_SAR: - gv2(RC_INT_BSIDE, RC_INT_BSIDE); // shift amount must be on same side as dst - r = vtop[-1].r; - fr = vtop[0].r; - vtop--; - C67_SHR(fr, r); // arithmetic shift - break; - - case '/': - t = TOK__divi; - call_func: - vswap(); - /* call generic idiv function */ - vpush_global_sym(&func_old_type, t); - vrott(3); - gfunc_call(2); - vpushi(0); - vtop->r = REG_IRET; - vtop->r2 = VT_CONST; - break; - case TOK_UDIV: - case TOK_PDIV: - t = TOK__divu; - goto call_func; - case '%': - t = TOK__remi; - goto call_func; - case TOK_UMOD: - t = TOK__remu; - goto call_func; - - default: - opc = 7; - goto gen_op8; - } -} - -/* generate a floating point operation 'v = t1 op t2' instruction. The - two operands are guaranteed to have the same floating point type */ -/* XXX: need to use ST1 too */ -void gen_opf(int op) -{ - int ft, fc, fr, r; - - if (op >= TOK_ULT && op <= TOK_GT) - gv2(RC_EDX, RC_EAX); // make sure src2 is on b side - else - gv2(RC_FLOAT, RC_FLOAT); // make sure src2 is on b side - - ft = vtop->type.t; - fc = vtop->c.i; - r = vtop->r; - fr = vtop[-1].r; - - - if ((ft & VT_BTYPE) == VT_LDOUBLE) - tcc_error("long doubles not supported"); - - if (op >= TOK_ULT && op <= TOK_GT) { - - r = vtop[-1].r; - fr = vtop[0].r; - - C67_compare_reg = C67_B2; - - if (op == TOK_LT) { - if ((ft & VT_BTYPE) == VT_DOUBLE) - C67_CMPLTDP(r, fr, C67_B2); - else - C67_CMPLTSP(r, fr, C67_B2); - - C67_invert_test = FALSE; - } else if (op == TOK_GE) { - if ((ft & VT_BTYPE) == VT_DOUBLE) - C67_CMPLTDP(r, fr, C67_B2); - else - C67_CMPLTSP(r, fr, C67_B2); - - C67_invert_test = TRUE; - } else if (op == TOK_GT) { - if ((ft & VT_BTYPE) == VT_DOUBLE) - C67_CMPGTDP(r, fr, C67_B2); - else - C67_CMPGTSP(r, fr, C67_B2); - - C67_invert_test = FALSE; - } else if (op == TOK_LE) { - if ((ft & VT_BTYPE) == VT_DOUBLE) - C67_CMPGTDP(r, fr, C67_B2); - else - C67_CMPGTSP(r, fr, C67_B2); - - C67_invert_test = TRUE; - } else if (op == TOK_EQ) { - if ((ft & VT_BTYPE) == VT_DOUBLE) - C67_CMPEQDP(r, fr, C67_B2); - else - C67_CMPEQSP(r, fr, C67_B2); - - C67_invert_test = FALSE; - } else if (op == TOK_NE) { - if ((ft & VT_BTYPE) == VT_DOUBLE) - C67_CMPEQDP(r, fr, C67_B2); - else - C67_CMPEQSP(r, fr, C67_B2); - - C67_invert_test = TRUE; - } else { - ALWAYS_ASSERT(FALSE); - } - vtop->r = VT_CMP; // tell TCC that result is in "flags" actually B2 - } else { - if (op == '+') { - if ((ft & VT_BTYPE) == VT_DOUBLE) { - C67_ADDDP(r, fr); // ADD fr,r,fr - C67_NOP(6); - } else { - C67_ADDSP(r, fr); // ADD fr,r,fr - C67_NOP(3); - } - vtop--; - } else if (op == '-') { - if ((ft & VT_BTYPE) == VT_DOUBLE) { - C67_SUBDP(r, fr); // SUB fr,r,fr - C67_NOP(6); - } else { - C67_SUBSP(r, fr); // SUB fr,r,fr - C67_NOP(3); - } - vtop--; - } else if (op == '*') { - if ((ft & VT_BTYPE) == VT_DOUBLE) { - C67_MPYDP(r, fr); // MPY fr,r,fr - C67_NOP(9); - } else { - C67_MPYSP(r, fr); // MPY fr,r,fr - C67_NOP(3); - } - vtop--; - } else if (op == '/') { - if ((ft & VT_BTYPE) == VT_DOUBLE) { - // must call intrinsic DP floating point divide - vswap(); - /* call generic idiv function */ - vpush_global_sym(&func_old_type, TOK__divd); - vrott(3); - gfunc_call(2); - vpushi(0); - vtop->r = REG_FRET; - vtop->r2 = REG_LRET; - - } else { - // must call intrinsic SP floating point divide - vswap(); - /* call generic idiv function */ - vpush_global_sym(&func_old_type, TOK__divf); - vrott(3); - gfunc_call(2); - vpushi(0); - vtop->r = REG_FRET; - vtop->r2 = VT_CONST; - } - } else - ALWAYS_ASSERT(FALSE); - - - } -} - - -/* convert integers to fp 't' type. Must handle 'int', 'unsigned int' - and 'long long' cases. */ -void gen_cvt_itof(int t) -{ - int r; - - gv(RC_INT); - r = vtop->r; - - if ((t & VT_BTYPE) == VT_DOUBLE) { - if (t & VT_UNSIGNED) - C67_INTDPU(r, r); - else - C67_INTDP(r, r); - - C67_NOP(4); - vtop->type.t = VT_DOUBLE; - } else { - if (t & VT_UNSIGNED) - C67_INTSPU(r, r); - else - C67_INTSP(r, r); - C67_NOP(3); - vtop->type.t = VT_FLOAT; - } - -} - -/* convert fp to int 't' type */ -/* XXX: handle long long case */ -void gen_cvt_ftoi(int t) -{ - int r; - - gv(RC_FLOAT); - r = vtop->r; - - if (t != VT_INT) - tcc_error("long long not supported"); - else { - if ((vtop->type.t & VT_BTYPE) == VT_DOUBLE) { - C67_DPTRUNC(r, r); - C67_NOP(3); - } else { - C67_SPTRUNC(r, r); - C67_NOP(3); - } - - vtop->type.t = VT_INT; - - } -} - -/* convert from one floating point type to another */ -void gen_cvt_ftof(int t) -{ - int r, r2; - - if ((vtop->type.t & VT_BTYPE) == VT_DOUBLE && - (t & VT_BTYPE) == VT_FLOAT) { - // convert double to float - - gv(RC_FLOAT); // get it in a register pair - - r = vtop->r; - - C67_DPSP(r, r); // convert it to SP same register - C67_NOP(3); - - vtop->type.t = VT_FLOAT; - vtop->r2 = VT_CONST; // set this as unused - } else if ((vtop->type.t & VT_BTYPE) == VT_FLOAT && - (t & VT_BTYPE) == VT_DOUBLE) { - // convert float to double - - gv(RC_FLOAT); // get it in a register - - r = vtop->r; - - if (r == TREG_EAX) { // make sure the paired reg is avail - r2 = get_reg(RC_ECX); - } else if (r == TREG_EDX) { - r2 = get_reg(RC_ST0); - } else { - ALWAYS_ASSERT(FALSE); - r2 = 0; /* avoid warning */ - } - - C67_SPDP(r, r); // convert it to DP same register - C67_NOP(1); - - vtop->type.t = VT_DOUBLE; - vtop->r2 = r2; // set this as unused - } else { - ALWAYS_ASSERT(FALSE); - } -} - -/* computed goto support */ -void ggoto(void) -{ - gcall_or_jmp(1); - vtop--; -} - -/* Save the stack pointer onto the stack and return the location of its address */ -ST_FUNC void gen_vla_sp_save(int addr) { - tcc_error("variable length arrays unsupported for this target"); -} - -/* Restore the SP from a location on the stack */ -ST_FUNC void gen_vla_sp_restore(int addr) { - tcc_error("variable length arrays unsupported for this target"); -} - -/* Subtract from the stack pointer, and push the resulting value onto the stack */ -ST_FUNC void gen_vla_alloc(CType *type, int align) { - tcc_error("variable length arrays unsupported for this target"); -} - -/* end of C67 code generator */ -/*************************************************************/ -#endif -/*************************************************************/ diff --git a/05/tcc-final-old/c67-link.c b/05/tcc-final-old/c67-link.c deleted file mode 100644 index de72e44..0000000 --- a/05/tcc-final-old/c67-link.c +++ /dev/null @@ -1,131 +0,0 @@ -#ifdef TARGET_DEFS_ONLY - -#define EM_TCC_TARGET EM_C60 - -/* relocation type for 32 bit data relocation */ -#define R_DATA_32 R_C60_32 -#define R_DATA_PTR R_C60_32 -#define R_JMP_SLOT R_C60_JMP_SLOT -#define R_GLOB_DAT R_C60_GLOB_DAT -#define R_COPY R_C60_COPY -#define R_RELATIVE R_C60_RELATIVE - -#define R_NUM R_C60_NUM - -#define ELF_START_ADDR 0x00000400 -#define ELF_PAGE_SIZE 0x1000 - -#define PCRELATIVE_DLLPLT 0 -#define RELOCATE_DLLPLT 0 - -#else /* !TARGET_DEFS_ONLY */ - -#include "tcc.h" - -/* Returns 1 for a code relocation, 0 for a data relocation. For unknown - relocations, returns -1. */ -int code_reloc (int reloc_type) -{ - switch (reloc_type) { - case R_C60_32: - case R_C60LO16: - case R_C60HI16: - case R_C60_GOT32: - case R_C60_GOTOFF: - case R_C60_GOTPC: - case R_C60_COPY: - return 0; - - case R_C60_PLT32: - return 1; - } - - tcc_error ("Unknown relocation type: %d", reloc_type); - return -1; -} - -/* Returns an enumerator to describe whether and when the relocation needs a - GOT and/or PLT entry to be created. See tcc.h for a description of the - different values. */ -int gotplt_entry_type (int reloc_type) -{ - switch (reloc_type) { - case R_C60_32: - case R_C60LO16: - case R_C60HI16: - case R_C60_COPY: - return NO_GOTPLT_ENTRY; - - case R_C60_GOTOFF: - case R_C60_GOTPC: - return BUILD_GOT_ONLY; - - case R_C60_PLT32: - case R_C60_GOT32: - return ALWAYS_GOTPLT_ENTRY; - } - - tcc_error ("Unknown relocation type: %d", reloc_type); - return -1; -} - -ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr) -{ - tcc_error("C67 got not implemented"); - return 0; -} - -/* relocate the PLT: compute addresses and offsets in the PLT now that final - address for PLT and GOT are known (see fill_program_header) */ -ST_FUNC void relocate_plt(TCCState *s1) -{ - uint8_t *p, *p_end; - - if (!s1->plt) - return; - - p = s1->plt->data; - p_end = p + s1->plt->data_offset; - - if (p < p_end) { - /* XXX: TODO */ - while (p < p_end) { - /* XXX: TODO */ - } - } -} - -void relocate_init(Section *sr) {} - -void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val) -{ - switch(type) { - case R_C60_32: - *(int *)ptr += val; - break; - case R_C60LO16: - { - uint32_t orig; - - /* put the low 16 bits of the absolute address add to what is - already there */ - orig = ((*(int *)(ptr )) >> 7) & 0xffff; - orig |= (((*(int *)(ptr+4)) >> 7) & 0xffff) << 16; - - /* patch both at once - assumes always in pairs Low - High */ - *(int *) ptr = (*(int *) ptr & (~(0xffff << 7)) ) | - (((val+orig) & 0xffff) << 7); - *(int *)(ptr+4) = (*(int *)(ptr+4) & (~(0xffff << 7)) ) | - ((((val+orig)>>16) & 0xffff) << 7); - } - break; - case R_C60HI16: - break; - default: - fprintf(stderr,"FIXME: handle reloc type %x at %x [%p] to %x\n", - type, (unsigned) addr, ptr, (unsigned) val); - break; - } -} - -#endif /* !TARGET_DEFS_ONLY */ diff --git a/05/tcc-final-old/coff.h b/05/tcc-final-old/coff.h deleted file mode 100644 index e8e6185..0000000 --- a/05/tcc-final-old/coff.h +++ /dev/null @@ -1,446 +0,0 @@ -/**************************************************************************/ -/* COFF.H */ -/* COFF data structures and related definitions used by the linker */ -/**************************************************************************/ - -/*------------------------------------------------------------------------*/ -/* COFF FILE HEADER */ -/*------------------------------------------------------------------------*/ -struct filehdr { - unsigned short f_magic; /* magic number */ - unsigned short f_nscns; /* number of sections */ - long f_timdat; /* time & date stamp */ - long f_symptr; /* file pointer to symtab */ - long f_nsyms; /* number of symtab entries */ - unsigned short f_opthdr; /* sizeof(optional hdr) */ - unsigned short f_flags; /* flags */ - unsigned short f_TargetID; /* for C6x = 0x0099 */ - }; - -/*------------------------------------------------------------------------*/ -/* File header flags */ -/*------------------------------------------------------------------------*/ -#define F_RELFLG 0x01 /* relocation info stripped from file */ -#define F_EXEC 0x02 /* file is executable (no unresolved refs) */ -#define F_LNNO 0x04 /* line numbers stripped from file */ -#define F_LSYMS 0x08 /* local symbols stripped from file */ -#define F_GSP10 0x10 /* 34010 version */ -#define F_GSP20 0x20 /* 34020 version */ -#define F_SWABD 0x40 /* bytes swabbed (in names) */ -#define F_AR16WR 0x80 /* byte ordering of an AR16WR (PDP-11) */ -#define F_LITTLE 0x100 /* byte ordering of an AR32WR (vax) */ -#define F_BIG 0x200 /* byte ordering of an AR32W (3B, maxi) */ -#define F_PATCH 0x400 /* contains "patch" list in optional header */ -#define F_NODF 0x400 - -#define F_VERSION (F_GSP10 | F_GSP20) -#define F_BYTE_ORDER (F_LITTLE | F_BIG) -#define FILHDR struct filehdr - -/* #define FILHSZ sizeof(FILHDR) */ -#define FILHSZ 22 /* above rounds to align on 4 bytes which causes problems */ - -#define COFF_C67_MAGIC 0x00c2 - -/*------------------------------------------------------------------------*/ -/* Macros to recognize magic numbers */ -/*------------------------------------------------------------------------*/ -#define ISMAGIC(x) (((unsigned short)(x))==(unsigned short)magic) -#define ISARCHIVE(x) ((((unsigned short)(x))==(unsigned short)ARTYPE)) -#define BADMAGIC(x) (((unsigned short)(x) & 0x8080) && !ISMAGIC(x)) - - -/*------------------------------------------------------------------------*/ -/* OPTIONAL FILE HEADER */ -/*------------------------------------------------------------------------*/ -typedef struct aouthdr { - short magic; /* see magic.h */ - short vstamp; /* version stamp */ - long tsize; /* text size in bytes, padded to FW bdry*/ - long dsize; /* initialized data " " */ - long bsize; /* uninitialized data " " */ - long entrypt; /* entry pt. */ - long text_start; /* base of text used for this file */ - long data_start; /* base of data used for this file */ -} AOUTHDR; - -#define AOUTSZ sizeof(AOUTHDR) - -/*----------------------------------------------------------------------*/ -/* When a UNIX aout header is to be built in the optional header, */ -/* the following magic numbers can appear in that header: */ -/* */ -/* AOUT1MAGIC : default : readonly sharable text segment */ -/* AOUT2MAGIC: : writable text segment */ -/* PAGEMAGIC : : configured for paging */ -/*----------------------------------------------------------------------*/ -#define AOUT1MAGIC 0410 -#define AOUT2MAGIC 0407 -#define PAGEMAGIC 0413 - - -/*------------------------------------------------------------------------*/ -/* COMMON ARCHIVE FILE STRUCTURES */ -/* */ -/* ARCHIVE File Organization: */ -/* _______________________________________________ */ -/* |__________ARCHIVE_MAGIC_STRING_______________| */ -/* |__________ARCHIVE_FILE_MEMBER_1______________| */ -/* | | */ -/* | Archive File Header "ar_hdr" | */ -/* |.............................................| */ -/* | Member Contents | */ -/* | 1. External symbol directory | */ -/* | 2. Text file | */ -/* |_____________________________________________| */ -/* |________ARCHIVE_FILE_MEMBER_2________________| */ -/* | "ar_hdr" | */ -/* |.............................................| */ -/* | Member Contents (.o or text file) | */ -/* |_____________________________________________| */ -/* | . . . | */ -/* | . . . | */ -/* | . . . | */ -/* |_____________________________________________| */ -/* |________ARCHIVE_FILE_MEMBER_n________________| */ -/* | "ar_hdr" | */ -/* |.............................................| */ -/* | Member Contents | */ -/* |_____________________________________________| */ -/* */ -/*------------------------------------------------------------------------*/ - -#define COFF_ARMAG "!\n" -#define SARMAG 8 -#define ARFMAG "`\n" - -struct ar_hdr /* archive file member header - printable ascii */ -{ - char ar_name[16]; /* file member name - `/' terminated */ - char ar_date[12]; /* file member date - decimal */ - char ar_uid[6]; /* file member user id - decimal */ - char ar_gid[6]; /* file member group id - decimal */ - char ar_mode[8]; /* file member mode - octal */ - char ar_size[10]; /* file member size - decimal */ - char ar_fmag[2]; /* ARFMAG - string to end header */ -}; - - -/*------------------------------------------------------------------------*/ -/* SECTION HEADER */ -/*------------------------------------------------------------------------*/ -struct scnhdr { - char s_name[8]; /* section name */ - long s_paddr; /* physical address */ - long s_vaddr; /* virtual address */ - long s_size; /* section size */ - long s_scnptr; /* file ptr to raw data for section */ - long s_relptr; /* file ptr to relocation */ - long s_lnnoptr; /* file ptr to line numbers */ - unsigned int s_nreloc; /* number of relocation entries */ - unsigned int s_nlnno; /* number of line number entries */ - unsigned int s_flags; /* flags */ - unsigned short s_reserved; /* reserved byte */ - unsigned short s_page; /* memory page id */ - }; - -#define SCNHDR struct scnhdr -#define SCNHSZ sizeof(SCNHDR) - -/*------------------------------------------------------------------------*/ -/* Define constants for names of "special" sections */ -/*------------------------------------------------------------------------*/ -/* #define _TEXT ".text" */ -#define _DATA ".data" -#define _BSS ".bss" -#define _CINIT ".cinit" -#define _TV ".tv" - -/*------------------------------------------------------------------------*/ -/* The low 4 bits of s_flags is used as a section "type" */ -/*------------------------------------------------------------------------*/ -#define STYP_REG 0x00 /* "regular" : allocated, relocated, loaded */ -#define STYP_DSECT 0x01 /* "dummy" : not allocated, relocated, not loaded */ -#define STYP_NOLOAD 0x02 /* "noload" : allocated, relocated, not loaded */ -#define STYP_GROUP 0x04 /* "grouped" : formed of input sections */ -#define STYP_PAD 0x08 /* "padding" : not allocated, not relocated, loaded */ -#define STYP_COPY 0x10 /* "copy" : used for C init tables - - not allocated, relocated, - loaded; reloc & lineno - entries processed normally */ -#define STYP_TEXT 0x20 /* section contains text only */ -#define STYP_DATA 0x40 /* section contains data only */ -#define STYP_BSS 0x80 /* section contains bss only */ - -#define STYP_ALIGN 0x100 /* align flag passed by old version assemblers */ -#define ALIGN_MASK 0x0F00 /* part of s_flags that is used for align vals */ -#define ALIGNSIZE(x) (1 << ((x & ALIGN_MASK) >> 8)) - - -/*------------------------------------------------------------------------*/ -/* RELOCATION ENTRIES */ -/*------------------------------------------------------------------------*/ -struct reloc -{ - long r_vaddr; /* (virtual) address of reference */ - short r_symndx; /* index into symbol table */ - unsigned short r_disp; /* additional bits for address calculation */ - unsigned short r_type; /* relocation type */ -}; - -#define RELOC struct reloc -#define RELSZ 10 /* sizeof(RELOC) */ - -/*--------------------------------------------------------------------------*/ -/* define all relocation types */ -/*--------------------------------------------------------------------------*/ - -#define R_ABS 0 /* absolute address - no relocation */ -#define R_DIR16 01 /* UNUSED */ -#define R_REL16 02 /* UNUSED */ -#define R_DIR24 04 /* UNUSED */ -#define R_REL24 05 /* 24 bits, direct */ -#define R_DIR32 06 /* UNUSED */ -#define R_RELBYTE 017 /* 8 bits, direct */ -#define R_RELWORD 020 /* 16 bits, direct */ -#define R_RELLONG 021 /* 32 bits, direct */ -#define R_PCRBYTE 022 /* 8 bits, PC-relative */ -#define R_PCRWORD 023 /* 16 bits, PC-relative */ -#define R_PCRLONG 024 /* 32 bits, PC-relative */ -#define R_OCRLONG 030 /* GSP: 32 bits, one's complement direct */ -#define R_GSPPCR16 031 /* GSP: 16 bits, PC relative (in words) */ -#define R_GSPOPR32 032 /* GSP: 32 bits, direct big-endian */ -#define R_PARTLS16 040 /* Brahma: 16 bit offset of 24 bit address*/ -#define R_PARTMS8 041 /* Brahma: 8 bit page of 24 bit address */ -#define R_PARTLS7 050 /* DSP: 7 bit offset of 16 bit address */ -#define R_PARTMS9 051 /* DSP: 9 bit page of 16 bit address */ -#define R_REL13 052 /* DSP: 13 bits, direct */ - - -/*------------------------------------------------------------------------*/ -/* LINE NUMBER ENTRIES */ -/*------------------------------------------------------------------------*/ -struct lineno -{ - union - { - long l_symndx ; /* sym. table index of function name - iff l_lnno == 0 */ - long l_paddr ; /* (physical) address of line number */ - } l_addr ; - unsigned short l_lnno ; /* line number */ -}; - -#define LINENO struct lineno -#define LINESZ 6 /* sizeof(LINENO) */ - - -/*------------------------------------------------------------------------*/ -/* STORAGE CLASSES */ -/*------------------------------------------------------------------------*/ -#define C_EFCN -1 /* physical end of function */ -#define C_NULL 0 -#define C_AUTO 1 /* automatic variable */ -#define C_EXT 2 /* external symbol */ -#define C_STAT 3 /* static */ -#define C_REG 4 /* register variable */ -#define C_EXTDEF 5 /* external definition */ -#define C_LABEL 6 /* label */ -#define C_ULABEL 7 /* undefined label */ -#define C_MOS 8 /* member of structure */ -#define C_ARG 9 /* function argument */ -#define C_STRTAG 10 /* structure tag */ -#define C_MOU 11 /* member of union */ -#define C_UNTAG 12 /* union tag */ -#define C_TPDEF 13 /* type definition */ -#define C_USTATIC 14 /* undefined static */ -#define C_ENTAG 15 /* enumeration tag */ -#define C_MOE 16 /* member of enumeration */ -#define C_REGPARM 17 /* register parameter */ -#define C_FIELD 18 /* bit field */ - -#define C_BLOCK 100 /* ".bb" or ".eb" */ -#define C_FCN 101 /* ".bf" or ".ef" */ -#define C_EOS 102 /* end of structure */ -#define C_FILE 103 /* file name */ -#define C_LINE 104 /* dummy sclass for line number entry */ -#define C_ALIAS 105 /* duplicate tag */ -#define C_HIDDEN 106 /* special storage class for external */ - /* symbols in dmert public libraries */ - -/*------------------------------------------------------------------------*/ -/* SYMBOL TABLE ENTRIES */ -/*------------------------------------------------------------------------*/ - -#define SYMNMLEN 8 /* Number of characters in a symbol name */ -#define FILNMLEN 14 /* Number of characters in a file name */ -#define DIMNUM 4 /* Number of array dimensions in auxiliary entry */ - - -struct syment -{ - union - { - char _n_name[SYMNMLEN]; /* old COFF version */ - struct - { - long _n_zeroes; /* new == 0 */ - long _n_offset; /* offset into string table */ - } _n_n; - char *_n_nptr[2]; /* allows for overlaying */ - } _n; - long n_value; /* value of symbol */ - short n_scnum; /* section number */ - unsigned short n_type; /* type and derived type */ - char n_sclass; /* storage class */ - char n_numaux; /* number of aux. entries */ -}; - -#define n_name _n._n_name -#define n_nptr _n._n_nptr[1] -#define n_zeroes _n._n_n._n_zeroes -#define n_offset _n._n_n._n_offset - -/*------------------------------------------------------------------------*/ -/* Relocatable symbols have a section number of the */ -/* section in which they are defined. Otherwise, section */ -/* numbers have the following meanings: */ -/*------------------------------------------------------------------------*/ -#define N_UNDEF 0 /* undefined symbol */ -#define N_ABS -1 /* value of symbol is absolute */ -#define N_DEBUG -2 /* special debugging symbol */ -#define N_TV (unsigned short)-3 /* needs transfer vector (preload) */ -#define P_TV (unsigned short)-4 /* needs transfer vector (postload) */ - - -/*------------------------------------------------------------------------*/ -/* The fundamental type of a symbol packed into the low */ -/* 4 bits of the word. */ -/*------------------------------------------------------------------------*/ -#define _EF ".ef" - -#define T_NULL 0 /* no type info */ -#define T_ARG 1 /* function argument (only used by compiler) */ -#define T_CHAR 2 /* character */ -#define T_SHORT 3 /* short integer */ -#define T_INT 4 /* integer */ -#define T_LONG 5 /* long integer */ -#define T_FLOAT 6 /* floating point */ -#define T_DOUBLE 7 /* double word */ -#define T_STRUCT 8 /* structure */ -#define T_UNION 9 /* union */ -#define T_ENUM 10 /* enumeration */ -#define T_MOE 11 /* member of enumeration */ -#define T_UCHAR 12 /* unsigned character */ -#define T_USHORT 13 /* unsigned short */ -#define T_UINT 14 /* unsigned integer */ -#define T_ULONG 15 /* unsigned long */ - -/*------------------------------------------------------------------------*/ -/* derived types are: */ -/*------------------------------------------------------------------------*/ -#define DT_NON 0 /* no derived type */ -#define DT_PTR 1 /* pointer */ -#define DT_FCN 2 /* function */ -#define DT_ARY 3 /* array */ - -#define MKTYPE(basic, d1,d2,d3,d4,d5,d6) \ - ((basic) | ((d1) << 4) | ((d2) << 6) | ((d3) << 8) |\ - ((d4) << 10) | ((d5) << 12) | ((d6) << 14)) - -/*------------------------------------------------------------------------*/ -/* type packing constants and macros */ -/*------------------------------------------------------------------------*/ -#define N_BTMASK_COFF 017 -#define N_TMASK_COFF 060 -#define N_TMASK1_COFF 0300 -#define N_TMASK2_COFF 0360 -#define N_BTSHFT_COFF 4 -#define N_TSHIFT_COFF 2 - -#define BTYPE_COFF(x) ((x) & N_BTMASK_COFF) -#define ISINT(x) (((x) >= T_CHAR && (x) <= T_LONG) || \ - ((x) >= T_UCHAR && (x) <= T_ULONG) || (x) == T_ENUM) -#define ISFLT_COFF(x) ((x) == T_DOUBLE || (x) == T_FLOAT) -#define ISPTR_COFF(x) (((x) & N_TMASK_COFF) == (DT_PTR << N_BTSHFT_COFF)) -#define ISFCN_COFF(x) (((x) & N_TMASK_COFF) == (DT_FCN << N_BTSHFT_COFF)) -#define ISARY_COFF(x) (((x) & N_TMASK_COFF) == (DT_ARY << N_BTSHFT_COFF)) -#define ISTAG_COFF(x) ((x)==C_STRTAG || (x)==C_UNTAG || (x)==C_ENTAG) - -#define INCREF_COFF(x) ((((x)&~N_BTMASK_COFF)<>N_TSHIFT_COFF)&~N_BTMASK_COFF)|((x)&N_BTMASK_COFF)) - - -/*------------------------------------------------------------------------*/ -/* AUXILIARY SYMBOL ENTRY */ -/*------------------------------------------------------------------------*/ -union auxent -{ - struct - { - long x_tagndx; /* str, un, or enum tag indx */ - union - { - struct - { - unsigned short x_lnno; /* declaration line number */ - unsigned short x_size; /* str, union, array size */ - } x_lnsz; - long x_fsize; /* size of function */ - } x_misc; - union - { - struct /* if ISFCN, tag, or .bb */ - { - long x_lnnoptr; /* ptr to fcn line # */ - long x_endndx; /* entry ndx past block end */ - } x_fcn; - struct /* if ISARY, up to 4 dimen. */ - { - unsigned short x_dimen[DIMNUM]; - } x_ary; - } x_fcnary; - unsigned short x_regcount; /* number of registers used by func */ - } x_sym; - struct - { - char x_fname[FILNMLEN]; - } x_file; - struct - { - long x_scnlen; /* section length */ - unsigned short x_nreloc; /* number of relocation entries */ - unsigned short x_nlinno; /* number of line numbers */ - } x_scn; -}; - -#define SYMENT struct syment -#define SYMESZ 18 /* sizeof(SYMENT) */ - -#define AUXENT union auxent -#define AUXESZ 18 /* sizeof(AUXENT) */ - -/*------------------------------------------------------------------------*/ -/* NAMES OF "SPECIAL" SYMBOLS */ -/*------------------------------------------------------------------------*/ -#define _STEXT ".text" -#define _ETEXT "etext" -#define _SDATA ".data" -#define _EDATA "edata" -#define _SBSS ".bss" -#define _END "end" -#define _CINITPTR "cinit" - -/*--------------------------------------------------------------------------*/ -/* ENTRY POINT SYMBOLS */ -/*--------------------------------------------------------------------------*/ -#define _START "_start" -#define _MAIN "_main" - /* _CSTART "_c_int00" (defined in params.h) */ - - -#define _TVORIG "_tvorig" -#define _TORIGIN "_torigin" -#define _DORIGIN "_dorigin" - -#define _SORIGIN "_sorigin" diff --git a/05/tcc-final-old/config.mak b/05/tcc-final-old/config.mak deleted file mode 100644 index 8d2d4fc..0000000 --- a/05/tcc-final-old/config.mak +++ /dev/null @@ -1,24 +0,0 @@ -# Automatically generated by configure - do not modify -prefix=/usr/local -bindir=$(DESTDIR)/usr/local/bin -tccdir=$(DESTDIR)/usr/local/lib/tcc -libdir=$(DESTDIR)/usr/local/lib -includedir=$(DESTDIR)/usr/local/include -mandir=$(DESTDIR)/usr/local/share/man -infodir=$(DESTDIR)/usr/local/share/info -docdir=$(DESTDIR)/usr/local/share/doc -CC=gcc -GCC_MAJOR=11 -GCC_MINOR=4 -AR=ar -STRIP=strip -s -R .comment -R .note -CFLAGS=-Wall -g -O2 -Wdeclaration-after-statement -fno-strict-aliasing -Wno-pointer-sign -Wno-sign-compare -Wno-unused-result -LDFLAGS= -LIBSUF=.a -EXESUF= -DLLSUF=.so -NATIVE_DEFINES+=-DCONFIG_TRIPLET="\"x86_64-linux-gnu\"" -ARCH=x86_64 -TARGETOS=Linux -VERSION = 0.9.27 -TOPSRC=$(TOP) diff --git a/05/tcc-final-old/configure b/05/tcc-final-old/configure deleted file mode 100755 index 1ee3acb..0000000 --- a/05/tcc-final-old/configure +++ /dev/null @@ -1,527 +0,0 @@ -#!/bin/sh -# -# tcc configure script (c) 2003 Fabrice Bellard - -# set temporary file name -# if test ! -z "$TMPDIR" ; then -# TMPDIR1="${TMPDIR}" -# elif test ! -z "$TEMPDIR" ; then -# TMPDIR1="${TEMPDIR}" -# else -# TMPDIR1="/tmp" -# fi -# -# bashism: TMPN="${TMPDIR1}/tcc-conf-${RANDOM}-$$-${RANDOM}.c" - -TMPN="./conftest-$$" -TMPH=$TMPN.h - -# default parameters -prefix="" -execprefix="" -bindir="" -libdir="" -tccdir="" -includedir="" -mandir="" -infodir="" -sysroot="" -cross_prefix="" -cc="gcc" -ar="ar" -strip="strip" -bigendian="no" -mingw32="no" -LIBSUF=".a" -EXESUF="" -DLLSUF=".so" -tcc_sysincludepaths="" -tcc_libpaths="" -tcc_crtprefix="" -tcc_elfinterp="" -triplet= -tcc_lddir= -confvars= -suggest="yes" -cpu= -cpuver= -gcc_major=0 -gcc_minor=0 - -# OS specific -targetos=`uname` -case $targetos in - Darwin) - confvars="$confvars OSX" - DLLSUF=".dylib" - ;; - MINGW*|MSYS*|CYGWIN*) - mingw32=yes - ;; - DragonFly|OpenBSD|FreeBSD|NetBSD) - confvars="$confvars ldl=no" - ;; - *) - ;; -esac - -# find source path -source_path=${0%configure} -source_path=${source_path%/} -source_path_used="yes" -if test -z "$source_path" -o "$source_path" = "." ; then - source_path=`pwd` - source_path_used="no" -fi - -for opt do - eval opt=\"$opt\" - case "$opt" in - --prefix=*) prefix=`echo $opt | cut -d '=' -f 2` - ;; - --exec-prefix=*) execprefix=`echo $opt | cut -d '=' -f 2` - ;; - --tccdir=*) tccdir=`echo $opt | cut -d '=' -f 2` - ;; - --bindir=*) bindir=`echo $opt | cut -d '=' -f 2` - ;; - --libdir=*) libdir=`echo $opt | cut -d '=' -f 2` - ;; - --includedir=*) includedir=`echo $opt | cut -d '=' -f 2` - ;; - --sharedir=*) sharedir=`echo $opt | cut -d '=' -f 2` - ;; - --mandir=*) mandir=`echo $opt | cut -d '=' -f 2` - ;; - --infodir=*) infodir=`echo $opt | cut -d '=' -f 2` - ;; - --docdir=*) docdir=`echo $opt | cut -d '=' -f 2` - ;; - --sysroot=*) sysroot=`echo $opt | cut -d '=' -f 2` - ;; - --source-path=*) source_path=`echo $opt | cut -d '=' -f 2` - ;; - --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2` - ;; - --cc=*) cc=`echo $opt | cut -d '=' -f 2` - ;; - --ar=*) ar=`echo $opt | cut -d '=' -f 2` - ;; - --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}" - ;; - --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}" - ;; - --extra-libs=*) extralibs="${opt#--extra-libs=}" - ;; - --sysincludepaths=*) tcc_sysincludepaths=`echo $opt | cut -d '=' -f 2` - ;; - --libpaths=*) tcc_libpaths=`echo $opt | cut -d '=' -f 2` - ;; - --crtprefix=*) tcc_crtprefix=`echo $opt | cut -d '=' -f 2` - ;; - --elfinterp=*) tcc_elfinterp=`echo $opt | cut -d '=' -f 2` - ;; - --triplet=*) triplet=`echo $opt | cut -d '=' -f 2` - ;; - --cpu=*) cpu=`echo $opt | cut -d '=' -f 2` - ;; - --enable-cross) confvars="$confvars cross" - ;; - --disable-static) confvars="$confvars static=no" - ;; - --enable-static) confvars="$confvars static" - ;; - --disable-rpath) confvars="$confvars rpath=no" - ;; - --strip-binaries) confvars="$confvars strip" - ;; - --with-libgcc) confvars="$confvars libgcc" - ;; - --with-selinux) confvars="$confvars selinux" - ;; - --config-mingw32*) mingw32=$(echo "$opt=yes" | cut -d '=' -f 2) - ;; - --config-*) confvars="$confvars ${opt#--config-}"; suggest="no" - ;; - --help|-h) show_help="yes" - ;; - *) echo "configure: WARNING: unrecognized option $opt" - ;; - esac -done - -if test -z "$cpu" ; then - if test -n "$ARCH" ; then - cpu="$ARCH" - else - cpu=`uname -m` - fi -fi - -case "$cpu" in - x86|i386|i486|i586|i686|i86pc|BePC|i686-AT386) - cpu="i386" - ;; - x86_64|amd64|x86-64) - cpu="x86_64" - ;; - arm*) - case "$cpu" in - arm|armv4l) - cpuver=4 - ;; - armv5tel|armv5tejl) - cpuver=5 - ;; - armv6j|armv6l) - cpuver=6 - ;; - armv7a|armv7l) - cpuver=7 - ;; - esac - cpu="arm" - ;; - aarch64) - cpu="aarch64" - ;; - alpha) - cpu="alpha" - ;; - "Power Macintosh"|ppc|ppc64) - cpu="ppc" - ;; - mips) - cpu="mips" - ;; - s390) - cpu="s390" - ;; - *) - echo "Unsupported CPU" - exit 1 - ;; -esac - -# Checking for CFLAGS -if test -z "$CFLAGS"; then - CFLAGS="-Wall -g -O2" -fi - -if test "$mingw32" = "yes" ; then - if test "$source_path_used" = "no"; then - source_path="." - fi - if test "$cc" = gcc; then - test -z "$LDFLAGS" && LDFLAGS="-static" - fi - test -z "$prefix" && prefix="C:/Program Files/tcc" - test -z "$tccdir" && tccdir="${prefix}" - test -z "$bindir" && bindir="${tccdir}" - test -z "$docdir" && docdir="${tccdir}/doc" - test -z "$libdir" && libdir="${tccdir}/libtcc" - confvars="$confvars WIN32" - LIBSUF=".lib" - EXESUF=".exe" - DLLSUF=".dll" -else - if test -z "$prefix" ; then - prefix="/usr/local" - fi - if test -z "$sharedir" ; then - sharedir="${prefix}/share" - fi - if test x"$execprefix" = x""; then - execprefix="${prefix}" - fi - if test x"$libdir" = x""; then - libdir="${execprefix}/lib" - fi - if test x"$bindir" = x""; then - bindir="${execprefix}/bin" - fi - if test x"$docdir" = x""; then - docdir="${sharedir}/doc" - fi - if test x"$mandir" = x""; then - mandir="${sharedir}/man" - fi - if test x"$infodir" = x""; then - infodir="${sharedir}/info" - fi - if test x"$tccdir" = x""; then - tccdir="${libdir}/tcc" - fi - if test x"$includedir" = x""; then - includedir="${prefix}/include" - fi -fi # mingw32 - -if test x"$show_help" = "xyes" ; then -cat << EOF -Usage: configure [options] -Options: [defaults in brackets after descriptions] - -Standard options: - --help print this message - --prefix=PREFIX install in PREFIX [$prefix] - --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX - [same as prefix] - --bindir=DIR user executables in DIR [EPREFIX/bin] - --libdir=DIR object code libraries in DIR [EPREFIX/lib] - --tccdir=DIR installation directory [EPREFIX/lib/tcc] - --includedir=DIR C header files in DIR [PREFIX/include] - --sharedir=DIR documentation root DIR [PREFIX/share] - --docdir=DIR documentation in DIR [SHAREDIR/doc/tcc] - --mandir=DIR man documentation in DIR [SHAREDIR/man] - --infodir=DIR info documentation in DIR [SHAREDIR/info] - -Advanced options (experts only): - --source-path=PATH path of source code [$source_path] - --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix] - --sysroot=PREFIX prepend PREFIX to library/include paths [] - --cc=CC use C compiler CC [$cc] - --ar=AR create archives using AR [$ar] - --extra-cflags= specify compiler flags [$CFLAGS] - --extra-ldflags= specify linker options [] - --cpu=CPU CPU [$cpu] - --strip-binaries strip symbol tables from resulting binaries - --disable-static make libtcc.so instead of libtcc.a - --enable-static make libtcc.a instead of libtcc.dll (win32) - --disable-rpath disable use of -rpath with the above - --with-libgcc use libgcc_s.so.1 instead of libtcc1.a - --enable-cross build cross compilers - --with-selinux use mmap for executable memory (with tcc -run) - --sysincludepaths=... specify system include paths, colon separated - --libpaths=... specify system library paths, colon separated - --crtprefix=... specify locations of crt?.o, colon separated - --elfinterp=... specify elf interpreter - --triplet=... specify system library/include directory triplet - --config-uClibc,-musl,-mingw32... enable system specific configurations -EOF -#echo "NOTE: The object files are build at the place where configure is launched" -exit 1 -fi - -cc="${cross_prefix}${cc}" -ar="${cross_prefix}${ar}" -strip="${cross_prefix}${strip}" - -if test -z "$cross_prefix" ; then - CONFTEST=./conftest$EXESUF - if ! $cc -o $CONFTEST $source_path/conftest.c 2>/dev/null ; then - echo "configure: error: '$cc' failed to compile conftest.c." - else - gcc_major="$($CONFTEST version)" - gcc_minor="$($CONFTEST minor)" - fi - bigendian="$($CONFTEST bigendian)" - if test "$mingw32" = "no" ; then - - if test -z "$triplet"; then - tt="$($CONFTEST triplet)" - if test -n "$tt" -a -f "/usr/lib/$tt/crti.o" ; then - triplet="$tt" - fi - fi - - if test -z "$triplet"; then - if test $cpu = "x86_64" -o $cpu = "aarch64" ; then - if test -f "/usr/lib64/crti.o" ; then - tcc_lddir="lib64" - fi - fi - fi - - if test "$cpu" = "arm" ; then - if test "${triplet%eabihf}" != "$triplet" ; then - confvars="$confvars arm_eabihf" - elif test "${triplet%eabi}" != "$triplet" ; then - confvars="$confvars arm_eabi" - fi - if grep -s -q "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo ; then - confvars="$confvars arm_vfp" - fi - fi - - if test "$suggest" = "yes"; then - if test -f "/lib/ld-uClibc.so.0" ; then - echo "Perhaps you want ./configure --config-uClibc" - fi - if test -f "/lib/ld-musl-$cpu.so.1"; then - echo "Perhaps you want ./configure --config-musl" - fi - fi - fi -else - # if cross compiling, cannot launch a program, so make a static guess - case $cpu in - ppc|mips|s390) bigendian=yes;; - esac -fi - -if test "$bigendian" = "yes" ; then - confvars="$confvars BIGENDIAN" -fi - -# a final configuration tuning -if ! echo "$cc" | grep -q "tcc"; then - OPT1="-Wdeclaration-after-statement -fno-strict-aliasing" - # we want -Wno- but gcc does not always reject unknown -Wno- options - OPT2="-Wpointer-sign -Wsign-compare -Wunused-result" - if echo "$cc" | grep -q "clang"; then - OPT1="$OPT1 -fheinous-gnu-extensions" - OPT2="$OPT2 -Wstring-plus-int" - fi - $cc $OPT1 $OPT2 -o a.out -c -xc - < /dev/null > cc_msg.txt 2>&1 - for o in $OPT1; do # enable these options - if ! grep -q -- $o cc_msg.txt; then CFLAGS="$CFLAGS $o"; fi - done - for o in $OPT2; do # disable these options - if ! grep -q -- $o cc_msg.txt; then CFLAGS="$CFLAGS -Wno-${o#-W*}"; fi - done - # cat cc_msg.txt - # echo $CFLAGS - rm -f cc_msg.txt a.out -fi - -fcho() { if test -n "$2"; then echo "$1$2"; fi } - -fcho "Binary directory " "$bindir" -fcho "TinyCC directory " "$tccdir" -fcho "Library directory " "$libdir" -fcho "Include directory " "$includedir" -fcho "Manual directory " "$mandir" -fcho "Info directory " "$infodir" -fcho "Doc directory " "$docdir" -fcho "Target root prefix " "$sysroot" -echo "Source path $source_path" -echo "C compiler $cc ($gcc_major.$gcc_minor)" -echo "Target OS $targetos" -echo "CPU $cpu" -fcho "Triplet " "$triplet" -fcho "Config " "${confvars# }" -echo "Creating config.mak and config.h" - -cat >config.mak <> $TMPH - echo "# define $1 \"$2\"" >> $TMPH - echo "#endif" >> $TMPH - fi -} - -print_mak() { - if test -n "$2"; then - echo "NATIVE_DEFINES+=-D$1=\"\\\"$2\\\"\"" >> config.mak - fi -} - -print_mak_int() { - if test -n "$2"; then - echo "NATIVE_DEFINES+=-D$1=$2" >> config.mak - fi -} - -echo "/* Automatically generated by configure - do not modify */" > $TMPH - -print_inc CONFIG_SYSROOT "$sysroot" -print_inc CONFIG_TCCDIR "$tccdir" -print_mak CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths" -print_mak CONFIG_TCC_LIBPATHS "$tcc_libpaths" -print_mak CONFIG_TCC_CRTPREFIX "$tcc_crtprefix" -print_mak CONFIG_TCC_ELFINTERP "$tcc_elfinterp" -print_mak CONFIG_LDDIR "$tcc_lddir" -print_mak CONFIG_TRIPLET "$triplet" -print_mak_int TCC_CPU_VERSION "$cpuver" - -if test "$cpu" = "aarch64" ; then - echo "ARCH=arm64" >> config.mak -else - echo "ARCH=$cpu" >> config.mak -fi -echo "TARGETOS=$targetos" >> config.mak - -for v in $confvars ; do - if test "${v%=*}" = "$v"; then - echo "CONFIG_$v=yes" >> config.mak - else - echo "CONFIG_$v" >> config.mak - fi -done - -version=`head $source_path/VERSION` -echo "VERSION = $version" >> config.mak -echo "#define TCC_VERSION \"$version\"" >> $TMPH -echo "@set VERSION $version" > config.texi - -if test "$source_path_used" = "yes" ; then - case $source_path in - /*) echo "TOPSRC=$source_path";; - *) echo "TOPSRC=\$(TOP)/$source_path";; - esac >>config.mak -else - echo 'TOPSRC=$(TOP)' >>config.mak -fi - -diff $TMPH config.h >/dev/null 2>&1 -if test $? -ne 0 ; then - mv -f $TMPH config.h -else - echo "config.h is unchanged" -fi - -rm -f $TMPN* $CONFTEST - -# --------------------------------------------------------------------------- -# build tree in object directory if source path is different from current one - -fn_makelink() -{ - tgt=$1/$2 - case $2 in - */*) dn=${2%/*} - test -d $dn || mkdir -p $dn - case $1 in - /*) ;; - *) while test $dn ; do - tgt=../$tgt; dn=${dn#${dn%%/*}}; dn=${dn#/} - done - ;; - esac - ;; - esac - - ln -sfn $tgt $2 || ( echo "ln failed. Using cp instead."; cp -f $1/$2 $2 ) -} - -if test "$source_path_used" = "yes" ; then - FILES="Makefile lib/Makefile tests/Makefile tests/tests2/Makefile tests/pp/Makefile" - for f in $FILES ; do - fn_makelink $source_path $f - done -fi - -# --------------------------------------------------------------------------- diff --git a/05/tcc-final-old/elf.h b/05/tcc-final-old/elf.h deleted file mode 100644 index 9fed6eb..0000000 --- a/05/tcc-final-old/elf.h +++ /dev/null @@ -1,3237 +0,0 @@ -/* This file defines standard ELF types, structures, and macros. - Copyright (C) 1995-2012 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#ifndef _ELF_H -#define _ELF_H 1 - -#ifndef _WIN32 -#include -#else -#ifndef __int8_t_defined -#define __int8_t_defined -typedef signed char int8_t; -typedef short int int16_t; -typedef int int32_t; -typedef long long int int64_t; -typedef unsigned char uint8_t; -typedef unsigned short int uint16_t; -typedef unsigned int uint32_t; -typedef unsigned long long int uint64_t; -#endif -#endif - -/* Standard ELF types. */ - -/* Type for a 16-bit quantity. */ -typedef uint16_t Elf32_Half; -typedef uint16_t Elf64_Half; - -/* Types for signed and unsigned 32-bit quantities. */ -typedef uint32_t Elf32_Word; -typedef int32_t Elf32_Sword; -typedef uint32_t Elf64_Word; -typedef int32_t Elf64_Sword; - -/* Types for signed and unsigned 64-bit quantities. */ -typedef uint64_t Elf32_Xword; -typedef int64_t Elf32_Sxword; -typedef uint64_t Elf64_Xword; -typedef int64_t Elf64_Sxword; - -/* Type of addresses. */ -typedef uint32_t Elf32_Addr; -typedef uint64_t Elf64_Addr; - -/* Type of file offsets. */ -typedef uint32_t Elf32_Off; -typedef uint64_t Elf64_Off; - -/* Type for section indices, which are 16-bit quantities. */ -typedef uint16_t Elf32_Section; -typedef uint16_t Elf64_Section; - -/* Type for version symbol information. */ -typedef Elf32_Half Elf32_Versym; -typedef Elf64_Half Elf64_Versym; - - -/* The ELF file header. This appears at the start of every ELF file. */ - -#define EI_NIDENT (16) - -typedef struct -{ - unsigned char e_ident[EI_NIDENT]; /* Magic number and other info */ - Elf32_Half e_type; /* Object file type */ - Elf32_Half e_machine; /* Architecture */ - Elf32_Word e_version; /* Object file version */ - Elf32_Addr e_entry; /* Entry point virtual address */ - Elf32_Off e_phoff; /* Program header table file offset */ - Elf32_Off e_shoff; /* Section header table file offset */ - Elf32_Word e_flags; /* Processor-specific flags */ - Elf32_Half e_ehsize; /* ELF header size in bytes */ - Elf32_Half e_phentsize; /* Program header table entry size */ - Elf32_Half e_phnum; /* Program header table entry count */ - Elf32_Half e_shentsize; /* Section header table entry size */ - Elf32_Half e_shnum; /* Section header table entry count */ - Elf32_Half e_shstrndx; /* Section header string table index */ -} Elf32_Ehdr; - -typedef struct -{ - unsigned char e_ident[EI_NIDENT]; /* Magic number and other info */ - Elf64_Half e_type; /* Object file type */ - Elf64_Half e_machine; /* Architecture */ - Elf64_Word e_version; /* Object file version */ - Elf64_Addr e_entry; /* Entry point virtual address */ - Elf64_Off e_phoff; /* Program header table file offset */ - Elf64_Off e_shoff; /* Section header table file offset */ - Elf64_Word e_flags; /* Processor-specific flags */ - Elf64_Half e_ehsize; /* ELF header size in bytes */ - Elf64_Half e_phentsize; /* Program header table entry size */ - Elf64_Half e_phnum; /* Program header table entry count */ - Elf64_Half e_shentsize; /* Section header table entry size */ - Elf64_Half e_shnum; /* Section header table entry count */ - Elf64_Half e_shstrndx; /* Section header string table index */ -} Elf64_Ehdr; - -/* Fields in the e_ident array. The EI_* macros are indices into the - array. The macros under each EI_* macro are the values the byte - may have. */ - -#define EI_MAG0 0 /* File identification byte 0 index */ -#define ELFMAG0 0x7f /* Magic number byte 0 */ - -#define EI_MAG1 1 /* File identification byte 1 index */ -#define ELFMAG1 'E' /* Magic number byte 1 */ - -#define EI_MAG2 2 /* File identification byte 2 index */ -#define ELFMAG2 'L' /* Magic number byte 2 */ - -#define EI_MAG3 3 /* File identification byte 3 index */ -#define ELFMAG3 'F' /* Magic number byte 3 */ - -/* Conglomeration of the identification bytes, for easy testing as a word. */ -#define ELFMAG "\177ELF" -#define SELFMAG 4 - -#define EI_CLASS 4 /* File class byte index */ -#define ELFCLASSNONE 0 /* Invalid class */ -#define ELFCLASS32 1 /* 32-bit objects */ -#define ELFCLASS64 2 /* 64-bit objects */ -#define ELFCLASSNUM 3 - -#define EI_DATA 5 /* Data encoding byte index */ -#define ELFDATANONE 0 /* Invalid data encoding */ -#define ELFDATA2LSB 1 /* 2's complement, little endian */ -#define ELFDATA2MSB 2 /* 2's complement, big endian */ -#define ELFDATANUM 3 - -#define EI_VERSION 6 /* File version byte index */ - /* Value must be EV_CURRENT */ - -#define EI_OSABI 7 /* OS ABI identification */ -#define ELFOSABI_NONE 0 /* UNIX System V ABI */ -#define ELFOSABI_SYSV 0 /* Alias. */ -#define ELFOSABI_HPUX 1 /* HP-UX */ -#define ELFOSABI_NETBSD 2 /* NetBSD. */ -#define ELFOSABI_GNU 3 /* Object uses GNU ELF extensions. */ -#define ELFOSABI_LINUX ELFOSABI_GNU /* Compatibility alias. */ -#define ELFOSABI_SOLARIS 6 /* Sun Solaris. */ -#define ELFOSABI_AIX 7 /* IBM AIX. */ -#define ELFOSABI_IRIX 8 /* SGI Irix. */ -#define ELFOSABI_FREEBSD 9 /* FreeBSD. */ -#define ELFOSABI_TRU64 10 /* Compaq TRU64 UNIX. */ -#define ELFOSABI_MODESTO 11 /* Novell Modesto. */ -#define ELFOSABI_OPENBSD 12 /* OpenBSD. */ -#define ELFOSABI_ARM_AEABI 64 /* ARM EABI */ -#define ELFOSABI_ARM 97 /* ARM */ -#define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */ - -#define EI_ABIVERSION 8 /* ABI version */ - -#define EI_PAD 9 /* Byte index of padding bytes */ - -/* Legal values for e_type (object file type). */ - -#define ET_NONE 0 /* No file type */ -#define ET_REL 1 /* Relocatable file */ -#define ET_EXEC 2 /* Executable file */ -#define ET_DYN 3 /* Shared object file */ -#define ET_CORE 4 /* Core file */ -#define ET_NUM 5 /* Number of defined types */ -#define ET_LOOS 0xfe00 /* OS-specific range start */ -#define ET_HIOS 0xfeff /* OS-specific range end */ -#define ET_LOPROC 0xff00 /* Processor-specific range start */ -#define ET_HIPROC 0xffff /* Processor-specific range end */ - -/* Legal values for e_machine (architecture). */ - -#define EM_NONE 0 /* No machine */ -#define EM_M32 1 /* AT&T WE 32100 */ -#define EM_SPARC 2 /* SUN SPARC */ -#define EM_386 3 /* Intel 80386 */ -#define EM_68K 4 /* Motorola m68k family */ -#define EM_88K 5 /* Motorola m88k family */ -#define EM_860 7 /* Intel 80860 */ -#define EM_MIPS 8 /* MIPS R3000 big-endian */ -#define EM_S370 9 /* IBM System/370 */ -#define EM_MIPS_RS3_LE 10 /* MIPS R3000 little-endian */ - -#define EM_PARISC 15 /* HPPA */ -#define EM_VPP500 17 /* Fujitsu VPP500 */ -#define EM_SPARC32PLUS 18 /* Sun's "v8plus" */ -#define EM_960 19 /* Intel 80960 */ -#define EM_PPC 20 /* PowerPC */ -#define EM_PPC64 21 /* PowerPC 64-bit */ -#define EM_S390 22 /* IBM S390 */ - -#define EM_V800 36 /* NEC V800 series */ -#define EM_FR20 37 /* Fujitsu FR20 */ -#define EM_RH32 38 /* TRW RH-32 */ -#define EM_RCE 39 /* Motorola RCE */ -#define EM_ARM 40 /* ARM */ -#define EM_FAKE_ALPHA 41 /* Digital Alpha */ -#define EM_SH 42 /* Hitachi SH */ -#define EM_SPARCV9 43 /* SPARC v9 64-bit */ -#define EM_TRICORE 44 /* Siemens Tricore */ -#define EM_ARC 45 /* Argonaut RISC Core */ -#define EM_H8_300 46 /* Hitachi H8/300 */ -#define EM_H8_300H 47 /* Hitachi H8/300H */ -#define EM_H8S 48 /* Hitachi H8S */ -#define EM_H8_500 49 /* Hitachi H8/500 */ -#define EM_IA_64 50 /* Intel Merced */ -#define EM_MIPS_X 51 /* Stanford MIPS-X */ -#define EM_COLDFIRE 52 /* Motorola Coldfire */ -#define EM_68HC12 53 /* Motorola M68HC12 */ -#define EM_MMA 54 /* Fujitsu MMA Multimedia Accelerator*/ -#define EM_PCP 55 /* Siemens PCP */ -#define EM_NCPU 56 /* Sony nCPU embedded RISC */ -#define EM_NDR1 57 /* Denso NDR1 microprocessor */ -#define EM_STARCORE 58 /* Motorola Start*Core processor */ -#define EM_ME16 59 /* Toyota ME16 processor */ -#define EM_ST100 60 /* STMicroelectronic ST100 processor */ -#define EM_TINYJ 61 /* Advanced Logic Corp. Tinyj emb.fam*/ -#define EM_X86_64 62 /* AMD x86-64 architecture */ -#define EM_PDSP 63 /* Sony DSP Processor */ - -#define EM_FX66 66 /* Siemens FX66 microcontroller */ -#define EM_ST9PLUS 67 /* STMicroelectronics ST9+ 8/16 mc */ -#define EM_ST7 68 /* STMicroelectronics ST7 8 bit mc */ -#define EM_68HC16 69 /* Motorola MC68HC16 microcontroller */ -#define EM_68HC11 70 /* Motorola MC68HC11 microcontroller */ -#define EM_68HC08 71 /* Motorola MC68HC08 microcontroller */ -#define EM_68HC05 72 /* Motorola MC68HC05 microcontroller */ -#define EM_SVX 73 /* Silicon Graphics SVx */ -#define EM_ST19 74 /* STMicroelectronics ST19 8 bit mc */ -#define EM_VAX 75 /* Digital VAX */ -#define EM_CRIS 76 /* Axis Communications 32-bit embedded processor */ -#define EM_JAVELIN 77 /* Infineon Technologies 32-bit embedded processor */ -#define EM_FIREPATH 78 /* Element 14 64-bit DSP Processor */ -#define EM_ZSP 79 /* LSI Logic 16-bit DSP Processor */ -#define EM_MMIX 80 /* Donald Knuth's educational 64-bit processor */ -#define EM_HUANY 81 /* Harvard University machine-independent object files */ -#define EM_PRISM 82 /* SiTera Prism */ -#define EM_AVR 83 /* Atmel AVR 8-bit microcontroller */ -#define EM_FR30 84 /* Fujitsu FR30 */ -#define EM_D10V 85 /* Mitsubishi D10V */ -#define EM_D30V 86 /* Mitsubishi D30V */ -#define EM_V850 87 /* NEC v850 */ -#define EM_M32R 88 /* Mitsubishi M32R */ -#define EM_MN10300 89 /* Matsushita MN10300 */ -#define EM_MN10200 90 /* Matsushita MN10200 */ -#define EM_PJ 91 /* picoJava */ -#define EM_OPENRISC 92 /* OpenRISC 32-bit embedded processor */ -#define EM_ARC_A5 93 /* ARC Cores Tangent-A5 */ -#define EM_XTENSA 94 /* Tensilica Xtensa Architecture */ -#define EM_AARCH64 183 /* ARM AARCH64 */ -#define EM_TILEPRO 188 /* Tilera TILEPro */ -#define EM_TILEGX 191 /* Tilera TILE-Gx */ -#define EM_NUM 192 - -/* If it is necessary to assign new unofficial EM_* values, please - pick large random numbers (0x8523, 0xa7f2, etc.) to minimize the - chances of collision with official or non-GNU unofficial values. */ - -#define EM_ALPHA 0x9026 -#define EM_C60 0x9c60 - -/* Legal values for e_version (version). */ - -#define EV_NONE 0 /* Invalid ELF version */ -#define EV_CURRENT 1 /* Current version */ -#define EV_NUM 2 - -/* Section header. */ - -typedef struct -{ - Elf32_Word sh_name; /* Section name (string tbl index) */ - Elf32_Word sh_type; /* Section type */ - Elf32_Word sh_flags; /* Section flags */ - Elf32_Addr sh_addr; /* Section virtual addr at execution */ - Elf32_Off sh_offset; /* Section file offset */ - Elf32_Word sh_size; /* Section size in bytes */ - Elf32_Word sh_link; /* Link to another section */ - Elf32_Word sh_info; /* Additional section information */ - Elf32_Word sh_addralign; /* Section alignment */ - Elf32_Word sh_entsize; /* Entry size if section holds table */ -} Elf32_Shdr; - -typedef struct -{ - Elf64_Word sh_name; /* Section name (string tbl index) */ - Elf64_Word sh_type; /* Section type */ - Elf64_Xword sh_flags; /* Section flags */ - Elf64_Addr sh_addr; /* Section virtual addr at execution */ - Elf64_Off sh_offset; /* Section file offset */ - Elf64_Xword sh_size; /* Section size in bytes */ - Elf64_Word sh_link; /* Link to another section */ - Elf64_Word sh_info; /* Additional section information */ - Elf64_Xword sh_addralign; /* Section alignment */ - Elf64_Xword sh_entsize; /* Entry size if section holds table */ -} Elf64_Shdr; - -/* Special section indices. */ - -#define SHN_UNDEF 0 /* Undefined section */ -#define SHN_LORESERVE 0xff00 /* Start of reserved indices */ -#define SHN_LOPROC 0xff00 /* Start of processor-specific */ -#define SHN_BEFORE 0xff00 /* Order section before all others - (Solaris). */ -#define SHN_AFTER 0xff01 /* Order section after all others - (Solaris). */ -#define SHN_HIPROC 0xff1f /* End of processor-specific */ -#define SHN_LOOS 0xff20 /* Start of OS-specific */ -#define SHN_HIOS 0xff3f /* End of OS-specific */ -#define SHN_ABS 0xfff1 /* Associated symbol is absolute */ -#define SHN_COMMON 0xfff2 /* Associated symbol is common */ -#define SHN_XINDEX 0xffff /* Index is in extra table. */ -#define SHN_HIRESERVE 0xffff /* End of reserved indices */ - -/* Legal values for sh_type (section type). */ - -#define SHT_NULL 0 /* Section header table entry unused */ -#define SHT_PROGBITS 1 /* Program data */ -#define SHT_SYMTAB 2 /* Symbol table */ -#define SHT_STRTAB 3 /* String table */ -#define SHT_RELA 4 /* Relocation entries with addends */ -#define SHT_HASH 5 /* Symbol hash table */ -#define SHT_DYNAMIC 6 /* Dynamic linking information */ -#define SHT_NOTE 7 /* Notes */ -#define SHT_NOBITS 8 /* Program space with no data (bss) */ -#define SHT_REL 9 /* Relocation entries, no addends */ -#define SHT_SHLIB 10 /* Reserved */ -#define SHT_DYNSYM 11 /* Dynamic linker symbol table */ -#define SHT_INIT_ARRAY 14 /* Array of constructors */ -#define SHT_FINI_ARRAY 15 /* Array of destructors */ -#define SHT_PREINIT_ARRAY 16 /* Array of pre-constructors */ -#define SHT_GROUP 17 /* Section group */ -#define SHT_SYMTAB_SHNDX 18 /* Extended section indices */ -#define SHT_NUM 19 /* Number of defined types. */ -#define SHT_LOOS 0x60000000 /* Start OS-specific. */ -#define SHT_GNU_ATTRIBUTES 0x6ffffff5 /* Object attributes. */ -#define SHT_GNU_HASH 0x6ffffff6 /* GNU-style hash table. */ -#define SHT_GNU_LIBLIST 0x6ffffff7 /* Prelink library list */ -#define SHT_CHECKSUM 0x6ffffff8 /* Checksum for DSO content. */ -#define SHT_LOSUNW 0x6ffffffa /* Sun-specific low bound. */ -#define SHT_SUNW_move 0x6ffffffa -#define SHT_SUNW_COMDAT 0x6ffffffb -#define SHT_SUNW_syminfo 0x6ffffffc -#define SHT_GNU_verdef 0x6ffffffd /* Version definition section. */ -#define SHT_GNU_verneed 0x6ffffffe /* Version needs section. */ -#define SHT_GNU_versym 0x6fffffff /* Version symbol table. */ -#define SHT_HISUNW 0x6fffffff /* Sun-specific high bound. */ -#define SHT_HIOS 0x6fffffff /* End OS-specific type */ -#define SHT_LOPROC 0x70000000 /* Start of processor-specific */ -#define SHT_HIPROC 0x7fffffff /* End of processor-specific */ -#define SHT_LOUSER 0x80000000 /* Start of application-specific */ -#define SHT_HIUSER 0x8fffffff /* End of application-specific */ - -/* Legal values for sh_flags (section flags). */ - -#define SHF_WRITE (1 << 0) /* Writable */ -#define SHF_ALLOC (1 << 1) /* Occupies memory during execution */ -#define SHF_EXECINSTR (1 << 2) /* Executable */ -#define SHF_MERGE (1 << 4) /* Might be merged */ -#define SHF_STRINGS (1 << 5) /* Contains nul-terminated strings */ -#define SHF_INFO_LINK (1 << 6) /* `sh_info' contains SHT index */ -#define SHF_LINK_ORDER (1 << 7) /* Preserve order after combining */ -#define SHF_OS_NONCONFORMING (1 << 8) /* Non-standard OS specific handling - required */ -#define SHF_GROUP (1 << 9) /* Section is member of a group. */ -#define SHF_TLS (1 << 10) /* Section hold thread-local data. */ -#define SHF_COMPRESSED (1 << 11) /* Section with compressed data. */ -#define SHF_MASKOS 0x0ff00000 /* OS-specific. */ -#define SHF_MASKPROC 0xf0000000 /* Processor-specific */ -#define SHF_ORDERED (1 << 30) /* Special ordering requirement - (Solaris). */ -#define SHF_EXCLUDE (1 << 31) /* Section is excluded unless - referenced or allocated (Solaris).*/ - -/* Section group handling. */ -#define GRP_COMDAT 0x1 /* Mark group as COMDAT. */ - -/* Symbol table entry. */ - -typedef struct -{ - Elf32_Word st_name; /* Symbol name (string tbl index) */ - Elf32_Addr st_value; /* Symbol value */ - Elf32_Word st_size; /* Symbol size */ - unsigned char st_info; /* Symbol type and binding */ - unsigned char st_other; /* Symbol visibility */ - Elf32_Section st_shndx; /* Section index */ -} Elf32_Sym; - -typedef struct -{ - Elf64_Word st_name; /* Symbol name (string tbl index) */ - unsigned char st_info; /* Symbol type and binding */ - unsigned char st_other; /* Symbol visibility */ - Elf64_Section st_shndx; /* Section index */ - Elf64_Addr st_value; /* Symbol value */ - Elf64_Xword st_size; /* Symbol size */ -} Elf64_Sym; - -/* The syminfo section if available contains additional information about - every dynamic symbol. */ - -typedef struct -{ - Elf32_Half si_boundto; /* Direct bindings, symbol bound to */ - Elf32_Half si_flags; /* Per symbol flags */ -} Elf32_Syminfo; - -typedef struct -{ - Elf64_Half si_boundto; /* Direct bindings, symbol bound to */ - Elf64_Half si_flags; /* Per symbol flags */ -} Elf64_Syminfo; - -/* Possible values for si_boundto. */ -#define SYMINFO_BT_SELF 0xffff /* Symbol bound to self */ -#define SYMINFO_BT_PARENT 0xfffe /* Symbol bound to parent */ -#define SYMINFO_BT_LOWRESERVE 0xff00 /* Beginning of reserved entries */ - -/* Possible bitmasks for si_flags. */ -#define SYMINFO_FLG_DIRECT 0x0001 /* Direct bound symbol */ -#define SYMINFO_FLG_PASSTHRU 0x0002 /* Pass-thru symbol for translator */ -#define SYMINFO_FLG_COPY 0x0004 /* Symbol is a copy-reloc */ -#define SYMINFO_FLG_LAZYLOAD 0x0008 /* Symbol bound to object to be lazy - loaded */ -/* Syminfo version values. */ -#define SYMINFO_NONE 0 -#define SYMINFO_CURRENT 1 -#define SYMINFO_NUM 2 - - -/* How to extract and insert information held in the st_info field. */ - -#define ELF32_ST_BIND(val) (((unsigned char) (val)) >> 4) -#define ELF32_ST_TYPE(val) ((val) & 0xf) -#define ELF32_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf)) - -/* Both Elf32_Sym and Elf64_Sym use the same one-byte st_info field. */ -#define ELF64_ST_BIND(val) ELF32_ST_BIND (val) -#define ELF64_ST_TYPE(val) ELF32_ST_TYPE (val) -#define ELF64_ST_INFO(bind, type) ELF32_ST_INFO ((bind), (type)) - -/* Legal values for ST_BIND subfield of st_info (symbol binding). */ - -#define STB_LOCAL 0 /* Local symbol */ -#define STB_GLOBAL 1 /* Global symbol */ -#define STB_WEAK 2 /* Weak symbol */ -#define STB_NUM 3 /* Number of defined types. */ -#define STB_LOOS 10 /* Start of OS-specific */ -#define STB_GNU_UNIQUE 10 /* Unique symbol. */ -#define STB_HIOS 12 /* End of OS-specific */ -#define STB_LOPROC 13 /* Start of processor-specific */ -#define STB_HIPROC 15 /* End of processor-specific */ - -/* Legal values for ST_TYPE subfield of st_info (symbol type). */ - -#define STT_NOTYPE 0 /* Symbol type is unspecified */ -#define STT_OBJECT 1 /* Symbol is a data object */ -#define STT_FUNC 2 /* Symbol is a code object */ -#define STT_SECTION 3 /* Symbol associated with a section */ -#define STT_FILE 4 /* Symbol's name is file name */ -#define STT_COMMON 5 /* Symbol is a common data object */ -#define STT_TLS 6 /* Symbol is thread-local data object*/ -#define STT_NUM 7 /* Number of defined types. */ -#define STT_LOOS 10 /* Start of OS-specific */ -#define STT_GNU_IFUNC 10 /* Symbol is indirect code object */ -#define STT_HIOS 12 /* End of OS-specific */ -#define STT_LOPROC 13 /* Start of processor-specific */ -#define STT_HIPROC 15 /* End of processor-specific */ - - -/* Symbol table indices are found in the hash buckets and chain table - of a symbol hash table section. This special index value indicates - the end of a chain, meaning no further symbols are found in that bucket. */ - -#define STN_UNDEF 0 /* End of a chain. */ - - -/* How to extract and insert information held in the st_other field. */ - -#define ELF32_ST_VISIBILITY(o) ((o) & 0x03) - -/* For ELF64 the definitions are the same. */ -#define ELF64_ST_VISIBILITY(o) ELF32_ST_VISIBILITY (o) - -/* Symbol visibility specification encoded in the st_other field. */ -#define STV_DEFAULT 0 /* Default symbol visibility rules */ -#define STV_INTERNAL 1 /* Processor specific hidden class */ -#define STV_HIDDEN 2 /* Sym unavailable in other modules */ -#define STV_PROTECTED 3 /* Not preemptible, not exported */ - - -/* Relocation table entry without addend (in section of type SHT_REL). */ - -typedef struct -{ - Elf32_Addr r_offset; /* Address */ - Elf32_Word r_info; /* Relocation type and symbol index */ -} Elf32_Rel; - -/* I have seen two different definitions of the Elf64_Rel and - Elf64_Rela structures, so we'll leave them out until Novell (or - whoever) gets their act together. */ -/* The following, at least, is used on Sparc v9, MIPS, and Alpha. */ - -typedef struct -{ - Elf64_Addr r_offset; /* Address */ - Elf64_Xword r_info; /* Relocation type and symbol index */ -} Elf64_Rel; - -/* Relocation table entry with addend (in section of type SHT_RELA). */ - -typedef struct -{ - Elf32_Addr r_offset; /* Address */ - Elf32_Word r_info; /* Relocation type and symbol index */ - Elf32_Sword r_addend; /* Addend */ -} Elf32_Rela; - -typedef struct -{ - Elf64_Addr r_offset; /* Address */ - Elf64_Xword r_info; /* Relocation type and symbol index */ - Elf64_Sxword r_addend; /* Addend */ -} Elf64_Rela; - -/* How to extract and insert information held in the r_info field. */ - -#define ELF32_R_SYM(val) ((val) >> 8) -#define ELF32_R_TYPE(val) ((val) & 0xff) -#define ELF32_R_INFO(sym, type) (((sym) << 8) + ((type) & 0xff)) - -#define ELF64_R_SYM(i) ((i) >> 32) -#define ELF64_R_TYPE(i) ((i) & 0xffffffff) -#define ELF64_R_INFO(sym,type) ((((Elf64_Xword) (sym)) << 32) + (type)) - -/* Program segment header. */ - -typedef struct -{ - Elf32_Word p_type; /* Segment type */ - Elf32_Off p_offset; /* Segment file offset */ - Elf32_Addr p_vaddr; /* Segment virtual address */ - Elf32_Addr p_paddr; /* Segment physical address */ - Elf32_Word p_filesz; /* Segment size in file */ - Elf32_Word p_memsz; /* Segment size in memory */ - Elf32_Word p_flags; /* Segment flags */ - Elf32_Word p_align; /* Segment alignment */ -} Elf32_Phdr; - -typedef struct -{ - Elf64_Word p_type; /* Segment type */ - Elf64_Word p_flags; /* Segment flags */ - Elf64_Off p_offset; /* Segment file offset */ - Elf64_Addr p_vaddr; /* Segment virtual address */ - Elf64_Addr p_paddr; /* Segment physical address */ - Elf64_Xword p_filesz; /* Segment size in file */ - Elf64_Xword p_memsz; /* Segment size in memory */ - Elf64_Xword p_align; /* Segment alignment */ -} Elf64_Phdr; - -/* Special value for e_phnum. This indicates that the real number of - program headers is too large to fit into e_phnum. Instead the real - value is in the field sh_info of section 0. */ - -#define PN_XNUM 0xffff - -/* Legal values for p_type (segment type). */ - -#define PT_NULL 0 /* Program header table entry unused */ -#define PT_LOAD 1 /* Loadable program segment */ -#define PT_DYNAMIC 2 /* Dynamic linking information */ -#define PT_INTERP 3 /* Program interpreter */ -#define PT_NOTE 4 /* Auxiliary information */ -#define PT_SHLIB 5 /* Reserved */ -#define PT_PHDR 6 /* Entry for header table itself */ -#define PT_TLS 7 /* Thread-local storage segment */ -#define PT_NUM 8 /* Number of defined types */ -#define PT_LOOS 0x60000000 /* Start of OS-specific */ -#define PT_GNU_EH_FRAME 0x6474e550 /* GCC .eh_frame_hdr segment */ -#define PT_GNU_STACK 0x6474e551 /* Indicates stack executability */ -#define PT_GNU_RELRO 0x6474e552 /* Read-only after relocation */ -#define PT_LOSUNW 0x6ffffffa -#define PT_SUNWBSS 0x6ffffffa /* Sun Specific segment */ -#define PT_SUNWSTACK 0x6ffffffb /* Stack segment */ -#define PT_HISUNW 0x6fffffff -#define PT_HIOS 0x6fffffff /* End of OS-specific */ -#define PT_LOPROC 0x70000000 /* Start of processor-specific */ -#define PT_HIPROC 0x7fffffff /* End of processor-specific */ - -/* Legal values for p_flags (segment flags). */ - -#define PF_X (1 << 0) /* Segment is executable */ -#define PF_W (1 << 1) /* Segment is writable */ -#define PF_R (1 << 2) /* Segment is readable */ -#define PF_MASKOS 0x0ff00000 /* OS-specific */ -#define PF_MASKPROC 0xf0000000 /* Processor-specific */ - -/* Legal values for note segment descriptor types for core files. */ - -#define NT_PRSTATUS 1 /* Contains copy of prstatus struct */ -#define NT_FPREGSET 2 /* Contains copy of fpregset struct */ -#define NT_PRPSINFO 3 /* Contains copy of prpsinfo struct */ -#define NT_PRXREG 4 /* Contains copy of prxregset struct */ -#define NT_TASKSTRUCT 4 /* Contains copy of task structure */ -#define NT_PLATFORM 5 /* String from sysinfo(SI_PLATFORM) */ -#define NT_AUXV 6 /* Contains copy of auxv array */ -#define NT_GWINDOWS 7 /* Contains copy of gwindows struct */ -#define NT_ASRS 8 /* Contains copy of asrset struct */ -#define NT_PSTATUS 10 /* Contains copy of pstatus struct */ -#define NT_PSINFO 13 /* Contains copy of psinfo struct */ -#define NT_PRCRED 14 /* Contains copy of prcred struct */ -#define NT_UTSNAME 15 /* Contains copy of utsname struct */ -#define NT_LWPSTATUS 16 /* Contains copy of lwpstatus struct */ -#define NT_LWPSINFO 17 /* Contains copy of lwpinfo struct */ -#define NT_PRFPXREG 20 /* Contains copy of fprxregset struct */ -#define NT_PRXFPREG 0x46e62b7f /* Contains copy of user_fxsr_struct */ -#define NT_PPC_VMX 0x100 /* PowerPC Altivec/VMX registers */ -#define NT_PPC_SPE 0x101 /* PowerPC SPE/EVR registers */ -#define NT_PPC_VSX 0x102 /* PowerPC VSX registers */ -#define NT_386_TLS 0x200 /* i386 TLS slots (struct user_desc) */ -#define NT_386_IOPERM 0x201 /* x86 io permission bitmap (1=deny) */ -#define NT_X86_XSTATE 0x202 /* x86 extended state using xsave */ -#define NT_S390_HIGH_GPRS 0x300 /* s390 upper register halves */ -#define NT_S390_TIMER 0x301 /* s390 timer register */ -#define NT_S390_TODCMP 0x302 /* s390 TOD clock comparator register */ -#define NT_S390_TODPREG 0x303 /* s390 TOD programmable register */ -#define NT_S390_CTRS 0x304 /* s390 control registers */ -#define NT_S390_PREFIX 0x305 /* s390 prefix register */ -#define NT_S390_LAST_BREAK 0x306 /* s390 breaking event address */ -#define NT_S390_SYSTEM_CALL 0x307 /* s390 system call restart data */ -#define NT_ARM_VFP 0x400 /* ARM VFP/NEON registers */ -#define NT_ARM_TLS 0x401 /* ARM TLS register */ -#define NT_ARM_HW_BREAK 0x402 /* ARM hardware breakpoint registers */ -#define NT_ARM_HW_WATCH 0x403 /* ARM hardware watchpoint registers */ - -/* Legal values for the note segment descriptor types for object files. */ - -#define NT_VERSION 1 /* Contains a version string. */ - - -/* Dynamic section entry. */ - -typedef struct -{ - Elf32_Sword d_tag; /* Dynamic entry type */ - union - { - Elf32_Word d_val; /* Integer value */ - Elf32_Addr d_ptr; /* Address value */ - } d_un; -} Elf32_Dyn; - -typedef struct -{ - Elf64_Sxword d_tag; /* Dynamic entry type */ - union - { - Elf64_Xword d_val; /* Integer value */ - Elf64_Addr d_ptr; /* Address value */ - } d_un; -} Elf64_Dyn; - -/* Legal values for d_tag (dynamic entry type). */ - -#define DT_NULL 0 /* Marks end of dynamic section */ -#define DT_NEEDED 1 /* Name of needed library */ -#define DT_PLTRELSZ 2 /* Size in bytes of PLT relocs */ -#define DT_PLTGOT 3 /* Processor defined value */ -#define DT_HASH 4 /* Address of symbol hash table */ -#define DT_STRTAB 5 /* Address of string table */ -#define DT_SYMTAB 6 /* Address of symbol table */ -#define DT_RELA 7 /* Address of Rela relocs */ -#define DT_RELASZ 8 /* Total size of Rela relocs */ -#define DT_RELAENT 9 /* Size of one Rela reloc */ -#define DT_STRSZ 10 /* Size of string table */ -#define DT_SYMENT 11 /* Size of one symbol table entry */ -#define DT_INIT 12 /* Address of init function */ -#define DT_FINI 13 /* Address of termination function */ -#define DT_SONAME 14 /* Name of shared object */ -#define DT_RPATH 15 /* Library search path (deprecated) */ -#define DT_SYMBOLIC 16 /* Start symbol search here */ -#define DT_REL 17 /* Address of Rel relocs */ -#define DT_RELSZ 18 /* Total size of Rel relocs */ -#define DT_RELENT 19 /* Size of one Rel reloc */ -#define DT_PLTREL 20 /* Type of reloc in PLT */ -#define DT_DEBUG 21 /* For debugging; unspecified */ -#define DT_TEXTREL 22 /* Reloc might modify .text */ -#define DT_JMPREL 23 /* Address of PLT relocs */ -#define DT_BIND_NOW 24 /* Process relocations of object */ -#define DT_INIT_ARRAY 25 /* Array with addresses of init fct */ -#define DT_FINI_ARRAY 26 /* Array with addresses of fini fct */ -#define DT_INIT_ARRAYSZ 27 /* Size in bytes of DT_INIT_ARRAY */ -#define DT_FINI_ARRAYSZ 28 /* Size in bytes of DT_FINI_ARRAY */ -#define DT_RUNPATH 29 /* Library search path */ -#define DT_FLAGS 30 /* Flags for the object being loaded */ -#define DT_ENCODING 32 /* Start of encoded range */ -#define DT_PREINIT_ARRAY 32 /* Array with addresses of preinit fct*/ -#define DT_PREINIT_ARRAYSZ 33 /* size in bytes of DT_PREINIT_ARRAY */ -#define DT_NUM 34 /* Number used */ -#define DT_LOOS 0x6000000d /* Start of OS-specific */ -#define DT_HIOS 0x6ffff000 /* End of OS-specific */ -#define DT_LOPROC 0x70000000 /* Start of processor-specific */ -#define DT_HIPROC 0x7fffffff /* End of processor-specific */ -#define DT_PROCNUM DT_MIPS_NUM /* Most used by any processor */ - -/* DT_* entries which fall between DT_VALRNGHI & DT_VALRNGLO use the - Dyn.d_un.d_val field of the Elf*_Dyn structure. This follows Sun's - approach. */ -#define DT_VALRNGLO 0x6ffffd00 -#define DT_GNU_PRELINKED 0x6ffffdf5 /* Prelinking timestamp */ -#define DT_GNU_CONFLICTSZ 0x6ffffdf6 /* Size of conflict section */ -#define DT_GNU_LIBLISTSZ 0x6ffffdf7 /* Size of library list */ -#define DT_CHECKSUM 0x6ffffdf8 -#define DT_PLTPADSZ 0x6ffffdf9 -#define DT_MOVEENT 0x6ffffdfa -#define DT_MOVESZ 0x6ffffdfb -#define DT_FEATURE_1 0x6ffffdfc /* Feature selection (DTF_*). */ -#define DT_POSFLAG_1 0x6ffffdfd /* Flags for DT_* entries, effecting - the following DT_* entry. */ -#define DT_SYMINSZ 0x6ffffdfe /* Size of syminfo table (in bytes) */ -#define DT_SYMINENT 0x6ffffdff /* Entry size of syminfo */ -#define DT_VALRNGHI 0x6ffffdff -#define DT_VALTAGIDX(tag) (DT_VALRNGHI - (tag)) /* Reverse order! */ -#define DT_VALNUM 12 - -/* DT_* entries which fall between DT_ADDRRNGHI & DT_ADDRRNGLO use the - Dyn.d_un.d_ptr field of the Elf*_Dyn structure. - - If any adjustment is made to the ELF object after it has been - built these entries will need to be adjusted. */ -#define DT_ADDRRNGLO 0x6ffffe00 -#define DT_GNU_HASH 0x6ffffef5 /* GNU-style hash table. */ -#define DT_TLSDESC_PLT 0x6ffffef6 -#define DT_TLSDESC_GOT 0x6ffffef7 -#define DT_GNU_CONFLICT 0x6ffffef8 /* Start of conflict section */ -#define DT_GNU_LIBLIST 0x6ffffef9 /* Library list */ -#define DT_CONFIG 0x6ffffefa /* Configuration information. */ -#define DT_DEPAUDIT 0x6ffffefb /* Dependency auditing. */ -#define DT_AUDIT 0x6ffffefc /* Object auditing. */ -#define DT_PLTPAD 0x6ffffefd /* PLT padding. */ -#define DT_MOVETAB 0x6ffffefe /* Move table. */ -#define DT_SYMINFO 0x6ffffeff /* Syminfo table. */ -#define DT_ADDRRNGHI 0x6ffffeff -#define DT_ADDRTAGIDX(tag) (DT_ADDRRNGHI - (tag)) /* Reverse order! */ -#define DT_ADDRNUM 11 - -/* The versioning entry types. The next are defined as part of the - GNU extension. */ -#define DT_VERSYM 0x6ffffff0 - -#define DT_RELACOUNT 0x6ffffff9 -#define DT_RELCOUNT 0x6ffffffa - -/* These were chosen by Sun. */ -#define DT_FLAGS_1 0x6ffffffb /* State flags, see DF_1_* below. */ -#define DT_VERDEF 0x6ffffffc /* Address of version definition - table */ -#define DT_VERDEFNUM 0x6ffffffd /* Number of version definitions */ -#define DT_VERNEED 0x6ffffffe /* Address of table with needed - versions */ -#define DT_VERNEEDNUM 0x6fffffff /* Number of needed versions */ -#define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */ -#define DT_VERSIONTAGNUM 16 - -/* Sun added these machine-independent extensions in the "processor-specific" - range. Be compatible. */ -#define DT_AUXILIARY 0x7ffffffd /* Shared object to load before self */ -#define DT_FILTER 0x7fffffff /* Shared object to get values from */ -#define DT_EXTRATAGIDX(tag) ((Elf32_Word)-((Elf32_Sword) (tag) <<1>>1)-1) -#define DT_EXTRANUM 3 - -/* Values of `d_un.d_val' in the DT_FLAGS entry. */ -#define DF_ORIGIN 0x00000001 /* Object may use DF_ORIGIN */ -#define DF_SYMBOLIC 0x00000002 /* Symbol resolutions starts here */ -#define DF_TEXTREL 0x00000004 /* Object contains text relocations */ -#define DF_BIND_NOW 0x00000008 /* No lazy binding for this object */ -#define DF_STATIC_TLS 0x00000010 /* Module uses the static TLS model */ - -/* State flags selectable in the `d_un.d_val' element of the DT_FLAGS_1 - entry in the dynamic section. */ -#define DF_1_NOW 0x00000001 /* Set RTLD_NOW for this object. */ -#define DF_1_GLOBAL 0x00000002 /* Set RTLD_GLOBAL for this object. */ -#define DF_1_GROUP 0x00000004 /* Set RTLD_GROUP for this object. */ -#define DF_1_NODELETE 0x00000008 /* Set RTLD_NODELETE for this object.*/ -#define DF_1_LOADFLTR 0x00000010 /* Trigger filtee loading at runtime.*/ -#define DF_1_INITFIRST 0x00000020 /* Set RTLD_INITFIRST for this object*/ -#define DF_1_NOOPEN 0x00000040 /* Set RTLD_NOOPEN for this object. */ -#define DF_1_ORIGIN 0x00000080 /* $ORIGIN must be handled. */ -#define DF_1_DIRECT 0x00000100 /* Direct binding enabled. */ -#define DF_1_TRANS 0x00000200 -#define DF_1_INTERPOSE 0x00000400 /* Object is used to interpose. */ -#define DF_1_NODEFLIB 0x00000800 /* Ignore default lib search path. */ -#define DF_1_NODUMP 0x00001000 /* Object can't be dldump'ed. */ -#define DF_1_CONFALT 0x00002000 /* Configuration alternative created.*/ -#define DF_1_ENDFILTEE 0x00004000 /* Filtee terminates filters search. */ -#define DF_1_DISPRELDNE 0x00008000 /* Disp reloc applied at build time. */ -#define DF_1_DISPRELPND 0x00010000 /* Disp reloc applied at run-time. */ -#define DF_1_NODIRECT 0x00020000 /* Object has no-direct binding. */ -#define DF_1_IGNMULDEF 0x00040000 -#define DF_1_NOKSYMS 0x00080000 -#define DF_1_NOHDR 0x00100000 -#define DF_1_EDITED 0x00200000 /* Object is modified after built. */ -#define DF_1_NORELOC 0x00400000 -#define DF_1_SYMINTPOSE 0x00800000 /* Object has individual interposers. */ -#define DF_1_GLOBAUDIT 0x01000000 /* Global auditing required. */ -#define DF_1_SINGLETON 0x02000000 /* Singleton symbols are used. */ - -/* Flags for the feature selection in DT_FEATURE_1. */ -#define DTF_1_PARINIT 0x00000001 -#define DTF_1_CONFEXP 0x00000002 - -/* Flags in the DT_POSFLAG_1 entry effecting only the next DT_* entry. */ -#define DF_P1_LAZYLOAD 0x00000001 /* Lazyload following object. */ -#define DF_P1_GROUPPERM 0x00000002 /* Symbols from next object are not - generally available. */ - -/* Version definition sections. */ - -typedef struct -{ - Elf32_Half vd_version; /* Version revision */ - Elf32_Half vd_flags; /* Version information */ - Elf32_Half vd_ndx; /* Version Index */ - Elf32_Half vd_cnt; /* Number of associated aux entries */ - Elf32_Word vd_hash; /* Version name hash value */ - Elf32_Word vd_aux; /* Offset in bytes to verdaux array */ - Elf32_Word vd_next; /* Offset in bytes to next verdef - entry */ -} Elf32_Verdef; - -typedef struct -{ - Elf64_Half vd_version; /* Version revision */ - Elf64_Half vd_flags; /* Version information */ - Elf64_Half vd_ndx; /* Version Index */ - Elf64_Half vd_cnt; /* Number of associated aux entries */ - Elf64_Word vd_hash; /* Version name hash value */ - Elf64_Word vd_aux; /* Offset in bytes to verdaux array */ - Elf64_Word vd_next; /* Offset in bytes to next verdef - entry */ -} Elf64_Verdef; - - -/* Legal values for vd_version (version revision). */ -#define VER_DEF_NONE 0 /* No version */ -#define VER_DEF_CURRENT 1 /* Current version */ -#define VER_DEF_NUM 2 /* Given version number */ - -/* Legal values for vd_flags (version information flags). */ -#define VER_FLG_BASE 0x1 /* Version definition of file itself */ -#define VER_FLG_WEAK 0x2 /* Weak version identifier */ - -/* Versym symbol index values. */ -#define VER_NDX_LOCAL 0 /* Symbol is local. */ -#define VER_NDX_GLOBAL 1 /* Symbol is global. */ -#define VER_NDX_LORESERVE 0xff00 /* Beginning of reserved entries. */ -#define VER_NDX_ELIMINATE 0xff01 /* Symbol is to be eliminated. */ - -/* Auxiliary version information. */ - -typedef struct -{ - Elf32_Word vda_name; /* Version or dependency names */ - Elf32_Word vda_next; /* Offset in bytes to next verdaux - entry */ -} Elf32_Verdaux; - -typedef struct -{ - Elf64_Word vda_name; /* Version or dependency names */ - Elf64_Word vda_next; /* Offset in bytes to next verdaux - entry */ -} Elf64_Verdaux; - - -/* Version dependency section. */ - -typedef struct -{ - Elf32_Half vn_version; /* Version of structure */ - Elf32_Half vn_cnt; /* Number of associated aux entries */ - Elf32_Word vn_file; /* Offset of filename for this - dependency */ - Elf32_Word vn_aux; /* Offset in bytes to vernaux array */ - Elf32_Word vn_next; /* Offset in bytes to next verneed - entry */ -} Elf32_Verneed; - -typedef struct -{ - Elf64_Half vn_version; /* Version of structure */ - Elf64_Half vn_cnt; /* Number of associated aux entries */ - Elf64_Word vn_file; /* Offset of filename for this - dependency */ - Elf64_Word vn_aux; /* Offset in bytes to vernaux array */ - Elf64_Word vn_next; /* Offset in bytes to next verneed - entry */ -} Elf64_Verneed; - - -/* Legal values for vn_version (version revision). */ -#define VER_NEED_NONE 0 /* No version */ -#define VER_NEED_CURRENT 1 /* Current version */ -#define VER_NEED_NUM 2 /* Given version number */ - -/* Auxiliary needed version information. */ - -typedef struct -{ - Elf32_Word vna_hash; /* Hash value of dependency name */ - Elf32_Half vna_flags; /* Dependency specific information */ - Elf32_Half vna_other; /* Unused */ - Elf32_Word vna_name; /* Dependency name string offset */ - Elf32_Word vna_next; /* Offset in bytes to next vernaux - entry */ -} Elf32_Vernaux; - -typedef struct -{ - Elf64_Word vna_hash; /* Hash value of dependency name */ - Elf64_Half vna_flags; /* Dependency specific information */ - Elf64_Half vna_other; /* Unused */ - Elf64_Word vna_name; /* Dependency name string offset */ - Elf64_Word vna_next; /* Offset in bytes to next vernaux - entry */ -} Elf64_Vernaux; - - -/* Legal values for vna_flags. */ -#define VER_FLG_WEAK 0x2 /* Weak version identifier */ - - -/* Auxiliary vector. */ - -/* This vector is normally only used by the program interpreter. The - usual definition in an ABI supplement uses the name auxv_t. The - vector is not usually defined in a standard file, but it - can't hurt. We rename it to avoid conflicts. The sizes of these - types are an arrangement between the exec server and the program - interpreter, so we don't fully specify them here. */ - -typedef struct -{ - uint32_t a_type; /* Entry type */ - union - { - uint32_t a_val; /* Integer value */ - /* We use to have pointer elements added here. We cannot do that, - though, since it does not work when using 32-bit definitions - on 64-bit platforms and vice versa. */ - } a_un; -} Elf32_auxv_t; - -typedef struct -{ - uint64_t a_type; /* Entry type */ - union - { - uint64_t a_val; /* Integer value */ - /* We use to have pointer elements added here. We cannot do that, - though, since it does not work when using 32-bit definitions - on 64-bit platforms and vice versa. */ - } a_un; -} Elf64_auxv_t; - -/* Legal values for a_type (entry type). */ - -#define AT_NULL 0 /* End of vector */ -#define AT_IGNORE 1 /* Entry should be ignored */ -#define AT_EXECFD 2 /* File descriptor of program */ -#define AT_PHDR 3 /* Program headers for program */ -#define AT_PHENT 4 /* Size of program header entry */ -#define AT_PHNUM 5 /* Number of program headers */ -#define AT_PAGESZ 6 /* System page size */ -#define AT_BASE 7 /* Base address of interpreter */ -#define AT_FLAGS 8 /* Flags */ -#define AT_ENTRY 9 /* Entry point of program */ -#define AT_NOTELF 10 /* Program is not ELF */ -#define AT_UID 11 /* Real uid */ -#define AT_EUID 12 /* Effective uid */ -#define AT_GID 13 /* Real gid */ -#define AT_EGID 14 /* Effective gid */ -#define AT_CLKTCK 17 /* Frequency of times() */ - -/* Some more special a_type values describing the hardware. */ -#define AT_PLATFORM 15 /* String identifying platform. */ -#define AT_HWCAP 16 /* Machine dependent hints about - processor capabilities. */ - -/* This entry gives some information about the FPU initialization - performed by the kernel. */ -#define AT_FPUCW 18 /* Used FPU control word. */ - -/* Cache block sizes. */ -#define AT_DCACHEBSIZE 19 /* Data cache block size. */ -#define AT_ICACHEBSIZE 20 /* Instruction cache block size. */ -#define AT_UCACHEBSIZE 21 /* Unified cache block size. */ - -/* A special ignored value for PPC, used by the kernel to control the - interpretation of the AUXV. Must be > 16. */ -#define AT_IGNOREPPC 22 /* Entry should be ignored. */ - -#define AT_SECURE 23 /* Boolean, was exec setuid-like? */ - -#define AT_BASE_PLATFORM 24 /* String identifying real platforms.*/ - -#define AT_RANDOM 25 /* Address of 16 random bytes. */ - -#define AT_EXECFN 31 /* Filename of executable. */ - -/* Pointer to the global system page used for system calls and other - nice things. */ -#define AT_SYSINFO 32 -#define AT_SYSINFO_EHDR 33 - -/* Shapes of the caches. Bits 0-3 contains associativity; bits 4-7 contains - log2 of line size; mask those to get cache size. */ -#define AT_L1I_CACHESHAPE 34 -#define AT_L1D_CACHESHAPE 35 -#define AT_L2_CACHESHAPE 36 -#define AT_L3_CACHESHAPE 37 - -/* Note section contents. Each entry in the note section begins with - a header of a fixed form. */ - -typedef struct -{ - Elf32_Word n_namesz; /* Length of the note's name. */ - Elf32_Word n_descsz; /* Length of the note's descriptor. */ - Elf32_Word n_type; /* Type of the note. */ -} Elf32_Nhdr; - -typedef struct -{ - Elf64_Word n_namesz; /* Length of the note's name. */ - Elf64_Word n_descsz; /* Length of the note's descriptor. */ - Elf64_Word n_type; /* Type of the note. */ -} Elf64_Nhdr; - -/* Known names of notes. */ - -/* Solaris entries in the note section have this name. */ -#define ELF_NOTE_SOLARIS "SUNW Solaris" - -/* Note entries for GNU systems have this name. */ -#define ELF_NOTE_GNU "GNU" - - -/* Defined types of notes for Solaris. */ - -/* Value of descriptor (one word) is desired pagesize for the binary. */ -#define ELF_NOTE_PAGESIZE_HINT 1 - - -/* Defined note types for GNU systems. */ - -/* ABI information. The descriptor consists of words: - word 0: OS descriptor - word 1: major version of the ABI - word 2: minor version of the ABI - word 3: subminor version of the ABI -*/ -#define NT_GNU_ABI_TAG 1 -#define ELF_NOTE_ABI NT_GNU_ABI_TAG /* Old name. */ - -/* Known OSes. These values can appear in word 0 of an - NT_GNU_ABI_TAG note section entry. */ -#define ELF_NOTE_OS_LINUX 0 -#define ELF_NOTE_OS_GNU 1 -#define ELF_NOTE_OS_SOLARIS2 2 -#define ELF_NOTE_OS_FREEBSD 3 - -/* Synthetic hwcap information. The descriptor begins with two words: - word 0: number of entries - word 1: bitmask of enabled entries - Then follow variable-length entries, one byte followed by a - '\0'-terminated hwcap name string. The byte gives the bit - number to test if enabled, (1U << bit) & bitmask. */ -#define NT_GNU_HWCAP 2 - -/* Build ID bits as generated by ld --build-id. - The descriptor consists of any nonzero number of bytes. */ -#define NT_GNU_BUILD_ID 3 - -/* Version note generated by GNU gold containing a version string. */ -#define NT_GNU_GOLD_VERSION 4 - - -/* Move records. */ -typedef struct -{ - Elf32_Xword m_value; /* Symbol value. */ - Elf32_Word m_info; /* Size and index. */ - Elf32_Word m_poffset; /* Symbol offset. */ - Elf32_Half m_repeat; /* Repeat count. */ - Elf32_Half m_stride; /* Stride info. */ -} Elf32_Move; - -typedef struct -{ - Elf64_Xword m_value; /* Symbol value. */ - Elf64_Xword m_info; /* Size and index. */ - Elf64_Xword m_poffset; /* Symbol offset. */ - Elf64_Half m_repeat; /* Repeat count. */ - Elf64_Half m_stride; /* Stride info. */ -} Elf64_Move; - -/* Macro to construct move records. */ -#define ELF32_M_SYM(info) ((info) >> 8) -#define ELF32_M_SIZE(info) ((unsigned char) (info)) -#define ELF32_M_INFO(sym, size) (((sym) << 8) + (unsigned char) (size)) - -#define ELF64_M_SYM(info) ELF32_M_SYM (info) -#define ELF64_M_SIZE(info) ELF32_M_SIZE (info) -#define ELF64_M_INFO(sym, size) ELF32_M_INFO (sym, size) - - -/* Motorola 68k specific definitions. */ - -/* Values for Elf32_Ehdr.e_flags. */ -#define EF_CPU32 0x00810000 - -/* m68k relocs. */ - -#define R_68K_NONE 0 /* No reloc */ -#define R_68K_32 1 /* Direct 32 bit */ -#define R_68K_16 2 /* Direct 16 bit */ -#define R_68K_8 3 /* Direct 8 bit */ -#define R_68K_PC32 4 /* PC relative 32 bit */ -#define R_68K_PC16 5 /* PC relative 16 bit */ -#define R_68K_PC8 6 /* PC relative 8 bit */ -#define R_68K_GOT32 7 /* 32 bit PC relative GOT entry */ -#define R_68K_GOT16 8 /* 16 bit PC relative GOT entry */ -#define R_68K_GOT8 9 /* 8 bit PC relative GOT entry */ -#define R_68K_GOT32O 10 /* 32 bit GOT offset */ -#define R_68K_GOT16O 11 /* 16 bit GOT offset */ -#define R_68K_GOT8O 12 /* 8 bit GOT offset */ -#define R_68K_PLT32 13 /* 32 bit PC relative PLT address */ -#define R_68K_PLT16 14 /* 16 bit PC relative PLT address */ -#define R_68K_PLT8 15 /* 8 bit PC relative PLT address */ -#define R_68K_PLT32O 16 /* 32 bit PLT offset */ -#define R_68K_PLT16O 17 /* 16 bit PLT offset */ -#define R_68K_PLT8O 18 /* 8 bit PLT offset */ -#define R_68K_COPY 19 /* Copy symbol at runtime */ -#define R_68K_GLOB_DAT 20 /* Create GOT entry */ -#define R_68K_JMP_SLOT 21 /* Create PLT entry */ -#define R_68K_RELATIVE 22 /* Adjust by program base */ -#define R_68K_TLS_GD32 25 /* 32 bit GOT offset for GD */ -#define R_68K_TLS_GD16 26 /* 16 bit GOT offset for GD */ -#define R_68K_TLS_GD8 27 /* 8 bit GOT offset for GD */ -#define R_68K_TLS_LDM32 28 /* 32 bit GOT offset for LDM */ -#define R_68K_TLS_LDM16 29 /* 16 bit GOT offset for LDM */ -#define R_68K_TLS_LDM8 30 /* 8 bit GOT offset for LDM */ -#define R_68K_TLS_LDO32 31 /* 32 bit module-relative offset */ -#define R_68K_TLS_LDO16 32 /* 16 bit module-relative offset */ -#define R_68K_TLS_LDO8 33 /* 8 bit module-relative offset */ -#define R_68K_TLS_IE32 34 /* 32 bit GOT offset for IE */ -#define R_68K_TLS_IE16 35 /* 16 bit GOT offset for IE */ -#define R_68K_TLS_IE8 36 /* 8 bit GOT offset for IE */ -#define R_68K_TLS_LE32 37 /* 32 bit offset relative to - static TLS block */ -#define R_68K_TLS_LE16 38 /* 16 bit offset relative to - static TLS block */ -#define R_68K_TLS_LE8 39 /* 8 bit offset relative to - static TLS block */ -#define R_68K_TLS_DTPMOD32 40 /* 32 bit module number */ -#define R_68K_TLS_DTPREL32 41 /* 32 bit module-relative offset */ -#define R_68K_TLS_TPREL32 42 /* 32 bit TP-relative offset */ -/* Keep this the last entry. */ -#define R_68K_NUM 43 - -/* Intel 80386 specific definitions. */ - -/* i386 relocs. */ - -#define R_386_NONE 0 /* No reloc */ -#define R_386_32 1 /* Direct 32 bit */ -#define R_386_PC32 2 /* PC relative 32 bit */ -#define R_386_GOT32 3 /* 32 bit GOT entry */ -#define R_386_PLT32 4 /* 32 bit PLT address */ -#define R_386_COPY 5 /* Copy symbol at runtime */ -#define R_386_GLOB_DAT 6 /* Create GOT entry */ -#define R_386_JMP_SLOT 7 /* Create PLT entry */ -#define R_386_RELATIVE 8 /* Adjust by program base */ -#define R_386_GOTOFF 9 /* 32 bit offset to GOT */ -#define R_386_GOTPC 10 /* 32 bit PC relative offset to GOT */ -#define R_386_32PLT 11 -#define R_386_TLS_TPOFF 14 /* Offset in static TLS block */ -#define R_386_TLS_IE 15 /* Address of GOT entry for static TLS - block offset */ -#define R_386_TLS_GOTIE 16 /* GOT entry for static TLS block - offset */ -#define R_386_TLS_LE 17 /* Offset relative to static TLS - block */ -#define R_386_TLS_GD 18 /* Direct 32 bit for GNU version of - general dynamic thread local data */ -#define R_386_TLS_LDM 19 /* Direct 32 bit for GNU version of - local dynamic thread local data - in LE code */ -#define R_386_16 20 -#define R_386_PC16 21 -#define R_386_8 22 -#define R_386_PC8 23 -#define R_386_TLS_GD_32 24 /* Direct 32 bit for general dynamic - thread local data */ -#define R_386_TLS_GD_PUSH 25 /* Tag for pushl in GD TLS code */ -#define R_386_TLS_GD_CALL 26 /* Relocation for call to - __tls_get_addr() */ -#define R_386_TLS_GD_POP 27 /* Tag for popl in GD TLS code */ -#define R_386_TLS_LDM_32 28 /* Direct 32 bit for local dynamic - thread local data in LE code */ -#define R_386_TLS_LDM_PUSH 29 /* Tag for pushl in LDM TLS code */ -#define R_386_TLS_LDM_CALL 30 /* Relocation for call to - __tls_get_addr() in LDM code */ -#define R_386_TLS_LDM_POP 31 /* Tag for popl in LDM TLS code */ -#define R_386_TLS_LDO_32 32 /* Offset relative to TLS block */ -#define R_386_TLS_IE_32 33 /* GOT entry for negated static TLS - block offset */ -#define R_386_TLS_LE_32 34 /* Negated offset relative to static - TLS block */ -#define R_386_TLS_DTPMOD32 35 /* ID of module containing symbol */ -#define R_386_TLS_DTPOFF32 36 /* Offset in TLS block */ -#define R_386_TLS_TPOFF32 37 /* Negated offset in static TLS block */ -/* 38? */ -#define R_386_TLS_GOTDESC 39 /* GOT offset for TLS descriptor. */ -#define R_386_TLS_DESC_CALL 40 /* Marker of call through TLS - descriptor for - relaxation. */ -#define R_386_TLS_DESC 41 /* TLS descriptor containing - pointer to code and to - argument, returning the TLS - offset for the symbol. */ -#define R_386_IRELATIVE 42 /* Adjust indirectly by program base */ -#define R_386_GOT32X 43 /* 32 bit GOT entry, relaxable */ -/* Keep this the last entry. */ -#define R_386_NUM 44 - -/* SUN SPARC specific definitions. */ - -/* Legal values for ST_TYPE subfield of st_info (symbol type). */ - -#define STT_SPARC_REGISTER 13 /* Global register reserved to app. */ - -/* Values for Elf64_Ehdr.e_flags. */ - -#define EF_SPARCV9_MM 3 -#define EF_SPARCV9_TSO 0 -#define EF_SPARCV9_PSO 1 -#define EF_SPARCV9_RMO 2 -#define EF_SPARC_LEDATA 0x800000 /* little endian data */ -#define EF_SPARC_EXT_MASK 0xFFFF00 -#define EF_SPARC_32PLUS 0x000100 /* generic V8+ features */ -#define EF_SPARC_SUN_US1 0x000200 /* Sun UltraSPARC1 extensions */ -#define EF_SPARC_HAL_R1 0x000400 /* HAL R1 extensions */ -#define EF_SPARC_SUN_US3 0x000800 /* Sun UltraSPARCIII extensions */ - -/* SPARC relocs. */ - -#define R_SPARC_NONE 0 /* No reloc */ -#define R_SPARC_8 1 /* Direct 8 bit */ -#define R_SPARC_16 2 /* Direct 16 bit */ -#define R_SPARC_32 3 /* Direct 32 bit */ -#define R_SPARC_DISP8 4 /* PC relative 8 bit */ -#define R_SPARC_DISP16 5 /* PC relative 16 bit */ -#define R_SPARC_DISP32 6 /* PC relative 32 bit */ -#define R_SPARC_WDISP30 7 /* PC relative 30 bit shifted */ -#define R_SPARC_WDISP22 8 /* PC relative 22 bit shifted */ -#define R_SPARC_HI22 9 /* High 22 bit */ -#define R_SPARC_22 10 /* Direct 22 bit */ -#define R_SPARC_13 11 /* Direct 13 bit */ -#define R_SPARC_LO10 12 /* Truncated 10 bit */ -#define R_SPARC_GOT10 13 /* Truncated 10 bit GOT entry */ -#define R_SPARC_GOT13 14 /* 13 bit GOT entry */ -#define R_SPARC_GOT22 15 /* 22 bit GOT entry shifted */ -#define R_SPARC_PC10 16 /* PC relative 10 bit truncated */ -#define R_SPARC_PC22 17 /* PC relative 22 bit shifted */ -#define R_SPARC_WPLT30 18 /* 30 bit PC relative PLT address */ -#define R_SPARC_COPY 19 /* Copy symbol at runtime */ -#define R_SPARC_GLOB_DAT 20 /* Create GOT entry */ -#define R_SPARC_JMP_SLOT 21 /* Create PLT entry */ -#define R_SPARC_RELATIVE 22 /* Adjust by program base */ -#define R_SPARC_UA32 23 /* Direct 32 bit unaligned */ - -/* Additional Sparc64 relocs. */ - -#define R_SPARC_PLT32 24 /* Direct 32 bit ref to PLT entry */ -#define R_SPARC_HIPLT22 25 /* High 22 bit PLT entry */ -#define R_SPARC_LOPLT10 26 /* Truncated 10 bit PLT entry */ -#define R_SPARC_PCPLT32 27 /* PC rel 32 bit ref to PLT entry */ -#define R_SPARC_PCPLT22 28 /* PC rel high 22 bit PLT entry */ -#define R_SPARC_PCPLT10 29 /* PC rel trunc 10 bit PLT entry */ -#define R_SPARC_10 30 /* Direct 10 bit */ -#define R_SPARC_11 31 /* Direct 11 bit */ -#define R_SPARC_64 32 /* Direct 64 bit */ -#define R_SPARC_OLO10 33 /* 10bit with secondary 13bit addend */ -#define R_SPARC_HH22 34 /* Top 22 bits of direct 64 bit */ -#define R_SPARC_HM10 35 /* High middle 10 bits of ... */ -#define R_SPARC_LM22 36 /* Low middle 22 bits of ... */ -#define R_SPARC_PC_HH22 37 /* Top 22 bits of pc rel 64 bit */ -#define R_SPARC_PC_HM10 38 /* High middle 10 bit of ... */ -#define R_SPARC_PC_LM22 39 /* Low middle 22 bits of ... */ -#define R_SPARC_WDISP16 40 /* PC relative 16 bit shifted */ -#define R_SPARC_WDISP19 41 /* PC relative 19 bit shifted */ -#define R_SPARC_GLOB_JMP 42 /* was part of v9 ABI but was removed */ -#define R_SPARC_7 43 /* Direct 7 bit */ -#define R_SPARC_5 44 /* Direct 5 bit */ -#define R_SPARC_6 45 /* Direct 6 bit */ -#define R_SPARC_DISP64 46 /* PC relative 64 bit */ -#define R_SPARC_PLT64 47 /* Direct 64 bit ref to PLT entry */ -#define R_SPARC_HIX22 48 /* High 22 bit complemented */ -#define R_SPARC_LOX10 49 /* Truncated 11 bit complemented */ -#define R_SPARC_H44 50 /* Direct high 12 of 44 bit */ -#define R_SPARC_M44 51 /* Direct mid 22 of 44 bit */ -#define R_SPARC_L44 52 /* Direct low 10 of 44 bit */ -#define R_SPARC_REGISTER 53 /* Global register usage */ -#define R_SPARC_UA64 54 /* Direct 64 bit unaligned */ -#define R_SPARC_UA16 55 /* Direct 16 bit unaligned */ -#define R_SPARC_TLS_GD_HI22 56 -#define R_SPARC_TLS_GD_LO10 57 -#define R_SPARC_TLS_GD_ADD 58 -#define R_SPARC_TLS_GD_CALL 59 -#define R_SPARC_TLS_LDM_HI22 60 -#define R_SPARC_TLS_LDM_LO10 61 -#define R_SPARC_TLS_LDM_ADD 62 -#define R_SPARC_TLS_LDM_CALL 63 -#define R_SPARC_TLS_LDO_HIX22 64 -#define R_SPARC_TLS_LDO_LOX10 65 -#define R_SPARC_TLS_LDO_ADD 66 -#define R_SPARC_TLS_IE_HI22 67 -#define R_SPARC_TLS_IE_LO10 68 -#define R_SPARC_TLS_IE_LD 69 -#define R_SPARC_TLS_IE_LDX 70 -#define R_SPARC_TLS_IE_ADD 71 -#define R_SPARC_TLS_LE_HIX22 72 -#define R_SPARC_TLS_LE_LOX10 73 -#define R_SPARC_TLS_DTPMOD32 74 -#define R_SPARC_TLS_DTPMOD64 75 -#define R_SPARC_TLS_DTPOFF32 76 -#define R_SPARC_TLS_DTPOFF64 77 -#define R_SPARC_TLS_TPOFF32 78 -#define R_SPARC_TLS_TPOFF64 79 -#define R_SPARC_GOTDATA_HIX22 80 -#define R_SPARC_GOTDATA_LOX10 81 -#define R_SPARC_GOTDATA_OP_HIX22 82 -#define R_SPARC_GOTDATA_OP_LOX10 83 -#define R_SPARC_GOTDATA_OP 84 -#define R_SPARC_H34 85 -#define R_SPARC_SIZE32 86 -#define R_SPARC_SIZE64 87 -#define R_SPARC_WDISP10 88 -#define R_SPARC_JMP_IREL 248 -#define R_SPARC_IRELATIVE 249 -#define R_SPARC_GNU_VTINHERIT 250 -#define R_SPARC_GNU_VTENTRY 251 -#define R_SPARC_REV32 252 -/* Keep this the last entry. */ -#define R_SPARC_NUM 253 - -/* For Sparc64, legal values for d_tag of Elf64_Dyn. */ - -#define DT_SPARC_REGISTER 0x70000001 -#define DT_SPARC_NUM 2 - -/* MIPS R3000 specific definitions. */ - -/* Legal values for e_flags field of Elf32_Ehdr. */ - -#define EF_MIPS_NOREORDER 1 /* A .noreorder directive was used */ -#define EF_MIPS_PIC 2 /* Contains PIC code */ -#define EF_MIPS_CPIC 4 /* Uses PIC calling sequence */ -#define EF_MIPS_XGOT 8 -#define EF_MIPS_64BIT_WHIRL 16 -#define EF_MIPS_ABI2 32 -#define EF_MIPS_ABI_ON32 64 -#define EF_MIPS_ARCH 0xf0000000 /* MIPS architecture level */ - -/* Legal values for MIPS architecture level. */ - -#define EF_MIPS_ARCH_1 0x00000000 /* -mips1 code. */ -#define EF_MIPS_ARCH_2 0x10000000 /* -mips2 code. */ -#define EF_MIPS_ARCH_3 0x20000000 /* -mips3 code. */ -#define EF_MIPS_ARCH_4 0x30000000 /* -mips4 code. */ -#define EF_MIPS_ARCH_5 0x40000000 /* -mips5 code. */ -#define EF_MIPS_ARCH_32 0x60000000 /* MIPS32 code. */ -#define EF_MIPS_ARCH_64 0x70000000 /* MIPS64 code. */ - -/* The following are non-official names and should not be used. */ - -#define E_MIPS_ARCH_1 0x00000000 /* -mips1 code. */ -#define E_MIPS_ARCH_2 0x10000000 /* -mips2 code. */ -#define E_MIPS_ARCH_3 0x20000000 /* -mips3 code. */ -#define E_MIPS_ARCH_4 0x30000000 /* -mips4 code. */ -#define E_MIPS_ARCH_5 0x40000000 /* -mips5 code. */ -#define E_MIPS_ARCH_32 0x60000000 /* MIPS32 code. */ -#define E_MIPS_ARCH_64 0x70000000 /* MIPS64 code. */ - -/* Special section indices. */ - -#define SHN_MIPS_ACOMMON 0xff00 /* Allocated common symbols */ -#define SHN_MIPS_TEXT 0xff01 /* Allocated test symbols. */ -#define SHN_MIPS_DATA 0xff02 /* Allocated data symbols. */ -#define SHN_MIPS_SCOMMON 0xff03 /* Small common symbols */ -#define SHN_MIPS_SUNDEFINED 0xff04 /* Small undefined symbols */ - -/* Legal values for sh_type field of Elf32_Shdr. */ - -#define SHT_MIPS_LIBLIST 0x70000000 /* Shared objects used in link */ -#define SHT_MIPS_MSYM 0x70000001 -#define SHT_MIPS_CONFLICT 0x70000002 /* Conflicting symbols */ -#define SHT_MIPS_GPTAB 0x70000003 /* Global data area sizes */ -#define SHT_MIPS_UCODE 0x70000004 /* Reserved for SGI/MIPS compilers */ -#define SHT_MIPS_DEBUG 0x70000005 /* MIPS ECOFF debugging information*/ -#define SHT_MIPS_REGINFO 0x70000006 /* Register usage information */ -#define SHT_MIPS_PACKAGE 0x70000007 -#define SHT_MIPS_PACKSYM 0x70000008 -#define SHT_MIPS_RELD 0x70000009 -#define SHT_MIPS_IFACE 0x7000000b -#define SHT_MIPS_CONTENT 0x7000000c -#define SHT_MIPS_OPTIONS 0x7000000d /* Miscellaneous options. */ -#define SHT_MIPS_SHDR 0x70000010 -#define SHT_MIPS_FDESC 0x70000011 -#define SHT_MIPS_EXTSYM 0x70000012 -#define SHT_MIPS_DENSE 0x70000013 -#define SHT_MIPS_PDESC 0x70000014 -#define SHT_MIPS_LOCSYM 0x70000015 -#define SHT_MIPS_AUXSYM 0x70000016 -#define SHT_MIPS_OPTSYM 0x70000017 -#define SHT_MIPS_LOCSTR 0x70000018 -#define SHT_MIPS_LINE 0x70000019 -#define SHT_MIPS_RFDESC 0x7000001a -#define SHT_MIPS_DELTASYM 0x7000001b -#define SHT_MIPS_DELTAINST 0x7000001c -#define SHT_MIPS_DELTACLASS 0x7000001d -#define SHT_MIPS_DWARF 0x7000001e /* DWARF debugging information. */ -#define SHT_MIPS_DELTADECL 0x7000001f -#define SHT_MIPS_SYMBOL_LIB 0x70000020 -#define SHT_MIPS_EVENTS 0x70000021 /* Event section. */ -#define SHT_MIPS_TRANSLATE 0x70000022 -#define SHT_MIPS_PIXIE 0x70000023 -#define SHT_MIPS_XLATE 0x70000024 -#define SHT_MIPS_XLATE_DEBUG 0x70000025 -#define SHT_MIPS_WHIRL 0x70000026 -#define SHT_MIPS_EH_REGION 0x70000027 -#define SHT_MIPS_XLATE_OLD 0x70000028 -#define SHT_MIPS_PDR_EXCEPTION 0x70000029 - -/* Legal values for sh_flags field of Elf32_Shdr. */ - -#define SHF_MIPS_GPREL 0x10000000 /* Must be part of global data area */ -#define SHF_MIPS_MERGE 0x20000000 -#define SHF_MIPS_ADDR 0x40000000 -#define SHF_MIPS_STRINGS 0x80000000 -#define SHF_MIPS_NOSTRIP 0x08000000 -#define SHF_MIPS_LOCAL 0x04000000 -#define SHF_MIPS_NAMES 0x02000000 -#define SHF_MIPS_NODUPE 0x01000000 - - -/* Symbol tables. */ - -/* MIPS specific values for `st_other'. */ -#define STO_MIPS_DEFAULT 0x0 -#define STO_MIPS_INTERNAL 0x1 -#define STO_MIPS_HIDDEN 0x2 -#define STO_MIPS_PROTECTED 0x3 -#define STO_MIPS_PLT 0x8 -#define STO_MIPS_SC_ALIGN_UNUSED 0xff - -/* MIPS specific values for `st_info'. */ -#define STB_MIPS_SPLIT_COMMON 13 - -/* Entries found in sections of type SHT_MIPS_GPTAB. */ - -typedef union -{ - struct - { - Elf32_Word gt_current_g_value; /* -G value used for compilation */ - Elf32_Word gt_unused; /* Not used */ - } gt_header; /* First entry in section */ - struct - { - Elf32_Word gt_g_value; /* If this value were used for -G */ - Elf32_Word gt_bytes; /* This many bytes would be used */ - } gt_entry; /* Subsequent entries in section */ -} Elf32_gptab; - -/* Entry found in sections of type SHT_MIPS_REGINFO. */ - -typedef struct -{ - Elf32_Word ri_gprmask; /* General registers used */ - Elf32_Word ri_cprmask[4]; /* Coprocessor registers used */ - Elf32_Sword ri_gp_value; /* $gp register value */ -} Elf32_RegInfo; - -/* Entries found in sections of type SHT_MIPS_OPTIONS. */ - -typedef struct -{ - unsigned char kind; /* Determines interpretation of the - variable part of descriptor. */ - unsigned char size; /* Size of descriptor, including header. */ - Elf32_Section section; /* Section header index of section affected, - 0 for global options. */ - Elf32_Word info; /* Kind-specific information. */ -} Elf_Options; - -/* Values for `kind' field in Elf_Options. */ - -#define ODK_NULL 0 /* Undefined. */ -#define ODK_REGINFO 1 /* Register usage information. */ -#define ODK_EXCEPTIONS 2 /* Exception processing options. */ -#define ODK_PAD 3 /* Section padding options. */ -#define ODK_HWPATCH 4 /* Hardware workarounds performed */ -#define ODK_FILL 5 /* record the fill value used by the linker. */ -#define ODK_TAGS 6 /* reserve space for desktop tools to write. */ -#define ODK_HWAND 7 /* HW workarounds. 'AND' bits when merging. */ -#define ODK_HWOR 8 /* HW workarounds. 'OR' bits when merging. */ - -/* Values for `info' in Elf_Options for ODK_EXCEPTIONS entries. */ - -#define OEX_FPU_MIN 0x1f /* FPE's which MUST be enabled. */ -#define OEX_FPU_MAX 0x1f00 /* FPE's which MAY be enabled. */ -#define OEX_PAGE0 0x10000 /* page zero must be mapped. */ -#define OEX_SMM 0x20000 /* Force sequential memory mode? */ -#define OEX_FPDBUG 0x40000 /* Force floating point debug mode? */ -#define OEX_PRECISEFP OEX_FPDBUG -#define OEX_DISMISS 0x80000 /* Dismiss invalid address faults? */ - -#define OEX_FPU_INVAL 0x10 -#define OEX_FPU_DIV0 0x08 -#define OEX_FPU_OFLO 0x04 -#define OEX_FPU_UFLO 0x02 -#define OEX_FPU_INEX 0x01 - -/* Masks for `info' in Elf_Options for an ODK_HWPATCH entry. */ - -#define OHW_R4KEOP 0x1 /* R4000 end-of-page patch. */ -#define OHW_R8KPFETCH 0x2 /* may need R8000 prefetch patch. */ -#define OHW_R5KEOP 0x4 /* R5000 end-of-page patch. */ -#define OHW_R5KCVTL 0x8 /* R5000 cvt.[ds].l bug. clean=1. */ - -#define OPAD_PREFIX 0x1 -#define OPAD_POSTFIX 0x2 -#define OPAD_SYMBOL 0x4 - -/* Entry found in `.options' section. */ - -typedef struct -{ - Elf32_Word hwp_flags1; /* Extra flags. */ - Elf32_Word hwp_flags2; /* Extra flags. */ -} Elf_Options_Hw; - -/* Masks for `info' in ElfOptions for ODK_HWAND and ODK_HWOR entries. */ - -#define OHWA0_R4KEOP_CHECKED 0x00000001 -#define OHWA1_R4KEOP_CLEAN 0x00000002 - -/* MIPS relocs. */ - -#define R_MIPS_NONE 0 /* No reloc */ -#define R_MIPS_16 1 /* Direct 16 bit */ -#define R_MIPS_32 2 /* Direct 32 bit */ -#define R_MIPS_REL32 3 /* PC relative 32 bit */ -#define R_MIPS_26 4 /* Direct 26 bit shifted */ -#define R_MIPS_HI16 5 /* High 16 bit */ -#define R_MIPS_LO16 6 /* Low 16 bit */ -#define R_MIPS_GPREL16 7 /* GP relative 16 bit */ -#define R_MIPS_LITERAL 8 /* 16 bit literal entry */ -#define R_MIPS_GOT16 9 /* 16 bit GOT entry */ -#define R_MIPS_PC16 10 /* PC relative 16 bit */ -#define R_MIPS_CALL16 11 /* 16 bit GOT entry for function */ -#define R_MIPS_GPREL32 12 /* GP relative 32 bit */ - -#define R_MIPS_SHIFT5 16 -#define R_MIPS_SHIFT6 17 -#define R_MIPS_64 18 -#define R_MIPS_GOT_DISP 19 -#define R_MIPS_GOT_PAGE 20 -#define R_MIPS_GOT_OFST 21 -#define R_MIPS_GOT_HI16 22 -#define R_MIPS_GOT_LO16 23 -#define R_MIPS_SUB 24 -#define R_MIPS_INSERT_A 25 -#define R_MIPS_INSERT_B 26 -#define R_MIPS_DELETE 27 -#define R_MIPS_HIGHER 28 -#define R_MIPS_HIGHEST 29 -#define R_MIPS_CALL_HI16 30 -#define R_MIPS_CALL_LO16 31 -#define R_MIPS_SCN_DISP 32 -#define R_MIPS_REL16 33 -#define R_MIPS_ADD_IMMEDIATE 34 -#define R_MIPS_PJUMP 35 -#define R_MIPS_RELGOT 36 -#define R_MIPS_JALR 37 -#define R_MIPS_TLS_DTPMOD32 38 /* Module number 32 bit */ -#define R_MIPS_TLS_DTPREL32 39 /* Module-relative offset 32 bit */ -#define R_MIPS_TLS_DTPMOD64 40 /* Module number 64 bit */ -#define R_MIPS_TLS_DTPREL64 41 /* Module-relative offset 64 bit */ -#define R_MIPS_TLS_GD 42 /* 16 bit GOT offset for GD */ -#define R_MIPS_TLS_LDM 43 /* 16 bit GOT offset for LDM */ -#define R_MIPS_TLS_DTPREL_HI16 44 /* Module-relative offset, high 16 bits */ -#define R_MIPS_TLS_DTPREL_LO16 45 /* Module-relative offset, low 16 bits */ -#define R_MIPS_TLS_GOTTPREL 46 /* 16 bit GOT offset for IE */ -#define R_MIPS_TLS_TPREL32 47 /* TP-relative offset, 32 bit */ -#define R_MIPS_TLS_TPREL64 48 /* TP-relative offset, 64 bit */ -#define R_MIPS_TLS_TPREL_HI16 49 /* TP-relative offset, high 16 bits */ -#define R_MIPS_TLS_TPREL_LO16 50 /* TP-relative offset, low 16 bits */ -#define R_MIPS_GLOB_DAT 51 -#define R_MIPS_COPY 126 -#define R_MIPS_JUMP_SLOT 127 -/* Keep this the last entry. */ -#define R_MIPS_NUM 128 - -/* Legal values for p_type field of Elf32_Phdr. */ - -#define PT_MIPS_REGINFO 0x70000000 /* Register usage information */ -#define PT_MIPS_RTPROC 0x70000001 /* Runtime procedure table. */ -#define PT_MIPS_OPTIONS 0x70000002 - -/* Special program header types. */ - -#define PF_MIPS_LOCAL 0x10000000 - -/* Legal values for d_tag field of Elf32_Dyn. */ - -#define DT_MIPS_RLD_VERSION 0x70000001 /* Runtime linker interface version */ -#define DT_MIPS_TIME_STAMP 0x70000002 /* Timestamp */ -#define DT_MIPS_ICHECKSUM 0x70000003 /* Checksum */ -#define DT_MIPS_IVERSION 0x70000004 /* Version string (string tbl index) */ -#define DT_MIPS_FLAGS 0x70000005 /* Flags */ -#define DT_MIPS_BASE_ADDRESS 0x70000006 /* Base address */ -#define DT_MIPS_MSYM 0x70000007 -#define DT_MIPS_CONFLICT 0x70000008 /* Address of CONFLICT section */ -#define DT_MIPS_LIBLIST 0x70000009 /* Address of LIBLIST section */ -#define DT_MIPS_LOCAL_GOTNO 0x7000000a /* Number of local GOT entries */ -#define DT_MIPS_CONFLICTNO 0x7000000b /* Number of CONFLICT entries */ -#define DT_MIPS_LIBLISTNO 0x70000010 /* Number of LIBLIST entries */ -#define DT_MIPS_SYMTABNO 0x70000011 /* Number of DYNSYM entries */ -#define DT_MIPS_UNREFEXTNO 0x70000012 /* First external DYNSYM */ -#define DT_MIPS_GOTSYM 0x70000013 /* First GOT entry in DYNSYM */ -#define DT_MIPS_HIPAGENO 0x70000014 /* Number of GOT page table entries */ -#define DT_MIPS_RLD_MAP 0x70000016 /* Address of run time loader map. */ -#define DT_MIPS_DELTA_CLASS 0x70000017 /* Delta C++ class definition. */ -#define DT_MIPS_DELTA_CLASS_NO 0x70000018 /* Number of entries in - DT_MIPS_DELTA_CLASS. */ -#define DT_MIPS_DELTA_INSTANCE 0x70000019 /* Delta C++ class instances. */ -#define DT_MIPS_DELTA_INSTANCE_NO 0x7000001a /* Number of entries in - DT_MIPS_DELTA_INSTANCE. */ -#define DT_MIPS_DELTA_RELOC 0x7000001b /* Delta relocations. */ -#define DT_MIPS_DELTA_RELOC_NO 0x7000001c /* Number of entries in - DT_MIPS_DELTA_RELOC. */ -#define DT_MIPS_DELTA_SYM 0x7000001d /* Delta symbols that Delta - relocations refer to. */ -#define DT_MIPS_DELTA_SYM_NO 0x7000001e /* Number of entries in - DT_MIPS_DELTA_SYM. */ -#define DT_MIPS_DELTA_CLASSSYM 0x70000020 /* Delta symbols that hold the - class declaration. */ -#define DT_MIPS_DELTA_CLASSSYM_NO 0x70000021 /* Number of entries in - DT_MIPS_DELTA_CLASSSYM. */ -#define DT_MIPS_CXX_FLAGS 0x70000022 /* Flags indicating for C++ flavor. */ -#define DT_MIPS_PIXIE_INIT 0x70000023 -#define DT_MIPS_SYMBOL_LIB 0x70000024 -#define DT_MIPS_LOCALPAGE_GOTIDX 0x70000025 -#define DT_MIPS_LOCAL_GOTIDX 0x70000026 -#define DT_MIPS_HIDDEN_GOTIDX 0x70000027 -#define DT_MIPS_PROTECTED_GOTIDX 0x70000028 -#define DT_MIPS_OPTIONS 0x70000029 /* Address of .options. */ -#define DT_MIPS_INTERFACE 0x7000002a /* Address of .interface. */ -#define DT_MIPS_DYNSTR_ALIGN 0x7000002b -#define DT_MIPS_INTERFACE_SIZE 0x7000002c /* Size of the .interface section. */ -#define DT_MIPS_RLD_TEXT_RESOLVE_ADDR 0x7000002d /* Address of rld_text_rsolve - function stored in GOT. */ -#define DT_MIPS_PERF_SUFFIX 0x7000002e /* Default suffix of dso to be added - by rld on dlopen() calls. */ -#define DT_MIPS_COMPACT_SIZE 0x7000002f /* (O32)Size of compact rel section. */ -#define DT_MIPS_GP_VALUE 0x70000030 /* GP value for aux GOTs. */ -#define DT_MIPS_AUX_DYNAMIC 0x70000031 /* Address of aux .dynamic. */ -/* The address of .got.plt in an executable using the new non-PIC ABI. */ -#define DT_MIPS_PLTGOT 0x70000032 -/* The base of the PLT in an executable using the new non-PIC ABI if that - PLT is writable. For a non-writable PLT, this is omitted or has a zero - value. */ -#define DT_MIPS_RWPLT 0x70000034 -#define DT_MIPS_NUM 0x35 - -/* Legal values for DT_MIPS_FLAGS Elf32_Dyn entry. */ - -#define RHF_NONE 0 /* No flags */ -#define RHF_QUICKSTART (1 << 0) /* Use quickstart */ -#define RHF_NOTPOT (1 << 1) /* Hash size not power of 2 */ -#define RHF_NO_LIBRARY_REPLACEMENT (1 << 2) /* Ignore LD_LIBRARY_PATH */ -#define RHF_NO_MOVE (1 << 3) -#define RHF_SGI_ONLY (1 << 4) -#define RHF_GUARANTEE_INIT (1 << 5) -#define RHF_DELTA_C_PLUS_PLUS (1 << 6) -#define RHF_GUARANTEE_START_INIT (1 << 7) -#define RHF_PIXIE (1 << 8) -#define RHF_DEFAULT_DELAY_LOAD (1 << 9) -#define RHF_REQUICKSTART (1 << 10) -#define RHF_REQUICKSTARTED (1 << 11) -#define RHF_CORD (1 << 12) -#define RHF_NO_UNRES_UNDEF (1 << 13) -#define RHF_RLD_ORDER_SAFE (1 << 14) - -/* Entries found in sections of type SHT_MIPS_LIBLIST. */ - -typedef struct -{ - Elf32_Word l_name; /* Name (string table index) */ - Elf32_Word l_time_stamp; /* Timestamp */ - Elf32_Word l_checksum; /* Checksum */ - Elf32_Word l_version; /* Interface version */ - Elf32_Word l_flags; /* Flags */ -} Elf32_Lib; - -typedef struct -{ - Elf64_Word l_name; /* Name (string table index) */ - Elf64_Word l_time_stamp; /* Timestamp */ - Elf64_Word l_checksum; /* Checksum */ - Elf64_Word l_version; /* Interface version */ - Elf64_Word l_flags; /* Flags */ -} Elf64_Lib; - - -/* Legal values for l_flags. */ - -#define LL_NONE 0 -#define LL_EXACT_MATCH (1 << 0) /* Require exact match */ -#define LL_IGNORE_INT_VER (1 << 1) /* Ignore interface version */ -#define LL_REQUIRE_MINOR (1 << 2) -#define LL_EXPORTS (1 << 3) -#define LL_DELAY_LOAD (1 << 4) -#define LL_DELTA (1 << 5) - -/* Entries found in sections of type SHT_MIPS_CONFLICT. */ - -typedef Elf32_Addr Elf32_Conflict; - - -/* HPPA specific definitions. */ - -/* Legal values for e_flags field of Elf32_Ehdr. */ - -#define EF_PARISC_TRAPNIL 0x00010000 /* Trap nil pointer dereference. */ -#define EF_PARISC_EXT 0x00020000 /* Program uses arch. extensions. */ -#define EF_PARISC_LSB 0x00040000 /* Program expects little endian. */ -#define EF_PARISC_WIDE 0x00080000 /* Program expects wide mode. */ -#define EF_PARISC_NO_KABP 0x00100000 /* No kernel assisted branch - prediction. */ -#define EF_PARISC_LAZYSWAP 0x00400000 /* Allow lazy swapping. */ -#define EF_PARISC_ARCH 0x0000ffff /* Architecture version. */ - -/* Defined values for `e_flags & EF_PARISC_ARCH' are: */ - -#define EFA_PARISC_1_0 0x020b /* PA-RISC 1.0 big-endian. */ -#define EFA_PARISC_1_1 0x0210 /* PA-RISC 1.1 big-endian. */ -#define EFA_PARISC_2_0 0x0214 /* PA-RISC 2.0 big-endian. */ - -/* Additional section indices. */ - -#define SHN_PARISC_ANSI_COMMON 0xff00 /* Section for tentatively declared - symbols in ANSI C. */ -#define SHN_PARISC_HUGE_COMMON 0xff01 /* Common blocks in huge model. */ - -/* Legal values for sh_type field of Elf32_Shdr. */ - -#define SHT_PARISC_EXT 0x70000000 /* Contains product specific ext. */ -#define SHT_PARISC_UNWIND 0x70000001 /* Unwind information. */ -#define SHT_PARISC_DOC 0x70000002 /* Debug info for optimized code. */ - -/* Legal values for sh_flags field of Elf32_Shdr. */ - -#define SHF_PARISC_SHORT 0x20000000 /* Section with short addressing. */ -#define SHF_PARISC_HUGE 0x40000000 /* Section far from gp. */ -#define SHF_PARISC_SBP 0x80000000 /* Static branch prediction code. */ - -/* Legal values for ST_TYPE subfield of st_info (symbol type). */ - -#define STT_PARISC_MILLICODE 13 /* Millicode function entry point. */ - -#define STT_HP_OPAQUE (STT_LOOS + 0x1) -#define STT_HP_STUB (STT_LOOS + 0x2) - -/* HPPA relocs. */ - -#define R_PARISC_NONE 0 /* No reloc. */ -#define R_PARISC_DIR32 1 /* Direct 32-bit reference. */ -#define R_PARISC_DIR21L 2 /* Left 21 bits of eff. address. */ -#define R_PARISC_DIR17R 3 /* Right 17 bits of eff. address. */ -#define R_PARISC_DIR17F 4 /* 17 bits of eff. address. */ -#define R_PARISC_DIR14R 6 /* Right 14 bits of eff. address. */ -#define R_PARISC_PCREL32 9 /* 32-bit rel. address. */ -#define R_PARISC_PCREL21L 10 /* Left 21 bits of rel. address. */ -#define R_PARISC_PCREL17R 11 /* Right 17 bits of rel. address. */ -#define R_PARISC_PCREL17F 12 /* 17 bits of rel. address. */ -#define R_PARISC_PCREL14R 14 /* Right 14 bits of rel. address. */ -#define R_PARISC_DPREL21L 18 /* Left 21 bits of rel. address. */ -#define R_PARISC_DPREL14R 22 /* Right 14 bits of rel. address. */ -#define R_PARISC_GPREL21L 26 /* GP-relative, left 21 bits. */ -#define R_PARISC_GPREL14R 30 /* GP-relative, right 14 bits. */ -#define R_PARISC_LTOFF21L 34 /* LT-relative, left 21 bits. */ -#define R_PARISC_LTOFF14R 38 /* LT-relative, right 14 bits. */ -#define R_PARISC_SECREL32 41 /* 32 bits section rel. address. */ -#define R_PARISC_SEGBASE 48 /* No relocation, set segment base. */ -#define R_PARISC_SEGREL32 49 /* 32 bits segment rel. address. */ -#define R_PARISC_PLTOFF21L 50 /* PLT rel. address, left 21 bits. */ -#define R_PARISC_PLTOFF14R 54 /* PLT rel. address, right 14 bits. */ -#define R_PARISC_LTOFF_FPTR32 57 /* 32 bits LT-rel. function pointer. */ -#define R_PARISC_LTOFF_FPTR21L 58 /* LT-rel. fct ptr, left 21 bits. */ -#define R_PARISC_LTOFF_FPTR14R 62 /* LT-rel. fct ptr, right 14 bits. */ -#define R_PARISC_FPTR64 64 /* 64 bits function address. */ -#define R_PARISC_PLABEL32 65 /* 32 bits function address. */ -#define R_PARISC_PLABEL21L 66 /* Left 21 bits of fdesc address. */ -#define R_PARISC_PLABEL14R 70 /* Right 14 bits of fdesc address. */ -#define R_PARISC_PCREL64 72 /* 64 bits PC-rel. address. */ -#define R_PARISC_PCREL22F 74 /* 22 bits PC-rel. address. */ -#define R_PARISC_PCREL14WR 75 /* PC-rel. address, right 14 bits. */ -#define R_PARISC_PCREL14DR 76 /* PC rel. address, right 14 bits. */ -#define R_PARISC_PCREL16F 77 /* 16 bits PC-rel. address. */ -#define R_PARISC_PCREL16WF 78 /* 16 bits PC-rel. address. */ -#define R_PARISC_PCREL16DF 79 /* 16 bits PC-rel. address. */ -#define R_PARISC_DIR64 80 /* 64 bits of eff. address. */ -#define R_PARISC_DIR14WR 83 /* 14 bits of eff. address. */ -#define R_PARISC_DIR14DR 84 /* 14 bits of eff. address. */ -#define R_PARISC_DIR16F 85 /* 16 bits of eff. address. */ -#define R_PARISC_DIR16WF 86 /* 16 bits of eff. address. */ -#define R_PARISC_DIR16DF 87 /* 16 bits of eff. address. */ -#define R_PARISC_GPREL64 88 /* 64 bits of GP-rel. address. */ -#define R_PARISC_GPREL14WR 91 /* GP-rel. address, right 14 bits. */ -#define R_PARISC_GPREL14DR 92 /* GP-rel. address, right 14 bits. */ -#define R_PARISC_GPREL16F 93 /* 16 bits GP-rel. address. */ -#define R_PARISC_GPREL16WF 94 /* 16 bits GP-rel. address. */ -#define R_PARISC_GPREL16DF 95 /* 16 bits GP-rel. address. */ -#define R_PARISC_LTOFF64 96 /* 64 bits LT-rel. address. */ -#define R_PARISC_LTOFF14WR 99 /* LT-rel. address, right 14 bits. */ -#define R_PARISC_LTOFF14DR 100 /* LT-rel. address, right 14 bits. */ -#define R_PARISC_LTOFF16F 101 /* 16 bits LT-rel. address. */ -#define R_PARISC_LTOFF16WF 102 /* 16 bits LT-rel. address. */ -#define R_PARISC_LTOFF16DF 103 /* 16 bits LT-rel. address. */ -#define R_PARISC_SECREL64 104 /* 64 bits section rel. address. */ -#define R_PARISC_SEGREL64 112 /* 64 bits segment rel. address. */ -#define R_PARISC_PLTOFF14WR 115 /* PLT-rel. address, right 14 bits. */ -#define R_PARISC_PLTOFF14DR 116 /* PLT-rel. address, right 14 bits. */ -#define R_PARISC_PLTOFF16F 117 /* 16 bits LT-rel. address. */ -#define R_PARISC_PLTOFF16WF 118 /* 16 bits PLT-rel. address. */ -#define R_PARISC_PLTOFF16DF 119 /* 16 bits PLT-rel. address. */ -#define R_PARISC_LTOFF_FPTR64 120 /* 64 bits LT-rel. function ptr. */ -#define R_PARISC_LTOFF_FPTR14WR 123 /* LT-rel. fct. ptr., right 14 bits. */ -#define R_PARISC_LTOFF_FPTR14DR 124 /* LT-rel. fct. ptr., right 14 bits. */ -#define R_PARISC_LTOFF_FPTR16F 125 /* 16 bits LT-rel. function ptr. */ -#define R_PARISC_LTOFF_FPTR16WF 126 /* 16 bits LT-rel. function ptr. */ -#define R_PARISC_LTOFF_FPTR16DF 127 /* 16 bits LT-rel. function ptr. */ -#define R_PARISC_LORESERVE 128 -#define R_PARISC_COPY 128 /* Copy relocation. */ -#define R_PARISC_IPLT 129 /* Dynamic reloc, imported PLT */ -#define R_PARISC_EPLT 130 /* Dynamic reloc, exported PLT */ -#define R_PARISC_TPREL32 153 /* 32 bits TP-rel. address. */ -#define R_PARISC_TPREL21L 154 /* TP-rel. address, left 21 bits. */ -#define R_PARISC_TPREL14R 158 /* TP-rel. address, right 14 bits. */ -#define R_PARISC_LTOFF_TP21L 162 /* LT-TP-rel. address, left 21 bits. */ -#define R_PARISC_LTOFF_TP14R 166 /* LT-TP-rel. address, right 14 bits.*/ -#define R_PARISC_LTOFF_TP14F 167 /* 14 bits LT-TP-rel. address. */ -#define R_PARISC_TPREL64 216 /* 64 bits TP-rel. address. */ -#define R_PARISC_TPREL14WR 219 /* TP-rel. address, right 14 bits. */ -#define R_PARISC_TPREL14DR 220 /* TP-rel. address, right 14 bits. */ -#define R_PARISC_TPREL16F 221 /* 16 bits TP-rel. address. */ -#define R_PARISC_TPREL16WF 222 /* 16 bits TP-rel. address. */ -#define R_PARISC_TPREL16DF 223 /* 16 bits TP-rel. address. */ -#define R_PARISC_LTOFF_TP64 224 /* 64 bits LT-TP-rel. address. */ -#define R_PARISC_LTOFF_TP14WR 227 /* LT-TP-rel. address, right 14 bits.*/ -#define R_PARISC_LTOFF_TP14DR 228 /* LT-TP-rel. address, right 14 bits.*/ -#define R_PARISC_LTOFF_TP16F 229 /* 16 bits LT-TP-rel. address. */ -#define R_PARISC_LTOFF_TP16WF 230 /* 16 bits LT-TP-rel. address. */ -#define R_PARISC_LTOFF_TP16DF 231 /* 16 bits LT-TP-rel. address. */ -#define R_PARISC_GNU_VTENTRY 232 -#define R_PARISC_GNU_VTINHERIT 233 -#define R_PARISC_TLS_GD21L 234 /* GD 21-bit left. */ -#define R_PARISC_TLS_GD14R 235 /* GD 14-bit right. */ -#define R_PARISC_TLS_GDCALL 236 /* GD call to __t_g_a. */ -#define R_PARISC_TLS_LDM21L 237 /* LD module 21-bit left. */ -#define R_PARISC_TLS_LDM14R 238 /* LD module 14-bit right. */ -#define R_PARISC_TLS_LDMCALL 239 /* LD module call to __t_g_a. */ -#define R_PARISC_TLS_LDO21L 240 /* LD offset 21-bit left. */ -#define R_PARISC_TLS_LDO14R 241 /* LD offset 14-bit right. */ -#define R_PARISC_TLS_DTPMOD32 242 /* DTP module 32-bit. */ -#define R_PARISC_TLS_DTPMOD64 243 /* DTP module 64-bit. */ -#define R_PARISC_TLS_DTPOFF32 244 /* DTP offset 32-bit. */ -#define R_PARISC_TLS_DTPOFF64 245 /* DTP offset 32-bit. */ -#define R_PARISC_TLS_LE21L R_PARISC_TPREL21L -#define R_PARISC_TLS_LE14R R_PARISC_TPREL14R -#define R_PARISC_TLS_IE21L R_PARISC_LTOFF_TP21L -#define R_PARISC_TLS_IE14R R_PARISC_LTOFF_TP14R -#define R_PARISC_TLS_TPREL32 R_PARISC_TPREL32 -#define R_PARISC_TLS_TPREL64 R_PARISC_TPREL64 -#define R_PARISC_HIRESERVE 255 - -/* Legal values for p_type field of Elf32_Phdr/Elf64_Phdr. */ - -#define PT_HP_TLS (PT_LOOS + 0x0) -#define PT_HP_CORE_NONE (PT_LOOS + 0x1) -#define PT_HP_CORE_VERSION (PT_LOOS + 0x2) -#define PT_HP_CORE_KERNEL (PT_LOOS + 0x3) -#define PT_HP_CORE_COMM (PT_LOOS + 0x4) -#define PT_HP_CORE_PROC (PT_LOOS + 0x5) -#define PT_HP_CORE_LOADABLE (PT_LOOS + 0x6) -#define PT_HP_CORE_STACK (PT_LOOS + 0x7) -#define PT_HP_CORE_SHM (PT_LOOS + 0x8) -#define PT_HP_CORE_MMF (PT_LOOS + 0x9) -#define PT_HP_PARALLEL (PT_LOOS + 0x10) -#define PT_HP_FASTBIND (PT_LOOS + 0x11) -#define PT_HP_OPT_ANNOT (PT_LOOS + 0x12) -#define PT_HP_HSL_ANNOT (PT_LOOS + 0x13) -#define PT_HP_STACK (PT_LOOS + 0x14) - -#define PT_PARISC_ARCHEXT 0x70000000 -#define PT_PARISC_UNWIND 0x70000001 - -/* Legal values for p_flags field of Elf32_Phdr/Elf64_Phdr. */ - -#define PF_PARISC_SBP 0x08000000 - -#define PF_HP_PAGE_SIZE 0x00100000 -#define PF_HP_FAR_SHARED 0x00200000 -#define PF_HP_NEAR_SHARED 0x00400000 -#define PF_HP_CODE 0x01000000 -#define PF_HP_MODIFY 0x02000000 -#define PF_HP_LAZYSWAP 0x04000000 -#define PF_HP_SBP 0x08000000 - - -/* Alpha specific definitions. */ - -/* Legal values for e_flags field of Elf64_Ehdr. */ - -#define EF_ALPHA_32BIT 1 /* All addresses must be < 2GB. */ -#define EF_ALPHA_CANRELAX 2 /* Relocations for relaxing exist. */ - -/* Legal values for sh_type field of Elf64_Shdr. */ - -/* These two are primarily concerned with ECOFF debugging info. */ -#define SHT_ALPHA_DEBUG 0x70000001 -#define SHT_ALPHA_REGINFO 0x70000002 - -/* Legal values for sh_flags field of Elf64_Shdr. */ - -#define SHF_ALPHA_GPREL 0x10000000 - -/* Legal values for st_other field of Elf64_Sym. */ -#define STO_ALPHA_NOPV 0x80 /* No PV required. */ -#define STO_ALPHA_STD_GPLOAD 0x88 /* PV only used for initial ldgp. */ - -/* Alpha relocs. */ - -#define R_ALPHA_NONE 0 /* No reloc */ -#define R_ALPHA_REFLONG 1 /* Direct 32 bit */ -#define R_ALPHA_REFQUAD 2 /* Direct 64 bit */ -#define R_ALPHA_GPREL32 3 /* GP relative 32 bit */ -#define R_ALPHA_LITERAL 4 /* GP relative 16 bit w/optimization */ -#define R_ALPHA_LITUSE 5 /* Optimization hint for LITERAL */ -#define R_ALPHA_GPDISP 6 /* Add displacement to GP */ -#define R_ALPHA_BRADDR 7 /* PC+4 relative 23 bit shifted */ -#define R_ALPHA_HINT 8 /* PC+4 relative 16 bit shifted */ -#define R_ALPHA_SREL16 9 /* PC relative 16 bit */ -#define R_ALPHA_SREL32 10 /* PC relative 32 bit */ -#define R_ALPHA_SREL64 11 /* PC relative 64 bit */ -#define R_ALPHA_GPRELHIGH 17 /* GP relative 32 bit, high 16 bits */ -#define R_ALPHA_GPRELLOW 18 /* GP relative 32 bit, low 16 bits */ -#define R_ALPHA_GPREL16 19 /* GP relative 16 bit */ -#define R_ALPHA_COPY 24 /* Copy symbol at runtime */ -#define R_ALPHA_GLOB_DAT 25 /* Create GOT entry */ -#define R_ALPHA_JMP_SLOT 26 /* Create PLT entry */ -#define R_ALPHA_RELATIVE 27 /* Adjust by program base */ -#define R_ALPHA_TLS_GD_HI 28 -#define R_ALPHA_TLSGD 29 -#define R_ALPHA_TLS_LDM 30 -#define R_ALPHA_DTPMOD64 31 -#define R_ALPHA_GOTDTPREL 32 -#define R_ALPHA_DTPREL64 33 -#define R_ALPHA_DTPRELHI 34 -#define R_ALPHA_DTPRELLO 35 -#define R_ALPHA_DTPREL16 36 -#define R_ALPHA_GOTTPREL 37 -#define R_ALPHA_TPREL64 38 -#define R_ALPHA_TPRELHI 39 -#define R_ALPHA_TPRELLO 40 -#define R_ALPHA_TPREL16 41 -/* Keep this the last entry. */ -#define R_ALPHA_NUM 46 - -/* Magic values of the LITUSE relocation addend. */ -#define LITUSE_ALPHA_ADDR 0 -#define LITUSE_ALPHA_BASE 1 -#define LITUSE_ALPHA_BYTOFF 2 -#define LITUSE_ALPHA_JSR 3 -#define LITUSE_ALPHA_TLS_GD 4 -#define LITUSE_ALPHA_TLS_LDM 5 - -/* Legal values for d_tag of Elf64_Dyn. */ -#define DT_ALPHA_PLTRO (DT_LOPROC + 0) -#define DT_ALPHA_NUM 1 - -/* PowerPC specific declarations */ - -/* Values for Elf32/64_Ehdr.e_flags. */ -#define EF_PPC_EMB 0x80000000 /* PowerPC embedded flag */ - -/* Cygnus local bits below */ -#define EF_PPC_RELOCATABLE 0x00010000 /* PowerPC -mrelocatable flag*/ -#define EF_PPC_RELOCATABLE_LIB 0x00008000 /* PowerPC -mrelocatable-lib - flag */ - -/* PowerPC relocations defined by the ABIs */ -#define R_PPC_NONE 0 -#define R_PPC_ADDR32 1 /* 32bit absolute address */ -#define R_PPC_ADDR24 2 /* 26bit address, 2 bits ignored. */ -#define R_PPC_ADDR16 3 /* 16bit absolute address */ -#define R_PPC_ADDR16_LO 4 /* lower 16bit of absolute address */ -#define R_PPC_ADDR16_HI 5 /* high 16bit of absolute address */ -#define R_PPC_ADDR16_HA 6 /* adjusted high 16bit */ -#define R_PPC_ADDR14 7 /* 16bit address, 2 bits ignored */ -#define R_PPC_ADDR14_BRTAKEN 8 -#define R_PPC_ADDR14_BRNTAKEN 9 -#define R_PPC_REL24 10 /* PC relative 26 bit */ -#define R_PPC_REL14 11 /* PC relative 16 bit */ -#define R_PPC_REL14_BRTAKEN 12 -#define R_PPC_REL14_BRNTAKEN 13 -#define R_PPC_GOT16 14 -#define R_PPC_GOT16_LO 15 -#define R_PPC_GOT16_HI 16 -#define R_PPC_GOT16_HA 17 -#define R_PPC_PLTREL24 18 -#define R_PPC_COPY 19 -#define R_PPC_GLOB_DAT 20 -#define R_PPC_JMP_SLOT 21 -#define R_PPC_RELATIVE 22 -#define R_PPC_LOCAL24PC 23 -#define R_PPC_UADDR32 24 -#define R_PPC_UADDR16 25 -#define R_PPC_REL32 26 -#define R_PPC_PLT32 27 -#define R_PPC_PLTREL32 28 -#define R_PPC_PLT16_LO 29 -#define R_PPC_PLT16_HI 30 -#define R_PPC_PLT16_HA 31 -#define R_PPC_SDAREL16 32 -#define R_PPC_SECTOFF 33 -#define R_PPC_SECTOFF_LO 34 -#define R_PPC_SECTOFF_HI 35 -#define R_PPC_SECTOFF_HA 36 - -/* PowerPC relocations defined for the TLS access ABI. */ -#define R_PPC_TLS 67 /* none (sym+add)@tls */ -#define R_PPC_DTPMOD32 68 /* word32 (sym+add)@dtpmod */ -#define R_PPC_TPREL16 69 /* half16* (sym+add)@tprel */ -#define R_PPC_TPREL16_LO 70 /* half16 (sym+add)@tprel@l */ -#define R_PPC_TPREL16_HI 71 /* half16 (sym+add)@tprel@h */ -#define R_PPC_TPREL16_HA 72 /* half16 (sym+add)@tprel@ha */ -#define R_PPC_TPREL32 73 /* word32 (sym+add)@tprel */ -#define R_PPC_DTPREL16 74 /* half16* (sym+add)@dtprel */ -#define R_PPC_DTPREL16_LO 75 /* half16 (sym+add)@dtprel@l */ -#define R_PPC_DTPREL16_HI 76 /* half16 (sym+add)@dtprel@h */ -#define R_PPC_DTPREL16_HA 77 /* half16 (sym+add)@dtprel@ha */ -#define R_PPC_DTPREL32 78 /* word32 (sym+add)@dtprel */ -#define R_PPC_GOT_TLSGD16 79 /* half16* (sym+add)@got@tlsgd */ -#define R_PPC_GOT_TLSGD16_LO 80 /* half16 (sym+add)@got@tlsgd@l */ -#define R_PPC_GOT_TLSGD16_HI 81 /* half16 (sym+add)@got@tlsgd@h */ -#define R_PPC_GOT_TLSGD16_HA 82 /* half16 (sym+add)@got@tlsgd@ha */ -#define R_PPC_GOT_TLSLD16 83 /* half16* (sym+add)@got@tlsld */ -#define R_PPC_GOT_TLSLD16_LO 84 /* half16 (sym+add)@got@tlsld@l */ -#define R_PPC_GOT_TLSLD16_HI 85 /* half16 (sym+add)@got@tlsld@h */ -#define R_PPC_GOT_TLSLD16_HA 86 /* half16 (sym+add)@got@tlsld@ha */ -#define R_PPC_GOT_TPREL16 87 /* half16* (sym+add)@got@tprel */ -#define R_PPC_GOT_TPREL16_LO 88 /* half16 (sym+add)@got@tprel@l */ -#define R_PPC_GOT_TPREL16_HI 89 /* half16 (sym+add)@got@tprel@h */ -#define R_PPC_GOT_TPREL16_HA 90 /* half16 (sym+add)@got@tprel@ha */ -#define R_PPC_GOT_DTPREL16 91 /* half16* (sym+add)@got@dtprel */ -#define R_PPC_GOT_DTPREL16_LO 92 /* half16* (sym+add)@got@dtprel@l */ -#define R_PPC_GOT_DTPREL16_HI 93 /* half16* (sym+add)@got@dtprel@h */ -#define R_PPC_GOT_DTPREL16_HA 94 /* half16* (sym+add)@got@dtprel@ha */ - -/* The remaining relocs are from the Embedded ELF ABI, and are not - in the SVR4 ELF ABI. */ -#define R_PPC_EMB_NADDR32 101 -#define R_PPC_EMB_NADDR16 102 -#define R_PPC_EMB_NADDR16_LO 103 -#define R_PPC_EMB_NADDR16_HI 104 -#define R_PPC_EMB_NADDR16_HA 105 -#define R_PPC_EMB_SDAI16 106 -#define R_PPC_EMB_SDA2I16 107 -#define R_PPC_EMB_SDA2REL 108 -#define R_PPC_EMB_SDA21 109 /* 16 bit offset in SDA */ -#define R_PPC_EMB_MRKREF 110 -#define R_PPC_EMB_RELSEC16 111 -#define R_PPC_EMB_RELST_LO 112 -#define R_PPC_EMB_RELST_HI 113 -#define R_PPC_EMB_RELST_HA 114 -#define R_PPC_EMB_BIT_FLD 115 -#define R_PPC_EMB_RELSDA 116 /* 16 bit relative offset in SDA */ - -/* Diab tool relocations. */ -#define R_PPC_DIAB_SDA21_LO 180 /* like EMB_SDA21, but lower 16 bit */ -#define R_PPC_DIAB_SDA21_HI 181 /* like EMB_SDA21, but high 16 bit */ -#define R_PPC_DIAB_SDA21_HA 182 /* like EMB_SDA21, adjusted high 16 */ -#define R_PPC_DIAB_RELSDA_LO 183 /* like EMB_RELSDA, but lower 16 bit */ -#define R_PPC_DIAB_RELSDA_HI 184 /* like EMB_RELSDA, but high 16 bit */ -#define R_PPC_DIAB_RELSDA_HA 185 /* like EMB_RELSDA, adjusted high 16 */ - -/* GNU extension to support local ifunc. */ -#define R_PPC_IRELATIVE 248 - -/* GNU relocs used in PIC code sequences. */ -#define R_PPC_REL16 249 /* half16 (sym+add-.) */ -#define R_PPC_REL16_LO 250 /* half16 (sym+add-.)@l */ -#define R_PPC_REL16_HI 251 /* half16 (sym+add-.)@h */ -#define R_PPC_REL16_HA 252 /* half16 (sym+add-.)@ha */ - -/* This is a phony reloc to handle any old fashioned TOC16 references - that may still be in object files. */ -#define R_PPC_TOC16 255 - -/* PowerPC specific values for the Dyn d_tag field. */ -#define DT_PPC_GOT (DT_LOPROC + 0) -#define DT_PPC_NUM 1 - -/* PowerPC64 relocations defined by the ABIs */ -#define R_PPC64_NONE R_PPC_NONE -#define R_PPC64_ADDR32 R_PPC_ADDR32 /* 32bit absolute address */ -#define R_PPC64_ADDR24 R_PPC_ADDR24 /* 26bit address, word aligned */ -#define R_PPC64_ADDR16 R_PPC_ADDR16 /* 16bit absolute address */ -#define R_PPC64_ADDR16_LO R_PPC_ADDR16_LO /* lower 16bits of address */ -#define R_PPC64_ADDR16_HI R_PPC_ADDR16_HI /* high 16bits of address. */ -#define R_PPC64_ADDR16_HA R_PPC_ADDR16_HA /* adjusted high 16bits. */ -#define R_PPC64_ADDR14 R_PPC_ADDR14 /* 16bit address, word aligned */ -#define R_PPC64_ADDR14_BRTAKEN R_PPC_ADDR14_BRTAKEN -#define R_PPC64_ADDR14_BRNTAKEN R_PPC_ADDR14_BRNTAKEN -#define R_PPC64_REL24 R_PPC_REL24 /* PC-rel. 26 bit, word aligned */ -#define R_PPC64_REL14 R_PPC_REL14 /* PC relative 16 bit */ -#define R_PPC64_REL14_BRTAKEN R_PPC_REL14_BRTAKEN -#define R_PPC64_REL14_BRNTAKEN R_PPC_REL14_BRNTAKEN -#define R_PPC64_GOT16 R_PPC_GOT16 -#define R_PPC64_GOT16_LO R_PPC_GOT16_LO -#define R_PPC64_GOT16_HI R_PPC_GOT16_HI -#define R_PPC64_GOT16_HA R_PPC_GOT16_HA - -#define R_PPC64_COPY R_PPC_COPY -#define R_PPC64_GLOB_DAT R_PPC_GLOB_DAT -#define R_PPC64_JMP_SLOT R_PPC_JMP_SLOT -#define R_PPC64_RELATIVE R_PPC_RELATIVE - -#define R_PPC64_UADDR32 R_PPC_UADDR32 -#define R_PPC64_UADDR16 R_PPC_UADDR16 -#define R_PPC64_REL32 R_PPC_REL32 -#define R_PPC64_PLT32 R_PPC_PLT32 -#define R_PPC64_PLTREL32 R_PPC_PLTREL32 -#define R_PPC64_PLT16_LO R_PPC_PLT16_LO -#define R_PPC64_PLT16_HI R_PPC_PLT16_HI -#define R_PPC64_PLT16_HA R_PPC_PLT16_HA - -#define R_PPC64_SECTOFF R_PPC_SECTOFF -#define R_PPC64_SECTOFF_LO R_PPC_SECTOFF_LO -#define R_PPC64_SECTOFF_HI R_PPC_SECTOFF_HI -#define R_PPC64_SECTOFF_HA R_PPC_SECTOFF_HA -#define R_PPC64_ADDR30 37 /* word30 (S + A - P) >> 2 */ -#define R_PPC64_ADDR64 38 /* doubleword64 S + A */ -#define R_PPC64_ADDR16_HIGHER 39 /* half16 #higher(S + A) */ -#define R_PPC64_ADDR16_HIGHERA 40 /* half16 #highera(S + A) */ -#define R_PPC64_ADDR16_HIGHEST 41 /* half16 #highest(S + A) */ -#define R_PPC64_ADDR16_HIGHESTA 42 /* half16 #highesta(S + A) */ -#define R_PPC64_UADDR64 43 /* doubleword64 S + A */ -#define R_PPC64_REL64 44 /* doubleword64 S + A - P */ -#define R_PPC64_PLT64 45 /* doubleword64 L + A */ -#define R_PPC64_PLTREL64 46 /* doubleword64 L + A - P */ -#define R_PPC64_TOC16 47 /* half16* S + A - .TOC */ -#define R_PPC64_TOC16_LO 48 /* half16 #lo(S + A - .TOC.) */ -#define R_PPC64_TOC16_HI 49 /* half16 #hi(S + A - .TOC.) */ -#define R_PPC64_TOC16_HA 50 /* half16 #ha(S + A - .TOC.) */ -#define R_PPC64_TOC 51 /* doubleword64 .TOC */ -#define R_PPC64_PLTGOT16 52 /* half16* M + A */ -#define R_PPC64_PLTGOT16_LO 53 /* half16 #lo(M + A) */ -#define R_PPC64_PLTGOT16_HI 54 /* half16 #hi(M + A) */ -#define R_PPC64_PLTGOT16_HA 55 /* half16 #ha(M + A) */ - -#define R_PPC64_ADDR16_DS 56 /* half16ds* (S + A) >> 2 */ -#define R_PPC64_ADDR16_LO_DS 57 /* half16ds #lo(S + A) >> 2 */ -#define R_PPC64_GOT16_DS 58 /* half16ds* (G + A) >> 2 */ -#define R_PPC64_GOT16_LO_DS 59 /* half16ds #lo(G + A) >> 2 */ -#define R_PPC64_PLT16_LO_DS 60 /* half16ds #lo(L + A) >> 2 */ -#define R_PPC64_SECTOFF_DS 61 /* half16ds* (R + A) >> 2 */ -#define R_PPC64_SECTOFF_LO_DS 62 /* half16ds #lo(R + A) >> 2 */ -#define R_PPC64_TOC16_DS 63 /* half16ds* (S + A - .TOC.) >> 2 */ -#define R_PPC64_TOC16_LO_DS 64 /* half16ds #lo(S + A - .TOC.) >> 2 */ -#define R_PPC64_PLTGOT16_DS 65 /* half16ds* (M + A) >> 2 */ -#define R_PPC64_PLTGOT16_LO_DS 66 /* half16ds #lo(M + A) >> 2 */ - -/* PowerPC64 relocations defined for the TLS access ABI. */ -#define R_PPC64_TLS 67 /* none (sym+add)@tls */ -#define R_PPC64_DTPMOD64 68 /* doubleword64 (sym+add)@dtpmod */ -#define R_PPC64_TPREL16 69 /* half16* (sym+add)@tprel */ -#define R_PPC64_TPREL16_LO 70 /* half16 (sym+add)@tprel@l */ -#define R_PPC64_TPREL16_HI 71 /* half16 (sym+add)@tprel@h */ -#define R_PPC64_TPREL16_HA 72 /* half16 (sym+add)@tprel@ha */ -#define R_PPC64_TPREL64 73 /* doubleword64 (sym+add)@tprel */ -#define R_PPC64_DTPREL16 74 /* half16* (sym+add)@dtprel */ -#define R_PPC64_DTPREL16_LO 75 /* half16 (sym+add)@dtprel@l */ -#define R_PPC64_DTPREL16_HI 76 /* half16 (sym+add)@dtprel@h */ -#define R_PPC64_DTPREL16_HA 77 /* half16 (sym+add)@dtprel@ha */ -#define R_PPC64_DTPREL64 78 /* doubleword64 (sym+add)@dtprel */ -#define R_PPC64_GOT_TLSGD16 79 /* half16* (sym+add)@got@tlsgd */ -#define R_PPC64_GOT_TLSGD16_LO 80 /* half16 (sym+add)@got@tlsgd@l */ -#define R_PPC64_GOT_TLSGD16_HI 81 /* half16 (sym+add)@got@tlsgd@h */ -#define R_PPC64_GOT_TLSGD16_HA 82 /* half16 (sym+add)@got@tlsgd@ha */ -#define R_PPC64_GOT_TLSLD16 83 /* half16* (sym+add)@got@tlsld */ -#define R_PPC64_GOT_TLSLD16_LO 84 /* half16 (sym+add)@got@tlsld@l */ -#define R_PPC64_GOT_TLSLD16_HI 85 /* half16 (sym+add)@got@tlsld@h */ -#define R_PPC64_GOT_TLSLD16_HA 86 /* half16 (sym+add)@got@tlsld@ha */ -#define R_PPC64_GOT_TPREL16_DS 87 /* half16ds* (sym+add)@got@tprel */ -#define R_PPC64_GOT_TPREL16_LO_DS 88 /* half16ds (sym+add)@got@tprel@l */ -#define R_PPC64_GOT_TPREL16_HI 89 /* half16 (sym+add)@got@tprel@h */ -#define R_PPC64_GOT_TPREL16_HA 90 /* half16 (sym+add)@got@tprel@ha */ -#define R_PPC64_GOT_DTPREL16_DS 91 /* half16ds* (sym+add)@got@dtprel */ -#define R_PPC64_GOT_DTPREL16_LO_DS 92 /* half16ds (sym+add)@got@dtprel@l */ -#define R_PPC64_GOT_DTPREL16_HI 93 /* half16 (sym+add)@got@dtprel@h */ -#define R_PPC64_GOT_DTPREL16_HA 94 /* half16 (sym+add)@got@dtprel@ha */ -#define R_PPC64_TPREL16_DS 95 /* half16ds* (sym+add)@tprel */ -#define R_PPC64_TPREL16_LO_DS 96 /* half16ds (sym+add)@tprel@l */ -#define R_PPC64_TPREL16_HIGHER 97 /* half16 (sym+add)@tprel@higher */ -#define R_PPC64_TPREL16_HIGHERA 98 /* half16 (sym+add)@tprel@highera */ -#define R_PPC64_TPREL16_HIGHEST 99 /* half16 (sym+add)@tprel@highest */ -#define R_PPC64_TPREL16_HIGHESTA 100 /* half16 (sym+add)@tprel@highesta */ -#define R_PPC64_DTPREL16_DS 101 /* half16ds* (sym+add)@dtprel */ -#define R_PPC64_DTPREL16_LO_DS 102 /* half16ds (sym+add)@dtprel@l */ -#define R_PPC64_DTPREL16_HIGHER 103 /* half16 (sym+add)@dtprel@higher */ -#define R_PPC64_DTPREL16_HIGHERA 104 /* half16 (sym+add)@dtprel@highera */ -#define R_PPC64_DTPREL16_HIGHEST 105 /* half16 (sym+add)@dtprel@highest */ -#define R_PPC64_DTPREL16_HIGHESTA 106 /* half16 (sym+add)@dtprel@highesta */ - -/* GNU extension to support local ifunc. */ -#define R_PPC64_JMP_IREL 247 -#define R_PPC64_IRELATIVE 248 -#define R_PPC64_REL16 249 /* half16 (sym+add-.) */ -#define R_PPC64_REL16_LO 250 /* half16 (sym+add-.)@l */ -#define R_PPC64_REL16_HI 251 /* half16 (sym+add-.)@h */ -#define R_PPC64_REL16_HA 252 /* half16 (sym+add-.)@ha */ - -/* PowerPC64 specific values for the Dyn d_tag field. */ -#define DT_PPC64_GLINK (DT_LOPROC + 0) -#define DT_PPC64_OPD (DT_LOPROC + 1) -#define DT_PPC64_OPDSZ (DT_LOPROC + 2) -#define DT_PPC64_NUM 3 - - -/* ARM specific declarations */ - -/* Processor specific flags for the ELF header e_flags field. */ -#define EF_ARM_RELEXEC 0x01 -#define EF_ARM_HASENTRY 0x02 -#define EF_ARM_INTERWORK 0x04 -#define EF_ARM_APCS_26 0x08 -#define EF_ARM_APCS_FLOAT 0x10 -#define EF_ARM_PIC 0x20 -#define EF_ARM_ALIGN8 0x40 /* 8-bit structure alignment is in use */ -#define EF_ARM_NEW_ABI 0x80 -#define EF_ARM_OLD_ABI 0x100 -#define EF_ARM_SOFT_FLOAT 0x200 -#define EF_ARM_VFP_FLOAT 0x400 -#define EF_ARM_MAVERICK_FLOAT 0x800 - -#define EF_ARM_ABI_FLOAT_SOFT 0x200 /* NB conflicts with EF_ARM_SOFT_FLOAT */ -#define EF_ARM_ABI_FLOAT_HARD 0x400 /* NB conflicts with EF_ARM_VFP_FLOAT */ - - -/* Other constants defined in the ARM ELF spec. version B-01. */ -/* NB. These conflict with values defined above. */ -#define EF_ARM_SYMSARESORTED 0x04 -#define EF_ARM_DYNSYMSUSESEGIDX 0x08 -#define EF_ARM_MAPSYMSFIRST 0x10 -#define EF_ARM_EABIMASK 0XFF000000 - -/* Constants defined in AAELF. */ -#define EF_ARM_BE8 0x00800000 -#define EF_ARM_LE8 0x00400000 - -#define EF_ARM_EABI_VERSION(flags) ((flags) & EF_ARM_EABIMASK) -#define EF_ARM_EABI_UNKNOWN 0x00000000 -#define EF_ARM_EABI_VER1 0x01000000 -#define EF_ARM_EABI_VER2 0x02000000 -#define EF_ARM_EABI_VER3 0x03000000 -#define EF_ARM_EABI_VER4 0x04000000 -#define EF_ARM_EABI_VER5 0x05000000 - -/* Additional symbol types for Thumb. */ -#define STT_ARM_TFUNC STT_LOPROC /* A Thumb function. */ -#define STT_ARM_16BIT STT_HIPROC /* A Thumb label. */ - -/* ARM-specific values for sh_flags */ -#define SHF_ARM_ENTRYSECT 0x10000000 /* Section contains an entry point */ -#define SHF_ARM_COMDEF 0x80000000 /* Section may be multiply defined - in the input to a link step. */ - -/* ARM-specific program header flags */ -#define PF_ARM_SB 0x10000000 /* Segment contains the location - addressed by the static base. */ -#define PF_ARM_PI 0x20000000 /* Position-independent segment. */ -#define PF_ARM_ABS 0x40000000 /* Absolute segment. */ - -/* Processor specific values for the Phdr p_type field. */ -#define PT_ARM_EXIDX (PT_LOPROC + 1) /* ARM unwind segment. */ - -/* Processor specific values for the Shdr sh_type field. */ -#define SHT_ARM_EXIDX (SHT_LOPROC + 1) /* ARM unwind section. */ -#define SHT_ARM_PREEMPTMAP (SHT_LOPROC + 2) /* Preemption details. */ -#define SHT_ARM_ATTRIBUTES (SHT_LOPROC + 3) /* ARM attributes section. */ - - -/* AArch64 relocs. */ - -#define R_AARCH64_NONE 0 /* No relocation. */ -#define R_AARCH64_ABS64 257 /* Direct 64 bit. */ -#define R_AARCH64_ABS32 258 /* Direct 32 bit. */ -#define R_AARCH64_ABS16 259 /* Direct 16-bit. */ -#define R_AARCH64_PREL64 260 /* PC-relative 64-bit. */ -#define R_AARCH64_PREL32 261 /* PC-relative 32-bit. */ -#define R_AARCH64_PREL16 262 /* PC-relative 16-bit. */ -#define R_AARCH64_MOVW_UABS_G0 263 /* Dir. MOVZ imm. from bits 15:0. */ -#define R_AARCH64_MOVW_UABS_G0_NC 264 /* Likewise for MOVK; no check. */ -#define R_AARCH64_MOVW_UABS_G1 265 /* Dir. MOVZ imm. from bits 31:16. */ -#define R_AARCH64_MOVW_UABS_G1_NC 266 /* Likewise for MOVK; no check. */ -#define R_AARCH64_MOVW_UABS_G2 267 /* Dir. MOVZ imm. from bits 47:32. */ -#define R_AARCH64_MOVW_UABS_G2_NC 268 /* Likewise for MOVK; no check. */ -#define R_AARCH64_MOVW_UABS_G3 269 /* Dir. MOV{K,Z} imm. from 63:48. */ -#define R_AARCH64_MOVW_SABS_G0 270 /* Dir. MOV{N,Z} imm. from 15:0. */ -#define R_AARCH64_MOVW_SABS_G1 271 /* Dir. MOV{N,Z} imm. from 31:16. */ -#define R_AARCH64_MOVW_SABS_G2 272 /* Dir. MOV{N,Z} imm. from 47:32. */ -#define R_AARCH64_LD_PREL_LO19 273 /* PC-rel. LD imm. from bits 20:2. */ -#define R_AARCH64_ADR_PREL_LO21 274 /* PC-rel. ADR imm. from bits 20:0. */ -#define R_AARCH64_ADR_PREL_PG_HI21 275 /* Page-rel. ADRP imm. from 32:12. */ -#define R_AARCH64_ADR_PREL_PG_HI21_NC 276 /* Likewise; no overflow check. */ -#define R_AARCH64_ADD_ABS_LO12_NC 277 /* Dir. ADD imm. from bits 11:0. */ -#define R_AARCH64_LDST8_ABS_LO12_NC 278 /* Likewise for LD/ST; no check. */ -#define R_AARCH64_TSTBR14 279 /* PC-rel. TBZ/TBNZ imm. from 15:2. */ -#define R_AARCH64_CONDBR19 280 /* PC-rel. cond. br. imm. from 20:2. */ -#define R_AARCH64_JUMP26 282 /* PC-rel. B imm. from bits 27:2. */ -#define R_AARCH64_CALL26 283 /* Likewise for CALL. */ -#define R_AARCH64_LDST16_ABS_LO12_NC 284 /* Dir. ADD imm. from bits 11:1. */ -#define R_AARCH64_LDST32_ABS_LO12_NC 285 /* Likewise for bits 11:2. */ -#define R_AARCH64_LDST64_ABS_LO12_NC 286 /* Likewise for bits 11:3. */ -#define R_AARCH64_MOVW_PREL_G0 287 /* PC-rel. MOV{N,Z} imm. from 15:0. */ -#define R_AARCH64_MOVW_PREL_G0_NC 288 /* Likewise for MOVK; no check. */ -#define R_AARCH64_MOVW_PREL_G1 289 /* PC-rel. MOV{N,Z} imm. from 31:16. */ -#define R_AARCH64_MOVW_PREL_G1_NC 290 /* Likewise for MOVK; no check. */ -#define R_AARCH64_MOVW_PREL_G2 291 /* PC-rel. MOV{N,Z} imm. from 47:32. */ -#define R_AARCH64_MOVW_PREL_G2_NC 292 /* Likewise for MOVK; no check. */ -#define R_AARCH64_MOVW_PREL_G3 293 /* PC-rel. MOV{N,Z} imm. from 63:48. */ -#define R_AARCH64_LDST128_ABS_LO12_NC 299 /* Dir. ADD imm. from bits 11:4. */ -#define R_AARCH64_MOVW_GOTOFF_G0 300 /* GOT-rel. off. MOV{N,Z} imm. 15:0. */ -#define R_AARCH64_MOVW_GOTOFF_G0_NC 301 /* Likewise for MOVK; no check. */ -#define R_AARCH64_MOVW_GOTOFF_G1 302 /* GOT-rel. o. MOV{N,Z} imm. 31:16. */ -#define R_AARCH64_MOVW_GOTOFF_G1_NC 303 /* Likewise for MOVK; no check. */ -#define R_AARCH64_MOVW_GOTOFF_G2 304 /* GOT-rel. o. MOV{N,Z} imm. 47:32. */ -#define R_AARCH64_MOVW_GOTOFF_G2_NC 305 /* Likewise for MOVK; no check. */ -#define R_AARCH64_MOVW_GOTOFF_G3 306 /* GOT-rel. o. MOV{N,Z} imm. 63:48. */ -#define R_AARCH64_GOTREL64 307 /* GOT-relative 64-bit. */ -#define R_AARCH64_GOTREL32 308 /* GOT-relative 32-bit. */ -#define R_AARCH64_GOT_LD_PREL19 309 /* PC-rel. GOT off. load imm. 20:2. */ -#define R_AARCH64_LD64_GOTOFF_LO15 310 /* GOT-rel. off. LD/ST imm. 14:3. */ -#define R_AARCH64_ADR_GOT_PAGE 311 /* P-page-rel. GOT off. ADRP 32:12. */ -#define R_AARCH64_LD64_GOT_LO12_NC 312 /* Dir. GOT off. LD/ST imm. 11:3. */ -#define R_AARCH64_LD64_GOTPAGE_LO15 313 /* GOT-page-rel. GOT off. LD/ST 14:3 */ -#define R_AARCH64_TLSGD_ADR_PREL21 512 /* PC-relative ADR imm. 20:0. */ -#define R_AARCH64_TLSGD_ADR_PAGE21 513 /* page-rel. ADRP imm. 32:12. */ -#define R_AARCH64_TLSGD_ADD_LO12_NC 514 /* direct ADD imm. from 11:0. */ -#define R_AARCH64_TLSGD_MOVW_G1 515 /* GOT-rel. MOV{N,Z} 31:16. */ -#define R_AARCH64_TLSGD_MOVW_G0_NC 516 /* GOT-rel. MOVK imm. 15:0. */ -#define R_AARCH64_TLSLD_ADR_PREL21 517 /* Like 512; local dynamic model. */ -#define R_AARCH64_TLSLD_ADR_PAGE21 518 /* Like 513; local dynamic model. */ -#define R_AARCH64_TLSLD_ADD_LO12_NC 519 /* Like 514; local dynamic model. */ -#define R_AARCH64_TLSLD_MOVW_G1 520 /* Like 515; local dynamic model. */ -#define R_AARCH64_TLSLD_MOVW_G0_NC 521 /* Like 516; local dynamic model. */ -#define R_AARCH64_TLSLD_LD_PREL19 522 /* TLS PC-rel. load imm. 20:2. */ -#define R_AARCH64_TLSLD_MOVW_DTPREL_G2 523 /* TLS DTP-rel. MOV{N,Z} 47:32. */ -#define R_AARCH64_TLSLD_MOVW_DTPREL_G1 524 /* TLS DTP-rel. MOV{N,Z} 31:16. */ -#define R_AARCH64_TLSLD_MOVW_DTPREL_G1_NC 525 /* Likewise; MOVK; no check. */ -#define R_AARCH64_TLSLD_MOVW_DTPREL_G0 526 /* TLS DTP-rel. MOV{N,Z} 15:0. */ -#define R_AARCH64_TLSLD_MOVW_DTPREL_G0_NC 527 /* Likewise; MOVK; no check. */ -#define R_AARCH64_TLSLD_ADD_DTPREL_HI12 528 /* DTP-rel. ADD imm. from 23:12. */ -#define R_AARCH64_TLSLD_ADD_DTPREL_LO12 529 /* DTP-rel. ADD imm. from 11:0. */ -#define R_AARCH64_TLSLD_ADD_DTPREL_LO12_NC 530 /* Likewise; no ovfl. check. */ -#define R_AARCH64_TLSLD_LDST8_DTPREL_LO12 531 /* DTP-rel. LD/ST imm. 11:0. */ -#define R_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC 532 /* Likewise; no check. */ -#define R_AARCH64_TLSLD_LDST16_DTPREL_LO12 533 /* DTP-rel. LD/ST imm. 11:1. */ -#define R_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC 534 /* Likewise; no check. */ -#define R_AARCH64_TLSLD_LDST32_DTPREL_LO12 535 /* DTP-rel. LD/ST imm. 11:2. */ -#define R_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC 536 /* Likewise; no check. */ -#define R_AARCH64_TLSLD_LDST64_DTPREL_LO12 537 /* DTP-rel. LD/ST imm. 11:3. */ -#define R_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC 538 /* Likewise; no check. */ -#define R_AARCH64_TLSIE_MOVW_GOTTPREL_G1 539 /* GOT-rel. MOV{N,Z} 31:16. */ -#define R_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC 540 /* GOT-rel. MOVK 15:0. */ -#define R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 541 /* Page-rel. ADRP 32:12. */ -#define R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC 542 /* Direct LD off. 11:3. */ -#define R_AARCH64_TLSIE_LD_GOTTPREL_PREL19 543 /* PC-rel. load imm. 20:2. */ -#define R_AARCH64_TLSLE_MOVW_TPREL_G2 544 /* TLS TP-rel. MOV{N,Z} 47:32. */ -#define R_AARCH64_TLSLE_MOVW_TPREL_G1 545 /* TLS TP-rel. MOV{N,Z} 31:16. */ -#define R_AARCH64_TLSLE_MOVW_TPREL_G1_NC 546 /* Likewise; MOVK; no check. */ -#define R_AARCH64_TLSLE_MOVW_TPREL_G0 547 /* TLS TP-rel. MOV{N,Z} 15:0. */ -#define R_AARCH64_TLSLE_MOVW_TPREL_G0_NC 548 /* Likewise; MOVK; no check. */ -#define R_AARCH64_TLSLE_ADD_TPREL_HI12 549 /* TP-rel. ADD imm. 23:12. */ -#define R_AARCH64_TLSLE_ADD_TPREL_LO12 550 /* TP-rel. ADD imm. 11:0. */ -#define R_AARCH64_TLSLE_ADD_TPREL_LO12_NC 551 /* Likewise; no ovfl. check. */ -#define R_AARCH64_TLSLE_LDST8_TPREL_LO12 552 /* TP-rel. LD/ST off. 11:0. */ -#define R_AARCH64_TLSLE_LDST8_TPREL_LO12_NC 553 /* Likewise; no ovfl. check. */ -#define R_AARCH64_TLSLE_LDST16_TPREL_LO12 554 /* TP-rel. LD/ST off. 11:1. */ -#define R_AARCH64_TLSLE_LDST16_TPREL_LO12_NC 555 /* Likewise; no check. */ -#define R_AARCH64_TLSLE_LDST32_TPREL_LO12 556 /* TP-rel. LD/ST off. 11:2. */ -#define R_AARCH64_TLSLE_LDST32_TPREL_LO12_NC 557 /* Likewise; no check. */ -#define R_AARCH64_TLSLE_LDST64_TPREL_LO12 558 /* TP-rel. LD/ST off. 11:3. */ -#define R_AARCH64_TLSLE_LDST64_TPREL_LO12_NC 559 /* Likewise; no check. */ -#define R_AARCH64_TLSDESC_LD_PREL19 560 /* PC-rel. load immediate 20:2. */ -#define R_AARCH64_TLSDESC_ADR_PREL21 561 /* PC-rel. ADR immediate 20:0. */ -#define R_AARCH64_TLSDESC_ADR_PAGE21 562 /* Page-rel. ADRP imm. 32:12. */ -#define R_AARCH64_TLSDESC_LD64_LO12 563 /* Direct LD off. from 11:3. */ -#define R_AARCH64_TLSDESC_ADD_LO12 564 /* Direct ADD imm. from 11:0. */ -#define R_AARCH64_TLSDESC_OFF_G1 565 /* GOT-rel. MOV{N,Z} imm. 31:16. */ -#define R_AARCH64_TLSDESC_OFF_G0_NC 566 /* GOT-rel. MOVK imm. 15:0; no ck. */ -#define R_AARCH64_TLSDESC_LDR 567 /* Relax LDR. */ -#define R_AARCH64_TLSDESC_ADD 568 /* Relax ADD. */ -#define R_AARCH64_TLSDESC_CALL 569 /* Relax BLR. */ -#define R_AARCH64_TLSLE_LDST128_TPREL_LO12 570 /* TP-rel. LD/ST off. 11:4. */ -#define R_AARCH64_TLSLE_LDST128_TPREL_LO12_NC 571 /* Likewise; no check. */ -#define R_AARCH64_TLSLD_LDST128_DTPREL_LO12 572 /* DTP-rel. LD/ST imm. 11:4. */ -#define R_AARCH64_TLSLD_LDST128_DTPREL_LO12_NC 573 /* Likewise; no check. */ -#define R_AARCH64_COPY 1024 /* Copy symbol at runtime. */ -#define R_AARCH64_GLOB_DAT 1025 /* Create GOT entry. */ -#define R_AARCH64_JUMP_SLOT 1026 /* Create PLT entry. */ -#define R_AARCH64_RELATIVE 1027 /* Adjust by program base. */ -#define R_AARCH64_TLS_DTPMOD64 1028 /* Module number, 64 bit. */ -#define R_AARCH64_TLS_DTPREL64 1029 /* Module-relative offset, 64 bit. */ -#define R_AARCH64_TLS_TPREL64 1030 /* TP-relative offset, 64 bit. */ -#define R_AARCH64_TLSDESC 1031 /* TLS Descriptor. */ -#define R_AARCH64_IRELATIVE 1032 /* STT_GNU_IFUNC relocation. */ -/* Keep this the last entry. */ -#define R_AARCH64_NUM 1033 - -/* ARM relocs. */ - -#define R_ARM_NONE 0 /* No reloc */ -#define R_ARM_PC24 1 /* PC relative 26 bit branch */ -#define R_ARM_ABS32 2 /* Direct 32 bit */ -#define R_ARM_REL32 3 /* PC relative 32 bit */ -#define R_ARM_PC13 4 -#define R_ARM_ABS16 5 /* Direct 16 bit */ -#define R_ARM_ABS12 6 /* Direct 12 bit */ -#define R_ARM_THM_ABS5 7 -#define R_ARM_ABS8 8 /* Direct 8 bit */ -#define R_ARM_SBREL32 9 -#define R_ARM_THM_PC22 10 -#define R_ARM_THM_PC8 11 -#define R_ARM_AMP_VCALL9 12 -#define R_ARM_SWI24 13 /* Obsolete static relocation. */ -#define R_ARM_TLS_DESC 13 /* Dynamic relocation. */ -#define R_ARM_THM_SWI8 14 -#define R_ARM_XPC25 15 -#define R_ARM_THM_XPC22 16 -#define R_ARM_TLS_DTPMOD32 17 /* ID of module containing symbol */ -#define R_ARM_TLS_DTPOFF32 18 /* Offset in TLS block */ -#define R_ARM_TLS_TPOFF32 19 /* Offset in static TLS block */ -#define R_ARM_COPY 20 /* Copy symbol at runtime */ -#define R_ARM_GLOB_DAT 21 /* Create GOT entry */ -#define R_ARM_JUMP_SLOT 22 /* Create PLT entry */ -#define R_ARM_RELATIVE 23 /* Adjust by program base */ -#define R_ARM_GOTOFF 24 /* 32 bit offset to GOT */ -#define R_ARM_GOTPC 25 /* 32 bit PC relative offset to GOT */ -#define R_ARM_GOT32 26 /* 32 bit GOT entry */ -#define R_ARM_PLT32 27 /* 32 bit PLT address */ -#define R_ARM_CALL 28 -#define R_ARM_JUMP24 29 -#define R_ARM_THM_JUMP24 30 -#define R_ARM_ALU_PCREL_7_0 32 -#define R_ARM_ALU_PCREL_15_8 33 -#define R_ARM_ALU_PCREL_23_15 34 -#define R_ARM_LDR_SBREL_11_0 35 -#define R_ARM_ALU_SBREL_19_12 36 -#define R_ARM_ALU_SBREL_27_20 37 -#define R_ARM_V4BX 40 -#define R_ARM_PREL31 42 -#define R_ARM_MOVW_ABS_NC 43 -#define R_ARM_MOVT_ABS 44 -#define R_ARM_THM_MOVW_ABS_NC 47 -#define R_ARM_THM_MOVT_ABS 48 -#define R_ARM_TLS_GOTDESC 90 -#define R_ARM_TLS_CALL 91 -#define R_ARM_TLS_DESCSEQ 92 -#define R_ARM_THM_TLS_CALL 93 -#define R_ARM_GNU_VTENTRY 100 -#define R_ARM_GNU_VTINHERIT 101 -#define R_ARM_THM_PC11 102 /* thumb unconditional branch */ -#define R_ARM_THM_PC9 103 /* thumb conditional branch */ -#define R_ARM_TLS_GD32 104 /* PC-rel 32 bit for global dynamic - thread local data */ -#define R_ARM_TLS_LDM32 105 /* PC-rel 32 bit for local dynamic - thread local data */ -#define R_ARM_TLS_LDO32 106 /* 32 bit offset relative to TLS - block */ -#define R_ARM_TLS_IE32 107 /* PC-rel 32 bit for GOT entry of - static TLS block offset */ -#define R_ARM_TLS_LE32 108 /* 32 bit offset relative to static - TLS block */ -#define R_ARM_THM_TLS_DESCSEQ 129 -#define R_ARM_IRELATIVE 160 -#define R_ARM_RXPC25 249 -#define R_ARM_RSBREL32 250 -#define R_ARM_THM_RPC22 251 -#define R_ARM_RREL32 252 -#define R_ARM_RABS22 253 -#define R_ARM_RPC24 254 -#define R_ARM_RBASE 255 -/* Keep this the last entry. */ -#define R_ARM_NUM 256 - -/* TMS320C67xx specific declarations */ - -/* XXX: no ELF standard yet*/ - -/* TMS320C67xx relocs. */ -#define R_C60_32 1 -#define R_C60_GOT32 3 /* 32 bit GOT entry */ -#define R_C60_PLT32 4 /* 32 bit PLT address */ -#define R_C60_COPY 5 /* Copy symbol at runtime */ -#define R_C60_GLOB_DAT 6 /* Create GOT entry */ -#define R_C60_JMP_SLOT 7 /* Create PLT entry */ -#define R_C60_RELATIVE 8 /* Adjust by program base */ -#define R_C60_GOTOFF 9 /* 32 bit offset to GOT */ -#define R_C60_GOTPC 10 /* 32 bit PC relative offset to GOT */ - -#define R_C60LO16 0x54 /* low 16 bit MVKL embedded */ -#define R_C60HI16 0x55 /* high 16 bit MVKH embedded */ -/* Keep this the last entry. */ -#define R_C60_NUM 0x56 - -/* IA-64 specific declarations. */ - -/* Processor specific flags for the Ehdr e_flags field. */ -#define EF_IA_64_MASKOS 0x0000000f /* os-specific flags */ -#define EF_IA_64_ABI64 0x00000010 /* 64-bit ABI */ -#define EF_IA_64_ARCH 0xff000000 /* arch. version mask */ - -/* Processor specific values for the Phdr p_type field. */ -#define PT_IA_64_ARCHEXT (PT_LOPROC + 0) /* arch extension bits */ -#define PT_IA_64_UNWIND (PT_LOPROC + 1) /* ia64 unwind bits */ -#define PT_IA_64_HP_OPT_ANOT (PT_LOOS + 0x12) -#define PT_IA_64_HP_HSL_ANOT (PT_LOOS + 0x13) -#define PT_IA_64_HP_STACK (PT_LOOS + 0x14) - -/* Processor specific flags for the Phdr p_flags field. */ -#define PF_IA_64_NORECOV 0x80000000 /* spec insns w/o recovery */ - -/* Processor specific values for the Shdr sh_type field. */ -#define SHT_IA_64_EXT (SHT_LOPROC + 0) /* extension bits */ -#define SHT_IA_64_UNWIND (SHT_LOPROC + 1) /* unwind bits */ - -/* Processor specific flags for the Shdr sh_flags field. */ -#define SHF_IA_64_SHORT 0x10000000 /* section near gp */ -#define SHF_IA_64_NORECOV 0x20000000 /* spec insns w/o recovery */ - -/* Processor specific values for the Dyn d_tag field. */ -#define DT_IA_64_PLT_RESERVE (DT_LOPROC + 0) -#define DT_IA_64_NUM 1 - -/* IA-64 relocations. */ -#define R_IA64_NONE 0x00 /* none */ -#define R_IA64_IMM14 0x21 /* symbol + addend, add imm14 */ -#define R_IA64_IMM22 0x22 /* symbol + addend, add imm22 */ -#define R_IA64_IMM64 0x23 /* symbol + addend, mov imm64 */ -#define R_IA64_DIR32MSB 0x24 /* symbol + addend, data4 MSB */ -#define R_IA64_DIR32LSB 0x25 /* symbol + addend, data4 LSB */ -#define R_IA64_DIR64MSB 0x26 /* symbol + addend, data8 MSB */ -#define R_IA64_DIR64LSB 0x27 /* symbol + addend, data8 LSB */ -#define R_IA64_GPREL22 0x2a /* @gprel(sym + add), add imm22 */ -#define R_IA64_GPREL64I 0x2b /* @gprel(sym + add), mov imm64 */ -#define R_IA64_GPREL32MSB 0x2c /* @gprel(sym + add), data4 MSB */ -#define R_IA64_GPREL32LSB 0x2d /* @gprel(sym + add), data4 LSB */ -#define R_IA64_GPREL64MSB 0x2e /* @gprel(sym + add), data8 MSB */ -#define R_IA64_GPREL64LSB 0x2f /* @gprel(sym + add), data8 LSB */ -#define R_IA64_LTOFF22 0x32 /* @ltoff(sym + add), add imm22 */ -#define R_IA64_LTOFF64I 0x33 /* @ltoff(sym + add), mov imm64 */ -#define R_IA64_PLTOFF22 0x3a /* @pltoff(sym + add), add imm22 */ -#define R_IA64_PLTOFF64I 0x3b /* @pltoff(sym + add), mov imm64 */ -#define R_IA64_PLTOFF64MSB 0x3e /* @pltoff(sym + add), data8 MSB */ -#define R_IA64_PLTOFF64LSB 0x3f /* @pltoff(sym + add), data8 LSB */ -#define R_IA64_FPTR64I 0x43 /* @fptr(sym + add), mov imm64 */ -#define R_IA64_FPTR32MSB 0x44 /* @fptr(sym + add), data4 MSB */ -#define R_IA64_FPTR32LSB 0x45 /* @fptr(sym + add), data4 LSB */ -#define R_IA64_FPTR64MSB 0x46 /* @fptr(sym + add), data8 MSB */ -#define R_IA64_FPTR64LSB 0x47 /* @fptr(sym + add), data8 LSB */ -#define R_IA64_PCREL60B 0x48 /* @pcrel(sym + add), brl */ -#define R_IA64_PCREL21B 0x49 /* @pcrel(sym + add), ptb, call */ -#define R_IA64_PCREL21M 0x4a /* @pcrel(sym + add), chk.s */ -#define R_IA64_PCREL21F 0x4b /* @pcrel(sym + add), fchkf */ -#define R_IA64_PCREL32MSB 0x4c /* @pcrel(sym + add), data4 MSB */ -#define R_IA64_PCREL32LSB 0x4d /* @pcrel(sym + add), data4 LSB */ -#define R_IA64_PCREL64MSB 0x4e /* @pcrel(sym + add), data8 MSB */ -#define R_IA64_PCREL64LSB 0x4f /* @pcrel(sym + add), data8 LSB */ -#define R_IA64_LTOFF_FPTR22 0x52 /* @ltoff(@fptr(s+a)), imm22 */ -#define R_IA64_LTOFF_FPTR64I 0x53 /* @ltoff(@fptr(s+a)), imm64 */ -#define R_IA64_LTOFF_FPTR32MSB 0x54 /* @ltoff(@fptr(s+a)), data4 MSB */ -#define R_IA64_LTOFF_FPTR32LSB 0x55 /* @ltoff(@fptr(s+a)), data4 LSB */ -#define R_IA64_LTOFF_FPTR64MSB 0x56 /* @ltoff(@fptr(s+a)), data8 MSB */ -#define R_IA64_LTOFF_FPTR64LSB 0x57 /* @ltoff(@fptr(s+a)), data8 LSB */ -#define R_IA64_SEGREL32MSB 0x5c /* @segrel(sym + add), data4 MSB */ -#define R_IA64_SEGREL32LSB 0x5d /* @segrel(sym + add), data4 LSB */ -#define R_IA64_SEGREL64MSB 0x5e /* @segrel(sym + add), data8 MSB */ -#define R_IA64_SEGREL64LSB 0x5f /* @segrel(sym + add), data8 LSB */ -#define R_IA64_SECREL32MSB 0x64 /* @secrel(sym + add), data4 MSB */ -#define R_IA64_SECREL32LSB 0x65 /* @secrel(sym + add), data4 LSB */ -#define R_IA64_SECREL64MSB 0x66 /* @secrel(sym + add), data8 MSB */ -#define R_IA64_SECREL64LSB 0x67 /* @secrel(sym + add), data8 LSB */ -#define R_IA64_REL32MSB 0x6c /* data 4 + REL */ -#define R_IA64_REL32LSB 0x6d /* data 4 + REL */ -#define R_IA64_REL64MSB 0x6e /* data 8 + REL */ -#define R_IA64_REL64LSB 0x6f /* data 8 + REL */ -#define R_IA64_LTV32MSB 0x74 /* symbol + addend, data4 MSB */ -#define R_IA64_LTV32LSB 0x75 /* symbol + addend, data4 LSB */ -#define R_IA64_LTV64MSB 0x76 /* symbol + addend, data8 MSB */ -#define R_IA64_LTV64LSB 0x77 /* symbol + addend, data8 LSB */ -#define R_IA64_PCREL21BI 0x79 /* @pcrel(sym + add), 21bit inst */ -#define R_IA64_PCREL22 0x7a /* @pcrel(sym + add), 22bit inst */ -#define R_IA64_PCREL64I 0x7b /* @pcrel(sym + add), 64bit inst */ -#define R_IA64_IPLTMSB 0x80 /* dynamic reloc, imported PLT, MSB */ -#define R_IA64_IPLTLSB 0x81 /* dynamic reloc, imported PLT, LSB */ -#define R_IA64_COPY 0x84 /* copy relocation */ -#define R_IA64_SUB 0x85 /* Addend and symbol difference */ -#define R_IA64_LTOFF22X 0x86 /* LTOFF22, relaxable. */ -#define R_IA64_LDXMOV 0x87 /* Use of LTOFF22X. */ -#define R_IA64_TPREL14 0x91 /* @tprel(sym + add), imm14 */ -#define R_IA64_TPREL22 0x92 /* @tprel(sym + add), imm22 */ -#define R_IA64_TPREL64I 0x93 /* @tprel(sym + add), imm64 */ -#define R_IA64_TPREL64MSB 0x96 /* @tprel(sym + add), data8 MSB */ -#define R_IA64_TPREL64LSB 0x97 /* @tprel(sym + add), data8 LSB */ -#define R_IA64_LTOFF_TPREL22 0x9a /* @ltoff(@tprel(s+a)), imm2 */ -#define R_IA64_DTPMOD64MSB 0xa6 /* @dtpmod(sym + add), data8 MSB */ -#define R_IA64_DTPMOD64LSB 0xa7 /* @dtpmod(sym + add), data8 LSB */ -#define R_IA64_LTOFF_DTPMOD22 0xaa /* @ltoff(@dtpmod(sym + add)), imm22 */ -#define R_IA64_DTPREL14 0xb1 /* @dtprel(sym + add), imm14 */ -#define R_IA64_DTPREL22 0xb2 /* @dtprel(sym + add), imm22 */ -#define R_IA64_DTPREL64I 0xb3 /* @dtprel(sym + add), imm64 */ -#define R_IA64_DTPREL32MSB 0xb4 /* @dtprel(sym + add), data4 MSB */ -#define R_IA64_DTPREL32LSB 0xb5 /* @dtprel(sym + add), data4 LSB */ -#define R_IA64_DTPREL64MSB 0xb6 /* @dtprel(sym + add), data8 MSB */ -#define R_IA64_DTPREL64LSB 0xb7 /* @dtprel(sym + add), data8 LSB */ -#define R_IA64_LTOFF_DTPREL22 0xba /* @ltoff(@dtprel(s+a)), imm22 */ - -/* SH specific declarations */ - -/* Processor specific flags for the ELF header e_flags field. */ -#define EF_SH_MACH_MASK 0x1f -#define EF_SH_UNKNOWN 0x0 -#define EF_SH1 0x1 -#define EF_SH2 0x2 -#define EF_SH3 0x3 -#define EF_SH_DSP 0x4 -#define EF_SH3_DSP 0x5 -#define EF_SH4AL_DSP 0x6 -#define EF_SH3E 0x8 -#define EF_SH4 0x9 -#define EF_SH2E 0xb -#define EF_SH4A 0xc -#define EF_SH2A 0xd -#define EF_SH4_NOFPU 0x10 -#define EF_SH4A_NOFPU 0x11 -#define EF_SH4_NOMMU_NOFPU 0x12 -#define EF_SH2A_NOFPU 0x13 -#define EF_SH3_NOMMU 0x14 -#define EF_SH2A_SH4_NOFPU 0x15 -#define EF_SH2A_SH3_NOFPU 0x16 -#define EF_SH2A_SH4 0x17 -#define EF_SH2A_SH3E 0x18 - -/* SH relocs. */ -#define R_SH_NONE 0 -#define R_SH_DIR32 1 -#define R_SH_REL32 2 -#define R_SH_DIR8WPN 3 -#define R_SH_IND12W 4 -#define R_SH_DIR8WPL 5 -#define R_SH_DIR8WPZ 6 -#define R_SH_DIR8BP 7 -#define R_SH_DIR8W 8 -#define R_SH_DIR8L 9 -#define R_SH_SWITCH16 25 -#define R_SH_SWITCH32 26 -#define R_SH_USES 27 -#define R_SH_COUNT 28 -#define R_SH_ALIGN 29 -#define R_SH_CODE 30 -#define R_SH_DATA 31 -#define R_SH_LABEL 32 -#define R_SH_SWITCH8 33 -#define R_SH_GNU_VTINHERIT 34 -#define R_SH_GNU_VTENTRY 35 -#define R_SH_TLS_GD_32 144 -#define R_SH_TLS_LD_32 145 -#define R_SH_TLS_LDO_32 146 -#define R_SH_TLS_IE_32 147 -#define R_SH_TLS_LE_32 148 -#define R_SH_TLS_DTPMOD32 149 -#define R_SH_TLS_DTPOFF32 150 -#define R_SH_TLS_TPOFF32 151 -#define R_SH_GOT32 160 -#define R_SH_PLT32 161 -#define R_SH_COPY 162 -#define R_SH_GLOB_DAT 163 -#define R_SH_JMP_SLOT 164 -#define R_SH_RELATIVE 165 -#define R_SH_GOTOFF 166 -#define R_SH_GOTPC 167 -/* Keep this the last entry. */ -#define R_SH_NUM 256 - -/* S/390 specific definitions. */ - -/* Valid values for the e_flags field. */ - -#define EF_S390_HIGH_GPRS 0x00000001 /* High GPRs kernel facility needed. */ - -/* Additional s390 relocs */ - -#define R_390_NONE 0 /* No reloc. */ -#define R_390_8 1 /* Direct 8 bit. */ -#define R_390_12 2 /* Direct 12 bit. */ -#define R_390_16 3 /* Direct 16 bit. */ -#define R_390_32 4 /* Direct 32 bit. */ -#define R_390_PC32 5 /* PC relative 32 bit. */ -#define R_390_GOT12 6 /* 12 bit GOT offset. */ -#define R_390_GOT32 7 /* 32 bit GOT offset. */ -#define R_390_PLT32 8 /* 32 bit PC relative PLT address. */ -#define R_390_COPY 9 /* Copy symbol at runtime. */ -#define R_390_GLOB_DAT 10 /* Create GOT entry. */ -#define R_390_JMP_SLOT 11 /* Create PLT entry. */ -#define R_390_RELATIVE 12 /* Adjust by program base. */ -#define R_390_GOTOFF32 13 /* 32 bit offset to GOT. */ -#define R_390_GOTPC 14 /* 32 bit PC relative offset to GOT. */ -#define R_390_GOT16 15 /* 16 bit GOT offset. */ -#define R_390_PC16 16 /* PC relative 16 bit. */ -#define R_390_PC16DBL 17 /* PC relative 16 bit shifted by 1. */ -#define R_390_PLT16DBL 18 /* 16 bit PC rel. PLT shifted by 1. */ -#define R_390_PC32DBL 19 /* PC relative 32 bit shifted by 1. */ -#define R_390_PLT32DBL 20 /* 32 bit PC rel. PLT shifted by 1. */ -#define R_390_GOTPCDBL 21 /* 32 bit PC rel. GOT shifted by 1. */ -#define R_390_64 22 /* Direct 64 bit. */ -#define R_390_PC64 23 /* PC relative 64 bit. */ -#define R_390_GOT64 24 /* 64 bit GOT offset. */ -#define R_390_PLT64 25 /* 64 bit PC relative PLT address. */ -#define R_390_GOTENT 26 /* 32 bit PC rel. to GOT entry >> 1. */ -#define R_390_GOTOFF16 27 /* 16 bit offset to GOT. */ -#define R_390_GOTOFF64 28 /* 64 bit offset to GOT. */ -#define R_390_GOTPLT12 29 /* 12 bit offset to jump slot. */ -#define R_390_GOTPLT16 30 /* 16 bit offset to jump slot. */ -#define R_390_GOTPLT32 31 /* 32 bit offset to jump slot. */ -#define R_390_GOTPLT64 32 /* 64 bit offset to jump slot. */ -#define R_390_GOTPLTENT 33 /* 32 bit rel. offset to jump slot. */ -#define R_390_PLTOFF16 34 /* 16 bit offset from GOT to PLT. */ -#define R_390_PLTOFF32 35 /* 32 bit offset from GOT to PLT. */ -#define R_390_PLTOFF64 36 /* 16 bit offset from GOT to PLT. */ -#define R_390_TLS_LOAD 37 /* Tag for load insn in TLS code. */ -#define R_390_TLS_GDCALL 38 /* Tag for function call in general - dynamic TLS code. */ -#define R_390_TLS_LDCALL 39 /* Tag for function call in local - dynamic TLS code. */ -#define R_390_TLS_GD32 40 /* Direct 32 bit for general dynamic - thread local data. */ -#define R_390_TLS_GD64 41 /* Direct 64 bit for general dynamic - thread local data. */ -#define R_390_TLS_GOTIE12 42 /* 12 bit GOT offset for static TLS - block offset. */ -#define R_390_TLS_GOTIE32 43 /* 32 bit GOT offset for static TLS - block offset. */ -#define R_390_TLS_GOTIE64 44 /* 64 bit GOT offset for static TLS - block offset. */ -#define R_390_TLS_LDM32 45 /* Direct 32 bit for local dynamic - thread local data in LE code. */ -#define R_390_TLS_LDM64 46 /* Direct 64 bit for local dynamic - thread local data in LE code. */ -#define R_390_TLS_IE32 47 /* 32 bit address of GOT entry for - negated static TLS block offset. */ -#define R_390_TLS_IE64 48 /* 64 bit address of GOT entry for - negated static TLS block offset. */ -#define R_390_TLS_IEENT 49 /* 32 bit rel. offset to GOT entry for - negated static TLS block offset. */ -#define R_390_TLS_LE32 50 /* 32 bit negated offset relative to - static TLS block. */ -#define R_390_TLS_LE64 51 /* 64 bit negated offset relative to - static TLS block. */ -#define R_390_TLS_LDO32 52 /* 32 bit offset relative to TLS - block. */ -#define R_390_TLS_LDO64 53 /* 64 bit offset relative to TLS - block. */ -#define R_390_TLS_DTPMOD 54 /* ID of module containing symbol. */ -#define R_390_TLS_DTPOFF 55 /* Offset in TLS block. */ -#define R_390_TLS_TPOFF 56 /* Negated offset in static TLS - block. */ -#define R_390_20 57 /* Direct 20 bit. */ -#define R_390_GOT20 58 /* 20 bit GOT offset. */ -#define R_390_GOTPLT20 59 /* 20 bit offset to jump slot. */ -#define R_390_TLS_GOTIE20 60 /* 20 bit GOT offset for static TLS - block offset. */ -#define R_390_IRELATIVE 61 /* STT_GNU_IFUNC relocation. */ -/* Keep this the last entry. */ -#define R_390_NUM 62 - - -/* CRIS relocations. */ -#define R_CRIS_NONE 0 -#define R_CRIS_8 1 -#define R_CRIS_16 2 -#define R_CRIS_32 3 -#define R_CRIS_8_PCREL 4 -#define R_CRIS_16_PCREL 5 -#define R_CRIS_32_PCREL 6 -#define R_CRIS_GNU_VTINHERIT 7 -#define R_CRIS_GNU_VTENTRY 8 -#define R_CRIS_COPY 9 -#define R_CRIS_GLOB_DAT 10 -#define R_CRIS_JUMP_SLOT 11 -#define R_CRIS_RELATIVE 12 -#define R_CRIS_16_GOT 13 -#define R_CRIS_32_GOT 14 -#define R_CRIS_16_GOTPLT 15 -#define R_CRIS_32_GOTPLT 16 -#define R_CRIS_32_GOTREL 17 -#define R_CRIS_32_PLT_GOTREL 18 -#define R_CRIS_32_PLT_PCREL 19 - -#define R_CRIS_NUM 20 - - -/* AMD x86-64 relocations. */ -#define R_X86_64_NONE 0 /* No reloc */ -#define R_X86_64_64 1 /* Direct 64 bit */ -#define R_X86_64_PC32 2 /* PC relative 32 bit signed */ -#define R_X86_64_GOT32 3 /* 32 bit GOT entry */ -#define R_X86_64_PLT32 4 /* 32 bit PLT address */ -#define R_X86_64_COPY 5 /* Copy symbol at runtime */ -#define R_X86_64_GLOB_DAT 6 /* Create GOT entry */ -#define R_X86_64_JUMP_SLOT 7 /* Create PLT entry */ -#define R_X86_64_RELATIVE 8 /* Adjust by program base */ -#define R_X86_64_GOTPCREL 9 /* 32 bit signed PC relative - offset to GOT */ -#define R_X86_64_32 10 /* Direct 32 bit zero extended */ -#define R_X86_64_32S 11 /* Direct 32 bit sign extended */ -#define R_X86_64_16 12 /* Direct 16 bit zero extended */ -#define R_X86_64_PC16 13 /* 16 bit sign extended pc relative */ -#define R_X86_64_8 14 /* Direct 8 bit sign extended */ -#define R_X86_64_PC8 15 /* 8 bit sign extended pc relative */ -#define R_X86_64_DTPMOD64 16 /* ID of module containing symbol */ -#define R_X86_64_DTPOFF64 17 /* Offset in module's TLS block */ -#define R_X86_64_TPOFF64 18 /* Offset in initial TLS block */ -#define R_X86_64_TLSGD 19 /* 32 bit signed PC relative offset - to two GOT entries for GD symbol */ -#define R_X86_64_TLSLD 20 /* 32 bit signed PC relative offset - to two GOT entries for LD symbol */ -#define R_X86_64_DTPOFF32 21 /* Offset in TLS block */ -#define R_X86_64_GOTTPOFF 22 /* 32 bit signed PC relative offset - to GOT entry for IE symbol */ -#define R_X86_64_TPOFF32 23 /* Offset in initial TLS block */ -#define R_X86_64_PC64 24 /* PC relative 64 bit */ -#define R_X86_64_GOTOFF64 25 /* 64 bit offset to GOT */ -#define R_X86_64_GOTPC32 26 /* 32 bit signed pc relative - offset to GOT */ -#define R_X86_64_GOT64 27 /* 64-bit GOT entry offset */ -#define R_X86_64_GOTPCREL64 28 /* 64-bit PC relative offset - to GOT entry */ -#define R_X86_64_GOTPC64 29 /* 64-bit PC relative offset to GOT */ -#define R_X86_64_GOTPLT64 30 /* like GOT64, says PLT entry needed */ -#define R_X86_64_PLTOFF64 31 /* 64-bit GOT relative offset - to PLT entry */ -#define R_X86_64_SIZE32 32 /* Size of symbol plus 32-bit addend */ -#define R_X86_64_SIZE64 33 /* Size of symbol plus 64-bit addend */ -#define R_X86_64_GOTPC32_TLSDESC 34 /* GOT offset for TLS descriptor. */ -#define R_X86_64_TLSDESC_CALL 35 /* Marker for call through TLS - descriptor. */ -#define R_X86_64_TLSDESC 36 /* TLS descriptor. */ -#define R_X86_64_IRELATIVE 37 /* Adjust indirectly by program base */ -#define R_X86_64_RELATIVE64 38 /* 64-bit adjust by program base */ -#define R_X86_64_GOTPCRELX 41 /* like GOTPCREL, but optionally with - linker optimizations */ -#define R_X86_64_REX_GOTPCRELX 42 /* like GOTPCRELX, but a REX prefix - is present */ - -#define R_X86_64_NUM 43 - - -/* AM33 relocations. */ -#define R_MN10300_NONE 0 /* No reloc. */ -#define R_MN10300_32 1 /* Direct 32 bit. */ -#define R_MN10300_16 2 /* Direct 16 bit. */ -#define R_MN10300_8 3 /* Direct 8 bit. */ -#define R_MN10300_PCREL32 4 /* PC-relative 32-bit. */ -#define R_MN10300_PCREL16 5 /* PC-relative 16-bit signed. */ -#define R_MN10300_PCREL8 6 /* PC-relative 8-bit signed. */ -#define R_MN10300_GNU_VTINHERIT 7 /* Ancient C++ vtable garbage... */ -#define R_MN10300_GNU_VTENTRY 8 /* ... collection annotation. */ -#define R_MN10300_24 9 /* Direct 24 bit. */ -#define R_MN10300_GOTPC32 10 /* 32-bit PCrel offset to GOT. */ -#define R_MN10300_GOTPC16 11 /* 16-bit PCrel offset to GOT. */ -#define R_MN10300_GOTOFF32 12 /* 32-bit offset from GOT. */ -#define R_MN10300_GOTOFF24 13 /* 24-bit offset from GOT. */ -#define R_MN10300_GOTOFF16 14 /* 16-bit offset from GOT. */ -#define R_MN10300_PLT32 15 /* 32-bit PCrel to PLT entry. */ -#define R_MN10300_PLT16 16 /* 16-bit PCrel to PLT entry. */ -#define R_MN10300_GOT32 17 /* 32-bit offset to GOT entry. */ -#define R_MN10300_GOT24 18 /* 24-bit offset to GOT entry. */ -#define R_MN10300_GOT16 19 /* 16-bit offset to GOT entry. */ -#define R_MN10300_COPY 20 /* Copy symbol at runtime. */ -#define R_MN10300_GLOB_DAT 21 /* Create GOT entry. */ -#define R_MN10300_JMP_SLOT 22 /* Create PLT entry. */ -#define R_MN10300_RELATIVE 23 /* Adjust by program base. */ -#define R_MN10300_TLS_GD 24 /* 32-bit offset for global dynamic. */ -#define R_MN10300_TLS_LD 25 /* 32-bit offset for local dynamic. */ -#define R_MN10300_TLS_LDO 26 /* Module-relative offset. */ -#define R_MN10300_TLS_GOTIE 27 /* GOT offset for static TLS block - offset. */ -#define R_MN10300_TLS_IE 28 /* GOT address for static TLS block - offset. */ -#define R_MN10300_TLS_LE 29 /* Offset relative to static TLS - block. */ -#define R_MN10300_TLS_DTPMOD 30 /* ID of module containing symbol. */ -#define R_MN10300_TLS_DTPOFF 31 /* Offset in module TLS block. */ -#define R_MN10300_TLS_TPOFF 32 /* Offset in static TLS block. */ -#define R_MN10300_SYM_DIFF 33 /* Adjustment for next reloc as needed - by linker relaxation. */ -#define R_MN10300_ALIGN 34 /* Alignment requirement for linker - relaxation. */ -#define R_MN10300_NUM 35 - - -/* M32R relocs. */ -#define R_M32R_NONE 0 /* No reloc. */ -#define R_M32R_16 1 /* Direct 16 bit. */ -#define R_M32R_32 2 /* Direct 32 bit. */ -#define R_M32R_24 3 /* Direct 24 bit. */ -#define R_M32R_10_PCREL 4 /* PC relative 10 bit shifted. */ -#define R_M32R_18_PCREL 5 /* PC relative 18 bit shifted. */ -#define R_M32R_26_PCREL 6 /* PC relative 26 bit shifted. */ -#define R_M32R_HI16_ULO 7 /* High 16 bit with unsigned low. */ -#define R_M32R_HI16_SLO 8 /* High 16 bit with signed low. */ -#define R_M32R_LO16 9 /* Low 16 bit. */ -#define R_M32R_SDA16 10 /* 16 bit offset in SDA. */ -#define R_M32R_GNU_VTINHERIT 11 -#define R_M32R_GNU_VTENTRY 12 -/* M32R relocs use SHT_RELA. */ -#define R_M32R_16_RELA 33 /* Direct 16 bit. */ -#define R_M32R_32_RELA 34 /* Direct 32 bit. */ -#define R_M32R_24_RELA 35 /* Direct 24 bit. */ -#define R_M32R_10_PCREL_RELA 36 /* PC relative 10 bit shifted. */ -#define R_M32R_18_PCREL_RELA 37 /* PC relative 18 bit shifted. */ -#define R_M32R_26_PCREL_RELA 38 /* PC relative 26 bit shifted. */ -#define R_M32R_HI16_ULO_RELA 39 /* High 16 bit with unsigned low */ -#define R_M32R_HI16_SLO_RELA 40 /* High 16 bit with signed low */ -#define R_M32R_LO16_RELA 41 /* Low 16 bit */ -#define R_M32R_SDA16_RELA 42 /* 16 bit offset in SDA */ -#define R_M32R_RELA_GNU_VTINHERIT 43 -#define R_M32R_RELA_GNU_VTENTRY 44 -#define R_M32R_REL32 45 /* PC relative 32 bit. */ - -#define R_M32R_GOT24 48 /* 24 bit GOT entry */ -#define R_M32R_26_PLTREL 49 /* 26 bit PC relative to PLT shifted */ -#define R_M32R_COPY 50 /* Copy symbol at runtime */ -#define R_M32R_GLOB_DAT 51 /* Create GOT entry */ -#define R_M32R_JMP_SLOT 52 /* Create PLT entry */ -#define R_M32R_RELATIVE 53 /* Adjust by program base */ -#define R_M32R_GOTOFF 54 /* 24 bit offset to GOT */ -#define R_M32R_GOTPC24 55 /* 24 bit PC relative offset to GOT */ -#define R_M32R_GOT16_HI_ULO 56 /* High 16 bit GOT entry with unsigned - low */ -#define R_M32R_GOT16_HI_SLO 57 /* High 16 bit GOT entry with signed - low */ -#define R_M32R_GOT16_LO 58 /* Low 16 bit GOT entry */ -#define R_M32R_GOTPC_HI_ULO 59 /* High 16 bit PC relative offset to - GOT with unsigned low */ -#define R_M32R_GOTPC_HI_SLO 60 /* High 16 bit PC relative offset to - GOT with signed low */ -#define R_M32R_GOTPC_LO 61 /* Low 16 bit PC relative offset to - GOT */ -#define R_M32R_GOTOFF_HI_ULO 62 /* High 16 bit offset to GOT - with unsigned low */ -#define R_M32R_GOTOFF_HI_SLO 63 /* High 16 bit offset to GOT - with signed low */ -#define R_M32R_GOTOFF_LO 64 /* Low 16 bit offset to GOT */ -#define R_M32R_NUM 256 /* Keep this the last entry. */ - - -/* TILEPro relocations. */ -#define R_TILEPRO_NONE 0 /* No reloc */ -#define R_TILEPRO_32 1 /* Direct 32 bit */ -#define R_TILEPRO_16 2 /* Direct 16 bit */ -#define R_TILEPRO_8 3 /* Direct 8 bit */ -#define R_TILEPRO_32_PCREL 4 /* PC relative 32 bit */ -#define R_TILEPRO_16_PCREL 5 /* PC relative 16 bit */ -#define R_TILEPRO_8_PCREL 6 /* PC relative 8 bit */ -#define R_TILEPRO_LO16 7 /* Low 16 bit */ -#define R_TILEPRO_HI16 8 /* High 16 bit */ -#define R_TILEPRO_HA16 9 /* High 16 bit, adjusted */ -#define R_TILEPRO_COPY 10 /* Copy relocation */ -#define R_TILEPRO_GLOB_DAT 11 /* Create GOT entry */ -#define R_TILEPRO_JMP_SLOT 12 /* Create PLT entry */ -#define R_TILEPRO_RELATIVE 13 /* Adjust by program base */ -#define R_TILEPRO_BROFF_X1 14 /* X1 pipe branch offset */ -#define R_TILEPRO_JOFFLONG_X1 15 /* X1 pipe jump offset */ -#define R_TILEPRO_JOFFLONG_X1_PLT 16 /* X1 pipe jump offset to PLT */ -#define R_TILEPRO_IMM8_X0 17 /* X0 pipe 8-bit */ -#define R_TILEPRO_IMM8_Y0 18 /* Y0 pipe 8-bit */ -#define R_TILEPRO_IMM8_X1 19 /* X1 pipe 8-bit */ -#define R_TILEPRO_IMM8_Y1 20 /* Y1 pipe 8-bit */ -#define R_TILEPRO_MT_IMM15_X1 21 /* X1 pipe mtspr */ -#define R_TILEPRO_MF_IMM15_X1 22 /* X1 pipe mfspr */ -#define R_TILEPRO_IMM16_X0 23 /* X0 pipe 16-bit */ -#define R_TILEPRO_IMM16_X1 24 /* X1 pipe 16-bit */ -#define R_TILEPRO_IMM16_X0_LO 25 /* X0 pipe low 16-bit */ -#define R_TILEPRO_IMM16_X1_LO 26 /* X1 pipe low 16-bit */ -#define R_TILEPRO_IMM16_X0_HI 27 /* X0 pipe high 16-bit */ -#define R_TILEPRO_IMM16_X1_HI 28 /* X1 pipe high 16-bit */ -#define R_TILEPRO_IMM16_X0_HA 29 /* X0 pipe high 16-bit, adjusted */ -#define R_TILEPRO_IMM16_X1_HA 30 /* X1 pipe high 16-bit, adjusted */ -#define R_TILEPRO_IMM16_X0_PCREL 31 /* X0 pipe PC relative 16 bit */ -#define R_TILEPRO_IMM16_X1_PCREL 32 /* X1 pipe PC relative 16 bit */ -#define R_TILEPRO_IMM16_X0_LO_PCREL 33 /* X0 pipe PC relative low 16 bit */ -#define R_TILEPRO_IMM16_X1_LO_PCREL 34 /* X1 pipe PC relative low 16 bit */ -#define R_TILEPRO_IMM16_X0_HI_PCREL 35 /* X0 pipe PC relative high 16 bit */ -#define R_TILEPRO_IMM16_X1_HI_PCREL 36 /* X1 pipe PC relative high 16 bit */ -#define R_TILEPRO_IMM16_X0_HA_PCREL 37 /* X0 pipe PC relative ha() 16 bit */ -#define R_TILEPRO_IMM16_X1_HA_PCREL 38 /* X1 pipe PC relative ha() 16 bit */ -#define R_TILEPRO_IMM16_X0_GOT 39 /* X0 pipe 16-bit GOT offset */ -#define R_TILEPRO_IMM16_X1_GOT 40 /* X1 pipe 16-bit GOT offset */ -#define R_TILEPRO_IMM16_X0_GOT_LO 41 /* X0 pipe low 16-bit GOT offset */ -#define R_TILEPRO_IMM16_X1_GOT_LO 42 /* X1 pipe low 16-bit GOT offset */ -#define R_TILEPRO_IMM16_X0_GOT_HI 43 /* X0 pipe high 16-bit GOT offset */ -#define R_TILEPRO_IMM16_X1_GOT_HI 44 /* X1 pipe high 16-bit GOT offset */ -#define R_TILEPRO_IMM16_X0_GOT_HA 45 /* X0 pipe ha() 16-bit GOT offset */ -#define R_TILEPRO_IMM16_X1_GOT_HA 46 /* X1 pipe ha() 16-bit GOT offset */ -#define R_TILEPRO_MMSTART_X0 47 /* X0 pipe mm "start" */ -#define R_TILEPRO_MMEND_X0 48 /* X0 pipe mm "end" */ -#define R_TILEPRO_MMSTART_X1 49 /* X1 pipe mm "start" */ -#define R_TILEPRO_MMEND_X1 50 /* X1 pipe mm "end" */ -#define R_TILEPRO_SHAMT_X0 51 /* X0 pipe shift amount */ -#define R_TILEPRO_SHAMT_X1 52 /* X1 pipe shift amount */ -#define R_TILEPRO_SHAMT_Y0 53 /* Y0 pipe shift amount */ -#define R_TILEPRO_SHAMT_Y1 54 /* Y1 pipe shift amount */ -#define R_TILEPRO_DEST_IMM8_X1 55 /* X1 pipe destination 8-bit */ -/* Relocs 56-59 are currently not defined. */ -#define R_TILEPRO_TLS_GD_CALL 60 /* "jal" for TLS GD */ -#define R_TILEPRO_IMM8_X0_TLS_GD_ADD 61 /* X0 pipe "addi" for TLS GD */ -#define R_TILEPRO_IMM8_X1_TLS_GD_ADD 62 /* X1 pipe "addi" for TLS GD */ -#define R_TILEPRO_IMM8_Y0_TLS_GD_ADD 63 /* Y0 pipe "addi" for TLS GD */ -#define R_TILEPRO_IMM8_Y1_TLS_GD_ADD 64 /* Y1 pipe "addi" for TLS GD */ -#define R_TILEPRO_TLS_IE_LOAD 65 /* "lw_tls" for TLS IE */ -#define R_TILEPRO_IMM16_X0_TLS_GD 66 /* X0 pipe 16-bit TLS GD offset */ -#define R_TILEPRO_IMM16_X1_TLS_GD 67 /* X1 pipe 16-bit TLS GD offset */ -#define R_TILEPRO_IMM16_X0_TLS_GD_LO 68 /* X0 pipe low 16-bit TLS GD offset */ -#define R_TILEPRO_IMM16_X1_TLS_GD_LO 69 /* X1 pipe low 16-bit TLS GD offset */ -#define R_TILEPRO_IMM16_X0_TLS_GD_HI 70 /* X0 pipe high 16-bit TLS GD offset */ -#define R_TILEPRO_IMM16_X1_TLS_GD_HI 71 /* X1 pipe high 16-bit TLS GD offset */ -#define R_TILEPRO_IMM16_X0_TLS_GD_HA 72 /* X0 pipe ha() 16-bit TLS GD offset */ -#define R_TILEPRO_IMM16_X1_TLS_GD_HA 73 /* X1 pipe ha() 16-bit TLS GD offset */ -#define R_TILEPRO_IMM16_X0_TLS_IE 74 /* X0 pipe 16-bit TLS IE offset */ -#define R_TILEPRO_IMM16_X1_TLS_IE 75 /* X1 pipe 16-bit TLS IE offset */ -#define R_TILEPRO_IMM16_X0_TLS_IE_LO 76 /* X0 pipe low 16-bit TLS IE offset */ -#define R_TILEPRO_IMM16_X1_TLS_IE_LO 77 /* X1 pipe low 16-bit TLS IE offset */ -#define R_TILEPRO_IMM16_X0_TLS_IE_HI 78 /* X0 pipe high 16-bit TLS IE offset */ -#define R_TILEPRO_IMM16_X1_TLS_IE_HI 79 /* X1 pipe high 16-bit TLS IE offset */ -#define R_TILEPRO_IMM16_X0_TLS_IE_HA 80 /* X0 pipe ha() 16-bit TLS IE offset */ -#define R_TILEPRO_IMM16_X1_TLS_IE_HA 81 /* X1 pipe ha() 16-bit TLS IE offset */ -#define R_TILEPRO_TLS_DTPMOD32 82 /* ID of module containing symbol */ -#define R_TILEPRO_TLS_DTPOFF32 83 /* Offset in TLS block */ -#define R_TILEPRO_TLS_TPOFF32 84 /* Offset in static TLS block */ -#define R_TILEPRO_IMM16_X0_TLS_LE 85 /* X0 pipe 16-bit TLS LE offset */ -#define R_TILEPRO_IMM16_X1_TLS_LE 86 /* X1 pipe 16-bit TLS LE offset */ -#define R_TILEPRO_IMM16_X0_TLS_LE_LO 87 /* X0 pipe low 16-bit TLS LE offset */ -#define R_TILEPRO_IMM16_X1_TLS_LE_LO 88 /* X1 pipe low 16-bit TLS LE offset */ -#define R_TILEPRO_IMM16_X0_TLS_LE_HI 89 /* X0 pipe high 16-bit TLS LE offset */ -#define R_TILEPRO_IMM16_X1_TLS_LE_HI 90 /* X1 pipe high 16-bit TLS LE offset */ -#define R_TILEPRO_IMM16_X0_TLS_LE_HA 91 /* X0 pipe ha() 16-bit TLS LE offset */ -#define R_TILEPRO_IMM16_X1_TLS_LE_HA 92 /* X1 pipe ha() 16-bit TLS LE offset */ - -#define R_TILEPRO_GNU_VTINHERIT 128 /* GNU C++ vtable hierarchy */ -#define R_TILEPRO_GNU_VTENTRY 129 /* GNU C++ vtable member usage */ - -#define R_TILEPRO_NUM 130 - - -/* TILE-Gx relocations. */ -#define R_TILEGX_NONE 0 /* No reloc */ -#define R_TILEGX_64 1 /* Direct 64 bit */ -#define R_TILEGX_32 2 /* Direct 32 bit */ -#define R_TILEGX_16 3 /* Direct 16 bit */ -#define R_TILEGX_8 4 /* Direct 8 bit */ -#define R_TILEGX_64_PCREL 5 /* PC relative 64 bit */ -#define R_TILEGX_32_PCREL 6 /* PC relative 32 bit */ -#define R_TILEGX_16_PCREL 7 /* PC relative 16 bit */ -#define R_TILEGX_8_PCREL 8 /* PC relative 8 bit */ -#define R_TILEGX_HW0 9 /* hword 0 16-bit */ -#define R_TILEGX_HW1 10 /* hword 1 16-bit */ -#define R_TILEGX_HW2 11 /* hword 2 16-bit */ -#define R_TILEGX_HW3 12 /* hword 3 16-bit */ -#define R_TILEGX_HW0_LAST 13 /* last hword 0 16-bit */ -#define R_TILEGX_HW1_LAST 14 /* last hword 1 16-bit */ -#define R_TILEGX_HW2_LAST 15 /* last hword 2 16-bit */ -#define R_TILEGX_COPY 16 /* Copy relocation */ -#define R_TILEGX_GLOB_DAT 17 /* Create GOT entry */ -#define R_TILEGX_JMP_SLOT 18 /* Create PLT entry */ -#define R_TILEGX_RELATIVE 19 /* Adjust by program base */ -#define R_TILEGX_BROFF_X1 20 /* X1 pipe branch offset */ -#define R_TILEGX_JUMPOFF_X1 21 /* X1 pipe jump offset */ -#define R_TILEGX_JUMPOFF_X1_PLT 22 /* X1 pipe jump offset to PLT */ -#define R_TILEGX_IMM8_X0 23 /* X0 pipe 8-bit */ -#define R_TILEGX_IMM8_Y0 24 /* Y0 pipe 8-bit */ -#define R_TILEGX_IMM8_X1 25 /* X1 pipe 8-bit */ -#define R_TILEGX_IMM8_Y1 26 /* Y1 pipe 8-bit */ -#define R_TILEGX_DEST_IMM8_X1 27 /* X1 pipe destination 8-bit */ -#define R_TILEGX_MT_IMM14_X1 28 /* X1 pipe mtspr */ -#define R_TILEGX_MF_IMM14_X1 29 /* X1 pipe mfspr */ -#define R_TILEGX_MMSTART_X0 30 /* X0 pipe mm "start" */ -#define R_TILEGX_MMEND_X0 31 /* X0 pipe mm "end" */ -#define R_TILEGX_SHAMT_X0 32 /* X0 pipe shift amount */ -#define R_TILEGX_SHAMT_X1 33 /* X1 pipe shift amount */ -#define R_TILEGX_SHAMT_Y0 34 /* Y0 pipe shift amount */ -#define R_TILEGX_SHAMT_Y1 35 /* Y1 pipe shift amount */ -#define R_TILEGX_IMM16_X0_HW0 36 /* X0 pipe hword 0 */ -#define R_TILEGX_IMM16_X1_HW0 37 /* X1 pipe hword 0 */ -#define R_TILEGX_IMM16_X0_HW1 38 /* X0 pipe hword 1 */ -#define R_TILEGX_IMM16_X1_HW1 39 /* X1 pipe hword 1 */ -#define R_TILEGX_IMM16_X0_HW2 40 /* X0 pipe hword 2 */ -#define R_TILEGX_IMM16_X1_HW2 41 /* X1 pipe hword 2 */ -#define R_TILEGX_IMM16_X0_HW3 42 /* X0 pipe hword 3 */ -#define R_TILEGX_IMM16_X1_HW3 43 /* X1 pipe hword 3 */ -#define R_TILEGX_IMM16_X0_HW0_LAST 44 /* X0 pipe last hword 0 */ -#define R_TILEGX_IMM16_X1_HW0_LAST 45 /* X1 pipe last hword 0 */ -#define R_TILEGX_IMM16_X0_HW1_LAST 46 /* X0 pipe last hword 1 */ -#define R_TILEGX_IMM16_X1_HW1_LAST 47 /* X1 pipe last hword 1 */ -#define R_TILEGX_IMM16_X0_HW2_LAST 48 /* X0 pipe last hword 2 */ -#define R_TILEGX_IMM16_X1_HW2_LAST 49 /* X1 pipe last hword 2 */ -#define R_TILEGX_IMM16_X0_HW0_PCREL 50 /* X0 pipe PC relative hword 0 */ -#define R_TILEGX_IMM16_X1_HW0_PCREL 51 /* X1 pipe PC relative hword 0 */ -#define R_TILEGX_IMM16_X0_HW1_PCREL 52 /* X0 pipe PC relative hword 1 */ -#define R_TILEGX_IMM16_X1_HW1_PCREL 53 /* X1 pipe PC relative hword 1 */ -#define R_TILEGX_IMM16_X0_HW2_PCREL 54 /* X0 pipe PC relative hword 2 */ -#define R_TILEGX_IMM16_X1_HW2_PCREL 55 /* X1 pipe PC relative hword 2 */ -#define R_TILEGX_IMM16_X0_HW3_PCREL 56 /* X0 pipe PC relative hword 3 */ -#define R_TILEGX_IMM16_X1_HW3_PCREL 57 /* X1 pipe PC relative hword 3 */ -#define R_TILEGX_IMM16_X0_HW0_LAST_PCREL 58 /* X0 pipe PC-rel last hword 0 */ -#define R_TILEGX_IMM16_X1_HW0_LAST_PCREL 59 /* X1 pipe PC-rel last hword 0 */ -#define R_TILEGX_IMM16_X0_HW1_LAST_PCREL 60 /* X0 pipe PC-rel last hword 1 */ -#define R_TILEGX_IMM16_X1_HW1_LAST_PCREL 61 /* X1 pipe PC-rel last hword 1 */ -#define R_TILEGX_IMM16_X0_HW2_LAST_PCREL 62 /* X0 pipe PC-rel last hword 2 */ -#define R_TILEGX_IMM16_X1_HW2_LAST_PCREL 63 /* X1 pipe PC-rel last hword 2 */ -#define R_TILEGX_IMM16_X0_HW0_GOT 64 /* X0 pipe hword 0 GOT offset */ -#define R_TILEGX_IMM16_X1_HW0_GOT 65 /* X1 pipe hword 0 GOT offset */ -#define R_TILEGX_IMM16_X0_HW0_PLT_PCREL 66 /* X0 pipe PC-rel PLT hword 0 */ -#define R_TILEGX_IMM16_X1_HW0_PLT_PCREL 67 /* X1 pipe PC-rel PLT hword 0 */ -#define R_TILEGX_IMM16_X0_HW1_PLT_PCREL 68 /* X0 pipe PC-rel PLT hword 1 */ -#define R_TILEGX_IMM16_X1_HW1_PLT_PCREL 69 /* X1 pipe PC-rel PLT hword 1 */ -#define R_TILEGX_IMM16_X0_HW2_PLT_PCREL 70 /* X0 pipe PC-rel PLT hword 2 */ -#define R_TILEGX_IMM16_X1_HW2_PLT_PCREL 71 /* X1 pipe PC-rel PLT hword 2 */ -#define R_TILEGX_IMM16_X0_HW0_LAST_GOT 72 /* X0 pipe last hword 0 GOT offset */ -#define R_TILEGX_IMM16_X1_HW0_LAST_GOT 73 /* X1 pipe last hword 0 GOT offset */ -#define R_TILEGX_IMM16_X0_HW1_LAST_GOT 74 /* X0 pipe last hword 1 GOT offset */ -#define R_TILEGX_IMM16_X1_HW1_LAST_GOT 75 /* X1 pipe last hword 1 GOT offset */ -#define R_TILEGX_IMM16_X0_HW3_PLT_PCREL 76 /* X0 pipe PC-rel PLT hword 3 */ -#define R_TILEGX_IMM16_X1_HW3_PLT_PCREL 77 /* X1 pipe PC-rel PLT hword 3 */ -#define R_TILEGX_IMM16_X0_HW0_TLS_GD 78 /* X0 pipe hword 0 TLS GD offset */ -#define R_TILEGX_IMM16_X1_HW0_TLS_GD 79 /* X1 pipe hword 0 TLS GD offset */ -#define R_TILEGX_IMM16_X0_HW0_TLS_LE 80 /* X0 pipe hword 0 TLS LE offset */ -#define R_TILEGX_IMM16_X1_HW0_TLS_LE 81 /* X1 pipe hword 0 TLS LE offset */ -#define R_TILEGX_IMM16_X0_HW0_LAST_TLS_LE 82 /* X0 pipe last hword 0 LE off */ -#define R_TILEGX_IMM16_X1_HW0_LAST_TLS_LE 83 /* X1 pipe last hword 0 LE off */ -#define R_TILEGX_IMM16_X0_HW1_LAST_TLS_LE 84 /* X0 pipe last hword 1 LE off */ -#define R_TILEGX_IMM16_X1_HW1_LAST_TLS_LE 85 /* X1 pipe last hword 1 LE off */ -#define R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD 86 /* X0 pipe last hword 0 GD off */ -#define R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD 87 /* X1 pipe last hword 0 GD off */ -#define R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD 88 /* X0 pipe last hword 1 GD off */ -#define R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD 89 /* X1 pipe last hword 1 GD off */ -/* Relocs 90-91 are currently not defined. */ -#define R_TILEGX_IMM16_X0_HW0_TLS_IE 92 /* X0 pipe hword 0 TLS IE offset */ -#define R_TILEGX_IMM16_X1_HW0_TLS_IE 93 /* X1 pipe hword 0 TLS IE offset */ -#define R_TILEGX_IMM16_X0_HW0_LAST_PLT_PCREL 94 /* X0 pipe PC-rel PLT last hword 0 */ -#define R_TILEGX_IMM16_X1_HW0_LAST_PLT_PCREL 95 /* X1 pipe PC-rel PLT last hword 0 */ -#define R_TILEGX_IMM16_X0_HW1_LAST_PLT_PCREL 96 /* X0 pipe PC-rel PLT last hword 1 */ -#define R_TILEGX_IMM16_X1_HW1_LAST_PLT_PCREL 97 /* X1 pipe PC-rel PLT last hword 1 */ -#define R_TILEGX_IMM16_X0_HW2_LAST_PLT_PCREL 98 /* X0 pipe PC-rel PLT last hword 2 */ -#define R_TILEGX_IMM16_X1_HW2_LAST_PLT_PCREL 99 /* X1 pipe PC-rel PLT last hword 2 */ -#define R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE 100 /* X0 pipe last hword 0 IE off */ -#define R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE 101 /* X1 pipe last hword 0 IE off */ -#define R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE 102 /* X0 pipe last hword 1 IE off */ -#define R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE 103 /* X1 pipe last hword 1 IE off */ -/* Relocs 104-105 are currently not defined. */ -#define R_TILEGX_TLS_DTPMOD64 106 /* 64-bit ID of symbol's module */ -#define R_TILEGX_TLS_DTPOFF64 107 /* 64-bit offset in TLS block */ -#define R_TILEGX_TLS_TPOFF64 108 /* 64-bit offset in static TLS block */ -#define R_TILEGX_TLS_DTPMOD32 109 /* 32-bit ID of symbol's module */ -#define R_TILEGX_TLS_DTPOFF32 110 /* 32-bit offset in TLS block */ -#define R_TILEGX_TLS_TPOFF32 111 /* 32-bit offset in static TLS block */ -#define R_TILEGX_TLS_GD_CALL 112 /* "jal" for TLS GD */ -#define R_TILEGX_IMM8_X0_TLS_GD_ADD 113 /* X0 pipe "addi" for TLS GD */ -#define R_TILEGX_IMM8_X1_TLS_GD_ADD 114 /* X1 pipe "addi" for TLS GD */ -#define R_TILEGX_IMM8_Y0_TLS_GD_ADD 115 /* Y0 pipe "addi" for TLS GD */ -#define R_TILEGX_IMM8_Y1_TLS_GD_ADD 116 /* Y1 pipe "addi" for TLS GD */ -#define R_TILEGX_TLS_IE_LOAD 117 /* "ld_tls" for TLS IE */ -#define R_TILEGX_IMM8_X0_TLS_ADD 118 /* X0 pipe "addi" for TLS GD/IE */ -#define R_TILEGX_IMM8_X1_TLS_ADD 119 /* X1 pipe "addi" for TLS GD/IE */ -#define R_TILEGX_IMM8_Y0_TLS_ADD 120 /* Y0 pipe "addi" for TLS GD/IE */ -#define R_TILEGX_IMM8_Y1_TLS_ADD 121 /* Y1 pipe "addi" for TLS GD/IE */ - -#define R_TILEGX_GNU_VTINHERIT 128 /* GNU C++ vtable hierarchy */ -#define R_TILEGX_GNU_VTENTRY 129 /* GNU C++ vtable member usage */ - -#define R_TILEGX_NUM 130 - - -#endif /* elf.h */ diff --git a/05/tcc-final-old/examples/ex1.c b/05/tcc-final-old/examples/ex1.c deleted file mode 100755 index 3d2a3e1..0000000 --- a/05/tcc-final-old/examples/ex1.c +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/local/bin/tcc -run -#include - -int main() -{ - printf("Hello World\n"); - return 0; -} diff --git a/05/tcc-final-old/examples/ex2.c b/05/tcc-final-old/examples/ex2.c deleted file mode 100644 index d415e39..0000000 --- a/05/tcc-final-old/examples/ex2.c +++ /dev/null @@ -1,98 +0,0 @@ -#include -#include - -#define N 20 - -int nb_num; -int tab[N]; -int stack_ptr; -int stack_op[N]; -int stack_res[60]; -int result; - -int find(int n, int i1, int a, int b, int op) -{ - int i, j; - int c; - - if (stack_ptr >= 0) { - stack_res[3*stack_ptr] = a; - stack_op[stack_ptr] = op; - stack_res[3*stack_ptr+1] = b; - stack_res[3*stack_ptr+2] = n; - if (n == result) - return 1; - tab[i1] = n; - } - - for(i=0;i - -int fib(n) -{ - if (n <= 2) - return 1; - else - return fib(n-1) + fib(n-2); -} - -int main(int argc, char **argv) -{ - int n; - if (argc < 2) { - printf("usage: fib n\n" - "Compute nth Fibonacci number\n"); - return 1; - } - - n = atoi(argv[1]); - printf("fib(%d) = %d\n", n, fib(n, 2)); - return 0; -} diff --git a/05/tcc-final-old/examples/ex4.c b/05/tcc-final-old/examples/ex4.c deleted file mode 100755 index f92c0da..0000000 --- a/05/tcc-final-old/examples/ex4.c +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/local/bin/tcc -run -L/usr/X11R6/lib -lX11 -#include -#include -#include - -/* Yes, TCC can use X11 too ! */ - -int main(int argc, char **argv) -{ - Display *display; - Screen *screen; - - display = XOpenDisplay(""); - if (!display) { - fprintf(stderr, "Could not open X11 display\n"); - exit(1); - } - printf("X11 display opened.\n"); - screen = XScreenOfDisplay(display, 0); - printf("width = %d\nheight = %d\ndepth = %d\n", - screen->width, - screen->height, - screen->root_depth); - XCloseDisplay(display); - return 0; -} diff --git a/05/tcc-final-old/examples/ex5.c b/05/tcc-final-old/examples/ex5.c deleted file mode 100644 index 156425e..0000000 --- a/05/tcc-final-old/examples/ex5.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include - -int main() -{ - printf("Hello World\n"); - return 0; -} diff --git a/05/tcc-final-old/i386-asm.c b/05/tcc-final-old/i386-asm.c deleted file mode 100644 index 55c95af..0000000 --- a/05/tcc-final-old/i386-asm.c +++ /dev/null @@ -1,1723 +0,0 @@ -/* - * i386 specific functions for TCC assembler - * - * Copyright (c) 2001, 2002 Fabrice Bellard - * Copyright (c) 2009 Frédéric Feret (x86_64 support) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "tcc.h" - -#define MAX_OPERANDS 3 - -#define TOK_ASM_first TOK_ASM_clc -#define TOK_ASM_last TOK_ASM_emms -#define TOK_ASM_alllast TOK_ASM_subps - -#define OPC_B 0x01 /* only used with OPC_WL */ -#define OPC_WL 0x02 /* accepts w, l or no suffix */ -#define OPC_BWL (OPC_B | OPC_WL) /* accepts b, w, l or no suffix */ -#define OPC_REG 0x04 /* register is added to opcode */ -#define OPC_MODRM 0x08 /* modrm encoding */ - -#define OPCT_MASK 0x70 -#define OPC_FWAIT 0x10 /* add fwait opcode */ -#define OPC_SHIFT 0x20 /* shift opcodes */ -#define OPC_ARITH 0x30 /* arithmetic opcodes */ -#define OPC_FARITH 0x40 /* FPU arithmetic opcodes */ -#define OPC_TEST 0x50 /* test opcodes */ -#define OPCT_IS(v,i) (((v) & OPCT_MASK) == (i)) - -#define OPC_0F 0x100 /* Is secondary map (0x0f prefix) */ -#define OPC_48 0x200 /* Always has REX prefix */ -#ifdef TCC_TARGET_X86_64 -# define OPC_WLQ 0x1000 /* accepts w, l, q or no suffix */ -# define OPC_BWLQ (OPC_B | OPC_WLQ) /* accepts b, w, l, q or no suffix */ -# define OPC_WLX OPC_WLQ -# define OPC_BWLX OPC_BWLQ -#else -# define OPC_WLX OPC_WL -# define OPC_BWLX OPC_BWL -#endif - -#define OPC_GROUP_SHIFT 13 - -/* in order to compress the operand type, we use specific operands and - we or only with EA */ -enum { - OPT_REG8=0, /* warning: value is hardcoded from TOK_ASM_xxx */ - OPT_REG16, /* warning: value is hardcoded from TOK_ASM_xxx */ - OPT_REG32, /* warning: value is hardcoded from TOK_ASM_xxx */ -#ifdef TCC_TARGET_X86_64 - OPT_REG64, /* warning: value is hardcoded from TOK_ASM_xxx */ -#endif - OPT_MMX, /* warning: value is hardcoded from TOK_ASM_xxx */ - OPT_SSE, /* warning: value is hardcoded from TOK_ASM_xxx */ - OPT_CR, /* warning: value is hardcoded from TOK_ASM_xxx */ - OPT_TR, /* warning: value is hardcoded from TOK_ASM_xxx */ - OPT_DB, /* warning: value is hardcoded from TOK_ASM_xxx */ - OPT_SEG, - OPT_ST, -#ifdef TCC_TARGET_X86_64 - OPT_REG8_LOW, /* %spl,%bpl,%sil,%dil, encoded like ah,ch,dh,bh, but - with REX prefix, not used in insn templates */ -#endif - OPT_IM8, - OPT_IM8S, - OPT_IM16, - OPT_IM32, -#ifdef TCC_TARGET_X86_64 - OPT_IM64, -#endif - OPT_EAX, /* %al, %ax, %eax or %rax register */ - OPT_ST0, /* %st(0) register */ - OPT_CL, /* %cl register */ - OPT_DX, /* %dx register */ - OPT_ADDR, /* OP_EA with only offset */ - OPT_INDIR, /* *(expr) */ - /* composite types */ - OPT_COMPOSITE_FIRST, - OPT_IM, /* IM8 | IM16 | IM32 */ - OPT_REG, /* REG8 | REG16 | REG32 | REG64 */ - OPT_REGW, /* REG16 | REG32 | REG64 */ - OPT_IMW, /* IM16 | IM32 */ - OPT_MMXSSE, /* MMX | SSE */ - OPT_DISP, /* Like OPT_ADDR, but emitted as displacement (for jumps) */ - OPT_DISP8, /* Like OPT_ADDR, but only 8bit (short jumps) */ - /* can be ored with any OPT_xxx */ - OPT_EA = 0x80 -}; - -#define OP_REG8 (1 << OPT_REG8) -#define OP_REG16 (1 << OPT_REG16) -#define OP_REG32 (1 << OPT_REG32) -#define OP_MMX (1 << OPT_MMX) -#define OP_SSE (1 << OPT_SSE) -#define OP_CR (1 << OPT_CR) -#define OP_TR (1 << OPT_TR) -#define OP_DB (1 << OPT_DB) -#define OP_SEG (1 << OPT_SEG) -#define OP_ST (1 << OPT_ST) -#define OP_IM8 (1 << OPT_IM8) -#define OP_IM8S (1 << OPT_IM8S) -#define OP_IM16 (1 << OPT_IM16) -#define OP_IM32 (1 << OPT_IM32) -#define OP_EAX (1 << OPT_EAX) -#define OP_ST0 (1 << OPT_ST0) -#define OP_CL (1 << OPT_CL) -#define OP_DX (1 << OPT_DX) -#define OP_ADDR (1 << OPT_ADDR) -#define OP_INDIR (1 << OPT_INDIR) -#ifdef TCC_TARGET_X86_64 -# define OP_REG64 (1 << OPT_REG64) -# define OP_REG8_LOW (1 << OPT_REG8_LOW) -# define OP_IM64 (1 << OPT_IM64) -# define OP_EA32 (OP_EA << 1) -#else -# define OP_REG64 0 -# define OP_REG8_LOW 0 -# define OP_IM64 0 -# define OP_EA32 0 -#endif - -#define OP_EA 0x40000000 -#define OP_REG (OP_REG8 | OP_REG16 | OP_REG32 | OP_REG64) - -#ifdef TCC_TARGET_X86_64 -# define TREG_XAX TREG_RAX -# define TREG_XCX TREG_RCX -# define TREG_XDX TREG_RDX -#else -# define TREG_XAX TREG_EAX -# define TREG_XCX TREG_ECX -# define TREG_XDX TREG_EDX -#endif - -typedef struct ASMInstr { - uint16_t sym; - uint16_t opcode; - uint16_t instr_type; - uint8_t nb_ops; - uint8_t op_type[MAX_OPERANDS]; /* see OP_xxx */ -} ASMInstr; - -typedef struct Operand { - uint32_t type; - int8_t reg; /* register, -1 if none */ - int8_t reg2; /* second register, -1 if none */ - uint8_t shift; - ExprValue e; -} Operand; - -static const uint8_t reg_to_size[9] = { -/* - [OP_REG8] = 0, - [OP_REG16] = 1, - [OP_REG32] = 2, -#ifdef TCC_TARGET_X86_64 - [OP_REG64] = 3, -#endif -*/ - 0, 0, 1, 0, 2, 0, 0, 0, 3 -}; - -#define NB_TEST_OPCODES 30 - -static const uint8_t test_bits[NB_TEST_OPCODES] = { - 0x00, /* o */ - 0x01, /* no */ - 0x02, /* b */ - 0x02, /* c */ - 0x02, /* nae */ - 0x03, /* nb */ - 0x03, /* nc */ - 0x03, /* ae */ - 0x04, /* e */ - 0x04, /* z */ - 0x05, /* ne */ - 0x05, /* nz */ - 0x06, /* be */ - 0x06, /* na */ - 0x07, /* nbe */ - 0x07, /* a */ - 0x08, /* s */ - 0x09, /* ns */ - 0x0a, /* p */ - 0x0a, /* pe */ - 0x0b, /* np */ - 0x0b, /* po */ - 0x0c, /* l */ - 0x0c, /* nge */ - 0x0d, /* nl */ - 0x0d, /* ge */ - 0x0e, /* le */ - 0x0e, /* ng */ - 0x0f, /* nle */ - 0x0f, /* g */ -}; - -static const uint8_t segment_prefixes[] = { - 0x26, /* es */ - 0x2e, /* cs */ - 0x36, /* ss */ - 0x3e, /* ds */ - 0x64, /* fs */ - 0x65 /* gs */ -}; - -static const ASMInstr asm_instrs[] = { -#define ALT(x) x -/* This removes a 0x0f in the second byte */ -#define O(o) ((uint64_t) ((((o) & 0xff00) == 0x0f00) ? ((((o) >> 8) & ~0xff) | ((o) & 0xff)) : (o))) -/* This constructs instr_type from opcode, type and group. */ -#define T(o,i,g) ((i) | ((g) << OPC_GROUP_SHIFT) | ((((o) & 0xff00) == 0x0f00) ? OPC_0F : 0)) -#define DEF_ASM_OP0(name, opcode) -#define DEF_ASM_OP0L(name, opcode, group, instr_type) { TOK_ASM_ ## name, O(opcode), T(opcode, instr_type, group), 0, { 0 } }, -#define DEF_ASM_OP1(name, opcode, group, instr_type, op0) { TOK_ASM_ ## name, O(opcode), T(opcode, instr_type, group), 1, { op0 }}, -#define DEF_ASM_OP2(name, opcode, group, instr_type, op0, op1) { TOK_ASM_ ## name, O(opcode), T(opcode, instr_type, group), 2, { op0, op1 }}, -#define DEF_ASM_OP3(name, opcode, group, instr_type, op0, op1, op2) { TOK_ASM_ ## name, O(opcode), T(opcode, instr_type, group), 3, { op0, op1, op2 }}, -#ifdef TCC_TARGET_X86_64 -# include "x86_64-asm.h" -#else -# include "i386-asm.h" -#endif - /* last operation */ - { 0, }, -}; - -static const uint16_t op0_codes[] = { -#define ALT(x) -#define DEF_ASM_OP0(x, opcode) opcode, -#define DEF_ASM_OP0L(name, opcode, group, instr_type) -#define DEF_ASM_OP1(name, opcode, group, instr_type, op0) -#define DEF_ASM_OP2(name, opcode, group, instr_type, op0, op1) -#define DEF_ASM_OP3(name, opcode, group, instr_type, op0, op1, op2) -#ifdef TCC_TARGET_X86_64 -# include "x86_64-asm.h" -#else -# include "i386-asm.h" -#endif -}; - -static inline int get_reg_shift(TCCState *s1) -{ - int shift, v; - v = asm_int_expr(s1); - switch(v) { - case 1: - shift = 0; - break; - case 2: - shift = 1; - break; - case 4: - shift = 2; - break; - case 8: - shift = 3; - break; - default: - expect("1, 2, 4 or 8 constant"); - shift = 0; - break; - } - return shift; -} - -#ifdef TCC_TARGET_X86_64 -static int asm_parse_numeric_reg(int t, unsigned int *type) -{ - int reg = -1; - if (t >= TOK_IDENT && t < tok_ident) { - const char *s = table_ident[t - TOK_IDENT]->str; - char c; - *type = OP_REG64; - if (*s == 'c') { - s++; - *type = OP_CR; - } - if (*s++ != 'r') - return -1; - /* Don't allow leading '0'. */ - if ((c = *s++) >= '1' && c <= '9') - reg = c - '0'; - else - return -1; - if ((c = *s) >= '0' && c <= '5') - s++, reg = reg * 10 + c - '0'; - if (reg > 15) - return -1; - if ((c = *s) == 0) - ; - else if (*type != OP_REG64) - return -1; - else if (c == 'b' && !s[1]) - *type = OP_REG8; - else if (c == 'w' && !s[1]) - *type = OP_REG16; - else if (c == 'd' && !s[1]) - *type = OP_REG32; - else - return -1; - } - return reg; -} -#endif - -static int asm_parse_reg(unsigned int *type) -{ - int reg = 0; - *type = 0; - if (tok != '%') - goto error_32; - next(); - if (tok >= TOK_ASM_eax && tok <= TOK_ASM_edi) { - reg = tok - TOK_ASM_eax; - *type = OP_REG32; -#ifdef TCC_TARGET_X86_64 - } else if (tok >= TOK_ASM_rax && tok <= TOK_ASM_rdi) { - reg = tok - TOK_ASM_rax; - *type = OP_REG64; - } else if (tok == TOK_ASM_rip) { - reg = -2; /* Probably should use different escape code. */ - *type = OP_REG64; - } else if ((reg = asm_parse_numeric_reg(tok, type)) >= 0 - && (*type == OP_REG32 || *type == OP_REG64)) { - ; -#endif - } else { - error_32: - expect("register"); - } - next(); - return reg; -} - -static void parse_operand(TCCState *s1, Operand *op) -{ - ExprValue e; - int reg, indir; - const char *p; - - indir = 0; - if (tok == '*') { - next(); - indir = OP_INDIR; - } - - if (tok == '%') { - next(); - if (tok >= TOK_ASM_al && tok <= TOK_ASM_db7) { - reg = tok - TOK_ASM_al; - op->type = 1 << (reg >> 3); /* WARNING: do not change constant order */ - op->reg = reg & 7; - if ((op->type & OP_REG) && op->reg == TREG_XAX) - op->type |= OP_EAX; - else if (op->type == OP_REG8 && op->reg == TREG_XCX) - op->type |= OP_CL; - else if (op->type == OP_REG16 && op->reg == TREG_XDX) - op->type |= OP_DX; - } else if (tok >= TOK_ASM_dr0 && tok <= TOK_ASM_dr7) { - op->type = OP_DB; - op->reg = tok - TOK_ASM_dr0; - } else if (tok >= TOK_ASM_es && tok <= TOK_ASM_gs) { - op->type = OP_SEG; - op->reg = tok - TOK_ASM_es; - } else if (tok == TOK_ASM_st) { - op->type = OP_ST; - op->reg = 0; - next(); - if (tok == '(') { - next(); - if (tok != TOK_PPNUM) - goto reg_error; - p = tokc.str.data; - reg = p[0] - '0'; - if ((unsigned)reg >= 8 || p[1] != '\0') - goto reg_error; - op->reg = reg; - next(); - skip(')'); - } - if (op->reg == 0) - op->type |= OP_ST0; - goto no_skip; -#ifdef TCC_TARGET_X86_64 - } else if (tok >= TOK_ASM_spl && tok <= TOK_ASM_dil) { - op->type = OP_REG8 | OP_REG8_LOW; - op->reg = 4 + tok - TOK_ASM_spl; - } else if ((op->reg = asm_parse_numeric_reg(tok, &op->type)) >= 0) { - ; -#endif - } else { - reg_error: - tcc_error("unknown register %%%s", get_tok_str(tok, &tokc)); - } - next(); - no_skip: ; - } else if (tok == '$') { - /* constant value */ - next(); - asm_expr(s1, &e); - op->type = OP_IM32; - op->e = e; - if (!op->e.sym) { - if (op->e.v == (uint8_t)op->e.v) - op->type |= OP_IM8; - if (op->e.v == (int8_t)op->e.v) - op->type |= OP_IM8S; - if (op->e.v == (uint16_t)op->e.v) - op->type |= OP_IM16; -#ifdef TCC_TARGET_X86_64 - if (op->e.v != (int32_t)op->e.v && op->e.v != (uint32_t)op->e.v) - op->type = OP_IM64; -#endif - } - } else { - /* address(reg,reg2,shift) with all variants */ - op->type = OP_EA; - op->reg = -1; - op->reg2 = -1; - op->shift = 0; - if (tok != '(') { - asm_expr(s1, &e); - op->e = e; - } else { - next(); - if (tok == '%') { - unget_tok('('); - op->e.v = 0; - op->e.sym = NULL; - } else { - /* bracketed offset expression */ - asm_expr(s1, &e); - if (tok != ')') - expect(")"); - next(); - op->e.v = e.v; - op->e.sym = e.sym; - } - op->e.pcrel = 0; - } - if (tok == '(') { - unsigned int type = 0; - next(); - if (tok != ',') { - op->reg = asm_parse_reg(&type); - } - if (tok == ',') { - next(); - if (tok != ',') { - op->reg2 = asm_parse_reg(&type); - } - if (tok == ',') { - next(); - op->shift = get_reg_shift(s1); - } - } - if (type & OP_REG32) - op->type |= OP_EA32; - skip(')'); - } - if (op->reg == -1 && op->reg2 == -1) - op->type |= OP_ADDR; - } - op->type |= indir; -} - -/* XXX: unify with C code output ? */ -ST_FUNC void gen_expr32(ExprValue *pe) -{ - if (pe->pcrel) - /* If PC-relative, always set VT_SYM, even without symbol, - so as to force a relocation to be emitted. */ - gen_addrpc32(VT_SYM, pe->sym, pe->v); - else - gen_addr32(pe->sym ? VT_SYM : 0, pe->sym, pe->v); -} - -#ifdef TCC_TARGET_X86_64 -ST_FUNC void gen_expr64(ExprValue *pe) -{ - gen_addr64(pe->sym ? VT_SYM : 0, pe->sym, pe->v); -} -#endif - -/* XXX: unify with C code output ? */ -static void gen_disp32(ExprValue *pe) -{ - Sym *sym = pe->sym; - ElfSym *esym = elfsym(sym); - if (esym && esym->st_shndx == cur_text_section->sh_num) { - /* same section: we can output an absolute value. Note - that the TCC compiler behaves differently here because - it always outputs a relocation to ease (future) code - elimination in the linker */ - gen_le32(pe->v + esym->st_value - ind - 4); - } else { - if (sym && sym->type.t == VT_VOID) { - sym->type.t = VT_FUNC; - sym->type.ref = NULL; - } - gen_addrpc32(VT_SYM, sym, pe->v); - } -} - -/* generate the modrm operand */ -static inline int asm_modrm(int reg, Operand *op) -{ - int mod, reg1, reg2, sib_reg1; - - if (op->type & (OP_REG | OP_MMX | OP_SSE)) { - g(0xc0 + (reg << 3) + op->reg); - } else if (op->reg == -1 && op->reg2 == -1) { - /* displacement only */ -#ifdef TCC_TARGET_X86_64 - g(0x04 + (reg << 3)); - g(0x25); -#else - g(0x05 + (reg << 3)); -#endif - gen_expr32(&op->e); -#ifdef TCC_TARGET_X86_64 - } else if (op->reg == -2) { - ExprValue *pe = &op->e; - g(0x05 + (reg << 3)); - gen_addrpc32(pe->sym ? VT_SYM : 0, pe->sym, pe->v); - return ind; -#endif - } else { - sib_reg1 = op->reg; - /* fist compute displacement encoding */ - if (sib_reg1 == -1) { - sib_reg1 = 5; - mod = 0x00; - } else if (op->e.v == 0 && !op->e.sym && op->reg != 5) { - mod = 0x00; - } else if (op->e.v == (int8_t)op->e.v && !op->e.sym) { - mod = 0x40; - } else { - mod = 0x80; - } - /* compute if sib byte needed */ - reg1 = op->reg; - if (op->reg2 != -1) - reg1 = 4; - g(mod + (reg << 3) + reg1); - if (reg1 == 4) { - /* add sib byte */ - reg2 = op->reg2; - if (reg2 == -1) - reg2 = 4; /* indicate no index */ - g((op->shift << 6) + (reg2 << 3) + sib_reg1); - } - /* add offset */ - if (mod == 0x40) { - g(op->e.v); - } else if (mod == 0x80 || op->reg == -1) { - gen_expr32(&op->e); - } - } - return 0; -} - -#ifdef TCC_TARGET_X86_64 -#define REX_W 0x48 -#define REX_R 0x44 -#define REX_X 0x42 -#define REX_B 0x41 - -static void asm_rex(int width64, Operand *ops, int nb_ops, int *op_type, - int regi, int rmi) -{ - unsigned char rex = width64 ? 0x48 : 0; - int saw_high_8bit = 0; - int i; - if (rmi == -1) { - /* No mod/rm byte, but we might have a register op nevertheless - (we will add it to the opcode later). */ - for(i = 0; i < nb_ops; i++) { - if (op_type[i] & (OP_REG | OP_ST)) { - if (ops[i].reg >= 8) { - rex |= REX_B; - ops[i].reg -= 8; - } else if (ops[i].type & OP_REG8_LOW) - rex |= 0x40; - else if (ops[i].type & OP_REG8 && ops[i].reg >= 4) - /* An 8 bit reg >= 4 without REG8 is ah/ch/dh/bh */ - saw_high_8bit = ops[i].reg; - break; - } - } - } else { - if (regi != -1) { - if (ops[regi].reg >= 8) { - rex |= REX_R; - ops[regi].reg -= 8; - } else if (ops[regi].type & OP_REG8_LOW) - rex |= 0x40; - else if (ops[regi].type & OP_REG8 && ops[regi].reg >= 4) - /* An 8 bit reg >= 4 without REG8 is ah/ch/dh/bh */ - saw_high_8bit = ops[regi].reg; - } - if (ops[rmi].type & (OP_REG | OP_MMX | OP_SSE | OP_CR | OP_EA)) { - if (ops[rmi].reg >= 8) { - rex |= REX_B; - ops[rmi].reg -= 8; - } else if (ops[rmi].type & OP_REG8_LOW) - rex |= 0x40; - else if (ops[rmi].type & OP_REG8 && ops[rmi].reg >= 4) - /* An 8 bit reg >= 4 without REG8 is ah/ch/dh/bh */ - saw_high_8bit = ops[rmi].reg; - } - if (ops[rmi].type & OP_EA && ops[rmi].reg2 >= 8) { - rex |= REX_X; - ops[rmi].reg2 -= 8; - } - } - if (rex) { - if (saw_high_8bit) - tcc_error("can't encode register %%%ch when REX prefix is required", - "acdb"[saw_high_8bit-4]); - g(rex); - } -} -#endif - -static void maybe_print_stats (void) -{ - static int already = 1; - if (!already) - /* print stats about opcodes */ - { - const struct ASMInstr *pa; - int freq[4]; - int op_vals[500]; - int nb_op_vals, i, j; - - already = 1; - nb_op_vals = 0; - memset(freq, 0, sizeof(freq)); - for(pa = asm_instrs; pa->sym != 0; pa++) { - freq[pa->nb_ops]++; - //for(i=0;inb_ops;i++) { - for(j=0;jop_type[i] == op_vals[j]) - if (pa->instr_type == op_vals[j]) - goto found; - } - //op_vals[nb_op_vals++] = pa->op_type[i]; - op_vals[nb_op_vals++] = pa->instr_type; - found: ; - //} - } - for(i=0;i= TOK_ASM_wait && opcode <= TOK_ASM_repnz) - unget_tok(';'); - - /* get operands */ - pop = ops; - nb_ops = 0; - seg_prefix = 0; - alltypes = 0; - for(;;) { - if (tok == ';' || tok == TOK_LINEFEED) - break; - if (nb_ops >= MAX_OPERANDS) { - tcc_error("incorrect number of operands"); - } - parse_operand(s1, pop); - if (tok == ':') { - if (pop->type != OP_SEG || seg_prefix) - tcc_error("incorrect prefix"); - seg_prefix = segment_prefixes[pop->reg]; - next(); - parse_operand(s1, pop); - if (!(pop->type & OP_EA)) { - tcc_error("segment prefix must be followed by memory reference"); - } - } - pop++; - nb_ops++; - if (tok != ',') - break; - next(); - } - - s = 0; /* avoid warning */ - -again: - /* optimize matching by using a lookup table (no hashing is needed - !) */ - for(pa = asm_instrs; pa->sym != 0; pa++) { - int it = pa->instr_type & OPCT_MASK; - s = 0; - if (it == OPC_FARITH) { - v = opcode - pa->sym; - if (!((unsigned)v < 8 * 6 && (v % 6) == 0)) - continue; - } else if (it == OPC_ARITH) { - if (!(opcode >= pa->sym && opcode < pa->sym + 8*NBWLX)) - continue; - s = (opcode - pa->sym) % NBWLX; - if ((pa->instr_type & OPC_BWLX) == OPC_WLX) - { - /* We need to reject the xxxb opcodes that we accepted above. - Note that pa->sym for WLX opcodes is the 'w' token, - to get the 'b' token subtract one. */ - if (((opcode - pa->sym + 1) % NBWLX) == 0) - continue; - s++; - } - } else if (it == OPC_SHIFT) { - if (!(opcode >= pa->sym && opcode < pa->sym + 7*NBWLX)) - continue; - s = (opcode - pa->sym) % NBWLX; - } else if (it == OPC_TEST) { - if (!(opcode >= pa->sym && opcode < pa->sym + NB_TEST_OPCODES)) - continue; - /* cmovxx is a test opcode but accepts multiple sizes. - The suffixes aren't encoded in the table, instead we - simply force size autodetection always and deal with suffixed - variants below when we don't find e.g. "cmovzl". */ - if (pa->instr_type & OPC_WLX) - s = NBWLX - 1; - } else if (pa->instr_type & OPC_B) { -#ifdef TCC_TARGET_X86_64 - /* Some instructions don't have the full size but only - bwl form. insb e.g. */ - if ((pa->instr_type & OPC_WLQ) != OPC_WLQ - && !(opcode >= pa->sym && opcode < pa->sym + NBWLX-1)) - continue; -#endif - if (!(opcode >= pa->sym && opcode < pa->sym + NBWLX)) - continue; - s = opcode - pa->sym; - } else if (pa->instr_type & OPC_WLX) { - if (!(opcode >= pa->sym && opcode < pa->sym + NBWLX-1)) - continue; - s = opcode - pa->sym + 1; - } else { - if (pa->sym != opcode) - continue; - } - if (pa->nb_ops != nb_ops) - continue; -#ifdef TCC_TARGET_X86_64 - /* Special case for moves. Selecting the IM64->REG64 form - should only be done if we really have an >32bit imm64, and that - is hardcoded. Ignore it here. */ - if (pa->opcode == 0xb0 && ops[0].type != OP_IM64 - && (ops[1].type & OP_REG) == OP_REG64 - && !(pa->instr_type & OPC_0F)) - continue; -#endif - /* now decode and check each operand */ - alltypes = 0; - for(i = 0; i < nb_ops; i++) { - int op1, op2; - op1 = pa->op_type[i]; - op2 = op1 & 0x1f; - switch(op2) { - case OPT_IM: - v = OP_IM8 | OP_IM16 | OP_IM32; - break; - case OPT_REG: - v = OP_REG8 | OP_REG16 | OP_REG32 | OP_REG64; - break; - case OPT_REGW: - v = OP_REG16 | OP_REG32 | OP_REG64; - break; - case OPT_IMW: - v = OP_IM16 | OP_IM32; - break; - case OPT_MMXSSE: - v = OP_MMX | OP_SSE; - break; - case OPT_DISP: - case OPT_DISP8: - v = OP_ADDR; - break; - default: - v = 1 << op2; - break; - } - if (op1 & OPT_EA) - v |= OP_EA; - op_type[i] = v; - if ((ops[i].type & v) == 0) - goto next; - alltypes |= ops[i].type; - } - /* all is matching ! */ - break; - next: ; - } - if (pa->sym == 0) { - if (opcode >= TOK_ASM_first && opcode <= TOK_ASM_last) { - int b; - b = op0_codes[opcode - TOK_ASM_first]; - if (b & 0xff00) - g(b >> 8); - g(b); - return; - } else if (opcode <= TOK_ASM_alllast) { - tcc_error("bad operand with opcode '%s'", - get_tok_str(opcode, NULL)); - } else { - /* Special case for cmovcc, we accept size suffixes but ignore - them, but we don't want them to blow up our tables. */ - TokenSym *ts = table_ident[opcode - TOK_IDENT]; - if (ts->len >= 6 - && strchr("wlq", ts->str[ts->len-1]) - && !memcmp(ts->str, "cmov", 4)) { - opcode = tok_alloc(ts->str, ts->len-1)->tok; - goto again; - } - tcc_error("unknown opcode '%s'", ts->str); - } - } - /* if the size is unknown, then evaluate it (OPC_B or OPC_WL case) */ - autosize = NBWLX-1; -#ifdef TCC_TARGET_X86_64 - /* XXX the autosize should rather be zero, to not have to adjust this - all the time. */ - if ((pa->instr_type & OPC_BWLQ) == OPC_B) - autosize = NBWLX-2; -#endif - if (s == autosize) { - /* Check for register operands providing hints about the size. - Start from the end, i.e. destination operands. This matters - only for opcodes accepting different sized registers, lar and lsl - are such opcodes. */ - for(i = nb_ops - 1; s == autosize && i >= 0; i--) { - if ((ops[i].type & OP_REG) && !(op_type[i] & (OP_CL | OP_DX))) - s = reg_to_size[ops[i].type & OP_REG]; - } - if (s == autosize) { - if ((opcode == TOK_ASM_push || opcode == TOK_ASM_pop) && - (ops[0].type & (OP_SEG | OP_IM8S | OP_IM32))) - s = 2; - else if ((opcode == TOK_ASM_push || opcode == TOK_ASM_pop) && - (ops[0].type & OP_EA)) - s = NBWLX - 2; - else - tcc_error("cannot infer opcode suffix"); - } - } - -#ifdef TCC_TARGET_X86_64 - /* Generate addr32 prefix if needed */ - for(i = 0; i < nb_ops; i++) { - if (ops[i].type & OP_EA32) { - g(0x67); - break; - } - } -#endif - /* generate data16 prefix if needed */ - p66 = 0; - if (s == 1) - p66 = 1; - else { - /* accepting mmx+sse in all operands --> needs 0x66 to - switch to sse mode. Accepting only sse in an operand --> is - already SSE insn and needs 0x66/f2/f3 handling. */ - for (i = 0; i < nb_ops; i++) - if ((op_type[i] & (OP_MMX | OP_SSE)) == (OP_MMX | OP_SSE) - && ops[i].type & OP_SSE) - p66 = 1; - } - if (p66) - g(0x66); -#ifdef TCC_TARGET_X86_64 - rex64 = 0; - if (pa->instr_type & OPC_48) - rex64 = 1; - else if (s == 3 || (alltypes & OP_REG64)) { - /* generate REX prefix */ - int default64 = 0; - for(i = 0; i < nb_ops; i++) { - if (op_type[i] == OP_REG64 && pa->opcode != 0xb8) { - /* If only 64bit regs are accepted in one operand - this is a default64 instruction without need for - REX prefixes, except for movabs(0xb8). */ - default64 = 1; - break; - } - } - /* XXX find better encoding for the default64 instructions. */ - if (((opcode != TOK_ASM_push && opcode != TOK_ASM_pop - && opcode != TOK_ASM_pushw && opcode != TOK_ASM_pushl - && opcode != TOK_ASM_pushq && opcode != TOK_ASM_popw - && opcode != TOK_ASM_popl && opcode != TOK_ASM_popq - && opcode != TOK_ASM_call && opcode != TOK_ASM_jmp)) - && !default64) - rex64 = 1; - } -#endif - - /* now generates the operation */ - if (OPCT_IS(pa->instr_type, OPC_FWAIT)) - g(0x9b); - if (seg_prefix) - g(seg_prefix); - - v = pa->opcode; - if (pa->instr_type & OPC_0F) - v = ((v & ~0xff) << 8) | 0x0f00 | (v & 0xff); - if ((v == 0x69 || v == 0x6b) && nb_ops == 2) { - /* kludge for imul $im, %reg */ - nb_ops = 3; - ops[2] = ops[1]; - op_type[2] = op_type[1]; - } else if (v == 0xcd && ops[0].e.v == 3 && !ops[0].e.sym) { - v--; /* int $3 case */ - nb_ops = 0; - } else if ((v == 0x06 || v == 0x07)) { - if (ops[0].reg >= 4) { - /* push/pop %fs or %gs */ - v = 0x0fa0 + (v - 0x06) + ((ops[0].reg - 4) << 3); - } else { - v += ops[0].reg << 3; - } - nb_ops = 0; - } else if (v <= 0x05) { - /* arith case */ - v += ((opcode - TOK_ASM_addb) / NBWLX) << 3; - } else if ((pa->instr_type & (OPCT_MASK | OPC_MODRM)) == OPC_FARITH) { - /* fpu arith case */ - v += ((opcode - pa->sym) / 6) << 3; - } - - /* search which operand will be used for modrm */ - modrm_index = -1; - modreg_index = -1; - if (pa->instr_type & OPC_MODRM) { - if (!nb_ops) { - /* A modrm opcode without operands is a special case (e.g. mfence). - It has a group and acts as if there's an register operand 0 - (ax). */ - i = 0; - ops[i].type = OP_REG; - ops[i].reg = 0; - goto modrm_found; - } - /* first look for an ea operand */ - for(i = 0;i < nb_ops; i++) { - if (op_type[i] & OP_EA) - goto modrm_found; - } - /* then if not found, a register or indirection (shift instructions) */ - for(i = 0;i < nb_ops; i++) { - if (op_type[i] & (OP_REG | OP_MMX | OP_SSE | OP_INDIR)) - goto modrm_found; - } -#ifdef ASM_DEBUG - tcc_error("bad op table"); -#endif - modrm_found: - modrm_index = i; - /* if a register is used in another operand then it is - used instead of group */ - for(i = 0;i < nb_ops; i++) { - int t = op_type[i]; - if (i != modrm_index && - (t & (OP_REG | OP_MMX | OP_SSE | OP_CR | OP_TR | OP_DB | OP_SEG))) { - modreg_index = i; - break; - } - } - } -#ifdef TCC_TARGET_X86_64 - asm_rex (rex64, ops, nb_ops, op_type, modreg_index, modrm_index); -#endif - - if (pa->instr_type & OPC_REG) { - /* mov $im, %reg case */ - if (v == 0xb0 && s >= 1) - v += 7; - for(i = 0; i < nb_ops; i++) { - if (op_type[i] & (OP_REG | OP_ST)) { - v += ops[i].reg; - break; - } - } - } - if (pa->instr_type & OPC_B) - v += s >= 1; - if (nb_ops == 1 && pa->op_type[0] == OPT_DISP8) { - ElfSym *esym; - int jmp_disp; - - /* see if we can really generate the jump with a byte offset */ - esym = elfsym(ops[0].e.sym); - if (!esym || esym->st_shndx != cur_text_section->sh_num) - goto no_short_jump; - jmp_disp = ops[0].e.v + esym->st_value - ind - 2 - (v >= 0xff); - if (jmp_disp == (int8_t)jmp_disp) { - /* OK to generate jump */ - ops[0].e.sym = 0; - ops[0].e.v = jmp_disp; - op_type[0] = OP_IM8S; - } else { - no_short_jump: - /* long jump will be allowed. need to modify the - opcode slightly */ - if (v == 0xeb) /* jmp */ - v = 0xe9; - else if (v == 0x70) /* jcc */ - v += 0x0f10; - else - tcc_error("invalid displacement"); - } - } - if (OPCT_IS(pa->instr_type, OPC_TEST)) - v += test_bits[opcode - pa->sym]; - op1 = v >> 16; - if (op1) - g(op1); - op1 = (v >> 8) & 0xff; - if (op1) - g(op1); - g(v); - - if (OPCT_IS(pa->instr_type, OPC_SHIFT)) { - reg = (opcode - pa->sym) / NBWLX; - if (reg == 6) - reg = 7; - } else if (OPCT_IS(pa->instr_type, OPC_ARITH)) { - reg = (opcode - pa->sym) / NBWLX; - } else if (OPCT_IS(pa->instr_type, OPC_FARITH)) { - reg = (opcode - pa->sym) / 6; - } else { - reg = (pa->instr_type >> OPC_GROUP_SHIFT) & 7; - } - - pc = 0; - if (pa->instr_type & OPC_MODRM) { - /* if a register is used in another operand then it is - used instead of group */ - if (modreg_index >= 0) - reg = ops[modreg_index].reg; - pc = asm_modrm(reg, &ops[modrm_index]); - } - - /* emit constants */ -#ifndef TCC_TARGET_X86_64 - if (!(pa->instr_type & OPC_0F) - && (pa->opcode == 0x9a || pa->opcode == 0xea)) { - /* ljmp or lcall kludge */ - gen_expr32(&ops[1].e); - if (ops[0].e.sym) - tcc_error("cannot relocate"); - gen_le16(ops[0].e.v); - return; - } -#endif - for(i = 0;i < nb_ops; i++) { - v = op_type[i]; - if (v & (OP_IM8 | OP_IM16 | OP_IM32 | OP_IM64 | OP_IM8S | OP_ADDR)) { - /* if multiple sizes are given it means we must look - at the op size */ - if ((v | OP_IM8 | OP_IM64) == (OP_IM8 | OP_IM16 | OP_IM32 | OP_IM64)) { - if (s == 0) - v = OP_IM8; - else if (s == 1) - v = OP_IM16; - else if (s == 2 || (v & OP_IM64) == 0) - v = OP_IM32; - else - v = OP_IM64; - } - - if ((v & (OP_IM8 | OP_IM8S | OP_IM16)) && ops[i].e.sym) - tcc_error("cannot relocate"); - - if (v & (OP_IM8 | OP_IM8S)) { - g(ops[i].e.v); - } else if (v & OP_IM16) { - gen_le16(ops[i].e.v); -#ifdef TCC_TARGET_X86_64 - } else if (v & OP_IM64) { - gen_expr64(&ops[i].e); -#endif - } else if (pa->op_type[i] == OPT_DISP || pa->op_type[i] == OPT_DISP8) { - gen_disp32(&ops[i].e); - } else { - gen_expr32(&ops[i].e); - } - } - } - - /* after immediate operands, adjust pc-relative address */ - if (pc) - add32le(cur_text_section->data + pc - 4, pc - ind); -} - -/* return the constraint priority (we allocate first the lowest - numbered constraints) */ -static inline int constraint_priority(const char *str) -{ - int priority, c, pr; - - /* we take the lowest priority */ - priority = 0; - for(;;) { - c = *str; - if (c == '\0') - break; - str++; - switch(c) { - case 'A': - pr = 0; - break; - case 'a': - case 'b': - case 'c': - case 'd': - case 'S': - case 'D': - pr = 1; - break; - case 'q': - pr = 2; - break; - case 'r': - case 'R': - case 'p': - pr = 3; - break; - case 'N': - case 'M': - case 'I': - case 'e': - case 'i': - case 'm': - case 'g': - pr = 4; - break; - default: - tcc_error("unknown constraint '%c'", c); - pr = 0; - } - if (pr > priority) - priority = pr; - } - return priority; -} - -static const char *skip_constraint_modifiers(const char *p) -{ - while (*p == '=' || *p == '&' || *p == '+' || *p == '%') - p++; - return p; -} - -/* If T (a token) is of the form "%reg" returns the register - number and type, otherwise return -1. */ -ST_FUNC int asm_parse_regvar (int t) -{ - const char *s; - Operand op; - if (t < TOK_IDENT) - return -1; - s = table_ident[t - TOK_IDENT]->str; - if (s[0] != '%') - return -1; - t = tok_alloc(s+1, strlen(s)-1)->tok; - unget_tok(t); - unget_tok('%'); - parse_operand(tcc_state, &op); - /* Accept only integer regs for now. */ - if (op.type & OP_REG) - return op.reg; - else - return -1; -} - -#define REG_OUT_MASK 0x01 -#define REG_IN_MASK 0x02 - -#define is_reg_allocated(reg) (regs_allocated[reg] & reg_mask) - -ST_FUNC void asm_compute_constraints(ASMOperand *operands, - int nb_operands, int nb_outputs, - const uint8_t *clobber_regs, - int *pout_reg) -{ - ASMOperand *op; - int sorted_op[MAX_ASM_OPERANDS]; - int i, j, k, p1, p2, tmp, reg, c, reg_mask; - const char *str; - uint8_t regs_allocated[NB_ASM_REGS]; - - /* init fields */ - for(i=0;iinput_index = -1; - op->ref_index = -1; - op->reg = -1; - op->is_memory = 0; - op->is_rw = 0; - } - /* compute constraint priority and evaluate references to output - constraints if input constraints */ - for(i=0;iconstraint; - str = skip_constraint_modifiers(str); - if (isnum(*str) || *str == '[') { - /* this is a reference to another constraint */ - k = find_constraint(operands, nb_operands, str, NULL); - if ((unsigned)k >= i || i < nb_outputs) - tcc_error("invalid reference in constraint %d ('%s')", - i, str); - op->ref_index = k; - if (operands[k].input_index >= 0) - tcc_error("cannot reference twice the same operand"); - operands[k].input_index = i; - op->priority = 5; - } else if ((op->vt->r & VT_VALMASK) == VT_LOCAL - && op->vt->sym - && (reg = op->vt->sym->r & VT_VALMASK) < VT_CONST) { - op->priority = 1; - op->reg = reg; - } else { - op->priority = constraint_priority(str); - } - } - - /* sort operands according to their priority */ - for(i=0;iconstraint; - /* no need to allocate references */ - if (op->ref_index >= 0) - continue; - /* select if register is used for output, input or both */ - if (op->input_index >= 0) { - reg_mask = REG_IN_MASK | REG_OUT_MASK; - } else if (j < nb_outputs) { - reg_mask = REG_OUT_MASK; - } else { - reg_mask = REG_IN_MASK; - } - if (op->reg >= 0) { - if (is_reg_allocated(op->reg)) - tcc_error("asm regvar requests register that's taken already"); - reg = op->reg; - goto reg_found; - } - try_next: - c = *str++; - switch(c) { - case '=': - goto try_next; - case '+': - op->is_rw = 1; - /* FALL THRU */ - case '&': - if (j >= nb_outputs) - tcc_error("'%c' modifier can only be applied to outputs", c); - reg_mask = REG_IN_MASK | REG_OUT_MASK; - goto try_next; - case 'A': - /* allocate both eax and edx */ - if (is_reg_allocated(TREG_XAX) || - is_reg_allocated(TREG_XDX)) - goto try_next; - op->is_llong = 1; - op->reg = TREG_XAX; - regs_allocated[TREG_XAX] |= reg_mask; - regs_allocated[TREG_XDX] |= reg_mask; - break; - case 'a': - reg = TREG_XAX; - goto alloc_reg; - case 'b': - reg = 3; - goto alloc_reg; - case 'c': - reg = TREG_XCX; - goto alloc_reg; - case 'd': - reg = TREG_XDX; - goto alloc_reg; - case 'S': - reg = 6; - goto alloc_reg; - case 'D': - reg = 7; - alloc_reg: - if (is_reg_allocated(reg)) - goto try_next; - goto reg_found; - case 'q': - /* eax, ebx, ecx or edx */ - for(reg = 0; reg < 4; reg++) { - if (!is_reg_allocated(reg)) - goto reg_found; - } - goto try_next; - case 'r': - case 'R': - case 'p': /* A general address, for x86(64) any register is acceptable*/ - /* any general register */ - for(reg = 0; reg < 8; reg++) { - if (!is_reg_allocated(reg)) - goto reg_found; - } - goto try_next; - reg_found: - /* now we can reload in the register */ - op->is_llong = 0; - op->reg = reg; - regs_allocated[reg] |= reg_mask; - break; - case 'e': - case 'i': - if (!((op->vt->r & (VT_VALMASK | VT_LVAL)) == VT_CONST)) - goto try_next; - break; - case 'I': - case 'N': - case 'M': - if (!((op->vt->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST)) - goto try_next; - break; - case 'm': - case 'g': - /* nothing special to do because the operand is already in - memory, except if the pointer itself is stored in a - memory variable (VT_LLOCAL case) */ - /* XXX: fix constant case */ - /* if it is a reference to a memory zone, it must lie - in a register, so we reserve the register in the - input registers and a load will be generated - later */ - if (j < nb_outputs || c == 'm') { - if ((op->vt->r & VT_VALMASK) == VT_LLOCAL) { - /* any general register */ - for(reg = 0; reg < 8; reg++) { - if (!(regs_allocated[reg] & REG_IN_MASK)) - goto reg_found1; - } - goto try_next; - reg_found1: - /* now we can reload in the register */ - regs_allocated[reg] |= REG_IN_MASK; - op->reg = reg; - op->is_memory = 1; - } - } - break; - default: - tcc_error("asm constraint %d ('%s') could not be satisfied", - j, op->constraint); - break; - } - /* if a reference is present for that operand, we assign it too */ - if (op->input_index >= 0) { - operands[op->input_index].reg = op->reg; - operands[op->input_index].is_llong = op->is_llong; - } - } - - /* compute out_reg. It is used to store outputs registers to memory - locations references by pointers (VT_LLOCAL case) */ - *pout_reg = -1; - for(i=0;ireg >= 0 && - (op->vt->r & VT_VALMASK) == VT_LLOCAL && - !op->is_memory) { - for(reg = 0; reg < 8; reg++) { - if (!(regs_allocated[reg] & REG_OUT_MASK)) - goto reg_found2; - } - tcc_error("could not find free output register for reloading"); - reg_found2: - *pout_reg = reg; - break; - } - } - - /* print sorted constraints */ -#ifdef ASM_DEBUG - for(i=0;iid ? get_tok_str(op->id, NULL) : "", - op->constraint, - op->vt->r, - op->reg); - } - if (*pout_reg >= 0) - printf("out_reg=%d\n", *pout_reg); -#endif -} - -ST_FUNC void subst_asm_operand(CString *add_str, - SValue *sv, int modifier) -{ - int r, reg, size, val; - char buf[64]; - - r = sv->r; - if ((r & VT_VALMASK) == VT_CONST) { - if (!(r & VT_LVAL) && modifier != 'c' && modifier != 'n' && - modifier != 'P') - cstr_ccat(add_str, '$'); - if (r & VT_SYM) { - const char *name = get_tok_str(sv->sym->v, NULL); - if (sv->sym->v >= SYM_FIRST_ANOM) { - /* In case of anonymous symbols ("L.42", used - for static data labels) we can't find them - in the C symbol table when later looking up - this name. So enter them now into the asm label - list when we still know the symbol. */ - get_asm_sym(tok_alloc(name, strlen(name))->tok, sv->sym); - } - cstr_cat(add_str, name, -1); - if ((uint32_t)sv->c.i == 0) - goto no_offset; - cstr_ccat(add_str, '+'); - } - val = sv->c.i; - if (modifier == 'n') - val = -val; - snprintf(buf, sizeof(buf), "%d", (int)sv->c.i); - cstr_cat(add_str, buf, -1); - no_offset:; -#ifdef TCC_TARGET_X86_64 - if (r & VT_LVAL) - cstr_cat(add_str, "(%rip)", -1); -#endif - } else if ((r & VT_VALMASK) == VT_LOCAL) { -#ifdef TCC_TARGET_X86_64 - snprintf(buf, sizeof(buf), "%d(%%rbp)", (int)sv->c.i); -#else - snprintf(buf, sizeof(buf), "%d(%%ebp)", (int)sv->c.i); -#endif - cstr_cat(add_str, buf, -1); - } else if (r & VT_LVAL) { - reg = r & VT_VALMASK; - if (reg >= VT_CONST) - tcc_error("internal compiler error"); - snprintf(buf, sizeof(buf), "(%%%s)", -#ifdef TCC_TARGET_X86_64 - get_tok_str(TOK_ASM_rax + reg, NULL) -#else - get_tok_str(TOK_ASM_eax + reg, NULL) -#endif - ); - cstr_cat(add_str, buf, -1); - } else { - /* register case */ - reg = r & VT_VALMASK; - if (reg >= VT_CONST) - tcc_error("internal compiler error"); - - /* choose register operand size */ - if ((sv->type.t & VT_BTYPE) == VT_BYTE || - (sv->type.t & VT_BTYPE) == VT_BOOL) - size = 1; - else if ((sv->type.t & VT_BTYPE) == VT_SHORT) - size = 2; -#ifdef TCC_TARGET_X86_64 - else if ((sv->type.t & VT_BTYPE) == VT_LLONG || - (sv->type.t & VT_BTYPE) == VT_PTR) - size = 8; -#endif - else - size = 4; - if (size == 1 && reg >= 4) - size = 4; - - if (modifier == 'b') { - if (reg >= 4) - tcc_error("cannot use byte register"); - size = 1; - } else if (modifier == 'h') { - if (reg >= 4) - tcc_error("cannot use byte register"); - size = -1; - } else if (modifier == 'w') { - size = 2; - } else if (modifier == 'k') { - size = 4; -#ifdef TCC_TARGET_X86_64 - } else if (modifier == 'q') { - size = 8; -#endif - } - - switch(size) { - case -1: - reg = TOK_ASM_ah + reg; - break; - case 1: - reg = TOK_ASM_al + reg; - break; - case 2: - reg = TOK_ASM_ax + reg; - break; - default: - reg = TOK_ASM_eax + reg; - break; -#ifdef TCC_TARGET_X86_64 - case 8: - reg = TOK_ASM_rax + reg; - break; -#endif - } - snprintf(buf, sizeof(buf), "%%%s", get_tok_str(reg, NULL)); - cstr_cat(add_str, buf, -1); - } -} - -/* generate prolog and epilog code for asm statement */ -ST_FUNC void asm_gen_code(ASMOperand *operands, int nb_operands, - int nb_outputs, int is_output, - uint8_t *clobber_regs, - int out_reg) -{ - uint8_t regs_allocated[NB_ASM_REGS]; - ASMOperand *op; - int i, reg; - - /* Strictly speaking %Xbp and %Xsp should be included in the - call-preserved registers, but currently it doesn't matter. */ -#ifdef TCC_TARGET_X86_64 -#ifdef TCC_TARGET_PE - static uint8_t reg_saved[] = { 3, 6, 7, 12, 13, 14, 15 }; -#else - static uint8_t reg_saved[] = { 3, 12, 13, 14, 15 }; -#endif -#else - static uint8_t reg_saved[] = { 3, 6, 7 }; -#endif - - /* mark all used registers */ - memcpy(regs_allocated, clobber_regs, sizeof(regs_allocated)); - for(i = 0; i < nb_operands;i++) { - op = &operands[i]; - if (op->reg >= 0) - regs_allocated[op->reg] = 1; - } - if (!is_output) { - /* generate reg save code */ - for(i = 0; i < sizeof(reg_saved)/sizeof(reg_saved[0]); i++) { - reg = reg_saved[i]; - if (regs_allocated[reg]) { - if (reg >= 8) - g(0x41), reg-=8; - g(0x50 + reg); - } - } - - /* generate load code */ - for(i = 0; i < nb_operands; i++) { - op = &operands[i]; - if (op->reg >= 0) { - if ((op->vt->r & VT_VALMASK) == VT_LLOCAL && - op->is_memory) { - /* memory reference case (for both input and - output cases) */ - SValue sv; - sv = *op->vt; - sv.r = (sv.r & ~VT_VALMASK) | VT_LOCAL | VT_LVAL; - sv.type.t = VT_PTR; - load(op->reg, &sv); - } else if (i >= nb_outputs || op->is_rw) { - /* load value in register */ - load(op->reg, op->vt); - if (op->is_llong) { - SValue sv; - sv = *op->vt; - sv.c.i += 4; - load(TREG_XDX, &sv); - } - } - } - } - } else { - /* generate save code */ - for(i = 0 ; i < nb_outputs; i++) { - op = &operands[i]; - if (op->reg >= 0) { - if ((op->vt->r & VT_VALMASK) == VT_LLOCAL) { - if (!op->is_memory) { - SValue sv; - sv = *op->vt; - sv.r = (sv.r & ~VT_VALMASK) | VT_LOCAL; - sv.type.t = VT_PTR; - load(out_reg, &sv); - - sv = *op->vt; - sv.r = (sv.r & ~VT_VALMASK) | out_reg; - store(op->reg, &sv); - } - } else { - store(op->reg, op->vt); - if (op->is_llong) { - SValue sv; - sv = *op->vt; - sv.c.i += 4; - store(TREG_XDX, &sv); - } - } - } - } - /* generate reg restore code */ - for(i = sizeof(reg_saved)/sizeof(reg_saved[0]) - 1; i >= 0; i--) { - reg = reg_saved[i]; - if (regs_allocated[reg]) { - if (reg >= 8) - g(0x41), reg-=8; - g(0x58 + reg); - } - } - } -} - -ST_FUNC void asm_clobber(uint8_t *clobber_regs, const char *str) -{ - int reg; - TokenSym *ts; -#ifdef TCC_TARGET_X86_64 - unsigned int type; -#endif - - if (!strcmp(str, "memory") || - !strcmp(str, "cc") || - !strcmp(str, "flags")) - return; - ts = tok_alloc(str, strlen(str)); - reg = ts->tok; - if (reg >= TOK_ASM_eax && reg <= TOK_ASM_edi) { - reg -= TOK_ASM_eax; - } else if (reg >= TOK_ASM_ax && reg <= TOK_ASM_di) { - reg -= TOK_ASM_ax; -#ifdef TCC_TARGET_X86_64 - } else if (reg >= TOK_ASM_rax && reg <= TOK_ASM_rdi) { - reg -= TOK_ASM_rax; - } else if ((reg = asm_parse_numeric_reg(reg, &type)) >= 0) { - ; -#endif - } else { - tcc_error("invalid clobber register '%s'", str); - } - clobber_regs[reg] = 1; -} diff --git a/05/tcc-final-old/i386-asm.h b/05/tcc-final-old/i386-asm.h deleted file mode 100644 index 65d5179..0000000 --- a/05/tcc-final-old/i386-asm.h +++ /dev/null @@ -1,480 +0,0 @@ - DEF_ASM_OP0(clc, 0xf8) /* must be first OP0 */ - DEF_ASM_OP0(cld, 0xfc) - DEF_ASM_OP0(cli, 0xfa) - DEF_ASM_OP0(clts, 0x0f06) - DEF_ASM_OP0(cmc, 0xf5) - DEF_ASM_OP0(lahf, 0x9f) - DEF_ASM_OP0(sahf, 0x9e) - DEF_ASM_OP0(pusha, 0x60) - DEF_ASM_OP0(popa, 0x61) - DEF_ASM_OP0(pushfl, 0x9c) - DEF_ASM_OP0(popfl, 0x9d) - DEF_ASM_OP0(pushf, 0x9c) - DEF_ASM_OP0(popf, 0x9d) - DEF_ASM_OP0(stc, 0xf9) - DEF_ASM_OP0(std, 0xfd) - DEF_ASM_OP0(sti, 0xfb) - DEF_ASM_OP0(aaa, 0x37) - DEF_ASM_OP0(aas, 0x3f) - DEF_ASM_OP0(daa, 0x27) - DEF_ASM_OP0(das, 0x2f) - DEF_ASM_OP0(aad, 0xd50a) - DEF_ASM_OP0(aam, 0xd40a) - DEF_ASM_OP0(cbw, 0x6698) - DEF_ASM_OP0(cwd, 0x6699) - DEF_ASM_OP0(cwde, 0x98) - DEF_ASM_OP0(cdq, 0x99) - DEF_ASM_OP0(cbtw, 0x6698) - DEF_ASM_OP0(cwtl, 0x98) - DEF_ASM_OP0(cwtd, 0x6699) - DEF_ASM_OP0(cltd, 0x99) - DEF_ASM_OP0(int3, 0xcc) - DEF_ASM_OP0(into, 0xce) - DEF_ASM_OP0(iret, 0xcf) - DEF_ASM_OP0(rsm, 0x0faa) - DEF_ASM_OP0(hlt, 0xf4) - DEF_ASM_OP0(nop, 0x90) - DEF_ASM_OP0(pause, 0xf390) - DEF_ASM_OP0(xlat, 0xd7) - - /* strings */ -ALT(DEF_ASM_OP0L(cmpsb, 0xa6, 0, OPC_BWLX)) -ALT(DEF_ASM_OP0L(scmpb, 0xa6, 0, OPC_BWLX)) - -ALT(DEF_ASM_OP0L(insb, 0x6c, 0, OPC_BWL)) -ALT(DEF_ASM_OP0L(outsb, 0x6e, 0, OPC_BWL)) - -ALT(DEF_ASM_OP0L(lodsb, 0xac, 0, OPC_BWLX)) -ALT(DEF_ASM_OP0L(slodb, 0xac, 0, OPC_BWLX)) - -ALT(DEF_ASM_OP0L(movsb, 0xa4, 0, OPC_BWLX)) -ALT(DEF_ASM_OP0L(smovb, 0xa4, 0, OPC_BWLX)) - -ALT(DEF_ASM_OP0L(scasb, 0xae, 0, OPC_BWLX)) -ALT(DEF_ASM_OP0L(sscab, 0xae, 0, OPC_BWLX)) - -ALT(DEF_ASM_OP0L(stosb, 0xaa, 0, OPC_BWLX)) -ALT(DEF_ASM_OP0L(sstob, 0xaa, 0, OPC_BWLX)) - - /* bits */ - -ALT(DEF_ASM_OP2(bsfw, 0x0fbc, 0, OPC_MODRM | OPC_WLX, OPT_REGW | OPT_EA, OPT_REGW)) -ALT(DEF_ASM_OP2(bsrw, 0x0fbd, 0, OPC_MODRM | OPC_WLX, OPT_REGW | OPT_EA, OPT_REGW)) - -ALT(DEF_ASM_OP2(btw, 0x0fa3, 0, OPC_MODRM | OPC_WLX, OPT_REGW, OPT_REGW | OPT_EA)) -ALT(DEF_ASM_OP2(btw, 0x0fba, 4, OPC_MODRM | OPC_WLX, OPT_IM8, OPT_REGW | OPT_EA)) - -ALT(DEF_ASM_OP2(btsw, 0x0fab, 0, OPC_MODRM | OPC_WLX, OPT_REGW, OPT_REGW | OPT_EA)) -ALT(DEF_ASM_OP2(btsw, 0x0fba, 5, OPC_MODRM | OPC_WLX, OPT_IM8, OPT_REGW | OPT_EA)) - -ALT(DEF_ASM_OP2(btrw, 0x0fb3, 0, OPC_MODRM | OPC_WLX, OPT_REGW, OPT_REGW | OPT_EA)) -ALT(DEF_ASM_OP2(btrw, 0x0fba, 6, OPC_MODRM | OPC_WLX, OPT_IM8, OPT_REGW | OPT_EA)) - -ALT(DEF_ASM_OP2(btcw, 0x0fbb, 0, OPC_MODRM | OPC_WLX, OPT_REGW, OPT_REGW | OPT_EA)) -ALT(DEF_ASM_OP2(btcw, 0x0fba, 7, OPC_MODRM | OPC_WLX, OPT_IM8, OPT_REGW | OPT_EA)) - - /* prefixes */ - DEF_ASM_OP0(wait, 0x9b) - DEF_ASM_OP0(fwait, 0x9b) - DEF_ASM_OP0(aword, 0x67) - DEF_ASM_OP0(addr16, 0x67) - ALT(DEF_ASM_OP0(word, 0x66)) - DEF_ASM_OP0(data16, 0x66) - DEF_ASM_OP0(lock, 0xf0) - DEF_ASM_OP0(rep, 0xf3) - DEF_ASM_OP0(repe, 0xf3) - DEF_ASM_OP0(repz, 0xf3) - DEF_ASM_OP0(repne, 0xf2) - DEF_ASM_OP0(repnz, 0xf2) - - DEF_ASM_OP0(invd, 0x0f08) - DEF_ASM_OP0(wbinvd, 0x0f09) - DEF_ASM_OP0(cpuid, 0x0fa2) - DEF_ASM_OP0(wrmsr, 0x0f30) - DEF_ASM_OP0(rdtsc, 0x0f31) - DEF_ASM_OP0(rdmsr, 0x0f32) - DEF_ASM_OP0(rdpmc, 0x0f33) - DEF_ASM_OP0(ud2, 0x0f0b) - - /* NOTE: we took the same order as gas opcode definition order */ -ALT(DEF_ASM_OP2(movb, 0xa0, 0, OPC_BWLX, OPT_ADDR, OPT_EAX)) -ALT(DEF_ASM_OP2(movb, 0xa2, 0, OPC_BWLX, OPT_EAX, OPT_ADDR)) -ALT(DEF_ASM_OP2(movb, 0x88, 0, OPC_MODRM | OPC_BWLX, OPT_REG, OPT_EA | OPT_REG)) -ALT(DEF_ASM_OP2(movb, 0x8a, 0, OPC_MODRM | OPC_BWLX, OPT_EA | OPT_REG, OPT_REG)) -ALT(DEF_ASM_OP2(movb, 0xb0, 0, OPC_REG | OPC_BWLX, OPT_IM, OPT_REG)) -ALT(DEF_ASM_OP2(movb, 0xc6, 0, OPC_MODRM | OPC_BWLX, OPT_IM, OPT_REG | OPT_EA)) - -ALT(DEF_ASM_OP2(movw, 0x8c, 0, OPC_MODRM | OPC_WLX, OPT_SEG, OPT_EA | OPT_REG)) -ALT(DEF_ASM_OP2(movw, 0x8e, 0, OPC_MODRM | OPC_WLX, OPT_EA | OPT_REG, OPT_SEG)) - -ALT(DEF_ASM_OP2(movw, 0x0f20, 0, OPC_MODRM | OPC_WLX, OPT_CR, OPT_REG32)) -ALT(DEF_ASM_OP2(movw, 0x0f21, 0, OPC_MODRM | OPC_WLX, OPT_DB, OPT_REG32)) -ALT(DEF_ASM_OP2(movw, 0x0f24, 0, OPC_MODRM | OPC_WLX, OPT_TR, OPT_REG32)) -ALT(DEF_ASM_OP2(movw, 0x0f22, 0, OPC_MODRM | OPC_WLX, OPT_REG32, OPT_CR)) -ALT(DEF_ASM_OP2(movw, 0x0f23, 0, OPC_MODRM | OPC_WLX, OPT_REG32, OPT_DB)) -ALT(DEF_ASM_OP2(movw, 0x0f26, 0, OPC_MODRM | OPC_WLX, OPT_REG32, OPT_TR)) - -ALT(DEF_ASM_OP2(movsbl, 0x0fbe, 0, OPC_MODRM, OPT_REG8 | OPT_EA, OPT_REG32)) -ALT(DEF_ASM_OP2(movsbw, 0x660fbe, 0, OPC_MODRM, OPT_REG8 | OPT_EA, OPT_REG16)) -ALT(DEF_ASM_OP2(movswl, 0x0fbf, 0, OPC_MODRM, OPT_REG16 | OPT_EA, OPT_REG32)) -ALT(DEF_ASM_OP2(movzbw, 0x0fb6, 0, OPC_MODRM | OPC_WLX, OPT_REG8 | OPT_EA, OPT_REGW)) -ALT(DEF_ASM_OP2(movzwl, 0x0fb7, 0, OPC_MODRM, OPT_REG16 | OPT_EA, OPT_REG32)) - -ALT(DEF_ASM_OP1(pushw, 0x50, 0, OPC_REG | OPC_WLX, OPT_REGW)) -ALT(DEF_ASM_OP1(pushw, 0xff, 6, OPC_MODRM | OPC_WLX, OPT_REGW | OPT_EA)) -ALT(DEF_ASM_OP1(pushw, 0x6a, 0, OPC_WLX, OPT_IM8S)) -ALT(DEF_ASM_OP1(pushw, 0x68, 0, OPC_WLX, OPT_IM32)) -ALT(DEF_ASM_OP1(pushw, 0x06, 0, OPC_WLX, OPT_SEG)) - -ALT(DEF_ASM_OP1(popw, 0x58, 0, OPC_REG | OPC_WLX, OPT_REGW)) -ALT(DEF_ASM_OP1(popw, 0x8f, 0, OPC_MODRM | OPC_WLX, OPT_REGW | OPT_EA)) -ALT(DEF_ASM_OP1(popw, 0x07, 0, OPC_WLX, OPT_SEG)) - -ALT(DEF_ASM_OP2(xchgw, 0x90, 0, OPC_REG | OPC_WLX, OPT_REGW, OPT_EAX)) -ALT(DEF_ASM_OP2(xchgw, 0x90, 0, OPC_REG | OPC_WLX, OPT_EAX, OPT_REGW)) -ALT(DEF_ASM_OP2(xchgb, 0x86, 0, OPC_MODRM | OPC_BWLX, OPT_REG, OPT_EA | OPT_REG)) -ALT(DEF_ASM_OP2(xchgb, 0x86, 0, OPC_MODRM | OPC_BWLX, OPT_EA | OPT_REG, OPT_REG)) - -ALT(DEF_ASM_OP2(inb, 0xe4, 0, OPC_BWL, OPT_IM8, OPT_EAX)) -ALT(DEF_ASM_OP1(inb, 0xe4, 0, OPC_BWL, OPT_IM8)) -ALT(DEF_ASM_OP2(inb, 0xec, 0, OPC_BWL, OPT_DX, OPT_EAX)) -ALT(DEF_ASM_OP1(inb, 0xec, 0, OPC_BWL, OPT_DX)) - -ALT(DEF_ASM_OP2(outb, 0xe6, 0, OPC_BWL, OPT_EAX, OPT_IM8)) -ALT(DEF_ASM_OP1(outb, 0xe6, 0, OPC_BWL, OPT_IM8)) -ALT(DEF_ASM_OP2(outb, 0xee, 0, OPC_BWL, OPT_EAX, OPT_DX)) -ALT(DEF_ASM_OP1(outb, 0xee, 0, OPC_BWL, OPT_DX)) - -ALT(DEF_ASM_OP2(leaw, 0x8d, 0, OPC_MODRM | OPC_WLX, OPT_EA, OPT_REG)) - -ALT(DEF_ASM_OP2(les, 0xc4, 0, OPC_MODRM, OPT_EA, OPT_REG32)) -ALT(DEF_ASM_OP2(lds, 0xc5, 0, OPC_MODRM, OPT_EA, OPT_REG32)) -ALT(DEF_ASM_OP2(lss, 0x0fb2, 0, OPC_MODRM, OPT_EA, OPT_REG32)) -ALT(DEF_ASM_OP2(lfs, 0x0fb4, 0, OPC_MODRM, OPT_EA, OPT_REG32)) -ALT(DEF_ASM_OP2(lgs, 0x0fb5, 0, OPC_MODRM, OPT_EA, OPT_REG32)) - - /* arith */ -ALT(DEF_ASM_OP2(addb, 0x00, 0, OPC_ARITH | OPC_MODRM | OPC_BWLX, OPT_REG, OPT_EA | OPT_REG)) /* XXX: use D bit ? */ -ALT(DEF_ASM_OP2(addb, 0x02, 0, OPC_ARITH | OPC_MODRM | OPC_BWLX, OPT_EA | OPT_REG, OPT_REG)) -ALT(DEF_ASM_OP2(addb, 0x04, 0, OPC_ARITH | OPC_BWLX, OPT_IM, OPT_EAX)) -ALT(DEF_ASM_OP2(addw, 0x83, 0, OPC_ARITH | OPC_MODRM | OPC_WLX, OPT_IM8S, OPT_EA | OPT_REGW)) -ALT(DEF_ASM_OP2(addb, 0x80, 0, OPC_ARITH | OPC_MODRM | OPC_BWLX, OPT_IM, OPT_EA | OPT_REG)) - -ALT(DEF_ASM_OP2(testb, 0x84, 0, OPC_MODRM | OPC_BWLX, OPT_REG, OPT_EA | OPT_REG)) -ALT(DEF_ASM_OP2(testb, 0x84, 0, OPC_MODRM | OPC_BWLX, OPT_EA | OPT_REG, OPT_REG)) -ALT(DEF_ASM_OP2(testb, 0xa8, 0, OPC_BWLX, OPT_IM, OPT_EAX)) -ALT(DEF_ASM_OP2(testb, 0xf6, 0, OPC_MODRM | OPC_BWLX, OPT_IM, OPT_EA | OPT_REG)) - -ALT(DEF_ASM_OP1(incw, 0x40, 0, OPC_REG | OPC_WLX, OPT_REGW)) -ALT(DEF_ASM_OP1(incb, 0xfe, 0, OPC_MODRM | OPC_BWLX, OPT_REG | OPT_EA)) -ALT(DEF_ASM_OP1(decw, 0x48, 0, OPC_REG | OPC_WLX, OPT_REGW)) -ALT(DEF_ASM_OP1(decb, 0xfe, 1, OPC_MODRM | OPC_BWLX, OPT_REG | OPT_EA)) - -ALT(DEF_ASM_OP1(notb, 0xf6, 2, OPC_MODRM | OPC_BWLX, OPT_REG | OPT_EA)) -ALT(DEF_ASM_OP1(negb, 0xf6, 3, OPC_MODRM | OPC_BWLX, OPT_REG | OPT_EA)) - -ALT(DEF_ASM_OP1(mulb, 0xf6, 4, OPC_MODRM | OPC_BWLX, OPT_REG | OPT_EA)) -ALT(DEF_ASM_OP1(imulb, 0xf6, 5, OPC_MODRM | OPC_BWLX, OPT_REG | OPT_EA)) - -ALT(DEF_ASM_OP2(imulw, 0x0faf, 0, OPC_MODRM | OPC_WLX, OPT_REG | OPT_EA, OPT_REG)) -ALT(DEF_ASM_OP3(imulw, 0x6b, 0, OPC_MODRM | OPC_WLX, OPT_IM8S, OPT_REGW | OPT_EA, OPT_REGW)) -ALT(DEF_ASM_OP2(imulw, 0x6b, 0, OPC_MODRM | OPC_WLX, OPT_IM8S, OPT_REGW)) -ALT(DEF_ASM_OP3(imulw, 0x69, 0, OPC_MODRM | OPC_WLX, OPT_IMW, OPT_REGW | OPT_EA, OPT_REGW)) -ALT(DEF_ASM_OP2(imulw, 0x69, 0, OPC_MODRM | OPC_WLX, OPT_IMW, OPT_REGW)) - -ALT(DEF_ASM_OP1(divb, 0xf6, 6, OPC_MODRM | OPC_BWLX, OPT_REG | OPT_EA)) -ALT(DEF_ASM_OP2(divb, 0xf6, 6, OPC_MODRM | OPC_BWLX, OPT_REG | OPT_EA, OPT_EAX)) -ALT(DEF_ASM_OP1(idivb, 0xf6, 7, OPC_MODRM | OPC_BWLX, OPT_REG | OPT_EA)) -ALT(DEF_ASM_OP2(idivb, 0xf6, 7, OPC_MODRM | OPC_BWLX, OPT_REG | OPT_EA, OPT_EAX)) - - /* shifts */ -ALT(DEF_ASM_OP2(rolb, 0xc0, 0, OPC_MODRM | OPC_BWLX | OPC_SHIFT, OPT_IM8, OPT_EA | OPT_REG)) -ALT(DEF_ASM_OP2(rolb, 0xd2, 0, OPC_MODRM | OPC_BWLX | OPC_SHIFT, OPT_CL, OPT_EA | OPT_REG)) -ALT(DEF_ASM_OP1(rolb, 0xd0, 0, OPC_MODRM | OPC_BWLX | OPC_SHIFT, OPT_EA | OPT_REG)) - -ALT(DEF_ASM_OP3(shldw, 0x0fa4, 0, OPC_MODRM | OPC_WLX, OPT_IM8, OPT_REGW, OPT_EA | OPT_REGW)) -ALT(DEF_ASM_OP3(shldw, 0x0fa5, 0, OPC_MODRM | OPC_WLX, OPT_CL, OPT_REGW, OPT_EA | OPT_REGW)) -ALT(DEF_ASM_OP2(shldw, 0x0fa5, 0, OPC_MODRM | OPC_WLX, OPT_REGW, OPT_EA | OPT_REGW)) -ALT(DEF_ASM_OP3(shrdw, 0x0fac, 0, OPC_MODRM | OPC_WLX, OPT_IM8, OPT_REGW, OPT_EA | OPT_REGW)) -ALT(DEF_ASM_OP3(shrdw, 0x0fad, 0, OPC_MODRM | OPC_WLX, OPT_CL, OPT_REGW, OPT_EA | OPT_REGW)) -ALT(DEF_ASM_OP2(shrdw, 0x0fad, 0, OPC_MODRM | OPC_WLX, OPT_REGW, OPT_EA | OPT_REGW)) - -ALT(DEF_ASM_OP1(call, 0xff, 2, OPC_MODRM, OPT_INDIR)) -ALT(DEF_ASM_OP1(call, 0xe8, 0, 0, OPT_DISP)) -ALT(DEF_ASM_OP1(jmp, 0xff, 4, OPC_MODRM, OPT_INDIR)) -ALT(DEF_ASM_OP1(jmp, 0xeb, 0, 0, OPT_DISP8)) - -ALT(DEF_ASM_OP2(lcall, 0x9a, 0, 0, OPT_IM16, OPT_IM32)) -ALT(DEF_ASM_OP1(lcall, 0xff, 3, OPC_MODRM, OPT_EA)) -ALT(DEF_ASM_OP2(ljmp, 0xea, 0, 0, OPT_IM16, OPT_IM32)) -ALT(DEF_ASM_OP1(ljmp, 0xff, 5, OPC_MODRM, OPT_EA)) - -ALT(DEF_ASM_OP1(int, 0xcd, 0, 0, OPT_IM8)) -ALT(DEF_ASM_OP1(seto, 0x0f90, 0, OPC_MODRM | OPC_TEST, OPT_REG8 | OPT_EA)) -ALT(DEF_ASM_OP1(setob, 0x0f90, 0, OPC_MODRM | OPC_TEST, OPT_REG8 | OPT_EA)) - DEF_ASM_OP2(enter, 0xc8, 0, 0, OPT_IM16, OPT_IM8) - DEF_ASM_OP0(leave, 0xc9) - DEF_ASM_OP0(ret, 0xc3) - DEF_ASM_OP0(retl,0xc3) -ALT(DEF_ASM_OP1(retl,0xc2, 0, 0, OPT_IM16)) -ALT(DEF_ASM_OP1(ret, 0xc2, 0, 0, OPT_IM16)) - DEF_ASM_OP0(lret, 0xcb) -ALT(DEF_ASM_OP1(lret, 0xca, 0, 0, OPT_IM16)) - -ALT(DEF_ASM_OP1(jo, 0x70, 0, OPC_TEST, OPT_DISP8)) - DEF_ASM_OP1(loopne, 0xe0, 0, 0, OPT_DISP8) - DEF_ASM_OP1(loopnz, 0xe0, 0, 0, OPT_DISP8) - DEF_ASM_OP1(loope, 0xe1, 0, 0, OPT_DISP8) - DEF_ASM_OP1(loopz, 0xe1, 0, 0, OPT_DISP8) - DEF_ASM_OP1(loop, 0xe2, 0, 0, OPT_DISP8) - DEF_ASM_OP1(jecxz, 0xe3, 0, 0, OPT_DISP8) - - /* float */ - /* specific fcomp handling */ -ALT(DEF_ASM_OP0L(fcomp, 0xd8d9, 0, 0)) - -ALT(DEF_ASM_OP1(fadd, 0xd8c0, 0, OPC_FARITH | OPC_REG, OPT_ST)) -ALT(DEF_ASM_OP2(fadd, 0xd8c0, 0, OPC_FARITH | OPC_REG, OPT_ST, OPT_ST0)) -ALT(DEF_ASM_OP2(fadd, 0xdcc0, 0, OPC_FARITH | OPC_REG, OPT_ST0, OPT_ST)) -ALT(DEF_ASM_OP2(fmul, 0xdcc8, 0, OPC_FARITH | OPC_REG, OPT_ST0, OPT_ST)) -ALT(DEF_ASM_OP0L(fadd, 0xdec1, 0, OPC_FARITH)) -ALT(DEF_ASM_OP1(faddp, 0xdec0, 0, OPC_FARITH | OPC_REG, OPT_ST)) -ALT(DEF_ASM_OP2(faddp, 0xdec0, 0, OPC_FARITH | OPC_REG, OPT_ST, OPT_ST0)) -ALT(DEF_ASM_OP2(faddp, 0xdec0, 0, OPC_FARITH | OPC_REG, OPT_ST0, OPT_ST)) -ALT(DEF_ASM_OP0L(faddp, 0xdec1, 0, OPC_FARITH)) -ALT(DEF_ASM_OP1(fadds, 0xd8, 0, OPC_FARITH | OPC_MODRM, OPT_EA)) -ALT(DEF_ASM_OP1(fiaddl, 0xda, 0, OPC_FARITH | OPC_MODRM, OPT_EA)) -ALT(DEF_ASM_OP1(faddl, 0xdc, 0, OPC_FARITH | OPC_MODRM, OPT_EA)) -ALT(DEF_ASM_OP1(fiadds, 0xde, 0, OPC_FARITH | OPC_MODRM, OPT_EA)) - - DEF_ASM_OP0(fucompp, 0xdae9) - DEF_ASM_OP0(ftst, 0xd9e4) - DEF_ASM_OP0(fxam, 0xd9e5) - DEF_ASM_OP0(fld1, 0xd9e8) - DEF_ASM_OP0(fldl2t, 0xd9e9) - DEF_ASM_OP0(fldl2e, 0xd9ea) - DEF_ASM_OP0(fldpi, 0xd9eb) - DEF_ASM_OP0(fldlg2, 0xd9ec) - DEF_ASM_OP0(fldln2, 0xd9ed) - DEF_ASM_OP0(fldz, 0xd9ee) - - DEF_ASM_OP0(f2xm1, 0xd9f0) - DEF_ASM_OP0(fyl2x, 0xd9f1) - DEF_ASM_OP0(fptan, 0xd9f2) - DEF_ASM_OP0(fpatan, 0xd9f3) - DEF_ASM_OP0(fxtract, 0xd9f4) - DEF_ASM_OP0(fprem1, 0xd9f5) - DEF_ASM_OP0(fdecstp, 0xd9f6) - DEF_ASM_OP0(fincstp, 0xd9f7) - DEF_ASM_OP0(fprem, 0xd9f8) - DEF_ASM_OP0(fyl2xp1, 0xd9f9) - DEF_ASM_OP0(fsqrt, 0xd9fa) - DEF_ASM_OP0(fsincos, 0xd9fb) - DEF_ASM_OP0(frndint, 0xd9fc) - DEF_ASM_OP0(fscale, 0xd9fd) - DEF_ASM_OP0(fsin, 0xd9fe) - DEF_ASM_OP0(fcos, 0xd9ff) - DEF_ASM_OP0(fchs, 0xd9e0) - DEF_ASM_OP0(fabs, 0xd9e1) - DEF_ASM_OP0(fninit, 0xdbe3) - DEF_ASM_OP0(fnclex, 0xdbe2) - DEF_ASM_OP0(fnop, 0xd9d0) - - /* fp load */ - DEF_ASM_OP1(fld, 0xd9c0, 0, OPC_REG, OPT_ST) - DEF_ASM_OP1(fldl, 0xd9c0, 0, OPC_REG, OPT_ST) - DEF_ASM_OP1(flds, 0xd9, 0, OPC_MODRM, OPT_EA) -ALT(DEF_ASM_OP1(fldl, 0xdd, 0, OPC_MODRM, OPT_EA)) - DEF_ASM_OP1(fildl, 0xdb, 0, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(fildq, 0xdf, 5, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(fildll, 0xdf, 5, OPC_MODRM,OPT_EA) - DEF_ASM_OP1(fldt, 0xdb, 5, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(fbld, 0xdf, 4, OPC_MODRM, OPT_EA) - - /* fp store */ - DEF_ASM_OP1(fst, 0xddd0, 0, OPC_REG, OPT_ST) - DEF_ASM_OP1(fstl, 0xddd0, 0, OPC_REG, OPT_ST) - DEF_ASM_OP1(fsts, 0xd9, 2, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(fstps, 0xd9, 3, OPC_MODRM, OPT_EA) -ALT(DEF_ASM_OP1(fstl, 0xdd, 2, OPC_MODRM, OPT_EA)) - DEF_ASM_OP1(fstpl, 0xdd, 3, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(fist, 0xdf, 2, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(fistp, 0xdf, 3, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(fistl, 0xdb, 2, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(fistpl, 0xdb, 3, OPC_MODRM, OPT_EA) - - DEF_ASM_OP1(fstp, 0xddd8, 0, OPC_REG, OPT_ST) - DEF_ASM_OP1(fistpq, 0xdf, 7, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(fistpll, 0xdf, 7, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(fstpt, 0xdb, 7, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(fbstp, 0xdf, 6, OPC_MODRM, OPT_EA) - - /* exchange */ - DEF_ASM_OP0(fxch, 0xd9c9) -ALT(DEF_ASM_OP1(fxch, 0xd9c8, 0, OPC_REG, OPT_ST)) - - /* misc FPU */ - DEF_ASM_OP1(fucom, 0xdde0, 0, OPC_REG, OPT_ST ) - DEF_ASM_OP1(fucomp, 0xdde8, 0, OPC_REG, OPT_ST ) - - DEF_ASM_OP0L(finit, 0xdbe3, 0, OPC_FWAIT) - DEF_ASM_OP1(fldcw, 0xd9, 5, OPC_MODRM, OPT_EA ) - DEF_ASM_OP1(fnstcw, 0xd9, 7, OPC_MODRM, OPT_EA ) - DEF_ASM_OP1(fstcw, 0xd9, 7, OPC_MODRM | OPC_FWAIT, OPT_EA ) - DEF_ASM_OP0(fnstsw, 0xdfe0) -ALT(DEF_ASM_OP1(fnstsw, 0xdfe0, 0, 0, OPT_EAX )) -ALT(DEF_ASM_OP1(fnstsw, 0xdd, 7, OPC_MODRM, OPT_EA )) - DEF_ASM_OP1(fstsw, 0xdfe0, 0, OPC_FWAIT, OPT_EAX ) -ALT(DEF_ASM_OP0L(fstsw, 0xdfe0, 0, OPC_FWAIT)) -ALT(DEF_ASM_OP1(fstsw, 0xdd, 7, OPC_MODRM | OPC_FWAIT, OPT_EA )) - DEF_ASM_OP0L(fclex, 0xdbe2, 0, OPC_FWAIT) - DEF_ASM_OP1(fnstenv, 0xd9, 6, OPC_MODRM, OPT_EA ) - DEF_ASM_OP1(fstenv, 0xd9, 6, OPC_MODRM | OPC_FWAIT, OPT_EA ) - DEF_ASM_OP1(fldenv, 0xd9, 4, OPC_MODRM, OPT_EA ) - DEF_ASM_OP1(fnsave, 0xdd, 6, OPC_MODRM, OPT_EA ) - DEF_ASM_OP1(fsave, 0xdd, 6, OPC_MODRM | OPC_FWAIT, OPT_EA ) - DEF_ASM_OP1(frstor, 0xdd, 4, OPC_MODRM, OPT_EA ) - DEF_ASM_OP1(ffree, 0xddc0, 4, OPC_REG, OPT_ST ) - DEF_ASM_OP1(ffreep, 0xdfc0, 4, OPC_REG, OPT_ST ) - DEF_ASM_OP1(fxsave, 0x0fae, 0, OPC_MODRM, OPT_EA ) - DEF_ASM_OP1(fxrstor, 0x0fae, 1, OPC_MODRM, OPT_EA ) - - /* segments */ - DEF_ASM_OP2(arpl, 0x63, 0, OPC_MODRM, OPT_REG16, OPT_REG16 | OPT_EA) -ALT(DEF_ASM_OP2(larw, 0x0f02, 0, OPC_MODRM | OPC_WLX, OPT_REG | OPT_EA, OPT_REG)) - DEF_ASM_OP1(lgdt, 0x0f01, 2, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(lidt, 0x0f01, 3, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(lldt, 0x0f00, 2, OPC_MODRM, OPT_EA | OPT_REG) - DEF_ASM_OP1(lmsw, 0x0f01, 6, OPC_MODRM, OPT_EA | OPT_REG) -ALT(DEF_ASM_OP2(lslw, 0x0f03, 0, OPC_MODRM | OPC_WLX, OPT_EA | OPT_REG, OPT_REG)) - DEF_ASM_OP1(ltr, 0x0f00, 3, OPC_MODRM, OPT_EA | OPT_REG) - DEF_ASM_OP1(sgdt, 0x0f01, 0, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(sidt, 0x0f01, 1, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(sldt, 0x0f00, 0, OPC_MODRM, OPT_REG | OPT_EA) - DEF_ASM_OP1(smsw, 0x0f01, 4, OPC_MODRM, OPT_REG | OPT_EA) - DEF_ASM_OP1(str, 0x0f00, 1, OPC_MODRM, OPT_REG16| OPT_EA) - DEF_ASM_OP1(verr, 0x0f00, 4, OPC_MODRM, OPT_REG | OPT_EA) - DEF_ASM_OP1(verw, 0x0f00, 5, OPC_MODRM, OPT_REG | OPT_EA) - - /* 486 */ - DEF_ASM_OP1(bswap, 0x0fc8, 0, OPC_REG, OPT_REG32 ) -ALT(DEF_ASM_OP2(xaddb, 0x0fc0, 0, OPC_MODRM | OPC_BWLX, OPT_REG, OPT_REG | OPT_EA )) -ALT(DEF_ASM_OP2(cmpxchgb, 0x0fb0, 0, OPC_MODRM | OPC_BWLX, OPT_REG, OPT_REG | OPT_EA )) - DEF_ASM_OP1(invlpg, 0x0f01, 7, OPC_MODRM, OPT_EA ) - - DEF_ASM_OP2(boundl, 0x62, 0, OPC_MODRM, OPT_REG32, OPT_EA) - DEF_ASM_OP2(boundw, 0x6662, 0, OPC_MODRM, OPT_REG16, OPT_EA) - - /* pentium */ - DEF_ASM_OP1(cmpxchg8b, 0x0fc7, 1, OPC_MODRM, OPT_EA ) - - /* pentium pro */ -ALT(DEF_ASM_OP2(cmovo, 0x0f40, 0, OPC_MODRM | OPC_TEST | OPC_WLX, OPT_REGW | OPT_EA, OPT_REGW)) - DEF_ASM_OP2(fcmovb, 0xdac0, 0, OPC_REG, OPT_ST, OPT_ST0 ) - DEF_ASM_OP2(fcmove, 0xdac8, 0, OPC_REG, OPT_ST, OPT_ST0 ) - DEF_ASM_OP2(fcmovbe, 0xdad0, 0, OPC_REG, OPT_ST, OPT_ST0 ) - DEF_ASM_OP2(fcmovu, 0xdad8, 0, OPC_REG, OPT_ST, OPT_ST0 ) - DEF_ASM_OP2(fcmovnb, 0xdbc0, 0, OPC_REG, OPT_ST, OPT_ST0 ) - DEF_ASM_OP2(fcmovne, 0xdbc8, 0, OPC_REG, OPT_ST, OPT_ST0 ) - DEF_ASM_OP2(fcmovnbe, 0xdbd0, 0, OPC_REG, OPT_ST, OPT_ST0 ) - DEF_ASM_OP2(fcmovnu, 0xdbd8, 0, OPC_REG, OPT_ST, OPT_ST0 ) - - DEF_ASM_OP2(fucomi, 0xdbe8, 0, OPC_REG, OPT_ST, OPT_ST0 ) - DEF_ASM_OP2(fcomi, 0xdbf0, 0, OPC_REG, OPT_ST, OPT_ST0 ) - DEF_ASM_OP2(fucomip, 0xdfe8, 0, OPC_REG, OPT_ST, OPT_ST0 ) - DEF_ASM_OP2(fcomip, 0xdff0, 0, OPC_REG, OPT_ST, OPT_ST0 ) - - /* mmx */ - DEF_ASM_OP0(emms, 0x0f77) /* must be last OP0 */ - DEF_ASM_OP2(movd, 0x0f6e, 0, OPC_MODRM, OPT_EA | OPT_REG32, OPT_MMXSSE ) - DEF_ASM_OP2(movq, 0x0f6f, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX ) -ALT(DEF_ASM_OP2(movd, 0x0f7e, 0, OPC_MODRM, OPT_MMXSSE, OPT_EA | OPT_REG32 )) -ALT(DEF_ASM_OP2(movq, 0x0f7f, 0, OPC_MODRM, OPT_MMX, OPT_EA | OPT_MMX )) -ALT(DEF_ASM_OP2(movq, 0x660fd6, 0, OPC_MODRM, OPT_SSE, OPT_EA | OPT_SSE )) -ALT(DEF_ASM_OP2(movq, 0xf30f7e, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE )) - - DEF_ASM_OP2(packssdw, 0x0f6b, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(packsswb, 0x0f63, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(packuswb, 0x0f67, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(paddb, 0x0ffc, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(paddw, 0x0ffd, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(paddd, 0x0ffe, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(paddsb, 0x0fec, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(paddsw, 0x0fed, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(paddusb, 0x0fdc, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(paddusw, 0x0fdd, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pand, 0x0fdb, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pandn, 0x0fdf, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pcmpeqb, 0x0f74, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pcmpeqw, 0x0f75, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pcmpeqd, 0x0f76, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pcmpgtb, 0x0f64, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pcmpgtw, 0x0f65, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pcmpgtd, 0x0f66, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pmaddwd, 0x0ff5, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pmulhw, 0x0fe5, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pmullw, 0x0fd5, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(por, 0x0feb, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(psllw, 0x0ff1, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) -ALT(DEF_ASM_OP2(psllw, 0x0f71, 6, OPC_MODRM, OPT_IM8, OPT_MMXSSE )) - DEF_ASM_OP2(pslld, 0x0ff2, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) -ALT(DEF_ASM_OP2(pslld, 0x0f72, 6, OPC_MODRM, OPT_IM8, OPT_MMXSSE )) - DEF_ASM_OP2(psllq, 0x0ff3, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) -ALT(DEF_ASM_OP2(psllq, 0x0f73, 6, OPC_MODRM, OPT_IM8, OPT_MMXSSE )) - DEF_ASM_OP2(psraw, 0x0fe1, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) -ALT(DEF_ASM_OP2(psraw, 0x0f71, 4, OPC_MODRM, OPT_IM8, OPT_MMXSSE )) - DEF_ASM_OP2(psrad, 0x0fe2, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) -ALT(DEF_ASM_OP2(psrad, 0x0f72, 4, OPC_MODRM, OPT_IM8, OPT_MMXSSE )) - DEF_ASM_OP2(psrlw, 0x0fd1, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) -ALT(DEF_ASM_OP2(psrlw, 0x0f71, 2, OPC_MODRM, OPT_IM8, OPT_MMXSSE )) - DEF_ASM_OP2(psrld, 0x0fd2, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) -ALT(DEF_ASM_OP2(psrld, 0x0f72, 2, OPC_MODRM, OPT_IM8, OPT_MMXSSE )) - DEF_ASM_OP2(psrlq, 0x0fd3, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) -ALT(DEF_ASM_OP2(psrlq, 0x0f73, 2, OPC_MODRM, OPT_IM8, OPT_MMXSSE )) - DEF_ASM_OP2(psubb, 0x0ff8, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(psubw, 0x0ff9, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(psubd, 0x0ffa, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(psubsb, 0x0fe8, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(psubsw, 0x0fe9, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(psubusb, 0x0fd8, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(psubusw, 0x0fd9, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(punpckhbw, 0x0f68, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(punpckhwd, 0x0f69, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(punpckhdq, 0x0f6a, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(punpcklbw, 0x0f60, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(punpcklwd, 0x0f61, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(punpckldq, 0x0f62, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pxor, 0x0fef, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - - /* sse */ - DEF_ASM_OP2(movups, 0x0f10, 0, OPC_MODRM, OPT_EA | OPT_REG32, OPT_SSE ) -ALT(DEF_ASM_OP2(movups, 0x0f11, 0, OPC_MODRM, OPT_SSE, OPT_EA | OPT_REG32 )) - DEF_ASM_OP2(movaps, 0x0f28, 0, OPC_MODRM, OPT_EA | OPT_REG32, OPT_SSE ) -ALT(DEF_ASM_OP2(movaps, 0x0f29, 0, OPC_MODRM, OPT_SSE, OPT_EA | OPT_REG32 )) - DEF_ASM_OP2(movhps, 0x0f16, 0, OPC_MODRM, OPT_EA | OPT_REG32, OPT_SSE ) -ALT(DEF_ASM_OP2(movhps, 0x0f17, 0, OPC_MODRM, OPT_SSE, OPT_EA | OPT_REG32 )) - DEF_ASM_OP2(addps, 0x0f58, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE ) - DEF_ASM_OP2(cvtpi2ps, 0x0f2a, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_SSE ) - DEF_ASM_OP2(cvtps2pi, 0x0f2d, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_MMX ) - DEF_ASM_OP2(cvttps2pi, 0x0f2c, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_MMX ) - DEF_ASM_OP2(divps, 0x0f5e, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE ) - DEF_ASM_OP2(maxps, 0x0f5f, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE ) - DEF_ASM_OP2(minps, 0x0f5d, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE ) - DEF_ASM_OP2(mulps, 0x0f59, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE ) - DEF_ASM_OP2(pavgb, 0x0fe0, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE ) - DEF_ASM_OP2(pavgw, 0x0fe3, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE ) - DEF_ASM_OP2(pmaxsw, 0x0fee, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pmaxub, 0x0fde, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pminsw, 0x0fea, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pminub, 0x0fda, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(rcpss, 0x0f53, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE ) - DEF_ASM_OP2(rsqrtps, 0x0f52, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE ) - DEF_ASM_OP2(sqrtps, 0x0f51, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE ) - DEF_ASM_OP2(subps, 0x0f5c, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE ) - -#undef ALT -#undef DEF_ASM_OP0 -#undef DEF_ASM_OP0L -#undef DEF_ASM_OP1 -#undef DEF_ASM_OP2 -#undef DEF_ASM_OP3 diff --git a/05/tcc-final-old/i386-gen.c b/05/tcc-final-old/i386-gen.c deleted file mode 100644 index b9c3599..0000000 --- a/05/tcc-final-old/i386-gen.c +++ /dev/null @@ -1,1164 +0,0 @@ -/* - * X86 code generator for TCC - * - * Copyright (c) 2001-2004 Fabrice Bellard - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifdef TARGET_DEFS_ONLY - -/* number of available registers */ -#define NB_REGS 5 -#define NB_ASM_REGS 8 -#define CONFIG_TCC_ASM - -/* a register can belong to several classes. The classes must be - sorted from more general to more precise (see gv2() code which does - assumptions on it). */ -#define RC_INT 0x0001 /* generic integer register */ -#define RC_FLOAT 0x0002 /* generic float register */ -#define RC_EAX 0x0004 -#define RC_ST0 0x0008 -#define RC_ECX 0x0010 -#define RC_EDX 0x0020 -#define RC_EBX 0x0040 - -#define RC_IRET RC_EAX /* function return: integer register */ -#define RC_LRET RC_EDX /* function return: second integer register */ -#define RC_FRET RC_ST0 /* function return: float register */ - -/* pretty names for the registers */ -enum { - TREG_EAX = 0, - TREG_ECX, - TREG_EDX, - TREG_EBX, - TREG_ST0, - TREG_ESP = 4 -}; - -/* return registers for function */ -#define REG_IRET TREG_EAX /* single word int return register */ -#define REG_LRET TREG_EDX /* second word return register (for long long) */ -#define REG_FRET TREG_ST0 /* float return register */ - -/* defined if function parameters must be evaluated in reverse order */ -#define INVERT_FUNC_PARAMS - -/* defined if structures are passed as pointers. Otherwise structures - are directly pushed on stack. */ -/* #define FUNC_STRUCT_PARAM_AS_PTR */ - -/* pointer size, in bytes */ -#define PTR_SIZE 4 - -/* long double size and alignment, in bytes */ -#define LDOUBLE_SIZE 12 -#define LDOUBLE_ALIGN 4 -/* maximum alignment (for aligned attribute support) */ -#define MAX_ALIGN 8 - -/******************************************************/ -#else /* ! TARGET_DEFS_ONLY */ -/******************************************************/ -#include "tcc.h" - -/* define to 1/0 to [not] have EBX as 4th register */ -#define USE_EBX 0 - -ST_DATA const int reg_classes[NB_REGS] = { - /* eax */ RC_INT | RC_EAX, - /* ecx */ RC_INT | RC_ECX, - /* edx */ RC_INT | RC_EDX, - /* ebx */ (RC_INT | RC_EBX) * USE_EBX, - /* st0 */ RC_FLOAT | RC_ST0, -}; - -static unsigned long func_sub_sp_offset; -static int func_ret_sub; -#ifdef CONFIG_TCC_BCHECK -static addr_t func_bound_offset; -static unsigned long func_bound_ind; -#endif - -/* XXX: make it faster ? */ -ST_FUNC void g(int c) -{ - int ind1; - if (nocode_wanted) - return; - ind1 = ind + 1; - if (ind1 > cur_text_section->data_allocated) - section_realloc(cur_text_section, ind1); - cur_text_section->data[ind] = c; - ind = ind1; -} - -ST_FUNC void o(unsigned int c) -{ - while (c) { - g(c); - c = c >> 8; - } -} - -ST_FUNC void gen_le16(int v) -{ - g(v); - g(v >> 8); -} - -ST_FUNC void gen_le32(int c) -{ - g(c); - g(c >> 8); - g(c >> 16); - g(c >> 24); -} - -/* output a symbol and patch all calls to it */ -ST_FUNC void gsym_addr(int t, int a) -{ - while (t) { - unsigned char *ptr = cur_text_section->data + t; - uint32_t n = read32le(ptr); /* next value */ - write32le(ptr, a - t - 4); - t = n; - } -} - -ST_FUNC void gsym(int t) -{ - gsym_addr(t, ind); -} - -/* instruction + 4 bytes data. Return the address of the data */ -static int oad(int c, int s) -{ - int t; - if (nocode_wanted) - return s; - o(c); - t = ind; - gen_le32(s); - return t; -} - -/* generate jmp to a label */ -#define gjmp2(instr,lbl) oad(instr,lbl) - -/* output constant with relocation if 'r & VT_SYM' is true */ -ST_FUNC void gen_addr32(int r, Sym *sym, int c) -{ - if (r & VT_SYM) - greloc(cur_text_section, sym, ind, R_386_32); - gen_le32(c); -} - -ST_FUNC void gen_addrpc32(int r, Sym *sym, int c) -{ - if (r & VT_SYM) - greloc(cur_text_section, sym, ind, R_386_PC32); - gen_le32(c - 4); -} - -/* generate a modrm reference. 'op_reg' contains the additional 3 - opcode bits */ -static void gen_modrm(int op_reg, int r, Sym *sym, int c) -{ - op_reg = op_reg << 3; - if ((r & VT_VALMASK) == VT_CONST) { - /* constant memory reference */ - o(0x05 | op_reg); - gen_addr32(r, sym, c); - } else if ((r & VT_VALMASK) == VT_LOCAL) { - /* currently, we use only ebp as base */ - if (c == (char)c) { - /* short reference */ - o(0x45 | op_reg); - g(c); - } else { - oad(0x85 | op_reg, c); - } - } else { - g(0x00 | op_reg | (r & VT_VALMASK)); - } -} - -/* load 'r' from value 'sv' */ -ST_FUNC void load(int r, SValue *sv) -{ - int v, t, ft, fc, fr; - SValue v1; - -#ifdef TCC_TARGET_PE - SValue v2; - sv = pe_getimport(sv, &v2); -#endif - - fr = sv->r; - ft = sv->type.t & ~VT_DEFSIGN; - fc = sv->c.i; - - ft &= ~(VT_VOLATILE | VT_CONSTANT); - - v = fr & VT_VALMASK; - if (fr & VT_LVAL) { - if (v == VT_LLOCAL) { - v1.type.t = VT_INT; - v1.r = VT_LOCAL | VT_LVAL; - v1.c.i = fc; - fr = r; - if (!(reg_classes[fr] & RC_INT)) - fr = get_reg(RC_INT); - load(fr, &v1); - } - if ((ft & VT_BTYPE) == VT_FLOAT) { - o(0xd9); /* flds */ - r = 0; - } else if ((ft & VT_BTYPE) == VT_DOUBLE) { - o(0xdd); /* fldl */ - r = 0; - } else if ((ft & VT_BTYPE) == VT_LDOUBLE) { - o(0xdb); /* fldt */ - r = 5; - } else if ((ft & VT_TYPE) == VT_BYTE || (ft & VT_TYPE) == VT_BOOL) { - o(0xbe0f); /* movsbl */ - } else if ((ft & VT_TYPE) == (VT_BYTE | VT_UNSIGNED)) { - o(0xb60f); /* movzbl */ - } else if ((ft & VT_TYPE) == VT_SHORT) { - o(0xbf0f); /* movswl */ - } else if ((ft & VT_TYPE) == (VT_SHORT | VT_UNSIGNED)) { - o(0xb70f); /* movzwl */ - } else { - o(0x8b); /* movl */ - } - gen_modrm(r, fr, sv->sym, fc); - } else { - if (v == VT_CONST) { - o(0xb8 + r); /* mov $xx, r */ - gen_addr32(fr, sv->sym, fc); - } else if (v == VT_LOCAL) { - if (fc) { - o(0x8d); /* lea xxx(%ebp), r */ - gen_modrm(r, VT_LOCAL, sv->sym, fc); - } else { - o(0x89); - o(0xe8 + r); /* mov %ebp, r */ - } - } else if (v == VT_CMP) { - oad(0xb8 + r, 0); /* mov $0, r */ - o(0x0f); /* setxx %br */ - o(fc); - o(0xc0 + r); - } else if (v == VT_JMP || v == VT_JMPI) { - t = v & 1; - oad(0xb8 + r, t); /* mov $1, r */ - o(0x05eb); /* jmp after */ - gsym(fc); - oad(0xb8 + r, t ^ 1); /* mov $0, r */ - } else if (v != r) { - o(0x89); - o(0xc0 + r + v * 8); /* mov v, r */ - } - } -} - -/* store register 'r' in lvalue 'v' */ -ST_FUNC void store(int r, SValue *v) -{ - int fr, bt, ft, fc; - -#ifdef TCC_TARGET_PE - SValue v2; - v = pe_getimport(v, &v2); -#endif - - ft = v->type.t; - fc = v->c.i; - fr = v->r & VT_VALMASK; - ft &= ~(VT_VOLATILE | VT_CONSTANT); - bt = ft & VT_BTYPE; - /* XXX: incorrect if float reg to reg */ - if (bt == VT_FLOAT) { - o(0xd9); /* fsts */ - r = 2; - } else if (bt == VT_DOUBLE) { - o(0xdd); /* fstpl */ - r = 2; - } else if (bt == VT_LDOUBLE) { - o(0xc0d9); /* fld %st(0) */ - o(0xdb); /* fstpt */ - r = 7; - } else { - if (bt == VT_SHORT) - o(0x66); - if (bt == VT_BYTE || bt == VT_BOOL) - o(0x88); - else - o(0x89); - } - if (fr == VT_CONST || - fr == VT_LOCAL || - (v->r & VT_LVAL)) { - gen_modrm(r, v->r, v->sym, fc); - } else if (fr != r) { - o(0xc0 + fr + r * 8); /* mov r, fr */ - } -} - -static void gadd_sp(int val) -{ - if (val == (char)val) { - o(0xc483); - g(val); - } else { - oad(0xc481, val); /* add $xxx, %esp */ - } -} - -#if defined CONFIG_TCC_BCHECK || defined TCC_TARGET_PE -static void gen_static_call(int v) -{ - Sym *sym; - - sym = external_global_sym(v, &func_old_type, 0); - oad(0xe8, -4); - greloc(cur_text_section, sym, ind-4, R_386_PC32); -} -#endif - -/* 'is_jmp' is '1' if it is a jump */ -static void gcall_or_jmp(int is_jmp) -{ - int r; - if ((vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST && (vtop->r & VT_SYM)) { - /* constant and relocation case */ - greloc(cur_text_section, vtop->sym, ind + 1, R_386_PC32); - oad(0xe8 + is_jmp, vtop->c.i - 4); /* call/jmp im */ - } else { - /* otherwise, indirect call */ - r = gv(RC_INT); - o(0xff); /* call/jmp *r */ - o(0xd0 + r + (is_jmp << 4)); - } - if (!is_jmp) { - int rt; - /* extend the return value to the whole register if necessary - visual studio and gcc do not always set the whole eax register - when assigning the return value of a function */ - rt = vtop->type.ref->type.t; - switch (rt & VT_BTYPE) { - case VT_BYTE: - if (rt & VT_UNSIGNED) { - o(0xc0b60f); /* movzx %al, %eax */ - } - else { - o(0xc0be0f); /* movsx %al, %eax */ - } - break; - case VT_SHORT: - if (rt & VT_UNSIGNED) { - o(0xc0b70f); /* movzx %ax, %eax */ - } - else { - o(0xc0bf0f); /* movsx %ax, %eax */ - } - break; - default: - break; - } - } -} - -static uint8_t fastcall_regs[3] = { TREG_EAX, TREG_EDX, TREG_ECX }; -static uint8_t fastcallw_regs[2] = { TREG_ECX, TREG_EDX }; - -/* Return the number of registers needed to return the struct, or 0 if - returning via struct pointer. */ -ST_FUNC int gfunc_sret(CType *vt, int variadic, CType *ret, int *ret_align, int *regsize) -{ -#ifdef TCC_TARGET_PE - int size, align; - *ret_align = 1; // Never have to re-align return values for x86 - *regsize = 4; - size = type_size(vt, &align); - if (size > 8 || (size & (size - 1))) - return 0; - if (size == 8) - ret->t = VT_LLONG; - else if (size == 4) - ret->t = VT_INT; - else if (size == 2) - ret->t = VT_SHORT; - else - ret->t = VT_BYTE; - ret->ref = NULL; - return 1; -#else - *ret_align = 1; // Never have to re-align return values for x86 - return 0; -#endif -} - -/* Generate function call. The function address is pushed first, then - all the parameters in call order. This functions pops all the - parameters and the function address. */ -ST_FUNC void gfunc_call(int nb_args) -{ - int size, align, r, args_size, i, func_call; - Sym *func_sym; - - args_size = 0; - for(i = 0;i < nb_args; i++) { - if ((vtop->type.t & VT_BTYPE) == VT_STRUCT) { - size = type_size(&vtop->type, &align); - /* align to stack align size */ - size = (size + 3) & ~3; - /* allocate the necessary size on stack */ - oad(0xec81, size); /* sub $xxx, %esp */ - /* generate structure store */ - r = get_reg(RC_INT); - o(0x89); /* mov %esp, r */ - o(0xe0 + r); - vset(&vtop->type, r | VT_LVAL, 0); - vswap(); - vstore(); - args_size += size; - } else if (is_float(vtop->type.t)) { - gv(RC_FLOAT); /* only one float register */ - if ((vtop->type.t & VT_BTYPE) == VT_FLOAT) - size = 4; - else if ((vtop->type.t & VT_BTYPE) == VT_DOUBLE) - size = 8; - else - size = 12; - oad(0xec81, size); /* sub $xxx, %esp */ - if (size == 12) - o(0x7cdb); - else - o(0x5cd9 + size - 4); /* fstp[s|l] 0(%esp) */ - g(0x24); - g(0x00); - args_size += size; - } else { - /* simple type (currently always same size) */ - /* XXX: implicit cast ? */ - r = gv(RC_INT); - if ((vtop->type.t & VT_BTYPE) == VT_LLONG) { - size = 8; - o(0x50 + vtop->r2); /* push r */ - } else { - size = 4; - } - o(0x50 + r); /* push r */ - args_size += size; - } - vtop--; - } - save_regs(0); /* save used temporary registers */ - func_sym = vtop->type.ref; - func_call = func_sym->f.func_call; - /* fast call case */ - if ((func_call >= FUNC_FASTCALL1 && func_call <= FUNC_FASTCALL3) || - func_call == FUNC_FASTCALLW) { - int fastcall_nb_regs; - uint8_t *fastcall_regs_ptr; - if (func_call == FUNC_FASTCALLW) { - fastcall_regs_ptr = fastcallw_regs; - fastcall_nb_regs = 2; - } else { - fastcall_regs_ptr = fastcall_regs; - fastcall_nb_regs = func_call - FUNC_FASTCALL1 + 1; - } - for(i = 0;i < fastcall_nb_regs; i++) { - if (args_size <= 0) - break; - o(0x58 + fastcall_regs_ptr[i]); /* pop r */ - /* XXX: incorrect for struct/floats */ - args_size -= 4; - } - } -#ifndef TCC_TARGET_PE - else if ((vtop->type.ref->type.t & VT_BTYPE) == VT_STRUCT) - args_size -= 4; -#endif - gcall_or_jmp(0); - - if (args_size && func_call != FUNC_STDCALL && func_call != FUNC_FASTCALLW) - gadd_sp(args_size); - vtop--; -} - -#ifdef TCC_TARGET_PE -#define FUNC_PROLOG_SIZE (10 + USE_EBX) -#else -#define FUNC_PROLOG_SIZE (9 + USE_EBX) -#endif - -/* generate function prolog of type 't' */ -ST_FUNC void gfunc_prolog(CType *func_type) -{ - int addr, align, size, func_call, fastcall_nb_regs; - int param_index, param_addr; - uint8_t *fastcall_regs_ptr; - Sym *sym; - CType *type; - - sym = func_type->ref; - func_call = sym->f.func_call; - addr = 8; - loc = 0; - func_vc = 0; - - if (func_call >= FUNC_FASTCALL1 && func_call <= FUNC_FASTCALL3) { - fastcall_nb_regs = func_call - FUNC_FASTCALL1 + 1; - fastcall_regs_ptr = fastcall_regs; - } else if (func_call == FUNC_FASTCALLW) { - fastcall_nb_regs = 2; - fastcall_regs_ptr = fastcallw_regs; - } else { - fastcall_nb_regs = 0; - fastcall_regs_ptr = NULL; - } - param_index = 0; - - ind += FUNC_PROLOG_SIZE; - func_sub_sp_offset = ind; - /* if the function returns a structure, then add an - implicit pointer parameter */ - func_vt = sym->type; - func_var = (sym->f.func_type == FUNC_ELLIPSIS); -#ifdef TCC_TARGET_PE - size = type_size(&func_vt,&align); - if (((func_vt.t & VT_BTYPE) == VT_STRUCT) - && (size > 8 || (size & (size - 1)))) { -#else - if ((func_vt.t & VT_BTYPE) == VT_STRUCT) { -#endif - /* XXX: fastcall case ? */ - func_vc = addr; - addr += 4; - param_index++; - } - /* define parameters */ - while ((sym = sym->next) != NULL) { - type = &sym->type; - size = type_size(type, &align); - size = (size + 3) & ~3; -#ifdef FUNC_STRUCT_PARAM_AS_PTR - /* structs are passed as pointer */ - if ((type->t & VT_BTYPE) == VT_STRUCT) { - size = 4; - } -#endif - if (param_index < fastcall_nb_regs) { - /* save FASTCALL register */ - loc -= 4; - o(0x89); /* movl */ - gen_modrm(fastcall_regs_ptr[param_index], VT_LOCAL, NULL, loc); - param_addr = loc; - } else { - param_addr = addr; - addr += size; - } - sym_push(sym->v & ~SYM_FIELD, type, - VT_LOCAL | lvalue_type(type->t), param_addr); - param_index++; - } - func_ret_sub = 0; - /* pascal type call or fastcall ? */ - if (func_call == FUNC_STDCALL || func_call == FUNC_FASTCALLW) - func_ret_sub = addr - 8; -#ifndef TCC_TARGET_PE - else if (func_vc) - func_ret_sub = 4; -#endif - -#ifdef CONFIG_TCC_BCHECK - /* leave some room for bound checking code */ - if (tcc_state->do_bounds_check) { - func_bound_offset = lbounds_section->data_offset; - func_bound_ind = ind; - oad(0xb8, 0); /* lbound section pointer */ - oad(0xb8, 0); /* call to function */ - } -#endif -} - -/* generate function epilog */ -ST_FUNC void gfunc_epilog(void) -{ - addr_t v, saved_ind; - -#ifdef CONFIG_TCC_BCHECK - if (tcc_state->do_bounds_check - && func_bound_offset != lbounds_section->data_offset) { - addr_t saved_ind; - addr_t *bounds_ptr; - Sym *sym_data; - - /* add end of table info */ - bounds_ptr = section_ptr_add(lbounds_section, sizeof(addr_t)); - *bounds_ptr = 0; - - /* generate bound local allocation */ - saved_ind = ind; - ind = func_bound_ind; - sym_data = get_sym_ref(&char_pointer_type, lbounds_section, - func_bound_offset, lbounds_section->data_offset); - greloc(cur_text_section, sym_data, - ind + 1, R_386_32); - oad(0xb8, 0); /* mov %eax, xxx */ - gen_static_call(TOK___bound_local_new); - ind = saved_ind; - - /* generate bound check local freeing */ - o(0x5250); /* save returned value, if any */ - greloc(cur_text_section, sym_data, ind + 1, R_386_32); - oad(0xb8, 0); /* mov %eax, xxx */ - gen_static_call(TOK___bound_local_delete); - o(0x585a); /* restore returned value, if any */ - } -#endif - - /* align local size to word & save local variables */ - v = (-loc + 3) & -4; - -#if USE_EBX - o(0x8b); - gen_modrm(TREG_EBX, VT_LOCAL, NULL, -(v+4)); -#endif - - o(0xc9); /* leave */ - if (func_ret_sub == 0) { - o(0xc3); /* ret */ - } else { - o(0xc2); /* ret n */ - g(func_ret_sub); - g(func_ret_sub >> 8); - } - saved_ind = ind; - ind = func_sub_sp_offset - FUNC_PROLOG_SIZE; -#ifdef TCC_TARGET_PE - if (v >= 4096) { - oad(0xb8, v); /* mov stacksize, %eax */ - gen_static_call(TOK___chkstk); /* call __chkstk, (does the stackframe too) */ - } else -#endif - { - o(0xe58955); /* push %ebp, mov %esp, %ebp */ - o(0xec81); /* sub esp, stacksize */ - gen_le32(v); -#ifdef TCC_TARGET_PE - o(0x90); /* adjust to FUNC_PROLOG_SIZE */ -#endif - } - o(0x53 * USE_EBX); /* push ebx */ - ind = saved_ind; -} - -/* generate a jump to a label */ -ST_FUNC int gjmp(int t) -{ - return gjmp2(0xe9, t); -} - -/* generate a jump to a fixed address */ -ST_FUNC void gjmp_addr(int a) -{ - int r; - r = a - ind - 2; - if (r == (char)r) { - g(0xeb); - g(r); - } else { - oad(0xe9, a - ind - 5); - } -} - -ST_FUNC void gtst_addr(int inv, int a) -{ - int v = vtop->r & VT_VALMASK; - if (v == VT_CMP) { - inv ^= (vtop--)->c.i; - a -= ind + 2; - if (a == (char)a) { - g(inv - 32); - g(a); - } else { - g(0x0f); - oad(inv - 16, a - 4); - } - } else if ((v & ~1) == VT_JMP) { - if ((v & 1) != inv) { - gjmp_addr(a); - gsym(vtop->c.i); - } else { - gsym(vtop->c.i); - o(0x05eb); - gjmp_addr(a); - } - vtop--; - } -} - -/* generate a test. set 'inv' to invert test. Stack entry is popped */ -ST_FUNC int gtst(int inv, int t) -{ - int v = vtop->r & VT_VALMASK; - if (nocode_wanted) { - ; - } else if (v == VT_CMP) { - /* fast case : can jump directly since flags are set */ - g(0x0f); - t = gjmp2((vtop->c.i - 16) ^ inv, t); - } else if (v == VT_JMP || v == VT_JMPI) { - /* && or || optimization */ - if ((v & 1) == inv) { - /* insert vtop->c jump list in t */ - uint32_t n1, n = vtop->c.i; - if (n) { - while ((n1 = read32le(cur_text_section->data + n))) - n = n1; - write32le(cur_text_section->data + n, t); - t = vtop->c.i; - } - } else { - t = gjmp(t); - gsym(vtop->c.i); - } - } - vtop--; - return t; -} - -/* generate an integer binary operation */ -ST_FUNC void gen_opi(int op) -{ - int r, fr, opc, c; - - switch(op) { - case '+': - case TOK_ADDC1: /* add with carry generation */ - opc = 0; - gen_op8: - if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) { - /* constant case */ - vswap(); - r = gv(RC_INT); - vswap(); - c = vtop->c.i; - if (c == (char)c) { - /* generate inc and dec for smaller code */ - if (c==1 && opc==0 && op != TOK_ADDC1) { - o (0x40 | r); // inc - } else if (c==1 && opc==5 && op != TOK_SUBC1) { - o (0x48 | r); // dec - } else { - o(0x83); - o(0xc0 | (opc << 3) | r); - g(c); - } - } else { - o(0x81); - oad(0xc0 | (opc << 3) | r, c); - } - } else { - gv2(RC_INT, RC_INT); - r = vtop[-1].r; - fr = vtop[0].r; - o((opc << 3) | 0x01); - o(0xc0 + r + fr * 8); - } - vtop--; - if (op >= TOK_ULT && op <= TOK_GT) { - vtop->r = VT_CMP; - vtop->c.i = op; - } - break; - case '-': - case TOK_SUBC1: /* sub with carry generation */ - opc = 5; - goto gen_op8; - case TOK_ADDC2: /* add with carry use */ - opc = 2; - goto gen_op8; - case TOK_SUBC2: /* sub with carry use */ - opc = 3; - goto gen_op8; - case '&': - opc = 4; - goto gen_op8; - case '^': - opc = 6; - goto gen_op8; - case '|': - opc = 1; - goto gen_op8; - case '*': - gv2(RC_INT, RC_INT); - r = vtop[-1].r; - fr = vtop[0].r; - vtop--; - o(0xaf0f); /* imul fr, r */ - o(0xc0 + fr + r * 8); - break; - case TOK_SHL: - opc = 4; - goto gen_shift; - case TOK_SHR: - opc = 5; - goto gen_shift; - case TOK_SAR: - opc = 7; - gen_shift: - opc = 0xc0 | (opc << 3); - if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) { - /* constant case */ - vswap(); - r = gv(RC_INT); - vswap(); - c = vtop->c.i & 0x1f; - o(0xc1); /* shl/shr/sar $xxx, r */ - o(opc | r); - g(c); - } else { - /* we generate the shift in ecx */ - gv2(RC_INT, RC_ECX); - r = vtop[-1].r; - o(0xd3); /* shl/shr/sar %cl, r */ - o(opc | r); - } - vtop--; - break; - case '/': - case TOK_UDIV: - case TOK_PDIV: - case '%': - case TOK_UMOD: - case TOK_UMULL: - /* first operand must be in eax */ - /* XXX: need better constraint for second operand */ - gv2(RC_EAX, RC_ECX); - r = vtop[-1].r; - fr = vtop[0].r; - vtop--; - save_reg(TREG_EDX); - /* save EAX too if used otherwise */ - save_reg_upstack(TREG_EAX, 1); - if (op == TOK_UMULL) { - o(0xf7); /* mul fr */ - o(0xe0 + fr); - vtop->r2 = TREG_EDX; - r = TREG_EAX; - } else { - if (op == TOK_UDIV || op == TOK_UMOD) { - o(0xf7d231); /* xor %edx, %edx, div fr, %eax */ - o(0xf0 + fr); - } else { - o(0xf799); /* cltd, idiv fr, %eax */ - o(0xf8 + fr); - } - if (op == '%' || op == TOK_UMOD) - r = TREG_EDX; - else - r = TREG_EAX; - } - vtop->r = r; - break; - default: - opc = 7; - goto gen_op8; - } -} - -/* generate a floating point operation 'v = t1 op t2' instruction. The - two operands are guaranteed to have the same floating point type */ -/* XXX: need to use ST1 too */ -ST_FUNC void gen_opf(int op) -{ - int a, ft, fc, swapped, r; - - /* convert constants to memory references */ - if ((vtop[-1].r & (VT_VALMASK | VT_LVAL)) == VT_CONST) { - vswap(); - gv(RC_FLOAT); - vswap(); - } - if ((vtop[0].r & (VT_VALMASK | VT_LVAL)) == VT_CONST) - gv(RC_FLOAT); - - /* must put at least one value in the floating point register */ - if ((vtop[-1].r & VT_LVAL) && - (vtop[0].r & VT_LVAL)) { - vswap(); - gv(RC_FLOAT); - vswap(); - } - swapped = 0; - /* swap the stack if needed so that t1 is the register and t2 is - the memory reference */ - if (vtop[-1].r & VT_LVAL) { - vswap(); - swapped = 1; - } - if (op >= TOK_ULT && op <= TOK_GT) { - /* load on stack second operand */ - load(TREG_ST0, vtop); - save_reg(TREG_EAX); /* eax is used by FP comparison code */ - if (op == TOK_GE || op == TOK_GT) - swapped = !swapped; - else if (op == TOK_EQ || op == TOK_NE) - swapped = 0; - if (swapped) - o(0xc9d9); /* fxch %st(1) */ - if (op == TOK_EQ || op == TOK_NE) - o(0xe9da); /* fucompp */ - else - o(0xd9de); /* fcompp */ - o(0xe0df); /* fnstsw %ax */ - if (op == TOK_EQ) { - o(0x45e480); /* and $0x45, %ah */ - o(0x40fC80); /* cmp $0x40, %ah */ - } else if (op == TOK_NE) { - o(0x45e480); /* and $0x45, %ah */ - o(0x40f480); /* xor $0x40, %ah */ - op = TOK_NE; - } else if (op == TOK_GE || op == TOK_LE) { - o(0x05c4f6); /* test $0x05, %ah */ - op = TOK_EQ; - } else { - o(0x45c4f6); /* test $0x45, %ah */ - op = TOK_EQ; - } - vtop--; - vtop->r = VT_CMP; - vtop->c.i = op; - } else { - /* no memory reference possible for long double operations */ - if ((vtop->type.t & VT_BTYPE) == VT_LDOUBLE) { - load(TREG_ST0, vtop); - swapped = !swapped; - } - - switch(op) { - default: - case '+': - a = 0; - break; - case '-': - a = 4; - if (swapped) - a++; - break; - case '*': - a = 1; - break; - case '/': - a = 6; - if (swapped) - a++; - break; - } - ft = vtop->type.t; - fc = vtop->c.i; - if ((ft & VT_BTYPE) == VT_LDOUBLE) { - o(0xde); /* fxxxp %st, %st(1) */ - o(0xc1 + (a << 3)); - } else { - /* if saved lvalue, then we must reload it */ - r = vtop->r; - if ((r & VT_VALMASK) == VT_LLOCAL) { - SValue v1; - r = get_reg(RC_INT); - v1.type.t = VT_INT; - v1.r = VT_LOCAL | VT_LVAL; - v1.c.i = fc; - load(r, &v1); - fc = 0; - } - - if ((ft & VT_BTYPE) == VT_DOUBLE) - o(0xdc); - else - o(0xd8); - gen_modrm(a, r, vtop->sym, fc); - } - vtop--; - } -} - -/* convert integers to fp 't' type. Must handle 'int', 'unsigned int' - and 'long long' cases. */ -ST_FUNC void gen_cvt_itof(int t) -{ - save_reg(TREG_ST0); - gv(RC_INT); - if ((vtop->type.t & VT_BTYPE) == VT_LLONG) { - /* signed long long to float/double/long double (unsigned case - is handled generically) */ - o(0x50 + vtop->r2); /* push r2 */ - o(0x50 + (vtop->r & VT_VALMASK)); /* push r */ - o(0x242cdf); /* fildll (%esp) */ - o(0x08c483); /* add $8, %esp */ - } else if ((vtop->type.t & (VT_BTYPE | VT_UNSIGNED)) == - (VT_INT | VT_UNSIGNED)) { - /* unsigned int to float/double/long double */ - o(0x6a); /* push $0 */ - g(0x00); - o(0x50 + (vtop->r & VT_VALMASK)); /* push r */ - o(0x242cdf); /* fildll (%esp) */ - o(0x08c483); /* add $8, %esp */ - } else { - /* int to float/double/long double */ - o(0x50 + (vtop->r & VT_VALMASK)); /* push r */ - o(0x2404db); /* fildl (%esp) */ - o(0x04c483); /* add $4, %esp */ - } - vtop->r = TREG_ST0; -} - -/* convert fp to int 't' type */ -ST_FUNC void gen_cvt_ftoi(int t) -{ - int bt = vtop->type.t & VT_BTYPE; - if (bt == VT_FLOAT) - vpush_global_sym(&func_old_type, TOK___fixsfdi); - else if (bt == VT_LDOUBLE) - vpush_global_sym(&func_old_type, TOK___fixxfdi); - else - vpush_global_sym(&func_old_type, TOK___fixdfdi); - vswap(); - gfunc_call(1); - vpushi(0); - vtop->r = REG_IRET; - vtop->r2 = REG_LRET; -} - -/* convert from one floating point type to another */ -ST_FUNC void gen_cvt_ftof(int t) -{ - /* all we have to do on i386 is to put the float in a register */ - gv(RC_FLOAT); -} - -/* computed goto support */ -ST_FUNC void ggoto(void) -{ - gcall_or_jmp(1); - vtop--; -} - -/* bound check support functions */ -#ifdef CONFIG_TCC_BCHECK - -/* generate a bounded pointer addition */ -ST_FUNC void gen_bounded_ptr_add(void) -{ - /* prepare fast i386 function call (args in eax and edx) */ - gv2(RC_EAX, RC_EDX); - /* save all temporary registers */ - vtop -= 2; - save_regs(0); - /* do a fast function call */ - gen_static_call(TOK___bound_ptr_add); - /* returned pointer is in eax */ - vtop++; - vtop->r = TREG_EAX | VT_BOUNDED; - /* address of bounding function call point */ - vtop->c.i = (cur_text_section->reloc->data_offset - sizeof(Elf32_Rel)); -} - -/* patch pointer addition in vtop so that pointer dereferencing is - also tested */ -ST_FUNC void gen_bounded_ptr_deref(void) -{ - addr_t func; - int size, align; - Elf32_Rel *rel; - Sym *sym; - - size = 0; - /* XXX: put that code in generic part of tcc */ - if (!is_float(vtop->type.t)) { - if (vtop->r & VT_LVAL_BYTE) - size = 1; - else if (vtop->r & VT_LVAL_SHORT) - size = 2; - } - if (!size) - size = type_size(&vtop->type, &align); - switch(size) { - case 1: func = TOK___bound_ptr_indir1; break; - case 2: func = TOK___bound_ptr_indir2; break; - case 4: func = TOK___bound_ptr_indir4; break; - case 8: func = TOK___bound_ptr_indir8; break; - case 12: func = TOK___bound_ptr_indir12; break; - case 16: func = TOK___bound_ptr_indir16; break; - default: - tcc_error("unhandled size when dereferencing bounded pointer"); - func = 0; - break; - } - - /* patch relocation */ - /* XXX: find a better solution ? */ - rel = (Elf32_Rel *)(cur_text_section->reloc->data + vtop->c.i); - sym = external_global_sym(func, &func_old_type, 0); - if (!sym->c) - put_extern_sym(sym, NULL, 0, 0); - rel->r_info = ELF32_R_INFO(sym->c, ELF32_R_TYPE(rel->r_info)); -} -#endif - -/* Save the stack pointer onto the stack */ -ST_FUNC void gen_vla_sp_save(int addr) { - /* mov %esp,addr(%ebp)*/ - o(0x89); - gen_modrm(TREG_ESP, VT_LOCAL, NULL, addr); -} - -/* Restore the SP from a location on the stack */ -ST_FUNC void gen_vla_sp_restore(int addr) { - o(0x8b); - gen_modrm(TREG_ESP, VT_LOCAL, NULL, addr); -} - -/* Subtract from the stack pointer, and push the resulting value onto the stack */ -ST_FUNC void gen_vla_alloc(CType *type, int align) { -#ifdef TCC_TARGET_PE - /* alloca does more than just adjust %rsp on Windows */ - vpush_global_sym(&func_old_type, TOK_alloca); - vswap(); /* Move alloca ref past allocation size */ - gfunc_call(1); -#else - int r; - r = gv(RC_INT); /* allocation size */ - /* sub r,%rsp */ - o(0x2b); - o(0xe0 | r); - /* We align to 16 bytes rather than align */ - /* and ~15, %esp */ - o(0xf0e483); - vpop(); -#endif -} - -/* end of X86 code generator */ -/*************************************************************/ -#endif -/*************************************************************/ diff --git a/05/tcc-final-old/i386-link.c b/05/tcc-final-old/i386-link.c deleted file mode 100644 index aea3c21..0000000 --- a/05/tcc-final-old/i386-link.c +++ /dev/null @@ -1,247 +0,0 @@ -#ifdef TARGET_DEFS_ONLY - -#define EM_TCC_TARGET EM_386 - -/* relocation type for 32 bit data relocation */ -#define R_DATA_32 R_386_32 -#define R_DATA_PTR R_386_32 -#define R_JMP_SLOT R_386_JMP_SLOT -#define R_GLOB_DAT R_386_GLOB_DAT -#define R_COPY R_386_COPY -#define R_RELATIVE R_386_RELATIVE - -#define R_NUM R_386_NUM - -#define ELF_START_ADDR 0x08048000 -#define ELF_PAGE_SIZE 0x1000 - -#define PCRELATIVE_DLLPLT 0 -#define RELOCATE_DLLPLT 0 - -#else /* !TARGET_DEFS_ONLY */ - -#include "tcc.h" - -/* Returns 1 for a code relocation, 0 for a data relocation. For unknown - relocations, returns -1. */ -int code_reloc (int reloc_type) -{ - switch (reloc_type) { - case R_386_RELATIVE: - case R_386_16: - case R_386_32: - case R_386_GOTPC: - case R_386_GOTOFF: - case R_386_GOT32: - case R_386_GOT32X: - case R_386_GLOB_DAT: - case R_386_COPY: - return 0; - - case R_386_PC16: - case R_386_PC32: - case R_386_PLT32: - case R_386_JMP_SLOT: - return 1; - } - - tcc_error ("Unknown relocation type: %d", reloc_type); - return -1; -} - -/* Returns an enumerator to describe whether and when the relocation needs a - GOT and/or PLT entry to be created. See tcc.h for a description of the - different values. */ -int gotplt_entry_type (int reloc_type) -{ - switch (reloc_type) { - case R_386_RELATIVE: - case R_386_16: - case R_386_GLOB_DAT: - case R_386_JMP_SLOT: - case R_386_COPY: - return NO_GOTPLT_ENTRY; - - case R_386_32: - /* This relocations shouldn't normally need GOT or PLT - slots if it weren't for simplicity in the code generator. - See our caller for comments. */ - return AUTO_GOTPLT_ENTRY; - - case R_386_PC16: - case R_386_PC32: - return AUTO_GOTPLT_ENTRY; - - case R_386_GOTPC: - case R_386_GOTOFF: - return BUILD_GOT_ONLY; - - case R_386_GOT32: - case R_386_GOT32X: - case R_386_PLT32: - return ALWAYS_GOTPLT_ENTRY; - } - - tcc_error ("Unknown relocation type: %d", reloc_type); - return -1; -} - -ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr) -{ - Section *plt = s1->plt; - uint8_t *p; - int modrm; - unsigned plt_offset, relofs; - - /* on i386 if we build a DLL, we add a %ebx offset */ - if (s1->output_type == TCC_OUTPUT_DLL) - modrm = 0xa3; - else - modrm = 0x25; - - /* empty PLT: create PLT0 entry that pushes the library identifier - (GOT + PTR_SIZE) and jumps to ld.so resolution routine - (GOT + 2 * PTR_SIZE) */ - if (plt->data_offset == 0) { - p = section_ptr_add(plt, 16); - p[0] = 0xff; /* pushl got + PTR_SIZE */ - p[1] = modrm + 0x10; - write32le(p + 2, PTR_SIZE); - p[6] = 0xff; /* jmp *(got + PTR_SIZE * 2) */ - p[7] = modrm; - write32le(p + 8, PTR_SIZE * 2); - } - plt_offset = plt->data_offset; - - /* The PLT slot refers to the relocation entry it needs via offset. - The reloc entry is created below, so its offset is the current - data_offset */ - relofs = s1->got->reloc ? s1->got->reloc->data_offset : 0; - - /* Jump to GOT entry where ld.so initially put the address of ip + 4 */ - p = section_ptr_add(plt, 16); - p[0] = 0xff; /* jmp *(got + x) */ - p[1] = modrm; - write32le(p + 2, got_offset); - p[6] = 0x68; /* push $xxx */ - write32le(p + 7, relofs); - p[11] = 0xe9; /* jmp plt_start */ - write32le(p + 12, -(plt->data_offset)); - return plt_offset; -} - -/* relocate the PLT: compute addresses and offsets in the PLT now that final - address for PLT and GOT are known (see fill_program_header) */ -ST_FUNC void relocate_plt(TCCState *s1) -{ - uint8_t *p, *p_end; - - if (!s1->plt) - return; - - p = s1->plt->data; - p_end = p + s1->plt->data_offset; - - if (p < p_end) { - add32le(p + 2, s1->got->sh_addr); - add32le(p + 8, s1->got->sh_addr); - p += 16; - while (p < p_end) { - add32le(p + 2, s1->got->sh_addr); - p += 16; - } - } -} - -static ElfW_Rel *qrel; /* ptr to next reloc entry reused */ - -void relocate_init(Section *sr) -{ - qrel = (ElfW_Rel *) sr->data; -} - -void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val) -{ - int sym_index, esym_index; - - sym_index = ELFW(R_SYM)(rel->r_info); - - switch (type) { - case R_386_32: - if (s1->output_type == TCC_OUTPUT_DLL) { - esym_index = s1->sym_attrs[sym_index].dyn_index; - qrel->r_offset = rel->r_offset; - if (esym_index) { - qrel->r_info = ELFW(R_INFO)(esym_index, R_386_32); - qrel++; - return; - } else { - qrel->r_info = ELFW(R_INFO)(0, R_386_RELATIVE); - qrel++; - } - } - add32le(ptr, val); - return; - case R_386_PC32: - if (s1->output_type == TCC_OUTPUT_DLL) { - /* DLL relocation */ - esym_index = s1->sym_attrs[sym_index].dyn_index; - if (esym_index) { - qrel->r_offset = rel->r_offset; - qrel->r_info = ELFW(R_INFO)(esym_index, R_386_PC32); - qrel++; - return; - } - } - add32le(ptr, val - addr); - return; - case R_386_PLT32: - add32le(ptr, val - addr); - return; - case R_386_GLOB_DAT: - case R_386_JMP_SLOT: - write32le(ptr, val); - return; - case R_386_GOTPC: - add32le(ptr, s1->got->sh_addr - addr); - return; - case R_386_GOTOFF: - add32le(ptr, val - s1->got->sh_addr); - return; - case R_386_GOT32: - case R_386_GOT32X: - /* we load the got offset */ - add32le(ptr, s1->sym_attrs[sym_index].got_offset); - return; - case R_386_16: - if (s1->output_format != TCC_OUTPUT_FORMAT_BINARY) { - output_file: - tcc_error("can only produce 16-bit binary files"); - } - write16le(ptr, read16le(ptr) + val); - return; - case R_386_PC16: - if (s1->output_format != TCC_OUTPUT_FORMAT_BINARY) - goto output_file; - write16le(ptr, read16le(ptr) + val - addr); - return; - case R_386_RELATIVE: -#ifdef TCC_TARGET_PE - add32le(ptr, val - s1->pe_imagebase); -#endif - /* do nothing */ - return; - case R_386_COPY: - /* This relocation must copy initialized data from the library - to the program .bss segment. Currently made like for ARM - (to remove noise of default case). Is this true? - */ - return; - default: - fprintf(stderr,"FIXME: handle reloc type %d at %x [%p] to %x\n", - type, (unsigned)addr, ptr, (unsigned)val); - return; - } -} - -#endif /* !TARGET_DEFS_ONLY */ diff --git a/05/tcc-final-old/i386-tok.h b/05/tcc-final-old/i386-tok.h deleted file mode 100644 index 8c25af0..0000000 --- a/05/tcc-final-old/i386-tok.h +++ /dev/null @@ -1,253 +0,0 @@ -/* ------------------------------------------------------------------ */ -/* WARNING: relative order of tokens is important. */ - -/* register */ - DEF_ASM(al) - DEF_ASM(cl) - DEF_ASM(dl) - DEF_ASM(bl) - DEF_ASM(ah) - DEF_ASM(ch) - DEF_ASM(dh) - DEF_ASM(bh) - DEF_ASM(ax) - DEF_ASM(cx) - DEF_ASM(dx) - DEF_ASM(bx) - DEF_ASM(sp) - DEF_ASM(bp) - DEF_ASM(si) - DEF_ASM(di) - DEF_ASM(eax) - DEF_ASM(ecx) - DEF_ASM(edx) - DEF_ASM(ebx) - DEF_ASM(esp) - DEF_ASM(ebp) - DEF_ASM(esi) - DEF_ASM(edi) -#ifdef TCC_TARGET_X86_64 - DEF_ASM(rax) - DEF_ASM(rcx) - DEF_ASM(rdx) - DEF_ASM(rbx) - DEF_ASM(rsp) - DEF_ASM(rbp) - DEF_ASM(rsi) - DEF_ASM(rdi) -#endif - DEF_ASM(mm0) - DEF_ASM(mm1) - DEF_ASM(mm2) - DEF_ASM(mm3) - DEF_ASM(mm4) - DEF_ASM(mm5) - DEF_ASM(mm6) - DEF_ASM(mm7) - DEF_ASM(xmm0) - DEF_ASM(xmm1) - DEF_ASM(xmm2) - DEF_ASM(xmm3) - DEF_ASM(xmm4) - DEF_ASM(xmm5) - DEF_ASM(xmm6) - DEF_ASM(xmm7) - DEF_ASM(cr0) - DEF_ASM(cr1) - DEF_ASM(cr2) - DEF_ASM(cr3) - DEF_ASM(cr4) - DEF_ASM(cr5) - DEF_ASM(cr6) - DEF_ASM(cr7) - DEF_ASM(tr0) - DEF_ASM(tr1) - DEF_ASM(tr2) - DEF_ASM(tr3) - DEF_ASM(tr4) - DEF_ASM(tr5) - DEF_ASM(tr6) - DEF_ASM(tr7) - DEF_ASM(db0) - DEF_ASM(db1) - DEF_ASM(db2) - DEF_ASM(db3) - DEF_ASM(db4) - DEF_ASM(db5) - DEF_ASM(db6) - DEF_ASM(db7) - DEF_ASM(dr0) - DEF_ASM(dr1) - DEF_ASM(dr2) - DEF_ASM(dr3) - DEF_ASM(dr4) - DEF_ASM(dr5) - DEF_ASM(dr6) - DEF_ASM(dr7) - DEF_ASM(es) - DEF_ASM(cs) - DEF_ASM(ss) - DEF_ASM(ds) - DEF_ASM(fs) - DEF_ASM(gs) - DEF_ASM(st) - DEF_ASM(rip) - -#ifdef TCC_TARGET_X86_64 - /* The four low parts of sp/bp/si/di that exist only on - x86-64 (encoding aliased to ah,ch,dh,dh when not using REX). */ - DEF_ASM(spl) - DEF_ASM(bpl) - DEF_ASM(sil) - DEF_ASM(dil) -#endif - /* generic two operands */ - DEF_BWLX(mov) - - DEF_BWLX(add) - DEF_BWLX(or) - DEF_BWLX(adc) - DEF_BWLX(sbb) - DEF_BWLX(and) - DEF_BWLX(sub) - DEF_BWLX(xor) - DEF_BWLX(cmp) - - /* unary ops */ - DEF_BWLX(inc) - DEF_BWLX(dec) - DEF_BWLX(not) - DEF_BWLX(neg) - DEF_BWLX(mul) - DEF_BWLX(imul) - DEF_BWLX(div) - DEF_BWLX(idiv) - - DEF_BWLX(xchg) - DEF_BWLX(test) - - /* shifts */ - DEF_BWLX(rol) - DEF_BWLX(ror) - DEF_BWLX(rcl) - DEF_BWLX(rcr) - DEF_BWLX(shl) - DEF_BWLX(shr) - DEF_BWLX(sar) - - DEF_WLX(shld) - DEF_WLX(shrd) - - DEF_ASM(pushw) - DEF_ASM(pushl) -#ifdef TCC_TARGET_X86_64 - DEF_ASM(pushq) -#endif - DEF_ASM(push) - - DEF_ASM(popw) - DEF_ASM(popl) -#ifdef TCC_TARGET_X86_64 - DEF_ASM(popq) -#endif - DEF_ASM(pop) - - DEF_BWL(in) - DEF_BWL(out) - - DEF_WLX(movzb) - DEF_ASM(movzwl) - DEF_ASM(movsbw) - DEF_ASM(movsbl) - DEF_ASM(movswl) -#ifdef TCC_TARGET_X86_64 - DEF_ASM(movsbq) - DEF_ASM(movswq) - DEF_ASM(movzwq) - DEF_ASM(movslq) -#endif - - DEF_WLX(lea) - - DEF_ASM(les) - DEF_ASM(lds) - DEF_ASM(lss) - DEF_ASM(lfs) - DEF_ASM(lgs) - - DEF_ASM(call) - DEF_ASM(jmp) - DEF_ASM(lcall) - DEF_ASM(ljmp) - - DEF_ASMTEST(j,) - - DEF_ASMTEST(set,) - DEF_ASMTEST(set,b) - DEF_ASMTEST(cmov,) - - DEF_WLX(bsf) - DEF_WLX(bsr) - DEF_WLX(bt) - DEF_WLX(bts) - DEF_WLX(btr) - DEF_WLX(btc) - - DEF_WLX(lar) - DEF_WLX(lsl) - - /* generic FP ops */ - DEF_FP(add) - DEF_FP(mul) - - DEF_ASM(fcom) - DEF_ASM(fcom_1) /* non existent op, just to have a regular table */ - DEF_FP1(com) - - DEF_FP(comp) - DEF_FP(sub) - DEF_FP(subr) - DEF_FP(div) - DEF_FP(divr) - - DEF_BWLX(xadd) - DEF_BWLX(cmpxchg) - - /* string ops */ - DEF_BWLX(cmps) - DEF_BWLX(scmp) - DEF_BWL(ins) - DEF_BWL(outs) - DEF_BWLX(lods) - DEF_BWLX(slod) - DEF_BWLX(movs) - DEF_BWLX(smov) - DEF_BWLX(scas) - DEF_BWLX(ssca) - DEF_BWLX(stos) - DEF_BWLX(ssto) - - /* generic asm ops */ -#define ALT(x) -#define DEF_ASM_OP0(name, opcode) DEF_ASM(name) -#define DEF_ASM_OP0L(name, opcode, group, instr_type) -#define DEF_ASM_OP1(name, opcode, group, instr_type, op0) -#define DEF_ASM_OP2(name, opcode, group, instr_type, op0, op1) -#define DEF_ASM_OP3(name, opcode, group, instr_type, op0, op1, op2) -#ifdef TCC_TARGET_X86_64 -# include "x86_64-asm.h" -#else -# include "i386-asm.h" -#endif - -#define ALT(x) -#define DEF_ASM_OP0(name, opcode) -#define DEF_ASM_OP0L(name, opcode, group, instr_type) DEF_ASM(name) -#define DEF_ASM_OP1(name, opcode, group, instr_type, op0) DEF_ASM(name) -#define DEF_ASM_OP2(name, opcode, group, instr_type, op0, op1) DEF_ASM(name) -#define DEF_ASM_OP3(name, opcode, group, instr_type, op0, op1, op2) DEF_ASM(name) -#ifdef TCC_TARGET_X86_64 -# include "x86_64-asm.h" -#else -# include "i386-asm.h" -#endif diff --git a/05/tcc-final-old/il-gen.c b/05/tcc-final-old/il-gen.c deleted file mode 100644 index bb670cc..0000000 --- a/05/tcc-final-old/il-gen.c +++ /dev/null @@ -1,657 +0,0 @@ -/* - * CIL code generator for TCC - * - * Copyright (c) 2002 Fabrice Bellard - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#error this code has bit-rotted since 2003 - -/* number of available registers */ -#define NB_REGS 3 - -/* a register can belong to several classes. The classes must be - sorted from more general to more precise (see gv2() code which does - assumptions on it). */ -#define RC_ST 0x0001 /* any stack entry */ -#define RC_ST0 0x0002 /* top of stack */ -#define RC_ST1 0x0004 /* top - 1 */ - -#define RC_INT RC_ST -#define RC_FLOAT RC_ST -#define RC_IRET RC_ST0 /* function return: integer register */ -#define RC_LRET RC_ST0 /* function return: second integer register */ -#define RC_FRET RC_ST0 /* function return: float register */ - -/* pretty names for the registers */ -enum { - REG_ST0 = 0, - REG_ST1, - REG_ST2, -}; - -const int reg_classes[NB_REGS] = { - /* ST0 */ RC_ST | RC_ST0, - /* ST1 */ RC_ST | RC_ST1, - /* ST2 */ RC_ST, -}; - -/* return registers for function */ -#define REG_IRET REG_ST0 /* single word int return register */ -#define REG_LRET REG_ST0 /* second word return register (for long long) */ -#define REG_FRET REG_ST0 /* float return register */ - -/* defined if function parameters must be evaluated in reverse order */ -/* #define INVERT_FUNC_PARAMS */ - -/* defined if structures are passed as pointers. Otherwise structures - are directly pushed on stack. */ -/* #define FUNC_STRUCT_PARAM_AS_PTR */ - -/* pointer size, in bytes */ -#define PTR_SIZE 4 - -/* long double size and alignment, in bytes */ -#define LDOUBLE_SIZE 8 -#define LDOUBLE_ALIGN 8 - -/* function call context */ -typedef struct GFuncContext { - int func_call; /* func call type (FUNC_STDCALL or FUNC_CDECL) */ -} GFuncContext; - -/******************************************************/ -/* opcode definitions */ - -#define IL_OP_PREFIX 0xFE - -enum ILOPCodes { -#define OP(name, str, n) IL_OP_ ## name = n, -#include "il-opcodes.h" -#undef OP -}; - -char *il_opcodes_str[] = { -#define OP(name, str, n) [n] = str, -#include "il-opcodes.h" -#undef OP -}; - -/******************************************************/ - -/* arguments variable numbers start from there */ -#define ARG_BASE 0x70000000 - -static FILE *il_outfile; - -static void out_byte(int c) -{ - *(char *)ind++ = c; -} - -static void out_le32(int c) -{ - out_byte(c); - out_byte(c >> 8); - out_byte(c >> 16); - out_byte(c >> 24); -} - -static void init_outfile(void) -{ - if (!il_outfile) { - il_outfile = stdout; - fprintf(il_outfile, - ".assembly extern mscorlib\n" - "{\n" - ".ver 1:0:2411:0\n" - "}\n\n"); - } -} - -static void out_op1(int op) -{ - if (op & 0x100) - out_byte(IL_OP_PREFIX); - out_byte(op & 0xff); -} - -/* output an opcode with prefix */ -static void out_op(int op) -{ - out_op1(op); - fprintf(il_outfile, " %s\n", il_opcodes_str[op]); -} - -static void out_opb(int op, int c) -{ - out_op1(op); - out_byte(c); - fprintf(il_outfile, " %s %d\n", il_opcodes_str[op], c); -} - -static void out_opi(int op, int c) -{ - out_op1(op); - out_le32(c); - fprintf(il_outfile, " %s 0x%x\n", il_opcodes_str[op], c); -} - -/* XXX: not complete */ -static void il_type_to_str(char *buf, int buf_size, - int t, const char *varstr) -{ - int bt; - Sym *s, *sa; - char buf1[256]; - const char *tstr; - - t = t & VT_TYPE; - bt = t & VT_BTYPE; - buf[0] = '\0'; - if (t & VT_UNSIGNED) - pstrcat(buf, buf_size, "unsigned "); - switch(bt) { - case VT_VOID: - tstr = "void"; - goto add_tstr; - case VT_BOOL: - tstr = "bool"; - goto add_tstr; - case VT_BYTE: - tstr = "int8"; - goto add_tstr; - case VT_SHORT: - tstr = "int16"; - goto add_tstr; - case VT_ENUM: - case VT_INT: - case VT_LONG: - tstr = "int32"; - goto add_tstr; - case VT_LLONG: - tstr = "int64"; - goto add_tstr; - case VT_FLOAT: - tstr = "float32"; - goto add_tstr; - case VT_DOUBLE: - case VT_LDOUBLE: - tstr = "float64"; - add_tstr: - pstrcat(buf, buf_size, tstr); - break; - case VT_STRUCT: - tcc_error("structures not handled yet"); - break; - case VT_FUNC: - s = sym_find((unsigned)t >> VT_STRUCT_SHIFT); - il_type_to_str(buf, buf_size, s->t, varstr); - pstrcat(buf, buf_size, "("); - sa = s->next; - while (sa != NULL) { - il_type_to_str(buf1, sizeof(buf1), sa->t, NULL); - pstrcat(buf, buf_size, buf1); - sa = sa->next; - if (sa) - pstrcat(buf, buf_size, ", "); - } - pstrcat(buf, buf_size, ")"); - goto no_var; - case VT_PTR: - s = sym_find((unsigned)t >> VT_STRUCT_SHIFT); - pstrcpy(buf1, sizeof(buf1), "*"); - if (varstr) - pstrcat(buf1, sizeof(buf1), varstr); - il_type_to_str(buf, buf_size, s->t, buf1); - goto no_var; - } - if (varstr) { - pstrcat(buf, buf_size, " "); - pstrcat(buf, buf_size, varstr); - } - no_var: ; -} - - -/* patch relocation entry with value 'val' */ -void greloc_patch1(Reloc *p, int val) -{ -} - -/* output a symbol and patch all calls to it */ -void gsym_addr(t, a) -{ -} - -/* output jump and return symbol */ -static int out_opj(int op, int c) -{ - out_op1(op); - out_le32(0); - if (c == 0) { - c = ind - (int)cur_text_section->data; - } - fprintf(il_outfile, " %s L%d\n", il_opcodes_str[op], c); - return c; -} - -void gsym(int t) -{ - fprintf(il_outfile, "L%d:\n", t); -} - -/* load 'r' from value 'sv' */ -void load(int r, SValue *sv) -{ - int v, fc, ft; - - v = sv->r & VT_VALMASK; - fc = sv->c.i; - ft = sv->t; - - if (sv->r & VT_LVAL) { - if (v == VT_LOCAL) { - if (fc >= ARG_BASE) { - fc -= ARG_BASE; - if (fc >= 0 && fc <= 4) { - out_op(IL_OP_LDARG_0 + fc); - } else if (fc <= 0xff) { - out_opb(IL_OP_LDARG_S, fc); - } else { - out_opi(IL_OP_LDARG, fc); - } - } else { - if (fc >= 0 && fc <= 4) { - out_op(IL_OP_LDLOC_0 + fc); - } else if (fc <= 0xff) { - out_opb(IL_OP_LDLOC_S, fc); - } else { - out_opi(IL_OP_LDLOC, fc); - } - } - } else if (v == VT_CONST) { - /* XXX: handle globals */ - out_opi(IL_OP_LDSFLD, 0); - } else { - if ((ft & VT_BTYPE) == VT_FLOAT) { - out_op(IL_OP_LDIND_R4); - } else if ((ft & VT_BTYPE) == VT_DOUBLE) { - out_op(IL_OP_LDIND_R8); - } else if ((ft & VT_BTYPE) == VT_LDOUBLE) { - out_op(IL_OP_LDIND_R8); - } else if ((ft & VT_TYPE) == VT_BYTE) - out_op(IL_OP_LDIND_I1); - else if ((ft & VT_TYPE) == (VT_BYTE | VT_UNSIGNED)) - out_op(IL_OP_LDIND_U1); - else if ((ft & VT_TYPE) == VT_SHORT) - out_op(IL_OP_LDIND_I2); - else if ((ft & VT_TYPE) == (VT_SHORT | VT_UNSIGNED)) - out_op(IL_OP_LDIND_U2); - else - out_op(IL_OP_LDIND_I4); - } - } else { - if (v == VT_CONST) { - /* XXX: handle globals */ - if (fc >= -1 && fc <= 8) { - out_op(IL_OP_LDC_I4_M1 + fc + 1); - } else { - out_opi(IL_OP_LDC_I4, fc); - } - } else if (v == VT_LOCAL) { - if (fc >= ARG_BASE) { - fc -= ARG_BASE; - if (fc <= 0xff) { - out_opb(IL_OP_LDARGA_S, fc); - } else { - out_opi(IL_OP_LDARGA, fc); - } - } else { - if (fc <= 0xff) { - out_opb(IL_OP_LDLOCA_S, fc); - } else { - out_opi(IL_OP_LDLOCA, fc); - } - } - } else { - /* XXX: do it */ - } - } -} - -/* store register 'r' in lvalue 'v' */ -void store(int r, SValue *sv) -{ - int v, fc, ft; - - v = sv->r & VT_VALMASK; - fc = sv->c.i; - ft = sv->t; - if (v == VT_LOCAL) { - if (fc >= ARG_BASE) { - fc -= ARG_BASE; - /* XXX: check IL arg store semantics */ - if (fc <= 0xff) { - out_opb(IL_OP_STARG_S, fc); - } else { - out_opi(IL_OP_STARG, fc); - } - } else { - if (fc >= 0 && fc <= 4) { - out_op(IL_OP_STLOC_0 + fc); - } else if (fc <= 0xff) { - out_opb(IL_OP_STLOC_S, fc); - } else { - out_opi(IL_OP_STLOC, fc); - } - } - } else if (v == VT_CONST) { - /* XXX: handle globals */ - out_opi(IL_OP_STSFLD, 0); - } else { - if ((ft & VT_BTYPE) == VT_FLOAT) - out_op(IL_OP_STIND_R4); - else if ((ft & VT_BTYPE) == VT_DOUBLE) - out_op(IL_OP_STIND_R8); - else if ((ft & VT_BTYPE) == VT_LDOUBLE) - out_op(IL_OP_STIND_R8); - else if ((ft & VT_BTYPE) == VT_BYTE) - out_op(IL_OP_STIND_I1); - else if ((ft & VT_BTYPE) == VT_SHORT) - out_op(IL_OP_STIND_I2); - else - out_op(IL_OP_STIND_I4); - } -} - -/* start function call and return function call context */ -void gfunc_start(GFuncContext *c, int func_call) -{ - c->func_call = func_call; -} - -/* push function parameter which is in (vtop->t, vtop->c). Stack entry - is then popped. */ -void gfunc_param(GFuncContext *c) -{ - if ((vtop->t & VT_BTYPE) == VT_STRUCT) { - tcc_error("structures passed as value not handled yet"); - } else { - /* simply push on stack */ - gv(RC_ST0); - } - vtop--; -} - -/* generate function call with address in (vtop->t, vtop->c) and free function - context. Stack entry is popped */ -void gfunc_call(GFuncContext *c) -{ - char buf[1024]; - - if ((vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST) { - /* XXX: more info needed from tcc */ - il_type_to_str(buf, sizeof(buf), vtop->t, "xxx"); - fprintf(il_outfile, " call %s\n", buf); - } else { - /* indirect call */ - gv(RC_INT); - il_type_to_str(buf, sizeof(buf), vtop->t, NULL); - fprintf(il_outfile, " calli %s\n", buf); - } - vtop--; -} - -/* generate function prolog of type 't' */ -void gfunc_prolog(int t) -{ - int addr, u, func_call; - Sym *sym; - char buf[1024]; - - init_outfile(); - - /* XXX: pass function name to gfunc_prolog */ - il_type_to_str(buf, sizeof(buf), t, funcname); - fprintf(il_outfile, ".method static %s il managed\n", buf); - fprintf(il_outfile, "{\n"); - /* XXX: cannot do better now */ - fprintf(il_outfile, " .maxstack %d\n", NB_REGS); - fprintf(il_outfile, " .locals (int32, int32, int32, int32, int32, int32, int32, int32)\n"); - - if (!strcmp(funcname, "main")) - fprintf(il_outfile, " .entrypoint\n"); - - sym = sym_find((unsigned)t >> VT_STRUCT_SHIFT); - func_call = sym->r; - - addr = ARG_BASE; - /* if the function returns a structure, then add an - implicit pointer parameter */ - func_vt = sym->t; - func_var = (sym->c == FUNC_ELLIPSIS); - if ((func_vt & VT_BTYPE) == VT_STRUCT) { - func_vc = addr; - addr++; - } - /* define parameters */ - while ((sym = sym->next) != NULL) { - u = sym->t; - sym_push(sym->v & ~SYM_FIELD, u, - VT_LOCAL | lvalue_type(sym->type.t), addr); - addr++; - } -} - -/* generate function epilog */ -void gfunc_epilog(void) -{ - out_op(IL_OP_RET); - fprintf(il_outfile, "}\n\n"); -} - -/* generate a jump to a label */ -int gjmp(int t) -{ - return out_opj(IL_OP_BR, t); -} - -/* generate a jump to a fixed address */ -void gjmp_addr(int a) -{ - /* XXX: handle syms */ - out_opi(IL_OP_BR, a); -} - -/* generate a test. set 'inv' to invert test. Stack entry is popped */ -int gtst(int inv, int t) -{ - int v, *p, c; - - v = vtop->r & VT_VALMASK; - if (v == VT_CMP) { - c = vtop->c.i ^ inv; - switch(c) { - case TOK_EQ: - c = IL_OP_BEQ; - break; - case TOK_NE: - c = IL_OP_BNE_UN; - break; - case TOK_LT: - c = IL_OP_BLT; - break; - case TOK_LE: - c = IL_OP_BLE; - break; - case TOK_GT: - c = IL_OP_BGT; - break; - case TOK_GE: - c = IL_OP_BGE; - break; - case TOK_ULT: - c = IL_OP_BLT_UN; - break; - case TOK_ULE: - c = IL_OP_BLE_UN; - break; - case TOK_UGT: - c = IL_OP_BGT_UN; - break; - case TOK_UGE: - c = IL_OP_BGE_UN; - break; - } - t = out_opj(c, t); - } else if (v == VT_JMP || v == VT_JMPI) { - /* && or || optimization */ - if ((v & 1) == inv) { - /* insert vtop->c jump list in t */ - p = &vtop->c.i; - while (*p != 0) - p = (int *)*p; - *p = t; - t = vtop->c.i; - } else { - t = gjmp(t); - gsym(vtop->c.i); - } - } - vtop--; - return t; -} - -/* generate an integer binary operation */ -void gen_opi(int op) -{ - gv2(RC_ST1, RC_ST0); - switch(op) { - case '+': - out_op(IL_OP_ADD); - goto std_op; - case '-': - out_op(IL_OP_SUB); - goto std_op; - case '&': - out_op(IL_OP_AND); - goto std_op; - case '^': - out_op(IL_OP_XOR); - goto std_op; - case '|': - out_op(IL_OP_OR); - goto std_op; - case '*': - out_op(IL_OP_MUL); - goto std_op; - case TOK_SHL: - out_op(IL_OP_SHL); - goto std_op; - case TOK_SHR: - out_op(IL_OP_SHR_UN); - goto std_op; - case TOK_SAR: - out_op(IL_OP_SHR); - goto std_op; - case '/': - case TOK_PDIV: - out_op(IL_OP_DIV); - goto std_op; - case TOK_UDIV: - out_op(IL_OP_DIV_UN); - goto std_op; - case '%': - out_op(IL_OP_REM); - goto std_op; - case TOK_UMOD: - out_op(IL_OP_REM_UN); - std_op: - vtop--; - vtop[0].r = REG_ST0; - break; - case TOK_EQ: - case TOK_NE: - case TOK_LT: - case TOK_LE: - case TOK_GT: - case TOK_GE: - case TOK_ULT: - case TOK_ULE: - case TOK_UGT: - case TOK_UGE: - vtop--; - vtop[0].r = VT_CMP; - vtop[0].c.i = op; - break; - } -} - -/* generate a floating point operation 'v = t1 op t2' instruction. The - two operands are guaranteed to have the same floating point type */ -void gen_opf(int op) -{ - /* same as integer */ - gen_opi(op); -} - -/* convert integers to fp 't' type. Must handle 'int', 'unsigned int' - and 'long long' cases. */ -void gen_cvt_itof(int t) -{ - gv(RC_ST0); - if (t == VT_FLOAT) - out_op(IL_OP_CONV_R4); - else - out_op(IL_OP_CONV_R8); -} - -/* convert fp to int 't' type */ -/* XXX: handle long long case */ -void gen_cvt_ftoi(int t) -{ - gv(RC_ST0); - switch(t) { - case VT_INT | VT_UNSIGNED: - out_op(IL_OP_CONV_U4); - break; - case VT_LLONG: - out_op(IL_OP_CONV_I8); - break; - case VT_LLONG | VT_UNSIGNED: - out_op(IL_OP_CONV_U8); - break; - default: - out_op(IL_OP_CONV_I4); - break; - } -} - -/* convert from one floating point type to another */ -void gen_cvt_ftof(int t) -{ - gv(RC_ST0); - if (t == VT_FLOAT) { - out_op(IL_OP_CONV_R4); - } else { - out_op(IL_OP_CONV_R8); - } -} - -/* end of CIL code generator */ -/*************************************************************/ - diff --git a/05/tcc-final-old/il-opcodes.h b/05/tcc-final-old/il-opcodes.h deleted file mode 100644 index d53ffb2..0000000 --- a/05/tcc-final-old/il-opcodes.h +++ /dev/null @@ -1,251 +0,0 @@ -/* - * CIL opcode definition - * - * Copyright (c) 2002 Fabrice Bellard - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ -OP(NOP, "nop", 0x00) -OP(BREAK, "break", 0x01) -OP(LDARG_0, "ldarg.0", 0x02) -OP(LDARG_1, "ldarg.1", 0x03) -OP(LDARG_2, "ldarg.2", 0x04) -OP(LDARG_3, "ldarg.3", 0x05) -OP(LDLOC_0, "ldloc.0", 0x06) -OP(LDLOC_1, "ldloc.1", 0x07) -OP(LDLOC_2, "ldloc.2", 0x08) -OP(LDLOC_3, "ldloc.3", 0x09) -OP(STLOC_0, "stloc.0", 0x0a) -OP(STLOC_1, "stloc.1", 0x0b) -OP(STLOC_2, "stloc.2", 0x0c) -OP(STLOC_3, "stloc.3", 0x0d) -OP(LDARG_S, "ldarg.s", 0x0e) -OP(LDARGA_S, "ldarga.s", 0x0f) -OP(STARG_S, "starg.s", 0x10) -OP(LDLOC_S, "ldloc.s", 0x11) -OP(LDLOCA_S, "ldloca.s", 0x12) -OP(STLOC_S, "stloc.s", 0x13) -OP(LDNULL, "ldnull", 0x14) -OP(LDC_I4_M1, "ldc.i4.m1", 0x15) -OP(LDC_I4_0, "ldc.i4.0", 0x16) -OP(LDC_I4_1, "ldc.i4.1", 0x17) -OP(LDC_I4_2, "ldc.i4.2", 0x18) -OP(LDC_I4_3, "ldc.i4.3", 0x19) -OP(LDC_I4_4, "ldc.i4.4", 0x1a) -OP(LDC_I4_5, "ldc.i4.5", 0x1b) -OP(LDC_I4_6, "ldc.i4.6", 0x1c) -OP(LDC_I4_7, "ldc.i4.7", 0x1d) -OP(LDC_I4_8, "ldc.i4.8", 0x1e) -OP(LDC_I4_S, "ldc.i4.s", 0x1f) -OP(LDC_I4, "ldc.i4", 0x20) -OP(LDC_I8, "ldc.i8", 0x21) -OP(LDC_R4, "ldc.r4", 0x22) -OP(LDC_R8, "ldc.r8", 0x23) -OP(LDPTR, "ldptr", 0x24) -OP(DUP, "dup", 0x25) -OP(POP, "pop", 0x26) -OP(JMP, "jmp", 0x27) -OP(CALL, "call", 0x28) -OP(CALLI, "calli", 0x29) -OP(RET, "ret", 0x2a) -OP(BR_S, "br.s", 0x2b) -OP(BRFALSE_S, "brfalse.s", 0x2c) -OP(BRTRUE_S, "brtrue.s", 0x2d) -OP(BEQ_S, "beq.s", 0x2e) -OP(BGE_S, "bge.s", 0x2f) -OP(BGT_S, "bgt.s", 0x30) -OP(BLE_S, "ble.s", 0x31) -OP(BLT_S, "blt.s", 0x32) -OP(BNE_UN_S, "bne.un.s", 0x33) -OP(BGE_UN_S, "bge.un.s", 0x34) -OP(BGT_UN_S, "bgt.un.s", 0x35) -OP(BLE_UN_S, "ble.un.s", 0x36) -OP(BLT_UN_S, "blt.un.s", 0x37) -OP(BR, "br", 0x38) -OP(BRFALSE, "brfalse", 0x39) -OP(BRTRUE, "brtrue", 0x3a) -OP(BEQ, "beq", 0x3b) -OP(BGE, "bge", 0x3c) -OP(BGT, "bgt", 0x3d) -OP(BLE, "ble", 0x3e) -OP(BLT, "blt", 0x3f) -OP(BNE_UN, "bne.un", 0x40) -OP(BGE_UN, "bge.un", 0x41) -OP(BGT_UN, "bgt.un", 0x42) -OP(BLE_UN, "ble.un", 0x43) -OP(BLT_UN, "blt.un", 0x44) -OP(SWITCH, "switch", 0x45) -OP(LDIND_I1, "ldind.i1", 0x46) -OP(LDIND_U1, "ldind.u1", 0x47) -OP(LDIND_I2, "ldind.i2", 0x48) -OP(LDIND_U2, "ldind.u2", 0x49) -OP(LDIND_I4, "ldind.i4", 0x4a) -OP(LDIND_U4, "ldind.u4", 0x4b) -OP(LDIND_I8, "ldind.i8", 0x4c) -OP(LDIND_I, "ldind.i", 0x4d) -OP(LDIND_R4, "ldind.r4", 0x4e) -OP(LDIND_R8, "ldind.r8", 0x4f) -OP(LDIND_REF, "ldind.ref", 0x50) -OP(STIND_REF, "stind.ref", 0x51) -OP(STIND_I1, "stind.i1", 0x52) -OP(STIND_I2, "stind.i2", 0x53) -OP(STIND_I4, "stind.i4", 0x54) -OP(STIND_I8, "stind.i8", 0x55) -OP(STIND_R4, "stind.r4", 0x56) -OP(STIND_R8, "stind.r8", 0x57) -OP(ADD, "add", 0x58) -OP(SUB, "sub", 0x59) -OP(MUL, "mul", 0x5a) -OP(DIV, "div", 0x5b) -OP(DIV_UN, "div.un", 0x5c) -OP(REM, "rem", 0x5d) -OP(REM_UN, "rem.un", 0x5e) -OP(AND, "and", 0x5f) -OP(OR, "or", 0x60) -OP(XOR, "xor", 0x61) -OP(SHL, "shl", 0x62) -OP(SHR, "shr", 0x63) -OP(SHR_UN, "shr.un", 0x64) -OP(NEG, "neg", 0x65) -OP(NOT, "not", 0x66) -OP(CONV_I1, "conv.i1", 0x67) -OP(CONV_I2, "conv.i2", 0x68) -OP(CONV_I4, "conv.i4", 0x69) -OP(CONV_I8, "conv.i8", 0x6a) -OP(CONV_R4, "conv.r4", 0x6b) -OP(CONV_R8, "conv.r8", 0x6c) -OP(CONV_U4, "conv.u4", 0x6d) -OP(CONV_U8, "conv.u8", 0x6e) -OP(CALLVIRT, "callvirt", 0x6f) -OP(CPOBJ, "cpobj", 0x70) -OP(LDOBJ, "ldobj", 0x71) -OP(LDSTR, "ldstr", 0x72) -OP(NEWOBJ, "newobj", 0x73) -OP(CASTCLASS, "castclass", 0x74) -OP(ISINST, "isinst", 0x75) -OP(CONV_R_UN, "conv.r.un", 0x76) -OP(ANN_DATA_S, "ann.data.s", 0x77) -OP(UNBOX, "unbox", 0x79) -OP(THROW, "throw", 0x7a) -OP(LDFLD, "ldfld", 0x7b) -OP(LDFLDA, "ldflda", 0x7c) -OP(STFLD, "stfld", 0x7d) -OP(LDSFLD, "ldsfld", 0x7e) -OP(LDSFLDA, "ldsflda", 0x7f) -OP(STSFLD, "stsfld", 0x80) -OP(STOBJ, "stobj", 0x81) -OP(CONV_OVF_I1_UN, "conv.ovf.i1.un", 0x82) -OP(CONV_OVF_I2_UN, "conv.ovf.i2.un", 0x83) -OP(CONV_OVF_I4_UN, "conv.ovf.i4.un", 0x84) -OP(CONV_OVF_I8_UN, "conv.ovf.i8.un", 0x85) -OP(CONV_OVF_U1_UN, "conv.ovf.u1.un", 0x86) -OP(CONV_OVF_U2_UN, "conv.ovf.u2.un", 0x87) -OP(CONV_OVF_U4_UN, "conv.ovf.u4.un", 0x88) -OP(CONV_OVF_U8_UN, "conv.ovf.u8.un", 0x89) -OP(CONV_OVF_I_UN, "conv.ovf.i.un", 0x8a) -OP(CONV_OVF_U_UN, "conv.ovf.u.un", 0x8b) -OP(BOX, "box", 0x8c) -OP(NEWARR, "newarr", 0x8d) -OP(LDLEN, "ldlen", 0x8e) -OP(LDELEMA, "ldelema", 0x8f) -OP(LDELEM_I1, "ldelem.i1", 0x90) -OP(LDELEM_U1, "ldelem.u1", 0x91) -OP(LDELEM_I2, "ldelem.i2", 0x92) -OP(LDELEM_U2, "ldelem.u2", 0x93) -OP(LDELEM_I4, "ldelem.i4", 0x94) -OP(LDELEM_U4, "ldelem.u4", 0x95) -OP(LDELEM_I8, "ldelem.i8", 0x96) -OP(LDELEM_I, "ldelem.i", 0x97) -OP(LDELEM_R4, "ldelem.r4", 0x98) -OP(LDELEM_R8, "ldelem.r8", 0x99) -OP(LDELEM_REF, "ldelem.ref", 0x9a) -OP(STELEM_I, "stelem.i", 0x9b) -OP(STELEM_I1, "stelem.i1", 0x9c) -OP(STELEM_I2, "stelem.i2", 0x9d) -OP(STELEM_I4, "stelem.i4", 0x9e) -OP(STELEM_I8, "stelem.i8", 0x9f) -OP(STELEM_R4, "stelem.r4", 0xa0) -OP(STELEM_R8, "stelem.r8", 0xa1) -OP(STELEM_REF, "stelem.ref", 0xa2) -OP(CONV_OVF_I1, "conv.ovf.i1", 0xb3) -OP(CONV_OVF_U1, "conv.ovf.u1", 0xb4) -OP(CONV_OVF_I2, "conv.ovf.i2", 0xb5) -OP(CONV_OVF_U2, "conv.ovf.u2", 0xb6) -OP(CONV_OVF_I4, "conv.ovf.i4", 0xb7) -OP(CONV_OVF_U4, "conv.ovf.u4", 0xb8) -OP(CONV_OVF_I8, "conv.ovf.i8", 0xb9) -OP(CONV_OVF_U8, "conv.ovf.u8", 0xba) -OP(REFANYVAL, "refanyval", 0xc2) -OP(CKFINITE, "ckfinite", 0xc3) -OP(MKREFANY, "mkrefany", 0xc6) -OP(ANN_CALL, "ann.call", 0xc7) -OP(ANN_CATCH, "ann.catch", 0xc8) -OP(ANN_DEAD, "ann.dead", 0xc9) -OP(ANN_HOISTED, "ann.hoisted", 0xca) -OP(ANN_HOISTED_CALL, "ann.hoisted.call", 0xcb) -OP(ANN_LAB, "ann.lab", 0xcc) -OP(ANN_DEF, "ann.def", 0xcd) -OP(ANN_REF_S, "ann.ref.s", 0xce) -OP(ANN_PHI, "ann.phi", 0xcf) -OP(LDTOKEN, "ldtoken", 0xd0) -OP(CONV_U2, "conv.u2", 0xd1) -OP(CONV_U1, "conv.u1", 0xd2) -OP(CONV_I, "conv.i", 0xd3) -OP(CONV_OVF_I, "conv.ovf.i", 0xd4) -OP(CONV_OVF_U, "conv.ovf.u", 0xd5) -OP(ADD_OVF, "add.ovf", 0xd6) -OP(ADD_OVF_UN, "add.ovf.un", 0xd7) -OP(MUL_OVF, "mul.ovf", 0xd8) -OP(MUL_OVF_UN, "mul.ovf.un", 0xd9) -OP(SUB_OVF, "sub.ovf", 0xda) -OP(SUB_OVF_UN, "sub.ovf.un", 0xdb) -OP(ENDFINALLY, "endfinally", 0xdc) -OP(LEAVE, "leave", 0xdd) -OP(LEAVE_S, "leave.s", 0xde) -OP(STIND_I, "stind.i", 0xdf) -OP(CONV_U, "conv.u", 0xe0) - -/* prefix instructions. we use an opcode >= 256 to ease coding */ - -OP(ARGLIST, "arglist", 0x100) -OP(CEQ, "ceq", 0x101) -OP(CGT, "cgt", 0x102) -OP(CGT_UN, "cgt.un", 0x103) -OP(CLT, "clt", 0x104) -OP(CLT_UN, "clt.un", 0x105) -OP(LDFTN, "ldftn", 0x106) -OP(LDVIRTFTN, "ldvirtftn", 0x107) -OP(JMPI, "jmpi", 0x108) -OP(LDARG, "ldarg", 0x109) -OP(LDARGA, "ldarga", 0x10a) -OP(STARG, "starg", 0x10b) -OP(LDLOC, "ldloc", 0x10c) -OP(LDLOCA, "ldloca", 0x10d) -OP(STLOC, "stloc", 0x10e) -OP(LOCALLOC, "localloc", 0x10f) -OP(ENDFILTER, "endfilter", 0x111) -OP(UNALIGNED, "unaligned", 0x112) -OP(VOLATILE, "volatile", 0x113) -OP(TAIL, "tail", 0x114) -OP(INITOBJ, "initobj", 0x115) -OP(ANN_LIVE, "ann.live", 0x116) -OP(CPBLK, "cpblk", 0x117) -OP(INITBLK, "initblk", 0x118) -OP(ANN_REF, "ann.ref", 0x119) -OP(RETHROW, "rethrow", 0x11a) -OP(SIZEOF, "sizeof", 0x11c) -OP(REFANYTYPE, "refanytype", 0x11d) -OP(ANN_DATA, "ann.data", 0x122) -OP(ANN_ARG, "ann.arg", 0x123) diff --git a/05/tcc-final-old/include/float.h b/05/tcc-final-old/include/float.h deleted file mode 100644 index f16f1f0..0000000 --- a/05/tcc-final-old/include/float.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef _FLOAT_H_ -#define _FLOAT_H_ - -#define FLT_RADIX 2 - -/* IEEE float */ -#define FLT_MANT_DIG 24 -#define FLT_DIG 6 -#define FLT_ROUNDS 1 -#define FLT_EPSILON 1.19209290e-07F -#define FLT_MIN_EXP (-125) -#define FLT_MIN 1.17549435e-38F -#define FLT_MIN_10_EXP (-37) -#define FLT_MAX_EXP 128 -#define FLT_MAX 3.40282347e+38F -#define FLT_MAX_10_EXP 38 - -/* IEEE double */ -#define DBL_MANT_DIG 53 -#define DBL_DIG 15 -#define DBL_EPSILON 2.2204460492503131e-16 -#define DBL_MIN_EXP (-1021) -#define DBL_MIN 2.2250738585072014e-308 -#define DBL_MIN_10_EXP (-307) -#define DBL_MAX_EXP 1024 -#define DBL_MAX 1.7976931348623157e+308 -#define DBL_MAX_10_EXP 308 - -/* horrible intel long double */ -#if defined __i386__ || defined __x86_64__ - -#define LDBL_MANT_DIG 64 -#define LDBL_DIG 18 -#define LDBL_EPSILON 1.08420217248550443401e-19L -#define LDBL_MIN_EXP (-16381) -#define LDBL_MIN 3.36210314311209350626e-4932L -#define LDBL_MIN_10_EXP (-4931) -#define LDBL_MAX_EXP 16384 -#define LDBL_MAX 1.18973149535723176502e+4932L -#define LDBL_MAX_10_EXP 4932 - -#else - -/* same as IEEE double */ -#define LDBL_MANT_DIG 53 -#define LDBL_DIG 15 -#define LDBL_EPSILON 2.2204460492503131e-16 -#define LDBL_MIN_EXP (-1021) -#define LDBL_MIN 2.2250738585072014e-308 -#define LDBL_MIN_10_EXP (-307) -#define LDBL_MAX_EXP 1024 -#define LDBL_MAX 1.7976931348623157e+308 -#define LDBL_MAX_10_EXP 308 - -#endif - -#endif /* _FLOAT_H_ */ diff --git a/05/tcc-final-old/include/stdarg.h b/05/tcc-final-old/include/stdarg.h deleted file mode 100644 index 10ce733..0000000 --- a/05/tcc-final-old/include/stdarg.h +++ /dev/null @@ -1,79 +0,0 @@ -#ifndef _STDARG_H -#define _STDARG_H - -#ifdef __x86_64__ -#ifndef _WIN64 - -//This should be in sync with the declaration on our lib/libtcc1.c -/* GCC compatible definition of va_list. */ -typedef struct { - unsigned int gp_offset; - unsigned int fp_offset; - union { - unsigned int overflow_offset; - char *overflow_arg_area; - }; - char *reg_save_area; -} __va_list_struct; - -typedef __va_list_struct va_list[1]; - -void __va_start(__va_list_struct *ap, void *fp); -void *__va_arg(__va_list_struct *ap, int arg_type, int size, int align); - -#define va_start(ap, last) __va_start(ap, __builtin_frame_address(0)) -#define va_arg(ap, type) \ - (*(type *)(__va_arg(ap, __builtin_va_arg_types(type), sizeof(type), __alignof__(type)))) -#define va_copy(dest, src) (*(dest) = *(src)) -#define va_end(ap) - -/* avoid conflicting definition for va_list on Macs. */ -#define _VA_LIST_T - -#else /* _WIN64 */ -typedef char *va_list; -#define va_start(ap,last) __builtin_va_start(ap,last) -#define va_arg(ap, t) ((sizeof(t) > 8 || (sizeof(t) & (sizeof(t) - 1))) \ - ? **(t **)((ap += 8) - 8) : *(t *)((ap += 8) - 8)) -#define va_copy(dest, src) ((dest) = (src)) -#define va_end(ap) -#endif - -#elif __arm__ -typedef char *va_list; -#define _tcc_alignof(type) ((int)&((struct {char c;type x;} *)0)->x) -#define _tcc_align(addr,type) (((unsigned)addr + _tcc_alignof(type) - 1) \ - & ~(_tcc_alignof(type) - 1)) -#define va_start(ap,last) ap = ((char *)&(last)) + ((sizeof(last)+3)&~3) -#define va_arg(ap,type) (ap = (void *) ((_tcc_align(ap,type)+sizeof(type)+3) \ - &~3), *(type *)(ap - ((sizeof(type)+3)&~3))) -#define va_copy(dest, src) (dest) = (src) -#define va_end(ap) - -#elif defined(__aarch64__) -typedef struct { - void *__stack; - void *__gr_top; - void *__vr_top; - int __gr_offs; - int __vr_offs; -} va_list; -#define va_start(ap, last) __va_start(ap, last) -#define va_arg(ap, type) __va_arg(ap, type) -#define va_end(ap) -#define va_copy(dest, src) ((dest) = (src)) - -#else /* __i386__ */ -typedef char *va_list; -/* only correct for i386 */ -#define va_start(ap,last) ap = ((char *)&(last)) + ((sizeof(last)+3)&~3) -#define va_arg(ap,type) (ap += (sizeof(type)+3)&~3, *(type *)(ap - ((sizeof(type)+3)&~3))) -#define va_copy(dest, src) (dest) = (src) -#define va_end(ap) -#endif - -/* fix a buggy dependency on GCC in libio.h */ -typedef va_list __gnuc_va_list; -#define _VA_LIST_DEFINED - -#endif /* _STDARG_H */ diff --git a/05/tcc-final-old/include/stdbool.h b/05/tcc-final-old/include/stdbool.h deleted file mode 100644 index d2ee446..0000000 --- a/05/tcc-final-old/include/stdbool.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef _STDBOOL_H -#define _STDBOOL_H - -/* ISOC99 boolean */ - -#define bool _Bool -#define true 1 -#define false 0 -#define __bool_true_false_are_defined 1 - -#endif /* _STDBOOL_H */ diff --git a/05/tcc-final-old/include/stddef.h b/05/tcc-final-old/include/stddef.h deleted file mode 100644 index 694d503..0000000 --- a/05/tcc-final-old/include/stddef.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef _STDDEF_H -#define _STDDEF_H - -typedef __SIZE_TYPE__ size_t; -typedef __PTRDIFF_TYPE__ ssize_t; -typedef __WCHAR_TYPE__ wchar_t; -typedef __PTRDIFF_TYPE__ ptrdiff_t; -typedef __PTRDIFF_TYPE__ intptr_t; -typedef __SIZE_TYPE__ uintptr_t; - -#ifndef __int8_t_defined -#define __int8_t_defined -typedef signed char int8_t; -typedef signed short int int16_t; -typedef signed int int32_t; -#ifdef __LP64__ -typedef signed long int int64_t; -#else -typedef signed long long int int64_t; -#endif -typedef unsigned char uint8_t; -typedef unsigned short int uint16_t; -typedef unsigned int uint32_t; -#ifdef __LP64__ -typedef unsigned long int uint64_t; -#else -typedef unsigned long long int uint64_t; -#endif -#endif - -#ifndef NULL -#define NULL ((void*)0) -#endif - -#define offsetof(type, field) ((size_t)&((type *)0)->field) - -void *alloca(size_t size); - -#endif - -/* Older glibc require a wint_t from (when requested - by __need_wint_t, as otherwise stddef.h isn't allowed to - define this type). Note that this must be outside the normal - _STDDEF_H guard, so that it works even when we've included the file - already (without requiring wint_t). Some other libs define _WINT_T - if they've already provided that type, so we can use that as guard. - TCC defines __WINT_TYPE__ for us. */ -#if defined (__need_wint_t) -#ifndef _WINT_T -#define _WINT_T -typedef __WINT_TYPE__ wint_t; -#endif -#undef __need_wint_t -#endif diff --git a/05/tcc-final-old/include/varargs.h b/05/tcc-final-old/include/varargs.h deleted file mode 100644 index d614366..0000000 --- a/05/tcc-final-old/include/varargs.h +++ /dev/null @@ -1,12 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _VARARGS_H -#define _VARARGS_H - -#error "TinyCC no longer implements ." -#error "Revise your code to use ." - -#endif diff --git a/05/tcc-final-old/lib/Makefile b/05/tcc-final-old/lib/Makefile deleted file mode 100644 index 0c1ec54..0000000 --- a/05/tcc-final-old/lib/Makefile +++ /dev/null @@ -1,73 +0,0 @@ -# -# Tiny C Compiler Makefile for libtcc1.a -# - -TOP = .. -include $(TOP)/Makefile -VPATH = $(TOPSRC)/lib $(TOPSRC)/win32/lib -T = $(or $(CROSS_TARGET),$(NATIVE_TARGET),unknown) -X = $(if $(CROSS_TARGET),$(CROSS_TARGET)-) -BIN = $(TOP)/$(X)libtcc1.a - -XTCC ?= $(TOP)/$(X)tcc$(EXESUF) -XCC = $(XTCC) -XAR = $(XTCC) -ar -XFLAGS-unx = -B$(TOPSRC) -XFLAGS-win = -B$(TOPSRC)/win32 -I$(TOPSRC)/include -XFLAGS = $(XFLAGS$(XCFG)) -XCFG = $(or $(findstring -win,$T),-unx) - -# in order to use gcc, tyoe: make -libtcc1-usegcc=yes -arm-libtcc1-usegcc ?= no - -ifeq "$($(T)-libtcc1-usegcc)" "yes" - XCC = $(CC) - XAR = $(AR) - XFLAGS = $(CFLAGS) -fPIC -endif - -# only for native compiler -$(X)BCHECK_O = bcheck.o - -ifeq ($(CONFIG_musl)$(CONFIG_uClibc),yes) - BCHECK_O = -endif - -ifdef CONFIG_OSX - XFLAGS += -D_ANSI_SOURCE -endif - -I386_O = libtcc1.o alloca86.o alloca86-bt.o -X86_64_O = libtcc1.o alloca86_64.o alloca86_64-bt.o -ARM_O = libtcc1.o armeabi.o alloca-arm.o armflush.o -ARM64_O = lib-arm64.o -WIN_O = crt1.o crt1w.o wincrt1.o wincrt1w.o dllcrt1.o dllmain.o - -OBJ-i386 = $(I386_O) $(BCHECK_O) -OBJ-x86_64 = $(X86_64_O) va_list.o $(BCHECK_O) -OBJ-x86_64-osx = $(X86_64_O) va_list.o -OBJ-i386-win32 = $(I386_O) chkstk.o bcheck.o $(WIN_O) -OBJ-x86_64-win32 = $(X86_64_O) chkstk.o bcheck.o $(WIN_O) -OBJ-arm64 = $(ARM64_O) -OBJ-arm = $(ARM_O) -OBJ-arm-fpa = $(ARM_O) -OBJ-arm-fpa-ld = $(ARM_O) -OBJ-arm-vfp = $(ARM_O) -OBJ-arm-eabi = $(ARM_O) -OBJ-arm-eabihf = $(ARM_O) -OBJ-arm-wince = $(ARM_O) $(WIN_O) - -$(BIN) : $(patsubst %.o,$(X)%.o,$(OBJ-$T)) - $(XAR) rcs $@ $^ - -$(X)%.o : %.c - $(XCC) -c $< -o $@ $(XFLAGS) - -$(X)%.o : %.S - $(XCC) -c $< -o $@ $(XFLAGS) - -$(X)crt1w.o : crt1.c -$(X)wincrt1w.o : wincrt1.c - -clean : - rm -f *.a *.o $(BIN) diff --git a/05/tcc-final-old/lib/alloca-arm.S b/05/tcc-final-old/lib/alloca-arm.S deleted file mode 100644 index 68556e3..0000000 --- a/05/tcc-final-old/lib/alloca-arm.S +++ /dev/null @@ -1,17 +0,0 @@ - .text - .align 2 - .global alloca - .type alloca, %function -alloca: -#ifdef __TINYC__ - .int 0xe060d00d - .int 0xe3cdd007 - .int 0xe1a0000d - .int 0xe1a0f00e -#else - rsb sp, r0, sp - bic sp, sp, #7 - mov r0, sp - mov pc, lr -#endif - .size alloca, .-alloca diff --git a/05/tcc-final-old/lib/alloca86-bt.S b/05/tcc-final-old/lib/alloca86-bt.S deleted file mode 100644 index 4f95cf1..0000000 --- a/05/tcc-final-old/lib/alloca86-bt.S +++ /dev/null @@ -1,47 +0,0 @@ -/* ---------------------------------------------- */ -/* alloca86-bt.S */ - -.globl __bound_alloca - -__bound_alloca: - pop %edx - pop %eax - mov %eax, %ecx - add $3,%eax - and $-4,%eax - jz p6 - -#ifdef _WIN32 -p4: - cmp $4096,%eax - jbe p5 - test %eax,-4096(%esp) - sub $4096,%esp - sub $4096,%eax - jmp p4 - -p5: -#endif - - sub %eax,%esp - mov %esp,%eax - - push %edx - push %eax - push %ecx - push %eax - call __bound_new_region - add $8, %esp - pop %eax - pop %edx - -p6: - push %edx - push %edx - ret - -/* mark stack as nonexecutable */ -#if defined __ELF__ && defined __linux__ - .section .note.GNU-stack,"",@progbits -#endif -/* ---------------------------------------------- */ diff --git a/05/tcc-final-old/lib/alloca86.S b/05/tcc-final-old/lib/alloca86.S deleted file mode 100644 index bb7a2c2..0000000 --- a/05/tcc-final-old/lib/alloca86.S +++ /dev/null @@ -1,31 +0,0 @@ -/* ---------------------------------------------- */ -/* alloca86.S */ - -.globl alloca - -alloca: - pop %edx - pop %eax - add $3,%eax - and $-4,%eax - jz p3 - -#ifdef _WIN32 -p1: - cmp $4096,%eax - jbe p2 - test %eax,-4096(%esp) - sub $4096,%esp - sub $4096,%eax - jmp p1 -p2: -#endif - - sub %eax,%esp - mov %esp,%eax -p3: - push %edx - push %edx - ret - -/* ---------------------------------------------- */ diff --git a/05/tcc-final-old/lib/alloca86_64-bt.S b/05/tcc-final-old/lib/alloca86_64-bt.S deleted file mode 100644 index 4cbad90..0000000 --- a/05/tcc-final-old/lib/alloca86_64-bt.S +++ /dev/null @@ -1,56 +0,0 @@ -/* ---------------------------------------------- */ -/* alloca86_64.S */ - -.globl __bound_alloca -__bound_alloca: - -#ifdef _WIN32 - # bound checking is not implemented - pop %rdx - mov %rcx,%rax - add $15,%rax - and $-16,%rax - jz p3 - -p1: - cmp $4096,%rax - jbe p2 - test %rax,-4096(%rsp) - sub $4096,%rsp - sub $4096,%rax - jmp p1 -p2: - - sub %rax,%rsp - mov %rsp,%rax - add $32,%rax - -p3: - push %rdx - ret -#else - pop %rdx - mov %rdi,%rax - mov %rax,%rsi # size, a second parm to the __bound_new_region - - add $15,%rax - and $-16,%rax - jz p3 - - - sub %rax,%rsp - mov %rsp,%rdi # pointer, a first parm to the __bound_new_region - mov %rsp,%rax - - push %rdx - push %rax - call __bound_new_region - pop %rax - pop %rdx - -p3: - push %rdx - ret -#endif - -/* ---------------------------------------------- */ diff --git a/05/tcc-final-old/lib/alloca86_64.S b/05/tcc-final-old/lib/alloca86_64.S deleted file mode 100644 index ae3c97d..0000000 --- a/05/tcc-final-old/lib/alloca86_64.S +++ /dev/null @@ -1,34 +0,0 @@ -/* ---------------------------------------------- */ -/* alloca86_64.S */ - -.globl alloca - -alloca: - pop %rdx -#ifdef _WIN32 - mov %rcx,%rax -#else - mov %rdi,%rax -#endif - add $15,%rax - and $-16,%rax - jz p3 - -#ifdef _WIN32 -p1: - cmp $4096,%rax - jbe p2 - test %rax,-4096(%rsp) - sub $4096,%rsp - sub $4096,%rax - jmp p1 -p2: -#endif - - sub %rax,%rsp - mov %rsp,%rax -p3: - push %rdx - ret - -/* ---------------------------------------------- */ diff --git a/05/tcc-final-old/lib/armeabi.c b/05/tcc-final-old/lib/armeabi.c deleted file mode 100644 index a59640d..0000000 --- a/05/tcc-final-old/lib/armeabi.c +++ /dev/null @@ -1,501 +0,0 @@ -/* TCC ARM runtime EABI - Copyright (C) 2013 Thomas Preud'homme - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE.*/ - -#ifdef __TINYC__ -#define INT_MIN (-2147483647 - 1) -#define INT_MAX 2147483647 -#define UINT_MAX 0xffffffff -#define LONG_MIN (-2147483647L - 1) -#define LONG_MAX 2147483647L -#define ULONG_MAX 0xffffffffUL -#define LLONG_MAX 9223372036854775807LL -#define LLONG_MIN (-9223372036854775807LL - 1) -#define ULLONG_MAX 0xffffffffffffffffULL -#else -#include -#endif - -/* We rely on the little endianness and EABI calling convention for this to - work */ - -typedef struct double_unsigned_struct { - unsigned low; - unsigned high; -} double_unsigned_struct; - -typedef struct unsigned_int_struct { - unsigned low; - int high; -} unsigned_int_struct; - -#define REGS_RETURN(name, type) \ - void name ## _return(type ret) {} - - -/* Float helper functions */ - -#define FLOAT_EXP_BITS 8 -#define FLOAT_FRAC_BITS 23 - -#define DOUBLE_EXP_BITS 11 -#define DOUBLE_FRAC_BITS 52 - -#define ONE_EXP(type) ((1 << (type ## _EXP_BITS - 1)) - 1) - -REGS_RETURN(unsigned_int_struct, unsigned_int_struct) -REGS_RETURN(double_unsigned_struct, double_unsigned_struct) - -/* float -> integer: (sign) 1.fraction x 2^(exponent - exp_for_one) */ - - -/* float to [unsigned] long long conversion */ -#define DEFINE__AEABI_F2XLZ(name, with_sign) \ -void __aeabi_ ## name(unsigned val) \ -{ \ - int exp, high_shift, sign; \ - double_unsigned_struct ret; \ - \ - /* compute sign */ \ - sign = val >> 31; \ - \ - /* compute real exponent */ \ - exp = val >> FLOAT_FRAC_BITS; \ - exp &= (1 << FLOAT_EXP_BITS) - 1; \ - exp -= ONE_EXP(FLOAT); \ - \ - /* undefined behavior if truncated value cannot be represented */ \ - if (with_sign) { \ - if (exp > 62) /* |val| too big, double cannot represent LLONG_MAX */ \ - return; \ - } else { \ - if ((sign && exp >= 0) || exp > 63) /* if val < 0 || val too big */ \ - return; \ - } \ - \ - val &= (1 << FLOAT_FRAC_BITS) - 1; \ - if (exp >= 32) { \ - ret.high = 1 << (exp - 32); \ - if (exp - 32 >= FLOAT_FRAC_BITS) { \ - ret.high |= val << (exp - 32 - FLOAT_FRAC_BITS); \ - ret.low = 0; \ - } else { \ - high_shift = FLOAT_FRAC_BITS - (exp - 32); \ - ret.high |= val >> high_shift; \ - ret.low = val << (32 - high_shift); \ - } \ - } else { \ - ret.high = 0; \ - ret.low = 1 << exp; \ - if (exp > FLOAT_FRAC_BITS) \ - ret.low |= val << (exp - FLOAT_FRAC_BITS); \ - else \ - ret.low |= val >> (FLOAT_FRAC_BITS - exp); \ - } \ - \ - /* encode negative integer using 2's complement */ \ - if (with_sign && sign) { \ - ret.low = ~ret.low; \ - ret.high = ~ret.high; \ - if (ret.low == UINT_MAX) { \ - ret.low = 0; \ - ret.high++; \ - } else \ - ret.low++; \ - } \ - \ - double_unsigned_struct_return(ret); \ -} - -/* float to unsigned long long conversion */ -DEFINE__AEABI_F2XLZ(f2ulz, 0) - -/* float to long long conversion */ -DEFINE__AEABI_F2XLZ(f2lz, 1) - -/* double to [unsigned] long long conversion */ -#define DEFINE__AEABI_D2XLZ(name, with_sign) \ -void __aeabi_ ## name(double_unsigned_struct val) \ -{ \ - int exp, high_shift, sign; \ - double_unsigned_struct ret; \ - \ - /* compute sign */ \ - sign = val.high >> 31; \ - \ - /* compute real exponent */ \ - exp = (val.high >> (DOUBLE_FRAC_BITS - 32)); \ - exp &= (1 << DOUBLE_EXP_BITS) - 1; \ - exp -= ONE_EXP(DOUBLE); \ - \ - /* undefined behavior if truncated value cannot be represented */ \ - if (with_sign) { \ - if (exp > 62) /* |val| too big, double cannot represent LLONG_MAX */ \ - return; \ - } else { \ - if ((sign && exp >= 0) || exp > 63) /* if val < 0 || val too big */ \ - return; \ - } \ - \ - val.high &= (1 << (DOUBLE_FRAC_BITS - 32)) - 1; \ - if (exp >= 32) { \ - ret.high = 1 << (exp - 32); \ - if (exp >= DOUBLE_FRAC_BITS) { \ - high_shift = exp - DOUBLE_FRAC_BITS; \ - ret.high |= val.high << high_shift; \ - ret.high |= val.low >> (32 - high_shift); \ - ret.low = val.low << high_shift; \ - } else { \ - high_shift = DOUBLE_FRAC_BITS - exp; \ - ret.high |= val.high >> high_shift; \ - ret.low = val.high << (32 - high_shift); \ - ret.low |= val.low >> high_shift; \ - } \ - } else { \ - ret.high = 0; \ - ret.low = 1 << exp; \ - if (exp > DOUBLE_FRAC_BITS - 32) { \ - high_shift = exp - DOUBLE_FRAC_BITS - 32; \ - ret.low |= val.high << high_shift; \ - ret.low |= val.low >> (32 - high_shift); \ - } else \ - ret.low |= val.high >> (DOUBLE_FRAC_BITS - 32 - exp); \ - } \ - \ - /* encode negative integer using 2's complement */ \ - if (with_sign && sign) { \ - ret.low = ~ret.low; \ - ret.high = ~ret.high; \ - if (ret.low == UINT_MAX) { \ - ret.low = 0; \ - ret.high++; \ - } else \ - ret.low++; \ - } \ - \ - double_unsigned_struct_return(ret); \ -} - -/* double to unsigned long long conversion */ -DEFINE__AEABI_D2XLZ(d2ulz, 0) - -/* double to long long conversion */ -DEFINE__AEABI_D2XLZ(d2lz, 1) - -/* long long to float conversion */ -#define DEFINE__AEABI_XL2F(name, with_sign) \ -unsigned __aeabi_ ## name(unsigned long long v) \ -{ \ - int s /* shift */, flb /* first lost bit */, sign = 0; \ - unsigned p = 0 /* power */, ret; \ - double_unsigned_struct val; \ - \ - /* fraction in negative float is encoded in 1's complement */ \ - if (with_sign && (v & (1ULL << 63))) { \ - sign = 1; \ - v = ~v + 1; \ - } \ - val.low = v; \ - val.high = v >> 32; \ - /* fill fraction bits */ \ - for (s = 31, p = 1 << 31; p && !(val.high & p); s--, p >>= 1); \ - if (p) { \ - ret = val.high & (p - 1); \ - if (s < FLOAT_FRAC_BITS) { \ - ret <<= FLOAT_FRAC_BITS - s; \ - ret |= val.low >> (32 - (FLOAT_FRAC_BITS - s)); \ - flb = (val.low >> (32 - (FLOAT_FRAC_BITS - s - 1))) & 1; \ - } else { \ - flb = (ret >> (s - FLOAT_FRAC_BITS - 1)) & 1; \ - ret >>= s - FLOAT_FRAC_BITS; \ - } \ - s += 32; \ - } else { \ - for (s = 31, p = 1 << 31; p && !(val.low & p); s--, p >>= 1); \ - if (p) { \ - ret = val.low & (p - 1); \ - if (s <= FLOAT_FRAC_BITS) { \ - ret <<= FLOAT_FRAC_BITS - s; \ - flb = 0; \ - } else { \ - flb = (ret >> (s - FLOAT_FRAC_BITS - 1)) & 1; \ - ret >>= s - FLOAT_FRAC_BITS; \ - } \ - } else \ - return 0; \ - } \ - if (flb) \ - ret++; \ - \ - /* fill exponent bits */ \ - ret |= (s + ONE_EXP(FLOAT)) << FLOAT_FRAC_BITS; \ - \ - /* fill sign bit */ \ - ret |= sign << 31; \ - \ - return ret; \ -} - -/* unsigned long long to float conversion */ -DEFINE__AEABI_XL2F(ul2f, 0) - -/* long long to float conversion */ -DEFINE__AEABI_XL2F(l2f, 1) - -/* long long to double conversion */ -#define __AEABI_XL2D(name, with_sign) \ -void __aeabi_ ## name(unsigned long long v) \ -{ \ - int s /* shift */, high_shift, sign = 0; \ - unsigned tmp, p = 0; \ - double_unsigned_struct val, ret; \ - \ - /* fraction in negative float is encoded in 1's complement */ \ - if (with_sign && (v & (1ULL << 63))) { \ - sign = 1; \ - v = ~v + 1; \ - } \ - val.low = v; \ - val.high = v >> 32; \ - \ - /* fill fraction bits */ \ - for (s = 31, p = 1 << 31; p && !(val.high & p); s--, p >>= 1); \ - if (p) { \ - tmp = val.high & (p - 1); \ - if (s < DOUBLE_FRAC_BITS - 32) { \ - high_shift = DOUBLE_FRAC_BITS - 32 - s; \ - ret.high = tmp << high_shift; \ - ret.high |= val.low >> (32 - high_shift); \ - ret.low = val.low << high_shift; \ - } else { \ - high_shift = s - (DOUBLE_FRAC_BITS - 32); \ - ret.high = tmp >> high_shift; \ - ret.low = tmp << (32 - high_shift); \ - ret.low |= val.low >> high_shift; \ - if ((val.low >> (high_shift - 1)) & 1) { \ - if (ret.low == UINT_MAX) { \ - ret.high++; \ - ret.low = 0; \ - } else \ - ret.low++; \ - } \ - } \ - s += 32; \ - } else { \ - for (s = 31, p = 1 << 31; p && !(val.low & p); s--, p >>= 1); \ - if (p) { \ - tmp = val.low & (p - 1); \ - if (s <= DOUBLE_FRAC_BITS - 32) { \ - high_shift = DOUBLE_FRAC_BITS - 32 - s; \ - ret.high = tmp << high_shift; \ - ret.low = 0; \ - } else { \ - high_shift = s - (DOUBLE_FRAC_BITS - 32); \ - ret.high = tmp >> high_shift; \ - ret.low = tmp << (32 - high_shift); \ - } \ - } else { \ - ret.high = ret.low = 0; \ - double_unsigned_struct_return(ret); \ - } \ - } \ - \ - /* fill exponent bits */ \ - ret.high |= (s + ONE_EXP(DOUBLE)) << (DOUBLE_FRAC_BITS - 32); \ - \ - /* fill sign bit */ \ - ret.high |= sign << 31; \ - \ - double_unsigned_struct_return(ret); \ -} - -/* unsigned long long to double conversion */ -__AEABI_XL2D(ul2d, 0) - -/* long long to double conversion */ -__AEABI_XL2D(l2d, 1) - - -/* Long long helper functions */ - -/* TODO: add error in case of den == 0 (see §4.3.1 and §4.3.2) */ - -#define define_aeabi_xdivmod_signed_type(basetype, type) \ -typedef struct type { \ - basetype quot; \ - unsigned basetype rem; \ -} type - -#define define_aeabi_xdivmod_unsigned_type(basetype, type) \ -typedef struct type { \ - basetype quot; \ - basetype rem; \ -} type - -#define AEABI_UXDIVMOD(name,type, rettype, typemacro) \ -static inline rettype aeabi_ ## name (type num, type den) \ -{ \ - rettype ret; \ - type quot = 0; \ - \ - /* Increase quotient while it is less than numerator */ \ - while (num >= den) { \ - type q = 1; \ - \ - /* Find closest power of two */ \ - while ((q << 1) * den <= num && q * den <= typemacro ## _MAX / 2) \ - q <<= 1; \ - \ - /* Compute difference between current quotient and numerator */ \ - num -= q * den; \ - quot += q; \ - } \ - ret.quot = quot; \ - ret.rem = num; \ - return ret; \ -} - -#define __AEABI_XDIVMOD(name, type, uiname, rettype, urettype, typemacro) \ -void __aeabi_ ## name(type numerator, type denominator) \ -{ \ - unsigned type num, den; \ - urettype uxdiv_ret; \ - rettype ret; \ - \ - if (numerator >= 0) \ - num = numerator; \ - else \ - num = 0 - numerator; \ - if (denominator >= 0) \ - den = denominator; \ - else \ - den = 0 - denominator; \ - uxdiv_ret = aeabi_ ## uiname(num, den); \ - /* signs differ */ \ - if ((numerator & typemacro ## _MIN) != (denominator & typemacro ## _MIN)) \ - ret.quot = 0 - uxdiv_ret.quot; \ - else \ - ret.quot = uxdiv_ret.quot; \ - if (numerator < 0) \ - ret.rem = 0 - uxdiv_ret.rem; \ - else \ - ret.rem = uxdiv_ret.rem; \ - \ - rettype ## _return(ret); \ -} - -define_aeabi_xdivmod_signed_type(long long, lldiv_t); -define_aeabi_xdivmod_unsigned_type(unsigned long long, ulldiv_t); -define_aeabi_xdivmod_signed_type(int, idiv_t); -define_aeabi_xdivmod_unsigned_type(unsigned, uidiv_t); - -REGS_RETURN(lldiv_t, lldiv_t) -REGS_RETURN(ulldiv_t, ulldiv_t) -REGS_RETURN(idiv_t, idiv_t) -REGS_RETURN(uidiv_t, uidiv_t) - -AEABI_UXDIVMOD(uldivmod, unsigned long long, ulldiv_t, ULLONG) - -__AEABI_XDIVMOD(ldivmod, long long, uldivmod, lldiv_t, ulldiv_t, LLONG) - -void __aeabi_uldivmod(unsigned long long num, unsigned long long den) -{ - ulldiv_t_return(aeabi_uldivmod(num, den)); -} - -void __aeabi_llsl(double_unsigned_struct val, int shift) -{ - double_unsigned_struct ret; - - if (shift >= 32) { - val.high = val.low; - val.low = 0; - shift -= 32; - } - if (shift > 0) { - ret.low = val.low << shift; - ret.high = (val.high << shift) | (val.low >> (32 - shift)); - double_unsigned_struct_return(ret); - return; - } - double_unsigned_struct_return(val); -} - -#define aeabi_lsr(val, shift, fill, type) \ - type ## _struct ret; \ - \ - if (shift >= 32) { \ - val.low = val.high; \ - val.high = fill; \ - shift -= 32; \ - } \ - if (shift > 0) { \ - ret.high = val.high >> shift; \ - ret.low = (val.high << (32 - shift)) | (val.low >> shift); \ - type ## _struct_return(ret); \ - return; \ - } \ - type ## _struct_return(val); - -void __aeabi_llsr(double_unsigned_struct val, int shift) -{ - aeabi_lsr(val, shift, 0, double_unsigned); -} - -void __aeabi_lasr(unsigned_int_struct val, int shift) -{ - aeabi_lsr(val, shift, val.high >> 31, unsigned_int); -} - - -/* Integer division functions */ - -AEABI_UXDIVMOD(uidivmod, unsigned, uidiv_t, UINT) - -int __aeabi_idiv(int numerator, int denominator) -{ - unsigned num, den; - uidiv_t ret; - - if (numerator >= 0) - num = numerator; - else - num = 0 - numerator; - if (denominator >= 0) - den = denominator; - else - den = 0 - denominator; - ret = aeabi_uidivmod(num, den); - if ((numerator & INT_MIN) != (denominator & INT_MIN)) /* signs differ */ - ret.quot *= -1; - return ret.quot; -} - -unsigned __aeabi_uidiv(unsigned num, unsigned den) -{ - return aeabi_uidivmod(num, den).quot; -} - -__AEABI_XDIVMOD(idivmod, int, uidivmod, idiv_t, uidiv_t, INT) - -void __aeabi_uidivmod(unsigned num, unsigned den) -{ - uidiv_t_return(aeabi_uidivmod(num, den)); -} diff --git a/05/tcc-final-old/lib/armflush.c b/05/tcc-final-old/lib/armflush.c deleted file mode 100644 index eae3260..0000000 --- a/05/tcc-final-old/lib/armflush.c +++ /dev/null @@ -1,58 +0,0 @@ -/* armflush.c - flush the instruction cache - - __clear_cache is used in tccrun.c, It is a built-in - intrinsic with gcc. However tcc in order to compile - itself needs this function */ - -#ifdef __TINYC__ - -/* syscall wrapper */ -unsigned syscall(unsigned syscall_nr, ...); - -/* arm-tcc supports only fake asm currently */ -__asm__( - ".global syscall\n" - "syscall:\n" - ".int 0xe92d4080\n" // push {r7, lr} - ".int 0xe1a07000\n" // mov r7, r0 - ".int 0xe1a00001\n" // mov r0, r1 - ".int 0xe1a01002\n" // mov r1, r2 - ".int 0xe1a02003\n" // mov r2, r3 - ".int 0xef000000\n" // svc 0x00000000 - ".int 0xe8bd8080\n" // pop {r7, pc} - ); - -/* from unistd.h: */ -#if defined(__thumb__) || defined(__ARM_EABI__) -# define __NR_SYSCALL_BASE 0x0 -#else -# define __NR_SYSCALL_BASE 0x900000 -#endif -#define __ARM_NR_BASE (__NR_SYSCALL_BASE+0x0f0000) -#define __ARM_NR_cacheflush (__ARM_NR_BASE+2) - -#else - -#define _GNU_SOURCE -#include -#include -#include - -#endif - -/* Flushing for tccrun */ -void __clear_cache(void *beginning, void *end) -{ -/* __ARM_NR_cacheflush is kernel private and should not be used in user space. - * However, there is no ARM asm parser in tcc so we use it for now */ -#if 1 - syscall(__ARM_NR_cacheflush, beginning, end, 0); -#else - __asm__ ("push {r7}\n\t" - "mov r7, #0xf0002\n\t" - "mov r2, #0\n\t" - "swi 0\n\t" - "pop {r7}\n\t" - "ret"); -#endif -} diff --git a/05/tcc-final-old/lib/bcheck.c b/05/tcc-final-old/lib/bcheck.c deleted file mode 100644 index 90f0ad2..0000000 --- a/05/tcc-final-old/lib/bcheck.c +++ /dev/null @@ -1,979 +0,0 @@ -/* - * Tiny C Memory and bounds checker - * - * Copyright (c) 2002 Fabrice Bellard - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#include -#include -#include -#include - -#if !defined(__FreeBSD__) \ - && !defined(__FreeBSD_kernel__) \ - && !defined(__DragonFly__) \ - && !defined(__OpenBSD__) \ - && !defined(__NetBSD__) -#include -#endif - -#if !defined(_WIN32) -#include -#endif - -/* #define BOUND_DEBUG */ - -#ifdef BOUND_DEBUG - #define dprintf(a...) fprintf(a) -#else - #define dprintf(a...) -#endif - -/* define so that bound array is static (faster, but use memory if - bound checking not used) */ -/* #define BOUND_STATIC */ - -/* use malloc hooks. Currently the code cannot be reliable if no hooks */ -#define CONFIG_TCC_MALLOC_HOOKS -#define HAVE_MEMALIGN - -#if defined(__FreeBSD__) \ - || defined(__FreeBSD_kernel__) \ - || defined(__DragonFly__) \ - || defined(__OpenBSD__) \ - || defined(__NetBSD__) \ - || defined(__dietlibc__) \ - || defined(_WIN32) -//#warning Bound checking does not support malloc (etc.) in this environment. -#undef CONFIG_TCC_MALLOC_HOOKS -#undef HAVE_MEMALIGN -#endif - -#define BOUND_T1_BITS 13 -#define BOUND_T2_BITS 11 -#define BOUND_T3_BITS (sizeof(size_t)*8 - BOUND_T1_BITS - BOUND_T2_BITS) -#define BOUND_E_BITS (sizeof(size_t)) - -#define BOUND_T1_SIZE ((size_t)1 << BOUND_T1_BITS) -#define BOUND_T2_SIZE ((size_t)1 << BOUND_T2_BITS) -#define BOUND_T3_SIZE ((size_t)1 << BOUND_T3_BITS) - -#define BOUND_T23_BITS (BOUND_T2_BITS + BOUND_T3_BITS) -#define BOUND_T23_SIZE ((size_t)1 << BOUND_T23_BITS) - - -/* this pointer is generated when bound check is incorrect */ -#define INVALID_POINTER ((void *)(-2)) -/* size of an empty region */ -#define EMPTY_SIZE ((size_t)(-1)) -/* size of an invalid region */ -#define INVALID_SIZE 0 - -typedef struct BoundEntry { - size_t start; - size_t size; - struct BoundEntry *next; - size_t is_invalid; /* true if pointers outside region are invalid */ -} BoundEntry; - -/* external interface */ -void __bound_init(void); -void __bound_new_region(void *p, size_t size); -int __bound_delete_region(void *p); - -#ifdef __attribute__ - /* an __attribute__ macro is defined in the system headers */ - #undef __attribute__ -#endif -#define FASTCALL __attribute__((regparm(3))) - -void *__bound_malloc(size_t size, const void *caller); -void *__bound_memalign(size_t size, size_t align, const void *caller); -void __bound_free(void *ptr, const void *caller); -void *__bound_realloc(void *ptr, size_t size, const void *caller); -static void *libc_malloc(size_t size); -static void libc_free(void *ptr); -static void install_malloc_hooks(void); -static void restore_malloc_hooks(void); - -#ifdef CONFIG_TCC_MALLOC_HOOKS -static void *saved_malloc_hook; -static void *saved_free_hook; -static void *saved_realloc_hook; -static void *saved_memalign_hook; -#endif - -/* TCC definitions */ -extern char __bounds_start; /* start of static bounds table */ -/* error message, just for TCC */ -const char *__bound_error_msg; - -/* runtime error output */ -extern void rt_error(size_t pc, const char *fmt, ...); - -#ifdef BOUND_STATIC -static BoundEntry *__bound_t1[BOUND_T1_SIZE]; /* page table */ -#else -static BoundEntry **__bound_t1; /* page table */ -#endif -static BoundEntry *__bound_empty_t2; /* empty page, for unused pages */ -static BoundEntry *__bound_invalid_t2; /* invalid page, for invalid pointers */ - -static BoundEntry *__bound_find_region(BoundEntry *e1, void *p) -{ - size_t addr, tmp; - BoundEntry *e; - - e = e1; - while (e != NULL) { - addr = (size_t)p; - addr -= e->start; - if (addr <= e->size) { - /* put region at the head */ - tmp = e1->start; - e1->start = e->start; - e->start = tmp; - tmp = e1->size; - e1->size = e->size; - e->size = tmp; - return e1; - } - e = e->next; - } - /* no entry found: return empty entry or invalid entry */ - if (e1->is_invalid) - return __bound_invalid_t2; - else - return __bound_empty_t2; -} - -/* print a bound error message */ -static void bound_error(const char *fmt, ...) -{ - __bound_error_msg = fmt; - fprintf(stderr,"%s %s: %s\n", __FILE__, __FUNCTION__, fmt); - *(void **)0 = 0; /* force a runtime error */ -} - -static void bound_alloc_error(void) -{ - bound_error("not enough memory for bound checking code"); -} - -/* return '(p + offset)' for pointer arithmetic (a pointer can reach - the end of a region in this case */ -void * FASTCALL __bound_ptr_add(void *p, size_t offset) -{ - size_t addr = (size_t)p; - BoundEntry *e; - - dprintf(stderr, "%s %s: %p %x\n", - __FILE__, __FUNCTION__, p, (unsigned)offset); - - __bound_init(); - - e = __bound_t1[addr >> (BOUND_T2_BITS + BOUND_T3_BITS)]; - e = (BoundEntry *)((char *)e + - ((addr >> (BOUND_T3_BITS - BOUND_E_BITS)) & - ((BOUND_T2_SIZE - 1) << BOUND_E_BITS))); - addr -= e->start; - if (addr > e->size) { - e = __bound_find_region(e, p); - addr = (size_t)p - e->start; - } - addr += offset; - if (addr >= e->size) { - fprintf(stderr,"%s %s: %p is outside of the region\n", - __FILE__, __FUNCTION__, p + offset); - return INVALID_POINTER; /* return an invalid pointer */ - } - return p + offset; -} - -/* return '(p + offset)' for pointer indirection (the resulting must - be strictly inside the region */ -#define BOUND_PTR_INDIR(dsize) \ -void * FASTCALL __bound_ptr_indir ## dsize (void *p, size_t offset) \ -{ \ - size_t addr = (size_t)p; \ - BoundEntry *e; \ - \ - dprintf(stderr, "%s %s: %p %x start\n", \ - __FILE__, __FUNCTION__, p, (unsigned)offset); \ - \ - __bound_init(); \ - e = __bound_t1[addr >> (BOUND_T2_BITS + BOUND_T3_BITS)]; \ - e = (BoundEntry *)((char *)e + \ - ((addr >> (BOUND_T3_BITS - BOUND_E_BITS)) & \ - ((BOUND_T2_SIZE - 1) << BOUND_E_BITS))); \ - addr -= e->start; \ - if (addr > e->size) { \ - e = __bound_find_region(e, p); \ - addr = (size_t)p - e->start; \ - } \ - addr += offset + dsize; \ - if (addr > e->size) { \ - fprintf(stderr,"%s %s: %p is outside of the region\n", \ - __FILE__, __FUNCTION__, p + offset); \ - return INVALID_POINTER; /* return an invalid pointer */ \ - } \ - dprintf(stderr, "%s %s: return p+offset = %p\n", \ - __FILE__, __FUNCTION__, p + offset); \ - return p + offset; \ -} - -BOUND_PTR_INDIR(1) -BOUND_PTR_INDIR(2) -BOUND_PTR_INDIR(4) -BOUND_PTR_INDIR(8) -BOUND_PTR_INDIR(12) -BOUND_PTR_INDIR(16) - -#if defined(__GNUC__) && (__GNUC__ >= 6) -/* - * At least gcc 6.2 complains when __builtin_frame_address is used with - * nonzero argument. - */ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wframe-address" -#endif - -/* return the frame pointer of the caller */ -#define GET_CALLER_FP(fp)\ -{\ - fp = (size_t)__builtin_frame_address(1);\ -} - -/* called when entering a function to add all the local regions */ -void FASTCALL __bound_local_new(void *p1) -{ - size_t addr, size, fp, *p = p1; - - dprintf(stderr, "%s, %s start p1=%p\n", __FILE__, __FUNCTION__, p); - GET_CALLER_FP(fp); - for(;;) { - addr = p[0]; - if (addr == 0) - break; - addr += fp; - size = p[1]; - p += 2; - __bound_new_region((void *)addr, size); - } - dprintf(stderr, "%s, %s end\n", __FILE__, __FUNCTION__); -} - -/* called when leaving a function to delete all the local regions */ -void FASTCALL __bound_local_delete(void *p1) -{ - size_t addr, fp, *p = p1; - GET_CALLER_FP(fp); - for(;;) { - addr = p[0]; - if (addr == 0) - break; - addr += fp; - p += 2; - __bound_delete_region((void *)addr); - } -} - -#if defined(__GNUC__) && (__GNUC__ >= 6) -#pragma GCC diagnostic pop -#endif - -static BoundEntry *__bound_new_page(void) -{ - BoundEntry *page; - size_t i; - - page = libc_malloc(sizeof(BoundEntry) * BOUND_T2_SIZE); - if (!page) - bound_alloc_error(); - for(i=0;i> BOUND_T3_BITS; - if (end != 0) - t2_end = end >> BOUND_T3_BITS; - else - t2_end = 1 << (BOUND_T1_BITS + BOUND_T2_BITS); - -#if 0 - dprintf(stderr, "mark_invalid: start = %x %x\n", t2_start, t2_end); -#endif - - /* first we handle full pages */ - t1_start = (t2_start + BOUND_T2_SIZE - 1) >> BOUND_T2_BITS; - t1_end = t2_end >> BOUND_T2_BITS; - - i = t2_start & (BOUND_T2_SIZE - 1); - j = t2_end & (BOUND_T2_SIZE - 1); - - if (t1_start == t1_end) { - page = get_page(t2_start >> BOUND_T2_BITS); - for(; i < j; i++) { - page[i].size = INVALID_SIZE; - page[i].is_invalid = 1; - } - } else { - if (i > 0) { - page = get_page(t2_start >> BOUND_T2_BITS); - for(; i < BOUND_T2_SIZE; i++) { - page[i].size = INVALID_SIZE; - page[i].is_invalid = 1; - } - } - for(i = t1_start; i < t1_end; i++) { - __bound_t1[i] = __bound_invalid_t2; - } - if (j != 0) { - page = get_page(t1_end); - for(i = 0; i < j; i++) { - page[i].size = INVALID_SIZE; - page[i].is_invalid = 1; - } - } - } -} - -void __bound_init(void) -{ - size_t i; - BoundEntry *page; - size_t start, size; - size_t *p; - - static int inited; - if (inited) - return; - - inited = 1; - - dprintf(stderr, "%s, %s() start\n", __FILE__, __FUNCTION__); - - /* save malloc hooks and install bound check hooks */ - install_malloc_hooks(); - -#ifndef BOUND_STATIC - __bound_t1 = libc_malloc(BOUND_T1_SIZE * sizeof(BoundEntry *)); - if (!__bound_t1) - bound_alloc_error(); -#endif - __bound_empty_t2 = __bound_new_page(); - for(i=0;i= v3.3, the alternative is to read - * start_brk from /proc/self/stat - */ - start = (size_t)sbrk(0); - size = 128 * 0x100000; - mark_invalid(start, size); -#endif - - /* add all static bound check values */ - p = (size_t *)&__bounds_start; - while (p[0] != 0) { - __bound_new_region((void *)p[0], p[1]); - p += 2; - } - - dprintf(stderr, "%s, %s() end\n\n", __FILE__, __FUNCTION__); -} - -void __bound_main_arg(void **p) -{ - void *start = p; - while (*p++); - - dprintf(stderr, "%s, %s calling __bound_new_region(%p %x)\n", - __FILE__, __FUNCTION__, start, (unsigned)((void *)p - start)); - - __bound_new_region(start, (void *) p - start); -} - -void __bound_exit(void) -{ - dprintf(stderr, "%s, %s()\n", __FILE__, __FUNCTION__); - restore_malloc_hooks(); -} - -static inline void add_region(BoundEntry *e, - size_t start, size_t size) -{ - BoundEntry *e1; - if (e->start == 0) { - /* no region : add it */ - e->start = start; - e->size = size; - } else { - /* already regions in the list: add it at the head */ - e1 = bound_new_entry(); - e1->start = e->start; - e1->size = e->size; - e1->next = e->next; - e->start = start; - e->size = size; - e->next = e1; - } -} - -/* create a new region. It should not already exist in the region list */ -void __bound_new_region(void *p, size_t size) -{ - size_t start, end; - BoundEntry *page, *e, *e2; - size_t t1_start, t1_end, i, t2_start, t2_end; - - dprintf(stderr, "%s, %s(%p, %x) start\n", - __FILE__, __FUNCTION__, p, (unsigned)size); - - __bound_init(); - - start = (size_t)p; - end = start + size; - t1_start = start >> (BOUND_T2_BITS + BOUND_T3_BITS); - t1_end = end >> (BOUND_T2_BITS + BOUND_T3_BITS); - - /* start */ - page = get_page(t1_start); - t2_start = (start >> (BOUND_T3_BITS - BOUND_E_BITS)) & - ((BOUND_T2_SIZE - 1) << BOUND_E_BITS); - t2_end = (end >> (BOUND_T3_BITS - BOUND_E_BITS)) & - ((BOUND_T2_SIZE - 1) << BOUND_E_BITS); - - - e = (BoundEntry *)((char *)page + t2_start); - add_region(e, start, size); - - if (t1_end == t1_start) { - /* same ending page */ - e2 = (BoundEntry *)((char *)page + t2_end); - if (e2 > e) { - e++; - for(;estart = start; - e->size = size; - } - add_region(e, start, size); - } - } else { - /* mark until end of page */ - e2 = page + BOUND_T2_SIZE; - e++; - for(;estart = start; - e->size = size; - } - /* mark intermediate pages, if any */ - for(i=t1_start+1;istart = start; - e->size = size; - } - } - /* last page */ - page = get_page(t1_end); - e2 = (BoundEntry *)((char *)page + t2_end); - for(e=page;estart = start; - e->size = size; - } - add_region(e, start, size); - } - - dprintf(stderr, "%s, %s end\n", __FILE__, __FUNCTION__); -} - -/* delete a region */ -static inline void delete_region(BoundEntry *e, void *p, size_t empty_size) -{ - size_t addr; - BoundEntry *e1; - - addr = (size_t)p; - addr -= e->start; - if (addr <= e->size) { - /* region found is first one */ - e1 = e->next; - if (e1 == NULL) { - /* no more region: mark it empty */ - e->start = 0; - e->size = empty_size; - } else { - /* copy next region in head */ - e->start = e1->start; - e->size = e1->size; - e->next = e1->next; - bound_free_entry(e1); - } - } else { - /* find the matching region */ - for(;;) { - e1 = e; - e = e->next; - /* region not found: do nothing */ - if (e == NULL) - break; - addr = (size_t)p - e->start; - if (addr <= e->size) { - /* found: remove entry */ - e1->next = e->next; - bound_free_entry(e); - break; - } - } - } -} - -/* WARNING: 'p' must be the starting point of the region. */ -/* return non zero if error */ -int __bound_delete_region(void *p) -{ - size_t start, end, addr, size, empty_size; - BoundEntry *page, *e, *e2; - size_t t1_start, t1_end, t2_start, t2_end, i; - - dprintf(stderr, "%s %s() start\n", __FILE__, __FUNCTION__); - - __bound_init(); - - start = (size_t)p; - t1_start = start >> (BOUND_T2_BITS + BOUND_T3_BITS); - t2_start = (start >> (BOUND_T3_BITS - BOUND_E_BITS)) & - ((BOUND_T2_SIZE - 1) << BOUND_E_BITS); - - /* find region size */ - page = __bound_t1[t1_start]; - e = (BoundEntry *)((char *)page + t2_start); - addr = start - e->start; - if (addr > e->size) - e = __bound_find_region(e, p); - /* test if invalid region */ - if (e->size == EMPTY_SIZE || (size_t)p != e->start) - return -1; - /* compute the size we put in invalid regions */ - if (e->is_invalid) - empty_size = INVALID_SIZE; - else - empty_size = EMPTY_SIZE; - size = e->size; - end = start + size; - - /* now we can free each entry */ - t1_end = end >> (BOUND_T2_BITS + BOUND_T3_BITS); - t2_end = (end >> (BOUND_T3_BITS - BOUND_E_BITS)) & - ((BOUND_T2_SIZE - 1) << BOUND_E_BITS); - - delete_region(e, p, empty_size); - if (t1_end == t1_start) { - /* same ending page */ - e2 = (BoundEntry *)((char *)page + t2_end); - if (e2 > e) { - e++; - for(;estart = 0; - e->size = empty_size; - } - delete_region(e, p, empty_size); - } - } else { - /* mark until end of page */ - e2 = page + BOUND_T2_SIZE; - e++; - for(;estart = 0; - e->size = empty_size; - } - /* mark intermediate pages, if any */ - /* XXX: should free them */ - for(i=t1_start+1;istart = 0; - e->size = empty_size; - } - } - /* last page */ - page = get_page(t1_end); - e2 = (BoundEntry *)((char *)page + t2_end); - for(e=page;estart = 0; - e->size = empty_size; - } - delete_region(e, p, empty_size); - } - - dprintf(stderr, "%s %s() end\n", __FILE__, __FUNCTION__); - - return 0; -} - -/* return the size of the region starting at p, or EMPTY_SIZE if non - existent region. */ -static size_t get_region_size(void *p) -{ - size_t addr = (size_t)p; - BoundEntry *e; - - e = __bound_t1[addr >> (BOUND_T2_BITS + BOUND_T3_BITS)]; - e = (BoundEntry *)((char *)e + - ((addr >> (BOUND_T3_BITS - BOUND_E_BITS)) & - ((BOUND_T2_SIZE - 1) << BOUND_E_BITS))); - addr -= e->start; - if (addr > e->size) - e = __bound_find_region(e, p); - if (e->start != (size_t)p) - return EMPTY_SIZE; - return e->size; -} - -/* patched memory functions */ - -/* force compiler to perform stores coded up to this point */ -#define barrier() __asm__ __volatile__ ("": : : "memory") - -static void install_malloc_hooks(void) -{ -#ifdef CONFIG_TCC_MALLOC_HOOKS - saved_malloc_hook = __malloc_hook; - saved_free_hook = __free_hook; - saved_realloc_hook = __realloc_hook; - saved_memalign_hook = __memalign_hook; - __malloc_hook = __bound_malloc; - __free_hook = __bound_free; - __realloc_hook = __bound_realloc; - __memalign_hook = __bound_memalign; - - barrier(); -#endif -} - -static void restore_malloc_hooks(void) -{ -#ifdef CONFIG_TCC_MALLOC_HOOKS - __malloc_hook = saved_malloc_hook; - __free_hook = saved_free_hook; - __realloc_hook = saved_realloc_hook; - __memalign_hook = saved_memalign_hook; - - barrier(); -#endif -} - -static void *libc_malloc(size_t size) -{ - void *ptr; - restore_malloc_hooks(); - ptr = malloc(size); - install_malloc_hooks(); - return ptr; -} - -static void libc_free(void *ptr) -{ - restore_malloc_hooks(); - free(ptr); - install_malloc_hooks(); -} - -/* XXX: we should use a malloc which ensure that it is unlikely that - two malloc'ed data have the same address if 'free' are made in - between. */ -void *__bound_malloc(size_t size, const void *caller) -{ - void *ptr; - - /* we allocate one more byte to ensure the regions will be - separated by at least one byte. With the glibc malloc, it may - be in fact not necessary */ - ptr = libc_malloc(size + 1); - - if (!ptr) - return NULL; - - dprintf(stderr, "%s, %s calling __bound_new_region(%p, %x)\n", - __FILE__, __FUNCTION__, ptr, (unsigned)size); - - __bound_new_region(ptr, size); - return ptr; -} - -void *__bound_memalign(size_t size, size_t align, const void *caller) -{ - void *ptr; - - restore_malloc_hooks(); - -#ifndef HAVE_MEMALIGN - if (align > 4) { - /* XXX: handle it ? */ - ptr = NULL; - } else { - /* we suppose that malloc aligns to at least four bytes */ - ptr = malloc(size + 1); - } -#else - /* we allocate one more byte to ensure the regions will be - separated by at least one byte. With the glibc malloc, it may - be in fact not necessary */ - ptr = memalign(size + 1, align); -#endif - - install_malloc_hooks(); - - if (!ptr) - return NULL; - - dprintf(stderr, "%s, %s calling __bound_new_region(%p, %x)\n", - __FILE__, __FUNCTION__, ptr, (unsigned)size); - - __bound_new_region(ptr, size); - return ptr; -} - -void __bound_free(void *ptr, const void *caller) -{ - if (ptr == NULL) - return; - if (__bound_delete_region(ptr) != 0) - bound_error("freeing invalid region"); - - libc_free(ptr); -} - -void *__bound_realloc(void *ptr, size_t size, const void *caller) -{ - void *ptr1; - size_t old_size; - - if (size == 0) { - __bound_free(ptr, caller); - return NULL; - } else { - ptr1 = __bound_malloc(size, caller); - if (ptr == NULL || ptr1 == NULL) - return ptr1; - old_size = get_region_size(ptr); - if (old_size == EMPTY_SIZE) - bound_error("realloc'ing invalid pointer"); - memcpy(ptr1, ptr, old_size); - __bound_free(ptr, caller); - return ptr1; - } -} - -#ifndef CONFIG_TCC_MALLOC_HOOKS -void *__bound_calloc(size_t nmemb, size_t size) -{ - void *ptr; - size = size * nmemb; - ptr = __bound_malloc(size, NULL); - if (!ptr) - return NULL; - memset(ptr, 0, size); - return ptr; -} -#endif - -#if 0 -static void bound_dump(void) -{ - BoundEntry *page, *e; - size_t i, j; - - fprintf(stderr, "region dump:\n"); - for(i=0;isize != EMPTY_SIZE && e->start != 0) { - fprintf(stderr, "%08x:", - (i << (BOUND_T2_BITS + BOUND_T3_BITS)) + - (j << BOUND_T3_BITS)); - do { - fprintf(stderr, " %08lx:%08lx", e->start, e->start + e->size); - e = e->next; - } while (e != NULL); - fprintf(stderr, "\n"); - } - } - } -} -#endif - -/* some useful checked functions */ - -/* check that (p ... p + size - 1) lies inside 'p' region, if any */ -static void __bound_check(const void *p, size_t size) -{ - if (size == 0) - return; - p = __bound_ptr_add((void *)p, size - 1); - if (p == INVALID_POINTER) - bound_error("invalid pointer"); -} - -void *__bound_memcpy(void *dst, const void *src, size_t size) -{ - void* p; - - dprintf(stderr, "%s %s: start, dst=%p src=%p size=%x\n", - __FILE__, __FUNCTION__, dst, src, (unsigned)size); - - __bound_check(dst, size); - __bound_check(src, size); - /* check also region overlap */ - if (src >= dst && src < dst + size) - bound_error("overlapping regions in memcpy()"); - - p = memcpy(dst, src, size); - - dprintf(stderr, "%s %s: end, p=%p\n", __FILE__, __FUNCTION__, p); - return p; -} - -void *__bound_memmove(void *dst, const void *src, size_t size) -{ - __bound_check(dst, size); - __bound_check(src, size); - return memmove(dst, src, size); -} - -void *__bound_memset(void *dst, int c, size_t size) -{ - __bound_check(dst, size); - return memset(dst, c, size); -} - -/* XXX: could be optimized */ -int __bound_strlen(const char *s) -{ - const char *p; - size_t len; - - len = 0; - for(;;) { - p = __bound_ptr_indir1((char *)s, len); - if (p == INVALID_POINTER) - bound_error("bad pointer in strlen()"); - if (*p == '\0') - break; - len++; - } - return len; -} - -char *__bound_strcpy(char *dst, const char *src) -{ - size_t len; - void *p; - - dprintf(stderr, "%s %s: strcpy start, dst=%p src=%p\n", - __FILE__, __FUNCTION__, dst, src); - len = __bound_strlen(src); - p = __bound_memcpy(dst, src, len + 1); - dprintf(stderr, "%s %s: strcpy end, p = %p\n", - __FILE__, __FUNCTION__, p); - return p; -} diff --git a/05/tcc-final-old/lib/lib-arm64.c b/05/tcc-final-old/lib/lib-arm64.c deleted file mode 100644 index b8fd9e8..0000000 --- a/05/tcc-final-old/lib/lib-arm64.c +++ /dev/null @@ -1,664 +0,0 @@ -/* - * TCC runtime library for arm64. - * - * Copyright (c) 2015 Edmund Grimley Evans - * - * Copying and distribution of this file, with or without modification, - * are permitted in any medium without royalty provided the copyright - * notice and this notice are preserved. This file is offered as-is, - * without any warranty. - */ - -#ifdef __TINYC__ -typedef signed char int8_t; -typedef unsigned char uint8_t; -typedef short int16_t; -typedef unsigned short uint16_t; -typedef int int32_t; -typedef unsigned uint32_t; -typedef long long int64_t; -typedef unsigned long long uint64_t; -void *memcpy(void*,void*,__SIZE_TYPE__); -#else -#include -#include -#endif - -void __clear_cache(void *beg, void *end) -{ - __arm64_clear_cache(beg, end); -} - -typedef struct { - uint64_t x0, x1; -} u128_t; - -static long double f3_zero(int sgn) -{ - long double f; - u128_t x = { 0, (uint64_t)sgn << 63 }; - memcpy(&f, &x, 16); - return f; -} - -static long double f3_infinity(int sgn) -{ - long double f; - u128_t x = { 0, (uint64_t)sgn << 63 | 0x7fff000000000000 }; - memcpy(&f, &x, 16); - return f; -} - -static long double f3_NaN(void) -{ - long double f; -#if 0 - // ARM's default NaN usually has just the top fraction bit set: - u128_t x = { 0, 0x7fff800000000000 }; -#else - // GCC's library sets all fraction bits: - u128_t x = { -1, 0x7fffffffffffffff }; -#endif - memcpy(&f, &x, 16); - return f; -} - -static int fp3_convert_NaN(long double *f, int sgn, u128_t mnt) -{ - u128_t x = { mnt.x0, - mnt.x1 | 0x7fff800000000000 | (uint64_t)sgn << 63 }; - memcpy(f, &x, 16); - return 1; -} - -static int fp3_detect_NaNs(long double *f, - int a_sgn, int a_exp, u128_t a, - int b_sgn, int b_exp, u128_t b) -{ - // Detect signalling NaNs: - if (a_exp == 32767 && (a.x0 | a.x1 << 16) && !(a.x1 >> 47 & 1)) - return fp3_convert_NaN(f, a_sgn, a); - if (b_exp == 32767 && (b.x0 | b.x1 << 16) && !(b.x1 >> 47 & 1)) - return fp3_convert_NaN(f, b_sgn, b); - - // Detect quiet NaNs: - if (a_exp == 32767 && (a.x0 | a.x1 << 16)) - return fp3_convert_NaN(f, a_sgn, a); - if (b_exp == 32767 && (b.x0 | b.x1 << 16)) - return fp3_convert_NaN(f, b_sgn, b); - - return 0; -} - -static void f3_unpack(int *sgn, int32_t *exp, u128_t *mnt, long double f) -{ - u128_t x; - memcpy(&x, &f, 16); - *sgn = x.x1 >> 63; - *exp = x.x1 >> 48 & 32767; - x.x1 = x.x1 << 16 >> 16; - if (*exp) - x.x1 |= (uint64_t)1 << 48; - else - *exp = 1; - *mnt = x; -} - -static u128_t f3_normalise(int32_t *exp, u128_t mnt) -{ - int sh; - if (!(mnt.x0 | mnt.x1)) - return mnt; - if (!mnt.x1) { - mnt.x1 = mnt.x0; - mnt.x0 = 0; - *exp -= 64; - } - for (sh = 32; sh; sh >>= 1) { - if (!(mnt.x1 >> (64 - sh))) { - mnt.x1 = mnt.x1 << sh | mnt.x0 >> (64 - sh); - mnt.x0 = mnt.x0 << sh; - *exp -= sh; - } - } - return mnt; -} - -static u128_t f3_sticky_shift(int32_t sh, u128_t x) -{ - if (sh >= 128) { - x.x0 = !!(x.x0 | x.x1); - x.x1 = 0; - return x; - } - if (sh >= 64) { - x.x0 = x.x1 | !!x.x0; - x.x1 = 0; - sh -= 64; - } - if (sh > 0) { - x.x0 = x.x0 >> sh | x.x1 << (64 - sh) | !!(x.x0 << (64 - sh)); - x.x1 = x.x1 >> sh; - } - return x; -} - -static long double f3_round(int sgn, int32_t exp, u128_t x) -{ - long double f; - int error; - - if (exp > 0) { - x = f3_sticky_shift(13, x); - } - else { - x = f3_sticky_shift(14 - exp, x); - exp = 0; - } - - error = x.x0 & 3; - x.x0 = x.x0 >> 2 | x.x1 << 62; - x.x1 = x.x1 >> 2; - - if (error == 3 || ((error == 2) & (x.x0 & 1))) { - if (!++x.x0) { - ++x.x1; - if (x.x1 == (uint64_t)1 << 48) - exp = 1; - else if (x.x1 == (uint64_t)1 << 49) { - ++exp; - x.x0 = x.x0 >> 1 | x.x1 << 63; - x.x1 = x.x1 >> 1; - } - } - } - - if (exp >= 32767) - return f3_infinity(sgn); - - x.x1 = x.x1 << 16 >> 16 | (uint64_t)exp << 48 | (uint64_t)sgn << 63; - memcpy(&f, &x, 16); - return f; -} - -static long double f3_add(long double fa, long double fb, int neg) -{ - u128_t a, b, x; - int32_t a_exp, b_exp, x_exp; - int a_sgn, b_sgn, x_sgn; - long double fx; - - f3_unpack(&a_sgn, &a_exp, &a, fa); - f3_unpack(&b_sgn, &b_exp, &b, fb); - - if (fp3_detect_NaNs(&fx, a_sgn, a_exp, a, b_sgn, b_exp, b)) - return fx; - - b_sgn ^= neg; - - // Handle infinities and zeroes: - if (a_exp == 32767 && b_exp == 32767 && a_sgn != b_sgn) - return f3_NaN(); - if (a_exp == 32767) - return f3_infinity(a_sgn); - if (b_exp == 32767) - return f3_infinity(b_sgn); - if (!(a.x0 | a.x1 | b.x0 | b.x1)) - return f3_zero(a_sgn & b_sgn); - - a.x1 = a.x1 << 3 | a.x0 >> 61; - a.x0 = a.x0 << 3; - b.x1 = b.x1 << 3 | b.x0 >> 61; - b.x0 = b.x0 << 3; - - if (a_exp <= b_exp) { - a = f3_sticky_shift(b_exp - a_exp, a); - a_exp = b_exp; - } - else { - b = f3_sticky_shift(a_exp - b_exp, b); - b_exp = a_exp; - } - - x_sgn = a_sgn; - x_exp = a_exp; - if (a_sgn == b_sgn) { - x.x0 = a.x0 + b.x0; - x.x1 = a.x1 + b.x1 + (x.x0 < a.x0); - } - else { - x.x0 = a.x0 - b.x0; - x.x1 = a.x1 - b.x1 - (x.x0 > a.x0); - if (x.x1 >> 63) { - x_sgn ^= 1; - x.x0 = -x.x0; - x.x1 = -x.x1 - !!x.x0; - } - } - - if (!(x.x0 | x.x1)) - return f3_zero(0); - - x = f3_normalise(&x_exp, x); - - return f3_round(x_sgn, x_exp + 12, x); -} - -long double __addtf3(long double a, long double b) -{ - return f3_add(a, b, 0); -} - -long double __subtf3(long double a, long double b) -{ - return f3_add(a, b, 1); -} - -long double __multf3(long double fa, long double fb) -{ - u128_t a, b, x; - int32_t a_exp, b_exp, x_exp; - int a_sgn, b_sgn, x_sgn; - long double fx; - - f3_unpack(&a_sgn, &a_exp, &a, fa); - f3_unpack(&b_sgn, &b_exp, &b, fb); - - if (fp3_detect_NaNs(&fx, a_sgn, a_exp, a, b_sgn, b_exp, b)) - return fx; - - // Handle infinities and zeroes: - if ((a_exp == 32767 && !(b.x0 | b.x1)) || - (b_exp == 32767 && !(a.x0 | a.x1))) - return f3_NaN(); - if (a_exp == 32767 || b_exp == 32767) - return f3_infinity(a_sgn ^ b_sgn); - if (!(a.x0 | a.x1) || !(b.x0 | b.x1)) - return f3_zero(a_sgn ^ b_sgn); - - a = f3_normalise(&a_exp, a); - b = f3_normalise(&b_exp, b); - - x_sgn = a_sgn ^ b_sgn; - x_exp = a_exp + b_exp - 16352; - - { - // Convert to base (1 << 30), discarding bottom 6 bits, which are zero, - // so there are (32, 30, 30, 30) bits in (a3, a2, a1, a0): - uint64_t a0 = a.x0 << 28 >> 34; - uint64_t b0 = b.x0 << 28 >> 34; - uint64_t a1 = a.x0 >> 36 | a.x1 << 62 >> 34; - uint64_t b1 = b.x0 >> 36 | b.x1 << 62 >> 34; - uint64_t a2 = a.x1 << 32 >> 34; - uint64_t b2 = b.x1 << 32 >> 34; - uint64_t a3 = a.x1 >> 32; - uint64_t b3 = b.x1 >> 32; - // Use 16 small multiplications and additions that do not overflow: - uint64_t x0 = a0 * b0; - uint64_t x1 = (x0 >> 30) + a0 * b1 + a1 * b0; - uint64_t x2 = (x1 >> 30) + a0 * b2 + a1 * b1 + a2 * b0; - uint64_t x3 = (x2 >> 30) + a0 * b3 + a1 * b2 + a2 * b1 + a3 * b0; - uint64_t x4 = (x3 >> 30) + a1 * b3 + a2 * b2 + a3 * b1; - uint64_t x5 = (x4 >> 30) + a2 * b3 + a3 * b2; - uint64_t x6 = (x5 >> 30) + a3 * b3; - // We now have (64, 30, 30, ...) bits in (x6, x5, x4, ...). - // Take the top 128 bits, setting bottom bit if any lower bits were set: - uint64_t y0 = (x5 << 34 | x4 << 34 >> 30 | x3 << 34 >> 60 | - !!(x3 << 38 | (x2 | x1 | x0) << 34)); - uint64_t y1 = x6; - // Top bit may be zero. Renormalise: - if (!(y1 >> 63)) { - y1 = y1 << 1 | y0 >> 63; - y0 = y0 << 1; - --x_exp; - } - x.x0 = y0; - x.x1 = y1; - } - - return f3_round(x_sgn, x_exp, x); -} - -long double __divtf3(long double fa, long double fb) -{ - u128_t a, b, x; - int32_t a_exp, b_exp, x_exp; - int a_sgn, b_sgn, x_sgn, i; - long double fx; - - f3_unpack(&a_sgn, &a_exp, &a, fa); - f3_unpack(&b_sgn, &b_exp, &b, fb); - - if (fp3_detect_NaNs(&fx, a_sgn, a_exp, a, b_sgn, b_exp, b)) - return fx; - - // Handle infinities and zeroes: - if ((a_exp == 32767 && b_exp == 32767) || - (!(a.x0 | a.x1) && !(b.x0 | b.x1))) - return f3_NaN(); - if (a_exp == 32767 || !(b.x0 | b.x1)) - return f3_infinity(a_sgn ^ b_sgn); - if (!(a.x0 | a.x1) || b_exp == 32767) - return f3_zero(a_sgn ^ b_sgn); - - a = f3_normalise(&a_exp, a); - b = f3_normalise(&b_exp, b); - - x_sgn = a_sgn ^ b_sgn; - x_exp = a_exp - b_exp + 16395; - - a.x0 = a.x0 >> 1 | a.x1 << 63; - a.x1 = a.x1 >> 1; - b.x0 = b.x0 >> 1 | b.x1 << 63; - b.x1 = b.x1 >> 1; - x.x0 = 0; - x.x1 = 0; - for (i = 0; i < 116; i++) { - x.x1 = x.x1 << 1 | x.x0 >> 63; - x.x0 = x.x0 << 1; - if (a.x1 > b.x1 || (a.x1 == b.x1 && a.x0 >= b.x0)) { - a.x1 = a.x1 - b.x1 - (a.x0 < b.x0); - a.x0 = a.x0 - b.x0; - x.x0 |= 1; - } - a.x1 = a.x1 << 1 | a.x0 >> 63; - a.x0 = a.x0 << 1; - } - x.x0 |= !!(a.x0 | a.x1); - - x = f3_normalise(&x_exp, x); - - return f3_round(x_sgn, x_exp, x); -} - -long double __extendsftf2(float f) -{ - long double fx; - u128_t x; - uint32_t a; - uint64_t aa; - memcpy(&a, &f, 4); - aa = a; - x.x0 = 0; - if (!(a << 1)) - x.x1 = aa << 32; - else if (a << 1 >> 24 == 255) - x.x1 = (0x7fff000000000000 | aa >> 31 << 63 | aa << 41 >> 16 | - (uint64_t)!!(a << 9) << 47); - else - x.x1 = (aa >> 31 << 63 | ((aa >> 23 & 255) + 16256) << 48 | - aa << 41 >> 16); - memcpy(&fx, &x, 16); - return fx; -} - -long double __extenddftf2(double f) -{ - long double fx; - u128_t x; - uint64_t a; - memcpy(&a, &f, 8); - x.x0 = a << 60; - if (!(a << 1)) - x.x1 = a; - else if (a << 1 >> 53 == 2047) - x.x1 = (0x7fff000000000000 | a >> 63 << 63 | a << 12 >> 16 | - (uint64_t)!!(a << 12) << 47); - else - x.x1 = a >> 63 << 63 | ((a >> 52 & 2047) + 15360) << 48 | a << 12 >> 16; - memcpy(&fx, &x, 16); - return fx; -} - -float __trunctfsf2(long double f) -{ - u128_t mnt; - int32_t exp; - int sgn; - uint32_t x; - float fx; - - f3_unpack(&sgn, &exp, &mnt, f); - - if (exp == 32767 && (mnt.x0 | mnt.x1 << 16)) - x = 0x7fc00000 | (uint32_t)sgn << 31 | (mnt.x1 >> 25 & 0x007fffff); - else if (exp > 16510) - x = 0x7f800000 | (uint32_t)sgn << 31; - else if (exp < 16233) - x = (uint32_t)sgn << 31; - else { - exp -= 16257; - x = mnt.x1 >> 23 | !!(mnt.x0 | mnt.x1 << 41); - if (exp < 0) { - x = x >> -exp | !!(x << (32 + exp)); - exp = 0; - } - if ((x & 3) == 3 || (x & 7) == 6) - x += 4; - x = ((x >> 2) + (exp << 23)) | (uint32_t)sgn << 31; - } - memcpy(&fx, &x, 4); - return fx; -} - -double __trunctfdf2(long double f) -{ - u128_t mnt; - int32_t exp; - int sgn; - uint64_t x; - double fx; - - f3_unpack(&sgn, &exp, &mnt, f); - - if (exp == 32767 && (mnt.x0 | mnt.x1 << 16)) - x = (0x7ff8000000000000 | (uint64_t)sgn << 63 | - mnt.x1 << 16 >> 12 | mnt.x0 >> 60); - else if (exp > 17406) - x = 0x7ff0000000000000 | (uint64_t)sgn << 63; - else if (exp < 15308) - x = (uint64_t)sgn << 63; - else { - exp -= 15361; - x = mnt.x1 << 6 | mnt.x0 >> 58 | !!(mnt.x0 << 6); - if (exp < 0) { - x = x >> -exp | !!(x << (64 + exp)); - exp = 0; - } - if ((x & 3) == 3 || (x & 7) == 6) - x += 4; - x = ((x >> 2) + ((uint64_t)exp << 52)) | (uint64_t)sgn << 63; - } - memcpy(&fx, &x, 8); - return fx; -} - -int32_t __fixtfsi(long double fa) -{ - u128_t a; - int32_t a_exp; - int a_sgn; - int32_t x; - f3_unpack(&a_sgn, &a_exp, &a, fa); - if (a_exp < 16369) - return 0; - if (a_exp > 16413) - return a_sgn ? -0x80000000 : 0x7fffffff; - x = a.x1 >> (16431 - a_exp); - return a_sgn ? -x : x; -} - -int64_t __fixtfdi(long double fa) -{ - u128_t a; - int32_t a_exp; - int a_sgn; - int64_t x; - f3_unpack(&a_sgn, &a_exp, &a, fa); - if (a_exp < 16383) - return 0; - if (a_exp > 16445) - return a_sgn ? -0x8000000000000000 : 0x7fffffffffffffff; - x = (a.x1 << 15 | a.x0 >> 49) >> (16446 - a_exp); - return a_sgn ? -x : x; -} - -uint32_t __fixunstfsi(long double fa) -{ - u128_t a; - int32_t a_exp; - int a_sgn; - f3_unpack(&a_sgn, &a_exp, &a, fa); - if (a_sgn || a_exp < 16369) - return 0; - if (a_exp > 16414) - return -1; - return a.x1 >> (16431 - a_exp); -} - -uint64_t __fixunstfdi(long double fa) -{ - u128_t a; - int32_t a_exp; - int a_sgn; - f3_unpack(&a_sgn, &a_exp, &a, fa); - if (a_sgn || a_exp < 16383) - return 0; - if (a_exp > 16446) - return -1; - return (a.x1 << 15 | a.x0 >> 49) >> (16446 - a_exp); -} - -long double __floatsitf(int32_t a) -{ - int sgn = 0; - int exp = 16414; - uint32_t mnt = a; - u128_t x = { 0, 0 }; - long double f; - int i; - if (a) { - if (a < 0) { - sgn = 1; - mnt = -mnt; - } - for (i = 16; i; i >>= 1) - if (!(mnt >> (32 - i))) { - mnt <<= i; - exp -= i; - } - x.x1 = ((uint64_t)sgn << 63 | (uint64_t)exp << 48 | - (uint64_t)(mnt << 1) << 16); - } - memcpy(&f, &x, 16); - return f; -} - -long double __floatditf(int64_t a) -{ - int sgn = 0; - int exp = 16446; - uint64_t mnt = a; - u128_t x = { 0, 0 }; - long double f; - int i; - if (a) { - if (a < 0) { - sgn = 1; - mnt = -mnt; - } - for (i = 32; i; i >>= 1) - if (!(mnt >> (64 - i))) { - mnt <<= i; - exp -= i; - } - x.x0 = mnt << 49; - x.x1 = (uint64_t)sgn << 63 | (uint64_t)exp << 48 | mnt << 1 >> 16; - } - memcpy(&f, &x, 16); - return f; -} - -long double __floatunsitf(uint32_t a) -{ - int exp = 16414; - uint32_t mnt = a; - u128_t x = { 0, 0 }; - long double f; - int i; - if (a) { - for (i = 16; i; i >>= 1) - if (!(mnt >> (32 - i))) { - mnt <<= i; - exp -= i; - } - x.x1 = (uint64_t)exp << 48 | (uint64_t)(mnt << 1) << 16; - } - memcpy(&f, &x, 16); - return f; -} - -long double __floatunditf(uint64_t a) -{ - int exp = 16446; - uint64_t mnt = a; - u128_t x = { 0, 0 }; - long double f; - int i; - if (a) { - for (i = 32; i; i >>= 1) - if (!(mnt >> (64 - i))) { - mnt <<= i; - exp -= i; - } - x.x0 = mnt << 49; - x.x1 = (uint64_t)exp << 48 | mnt << 1 >> 16; - } - memcpy(&f, &x, 16); - return f; -} - -static int f3_cmp(long double fa, long double fb) -{ - u128_t a, b; - memcpy(&a, &fa, 16); - memcpy(&b, &fb, 16); - return (!(a.x0 | a.x1 << 1 | b.x0 | b.x1 << 1) ? 0 : - ((a.x1 << 1 >> 49 == 0x7fff && (a.x0 | a.x1 << 16)) || - (b.x1 << 1 >> 49 == 0x7fff && (b.x0 | b.x1 << 16))) ? 2 : - a.x1 >> 63 != b.x1 >> 63 ? (int)(b.x1 >> 63) - (int)(a.x1 >> 63) : - a.x1 < b.x1 ? (int)(a.x1 >> 63 << 1) - 1 : - a.x1 > b.x1 ? 1 - (int)(a.x1 >> 63 << 1) : - a.x0 < b.x0 ? (int)(a.x1 >> 63 << 1) - 1 : - b.x0 < a.x0 ? 1 - (int)(a.x1 >> 63 << 1) : 0); -} - -int __eqtf2(long double a, long double b) -{ - return !!f3_cmp(a, b); -} - -int __netf2(long double a, long double b) -{ - return !!f3_cmp(a, b); -} - -int __lttf2(long double a, long double b) -{ - return f3_cmp(a, b); -} - -int __letf2(long double a, long double b) -{ - return f3_cmp(a, b); -} - -int __gttf2(long double a, long double b) -{ - return -f3_cmp(b, a); -} - -int __getf2(long double a, long double b) -{ - return -f3_cmp(b, a); -} diff --git a/05/tcc-final-old/lib/libtcc1.c b/05/tcc-final-old/lib/libtcc1.c deleted file mode 100644 index 0e46618..0000000 --- a/05/tcc-final-old/lib/libtcc1.c +++ /dev/null @@ -1,622 +0,0 @@ -/* TCC runtime library. - Parts of this code are (c) 2002 Fabrice Bellard - - Copyright (C) 1987, 1988, 1992, 1994, 1995 Free Software Foundation, Inc. - -This file is free software; you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 2, or (at your option) any -later version. - -In addition to the permissions in the GNU General Public License, the -Free Software Foundation gives you unlimited permission to link the -compiled version of this file into combinations with other programs, -and to distribute those combinations without any restriction coming -from the use of this file. (The General Public License restrictions -do apply in other respects; for example, they cover modification of -the file, and distribution when not linked into a combine -executable.) - -This file is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; see the file COPYING. If not, write to -the Free Software Foundation, 59 Temple Place - Suite 330, -Boston, MA 02111-1307, USA. -*/ - -#define W_TYPE_SIZE 32 -#define BITS_PER_UNIT 8 - -typedef int Wtype; -typedef unsigned int UWtype; -typedef unsigned int USItype; -typedef long long DWtype; -typedef unsigned long long UDWtype; - -struct DWstruct { - Wtype low, high; -}; - -typedef union -{ - struct DWstruct s; - DWtype ll; -} DWunion; - -typedef long double XFtype; -#define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT) -#define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE) - -/* the following deal with IEEE single-precision numbers */ -#define EXCESS 126 -#define SIGNBIT 0x80000000 -#define HIDDEN (1 << 23) -#define SIGN(fp) ((fp) & SIGNBIT) -#define EXP(fp) (((fp) >> 23) & 0xFF) -#define MANT(fp) (((fp) & 0x7FFFFF) | HIDDEN) -#define PACK(s,e,m) ((s) | ((e) << 23) | (m)) - -/* the following deal with IEEE double-precision numbers */ -#define EXCESSD 1022 -#define HIDDEND (1 << 20) -#define EXPD(fp) (((fp.l.upper) >> 20) & 0x7FF) -#define SIGND(fp) ((fp.l.upper) & SIGNBIT) -#define MANTD(fp) (((((fp.l.upper) & 0xFFFFF) | HIDDEND) << 10) | \ - (fp.l.lower >> 22)) -#define HIDDEND_LL ((long long)1 << 52) -#define MANTD_LL(fp) ((fp.ll & (HIDDEND_LL-1)) | HIDDEND_LL) -#define PACKD_LL(s,e,m) (((long long)((s)+((e)<<20))<<32)|(m)) - -/* the following deal with x86 long double-precision numbers */ -#define EXCESSLD 16382 -#define EXPLD(fp) (fp.l.upper & 0x7fff) -#define SIGNLD(fp) ((fp.l.upper) & 0x8000) - -/* only for x86 */ -union ldouble_long { - long double ld; - struct { - unsigned long long lower; - unsigned short upper; - } l; -}; - -union double_long { - double d; -#if 1 - struct { - unsigned int lower; - int upper; - } l; -#else - struct { - int upper; - unsigned int lower; - } l; -#endif - long long ll; -}; - -union float_long { - float f; - unsigned int l; -}; - -/* XXX: we don't support several builtin supports for now */ -#if !defined __x86_64__ && !defined __arm__ - -/* XXX: use gcc/tcc intrinsic ? */ -#if defined __i386__ -#define sub_ddmmss(sh, sl, ah, al, bh, bl) \ - __asm__ ("subl %5,%1\n\tsbbl %3,%0" \ - : "=r" ((USItype) (sh)), \ - "=&r" ((USItype) (sl)) \ - : "0" ((USItype) (ah)), \ - "g" ((USItype) (bh)), \ - "1" ((USItype) (al)), \ - "g" ((USItype) (bl))) -#define umul_ppmm(w1, w0, u, v) \ - __asm__ ("mull %3" \ - : "=a" ((USItype) (w0)), \ - "=d" ((USItype) (w1)) \ - : "%0" ((USItype) (u)), \ - "rm" ((USItype) (v))) -#define udiv_qrnnd(q, r, n1, n0, dv) \ - __asm__ ("divl %4" \ - : "=a" ((USItype) (q)), \ - "=d" ((USItype) (r)) \ - : "0" ((USItype) (n0)), \ - "1" ((USItype) (n1)), \ - "rm" ((USItype) (dv))) -#define count_leading_zeros(count, x) \ - do { \ - USItype __cbtmp; \ - __asm__ ("bsrl %1,%0" \ - : "=r" (__cbtmp) : "rm" ((USItype) (x))); \ - (count) = __cbtmp ^ 31; \ - } while (0) -#else -#error unsupported CPU type -#endif - -/* most of this code is taken from libgcc2.c from gcc */ - -static UDWtype __udivmoddi4 (UDWtype n, UDWtype d, UDWtype *rp) -{ - DWunion ww; - DWunion nn, dd; - DWunion rr; - UWtype d0, d1, n0, n1, n2; - UWtype q0, q1; - UWtype b, bm; - - nn.ll = n; - dd.ll = d; - - d0 = dd.s.low; - d1 = dd.s.high; - n0 = nn.s.low; - n1 = nn.s.high; - -#if !defined(UDIV_NEEDS_NORMALIZATION) - if (d1 == 0) - { - if (d0 > n1) - { - /* 0q = nn / 0D */ - - udiv_qrnnd (q0, n0, n1, n0, d0); - q1 = 0; - - /* Remainder in n0. */ - } - else - { - /* qq = NN / 0d */ - - if (d0 == 0) - d0 = 1 / d0; /* Divide intentionally by zero. */ - - udiv_qrnnd (q1, n1, 0, n1, d0); - udiv_qrnnd (q0, n0, n1, n0, d0); - - /* Remainder in n0. */ - } - - if (rp != 0) - { - rr.s.low = n0; - rr.s.high = 0; - *rp = rr.ll; - } - } - -#else /* UDIV_NEEDS_NORMALIZATION */ - - if (d1 == 0) - { - if (d0 > n1) - { - /* 0q = nn / 0D */ - - count_leading_zeros (bm, d0); - - if (bm != 0) - { - /* Normalize, i.e. make the most significant bit of the - denominator set. */ - - d0 = d0 << bm; - n1 = (n1 << bm) | (n0 >> (W_TYPE_SIZE - bm)); - n0 = n0 << bm; - } - - udiv_qrnnd (q0, n0, n1, n0, d0); - q1 = 0; - - /* Remainder in n0 >> bm. */ - } - else - { - /* qq = NN / 0d */ - - if (d0 == 0) - d0 = 1 / d0; /* Divide intentionally by zero. */ - - count_leading_zeros (bm, d0); - - if (bm == 0) - { - /* From (n1 >= d0) /\ (the most significant bit of d0 is set), - conclude (the most significant bit of n1 is set) /\ (the - leading quotient digit q1 = 1). - - This special case is necessary, not an optimization. - (Shifts counts of W_TYPE_SIZE are undefined.) */ - - n1 -= d0; - q1 = 1; - } - else - { - /* Normalize. */ - - b = W_TYPE_SIZE - bm; - - d0 = d0 << bm; - n2 = n1 >> b; - n1 = (n1 << bm) | (n0 >> b); - n0 = n0 << bm; - - udiv_qrnnd (q1, n1, n2, n1, d0); - } - - /* n1 != d0... */ - - udiv_qrnnd (q0, n0, n1, n0, d0); - - /* Remainder in n0 >> bm. */ - } - - if (rp != 0) - { - rr.s.low = n0 >> bm; - rr.s.high = 0; - *rp = rr.ll; - } - } -#endif /* UDIV_NEEDS_NORMALIZATION */ - - else - { - if (d1 > n1) - { - /* 00 = nn / DD */ - - q0 = 0; - q1 = 0; - - /* Remainder in n1n0. */ - if (rp != 0) - { - rr.s.low = n0; - rr.s.high = n1; - *rp = rr.ll; - } - } - else - { - /* 0q = NN / dd */ - - count_leading_zeros (bm, d1); - if (bm == 0) - { - /* From (n1 >= d1) /\ (the most significant bit of d1 is set), - conclude (the most significant bit of n1 is set) /\ (the - quotient digit q0 = 0 or 1). - - This special case is necessary, not an optimization. */ - - /* The condition on the next line takes advantage of that - n1 >= d1 (true due to program flow). */ - if (n1 > d1 || n0 >= d0) - { - q0 = 1; - sub_ddmmss (n1, n0, n1, n0, d1, d0); - } - else - q0 = 0; - - q1 = 0; - - if (rp != 0) - { - rr.s.low = n0; - rr.s.high = n1; - *rp = rr.ll; - } - } - else - { - UWtype m1, m0; - /* Normalize. */ - - b = W_TYPE_SIZE - bm; - - d1 = (d1 << bm) | (d0 >> b); - d0 = d0 << bm; - n2 = n1 >> b; - n1 = (n1 << bm) | (n0 >> b); - n0 = n0 << bm; - - udiv_qrnnd (q0, n1, n2, n1, d1); - umul_ppmm (m1, m0, q0, d0); - - if (m1 > n1 || (m1 == n1 && m0 > n0)) - { - q0--; - sub_ddmmss (m1, m0, m1, m0, d1, d0); - } - - q1 = 0; - - /* Remainder in (n1n0 - m1m0) >> bm. */ - if (rp != 0) - { - sub_ddmmss (n1, n0, n1, n0, m1, m0); - rr.s.low = (n1 << b) | (n0 >> bm); - rr.s.high = n1 >> bm; - *rp = rr.ll; - } - } - } - } - - ww.s.low = q0; - ww.s.high = q1; - return ww.ll; -} - -#define __negdi2(a) (-(a)) - -long long __divdi3(long long u, long long v) -{ - int c = 0; - DWunion uu, vv; - DWtype w; - - uu.ll = u; - vv.ll = v; - - if (uu.s.high < 0) { - c = ~c; - uu.ll = __negdi2 (uu.ll); - } - if (vv.s.high < 0) { - c = ~c; - vv.ll = __negdi2 (vv.ll); - } - w = __udivmoddi4 (uu.ll, vv.ll, (UDWtype *) 0); - if (c) - w = __negdi2 (w); - return w; -} - -long long __moddi3(long long u, long long v) -{ - int c = 0; - DWunion uu, vv; - DWtype w; - - uu.ll = u; - vv.ll = v; - - if (uu.s.high < 0) { - c = ~c; - uu.ll = __negdi2 (uu.ll); - } - if (vv.s.high < 0) - vv.ll = __negdi2 (vv.ll); - - __udivmoddi4 (uu.ll, vv.ll, (UDWtype *) &w); - if (c) - w = __negdi2 (w); - return w; -} - -unsigned long long __udivdi3(unsigned long long u, unsigned long long v) -{ - return __udivmoddi4 (u, v, (UDWtype *) 0); -} - -unsigned long long __umoddi3(unsigned long long u, unsigned long long v) -{ - UDWtype w; - - __udivmoddi4 (u, v, &w); - return w; -} - -/* XXX: fix tcc's code generator to do this instead */ -long long __ashrdi3(long long a, int b) -{ -#ifdef __TINYC__ - DWunion u; - u.ll = a; - if (b >= 32) { - u.s.low = u.s.high >> (b - 32); - u.s.high = u.s.high >> 31; - } else if (b != 0) { - u.s.low = ((unsigned)u.s.low >> b) | (u.s.high << (32 - b)); - u.s.high = u.s.high >> b; - } - return u.ll; -#else - return a >> b; -#endif -} - -/* XXX: fix tcc's code generator to do this instead */ -unsigned long long __lshrdi3(unsigned long long a, int b) -{ -#ifdef __TINYC__ - DWunion u; - u.ll = a; - if (b >= 32) { - u.s.low = (unsigned)u.s.high >> (b - 32); - u.s.high = 0; - } else if (b != 0) { - u.s.low = ((unsigned)u.s.low >> b) | (u.s.high << (32 - b)); - u.s.high = (unsigned)u.s.high >> b; - } - return u.ll; -#else - return a >> b; -#endif -} - -/* XXX: fix tcc's code generator to do this instead */ -long long __ashldi3(long long a, int b) -{ -#ifdef __TINYC__ - DWunion u; - u.ll = a; - if (b >= 32) { - u.s.high = (unsigned)u.s.low << (b - 32); - u.s.low = 0; - } else if (b != 0) { - u.s.high = ((unsigned)u.s.high << b) | ((unsigned)u.s.low >> (32 - b)); - u.s.low = (unsigned)u.s.low << b; - } - return u.ll; -#else - return a << b; -#endif -} - -#endif /* !__x86_64__ */ - -/* XXX: fix tcc's code generator to do this instead */ -float __floatundisf(unsigned long long a) -{ - DWunion uu; - XFtype r; - - uu.ll = a; - if (uu.s.high >= 0) { - return (float)uu.ll; - } else { - r = (XFtype)uu.ll; - r += 18446744073709551616.0; - return (float)r; - } -} - -double __floatundidf(unsigned long long a) -{ - DWunion uu; - XFtype r; - - uu.ll = a; - if (uu.s.high >= 0) { - return (double)uu.ll; - } else { - r = (XFtype)uu.ll; - r += 18446744073709551616.0; - return (double)r; - } -} - -long double __floatundixf(unsigned long long a) -{ - DWunion uu; - XFtype r; - - uu.ll = a; - if (uu.s.high >= 0) { - return (long double)uu.ll; - } else { - r = (XFtype)uu.ll; - r += 18446744073709551616.0; - return (long double)r; - } -} - -unsigned long long __fixunssfdi (float a1) -{ - register union float_long fl1; - register int exp; - register unsigned long l; - - fl1.f = a1; - - if (fl1.l == 0) - return (0); - - exp = EXP (fl1.l) - EXCESS - 24; - - l = MANT(fl1.l); - if (exp >= 41) - return (unsigned long long)-1; - else if (exp >= 0) - return (unsigned long long)l << exp; - else if (exp >= -23) - return l >> -exp; - else - return 0; -} - -long long __fixsfdi (float a1) -{ - long long ret; int s; - ret = __fixunssfdi((s = a1 >= 0) ? a1 : -a1); - return s ? ret : -ret; -} - -unsigned long long __fixunsdfdi (double a1) -{ - register union double_long dl1; - register int exp; - register unsigned long long l; - - dl1.d = a1; - - if (dl1.ll == 0) - return (0); - - exp = EXPD (dl1) - EXCESSD - 53; - - l = MANTD_LL(dl1); - - if (exp >= 12) - return (unsigned long long)-1; - else if (exp >= 0) - return l << exp; - else if (exp >= -52) - return l >> -exp; - else - return 0; -} - -long long __fixdfdi (double a1) -{ - long long ret; int s; - ret = __fixunsdfdi((s = a1 >= 0) ? a1 : -a1); - return s ? ret : -ret; -} - -#ifndef __arm__ -unsigned long long __fixunsxfdi (long double a1) -{ - register union ldouble_long dl1; - register int exp; - register unsigned long long l; - - dl1.ld = a1; - - if (dl1.l.lower == 0 && dl1.l.upper == 0) - return (0); - - exp = EXPLD (dl1) - EXCESSLD - 64; - - l = dl1.l.lower; - - if (exp > 0) - return (unsigned long long)-1; - else if (exp >= -63) - return l >> -exp; - else - return 0; -} - -long long __fixxfdi (long double a1) -{ - long long ret; int s; - ret = __fixunsxfdi((s = a1 >= 0) ? a1 : -a1); - return s ? ret : -ret; -} -#endif /* !ARM */ diff --git a/05/tcc-final-old/lib/va_list.c b/05/tcc-final-old/lib/va_list.c deleted file mode 100644 index 8749f46..0000000 --- a/05/tcc-final-old/lib/va_list.c +++ /dev/null @@ -1,65 +0,0 @@ -/* va_list.c - tinycc support for va_list on X86_64 */ - -#if defined __x86_64__ - -/* Avoid include files, they may not be available when cross compiling */ -extern void *memset(void *s, int c, __SIZE_TYPE__ n); -extern void abort(void); - -/* This should be in sync with our include/stdarg.h */ -enum __va_arg_type { - __va_gen_reg, __va_float_reg, __va_stack -}; - -/* GCC compatible definition of va_list. */ -typedef struct { - unsigned int gp_offset; - unsigned int fp_offset; - union { - unsigned int overflow_offset; - char *overflow_arg_area; - }; - char *reg_save_area; -} __va_list_struct; - -void __va_start(__va_list_struct *ap, void *fp) -{ - memset(ap, 0, sizeof(__va_list_struct)); - *ap = *(__va_list_struct *)((char *)fp - 16); - ap->overflow_arg_area = (char *)fp + ap->overflow_offset; - ap->reg_save_area = (char *)fp - 176 - 16; -} - -void *__va_arg(__va_list_struct *ap, - enum __va_arg_type arg_type, - int size, int align) -{ - size = (size + 7) & ~7; - align = (align + 7) & ~7; - switch (arg_type) { - case __va_gen_reg: - if (ap->gp_offset + size <= 48) { - ap->gp_offset += size; - return ap->reg_save_area + ap->gp_offset - size; - } - goto use_overflow_area; - - case __va_float_reg: - if (ap->fp_offset < 128 + 48) { - ap->fp_offset += 16; - return ap->reg_save_area + ap->fp_offset - 16; - } - size = 8; - goto use_overflow_area; - - case __va_stack: - use_overflow_area: - ap->overflow_arg_area += size; - ap->overflow_arg_area = (char*)((long long)(ap->overflow_arg_area + align - 1) & -align); - return ap->overflow_arg_area - size; - - default: /* should never happen */ - abort(); - } -} -#endif diff --git a/05/tcc-final-old/libtcc.c b/05/tcc-final-old/libtcc.c deleted file mode 100644 index 1e9dd97..0000000 --- a/05/tcc-final-old/libtcc.c +++ /dev/null @@ -1,1981 +0,0 @@ -/* - * TCC - Tiny C Compiler - * - * Copyright (c) 2001-2004 Fabrice Bellard - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "tcc.h" - -/********************************************************/ -/* global variables */ - -/* use GNU C extensions */ -ST_DATA int gnu_ext = 1; - -/* use TinyCC extensions */ -ST_DATA int tcc_ext = 1; - -/* XXX: get rid of this ASAP */ -ST_DATA struct TCCState *tcc_state; - -static int nb_states; - -/********************************************************/ - -#if ONE_SOURCE -#include "tccpp.c" -#include "tccgen.c" -#include "tccelf.c" -#include "tccrun.c" -#ifdef TCC_TARGET_I386 -#include "i386-gen.c" -#include "i386-link.c" -#include "i386-asm.c" -#endif -#ifdef TCC_TARGET_ARM -#include "arm-gen.c" -#include "arm-link.c" -#include "arm-asm.c" -#endif -#ifdef TCC_TARGET_ARM64 -#include "arm64-gen.c" -#include "arm64-link.c" -#endif -#ifdef TCC_TARGET_C67 -#include "c67-gen.c" -#include "c67-link.c" -#include "tcccoff.c" -#endif -#ifdef TCC_TARGET_X86_64 -#include "x86_64-gen.c" -#include "x86_64-link.c" -#include "i386-asm.c" -#endif -#ifdef CONFIG_TCC_ASM -#include "tccasm.c" -#endif -#ifdef TCC_TARGET_PE -#include "tccpe.c" -#endif -#endif /* ONE_SOURCE */ - -/********************************************************/ -#ifndef CONFIG_TCC_ASM -ST_FUNC void asm_instr(void) -{ - tcc_error("inline asm() not supported"); -} -ST_FUNC void asm_global_instr(void) -{ - tcc_error("inline asm() not supported"); -} -#endif - -/********************************************************/ -#ifdef _WIN32 -ST_FUNC char *normalize_slashes(char *path) -{ - char *p; - for (p = path; *p; ++p) - if (*p == '\\') - *p = '/'; - return path; -} - -static HMODULE tcc_module; - -/* on win32, we suppose the lib and includes are at the location of 'tcc.exe' */ -static void tcc_set_lib_path_w32(TCCState *s) -{ - char path[1024], *p; - GetModuleFileNameA(tcc_module, path, sizeof path); - p = tcc_basename(normalize_slashes(strlwr(path))); - if (p > path) - --p; - *p = 0; - tcc_set_lib_path(s, path); -} - -#ifdef TCC_TARGET_PE -static void tcc_add_systemdir(TCCState *s) -{ - char buf[1000]; - GetSystemDirectory(buf, sizeof buf); - tcc_add_library_path(s, normalize_slashes(buf)); -} -#endif - -#ifdef LIBTCC_AS_DLL -BOOL WINAPI DllMain (HINSTANCE hDll, DWORD dwReason, LPVOID lpReserved) -{ - if (DLL_PROCESS_ATTACH == dwReason) - tcc_module = hDll; - return TRUE; -} -#endif -#endif - -/********************************************************/ -/* copy a string and truncate it. */ -ST_FUNC char *pstrcpy(char *buf, int buf_size, const char *s) -{ - char *q, *q_end; - int c; - - if (buf_size > 0) { - q = buf; - q_end = buf + buf_size - 1; - while (q < q_end) { - c = *s++; - if (c == '\0') - break; - *q++ = c; - } - *q = '\0'; - } - return buf; -} - -/* strcat and truncate. */ -ST_FUNC char *pstrcat(char *buf, int buf_size, const char *s) -{ - int len; - len = strlen(buf); - if (len < buf_size) - pstrcpy(buf + len, buf_size - len, s); - return buf; -} - -ST_FUNC char *pstrncpy(char *out, const char *in, size_t num) -{ - memcpy(out, in, num); - out[num] = '\0'; - return out; -} - -/* extract the basename of a file */ -PUB_FUNC char *tcc_basename(const char *name) -{ - char *p = strchr(name, 0); - while (p > name && !IS_DIRSEP(p[-1])) - --p; - return p; -} - -/* extract extension part of a file - * - * (if no extension, return pointer to end-of-string) - */ -PUB_FUNC char *tcc_fileextension (const char *name) -{ - char *b = tcc_basename(name); - char *e = strrchr(b, '.'); - return e ? e : strchr(b, 0); -} - -/********************************************************/ -/* memory management */ - -#undef free -#undef malloc -#undef realloc - -#ifndef MEM_DEBUG - -PUB_FUNC void tcc_free(void *ptr) -{ - free(ptr); -} - -PUB_FUNC void *tcc_malloc(unsigned long size) -{ - void *ptr; - ptr = malloc(size); - if (!ptr && size) - tcc_error("memory full (malloc)"); - return ptr; -} - -PUB_FUNC void *tcc_mallocz(unsigned long size) -{ - void *ptr; - ptr = tcc_malloc(size); - memset(ptr, 0, size); - return ptr; -} - -PUB_FUNC void *tcc_realloc(void *ptr, unsigned long size) -{ - void *ptr1; - ptr1 = realloc(ptr, size); - if (!ptr1 && size) - tcc_error("memory full (realloc)"); - return ptr1; -} - -PUB_FUNC char *tcc_strdup(const char *str) -{ - char *ptr; - ptr = tcc_malloc(strlen(str) + 1); - strcpy(ptr, str); - return ptr; -} - -PUB_FUNC void tcc_memcheck(void) -{ -} - -#else - -#define MEM_DEBUG_MAGIC1 0xFEEDDEB1 -#define MEM_DEBUG_MAGIC2 0xFEEDDEB2 -#define MEM_DEBUG_MAGIC3 0xFEEDDEB3 -#define MEM_DEBUG_FILE_LEN 40 -#define MEM_DEBUG_CHECK3(header) \ - ((mem_debug_header_t*)((char*)header + header->size))->magic3 -#define MEM_USER_PTR(header) \ - ((char *)header + offsetof(mem_debug_header_t, magic3)) -#define MEM_HEADER_PTR(ptr) \ - (mem_debug_header_t *)((char*)ptr - offsetof(mem_debug_header_t, magic3)) - -struct mem_debug_header { - unsigned magic1; - unsigned size; - struct mem_debug_header *prev; - struct mem_debug_header *next; - int line_num; - char file_name[MEM_DEBUG_FILE_LEN + 1]; - unsigned magic2; - ALIGNED(16) unsigned magic3; -}; - -typedef struct mem_debug_header mem_debug_header_t; - -static mem_debug_header_t *mem_debug_chain; -static unsigned mem_cur_size; -static unsigned mem_max_size; - -static mem_debug_header_t *malloc_check(void *ptr, const char *msg) -{ - mem_debug_header_t * header = MEM_HEADER_PTR(ptr); - if (header->magic1 != MEM_DEBUG_MAGIC1 || - header->magic2 != MEM_DEBUG_MAGIC2 || - MEM_DEBUG_CHECK3(header) != MEM_DEBUG_MAGIC3 || - header->size == (unsigned)-1) { - fprintf(stderr, "%s check failed\n", msg); - if (header->magic1 == MEM_DEBUG_MAGIC1) - fprintf(stderr, "%s:%u: block allocated here.\n", - header->file_name, header->line_num); - exit(1); - } - return header; -} - -PUB_FUNC void *tcc_malloc_debug(unsigned long size, const char *file, int line) -{ - int ofs; - mem_debug_header_t *header; - - header = malloc(sizeof(mem_debug_header_t) + size); - if (!header) - tcc_error("memory full (malloc)"); - - header->magic1 = MEM_DEBUG_MAGIC1; - header->magic2 = MEM_DEBUG_MAGIC2; - header->size = size; - MEM_DEBUG_CHECK3(header) = MEM_DEBUG_MAGIC3; - header->line_num = line; - ofs = strlen(file) - MEM_DEBUG_FILE_LEN; - strncpy(header->file_name, file + (ofs > 0 ? ofs : 0), MEM_DEBUG_FILE_LEN); - header->file_name[MEM_DEBUG_FILE_LEN] = 0; - - header->next = mem_debug_chain; - header->prev = NULL; - if (header->next) - header->next->prev = header; - mem_debug_chain = header; - - mem_cur_size += size; - if (mem_cur_size > mem_max_size) - mem_max_size = mem_cur_size; - - return MEM_USER_PTR(header); -} - -PUB_FUNC void tcc_free_debug(void *ptr) -{ - mem_debug_header_t *header; - if (!ptr) - return; - header = malloc_check(ptr, "tcc_free"); - mem_cur_size -= header->size; - header->size = (unsigned)-1; - if (header->next) - header->next->prev = header->prev; - if (header->prev) - header->prev->next = header->next; - if (header == mem_debug_chain) - mem_debug_chain = header->next; - free(header); -} - -PUB_FUNC void *tcc_mallocz_debug(unsigned long size, const char *file, int line) -{ - void *ptr; - ptr = tcc_malloc_debug(size,file,line); - memset(ptr, 0, size); - return ptr; -} - -PUB_FUNC void *tcc_realloc_debug(void *ptr, unsigned long size, const char *file, int line) -{ - mem_debug_header_t *header; - int mem_debug_chain_update = 0; - if (!ptr) - return tcc_malloc_debug(size, file, line); - header = malloc_check(ptr, "tcc_realloc"); - mem_cur_size -= header->size; - mem_debug_chain_update = (header == mem_debug_chain); - header = realloc(header, sizeof(mem_debug_header_t) + size); - if (!header) - tcc_error("memory full (realloc)"); - header->size = size; - MEM_DEBUG_CHECK3(header) = MEM_DEBUG_MAGIC3; - if (header->next) - header->next->prev = header; - if (header->prev) - header->prev->next = header; - if (mem_debug_chain_update) - mem_debug_chain = header; - mem_cur_size += size; - if (mem_cur_size > mem_max_size) - mem_max_size = mem_cur_size; - return MEM_USER_PTR(header); -} - -PUB_FUNC char *tcc_strdup_debug(const char *str, const char *file, int line) -{ - char *ptr; - ptr = tcc_malloc_debug(strlen(str) + 1, file, line); - strcpy(ptr, str); - return ptr; -} - -PUB_FUNC void tcc_memcheck(void) -{ - if (mem_cur_size) { - mem_debug_header_t *header = mem_debug_chain; - fprintf(stderr, "MEM_DEBUG: mem_leak= %d bytes, mem_max_size= %d bytes\n", - mem_cur_size, mem_max_size); - while (header) { - fprintf(stderr, "%s:%u: error: %u bytes leaked\n", - header->file_name, header->line_num, header->size); - header = header->next; - } -#if MEM_DEBUG-0 == 2 - exit(2); -#endif - } -} -#endif /* MEM_DEBUG */ - -#define free(p) use_tcc_free(p) -#define malloc(s) use_tcc_malloc(s) -#define realloc(p, s) use_tcc_realloc(p, s) - -/********************************************************/ -/* dynarrays */ - -ST_FUNC void dynarray_add(void *ptab, int *nb_ptr, void *data) -{ - int nb, nb_alloc; - void **pp; - - nb = *nb_ptr; - pp = *(void ***)ptab; - /* every power of two we double array size */ - if ((nb & (nb - 1)) == 0) { - if (!nb) - nb_alloc = 1; - else - nb_alloc = nb * 2; - pp = tcc_realloc(pp, nb_alloc * sizeof(void *)); - *(void***)ptab = pp; - } - pp[nb++] = data; - *nb_ptr = nb; -} - -ST_FUNC void dynarray_reset(void *pp, int *n) -{ - void **p; - for (p = *(void***)pp; *n; ++p, --*n) - if (*p) - tcc_free(*p); - tcc_free(*(void**)pp); - *(void**)pp = NULL; -} - -static void tcc_split_path(TCCState *s, void *p_ary, int *p_nb_ary, const char *in) -{ - const char *p; - do { - int c; - CString str; - - cstr_new(&str); - for (p = in; c = *p, c != '\0' && c != PATHSEP[0]; ++p) { - if (c == '{' && p[1] && p[2] == '}') { - c = p[1], p += 2; - if (c == 'B') - cstr_cat(&str, s->tcc_lib_path, -1); - } else { - cstr_ccat(&str, c); - } - } - if (str.size) { - cstr_ccat(&str, '\0'); - dynarray_add(p_ary, p_nb_ary, tcc_strdup(str.data)); - } - cstr_free(&str); - in = p+1; - } while (*p); -} - -/********************************************************/ - -static void strcat_vprintf(char *buf, int buf_size, const char *fmt, va_list ap) -{ - int len; - len = strlen(buf); - vsnprintf(buf + len, buf_size - len, fmt, ap); -} - -static void strcat_printf(char *buf, int buf_size, const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - strcat_vprintf(buf, buf_size, fmt, ap); - va_end(ap); -} - -static void error1(TCCState *s1, int is_warning, const char *fmt, va_list ap) -{ - char buf[2048]; - BufferedFile **pf, *f; - - buf[0] = '\0'; - /* use upper file if inline ":asm:" or token ":paste:" */ - for (f = file; f && f->filename[0] == ':'; f = f->prev) - ; - if (f) { - for(pf = s1->include_stack; pf < s1->include_stack_ptr; pf++) - strcat_printf(buf, sizeof(buf), "In file included from %s:%d:\n", - (*pf)->filename, (*pf)->line_num); - if (s1->error_set_jmp_enabled) { - strcat_printf(buf, sizeof(buf), "%s:%d: ", - f->filename, f->line_num - !!(tok_flags & TOK_FLAG_BOL)); - } else { - strcat_printf(buf, sizeof(buf), "%s: ", - f->filename); - } - } else { - strcat_printf(buf, sizeof(buf), "tcc: "); - } - if (is_warning) - strcat_printf(buf, sizeof(buf), "warning: "); - else - strcat_printf(buf, sizeof(buf), "error: "); - strcat_vprintf(buf, sizeof(buf), fmt, ap); - - if (!s1->error_func) { - /* default case: stderr */ - if (s1->output_type == TCC_OUTPUT_PREPROCESS && s1->ppfp == stdout) - /* print a newline during tcc -E */ - printf("\n"), fflush(stdout); - fflush(stdout); /* flush -v output */ - fprintf(stderr, "%s\n", buf); - fflush(stderr); /* print error/warning now (win32) */ - } else { - s1->error_func(s1->error_opaque, buf); - } - if (!is_warning || s1->warn_error) - s1->nb_errors++; -} - -LIBTCCAPI void tcc_set_error_func(TCCState *s, void *error_opaque, - void (*error_func)(void *opaque, const char *msg)) -{ - s->error_opaque = error_opaque; - s->error_func = error_func; -} - -/* error without aborting current compilation */ -PUB_FUNC void tcc_error_noabort(const char *fmt, ...) -{ - TCCState *s1 = tcc_state; - va_list ap; - - va_start(ap, fmt); - error1(s1, 0, fmt, ap); - va_end(ap); -} - -PUB_FUNC void tcc_error(const char *fmt, ...) -{ - TCCState *s1 = tcc_state; - va_list ap; - - va_start(ap, fmt); - error1(s1, 0, fmt, ap); - va_end(ap); - /* better than nothing: in some cases, we accept to handle errors */ - if (s1->error_set_jmp_enabled) { - longjmp(s1->error_jmp_buf, 1); - } else { - /* XXX: eliminate this someday */ - exit(1); - } -} - -PUB_FUNC void tcc_warning(const char *fmt, ...) -{ - TCCState *s1 = tcc_state; - va_list ap; - - if (s1->warn_none) - return; - - va_start(ap, fmt); - error1(s1, 1, fmt, ap); - va_end(ap); -} - -/********************************************************/ -/* I/O layer */ - -ST_FUNC void tcc_open_bf(TCCState *s1, const char *filename, int initlen) -{ - BufferedFile *bf; - int buflen = initlen ? initlen : IO_BUF_SIZE; - - bf = tcc_mallocz(sizeof(BufferedFile) + buflen); - bf->buf_ptr = bf->buffer; - bf->buf_end = bf->buffer + initlen; - bf->buf_end[0] = CH_EOB; /* put eob symbol */ - pstrcpy(bf->filename, sizeof(bf->filename), filename); - bf->true_filename = bf->filename; - bf->line_num = 1; - bf->ifdef_stack_ptr = s1->ifdef_stack_ptr; - bf->fd = -1; - bf->prev = file; - file = bf; - tok_flags = TOK_FLAG_BOL | TOK_FLAG_BOF; -} - -ST_FUNC void tcc_close(void) -{ - BufferedFile *bf = file; - if (bf->fd > 0) { - close(bf->fd); - total_lines += bf->line_num; - } - if (bf->true_filename != bf->filename) - tcc_free(bf->true_filename); - file = bf->prev; - tcc_free(bf); -} - -ST_FUNC int tcc_open(TCCState *s1, const char *filename) -{ - int fd; - if (strcmp(filename, "-") == 0) - fd = 0, filename = ""; - else - fd = open(filename, O_RDONLY | O_BINARY); - if ((s1->verbose == 2 && fd >= 0) || s1->verbose == 3) - printf("%s %*s%s\n", fd < 0 ? "nf":"->", - (int)(s1->include_stack_ptr - s1->include_stack), "", filename); - if (fd < 0) - return -1; - tcc_open_bf(s1, filename, 0); -#ifdef _WIN32 - normalize_slashes(file->filename); -#endif - file->fd = fd; - return fd; -} - -/* compile the file opened in 'file'. Return non zero if errors. */ -static int tcc_compile(TCCState *s1) -{ - Sym *define_start; - int filetype, is_asm; - - define_start = define_stack; - filetype = s1->filetype; - is_asm = filetype == AFF_TYPE_ASM || filetype == AFF_TYPE_ASMPP; - tccelf_begin_file(s1); - - if (setjmp(s1->error_jmp_buf) == 0) { - s1->nb_errors = 0; - s1->error_set_jmp_enabled = 1; - - preprocess_start(s1, is_asm); - if (s1->output_type == TCC_OUTPUT_PREPROCESS) { - tcc_preprocess(s1); - } else if (is_asm) { -#ifdef CONFIG_TCC_ASM - tcc_assemble(s1, filetype == AFF_TYPE_ASMPP); -#else - tcc_error_noabort("asm not supported"); -#endif - } else { - tccgen_compile(s1); - } - } - s1->error_set_jmp_enabled = 0; - - preprocess_end(s1); - free_inline_functions(s1); - /* reset define stack, but keep -D and built-ins */ - free_defines(define_start); - sym_pop(&global_stack, NULL, 0); - sym_pop(&local_stack, NULL, 0); - tccelf_end_file(s1); - return s1->nb_errors != 0 ? -1 : 0; -} - -LIBTCCAPI int tcc_compile_string(TCCState *s, const char *str) -{ - int len, ret; - - len = strlen(str); - tcc_open_bf(s, "", len); - memcpy(file->buffer, str, len); - ret = tcc_compile(s); - tcc_close(); - return ret; -} - -/* define a preprocessor symbol. A value can also be provided with the '=' operator */ -LIBTCCAPI void tcc_define_symbol(TCCState *s1, const char *sym, const char *value) -{ - int len1, len2; - /* default value */ - if (!value) - value = "1"; - len1 = strlen(sym); - len2 = strlen(value); - - /* init file structure */ - tcc_open_bf(s1, "", len1 + len2 + 1); - memcpy(file->buffer, sym, len1); - file->buffer[len1] = ' '; - memcpy(file->buffer + len1 + 1, value, len2); - - /* parse with define parser */ - next_nomacro(); - parse_define(); - tcc_close(); -} - -/* undefine a preprocessor symbol */ -LIBTCCAPI void tcc_undefine_symbol(TCCState *s1, const char *sym) -{ - TokenSym *ts; - Sym *s; - ts = tok_alloc(sym, strlen(sym)); - s = define_find(ts->tok); - /* undefine symbol by putting an invalid name */ - if (s) - define_undef(s); -} - -/* cleanup all static data used during compilation */ -static void tcc_cleanup(void) -{ - if (NULL == tcc_state) - return; - while (file) - tcc_close(); - tccpp_delete(tcc_state); - tcc_state = NULL; - /* free sym_pools */ - dynarray_reset(&sym_pools, &nb_sym_pools); - /* reset symbol stack */ - sym_free_first = NULL; -} - -LIBTCCAPI TCCState *tcc_new(void) -{ - TCCState *s; - - tcc_cleanup(); - - s = tcc_mallocz(sizeof(TCCState)); - if (!s) - return NULL; - tcc_state = s; - ++nb_states; - - s->alacarte_link = 1; - s->nocommon = 1; - s->warn_implicit_function_declaration = 1; - s->ms_extensions = 1; - -#ifdef CHAR_IS_UNSIGNED - s->char_is_unsigned = 1; -#endif -#ifdef TCC_TARGET_I386 - s->seg_size = 32; -#endif - /* enable this if you want symbols with leading underscore on windows: */ -#if 0 /* def TCC_TARGET_PE */ - s->leading_underscore = 1; -#endif -#ifdef _WIN32 - tcc_set_lib_path_w32(s); -#else - tcc_set_lib_path(s, CONFIG_TCCDIR); -#endif - tccelf_new(s); - tccpp_new(s); - - /* we add dummy defines for some special macros to speed up tests - and to have working defined() */ - define_push(TOK___LINE__, MACRO_OBJ, NULL, NULL); - define_push(TOK___FILE__, MACRO_OBJ, NULL, NULL); - define_push(TOK___DATE__, MACRO_OBJ, NULL, NULL); - define_push(TOK___TIME__, MACRO_OBJ, NULL, NULL); - define_push(TOK___COUNTER__, MACRO_OBJ, NULL, NULL); - { - /* define __TINYC__ 92X */ - char buffer[32]; int a,b,c; - sscanf(TCC_VERSION, "%d.%d.%d", &a, &b, &c); - sprintf(buffer, "%d", a*10000 + b*100 + c); - tcc_define_symbol(s, "__TINYC__", buffer); - } - - /* standard defines */ - tcc_define_symbol(s, "__STDC__", NULL); - tcc_define_symbol(s, "__STDC_VERSION__", "199901L"); - tcc_define_symbol(s, "__STDC_HOSTED__", NULL); - - /* target defines */ -#if defined(TCC_TARGET_I386) - tcc_define_symbol(s, "__i386__", NULL); - tcc_define_symbol(s, "__i386", NULL); - tcc_define_symbol(s, "i386", NULL); -#elif defined(TCC_TARGET_X86_64) - tcc_define_symbol(s, "__x86_64__", NULL); -#elif defined(TCC_TARGET_ARM) - tcc_define_symbol(s, "__ARM_ARCH_4__", NULL); - tcc_define_symbol(s, "__arm_elf__", NULL); - tcc_define_symbol(s, "__arm_elf", NULL); - tcc_define_symbol(s, "arm_elf", NULL); - tcc_define_symbol(s, "__arm__", NULL); - tcc_define_symbol(s, "__arm", NULL); - tcc_define_symbol(s, "arm", NULL); - tcc_define_symbol(s, "__APCS_32__", NULL); - tcc_define_symbol(s, "__ARMEL__", NULL); -#if defined(TCC_ARM_EABI) - tcc_define_symbol(s, "__ARM_EABI__", NULL); -#endif -#if defined(TCC_ARM_HARDFLOAT) - s->float_abi = ARM_HARD_FLOAT; - tcc_define_symbol(s, "__ARM_PCS_VFP", NULL); -#else - s->float_abi = ARM_SOFTFP_FLOAT; -#endif -#elif defined(TCC_TARGET_ARM64) - tcc_define_symbol(s, "__aarch64__", NULL); -#elif defined TCC_TARGET_C67 - tcc_define_symbol(s, "__C67__", NULL); -#endif - -#ifdef TCC_TARGET_PE - tcc_define_symbol(s, "_WIN32", NULL); -# ifdef TCC_TARGET_X86_64 - tcc_define_symbol(s, "_WIN64", NULL); -# endif -#else - tcc_define_symbol(s, "__unix__", NULL); - tcc_define_symbol(s, "__unix", NULL); - tcc_define_symbol(s, "unix", NULL); -# if defined(__linux__) - tcc_define_symbol(s, "__linux__", NULL); - tcc_define_symbol(s, "__linux", NULL); -# endif -# if defined(__FreeBSD__) - tcc_define_symbol(s, "__FreeBSD__", "__FreeBSD__"); - /* No 'Thread Storage Local' on FreeBSD with tcc */ - tcc_define_symbol(s, "__NO_TLS", NULL); -# endif -# if defined(__FreeBSD_kernel__) - tcc_define_symbol(s, "__FreeBSD_kernel__", NULL); -# endif -# if defined(__NetBSD__) - tcc_define_symbol(s, "__NetBSD__", "__NetBSD__"); -# endif -# if defined(__OpenBSD__) - tcc_define_symbol(s, "__OpenBSD__", "__OpenBSD__"); -# endif -#endif - - /* TinyCC & gcc defines */ -#if PTR_SIZE == 4 - /* 32bit systems. */ - tcc_define_symbol(s, "__SIZE_TYPE__", "unsigned int"); - tcc_define_symbol(s, "__PTRDIFF_TYPE__", "int"); - tcc_define_symbol(s, "__ILP32__", NULL); -#elif LONG_SIZE == 4 - /* 64bit Windows. */ - tcc_define_symbol(s, "__SIZE_TYPE__", "unsigned long long"); - tcc_define_symbol(s, "__PTRDIFF_TYPE__", "long long"); - tcc_define_symbol(s, "__LLP64__", NULL); -#else - /* Other 64bit systems. */ - tcc_define_symbol(s, "__SIZE_TYPE__", "unsigned long"); - tcc_define_symbol(s, "__PTRDIFF_TYPE__", "long"); - tcc_define_symbol(s, "__LP64__", NULL); -#endif - -#ifdef TCC_TARGET_PE - tcc_define_symbol(s, "__WCHAR_TYPE__", "unsigned short"); - tcc_define_symbol(s, "__WINT_TYPE__", "unsigned short"); -#else - tcc_define_symbol(s, "__WCHAR_TYPE__", "int"); - /* wint_t is unsigned int by default, but (signed) int on BSDs - and unsigned short on windows. Other OSes might have still - other conventions, sigh. */ -# if defined(__FreeBSD__) || defined (__FreeBSD_kernel__) \ - || defined(__NetBSD__) || defined(__OpenBSD__) - tcc_define_symbol(s, "__WINT_TYPE__", "int"); -# ifdef __FreeBSD__ - /* define __GNUC__ to have some useful stuff from sys/cdefs.h - that are unconditionally used in FreeBSDs other system headers :/ */ - tcc_define_symbol(s, "__GNUC__", "2"); - tcc_define_symbol(s, "__GNUC_MINOR__", "7"); - tcc_define_symbol(s, "__builtin_alloca", "alloca"); -# endif -# else - tcc_define_symbol(s, "__WINT_TYPE__", "unsigned int"); - /* glibc defines */ - tcc_define_symbol(s, "__REDIRECT(name, proto, alias)", - "name proto __asm__ (#alias)"); - tcc_define_symbol(s, "__REDIRECT_NTH(name, proto, alias)", - "name proto __asm__ (#alias) __THROW"); -# endif -# if defined(TCC_MUSL) - tcc_define_symbol(s, "__DEFINED_va_list", ""); - tcc_define_symbol(s, "__DEFINED___isoc_va_list", ""); - tcc_define_symbol(s, "__isoc_va_list", "void *"); -# endif /* TCC_MUSL */ - /* Some GCC builtins that are simple to express as macros. */ - tcc_define_symbol(s, "__builtin_extract_return_addr(x)", "x"); -#endif /* ndef TCC_TARGET_PE */ - return s; -} - -LIBTCCAPI void tcc_delete(TCCState *s1) -{ - tcc_cleanup(); - - /* free sections */ - tccelf_delete(s1); - - /* free library paths */ - dynarray_reset(&s1->library_paths, &s1->nb_library_paths); - dynarray_reset(&s1->crt_paths, &s1->nb_crt_paths); - - /* free include paths */ - dynarray_reset(&s1->cached_includes, &s1->nb_cached_includes); - dynarray_reset(&s1->include_paths, &s1->nb_include_paths); - dynarray_reset(&s1->sysinclude_paths, &s1->nb_sysinclude_paths); - dynarray_reset(&s1->cmd_include_files, &s1->nb_cmd_include_files); - - tcc_free(s1->tcc_lib_path); - tcc_free(s1->soname); - tcc_free(s1->rpath); - tcc_free(s1->init_symbol); - tcc_free(s1->fini_symbol); - tcc_free(s1->outfile); - tcc_free(s1->deps_outfile); - dynarray_reset(&s1->files, &s1->nb_files); - dynarray_reset(&s1->target_deps, &s1->nb_target_deps); - dynarray_reset(&s1->pragma_libs, &s1->nb_pragma_libs); - dynarray_reset(&s1->argv, &s1->argc); - -#ifdef TCC_IS_NATIVE - /* free runtime memory */ - tcc_run_free(s1); -#endif - - tcc_free(s1); - if (0 == --nb_states) - tcc_memcheck(); -} - -LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type) -{ - s->output_type = output_type; - - /* always elf for objects */ - if (output_type == TCC_OUTPUT_OBJ) - s->output_format = TCC_OUTPUT_FORMAT_ELF; - - if (s->char_is_unsigned) - tcc_define_symbol(s, "__CHAR_UNSIGNED__", NULL); - - if (!s->nostdinc) { - /* default include paths */ - /* -isystem paths have already been handled */ - tcc_add_sysinclude_path(s, CONFIG_TCC_SYSINCLUDEPATHS); - } - -#ifdef CONFIG_TCC_BCHECK - if (s->do_bounds_check) { - /* if bound checking, then add corresponding sections */ - tccelf_bounds_new(s); - /* define symbol */ - tcc_define_symbol(s, "__BOUNDS_CHECKING_ON", NULL); - } -#endif - if (s->do_debug) { - /* add debug sections */ - tccelf_stab_new(s); - } - - tcc_add_library_path(s, CONFIG_TCC_LIBPATHS); - -#ifdef TCC_TARGET_PE -# ifdef _WIN32 - if (!s->nostdlib && output_type != TCC_OUTPUT_OBJ) - tcc_add_systemdir(s); -# endif -#else - /* paths for crt objects */ - tcc_split_path(s, &s->crt_paths, &s->nb_crt_paths, CONFIG_TCC_CRTPREFIX); - /* add libc crt1/crti objects */ - if ((output_type == TCC_OUTPUT_EXE || output_type == TCC_OUTPUT_DLL) && - !s->nostdlib) { - if (output_type != TCC_OUTPUT_DLL) - tcc_add_crt(s, "crt1.o"); - tcc_add_crt(s, "crti.o"); - } -#endif - return 0; -} - -LIBTCCAPI int tcc_add_include_path(TCCState *s, const char *pathname) -{ - tcc_split_path(s, &s->include_paths, &s->nb_include_paths, pathname); - return 0; -} - -LIBTCCAPI int tcc_add_sysinclude_path(TCCState *s, const char *pathname) -{ - tcc_split_path(s, &s->sysinclude_paths, &s->nb_sysinclude_paths, pathname); - return 0; -} - -ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags) -{ - int ret; - - /* open the file */ - ret = tcc_open(s1, filename); - if (ret < 0) { - if (flags & AFF_PRINT_ERROR) - tcc_error_noabort("file '%s' not found", filename); - return ret; - } - - /* update target deps */ - dynarray_add(&s1->target_deps, &s1->nb_target_deps, - tcc_strdup(filename)); - - if (flags & AFF_TYPE_BIN) { - ElfW(Ehdr) ehdr; - int fd, obj_type; - - fd = file->fd; - obj_type = tcc_object_type(fd, &ehdr); - lseek(fd, 0, SEEK_SET); - -#ifdef TCC_TARGET_MACHO - if (0 == obj_type && 0 == strcmp(tcc_fileextension(filename), ".dylib")) - obj_type = AFF_BINTYPE_DYN; -#endif - - switch (obj_type) { - case AFF_BINTYPE_REL: - ret = tcc_load_object_file(s1, fd, 0); - break; -#ifndef TCC_TARGET_PE - case AFF_BINTYPE_DYN: - if (s1->output_type == TCC_OUTPUT_MEMORY) { - ret = 0; -#ifdef TCC_IS_NATIVE - if (NULL == dlopen(filename, RTLD_GLOBAL | RTLD_LAZY)) - ret = -1; -#endif - } else { - ret = tcc_load_dll(s1, fd, filename, - (flags & AFF_REFERENCED_DLL) != 0); - } - break; -#endif - case AFF_BINTYPE_AR: - ret = tcc_load_archive(s1, fd); - break; -#ifdef TCC_TARGET_COFF - case AFF_BINTYPE_C67: - ret = tcc_load_coff(s1, fd); - break; -#endif - default: -#ifdef TCC_TARGET_PE - ret = pe_load_file(s1, filename, fd); -#else - /* as GNU ld, consider it is an ld script if not recognized */ - ret = tcc_load_ldscript(s1); -#endif - if (ret < 0) - tcc_error_noabort("unrecognized file type"); - break; - } - } else { - ret = tcc_compile(s1); - } - tcc_close(); - return ret; -} - -LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename) -{ - int filetype = s->filetype; - int flags = AFF_PRINT_ERROR; - if (filetype == 0) { - /* use a file extension to detect a filetype */ - const char *ext = tcc_fileextension(filename); - if (ext[0]) { - ext++; - if (!strcmp(ext, "S")) - filetype = AFF_TYPE_ASMPP; - else if (!strcmp(ext, "s")) - filetype = AFF_TYPE_ASM; - else if (!PATHCMP(ext, "c") || !PATHCMP(ext, "i")) - filetype = AFF_TYPE_C; - else - flags |= AFF_TYPE_BIN; - } else { - filetype = AFF_TYPE_C; - } - s->filetype = filetype; - } - return tcc_add_file_internal(s, filename, flags); -} - -LIBTCCAPI int tcc_add_library_path(TCCState *s, const char *pathname) -{ - tcc_split_path(s, &s->library_paths, &s->nb_library_paths, pathname); - return 0; -} - -static int tcc_add_library_internal(TCCState *s, const char *fmt, - const char *filename, int flags, char **paths, int nb_paths) -{ - char buf[1024]; - int i; - - for(i = 0; i < nb_paths; i++) { - snprintf(buf, sizeof(buf), fmt, paths[i], filename); - if (tcc_add_file_internal(s, buf, flags | AFF_TYPE_BIN) == 0) - return 0; - } - return -1; -} - -/* find and load a dll. Return non zero if not found */ -/* XXX: add '-rpath' option support ? */ -ST_FUNC int tcc_add_dll(TCCState *s, const char *filename, int flags) -{ - return tcc_add_library_internal(s, "%s/%s", filename, flags, - s->library_paths, s->nb_library_paths); -} - -ST_FUNC int tcc_add_crt(TCCState *s, const char *filename) -{ - if (-1 == tcc_add_library_internal(s, "%s/%s", - filename, 0, s->crt_paths, s->nb_crt_paths)) - tcc_error_noabort("file '%s' not found", filename); - return 0; -} - -/* the library name is the same as the argument of the '-l' option */ -LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname) -{ -#if defined TCC_TARGET_PE - const char *libs[] = { "%s/%s.def", "%s/lib%s.def", "%s/%s.dll", "%s/lib%s.dll", "%s/lib%s.a", NULL }; - const char **pp = s->static_link ? libs + 4 : libs; -#elif defined TCC_TARGET_MACHO - const char *libs[] = { "%s/lib%s.dylib", "%s/lib%s.a", NULL }; - const char **pp = s->static_link ? libs + 1 : libs; -#else - const char *libs[] = { "%s/lib%s.so", "%s/lib%s.a", NULL }; - const char **pp = s->static_link ? libs + 1 : libs; -#endif - while (*pp) { - if (0 == tcc_add_library_internal(s, *pp, - libraryname, 0, s->library_paths, s->nb_library_paths)) - return 0; - ++pp; - } - return -1; -} - -PUB_FUNC int tcc_add_library_err(TCCState *s, const char *libname) -{ - int ret = tcc_add_library(s, libname); - if (ret < 0) - tcc_error_noabort("library '%s' not found", libname); - return ret; -} - -/* handle #pragma comment(lib,) */ -ST_FUNC void tcc_add_pragma_libs(TCCState *s1) -{ - int i; - for (i = 0; i < s1->nb_pragma_libs; i++) - tcc_add_library_err(s1, s1->pragma_libs[i]); -} - -LIBTCCAPI int tcc_add_symbol(TCCState *s, const char *name, const void *val) -{ -#ifdef TCC_TARGET_PE - /* On x86_64 'val' might not be reachable with a 32bit offset. - So it is handled here as if it were in a DLL. */ - pe_putimport(s, 0, name, (uintptr_t)val); -#else - set_elf_sym(symtab_section, (uintptr_t)val, 0, - ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, - SHN_ABS, name); -#endif - return 0; -} - -LIBTCCAPI void tcc_set_lib_path(TCCState *s, const char *path) -{ - tcc_free(s->tcc_lib_path); - s->tcc_lib_path = tcc_strdup(path); -} - -#define WD_ALL 0x0001 /* warning is activated when using -Wall */ -#define FD_INVERT 0x0002 /* invert value before storing */ - -typedef struct FlagDef { - uint16_t offset; - uint16_t flags; - const char *name; -} FlagDef; - -static int no_flag(const char **pp) -{ - const char *p = *pp; - if (*p != 'n' || *++p != 'o' || *++p != '-') - return 0; - *pp = p + 1; - return 1; -} - -ST_FUNC int set_flag(TCCState *s, const FlagDef *flags, const char *name) -{ - int value, ret; - const FlagDef *p; - const char *r; - - value = 1; - r = name; - if (no_flag(&r)) - value = 0; - - for (ret = -1, p = flags; p->name; ++p) { - if (ret) { - if (strcmp(r, p->name)) - continue; - } else { - if (0 == (p->flags & WD_ALL)) - continue; - } - if (p->offset) { - *(int*)((char *)s + p->offset) = - p->flags & FD_INVERT ? !value : value; - if (ret) - return 0; - } else { - ret = 0; - } - } - return ret; -} - -static int strstart(const char *val, const char **str) -{ - const char *p, *q; - p = *str; - q = val; - while (*q) { - if (*p != *q) - return 0; - p++; - q++; - } - *str = p; - return 1; -} - -/* Like strstart, but automatically takes into account that ld options can - * - * - start with double or single dash (e.g. '--soname' or '-soname') - * - arguments can be given as separate or after '=' (e.g. '-Wl,-soname,x.so' - * or '-Wl,-soname=x.so') - * - * you provide `val` always in 'option[=]' form (no leading -) - */ -static int link_option(const char *str, const char *val, const char **ptr) -{ - const char *p, *q; - int ret; - - /* there should be 1 or 2 dashes */ - if (*str++ != '-') - return 0; - if (*str == '-') - str++; - - /* then str & val should match (potentially up to '=') */ - p = str; - q = val; - - ret = 1; - if (q[0] == '?') { - ++q; - if (no_flag(&p)) - ret = -1; - } - - while (*q != '\0' && *q != '=') { - if (*p != *q) - return 0; - p++; - q++; - } - - /* '=' near eos means ',' or '=' is ok */ - if (*q == '=') { - if (*p == 0) - *ptr = p; - if (*p != ',' && *p != '=') - return 0; - p++; - } else if (*p) { - return 0; - } - *ptr = p; - return ret; -} - -static const char *skip_linker_arg(const char **str) -{ - const char *s1 = *str; - const char *s2 = strchr(s1, ','); - *str = s2 ? s2++ : (s2 = s1 + strlen(s1)); - return s2; -} - -static void copy_linker_arg(char **pp, const char *s, int sep) -{ - const char *q = s; - char *p = *pp; - int l = 0; - if (p && sep) - p[l = strlen(p)] = sep, ++l; - skip_linker_arg(&q); - pstrncpy(l + (*pp = tcc_realloc(p, q - s + l + 1)), s, q - s); -} - -/* set linker options */ -static int tcc_set_linker(TCCState *s, const char *option) -{ - while (*option) { - - const char *p = NULL; - char *end = NULL; - int ignoring = 0; - int ret; - - if (link_option(option, "Bsymbolic", &p)) { - s->symbolic = 1; - } else if (link_option(option, "nostdlib", &p)) { - s->nostdlib = 1; - } else if (link_option(option, "fini=", &p)) { - copy_linker_arg(&s->fini_symbol, p, 0); - ignoring = 1; - } else if (link_option(option, "image-base=", &p) - || link_option(option, "Ttext=", &p)) { - s->text_addr = strtoull(p, &end, 16); - s->has_text_addr = 1; - } else if (link_option(option, "init=", &p)) { - copy_linker_arg(&s->init_symbol, p, 0); - ignoring = 1; - } else if (link_option(option, "oformat=", &p)) { -#if defined(TCC_TARGET_PE) - if (strstart("pe-", &p)) { -#elif PTR_SIZE == 8 - if (strstart("elf64-", &p)) { -#else - if (strstart("elf32-", &p)) { -#endif - s->output_format = TCC_OUTPUT_FORMAT_ELF; - } else if (!strcmp(p, "binary")) { - s->output_format = TCC_OUTPUT_FORMAT_BINARY; -#ifdef TCC_TARGET_COFF - } else if (!strcmp(p, "coff")) { - s->output_format = TCC_OUTPUT_FORMAT_COFF; -#endif - } else - goto err; - - } else if (link_option(option, "as-needed", &p)) { - ignoring = 1; - } else if (link_option(option, "O", &p)) { - ignoring = 1; - } else if (link_option(option, "export-all-symbols", &p)) { - s->rdynamic = 1; - } else if (link_option(option, "rpath=", &p)) { - copy_linker_arg(&s->rpath, p, ':'); - } else if (link_option(option, "enable-new-dtags", &p)) { - s->enable_new_dtags = 1; - } else if (link_option(option, "section-alignment=", &p)) { - s->section_align = strtoul(p, &end, 16); - } else if (link_option(option, "soname=", &p)) { - copy_linker_arg(&s->soname, p, 0); -#ifdef TCC_TARGET_PE - } else if (link_option(option, "large-address-aware", &p)) { - s->pe_characteristics |= 0x20; - } else if (link_option(option, "file-alignment=", &p)) { - s->pe_file_align = strtoul(p, &end, 16); - } else if (link_option(option, "stack=", &p)) { - s->pe_stack_size = strtoul(p, &end, 10); - } else if (link_option(option, "subsystem=", &p)) { -#if defined(TCC_TARGET_I386) || defined(TCC_TARGET_X86_64) - if (!strcmp(p, "native")) { - s->pe_subsystem = 1; - } else if (!strcmp(p, "console")) { - s->pe_subsystem = 3; - } else if (!strcmp(p, "gui") || !strcmp(p, "windows")) { - s->pe_subsystem = 2; - } else if (!strcmp(p, "posix")) { - s->pe_subsystem = 7; - } else if (!strcmp(p, "efiapp")) { - s->pe_subsystem = 10; - } else if (!strcmp(p, "efiboot")) { - s->pe_subsystem = 11; - } else if (!strcmp(p, "efiruntime")) { - s->pe_subsystem = 12; - } else if (!strcmp(p, "efirom")) { - s->pe_subsystem = 13; -#elif defined(TCC_TARGET_ARM) - if (!strcmp(p, "wince")) { - s->pe_subsystem = 9; -#endif - } else - goto err; -#endif - } else if (ret = link_option(option, "?whole-archive", &p), ret) { - s->alacarte_link = ret < 0; - } else if (p) { - return 0; - } else { - err: - tcc_error("unsupported linker option '%s'", option); - } - - if (ignoring && s->warn_unsupported) - tcc_warning("unsupported linker option '%s'", option); - - option = skip_linker_arg(&p); - } - return 1; -} - -typedef struct TCCOption { - const char *name; - uint16_t index; - uint16_t flags; -} TCCOption; - -enum { - TCC_OPTION_HELP, - TCC_OPTION_HELP2, - TCC_OPTION_v, - TCC_OPTION_I, - TCC_OPTION_D, - TCC_OPTION_U, - TCC_OPTION_P, - TCC_OPTION_L, - TCC_OPTION_B, - TCC_OPTION_l, - TCC_OPTION_bench, - TCC_OPTION_bt, - TCC_OPTION_b, - TCC_OPTION_g, - TCC_OPTION_c, - TCC_OPTION_dumpversion, - TCC_OPTION_d, - TCC_OPTION_static, - TCC_OPTION_std, - TCC_OPTION_shared, - TCC_OPTION_soname, - TCC_OPTION_o, - TCC_OPTION_r, - TCC_OPTION_s, - TCC_OPTION_traditional, - TCC_OPTION_Wl, - TCC_OPTION_Wp, - TCC_OPTION_W, - TCC_OPTION_O, - TCC_OPTION_mfloat_abi, - TCC_OPTION_m, - TCC_OPTION_f, - TCC_OPTION_isystem, - TCC_OPTION_iwithprefix, - TCC_OPTION_include, - TCC_OPTION_nostdinc, - TCC_OPTION_nostdlib, - TCC_OPTION_print_search_dirs, - TCC_OPTION_rdynamic, - TCC_OPTION_param, - TCC_OPTION_pedantic, - TCC_OPTION_pthread, - TCC_OPTION_run, - TCC_OPTION_w, - TCC_OPTION_pipe, - TCC_OPTION_E, - TCC_OPTION_MD, - TCC_OPTION_MF, - TCC_OPTION_x, - TCC_OPTION_ar, - TCC_OPTION_impdef -}; - -#define TCC_OPTION_HAS_ARG 0x0001 -#define TCC_OPTION_NOSEP 0x0002 /* cannot have space before option and arg */ - -static const TCCOption tcc_options[] = { - { "h", TCC_OPTION_HELP, 0 }, - { "-help", TCC_OPTION_HELP, 0 }, - { "?", TCC_OPTION_HELP, 0 }, - { "hh", TCC_OPTION_HELP2, 0 }, - { "v", TCC_OPTION_v, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, - { "I", TCC_OPTION_I, TCC_OPTION_HAS_ARG }, - { "D", TCC_OPTION_D, TCC_OPTION_HAS_ARG }, - { "U", TCC_OPTION_U, TCC_OPTION_HAS_ARG }, - { "P", TCC_OPTION_P, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, - { "L", TCC_OPTION_L, TCC_OPTION_HAS_ARG }, - { "B", TCC_OPTION_B, TCC_OPTION_HAS_ARG }, - { "l", TCC_OPTION_l, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, - { "bench", TCC_OPTION_bench, 0 }, -#ifdef CONFIG_TCC_BACKTRACE - { "bt", TCC_OPTION_bt, TCC_OPTION_HAS_ARG }, -#endif -#ifdef CONFIG_TCC_BCHECK - { "b", TCC_OPTION_b, 0 }, -#endif - { "g", TCC_OPTION_g, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, - { "c", TCC_OPTION_c, 0 }, - { "dumpversion", TCC_OPTION_dumpversion, 0}, - { "d", TCC_OPTION_d, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, - { "static", TCC_OPTION_static, 0 }, - { "std", TCC_OPTION_std, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, - { "shared", TCC_OPTION_shared, 0 }, - { "soname", TCC_OPTION_soname, TCC_OPTION_HAS_ARG }, - { "o", TCC_OPTION_o, TCC_OPTION_HAS_ARG }, - { "-param", TCC_OPTION_param, TCC_OPTION_HAS_ARG }, - { "pedantic", TCC_OPTION_pedantic, 0}, - { "pthread", TCC_OPTION_pthread, 0}, - { "run", TCC_OPTION_run, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, - { "rdynamic", TCC_OPTION_rdynamic, 0 }, - { "r", TCC_OPTION_r, 0 }, - { "s", TCC_OPTION_s, 0 }, - { "traditional", TCC_OPTION_traditional, 0 }, - { "Wl,", TCC_OPTION_Wl, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, - { "Wp,", TCC_OPTION_Wp, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, - { "W", TCC_OPTION_W, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, - { "O", TCC_OPTION_O, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, -#ifdef TCC_TARGET_ARM - { "mfloat-abi", TCC_OPTION_mfloat_abi, TCC_OPTION_HAS_ARG }, -#endif - { "m", TCC_OPTION_m, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, - { "f", TCC_OPTION_f, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, - { "isystem", TCC_OPTION_isystem, TCC_OPTION_HAS_ARG }, - { "include", TCC_OPTION_include, TCC_OPTION_HAS_ARG }, - { "nostdinc", TCC_OPTION_nostdinc, 0 }, - { "nostdlib", TCC_OPTION_nostdlib, 0 }, - { "print-search-dirs", TCC_OPTION_print_search_dirs, 0 }, - { "w", TCC_OPTION_w, 0 }, - { "pipe", TCC_OPTION_pipe, 0}, - { "E", TCC_OPTION_E, 0}, - { "MD", TCC_OPTION_MD, 0}, - { "MF", TCC_OPTION_MF, TCC_OPTION_HAS_ARG }, - { "x", TCC_OPTION_x, TCC_OPTION_HAS_ARG }, - { "ar", TCC_OPTION_ar, 0}, -#ifdef TCC_TARGET_PE - { "impdef", TCC_OPTION_impdef, 0}, -#endif - { NULL, 0, 0 }, -}; - -static const FlagDef options_W[] = { - { 0, 0, "all" }, - { offsetof(TCCState, warn_unsupported), 0, "unsupported" }, - { offsetof(TCCState, warn_write_strings), 0, "write-strings" }, - { offsetof(TCCState, warn_error), 0, "error" }, - { offsetof(TCCState, warn_gcc_compat), 0, "gcc-compat" }, - { offsetof(TCCState, warn_implicit_function_declaration), WD_ALL, - "implicit-function-declaration" }, - { 0, 0, NULL } -}; - -static const FlagDef options_f[] = { - { offsetof(TCCState, char_is_unsigned), 0, "unsigned-char" }, - { offsetof(TCCState, char_is_unsigned), FD_INVERT, "signed-char" }, - { offsetof(TCCState, nocommon), FD_INVERT, "common" }, - { offsetof(TCCState, leading_underscore), 0, "leading-underscore" }, - { offsetof(TCCState, ms_extensions), 0, "ms-extensions" }, - { offsetof(TCCState, dollars_in_identifiers), 0, "dollars-in-identifiers" }, - { 0, 0, NULL } -}; - -static const FlagDef options_m[] = { - { offsetof(TCCState, ms_bitfields), 0, "ms-bitfields" }, -#ifdef TCC_TARGET_X86_64 - { offsetof(TCCState, nosse), FD_INVERT, "sse" }, -#endif - { 0, 0, NULL } -}; - -static void parse_option_D(TCCState *s1, const char *optarg) -{ - char *sym = tcc_strdup(optarg); - char *value = strchr(sym, '='); - if (value) - *value++ = '\0'; - tcc_define_symbol(s1, sym, value); - tcc_free(sym); -} - -static void args_parser_add_file(TCCState *s, const char* filename, int filetype) -{ - struct filespec *f = tcc_malloc(sizeof *f + strlen(filename)); - f->type = filetype; - f->alacarte = s->alacarte_link; - strcpy(f->name, filename); - dynarray_add(&s->files, &s->nb_files, f); -} - -static int args_parser_make_argv(const char *r, int *argc, char ***argv) -{ - int ret = 0, q, c; - CString str; - for(;;) { - while (c = (unsigned char)*r, c && c <= ' ') - ++r; - if (c == 0) - break; - q = 0; - cstr_new(&str); - while (c = (unsigned char)*r, c) { - ++r; - if (c == '\\' && (*r == '"' || *r == '\\')) { - c = *r++; - } else if (c == '"') { - q = !q; - continue; - } else if (q == 0 && c <= ' ') { - break; - } - cstr_ccat(&str, c); - } - cstr_ccat(&str, 0); - //printf("<%s>\n", str.data), fflush(stdout); - dynarray_add(argv, argc, tcc_strdup(str.data)); - cstr_free(&str); - ++ret; - } - return ret; -} - -/* read list file */ -static void args_parser_listfile(TCCState *s, - const char *filename, int optind, int *pargc, char ***pargv) -{ - int fd, i; - size_t len; - char *p; - int argc = 0; - char **argv = NULL; - - fd = open(filename, O_RDONLY | O_BINARY); - if (fd < 0) - tcc_error("listfile '%s' not found", filename); - - len = lseek(fd, 0, SEEK_END); - p = tcc_malloc(len + 1), p[len] = 0; - lseek(fd, 0, SEEK_SET), read(fd, p, len), close(fd); - - for (i = 0; i < *pargc; ++i) - if (i == optind) - args_parser_make_argv(p, &argc, &argv); - else - dynarray_add(&argv, &argc, tcc_strdup((*pargv)[i])); - - tcc_free(p); - dynarray_reset(&s->argv, &s->argc); - *pargc = s->argc = argc, *pargv = s->argv = argv; -} - -PUB_FUNC int tcc_parse_args(TCCState *s, int *pargc, char ***pargv, int optind) -{ - const TCCOption *popt; - const char *optarg, *r; - const char *run = NULL; - int last_o = -1; - int x; - CString linker_arg; /* collect -Wl options */ - int tool = 0, arg_start = 0, noaction = optind; - char **argv = *pargv; - int argc = *pargc; - - cstr_new(&linker_arg); - - while (optind < argc) { - r = argv[optind]; - if (r[0] == '@' && r[1] != '\0') { - args_parser_listfile(s, r + 1, optind, &argc, &argv); - continue; - } - optind++; - if (tool) { - if (r[0] == '-' && r[1] == 'v' && r[2] == 0) - ++s->verbose; - continue; - } -reparse: - if (r[0] != '-' || r[1] == '\0') { - if (r[0] != '@') /* allow "tcc file(s) -run @ args ..." */ - args_parser_add_file(s, r, s->filetype); - if (run) { - tcc_set_options(s, run); - arg_start = optind - 1; - break; - } - continue; - } - - /* find option in table */ - for(popt = tcc_options; ; ++popt) { - const char *p1 = popt->name; - const char *r1 = r + 1; - if (p1 == NULL) - tcc_error("invalid option -- '%s'", r); - if (!strstart(p1, &r1)) - continue; - optarg = r1; - if (popt->flags & TCC_OPTION_HAS_ARG) { - if (*r1 == '\0' && !(popt->flags & TCC_OPTION_NOSEP)) { - if (optind >= argc) - arg_err: - tcc_error("argument to '%s' is missing", r); - optarg = argv[optind++]; - } - } else if (*r1 != '\0') - continue; - break; - } - - switch(popt->index) { - case TCC_OPTION_HELP: - return OPT_HELP; - case TCC_OPTION_HELP2: - return OPT_HELP2; - case TCC_OPTION_I: - tcc_add_include_path(s, optarg); - break; - case TCC_OPTION_D: - parse_option_D(s, optarg); - break; - case TCC_OPTION_U: - tcc_undefine_symbol(s, optarg); - break; - case TCC_OPTION_L: - tcc_add_library_path(s, optarg); - break; - case TCC_OPTION_B: - /* set tcc utilities path (mainly for tcc development) */ - tcc_set_lib_path(s, optarg); - break; - case TCC_OPTION_l: - args_parser_add_file(s, optarg, AFF_TYPE_LIB); - s->nb_libraries++; - break; - case TCC_OPTION_pthread: - parse_option_D(s, "_REENTRANT"); - s->option_pthread = 1; - break; - case TCC_OPTION_bench: - s->do_bench = 1; - break; -#ifdef CONFIG_TCC_BACKTRACE - case TCC_OPTION_bt: - tcc_set_num_callers(atoi(optarg)); - break; -#endif -#ifdef CONFIG_TCC_BCHECK - case TCC_OPTION_b: - s->do_bounds_check = 1; - s->do_debug = 1; - break; -#endif - case TCC_OPTION_g: - s->do_debug = 1; - break; - case TCC_OPTION_c: - x = TCC_OUTPUT_OBJ; - set_output_type: - if (s->output_type) - tcc_warning("-%s: overriding compiler action already specified", popt->name); - s->output_type = x; - break; - case TCC_OPTION_d: - if (*optarg == 'D') - s->dflag = 3; - else if (*optarg == 'M') - s->dflag = 7; - else if (*optarg == 't') - s->dflag = 16; - else if (isnum(*optarg)) - g_debug = atoi(optarg); - else - goto unsupported_option; - break; - case TCC_OPTION_static: - s->static_link = 1; - break; - case TCC_OPTION_std: - /* silently ignore, a current purpose: - allow to use a tcc as a reference compiler for "make test" */ - break; - case TCC_OPTION_shared: - x = TCC_OUTPUT_DLL; - goto set_output_type; - case TCC_OPTION_soname: - s->soname = tcc_strdup(optarg); - break; - case TCC_OPTION_o: - if (s->outfile) { - tcc_warning("multiple -o option"); - tcc_free(s->outfile); - } - s->outfile = tcc_strdup(optarg); - break; - case TCC_OPTION_r: - /* generate a .o merging several output files */ - s->option_r = 1; - x = TCC_OUTPUT_OBJ; - goto set_output_type; - case TCC_OPTION_isystem: - tcc_add_sysinclude_path(s, optarg); - break; - case TCC_OPTION_include: - dynarray_add(&s->cmd_include_files, - &s->nb_cmd_include_files, tcc_strdup(optarg)); - break; - case TCC_OPTION_nostdinc: - s->nostdinc = 1; - break; - case TCC_OPTION_nostdlib: - s->nostdlib = 1; - break; - case TCC_OPTION_run: -#ifndef TCC_IS_NATIVE - tcc_error("-run is not available in a cross compiler"); -#endif - run = optarg; - x = TCC_OUTPUT_MEMORY; - goto set_output_type; - case TCC_OPTION_v: - do ++s->verbose; while (*optarg++ == 'v'); - ++noaction; - break; - case TCC_OPTION_f: - if (set_flag(s, options_f, optarg) < 0) - goto unsupported_option; - break; -#ifdef TCC_TARGET_ARM - case TCC_OPTION_mfloat_abi: - /* tcc doesn't support soft float yet */ - if (!strcmp(optarg, "softfp")) { - s->float_abi = ARM_SOFTFP_FLOAT; - tcc_undefine_symbol(s, "__ARM_PCS_VFP"); - } else if (!strcmp(optarg, "hard")) - s->float_abi = ARM_HARD_FLOAT; - else - tcc_error("unsupported float abi '%s'", optarg); - break; -#endif - case TCC_OPTION_m: - if (set_flag(s, options_m, optarg) < 0) { - if (x = atoi(optarg), x != 32 && x != 64) - goto unsupported_option; - if (PTR_SIZE != x/8) - return x; - ++noaction; - } - break; - case TCC_OPTION_W: - if (set_flag(s, options_W, optarg) < 0) - goto unsupported_option; - break; - case TCC_OPTION_w: - s->warn_none = 1; - break; - case TCC_OPTION_rdynamic: - s->rdynamic = 1; - break; - case TCC_OPTION_Wl: - if (linker_arg.size) - --linker_arg.size, cstr_ccat(&linker_arg, ','); - cstr_cat(&linker_arg, optarg, 0); - if (tcc_set_linker(s, linker_arg.data)) - cstr_free(&linker_arg); - break; - case TCC_OPTION_Wp: - r = optarg; - goto reparse; - case TCC_OPTION_E: - x = TCC_OUTPUT_PREPROCESS; - goto set_output_type; - case TCC_OPTION_P: - s->Pflag = atoi(optarg) + 1; - break; - case TCC_OPTION_MD: - s->gen_deps = 1; - break; - case TCC_OPTION_MF: - s->deps_outfile = tcc_strdup(optarg); - break; - case TCC_OPTION_dumpversion: - printf ("%s\n", TCC_VERSION); - exit(0); - break; - case TCC_OPTION_x: - if (*optarg == 'c') - s->filetype = AFF_TYPE_C; - else if (*optarg == 'a') - s->filetype = AFF_TYPE_ASMPP; - else if (*optarg == 'n') - s->filetype = AFF_TYPE_NONE; - else - tcc_warning("unsupported language '%s'", optarg); - break; - case TCC_OPTION_O: - last_o = atoi(optarg); - break; - case TCC_OPTION_print_search_dirs: - x = OPT_PRINT_DIRS; - goto extra_action; - case TCC_OPTION_impdef: - x = OPT_IMPDEF; - goto extra_action; - case TCC_OPTION_ar: - x = OPT_AR; - extra_action: - arg_start = optind - 1; - if (arg_start != noaction) - tcc_error("cannot parse %s here", r); - tool = x; - break; - case TCC_OPTION_traditional: - case TCC_OPTION_pedantic: - case TCC_OPTION_pipe: - case TCC_OPTION_s: - /* ignored */ - break; - default: -unsupported_option: - if (s->warn_unsupported) - tcc_warning("unsupported option '%s'", r); - break; - } - } - if (last_o > 0) - tcc_define_symbol(s, "__OPTIMIZE__", NULL); - if (linker_arg.size) { - r = linker_arg.data; - goto arg_err; - } - *pargc = argc - arg_start; - *pargv = argv + arg_start; - if (tool) - return tool; - if (optind != noaction) - return 0; - if (s->verbose == 2) - return OPT_PRINT_DIRS; - if (s->verbose) - return OPT_V; - return OPT_HELP; -} - -LIBTCCAPI void tcc_set_options(TCCState *s, const char *r) -{ - char **argv = NULL; - int argc = 0; - args_parser_make_argv(r, &argc, &argv); - tcc_parse_args(s, &argc, &argv, 0); - dynarray_reset(&argv, &argc); -} - -PUB_FUNC void tcc_print_stats(TCCState *s, unsigned total_time) -{ - if (total_time < 1) - total_time = 1; - if (total_bytes < 1) - total_bytes = 1; - fprintf(stderr, "* %d idents, %d lines, %d bytes\n" - "* %0.3f s, %u lines/s, %0.1f MB/s\n", - tok_ident - TOK_IDENT, total_lines, total_bytes, - (double)total_time/1000, - (unsigned)total_lines*1000/total_time, - (double)total_bytes/1000/total_time); -#ifdef MEM_DEBUG - fprintf(stderr, "* %d bytes memory used\n", mem_max_size); -#endif -} diff --git a/05/tcc-final-old/libtcc.h b/05/tcc-final-old/libtcc.h deleted file mode 100644 index a1b31e3..0000000 --- a/05/tcc-final-old/libtcc.h +++ /dev/null @@ -1,100 +0,0 @@ -#ifndef LIBTCC_H -#define LIBTCC_H - -#ifndef LIBTCCAPI -# define LIBTCCAPI -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -struct TCCState; - -typedef struct TCCState TCCState; - -/* create a new TCC compilation context */ -LIBTCCAPI TCCState *tcc_new(void); - -/* free a TCC compilation context */ -LIBTCCAPI void tcc_delete(TCCState *s); - -/* set CONFIG_TCCDIR at runtime */ -LIBTCCAPI void tcc_set_lib_path(TCCState *s, const char *path); - -/* set error/warning display callback */ -LIBTCCAPI void tcc_set_error_func(TCCState *s, void *error_opaque, - void (*error_func)(void *opaque, const char *msg)); - -/* set options as from command line (multiple supported) */ -LIBTCCAPI void tcc_set_options(TCCState *s, const char *str); - -/*****************************/ -/* preprocessor */ - -/* add include path */ -LIBTCCAPI int tcc_add_include_path(TCCState *s, const char *pathname); - -/* add in system include path */ -LIBTCCAPI int tcc_add_sysinclude_path(TCCState *s, const char *pathname); - -/* define preprocessor symbol 'sym'. Can put optional value */ -LIBTCCAPI void tcc_define_symbol(TCCState *s, const char *sym, const char *value); - -/* undefine preprocess symbol 'sym' */ -LIBTCCAPI void tcc_undefine_symbol(TCCState *s, const char *sym); - -/*****************************/ -/* compiling */ - -/* add a file (C file, dll, object, library, ld script). Return -1 if error. */ -LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename); - -/* compile a string containing a C source. Return -1 if error. */ -LIBTCCAPI int tcc_compile_string(TCCState *s, const char *buf); - -/*****************************/ -/* linking commands */ - -/* set output type. MUST BE CALLED before any compilation */ -LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type); -#define TCC_OUTPUT_MEMORY 1 /* output will be run in memory (default) */ -#define TCC_OUTPUT_EXE 2 /* executable file */ -#define TCC_OUTPUT_DLL 3 /* dynamic library */ -#define TCC_OUTPUT_OBJ 4 /* object file */ -#define TCC_OUTPUT_PREPROCESS 5 /* only preprocess (used internally) */ - -/* equivalent to -Lpath option */ -LIBTCCAPI int tcc_add_library_path(TCCState *s, const char *pathname); - -/* the library name is the same as the argument of the '-l' option */ -LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname); - -/* add a symbol to the compiled program */ -LIBTCCAPI int tcc_add_symbol(TCCState *s, const char *name, const void *val); - -/* output an executable, library or object file. DO NOT call - tcc_relocate() before. */ -LIBTCCAPI int tcc_output_file(TCCState *s, const char *filename); - -/* link and run main() function and return its value. DO NOT call - tcc_relocate() before. */ -LIBTCCAPI int tcc_run(TCCState *s, int argc, char **argv); - -/* do all relocations (needed before using tcc_get_symbol()) */ -LIBTCCAPI int tcc_relocate(TCCState *s1, void *ptr); -/* possible values for 'ptr': - - TCC_RELOCATE_AUTO : Allocate and manage memory internally - - NULL : return required memory size for the step below - - memory address : copy code to memory passed by the caller - returns -1 if error. */ -#define TCC_RELOCATE_AUTO (void*)1 - -/* return symbol value or NULL if not found */ -LIBTCCAPI void *tcc_get_symbol(TCCState *s, const char *name); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/05/tcc-final-old/stab.def b/05/tcc-final-old/stab.def deleted file mode 100644 index 48ea231..0000000 --- a/05/tcc-final-old/stab.def +++ /dev/null @@ -1,234 +0,0 @@ -/* Table of DBX symbol codes for the GNU system. - Copyright (C) 1988, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -/* This contains contribution from Cygnus Support. */ - -/* Global variable. Only the name is significant. - To find the address, look in the corresponding external symbol. */ -__define_stab (N_GSYM, 0x20, "GSYM") - -/* Function name for BSD Fortran. Only the name is significant. - To find the address, look in the corresponding external symbol. */ -__define_stab (N_FNAME, 0x22, "FNAME") - -/* Function name or text-segment variable for C. Value is its address. - Desc is supposedly starting line number, but GCC doesn't set it - and DBX seems not to miss it. */ -__define_stab (N_FUN, 0x24, "FUN") - -/* Data-segment variable with internal linkage. Value is its address. - "Static Sym". */ -__define_stab (N_STSYM, 0x26, "STSYM") - -/* BSS-segment variable with internal linkage. Value is its address. */ -__define_stab (N_LCSYM, 0x28, "LCSYM") - -/* Name of main routine. Only the name is significant. - This is not used in C. */ -__define_stab (N_MAIN, 0x2a, "MAIN") - -/* Global symbol in Pascal. - Supposedly the value is its line number; I'm skeptical. */ -__define_stab (N_PC, 0x30, "PC") - -/* Number of symbols: 0, files,,funcs,lines according to Ultrix V4.0. */ -__define_stab (N_NSYMS, 0x32, "NSYMS") - -/* "No DST map for sym: name, ,0,type,ignored" according to Ultrix V4.0. */ -__define_stab (N_NOMAP, 0x34, "NOMAP") - -/* New stab from Solaris. I don't know what it means, but it - don't seem to contain useful information. */ -__define_stab (N_OBJ, 0x38, "OBJ") - -/* New stab from Solaris. I don't know what it means, but it - don't seem to contain useful information. Possibly related to the - optimization flags used in this module. */ -__define_stab (N_OPT, 0x3c, "OPT") - -/* Register variable. Value is number of register. */ -__define_stab (N_RSYM, 0x40, "RSYM") - -/* Modula-2 compilation unit. Can someone say what info it contains? */ -__define_stab (N_M2C, 0x42, "M2C") - -/* Line number in text segment. Desc is the line number; - value is corresponding address. */ -__define_stab (N_SLINE, 0x44, "SLINE") - -/* Similar, for data segment. */ -__define_stab (N_DSLINE, 0x46, "DSLINE") - -/* Similar, for bss segment. */ -__define_stab (N_BSLINE, 0x48, "BSLINE") - -/* Sun's source-code browser stabs. ?? Don't know what the fields are. - Supposedly the field is "path to associated .cb file". THIS VALUE - OVERLAPS WITH N_BSLINE! */ -__define_stab (N_BROWS, 0x48, "BROWS") - -/* GNU Modula-2 definition module dependency. Value is the modification time - of the definition file. Other is non-zero if it is imported with the - GNU M2 keyword %INITIALIZE. Perhaps N_M2C can be used if there - are enough empty fields? */ -__define_stab(N_DEFD, 0x4a, "DEFD") - -/* THE FOLLOWING TWO STAB VALUES CONFLICT. Happily, one is for Modula-2 - and one is for C++. Still,... */ -/* GNU C++ exception variable. Name is variable name. */ -__define_stab (N_EHDECL, 0x50, "EHDECL") -/* Modula2 info "for imc": name,,0,0,0 according to Ultrix V4.0. */ -__define_stab (N_MOD2, 0x50, "MOD2") - -/* GNU C++ `catch' clause. Value is its address. Desc is nonzero if - this entry is immediately followed by a CAUGHT stab saying what exception - was caught. Multiple CAUGHT stabs means that multiple exceptions - can be caught here. If Desc is 0, it means all exceptions are caught - here. */ -__define_stab (N_CATCH, 0x54, "CATCH") - -/* Structure or union element. Value is offset in the structure. */ -__define_stab (N_SSYM, 0x60, "SSYM") - -/* Name of main source file. - Value is starting text address of the compilation. */ -__define_stab (N_SO, 0x64, "SO") - -/* Automatic variable in the stack. Value is offset from frame pointer. - Also used for type descriptions. */ -__define_stab (N_LSYM, 0x80, "LSYM") - -/* Beginning of an include file. Only Sun uses this. - In an object file, only the name is significant. - The Sun linker puts data into some of the other fields. */ -__define_stab (N_BINCL, 0x82, "BINCL") - -/* Name of sub-source file (#include file). - Value is starting text address of the compilation. */ -__define_stab (N_SOL, 0x84, "SOL") - -/* Parameter variable. Value is offset from argument pointer. - (On most machines the argument pointer is the same as the frame pointer. */ -__define_stab (N_PSYM, 0xa0, "PSYM") - -/* End of an include file. No name. - This and N_BINCL act as brackets around the file's output. - In an object file, there is no significant data in this entry. - The Sun linker puts data into some of the fields. */ -__define_stab (N_EINCL, 0xa2, "EINCL") - -/* Alternate entry point. Value is its address. */ -__define_stab (N_ENTRY, 0xa4, "ENTRY") - -/* Beginning of lexical block. - The desc is the nesting level in lexical blocks. - The value is the address of the start of the text for the block. - The variables declared inside the block *precede* the N_LBRAC symbol. */ -__define_stab (N_LBRAC, 0xc0, "LBRAC") - -/* Place holder for deleted include file. Replaces a N_BINCL and everything - up to the corresponding N_EINCL. The Sun linker generates these when - it finds multiple identical copies of the symbols from an include file. - This appears only in output from the Sun linker. */ -__define_stab (N_EXCL, 0xc2, "EXCL") - -/* Modula-2 scope information. Can someone say what info it contains? */ -__define_stab (N_SCOPE, 0xc4, "SCOPE") - -/* End of a lexical block. Desc matches the N_LBRAC's desc. - The value is the address of the end of the text for the block. */ -__define_stab (N_RBRAC, 0xe0, "RBRAC") - -/* Begin named common block. Only the name is significant. */ -__define_stab (N_BCOMM, 0xe2, "BCOMM") - -/* End named common block. Only the name is significant - (and it should match the N_BCOMM). */ -__define_stab (N_ECOMM, 0xe4, "ECOMM") - -/* End common (local name): value is address. - I'm not sure how this is used. */ -__define_stab (N_ECOML, 0xe8, "ECOML") - -/* These STAB's are used on Gould systems for Non-Base register symbols - or something like that. FIXME. I have assigned the values at random - since I don't have a Gould here. Fixups from Gould folk welcome... */ -__define_stab (N_NBTEXT, 0xF0, "NBTEXT") -__define_stab (N_NBDATA, 0xF2, "NBDATA") -__define_stab (N_NBBSS, 0xF4, "NBBSS") -__define_stab (N_NBSTS, 0xF6, "NBSTS") -__define_stab (N_NBLCS, 0xF8, "NBLCS") - -/* Second symbol entry containing a length-value for the preceding entry. - The value is the length. */ -__define_stab (N_LENG, 0xfe, "LENG") - -/* The above information, in matrix format. - - STAB MATRIX - _________________________________________________ - | 00 - 1F are not dbx stab symbols | - | In most cases, the low bit is the EXTernal bit| - - | 00 UNDEF | 02 ABS | 04 TEXT | 06 DATA | - | 01 |EXT | 03 |EXT | 05 |EXT | 07 |EXT | - - | 08 BSS | 0A INDR | 0C FN_SEQ | 0E | - | 09 |EXT | 0B | 0D | 0F | - - | 10 | 12 COMM | 14 SETA | 16 SETT | - | 11 | 13 | 15 | 17 | - - | 18 SETD | 1A SETB | 1C SETV | 1E WARNING| - | 19 | 1B | 1D | 1F FN | - - |_______________________________________________| - | Debug entries with bit 01 set are unused. | - | 20 GSYM | 22 FNAME | 24 FUN | 26 STSYM | - | 28 LCSYM | 2A MAIN | 2C | 2E | - | 30 PC | 32 NSYMS | 34 NOMAP | 36 | - | 38 OBJ | 3A | 3C OPT | 3E | - | 40 RSYM | 42 M2C | 44 SLINE | 46 DSLINE | - | 48 BSLINE*| 4A DEFD | 4C | 4E | - | 50 EHDECL*| 52 | 54 CATCH | 56 | - | 58 | 5A | 5C | 5E | - | 60 SSYM | 62 | 64 SO | 66 | - | 68 | 6A | 6C | 6E | - | 70 | 72 | 74 | 76 | - | 78 | 7A | 7C | 7E | - | 80 LSYM | 82 BINCL | 84 SOL | 86 | - | 88 | 8A | 8C | 8E | - | 90 | 92 | 94 | 96 | - | 98 | 9A | 9C | 9E | - | A0 PSYM | A2 EINCL | A4 ENTRY | A6 | - | A8 | AA | AC | AE | - | B0 | B2 | B4 | B6 | - | B8 | BA | BC | BE | - | C0 LBRAC | C2 EXCL | C4 SCOPE | C6 | - | C8 | CA | CC | CE | - | D0 | D2 | D4 | D6 | - | D8 | DA | DC | DE | - | E0 RBRAC | E2 BCOMM | E4 ECOMM | E6 | - | E8 ECOML | EA | EC | EE | - | F0 | F2 | F4 | F6 | - | F8 | FA | FC | FE LENG | - +-----------------------------------------------+ - * 50 EHDECL is also MOD2. - * 48 BSLINE is also BROWS. - */ diff --git a/05/tcc-final-old/stab.h b/05/tcc-final-old/stab.h deleted file mode 100644 index 80bd594..0000000 --- a/05/tcc-final-old/stab.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef __GNU_STAB__ - -/* Indicate the GNU stab.h is in use. */ - -#define __GNU_STAB__ - -#define __define_stab(NAME, CODE, STRING) NAME=CODE, - -enum __stab_debug_code -{ -#include "stab.def" -LAST_UNUSED_STAB_CODE -}; - -#undef __define_stab - -#endif /* __GNU_STAB_ */ diff --git a/05/tcc-final-old/tcc-doc.texi b/05/tcc-final-old/tcc-doc.texi deleted file mode 100644 index 5e718a2..0000000 --- a/05/tcc-final-old/tcc-doc.texi +++ /dev/null @@ -1,1326 +0,0 @@ -\input texinfo @c -*- texinfo -*- -@c %**start of header -@setfilename tcc-doc.info -@settitle Tiny C Compiler Reference Documentation -@dircategory Software development -@direntry -* TCC: (tcc-doc). The Tiny C Compiler. -@end direntry -@c %**end of header - -@include config.texi - -@iftex -@titlepage -@afourpaper -@sp 7 -@center @titlefont{Tiny C Compiler Reference Documentation} -@sp 3 -@end titlepage -@headings double -@end iftex - -@contents - -@node Top, Introduction, (dir), (dir) -@top Tiny C Compiler Reference Documentation - -This manual documents version @value{VERSION} of the Tiny C Compiler. - -@menu -* Introduction:: Introduction to tcc. -* Invoke:: Invocation of tcc (command line, options). -* Clang:: ANSI C and extensions. -* asm:: Assembler syntax. -* linker:: Output file generation and supported targets. -* Bounds:: Automatic bounds-checking of C code. -* Libtcc:: The libtcc library. -* devel:: Guide for Developers. -@end menu - - -@node Introduction -@chapter Introduction - -TinyCC (aka TCC) is a small but hyper fast C compiler. Unlike other C -compilers, it is meant to be self-relying: you do not need an -external assembler or linker because TCC does that for you. - -TCC compiles so @emph{fast} that even for big projects @code{Makefile}s may -not be necessary. - -TCC not only supports ANSI C, but also most of the new ISO C99 -standard and many GNUC extensions including inline assembly. - -TCC can also be used to make @emph{C scripts}, i.e. pieces of C source -that you run as a Perl or Python script. Compilation is so fast that -your script will be as fast as if it was an executable. - -TCC can also automatically generate memory and bound checks -(@pxref{Bounds}) while allowing all C pointers operations. TCC can do -these checks even if non patched libraries are used. - -With @code{libtcc}, you can use TCC as a backend for dynamic code -generation (@pxref{Libtcc}). - -TCC mainly supports the i386 target on Linux and Windows. There are alpha -ports for the ARM (@code{arm-tcc}) and the TMS320C67xx targets -(@code{c67-tcc}). More information about the ARM port is available at -@url{http://lists.gnu.org/archive/html/tinycc-devel/2003-10/msg00044.html}. - -For usage on Windows, see also @url{tcc-win32.txt}. - -@node Invoke -@chapter Command line invocation - -@section Quick start - -@example -@c man begin SYNOPSIS -usage: tcc [options] [@var{infile1} @var{infile2}@dots{}] [@option{-run} @var{infile} @var{args}@dots{}] -@c man end -@end example - -@noindent -@c man begin DESCRIPTION -TCC options are a very much like gcc options. The main difference is that TCC -can also execute directly the resulting program and give it runtime -arguments. - -Here are some examples to understand the logic: - -@table @code -@item @samp{tcc -run a.c} -Compile @file{a.c} and execute it directly - -@item @samp{tcc -run a.c arg1} -Compile a.c and execute it directly. arg1 is given as first argument to -the @code{main()} of a.c. - -@item @samp{tcc a.c -run b.c arg1} -Compile @file{a.c} and @file{b.c}, link them together and execute them. arg1 is given -as first argument to the @code{main()} of the resulting program. -@ignore -Because multiple C files are specified, @option{--} are necessary to clearly -separate the program arguments from the TCC options. -@end ignore - -@item @samp{tcc -o myprog a.c b.c} -Compile @file{a.c} and @file{b.c}, link them and generate the executable @file{myprog}. - -@item @samp{tcc -o myprog a.o b.o} -link @file{a.o} and @file{b.o} together and generate the executable @file{myprog}. - -@item @samp{tcc -c a.c} -Compile @file{a.c} and generate object file @file{a.o}. - -@item @samp{tcc -c asmfile.S} -Preprocess with C preprocess and assemble @file{asmfile.S} and generate -object file @file{asmfile.o}. - -@item @samp{tcc -c asmfile.s} -Assemble (but not preprocess) @file{asmfile.s} and generate object file -@file{asmfile.o}. - -@item @samp{tcc -r -o ab.o a.c b.c} -Compile @file{a.c} and @file{b.c}, link them together and generate the object file @file{ab.o}. - -@end table - -Scripting: - -TCC can be invoked from @emph{scripts}, just as shell scripts. You just -need to add @code{#!/usr/local/bin/tcc -run} at the start of your C source: - -@example -#!/usr/local/bin/tcc -run -#include - -int main() -@{ - printf("Hello World\n"); - return 0; -@} -@end example - -TCC can read C source code from @emph{standard input} when @option{-} is used in -place of @option{infile}. Example: - -@example -echo 'main()@{puts("hello");@}' | tcc -run - -@end example -@c man end - -@section Option summary - -General Options: - -@c man begin OPTIONS -@table @option -@item -c -Generate an object file. - -@item -o outfile -Put object file, executable, or dll into output file @file{outfile}. - -@item -run source [args...] -Compile file @var{source} and run it with the command line arguments -@var{args}. In order to be able to give more than one argument to a -script, several TCC options can be given @emph{after} the -@option{-run} option, separated by spaces: -@example -tcc "-run -L/usr/X11R6/lib -lX11" ex4.c -@end example -In a script, it gives the following header: -@example -#!/usr/local/bin/tcc -run -L/usr/X11R6/lib -lX11 -@end example - -@item -v -Display TCC version. - -@item -vv -Show included files. As sole argument, print search dirs. -vvv shows tries too. - -@item -bench -Display compilation statistics. - -@end table - -Preprocessor options: - -@table @option -@item -Idir -Specify an additional include path. Include paths are searched in the -order they are specified. - -System include paths are always searched after. The default system -include paths are: @file{/usr/local/include}, @file{/usr/include} -and @file{PREFIX/lib/tcc/include}. (@file{PREFIX} is usually -@file{/usr} or @file{/usr/local}). - -@item -Dsym[=val] -Define preprocessor symbol @samp{sym} to -val. If val is not present, its value is @samp{1}. Function-like macros can -also be defined: @option{-DF(a)=a+1} - -@item -Usym -Undefine preprocessor symbol @samp{sym}. - -@item -E -Preprocess only, to stdout or file (with -o). - -@end table - -Compilation flags: - -Note: each of the following options has a negative form beginning with -@option{-fno-}. - -@table @option -@item -funsigned-char -Let the @code{char} type be unsigned. - -@item -fsigned-char -Let the @code{char} type be signed. - -@item -fno-common -Do not generate common symbols for uninitialized data. - -@item -fleading-underscore -Add a leading underscore at the beginning of each C symbol. - -@item -fms-extensions -Allow a MS C compiler extensions to the language. Currently this -assumes a nested named structure declaration without an identifier -behaves like an unnamed one. - -@item -fdollars-in-identifiers -Allow dollar signs in identifiers - -@end table - -Warning options: - -@table @option -@item -w -Disable all warnings. - -@end table - -Note: each of the following warning options has a negative form beginning with -@option{-Wno-}. - -@table @option -@item -Wimplicit-function-declaration -Warn about implicit function declaration. - -@item -Wunsupported -Warn about unsupported GCC features that are ignored by TCC. - -@item -Wwrite-strings -Make string constants be of type @code{const char *} instead of @code{char -*}. - -@item -Werror -Abort compilation if warnings are issued. - -@item -Wall -Activate all warnings, except @option{-Werror}, @option{-Wunusupported} and -@option{-Wwrite-strings}. - -@end table - -Linker options: - -@table @option -@item -Ldir -Specify an additional static library path for the @option{-l} option. The -default library paths are @file{/usr/local/lib}, @file{/usr/lib} and @file{/lib}. - -@item -lxxx -Link your program with dynamic library libxxx.so or static library -libxxx.a. The library is searched in the paths specified by the -@option{-L} option and @env{LIBRARY_PATH} variable. - -@item -Bdir -Set the path where the tcc internal libraries (and include files) can be -found (default is @file{PREFIX/lib/tcc}). - -@item -shared -Generate a shared library instead of an executable. - -@item -soname name -set name for shared library to be used at runtime - -@item -static -Generate a statically linked executable (default is a shared linked -executable). - -@item -rdynamic -Export global symbols to the dynamic linker. It is useful when a library -opened with @code{dlopen()} needs to access executable symbols. - -@item -r -Generate an object file combining all input files. - -@item -Wl,-rpath=path -Put custom search path for dynamic libraries into executable. - -@item -Wl,--enable-new-dtags -When putting a custom search path for dynamic libraries into the executable, -create the new ELF dynamic tag DT_RUNPATH instead of the old legacy DT_RPATH. - -@item -Wl,--oformat=fmt -Use @var{fmt} as output format. The supported output formats are: -@table @code -@item elf32-i386 -ELF output format (default) -@item binary -Binary image (only for executable output) -@item coff -COFF output format (only for executable output for TMS320C67xx target) -@end table - -@item -Wl,-subsystem=console/gui/wince/... -Set type for PE (Windows) executables. - -@item -Wl,-[Ttext=# | section-alignment=# | file-alignment=# | image-base=# | stack=#] -Modify executable layout. - -@item -Wl,-Bsymbolic -Set DT_SYMBOLIC tag. - -@item -Wl,-(no-)whole-archive -Turn on/off linking of all objects in archives. - -@end table - -Debugger options: - -@table @option -@item -g -Generate run time debug information so that you get clear run time -error messages: @code{ test.c:68: in function 'test5()': dereferencing -invalid pointer} instead of the laconic @code{Segmentation -fault}. - -@item -b -Generate additional support code to check -memory allocations and array/pointer bounds. @option{-g} is implied. Note -that the generated code is slower and bigger in this case. - -Note: @option{-b} is only available on i386 when using libtcc for the moment. - -@item -bt N -Display N callers in stack traces. This is useful with @option{-g} or -@option{-b}. - -@end table - -Misc options: - -@table @option -@item -MD -Generate makefile fragment with dependencies. - -@item -MF depfile -Use @file{depfile} as output for -MD. - -@item -print-search-dirs -Print the configured installation directory and a list of library -and include directories tcc will search. - -@item -dumpversion -Print version. - -@end table - -Target specific options: - -@table @option -@item -mms-bitfields -Use an algorithm for bitfield alignment consistent with MSVC. Default is -gcc's algorithm. - -@item -mfloat-abi (ARM only) -Select the float ABI. Possible values: @code{softfp} and @code{hard} - -@item -mno-sse -Do not use sse registers on x86_64 - -@item -m32, -m64 -Pass command line to the i386/x86_64 cross compiler. - -@end table - -Note: GCC options @option{-Ox}, @option{-fx} and @option{-mx} are -ignored. -@c man end - -@c man begin ENVIRONMENT -Environment variables that affect how tcc operates. - -@table @option - -@item CPATH -@item C_INCLUDE_PATH -A colon-separated list of directories searched for include files, -directories given with @option{-I} are searched first. - -@item LIBRARY_PATH -A colon-separated list of directories searched for libraries for the -@option{-l} option, directories given with @option{-L} are searched first. - -@end table - -@c man end - -@ignore - -@setfilename tcc -@settitle Tiny C Compiler - -@c man begin SEEALSO -cpp(1), -gcc(1) -@c man end - -@c man begin AUTHOR -Fabrice Bellard -@c man end - -@end ignore - -@node Clang -@chapter C language support - -@section ANSI C - -TCC implements all the ANSI C standard, including structure bit fields -and floating point numbers (@code{long double}, @code{double}, and -@code{float} fully supported). - -@section ISOC99 extensions - -TCC implements many features of the new C standard: ISO C99. Currently -missing items are: complex and imaginary numbers. - -Currently implemented ISOC99 features: - -@itemize - -@item variable length arrays. - -@item 64 bit @code{long long} types are fully supported. - -@item The boolean type @code{_Bool} is supported. - -@item @code{__func__} is a string variable containing the current -function name. - -@item Variadic macros: @code{__VA_ARGS__} can be used for - function-like macros: -@example - #define dprintf(level, __VA_ARGS__) printf(__VA_ARGS__) -@end example - -@noindent -@code{dprintf} can then be used with a variable number of parameters. - -@item Declarations can appear anywhere in a block (as in C++). - -@item Array and struct/union elements can be initialized in any order by - using designators: -@example - struct @{ int x, y; @} st[10] = @{ [0].x = 1, [0].y = 2 @}; - - int tab[10] = @{ 1, 2, [5] = 5, [9] = 9@}; -@end example - -@item Compound initializers are supported: -@example - int *p = (int [])@{ 1, 2, 3 @}; -@end example -to initialize a pointer pointing to an initialized array. The same -works for structures and strings. - -@item Hexadecimal floating point constants are supported: -@example - double d = 0x1234p10; -@end example - -@noindent -is the same as writing -@example - double d = 4771840.0; -@end example - -@item @code{inline} keyword is ignored. - -@item @code{restrict} keyword is ignored. -@end itemize - -@section GNU C extensions - -TCC implements some GNU C extensions: - -@itemize - -@item array designators can be used without '=': -@example - int a[10] = @{ [0] 1, [5] 2, 3, 4 @}; -@end example - -@item Structure field designators can be a label: -@example - struct @{ int x, y; @} st = @{ x: 1, y: 1@}; -@end example -instead of -@example - struct @{ int x, y; @} st = @{ .x = 1, .y = 1@}; -@end example - -@item @code{\e} is ASCII character 27. - -@item case ranges : ranges can be used in @code{case}s: -@example - switch(a) @{ - case 1 @dots{} 9: - printf("range 1 to 9\n"); - break; - default: - printf("unexpected\n"); - break; - @} -@end example - -@cindex aligned attribute -@cindex packed attribute -@cindex section attribute -@cindex unused attribute -@cindex cdecl attribute -@cindex stdcall attribute -@cindex regparm attribute -@cindex dllexport attribute - -@item The keyword @code{__attribute__} is handled to specify variable or -function attributes. The following attributes are supported: - @itemize - - @item @code{aligned(n)}: align a variable or a structure field to n bytes -(must be a power of two). - - @item @code{packed}: force alignment of a variable or a structure field to - 1. - - @item @code{section(name)}: generate function or data in assembly section -name (name is a string containing the section name) instead of the default -section. - - @item @code{unused}: specify that the variable or the function is unused. - - @item @code{cdecl}: use standard C calling convention (default). - - @item @code{stdcall}: use Pascal-like calling convention. - - @item @code{regparm(n)}: use fast i386 calling convention. @var{n} must be -between 1 and 3. The first @var{n} function parameters are respectively put in -registers @code{%eax}, @code{%edx} and @code{%ecx}. - - @item @code{dllexport}: export function from dll/executable (win32 only) - - @end itemize - -Here are some examples: -@example - int a __attribute__ ((aligned(8), section(".mysection"))); -@end example - -@noindent -align variable @code{a} to 8 bytes and put it in section @code{.mysection}. - -@example - int my_add(int a, int b) __attribute__ ((section(".mycodesection"))) - @{ - return a + b; - @} -@end example - -@noindent -generate function @code{my_add} in section @code{.mycodesection}. - -@item GNU style variadic macros: -@example - #define dprintf(fmt, args@dots{}) printf(fmt, ## args) - - dprintf("no arg\n"); - dprintf("one arg %d\n", 1); -@end example - -@item @code{__FUNCTION__} is interpreted as C99 @code{__func__} -(so it has not exactly the same semantics as string literal GNUC -where it is a string literal). - -@item The @code{__alignof__} keyword can be used as @code{sizeof} -to get the alignment of a type or an expression. - -@item The @code{typeof(x)} returns the type of @code{x}. -@code{x} is an expression or a type. - -@item Computed gotos: @code{&&label} returns a pointer of type -@code{void *} on the goto label @code{label}. @code{goto *expr} can be -used to jump on the pointer resulting from @code{expr}. - -@item Inline assembly with asm instruction: -@cindex inline assembly -@cindex assembly, inline -@cindex __asm__ -@example -static inline void * my_memcpy(void * to, const void * from, size_t n) -@{ -int d0, d1, d2; -__asm__ __volatile__( - "rep ; movsl\n\t" - "testb $2,%b4\n\t" - "je 1f\n\t" - "movsw\n" - "1:\ttestb $1,%b4\n\t" - "je 2f\n\t" - "movsb\n" - "2:" - : "=&c" (d0), "=&D" (d1), "=&S" (d2) - :"0" (n/4), "q" (n),"1" ((long) to),"2" ((long) from) - : "memory"); -return (to); -@} -@end example - -@noindent -@cindex gas -TCC includes its own x86 inline assembler with a @code{gas}-like (GNU -assembler) syntax. No intermediate files are generated. GCC 3.x named -operands are supported. - -@item @code{__builtin_types_compatible_p()} and @code{__builtin_constant_p()} -are supported. - -@item @code{#pragma pack} is supported for win32 compatibility. - -@end itemize - -@section TinyCC extensions - -@itemize - -@item @code{__TINYC__} is a predefined macro to indicate that you use TCC. - -@item @code{#!} at the start of a line is ignored to allow scripting. - -@item Binary digits can be entered (@code{0b101} instead of -@code{5}). - -@item @code{__BOUNDS_CHECKING_ON} is defined if bound checking is activated. - -@end itemize - -@node asm -@chapter TinyCC Assembler - -Since version 0.9.16, TinyCC integrates its own assembler. TinyCC -assembler supports a gas-like syntax (GNU assembler). You can -deactivate assembler support if you want a smaller TinyCC executable -(the C compiler does not rely on the assembler). - -TinyCC Assembler is used to handle files with @file{.S} (C -preprocessed assembler) and @file{.s} extensions. It is also used to -handle the GNU inline assembler with the @code{asm} keyword. - -@section Syntax - -TinyCC Assembler supports most of the gas syntax. The tokens are the -same as C. - -@itemize - -@item C and C++ comments are supported. - -@item Identifiers are the same as C, so you cannot use '.' or '$'. - -@item Only 32 bit integer numbers are supported. - -@end itemize - -@section Expressions - -@itemize - -@item Integers in decimal, octal and hexa are supported. - -@item Unary operators: +, -, ~. - -@item Binary operators in decreasing priority order: - -@enumerate -@item *, /, % -@item &, |, ^ -@item +, - -@end enumerate - -@item A value is either an absolute number or a label plus an offset. -All operators accept absolute values except '+' and '-'. '+' or '-' can be -used to add an offset to a label. '-' supports two labels only if they -are the same or if they are both defined and in the same section. - -@end itemize - -@section Labels - -@itemize - -@item All labels are considered as local, except undefined ones. - -@item Numeric labels can be used as local @code{gas}-like labels. -They can be defined several times in the same source. Use 'b' -(backward) or 'f' (forward) as suffix to reference them: - -@example - 1: - jmp 1b /* jump to '1' label before */ - jmp 1f /* jump to '1' label after */ - 1: -@end example - -@end itemize - -@section Directives -@cindex assembler directives -@cindex directives, assembler -@cindex align directive -@cindex skip directive -@cindex space directive -@cindex byte directive -@cindex word directive -@cindex short directive -@cindex int directive -@cindex long directive -@cindex quad directive -@cindex globl directive -@cindex global directive -@cindex section directive -@cindex text directive -@cindex data directive -@cindex bss directive -@cindex fill directive -@cindex org directive -@cindex previous directive -@cindex string directive -@cindex asciz directive -@cindex ascii directive - -All directives are preceded by a '.'. The following directives are -supported: - -@itemize -@item .align n[,value] -@item .skip n[,value] -@item .space n[,value] -@item .byte value1[,...] -@item .word value1[,...] -@item .short value1[,...] -@item .int value1[,...] -@item .long value1[,...] -@item .quad immediate_value1[,...] -@item .globl symbol -@item .global symbol -@item .section section -@item .text -@item .data -@item .bss -@item .fill repeat[,size[,value]] -@item .org n -@item .previous -@item .string string[,...] -@item .asciz string[,...] -@item .ascii string[,...] -@end itemize - -@section X86 Assembler -@cindex assembler - -All X86 opcodes are supported. Only ATT syntax is supported (source -then destination operand order). If no size suffix is given, TinyCC -tries to guess it from the operand sizes. - -Currently, MMX opcodes are supported but not SSE ones. - -@node linker -@chapter TinyCC Linker -@cindex linker - -@section ELF file generation -@cindex ELF - -TCC can directly output relocatable ELF files (object files), -executable ELF files and dynamic ELF libraries without relying on an -external linker. - -Dynamic ELF libraries can be output but the C compiler does not generate -position independent code (PIC). It means that the dynamic library -code generated by TCC cannot be factorized among processes yet. - -TCC linker eliminates unreferenced object code in libraries. A single pass is -done on the object and library list, so the order in which object files and -libraries are specified is important (same constraint as GNU ld). No grouping -options (@option{--start-group} and @option{--end-group}) are supported. - -@section ELF file loader - -TCC can load ELF object files, archives (.a files) and dynamic -libraries (.so). - -@section PE-i386 file generation -@cindex PE-i386 - -TCC for Windows supports the native Win32 executable file format (PE-i386). It -generates EXE files (console and gui) and DLL files. - -For usage on Windows, see also tcc-win32.txt. - -@section GNU Linker Scripts -@cindex scripts, linker -@cindex linker scripts -@cindex GROUP, linker command -@cindex FILE, linker command -@cindex OUTPUT_FORMAT, linker command -@cindex TARGET, linker command - -Because on many Linux systems some dynamic libraries (such as -@file{/usr/lib/libc.so}) are in fact GNU ld link scripts (horrible!), -the TCC linker also supports a subset of GNU ld scripts. - -The @code{GROUP} and @code{FILE} commands are supported. @code{OUTPUT_FORMAT} -and @code{TARGET} are ignored. - -Example from @file{/usr/lib/libc.so}: -@example -/* GNU ld script - Use the shared library, but some functions are only in - the static library, so try that secondarily. */ -GROUP ( /lib/libc.so.6 /usr/lib/libc_nonshared.a ) -@end example - -@node Bounds -@chapter TinyCC Memory and Bound checks -@cindex bound checks -@cindex memory checks - -This feature is activated with the @option{-b} (@pxref{Invoke}). - -Note that pointer size is @emph{unchanged} and that code generated -with bound checks is @emph{fully compatible} with unchecked -code. When a pointer comes from unchecked code, it is assumed to be -valid. Even very obscure C code with casts should work correctly. - -For more information about the ideas behind this method, see -@url{http://www.doc.ic.ac.uk/~phjk/BoundsChecking.html}. - -Here are some examples of caught errors: - -@table @asis - -@item Invalid range with standard string function: -@example -@{ - char tab[10]; - memset(tab, 0, 11); -@} -@end example - -@item Out of bounds-error in global or local arrays: -@example -@{ - int tab[10]; - for(i=0;i<11;i++) @{ - sum += tab[i]; - @} -@} -@end example - -@item Out of bounds-error in malloc'ed data: -@example -@{ - int *tab; - tab = malloc(20 * sizeof(int)); - for(i=0;i<21;i++) @{ - sum += tab4[i]; - @} - free(tab); -@} -@end example - -@item Access of freed memory: -@example -@{ - int *tab; - tab = malloc(20 * sizeof(int)); - free(tab); - for(i=0;i<20;i++) @{ - sum += tab4[i]; - @} -@} -@end example - -@item Double free: -@example -@{ - int *tab; - tab = malloc(20 * sizeof(int)); - free(tab); - free(tab); -@} -@end example - -@end table - -@node Libtcc -@chapter The @code{libtcc} library - -The @code{libtcc} library enables you to use TCC as a backend for -dynamic code generation. - -Read the @file{libtcc.h} to have an overview of the API. Read -@file{libtcc_test.c} to have a very simple example. - -The idea consists in giving a C string containing the program you want -to compile directly to @code{libtcc}. Then you can access to any global -symbol (function or variable) defined. - -@node devel -@chapter Developer's guide - -This chapter gives some hints to understand how TCC works. You can skip -it if you do not intend to modify the TCC code. - -@section File reading - -The @code{BufferedFile} structure contains the context needed to read a -file, including the current line number. @code{tcc_open()} opens a new -file and @code{tcc_close()} closes it. @code{inp()} returns the next -character. - -@section Lexer - -@code{next()} reads the next token in the current -file. @code{next_nomacro()} reads the next token without macro -expansion. - -@code{tok} contains the current token (see @code{TOK_xxx}) -constants. Identifiers and keywords are also keywords. @code{tokc} -contains additional infos about the token (for example a constant value -if number or string token). - -@section Parser - -The parser is hardcoded (yacc is not necessary). It does only one pass, -except: - -@itemize - -@item For initialized arrays with unknown size, a first pass -is done to count the number of elements. - -@item For architectures where arguments are evaluated in -reverse order, a first pass is done to reverse the argument order. - -@end itemize - -@section Types - -The types are stored in a single 'int' variable. It was chosen in the -first stages of development when tcc was much simpler. Now, it may not -be the best solution. - -@example -#define VT_INT 0 /* integer type */ -#define VT_BYTE 1 /* signed byte type */ -#define VT_SHORT 2 /* short type */ -#define VT_VOID 3 /* void type */ -#define VT_PTR 4 /* pointer */ -#define VT_ENUM 5 /* enum definition */ -#define VT_FUNC 6 /* function type */ -#define VT_STRUCT 7 /* struct/union definition */ -#define VT_FLOAT 8 /* IEEE float */ -#define VT_DOUBLE 9 /* IEEE double */ -#define VT_LDOUBLE 10 /* IEEE long double */ -#define VT_BOOL 11 /* ISOC99 boolean type */ -#define VT_LLONG 12 /* 64 bit integer */ -#define VT_LONG 13 /* long integer (NEVER USED as type, only - during parsing) */ -#define VT_BTYPE 0x000f /* mask for basic type */ -#define VT_UNSIGNED 0x0010 /* unsigned type */ -#define VT_ARRAY 0x0020 /* array type (also has VT_PTR) */ -#define VT_VLA 0x20000 /* VLA type (also has VT_PTR and VT_ARRAY) */ -#define VT_BITFIELD 0x0040 /* bitfield modifier */ -#define VT_CONSTANT 0x0800 /* const modifier */ -#define VT_VOLATILE 0x1000 /* volatile modifier */ -#define VT_DEFSIGN 0x2000 /* signed type */ - -#define VT_STRUCT_SHIFT 18 /* structure/enum name shift (14 bits left) */ -@end example - -When a reference to another type is needed (for pointers, functions and -structures), the @code{32 - VT_STRUCT_SHIFT} high order bits are used to -store an identifier reference. - -The @code{VT_UNSIGNED} flag can be set for chars, shorts, ints and long -longs. - -Arrays are considered as pointers @code{VT_PTR} with the flag -@code{VT_ARRAY} set. Variable length arrays are considered as special -arrays and have flag @code{VT_VLA} set instead of @code{VT_ARRAY}. - -The @code{VT_BITFIELD} flag can be set for chars, shorts, ints and long -longs. If it is set, then the bitfield position is stored from bits -VT_STRUCT_SHIFT to VT_STRUCT_SHIFT + 5 and the bit field size is stored -from bits VT_STRUCT_SHIFT + 6 to VT_STRUCT_SHIFT + 11. - -@code{VT_LONG} is never used except during parsing. - -During parsing, the storage of an object is also stored in the type -integer: - -@example -#define VT_EXTERN 0x00000080 /* extern definition */ -#define VT_STATIC 0x00000100 /* static variable */ -#define VT_TYPEDEF 0x00000200 /* typedef definition */ -#define VT_INLINE 0x00000400 /* inline definition */ -#define VT_IMPORT 0x00004000 /* win32: extern data imported from dll */ -#define VT_EXPORT 0x00008000 /* win32: data exported from dll */ -#define VT_WEAK 0x00010000 /* win32: data exported from dll */ -@end example - -@section Symbols - -All symbols are stored in hashed symbol stacks. Each symbol stack -contains @code{Sym} structures. - -@code{Sym.v} contains the symbol name (remember -an identifier is also a token, so a string is never necessary to store -it). @code{Sym.t} gives the type of the symbol. @code{Sym.r} is usually -the register in which the corresponding variable is stored. @code{Sym.c} is -usually a constant associated to the symbol like its address for normal -symbols, and the number of entries for symbols representing arrays. -Variable length array types use @code{Sym.c} as a location on the stack -which holds the runtime sizeof for the type. - -Four main symbol stacks are defined: - -@table @code - -@item define_stack -for the macros (@code{#define}s). - -@item global_stack -for the global variables, functions and types. - -@item local_stack -for the local variables, functions and types. - -@item global_label_stack -for the local labels (for @code{goto}). - -@item label_stack -for GCC block local labels (see the @code{__label__} keyword). - -@end table - -@code{sym_push()} is used to add a new symbol in the local symbol -stack. If no local symbol stack is active, it is added in the global -symbol stack. - -@code{sym_pop(st,b)} pops symbols from the symbol stack @var{st} until -the symbol @var{b} is on the top of stack. If @var{b} is NULL, the stack -is emptied. - -@code{sym_find(v)} return the symbol associated to the identifier -@var{v}. The local stack is searched first from top to bottom, then the -global stack. - -@section Sections - -The generated code and data are written in sections. The structure -@code{Section} contains all the necessary information for a given -section. @code{new_section()} creates a new section. ELF file semantics -is assumed for each section. - -The following sections are predefined: - -@table @code - -@item text_section -is the section containing the generated code. @var{ind} contains the -current position in the code section. - -@item data_section -contains initialized data - -@item bss_section -contains uninitialized data - -@item bounds_section -@itemx lbounds_section -are used when bound checking is activated - -@item stab_section -@itemx stabstr_section -are used when debugging is active to store debug information - -@item symtab_section -@itemx strtab_section -contain the exported symbols (currently only used for debugging). - -@end table - -@section Code generation -@cindex code generation - -@subsection Introduction - -The TCC code generator directly generates linked binary code in one -pass. It is rather unusual these days (see gcc for example which -generates text assembly), but it can be very fast and surprisingly -little complicated. - -The TCC code generator is register based. Optimization is only done at -the expression level. No intermediate representation of expression is -kept except the current values stored in the @emph{value stack}. - -On x86, three temporary registers are used. When more registers are -needed, one register is spilled into a new temporary variable on the stack. - -@subsection The value stack -@cindex value stack, introduction - -When an expression is parsed, its value is pushed on the value stack -(@var{vstack}). The top of the value stack is @var{vtop}. Each value -stack entry is the structure @code{SValue}. - -@code{SValue.t} is the type. @code{SValue.r} indicates how the value is -currently stored in the generated code. It is usually a CPU register -index (@code{REG_xxx} constants), but additional values and flags are -defined: - -@example -#define VT_CONST 0x00f0 -#define VT_LLOCAL 0x00f1 -#define VT_LOCAL 0x00f2 -#define VT_CMP 0x00f3 -#define VT_JMP 0x00f4 -#define VT_JMPI 0x00f5 -#define VT_LVAL 0x0100 -#define VT_SYM 0x0200 -#define VT_MUSTCAST 0x0400 -#define VT_MUSTBOUND 0x0800 -#define VT_BOUNDED 0x8000 -#define VT_LVAL_BYTE 0x1000 -#define VT_LVAL_SHORT 0x2000 -#define VT_LVAL_UNSIGNED 0x4000 -#define VT_LVAL_TYPE (VT_LVAL_BYTE | VT_LVAL_SHORT | VT_LVAL_UNSIGNED) -@end example - -@table @code - -@item VT_CONST -indicates that the value is a constant. It is stored in the union -@code{SValue.c}, depending on its type. - -@item VT_LOCAL -indicates a local variable pointer at offset @code{SValue.c.i} in the -stack. - -@item VT_CMP -indicates that the value is actually stored in the CPU flags (i.e. the -value is the consequence of a test). The value is either 0 or 1. The -actual CPU flags used is indicated in @code{SValue.c.i}. - -If any code is generated which destroys the CPU flags, this value MUST be -put in a normal register. - -@item VT_JMP -@itemx VT_JMPI -indicates that the value is the consequence of a conditional jump. For VT_JMP, -it is 1 if the jump is taken, 0 otherwise. For VT_JMPI it is inverted. - -These values are used to compile the @code{||} and @code{&&} logical -operators. - -If any code is generated, this value MUST be put in a normal -register. Otherwise, the generated code won't be executed if the jump is -taken. - -@item VT_LVAL -is a flag indicating that the value is actually an lvalue (left value of -an assignment). It means that the value stored is actually a pointer to -the wanted value. - -Understanding the use @code{VT_LVAL} is very important if you want to -understand how TCC works. - -@item VT_LVAL_BYTE -@itemx VT_LVAL_SHORT -@itemx VT_LVAL_UNSIGNED -if the lvalue has an integer type, then these flags give its real -type. The type alone is not enough in case of cast optimisations. - -@item VT_LLOCAL -is a saved lvalue on the stack. @code{VT_LVAL} must also be set with -@code{VT_LLOCAL}. @code{VT_LLOCAL} can arise when a @code{VT_LVAL} in -a register has to be saved to the stack, or it can come from an -architecture-specific calling convention. - -@item VT_MUSTCAST -indicates that a cast to the value type must be performed if the value -is used (lazy casting). - -@item VT_SYM -indicates that the symbol @code{SValue.sym} must be added to the constant. - -@item VT_MUSTBOUND -@itemx VT_BOUNDED -are only used for optional bound checking. - -@end table - -@subsection Manipulating the value stack -@cindex value stack - -@code{vsetc()} and @code{vset()} pushes a new value on the value -stack. If the previous @var{vtop} was stored in a very unsafe place(for -example in the CPU flags), then some code is generated to put the -previous @var{vtop} in a safe storage. - -@code{vpop()} pops @var{vtop}. In some cases, it also generates cleanup -code (for example if stacked floating point registers are used as on -x86). - -The @code{gv(rc)} function generates code to evaluate @var{vtop} (the -top value of the stack) into registers. @var{rc} selects in which -register class the value should be put. @code{gv()} is the @emph{most -important function} of the code generator. - -@code{gv2()} is the same as @code{gv()} but for the top two stack -entries. - -@subsection CPU dependent code generation -@cindex CPU dependent -See the @file{i386-gen.c} file to have an example. - -@table @code - -@item load() -must generate the code needed to load a stack value into a register. - -@item store() -must generate the code needed to store a register into a stack value -lvalue. - -@item gfunc_start() -@itemx gfunc_param() -@itemx gfunc_call() -should generate a function call - -@item gfunc_prolog() -@itemx gfunc_epilog() -should generate a function prolog/epilog. - -@item gen_opi(op) -must generate the binary integer operation @var{op} on the two top -entries of the stack which are guaranteed to contain integer types. - -The result value should be put on the stack. - -@item gen_opf(op) -same as @code{gen_opi()} for floating point operations. The two top -entries of the stack are guaranteed to contain floating point values of -same types. - -@item gen_cvt_itof() -integer to floating point conversion. - -@item gen_cvt_ftoi() -floating point to integer conversion. - -@item gen_cvt_ftof() -floating point to floating point of different size conversion. - -@item gen_bounded_ptr_add() -@item gen_bounded_ptr_deref() -are only used for bounds checking. - -@end table - -@section Optimizations done -@cindex optimizations -@cindex constant propagation -@cindex strength reduction -@cindex comparison operators -@cindex caching processor flags -@cindex flags, caching -@cindex jump optimization -Constant propagation is done for all operations. Multiplications and -divisions are optimized to shifts when appropriate. Comparison -operators are optimized by maintaining a special cache for the -processor flags. &&, || and ! are optimized by maintaining a special -'jump target' value. No other jump optimization is currently performed -because it would require to store the code in a more abstract fashion. - -@unnumbered Concept Index -@printindex cp - -@bye - -@c Local variables: -@c fill-column: 78 -@c texinfo-column-for-description: 32 -@c End: diff --git a/05/tcc-final-old/tcc.c b/05/tcc-final-old/tcc.c deleted file mode 100644 index 740aa49..0000000 --- a/05/tcc-final-old/tcc.c +++ /dev/null @@ -1,371 +0,0 @@ -/* - * TCC - Tiny C Compiler - * - * Copyright (c) 2001-2004 Fabrice Bellard - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "tcc.h" -#if ONE_SOURCE -# include "libtcc.c" -#endif -#include "tcctools.c" - -static const char help[] = - "Tiny C Compiler "TCC_VERSION" - Copyright (C) 2001-2006 Fabrice Bellard\n" - "Usage: tcc [options...] [-o outfile] [-c] infile(s)...\n" - " tcc [options...] -run infile [arguments...]\n" - "General options:\n" - " -c compile only - generate an object file\n" - " -o outfile set output filename\n" - " -run run compiled source\n" - " -fflag set or reset (with 'no-' prefix) 'flag' (see tcc -hh)\n" - " -Wwarning set or reset (with 'no-' prefix) 'warning' (see tcc -hh)\n" - " -w disable all warnings\n" - " -v -vv show version, show search paths or loaded files\n" - " -h -hh show this, show more help\n" - " -bench show compilation statistics\n" - " - use stdin pipe as infile\n" - " @listfile read arguments from listfile\n" - "Preprocessor options:\n" - " -Idir add include path 'dir'\n" - " -Dsym[=val] define 'sym' with value 'val'\n" - " -Usym undefine 'sym'\n" - " -E preprocess only\n" - "Linker options:\n" - " -Ldir add library path 'dir'\n" - " -llib link with dynamic or static library 'lib'\n" - " -r generate (relocatable) object file\n" - " -shared generate a shared library/dll\n" - " -rdynamic export all global symbols to dynamic linker\n" - " -soname set name for shared library to be used at runtime\n" - " -Wl,-opt[=val] set linker option (see tcc -hh)\n" - "Debugger options:\n" - " -g generate runtime debug info\n" -#ifdef CONFIG_TCC_BCHECK - " -b compile with built-in memory and bounds checker (implies -g)\n" -#endif -#ifdef CONFIG_TCC_BACKTRACE - " -bt N show N callers in stack traces\n" -#endif - "Misc. options:\n" - " -x[c|a|n] specify type of the next infile\n" - " -nostdinc do not use standard system include paths\n" - " -nostdlib do not link with standard crt and libraries\n" - " -Bdir set tcc's private include/library dir\n" - " -MD generate dependency file for make\n" - " -MF file specify dependency file name\n" - " -m32/64 defer to i386/x86_64 cross compiler\n" - "Tools:\n" - " create library : tcc -ar [rcsv] lib.a files\n" -#ifdef TCC_TARGET_PE - " create def file : tcc -impdef lib.dll [-v] [-o lib.def]\n" -#endif - ; - -static const char help2[] = - "Tiny C Compiler "TCC_VERSION" - More Options\n" - "Special options:\n" - " -P -P1 with -E: no/alternative #line output\n" - " -dD -dM with -E: output #define directives\n" - " -pthread same as -D_REENTRANT and -lpthread\n" - " -On same as -D__OPTIMIZE__ for n > 0\n" - " -Wp,-opt same as -opt\n" - " -include file include 'file' above each input file\n" - " -isystem dir add 'dir' to system include path\n" - " -static link to static libraries (not recommended)\n" - " -dumpversion print version\n" - " -print-search-dirs print search paths\n" - " -dt with -run/-E: auto-define 'test_...' macros\n" - "Ignored options:\n" - " --param -pedantic -pipe -s -std -traditional\n" - "-W... warnings:\n" - " all turn on some (*) warnings\n" - " error stop after first warning\n" - " unsupported warn about ignored options, pragmas, etc.\n" - " write-strings strings are const\n" - " implicit-function-declaration warn for missing prototype (*)\n" - "-f[no-]... flags:\n" - " unsigned-char default char is unsigned\n" - " signed-char default char is signed\n" - " common use common section instead of bss\n" - " leading-underscore decorate extern symbols\n" - " ms-extensions allow anonymous struct in struct\n" - " dollars-in-identifiers allow '$' in C symbols\n" - "-m... target specific options:\n" - " ms-bitfields use MSVC bitfield layout\n" -#ifdef TCC_TARGET_ARM - " float-abi hard/softfp on arm\n" -#endif -#ifdef TCC_TARGET_X86_64 - " no-sse disable floats on x86_64\n" -#endif - "-Wl,... linker options:\n" - " -nostdlib do not link with standard crt/libs\n" - " -[no-]whole-archive load lib(s) fully/only as needed\n" - " -export-all-symbols same as -rdynamic\n" - " -image-base= -Ttext= set base address of executable\n" - " -section-alignment= set section alignment in executable\n" -#ifdef TCC_TARGET_PE - " -file-alignment= set PE file alignment\n" - " -stack= set PE stack reserve\n" - " -large-address-aware set related PE option\n" - " -subsystem=[console/windows] set PE subsystem\n" - " -oformat=[pe-* binary] set executable output format\n" - "Predefined macros:\n" - " tcc -E -dM - < nul\n" -#else - " -rpath= set dynamic library search path\n" - " -enable-new-dtags set DT_RUNPATH instead of DT_RPATH\n" - " -soname= set DT_SONAME elf tag\n" - " -Bsymbolic set DT_SYMBOLIC elf tag\n" - " -oformat=[elf32/64-* binary] set executable output format\n" - " -init= -fini= -as-needed -O (ignored)\n" - "Predefined macros:\n" - " tcc -E -dM - < /dev/null\n" -#endif - "See also the manual for more details.\n" - ; - -static const char version[] = - "tcc version "TCC_VERSION" (" -#ifdef TCC_TARGET_I386 - "i386" -#elif defined TCC_TARGET_X86_64 - "x86_64" -#elif defined TCC_TARGET_C67 - "C67" -#elif defined TCC_TARGET_ARM - "ARM" -#elif defined TCC_TARGET_ARM64 - "AArch64" -#endif -#ifdef TCC_ARM_HARDFLOAT - " Hard Float" -#endif -#ifdef TCC_TARGET_PE - " Windows" -#elif defined(TCC_TARGET_MACHO) - " Darwin" -#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) - " FreeBSD" -#else - " Linux" -#endif - ")\n" - ; - -static void print_dirs(const char *msg, char **paths, int nb_paths) -{ - int i; - printf("%s:\n%s", msg, nb_paths ? "" : " -\n"); - for(i = 0; i < nb_paths; i++) - printf(" %s\n", paths[i]); -} - -static void print_search_dirs(TCCState *s) -{ - printf("install: %s\n", s->tcc_lib_path); - /* print_dirs("programs", NULL, 0); */ - print_dirs("include", s->sysinclude_paths, s->nb_sysinclude_paths); - print_dirs("libraries", s->library_paths, s->nb_library_paths); - printf("libtcc1:\n %s/"TCC_LIBTCC1"\n", s->tcc_lib_path); -#ifndef TCC_TARGET_PE - print_dirs("crt", s->crt_paths, s->nb_crt_paths); - printf("elfinterp:\n %s\n", DEFAULT_ELFINTERP(s)); -#endif -} - -static void set_environment(TCCState *s) -{ - char * path; - - path = getenv("C_INCLUDE_PATH"); - if(path != NULL) { - tcc_add_sysinclude_path(s, path); - } - path = getenv("CPATH"); - if(path != NULL) { - tcc_add_include_path(s, path); - } - path = getenv("LIBRARY_PATH"); - if(path != NULL) { - tcc_add_library_path(s, path); - } -} - -static char *default_outputfile(TCCState *s, const char *first_file) -{ - char buf[1024]; - char *ext; - const char *name = "a"; - - if (first_file && strcmp(first_file, "-")) - name = tcc_basename(first_file); - snprintf(buf, sizeof(buf), "%s", name); - ext = tcc_fileextension(buf); -#ifdef TCC_TARGET_PE - if (s->output_type == TCC_OUTPUT_DLL) - strcpy(ext, ".dll"); - else - if (s->output_type == TCC_OUTPUT_EXE) - strcpy(ext, ".exe"); - else -#endif - if (s->output_type == TCC_OUTPUT_OBJ && !s->option_r && *ext) - strcpy(ext, ".o"); - else - strcpy(buf, "a.out"); - return tcc_strdup(buf); -} - -static unsigned getclock_ms(void) -{ -#ifdef _WIN32 - return GetTickCount(); -#else - struct timeval tv; - gettimeofday(&tv, NULL); - return tv.tv_sec*1000 + (tv.tv_usec+500)/1000; -#endif -} - -int main(int argc0, char **argv0) -{ - TCCState *s; - int ret, opt, n = 0, t = 0; - unsigned start_time = 0; - const char *first_file; - int argc; char **argv; - FILE *ppfp = stdout; - -redo: - argc = argc0, argv = argv0; - s = tcc_new(); - opt = tcc_parse_args(s, &argc, &argv, 1); - - if ((n | t) == 0) { - if (opt == OPT_HELP) - return printf(help), 0; - if (opt == OPT_HELP2) - return printf(help2), 0; - if (opt == OPT_M32 || opt == OPT_M64) - tcc_tool_cross(s, argv, opt); /* never returns */ - if (s->verbose) - printf(version); - if (opt == OPT_AR) - return tcc_tool_ar(s, argc, argv); -#ifdef TCC_TARGET_PE - if (opt == OPT_IMPDEF) - return tcc_tool_impdef(s, argc, argv); -#endif - if (opt == OPT_V) - return 0; - if (opt == OPT_PRINT_DIRS) { - /* initialize search dirs */ - set_environment(s); - tcc_set_output_type(s, TCC_OUTPUT_MEMORY); - print_search_dirs(s); - return 0; - } - - n = s->nb_files; - if (n == 0) - tcc_error("no input files\n"); - - if (s->output_type == TCC_OUTPUT_PREPROCESS) { - if (s->outfile) { - ppfp = fopen(s->outfile, "w"); - if (!ppfp) - tcc_error("could not write '%s'", s->outfile); - } - } else if (s->output_type == TCC_OUTPUT_OBJ && !s->option_r) { - if (s->nb_libraries) - tcc_error("cannot specify libraries with -c"); - if (n > 1 && s->outfile) - tcc_error("cannot specify output file with -c many files"); - } else { - if (s->option_pthread) - tcc_set_options(s, "-lpthread"); - } - - if (s->do_bench) - start_time = getclock_ms(); - } - - set_environment(s); - if (s->output_type == 0) - s->output_type = TCC_OUTPUT_EXE; - tcc_set_output_type(s, s->output_type); - s->ppfp = ppfp; - - if ((s->output_type == TCC_OUTPUT_MEMORY - || s->output_type == TCC_OUTPUT_PREPROCESS) && (s->dflag & 16)) - s->dflag |= t ? 32 : 0, s->run_test = ++t, n = s->nb_files; - - /* compile or add each files or library */ - for (first_file = NULL, ret = 0;;) { - struct filespec *f = s->files[s->nb_files - n]; - s->filetype = f->type; - s->alacarte_link = f->alacarte; - if (f->type == AFF_TYPE_LIB) { - if (tcc_add_library_err(s, f->name) < 0) - ret = 1; - } else { - if (1 == s->verbose) - printf("-> %s\n", f->name); - if (!first_file) - first_file = f->name; - if (tcc_add_file(s, f->name) < 0) - ret = 1; - } - s->filetype = 0; - s->alacarte_link = 1; - if (--n == 0 || ret - || (s->output_type == TCC_OUTPUT_OBJ && !s->option_r)) - break; - } - - if (s->run_test) { - t = 0; - } else if (s->output_type == TCC_OUTPUT_PREPROCESS) { - ; - } else if (0 == ret) { - if (s->output_type == TCC_OUTPUT_MEMORY) { -#ifdef TCC_IS_NATIVE - ret = tcc_run(s, argc, argv); -#endif - } else { - if (!s->outfile) - s->outfile = default_outputfile(s, first_file); - if (tcc_output_file(s, s->outfile)) - ret = 1; - else if (s->gen_deps) - gen_makedeps(s, s->outfile, s->deps_outfile); - } - } - - if (s->do_bench && (n | t | ret) == 0) - tcc_print_stats(s, getclock_ms() - start_time); - tcc_delete(s); - if (ret == 0 && n) - goto redo; /* compile more files with -c */ - if (t) - goto redo; /* run more tests with -dt -run */ - if (ppfp && ppfp != stdout) - fclose(ppfp); - return ret; -} diff --git a/05/tcc-final-old/tcc.h b/05/tcc-final-old/tcc.h deleted file mode 100644 index cd67973..0000000 --- a/05/tcc-final-old/tcc.h +++ /dev/null @@ -1,1660 +0,0 @@ -/* - * TCC - Tiny C Compiler - * - * Copyright (c) 2001-2004 Fabrice Bellard - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef _TCC_H -#define _TCC_H - -#define _GNU_SOURCE -#include "config.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifndef _WIN32 -# include -# include -# ifndef CONFIG_TCC_STATIC -# include -# endif -/* XXX: need to define this to use them in non ISOC99 context */ -extern float strtof (const char *__nptr, char **__endptr); -extern long double strtold (const char *__nptr, char **__endptr); -#endif - -#ifdef _WIN32 -# include -# include /* open, close etc. */ -# include /* getcwd */ -# ifdef __GNUC__ -# include -# endif -# define inline __inline -# define snprintf _snprintf -# define vsnprintf _vsnprintf -# ifndef __GNUC__ -# define strtold (long double)strtod -# define strtof (float)strtod -# define strtoll _strtoi64 -# define strtoull _strtoui64 -# endif -# ifdef LIBTCC_AS_DLL -# define LIBTCCAPI __declspec(dllexport) -# define PUB_FUNC LIBTCCAPI -# endif -# define inp next_inp /* inp is an intrinsic on msvc/mingw */ -# ifdef _MSC_VER -# pragma warning (disable : 4244) // conversion from 'uint64_t' to 'int', possible loss of data -# pragma warning (disable : 4267) // conversion from 'size_t' to 'int', possible loss of data -# pragma warning (disable : 4996) // The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name -# pragma warning (disable : 4018) // signed/unsigned mismatch -# pragma warning (disable : 4146) // unary minus operator applied to unsigned type, result still unsigned -# define ssize_t intptr_t -# endif -# undef CONFIG_TCC_STATIC -#endif - -#ifndef O_BINARY -# define O_BINARY 0 -#endif - -#ifndef offsetof -#define offsetof(type, field) ((size_t) &((type *)0)->field) -#endif - -#ifndef countof -#define countof(tab) (sizeof(tab) / sizeof((tab)[0])) -#endif - -#ifdef _MSC_VER -# define NORETURN __declspec(noreturn) -# define ALIGNED(x) __declspec(align(x)) -#else -# define NORETURN __attribute__((noreturn)) -# define ALIGNED(x) __attribute__((aligned(x))) -#endif - -#ifdef _WIN32 -# define IS_DIRSEP(c) (c == '/' || c == '\\') -# define IS_ABSPATH(p) (IS_DIRSEP(p[0]) || (p[0] && p[1] == ':' && IS_DIRSEP(p[2]))) -# define PATHCMP stricmp -# define PATHSEP ";" -#else -# define IS_DIRSEP(c) (c == '/') -# define IS_ABSPATH(p) IS_DIRSEP(p[0]) -# define PATHCMP strcmp -# define PATHSEP ":" -#endif - -/* -------------------------------------------- */ - -/* parser debug */ -/* #define PARSE_DEBUG */ -/* preprocessor debug */ -/* #define PP_DEBUG */ -/* include file debug */ -/* #define INC_DEBUG */ -/* memory leak debug */ -/* #define MEM_DEBUG */ -/* assembler debug */ -/* #define ASM_DEBUG */ - -/* target selection */ -/* #define TCC_TARGET_I386 *//* i386 code generator */ -/* #define TCC_TARGET_X86_64 *//* x86-64 code generator */ -/* #define TCC_TARGET_ARM *//* ARMv4 code generator */ -/* #define TCC_TARGET_ARM64 *//* ARMv8 code generator */ -/* #define TCC_TARGET_C67 *//* TMS320C67xx code generator */ - -/* default target is I386 */ -#if !defined(TCC_TARGET_I386) && !defined(TCC_TARGET_ARM) && \ - !defined(TCC_TARGET_ARM64) && !defined(TCC_TARGET_C67) && \ - !defined(TCC_TARGET_X86_64) -# if defined __x86_64__ || defined _AMD64_ -# define TCC_TARGET_X86_64 -# elif defined __arm__ -# define TCC_TARGET_ARM -# define TCC_ARM_EABI -# define TCC_ARM_HARDFLOAT -# elif defined __aarch64__ -# define TCC_TARGET_ARM64 -# else -# define TCC_TARGET_I386 -# endif -# ifdef _WIN32 -# define TCC_TARGET_PE 1 -# endif -#endif - -/* only native compiler supports -run */ -#if defined _WIN32 == defined TCC_TARGET_PE -# if (defined __i386__ || defined _X86_) && defined TCC_TARGET_I386 -# define TCC_IS_NATIVE -# elif (defined __x86_64__ || defined _AMD64_) && defined TCC_TARGET_X86_64 -# define TCC_IS_NATIVE -# elif defined __arm__ && defined TCC_TARGET_ARM -# define TCC_IS_NATIVE -# elif defined __aarch64__ && defined TCC_TARGET_ARM64 -# define TCC_IS_NATIVE -# endif -#endif - -#if defined TCC_IS_NATIVE && !defined CONFIG_TCCBOOT -# define CONFIG_TCC_BACKTRACE -# if (defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64) \ - && !defined TCC_UCLIBC && !defined TCC_MUSL -# define CONFIG_TCC_BCHECK /* enable bound checking code */ -# endif -#endif - -/* ------------ path configuration ------------ */ - -#ifndef CONFIG_SYSROOT -# define CONFIG_SYSROOT "" -#endif -#ifndef CONFIG_TCCDIR -# define CONFIG_TCCDIR "/usr/local/lib/tcc" -#endif -#ifndef CONFIG_LDDIR -# define CONFIG_LDDIR "lib" -#endif -#ifdef CONFIG_TRIPLET -# define USE_TRIPLET(s) s "/" CONFIG_TRIPLET -# define ALSO_TRIPLET(s) USE_TRIPLET(s) ":" s -#else -# define USE_TRIPLET(s) s -# define ALSO_TRIPLET(s) s -#endif - -/* path to find crt1.o, crti.o and crtn.o */ -#ifndef CONFIG_TCC_CRTPREFIX -# define CONFIG_TCC_CRTPREFIX USE_TRIPLET(CONFIG_SYSROOT "/usr/" CONFIG_LDDIR) -#endif - -/* Below: {B} is substituted by CONFIG_TCCDIR (rsp. -B option) */ - -/* system include paths */ -#ifndef CONFIG_TCC_SYSINCLUDEPATHS -# ifdef TCC_TARGET_PE -# define CONFIG_TCC_SYSINCLUDEPATHS "{B}/include"PATHSEP"{B}/include/winapi" -# else -# define CONFIG_TCC_SYSINCLUDEPATHS \ - "{B}/include" \ - ":" ALSO_TRIPLET(CONFIG_SYSROOT "/usr/local/include") \ - ":" ALSO_TRIPLET(CONFIG_SYSROOT "/usr/include") -# endif -#endif - -/* library search paths */ -#ifndef CONFIG_TCC_LIBPATHS -# ifdef TCC_TARGET_PE -# define CONFIG_TCC_LIBPATHS "{B}/lib" -# else -# define CONFIG_TCC_LIBPATHS \ - ALSO_TRIPLET(CONFIG_SYSROOT "/usr/" CONFIG_LDDIR) \ - ":" ALSO_TRIPLET(CONFIG_SYSROOT "/" CONFIG_LDDIR) \ - ":" ALSO_TRIPLET(CONFIG_SYSROOT "/usr/local/" CONFIG_LDDIR) -# endif -#endif - -/* name of ELF interpreter */ -#ifndef CONFIG_TCC_ELFINTERP -# if defined __FreeBSD__ -# define CONFIG_TCC_ELFINTERP "/libexec/ld-elf.so.1" -# elif defined __FreeBSD_kernel__ -# if defined(TCC_TARGET_X86_64) -# define CONFIG_TCC_ELFINTERP "/lib/ld-kfreebsd-x86-64.so.1" -# else -# define CONFIG_TCC_ELFINTERP "/lib/ld.so.1" -# endif -# elif defined __DragonFly__ -# define CONFIG_TCC_ELFINTERP "/usr/libexec/ld-elf.so.2" -# elif defined __NetBSD__ -# define CONFIG_TCC_ELFINTERP "/usr/libexec/ld.elf_so" -# elif defined __GNU__ -# define CONFIG_TCC_ELFINTERP "/lib/ld.so" -# elif defined(TCC_TARGET_PE) -# define CONFIG_TCC_ELFINTERP "-" -# elif defined(TCC_UCLIBC) -# define CONFIG_TCC_ELFINTERP "/lib/ld-uClibc.so.0" /* is there a uClibc for x86_64 ? */ -# elif defined TCC_TARGET_ARM64 -# if defined(TCC_MUSL) -# define CONFIG_TCC_ELFINTERP "/lib/ld-musl-aarch64.so.1" -# else -# define CONFIG_TCC_ELFINTERP "/lib/ld-linux-aarch64.so.1" -# endif -# elif defined(TCC_TARGET_X86_64) -# if defined(TCC_MUSL) -# define CONFIG_TCC_ELFINTERP "/lib/ld-musl-x86_64.so.1" -# else -# define CONFIG_TCC_ELFINTERP "/lib64/ld-linux-x86-64.so.2" -# endif -# elif !defined(TCC_ARM_EABI) -# if defined(TCC_MUSL) -# define CONFIG_TCC_ELFINTERP "/lib/ld-musl-arm.so.1" -# else -# define CONFIG_TCC_ELFINTERP "/lib/ld-linux.so.2" -# endif -# endif -#endif - -/* var elf_interp dans *-gen.c */ -#ifdef CONFIG_TCC_ELFINTERP -# define DEFAULT_ELFINTERP(s) CONFIG_TCC_ELFINTERP -#else -# define DEFAULT_ELFINTERP(s) default_elfinterp(s) -#endif - -/* (target specific) libtcc1.a */ -#ifndef TCC_LIBTCC1 -# define TCC_LIBTCC1 "libtcc1.a" -#endif - -/* library to use with CONFIG_USE_LIBGCC instead of libtcc1.a */ -#if defined CONFIG_USE_LIBGCC && !defined TCC_LIBGCC -#define TCC_LIBGCC USE_TRIPLET(CONFIG_SYSROOT "/" CONFIG_LDDIR) "/libgcc_s.so.1" -#endif - -/* -------------------------------------------- */ - -#include "libtcc.h" -#include "elf.h" -#include "stab.h" - -/* -------------------------------------------- */ - -#ifndef PUB_FUNC /* functions used by tcc.c but not in libtcc.h */ -# define PUB_FUNC -#endif - -#ifndef ONE_SOURCE -# define ONE_SOURCE 1 -#endif - -#if ONE_SOURCE -#define ST_INLN static inline -#define ST_FUNC static -#define ST_DATA static -#else -#define ST_INLN -#define ST_FUNC -#define ST_DATA extern -#endif - -#ifdef TCC_PROFILE /* profile all functions */ -# define static -#endif - -/* -------------------------------------------- */ -/* include the target specific definitions */ - -#define TARGET_DEFS_ONLY -#ifdef TCC_TARGET_I386 -# include "i386-gen.c" -# include "i386-link.c" -#endif -#ifdef TCC_TARGET_X86_64 -# include "x86_64-gen.c" -# include "x86_64-link.c" -#endif -#ifdef TCC_TARGET_ARM -# include "arm-gen.c" -# include "arm-link.c" -# include "arm-asm.c" -#endif -#ifdef TCC_TARGET_ARM64 -# include "arm64-gen.c" -# include "arm64-link.c" -#endif -#ifdef TCC_TARGET_C67 -# define TCC_TARGET_COFF -# include "coff.h" -# include "c67-gen.c" -# include "c67-link.c" -#endif -#undef TARGET_DEFS_ONLY - -/* -------------------------------------------- */ - -#if PTR_SIZE == 8 -# define ELFCLASSW ELFCLASS64 -# define ElfW(type) Elf##64##_##type -# define ELFW(type) ELF##64##_##type -# define ElfW_Rel ElfW(Rela) -# define SHT_RELX SHT_RELA -# define REL_SECTION_FMT ".rela%s" -#else -# define ELFCLASSW ELFCLASS32 -# define ElfW(type) Elf##32##_##type -# define ELFW(type) ELF##32##_##type -# define ElfW_Rel ElfW(Rel) -# define SHT_RELX SHT_REL -# define REL_SECTION_FMT ".rel%s" -#endif -/* target address type */ -#define addr_t ElfW(Addr) -#define ElfSym ElfW(Sym) - -#if PTR_SIZE == 8 && !defined TCC_TARGET_PE -# define LONG_SIZE 8 -#else -# define LONG_SIZE 4 -#endif - -/* -------------------------------------------- */ - -#define INCLUDE_STACK_SIZE 32 -#define IFDEF_STACK_SIZE 64 -#define VSTACK_SIZE 256 -#define STRING_MAX_SIZE 1024 -#define TOKSTR_MAX_SIZE 256 -#define PACK_STACK_SIZE 8 - -#define TOK_HASH_SIZE 16384 /* must be a power of two */ -#define TOK_ALLOC_INCR 512 /* must be a power of two */ -#define TOK_MAX_SIZE 4 /* token max size in int unit when stored in string */ - -/* token symbol management */ -typedef struct TokenSym { - struct TokenSym *hash_next; - struct Sym *sym_define; /* direct pointer to define */ - struct Sym *sym_label; /* direct pointer to label */ - struct Sym *sym_struct; /* direct pointer to structure */ - struct Sym *sym_identifier; /* direct pointer to identifier */ - int tok; /* token number */ - int len; - char str[1]; -} TokenSym; - -#ifdef TCC_TARGET_PE -typedef unsigned short nwchar_t; -#else -typedef int nwchar_t; -#endif - -typedef struct CString { - int size; /* size in bytes */ - void *data; /* either 'char *' or 'nwchar_t *' */ - int size_allocated; -} CString; - -/* type definition */ -typedef struct CType { - int t; - struct Sym *ref; -} CType; - -/* constant value */ -typedef union CValue { - long double ld; - double d; - float f; - uint64_t i; - struct { - int size; - const void *data; - } str; - int tab[LDOUBLE_SIZE/4]; -} CValue; - -/* value on stack */ -typedef struct SValue { - CType type; /* type */ - unsigned short r; /* register + flags */ - unsigned short r2; /* second register, used for 'long long' - type. If not used, set to VT_CONST */ - CValue c; /* constant, if VT_CONST */ - struct Sym *sym; /* symbol, if (VT_SYM | VT_CONST), or if - result of unary() for an identifier. */ -} SValue; - -/* symbol attributes */ -struct SymAttr { - unsigned short - aligned : 5, /* alignment as log2+1 (0 == unspecified) */ - packed : 1, - weak : 1, - visibility : 2, - dllexport : 1, - dllimport : 1, - unused : 5; -}; - -/* function attributes or temporary attributes for parsing */ -struct FuncAttr { - unsigned - func_call : 3, /* calling convention (0..5), see below */ - func_type : 2, /* FUNC_OLD/NEW/ELLIPSIS */ - func_args : 8; /* PE __stdcall args */ -}; - -/* GNUC attribute definition */ -typedef struct AttributeDef { - struct SymAttr a; - struct FuncAttr f; - struct Section *section; - int alias_target; /* token */ - int asm_label; /* associated asm label */ - char attr_mode; /* __attribute__((__mode__(...))) */ -} AttributeDef; - -/* symbol management */ -typedef struct Sym { - int v; /* symbol token */ - unsigned short r; /* associated register or VT_CONST/VT_LOCAL and LVAL type */ - struct SymAttr a; /* symbol attributes */ - union { - struct { - int c; /* associated number or Elf symbol index */ - union { - int sym_scope; /* scope level for locals */ - int jnext; /* next jump label */ - struct FuncAttr f; /* function attributes */ - int auxtype; /* bitfield access type */ - }; - }; - long long enum_val; /* enum constant if IS_ENUM_VAL */ - int *d; /* define token stream */ - }; - CType type; /* associated type */ - union { - struct Sym *next; /* next related symbol (for fields and anoms) */ - int asm_label; /* associated asm label */ - }; - struct Sym *prev; /* prev symbol in stack */ - struct Sym *prev_tok; /* previous symbol for this token */ -} Sym; - -/* section definition */ -typedef struct Section { - unsigned long data_offset; /* current data offset */ - unsigned char *data; /* section data */ - unsigned long data_allocated; /* used for realloc() handling */ - int sh_name; /* elf section name (only used during output) */ - int sh_num; /* elf section number */ - int sh_type; /* elf section type */ - int sh_flags; /* elf section flags */ - int sh_info; /* elf section info */ - int sh_addralign; /* elf section alignment */ - int sh_entsize; /* elf entry size */ - unsigned long sh_size; /* section size (only used during output) */ - addr_t sh_addr; /* address at which the section is relocated */ - unsigned long sh_offset; /* file offset */ - int nb_hashed_syms; /* used to resize the hash table */ - struct Section *link; /* link to another section */ - struct Section *reloc; /* corresponding section for relocation, if any */ - struct Section *hash; /* hash table for symbols */ - struct Section *prev; /* previous section on section stack */ - char name[1]; /* section name */ -} Section; - -typedef struct DLLReference { - int level; - void *handle; - char name[1]; -} DLLReference; - -/* -------------------------------------------------- */ - -#define SYM_STRUCT 0x40000000 /* struct/union/enum symbol space */ -#define SYM_FIELD 0x20000000 /* struct/union field symbol space */ -#define SYM_FIRST_ANOM 0x10000000 /* first anonymous sym */ - -/* stored in 'Sym->f.func_type' field */ -#define FUNC_NEW 1 /* ansi function prototype */ -#define FUNC_OLD 2 /* old function prototype */ -#define FUNC_ELLIPSIS 3 /* ansi function prototype with ... */ - -/* stored in 'Sym->f.func_call' field */ -#define FUNC_CDECL 0 /* standard c call */ -#define FUNC_STDCALL 1 /* pascal c call */ -#define FUNC_FASTCALL1 2 /* first param in %eax */ -#define FUNC_FASTCALL2 3 /* first parameters in %eax, %edx */ -#define FUNC_FASTCALL3 4 /* first parameter in %eax, %edx, %ecx */ -#define FUNC_FASTCALLW 5 /* first parameter in %ecx, %edx */ - -/* field 'Sym.t' for macros */ -#define MACRO_OBJ 0 /* object like macro */ -#define MACRO_FUNC 1 /* function like macro */ - -/* field 'Sym.r' for C labels */ -#define LABEL_DEFINED 0 /* label is defined */ -#define LABEL_FORWARD 1 /* label is forward defined */ -#define LABEL_DECLARED 2 /* label is declared but never used */ - -/* type_decl() types */ -#define TYPE_ABSTRACT 1 /* type without variable */ -#define TYPE_DIRECT 2 /* type with variable */ - -#define IO_BUF_SIZE 8192 - -typedef struct BufferedFile { - uint8_t *buf_ptr; - uint8_t *buf_end; - int fd; - struct BufferedFile *prev; - int line_num; /* current line number - here to simplify code */ - int line_ref; /* tcc -E: last printed line */ - int ifndef_macro; /* #ifndef macro / #endif search */ - int ifndef_macro_saved; /* saved ifndef_macro */ - int *ifdef_stack_ptr; /* ifdef_stack value at the start of the file */ - int include_next_index; /* next search path */ - char filename[1024]; /* filename */ - char *true_filename; /* filename not modified by # line directive */ - unsigned char unget[4]; - unsigned char buffer[1]; /* extra size for CH_EOB char */ -} BufferedFile; - -#define CH_EOB '\\' /* end of buffer or '\0' char in file */ -#define CH_EOF (-1) /* end of file */ - -/* used to record tokens */ -typedef struct TokenString { - int *str; - int len; - int lastlen; - int allocated_len; - int last_line_num; - int save_line_num; - /* used to chain token-strings with begin/end_macro() */ - struct TokenString *prev; - const int *prev_ptr; - char alloc; -} TokenString; - -/* inline functions */ -typedef struct InlineFunc { - TokenString *func_str; - Sym *sym; - char filename[1]; -} InlineFunc; - -/* include file cache, used to find files faster and also to eliminate - inclusion if the include file is protected by #ifndef ... #endif */ -typedef struct CachedInclude { - int ifndef_macro; - int once; - int hash_next; /* -1 if none */ - char filename[1]; /* path specified in #include */ -} CachedInclude; - -#define CACHED_INCLUDES_HASH_SIZE 32 - -#ifdef CONFIG_TCC_ASM -typedef struct ExprValue { - uint64_t v; - Sym *sym; - int pcrel; -} ExprValue; - -#define MAX_ASM_OPERANDS 30 -typedef struct ASMOperand { - int id; /* GCC 3 optional identifier (0 if number only supported */ - char *constraint; - char asm_str[16]; /* computed asm string for operand */ - SValue *vt; /* C value of the expression */ - int ref_index; /* if >= 0, gives reference to a output constraint */ - int input_index; /* if >= 0, gives reference to an input constraint */ - int priority; /* priority, used to assign registers */ - int reg; /* if >= 0, register number used for this operand */ - int is_llong; /* true if double register value */ - int is_memory; /* true if memory operand */ - int is_rw; /* for '+' modifier */ -} ASMOperand; -#endif - -/* extra symbol attributes (not in symbol table) */ -struct sym_attr { - unsigned got_offset; - unsigned plt_offset; - int plt_sym; - int dyn_index; -#ifdef TCC_TARGET_ARM - unsigned char plt_thumb_stub:1; -#endif -}; - -struct TCCState { - - int verbose; /* if true, display some information during compilation */ - int nostdinc; /* if true, no standard headers are added */ - int nostdlib; /* if true, no standard libraries are added */ - int nocommon; /* if true, do not use common symbols for .bss data */ - int static_link; /* if true, static linking is performed */ - int rdynamic; /* if true, all symbols are exported */ - int symbolic; /* if true, resolve symbols in the current module first */ - int alacarte_link; /* if true, only link in referenced objects from archive */ - - char *tcc_lib_path; /* CONFIG_TCCDIR or -B option */ - char *soname; /* as specified on the command line (-soname) */ - char *rpath; /* as specified on the command line (-Wl,-rpath=) */ - int enable_new_dtags; /* ditto, (-Wl,--enable-new-dtags) */ - - /* output type, see TCC_OUTPUT_XXX */ - int output_type; - /* output format, see TCC_OUTPUT_FORMAT_xxx */ - int output_format; - - /* C language options */ - int char_is_unsigned; - int leading_underscore; - int ms_extensions; /* allow nested named struct w/o identifier behave like unnamed */ - int dollars_in_identifiers; /* allows '$' char in identifiers */ - int ms_bitfields; /* if true, emulate MS algorithm for aligning bitfields */ - - /* warning switches */ - int warn_write_strings; - int warn_unsupported; - int warn_error; - int warn_none; - int warn_implicit_function_declaration; - int warn_gcc_compat; - - /* compile with debug symbol (and use them if error during execution) */ - int do_debug; -#ifdef CONFIG_TCC_BCHECK - /* compile with built-in memory and bounds checker */ - int do_bounds_check; -#endif -#ifdef TCC_TARGET_ARM - enum float_abi float_abi; /* float ABI of the generated code*/ -#endif - int run_test; /* nth test to run with -dt -run */ - - addr_t text_addr; /* address of text section */ - int has_text_addr; - - unsigned section_align; /* section alignment */ - - char *init_symbol; /* symbols to call at load-time (not used currently) */ - char *fini_symbol; /* symbols to call at unload-time (not used currently) */ - -#ifdef TCC_TARGET_I386 - int seg_size; /* 32. Can be 16 with i386 assembler (.code16) */ -#endif -#ifdef TCC_TARGET_X86_64 - int nosse; /* For -mno-sse support. */ -#endif - - /* array of all loaded dlls (including those referenced by loaded dlls) */ - DLLReference **loaded_dlls; - int nb_loaded_dlls; - - /* include paths */ - char **include_paths; - int nb_include_paths; - - char **sysinclude_paths; - int nb_sysinclude_paths; - - /* library paths */ - char **library_paths; - int nb_library_paths; - - /* crt?.o object path */ - char **crt_paths; - int nb_crt_paths; - - /* -include files */ - char **cmd_include_files; - int nb_cmd_include_files; - - /* error handling */ - void *error_opaque; - void (*error_func)(void *opaque, const char *msg); - int error_set_jmp_enabled; - jmp_buf error_jmp_buf; - int nb_errors; - - /* output file for preprocessing (-E) */ - FILE *ppfp; - enum { - LINE_MACRO_OUTPUT_FORMAT_GCC, - LINE_MACRO_OUTPUT_FORMAT_NONE, - LINE_MACRO_OUTPUT_FORMAT_STD, - LINE_MACRO_OUTPUT_FORMAT_P10 = 11 - } Pflag; /* -P switch */ - char dflag; /* -dX value */ - - /* for -MD/-MF: collected dependencies for this compilation */ - char **target_deps; - int nb_target_deps; - - /* compilation */ - BufferedFile *include_stack[INCLUDE_STACK_SIZE]; - BufferedFile **include_stack_ptr; - - int ifdef_stack[IFDEF_STACK_SIZE]; - int *ifdef_stack_ptr; - - /* included files enclosed with #ifndef MACRO */ - int cached_includes_hash[CACHED_INCLUDES_HASH_SIZE]; - CachedInclude **cached_includes; - int nb_cached_includes; - - /* #pragma pack stack */ - int pack_stack[PACK_STACK_SIZE]; - int *pack_stack_ptr; - char **pragma_libs; - int nb_pragma_libs; - - /* inline functions are stored as token lists and compiled last - only if referenced */ - struct InlineFunc **inline_fns; - int nb_inline_fns; - - /* sections */ - Section **sections; - int nb_sections; /* number of sections, including first dummy section */ - - Section **priv_sections; - int nb_priv_sections; /* number of private sections */ - - /* got & plt handling */ - Section *got; - Section *plt; - - /* temporary dynamic symbol sections (for dll loading) */ - Section *dynsymtab_section; - /* exported dynamic symbol section */ - Section *dynsym; - /* copy of the global symtab_section variable */ - Section *symtab; - /* extra attributes (eg. GOT/PLT value) for symtab symbols */ - struct sym_attr *sym_attrs; - int nb_sym_attrs; - -#ifdef TCC_TARGET_PE - /* PE info */ - int pe_subsystem; - unsigned pe_characteristics; - unsigned pe_file_align; - unsigned pe_stack_size; - addr_t pe_imagebase; -# ifdef TCC_TARGET_X86_64 - Section *uw_pdata; - int uw_sym; - unsigned uw_offs; -# endif -#endif - -#ifdef TCC_IS_NATIVE - const char *runtime_main; - void **runtime_mem; - int nb_runtime_mem; -#endif - - /* used by main and tcc_parse_args only */ - struct filespec **files; /* files seen on command line */ - int nb_files; /* number thereof */ - int nb_libraries; /* number of libs thereof */ - int filetype; - char *outfile; /* output filename */ - int option_r; /* option -r */ - int do_bench; /* option -bench */ - int gen_deps; /* option -MD */ - char *deps_outfile; /* option -MF */ - int option_pthread; /* -pthread option */ - int argc; - char **argv; -}; - -struct filespec { - char type; - char alacarte; - char name[1]; -}; - -/* The current value can be: */ -#define VT_VALMASK 0x003f /* mask for value location, register or: */ -#define VT_CONST 0x0030 /* constant in vc (must be first non register value) */ -#define VT_LLOCAL 0x0031 /* lvalue, offset on stack */ -#define VT_LOCAL 0x0032 /* offset on stack */ -#define VT_CMP 0x0033 /* the value is stored in processor flags (in vc) */ -#define VT_JMP 0x0034 /* value is the consequence of jmp true (even) */ -#define VT_JMPI 0x0035 /* value is the consequence of jmp false (odd) */ -#define VT_LVAL 0x0100 /* var is an lvalue */ -#define VT_SYM 0x0200 /* a symbol value is added */ -#define VT_MUSTCAST 0x0400 /* value must be casted to be correct (used for - char/short stored in integer registers) */ -#define VT_MUSTBOUND 0x0800 /* bound checking must be done before - dereferencing value */ -#define VT_BOUNDED 0x8000 /* value is bounded. The address of the - bounding function call point is in vc */ -#define VT_LVAL_BYTE 0x1000 /* lvalue is a byte */ -#define VT_LVAL_SHORT 0x2000 /* lvalue is a short */ -#define VT_LVAL_UNSIGNED 0x4000 /* lvalue is unsigned */ -#define VT_LVAL_TYPE (VT_LVAL_BYTE | VT_LVAL_SHORT | VT_LVAL_UNSIGNED) - -/* types */ -#define VT_BTYPE 0x000f /* mask for basic type */ -#define VT_VOID 0 /* void type */ -#define VT_BYTE 1 /* signed byte type */ -#define VT_SHORT 2 /* short type */ -#define VT_INT 3 /* integer type */ -#define VT_LLONG 4 /* 64 bit integer */ -#define VT_PTR 5 /* pointer */ -#define VT_FUNC 6 /* function type */ -#define VT_STRUCT 7 /* struct/union definition */ -#define VT_FLOAT 8 /* IEEE float */ -#define VT_DOUBLE 9 /* IEEE double */ -#define VT_LDOUBLE 10 /* IEEE long double */ -#define VT_BOOL 11 /* ISOC99 boolean type */ -#define VT_QLONG 13 /* 128-bit integer. Only used for x86-64 ABI */ -#define VT_QFLOAT 14 /* 128-bit float. Only used for x86-64 ABI */ - -#define VT_UNSIGNED 0x0010 /* unsigned type */ -#define VT_DEFSIGN 0x0020 /* explicitly signed or unsigned */ -#define VT_ARRAY 0x0040 /* array type (also has VT_PTR) */ -#define VT_BITFIELD 0x0080 /* bitfield modifier */ -#define VT_CONSTANT 0x0100 /* const modifier */ -#define VT_VOLATILE 0x0200 /* volatile modifier */ -#define VT_VLA 0x0400 /* VLA type (also has VT_PTR and VT_ARRAY) */ -#define VT_LONG 0x0800 /* long type (also has VT_INT rsp. VT_LLONG) */ - -/* storage */ -#define VT_EXTERN 0x00001000 /* extern definition */ -#define VT_STATIC 0x00002000 /* static variable */ -#define VT_TYPEDEF 0x00004000 /* typedef definition */ -#define VT_INLINE 0x00008000 /* inline definition */ -/* currently unused: 0x000[1248]0000 */ - -#define VT_STRUCT_SHIFT 20 /* shift for bitfield shift values (32 - 2*6) */ -#define VT_STRUCT_MASK (((1 << (6+6)) - 1) << VT_STRUCT_SHIFT | VT_BITFIELD) -#define BIT_POS(t) (((t) >> VT_STRUCT_SHIFT) & 0x3f) -#define BIT_SIZE(t) (((t) >> (VT_STRUCT_SHIFT + 6)) & 0x3f) - -#define VT_UNION (1 << VT_STRUCT_SHIFT | VT_STRUCT) -#define VT_ENUM (2 << VT_STRUCT_SHIFT) /* integral type is an enum really */ -#define VT_ENUM_VAL (3 << VT_STRUCT_SHIFT) /* integral type is an enum constant really */ - -#define IS_ENUM(t) ((t & VT_STRUCT_MASK) == VT_ENUM) -#define IS_ENUM_VAL(t) ((t & VT_STRUCT_MASK) == VT_ENUM_VAL) -#define IS_UNION(t) ((t & (VT_STRUCT_MASK|VT_BTYPE)) == VT_UNION) - -/* type mask (except storage) */ -#define VT_STORAGE (VT_EXTERN | VT_STATIC | VT_TYPEDEF | VT_INLINE) -#define VT_TYPE (~(VT_STORAGE|VT_STRUCT_MASK)) - -/* symbol was created by tccasm.c first */ -#define VT_ASM (VT_VOID | VT_UNSIGNED) -#define IS_ASM_SYM(sym) (((sym)->type.t & (VT_BTYPE | VT_ASM)) == VT_ASM) - -/* token values */ - -/* warning: the following compare tokens depend on i386 asm code */ -#define TOK_ULT 0x92 -#define TOK_UGE 0x93 -#define TOK_EQ 0x94 -#define TOK_NE 0x95 -#define TOK_ULE 0x96 -#define TOK_UGT 0x97 -#define TOK_Nset 0x98 -#define TOK_Nclear 0x99 -#define TOK_LT 0x9c -#define TOK_GE 0x9d -#define TOK_LE 0x9e -#define TOK_GT 0x9f - -#define TOK_LAND 0xa0 -#define TOK_LOR 0xa1 -#define TOK_DEC 0xa2 -#define TOK_MID 0xa3 /* inc/dec, to void constant */ -#define TOK_INC 0xa4 -#define TOK_UDIV 0xb0 /* unsigned division */ -#define TOK_UMOD 0xb1 /* unsigned modulo */ -#define TOK_PDIV 0xb2 /* fast division with undefined rounding for pointers */ - -/* tokens that carry values (in additional token string space / tokc) --> */ -#define TOK_CCHAR 0xb3 /* char constant in tokc */ -#define TOK_LCHAR 0xb4 -#define TOK_CINT 0xb5 /* number in tokc */ -#define TOK_CUINT 0xb6 /* unsigned int constant */ -#define TOK_CLLONG 0xb7 /* long long constant */ -#define TOK_CULLONG 0xb8 /* unsigned long long constant */ -#define TOK_STR 0xb9 /* pointer to string in tokc */ -#define TOK_LSTR 0xba -#define TOK_CFLOAT 0xbb /* float constant */ -#define TOK_CDOUBLE 0xbc /* double constant */ -#define TOK_CLDOUBLE 0xbd /* long double constant */ -#define TOK_PPNUM 0xbe /* preprocessor number */ -#define TOK_PPSTR 0xbf /* preprocessor string */ -#define TOK_LINENUM 0xc0 /* line number info */ -#define TOK_TWODOTS 0xa8 /* C++ token ? */ -/* <-- */ - -#define TOK_UMULL 0xc2 /* unsigned 32x32 -> 64 mul */ -#define TOK_ADDC1 0xc3 /* add with carry generation */ -#define TOK_ADDC2 0xc4 /* add with carry use */ -#define TOK_SUBC1 0xc5 /* add with carry generation */ -#define TOK_SUBC2 0xc6 /* add with carry use */ -#define TOK_ARROW 0xc7 -#define TOK_DOTS 0xc8 /* three dots */ -#define TOK_SHR 0xc9 /* unsigned shift right */ -#define TOK_TWOSHARPS 0xca /* ## preprocessing token */ -#define TOK_PLCHLDR 0xcb /* placeholder token as defined in C99 */ -#define TOK_NOSUBST 0xcc /* means following token has already been pp'd */ -#define TOK_PPJOIN 0xcd /* A '##' in the right position to mean pasting */ -#define TOK_CLONG 0xce /* long constant */ -#define TOK_CULONG 0xcf /* unsigned long constant */ - -#define TOK_SHL 0x01 /* shift left */ -#define TOK_SAR 0x02 /* signed shift right */ - -/* assignment operators : normal operator or 0x80 */ -#define TOK_A_MOD 0xa5 -#define TOK_A_AND 0xa6 -#define TOK_A_MUL 0xaa -#define TOK_A_ADD 0xab -#define TOK_A_SUB 0xad -#define TOK_A_DIV 0xaf -#define TOK_A_XOR 0xde -#define TOK_A_OR 0xfc -#define TOK_A_SHL 0x81 -#define TOK_A_SAR 0x82 - -#define TOK_EOF (-1) /* end of file */ -#define TOK_LINEFEED 10 /* line feed */ - -/* all identifiers and strings have token above that */ -#define TOK_IDENT 256 - -#define DEF_ASM(x) DEF(TOK_ASM_ ## x, #x) -#define TOK_ASM_int TOK_INT -#define DEF_ASMDIR(x) DEF(TOK_ASMDIR_ ## x, "." #x) -#define TOK_ASMDIR_FIRST TOK_ASMDIR_byte -#define TOK_ASMDIR_LAST TOK_ASMDIR_section - -#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64 -/* only used for i386 asm opcodes definitions */ -#define DEF_BWL(x) \ - DEF(TOK_ASM_ ## x ## b, #x "b") \ - DEF(TOK_ASM_ ## x ## w, #x "w") \ - DEF(TOK_ASM_ ## x ## l, #x "l") \ - DEF(TOK_ASM_ ## x, #x) -#define DEF_WL(x) \ - DEF(TOK_ASM_ ## x ## w, #x "w") \ - DEF(TOK_ASM_ ## x ## l, #x "l") \ - DEF(TOK_ASM_ ## x, #x) -#ifdef TCC_TARGET_X86_64 -# define DEF_BWLQ(x) \ - DEF(TOK_ASM_ ## x ## b, #x "b") \ - DEF(TOK_ASM_ ## x ## w, #x "w") \ - DEF(TOK_ASM_ ## x ## l, #x "l") \ - DEF(TOK_ASM_ ## x ## q, #x "q") \ - DEF(TOK_ASM_ ## x, #x) -# define DEF_WLQ(x) \ - DEF(TOK_ASM_ ## x ## w, #x "w") \ - DEF(TOK_ASM_ ## x ## l, #x "l") \ - DEF(TOK_ASM_ ## x ## q, #x "q") \ - DEF(TOK_ASM_ ## x, #x) -# define DEF_BWLX DEF_BWLQ -# define DEF_WLX DEF_WLQ -/* number of sizes + 1 */ -# define NBWLX 5 -#else -# define DEF_BWLX DEF_BWL -# define DEF_WLX DEF_WL -/* number of sizes + 1 */ -# define NBWLX 4 -#endif - -#define DEF_FP1(x) \ - DEF(TOK_ASM_ ## f ## x ## s, "f" #x "s") \ - DEF(TOK_ASM_ ## fi ## x ## l, "fi" #x "l") \ - DEF(TOK_ASM_ ## f ## x ## l, "f" #x "l") \ - DEF(TOK_ASM_ ## fi ## x ## s, "fi" #x "s") - -#define DEF_FP(x) \ - DEF(TOK_ASM_ ## f ## x, "f" #x ) \ - DEF(TOK_ASM_ ## f ## x ## p, "f" #x "p") \ - DEF_FP1(x) - -#define DEF_ASMTEST(x,suffix) \ - DEF_ASM(x ## o ## suffix) \ - DEF_ASM(x ## no ## suffix) \ - DEF_ASM(x ## b ## suffix) \ - DEF_ASM(x ## c ## suffix) \ - DEF_ASM(x ## nae ## suffix) \ - DEF_ASM(x ## nb ## suffix) \ - DEF_ASM(x ## nc ## suffix) \ - DEF_ASM(x ## ae ## suffix) \ - DEF_ASM(x ## e ## suffix) \ - DEF_ASM(x ## z ## suffix) \ - DEF_ASM(x ## ne ## suffix) \ - DEF_ASM(x ## nz ## suffix) \ - DEF_ASM(x ## be ## suffix) \ - DEF_ASM(x ## na ## suffix) \ - DEF_ASM(x ## nbe ## suffix) \ - DEF_ASM(x ## a ## suffix) \ - DEF_ASM(x ## s ## suffix) \ - DEF_ASM(x ## ns ## suffix) \ - DEF_ASM(x ## p ## suffix) \ - DEF_ASM(x ## pe ## suffix) \ - DEF_ASM(x ## np ## suffix) \ - DEF_ASM(x ## po ## suffix) \ - DEF_ASM(x ## l ## suffix) \ - DEF_ASM(x ## nge ## suffix) \ - DEF_ASM(x ## nl ## suffix) \ - DEF_ASM(x ## ge ## suffix) \ - DEF_ASM(x ## le ## suffix) \ - DEF_ASM(x ## ng ## suffix) \ - DEF_ASM(x ## nle ## suffix) \ - DEF_ASM(x ## g ## suffix) - -#endif /* defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64 */ - -enum tcc_token { - TOK_LAST = TOK_IDENT - 1 -#define DEF(id, str) ,id -#include "tcctok.h" -#undef DEF -}; - -/* keywords: tok >= TOK_IDENT && tok < TOK_UIDENT */ -#define TOK_UIDENT TOK_DEFINE - -/* ------------ libtcc.c ------------ */ - -/* use GNU C extensions */ -ST_DATA int gnu_ext; -/* use Tiny C extensions */ -ST_DATA int tcc_ext; -/* XXX: get rid of this ASAP */ -ST_DATA struct TCCState *tcc_state; - -/* public functions currently used by the tcc main function */ -ST_FUNC char *pstrcpy(char *buf, int buf_size, const char *s); -ST_FUNC char *pstrcat(char *buf, int buf_size, const char *s); -ST_FUNC char *pstrncpy(char *out, const char *in, size_t num); -PUB_FUNC char *tcc_basename(const char *name); -PUB_FUNC char *tcc_fileextension (const char *name); - -#ifndef MEM_DEBUG -PUB_FUNC void tcc_free(void *ptr); -PUB_FUNC void *tcc_malloc(unsigned long size); -PUB_FUNC void *tcc_mallocz(unsigned long size); -PUB_FUNC void *tcc_realloc(void *ptr, unsigned long size); -PUB_FUNC char *tcc_strdup(const char *str); -#else -#define tcc_free(ptr) tcc_free_debug(ptr) -#define tcc_malloc(size) tcc_malloc_debug(size, __FILE__, __LINE__) -#define tcc_mallocz(size) tcc_mallocz_debug(size, __FILE__, __LINE__) -#define tcc_realloc(ptr,size) tcc_realloc_debug(ptr, size, __FILE__, __LINE__) -#define tcc_strdup(str) tcc_strdup_debug(str, __FILE__, __LINE__) -PUB_FUNC void tcc_free_debug(void *ptr); -PUB_FUNC void *tcc_malloc_debug(unsigned long size, const char *file, int line); -PUB_FUNC void *tcc_mallocz_debug(unsigned long size, const char *file, int line); -PUB_FUNC void *tcc_realloc_debug(void *ptr, unsigned long size, const char *file, int line); -PUB_FUNC char *tcc_strdup_debug(const char *str, const char *file, int line); -#endif - -#define free(p) use_tcc_free(p) -#define malloc(s) use_tcc_malloc(s) -#define realloc(p, s) use_tcc_realloc(p, s) -#undef strdup -#define strdup(s) use_tcc_strdup(s) -PUB_FUNC void tcc_memcheck(void); -PUB_FUNC void tcc_error_noabort(const char *fmt, ...); -PUB_FUNC NORETURN void tcc_error(const char *fmt, ...); -PUB_FUNC void tcc_warning(const char *fmt, ...); - -/* other utilities */ -ST_FUNC void dynarray_add(void *ptab, int *nb_ptr, void *data); -ST_FUNC void dynarray_reset(void *pp, int *n); -ST_INLN void cstr_ccat(CString *cstr, int ch); -ST_FUNC void cstr_cat(CString *cstr, const char *str, int len); -ST_FUNC void cstr_wccat(CString *cstr, int ch); -ST_FUNC void cstr_new(CString *cstr); -ST_FUNC void cstr_free(CString *cstr); -ST_FUNC void cstr_reset(CString *cstr); - -ST_INLN void sym_free(Sym *sym); -ST_FUNC Sym *sym_push2(Sym **ps, int v, int t, int c); -ST_FUNC Sym *sym_find2(Sym *s, int v); -ST_FUNC Sym *sym_push(int v, CType *type, int r, int c); -ST_FUNC void sym_pop(Sym **ptop, Sym *b, int keep); -ST_INLN Sym *struct_find(int v); -ST_INLN Sym *sym_find(int v); -ST_FUNC Sym *global_identifier_push(int v, int t, int c); - -ST_FUNC void tcc_open_bf(TCCState *s1, const char *filename, int initlen); -ST_FUNC int tcc_open(TCCState *s1, const char *filename); -ST_FUNC void tcc_close(void); - -ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags); -/* flags: */ -#define AFF_PRINT_ERROR 0x10 /* print error if file not found */ -#define AFF_REFERENCED_DLL 0x20 /* load a referenced dll from another dll */ -#define AFF_TYPE_BIN 0x40 /* file to add is binary */ -/* s->filetype: */ -#define AFF_TYPE_NONE 0 -#define AFF_TYPE_C 1 -#define AFF_TYPE_ASM 2 -#define AFF_TYPE_ASMPP 3 -#define AFF_TYPE_LIB 4 -/* values from tcc_object_type(...) */ -#define AFF_BINTYPE_REL 1 -#define AFF_BINTYPE_DYN 2 -#define AFF_BINTYPE_AR 3 -#define AFF_BINTYPE_C67 4 - - -ST_FUNC int tcc_add_crt(TCCState *s, const char *filename); -ST_FUNC int tcc_add_dll(TCCState *s, const char *filename, int flags); -ST_FUNC void tcc_add_pragma_libs(TCCState *s1); -PUB_FUNC int tcc_add_library_err(TCCState *s, const char *f); -PUB_FUNC void tcc_print_stats(TCCState *s, unsigned total_time); -PUB_FUNC int tcc_parse_args(TCCState *s, int *argc, char ***argv, int optind); -#ifdef _WIN32 -ST_FUNC char *normalize_slashes(char *path); -#endif - -/* tcc_parse_args return codes: */ -#define OPT_HELP 1 -#define OPT_HELP2 2 -#define OPT_V 3 -#define OPT_PRINT_DIRS 4 -#define OPT_AR 5 -#define OPT_IMPDEF 6 -#define OPT_M32 32 -#define OPT_M64 64 - -/* ------------ tccpp.c ------------ */ - -ST_DATA struct BufferedFile *file; -ST_DATA int ch, tok; -ST_DATA CValue tokc; -ST_DATA const int *macro_ptr; -ST_DATA int parse_flags; -ST_DATA int tok_flags; -ST_DATA CString tokcstr; /* current parsed string, if any */ - -/* display benchmark infos */ -ST_DATA int total_lines; -ST_DATA int total_bytes; -ST_DATA int tok_ident; -ST_DATA TokenSym **table_ident; - -#define TOK_FLAG_BOL 0x0001 /* beginning of line before */ -#define TOK_FLAG_BOF 0x0002 /* beginning of file before */ -#define TOK_FLAG_ENDIF 0x0004 /* a endif was found matching starting #ifdef */ -#define TOK_FLAG_EOF 0x0008 /* end of file */ - -#define PARSE_FLAG_PREPROCESS 0x0001 /* activate preprocessing */ -#define PARSE_FLAG_TOK_NUM 0x0002 /* return numbers instead of TOK_PPNUM */ -#define PARSE_FLAG_LINEFEED 0x0004 /* line feed is returned as a - token. line feed is also - returned at eof */ -#define PARSE_FLAG_ASM_FILE 0x0008 /* we processing an asm file: '#' can be used for line comment, etc. */ -#define PARSE_FLAG_SPACES 0x0010 /* next() returns space tokens (for -E) */ -#define PARSE_FLAG_ACCEPT_STRAYS 0x0020 /* next() returns '\\' token */ -#define PARSE_FLAG_TOK_STR 0x0040 /* return parsed strings instead of TOK_PPSTR */ - -/* isidnum_table flags: */ -#define IS_SPC 1 -#define IS_ID 2 -#define IS_NUM 4 - -ST_FUNC TokenSym *tok_alloc(const char *str, int len); -ST_FUNC const char *get_tok_str(int v, CValue *cv); -ST_FUNC void begin_macro(TokenString *str, int alloc); -ST_FUNC void end_macro(void); -ST_FUNC int set_idnum(int c, int val); -ST_INLN void tok_str_new(TokenString *s); -ST_FUNC TokenString *tok_str_alloc(void); -ST_FUNC void tok_str_free(TokenString *s); -ST_FUNC void tok_str_free_str(int *str); -ST_FUNC void tok_str_add(TokenString *s, int t); -ST_FUNC void tok_str_add_tok(TokenString *s); -ST_INLN void define_push(int v, int macro_type, int *str, Sym *first_arg); -ST_FUNC void define_undef(Sym *s); -ST_INLN Sym *define_find(int v); -ST_FUNC void free_defines(Sym *b); -ST_FUNC Sym *label_find(int v); -ST_FUNC Sym *label_push(Sym **ptop, int v, int flags); -ST_FUNC void label_pop(Sym **ptop, Sym *slast, int keep); -ST_FUNC void parse_define(void); -ST_FUNC void preprocess(int is_bof); -ST_FUNC void next_nomacro(void); -ST_FUNC void next(void); -ST_INLN void unget_tok(int last_tok); -ST_FUNC void preprocess_start(TCCState *s1, int is_asm); -ST_FUNC void preprocess_end(TCCState *s1); -ST_FUNC void tccpp_new(TCCState *s); -ST_FUNC void tccpp_delete(TCCState *s); -ST_FUNC int tcc_preprocess(TCCState *s1); -ST_FUNC void skip(int c); -ST_FUNC NORETURN void expect(const char *msg); - -/* space excluding newline */ -static inline int is_space(int ch) { - return ch == ' ' || ch == '\t' || ch == '\v' || ch == '\f' || ch == '\r'; -} -static inline int isid(int c) { - return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_'; -} -static inline int isnum(int c) { - return c >= '0' && c <= '9'; -} -static inline int isoct(int c) { - return c >= '0' && c <= '7'; -} -static inline int toup(int c) { - return (c >= 'a' && c <= 'z') ? c - 'a' + 'A' : c; -} - -/* ------------ tccgen.c ------------ */ - -#define SYM_POOL_NB (8192 / sizeof(Sym)) -ST_DATA Sym *sym_free_first; -ST_DATA void **sym_pools; -ST_DATA int nb_sym_pools; - -ST_DATA Sym *global_stack; -ST_DATA Sym *local_stack; -ST_DATA Sym *local_label_stack; -ST_DATA Sym *global_label_stack; -ST_DATA Sym *define_stack; -ST_DATA CType char_pointer_type, func_old_type, int_type, size_type; -ST_DATA SValue __vstack[1+/*to make bcheck happy*/ VSTACK_SIZE], *vtop, *pvtop; -#define vstack (__vstack + 1) -ST_DATA int rsym, anon_sym, ind, loc; - -ST_DATA int const_wanted; /* true if constant wanted */ -ST_DATA int nocode_wanted; /* true if no code generation wanted for an expression */ -ST_DATA int global_expr; /* true if compound literals must be allocated globally (used during initializers parsing */ -ST_DATA CType func_vt; /* current function return type (used by return instruction) */ -ST_DATA int func_var; /* true if current function is variadic */ -ST_DATA int func_vc; -ST_DATA int last_line_num, last_ind, func_ind; /* debug last line number and pc */ -ST_DATA const char *funcname; -ST_DATA int g_debug; - -ST_FUNC void tcc_debug_start(TCCState *s1); -ST_FUNC void tcc_debug_end(TCCState *s1); -ST_FUNC void tcc_debug_funcstart(TCCState *s1, Sym *sym); -ST_FUNC void tcc_debug_funcend(TCCState *s1, int size); -ST_FUNC void tcc_debug_line(TCCState *s1); - -ST_FUNC int tccgen_compile(TCCState *s1); -ST_FUNC void free_inline_functions(TCCState *s); -ST_FUNC void check_vstack(void); - -ST_INLN int is_float(int t); -ST_FUNC int ieee_finite(double d); -ST_FUNC void test_lvalue(void); -ST_FUNC void vpushi(int v); -ST_FUNC ElfSym *elfsym(Sym *); -ST_FUNC void update_storage(Sym *sym); -ST_FUNC Sym *external_global_sym(int v, CType *type, int r); -ST_FUNC void vset(CType *type, int r, int v); -ST_FUNC void vswap(void); -ST_FUNC void vpush_global_sym(CType *type, int v); -ST_FUNC void vrote(SValue *e, int n); -ST_FUNC void vrott(int n); -ST_FUNC void vrotb(int n); -#ifdef TCC_TARGET_ARM -ST_FUNC int get_reg_ex(int rc, int rc2); -ST_FUNC void lexpand_nr(void); -#endif -ST_FUNC void vpushv(SValue *v); -ST_FUNC void save_reg(int r); -ST_FUNC void save_reg_upstack(int r, int n); -ST_FUNC int get_reg(int rc); -ST_FUNC void save_regs(int n); -ST_FUNC void gaddrof(void); -ST_FUNC int gv(int rc); -ST_FUNC void gv2(int rc1, int rc2); -ST_FUNC void vpop(void); -ST_FUNC void gen_op(int op); -ST_FUNC int type_size(CType *type, int *a); -ST_FUNC void mk_pointer(CType *type); -ST_FUNC void vstore(void); -ST_FUNC void inc(int post, int c); -ST_FUNC void parse_mult_str (CString *astr, const char *msg); -ST_FUNC void parse_asm_str(CString *astr); -ST_FUNC int lvalue_type(int t); -ST_FUNC void indir(void); -ST_FUNC void unary(void); -ST_FUNC void expr_prod(void); -ST_FUNC void expr_sum(void); -ST_FUNC void gexpr(void); -ST_FUNC int expr_const(void); -#if defined CONFIG_TCC_BCHECK || defined TCC_TARGET_C67 -ST_FUNC Sym *get_sym_ref(CType *type, Section *sec, unsigned long offset, unsigned long size); -#endif -#if defined TCC_TARGET_X86_64 && !defined TCC_TARGET_PE -ST_FUNC int classify_x86_64_va_arg(CType *ty); -#endif - -/* ------------ tccelf.c ------------ */ - -#define TCC_OUTPUT_FORMAT_ELF 0 /* default output format: ELF */ -#define TCC_OUTPUT_FORMAT_BINARY 1 /* binary image output */ -#define TCC_OUTPUT_FORMAT_COFF 2 /* COFF */ - -#define ARMAG "!\012" /* For COFF and a.out archives */ - -typedef struct { - unsigned int n_strx; /* index into string table of name */ - unsigned char n_type; /* type of symbol */ - unsigned char n_other; /* misc info (usually empty) */ - unsigned short n_desc; /* description field */ - unsigned int n_value; /* value of symbol */ -} Stab_Sym; - -ST_DATA Section *text_section, *data_section, *bss_section; /* predefined sections */ -ST_DATA Section *common_section; -ST_DATA Section *cur_text_section; /* current section where function code is generated */ -#ifdef CONFIG_TCC_ASM -ST_DATA Section *last_text_section; /* to handle .previous asm directive */ -#endif -#ifdef CONFIG_TCC_BCHECK -/* bound check related sections */ -ST_DATA Section *bounds_section; /* contains global data bound description */ -ST_DATA Section *lbounds_section; /* contains local data bound description */ -ST_FUNC void tccelf_bounds_new(TCCState *s); -#endif -/* symbol sections */ -ST_DATA Section *symtab_section; -/* debug sections */ -ST_DATA Section *stab_section, *stabstr_section; - -ST_FUNC void tccelf_new(TCCState *s); -ST_FUNC void tccelf_delete(TCCState *s); -ST_FUNC void tccelf_stab_new(TCCState *s); -ST_FUNC void tccelf_begin_file(TCCState *s1); -ST_FUNC void tccelf_end_file(TCCState *s1); - -ST_FUNC Section *new_section(TCCState *s1, const char *name, int sh_type, int sh_flags); -ST_FUNC void section_realloc(Section *sec, unsigned long new_size); -ST_FUNC size_t section_add(Section *sec, addr_t size, int align); -ST_FUNC void *section_ptr_add(Section *sec, addr_t size); -ST_FUNC void section_reserve(Section *sec, unsigned long size); -ST_FUNC Section *find_section(TCCState *s1, const char *name); -ST_FUNC Section *new_symtab(TCCState *s1, const char *symtab_name, int sh_type, int sh_flags, const char *strtab_name, const char *hash_name, int hash_sh_flags); - -ST_FUNC void put_extern_sym2(Sym *sym, int sh_num, addr_t value, unsigned long size, int can_add_underscore); -ST_FUNC void put_extern_sym(Sym *sym, Section *section, addr_t value, unsigned long size); -#if PTR_SIZE == 4 -ST_FUNC void greloc(Section *s, Sym *sym, unsigned long offset, int type); -#endif -ST_FUNC void greloca(Section *s, Sym *sym, unsigned long offset, int type, addr_t addend); - -ST_FUNC int put_elf_str(Section *s, const char *sym); -ST_FUNC int put_elf_sym(Section *s, addr_t value, unsigned long size, int info, int other, int shndx, const char *name); -ST_FUNC int set_elf_sym(Section *s, addr_t value, unsigned long size, int info, int other, int shndx, const char *name); -ST_FUNC int find_elf_sym(Section *s, const char *name); -ST_FUNC void put_elf_reloc(Section *symtab, Section *s, unsigned long offset, int type, int symbol); -ST_FUNC void put_elf_reloca(Section *symtab, Section *s, unsigned long offset, int type, int symbol, addr_t addend); - -ST_FUNC void put_stabs(const char *str, int type, int other, int desc, unsigned long value); -ST_FUNC void put_stabs_r(const char *str, int type, int other, int desc, unsigned long value, Section *sec, int sym_index); -ST_FUNC void put_stabn(int type, int other, int desc, int value); -ST_FUNC void put_stabd(int type, int other, int desc); - -ST_FUNC void resolve_common_syms(TCCState *s1); -ST_FUNC void relocate_syms(TCCState *s1, Section *symtab, int do_resolve); -ST_FUNC void relocate_section(TCCState *s1, Section *s); - -ST_FUNC int tcc_object_type(int fd, ElfW(Ehdr) *h); -ST_FUNC int tcc_load_object_file(TCCState *s1, int fd, unsigned long file_offset); -ST_FUNC int tcc_load_archive(TCCState *s1, int fd); -ST_FUNC void tcc_add_bcheck(TCCState *s1); -ST_FUNC void tcc_add_runtime(TCCState *s1); - -ST_FUNC void build_got_entries(TCCState *s1); -ST_FUNC struct sym_attr *get_sym_attr(TCCState *s1, int index, int alloc); -ST_FUNC void squeeze_multi_relocs(Section *sec, size_t oldrelocoffset); - -ST_FUNC addr_t get_elf_sym_addr(TCCState *s, const char *name, int err); -#if defined TCC_IS_NATIVE || defined TCC_TARGET_PE -ST_FUNC void *tcc_get_symbol_err(TCCState *s, const char *name); -#endif - -#ifndef TCC_TARGET_PE -ST_FUNC int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level); -ST_FUNC int tcc_load_ldscript(TCCState *s1); -ST_FUNC uint8_t *parse_comment(uint8_t *p); -ST_FUNC void minp(void); -ST_INLN void inp(void); -ST_FUNC int handle_eob(void); -#endif - -/* ------------ xxx-link.c ------------ */ - -/* Whether to generate a GOT/PLT entry and when. NO_GOTPLT_ENTRY is first so - that unknown relocation don't create a GOT or PLT entry */ -enum gotplt_entry { - NO_GOTPLT_ENTRY, /* never generate (eg. GLOB_DAT & JMP_SLOT relocs) */ - BUILD_GOT_ONLY, /* only build GOT (eg. TPOFF relocs) */ - AUTO_GOTPLT_ENTRY, /* generate if sym is UNDEF */ - ALWAYS_GOTPLT_ENTRY /* always generate (eg. PLTOFF relocs) */ -}; - -ST_FUNC int code_reloc (int reloc_type); -ST_FUNC int gotplt_entry_type (int reloc_type); -ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr); -ST_FUNC void relocate_init(Section *sr); -ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val); -ST_FUNC void relocate_plt(TCCState *s1); - -/* ------------ xxx-gen.c ------------ */ - -ST_DATA const int reg_classes[NB_REGS]; - -ST_FUNC void gsym_addr(int t, int a); -ST_FUNC void gsym(int t); -ST_FUNC void load(int r, SValue *sv); -ST_FUNC void store(int r, SValue *v); -ST_FUNC int gfunc_sret(CType *vt, int variadic, CType *ret, int *align, int *regsize); -ST_FUNC void gfunc_call(int nb_args); -ST_FUNC void gfunc_prolog(CType *func_type); -ST_FUNC void gfunc_epilog(void); -ST_FUNC int gjmp(int t); -ST_FUNC void gjmp_addr(int a); -ST_FUNC int gtst(int inv, int t); -#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64 -ST_FUNC void gtst_addr(int inv, int a); -#else -#define gtst_addr(inv, a) gsym_addr(gtst(inv, 0), a) -#endif -ST_FUNC void gen_opi(int op); -ST_FUNC void gen_opf(int op); -ST_FUNC void gen_cvt_ftoi(int t); -ST_FUNC void gen_cvt_ftof(int t); -ST_FUNC void ggoto(void); -#ifndef TCC_TARGET_C67 -ST_FUNC void o(unsigned int c); -#endif -#ifndef TCC_TARGET_ARM -ST_FUNC void gen_cvt_itof(int t); -#endif -ST_FUNC void gen_vla_sp_save(int addr); -ST_FUNC void gen_vla_sp_restore(int addr); -ST_FUNC void gen_vla_alloc(CType *type, int align); - -static inline uint16_t read16le(unsigned char *p) { - return p[0] | (uint16_t)p[1] << 8; -} -static inline void write16le(unsigned char *p, uint16_t x) { - p[0] = x & 255; p[1] = x >> 8 & 255; -} -static inline uint32_t read32le(unsigned char *p) { - return read16le(p) | (uint32_t)read16le(p + 2) << 16; -} -static inline void write32le(unsigned char *p, uint32_t x) { - write16le(p, x); write16le(p + 2, x >> 16); -} -static inline void add32le(unsigned char *p, int32_t x) { - write32le(p, read32le(p) + x); -} -static inline uint64_t read64le(unsigned char *p) { - return read32le(p) | (uint64_t)read32le(p + 4) << 32; -} -static inline void write64le(unsigned char *p, uint64_t x) { - write32le(p, x); write32le(p + 4, x >> 32); -} -static inline void add64le(unsigned char *p, int64_t x) { - write64le(p, read64le(p) + x); -} - -/* ------------ i386-gen.c ------------ */ -#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64 -ST_FUNC void g(int c); -ST_FUNC void gen_le16(int c); -ST_FUNC void gen_le32(int c); -ST_FUNC void gen_addr32(int r, Sym *sym, int c); -ST_FUNC void gen_addrpc32(int r, Sym *sym, int c); -#endif - -#ifdef CONFIG_TCC_BCHECK -ST_FUNC void gen_bounded_ptr_add(void); -ST_FUNC void gen_bounded_ptr_deref(void); -#endif - -/* ------------ x86_64-gen.c ------------ */ -#ifdef TCC_TARGET_X86_64 -ST_FUNC void gen_addr64(int r, Sym *sym, int64_t c); -ST_FUNC void gen_opl(int op); -#ifdef TCC_TARGET_PE -ST_FUNC void gen_vla_result(int addr); -#endif -#endif - -/* ------------ arm-gen.c ------------ */ -#ifdef TCC_TARGET_ARM -#if defined(TCC_ARM_EABI) && !defined(CONFIG_TCC_ELFINTERP) -PUB_FUNC const char *default_elfinterp(struct TCCState *s); -#endif -ST_FUNC void arm_init(struct TCCState *s); -ST_FUNC void gen_cvt_itof1(int t); -#endif - -/* ------------ arm64-gen.c ------------ */ -#ifdef TCC_TARGET_ARM64 -ST_FUNC void gen_cvt_sxtw(void); -ST_FUNC void gen_opl(int op); -ST_FUNC void gfunc_return(CType *func_type); -ST_FUNC void gen_va_start(void); -ST_FUNC void gen_va_arg(CType *t); -ST_FUNC void gen_clear_cache(void); -#endif - -/* ------------ c67-gen.c ------------ */ -#ifdef TCC_TARGET_C67 -#endif - -/* ------------ tcccoff.c ------------ */ - -#ifdef TCC_TARGET_COFF -ST_FUNC int tcc_output_coff(TCCState *s1, FILE *f); -ST_FUNC int tcc_load_coff(TCCState * s1, int fd); -#endif - -/* ------------ tccasm.c ------------ */ -ST_FUNC void asm_instr(void); -ST_FUNC void asm_global_instr(void); -#ifdef CONFIG_TCC_ASM -ST_FUNC int find_constraint(ASMOperand *operands, int nb_operands, const char *name, const char **pp); -ST_FUNC Sym* get_asm_sym(int name, Sym *csym); -ST_FUNC void asm_expr(TCCState *s1, ExprValue *pe); -ST_FUNC int asm_int_expr(TCCState *s1); -ST_FUNC int tcc_assemble(TCCState *s1, int do_preprocess); -/* ------------ i386-asm.c ------------ */ -ST_FUNC void gen_expr32(ExprValue *pe); -#ifdef TCC_TARGET_X86_64 -ST_FUNC void gen_expr64(ExprValue *pe); -#endif -ST_FUNC void asm_opcode(TCCState *s1, int opcode); -ST_FUNC int asm_parse_regvar(int t); -ST_FUNC void asm_compute_constraints(ASMOperand *operands, int nb_operands, int nb_outputs, const uint8_t *clobber_regs, int *pout_reg); -ST_FUNC void subst_asm_operand(CString *add_str, SValue *sv, int modifier); -ST_FUNC void asm_gen_code(ASMOperand *operands, int nb_operands, int nb_outputs, int is_output, uint8_t *clobber_regs, int out_reg); -ST_FUNC void asm_clobber(uint8_t *clobber_regs, const char *str); -#endif - -/* ------------ tccpe.c -------------- */ -#ifdef TCC_TARGET_PE -ST_FUNC int pe_load_file(struct TCCState *s1, const char *filename, int fd); -ST_FUNC int pe_output_file(TCCState * s1, const char *filename); -ST_FUNC int pe_putimport(TCCState *s1, int dllindex, const char *name, addr_t value); -#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64 -ST_FUNC SValue *pe_getimport(SValue *sv, SValue *v2); -#endif -#ifdef TCC_TARGET_X86_64 -ST_FUNC void pe_add_unwind_data(unsigned start, unsigned end, unsigned stack); -#endif -PUB_FUNC int tcc_get_dllexports(const char *filename, char **pp); -/* symbol properties stored in Elf32_Sym->st_other */ -# define ST_PE_EXPORT 0x10 -# define ST_PE_IMPORT 0x20 -# define ST_PE_STDCALL 0x40 -#endif -#define ST_ASM_SET 0x04 - -/* ------------ tccrun.c ----------------- */ -#ifdef TCC_IS_NATIVE -#ifdef CONFIG_TCC_STATIC -#define RTLD_LAZY 0x001 -#define RTLD_NOW 0x002 -#define RTLD_GLOBAL 0x100 -#define RTLD_DEFAULT NULL -/* dummy function for profiling */ -ST_FUNC void *dlopen(const char *filename, int flag); -ST_FUNC void dlclose(void *p); -ST_FUNC const char *dlerror(void); -ST_FUNC void *dlsym(void *handle, const char *symbol); -#endif -#ifdef CONFIG_TCC_BACKTRACE -ST_DATA int rt_num_callers; -ST_DATA const char **rt_bound_error_msg; -ST_DATA void *rt_prog_main; -ST_FUNC void tcc_set_num_callers(int n); -#endif -ST_FUNC void tcc_run_free(TCCState *s1); -#endif - -/* ------------ tcctools.c ----------------- */ -#if 0 /* included in tcc.c */ -ST_FUNC int tcc_tool_ar(TCCState *s, int argc, char **argv); -#ifdef TCC_TARGET_PE -ST_FUNC int tcc_tool_impdef(TCCState *s, int argc, char **argv); -#endif -ST_FUNC void tcc_tool_cross(TCCState *s, char **argv, int option); -ST_FUNC void gen_makedeps(TCCState *s, const char *target, const char *filename); -#endif - -/********************************************************/ -#undef ST_DATA -#if ONE_SOURCE -#define ST_DATA static -#else -#define ST_DATA -#endif -/********************************************************/ -#endif /* _TCC_H */ diff --git a/05/tcc-final-old/tccasm.c b/05/tcc-final-old/tccasm.c deleted file mode 100644 index c035c8b..0000000 --- a/05/tcc-final-old/tccasm.c +++ /dev/null @@ -1,1277 +0,0 @@ -/* - * GAS like assembler for TCC - * - * Copyright (c) 2001-2004 Fabrice Bellard - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "tcc.h" -#ifdef CONFIG_TCC_ASM - -ST_FUNC int asm_get_local_label_name(TCCState *s1, unsigned int n) -{ - char buf[64]; - TokenSym *ts; - - snprintf(buf, sizeof(buf), "L..%u", n); - ts = tok_alloc(buf, strlen(buf)); - return ts->tok; -} - -static int tcc_assemble_internal(TCCState *s1, int do_preprocess, int global); -static Sym* asm_new_label(TCCState *s1, int label, int is_local); -static Sym* asm_new_label1(TCCState *s1, int label, int is_local, int sh_num, int value); - -static Sym *asm_label_find(int v) -{ - Sym *sym = sym_find(v); - while (sym && sym->sym_scope) - sym = sym->prev_tok; - return sym; -} - -static Sym *asm_label_push(int v) -{ - /* We always add VT_EXTERN, for sym definition that's tentative - (for .set, removed for real defs), for mere references it's correct - as is. */ - Sym *sym = global_identifier_push(v, VT_ASM | VT_EXTERN | VT_STATIC, 0); - sym->r = VT_CONST | VT_SYM; - return sym; -} - -/* Return a symbol we can use inside the assembler, having name NAME. - Symbols from asm and C source share a namespace. If we generate - an asm symbol it's also a (file-global) C symbol, but it's - either not accessible by name (like "L.123"), or its type information - is such that it's not usable without a proper C declaration. - - Sometimes we need symbols accessible by name from asm, which - are anonymous in C, in this case CSYM can be used to transfer - all information from that symbol to the (possibly newly created) - asm symbol. */ -ST_FUNC Sym* get_asm_sym(int name, Sym *csym) -{ - Sym *sym = asm_label_find(name); - if (!sym) { - sym = asm_label_push(name); - if (csym) - sym->c = csym->c; - } - return sym; -} - -static Sym* asm_section_sym(TCCState *s1, Section *sec) -{ - char buf[100]; - int label = tok_alloc(buf, - snprintf(buf, sizeof buf, "L.%s", sec->name) - )->tok; - Sym *sym = asm_label_find(label); - return sym ? sym : asm_new_label1(s1, label, 1, sec->sh_num, 0); -} - -/* We do not use the C expression parser to handle symbols. Maybe the - C expression parser could be tweaked to do so. */ - -static void asm_expr_unary(TCCState *s1, ExprValue *pe) -{ - Sym *sym; - int op, label; - uint64_t n; - const char *p; - - switch(tok) { - case TOK_PPNUM: - p = tokc.str.data; - n = strtoull(p, (char **)&p, 0); - if (*p == 'b' || *p == 'f') { - /* backward or forward label */ - label = asm_get_local_label_name(s1, n); - sym = asm_label_find(label); - if (*p == 'b') { - /* backward : find the last corresponding defined label */ - if (sym && (!sym->c || elfsym(sym)->st_shndx == SHN_UNDEF)) - sym = sym->prev_tok; - if (!sym) - tcc_error("local label '%d' not found backward", n); - } else { - /* forward */ - if (!sym || (sym->c && elfsym(sym)->st_shndx != SHN_UNDEF)) { - /* if the last label is defined, then define a new one */ - sym = asm_label_push(label); - } - } - pe->v = 0; - pe->sym = sym; - pe->pcrel = 0; - } else if (*p == '\0') { - pe->v = n; - pe->sym = NULL; - pe->pcrel = 0; - } else { - tcc_error("invalid number syntax"); - } - next(); - break; - case '+': - next(); - asm_expr_unary(s1, pe); - break; - case '-': - case '~': - op = tok; - next(); - asm_expr_unary(s1, pe); - if (pe->sym) - tcc_error("invalid operation with label"); - if (op == '-') - pe->v = -pe->v; - else - pe->v = ~pe->v; - break; - case TOK_CCHAR: - case TOK_LCHAR: - pe->v = tokc.i; - pe->sym = NULL; - pe->pcrel = 0; - next(); - break; - case '(': - next(); - asm_expr(s1, pe); - skip(')'); - break; - case '.': - pe->v = ind; - pe->sym = asm_section_sym(s1, cur_text_section); - pe->pcrel = 0; - next(); - break; - default: - if (tok >= TOK_IDENT) { - ElfSym *esym; - /* label case : if the label was not found, add one */ - sym = get_asm_sym(tok, NULL); - esym = elfsym(sym); - if (esym && esym->st_shndx == SHN_ABS) { - /* if absolute symbol, no need to put a symbol value */ - pe->v = esym->st_value; - pe->sym = NULL; - pe->pcrel = 0; - } else { - pe->v = 0; - pe->sym = sym; - pe->pcrel = 0; - } - next(); - } else { - tcc_error("bad expression syntax [%s]", get_tok_str(tok, &tokc)); - } - break; - } -} - -static void asm_expr_prod(TCCState *s1, ExprValue *pe) -{ - int op; - ExprValue e2; - - asm_expr_unary(s1, pe); - for(;;) { - op = tok; - if (op != '*' && op != '/' && op != '%' && - op != TOK_SHL && op != TOK_SAR) - break; - next(); - asm_expr_unary(s1, &e2); - if (pe->sym || e2.sym) - tcc_error("invalid operation with label"); - switch(op) { - case '*': - pe->v *= e2.v; - break; - case '/': - if (e2.v == 0) { - div_error: - tcc_error("division by zero"); - } - pe->v /= e2.v; - break; - case '%': - if (e2.v == 0) - goto div_error; - pe->v %= e2.v; - break; - case TOK_SHL: - pe->v <<= e2.v; - break; - default: - case TOK_SAR: - pe->v >>= e2.v; - break; - } - } -} - -static void asm_expr_logic(TCCState *s1, ExprValue *pe) -{ - int op; - ExprValue e2; - - asm_expr_prod(s1, pe); - for(;;) { - op = tok; - if (op != '&' && op != '|' && op != '^') - break; - next(); - asm_expr_prod(s1, &e2); - if (pe->sym || e2.sym) - tcc_error("invalid operation with label"); - switch(op) { - case '&': - pe->v &= e2.v; - break; - case '|': - pe->v |= e2.v; - break; - default: - case '^': - pe->v ^= e2.v; - break; - } - } -} - -static inline void asm_expr_sum(TCCState *s1, ExprValue *pe) -{ - int op; - ExprValue e2; - - asm_expr_logic(s1, pe); - for(;;) { - op = tok; - if (op != '+' && op != '-') - break; - next(); - asm_expr_logic(s1, &e2); - if (op == '+') { - if (pe->sym != NULL && e2.sym != NULL) - goto cannot_relocate; - pe->v += e2.v; - if (pe->sym == NULL && e2.sym != NULL) - pe->sym = e2.sym; - } else { - pe->v -= e2.v; - /* NOTE: we are less powerful than gas in that case - because we store only one symbol in the expression */ - if (!e2.sym) { - /* OK */ - } else if (pe->sym == e2.sym) { - /* OK */ - pe->sym = NULL; /* same symbols can be subtracted to NULL */ - } else { - ElfSym *esym1, *esym2; - esym1 = elfsym(pe->sym); - esym2 = elfsym(e2.sym); - if (esym1 && esym1->st_shndx == esym2->st_shndx - && esym1->st_shndx != SHN_UNDEF) { - /* we also accept defined symbols in the same section */ - pe->v += esym1->st_value - esym2->st_value; - pe->sym = NULL; - } else if (esym2->st_shndx == cur_text_section->sh_num) { - /* When subtracting a defined symbol in current section - this actually makes the value PC-relative. */ - pe->v -= esym2->st_value - ind - 4; - pe->pcrel = 1; - e2.sym = NULL; - } else { -cannot_relocate: - tcc_error("invalid operation with label"); - } - } - } - } -} - -static inline void asm_expr_cmp(TCCState *s1, ExprValue *pe) -{ - int op; - ExprValue e2; - - asm_expr_sum(s1, pe); - for(;;) { - op = tok; - if (op != TOK_EQ && op != TOK_NE - && (op > TOK_GT || op < TOK_ULE)) - break; - next(); - asm_expr_sum(s1, &e2); - if (pe->sym || e2.sym) - tcc_error("invalid operation with label"); - switch(op) { - case TOK_EQ: - pe->v = pe->v == e2.v; - break; - case TOK_NE: - pe->v = pe->v != e2.v; - break; - case TOK_LT: - pe->v = (int64_t)pe->v < (int64_t)e2.v; - break; - case TOK_GE: - pe->v = (int64_t)pe->v >= (int64_t)e2.v; - break; - case TOK_LE: - pe->v = (int64_t)pe->v <= (int64_t)e2.v; - break; - case TOK_GT: - pe->v = (int64_t)pe->v > (int64_t)e2.v; - break; - default: - break; - } - /* GAS compare results are -1/0 not 1/0. */ - pe->v = -(int64_t)pe->v; - } -} - -ST_FUNC void asm_expr(TCCState *s1, ExprValue *pe) -{ - asm_expr_cmp(s1, pe); -} - -ST_FUNC int asm_int_expr(TCCState *s1) -{ - ExprValue e; - asm_expr(s1, &e); - if (e.sym) - expect("constant"); - return e.v; -} - -static Sym* asm_new_label1(TCCState *s1, int label, int is_local, - int sh_num, int value) -{ - Sym *sym; - ElfSym *esym; - - sym = asm_label_find(label); - if (sym) { - esym = elfsym(sym); - /* A VT_EXTERN symbol, even if it has a section is considered - overridable. This is how we "define" .set targets. Real - definitions won't have VT_EXTERN set. */ - if (esym && esym->st_shndx != SHN_UNDEF) { - /* the label is already defined */ - if (IS_ASM_SYM(sym) - && (is_local == 1 || (sym->type.t & VT_EXTERN))) - goto new_label; - if (!(sym->type.t & VT_EXTERN)) - tcc_error("assembler label '%s' already defined", - get_tok_str(label, NULL)); - } - } else { - new_label: - sym = asm_label_push(label); - } - if (!sym->c) - put_extern_sym2(sym, SHN_UNDEF, 0, 0, 0); - esym = elfsym(sym); - esym->st_shndx = sh_num; - esym->st_value = value; - if (is_local != 2) - sym->type.t &= ~VT_EXTERN; - return sym; -} - -static Sym* asm_new_label(TCCState *s1, int label, int is_local) -{ - return asm_new_label1(s1, label, is_local, cur_text_section->sh_num, ind); -} - -/* Set the value of LABEL to that of some expression (possibly - involving other symbols). LABEL can be overwritten later still. */ -static Sym* set_symbol(TCCState *s1, int label) -{ - long n; - ExprValue e; - Sym *sym; - ElfSym *esym; - next(); - asm_expr(s1, &e); - n = e.v; - esym = elfsym(e.sym); - if (esym) - n += esym->st_value; - sym = asm_new_label1(s1, label, 2, esym ? esym->st_shndx : SHN_ABS, n); - elfsym(sym)->st_other |= ST_ASM_SET; - return sym; -} - -static void use_section1(TCCState *s1, Section *sec) -{ - cur_text_section->data_offset = ind; - cur_text_section = sec; - ind = cur_text_section->data_offset; -} - -static void use_section(TCCState *s1, const char *name) -{ - Section *sec; - sec = find_section(s1, name); - use_section1(s1, sec); -} - -static void push_section(TCCState *s1, const char *name) -{ - Section *sec = find_section(s1, name); - sec->prev = cur_text_section; - use_section1(s1, sec); -} - -static void pop_section(TCCState *s1) -{ - Section *prev = cur_text_section->prev; - if (!prev) - tcc_error(".popsection without .pushsection"); - cur_text_section->prev = NULL; - use_section1(s1, prev); -} - -static void asm_parse_directive(TCCState *s1, int global) -{ - int n, offset, v, size, tok1; - Section *sec; - uint8_t *ptr; - - /* assembler directive */ - sec = cur_text_section; - switch(tok) { - case TOK_ASMDIR_align: - case TOK_ASMDIR_balign: - case TOK_ASMDIR_p2align: - case TOK_ASMDIR_skip: - case TOK_ASMDIR_space: - tok1 = tok; - next(); - n = asm_int_expr(s1); - if (tok1 == TOK_ASMDIR_p2align) - { - if (n < 0 || n > 30) - tcc_error("invalid p2align, must be between 0 and 30"); - n = 1 << n; - tok1 = TOK_ASMDIR_align; - } - if (tok1 == TOK_ASMDIR_align || tok1 == TOK_ASMDIR_balign) { - if (n < 0 || (n & (n-1)) != 0) - tcc_error("alignment must be a positive power of two"); - offset = (ind + n - 1) & -n; - size = offset - ind; - /* the section must have a compatible alignment */ - if (sec->sh_addralign < n) - sec->sh_addralign = n; - } else { - if (n < 0) - n = 0; - size = n; - } - v = 0; - if (tok == ',') { - next(); - v = asm_int_expr(s1); - } - zero_pad: - if (sec->sh_type != SHT_NOBITS) { - sec->data_offset = ind; - ptr = section_ptr_add(sec, size); - memset(ptr, v, size); - } - ind += size; - break; - case TOK_ASMDIR_quad: -#ifdef TCC_TARGET_X86_64 - size = 8; - goto asm_data; -#else - next(); - for(;;) { - uint64_t vl; - const char *p; - - p = tokc.str.data; - if (tok != TOK_PPNUM) { - error_constant: - tcc_error("64 bit constant"); - } - vl = strtoll(p, (char **)&p, 0); - if (*p != '\0') - goto error_constant; - next(); - if (sec->sh_type != SHT_NOBITS) { - /* XXX: endianness */ - gen_le32(vl); - gen_le32(vl >> 32); - } else { - ind += 8; - } - if (tok != ',') - break; - next(); - } - break; -#endif - case TOK_ASMDIR_byte: - size = 1; - goto asm_data; - case TOK_ASMDIR_word: - case TOK_ASMDIR_short: - size = 2; - goto asm_data; - case TOK_ASMDIR_long: - case TOK_ASMDIR_int: - size = 4; - asm_data: - next(); - for(;;) { - ExprValue e; - asm_expr(s1, &e); - if (sec->sh_type != SHT_NOBITS) { - if (size == 4) { - gen_expr32(&e); -#ifdef TCC_TARGET_X86_64 - } else if (size == 8) { - gen_expr64(&e); -#endif - } else { - if (e.sym) - expect("constant"); - if (size == 1) - g(e.v); - else - gen_le16(e.v); - } - } else { - ind += size; - } - if (tok != ',') - break; - next(); - } - break; - case TOK_ASMDIR_fill: - { - int repeat, size, val, i, j; - uint8_t repeat_buf[8]; - next(); - repeat = asm_int_expr(s1); - if (repeat < 0) { - tcc_error("repeat < 0; .fill ignored"); - break; - } - size = 1; - val = 0; - if (tok == ',') { - next(); - size = asm_int_expr(s1); - if (size < 0) { - tcc_error("size < 0; .fill ignored"); - break; - } - if (size > 8) - size = 8; - if (tok == ',') { - next(); - val = asm_int_expr(s1); - } - } - /* XXX: endianness */ - repeat_buf[0] = val; - repeat_buf[1] = val >> 8; - repeat_buf[2] = val >> 16; - repeat_buf[3] = val >> 24; - repeat_buf[4] = 0; - repeat_buf[5] = 0; - repeat_buf[6] = 0; - repeat_buf[7] = 0; - for(i = 0; i < repeat; i++) { - for(j = 0; j < size; j++) { - g(repeat_buf[j]); - } - } - } - break; - case TOK_ASMDIR_rept: - { - int repeat; - TokenString *init_str; - next(); - repeat = asm_int_expr(s1); - init_str = tok_str_alloc(); - while (next(), tok != TOK_ASMDIR_endr) { - if (tok == CH_EOF) - tcc_error("we at end of file, .endr not found"); - tok_str_add_tok(init_str); - } - tok_str_add(init_str, -1); - tok_str_add(init_str, 0); - begin_macro(init_str, 1); - while (repeat-- > 0) { - tcc_assemble_internal(s1, (parse_flags & PARSE_FLAG_PREPROCESS), - global); - macro_ptr = init_str->str; - } - end_macro(); - next(); - break; - } - case TOK_ASMDIR_org: - { - unsigned long n; - ExprValue e; - ElfSym *esym; - next(); - asm_expr(s1, &e); - n = e.v; - esym = elfsym(e.sym); - if (esym) { - if (esym->st_shndx != cur_text_section->sh_num) - expect("constant or same-section symbol"); - n += esym->st_value; - } - if (n < ind) - tcc_error("attempt to .org backwards"); - v = 0; - size = n - ind; - goto zero_pad; - } - break; - case TOK_ASMDIR_set: - next(); - tok1 = tok; - next(); - /* Also accept '.set stuff', but don't do anything with this. - It's used in GAS to set various features like '.set mips16'. */ - if (tok == ',') - set_symbol(s1, tok1); - break; - case TOK_ASMDIR_globl: - case TOK_ASMDIR_global: - case TOK_ASMDIR_weak: - case TOK_ASMDIR_hidden: - tok1 = tok; - do { - Sym *sym; - next(); - sym = get_asm_sym(tok, NULL); - if (tok1 != TOK_ASMDIR_hidden) - sym->type.t &= ~VT_STATIC; - if (tok1 == TOK_ASMDIR_weak) - sym->a.weak = 1; - else if (tok1 == TOK_ASMDIR_hidden) - sym->a.visibility = STV_HIDDEN; - update_storage(sym); - next(); - } while (tok == ','); - break; - case TOK_ASMDIR_string: - case TOK_ASMDIR_ascii: - case TOK_ASMDIR_asciz: - { - const uint8_t *p; - int i, size, t; - - t = tok; - next(); - for(;;) { - if (tok != TOK_STR) - expect("string constant"); - p = tokc.str.data; - size = tokc.str.size; - if (t == TOK_ASMDIR_ascii && size > 0) - size--; - for(i = 0; i < size; i++) - g(p[i]); - next(); - if (tok == ',') { - next(); - } else if (tok != TOK_STR) { - break; - } - } - } - break; - case TOK_ASMDIR_text: - case TOK_ASMDIR_data: - case TOK_ASMDIR_bss: - { - char sname[64]; - tok1 = tok; - n = 0; - next(); - if (tok != ';' && tok != TOK_LINEFEED) { - n = asm_int_expr(s1); - next(); - } - if (n) - sprintf(sname, "%s%d", get_tok_str(tok1, NULL), n); - else - sprintf(sname, "%s", get_tok_str(tok1, NULL)); - use_section(s1, sname); - } - break; - case TOK_ASMDIR_file: - { - char filename[512]; - - filename[0] = '\0'; - next(); - - if (tok == TOK_STR) - pstrcat(filename, sizeof(filename), tokc.str.data); - else - pstrcat(filename, sizeof(filename), get_tok_str(tok, NULL)); - - if (s1->warn_unsupported) - tcc_warning("ignoring .file %s", filename); - - next(); - } - break; - case TOK_ASMDIR_ident: - { - char ident[256]; - - ident[0] = '\0'; - next(); - - if (tok == TOK_STR) - pstrcat(ident, sizeof(ident), tokc.str.data); - else - pstrcat(ident, sizeof(ident), get_tok_str(tok, NULL)); - - if (s1->warn_unsupported) - tcc_warning("ignoring .ident %s", ident); - - next(); - } - break; - case TOK_ASMDIR_size: - { - Sym *sym; - - next(); - sym = asm_label_find(tok); - if (!sym) { - tcc_error("label not found: %s", get_tok_str(tok, NULL)); - } - - /* XXX .size name,label2-label1 */ - if (s1->warn_unsupported) - tcc_warning("ignoring .size %s,*", get_tok_str(tok, NULL)); - - next(); - skip(','); - while (tok != TOK_LINEFEED && tok != ';' && tok != CH_EOF) { - next(); - } - } - break; - case TOK_ASMDIR_type: - { - Sym *sym; - const char *newtype; - - next(); - sym = get_asm_sym(tok, NULL); - next(); - skip(','); - if (tok == TOK_STR) { - newtype = tokc.str.data; - } else { - if (tok == '@' || tok == '%') - next(); - newtype = get_tok_str(tok, NULL); - } - - if (!strcmp(newtype, "function") || !strcmp(newtype, "STT_FUNC")) { - sym->type.t = (sym->type.t & ~VT_BTYPE) | VT_FUNC; - } - else if (s1->warn_unsupported) - tcc_warning("change type of '%s' from 0x%x to '%s' ignored", - get_tok_str(sym->v, NULL), sym->type.t, newtype); - - next(); - } - break; - case TOK_ASMDIR_pushsection: - case TOK_ASMDIR_section: - { - char sname[256]; - int old_nb_section = s1->nb_sections; - - tok1 = tok; - /* XXX: support more options */ - next(); - sname[0] = '\0'; - while (tok != ';' && tok != TOK_LINEFEED && tok != ',') { - if (tok == TOK_STR) - pstrcat(sname, sizeof(sname), tokc.str.data); - else - pstrcat(sname, sizeof(sname), get_tok_str(tok, NULL)); - next(); - } - if (tok == ',') { - /* skip section options */ - next(); - if (tok != TOK_STR) - expect("string constant"); - next(); - if (tok == ',') { - next(); - if (tok == '@' || tok == '%') - next(); - next(); - } - } - last_text_section = cur_text_section; - if (tok1 == TOK_ASMDIR_section) - use_section(s1, sname); - else - push_section(s1, sname); - /* If we just allocated a new section reset its alignment to - 1. new_section normally acts for GCC compatibility and - sets alignment to PTR_SIZE. The assembler behaves different. */ - if (old_nb_section != s1->nb_sections) - cur_text_section->sh_addralign = 1; - } - break; - case TOK_ASMDIR_previous: - { - Section *sec; - next(); - if (!last_text_section) - tcc_error("no previous section referenced"); - sec = cur_text_section; - use_section1(s1, last_text_section); - last_text_section = sec; - } - break; - case TOK_ASMDIR_popsection: - next(); - pop_section(s1); - break; -#ifdef TCC_TARGET_I386 - case TOK_ASMDIR_code16: - { - next(); - s1->seg_size = 16; - } - break; - case TOK_ASMDIR_code32: - { - next(); - s1->seg_size = 32; - } - break; -#endif -#ifdef TCC_TARGET_X86_64 - /* added for compatibility with GAS */ - case TOK_ASMDIR_code64: - next(); - break; -#endif - default: - tcc_error("unknown assembler directive '.%s'", get_tok_str(tok, NULL)); - break; - } -} - - -/* assemble a file */ -static int tcc_assemble_internal(TCCState *s1, int do_preprocess, int global) -{ - int opcode; - int saved_parse_flags = parse_flags; - - parse_flags = PARSE_FLAG_ASM_FILE | PARSE_FLAG_TOK_STR; - if (do_preprocess) - parse_flags |= PARSE_FLAG_PREPROCESS; - for(;;) { - next(); - if (tok == TOK_EOF) - break; - /* generate line number info */ - if (global && s1->do_debug) - tcc_debug_line(s1); - parse_flags |= PARSE_FLAG_LINEFEED; /* XXX: suppress that hack */ - redo: - if (tok == '#') { - /* horrible gas comment */ - while (tok != TOK_LINEFEED) - next(); - } else if (tok >= TOK_ASMDIR_FIRST && tok <= TOK_ASMDIR_LAST) { - asm_parse_directive(s1, global); - } else if (tok == TOK_PPNUM) { - const char *p; - int n; - p = tokc.str.data; - n = strtoul(p, (char **)&p, 10); - if (*p != '\0') - expect("':'"); - /* new local label */ - asm_new_label(s1, asm_get_local_label_name(s1, n), 1); - next(); - skip(':'); - goto redo; - } else if (tok >= TOK_IDENT) { - /* instruction or label */ - opcode = tok; - next(); - if (tok == ':') { - /* new label */ - asm_new_label(s1, opcode, 0); - next(); - goto redo; - } else if (tok == '=') { - set_symbol(s1, opcode); - goto redo; - } else { - asm_opcode(s1, opcode); - } - } - /* end of line */ - if (tok != ';' && tok != TOK_LINEFEED) - expect("end of line"); - parse_flags &= ~PARSE_FLAG_LINEFEED; /* XXX: suppress that hack */ - } - - parse_flags = saved_parse_flags; - return 0; -} - -/* Assemble the current file */ -ST_FUNC int tcc_assemble(TCCState *s1, int do_preprocess) -{ - int ret; - tcc_debug_start(s1); - /* default section is text */ - cur_text_section = text_section; - ind = cur_text_section->data_offset; - nocode_wanted = 0; - ret = tcc_assemble_internal(s1, do_preprocess, 1); - cur_text_section->data_offset = ind; - tcc_debug_end(s1); - return ret; -} - -/********************************************************************/ -/* GCC inline asm support */ - -/* assemble the string 'str' in the current C compilation unit without - C preprocessing. NOTE: str is modified by modifying the '\0' at the - end */ -static void tcc_assemble_inline(TCCState *s1, char *str, int len, int global) -{ - const int *saved_macro_ptr = macro_ptr; - int dotid = set_idnum('.', IS_ID); - - tcc_open_bf(s1, ":asm:", len); - memcpy(file->buffer, str, len); - macro_ptr = NULL; - tcc_assemble_internal(s1, 0, global); - tcc_close(); - - set_idnum('.', dotid); - macro_ptr = saved_macro_ptr; -} - -/* find a constraint by its number or id (gcc 3 extended - syntax). return -1 if not found. Return in *pp in char after the - constraint */ -ST_FUNC int find_constraint(ASMOperand *operands, int nb_operands, - const char *name, const char **pp) -{ - int index; - TokenSym *ts; - const char *p; - - if (isnum(*name)) { - index = 0; - while (isnum(*name)) { - index = (index * 10) + (*name) - '0'; - name++; - } - if ((unsigned)index >= nb_operands) - index = -1; - } else if (*name == '[') { - name++; - p = strchr(name, ']'); - if (p) { - ts = tok_alloc(name, p - name); - for(index = 0; index < nb_operands; index++) { - if (operands[index].id == ts->tok) - goto found; - } - index = -1; - found: - name = p + 1; - } else { - index = -1; - } - } else { - index = -1; - } - if (pp) - *pp = name; - return index; -} - -static void subst_asm_operands(ASMOperand *operands, int nb_operands, - CString *out_str, CString *in_str) -{ - int c, index, modifier; - const char *str; - ASMOperand *op; - SValue sv; - - cstr_new(out_str); - str = in_str->data; - for(;;) { - c = *str++; - if (c == '%') { - if (*str == '%') { - str++; - goto add_char; - } - modifier = 0; - if (*str == 'c' || *str == 'n' || - *str == 'b' || *str == 'w' || *str == 'h' || *str == 'k' || - *str == 'q' || - /* P in GCC would add "@PLT" to symbol refs in PIC mode, - and make literal operands not be decorated with '$'. */ - *str == 'P') - modifier = *str++; - index = find_constraint(operands, nb_operands, str, &str); - if (index < 0) - tcc_error("invalid operand reference after %%"); - op = &operands[index]; - sv = *op->vt; - if (op->reg >= 0) { - sv.r = op->reg; - if ((op->vt->r & VT_VALMASK) == VT_LLOCAL && op->is_memory) - sv.r |= VT_LVAL; - } - subst_asm_operand(out_str, &sv, modifier); - } else { - add_char: - cstr_ccat(out_str, c); - if (c == '\0') - break; - } - } -} - - -static void parse_asm_operands(ASMOperand *operands, int *nb_operands_ptr, - int is_output) -{ - ASMOperand *op; - int nb_operands; - - if (tok != ':') { - nb_operands = *nb_operands_ptr; - for(;;) { - CString astr; - if (nb_operands >= MAX_ASM_OPERANDS) - tcc_error("too many asm operands"); - op = &operands[nb_operands++]; - op->id = 0; - if (tok == '[') { - next(); - if (tok < TOK_IDENT) - expect("identifier"); - op->id = tok; - next(); - skip(']'); - } - parse_mult_str(&astr, "string constant"); - op->constraint = tcc_malloc(astr.size); - strcpy(op->constraint, astr.data); - cstr_free(&astr); - skip('('); - gexpr(); - if (is_output) { - if (!(vtop->type.t & VT_ARRAY)) - test_lvalue(); - } else { - /* we want to avoid LLOCAL case, except when the 'm' - constraint is used. Note that it may come from - register storage, so we need to convert (reg) - case */ - if ((vtop->r & VT_LVAL) && - ((vtop->r & VT_VALMASK) == VT_LLOCAL || - (vtop->r & VT_VALMASK) < VT_CONST) && - !strchr(op->constraint, 'm')) { - gv(RC_INT); - } - } - op->vt = vtop; - skip(')'); - if (tok == ',') { - next(); - } else { - break; - } - } - *nb_operands_ptr = nb_operands; - } -} - -/* parse the GCC asm() instruction */ -ST_FUNC void asm_instr(void) -{ - CString astr, astr1; - ASMOperand operands[MAX_ASM_OPERANDS]; - int nb_outputs, nb_operands, i, must_subst, out_reg; - uint8_t clobber_regs[NB_ASM_REGS]; - - next(); - /* since we always generate the asm() instruction, we can ignore - volatile */ - if (tok == TOK_VOLATILE1 || tok == TOK_VOLATILE2 || tok == TOK_VOLATILE3) { - next(); - } - parse_asm_str(&astr); - nb_operands = 0; - nb_outputs = 0; - must_subst = 0; - memset(clobber_regs, 0, sizeof(clobber_regs)); - if (tok == ':') { - next(); - must_subst = 1; - /* output args */ - parse_asm_operands(operands, &nb_operands, 1); - nb_outputs = nb_operands; - if (tok == ':') { - next(); - if (tok != ')') { - /* input args */ - parse_asm_operands(operands, &nb_operands, 0); - if (tok == ':') { - /* clobber list */ - /* XXX: handle registers */ - next(); - for(;;) { - if (tok != TOK_STR) - expect("string constant"); - asm_clobber(clobber_regs, tokc.str.data); - next(); - if (tok == ',') { - next(); - } else { - break; - } - } - } - } - } - } - skip(')'); - /* NOTE: we do not eat the ';' so that we can restore the current - token after the assembler parsing */ - if (tok != ';') - expect("';'"); - - /* save all values in the memory */ - save_regs(0); - - /* compute constraints */ - asm_compute_constraints(operands, nb_operands, nb_outputs, - clobber_regs, &out_reg); - - /* substitute the operands in the asm string. No substitution is - done if no operands (GCC behaviour) */ -#ifdef ASM_DEBUG - printf("asm: \"%s\"\n", (char *)astr.data); -#endif - if (must_subst) { - subst_asm_operands(operands, nb_operands, &astr1, &astr); - cstr_free(&astr); - } else { - astr1 = astr; - } -#ifdef ASM_DEBUG - printf("subst_asm: \"%s\"\n", (char *)astr1.data); -#endif - - /* generate loads */ - asm_gen_code(operands, nb_operands, nb_outputs, 0, - clobber_regs, out_reg); - - /* assemble the string with tcc internal assembler */ - tcc_assemble_inline(tcc_state, astr1.data, astr1.size - 1, 0); - - /* restore the current C token */ - next(); - - /* store the output values if needed */ - asm_gen_code(operands, nb_operands, nb_outputs, 1, - clobber_regs, out_reg); - - /* free everything */ - for(i=0;iconstraint); - vpop(); - } - cstr_free(&astr1); -} - -ST_FUNC void asm_global_instr(void) -{ - CString astr; - int saved_nocode_wanted = nocode_wanted; - - /* Global asm blocks are always emitted. */ - nocode_wanted = 0; - next(); - parse_asm_str(&astr); - skip(')'); - /* NOTE: we do not eat the ';' so that we can restore the current - token after the assembler parsing */ - if (tok != ';') - expect("';'"); - -#ifdef ASM_DEBUG - printf("asm_global: \"%s\"\n", (char *)astr.data); -#endif - cur_text_section = text_section; - ind = cur_text_section->data_offset; - - /* assemble the string with tcc internal assembler */ - tcc_assemble_inline(tcc_state, astr.data, astr.size - 1, 1); - - cur_text_section->data_offset = ind; - - /* restore the current C token */ - next(); - - cstr_free(&astr); - nocode_wanted = saved_nocode_wanted; -} -#endif /* CONFIG_TCC_ASM */ diff --git a/05/tcc-final-old/tcccoff.c b/05/tcc-final-old/tcccoff.c deleted file mode 100644 index 1421ca2..0000000 --- a/05/tcc-final-old/tcccoff.c +++ /dev/null @@ -1,948 +0,0 @@ -/* - * COFF file handling for TCC - * - * Copyright (c) 2003, 2004 TK - * Copyright (c) 2004 Fabrice Bellard - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "tcc.h" - -#define MAXNSCNS 255 /* MAXIMUM NUMBER OF SECTIONS */ -#define MAX_STR_TABLE 1000000 -AOUTHDR o_filehdr; /* OPTIONAL (A.OUT) FILE HEADER */ - -SCNHDR section_header[MAXNSCNS]; - -#define MAX_FUNCS 1000 -#define MAX_FUNC_NAME_LENGTH 128 - -int nFuncs; -char Func[MAX_FUNCS][MAX_FUNC_NAME_LENGTH]; -char AssociatedFile[MAX_FUNCS][MAX_FUNC_NAME_LENGTH]; -int LineNoFilePtr[MAX_FUNCS]; -int EndAddress[MAX_FUNCS]; -int LastLineNo[MAX_FUNCS]; -int FuncEntries[MAX_FUNCS]; - -int OutputTheSection(Section * sect); -short int GetCoffFlags(const char *s); -void SortSymbolTable(void); -Section *FindSection(TCCState * s1, const char *sname); - -int C67_main_entry_point; - -int FindCoffSymbolIndex(const char *func_name); -int nb_syms; - -typedef struct { - long tag; - long size; - long fileptr; - long nextsym; - short int dummy; -} AUXFUNC; - -typedef struct { - long regmask; - unsigned short lineno; - unsigned short nentries; - int localframe; - int nextentry; - short int dummy; -} AUXBF; - -typedef struct { - long dummy; - unsigned short lineno; - unsigned short dummy1; - int dummy2; - int dummy3; - unsigned short dummy4; -} AUXEF; - -ST_FUNC int tcc_output_coff(TCCState *s1, FILE *f) -{ - Section *tcc_sect; - SCNHDR *coff_sec; - int file_pointer; - char *Coff_str_table, *pCoff_str_table; - int CoffTextSectionNo, coff_nb_syms; - FILHDR file_hdr; /* FILE HEADER STRUCTURE */ - Section *stext, *sdata, *sbss; - int i, NSectionsToOutput = 0; - - Coff_str_table = pCoff_str_table = NULL; - - stext = FindSection(s1, ".text"); - sdata = FindSection(s1, ".data"); - sbss = FindSection(s1, ".bss"); - - nb_syms = symtab_section->data_offset / sizeof(Elf32_Sym); - coff_nb_syms = FindCoffSymbolIndex("XXXXXXXXXX1"); - - file_hdr.f_magic = COFF_C67_MAGIC; /* magic number */ - file_hdr.f_timdat = 0; /* time & date stamp */ - file_hdr.f_opthdr = sizeof(AOUTHDR); /* sizeof(optional hdr) */ - file_hdr.f_flags = 0x1143; /* flags (copied from what code composer does) */ - file_hdr.f_TargetID = 0x99; /* for C6x = 0x0099 */ - - o_filehdr.magic = 0x0108; /* see magic.h */ - o_filehdr.vstamp = 0x0190; /* version stamp */ - o_filehdr.tsize = stext->data_offset; /* text size in bytes, padded to FW bdry */ - o_filehdr.dsize = sdata->data_offset; /* initialized data " " */ - o_filehdr.bsize = sbss->data_offset; /* uninitialized data " " */ - o_filehdr.entrypt = C67_main_entry_point; /* entry pt. */ - o_filehdr.text_start = stext->sh_addr; /* base of text used for this file */ - o_filehdr.data_start = sdata->sh_addr; /* base of data used for this file */ - - - // create all the section headers - - file_pointer = FILHSZ + sizeof(AOUTHDR); - - CoffTextSectionNo = -1; - - for (i = 1; i < s1->nb_sections; i++) { - coff_sec = §ion_header[i]; - tcc_sect = s1->sections[i]; - - if (OutputTheSection(tcc_sect)) { - NSectionsToOutput++; - - if (CoffTextSectionNo == -1 && tcc_sect == stext) - CoffTextSectionNo = NSectionsToOutput; // rem which coff sect number the .text sect is - - strcpy(coff_sec->s_name, tcc_sect->name); /* section name */ - - coff_sec->s_paddr = tcc_sect->sh_addr; /* physical address */ - coff_sec->s_vaddr = tcc_sect->sh_addr; /* virtual address */ - coff_sec->s_size = tcc_sect->data_offset; /* section size */ - coff_sec->s_scnptr = 0; /* file ptr to raw data for section */ - coff_sec->s_relptr = 0; /* file ptr to relocation */ - coff_sec->s_lnnoptr = 0; /* file ptr to line numbers */ - coff_sec->s_nreloc = 0; /* number of relocation entries */ - coff_sec->s_flags = GetCoffFlags(coff_sec->s_name); /* flags */ - coff_sec->s_reserved = 0; /* reserved byte */ - coff_sec->s_page = 0; /* memory page id */ - - file_pointer += sizeof(SCNHDR); - } - } - - file_hdr.f_nscns = NSectionsToOutput; /* number of sections */ - - // now loop through and determine file pointer locations - // for the raw data - - - for (i = 1; i < s1->nb_sections; i++) { - coff_sec = §ion_header[i]; - tcc_sect = s1->sections[i]; - - if (OutputTheSection(tcc_sect)) { - // put raw data - coff_sec->s_scnptr = file_pointer; /* file ptr to raw data for section */ - file_pointer += coff_sec->s_size; - } - } - - // now loop through and determine file pointer locations - // for the relocation data - - for (i = 1; i < s1->nb_sections; i++) { - coff_sec = §ion_header[i]; - tcc_sect = s1->sections[i]; - - if (OutputTheSection(tcc_sect)) { - // put relocations data - if (coff_sec->s_nreloc > 0) { - coff_sec->s_relptr = file_pointer; /* file ptr to relocation */ - file_pointer += coff_sec->s_nreloc * sizeof(struct reloc); - } - } - } - - // now loop through and determine file pointer locations - // for the line number data - - for (i = 1; i < s1->nb_sections; i++) { - coff_sec = §ion_header[i]; - tcc_sect = s1->sections[i]; - - coff_sec->s_nlnno = 0; - coff_sec->s_lnnoptr = 0; - - if (s1->do_debug && tcc_sect == stext) { - // count how many line nos data - - // also find association between source file name and function - // so we can sort the symbol table - - - Stab_Sym *sym, *sym_end; - char func_name[MAX_FUNC_NAME_LENGTH], - last_func_name[MAX_FUNC_NAME_LENGTH]; - unsigned long func_addr, last_pc, pc; - const char *incl_files[INCLUDE_STACK_SIZE]; - int incl_index, len, last_line_num; - const char *str, *p; - - coff_sec->s_lnnoptr = file_pointer; /* file ptr to linno */ - - - func_name[0] = '\0'; - func_addr = 0; - incl_index = 0; - last_func_name[0] = '\0'; - last_pc = 0xffffffff; - last_line_num = 1; - sym = (Stab_Sym *) stab_section->data + 1; - sym_end = - (Stab_Sym *) (stab_section->data + - stab_section->data_offset); - - nFuncs = 0; - while (sym < sym_end) { - switch (sym->n_type) { - /* function start or end */ - case N_FUN: - if (sym->n_strx == 0) { - // end of function - - coff_sec->s_nlnno++; - file_pointer += LINESZ; - - pc = sym->n_value + func_addr; - func_name[0] = '\0'; - func_addr = 0; - EndAddress[nFuncs] = pc; - FuncEntries[nFuncs] = - (file_pointer - - LineNoFilePtr[nFuncs]) / LINESZ - 1; - LastLineNo[nFuncs++] = last_line_num + 1; - } else { - // beginning of function - - LineNoFilePtr[nFuncs] = file_pointer; - coff_sec->s_nlnno++; - file_pointer += LINESZ; - - str = - (const char *) stabstr_section->data + - sym->n_strx; - - p = strchr(str, ':'); - if (!p) { - pstrcpy(func_name, sizeof(func_name), str); - pstrcpy(Func[nFuncs], sizeof(func_name), str); - } else { - len = p - str; - if (len > sizeof(func_name) - 1) - len = sizeof(func_name) - 1; - memcpy(func_name, str, len); - memcpy(Func[nFuncs], str, len); - func_name[len] = '\0'; - } - - // save the file that it came in so we can sort later - pstrcpy(AssociatedFile[nFuncs], sizeof(func_name), - incl_files[incl_index - 1]); - - func_addr = sym->n_value; - } - break; - - /* line number info */ - case N_SLINE: - pc = sym->n_value + func_addr; - - last_pc = pc; - last_line_num = sym->n_desc; - - /* XXX: slow! */ - strcpy(last_func_name, func_name); - - coff_sec->s_nlnno++; - file_pointer += LINESZ; - break; - /* include files */ - case N_BINCL: - str = - (const char *) stabstr_section->data + sym->n_strx; - add_incl: - if (incl_index < INCLUDE_STACK_SIZE) { - incl_files[incl_index++] = str; - } - break; - case N_EINCL: - if (incl_index > 1) - incl_index--; - break; - case N_SO: - if (sym->n_strx == 0) { - incl_index = 0; /* end of translation unit */ - } else { - str = - (const char *) stabstr_section->data + - sym->n_strx; - /* do not add path */ - len = strlen(str); - if (len > 0 && str[len - 1] != '/') - goto add_incl; - } - break; - } - sym++; - } - } - - } - - file_hdr.f_symptr = file_pointer; /* file pointer to symtab */ - - if (s1->do_debug) - file_hdr.f_nsyms = coff_nb_syms; /* number of symtab entries */ - else - file_hdr.f_nsyms = 0; - - file_pointer += file_hdr.f_nsyms * SYMNMLEN; - - // OK now we are all set to write the file - - - fwrite(&file_hdr, FILHSZ, 1, f); - fwrite(&o_filehdr, sizeof(o_filehdr), 1, f); - - // write section headers - for (i = 1; i < s1->nb_sections; i++) { - coff_sec = §ion_header[i]; - tcc_sect = s1->sections[i]; - - if (OutputTheSection(tcc_sect)) { - fwrite(coff_sec, sizeof(SCNHDR), 1, f); - } - } - - // write raw data - for (i = 1; i < s1->nb_sections; i++) { - coff_sec = §ion_header[i]; - tcc_sect = s1->sections[i]; - - if (OutputTheSection(tcc_sect)) { - fwrite(tcc_sect->data, tcc_sect->data_offset, 1, f); - } - } - - // write relocation data - for (i = 1; i < s1->nb_sections; i++) { - coff_sec = §ion_header[i]; - tcc_sect = s1->sections[i]; - - if (OutputTheSection(tcc_sect)) { - // put relocations data - if (coff_sec->s_nreloc > 0) { - fwrite(tcc_sect->reloc, - coff_sec->s_nreloc * sizeof(struct reloc), 1, f); - } - } - } - - - // group the symbols in order of filename, func1, func2, etc - // finally global symbols - - if (s1->do_debug) - SortSymbolTable(); - - // write line no data - - for (i = 1; i < s1->nb_sections; i++) { - coff_sec = §ion_header[i]; - tcc_sect = s1->sections[i]; - - if (s1->do_debug && tcc_sect == stext) { - // count how many line nos data - - - Stab_Sym *sym, *sym_end; - char func_name[128], last_func_name[128]; - unsigned long func_addr, last_pc, pc; - const char *incl_files[INCLUDE_STACK_SIZE]; - int incl_index, len, last_line_num; - const char *str, *p; - - LINENO CoffLineNo; - - func_name[0] = '\0'; - func_addr = 0; - incl_index = 0; - last_func_name[0] = '\0'; - last_pc = 0; - last_line_num = 1; - sym = (Stab_Sym *) stab_section->data + 1; - sym_end = - (Stab_Sym *) (stab_section->data + - stab_section->data_offset); - - while (sym < sym_end) { - switch (sym->n_type) { - /* function start or end */ - case N_FUN: - if (sym->n_strx == 0) { - // end of function - - CoffLineNo.l_addr.l_paddr = last_pc; - CoffLineNo.l_lnno = last_line_num + 1; - fwrite(&CoffLineNo, 6, 1, f); - - pc = sym->n_value + func_addr; - func_name[0] = '\0'; - func_addr = 0; - } else { - // beginning of function - - str = - (const char *) stabstr_section->data + - sym->n_strx; - - - p = strchr(str, ':'); - if (!p) { - pstrcpy(func_name, sizeof(func_name), str); - } else { - len = p - str; - if (len > sizeof(func_name) - 1) - len = sizeof(func_name) - 1; - memcpy(func_name, str, len); - func_name[len] = '\0'; - } - func_addr = sym->n_value; - last_pc = func_addr; - last_line_num = -1; - - // output a function begin - - CoffLineNo.l_addr.l_symndx = - FindCoffSymbolIndex(func_name); - CoffLineNo.l_lnno = 0; - - fwrite(&CoffLineNo, 6, 1, f); - } - break; - - /* line number info */ - case N_SLINE: - pc = sym->n_value + func_addr; - - - /* XXX: slow! */ - strcpy(last_func_name, func_name); - - // output a line reference - - CoffLineNo.l_addr.l_paddr = last_pc; - - if (last_line_num == -1) { - CoffLineNo.l_lnno = sym->n_desc; - } else { - CoffLineNo.l_lnno = last_line_num + 1; - } - - fwrite(&CoffLineNo, 6, 1, f); - - last_pc = pc; - last_line_num = sym->n_desc; - - break; - - /* include files */ - case N_BINCL: - str = - (const char *) stabstr_section->data + sym->n_strx; - add_incl2: - if (incl_index < INCLUDE_STACK_SIZE) { - incl_files[incl_index++] = str; - } - break; - case N_EINCL: - if (incl_index > 1) - incl_index--; - break; - case N_SO: - if (sym->n_strx == 0) { - incl_index = 0; /* end of translation unit */ - } else { - str = - (const char *) stabstr_section->data + - sym->n_strx; - /* do not add path */ - len = strlen(str); - if (len > 0 && str[len - 1] != '/') - goto add_incl2; - } - break; - } - sym++; - } - } - } - - // write symbol table - if (s1->do_debug) { - int k; - struct syment csym; - AUXFUNC auxfunc; - AUXBF auxbf; - AUXEF auxef; - int i; - Elf32_Sym *p; - const char *name; - int nstr; - int n = 0; - - Coff_str_table = (char *) tcc_malloc(MAX_STR_TABLE); - pCoff_str_table = Coff_str_table; - nstr = 0; - - p = (Elf32_Sym *) symtab_section->data; - - - for (i = 0; i < nb_syms; i++) { - - name = symtab_section->link->data + p->st_name; - - for (k = 0; k < 8; k++) - csym._n._n_name[k] = 0; - - if (strlen(name) <= 8) { - strcpy(csym._n._n_name, name); - } else { - if (pCoff_str_table - Coff_str_table + strlen(name) > - MAX_STR_TABLE - 1) - tcc_error("String table too large"); - - csym._n._n_n._n_zeroes = 0; - csym._n._n_n._n_offset = - pCoff_str_table - Coff_str_table + 4; - - strcpy(pCoff_str_table, name); - pCoff_str_table += strlen(name) + 1; // skip over null - nstr++; - } - - if (p->st_info == 4) { - // put a filename symbol - csym.n_value = 33; // ????? - csym.n_scnum = N_DEBUG; - csym.n_type = 0; - csym.n_sclass = C_FILE; - csym.n_numaux = 0; - fwrite(&csym, 18, 1, f); - n++; - - } else if (p->st_info == 0x12) { - // find the function data - - for (k = 0; k < nFuncs; k++) { - if (strcmp(name, Func[k]) == 0) - break; - } - - if (k >= nFuncs) { - tcc_error("debug info can't find function: %s", name); - } - // put a Function Name - - csym.n_value = p->st_value; // physical address - csym.n_scnum = CoffTextSectionNo; - csym.n_type = MKTYPE(T_INT, DT_FCN, 0, 0, 0, 0, 0); - csym.n_sclass = C_EXT; - csym.n_numaux = 1; - fwrite(&csym, 18, 1, f); - - // now put aux info - - auxfunc.tag = 0; - auxfunc.size = EndAddress[k] - p->st_value; - auxfunc.fileptr = LineNoFilePtr[k]; - auxfunc.nextsym = n + 6; // tktk - auxfunc.dummy = 0; - fwrite(&auxfunc, 18, 1, f); - - // put a .bf - - strcpy(csym._n._n_name, ".bf"); - csym.n_value = p->st_value; // physical address - csym.n_scnum = CoffTextSectionNo; - csym.n_type = 0; - csym.n_sclass = C_FCN; - csym.n_numaux = 1; - fwrite(&csym, 18, 1, f); - - // now put aux info - - auxbf.regmask = 0; - auxbf.lineno = 0; - auxbf.nentries = FuncEntries[k]; - auxbf.localframe = 0; - auxbf.nextentry = n + 6; - auxbf.dummy = 0; - fwrite(&auxbf, 18, 1, f); - - // put a .ef - - strcpy(csym._n._n_name, ".ef"); - csym.n_value = EndAddress[k]; // physical address - csym.n_scnum = CoffTextSectionNo; - csym.n_type = 0; - csym.n_sclass = C_FCN; - csym.n_numaux = 1; - fwrite(&csym, 18, 1, f); - - // now put aux info - - auxef.dummy = 0; - auxef.lineno = LastLineNo[k]; - auxef.dummy1 = 0; - auxef.dummy2 = 0; - auxef.dummy3 = 0; - auxef.dummy4 = 0; - fwrite(&auxef, 18, 1, f); - - n += 6; - - } else { - // try an put some type info - - if ((p->st_other & VT_BTYPE) == VT_DOUBLE) { - csym.n_type = T_DOUBLE; // int - csym.n_sclass = C_EXT; - } else if ((p->st_other & VT_BTYPE) == VT_FLOAT) { - csym.n_type = T_FLOAT; - csym.n_sclass = C_EXT; - } else if ((p->st_other & VT_BTYPE) == VT_INT) { - csym.n_type = T_INT; // int - csym.n_sclass = C_EXT; - } else if ((p->st_other & VT_BTYPE) == VT_SHORT) { - csym.n_type = T_SHORT; - csym.n_sclass = C_EXT; - } else if ((p->st_other & VT_BTYPE) == VT_BYTE) { - csym.n_type = T_CHAR; - csym.n_sclass = C_EXT; - } else { - csym.n_type = T_INT; // just mark as a label - csym.n_sclass = C_LABEL; - } - - - csym.n_value = p->st_value; - csym.n_scnum = 2; - csym.n_numaux = 1; - fwrite(&csym, 18, 1, f); - - auxfunc.tag = 0; - auxfunc.size = 0x20; - auxfunc.fileptr = 0; - auxfunc.nextsym = 0; - auxfunc.dummy = 0; - fwrite(&auxfunc, 18, 1, f); - n++; - n++; - - } - - p++; - } - } - - if (s1->do_debug) { - // write string table - - // first write the size - i = pCoff_str_table - Coff_str_table; - fwrite(&i, 4, 1, f); - - // then write the strings - fwrite(Coff_str_table, i, 1, f); - - tcc_free(Coff_str_table); - } - - return 0; -} - - - -// group the symbols in order of filename, func1, func2, etc -// finally global symbols - -void SortSymbolTable(void) -{ - int i, j, k, n = 0; - Elf32_Sym *p, *p2, *NewTable; - char *name, *name2; - - NewTable = (Elf32_Sym *) tcc_malloc(nb_syms * sizeof(Elf32_Sym)); - - p = (Elf32_Sym *) symtab_section->data; - - - // find a file symbol, copy it over - // then scan the whole symbol list and copy any function - // symbols that match the file association - - for (i = 0; i < nb_syms; i++) { - if (p->st_info == 4) { - name = (char *) symtab_section->link->data + p->st_name; - - // this is a file symbol, copy it over - - NewTable[n++] = *p; - - p2 = (Elf32_Sym *) symtab_section->data; - - for (j = 0; j < nb_syms; j++) { - if (p2->st_info == 0x12) { - // this is a func symbol - - name2 = - (char *) symtab_section->link->data + p2->st_name; - - // find the function data index - - for (k = 0; k < nFuncs; k++) { - if (strcmp(name2, Func[k]) == 0) - break; - } - - if (k >= nFuncs) { - tcc_error("debug (sort) info can't find function: %s", name2); - } - - if (strcmp(AssociatedFile[k], name) == 0) { - // yes they match copy it over - - NewTable[n++] = *p2; - } - } - p2++; - } - } - p++; - } - - // now all the filename and func symbols should have been copied over - // copy all the rest over (all except file and funcs) - - p = (Elf32_Sym *) symtab_section->data; - for (i = 0; i < nb_syms; i++) { - if (p->st_info != 4 && p->st_info != 0x12) { - NewTable[n++] = *p; - } - p++; - } - - if (n != nb_syms) - tcc_error("Internal Compiler error, debug info"); - - // copy it all back - - p = (Elf32_Sym *) symtab_section->data; - for (i = 0; i < nb_syms; i++) { - *p++ = NewTable[i]; - } - - tcc_free(NewTable); -} - - -int FindCoffSymbolIndex(const char *func_name) -{ - int i, n = 0; - Elf32_Sym *p; - char *name; - - p = (Elf32_Sym *) symtab_section->data; - - for (i = 0; i < nb_syms; i++) { - - name = (char *) symtab_section->link->data + p->st_name; - - if (p->st_info == 4) { - // put a filename symbol - n++; - } else if (p->st_info == 0x12) { - - if (strcmp(func_name, name) == 0) - return n; - - n += 6; - - // put a Function Name - - // now put aux info - - // put a .bf - - // now put aux info - - // put a .ef - - // now put aux info - - } else { - n += 2; - } - - p++; - } - - return n; // total number of symbols -} - -int OutputTheSection(Section * sect) -{ - const char *s = sect->name; - - if (!strcmp(s, ".text")) - return 1; - else if (!strcmp(s, ".data")) - return 1; - else - return 0; -} - -short int GetCoffFlags(const char *s) -{ - if (!strcmp(s, ".text")) - return STYP_TEXT | STYP_DATA | STYP_ALIGN | 0x400; - else if (!strcmp(s, ".data")) - return STYP_DATA; - else if (!strcmp(s, ".bss")) - return STYP_BSS; - else if (!strcmp(s, ".stack")) - return STYP_BSS | STYP_ALIGN | 0x200; - else if (!strcmp(s, ".cinit")) - return STYP_COPY | STYP_DATA | STYP_ALIGN | 0x200; - else - return 0; -} - -Section *FindSection(TCCState * s1, const char *sname) -{ - Section *s; - int i; - - for (i = 1; i < s1->nb_sections; i++) { - s = s1->sections[i]; - - if (!strcmp(sname, s->name)) - return s; - } - - tcc_error("could not find section %s", sname); - return 0; -} - -ST_FUNC int tcc_load_coff(TCCState * s1, int fd) -{ -// tktk TokenSym *ts; - - FILE *f; - unsigned int str_size; - char *Coff_str_table, *name; - int i, k; - struct syment csym; - char name2[9]; - FILHDR file_hdr; /* FILE HEADER STRUCTURE */ - - f = fdopen(fd, "rb"); - if (!f) { - tcc_error("Unable to open .out file for input"); - } - - if (fread(&file_hdr, FILHSZ, 1, f) != 1) - tcc_error("error reading .out file for input"); - - if (fread(&o_filehdr, sizeof(o_filehdr), 1, f) != 1) - tcc_error("error reading .out file for input"); - - // first read the string table - - if (fseek(f, file_hdr.f_symptr + file_hdr.f_nsyms * SYMESZ, SEEK_SET)) - tcc_error("error reading .out file for input"); - - if (fread(&str_size, sizeof(int), 1, f) != 1) - tcc_error("error reading .out file for input"); - - - Coff_str_table = (char *) tcc_malloc(str_size); - - if (fread(Coff_str_table, str_size - 4, 1, f) != 1) - tcc_error("error reading .out file for input"); - - // read/process all the symbols - - // seek back to symbols - - if (fseek(f, file_hdr.f_symptr, SEEK_SET)) - tcc_error("error reading .out file for input"); - - for (i = 0; i < file_hdr.f_nsyms; i++) { - if (fread(&csym, SYMESZ, 1, f) != 1) - tcc_error("error reading .out file for input"); - - if (csym._n._n_n._n_zeroes == 0) { - name = Coff_str_table + csym._n._n_n._n_offset - 4; - } else { - name = csym._n._n_name; - - if (name[7] != 0) { - for (k = 0; k < 8; k++) - name2[k] = name[k]; - - name2[8] = 0; - - name = name2; - } - } -// if (strcmp("_DAC_Buffer",name)==0) // tktk -// name[0]=0; - - if (((csym.n_type & 0x30) == 0x20 && csym.n_sclass == 0x2) || ((csym.n_type & 0x30) == 0x30 && csym.n_sclass == 0x2) || (csym.n_type == 0x4 && csym.n_sclass == 0x2) || (csym.n_type == 0x8 && csym.n_sclass == 0x2) || // structures - (csym.n_type == 0x18 && csym.n_sclass == 0x2) || // pointer to structure - (csym.n_type == 0x7 && csym.n_sclass == 0x2) || // doubles - (csym.n_type == 0x6 && csym.n_sclass == 0x2)) // floats - { - // strip off any leading underscore (except for other main routine) - - if (name[0] == '_' && strcmp(name, "_main") != 0) - name++; - - tcc_add_symbol(s1, name, (void*)(uintptr_t)csym.n_value); - } - // skip any aux records - - if (csym.n_numaux == 1) { - if (fread(&csym, SYMESZ, 1, f) != 1) - tcc_error("error reading .out file for input"); - i++; - } - } - - return 0; -} diff --git a/05/tcc-final-old/tccelf.c b/05/tcc-final-old/tccelf.c deleted file mode 100644 index 70d47e1..0000000 --- a/05/tcc-final-old/tccelf.c +++ /dev/null @@ -1,3058 +0,0 @@ -/* - * ELF file handling for TCC - * - * Copyright (c) 2001-2004 Fabrice Bellard - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "tcc.h" - -/* Define this to get some debug output during relocation processing. */ -#undef DEBUG_RELOC - -/********************************************************/ -/* global variables */ - -ST_DATA Section *text_section, *data_section, *bss_section; /* predefined sections */ -ST_DATA Section *common_section; -ST_DATA Section *cur_text_section; /* current section where function code is generated */ -#ifdef CONFIG_TCC_ASM -ST_DATA Section *last_text_section; /* to handle .previous asm directive */ -#endif -#ifdef CONFIG_TCC_BCHECK -/* bound check related sections */ -ST_DATA Section *bounds_section; /* contains global data bound description */ -ST_DATA Section *lbounds_section; /* contains local data bound description */ -#endif -/* symbol sections */ -ST_DATA Section *symtab_section; -/* debug sections */ -ST_DATA Section *stab_section, *stabstr_section; - -/* XXX: avoid static variable */ -static int new_undef_sym = 0; /* Is there a new undefined sym since last new_undef_sym() */ - -/* special flag to indicate that the section should not be linked to the other ones */ -#define SHF_PRIVATE 0x80000000 -/* section is dynsymtab_section */ -#define SHF_DYNSYM 0x40000000 - -/* ------------------------------------------------------------------------- */ - -ST_FUNC void tccelf_new(TCCState *s) -{ - /* no section zero */ - dynarray_add(&s->sections, &s->nb_sections, NULL); - - /* create standard sections */ - text_section = new_section(s, ".text", SHT_PROGBITS, SHF_ALLOC | SHF_EXECINSTR); - data_section = new_section(s, ".data", SHT_PROGBITS, SHF_ALLOC | SHF_WRITE); - bss_section = new_section(s, ".bss", SHT_NOBITS, SHF_ALLOC | SHF_WRITE); - common_section = new_section(s, ".common", SHT_NOBITS, SHF_PRIVATE); - common_section->sh_num = SHN_COMMON; - - /* symbols are always generated for linking stage */ - symtab_section = new_symtab(s, ".symtab", SHT_SYMTAB, 0, - ".strtab", - ".hashtab", SHF_PRIVATE); - s->symtab = symtab_section; - - /* private symbol table for dynamic symbols */ - s->dynsymtab_section = new_symtab(s, ".dynsymtab", SHT_SYMTAB, SHF_PRIVATE|SHF_DYNSYM, - ".dynstrtab", - ".dynhashtab", SHF_PRIVATE); - get_sym_attr(s, 0, 1); -} - -#ifdef CONFIG_TCC_BCHECK -ST_FUNC void tccelf_bounds_new(TCCState *s) -{ - /* create bounds sections */ - bounds_section = new_section(s, ".bounds", - SHT_PROGBITS, SHF_ALLOC); - lbounds_section = new_section(s, ".lbounds", - SHT_PROGBITS, SHF_ALLOC); -} -#endif - -ST_FUNC void tccelf_stab_new(TCCState *s) -{ - stab_section = new_section(s, ".stab", SHT_PROGBITS, 0); - stab_section->sh_entsize = sizeof(Stab_Sym); - stabstr_section = new_section(s, ".stabstr", SHT_STRTAB, 0); - put_elf_str(stabstr_section, ""); - stab_section->link = stabstr_section; - /* put first entry */ - put_stabs("", 0, 0, 0, 0); -} - -static void free_section(Section *s) -{ - tcc_free(s->data); -} - -ST_FUNC void tccelf_delete(TCCState *s1) -{ - int i; - - /* free all sections */ - for(i = 1; i < s1->nb_sections; i++) - free_section(s1->sections[i]); - dynarray_reset(&s1->sections, &s1->nb_sections); - - for(i = 0; i < s1->nb_priv_sections; i++) - free_section(s1->priv_sections[i]); - dynarray_reset(&s1->priv_sections, &s1->nb_priv_sections); - - /* free any loaded DLLs */ -#ifdef TCC_IS_NATIVE - for ( i = 0; i < s1->nb_loaded_dlls; i++) { - DLLReference *ref = s1->loaded_dlls[i]; - if ( ref->handle ) -# ifdef _WIN32 - FreeLibrary((HMODULE)ref->handle); -# else - dlclose(ref->handle); -# endif - } -#endif - /* free loaded dlls array */ - dynarray_reset(&s1->loaded_dlls, &s1->nb_loaded_dlls); - tcc_free(s1->sym_attrs); - - symtab_section = NULL; /* for tccrun.c:rt_printline() */ -} - -/* save section data state */ -ST_FUNC void tccelf_begin_file(TCCState *s1) -{ - Section *s; int i; - for (i = 1; i < s1->nb_sections; i++) { - s = s1->sections[i]; - s->sh_offset = s->data_offset; - } - /* disable symbol hashing during compilation */ - s = s1->symtab, s->reloc = s->hash, s->hash = NULL; -#if defined TCC_TARGET_X86_64 && defined TCC_TARGET_PE - s1->uw_sym = 0; -#endif -} - -/* At the end of compilation, convert any UNDEF syms to global, and merge - with previously existing symbols */ -ST_FUNC void tccelf_end_file(TCCState *s1) -{ - Section *s = s1->symtab; - int first_sym, nb_syms, *tr, i; - - first_sym = s->sh_offset / sizeof (ElfSym); - nb_syms = s->data_offset / sizeof (ElfSym) - first_sym; - s->data_offset = s->sh_offset; - s->link->data_offset = s->link->sh_offset; - s->hash = s->reloc, s->reloc = NULL; - tr = tcc_mallocz(nb_syms * sizeof *tr); - - for (i = 0; i < nb_syms; ++i) { - ElfSym *sym = (ElfSym*)s->data + first_sym + i; - if (sym->st_shndx == SHN_UNDEF - && ELFW(ST_BIND)(sym->st_info) == STB_LOCAL) - sym->st_info = ELFW(ST_INFO)(STB_GLOBAL, ELFW(ST_TYPE)(sym->st_info)); - tr[i] = set_elf_sym(s, sym->st_value, sym->st_size, sym->st_info, - sym->st_other, sym->st_shndx, s->link->data + sym->st_name); - } - /* now update relocations */ - for (i = 1; i < s1->nb_sections; i++) { - Section *sr = s1->sections[i]; - if (sr->sh_type == SHT_RELX && sr->link == s) { - ElfW_Rel *rel = (ElfW_Rel*)(sr->data + sr->sh_offset); - ElfW_Rel *rel_end = (ElfW_Rel*)(sr->data + sr->data_offset); - for (; rel < rel_end; ++rel) { - int n = ELFW(R_SYM)(rel->r_info) - first_sym; - //if (n < 0) tcc_error("internal: invalid symbol index in relocation"); - rel->r_info = ELFW(R_INFO)(tr[n], ELFW(R_TYPE)(rel->r_info)); - } - } - } - tcc_free(tr); -} - -ST_FUNC Section *new_section(TCCState *s1, const char *name, int sh_type, int sh_flags) -{ - Section *sec; - - sec = tcc_mallocz(sizeof(Section) + strlen(name)); - strcpy(sec->name, name); - sec->sh_type = sh_type; - sec->sh_flags = sh_flags; - switch(sh_type) { - case SHT_HASH: - case SHT_REL: - case SHT_RELA: - case SHT_DYNSYM: - case SHT_SYMTAB: - case SHT_DYNAMIC: - sec->sh_addralign = 4; - break; - case SHT_STRTAB: - sec->sh_addralign = 1; - break; - default: - sec->sh_addralign = PTR_SIZE; /* gcc/pcc default alignment */ - break; - } - - if (sh_flags & SHF_PRIVATE) { - dynarray_add(&s1->priv_sections, &s1->nb_priv_sections, sec); - } else { - sec->sh_num = s1->nb_sections; - dynarray_add(&s1->sections, &s1->nb_sections, sec); - } - - return sec; -} - -ST_FUNC Section *new_symtab(TCCState *s1, - const char *symtab_name, int sh_type, int sh_flags, - const char *strtab_name, - const char *hash_name, int hash_sh_flags) -{ - Section *symtab, *strtab, *hash; - int *ptr, nb_buckets; - - symtab = new_section(s1, symtab_name, sh_type, sh_flags); - symtab->sh_entsize = sizeof(ElfW(Sym)); - strtab = new_section(s1, strtab_name, SHT_STRTAB, sh_flags); - put_elf_str(strtab, ""); - symtab->link = strtab; - put_elf_sym(symtab, 0, 0, 0, 0, 0, NULL); - - nb_buckets = 1; - - hash = new_section(s1, hash_name, SHT_HASH, hash_sh_flags); - hash->sh_entsize = sizeof(int); - symtab->hash = hash; - hash->link = symtab; - - ptr = section_ptr_add(hash, (2 + nb_buckets + 1) * sizeof(int)); - ptr[0] = nb_buckets; - ptr[1] = 1; - memset(ptr + 2, 0, (nb_buckets + 1) * sizeof(int)); - return symtab; -} - -/* realloc section and set its content to zero */ -ST_FUNC void section_realloc(Section *sec, unsigned long new_size) -{ - unsigned long size; - unsigned char *data; - - size = sec->data_allocated; - if (size == 0) - size = 1; - while (size < new_size) - size = size * 2; - data = tcc_realloc(sec->data, size); - memset(data + sec->data_allocated, 0, size - sec->data_allocated); - sec->data = data; - sec->data_allocated = size; -} - -/* reserve at least 'size' bytes aligned per 'align' in section - 'sec' from current offset, and return the aligned offset */ -ST_FUNC size_t section_add(Section *sec, addr_t size, int align) -{ - size_t offset, offset1; - - offset = (sec->data_offset + align - 1) & -align; - offset1 = offset + size; - if (sec->sh_type != SHT_NOBITS && offset1 > sec->data_allocated) - section_realloc(sec, offset1); - sec->data_offset = offset1; - if (align > sec->sh_addralign) - sec->sh_addralign = align; - return offset; -} - -/* reserve at least 'size' bytes in section 'sec' from - sec->data_offset. */ -ST_FUNC void *section_ptr_add(Section *sec, addr_t size) -{ - size_t offset = section_add(sec, size, 1); - return sec->data + offset; -} - -/* reserve at least 'size' bytes from section start */ -ST_FUNC void section_reserve(Section *sec, unsigned long size) -{ - if (size > sec->data_allocated) - section_realloc(sec, size); - if (size > sec->data_offset) - sec->data_offset = size; -} - -/* return a reference to a section, and create it if it does not - exists */ -ST_FUNC Section *find_section(TCCState *s1, const char *name) -{ - Section *sec; - int i; - for(i = 1; i < s1->nb_sections; i++) { - sec = s1->sections[i]; - if (!strcmp(name, sec->name)) - return sec; - } - /* sections are created as PROGBITS */ - return new_section(s1, name, SHT_PROGBITS, SHF_ALLOC); -} - -/* ------------------------------------------------------------------------- */ - -ST_FUNC int put_elf_str(Section *s, const char *sym) -{ - int offset, len; - char *ptr; - - len = strlen(sym) + 1; - offset = s->data_offset; - ptr = section_ptr_add(s, len); - memmove(ptr, sym, len); - return offset; -} - -/* elf symbol hashing function */ -static unsigned long elf_hash(const unsigned char *name) -{ - unsigned long h = 0, g; - - while (*name) { - h = (h << 4) + *name++; - g = h & 0xf0000000; - if (g) - h ^= g >> 24; - h &= ~g; - } - return h; -} - -/* rebuild hash table of section s */ -/* NOTE: we do factorize the hash table code to go faster */ -static void rebuild_hash(Section *s, unsigned int nb_buckets) -{ - ElfW(Sym) *sym; - int *ptr, *hash, nb_syms, sym_index, h; - unsigned char *strtab; - - strtab = s->link->data; - nb_syms = s->data_offset / sizeof(ElfW(Sym)); - - if (!nb_buckets) - nb_buckets = ((int*)s->hash->data)[0]; - - s->hash->data_offset = 0; - ptr = section_ptr_add(s->hash, (2 + nb_buckets + nb_syms) * sizeof(int)); - ptr[0] = nb_buckets; - ptr[1] = nb_syms; - ptr += 2; - hash = ptr; - memset(hash, 0, (nb_buckets + 1) * sizeof(int)); - ptr += nb_buckets + 1; - - sym = (ElfW(Sym) *)s->data + 1; - for(sym_index = 1; sym_index < nb_syms; sym_index++) { - if (ELFW(ST_BIND)(sym->st_info) != STB_LOCAL) { - h = elf_hash(strtab + sym->st_name) % nb_buckets; - *ptr = hash[h]; - hash[h] = sym_index; - } else { - *ptr = 0; - } - ptr++; - sym++; - } -} - -/* return the symbol number */ -ST_FUNC int put_elf_sym(Section *s, addr_t value, unsigned long size, - int info, int other, int shndx, const char *name) -{ - int name_offset, sym_index; - int nbuckets, h; - ElfW(Sym) *sym; - Section *hs; - - sym = section_ptr_add(s, sizeof(ElfW(Sym))); - if (name && name[0]) - name_offset = put_elf_str(s->link, name); - else - name_offset = 0; - /* XXX: endianness */ - sym->st_name = name_offset; - sym->st_value = value; - sym->st_size = size; - sym->st_info = info; - sym->st_other = other; - sym->st_shndx = shndx; - sym_index = sym - (ElfW(Sym) *)s->data; - hs = s->hash; - if (hs) { - int *ptr, *base; - ptr = section_ptr_add(hs, sizeof(int)); - base = (int *)hs->data; - /* only add global or weak symbols. */ - if (ELFW(ST_BIND)(info) != STB_LOCAL) { - /* add another hashing entry */ - nbuckets = base[0]; - h = elf_hash((unsigned char *)s->link->data + name_offset) % nbuckets; - *ptr = base[2 + h]; - base[2 + h] = sym_index; - base[1]++; - /* we resize the hash table */ - hs->nb_hashed_syms++; - if (hs->nb_hashed_syms > 2 * nbuckets) { - rebuild_hash(s, 2 * nbuckets); - } - } else { - *ptr = 0; - base[1]++; - } - } - return sym_index; -} - -ST_FUNC int find_elf_sym(Section *s, const char *name) -{ - ElfW(Sym) *sym; - Section *hs; - int nbuckets, sym_index, h; - const char *name1; - - hs = s->hash; - if (!hs) - return 0; - nbuckets = ((int *)hs->data)[0]; - h = elf_hash((unsigned char *) name) % nbuckets; - sym_index = ((int *)hs->data)[2 + h]; - while (sym_index != 0) { - sym = &((ElfW(Sym) *)s->data)[sym_index]; - name1 = (char *) s->link->data + sym->st_name; - if (!strcmp(name, name1)) - return sym_index; - sym_index = ((int *)hs->data)[2 + nbuckets + sym_index]; - } - return 0; -} - -/* return elf symbol value, signal error if 'err' is nonzero */ -ST_FUNC addr_t get_elf_sym_addr(TCCState *s, const char *name, int err) -{ - int sym_index; - ElfW(Sym) *sym; - - sym_index = find_elf_sym(s->symtab, name); - sym = &((ElfW(Sym) *)s->symtab->data)[sym_index]; - if (!sym_index || sym->st_shndx == SHN_UNDEF) { - if (err) - tcc_error("%s not defined", name); - return 0; - } - return sym->st_value; -} - -/* return elf symbol value */ -LIBTCCAPI void *tcc_get_symbol(TCCState *s, const char *name) -{ - return (void*)(uintptr_t)get_elf_sym_addr(s, name, 0); -} - -#if defined TCC_IS_NATIVE || defined TCC_TARGET_PE -/* return elf symbol value or error */ -ST_FUNC void* tcc_get_symbol_err(TCCState *s, const char *name) -{ - return (void*)(uintptr_t)get_elf_sym_addr(s, name, 1); -} -#endif - -/* add an elf symbol : check if it is already defined and patch - it. Return symbol index. NOTE that sh_num can be SHN_UNDEF. */ -ST_FUNC int set_elf_sym(Section *s, addr_t value, unsigned long size, - int info, int other, int shndx, const char *name) -{ - ElfW(Sym) *esym; - int sym_bind, sym_index, sym_type, esym_bind; - unsigned char sym_vis, esym_vis, new_vis; - - sym_bind = ELFW(ST_BIND)(info); - sym_type = ELFW(ST_TYPE)(info); - sym_vis = ELFW(ST_VISIBILITY)(other); - - if (sym_bind != STB_LOCAL) { - /* we search global or weak symbols */ - sym_index = find_elf_sym(s, name); - if (!sym_index) - goto do_def; - esym = &((ElfW(Sym) *)s->data)[sym_index]; - if (esym->st_value == value && esym->st_size == size && esym->st_info == info - && esym->st_other == other && esym->st_shndx == shndx) - return sym_index; - if (esym->st_shndx != SHN_UNDEF) { - esym_bind = ELFW(ST_BIND)(esym->st_info); - /* propagate the most constraining visibility */ - /* STV_DEFAULT(0)st_other); - if (esym_vis == STV_DEFAULT) { - new_vis = sym_vis; - } else if (sym_vis == STV_DEFAULT) { - new_vis = esym_vis; - } else { - new_vis = (esym_vis < sym_vis) ? esym_vis : sym_vis; - } - esym->st_other = (esym->st_other & ~ELFW(ST_VISIBILITY)(-1)) - | new_vis; - other = esym->st_other; /* in case we have to patch esym */ - if (shndx == SHN_UNDEF) { - /* ignore adding of undefined symbol if the - corresponding symbol is already defined */ - } else if (sym_bind == STB_GLOBAL && esym_bind == STB_WEAK) { - /* global overrides weak, so patch */ - goto do_patch; - } else if (sym_bind == STB_WEAK && esym_bind == STB_GLOBAL) { - /* weak is ignored if already global */ - } else if (sym_bind == STB_WEAK && esym_bind == STB_WEAK) { - /* keep first-found weak definition, ignore subsequents */ - } else if (sym_vis == STV_HIDDEN || sym_vis == STV_INTERNAL) { - /* ignore hidden symbols after */ - } else if ((esym->st_shndx == SHN_COMMON - || esym->st_shndx == bss_section->sh_num) - && (shndx < SHN_LORESERVE - && shndx != bss_section->sh_num)) { - /* data symbol gets precedence over common/bss */ - goto do_patch; - } else if (shndx == SHN_COMMON || shndx == bss_section->sh_num) { - /* data symbol keeps precedence over common/bss */ - } else if (s->sh_flags & SHF_DYNSYM) { - /* we accept that two DLL define the same symbol */ - } else if (esym->st_other & ST_ASM_SET) { - /* If the existing symbol came from an asm .set - we can override. */ - goto do_patch; - } else { -#if 0 - printf("new_bind=%x new_shndx=%x new_vis=%x old_bind=%x old_shndx=%x old_vis=%x\n", - sym_bind, shndx, new_vis, esym_bind, esym->st_shndx, esym_vis); -#endif - tcc_error_noabort("'%s' defined twice", name); - } - } else { - do_patch: - esym->st_info = ELFW(ST_INFO)(sym_bind, sym_type); - esym->st_shndx = shndx; - new_undef_sym = 1; - esym->st_value = value; - esym->st_size = size; - esym->st_other = other; - } - } else { - do_def: - sym_index = put_elf_sym(s, value, size, - ELFW(ST_INFO)(sym_bind, sym_type), other, - shndx, name); - } - return sym_index; -} - -/* put relocation */ -ST_FUNC void put_elf_reloca(Section *symtab, Section *s, unsigned long offset, - int type, int symbol, addr_t addend) -{ - char buf[256]; - Section *sr; - ElfW_Rel *rel; - - sr = s->reloc; - if (!sr) { - /* if no relocation section, create it */ - snprintf(buf, sizeof(buf), REL_SECTION_FMT, s->name); - /* if the symtab is allocated, then we consider the relocation - are also */ - sr = new_section(tcc_state, buf, SHT_RELX, symtab->sh_flags); - sr->sh_entsize = sizeof(ElfW_Rel); - sr->link = symtab; - sr->sh_info = s->sh_num; - s->reloc = sr; - } - rel = section_ptr_add(sr, sizeof(ElfW_Rel)); - rel->r_offset = offset; - rel->r_info = ELFW(R_INFO)(symbol, type); -#if SHT_RELX == SHT_RELA - rel->r_addend = addend; -#else - if (addend) - tcc_error("non-zero addend on REL architecture"); -#endif -} - -ST_FUNC void put_elf_reloc(Section *symtab, Section *s, unsigned long offset, - int type, int symbol) -{ - put_elf_reloca(symtab, s, offset, type, symbol, 0); -} - -/* Remove relocations for section S->reloc starting at oldrelocoffset - that are to the same place, retaining the last of them. As side effect - the relocations are sorted. Possibly reduces the number of relocs. */ -ST_FUNC void squeeze_multi_relocs(Section *s, size_t oldrelocoffset) -{ - Section *sr = s->reloc; - ElfW_Rel *r, *dest; - ssize_t a; - ElfW(Addr) addr; - - if (oldrelocoffset + sizeof(*r) >= sr->data_offset) - return; - /* The relocs we're dealing with are the result of initializer parsing. - So they will be mostly in order and there aren't many of them. - Secondly we need a stable sort (which qsort isn't). We use - a simple insertion sort. */ - for (a = oldrelocoffset + sizeof(*r); a < sr->data_offset; a += sizeof(*r)) { - ssize_t i = a - sizeof(*r); - addr = ((ElfW_Rel*)(sr->data + a))->r_offset; - for (; i >= (ssize_t)oldrelocoffset && - ((ElfW_Rel*)(sr->data + i))->r_offset > addr; i -= sizeof(*r)) { - ElfW_Rel tmp = *(ElfW_Rel*)(sr->data + a); - *(ElfW_Rel*)(sr->data + a) = *(ElfW_Rel*)(sr->data + i); - *(ElfW_Rel*)(sr->data + i) = tmp; - } - } - - r = (ElfW_Rel*)(sr->data + oldrelocoffset); - dest = r; - for (; r < (ElfW_Rel*)(sr->data + sr->data_offset); r++) { - if (dest->r_offset != r->r_offset) - dest++; - *dest = *r; - } - sr->data_offset = (unsigned char*)dest - sr->data + sizeof(*r); -} - -/* put stab debug information */ - -ST_FUNC void put_stabs(const char *str, int type, int other, int desc, - unsigned long value) -{ - Stab_Sym *sym; - - sym = section_ptr_add(stab_section, sizeof(Stab_Sym)); - if (str) { - sym->n_strx = put_elf_str(stabstr_section, str); - } else { - sym->n_strx = 0; - } - sym->n_type = type; - sym->n_other = other; - sym->n_desc = desc; - sym->n_value = value; -} - -ST_FUNC void put_stabs_r(const char *str, int type, int other, int desc, - unsigned long value, Section *sec, int sym_index) -{ - put_stabs(str, type, other, desc, value); - put_elf_reloc(symtab_section, stab_section, - stab_section->data_offset - sizeof(unsigned int), - R_DATA_32, sym_index); -} - -ST_FUNC void put_stabn(int type, int other, int desc, int value) -{ - put_stabs(NULL, type, other, desc, value); -} - -ST_FUNC void put_stabd(int type, int other, int desc) -{ - put_stabs(NULL, type, other, desc, 0); -} - -ST_FUNC struct sym_attr *get_sym_attr(TCCState *s1, int index, int alloc) -{ - int n; - struct sym_attr *tab; - - if (index >= s1->nb_sym_attrs) { - if (!alloc) - return s1->sym_attrs; - /* find immediately bigger power of 2 and reallocate array */ - n = 1; - while (index >= n) - n *= 2; - tab = tcc_realloc(s1->sym_attrs, n * sizeof(*s1->sym_attrs)); - s1->sym_attrs = tab; - memset(s1->sym_attrs + s1->nb_sym_attrs, 0, - (n - s1->nb_sym_attrs) * sizeof(*s1->sym_attrs)); - s1->nb_sym_attrs = n; - } - return &s1->sym_attrs[index]; -} - -/* Browse each elem of type in section starting at elem - using variable */ -#define for_each_elem(sec, startoff, elem, type) \ - for (elem = (type *) sec->data + startoff; \ - elem < (type *) (sec->data + sec->data_offset); elem++) - -/* In an ELF file symbol table, the local symbols must appear below - the global and weak ones. Since TCC cannot sort it while generating - the code, we must do it after. All the relocation tables are also - modified to take into account the symbol table sorting */ -static void sort_syms(TCCState *s1, Section *s) -{ - int *old_to_new_syms; - ElfW(Sym) *new_syms; - int nb_syms, i; - ElfW(Sym) *p, *q; - ElfW_Rel *rel; - Section *sr; - int type, sym_index; - - nb_syms = s->data_offset / sizeof(ElfW(Sym)); - new_syms = tcc_malloc(nb_syms * sizeof(ElfW(Sym))); - old_to_new_syms = tcc_malloc(nb_syms * sizeof(int)); - - /* first pass for local symbols */ - p = (ElfW(Sym) *)s->data; - q = new_syms; - for(i = 0; i < nb_syms; i++) { - if (ELFW(ST_BIND)(p->st_info) == STB_LOCAL) { - old_to_new_syms[i] = q - new_syms; - *q++ = *p; - } - p++; - } - /* save the number of local symbols in section header */ - if( s->sh_size ) /* this 'if' makes IDA happy */ - s->sh_info = q - new_syms; - - /* then second pass for non local symbols */ - p = (ElfW(Sym) *)s->data; - for(i = 0; i < nb_syms; i++) { - if (ELFW(ST_BIND)(p->st_info) != STB_LOCAL) { - old_to_new_syms[i] = q - new_syms; - *q++ = *p; - } - p++; - } - - /* we copy the new symbols to the old */ - memcpy(s->data, new_syms, nb_syms * sizeof(ElfW(Sym))); - tcc_free(new_syms); - - /* now we modify all the relocations */ - for(i = 1; i < s1->nb_sections; i++) { - sr = s1->sections[i]; - if (sr->sh_type == SHT_RELX && sr->link == s) { - for_each_elem(sr, 0, rel, ElfW_Rel) { - sym_index = ELFW(R_SYM)(rel->r_info); - type = ELFW(R_TYPE)(rel->r_info); - sym_index = old_to_new_syms[sym_index]; - rel->r_info = ELFW(R_INFO)(sym_index, type); - } - } - } - - tcc_free(old_to_new_syms); -} - -/* relocate symbol table, resolve undefined symbols if do_resolve is - true and output error if undefined symbol. */ -ST_FUNC void relocate_syms(TCCState *s1, Section *symtab, int do_resolve) -{ - ElfW(Sym) *sym; - int sym_bind, sh_num; - const char *name; - - for_each_elem(symtab, 1, sym, ElfW(Sym)) { - sh_num = sym->st_shndx; - if (sh_num == SHN_UNDEF) { - name = (char *) s1->symtab->link->data + sym->st_name; - /* Use ld.so to resolve symbol for us (for tcc -run) */ - if (do_resolve) { -#if defined TCC_IS_NATIVE && !defined TCC_TARGET_PE - void *addr = dlsym(RTLD_DEFAULT, name); - if (addr) { - sym->st_value = (addr_t) addr; -#ifdef DEBUG_RELOC - printf ("relocate_sym: %s -> 0x%lx\n", name, sym->st_value); -#endif - goto found; - } -#endif - /* if dynamic symbol exist, it will be used in relocate_section */ - } else if (s1->dynsym && find_elf_sym(s1->dynsym, name)) - goto found; - /* XXX: _fp_hw seems to be part of the ABI, so we ignore - it */ - if (!strcmp(name, "_fp_hw")) - goto found; - /* only weak symbols are accepted to be undefined. Their - value is zero */ - sym_bind = ELFW(ST_BIND)(sym->st_info); - if (sym_bind == STB_WEAK) - sym->st_value = 0; - else - tcc_error_noabort("undefined symbol '%s'", name); - } else if (sh_num < SHN_LORESERVE) { - /* add section base */ - sym->st_value += s1->sections[sym->st_shndx]->sh_addr; - } - found: ; - } -} - -/* relocate a given section (CPU dependent) by applying the relocations - in the associated relocation section */ -ST_FUNC void relocate_section(TCCState *s1, Section *s) -{ - Section *sr = s->reloc; - ElfW_Rel *rel; - ElfW(Sym) *sym; - int type, sym_index; - unsigned char *ptr; - addr_t tgt, addr; - - relocate_init(sr); - - for_each_elem(sr, 0, rel, ElfW_Rel) { - ptr = s->data + rel->r_offset; - sym_index = ELFW(R_SYM)(rel->r_info); - sym = &((ElfW(Sym) *)symtab_section->data)[sym_index]; - type = ELFW(R_TYPE)(rel->r_info); - tgt = sym->st_value; -#if SHT_RELX == SHT_RELA - tgt += rel->r_addend; -#endif - addr = s->sh_addr + rel->r_offset; - relocate(s1, rel, type, ptr, addr, tgt); - } - /* if the relocation is allocated, we change its symbol table */ - if (sr->sh_flags & SHF_ALLOC) - sr->link = s1->dynsym; -} - -/* relocate relocation table in 'sr' */ -static void relocate_rel(TCCState *s1, Section *sr) -{ - Section *s; - ElfW_Rel *rel; - - s = s1->sections[sr->sh_info]; - for_each_elem(sr, 0, rel, ElfW_Rel) - rel->r_offset += s->sh_addr; -} - -/* count the number of dynamic relocations so that we can reserve - their space */ -static int prepare_dynamic_rel(TCCState *s1, Section *sr) -{ - ElfW_Rel *rel; - int sym_index, type, count; - - count = 0; - for_each_elem(sr, 0, rel, ElfW_Rel) { - sym_index = ELFW(R_SYM)(rel->r_info); - type = ELFW(R_TYPE)(rel->r_info); - switch(type) { -#if defined(TCC_TARGET_I386) - case R_386_32: - if (!get_sym_attr(s1, sym_index, 0)->dyn_index - && ((ElfW(Sym)*)symtab_section->data + sym_index)->st_shndx == SHN_UNDEF) { - /* don't fixup unresolved (weak) symbols */ - rel->r_info = ELFW(R_INFO)(sym_index, R_386_RELATIVE); - break; - } -#elif defined(TCC_TARGET_X86_64) - case R_X86_64_32: - case R_X86_64_32S: - case R_X86_64_64: -#endif - count++; - break; -#if defined(TCC_TARGET_I386) - case R_386_PC32: -#elif defined(TCC_TARGET_X86_64) - case R_X86_64_PC32: -#endif - if (get_sym_attr(s1, sym_index, 0)->dyn_index) - count++; - break; - default: - break; - } - } - if (count) { - /* allocate the section */ - sr->sh_flags |= SHF_ALLOC; - sr->sh_size = count * sizeof(ElfW_Rel); - } - return count; -} - -static void build_got(TCCState *s1) -{ - /* if no got, then create it */ - s1->got = new_section(s1, ".got", SHT_PROGBITS, SHF_ALLOC | SHF_WRITE); - s1->got->sh_entsize = 4; - set_elf_sym(symtab_section, 0, 4, ELFW(ST_INFO)(STB_GLOBAL, STT_OBJECT), - 0, s1->got->sh_num, "_GLOBAL_OFFSET_TABLE_"); - /* keep space for _DYNAMIC pointer and two dummy got entries */ - section_ptr_add(s1->got, 3 * PTR_SIZE); -} - -/* Create a GOT and (for function call) a PLT entry corresponding to a symbol - in s1->symtab. When creating the dynamic symbol table entry for the GOT - relocation, use 'size' and 'info' for the corresponding symbol metadata. - Returns the offset of the GOT or (if any) PLT entry. */ -static struct sym_attr * put_got_entry(TCCState *s1, int dyn_reloc_type, - unsigned long size, - int info, int sym_index) -{ - int need_plt_entry; - const char *name; - ElfW(Sym) *sym; - struct sym_attr *attr; - unsigned got_offset; - char plt_name[100]; - int len; - - need_plt_entry = (dyn_reloc_type == R_JMP_SLOT); - attr = get_sym_attr(s1, sym_index, 1); - - /* In case a function is both called and its address taken 2 GOT entries - are created, one for taking the address (GOT) and the other for the PLT - entry (PLTGOT). */ - if (need_plt_entry ? attr->plt_offset : attr->got_offset) - return attr; - - /* create the GOT entry */ - got_offset = s1->got->data_offset; - section_ptr_add(s1->got, PTR_SIZE); - - /* Create the GOT relocation that will insert the address of the object or - function of interest in the GOT entry. This is a static relocation for - memory output (dlsym will give us the address of symbols) and dynamic - relocation otherwise (executable and DLLs). The relocation should be - done lazily for GOT entry with *_JUMP_SLOT relocation type (the one - associated to a PLT entry) but is currently done at load time for an - unknown reason. */ - - sym = &((ElfW(Sym) *) symtab_section->data)[sym_index]; - name = (char *) symtab_section->link->data + sym->st_name; - - if (s1->dynsym) { - if (ELFW(ST_BIND)(sym->st_info) == STB_LOCAL) { - /* Hack alarm. We don't want to emit dynamic symbols - and symbol based relocs for STB_LOCAL symbols, but rather - want to resolve them directly. At this point the symbol - values aren't final yet, so we must defer this. We will later - have to create a RELATIVE reloc anyway, so we misuse the - relocation slot to smuggle the symbol reference until - fill_local_got_entries. Not that the sym_index is - relative to symtab_section, not s1->dynsym! Nevertheless - we use s1->dyn_sym so that if this is the first call - that got->reloc is correctly created. Also note that - RELATIVE relocs are not normally created for the .got, - so the types serves as a marker for later (and is retained - also for the final output, which is okay because then the - got is just normal data). */ - put_elf_reloc(s1->dynsym, s1->got, got_offset, R_RELATIVE, - sym_index); - } else { - if (0 == attr->dyn_index) - attr->dyn_index = set_elf_sym(s1->dynsym, sym->st_value, size, - info, 0, sym->st_shndx, name); - put_elf_reloc(s1->dynsym, s1->got, got_offset, dyn_reloc_type, - attr->dyn_index); - } - } else { - put_elf_reloc(symtab_section, s1->got, got_offset, dyn_reloc_type, - sym_index); - } - - if (need_plt_entry) { - if (!s1->plt) { - s1->plt = new_section(s1, ".plt", SHT_PROGBITS, - SHF_ALLOC | SHF_EXECINSTR); - s1->plt->sh_entsize = 4; - } - - attr->plt_offset = create_plt_entry(s1, got_offset, attr); - - /* create a symbol 'sym@plt' for the PLT jump vector */ - len = strlen(name); - if (len > sizeof plt_name - 5) - len = sizeof plt_name - 5; - memcpy(plt_name, name, len); - strcpy(plt_name + len, "@plt"); - attr->plt_sym = put_elf_sym(s1->symtab, attr->plt_offset, sym->st_size, - ELFW(ST_INFO)(STB_GLOBAL, STT_FUNC), 0, s1->plt->sh_num, plt_name); - - } else { - attr->got_offset = got_offset; - } - - return attr; -} - -/* build GOT and PLT entries */ -ST_FUNC void build_got_entries(TCCState *s1) -{ - Section *s; - ElfW_Rel *rel; - ElfW(Sym) *sym; - int i, type, gotplt_entry, reloc_type, sym_index; - struct sym_attr *attr; - - for(i = 1; i < s1->nb_sections; i++) { - s = s1->sections[i]; - if (s->sh_type != SHT_RELX) - continue; - /* no need to handle got relocations */ - if (s->link != symtab_section) - continue; - for_each_elem(s, 0, rel, ElfW_Rel) { - type = ELFW(R_TYPE)(rel->r_info); - gotplt_entry = gotplt_entry_type(type); - sym_index = ELFW(R_SYM)(rel->r_info); - sym = &((ElfW(Sym) *)symtab_section->data)[sym_index]; - - if (gotplt_entry == NO_GOTPLT_ENTRY) { - continue; - } - - /* Automatically create PLT/GOT [entry] if it is an undefined - reference (resolved at runtime), or the symbol is absolute, - probably created by tcc_add_symbol, and thus on 64-bit - targets might be too far from application code. */ - if (gotplt_entry == AUTO_GOTPLT_ENTRY) { - if (sym->st_shndx == SHN_UNDEF) { - ElfW(Sym) *esym; - int dynindex; - if (s1->output_type == TCC_OUTPUT_DLL && ! PCRELATIVE_DLLPLT) - continue; - /* Relocations for UNDEF symbols would normally need - to be transferred into the executable or shared object. - If that were done AUTO_GOTPLT_ENTRY wouldn't exist. - But TCC doesn't do that (at least for exes), so we - need to resolve all such relocs locally. And that - means PLT slots for functions in DLLs and COPY relocs for - data symbols. COPY relocs were generated in - bind_exe_dynsyms (and the symbol adjusted to be defined), - and for functions we were generated a dynamic symbol - of function type. */ - if (s1->dynsym) { - /* dynsym isn't set for -run :-/ */ - dynindex = get_sym_attr(s1, sym_index, 0)->dyn_index; - esym = (ElfW(Sym) *)s1->dynsym->data + dynindex; - if (dynindex - && (ELFW(ST_TYPE)(esym->st_info) == STT_FUNC - || (ELFW(ST_TYPE)(esym->st_info) == STT_NOTYPE - && ELFW(ST_TYPE)(sym->st_info) == STT_FUNC))) - goto jmp_slot; - } - } else if (!(sym->st_shndx == SHN_ABS -#ifndef TCC_TARGET_ARM - && PTR_SIZE == 8 -#endif - )) - continue; - } - -#ifdef TCC_TARGET_X86_64 - if ((type == R_X86_64_PLT32 || type == R_X86_64_PC32) && - (ELFW(ST_VISIBILITY)(sym->st_other) != STV_DEFAULT || - ELFW(ST_BIND)(sym->st_info) == STB_LOCAL)) { - rel->r_info = ELFW(R_INFO)(sym_index, R_X86_64_PC32); - continue; - } -#endif - if (code_reloc(type)) { - jmp_slot: - reloc_type = R_JMP_SLOT; - } else - reloc_type = R_GLOB_DAT; - - if (!s1->got) - build_got(s1); - - if (gotplt_entry == BUILD_GOT_ONLY) - continue; - - attr = put_got_entry(s1, reloc_type, sym->st_size, sym->st_info, - sym_index); - - if (reloc_type == R_JMP_SLOT) - rel->r_info = ELFW(R_INFO)(attr->plt_sym, type); - } - } -} - -/* put dynamic tag */ -static void put_dt(Section *dynamic, int dt, addr_t val) -{ - ElfW(Dyn) *dyn; - dyn = section_ptr_add(dynamic, sizeof(ElfW(Dyn))); - dyn->d_tag = dt; - dyn->d_un.d_val = val; -} - -#ifndef TCC_TARGET_PE -static void add_init_array_defines(TCCState *s1, const char *section_name) -{ - Section *s; - long end_offset; - char sym_start[1024]; - char sym_end[1024]; - - snprintf(sym_start, sizeof(sym_start), "__%s_start", section_name + 1); - snprintf(sym_end, sizeof(sym_end), "__%s_end", section_name + 1); - - s = find_section(s1, section_name); - if (!s) { - end_offset = 0; - s = data_section; - } else { - end_offset = s->data_offset; - } - - set_elf_sym(symtab_section, - 0, 0, - ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, - s->sh_num, sym_start); - set_elf_sym(symtab_section, - end_offset, 0, - ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, - s->sh_num, sym_end); -} -#endif - -static int tcc_add_support(TCCState *s1, const char *filename) -{ - char buf[1024]; - snprintf(buf, sizeof(buf), "%s/%s", s1->tcc_lib_path, filename); - return tcc_add_file(s1, buf); -} - -ST_FUNC void tcc_add_bcheck(TCCState *s1) -{ -#ifdef CONFIG_TCC_BCHECK - addr_t *ptr; - int sym_index; - - if (0 == s1->do_bounds_check) - return; - /* XXX: add an object file to do that */ - ptr = section_ptr_add(bounds_section, sizeof(*ptr)); - *ptr = 0; - set_elf_sym(symtab_section, 0, 0, - ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, - bounds_section->sh_num, "__bounds_start"); - /* pull bcheck.o from libtcc1.a */ - sym_index = set_elf_sym(symtab_section, 0, 0, - ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, - SHN_UNDEF, "__bound_init"); - if (s1->output_type != TCC_OUTPUT_MEMORY) { - /* add 'call __bound_init()' in .init section */ - Section *init_section = find_section(s1, ".init"); - unsigned char *pinit = section_ptr_add(init_section, 5); - pinit[0] = 0xe8; - write32le(pinit + 1, -4); - put_elf_reloc(symtab_section, init_section, - init_section->data_offset - 4, R_386_PC32, sym_index); - /* R_386_PC32 = R_X86_64_PC32 = 2 */ - } -#endif -} - -/* add tcc runtime libraries */ -ST_FUNC void tcc_add_runtime(TCCState *s1) -{ - tcc_add_bcheck(s1); - tcc_add_pragma_libs(s1); - /* add libc */ - if (!s1->nostdlib) { - tcc_add_library_err(s1, "c"); -#ifdef TCC_LIBGCC - if (!s1->static_link) { - if (TCC_LIBGCC[0] == '/') - tcc_add_file(s1, TCC_LIBGCC); - else - tcc_add_dll(s1, TCC_LIBGCC, 0); - } -#endif - tcc_add_support(s1, TCC_LIBTCC1); - /* add crt end if not memory output */ - if (s1->output_type != TCC_OUTPUT_MEMORY) - tcc_add_crt(s1, "crtn.o"); - } -} - -/* add various standard linker symbols (must be done after the - sections are filled (for example after allocating common - symbols)) */ -static void tcc_add_linker_symbols(TCCState *s1) -{ - char buf[1024]; - int i; - Section *s; - - set_elf_sym(symtab_section, - text_section->data_offset, 0, - ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, - text_section->sh_num, "_etext"); - set_elf_sym(symtab_section, - data_section->data_offset, 0, - ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, - data_section->sh_num, "_edata"); - set_elf_sym(symtab_section, - bss_section->data_offset, 0, - ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, - bss_section->sh_num, "_end"); -#ifndef TCC_TARGET_PE - /* horrible new standard ldscript defines */ - add_init_array_defines(s1, ".preinit_array"); - add_init_array_defines(s1, ".init_array"); - add_init_array_defines(s1, ".fini_array"); -#endif - - /* add start and stop symbols for sections whose name can be - expressed in C */ - for(i = 1; i < s1->nb_sections; i++) { - s = s1->sections[i]; - if (s->sh_type == SHT_PROGBITS && - (s->sh_flags & SHF_ALLOC)) { - const char *p; - int ch; - - /* check if section name can be expressed in C */ - p = s->name; - for(;;) { - ch = *p; - if (!ch) - break; - if (!isid(ch) && !isnum(ch)) - goto next_sec; - p++; - } - snprintf(buf, sizeof(buf), "__start_%s", s->name); - set_elf_sym(symtab_section, - 0, 0, - ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, - s->sh_num, buf); - snprintf(buf, sizeof(buf), "__stop_%s", s->name); - set_elf_sym(symtab_section, - s->data_offset, 0, - ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, - s->sh_num, buf); - } - next_sec: ; - } -} - -ST_FUNC void resolve_common_syms(TCCState *s1) -{ - ElfW(Sym) *sym; - - /* Allocate common symbols in BSS. */ - for_each_elem(symtab_section, 1, sym, ElfW(Sym)) { - if (sym->st_shndx == SHN_COMMON) { - /* symbol alignment is in st_value for SHN_COMMONs */ - sym->st_value = section_add(bss_section, sym->st_size, - sym->st_value); - sym->st_shndx = bss_section->sh_num; - } - } - - /* Now assign linker provided symbols their value. */ - tcc_add_linker_symbols(s1); -} - -static void tcc_output_binary(TCCState *s1, FILE *f, - const int *sec_order) -{ - Section *s; - int i, offset, size; - - offset = 0; - for(i=1;inb_sections;i++) { - s = s1->sections[sec_order[i]]; - if (s->sh_type != SHT_NOBITS && - (s->sh_flags & SHF_ALLOC)) { - while (offset < s->sh_offset) { - fputc(0, f); - offset++; - } - size = s->sh_size; - fwrite(s->data, 1, size, f); - offset += size; - } - } -} - -ST_FUNC void fill_got_entry(TCCState *s1, ElfW_Rel *rel) -{ - int sym_index = ELFW(R_SYM) (rel->r_info); - ElfW(Sym) *sym = &((ElfW(Sym) *) symtab_section->data)[sym_index]; - struct sym_attr *attr = get_sym_attr(s1, sym_index, 0); - unsigned offset = attr->got_offset; - - if (0 == offset) - return; - section_reserve(s1->got, offset + PTR_SIZE); -#ifdef TCC_TARGET_X86_64 - write64le(s1->got->data + offset, sym->st_value); -#else - write32le(s1->got->data + offset, sym->st_value); -#endif -} - -/* Perform relocation to GOT or PLT entries */ -ST_FUNC void fill_got(TCCState *s1) -{ - Section *s; - ElfW_Rel *rel; - int i; - - for(i = 1; i < s1->nb_sections; i++) { - s = s1->sections[i]; - if (s->sh_type != SHT_RELX) - continue; - /* no need to handle got relocations */ - if (s->link != symtab_section) - continue; - for_each_elem(s, 0, rel, ElfW_Rel) { - switch (ELFW(R_TYPE) (rel->r_info)) { - case R_X86_64_GOT32: - case R_X86_64_GOTPCREL: - case R_X86_64_GOTPCRELX: - case R_X86_64_REX_GOTPCRELX: - case R_X86_64_PLT32: - fill_got_entry(s1, rel); - break; - } - } - } -} - -/* See put_got_entry for a description. This is the second stage - where GOT references to local defined symbols are rewritten. */ -static void fill_local_got_entries(TCCState *s1) -{ - ElfW_Rel *rel; - for_each_elem(s1->got->reloc, 0, rel, ElfW_Rel) { - if (ELFW(R_TYPE)(rel->r_info) == R_RELATIVE) { - int sym_index = ELFW(R_SYM) (rel->r_info); - ElfW(Sym) *sym = &((ElfW(Sym) *) symtab_section->data)[sym_index]; - struct sym_attr *attr = get_sym_attr(s1, sym_index, 0); - unsigned offset = attr->got_offset; - if (offset != rel->r_offset - s1->got->sh_addr) - tcc_error_noabort("huh"); - rel->r_info = ELFW(R_INFO)(0, R_RELATIVE); -#if SHT_RELX == SHT_RELA - rel->r_addend = sym->st_value; -#else - /* All our REL architectures also happen to be 32bit LE. */ - write32le(s1->got->data + offset, sym->st_value); -#endif - } - } -} - -/* Bind symbols of executable: resolve undefined symbols from exported symbols - in shared libraries and export non local defined symbols to shared libraries - if -rdynamic switch was given on command line */ -static void bind_exe_dynsyms(TCCState *s1) -{ - const char *name; - int sym_index, index; - ElfW(Sym) *sym, *esym; - int type; - - /* Resolve undefined symbols from dynamic symbols. When there is a match: - - if STT_FUNC or STT_GNU_IFUNC symbol -> add it in PLT - - if STT_OBJECT symbol -> add it in .bss section with suitable reloc */ - for_each_elem(symtab_section, 1, sym, ElfW(Sym)) { - if (sym->st_shndx == SHN_UNDEF) { - name = (char *) symtab_section->link->data + sym->st_name; - sym_index = find_elf_sym(s1->dynsymtab_section, name); - if (sym_index) { - esym = &((ElfW(Sym) *)s1->dynsymtab_section->data)[sym_index]; - type = ELFW(ST_TYPE)(esym->st_info); - if ((type == STT_FUNC) || (type == STT_GNU_IFUNC)) { - /* Indirect functions shall have STT_FUNC type in executable - * dynsym section. Indeed, a dlsym call following a lazy - * resolution would pick the symbol value from the - * executable dynsym entry which would contain the address - * of the function wanted by the caller of dlsym instead of - * the address of the function that would return that - * address */ - int dynindex - = put_elf_sym(s1->dynsym, 0, esym->st_size, - ELFW(ST_INFO)(STB_GLOBAL,STT_FUNC), 0, 0, - name); - int index = sym - (ElfW(Sym) *) symtab_section->data; - get_sym_attr(s1, index, 1)->dyn_index = dynindex; - } else if (type == STT_OBJECT) { - unsigned long offset; - ElfW(Sym) *dynsym; - offset = bss_section->data_offset; - /* XXX: which alignment ? */ - offset = (offset + 16 - 1) & -16; - set_elf_sym (s1->symtab, offset, esym->st_size, - esym->st_info, 0, bss_section->sh_num, name); - index = put_elf_sym(s1->dynsym, offset, esym->st_size, - esym->st_info, 0, bss_section->sh_num, - name); - - /* Ensure R_COPY works for weak symbol aliases */ - if (ELFW(ST_BIND)(esym->st_info) == STB_WEAK) { - for_each_elem(s1->dynsymtab_section, 1, dynsym, ElfW(Sym)) { - if ((dynsym->st_value == esym->st_value) - && (ELFW(ST_BIND)(dynsym->st_info) == STB_GLOBAL)) { - char *dynname = (char *) s1->dynsymtab_section->link->data - + dynsym->st_name; - put_elf_sym(s1->dynsym, offset, dynsym->st_size, - dynsym->st_info, 0, - bss_section->sh_num, dynname); - break; - } - } - } - - put_elf_reloc(s1->dynsym, bss_section, - offset, R_COPY, index); - offset += esym->st_size; - bss_section->data_offset = offset; - } - } else { - /* STB_WEAK undefined symbols are accepted */ - /* XXX: _fp_hw seems to be part of the ABI, so we ignore it */ - if (ELFW(ST_BIND)(sym->st_info) == STB_WEAK || - !strcmp(name, "_fp_hw")) { - } else { - tcc_error_noabort("undefined symbol '%s'", name); - } - } - } else if (s1->rdynamic && ELFW(ST_BIND)(sym->st_info) != STB_LOCAL) { - /* if -rdynamic option, then export all non local symbols */ - name = (char *) symtab_section->link->data + sym->st_name; - set_elf_sym(s1->dynsym, sym->st_value, sym->st_size, sym->st_info, - 0, sym->st_shndx, name); - } - } -} - -/* Bind symbols of libraries: export all non local symbols of executable that - are referenced by shared libraries. The reason is that the dynamic loader - search symbol first in executable and then in libraries. Therefore a - reference to a symbol already defined by a library can still be resolved by - a symbol in the executable. */ -static void bind_libs_dynsyms(TCCState *s1) -{ - const char *name; - int sym_index; - ElfW(Sym) *sym, *esym; - - for_each_elem(s1->dynsymtab_section, 1, esym, ElfW(Sym)) { - name = (char *) s1->dynsymtab_section->link->data + esym->st_name; - sym_index = find_elf_sym(symtab_section, name); - sym = &((ElfW(Sym) *)symtab_section->data)[sym_index]; - if (sym_index && sym->st_shndx != SHN_UNDEF - && ELFW(ST_BIND)(sym->st_info) != STB_LOCAL) { - set_elf_sym(s1->dynsym, sym->st_value, sym->st_size, - sym->st_info, 0, sym->st_shndx, name); - } else if (esym->st_shndx == SHN_UNDEF) { - /* weak symbols can stay undefined */ - if (ELFW(ST_BIND)(esym->st_info) != STB_WEAK) - tcc_warning("undefined dynamic symbol '%s'", name); - } - } -} - -/* Export all non local symbols. This is used by shared libraries so that the - non local symbols they define can resolve a reference in another shared - library or in the executable. Correspondingly, it allows undefined local - symbols to be resolved by other shared libraries or by the executable. */ -static void export_global_syms(TCCState *s1) -{ - int dynindex, index; - const char *name; - ElfW(Sym) *sym; - - for_each_elem(symtab_section, 1, sym, ElfW(Sym)) { - if (ELFW(ST_BIND)(sym->st_info) != STB_LOCAL) { - name = (char *) symtab_section->link->data + sym->st_name; - dynindex = put_elf_sym(s1->dynsym, sym->st_value, sym->st_size, - sym->st_info, 0, sym->st_shndx, name); - index = sym - (ElfW(Sym) *) symtab_section->data; - get_sym_attr(s1, index, 1)->dyn_index = dynindex; - } - } -} - -/* Allocate strings for section names and decide if an unallocated section - should be output. - NOTE: the strsec section comes last, so its size is also correct ! */ -static int alloc_sec_names(TCCState *s1, int file_type, Section *strsec) -{ - int i; - Section *s; - int textrel = 0; - - /* Allocate strings for section names */ - for(i = 1; i < s1->nb_sections; i++) { - s = s1->sections[i]; - /* when generating a DLL, we include relocations but we may - patch them */ - if (file_type == TCC_OUTPUT_DLL && - s->sh_type == SHT_RELX && - !(s->sh_flags & SHF_ALLOC) && - (s1->sections[s->sh_info]->sh_flags & SHF_ALLOC) && - prepare_dynamic_rel(s1, s)) { - if (s1->sections[s->sh_info]->sh_flags & SHF_EXECINSTR) - textrel = 1; - } else if (s1->do_debug || - file_type == TCC_OUTPUT_OBJ || - (s->sh_flags & SHF_ALLOC) || - i == (s1->nb_sections - 1)) { - /* we output all sections if debug or object file */ - s->sh_size = s->data_offset; - } - if (s->sh_size || (s->sh_flags & SHF_ALLOC)) - s->sh_name = put_elf_str(strsec, s->name); - } - strsec->sh_size = strsec->data_offset; - return textrel; -} - -/* Info to be copied in dynamic section */ -struct dyn_inf { - Section *dynamic; - Section *dynstr; - unsigned long data_offset; - addr_t rel_addr; - addr_t rel_size; -#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) - addr_t bss_addr; - addr_t bss_size; -#endif -}; - -/* Assign sections to segments and decide how are sections laid out when loaded - in memory. This function also fills corresponding program headers. */ -static int layout_sections(TCCState *s1, ElfW(Phdr) *phdr, int phnum, - Section *interp, Section* strsec, - struct dyn_inf *dyninf, int *sec_order) -{ - int i, j, k, file_type, sh_order_index, file_offset; - unsigned long s_align; - long long tmp; - addr_t addr; - ElfW(Phdr) *ph; - Section *s; - - file_type = s1->output_type; - sh_order_index = 1; - file_offset = 0; - if (s1->output_format == TCC_OUTPUT_FORMAT_ELF) - file_offset = sizeof(ElfW(Ehdr)) + phnum * sizeof(ElfW(Phdr)); - s_align = ELF_PAGE_SIZE; - if (s1->section_align) - s_align = s1->section_align; - - if (phnum > 0) { - if (s1->has_text_addr) { - int a_offset, p_offset; - addr = s1->text_addr; - /* we ensure that (addr % ELF_PAGE_SIZE) == file_offset % - ELF_PAGE_SIZE */ - a_offset = (int) (addr & (s_align - 1)); - p_offset = file_offset & (s_align - 1); - if (a_offset < p_offset) - a_offset += s_align; - file_offset += (a_offset - p_offset); - } else { - if (file_type == TCC_OUTPUT_DLL) - addr = 0; - else - addr = ELF_START_ADDR; - /* compute address after headers */ - addr += (file_offset & (s_align - 1)); - } - - ph = &phdr[0]; - /* Leave one program headers for the program interpreter and one for - the program header table itself if needed. These are done later as - they require section layout to be done first. */ - if (interp) - ph += 2; - - /* dynamic relocation table information, for .dynamic section */ - dyninf->rel_addr = dyninf->rel_size = 0; -#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) - dyninf->bss_addr = dyninf->bss_size = 0; -#endif - - for(j = 0; j < 2; j++) { - ph->p_type = PT_LOAD; - if (j == 0) - ph->p_flags = PF_R | PF_X; - else - ph->p_flags = PF_R | PF_W; - ph->p_align = s_align; - - /* Decide the layout of sections loaded in memory. This must - be done before program headers are filled since they contain - info about the layout. We do the following ordering: interp, - symbol tables, relocations, progbits, nobits */ - /* XXX: do faster and simpler sorting */ - for(k = 0; k < 5; k++) { - for(i = 1; i < s1->nb_sections; i++) { - s = s1->sections[i]; - /* compute if section should be included */ - if (j == 0) { - if ((s->sh_flags & (SHF_ALLOC | SHF_WRITE)) != - SHF_ALLOC) - continue; - } else { - if ((s->sh_flags & (SHF_ALLOC | SHF_WRITE)) != - (SHF_ALLOC | SHF_WRITE)) - continue; - } - if (s == interp) { - if (k != 0) - continue; - } else if (s->sh_type == SHT_DYNSYM || - s->sh_type == SHT_STRTAB || - s->sh_type == SHT_HASH) { - if (k != 1) - continue; - } else if (s->sh_type == SHT_RELX) { - if (k != 2) - continue; - } else if (s->sh_type == SHT_NOBITS) { - if (k != 4) - continue; - } else { - if (k != 3) - continue; - } - sec_order[sh_order_index++] = i; - - /* section matches: we align it and add its size */ - tmp = addr; - addr = (addr + s->sh_addralign - 1) & - ~(s->sh_addralign - 1); - file_offset += (int) ( addr - tmp ); - s->sh_offset = file_offset; - s->sh_addr = addr; - - /* update program header infos */ - if (ph->p_offset == 0) { - ph->p_offset = file_offset; - ph->p_vaddr = addr; - ph->p_paddr = ph->p_vaddr; - } - /* update dynamic relocation infos */ - if (s->sh_type == SHT_RELX) { -#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) - if (!strcmp(strsec->data + s->sh_name, ".rel.got")) { - dyninf->rel_addr = addr; - dyninf->rel_size += s->sh_size; /* XXX only first rel. */ - } - if (!strcmp(strsec->data + s->sh_name, ".rel.bss")) { - dyninf->bss_addr = addr; - dyninf->bss_size = s->sh_size; /* XXX only first rel. */ - } -#else - if (dyninf->rel_size == 0) - dyninf->rel_addr = addr; - dyninf->rel_size += s->sh_size; -#endif - } - addr += s->sh_size; - if (s->sh_type != SHT_NOBITS) - file_offset += s->sh_size; - } - } - if (j == 0) { - /* Make the first PT_LOAD segment include the program - headers itself (and the ELF header as well), it'll - come out with same memory use but will make various - tools like binutils strip work better. */ - ph->p_offset &= ~(ph->p_align - 1); - ph->p_vaddr &= ~(ph->p_align - 1); - ph->p_paddr &= ~(ph->p_align - 1); - } - ph->p_filesz = file_offset - ph->p_offset; - ph->p_memsz = addr - ph->p_vaddr; - ph++; - if (j == 0) { - if (s1->output_format == TCC_OUTPUT_FORMAT_ELF) { - /* if in the middle of a page, we duplicate the page in - memory so that one copy is RX and the other is RW */ - if ((addr & (s_align - 1)) != 0) - addr += s_align; - } else { - addr = (addr + s_align - 1) & ~(s_align - 1); - file_offset = (file_offset + s_align - 1) & ~(s_align - 1); - } - } - } - } - - /* all other sections come after */ - for(i = 1; i < s1->nb_sections; i++) { - s = s1->sections[i]; - if (phnum > 0 && (s->sh_flags & SHF_ALLOC)) - continue; - sec_order[sh_order_index++] = i; - - file_offset = (file_offset + s->sh_addralign - 1) & - ~(s->sh_addralign - 1); - s->sh_offset = file_offset; - if (s->sh_type != SHT_NOBITS) - file_offset += s->sh_size; - } - - return file_offset; -} - -static void fill_unloadable_phdr(ElfW(Phdr) *phdr, int phnum, Section *interp, - Section *dynamic) -{ - ElfW(Phdr) *ph; - - /* if interpreter, then add corresponding program header */ - if (interp) { - ph = &phdr[0]; - - ph->p_type = PT_PHDR; - ph->p_offset = sizeof(ElfW(Ehdr)); - ph->p_filesz = ph->p_memsz = phnum * sizeof(ElfW(Phdr)); - ph->p_vaddr = interp->sh_addr - ph->p_filesz; - ph->p_paddr = ph->p_vaddr; - ph->p_flags = PF_R | PF_X; - ph->p_align = 4; /* interp->sh_addralign; */ - ph++; - - ph->p_type = PT_INTERP; - ph->p_offset = interp->sh_offset; - ph->p_vaddr = interp->sh_addr; - ph->p_paddr = ph->p_vaddr; - ph->p_filesz = interp->sh_size; - ph->p_memsz = interp->sh_size; - ph->p_flags = PF_R; - ph->p_align = interp->sh_addralign; - } - - /* if dynamic section, then add corresponding program header */ - if (dynamic) { - ph = &phdr[phnum - 1]; - - ph->p_type = PT_DYNAMIC; - ph->p_offset = dynamic->sh_offset; - ph->p_vaddr = dynamic->sh_addr; - ph->p_paddr = ph->p_vaddr; - ph->p_filesz = dynamic->sh_size; - ph->p_memsz = dynamic->sh_size; - ph->p_flags = PF_R | PF_W; - ph->p_align = dynamic->sh_addralign; - } -} - -/* Fill the dynamic section with tags describing the address and size of - sections */ -static void fill_dynamic(TCCState *s1, struct dyn_inf *dyninf) -{ - Section *dynamic = dyninf->dynamic; - - /* put dynamic section entries */ - put_dt(dynamic, DT_HASH, s1->dynsym->hash->sh_addr); - put_dt(dynamic, DT_STRTAB, dyninf->dynstr->sh_addr); - put_dt(dynamic, DT_SYMTAB, s1->dynsym->sh_addr); - put_dt(dynamic, DT_STRSZ, dyninf->dynstr->data_offset); - put_dt(dynamic, DT_SYMENT, sizeof(ElfW(Sym))); -#if PTR_SIZE == 8 - put_dt(dynamic, DT_RELA, dyninf->rel_addr); - put_dt(dynamic, DT_RELASZ, dyninf->rel_size); - put_dt(dynamic, DT_RELAENT, sizeof(ElfW_Rel)); -#else -#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) - put_dt(dynamic, DT_PLTGOT, s1->got->sh_addr); - put_dt(dynamic, DT_PLTRELSZ, dyninf->rel_size); - put_dt(dynamic, DT_JMPREL, dyninf->rel_addr); - put_dt(dynamic, DT_PLTREL, DT_REL); - put_dt(dynamic, DT_REL, dyninf->bss_addr); - put_dt(dynamic, DT_RELSZ, dyninf->bss_size); -#else - put_dt(dynamic, DT_REL, dyninf->rel_addr); - put_dt(dynamic, DT_RELSZ, dyninf->rel_size); - put_dt(dynamic, DT_RELENT, sizeof(ElfW_Rel)); -#endif -#endif - if (s1->do_debug) - put_dt(dynamic, DT_DEBUG, 0); - put_dt(dynamic, DT_NULL, 0); -} - -/* Relocate remaining sections and symbols (that is those not related to - dynamic linking) */ -static int final_sections_reloc(TCCState *s1) -{ - int i; - Section *s; - - relocate_syms(s1, s1->symtab, 0); - - if (s1->nb_errors != 0) - return -1; - - /* relocate sections */ - /* XXX: ignore sections with allocated relocations ? */ - for(i = 1; i < s1->nb_sections; i++) { - s = s1->sections[i]; -#if defined(TCC_TARGET_I386) || defined(TCC_MUSL) - if (s->reloc && s != s1->got && (s->sh_flags & SHF_ALLOC)) //gr - /* On X86 gdb 7.3 works in any case but gdb 6.6 will crash if SHF_ALLOC - checking is removed */ -#else - if (s->reloc && s != s1->got) - /* On X86_64 gdb 7.3 will crash if SHF_ALLOC checking is present */ -#endif - relocate_section(s1, s); - } - - /* relocate relocation entries if the relocation tables are - allocated in the executable */ - for(i = 1; i < s1->nb_sections; i++) { - s = s1->sections[i]; - if ((s->sh_flags & SHF_ALLOC) && - s->sh_type == SHT_RELX) { - relocate_rel(s1, s); - } - } - return 0; -} - -/* Create an ELF file on disk. - This function handle ELF specific layout requirements */ -static void tcc_output_elf(TCCState *s1, FILE *f, int phnum, ElfW(Phdr) *phdr, - int file_offset, int *sec_order) -{ - int i, shnum, offset, size, file_type; - Section *s; - ElfW(Ehdr) ehdr; - ElfW(Shdr) shdr, *sh; - - file_type = s1->output_type; - shnum = s1->nb_sections; - - memset(&ehdr, 0, sizeof(ehdr)); - - if (phnum > 0) { - ehdr.e_phentsize = sizeof(ElfW(Phdr)); - ehdr.e_phnum = phnum; - ehdr.e_phoff = sizeof(ElfW(Ehdr)); - } - - /* align to 4 */ - file_offset = (file_offset + 3) & -4; - - /* fill header */ - ehdr.e_ident[0] = ELFMAG0; - ehdr.e_ident[1] = ELFMAG1; - ehdr.e_ident[2] = ELFMAG2; - ehdr.e_ident[3] = ELFMAG3; - ehdr.e_ident[4] = ELFCLASSW; - ehdr.e_ident[5] = ELFDATA2LSB; - ehdr.e_ident[6] = EV_CURRENT; -#if !defined(TCC_TARGET_PE) && (defined(__FreeBSD__) || defined(__FreeBSD_kernel__)) - /* FIXME: should set only for freebsd _target_, but we exclude only PE target */ - ehdr.e_ident[EI_OSABI] = ELFOSABI_FREEBSD; -#endif -#ifdef TCC_TARGET_ARM -#ifdef TCC_ARM_EABI - ehdr.e_ident[EI_OSABI] = 0; - ehdr.e_flags = EF_ARM_EABI_VER4; - if (file_type == TCC_OUTPUT_EXE || file_type == TCC_OUTPUT_DLL) - ehdr.e_flags |= EF_ARM_HASENTRY; - if (s1->float_abi == ARM_HARD_FLOAT) - ehdr.e_flags |= EF_ARM_VFP_FLOAT; - else - ehdr.e_flags |= EF_ARM_SOFT_FLOAT; -#else - ehdr.e_ident[EI_OSABI] = ELFOSABI_ARM; -#endif -#endif - switch(file_type) { - default: - case TCC_OUTPUT_EXE: - ehdr.e_type = ET_EXEC; - ehdr.e_entry = get_elf_sym_addr(s1, "_start", 1); - break; - case TCC_OUTPUT_DLL: - ehdr.e_type = ET_DYN; - ehdr.e_entry = text_section->sh_addr; /* XXX: is it correct ? */ - break; - case TCC_OUTPUT_OBJ: - ehdr.e_type = ET_REL; - break; - } - ehdr.e_machine = EM_TCC_TARGET; - ehdr.e_version = EV_CURRENT; - ehdr.e_shoff = file_offset; - ehdr.e_ehsize = sizeof(ElfW(Ehdr)); - ehdr.e_shentsize = sizeof(ElfW(Shdr)); - ehdr.e_shnum = shnum; - ehdr.e_shstrndx = shnum - 1; - - fwrite(&ehdr, 1, sizeof(ElfW(Ehdr)), f); - fwrite(phdr, 1, phnum * sizeof(ElfW(Phdr)), f); - offset = sizeof(ElfW(Ehdr)) + phnum * sizeof(ElfW(Phdr)); - - sort_syms(s1, symtab_section); - for(i = 1; i < s1->nb_sections; i++) { - s = s1->sections[sec_order[i]]; - if (s->sh_type != SHT_NOBITS) { - while (offset < s->sh_offset) { - fputc(0, f); - offset++; - } - size = s->sh_size; - if (size) - fwrite(s->data, 1, size, f); - offset += size; - } - } - - /* output section headers */ - while (offset < ehdr.e_shoff) { - fputc(0, f); - offset++; - } - - for(i = 0; i < s1->nb_sections; i++) { - sh = &shdr; - memset(sh, 0, sizeof(ElfW(Shdr))); - s = s1->sections[i]; - if (s) { - sh->sh_name = s->sh_name; - sh->sh_type = s->sh_type; - sh->sh_flags = s->sh_flags; - sh->sh_entsize = s->sh_entsize; - sh->sh_info = s->sh_info; - if (s->link) - sh->sh_link = s->link->sh_num; - sh->sh_addralign = s->sh_addralign; - sh->sh_addr = s->sh_addr; - sh->sh_offset = s->sh_offset; - sh->sh_size = s->sh_size; - } - fwrite(sh, 1, sizeof(ElfW(Shdr)), f); - } -} - -/* Write an elf, coff or "binary" file */ -static int tcc_write_elf_file(TCCState *s1, const char *filename, int phnum, - ElfW(Phdr) *phdr, int file_offset, int *sec_order) -{ - int fd, mode, file_type; - FILE *f; - - file_type = s1->output_type; - if (file_type == TCC_OUTPUT_OBJ) - mode = 0666; - else - mode = 0777; - unlink(filename); - fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, mode); - if (fd < 0) { - tcc_error_noabort("could not write '%s'", filename); - return -1; - } - f = fdopen(fd, "wb"); - if (s1->verbose) - printf("<- %s\n", filename); - -#ifdef TCC_TARGET_COFF - if (s1->output_format == TCC_OUTPUT_FORMAT_COFF) - tcc_output_coff(s1, f); - else -#endif - if (s1->output_format == TCC_OUTPUT_FORMAT_ELF) - tcc_output_elf(s1, f, phnum, phdr, file_offset, sec_order); - else - tcc_output_binary(s1, f, sec_order); - fclose(f); - - return 0; -} - -/* Sort section headers by assigned sh_addr, remove sections - that we aren't going to output. */ -static void tidy_section_headers(TCCState *s1, int *sec_order) -{ - int i, nnew, l, *backmap; - Section **snew, *s; - ElfW(Sym) *sym; - - snew = tcc_malloc(s1->nb_sections * sizeof(snew[0])); - backmap = tcc_malloc(s1->nb_sections * sizeof(backmap[0])); - for (i = 0, nnew = 0, l = s1->nb_sections; i < s1->nb_sections; i++) { - s = s1->sections[sec_order[i]]; - if (!i || s->sh_name) { - backmap[sec_order[i]] = nnew; - snew[nnew] = s; - ++nnew; - } else { - backmap[sec_order[i]] = 0; - snew[--l] = s; - } - } - for (i = 0; i < nnew; i++) { - s = snew[i]; - if (s) { - s->sh_num = i; - if (s->sh_type == SHT_RELX) - s->sh_info = backmap[s->sh_info]; - } - } - - for_each_elem(symtab_section, 1, sym, ElfW(Sym)) - if (sym->st_shndx != SHN_UNDEF && sym->st_shndx < SHN_LORESERVE) - sym->st_shndx = backmap[sym->st_shndx]; - if( !s1->static_link ) { - for_each_elem(s1->dynsym, 1, sym, ElfW(Sym)) - if (sym->st_shndx != SHN_UNDEF && sym->st_shndx < SHN_LORESERVE) - sym->st_shndx = backmap[sym->st_shndx]; - } - for (i = 0; i < s1->nb_sections; i++) - sec_order[i] = i; - tcc_free(s1->sections); - s1->sections = snew; - s1->nb_sections = nnew; - tcc_free(backmap); -} - -/* Output an elf, coff or binary file */ -/* XXX: suppress unneeded sections */ -static int elf_output_file(TCCState *s1, const char *filename) -{ - int i, ret, phnum, shnum, file_type, file_offset, *sec_order; - struct dyn_inf dyninf = {0}; - ElfW(Phdr) *phdr; - ElfW(Sym) *sym; - Section *strsec, *interp, *dynamic, *dynstr; - int textrel; - - file_type = s1->output_type; - s1->nb_errors = 0; - ret = -1; - phdr = NULL; - sec_order = NULL; - interp = dynamic = dynstr = NULL; /* avoid warning */ - textrel = 0; - - if (file_type != TCC_OUTPUT_OBJ) { - /* if linking, also link in runtime libraries (libc, libgcc, etc.) */ - tcc_add_runtime(s1); - resolve_common_syms(s1); - - if (!s1->static_link) { - if (file_type == TCC_OUTPUT_EXE) { - char *ptr; - /* allow override the dynamic loader */ - const char *elfint = getenv("LD_SO"); - if (elfint == NULL) - elfint = DEFAULT_ELFINTERP(s1); - /* add interpreter section only if executable */ - interp = new_section(s1, ".interp", SHT_PROGBITS, SHF_ALLOC); - interp->sh_addralign = 1; - ptr = section_ptr_add(interp, 1 + strlen(elfint)); - strcpy(ptr, elfint); - } - - /* add dynamic symbol table */ - s1->dynsym = new_symtab(s1, ".dynsym", SHT_DYNSYM, SHF_ALLOC, - ".dynstr", - ".hash", SHF_ALLOC); - dynstr = s1->dynsym->link; - - /* add dynamic section */ - dynamic = new_section(s1, ".dynamic", SHT_DYNAMIC, - SHF_ALLOC | SHF_WRITE); - dynamic->link = dynstr; - dynamic->sh_entsize = sizeof(ElfW(Dyn)); - - build_got(s1); - - if (file_type == TCC_OUTPUT_EXE) { - bind_exe_dynsyms(s1); - if (s1->nb_errors) - goto the_end; - bind_libs_dynsyms(s1); - } else { - /* shared library case: simply export all global symbols */ - export_global_syms(s1); - } - } - build_got_entries(s1); - } - - /* we add a section for symbols */ - strsec = new_section(s1, ".shstrtab", SHT_STRTAB, 0); - put_elf_str(strsec, ""); - - /* Allocate strings for section names */ - textrel = alloc_sec_names(s1, file_type, strsec); - - if (dynamic) { - /* add a list of needed dlls */ - for(i = 0; i < s1->nb_loaded_dlls; i++) { - DLLReference *dllref = s1->loaded_dlls[i]; - if (dllref->level == 0) - put_dt(dynamic, DT_NEEDED, put_elf_str(dynstr, dllref->name)); - } - - if (s1->rpath) - put_dt(dynamic, s1->enable_new_dtags ? DT_RUNPATH : DT_RPATH, - put_elf_str(dynstr, s1->rpath)); - - if (file_type == TCC_OUTPUT_DLL) { - if (s1->soname) - put_dt(dynamic, DT_SONAME, put_elf_str(dynstr, s1->soname)); - /* XXX: currently, since we do not handle PIC code, we - must relocate the readonly segments */ - if (textrel) - put_dt(dynamic, DT_TEXTREL, 0); - } - - if (s1->symbolic) - put_dt(dynamic, DT_SYMBOLIC, 0); - - dyninf.dynamic = dynamic; - dyninf.dynstr = dynstr; - /* remember offset and reserve space for 2nd call below */ - dyninf.data_offset = dynamic->data_offset; - fill_dynamic(s1, &dyninf); - dynamic->sh_size = dynamic->data_offset; - dynstr->sh_size = dynstr->data_offset; - } - - /* compute number of program headers */ - if (file_type == TCC_OUTPUT_OBJ) - phnum = 0; - else if (file_type == TCC_OUTPUT_DLL) - phnum = 3; - else if (s1->static_link) - phnum = 2; - else - phnum = 5; - - /* allocate program segment headers */ - phdr = tcc_mallocz(phnum * sizeof(ElfW(Phdr))); - - /* compute number of sections */ - shnum = s1->nb_sections; - - /* this array is used to reorder sections in the output file */ - sec_order = tcc_malloc(sizeof(int) * shnum); - sec_order[0] = 0; - - /* compute section to program header mapping */ - file_offset = layout_sections(s1, phdr, phnum, interp, strsec, &dyninf, - sec_order); - - /* Fill remaining program header and finalize relocation related to dynamic - linking. */ - if (file_type != TCC_OUTPUT_OBJ) { - fill_unloadable_phdr(phdr, phnum, interp, dynamic); - if (dynamic) { - dynamic->data_offset = dyninf.data_offset; - fill_dynamic(s1, &dyninf); - - /* put in GOT the dynamic section address and relocate PLT */ - write32le(s1->got->data, dynamic->sh_addr); - if (file_type == TCC_OUTPUT_EXE - || (RELOCATE_DLLPLT && file_type == TCC_OUTPUT_DLL)) - relocate_plt(s1); - - /* relocate symbols in .dynsym now that final addresses are known */ - for_each_elem(s1->dynsym, 1, sym, ElfW(Sym)) { - if (sym->st_shndx != SHN_UNDEF && sym->st_shndx < SHN_LORESERVE) { - /* do symbol relocation */ - sym->st_value += s1->sections[sym->st_shndx]->sh_addr; - } - } - } - - /* if building executable or DLL, then relocate each section - except the GOT which is already relocated */ - ret = final_sections_reloc(s1); - if (ret) - goto the_end; - tidy_section_headers(s1, sec_order); - - /* Perform relocation to GOT or PLT entries */ - if (file_type == TCC_OUTPUT_EXE && s1->static_link) - fill_got(s1); - else if (s1->got) - fill_local_got_entries(s1); - } - - /* Create the ELF file with name 'filename' */ - ret = tcc_write_elf_file(s1, filename, phnum, phdr, file_offset, sec_order); - s1->nb_sections = shnum; - the_end: - tcc_free(sec_order); - tcc_free(phdr); - return ret; -} - -LIBTCCAPI int tcc_output_file(TCCState *s, const char *filename) -{ - int ret; -#ifdef TCC_TARGET_PE - if (s->output_type != TCC_OUTPUT_OBJ) { - ret = pe_output_file(s, filename); - } else -#endif - ret = elf_output_file(s, filename); - return ret; -} - -static void *load_data(int fd, unsigned long file_offset, unsigned long size) -{ - void *data; - - data = tcc_malloc(size); - lseek(fd, file_offset, SEEK_SET); - read(fd, data, size); - return data; -} - -typedef struct SectionMergeInfo { - Section *s; /* corresponding existing section */ - unsigned long offset; /* offset of the new section in the existing section */ - uint8_t new_section; /* true if section 's' was added */ - uint8_t link_once; /* true if link once section */ -} SectionMergeInfo; - -ST_FUNC int tcc_object_type(int fd, ElfW(Ehdr) *h) -{ - int size = read(fd, h, sizeof *h); - if (size == sizeof *h && 0 == memcmp(h, ELFMAG, 4)) { - if (h->e_type == ET_REL) - return AFF_BINTYPE_REL; - if (h->e_type == ET_DYN) - return AFF_BINTYPE_DYN; - } else if (size >= 8) { - if (0 == memcmp(h, ARMAG, 8)) - return AFF_BINTYPE_AR; -#ifdef TCC_TARGET_COFF - if (((struct filehdr*)h)->f_magic == COFF_C67_MAGIC) - return AFF_BINTYPE_C67; -#endif - } - return 0; -} - -/* load an object file and merge it with current files */ -/* XXX: handle correctly stab (debug) info */ -ST_FUNC int tcc_load_object_file(TCCState *s1, - int fd, unsigned long file_offset) -{ - ElfW(Ehdr) ehdr; - ElfW(Shdr) *shdr, *sh; - int size, i, j, offset, offseti, nb_syms, sym_index, ret, seencompressed; - unsigned char *strsec, *strtab; - int *old_to_new_syms; - char *sh_name, *name; - SectionMergeInfo *sm_table, *sm; - ElfW(Sym) *sym, *symtab; - ElfW_Rel *rel; - Section *s; - - int stab_index; - int stabstr_index; - - stab_index = stabstr_index = 0; - - lseek(fd, file_offset, SEEK_SET); - if (tcc_object_type(fd, &ehdr) != AFF_BINTYPE_REL) - goto fail1; - /* test CPU specific stuff */ - if (ehdr.e_ident[5] != ELFDATA2LSB || - ehdr.e_machine != EM_TCC_TARGET) { - fail1: - tcc_error_noabort("invalid object file"); - return -1; - } - /* read sections */ - shdr = load_data(fd, file_offset + ehdr.e_shoff, - sizeof(ElfW(Shdr)) * ehdr.e_shnum); - sm_table = tcc_mallocz(sizeof(SectionMergeInfo) * ehdr.e_shnum); - - /* load section names */ - sh = &shdr[ehdr.e_shstrndx]; - strsec = load_data(fd, file_offset + sh->sh_offset, sh->sh_size); - - /* load symtab and strtab */ - old_to_new_syms = NULL; - symtab = NULL; - strtab = NULL; - nb_syms = 0; - seencompressed = 0; - for(i = 1; i < ehdr.e_shnum; i++) { - sh = &shdr[i]; - if (sh->sh_type == SHT_SYMTAB) { - if (symtab) { - tcc_error_noabort("object must contain only one symtab"); - fail: - ret = -1; - goto the_end; - } - nb_syms = sh->sh_size / sizeof(ElfW(Sym)); - symtab = load_data(fd, file_offset + sh->sh_offset, sh->sh_size); - sm_table[i].s = symtab_section; - - /* now load strtab */ - sh = &shdr[sh->sh_link]; - strtab = load_data(fd, file_offset + sh->sh_offset, sh->sh_size); - } - if (sh->sh_flags & SHF_COMPRESSED) - seencompressed = 1; - } - - /* now examine each section and try to merge its content with the - ones in memory */ - for(i = 1; i < ehdr.e_shnum; i++) { - /* no need to examine section name strtab */ - if (i == ehdr.e_shstrndx) - continue; - sh = &shdr[i]; - sh_name = (char *) strsec + sh->sh_name; - /* ignore sections types we do not handle */ - if (sh->sh_type != SHT_PROGBITS && - sh->sh_type != SHT_RELX && -#ifdef TCC_ARM_EABI - sh->sh_type != SHT_ARM_EXIDX && -#endif - sh->sh_type != SHT_NOBITS && - sh->sh_type != SHT_PREINIT_ARRAY && - sh->sh_type != SHT_INIT_ARRAY && - sh->sh_type != SHT_FINI_ARRAY && - strcmp(sh_name, ".stabstr") - ) - continue; - if (seencompressed - && (!strncmp(sh_name, ".debug_", sizeof(".debug_")-1) - || (sh->sh_type == SHT_RELX - && !strncmp((char*)strsec + shdr[sh->sh_info].sh_name, - ".debug_", sizeof(".debug_")-1)))) - continue; - if (sh->sh_addralign < 1) - sh->sh_addralign = 1; - /* find corresponding section, if any */ - for(j = 1; j < s1->nb_sections;j++) { - s = s1->sections[j]; - if (!strcmp(s->name, sh_name)) { - if (!strncmp(sh_name, ".gnu.linkonce", - sizeof(".gnu.linkonce") - 1)) { - /* if a 'linkonce' section is already present, we - do not add it again. It is a little tricky as - symbols can still be defined in - it. */ - sm_table[i].link_once = 1; - goto next; - } else { - goto found; - } - } - } - /* not found: create new section */ - s = new_section(s1, sh_name, sh->sh_type, sh->sh_flags & ~SHF_GROUP); - /* take as much info as possible from the section. sh_link and - sh_info will be updated later */ - s->sh_addralign = sh->sh_addralign; - s->sh_entsize = sh->sh_entsize; - sm_table[i].new_section = 1; - found: - if (sh->sh_type != s->sh_type) { - tcc_error_noabort("invalid section type"); - goto fail; - } - - /* align start of section */ - offset = s->data_offset; - - if (0 == strcmp(sh_name, ".stab")) { - stab_index = i; - goto no_align; - } - if (0 == strcmp(sh_name, ".stabstr")) { - stabstr_index = i; - goto no_align; - } - - size = sh->sh_addralign - 1; - offset = (offset + size) & ~size; - if (sh->sh_addralign > s->sh_addralign) - s->sh_addralign = sh->sh_addralign; - s->data_offset = offset; - no_align: - sm_table[i].offset = offset; - sm_table[i].s = s; - /* concatenate sections */ - size = sh->sh_size; - if (sh->sh_type != SHT_NOBITS) { - unsigned char *ptr; - lseek(fd, file_offset + sh->sh_offset, SEEK_SET); - ptr = section_ptr_add(s, size); - read(fd, ptr, size); - } else { - s->data_offset += size; - } - next: ; - } - - /* gr relocate stab strings */ - if (stab_index && stabstr_index) { - Stab_Sym *a, *b; - unsigned o; - s = sm_table[stab_index].s; - a = (Stab_Sym *)(s->data + sm_table[stab_index].offset); - b = (Stab_Sym *)(s->data + s->data_offset); - o = sm_table[stabstr_index].offset; - while (a < b) - a->n_strx += o, a++; - } - - /* second short pass to update sh_link and sh_info fields of new - sections */ - for(i = 1; i < ehdr.e_shnum; i++) { - s = sm_table[i].s; - if (!s || !sm_table[i].new_section) - continue; - sh = &shdr[i]; - if (sh->sh_link > 0) - s->link = sm_table[sh->sh_link].s; - if (sh->sh_type == SHT_RELX) { - s->sh_info = sm_table[sh->sh_info].s->sh_num; - /* update backward link */ - s1->sections[s->sh_info]->reloc = s; - } - } - sm = sm_table; - - /* resolve symbols */ - old_to_new_syms = tcc_mallocz(nb_syms * sizeof(int)); - - sym = symtab + 1; - for(i = 1; i < nb_syms; i++, sym++) { - if (sym->st_shndx != SHN_UNDEF && - sym->st_shndx < SHN_LORESERVE) { - sm = &sm_table[sym->st_shndx]; - if (sm->link_once) { - /* if a symbol is in a link once section, we use the - already defined symbol. It is very important to get - correct relocations */ - if (ELFW(ST_BIND)(sym->st_info) != STB_LOCAL) { - name = (char *) strtab + sym->st_name; - sym_index = find_elf_sym(symtab_section, name); - if (sym_index) - old_to_new_syms[i] = sym_index; - } - continue; - } - /* if no corresponding section added, no need to add symbol */ - if (!sm->s) - continue; - /* convert section number */ - sym->st_shndx = sm->s->sh_num; - /* offset value */ - sym->st_value += sm->offset; - } - /* add symbol */ - name = (char *) strtab + sym->st_name; - sym_index = set_elf_sym(symtab_section, sym->st_value, sym->st_size, - sym->st_info, sym->st_other, - sym->st_shndx, name); - old_to_new_syms[i] = sym_index; - } - - /* third pass to patch relocation entries */ - for(i = 1; i < ehdr.e_shnum; i++) { - s = sm_table[i].s; - if (!s) - continue; - sh = &shdr[i]; - offset = sm_table[i].offset; - switch(s->sh_type) { - case SHT_RELX: - /* take relocation offset information */ - offseti = sm_table[sh->sh_info].offset; - for_each_elem(s, (offset / sizeof(*rel)), rel, ElfW_Rel) { - int type; - unsigned sym_index; - /* convert symbol index */ - type = ELFW(R_TYPE)(rel->r_info); - sym_index = ELFW(R_SYM)(rel->r_info); - /* NOTE: only one symtab assumed */ - if (sym_index >= nb_syms) - goto invalid_reloc; - sym_index = old_to_new_syms[sym_index]; - /* ignore link_once in rel section. */ - if (!sym_index && !sm->link_once -#ifdef TCC_TARGET_ARM - && type != R_ARM_V4BX -#endif - ) { - invalid_reloc: - tcc_error_noabort("Invalid relocation entry [%2d] '%s' @ %.8x", - i, strsec + sh->sh_name, rel->r_offset); - goto fail; - } - rel->r_info = ELFW(R_INFO)(sym_index, type); - /* offset the relocation offset */ - rel->r_offset += offseti; -#ifdef TCC_TARGET_ARM - /* Jumps and branches from a Thumb code to a PLT entry need - special handling since PLT entries are ARM code. - Unconditional bl instructions referencing PLT entries are - handled by converting these instructions into blx - instructions. Other case of instructions referencing a PLT - entry require to add a Thumb stub before the PLT entry to - switch to ARM mode. We set bit plt_thumb_stub of the - attribute of a symbol to indicate such a case. */ - if (type == R_ARM_THM_JUMP24) - get_sym_attr(s1, sym_index, 1)->plt_thumb_stub = 1; -#endif - } - break; - default: - break; - } - } - - ret = 0; - the_end: - tcc_free(symtab); - tcc_free(strtab); - tcc_free(old_to_new_syms); - tcc_free(sm_table); - tcc_free(strsec); - tcc_free(shdr); - return ret; -} - -typedef struct ArchiveHeader { - char ar_name[16]; /* name of this member */ - char ar_date[12]; /* file mtime */ - char ar_uid[6]; /* owner uid; printed as decimal */ - char ar_gid[6]; /* owner gid; printed as decimal */ - char ar_mode[8]; /* file mode, printed as octal */ - char ar_size[10]; /* file size, printed as decimal */ - char ar_fmag[2]; /* should contain ARFMAG */ -} ArchiveHeader; - -static int get_be32(const uint8_t *b) -{ - return b[3] | (b[2] << 8) | (b[1] << 16) | (b[0] << 24); -} - -static long get_be64(const uint8_t *b) -{ - long long ret = get_be32(b); - ret = (ret << 32) | (unsigned)get_be32(b+4); - return (long)ret; -} - -/* load only the objects which resolve undefined symbols */ -static int tcc_load_alacarte(TCCState *s1, int fd, int size, int entrysize) -{ - long i, bound, nsyms, sym_index, off, ret; - uint8_t *data; - const char *ar_names, *p; - const uint8_t *ar_index; - ElfW(Sym) *sym; - - data = tcc_malloc(size); - if (read(fd, data, size) != size) - goto fail; - nsyms = entrysize == 4 ? get_be32(data) : get_be64(data); - ar_index = data + entrysize; - ar_names = (char *) ar_index + nsyms * entrysize; - - do { - bound = 0; - for(p = ar_names, i = 0; i < nsyms; i++, p += strlen(p)+1) { - sym_index = find_elf_sym(symtab_section, p); - if(sym_index) { - sym = &((ElfW(Sym) *)symtab_section->data)[sym_index]; - if(sym->st_shndx == SHN_UNDEF) { - off = (entrysize == 4 - ? get_be32(ar_index + i * 4) - : get_be64(ar_index + i * 8)) - + sizeof(ArchiveHeader); - ++bound; - if(tcc_load_object_file(s1, fd, off) < 0) { - fail: - ret = -1; - goto the_end; - } - } - } - } - } while(bound); - ret = 0; - the_end: - tcc_free(data); - return ret; -} - -/* load a '.a' file */ -ST_FUNC int tcc_load_archive(TCCState *s1, int fd) -{ - ArchiveHeader hdr; - char ar_size[11]; - char ar_name[17]; - char magic[8]; - int size, len, i; - unsigned long file_offset; - - /* skip magic which was already checked */ - read(fd, magic, sizeof(magic)); - - for(;;) { - len = read(fd, &hdr, sizeof(hdr)); - if (len == 0) - break; - if (len != sizeof(hdr)) { - tcc_error_noabort("invalid archive"); - return -1; - } - memcpy(ar_size, hdr.ar_size, sizeof(hdr.ar_size)); - ar_size[sizeof(hdr.ar_size)] = '\0'; - size = strtol(ar_size, NULL, 0); - memcpy(ar_name, hdr.ar_name, sizeof(hdr.ar_name)); - for(i = sizeof(hdr.ar_name) - 1; i >= 0; i--) { - if (ar_name[i] != ' ') - break; - } - ar_name[i + 1] = '\0'; - file_offset = lseek(fd, 0, SEEK_CUR); - /* align to even */ - size = (size + 1) & ~1; - if (!strcmp(ar_name, "/")) { - /* coff symbol table : we handle it */ - if(s1->alacarte_link) - return tcc_load_alacarte(s1, fd, size, 4); - } else if (!strcmp(ar_name, "/SYM64/")) { - if(s1->alacarte_link) - return tcc_load_alacarte(s1, fd, size, 8); - } else { - ElfW(Ehdr) ehdr; - if (tcc_object_type(fd, &ehdr) == AFF_BINTYPE_REL) { - if (tcc_load_object_file(s1, fd, file_offset) < 0) - return -1; - } - } - lseek(fd, file_offset + size, SEEK_SET); - } - return 0; -} - -#ifndef TCC_TARGET_PE -/* load a DLL and all referenced DLLs. 'level = 0' means that the DLL - is referenced by the user (so it should be added as DT_NEEDED in - the generated ELF file) */ -ST_FUNC int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level) -{ - ElfW(Ehdr) ehdr; - ElfW(Shdr) *shdr, *sh, *sh1; - int i, j, nb_syms, nb_dts, sym_bind, ret; - ElfW(Sym) *sym, *dynsym; - ElfW(Dyn) *dt, *dynamic; - unsigned char *dynstr; - const char *name, *soname; - DLLReference *dllref; - - read(fd, &ehdr, sizeof(ehdr)); - - /* test CPU specific stuff */ - if (ehdr.e_ident[5] != ELFDATA2LSB || - ehdr.e_machine != EM_TCC_TARGET) { - tcc_error_noabort("bad architecture"); - return -1; - } - - /* read sections */ - shdr = load_data(fd, ehdr.e_shoff, sizeof(ElfW(Shdr)) * ehdr.e_shnum); - - /* load dynamic section and dynamic symbols */ - nb_syms = 0; - nb_dts = 0; - dynamic = NULL; - dynsym = NULL; /* avoid warning */ - dynstr = NULL; /* avoid warning */ - for(i = 0, sh = shdr; i < ehdr.e_shnum; i++, sh++) { - switch(sh->sh_type) { - case SHT_DYNAMIC: - nb_dts = sh->sh_size / sizeof(ElfW(Dyn)); - dynamic = load_data(fd, sh->sh_offset, sh->sh_size); - break; - case SHT_DYNSYM: - nb_syms = sh->sh_size / sizeof(ElfW(Sym)); - dynsym = load_data(fd, sh->sh_offset, sh->sh_size); - sh1 = &shdr[sh->sh_link]; - dynstr = load_data(fd, sh1->sh_offset, sh1->sh_size); - break; - default: - break; - } - } - - /* compute the real library name */ - soname = tcc_basename(filename); - - for(i = 0, dt = dynamic; i < nb_dts; i++, dt++) { - if (dt->d_tag == DT_SONAME) { - soname = (char *) dynstr + dt->d_un.d_val; - } - } - - /* if the dll is already loaded, do not load it */ - for(i = 0; i < s1->nb_loaded_dlls; i++) { - dllref = s1->loaded_dlls[i]; - if (!strcmp(soname, dllref->name)) { - /* but update level if needed */ - if (level < dllref->level) - dllref->level = level; - ret = 0; - goto the_end; - } - } - - /* add the dll and its level */ - dllref = tcc_mallocz(sizeof(DLLReference) + strlen(soname)); - dllref->level = level; - strcpy(dllref->name, soname); - dynarray_add(&s1->loaded_dlls, &s1->nb_loaded_dlls, dllref); - - /* add dynamic symbols in dynsym_section */ - for(i = 1, sym = dynsym + 1; i < nb_syms; i++, sym++) { - sym_bind = ELFW(ST_BIND)(sym->st_info); - if (sym_bind == STB_LOCAL) - continue; - name = (char *) dynstr + sym->st_name; - set_elf_sym(s1->dynsymtab_section, sym->st_value, sym->st_size, - sym->st_info, sym->st_other, sym->st_shndx, name); - } - - /* load all referenced DLLs */ - for(i = 0, dt = dynamic; i < nb_dts; i++, dt++) { - switch(dt->d_tag) { - case DT_NEEDED: - name = (char *) dynstr + dt->d_un.d_val; - for(j = 0; j < s1->nb_loaded_dlls; j++) { - dllref = s1->loaded_dlls[j]; - if (!strcmp(name, dllref->name)) - goto already_loaded; - } - if (tcc_add_dll(s1, name, AFF_REFERENCED_DLL) < 0) { - tcc_error_noabort("referenced dll '%s' not found", name); - ret = -1; - goto the_end; - } - already_loaded: - break; - } - } - ret = 0; - the_end: - tcc_free(dynstr); - tcc_free(dynsym); - tcc_free(dynamic); - tcc_free(shdr); - return ret; -} - -#define LD_TOK_NAME 256 -#define LD_TOK_EOF (-1) - -/* return next ld script token */ -static int ld_next(TCCState *s1, char *name, int name_size) -{ - int c; - char *q; - - redo: - switch(ch) { - case ' ': - case '\t': - case '\f': - case '\v': - case '\r': - case '\n': - inp(); - goto redo; - case '/': - minp(); - if (ch == '*') { - file->buf_ptr = parse_comment(file->buf_ptr); - ch = file->buf_ptr[0]; - goto redo; - } else { - q = name; - *q++ = '/'; - goto parse_name; - } - break; - case '\\': - ch = handle_eob(); - if (ch != '\\') - goto redo; - /* fall through */ - /* case 'a' ... 'z': */ - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': - /* case 'A' ... 'z': */ - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '_': - case '.': - case '$': - case '~': - q = name; - parse_name: - for(;;) { - if (!((ch >= 'a' && ch <= 'z') || - (ch >= 'A' && ch <= 'Z') || - (ch >= '0' && ch <= '9') || - strchr("/.-_+=$:\\,~", ch))) - break; - if ((q - name) < name_size - 1) { - *q++ = ch; - } - minp(); - } - *q = '\0'; - c = LD_TOK_NAME; - break; - case CH_EOF: - c = LD_TOK_EOF; - break; - default: - c = ch; - inp(); - break; - } - return c; -} - -static int ld_add_file(TCCState *s1, const char filename[]) -{ - if (filename[0] == '/') { - if (CONFIG_SYSROOT[0] == '\0' - && tcc_add_file_internal(s1, filename, AFF_TYPE_BIN) == 0) - return 0; - filename = tcc_basename(filename); - } - return tcc_add_dll(s1, filename, 0); -} - -static inline int new_undef_syms(void) -{ - int ret = 0; - ret = new_undef_sym; - new_undef_sym = 0; - return ret; -} - -static int ld_add_file_list(TCCState *s1, const char *cmd, int as_needed) -{ - char filename[1024], libname[1024]; - int t, group, nblibs = 0, ret = 0; - char **libs = NULL; - - group = !strcmp(cmd, "GROUP"); - if (!as_needed) - new_undef_syms(); - t = ld_next(s1, filename, sizeof(filename)); - if (t != '(') - expect("("); - t = ld_next(s1, filename, sizeof(filename)); - for(;;) { - libname[0] = '\0'; - if (t == LD_TOK_EOF) { - tcc_error_noabort("unexpected end of file"); - ret = -1; - goto lib_parse_error; - } else if (t == ')') { - break; - } else if (t == '-') { - t = ld_next(s1, filename, sizeof(filename)); - if ((t != LD_TOK_NAME) || (filename[0] != 'l')) { - tcc_error_noabort("library name expected"); - ret = -1; - goto lib_parse_error; - } - pstrcpy(libname, sizeof libname, &filename[1]); - if (s1->static_link) { - snprintf(filename, sizeof filename, "lib%s.a", libname); - } else { - snprintf(filename, sizeof filename, "lib%s.so", libname); - } - } else if (t != LD_TOK_NAME) { - tcc_error_noabort("filename expected"); - ret = -1; - goto lib_parse_error; - } - if (!strcmp(filename, "AS_NEEDED")) { - ret = ld_add_file_list(s1, cmd, 1); - if (ret) - goto lib_parse_error; - } else { - /* TODO: Implement AS_NEEDED support. Ignore it for now */ - if (!as_needed) { - ret = ld_add_file(s1, filename); - if (ret) - goto lib_parse_error; - if (group) { - /* Add the filename *and* the libname to avoid future conversions */ - dynarray_add(&libs, &nblibs, tcc_strdup(filename)); - if (libname[0] != '\0') - dynarray_add(&libs, &nblibs, tcc_strdup(libname)); - } - } - } - t = ld_next(s1, filename, sizeof(filename)); - if (t == ',') { - t = ld_next(s1, filename, sizeof(filename)); - } - } - if (group && !as_needed) { - while (new_undef_syms()) { - int i; - - for (i = 0; i < nblibs; i ++) - ld_add_file(s1, libs[i]); - } - } -lib_parse_error: - dynarray_reset(&libs, &nblibs); - return ret; -} - -/* interpret a subset of GNU ldscripts to handle the dummy libc.so - files */ -ST_FUNC int tcc_load_ldscript(TCCState *s1) -{ - char cmd[64]; - char filename[1024]; - int t, ret; - - ch = handle_eob(); - for(;;) { - t = ld_next(s1, cmd, sizeof(cmd)); - if (t == LD_TOK_EOF) - return 0; - else if (t != LD_TOK_NAME) - return -1; - if (!strcmp(cmd, "INPUT") || - !strcmp(cmd, "GROUP")) { - ret = ld_add_file_list(s1, cmd, 0); - if (ret) - return ret; - } else if (!strcmp(cmd, "OUTPUT_FORMAT") || - !strcmp(cmd, "TARGET")) { - /* ignore some commands */ - t = ld_next(s1, cmd, sizeof(cmd)); - if (t != '(') - expect("("); - for(;;) { - t = ld_next(s1, filename, sizeof(filename)); - if (t == LD_TOK_EOF) { - tcc_error_noabort("unexpected end of file"); - return -1; - } else if (t == ')') { - break; - } - } - } else { - return -1; - } - } - return 0; -} -#endif /* !TCC_TARGET_PE */ diff --git a/05/tcc-final-old/tccgen.c b/05/tcc-final-old/tccgen.c deleted file mode 100644 index e0b744e..0000000 --- a/05/tcc-final-old/tccgen.c +++ /dev/null @@ -1,7386 +0,0 @@ -/* - * TCC - Tiny C Compiler - * - * Copyright (c) 2001-2004 Fabrice Bellard - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "tcc.h" - -/********************************************************/ -/* global variables */ - -/* loc : local variable index - ind : output code index - rsym: return symbol - anon_sym: anonymous symbol index -*/ -ST_DATA int rsym, anon_sym, ind, loc; - -ST_DATA Sym *sym_free_first; -ST_DATA void **sym_pools; -ST_DATA int nb_sym_pools; - -ST_DATA Sym *global_stack; -ST_DATA Sym *local_stack; -ST_DATA Sym *define_stack; -ST_DATA Sym *global_label_stack; -ST_DATA Sym *local_label_stack; -static int local_scope; -static int in_sizeof; -static int section_sym; - -ST_DATA int vlas_in_scope; /* number of VLAs that are currently in scope */ -ST_DATA int vla_sp_root_loc; /* vla_sp_loc for SP before any VLAs were pushed */ -ST_DATA int vla_sp_loc; /* Pointer to variable holding location to store stack pointer on the stack when modifying stack pointer */ - -ST_DATA SValue __vstack[1+VSTACK_SIZE], *vtop, *pvtop; - -ST_DATA int const_wanted; /* true if constant wanted */ -ST_DATA int nocode_wanted; /* no code generation wanted */ -#define NODATA_WANTED (nocode_wanted > 0) /* no static data output wanted either */ -#define STATIC_DATA_WANTED (nocode_wanted & 0xC0000000) /* only static data output */ -ST_DATA int global_expr; /* true if compound literals must be allocated globally (used during initializers parsing */ -ST_DATA CType func_vt; /* current function return type (used by return instruction) */ -ST_DATA int func_var; /* true if current function is variadic (used by return instruction) */ -ST_DATA int func_vc; -ST_DATA int last_line_num, last_ind, func_ind; /* debug last line number and pc */ -ST_DATA const char *funcname; -ST_DATA int g_debug; - -ST_DATA CType char_pointer_type, func_old_type, int_type, size_type, ptrdiff_type; - -ST_DATA struct switch_t { - struct case_t { - int64_t v1, v2; - int sym; - } **p; int n; /* list of case ranges */ - int def_sym; /* default symbol */ -} *cur_switch; /* current switch */ - -/* ------------------------------------------------------------------------- */ - -static void gen_cast(CType *type); -static void gen_cast_s(int t); -static inline CType *pointed_type(CType *type); -static int is_compatible_types(CType *type1, CType *type2); -static int parse_btype(CType *type, AttributeDef *ad); -static CType *type_decl(CType *type, AttributeDef *ad, int *v, int td); -static void parse_expr_type(CType *type); -static void init_putv(CType *type, Section *sec, unsigned long c); -static void decl_initializer(CType *type, Section *sec, unsigned long c, int first, int size_only); -static void block(int *bsym, int *csym, int is_expr); -static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, int has_init, int v, int scope); -static void decl(int l); -static int decl0(int l, int is_for_loop_init, Sym *); -static void expr_eq(void); -static void vla_runtime_type_size(CType *type, int *a); -static void vla_sp_restore(void); -static void vla_sp_restore_root(void); -static int is_compatible_unqualified_types(CType *type1, CType *type2); -static inline int64_t expr_const64(void); -static void vpush64(int ty, unsigned long long v); -static void vpush(CType *type); -static int gvtst(int inv, int t); -static void gen_inline_functions(TCCState *s); -static void skip_or_save_block(TokenString **str); -static void gv_dup(void); - -ST_INLN int is_float(int t) -{ - int bt; - bt = t & VT_BTYPE; - return bt == VT_LDOUBLE || bt == VT_DOUBLE || bt == VT_FLOAT || bt == VT_QFLOAT; -} - -/* we use our own 'finite' function to avoid potential problems with - non standard math libs */ -/* XXX: endianness dependent */ -ST_FUNC int ieee_finite(double d) -{ - int p[4]; - memcpy(p, &d, sizeof(double)); - return ((unsigned)((p[1] | 0x800fffff) + 1)) >> 31; -} - -/* compiling intel long double natively */ -#if (defined __i386__ || defined __x86_64__) \ - && (defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64) -# define TCC_IS_NATIVE_387 -#endif - -ST_FUNC void test_lvalue(void) -{ - if (!(vtop->r & VT_LVAL)) - expect("lvalue"); -} - -ST_FUNC void check_vstack(void) -{ - if (pvtop != vtop) - tcc_error("internal compiler error: vstack leak (%d)", vtop - pvtop); -} - -/* ------------------------------------------------------------------------- */ -/* vstack debugging aid */ - -#if 0 -void pv (const char *lbl, int a, int b) -{ - int i; - for (i = a; i < a + b; ++i) { - SValue *p = &vtop[-i]; - printf("%s vtop[-%d] : type.t:%04x r:%04x r2:%04x c.i:%d\n", - lbl, i, p->type.t, p->r, p->r2, (int)p->c.i); - } -} -#endif - -/* ------------------------------------------------------------------------- */ -/* start of translation unit info */ -ST_FUNC void tcc_debug_start(TCCState *s1) -{ - if (s1->do_debug) { - char buf[512]; - - /* file info: full path + filename */ - section_sym = put_elf_sym(symtab_section, 0, 0, - ELFW(ST_INFO)(STB_LOCAL, STT_SECTION), 0, - text_section->sh_num, NULL); - getcwd(buf, sizeof(buf)); -#ifdef _WIN32 - normalize_slashes(buf); -#endif - pstrcat(buf, sizeof(buf), "/"); - put_stabs_r(buf, N_SO, 0, 0, - text_section->data_offset, text_section, section_sym); - put_stabs_r(file->filename, N_SO, 0, 0, - text_section->data_offset, text_section, section_sym); - last_ind = 0; - last_line_num = 0; - } - - /* an elf symbol of type STT_FILE must be put so that STB_LOCAL - symbols can be safely used */ - put_elf_sym(symtab_section, 0, 0, - ELFW(ST_INFO)(STB_LOCAL, STT_FILE), 0, - SHN_ABS, file->filename); -} - -/* put end of translation unit info */ -ST_FUNC void tcc_debug_end(TCCState *s1) -{ - if (!s1->do_debug) - return; - put_stabs_r(NULL, N_SO, 0, 0, - text_section->data_offset, text_section, section_sym); - -} - -/* generate line number info */ -ST_FUNC void tcc_debug_line(TCCState *s1) -{ - if (!s1->do_debug) - return; - if ((last_line_num != file->line_num || last_ind != ind)) { - put_stabn(N_SLINE, 0, file->line_num, ind - func_ind); - last_ind = ind; - last_line_num = file->line_num; - } -} - -/* put function symbol */ -ST_FUNC void tcc_debug_funcstart(TCCState *s1, Sym *sym) -{ - char buf[512]; - - if (!s1->do_debug) - return; - - /* stabs info */ - /* XXX: we put here a dummy type */ - snprintf(buf, sizeof(buf), "%s:%c1", - funcname, sym->type.t & VT_STATIC ? 'f' : 'F'); - put_stabs_r(buf, N_FUN, 0, file->line_num, 0, - cur_text_section, sym->c); - /* //gr gdb wants a line at the function */ - put_stabn(N_SLINE, 0, file->line_num, 0); - - last_ind = 0; - last_line_num = 0; -} - -/* put function size */ -ST_FUNC void tcc_debug_funcend(TCCState *s1, int size) -{ - if (!s1->do_debug) - return; - put_stabn(N_FUN, 0, 0, size); -} - -/* ------------------------------------------------------------------------- */ -ST_FUNC int tccgen_compile(TCCState *s1) -{ - cur_text_section = NULL; - funcname = ""; - anon_sym = SYM_FIRST_ANOM; - section_sym = 0; - const_wanted = 0; - nocode_wanted = 0x80000000; - - /* define some often used types */ - int_type.t = VT_INT; - char_pointer_type.t = VT_BYTE; - mk_pointer(&char_pointer_type); -#if PTR_SIZE == 4 - size_type.t = VT_INT | VT_UNSIGNED; - ptrdiff_type.t = VT_INT; -#elif LONG_SIZE == 4 - size_type.t = VT_LLONG | VT_UNSIGNED; - ptrdiff_type.t = VT_LLONG; -#else - size_type.t = VT_LONG | VT_LLONG | VT_UNSIGNED; - ptrdiff_type.t = VT_LONG | VT_LLONG; -#endif - func_old_type.t = VT_FUNC; - func_old_type.ref = sym_push(SYM_FIELD, &int_type, 0, 0); - func_old_type.ref->f.func_call = FUNC_CDECL; - func_old_type.ref->f.func_type = FUNC_OLD; - - tcc_debug_start(s1); - -#ifdef TCC_TARGET_ARM - arm_init(s1); -#endif - -#ifdef INC_DEBUG - printf("%s: **** new file\n", file->filename); -#endif - - parse_flags = PARSE_FLAG_PREPROCESS | PARSE_FLAG_TOK_NUM | PARSE_FLAG_TOK_STR; - next(); - decl(VT_CONST); - gen_inline_functions(s1); - check_vstack(); - /* end of translation unit info */ - tcc_debug_end(s1); - return 0; -} - -/* ------------------------------------------------------------------------- */ -ST_FUNC ElfSym *elfsym(Sym *s) -{ - if (!s || !s->c) - return NULL; - return &((ElfSym *)symtab_section->data)[s->c]; -} - -/* apply storage attributes to Elf symbol */ -ST_FUNC void update_storage(Sym *sym) -{ - ElfSym *esym; - int sym_bind, old_sym_bind; - - esym = elfsym(sym); - if (!esym) - return; - - if (sym->a.visibility) - esym->st_other = (esym->st_other & ~ELFW(ST_VISIBILITY)(-1)) - | sym->a.visibility; - - if (sym->type.t & VT_STATIC) - sym_bind = STB_LOCAL; - else if (sym->a.weak) - sym_bind = STB_WEAK; - else - sym_bind = STB_GLOBAL; - old_sym_bind = ELFW(ST_BIND)(esym->st_info); - if (sym_bind != old_sym_bind) { - esym->st_info = ELFW(ST_INFO)(sym_bind, ELFW(ST_TYPE)(esym->st_info)); - } - -#ifdef TCC_TARGET_PE - if (sym->a.dllimport) - esym->st_other |= ST_PE_IMPORT; - if (sym->a.dllexport) - esym->st_other |= ST_PE_EXPORT; -#endif - -#if 0 - printf("storage %s: bind=%c vis=%d exp=%d imp=%d\n", - get_tok_str(sym->v, NULL), - sym_bind == STB_WEAK ? 'w' : sym_bind == STB_LOCAL ? 'l' : 'g', - sym->a.visibility, - sym->a.dllexport, - sym->a.dllimport - ); -#endif -} - -/* ------------------------------------------------------------------------- */ -/* update sym->c so that it points to an external symbol in section - 'section' with value 'value' */ - -ST_FUNC void put_extern_sym2(Sym *sym, int sh_num, - addr_t value, unsigned long size, - int can_add_underscore) -{ - int sym_type, sym_bind, info, other, t; - ElfSym *esym; - const char *name; - char buf1[256]; -#ifdef CONFIG_TCC_BCHECK - char buf[32]; -#endif - - if (!sym->c) { - name = get_tok_str(sym->v, NULL); -#ifdef CONFIG_TCC_BCHECK - if (tcc_state->do_bounds_check) { - /* XXX: avoid doing that for statics ? */ - /* if bound checking is activated, we change some function - names by adding the "__bound" prefix */ - switch(sym->v) { -#ifdef TCC_TARGET_PE - /* XXX: we rely only on malloc hooks */ - case TOK_malloc: - case TOK_free: - case TOK_realloc: - case TOK_memalign: - case TOK_calloc: -#endif - case TOK_memcpy: - case TOK_memmove: - case TOK_memset: - case TOK_strlen: - case TOK_strcpy: - case TOK_alloca: - strcpy(buf, "__bound_"); - strcat(buf, name); - name = buf; - break; - } - } -#endif - t = sym->type.t; - if ((t & VT_BTYPE) == VT_FUNC) { - sym_type = STT_FUNC; - } else if ((t & VT_BTYPE) == VT_VOID) { - sym_type = STT_NOTYPE; - } else { - sym_type = STT_OBJECT; - } - if (t & VT_STATIC) - sym_bind = STB_LOCAL; - else - sym_bind = STB_GLOBAL; - other = 0; -#ifdef TCC_TARGET_PE - if (sym_type == STT_FUNC && sym->type.ref) { - Sym *ref = sym->type.ref; - if (ref->f.func_call == FUNC_STDCALL && can_add_underscore) { - sprintf(buf1, "_%s@%d", name, ref->f.func_args * PTR_SIZE); - name = buf1; - other |= ST_PE_STDCALL; - can_add_underscore = 0; - } - } -#endif - if (tcc_state->leading_underscore && can_add_underscore) { - buf1[0] = '_'; - pstrcpy(buf1 + 1, sizeof(buf1) - 1, name); - name = buf1; - } - if (sym->asm_label) - name = get_tok_str(sym->asm_label, NULL); - info = ELFW(ST_INFO)(sym_bind, sym_type); - sym->c = put_elf_sym(symtab_section, value, size, info, other, sh_num, name); - } else { - esym = elfsym(sym); - esym->st_value = value; - esym->st_size = size; - esym->st_shndx = sh_num; - } - update_storage(sym); -} - -ST_FUNC void put_extern_sym(Sym *sym, Section *section, - addr_t value, unsigned long size) -{ - int sh_num = section ? section->sh_num : SHN_UNDEF; - put_extern_sym2(sym, sh_num, value, size, 1); -} - -/* add a new relocation entry to symbol 'sym' in section 's' */ -ST_FUNC void greloca(Section *s, Sym *sym, unsigned long offset, int type, - addr_t addend) -{ - int c = 0; - - if (nocode_wanted && s == cur_text_section) - return; - - if (sym) { - if (0 == sym->c) - put_extern_sym(sym, NULL, 0, 0); - c = sym->c; - } - - /* now we can add ELF relocation info */ - put_elf_reloca(symtab_section, s, offset, type, c, addend); -} - -#if PTR_SIZE == 4 -ST_FUNC void greloc(Section *s, Sym *sym, unsigned long offset, int type) -{ - greloca(s, sym, offset, type, 0); -} -#endif - -/* ------------------------------------------------------------------------- */ -/* symbol allocator */ -static Sym *__sym_malloc(void) -{ - Sym *sym_pool, *sym, *last_sym; - int i; - - sym_pool = tcc_malloc(SYM_POOL_NB * sizeof(Sym)); - dynarray_add(&sym_pools, &nb_sym_pools, sym_pool); - - last_sym = sym_free_first; - sym = sym_pool; - for(i = 0; i < SYM_POOL_NB; i++) { - sym->next = last_sym; - last_sym = sym; - sym++; - } - sym_free_first = last_sym; - return last_sym; -} - -static inline Sym *sym_malloc(void) -{ - Sym *sym; -#ifndef SYM_DEBUG - sym = sym_free_first; - if (!sym) - sym = __sym_malloc(); - sym_free_first = sym->next; - return sym; -#else - sym = tcc_malloc(sizeof(Sym)); - return sym; -#endif -} - -ST_INLN void sym_free(Sym *sym) -{ -#ifndef SYM_DEBUG - sym->next = sym_free_first; - sym_free_first = sym; -#else - tcc_free(sym); -#endif -} - -/* push, without hashing */ -ST_FUNC Sym *sym_push2(Sym **ps, int v, int t, int c) -{ - Sym *s; - - s = sym_malloc(); - memset(s, 0, sizeof *s); - s->v = v; - s->type.t = t; - s->c = c; - /* add in stack */ - s->prev = *ps; - *ps = s; - return s; -} - -/* find a symbol and return its associated structure. 's' is the top - of the symbol stack */ -ST_FUNC Sym *sym_find2(Sym *s, int v) -{ - while (s) { - if (s->v == v) - return s; - else if (s->v == -1) - return NULL; - s = s->prev; - } - return NULL; -} - -/* structure lookup */ -ST_INLN Sym *struct_find(int v) -{ - v -= TOK_IDENT; - if ((unsigned)v >= (unsigned)(tok_ident - TOK_IDENT)) - return NULL; - return table_ident[v]->sym_struct; -} - -/* find an identifier */ -ST_INLN Sym *sym_find(int v) -{ - v -= TOK_IDENT; - if ((unsigned)v >= (unsigned)(tok_ident - TOK_IDENT)) - return NULL; - return table_ident[v]->sym_identifier; -} - -/* push a given symbol on the symbol stack */ -ST_FUNC Sym *sym_push(int v, CType *type, int r, int c) -{ - Sym *s, **ps; - TokenSym *ts; - - if (local_stack) - ps = &local_stack; - else - ps = &global_stack; - s = sym_push2(ps, v, type->t, c); - s->type.ref = type->ref; - s->r = r; - /* don't record fields or anonymous symbols */ - /* XXX: simplify */ - if (!(v & SYM_FIELD) && (v & ~SYM_STRUCT) < SYM_FIRST_ANOM) { - /* record symbol in token array */ - ts = table_ident[(v & ~SYM_STRUCT) - TOK_IDENT]; - if (v & SYM_STRUCT) - ps = &ts->sym_struct; - else - ps = &ts->sym_identifier; - s->prev_tok = *ps; - *ps = s; - s->sym_scope = local_scope; - if (s->prev_tok && s->prev_tok->sym_scope == s->sym_scope) - tcc_error("redeclaration of '%s'", - get_tok_str(v & ~SYM_STRUCT, NULL)); - } - return s; -} - -/* push a global identifier */ -ST_FUNC Sym *global_identifier_push(int v, int t, int c) -{ - Sym *s, **ps; - s = sym_push2(&global_stack, v, t, c); - /* don't record anonymous symbol */ - if (v < SYM_FIRST_ANOM) { - ps = &table_ident[v - TOK_IDENT]->sym_identifier; - /* modify the top most local identifier, so that - sym_identifier will point to 's' when popped */ - while (*ps != NULL && (*ps)->sym_scope) - ps = &(*ps)->prev_tok; - s->prev_tok = *ps; - *ps = s; - } - return s; -} - -/* pop symbols until top reaches 'b'. If KEEP is non-zero don't really - pop them yet from the list, but do remove them from the token array. */ -ST_FUNC void sym_pop(Sym **ptop, Sym *b, int keep) -{ - Sym *s, *ss, **ps; - TokenSym *ts; - int v; - - s = *ptop; - while(s != b) { - ss = s->prev; - v = s->v; - /* remove symbol in token array */ - /* XXX: simplify */ - if (!(v & SYM_FIELD) && (v & ~SYM_STRUCT) < SYM_FIRST_ANOM) { - ts = table_ident[(v & ~SYM_STRUCT) - TOK_IDENT]; - if (v & SYM_STRUCT) - ps = &ts->sym_struct; - else - ps = &ts->sym_identifier; - *ps = s->prev_tok; - } - if (!keep) - sym_free(s); - s = ss; - } - if (!keep) - *ptop = b; -} - -/* ------------------------------------------------------------------------- */ - -static void vsetc(CType *type, int r, CValue *vc) -{ - int v; - - if (vtop >= vstack + (VSTACK_SIZE - 1)) - tcc_error("memory full (vstack)"); - /* cannot let cpu flags if other instruction are generated. Also - avoid leaving VT_JMP anywhere except on the top of the stack - because it would complicate the code generator. - - Don't do this when nocode_wanted. vtop might come from - !nocode_wanted regions (see 88_codeopt.c) and transforming - it to a register without actually generating code is wrong - as their value might still be used for real. All values - we push under nocode_wanted will eventually be popped - again, so that the VT_CMP/VT_JMP value will be in vtop - when code is unsuppressed again. - - Same logic below in vswap(); */ - if (vtop >= vstack && !nocode_wanted) { - v = vtop->r & VT_VALMASK; - if (v == VT_CMP || (v & ~1) == VT_JMP) - gv(RC_INT); - } - - vtop++; - vtop->type = *type; - vtop->r = r; - vtop->r2 = VT_CONST; - vtop->c = *vc; - vtop->sym = NULL; -} - -ST_FUNC void vswap(void) -{ - SValue tmp; - /* cannot vswap cpu flags. See comment at vsetc() above */ - if (vtop >= vstack && !nocode_wanted) { - int v = vtop->r & VT_VALMASK; - if (v == VT_CMP || (v & ~1) == VT_JMP) - gv(RC_INT); - } - tmp = vtop[0]; - vtop[0] = vtop[-1]; - vtop[-1] = tmp; -} - -/* pop stack value */ -ST_FUNC void vpop(void) -{ - int v; - v = vtop->r & VT_VALMASK; -#if defined(TCC_TARGET_I386) || defined(TCC_TARGET_X86_64) - /* for x86, we need to pop the FP stack */ - if (v == TREG_ST0) { - o(0xd8dd); /* fstp %st(0) */ - } else -#endif - if (v == VT_JMP || v == VT_JMPI) { - /* need to put correct jump if && or || without test */ - gsym(vtop->c.i); - } - vtop--; -} - -/* push constant of type "type" with useless value */ -ST_FUNC void vpush(CType *type) -{ - vset(type, VT_CONST, 0); -} - -/* push integer constant */ -ST_FUNC void vpushi(int v) -{ - CValue cval; - cval.i = v; - vsetc(&int_type, VT_CONST, &cval); -} - -/* push a pointer sized constant */ -static void vpushs(addr_t v) -{ - CValue cval; - cval.i = v; - vsetc(&size_type, VT_CONST, &cval); -} - -/* push arbitrary 64bit constant */ -ST_FUNC void vpush64(int ty, unsigned long long v) -{ - CValue cval; - CType ctype; - ctype.t = ty; - ctype.ref = NULL; - cval.i = v; - vsetc(&ctype, VT_CONST, &cval); -} - -/* push long long constant */ -static inline void vpushll(long long v) -{ - vpush64(VT_LLONG, v); -} - -ST_FUNC void vset(CType *type, int r, int v) -{ - CValue cval; - - cval.i = v; - vsetc(type, r, &cval); -} - -static void vseti(int r, int v) -{ - CType type; - type.t = VT_INT; - type.ref = NULL; - vset(&type, r, v); -} - -ST_FUNC void vpushv(SValue *v) -{ - if (vtop >= vstack + (VSTACK_SIZE - 1)) - tcc_error("memory full (vstack)"); - vtop++; - *vtop = *v; -} - -static void vdup(void) -{ - vpushv(vtop); -} - -/* rotate n first stack elements to the bottom - I1 ... In -> I2 ... In I1 [top is right] -*/ -ST_FUNC void vrotb(int n) -{ - int i; - SValue tmp; - - tmp = vtop[-n + 1]; - for(i=-n+1;i!=0;i++) - vtop[i] = vtop[i+1]; - vtop[0] = tmp; -} - -/* rotate the n elements before entry e towards the top - I1 ... In ... -> In I1 ... I(n-1) ... [top is right] - */ -ST_FUNC void vrote(SValue *e, int n) -{ - int i; - SValue tmp; - - tmp = *e; - for(i = 0;i < n - 1; i++) - e[-i] = e[-i - 1]; - e[-n + 1] = tmp; -} - -/* rotate n first stack elements to the top - I1 ... In -> In I1 ... I(n-1) [top is right] - */ -ST_FUNC void vrott(int n) -{ - vrote(vtop, n); -} - -/* push a symbol value of TYPE */ -static inline void vpushsym(CType *type, Sym *sym) -{ - CValue cval; - cval.i = 0; - vsetc(type, VT_CONST | VT_SYM, &cval); - vtop->sym = sym; -} - -/* Return a static symbol pointing to a section */ -ST_FUNC Sym *get_sym_ref(CType *type, Section *sec, unsigned long offset, unsigned long size) -{ - int v; - Sym *sym; - - v = anon_sym++; - sym = global_identifier_push(v, type->t | VT_STATIC, 0); - sym->type.ref = type->ref; - sym->r = VT_CONST | VT_SYM; - put_extern_sym(sym, sec, offset, size); - return sym; -} - -/* push a reference to a section offset by adding a dummy symbol */ -static void vpush_ref(CType *type, Section *sec, unsigned long offset, unsigned long size) -{ - vpushsym(type, get_sym_ref(type, sec, offset, size)); -} - -/* define a new external reference to a symbol 'v' of type 'u' */ -ST_FUNC Sym *external_global_sym(int v, CType *type, int r) -{ - Sym *s; - - s = sym_find(v); - if (!s) { - /* push forward reference */ - s = global_identifier_push(v, type->t | VT_EXTERN, 0); - s->type.ref = type->ref; - s->r = r | VT_CONST | VT_SYM; - } else if (IS_ASM_SYM(s)) { - s->type.t = type->t | (s->type.t & VT_EXTERN); - s->type.ref = type->ref; - update_storage(s); - } - return s; -} - -/* Merge some type attributes. */ -static void patch_type(Sym *sym, CType *type) -{ - if (!(type->t & VT_EXTERN)) { - if (!(sym->type.t & VT_EXTERN)) - tcc_error("redefinition of '%s'", get_tok_str(sym->v, NULL)); - sym->type.t &= ~VT_EXTERN; - } - - if (IS_ASM_SYM(sym)) { - /* stay static if both are static */ - sym->type.t = type->t & (sym->type.t | ~VT_STATIC); - sym->type.ref = type->ref; - } - - if (!is_compatible_types(&sym->type, type)) { - tcc_error("incompatible types for redefinition of '%s'", - get_tok_str(sym->v, NULL)); - - } else if ((sym->type.t & VT_BTYPE) == VT_FUNC) { - int static_proto = sym->type.t & VT_STATIC; - /* warn if static follows non-static function declaration */ - if ((type->t & VT_STATIC) && !static_proto && !(type->t & VT_INLINE)) - tcc_warning("static storage ignored for redefinition of '%s'", - get_tok_str(sym->v, NULL)); - - if (0 == (type->t & VT_EXTERN)) { - /* put complete type, use static from prototype */ - sym->type.t = (type->t & ~VT_STATIC) | static_proto; - if (type->t & VT_INLINE) - sym->type.t = type->t; - sym->type.ref = type->ref; - } - - } else { - if ((sym->type.t & VT_ARRAY) && type->ref->c >= 0) { - /* set array size if it was omitted in extern declaration */ - if (sym->type.ref->c < 0) - sym->type.ref->c = type->ref->c; - else if (sym->type.ref->c != type->ref->c) - tcc_error("conflicting type for '%s'", get_tok_str(sym->v, NULL)); - } - if ((type->t ^ sym->type.t) & VT_STATIC) - tcc_warning("storage mismatch for redefinition of '%s'", - get_tok_str(sym->v, NULL)); - } -} - - -/* Merge some storage attributes. */ -static void patch_storage(Sym *sym, AttributeDef *ad, CType *type) -{ - if (type) - patch_type(sym, type); - -#ifdef TCC_TARGET_PE - if (sym->a.dllimport != ad->a.dllimport) - tcc_error("incompatible dll linkage for redefinition of '%s'", - get_tok_str(sym->v, NULL)); - sym->a.dllexport |= ad->a.dllexport; -#endif - sym->a.weak |= ad->a.weak; - if (ad->a.visibility) { - int vis = sym->a.visibility; - int vis2 = ad->a.visibility; - if (vis == STV_DEFAULT) - vis = vis2; - else if (vis2 != STV_DEFAULT) - vis = (vis < vis2) ? vis : vis2; - sym->a.visibility = vis; - } - if (ad->a.aligned) - sym->a.aligned = ad->a.aligned; - if (ad->asm_label) - sym->asm_label = ad->asm_label; - update_storage(sym); -} - -/* define a new external reference to a symbol 'v' */ -static Sym *external_sym(int v, CType *type, int r, AttributeDef *ad) -{ - Sym *s; - s = sym_find(v); - if (!s) { - /* push forward reference */ - s = sym_push(v, type, r | VT_CONST | VT_SYM, 0); - s->type.t |= VT_EXTERN; - s->a = ad->a; - s->sym_scope = 0; - } else { - if (s->type.ref == func_old_type.ref) { - s->type.ref = type->ref; - s->r = r | VT_CONST | VT_SYM; - s->type.t |= VT_EXTERN; - } - patch_storage(s, ad, type); - } - return s; -} - -/* push a reference to global symbol v */ -ST_FUNC void vpush_global_sym(CType *type, int v) -{ - vpushsym(type, external_global_sym(v, type, 0)); -} - -/* save registers up to (vtop - n) stack entry */ -ST_FUNC void save_regs(int n) -{ - SValue *p, *p1; - for(p = vstack, p1 = vtop - n; p <= p1; p++) - save_reg(p->r); -} - -/* save r to the memory stack, and mark it as being free */ -ST_FUNC void save_reg(int r) -{ - save_reg_upstack(r, 0); -} - -/* save r to the memory stack, and mark it as being free, - if seen up to (vtop - n) stack entry */ -ST_FUNC void save_reg_upstack(int r, int n) -{ - int l, saved, size, align; - SValue *p, *p1, sv; - CType *type; - - if ((r &= VT_VALMASK) >= VT_CONST) - return; - if (nocode_wanted) - return; - - /* modify all stack values */ - saved = 0; - l = 0; - for(p = vstack, p1 = vtop - n; p <= p1; p++) { - if ((p->r & VT_VALMASK) == r || - ((p->type.t & VT_BTYPE) == VT_LLONG && (p->r2 & VT_VALMASK) == r)) { - /* must save value on stack if not already done */ - if (!saved) { - /* NOTE: must reload 'r' because r might be equal to r2 */ - r = p->r & VT_VALMASK; - /* store register in the stack */ - type = &p->type; - if ((p->r & VT_LVAL) || - (!is_float(type->t) && (type->t & VT_BTYPE) != VT_LLONG)) -#if PTR_SIZE == 8 - type = &char_pointer_type; -#else - type = &int_type; -#endif - size = type_size(type, &align); - loc = (loc - size) & -align; - sv.type.t = type->t; - sv.r = VT_LOCAL | VT_LVAL; - sv.c.i = loc; - store(r, &sv); -#if defined(TCC_TARGET_I386) || defined(TCC_TARGET_X86_64) - /* x86 specific: need to pop fp register ST0 if saved */ - if (r == TREG_ST0) { - o(0xd8dd); /* fstp %st(0) */ - } -#endif -#if PTR_SIZE == 4 - /* special long long case */ - if ((type->t & VT_BTYPE) == VT_LLONG) { - sv.c.i += 4; - store(p->r2, &sv); - } -#endif - l = loc; - saved = 1; - } - /* mark that stack entry as being saved on the stack */ - if (p->r & VT_LVAL) { - /* also clear the bounded flag because the - relocation address of the function was stored in - p->c.i */ - p->r = (p->r & ~(VT_VALMASK | VT_BOUNDED)) | VT_LLOCAL; - } else { - p->r = lvalue_type(p->type.t) | VT_LOCAL; - } - p->r2 = VT_CONST; - p->c.i = l; - } - } -} - -#ifdef TCC_TARGET_ARM -/* find a register of class 'rc2' with at most one reference on stack. - * If none, call get_reg(rc) */ -ST_FUNC int get_reg_ex(int rc, int rc2) -{ - int r; - SValue *p; - - for(r=0;rr & VT_VALMASK) == r || - (p->r2 & VT_VALMASK) == r) - n++; - } - if (n <= 1) - return r; - } - } - return get_reg(rc); -} -#endif - -/* find a free register of class 'rc'. If none, save one register */ -ST_FUNC int get_reg(int rc) -{ - int r; - SValue *p; - - /* find a free register */ - for(r=0;rr & VT_VALMASK) == r || - (p->r2 & VT_VALMASK) == r) - goto notfound; - } - return r; - } - notfound: ; - } - - /* no register left : free the first one on the stack (VERY - IMPORTANT to start from the bottom to ensure that we don't - spill registers used in gen_opi()) */ - for(p=vstack;p<=vtop;p++) { - /* look at second register (if long long) */ - r = p->r2 & VT_VALMASK; - if (r < VT_CONST && (reg_classes[r] & rc)) - goto save_found; - r = p->r & VT_VALMASK; - if (r < VT_CONST && (reg_classes[r] & rc)) { - save_found: - save_reg(r); - return r; - } - } - /* Should never comes here */ - return -1; -} - -/* move register 's' (of type 't') to 'r', and flush previous value of r to memory - if needed */ -static void move_reg(int r, int s, int t) -{ - SValue sv; - - if (r != s) { - save_reg(r); - sv.type.t = t; - sv.type.ref = NULL; - sv.r = s; - sv.c.i = 0; - load(r, &sv); - } -} - -/* get address of vtop (vtop MUST BE an lvalue) */ -ST_FUNC void gaddrof(void) -{ - vtop->r &= ~VT_LVAL; - /* tricky: if saved lvalue, then we can go back to lvalue */ - if ((vtop->r & VT_VALMASK) == VT_LLOCAL) - vtop->r = (vtop->r & ~(VT_VALMASK | VT_LVAL_TYPE)) | VT_LOCAL | VT_LVAL; - - -} - -#ifdef CONFIG_TCC_BCHECK -/* generate lvalue bound code */ -static void gbound(void) -{ - int lval_type; - CType type1; - - vtop->r &= ~VT_MUSTBOUND; - /* if lvalue, then use checking code before dereferencing */ - if (vtop->r & VT_LVAL) { - /* if not VT_BOUNDED value, then make one */ - if (!(vtop->r & VT_BOUNDED)) { - lval_type = vtop->r & (VT_LVAL_TYPE | VT_LVAL); - /* must save type because we must set it to int to get pointer */ - type1 = vtop->type; - vtop->type.t = VT_PTR; - gaddrof(); - vpushi(0); - gen_bounded_ptr_add(); - vtop->r |= lval_type; - vtop->type = type1; - } - /* then check for dereferencing */ - gen_bounded_ptr_deref(); - } -} -#endif - -static void incr_bf_adr(int o) -{ - vtop->type = char_pointer_type; - gaddrof(); - vpushi(o); - gen_op('+'); - vtop->type.t = (vtop->type.t & ~(VT_BTYPE|VT_DEFSIGN)) - | (VT_BYTE|VT_UNSIGNED); - vtop->r = (vtop->r & ~VT_LVAL_TYPE) - | (VT_LVAL_BYTE|VT_LVAL_UNSIGNED|VT_LVAL); -} - -/* single-byte load mode for packed or otherwise unaligned bitfields */ -static void load_packed_bf(CType *type, int bit_pos, int bit_size) -{ - int n, o, bits; - save_reg_upstack(vtop->r, 1); - vpush64(type->t & VT_BTYPE, 0); // B X - bits = 0, o = bit_pos >> 3, bit_pos &= 7; - do { - vswap(); // X B - incr_bf_adr(o); - vdup(); // X B B - n = 8 - bit_pos; - if (n > bit_size) - n = bit_size; - if (bit_pos) - vpushi(bit_pos), gen_op(TOK_SHR), bit_pos = 0; // X B Y - if (n < 8) - vpushi((1 << n) - 1), gen_op('&'); - gen_cast(type); - if (bits) - vpushi(bits), gen_op(TOK_SHL); - vrotb(3); // B Y X - gen_op('|'); // B X - bits += n, bit_size -= n, o = 1; - } while (bit_size); - vswap(), vpop(); - if (!(type->t & VT_UNSIGNED)) { - n = ((type->t & VT_BTYPE) == VT_LLONG ? 64 : 32) - bits; - vpushi(n), gen_op(TOK_SHL); - vpushi(n), gen_op(TOK_SAR); - } -} - -/* single-byte store mode for packed or otherwise unaligned bitfields */ -static void store_packed_bf(int bit_pos, int bit_size) -{ - int bits, n, o, m, c; - - c = (vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST; - vswap(); // X B - save_reg_upstack(vtop->r, 1); - bits = 0, o = bit_pos >> 3, bit_pos &= 7; - do { - incr_bf_adr(o); // X B - vswap(); //B X - c ? vdup() : gv_dup(); // B V X - vrott(3); // X B V - if (bits) - vpushi(bits), gen_op(TOK_SHR); - if (bit_pos) - vpushi(bit_pos), gen_op(TOK_SHL); - n = 8 - bit_pos; - if (n > bit_size) - n = bit_size; - if (n < 8) { - m = ((1 << n) - 1) << bit_pos; - vpushi(m), gen_op('&'); // X B V1 - vpushv(vtop-1); // X B V1 B - vpushi(m & 0x80 ? ~m & 0x7f : ~m); - gen_op('&'); // X B V1 B1 - gen_op('|'); // X B V2 - } - vdup(), vtop[-1] = vtop[-2]; // X B B V2 - vstore(), vpop(); // X B - bits += n, bit_size -= n, bit_pos = 0, o = 1; - } while (bit_size); - vpop(), vpop(); -} - -static int adjust_bf(SValue *sv, int bit_pos, int bit_size) -{ - int t; - if (0 == sv->type.ref) - return 0; - t = sv->type.ref->auxtype; - if (t != -1 && t != VT_STRUCT) { - sv->type.t = (sv->type.t & ~VT_BTYPE) | t; - sv->r = (sv->r & ~VT_LVAL_TYPE) | lvalue_type(sv->type.t); - } - return t; -} - -/* store vtop a register belonging to class 'rc'. lvalues are - converted to values. Cannot be used if cannot be converted to - register value (such as structures). */ -ST_FUNC int gv(int rc) -{ - int r, bit_pos, bit_size, size, align, rc2; - - /* NOTE: get_reg can modify vstack[] */ - if (vtop->type.t & VT_BITFIELD) { - CType type; - - bit_pos = BIT_POS(vtop->type.t); - bit_size = BIT_SIZE(vtop->type.t); - /* remove bit field info to avoid loops */ - vtop->type.t &= ~VT_STRUCT_MASK; - - type.ref = NULL; - type.t = vtop->type.t & VT_UNSIGNED; - if ((vtop->type.t & VT_BTYPE) == VT_BOOL) - type.t |= VT_UNSIGNED; - - r = adjust_bf(vtop, bit_pos, bit_size); - - if ((vtop->type.t & VT_BTYPE) == VT_LLONG) - type.t |= VT_LLONG; - else - type.t |= VT_INT; - - if (r == VT_STRUCT) { - load_packed_bf(&type, bit_pos, bit_size); - } else { - int bits = (type.t & VT_BTYPE) == VT_LLONG ? 64 : 32; - /* cast to int to propagate signedness in following ops */ - gen_cast(&type); - /* generate shifts */ - vpushi(bits - (bit_pos + bit_size)); - gen_op(TOK_SHL); - vpushi(bits - bit_size); - /* NOTE: transformed to SHR if unsigned */ - gen_op(TOK_SAR); - } - r = gv(rc); - } else { - if (is_float(vtop->type.t) && - (vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST) { - unsigned long offset; - /* CPUs usually cannot use float constants, so we store them - generically in data segment */ - size = type_size(&vtop->type, &align); - if (NODATA_WANTED) - size = 0, align = 1; - offset = section_add(data_section, size, align); - vpush_ref(&vtop->type, data_section, offset, size); - vswap(); - init_putv(&vtop->type, data_section, offset); - vtop->r |= VT_LVAL; - } -#ifdef CONFIG_TCC_BCHECK - if (vtop->r & VT_MUSTBOUND) - gbound(); -#endif - - r = vtop->r & VT_VALMASK; - rc2 = (rc & RC_FLOAT) ? RC_FLOAT : RC_INT; -#ifndef TCC_TARGET_ARM64 - if (rc == RC_IRET) - rc2 = RC_LRET; -#ifdef TCC_TARGET_X86_64 - else if (rc == RC_FRET) - rc2 = RC_QRET; -#endif -#endif - /* need to reload if: - - constant - - lvalue (need to dereference pointer) - - already a register, but not in the right class */ - if (r >= VT_CONST - || (vtop->r & VT_LVAL) - || !(reg_classes[r] & rc) -#if PTR_SIZE == 8 - || ((vtop->type.t & VT_BTYPE) == VT_QLONG && !(reg_classes[vtop->r2] & rc2)) - || ((vtop->type.t & VT_BTYPE) == VT_QFLOAT && !(reg_classes[vtop->r2] & rc2)) -#else - || ((vtop->type.t & VT_BTYPE) == VT_LLONG && !(reg_classes[vtop->r2] & rc2)) -#endif - ) - { - r = get_reg(rc); -#if PTR_SIZE == 8 - if (((vtop->type.t & VT_BTYPE) == VT_QLONG) || ((vtop->type.t & VT_BTYPE) == VT_QFLOAT)) { - int addr_type = VT_LLONG, load_size = 8, load_type = ((vtop->type.t & VT_BTYPE) == VT_QLONG) ? VT_LLONG : VT_DOUBLE; -#else - if ((vtop->type.t & VT_BTYPE) == VT_LLONG) { - int addr_type = VT_INT, load_size = 4, load_type = VT_INT; - unsigned long long ll; -#endif - int r2, original_type; - original_type = vtop->type.t; - /* two register type load : expand to two words - temporarily */ -#if PTR_SIZE == 4 - if ((vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST) { - /* load constant */ - ll = vtop->c.i; - vtop->c.i = ll; /* first word */ - load(r, vtop); - vtop->r = r; /* save register value */ - vpushi(ll >> 32); /* second word */ - } else -#endif - if (vtop->r & VT_LVAL) { - /* We do not want to modifier the long long - pointer here, so the safest (and less - efficient) is to save all the other registers - in the stack. XXX: totally inefficient. */ - #if 0 - save_regs(1); - #else - /* lvalue_save: save only if used further down the stack */ - save_reg_upstack(vtop->r, 1); - #endif - /* load from memory */ - vtop->type.t = load_type; - load(r, vtop); - vdup(); - vtop[-1].r = r; /* save register value */ - /* increment pointer to get second word */ - vtop->type.t = addr_type; - gaddrof(); - vpushi(load_size); - gen_op('+'); - vtop->r |= VT_LVAL; - vtop->type.t = load_type; - } else { - /* move registers */ - load(r, vtop); - vdup(); - vtop[-1].r = r; /* save register value */ - vtop->r = vtop[-1].r2; - } - /* Allocate second register. Here we rely on the fact that - get_reg() tries first to free r2 of an SValue. */ - r2 = get_reg(rc2); - load(r2, vtop); - vpop(); - /* write second register */ - vtop->r2 = r2; - vtop->type.t = original_type; - } else if ((vtop->r & VT_LVAL) && !is_float(vtop->type.t)) { - int t1, t; - /* lvalue of scalar type : need to use lvalue type - because of possible cast */ - t = vtop->type.t; - t1 = t; - /* compute memory access type */ - if (vtop->r & VT_LVAL_BYTE) - t = VT_BYTE; - else if (vtop->r & VT_LVAL_SHORT) - t = VT_SHORT; - if (vtop->r & VT_LVAL_UNSIGNED) - t |= VT_UNSIGNED; - vtop->type.t = t; - load(r, vtop); - /* restore wanted type */ - vtop->type.t = t1; - } else { - /* one register type load */ - load(r, vtop); - } - } - vtop->r = r; -#ifdef TCC_TARGET_C67 - /* uses register pairs for doubles */ - if ((vtop->type.t & VT_BTYPE) == VT_DOUBLE) - vtop->r2 = r+1; -#endif - } - return r; -} - -/* generate vtop[-1] and vtop[0] in resp. classes rc1 and rc2 */ -ST_FUNC void gv2(int rc1, int rc2) -{ - int v; - - /* generate more generic register first. But VT_JMP or VT_CMP - values must be generated first in all cases to avoid possible - reload errors */ - v = vtop[0].r & VT_VALMASK; - if (v != VT_CMP && (v & ~1) != VT_JMP && rc1 <= rc2) { - vswap(); - gv(rc1); - vswap(); - gv(rc2); - /* test if reload is needed for first register */ - if ((vtop[-1].r & VT_VALMASK) >= VT_CONST) { - vswap(); - gv(rc1); - vswap(); - } - } else { - gv(rc2); - vswap(); - gv(rc1); - vswap(); - /* test if reload is needed for first register */ - if ((vtop[0].r & VT_VALMASK) >= VT_CONST) { - gv(rc2); - } - } -} - -#ifndef TCC_TARGET_ARM64 -/* wrapper around RC_FRET to return a register by type */ -static int rc_fret(int t) -{ -#ifdef TCC_TARGET_X86_64 - if (t == VT_LDOUBLE) { - return RC_ST0; - } -#endif - return RC_FRET; -} -#endif - -/* wrapper around REG_FRET to return a register by type */ -static int reg_fret(int t) -{ -#ifdef TCC_TARGET_X86_64 - if (t == VT_LDOUBLE) { - return TREG_ST0; - } -#endif - return REG_FRET; -} - -#if PTR_SIZE == 4 -/* expand 64bit on stack in two ints */ -static void lexpand(void) -{ - int u, v; - u = vtop->type.t & (VT_DEFSIGN | VT_UNSIGNED); - v = vtop->r & (VT_VALMASK | VT_LVAL); - if (v == VT_CONST) { - vdup(); - vtop[0].c.i >>= 32; - } else if (v == (VT_LVAL|VT_CONST) || v == (VT_LVAL|VT_LOCAL)) { - vdup(); - vtop[0].c.i += 4; - } else { - gv(RC_INT); - vdup(); - vtop[0].r = vtop[-1].r2; - vtop[0].r2 = vtop[-1].r2 = VT_CONST; - } - vtop[0].type.t = vtop[-1].type.t = VT_INT | u; -} -#endif - -#ifdef TCC_TARGET_ARM -/* expand long long on stack */ -ST_FUNC void lexpand_nr(void) -{ - int u,v; - - u = vtop->type.t & (VT_DEFSIGN | VT_UNSIGNED); - vdup(); - vtop->r2 = VT_CONST; - vtop->type.t = VT_INT | u; - v=vtop[-1].r & (VT_VALMASK | VT_LVAL); - if (v == VT_CONST) { - vtop[-1].c.i = vtop->c.i; - vtop->c.i = vtop->c.i >> 32; - vtop->r = VT_CONST; - } else if (v == (VT_LVAL|VT_CONST) || v == (VT_LVAL|VT_LOCAL)) { - vtop->c.i += 4; - vtop->r = vtop[-1].r; - } else if (v > VT_CONST) { - vtop--; - lexpand(); - } else - vtop->r = vtop[-1].r2; - vtop[-1].r2 = VT_CONST; - vtop[-1].type.t = VT_INT | u; -} -#endif - -#if PTR_SIZE == 4 -/* build a long long from two ints */ -static void lbuild(int t) -{ - gv2(RC_INT, RC_INT); - vtop[-1].r2 = vtop[0].r; - vtop[-1].type.t = t; - vpop(); -} -#endif - -/* convert stack entry to register and duplicate its value in another - register */ -static void gv_dup(void) -{ - int rc, t, r, r1; - SValue sv; - - t = vtop->type.t; -#if PTR_SIZE == 4 - if ((t & VT_BTYPE) == VT_LLONG) { - if (t & VT_BITFIELD) { - gv(RC_INT); - t = vtop->type.t; - } - lexpand(); - gv_dup(); - vswap(); - vrotb(3); - gv_dup(); - vrotb(4); - /* stack: H L L1 H1 */ - lbuild(t); - vrotb(3); - vrotb(3); - vswap(); - lbuild(t); - vswap(); - } else -#endif - { - /* duplicate value */ - rc = RC_INT; - sv.type.t = VT_INT; - if (is_float(t)) { - rc = RC_FLOAT; -#ifdef TCC_TARGET_X86_64 - if ((t & VT_BTYPE) == VT_LDOUBLE) { - rc = RC_ST0; - } -#endif - sv.type.t = t; - } - r = gv(rc); - r1 = get_reg(rc); - sv.r = r; - sv.c.i = 0; - load(r1, &sv); /* move r to r1 */ - vdup(); - /* duplicates value */ - if (r != r1) - vtop->r = r1; - } -} - -/* Generate value test - * - * Generate a test for any value (jump, comparison and integers) */ -ST_FUNC int gvtst(int inv, int t) -{ - int v = vtop->r & VT_VALMASK; - if (v != VT_CMP && v != VT_JMP && v != VT_JMPI) { - vpushi(0); - gen_op(TOK_NE); - } - if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) { - /* constant jmp optimization */ - if ((vtop->c.i != 0) != inv) - t = gjmp(t); - vtop--; - return t; - } - return gtst(inv, t); -} - -#if PTR_SIZE == 4 -/* generate CPU independent (unsigned) long long operations */ -static void gen_opl(int op) -{ - int t, a, b, op1, c, i; - int func; - unsigned short reg_iret = REG_IRET; - unsigned short reg_lret = REG_LRET; - SValue tmp; - - switch(op) { - case '/': - case TOK_PDIV: - func = TOK___divdi3; - goto gen_func; - case TOK_UDIV: - func = TOK___udivdi3; - goto gen_func; - case '%': - func = TOK___moddi3; - goto gen_mod_func; - case TOK_UMOD: - func = TOK___umoddi3; - gen_mod_func: -#ifdef TCC_ARM_EABI - reg_iret = TREG_R2; - reg_lret = TREG_R3; -#endif - gen_func: - /* call generic long long function */ - vpush_global_sym(&func_old_type, func); - vrott(3); - gfunc_call(2); - vpushi(0); - vtop->r = reg_iret; - vtop->r2 = reg_lret; - break; - case '^': - case '&': - case '|': - case '*': - case '+': - case '-': - //pv("gen_opl A",0,2); - t = vtop->type.t; - vswap(); - lexpand(); - vrotb(3); - lexpand(); - /* stack: L1 H1 L2 H2 */ - tmp = vtop[0]; - vtop[0] = vtop[-3]; - vtop[-3] = tmp; - tmp = vtop[-2]; - vtop[-2] = vtop[-3]; - vtop[-3] = tmp; - vswap(); - /* stack: H1 H2 L1 L2 */ - //pv("gen_opl B",0,4); - if (op == '*') { - vpushv(vtop - 1); - vpushv(vtop - 1); - gen_op(TOK_UMULL); - lexpand(); - /* stack: H1 H2 L1 L2 ML MH */ - for(i=0;i<4;i++) - vrotb(6); - /* stack: ML MH H1 H2 L1 L2 */ - tmp = vtop[0]; - vtop[0] = vtop[-2]; - vtop[-2] = tmp; - /* stack: ML MH H1 L2 H2 L1 */ - gen_op('*'); - vrotb(3); - vrotb(3); - gen_op('*'); - /* stack: ML MH M1 M2 */ - gen_op('+'); - gen_op('+'); - } else if (op == '+' || op == '-') { - /* XXX: add non carry method too (for MIPS or alpha) */ - if (op == '+') - op1 = TOK_ADDC1; - else - op1 = TOK_SUBC1; - gen_op(op1); - /* stack: H1 H2 (L1 op L2) */ - vrotb(3); - vrotb(3); - gen_op(op1 + 1); /* TOK_xxxC2 */ - } else { - gen_op(op); - /* stack: H1 H2 (L1 op L2) */ - vrotb(3); - vrotb(3); - /* stack: (L1 op L2) H1 H2 */ - gen_op(op); - /* stack: (L1 op L2) (H1 op H2) */ - } - /* stack: L H */ - lbuild(t); - break; - case TOK_SAR: - case TOK_SHR: - case TOK_SHL: - if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) { - t = vtop[-1].type.t; - vswap(); - lexpand(); - vrotb(3); - /* stack: L H shift */ - c = (int)vtop->c.i; - /* constant: simpler */ - /* NOTE: all comments are for SHL. the other cases are - done by swapping words */ - vpop(); - if (op != TOK_SHL) - vswap(); - if (c >= 32) { - /* stack: L H */ - vpop(); - if (c > 32) { - vpushi(c - 32); - gen_op(op); - } - if (op != TOK_SAR) { - vpushi(0); - } else { - gv_dup(); - vpushi(31); - gen_op(TOK_SAR); - } - vswap(); - } else { - vswap(); - gv_dup(); - /* stack: H L L */ - vpushi(c); - gen_op(op); - vswap(); - vpushi(32 - c); - if (op == TOK_SHL) - gen_op(TOK_SHR); - else - gen_op(TOK_SHL); - vrotb(3); - /* stack: L L H */ - vpushi(c); - if (op == TOK_SHL) - gen_op(TOK_SHL); - else - gen_op(TOK_SHR); - gen_op('|'); - } - if (op != TOK_SHL) - vswap(); - lbuild(t); - } else { - /* XXX: should provide a faster fallback on x86 ? */ - switch(op) { - case TOK_SAR: - func = TOK___ashrdi3; - goto gen_func; - case TOK_SHR: - func = TOK___lshrdi3; - goto gen_func; - case TOK_SHL: - func = TOK___ashldi3; - goto gen_func; - } - } - break; - default: - /* compare operations */ - t = vtop->type.t; - vswap(); - lexpand(); - vrotb(3); - lexpand(); - /* stack: L1 H1 L2 H2 */ - tmp = vtop[-1]; - vtop[-1] = vtop[-2]; - vtop[-2] = tmp; - /* stack: L1 L2 H1 H2 */ - /* compare high */ - op1 = op; - /* when values are equal, we need to compare low words. since - the jump is inverted, we invert the test too. */ - if (op1 == TOK_LT) - op1 = TOK_LE; - else if (op1 == TOK_GT) - op1 = TOK_GE; - else if (op1 == TOK_ULT) - op1 = TOK_ULE; - else if (op1 == TOK_UGT) - op1 = TOK_UGE; - a = 0; - b = 0; - gen_op(op1); - if (op == TOK_NE) { - b = gvtst(0, 0); - } else { - a = gvtst(1, 0); - if (op != TOK_EQ) { - /* generate non equal test */ - vpushi(TOK_NE); - vtop->r = VT_CMP; - b = gvtst(0, 0); - } - } - /* compare low. Always unsigned */ - op1 = op; - if (op1 == TOK_LT) - op1 = TOK_ULT; - else if (op1 == TOK_LE) - op1 = TOK_ULE; - else if (op1 == TOK_GT) - op1 = TOK_UGT; - else if (op1 == TOK_GE) - op1 = TOK_UGE; - gen_op(op1); - a = gvtst(1, a); - gsym(b); - vseti(VT_JMPI, a); - break; - } -} -#endif - -static uint64_t gen_opic_sdiv(uint64_t a, uint64_t b) -{ - uint64_t x = (a >> 63 ? -a : a) / (b >> 63 ? -b : b); - return (a ^ b) >> 63 ? -x : x; -} - -static int gen_opic_lt(uint64_t a, uint64_t b) -{ - return (a ^ (uint64_t)1 << 63) < (b ^ (uint64_t)1 << 63); -} - -/* handle integer constant optimizations and various machine - independent opt */ -static void gen_opic(int op) -{ - SValue *v1 = vtop - 1; - SValue *v2 = vtop; - int t1 = v1->type.t & VT_BTYPE; - int t2 = v2->type.t & VT_BTYPE; - int c1 = (v1->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST; - int c2 = (v2->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST; - uint64_t l1 = c1 ? v1->c.i : 0; - uint64_t l2 = c2 ? v2->c.i : 0; - int shm = (t1 == VT_LLONG) ? 63 : 31; - - if (t1 != VT_LLONG && (PTR_SIZE != 8 || t1 != VT_PTR)) - l1 = ((uint32_t)l1 | - (v1->type.t & VT_UNSIGNED ? 0 : -(l1 & 0x80000000))); - if (t2 != VT_LLONG && (PTR_SIZE != 8 || t2 != VT_PTR)) - l2 = ((uint32_t)l2 | - (v2->type.t & VT_UNSIGNED ? 0 : -(l2 & 0x80000000))); - - if (c1 && c2) { - switch(op) { - case '+': l1 += l2; break; - case '-': l1 -= l2; break; - case '&': l1 &= l2; break; - case '^': l1 ^= l2; break; - case '|': l1 |= l2; break; - case '*': l1 *= l2; break; - - case TOK_PDIV: - case '/': - case '%': - case TOK_UDIV: - case TOK_UMOD: - /* if division by zero, generate explicit division */ - if (l2 == 0) { - if (const_wanted) - tcc_error("division by zero in constant"); - goto general_case; - } - switch(op) { - default: l1 = gen_opic_sdiv(l1, l2); break; - case '%': l1 = l1 - l2 * gen_opic_sdiv(l1, l2); break; - case TOK_UDIV: l1 = l1 / l2; break; - case TOK_UMOD: l1 = l1 % l2; break; - } - break; - case TOK_SHL: l1 <<= (l2 & shm); break; - case TOK_SHR: l1 >>= (l2 & shm); break; - case TOK_SAR: - l1 = (l1 >> 63) ? ~(~l1 >> (l2 & shm)) : l1 >> (l2 & shm); - break; - /* tests */ - case TOK_ULT: l1 = l1 < l2; break; - case TOK_UGE: l1 = l1 >= l2; break; - case TOK_EQ: l1 = l1 == l2; break; - case TOK_NE: l1 = l1 != l2; break; - case TOK_ULE: l1 = l1 <= l2; break; - case TOK_UGT: l1 = l1 > l2; break; - case TOK_LT: l1 = gen_opic_lt(l1, l2); break; - case TOK_GE: l1 = !gen_opic_lt(l1, l2); break; - case TOK_LE: l1 = !gen_opic_lt(l2, l1); break; - case TOK_GT: l1 = gen_opic_lt(l2, l1); break; - /* logical */ - case TOK_LAND: l1 = l1 && l2; break; - case TOK_LOR: l1 = l1 || l2; break; - default: - goto general_case; - } - if (t1 != VT_LLONG && (PTR_SIZE != 8 || t1 != VT_PTR)) - l1 = ((uint32_t)l1 | - (v1->type.t & VT_UNSIGNED ? 0 : -(l1 & 0x80000000))); - v1->c.i = l1; - vtop--; - } else { - /* if commutative ops, put c2 as constant */ - if (c1 && (op == '+' || op == '&' || op == '^' || - op == '|' || op == '*')) { - vswap(); - c2 = c1; //c = c1, c1 = c2, c2 = c; - l2 = l1; //l = l1, l1 = l2, l2 = l; - } - if (!const_wanted && - c1 && ((l1 == 0 && - (op == TOK_SHL || op == TOK_SHR || op == TOK_SAR)) || - (l1 == -1 && op == TOK_SAR))) { - /* treat (0 << x), (0 >> x) and (-1 >> x) as constant */ - vtop--; - } else if (!const_wanted && - c2 && ((l2 == 0 && (op == '&' || op == '*')) || - (op == '|' && - (l2 == -1 || (l2 == 0xFFFFFFFF && t2 != VT_LLONG))) || - (l2 == 1 && (op == '%' || op == TOK_UMOD)))) { - /* treat (x & 0), (x * 0), (x | -1) and (x % 1) as constant */ - if (l2 == 1) - vtop->c.i = 0; - vswap(); - vtop--; - } else if (c2 && (((op == '*' || op == '/' || op == TOK_UDIV || - op == TOK_PDIV) && - l2 == 1) || - ((op == '+' || op == '-' || op == '|' || op == '^' || - op == TOK_SHL || op == TOK_SHR || op == TOK_SAR) && - l2 == 0) || - (op == '&' && - (l2 == -1 || (l2 == 0xFFFFFFFF && t2 != VT_LLONG))))) { - /* filter out NOP operations like x*1, x-0, x&-1... */ - vtop--; - } else if (c2 && (op == '*' || op == TOK_PDIV || op == TOK_UDIV)) { - /* try to use shifts instead of muls or divs */ - if (l2 > 0 && (l2 & (l2 - 1)) == 0) { - int n = -1; - while (l2) { - l2 >>= 1; - n++; - } - vtop->c.i = n; - if (op == '*') - op = TOK_SHL; - else if (op == TOK_PDIV) - op = TOK_SAR; - else - op = TOK_SHR; - } - goto general_case; - } else if (c2 && (op == '+' || op == '-') && - (((vtop[-1].r & (VT_VALMASK | VT_LVAL | VT_SYM)) == (VT_CONST | VT_SYM)) - || (vtop[-1].r & (VT_VALMASK | VT_LVAL)) == VT_LOCAL)) { - /* symbol + constant case */ - if (op == '-') - l2 = -l2; - l2 += vtop[-1].c.i; - /* The backends can't always deal with addends to symbols - larger than +-1<<31. Don't construct such. */ - if ((int)l2 != l2) - goto general_case; - vtop--; - vtop->c.i = l2; - } else { - general_case: - /* call low level op generator */ - if (t1 == VT_LLONG || t2 == VT_LLONG || - (PTR_SIZE == 8 && (t1 == VT_PTR || t2 == VT_PTR))) - gen_opl(op); - else - gen_opi(op); - } - } -} - -/* generate a floating point operation with constant propagation */ -static void gen_opif(int op) -{ - int c1, c2; - SValue *v1, *v2; -#if defined _MSC_VER && defined _AMD64_ - /* avoid bad optimization with f1 -= f2 for f1:-0.0, f2:0.0 */ - volatile -#endif - long double f1, f2; - - v1 = vtop - 1; - v2 = vtop; - /* currently, we cannot do computations with forward symbols */ - c1 = (v1->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST; - c2 = (v2->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST; - if (c1 && c2) { - if (v1->type.t == VT_FLOAT) { - f1 = v1->c.f; - f2 = v2->c.f; - } else if (v1->type.t == VT_DOUBLE) { - f1 = v1->c.d; - f2 = v2->c.d; - } else { - f1 = v1->c.ld; - f2 = v2->c.ld; - } - - /* NOTE: we only do constant propagation if finite number (not - NaN or infinity) (ANSI spec) */ - if (!ieee_finite(f1) || !ieee_finite(f2)) - goto general_case; - - switch(op) { - case '+': f1 += f2; break; - case '-': f1 -= f2; break; - case '*': f1 *= f2; break; - case '/': - if (f2 == 0.0) { - if (const_wanted) - tcc_error("division by zero in constant"); - goto general_case; - } - f1 /= f2; - break; - /* XXX: also handles tests ? */ - default: - goto general_case; - } - /* XXX: overflow test ? */ - if (v1->type.t == VT_FLOAT) { - v1->c.f = f1; - } else if (v1->type.t == VT_DOUBLE) { - v1->c.d = f1; - } else { - v1->c.ld = f1; - } - vtop--; - } else { - general_case: - gen_opf(op); - } -} - -static int pointed_size(CType *type) -{ - int align; - return type_size(pointed_type(type), &align); -} - -static void vla_runtime_pointed_size(CType *type) -{ - int align; - vla_runtime_type_size(pointed_type(type), &align); -} - -static inline int is_null_pointer(SValue *p) -{ - if ((p->r & (VT_VALMASK | VT_LVAL | VT_SYM)) != VT_CONST) - return 0; - return ((p->type.t & VT_BTYPE) == VT_INT && (uint32_t)p->c.i == 0) || - ((p->type.t & VT_BTYPE) == VT_LLONG && p->c.i == 0) || - ((p->type.t & VT_BTYPE) == VT_PTR && - (PTR_SIZE == 4 ? (uint32_t)p->c.i == 0 : p->c.i == 0)); -} - -static inline int is_integer_btype(int bt) -{ - return (bt == VT_BYTE || bt == VT_SHORT || - bt == VT_INT || bt == VT_LLONG); -} - -/* check types for comparison or subtraction of pointers */ -static void check_comparison_pointer_types(SValue *p1, SValue *p2, int op) -{ - CType *type1, *type2, tmp_type1, tmp_type2; - int bt1, bt2; - - /* null pointers are accepted for all comparisons as gcc */ - if (is_null_pointer(p1) || is_null_pointer(p2)) - return; - type1 = &p1->type; - type2 = &p2->type; - bt1 = type1->t & VT_BTYPE; - bt2 = type2->t & VT_BTYPE; - /* accept comparison between pointer and integer with a warning */ - if ((is_integer_btype(bt1) || is_integer_btype(bt2)) && op != '-') { - if (op != TOK_LOR && op != TOK_LAND ) - tcc_warning("comparison between pointer and integer"); - return; - } - - /* both must be pointers or implicit function pointers */ - if (bt1 == VT_PTR) { - type1 = pointed_type(type1); - } else if (bt1 != VT_FUNC) - goto invalid_operands; - - if (bt2 == VT_PTR) { - type2 = pointed_type(type2); - } else if (bt2 != VT_FUNC) { - invalid_operands: - tcc_error("invalid operands to binary %s", get_tok_str(op, NULL)); - } - if ((type1->t & VT_BTYPE) == VT_VOID || - (type2->t & VT_BTYPE) == VT_VOID) - return; - tmp_type1 = *type1; - tmp_type2 = *type2; - tmp_type1.t &= ~(VT_DEFSIGN | VT_UNSIGNED | VT_CONSTANT | VT_VOLATILE); - tmp_type2.t &= ~(VT_DEFSIGN | VT_UNSIGNED | VT_CONSTANT | VT_VOLATILE); - if (!is_compatible_types(&tmp_type1, &tmp_type2)) { - /* gcc-like error if '-' is used */ - if (op == '-') - goto invalid_operands; - else - tcc_warning("comparison of distinct pointer types lacks a cast"); - } -} - -/* generic gen_op: handles types problems */ -ST_FUNC void gen_op(int op) -{ - int u, t1, t2, bt1, bt2, t; - CType type1; - -redo: - t1 = vtop[-1].type.t; - t2 = vtop[0].type.t; - bt1 = t1 & VT_BTYPE; - bt2 = t2 & VT_BTYPE; - - if (bt1 == VT_STRUCT || bt2 == VT_STRUCT) { - tcc_error("operation on a struct"); - } else if (bt1 == VT_FUNC || bt2 == VT_FUNC) { - if (bt2 == VT_FUNC) { - mk_pointer(&vtop->type); - gaddrof(); - } - if (bt1 == VT_FUNC) { - vswap(); - mk_pointer(&vtop->type); - gaddrof(); - vswap(); - } - goto redo; - } else if (bt1 == VT_PTR || bt2 == VT_PTR) { - /* at least one operand is a pointer */ - /* relational op: must be both pointers */ - if (op >= TOK_ULT && op <= TOK_LOR) { - check_comparison_pointer_types(vtop - 1, vtop, op); - /* pointers are handled are unsigned */ -#if PTR_SIZE == 8 - t = VT_LLONG | VT_UNSIGNED; -#else - t = VT_INT | VT_UNSIGNED; -#endif - goto std_op; - } - /* if both pointers, then it must be the '-' op */ - if (bt1 == VT_PTR && bt2 == VT_PTR) { - if (op != '-') - tcc_error("cannot use pointers here"); - check_comparison_pointer_types(vtop - 1, vtop, op); - /* XXX: check that types are compatible */ - if (vtop[-1].type.t & VT_VLA) { - vla_runtime_pointed_size(&vtop[-1].type); - } else { - vpushi(pointed_size(&vtop[-1].type)); - } - vrott(3); - gen_opic(op); - vtop->type.t = ptrdiff_type.t; - vswap(); - gen_op(TOK_PDIV); - } else { - /* exactly one pointer : must be '+' or '-'. */ - if (op != '-' && op != '+') - tcc_error("cannot use pointers here"); - /* Put pointer as first operand */ - if (bt2 == VT_PTR) { - vswap(); - t = t1, t1 = t2, t2 = t; - } -#if PTR_SIZE == 4 - if ((vtop[0].type.t & VT_BTYPE) == VT_LLONG) - /* XXX: truncate here because gen_opl can't handle ptr + long long */ - gen_cast_s(VT_INT); -#endif - type1 = vtop[-1].type; - type1.t &= ~VT_ARRAY; - if (vtop[-1].type.t & VT_VLA) - vla_runtime_pointed_size(&vtop[-1].type); - else { - u = pointed_size(&vtop[-1].type); - if (u < 0) - tcc_error("unknown array element size"); -#if PTR_SIZE == 8 - vpushll(u); -#else - /* XXX: cast to int ? (long long case) */ - vpushi(u); -#endif - } - gen_op('*'); -#if 0 -/* #ifdef CONFIG_TCC_BCHECK - The main reason to removing this code: - #include - int main () - { - int v[10]; - int i = 10; - int j = 9; - fprintf(stderr, "v+i-j = %p\n", v+i-j); - fprintf(stderr, "v+(i-j) = %p\n", v+(i-j)); - } - When this code is on. then the output looks like - v+i-j = 0xfffffffe - v+(i-j) = 0xbff84000 - */ - /* if evaluating constant expression, no code should be - generated, so no bound check */ - if (tcc_state->do_bounds_check && !const_wanted) { - /* if bounded pointers, we generate a special code to - test bounds */ - if (op == '-') { - vpushi(0); - vswap(); - gen_op('-'); - } - gen_bounded_ptr_add(); - } else -#endif - { - gen_opic(op); - } - /* put again type if gen_opic() swaped operands */ - vtop->type = type1; - } - } else if (is_float(bt1) || is_float(bt2)) { - /* compute bigger type and do implicit casts */ - if (bt1 == VT_LDOUBLE || bt2 == VT_LDOUBLE) { - t = VT_LDOUBLE; - } else if (bt1 == VT_DOUBLE || bt2 == VT_DOUBLE) { - t = VT_DOUBLE; - } else { - t = VT_FLOAT; - } - /* floats can only be used for a few operations */ - if (op != '+' && op != '-' && op != '*' && op != '/' && - (op < TOK_ULT || op > TOK_GT)) - tcc_error("invalid operands for binary operation"); - goto std_op; - } else if (op == TOK_SHR || op == TOK_SAR || op == TOK_SHL) { - t = bt1 == VT_LLONG ? VT_LLONG : VT_INT; - if ((t1 & (VT_BTYPE | VT_UNSIGNED | VT_BITFIELD)) == (t | VT_UNSIGNED)) - t |= VT_UNSIGNED; - t |= (VT_LONG & t1); - goto std_op; - } else if (bt1 == VT_LLONG || bt2 == VT_LLONG) { - /* cast to biggest op */ - t = VT_LLONG | VT_LONG; - if (bt1 == VT_LLONG) - t &= t1; - if (bt2 == VT_LLONG) - t &= t2; - /* convert to unsigned if it does not fit in a long long */ - if ((t1 & (VT_BTYPE | VT_UNSIGNED | VT_BITFIELD)) == (VT_LLONG | VT_UNSIGNED) || - (t2 & (VT_BTYPE | VT_UNSIGNED | VT_BITFIELD)) == (VT_LLONG | VT_UNSIGNED)) - t |= VT_UNSIGNED; - goto std_op; - } else { - /* integer operations */ - t = VT_INT | (VT_LONG & (t1 | t2)); - /* convert to unsigned if it does not fit in an integer */ - if ((t1 & (VT_BTYPE | VT_UNSIGNED | VT_BITFIELD)) == (VT_INT | VT_UNSIGNED) || - (t2 & (VT_BTYPE | VT_UNSIGNED | VT_BITFIELD)) == (VT_INT | VT_UNSIGNED)) - t |= VT_UNSIGNED; - std_op: - /* XXX: currently, some unsigned operations are explicit, so - we modify them here */ - if (t & VT_UNSIGNED) { - if (op == TOK_SAR) - op = TOK_SHR; - else if (op == '/') - op = TOK_UDIV; - else if (op == '%') - op = TOK_UMOD; - else if (op == TOK_LT) - op = TOK_ULT; - else if (op == TOK_GT) - op = TOK_UGT; - else if (op == TOK_LE) - op = TOK_ULE; - else if (op == TOK_GE) - op = TOK_UGE; - } - vswap(); - type1.t = t; - type1.ref = NULL; - gen_cast(&type1); - vswap(); - /* special case for shifts and long long: we keep the shift as - an integer */ - if (op == TOK_SHR || op == TOK_SAR || op == TOK_SHL) - type1.t = VT_INT; - gen_cast(&type1); - if (is_float(t)) - gen_opif(op); - else - gen_opic(op); - if (op >= TOK_ULT && op <= TOK_GT) { - /* relational op: the result is an int */ - vtop->type.t = VT_INT; - } else { - vtop->type.t = t; - } - } - // Make sure that we have converted to an rvalue: - if (vtop->r & VT_LVAL) - gv(is_float(vtop->type.t & VT_BTYPE) ? RC_FLOAT : RC_INT); -} - -#ifndef TCC_TARGET_ARM -/* generic itof for unsigned long long case */ -static void gen_cvt_itof1(int t) -{ -#ifdef TCC_TARGET_ARM64 - gen_cvt_itof(t); -#else - if ((vtop->type.t & (VT_BTYPE | VT_UNSIGNED)) == - (VT_LLONG | VT_UNSIGNED)) { - - if (t == VT_FLOAT) - vpush_global_sym(&func_old_type, TOK___floatundisf); -#if LDOUBLE_SIZE != 8 - else if (t == VT_LDOUBLE) - vpush_global_sym(&func_old_type, TOK___floatundixf); -#endif - else - vpush_global_sym(&func_old_type, TOK___floatundidf); - vrott(2); - gfunc_call(1); - vpushi(0); - vtop->r = reg_fret(t); - } else { - gen_cvt_itof(t); - } -#endif -} -#endif - -/* generic ftoi for unsigned long long case */ -static void gen_cvt_ftoi1(int t) -{ -#ifdef TCC_TARGET_ARM64 - gen_cvt_ftoi(t); -#else - int st; - - if (t == (VT_LLONG | VT_UNSIGNED)) { - /* not handled natively */ - st = vtop->type.t & VT_BTYPE; - if (st == VT_FLOAT) - vpush_global_sym(&func_old_type, TOK___fixunssfdi); -#if LDOUBLE_SIZE != 8 - else if (st == VT_LDOUBLE) - vpush_global_sym(&func_old_type, TOK___fixunsxfdi); -#endif - else - vpush_global_sym(&func_old_type, TOK___fixunsdfdi); - vrott(2); - gfunc_call(1); - vpushi(0); - vtop->r = REG_IRET; - vtop->r2 = REG_LRET; - } else { - gen_cvt_ftoi(t); - } -#endif -} - -/* force char or short cast */ -static void force_charshort_cast(int t) -{ - int bits, dbt; - - /* cannot cast static initializers */ - if (STATIC_DATA_WANTED) - return; - - dbt = t & VT_BTYPE; - /* XXX: add optimization if lvalue : just change type and offset */ - if (dbt == VT_BYTE) - bits = 8; - else - bits = 16; - if (t & VT_UNSIGNED) { - vpushi((1 << bits) - 1); - gen_op('&'); - } else { - if ((vtop->type.t & VT_BTYPE) == VT_LLONG) - bits = 64 - bits; - else - bits = 32 - bits; - vpushi(bits); - gen_op(TOK_SHL); - /* result must be signed or the SAR is converted to an SHL - This was not the case when "t" was a signed short - and the last value on the stack was an unsigned int */ - vtop->type.t &= ~VT_UNSIGNED; - vpushi(bits); - gen_op(TOK_SAR); - } -} - -/* cast 'vtop' to 'type'. Casting to bitfields is forbidden. */ -static void gen_cast_s(int t) -{ - CType type; - type.t = t; - type.ref = NULL; - gen_cast(&type); -} - -static void gen_cast(CType *type) -{ - int sbt, dbt, sf, df, c, p; - - /* special delayed cast for char/short */ - /* XXX: in some cases (multiple cascaded casts), it may still - be incorrect */ - if (vtop->r & VT_MUSTCAST) { - vtop->r &= ~VT_MUSTCAST; - force_charshort_cast(vtop->type.t); - } - - /* bitfields first get cast to ints */ - if (vtop->type.t & VT_BITFIELD) { - gv(RC_INT); - } - - dbt = type->t & (VT_BTYPE | VT_UNSIGNED); - sbt = vtop->type.t & (VT_BTYPE | VT_UNSIGNED); - - if (sbt != dbt) { - sf = is_float(sbt); - df = is_float(dbt); - c = (vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST; - p = (vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == (VT_CONST | VT_SYM); -#if !defined TCC_IS_NATIVE && !defined TCC_IS_NATIVE_387 - c &= dbt != VT_LDOUBLE; -#endif - if (c) { - /* constant case: we can do it now */ - /* XXX: in ISOC, cannot do it if error in convert */ - if (sbt == VT_FLOAT) - vtop->c.ld = vtop->c.f; - else if (sbt == VT_DOUBLE) - vtop->c.ld = vtop->c.d; - - if (df) { - if ((sbt & VT_BTYPE) == VT_LLONG) { - if ((sbt & VT_UNSIGNED) || !(vtop->c.i >> 63)) - vtop->c.ld = vtop->c.i; - else - vtop->c.ld = -(long double)-vtop->c.i; - } else if(!sf) { - if ((sbt & VT_UNSIGNED) || !(vtop->c.i >> 31)) - vtop->c.ld = (uint32_t)vtop->c.i; - else - vtop->c.ld = -(long double)-(uint32_t)vtop->c.i; - } - - if (dbt == VT_FLOAT) - vtop->c.f = (float)vtop->c.ld; - else if (dbt == VT_DOUBLE) - vtop->c.d = (double)vtop->c.ld; - } else if (sf && dbt == (VT_LLONG|VT_UNSIGNED)) { - vtop->c.i = vtop->c.ld; - } else if (sf && dbt == VT_BOOL) { - vtop->c.i = (vtop->c.ld != 0); - } else { - if(sf) - vtop->c.i = vtop->c.ld; - else if (sbt == (VT_LLONG|VT_UNSIGNED)) - ; - else if (sbt & VT_UNSIGNED) - vtop->c.i = (uint32_t)vtop->c.i; -#if PTR_SIZE == 8 - else if (sbt == VT_PTR) - ; -#endif - else if (sbt != VT_LLONG) - vtop->c.i = ((uint32_t)vtop->c.i | - -(vtop->c.i & 0x80000000)); - - if (dbt == (VT_LLONG|VT_UNSIGNED)) - ; - else if (dbt == VT_BOOL) - vtop->c.i = (vtop->c.i != 0); -#if PTR_SIZE == 8 - else if (dbt == VT_PTR) - ; -#endif - else if (dbt != VT_LLONG) { - uint32_t m = ((dbt & VT_BTYPE) == VT_BYTE ? 0xff : - (dbt & VT_BTYPE) == VT_SHORT ? 0xffff : - 0xffffffff); - vtop->c.i &= m; - if (!(dbt & VT_UNSIGNED)) - vtop->c.i |= -(vtop->c.i & ((m >> 1) + 1)); - } - } - } else if (p && dbt == VT_BOOL) { - vtop->r = VT_CONST; - vtop->c.i = 1; - } else { - /* non constant case: generate code */ - if (sf && df) { - /* convert from fp to fp */ - gen_cvt_ftof(dbt); - } else if (df) { - /* convert int to fp */ - gen_cvt_itof1(dbt); - } else if (sf) { - /* convert fp to int */ - if (dbt == VT_BOOL) { - vpushi(0); - gen_op(TOK_NE); - } else { - /* we handle char/short/etc... with generic code */ - if (dbt != (VT_INT | VT_UNSIGNED) && - dbt != (VT_LLONG | VT_UNSIGNED) && - dbt != VT_LLONG) - dbt = VT_INT; - gen_cvt_ftoi1(dbt); - if (dbt == VT_INT && (type->t & (VT_BTYPE | VT_UNSIGNED)) != dbt) { - /* additional cast for char/short... */ - vtop->type.t = dbt; - gen_cast(type); - } - } -#if PTR_SIZE == 4 - } else if ((dbt & VT_BTYPE) == VT_LLONG) { - if ((sbt & VT_BTYPE) != VT_LLONG) { - /* scalar to long long */ - /* machine independent conversion */ - gv(RC_INT); - /* generate high word */ - if (sbt == (VT_INT | VT_UNSIGNED)) { - vpushi(0); - gv(RC_INT); - } else { - if (sbt == VT_PTR) { - /* cast from pointer to int before we apply - shift operation, which pointers don't support*/ - gen_cast_s(VT_INT); - } - gv_dup(); - vpushi(31); - gen_op(TOK_SAR); - } - /* patch second register */ - vtop[-1].r2 = vtop->r; - vpop(); - } -#else - } else if ((dbt & VT_BTYPE) == VT_LLONG || - (dbt & VT_BTYPE) == VT_PTR || - (dbt & VT_BTYPE) == VT_FUNC) { - if ((sbt & VT_BTYPE) != VT_LLONG && - (sbt & VT_BTYPE) != VT_PTR && - (sbt & VT_BTYPE) != VT_FUNC) { - /* need to convert from 32bit to 64bit */ - gv(RC_INT); - if (sbt != (VT_INT | VT_UNSIGNED)) { -#if defined(TCC_TARGET_ARM64) - gen_cvt_sxtw(); -#elif defined(TCC_TARGET_X86_64) - int r = gv(RC_INT); - /* x86_64 specific: movslq */ - o(0x6348); - o(0xc0 + (REG_VALUE(r) << 3) + REG_VALUE(r)); -#else -#error -#endif - } - } -#endif - } else if (dbt == VT_BOOL) { - /* scalar to bool */ - vpushi(0); - gen_op(TOK_NE); - } else if ((dbt & VT_BTYPE) == VT_BYTE || - (dbt & VT_BTYPE) == VT_SHORT) { - if (sbt == VT_PTR) { - vtop->type.t = VT_INT; - tcc_warning("nonportable conversion from pointer to char/short"); - } - force_charshort_cast(dbt); -#if PTR_SIZE == 4 - } else if ((dbt & VT_BTYPE) == VT_INT) { - /* scalar to int */ - if ((sbt & VT_BTYPE) == VT_LLONG) { - /* from long long: just take low order word */ - lexpand(); - vpop(); - } - /* if lvalue and single word type, nothing to do because - the lvalue already contains the real type size (see - VT_LVAL_xxx constants) */ -#endif - } - } - } else if ((dbt & VT_BTYPE) == VT_PTR && !(vtop->r & VT_LVAL)) { - /* if we are casting between pointer types, - we must update the VT_LVAL_xxx size */ - vtop->r = (vtop->r & ~VT_LVAL_TYPE) - | (lvalue_type(type->ref->type.t) & VT_LVAL_TYPE); - } - vtop->type = *type; -} - -/* return type size as known at compile time. Put alignment at 'a' */ -ST_FUNC int type_size(CType *type, int *a) -{ - Sym *s; - int bt; - - bt = type->t & VT_BTYPE; - if (bt == VT_STRUCT) { - /* struct/union */ - s = type->ref; - *a = s->r; - return s->c; - } else if (bt == VT_PTR) { - if (type->t & VT_ARRAY) { - int ts; - - s = type->ref; - ts = type_size(&s->type, a); - - if (ts < 0 && s->c < 0) - ts = -ts; - - return ts * s->c; - } else { - *a = PTR_SIZE; - return PTR_SIZE; - } - } else if (IS_ENUM(type->t) && type->ref->c == -1) { - return -1; /* incomplete enum */ - } else if (bt == VT_LDOUBLE) { - *a = LDOUBLE_ALIGN; - return LDOUBLE_SIZE; - } else if (bt == VT_DOUBLE || bt == VT_LLONG) { -#ifdef TCC_TARGET_I386 -#ifdef TCC_TARGET_PE - *a = 8; -#else - *a = 4; -#endif -#elif defined(TCC_TARGET_ARM) -#ifdef TCC_ARM_EABI - *a = 8; -#else - *a = 4; -#endif -#else - *a = 8; -#endif - return 8; - } else if (bt == VT_INT || bt == VT_FLOAT) { - *a = 4; - return 4; - } else if (bt == VT_SHORT) { - *a = 2; - return 2; - } else if (bt == VT_QLONG || bt == VT_QFLOAT) { - *a = 8; - return 16; - } else { - /* char, void, function, _Bool */ - *a = 1; - return 1; - } -} - -/* push type size as known at runtime time on top of value stack. Put - alignment at 'a' */ -ST_FUNC void vla_runtime_type_size(CType *type, int *a) -{ - if (type->t & VT_VLA) { - type_size(&type->ref->type, a); - vset(&int_type, VT_LOCAL|VT_LVAL, type->ref->c); - } else { - vpushi(type_size(type, a)); - } -} - -static void vla_sp_restore(void) { - if (vlas_in_scope) { - gen_vla_sp_restore(vla_sp_loc); - } -} - -static void vla_sp_restore_root(void) { - if (vlas_in_scope) { - gen_vla_sp_restore(vla_sp_root_loc); - } -} - -/* return the pointed type of t */ -static inline CType *pointed_type(CType *type) -{ - return &type->ref->type; -} - -/* modify type so that its it is a pointer to type. */ -ST_FUNC void mk_pointer(CType *type) -{ - Sym *s; - s = sym_push(SYM_FIELD, type, 0, -1); - type->t = VT_PTR | (type->t & VT_STORAGE); - type->ref = s; -} - -/* compare function types. OLD functions match any new functions */ -static int is_compatible_func(CType *type1, CType *type2) -{ - Sym *s1, *s2; - - s1 = type1->ref; - s2 = type2->ref; - if (!is_compatible_types(&s1->type, &s2->type)) - return 0; - /* check func_call */ - if (s1->f.func_call != s2->f.func_call) - return 0; - /* XXX: not complete */ - if (s1->f.func_type == FUNC_OLD || s2->f.func_type == FUNC_OLD) - return 1; - if (s1->f.func_type != s2->f.func_type) - return 0; - while (s1 != NULL) { - if (s2 == NULL) - return 0; - if (!is_compatible_unqualified_types(&s1->type, &s2->type)) - return 0; - s1 = s1->next; - s2 = s2->next; - } - if (s2) - return 0; - return 1; -} - -/* return true if type1 and type2 are the same. If unqualified is - true, qualifiers on the types are ignored. - - - enums are not checked as gcc __builtin_types_compatible_p () - */ -static int compare_types(CType *type1, CType *type2, int unqualified) -{ - int bt1, t1, t2; - - t1 = type1->t & VT_TYPE; - t2 = type2->t & VT_TYPE; - if (unqualified) { - /* strip qualifiers before comparing */ - t1 &= ~(VT_CONSTANT | VT_VOLATILE); - t2 &= ~(VT_CONSTANT | VT_VOLATILE); - } - - /* Default Vs explicit signedness only matters for char */ - if ((t1 & VT_BTYPE) != VT_BYTE) { - t1 &= ~VT_DEFSIGN; - t2 &= ~VT_DEFSIGN; - } - /* XXX: bitfields ? */ - if (t1 != t2) - return 0; - /* test more complicated cases */ - bt1 = t1 & VT_BTYPE; - if (bt1 == VT_PTR) { - type1 = pointed_type(type1); - type2 = pointed_type(type2); - return is_compatible_types(type1, type2); - } else if (bt1 == VT_STRUCT) { - return (type1->ref == type2->ref); - } else if (bt1 == VT_FUNC) { - return is_compatible_func(type1, type2); - } else { - return 1; - } -} - -/* return true if type1 and type2 are exactly the same (including - qualifiers). -*/ -static int is_compatible_types(CType *type1, CType *type2) -{ - return compare_types(type1,type2,0); -} - -/* return true if type1 and type2 are the same (ignoring qualifiers). -*/ -static int is_compatible_unqualified_types(CType *type1, CType *type2) -{ - return compare_types(type1,type2,1); -} - -/* print a type. If 'varstr' is not NULL, then the variable is also - printed in the type */ -/* XXX: union */ -/* XXX: add array and function pointers */ -static void type_to_str(char *buf, int buf_size, - CType *type, const char *varstr) -{ - int bt, v, t; - Sym *s, *sa; - char buf1[256]; - const char *tstr; - - t = type->t; - bt = t & VT_BTYPE; - buf[0] = '\0'; - - if (t & VT_EXTERN) - pstrcat(buf, buf_size, "extern "); - if (t & VT_STATIC) - pstrcat(buf, buf_size, "static "); - if (t & VT_TYPEDEF) - pstrcat(buf, buf_size, "typedef "); - if (t & VT_INLINE) - pstrcat(buf, buf_size, "inline "); - if (t & VT_VOLATILE) - pstrcat(buf, buf_size, "volatile "); - if (t & VT_CONSTANT) - pstrcat(buf, buf_size, "const "); - - if (((t & VT_DEFSIGN) && bt == VT_BYTE) - || ((t & VT_UNSIGNED) - && (bt == VT_SHORT || bt == VT_INT || bt == VT_LLONG) - && !IS_ENUM(t) - )) - pstrcat(buf, buf_size, (t & VT_UNSIGNED) ? "unsigned " : "signed "); - - buf_size -= strlen(buf); - buf += strlen(buf); - - switch(bt) { - case VT_VOID: - tstr = "void"; - goto add_tstr; - case VT_BOOL: - tstr = "_Bool"; - goto add_tstr; - case VT_BYTE: - tstr = "char"; - goto add_tstr; - case VT_SHORT: - tstr = "short"; - goto add_tstr; - case VT_INT: - tstr = "int"; - goto maybe_long; - case VT_LLONG: - tstr = "long long"; - maybe_long: - if (t & VT_LONG) - tstr = "long"; - if (!IS_ENUM(t)) - goto add_tstr; - tstr = "enum "; - goto tstruct; - case VT_FLOAT: - tstr = "float"; - goto add_tstr; - case VT_DOUBLE: - tstr = "double"; - goto add_tstr; - case VT_LDOUBLE: - tstr = "long double"; - add_tstr: - pstrcat(buf, buf_size, tstr); - break; - case VT_STRUCT: - tstr = "struct "; - if (IS_UNION(t)) - tstr = "union "; - tstruct: - pstrcat(buf, buf_size, tstr); - v = type->ref->v & ~SYM_STRUCT; - if (v >= SYM_FIRST_ANOM) - pstrcat(buf, buf_size, ""); - else - pstrcat(buf, buf_size, get_tok_str(v, NULL)); - break; - case VT_FUNC: - s = type->ref; - type_to_str(buf, buf_size, &s->type, varstr); - pstrcat(buf, buf_size, "("); - sa = s->next; - while (sa != NULL) { - type_to_str(buf1, sizeof(buf1), &sa->type, NULL); - pstrcat(buf, buf_size, buf1); - sa = sa->next; - if (sa) - pstrcat(buf, buf_size, ", "); - } - pstrcat(buf, buf_size, ")"); - goto no_var; - case VT_PTR: - s = type->ref; - if (t & VT_ARRAY) { - snprintf(buf1, sizeof(buf1), "%s[%d]", varstr ? varstr : "", s->c); - type_to_str(buf, buf_size, &s->type, buf1); - goto no_var; - } - pstrcpy(buf1, sizeof(buf1), "*"); - if (t & VT_CONSTANT) - pstrcat(buf1, buf_size, "const "); - if (t & VT_VOLATILE) - pstrcat(buf1, buf_size, "volatile "); - if (varstr) - pstrcat(buf1, sizeof(buf1), varstr); - type_to_str(buf, buf_size, &s->type, buf1); - goto no_var; - } - if (varstr) { - pstrcat(buf, buf_size, " "); - pstrcat(buf, buf_size, varstr); - } - no_var: ; -} - -/* verify type compatibility to store vtop in 'dt' type, and generate - casts if needed. */ -static void gen_assign_cast(CType *dt) -{ - CType *st, *type1, *type2; - char buf1[256], buf2[256]; - int dbt, sbt; - - st = &vtop->type; /* source type */ - dbt = dt->t & VT_BTYPE; - sbt = st->t & VT_BTYPE; - if (sbt == VT_VOID || dbt == VT_VOID) { - if (sbt == VT_VOID && dbt == VT_VOID) - ; /* - It is Ok if both are void - A test program: - void func1() {} - void func2() { - return func1(); - } - gcc accepts this program - */ - else - tcc_error("cannot cast from/to void"); - } - if (dt->t & VT_CONSTANT) - tcc_warning("assignment of read-only location"); - switch(dbt) { - case VT_PTR: - /* special cases for pointers */ - /* '0' can also be a pointer */ - if (is_null_pointer(vtop)) - goto type_ok; - /* accept implicit pointer to integer cast with warning */ - if (is_integer_btype(sbt)) { - tcc_warning("assignment makes pointer from integer without a cast"); - goto type_ok; - } - type1 = pointed_type(dt); - /* a function is implicitly a function pointer */ - if (sbt == VT_FUNC) { - if ((type1->t & VT_BTYPE) != VT_VOID && - !is_compatible_types(pointed_type(dt), st)) - tcc_warning("assignment from incompatible pointer type"); - goto type_ok; - } - if (sbt != VT_PTR) - goto error; - type2 = pointed_type(st); - if ((type1->t & VT_BTYPE) == VT_VOID || - (type2->t & VT_BTYPE) == VT_VOID) { - /* void * can match anything */ - } else { - //printf("types %08x %08x\n", type1->t, type2->t); - /* exact type match, except for qualifiers */ - if (!is_compatible_unqualified_types(type1, type2)) { - /* Like GCC don't warn by default for merely changes - in pointer target signedness. Do warn for different - base types, though, in particular for unsigned enums - and signed int targets. */ - if ((type1->t & (VT_BTYPE|VT_LONG)) != (type2->t & (VT_BTYPE|VT_LONG)) - || IS_ENUM(type1->t) || IS_ENUM(type2->t) - ) - tcc_warning("assignment from incompatible pointer type"); - } - } - /* check const and volatile */ - if ((!(type1->t & VT_CONSTANT) && (type2->t & VT_CONSTANT)) || - (!(type1->t & VT_VOLATILE) && (type2->t & VT_VOLATILE))) - tcc_warning("assignment discards qualifiers from pointer target type"); - break; - case VT_BYTE: - case VT_SHORT: - case VT_INT: - case VT_LLONG: - if (sbt == VT_PTR || sbt == VT_FUNC) { - tcc_warning("assignment makes integer from pointer without a cast"); - } else if (sbt == VT_STRUCT) { - goto case_VT_STRUCT; - } - /* XXX: more tests */ - break; - case VT_STRUCT: - case_VT_STRUCT: - if (!is_compatible_unqualified_types(dt, st)) { - error: - type_to_str(buf1, sizeof(buf1), st, NULL); - type_to_str(buf2, sizeof(buf2), dt, NULL); - tcc_error("cannot cast '%s' to '%s'", buf1, buf2); - } - break; - } - type_ok: - gen_cast(dt); -} - -/* store vtop in lvalue pushed on stack */ -ST_FUNC void vstore(void) -{ - int sbt, dbt, ft, r, t, size, align, bit_size, bit_pos, rc, delayed_cast; - - ft = vtop[-1].type.t; - sbt = vtop->type.t & VT_BTYPE; - dbt = ft & VT_BTYPE; - if ((((sbt == VT_INT || sbt == VT_SHORT) && dbt == VT_BYTE) || - (sbt == VT_INT && dbt == VT_SHORT)) - && !(vtop->type.t & VT_BITFIELD)) { - /* optimize char/short casts */ - delayed_cast = VT_MUSTCAST; - vtop->type.t = ft & VT_TYPE; - /* XXX: factorize */ - if (ft & VT_CONSTANT) - tcc_warning("assignment of read-only location"); - } else { - delayed_cast = 0; - if (!(ft & VT_BITFIELD)) - gen_assign_cast(&vtop[-1].type); - } - - if (sbt == VT_STRUCT) { - /* if structure, only generate pointer */ - /* structure assignment : generate memcpy */ - /* XXX: optimize if small size */ - size = type_size(&vtop->type, &align); - - /* destination */ - vswap(); - vtop->type.t = VT_PTR; - gaddrof(); - - /* address of memcpy() */ -#ifdef TCC_ARM_EABI - if(!(align & 7)) - vpush_global_sym(&func_old_type, TOK_memcpy8); - else if(!(align & 3)) - vpush_global_sym(&func_old_type, TOK_memcpy4); - else -#endif - /* Use memmove, rather than memcpy, as dest and src may be same: */ - vpush_global_sym(&func_old_type, TOK_memmove); - - vswap(); - /* source */ - vpushv(vtop - 2); - vtop->type.t = VT_PTR; - gaddrof(); - /* type size */ - vpushi(size); - gfunc_call(3); - - /* leave source on stack */ - } else if (ft & VT_BITFIELD) { - /* bitfield store handling */ - - /* save lvalue as expression result (example: s.b = s.a = n;) */ - vdup(), vtop[-1] = vtop[-2]; - - bit_pos = BIT_POS(ft); - bit_size = BIT_SIZE(ft); - /* remove bit field info to avoid loops */ - vtop[-1].type.t = ft & ~VT_STRUCT_MASK; - - if ((ft & VT_BTYPE) == VT_BOOL) { - gen_cast(&vtop[-1].type); - vtop[-1].type.t = (vtop[-1].type.t & ~VT_BTYPE) | (VT_BYTE | VT_UNSIGNED); - } - - r = adjust_bf(vtop - 1, bit_pos, bit_size); - if (r == VT_STRUCT) { - gen_cast_s((ft & VT_BTYPE) == VT_LLONG ? VT_LLONG : VT_INT); - store_packed_bf(bit_pos, bit_size); - } else { - unsigned long long mask = (1ULL << bit_size) - 1; - if ((ft & VT_BTYPE) != VT_BOOL) { - /* mask source */ - if ((vtop[-1].type.t & VT_BTYPE) == VT_LLONG) - vpushll(mask); - else - vpushi((unsigned)mask); - gen_op('&'); - } - /* shift source */ - vpushi(bit_pos); - gen_op(TOK_SHL); - vswap(); - /* duplicate destination */ - vdup(); - vrott(3); - /* load destination, mask and or with source */ - if ((vtop->type.t & VT_BTYPE) == VT_LLONG) - vpushll(~(mask << bit_pos)); - else - vpushi(~((unsigned)mask << bit_pos)); - gen_op('&'); - gen_op('|'); - /* store result */ - vstore(); - /* ... and discard */ - vpop(); - } - } else if (dbt == VT_VOID) { - --vtop; - } else { -#ifdef CONFIG_TCC_BCHECK - /* bound check case */ - if (vtop[-1].r & VT_MUSTBOUND) { - vswap(); - gbound(); - vswap(); - } -#endif - rc = RC_INT; - if (is_float(ft)) { - rc = RC_FLOAT; -#ifdef TCC_TARGET_X86_64 - if ((ft & VT_BTYPE) == VT_LDOUBLE) { - rc = RC_ST0; - } else if ((ft & VT_BTYPE) == VT_QFLOAT) { - rc = RC_FRET; - } -#endif - } - r = gv(rc); /* generate value */ - /* if lvalue was saved on stack, must read it */ - if ((vtop[-1].r & VT_VALMASK) == VT_LLOCAL) { - SValue sv; - t = get_reg(RC_INT); -#if PTR_SIZE == 8 - sv.type.t = VT_PTR; -#else - sv.type.t = VT_INT; -#endif - sv.r = VT_LOCAL | VT_LVAL; - sv.c.i = vtop[-1].c.i; - load(t, &sv); - vtop[-1].r = t | VT_LVAL; - } - /* two word case handling : store second register at word + 4 (or +8 for x86-64) */ -#if PTR_SIZE == 8 - if (((ft & VT_BTYPE) == VT_QLONG) || ((ft & VT_BTYPE) == VT_QFLOAT)) { - int addr_type = VT_LLONG, load_size = 8, load_type = ((vtop->type.t & VT_BTYPE) == VT_QLONG) ? VT_LLONG : VT_DOUBLE; -#else - if ((ft & VT_BTYPE) == VT_LLONG) { - int addr_type = VT_INT, load_size = 4, load_type = VT_INT; -#endif - vtop[-1].type.t = load_type; - store(r, vtop - 1); - vswap(); - /* convert to int to increment easily */ - vtop->type.t = addr_type; - gaddrof(); - vpushi(load_size); - gen_op('+'); - vtop->r |= VT_LVAL; - vswap(); - vtop[-1].type.t = load_type; - /* XXX: it works because r2 is spilled last ! */ - store(vtop->r2, vtop - 1); - } else { - store(r, vtop - 1); - } - - vswap(); - vtop--; /* NOT vpop() because on x86 it would flush the fp stack */ - vtop->r |= delayed_cast; - } -} - -/* post defines POST/PRE add. c is the token ++ or -- */ -ST_FUNC void inc(int post, int c) -{ - test_lvalue(); - vdup(); /* save lvalue */ - if (post) { - gv_dup(); /* duplicate value */ - vrotb(3); - vrotb(3); - } - /* add constant */ - vpushi(c - TOK_MID); - gen_op('+'); - vstore(); /* store value */ - if (post) - vpop(); /* if post op, return saved value */ -} - -ST_FUNC void parse_mult_str (CString *astr, const char *msg) -{ - /* read the string */ - if (tok != TOK_STR) - expect(msg); - cstr_new(astr); - while (tok == TOK_STR) { - /* XXX: add \0 handling too ? */ - cstr_cat(astr, tokc.str.data, -1); - next(); - } - cstr_ccat(astr, '\0'); -} - -/* If I is >= 1 and a power of two, returns log2(i)+1. - If I is 0 returns 0. */ -static int exact_log2p1(int i) -{ - int ret; - if (!i) - return 0; - for (ret = 1; i >= 1 << 8; ret += 8) - i >>= 8; - if (i >= 1 << 4) - ret += 4, i >>= 4; - if (i >= 1 << 2) - ret += 2, i >>= 2; - if (i >= 1 << 1) - ret++; - return ret; -} - -/* Parse __attribute__((...)) GNUC extension. */ -static void parse_attribute(AttributeDef *ad) -{ - int t, n; - CString astr; - -redo: - if (tok != TOK_ATTRIBUTE1 && tok != TOK_ATTRIBUTE2) - return; - next(); - skip('('); - skip('('); - while (tok != ')') { - if (tok < TOK_IDENT) - expect("attribute name"); - t = tok; - next(); - switch(t) { - case TOK_SECTION1: - case TOK_SECTION2: - skip('('); - parse_mult_str(&astr, "section name"); - ad->section = find_section(tcc_state, (char *)astr.data); - skip(')'); - cstr_free(&astr); - break; - case TOK_ALIAS1: - case TOK_ALIAS2: - skip('('); - parse_mult_str(&astr, "alias(\"target\")"); - ad->alias_target = /* save string as token, for later */ - tok_alloc((char*)astr.data, astr.size-1)->tok; - skip(')'); - cstr_free(&astr); - break; - case TOK_VISIBILITY1: - case TOK_VISIBILITY2: - skip('('); - parse_mult_str(&astr, - "visibility(\"default|hidden|internal|protected\")"); - if (!strcmp (astr.data, "default")) - ad->a.visibility = STV_DEFAULT; - else if (!strcmp (astr.data, "hidden")) - ad->a.visibility = STV_HIDDEN; - else if (!strcmp (astr.data, "internal")) - ad->a.visibility = STV_INTERNAL; - else if (!strcmp (astr.data, "protected")) - ad->a.visibility = STV_PROTECTED; - else - expect("visibility(\"default|hidden|internal|protected\")"); - skip(')'); - cstr_free(&astr); - break; - case TOK_ALIGNED1: - case TOK_ALIGNED2: - if (tok == '(') { - next(); - n = expr_const(); - if (n <= 0 || (n & (n - 1)) != 0) - tcc_error("alignment must be a positive power of two"); - skip(')'); - } else { - n = MAX_ALIGN; - } - ad->a.aligned = exact_log2p1(n); - if (n != 1 << (ad->a.aligned - 1)) - tcc_error("alignment of %d is larger than implemented", n); - break; - case TOK_PACKED1: - case TOK_PACKED2: - ad->a.packed = 1; - break; - case TOK_WEAK1: - case TOK_WEAK2: - ad->a.weak = 1; - break; - case TOK_UNUSED1: - case TOK_UNUSED2: - /* currently, no need to handle it because tcc does not - track unused objects */ - break; - case TOK_NORETURN1: - case TOK_NORETURN2: - /* currently, no need to handle it because tcc does not - track unused objects */ - break; - case TOK_CDECL1: - case TOK_CDECL2: - case TOK_CDECL3: - ad->f.func_call = FUNC_CDECL; - break; - case TOK_STDCALL1: - case TOK_STDCALL2: - case TOK_STDCALL3: - ad->f.func_call = FUNC_STDCALL; - break; -#ifdef TCC_TARGET_I386 - case TOK_REGPARM1: - case TOK_REGPARM2: - skip('('); - n = expr_const(); - if (n > 3) - n = 3; - else if (n < 0) - n = 0; - if (n > 0) - ad->f.func_call = FUNC_FASTCALL1 + n - 1; - skip(')'); - break; - case TOK_FASTCALL1: - case TOK_FASTCALL2: - case TOK_FASTCALL3: - ad->f.func_call = FUNC_FASTCALLW; - break; -#endif - case TOK_MODE: - skip('('); - switch(tok) { - case TOK_MODE_DI: - ad->attr_mode = VT_LLONG + 1; - break; - case TOK_MODE_QI: - ad->attr_mode = VT_BYTE + 1; - break; - case TOK_MODE_HI: - ad->attr_mode = VT_SHORT + 1; - break; - case TOK_MODE_SI: - case TOK_MODE_word: - ad->attr_mode = VT_INT + 1; - break; - default: - tcc_warning("__mode__(%s) not supported\n", get_tok_str(tok, NULL)); - break; - } - next(); - skip(')'); - break; - case TOK_DLLEXPORT: - ad->a.dllexport = 1; - break; - case TOK_DLLIMPORT: - ad->a.dllimport = 1; - break; - default: - if (tcc_state->warn_unsupported) - tcc_warning("'%s' attribute ignored", get_tok_str(t, NULL)); - /* skip parameters */ - if (tok == '(') { - int parenthesis = 0; - do { - if (tok == '(') - parenthesis++; - else if (tok == ')') - parenthesis--; - next(); - } while (parenthesis && tok != -1); - } - break; - } - if (tok != ',') - break; - next(); - } - skip(')'); - skip(')'); - goto redo; -} - -static Sym * find_field (CType *type, int v) -{ - Sym *s = type->ref; - v |= SYM_FIELD; - while ((s = s->next) != NULL) { - if ((s->v & SYM_FIELD) && - (s->type.t & VT_BTYPE) == VT_STRUCT && - (s->v & ~SYM_FIELD) >= SYM_FIRST_ANOM) { - Sym *ret = find_field (&s->type, v); - if (ret) - return ret; - } - if (s->v == v) - break; - } - return s; -} - -static void struct_add_offset (Sym *s, int offset) -{ - while ((s = s->next) != NULL) { - if ((s->v & SYM_FIELD) && - (s->type.t & VT_BTYPE) == VT_STRUCT && - (s->v & ~SYM_FIELD) >= SYM_FIRST_ANOM) { - struct_add_offset(s->type.ref, offset); - } else - s->c += offset; - } -} - -static void struct_layout(CType *type, AttributeDef *ad) -{ - int size, align, maxalign, offset, c, bit_pos, bit_size; - int packed, a, bt, prevbt, prev_bit_size; - int pcc = !tcc_state->ms_bitfields; - int pragma_pack = *tcc_state->pack_stack_ptr; - Sym *f; - - maxalign = 1; - offset = 0; - c = 0; - bit_pos = 0; - prevbt = VT_STRUCT; /* make it never match */ - prev_bit_size = 0; - -//#define BF_DEBUG - - for (f = type->ref->next; f; f = f->next) { - if (f->type.t & VT_BITFIELD) - bit_size = BIT_SIZE(f->type.t); - else - bit_size = -1; - size = type_size(&f->type, &align); - a = f->a.aligned ? 1 << (f->a.aligned - 1) : 0; - packed = 0; - - if (pcc && bit_size == 0) { - /* in pcc mode, packing does not affect zero-width bitfields */ - - } else { - /* in pcc mode, attribute packed overrides if set. */ - if (pcc && (f->a.packed || ad->a.packed)) - align = packed = 1; - - /* pragma pack overrides align if lesser and packs bitfields always */ - if (pragma_pack) { - packed = 1; - if (pragma_pack < align) - align = pragma_pack; - /* in pcc mode pragma pack also overrides individual align */ - if (pcc && pragma_pack < a) - a = 0; - } - } - /* some individual align was specified */ - if (a) - align = a; - - if (type->ref->type.t == VT_UNION) { - if (pcc && bit_size >= 0) - size = (bit_size + 7) >> 3; - offset = 0; - if (size > c) - c = size; - - } else if (bit_size < 0) { - if (pcc) - c += (bit_pos + 7) >> 3; - c = (c + align - 1) & -align; - offset = c; - if (size > 0) - c += size; - bit_pos = 0; - prevbt = VT_STRUCT; - prev_bit_size = 0; - - } else { - /* A bit-field. Layout is more complicated. There are two - options: PCC (GCC) compatible and MS compatible */ - if (pcc) { - /* In PCC layout a bit-field is placed adjacent to the - preceding bit-fields, except if: - - it has zero-width - - an individual alignment was given - - it would overflow its base type container and - there is no packing */ - if (bit_size == 0) { - new_field: - c = (c + ((bit_pos + 7) >> 3) + align - 1) & -align; - bit_pos = 0; - } else if (f->a.aligned) { - goto new_field; - } else if (!packed) { - int a8 = align * 8; - int ofs = ((c * 8 + bit_pos) % a8 + bit_size + a8 - 1) / a8; - if (ofs > size / align) - goto new_field; - } - - /* in pcc mode, long long bitfields have type int if they fit */ - if (size == 8 && bit_size <= 32) - f->type.t = (f->type.t & ~VT_BTYPE) | VT_INT, size = 4; - - while (bit_pos >= align * 8) - c += align, bit_pos -= align * 8; - offset = c; - - /* In PCC layout named bit-fields influence the alignment - of the containing struct using the base types alignment, - except for packed fields (which here have correct align). */ - if (f->v & SYM_FIRST_ANOM - // && bit_size // ??? gcc on ARM/rpi does that - ) - align = 1; - - } else { - bt = f->type.t & VT_BTYPE; - if ((bit_pos + bit_size > size * 8) - || (bit_size > 0) == (bt != prevbt) - ) { - c = (c + align - 1) & -align; - offset = c; - bit_pos = 0; - /* In MS bitfield mode a bit-field run always uses - at least as many bits as the underlying type. - To start a new run it's also required that this - or the last bit-field had non-zero width. */ - if (bit_size || prev_bit_size) - c += size; - } - /* In MS layout the records alignment is normally - influenced by the field, except for a zero-width - field at the start of a run (but by further zero-width - fields it is again). */ - if (bit_size == 0 && prevbt != bt) - align = 1; - prevbt = bt; - prev_bit_size = bit_size; - } - - f->type.t = (f->type.t & ~(0x3f << VT_STRUCT_SHIFT)) - | (bit_pos << VT_STRUCT_SHIFT); - bit_pos += bit_size; - } - if (align > maxalign) - maxalign = align; - -#ifdef BF_DEBUG - printf("set field %s offset %-2d size %-2d align %-2d", - get_tok_str(f->v & ~SYM_FIELD, NULL), offset, size, align); - if (f->type.t & VT_BITFIELD) { - printf(" pos %-2d bits %-2d", - BIT_POS(f->type.t), - BIT_SIZE(f->type.t) - ); - } - printf("\n"); -#endif - - if (f->v & SYM_FIRST_ANOM && (f->type.t & VT_BTYPE) == VT_STRUCT) { - Sym *ass; - /* An anonymous struct/union. Adjust member offsets - to reflect the real offset of our containing struct. - Also set the offset of this anon member inside - the outer struct to be zero. Via this it - works when accessing the field offset directly - (from base object), as well as when recursing - members in initializer handling. */ - int v2 = f->type.ref->v; - if (!(v2 & SYM_FIELD) && - (v2 & ~SYM_STRUCT) < SYM_FIRST_ANOM) { - Sym **pps; - /* This happens only with MS extensions. The - anon member has a named struct type, so it - potentially is shared with other references. - We need to unshare members so we can modify - them. */ - ass = f->type.ref; - f->type.ref = sym_push(anon_sym++ | SYM_FIELD, - &f->type.ref->type, 0, - f->type.ref->c); - pps = &f->type.ref->next; - while ((ass = ass->next) != NULL) { - *pps = sym_push(ass->v, &ass->type, 0, ass->c); - pps = &((*pps)->next); - } - *pps = NULL; - } - struct_add_offset(f->type.ref, offset); - f->c = 0; - } else { - f->c = offset; - } - - f->r = 0; - } - - if (pcc) - c += (bit_pos + 7) >> 3; - - /* store size and alignment */ - a = bt = ad->a.aligned ? 1 << (ad->a.aligned - 1) : 1; - if (a < maxalign) - a = maxalign; - type->ref->r = a; - if (pragma_pack && pragma_pack < maxalign && 0 == pcc) { - /* can happen if individual align for some member was given. In - this case MSVC ignores maxalign when aligning the size */ - a = pragma_pack; - if (a < bt) - a = bt; - } - c = (c + a - 1) & -a; - type->ref->c = c; - -#ifdef BF_DEBUG - printf("struct size %-2d align %-2d\n\n", c, a), fflush(stdout); -#endif - - /* check whether we can access bitfields by their type */ - for (f = type->ref->next; f; f = f->next) { - int s, px, cx, c0; - CType t; - - if (0 == (f->type.t & VT_BITFIELD)) - continue; - f->type.ref = f; - f->auxtype = -1; - bit_size = BIT_SIZE(f->type.t); - if (bit_size == 0) - continue; - bit_pos = BIT_POS(f->type.t); - size = type_size(&f->type, &align); - if (bit_pos + bit_size <= size * 8 && f->c + size <= c) - continue; - - /* try to access the field using a different type */ - c0 = -1, s = align = 1; - for (;;) { - px = f->c * 8 + bit_pos; - cx = (px >> 3) & -align; - px = px - (cx << 3); - if (c0 == cx) - break; - s = (px + bit_size + 7) >> 3; - if (s > 4) { - t.t = VT_LLONG; - } else if (s > 2) { - t.t = VT_INT; - } else if (s > 1) { - t.t = VT_SHORT; - } else { - t.t = VT_BYTE; - } - s = type_size(&t, &align); - c0 = cx; - } - - if (px + bit_size <= s * 8 && cx + s <= c) { - /* update offset and bit position */ - f->c = cx; - bit_pos = px; - f->type.t = (f->type.t & ~(0x3f << VT_STRUCT_SHIFT)) - | (bit_pos << VT_STRUCT_SHIFT); - if (s != size) - f->auxtype = t.t; -#ifdef BF_DEBUG - printf("FIX field %s offset %-2d size %-2d align %-2d " - "pos %-2d bits %-2d\n", - get_tok_str(f->v & ~SYM_FIELD, NULL), - cx, s, align, px, bit_size); -#endif - } else { - /* fall back to load/store single-byte wise */ - f->auxtype = VT_STRUCT; -#ifdef BF_DEBUG - printf("FIX field %s : load byte-wise\n", - get_tok_str(f->v & ~SYM_FIELD, NULL)); -#endif - } - } -} - -/* enum/struct/union declaration. u is VT_ENUM/VT_STRUCT/VT_UNION */ -static void struct_decl(CType *type, int u) -{ - int v, c, size, align, flexible; - int bit_size, bsize, bt; - Sym *s, *ss, **ps; - AttributeDef ad, ad1; - CType type1, btype; - - memset(&ad, 0, sizeof ad); - next(); - parse_attribute(&ad); - if (tok != '{') { - v = tok; - next(); - /* struct already defined ? return it */ - if (v < TOK_IDENT) - expect("struct/union/enum name"); - s = struct_find(v); - if (s && (s->sym_scope == local_scope || tok != '{')) { - if (u == s->type.t) - goto do_decl; - if (u == VT_ENUM && IS_ENUM(s->type.t)) - goto do_decl; - tcc_error("redefinition of '%s'", get_tok_str(v, NULL)); - } - } else { - v = anon_sym++; - } - /* Record the original enum/struct/union token. */ - type1.t = u == VT_ENUM ? u | VT_INT | VT_UNSIGNED : u; - type1.ref = NULL; - /* we put an undefined size for struct/union */ - s = sym_push(v | SYM_STRUCT, &type1, 0, -1); - s->r = 0; /* default alignment is zero as gcc */ -do_decl: - type->t = s->type.t; - type->ref = s; - - if (tok == '{') { - next(); - if (s->c != -1) - tcc_error("struct/union/enum already defined"); - /* cannot be empty */ - /* non empty enums are not allowed */ - ps = &s->next; - if (u == VT_ENUM) { - long long ll = 0, pl = 0, nl = 0; - CType t; - t.ref = s; - /* enum symbols have static storage */ - t.t = VT_INT|VT_STATIC|VT_ENUM_VAL; - for(;;) { - v = tok; - if (v < TOK_UIDENT) - expect("identifier"); - ss = sym_find(v); - if (ss && !local_stack) - tcc_error("redefinition of enumerator '%s'", - get_tok_str(v, NULL)); - next(); - if (tok == '=') { - next(); - ll = expr_const64(); - } - ss = sym_push(v, &t, VT_CONST, 0); - ss->enum_val = ll; - *ps = ss, ps = &ss->next; - if (ll < nl) - nl = ll; - if (ll > pl) - pl = ll; - if (tok != ',') - break; - next(); - ll++; - /* NOTE: we accept a trailing comma */ - if (tok == '}') - break; - } - skip('}'); - /* set integral type of the enum */ - t.t = VT_INT; - if (nl >= 0) { - if (pl != (unsigned)pl) - t.t = (LONG_SIZE==8 ? VT_LLONG|VT_LONG : VT_LLONG); - t.t |= VT_UNSIGNED; - } else if (pl != (int)pl || nl != (int)nl) - t.t = (LONG_SIZE==8 ? VT_LLONG|VT_LONG : VT_LLONG); - s->type.t = type->t = t.t | VT_ENUM; - s->c = 0; - /* set type for enum members */ - for (ss = s->next; ss; ss = ss->next) { - ll = ss->enum_val; - if (ll == (int)ll) /* default is int if it fits */ - continue; - if (t.t & VT_UNSIGNED) { - ss->type.t |= VT_UNSIGNED; - if (ll == (unsigned)ll) - continue; - } - ss->type.t = (ss->type.t & ~VT_BTYPE) - | (LONG_SIZE==8 ? VT_LLONG|VT_LONG : VT_LLONG); - } - } else { - c = 0; - flexible = 0; - while (tok != '}') { - if (!parse_btype(&btype, &ad1)) { - skip(';'); - continue; - } - while (1) { - if (flexible) - tcc_error("flexible array member '%s' not at the end of struct", - get_tok_str(v, NULL)); - bit_size = -1; - v = 0; - type1 = btype; - if (tok != ':') { - if (tok != ';') - type_decl(&type1, &ad1, &v, TYPE_DIRECT); - if (v == 0) { - if ((type1.t & VT_BTYPE) != VT_STRUCT) - expect("identifier"); - else { - int v = btype.ref->v; - if (!(v & SYM_FIELD) && (v & ~SYM_STRUCT) < SYM_FIRST_ANOM) { - if (tcc_state->ms_extensions == 0) - expect("identifier"); - } - } - } - if (type_size(&type1, &align) < 0) { - if ((u == VT_STRUCT) && (type1.t & VT_ARRAY) && c) - flexible = 1; - else - tcc_error("field '%s' has incomplete type", - get_tok_str(v, NULL)); - } - if ((type1.t & VT_BTYPE) == VT_FUNC || - (type1.t & VT_STORAGE)) - tcc_error("invalid type for '%s'", - get_tok_str(v, NULL)); - } - if (tok == ':') { - next(); - bit_size = expr_const(); - /* XXX: handle v = 0 case for messages */ - if (bit_size < 0) - tcc_error("negative width in bit-field '%s'", - get_tok_str(v, NULL)); - if (v && bit_size == 0) - tcc_error("zero width for bit-field '%s'", - get_tok_str(v, NULL)); - parse_attribute(&ad1); - } - size = type_size(&type1, &align); - if (bit_size >= 0) { - bt = type1.t & VT_BTYPE; - if (bt != VT_INT && - bt != VT_BYTE && - bt != VT_SHORT && - bt != VT_BOOL && - bt != VT_LLONG) - tcc_error("bitfields must have scalar type"); - bsize = size * 8; - if (bit_size > bsize) { - tcc_error("width of '%s' exceeds its type", - get_tok_str(v, NULL)); - } else if (bit_size == bsize - && !ad.a.packed && !ad1.a.packed) { - /* no need for bit fields */ - ; - } else if (bit_size == 64) { - tcc_error("field width 64 not implemented"); - } else { - type1.t = (type1.t & ~VT_STRUCT_MASK) - | VT_BITFIELD - | (bit_size << (VT_STRUCT_SHIFT + 6)); - } - } - if (v != 0 || (type1.t & VT_BTYPE) == VT_STRUCT) { - /* Remember we've seen a real field to check - for placement of flexible array member. */ - c = 1; - } - /* If member is a struct or bit-field, enforce - placing into the struct (as anonymous). */ - if (v == 0 && - ((type1.t & VT_BTYPE) == VT_STRUCT || - bit_size >= 0)) { - v = anon_sym++; - } - if (v) { - ss = sym_push(v | SYM_FIELD, &type1, 0, 0); - ss->a = ad1.a; - *ps = ss; - ps = &ss->next; - } - if (tok == ';' || tok == TOK_EOF) - break; - skip(','); - } - skip(';'); - } - skip('}'); - parse_attribute(&ad); - struct_layout(type, &ad); - } - } -} - -static void sym_to_attr(AttributeDef *ad, Sym *s) -{ - if (s->a.aligned && 0 == ad->a.aligned) - ad->a.aligned = s->a.aligned; - if (s->f.func_call && 0 == ad->f.func_call) - ad->f.func_call = s->f.func_call; - if (s->f.func_type && 0 == ad->f.func_type) - ad->f.func_type = s->f.func_type; - if (s->a.packed) - ad->a.packed = 1; -} - -/* Add type qualifiers to a type. If the type is an array then the qualifiers - are added to the element type, copied because it could be a typedef. */ -static void parse_btype_qualify(CType *type, int qualifiers) -{ - while (type->t & VT_ARRAY) { - type->ref = sym_push(SYM_FIELD, &type->ref->type, 0, type->ref->c); - type = &type->ref->type; - } - type->t |= qualifiers; -} - -/* return 0 if no type declaration. otherwise, return the basic type - and skip it. - */ -static int parse_btype(CType *type, AttributeDef *ad) -{ - int t, u, bt, st, type_found, typespec_found, g; - Sym *s; - CType type1; - - memset(ad, 0, sizeof(AttributeDef)); - type_found = 0; - typespec_found = 0; - t = VT_INT; - bt = st = -1; - type->ref = NULL; - - while(1) { - switch(tok) { - case TOK_EXTENSION: - /* currently, we really ignore extension */ - next(); - continue; - - /* basic types */ - case TOK_CHAR: - u = VT_BYTE; - basic_type: - next(); - basic_type1: - if (u == VT_SHORT || u == VT_LONG) { - if (st != -1 || (bt != -1 && bt != VT_INT)) - tmbt: tcc_error("too many basic types"); - st = u; - } else { - if (bt != -1 || (st != -1 && u != VT_INT)) - goto tmbt; - bt = u; - } - if (u != VT_INT) - t = (t & ~(VT_BTYPE|VT_LONG)) | u; - typespec_found = 1; - break; - case TOK_VOID: - u = VT_VOID; - goto basic_type; - case TOK_SHORT: - u = VT_SHORT; - goto basic_type; - case TOK_INT: - u = VT_INT; - goto basic_type; - case TOK_LONG: - if ((t & VT_BTYPE) == VT_DOUBLE) { - t = (t & ~(VT_BTYPE|VT_LONG)) | VT_LDOUBLE; - } else if ((t & (VT_BTYPE|VT_LONG)) == VT_LONG) { - t = (t & ~(VT_BTYPE|VT_LONG)) | VT_LLONG; - } else { - u = VT_LONG; - goto basic_type; - } - next(); - break; -#ifdef TCC_TARGET_ARM64 - case TOK_UINT128: - /* GCC's __uint128_t appears in some Linux header files. Make it a - synonym for long double to get the size and alignment right. */ - u = VT_LDOUBLE; - goto basic_type; -#endif - case TOK_BOOL: - u = VT_BOOL; - goto basic_type; - case TOK_FLOAT: - u = VT_FLOAT; - goto basic_type; - case TOK_DOUBLE: - if ((t & (VT_BTYPE|VT_LONG)) == VT_LONG) { - t = (t & ~(VT_BTYPE|VT_LONG)) | VT_LDOUBLE; - } else { - u = VT_DOUBLE; - goto basic_type; - } - next(); - break; - case TOK_ENUM: - struct_decl(&type1, VT_ENUM); - basic_type2: - u = type1.t; - type->ref = type1.ref; - goto basic_type1; - case TOK_STRUCT: - struct_decl(&type1, VT_STRUCT); - goto basic_type2; - case TOK_UNION: - struct_decl(&type1, VT_UNION); - goto basic_type2; - - /* type modifiers */ - case TOK_CONST1: - case TOK_CONST2: - case TOK_CONST3: - type->t = t; - parse_btype_qualify(type, VT_CONSTANT); - t = type->t; - next(); - break; - case TOK_VOLATILE1: - case TOK_VOLATILE2: - case TOK_VOLATILE3: - type->t = t; - parse_btype_qualify(type, VT_VOLATILE); - t = type->t; - next(); - break; - case TOK_SIGNED1: - case TOK_SIGNED2: - case TOK_SIGNED3: - if ((t & (VT_DEFSIGN|VT_UNSIGNED)) == (VT_DEFSIGN|VT_UNSIGNED)) - tcc_error("signed and unsigned modifier"); - t |= VT_DEFSIGN; - next(); - typespec_found = 1; - break; - case TOK_REGISTER: - case TOK_AUTO: - case TOK_RESTRICT1: - case TOK_RESTRICT2: - case TOK_RESTRICT3: - next(); - break; - case TOK_UNSIGNED: - if ((t & (VT_DEFSIGN|VT_UNSIGNED)) == VT_DEFSIGN) - tcc_error("signed and unsigned modifier"); - t |= VT_DEFSIGN | VT_UNSIGNED; - next(); - typespec_found = 1; - break; - - /* storage */ - case TOK_EXTERN: - g = VT_EXTERN; - goto storage; - case TOK_STATIC: - g = VT_STATIC; - goto storage; - case TOK_TYPEDEF: - g = VT_TYPEDEF; - goto storage; - storage: - if (t & (VT_EXTERN|VT_STATIC|VT_TYPEDEF) & ~g) - tcc_error("multiple storage classes"); - t |= g; - next(); - break; - case TOK_INLINE1: - case TOK_INLINE2: - case TOK_INLINE3: - t |= VT_INLINE; - next(); - break; - - /* GNUC attribute */ - case TOK_ATTRIBUTE1: - case TOK_ATTRIBUTE2: - parse_attribute(ad); - if (ad->attr_mode) { - u = ad->attr_mode -1; - t = (t & ~(VT_BTYPE|VT_LONG)) | u; - } - break; - /* GNUC typeof */ - case TOK_TYPEOF1: - case TOK_TYPEOF2: - case TOK_TYPEOF3: - next(); - parse_expr_type(&type1); - /* remove all storage modifiers except typedef */ - type1.t &= ~(VT_STORAGE&~VT_TYPEDEF); - if (type1.ref) - sym_to_attr(ad, type1.ref); - goto basic_type2; - default: - if (typespec_found) - goto the_end; - s = sym_find(tok); - if (!s || !(s->type.t & VT_TYPEDEF)) - goto the_end; - t &= ~(VT_BTYPE|VT_LONG); - u = t & ~(VT_CONSTANT | VT_VOLATILE), t ^= u; - type->t = (s->type.t & ~VT_TYPEDEF) | u; - type->ref = s->type.ref; - if (t) - parse_btype_qualify(type, t); - t = type->t; - /* get attributes from typedef */ - sym_to_attr(ad, s); - next(); - typespec_found = 1; - st = bt = -2; - break; - } - type_found = 1; - } -the_end: - if (tcc_state->char_is_unsigned) { - if ((t & (VT_DEFSIGN|VT_BTYPE)) == VT_BYTE) - t |= VT_UNSIGNED; - } - /* VT_LONG is used just as a modifier for VT_INT / VT_LLONG */ - bt = t & (VT_BTYPE|VT_LONG); - if (bt == VT_LONG) - t |= LONG_SIZE == 8 ? VT_LLONG : VT_INT; -#ifdef TCC_TARGET_PE - if (bt == VT_LDOUBLE) - t = (t & ~(VT_BTYPE|VT_LONG)) | VT_DOUBLE; -#endif - type->t = t; - return type_found; -} - -/* convert a function parameter type (array to pointer and function to - function pointer) */ -static inline void convert_parameter_type(CType *pt) -{ - /* remove const and volatile qualifiers (XXX: const could be used - to indicate a const function parameter */ - pt->t &= ~(VT_CONSTANT | VT_VOLATILE); - /* array must be transformed to pointer according to ANSI C */ - pt->t &= ~VT_ARRAY; - if ((pt->t & VT_BTYPE) == VT_FUNC) { - mk_pointer(pt); - } -} - -ST_FUNC void parse_asm_str(CString *astr) -{ - skip('('); - parse_mult_str(astr, "string constant"); -} - -/* Parse an asm label and return the token */ -static int asm_label_instr(void) -{ - int v; - CString astr; - - next(); - parse_asm_str(&astr); - skip(')'); -#ifdef ASM_DEBUG - printf("asm_alias: \"%s\"\n", (char *)astr.data); -#endif - v = tok_alloc(astr.data, astr.size - 1)->tok; - cstr_free(&astr); - return v; -} - -static int post_type(CType *type, AttributeDef *ad, int storage, int td) -{ - int n, l, t1, arg_size, align; - Sym **plast, *s, *first; - AttributeDef ad1; - CType pt; - - if (tok == '(') { - /* function type, or recursive declarator (return if so) */ - next(); - if (td && !(td & TYPE_ABSTRACT)) - return 0; - if (tok == ')') - l = 0; - else if (parse_btype(&pt, &ad1)) - l = FUNC_NEW; - else if (td) - return 0; - else - l = FUNC_OLD; - first = NULL; - plast = &first; - arg_size = 0; - if (l) { - for(;;) { - /* read param name and compute offset */ - if (l != FUNC_OLD) { - if ((pt.t & VT_BTYPE) == VT_VOID && tok == ')') - break; - type_decl(&pt, &ad1, &n, TYPE_DIRECT | TYPE_ABSTRACT); - if ((pt.t & VT_BTYPE) == VT_VOID) - tcc_error("parameter declared as void"); - arg_size += (type_size(&pt, &align) + PTR_SIZE - 1) / PTR_SIZE; - } else { - n = tok; - if (n < TOK_UIDENT) - expect("identifier"); - pt.t = VT_VOID; /* invalid type */ - next(); - } - convert_parameter_type(&pt); - s = sym_push(n | SYM_FIELD, &pt, 0, 0); - *plast = s; - plast = &s->next; - if (tok == ')') - break; - skip(','); - if (l == FUNC_NEW && tok == TOK_DOTS) { - l = FUNC_ELLIPSIS; - next(); - break; - } - if (l == FUNC_NEW && !parse_btype(&pt, &ad1)) - tcc_error("invalid type"); - } - } else - /* if no parameters, then old type prototype */ - l = FUNC_OLD; - skip(')'); - /* NOTE: const is ignored in returned type as it has a special - meaning in gcc / C++ */ - type->t &= ~VT_CONSTANT; - /* some ancient pre-K&R C allows a function to return an array - and the array brackets to be put after the arguments, such - that "int c()[]" means something like "int[] c()" */ - if (tok == '[') { - next(); - skip(']'); /* only handle simple "[]" */ - mk_pointer(type); - } - /* we push a anonymous symbol which will contain the function prototype */ - ad->f.func_args = arg_size; - ad->f.func_type = l; - s = sym_push(SYM_FIELD, type, 0, 0); - s->a = ad->a; - s->f = ad->f; - s->next = first; - type->t = VT_FUNC; - type->ref = s; - } else if (tok == '[') { - int saved_nocode_wanted = nocode_wanted; - /* array definition */ - next(); - if (tok == TOK_RESTRICT1) - next(); - n = -1; - t1 = 0; - if (tok != ']') { - if (!local_stack || (storage & VT_STATIC)) - vpushi(expr_const()); - else { - /* VLAs (which can only happen with local_stack && !VT_STATIC) - length must always be evaluated, even under nocode_wanted, - so that its size slot is initialized (e.g. under sizeof - or typeof). */ - nocode_wanted = 0; - gexpr(); - } - if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) { - n = vtop->c.i; - if (n < 0) - tcc_error("invalid array size"); - } else { - if (!is_integer_btype(vtop->type.t & VT_BTYPE)) - tcc_error("size of variable length array should be an integer"); - t1 = VT_VLA; - } - } - skip(']'); - /* parse next post type */ - post_type(type, ad, storage, 0); - if (type->t == VT_FUNC) - tcc_error("declaration of an array of functions"); - t1 |= type->t & VT_VLA; - - if (t1 & VT_VLA) { - loc -= type_size(&int_type, &align); - loc &= -align; - n = loc; - - vla_runtime_type_size(type, &align); - gen_op('*'); - vset(&int_type, VT_LOCAL|VT_LVAL, n); - vswap(); - vstore(); - } - if (n != -1) - vpop(); - nocode_wanted = saved_nocode_wanted; - - /* we push an anonymous symbol which will contain the array - element type */ - s = sym_push(SYM_FIELD, type, 0, n); - type->t = (t1 ? VT_VLA : VT_ARRAY) | VT_PTR; - type->ref = s; - } - return 1; -} - -/* Parse a type declarator (except basic type), and return the type - in 'type'. 'td' is a bitmask indicating which kind of type decl is - expected. 'type' should contain the basic type. 'ad' is the - attribute definition of the basic type. It can be modified by - type_decl(). If this (possibly abstract) declarator is a pointer chain - it returns the innermost pointed to type (equals *type, but is a different - pointer), otherwise returns type itself, that's used for recursive calls. */ -static CType *type_decl(CType *type, AttributeDef *ad, int *v, int td) -{ - CType *post, *ret; - int qualifiers, storage; - - /* recursive type, remove storage bits first, apply them later again */ - storage = type->t & VT_STORAGE; - type->t &= ~VT_STORAGE; - post = ret = type; - - while (tok == '*') { - qualifiers = 0; - redo: - next(); - switch(tok) { - case TOK_CONST1: - case TOK_CONST2: - case TOK_CONST3: - qualifiers |= VT_CONSTANT; - goto redo; - case TOK_VOLATILE1: - case TOK_VOLATILE2: - case TOK_VOLATILE3: - qualifiers |= VT_VOLATILE; - goto redo; - case TOK_RESTRICT1: - case TOK_RESTRICT2: - case TOK_RESTRICT3: - goto redo; - /* XXX: clarify attribute handling */ - case TOK_ATTRIBUTE1: - case TOK_ATTRIBUTE2: - parse_attribute(ad); - break; - } - mk_pointer(type); - type->t |= qualifiers; - if (ret == type) - /* innermost pointed to type is the one for the first derivation */ - ret = pointed_type(type); - } - - if (tok == '(') { - /* This is possibly a parameter type list for abstract declarators - ('int ()'), use post_type for testing this. */ - if (!post_type(type, ad, 0, td)) { - /* It's not, so it's a nested declarator, and the post operations - apply to the innermost pointed to type (if any). */ - /* XXX: this is not correct to modify 'ad' at this point, but - the syntax is not clear */ - parse_attribute(ad); - post = type_decl(type, ad, v, td); - skip(')'); - } - } else if (tok >= TOK_IDENT && (td & TYPE_DIRECT)) { - /* type identifier */ - *v = tok; - next(); - } else { - if (!(td & TYPE_ABSTRACT)) - expect("identifier"); - *v = 0; - } - post_type(post, ad, storage, 0); - parse_attribute(ad); - type->t |= storage; - return ret; -} - -/* compute the lvalue VT_LVAL_xxx needed to match type t. */ -ST_FUNC int lvalue_type(int t) -{ - int bt, r; - r = VT_LVAL; - bt = t & VT_BTYPE; - if (bt == VT_BYTE || bt == VT_BOOL) - r |= VT_LVAL_BYTE; - else if (bt == VT_SHORT) - r |= VT_LVAL_SHORT; - else - return r; - if (t & VT_UNSIGNED) - r |= VT_LVAL_UNSIGNED; - return r; -} - -/* indirection with full error checking and bound check */ -ST_FUNC void indir(void) -{ - if ((vtop->type.t & VT_BTYPE) != VT_PTR) { - if ((vtop->type.t & VT_BTYPE) == VT_FUNC) - return; - expect("pointer"); - } - if (vtop->r & VT_LVAL) - gv(RC_INT); - vtop->type = *pointed_type(&vtop->type); - /* Arrays and functions are never lvalues */ - if (!(vtop->type.t & VT_ARRAY) && !(vtop->type.t & VT_VLA) - && (vtop->type.t & VT_BTYPE) != VT_FUNC) { - vtop->r |= lvalue_type(vtop->type.t); - /* if bound checking, the referenced pointer must be checked */ -#ifdef CONFIG_TCC_BCHECK - if (tcc_state->do_bounds_check) - vtop->r |= VT_MUSTBOUND; -#endif - } -} - -/* pass a parameter to a function and do type checking and casting */ -static void gfunc_param_typed(Sym *func, Sym *arg) -{ - int func_type; - CType type; - - func_type = func->f.func_type; - if (func_type == FUNC_OLD || - (func_type == FUNC_ELLIPSIS && arg == NULL)) { - /* default casting : only need to convert float to double */ - if ((vtop->type.t & VT_BTYPE) == VT_FLOAT) { - gen_cast_s(VT_DOUBLE); - } else if (vtop->type.t & VT_BITFIELD) { - type.t = vtop->type.t & (VT_BTYPE | VT_UNSIGNED); - type.ref = vtop->type.ref; - gen_cast(&type); - } - } else if (arg == NULL) { - tcc_error("too many arguments to function"); - } else { - type = arg->type; - type.t &= ~VT_CONSTANT; /* need to do that to avoid false warning */ - gen_assign_cast(&type); - } -} - -/* parse an expression and return its type without any side effect. */ -static void expr_type(CType *type, void (*expr_fn)(void)) -{ - nocode_wanted++; - expr_fn(); - *type = vtop->type; - vpop(); - nocode_wanted--; -} - -/* parse an expression of the form '(type)' or '(expr)' and return its - type */ -static void parse_expr_type(CType *type) -{ - int n; - AttributeDef ad; - - skip('('); - if (parse_btype(type, &ad)) { - type_decl(type, &ad, &n, TYPE_ABSTRACT); - } else { - expr_type(type, gexpr); - } - skip(')'); -} - -static void parse_type(CType *type) -{ - AttributeDef ad; - int n; - - if (!parse_btype(type, &ad)) { - expect("type"); - } - type_decl(type, &ad, &n, TYPE_ABSTRACT); -} - -static void parse_builtin_params(int nc, const char *args) -{ - char c, sep = '('; - CType t; - if (nc) - nocode_wanted++; - next(); - while ((c = *args++)) { - skip(sep); - sep = ','; - switch (c) { - case 'e': expr_eq(); continue; - case 't': parse_type(&t); vpush(&t); continue; - default: tcc_error("internal error"); break; - } - } - skip(')'); - if (nc) - nocode_wanted--; -} - -ST_FUNC void unary(void) -{ - int n, t, align, size, r, sizeof_caller; - CType type; - Sym *s; - AttributeDef ad; - - sizeof_caller = in_sizeof; - in_sizeof = 0; - type.ref = NULL; - /* XXX: GCC 2.95.3 does not generate a table although it should be - better here */ - tok_next: - switch(tok) { - case TOK_EXTENSION: - next(); - goto tok_next; - case TOK_LCHAR: -#ifdef TCC_TARGET_PE - t = VT_SHORT|VT_UNSIGNED; - goto push_tokc; -#endif - case TOK_CINT: - case TOK_CCHAR: - t = VT_INT; - push_tokc: - type.t = t; - vsetc(&type, VT_CONST, &tokc); - next(); - break; - case TOK_CUINT: - t = VT_INT | VT_UNSIGNED; - goto push_tokc; - case TOK_CLLONG: - t = VT_LLONG; - goto push_tokc; - case TOK_CULLONG: - t = VT_LLONG | VT_UNSIGNED; - goto push_tokc; - case TOK_CFLOAT: - t = VT_FLOAT; - goto push_tokc; - case TOK_CDOUBLE: - t = VT_DOUBLE; - goto push_tokc; - case TOK_CLDOUBLE: - t = VT_LDOUBLE; - goto push_tokc; - case TOK_CLONG: - t = (LONG_SIZE == 8 ? VT_LLONG : VT_INT) | VT_LONG; - goto push_tokc; - case TOK_CULONG: - t = (LONG_SIZE == 8 ? VT_LLONG : VT_INT) | VT_LONG | VT_UNSIGNED; - goto push_tokc; - case TOK___FUNCTION__: - if (!gnu_ext) - goto tok_identifier; - /* fall thru */ - case TOK___FUNC__: - { - void *ptr; - int len; - /* special function name identifier */ - len = strlen(funcname) + 1; - /* generate char[len] type */ - type.t = VT_BYTE; - mk_pointer(&type); - type.t |= VT_ARRAY; - type.ref->c = len; - vpush_ref(&type, data_section, data_section->data_offset, len); - if (!NODATA_WANTED) { - ptr = section_ptr_add(data_section, len); - memcpy(ptr, funcname, len); - } - next(); - } - break; - case TOK_LSTR: -#ifdef TCC_TARGET_PE - t = VT_SHORT | VT_UNSIGNED; -#else - t = VT_INT; -#endif - goto str_init; - case TOK_STR: - /* string parsing */ - t = VT_BYTE; - if (tcc_state->char_is_unsigned) - t = VT_BYTE | VT_UNSIGNED; - str_init: - if (tcc_state->warn_write_strings) - t |= VT_CONSTANT; - type.t = t; - mk_pointer(&type); - type.t |= VT_ARRAY; - memset(&ad, 0, sizeof(AttributeDef)); - decl_initializer_alloc(&type, &ad, VT_CONST, 2, 0, 0); - break; - case '(': - next(); - /* cast ? */ - if (parse_btype(&type, &ad)) { - type_decl(&type, &ad, &n, TYPE_ABSTRACT); - skip(')'); - /* check ISOC99 compound literal */ - if (tok == '{') { - /* data is allocated locally by default */ - if (global_expr) - r = VT_CONST; - else - r = VT_LOCAL; - /* all except arrays are lvalues */ - if (!(type.t & VT_ARRAY)) - r |= lvalue_type(type.t); - memset(&ad, 0, sizeof(AttributeDef)); - decl_initializer_alloc(&type, &ad, r, 1, 0, 0); - } else { - if (sizeof_caller) { - vpush(&type); - return; - } - unary(); - gen_cast(&type); - } - } else if (tok == '{') { - int saved_nocode_wanted = nocode_wanted; - if (const_wanted) - tcc_error("expected constant"); - /* save all registers */ - save_regs(0); - /* statement expression : we do not accept break/continue - inside as GCC does. We do retain the nocode_wanted state, - as statement expressions can't ever be entered from the - outside, so any reactivation of code emission (from labels - or loop heads) can be disabled again after the end of it. */ - block(NULL, NULL, 1); - nocode_wanted = saved_nocode_wanted; - skip(')'); - } else { - gexpr(); - skip(')'); - } - break; - case '*': - next(); - unary(); - indir(); - break; - case '&': - next(); - unary(); - /* functions names must be treated as function pointers, - except for unary '&' and sizeof. Since we consider that - functions are not lvalues, we only have to handle it - there and in function calls. */ - /* arrays can also be used although they are not lvalues */ - if ((vtop->type.t & VT_BTYPE) != VT_FUNC && - !(vtop->type.t & VT_ARRAY)) - test_lvalue(); - mk_pointer(&vtop->type); - gaddrof(); - break; - case '!': - next(); - unary(); - if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) { - gen_cast_s(VT_BOOL); - vtop->c.i = !vtop->c.i; - } else if ((vtop->r & VT_VALMASK) == VT_CMP) - vtop->c.i ^= 1; - else { - save_regs(1); - vseti(VT_JMP, gvtst(1, 0)); - } - break; - case '~': - next(); - unary(); - vpushi(-1); - gen_op('^'); - break; - case '+': - next(); - unary(); - if ((vtop->type.t & VT_BTYPE) == VT_PTR) - tcc_error("pointer not accepted for unary plus"); - /* In order to force cast, we add zero, except for floating point - where we really need an noop (otherwise -0.0 will be transformed - into +0.0). */ - if (!is_float(vtop->type.t)) { - vpushi(0); - gen_op('+'); - } - break; - case TOK_SIZEOF: - case TOK_ALIGNOF1: - case TOK_ALIGNOF2: - t = tok; - next(); - in_sizeof++; - expr_type(&type, unary); /* Perform a in_sizeof = 0; */ - s = vtop[1].sym; /* hack: accessing previous vtop */ - size = type_size(&type, &align); - if (s && s->a.aligned) - align = 1 << (s->a.aligned - 1); - if (t == TOK_SIZEOF) { - if (!(type.t & VT_VLA)) { - if (size < 0) - tcc_error("sizeof applied to an incomplete type"); - vpushs(size); - } else { - vla_runtime_type_size(&type, &align); - } - } else { - vpushs(align); - } - vtop->type.t |= VT_UNSIGNED; - break; - - case TOK_builtin_expect: - /* __builtin_expect is a no-op for now */ - parse_builtin_params(0, "ee"); - vpop(); - break; - case TOK_builtin_types_compatible_p: - parse_builtin_params(0, "tt"); - vtop[-1].type.t &= ~(VT_CONSTANT | VT_VOLATILE); - vtop[0].type.t &= ~(VT_CONSTANT | VT_VOLATILE); - n = is_compatible_types(&vtop[-1].type, &vtop[0].type); - vtop -= 2; - vpushi(n); - break; - case TOK_builtin_choose_expr: - { - int64_t c; - next(); - skip('('); - c = expr_const64(); - skip(','); - if (!c) { - nocode_wanted++; - } - expr_eq(); - if (!c) { - vpop(); - nocode_wanted--; - } - skip(','); - if (c) { - nocode_wanted++; - } - expr_eq(); - if (c) { - vpop(); - nocode_wanted--; - } - skip(')'); - } - break; - case TOK_builtin_constant_p: - parse_builtin_params(1, "e"); - n = (vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST; - vtop--; - vpushi(n); - break; - case TOK_builtin_frame_address: - case TOK_builtin_return_address: - { - int tok1 = tok; - int level; - next(); - skip('('); - if (tok != TOK_CINT) { - tcc_error("%s only takes positive integers", - tok1 == TOK_builtin_return_address ? - "__builtin_return_address" : - "__builtin_frame_address"); - } - level = (uint32_t)tokc.i; - next(); - skip(')'); - type.t = VT_VOID; - mk_pointer(&type); - vset(&type, VT_LOCAL, 0); /* local frame */ - while (level--) { - mk_pointer(&vtop->type); - indir(); /* -> parent frame */ - } - if (tok1 == TOK_builtin_return_address) { - // assume return address is just above frame pointer on stack - vpushi(PTR_SIZE); - gen_op('+'); - mk_pointer(&vtop->type); - indir(); - } - } - break; -#ifdef TCC_TARGET_X86_64 -#ifdef TCC_TARGET_PE - case TOK_builtin_va_start: - parse_builtin_params(0, "ee"); - r = vtop->r & VT_VALMASK; - if (r == VT_LLOCAL) - r = VT_LOCAL; - if (r != VT_LOCAL) - tcc_error("__builtin_va_start expects a local variable"); - vtop->r = r; - vtop->type = char_pointer_type; - vtop->c.i += 8; - vstore(); - break; -#else - case TOK_builtin_va_arg_types: - parse_builtin_params(0, "t"); - vpushi(classify_x86_64_va_arg(&vtop->type)); - vswap(); - vpop(); - break; -#endif -#endif - -#ifdef TCC_TARGET_ARM64 - case TOK___va_start: { - parse_builtin_params(0, "ee"); - //xx check types - gen_va_start(); - vpushi(0); - vtop->type.t = VT_VOID; - break; - } - case TOK___va_arg: { - parse_builtin_params(0, "et"); - type = vtop->type; - vpop(); - //xx check types - gen_va_arg(&type); - vtop->type = type; - break; - } - case TOK___arm64_clear_cache: { - parse_builtin_params(0, "ee"); - gen_clear_cache(); - vpushi(0); - vtop->type.t = VT_VOID; - break; - } -#endif - /* pre operations */ - case TOK_INC: - case TOK_DEC: - t = tok; - next(); - unary(); - inc(0, t); - break; - case '-': - next(); - unary(); - t = vtop->type.t & VT_BTYPE; - if (is_float(t)) { - /* In IEEE negate(x) isn't subtract(0,x), but rather - subtract(-0, x). */ - vpush(&vtop->type); - if (t == VT_FLOAT) - vtop->c.f = -1.0 * 0.0; - else if (t == VT_DOUBLE) - vtop->c.d = -1.0 * 0.0; - else - vtop->c.ld = -1.0 * 0.0; - } else - vpushi(0); - vswap(); - gen_op('-'); - break; - case TOK_LAND: - if (!gnu_ext) - goto tok_identifier; - next(); - /* allow to take the address of a label */ - if (tok < TOK_UIDENT) - expect("label identifier"); - s = label_find(tok); - if (!s) { - s = label_push(&global_label_stack, tok, LABEL_FORWARD); - } else { - if (s->r == LABEL_DECLARED) - s->r = LABEL_FORWARD; - } - if (!s->type.t) { - s->type.t = VT_VOID; - mk_pointer(&s->type); - s->type.t |= VT_STATIC; - } - vpushsym(&s->type, s); - next(); - break; - - case TOK_GENERIC: - { - CType controlling_type; - int has_default = 0; - int has_match = 0; - int learn = 0; - TokenString *str = NULL; - - next(); - skip('('); - expr_type(&controlling_type, expr_eq); - controlling_type.t &= ~(VT_CONSTANT | VT_VOLATILE | VT_ARRAY); - for (;;) { - learn = 0; - skip(','); - if (tok == TOK_DEFAULT) { - if (has_default) - tcc_error("too many 'default'"); - has_default = 1; - if (!has_match) - learn = 1; - next(); - } else { - AttributeDef ad_tmp; - int itmp; - CType cur_type; - parse_btype(&cur_type, &ad_tmp); - type_decl(&cur_type, &ad_tmp, &itmp, TYPE_ABSTRACT); - if (compare_types(&controlling_type, &cur_type, 0)) { - if (has_match) { - tcc_error("type match twice"); - } - has_match = 1; - learn = 1; - } - } - skip(':'); - if (learn) { - if (str) - tok_str_free(str); - skip_or_save_block(&str); - } else { - skip_or_save_block(NULL); - } - if (tok == ')') - break; - } - if (!str) { - char buf[60]; - type_to_str(buf, sizeof buf, &controlling_type, NULL); - tcc_error("type '%s' does not match any association", buf); - } - begin_macro(str, 1); - next(); - expr_eq(); - if (tok != TOK_EOF) - expect(","); - end_macro(); - next(); - break; - } - // special qnan , snan and infinity values - case TOK___NAN__: - vpush64(VT_DOUBLE, 0x7ff8000000000000ULL); - next(); - break; - case TOK___SNAN__: - vpush64(VT_DOUBLE, 0x7ff0000000000001ULL); - next(); - break; - case TOK___INF__: - vpush64(VT_DOUBLE, 0x7ff0000000000000ULL); - next(); - break; - - default: - tok_identifier: - t = tok; - next(); - if (t < TOK_UIDENT) - expect("identifier"); - s = sym_find(t); - if (!s || IS_ASM_SYM(s)) { - const char *name = get_tok_str(t, NULL); - if (tok != '(') - tcc_error("'%s' undeclared", name); - /* for simple function calls, we tolerate undeclared - external reference to int() function */ - if (tcc_state->warn_implicit_function_declaration -#ifdef TCC_TARGET_PE - /* people must be warned about using undeclared WINAPI functions - (which usually start with uppercase letter) */ - || (name[0] >= 'A' && name[0] <= 'Z') -#endif - ) - tcc_warning("implicit declaration of function '%s'", name); - s = external_global_sym(t, &func_old_type, 0); - } - - r = s->r; - /* A symbol that has a register is a local register variable, - which starts out as VT_LOCAL value. */ - if ((r & VT_VALMASK) < VT_CONST) - r = (r & ~VT_VALMASK) | VT_LOCAL; - - vset(&s->type, r, s->c); - /* Point to s as backpointer (even without r&VT_SYM). - Will be used by at least the x86 inline asm parser for - regvars. */ - vtop->sym = s; - - if (r & VT_SYM) { - vtop->c.i = 0; - } else if (r == VT_CONST && IS_ENUM_VAL(s->type.t)) { - vtop->c.i = s->enum_val; - } - break; - } - - /* post operations */ - while (1) { - if (tok == TOK_INC || tok == TOK_DEC) { - inc(1, tok); - next(); - } else if (tok == '.' || tok == TOK_ARROW || tok == TOK_CDOUBLE) { - int qualifiers; - /* field */ - if (tok == TOK_ARROW) - indir(); - qualifiers = vtop->type.t & (VT_CONSTANT | VT_VOLATILE); - test_lvalue(); - gaddrof(); - /* expect pointer on structure */ - if ((vtop->type.t & VT_BTYPE) != VT_STRUCT) - expect("struct or union"); - if (tok == TOK_CDOUBLE) - expect("field name"); - next(); - if (tok == TOK_CINT || tok == TOK_CUINT) - expect("field name"); - s = find_field(&vtop->type, tok); - if (!s) - tcc_error("field not found: %s", get_tok_str(tok & ~SYM_FIELD, &tokc)); - /* add field offset to pointer */ - vtop->type = char_pointer_type; /* change type to 'char *' */ - vpushi(s->c); - gen_op('+'); - /* change type to field type, and set to lvalue */ - vtop->type = s->type; - vtop->type.t |= qualifiers; - /* an array is never an lvalue */ - if (!(vtop->type.t & VT_ARRAY)) { - vtop->r |= lvalue_type(vtop->type.t); -#ifdef CONFIG_TCC_BCHECK - /* if bound checking, the referenced pointer must be checked */ - if (tcc_state->do_bounds_check && (vtop->r & VT_VALMASK) != VT_LOCAL) - vtop->r |= VT_MUSTBOUND; -#endif - } - next(); - } else if (tok == '[') { - next(); - gexpr(); - gen_op('+'); - indir(); - skip(']'); - } else if (tok == '(') { - SValue ret; - Sym *sa; - int nb_args, ret_nregs, ret_align, regsize, variadic; - - /* function call */ - if ((vtop->type.t & VT_BTYPE) != VT_FUNC) { - /* pointer test (no array accepted) */ - if ((vtop->type.t & (VT_BTYPE | VT_ARRAY)) == VT_PTR) { - vtop->type = *pointed_type(&vtop->type); - if ((vtop->type.t & VT_BTYPE) != VT_FUNC) - goto error_func; - } else { - error_func: - expect("function pointer"); - } - } else { - vtop->r &= ~VT_LVAL; /* no lvalue */ - } - /* get return type */ - s = vtop->type.ref; - next(); - sa = s->next; /* first parameter */ - nb_args = regsize = 0; - ret.r2 = VT_CONST; - /* compute first implicit argument if a structure is returned */ - if ((s->type.t & VT_BTYPE) == VT_STRUCT) { - variadic = (s->f.func_type == FUNC_ELLIPSIS); - ret_nregs = gfunc_sret(&s->type, variadic, &ret.type, - &ret_align, ®size); - if (!ret_nregs) { - /* get some space for the returned structure */ - size = type_size(&s->type, &align); -#ifdef TCC_TARGET_ARM64 - /* On arm64, a small struct is return in registers. - It is much easier to write it to memory if we know - that we are allowed to write some extra bytes, so - round the allocated space up to a power of 2: */ - if (size < 16) - while (size & (size - 1)) - size = (size | (size - 1)) + 1; -#endif - loc = (loc - size) & -align; - ret.type = s->type; - ret.r = VT_LOCAL | VT_LVAL; - /* pass it as 'int' to avoid structure arg passing - problems */ - vseti(VT_LOCAL, loc); - ret.c = vtop->c; - nb_args++; - } - } else { - ret_nregs = 1; - ret.type = s->type; - } - - if (ret_nregs) { - /* return in register */ - if (is_float(ret.type.t)) { - ret.r = reg_fret(ret.type.t); -#ifdef TCC_TARGET_X86_64 - if ((ret.type.t & VT_BTYPE) == VT_QFLOAT) - ret.r2 = REG_QRET; -#endif - } else { -#ifndef TCC_TARGET_ARM64 -#ifdef TCC_TARGET_X86_64 - if ((ret.type.t & VT_BTYPE) == VT_QLONG) -#else - if ((ret.type.t & VT_BTYPE) == VT_LLONG) -#endif - ret.r2 = REG_LRET; -#endif - ret.r = REG_IRET; - } - ret.c.i = 0; - } - if (tok != ')') { - for(;;) { - expr_eq(); - gfunc_param_typed(s, sa); - nb_args++; - if (sa) - sa = sa->next; - if (tok == ')') - break; - skip(','); - } - } - if (sa) - tcc_error("too few arguments to function"); - skip(')'); - gfunc_call(nb_args); - - /* return value */ - for (r = ret.r + ret_nregs + !ret_nregs; r-- > ret.r;) { - vsetc(&ret.type, r, &ret.c); - vtop->r2 = ret.r2; /* Loop only happens when r2 is VT_CONST */ - } - - /* handle packed struct return */ - if (((s->type.t & VT_BTYPE) == VT_STRUCT) && ret_nregs) { - int addr, offset; - - size = type_size(&s->type, &align); - /* We're writing whole regs often, make sure there's enough - space. Assume register size is power of 2. */ - if (regsize > align) - align = regsize; - loc = (loc - size) & -align; - addr = loc; - offset = 0; - for (;;) { - vset(&ret.type, VT_LOCAL | VT_LVAL, addr + offset); - vswap(); - vstore(); - vtop--; - if (--ret_nregs == 0) - break; - offset += regsize; - } - vset(&s->type, VT_LOCAL | VT_LVAL, addr); - } - } else { - break; - } - } -} - -ST_FUNC void expr_prod(void) -{ - int t; - - unary(); - while (tok == '*' || tok == '/' || tok == '%') { - t = tok; - next(); - unary(); - gen_op(t); - } -} - -ST_FUNC void expr_sum(void) -{ - int t; - - expr_prod(); - while (tok == '+' || tok == '-') { - t = tok; - next(); - expr_prod(); - gen_op(t); - } -} - -static void expr_shift(void) -{ - int t; - - expr_sum(); - while (tok == TOK_SHL || tok == TOK_SAR) { - t = tok; - next(); - expr_sum(); - gen_op(t); - } -} - -static void expr_cmp(void) -{ - int t; - - expr_shift(); - while ((tok >= TOK_ULE && tok <= TOK_GT) || - tok == TOK_ULT || tok == TOK_UGE) { - t = tok; - next(); - expr_shift(); - gen_op(t); - } -} - -static void expr_cmpeq(void) -{ - int t; - - expr_cmp(); - while (tok == TOK_EQ || tok == TOK_NE) { - t = tok; - next(); - expr_cmp(); - gen_op(t); - } -} - -static void expr_and(void) -{ - expr_cmpeq(); - while (tok == '&') { - next(); - expr_cmpeq(); - gen_op('&'); - } -} - -static void expr_xor(void) -{ - expr_and(); - while (tok == '^') { - next(); - expr_and(); - gen_op('^'); - } -} - -static void expr_or(void) -{ - expr_xor(); - while (tok == '|') { - next(); - expr_xor(); - gen_op('|'); - } -} - -static void expr_land(void) -{ - expr_or(); - if (tok == TOK_LAND) { - int t = 0; - for(;;) { - if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) { - gen_cast_s(VT_BOOL); - if (vtop->c.i) { - vpop(); - } else { - nocode_wanted++; - while (tok == TOK_LAND) { - next(); - expr_or(); - vpop(); - } - nocode_wanted--; - if (t) - gsym(t); - gen_cast_s(VT_INT); - break; - } - } else { - if (!t) - save_regs(1); - t = gvtst(1, t); - } - if (tok != TOK_LAND) { - if (t) - vseti(VT_JMPI, t); - else - vpushi(1); - break; - } - next(); - expr_or(); - } - } -} - -static void expr_lor(void) -{ - expr_land(); - if (tok == TOK_LOR) { - int t = 0; - for(;;) { - if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) { - gen_cast_s(VT_BOOL); - if (!vtop->c.i) { - vpop(); - } else { - nocode_wanted++; - while (tok == TOK_LOR) { - next(); - expr_land(); - vpop(); - } - nocode_wanted--; - if (t) - gsym(t); - gen_cast_s(VT_INT); - break; - } - } else { - if (!t) - save_regs(1); - t = gvtst(0, t); - } - if (tok != TOK_LOR) { - if (t) - vseti(VT_JMP, t); - else - vpushi(0); - break; - } - next(); - expr_land(); - } - } -} - -/* Assuming vtop is a value used in a conditional context - (i.e. compared with zero) return 0 if it's false, 1 if - true and -1 if it can't be statically determined. */ -static int condition_3way(void) -{ - int c = -1; - if ((vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST && - (!(vtop->r & VT_SYM) || !vtop->sym->a.weak)) { - vdup(); - gen_cast_s(VT_BOOL); - c = vtop->c.i; - vpop(); - } - return c; -} - -static void expr_cond(void) -{ - int tt, u, r1, r2, rc, t1, t2, bt1, bt2, islv, c, g; - SValue sv; - CType type, type1, type2; - - expr_lor(); - if (tok == '?') { - next(); - c = condition_3way(); - g = (tok == ':' && gnu_ext); - if (c < 0) { - /* needed to avoid having different registers saved in - each branch */ - if (is_float(vtop->type.t)) { - rc = RC_FLOAT; -#ifdef TCC_TARGET_X86_64 - if ((vtop->type.t & VT_BTYPE) == VT_LDOUBLE) { - rc = RC_ST0; - } -#endif - } else - rc = RC_INT; - gv(rc); - save_regs(1); - if (g) - gv_dup(); - tt = gvtst(1, 0); - - } else { - if (!g) - vpop(); - tt = 0; - } - - if (1) { - if (c == 0) - nocode_wanted++; - if (!g) - gexpr(); - - type1 = vtop->type; - sv = *vtop; /* save value to handle it later */ - vtop--; /* no vpop so that FP stack is not flushed */ - skip(':'); - - u = 0; - if (c < 0) - u = gjmp(0); - gsym(tt); - - if (c == 0) - nocode_wanted--; - if (c == 1) - nocode_wanted++; - expr_cond(); - if (c == 1) - nocode_wanted--; - - type2 = vtop->type; - t1 = type1.t; - bt1 = t1 & VT_BTYPE; - t2 = type2.t; - bt2 = t2 & VT_BTYPE; - type.ref = NULL; - - /* cast operands to correct type according to ISOC rules */ - if (is_float(bt1) || is_float(bt2)) { - if (bt1 == VT_LDOUBLE || bt2 == VT_LDOUBLE) { - type.t = VT_LDOUBLE; - - } else if (bt1 == VT_DOUBLE || bt2 == VT_DOUBLE) { - type.t = VT_DOUBLE; - } else { - type.t = VT_FLOAT; - } - } else if (bt1 == VT_LLONG || bt2 == VT_LLONG) { - /* cast to biggest op */ - type.t = VT_LLONG | VT_LONG; - if (bt1 == VT_LLONG) - type.t &= t1; - if (bt2 == VT_LLONG) - type.t &= t2; - /* convert to unsigned if it does not fit in a long long */ - if ((t1 & (VT_BTYPE | VT_UNSIGNED | VT_BITFIELD)) == (VT_LLONG | VT_UNSIGNED) || - (t2 & (VT_BTYPE | VT_UNSIGNED | VT_BITFIELD)) == (VT_LLONG | VT_UNSIGNED)) - type.t |= VT_UNSIGNED; - } else if (bt1 == VT_PTR || bt2 == VT_PTR) { - /* If one is a null ptr constant the result type - is the other. */ - if (is_null_pointer (vtop)) - type = type1; - else if (is_null_pointer (&sv)) - type = type2; - /* XXX: test pointer compatibility, C99 has more elaborate - rules here. */ - else - type = type1; - } else if (bt1 == VT_FUNC || bt2 == VT_FUNC) { - /* XXX: test function pointer compatibility */ - type = bt1 == VT_FUNC ? type1 : type2; - } else if (bt1 == VT_STRUCT || bt2 == VT_STRUCT) { - /* XXX: test structure compatibility */ - type = bt1 == VT_STRUCT ? type1 : type2; - } else if (bt1 == VT_VOID || bt2 == VT_VOID) { - /* NOTE: as an extension, we accept void on only one side */ - type.t = VT_VOID; - } else { - /* integer operations */ - type.t = VT_INT | (VT_LONG & (t1 | t2)); - /* convert to unsigned if it does not fit in an integer */ - if ((t1 & (VT_BTYPE | VT_UNSIGNED | VT_BITFIELD)) == (VT_INT | VT_UNSIGNED) || - (t2 & (VT_BTYPE | VT_UNSIGNED | VT_BITFIELD)) == (VT_INT | VT_UNSIGNED)) - type.t |= VT_UNSIGNED; - } - /* keep structs lvalue by transforming `(expr ? a : b)` to `*(expr ? &a : &b)` so - that `(expr ? a : b).mem` does not error with "lvalue expected" */ - islv = (vtop->r & VT_LVAL) && (sv.r & VT_LVAL) && VT_STRUCT == (type.t & VT_BTYPE); - islv &= c < 0; - - /* now we convert second operand */ - if (c != 1) { - gen_cast(&type); - if (islv) { - mk_pointer(&vtop->type); - gaddrof(); - } else if (VT_STRUCT == (vtop->type.t & VT_BTYPE)) - gaddrof(); - } - - rc = RC_INT; - if (is_float(type.t)) { - rc = RC_FLOAT; -#ifdef TCC_TARGET_X86_64 - if ((type.t & VT_BTYPE) == VT_LDOUBLE) { - rc = RC_ST0; - } -#endif - } else if ((type.t & VT_BTYPE) == VT_LLONG) { - /* for long longs, we use fixed registers to avoid having - to handle a complicated move */ - rc = RC_IRET; - } - - tt = r2 = 0; - if (c < 0) { - r2 = gv(rc); - tt = gjmp(0); - } - gsym(u); - - /* this is horrible, but we must also convert first - operand */ - if (c != 0) { - *vtop = sv; - gen_cast(&type); - if (islv) { - mk_pointer(&vtop->type); - gaddrof(); - } else if (VT_STRUCT == (vtop->type.t & VT_BTYPE)) - gaddrof(); - } - - if (c < 0) { - r1 = gv(rc); - move_reg(r2, r1, type.t); - vtop->r = r2; - gsym(tt); - if (islv) - indir(); - } - } - } -} - -static void expr_eq(void) -{ - int t; - - expr_cond(); - if (tok == '=' || - (tok >= TOK_A_MOD && tok <= TOK_A_DIV) || - tok == TOK_A_XOR || tok == TOK_A_OR || - tok == TOK_A_SHL || tok == TOK_A_SAR) { - test_lvalue(); - t = tok; - next(); - if (t == '=') { - expr_eq(); - } else { - vdup(); - expr_eq(); - gen_op(t & 0x7f); - } - vstore(); - } -} - -ST_FUNC void gexpr(void) -{ - while (1) { - expr_eq(); - if (tok != ',') - break; - vpop(); - next(); - } -} - -/* parse a constant expression and return value in vtop. */ -static void expr_const1(void) -{ - const_wanted++; - nocode_wanted++; - expr_cond(); - nocode_wanted--; - const_wanted--; -} - -/* parse an integer constant and return its value. */ -static inline int64_t expr_const64(void) -{ - int64_t c; - expr_const1(); - if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) != VT_CONST) - expect("constant expression"); - c = vtop->c.i; - vpop(); - return c; -} - -/* parse an integer constant and return its value. - Complain if it doesn't fit 32bit (signed or unsigned). */ -ST_FUNC int expr_const(void) -{ - int c; - int64_t wc = expr_const64(); - c = wc; - if (c != wc && (unsigned)c != wc) - tcc_error("constant exceeds 32 bit"); - return c; -} - -/* return the label token if current token is a label, otherwise - return zero */ -static int is_label(void) -{ - int last_tok; - - /* fast test first */ - if (tok < TOK_UIDENT) - return 0; - /* no need to save tokc because tok is an identifier */ - last_tok = tok; - next(); - if (tok == ':') { - return last_tok; - } else { - unget_tok(last_tok); - return 0; - } -} - -#ifndef TCC_TARGET_ARM64 -static void gfunc_return(CType *func_type) -{ - if ((func_type->t & VT_BTYPE) == VT_STRUCT) { - CType type, ret_type; - int ret_align, ret_nregs, regsize; - ret_nregs = gfunc_sret(func_type, func_var, &ret_type, - &ret_align, ®size); - if (0 == ret_nregs) { - /* if returning structure, must copy it to implicit - first pointer arg location */ - type = *func_type; - mk_pointer(&type); - vset(&type, VT_LOCAL | VT_LVAL, func_vc); - indir(); - vswap(); - /* copy structure value to pointer */ - vstore(); - } else { - /* returning structure packed into registers */ - int r, size, addr, align; - size = type_size(func_type,&align); - if ((vtop->r != (VT_LOCAL | VT_LVAL) || - (vtop->c.i & (ret_align-1))) - && (align & (ret_align-1))) { - loc = (loc - size) & -ret_align; - addr = loc; - type = *func_type; - vset(&type, VT_LOCAL | VT_LVAL, addr); - vswap(); - vstore(); - vpop(); - vset(&ret_type, VT_LOCAL | VT_LVAL, addr); - } - vtop->type = ret_type; - if (is_float(ret_type.t)) - r = rc_fret(ret_type.t); - else - r = RC_IRET; - - if (ret_nregs == 1) - gv(r); - else { - for (;;) { - vdup(); - gv(r); - vpop(); - if (--ret_nregs == 0) - break; - /* We assume that when a structure is returned in multiple - registers, their classes are consecutive values of the - suite s(n) = 2^n */ - r <<= 1; - vtop->c.i += regsize; - } - } - } - } else if (is_float(func_type->t)) { - gv(rc_fret(func_type->t)); - } else { - gv(RC_IRET); - } - vtop--; /* NOT vpop() because on x86 it would flush the fp stack */ -} -#endif - -static int case_cmp(const void *pa, const void *pb) -{ - int64_t a = (*(struct case_t**) pa)->v1; - int64_t b = (*(struct case_t**) pb)->v1; - return a < b ? -1 : a > b; -} - -static void gcase(struct case_t **base, int len, int *bsym) -{ - struct case_t *p; - int e; - int ll = (vtop->type.t & VT_BTYPE) == VT_LLONG; - gv(RC_INT); - while (len > 4) { - /* binary search */ - p = base[len/2]; - vdup(); - if (ll) - vpushll(p->v2); - else - vpushi(p->v2); - gen_op(TOK_LE); - e = gtst(1, 0); - vdup(); - if (ll) - vpushll(p->v1); - else - vpushi(p->v1); - gen_op(TOK_GE); - gtst_addr(0, p->sym); /* v1 <= x <= v2 */ - /* x < v1 */ - gcase(base, len/2, bsym); - if (cur_switch->def_sym) - gjmp_addr(cur_switch->def_sym); - else - *bsym = gjmp(*bsym); - /* x > v2 */ - gsym(e); - e = len/2 + 1; - base += e; len -= e; - } - /* linear scan */ - while (len--) { - p = *base++; - vdup(); - if (ll) - vpushll(p->v2); - else - vpushi(p->v2); - if (p->v1 == p->v2) { - gen_op(TOK_EQ); - gtst_addr(0, p->sym); - } else { - gen_op(TOK_LE); - e = gtst(1, 0); - vdup(); - if (ll) - vpushll(p->v1); - else - vpushi(p->v1); - gen_op(TOK_GE); - gtst_addr(0, p->sym); - gsym(e); - } - } -} - -static void block(int *bsym, int *csym, int is_expr) -{ - int a, b, c, d, cond; - Sym *s; - - /* generate line number info */ - if (tcc_state->do_debug) - tcc_debug_line(tcc_state); - - if (is_expr) { - /* default return value is (void) */ - vpushi(0); - vtop->type.t = VT_VOID; - } - - if (tok == TOK_IF) { - /* if test */ - int saved_nocode_wanted = nocode_wanted; - next(); - skip('('); - gexpr(); - skip(')'); - cond = condition_3way(); - if (cond == 1) - a = 0, vpop(); - else - a = gvtst(1, 0); - if (cond == 0) - nocode_wanted |= 0x20000000; - block(bsym, csym, 0); - if (cond != 1) - nocode_wanted = saved_nocode_wanted; - c = tok; - if (c == TOK_ELSE) { - next(); - d = gjmp(0); - gsym(a); - if (cond == 1) - nocode_wanted |= 0x20000000; - block(bsym, csym, 0); - gsym(d); /* patch else jmp */ - if (cond != 0) - nocode_wanted = saved_nocode_wanted; - } else - gsym(a); - } else if (tok == TOK_WHILE) { - int saved_nocode_wanted; - nocode_wanted &= ~0x20000000; - next(); - d = ind; - vla_sp_restore(); - skip('('); - gexpr(); - skip(')'); - a = gvtst(1, 0); - b = 0; - ++local_scope; - saved_nocode_wanted = nocode_wanted; - block(&a, &b, 0); - nocode_wanted = saved_nocode_wanted; - --local_scope; - gjmp_addr(d); - gsym(a); - gsym_addr(b, d); - } else if (tok == '{') { - Sym *llabel; - int block_vla_sp_loc = vla_sp_loc, saved_vlas_in_scope = vlas_in_scope; - - next(); - /* record local declaration stack position */ - s = local_stack; - llabel = local_label_stack; - ++local_scope; - - /* handle local labels declarations */ - if (tok == TOK_LABEL) { - next(); - for(;;) { - if (tok < TOK_UIDENT) - expect("label identifier"); - label_push(&local_label_stack, tok, LABEL_DECLARED); - next(); - if (tok == ',') { - next(); - } else { - skip(';'); - break; - } - } - } - while (tok != '}') { - if ((a = is_label())) - unget_tok(a); - else - decl(VT_LOCAL); - if (tok != '}') { - if (is_expr) - vpop(); - block(bsym, csym, is_expr); - } - } - /* pop locally defined labels */ - label_pop(&local_label_stack, llabel, is_expr); - /* pop locally defined symbols */ - --local_scope; - /* In the is_expr case (a statement expression is finished here), - vtop might refer to symbols on the local_stack. Either via the - type or via vtop->sym. We can't pop those nor any that in turn - might be referred to. To make it easier we don't roll back - any symbols in that case; some upper level call to block() will - do that. We do have to remove such symbols from the lookup - tables, though. sym_pop will do that. */ - sym_pop(&local_stack, s, is_expr); - - /* Pop VLA frames and restore stack pointer if required */ - if (vlas_in_scope > saved_vlas_in_scope) { - vla_sp_loc = saved_vlas_in_scope ? block_vla_sp_loc : vla_sp_root_loc; - vla_sp_restore(); - } - vlas_in_scope = saved_vlas_in_scope; - - next(); - } else if (tok == TOK_RETURN) { - next(); - if (tok != ';') { - gexpr(); - gen_assign_cast(&func_vt); - if ((func_vt.t & VT_BTYPE) == VT_VOID) - vtop--; - else - gfunc_return(&func_vt); - } - skip(';'); - /* jump unless last stmt in top-level block */ - if (tok != '}' || local_scope != 1) - rsym = gjmp(rsym); - nocode_wanted |= 0x20000000; - } else if (tok == TOK_BREAK) { - /* compute jump */ - if (!bsym) - tcc_error("cannot break"); - *bsym = gjmp(*bsym); - next(); - skip(';'); - nocode_wanted |= 0x20000000; - } else if (tok == TOK_CONTINUE) { - /* compute jump */ - if (!csym) - tcc_error("cannot continue"); - vla_sp_restore_root(); - *csym = gjmp(*csym); - next(); - skip(';'); - } else if (tok == TOK_FOR) { - int e; - int saved_nocode_wanted; - nocode_wanted &= ~0x20000000; - next(); - skip('('); - s = local_stack; - ++local_scope; - if (tok != ';') { - /* c99 for-loop init decl? */ - if (!decl0(VT_LOCAL, 1, NULL)) { - /* no, regular for-loop init expr */ - gexpr(); - vpop(); - } - } - skip(';'); - d = ind; - c = ind; - vla_sp_restore(); - a = 0; - b = 0; - if (tok != ';') { - gexpr(); - a = gvtst(1, 0); - } - skip(';'); - if (tok != ')') { - e = gjmp(0); - c = ind; - vla_sp_restore(); - gexpr(); - vpop(); - gjmp_addr(d); - gsym(e); - } - skip(')'); - saved_nocode_wanted = nocode_wanted; - block(&a, &b, 0); - nocode_wanted = saved_nocode_wanted; - gjmp_addr(c); - gsym(a); - gsym_addr(b, c); - --local_scope; - sym_pop(&local_stack, s, 0); - - } else - if (tok == TOK_DO) { - int saved_nocode_wanted; - nocode_wanted &= ~0x20000000; - next(); - a = 0; - b = 0; - d = ind; - vla_sp_restore(); - saved_nocode_wanted = nocode_wanted; - block(&a, &b, 0); - skip(TOK_WHILE); - skip('('); - gsym(b); - gexpr(); - c = gvtst(0, 0); - gsym_addr(c, d); - nocode_wanted = saved_nocode_wanted; - skip(')'); - gsym(a); - skip(';'); - } else - if (tok == TOK_SWITCH) { - struct switch_t *saved, sw; - int saved_nocode_wanted = nocode_wanted; - SValue switchval; - next(); - skip('('); - gexpr(); - skip(')'); - switchval = *vtop--; - a = 0; - b = gjmp(0); /* jump to first case */ - sw.p = NULL; sw.n = 0; sw.def_sym = 0; - saved = cur_switch; - cur_switch = &sw; - block(&a, csym, 0); - nocode_wanted = saved_nocode_wanted; - a = gjmp(a); /* add implicit break */ - /* case lookup */ - gsym(b); - qsort(sw.p, sw.n, sizeof(void*), case_cmp); - for (b = 1; b < sw.n; b++) - if (sw.p[b - 1]->v2 >= sw.p[b]->v1) - tcc_error("duplicate case value"); - /* Our switch table sorting is signed, so the compared - value needs to be as well when it's 64bit. */ - if ((switchval.type.t & VT_BTYPE) == VT_LLONG) - switchval.type.t &= ~VT_UNSIGNED; - vpushv(&switchval); - gcase(sw.p, sw.n, &a); - vpop(); - if (sw.def_sym) - gjmp_addr(sw.def_sym); - dynarray_reset(&sw.p, &sw.n); - cur_switch = saved; - /* break label */ - gsym(a); - } else - if (tok == TOK_CASE) { - struct case_t *cr = tcc_malloc(sizeof(struct case_t)); - if (!cur_switch) - expect("switch"); - nocode_wanted &= ~0x20000000; - next(); - cr->v1 = cr->v2 = expr_const64(); - if (gnu_ext && tok == TOK_DOTS) { - next(); - cr->v2 = expr_const64(); - if (cr->v2 < cr->v1) - tcc_warning("empty case range"); - } - cr->sym = ind; - dynarray_add(&cur_switch->p, &cur_switch->n, cr); - skip(':'); - is_expr = 0; - goto block_after_label; - } else - if (tok == TOK_DEFAULT) { - next(); - skip(':'); - if (!cur_switch) - expect("switch"); - if (cur_switch->def_sym) - tcc_error("too many 'default'"); - cur_switch->def_sym = ind; - is_expr = 0; - goto block_after_label; - } else - if (tok == TOK_GOTO) { - next(); - if (tok == '*' && gnu_ext) { - /* computed goto */ - next(); - gexpr(); - if ((vtop->type.t & VT_BTYPE) != VT_PTR) - expect("pointer"); - ggoto(); - } else if (tok >= TOK_UIDENT) { - s = label_find(tok); - /* put forward definition if needed */ - if (!s) { - s = label_push(&global_label_stack, tok, LABEL_FORWARD); - } else { - if (s->r == LABEL_DECLARED) - s->r = LABEL_FORWARD; - } - vla_sp_restore_root(); - if (s->r & LABEL_FORWARD) - s->jnext = gjmp(s->jnext); - else - gjmp_addr(s->jnext); - next(); - } else { - expect("label identifier"); - } - skip(';'); - } else if (tok == TOK_ASM1 || tok == TOK_ASM2 || tok == TOK_ASM3) { - asm_instr(); - } else { - b = is_label(); - if (b) { - /* label case */ - next(); - s = label_find(b); - if (s) { - if (s->r == LABEL_DEFINED) - tcc_error("duplicate label '%s'", get_tok_str(s->v, NULL)); - gsym(s->jnext); - s->r = LABEL_DEFINED; - } else { - s = label_push(&global_label_stack, b, LABEL_DEFINED); - } - s->jnext = ind; - vla_sp_restore(); - /* we accept this, but it is a mistake */ - block_after_label: - nocode_wanted &= ~0x20000000; - if (tok == '}') { - tcc_warning("deprecated use of label at end of compound statement"); - } else { - if (is_expr) - vpop(); - block(bsym, csym, is_expr); - } - } else { - /* expression case */ - if (tok != ';') { - if (is_expr) { - vpop(); - gexpr(); - } else { - gexpr(); - vpop(); - } - } - skip(';'); - } - } -} - -/* This skips over a stream of tokens containing balanced {} and () - pairs, stopping at outer ',' ';' and '}' (or matching '}' if we started - with a '{'). If STR then allocates and stores the skipped tokens - in *STR. This doesn't check if () and {} are nested correctly, - i.e. "({)}" is accepted. */ -static void skip_or_save_block(TokenString **str) -{ - int braces = tok == '{'; - int level = 0; - if (str) - *str = tok_str_alloc(); - - while ((level > 0 || (tok != '}' && tok != ',' && tok != ';' && tok != ')'))) { - int t; - if (tok == TOK_EOF) { - if (str || level > 0) - tcc_error("unexpected end of file"); - else - break; - } - if (str) - tok_str_add_tok(*str); - t = tok; - next(); - if (t == '{' || t == '(') { - level++; - } else if (t == '}' || t == ')') { - level--; - if (level == 0 && braces && t == '}') - break; - } - } - if (str) { - tok_str_add(*str, -1); - tok_str_add(*str, 0); - } -} - -#define EXPR_CONST 1 -#define EXPR_ANY 2 - -static void parse_init_elem(int expr_type) -{ - int saved_global_expr; - switch(expr_type) { - case EXPR_CONST: - /* compound literals must be allocated globally in this case */ - saved_global_expr = global_expr; - global_expr = 1; - expr_const1(); - global_expr = saved_global_expr; - /* NOTE: symbols are accepted, as well as lvalue for anon symbols - (compound literals). */ - if (((vtop->r & (VT_VALMASK | VT_LVAL)) != VT_CONST - && ((vtop->r & (VT_SYM|VT_LVAL)) != (VT_SYM|VT_LVAL) - || vtop->sym->v < SYM_FIRST_ANOM)) -#ifdef TCC_TARGET_PE - || ((vtop->r & VT_SYM) && vtop->sym->a.dllimport) -#endif - ) - tcc_error("initializer element is not constant"); - break; - case EXPR_ANY: - expr_eq(); - break; - } -} - -/* put zeros for variable based init */ -static void init_putz(Section *sec, unsigned long c, int size) -{ - if (sec) { - /* nothing to do because globals are already set to zero */ - } else { - vpush_global_sym(&func_old_type, TOK_memset); - vseti(VT_LOCAL, c); -#ifdef TCC_TARGET_ARM - vpushs(size); - vpushi(0); -#else - vpushi(0); - vpushs(size); -#endif - gfunc_call(3); - } -} - -/* t is the array or struct type. c is the array or struct - address. cur_field is the pointer to the current - field, for arrays the 'c' member contains the current start - index. 'size_only' is true if only size info is needed (only used - in arrays). al contains the already initialized length of the - current container (starting at c). This returns the new length of that. */ -static int decl_designator(CType *type, Section *sec, unsigned long c, - Sym **cur_field, int size_only, int al) -{ - Sym *s, *f; - int index, index_last, align, l, nb_elems, elem_size; - unsigned long corig = c; - - elem_size = 0; - nb_elems = 1; - if (gnu_ext && (l = is_label()) != 0) - goto struct_field; - /* NOTE: we only support ranges for last designator */ - while (nb_elems == 1 && (tok == '[' || tok == '.')) { - if (tok == '[') { - if (!(type->t & VT_ARRAY)) - expect("array type"); - next(); - index = index_last = expr_const(); - if (tok == TOK_DOTS && gnu_ext) { - next(); - index_last = expr_const(); - } - skip(']'); - s = type->ref; - if (index < 0 || (s->c >= 0 && index_last >= s->c) || - index_last < index) - tcc_error("invalid index"); - if (cur_field) - (*cur_field)->c = index_last; - type = pointed_type(type); - elem_size = type_size(type, &align); - c += index * elem_size; - nb_elems = index_last - index + 1; - } else { - next(); - l = tok; - struct_field: - next(); - if ((type->t & VT_BTYPE) != VT_STRUCT) - expect("struct/union type"); - f = find_field(type, l); - if (!f) - expect("field"); - if (cur_field) - *cur_field = f; - type = &f->type; - c += f->c; - } - cur_field = NULL; - } - if (!cur_field) { - if (tok == '=') { - next(); - } else if (!gnu_ext) { - expect("="); - } - } else { - if (type->t & VT_ARRAY) { - index = (*cur_field)->c; - if (type->ref->c >= 0 && index >= type->ref->c) - tcc_error("index too large"); - type = pointed_type(type); - c += index * type_size(type, &align); - } else { - f = *cur_field; - while (f && (f->v & SYM_FIRST_ANOM) && (f->type.t & VT_BITFIELD)) - *cur_field = f = f->next; - if (!f) - tcc_error("too many field init"); - type = &f->type; - c += f->c; - } - } - /* must put zero in holes (note that doing it that way - ensures that it even works with designators) */ - if (!size_only && c - corig > al) - init_putz(sec, corig + al, c - corig - al); - decl_initializer(type, sec, c, 0, size_only); - - /* XXX: make it more general */ - if (!size_only && nb_elems > 1) { - unsigned long c_end; - uint8_t *src, *dst; - int i; - - if (!sec) { - vset(type, VT_LOCAL|VT_LVAL, c); - for (i = 1; i < nb_elems; i++) { - vset(type, VT_LOCAL|VT_LVAL, c + elem_size * i); - vswap(); - vstore(); - } - vpop(); - } else if (!NODATA_WANTED) { - c_end = c + nb_elems * elem_size; - if (c_end > sec->data_allocated) - section_realloc(sec, c_end); - src = sec->data + c; - dst = src; - for(i = 1; i < nb_elems; i++) { - dst += elem_size; - memcpy(dst, src, elem_size); - } - } - } - c += nb_elems * type_size(type, &align); - if (c - corig > al) - al = c - corig; - return al; -} - -/* store a value or an expression directly in global data or in local array */ -static void init_putv(CType *type, Section *sec, unsigned long c) -{ - int bt; - void *ptr; - CType dtype; - - dtype = *type; - dtype.t &= ~VT_CONSTANT; /* need to do that to avoid false warning */ - - if (sec) { - int size, align; - /* XXX: not portable */ - /* XXX: generate error if incorrect relocation */ - gen_assign_cast(&dtype); - bt = type->t & VT_BTYPE; - - if ((vtop->r & VT_SYM) - && bt != VT_PTR - && bt != VT_FUNC - && (bt != (PTR_SIZE == 8 ? VT_LLONG : VT_INT) - || (type->t & VT_BITFIELD)) - && !((vtop->r & VT_CONST) && vtop->sym->v >= SYM_FIRST_ANOM) - ) - tcc_error("initializer element is not computable at load time"); - - if (NODATA_WANTED) { - vtop--; - return; - } - - size = type_size(type, &align); - section_reserve(sec, c + size); - ptr = sec->data + c; - - /* XXX: make code faster ? */ - if ((vtop->r & (VT_SYM|VT_CONST)) == (VT_SYM|VT_CONST) && - vtop->sym->v >= SYM_FIRST_ANOM && - /* XXX This rejects compound literals like - '(void *){ptr}'. The problem is that '&sym' is - represented the same way, which would be ruled out - by the SYM_FIRST_ANOM check above, but also '"string"' - in 'char *p = "string"' is represented the same - with the type being VT_PTR and the symbol being an - anonymous one. That is, there's no difference in vtop - between '(void *){x}' and '&(void *){x}'. Ignore - pointer typed entities here. Hopefully no real code - will every use compound literals with scalar type. */ - (vtop->type.t & VT_BTYPE) != VT_PTR) { - /* These come from compound literals, memcpy stuff over. */ - Section *ssec; - ElfSym *esym; - ElfW_Rel *rel; - esym = elfsym(vtop->sym); - ssec = tcc_state->sections[esym->st_shndx]; - memmove (ptr, ssec->data + esym->st_value, size); - if (ssec->reloc) { - /* We need to copy over all memory contents, and that - includes relocations. Use the fact that relocs are - created it order, so look from the end of relocs - until we hit one before the copied region. */ - int num_relocs = ssec->reloc->data_offset / sizeof(*rel); - rel = (ElfW_Rel*)(ssec->reloc->data + ssec->reloc->data_offset); - while (num_relocs--) { - rel--; - if (rel->r_offset >= esym->st_value + size) - continue; - if (rel->r_offset < esym->st_value) - break; - /* Note: if the same fields are initialized multiple - times (possible with designators) then we possibly - add multiple relocations for the same offset here. - That would lead to wrong code, the last reloc needs - to win. We clean this up later after the whole - initializer is parsed. */ - put_elf_reloca(symtab_section, sec, - c + rel->r_offset - esym->st_value, - ELFW(R_TYPE)(rel->r_info), - ELFW(R_SYM)(rel->r_info), -#if PTR_SIZE == 8 - rel->r_addend -#else - 0 -#endif - ); - } - } - } else { - if (type->t & VT_BITFIELD) { - int bit_pos, bit_size, bits, n; - unsigned char *p, v, m; - bit_pos = BIT_POS(vtop->type.t); - bit_size = BIT_SIZE(vtop->type.t); - p = (unsigned char*)ptr + (bit_pos >> 3); - bit_pos &= 7, bits = 0; - while (bit_size) { - n = 8 - bit_pos; - if (n > bit_size) - n = bit_size; - v = vtop->c.i >> bits << bit_pos; - m = ((1 << n) - 1) << bit_pos; - *p = (*p & ~m) | (v & m); - bits += n, bit_size -= n, bit_pos = 0, ++p; - } - } else - switch(bt) { - /* XXX: when cross-compiling we assume that each type has the - same representation on host and target, which is likely to - be wrong in the case of long double */ - case VT_BOOL: - vtop->c.i = vtop->c.i != 0; - case VT_BYTE: - *(char *)ptr |= vtop->c.i; - break; - case VT_SHORT: - *(short *)ptr |= vtop->c.i; - break; - case VT_FLOAT: - *(float*)ptr = vtop->c.f; - break; - case VT_DOUBLE: - *(double *)ptr = vtop->c.d; - break; - case VT_LDOUBLE: -#if defined TCC_IS_NATIVE_387 - if (sizeof (long double) >= 10) /* zero pad ten-byte LD */ - memcpy(ptr, &vtop->c.ld, 10); -#ifdef __TINYC__ - else if (sizeof (long double) == sizeof (double)) - __asm__("fldl %1\nfstpt %0\n" : "=m" (*ptr) : "m" (vtop->c.ld)); -#endif - else if (vtop->c.ld == 0.0) - ; - else -#endif - if (sizeof(long double) == LDOUBLE_SIZE) - *(long double*)ptr = vtop->c.ld; - else if (sizeof(double) == LDOUBLE_SIZE) - *(double *)ptr = (double)vtop->c.ld; - else - tcc_error("can't cross compile long double constants"); - break; -#if PTR_SIZE != 8 - case VT_LLONG: - *(long long *)ptr |= vtop->c.i; - break; -#else - case VT_LLONG: -#endif - case VT_PTR: - { - addr_t val = vtop->c.i; -#if PTR_SIZE == 8 - if (vtop->r & VT_SYM) - greloca(sec, vtop->sym, c, R_DATA_PTR, val); - else - *(addr_t *)ptr |= val; -#else - if (vtop->r & VT_SYM) - greloc(sec, vtop->sym, c, R_DATA_PTR); - *(addr_t *)ptr |= val; -#endif - break; - } - default: - { - int val = vtop->c.i; -#if PTR_SIZE == 8 - if (vtop->r & VT_SYM) - greloca(sec, vtop->sym, c, R_DATA_PTR, val); - else - *(int *)ptr |= val; -#else - if (vtop->r & VT_SYM) - greloc(sec, vtop->sym, c, R_DATA_PTR); - *(int *)ptr |= val; -#endif - break; - } - } - } - vtop--; - } else { - vset(&dtype, VT_LOCAL|VT_LVAL, c); - vswap(); - vstore(); - vpop(); - } -} - -/* 't' contains the type and storage info. 'c' is the offset of the - object in section 'sec'. If 'sec' is NULL, it means stack based - allocation. 'first' is true if array '{' must be read (multi - dimension implicit array init handling). 'size_only' is true if - size only evaluation is wanted (only for arrays). */ -static void decl_initializer(CType *type, Section *sec, unsigned long c, - int first, int size_only) -{ - int len, n, no_oblock, nb, i; - int size1, align1; - int have_elem; - Sym *s, *f; - Sym indexsym; - CType *t1; - - /* If we currently are at an '}' or ',' we have read an initializer - element in one of our callers, and not yet consumed it. */ - have_elem = tok == '}' || tok == ','; - if (!have_elem && tok != '{' && - /* In case of strings we have special handling for arrays, so - don't consume them as initializer value (which would commit them - to some anonymous symbol). */ - tok != TOK_LSTR && tok != TOK_STR && - !size_only) { - parse_init_elem(!sec ? EXPR_ANY : EXPR_CONST); - have_elem = 1; - } - - if (have_elem && - !(type->t & VT_ARRAY) && - /* Use i_c_parameter_t, to strip toplevel qualifiers. - The source type might have VT_CONSTANT set, which is - of course assignable to non-const elements. */ - is_compatible_unqualified_types(type, &vtop->type)) { - init_putv(type, sec, c); - } else if (type->t & VT_ARRAY) { - s = type->ref; - n = s->c; - t1 = pointed_type(type); - size1 = type_size(t1, &align1); - - no_oblock = 1; - if ((first && tok != TOK_LSTR && tok != TOK_STR) || - tok == '{') { - if (tok != '{') - tcc_error("character array initializer must be a literal," - " optionally enclosed in braces"); - skip('{'); - no_oblock = 0; - } - - /* only parse strings here if correct type (otherwise: handle - them as ((w)char *) expressions */ - if ((tok == TOK_LSTR && -#ifdef TCC_TARGET_PE - (t1->t & VT_BTYPE) == VT_SHORT && (t1->t & VT_UNSIGNED) -#else - (t1->t & VT_BTYPE) == VT_INT -#endif - ) || (tok == TOK_STR && (t1->t & VT_BTYPE) == VT_BYTE)) { - len = 0; - while (tok == TOK_STR || tok == TOK_LSTR) { - int cstr_len, ch; - - /* compute maximum number of chars wanted */ - if (tok == TOK_STR) - cstr_len = tokc.str.size; - else - cstr_len = tokc.str.size / sizeof(nwchar_t); - cstr_len--; - nb = cstr_len; - if (n >= 0 && nb > (n - len)) - nb = n - len; - if (!size_only) { - if (cstr_len > nb) - tcc_warning("initializer-string for array is too long"); - /* in order to go faster for common case (char - string in global variable, we handle it - specifically */ - if (sec && tok == TOK_STR && size1 == 1) { - if (!NODATA_WANTED) - memcpy(sec->data + c + len, tokc.str.data, nb); - } else { - for(i=0;it & VT_ARRAY) { - ++indexsym.c; - /* special test for multi dimensional arrays (may not - be strictly correct if designators are used at the - same time) */ - if (no_oblock && len >= n*size1) - break; - } else { - if (s->type.t == VT_UNION) - f = NULL; - else - f = f->next; - if (no_oblock && f == NULL) - break; - } - - if (tok == '}') - break; - skip(','); - } - } - /* put zeros at the end */ - if (!size_only && len < n*size1) - init_putz(sec, c + len, n*size1 - len); - if (!no_oblock) - skip('}'); - /* patch type size if needed, which happens only for array types */ - if (n < 0) - s->c = size1 == 1 ? len : ((len + size1 - 1)/size1); - } else if ((type->t & VT_BTYPE) == VT_STRUCT) { - size1 = 1; - no_oblock = 1; - if (first || tok == '{') { - skip('{'); - no_oblock = 0; - } - s = type->ref; - f = s->next; - n = s->c; - goto do_init_list; - } else if (tok == '{') { - next(); - decl_initializer(type, sec, c, first, size_only); - skip('}'); - } else if (size_only) { - /* If we supported only ISO C we wouldn't have to accept calling - this on anything than an array size_only==1 (and even then - only on the outermost level, so no recursion would be needed), - because initializing a flex array member isn't supported. - But GNU C supports it, so we need to recurse even into - subfields of structs and arrays when size_only is set. */ - /* just skip expression */ - skip_or_save_block(NULL); - } else { - if (!have_elem) { - /* This should happen only when we haven't parsed - the init element above for fear of committing a - string constant to memory too early. */ - if (tok != TOK_STR && tok != TOK_LSTR) - expect("string constant"); - parse_init_elem(!sec ? EXPR_ANY : EXPR_CONST); - } - init_putv(type, sec, c); - } -} - -/* parse an initializer for type 't' if 'has_init' is non zero, and - allocate space in local or global data space ('r' is either - VT_LOCAL or VT_CONST). If 'v' is non zero, then an associated - variable 'v' of scope 'scope' is declared before initializers - are parsed. If 'v' is zero, then a reference to the new object - is put in the value stack. If 'has_init' is 2, a special parsing - is done to handle string constants. */ -static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, - int has_init, int v, int scope) -{ - int size, align, addr; - TokenString *init_str = NULL; - - Section *sec; - Sym *flexible_array; - Sym *sym = NULL; - int saved_nocode_wanted = nocode_wanted; -#ifdef CONFIG_TCC_BCHECK - int bcheck = tcc_state->do_bounds_check && !NODATA_WANTED; -#endif - - if (type->t & VT_STATIC) - nocode_wanted |= NODATA_WANTED ? 0x40000000 : 0x80000000; - - flexible_array = NULL; - if ((type->t & VT_BTYPE) == VT_STRUCT) { - Sym *field = type->ref->next; - if (field) { - while (field->next) - field = field->next; - if (field->type.t & VT_ARRAY && field->type.ref->c < 0) - flexible_array = field; - } - } - - size = type_size(type, &align); - /* If unknown size, we must evaluate it before - evaluating initializers because - initializers can generate global data too - (e.g. string pointers or ISOC99 compound - literals). It also simplifies local - initializers handling */ - if (size < 0 || (flexible_array && has_init)) { - if (!has_init) - tcc_error("unknown type size"); - /* get all init string */ - if (has_init == 2) { - init_str = tok_str_alloc(); - /* only get strings */ - while (tok == TOK_STR || tok == TOK_LSTR) { - tok_str_add_tok(init_str); - next(); - } - tok_str_add(init_str, -1); - tok_str_add(init_str, 0); - } else { - skip_or_save_block(&init_str); - } - unget_tok(0); - - /* compute size */ - begin_macro(init_str, 1); - next(); - decl_initializer(type, NULL, 0, 1, 1); - /* prepare second initializer parsing */ - macro_ptr = init_str->str; - next(); - - /* if still unknown size, error */ - size = type_size(type, &align); - if (size < 0) - tcc_error("unknown type size"); - } - /* If there's a flex member and it was used in the initializer - adjust size. */ - if (flexible_array && - flexible_array->type.ref->c > 0) - size += flexible_array->type.ref->c - * pointed_size(&flexible_array->type); - /* take into account specified alignment if bigger */ - if (ad->a.aligned) { - int speca = 1 << (ad->a.aligned - 1); - if (speca > align) - align = speca; - } else if (ad->a.packed) { - align = 1; - } - - if (NODATA_WANTED) - size = 0, align = 1; - - if ((r & VT_VALMASK) == VT_LOCAL) { - sec = NULL; -#ifdef CONFIG_TCC_BCHECK - if (bcheck && (type->t & VT_ARRAY)) { - loc--; - } -#endif - loc = (loc - size) & -align; - addr = loc; -#ifdef CONFIG_TCC_BCHECK - /* handles bounds */ - /* XXX: currently, since we do only one pass, we cannot track - '&' operators, so we add only arrays */ - if (bcheck && (type->t & VT_ARRAY)) { - addr_t *bounds_ptr; - /* add padding between regions */ - loc--; - /* then add local bound info */ - bounds_ptr = section_ptr_add(lbounds_section, 2 * sizeof(addr_t)); - bounds_ptr[0] = addr; - bounds_ptr[1] = size; - } -#endif - if (v) { - /* local variable */ -#ifdef CONFIG_TCC_ASM - if (ad->asm_label) { - int reg = asm_parse_regvar(ad->asm_label); - if (reg >= 0) - r = (r & ~VT_VALMASK) | reg; - } -#endif - sym = sym_push(v, type, r, addr); - sym->a = ad->a; - } else { - /* push local reference */ - vset(type, r, addr); - } - } else { - if (v && scope == VT_CONST) { - /* see if the symbol was already defined */ - sym = sym_find(v); - if (sym) { - patch_storage(sym, ad, type); - /* we accept several definitions of the same global variable. */ - if (!has_init && sym->c && elfsym(sym)->st_shndx != SHN_UNDEF) - goto no_alloc; - } - } - - /* allocate symbol in corresponding section */ - sec = ad->section; - if (!sec) { - if (has_init) - sec = data_section; - else if (tcc_state->nocommon) - sec = bss_section; - } - - if (sec) { - addr = section_add(sec, size, align); -#ifdef CONFIG_TCC_BCHECK - /* add padding if bound check */ - if (bcheck) - section_add(sec, 1, 1); -#endif - } else { - addr = align; /* SHN_COMMON is special, symbol value is align */ - sec = common_section; - } - - if (v) { - if (!sym) { - sym = sym_push(v, type, r | VT_SYM, 0); - patch_storage(sym, ad, NULL); - } - /* Local statics have a scope until now (for - warnings), remove it here. */ - sym->sym_scope = 0; - /* update symbol definition */ - put_extern_sym(sym, sec, addr, size); - } else { - /* push global reference */ - sym = get_sym_ref(type, sec, addr, size); - vpushsym(type, sym); - vtop->r |= r; - } - -#ifdef CONFIG_TCC_BCHECK - /* handles bounds now because the symbol must be defined - before for the relocation */ - if (bcheck) { - addr_t *bounds_ptr; - - greloca(bounds_section, sym, bounds_section->data_offset, R_DATA_PTR, 0); - /* then add global bound info */ - bounds_ptr = section_ptr_add(bounds_section, 2 * sizeof(addr_t)); - bounds_ptr[0] = 0; /* relocated */ - bounds_ptr[1] = size; - } -#endif - } - - if (type->t & VT_VLA) { - int a; - - if (NODATA_WANTED) - goto no_alloc; - - /* save current stack pointer */ - if (vlas_in_scope == 0) { - if (vla_sp_root_loc == -1) - vla_sp_root_loc = (loc -= PTR_SIZE); - gen_vla_sp_save(vla_sp_root_loc); - } - - vla_runtime_type_size(type, &a); - gen_vla_alloc(type, a); -#if defined TCC_TARGET_PE && defined TCC_TARGET_X86_64 - /* on _WIN64, because of the function args scratch area, the - result of alloca differs from RSP and is returned in RAX. */ - gen_vla_result(addr), addr = (loc -= PTR_SIZE); -#endif - gen_vla_sp_save(addr); - vla_sp_loc = addr; - vlas_in_scope++; - - } else if (has_init) { - size_t oldreloc_offset = 0; - if (sec && sec->reloc) - oldreloc_offset = sec->reloc->data_offset; - decl_initializer(type, sec, addr, 1, 0); - if (sec && sec->reloc) - squeeze_multi_relocs(sec, oldreloc_offset); - /* patch flexible array member size back to -1, */ - /* for possible subsequent similar declarations */ - if (flexible_array) - flexible_array->type.ref->c = -1; - } - - no_alloc: - /* restore parse state if needed */ - if (init_str) { - end_macro(); - next(); - } - - nocode_wanted = saved_nocode_wanted; -} - -/* parse a function defined by symbol 'sym' and generate its code in - 'cur_text_section' */ -static void gen_function(Sym *sym) -{ - nocode_wanted = 0; - ind = cur_text_section->data_offset; - /* NOTE: we patch the symbol size later */ - put_extern_sym(sym, cur_text_section, ind, 0); - funcname = get_tok_str(sym->v, NULL); - func_ind = ind; - /* Initialize VLA state */ - vla_sp_loc = -1; - vla_sp_root_loc = -1; - /* put debug symbol */ - tcc_debug_funcstart(tcc_state, sym); - /* push a dummy symbol to enable local sym storage */ - sym_push2(&local_stack, SYM_FIELD, 0, 0); - local_scope = 1; /* for function parameters */ - gfunc_prolog(&sym->type); - local_scope = 0; - rsym = 0; - block(NULL, NULL, 0); - nocode_wanted = 0; - gsym(rsym); - gfunc_epilog(); - cur_text_section->data_offset = ind; - label_pop(&global_label_stack, NULL, 0); - /* reset local stack */ - local_scope = 0; - sym_pop(&local_stack, NULL, 0); - /* end of function */ - /* patch symbol size */ - elfsym(sym)->st_size = ind - func_ind; - tcc_debug_funcend(tcc_state, ind - func_ind); - /* It's better to crash than to generate wrong code */ - cur_text_section = NULL; - funcname = ""; /* for safety */ - func_vt.t = VT_VOID; /* for safety */ - func_var = 0; /* for safety */ - ind = 0; /* for safety */ - nocode_wanted = 0x80000000; - check_vstack(); -} - -static void gen_inline_functions(TCCState *s) -{ - Sym *sym; - int inline_generated, i, ln; - struct InlineFunc *fn; - - ln = file->line_num; - /* iterate while inline function are referenced */ - do { - inline_generated = 0; - for (i = 0; i < s->nb_inline_fns; ++i) { - fn = s->inline_fns[i]; - sym = fn->sym; - if (sym && sym->c) { - /* the function was used: generate its code and - convert it to a normal function */ - fn->sym = NULL; - if (file) - pstrcpy(file->filename, sizeof file->filename, fn->filename); - sym->type.t &= ~VT_INLINE; - - begin_macro(fn->func_str, 1); - next(); - cur_text_section = text_section; - gen_function(sym); - end_macro(); - - inline_generated = 1; - } - } - } while (inline_generated); - file->line_num = ln; -} - -ST_FUNC void free_inline_functions(TCCState *s) -{ - int i; - /* free tokens of unused inline functions */ - for (i = 0; i < s->nb_inline_fns; ++i) { - struct InlineFunc *fn = s->inline_fns[i]; - if (fn->sym) - tok_str_free(fn->func_str); - } - dynarray_reset(&s->inline_fns, &s->nb_inline_fns); -} - -/* 'l' is VT_LOCAL or VT_CONST to define default storage type, or VT_CMP - if parsing old style parameter decl list (and FUNC_SYM is set then) */ -static int decl0(int l, int is_for_loop_init, Sym *func_sym) -{ - int v, has_init, r; - CType type, btype; - Sym *sym; - AttributeDef ad; - - while (1) { - if (!parse_btype(&btype, &ad)) { - if (is_for_loop_init) - return 0; - /* skip redundant ';' if not in old parameter decl scope */ - if (tok == ';' && l != VT_CMP) { - next(); - continue; - } - if (l != VT_CONST) - break; - if (tok == TOK_ASM1 || tok == TOK_ASM2 || tok == TOK_ASM3) { - /* global asm block */ - asm_global_instr(); - continue; - } - if (tok >= TOK_UIDENT) { - /* special test for old K&R protos without explicit int - type. Only accepted when defining global data */ - btype.t = VT_INT; - } else { - if (tok != TOK_EOF) - expect("declaration"); - break; - } - } - if (tok == ';') { - if ((btype.t & VT_BTYPE) == VT_STRUCT) { - int v = btype.ref->v; - if (!(v & SYM_FIELD) && (v & ~SYM_STRUCT) >= SYM_FIRST_ANOM) - tcc_warning("unnamed struct/union that defines no instances"); - next(); - continue; - } - if (IS_ENUM(btype.t)) { - next(); - continue; - } - } - while (1) { /* iterate thru each declaration */ - type = btype; - /* If the base type itself was an array type of unspecified - size (like in 'typedef int arr[]; arr x = {1};') then - we will overwrite the unknown size by the real one for - this decl. We need to unshare the ref symbol holding - that size. */ - if ((type.t & VT_ARRAY) && type.ref->c < 0) { - type.ref = sym_push(SYM_FIELD, &type.ref->type, 0, type.ref->c); - } - type_decl(&type, &ad, &v, TYPE_DIRECT); -#if 0 - { - char buf[500]; - type_to_str(buf, sizeof(buf), &type, get_tok_str(v, NULL)); - printf("type = '%s'\n", buf); - } -#endif - if ((type.t & VT_BTYPE) == VT_FUNC) { - if ((type.t & VT_STATIC) && (l == VT_LOCAL)) { - tcc_error("function without file scope cannot be static"); - } - /* if old style function prototype, we accept a - declaration list */ - sym = type.ref; - if (sym->f.func_type == FUNC_OLD && l == VT_CONST) - decl0(VT_CMP, 0, sym); - } - - if (gnu_ext && (tok == TOK_ASM1 || tok == TOK_ASM2 || tok == TOK_ASM3)) { - ad.asm_label = asm_label_instr(); - /* parse one last attribute list, after asm label */ - parse_attribute(&ad); - if (tok == '{') - expect(";"); - } - -#ifdef TCC_TARGET_PE - if (ad.a.dllimport || ad.a.dllexport) { - if (type.t & (VT_STATIC|VT_TYPEDEF)) - tcc_error("cannot have dll linkage with static or typedef"); - if (ad.a.dllimport) { - if ((type.t & VT_BTYPE) == VT_FUNC) - ad.a.dllimport = 0; - else - type.t |= VT_EXTERN; - } - } -#endif - if (tok == '{') { - if (l != VT_CONST) - tcc_error("cannot use local functions"); - if ((type.t & VT_BTYPE) != VT_FUNC) - expect("function definition"); - - /* reject abstract declarators in function definition - make old style params without decl have int type */ - sym = type.ref; - while ((sym = sym->next) != NULL) { - if (!(sym->v & ~SYM_FIELD)) - expect("identifier"); - if (sym->type.t == VT_VOID) - sym->type = int_type; - } - - /* XXX: cannot do better now: convert extern line to static inline */ - if ((type.t & (VT_EXTERN | VT_INLINE)) == (VT_EXTERN | VT_INLINE)) - type.t = (type.t & ~VT_EXTERN) | VT_STATIC; - - /* put function symbol */ - sym = external_global_sym(v, &type, 0); - type.t &= ~VT_EXTERN; - patch_storage(sym, &ad, &type); - - /* static inline functions are just recorded as a kind - of macro. Their code will be emitted at the end of - the compilation unit only if they are used */ - if ((type.t & (VT_INLINE | VT_STATIC)) == - (VT_INLINE | VT_STATIC)) { - struct InlineFunc *fn; - const char *filename; - - filename = file ? file->filename : ""; - fn = tcc_malloc(sizeof *fn + strlen(filename)); - strcpy(fn->filename, filename); - fn->sym = sym; - skip_or_save_block(&fn->func_str); - dynarray_add(&tcc_state->inline_fns, - &tcc_state->nb_inline_fns, fn); - } else { - /* compute text section */ - cur_text_section = ad.section; - if (!cur_text_section) - cur_text_section = text_section; - gen_function(sym); - } - break; - } else { - if (l == VT_CMP) { - /* find parameter in function parameter list */ - for (sym = func_sym->next; sym; sym = sym->next) - if ((sym->v & ~SYM_FIELD) == v) - goto found; - tcc_error("declaration for parameter '%s' but no such parameter", - get_tok_str(v, NULL)); -found: - if (type.t & VT_STORAGE) /* 'register' is okay */ - tcc_error("storage class specified for '%s'", - get_tok_str(v, NULL)); - if (sym->type.t != VT_VOID) - tcc_error("redefinition of parameter '%s'", - get_tok_str(v, NULL)); - convert_parameter_type(&type); - sym->type = type; - } else if (type.t & VT_TYPEDEF) { - /* save typedefed type */ - /* XXX: test storage specifiers ? */ - sym = sym_find(v); - if (sym && sym->sym_scope == local_scope) { - if (!is_compatible_types(&sym->type, &type) - || !(sym->type.t & VT_TYPEDEF)) - tcc_error("incompatible redefinition of '%s'", - get_tok_str(v, NULL)); - sym->type = type; - } else { - sym = sym_push(v, &type, 0, 0); - } - sym->a = ad.a; - sym->f = ad.f; - } else { - r = 0; - if ((type.t & VT_BTYPE) == VT_FUNC) { - /* external function definition */ - /* specific case for func_call attribute */ - type.ref->f = ad.f; - } else if (!(type.t & VT_ARRAY)) { - /* not lvalue if array */ - r |= lvalue_type(type.t); - } - has_init = (tok == '='); - if (has_init && (type.t & VT_VLA)) - tcc_error("variable length array cannot be initialized"); - if (((type.t & VT_EXTERN) && (!has_init || l != VT_CONST)) || - ((type.t & VT_BTYPE) == VT_FUNC) || - ((type.t & VT_ARRAY) && (type.t & VT_STATIC) && - !has_init && l == VT_CONST && type.ref->c < 0)) { - /* external variable or function */ - /* NOTE: as GCC, uninitialized global static - arrays of null size are considered as - extern */ - type.t |= VT_EXTERN; - sym = external_sym(v, &type, r, &ad); - if (ad.alias_target) { - ElfSym *esym; - Sym *alias_target; - alias_target = sym_find(ad.alias_target); - esym = elfsym(alias_target); - if (!esym) - tcc_error("unsupported forward __alias__ attribute"); - /* Local statics have a scope until now (for - warnings), remove it here. */ - sym->sym_scope = 0; - put_extern_sym2(sym, esym->st_shndx, esym->st_value, esym->st_size, 0); - } - } else { - if (type.t & VT_STATIC) - r |= VT_CONST; - else - r |= l; - if (has_init) - next(); - else if (l == VT_CONST) - /* uninitialized global variables may be overridden */ - type.t |= VT_EXTERN; - decl_initializer_alloc(&type, &ad, r, has_init, v, l); - } - } - if (tok != ',') { - if (is_for_loop_init) - return 1; - skip(';'); - break; - } - next(); - } - ad.a.aligned = 0; - } - } - return 0; -} - -static void decl(int l) -{ - decl0(l, 0, NULL); -} - -/* ------------------------------------------------------------------------- */ diff --git a/05/tcc-final-old/tcclib.h b/05/tcc-final-old/tcclib.h deleted file mode 100644 index 8d59e4c..0000000 --- a/05/tcc-final-old/tcclib.h +++ /dev/null @@ -1,80 +0,0 @@ -/* Simple libc header for TCC - * - * Add any function you want from the libc there. This file is here - * only for your convenience so that you do not need to put the whole - * glibc include files on your floppy disk - */ -#ifndef _TCCLIB_H -#define _TCCLIB_H - -#include -#include - -/* stdlib.h */ -void *calloc(size_t nmemb, size_t size); -void *malloc(size_t size); -void free(void *ptr); -void *realloc(void *ptr, size_t size); -int atoi(const char *nptr); -long int strtol(const char *nptr, char **endptr, int base); -unsigned long int strtoul(const char *nptr, char **endptr, int base); -void exit(int); - -/* stdio.h */ -typedef struct __FILE FILE; -#define EOF (-1) -extern FILE *stdin; -extern FILE *stdout; -extern FILE *stderr; -FILE *fopen(const char *path, const char *mode); -FILE *fdopen(int fildes, const char *mode); -FILE *freopen(const char *path, const char *mode, FILE *stream); -int fclose(FILE *stream); -size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream); -size_t fwrite(void *ptr, size_t size, size_t nmemb, FILE *stream); -int fgetc(FILE *stream); -char *fgets(char *s, int size, FILE *stream); -int getc(FILE *stream); -int getchar(void); -char *gets(char *s); -int ungetc(int c, FILE *stream); -int fflush(FILE *stream); -int putchar (int c); - -int printf(const char *format, ...); -int fprintf(FILE *stream, const char *format, ...); -int sprintf(char *str, const char *format, ...); -int snprintf(char *str, size_t size, const char *format, ...); -int asprintf(char **strp, const char *format, ...); -int dprintf(int fd, const char *format, ...); -int vprintf(const char *format, va_list ap); -int vfprintf(FILE *stream, const char *format, va_list ap); -int vsprintf(char *str, const char *format, va_list ap); -int vsnprintf(char *str, size_t size, const char *format, va_list ap); -int vasprintf(char **strp, const char *format, va_list ap); -int vdprintf(int fd, const char *format, va_list ap); - -void perror(const char *s); - -/* string.h */ -char *strcat(char *dest, const char *src); -char *strchr(const char *s, int c); -char *strrchr(const char *s, int c); -char *strcpy(char *dest, const char *src); -void *memcpy(void *dest, const void *src, size_t n); -void *memmove(void *dest, const void *src, size_t n); -void *memset(void *s, int c, size_t n); -char *strdup(const char *s); -size_t strlen(const char *s); - -/* dlfcn.h */ -#define RTLD_LAZY 0x001 -#define RTLD_NOW 0x002 -#define RTLD_GLOBAL 0x100 - -void *dlopen(const char *filename, int flag); -const char *dlerror(void); -void *dlsym(void *handle, char *symbol); -int dlclose(void *handle); - -#endif /* _TCCLIB_H */ diff --git a/05/tcc-final-old/tccpe.c b/05/tcc-final-old/tccpe.c deleted file mode 100644 index a7266c9..0000000 --- a/05/tcc-final-old/tccpe.c +++ /dev/null @@ -1,1996 +0,0 @@ -/* - * TCCPE.C - PE file output for the Tiny C Compiler - * - * Copyright (c) 2005-2007 grischka - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "tcc.h" - -#define PE_MERGE_DATA -/* #define PE_PRINT_SECTIONS */ - -#ifndef _WIN32 -#define stricmp strcasecmp -#define strnicmp strncasecmp -#include /* chmod() */ -#endif - -#ifdef TCC_TARGET_X86_64 -# define ADDR3264 ULONGLONG -# define PE_IMAGE_REL IMAGE_REL_BASED_DIR64 -# define REL_TYPE_DIRECT R_X86_64_64 -# define R_XXX_THUNKFIX R_X86_64_PC32 -# define R_XXX_RELATIVE R_X86_64_RELATIVE -# define IMAGE_FILE_MACHINE 0x8664 -# define RSRC_RELTYPE 3 - -#elif defined TCC_TARGET_ARM -# define ADDR3264 DWORD -# define PE_IMAGE_REL IMAGE_REL_BASED_HIGHLOW -# define REL_TYPE_DIRECT R_ARM_ABS32 -# define R_XXX_THUNKFIX R_ARM_ABS32 -# define R_XXX_RELATIVE R_ARM_RELATIVE -# define IMAGE_FILE_MACHINE 0x01C0 -# define RSRC_RELTYPE 7 /* ??? (not tested) */ - -#elif defined TCC_TARGET_I386 -# define ADDR3264 DWORD -# define PE_IMAGE_REL IMAGE_REL_BASED_HIGHLOW -# define REL_TYPE_DIRECT R_386_32 -# define R_XXX_THUNKFIX R_386_32 -# define R_XXX_RELATIVE R_386_RELATIVE -# define IMAGE_FILE_MACHINE 0x014C -# define RSRC_RELTYPE 7 /* DIR32NB */ - -#endif - -#ifndef IMAGE_NT_SIGNATURE -/* ----------------------------------------------------------- */ -/* definitions below are from winnt.h */ - -typedef unsigned char BYTE; -typedef unsigned short WORD; -typedef unsigned int DWORD; -typedef unsigned long long ULONGLONG; -#pragma pack(push, 1) - -typedef struct _IMAGE_DOS_HEADER { /* DOS .EXE header */ - WORD e_magic; /* Magic number */ - WORD e_cblp; /* Bytes on last page of file */ - WORD e_cp; /* Pages in file */ - WORD e_crlc; /* Relocations */ - WORD e_cparhdr; /* Size of header in paragraphs */ - WORD e_minalloc; /* Minimum extra paragraphs needed */ - WORD e_maxalloc; /* Maximum extra paragraphs needed */ - WORD e_ss; /* Initial (relative) SS value */ - WORD e_sp; /* Initial SP value */ - WORD e_csum; /* Checksum */ - WORD e_ip; /* Initial IP value */ - WORD e_cs; /* Initial (relative) CS value */ - WORD e_lfarlc; /* File address of relocation table */ - WORD e_ovno; /* Overlay number */ - WORD e_res[4]; /* Reserved words */ - WORD e_oemid; /* OEM identifier (for e_oeminfo) */ - WORD e_oeminfo; /* OEM information; e_oemid specific */ - WORD e_res2[10]; /* Reserved words */ - DWORD e_lfanew; /* File address of new exe header */ -} IMAGE_DOS_HEADER, *PIMAGE_DOS_HEADER; - -#define IMAGE_NT_SIGNATURE 0x00004550 /* PE00 */ -#define SIZE_OF_NT_SIGNATURE 4 - -typedef struct _IMAGE_FILE_HEADER { - WORD Machine; - WORD NumberOfSections; - DWORD TimeDateStamp; - DWORD PointerToSymbolTable; - DWORD NumberOfSymbols; - WORD SizeOfOptionalHeader; - WORD Characteristics; -} IMAGE_FILE_HEADER, *PIMAGE_FILE_HEADER; - - -#define IMAGE_SIZEOF_FILE_HEADER 20 - -typedef struct _IMAGE_DATA_DIRECTORY { - DWORD VirtualAddress; - DWORD Size; -} IMAGE_DATA_DIRECTORY, *PIMAGE_DATA_DIRECTORY; - - -typedef struct _IMAGE_OPTIONAL_HEADER { - /* Standard fields. */ - WORD Magic; - BYTE MajorLinkerVersion; - BYTE MinorLinkerVersion; - DWORD SizeOfCode; - DWORD SizeOfInitializedData; - DWORD SizeOfUninitializedData; - DWORD AddressOfEntryPoint; - DWORD BaseOfCode; -#ifndef TCC_TARGET_X86_64 - DWORD BaseOfData; -#endif - /* NT additional fields. */ - ADDR3264 ImageBase; - DWORD SectionAlignment; - DWORD FileAlignment; - WORD MajorOperatingSystemVersion; - WORD MinorOperatingSystemVersion; - WORD MajorImageVersion; - WORD MinorImageVersion; - WORD MajorSubsystemVersion; - WORD MinorSubsystemVersion; - DWORD Win32VersionValue; - DWORD SizeOfImage; - DWORD SizeOfHeaders; - DWORD CheckSum; - WORD Subsystem; - WORD DllCharacteristics; - ADDR3264 SizeOfStackReserve; - ADDR3264 SizeOfStackCommit; - ADDR3264 SizeOfHeapReserve; - ADDR3264 SizeOfHeapCommit; - DWORD LoaderFlags; - DWORD NumberOfRvaAndSizes; - IMAGE_DATA_DIRECTORY DataDirectory[16]; -} IMAGE_OPTIONAL_HEADER32, IMAGE_OPTIONAL_HEADER64, IMAGE_OPTIONAL_HEADER; - -#define IMAGE_DIRECTORY_ENTRY_EXPORT 0 /* Export Directory */ -#define IMAGE_DIRECTORY_ENTRY_IMPORT 1 /* Import Directory */ -#define IMAGE_DIRECTORY_ENTRY_RESOURCE 2 /* Resource Directory */ -#define IMAGE_DIRECTORY_ENTRY_EXCEPTION 3 /* Exception Directory */ -#define IMAGE_DIRECTORY_ENTRY_SECURITY 4 /* Security Directory */ -#define IMAGE_DIRECTORY_ENTRY_BASERELOC 5 /* Base Relocation Table */ -#define IMAGE_DIRECTORY_ENTRY_DEBUG 6 /* Debug Directory */ -/* IMAGE_DIRECTORY_ENTRY_COPYRIGHT 7 (X86 usage) */ -#define IMAGE_DIRECTORY_ENTRY_ARCHITECTURE 7 /* Architecture Specific Data */ -#define IMAGE_DIRECTORY_ENTRY_GLOBALPTR 8 /* RVA of GP */ -#define IMAGE_DIRECTORY_ENTRY_TLS 9 /* TLS Directory */ -#define IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG 10 /* Load Configuration Directory */ -#define IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT 11 /* Bound Import Directory in headers */ -#define IMAGE_DIRECTORY_ENTRY_IAT 12 /* Import Address Table */ -#define IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT 13 /* Delay Load Import Descriptors */ -#define IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR 14 /* COM Runtime descriptor */ - -/* Section header format. */ -#define IMAGE_SIZEOF_SHORT_NAME 8 - -typedef struct _IMAGE_SECTION_HEADER { - BYTE Name[IMAGE_SIZEOF_SHORT_NAME]; - union { - DWORD PhysicalAddress; - DWORD VirtualSize; - } Misc; - DWORD VirtualAddress; - DWORD SizeOfRawData; - DWORD PointerToRawData; - DWORD PointerToRelocations; - DWORD PointerToLinenumbers; - WORD NumberOfRelocations; - WORD NumberOfLinenumbers; - DWORD Characteristics; -} IMAGE_SECTION_HEADER, *PIMAGE_SECTION_HEADER; - -#define IMAGE_SIZEOF_SECTION_HEADER 40 - -typedef struct _IMAGE_EXPORT_DIRECTORY { - DWORD Characteristics; - DWORD TimeDateStamp; - WORD MajorVersion; - WORD MinorVersion; - DWORD Name; - DWORD Base; - DWORD NumberOfFunctions; - DWORD NumberOfNames; - DWORD AddressOfFunctions; - DWORD AddressOfNames; - DWORD AddressOfNameOrdinals; -} IMAGE_EXPORT_DIRECTORY,*PIMAGE_EXPORT_DIRECTORY; - -typedef struct _IMAGE_IMPORT_DESCRIPTOR { - union { - DWORD Characteristics; - DWORD OriginalFirstThunk; - }; - DWORD TimeDateStamp; - DWORD ForwarderChain; - DWORD Name; - DWORD FirstThunk; -} IMAGE_IMPORT_DESCRIPTOR; - -typedef struct _IMAGE_BASE_RELOCATION { - DWORD VirtualAddress; - DWORD SizeOfBlock; -// WORD TypeOffset[1]; -} IMAGE_BASE_RELOCATION; - -#define IMAGE_SIZEOF_BASE_RELOCATION 8 - -#define IMAGE_REL_BASED_ABSOLUTE 0 -#define IMAGE_REL_BASED_HIGH 1 -#define IMAGE_REL_BASED_LOW 2 -#define IMAGE_REL_BASED_HIGHLOW 3 -#define IMAGE_REL_BASED_HIGHADJ 4 -#define IMAGE_REL_BASED_MIPS_JMPADDR 5 -#define IMAGE_REL_BASED_SECTION 6 -#define IMAGE_REL_BASED_REL32 7 -#define IMAGE_REL_BASED_DIR64 10 - -#pragma pack(pop) - -/* ----------------------------------------------------------- */ -#endif /* ndef IMAGE_NT_SIGNATURE */ -/* ----------------------------------------------------------- */ - -#ifndef IMAGE_REL_BASED_DIR64 -# define IMAGE_REL_BASED_DIR64 10 -#endif - -#pragma pack(push, 1) -struct pe_header -{ - IMAGE_DOS_HEADER doshdr; - BYTE dosstub[0x40]; - DWORD nt_sig; - IMAGE_FILE_HEADER filehdr; -#ifdef TCC_TARGET_X86_64 - IMAGE_OPTIONAL_HEADER64 opthdr; -#else -#ifdef _WIN64 - IMAGE_OPTIONAL_HEADER32 opthdr; -#else - IMAGE_OPTIONAL_HEADER opthdr; -#endif -#endif -}; - -struct pe_reloc_header { - DWORD offset; - DWORD size; -}; - -struct pe_rsrc_header { - struct _IMAGE_FILE_HEADER filehdr; - struct _IMAGE_SECTION_HEADER sectionhdr; -}; - -struct pe_rsrc_reloc { - DWORD offset; - DWORD size; - WORD type; -}; -#pragma pack(pop) - -/* ------------------------------------------------------------- */ -/* internal temporary structures */ - -/* -#define IMAGE_SCN_CNT_CODE 0x00000020 -#define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040 -#define IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080 -#define IMAGE_SCN_MEM_DISCARDABLE 0x02000000 -#define IMAGE_SCN_MEM_SHARED 0x10000000 -#define IMAGE_SCN_MEM_EXECUTE 0x20000000 -#define IMAGE_SCN_MEM_READ 0x40000000 -#define IMAGE_SCN_MEM_WRITE 0x80000000 -*/ - -enum { - sec_text = 0, - sec_data , - sec_bss , - sec_idata , - sec_pdata , - sec_other , - sec_rsrc , - sec_stab , - sec_reloc , - sec_last -}; - -static const DWORD pe_sec_flags[] = { - 0x60000020, /* ".text" , */ - 0xC0000040, /* ".data" , */ - 0xC0000080, /* ".bss" , */ - 0x40000040, /* ".idata" , */ - 0x40000040, /* ".pdata" , */ - 0xE0000060, /* < other > , */ - 0x40000040, /* ".rsrc" , */ - 0x42000802, /* ".stab" , */ - 0x42000040, /* ".reloc" , */ -}; - -struct section_info { - int cls, ord; - char name[32]; - DWORD sh_addr; - DWORD sh_size; - DWORD sh_flags; - unsigned char *data; - DWORD data_size; - IMAGE_SECTION_HEADER ish; -}; - -struct import_symbol { - int sym_index; - int iat_index; - int thk_offset; -}; - -struct pe_import_info { - int dll_index; - int sym_count; - struct import_symbol **symbols; -}; - -struct pe_info { - TCCState *s1; - Section *reloc; - Section *thunk; - const char *filename; - int type; - DWORD sizeofheaders; - ADDR3264 imagebase; - const char *start_symbol; - DWORD start_addr; - DWORD imp_offs; - DWORD imp_size; - DWORD iat_offs; - DWORD iat_size; - DWORD exp_offs; - DWORD exp_size; - int subsystem; - DWORD section_align; - DWORD file_align; - struct section_info *sec_info; - int sec_count; - struct pe_import_info **imp_info; - int imp_count; -}; - -#define PE_NUL 0 -#define PE_DLL 1 -#define PE_GUI 2 -#define PE_EXE 3 -#define PE_RUN 4 - -/* --------------------------------------------*/ - -static const char *pe_export_name(TCCState *s1, ElfW(Sym) *sym) -{ - const char *name = (char*)symtab_section->link->data + sym->st_name; - if (s1->leading_underscore && name[0] == '_' && !(sym->st_other & ST_PE_STDCALL)) - return name + 1; - return name; -} - -static int pe_find_import(TCCState * s1, ElfW(Sym) *sym) -{ - char buffer[200]; - const char *s, *p; - int sym_index = 0, n = 0; - int a, err = 0; - - do { - s = pe_export_name(s1, sym); - a = 0; - if (n) { - /* second try: */ - if (sym->st_other & ST_PE_STDCALL) { - /* try w/0 stdcall deco (windows API convention) */ - p = strrchr(s, '@'); - if (!p || s[0] != '_') - break; - strcpy(buffer, s+1)[p-s-1] = 0; - } else if (s[0] != '_') { /* try non-ansi function */ - buffer[0] = '_', strcpy(buffer + 1, s); - } else if (0 == memcmp(s, "__imp_", 6)) { /* mingw 2.0 */ - strcpy(buffer, s + 6), a = 1; - } else if (0 == memcmp(s, "_imp__", 6)) { /* mingw 3.7 */ - strcpy(buffer, s + 6), a = 1; - } else { - continue; - } - s = buffer; - } - sym_index = find_elf_sym(s1->dynsymtab_section, s); - // printf("find (%d) %d %s\n", n, sym_index, s); - if (sym_index - && ELFW(ST_TYPE)(sym->st_info) == STT_OBJECT - && 0 == (sym->st_other & ST_PE_IMPORT) - && 0 == a - ) err = -1, sym_index = 0; - } while (0 == sym_index && ++n < 2); - return n == 2 ? err : sym_index; -} - -/*----------------------------------------------------------------------------*/ - -static int dynarray_assoc(void **pp, int n, int key) -{ - int i; - for (i = 0; i < n; ++i, ++pp) - if (key == **(int **) pp) - return i; - return -1; -} - -#if 0 -ST_FN DWORD umin(DWORD a, DWORD b) -{ - return a < b ? a : b; -} -#endif - -static DWORD umax(DWORD a, DWORD b) -{ - return a < b ? b : a; -} - -static DWORD pe_file_align(struct pe_info *pe, DWORD n) -{ - return (n + (pe->file_align - 1)) & ~(pe->file_align - 1); -} - -static DWORD pe_virtual_align(struct pe_info *pe, DWORD n) -{ - return (n + (pe->section_align - 1)) & ~(pe->section_align - 1); -} - -static void pe_align_section(Section *s, int a) -{ - int i = s->data_offset & (a-1); - if (i) - section_ptr_add(s, a - i); -} - -static void pe_set_datadir(struct pe_header *hdr, int dir, DWORD addr, DWORD size) -{ - hdr->opthdr.DataDirectory[dir].VirtualAddress = addr; - hdr->opthdr.DataDirectory[dir].Size = size; -} - -static int pe_fwrite(void *data, unsigned len, FILE *fp, DWORD *psum) -{ - if (psum) { - DWORD sum = *psum; - WORD *p = data; - int i; - for (i = len; i > 0; i -= 2) { - sum += (i >= 2) ? *p++ : *(BYTE*)p; - sum = (sum + (sum >> 16)) & 0xFFFF; - } - *psum = sum; - } - return len == fwrite(data, 1, len, fp) ? 0 : -1; -} - -static void pe_fpad(FILE *fp, DWORD new_pos) -{ - DWORD pos = ftell(fp); - while (++pos <= new_pos) - fputc(0, fp); -} - -/*----------------------------------------------------------------------------*/ -static int pe_write(struct pe_info *pe) -{ - static const struct pe_header pe_template = { - { - /* IMAGE_DOS_HEADER doshdr */ - 0x5A4D, /*WORD e_magic; Magic number */ - 0x0090, /*WORD e_cblp; Bytes on last page of file */ - 0x0003, /*WORD e_cp; Pages in file */ - 0x0000, /*WORD e_crlc; Relocations */ - - 0x0004, /*WORD e_cparhdr; Size of header in paragraphs */ - 0x0000, /*WORD e_minalloc; Minimum extra paragraphs needed */ - 0xFFFF, /*WORD e_maxalloc; Maximum extra paragraphs needed */ - 0x0000, /*WORD e_ss; Initial (relative) SS value */ - - 0x00B8, /*WORD e_sp; Initial SP value */ - 0x0000, /*WORD e_csum; Checksum */ - 0x0000, /*WORD e_ip; Initial IP value */ - 0x0000, /*WORD e_cs; Initial (relative) CS value */ - 0x0040, /*WORD e_lfarlc; File address of relocation table */ - 0x0000, /*WORD e_ovno; Overlay number */ - {0,0,0,0}, /*WORD e_res[4]; Reserved words */ - 0x0000, /*WORD e_oemid; OEM identifier (for e_oeminfo) */ - 0x0000, /*WORD e_oeminfo; OEM information; e_oemid specific */ - {0,0,0,0,0,0,0,0,0,0}, /*WORD e_res2[10]; Reserved words */ - 0x00000080 /*DWORD e_lfanew; File address of new exe header */ - },{ - /* BYTE dosstub[0x40] */ - /* 14 code bytes + "This program cannot be run in DOS mode.\r\r\n$" + 6 * 0x00 */ - 0x0e,0x1f,0xba,0x0e,0x00,0xb4,0x09,0xcd,0x21,0xb8,0x01,0x4c,0xcd,0x21,0x54,0x68, - 0x69,0x73,0x20,0x70,0x72,0x6f,0x67,0x72,0x61,0x6d,0x20,0x63,0x61,0x6e,0x6e,0x6f, - 0x74,0x20,0x62,0x65,0x20,0x72,0x75,0x6e,0x20,0x69,0x6e,0x20,0x44,0x4f,0x53,0x20, - 0x6d,0x6f,0x64,0x65,0x2e,0x0d,0x0d,0x0a,0x24,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - }, - 0x00004550, /* DWORD nt_sig = IMAGE_NT_SIGNATURE */ - { - /* IMAGE_FILE_HEADER filehdr */ - IMAGE_FILE_MACHINE, /*WORD Machine; */ - 0x0003, /*WORD NumberOfSections; */ - 0x00000000, /*DWORD TimeDateStamp; */ - 0x00000000, /*DWORD PointerToSymbolTable; */ - 0x00000000, /*DWORD NumberOfSymbols; */ -#if defined(TCC_TARGET_X86_64) - 0x00F0, /*WORD SizeOfOptionalHeader; */ - 0x022F /*WORD Characteristics; */ -#define CHARACTERISTICS_DLL 0x222E -#elif defined(TCC_TARGET_I386) - 0x00E0, /*WORD SizeOfOptionalHeader; */ - 0x030F /*WORD Characteristics; */ -#define CHARACTERISTICS_DLL 0x230E -#elif defined(TCC_TARGET_ARM) - 0x00E0, /*WORD SizeOfOptionalHeader; */ - 0x010F, /*WORD Characteristics; */ -#define CHARACTERISTICS_DLL 0x230F -#endif -},{ - /* IMAGE_OPTIONAL_HEADER opthdr */ - /* Standard fields. */ -#ifdef TCC_TARGET_X86_64 - 0x020B, /*WORD Magic; */ -#else - 0x010B, /*WORD Magic; */ -#endif - 0x06, /*BYTE MajorLinkerVersion; */ - 0x00, /*BYTE MinorLinkerVersion; */ - 0x00000000, /*DWORD SizeOfCode; */ - 0x00000000, /*DWORD SizeOfInitializedData; */ - 0x00000000, /*DWORD SizeOfUninitializedData; */ - 0x00000000, /*DWORD AddressOfEntryPoint; */ - 0x00000000, /*DWORD BaseOfCode; */ -#ifndef TCC_TARGET_X86_64 - 0x00000000, /*DWORD BaseOfData; */ -#endif - /* NT additional fields. */ -#if defined(TCC_TARGET_ARM) - 0x00100000, /*DWORD ImageBase; */ -#else - 0x00400000, /*DWORD ImageBase; */ -#endif - 0x00001000, /*DWORD SectionAlignment; */ - 0x00000200, /*DWORD FileAlignment; */ - 0x0004, /*WORD MajorOperatingSystemVersion; */ - 0x0000, /*WORD MinorOperatingSystemVersion; */ - 0x0000, /*WORD MajorImageVersion; */ - 0x0000, /*WORD MinorImageVersion; */ - 0x0004, /*WORD MajorSubsystemVersion; */ - 0x0000, /*WORD MinorSubsystemVersion; */ - 0x00000000, /*DWORD Win32VersionValue; */ - 0x00000000, /*DWORD SizeOfImage; */ - 0x00000200, /*DWORD SizeOfHeaders; */ - 0x00000000, /*DWORD CheckSum; */ - 0x0002, /*WORD Subsystem; */ - 0x0000, /*WORD DllCharacteristics; */ - 0x00100000, /*DWORD SizeOfStackReserve; */ - 0x00001000, /*DWORD SizeOfStackCommit; */ - 0x00100000, /*DWORD SizeOfHeapReserve; */ - 0x00001000, /*DWORD SizeOfHeapCommit; */ - 0x00000000, /*DWORD LoaderFlags; */ - 0x00000010, /*DWORD NumberOfRvaAndSizes; */ - - /* IMAGE_DATA_DIRECTORY DataDirectory[16]; */ - {{0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, - {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}} - }}; - - struct pe_header pe_header = pe_template; - - int i; - FILE *op; - DWORD file_offset, sum; - struct section_info *si; - IMAGE_SECTION_HEADER *psh; - - op = fopen(pe->filename, "wb"); - if (NULL == op) { - tcc_error_noabort("could not write '%s': %s", pe->filename, strerror(errno)); - return -1; - } - - pe->sizeofheaders = pe_file_align(pe, - sizeof (struct pe_header) - + pe->sec_count * sizeof (IMAGE_SECTION_HEADER) - ); - - file_offset = pe->sizeofheaders; - - if (2 == pe->s1->verbose) - printf("-------------------------------" - "\n virt file size section" "\n"); - for (i = 0; i < pe->sec_count; ++i) { - DWORD addr, size; - const char *sh_name; - - si = pe->sec_info + i; - sh_name = si->name; - addr = si->sh_addr - pe->imagebase; - size = si->sh_size; - psh = &si->ish; - - if (2 == pe->s1->verbose) - printf("%6x %6x %6x %s\n", - (unsigned)addr, (unsigned)file_offset, (unsigned)size, sh_name); - - switch (si->cls) { - case sec_text: - pe_header.opthdr.BaseOfCode = addr; - break; - - case sec_data: -#ifndef TCC_TARGET_X86_64 - pe_header.opthdr.BaseOfData = addr; -#endif - break; - - case sec_bss: - break; - - case sec_reloc: - pe_set_datadir(&pe_header, IMAGE_DIRECTORY_ENTRY_BASERELOC, addr, size); - break; - - case sec_rsrc: - pe_set_datadir(&pe_header, IMAGE_DIRECTORY_ENTRY_RESOURCE, addr, size); - break; - - case sec_pdata: - pe_set_datadir(&pe_header, IMAGE_DIRECTORY_ENTRY_EXCEPTION, addr, size); - break; - - case sec_stab: - break; - } - - if (pe->thunk == pe->s1->sections[si->ord]) { - if (pe->imp_size) { - pe_set_datadir(&pe_header, IMAGE_DIRECTORY_ENTRY_IMPORT, - pe->imp_offs + addr, pe->imp_size); - pe_set_datadir(&pe_header, IMAGE_DIRECTORY_ENTRY_IAT, - pe->iat_offs + addr, pe->iat_size); - } - if (pe->exp_size) { - pe_set_datadir(&pe_header, IMAGE_DIRECTORY_ENTRY_EXPORT, - pe->exp_offs + addr, pe->exp_size); - } - } - - strncpy((char*)psh->Name, sh_name, sizeof psh->Name); - - psh->Characteristics = pe_sec_flags[si->cls]; - psh->VirtualAddress = addr; - psh->Misc.VirtualSize = size; - pe_header.opthdr.SizeOfImage = - umax(pe_virtual_align(pe, size + addr), pe_header.opthdr.SizeOfImage); - - if (si->data_size) { - psh->PointerToRawData = file_offset; - file_offset = pe_file_align(pe, file_offset + si->data_size); - psh->SizeOfRawData = file_offset - psh->PointerToRawData; - if (si->cls == sec_text) - pe_header.opthdr.SizeOfCode += psh->SizeOfRawData; - else - pe_header.opthdr.SizeOfInitializedData += psh->SizeOfRawData; - } - } - - //pe_header.filehdr.TimeDateStamp = time(NULL); - pe_header.filehdr.NumberOfSections = pe->sec_count; - pe_header.opthdr.AddressOfEntryPoint = pe->start_addr; - pe_header.opthdr.SizeOfHeaders = pe->sizeofheaders; - pe_header.opthdr.ImageBase = pe->imagebase; - pe_header.opthdr.Subsystem = pe->subsystem; - if (pe->s1->pe_stack_size) - pe_header.opthdr.SizeOfStackReserve = pe->s1->pe_stack_size; - if (PE_DLL == pe->type) - pe_header.filehdr.Characteristics = CHARACTERISTICS_DLL; - pe_header.filehdr.Characteristics |= pe->s1->pe_characteristics; - - sum = 0; - pe_fwrite(&pe_header, sizeof pe_header, op, &sum); - for (i = 0; i < pe->sec_count; ++i) - pe_fwrite(&pe->sec_info[i].ish, sizeof(IMAGE_SECTION_HEADER), op, &sum); - pe_fpad(op, pe->sizeofheaders); - for (i = 0; i < pe->sec_count; ++i) { - si = pe->sec_info + i; - psh = &si->ish; - if (si->data_size) { - pe_fwrite(si->data, si->data_size, op, &sum); - file_offset = psh->PointerToRawData + psh->SizeOfRawData; - pe_fpad(op, file_offset); - } - } - - pe_header.opthdr.CheckSum = sum + file_offset; - fseek(op, offsetof(struct pe_header, opthdr.CheckSum), SEEK_SET); - pe_fwrite(&pe_header.opthdr.CheckSum, sizeof pe_header.opthdr.CheckSum, op, NULL); - fclose (op); -#ifndef _WIN32 - chmod(pe->filename, 0777); -#endif - - if (2 == pe->s1->verbose) - printf("-------------------------------\n"); - if (pe->s1->verbose) - printf("<- %s (%u bytes)\n", pe->filename, (unsigned)file_offset); - - return 0; -} - -/*----------------------------------------------------------------------------*/ - -static struct import_symbol *pe_add_import(struct pe_info *pe, int sym_index) -{ - int i; - int dll_index; - struct pe_import_info *p; - struct import_symbol *s; - ElfW(Sym) *isym; - - isym = (ElfW(Sym) *)pe->s1->dynsymtab_section->data + sym_index; - dll_index = isym->st_size; - - i = dynarray_assoc ((void**)pe->imp_info, pe->imp_count, dll_index); - if (-1 != i) { - p = pe->imp_info[i]; - goto found_dll; - } - p = tcc_mallocz(sizeof *p); - p->dll_index = dll_index; - dynarray_add(&pe->imp_info, &pe->imp_count, p); - -found_dll: - i = dynarray_assoc ((void**)p->symbols, p->sym_count, sym_index); - if (-1 != i) - return p->symbols[i]; - - s = tcc_mallocz(sizeof *s); - dynarray_add(&p->symbols, &p->sym_count, s); - s->sym_index = sym_index; - return s; -} - -void pe_free_imports(struct pe_info *pe) -{ - int i; - for (i = 0; i < pe->imp_count; ++i) { - struct pe_import_info *p = pe->imp_info[i]; - dynarray_reset(&p->symbols, &p->sym_count); - } - dynarray_reset(&pe->imp_info, &pe->imp_count); -} - -/*----------------------------------------------------------------------------*/ -static void pe_build_imports(struct pe_info *pe) -{ - int thk_ptr, ent_ptr, dll_ptr, sym_cnt, i; - DWORD rva_base = pe->thunk->sh_addr - pe->imagebase; - int ndlls = pe->imp_count; - - for (sym_cnt = i = 0; i < ndlls; ++i) - sym_cnt += pe->imp_info[i]->sym_count; - - if (0 == sym_cnt) - return; - - pe_align_section(pe->thunk, 16); - - pe->imp_offs = dll_ptr = pe->thunk->data_offset; - pe->imp_size = (ndlls + 1) * sizeof(IMAGE_IMPORT_DESCRIPTOR); - pe->iat_offs = dll_ptr + pe->imp_size; - pe->iat_size = (sym_cnt + ndlls) * sizeof(ADDR3264); - section_ptr_add(pe->thunk, pe->imp_size + 2*pe->iat_size); - - thk_ptr = pe->iat_offs; - ent_ptr = pe->iat_offs + pe->iat_size; - - for (i = 0; i < pe->imp_count; ++i) { - IMAGE_IMPORT_DESCRIPTOR *hdr; - int k, n, dllindex; - ADDR3264 v; - struct pe_import_info *p = pe->imp_info[i]; - const char *name; - DLLReference *dllref; - - dllindex = p->dll_index; - if (dllindex) - name = (dllref = pe->s1->loaded_dlls[dllindex-1])->name; - else - name = "", dllref = NULL; - - /* put the dll name into the import header */ - v = put_elf_str(pe->thunk, name); - hdr = (IMAGE_IMPORT_DESCRIPTOR*)(pe->thunk->data + dll_ptr); - hdr->FirstThunk = thk_ptr + rva_base; - hdr->OriginalFirstThunk = ent_ptr + rva_base; - hdr->Name = v + rva_base; - - for (k = 0, n = p->sym_count; k <= n; ++k) { - if (k < n) { - int iat_index = p->symbols[k]->iat_index; - int sym_index = p->symbols[k]->sym_index; - ElfW(Sym) *imp_sym = (ElfW(Sym) *)pe->s1->dynsymtab_section->data + sym_index; - ElfW(Sym) *org_sym = (ElfW(Sym) *)symtab_section->data + iat_index; - const char *name = (char*)pe->s1->dynsymtab_section->link->data + imp_sym->st_name; - int ordinal; - - org_sym->st_value = thk_ptr; - org_sym->st_shndx = pe->thunk->sh_num; - - if (dllref) - v = 0, ordinal = imp_sym->st_value; /* ordinal from pe_load_def */ - else - ordinal = 0, v = imp_sym->st_value; /* address from tcc_add_symbol() */ - -#ifdef TCC_IS_NATIVE - if (pe->type == PE_RUN) { - if (dllref) { - if ( !dllref->handle ) - dllref->handle = LoadLibrary(dllref->name); - v = (ADDR3264)GetProcAddress(dllref->handle, ordinal?(char*)0+ordinal:name); - } - if (!v) - tcc_error_noabort("can't build symbol '%s'", name); - } else -#endif - if (ordinal) { - v = ordinal | (ADDR3264)1 << (sizeof(ADDR3264)*8 - 1); - } else { - v = pe->thunk->data_offset + rva_base; - section_ptr_add(pe->thunk, sizeof(WORD)); /* hint, not used */ - put_elf_str(pe->thunk, name); - } - - } else { - v = 0; /* last entry is zero */ - } - - *(ADDR3264*)(pe->thunk->data+thk_ptr) = - *(ADDR3264*)(pe->thunk->data+ent_ptr) = v; - thk_ptr += sizeof (ADDR3264); - ent_ptr += sizeof (ADDR3264); - } - dll_ptr += sizeof(IMAGE_IMPORT_DESCRIPTOR); - } -} - -/* ------------------------------------------------------------- */ - -struct pe_sort_sym -{ - int index; - const char *name; -}; - -static int sym_cmp(const void *va, const void *vb) -{ - const char *ca = (*(struct pe_sort_sym**)va)->name; - const char *cb = (*(struct pe_sort_sym**)vb)->name; - return strcmp(ca, cb); -} - -static void pe_build_exports(struct pe_info *pe) -{ - ElfW(Sym) *sym; - int sym_index, sym_end; - DWORD rva_base, func_o, name_o, ord_o, str_o; - IMAGE_EXPORT_DIRECTORY *hdr; - int sym_count, ord; - struct pe_sort_sym **sorted, *p; - - FILE *op; - char buf[260]; - const char *dllname; - const char *name; - - rva_base = pe->thunk->sh_addr - pe->imagebase; - sym_count = 0, sorted = NULL, op = NULL; - - sym_end = symtab_section->data_offset / sizeof(ElfW(Sym)); - for (sym_index = 1; sym_index < sym_end; ++sym_index) { - sym = (ElfW(Sym)*)symtab_section->data + sym_index; - name = pe_export_name(pe->s1, sym); - if ((sym->st_other & ST_PE_EXPORT) - /* export only symbols from actually written sections */ - && pe->s1->sections[sym->st_shndx]->sh_addr) { - p = tcc_malloc(sizeof *p); - p->index = sym_index; - p->name = name; - dynarray_add(&sorted, &sym_count, p); - } -#if 0 - if (sym->st_other & ST_PE_EXPORT) - printf("export: %s\n", name); - if (sym->st_other & ST_PE_STDCALL) - printf("stdcall: %s\n", name); -#endif - } - - if (0 == sym_count) - return; - - qsort (sorted, sym_count, sizeof *sorted, sym_cmp); - - pe_align_section(pe->thunk, 16); - dllname = tcc_basename(pe->filename); - - pe->exp_offs = pe->thunk->data_offset; - func_o = pe->exp_offs + sizeof(IMAGE_EXPORT_DIRECTORY); - name_o = func_o + sym_count * sizeof (DWORD); - ord_o = name_o + sym_count * sizeof (DWORD); - str_o = ord_o + sym_count * sizeof(WORD); - - hdr = section_ptr_add(pe->thunk, str_o - pe->exp_offs); - hdr->Characteristics = 0; - hdr->Base = 1; - hdr->NumberOfFunctions = sym_count; - hdr->NumberOfNames = sym_count; - hdr->AddressOfFunctions = func_o + rva_base; - hdr->AddressOfNames = name_o + rva_base; - hdr->AddressOfNameOrdinals = ord_o + rva_base; - hdr->Name = str_o + rva_base; - put_elf_str(pe->thunk, dllname); - -#if 1 - /* automatically write exports to .def */ - pstrcpy(buf, sizeof buf, pe->filename); - strcpy(tcc_fileextension(buf), ".def"); - op = fopen(buf, "wb"); - if (NULL == op) { - tcc_error_noabort("could not create '%s': %s", buf, strerror(errno)); - } else { - fprintf(op, "LIBRARY %s\n\nEXPORTS\n", dllname); - if (pe->s1->verbose) - printf("<- %s (%d symbol%s)\n", buf, sym_count, &"s"[sym_count < 2]); - } -#endif - - for (ord = 0; ord < sym_count; ++ord) - { - p = sorted[ord], sym_index = p->index, name = p->name; - /* insert actual address later in relocate_section() */ - put_elf_reloc(symtab_section, pe->thunk, - func_o, R_XXX_RELATIVE, sym_index); - *(DWORD*)(pe->thunk->data + name_o) - = pe->thunk->data_offset + rva_base; - *(WORD*)(pe->thunk->data + ord_o) - = ord; - put_elf_str(pe->thunk, name); - func_o += sizeof (DWORD); - name_o += sizeof (DWORD); - ord_o += sizeof (WORD); - if (op) - fprintf(op, "%s\n", name); - } - pe->exp_size = pe->thunk->data_offset - pe->exp_offs; - dynarray_reset(&sorted, &sym_count); - if (op) - fclose(op); -} - -/* ------------------------------------------------------------- */ -static void pe_build_reloc (struct pe_info *pe) -{ - DWORD offset, block_ptr, addr; - int count, i; - ElfW_Rel *rel, *rel_end; - Section *s = NULL, *sr; - - offset = addr = block_ptr = count = i = 0; - rel = rel_end = NULL; - - for(;;) { - if (rel < rel_end) { - int type = ELFW(R_TYPE)(rel->r_info); - addr = rel->r_offset + s->sh_addr; - ++ rel; - if (type != REL_TYPE_DIRECT) - continue; - if (count == 0) { /* new block */ - block_ptr = pe->reloc->data_offset; - section_ptr_add(pe->reloc, sizeof(struct pe_reloc_header)); - offset = addr & 0xFFFFFFFF<<12; - } - if ((addr -= offset) < (1<<12)) { /* one block spans 4k addresses */ - WORD *wp = section_ptr_add(pe->reloc, sizeof (WORD)); - *wp = addr | PE_IMAGE_REL<<12; - ++count; - continue; - } - -- rel; - - } else if (i < pe->sec_count) { - sr = (s = pe->s1->sections[pe->sec_info[i++].ord])->reloc; - if (sr) { - rel = (ElfW_Rel *)sr->data; - rel_end = (ElfW_Rel *)(sr->data + sr->data_offset); - } - continue; - } - - if (count) { - /* store the last block and ready for a new one */ - struct pe_reloc_header *hdr; - if (count & 1) /* align for DWORDS */ - section_ptr_add(pe->reloc, sizeof(WORD)), ++count; - hdr = (struct pe_reloc_header *)(pe->reloc->data + block_ptr); - hdr -> offset = offset - pe->imagebase; - hdr -> size = count * sizeof(WORD) + sizeof(struct pe_reloc_header); - count = 0; - } - - if (rel >= rel_end) - break; - } -} - -/* ------------------------------------------------------------- */ -static int pe_section_class(Section *s) -{ - int type, flags; - const char *name; - - type = s->sh_type; - flags = s->sh_flags; - name = s->name; - if (flags & SHF_ALLOC) { - if (type == SHT_PROGBITS) { - if (flags & SHF_EXECINSTR) - return sec_text; - if (flags & SHF_WRITE) - return sec_data; - if (0 == strcmp(name, ".rsrc")) - return sec_rsrc; - if (0 == strcmp(name, ".iedat")) - return sec_idata; - if (0 == strcmp(name, ".pdata")) - return sec_pdata; - return sec_other; - } else if (type == SHT_NOBITS) { - if (flags & SHF_WRITE) - return sec_bss; - } - } else { - if (0 == strcmp(name, ".reloc")) - return sec_reloc; - if (0 == strncmp(name, ".stab", 5)) /* .stab and .stabstr */ - return sec_stab; - } - return -1; -} - -static int pe_assign_addresses (struct pe_info *pe) -{ - int i, k, o, c; - DWORD addr; - int *section_order; - struct section_info *si; - Section *s; - - if (PE_DLL == pe->type) - pe->reloc = new_section(pe->s1, ".reloc", SHT_PROGBITS, 0); - - // pe->thunk = new_section(pe->s1, ".iedat", SHT_PROGBITS, SHF_ALLOC); - - section_order = tcc_malloc(pe->s1->nb_sections * sizeof (int)); - for (o = k = 0 ; k < sec_last; ++k) { - for (i = 1; i < pe->s1->nb_sections; ++i) { - s = pe->s1->sections[i]; - if (k == pe_section_class(s)) { - // printf("%s %d\n", s->name, k); - s->sh_addr = pe->imagebase; - section_order[o++] = i; - } - } - } - - pe->sec_info = tcc_mallocz(o * sizeof (struct section_info)); - addr = pe->imagebase + 1; - - for (i = 0; i < o; ++i) - { - k = section_order[i]; - s = pe->s1->sections[k]; - c = pe_section_class(s); - si = &pe->sec_info[pe->sec_count]; - -#ifdef PE_MERGE_DATA - if (c == sec_bss && pe->sec_count && si[-1].cls == sec_data) { - /* append .bss to .data */ - s->sh_addr = addr = ((addr-1) | (s->sh_addralign-1)) + 1; - addr += s->data_offset; - si[-1].sh_size = addr - si[-1].sh_addr; - continue; - } -#endif - if (c == sec_stab && 0 == pe->s1->do_debug) - continue; - - strcpy(si->name, s->name); - si->cls = c; - si->ord = k; - si->sh_addr = s->sh_addr = addr = pe_virtual_align(pe, addr); - si->sh_flags = s->sh_flags; - - if (c == sec_data && NULL == pe->thunk) - pe->thunk = s; - - if (s == pe->thunk) { - pe_build_imports(pe); - pe_build_exports(pe); - } - - if (c == sec_reloc) - pe_build_reloc (pe); - - if (s->data_offset) - { - if (s->sh_type != SHT_NOBITS) { - si->data = s->data; - si->data_size = s->data_offset; - } - - addr += s->data_offset; - si->sh_size = s->data_offset; - ++pe->sec_count; - } - // printf("%08x %05x %s\n", si->sh_addr, si->sh_size, si->name); - } - -#if 0 - for (i = 1; i < pe->s1->nb_sections; ++i) { - Section *s = pe->s1->sections[i]; - int type = s->sh_type; - int flags = s->sh_flags; - printf("section %-16s %-10s %5x %s,%s,%s\n", - s->name, - type == SHT_PROGBITS ? "progbits" : - type == SHT_NOBITS ? "nobits" : - type == SHT_SYMTAB ? "symtab" : - type == SHT_STRTAB ? "strtab" : - type == SHT_RELX ? "rel" : "???", - s->data_offset, - flags & SHF_ALLOC ? "alloc" : "", - flags & SHF_WRITE ? "write" : "", - flags & SHF_EXECINSTR ? "exec" : "" - ); - } - pe->s1->verbose = 2; -#endif - - tcc_free(section_order); - return 0; -} - -/*----------------------------------------------------------------------------*/ - -static int pe_isafunc(int sym_index) -{ - Section *sr = text_section->reloc; - ElfW_Rel *rel, *rel_end; - Elf32_Word info = ELF32_R_INFO(sym_index, R_386_PC32); - if (!sr) - return 0; - rel_end = (ElfW_Rel *)(sr->data + sr->data_offset); - for (rel = (ElfW_Rel *)sr->data; rel < rel_end; rel++) - if (rel->r_info == info) - return 1; - return 0; -} - -/*----------------------------------------------------------------------------*/ -static int pe_check_symbols(struct pe_info *pe) -{ - ElfW(Sym) *sym; - int sym_index, sym_end; - int ret = 0; - - pe_align_section(text_section, 8); - - sym_end = symtab_section->data_offset / sizeof(ElfW(Sym)); - for (sym_index = 1; sym_index < sym_end; ++sym_index) { - - sym = (ElfW(Sym) *)symtab_section->data + sym_index; - if (sym->st_shndx == SHN_UNDEF) { - - const char *name = (char*)symtab_section->link->data + sym->st_name; - unsigned type = ELFW(ST_TYPE)(sym->st_info); - int imp_sym = pe_find_import(pe->s1, sym); - struct import_symbol *is; - - if (imp_sym <= 0) - goto not_found; - - if (type == STT_NOTYPE) { - /* symbols from assembler have no type, find out which */ - if (pe_isafunc(sym_index)) - type = STT_FUNC; - else - type = STT_OBJECT; - } - - is = pe_add_import(pe, imp_sym); - - if (type == STT_FUNC) { - unsigned long offset = is->thk_offset; - if (offset) { - /* got aliased symbol, like stricmp and _stricmp */ - - } else { - char buffer[100]; - WORD *p; - - offset = text_section->data_offset; - /* add the 'jmp IAT[x]' instruction */ -#ifdef TCC_TARGET_ARM - p = section_ptr_add(text_section, 8+4); // room for code and address - (*(DWORD*)(p)) = 0xE59FC000; // arm code ldr ip, [pc] ; PC+8+0 = 0001xxxx - (*(DWORD*)(p+2)) = 0xE59CF000; // arm code ldr pc, [ip] -#else - p = section_ptr_add(text_section, 8); - *p = 0x25FF; -#ifdef TCC_TARGET_X86_64 - *(DWORD*)(p+1) = (DWORD)-4; -#endif -#endif - /* add a helper symbol, will be patched later in - pe_build_imports */ - sprintf(buffer, "IAT.%s", name); - is->iat_index = put_elf_sym( - symtab_section, 0, sizeof(DWORD), - ELFW(ST_INFO)(STB_GLOBAL, STT_OBJECT), - 0, SHN_UNDEF, buffer); -#ifdef TCC_TARGET_ARM - put_elf_reloc(symtab_section, text_section, - offset + 8, R_XXX_THUNKFIX, is->iat_index); // offset to IAT position -#else - put_elf_reloc(symtab_section, text_section, - offset + 2, R_XXX_THUNKFIX, is->iat_index); -#endif - is->thk_offset = offset; - } - - /* tcc_realloc might have altered sym's address */ - sym = (ElfW(Sym) *)symtab_section->data + sym_index; - - /* patch the original symbol */ - sym->st_value = offset; - sym->st_shndx = text_section->sh_num; - sym->st_other &= ~ST_PE_EXPORT; /* do not export */ - continue; - } - - if (type == STT_OBJECT) { /* data, ptr to that should be */ - if (0 == is->iat_index) { - /* original symbol will be patched later in pe_build_imports */ - is->iat_index = sym_index; - continue; - } - } - - not_found: - if (ELFW(ST_BIND)(sym->st_info) == STB_WEAK) - /* STB_WEAK undefined symbols are accepted */ - continue; - tcc_error_noabort("undefined symbol '%s'%s", name, - imp_sym < 0 ? ", missing __declspec(dllimport)?":""); - ret = -1; - - } else if (pe->s1->rdynamic - && ELFW(ST_BIND)(sym->st_info) != STB_LOCAL) { - /* if -rdynamic option, then export all non local symbols */ - sym->st_other |= ST_PE_EXPORT; - } - } - return ret; -} - -/*----------------------------------------------------------------------------*/ -#ifdef PE_PRINT_SECTIONS -static void pe_print_section(FILE * f, Section * s) -{ - /* just if you're curious */ - BYTE *p, *e, b; - int i, n, l, m; - p = s->data; - e = s->data + s->data_offset; - l = e - p; - - fprintf(f, "section \"%s\"", s->name); - if (s->link) - fprintf(f, "\nlink \"%s\"", s->link->name); - if (s->reloc) - fprintf(f, "\nreloc \"%s\"", s->reloc->name); - fprintf(f, "\nv_addr %08X", (unsigned)s->sh_addr); - fprintf(f, "\ncontents %08X", (unsigned)l); - fprintf(f, "\n\n"); - - if (s->sh_type == SHT_NOBITS) - return; - - if (0 == l) - return; - - if (s->sh_type == SHT_SYMTAB) - m = sizeof(ElfW(Sym)); - else if (s->sh_type == SHT_RELX) - m = sizeof(ElfW_Rel); - else - m = 16; - - fprintf(f, "%-8s", "offset"); - for (i = 0; i < m; ++i) - fprintf(f, " %02x", i); - n = 56; - - if (s->sh_type == SHT_SYMTAB || s->sh_type == SHT_RELX) { - const char *fields1[] = { - "name", - "value", - "size", - "bind", - "type", - "other", - "shndx", - NULL - }; - - const char *fields2[] = { - "offs", - "type", - "symb", - NULL - }; - - const char **p; - - if (s->sh_type == SHT_SYMTAB) - p = fields1, n = 106; - else - p = fields2, n = 58; - - for (i = 0; p[i]; ++i) - fprintf(f, "%6s", p[i]); - fprintf(f, " symbol"); - } - - fprintf(f, "\n"); - for (i = 0; i < n; ++i) - fprintf(f, "-"); - fprintf(f, "\n"); - - for (i = 0; i < l;) - { - fprintf(f, "%08X", i); - for (n = 0; n < m; ++n) { - if (n + i < l) - fprintf(f, " %02X", p[i + n]); - else - fprintf(f, " "); - } - - if (s->sh_type == SHT_SYMTAB) { - ElfW(Sym) *sym = (ElfW(Sym) *) (p + i); - const char *name = s->link->data + sym->st_name; - fprintf(f, " %04X %04X %04X %02X %02X %02X %04X \"%s\"", - (unsigned)sym->st_name, - (unsigned)sym->st_value, - (unsigned)sym->st_size, - (unsigned)ELFW(ST_BIND)(sym->st_info), - (unsigned)ELFW(ST_TYPE)(sym->st_info), - (unsigned)sym->st_other, - (unsigned)sym->st_shndx, - name); - - } else if (s->sh_type == SHT_RELX) { - ElfW_Rel *rel = (ElfW_Rel *) (p + i); - ElfW(Sym) *sym = - (ElfW(Sym) *) s->link->data + ELFW(R_SYM)(rel->r_info); - const char *name = s->link->link->data + sym->st_name; - fprintf(f, " %04X %02X %04X \"%s\"", - (unsigned)rel->r_offset, - (unsigned)ELFW(R_TYPE)(rel->r_info), - (unsigned)ELFW(R_SYM)(rel->r_info), - name); - } else { - fprintf(f, " "); - for (n = 0; n < m; ++n) { - if (n + i < l) { - b = p[i + n]; - if (b < 32 || b >= 127) - b = '.'; - fprintf(f, "%c", b); - } - } - } - i += m; - fprintf(f, "\n"); - } - fprintf(f, "\n\n"); -} - -static void pe_print_sections(TCCState *s1, const char *fname) -{ - Section *s; - FILE *f; - int i; - f = fopen(fname, "w"); - for (i = 1; i < s1->nb_sections; ++i) { - s = s1->sections[i]; - pe_print_section(f, s); - } - pe_print_section(f, s1->dynsymtab_section); - fclose(f); -} -#endif - -/* ------------------------------------------------------------- */ -/* helper function for load/store to insert one more indirection */ - -#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64 -ST_FUNC SValue *pe_getimport(SValue *sv, SValue *v2) -{ - int r2; - if ((sv->r & (VT_VALMASK|VT_SYM)) != (VT_CONST|VT_SYM) || (sv->r2 != VT_CONST)) - return sv; - if (!sv->sym->a.dllimport) - return sv; - // printf("import %04x %04x %04x %s\n", sv->type.t, sv->sym->type.t, sv->r, get_tok_str(sv->sym->v, NULL)); - memset(v2, 0, sizeof *v2); - v2->type.t = VT_PTR; - v2->r = VT_CONST | VT_SYM | VT_LVAL; - v2->sym = sv->sym; - - r2 = get_reg(RC_INT); - load(r2, v2); - v2->r = r2; - if ((uint32_t)sv->c.i) { - vpushv(v2); - vpushi(sv->c.i); - gen_opi('+'); - *v2 = *vtop--; - } - v2->type.t = sv->type.t; - v2->r |= sv->r & VT_LVAL; - return v2; -} -#endif - -ST_FUNC int pe_putimport(TCCState *s1, int dllindex, const char *name, addr_t value) -{ - return set_elf_sym( - s1->dynsymtab_section, - value, - dllindex, /* st_size */ - ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), - 0, - value ? SHN_ABS : SHN_UNDEF, - name - ); -} - -static int add_dllref(TCCState *s1, const char *dllname) -{ - DLLReference *dllref; - int i; - for (i = 0; i < s1->nb_loaded_dlls; ++i) - if (0 == strcmp(s1->loaded_dlls[i]->name, dllname)) - return i + 1; - dllref = tcc_mallocz(sizeof(DLLReference) + strlen(dllname)); - strcpy(dllref->name, dllname); - dynarray_add(&s1->loaded_dlls, &s1->nb_loaded_dlls, dllref); - return s1->nb_loaded_dlls; -} - -/* ------------------------------------------------------------- */ - -static int read_mem(int fd, unsigned offset, void *buffer, unsigned len) -{ - lseek(fd, offset, SEEK_SET); - return len == read(fd, buffer, len); -} - -/* ------------------------------------------------------------- */ - -PUB_FUNC int tcc_get_dllexports(const char *filename, char **pp) -{ - int l, i, n, n0, ret; - char *p; - int fd; - - IMAGE_SECTION_HEADER ish; - IMAGE_EXPORT_DIRECTORY ied; - IMAGE_DOS_HEADER dh; - IMAGE_FILE_HEADER ih; - DWORD sig, ref, addr, ptr, namep; - - int pef_hdroffset, opt_hdroffset, sec_hdroffset; - - n = n0 = 0; - p = NULL; - ret = -1; - - fd = open(filename, O_RDONLY | O_BINARY); - if (fd < 0) - goto the_end_1; - ret = 1; - if (!read_mem(fd, 0, &dh, sizeof dh)) - goto the_end; - if (!read_mem(fd, dh.e_lfanew, &sig, sizeof sig)) - goto the_end; - if (sig != 0x00004550) - goto the_end; - pef_hdroffset = dh.e_lfanew + sizeof sig; - if (!read_mem(fd, pef_hdroffset, &ih, sizeof ih)) - goto the_end; - opt_hdroffset = pef_hdroffset + sizeof ih; - if (ih.Machine == 0x014C) { - IMAGE_OPTIONAL_HEADER32 oh; - sec_hdroffset = opt_hdroffset + sizeof oh; - if (!read_mem(fd, opt_hdroffset, &oh, sizeof oh)) - goto the_end; - if (IMAGE_DIRECTORY_ENTRY_EXPORT >= oh.NumberOfRvaAndSizes) - goto the_end_0; - addr = oh.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress; - } else if (ih.Machine == 0x8664) { - IMAGE_OPTIONAL_HEADER64 oh; - sec_hdroffset = opt_hdroffset + sizeof oh; - if (!read_mem(fd, opt_hdroffset, &oh, sizeof oh)) - goto the_end; - if (IMAGE_DIRECTORY_ENTRY_EXPORT >= oh.NumberOfRvaAndSizes) - goto the_end_0; - addr = oh.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress; - } else - goto the_end; - - //printf("addr: %08x\n", addr); - for (i = 0; i < ih.NumberOfSections; ++i) { - if (!read_mem(fd, sec_hdroffset + i * sizeof ish, &ish, sizeof ish)) - goto the_end; - //printf("vaddr: %08x\n", ish.VirtualAddress); - if (addr >= ish.VirtualAddress && addr < ish.VirtualAddress + ish.SizeOfRawData) - goto found; - } - goto the_end_0; - -found: - ref = ish.VirtualAddress - ish.PointerToRawData; - if (!read_mem(fd, addr - ref, &ied, sizeof ied)) - goto the_end; - - namep = ied.AddressOfNames - ref; - for (i = 0; i < ied.NumberOfNames; ++i) { - if (!read_mem(fd, namep, &ptr, sizeof ptr)) - goto the_end; - namep += sizeof ptr; - for (l = 0;;) { - if (n+1 >= n0) - p = tcc_realloc(p, n0 = n0 ? n0 * 2 : 256); - if (!read_mem(fd, ptr - ref + l++, p + n, 1)) { - tcc_free(p), p = NULL; - goto the_end; - } - if (p[n++] == 0) - break; - } - } - if (p) - p[n] = 0; -the_end_0: - ret = 0; -the_end: - close(fd); -the_end_1: - *pp = p; - return ret; -} - -/* ------------------------------------------------------------- - * This is for compiled windows resources in 'coff' format - * as generated by 'windres.exe -O coff ...'. - */ - -static int pe_load_res(TCCState *s1, int fd) -{ - struct pe_rsrc_header hdr; - Section *rsrc_section; - int i, ret = -1, sym_index; - BYTE *ptr; - unsigned offs; - - if (!read_mem(fd, 0, &hdr, sizeof hdr)) - goto quit; - - if (hdr.filehdr.Machine != IMAGE_FILE_MACHINE - || hdr.filehdr.NumberOfSections != 1 - || strcmp((char*)hdr.sectionhdr.Name, ".rsrc") != 0) - goto quit; - - rsrc_section = new_section(s1, ".rsrc", SHT_PROGBITS, SHF_ALLOC); - ptr = section_ptr_add(rsrc_section, hdr.sectionhdr.SizeOfRawData); - offs = hdr.sectionhdr.PointerToRawData; - if (!read_mem(fd, offs, ptr, hdr.sectionhdr.SizeOfRawData)) - goto quit; - offs = hdr.sectionhdr.PointerToRelocations; - sym_index = put_elf_sym(symtab_section, 0, 0, 0, 0, rsrc_section->sh_num, ".rsrc"); - for (i = 0; i < hdr.sectionhdr.NumberOfRelocations; ++i) { - struct pe_rsrc_reloc rel; - if (!read_mem(fd, offs, &rel, sizeof rel)) - goto quit; - // printf("rsrc_reloc: %x %x %x\n", rel.offset, rel.size, rel.type); - if (rel.type != RSRC_RELTYPE) - goto quit; - put_elf_reloc(symtab_section, rsrc_section, - rel.offset, R_XXX_RELATIVE, sym_index); - offs += sizeof rel; - } - ret = 0; -quit: - return ret; -} - -/* ------------------------------------------------------------- */ - -static char *trimfront(char *p) -{ - while (*p && (unsigned char)*p <= ' ') - ++p; - return p; -} - -static char *trimback(char *a, char *e) -{ - while (e > a && (unsigned char)e[-1] <= ' ') - --e; - *e = 0;; - return a; -} - -/* ------------------------------------------------------------- */ -static int pe_load_def(TCCState *s1, int fd) -{ - int state = 0, ret = -1, dllindex = 0, ord; - char line[400], dllname[80], *p, *x; - FILE *fp; - - fp = fdopen(dup(fd), "rb"); - while (fgets(line, sizeof line, fp)) - { - p = trimfront(trimback(line, strchr(line, 0))); - if (0 == *p || ';' == *p) - continue; - - switch (state) { - case 0: - if (0 != strnicmp(p, "LIBRARY", 7)) - goto quit; - pstrcpy(dllname, sizeof dllname, trimfront(p+7)); - ++state; - continue; - - case 1: - if (0 != stricmp(p, "EXPORTS")) - goto quit; - ++state; - continue; - - case 2: - dllindex = add_dllref(s1, dllname); - ++state; - /* fall through */ - default: - /* get ordinal and will store in sym->st_value */ - ord = 0; - x = strchr(p, ' '); - if (x) { - *x = 0, x = strrchr(x + 1, '@'); - if (x) { - char *d; - ord = (int)strtol(x + 1, &d, 10); - if (*d) - ord = 0; - } - } - pe_putimport(s1, dllindex, p, ord); - continue; - } - } - ret = 0; -quit: - fclose(fp); - return ret; -} - -/* ------------------------------------------------------------- */ -static int pe_load_dll(TCCState *s1, const char *filename) -{ - char *p, *q; - int index, ret; - - ret = tcc_get_dllexports(filename, &p); - if (ret) { - return -1; - } else if (p) { - index = add_dllref(s1, tcc_basename(filename)); - for (q = p; *q; q += 1 + strlen(q)) - pe_putimport(s1, index, q, 0); - tcc_free(p); - } - return 0; -} - -/* ------------------------------------------------------------- */ -ST_FUNC int pe_load_file(struct TCCState *s1, const char *filename, int fd) -{ - int ret = -1; - char buf[10]; - if (0 == strcmp(tcc_fileextension(filename), ".def")) - ret = pe_load_def(s1, fd); - else if (pe_load_res(s1, fd) == 0) - ret = 0; - else if (read_mem(fd, 0, buf, 4) && 0 == memcmp(buf, "MZ\220", 4)) - ret = pe_load_dll(s1, filename); - return ret; -} - -/* ------------------------------------------------------------- */ -#ifdef TCC_TARGET_X86_64 -static unsigned pe_add_uwwind_info(TCCState *s1) -{ - if (NULL == s1->uw_pdata) { - s1->uw_pdata = find_section(tcc_state, ".pdata"); - s1->uw_pdata->sh_addralign = 4; - } - if (0 == s1->uw_sym) - s1->uw_sym = put_elf_sym(symtab_section, 0, 0, 0, 0, text_section->sh_num, ".uw_base"); - if (0 == s1->uw_offs) { - /* As our functions all have the same stackframe, we use one entry for all */ - static const unsigned char uw_info[] = { - 0x01, // UBYTE: 3 Version , UBYTE: 5 Flags - 0x04, // UBYTE Size of prolog - 0x02, // UBYTE Count of unwind codes - 0x05, // UBYTE: 4 Frame Register (rbp), UBYTE: 4 Frame Register offset (scaled) - // USHORT * n Unwind codes array - // 0x0b, 0x01, 0xff, 0xff, // stack size - 0x04, 0x03, // set frame ptr (mov rsp -> rbp) - 0x01, 0x50 // push reg (rbp) - }; - - Section *s = text_section; - unsigned char *p; - - section_ptr_add(s, -s->data_offset & 3); /* align */ - s1->uw_offs = s->data_offset; - p = section_ptr_add(s, sizeof uw_info); - memcpy(p, uw_info, sizeof uw_info); - } - - return s1->uw_offs; -} - -ST_FUNC void pe_add_unwind_data(unsigned start, unsigned end, unsigned stack) -{ - TCCState *s1 = tcc_state; - Section *pd; - unsigned o, n, d; - struct /* _RUNTIME_FUNCTION */ { - DWORD BeginAddress; - DWORD EndAddress; - DWORD UnwindData; - } *p; - - d = pe_add_uwwind_info(s1); - pd = s1->uw_pdata; - o = pd->data_offset; - p = section_ptr_add(pd, sizeof *p); - - /* record this function */ - p->BeginAddress = start; - p->EndAddress = end; - p->UnwindData = d; - - /* put relocations on it */ - for (n = o + sizeof *p; o < n; o += sizeof p->BeginAddress) - put_elf_reloc(symtab_section, pd, o, R_XXX_RELATIVE, s1->uw_sym); -} -#endif -/* ------------------------------------------------------------- */ -#ifdef TCC_TARGET_X86_64 -#define PE_STDSYM(n,s) n -#else -#define PE_STDSYM(n,s) "_" n s -#endif - -static void pe_add_runtime(TCCState *s1, struct pe_info *pe) -{ - const char *start_symbol; - int pe_type = 0; - int unicode_entry = 0; - - if (find_elf_sym(symtab_section, PE_STDSYM("WinMain","@16"))) - pe_type = PE_GUI; - else - if (find_elf_sym(symtab_section, PE_STDSYM("wWinMain","@16"))) { - pe_type = PE_GUI; - unicode_entry = PE_GUI; - } - else - if (TCC_OUTPUT_DLL == s1->output_type) { - pe_type = PE_DLL; - /* need this for 'tccelf.c:relocate_section()' */ - s1->output_type = TCC_OUTPUT_EXE; - } - else { - pe_type = PE_EXE; - if (find_elf_sym(symtab_section, "wmain")) - unicode_entry = PE_EXE; - } - - start_symbol = - TCC_OUTPUT_MEMORY == s1->output_type - ? PE_GUI == pe_type ? (unicode_entry ? "__runwwinmain" : "__runwinmain") - : (unicode_entry ? "__runwmain" : "__runmain") - : PE_DLL == pe_type ? PE_STDSYM("__dllstart","@12") - : PE_GUI == pe_type ? (unicode_entry ? "__wwinstart": "__winstart") - : (unicode_entry ? "__wstart" : "__start") - ; - - if (!s1->leading_underscore || strchr(start_symbol, '@')) - ++start_symbol; - - /* grab the startup code from libtcc1 */ -#ifdef TCC_IS_NATIVE - if (TCC_OUTPUT_MEMORY != s1->output_type || s1->runtime_main) -#endif - set_elf_sym(symtab_section, - 0, 0, - ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, - SHN_UNDEF, start_symbol); - - tcc_add_pragma_libs(s1); - - if (0 == s1->nostdlib) { - static const char *libs[] = { - TCC_LIBTCC1, "msvcrt", "kernel32", "", "user32", "gdi32", NULL - }; - const char **pp, *p; - for (pp = libs; 0 != (p = *pp); ++pp) { - if (0 == *p) { - if (PE_DLL != pe_type && PE_GUI != pe_type) - break; - } else if (pp == libs && tcc_add_dll(s1, p, 0) >= 0) { - continue; - } else { - tcc_add_library_err(s1, p); - } - } - } - - if (TCC_OUTPUT_MEMORY == s1->output_type) - pe_type = PE_RUN; - pe->type = pe_type; - pe->start_symbol = start_symbol; -} - -static void pe_set_options(TCCState * s1, struct pe_info *pe) -{ - if (PE_DLL == pe->type) { - /* XXX: check if is correct for arm-pe target */ - pe->imagebase = 0x10000000; - } else { -#if defined(TCC_TARGET_ARM) - pe->imagebase = 0x00010000; -#else - pe->imagebase = 0x00400000; -#endif - } - -#if defined(TCC_TARGET_ARM) - /* we use "console" subsystem by default */ - pe->subsystem = 9; -#else - if (PE_DLL == pe->type || PE_GUI == pe->type) - pe->subsystem = 2; - else - pe->subsystem = 3; -#endif - /* Allow override via -Wl,-subsystem=... option */ - if (s1->pe_subsystem != 0) - pe->subsystem = s1->pe_subsystem; - - /* set default file/section alignment */ - if (pe->subsystem == 1) { - pe->section_align = 0x20; - pe->file_align = 0x20; - } else { - pe->section_align = 0x1000; - pe->file_align = 0x200; - } - - if (s1->section_align != 0) - pe->section_align = s1->section_align; - if (s1->pe_file_align != 0) - pe->file_align = s1->pe_file_align; - - if ((pe->subsystem >= 10) && (pe->subsystem <= 12)) - pe->imagebase = 0; - - if (s1->has_text_addr) - pe->imagebase = s1->text_addr; -} - -ST_FUNC int pe_output_file(TCCState *s1, const char *filename) -{ - int ret; - struct pe_info pe; - int i; - - memset(&pe, 0, sizeof pe); - pe.filename = filename; - pe.s1 = s1; - - tcc_add_bcheck(s1); - pe_add_runtime(s1, &pe); - resolve_common_syms(s1); - pe_set_options(s1, &pe); - - ret = pe_check_symbols(&pe); - if (ret) - ; - else if (filename) { - pe_assign_addresses(&pe); - relocate_syms(s1, s1->symtab, 0); - s1->pe_imagebase = pe.imagebase; - for (i = 1; i < s1->nb_sections; ++i) { - Section *s = s1->sections[i]; - if (s->reloc) { - relocate_section(s1, s); - } - } - pe.start_addr = (DWORD) - ((uintptr_t)tcc_get_symbol_err(s1, pe.start_symbol) - - pe.imagebase); - if (s1->nb_errors) - ret = -1; - else - ret = pe_write(&pe); - tcc_free(pe.sec_info); - } else { -#ifdef TCC_IS_NATIVE - pe.thunk = data_section; - pe_build_imports(&pe); - s1->runtime_main = pe.start_symbol; -#ifdef TCC_TARGET_X86_64 - s1->uw_pdata = find_section(s1, ".pdata"); -#endif -#endif - } - - pe_free_imports(&pe); - -#ifdef PE_PRINT_SECTIONS - pe_print_sections(s1, "tcc.log"); -#endif - return ret; -} - -/* ------------------------------------------------------------- */ diff --git a/05/tcc-final-old/tccpp.c b/05/tcc-final-old/tccpp.c deleted file mode 100644 index 76f9e42..0000000 --- a/05/tcc-final-old/tccpp.c +++ /dev/null @@ -1,3903 +0,0 @@ -/* - * TCC - Tiny C Compiler - * - * Copyright (c) 2001-2004 Fabrice Bellard - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "tcc.h" - -/********************************************************/ -/* global variables */ - -ST_DATA int tok_flags; -ST_DATA int parse_flags; - -ST_DATA struct BufferedFile *file; -ST_DATA int ch, tok; -ST_DATA CValue tokc; -ST_DATA const int *macro_ptr; -ST_DATA CString tokcstr; /* current parsed string, if any */ - -/* display benchmark infos */ -ST_DATA int total_lines; -ST_DATA int total_bytes; -ST_DATA int tok_ident; -ST_DATA TokenSym **table_ident; - -/* ------------------------------------------------------------------------- */ - -static TokenSym *hash_ident[TOK_HASH_SIZE]; -static char token_buf[STRING_MAX_SIZE + 1]; -static CString cstr_buf; -static CString macro_equal_buf; -static TokenString tokstr_buf; -static unsigned char isidnum_table[256 - CH_EOF]; -static int pp_debug_tok, pp_debug_symv; -static int pp_once; -static int pp_expr; -static int pp_counter; -static void tok_print(const char *msg, const int *str); - -static struct TinyAlloc *toksym_alloc; -static struct TinyAlloc *tokstr_alloc; -static struct TinyAlloc *cstr_alloc; - -static TokenString *macro_stack; - -static const char tcc_keywords[] = -#define DEF(id, str) str "\0" -#include "tcctok.h" -#undef DEF -; - -/* WARNING: the content of this string encodes token numbers */ -static const unsigned char tok_two_chars[] = -/* outdated -- gr - "<=\236>=\235!=\225&&\240||\241++\244--\242==\224<<\1>>\2+=\253" - "-=\255*=\252/=\257%=\245&=\246^=\336|=\374->\313..\250##\266"; -*/{ - '<','=', TOK_LE, - '>','=', TOK_GE, - '!','=', TOK_NE, - '&','&', TOK_LAND, - '|','|', TOK_LOR, - '+','+', TOK_INC, - '-','-', TOK_DEC, - '=','=', TOK_EQ, - '<','<', TOK_SHL, - '>','>', TOK_SAR, - '+','=', TOK_A_ADD, - '-','=', TOK_A_SUB, - '*','=', TOK_A_MUL, - '/','=', TOK_A_DIV, - '%','=', TOK_A_MOD, - '&','=', TOK_A_AND, - '^','=', TOK_A_XOR, - '|','=', TOK_A_OR, - '-','>', TOK_ARROW, - '.','.', TOK_TWODOTS, - '#','#', TOK_TWOSHARPS, - 0 -}; - -static void next_nomacro_spc(void); - -ST_FUNC void skip(int c) -{ - if (tok != c) - tcc_error("'%c' expected (got \"%s\")", c, get_tok_str(tok, &tokc)); - next(); -} - -ST_FUNC void expect(const char *msg) -{ - tcc_error("%s expected", msg); -} - -/* ------------------------------------------------------------------------- */ -/* Custom allocator for tiny objects */ - -#define USE_TAL - -#ifndef USE_TAL -#define tal_free(al, p) tcc_free(p) -#define tal_realloc(al, p, size) tcc_realloc(p, size) -#define tal_new(a,b,c) -#define tal_delete(a) -#else -#if !defined(MEM_DEBUG) -#define tal_free(al, p) tal_free_impl(al, p) -#define tal_realloc(al, p, size) tal_realloc_impl(&al, p, size) -#define TAL_DEBUG_PARAMS -#else -#define TAL_DEBUG 1 -//#define TAL_INFO 1 /* collect and dump allocators stats */ -#define tal_free(al, p) tal_free_impl(al, p, __FILE__, __LINE__) -#define tal_realloc(al, p, size) tal_realloc_impl(&al, p, size, __FILE__, __LINE__) -#define TAL_DEBUG_PARAMS , const char *file, int line -#define TAL_DEBUG_FILE_LEN 40 -#endif - -#define TOKSYM_TAL_SIZE (768 * 1024) /* allocator for tiny TokenSym in table_ident */ -#define TOKSTR_TAL_SIZE (768 * 1024) /* allocator for tiny TokenString instances */ -#define CSTR_TAL_SIZE (256 * 1024) /* allocator for tiny CString instances */ -#define TOKSYM_TAL_LIMIT 256 /* prefer unique limits to distinguish allocators debug msgs */ -#define TOKSTR_TAL_LIMIT 128 /* 32 * sizeof(int) */ -#define CSTR_TAL_LIMIT 1024 - -typedef struct TinyAlloc { - unsigned limit; - unsigned size; - uint8_t *buffer; - uint8_t *p; - unsigned nb_allocs; - struct TinyAlloc *next, *top; -#ifdef TAL_INFO - unsigned nb_peak; - unsigned nb_total; - unsigned nb_missed; - uint8_t *peak_p; -#endif -} TinyAlloc; - -typedef struct tal_header_t { - unsigned size; -#ifdef TAL_DEBUG - int line_num; /* negative line_num used for double free check */ - char file_name[TAL_DEBUG_FILE_LEN + 1]; -#endif -} tal_header_t; - -/* ------------------------------------------------------------------------- */ - -static TinyAlloc *tal_new(TinyAlloc **pal, unsigned limit, unsigned size) -{ - TinyAlloc *al = tcc_mallocz(sizeof(TinyAlloc)); - al->p = al->buffer = tcc_malloc(size); - al->limit = limit; - al->size = size; - if (pal) *pal = al; - return al; -} - -static void tal_delete(TinyAlloc *al) -{ - TinyAlloc *next; - -tail_call: - if (!al) - return; -#ifdef TAL_INFO - fprintf(stderr, "limit=%5d, size=%5g MB, nb_peak=%6d, nb_total=%8d, nb_missed=%6d, usage=%5.1f%%\n", - al->limit, al->size / 1024.0 / 1024.0, al->nb_peak, al->nb_total, al->nb_missed, - (al->peak_p - al->buffer) * 100.0 / al->size); -#endif -#ifdef TAL_DEBUG - if (al->nb_allocs > 0) { - uint8_t *p; - fprintf(stderr, "TAL_DEBUG: memory leak %d chunk(s) (limit= %d)\n", - al->nb_allocs, al->limit); - p = al->buffer; - while (p < al->p) { - tal_header_t *header = (tal_header_t *)p; - if (header->line_num > 0) { - fprintf(stderr, "%s:%d: chunk of %d bytes leaked\n", - header->file_name, header->line_num, header->size); - } - p += header->size + sizeof(tal_header_t); - } -#if MEM_DEBUG-0 == 2 - exit(2); -#endif - } -#endif - next = al->next; - tcc_free(al->buffer); - tcc_free(al); - al = next; - goto tail_call; -} - -static void tal_free_impl(TinyAlloc *al, void *p TAL_DEBUG_PARAMS) -{ - if (!p) - return; -tail_call: - if (al->buffer <= (uint8_t *)p && (uint8_t *)p < al->buffer + al->size) { -#ifdef TAL_DEBUG - tal_header_t *header = (((tal_header_t *)p) - 1); - if (header->line_num < 0) { - fprintf(stderr, "%s:%d: TAL_DEBUG: double frees chunk from\n", - file, line); - fprintf(stderr, "%s:%d: %d bytes\n", - header->file_name, (int)-header->line_num, (int)header->size); - } else - header->line_num = -header->line_num; -#endif - al->nb_allocs--; - if (!al->nb_allocs) - al->p = al->buffer; - } else if (al->next) { - al = al->next; - goto tail_call; - } - else - tcc_free(p); -} - -static void *tal_realloc_impl(TinyAlloc **pal, void *p, unsigned size TAL_DEBUG_PARAMS) -{ - tal_header_t *header; - void *ret; - int is_own; - unsigned adj_size = (size + 3) & -4; - TinyAlloc *al = *pal; - -tail_call: - is_own = (al->buffer <= (uint8_t *)p && (uint8_t *)p < al->buffer + al->size); - if ((!p || is_own) && size <= al->limit) { - if (al->p + adj_size + sizeof(tal_header_t) < al->buffer + al->size) { - header = (tal_header_t *)al->p; - header->size = adj_size; -#ifdef TAL_DEBUG - { int ofs = strlen(file) - TAL_DEBUG_FILE_LEN; - strncpy(header->file_name, file + (ofs > 0 ? ofs : 0), TAL_DEBUG_FILE_LEN); - header->file_name[TAL_DEBUG_FILE_LEN] = 0; - header->line_num = line; } -#endif - ret = al->p + sizeof(tal_header_t); - al->p += adj_size + sizeof(tal_header_t); - if (is_own) { - header = (((tal_header_t *)p) - 1); - memcpy(ret, p, header->size); -#ifdef TAL_DEBUG - header->line_num = -header->line_num; -#endif - } else { - al->nb_allocs++; - } -#ifdef TAL_INFO - if (al->nb_peak < al->nb_allocs) - al->nb_peak = al->nb_allocs; - if (al->peak_p < al->p) - al->peak_p = al->p; - al->nb_total++; -#endif - return ret; - } else if (is_own) { - al->nb_allocs--; - ret = tal_realloc(*pal, 0, size); - header = (((tal_header_t *)p) - 1); - memcpy(ret, p, header->size); -#ifdef TAL_DEBUG - header->line_num = -header->line_num; -#endif - return ret; - } - if (al->next) { - al = al->next; - } else { - TinyAlloc *bottom = al, *next = al->top ? al->top : al; - - al = tal_new(pal, next->limit, next->size * 2); - al->next = next; - bottom->top = al; - } - goto tail_call; - } - if (is_own) { - al->nb_allocs--; - ret = tcc_malloc(size); - header = (((tal_header_t *)p) - 1); - memcpy(ret, p, header->size); -#ifdef TAL_DEBUG - header->line_num = -header->line_num; -#endif - } else if (al->next) { - al = al->next; - goto tail_call; - } else - ret = tcc_realloc(p, size); -#ifdef TAL_INFO - al->nb_missed++; -#endif - return ret; -} - -#endif /* USE_TAL */ - -/* ------------------------------------------------------------------------- */ -/* CString handling */ -static void cstr_realloc(CString *cstr, int new_size) -{ - int size; - - size = cstr->size_allocated; - if (size < 8) - size = 8; /* no need to allocate a too small first string */ - while (size < new_size) - size = size * 2; - cstr->data = tal_realloc(cstr_alloc, cstr->data, size); - cstr->size_allocated = size; -} - -/* add a byte */ -ST_INLN void cstr_ccat(CString *cstr, int ch) -{ - int size; - size = cstr->size + 1; - if (size > cstr->size_allocated) - cstr_realloc(cstr, size); - ((unsigned char *)cstr->data)[size - 1] = ch; - cstr->size = size; -} - -ST_FUNC void cstr_cat(CString *cstr, const char *str, int len) -{ - int size; - if (len <= 0) - len = strlen(str) + 1 + len; - size = cstr->size + len; - if (size > cstr->size_allocated) - cstr_realloc(cstr, size); - memmove(((unsigned char *)cstr->data) + cstr->size, str, len); - cstr->size = size; -} - -/* add a wide char */ -ST_FUNC void cstr_wccat(CString *cstr, int ch) -{ - int size; - size = cstr->size + sizeof(nwchar_t); - if (size > cstr->size_allocated) - cstr_realloc(cstr, size); - *(nwchar_t *)(((unsigned char *)cstr->data) + size - sizeof(nwchar_t)) = ch; - cstr->size = size; -} - -ST_FUNC void cstr_new(CString *cstr) -{ - memset(cstr, 0, sizeof(CString)); -} - -/* free string and reset it to NULL */ -ST_FUNC void cstr_free(CString *cstr) -{ - tal_free(cstr_alloc, cstr->data); - cstr_new(cstr); -} - -/* reset string to empty */ -ST_FUNC void cstr_reset(CString *cstr) -{ - cstr->size = 0; -} - -/* XXX: unicode ? */ -static void add_char(CString *cstr, int c) -{ - if (c == '\'' || c == '\"' || c == '\\') { - /* XXX: could be more precise if char or string */ - cstr_ccat(cstr, '\\'); - } - if (c >= 32 && c <= 126) { - cstr_ccat(cstr, c); - } else { - cstr_ccat(cstr, '\\'); - if (c == '\n') { - cstr_ccat(cstr, 'n'); - } else { - cstr_ccat(cstr, '0' + ((c >> 6) & 7)); - cstr_ccat(cstr, '0' + ((c >> 3) & 7)); - cstr_ccat(cstr, '0' + (c & 7)); - } - } -} - -/* ------------------------------------------------------------------------- */ -/* allocate a new token */ -static TokenSym *tok_alloc_new(TokenSym **pts, const char *str, int len) -{ - TokenSym *ts, **ptable; - int i; - - if (tok_ident >= SYM_FIRST_ANOM) - tcc_error("memory full (symbols)"); - - /* expand token table if needed */ - i = tok_ident - TOK_IDENT; - if ((i % TOK_ALLOC_INCR) == 0) { - ptable = tcc_realloc(table_ident, (i + TOK_ALLOC_INCR) * sizeof(TokenSym *)); - table_ident = ptable; - } - - ts = tal_realloc(toksym_alloc, 0, sizeof(TokenSym) + len); - table_ident[i] = ts; - ts->tok = tok_ident++; - ts->sym_define = NULL; - ts->sym_label = NULL; - ts->sym_struct = NULL; - ts->sym_identifier = NULL; - ts->len = len; - ts->hash_next = NULL; - memcpy(ts->str, str, len); - ts->str[len] = '\0'; - *pts = ts; - return ts; -} - -#define TOK_HASH_INIT 1 -#define TOK_HASH_FUNC(h, c) ((h) + ((h) << 5) + ((h) >> 27) + (c)) - - -/* find a token and add it if not found */ -ST_FUNC TokenSym *tok_alloc(const char *str, int len) -{ - TokenSym *ts, **pts; - int i; - unsigned int h; - - h = TOK_HASH_INIT; - for(i=0;ilen == len && !memcmp(ts->str, str, len)) - return ts; - pts = &(ts->hash_next); - } - return tok_alloc_new(pts, str, len); -} - -/* XXX: buffer overflow */ -/* XXX: float tokens */ -ST_FUNC const char *get_tok_str(int v, CValue *cv) -{ - char *p; - int i, len; - - cstr_reset(&cstr_buf); - p = cstr_buf.data; - - switch(v) { - case TOK_CINT: - case TOK_CUINT: - case TOK_CLONG: - case TOK_CULONG: - case TOK_CLLONG: - case TOK_CULLONG: - /* XXX: not quite exact, but only useful for testing */ -#ifdef _WIN32 - sprintf(p, "%u", (unsigned)cv->i); -#else - sprintf(p, "%llu", (unsigned long long)cv->i); -#endif - break; - case TOK_LCHAR: - cstr_ccat(&cstr_buf, 'L'); - case TOK_CCHAR: - cstr_ccat(&cstr_buf, '\''); - add_char(&cstr_buf, cv->i); - cstr_ccat(&cstr_buf, '\''); - cstr_ccat(&cstr_buf, '\0'); - break; - case TOK_PPNUM: - case TOK_PPSTR: - return (char*)cv->str.data; - case TOK_LSTR: - cstr_ccat(&cstr_buf, 'L'); - case TOK_STR: - cstr_ccat(&cstr_buf, '\"'); - if (v == TOK_STR) { - len = cv->str.size - 1; - for(i=0;istr.data)[i]); - } else { - len = (cv->str.size / sizeof(nwchar_t)) - 1; - for(i=0;istr.data)[i]); - } - cstr_ccat(&cstr_buf, '\"'); - cstr_ccat(&cstr_buf, '\0'); - break; - - case TOK_CFLOAT: - cstr_cat(&cstr_buf, "", 0); - break; - case TOK_CDOUBLE: - cstr_cat(&cstr_buf, "", 0); - break; - case TOK_CLDOUBLE: - cstr_cat(&cstr_buf, "", 0); - break; - case TOK_LINENUM: - cstr_cat(&cstr_buf, "", 0); - break; - - /* above tokens have value, the ones below don't */ - case TOK_LT: - v = '<'; - goto addv; - case TOK_GT: - v = '>'; - goto addv; - case TOK_DOTS: - return strcpy(p, "..."); - case TOK_A_SHL: - return strcpy(p, "<<="); - case TOK_A_SAR: - return strcpy(p, ">>="); - case TOK_EOF: - return strcpy(p, ""); - default: - if (v < TOK_IDENT) { - /* search in two bytes table */ - const unsigned char *q = tok_two_chars; - while (*q) { - if (q[2] == v) { - *p++ = q[0]; - *p++ = q[1]; - *p = '\0'; - return cstr_buf.data; - } - q += 3; - } - if (v >= 127) { - sprintf(cstr_buf.data, "<%02x>", v); - return cstr_buf.data; - } - addv: - *p++ = v; - *p = '\0'; - } else if (v < tok_ident) { - return table_ident[v - TOK_IDENT]->str; - } else if (v >= SYM_FIRST_ANOM) { - /* special name for anonymous symbol */ - sprintf(p, "L.%u", v - SYM_FIRST_ANOM); - } else { - /* should never happen */ - return NULL; - } - break; - } - return cstr_buf.data; -} - -/* return the current character, handling end of block if necessary - (but not stray) */ -ST_FUNC int handle_eob(void) -{ - BufferedFile *bf = file; - int len; - - /* only tries to read if really end of buffer */ - if (bf->buf_ptr >= bf->buf_end) { - if (bf->fd >= 0) { -#if defined(PARSE_DEBUG) - len = 1; -#else - len = IO_BUF_SIZE; -#endif - len = read(bf->fd, bf->buffer, len); - if (len < 0) - len = 0; - } else { - len = 0; - } - total_bytes += len; - bf->buf_ptr = bf->buffer; - bf->buf_end = bf->buffer + len; - *bf->buf_end = CH_EOB; - } - if (bf->buf_ptr < bf->buf_end) { - return bf->buf_ptr[0]; - } else { - bf->buf_ptr = bf->buf_end; - return CH_EOF; - } -} - -/* read next char from current input file and handle end of input buffer */ -ST_INLN void inp(void) -{ - ch = *(++(file->buf_ptr)); - /* end of buffer/file handling */ - if (ch == CH_EOB) - ch = handle_eob(); -} - -/* handle '\[\r]\n' */ -static int handle_stray_noerror(void) -{ - while (ch == '\\') { - inp(); - if (ch == '\n') { - file->line_num++; - inp(); - } else if (ch == '\r') { - inp(); - if (ch != '\n') - goto fail; - file->line_num++; - inp(); - } else { - fail: - return 1; - } - } - return 0; -} - -static void handle_stray(void) -{ - if (handle_stray_noerror()) - tcc_error("stray '\\' in program"); -} - -/* skip the stray and handle the \\n case. Output an error if - incorrect char after the stray */ -static int handle_stray1(uint8_t *p) -{ - int c; - - file->buf_ptr = p; - if (p >= file->buf_end) { - c = handle_eob(); - if (c != '\\') - return c; - p = file->buf_ptr; - } - ch = *p; - if (handle_stray_noerror()) { - if (!(parse_flags & PARSE_FLAG_ACCEPT_STRAYS)) - tcc_error("stray '\\' in program"); - *--file->buf_ptr = '\\'; - } - p = file->buf_ptr; - c = *p; - return c; -} - -/* handle just the EOB case, but not stray */ -#define PEEKC_EOB(c, p)\ -{\ - p++;\ - c = *p;\ - if (c == '\\') {\ - file->buf_ptr = p;\ - c = handle_eob();\ - p = file->buf_ptr;\ - }\ -} - -/* handle the complicated stray case */ -#define PEEKC(c, p)\ -{\ - p++;\ - c = *p;\ - if (c == '\\') {\ - c = handle_stray1(p);\ - p = file->buf_ptr;\ - }\ -} - -/* input with '\[\r]\n' handling. Note that this function cannot - handle other characters after '\', so you cannot call it inside - strings or comments */ -ST_FUNC void minp(void) -{ - inp(); - if (ch == '\\') - handle_stray(); -} - -/* single line C++ comments */ -static uint8_t *parse_line_comment(uint8_t *p) -{ - int c; - - p++; - for(;;) { - c = *p; - redo: - if (c == '\n' || c == CH_EOF) { - break; - } else if (c == '\\') { - file->buf_ptr = p; - c = handle_eob(); - p = file->buf_ptr; - if (c == '\\') { - PEEKC_EOB(c, p); - if (c == '\n') { - file->line_num++; - PEEKC_EOB(c, p); - } else if (c == '\r') { - PEEKC_EOB(c, p); - if (c == '\n') { - file->line_num++; - PEEKC_EOB(c, p); - } - } - } else { - goto redo; - } - } else { - p++; - } - } - return p; -} - -/* C comments */ -ST_FUNC uint8_t *parse_comment(uint8_t *p) -{ - int c; - - p++; - for(;;) { - /* fast skip loop */ - for(;;) { - c = *p; - if (c == '\n' || c == '*' || c == '\\') - break; - p++; - c = *p; - if (c == '\n' || c == '*' || c == '\\') - break; - p++; - } - /* now we can handle all the cases */ - if (c == '\n') { - file->line_num++; - p++; - } else if (c == '*') { - p++; - for(;;) { - c = *p; - if (c == '*') { - p++; - } else if (c == '/') { - goto end_of_comment; - } else if (c == '\\') { - file->buf_ptr = p; - c = handle_eob(); - p = file->buf_ptr; - if (c == CH_EOF) - tcc_error("unexpected end of file in comment"); - if (c == '\\') { - /* skip '\[\r]\n', otherwise just skip the stray */ - while (c == '\\') { - PEEKC_EOB(c, p); - if (c == '\n') { - file->line_num++; - PEEKC_EOB(c, p); - } else if (c == '\r') { - PEEKC_EOB(c, p); - if (c == '\n') { - file->line_num++; - PEEKC_EOB(c, p); - } - } else { - goto after_star; - } - } - } - } else { - break; - } - } - after_star: ; - } else { - /* stray, eob or eof */ - file->buf_ptr = p; - c = handle_eob(); - p = file->buf_ptr; - if (c == CH_EOF) { - tcc_error("unexpected end of file in comment"); - } else if (c == '\\') { - p++; - } - } - } - end_of_comment: - p++; - return p; -} - -ST_FUNC int set_idnum(int c, int val) -{ - int prev = isidnum_table[c - CH_EOF]; - isidnum_table[c - CH_EOF] = val; - return prev; -} - -#define cinp minp - -static inline void skip_spaces(void) -{ - while (isidnum_table[ch - CH_EOF] & IS_SPC) - cinp(); -} - -static inline int check_space(int t, int *spc) -{ - if (t < 256 && (isidnum_table[t - CH_EOF] & IS_SPC)) { - if (*spc) - return 1; - *spc = 1; - } else - *spc = 0; - return 0; -} - -/* parse a string without interpreting escapes */ -static uint8_t *parse_pp_string(uint8_t *p, - int sep, CString *str) -{ - int c; - p++; - for(;;) { - c = *p; - if (c == sep) { - break; - } else if (c == '\\') { - file->buf_ptr = p; - c = handle_eob(); - p = file->buf_ptr; - if (c == CH_EOF) { - unterminated_string: - /* XXX: indicate line number of start of string */ - tcc_error("missing terminating %c character", sep); - } else if (c == '\\') { - /* escape : just skip \[\r]\n */ - PEEKC_EOB(c, p); - if (c == '\n') { - file->line_num++; - p++; - } else if (c == '\r') { - PEEKC_EOB(c, p); - if (c != '\n') - expect("'\n' after '\r'"); - file->line_num++; - p++; - } else if (c == CH_EOF) { - goto unterminated_string; - } else { - if (str) { - cstr_ccat(str, '\\'); - cstr_ccat(str, c); - } - p++; - } - } - } else if (c == '\n') { - file->line_num++; - goto add_char; - } else if (c == '\r') { - PEEKC_EOB(c, p); - if (c != '\n') { - if (str) - cstr_ccat(str, '\r'); - } else { - file->line_num++; - goto add_char; - } - } else { - add_char: - if (str) - cstr_ccat(str, c); - p++; - } - } - p++; - return p; -} - -/* skip block of text until #else, #elif or #endif. skip also pairs of - #if/#endif */ -static void preprocess_skip(void) -{ - int a, start_of_line, c, in_warn_or_error; - uint8_t *p; - - p = file->buf_ptr; - a = 0; -redo_start: - start_of_line = 1; - in_warn_or_error = 0; - for(;;) { - redo_no_start: - c = *p; - switch(c) { - case ' ': - case '\t': - case '\f': - case '\v': - case '\r': - p++; - goto redo_no_start; - case '\n': - file->line_num++; - p++; - goto redo_start; - case '\\': - file->buf_ptr = p; - c = handle_eob(); - if (c == CH_EOF) { - expect("#endif"); - } else if (c == '\\') { - ch = file->buf_ptr[0]; - handle_stray_noerror(); - } - p = file->buf_ptr; - goto redo_no_start; - /* skip strings */ - case '\"': - case '\'': - if (in_warn_or_error) - goto _default; - p = parse_pp_string(p, c, NULL); - break; - /* skip comments */ - case '/': - if (in_warn_or_error) - goto _default; - file->buf_ptr = p; - ch = *p; - minp(); - p = file->buf_ptr; - if (ch == '*') { - p = parse_comment(p); - } else if (ch == '/') { - p = parse_line_comment(p); - } - break; - case '#': - p++; - if (start_of_line) { - file->buf_ptr = p; - next_nomacro(); - p = file->buf_ptr; - if (a == 0 && - (tok == TOK_ELSE || tok == TOK_ELIF || tok == TOK_ENDIF)) - goto the_end; - if (tok == TOK_IF || tok == TOK_IFDEF || tok == TOK_IFNDEF) - a++; - else if (tok == TOK_ENDIF) - a--; - else if( tok == TOK_ERROR || tok == TOK_WARNING) - in_warn_or_error = 1; - else if (tok == TOK_LINEFEED) - goto redo_start; - else if (parse_flags & PARSE_FLAG_ASM_FILE) - p = parse_line_comment(p - 1); - } else if (parse_flags & PARSE_FLAG_ASM_FILE) - p = parse_line_comment(p - 1); - break; -_default: - default: - p++; - break; - } - start_of_line = 0; - } - the_end: ; - file->buf_ptr = p; -} - -#if 0 -/* return the number of additional 'ints' necessary to store the - token */ -static inline int tok_size(const int *p) -{ - switch(*p) { - /* 4 bytes */ - case TOK_CINT: - case TOK_CUINT: - case TOK_CCHAR: - case TOK_LCHAR: - case TOK_CFLOAT: - case TOK_LINENUM: - return 1 + 1; - case TOK_STR: - case TOK_LSTR: - case TOK_PPNUM: - case TOK_PPSTR: - return 1 + ((sizeof(CString) + ((CString *)(p+1))->size + 3) >> 2); - case TOK_CLONG: - case TOK_CULONG: - return 1 + LONG_SIZE / 4; - case TOK_CDOUBLE: - case TOK_CLLONG: - case TOK_CULLONG: - return 1 + 2; - case TOK_CLDOUBLE: - return 1 + LDOUBLE_SIZE / 4; - default: - return 1 + 0; - } -} -#endif - -/* token string handling */ -ST_INLN void tok_str_new(TokenString *s) -{ - s->str = NULL; - s->len = s->lastlen = 0; - s->allocated_len = 0; - s->last_line_num = -1; -} - -ST_FUNC TokenString *tok_str_alloc(void) -{ - TokenString *str = tal_realloc(tokstr_alloc, 0, sizeof *str); - tok_str_new(str); - return str; -} - -ST_FUNC int *tok_str_dup(TokenString *s) -{ - int *str; - - str = tal_realloc(tokstr_alloc, 0, s->len * sizeof(int)); - memcpy(str, s->str, s->len * sizeof(int)); - return str; -} - -ST_FUNC void tok_str_free_str(int *str) -{ - tal_free(tokstr_alloc, str); -} - -ST_FUNC void tok_str_free(TokenString *str) -{ - tok_str_free_str(str->str); - tal_free(tokstr_alloc, str); -} - -ST_FUNC int *tok_str_realloc(TokenString *s, int new_size) -{ - int *str, size; - - size = s->allocated_len; - if (size < 16) - size = 16; - while (size < new_size) - size = size * 2; - if (size > s->allocated_len) { - str = tal_realloc(tokstr_alloc, s->str, size * sizeof(int)); - s->allocated_len = size; - s->str = str; - } - return s->str; -} - -ST_FUNC void tok_str_add(TokenString *s, int t) -{ - int len, *str; - - len = s->len; - str = s->str; - if (len >= s->allocated_len) - str = tok_str_realloc(s, len + 1); - str[len++] = t; - s->len = len; -} - -ST_FUNC void begin_macro(TokenString *str, int alloc) -{ - str->alloc = alloc; - str->prev = macro_stack; - str->prev_ptr = macro_ptr; - str->save_line_num = file->line_num; - macro_ptr = str->str; - macro_stack = str; -} - -ST_FUNC void end_macro(void) -{ - TokenString *str = macro_stack; - macro_stack = str->prev; - macro_ptr = str->prev_ptr; - file->line_num = str->save_line_num; - if (str->alloc == 2) { - str->alloc = 3; /* just mark as finished */ - } else { - tok_str_free(str); - } -} - -static void tok_str_add2(TokenString *s, int t, CValue *cv) -{ - int len, *str; - - len = s->lastlen = s->len; - str = s->str; - - /* allocate space for worst case */ - if (len + TOK_MAX_SIZE >= s->allocated_len) - str = tok_str_realloc(s, len + TOK_MAX_SIZE + 1); - str[len++] = t; - switch(t) { - case TOK_CINT: - case TOK_CUINT: - case TOK_CCHAR: - case TOK_LCHAR: - case TOK_CFLOAT: - case TOK_LINENUM: -#if LONG_SIZE == 4 - case TOK_CLONG: - case TOK_CULONG: -#endif - str[len++] = cv->tab[0]; - break; - case TOK_PPNUM: - case TOK_PPSTR: - case TOK_STR: - case TOK_LSTR: - { - /* Insert the string into the int array. */ - size_t nb_words = - 1 + (cv->str.size + sizeof(int) - 1) / sizeof(int); - if (len + nb_words >= s->allocated_len) - str = tok_str_realloc(s, len + nb_words + 1); - str[len] = cv->str.size; - memcpy(&str[len + 1], cv->str.data, cv->str.size); - len += nb_words; - } - break; - case TOK_CDOUBLE: - case TOK_CLLONG: - case TOK_CULLONG: -#if LONG_SIZE == 8 - case TOK_CLONG: - case TOK_CULONG: -#endif -#if LDOUBLE_SIZE == 8 - case TOK_CLDOUBLE: -#endif - str[len++] = cv->tab[0]; - str[len++] = cv->tab[1]; - break; -#if LDOUBLE_SIZE == 12 - case TOK_CLDOUBLE: - str[len++] = cv->tab[0]; - str[len++] = cv->tab[1]; - str[len++] = cv->tab[2]; -#elif LDOUBLE_SIZE == 16 - case TOK_CLDOUBLE: - str[len++] = cv->tab[0]; - str[len++] = cv->tab[1]; - str[len++] = cv->tab[2]; - str[len++] = cv->tab[3]; -#elif LDOUBLE_SIZE != 8 -#error add long double size support -#endif - break; - default: - break; - } - s->len = len; -} - -/* add the current parse token in token string 's' */ -ST_FUNC void tok_str_add_tok(TokenString *s) -{ - CValue cval; - - /* save line number info */ - if (file->line_num != s->last_line_num) { - s->last_line_num = file->line_num; - cval.i = s->last_line_num; - tok_str_add2(s, TOK_LINENUM, &cval); - } - tok_str_add2(s, tok, &tokc); -} - -/* get a token from an integer array and increment pointer - accordingly. we code it as a macro to avoid pointer aliasing. */ -static inline void TOK_GET(int *t, const int **pp, CValue *cv) -{ - const int *p = *pp; - int n, *tab; - - tab = cv->tab; - switch(*t = *p++) { -#if LONG_SIZE == 4 - case TOK_CLONG: -#endif - case TOK_CINT: - case TOK_CCHAR: - case TOK_LCHAR: - case TOK_LINENUM: - cv->i = *p++; - break; -#if LONG_SIZE == 4 - case TOK_CULONG: -#endif - case TOK_CUINT: - cv->i = (unsigned)*p++; - break; - case TOK_CFLOAT: - tab[0] = *p++; - break; - case TOK_STR: - case TOK_LSTR: - case TOK_PPNUM: - case TOK_PPSTR: - cv->str.size = *p++; - cv->str.data = p; - p += (cv->str.size + sizeof(int) - 1) / sizeof(int); - break; - case TOK_CDOUBLE: - case TOK_CLLONG: - case TOK_CULLONG: -#if LONG_SIZE == 8 - case TOK_CLONG: - case TOK_CULONG: -#endif - n = 2; - goto copy; - case TOK_CLDOUBLE: -#if LDOUBLE_SIZE == 16 - n = 4; -#elif LDOUBLE_SIZE == 12 - n = 3; -#elif LDOUBLE_SIZE == 8 - n = 2; -#else -# error add long double size support -#endif - copy: - do - *tab++ = *p++; - while (--n); - break; - default: - break; - } - *pp = p; -} - -static int macro_is_equal(const int *a, const int *b) -{ - CValue cv; - int t; - - if (!a || !b) - return 1; - - while (*a && *b) { - /* first time preallocate macro_equal_buf, next time only reset position to start */ - cstr_reset(¯o_equal_buf); - TOK_GET(&t, &a, &cv); - cstr_cat(¯o_equal_buf, get_tok_str(t, &cv), 0); - TOK_GET(&t, &b, &cv); - if (strcmp(macro_equal_buf.data, get_tok_str(t, &cv))) - return 0; - } - return !(*a || *b); -} - -/* defines handling */ -ST_INLN void define_push(int v, int macro_type, int *str, Sym *first_arg) -{ - Sym *s, *o; - - o = define_find(v); - s = sym_push2(&define_stack, v, macro_type, 0); - s->d = str; - s->next = first_arg; - table_ident[v - TOK_IDENT]->sym_define = s; - - if (o && !macro_is_equal(o->d, s->d)) - tcc_warning("%s redefined", get_tok_str(v, NULL)); -} - -/* undefined a define symbol. Its name is just set to zero */ -ST_FUNC void define_undef(Sym *s) -{ - int v = s->v; - if (v >= TOK_IDENT && v < tok_ident) - table_ident[v - TOK_IDENT]->sym_define = NULL; -} - -ST_INLN Sym *define_find(int v) -{ - v -= TOK_IDENT; - if ((unsigned)v >= (unsigned)(tok_ident - TOK_IDENT)) - return NULL; - return table_ident[v]->sym_define; -} - -/* free define stack until top reaches 'b' */ -ST_FUNC void free_defines(Sym *b) -{ - while (define_stack != b) { - Sym *top = define_stack; - define_stack = top->prev; - tok_str_free_str(top->d); - define_undef(top); - sym_free(top); - } - - /* restore remaining (-D or predefined) symbols if they were - #undef'd in the file */ - while (b) { - int v = b->v; - if (v >= TOK_IDENT && v < tok_ident) { - Sym **d = &table_ident[v - TOK_IDENT]->sym_define; - if (!*d) - *d = b; - } - b = b->prev; - } -} - -/* label lookup */ -ST_FUNC Sym *label_find(int v) -{ - v -= TOK_IDENT; - if ((unsigned)v >= (unsigned)(tok_ident - TOK_IDENT)) - return NULL; - return table_ident[v]->sym_label; -} - -ST_FUNC Sym *label_push(Sym **ptop, int v, int flags) -{ - Sym *s, **ps; - s = sym_push2(ptop, v, 0, 0); - s->r = flags; - ps = &table_ident[v - TOK_IDENT]->sym_label; - if (ptop == &global_label_stack) { - /* modify the top most local identifier, so that - sym_identifier will point to 's' when popped */ - while (*ps != NULL) - ps = &(*ps)->prev_tok; - } - s->prev_tok = *ps; - *ps = s; - return s; -} - -/* pop labels until element last is reached. Look if any labels are - undefined. Define symbols if '&&label' was used. */ -ST_FUNC void label_pop(Sym **ptop, Sym *slast, int keep) -{ - Sym *s, *s1; - for(s = *ptop; s != slast; s = s1) { - s1 = s->prev; - if (s->r == LABEL_DECLARED) { - tcc_warning("label '%s' declared but not used", get_tok_str(s->v, NULL)); - } else if (s->r == LABEL_FORWARD) { - tcc_error("label '%s' used but not defined", - get_tok_str(s->v, NULL)); - } else { - if (s->c) { - /* define corresponding symbol. A size of - 1 is put. */ - put_extern_sym(s, cur_text_section, s->jnext, 1); - } - } - /* remove label */ - table_ident[s->v - TOK_IDENT]->sym_label = s->prev_tok; - if (!keep) - sym_free(s); - } - if (!keep) - *ptop = slast; -} - -/* fake the nth "#if defined test_..." for tcc -dt -run */ -static void maybe_run_test(TCCState *s) -{ - const char *p; - if (s->include_stack_ptr != s->include_stack) - return; - p = get_tok_str(tok, NULL); - if (0 != memcmp(p, "test_", 5)) - return; - if (0 != --s->run_test) - return; - fprintf(s->ppfp, "\n[%s]\n" + !(s->dflag & 32), p), fflush(s->ppfp); - define_push(tok, MACRO_OBJ, NULL, NULL); -} - -/* eval an expression for #if/#elif */ -static int expr_preprocess(void) -{ - int c, t; - TokenString *str; - - str = tok_str_alloc(); - pp_expr = 1; - while (tok != TOK_LINEFEED && tok != TOK_EOF) { - next(); /* do macro subst */ - if (tok == TOK_DEFINED) { - next_nomacro(); - t = tok; - if (t == '(') - next_nomacro(); - if (tok < TOK_IDENT) - expect("identifier"); - if (tcc_state->run_test) - maybe_run_test(tcc_state); - c = define_find(tok) != 0; - if (t == '(') { - next_nomacro(); - if (tok != ')') - expect("')'"); - } - tok = TOK_CINT; - tokc.i = c; - } else if (tok >= TOK_IDENT) { - /* if undefined macro */ - tok = TOK_CINT; - tokc.i = 0; - } - tok_str_add_tok(str); - } - pp_expr = 0; - tok_str_add(str, -1); /* simulate end of file */ - tok_str_add(str, 0); - /* now evaluate C constant expression */ - begin_macro(str, 1); - next(); - c = expr_const(); - end_macro(); - return c != 0; -} - - -/* parse after #define */ -ST_FUNC void parse_define(void) -{ - Sym *s, *first, **ps; - int v, t, varg, is_vaargs, spc; - int saved_parse_flags = parse_flags; - - v = tok; - if (v < TOK_IDENT || v == TOK_DEFINED) - tcc_error("invalid macro name '%s'", get_tok_str(tok, &tokc)); - /* XXX: should check if same macro (ANSI) */ - first = NULL; - t = MACRO_OBJ; - /* We have to parse the whole define as if not in asm mode, in particular - no line comment with '#' must be ignored. Also for function - macros the argument list must be parsed without '.' being an ID - character. */ - parse_flags = ((parse_flags & ~PARSE_FLAG_ASM_FILE) | PARSE_FLAG_SPACES); - /* '(' must be just after macro definition for MACRO_FUNC */ - next_nomacro_spc(); - if (tok == '(') { - int dotid = set_idnum('.', 0); - next_nomacro(); - ps = &first; - if (tok != ')') for (;;) { - varg = tok; - next_nomacro(); - is_vaargs = 0; - if (varg == TOK_DOTS) { - varg = TOK___VA_ARGS__; - is_vaargs = 1; - } else if (tok == TOK_DOTS && gnu_ext) { - is_vaargs = 1; - next_nomacro(); - } - if (varg < TOK_IDENT) - bad_list: - tcc_error("bad macro parameter list"); - s = sym_push2(&define_stack, varg | SYM_FIELD, is_vaargs, 0); - *ps = s; - ps = &s->next; - if (tok == ')') - break; - if (tok != ',' || is_vaargs) - goto bad_list; - next_nomacro(); - } - next_nomacro_spc(); - t = MACRO_FUNC; - set_idnum('.', dotid); - } - - tokstr_buf.len = 0; - spc = 2; - parse_flags |= PARSE_FLAG_ACCEPT_STRAYS | PARSE_FLAG_SPACES | PARSE_FLAG_LINEFEED; - /* The body of a macro definition should be parsed such that identifiers - are parsed like the file mode determines (i.e. with '.' being an - ID character in asm mode). But '#' should be retained instead of - regarded as line comment leader, so still don't set ASM_FILE - in parse_flags. */ - while (tok != TOK_LINEFEED && tok != TOK_EOF) { - /* remove spaces around ## and after '#' */ - if (TOK_TWOSHARPS == tok) { - if (2 == spc) - goto bad_twosharp; - if (1 == spc) - --tokstr_buf.len; - spc = 3; - tok = TOK_PPJOIN; - } else if ('#' == tok) { - spc = 4; - } else if (check_space(tok, &spc)) { - goto skip; - } - tok_str_add2(&tokstr_buf, tok, &tokc); - skip: - next_nomacro_spc(); - } - - parse_flags = saved_parse_flags; - if (spc == 1) - --tokstr_buf.len; /* remove trailing space */ - tok_str_add(&tokstr_buf, 0); - if (3 == spc) -bad_twosharp: - tcc_error("'##' cannot appear at either end of macro"); - define_push(v, t, tok_str_dup(&tokstr_buf), first); -} - -static CachedInclude *search_cached_include(TCCState *s1, const char *filename, int add) -{ - const unsigned char *s; - unsigned int h; - CachedInclude *e; - int i; - - h = TOK_HASH_INIT; - s = (unsigned char *) filename; - while (*s) { -#ifdef _WIN32 - h = TOK_HASH_FUNC(h, toup(*s)); -#else - h = TOK_HASH_FUNC(h, *s); -#endif - s++; - } - h &= (CACHED_INCLUDES_HASH_SIZE - 1); - - i = s1->cached_includes_hash[h]; - for(;;) { - if (i == 0) - break; - e = s1->cached_includes[i - 1]; - if (0 == PATHCMP(e->filename, filename)) - return e; - i = e->hash_next; - } - if (!add) - return NULL; - - e = tcc_malloc(sizeof(CachedInclude) + strlen(filename)); - strcpy(e->filename, filename); - e->ifndef_macro = e->once = 0; - dynarray_add(&s1->cached_includes, &s1->nb_cached_includes, e); - /* add in hash table */ - e->hash_next = s1->cached_includes_hash[h]; - s1->cached_includes_hash[h] = s1->nb_cached_includes; -#ifdef INC_DEBUG - printf("adding cached '%s'\n", filename); -#endif - return e; -} - -static void pragma_parse(TCCState *s1) -{ - next_nomacro(); - if (tok == TOK_push_macro || tok == TOK_pop_macro) { - int t = tok, v; - Sym *s; - - if (next(), tok != '(') - goto pragma_err; - if (next(), tok != TOK_STR) - goto pragma_err; - v = tok_alloc(tokc.str.data, tokc.str.size - 1)->tok; - if (next(), tok != ')') - goto pragma_err; - if (t == TOK_push_macro) { - while (NULL == (s = define_find(v))) - define_push(v, 0, NULL, NULL); - s->type.ref = s; /* set push boundary */ - } else { - for (s = define_stack; s; s = s->prev) - if (s->v == v && s->type.ref == s) { - s->type.ref = NULL; - break; - } - } - if (s) - table_ident[v - TOK_IDENT]->sym_define = s->d ? s : NULL; - else - tcc_warning("unbalanced #pragma pop_macro"); - pp_debug_tok = t, pp_debug_symv = v; - - } else if (tok == TOK_once) { - search_cached_include(s1, file->filename, 1)->once = pp_once; - - } else if (s1->output_type == TCC_OUTPUT_PREPROCESS) { - /* tcc -E: keep pragmas below unchanged */ - unget_tok(' '); - unget_tok(TOK_PRAGMA); - unget_tok('#'); - unget_tok(TOK_LINEFEED); - - } else if (tok == TOK_pack) { - /* This may be: - #pragma pack(1) // set - #pragma pack() // reset to default - #pragma pack(push,1) // push & set - #pragma pack(pop) // restore previous */ - next(); - skip('('); - if (tok == TOK_ASM_pop) { - next(); - if (s1->pack_stack_ptr <= s1->pack_stack) { - stk_error: - tcc_error("out of pack stack"); - } - s1->pack_stack_ptr--; - } else { - int val = 0; - if (tok != ')') { - if (tok == TOK_ASM_push) { - next(); - if (s1->pack_stack_ptr >= s1->pack_stack + PACK_STACK_SIZE - 1) - goto stk_error; - s1->pack_stack_ptr++; - skip(','); - } - if (tok != TOK_CINT) - goto pragma_err; - val = tokc.i; - if (val < 1 || val > 16 || (val & (val - 1)) != 0) - goto pragma_err; - next(); - } - *s1->pack_stack_ptr = val; - } - if (tok != ')') - goto pragma_err; - - } else if (tok == TOK_comment) { - char *p; int t; - next(); - skip('('); - t = tok; - next(); - skip(','); - if (tok != TOK_STR) - goto pragma_err; - p = tcc_strdup((char *)tokc.str.data); - next(); - if (tok != ')') - goto pragma_err; - if (t == TOK_lib) { - dynarray_add(&s1->pragma_libs, &s1->nb_pragma_libs, p); - } else { - if (t == TOK_option) - tcc_set_options(s1, p); - tcc_free(p); - } - - } else if (s1->warn_unsupported) { - tcc_warning("#pragma %s is ignored", get_tok_str(tok, &tokc)); - } - return; - -pragma_err: - tcc_error("malformed #pragma directive"); - return; -} - -/* is_bof is true if first non space token at beginning of file */ -ST_FUNC void preprocess(int is_bof) -{ - TCCState *s1 = tcc_state; - int i, c, n, saved_parse_flags; - char buf[1024], *q; - Sym *s; - - saved_parse_flags = parse_flags; - parse_flags = PARSE_FLAG_PREPROCESS - | PARSE_FLAG_TOK_NUM - | PARSE_FLAG_TOK_STR - | PARSE_FLAG_LINEFEED - | (parse_flags & PARSE_FLAG_ASM_FILE) - ; - - next_nomacro(); - redo: - switch(tok) { - case TOK_DEFINE: - pp_debug_tok = tok; - next_nomacro(); - pp_debug_symv = tok; - parse_define(); - break; - case TOK_UNDEF: - pp_debug_tok = tok; - next_nomacro(); - pp_debug_symv = tok; - s = define_find(tok); - /* undefine symbol by putting an invalid name */ - if (s) - define_undef(s); - break; - case TOK_INCLUDE: - case TOK_INCLUDE_NEXT: - ch = file->buf_ptr[0]; - /* XXX: incorrect if comments : use next_nomacro with a special mode */ - skip_spaces(); - if (ch == '<') { - c = '>'; - goto read_name; - } else if (ch == '\"') { - c = ch; - read_name: - inp(); - q = buf; - while (ch != c && ch != '\n' && ch != CH_EOF) { - if ((q - buf) < sizeof(buf) - 1) - *q++ = ch; - if (ch == '\\') { - if (handle_stray_noerror() == 0) - --q; - } else - inp(); - } - *q = '\0'; - minp(); -#if 0 - /* eat all spaces and comments after include */ - /* XXX: slightly incorrect */ - while (ch1 != '\n' && ch1 != CH_EOF) - inp(); -#endif - } else { - int len; - /* computed #include : concatenate everything up to linefeed, - the result must be one of the two accepted forms. - Don't convert pp-tokens to tokens here. */ - parse_flags = (PARSE_FLAG_PREPROCESS - | PARSE_FLAG_LINEFEED - | (parse_flags & PARSE_FLAG_ASM_FILE)); - next(); - buf[0] = '\0'; - while (tok != TOK_LINEFEED) { - pstrcat(buf, sizeof(buf), get_tok_str(tok, &tokc)); - next(); - } - len = strlen(buf); - /* check syntax and remove '<>|""' */ - if ((len < 2 || ((buf[0] != '"' || buf[len-1] != '"') && - (buf[0] != '<' || buf[len-1] != '>')))) - tcc_error("'#include' expects \"FILENAME\" or "); - c = buf[len-1]; - memmove(buf, buf + 1, len - 2); - buf[len - 2] = '\0'; - } - - if (s1->include_stack_ptr >= s1->include_stack + INCLUDE_STACK_SIZE) - tcc_error("#include recursion too deep"); - /* store current file in stack, but increment stack later below */ - *s1->include_stack_ptr = file; - i = tok == TOK_INCLUDE_NEXT ? file->include_next_index : 0; - n = 2 + s1->nb_include_paths + s1->nb_sysinclude_paths; - for (; i < n; ++i) { - char buf1[sizeof file->filename]; - CachedInclude *e; - const char *path; - - if (i == 0) { - /* check absolute include path */ - if (!IS_ABSPATH(buf)) - continue; - buf1[0] = 0; - - } else if (i == 1) { - /* search in file's dir if "header.h" */ - if (c != '\"') - continue; - /* https://savannah.nongnu.org/bugs/index.php?50847 */ - path = file->true_filename; - pstrncpy(buf1, path, tcc_basename(path) - path); - - } else { - /* search in all the include paths */ - int j = i - 2, k = j - s1->nb_include_paths; - path = k < 0 ? s1->include_paths[j] : s1->sysinclude_paths[k]; - pstrcpy(buf1, sizeof(buf1), path); - pstrcat(buf1, sizeof(buf1), "/"); - } - - pstrcat(buf1, sizeof(buf1), buf); - e = search_cached_include(s1, buf1, 0); - if (e && (define_find(e->ifndef_macro) || e->once == pp_once)) { - /* no need to parse the include because the 'ifndef macro' - is defined (or had #pragma once) */ -#ifdef INC_DEBUG - printf("%s: skipping cached %s\n", file->filename, buf1); -#endif - goto include_done; - } - - if (tcc_open(s1, buf1) < 0) - continue; - - file->include_next_index = i + 1; -#ifdef INC_DEBUG - printf("%s: including %s\n", file->prev->filename, file->filename); -#endif - /* update target deps */ - dynarray_add(&s1->target_deps, &s1->nb_target_deps, - tcc_strdup(buf1)); - /* push current file in stack */ - ++s1->include_stack_ptr; - /* add include file debug info */ - if (s1->do_debug) - put_stabs(file->filename, N_BINCL, 0, 0, 0); - tok_flags |= TOK_FLAG_BOF | TOK_FLAG_BOL; - ch = file->buf_ptr[0]; - goto the_end; - } - tcc_error("include file '%s' not found", buf); -include_done: - break; - case TOK_IFNDEF: - c = 1; - goto do_ifdef; - case TOK_IF: - c = expr_preprocess(); - goto do_if; - case TOK_IFDEF: - c = 0; - do_ifdef: - next_nomacro(); - if (tok < TOK_IDENT) - tcc_error("invalid argument for '#if%sdef'", c ? "n" : ""); - if (is_bof) { - if (c) { -#ifdef INC_DEBUG - printf("#ifndef %s\n", get_tok_str(tok, NULL)); -#endif - file->ifndef_macro = tok; - } - } - c = (define_find(tok) != 0) ^ c; - do_if: - if (s1->ifdef_stack_ptr >= s1->ifdef_stack + IFDEF_STACK_SIZE) - tcc_error("memory full (ifdef)"); - *s1->ifdef_stack_ptr++ = c; - goto test_skip; - case TOK_ELSE: - if (s1->ifdef_stack_ptr == s1->ifdef_stack) - tcc_error("#else without matching #if"); - if (s1->ifdef_stack_ptr[-1] & 2) - tcc_error("#else after #else"); - c = (s1->ifdef_stack_ptr[-1] ^= 3); - goto test_else; - case TOK_ELIF: - if (s1->ifdef_stack_ptr == s1->ifdef_stack) - tcc_error("#elif without matching #if"); - c = s1->ifdef_stack_ptr[-1]; - if (c > 1) - tcc_error("#elif after #else"); - /* last #if/#elif expression was true: we skip */ - if (c == 1) { - c = 0; - } else { - c = expr_preprocess(); - s1->ifdef_stack_ptr[-1] = c; - } - test_else: - if (s1->ifdef_stack_ptr == file->ifdef_stack_ptr + 1) - file->ifndef_macro = 0; - test_skip: - if (!(c & 1)) { - preprocess_skip(); - is_bof = 0; - goto redo; - } - break; - case TOK_ENDIF: - if (s1->ifdef_stack_ptr <= file->ifdef_stack_ptr) - tcc_error("#endif without matching #if"); - s1->ifdef_stack_ptr--; - /* '#ifndef macro' was at the start of file. Now we check if - an '#endif' is exactly at the end of file */ - if (file->ifndef_macro && - s1->ifdef_stack_ptr == file->ifdef_stack_ptr) { - file->ifndef_macro_saved = file->ifndef_macro; - /* need to set to zero to avoid false matches if another - #ifndef at middle of file */ - file->ifndef_macro = 0; - while (tok != TOK_LINEFEED) - next_nomacro(); - tok_flags |= TOK_FLAG_ENDIF; - goto the_end; - } - break; - case TOK_PPNUM: - n = strtoul((char*)tokc.str.data, &q, 10); - goto _line_num; - case TOK_LINE: - next(); - if (tok != TOK_CINT) - _line_err: - tcc_error("wrong #line format"); - n = tokc.i; - _line_num: - next(); - if (tok != TOK_LINEFEED) { - if (tok == TOK_STR) { - if (file->true_filename == file->filename) - file->true_filename = tcc_strdup(file->filename); - pstrcpy(file->filename, sizeof(file->filename), (char *)tokc.str.data); - } else if (parse_flags & PARSE_FLAG_ASM_FILE) - break; - else - goto _line_err; - --n; - } - if (file->fd > 0) - total_lines += file->line_num - n; - file->line_num = n; - if (s1->do_debug) - put_stabs(file->filename, N_BINCL, 0, 0, 0); - break; - case TOK_ERROR: - case TOK_WARNING: - c = tok; - ch = file->buf_ptr[0]; - skip_spaces(); - q = buf; - while (ch != '\n' && ch != CH_EOF) { - if ((q - buf) < sizeof(buf) - 1) - *q++ = ch; - if (ch == '\\') { - if (handle_stray_noerror() == 0) - --q; - } else - inp(); - } - *q = '\0'; - if (c == TOK_ERROR) - tcc_error("#error %s", buf); - else - tcc_warning("#warning %s", buf); - break; - case TOK_PRAGMA: - pragma_parse(s1); - break; - case TOK_LINEFEED: - goto the_end; - default: - /* ignore gas line comment in an 'S' file. */ - if (saved_parse_flags & PARSE_FLAG_ASM_FILE) - goto ignore; - if (tok == '!' && is_bof) - /* '!' is ignored at beginning to allow C scripts. */ - goto ignore; - tcc_warning("Ignoring unknown preprocessing directive #%s", get_tok_str(tok, &tokc)); - ignore: - file->buf_ptr = parse_line_comment(file->buf_ptr - 1); - goto the_end; - } - /* ignore other preprocess commands or #! for C scripts */ - while (tok != TOK_LINEFEED) - next_nomacro(); - the_end: - parse_flags = saved_parse_flags; -} - -/* evaluate escape codes in a string. */ -static void parse_escape_string(CString *outstr, const uint8_t *buf, int is_long) -{ - int c, n; - const uint8_t *p; - - p = buf; - for(;;) { - c = *p; - if (c == '\0') - break; - if (c == '\\') { - p++; - /* escape */ - c = *p; - switch(c) { - case '0': case '1': case '2': case '3': - case '4': case '5': case '6': case '7': - /* at most three octal digits */ - n = c - '0'; - p++; - c = *p; - if (isoct(c)) { - n = n * 8 + c - '0'; - p++; - c = *p; - if (isoct(c)) { - n = n * 8 + c - '0'; - p++; - } - } - c = n; - goto add_char_nonext; - case 'x': - case 'u': - case 'U': - p++; - n = 0; - for(;;) { - c = *p; - if (c >= 'a' && c <= 'f') - c = c - 'a' + 10; - else if (c >= 'A' && c <= 'F') - c = c - 'A' + 10; - else if (isnum(c)) - c = c - '0'; - else - break; - n = n * 16 + c; - p++; - } - c = n; - goto add_char_nonext; - case 'a': - c = '\a'; - break; - case 'b': - c = '\b'; - break; - case 'f': - c = '\f'; - break; - case 'n': - c = '\n'; - break; - case 'r': - c = '\r'; - break; - case 't': - c = '\t'; - break; - case 'v': - c = '\v'; - break; - case 'e': - if (!gnu_ext) - goto invalid_escape; - c = 27; - break; - case '\'': - case '\"': - case '\\': - case '?': - break; - default: - invalid_escape: - if (c >= '!' && c <= '~') - tcc_warning("unknown escape sequence: \'\\%c\'", c); - else - tcc_warning("unknown escape sequence: \'\\x%x\'", c); - break; - } - } else if (is_long && c >= 0x80) { - /* assume we are processing UTF-8 sequence */ - /* reference: The Unicode Standard, Version 10.0, ch3.9 */ - - int cont; /* count of continuation bytes */ - int skip; /* how many bytes should skip when error occurred */ - int i; - - /* decode leading byte */ - if (c < 0xC2) { - skip = 1; goto invalid_utf8_sequence; - } else if (c <= 0xDF) { - cont = 1; n = c & 0x1f; - } else if (c <= 0xEF) { - cont = 2; n = c & 0xf; - } else if (c <= 0xF4) { - cont = 3; n = c & 0x7; - } else { - skip = 1; goto invalid_utf8_sequence; - } - - /* decode continuation bytes */ - for (i = 1; i <= cont; i++) { - int l = 0x80, h = 0xBF; - - /* adjust limit for second byte */ - if (i == 1) { - switch (c) { - case 0xE0: l = 0xA0; break; - case 0xED: h = 0x9F; break; - case 0xF0: l = 0x90; break; - case 0xF4: h = 0x8F; break; - } - } - - if (p[i] < l || p[i] > h) { - skip = i; goto invalid_utf8_sequence; - } - - n = (n << 6) | (p[i] & 0x3f); - } - - /* advance pointer */ - p += 1 + cont; - c = n; - goto add_char_nonext; - - /* error handling */ - invalid_utf8_sequence: - tcc_warning("ill-formed UTF-8 subsequence starting with: \'\\x%x\'", c); - c = 0xFFFD; - p += skip; - goto add_char_nonext; - - } - p++; - add_char_nonext: - if (!is_long) - cstr_ccat(outstr, c); - else { -#ifdef TCC_TARGET_PE - /* store as UTF-16 */ - if (c < 0x10000) { - cstr_wccat(outstr, c); - } else { - c -= 0x10000; - cstr_wccat(outstr, (c >> 10) + 0xD800); - cstr_wccat(outstr, (c & 0x3FF) + 0xDC00); - } -#else - cstr_wccat(outstr, c); -#endif - } - } - /* add a trailing '\0' */ - if (!is_long) - cstr_ccat(outstr, '\0'); - else - cstr_wccat(outstr, '\0'); -} - -static void parse_string(const char *s, int len) -{ - uint8_t buf[1000], *p = buf; - int is_long, sep; - - if ((is_long = *s == 'L')) - ++s, --len; - sep = *s++; - len -= 2; - if (len >= sizeof buf) - p = tcc_malloc(len + 1); - memcpy(p, s, len); - p[len] = 0; - - cstr_reset(&tokcstr); - parse_escape_string(&tokcstr, p, is_long); - if (p != buf) - tcc_free(p); - - if (sep == '\'') { - int char_size, i, n, c; - /* XXX: make it portable */ - if (!is_long) - tok = TOK_CCHAR, char_size = 1; - else - tok = TOK_LCHAR, char_size = sizeof(nwchar_t); - n = tokcstr.size / char_size - 1; - if (n < 1) - tcc_error("empty character constant"); - if (n > 1) - tcc_warning("multi-character character constant"); - for (c = i = 0; i < n; ++i) { - if (is_long) - c = ((nwchar_t *)tokcstr.data)[i]; - else - c = (c << 8) | ((char *)tokcstr.data)[i]; - } - tokc.i = c; - } else { - tokc.str.size = tokcstr.size; - tokc.str.data = tokcstr.data; - if (!is_long) - tok = TOK_STR; - else - tok = TOK_LSTR; - } -} - -/* we use 64 bit numbers */ -#define BN_SIZE 2 - -/* bn = (bn << shift) | or_val */ -static void bn_lshift(unsigned int *bn, int shift, int or_val) -{ - int i; - unsigned int v; - for(i=0;i> (32 - shift); - } -} - -static void bn_zero(unsigned int *bn) -{ - int i; - for(i=0;i= 'a' && ch <= 'f') - t = ch - 'a' + 10; - else if (ch >= 'A' && ch <= 'F') - t = ch - 'A' + 10; - else if (isnum(ch)) - t = ch - '0'; - else - break; - if (t >= b) - break; - if (q >= token_buf + STRING_MAX_SIZE) { - num_too_long: - tcc_error("number too long"); - } - *q++ = ch; - ch = *p++; - } - if (ch == '.' || - ((ch == 'e' || ch == 'E') && b == 10) || - ((ch == 'p' || ch == 'P') && (b == 16 || b == 2))) { - if (b != 10) { - /* NOTE: strtox should support that for hexa numbers, but - non ISOC99 libcs do not support it, so we prefer to do - it by hand */ - /* hexadecimal or binary floats */ - /* XXX: handle overflows */ - *q = '\0'; - if (b == 16) - shift = 4; - else - shift = 1; - bn_zero(bn); - q = token_buf; - while (1) { - t = *q++; - if (t == '\0') { - break; - } else if (t >= 'a') { - t = t - 'a' + 10; - } else if (t >= 'A') { - t = t - 'A' + 10; - } else { - t = t - '0'; - } - bn_lshift(bn, shift, t); - } - frac_bits = 0; - if (ch == '.') { - ch = *p++; - while (1) { - t = ch; - if (t >= 'a' && t <= 'f') { - t = t - 'a' + 10; - } else if (t >= 'A' && t <= 'F') { - t = t - 'A' + 10; - } else if (t >= '0' && t <= '9') { - t = t - '0'; - } else { - break; - } - if (t >= b) - tcc_error("invalid digit"); - bn_lshift(bn, shift, t); - frac_bits += shift; - ch = *p++; - } - } - if (ch != 'p' && ch != 'P') - expect("exponent"); - ch = *p++; - s = 1; - exp_val = 0; - if (ch == '+') { - ch = *p++; - } else if (ch == '-') { - s = -1; - ch = *p++; - } - if (ch < '0' || ch > '9') - expect("exponent digits"); - while (ch >= '0' && ch <= '9') { - exp_val = exp_val * 10 + ch - '0'; - ch = *p++; - } - exp_val = exp_val * s; - - /* now we can generate the number */ - /* XXX: should patch directly float number */ - d = (double)bn[1] * 4294967296.0 + (double)bn[0]; - d = ldexp(d, exp_val - frac_bits); - t = toup(ch); - if (t == 'F') { - ch = *p++; - tok = TOK_CFLOAT; - /* float : should handle overflow */ - tokc.f = (float)d; - } else if (t == 'L') { - ch = *p++; -#ifdef TCC_TARGET_PE - tok = TOK_CDOUBLE; - tokc.d = d; -#else - tok = TOK_CLDOUBLE; - /* XXX: not large enough */ - tokc.ld = (long double)d; -#endif - } else { - tok = TOK_CDOUBLE; - tokc.d = d; - } - } else { - /* decimal floats */ - if (ch == '.') { - if (q >= token_buf + STRING_MAX_SIZE) - goto num_too_long; - *q++ = ch; - ch = *p++; - float_frac_parse: - while (ch >= '0' && ch <= '9') { - if (q >= token_buf + STRING_MAX_SIZE) - goto num_too_long; - *q++ = ch; - ch = *p++; - } - } - if (ch == 'e' || ch == 'E') { - if (q >= token_buf + STRING_MAX_SIZE) - goto num_too_long; - *q++ = ch; - ch = *p++; - if (ch == '-' || ch == '+') { - if (q >= token_buf + STRING_MAX_SIZE) - goto num_too_long; - *q++ = ch; - ch = *p++; - } - if (ch < '0' || ch > '9') - expect("exponent digits"); - while (ch >= '0' && ch <= '9') { - if (q >= token_buf + STRING_MAX_SIZE) - goto num_too_long; - *q++ = ch; - ch = *p++; - } - } - *q = '\0'; - t = toup(ch); - errno = 0; - if (t == 'F') { - ch = *p++; - tok = TOK_CFLOAT; - tokc.f = strtof(token_buf, NULL); - } else if (t == 'L') { - ch = *p++; -#ifdef TCC_TARGET_PE - tok = TOK_CDOUBLE; - tokc.d = strtod(token_buf, NULL); -#else - tok = TOK_CLDOUBLE; - tokc.ld = strtold(token_buf, NULL); -#endif - } else { - tok = TOK_CDOUBLE; - tokc.d = strtod(token_buf, NULL); - } - } - } else { - unsigned long long n, n1; - int lcount, ucount, ov = 0; - const char *p1; - - /* integer number */ - *q = '\0'; - q = token_buf; - if (b == 10 && *q == '0') { - b = 8; - q++; - } - n = 0; - while(1) { - t = *q++; - /* no need for checks except for base 10 / 8 errors */ - if (t == '\0') - break; - else if (t >= 'a') - t = t - 'a' + 10; - else if (t >= 'A') - t = t - 'A' + 10; - else - t = t - '0'; - if (t >= b) - tcc_error("invalid digit"); - n1 = n; - n = n * b + t; - /* detect overflow */ - if (n1 >= 0x1000000000000000ULL && n / b != n1) - ov = 1; - } - - /* Determine the characteristics (unsigned and/or 64bit) the type of - the constant must have according to the constant suffix(es) */ - lcount = ucount = 0; - p1 = p; - for(;;) { - t = toup(ch); - if (t == 'L') { - if (lcount >= 2) - tcc_error("three 'l's in integer constant"); - if (lcount && *(p - 1) != ch) - tcc_error("incorrect integer suffix: %s", p1); - lcount++; - ch = *p++; - } else if (t == 'U') { - if (ucount >= 1) - tcc_error("two 'u's in integer constant"); - ucount++; - ch = *p++; - } else { - break; - } - } - - /* Determine if it needs 64 bits and/or unsigned in order to fit */ - if (ucount == 0 && b == 10) { - if (lcount <= (LONG_SIZE == 4)) { - if (n >= 0x80000000U) - lcount = (LONG_SIZE == 4) + 1; - } - if (n >= 0x8000000000000000ULL) - ov = 1, ucount = 1; - } else { - if (lcount <= (LONG_SIZE == 4)) { - if (n >= 0x100000000ULL) - lcount = (LONG_SIZE == 4) + 1; - else if (n >= 0x80000000U) - ucount = 1; - } - if (n >= 0x8000000000000000ULL) - ucount = 1; - } - - if (ov) - tcc_warning("integer constant overflow"); - - tok = TOK_CINT; - if (lcount) { - tok = TOK_CLONG; - if (lcount == 2) - tok = TOK_CLLONG; - } - if (ucount) - ++tok; /* TOK_CU... */ - tokc.i = n; - } - if (ch) - tcc_error("invalid number\n"); -} - - -#define PARSE2(c1, tok1, c2, tok2) \ - case c1: \ - PEEKC(c, p); \ - if (c == c2) { \ - p++; \ - tok = tok2; \ - } else { \ - tok = tok1; \ - } \ - break; - -/* return next token without macro substitution */ -static inline void next_nomacro1(void) -{ - int t, c, is_long, len; - TokenSym *ts; - uint8_t *p, *p1; - unsigned int h; - - p = file->buf_ptr; - redo_no_start: - c = *p; - switch(c) { - case ' ': - case '\t': - tok = c; - p++; - if (parse_flags & PARSE_FLAG_SPACES) - goto keep_tok_flags; - while (isidnum_table[*p - CH_EOF] & IS_SPC) - ++p; - goto redo_no_start; - case '\f': - case '\v': - case '\r': - p++; - goto redo_no_start; - case '\\': - /* first look if it is in fact an end of buffer */ - c = handle_stray1(p); - p = file->buf_ptr; - if (c == '\\') - goto parse_simple; - if (c != CH_EOF) - goto redo_no_start; - { - TCCState *s1 = tcc_state; - if ((parse_flags & PARSE_FLAG_LINEFEED) - && !(tok_flags & TOK_FLAG_EOF)) { - tok_flags |= TOK_FLAG_EOF; - tok = TOK_LINEFEED; - goto keep_tok_flags; - } else if (!(parse_flags & PARSE_FLAG_PREPROCESS)) { - tok = TOK_EOF; - } else if (s1->ifdef_stack_ptr != file->ifdef_stack_ptr) { - tcc_error("missing #endif"); - } else if (s1->include_stack_ptr == s1->include_stack) { - /* no include left : end of file. */ - tok = TOK_EOF; - } else { - tok_flags &= ~TOK_FLAG_EOF; - /* pop include file */ - - /* test if previous '#endif' was after a #ifdef at - start of file */ - if (tok_flags & TOK_FLAG_ENDIF) { -#ifdef INC_DEBUG - printf("#endif %s\n", get_tok_str(file->ifndef_macro_saved, NULL)); -#endif - search_cached_include(s1, file->filename, 1) - ->ifndef_macro = file->ifndef_macro_saved; - tok_flags &= ~TOK_FLAG_ENDIF; - } - - /* add end of include file debug info */ - if (tcc_state->do_debug) { - put_stabd(N_EINCL, 0, 0); - } - /* pop include stack */ - tcc_close(); - s1->include_stack_ptr--; - p = file->buf_ptr; - if (p == file->buffer) - tok_flags = TOK_FLAG_BOF|TOK_FLAG_BOL; - goto redo_no_start; - } - } - break; - - case '\n': - file->line_num++; - tok_flags |= TOK_FLAG_BOL; - p++; -maybe_newline: - if (0 == (parse_flags & PARSE_FLAG_LINEFEED)) - goto redo_no_start; - tok = TOK_LINEFEED; - goto keep_tok_flags; - - case '#': - /* XXX: simplify */ - PEEKC(c, p); - if ((tok_flags & TOK_FLAG_BOL) && - (parse_flags & PARSE_FLAG_PREPROCESS)) { - file->buf_ptr = p; - preprocess(tok_flags & TOK_FLAG_BOF); - p = file->buf_ptr; - goto maybe_newline; - } else { - if (c == '#') { - p++; - tok = TOK_TWOSHARPS; - } else { - if (parse_flags & PARSE_FLAG_ASM_FILE) { - p = parse_line_comment(p - 1); - goto redo_no_start; - } else { - tok = '#'; - } - } - } - break; - - /* dollar is allowed to start identifiers when not parsing asm */ - case '$': - if (!(isidnum_table[c - CH_EOF] & IS_ID) - || (parse_flags & PARSE_FLAG_ASM_FILE)) - goto parse_simple; - - case 'a': case 'b': case 'c': case 'd': - case 'e': case 'f': case 'g': case 'h': - case 'i': case 'j': case 'k': case 'l': - case 'm': case 'n': case 'o': case 'p': - case 'q': case 'r': case 's': case 't': - case 'u': case 'v': case 'w': case 'x': - case 'y': case 'z': - case 'A': case 'B': case 'C': case 'D': - case 'E': case 'F': case 'G': case 'H': - case 'I': case 'J': case 'K': - case 'M': case 'N': case 'O': case 'P': - case 'Q': case 'R': case 'S': case 'T': - case 'U': case 'V': case 'W': case 'X': - case 'Y': case 'Z': - case '_': - parse_ident_fast: - p1 = p; - h = TOK_HASH_INIT; - h = TOK_HASH_FUNC(h, c); - while (c = *++p, isidnum_table[c - CH_EOF] & (IS_ID|IS_NUM)) - h = TOK_HASH_FUNC(h, c); - len = p - p1; - if (c != '\\') { - TokenSym **pts; - - /* fast case : no stray found, so we have the full token - and we have already hashed it */ - h &= (TOK_HASH_SIZE - 1); - pts = &hash_ident[h]; - for(;;) { - ts = *pts; - if (!ts) - break; - if (ts->len == len && !memcmp(ts->str, p1, len)) - goto token_found; - pts = &(ts->hash_next); - } - ts = tok_alloc_new(pts, (char *) p1, len); - token_found: ; - } else { - /* slower case */ - cstr_reset(&tokcstr); - cstr_cat(&tokcstr, (char *) p1, len); - p--; - PEEKC(c, p); - parse_ident_slow: - while (isidnum_table[c - CH_EOF] & (IS_ID|IS_NUM)) - { - cstr_ccat(&tokcstr, c); - PEEKC(c, p); - } - ts = tok_alloc(tokcstr.data, tokcstr.size); - } - tok = ts->tok; - break; - case 'L': - t = p[1]; - if (t != '\\' && t != '\'' && t != '\"') { - /* fast case */ - goto parse_ident_fast; - } else { - PEEKC(c, p); - if (c == '\'' || c == '\"') { - is_long = 1; - goto str_const; - } else { - cstr_reset(&tokcstr); - cstr_ccat(&tokcstr, 'L'); - goto parse_ident_slow; - } - } - break; - - case '0': case '1': case '2': case '3': - case '4': case '5': case '6': case '7': - case '8': case '9': - t = c; - PEEKC(c, p); - /* after the first digit, accept digits, alpha, '.' or sign if - prefixed by 'eEpP' */ - parse_num: - cstr_reset(&tokcstr); - for(;;) { - cstr_ccat(&tokcstr, t); - if (!((isidnum_table[c - CH_EOF] & (IS_ID|IS_NUM)) - || c == '.' - || ((c == '+' || c == '-') - && (((t == 'e' || t == 'E') - && !(parse_flags & PARSE_FLAG_ASM_FILE - /* 0xe+1 is 3 tokens in asm */ - && ((char*)tokcstr.data)[0] == '0' - && toup(((char*)tokcstr.data)[1]) == 'X')) - || t == 'p' || t == 'P')))) - break; - t = c; - PEEKC(c, p); - } - /* We add a trailing '\0' to ease parsing */ - cstr_ccat(&tokcstr, '\0'); - tokc.str.size = tokcstr.size; - tokc.str.data = tokcstr.data; - tok = TOK_PPNUM; - break; - - case '.': - /* special dot handling because it can also start a number */ - PEEKC(c, p); - if (isnum(c)) { - t = '.'; - goto parse_num; - } else if ((isidnum_table['.' - CH_EOF] & IS_ID) - && (isidnum_table[c - CH_EOF] & (IS_ID|IS_NUM))) { - *--p = c = '.'; - goto parse_ident_fast; - } else if (c == '.') { - PEEKC(c, p); - if (c == '.') { - p++; - tok = TOK_DOTS; - } else { - *--p = '.'; /* may underflow into file->unget[] */ - tok = '.'; - } - } else { - tok = '.'; - } - break; - case '\'': - case '\"': - is_long = 0; - str_const: - cstr_reset(&tokcstr); - if (is_long) - cstr_ccat(&tokcstr, 'L'); - cstr_ccat(&tokcstr, c); - p = parse_pp_string(p, c, &tokcstr); - cstr_ccat(&tokcstr, c); - cstr_ccat(&tokcstr, '\0'); - tokc.str.size = tokcstr.size; - tokc.str.data = tokcstr.data; - tok = TOK_PPSTR; - break; - - case '<': - PEEKC(c, p); - if (c == '=') { - p++; - tok = TOK_LE; - } else if (c == '<') { - PEEKC(c, p); - if (c == '=') { - p++; - tok = TOK_A_SHL; - } else { - tok = TOK_SHL; - } - } else { - tok = TOK_LT; - } - break; - case '>': - PEEKC(c, p); - if (c == '=') { - p++; - tok = TOK_GE; - } else if (c == '>') { - PEEKC(c, p); - if (c == '=') { - p++; - tok = TOK_A_SAR; - } else { - tok = TOK_SAR; - } - } else { - tok = TOK_GT; - } - break; - - case '&': - PEEKC(c, p); - if (c == '&') { - p++; - tok = TOK_LAND; - } else if (c == '=') { - p++; - tok = TOK_A_AND; - } else { - tok = '&'; - } - break; - - case '|': - PEEKC(c, p); - if (c == '|') { - p++; - tok = TOK_LOR; - } else if (c == '=') { - p++; - tok = TOK_A_OR; - } else { - tok = '|'; - } - break; - - case '+': - PEEKC(c, p); - if (c == '+') { - p++; - tok = TOK_INC; - } else if (c == '=') { - p++; - tok = TOK_A_ADD; - } else { - tok = '+'; - } - break; - - case '-': - PEEKC(c, p); - if (c == '-') { - p++; - tok = TOK_DEC; - } else if (c == '=') { - p++; - tok = TOK_A_SUB; - } else if (c == '>') { - p++; - tok = TOK_ARROW; - } else { - tok = '-'; - } - break; - - PARSE2('!', '!', '=', TOK_NE) - PARSE2('=', '=', '=', TOK_EQ) - PARSE2('*', '*', '=', TOK_A_MUL) - PARSE2('%', '%', '=', TOK_A_MOD) - PARSE2('^', '^', '=', TOK_A_XOR) - - /* comments or operator */ - case '/': - PEEKC(c, p); - if (c == '*') { - p = parse_comment(p); - /* comments replaced by a blank */ - tok = ' '; - goto keep_tok_flags; - } else if (c == '/') { - p = parse_line_comment(p); - tok = ' '; - goto keep_tok_flags; - } else if (c == '=') { - p++; - tok = TOK_A_DIV; - } else { - tok = '/'; - } - break; - - /* simple tokens */ - case '(': - case ')': - case '[': - case ']': - case '{': - case '}': - case ',': - case ';': - case ':': - case '?': - case '~': - case '@': /* only used in assembler */ - parse_simple: - tok = c; - p++; - break; - default: - if (c >= 0x80 && c <= 0xFF) /* utf8 identifiers */ - goto parse_ident_fast; - if (parse_flags & PARSE_FLAG_ASM_FILE) - goto parse_simple; - tcc_error("unrecognized character \\x%02x", c); - break; - } - tok_flags = 0; -keep_tok_flags: - file->buf_ptr = p; -#if defined(PARSE_DEBUG) - printf("token = %d %s\n", tok, get_tok_str(tok, &tokc)); -#endif -} - -/* return next token without macro substitution. Can read input from - macro_ptr buffer */ -static void next_nomacro_spc(void) -{ - if (macro_ptr) { - redo: - tok = *macro_ptr; - if (tok) { - TOK_GET(&tok, ¯o_ptr, &tokc); - if (tok == TOK_LINENUM) { - file->line_num = tokc.i; - goto redo; - } - } - } else { - next_nomacro1(); - } - //printf("token = %s\n", get_tok_str(tok, &tokc)); -} - -ST_FUNC void next_nomacro(void) -{ - do { - next_nomacro_spc(); - } while (tok < 256 && (isidnum_table[tok - CH_EOF] & IS_SPC)); -} - - -static void macro_subst( - TokenString *tok_str, - Sym **nested_list, - const int *macro_str - ); - -/* substitute arguments in replacement lists in macro_str by the values in - args (field d) and return allocated string */ -static int *macro_arg_subst(Sym **nested_list, const int *macro_str, Sym *args) -{ - int t, t0, t1, spc; - const int *st; - Sym *s; - CValue cval; - TokenString str; - CString cstr; - - tok_str_new(&str); - t0 = t1 = 0; - while(1) { - TOK_GET(&t, ¯o_str, &cval); - if (!t) - break; - if (t == '#') { - /* stringize */ - TOK_GET(&t, ¯o_str, &cval); - if (!t) - goto bad_stringy; - s = sym_find2(args, t); - if (s) { - cstr_new(&cstr); - cstr_ccat(&cstr, '\"'); - st = s->d; - spc = 0; - while (*st >= 0) { - TOK_GET(&t, &st, &cval); - if (t != TOK_PLCHLDR - && t != TOK_NOSUBST - && 0 == check_space(t, &spc)) { - const char *s = get_tok_str(t, &cval); - while (*s) { - if (t == TOK_PPSTR && *s != '\'') - add_char(&cstr, *s); - else - cstr_ccat(&cstr, *s); - ++s; - } - } - } - cstr.size -= spc; - cstr_ccat(&cstr, '\"'); - cstr_ccat(&cstr, '\0'); -#ifdef PP_DEBUG - printf("\nstringize: <%s>\n", (char *)cstr.data); -#endif - /* add string */ - cval.str.size = cstr.size; - cval.str.data = cstr.data; - tok_str_add2(&str, TOK_PPSTR, &cval); - cstr_free(&cstr); - } else { - bad_stringy: - expect("macro parameter after '#'"); - } - } else if (t >= TOK_IDENT) { - s = sym_find2(args, t); - if (s) { - int l0 = str.len; - st = s->d; - /* if '##' is present before or after, no arg substitution */ - if (*macro_str == TOK_PPJOIN || t1 == TOK_PPJOIN) { - /* special case for var arg macros : ## eats the ',' - if empty VA_ARGS variable. */ - if (t1 == TOK_PPJOIN && t0 == ',' && gnu_ext && s->type.t) { - if (*st <= 0) { - /* suppress ',' '##' */ - str.len -= 2; - } else { - /* suppress '##' and add variable */ - str.len--; - goto add_var; - } - } - } else { - add_var: - if (!s->next) { - /* Expand arguments tokens and store them. In most - cases we could also re-expand each argument if - used multiple times, but not if the argument - contains the __COUNTER__ macro. */ - TokenString str2; - sym_push2(&s->next, s->v, s->type.t, 0); - tok_str_new(&str2); - macro_subst(&str2, nested_list, st); - tok_str_add(&str2, 0); - s->next->d = str2.str; - } - st = s->next->d; - } - for(;;) { - int t2; - TOK_GET(&t2, &st, &cval); - if (t2 <= 0) - break; - tok_str_add2(&str, t2, &cval); - } - if (str.len == l0) /* expanded to empty string */ - tok_str_add(&str, TOK_PLCHLDR); - } else { - tok_str_add(&str, t); - } - } else { - tok_str_add2(&str, t, &cval); - } - t0 = t1, t1 = t; - } - tok_str_add(&str, 0); - return str.str; -} - -static char const ab_month_name[12][4] = -{ - "Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" -}; - -static int paste_tokens(int t1, CValue *v1, int t2, CValue *v2) -{ - CString cstr; - int n, ret = 1; - - cstr_new(&cstr); - if (t1 != TOK_PLCHLDR) - cstr_cat(&cstr, get_tok_str(t1, v1), -1); - n = cstr.size; - if (t2 != TOK_PLCHLDR) - cstr_cat(&cstr, get_tok_str(t2, v2), -1); - cstr_ccat(&cstr, '\0'); - - tcc_open_bf(tcc_state, ":paste:", cstr.size); - memcpy(file->buffer, cstr.data, cstr.size); - tok_flags = 0; - for (;;) { - next_nomacro1(); - if (0 == *file->buf_ptr) - break; - if (is_space(tok)) - continue; - tcc_warning("pasting \"%.*s\" and \"%s\" does not give a valid" - " preprocessing token", n, cstr.data, (char*)cstr.data + n); - ret = 0; - break; - } - tcc_close(); - //printf("paste <%s>\n", (char*)cstr.data); - cstr_free(&cstr); - return ret; -} - -/* handle the '##' operator. Return NULL if no '##' seen. Otherwise - return the resulting string (which must be freed). */ -static inline int *macro_twosharps(const int *ptr0) -{ - int t; - CValue cval; - TokenString macro_str1; - int start_of_nosubsts = -1; - const int *ptr; - - /* we search the first '##' */ - for (ptr = ptr0;;) { - TOK_GET(&t, &ptr, &cval); - if (t == TOK_PPJOIN) - break; - if (t == 0) - return NULL; - } - - tok_str_new(¯o_str1); - - //tok_print(" $$$", ptr0); - for (ptr = ptr0;;) { - TOK_GET(&t, &ptr, &cval); - if (t == 0) - break; - if (t == TOK_PPJOIN) - continue; - while (*ptr == TOK_PPJOIN) { - int t1; CValue cv1; - /* given 'a##b', remove nosubsts preceding 'a' */ - if (start_of_nosubsts >= 0) - macro_str1.len = start_of_nosubsts; - /* given 'a##b', remove nosubsts preceding 'b' */ - while ((t1 = *++ptr) == TOK_NOSUBST) - ; - if (t1 && t1 != TOK_PPJOIN) { - TOK_GET(&t1, &ptr, &cv1); - if (t != TOK_PLCHLDR || t1 != TOK_PLCHLDR) { - if (paste_tokens(t, &cval, t1, &cv1)) { - t = tok, cval = tokc; - } else { - tok_str_add2(¯o_str1, t, &cval); - t = t1, cval = cv1; - } - } - } - } - if (t == TOK_NOSUBST) { - if (start_of_nosubsts < 0) - start_of_nosubsts = macro_str1.len; - } else { - start_of_nosubsts = -1; - } - tok_str_add2(¯o_str1, t, &cval); - } - tok_str_add(¯o_str1, 0); - //tok_print(" ###", macro_str1.str); - return macro_str1.str; -} - -/* peek or read [ws_str == NULL] next token from function macro call, - walking up macro levels up to the file if necessary */ -static int next_argstream(Sym **nested_list, TokenString *ws_str) -{ - int t; - const int *p; - Sym *sa; - - for (;;) { - if (macro_ptr) { - p = macro_ptr, t = *p; - if (ws_str) { - while (is_space(t) || TOK_LINEFEED == t || TOK_PLCHLDR == t) - tok_str_add(ws_str, t), t = *++p; - } - if (t == 0) { - end_macro(); - /* also, end of scope for nested defined symbol */ - sa = *nested_list; - while (sa && sa->v == 0) - sa = sa->prev; - if (sa) - sa->v = 0; - continue; - } - } else { - ch = handle_eob(); - if (ws_str) { - while (is_space(ch) || ch == '\n' || ch == '/') { - if (ch == '/') { - int c; - uint8_t *p = file->buf_ptr; - PEEKC(c, p); - if (c == '*') { - p = parse_comment(p); - file->buf_ptr = p - 1; - } else if (c == '/') { - p = parse_line_comment(p); - file->buf_ptr = p - 1; - } else - break; - ch = ' '; - } - if (ch == '\n') - file->line_num++; - if (!(ch == '\f' || ch == '\v' || ch == '\r')) - tok_str_add(ws_str, ch); - cinp(); - } - } - t = ch; - } - - if (ws_str) - return t; - next_nomacro_spc(); - return tok; - } -} - -/* do macro substitution of current token with macro 's' and add - result to (tok_str,tok_len). 'nested_list' is the list of all - macros we got inside to avoid recursing. Return non zero if no - substitution needs to be done */ -static int macro_subst_tok( - TokenString *tok_str, - Sym **nested_list, - Sym *s) -{ - Sym *args, *sa, *sa1; - int parlevel, t, t1, spc; - TokenString str; - char *cstrval; - CValue cval; - CString cstr; - char buf[32]; - - /* if symbol is a macro, prepare substitution */ - /* special macros */ - if (tok == TOK___LINE__ || tok == TOK___COUNTER__) { - t = tok == TOK___LINE__ ? file->line_num : pp_counter++; - snprintf(buf, sizeof(buf), "%d", t); - cstrval = buf; - t1 = TOK_PPNUM; - goto add_cstr1; - } else if (tok == TOK___FILE__) { - cstrval = file->filename; - goto add_cstr; - } else if (tok == TOK___DATE__ || tok == TOK___TIME__) { - time_t ti; - struct tm *tm; - - time(&ti); - tm = localtime(&ti); - if (tok == TOK___DATE__) { - snprintf(buf, sizeof(buf), "%s %2d %d", - ab_month_name[tm->tm_mon], tm->tm_mday, tm->tm_year + 1900); - } else { - snprintf(buf, sizeof(buf), "%02d:%02d:%02d", - tm->tm_hour, tm->tm_min, tm->tm_sec); - } - cstrval = buf; - add_cstr: - t1 = TOK_STR; - add_cstr1: - cstr_new(&cstr); - cstr_cat(&cstr, cstrval, 0); - cval.str.size = cstr.size; - cval.str.data = cstr.data; - tok_str_add2(tok_str, t1, &cval); - cstr_free(&cstr); - } else if (s->d) { - int saved_parse_flags = parse_flags; - int *joined_str = NULL; - int *mstr = s->d; - - if (s->type.t == MACRO_FUNC) { - /* whitespace between macro name and argument list */ - TokenString ws_str; - tok_str_new(&ws_str); - - spc = 0; - parse_flags |= PARSE_FLAG_SPACES | PARSE_FLAG_LINEFEED - | PARSE_FLAG_ACCEPT_STRAYS; - - /* get next token from argument stream */ - t = next_argstream(nested_list, &ws_str); - if (t != '(') { - /* not a macro substitution after all, restore the - * macro token plus all whitespace we've read. - * whitespace is intentionally not merged to preserve - * newlines. */ - parse_flags = saved_parse_flags; - tok_str_add(tok_str, tok); - if (parse_flags & PARSE_FLAG_SPACES) { - int i; - for (i = 0; i < ws_str.len; i++) - tok_str_add(tok_str, ws_str.str[i]); - } - tok_str_free_str(ws_str.str); - return 0; - } else { - tok_str_free_str(ws_str.str); - } - do { - next_nomacro(); /* eat '(' */ - } while (tok == TOK_PLCHLDR); - - /* argument macro */ - args = NULL; - sa = s->next; - /* NOTE: empty args are allowed, except if no args */ - for(;;) { - do { - next_argstream(nested_list, NULL); - } while (is_space(tok) || TOK_LINEFEED == tok); - empty_arg: - /* handle '()' case */ - if (!args && !sa && tok == ')') - break; - if (!sa) - tcc_error("macro '%s' used with too many args", - get_tok_str(s->v, 0)); - tok_str_new(&str); - parlevel = spc = 0; - /* NOTE: non zero sa->t indicates VA_ARGS */ - while ((parlevel > 0 || - (tok != ')' && - (tok != ',' || sa->type.t)))) { - if (tok == TOK_EOF || tok == 0) - break; - if (tok == '(') - parlevel++; - else if (tok == ')') - parlevel--; - if (tok == TOK_LINEFEED) - tok = ' '; - if (!check_space(tok, &spc)) - tok_str_add2(&str, tok, &tokc); - next_argstream(nested_list, NULL); - } - if (parlevel) - expect(")"); - str.len -= spc; - tok_str_add(&str, -1); - tok_str_add(&str, 0); - sa1 = sym_push2(&args, sa->v & ~SYM_FIELD, sa->type.t, 0); - sa1->d = str.str; - sa = sa->next; - if (tok == ')') { - /* special case for gcc var args: add an empty - var arg argument if it is omitted */ - if (sa && sa->type.t && gnu_ext) - goto empty_arg; - break; - } - if (tok != ',') - expect(","); - } - if (sa) { - tcc_error("macro '%s' used with too few args", - get_tok_str(s->v, 0)); - } - - parse_flags = saved_parse_flags; - - /* now subst each arg */ - mstr = macro_arg_subst(nested_list, mstr, args); - /* free memory */ - sa = args; - while (sa) { - sa1 = sa->prev; - tok_str_free_str(sa->d); - if (sa->next) { - tok_str_free_str(sa->next->d); - sym_free(sa->next); - } - sym_free(sa); - sa = sa1; - } - } - - sym_push2(nested_list, s->v, 0, 0); - parse_flags = saved_parse_flags; - joined_str = macro_twosharps(mstr); - macro_subst(tok_str, nested_list, joined_str ? joined_str : mstr); - - /* pop nested defined symbol */ - sa1 = *nested_list; - *nested_list = sa1->prev; - sym_free(sa1); - if (joined_str) - tok_str_free_str(joined_str); - if (mstr != s->d) - tok_str_free_str(mstr); - } - return 0; -} - -/* do macro substitution of macro_str and add result to - (tok_str,tok_len). 'nested_list' is the list of all macros we got - inside to avoid recursing. */ -static void macro_subst( - TokenString *tok_str, - Sym **nested_list, - const int *macro_str - ) -{ - Sym *s; - int t, spc, nosubst; - CValue cval; - - spc = nosubst = 0; - - while (1) { - TOK_GET(&t, ¯o_str, &cval); - if (t <= 0) - break; - - if (t >= TOK_IDENT && 0 == nosubst) { - s = define_find(t); - if (s == NULL) - goto no_subst; - - /* if nested substitution, do nothing */ - if (sym_find2(*nested_list, t)) { - /* and mark it as TOK_NOSUBST, so it doesn't get subst'd again */ - tok_str_add2(tok_str, TOK_NOSUBST, NULL); - goto no_subst; - } - - { - TokenString str; - str.str = (int*)macro_str; - begin_macro(&str, 2); - - tok = t; - macro_subst_tok(tok_str, nested_list, s); - - if (str.alloc == 3) { - /* already finished by reading function macro arguments */ - break; - } - - macro_str = macro_ptr; - end_macro (); - } - if (tok_str->len) - spc = is_space(t = tok_str->str[tok_str->lastlen]); - } else { - if (t == '\\' && !(parse_flags & PARSE_FLAG_ACCEPT_STRAYS)) - tcc_error("stray '\\' in program"); -no_subst: - if (!check_space(t, &spc)) - tok_str_add2(tok_str, t, &cval); - - if (nosubst) { - if (nosubst > 1 && (spc || (++nosubst == 3 && t == '('))) - continue; - nosubst = 0; - } - if (t == TOK_NOSUBST) - nosubst = 1; - } - /* GCC supports 'defined' as result of a macro substitution */ - if (t == TOK_DEFINED && pp_expr) - nosubst = 2; - } -} - -/* return next token with macro substitution */ -ST_FUNC void next(void) -{ - redo: - if (parse_flags & PARSE_FLAG_SPACES) - next_nomacro_spc(); - else - next_nomacro(); - - if (macro_ptr) { - if (tok == TOK_NOSUBST || tok == TOK_PLCHLDR) { - /* discard preprocessor markers */ - goto redo; - } else if (tok == 0) { - /* end of macro or unget token string */ - end_macro(); - goto redo; - } - } else if (tok >= TOK_IDENT && (parse_flags & PARSE_FLAG_PREPROCESS)) { - Sym *s; - /* if reading from file, try to substitute macros */ - s = define_find(tok); - if (s) { - Sym *nested_list = NULL; - tokstr_buf.len = 0; - macro_subst_tok(&tokstr_buf, &nested_list, s); - tok_str_add(&tokstr_buf, 0); - begin_macro(&tokstr_buf, 2); - goto redo; - } - } - /* convert preprocessor tokens into C tokens */ - if (tok == TOK_PPNUM) { - if (parse_flags & PARSE_FLAG_TOK_NUM) - parse_number((char *)tokc.str.data); - } else if (tok == TOK_PPSTR) { - if (parse_flags & PARSE_FLAG_TOK_STR) - parse_string((char *)tokc.str.data, tokc.str.size - 1); - } -} - -/* push back current token and set current token to 'last_tok'. Only - identifier case handled for labels. */ -ST_INLN void unget_tok(int last_tok) -{ - - TokenString *str = tok_str_alloc(); - tok_str_add2(str, tok, &tokc); - tok_str_add(str, 0); - begin_macro(str, 1); - tok = last_tok; -} - -ST_FUNC void preprocess_start(TCCState *s1, int is_asm) -{ - CString cstr; - int i; - - s1->include_stack_ptr = s1->include_stack; - s1->ifdef_stack_ptr = s1->ifdef_stack; - file->ifdef_stack_ptr = s1->ifdef_stack_ptr; - pp_expr = 0; - pp_counter = 0; - pp_debug_tok = pp_debug_symv = 0; - pp_once++; - pvtop = vtop = vstack - 1; - s1->pack_stack[0] = 0; - s1->pack_stack_ptr = s1->pack_stack; - - set_idnum('$', s1->dollars_in_identifiers ? IS_ID : 0); - set_idnum('.', is_asm ? IS_ID : 0); - - cstr_new(&cstr); - cstr_cat(&cstr, "\"", -1); - cstr_cat(&cstr, file->filename, -1); - cstr_cat(&cstr, "\"", 0); - tcc_define_symbol(s1, "__BASE_FILE__", cstr.data); - - cstr_reset(&cstr); - for (i = 0; i < s1->nb_cmd_include_files; i++) { - cstr_cat(&cstr, "#include \"", -1); - cstr_cat(&cstr, s1->cmd_include_files[i], -1); - cstr_cat(&cstr, "\"\n", -1); - } - if (cstr.size) { - *s1->include_stack_ptr++ = file; - tcc_open_bf(s1, "", cstr.size); - memcpy(file->buffer, cstr.data, cstr.size); - } - cstr_free(&cstr); - - if (is_asm) - tcc_define_symbol(s1, "__ASSEMBLER__", NULL); - - parse_flags = is_asm ? PARSE_FLAG_ASM_FILE : 0; - tok_flags = TOK_FLAG_BOL | TOK_FLAG_BOF; -} - -/* cleanup from error/setjmp */ -ST_FUNC void preprocess_end(TCCState *s1) -{ - while (macro_stack) - end_macro(); - macro_ptr = NULL; -} - -ST_FUNC void tccpp_new(TCCState *s) -{ - int i, c; - const char *p, *r; - - /* might be used in error() before preprocess_start() */ - s->include_stack_ptr = s->include_stack; - s->ppfp = stdout; - - /* init isid table */ - for(i = CH_EOF; i<128; i++) - set_idnum(i, - is_space(i) ? IS_SPC - : isid(i) ? IS_ID - : isnum(i) ? IS_NUM - : 0); - - for(i = 128; i<256; i++) - set_idnum(i, IS_ID); - - /* init allocators */ - tal_new(&toksym_alloc, TOKSYM_TAL_LIMIT, TOKSYM_TAL_SIZE); - tal_new(&tokstr_alloc, TOKSTR_TAL_LIMIT, TOKSTR_TAL_SIZE); - tal_new(&cstr_alloc, CSTR_TAL_LIMIT, CSTR_TAL_SIZE); - - memset(hash_ident, 0, TOK_HASH_SIZE * sizeof(TokenSym *)); - cstr_new(&cstr_buf); - cstr_realloc(&cstr_buf, STRING_MAX_SIZE); - tok_str_new(&tokstr_buf); - tok_str_realloc(&tokstr_buf, TOKSTR_MAX_SIZE); - - tok_ident = TOK_IDENT; - p = tcc_keywords; - while (*p) { - r = p; - for(;;) { - c = *r++; - if (c == '\0') - break; - } - tok_alloc(p, r - p - 1); - p = r; - } -} - -ST_FUNC void tccpp_delete(TCCState *s) -{ - int i, n; - - /* free -D and compiler defines */ - free_defines(NULL); - - /* free tokens */ - n = tok_ident - TOK_IDENT; - for(i = 0; i < n; i++) - tal_free(toksym_alloc, table_ident[i]); - tcc_free(table_ident); - table_ident = NULL; - - /* free static buffers */ - cstr_free(&tokcstr); - cstr_free(&cstr_buf); - cstr_free(¯o_equal_buf); - tok_str_free_str(tokstr_buf.str); - - /* free allocators */ - tal_delete(toksym_alloc); - toksym_alloc = NULL; - tal_delete(tokstr_alloc); - tokstr_alloc = NULL; - tal_delete(cstr_alloc); - cstr_alloc = NULL; -} - -/* ------------------------------------------------------------------------- */ -/* tcc -E [-P[1]] [-dD} support */ - -static void tok_print(const char *msg, const int *str) -{ - FILE *fp; - int t, s = 0; - CValue cval; - - fp = tcc_state->ppfp; - fprintf(fp, "%s", msg); - while (str) { - TOK_GET(&t, &str, &cval); - if (!t) - break; - fprintf(fp, " %s" + s, get_tok_str(t, &cval)), s = 1; - } - fprintf(fp, "\n"); -} - -static void pp_line(TCCState *s1, BufferedFile *f, int level) -{ - int d = f->line_num - f->line_ref; - - if (s1->dflag & 4) - return; - - if (s1->Pflag == LINE_MACRO_OUTPUT_FORMAT_NONE) { - ; - } else if (level == 0 && f->line_ref && d < 8) { - while (d > 0) - fputs("\n", s1->ppfp), --d; - } else if (s1->Pflag == LINE_MACRO_OUTPUT_FORMAT_STD) { - fprintf(s1->ppfp, "#line %d \"%s\"\n", f->line_num, f->filename); - } else { - fprintf(s1->ppfp, "# %d \"%s\"%s\n", f->line_num, f->filename, - level > 0 ? " 1" : level < 0 ? " 2" : ""); - } - f->line_ref = f->line_num; -} - -static void define_print(TCCState *s1, int v) -{ - FILE *fp; - Sym *s; - - s = define_find(v); - if (NULL == s || NULL == s->d) - return; - - fp = s1->ppfp; - fprintf(fp, "#define %s", get_tok_str(v, NULL)); - if (s->type.t == MACRO_FUNC) { - Sym *a = s->next; - fprintf(fp,"("); - if (a) - for (;;) { - fprintf(fp,"%s", get_tok_str(a->v & ~SYM_FIELD, NULL)); - if (!(a = a->next)) - break; - fprintf(fp,","); - } - fprintf(fp,")"); - } - tok_print("", s->d); -} - -static void pp_debug_defines(TCCState *s1) -{ - int v, t; - const char *vs; - FILE *fp; - - t = pp_debug_tok; - if (t == 0) - return; - - file->line_num--; - pp_line(s1, file, 0); - file->line_ref = ++file->line_num; - - fp = s1->ppfp; - v = pp_debug_symv; - vs = get_tok_str(v, NULL); - if (t == TOK_DEFINE) { - define_print(s1, v); - } else if (t == TOK_UNDEF) { - fprintf(fp, "#undef %s\n", vs); - } else if (t == TOK_push_macro) { - fprintf(fp, "#pragma push_macro(\"%s\")\n", vs); - } else if (t == TOK_pop_macro) { - fprintf(fp, "#pragma pop_macro(\"%s\")\n", vs); - } - pp_debug_tok = 0; -} - -static void pp_debug_builtins(TCCState *s1) -{ - int v; - for (v = TOK_IDENT; v < tok_ident; ++v) - define_print(s1, v); -} - -/* Add a space between tokens a and b to avoid unwanted textual pasting */ -static int pp_need_space(int a, int b) -{ - return 'E' == a ? '+' == b || '-' == b - : '+' == a ? TOK_INC == b || '+' == b - : '-' == a ? TOK_DEC == b || '-' == b - : a >= TOK_IDENT ? b >= TOK_IDENT - : a == TOK_PPNUM ? b >= TOK_IDENT - : 0; -} - -/* maybe hex like 0x1e */ -static int pp_check_he0xE(int t, const char *p) -{ - if (t == TOK_PPNUM && toup(strchr(p, 0)[-1]) == 'E') - return 'E'; - return t; -} - -/* Preprocess the current file */ -ST_FUNC int tcc_preprocess(TCCState *s1) -{ - BufferedFile **iptr; - int token_seen, spcs, level; - const char *p; - char white[400]; - - parse_flags = PARSE_FLAG_PREPROCESS - | (parse_flags & PARSE_FLAG_ASM_FILE) - | PARSE_FLAG_LINEFEED - | PARSE_FLAG_SPACES - | PARSE_FLAG_ACCEPT_STRAYS - ; - /* Credits to Fabrice Bellard's initial revision to demonstrate its - capability to compile and run itself, provided all numbers are - given as decimals. tcc -E -P10 will do. */ - if (s1->Pflag == LINE_MACRO_OUTPUT_FORMAT_P10) - parse_flags |= PARSE_FLAG_TOK_NUM, s1->Pflag = 1; - -#ifdef PP_BENCH - /* for PP benchmarks */ - do next(); while (tok != TOK_EOF); - return 0; -#endif - - if (s1->dflag & 1) { - pp_debug_builtins(s1); - s1->dflag &= ~1; - } - - token_seen = TOK_LINEFEED, spcs = 0; - pp_line(s1, file, 0); - for (;;) { - iptr = s1->include_stack_ptr; - next(); - if (tok == TOK_EOF) - break; - - level = s1->include_stack_ptr - iptr; - if (level) { - if (level > 0) - pp_line(s1, *iptr, 0); - pp_line(s1, file, level); - } - if (s1->dflag & 7) { - pp_debug_defines(s1); - if (s1->dflag & 4) - continue; - } - - if (is_space(tok)) { - if (spcs < sizeof white - 1) - white[spcs++] = tok; - continue; - } else if (tok == TOK_LINEFEED) { - spcs = 0; - if (token_seen == TOK_LINEFEED) - continue; - ++file->line_ref; - } else if (token_seen == TOK_LINEFEED) { - pp_line(s1, file, 0); - } else if (spcs == 0 && pp_need_space(token_seen, tok)) { - white[spcs++] = ' '; - } - - white[spcs] = 0, fputs(white, s1->ppfp), spcs = 0; - fputs(p = get_tok_str(tok, &tokc), s1->ppfp); - token_seen = pp_check_he0xE(tok, p); - } - return 0; -} - -/* ------------------------------------------------------------------------- */ diff --git a/05/tcc-final-old/tccrun.c b/05/tcc-final-old/tccrun.c deleted file mode 100644 index 2247499..0000000 --- a/05/tcc-final-old/tccrun.c +++ /dev/null @@ -1,894 +0,0 @@ -/* - * TCC - Tiny C Compiler - Support for -run switch - * - * Copyright (c) 2001-2004 Fabrice Bellard - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -enum -{ - REG_R8 = 0, -# define REG_R8 REG_R8 - REG_R9, -# define REG_R9 REG_R9 - REG_R10, -# define REG_R10 REG_R10 - REG_R11, -# define REG_R11 REG_R11 - REG_R12, -# define REG_R12 REG_R12 - REG_R13, -# define REG_R13 REG_R13 - REG_R14, -# define REG_R14 REG_R14 - REG_R15, -# define REG_R15 REG_R15 - REG_RDI, -# define REG_RDI REG_RDI - REG_RSI, -# define REG_RSI REG_RSI - REG_RBP, -# define REG_RBP REG_RBP - REG_RBX, -# define REG_RBX REG_RBX - REG_RDX, -# define REG_RDX REG_RDX - REG_RAX, -# define REG_RAX REG_RAX - REG_RCX, -# define REG_RCX REG_RCX - REG_RSP, -# define REG_RSP REG_RSP - REG_RIP, -# define REG_RIP REG_RIP - REG_EFL, -# define REG_EFL REG_EFL - REG_CSGSFS, /* Actually short cs, gs, fs, __pad0. */ -# define REG_CSGSFS REG_CSGSFS - REG_ERR, -# define REG_ERR REG_ERR - REG_TRAPNO, -# define REG_TRAPNO REG_TRAPNO - REG_OLDMASK, -# define REG_OLDMASK REG_OLDMASK - REG_CR2 -# define REG_CR2 REG_CR2 -}; - -#include "tcc.h" - -/* only native compiler supports -run */ -#ifdef TCC_IS_NATIVE - -#ifndef _WIN32 -# include -#endif - -#ifdef CONFIG_TCC_BACKTRACE -# ifndef _WIN32 -# include -# ifndef __OpenBSD__ -# include -# endif -# else -# define ucontext_t CONTEXT -# endif -ST_DATA int rt_num_callers = 6; -ST_DATA const char **rt_bound_error_msg; -ST_DATA void *rt_prog_main; -static int rt_get_caller_pc(addr_t *paddr, ucontext_t *uc, int level); -static void rt_error(ucontext_t *uc, const char *fmt, ...); -static void set_exception_handler(void); -#endif - -static void set_pages_executable(void *ptr, unsigned long length); -static int tcc_relocate_ex(TCCState *s1, void *ptr, addr_t ptr_diff); - -#ifdef _WIN64 -static void *win64_add_function_table(TCCState *s1); -static void win64_del_function_table(void *); -#endif - -/* ------------------------------------------------------------- */ -/* Do all relocations (needed before using tcc_get_symbol()) - Returns -1 on error. */ - -LIBTCCAPI int tcc_relocate(TCCState *s1, void *ptr) -{ - int size; - addr_t ptr_diff = 0; - - if (TCC_RELOCATE_AUTO != ptr) - return tcc_relocate_ex(s1, ptr, 0); - - size = tcc_relocate_ex(s1, NULL, 0); - if (size < 0) - return -1; - -#ifdef HAVE_SELINUX -{ - /* Using mmap instead of malloc */ - void *prx; - char tmpfname[] = "/tmp/.tccrunXXXXXX"; - int fd = mkstemp(tmpfname); - unlink(tmpfname); - ftruncate(fd, size); - - ptr = mmap (NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); - prx = mmap (NULL, size, PROT_READ|PROT_EXEC, MAP_SHARED, fd, 0); - if (ptr == MAP_FAILED || prx == MAP_FAILED) - tcc_error("tccrun: could not map memory"); - dynarray_add(&s1->runtime_mem, &s1->nb_runtime_mem, (void*)(addr_t)size); - dynarray_add(&s1->runtime_mem, &s1->nb_runtime_mem, prx); - ptr_diff = (char*)prx - (char*)ptr; -} -#else - ptr = tcc_malloc(size); -#endif - tcc_relocate_ex(s1, ptr, ptr_diff); /* no more errors expected */ - dynarray_add(&s1->runtime_mem, &s1->nb_runtime_mem, ptr); - return 0; -} - -ST_FUNC void tcc_run_free(TCCState *s1) -{ - int i; - - for (i = 0; i < s1->nb_runtime_mem; ++i) { -#ifdef HAVE_SELINUX - unsigned size = (unsigned)(addr_t)s1->runtime_mem[i++]; - munmap(s1->runtime_mem[i++], size); - munmap(s1->runtime_mem[i], size); -#else -#ifdef _WIN64 - win64_del_function_table(*(void**)s1->runtime_mem[i]); -#endif - tcc_free(s1->runtime_mem[i]); -#endif - } - tcc_free(s1->runtime_mem); -} - -/* launch the compiled program with the given arguments */ -LIBTCCAPI int tcc_run(TCCState *s1, int argc, char **argv) -{ - int (*prog_main)(int, char **); - - s1->runtime_main = "main"; - if ((s1->dflag & 16) && !find_elf_sym(s1->symtab, s1->runtime_main)) - return 0; - if (tcc_relocate(s1, TCC_RELOCATE_AUTO) < 0) - return -1; - prog_main = tcc_get_symbol_err(s1, s1->runtime_main); - -#ifdef CONFIG_TCC_BACKTRACE - if (s1->do_debug) { - set_exception_handler(); - rt_prog_main = prog_main; - } -#endif - - errno = 0; /* clean errno value */ - -#ifdef CONFIG_TCC_BCHECK - if (s1->do_bounds_check) { - void (*bound_init)(void); - void (*bound_exit)(void); - void (*bound_new_region)(void *p, addr_t size); - int (*bound_delete_region)(void *p); - int i, ret; - - /* set error function */ - rt_bound_error_msg = tcc_get_symbol_err(s1, "__bound_error_msg"); - /* XXX: use .init section so that it also work in binary ? */ - bound_init = tcc_get_symbol_err(s1, "__bound_init"); - bound_exit = tcc_get_symbol_err(s1, "__bound_exit"); - bound_new_region = tcc_get_symbol_err(s1, "__bound_new_region"); - bound_delete_region = tcc_get_symbol_err(s1, "__bound_delete_region"); - - bound_init(); - /* mark argv area as valid */ - bound_new_region(argv, argc*sizeof(argv[0])); - for (i=0; inb_errors = 0; -#ifdef TCC_TARGET_PE - pe_output_file(s1, NULL); -#else - tcc_add_runtime(s1); - resolve_common_syms(s1); - build_got_entries(s1); -#endif - if (s1->nb_errors) - return -1; - } - - offset = 0, mem = (addr_t)ptr; - fill = -mem & RUN_SECTION_ALIGNMENT; -#ifdef _WIN64 - offset += sizeof (void*); -#endif - for (k = 0; k < 2; ++k) { - for(i = 1; i < s1->nb_sections; i++) { - s = s1->sections[i]; - if (0 == (s->sh_flags & SHF_ALLOC)) - continue; - if (k != !(s->sh_flags & SHF_EXECINSTR)) - continue; - offset += fill; - if (!mem) - s->sh_addr = 0; - else if (s->sh_flags & SHF_EXECINSTR) - s->sh_addr = mem + offset + ptr_diff; - else - s->sh_addr = mem + offset; -#if 0 - if (mem) - printf("%-16s +%02lx %p %04x\n", - s->name, fill, (void*)s->sh_addr, (unsigned)s->data_offset); -#endif - offset += s->data_offset; - fill = -(mem + offset) & 15; - } -#if RUN_SECTION_ALIGNMENT > 15 - /* To avoid that x86 processors would reload cached instructions each time - when data is written in the near, we need to make sure that code and data - do not share the same 64 byte unit */ - fill = -(mem + offset) & RUN_SECTION_ALIGNMENT; -#endif - } - - /* relocate symbols */ - relocate_syms(s1, s1->symtab, 1); - if (s1->nb_errors) - return -1; - - if (0 == mem) - return offset + RUN_SECTION_ALIGNMENT; - -#ifdef TCC_TARGET_PE - s1->pe_imagebase = mem; -#endif - - /* relocate each section */ - for(i = 1; i < s1->nb_sections; i++) { - s = s1->sections[i]; - if (s->reloc) - relocate_section(s1, s); - } - relocate_plt(s1); - - for(i = 1; i < s1->nb_sections; i++) { - s = s1->sections[i]; - if (0 == (s->sh_flags & SHF_ALLOC)) - continue; - length = s->data_offset; - ptr = (void*)s->sh_addr; - if (s->sh_flags & SHF_EXECINSTR) - ptr = (char*)ptr - ptr_diff; - if (NULL == s->data || s->sh_type == SHT_NOBITS) - memset(ptr, 0, length); - else - memcpy(ptr, s->data, length); - /* mark executable sections as executable in memory */ - if (s->sh_flags & SHF_EXECINSTR) - set_pages_executable((char*)ptr + ptr_diff, length); - } - -#ifdef _WIN64 - *(void**)mem = win64_add_function_table(s1); -#endif - - return 0; -} - -/* ------------------------------------------------------------- */ -/* allow to run code in memory */ - -static void set_pages_executable(void *ptr, unsigned long length) -{ -#ifdef _WIN32 - unsigned long old_protect; - VirtualProtect(ptr, length, PAGE_EXECUTE_READWRITE, &old_protect); -#else - void __clear_cache(void *beginning, void *end); -# ifndef HAVE_SELINUX - addr_t start, end; -# ifndef PAGESIZE -# define PAGESIZE 4096 -# endif - start = (addr_t)ptr & ~(PAGESIZE - 1); - end = (addr_t)ptr + length; - end = (end + PAGESIZE - 1) & ~(PAGESIZE - 1); - if (mprotect((void *)start, end - start, PROT_READ | PROT_WRITE | PROT_EXEC)) - tcc_error("mprotect failed: did you mean to configure --with-selinux?"); -# endif -# if defined TCC_TARGET_ARM || defined TCC_TARGET_ARM64 - __clear_cache(ptr, (char *)ptr + length); -# endif -#endif -} - -#ifdef _WIN64 -static void *win64_add_function_table(TCCState *s1) -{ - void *p = NULL; - if (s1->uw_pdata) { - p = (void*)s1->uw_pdata->sh_addr; - RtlAddFunctionTable( - (RUNTIME_FUNCTION*)p, - s1->uw_pdata->data_offset / sizeof (RUNTIME_FUNCTION), - s1->pe_imagebase - ); - s1->uw_pdata = NULL; - } - return p; -} - -static void win64_del_function_table(void *p) -{ - if (p) { - RtlDeleteFunctionTable((RUNTIME_FUNCTION*)p); - } -} -#endif - -/* ------------------------------------------------------------- */ -#ifdef CONFIG_TCC_BACKTRACE - -ST_FUNC void tcc_set_num_callers(int n) -{ - rt_num_callers = n; -} - -/* print the position in the source file of PC value 'pc' by reading - the stabs debug information */ -static addr_t rt_printline(addr_t wanted_pc, const char *msg) -{ - char func_name[128], last_func_name[128]; - addr_t func_addr, last_pc, pc; - const char *incl_files[INCLUDE_STACK_SIZE]; - int incl_index, len, last_line_num, i; - const char *str, *p; - - Stab_Sym *stab_sym = NULL, *stab_sym_end, *sym; - int stab_len = 0; - char *stab_str = NULL; - - if (stab_section) { - stab_len = stab_section->data_offset; - stab_sym = (Stab_Sym *)stab_section->data; - stab_str = (char *) stabstr_section->data; - } - - func_name[0] = '\0'; - func_addr = 0; - incl_index = 0; - last_func_name[0] = '\0'; - last_pc = (addr_t)-1; - last_line_num = 1; - - if (!stab_sym) - goto no_stabs; - - stab_sym_end = (Stab_Sym*)((char*)stab_sym + stab_len); - for (sym = stab_sym + 1; sym < stab_sym_end; ++sym) { - switch(sym->n_type) { - /* function start or end */ - case N_FUN: - if (sym->n_strx == 0) { - /* we test if between last line and end of function */ - pc = sym->n_value + func_addr; - if (wanted_pc >= last_pc && wanted_pc < pc) - goto found; - func_name[0] = '\0'; - func_addr = 0; - } else { - str = stab_str + sym->n_strx; - p = strchr(str, ':'); - if (!p) { - pstrcpy(func_name, sizeof(func_name), str); - } else { - len = p - str; - if (len > sizeof(func_name) - 1) - len = sizeof(func_name) - 1; - memcpy(func_name, str, len); - func_name[len] = '\0'; - } - func_addr = sym->n_value; - } - break; - /* line number info */ - case N_SLINE: - pc = sym->n_value + func_addr; - if (wanted_pc >= last_pc && wanted_pc < pc) - goto found; - last_pc = pc; - last_line_num = sym->n_desc; - /* XXX: slow! */ - strcpy(last_func_name, func_name); - break; - /* include files */ - case N_BINCL: - str = stab_str + sym->n_strx; - add_incl: - if (incl_index < INCLUDE_STACK_SIZE) { - incl_files[incl_index++] = str; - } - break; - case N_EINCL: - if (incl_index > 1) - incl_index--; - break; - case N_SO: - if (sym->n_strx == 0) { - incl_index = 0; /* end of translation unit */ - } else { - str = stab_str + sym->n_strx; - /* do not add path */ - len = strlen(str); - if (len > 0 && str[len - 1] != '/') - goto add_incl; - } - break; - } - } - -no_stabs: - /* second pass: we try symtab symbols (no line number info) */ - incl_index = 0; - if (symtab_section) - { - ElfW(Sym) *sym, *sym_end; - int type; - - sym_end = (ElfW(Sym) *)(symtab_section->data + symtab_section->data_offset); - for(sym = (ElfW(Sym) *)symtab_section->data + 1; - sym < sym_end; - sym++) { - type = ELFW(ST_TYPE)(sym->st_info); - if (type == STT_FUNC || type == STT_GNU_IFUNC) { - if (wanted_pc >= sym->st_value && - wanted_pc < sym->st_value + sym->st_size) { - pstrcpy(last_func_name, sizeof(last_func_name), - (char *) symtab_section->link->data + sym->st_name); - func_addr = sym->st_value; - goto found; - } - } - } - } - /* did not find any info: */ - fprintf(stderr, "%s %p ???\n", msg, (void*)wanted_pc); - fflush(stderr); - return 0; - found: - i = incl_index; - if (i > 0) - fprintf(stderr, "%s:%d: ", incl_files[--i], last_line_num); - fprintf(stderr, "%s %p", msg, (void*)wanted_pc); - if (last_func_name[0] != '\0') - fprintf(stderr, " %s()", last_func_name); - if (--i >= 0) { - fprintf(stderr, " (included from "); - for (;;) { - fprintf(stderr, "%s", incl_files[i]); - if (--i < 0) - break; - fprintf(stderr, ", "); - } - fprintf(stderr, ")"); - } - fprintf(stderr, "\n"); - fflush(stderr); - return func_addr; -} - -/* emit a run time error at position 'pc' */ -static void rt_error(ucontext_t *uc, const char *fmt, ...) -{ - va_list ap; - addr_t pc; - int i; - - fprintf(stderr, "Runtime error: "); - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); - fprintf(stderr, "\n"); - - for(i=0;isi_code) { -// case FPE_INTDIV: -// case FPE_FLTDIV: -// rt_error(uc, "division by zero"); -// break; -// default: -// rt_error(uc, "floating point exception"); -// break; -// } -// break; -// case SIGBUS: -// case SIGSEGV: -// if (rt_bound_error_msg && *rt_bound_error_msg) -// rt_error(uc, *rt_bound_error_msg); -// else -// rt_error(uc, "dereferencing invalid pointer"); -// break; -// case SIGILL: -// rt_error(uc, "illegal instruction"); -// break; -// case SIGABRT: -// rt_error(uc, "abort() called"); -// break; -// default: -// rt_error(uc, "caught signal %d", signum); -// break; -// } -// exit(255); -// } - -#ifndef SA_SIGINFO -# define SA_SIGINFO 0x00000004u -#endif - -/* Generate a stack backtrace when a CPU exception occurs. */ -static void set_exception_handler(void) -{ - struct sigaction sigact; - /* install TCC signal handlers to print debug info on fatal - runtime errors */ - sigact.sa_flags = SA_SIGINFO | SA_RESETHAND; - // sigact.sa_sigaction = sig_error; - sigemptyset(&sigact.sa_mask); - sigaction(SIGFPE, &sigact, NULL); - sigaction(SIGILL, &sigact, NULL); - sigaction(SIGSEGV, &sigact, NULL); - sigaction(SIGBUS, &sigact, NULL); - sigaction(SIGABRT, &sigact, NULL); -} - -/* ------------------------------------------------------------- */ -#ifdef __i386__ - -/* fix for glibc 2.1 */ -#ifndef REG_EIP -#define REG_EIP EIP -#define REG_EBP EBP -#endif - -/* return the PC at frame level 'level'. Return negative if not found */ -static int rt_get_caller_pc(addr_t *paddr, ucontext_t *uc, int level) -{ - addr_t fp; - int i; - - if (level == 0) { -#if defined(__APPLE__) - *paddr = uc->uc_mcontext->__ss.__eip; -#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) - *paddr = uc->uc_mcontext.mc_eip; -#elif defined(__dietlibc__) - *paddr = uc->uc_mcontext.eip; -#elif defined(__NetBSD__) - *paddr = uc->uc_mcontext.__gregs[_REG_EIP]; -#elif defined(__OpenBSD__) - *paddr = uc->sc_eip; -#else - *paddr = uc->uc_mcontext.__gregs[REG_EIP]; -#endif - return 0; - } else { -#if defined(__APPLE__) - fp = uc->uc_mcontext->__ss.__ebp; -#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) - fp = uc->uc_mcontext.mc_ebp; -#elif defined(__dietlibc__) - fp = uc->uc_mcontext.ebp; -#elif defined(__NetBSD__) - fp = uc->uc_mcontext.__gregs[_REG_EBP]; -#elif defined(__OpenBSD__) - *paddr = uc->sc_ebp; -#else - fp = uc->uc_mcontext.__gregs[REG_EBP]; -#endif - for(i=1;i= 0xc0000000) - return -1; - fp = ((addr_t *)fp)[0]; - } - *paddr = ((addr_t *)fp)[1]; - return 0; - } -} - -/* ------------------------------------------------------------- */ -#elif defined(__x86_64__) - -/* return the PC at frame level 'level'. Return negative if not found */ -static int rt_get_caller_pc(addr_t *paddr, ucontext_t *uc, int level) -{ - addr_t fp; - int i; - - if (level == 0) { - /* XXX: only support linux */ -#if defined(__APPLE__) - *paddr = uc->uc_mcontext->__ss.__rip; -#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) - *paddr = uc->uc_mcontext.mc_rip; -#elif defined(__NetBSD__) - *paddr = uc->uc_mcontext.__gregs[_REG_RIP]; -#else - *paddr = uc->uc_mcontext.__gregs[REG_RIP]; -#endif - return 0; - } else { -#if defined(__APPLE__) - fp = uc->uc_mcontext->__ss.__rbp; -#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) - fp = uc->uc_mcontext.mc_rbp; -#elif defined(__NetBSD__) - fp = uc->uc_mcontext.__gregs[_REG_RBP]; -#else - fp = uc->uc_mcontext.__gregs[REG_RBP]; -#endif - for(i=1;iuc_mcontext.arm_pc; -#else - return -1; -#endif - return 0; - } else { -#if defined(__linux__) - fp = uc->uc_mcontext.arm_fp; - sp = uc->uc_mcontext.arm_sp; - if (sp < 0x1000) - sp = 0x1000; -#else - return -1; -#endif - /* XXX: specific to tinycc stack frames */ - if (fp < sp + 12 || fp & 3) - return -1; - for(i = 1; i < level; i++) { - sp = ((addr_t *)fp)[-2]; - if (sp < fp || sp - fp > 16 || sp & 3) - return -1; - fp = ((addr_t *)fp)[-3]; - if (fp <= sp || fp - sp < 12 || fp & 3) - return -1; - } - /* XXX: check address validity with program info */ - *paddr = ((addr_t *)fp)[-1]; - return 0; - } -} - -/* ------------------------------------------------------------- */ -#elif defined(__aarch64__) - -static int rt_get_caller_pc(addr_t *paddr, ucontext_t *uc, int level) -{ - if (level < 0) - return -1; - else if (level == 0) { - *paddr = uc->uc_mcontext.pc; - return 0; - } - else { - addr_t *fp = (addr_t *)uc->uc_mcontext.regs[29]; - int i; - for (i = 1; i < level; i++) - fp = (addr_t *)fp[0]; - *paddr = fp[1]; - return 0; - } -} - -/* ------------------------------------------------------------- */ -#else - -#warning add arch specific rt_get_caller_pc() -static int rt_get_caller_pc(addr_t *paddr, ucontext_t *uc, int level) -{ - return -1; -} - -#endif /* !__i386__ */ - -/* ------------------------------------------------------------- */ -#else /* WIN32 */ - -static long __stdcall cpu_exception_handler(EXCEPTION_POINTERS *ex_info) -{ - EXCEPTION_RECORD *er = ex_info->ExceptionRecord; - CONTEXT *uc = ex_info->ContextRecord; - switch (er->ExceptionCode) { - case EXCEPTION_ACCESS_VIOLATION: - if (rt_bound_error_msg && *rt_bound_error_msg) - rt_error(uc, *rt_bound_error_msg); - else - rt_error(uc, "access violation"); - break; - case EXCEPTION_STACK_OVERFLOW: - rt_error(uc, "stack overflow"); - break; - case EXCEPTION_INT_DIVIDE_BY_ZERO: - rt_error(uc, "division by zero"); - break; - default: - rt_error(uc, "exception caught"); - break; - } - return EXCEPTION_EXECUTE_HANDLER; -} - -/* Generate a stack backtrace when a CPU exception occurs. */ -static void set_exception_handler(void) -{ - SetUnhandledExceptionFilter(cpu_exception_handler); -} - -/* return the PC at frame level 'level'. Return non zero if not found */ -static int rt_get_caller_pc(addr_t *paddr, CONTEXT *uc, int level) -{ - addr_t fp, pc; - int i; -#ifdef _WIN64 - pc = uc->Rip; - fp = uc->Rbp; -#else - pc = uc->Eip; - fp = uc->Ebp; -#endif - if (level > 0) { - for(i=1;i= 0xc0000000) - return -1; - fp = ((addr_t*)fp)[0]; - } - pc = ((addr_t*)fp)[1]; - } - *paddr = pc; - return 0; -} - -#endif /* _WIN32 */ -#endif /* CONFIG_TCC_BACKTRACE */ -/* ------------------------------------------------------------- */ -#ifdef CONFIG_TCC_STATIC - -/* dummy function for profiling */ -ST_FUNC void *dlopen(const char *filename, int flag) -{ - return NULL; -} - -ST_FUNC void dlclose(void *p) -{ -} - -ST_FUNC const char *dlerror(void) -{ - return "error"; -} - -typedef struct TCCSyms { - char *str; - void *ptr; -} TCCSyms; - - -/* add the symbol you want here if no dynamic linking is done */ -static TCCSyms tcc_syms[] = { -#if !defined(CONFIG_TCCBOOT) -#define TCCSYM(a) { #a, &a, }, - TCCSYM(printf) - TCCSYM(fprintf) - TCCSYM(fopen) - TCCSYM(fclose) -#undef TCCSYM -#endif - { NULL, NULL }, -}; - -ST_FUNC void *dlsym(void *handle, const char *symbol) -{ - TCCSyms *p; - p = tcc_syms; - while (p->str != NULL) { - if (!strcmp(p->str, symbol)) - return p->ptr; - p++; - } - return NULL; -} - -#endif /* CONFIG_TCC_STATIC */ -#endif /* TCC_IS_NATIVE */ -/* ------------------------------------------------------------- */ diff --git a/05/tcc-final-old/tcctok.h b/05/tcc-final-old/tcctok.h deleted file mode 100644 index 317f64c..0000000 --- a/05/tcc-final-old/tcctok.h +++ /dev/null @@ -1,350 +0,0 @@ -/* keywords */ - DEF(TOK_INT, "int") - DEF(TOK_VOID, "void") - DEF(TOK_CHAR, "char") - DEF(TOK_IF, "if") - DEF(TOK_ELSE, "else") - DEF(TOK_WHILE, "while") - DEF(TOK_BREAK, "break") - DEF(TOK_RETURN, "return") - DEF(TOK_FOR, "for") - DEF(TOK_EXTERN, "extern") - DEF(TOK_STATIC, "static") - DEF(TOK_UNSIGNED, "unsigned") - DEF(TOK_GOTO, "goto") - DEF(TOK_DO, "do") - DEF(TOK_CONTINUE, "continue") - DEF(TOK_SWITCH, "switch") - DEF(TOK_CASE, "case") - - DEF(TOK_CONST1, "const") - DEF(TOK_CONST2, "__const") /* gcc keyword */ - DEF(TOK_CONST3, "__const__") /* gcc keyword */ - DEF(TOK_VOLATILE1, "volatile") - DEF(TOK_VOLATILE2, "__volatile") /* gcc keyword */ - DEF(TOK_VOLATILE3, "__volatile__") /* gcc keyword */ - DEF(TOK_LONG, "long") - DEF(TOK_REGISTER, "register") - DEF(TOK_SIGNED1, "signed") - DEF(TOK_SIGNED2, "__signed") /* gcc keyword */ - DEF(TOK_SIGNED3, "__signed__") /* gcc keyword */ - DEF(TOK_AUTO, "auto") - DEF(TOK_INLINE1, "inline") - DEF(TOK_INLINE2, "__inline") /* gcc keyword */ - DEF(TOK_INLINE3, "__inline__") /* gcc keyword */ - DEF(TOK_RESTRICT1, "restrict") - DEF(TOK_RESTRICT2, "__restrict") - DEF(TOK_RESTRICT3, "__restrict__") - DEF(TOK_EXTENSION, "__extension__") /* gcc keyword */ - - DEF(TOK_GENERIC, "_Generic") - - DEF(TOK_FLOAT, "float") - DEF(TOK_DOUBLE, "double") - DEF(TOK_BOOL, "_Bool") - DEF(TOK_SHORT, "short") - DEF(TOK_STRUCT, "struct") - DEF(TOK_UNION, "union") - DEF(TOK_TYPEDEF, "typedef") - DEF(TOK_DEFAULT, "default") - DEF(TOK_ENUM, "enum") - DEF(TOK_SIZEOF, "sizeof") - DEF(TOK_ATTRIBUTE1, "__attribute") - DEF(TOK_ATTRIBUTE2, "__attribute__") - DEF(TOK_ALIGNOF1, "__alignof") - DEF(TOK_ALIGNOF2, "__alignof__") - DEF(TOK_TYPEOF1, "typeof") - DEF(TOK_TYPEOF2, "__typeof") - DEF(TOK_TYPEOF3, "__typeof__") - DEF(TOK_LABEL, "__label__") - DEF(TOK_ASM1, "asm") - DEF(TOK_ASM2, "__asm") - DEF(TOK_ASM3, "__asm__") - -#ifdef TCC_TARGET_ARM64 - DEF(TOK_UINT128, "__uint128_t") -#endif - -/*********************************************************************/ -/* the following are not keywords. They are included to ease parsing */ -/* preprocessor only */ - DEF(TOK_DEFINE, "define") - DEF(TOK_INCLUDE, "include") - DEF(TOK_INCLUDE_NEXT, "include_next") - DEF(TOK_IFDEF, "ifdef") - DEF(TOK_IFNDEF, "ifndef") - DEF(TOK_ELIF, "elif") - DEF(TOK_ENDIF, "endif") - DEF(TOK_DEFINED, "defined") - DEF(TOK_UNDEF, "undef") - DEF(TOK_ERROR, "error") - DEF(TOK_WARNING, "warning") - DEF(TOK_LINE, "line") - DEF(TOK_PRAGMA, "pragma") - DEF(TOK___LINE__, "__LINE__") - DEF(TOK___FILE__, "__FILE__") - DEF(TOK___DATE__, "__DATE__") - DEF(TOK___TIME__, "__TIME__") - DEF(TOK___FUNCTION__, "__FUNCTION__") - DEF(TOK___VA_ARGS__, "__VA_ARGS__") - DEF(TOK___COUNTER__, "__COUNTER__") - -/* special identifiers */ - DEF(TOK___FUNC__, "__func__") - -/* special floating point values */ - DEF(TOK___NAN__, "__nan__") - DEF(TOK___SNAN__, "__snan__") - DEF(TOK___INF__, "__inf__") - -/* attribute identifiers */ -/* XXX: handle all tokens generically since speed is not critical */ - DEF(TOK_SECTION1, "section") - DEF(TOK_SECTION2, "__section__") - DEF(TOK_ALIGNED1, "aligned") - DEF(TOK_ALIGNED2, "__aligned__") - DEF(TOK_PACKED1, "packed") - DEF(TOK_PACKED2, "__packed__") - DEF(TOK_WEAK1, "weak") - DEF(TOK_WEAK2, "__weak__") - DEF(TOK_ALIAS1, "alias") - DEF(TOK_ALIAS2, "__alias__") - DEF(TOK_UNUSED1, "unused") - DEF(TOK_UNUSED2, "__unused__") - DEF(TOK_CDECL1, "cdecl") - DEF(TOK_CDECL2, "__cdecl") - DEF(TOK_CDECL3, "__cdecl__") - DEF(TOK_STDCALL1, "stdcall") - DEF(TOK_STDCALL2, "__stdcall") - DEF(TOK_STDCALL3, "__stdcall__") - DEF(TOK_FASTCALL1, "fastcall") - DEF(TOK_FASTCALL2, "__fastcall") - DEF(TOK_FASTCALL3, "__fastcall__") - DEF(TOK_REGPARM1, "regparm") - DEF(TOK_REGPARM2, "__regparm__") - - DEF(TOK_MODE, "__mode__") - DEF(TOK_MODE_QI, "__QI__") - DEF(TOK_MODE_DI, "__DI__") - DEF(TOK_MODE_HI, "__HI__") - DEF(TOK_MODE_SI, "__SI__") - DEF(TOK_MODE_word, "__word__") - - DEF(TOK_DLLEXPORT, "dllexport") - DEF(TOK_DLLIMPORT, "dllimport") - DEF(TOK_NORETURN1, "noreturn") - DEF(TOK_NORETURN2, "__noreturn__") - DEF(TOK_VISIBILITY1, "visibility") - DEF(TOK_VISIBILITY2, "__visibility__") - - DEF(TOK_builtin_types_compatible_p, "__builtin_types_compatible_p") - DEF(TOK_builtin_choose_expr, "__builtin_choose_expr") - DEF(TOK_builtin_constant_p, "__builtin_constant_p") - DEF(TOK_builtin_frame_address, "__builtin_frame_address") - DEF(TOK_builtin_return_address, "__builtin_return_address") - DEF(TOK_builtin_expect, "__builtin_expect") - /*DEF(TOK_builtin_va_list, "__builtin_va_list")*/ -#if defined TCC_TARGET_PE && defined TCC_TARGET_X86_64 - DEF(TOK_builtin_va_start, "__builtin_va_start") -#elif defined TCC_TARGET_X86_64 - DEF(TOK_builtin_va_arg_types, "__builtin_va_arg_types") -#elif defined TCC_TARGET_ARM64 - DEF(TOK___va_start, "__va_start") - DEF(TOK___va_arg, "__va_arg") -#endif - -/* pragma */ - DEF(TOK_pack, "pack") -#if !defined(TCC_TARGET_I386) && !defined(TCC_TARGET_X86_64) - /* already defined for assembler */ - DEF(TOK_ASM_push, "push") - DEF(TOK_ASM_pop, "pop") -#endif - DEF(TOK_comment, "comment") - DEF(TOK_lib, "lib") - DEF(TOK_push_macro, "push_macro") - DEF(TOK_pop_macro, "pop_macro") - DEF(TOK_once, "once") - DEF(TOK_option, "option") - -/* builtin functions or variables */ -#ifndef TCC_ARM_EABI - DEF(TOK_memcpy, "memcpy") - DEF(TOK_memmove, "memmove") - DEF(TOK_memset, "memset") - DEF(TOK___divdi3, "__divdi3") - DEF(TOK___moddi3, "__moddi3") - DEF(TOK___udivdi3, "__udivdi3") - DEF(TOK___umoddi3, "__umoddi3") - DEF(TOK___ashrdi3, "__ashrdi3") - DEF(TOK___lshrdi3, "__lshrdi3") - DEF(TOK___ashldi3, "__ashldi3") - DEF(TOK___floatundisf, "__floatundisf") - DEF(TOK___floatundidf, "__floatundidf") -# ifndef TCC_ARM_VFP - DEF(TOK___floatundixf, "__floatundixf") - DEF(TOK___fixunsxfdi, "__fixunsxfdi") -# endif - DEF(TOK___fixunssfdi, "__fixunssfdi") - DEF(TOK___fixunsdfdi, "__fixunsdfdi") -#endif - -#if defined TCC_TARGET_ARM -# ifdef TCC_ARM_EABI - DEF(TOK_memcpy, "__aeabi_memcpy") - DEF(TOK_memcpy4, "__aeabi_memcpy4") - DEF(TOK_memcpy8, "__aeabi_memcpy8") - DEF(TOK_memmove, "__aeabi_memmove") - DEF(TOK_memset, "__aeabi_memset") - DEF(TOK___aeabi_ldivmod, "__aeabi_ldivmod") - DEF(TOK___aeabi_uldivmod, "__aeabi_uldivmod") - DEF(TOK___aeabi_idivmod, "__aeabi_idivmod") - DEF(TOK___aeabi_uidivmod, "__aeabi_uidivmod") - DEF(TOK___divsi3, "__aeabi_idiv") - DEF(TOK___udivsi3, "__aeabi_uidiv") - DEF(TOK___floatdisf, "__aeabi_l2f") - DEF(TOK___floatdidf, "__aeabi_l2d") - DEF(TOK___fixsfdi, "__aeabi_f2lz") - DEF(TOK___fixdfdi, "__aeabi_d2lz") - DEF(TOK___ashrdi3, "__aeabi_lasr") - DEF(TOK___lshrdi3, "__aeabi_llsr") - DEF(TOK___ashldi3, "__aeabi_llsl") - DEF(TOK___floatundisf, "__aeabi_ul2f") - DEF(TOK___floatundidf, "__aeabi_ul2d") - DEF(TOK___fixunssfdi, "__aeabi_f2ulz") - DEF(TOK___fixunsdfdi, "__aeabi_d2ulz") -# else - DEF(TOK___modsi3, "__modsi3") - DEF(TOK___umodsi3, "__umodsi3") - DEF(TOK___divsi3, "__divsi3") - DEF(TOK___udivsi3, "__udivsi3") - DEF(TOK___floatdisf, "__floatdisf") - DEF(TOK___floatdidf, "__floatdidf") -# ifndef TCC_ARM_VFP - DEF(TOK___floatdixf, "__floatdixf") - DEF(TOK___fixunssfsi, "__fixunssfsi") - DEF(TOK___fixunsdfsi, "__fixunsdfsi") - DEF(TOK___fixunsxfsi, "__fixunsxfsi") - DEF(TOK___fixxfdi, "__fixxfdi") -# endif - DEF(TOK___fixsfdi, "__fixsfdi") - DEF(TOK___fixdfdi, "__fixdfdi") -# endif -#endif - -#if defined TCC_TARGET_C67 - DEF(TOK__divi, "_divi") - DEF(TOK__divu, "_divu") - DEF(TOK__divf, "_divf") - DEF(TOK__divd, "_divd") - DEF(TOK__remi, "_remi") - DEF(TOK__remu, "_remu") -#endif - -#if defined TCC_TARGET_I386 - DEF(TOK___fixsfdi, "__fixsfdi") - DEF(TOK___fixdfdi, "__fixdfdi") - DEF(TOK___fixxfdi, "__fixxfdi") -#endif - -#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64 - DEF(TOK_alloca, "alloca") -#endif - -#if defined TCC_TARGET_PE - DEF(TOK___chkstk, "__chkstk") -#endif -#ifdef TCC_TARGET_ARM64 - DEF(TOK___arm64_clear_cache, "__arm64_clear_cache") - DEF(TOK___addtf3, "__addtf3") - DEF(TOK___subtf3, "__subtf3") - DEF(TOK___multf3, "__multf3") - DEF(TOK___divtf3, "__divtf3") - DEF(TOK___extendsftf2, "__extendsftf2") - DEF(TOK___extenddftf2, "__extenddftf2") - DEF(TOK___trunctfsf2, "__trunctfsf2") - DEF(TOK___trunctfdf2, "__trunctfdf2") - DEF(TOK___fixtfsi, "__fixtfsi") - DEF(TOK___fixtfdi, "__fixtfdi") - DEF(TOK___fixunstfsi, "__fixunstfsi") - DEF(TOK___fixunstfdi, "__fixunstfdi") - DEF(TOK___floatsitf, "__floatsitf") - DEF(TOK___floatditf, "__floatditf") - DEF(TOK___floatunsitf, "__floatunsitf") - DEF(TOK___floatunditf, "__floatunditf") - DEF(TOK___eqtf2, "__eqtf2") - DEF(TOK___netf2, "__netf2") - DEF(TOK___lttf2, "__lttf2") - DEF(TOK___letf2, "__letf2") - DEF(TOK___gttf2, "__gttf2") - DEF(TOK___getf2, "__getf2") -#endif - -/* bound checking symbols */ -#ifdef CONFIG_TCC_BCHECK - DEF(TOK___bound_ptr_add, "__bound_ptr_add") - DEF(TOK___bound_ptr_indir1, "__bound_ptr_indir1") - DEF(TOK___bound_ptr_indir2, "__bound_ptr_indir2") - DEF(TOK___bound_ptr_indir4, "__bound_ptr_indir4") - DEF(TOK___bound_ptr_indir8, "__bound_ptr_indir8") - DEF(TOK___bound_ptr_indir12, "__bound_ptr_indir12") - DEF(TOK___bound_ptr_indir16, "__bound_ptr_indir16") - DEF(TOK___bound_main_arg, "__bound_main_arg") - DEF(TOK___bound_local_new, "__bound_local_new") - DEF(TOK___bound_local_delete, "__bound_local_delete") -# ifdef TCC_TARGET_PE - DEF(TOK_malloc, "malloc") - DEF(TOK_free, "free") - DEF(TOK_realloc, "realloc") - DEF(TOK_memalign, "memalign") - DEF(TOK_calloc, "calloc") -# endif - DEF(TOK_strlen, "strlen") - DEF(TOK_strcpy, "strcpy") -#endif - -/* Tiny Assembler */ - DEF_ASMDIR(byte) /* must be first directive */ - DEF_ASMDIR(word) - DEF_ASMDIR(align) - DEF_ASMDIR(balign) - DEF_ASMDIR(p2align) - DEF_ASMDIR(set) - DEF_ASMDIR(skip) - DEF_ASMDIR(space) - DEF_ASMDIR(string) - DEF_ASMDIR(asciz) - DEF_ASMDIR(ascii) - DEF_ASMDIR(file) - DEF_ASMDIR(globl) - DEF_ASMDIR(global) - DEF_ASMDIR(weak) - DEF_ASMDIR(hidden) - DEF_ASMDIR(ident) - DEF_ASMDIR(size) - DEF_ASMDIR(type) - DEF_ASMDIR(text) - DEF_ASMDIR(data) - DEF_ASMDIR(bss) - DEF_ASMDIR(previous) - DEF_ASMDIR(pushsection) - DEF_ASMDIR(popsection) - DEF_ASMDIR(fill) - DEF_ASMDIR(rept) - DEF_ASMDIR(endr) - DEF_ASMDIR(org) - DEF_ASMDIR(quad) -#if defined(TCC_TARGET_I386) - DEF_ASMDIR(code16) - DEF_ASMDIR(code32) -#elif defined(TCC_TARGET_X86_64) - DEF_ASMDIR(code64) -#endif - DEF_ASMDIR(short) - DEF_ASMDIR(long) - DEF_ASMDIR(int) - DEF_ASMDIR(section) /* must be last directive */ - -#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64 -#include "i386-tok.h" -#endif diff --git a/05/tcc-final-old/tcctools.c b/05/tcc-final-old/tcctools.c deleted file mode 100644 index 1d4424e..0000000 --- a/05/tcc-final-old/tcctools.c +++ /dev/null @@ -1,546 +0,0 @@ -/* -------------------------------------------------------------- */ -/* - * TCC - Tiny C Compiler - * - * tcctools.c - extra tools and and -m32/64 support - * - */ - -/* -------------------------------------------------------------- */ -/* - * This program is for making libtcc1.a without ar - * tiny_libmaker - tiny elf lib maker - * usage: tiny_libmaker [lib] files... - * Copyright (c) 2007 Timppa - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include "tcc.h" - -//#define ARMAG "!\n" -#define ARFMAG "`\n" - -typedef struct { - char ar_name[16]; - char ar_date[12]; - char ar_uid[6]; - char ar_gid[6]; - char ar_mode[8]; - char ar_size[10]; - char ar_fmag[2]; -} ArHdr; - -static unsigned long le2belong(unsigned long ul) { - return ((ul & 0xFF0000)>>8)+((ul & 0xFF000000)>>24) + - ((ul & 0xFF)<<24)+((ul & 0xFF00)<<8); -} - -/* Returns 1 if s contains any of the chars of list, else 0 */ -static int contains_any(const char *s, const char *list) { - const char *l; - for (; *s; s++) { - for (l = list; *l; l++) { - if (*s == *l) - return 1; - } - } - return 0; -} - -static int ar_usage(int ret) { - fprintf(stderr, "usage: tcc -ar [rcsv] lib file...\n"); - fprintf(stderr, "create library ([abdioptxN] not supported).\n"); - return ret; -} - -ST_FUNC int tcc_tool_ar(TCCState *s1, int argc, char **argv) -{ - static ArHdr arhdr = { - "/ ", - " ", - "0 ", - "0 ", - "0 ", - " ", - ARFMAG - }; - - static ArHdr arhdro = { - " ", - " ", - "0 ", - "0 ", - "0 ", - " ", - ARFMAG - }; - - FILE *fi, *fh = NULL, *fo = NULL; - ElfW(Ehdr) *ehdr; - ElfW(Shdr) *shdr; - ElfW(Sym) *sym; - int i, fsize, i_lib, i_obj; - char *buf, *shstr, *symtab = NULL, *strtab = NULL; - int symtabsize = 0;//, strtabsize = 0; - char *anames = NULL; - int *afpos = NULL; - int istrlen, strpos = 0, fpos = 0, funccnt = 0, funcmax, hofs; - char tfile[260], stmp[20]; - char *file, *name; - int ret = 2; - const char *ops_conflict = "habdioptxN"; // unsupported but destructive if ignored. - int verbose = 0; - - i_lib = 0; i_obj = 0; // will hold the index of the lib and first obj - for (i = 1; i < argc; i++) { - const char *a = argv[i]; - if (*a == '-' && strstr(a, ".")) - ret = 1; // -x.y is always invalid (same as gnu ar) - if ((*a == '-') || (i == 1 && !strstr(a, "."))) { // options argument - if (contains_any(a, ops_conflict)) - ret = 1; - if (strstr(a, "v")) - verbose = 1; - } else { // lib or obj files: don't abort - keep validating all args. - if (!i_lib) // first file is the lib - i_lib = i; - else if (!i_obj) // second file is the first obj - i_obj = i; - } - } - - if (!i_obj) // i_obj implies also i_lib. we require both. - ret = 1; - - if (ret == 1) - return ar_usage(ret); - - if ((fh = fopen(argv[i_lib], "wb")) == NULL) - { - fprintf(stderr, "tcc: ar: can't open file %s \n", argv[i_lib]); - goto the_end; - } - - sprintf(tfile, "%s.tmp", argv[i_lib]); - if ((fo = fopen(tfile, "wb+")) == NULL) - { - fprintf(stderr, "tcc: ar: can't create temporary file %s\n", tfile); - goto the_end; - } - - funcmax = 250; - afpos = tcc_realloc(NULL, funcmax * sizeof *afpos); // 250 func - memcpy(&arhdro.ar_mode, "100666", 6); - - // i_obj = first input object file - while (i_obj < argc) - { - if (*argv[i_obj] == '-') { // by now, all options start with '-' - i_obj++; - continue; - } - if ((fi = fopen(argv[i_obj], "rb")) == NULL) { - fprintf(stderr, "tcc: ar: can't open file %s \n", argv[i_obj]); - goto the_end; - } - if (verbose) - printf("a - %s\n", argv[i_obj]); - - fseek(fi, 0, SEEK_END); - fsize = ftell(fi); - fseek(fi, 0, SEEK_SET); - buf = tcc_malloc(fsize + 1); - fread(buf, fsize, 1, fi); - fclose(fi); - - // elf header - ehdr = (ElfW(Ehdr) *)buf; - if (ehdr->e_ident[4] != ELFCLASSW) - { - fprintf(stderr, "tcc: ar: Unsupported Elf Class: %s\n", argv[i_obj]); - goto the_end; - } - - shdr = (ElfW(Shdr) *) (buf + ehdr->e_shoff + ehdr->e_shstrndx * ehdr->e_shentsize); - shstr = (char *)(buf + shdr->sh_offset); - for (i = 0; i < ehdr->e_shnum; i++) - { - shdr = (ElfW(Shdr) *) (buf + ehdr->e_shoff + i * ehdr->e_shentsize); - if (!shdr->sh_offset) - continue; - if (shdr->sh_type == SHT_SYMTAB) - { - symtab = (char *)(buf + shdr->sh_offset); - symtabsize = shdr->sh_size; - } - if (shdr->sh_type == SHT_STRTAB) - { - if (!strcmp(shstr + shdr->sh_name, ".strtab")) - { - strtab = (char *)(buf + shdr->sh_offset); - //strtabsize = shdr->sh_size; - } - } - } - - if (symtab && symtabsize) - { - int nsym = symtabsize / sizeof(ElfW(Sym)); - //printf("symtab: info size shndx name\n"); - for (i = 1; i < nsym; i++) - { - sym = (ElfW(Sym) *) (symtab + i * sizeof(ElfW(Sym))); - if (sym->st_shndx && - (sym->st_info == 0x10 - || sym->st_info == 0x11 - || sym->st_info == 0x12 - )) { - //printf("symtab: %2Xh %4Xh %2Xh %s\n", sym->st_info, sym->st_size, sym->st_shndx, strtab + sym->st_name); - istrlen = strlen(strtab + sym->st_name)+1; - anames = tcc_realloc(anames, strpos+istrlen); - strcpy(anames + strpos, strtab + sym->st_name); - strpos += istrlen; - if (++funccnt >= funcmax) { - funcmax += 250; - afpos = tcc_realloc(afpos, funcmax * sizeof *afpos); // 250 func more - } - afpos[funccnt] = fpos; - } - } - } - - file = argv[i_obj]; - for (name = strchr(file, 0); - name > file && name[-1] != '/' && name[-1] != '\\'; - --name); - istrlen = strlen(name); - if (istrlen >= sizeof(arhdro.ar_name)) - istrlen = sizeof(arhdro.ar_name) - 1; - memset(arhdro.ar_name, ' ', sizeof(arhdro.ar_name)); - memcpy(arhdro.ar_name, name, istrlen); - arhdro.ar_name[istrlen] = '/'; - sprintf(stmp, "%-10d", fsize); - memcpy(&arhdro.ar_size, stmp, 10); - fwrite(&arhdro, sizeof(arhdro), 1, fo); - fwrite(buf, fsize, 1, fo); - tcc_free(buf); - i_obj++; - fpos += (fsize + sizeof(arhdro)); - } - hofs = 8 + sizeof(arhdr) + strpos + (funccnt+1) * sizeof(int); - fpos = 0; - if ((hofs & 1)) // align - hofs++, fpos = 1; - // write header - fwrite("!\n", 8, 1, fh); - sprintf(stmp, "%-10d", (int)(strpos + (funccnt+1) * sizeof(int))); - memcpy(&arhdr.ar_size, stmp, 10); - fwrite(&arhdr, sizeof(arhdr), 1, fh); - afpos[0] = le2belong(funccnt); - for (i=1; i<=funccnt; i++) - afpos[i] = le2belong(afpos[i] + hofs); - fwrite(afpos, (funccnt+1) * sizeof(int), 1, fh); - fwrite(anames, strpos, 1, fh); - if (fpos) - fwrite("", 1, 1, fh); - // write objects - fseek(fo, 0, SEEK_END); - fsize = ftell(fo); - fseek(fo, 0, SEEK_SET); - buf = tcc_malloc(fsize + 1); - fread(buf, fsize, 1, fo); - fwrite(buf, fsize, 1, fh); - tcc_free(buf); - ret = 0; -the_end: - if (anames) - tcc_free(anames); - if (afpos) - tcc_free(afpos); - if (fh) - fclose(fh); - if (fo) - fclose(fo), remove(tfile); - return ret; -} - -/* -------------------------------------------------------------- */ -/* - * tiny_impdef creates an export definition file (.def) from a dll - * on MS-Windows. Usage: tiny_impdef library.dll [-o outputfile]" - * - * Copyright (c) 2005,2007 grischka - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#ifdef TCC_TARGET_PE - -ST_FUNC int tcc_tool_impdef(TCCState *s1, int argc, char **argv) -{ - int ret, v, i; - char infile[260]; - char outfile[260]; - - const char *file; - char *p, *q; - FILE *fp, *op; - -#ifdef _WIN32 - char path[260]; -#endif - - infile[0] = outfile[0] = 0; - fp = op = NULL; - ret = 1; - p = NULL; - v = 0; - - for (i = 1; i < argc; ++i) { - const char *a = argv[i]; - if ('-' == a[0]) { - if (0 == strcmp(a, "-v")) { - v = 1; - } else if (0 == strcmp(a, "-o")) { - if (++i == argc) - goto usage; - strcpy(outfile, argv[i]); - } else - goto usage; - } else if (0 == infile[0]) - strcpy(infile, a); - else - goto usage; - } - - if (0 == infile[0]) { -usage: - fprintf(stderr, - "usage: tcc -impdef library.dll [-v] [-o outputfile]\n" - "create export definition file (.def) from dll\n" - ); - goto the_end; - } - - if (0 == outfile[0]) { - strcpy(outfile, tcc_basename(infile)); - q = strrchr(outfile, '.'); - if (NULL == q) - q = strchr(outfile, 0); - strcpy(q, ".def"); - } - - file = infile; -#ifdef _WIN32 - if (SearchPath(NULL, file, ".dll", sizeof path, path, NULL)) - file = path; -#endif - ret = tcc_get_dllexports(file, &p); - if (ret || !p) { - fprintf(stderr, "tcc: impdef: %s '%s'\n", - ret == -1 ? "can't find file" : - ret == 1 ? "can't read symbols" : - ret == 0 ? "no symbols found in" : - "unknown file type", file); - ret = 1; - goto the_end; - } - - if (v) - printf("-> %s\n", file); - - op = fopen(outfile, "wb"); - if (NULL == op) { - fprintf(stderr, "tcc: impdef: could not create output file: %s\n", outfile); - goto the_end; - } - - fprintf(op, "LIBRARY %s\n\nEXPORTS\n", tcc_basename(file)); - for (q = p, i = 0; *q; ++i) { - fprintf(op, "%s\n", q); - q += strlen(q) + 1; - } - - if (v) - printf("<- %s (%d symbol%s)\n", outfile, i, &"s"[i<2]); - - ret = 0; - -the_end: - /* cannot free memory received from tcc_get_dllexports - if it came from a dll */ - /* if (p) - tcc_free(p); */ - if (fp) - fclose(fp); - if (op) - fclose(op); - return ret; -} - -#endif /* TCC_TARGET_PE */ - -/* -------------------------------------------------------------- */ -/* - * TCC - Tiny C Compiler - * - * Copyright (c) 2001-2004 Fabrice Bellard - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* re-execute the i386/x86_64 cross-compilers with tcc -m32/-m64: */ - -#if !defined TCC_TARGET_I386 && !defined TCC_TARGET_X86_64 - -ST_FUNC void tcc_tool_cross(TCCState *s, char **argv, int option) -{ - tcc_error("-m%d not implemented.", option); -} - -#else -#ifdef _WIN32 -#include - -static char *str_replace(const char *str, const char *p, const char *r) -{ - const char *s, *s0; - char *d, *d0; - int sl, pl, rl; - - sl = strlen(str); - pl = strlen(p); - rl = strlen(r); - for (d0 = NULL;; d0 = tcc_malloc(sl + 1)) { - for (d = d0, s = str; s0 = s, s = strstr(s, p), s; s += pl) { - if (d) { - memcpy(d, s0, sl = s - s0), d += sl; - memcpy(d, r, rl), d += rl; - } else - sl += rl - pl; - } - if (d) { - strcpy(d, s0); - return d0; - } - } -} - -static int execvp_win32(const char *prog, char **argv) -{ - int ret; char **p; - /* replace all " by \" */ - for (p = argv; *p; ++p) - if (strchr(*p, '"')) - *p = str_replace(*p, "\"", "\\\""); - ret = _spawnvp(P_NOWAIT, prog, (const char *const*)argv); - if (-1 == ret) - return ret; - _cwait(&ret, ret, WAIT_CHILD); - exit(ret); -} -#define execvp execvp_win32 -#endif /* _WIN32 */ - -ST_FUNC void tcc_tool_cross(TCCState *s, char **argv, int target) -{ - char program[4096]; - char *a0 = argv[0]; - int prefix = tcc_basename(a0) - a0; - - snprintf(program, sizeof program, - "%.*s%s" -#ifdef TCC_TARGET_PE - "-win32" -#endif - "-tcc" -#ifdef _WIN32 - ".exe" -#endif - , prefix, a0, target == 64 ? "x86_64" : "i386"); - - if (strcmp(a0, program)) - execvp(argv[0] = program, argv); - tcc_error("could not run '%s'", program); -} - -#endif /* TCC_TARGET_I386 && TCC_TARGET_X86_64 */ -/* -------------------------------------------------------------- */ -/* enable commandline wildcard expansion (tcc -o x.exe *.c) */ - -#ifdef _WIN32 -int _CRT_glob = 1; -#ifndef _CRT_glob -int _dowildcard = 1; -#endif -#endif - -/* -------------------------------------------------------------- */ -/* generate xxx.d file */ - -ST_FUNC void gen_makedeps(TCCState *s, const char *target, const char *filename) -{ - FILE *depout; - char buf[1024]; - int i; - - if (!filename) { - /* compute filename automatically: dir/file.o -> dir/file.d */ - snprintf(buf, sizeof buf, "%.*s.d", - (int)(tcc_fileextension(target) - target), target); - filename = buf; - } - - if (s->verbose) - printf("<- %s\n", filename); - - /* XXX return err codes instead of error() ? */ - depout = fopen(filename, "w"); - if (!depout) - tcc_error("could not open '%s'", filename); - - fprintf(depout, "%s: \\\n", target); - for (i=0; inb_target_deps; ++i) - fprintf(depout, " %s \\\n", s->target_deps[i]); - fprintf(depout, "\n"); - fclose(depout); -} - -/* -------------------------------------------------------------- */ diff --git a/05/tcc-final-old/tests/42test.h b/05/tcc-final-old/tests/42test.h deleted file mode 100644 index 5db7d1c..0000000 --- a/05/tcc-final-old/tests/42test.h +++ /dev/null @@ -1,13 +0,0 @@ -/* This file is to test compute #include directives. It's named so - that it starts with a pre-processing number which isn't a valid - number (42test.h). Including this must work. */ -#ifndef INC42_FIRST -int have_included_42test_h; -#define INC42_FIRST -#elif !defined INC42_SECOND -#define INC42_SECOND -int have_included_42test_h_second; -#else -#define INC42_THIRD -int have_included_42test_h_third; -#endif diff --git a/05/tcc-final-old/tests/Makefile b/05/tcc-final-old/tests/Makefile deleted file mode 100644 index 5f6777d..0000000 --- a/05/tcc-final-old/tests/Makefile +++ /dev/null @@ -1,289 +0,0 @@ -# -# Tiny C Compiler Makefile - tests -# - -TOP = .. -include $(TOP)/Makefile -VPATH = $(TOPSRC)/tests $(TOPSRC) $(TOP) -CFLAGS := $(filter-out -W% -g% -O%,$(CFLAGS)) -I$(TOPSRC) $(LDFLAGS) - -# what tests to run -TESTS = \ - hello-exe \ - hello-run \ - libtest \ - test3 \ - memtest \ - dlltest \ - abitest \ - asm-c-connect-test \ - vla_test-run \ - cross-test \ - tests2-dir \ - pp-dir - -BTESTS = test1b test3b btest - -# test4 -- problem with -static -# asmtest / asmtest2 -- minor differences with gcc -# btest -- works on i386 (including win32) - -# bounds-checking is supported only on i386 -ifneq ($(ARCH),i386) - TESTS := $(filter-out $(BTESTS),$(TESTS)) -endif -ifdef CONFIG_WIN32 - TESTS := $(filter-out $(BTESTS),$(TESTS)) -endif -ifdef CONFIG_OSX # -run only - TESTS := hello-run libtest tests2-dir pp-dir -endif -ifeq (,$(filter arm64 i386 x86_64,$(ARCH))) - TESTS := $(filter-out vla_test-run,$(TESTS)) -endif -ifeq ($(CONFIG_arm_eabi),yes) - TESTS := $(filter-out test3,$(TESTS)) -endif -ifeq (,$(filter i386 x86_64,$(ARCH))) - TESTS := $(filter-out dlltest asm-c-connect-test,$(TESTS)) -endif -ifndef CONFIG_cross - TESTS := $(filter-out cross-%,$(TESTS)) -endif - -ifeq ($(OS),Windows_NT) # for libtcc_test to find libtcc.dll - PATH := $(CURDIR)/$(TOP)$(if $(findstring :\,$(PATH)),;,:)$(PATH) -endif - -RUN_TCC = $(NATIVE_DEFINES) -run $(TOPSRC)/tcc.c $(TCCFLAGS) -DISAS = objdump -d -DUMPTCC = (set -x; $(TOP)/tcc -vv; ldd $(TOP)/tcc; exit 1) - -all test : clean-s $(TESTS) - -hello-exe: ../examples/ex1.c - @echo ------------ $@ ------------ - $(TCC) $< -o hello$(EXESUF) && ./hello$(EXESUF) || $(DUMPTCC) - -hello-run: ../examples/ex1.c - @echo ------------ $@ ------------ - $(TCC) -run $< || $(DUMPTCC) - -libtest: libtcc_test$(EXESUF) - @echo ------------ $@ ------------ - ./libtcc_test$(EXESUF) $(TCCFLAGS) - -libtcc_test$(EXESUF): libtcc_test.c $(LIBTCC) - $(CC) -o $@ $^ $(CFLAGS) $(LIBS) - -%-dir: - @echo ------------ $@ ------------ - $(MAKE) -k -C $* - -# test.ref - generate using cc -test.ref: tcctest.c - $(CC) -o tcctest.gcc $< $(NATIVE_DEFINES) $(CFLAGS) -w -O0 -std=gnu99 -fno-omit-frame-pointer - ./tcctest.gcc > $@ - -# auto test -test1 test1b: tcctest.c test.ref - @echo ------------ $@ ------------ - $(TCC) -run $< > test.out1 - @diff -u test.ref test.out1 && echo "Auto Test OK" - -# iterated test2 (compile tcc then compile tcctest.c !) -test2 test2b: tcctest.c test.ref - @echo ------------ $@ ------------ - $(TCC) $(RUN_TCC) $(RUN_TCC) -run $< > test.out2 - @diff -u test.ref test.out2 && echo "Auto Test2 OK" - -# iterated test3 (compile tcc then compile tcc then compile tcctest.c !) -test3 test3b: tcctest.c test.ref - @echo ------------ $@ ------------ - $(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run $< > test.out3 - @diff -u test.ref test.out3 && echo "Auto Test3 OK" - -test%b : TCCFLAGS += -b - -# binary output test -test4: tcctest.c test.ref - @echo ------------ $@ ------------ -# object + link output - $(TCC) -c -o tcctest3.o $< - $(TCC) -o tcctest3 tcctest3.o - ./tcctest3 > test3.out - @if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi -# dynamic output - $(TCC) -o tcctest1 $< - ./tcctest1 > test1.out - @if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi -# dynamic output + bound check - $(TCC) -b -o tcctest4 $< - ./tcctest4 > test4.out - @if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi -# static output - $(TCC) -static -o tcctest2 $< - ./tcctest2 > test2.out - @if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi - -# use tcc to create libtcc.so/.dll and the tcc(.exe) frontend and run them -dlltest: - @echo ------------ $@ ------------ - $(TCC) $(NATIVE_DEFINES) -DLIBTCC_AS_DLL $(TOPSRC)/libtcc.c $(LIBS) -shared -o libtcc2$(DLLSUF) - $(TCC) $(NATIVE_DEFINES) -DONE_SOURCE=0 $(TOPSRC)/tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF) - ./tcc2$(EXESUF) $(TCCFLAGS) $(RUN_TCC) -run $(TOPSRC)/examples/ex1.c -ifndef CONFIG_WIN32 - @echo ------------ $@ with PIC ------------ - $(CC) $(CFLAGS) -fPIC $(NATIVE_DEFINES) -DLIBTCC_AS_DLL -c $(TOPSRC)/libtcc.c - $(TCC) libtcc.o $(LIBS) -shared -o libtcc2$(DLLSUF) - $(TCC) $(NATIVE_DEFINES) -DONE_SOURCE=0 $(TOPSRC)/tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF) - ./tcc2$(EXESUF) $(TCCFLAGS) $(RUN_TCC) -run $(TOPSRC)/examples/ex1.c -endif - @rm tcc2$(EXESUF) libtcc2$(DLLSUF) - -memtest: - @echo ------------ $@ ------------ - $(CC) $(CFLAGS) $(NATIVE_DEFINES) -DMEM_DEBUG=2 $(TOPSRC)/tcc.c $(LIBS) -o memtest-tcc$(EXESUF) - ./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) $(TOPSRC)/tcc.c $(LIBS) - ./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) -run $(TOPSRC)/tcc.c $(TCCFLAGS) $(TOPSRC)/tests/tcctest.c - - -# memory and bound check auto test -BOUNDS_OK = 1 4 8 10 14 -BOUNDS_FAIL= 2 5 7 9 11 12 13 15 - -btest: boundtest.c - @echo ------------ $@ ------------ - @for i in $(BOUNDS_OK); do \ - echo ; echo --- boundtest $$i ---; \ - if $(TCC) -b -run $< $$i ; then \ - echo succeeded as expected; \ - else\ - echo Failed positive test $$i ; exit 1 ; \ - fi ;\ - done ;\ - for i in $(BOUNDS_FAIL); do \ - echo ; echo --- boundtest $$i ---; \ - if $(TCC) -b -run $< $$i ; then \ - echo Failed negative test $$i ; exit 1 ;\ - else\ - echo failed as expected; \ - fi ;\ - done ;\ - echo; echo Bound test OK - -# speed test -speedtest: ex2 ex3 - @echo ------------ $@ ------------ - time ./ex2 1238 2 3 4 10 13 4 - time $(TCC) -run $(TOPSRC)/examples/ex2.c 1238 2 3 4 10 13 4 - time ./ex3 35 - time $(TCC) -run $(TOPSRC)/examples/ex3.c 35 - -weaktest: tcctest.c test.ref - $(TCC) -c $< -o weaktest.tcc.o - $(CC) -c $< -o weaktest.gcc.o $(NATIVE_DEFINES) $(CFLAGS) -w -O0 -std=gnu99 -fno-omit-frame-pointer - objdump -t weaktest.tcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.tcc.o.txt - objdump -t weaktest.gcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.gcc.o.txt - diff weaktest.gcc.o.txt weaktest.tcc.o.txt && echo "Weak Auto Test OK" - -ex%: $(TOPSRC)/examples/ex%.c - $(CC) -o $@ $< $(CFLAGS) - -# tiny assembler testing -asmtest.ref: asmtest.S - $(CC) -Wa,-W -o asmtest.ref.o -c asmtest.S - objdump -D asmtest.ref.o > asmtest.ref - -asmtest asmtest2: asmtest.ref - @echo ------------ $@ ------------ - $(TCC) $(MAYBE_RUN_TCC) -c asmtest.S - objdump -D asmtest.o > asmtest.out - @if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi - -# test assembler with tcc compiled by itself -asmtest2: MAYBE_RUN_TCC = $(RUN_TCC) - -# Check that code generated by libtcc is binary compatible with -# that generated by CC -abitest-cc$(EXESUF): abitest.c $(LIBTCC) - $(CC) -o $@ $^ $(CFLAGS) $(LIBS) -w - -abitest-tcc$(EXESUF): abitest.c libtcc.c - $(TCC) -o $@ $^ $(NATIVE_DEFINES) $(LIBS) - -ABITESTS := abitest-cc$(EXESUF) -ifneq ($(CONFIG_arm_eabi),yes) # not ARM soft-float - ABITESTS += abitest-tcc$(EXESUF) -endif - -abitest: $(ABITESTS) - @echo ------------ $@ ------------ - ./abitest-cc$(EXESUF) $(TCCFLAGS) -ifneq ($(CONFIG_arm_eabi),yes) # not ARM soft-float - ./abitest-tcc$(EXESUF) $(TCCFLAGS) -endif - -vla_test$(EXESUF): vla_test.c - $(TCC) -o $@ $^ - -vla_test-run: vla_test$(EXESUF) - @echo ------------ $@ ------------ - ./vla_test$(EXESUF) - -asm-c-connect$(EXESUF): asm-c-connect-1.c asm-c-connect-2.c - $(TCC) -o $@ $^ - -asm-c-connect-%.o: asm-c-connect-%.c - $(TCC) -c -o $@ $< - -asm-c-connect-sep$(EXESUF): asm-c-connect-1.o asm-c-connect-2.o - $(TCC) -o $@ $^ - -asm-c-connect-test: asm-c-connect$(EXESUF) asm-c-connect-sep$(EXESUF) - @echo ------------ $@ ------------ - ./asm-c-connect$(EXESUF) > asm-c-connect.out1 && cat asm-c-connect.out1 - ./asm-c-connect-sep$(EXESUF) > asm-c-connect.out2 && cat asm-c-connect.out2 - @diff -u asm-c-connect.out1 asm-c-connect.out2 && echo "ok" - -cross-test : - @echo ------------ $@ ------------ - $(TOP)/i386-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok" - $(TOP)/i386-win32-tcc$(EXESUF) $(TCCFLAGS-win) $(TOPSRC)/examples/ex3.c && echo "ok" - $(TOP)/x86_64-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok" - $(TOP)/x86_64-win32-tcc$(EXESUF) $(TCCFLAGS-win) $(TOPSRC)/examples/ex3.c && echo "ok" - $(TOP)/arm-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok" - $(TOP)/arm-wince-tcc$(EXESUF) $(TCCFLAGS-win) -c $(TOPSRC)/examples/ex3.c && echo "ok" - $(TOP)/arm64-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok" - $(TOP)/c67-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok" - $(TOP)/i386-win32-tcc$(EXESUF) $(TCCFLAGS-win) $(TOPSRC)/win32/examples/hello_win.c && echo "ok" - $(TOP)/x86_64-win32-tcc$(EXESUF) $(TCCFLAGS-win) $(TOPSRC)/win32/examples/hello_win.c && echo "ok" - $(TOP)/arm-wince-tcc$(EXESUF) $(TCCFLAGS-win) -c $(TOPSRC)/win32/examples/hello_win.c && echo "ok" - -# targets for development -%.bin: %.c tcc - $(TCC) -g -o $@ $< - $(DISAS) $@ - -instr: instr.o - objdump -d instr.o - -instr.o: instr.S - $(CC) -o $@ -c $< -O2 -Wall -g - -cache: tcc_g - cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c - vg_annotate tcc.c > /tmp/linpack.cache.log - -# clean -clean: - rm -f *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.cc *.gcc - rm -f *-cc *-gcc *-tcc *.exe hello libtcc_test vla_test tcctest[1234] - rm -f asm-c-connect$(EXESUF) - rm -f ex? tcc_g weaktest.*.txt *.def - @$(MAKE) -C tests2 $@ - @$(MAKE) -C pp $@ - -# silent clean, used before running tests -clean-s: - @$(MAKE) -s --no-print-directory clean diff --git a/05/tcc-final-old/tests/abitest.c b/05/tcc-final-old/tests/abitest.c deleted file mode 100644 index 4a192bd..0000000 --- a/05/tcc-final-old/tests/abitest.c +++ /dev/null @@ -1,691 +0,0 @@ -#include -#include -#include -#include -#include - -// MinGW has 80-bit rather than 64-bit long double which isn't compatible with TCC or MSVC -#if defined(_WIN32) && defined(__GNUC__) -#define LONG_DOUBLE double -#define LONG_DOUBLE_LITERAL(x) x -#else -#define LONG_DOUBLE long double -#define LONG_DOUBLE_LITERAL(x) x ## L -#endif - -static int g_argc; -static char **g_argv; - -static void set_options(TCCState *s, int argc, char **argv) -{ - int i; - for (i = 1; i < argc; ++i) { - char *a = argv[i]; - if (a[0] == '-') { - if (a[1] == 'B') - tcc_set_lib_path(s, a+2); - else if (a[1] == 'I') - tcc_add_include_path(s, a+2); - else if (a[1] == 'L') - tcc_add_library_path(s, a+2); - } - } -} - -typedef int (*callback_type) (void*); - -/* - * Compile source code and call a callback with a pointer to the symbol "f". - */ -static int run_callback(const char *src, callback_type callback) { - TCCState *s; - int result; - void *ptr; - - s = tcc_new(); - if (!s) - return -1; - - set_options(s, g_argc, g_argv); - - if (tcc_set_output_type(s, TCC_OUTPUT_MEMORY) == -1) - return -1; - if (tcc_compile_string(s, src) == -1) - return -1; - if (tcc_relocate(s, TCC_RELOCATE_AUTO) == -1) - return -1; - - ptr = tcc_get_symbol(s, "f"); - if (!ptr) - return -1; - result = callback(ptr); - - tcc_delete(s); - - return result; -} - -#define STR2(x) #x -#define STR(x) STR2(x) - -#define RET_PRIMITIVE_TEST(name, type, val) \ - static int ret_ ## name ## _test_callback(void *ptr) { \ - type (*callback) (type) = (type(*)(type))ptr; \ - type x = val; \ - type y = callback(x); \ - return (y == x+x) ? 0 : -1; \ - } \ - \ - static int ret_ ## name ## _test(void) { \ - const char *src = STR(type) " f(" STR(type) " x) {return x+x;}"; \ - return run_callback(src, ret_ ## name ## _test_callback); \ - } - -RET_PRIMITIVE_TEST(int, int, 70000) -RET_PRIMITIVE_TEST(longlong, long long, 4333369356528LL) -RET_PRIMITIVE_TEST(float, float, 63.0) -RET_PRIMITIVE_TEST(double, double, 14789798.0) -RET_PRIMITIVE_TEST(longdouble, LONG_DOUBLE, LONG_DOUBLE_LITERAL(378943892.0)) - -/* - * ret_2float_test: - * - * On x86-64, a struct with 2 floats should be packed into a single - * SSE register (VT_DOUBLE is used for this purpose). - */ -typedef struct ret_2float_test_type_s {float x, y;} ret_2float_test_type; -typedef ret_2float_test_type (*ret_2float_test_function_type) (ret_2float_test_type); - -static int ret_2float_test_callback(void *ptr) { - ret_2float_test_function_type f = (ret_2float_test_function_type)ptr; - ret_2float_test_type a = {10, 35}; - ret_2float_test_type r; - r = f(a); - return ((r.x == a.x*5) && (r.y == a.y*3)) ? 0 : -1; -} - -static int ret_2float_test(void) { - const char *src = - "typedef struct ret_2float_test_type_s {float x, y;} ret_2float_test_type;" - "ret_2float_test_type f(ret_2float_test_type a) {\n" - " ret_2float_test_type r = {a.x*5, a.y*3};\n" - " return r;\n" - "}\n"; - - return run_callback(src, ret_2float_test_callback); -} - -/* - * ret_2double_test: - * - * On x86-64, a struct with 2 doubles should be passed in two SSE - * registers. - */ -typedef struct ret_2double_test_type_s {double x, y;} ret_2double_test_type; -typedef ret_2double_test_type (*ret_2double_test_function_type) (ret_2double_test_type); - -static int ret_2double_test_callback(void *ptr) { - ret_2double_test_function_type f = (ret_2double_test_function_type)ptr; - ret_2double_test_type a = {10, 35}; - ret_2double_test_type r; - r = f(a); - return ((r.x == a.x*5) && (r.y == a.y*3)) ? 0 : -1; -} - -static int ret_2double_test(void) { - const char *src = - "typedef struct ret_2double_test_type_s {double x, y;} ret_2double_test_type;" - "ret_2double_test_type f(ret_2double_test_type a) {\n" - " ret_2double_test_type r = {a.x*5, a.y*3};\n" - " return r;\n" - "}\n"; - - return run_callback(src, ret_2double_test_callback); -} - -/* - * ret_8plus2double_test: - * - * This catches a corner case in the x86_64 ABI code: the first 7 - * arguments fit into registers, the 8th doesn't, but the 9th argument - * fits into the 8th XMM register. - * - * Note that the purpose of the 10th argument is to avoid a situation - * in which gcc would accidentally put the double at the right - * address, thus causing a success message even though TCC actually - * generated incorrect code. - */ -typedef ret_2double_test_type (*ret_8plus2double_test_function_type) (double, double, double, double, double, double, double, ret_2double_test_type, double, double); - -static int ret_8plus2double_test_callback(void *ptr) { - ret_8plus2double_test_function_type f = (ret_8plus2double_test_function_type)ptr; - ret_2double_test_type a = {10, 35}; - ret_2double_test_type r; - r = f(0, 0, 0, 0, 0, 0, 0, a, 37, 38); - return ((r.x == 37) && (r.y == 37)) ? 0 : -1; -} - -static int ret_8plus2double_test(void) { - const char *src = - "typedef struct ret_2double_test_type_s {double x, y;} ret_2double_test_type;" - "ret_2double_test_type f(double x1, double x2, double x3, double x4, double x5, double x6, double x7, ret_2double_test_type a, double x8, double x9) {\n" - " ret_2double_test_type r = { x8, x8 };\n" - " return r;\n" - "}\n"; - - return run_callback(src, ret_8plus2double_test_callback); -} - -/* - * ret_mixed_test: - * - * On x86-64, a struct with a double and a 64-bit integer should be - * passed in one SSE register and one integer register. - */ -typedef struct ret_mixed_test_type_s {double x; long long y;} ret_mixed_test_type; -typedef ret_mixed_test_type (*ret_mixed_test_function_type) (ret_mixed_test_type); - -static int ret_mixed_test_callback(void *ptr) { - ret_mixed_test_function_type f = (ret_mixed_test_function_type)ptr; - ret_mixed_test_type a = {10, 35}; - ret_mixed_test_type r; - r = f(a); - return ((r.x == a.x*5) && (r.y == a.y*3)) ? 0 : -1; -} - -static int ret_mixed_test(void) { - const char *src = - "typedef struct ret_mixed_test_type_s {double x; long long y;} ret_mixed_test_type;" - "ret_mixed_test_type f(ret_mixed_test_type a) {\n" - " ret_mixed_test_type r = {a.x*5, a.y*3};\n" - " return r;\n" - "}\n"; - - return run_callback(src, ret_mixed_test_callback); -} - -/* - * ret_mixed2_test: - * - * On x86-64, a struct with two floats and two 32-bit integers should - * be passed in one SSE register and one integer register. - */ -typedef struct ret_mixed2_test_type_s {float x,x2; int y,y2;} ret_mixed2_test_type; -typedef ret_mixed2_test_type (*ret_mixed2_test_function_type) (ret_mixed2_test_type); - -static int ret_mixed2_test_callback(void *ptr) { - ret_mixed2_test_function_type f = (ret_mixed2_test_function_type)ptr; - ret_mixed2_test_type a = {10, 5, 35, 7 }; - ret_mixed2_test_type r; - r = f(a); - return ((r.x == a.x*5) && (r.y == a.y*3)) ? 0 : -1; -} - -static int ret_mixed2_test(void) { - const char *src = - "typedef struct ret_mixed2_test_type_s {float x, x2; int y,y2;} ret_mixed2_test_type;" - "ret_mixed2_test_type f(ret_mixed2_test_type a) {\n" - " ret_mixed2_test_type r = {a.x*5, 0, a.y*3, 0};\n" - " return r;\n" - "}\n"; - - return run_callback(src, ret_mixed2_test_callback); -} - -/* - * ret_mixed3_test: - * - * On x86-64, this struct should be passed in two integer registers. - */ -typedef struct ret_mixed3_test_type_s {float x; int y; float x2; int y2;} ret_mixed3_test_type; -typedef ret_mixed3_test_type (*ret_mixed3_test_function_type) (ret_mixed3_test_type); - -static int ret_mixed3_test_callback(void *ptr) { - ret_mixed3_test_function_type f = (ret_mixed3_test_function_type)ptr; - ret_mixed3_test_type a = {10, 5, 35, 7 }; - ret_mixed3_test_type r; - r = f(a); - return ((r.x == a.x*5) && (r.y2 == a.y*3)) ? 0 : -1; -} - -static int ret_mixed3_test(void) { - const char *src = - "typedef struct ret_mixed3_test_type_s {float x; int y; float x2; int y2;} ret_mixed3_test_type;" - "ret_mixed3_test_type f(ret_mixed3_test_type a) {\n" - " ret_mixed3_test_type r = {a.x*5, 0, 0, a.y*3};\n" - " return r;\n" - "}\n"; - - return run_callback(src, ret_mixed3_test_callback); -} - -/* - * reg_pack_test: return a small struct which should be packed into - * registers (Win32) during return. - */ -typedef struct reg_pack_test_type_s {int x, y;} reg_pack_test_type; -typedef reg_pack_test_type (*reg_pack_test_function_type) (reg_pack_test_type); - -static int reg_pack_test_callback(void *ptr) { - reg_pack_test_function_type f = (reg_pack_test_function_type)ptr; - reg_pack_test_type a = {10, 35}; - reg_pack_test_type r; - r = f(a); - return ((r.x == a.x*5) && (r.y == a.y*3)) ? 0 : -1; -} - -static int reg_pack_test(void) { - const char *src = - "typedef struct reg_pack_test_type_s {int x, y;} reg_pack_test_type;" - "reg_pack_test_type f(reg_pack_test_type a) {\n" - " reg_pack_test_type r = {a.x*5, a.y*3};\n" - " return r;\n" - "}\n"; - - return run_callback(src, reg_pack_test_callback); -} - -/* - * reg_pack_longlong_test: return a small struct which should be packed into - * registers (x86-64) during return. - */ -typedef struct reg_pack_longlong_test_type_s {long long x, y;} reg_pack_longlong_test_type; -typedef reg_pack_longlong_test_type (*reg_pack_longlong_test_function_type) (reg_pack_longlong_test_type); - -static int reg_pack_longlong_test_callback(void *ptr) { - reg_pack_longlong_test_function_type f = (reg_pack_longlong_test_function_type)ptr; - reg_pack_longlong_test_type a = {10, 35}; - reg_pack_longlong_test_type r; - r = f(a); - return ((r.x == a.x*5) && (r.y == a.y*3)) ? 0 : -1; -} - -static int reg_pack_longlong_test(void) { - const char *src = - "typedef struct reg_pack_longlong_test_type_s {long long x, y;} reg_pack_longlong_test_type;" - "reg_pack_longlong_test_type f(reg_pack_longlong_test_type a) {\n" - " reg_pack_longlong_test_type r = {a.x*5, a.y*3};\n" - " return r;\n" - "}\n"; - - return run_callback(src, reg_pack_longlong_test_callback); -} - -/* - * ret_6plus2longlong_test: - * - * This catches a corner case in the x86_64 ABI code: the first 5 - * arguments fit into registers, the 6th doesn't, but the 7th argument - * fits into the 6th argument integer register, %r9. - * - * Note that the purpose of the 10th argument is to avoid a situation - * in which gcc would accidentally put the longlong at the right - * address, thus causing a success message even though TCC actually - * generated incorrect code. - */ -typedef reg_pack_longlong_test_type (*ret_6plus2longlong_test_function_type) (long long, long long, long long, long long, long long, reg_pack_longlong_test_type, long long, long long); - -static int ret_6plus2longlong_test_callback(void *ptr) { - ret_6plus2longlong_test_function_type f = (ret_6plus2longlong_test_function_type)ptr; - reg_pack_longlong_test_type a = {10, 35}; - reg_pack_longlong_test_type r; - r = f(0, 0, 0, 0, 0, a, 37, 38); - return ((r.x == 37) && (r.y == 37)) ? 0 : -1; -} - -static int ret_6plus2longlong_test(void) { - const char *src = - "typedef struct reg_pack_longlong_test_type_s {long long x, y;} reg_pack_longlong_test_type;" - "reg_pack_longlong_test_type f(long long x1, long long x2, long long x3, long long x4, long long x5, reg_pack_longlong_test_type a, long long x8, long long x9) {\n" - " reg_pack_longlong_test_type r = { x8, x8 };\n" - " return r;\n" - "}\n"; - - return run_callback(src, ret_6plus2longlong_test_callback); -} - -/* - * sret_test: Create a struct large enough to be returned via sret - * (hidden pointer as first function argument) - */ -typedef struct sret_test_type_s {long long a, b, c;} sret_test_type; -typedef sret_test_type (*sret_test_function_type) (sret_test_type); - -static int sret_test_callback(void *ptr) { - sret_test_function_type f = (sret_test_function_type)(ptr); - sret_test_type x = {5436LL, 658277698LL, 43878957LL}; - sret_test_type r = f(x); - return ((r.a==x.a*35)&&(r.b==x.b*19)&&(r.c==x.c*21)) ? 0 : -1; -} - -static int sret_test(void) { - const char *src = - "typedef struct sret_test_type_s {long long a, b, c;} sret_test_type;\n" - "sret_test_type f(sret_test_type x) {\n" - " sret_test_type r = {x.a*35, x.b*19, x.c*21};\n" - " return r;\n" - "}\n"; - - return run_callback(src, sret_test_callback); -} - -/* - * one_member_union_test: - * - * In the x86-64 ABI a union should always be passed on the stack. However - * it appears that a single member union is treated by GCC as its member. - */ -typedef union one_member_union_test_type_u {int x;} one_member_union_test_type; -typedef one_member_union_test_type (*one_member_union_test_function_type) (one_member_union_test_type); - -static int one_member_union_test_callback(void *ptr) { - one_member_union_test_function_type f = (one_member_union_test_function_type)ptr; - one_member_union_test_type a, b; - a.x = 34; - b = f(a); - return (b.x == a.x*2) ? 0 : -1; -} - -static int one_member_union_test(void) { - const char *src = - "typedef union one_member_union_test_type_u {int x;} one_member_union_test_type;\n" - "one_member_union_test_type f(one_member_union_test_type a) {\n" - " one_member_union_test_type b;\n" - " b.x = a.x * 2;\n" - " return b;\n" - "}\n"; - return run_callback(src, one_member_union_test_callback); -} - -/* - * two_member_union_test: - * - * In the x86-64 ABI a union should always be passed on the stack. - */ -typedef union two_member_union_test_type_u {int x; long y;} two_member_union_test_type; -typedef two_member_union_test_type (*two_member_union_test_function_type) (two_member_union_test_type); - -static int two_member_union_test_callback(void *ptr) { - two_member_union_test_function_type f = (two_member_union_test_function_type)ptr; - two_member_union_test_type a, b; - a.x = 34; - b = f(a); - return (b.x == a.x*2) ? 0 : -1; -} - -static int two_member_union_test(void) { - const char *src = - "typedef union two_member_union_test_type_u {int x; long y;} two_member_union_test_type;\n" - "two_member_union_test_type f(two_member_union_test_type a) {\n" - " two_member_union_test_type b;\n" - " b.x = a.x * 2;\n" - " return b;\n" - "}\n"; - return run_callback(src, two_member_union_test_callback); -} - -/* - * Win64 calling convention test. - */ - -typedef struct many_struct_test_type_s {long long a, b, c;} many_struct_test_type; -typedef many_struct_test_type (*many_struct_test_function_type) (many_struct_test_type,many_struct_test_type,many_struct_test_type,many_struct_test_type,many_struct_test_type,many_struct_test_type); - -static int many_struct_test_callback(void *ptr) { - many_struct_test_function_type f = (many_struct_test_function_type)ptr; - many_struct_test_type v = {1, 2, 3}; - many_struct_test_type r = f(v,v,v,v,v,v); - return ((r.a == 6) && (r.b == 12) && (r.c == 18))?0:-1; -} - -static int many_struct_test(void) { - const char *src = - "typedef struct many_struct_test_type_s {long long a, b, c;} many_struct_test_type;\n" - "many_struct_test_type f(many_struct_test_type x1, many_struct_test_type x2, many_struct_test_type x3, many_struct_test_type x4, many_struct_test_type x5, many_struct_test_type x6) {\n" - " many_struct_test_type y;\n" - " y.a = x1.a + x2.a + x3.a + x4.a + x5.a + x6.a;\n" - " y.b = x1.b + x2.b + x3.b + x4.b + x5.b + x6.b;\n" - " y.c = x1.c + x2.c + x3.c + x4.c + x5.c + x6.c;\n" - " return y;\n" - "}\n"; - return run_callback(src, many_struct_test_callback); -} - -/* - * Win64 calling convention test. - */ - -typedef struct many_struct_test_2_type_s {int a, b;} many_struct_test_2_type; -typedef many_struct_test_2_type (*many_struct_test_2_function_type) (many_struct_test_2_type,many_struct_test_2_type,many_struct_test_2_type,many_struct_test_2_type,many_struct_test_2_type,many_struct_test_2_type); - -static int many_struct_test_2_callback(void *ptr) { - many_struct_test_2_function_type f = (many_struct_test_2_function_type)ptr; - many_struct_test_2_type v = {1,2}; - many_struct_test_2_type r = f(v,v,v,v,v,v); - return ((r.a == 6) && (r.b == 12))?0:-1; -} - -static int many_struct_test_2(void) { - const char *src = - "typedef struct many_struct_test_2_type_s {int a, b;} many_struct_test_2_type;\n" - "many_struct_test_2_type f(many_struct_test_2_type x1, many_struct_test_2_type x2, many_struct_test_2_type x3, many_struct_test_2_type x4, many_struct_test_2_type x5, many_struct_test_2_type x6) {\n" - " many_struct_test_2_type y;\n" - " y.a = x1.a + x2.a + x3.a + x4.a + x5.a + x6.a;\n" - " y.b = x1.b + x2.b + x3.b + x4.b + x5.b + x6.b;\n" - " return y;\n" - "}\n"; - return run_callback(src, many_struct_test_2_callback); -} - -/* - * Win64 calling convention test. - */ - -typedef struct many_struct_test_3_type_s {int a, b;} many_struct_test_3_type; -typedef many_struct_test_3_type (*many_struct_test_3_function_type) (many_struct_test_3_type,many_struct_test_3_type,many_struct_test_3_type,many_struct_test_3_type,many_struct_test_3_type,many_struct_test_3_type, ...); -typedef struct many_struct_test_3_struct_type { many_struct_test_3_function_type f; many_struct_test_3_function_type *f2; } many_struct_test_3_struct_type; - -static void many_struct_test_3_dummy(double d, ...) -{ - volatile double x = d; -} - -static int many_struct_test_3_callback(void *ptr) { - many_struct_test_3_struct_type s = { ptr, }; - many_struct_test_3_struct_type *s2 = &s; - s2->f2 = &s2->f; - many_struct_test_3_dummy(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, &s2); - many_struct_test_3_function_type f = *(s2->f2); - many_struct_test_3_type v = {1,2}; - many_struct_test_3_type r = (*((s2->f2=&f)+0))(v,v,v,v,v,v,1.0); - return ((r.a == 6) && (r.b == 12))?0:-1; -} - -static int many_struct_test_3(void) { - const char *src = - "typedef struct many_struct_test_3_type_s {int a, b;} many_struct_test_3_type;\n" - "many_struct_test_3_type f(many_struct_test_3_type x1, many_struct_test_3_type x2, many_struct_test_3_type x3, many_struct_test_3_type x4, many_struct_test_3_type x5, many_struct_test_3_type x6, ...) {\n" - " many_struct_test_3_type y;\n" - " y.a = x1.a + x2.a + x3.a + x4.a + x5.a + x6.a;\n" - " y.b = x1.b + x2.b + x3.b + x4.b + x5.b + x6.b;\n" - " return y;\n" - "}\n"; - return run_callback(src, many_struct_test_3_callback); -} - -/* - * stdarg_test: Test variable argument list ABI - */ - -typedef struct {long long a, b, c;} stdarg_test_struct_type; -typedef void (*stdarg_test_function_type) (int,int,int,...); - -static int stdarg_test_callback(void *ptr) { - stdarg_test_function_type f = (stdarg_test_function_type)ptr; - int x; - double y; - stdarg_test_struct_type z = {1, 2, 3}, w; - f(10, 10, 5, - 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, &x, - 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, &y, - z, z, z, z, z, &w); - return ((x == 55) && (y == 55) && (w.a == 5) && (w.b == 10) && (w.c == 15)) ? 0 : -1; -} - -static int stdarg_test(void) { - const char *src = - "#include \n" - "typedef struct {long long a, b, c;} stdarg_test_struct_type;\n" - "void f(int n_int, int n_float, int n_struct, ...) {\n" - " int i, ti = 0;\n" - " double td = 0.0;\n" - " stdarg_test_struct_type ts = {0,0,0}, tmp;\n" - " va_list ap;\n" - " va_start(ap, n_struct);\n" - " for (i = 0, ti = 0; i < n_int; ++i)\n" - " ti += va_arg(ap, int);\n" - " *va_arg(ap, int*) = ti;\n" - " for (i = 0, td = 0; i < n_float; ++i)\n" - " td += va_arg(ap, double);\n" - " *va_arg(ap, double*) = td;\n" - " for (i = 0; i < n_struct; ++i) {\n" - " tmp = va_arg(ap, stdarg_test_struct_type);\n" - " ts.a += tmp.a; ts.b += tmp.b; ts.c += tmp.c;" - " }\n" - " *va_arg(ap, stdarg_test_struct_type*) = ts;\n" - " va_end(ap);" - "}\n"; - return run_callback(src, stdarg_test_callback); -} - -typedef struct {long long a, b;} stdarg_many_test_struct_type; -typedef void (*stdarg_many_test_function_type) (int, int, int, int, int, - stdarg_many_test_struct_type, - int, int, ...); - -static int stdarg_many_test_callback(void *ptr) -{ - stdarg_many_test_function_type f = (stdarg_many_test_function_type)ptr; - int x; - stdarg_many_test_struct_type l = {10, 11}; - f(1, 2, 3, 4, 5, l, 6, 7, &x, 44); - return x == 44 ? 0 : -1; -} - -static int stdarg_many_test(void) -{ - const char *src = - "#include \n" - "typedef struct {long long a, b;} stdarg_many_test_struct_type;\n" - "void f (int a, int b, int c, int d, int e, stdarg_many_test_struct_type l, int f, int g, ...){\n" - " va_list ap;\n" - " int *p;\n" - " va_start (ap, g);\n" - " p = va_arg(ap, int*);\n" - " *p = va_arg(ap, int);\n" - " va_end (ap);\n" - "}\n"; - return run_callback(src, stdarg_many_test_callback); -} - -/* - * Test Win32 stdarg handling, since the calling convention will pass a pointer - * to the struct and the stdarg pointer must point to that pointer initially. - */ - -typedef struct {long long a, b, c;} stdarg_struct_test_struct_type; -typedef int (*stdarg_struct_test_function_type) (stdarg_struct_test_struct_type a, ...); - -static int stdarg_struct_test_callback(void *ptr) { - stdarg_struct_test_function_type f = (stdarg_struct_test_function_type)ptr; - stdarg_struct_test_struct_type v = {10, 35, 99}; - int x = f(v, 234); - return (x == 378) ? 0 : -1; -} - -static int stdarg_struct_test(void) { - const char *src = - "#include \n" - "typedef struct {long long a, b, c;} stdarg_struct_test_struct_type;\n" - "int f(stdarg_struct_test_struct_type a, ...) {\n" - " va_list ap;\n" - " va_start(ap, a);\n" - " int z = va_arg(ap, int);\n" - " va_end(ap);\n" - " return z + a.a + a.b + a.c;\n" - "}\n"; - return run_callback(src, stdarg_struct_test_callback); -} - -/* Test that x86-64 arranges the stack correctly for arguments with alignment >8 bytes */ - -typedef LONG_DOUBLE (*arg_align_test_callback_type) (LONG_DOUBLE,int,LONG_DOUBLE,int,LONG_DOUBLE); - -static int arg_align_test_callback(void *ptr) { - arg_align_test_callback_type f = (arg_align_test_callback_type)ptr; - long double x = f(12, 0, 25, 0, 37); - return (x == 74) ? 0 : -1; -} - -static int arg_align_test(void) { - const char *src = - "long double f(long double a, int b, long double c, int d, long double e) {\n" - " return a + c + e;\n" - "}\n"; - return run_callback(src, arg_align_test_callback); -} - -#define RUN_TEST(t) \ - if (!testname || (strcmp(#t, testname) == 0)) { \ - fputs(#t "... ", stdout); \ - fflush(stdout); \ - if (t() == 0) { \ - fputs("success\n", stdout); \ - } else { \ - fputs("failure\n", stdout); \ - retval = EXIT_FAILURE; \ - } \ - } - -int main(int argc, char **argv) { - int i; - const char *testname = NULL; - int retval = EXIT_SUCCESS; - - /* if tcclib.h and libtcc1.a are not installed, where can we find them */ - for (i = 1; i < argc; ++i) { - if (!memcmp(argv[i], "run_test=", 9)) - testname = argv[i] + 9; - } - - g_argv = argv, g_argc = argc; - - RUN_TEST(ret_int_test); - RUN_TEST(ret_longlong_test); - RUN_TEST(ret_float_test); - RUN_TEST(ret_double_test); - RUN_TEST(ret_longdouble_test); - RUN_TEST(ret_2float_test); - RUN_TEST(ret_2double_test); - RUN_TEST(ret_8plus2double_test); - RUN_TEST(ret_6plus2longlong_test); -#if !defined __x86_64__ || defined _WIN32 - /* currently broken on x86_64 linux */ - RUN_TEST(ret_mixed_test); - RUN_TEST(ret_mixed2_test); -#endif - RUN_TEST(ret_mixed3_test); - RUN_TEST(reg_pack_test); - RUN_TEST(reg_pack_longlong_test); - RUN_TEST(sret_test); - RUN_TEST(one_member_union_test); - RUN_TEST(two_member_union_test); - RUN_TEST(many_struct_test); - RUN_TEST(many_struct_test_2); - RUN_TEST(many_struct_test_3); - RUN_TEST(stdarg_test); - RUN_TEST(stdarg_many_test); - RUN_TEST(stdarg_struct_test); - RUN_TEST(arg_align_test); - return retval; -} diff --git a/05/tcc-final-old/tests/asm-c-connect-1.c b/05/tcc-final-old/tests/asm-c-connect-1.c deleted file mode 100644 index 8a28d78..0000000 --- a/05/tcc-final-old/tests/asm-c-connect-1.c +++ /dev/null @@ -1,57 +0,0 @@ -#include - -#if defined _WIN32 && !defined __TINYC__ -# define _ "_" -#else -# define _ -#endif - -static int x1_c(void) -{ - printf(" x1"); - return 1; -} - -asm(".text;"_"x1: call "_"x1_c; ret"); - -void callx4(void); -void callx5_again(void); - -void x6() -{ - printf(" x6-1"); -} - -int main(int argc, char *argv[]) -{ - printf("*"); - asm("call "_"x1"); - asm("call "_"x2"); - asm("call "_"x3"); - callx4(); - asm("call "_"x5"); - callx5_again(); - x6(); - printf(" *\n"); - return 0; -} - -static -int x2(void) -{ - printf(" x2"); - return 2; -} - -extern int x3(void); - -void x4(void) -{ - printf(" x4"); -} - -void x5(void); -void x5(void) -{ - printf(" x5"); -} diff --git a/05/tcc-final-old/tests/asm-c-connect-2.c b/05/tcc-final-old/tests/asm-c-connect-2.c deleted file mode 100644 index 3440b40..0000000 --- a/05/tcc-final-old/tests/asm-c-connect-2.c +++ /dev/null @@ -1,36 +0,0 @@ -#include - -#if defined _WIN32 && !defined __TINYC__ -# define _ "_" -#else -# define _ -#endif - -int x3(void) -{ - printf(" x3"); - return 3; -} - -/* That callx4 is defined globally (as if ".globl callx4") - is a TCC extension. GCC doesn't behave like this. */ -void callx4(void); -__asm__(_"callx4: call "_"x4; ret;" -#ifndef __TINYC__ - " .global "_"callx4" -#endif -); - -extern void x5(void); - -void callx5_again(void); -void callx5_again(void) -{ - x5(); - asm("call "_"x6"); -} - -static void x6() -{ - printf(" x6-2"); -} diff --git a/05/tcc-final-old/tests/asmtest.S b/05/tcc-final-old/tests/asmtest.S deleted file mode 100644 index e9c0e32..0000000 --- a/05/tcc-final-old/tests/asmtest.S +++ /dev/null @@ -1,978 +0,0 @@ -# gas comment with ``gnu'' style quotes - -/* some directive tests */ - - .byte 0xff - .byte 1, 2, 3 - .short 1, 2, 3 - .word 1, 2, 3 - .long 1, 2, 3 - .int 1, 2, 3 - .align 8 - .byte 1 -/* .align 16, 0x90 gas is too clever for us with 0x90 fill */ - .balign 4, 0x92 - .align 16, 0x91 /* 0x91 tests the non-clever behaviour */ - .skip 3 - .skip 15, 0x90 - .string "hello\0world" -/* Macro expansion should work like with C, the #n shouldn't be parsed - as asm line comment */ -#define __stringify(n) #n -#define stringify(n) __stringify(n) - .skip 8,0x90 - .asciz stringify(BLA) - .skip 8,0x90 - -# 28 "asmtest.S" # a line directive (and a line comment) - movl %eax, %ebx # some more asm comment -/* some label tests */ -L1: - movl %eax, %ebx - mov 0x10000, %eax -L2: - movl $L2 - L1, %ecx -var1: - nop ; nop ; nop ; nop - - mov var1, %eax - -/* instruction tests */ -movl %eax, %ebx -mov 0x10000, %eax -mov 0x10000, %ax -mov 0x10000, %al -mov %al, 0x10000 - -mov $1, %edx -mov $1, %dx -mov $1, %cl -movb $2, 0x100(%ebx,%edx,2) -movw $2, 0x100(%ebx,%edx,2) -movl $2, 0x100(%ebx,%edx,2) -movl %eax, 0x100(%ebx,%edx,2) -movl 0x100(%ebx,%edx,2), %edx -movw %ax, 0x100(%ebx,%edx,2) - -movw $0x1122,%si -movl $0x112233,%edx -movl $0x80000000, %esi -movl $-0x7fffffff, %edi -#ifdef __x86_64__ -mov $0x11223344,%rbx -movq $0x11223344,%rbx -mov $0x1122334455,%rbx -movq $0x1122334455,%rbx -movl $0x11334455,(%rbx) -#endif - -mov %eax, 0x12(,%edx,2) - -#ifdef __i386__ -mov %cr3, %edx -mov %ecx, %cr3 -movl %cr3, %eax -movl %tr3, %eax -movl %db3, %ebx -movl %dr6, %eax -#else -mov %cr3, %rdx -mov %rcx, %cr3 -movq %cr3, %rax -movq %db3, %rbx -movq %dr6, %rax -mov %cr8, %rsi -mov %rdi, %cr8 -#endif -movl %fs, %ecx -movl %ebx, %fs - -#ifdef __x86_64__ -movq %r8, %r9 -movq %r10, %r11 -movq %r12, %r13 -movq %r14, %r15 -movq %rax, %r9 -movq %r15, %rsi -inc %r9b -dec %r10w -not %r11d -negq %r12 -decb %r13b -incw %r14w -notl %r15d -#endif - - movsbl 0x1000, %eax - movsbw 0x1000, %ax - movswl 0x1000, %eax - - movzbl 0x1000, %eax - movzbw 0x1000, %ax - movzwl 0x1000, %eax - - movzb 0x1000, %eax - movzb 0x1000, %ax - - mov $0x12345678,%eax - -#ifdef __x86_64__ - movzb 0x1000, %rax - movzbq 0x1000, %rbx - movsbq 0x1000, %rdx - movzwq 0x1000, %rdi - movswq 0x1000, %rdx - movslq %eax, %rcx - mov $0x12345678,%rax - mov $0x12345678,%rdx - mov $0x12345678,%r10 - mov $0x123456789abcdef0,%rax - mov $0x123456789abcdef0,%rcx - mov $0x123456789abcdef0,%r11 -#endif - -#ifdef __i386__ - pushl %eax - push %eax - push %cs -#else - pushq %rax - push %rax -#endif - pushw %ax - push %gs - push $1 - push $100 - push 0x42(%eax) - pop 0x43(%esi) - -#ifdef __i386__ - popl %eax - pop %eax - pop %ds -#else - popq %rax - pop %rax -#endif - popw %ax - pop %fs - - xchg %eax, %ecx - xchg %edx, %eax - xchg %bx, 0x10000 - xchg 0x10000, %ebx - xchg 0x10000, %dl - - in $100, %al - in $100, %ax - in $100, %eax - in %dx, %al - in %dx, %ax - in %dx, %eax - inb %dx - inw %dx - inl %dx - - out %al, $100 - out %ax, $100 - out %eax, $100 - - /* NOTE: gas is bugged here, so size must be added */ - outb %al, %dx - outw %ax, %dx - outl %eax, %dx - - leal 0x1000(%ebx), %ecx - lea 0x1000(%ebx), %ecx - -#ifdef __i386__ - les 0x2000, %eax - lds 0x2000, %ebx - lss 0x2000, %edx -#endif - lfs 0x2000, %ecx - lgs 0x2000, %edx - -addl $0x123, %eax -add $0x123, %ebx -add $-16, %ecx -add $-0x123, %esi -add $1, %bx -add $1, %ebx -add $-1, %bx -add $-1, %ebx -add $127, %bx -addl $127, %ebx -addl $-128, %ebx -addl $-128, %ebx -addl $-129, %ebx -addl $128, %ebx -addl $255, %ebx -addl $256, %ebx -andb $0xf, %ah -andb $-15, %cl -xorb $127, %dh -cmpb $42, (%eax) -addl $0x123, 0x100 -addl $0x123, 0x100(%ebx) -addl $0x123, 0x100(%ebx,%edx,2) -addl $0x123, 0x100(%esp) -addl $0x123, (3*8)(%esp) -addl $0x123, (%ebp) -addl $0x123, (%esp) -cmpl $0x123, (%esp) - -#ifdef __x86_64__ -xor %bl,%ah -xor %bl,%r8b -xor %r9b,%bl -xor %sil,%cl -add %eax,(%r8d) -add %ebx,(%r9) -add %edx,(%r10d,%r11d) -add %ecx,(%r12,%r13) -add %esi,(%r14,%r15,4) -add %edi,0x1000(%rbx,%r12,8) -add %r11,0x1000(%ebp,%r9d,8) -movb $12, %ah -movb $13, %bpl -movb $14, %dil -movb $15, %r12b -#endif - -add %eax, (%ebx) -add (%ebx), %eax - -or %dx, (%ebx) -or (%ebx), %si - -add %cl, (%ebx) -add (%ebx), %dl - - inc %edx - incl 0x10000 - incb 0x10000 - dec %dx - - test $1, %al - test $1, %cl - - testl $1, 0x1000 - testb $1, 0x1000 - testw $1, 0x1000 - test %eax, %ebx - test %eax, 0x1000 - test 0x1000, %edx - - not %edx - notw 0x10000 - notl 0x10000 - notb 0x10000 - - neg %edx - negw 0x10000 - negl 0x10000 - negb 0x10000 - - imul %ecx - mul %edx - mulb %cl - - imul %eax, %ecx - imul 0x1000, %cx - imul $10, %eax, %ecx - imul $10, %ax, %cx - imul $10, %eax - imul $0x1100000, %eax - imul $1, %eax - - idivw 0x1000 - div %ecx - div %bl - div %ecx, %eax - -and $15,%bx -and $-20,%edx - -shl %edx -shl $10, %edx -shl %cl, %edx - -shld $1, %eax, %edx -shld %cl, %eax, %edx -shld %eax, %edx - -shrd $1, %eax, %edx -shrd %cl, %eax, %edx -shrd %eax, %edx - -L4: -call 0x1000 -call L4 -#ifdef __i386__ -call *%eax -#else -call *%rax -#endif -call *0x1000 -call func1 - -.global L5,L6 - -L5: -L6: - -#ifdef __i386__ -lcall $0x100, $0x1000 -#else -lcall *0x100 -lcall *(%rax) -#endif - -jmp 0x1000 -jmp *(%edi) -#ifdef __i386__ -jmp *%eax -#else -jmp *%rax -#endif -jmp *0x1000 - -#ifdef __i386__ -ljmp $0x100, $0x1000 -#else -ljmp *0x100 -ljmp *(%rdi) -ljmpl *(%esi) -ljmpw *(%esi) -#endif - -ret -ret $10 -#ifdef __i386__ -retl -retl $10 -#else -retq -retq $10 -#endif - -lret - -lret $10 - -enter $1234, $10 - -L3: - jo 0x1000 - jnp 0x1001 - jne 0x1002 - jg 0x1003 - - jo L3 - jnp L3 - jne L3 - jg L3 - - loopne L3 - loopnz L3 - loope L3 - loopz L3 - loop L3 - jecxz L3 - - - seto %al - setc %al - setcb %al - setnp 0x1000 - setl 0xaaaa - setg %dl - - fadd - fadd %st(1), %st - fadd %st(0), %st(1) - fadd %st(3) - - fmul %st(0),%st(0) - fmul %st(0),%st(1) - - faddp %st(5) - faddp - faddp %st(1), %st - - fadds 0x1000 - fiadds 0x1002 - faddl 0x1004 - fiaddl 0x1006 - - fmul - fmul %st(1), %st - fmul %st(3) - - fmulp %st(5) - fmulp - fmulp %st(1), %st - - fmuls 0x1000 - fimuls 0x1002 - fmull 0x1004 - fimull 0x1006 - - fsub - fsub %st(1), %st - fsub %st(3) - - fsubp %st(5) - fsubp - fsubp %st(1), %st - - fsubs 0x1000 - fisubs 0x1002 - fsubl 0x1004 - fisubl 0x1006 - - fsubr - fsubr %st(1), %st - fsubr %st(3) - - fsubrp %st(5) - fsubrp - fsubrp %st(1), %st - - fsubrs 0x1000 - fisubrs 0x1002 - fsubrl 0x1004 - fisubrl 0x1006 - - fdiv - fdiv %st(1), %st - fdiv %st(3) - - fdivp %st(5) - fdivp - fdivp %st(1), %st - - fdivs 0x1000 - fidivs 0x1002 - fdivl 0x1004 - fidivl 0x1006 - - fcom %st(3) - - fcoms 0x1000 - ficoms 0x1002 - fcoml 0x1004 - ficoml 0x1006 - - fcomp %st(5) - fcomp - fcompp - - fcomps 0x1000 - ficomps 0x1002 - fcompl 0x1004 - ficompl 0x1006 - - fld %st(5) - fldl 0x1000 - flds 0x1002 - fildl 0x1004 - fst %st(4) - fstp %st(6) - fstpt 0x1006 - fbstp 0x1008 - - fxch - fxch %st(4) - - fucom %st(6) - fucomp %st(3) - fucompp - - finit - fninit - fldcw 0x1000 - fnstcw 0x1002 - fstcw 0x1002 - fnstsw 0x1004 - fnstsw (%eax) - fstsw 0x1004 - fstsw (%eax) - fnclex - fclex - fnstenv 0x1000 - fstenv 0x1000 - fldenv 0x1000 - fnsave 0x1002 - fsave 0x1000 - frstor 0x1000 - ffree %st(7) - ffreep %st(6) - - ftst - fxam - fld1 - fldl2t - fldl2e - fldpi - fldlg2 - fldln2 - fldz - - f2xm1 - fyl2x - fptan - fpatan - fxtract - fprem1 - fdecstp - fincstp - fprem - fyl2xp1 - fsqrt - fsincos - frndint - fscale - fsin - fcos - fchs - fabs - fnop - fwait - -bswap %edx -bswapl %ecx -xadd %ecx, %edx -xaddb %dl, 0x1000 -xaddw %ax, 0x1000 -xaddl %eax, 0x1000 -cmpxchg %ecx, %edx -cmpxchgb %dl, 0x1000 -cmpxchgw %ax, 0x1000 -cmpxchgl %eax, 0x1000 -invlpg 0x1000 -cmpxchg8b 0x1002 -#ifdef __x86_64__ -cmpxchg16b (%rax) -cmpxchg16b (%r10,%r11) -#endif - -fcmovb %st(5), %st -fcmove %st(5), %st -fcmovbe %st(5), %st -fcmovu %st(5), %st -fcmovnb %st(5), %st -fcmovne %st(5), %st -fcmovnbe %st(5), %st -fcmovnu %st(5), %st -fcomi %st(5), %st -fucomi %st(5), %st -fcomip %st(5), %st -fucomip %st(5), %st - - - - cmovo 0x1000, %eax - cmovs 0x1000, %eax - cmovns %edx, %edi - cmovne %ax, %si - cmovbw %ax, %di - cmovnbel %edx, %ecx -#ifdef __x86_64__ - bswapq %rsi - bswapq %r10 - cmovz %rdi,%rbx - cmovpeq %rsi, %rdx -#endif - -int $3 -int $0x10 - -#ifdef __i386__ - pusha - popa -#endif - clc # another comment - cld # a comment with embedded ' tick - cli - clts - cmc - lahf - sahf -#ifdef __i386__ - pushfl - popfl -#else - pushfq - popfq -#endif - pushf - popf - stc - std - sti -#ifdef __i386__ - aaa - aas - daa - das - aad - aam - into -#endif - cbw - cwd - cwde - cdq - cbtw - cwtd - cwtl - cltd - leave - int3 - iret - rsm - hlt - wait - nop - - /* XXX: handle prefixes */ -#if 0 - aword - addr16 -#endif - lock - rep - repe - repz - repne - repnz - nop - - lock ;negl (%eax) - wait ;pushf - rep ;stosb - repe ;lodsb - repz ;cmpsb - repne;movsb - repnz;outsb - - /* handle one-line prefix + ops */ - lock negl (%eax) - wait pushf - rep stosb - repe lodsb - repz cmpsb - repne movsb - repnz outsb - - invd - wbinvd - cpuid - wrmsr - rdtsc - rdmsr - rdpmc - ud2 -#ifdef __x86_64__ - syscall - sysret - sysretq - lfence - mfence - sfence - prefetchnta 0x18(%rdx) - prefetcht0 (%rcx) - prefetcht1 (%rsi) - prefetcht2 (%rdi) - prefetchw (%rdi) - clflush 0x1000(%rax,%rcx) - fxsaveq (%rdx) - fxsaveq (%r11) - fxrstorq (%rcx) - fxrstorq (%r10) - -#endif - - lar %ax,%dx - lar %eax,%dx - lar %ax,%edx - lar %eax,%edx -#ifdef __x86_64__ - lar %ax,%rdx - lar %eax,%rdx -#endif - emms - movd %edx, %mm3 - movd 0x1000, %mm2 - movd %mm4, %ecx - movd %mm5, 0x1000 - - movq 0x1000, %mm2 - movq %mm4, 0x1000 - - pand 0x1000, %mm3 - pand %mm4, %mm5 - - psllw $1, %mm6 - psllw 0x1000, %mm7 - psllw %mm2, %mm7 - - xlat - cmpsb - scmpw - insl - outsw - lodsb - slodl - movsb - movsl - smovb - scasb - sscaw - stosw - sstol - - bsf 0x1000, %ebx - bsr 0x1000, %ebx - bt %edx, 0x1000 - btl $2, 0x1000 - btc %edx, 0x1000 - btcl $2, 0x1000 - btr %edx, 0x1000 - btrl $2, 0x1000 - bts %edx, 0x1000 - btsl $2, 0x1000 - - - -#ifdef __i386__ - boundl %edx, 0x10000 - boundw %bx, 0x1000 - - arpl %bx, 0x1000 -#endif - lar 0x1000, %eax - lgdt 0x1000 - lidt 0x1000 - lldt 0x1000 - sgdt 0x1000 - sidt 0x1000 - sldt 0x1000 -#ifdef __x86_64__ - lgdtq 0x1000 - lidtq 0x1000 - sgdtq 0x1000 - sidtq 0x1000 - - swapgs - - str %rdx - str %r9 -#endif - - lmsw 0x1000 - lsl 0x1000, %ecx - ltr 0x1000 - ltr %si - smsw 0x1000 - str 0x1000 - str %ecx - str %dx - - verr 0x1000 - verw 0x1000 - -#ifdef __i386__ - push %ds - pushw %ds - pushl %ds - pop %ds - popw %ds - popl %ds -#endif - fxsave 1(%ebx) - fxrstor 1(%ecx) -#ifdef __i386__ - pushl $1 -#else - pushq $1 -#endif - pushw $1 - push $1 - -#ifdef __ASSEMBLER__ // should be defined, for S files - inc %eax -#endif - -#ifndef _WIN32 -ft1: ft2: ft3: ft4: ft5: ft6: ft7: ft8: ft9: - xor %eax, %eax - ret - -.type ft1,STT_FUNC -.type ft2,@STT_FUNC -.type ft3,%STT_FUNC -.type ft4,"STT_FUNC" -.type ft5,function -.type ft6,@function -.type ft7,%function -.type ft8,"function" -#endif - - pause -.rept 6 - nop -.endr -.fill 4,1,0x90 - -.section .text.one,"ax" -nop -.previous -.pushsection .text.one,"ax" -nop -.pushsection .text.two,"ax" -nop -.popsection -.popsection - -1: ud2 -.pushsection __bug_table,"a" -.align 8 -2: .long 1b - 2b - .long 0x600000 - 2b - .long 1b + 42 - .long 43 + 1b - .long 2b + 144 - .long 145 + 2b - .word 164, 0 - .org 2b+32 -#ifdef __x86_64__ - .quad 1b -#else - .long 1b -#endif -.popsection -3: mov %eax,%ecx -4: -.pushsection .text.three, "ax" -nop -.skip (-((4b-3b) > 0) * 2) , 0x90 -.popsection - -.globl overrideme -.weak overrideme - nop -.globl notimplemented -notimplemented: - ret -.set overrideme, notimplemented -overrideme = notimplemented -overrideme: - ret - - movd %esi, %mm1 - movd %edi, %xmm2 - movd (%ebx), %mm3 - movd (%ebx), %xmm3 - movd %mm1, %esi - movd %xmm2, %edi - movd %mm3, (%edx) - movd %xmm3, (%edx) -#ifdef __x86_64__ - movd %rsi, %mm1 - movd %rdi, %xmm2 - movd (%rbx), %mm3 - movd (%rbx), %xmm3 - movd %mm1, %r12 - movd %xmm2, %rdi - movd %mm3, (%r8) - movd %xmm3, (%r13) -#endif - - movq (%ebp), %mm1 - movq %mm2, (%edi) - movq (%edi), %xmm3 - movq %mm4, %mm5 -#ifdef __x86_64__ - movq %rcx, %mm1 - movq %rdx, %xmm2 - movq %r13, %xmm3 - /* movq mem64->xmm is encoded as f30f7e by GAS, but as - 660f6e by tcc (which really is a movd and would need - a REX.W prefix to be movq). */ - movq (%rsi), %xmm3 - movq %mm1, %rdx - movq %xmm3, %rcx - movq %xmm4, (%rsi) -#endif - -#define TEST_MMX_SSE(insn) \ - insn %mm1, %mm2; \ - insn %xmm2, %xmm3; \ - insn (%ebx), %xmm3; -#define TEST_MMX_SSE_I8(insn) \ - TEST_MMX_SSE(insn) \ - insn $0x42, %mm4; \ - insn $0x42, %xmm4; - - TEST_MMX_SSE(packssdw) - TEST_MMX_SSE(packsswb) - TEST_MMX_SSE(packuswb) - TEST_MMX_SSE(paddb) - TEST_MMX_SSE(paddw) - TEST_MMX_SSE(paddd) - TEST_MMX_SSE(paddsb) - TEST_MMX_SSE(paddsw) - TEST_MMX_SSE(paddusb) - TEST_MMX_SSE(paddusw) - TEST_MMX_SSE(pand) - TEST_MMX_SSE(pandn) - TEST_MMX_SSE(pcmpeqb) - TEST_MMX_SSE(pcmpeqw) - TEST_MMX_SSE(pcmpeqd) - TEST_MMX_SSE(pcmpgtb) - TEST_MMX_SSE(pcmpgtw) - TEST_MMX_SSE(pcmpgtd) - TEST_MMX_SSE(pmaddwd) - TEST_MMX_SSE(pmulhw) - TEST_MMX_SSE(pmullw) - TEST_MMX_SSE(por) - TEST_MMX_SSE(psllw) -TEST_MMX_SSE_I8(psllw) - TEST_MMX_SSE(pslld) -TEST_MMX_SSE_I8(pslld) - TEST_MMX_SSE(psllq) -TEST_MMX_SSE_I8(psllq) - TEST_MMX_SSE(psraw) -TEST_MMX_SSE_I8(psraw) - TEST_MMX_SSE(psrad) -TEST_MMX_SSE_I8(psrad) - TEST_MMX_SSE(psrlw) -TEST_MMX_SSE_I8(psrlw) - TEST_MMX_SSE(psrld) -TEST_MMX_SSE_I8(psrld) - TEST_MMX_SSE(psrlq) -TEST_MMX_SSE_I8(psrlq) - TEST_MMX_SSE(psubb) - TEST_MMX_SSE(psubw) - TEST_MMX_SSE(psubd) - TEST_MMX_SSE(psubsb) - TEST_MMX_SSE(psubsw) - TEST_MMX_SSE(psubusb) - TEST_MMX_SSE(psubusw) - TEST_MMX_SSE(punpckhbw) - TEST_MMX_SSE(punpckhwd) - TEST_MMX_SSE(punpckhdq) - TEST_MMX_SSE(punpcklbw) - TEST_MMX_SSE(punpcklwd) - TEST_MMX_SSE(punpckldq) - TEST_MMX_SSE(pxor) - - cvtpi2ps %mm1, %xmm2 - cvtpi2ps (%ebx), %xmm2 - TEST_MMX_SSE(pmaxsw) - TEST_MMX_SSE(pmaxub) - TEST_MMX_SSE(pminsw) - TEST_MMX_SSE(pminub) diff --git a/05/tcc-final-old/tests/boundtest.c b/05/tcc-final-old/tests/boundtest.c deleted file mode 100644 index 15bffb4..0000000 --- a/05/tcc-final-old/tests/boundtest.c +++ /dev/null @@ -1,285 +0,0 @@ -#include -#include -#include - -#define NB_ITS 1000000 -//#define NB_ITS 1 -#define TAB_SIZE 100 - -int tab[TAB_SIZE]; -int ret_sum; -char tab3[256]; - -int test1(void) -{ - int i, sum = 0; - for(i=0;i= 2) - index = atoi(argv[1]) - 1; - - if ((index < 0) || (index >= index_max)) { - printf("N is outside of the valid range (%d)\n", index); - exit(2); - } - - /* well, we also use bounds on this ! */ - ftest = table_test[index]; - ftest(); - - return 0; -} - -/* - * without bound 0.77 s - * with bounds 4.73 - */ diff --git a/05/tcc-final-old/tests/gcctestsuite.sh b/05/tcc-final-old/tests/gcctestsuite.sh deleted file mode 100755 index f3cc538..0000000 --- a/05/tcc-final-old/tests/gcctestsuite.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/sh - -TESTSUITE_PATH=$HOME/gcc/gcc-3.2/gcc/testsuite/gcc.c-torture -TCC="./tcc -B. -I. -DNO_TRAMPOLINES" -rm -f tcc.sum tcc.log -nb_failed="0" - -for src in $TESTSUITE_PATH/compile/*.c ; do - echo $TCC -o /tmp/test.o -c $src - $TCC -o /tmp/test.o -c $src >> tcc.log 2>&1 - if [ "$?" = "0" ] ; then - result="PASS" - else - result="FAIL" - nb_failed=$(( $nb_failed + 1 )) - fi - echo "$result: $src" >> tcc.sum -done - -for src in $TESTSUITE_PATH/execute/*.c ; do - echo $TCC $src - $TCC $src >> tcc.log 2>&1 - if [ "$?" = "0" ] ; then - result="PASS" - else - result="FAIL" - nb_failed=$(( $nb_failed + 1 )) - fi - echo "$result: $src" >> tcc.sum -done - -echo "$nb_failed test(s) failed." >> tcc.sum -echo "$nb_failed test(s) failed." diff --git a/05/tcc-final-old/tests/libtcc_test.c b/05/tcc-final-old/tests/libtcc_test.c deleted file mode 100644 index 480d314..0000000 --- a/05/tcc-final-old/tests/libtcc_test.c +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Simple Test program for libtcc - * - * libtcc can be useful to use tcc as a "backend" for a code generator. - */ -#include -#include -#include - -#include "libtcc.h" - -/* this function is called by the generated code */ -int add(int a, int b) -{ - return a + b; -} - -/* this strinc is referenced by the generated code */ -const char hello[] = "Hello World!"; - -char my_program[] = -"#include \n" /* include the "Simple libc header for TCC" */ -"extern int add(int a, int b);\n" -"#ifdef _WIN32\n" /* dynamically linked data needs 'dllimport' */ -" __attribute__((dllimport))\n" -"#endif\n" -"extern const char hello[];\n" -"int fib(int n)\n" -"{\n" -" if (n <= 2)\n" -" return 1;\n" -" else\n" -" return fib(n-1) + fib(n-2);\n" -"}\n" -"\n" -"int foo(int n)\n" -"{\n" -" printf(\"%s\\n\", hello);\n" -" printf(\"fib(%d) = %d\\n\", n, fib(n));\n" -" printf(\"add(%d, %d) = %d\\n\", n, 2 * n, add(n, 2 * n));\n" -" return 0;\n" -"}\n"; - -int main(int argc, char **argv) -{ - TCCState *s; - int i; - int (*func)(int); - - s = tcc_new(); - if (!s) { - fprintf(stderr, "Could not create tcc state\n"); - exit(1); - } - - /* if tcclib.h and libtcc1.a are not installed, where can we find them */ - for (i = 1; i < argc; ++i) { - char *a = argv[i]; - if (a[0] == '-') { - if (a[1] == 'B') - tcc_set_lib_path(s, a+2); - else if (a[1] == 'I') - tcc_add_include_path(s, a+2); - else if (a[1] == 'L') - tcc_add_library_path(s, a+2); - } - } - - /* MUST BE CALLED before any compilation */ - tcc_set_output_type(s, TCC_OUTPUT_MEMORY); - - if (tcc_compile_string(s, my_program) == -1) - return 1; - - /* as a test, we add symbols that the compiled program can use. - You may also open a dll with tcc_add_dll() and use symbols from that */ - tcc_add_symbol(s, "add", add); - tcc_add_symbol(s, "hello", hello); - - /* relocate the code */ - if (tcc_relocate(s, TCC_RELOCATE_AUTO) < 0) - return 1; - - /* get entry symbol */ - func = tcc_get_symbol(s, "foo"); - if (!func) - return 1; - - /* run the code */ - func(32); - - /* delete the state */ - tcc_delete(s); - - return 0; -} diff --git a/05/tcc-final-old/tests/pp/01.c b/05/tcc-final-old/tests/pp/01.c deleted file mode 100644 index 2fc3d79..0000000 --- a/05/tcc-final-old/tests/pp/01.c +++ /dev/null @@ -1,6 +0,0 @@ -#define hash_hash # ## # -#define mkstr(a) # a -#define in_between(a) mkstr(a) -#define join(c, d) in_between(c hash_hash d) -char p[] = join(x, y); -// char p[] = "x ## y"; diff --git a/05/tcc-final-old/tests/pp/01.expect b/05/tcc-final-old/tests/pp/01.expect deleted file mode 100644 index cf5b153..0000000 --- a/05/tcc-final-old/tests/pp/01.expect +++ /dev/null @@ -1 +0,0 @@ -char p[] = "x ## y"; diff --git a/05/tcc-final-old/tests/pp/02.c b/05/tcc-final-old/tests/pp/02.c deleted file mode 100644 index feb1254..0000000 --- a/05/tcc-final-old/tests/pp/02.c +++ /dev/null @@ -1,28 +0,0 @@ -#define x 3 -#define f(a) f(x * (a)) -#undef x -#define x 2 -#define g f -#define z z[0] -#define h g(~ -#define m(a) a(w) -#define w 0,1 -#define t(a) a -#define p() int -#define q(x) x -#define r(x,y) x ## y -#define str(x) # x -f(y+1) + f(f(z)) % t(t(g)(0) + t)(1); -g(x+(3,4)-w) | h 5) & m -(f)^m(m); -char c[2][6] = { str(hello), str() }; -/* - * f(2 * (y+1)) + f(2 * (f(2 * (z[0])))) % f(2 * (0)) + t(1); - * f(2 * (2+(3,4)-0,1)) | f(2 * (~ 5)) & f(2 * (0,1))^m(0,1); - * char c[2][6] = { "hello", "" }; - */ -#define L21 f(y+1) + f(f(z)) % t(t(g)(0) + t)(1); -#define L22 g(x+(3,4)-w) | h 5) & m\ -(f)^m(m); -L21 -L22 diff --git a/05/tcc-final-old/tests/pp/02.expect b/05/tcc-final-old/tests/pp/02.expect deleted file mode 100644 index 8ae2eb9..0000000 --- a/05/tcc-final-old/tests/pp/02.expect +++ /dev/null @@ -1,5 +0,0 @@ -f(2 * (y+1)) + f(2 * (f(2 * (z[0])))) % f(2 * (0)) + t(1); -f(2 * (2 +(3,4)-0,1)) | f(2 * (~ 5)) & f(2 * (0,1))^m(0,1); -char c[2][6] = { "hello", "" }; -f(2 * (y+1)) + f(2 * (f(2 * (z[0])))) % f(2 * (0)) + t(1); -f(2 * (2 +(3,4)-0,1)) | f(2 * (~ 5)) & f(2 * (0,1))^m(0,1); diff --git a/05/tcc-final-old/tests/pp/03.c b/05/tcc-final-old/tests/pp/03.c deleted file mode 100644 index a659245..0000000 --- a/05/tcc-final-old/tests/pp/03.c +++ /dev/null @@ -1,15 +0,0 @@ -#define str(s) # s -#define xstr(s) str(s) -#define debug(s, t) printf("x" # s "= %d, x" # t "= %s", \ - x ## s, x ## t) -#define INCFILE(n) vers ## n -#define glue(a, b) a ## b -#define xglue(a, b) glue(a, b) -#define HIGHLOW "hello" -#define LOW LOW ", world" -debug(1, 2); -fputs(str(strncmp("abc\0d", "abc", '\4') // this goes away - == 0) str(: @\n), s); -\#include xstr(INCFILE(2).h) -glue(HIGH, LOW); -xglue(HIGH, LOW) diff --git a/05/tcc-final-old/tests/pp/03.expect b/05/tcc-final-old/tests/pp/03.expect deleted file mode 100644 index 44aad0a..0000000 --- a/05/tcc-final-old/tests/pp/03.expect +++ /dev/null @@ -1,5 +0,0 @@ -printf("x" "1" "= %d, x" "2" "= %s", x1, x2); -fputs("strncmp(\"abc\\0d\", \"abc\", '\\4') == 0" ": @\n", s); -\#include "vers2.h" -"hello"; -"hello" ", world" diff --git a/05/tcc-final-old/tests/pp/04.c b/05/tcc-final-old/tests/pp/04.c deleted file mode 100644 index 0068f37..0000000 --- a/05/tcc-final-old/tests/pp/04.c +++ /dev/null @@ -1,4 +0,0 @@ -#define foobar 1 -#define C(x,y) x##y -#define D(x) (C(x,bar)) -D(foo) diff --git a/05/tcc-final-old/tests/pp/04.expect b/05/tcc-final-old/tests/pp/04.expect deleted file mode 100644 index 7c67b01..0000000 --- a/05/tcc-final-old/tests/pp/04.expect +++ /dev/null @@ -1 +0,0 @@ -(1) diff --git a/05/tcc-final-old/tests/pp/05.c b/05/tcc-final-old/tests/pp/05.c deleted file mode 100644 index 7274941..0000000 --- a/05/tcc-final-old/tests/pp/05.c +++ /dev/null @@ -1,7 +0,0 @@ -#define t(x,y,z) x ## y ## z -#define xxx(s) int s[] = { t(1,2,3), t(,4,5), t(6,,7), t(8,9,), \ - t(10,,), t(,11,), t(,,12), t(,,) }; - -int j[] = { t(1,2,3), t(,4,5), t(6,,7), t(8,9,), - t(10,,), t(,11,), t(,,12), t(,,) }; -xxx(j) diff --git a/05/tcc-final-old/tests/pp/05.expect b/05/tcc-final-old/tests/pp/05.expect deleted file mode 100644 index 9f9be37..0000000 --- a/05/tcc-final-old/tests/pp/05.expect +++ /dev/null @@ -1,3 +0,0 @@ -int j[] = { 123, 45, 67, 89, - 10, 11, 12, }; -int j[] = { 123, 45, 67, 89, 10, 11, 12, }; diff --git a/05/tcc-final-old/tests/pp/06.c b/05/tcc-final-old/tests/pp/06.c deleted file mode 100644 index 28cfdde..0000000 --- a/05/tcc-final-old/tests/pp/06.c +++ /dev/null @@ -1,5 +0,0 @@ -#define X(a,b, \ - c,d) \ - foo - -X(1,2,3,4) diff --git a/05/tcc-final-old/tests/pp/06.expect b/05/tcc-final-old/tests/pp/06.expect deleted file mode 100644 index 257cc56..0000000 --- a/05/tcc-final-old/tests/pp/06.expect +++ /dev/null @@ -1 +0,0 @@ -foo diff --git a/05/tcc-final-old/tests/pp/07.c b/05/tcc-final-old/tests/pp/07.c deleted file mode 100644 index b22b22b..0000000 --- a/05/tcc-final-old/tests/pp/07.c +++ /dev/null @@ -1,4 +0,0 @@ -#define a() YES -#define b() a -b() -b()() diff --git a/05/tcc-final-old/tests/pp/07.expect b/05/tcc-final-old/tests/pp/07.expect deleted file mode 100644 index ad0e20a..0000000 --- a/05/tcc-final-old/tests/pp/07.expect +++ /dev/null @@ -1,2 +0,0 @@ -a -YES diff --git a/05/tcc-final-old/tests/pp/08.c b/05/tcc-final-old/tests/pp/08.c deleted file mode 100644 index 93018e1..0000000 --- a/05/tcc-final-old/tests/pp/08.c +++ /dev/null @@ -1,4 +0,0 @@ -// test macro expansion in arguments -#define s_pos s_s.s_pos -#define foo(x) (x) -foo(hej.s_pos) diff --git a/05/tcc-final-old/tests/pp/08.expect b/05/tcc-final-old/tests/pp/08.expect deleted file mode 100644 index 2b2e3ee..0000000 --- a/05/tcc-final-old/tests/pp/08.expect +++ /dev/null @@ -1 +0,0 @@ -(hej.s_s.s_pos) diff --git a/05/tcc-final-old/tests/pp/09.c b/05/tcc-final-old/tests/pp/09.c deleted file mode 100644 index 315b297..0000000 --- a/05/tcc-final-old/tests/pp/09.c +++ /dev/null @@ -1,4 +0,0 @@ -#define C(a,b,c) a##b##c -#define N(x,y) C(x,_,y) -#define A_O aaaaoooo -N(A,O) diff --git a/05/tcc-final-old/tests/pp/09.expect b/05/tcc-final-old/tests/pp/09.expect deleted file mode 100644 index adce0f9..0000000 --- a/05/tcc-final-old/tests/pp/09.expect +++ /dev/null @@ -1 +0,0 @@ -aaaaoooo diff --git a/05/tcc-final-old/tests/pp/10.c b/05/tcc-final-old/tests/pp/10.c deleted file mode 100644 index f180eff..0000000 --- a/05/tcc-final-old/tests/pp/10.c +++ /dev/null @@ -1,10 +0,0 @@ -#define f(x) x -#define g(x) f(x) f(x -#define i(x) g(x)) g(x -#define h(x) i(x))) i(x -#define k(x) i(x))) i(x)))) -f(x) -g(x)) -i(x))) -h(x)))) -k(x)))) diff --git a/05/tcc-final-old/tests/pp/10.expect b/05/tcc-final-old/tests/pp/10.expect deleted file mode 100644 index bd18e18..0000000 --- a/05/tcc-final-old/tests/pp/10.expect +++ /dev/null @@ -1,5 +0,0 @@ -x -x x -x x x x -x x x x x x x x -x x x x x x x x)))) diff --git a/05/tcc-final-old/tests/pp/11.c b/05/tcc-final-old/tests/pp/11.c deleted file mode 100644 index c0edf62..0000000 --- a/05/tcc-final-old/tests/pp/11.c +++ /dev/null @@ -1,31 +0,0 @@ -#define D1(s, ...) s -#define D2(s, ...) s D1(__VA_ARGS__) -#define D3(s, ...) s D2(__VA_ARGS__) -#define D4(s, ...) s D3(__VA_ARGS__) - -D1(a) -D2(a, b) -D3(a, b, c) -D4(a, b, c, d) - -x D4(a, b, c, d) y -x D4(a, b, c) y -x D4(a, b) y -x D4(a) y -x D4() y - -#define GNU_COMMA(X,Y...) X,## Y - -x GNU_COMMA(A,B,C) y -x GNU_COMMA(A,B) y -x GNU_COMMA(A) y -x GNU_COMMA() y - -#define __sun_attr___noreturn__ __attribute__((__noreturn__)) -#define ___sun_attr_inner(__a) __sun_attr_##__a -#define __sun_attr__(__a) ___sun_attr_inner __a -#define __NORETURN __sun_attr__((__noreturn__)) -__NORETURN -#define X(...) -#define Y(...) 1 __VA_ARGS__ 2 -Y(X X() ()) diff --git a/05/tcc-final-old/tests/pp/11.expect b/05/tcc-final-old/tests/pp/11.expect deleted file mode 100644 index 6b9806c..0000000 --- a/05/tcc-final-old/tests/pp/11.expect +++ /dev/null @@ -1,15 +0,0 @@ -a -a b -a b c -a b c d -x a b c d y -x a b c y -x a b y -x a y -x y -x A,B,C y -x A,B y -x A y -x y -__attribute__((__noreturn__)) -1 2 diff --git a/05/tcc-final-old/tests/pp/12.S b/05/tcc-final-old/tests/pp/12.S deleted file mode 100644 index 597ccb4..0000000 --- a/05/tcc-final-old/tests/pp/12.S +++ /dev/null @@ -1,8 +0,0 @@ -#define SRC(y...) \ - 9999: y; \ - .section __ex_table, "a"; \ - .long 9999b, 6001f ; \ - // .previous - - SRC(1: movw (%esi), %bx) -6001: diff --git a/05/tcc-final-old/tests/pp/12.expect b/05/tcc-final-old/tests/pp/12.expect deleted file mode 100644 index 17a861c..0000000 --- a/05/tcc-final-old/tests/pp/12.expect +++ /dev/null @@ -1,2 +0,0 @@ - 9999: 1: movw (%esi), %bx; .section __ex_table, "a"; .long 9999b, 6001f ; -6001: diff --git a/05/tcc-final-old/tests/pp/13.S b/05/tcc-final-old/tests/pp/13.S deleted file mode 100644 index bf0b525..0000000 --- a/05/tcc-final-old/tests/pp/13.S +++ /dev/null @@ -1,6 +0,0 @@ -# `modelist' label. Each video mode record looks like: -#ifdef AAA -# modelist' label. Each video mode record looks like: -#endif -.text -endtext: diff --git a/05/tcc-final-old/tests/pp/13.expect b/05/tcc-final-old/tests/pp/13.expect deleted file mode 100644 index c7a3230..0000000 --- a/05/tcc-final-old/tests/pp/13.expect +++ /dev/null @@ -1,2 +0,0 @@ -.text -endtext: diff --git a/05/tcc-final-old/tests/pp/14.c b/05/tcc-final-old/tests/pp/14.c deleted file mode 100644 index e15468c..0000000 --- a/05/tcc-final-old/tests/pp/14.c +++ /dev/null @@ -1,13 +0,0 @@ -#define W Z -#define Z(X) W(X,2) -#define Y(X) Z(X) -#define X Y -return X(X(1)); - -#define P Q -#define Q(n) P(n,2) -return P(1); - -#define A (B * B) -#define B (A + A) -return A + B; diff --git a/05/tcc-final-old/tests/pp/14.expect b/05/tcc-final-old/tests/pp/14.expect deleted file mode 100644 index 3786044..0000000 --- a/05/tcc-final-old/tests/pp/14.expect +++ /dev/null @@ -1,3 +0,0 @@ -return Z(Z(1,2),2); -return Q(1,2); -return ((A + A) * (A + A)) + ((B * B) + (B * B)); diff --git a/05/tcc-final-old/tests/pp/15.c b/05/tcc-final-old/tests/pp/15.c deleted file mode 100644 index cf13f9a..0000000 --- a/05/tcc-final-old/tests/pp/15.c +++ /dev/null @@ -1,18 +0,0 @@ -// insert a space between two tokens if otherwise they -// would form a single token when read back - -#define n(x) x - -return (n(long)n(double))d; -return n(A)n(++)n(+)n(B); -return n(A)n(+)n(++)n(B); -return n(A)n(++)n(+)n(+)n(B); - -// not a hex float -return n(0x1E)n(-1); - -// unlike gcc but correct -// XXX: return n(x)+n(x)-n(1)+n(1)-2; - -// unlike gcc, but cannot appear in valid C -// XXX: return n(x)n(x)n(1)n(2)n(x); diff --git a/05/tcc-final-old/tests/pp/15.expect b/05/tcc-final-old/tests/pp/15.expect deleted file mode 100644 index b4f885e..0000000 --- a/05/tcc-final-old/tests/pp/15.expect +++ /dev/null @@ -1,5 +0,0 @@ -return (long double)d; -return A+++B; -return A+ ++B; -return A+++ +B; -return 0x1E -1; diff --git a/05/tcc-final-old/tests/pp/16.c b/05/tcc-final-old/tests/pp/16.c deleted file mode 100644 index 8b5b642..0000000 --- a/05/tcc-final-old/tests/pp/16.c +++ /dev/null @@ -1,3 +0,0 @@ -/* The following should warn */ -#define A ... -#define A <<= diff --git a/05/tcc-final-old/tests/pp/16.expect b/05/tcc-final-old/tests/pp/16.expect deleted file mode 100644 index 695d6d4..0000000 --- a/05/tcc-final-old/tests/pp/16.expect +++ /dev/null @@ -1,2 +0,0 @@ - -16.c:3: warning: A redefined diff --git a/05/tcc-final-old/tests/pp/17.c b/05/tcc-final-old/tests/pp/17.c deleted file mode 100644 index f12196f..0000000 --- a/05/tcc-final-old/tests/pp/17.c +++ /dev/null @@ -1,14 +0,0 @@ -#define STR1(u) # u -#define pass(a) a -#define __ASM_REG(reg) STR1(one##reg) -#define _ASM_DX __ASM_REG(tok) -X162 pass(__ASM_REG(tok)) -X161 pass(_ASM_DX) -X163 pass(STR1(one##tok)) - -X170 pass(x ## y) -X171 pass(x pass(##) y) - -#define Y(x) Z(x) -#define X Y -X180 return X(X(1)); diff --git a/05/tcc-final-old/tests/pp/17.expect b/05/tcc-final-old/tests/pp/17.expect deleted file mode 100644 index e95aafe..0000000 --- a/05/tcc-final-old/tests/pp/17.expect +++ /dev/null @@ -1,6 +0,0 @@ -X162 "onetok" -X161 "onetok" -X163 "one##tok" -X170 x ## y -X171 x ## y -X180 return Z(Z(1)); diff --git a/05/tcc-final-old/tests/pp/18.c b/05/tcc-final-old/tests/pp/18.c deleted file mode 100644 index 0961426..0000000 --- a/05/tcc-final-old/tests/pp/18.c +++ /dev/null @@ -1,15 +0,0 @@ -#define M_RETI_ARG27(x,y,z,aa, ...) aa -#define M_RET_ARG27(...) M_RETI_ARG27(__VA_ARGS__) -#define M_COMMA_P(...) M_RET_ARG27(__VA_ARGS__, 1, 1, 0, useless) -#define M_EMPTYI_DETECT(...) 0, 1, -#define M_EMPTYI_P_C1(...) M_COMMA_P(M_EMPTYI_DETECT __VA_ARGS__ () ) -#define EX -#define empty(x) -#define fnlike(x) yeah x -/* If the following macro is called with empty arg (X183), the use - of 'x' between fnlike and '(' doesn't hinder the recognition of this - being a further fnlike macro invocation. */ -#define usefnlike(x) fnlike x (x) -X181 M_EMPTYI_P_C1() -X182 M_EMPTYI_P_C1(x) -X183 usefnlike() diff --git a/05/tcc-final-old/tests/pp/18.expect b/05/tcc-final-old/tests/pp/18.expect deleted file mode 100644 index 447a9b2..0000000 --- a/05/tcc-final-old/tests/pp/18.expect +++ /dev/null @@ -1,3 +0,0 @@ -X181 1 -X182 0 -X183 yeah diff --git a/05/tcc-final-old/tests/pp/19.c b/05/tcc-final-old/tests/pp/19.c deleted file mode 100644 index aa91abe..0000000 --- a/05/tcc-final-old/tests/pp/19.c +++ /dev/null @@ -1,101 +0,0 @@ -#define M_C2I(a, ...) a ## __VA_ARGS__ -#define M_C(a, ...) M_C2I(a, __VA_ARGS__) -#define M_C3I(a, b, ...) a ## b ## __VA_ARGS__ -#define M_C3(a, b, ...) M_C3I(a ,b, __VA_ARGS__) - -#define M_RETI_ARG2(a, b, ...) b -#define M_RET_ARG2(...) M_RETI_ARG2(__VA_ARGS__) -#define M_RETI_ARG27(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa, ...) aa -#define M_RET_ARG27(...) M_RETI_ARG27(__VA_ARGS__) - -#define M_TOBOOLI_0 1, 0, -#define M_BOOL(x) M_RET_ARG2(M_C(M_TOBOOLI_, x), 1, useless) - -#define M_IFI_0(true_macro, ...) __VA_ARGS__ -#define M_IFI_1(true_macro, ...) true_macro -#define M_IF(c) M_C(M_IFI_, M_BOOL(c)) - -#define M_FLAT(...) __VA_ARGS__ -#define M_INVI_0 1 -#define M_INVI_1 0 -#define M_INV(x) M_C(M_INVI_, x) - -#define M_ANDI_00 0 -#define M_ANDI_01 0 -#define M_ANDI_10 0 -#define M_ANDI_11 1 -#define M_AND(x,y) M_C3(M_ANDI_, x, y) - -#define M_ORI_00 0 -#define M_ORI_01 1 -#define M_ORI_10 1 -#define M_ORI_11 1 -#define M_OR(x,y) M_C3(M_ORI_, x, y) - -#define M_COMMA_P(...) M_RET_ARG27(__VA_ARGS__, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, useless) - -#define M_EMPTYI_DETECT(...) 0, 1, -#define M_EMPTYI_P_C1(...) M_COMMA_P(M_EMPTYI_DETECT __VA_ARGS__ ()) -#define M_EMPTYI_P_C2(...) M_COMMA_P(M_EMPTYI_DETECT __VA_ARGS__) -#define M_EMPTYI_P_C3(...) M_COMMA_P(__VA_ARGS__ () ) -#define M_EMPTY_P(...) M_AND(M_EMPTYI_P_C1(__VA_ARGS__), M_INV(M_OR(M_OR(M_EMPTYI_P_C2(__VA_ARGS__), M_COMMA_P(__VA_ARGS__)),M_EMPTYI_P_C3(__VA_ARGS__)))) -#define M_APPLY_FUNC2B(func, arg1, arg2) \ - M_IF(M_EMPTY_P(arg2))(,func(arg1, arg2)) -#define M_MAP2B_0(func, data, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z,...) \ - M_APPLY_FUNC2B(func, data, a) M_APPLY_FUNC2B(func, data, b) M_APPLY_FUNC2B(func, data, c) \ - M_APPLY_FUNC2B(func, data, d) M_APPLY_FUNC2B(func, data, e) M_APPLY_FUNC2B(func, data, f) \ - M_APPLY_FUNC2B(func, data, g) M_APPLY_FUNC2B(func, data, h) M_APPLY_FUNC2B(func, data, i) \ - M_APPLY_FUNC2B(func, data, j) M_APPLY_FUNC2B(func, data, k) M_APPLY_FUNC2B(func, data, l) \ - M_APPLY_FUNC2B(func, data, m) M_APPLY_FUNC2B(func, data, n) M_APPLY_FUNC2B(func, data, o) \ - M_APPLY_FUNC2B(func, data, p) M_APPLY_FUNC2B(func, data, q) M_APPLY_FUNC2B(func, data, r) \ - M_APPLY_FUNC2B(func, data, s) M_APPLY_FUNC2B(func, data, t) M_APPLY_FUNC2B(func, data, u) \ - M_APPLY_FUNC2B(func, data, v) M_APPLY_FUNC2B(func, data, w) M_APPLY_FUNC2B(func, data, x) \ - M_APPLY_FUNC2B(func, data, y) M_APPLY_FUNC2B(func, data, z) -#define M_MAP2B(f, ...) M_MAP2B_0(f, __VA_ARGS__, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ) -#define M_INIT_INIT(a) ,a, - -#define M_GET_METHOD(method, method_default, ...) \ - M_RET_ARG2 (M_MAP2B(M_C, M_C3(M_, method, _), __VA_ARGS__), method_default,) - -#define M_TEST_METHOD_P(method, oplist) \ - M_BOOL(M_GET_METHOD (method, 0, M_FLAT oplist)) - -#define TRUE 1 -#define TEST1(n) \ - M_IF(n)(ok,nok) -#define TEST2(op) \ - M_TEST_METHOD_P(INIT, op) -#define TEST3(op) \ - M_IF(M_TEST_METHOD_P(INIT, op))(ok, nok) -#define TEST4(op) \ - TEST1(TEST2(op)) -#define KO(a) ((void)1) - -/* This checks that the various expansions that ultimately lead to - something like 'KO(arg,arg)', where 'KO' comes from a macro - expansion reducing from a large macro chain do not are regarded - as funclike macro invocation of KO. E.g. X93 and X94 expand to 'KO', - but X95 must not consume the (a,b) arguments outside the M_IF() - invocation to reduce the 'KO' macro to an invocation. Instead - X95 should reduce via M_IF(KO)(a,b) to 'a'. - - The other lines here are variations on this scheme, with X1 to - X6 coming from the bug report at - http://lists.nongnu.org/archive/html/tinycc-devel/2017-07/msg00017.html */ -X92 M_IF(KO) -X93 M_GET_METHOD(INIT, 0, INIT(KO)) -X94 M_GET_METHOD(INIT, 0, M_FLAT (INIT(KO))) -X95 M_IF(M_GET_METHOD(INIT, 0, INIT(KO)))(a,b) -X96 M_IF(M_GET_METHOD(INIT, 0, M_FLAT (INIT(KO)))) -X97 M_IF(M_GET_METHOD(INIT, 0, M_FLAT (INIT(KO))))(ok,nok) -X98 (M_TEST_METHOD_P(INIT, (INIT(KO))))(ok, nok) -X99 M_IF(M_TEST_METHOD_P(INIT, (INIT(KO))))(ok, nok) -// test begins -X1 TEST1(TRUE) // ==> expect ok, get ok -// First test with a token which is not a macro -X2 TEST2((INIT(ok))) // ==> expect 1, get 1 -X3 TEST3((INIT(ok))) // ==> expect ok, get ok -// Then test with a token which is a macro, but should not be expanded. -X4 TEST2((INIT(KO))) // ==> expect 1, get 1 -X5 TEST4(INIT(KO)) -X6 TEST3((INIT(KO))) // ==> expect ok, get "error: macro 'KO' used with too many args" diff --git a/05/tcc-final-old/tests/pp/19.expect b/05/tcc-final-old/tests/pp/19.expect deleted file mode 100644 index 08c0858..0000000 --- a/05/tcc-final-old/tests/pp/19.expect +++ /dev/null @@ -1,14 +0,0 @@ -X92 M_IFI_1 -X93 KO -X94 KO -X95 a -X96 M_IFI_1 -X97 ok -X98 (1)(ok, nok) -X99 ok -X1 ok -X2 1 -X3 ok -X4 1 -X5 nok -X6 ok diff --git a/05/tcc-final-old/tests/pp/20.c b/05/tcc-final-old/tests/pp/20.c deleted file mode 100644 index 7944d62..0000000 --- a/05/tcc-final-old/tests/pp/20.c +++ /dev/null @@ -1,13 +0,0 @@ -/* Various things I encountered while hacking the pre processor */ -#define wrap(x) x -#define pr_warning(fmt, ...) printk(KERN_WARNING fmt, ##__VA_ARGS__) -#define pr_warn(x,y) pr_warning(x,y) -#define net_ratelimited_function(function, ...) function(__VA_ARGS__) -X1 net_ratelimited_function(pr_warn, "pipapo", bla); -X2 net_ratelimited_function(wrap(pr_warn), "bla", foo); -#define two m n -#define chain4(a,b,c,d) a ## b ## c ## d -X2 chain4(two,o,p,q) -X3 chain4(o,two,p,q) -X4 chain4(o,p,two,q) -X5 chain4(o,p,q,two) diff --git a/05/tcc-final-old/tests/pp/20.expect b/05/tcc-final-old/tests/pp/20.expect deleted file mode 100644 index d19405d..0000000 --- a/05/tcc-final-old/tests/pp/20.expect +++ /dev/null @@ -1,6 +0,0 @@ -X1 printk(KERN_WARNING "pipapo",bla); -X2 printk(KERN_WARNING "bla",foo); -X2 twoopq -X3 otwopq -X4 optwoq -X5 opqtwo diff --git a/05/tcc-final-old/tests/pp/21.c b/05/tcc-final-old/tests/pp/21.c deleted file mode 100644 index 1316226..0000000 --- a/05/tcc-final-old/tests/pp/21.c +++ /dev/null @@ -1,36 +0,0 @@ -/* accept 'defined' as result of substitution */ - ------ 1 ------ -#define AAA 2 -#define BBB -#define CCC (defined ( AAA ) && AAA > 1 && !defined BBB) -#if !CCC -OK -#else -NOT OK -#endif - ------ 2 ------ -#undef BBB -#if CCC -OK -#else -NOT OK -#endif - ------ 3 ------ -#define DEFINED defined -#define DDD (DEFINED ( AAA ) && AAA > 1 && !DEFINED BBB) -#if (DDD) -OK -#else -NOT OK -#endif - ------ 4 ------ -#undef AAA -#if !(DDD) -OK -#else -NOT OK -#endif diff --git a/05/tcc-final-old/tests/pp/21.expect b/05/tcc-final-old/tests/pp/21.expect deleted file mode 100644 index 5a1376b..0000000 --- a/05/tcc-final-old/tests/pp/21.expect +++ /dev/null @@ -1,8 +0,0 @@ ------ 1 ------ -OK ------ 2 ------ -OK ------ 3 ------ -OK ------ 4 ------ -OK diff --git a/05/tcc-final-old/tests/pp/Makefile b/05/tcc-final-old/tests/pp/Makefile deleted file mode 100644 index 687aa52..0000000 --- a/05/tcc-final-old/tests/pp/Makefile +++ /dev/null @@ -1,49 +0,0 @@ -# -# credits: 01..13.c from the pcc cpp-tests suite -# - -TOP = ../.. -include $(TOP)/Makefile -SRC = $(TOPSRC)/tests/pp -VPATH = $(SRC) - -files = $(patsubst %.$1,%.test,$(notdir $(wildcard $(SRC)/*.$1))) -TESTS = $(call files,c) $(call files,S) - -all test : $(sort $(TESTS)) - -DIFF_OPTS = -Nu -b -B - -# Filter source directory in warnings/errors (out-of-tree builds) -FILTER = 2>&1 | sed 's,$(SRC)/,,g' - -%.test: %.c %.expect - @echo PPTest $* ... - -@$(TCC) -E -P $< $(FILTER) >$*.output 2>&1 ; \ - diff $(DIFF_OPTS) $(SRC)/$*.expect $*.output \ - && rm -f $*.output - -%.test: %.S %.expect - @echo PPTest $* ... - -@$(TCC) -E -P $< $(FILTER) >$*.output 2>&1 ; \ - diff $(DIFF_OPTS) $(SRC)/$*.expect $*.output \ - && rm -f $*.output - -# automatically generate .expect files with gcc: -%.expect: # %.c - gcc -E -P $*.[cS] >$*.expect 2>&1 - -# tell make not to delete -.PRECIOUS: %.expect - -clean: - rm -f *.output - -02.test : DIFF_OPTS += -w -# 15.test : DIFF_OPTS += -I"^XXX:" - -# diff options: -# -b ighore space changes -# -w ighore all whitespace -# -B ignore blank lines -# -I ignore lines matching RE diff --git a/05/tcc-final-old/tests/pp/pp-counter.c b/05/tcc-final-old/tests/pp/pp-counter.c deleted file mode 100644 index 3978e1a..0000000 --- a/05/tcc-final-old/tests/pp/pp-counter.c +++ /dev/null @@ -1,27 +0,0 @@ -X1 __COUNTER__ -X2 __COUNTER__ -#if __COUNTER__ -X3 __COUNTER__ -#endif -#define pass(x) x -#define a x __COUNTER__ y -#define a2 pass(__COUNTER__) -#define f(c) c __COUNTER__ -#define apply(d) d d __COUNTER__ x2 f(d) y2 __COUNTER__ -#define _paste(a,b) a ## b -#define paste(a,b) _paste(a,b) -#define _paste3(a,b,c) a ## b ## c -#define doublepaste(a,b) _paste3(a,b,b) -#define str(x) #x -X4 a -X5 f(a) -X6 f(b) -X7 f(__COUNTER__) -X8 apply(a) -X9 apply(f(a)) -X10 apply(__COUNTER__) -X11 apply(a2) -X12 str(__COUNTER__) -X13 paste(x,__COUNTER__) -X14 _paste(x,__COUNTER__) -X15 doublepaste(x,__COUNTER__) diff --git a/05/tcc-final-old/tests/pp/pp-counter.expect b/05/tcc-final-old/tests/pp/pp-counter.expect deleted file mode 100644 index 02fc535..0000000 --- a/05/tcc-final-old/tests/pp/pp-counter.expect +++ /dev/null @@ -1,15 +0,0 @@ -X1 0 -X2 1 -X3 3 -X4 x 4 y -X5 x 5 y 6 -X6 b 7 -X7 8 9 -X8 x 10 y x 10 y 11 x2 x 10 y 12 y2 13 -X9 x 14 y 15 x 14 y 15 16 x2 x 14 y 15 17 y2 18 -X10 19 19 20 x2 19 21 y2 22 -X11 23 23 24 x2 23 25 y2 26 -X12 "__COUNTER__" -X13 x27 -X14 x__COUNTER__ -X15 x2828 diff --git a/05/tcc-final-old/tests/tcctest.c b/05/tcc-final-old/tests/tcctest.c deleted file mode 100644 index 57670be..0000000 --- a/05/tcc-final-old/tests/tcctest.c +++ /dev/null @@ -1,3871 +0,0 @@ -/* - * TCC auto test program - */ -#include "config.h" - -#if GCC_MAJOR >= 3 - -/* Unfortunately, gcc version < 3 does not handle that! */ -#define ALL_ISOC99 - -/* only gcc 3 handles _Bool correctly */ -#define BOOL_ISOC99 - -/* gcc 2.95.3 does not handle correctly CR in strings or after strays */ -#define CORRECT_CR_HANDLING - -#endif - -#if defined(_WIN32) -#define LONG_LONG_FORMAT "%lld" -#define ULONG_LONG_FORMAT "%llu" -#else -#define LONG_LONG_FORMAT "%Ld" -#define ULONG_LONG_FORMAT "%Lu" -#endif - -// MinGW has 80-bit rather than 64-bit long double which isn't compatible with TCC or MSVC -#if defined(_WIN32) && defined(__GNUC__) -#define LONG_DOUBLE double -#define LONG_DOUBLE_LITERAL(x) x -#else -#define LONG_DOUBLE long double -#define LONG_DOUBLE_LITERAL(x) x ## L -#endif - -/* deprecated and no longer supported in gcc 3.3 */ -//#define ACCEPT_CR_IN_STRINGS - -/* __VA_ARGS__ and __func__ support */ -#define C99_MACROS - -/* test various include syntaxes */ - -#define TCCLIB_INC -#define TCCLIB_INC1 -#define TCCLIB_INC3 "tcclib.h" - -#include TCCLIB_INC - -#include TCCLIB_INC1.TCCLIB_INC2 - -#include TCCLIB_INC1.h> - -#include TCCLIB_INC3 - -#include - -#include "tcclib.h" - -#include "tcctest.h" - -/* Test two more ways to include a file named like a pp-number */ -#define INC(name) -#define funnyname 42test.h -#define incdir tests/ -#define incname < incdir funnyname > -#define __stringify(x) #x -#define stringify(x) __stringify(x) -#include INC(42test) -#include incname -#include stringify(funnyname) - -void intdiv_test(); -void string_test(); -void expr_test(); -void macro_test(); -void recursive_macro_test(); -void scope_test(); -void forward_test(); -void funcptr_test(); -void loop_test(); -void switch_test(); -void goto_test(); -void enum_test(); -void typedef_test(); -void struct_test(); -void array_test(); -void expr_ptr_test(); -void bool_test(); -void optimize_out(); -void expr2_test(); -void constant_expr_test(); -void expr_cmp_test(); -void char_short_test(); -void init_test(void); -void compound_literal_test(void); -int kr_test(); -void struct_assign_test(void); -void cast_test(void); -void bitfield_test(void); -void c99_bool_test(void); -void float_test(void); -void longlong_test(void); -void manyarg_test(void); -void stdarg_test(void); -void whitespace_test(void); -void relocation_test(void); -void old_style_function(void); -void alloca_test(void); -void c99_vla_test(int size1, int size2); -void sizeof_test(void); -void typeof_test(void); -void local_label_test(void); -void statement_expr_test(void); -void asm_test(void); -void builtin_test(void); -void weak_test(void); -void global_data_test(void); -void cmp_comparison_test(void); -void math_cmp_test(void); -void callsave_test(void); -void builtin_frame_address_test(void); -void attrib_test(void); - -int fib(int n); -void num(int n); -void forward_ref(void); -int isid(int c); - -/* Line joining happens before tokenization, so the following - must be parsed as ellipsis. */ -void funny_line_continuation (int, ..\ -. ); - -char via_volatile (char); - -#define A 2 -#define N 1234 + A -#define pf printf -#define M1(a, b) (a) + (b) - -#define str\ -(s) # s -#define glue(a, b) a ## b -#define xglue(a, b) glue(a, b) -#define HIGHLOW "hello" -#define LOW LOW ", world" - -static int onetwothree = 123; -#define onetwothree4 onetwothree -#define onetwothree xglue(onetwothree,4) - -#define min(a, b) ((a) < (b) ? (a) : (b)) - -#ifdef C99_MACROS -#define dprintf(level,...) printf(__VA_ARGS__) -#endif - -/* gcc vararg macros */ -#define dprintf1(level, fmt, args...) printf(fmt, ## args) - -#define MACRO_NOARGS() - -#define AAA 3 -#undef AAA -#define AAA 4 - -#if 1 -#define B3 1 -#elif 1 -#define B3 2 -#elif 0 -#define B3 3 -#else -#define B3 4 -#endif - -#ifdef __TINYC__ -/* We try to handle this syntax. Make at least sure it doesn't segfault. */ -char invalid_function_def()[] {} -#endif - -#define __INT64_C(c) c ## LL -#define INT64_MIN (-__INT64_C(9223372036854775807)-1) - -int qq(int x) -{ - return x + 40; -} -#define qq(x) x - -#define spin_lock(lock) do { } while (0) -#define wq_spin_lock spin_lock -#define TEST2() wq_spin_lock(a) - -#define UINT_MAX ((unsigned) -1) - -void intdiv_test(void) -{ - printf("18/21=%u\n", 18/21); - printf("18%%21=%u\n", 18%21); - printf("41/21=%u\n", 41/21); - printf("41%%21=%u\n", 41%21); - printf("42/21=%u\n", 42/21); - printf("42%%21=%u\n", 42%21); - printf("43/21=%u\n", 43/21); - printf("43%%21=%u\n", 43%21); - printf("126/21=%u\n", 126/21); - printf("126%%21=%u\n", 126%21); - printf("131/21=%u\n", 131/21); - printf("131%%21=%u\n", 131%21); - printf("(UINT_MAX/2+3)/2=%u\n", (UINT_MAX/2+3)/2); - printf("(UINT_MAX/2+3)%%2=%u\n", (UINT_MAX/2+3)%2); - - printf("18/-21=%u\n", 18/-21); - printf("18%%-21=%u\n", 18%-21); - printf("41/-21=%u\n", 41/-21); - printf("41%%-21=%u\n", 41%-21); - printf("42/-21=%u\n", 42/-21); - printf("42%%-21=%u\n", 42%-21); - printf("43/-21=%u\n", 43/-21); - printf("43%%-21=%u\n", 43%-21); - printf("126/-21=%u\n", 126/-21); - printf("126%%-21=%u\n", 126%-21); - printf("131/-21=%u\n", 131/-21); - printf("131%%-21=%u\n", 131%-21); - printf("(UINT_MAX/2+3)/-2=%u\n", (UINT_MAX/2+3)/-2); - printf("(UINT_MAX/2+3)%%-2=%u\n", (UINT_MAX/2+3)%-2); - - printf("-18/21=%u\n", -18/21); - printf("-18%%21=%u\n", -18%21); - printf("-41/21=%u\n", -41/21); - printf("-41%%21=%u\n", -41%21); - printf("-42/21=%u\n", -42/21); - printf("-42%%21=%u\n", -42%21); - printf("-43/21=%u\n", -43/21); - printf("-43%%21=%u\n", -43%21); - printf("-126/21=%u\n", -126/21); - printf("-126%%21=%u\n", -126%21); - printf("-131/21=%u\n", -131/21); - printf("-131%%21=%u\n", -131%21); - printf("-(UINT_MAX/2+3)/2=%u\n", (0-(UINT_MAX/2+3))/2); - printf("-(UINT_MAX/2+3)%%2=%u\n", (0-(UINT_MAX/2+3))%2); - - printf("-18/-21=%u\n", -18/-21); - printf("-18%%-21=%u\n", -18%-21); - printf("-41/-21=%u\n", -41/-21); - printf("-41%%-21=%u\n", -41%-21); - printf("-42/-21=%u\n", -42/-21); - printf("-42%%-21=%u\n", -42%-21); - printf("-43/-21=%u\n", -43/-21); - printf("-43%%-21=%u\n", -43%-21); - printf("-126/-21=%u\n", -126/-21); - printf("-126%%-21=%u\n", -126%-21); - printf("-131/-21=%u\n", -131/-21); - printf("-131%%-21=%u\n", -131%-21); - printf("-(UINT_MAX/2+3)/-2=%u\n", (0-(UINT_MAX/2+3))/-2); - printf("-(UINT_MAX/2+3)%%-2=%u\n", (0-(UINT_MAX/2+3))%-2); -} - -void macro_test(void) -{ - printf("macro:\n"); - pf("N=%d\n", N); - printf("aaa=%d\n", AAA); - - printf("min=%d\n", min(1, min(2, -1))); - - printf("s1=%s\n", glue(HIGH, LOW)); - printf("s2=%s\n", xglue(HIGH, LOW)); - printf("s3=%s\n", str("c")); - printf("s4=%s\n", str(a1)); - printf("B3=%d\n", B3); - - printf("onetwothree=%d\n", onetwothree); - -#ifdef A - printf("A defined\n"); -#endif -#ifdef B - printf("B defined\n"); -#endif -#ifdef A - printf("A defined\n"); -#else - printf("A not defined\n"); -#endif -#ifdef B - printf("B defined\n"); -#else - printf("B not defined\n"); -#endif - -#ifdef A - printf("A defined\n"); -#ifdef B - printf("B1 defined\n"); -#else - printf("B1 not defined\n"); -#endif -#else - printf("A not defined\n"); -#ifdef B - printf("B2 defined\n"); -#else - printf("B2 not defined\n"); -#endif -#endif - -#if 1+1 - printf("test true1\n"); -#endif -#if 0 - printf("test true2\n"); -#endif -#if 1-1 - printf("test true3\n"); -#endif -#if defined(A) - printf("test trueA\n"); -#endif -#if defined(B) - printf("test trueB\n"); -#endif - -#if 0 - printf("test 0\n"); -#elif 0 - printf("test 1\n"); -#elif 2 - printf("test 2\n"); -#else - printf("test 3\n"); -#endif - - MACRO_NOARGS(); - -#ifdef __LINE__ - printf("__LINE__ defined\n"); -#endif - - printf("__LINE__=%d __FILE__=%s\n", - __LINE__, __FILE__); -#if 0 -#line 200 - printf("__LINE__=%d __FILE__=%s\n", - __LINE__, __FILE__); -#line 203 "test" - printf("__LINE__=%d __FILE__=%s\n", - __LINE__, __FILE__); -#line 227 "tcctest.c" -#endif - - /* not strictly preprocessor, but we test it there */ -#ifdef C99_MACROS - printf("__func__ = %s\n", __func__); - dprintf(1, "vaarg=%d\n", 1); -#endif - dprintf1(1, "vaarg1\n"); - dprintf1(1, "vaarg1=%d\n", 2); - dprintf1(1, "vaarg1=%d %d\n", 1, 2); - - /* gcc extension */ - printf("func='%s'\n", __FUNCTION__); - - /* complicated macros in glibc */ - printf("INT64_MIN=" LONG_LONG_FORMAT "\n", INT64_MIN); - { - int a; - a = 1; - glue(a+, +); - printf("a=%d\n", a); - glue(a <, <= 2); - printf("a=%d\n", a); - } - - /* macro function with argument outside the macro string */ -#define MF_s MF_hello -#define MF_hello(msg) printf("%s\n",msg) - -#define MF_t printf("tralala\n"); MF_hello - - MF_s("hi"); - MF_t("hi"); - - /* test macro substitution inside args (should not eat stream) */ - printf("qq=%d\n", qq(qq)(2)); - - /* test zero argument case. NOTE: gcc 2.95.x does not accept a - null argument without a space. gcc 3.2 fixes that. */ - -#define qq1(x) 1 - printf("qq1=%d\n", qq1( )); - - /* comment with stray handling *\ -/ - /* this is a valid *\/ comment */ - /* this is a valid comment *\*/ - // this is a valid\ -comment - - /* test function macro substitution when the function name is - substituted */ - TEST2(); - - /* And again when the name and parentheses are separated by a - comment. */ - TEST2 /* the comment */ (); - - printf("%s\n", get_basefile_from_header()); - printf("%s\n", __BASE_FILE__); - printf("%s\n", get_file_from_header()); - printf("%s\n", __FILE__); - - /* Check that funnily named include was in fact included */ - have_included_42test_h = 1; - have_included_42test_h_second = 1; - have_included_42test_h_third = 1; -} - - -static void print_num(char *fn, int line, int num) { - printf("fn %s, line %d, num %d\n", fn, line, num); -} - -void recursive_macro_test(void) -{ - -#define ELF32_ST_TYPE(val) ((val) & 0xf) -#define ELF32_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf)) -#define STB_WEAK 2 /* Weak symbol */ -#define ELFW(type) ELF##32##_##type - printf("%d\n", ELFW(ST_INFO)(STB_WEAK, ELFW(ST_TYPE)(123))); - -#define WRAP(x) x - -#define print_num(x) print_num(__FILE__,__LINE__,x) - print_num(123); - WRAP(print_num(123)); - WRAP(WRAP(print_num(123))); - -static struct recursive_macro { int rm_field; } G; -#define rm_field (G.rm_field) - printf("rm_field = %d\n", rm_field); - printf("rm_field = %d\n", WRAP(rm_field)); - WRAP((printf("rm_field = %d %d\n", rm_field, WRAP(rm_field)))); -} - -int op(a,b) -{ - return a / b; -} - -int ret(a) -{ - if (a == 2) - return 1; - if (a == 3) - return 2; - return 0; -} - -void ps(const char *s) -{ - int c; - while (1) { - c = *s; - if (c == 0) - break; - printf("%c", c); - s++; - } -} - -const char foo1_string[] = "\ -bar\n\ -test\14\ -1"; - -void string_test() -{ - unsigned int b; - printf("string:\n"); - printf("\141\1423\143\n");/* dezdez test */ - printf("\x41\x42\x43\x3a\n"); - printf("c=%c\n", 'r'); - printf("wc=%C 0x%lx %C\n", L'a', L'\x1234', L'c'); - printf("foo1_string='%s'\n", foo1_string); -#if 0 - printf("wstring=%S\n", L"abc"); - printf("wstring=%S\n", L"abc" L"def" "ghi"); - printf("'\\377'=%d '\\xff'=%d\n", '\377', '\xff'); - printf("L'\\377'=%d L'\\xff'=%d\n", L'\377', L'\xff'); -#endif - ps("test\n"); - b = 32; - while ((b = b + 1) < 96) { - printf("%c", b); - } - printf("\n"); - printf("fib=%d\n", fib(33)); - b = 262144; - while (b != 0x80000000) { - num(b); - b = b * 2; - } -} - -void loop_test() -{ - int i; - i = 0; - while (i < 10) - printf("%d", i++); - printf("\n"); - for(i = 0; i < 10;i++) - printf("%d", i); - printf("\n"); - i = 0; - do { - printf("%d", i++); - } while (i < 10); - printf("\n"); - - char count = 123; - /* c99 for loop init test */ - for (size_t count = 1; count < 3; count++) - printf("count=%d\n", count); - printf("count = %d\n", count); - - /* break/continue tests */ - i = 0; - while (1) { - if (i == 6) - break; - i++; - if (i == 3) - continue; - printf("%d", i); - } - printf("\n"); - - /* break/continue tests */ - i = 0; - do { - if (i == 6) - break; - i++; - if (i == 3) - continue; - printf("%d", i); - } while(1); - printf("\n"); - - for(i = 0;i < 10;i++) { - if (i == 3) - continue; - printf("%d", i); - } - printf("\n"); -} - -typedef int typedef_and_label; - -void goto_test() -{ - int i; - static void *label_table[3] = { &&label1, &&label2, &&label3 }; - - printf("goto:\n"); - i = 0; - /* This needs to parse as label, not as start of decl. */ - typedef_and_label: - s_loop: - if (i >= 10) - goto s_end; - printf("%d", i); - i++; - goto s_loop; - s_end: - printf("\n"); - - /* we also test computed gotos (GCC extension) */ - for(i=0;i<3;i++) { - goto *label_table[i]; - label1: - printf("label1\n"); - goto next; - label2: - printf("label2\n"); - goto next; - label3: - printf("label3\n"); - next: ; - } -} - -enum { - E0, - E1 = 2, - E2 = 4, - E3, - E4, -}; - -enum test { - E5 = 1000, -}; - -struct S_enum { - enum {E6 = 42, E7, E8} e:8; -}; - -enum ELong { - /* This is either 0 on L32 machines, or a large number - on L64 machines. We should be able to store this. */ - EL_large = ((unsigned long)0xf000 << 31) << 1, -}; - -enum { BIASU = -1U<<31 }; -enum { BIASS = -1 << 31 }; - -static int getint(int i) -{ - if (i) - return 0; - else - return (int)(-1U << 31); -} - -void enum_test() -{ - enum test b1; - /* The following should give no warning */ - unsigned *p = &b1; - struct S_enum s = {E7}; - printf("enum: %d\n", s.e); - printf("enum:\n%d %d %d %d %d %d\n", - E0, E1, E2, E3, E4, E5); - b1 = 1; - printf("b1=%d\n", b1); - printf("enum large: %ld\n", EL_large); - - if (getint(0) == BIASU) - printf("enum unsigned: ok\n"); - else - printf("enum unsigned: wrong\n"); - if (getint(0) == BIASS) - printf("enum unsigned: ok\n"); - else - printf("enum unsigned: wrong\n"); -} - -typedef int *my_ptr; - -typedef int mytype1; -typedef int mytype2; - -void typedef_test() -{ - my_ptr a; - mytype1 mytype2; - int b; - - a = &b; - *a = 1234; - printf("typedef:\n"); - printf("a=%d\n", *a); - mytype2 = 2; - printf("mytype2=%d\n", mytype2); -} - -void forward_test() -{ - printf("forward:\n"); - forward_ref(); - forward_ref(); -} - - -void forward_ref(void) -{ - printf("forward ok\n"); -} - -typedef struct struct1 { - int f1; - int f2, f3; - union union1 { - int v1; - int v2; - } u; - char str[3]; -} struct1; - -struct struct2 { - int a; - char b; -}; - -union union2 { - int w1; - int w2; -}; - -struct struct1 st1, st2; - -struct empty_mem { - /* nothing */ ; - int x; -}; - -int main(int argc, char **argv) -{ - string_test(); - expr_test(); - macro_test(); - recursive_macro_test(); - scope_test(); - forward_test(); - funcptr_test(); - loop_test(); - switch_test(); - goto_test(); - enum_test(); - typedef_test(); - struct_test(); - array_test(); - expr_ptr_test(); - bool_test(); - optimize_out(); - expr2_test(); - constant_expr_test(); - expr_cmp_test(); - char_short_test(); - init_test(); - compound_literal_test(); - kr_test(); - struct_assign_test(); - cast_test(); - bitfield_test(); - c99_bool_test(); - float_test(); - longlong_test(); - manyarg_test(); - stdarg_test(); - whitespace_test(); - relocation_test(); - old_style_function(); - alloca_test(); - c99_vla_test(5, 2); - sizeof_test(); - typeof_test(); - statement_expr_test(); - local_label_test(); - asm_test(); - builtin_test(); -#ifndef _WIN32 - weak_test(); -#endif - global_data_test(); - cmp_comparison_test(); - math_cmp_test(); - callsave_test(); - builtin_frame_address_test(); - intdiv_test(); - if (via_volatile (42) != 42) - printf ("via_volatile broken\n"); - attrib_test(); - return 0; -} - -int tab[3]; -int tab2[3][2]; - -int g; - -void f1(g) -{ - printf("g1=%d\n", g); -} - -void scope_test() -{ - printf("scope:\n"); - g = 2; - f1(1); - printf("g2=%d\n", g); - { - int g; - g = 3; - printf("g3=%d\n", g); - { - int g; - g = 4; - printf("g4=%d\n", g); - } - } - printf("g5=%d\n", g); -} - -void array_test() -{ - int i, j, a[4]; - - printf("array:\n"); - printf("sizeof(a) = %d\n", sizeof(a)); - printf("sizeof(\"a\") = %d\n", sizeof("a")); -#ifdef C99_MACROS - printf("sizeof(__func__) = %d\n", sizeof(__func__)); -#endif - printf("sizeof tab %d\n", sizeof(tab)); - printf("sizeof tab2 %d\n", sizeof tab2); - tab[0] = 1; - tab[1] = 2; - tab[2] = 3; - printf("%d %d %d\n", tab[0], tab[1], tab[2]); - for(i=0;i<3;i++) - for(j=0;j<2;j++) - tab2[i][j] = 10 * i + j; - for(i=0;i<3*2;i++) { - printf(" %3d", ((int *)tab2)[i]); - } - printf("\n"); - printf("sizeof(size_t)=%d\n", sizeof(size_t)); - printf("sizeof(ptrdiff_t)=%d\n", sizeof(ptrdiff_t)); -} - -void expr_test() -{ - int a, b; - a = 0; - printf("%d\n", a += 1); - printf("%d\n", a -= 2); - printf("%d\n", a *= 31232132); - printf("%d\n", a /= 4); - printf("%d\n", a %= 20); - printf("%d\n", a &= 6); - printf("%d\n", a ^= 7); - printf("%d\n", a |= 8); - printf("%d\n", a >>= 3); - printf("%d\n", a <<= 4); - - a = 22321; - b = -22321; - printf("%d\n", a + 1); - printf("%d\n", a - 2); - printf("%d\n", a * 312); - printf("%d\n", a / 4); - printf("%d\n", b / 4); - printf("%d\n", (unsigned)b / 4); - printf("%d\n", a % 20); - printf("%d\n", b % 20); - printf("%d\n", (unsigned)b % 20); - printf("%d\n", a & 6); - printf("%d\n", a ^ 7); - printf("%d\n", a | 8); - printf("%d\n", a >> 3); - printf("%d\n", b >> 3); - printf("%d\n", (unsigned)b >> 3); - printf("%d\n", a << 4); - printf("%d\n", ~a); - printf("%d\n", -a); - printf("%d\n", +a); - - printf("%d\n", 12 + 1); - printf("%d\n", 12 - 2); - printf("%d\n", 12 * 312); - printf("%d\n", 12 / 4); - printf("%d\n", 12 % 20); - printf("%d\n", 12 & 6); - printf("%d\n", 12 ^ 7); - printf("%d\n", 12 | 8); - printf("%d\n", 12 >> 2); - printf("%d\n", 12 << 4); - printf("%d\n", ~12); - printf("%d\n", -12); - printf("%d\n", +12); - printf("%d %d %d %d\n", - isid('a'), - isid('g'), - isid('T'), - isid('(')); -} - -int isid(int c) -{ - return (c >= 'a' & c <= 'z') | (c >= 'A' & c <= 'Z') | c == '_'; -} - -/**********************/ - -int vstack[10], *vstack_ptr; - -void vpush(int vt, int vc) -{ - *vstack_ptr++ = vt; - *vstack_ptr++ = vc; -} - -void vpop(int *ft, int *fc) -{ - *fc = *--vstack_ptr; - *ft = *--vstack_ptr; -} - -void expr2_test() -{ - int a, b; - - printf("expr2:\n"); - vstack_ptr = vstack; - vpush(1432432, 2); - vstack_ptr[-2] &= ~0xffffff80; - vpop(&a, &b); - printf("res= %d %d\n", a, b); -} - -void constant_expr_test() -{ - int a; - printf("constant_expr:\n"); - a = 3; - printf("%d\n", a * 16); - printf("%d\n", a * 1); - printf("%d\n", a + 0); -} - -int tab4[10]; - -void expr_ptr_test() -{ - int *p, *q; - int i = -1; - - printf("expr_ptr:\n"); - p = tab4; - q = tab4 + 10; - printf("diff=%d\n", q - p); - p++; - printf("inc=%d\n", p - tab4); - p--; - printf("dec=%d\n", p - tab4); - ++p; - printf("inc=%d\n", p - tab4); - --p; - printf("dec=%d\n", p - tab4); - printf("add=%d\n", p + 3 - tab4); - printf("add=%d\n", 3 + p - tab4); - - /* check if 64bit support is ok */ - q = p = 0; - q += i; - printf("%p %p %ld\n", q, p, p-q); - printf("%d %d %d %d %d %d\n", - p == q, p != q, p < q, p <= q, p >= q, p > q); - i = 0xf0000000; - p += i; - printf("%p %p %ld\n", q, p, p-q); - printf("%d %d %d %d %d %d\n", - p == q, p != q, p < q, p <= q, p >= q, p > q); - p = (int *)((char *)p + 0xf0000000); - printf("%p %p %ld\n", q, p, p-q); - printf("%d %d %d %d %d %d\n", - p == q, p != q, p < q, p <= q, p >= q, p > q); - p += 0xf0000000; - printf("%p %p %ld\n", q, p, p-q); - printf("%d %d %d %d %d %d\n", - p == q, p != q, p < q, p <= q, p >= q, p > q); - { - struct size12 { - int i, j, k; - }; - struct size12 s[2], *sp = s; - int i, j; - sp->i = 42; - sp++; - j = -1; - printf("%d\n", sp[j].i); - } -#ifdef __LP64__ - i = 1; - p = (int*)0x100000000UL + i; - i = ((long)p) >> 32; - printf("largeptr: %p %d\n", p, i); -#endif -} - -void expr_cmp_test() -{ - int a, b; - printf("constant_expr:\n"); - a = -1; - b = 1; - printf("%d\n", a == a); - printf("%d\n", a != a); - - printf("%d\n", a < b); - printf("%d\n", a <= b); - printf("%d\n", a <= a); - printf("%d\n", b >= a); - printf("%d\n", a >= a); - printf("%d\n", b > a); - - printf("%d\n", (unsigned)a < b); - printf("%d\n", (unsigned)a <= b); - printf("%d\n", (unsigned)a <= a); - printf("%d\n", (unsigned)b >= a); - printf("%d\n", (unsigned)a >= a); - printf("%d\n", (unsigned)b > a); -} - -struct empty { -}; - -struct aligntest1 { - char a[10]; -}; - -struct aligntest2 { - int a; - char b[10]; -}; - -struct aligntest3 { - double a, b; -}; - -struct aligntest4 { - double a[0]; -}; - -struct __attribute__((aligned(16))) aligntest5 -{ - int i; -}; -struct aligntest6 -{ - int i; -} __attribute__((aligned(16))); -struct aligntest7 -{ - int i; -}; -struct aligntest5 altest5[2]; -struct aligntest6 altest6[2]; -int pad1; -/* altest7 is correctly aligned to 16 bytes also with TCC, - but __alignof__ returns the wrong result (4) because we - can't store the alignment yet when specified on symbols - directly (it's stored in the type so we'd need to make - a copy of it). -- FIXED */ -struct aligntest7 altest7[2] __attribute__((aligned(16))); - -struct aligntest8 -{ - int i; -} __attribute__((aligned(4096))); - -struct Large { - unsigned long flags; - union { - void *u1; - int *u2; - }; - - struct { - union { - unsigned long index; - void *freelist; - }; - union { - unsigned long counters; - struct { - int bla; - }; - }; - }; - - union { - struct { - long u3; - long u4; - }; - void *u5; - struct { - unsigned long compound_head; - unsigned int compound_dtor; - unsigned int compound_order; - }; - }; -} __attribute__((aligned(2 * sizeof(long)))); - -typedef unsigned long long __attribute__((aligned(4))) unaligned_u64; - -struct aligntest9 { - unsigned int buf_nr; - unaligned_u64 start_lba; -}; - -struct aligntest10 { - unsigned int buf_nr; - unsigned long long start_lba; -}; - -void struct_test() -{ - struct1 *s; - union union2 u; - struct Large ls; - - printf("struct:\n"); - printf("sizes: %d %d %d %d\n", - sizeof(struct struct1), - sizeof(struct struct2), - sizeof(union union1), - sizeof(union union2)); - printf("offsets: %d\n", (int)((char*)&st1.u.v1 - (char*)&st1)); - st1.f1 = 1; - st1.f2 = 2; - st1.f3 = 3; - printf("st1: %d %d %d\n", - st1.f1, st1.f2, st1.f3); - st1.u.v1 = 1; - st1.u.v2 = 2; - printf("union1: %d\n", st1.u.v1); - u.w1 = 1; - u.w2 = 2; - printf("union2: %d\n", u.w1); - s = &st2; - s->f1 = 3; - s->f2 = 2; - s->f3 = 1; - printf("st2: %d %d %d\n", - s->f1, s->f2, s->f3); - printf("str_addr=%x\n", (int)st1.str - (int)&st1.f1); - - /* align / size tests */ - printf("aligntest1 sizeof=%d alignof=%d\n", - sizeof(struct aligntest1), __alignof__(struct aligntest1)); - printf("aligntest2 sizeof=%d alignof=%d\n", - sizeof(struct aligntest2), __alignof__(struct aligntest2)); - printf("aligntest3 sizeof=%d alignof=%d\n", - sizeof(struct aligntest3), __alignof__(struct aligntest3)); - printf("aligntest4 sizeof=%d alignof=%d\n", - sizeof(struct aligntest4), __alignof__(struct aligntest4)); - printf("aligntest5 sizeof=%d alignof=%d\n", - sizeof(struct aligntest5), __alignof__(struct aligntest5)); - printf("aligntest6 sizeof=%d alignof=%d\n", - sizeof(struct aligntest6), __alignof__(struct aligntest6)); - printf("aligntest7 sizeof=%d alignof=%d\n", - sizeof(struct aligntest7), __alignof__(struct aligntest7)); - printf("aligntest8 sizeof=%d alignof=%d\n", - sizeof(struct aligntest8), __alignof__(struct aligntest8)); - printf("aligntest9 sizeof=%d alignof=%d\n", - sizeof(struct aligntest9), __alignof__(struct aligntest9)); - printf("aligntest10 sizeof=%d alignof=%d\n", - sizeof(struct aligntest10), __alignof__(struct aligntest10)); - printf("altest5 sizeof=%d alignof=%d\n", - sizeof(altest5), __alignof__(altest5)); - printf("altest6 sizeof=%d alignof=%d\n", - sizeof(altest6), __alignof__(altest6)); - printf("altest7 sizeof=%d alignof=%d\n", - sizeof(altest7), __alignof__(altest7)); - - /* empty structures (GCC extension) */ - printf("sizeof(struct empty) = %d\n", sizeof(struct empty)); - printf("alignof(struct empty) = %d\n", __alignof__(struct empty)); - - printf("Large: sizeof=%d\n", sizeof(ls)); - memset(&ls, 0, sizeof(ls)); - ls.compound_head = 42; - printf("Large: offsetof(compound_head)=%d\n", (int)((char*)&ls.compound_head - (char*)&ls)); -} - -/* XXX: depend on endianness */ -void char_short_test() -{ - int var1, var2; - - printf("char_short:\n"); - - var1 = 0x01020304; - var2 = 0xfffefdfc; - printf("s8=%d %d\n", - *(char *)&var1, *(char *)&var2); - printf("u8=%d %d\n", - *(unsigned char *)&var1, *(unsigned char *)&var2); - printf("s16=%d %d\n", - *(short *)&var1, *(short *)&var2); - printf("u16=%d %d\n", - *(unsigned short *)&var1, *(unsigned short *)&var2); - printf("s32=%d %d\n", - *(int *)&var1, *(int *)&var2); - printf("u32=%d %d\n", - *(unsigned int *)&var1, *(unsigned int *)&var2); - *(char *)&var1 = 0x08; - printf("var1=%x\n", var1); - *(short *)&var1 = 0x0809; - printf("var1=%x\n", var1); - *(int *)&var1 = 0x08090a0b; - printf("var1=%x\n", var1); -} - -/******************/ - -typedef struct Sym { - int v; - int t; - int c; - struct Sym *next; - struct Sym *prev; -} Sym; - -#define ISLOWER(c) ('a' <= (c) && (c) <= 'z') -#define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) - -static int toupper1(int a) -{ - return TOUPPER(a); -} - -static unsigned int calc_vm_flags(unsigned int prot) -{ - unsigned int prot_bits; - /* This used to segfault in some revisions: */ - prot_bits = ((0x1==0x00000001)?(prot&0x1):(prot&0x1)?0x00000001:0); - return prot_bits; -} - -void bool_test() -{ - int *s, a, b, t, f, i; - - a = 0; - s = (void*)0; - printf("!s=%d\n", !s); - - if (!s || !s[0]) - a = 1; - printf("a=%d\n", a); - - printf("a=%d %d %d\n", 0 || 0, 0 || 1, 1 || 1); - printf("a=%d %d %d\n", 0 && 0, 0 && 1, 1 && 1); - printf("a=%d %d\n", 1 ? 1 : 0, 0 ? 1 : 0); -#if 1 && 1 - printf("a1\n"); -#endif -#if 1 || 0 - printf("a2\n"); -#endif -#if 1 ? 0 : 1 - printf("a3\n"); -#endif -#if 0 ? 0 : 1 - printf("a4\n"); -#endif - - a = 4; - printf("b=%d\n", a + (0 ? 1 : a / 2)); - - /* test register spilling */ - a = 10; - b = 10; - a = (a + b) * ((a < b) ? - ((b - a) * (a - b)): a + b); - printf("a=%d\n", a); - - /* test complex || or && expressions */ - t = 1; - f = 0; - a = 32; - printf("exp=%d\n", f == (32 <= a && a <= 3)); - printf("r=%d\n", (t || f) + (t && f)); - - /* test ? : cast */ - { - int aspect_on; - int aspect_native = 65536; - double bfu_aspect = 1.0; - int aspect; - for(aspect_on = 0; aspect_on < 2; aspect_on++) { - aspect=aspect_on?(aspect_native*bfu_aspect+0.5):65535UL; - printf("aspect=%d\n", aspect); - } - } - - /* test ? : GCC extension */ - { - static int v1 = 34 ? : -1; /* constant case */ - static int v2 = 0 ? : -1; /* constant case */ - int a = 30; - - printf("%d %d\n", v1, v2); - printf("%d %d\n", a - 30 ? : a * 2, a + 1 ? : a * 2); - } - - /* again complex expression */ - for(i=0;i<256;i++) { - if (toupper1 (i) != TOUPPER (i)) - printf("error %d\n", i); - } - printf ("bits = 0x%x\n", calc_vm_flags (0x1)); -} - -extern int undefined_function(void); -extern int defined_function(void); - -static inline void refer_to_undefined(void) -{ - undefined_function(); -} - -void optimize_out(void) -{ - int i = 0 ? undefined_function() : defined_function(); - printf ("oo:%d\n", i); - int j = 1 ? defined_function() : undefined_function(); - printf ("oo:%d\n", j); - if (0) - printf("oo:%d\n", undefined_function()); - else - printf("oo:%d\n", defined_function()); - if (1) - printf("oo:%d\n", defined_function()); - else - printf("oo:%d\n", undefined_function()); - while (1) { - printf("oow:%d\n", defined_function()); - break; - printf("oow:%d\n", undefined_function()); - } - j = 1; - /* Following is a switch without {} block intentionally. */ - switch (j) - case 1: break; - printf ("oos:%d\n", defined_function()); - /* The following break shouldn't lead to disabled code after - the while. */ - while (1) - break; - printf ("ool1:%d\n", defined_function()); - /* Same for the other types of loops. */ - do - break; - while (1); - printf ("ool2:%d\n", defined_function()); - for (;;) - break; - printf ("ool3:%d\n", defined_function()); - /* Normal {} blocks without controlling statements - shouldn't reactivate code emission */ - while (1) { - { - break; - } - printf ("ool4:%d\n", undefined_function()); - } - j = 1; - while (j) { - if (j == 0) - break; /* this break shouldn't disable code outside the if. */ - printf("ool5:%d\n", defined_function()); - j--; - } - - j = 1; - while (j) { - if (1) - j--; - else - breakhere: break; - printf("ool6:%d\n", defined_function()); - goto breakhere; - } - - /* Test that constants in logical && are optimized: */ - i = 0 && undefined_function(); - i = defined_function() && 0 && undefined_function(); - if (0 && undefined_function()) - undefined_function(); - if (defined_function() && 0) - undefined_function(); - if (0 && 0) - undefined_function(); - if (defined_function() && 0 && undefined_function()) - undefined_function(); - /* The same for || : */ - i = 1 || undefined_function(); - i = defined_function() || 1 || undefined_function(); - if (1 || undefined_function()) - ; - else - undefined_function(); - if (defined_function() || 1) - ; - else - undefined_function(); - if (1 || 1) - ; - else - undefined_function(); - if (defined_function() || 1 || undefined_function()) - ; - else - undefined_function(); - - if (defined_function() && 0) - refer_to_undefined(); - - if (0) { - (void)sizeof( ({ - do { } while (0); - 0; - }) ); - undefined_function(); - } - - /* Leave the "if(1)return; printf()" in this order and last in the function */ - if (1) - return; - printf ("oor:%d\n", undefined_function()); -} - -int defined_function(void) -{ - static int i = 40; - return i++; -} - -/* GCC accepts that */ -static int tab_reinit[]; -static int tab_reinit[10]; - -//int cinit1; /* a global variable can be defined several times without error ! */ -int cinit1; -int cinit1; -int cinit1 = 0; -int *cinit2 = (int []){3, 2, 1}; - -void compound_literal_test(void) -{ - int *p, i; - char *q, *q3; - - printf("compound_test:\n"); - - p = (int []){1, 2, 3}; - for(i=0;i<3;i++) - printf(" %d", p[i]); - printf("\n"); - - for(i=0;i<3;i++) - printf("%d", cinit2[i]); - printf("\n"); - - q = "tralala1"; - printf("q1=%s\n", q); - - q = (char *){ "tralala2" }; - printf("q2=%s\n", q); - - q3 = (char *){ q }; - printf("q3=%s\n", q3); - - q = (char []){ "tralala3" }; - printf("q4=%s\n", q); - -#ifdef ALL_ISOC99 - p = (int []){1, 2, cinit1 + 3}; - for(i=0;i<3;i++) - printf(" %d", p[i]); - printf("\n"); - - for(i=0;i<3;i++) { - p = (int []){1, 2, 4 + i}; - printf("%d %d %d\n", - p[0], - p[1], - p[2]); - } -#endif -} - -/* K & R protos */ - -kr_func1(a, b) -{ - return a + b; -} - -int kr_func2(a, b) -{ - return a + b; -} - -kr_test() -{ - printf("kr_test:\n"); - printf("func1=%d\n", kr_func1(3, 4)); - printf("func2=%d\n", kr_func2(3, 4)); - return 0; -} - -void num(int n) -{ - char *tab, *p; - tab = (char*)malloc(20); - p = tab; - while (1) { - *p = 48 + (n % 10); - p++; - n = n / 10; - if (n == 0) - break; - } - while (p != tab) { - p--; - printf("%c", *p); - } - printf("\n"); - free(tab); -} - -/* structure assignment tests */ -struct structa1 { - int f1; - char f2; -}; - -struct structa1 ssta1; - -void struct_assign_test1(struct structa1 s1, int t, float f) -{ - printf("%d %d %d %f\n", s1.f1, s1.f2, t, f); -} - -struct structa1 struct_assign_test2(struct structa1 s1, int t) -{ - s1.f1 += t; - s1.f2 -= t; - return s1; -} - -void struct_assign_test(void) -{ - struct S { - struct structa1 lsta1, lsta2; - int i; - } s, *ps; - - ps = &s; - ps->i = 4; -#if 0 - printf("struct_assign_test:\n"); - - s.lsta1.f1 = 1; - s.lsta1.f2 = 2; - printf("%d %d\n", s.lsta1.f1, s.lsta1.f2); - s.lsta2 = s.lsta1; - printf("%d %d\n", s.lsta2.f1, s.lsta2.f2); -#else - s.lsta2.f1 = 1; - s.lsta2.f2 = 2; -#endif - struct_assign_test1(ps->lsta2, 3, 4.5); - - printf("before call: %d %d\n", s.lsta2.f1, s.lsta2.f2); - ps->lsta2 = struct_assign_test2(ps->lsta2, ps->i); - printf("after call: %d %d\n", ps->lsta2.f1, ps->lsta2.f2); - - static struct { - void (*elem)(); - } t[] = { - /* XXX: we should allow this even without braces */ - { struct_assign_test } - }; - printf("%d\n", struct_assign_test == t[0].elem); -} - -/* casts to short/char */ - -void cast1(char a, short b, unsigned char c, unsigned short d) -{ - printf("%d %d %d %d\n", a, b, c, d); -} - -char bcast; -short scast; - -void cast_test() -{ - int a; - char c; - char tab[10]; - unsigned b,d; - short s; - char *p = NULL; - p -= 0x700000000042; - - printf("cast_test:\n"); - a = 0xfffff; - cast1(a, a, a, a); - a = 0xffffe; - printf("%d %d %d %d\n", - (char)(a + 1), - (short)(a + 1), - (unsigned char)(a + 1), - (unsigned short)(a + 1)); - printf("%d %d %d %d\n", - (char)0xfffff, - (short)0xfffff, - (unsigned char)0xfffff, - (unsigned short)0xfffff); - - a = (bcast = 128) + 1; - printf("%d\n", a); - a = (scast = 65536) + 1; - printf("%d\n", a); - - printf("sizeof(c) = %d, sizeof((int)c) = %d\n", sizeof(c), sizeof((int)c)); - - /* test cast from unsigned to signed short to int */ - b = 0xf000; - d = (short)b; - printf("((unsigned)(short)0x%08x) = 0x%08x\n", b, d); - b = 0xf0f0; - d = (char)b; - printf("((unsigned)(char)0x%08x) = 0x%08x\n", b, d); - - /* test implicit int casting for array accesses */ - c = 0; - tab[1] = 2; - tab[c] = 1; - printf("%d %d\n", tab[0], tab[1]); - - /* test implicit casting on some operators */ - printf("sizeof(+(char)'a') = %d\n", sizeof(+(char)'a')); - printf("sizeof(-(char)'a') = %d\n", sizeof(-(char)'a')); - printf("sizeof(~(char)'a') = %d\n", sizeof(-(char)'a')); - - /* from pointer to integer types */ - printf("%d %d %ld %ld %lld %lld\n", - (int)p, (unsigned int)p, - (long)p, (unsigned long)p, - (long long)p, (unsigned long long)p); - - /* from integers to pointers */ - printf("%p %p %p %p\n", - (void *)a, (void *)b, (void *)c, (void *)d); -} - -/* initializers tests */ -struct structinit1 { - int f1; - char f2; - short f3; - int farray[3]; -}; - -int sinit1 = 2; -int sinit2 = { 3 }; -int sinit3[3] = { 1, 2, {{3}}, }; -int sinit4[3][2] = { {1, 2}, {3, 4}, {5, 6} }; -int sinit5[3][2] = { 1, 2, 3, 4, 5, 6 }; -int sinit6[] = { 1, 2, 3 }; -int sinit7[] = { [2] = 3, [0] = 1, 2 }; -char sinit8[] = "hello" "trala"; - -struct structinit1 sinit9 = { 1, 2, 3 }; -struct structinit1 sinit10 = { .f2 = 2, 3, .f1 = 1 }; -struct structinit1 sinit11 = { .f2 = 2, 3, .f1 = 1, -#ifdef ALL_ISOC99 - .farray[0] = 10, - .farray[1] = 11, - .farray[2] = 12, -#endif -}; - -char *sinit12 = "hello world"; -char *sinit13[] = { - "test1", - "test2", - "test3", -}; -char sinit14[10] = { "abc" }; -int sinit15[3] = { sizeof(sinit15), 1, 2 }; - -struct { int a[3], b; } sinit16[] = { { 1 }, 2 }; - -struct bar { - char *s; - int len; -} sinit17[] = { - "a1", 4, - "a2", 1 -}; - -int sinit18[10] = { - [2 ... 5] = 20, - 2, - [8] = 10, -}; - -struct complexinit0 { - int a; - int b; -}; - -struct complexinit { - int a; - const struct complexinit0 *b; -}; - -const static struct complexinit cix[] = { - [0] = { - .a = 2000, - .b = (const struct complexinit0[]) { - { 2001, 2002 }, - { 2003, 2003 }, - {} - } - } -}; - -struct complexinit2 { - int a; - int b[]; -}; - -struct complexinit2 cix20; - -struct complexinit2 cix21 = { - .a = 3000, - .b = { 3001, 3002, 3003 } -}; - -struct complexinit2 cix22 = { - .a = 4000, - .b = { 4001, 4002, 4003, 4004, 4005, 4006 } -}; - -typedef int arrtype1[]; -arrtype1 sinit19 = {1}; -arrtype1 sinit20 = {2,3}; -typedef int arrtype2[3]; -arrtype2 sinit21 = {4}; -arrtype2 sinit22 = {5,6,7}; - -/* Address comparisons of non-weak symbols with zero can be const-folded */ -int sinit23[2] = { "astring" ? sizeof("astring") : -1, - &sinit23 ? 42 : -1 }; - -extern int external_inited = 42; - -void init_test(void) -{ - int linit1 = 2; - int linit2 = { 3 }; - int linit4[3][2] = { {1, 2}, {3, 4}, {5, 6} }; - int linit6[] = { 1, 2, 3 }; - int i, j; - char linit8[] = "hello" "trala"; - int linit12[10] = { 1, 2 }; - int linit13[10] = { 1, 2, [7] = 3, [3] = 4, }; - char linit14[10] = "abc"; - int linit15[10] = { linit1, linit1 + 1, [6] = linit1 + 2, }; - struct linit16 { int a1, a2, a3, a4; } linit16 = { 1, .a3 = 2 }; - int linit17 = sizeof(linit17); - int zero = 0; - /* Addresses on non-weak symbols are non-zero, but not the access itself */ - int linit18[2] = {&zero ? 1 : -1, zero ? -1 : 1 }; - - printf("init_test:\n"); - - printf("sinit1=%d\n", sinit1); - printf("sinit2=%d\n", sinit2); - printf("sinit3=%d %d %d %d\n", - sizeof(sinit3), - sinit3[0], - sinit3[1], - sinit3[2] - ); - printf("sinit6=%d\n", sizeof(sinit6)); - printf("sinit7=%d %d %d %d\n", - sizeof(sinit7), - sinit7[0], - sinit7[1], - sinit7[2] - ); - printf("sinit8=%s\n", sinit8); - printf("sinit9=%d %d %d\n", - sinit9.f1, - sinit9.f2, - sinit9.f3 - ); - printf("sinit10=%d %d %d\n", - sinit10.f1, - sinit10.f2, - sinit10.f3 - ); - printf("sinit11=%d %d %d %d %d %d\n", - sinit11.f1, - sinit11.f2, - sinit11.f3, - sinit11.farray[0], - sinit11.farray[1], - sinit11.farray[2] - ); - - for(i=0;i<3;i++) - for(j=0;j<2;j++) - printf("[%d][%d] = %d %d %d\n", - i, j, sinit4[i][j], sinit5[i][j], linit4[i][j]); - printf("linit1=%d\n", linit1); - printf("linit2=%d\n", linit2); - printf("linit6=%d\n", sizeof(linit6)); - printf("linit8=%d %s\n", sizeof(linit8), linit8); - - printf("sinit12=%s\n", sinit12); - printf("sinit13=%d %s %s %s\n", - sizeof(sinit13), - sinit13[0], - sinit13[1], - sinit13[2]); - printf("sinit14=%s\n", sinit14); - - for(i=0;i<10;i++) printf(" %d", linit12[i]); - printf("\n"); - for(i=0;i<10;i++) printf(" %d", linit13[i]); - printf("\n"); - for(i=0;i<10;i++) printf(" %d", linit14[i]); - printf("\n"); - for(i=0;i<10;i++) printf(" %d", linit15[i]); - printf("\n"); - printf("%d %d %d %d\n", - linit16.a1, - linit16.a2, - linit16.a3, - linit16.a4); - /* test that initialisation is done after variable declare */ - printf("linit17=%d\n", linit17); - printf("sinit15=%d\n", sinit15[0]); - printf("sinit16=%d %d\n", sinit16[0].a[0], sinit16[1].a[0]); - printf("sinit17=%s %d %s %d\n", - sinit17[0].s, sinit17[0].len, - sinit17[1].s, sinit17[1].len); - for(i=0;i<10;i++) - printf("%x ", sinit18[i]); - printf("\n"); - /* complex init check */ - printf("cix: %d %d %d %d %d %d %d\n", - cix[0].a, - cix[0].b[0].a, cix[0].b[0].b, - cix[0].b[1].a, cix[0].b[1].b, - cix[0].b[2].a, cix[0].b[2].b); - printf("cix2: %d %d\n", cix21.b[2], cix22.b[5]); - printf("sizeof cix20 %d, cix21 %d, sizeof cix22 %d\n", sizeof cix20, sizeof cix21, sizeof cix22); - - printf("arrtype1: %d %d %d\n", sinit19[0], sinit20[0], sinit20[1]); - printf("arrtype2: %d %d\n", sizeof(sinit19), sizeof(sinit20)); - printf("arrtype3: %d %d %d\n", sinit21[0], sinit21[1], sinit21[2]); - printf("arrtype4: %d %d %d\n", sinit22[0], sinit22[1], sinit22[2]); - printf("arrtype5: %d %d\n", sizeof(sinit21), sizeof(sinit22)); - printf("arrtype6: %d\n", sizeof(arrtype2)); - - printf("sinit23= %d %d\n", sinit23[0], sinit23[1]); - printf("linit18= %d %d\n", linit18[0], linit18[1]); -} - -void switch_uc(unsigned char uc) -{ - switch (uc) { - case 0xfb ... 0xfe: - printf("ucsw:1\n"); - break; - case 0xff: - printf("ucsw:2\n"); - break; - case 0 ... 5: - printf("ucsw:3\n"); - break; - default: - printf("ucsw: broken!\n"); - } -} - -void switch_sc(signed char sc) -{ - switch (sc) { - case -5 ... -2: - printf("scsw:1\n"); - break; - case -1: - printf("scsw:2\n"); - break; - case 0 ... 5: - printf("scsw:3\n"); - break; - default: - printf("scsw: broken!\n"); - } -} - -void switch_test() -{ - int i; - unsigned long long ull; - long long ll; - - for(i=0;i<15;i++) { - switch(i) { - case 0: - case 1: - printf("a"); - break; - default: - printf("%d", i); - break; - case 8 ... 12: - printf("c"); - break; - case 3: - printf("b"); - break; - case 0xc33c6b9fU: - case 0x7c9eeeb9U: - break; - } - } - printf("\n"); - - for (i = 1; i <= 5; i++) { - ull = (unsigned long long)i << 61; - switch (ull) { - case 1ULL << 61: - printf("ullsw:1\n"); - break; - case 2ULL << 61: - printf("ullsw:2\n"); - break; - case 3ULL << 61: - printf("ullsw:3\n"); - break; - case 4ULL << 61: - printf("ullsw:4\n"); - break; - case 5ULL << 61: - printf("ullsw:5\n"); - break; - default: - printf("ullsw: broken!\n"); - } - } - - for (i = 1; i <= 5; i++) { - ll = (long long)i << 61; - switch (ll) { - case 1LL << 61: - printf("llsw:1\n"); - break; - case 2LL << 61: - printf("llsw:2\n"); - break; - case 3LL << 61: - printf("llsw:3\n"); - break; - case 4LL << 61: - printf("llsw:4\n"); - break; - case 5LL << 61: - printf("llsw:5\n"); - break; - default: - printf("llsw: broken!\n"); - } - } - - for (i = -5; i <= 5; i++) { - switch_uc((unsigned char)i); - } - - for (i = -5; i <= 5; i++) { - switch_sc ((signed char)i); - } -} - -/* ISOC99 _Bool type */ -void c99_bool_test(void) -{ -#ifdef BOOL_ISOC99 - int a; - _Bool b; - - printf("bool_test:\n"); - printf("sizeof(_Bool) = %d\n", sizeof(_Bool)); - a = 3; - printf("cast: %d %d %d\n", (_Bool)10, (_Bool)0, (_Bool)a); - b = 3; - printf("b = %d\n", b); - b++; - printf("b = %d\n", b); -#endif -} - -void bitfield_test(void) -{ - int a; - short sa; - unsigned char ca; - struct sbf1 { - int f1 : 3; - int : 2; - int f2 : 1; - int : 0; - int f3 : 5; - int f4 : 7; - unsigned int f5 : 7; - } st1; - printf("bitfield_test:"); - printf("sizeof(st1) = %d\n", sizeof(st1)); - - st1.f1 = 3; - st1.f2 = 1; - st1.f3 = 15; - a = 120; - st1.f4 = a; - st1.f5 = a; - st1.f5++; - printf("%d %d %d %d %d\n", - st1.f1, st1.f2, st1.f3, st1.f4, st1.f5); - sa = st1.f5; - ca = st1.f5; - printf("%d %d\n", sa, ca); - - st1.f1 = 7; - if (st1.f1 == -1) - printf("st1.f1 == -1\n"); - else - printf("st1.f1 != -1\n"); - if (st1.f2 == -1) - printf("st1.f2 == -1\n"); - else - printf("st1.f2 != -1\n"); - - struct sbf2 { - long long f1 : 45; - long long : 2; - long long f2 : 35; - unsigned long long f3 : 38; - } st2; - st2.f1 = 0x123456789ULL; - a = 120; - st2.f2 = (long long)a << 25; - st2.f3 = a; - st2.f2++; - printf("%lld %lld %lld\n", st2.f1, st2.f2, st2.f3); - -#if 0 - Disabled for now until further clarification re GCC compatibility - struct sbf3 { - int f1 : 7; - int f2 : 1; - char f3; - int f4 : 8; - int f5 : 1; - int f6 : 16; - } st3; - printf("sizeof(st3) = %d\n", sizeof(st3)); -#endif - - struct sbf4 { - int x : 31; - char y : 2; - } st4; - st4.y = 1; - printf("st4.y == %d\n", st4.y); - struct sbf5 { - int a; - char b; - int x : 12, y : 4, : 0, : 4, z : 3; - char c; - } st5 = { 1, 2, 3, 4, -3, 6 }; - printf("st5 = %d %d %d %d %d %d\n", st5.a, st5.b, st5.x, st5.y, st5.z, st5.c); - struct sbf6 { - short x : 12; - unsigned char y : 2; - } st6; - st6.y = 1; - printf("st6.y == %d\n", st6.y); -} - -#ifdef __x86_64__ -#define FLOAT_FMT "%f\n" -#else -/* x86's float isn't compatible with GCC */ -#define FLOAT_FMT "%.5f\n" -#endif - -/* declare strto* functions as they are C99 */ -double strtod(const char *nptr, char **endptr); - -#if defined(_WIN32) -float strtof(const char *nptr, char **endptr) {return (float)strtod(nptr, endptr);} -LONG_DOUBLE strtold(const char *nptr, char **endptr) {return (LONG_DOUBLE)strtod(nptr, endptr);} -#else -float strtof(const char *nptr, char **endptr); -LONG_DOUBLE strtold(const char *nptr, char **endptr); -#endif - -#define FTEST(prefix, typename, type, fmt)\ -void prefix ## cmp(type a, type b)\ -{\ - printf("%d %d %d %d %d %d\n",\ - a == b,\ - a != b,\ - a < b,\ - a > b,\ - a >= b,\ - a <= b);\ - printf(fmt " " fmt " " fmt " " fmt " " fmt " " fmt " " fmt "\n",\ - a,\ - b,\ - a + b,\ - a - b,\ - a * b,\ - a / b,\ - -a);\ - printf(fmt "\n", ++a);\ - printf(fmt "\n", a++);\ - printf(fmt "\n", a);\ - b = 0;\ - printf("%d %d\n", !a, !b);\ -}\ -void prefix ## fcast(type a)\ -{\ - float fa;\ - double da;\ - LONG_DOUBLE la;\ - int ia;\ - long long llia;\ - unsigned int ua;\ - unsigned long long llua;\ - type b;\ - fa = a;\ - da = a;\ - la = a;\ - printf("ftof: %f %f %Lf\n", fa, da, la);\ - ia = (int)a;\ - llia = (long long)a;\ - a = (a >= 0) ? a : -a;\ - ua = (unsigned int)a;\ - llua = (unsigned long long)a;\ - printf("ftoi: %d %u %lld %llu\n", ia, ua, llia, llua);\ - ia = -1234;\ - ua = 0x81234500;\ - llia = -0x123456789012345LL;\ - llua = 0xf123456789012345LLU;\ - b = ia;\ - printf("itof: " fmt "\n", b);\ - b = ua;\ - printf("utof: " fmt "\n", b);\ - b = llia;\ - printf("lltof: " fmt "\n", b);\ - b = llua;\ - printf("ulltof: " fmt "\n", b);\ -}\ -\ -float prefix ## retf(type a) { return a; }\ -double prefix ## retd(type a) { return a; }\ -LONG_DOUBLE prefix ## retld(type a) { return a; }\ -\ -void prefix ## call(void)\ -{\ - printf("float: " FLOAT_FMT, prefix ## retf(42.123456789));\ - printf("double: %f\n", prefix ## retd(42.123456789));\ - printf("long double: %Lf\n", prefix ## retld(42.123456789));\ - printf("strto%s: %f\n", #prefix, (double)strto ## prefix("1.2", NULL));\ -}\ -\ -void prefix ## signed_zeros(void) \ -{\ - type x = 0.0, y = -0.0, n, p;\ - if (x == y)\ - printf ("Test 1.0 / x != 1.0 / y returns %d (should be 1).\n",\ - 1.0 / x != 1.0 / y);\ - else\ - printf ("x != y; this is wrong!\n");\ -\ - n = -x;\ - if (x == n)\ - printf ("Test 1.0 / x != 1.0 / -x returns %d (should be 1).\n",\ - 1.0 / x != 1.0 / n);\ - else\ - printf ("x != -x; this is wrong!\n");\ -\ - p = +y;\ - if (x == p)\ - printf ("Test 1.0 / x != 1.0 / +y returns %d (should be 1).\n",\ - 1.0 / x != 1.0 / p);\ - else\ - printf ("x != +y; this is wrong!\n");\ - p = -y;\ - if (x == p)\ - printf ("Test 1.0 / x != 1.0 / -y returns %d (should be 0).\n",\ - 1.0 / x != 1.0 / p);\ - else\ - printf ("x != -y; this is wrong!\n");\ -}\ -void prefix ## test(void)\ -{\ - printf("testing '%s'\n", #typename);\ - prefix ## cmp(1, 2.5);\ - prefix ## cmp(2, 1.5);\ - prefix ## cmp(1, 1);\ - prefix ## fcast(234.6);\ - prefix ## fcast(-2334.6);\ - prefix ## call();\ - prefix ## signed_zeros();\ -} - -FTEST(f, float, float, "%f") -FTEST(d, double, double, "%f") -FTEST(ld, long double, LONG_DOUBLE, "%Lf") - -double ftab1[3] = { 1.2, 3.4, -5.6 }; - - -void float_test(void) -{ -#if !defined(__arm__) || defined(__ARM_PCS_VFP) - float fa, fb; - double da, db; - int a; - unsigned int b; - - printf("float_test:\n"); - printf("sizeof(float) = %d\n", sizeof(float)); - printf("sizeof(double) = %d\n", sizeof(double)); - printf("sizeof(long double) = %d\n", sizeof(LONG_DOUBLE)); - ftest(); - dtest(); - ldtest(); - printf("%f %f %f\n", ftab1[0], ftab1[1], ftab1[2]); - printf("%f %f %f\n", 2.12, .5, 2.3e10); - // printf("%f %f %f\n", 0x1234p12, 0x1e23.23p10, 0x12dp-10); - da = 123; - printf("da=%f\n", da); - fa = 123; - printf("fa=%f\n", fa); - a = 4000000000; - da = a; - printf("da = %f\n", da); - b = 4000000000; - db = b; - printf("db = %f\n", db); -#endif -} - -int fib(int n) -{ - if (n <= 2) - return 1; - else - return fib(n-1) + fib(n-2); -} - -void funcptr_test() -{ - void (*func)(int); - int a; - struct { - int dummy; - void (*func)(int); - } st1; - long diff; - - printf("funcptr:\n"); - func = # - (*func)(12345); - func = num; - a = 1; - a = 1; - func(12345); - /* more complicated pointer computation */ - st1.func = num; - st1.func(12346); - printf("sizeof1 = %d\n", sizeof(funcptr_test)); - printf("sizeof2 = %d\n", sizeof funcptr_test); - printf("sizeof3 = %d\n", sizeof(&funcptr_test)); - printf("sizeof4 = %d\n", sizeof &funcptr_test); - a = 0; - func = num + a; - diff = func - num; - func(42); - (func + diff)(42); - (num + a)(43); -} - -void lloptest(long long a, long long b) -{ - unsigned long long ua, ub; - - ua = a; - ub = b; - /* arith */ - printf("arith: " LONG_LONG_FORMAT " " LONG_LONG_FORMAT " " LONG_LONG_FORMAT "\n", - a + b, - a - b, - a * b); - - if (b != 0) { - printf("arith1: " LONG_LONG_FORMAT " " LONG_LONG_FORMAT "\n", - a / b, - a % b); - } - - /* binary */ - printf("bin: " LONG_LONG_FORMAT " " LONG_LONG_FORMAT " " LONG_LONG_FORMAT "\n", - a & b, - a | b, - a ^ b); - - /* tests */ - printf("test: %d %d %d %d %d %d\n", - a == b, - a != b, - a < b, - a > b, - a >= b, - a <= b); - - printf("utest: %d %d %d %d %d %d\n", - ua == ub, - ua != ub, - ua < ub, - ua > ub, - ua >= ub, - ua <= ub); - - /* arith2 */ - a++; - b++; - printf("arith2: " LONG_LONG_FORMAT " " LONG_LONG_FORMAT "\n", a, b); - printf("arith2: " LONG_LONG_FORMAT " " LONG_LONG_FORMAT "\n", a++, b++); - printf("arith2: " LONG_LONG_FORMAT " " LONG_LONG_FORMAT "\n", --a, --b); - printf("arith2: " LONG_LONG_FORMAT " " LONG_LONG_FORMAT "\n", a, b); - b = ub = 0; - printf("not: %d %d %d %d\n", !a, !ua, !b, !ub); -} - -void llshift(long long a, int b) -{ - printf("shift: " LONG_LONG_FORMAT " " LONG_LONG_FORMAT " " LONG_LONG_FORMAT "\n", - (unsigned long long)a >> b, - a >> b, - a << b); - printf("shiftc: " LONG_LONG_FORMAT " " LONG_LONG_FORMAT " " LONG_LONG_FORMAT "\n", - (unsigned long long)a >> 3, - a >> 3, - a << 3); - printf("shiftc: " LONG_LONG_FORMAT " " LONG_LONG_FORMAT " " LONG_LONG_FORMAT "\n", - (unsigned long long)a >> 35, - a >> 35, - a << 35); -} - -void llfloat(void) -{ - float fa; - double da; - LONG_DOUBLE lda; - long long la, lb, lc; - unsigned long long ula, ulb, ulc; - la = 0x12345678; - ula = 0x72345678; - la = (la << 20) | 0x12345; - ula = ula << 33; - printf("la=" LONG_LONG_FORMAT " ula=" ULONG_LONG_FORMAT "\n", la, ula); - - fa = la; - da = la; - lda = la; - printf("lltof: %f %f %Lf\n", fa, da, lda); - - la = fa; - lb = da; - lc = lda; - printf("ftoll: " LONG_LONG_FORMAT " " LONG_LONG_FORMAT " " LONG_LONG_FORMAT "\n", la, lb, lc); - - fa = ula; - da = ula; - lda = ula; - printf("ulltof: %f %f %Lf\n", fa, da, lda); - - ula = fa; - ulb = da; - ulc = lda; - printf("ftoull: " ULONG_LONG_FORMAT " " ULONG_LONG_FORMAT " " ULONG_LONG_FORMAT "\n", ula, ulb, ulc); -} - -long long llfunc1(int a) -{ - return a * 2; -} - -struct S { - int id; - char item; -}; - -long long int value(struct S *v) -{ - return ((long long int)v->item); -} - -long long llfunc2(long long x, long long y, int z) -{ - return x * y * z; -} - -void longlong_test(void) -{ - long long a, b, c; - int ia; - unsigned int ua; - printf("longlong_test:\n"); - printf("sizeof(long long) = %d\n", sizeof(long long)); - ia = -1; - ua = -2; - a = ia; - b = ua; - printf(LONG_LONG_FORMAT " " LONG_LONG_FORMAT "\n", a, b); - printf(LONG_LONG_FORMAT " " LONG_LONG_FORMAT " " LONG_LONG_FORMAT " %Lx\n", - (long long)1, - (long long)-2, - 1LL, - 0x1234567812345679); - a = llfunc1(-3); - printf(LONG_LONG_FORMAT "\n", a); - - lloptest(1000, 23); - lloptest(0xff, 0x1234); - b = 0x72345678 << 10; - lloptest(-3, b); - llshift(0x123, 5); - llshift(-23, 5); - b = 0x72345678LL << 10; - llshift(b, 47); - - llfloat(); -#if 1 - b = 0x12345678; - a = -1; - c = a + b; - printf("%Lx\n", c); -#endif - - /* long long reg spill test */ - { - struct S a; - - a.item = 3; - printf("%lld\n", value(&a)); - } - lloptest(0x80000000, 0); - - { - long long *p, v, **pp; - v = 1; - p = &v; - p[0]++; - printf("another long long spill test : %lld\n", *p); - pp = &p; - - v = llfunc2(**pp, **pp, ia); - printf("a long long function (arm-)reg-args test : %lld\n", v); - } - a = 68719476720LL; - b = 4294967295LL; - printf("%d %d %d %d\n", a > b, a < b, a >= b, a <= b); - - printf(LONG_LONG_FORMAT "\n", 0x123456789LLU); - - /* long long pointer deref in argument passing test */ - a = 0x123; - long long *p = &a; - llshift(*p, 5); -} - -void manyarg_test(void) -{ - LONG_DOUBLE ld = 1234567891234LL; - printf("manyarg_test:\n"); - printf("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f\n", - 1, 2, 3, 4, 5, 6, 7, 8, - 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0); - printf("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f " - LONG_LONG_FORMAT " " LONG_LONG_FORMAT " %f %f\n", - 1, 2, 3, 4, 5, 6, 7, 8, - 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0, - 1234567891234LL, 987654321986LL, - 42.0, 43.0); - printf("%Lf %d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f " - LONG_LONG_FORMAT " " LONG_LONG_FORMAT " %f %f\n", - ld, 1, 2, 3, 4, 5, 6, 7, 8, - 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0, - 1234567891234LL, 987654321986LL, - 42.0, 43.0); - printf("%d %d %d %d %d %d %d %d %Lf\n", - 1, 2, 3, 4, 5, 6, 7, 8, ld); - printf("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f " - LONG_LONG_FORMAT " " LONG_LONG_FORMAT "%f %f %Lf\n", - 1, 2, 3, 4, 5, 6, 7, 8, - 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0, - 1234567891234LL, 987654321986LL, - 42.0, 43.0, ld); - printf("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f " - "%Lf " LONG_LONG_FORMAT " " LONG_LONG_FORMAT " %f %f %Lf\n", - 1, 2, 3, 4, 5, 6, 7, 8, - 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0, - ld, 1234567891234LL, 987654321986LL, - 42.0, 43.0, ld); -} - -void vprintf1(const char *fmt, ...) -{ - va_list ap, aq; - const char *p; - int c, i; - double d; - long long ll; - LONG_DOUBLE ld; - - va_start(aq, fmt); - va_copy(ap, aq); - - p = fmt; - for(;;) { - c = *p; - if (c == '\0') - break; - p++; - if (c == '%') { - c = *p; - switch(c) { - case '\0': - goto the_end; - case 'd': - i = va_arg(ap, int); - printf("%d", i); - break; - case 'f': - d = va_arg(ap, double); - printf("%f", d); - break; - case 'l': - ll = va_arg(ap, long long); - printf(LONG_LONG_FORMAT, ll); - break; - case 'F': - ld = va_arg(ap, LONG_DOUBLE); - printf("%Lf", ld); - break; - } - p++; - } else { - putchar(c); - } - } - the_end: - va_end(aq); - va_end(ap); -} - -struct myspace { - short int profile; -}; - -void stdarg_for_struct(struct myspace bob, ...) -{ - struct myspace george, bill; - va_list ap; - short int validate; - - va_start(ap, bob); - bill = va_arg(ap, struct myspace); - george = va_arg(ap, struct myspace); - validate = va_arg(ap, int); - printf("stdarg_for_struct: %d %d %d %d\n", - bob.profile, bill.profile, george.profile, validate); - va_end(ap); -} - -void stdarg_for_libc(const char *fmt, ...) -{ - va_list args; - va_start(args, fmt); - vprintf(fmt, args); - va_end(args); -} - -void stdarg_test(void) -{ - LONG_DOUBLE ld = 1234567891234LL; - struct myspace bob; - - vprintf1("%d %d %d\n", 1, 2, 3); - vprintf1("%f %d %f\n", 1.0, 2, 3.0); - vprintf1("%l %l %d %f\n", 1234567891234LL, 987654321986LL, 3, 1234.0); - vprintf1("%F %F %F\n", LONG_DOUBLE_LITERAL(1.2), LONG_DOUBLE_LITERAL(2.3), LONG_DOUBLE_LITERAL(3.4)); - vprintf1("%d %f %l %F %d %f %l %F\n", - 1, 1.2, 3LL, LONG_DOUBLE_LITERAL(4.5), 6, 7.8, 9LL, LONG_DOUBLE_LITERAL(0.1)); - vprintf1("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f\n", - 1, 2, 3, 4, 5, 6, 7, 8, - 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8); - vprintf1("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f\n", - 1, 2, 3, 4, 5, 6, 7, 8, - 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0); - vprintf1("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f " - "%l %l %f %f\n", - 1, 2, 3, 4, 5, 6, 7, 8, - 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0, - 1234567891234LL, 987654321986LL, - 42.0, 43.0); - vprintf1("%F %d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f " - "%l %l %f %f\n", - ld, 1, 2, 3, 4, 5, 6, 7, 8, - 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0, - 1234567891234LL, 987654321986LL, - 42.0, 43.0); - vprintf1("%d %d %d %d %d %d %d %d %F\n", - 1, 2, 3, 4, 5, 6, 7, 8, ld); - vprintf1("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f " - "%l %l %f %f %F\n", - 1, 2, 3, 4, 5, 6, 7, 8, - 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0, - 1234567891234LL, 987654321986LL, - 42.0, 43.0, ld); - vprintf1("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f " - "%F %l %l %f %f %F\n", - 1, 2, 3, 4, 5, 6, 7, 8, - 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0, - ld, 1234567891234LL, 987654321986LL, - 42.0, 43.0, ld); - - bob.profile = 42; - stdarg_for_struct(bob, bob, bob, bob.profile); - stdarg_for_libc("stdarg_for_libc: %s %.2f %d\n", "string", 1.23, 456); -} - -void whitespace_test(void) -{ - char *str; - - #if 1 - pri\ -ntf("whitspace:\n"); -#endif - pf("N=%d\n", 2); - -#ifdef CORRECT_CR_HANDLING - pri\ -ntf("aaa=%d\n", 3); -#endif - - pri\ -\ -ntf("min=%d\n", 4); - -#ifdef ACCEPT_CR_IN_STRINGS - printf("len1=%d\n", strlen(" -")); -#ifdef CORRECT_CR_HANDLING - str = " -"; - printf("len1=%d str[0]=%d\n", strlen(str), str[0]); -#endif - printf("len1=%d\n", strlen(" a -")); -#endif /* ACCEPT_CR_IN_STRINGS */ -} - -int reltab[3] = { 1, 2, 3 }; - -int *rel1 = &reltab[1]; -int *rel2 = &reltab[2]; - -#ifdef _WIN64 -void relocation_test(void) {} -#else -void getmyaddress(void) -{ - printf("in getmyaddress\n"); -} - -#ifdef __LP64__ -long __pa_symbol(void) -{ - /* This 64bit constant was handled incorrectly, it was used as addend - (which can hold 64bit just fine) in connection with a symbol, - and TCC generates wrong code for that (displacements are 32bit only). - This effectively is "+ 0x80000000", and if addresses of globals - are below 2GB the result should be a number without high 32 bits set. */ - return ((long)(((unsigned long)(&rel1))) - (0xffffffff80000000UL)); -} -#endif - -unsigned long theaddress = (unsigned long)getmyaddress; -void relocation_test(void) -{ - void (*fptr)(void) = (void (*)(void))theaddress; - printf("*rel1=%d\n", *rel1); - printf("*rel2=%d\n", *rel2); - fptr(); -#ifdef __LP64__ - printf("pa_symbol=0x%lx\n", __pa_symbol() >> 63); -#endif -} -#endif - -void old_style_f(a,b,c) - int a, b; - double c; -{ - printf("a=%d b=%d b=%f\n", a, b, c); -} - -void decl_func1(int cmpfn()) -{ - printf("cmpfn=%lx\n", (long)cmpfn); -} - -void decl_func2(cmpfn) -int cmpfn(); -{ - printf("cmpfn=%lx\n", (long)cmpfn); -} - -void old_style_function(void) -{ - old_style_f((void *)1, 2, 3.0); - decl_func1(NULL); - decl_func2(NULL); -} - -void alloca_test() -{ -#if defined __i386__ || defined __x86_64__ || defined __arm__ - char *p = alloca(16); - strcpy(p,"123456789012345"); - printf("alloca: p is %s\n", p); - char *demo = "This is only a test.\n"; - /* Test alloca embedded in a larger expression */ - printf("alloca: %s\n", strcpy(alloca(strlen(demo)+1),demo) ); -#endif -} - -void *bounds_checking_is_enabled() -{ - char ca[10], *cp = ca-1; - return (ca != cp + 1) ? cp : NULL; -} - -typedef int constant_negative_array_size_as_compile_time_assertion_idiom[(1 ? 2 : 0) - 1]; - -void c99_vla_test(int size1, int size2) -{ -#if defined __i386__ || defined __x86_64__ - int size = size1 * size2; - int tab1[size][2], tab2[10][2]; - void *tab1_ptr, *tab2_ptr, *bad_ptr; - - /* "size" should have been 'captured' at tab1 declaration, - so modifying it should have no effect on VLA behaviour. */ - size = size-1; - - printf("Test C99 VLA 1 (sizeof): "); - printf("%s\n", (sizeof tab1 == size1 * size2 * 2 * sizeof(int)) ? "PASSED" : "FAILED"); - tab1_ptr = tab1; - tab2_ptr = tab2; - printf("Test C99 VLA 2 (ptrs subtract): "); - printf("%s\n", (tab2 - tab1 == (tab2_ptr - tab1_ptr) / (sizeof(int) * 2)) ? "PASSED" : "FAILED"); - printf("Test C99 VLA 3 (ptr add): "); - printf("%s\n", &tab1[5][1] == (tab1_ptr + (5 * 2 + 1) * sizeof(int)) ? "PASSED" : "FAILED"); - printf("Test C99 VLA 4 (ptr access): "); - tab1[size1][1] = 42; - printf("%s\n", (*((int *) (tab1_ptr + (size1 * 2 + 1) * sizeof(int))) == 42) ? "PASSED" : "FAILED"); - - printf("Test C99 VLA 5 (bounds checking (might be disabled)): "); - if (bad_ptr = bounds_checking_is_enabled()) { - int *t1 = &tab1[size1 * size2 - 1][3]; - int *t2 = &tab2[9][3]; - printf("%s ", bad_ptr == t1 ? "PASSED" : "FAILED"); - printf("%s ", bad_ptr == t2 ? "PASSED" : "FAILED"); - - char*c1 = 1 + sizeof(tab1) + (char*)tab1; - char*c2 = 1 + sizeof(tab2) + (char*)tab2; - printf("%s ", bad_ptr == c1 ? "PASSED" : "FAILED"); - printf("%s ", bad_ptr == c2 ? "PASSED" : "FAILED"); - - int *i1 = tab1[-1]; - int *i2 = tab2[-1]; - printf("%s ", bad_ptr == i1 ? "PASSED" : "FAILED"); - printf("%s ", bad_ptr == i2 ? "PASSED" : "FAILED"); - - int *x1 = tab1[size1 * size2 + 1]; - int *x2 = tab2[10 + 1]; - printf("%s ", bad_ptr == x1 ? "PASSED" : "FAILED"); - printf("%s ", bad_ptr == x2 ? "PASSED" : "FAILED"); - } else { - printf("PASSED PASSED PASSED PASSED PASSED PASSED PASSED PASSED "); - } - printf("\n"); -#endif -} - -#ifndef __TINYC__ -typedef __SIZE_TYPE__ uintptr_t; -#endif - -void sizeof_test(void) -{ - int a; - int **ptr; - - printf("sizeof(int) = %d\n", sizeof(int)); - printf("sizeof(unsigned int) = %d\n", sizeof(unsigned int)); - printf("sizeof(long) = %d\n", sizeof(long)); - printf("sizeof(unsigned long) = %d\n", sizeof(unsigned long)); - printf("sizeof(short) = %d\n", sizeof(short)); - printf("sizeof(unsigned short) = %d\n", sizeof(unsigned short)); - printf("sizeof(char) = %d\n", sizeof(char)); - printf("sizeof(unsigned char) = %d\n", sizeof(unsigned char)); - printf("sizeof(func) = %d\n", sizeof sizeof_test()); - a = 1; - printf("sizeof(a++) = %d\n", sizeof a++); - printf("a=%d\n", a); - ptr = NULL; - printf("sizeof(**ptr) = %d\n", sizeof (**ptr)); - - /* The type of sizeof should be as large as a pointer, actually - it should be size_t. */ - printf("sizeof(sizeof(int) = %d\n", sizeof(sizeof(int))); - uintptr_t t = 1; - uintptr_t t2; - /* Effectively <<32, but defined also on 32bit machines. */ - t <<= 16; - t <<= 16; - t++; - /* This checks that sizeof really can be used to manipulate - uintptr_t objects, without truncation. */ - t2 = t & -sizeof(uintptr_t); - printf ("%lu %lu\n", t, t2); - - /* some alignof tests */ - printf("__alignof__(int) = %d\n", __alignof__(int)); - printf("__alignof__(unsigned int) = %d\n", __alignof__(unsigned int)); - printf("__alignof__(short) = %d\n", __alignof__(short)); - printf("__alignof__(unsigned short) = %d\n", __alignof__(unsigned short)); - printf("__alignof__(char) = %d\n", __alignof__(char)); - printf("__alignof__(unsigned char) = %d\n", __alignof__(unsigned char)); - printf("__alignof__(func) = %d\n", __alignof__ sizeof_test()); - - /* sizes of VLAs need to be evaluated even inside sizeof: */ - a = 2; - printf("sizeof(char[1+2*a]) = %d\n", sizeof(char[1+2*a])); - /* And checking if sizeof compound literal works. Parenthesized: */ - printf("sizeof( (struct {int i; int j;}){4,5} ) = %d\n", - sizeof( (struct {int i; int j;}){4,5} )); - /* And as direct sizeof argument (as unary expression): */ - printf("sizeof (struct {short i; short j;}){4,5} = %d\n", - sizeof (struct {short i; short j;}){4,5} ); - - /* sizeof(x && y) should be sizeof(int), even if constant - evaluating is possible. */ - printf("sizeof(t && 0) = %d\n", sizeof(t && 0)); - printf("sizeof(1 && 1) = %d\n", sizeof(1 && 1)); - printf("sizeof(t || 1) = %d\n", sizeof(t || 1)); - printf("sizeof(0 || 0) = %d\n", sizeof(0 || 0)); -} - -void typeof_test(void) -{ - double a; - typeof(a) b; - typeof(float) c; - - a = 1.5; - b = 2.5; - c = 3.5; - printf("a=%f b=%f c=%f\n", a, b, c); -} - - -struct hlist_node; -struct hlist_head { - struct hlist_node *first, *last; -}; - -void consume_ulong (unsigned long i) -{ - i = 0; -} - -void statement_expr_test(void) -{ - int a, i; - - /* Basic stmt expr test */ - a = 0; - for(i=0;i<10;i++) { - a += 1 + - ( { int b, j; - b = 0; - for(j=0;j<5;j++) - b += j; b; - } ); - } - printf("a=%d\n", a); - - /* Test that symbols aren't freed prematurely. - With SYM_DEBUG valgrind will show a read from a freed - symbol, and tcc will show an (invalid) warning on the initialization - of 'ptr' below, if symbols are popped after the stmt expr. */ - void *v = (void*)39; - typeof(({ - (struct hlist_node *)v; - })) x; - typeof (x) - ptr = (struct hlist_node *)v; - - /* This part used to segfault when symbols were popped prematurely. - The symbols for the static local would be overwritten with - helper symbols from the pre-processor expansions in between. */ -#define some_attr __attribute__((aligned(1))) -#define tps(str) ({ \ - static const char *t some_attr = str; \ - t; \ - }) - printf ("stmtexpr: %s %s\n", - tps("somerandomlongstring"), - tps("anotherlongstring")); - - /* Test that the three decls of 't' don't interact. */ - int t = 40; - int b = ({ int t = 41; t; }); - int c = ({ int t = 42; t; }); - - /* Test that aggregate return values work. */ - struct hlist_head h - = ({ - typedef struct hlist_head T; - long pre = 48; - T t = { (void*)43, (void*)44 }; - long post = 49; - t; - }); - printf ("stmtexpr: %d %d %d\n", t, b, c); - printf ("stmtexpr: %ld %ld\n", (long)h.first, (long)h.last); - - /* Test that we can give out addresses of local labels. */ - consume_ulong(({ __label__ __here; __here: (unsigned long)&&__here; })); -} - -void local_label_test(void) -{ - int a; - goto l1; - l2: - a = 1 + ({ - __label__ l1, l2, l3, l4; - goto l1; - l4: - printf("aa1\n"); - goto l3; - l2: - printf("aa3\n"); - goto l4; - l1: - printf("aa2\n"); - goto l2; - l3:; - 1; - }); - printf("a=%d\n", a); - return; - l4: - printf("bb1\n"); - goto l2; - l1: - printf("bb2\n"); - goto l4; -} - -/* inline assembler test */ -#if defined(__i386__) || defined(__x86_64__) - -/* from linux kernel */ -static char * strncat1(char * dest,const char * src,size_t count) -{ -long d0, d1, d2, d3; -__asm__ __volatile__( - "repne\n\t" - "scasb\n\t" - "dec %1\n\t" - "mov %8,%3\n" - "1:\tdec %3\n\t" - "js 2f\n\t" - "lodsb\n\t" - "stosb\n\t" - "testb %%al,%%al\n\t" - "jne 1b\n" - "2:\txor %2,%2\n\t" - "stosb" - : "=&S" (d0), "=&D" (d1), "=&a" (d2), "=&c" (d3) - : "0" (src),"1" (dest),"2" (0),"3" (0xffffffff), "g" (count) - : "memory"); -return dest; -} - -static char * strncat2(char * dest,const char * src,size_t count) -{ -long d0, d1, d2, d3; -__asm__ __volatile__( - "repne scasb\n\t" /* one-line repne prefix + string op */ - "dec %1\n\t" - "mov %8,%3\n" - "1:\tdec %3\n\t" - "js 2f\n\t" - "lodsb\n\t" - "stosb\n\t" - "testb %%al,%%al\n\t" - "jne 1b\n" - "2:\txor %2,%2\n\t" - "stosb" - : "=&S" (d0), "=&D" (d1), "=&a" (d2), "=&c" (d3) - : "0" (src),"1" (dest),"2" (0),"3" (0xffffffff), "g" (count) - : "memory"); -return dest; -} - -static inline void * memcpy1(void * to, const void * from, size_t n) -{ -long d0, d1, d2; -__asm__ __volatile__( - "rep ; movsl\n\t" - "testb $2,%b4\n\t" - "je 1f\n\t" - "movsw\n" - "1:\ttestb $1,%b4\n\t" - "je 2f\n\t" - "movsb\n" - "2:" - : "=&c" (d0), "=&D" (d1), "=&S" (d2) - :"0" (n/4), "q" (n),"1" ((long) to),"2" ((long) from) - : "memory"); -return (to); -} - -static inline void * memcpy2(void * to, const void * from, size_t n) -{ -long d0, d1, d2; -__asm__ __volatile__( - "rep movsl\n\t" /* one-line rep prefix + string op */ - "testb $2,%b4\n\t" - "je 1f\n\t" - "movsw\n" - "1:\ttestb $1,%b4\n\t" - "je 2f\n\t" - "movsb\n" - "2:" - : "=&c" (d0), "=&D" (d1), "=&S" (d2) - :"0" (n/4), "q" (n),"1" ((long) to),"2" ((long) from) - : "memory"); -return (to); -} - -static __inline__ void sigaddset1(unsigned int *set, int _sig) -{ - __asm__("btsl %1,%0" : "=m"(*set) : "Ir"(_sig - 1) : "cc"); -} - -static __inline__ void sigdelset1(unsigned int *set, int _sig) -{ - asm("btrl %1,%0" : "=m"(*set) : "Ir"(_sig - 1) : "cc", "flags"); -} - -static __inline__ __const__ unsigned int swab32(unsigned int x) -{ - __asm__("xchgb %b0,%h0\n\t" /* swap lower bytes */ - "rorl $16,%0\n\t" /* swap words */ - "xchgb %b0,%h0" /* swap higher bytes */ - :"=" "q" (x) - : "0" (x)); - return x; -} - -static __inline__ unsigned long long mul64(unsigned int a, unsigned int b) -{ - unsigned long long res; -#ifdef __x86_64__ - /* Using the A constraint is wrong (it means rdx:rax, which is too large) - but still test the 32bit->64bit mull. */ - unsigned int resh, resl; - __asm__("mull %2" : "=a" (resl), "=d" (resh) : "a" (a), "r" (b)); - res = ((unsigned long long)resh << 32) | resl; -#else - __asm__("mull %2" : "=A" (res) : "a" (a), "r" (b)); -#endif - return res; -} - -static __inline__ unsigned long long inc64(unsigned long long a) -{ - unsigned long long res; -#ifdef __x86_64__ - /* Using the A constraint is wrong, and increments are tested - elsewhere. */ - res = a + 1; -#else - __asm__("addl $1, %%eax ; adcl $0, %%edx" : "=A" (res) : "A" (a)); -#endif - return res; -} - -struct struct123 { - int a; - int b; -}; -struct struct1231 { - unsigned long addr; -}; - -unsigned long mconstraint_test(struct struct1231 *r) -{ - unsigned long ret; - unsigned int a[2]; - a[0] = 0; - __asm__ volatile ("lea %2,%0; movl 4(%0),%k0; addl %2,%k0; movl $51,%2; movl $52,4%2; movl $63,%1" - : "=&r" (ret), "=m" (a) - : "m" (*(struct struct123 *)r->addr)); - return ret + a[0]; -} - -#ifdef __x86_64__ -int fls64(unsigned long long x) -{ - int bitpos = -1; - asm("bsrq %1,%q0" - : "+r" (bitpos) - : "rm" (x)); - return bitpos + 1; -} -#endif - -void other_constraints_test(void) -{ - unsigned long ret; - int var; -#ifndef _WIN64 - __asm__ volatile ("mov %P1,%0" : "=r" (ret) : "p" (&var)); - printf ("oc1: %d\n", ret == (unsigned long)&var); -#endif -} - -#ifndef _WIN32 -/* Test global asm blocks playing with aliases. */ -void base_func(void) -{ - printf ("asmc: base\n"); -} - -extern void override_func1 (void); -extern void override_func2 (void); - -asm(".weak override_func1\n.set override_func1, base_func"); -asm(".set override_func1, base_func"); -asm(".set override_func2, base_func"); - -void override_func2 (void) -{ - printf ("asmc: override2\n"); -} - -/* This checks a construct used by the linux kernel to encode - references to strings by PC relative references. */ -extern int bug_table[] __attribute__((section("__bug_table"))); -char * get_asm_string (void) -{ - extern int some_symbol; - asm volatile (".globl some_symbol\n" - "jmp .+6\n" - "1:\n" - "some_symbol: .long 0\n" - ".pushsection __bug_table, \"a\"\n" - ".globl bug_table\n" - "bug_table:\n" - /* The first entry (1b-2b) is unused in this test, - but we include it to check if cross-section - PC-relative references work. */ - "2:\t.long 1b - 2b, %c0 - 2b\n" - ".popsection\n" : : "i" ("A string")); - char * str = ((char*)bug_table) + bug_table[1]; - return str; -} - -/* This checks another constructs with local labels. */ -extern unsigned char alld_stuff[]; -asm(".data\n" - ".byte 41\n" - "alld_stuff:\n" - "661:\n" - ".byte 42\n" - "662:\n" - ".pushsection .data.ignore\n" - ".long 661b - .\n" /* This reference to 661 generates an external sym - which shouldn't somehow overwrite the offset that's - already determined for it. */ - ".popsection\n" - ".byte 662b - 661b\n" /* So that this value is undeniably 1. */); - -void asm_local_label_diff (void) -{ - printf ("asm_local_label_diff: %d %d\n", alld_stuff[0], alld_stuff[1]); -} - -/* This checks that static local variables are available from assembler. */ -void asm_local_statics (void) -{ - static int localint = 41; - asm("incl %0" : "+m" (localint)); - printf ("asm_local_statics: %d\n", localint); -} -#endif - -static -unsigned int set; - -void fancy_copy (unsigned *in, unsigned *out) -{ - asm volatile ("" : "=r" (*out) : "0" (*in)); -} - -void fancy_copy2 (unsigned *in, unsigned *out) -{ - asm volatile ("mov %0,(%1)" : : "r" (*in), "r" (out) : "memory"); -} - -#if defined __x86_64__ && !defined _WIN64 -void clobber_r12(void) -{ - asm volatile("mov $1, %%r12" ::: "r12"); -} -#endif - -void test_high_clobbers(void) -{ -#if defined __x86_64__ && !defined _WIN64 - register long val asm("r12"); - long val2; - /* This tests if asm clobbers correctly save/restore callee saved - registers if they are clobbered and if it's the high 8 x86-64 - registers. This is fragile for GCC as the constraints do not - correctly capture the data flow, but good enough for us. */ - asm volatile("mov $0x4542, %%r12" : "=r" (val):: "memory"); - clobber_r12(); - asm volatile("mov %%r12, %0" : "=r" (val2) : "r" (val): "memory"); - printf("asmhc: 0x%x\n", val2); -#endif -} - -static long cpu_number; -void trace_console(long len, long len2) -{ -#ifdef __x86_64__ - /* This generated invalid code when the emission of the switch - table isn't disabled. The asms are necessary to show the bug, - normal statements don't work (they need to generate some code - even under nocode_wanted, which normal statements don't do, - but asms do). Also at least these number of cases is necessary - to generate enough "random" bytes. They ultimately are enough - to create invalid instruction patterns to which the first - skip-to-decision-table jump jumps. If decision table emission - is disabled all of this is no problem. - - It also is necessary that the switches are in a statement expression - (which has the property of not being enterable from outside. no - matter what). */ - if (0 - && - ({ - long pscr_ret__; - switch(len) { - case 4: - { - long pfo_ret__; - switch (len2) { - case 8: printf("bla"); pfo_ret__ = 42; break; - } - pscr_ret__ = pfo_ret__; - } - break; - case 8: - { - long pfo_ret__; - switch (len2) { - case 1:asm("movq %1,%0": "=r" (pfo_ret__) : "m" (cpu_number)); break; - case 2:asm("movq %1,%0": "=r" (pfo_ret__) : "m" (cpu_number)); break; - case 4:asm("movq %1,%0": "=r" (pfo_ret__) : "m" (cpu_number)); break; - case 8:asm("movq %1,%0": "=r" (pfo_ret__) : "m" (cpu_number)); break; - default: printf("impossible\n"); - } - pscr_ret__ = pfo_ret__; - }; - break; - } - pscr_ret__; - })) - { - printf("huh?\n"); - } -#endif -} - -void test_asm_dead_code(void) -{ - long rdi; - /* Try to make sure that xdi contains a zero, and hence will - lead to a segfault if the next asm is evaluated without - arguments being set up. */ - asm volatile ("" : "=D" (rdi) : "0" (0)); - (void)sizeof (({ - int var; - /* This shouldn't trigger a segfault, either the argument - registers need to be set up and the asm emitted despite - this being in an unevaluated context, or both the argument - setup _and_ the asm emission need to be suppressed. The latter - is better. Disabling asm code gen when suppression is on - also fixes the above trace_console bug, but that came earlier - than asm suppression. */ - asm volatile ("movl $0,(%0)" : : "D" (&var) : "memory"); - var; - })); -} - -void test_asm_call(void) -{ -#if defined __x86_64__ && !defined _WIN64 - static char str[] = "PATH"; - char *s; - /* This tests if a reference to an undefined symbol from an asm - block, which isn't otherwise referenced in this file, is correctly - regarded as global symbol, so that it's resolved by other object files - or libraries. We chose getenv here, which isn't used anywhere else - in this file. (If we used e.g. printf, which is used we already - would have a global symbol entry, not triggering the bug which is - tested here). */ - /* two pushes so stack remains aligned */ - asm volatile ("push %%rdi; push %%rdi; mov %0, %%rdi;" -#if 1 && !defined(__TINYC__) && (defined(__PIC__) || defined(__PIE__)) - "call getenv@plt;" -#else - "call getenv;" -#endif - "pop %%rdi; pop %%rdi" - : "=a" (s) : "r" (str)); - printf("asmd: %s\n", s); -#endif -} - -#if defined __x86_64__ -# define RX "(%rip)" -#else -# define RX -#endif - -void asm_dot_test(void) -{ - int x; - for (x = 1;; ++x) { - int r = x; - switch (x) { - case 1: - asm(".text; lea S"RX",%eax; lea ."RX",%ecx; sub %ecx,%eax; S=.; jmp p0"); - case 2: - asm(".text; jmp .+6; .int 123; mov .-4"RX",%eax; jmp p0"); - case 3: - asm(".data; Y=.; .int 999; X=Y; .int 456; X=.-4"); - asm(".text; mov X"RX",%eax; jmp p0"); - case 4: - asm(".data; X=.; .int 789; Y=.; .int 999"); - asm(".text; mov X"RX",%eax; X=Y; jmp p0"); - case 0: - asm(".text; p0=.; mov %%eax,%0;" : "=m"(r)); break; - } - if (r == x) - break; - printf("asm_dot_test %d: %d\n", x, r); - } -} - -void asm_test(void) -{ - char buf[128]; - unsigned int val, val2; - struct struct123 s1; - struct struct1231 s2 = { (unsigned long)&s1 }; - /* Hide the outer base_func, but check later that the inline - asm block gets the outer one. */ - int base_func = 42; - void override_func3 (void); - unsigned long asmret; -#ifdef BOOL_ISOC99 - _Bool somebool; -#endif - register int regvar asm("%esi"); - - printf("inline asm:\n"); - - // parse 0x1E-1 as 3 tokens in asm mode - asm volatile ("mov $0x1E-1,%eax"); - - /* test the no operand case */ - asm volatile ("xorl %eax, %eax"); - - memcpy1(buf, "hello", 6); - strncat1(buf, " worldXXXXX", 3); - printf("%s\n", buf); - - memcpy2(buf, "hello", 6); - strncat2(buf, " worldXXXXX", 3); - printf("%s\n", buf); - - /* 'A' constraint test */ - printf("mul64=0x%Lx\n", mul64(0x12345678, 0xabcd1234)); - printf("inc64=0x%Lx\n", inc64(0x12345678ffffffff)); - - s1.a = 42; - s1.b = 43; - printf("mconstraint: %d", mconstraint_test(&s2)); - printf(" %d %d\n", s1.a, s1.b); - other_constraints_test(); - set = 0xff; - sigdelset1(&set, 2); - sigaddset1(&set, 16); - /* NOTE: we test here if C labels are correctly restored after the - asm statement */ - goto label1; - label2: - __asm__("btsl %1,%0" : "=m"(set) : "Ir"(20) : "cc"); - printf("set=0x%x\n", set); - val = 0x01020304; - printf("swab32(0x%08x) = 0x%0x\n", val, swab32(val)); -#ifndef _WIN32 - override_func1(); - override_func2(); - /* The base_func ref from the following inline asm should find - the global one, not the local decl from this function. */ - asm volatile(".weak override_func3\n.set override_func3, base_func"); - override_func3(); - printf("asmstr: %s\n", get_asm_string()); - asm_local_label_diff(); - asm_local_statics(); -#endif - /* Check that we can also load structs of appropriate layout - into registers. */ - asm volatile("" : "=r" (asmret) : "0"(s2)); - if (asmret != s2.addr) - printf("asmstr: failed\n"); -#ifdef BOOL_ISOC99 - /* Check that the typesize correctly sets the register size to - 8 bit. */ - asm volatile("cmp %1,%2; sete %0" : "=a"(somebool) : "r"(1), "r"(2)); - if (!somebool) - printf("asmbool: failed\n"); -#endif - val = 43; - fancy_copy (&val, &val2); - printf ("fancycpy(%d)=%d\n", val, val2); - val = 44; - fancy_copy2 (&val, &val2); - printf ("fancycpy2(%d)=%d\n", val, val2); - asm volatile ("mov $0x4243, %%esi" : "=r" (regvar)); - printf ("regvar=%x\n", regvar); - test_high_clobbers(); - trace_console(8, 8); - test_asm_dead_code(); - test_asm_call(); - asm_dot_test(); - return; - label1: - goto label2; -} - -#else - -void asm_test(void) -{ -} - -#endif - -#define COMPAT_TYPE(type1, type2) \ -{\ - printf("__builtin_types_compatible_p(%s, %s) = %d\n", #type1, #type2, \ - __builtin_types_compatible_p (type1, type2));\ -} - -int constant_p_var; - -void builtin_test(void) -{ - short s; - int i; - long long ll; -#if GCC_MAJOR >= 3 - COMPAT_TYPE(int, int); - COMPAT_TYPE(int, unsigned int); - COMPAT_TYPE(int, char); - COMPAT_TYPE(int, const int); - COMPAT_TYPE(int, volatile int); - COMPAT_TYPE(int *, int *); - COMPAT_TYPE(int *, void *); - COMPAT_TYPE(int *, const int *); - COMPAT_TYPE(char *, unsigned char *); - COMPAT_TYPE(char *, signed char *); - COMPAT_TYPE(char *, char *); -/* space is needed because tcc preprocessor introduces a space between each token */ - COMPAT_TYPE(char * *, void *); -#endif - printf("res = %d\n", __builtin_constant_p(1)); - printf("res = %d\n", __builtin_constant_p(1 + 2)); - printf("res = %d\n", __builtin_constant_p(&constant_p_var)); - printf("res = %d\n", __builtin_constant_p(constant_p_var)); - printf("res = %d\n", __builtin_constant_p(100000 / constant_p_var)); - s = 1; - ll = 2; - i = __builtin_choose_expr (1 != 0, ll, s); - printf("bce: %d\n", i); - i = __builtin_choose_expr (1 != 1, ll, s); - printf("bce: %d\n", i); - i = sizeof (__builtin_choose_expr (1, ll, s)); - printf("bce: %d\n", i); - i = sizeof (__builtin_choose_expr (0, ll, s)); - printf("bce: %d\n", i); - - //printf("bera: %p\n", __builtin_extract_return_addr((void*)43)); -} - -#ifndef _WIN32 -extern int __attribute__((weak)) weak_f1(void); -extern int __attribute__((weak)) weak_f2(void); -extern int weak_f3(void); -extern int __attribute__((weak)) weak_v1; -extern int __attribute__((weak)) weak_v2; -extern int weak_v3; - -extern int (*weak_fpa)() __attribute__((weak)); -extern int __attribute__((weak)) (*weak_fpb)(); -extern __attribute__((weak)) int (*weak_fpc)(); - -extern int weak_asm_f1(void) asm("weak_asm_f1x") __attribute((weak)); -extern int __attribute((weak)) weak_asm_f2(void) asm("weak_asm_f2x") ; -extern int __attribute((weak)) weak_asm_f3(void) asm("weak_asm_f3x") __attribute((weak)); -extern int weak_asm_v1 asm("weak_asm_v1x") __attribute((weak)); -extern int __attribute((weak)) weak_asm_v2 asm("weak_asm_v2x") ; -extern int __attribute((weak)) weak_asm_v3(void) asm("weak_asm_v3x") __attribute((weak)); - -static const size_t dummy = 0; -extern __typeof(dummy) weak_dummy1 __attribute__((weak, alias("dummy"))); -extern __typeof(dummy) __attribute__((weak, alias("dummy"))) weak_dummy2; -extern __attribute__((weak, alias("dummy"))) __typeof(dummy) weak_dummy3; - -int some_lib_func(void); -int dummy_impl_of_slf(void) { return 444; } -int some_lib_func(void) __attribute__((weak, alias("dummy_impl_of_slf"))); - -int weak_toolate() __attribute__((weak)); -int weak_toolate() { return 0; } - -void __attribute__((weak)) weak_test(void) -{ - printf("weak_f1=%d\n", weak_f1 ? weak_f1() : 123); - printf("weak_f2=%d\n", weak_f2 ? weak_f2() : 123); - printf("weak_f3=%d\n", weak_f3 ? weak_f3() : 123); - printf("weak_v1=%d\n",&weak_v1 ? weak_v1 : 123); - printf("weak_v2=%d\n",&weak_v2 ? weak_v2 : 123); - printf("weak_v3=%d\n",&weak_v3 ? weak_v3 : 123); - - printf("weak_fpa=%d\n",&weak_fpa ? weak_fpa() : 123); - printf("weak_fpb=%d\n",&weak_fpb ? weak_fpb() : 123); - printf("weak_fpc=%d\n",&weak_fpc ? weak_fpc() : 123); - - printf("weak_asm_f1=%d\n", weak_asm_f1 != NULL); - printf("weak_asm_f2=%d\n", weak_asm_f2 != NULL); - printf("weak_asm_f3=%d\n", weak_asm_f3 != NULL); - printf("weak_asm_v1=%d\n",&weak_asm_v1 != NULL); - printf("weak_asm_v2=%d\n",&weak_asm_v2 != NULL); - printf("weak_asm_v3=%d\n",&weak_asm_v3 != NULL); - printf("some_lib_func=%d\n", &some_lib_func ? some_lib_func() : 0); -} - -int __attribute__((weak)) weak_f2() { return 222; } -int __attribute__((weak)) weak_f3() { return 333; } -int __attribute__((weak)) weak_v2 = 222; -int __attribute__((weak)) weak_v3 = 333; -#endif - -void const_func(const int a) -{ -} - -void const_warn_test(void) -{ - const_func(1); -} - -struct condstruct { - int i; -}; - -int getme (struct condstruct *s, int i) -{ - int i1 = (i == 0 ? 0 : s)->i; - int i2 = (i == 0 ? s : 0)->i; - int i3 = (i == 0 ? (void*)0 : s)->i; - int i4 = (i == 0 ? s : (void*)0)->i; - return i1 + i2 + i3 + i4; -} - -struct global_data -{ - int a[40]; - int *b[40]; -}; - -struct global_data global_data; - -int global_data_getstuff (int *, int); - -void global_data_callit (int i) -{ - *global_data.b[i] = global_data_getstuff (global_data.b[i], 1); -} - -int global_data_getstuff (int *p, int i) -{ - return *p + i; -} - -void global_data_test (void) -{ - global_data.a[0] = 42; - global_data.b[0] = &global_data.a[0]; - global_data_callit (0); - printf ("%d\n", global_data.a[0]); -} - -struct cmpcmpS -{ - unsigned char fill : 3; - unsigned char b1 : 1; - unsigned char b2 : 1; - unsigned char fill2 : 3; -}; - -int glob1, glob2, glob3; - -void compare_comparisons (struct cmpcmpS *s) -{ - if (s->b1 != (glob1 == glob2) - || (s->b2 != (glob1 == glob3))) - printf ("comparing comparisons broken\n"); -} - -void cmp_comparison_test(void) -{ - struct cmpcmpS s; - s.b1 = 1; - glob1 = 42; glob2 = 42; - s.b2 = 0; - glob3 = 43; - compare_comparisons (&s); -} - -int fcompare (double a, double b, int code) -{ - switch (code) { - case 0: return a == b; - case 1: return a != b; - case 2: return a < b; - case 3: return a >= b; - case 4: return a > b; - case 5: return a <= b; - } -} - -void math_cmp_test(void) -{ - double nan = 0.0/0.0; - double one = 1.0; - double two = 2.0; - int comp = 0; -#define bug(a,b,op,iop,part) printf("Test broken: %s %s %s %s %d\n", #a, #b, #op, #iop, part) - - /* This asserts that "a op b" is _not_ true, but "a iop b" is true. - And it does this in various ways so that all code generation paths - are checked (generating inverted tests, or non-inverted tests, or - producing a 0/1 value without jumps (that's done in the fcompare - function). */ -#define FCMP(a,b,op,iop,code) \ - if (fcompare (a,b,code)) \ - bug (a,b,op,iop,1); \ - if (a op b) \ - bug (a,b,op,iop,2); \ - if (a iop b) \ - ; \ - else \ - bug (a,b,op,iop,3); \ - if ((a op b) || comp) \ - bug (a,b,op,iop,4); \ - if ((a iop b) || comp) \ - ; \ - else \ - bug (a,b,op,iop,5); - - /* Equality tests. */ - FCMP(nan, nan, ==, !=, 0); - FCMP(one, two, ==, !=, 0); - FCMP(one, one, !=, ==, 1); - /* Non-equality is a bit special. */ - if (!fcompare (nan, nan, 1)) - bug (nan, nan, !=, ==, 6); - - /* Relational tests on numbers. */ - FCMP(two, one, <, >=, 2); - FCMP(one, two, >=, <, 3); - FCMP(one, two, >, <=, 4); - FCMP(two, one, <=, >, 5); - - /* Relational tests on NaNs. Note that the inverse op here is - always !=, there's no operator in C that is equivalent to !(a < b), - when NaNs are involved, same for the other relational ops. */ - FCMP(nan, nan, <, !=, 2); - FCMP(nan, nan, >=, !=, 3); - FCMP(nan, nan, >, !=, 4); - FCMP(nan, nan, <=, !=, 5); -} - -double get100 () { return 100.0; } - -void callsave_test(void) -{ -#if defined __i386__ || defined __x86_64__ || defined __arm__ - int i, s; double *d; double t; - s = sizeof (double); - printf ("callsavetest: %d\n", s); - d = alloca (sizeof(double)); - d[0] = 10.0; - /* x86-64 had a bug were the next call to get100 would evict - the lvalue &d[0] as VT_LLOCAL, and the reload would be done - in int type, not pointer type. When alloca returns a pointer - with the high 32 bit set (which is likely on x86-64) the access - generates a segfault. */ - i = d[0] > get100 (); - printf ("%d\n", i); -#endif -} - - -void bfa3(ptrdiff_t str_offset) -{ - printf("bfa3: %s\n", (char *)__builtin_frame_address(3) + str_offset); -} -void bfa2(ptrdiff_t str_offset) -{ - printf("bfa2: %s\n", (char *)__builtin_frame_address(2) + str_offset); - bfa3(str_offset); -} -void bfa1(ptrdiff_t str_offset) -{ - printf("bfa1: %s\n", (char *)__builtin_frame_address(1) + str_offset); - bfa2(str_offset); -} - -void builtin_frame_address_test(void) -{ -/* builtin_frame_address fails on ARM with gcc which make test3 fail */ -#ifndef __arm__ - char str[] = "__builtin_frame_address"; - char *fp0 = __builtin_frame_address(0); - - printf("str: %s\n", str); - bfa1(str-fp0); -#endif -} - -char via_volatile (char i) -{ - char volatile vi; - vi = i; - return vi; -} - -struct __attribute__((__packed__)) Spacked { - char a; - short b; - int c; -}; -struct Spacked spacked; -typedef struct __attribute__((__packed__)) { - char a; - short b; - int c; -} Spacked2; -Spacked2 spacked2; -typedef struct Spacked3_s { - char a; - short b; - int c; -} __attribute__((__packed__)) Spacked3; -Spacked3 spacked3; -struct gate_struct64 { - unsigned short offset_low; - unsigned short segment; - unsigned ist : 3, zero0 : 5, type : 5, dpl : 2, p : 1; - unsigned short offset_middle; - unsigned offset_high; - unsigned zero1; -} __attribute__((packed)); -typedef struct gate_struct64 gate_desc; -gate_desc a_gate_desc; -void attrib_test(void) -{ -#ifndef _WIN32 - printf("attr: %d %d %d %d\n", sizeof(struct Spacked), - sizeof(spacked), sizeof(Spacked2), sizeof(spacked2)); - printf("attr: %d %d\n", sizeof(Spacked3), sizeof(spacked3)); - printf("attr: %d %d\n", sizeof(gate_desc), sizeof(a_gate_desc)); -#endif -} -extern __attribute__((__unused__)) char * __attribute__((__unused__)) * -strange_attrib_placement (void); - -void * __attribute__((__unused__)) get_void_ptr (void *a) -{ - return a; -} - -/* This part checks for a bug in TOK_GET (used for inline expansion), - where the large long long constant left the the high bits set for - the integer constant token. */ -static inline -int __get_order(unsigned long long size) -{ - int order; - size -= 0xffff880000000000ULL; // this const left high bits set in the token - { - struct S { int i : 1; } s; // constructed for this '1' - } - order = size; - return order; -} - -/* This just forces the above inline function to be actually emitted. */ -int force_get_order(unsigned long s) -{ - return __get_order(s); -} diff --git a/05/tcc-final-old/tests/tcctest.h b/05/tcc-final-old/tests/tcctest.h deleted file mode 100644 index b301c7c..0000000 --- a/05/tcc-final-old/tests/tcctest.h +++ /dev/null @@ -1,9 +0,0 @@ -static inline const char *get_basefile_from_header(void) -{ - return __BASE_FILE__; -} - -static inline const char *get_file_from_header(void) -{ - return __FILE__; -} diff --git a/05/tcc-final-old/tests/testfp.c b/05/tcc-final-old/tests/testfp.c deleted file mode 100644 index 63342b4..0000000 --- a/05/tcc-final-old/tests/testfp.c +++ /dev/null @@ -1,510 +0,0 @@ -/* - * Test 128-bit floating-point arithmetic on arm64: - * build with two different compilers and compare the output. - * - * Copyright (c) 2015 Edmund Grimley Evans - * - * Copying and distribution of this file, with or without modification, - * are permitted in any medium without royalty provided the copyright - * notice and this notice are preserved. This file is offered as-is, - * without any warranty. - */ - -#include -#include -#include -#include - -#define check(x) ((x) ? (void)0 : check_fail(#x, __FILE__, __LINE__)) - -void check_fail(const char *assertion, const char *file, unsigned int line) -{ - printf("%s:%d: Check (%s) failed.", file, line, assertion); - exit(1); -} - -typedef struct { - unsigned long long x0, x1; -} u128_t; - -float copy_fi(uint32_t x) -{ - float f; - memcpy(&f, &x, 4); - return f; -} - -double copy_di(uint64_t x) -{ - double f; - memcpy(&f, &x, 8); - return f; -} - -long double copy_ldi(u128_t x) -{ - long double f; - memcpy(&f, &x, 16); - return f; -} - -uint32_t copy_if(float f) -{ - uint32_t x; - memcpy(&x, &f, 4); - return x; -} - -uint64_t copy_id(double f) -{ - uint64_t x; - memcpy(&x, &f, 8); - return x; -} - -u128_t copy_ild(long double f) -{ - u128_t x; - memcpy(&x, &f, 16); - return x; -} - -long double make(int sgn, int exp, uint64_t high, uint64_t low) -{ - u128_t x = { low, - (0x0000ffffffffffff & high) | - (0x7fff000000000000 & (uint64_t)exp << 48) | - (0x8000000000000000 & (uint64_t)sgn << 63) }; - return copy_ldi(x); -} - -void cmp(long double a, long double b) -{ - u128_t ax = copy_ild(a); - u128_t bx = copy_ild(b); - int eq = (a == b); - int ne = (a != b); - int lt = (a < b); - int le = (a <= b); - int gt = (a > b); - int ge = (a >= b); - - check(eq == 0 || eq == 1); - check(lt == 0 || lt == 1); - check(gt == 0 || gt == 1); - check(ne == !eq && le == (lt | eq) && ge == (gt | eq)); - check(eq + lt + gt < 2); - - printf("cmp %016llx%016llx %016llx%016llx %d %d %d\n", - ax.x1, ax.x0, bx.x1, bx.x0, lt, eq, gt); -} - -void cmps(void) -{ - int i, j; - - for (i = 0; i < 2; i++) - for (j = 0; j < 2; j++) - cmp(make(i, 0, 0, 0), make(j, 0, 0, 0)); - - for (i = 0; i < 2; i++) { - for (j = 0; j < 64; j++) { - long double f1 = make(i, 32767, (uint64_t)1 << j, 0); - long double f2 = make(i, 32767, 0, (uint64_t)1 << j); - cmp(f1, 0); - cmp(f2, 0); - cmp(0, f1); - cmp(0, f2); - } - } - - for (i = 0; i < 6; i++) - for (j = 0; j < 6; j++) - cmp(make(i & 1, i >> 1, 0, 0), - make(j & 1, j >> 1, 0, 0)); - - for (i = 0; i < 2; i++) { - for (j = 0; j < 2; j++) { - int a, b; - for (a = 0; a < 2; a++) { - for (b = 0; b < 2; b++) { - cmp(make(i, j, a, b), make(i, j, 0, 0)); - cmp(make(i, j, 0, 0), make(i, j, a, b)); - } - } - } - } -} - -void xop(const char *name, long double a, long double b, long double c) -{ - u128_t ax = copy_ild(a); - u128_t bx = copy_ild(b); - u128_t cx = copy_ild(c); - printf("%s %016llx%016llx %016llx%016llx %016llx%016llx\n", - name, ax.x1, ax.x0, bx.x1, bx.x0, cx.x1, cx.x0); -} - -void fadd(long double a, long double b) -{ - xop("add", a, b, a + b); -} - -void fsub(long double a, long double b) -{ - xop("sub", a, b, a - b); -} - -void fmul(long double a, long double b) -{ - xop("mul", a, b, a * b); -} - -void fdiv(long double a, long double b) -{ - xop("div", a, b, a / b); -} - -void nanz(void) -{ - // Check NaNs: - { - long double x[7]; - int i, j, n = 0; - x[n++] = make(0, 32000, 0x95132b76effc, 0xd79035214b4f8d53); - x[n++] = make(1, 32001, 0xbe71d7a51587, 0x30601c6815d6c3ac); - x[n++] = make(0, 32767, 0, 1); - x[n++] = make(0, 32767, (uint64_t)1 << 46, 0); - x[n++] = make(1, 32767, (uint64_t)1 << 47, 0); - x[n++] = make(1, 32767, 0x7596c7099ad5, 0xe25fed2c58f73fc9); - x[n++] = make(0, 32767, 0x835d143360f9, 0x5e315efb35630666); - check(n == sizeof(x) / sizeof(*x)); - for (i = 0; i < n; i++) { - for (j = 0; j < n; j++) { - fadd(x[i], x[j]); - fsub(x[i], x[j]); - fmul(x[i], x[j]); - fdiv(x[i], x[j]); - } - } - } - - // Check infinities and zeroes: - { - long double x[6]; - int i, j, n = 0; - x[n++] = make(1, 32000, 0x62acda85f700, 0x47b6c9f35edc4044); - x[n++] = make(0, 32001, 0x94b7abf55af7, 0x9f425fe354428e19); - x[n++] = make(0, 32767, 0, 0); - x[n++] = make(1, 32767, 0, 0); - x[n++] = make(0, 0, 0, 0); - x[n++] = make(1, 0, 0, 0); - check(n == sizeof(x) / sizeof(*x)); - for (i = 0; i < n; i++) { - for (j = 0; j < n; j++) { - fadd(x[i], x[j]); - fsub(x[i], x[j]); - fmul(x[i], x[j]); - fdiv(x[i], x[j]); - } - } - } -} - -void adds(void) -{ - // Check shifting and add/sub: - { - int i; - for (i = -130; i <= 130; i++) { - int s1 = (uint32_t)i % 3 < 1; - int s2 = (uint32_t)i % 5 < 2; - fadd(make(s1, 16384 , 0x502c065e4f71a65d, 0xd2f9bdb031f4f031), - make(s2, 16384 + i, 0xae267395a9bc1033, 0xb56b5800da1ba448)); - } - } - - // Check normalisation: - { - uint64_t a0 = 0xc6bab0a6afbef5ed; - uint64_t a1 = 0x4f84136c4a2e9b52; - int ee[] = { 0, 1, 10000 }; - int e, i; - for (e = 0; e < sizeof(ee) / sizeof(*ee); e++) { - int exp = ee[e]; - fsub(make(0, exp, a1, a0), make(0, 0, 0, 0)); - for (i = 63; i >= 0; i--) - fsub(make(0, exp, a1 | (uint64_t)1 << i >> 1, a0), - make(0, exp, a1 >> i << i, 0)); - for (i = 63; i >=0; i--) - fsub(make(0, exp, a1, a0 | (uint64_t)1 << i >> 1), - make(0, exp, a1, a0 >> i << i)); - } - } - - // Carry/overflow from rounding: - { - fadd(make(0, 114, -1, -1), make(0, 1, 0, 0)); - fadd(make(0, 32766, -1, -1), make(0, 32653, 0, 0)); - fsub(make(1, 32766, -1, -1), make(0, 32653, 0, 0)); - } -} - -void muls(void) -{ - int i, j; - - { - long double max = make(0, 32766, -1, -1); - long double min = make(0, 0, 0, 1); - fmul(max, max); - fmul(max, min); - fmul(min, min); - } - - for (i = 117; i > 0; i--) - fmul(make(0, 16268, 0x643dcea76edc, 0xe0877a598403627a), - make(i & 1, i, 0, 0)); - - fmul(make(0, 16383, -1, -3), make(0, 16383, 0, 1)); - // Round to next exponent: - fmul(make(0, 16383, -1, -2), make(0, 16383, 0, 1)); - // Round from subnormal to normal: - fmul(make(0, 1, -1, -1), make(0, 16382, 0, 0)); - - for (i = 0; i < 2; i++) - for (j = 0; j < 112; j++) - fmul(make(0, 16383, (uint64_t)1 << i, 0), - make(0, 16383, - j < 64 ? 0 : (uint64_t)1 << (j - 64), - j < 64 ? (uint64_t)1 << j : 0)); -} - -void divs(void) -{ - int i; - - { - long double max = make(0, 32766, -1, -1); - long double min = make(0, 0, 0, 1); - fdiv(max, max); - fdiv(max, min); - fdiv(min, max); - fdiv(min, min); - } - - for (i = 0; i < 64; i++) - fdiv(make(0, 16383, -1, -1), make(0, 16383, -1, -(uint64_t)1 << i)); - for (i = 0; i < 48; i++) - fdiv(make(0, 16383, -1, -1), make(0, 16383, -(uint64_t)1 << i, 0)); -} - -void cvtlsw(int32_t a) -{ - long double f = a; - u128_t x = copy_ild(f); - printf("cvtlsw %08lx %016llx%016llx\n", (long)(uint32_t)a, x.x1, x.x0); -} - -void cvtlsx(int64_t a) -{ - long double f = a; - u128_t x = copy_ild(f); - printf("cvtlsx %016llx %016llx%016llx\n", - (long long)(uint64_t)a, x.x1, x.x0); -} - -void cvtluw(uint32_t a) -{ - long double f = a; - u128_t x = copy_ild(f); - printf("cvtluw %08lx %016llx%016llx\n", (long)a, x.x1, x.x0); -} - -void cvtlux(uint64_t a) -{ - long double f = a; - u128_t x = copy_ild(f); - printf("cvtlux %016llx %016llx%016llx\n", (long long)a, x.x1, x.x0); -} - -void cvtil(long double a) -{ - u128_t x = copy_ild(a); - int32_t b1 = a; - int64_t b2 = a; - uint32_t b3 = a; - uint64_t b4 = a; - printf("cvtswl %016llx%016llx %08lx\n", - x.x1, x.x0, (long)(uint32_t)b1); - printf("cvtsxl %016llx%016llx %016llx\n", - x.x1, x.x0, (long long)(uint64_t)b2); - printf("cvtuwl %016llx%016llx %08lx\n", - x.x1, x.x0, (long)b3); - printf("cvtuxl %016llx%016llx %016llx\n", - x.x1, x.x0, (long long)b4); -} - -void cvtlf(float a) -{ - uint32_t ax = copy_if(a); - long double b = a; - u128_t bx = copy_ild(b); - printf("cvtlf %08lx %016llx%016llx\n", (long)ax, bx.x1, bx.x0); -} - -void cvtld(double a) -{ - uint64_t ax = copy_id(a); - long double b = a; - u128_t bx = copy_ild(b); - printf("cvtld %016llx %016llx%016llx\n", (long long)ax, bx.x1, bx.x0); -} - -void cvtfl(long double a) -{ - u128_t ax = copy_ild(a); - float b = a; - uint32_t bx = copy_if(b); - printf("cvtfl %016llx%016llx %08lx\n", ax.x1, ax.x0, (long)bx); -} - -void cvtdl(long double a) -{ - u128_t ax = copy_ild(a); - double b = a; - uint64_t bx = copy_id(b); - printf("cvtdl %016llx%016llx %016llx\n", ax.x1, ax.x0, (long long)bx); -} - -void cvts(void) -{ - int i, j; - - { - uint32_t x = 0xad040c5b; - cvtlsw(0); - for (i = 0; i < 31; i++) - cvtlsw(x >> (31 - i)); - for (i = 0; i < 31; i++) - cvtlsw(-(x >> (31 - i))); - cvtlsw(0x80000000); - } - { - uint64_t x = 0xb630a248cad9afd2; - cvtlsx(0); - for (i = 0; i < 63; i++) - cvtlsx(x >> (63 - i)); - for (i = 0; i < 63; i++) - cvtlsx(-(x >> (63 - i))); - cvtlsx(0x8000000000000000); - } - { - uint32_t x = 0xad040c5b; - cvtluw(0); - for (i = 0; i < 32; i++) - cvtluw(x >> (31 - i)); - } - { - uint64_t x = 0xb630a248cad9afd2; - cvtlux(0); - for (i = 0; i < 64; i++) - cvtlux(x >> (63 - i)); - } - - for (i = 0; i < 2; i++) { - cvtil(make(i, 32767, 0, 1)); - cvtil(make(i, 32767, (uint64_t)1 << 47, 0)); - cvtil(make(i, 32767, 123, 456)); - cvtil(make(i, 32767, 0, 0)); - cvtil(make(i, 16382, -1, -1)); - cvtil(make(i, 16383, -1, -1)); - cvtil(make(i, 16384, 0x7fffffffffff, -1)); - cvtil(make(i, 16384, 0x800000000000, 0)); - for (j = 0; j < 68; j++) - cvtil(make(i, 16381 + j, 0xd4822c0a10ec, 0x1fe2f8b2669f5c9d)); - } - - cvtlf(copy_fi(0x00000000)); - cvtlf(copy_fi(0x456789ab)); - cvtlf(copy_fi(0x7f800000)); - cvtlf(copy_fi(0x7f923456)); - cvtlf(copy_fi(0x7fdbcdef)); - cvtlf(copy_fi(0x80000000)); - cvtlf(copy_fi(0xabcdef12)); - cvtlf(copy_fi(0xff800000)); - cvtlf(copy_fi(0xff923456)); - cvtlf(copy_fi(0xffdbcdef)); - - cvtld(copy_di(0x0000000000000000)); - cvtld(copy_di(0x456789abcdef0123)); - cvtld(copy_di(0x7ff0000000000000)); - cvtld(copy_di(0x7ff123456789abcd)); - cvtld(copy_di(0x7ffabcdef1234567)); - cvtld(copy_di(0x8000000000000000)); - cvtld(copy_di(0xcdef123456789abc)); - cvtld(copy_di(0xfff0000000000000)); - cvtld(copy_di(0xfff123456789abcd)); - cvtld(copy_di(0xfffabcdef1234567)); - - for (i = 0; i < 2; i++) { \ - cvtfl(make(i, 0, 0, 0)); - cvtfl(make(i, 16232, -1, -1)); - cvtfl(make(i, 16233, 0, 0)); - cvtfl(make(i, 16233, 0, 1)); - cvtfl(make(i, 16383, 0xab0ffd000000, 0)); - cvtfl(make(i, 16383, 0xab0ffd000001, 0)); - cvtfl(make(i, 16383, 0xab0ffeffffff, 0)); - cvtfl(make(i, 16383, 0xab0fff000000, 0)); - cvtfl(make(i, 16383, 0xab0fff000001, 0)); - cvtfl(make(i, 16510, 0xfffffeffffff, -1)); - cvtfl(make(i, 16510, 0xffffff000000, 0)); - cvtfl(make(i, 16511, 0, 0)); - cvtfl(make(i, 32767, 0, 0)); - cvtfl(make(i, 32767, 0, 1)); - cvtfl(make(i, 32767, 0x4cbe01ac5f40, 0x75cee3c6afbb00b5)); - cvtfl(make(i, 32767, 0x800000000000, 1)); - cvtfl(make(i, 32767, 0xa11caaaf6a52, 0x696033e871eab099)); - } - - for (i = 0; i < 2; i++) { - cvtdl(make(i, 0, 0, 0)); - cvtdl(make(i, 15307, -1, -1)); - cvtdl(make(i, 15308, 0, 0)); - cvtdl(make(i, 15308, 0, 1)); - cvtdl(make(i, 16383, 0xabc123abc0ff, 0xe800000000000000)); - cvtdl(make(i, 16383, 0xabc123abc0ff, 0xe800000000000001)); - cvtdl(make(i, 16383, 0xabc123abc0ff, 0xf7ffffffffffffff)); - cvtdl(make(i, 16383, 0xabc123abc0ff, 0xf800000000000000)); - cvtdl(make(i, 16383, 0xabc123abc0ff, 0xf800000000000001)); - cvtdl(make(i, 17406, 0xffffffffffff, 0xf7ffffffffffffff)); - cvtdl(make(i, 17406, 0xffffffffffff, 0xf800000000000000)); - cvtdl(make(i, 17407, 0, 0)); - cvtdl(make(i, 32767, 0, 0)); - cvtdl(make(i, 32767, 0, 1)); - cvtdl(make(i, 32767, 0x4cbe01ac5f40, 0x75cee3c6afbb00b5)); - cvtdl(make(i, 32767, 0x800000000000, 1)); - cvtdl(make(i, 32767, 0xa11caaaf6a52, 0x696033e871eab099)); - } -} - -void tests(void) -{ - cmps(); - nanz(); - adds(); - muls(); - divs(); - cvts(); -} - -int main() -{ -#ifdef __aarch64__ - tests(); -#else - printf("This test program is intended for a little-endian architecture\n" - "with an IEEE-standard 128-bit long double.\n"); -#endif - return 0; -} diff --git a/05/tcc-final-old/tests/tests2/00_assignment.c b/05/tcc-final-old/tests/tests2/00_assignment.c deleted file mode 100644 index c96109f..0000000 --- a/05/tcc-final-old/tests/tests2/00_assignment.c +++ /dev/null @@ -1,18 +0,0 @@ -#include - -int main() -{ - int a; - a = 42; - printf("%d\n", a); - - int b = 64; - printf("%d\n", b); - - int c = 12, d = 34; - printf("%d, %d\n", c, d); - - return 0; -} - -// vim: set expandtab ts=4 sw=3 sts=3 tw=80 : diff --git a/05/tcc-final-old/tests/tests2/00_assignment.expect b/05/tcc-final-old/tests/tests2/00_assignment.expect deleted file mode 100644 index d4407f3..0000000 --- a/05/tcc-final-old/tests/tests2/00_assignment.expect +++ /dev/null @@ -1,3 +0,0 @@ -42 -64 -12, 34 diff --git a/05/tcc-final-old/tests/tests2/01_comment.c b/05/tcc-final-old/tests/tests2/01_comment.c deleted file mode 100644 index a2e6bc6..0000000 --- a/05/tcc-final-old/tests/tests2/01_comment.c +++ /dev/null @@ -1,14 +0,0 @@ -#include - -int main() -{ - printf("Hello\n"); - printf("Hello\n"); /* this is a comment */ printf("Hello\n"); - printf("Hello\n"); - // this is also a comment sayhello(); - printf("Hello\n"); - - return 0; -} - -// vim: set expandtab ts=4 sw=3 sts=3 tw=80 : diff --git a/05/tcc-final-old/tests/tests2/01_comment.expect b/05/tcc-final-old/tests/tests2/01_comment.expect deleted file mode 100644 index b1387ad..0000000 --- a/05/tcc-final-old/tests/tests2/01_comment.expect +++ /dev/null @@ -1,5 +0,0 @@ -Hello -Hello -Hello -Hello -Hello diff --git a/05/tcc-final-old/tests/tests2/02_printf.c b/05/tcc-final-old/tests/tests2/02_printf.c deleted file mode 100644 index 4c34dd8..0000000 --- a/05/tcc-final-old/tests/tests2/02_printf.c +++ /dev/null @@ -1,18 +0,0 @@ -#include - -int main() -{ - printf("Hello world\n"); - - int Count; - for (Count = -5; Count <= 5; Count++) - printf("Count = %d\n", Count); - - printf("String 'hello', 'there' is '%s', '%s'\n", "hello", "there"); - printf("Character 'A' is '%c'\n", 65); - printf("Character 'a' is '%c'\n", 'a'); - - return 0; -} - -// vim: set expandtab ts=4 sw=3 sts=3 tw=80 : diff --git a/05/tcc-final-old/tests/tests2/02_printf.expect b/05/tcc-final-old/tests/tests2/02_printf.expect deleted file mode 100644 index f67a0f6..0000000 --- a/05/tcc-final-old/tests/tests2/02_printf.expect +++ /dev/null @@ -1,15 +0,0 @@ -Hello world -Count = -5 -Count = -4 -Count = -3 -Count = -2 -Count = -1 -Count = 0 -Count = 1 -Count = 2 -Count = 3 -Count = 4 -Count = 5 -String 'hello', 'there' is 'hello', 'there' -Character 'A' is 'A' -Character 'a' is 'a' diff --git a/05/tcc-final-old/tests/tests2/03_struct.c b/05/tcc-final-old/tests/tests2/03_struct.c deleted file mode 100644 index c5d48c5..0000000 --- a/05/tcc-final-old/tests/tests2/03_struct.c +++ /dev/null @@ -1,31 +0,0 @@ -#include - -struct fred -{ - int boris; - int natasha; -}; - -int main() -{ - struct fred bloggs; - - bloggs.boris = 12; - bloggs.natasha = 34; - - printf("%d\n", bloggs.boris); - printf("%d\n", bloggs.natasha); - - struct fred jones[2]; - jones[0].boris = 12; - jones[0].natasha = 34; - jones[1].boris = 56; - jones[1].natasha = 78; - - printf("%d\n", jones[0].boris); - printf("%d\n", jones[0].natasha); - printf("%d\n", jones[1].boris); - printf("%d\n", jones[1].natasha); - - return 0; -} diff --git a/05/tcc-final-old/tests/tests2/03_struct.expect b/05/tcc-final-old/tests/tests2/03_struct.expect deleted file mode 100644 index ecbf589..0000000 --- a/05/tcc-final-old/tests/tests2/03_struct.expect +++ /dev/null @@ -1,6 +0,0 @@ -12 -34 -12 -34 -56 -78 diff --git a/05/tcc-final-old/tests/tests2/04_for.c b/05/tcc-final-old/tests/tests2/04_for.c deleted file mode 100644 index 312fed8..0000000 --- a/05/tcc-final-old/tests/tests2/04_for.c +++ /dev/null @@ -1,15 +0,0 @@ -#include - -int main() -{ - int Count; - - for (Count = 1; Count <= 10; Count++) - { - printf("%d\n", Count); - } - - return 0; -} - -// vim: set expandtab ts=4 sw=3 sts=3 tw=80 : diff --git a/05/tcc-final-old/tests/tests2/04_for.expect b/05/tcc-final-old/tests/tests2/04_for.expect deleted file mode 100644 index f00c965..0000000 --- a/05/tcc-final-old/tests/tests2/04_for.expect +++ /dev/null @@ -1,10 +0,0 @@ -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 diff --git a/05/tcc-final-old/tests/tests2/05_array.c b/05/tcc-final-old/tests/tests2/05_array.c deleted file mode 100644 index c218f31..0000000 --- a/05/tcc-final-old/tests/tests2/05_array.c +++ /dev/null @@ -1,21 +0,0 @@ -#include - -int main() -{ - int Count; - int Array[10]; - - for (Count = 1; Count <= 10; Count++) - { - Array[Count-1] = Count * Count; - } - - for (Count = 0; Count < 10; Count++) - { - printf("%d\n", Array[Count]); - } - - return 0; -} - -// vim: set expandtab ts=4 sw=3 sts=3 tw=80 : diff --git a/05/tcc-final-old/tests/tests2/05_array.expect b/05/tcc-final-old/tests/tests2/05_array.expect deleted file mode 100644 index bc7257c..0000000 --- a/05/tcc-final-old/tests/tests2/05_array.expect +++ /dev/null @@ -1,10 +0,0 @@ -1 -4 -9 -16 -25 -36 -49 -64 -81 -100 diff --git a/05/tcc-final-old/tests/tests2/06_case.c b/05/tcc-final-old/tests/tests2/06_case.c deleted file mode 100644 index c0191e2..0000000 --- a/05/tcc-final-old/tests/tests2/06_case.c +++ /dev/null @@ -1,29 +0,0 @@ -#include - -int main() -{ - int Count; - - for (Count = 0; Count < 4; Count++) - { - printf("%d\n", Count); - switch (Count) - { - case 1: - printf("%d\n", 1); - break; - - case 2: - printf("%d\n", 2); - break; - - default: - printf("%d\n", 0); - break; - } - } - - return 0; -} - -// vim: set expandtab ts=4 sw=3 sts=3 tw=80 : diff --git a/05/tcc-final-old/tests/tests2/06_case.expect b/05/tcc-final-old/tests/tests2/06_case.expect deleted file mode 100644 index fab2c20..0000000 --- a/05/tcc-final-old/tests/tests2/06_case.expect +++ /dev/null @@ -1,8 +0,0 @@ -0 -0 -1 -1 -2 -2 -3 -0 diff --git a/05/tcc-final-old/tests/tests2/07_function.c b/05/tcc-final-old/tests/tests2/07_function.c deleted file mode 100644 index 0477ce1..0000000 --- a/05/tcc-final-old/tests/tests2/07_function.c +++ /dev/null @@ -1,30 +0,0 @@ -#include - -int myfunc(int x) -{ - return x * x; -} - -void vfunc(int a) -{ - printf("a=%d\n", a); -} - -void qfunc() -{ - printf("qfunc()\n"); -} - -int main() -{ - printf("%d\n", myfunc(3)); - printf("%d\n", myfunc(4)); - - vfunc(1234); - - qfunc(); - - return 0; -} - -// vim: set expandtab ts=4 sw=3 sts=3 tw=80 : diff --git a/05/tcc-final-old/tests/tests2/07_function.expect b/05/tcc-final-old/tests/tests2/07_function.expect deleted file mode 100644 index 8ffb0a7..0000000 --- a/05/tcc-final-old/tests/tests2/07_function.expect +++ /dev/null @@ -1,4 +0,0 @@ -9 -16 -a=1234 -qfunc() diff --git a/05/tcc-final-old/tests/tests2/08_while.c b/05/tcc-final-old/tests/tests2/08_while.c deleted file mode 100644 index 602ffc7..0000000 --- a/05/tcc-final-old/tests/tests2/08_while.c +++ /dev/null @@ -1,24 +0,0 @@ -#include - -int main() -{ - int a; - int p; - int t; - - a = 1; - p = 0; - t = 0; - - while (a < 100) - { - printf("%d\n", a); - t = a; - a = t + p; - p = t; - } - - return 0; -} - -// vim: set expandtab ts=4 sw=3 sts=3 tw=80 : diff --git a/05/tcc-final-old/tests/tests2/08_while.expect b/05/tcc-final-old/tests/tests2/08_while.expect deleted file mode 100644 index 702d4c0..0000000 --- a/05/tcc-final-old/tests/tests2/08_while.expect +++ /dev/null @@ -1,11 +0,0 @@ -1 -1 -2 -3 -5 -8 -13 -21 -34 -55 -89 diff --git a/05/tcc-final-old/tests/tests2/09_do_while.c b/05/tcc-final-old/tests/tests2/09_do_while.c deleted file mode 100644 index 1d3315d..0000000 --- a/05/tcc-final-old/tests/tests2/09_do_while.c +++ /dev/null @@ -1,24 +0,0 @@ -#include - -int main() -{ - int a; - int p; - int t; - - a = 1; - p = 0; - t = 0; - - do - { - printf("%d\n", a); - t = a; - a = t + p; - p = t; - } while (a < 100); - - return 0; -} - -// vim: set expandtab ts=4 sw=3 sts=3 tw=80 : diff --git a/05/tcc-final-old/tests/tests2/09_do_while.expect b/05/tcc-final-old/tests/tests2/09_do_while.expect deleted file mode 100644 index 702d4c0..0000000 --- a/05/tcc-final-old/tests/tests2/09_do_while.expect +++ /dev/null @@ -1,11 +0,0 @@ -1 -1 -2 -3 -5 -8 -13 -21 -34 -55 -89 diff --git a/05/tcc-final-old/tests/tests2/10_pointer.c b/05/tcc-final-old/tests/tests2/10_pointer.c deleted file mode 100644 index 0177f4d..0000000 --- a/05/tcc-final-old/tests/tests2/10_pointer.c +++ /dev/null @@ -1,40 +0,0 @@ -#include - -struct ziggy -{ - int a; - int b; - int c; -} bolshevic; - -int main() -{ - int a; - int *b; - int c; - - a = 42; - b = &a; - printf("a = %d\n", *b); - - bolshevic.a = 12; - bolshevic.b = 34; - bolshevic.c = 56; - - printf("bolshevic.a = %d\n", bolshevic.a); - printf("bolshevic.b = %d\n", bolshevic.b); - printf("bolshevic.c = %d\n", bolshevic.c); - - struct ziggy *tsar = &bolshevic; - - printf("tsar->a = %d\n", tsar->a); - printf("tsar->b = %d\n", tsar->b); - printf("tsar->c = %d\n", tsar->c); - - b = &(bolshevic.b); - printf("bolshevic.b = %d\n", *b); - - return 0; -} - -// vim: set expandtab ts=4 sw=3 sts=3 tw=80 : diff --git a/05/tcc-final-old/tests/tests2/10_pointer.expect b/05/tcc-final-old/tests/tests2/10_pointer.expect deleted file mode 100644 index 1e3c473..0000000 --- a/05/tcc-final-old/tests/tests2/10_pointer.expect +++ /dev/null @@ -1,8 +0,0 @@ -a = 42 -bolshevic.a = 12 -bolshevic.b = 34 -bolshevic.c = 56 -tsar->a = 12 -tsar->b = 34 -tsar->c = 56 -bolshevic.b = 34 diff --git a/05/tcc-final-old/tests/tests2/11_precedence.c b/05/tcc-final-old/tests/tests2/11_precedence.c deleted file mode 100644 index db2049d..0000000 --- a/05/tcc-final-old/tests/tests2/11_precedence.c +++ /dev/null @@ -1,40 +0,0 @@ -#include - -int main() -{ - int a; - int b; - int c; - int d; - int e; - int f; - int x; - int y; - - a = 12; - b = 34; - c = 56; - d = 78; - e = 0; - f = 1; - - printf("%d\n", c + d); - printf("%d\n", (y = c + d)); - printf("%d\n", e || e && f); - printf("%d\n", e || f && f); - printf("%d\n", e && e || f); - printf("%d\n", e && f || f); - printf("%d\n", a && f | f); - printf("%d\n", a | b ^ c & d); - printf("%d, %d\n", a == a, a == b); - printf("%d, %d\n", a != a, a != b); - printf("%d\n", a != b && c != d); - printf("%d\n", a + b * c / f); - printf("%d\n", a + b * c / f); - printf("%d\n", (4 << 4)); - printf("%d\n", (64 >> 4)); - - return 0; -} - -// vim: set expandtab ts=4 sw=3 sts=3 tw=80 : diff --git a/05/tcc-final-old/tests/tests2/11_precedence.expect b/05/tcc-final-old/tests/tests2/11_precedence.expect deleted file mode 100644 index b692396..0000000 --- a/05/tcc-final-old/tests/tests2/11_precedence.expect +++ /dev/null @@ -1,15 +0,0 @@ -134 -134 -0 -1 -1 -1 -1 -46 -1, 0 -0, 1 -1 -1916 -1916 -64 -4 diff --git a/05/tcc-final-old/tests/tests2/12_hashdefine.c b/05/tcc-final-old/tests/tests2/12_hashdefine.c deleted file mode 100644 index 5c521e0..0000000 --- a/05/tcc-final-old/tests/tests2/12_hashdefine.c +++ /dev/null @@ -1,14 +0,0 @@ -#include - -#define FRED 12 -#define BLOGGS(x) (12*(x)) - -int main() -{ - printf("%d\n", FRED); - printf("%d, %d, %d\n", BLOGGS(1), BLOGGS(2), BLOGGS(3)); - - return 0; -} - -// vim: set expandtab ts=4 sw=3 sts=3 tw=80 : diff --git a/05/tcc-final-old/tests/tests2/12_hashdefine.expect b/05/tcc-final-old/tests/tests2/12_hashdefine.expect deleted file mode 100644 index 99f2ed5..0000000 --- a/05/tcc-final-old/tests/tests2/12_hashdefine.expect +++ /dev/null @@ -1,2 +0,0 @@ -12 -12, 24, 36 diff --git a/05/tcc-final-old/tests/tests2/13_integer_literals.c b/05/tcc-final-old/tests/tests2/13_integer_literals.c deleted file mode 100644 index 7cee98b..0000000 --- a/05/tcc-final-old/tests/tests2/13_integer_literals.c +++ /dev/null @@ -1,20 +0,0 @@ -#include - -int main() -{ - int a = 24680; - int b = 01234567; - int c = 0x2468ac; - int d = 0x2468AC; - int e = 0b010101010101; - - printf("%d\n", a); - printf("%d\n", b); - printf("%d\n", c); - printf("%d\n", d); - printf("%d\n", e); - - return 0; -} - -// vim: set expandtab ts=4 sw=3 sts=3 tw=80 : diff --git a/05/tcc-final-old/tests/tests2/13_integer_literals.expect b/05/tcc-final-old/tests/tests2/13_integer_literals.expect deleted file mode 100644 index f5aca06..0000000 --- a/05/tcc-final-old/tests/tests2/13_integer_literals.expect +++ /dev/null @@ -1,5 +0,0 @@ -24680 -342391 -2386092 -2386092 -1365 diff --git a/05/tcc-final-old/tests/tests2/14_if.c b/05/tcc-final-old/tests/tests2/14_if.c deleted file mode 100644 index 2bd2550..0000000 --- a/05/tcc-final-old/tests/tests2/14_if.c +++ /dev/null @@ -1,21 +0,0 @@ -#include - -int main() -{ - int a = 1; - - if (a) - printf("a is true\n"); - else - printf("a is false\n"); - - int b = 0; - if (b) - printf("b is true\n"); - else - printf("b is false\n"); - - return 0; -} - -// vim: set expandtab ts=4 sw=3 sts=3 tw=80 : diff --git a/05/tcc-final-old/tests/tests2/14_if.expect b/05/tcc-final-old/tests/tests2/14_if.expect deleted file mode 100644 index c32c415..0000000 --- a/05/tcc-final-old/tests/tests2/14_if.expect +++ /dev/null @@ -1,2 +0,0 @@ -a is true -b is false diff --git a/05/tcc-final-old/tests/tests2/15_recursion.c b/05/tcc-final-old/tests/tests2/15_recursion.c deleted file mode 100644 index f79a00d..0000000 --- a/05/tcc-final-old/tests/tests2/15_recursion.c +++ /dev/null @@ -1,21 +0,0 @@ -#include - -int factorial(int i) -{ - if (i < 2) - return i; - else - return i * factorial(i - 1); -} - -int main() -{ - int Count; - - for (Count = 1; Count <= 10; Count++) - printf("%d\n", factorial(Count)); - - return 0; -} - -/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ diff --git a/05/tcc-final-old/tests/tests2/15_recursion.expect b/05/tcc-final-old/tests/tests2/15_recursion.expect deleted file mode 100644 index db47b28..0000000 --- a/05/tcc-final-old/tests/tests2/15_recursion.expect +++ /dev/null @@ -1,10 +0,0 @@ -1 -2 -6 -24 -120 -720 -5040 -40320 -362880 -3628800 diff --git a/05/tcc-final-old/tests/tests2/16_nesting.c b/05/tcc-final-old/tests/tests2/16_nesting.c deleted file mode 100644 index 2b72cc0..0000000 --- a/05/tcc-final-old/tests/tests2/16_nesting.c +++ /dev/null @@ -1,21 +0,0 @@ -#include - -int main() -{ - int x, y, z; - - for (x = 0; x < 2; x++) - { - for (y = 0; y < 3; y++) - { - for (z = 0; z < 3; z++) - { - printf("%d %d %d\n", x, y, z); - } - } - } - - return 0; -} - -/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ diff --git a/05/tcc-final-old/tests/tests2/16_nesting.expect b/05/tcc-final-old/tests/tests2/16_nesting.expect deleted file mode 100644 index 5a3431e..0000000 --- a/05/tcc-final-old/tests/tests2/16_nesting.expect +++ /dev/null @@ -1,18 +0,0 @@ -0 0 0 -0 0 1 -0 0 2 -0 1 0 -0 1 1 -0 1 2 -0 2 0 -0 2 1 -0 2 2 -1 0 0 -1 0 1 -1 0 2 -1 1 0 -1 1 1 -1 1 2 -1 2 0 -1 2 1 -1 2 2 diff --git a/05/tcc-final-old/tests/tests2/17_enum.c b/05/tcc-final-old/tests/tests2/17_enum.c deleted file mode 100644 index e2bc736..0000000 --- a/05/tcc-final-old/tests/tests2/17_enum.c +++ /dev/null @@ -1,72 +0,0 @@ -#include - -enum fred -{ - a, - b, - c, - d, - e = 54, - f = 73, - g, - h -}; - -/* All following uses of enum efoo should compile - without warning. While forward enums aren't ISO C, - it's accepted by GCC also in strict mode, and only warned - about with -pedantic. This happens in the real world. */ -/* Strict ISO C doesn't allow this kind of forward declaration of - enums, but GCC accepts it (and gives only pedantic warning), and - it occurs in the wild. */ -enum efoo; -struct Sforward_use { - int (*fmember) (enum efoo x); -}; - -extern enum efoo it_real_fn(void); -enum efoo { - ONE, - TWO, -}; -struct S2 { - enum efoo (*f2) (void); -}; -void should_compile(struct S2 *s) -{ - s->f2 = it_real_fn; -} - -enum efoo it_real_fn(void) -{ - return TWO; -} - -static unsigned int deref_uintptr(unsigned int *p) -{ - return *p; -} - -enum Epositive { - epos_one, epos_two -}; - -int main() -{ - enum fred frod; - enum Epositive epos = epos_two; - - printf("%d %d %d %d %d %d %d %d\n", a, b, c, d, e, f, g, h); - /* printf("%d\n", frod); */ - frod = 12; - printf("%d\n", frod); - frod = e; - printf("%d\n", frod); - - /* Following should compile without warning. */ - printf ("enum to int: %u\n", deref_uintptr(&epos)); - - return 0; -} - -/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ diff --git a/05/tcc-final-old/tests/tests2/17_enum.expect b/05/tcc-final-old/tests/tests2/17_enum.expect deleted file mode 100644 index d453a61..0000000 --- a/05/tcc-final-old/tests/tests2/17_enum.expect +++ /dev/null @@ -1,4 +0,0 @@ -0 1 2 3 54 73 74 75 -12 -54 -enum to int: 1 diff --git a/05/tcc-final-old/tests/tests2/18_include.c b/05/tcc-final-old/tests/tests2/18_include.c deleted file mode 100644 index dbae3aa..0000000 --- a/05/tcc-final-old/tests/tests2/18_include.c +++ /dev/null @@ -1,12 +0,0 @@ -#include - -int main() -{ - printf("including\n"); -#include "18_include.h" - printf("done\n"); - - return 0; -} - -/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ diff --git a/05/tcc-final-old/tests/tests2/18_include.expect b/05/tcc-final-old/tests/tests2/18_include.expect deleted file mode 100644 index 58c6d29..0000000 --- a/05/tcc-final-old/tests/tests2/18_include.expect +++ /dev/null @@ -1,3 +0,0 @@ -including -included -done diff --git a/05/tcc-final-old/tests/tests2/18_include.h b/05/tcc-final-old/tests/tests2/18_include.h deleted file mode 100644 index dc86080..0000000 --- a/05/tcc-final-old/tests/tests2/18_include.h +++ /dev/null @@ -1 +0,0 @@ -printf("included\n"); diff --git a/05/tcc-final-old/tests/tests2/19_pointer_arithmetic.c b/05/tcc-final-old/tests/tests2/19_pointer_arithmetic.c deleted file mode 100644 index aff65e5..0000000 --- a/05/tcc-final-old/tests/tests2/19_pointer_arithmetic.c +++ /dev/null @@ -1,28 +0,0 @@ -#include - -int main() -{ - int a; - int *b; - int *c; - - a = 42; - b = &a; - c = NULL; - - printf("%d\n", *b); - - if (b == NULL) - printf("b is NULL\n"); - else - printf("b is not NULL\n"); - - if (c == NULL) - printf("c is NULL\n"); - else - printf("c is not NULL\n"); - - return 0; -} - -/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ diff --git a/05/tcc-final-old/tests/tests2/19_pointer_arithmetic.expect b/05/tcc-final-old/tests/tests2/19_pointer_arithmetic.expect deleted file mode 100644 index 0cf781b..0000000 --- a/05/tcc-final-old/tests/tests2/19_pointer_arithmetic.expect +++ /dev/null @@ -1,3 +0,0 @@ -42 -b is not NULL -c is NULL diff --git a/05/tcc-final-old/tests/tests2/20_pointer_comparison.c b/05/tcc-final-old/tests/tests2/20_pointer_comparison.c deleted file mode 100644 index 825f778..0000000 --- a/05/tcc-final-old/tests/tests2/20_pointer_comparison.c +++ /dev/null @@ -1,24 +0,0 @@ -#include - -int main() -{ - int a; - int b; - int *d; - int *e; - d = &a; - e = &b; - a = 12; - b = 34; - printf("%d\n", *d); - printf("%d\n", *e); - printf("%d\n", d == e); - printf("%d\n", d != e); - d = e; - printf("%d\n", d == e); - printf("%d\n", d != e); - - return 0; -} - -/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ diff --git a/05/tcc-final-old/tests/tests2/20_pointer_comparison.expect b/05/tcc-final-old/tests/tests2/20_pointer_comparison.expect deleted file mode 100644 index 5d1e5f5..0000000 --- a/05/tcc-final-old/tests/tests2/20_pointer_comparison.expect +++ /dev/null @@ -1,6 +0,0 @@ -12 -34 -0 -1 -1 -0 diff --git a/05/tcc-final-old/tests/tests2/21_char_array.c b/05/tcc-final-old/tests/tests2/21_char_array.c deleted file mode 100644 index f22f527..0000000 --- a/05/tcc-final-old/tests/tests2/21_char_array.c +++ /dev/null @@ -1,33 +0,0 @@ -#include - -int main() -{ - int x = 'a'; - char y = x; - - char *a = "hello"; - - printf("%s\n", a); - - int c; - c = *a; - - char *b; - for (b = a; *b != 0; b++) - printf("%c: %d\n", *b, *b); - - char destarray[10]; - char *dest = &destarray[0]; - char *src = a; - - while (*src != 0) - *dest++ = *src++; - - *dest = 0; - - printf("copied string is %s\n", destarray); - - return 0; -} - -/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ diff --git a/05/tcc-final-old/tests/tests2/21_char_array.expect b/05/tcc-final-old/tests/tests2/21_char_array.expect deleted file mode 100644 index dbc6068..0000000 --- a/05/tcc-final-old/tests/tests2/21_char_array.expect +++ /dev/null @@ -1,7 +0,0 @@ -hello -h: 104 -e: 101 -l: 108 -l: 108 -o: 111 -copied string is hello diff --git a/05/tcc-final-old/tests/tests2/22_floating_point.c b/05/tcc-final-old/tests/tests2/22_floating_point.c deleted file mode 100644 index e3491f5..0000000 --- a/05/tcc-final-old/tests/tests2/22_floating_point.c +++ /dev/null @@ -1,50 +0,0 @@ -#include -#include - -int main() -{ - // variables - float a = 12.34 + 56.78; - printf("%f\n", a); - - // infix operators - printf("%f\n", 12.34 + 56.78); - printf("%f\n", 12.34 - 56.78); - printf("%f\n", 12.34 * 56.78); - printf("%f\n", 12.34 / 56.78); - - // comparison operators - printf("%d %d %d %d %d %d\n", 12.34 < 56.78, 12.34 <= 56.78, 12.34 == 56.78, 12.34 >= 56.78, 12.34 > 56.78, 12.34 != 56.78); - printf("%d %d %d %d %d %d\n", 12.34 < 12.34, 12.34 <= 12.34, 12.34 == 12.34, 12.34 >= 12.34, 12.34 > 12.34, 12.34 != 12.34); - printf("%d %d %d %d %d %d\n", 56.78 < 12.34, 56.78 <= 12.34, 56.78 == 12.34, 56.78 >= 12.34, 56.78 > 12.34, 56.78 != 12.34); - - // assignment operators - a = 12.34; - a += 56.78; - printf("%f\n", a); - - a = 12.34; - a -= 56.78; - printf("%f\n", a); - - a = 12.34; - a *= 56.78; - printf("%f\n", a); - - a = 12.34; - a /= 56.78; - printf("%f\n", a); - - // prefix operators - printf("%f\n", +12.34); - printf("%f\n", -12.34); - - // type coercion - a = 2; - printf("%f\n", a); - printf("%f\n", sin(2)); - - return 0; -} - -/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ diff --git a/05/tcc-final-old/tests/tests2/22_floating_point.expect b/05/tcc-final-old/tests/tests2/22_floating_point.expect deleted file mode 100644 index 75ea3a7..0000000 --- a/05/tcc-final-old/tests/tests2/22_floating_point.expect +++ /dev/null @@ -1,16 +0,0 @@ -69.120003 -69.120000 --44.440000 -700.665200 -0.217330 -1 1 0 0 0 1 -0 1 1 1 0 0 -0 0 0 1 1 1 -69.120003 --44.439999 -700.665222 -0.217330 -12.340000 --12.340000 -2.000000 -0.909297 diff --git a/05/tcc-final-old/tests/tests2/23_type_coercion.c b/05/tcc-final-old/tests/tests2/23_type_coercion.c deleted file mode 100644 index 1fcc335..0000000 --- a/05/tcc-final-old/tests/tests2/23_type_coercion.c +++ /dev/null @@ -1,54 +0,0 @@ -#include - -void charfunc(char a) -{ - printf("char: %c\n", a); -} - -void intfunc(int a) -{ - printf("int: %d\n", a); -} - -void floatfunc(float a) -{ - printf("float: %f\n", a); -} - -int main() -{ - charfunc('a'); - charfunc(98); - charfunc(99.0); - - intfunc('a'); - intfunc(98); - intfunc(99.0); - - floatfunc('a'); - floatfunc(98); - floatfunc(99.0); - - /* printf("%c %d %f\n", 'a', 'b', 'c'); */ - /* printf("%c %d %f\n", 97, 98, 99); */ - /* printf("%c %d %f\n", 97.0, 98.0, 99.0); */ - - char b = 97; - char c = 97.0; - - printf("%d %d\n", b, c); - - int d = 'a'; - int e = 97.0; - - printf("%d %d\n", d, e); - - float f = 'a'; - float g = 97; - - printf("%f %f\n", f, g); - - return 0; -} - -/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ diff --git a/05/tcc-final-old/tests/tests2/23_type_coercion.expect b/05/tcc-final-old/tests/tests2/23_type_coercion.expect deleted file mode 100644 index d9076f0..0000000 --- a/05/tcc-final-old/tests/tests2/23_type_coercion.expect +++ /dev/null @@ -1,12 +0,0 @@ -char: a -char: b -char: c -int: 97 -int: 98 -int: 99 -float: 97.000000 -float: 98.000000 -float: 99.000000 -97 97 -97 97 -97.000000 97.000000 diff --git a/05/tcc-final-old/tests/tests2/24_math_library.c b/05/tcc-final-old/tests/tests2/24_math_library.c deleted file mode 100644 index 514a25f..0000000 --- a/05/tcc-final-old/tests/tests2/24_math_library.c +++ /dev/null @@ -1,30 +0,0 @@ -#define _ISOC99_SOURCE 1 - -#include -#include - -int main() -{ - printf("%f\n", sin(0.12)); - printf("%f\n", cos(0.12)); - printf("%f\n", tan(0.12)); - printf("%f\n", asin(0.12)); - printf("%f\n", acos(0.12)); - printf("%f\n", atan(0.12)); - printf("%f\n", sinh(0.12)); - printf("%f\n", cosh(0.12)); - printf("%f\n", tanh(0.12)); - printf("%f\n", exp(0.12)); - printf("%f\n", fabs(-0.12)); - printf("%f\n", log(0.12)); - printf("%f\n", log10(0.12)); - printf("%f\n", pow(0.12, 0.12)); - printf("%f\n", sqrt(0.12)); - printf("%f\n", round(12.34)); - printf("%f\n", ceil(12.34)); - printf("%f\n", floor(12.34)); - - return 0; -} - -/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ diff --git a/05/tcc-final-old/tests/tests2/24_math_library.expect b/05/tcc-final-old/tests/tests2/24_math_library.expect deleted file mode 100644 index 99f7299..0000000 --- a/05/tcc-final-old/tests/tests2/24_math_library.expect +++ /dev/null @@ -1,18 +0,0 @@ -0.119712 -0.992809 -0.120579 -0.120290 -1.450506 -0.119429 -0.120288 -1.007209 -0.119427 -1.127497 -0.120000 --2.120264 --0.920819 -0.775357 -0.346410 -12.000000 -13.000000 -12.000000 diff --git a/05/tcc-final-old/tests/tests2/25_quicksort.c b/05/tcc-final-old/tests/tests2/25_quicksort.c deleted file mode 100644 index 5cc08bd..0000000 --- a/05/tcc-final-old/tests/tests2/25_quicksort.c +++ /dev/null @@ -1,83 +0,0 @@ -#include - -int array[16]; - -//Swap integer values by array indexes -void swap(int a, int b) -{ - int tmp = array[a]; - array[a] = array[b]; - array[b] = tmp; -} - -//Partition the array into two halves and return the -//index about which the array is partitioned -int partition(int left, int right) -{ - int pivotIndex = left; - int pivotValue = array[pivotIndex]; - int index = left; - int i; - - swap(pivotIndex, right); - for(i = left; i < right; i++) - { - if(array[i] < pivotValue) - { - swap(i, index); - index += 1; - } - } - swap(right, index); - - return index; -} - -//Quicksort the array -void quicksort(int left, int right) -{ - if(left >= right) - return; - - int index = partition(left, right); - quicksort(left, index - 1); - quicksort(index + 1, right); -} - -int main() -{ - int i; - - array[0] = 62; - array[1] = 83; - array[2] = 4; - array[3] = 89; - array[4] = 36; - array[5] = 21; - array[6] = 74; - array[7] = 37; - array[8] = 65; - array[9] = 33; - array[10] = 96; - array[11] = 38; - array[12] = 53; - array[13] = 16; - array[14] = 74; - array[15] = 55; - - for (i = 0; i < 16; i++) - printf("%d ", array[i]); - - printf("\n"); - - quicksort(0, 15); - - for (i = 0; i < 16; i++) - printf("%d ", array[i]); - - printf("\n"); - - return 0; -} - -/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ diff --git a/05/tcc-final-old/tests/tests2/25_quicksort.expect b/05/tcc-final-old/tests/tests2/25_quicksort.expect deleted file mode 100644 index 2d39cd3..0000000 --- a/05/tcc-final-old/tests/tests2/25_quicksort.expect +++ /dev/null @@ -1,2 +0,0 @@ -62 83 4 89 36 21 74 37 65 33 96 38 53 16 74 55 -4 16 21 33 36 37 38 53 55 62 65 74 74 83 89 96 diff --git a/05/tcc-final-old/tests/tests2/26_character_constants.c b/05/tcc-final-old/tests/tests2/26_character_constants.c deleted file mode 100644 index 95c4423..0000000 --- a/05/tcc-final-old/tests/tests2/26_character_constants.c +++ /dev/null @@ -1,17 +0,0 @@ -#include - -int main() -{ - printf("%d\n", '\1'); - printf("%d\n", '\10'); - printf("%d\n", '\100'); - printf("%d\n", '\x01'); - printf("%d\n", '\x0e'); - printf("%d\n", '\x10'); - printf("%d\n", '\x40'); - printf("test \x40\n"); - - return 0; -} - -/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ diff --git a/05/tcc-final-old/tests/tests2/26_character_constants.expect b/05/tcc-final-old/tests/tests2/26_character_constants.expect deleted file mode 100644 index 8f8bfa4..0000000 --- a/05/tcc-final-old/tests/tests2/26_character_constants.expect +++ /dev/null @@ -1,8 +0,0 @@ -1 -8 -64 -1 -14 -16 -64 -test @ diff --git a/05/tcc-final-old/tests/tests2/27_sizeof.c b/05/tcc-final-old/tests/tests2/27_sizeof.c deleted file mode 100644 index 5ae0ede..0000000 --- a/05/tcc-final-old/tests/tests2/27_sizeof.c +++ /dev/null @@ -1,18 +0,0 @@ -#include - -int main() -{ - char a; - int b; - double c; - - printf("%d\n", sizeof(a)); - printf("%d\n", sizeof(b)); - printf("%d\n", sizeof(c)); - - printf("%d\n", sizeof(!a)); - - return 0; -} - -/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ diff --git a/05/tcc-final-old/tests/tests2/27_sizeof.expect b/05/tcc-final-old/tests/tests2/27_sizeof.expect deleted file mode 100644 index a47ea3a..0000000 --- a/05/tcc-final-old/tests/tests2/27_sizeof.expect +++ /dev/null @@ -1,4 +0,0 @@ -1 -4 -8 -4 diff --git a/05/tcc-final-old/tests/tests2/28_strings.c b/05/tcc-final-old/tests/tests2/28_strings.c deleted file mode 100644 index 2db2298..0000000 --- a/05/tcc-final-old/tests/tests2/28_strings.c +++ /dev/null @@ -1,45 +0,0 @@ -#include -#include - -int main() -{ - char a[10]; - - strcpy(a, "hello"); - printf("%s\n", a); - - strncpy(a, "gosh", 2); - printf("%s\n", a); - - printf("%d\n", strcmp(a, "apple") > 0); - printf("%d\n", strcmp(a, "goere") > 0); - printf("%d\n", strcmp(a, "zebra") < 0); - - printf("%d\n", strlen(a)); - - strcat(a, "!"); - printf("%s\n", a); - - printf("%d\n", strncmp(a, "apple", 2) > 0); - printf("%d\n", strncmp(a, "goere", 2) == 0); - printf("%d\n", strncmp(a, "goerg", 2) == 0); - printf("%d\n", strncmp(a, "zebra", 2) < 0); - - printf("%s\n", strchr(a, 'o')); - printf("%s\n", strrchr(a, 'l')); - printf("%d\n", strrchr(a, 'x') == NULL); - - memset(&a[1], 'r', 4); - printf("%s\n", a); - - memcpy(&a[2], a, 2); - printf("%s\n", a); - - printf("%d\n", memcmp(a, "apple", 4) > 0); - printf("%d\n", memcmp(a, "grgr", 4) == 0); - printf("%d\n", memcmp(a, "zebra", 4) < 0); - - return 0; -} - -/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ diff --git a/05/tcc-final-old/tests/tests2/28_strings.expect b/05/tcc-final-old/tests/tests2/28_strings.expect deleted file mode 100644 index fd9217a..0000000 --- a/05/tcc-final-old/tests/tests2/28_strings.expect +++ /dev/null @@ -1,19 +0,0 @@ -hello -gollo -1 -1 -1 -5 -gollo! -1 -1 -1 -1 -ollo! -lo! -1 -grrrr! -grgrr! -1 -1 -1 diff --git a/05/tcc-final-old/tests/tests2/29_array_address.c b/05/tcc-final-old/tests/tests2/29_array_address.c deleted file mode 100644 index bda5ddd..0000000 --- a/05/tcc-final-old/tests/tests2/29_array_address.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include - -int main() -{ - char a[10]; - strcpy(a, "abcdef"); - printf("%s\n", &a[1]); - - return 0; -} - -/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ diff --git a/05/tcc-final-old/tests/tests2/29_array_address.expect b/05/tcc-final-old/tests/tests2/29_array_address.expect deleted file mode 100644 index 9bc8683..0000000 --- a/05/tcc-final-old/tests/tests2/29_array_address.expect +++ /dev/null @@ -1 +0,0 @@ -bcdef diff --git a/05/tcc-final-old/tests/tests2/30_hanoi.c b/05/tcc-final-old/tests/tests2/30_hanoi.c deleted file mode 100644 index 7c0893b..0000000 --- a/05/tcc-final-old/tests/tests2/30_hanoi.c +++ /dev/null @@ -1,122 +0,0 @@ -/* example from http://barnyard.syr.edu/quickies/hanoi.c */ - -/* hanoi.c: solves the tower of hanoi problem. (Programming exercise.) */ -/* By Terry R. McConnell (12/2/97) */ -/* Compile: cc -o hanoi hanoi.c */ - -/* This program does no error checking. But then, if it's right, - it's right ... right ? */ - - -/* The original towers of hanoi problem seems to have been originally posed - by one M. Claus in 1883. There is a popular legend that goes along with - it that has been often repeated and paraphrased. It goes something like this: - In the great temple at Benares there are 3 golden spikes. On one of them, - God placed 64 disks increasing in size from bottom to top, at the beginning - of time. Since then, and to this day, the priest on duty constantly transfers - disks, one at a time, in such a way that no larger disk is ever put on top - of a smaller one. When the disks have been transferred entirely to another - spike the Universe will come to an end in a large thunderclap. - - This paraphrases the original legend due to DeParville, La Nature, Paris 1884, - Part I, 285-286. For this and further information see: Mathematical - Recreations & Essays, W.W. Rouse Ball, MacMillan, NewYork, 11th Ed. 1967, - 303-305. - * - * - */ - -#include -#include - -#define TRUE 1 -#define FALSE 0 - -/* This is the number of "disks" on tower A initially. Taken to be 64 in the - * legend. The number of moves required, in general, is 2^N - 1. For N = 64, - * this is 18,446,744,073,709,551,615 */ -#define N 4 - -/* These are the three towers. For example if the state of A is 0,1,3,4, that - * means that there are three discs on A of sizes 1, 3, and 4. (Think of right - * as being the "down" direction.) */ -int A[N], B[N], C[N]; - -void Hanoi(int,int*,int*,int*); - -/* Print the current configuration of A, B, and C to the screen */ -void PrintAll() -{ - int i; - - printf("A: "); - for(i=0;i - -int main(int argc, char **argv) -{ - int Count; - - printf("hello world %d\n", argc); - for (Count = 1; Count < argc; Count++) - printf("arg %d: %s\n", Count, argv[Count]); - - return 0; -} - -/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ diff --git a/05/tcc-final-old/tests/tests2/31_args.expect b/05/tcc-final-old/tests/tests2/31_args.expect deleted file mode 100644 index 8c60bfc..0000000 --- a/05/tcc-final-old/tests/tests2/31_args.expect +++ /dev/null @@ -1,6 +0,0 @@ -hello world 6 -arg 1: arg1 -arg 2: arg2 -arg 3: arg3 -arg 4: arg4 -arg 5: arg5 diff --git a/05/tcc-final-old/tests/tests2/32_led.c b/05/tcc-final-old/tests/tests2/32_led.c deleted file mode 100644 index 5596cbf..0000000 --- a/05/tcc-final-old/tests/tests2/32_led.c +++ /dev/null @@ -1,266 +0,0 @@ -/* example from http://barnyard.syr.edu/quickies/led.c */ - -/* led.c: print out number as if on 7 line led display. I.e., write integer - given on command line like this: - _ _ _ - | _| _| |_| |_ - | |_ _| | _| etc. - - We assume the terminal behaves like a classical teletype. So the top - lines of all digits have to be printed first, then the middle lines of - all digits, etc. - - By Terry R. McConnell - -compile: cc -o led led.c - -If you just want to link in the subroutine print_led that does all the -work, compile with -DNO_MAIN, and declare the following in any source file -that uses the call: - -extern void print_led(unsigned long x, char *buf); - -Bug: you cannot call repeatedly to print more than one number to a line. -That would require curses or some other terminal API that allows moving the -cursor to a previous line. - -*/ - - - -#include -#include - -#define MAX_DIGITS 32 -#define NO_MAIN - - -/* Print the top line of the digit d into buffer. - Does not null terminate buffer. */ - -void topline(int d, char *p){ - - *p++ = ' '; - switch(d){ - - /* all these have _ on top line */ - - case 0: - case 2: - case 3: - case 5: - case 7: - case 8: - case 9: - *p++ = '_'; - break; - default: - *p++=' '; - - } - *p++=' '; -} - -/* Print the middle line of the digit d into the buffer. - Does not null terminate. */ - -void midline(int d, char *p){ - - switch(d){ - - /* those that have leading | on middle line */ - - case 0: - case 4: - case 5: - case 6: - case 8: - case 9: - *p++='|'; - break; - default: - *p++=' '; - } - switch(d){ - - /* those that have _ on middle line */ - - case 2: - case 3: - case 4: - case 5: - case 6: - case 8: - case 9: - *p++='_'; - break; - default: - *p++=' '; - - } - switch(d){ - - /* those that have closing | on middle line */ - - case 0: - case 1: - case 2: - case 3: - case 4: - case 7: - case 8: - case 9: - *p++='|'; - break; - default: - *p++=' '; - - } -} - -/* Print the bottom line of the digit d. Does not null terminate. */ - -void botline(int d, char *p){ - - - switch(d){ - - /* those that have leading | on bottom line */ - - case 0: - case 2: - case 6: - case 8: - *p++='|'; - break; - default: - *p++=' '; - } - switch(d){ - - /* those that have _ on bottom line */ - - case 0: - case 2: - case 3: - case 5: - case 6: - case 8: - *p++='_'; - break; - default: - *p++=' '; - - } - switch(d){ - - /* those that have closing | on bottom line */ - - case 0: - case 1: - case 3: - case 4: - case 5: - case 6: - case 7: - case 8: - case 9: - *p++='|'; - break; - default: - *p++=' '; - - } -} - -/* Write the led representation of integer to string buffer. */ - -void print_led(unsigned long x, char *buf) -{ - - int i=0,n; - static int d[MAX_DIGITS]; - - - /* extract digits from x */ - - n = ( x == 0L ? 1 : 0 ); /* 0 is a digit, hence a special case */ - - while(x){ - d[n++] = (int)(x%10L); - if(n >= MAX_DIGITS)break; - x = x/10L; - } - - /* print top lines of all digits */ - - for(i=n-1;i>=0;i--){ - topline(d[i],buf); - buf += 3; - *buf++=' '; - } - *buf++='\n'; /* move teletype to next line */ - - /* print middle lines of all digits */ - - for(i=n-1;i>=0;i--){ - midline(d[i],buf); - buf += 3; - *buf++=' '; - } - *buf++='\n'; - - /* print bottom lines of all digits */ - - for(i=n-1;i>=0;i--){ - botline(d[i],buf); - buf += 3; - *buf++=' '; - } - *buf++='\n'; - *buf='\0'; -} - -int main() -{ - char buf[5*MAX_DIGITS]; - print_led(1234567, buf); - printf("%s\n",buf); - - return 0; -} - -#ifndef NO_MAIN -int main(int argc, char **argv) -{ - - int i=0,n; - long x; - static int d[MAX_DIGITS]; - char buf[5*MAX_DIGITS]; - - if(argc != 2){ - fprintf(stderr,"led: usage: led integer\n"); - return 1; - } - - /* fetch argument from command line */ - - x = atol(argv[1]); - - /* sanity check */ - - if(x<0){ - fprintf(stderr,"led: %d must be non-negative\n",x); - return 1; - } - - print_led(x,buf); - printf("%s\n",buf); - - return 0; - -} -#endif - -/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ diff --git a/05/tcc-final-old/tests/tests2/32_led.expect b/05/tcc-final-old/tests/tests2/32_led.expect deleted file mode 100644 index c53b58a..0000000 --- a/05/tcc-final-old/tests/tests2/32_led.expect +++ /dev/null @@ -1,4 +0,0 @@ - _ _ _ _ - | _| _| |_| |_ |_ | - | |_ _| | _| |_| | - diff --git a/05/tcc-final-old/tests/tests2/33_ternary_op.c b/05/tcc-final-old/tests/tests2/33_ternary_op.c deleted file mode 100644 index 8579b50..0000000 --- a/05/tcc-final-old/tests/tests2/33_ternary_op.c +++ /dev/null @@ -1,15 +0,0 @@ -#include - -int main() -{ - int Count; - - for (Count = 0; Count < 10; Count++) - { - printf("%d\n", (Count < 5) ? (Count*Count) : (Count * 3)); - } - - return 0; -} - -/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ diff --git a/05/tcc-final-old/tests/tests2/33_ternary_op.expect b/05/tcc-final-old/tests/tests2/33_ternary_op.expect deleted file mode 100644 index 45ea507..0000000 --- a/05/tcc-final-old/tests/tests2/33_ternary_op.expect +++ /dev/null @@ -1,10 +0,0 @@ -0 -1 -4 -9 -16 -15 -18 -21 -24 -27 diff --git a/05/tcc-final-old/tests/tests2/34_array_assignment.c b/05/tcc-final-old/tests/tests2/34_array_assignment.c deleted file mode 100644 index 5885c97..0000000 --- a/05/tcc-final-old/tests/tests2/34_array_assignment.c +++ /dev/null @@ -1,23 +0,0 @@ -#include - -int main() -{ - int a[4]; - - a[0] = 12; - a[1] = 23; - a[2] = 34; - a[3] = 45; - - printf("%d %d %d %d\n", a[0], a[1], a[2], a[3]); - - int b[4]; - - b = a; - - printf("%d %d %d %d\n", b[0], b[1], b[2], b[3]); - - return 0; -} - -/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ diff --git a/05/tcc-final-old/tests/tests2/34_array_assignment.expect b/05/tcc-final-old/tests/tests2/34_array_assignment.expect deleted file mode 100644 index 9736bf5..0000000 --- a/05/tcc-final-old/tests/tests2/34_array_assignment.expect +++ /dev/null @@ -1,2 +0,0 @@ -12 23 34 45 -12 23 34 45 diff --git a/05/tcc-final-old/tests/tests2/35_sizeof.c b/05/tcc-final-old/tests/tests2/35_sizeof.c deleted file mode 100644 index 672e87e..0000000 --- a/05/tcc-final-old/tests/tests2/35_sizeof.c +++ /dev/null @@ -1,14 +0,0 @@ -#include - -int main() -{ - char a; - short b; - - printf("%d %d\n", sizeof(char), sizeof(a)); - printf("%d %d\n", sizeof(short), sizeof(b)); - - return 0; -} - -/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ diff --git a/05/tcc-final-old/tests/tests2/35_sizeof.expect b/05/tcc-final-old/tests/tests2/35_sizeof.expect deleted file mode 100644 index 534fb83..0000000 --- a/05/tcc-final-old/tests/tests2/35_sizeof.expect +++ /dev/null @@ -1,2 +0,0 @@ -1 1 -2 2 diff --git a/05/tcc-final-old/tests/tests2/36_array_initialisers.c b/05/tcc-final-old/tests/tests2/36_array_initialisers.c deleted file mode 100644 index 1bc8ee0..0000000 --- a/05/tcc-final-old/tests/tests2/36_array_initialisers.c +++ /dev/null @@ -1,21 +0,0 @@ -#include - -int main() -{ - int Count; - - int Array[10] = { 12, 34, 56, 78, 90, 123, 456, 789, 8642, 9753 }; - - for (Count = 0; Count < 10; Count++) - printf("%d: %d\n", Count, Array[Count]); - - int Array2[10] = { 12, 34, 56, 78, 90, 123, 456, 789, 8642, 9753, }; - - for (Count = 0; Count < 10; Count++) - printf("%d: %d\n", Count, Array2[Count]); - - - return 0; -} - -/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ diff --git a/05/tcc-final-old/tests/tests2/36_array_initialisers.expect b/05/tcc-final-old/tests/tests2/36_array_initialisers.expect deleted file mode 100644 index 3ac6c77..0000000 --- a/05/tcc-final-old/tests/tests2/36_array_initialisers.expect +++ /dev/null @@ -1,20 +0,0 @@ -0: 12 -1: 34 -2: 56 -3: 78 -4: 90 -5: 123 -6: 456 -7: 789 -8: 8642 -9: 9753 -0: 12 -1: 34 -2: 56 -3: 78 -4: 90 -5: 123 -6: 456 -7: 789 -8: 8642 -9: 9753 diff --git a/05/tcc-final-old/tests/tests2/37_sprintf.c b/05/tcc-final-old/tests/tests2/37_sprintf.c deleted file mode 100644 index 1dd1dce..0000000 --- a/05/tcc-final-old/tests/tests2/37_sprintf.c +++ /dev/null @@ -1,17 +0,0 @@ -#include - -int main() -{ - char Buf[100]; - int Count; - - for (Count = 1; Count <= 20; Count++) - { - sprintf(Buf, "->%02d<-\n", Count); - printf("%s", Buf); - } - - return 0; -} - -/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ diff --git a/05/tcc-final-old/tests/tests2/37_sprintf.expect b/05/tcc-final-old/tests/tests2/37_sprintf.expect deleted file mode 100644 index a643da8..0000000 --- a/05/tcc-final-old/tests/tests2/37_sprintf.expect +++ /dev/null @@ -1,20 +0,0 @@ -->01<- -->02<- -->03<- -->04<- -->05<- -->06<- -->07<- -->08<- -->09<- -->10<- -->11<- -->12<- -->13<- -->14<- -->15<- -->16<- -->17<- -->18<- -->19<- -->20<- diff --git a/05/tcc-final-old/tests/tests2/38_multiple_array_index.c b/05/tcc-final-old/tests/tests2/38_multiple_array_index.c deleted file mode 100644 index 4e1868e..0000000 --- a/05/tcc-final-old/tests/tests2/38_multiple_array_index.c +++ /dev/null @@ -1,32 +0,0 @@ -#include - -int main() -{ - int a[4][4]; - int b = 0; - int x; - int y; - - for (x = 0; x < 4; x++) - { - for (y = 0; y < 4; y++) - { - b++; - a[x][y] = b; - } - } - - for (x = 0; x < 4; x++) - { - printf("x=%d: ", x); - for (y = 0; y < 4; y++) - { - printf("%d ", a[x][y]); - } - printf("\n"); - } - - return 0; -} - -/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ diff --git a/05/tcc-final-old/tests/tests2/38_multiple_array_index.expect b/05/tcc-final-old/tests/tests2/38_multiple_array_index.expect deleted file mode 100644 index 747ad75..0000000 --- a/05/tcc-final-old/tests/tests2/38_multiple_array_index.expect +++ /dev/null @@ -1,4 +0,0 @@ -x=0: 1 2 3 4 -x=1: 5 6 7 8 -x=2: 9 10 11 12 -x=3: 13 14 15 16 diff --git a/05/tcc-final-old/tests/tests2/39_typedef.c b/05/tcc-final-old/tests/tests2/39_typedef.c deleted file mode 100644 index da73f71..0000000 --- a/05/tcc-final-old/tests/tests2/39_typedef.c +++ /dev/null @@ -1,65 +0,0 @@ -#include - -typedef int MyInt; - -struct FunStruct -{ - int i; - int j; -}; - -typedef struct FunStruct MyFunStruct; - -typedef MyFunStruct *MoreFunThanEver; - -int main() -{ - MyInt a = 1; - printf("%d\n", a); - - MyFunStruct b; - b.i = 12; - b.j = 34; - printf("%d,%d\n", b.i, b.j); - - MoreFunThanEver c = &b; - printf("%d,%d\n", c->i, c->j); - - return 0; -} - -/* "If the specification of an array type includes any type qualifiers, - the element type is so-qualified, not the array type." */ - -typedef int A[3]; -extern A const ca; -extern const A ca; -extern const int ca[3]; - -typedef A B[1][2]; -extern B const cb; -extern const B cb; -extern const int cb[1][2][3]; - -extern B b; -extern int b[1][2][3]; - -/* Funny but valid function declaration. */ -typedef int functype (int); -extern functype func; -int func(int i) -{ - return i + 1; -} - -/* Even funnier function decl and definition using typeof. */ -int set_anon_super(void); -int set_anon_super(void) -{ - return 42; -} -typedef int sas_type (void); -extern typeof(set_anon_super) set_anon_super; -extern sas_type set_anon_super; - -/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ diff --git a/05/tcc-final-old/tests/tests2/39_typedef.expect b/05/tcc-final-old/tests/tests2/39_typedef.expect deleted file mode 100644 index b9050a9..0000000 --- a/05/tcc-final-old/tests/tests2/39_typedef.expect +++ /dev/null @@ -1,3 +0,0 @@ -1 -12,34 -12,34 diff --git a/05/tcc-final-old/tests/tests2/40_stdio.c b/05/tcc-final-old/tests/tests2/40_stdio.c deleted file mode 100644 index b986093..0000000 --- a/05/tcc-final-old/tests/tests2/40_stdio.c +++ /dev/null @@ -1,52 +0,0 @@ -#include - -int main() -{ - FILE *f = fopen("fred.txt", "w"); - fwrite("hello\nhello\n", 1, 12, f); - fclose(f); - - char freddy[7]; - f = fopen("fred.txt", "r"); - if (fread(freddy, 1, 6, f) != 6) - printf("couldn't read fred.txt\n"); - - freddy[6] = '\0'; - fclose(f); - - printf("%s", freddy); - - int InChar; - char ShowChar; - f = fopen("fred.txt", "r"); - while ( (InChar = fgetc(f)) != EOF) - { - ShowChar = InChar; - if (ShowChar < ' ') - ShowChar = '.'; - - printf("ch: %d '%c'\n", InChar, ShowChar); - } - fclose(f); - - f = fopen("fred.txt", "r"); - while ( (InChar = getc(f)) != EOF) - { - ShowChar = InChar; - if (ShowChar < ' ') - ShowChar = '.'; - - printf("ch: %d '%c'\n", InChar, ShowChar); - } - fclose(f); - - f = fopen("fred.txt", "r"); - while (fgets(freddy, sizeof(freddy), f) != NULL) - printf("x: %s", freddy); - - fclose(f); - - return 0; -} - -/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ diff --git a/05/tcc-final-old/tests/tests2/40_stdio.expect b/05/tcc-final-old/tests/tests2/40_stdio.expect deleted file mode 100644 index e08167a..0000000 --- a/05/tcc-final-old/tests/tests2/40_stdio.expect +++ /dev/null @@ -1,27 +0,0 @@ -hello -ch: 104 'h' -ch: 101 'e' -ch: 108 'l' -ch: 108 'l' -ch: 111 'o' -ch: 10 '.' -ch: 104 'h' -ch: 101 'e' -ch: 108 'l' -ch: 108 'l' -ch: 111 'o' -ch: 10 '.' -ch: 104 'h' -ch: 101 'e' -ch: 108 'l' -ch: 108 'l' -ch: 111 'o' -ch: 10 '.' -ch: 104 'h' -ch: 101 'e' -ch: 108 'l' -ch: 108 'l' -ch: 111 'o' -ch: 10 '.' -x: hello -x: hello diff --git a/05/tcc-final-old/tests/tests2/41_hashif.c b/05/tcc-final-old/tests/tests2/41_hashif.c deleted file mode 100644 index cb37b9e..0000000 --- a/05/tcc-final-old/tests/tests2/41_hashif.c +++ /dev/null @@ -1,85 +0,0 @@ -#include - -int main() -{ - printf("#include test\n"); - -#if 1 -#if 0 - printf("a\n"); -#else - printf("b\n"); -#endif -#else -#if 0 - printf("c\n"); -#else - printf("d\n"); -#endif -#endif - -#if 0 -#if 1 - printf("e\n"); -#else - printf("f\n"); -#endif -#else -#if 1 - printf("g\n"); -#else - printf("h\n"); -#endif -#endif - -#define DEF - -#ifdef DEF -#ifdef DEF - printf("i\n"); -#else - printf("j\n"); -#endif -#else -#ifdef DEF - printf("k\n"); -#else - printf("l\n"); -#endif -#endif - -#ifndef DEF -#ifndef DEF - printf("m\n"); -#else - printf("n\n"); -#endif -#else -#ifndef DEF - printf("o\n"); -#else - printf("p\n"); -#endif -#endif - -#define ONE 1 -#define ZERO 0 - -#if ONE -#if ZERO - printf("q\n"); -#else - printf("r\n"); -#endif -#else -#if ZERO - printf("s\n"); -#else - printf("t\n"); -#endif -#endif - - return 0; -} - -/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ diff --git a/05/tcc-final-old/tests/tests2/41_hashif.expect b/05/tcc-final-old/tests/tests2/41_hashif.expect deleted file mode 100644 index 5fd414b..0000000 --- a/05/tcc-final-old/tests/tests2/41_hashif.expect +++ /dev/null @@ -1,6 +0,0 @@ -#include test -b -g -i -p -r diff --git a/05/tcc-final-old/tests/tests2/42_function_pointer.c b/05/tcc-final-old/tests/tests2/42_function_pointer.c deleted file mode 100644 index 697bd79..0000000 --- a/05/tcc-final-old/tests/tests2/42_function_pointer.c +++ /dev/null @@ -1,22 +0,0 @@ -#include - -int fred(int p) -{ - printf("yo %d\n", p); - return 42; -} - -int (*f)(int) = &fred; - -/* To test what this is supposed to test the destination function - (fprint here) must not be called directly anywhere in the test. */ -int (*fprintfptr)(FILE *, const char *, ...) = &fprintf; - -int main() -{ - fprintfptr(stdout, "%d\n", (*f)(24)); - - return 0; -} - -/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ diff --git a/05/tcc-final-old/tests/tests2/42_function_pointer.expect b/05/tcc-final-old/tests/tests2/42_function_pointer.expect deleted file mode 100644 index 6c8b6ce..0000000 --- a/05/tcc-final-old/tests/tests2/42_function_pointer.expect +++ /dev/null @@ -1,2 +0,0 @@ -yo 24 -42 diff --git a/05/tcc-final-old/tests/tests2/43_void_param.c b/05/tcc-final-old/tests/tests2/43_void_param.c deleted file mode 100644 index de17098..0000000 --- a/05/tcc-final-old/tests/tests2/43_void_param.c +++ /dev/null @@ -1,15 +0,0 @@ -#include - -void fred(void) -{ - printf("yo\n"); -} - -int main() -{ - fred(); - - return 0; -} - -/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ diff --git a/05/tcc-final-old/tests/tests2/43_void_param.expect b/05/tcc-final-old/tests/tests2/43_void_param.expect deleted file mode 100644 index 092bfb9..0000000 --- a/05/tcc-final-old/tests/tests2/43_void_param.expect +++ /dev/null @@ -1 +0,0 @@ -yo diff --git a/05/tcc-final-old/tests/tests2/44_scoped_declarations.c b/05/tcc-final-old/tests/tests2/44_scoped_declarations.c deleted file mode 100644 index f38664f..0000000 --- a/05/tcc-final-old/tests/tests2/44_scoped_declarations.c +++ /dev/null @@ -1,17 +0,0 @@ -#include - -int main() -{ - int a; - - for (a = 0; a < 2; a++) - { - int b = a; - } - - printf("it's all good\n"); - - return 0; -} - -/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ diff --git a/05/tcc-final-old/tests/tests2/44_scoped_declarations.expect b/05/tcc-final-old/tests/tests2/44_scoped_declarations.expect deleted file mode 100644 index 231ccc0..0000000 --- a/05/tcc-final-old/tests/tests2/44_scoped_declarations.expect +++ /dev/null @@ -1 +0,0 @@ -it's all good diff --git a/05/tcc-final-old/tests/tests2/45_empty_for.c b/05/tcc-final-old/tests/tests2/45_empty_for.c deleted file mode 100644 index 7cef513..0000000 --- a/05/tcc-final-old/tests/tests2/45_empty_for.c +++ /dev/null @@ -1,18 +0,0 @@ -#include - -int main() -{ - int Count = 0; - - for (;;) - { - Count++; - printf("%d\n", Count); - if (Count >= 10) - break; - } - - return 0; -} - -/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ diff --git a/05/tcc-final-old/tests/tests2/45_empty_for.expect b/05/tcc-final-old/tests/tests2/45_empty_for.expect deleted file mode 100644 index f00c965..0000000 --- a/05/tcc-final-old/tests/tests2/45_empty_for.expect +++ /dev/null @@ -1,10 +0,0 @@ -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 diff --git a/05/tcc-final-old/tests/tests2/46_grep.c b/05/tcc-final-old/tests/tests2/46_grep.c deleted file mode 100644 index 049dfb1..0000000 --- a/05/tcc-final-old/tests/tests2/46_grep.c +++ /dev/null @@ -1,568 +0,0 @@ -/* - * The information in this document is subject to change - * without notice and should not be construed as a commitment - * by Digital Equipment Corporation or by DECUS. - * - * Neither Digital Equipment Corporation, DECUS, nor the authors - * assume any responsibility for the use or reliability of this - * document or the described software. - * - * Copyright (C) 1980, DECUS - * - * General permission to copy or modify, but not for profit, is - * hereby granted, provided that the above copyright notice is - * included and reference made to the fact that reproduction - * privileges were granted by DECUS. - */ -#include -#include -#include // tolower() - -/* - * grep - * - * Runs on the Decus compiler or on vms, On vms, define as: - * grep :== "$disk:[account]grep" (native) - * grep :== "$disk:[account]grep grep" (Decus) - * See below for more information. - */ - -char *documentation[] = { - "grep searches a file for a given pattern. Execute by", - " grep [flags] regular_expression file_list\n", - "Flags are single characters preceded by '-':", - " -c Only a count of matching lines is printed", - " -f Print file name for matching lines switch, see below", - " -n Each line is preceded by its line number", - " -v Only print non-matching lines\n", - "The file_list is a list of files (wildcards are acceptable on RSX modes).", - "\nThe file name is normally printed if there is a file given.", - "The -f flag reverses this action (print name no file, not if more).\n", - 0 }; - -char *patdoc[] = { - "The regular_expression defines the pattern to search for. Upper- and", - "lower-case are always ignored. Blank lines never match. The expression", - "should be quoted to prevent file-name translation.", - "x An ordinary character (not mentioned below) matches that character.", - "'\\' The backslash quotes any character. \"\\$\" matches a dollar-sign.", - "'^' A circumflex at the beginning of an expression matches the", - " beginning of a line.", - "'$' A dollar-sign at the end of an expression matches the end of a line.", - "'.' A period matches any character except \"new-line\".", - "':a' A colon matches a class of characters described by the following", - "':d' character. \":a\" matches any alphabetic, \":d\" matches digits,", - "':n' \":n\" matches alphanumerics, \": \" matches spaces, tabs, and", - "': ' other control characters, such as new-line.", - "'*' An expression followed by an asterisk matches zero or more", - " occurrences of that expression: \"fo*\" matches \"f\", \"fo\"", - " \"foo\", etc.", - "'+' An expression followed by a plus sign matches one or more", - " occurrences of that expression: \"fo+\" matches \"fo\", etc.", - "'-' An expression followed by a minus sign optionally matches", - " the expression.", - "'[]' A string enclosed in square brackets matches any character in", - " that string, but no others. If the first character in the", - " string is a circumflex, the expression matches any character", - " except \"new-line\" and the characters in the string. For", - " example, \"[xyz]\" matches \"xx\" and \"zyx\", while \"[^xyz]\"", - " matches \"abc\" but not \"axb\". A range of characters may be", - " specified by two characters separated by \"-\". Note that,", - " [a-z] matches alphabetics, while [z-a] never matches.", - "The concatenation of regular expressions is a regular expression.", - 0}; - -#define LMAX 512 -#define PMAX 256 - -#define CHAR 1 -#define BOL 2 -#define EOL 3 -#define ANY 4 -#define CLASS 5 -#define NCLASS 6 -#define STAR 7 -#define PLUS 8 -#define MINUS 9 -#define ALPHA 10 -#define DIGIT 11 -#define NALPHA 12 -#define PUNCT 13 -#define RANGE 14 -#define ENDPAT 15 - -int cflag=0, fflag=0, nflag=0, vflag=0, nfile=0, debug=0; - -char *pp, lbuf[LMAX], pbuf[PMAX]; - -char *cclass(); -char *pmatch(); -void store(int); -void error(char *); -void badpat(char *, char *, char *); -int match(void); - - -/*** Display a file name *******************************/ -void file(char *s) -{ - printf("File %s:\n", s); -} - -/*** Report unopenable file ****************************/ -void cant(char *s) -{ - fprintf(stderr, "%s: cannot open\n", s); -} - -/*** Give good help ************************************/ -void help(char **hp) -{ - char **dp; - - for (dp = hp; *dp; ++dp) - printf("%s\n", *dp); -} - -/*** Display usage summary *****************************/ -void usage(char *s) -{ - fprintf(stderr, "?GREP-E-%s\n", s); - fprintf(stderr, - "Usage: grep [-cfnv] pattern [file ...]. grep ? for help\n"); - exit(1); -} - -/*** Compile the pattern into global pbuf[] ************/ -void compile(char *source) -{ - char *s; /* Source string pointer */ - char *lp; /* Last pattern pointer */ - int c; /* Current character */ - int o; /* Temp */ - char *spp; /* Save beginning of pattern */ - - s = source; - if (debug) - printf("Pattern = \"%s\"\n", s); - pp = pbuf; - while (c = *s++) { - /* - * STAR, PLUS and MINUS are special. - */ - if (c == '*' || c == '+' || c == '-') { - if (pp == pbuf || - (o=pp[-1]) == BOL || - o == EOL || - o == STAR || - o == PLUS || - o == MINUS) - badpat("Illegal occurrence op.", source, s); - store(ENDPAT); - store(ENDPAT); - spp = pp; /* Save pattern end */ - while (--pp > lp) /* Move pattern down */ - *pp = pp[-1]; /* one byte */ - *pp = (c == '*') ? STAR : - (c == '-') ? MINUS : PLUS; - pp = spp; /* Restore pattern end */ - continue; - } - /* - * All the rest. - */ - lp = pp; /* Remember start */ - switch(c) { - - case '^': - store(BOL); - break; - - case '$': - store(EOL); - break; - - case '.': - store(ANY); - break; - - case '[': - s = cclass(source, s); - break; - - case ':': - if (*s) { - switch(tolower(c = *s++)) { - - case 'a': - case 'A': - store(ALPHA); - break; - - case 'd': - case 'D': - store(DIGIT); - break; - - case 'n': - case 'N': - store(NALPHA); - break; - - case ' ': - store(PUNCT); - break; - - default: - badpat("Unknown : type", source, s); - - } - break; - } - else badpat("No : type", source, s); - - case '\\': - if (*s) - c = *s++; - - default: - store(CHAR); - store(tolower(c)); - } - } - store(ENDPAT); - store(0); /* Terminate string */ - if (debug) { - for (lp = pbuf; lp < pp;) { - if ((c = (*lp++ & 0377)) < ' ') - printf("\\%o ", c); - else printf("%c ", c); - } - printf("\n"); - } -} - -/*** Compile a class (within []) ***********************/ -char *cclass(char *source, char *src) - /* char *source; // Pattern start -- for error msg. */ - /* char *src; // Class start */ -{ - char *s; /* Source pointer */ - char *cp; /* Pattern start */ - int c; /* Current character */ - int o; /* Temp */ - - s = src; - o = CLASS; - if (*s == '^') { - ++s; - o = NCLASS; - } - store(o); - cp = pp; - store(0); /* Byte count */ - while ((c = *s++) && c!=']') { - if (c == '\\') { /* Store quoted char */ - if ((c = *s++) == '\0') /* Gotta get something */ - badpat("Class terminates badly", source, s); - else store(tolower(c)); - } - else if (c == '-' && - (pp - cp) > 1 && *s != ']' && *s != '\0') { - c = pp[-1]; /* Range start */ - pp[-1] = RANGE; /* Range signal */ - store(c); /* Re-store start */ - c = *s++; /* Get end char and*/ - store(tolower(c)); /* Store it */ - } - else { - store(tolower(c)); /* Store normal char */ - } - } - if (c != ']') - badpat("Unterminated class", source, s); - if ((c = (pp - cp)) >= 256) - badpat("Class too large", source, s); - if (c == 0) - badpat("Empty class", source, s); - *cp = c; - return(s); -} - -/*** Store an entry in the pattern buffer **************/ -void store(int op) -{ - if (pp >= &pbuf[PMAX]) - error("Pattern too complex\n"); - *pp++ = op; -} - -/*** Report a bad pattern specification ****************/ -void badpat(char *message, char *source, char *stop) - /* char *message; // Error message */ - /* char *source; // Pattern start */ - /* char *stop; // Pattern end */ -{ - fprintf(stderr, "-GREP-E-%s, pattern is\"%s\"\n", message, source); - fprintf(stderr, "-GREP-E-Stopped at byte %ld, '%c'\n", - stop-source, stop[-1]); - error("?GREP-E-Bad pattern\n"); -} - -/*** Scan the file for the pattern in pbuf[] ***********/ -void grep(FILE *fp, char *fn) - /* FILE *fp; // File to process */ - /* char *fn; // File name (for -f option) */ -{ - int lno, count, m; - - lno = 0; - count = 0; - while (fgets(lbuf, LMAX, fp)) { - ++lno; - m = match(); - if ((m && !vflag) || (!m && vflag)) { - ++count; - if (!cflag) { - if (fflag && fn) { - file(fn); - fn = 0; - } - if (nflag) - printf("%d\t", lno); - printf("%s\n", lbuf); - } - } - } - if (cflag) { - if (fflag && fn) - file(fn); - printf("%d\n", count); - } -} - -/*** Match line (lbuf) with pattern (pbuf) return 1 if match ***/ -int match() -{ - char *l; /* Line pointer */ - - for (l = lbuf; *l; ++l) { - if (pmatch(l, pbuf)) - return(1); - } - return(0); -} - -/*** Match partial line with pattern *******************/ -char *pmatch(char *line, char *pattern) - /* char *line; // (partial) line to match */ - /* char *pattern; // (partial) pattern to match */ -{ - char *l; /* Current line pointer */ - char *p; /* Current pattern pointer */ - char c; /* Current character */ - char *e; /* End for STAR and PLUS match */ - int op; /* Pattern operation */ - int n; /* Class counter */ - char *are; /* Start of STAR match */ - - l = line; - if (debug > 1) - printf("pmatch(\"%s\")\n", line); - p = pattern; - while ((op = *p++) != ENDPAT) { - if (debug > 1) - printf("byte[%ld] = 0%o, '%c', op = 0%o\n", - l-line, *l, *l, op); - switch(op) { - - case CHAR: - if (tolower(*l++) != *p++) - return(0); - break; - - case BOL: - if (l != lbuf) - return(0); - break; - - case EOL: - if (*l != '\0') - return(0); - break; - - case ANY: - if (*l++ == '\0') - return(0); - break; - - case DIGIT: - if ((c = *l++) < '0' || (c > '9')) - return(0); - break; - - case ALPHA: - c = tolower(*l++); - if (c < 'a' || c > 'z') - return(0); - break; - - case NALPHA: - c = tolower(*l++); - if (c >= 'a' && c <= 'z') - break; - else if (c < '0' || c > '9') - return(0); - break; - - case PUNCT: - c = *l++; - if (c == 0 || c > ' ') - return(0); - break; - - case CLASS: - case NCLASS: - c = tolower(*l++); - n = *p++ & 0377; - do { - if (*p == RANGE) { - p += 3; - n -= 2; - if (c >= p[-2] && c <= p[-1]) - break; - } - else if (c == *p++) - break; - } while (--n > 1); - if ((op == CLASS) == (n <= 1)) - return(0); - if (op == CLASS) - p += n - 2; - break; - - case MINUS: - e = pmatch(l, p); /* Look for a match */ - while (*p++ != ENDPAT); /* Skip over pattern */ - if (e) /* Got a match? */ - l = e; /* Yes, update string */ - break; /* Always succeeds */ - - case PLUS: /* One or more ... */ - if ((l = pmatch(l, p)) == 0) - return(0); /* Gotta have a match */ - case STAR: /* Zero or more ... */ - are = l; /* Remember line start */ - while (*l && (e = pmatch(l, p))) - l = e; /* Get longest match */ - while (*p++ != ENDPAT); /* Skip over pattern */ - while (l >= are) { /* Try to match rest */ - if (e = pmatch(l, p)) - return(e); - --l; /* Nope, try earlier */ - } - return(0); /* Nothing else worked */ - - default: - printf("Bad op code %d\n", op); - error("Cannot happen -- match\n"); - } - } - return(l); -} - -/*** Report an error ***********************************/ -void error(char *s) -{ - fprintf(stderr, "%s", s); - exit(1); -} - -/*** Main program - parse arguments & grep *************/ -int main(int argc, char **argv) -{ - char *p; - int c, i; - int gotpattern; - - FILE *f; - - if (argc <= 1) - usage("No arguments"); - if (argc == 2 && argv[1][0] == '?' && argv[1][1] == 0) { - help(documentation); - help(patdoc); - return 0; - } - nfile = argc-1; - gotpattern = 0; - for (i=1; i < argc; ++i) { - p = argv[i]; - if (*p == '-') { - ++p; - while (c = *p++) { - switch(tolower(c)) { - - case '?': - help(documentation); - break; - - case 'C': - case 'c': - ++cflag; - break; - - case 'D': - case 'd': - ++debug; - break; - - case 'F': - case 'f': - ++fflag; - break; - - case 'n': - case 'N': - ++nflag; - break; - - case 'v': - case 'V': - ++vflag; - break; - - default: - usage("Unknown flag"); - } - } - argv[i] = 0; - --nfile; - } else if (!gotpattern) { - compile(p); - argv[i] = 0; - ++gotpattern; - --nfile; - } - } - if (!gotpattern) - usage("No pattern"); - if (nfile == 0) - grep(stdin, 0); - else { - fflag = fflag ^ (nfile > 0); - for (i=1; i < argc; ++i) { - if (p = argv[i]) { - if ((f=fopen(p, "r")) == NULL) - cant(p); - else { - grep(f, p); - fclose(f); - } - } - } - } - return 0; -} - -/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ diff --git a/05/tcc-final-old/tests/tests2/46_grep.expect b/05/tcc-final-old/tests/tests2/46_grep.expect deleted file mode 100644 index e8a6791..0000000 --- a/05/tcc-final-old/tests/tests2/46_grep.expect +++ /dev/null @@ -1,3 +0,0 @@ -File 46_grep.c: -/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ - diff --git a/05/tcc-final-old/tests/tests2/47_switch_return.c b/05/tcc-final-old/tests/tests2/47_switch_return.c deleted file mode 100644 index 1ec7924..0000000 --- a/05/tcc-final-old/tests/tests2/47_switch_return.c +++ /dev/null @@ -1,24 +0,0 @@ -#include - -void fred(int x) -{ - switch (x) - { - case 1: printf("1\n"); return; - case 2: printf("2\n"); break; - case 3: printf("3\n"); return; - } - - printf("out\n"); -} - -int main() -{ - fred(1); - fred(2); - fred(3); - - return 0; -} - -/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ diff --git a/05/tcc-final-old/tests/tests2/47_switch_return.expect b/05/tcc-final-old/tests/tests2/47_switch_return.expect deleted file mode 100644 index b6deb7e..0000000 --- a/05/tcc-final-old/tests/tests2/47_switch_return.expect +++ /dev/null @@ -1,4 +0,0 @@ -1 -2 -out -3 diff --git a/05/tcc-final-old/tests/tests2/48_nested_break.c b/05/tcc-final-old/tests/tests2/48_nested_break.c deleted file mode 100644 index 5bc5ba4..0000000 --- a/05/tcc-final-old/tests/tests2/48_nested_break.c +++ /dev/null @@ -1,26 +0,0 @@ -#include - -int main() -{ - int a; - char b; - - a = 0; - while (a < 2) - { - printf("%d", a++); - break; - - b = 'A'; - while (b < 'C') - { - printf("%c", b++); - } - printf("e"); - } - printf("\n"); - - return 0; -} - -/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ diff --git a/05/tcc-final-old/tests/tests2/48_nested_break.expect b/05/tcc-final-old/tests/tests2/48_nested_break.expect deleted file mode 100644 index 573541a..0000000 --- a/05/tcc-final-old/tests/tests2/48_nested_break.expect +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/05/tcc-final-old/tests/tests2/49_bracket_evaluation.c b/05/tcc-final-old/tests/tests2/49_bracket_evaluation.c deleted file mode 100644 index 0cbe57d..0000000 --- a/05/tcc-final-old/tests/tests2/49_bracket_evaluation.c +++ /dev/null @@ -1,23 +0,0 @@ -#include - -struct point -{ - double x; - double y; -}; - -struct point point_array[100]; - -int main() -{ - int my_point = 10; - - point_array[my_point].x = 12.34; - point_array[my_point].y = 56.78; - - printf("%f, %f\n", point_array[my_point].x, point_array[my_point].y); - - return 0; -} - -/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ diff --git a/05/tcc-final-old/tests/tests2/49_bracket_evaluation.expect b/05/tcc-final-old/tests/tests2/49_bracket_evaluation.expect deleted file mode 100644 index 1da66db..0000000 --- a/05/tcc-final-old/tests/tests2/49_bracket_evaluation.expect +++ /dev/null @@ -1 +0,0 @@ -12.340000, 56.780000 diff --git a/05/tcc-final-old/tests/tests2/50_logical_second_arg.c b/05/tcc-final-old/tests/tests2/50_logical_second_arg.c deleted file mode 100644 index ddec08c..0000000 --- a/05/tcc-final-old/tests/tests2/50_logical_second_arg.c +++ /dev/null @@ -1,29 +0,0 @@ -#include - -int fred() -{ - printf("fred\n"); - return 0; -} - -int joe() -{ - printf("joe\n"); - return 1; -} - -int main() -{ - printf("%d\n", fred() && joe()); - printf("%d\n", fred() || joe()); - printf("%d\n", joe() && fred()); - printf("%d\n", joe() || fred()); - printf("%d\n", fred() && (1 + joe())); - printf("%d\n", fred() || (0 + joe())); - printf("%d\n", joe() && (0 + fred())); - printf("%d\n", joe() || (1 + fred())); - - return 0; -} - -/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ diff --git a/05/tcc-final-old/tests/tests2/50_logical_second_arg.expect b/05/tcc-final-old/tests/tests2/50_logical_second_arg.expect deleted file mode 100644 index d6174ae..0000000 --- a/05/tcc-final-old/tests/tests2/50_logical_second_arg.expect +++ /dev/null @@ -1,20 +0,0 @@ -fred -0 -fred -joe -1 -joe -fred -0 -joe -1 -fred -0 -fred -joe -1 -joe -fred -0 -joe -1 diff --git a/05/tcc-final-old/tests/tests2/51_static.c b/05/tcc-final-old/tests/tests2/51_static.c deleted file mode 100644 index d6c0917..0000000 --- a/05/tcc-final-old/tests/tests2/51_static.c +++ /dev/null @@ -1,30 +0,0 @@ -#include - -static int fred = 1234; -static int joe; - -void henry() -{ - static int fred = 4567; - - printf("%d\n", fred); - fred++; -} - -int main() -{ - printf("%d\n", fred); - henry(); - henry(); - henry(); - henry(); - printf("%d\n", fred); - fred = 8901; - joe = 2345; - printf("%d\n", fred); - printf("%d\n", joe); - - return 0; -} - -/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ diff --git a/05/tcc-final-old/tests/tests2/51_static.expect b/05/tcc-final-old/tests/tests2/51_static.expect deleted file mode 100644 index 18224fa..0000000 --- a/05/tcc-final-old/tests/tests2/51_static.expect +++ /dev/null @@ -1,8 +0,0 @@ -1234 -4567 -4568 -4569 -4570 -1234 -8901 -2345 diff --git a/05/tcc-final-old/tests/tests2/52_unnamed_enum.c b/05/tcc-final-old/tests/tests2/52_unnamed_enum.c deleted file mode 100644 index d0395b2..0000000 --- a/05/tcc-final-old/tests/tests2/52_unnamed_enum.c +++ /dev/null @@ -1,27 +0,0 @@ -#include - -enum fred { a, b, c }; - -int main() -{ - printf("a=%d\n", a); - printf("b=%d\n", b); - printf("c=%d\n", c); - - enum fred d; - - typedef enum { e, f, g } h; - typedef enum { i, j, k } m; - - printf("e=%d\n", e); - printf("f=%d\n", f); - printf("g=%d\n", g); - - printf("i=%d\n", i); - printf("j=%d\n", j); - printf("k=%d\n", k); - - return 0; -} - -/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ diff --git a/05/tcc-final-old/tests/tests2/52_unnamed_enum.expect b/05/tcc-final-old/tests/tests2/52_unnamed_enum.expect deleted file mode 100644 index 84f2ac8..0000000 --- a/05/tcc-final-old/tests/tests2/52_unnamed_enum.expect +++ /dev/null @@ -1,9 +0,0 @@ -a=0 -b=1 -c=2 -e=0 -f=1 -g=2 -i=0 -j=1 -k=2 diff --git a/05/tcc-final-old/tests/tests2/54_goto.c b/05/tcc-final-old/tests/tests2/54_goto.c deleted file mode 100644 index 2e151bb..0000000 --- a/05/tcc-final-old/tests/tests2/54_goto.c +++ /dev/null @@ -1,56 +0,0 @@ -#include - -void fred() -{ - printf("In fred()\n"); - goto done; - printf("In middle\n"); -done: - printf("At end\n"); -} - -void joe() -{ - int b = 5678; - - printf("In joe()\n"); - - { - int c = 1234; - printf("c = %d\n", c); - goto outer; - printf("uh-oh\n"); - } - -outer: - - printf("done\n"); -} - -void henry() -{ - int a; - - printf("In henry()\n"); - goto inner; - - { - int b; -inner: - b = 1234; - printf("b = %d\n", b); - } - - printf("done\n"); -} - -int main() -{ - fred(); - joe(); - henry(); - - return 0; -} - -/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ diff --git a/05/tcc-final-old/tests/tests2/54_goto.expect b/05/tcc-final-old/tests/tests2/54_goto.expect deleted file mode 100644 index 8e553fa..0000000 --- a/05/tcc-final-old/tests/tests2/54_goto.expect +++ /dev/null @@ -1,8 +0,0 @@ -In fred() -At end -In joe() -c = 1234 -done -In henry() -b = 1234 -done diff --git a/05/tcc-final-old/tests/tests2/55_lshift_type.c b/05/tcc-final-old/tests/tests2/55_lshift_type.c deleted file mode 100644 index aa3e51a..0000000 --- a/05/tcc-final-old/tests/tests2/55_lshift_type.c +++ /dev/null @@ -1,52 +0,0 @@ -/* $Id: lshift-type.c 53089 2012-07-06 11:18:26Z vinc17/ypig $ - -Tests on left-shift type, written by Vincent Lefevre . - -ISO C99 TC3 says: [6.5.7#3] "The integer promotions are performed on -each of the operands. The type of the result is that of the promoted -left operand." -*/ - -#include - -#define PTYPE(M) ((M) < 0 || -(M) < 0 ? -1 : 1) * (int) sizeof((M)+0) -#define CHECK(X,T) check(#X, PTYPE(X), PTYPE((X) << (T) 1)) -#define TEST1(X,T) do { CHECK(X,T); CHECK(X,unsigned T); } while (0) -#define TEST2(X) \ - do \ - { \ - TEST1((X),short); \ - TEST1((X),int); \ - TEST1((X),long); \ - TEST1((X),long long); \ - } \ - while (0) -#define TEST3(X,T) do { TEST2((T)(X)); TEST2((unsigned T)(X)); } while (0) -#define TEST4(X) \ - do \ - { \ - TEST3((X),short); \ - TEST3((X),int); \ - TEST3((X),long); \ - TEST3((X),long long); \ - } \ - while (0) - -static int debug, nfailed = 0; - -static void check (const char *s, int arg1, int shift) -{ - int failed = arg1 != shift; - if (debug || failed) - printf ("%s %d %d\n", s, arg1, shift); - nfailed += failed; -} - -int main (int argc, char **argv) -{ - debug = argc > 1; - TEST4(1); - TEST4(-1); - printf ("%d test(s) failed\n", nfailed); - return nfailed != 0; -} diff --git a/05/tcc-final-old/tests/tests2/55_lshift_type.expect b/05/tcc-final-old/tests/tests2/55_lshift_type.expect deleted file mode 100644 index 8523767..0000000 --- a/05/tcc-final-old/tests/tests2/55_lshift_type.expect +++ /dev/null @@ -1 +0,0 @@ -0 test(s) failed diff --git a/05/tcc-final-old/tests/tests2/60_errors_and_warnings.c b/05/tcc-final-old/tests/tests2/60_errors_and_warnings.c deleted file mode 100644 index 0028caf..0000000 --- a/05/tcc-final-old/tests/tests2/60_errors_and_warnings.c +++ /dev/null @@ -1,51 +0,0 @@ -#if defined test_56_btype_excess_1 -struct A {} int i; - -#elif defined test_57_btype_excess_2 -char int i; - -#elif defined test_58_function_redefinition -int f(void) { return 0; } -int f(void) { return 1; } - -#elif defined test_global_redefinition -int xxx = 1; -int xxx; -int xxx = 2; - -#elif defined test_59_function_array -int (*fct)[42](int x); - -#elif defined test_60_enum_redefinition -enum color { RED, GREEN, BLUE }; -enum color { R, G, B }; -enum color c; - -#elif defined test_62_enumerator_redefinition -enum color { RED, GREEN, BLUE }; -enum rgb { RED, G, B}; -enum color c = RED; - -#elif defined test_63_local_enumerator_redefinition -enum { - FOO, - BAR -}; - -int main(void) -{ - enum { - FOO = 2, - BAR - }; - - return BAR - FOO; -} - -#elif defined test_61_undefined_enum -enum rgb3 c = 42; - -#elif defined test_74_non_const_init -int i = i++; - -#endif diff --git a/05/tcc-final-old/tests/tests2/60_errors_and_warnings.expect b/05/tcc-final-old/tests/tests2/60_errors_and_warnings.expect deleted file mode 100644 index ed6a690..0000000 --- a/05/tcc-final-old/tests/tests2/60_errors_and_warnings.expect +++ /dev/null @@ -1,28 +0,0 @@ -[test_56_btype_excess_1] -60_errors_and_warnings.c:2: error: too many basic types - -[test_57_btype_excess_2] -60_errors_and_warnings.c:5: error: too many basic types - -[test_58_function_redefinition] -60_errors_and_warnings.c:9: error: redefinition of 'f' - -[test_global_redefinition] -60_errors_and_warnings.c:14: error: redefinition of 'xxx' - -[test_59_function_array] -60_errors_and_warnings.c:17: error: declaration of an array of functions - -[test_60_enum_redefinition] -60_errors_and_warnings.c:21: error: struct/union/enum already defined - -[test_62_enumerator_redefinition] -60_errors_and_warnings.c:26: error: redefinition of enumerator 'RED' - -[test_63_local_enumerator_redefinition] - -[test_61_undefined_enum] -60_errors_and_warnings.c:46: error: unknown type size - -[test_74_non_const_init] -60_errors_and_warnings.c:49: error: initializer element is not constant diff --git a/05/tcc-final-old/tests/tests2/64_macro_nesting.c b/05/tcc-final-old/tests/tests2/64_macro_nesting.c deleted file mode 100644 index 676e5d3..0000000 --- a/05/tcc-final-old/tests/tests2/64_macro_nesting.c +++ /dev/null @@ -1,12 +0,0 @@ -#include // printf() - -#define CAT2(a,b) a##b -#define CAT(a,b) CAT2(a,b) -#define AB(x) CAT(x,y) - -int main(void) -{ - int xy = 42; - printf("%d\n", CAT(A,B)(x)); - return 0; -} diff --git a/05/tcc-final-old/tests/tests2/64_macro_nesting.expect b/05/tcc-final-old/tests/tests2/64_macro_nesting.expect deleted file mode 100644 index d81cc07..0000000 --- a/05/tcc-final-old/tests/tests2/64_macro_nesting.expect +++ /dev/null @@ -1 +0,0 @@ -42 diff --git a/05/tcc-final-old/tests/tests2/67_macro_concat.c b/05/tcc-final-old/tests/tests2/67_macro_concat.c deleted file mode 100644 index c580d3a..0000000 --- a/05/tcc-final-old/tests/tests2/67_macro_concat.c +++ /dev/null @@ -1,14 +0,0 @@ -#include - -#define P(A,B) A ## B ; bob -#define Q(A,B) A ## B+ - -int main(void) -{ - int bob, jim = 21; - bob = P(jim,) *= 2; - printf("jim: %d, bob: %d\n", jim, bob); - jim = 60 Q(+,)3; - printf("jim: %d\n", jim); - return 0; -} diff --git a/05/tcc-final-old/tests/tests2/67_macro_concat.expect b/05/tcc-final-old/tests/tests2/67_macro_concat.expect deleted file mode 100644 index 8386c2d..0000000 --- a/05/tcc-final-old/tests/tests2/67_macro_concat.expect +++ /dev/null @@ -1,2 +0,0 @@ -jim: 21, bob: 42 -jim: 63 diff --git a/05/tcc-final-old/tests/tests2/70_floating_point_literals.c b/05/tcc-final-old/tests/tests2/70_floating_point_literals.c deleted file mode 100644 index 012fb4f..0000000 --- a/05/tcc-final-old/tests/tests2/70_floating_point_literals.c +++ /dev/null @@ -1,77 +0,0 @@ -#include - -int main() -{ - /* decimal floating constant */ - float fa0 = .123f; - float fa1 = .123E12F; - float fa2 = .123e-12f; - float fa3 = .123e+12f; - printf("%f\n%f\n%f\n%f\n\n", fa0, fa1, fa2, fa3); - - float fb0 = 123.123f; - float fb1 = 123.123E12F; - float fb2 = 123.123e-12f; - float fb3 = 123.123e+12f; - printf("%f\n%f\n%f\n%f\n\n", fb0, fb1, fb2, fb3); - - float fc0 = 123.f; - float fc1 = 123.E12F; - float fc2 = 123.e-12f; - float fc3 = 123.e+12f; - printf("%f\n%f\n%f\n%f\n\n", fc0, fc1, fc2, fc3); - - float fd0 = 123E12F; - float fd1 = 123e-12f; - float fd2 = 123e+12f; - printf("%f\n%f\n%f\n\n", fd0, fd1, fd2); - printf("\n"); - - /* hexadecimal floating constant */ - double da0 = 0X.1ACP12; - double da1 = 0x.1acp-12; - double da2 = 0x.1acp+12; - printf("%f\n%f\n%f\n\n", da0, da1, da2); - - double db0 = 0X1AC.BDP12; - double db1 = 0x1ac.bdp-12; - double db2 = 0x1ac.dbp+12; - printf("%f\n%f\n%f\n\n", db0, db1, db2); - - double dc0 = 0X1AC.P12; - double dc1 = 0x1ac.p-12; - double dc2 = 0x1ac.p+12; - printf("%f\n%f\n%f\n\n", dc0, dc1, dc2); - - double dd0 = 0X1ACP12; - double dd1 = 0x1acp-12; - double dd2 = 0x1acp+12; - printf("%f\n%f\n%f\n\n", dd0, dd1, dd2); - printf("\n"); - -#ifdef __TINYC__ - /* TCC extension - binary floating constant */ - long double la0 = 0B.110101100P12L; - long double la1 = 0b.110101100p-12l; - long double la2 = 0b.110101100p+12l; - printf("%Lf\n%Lf\n%Lf\n\n", la0, la1, la2); - - long double lb0 = 0B110101100.10111101P12L; - long double lb1 = 0b110101100.10111101p-12l; - long double lb2 = 0b110101100.10111101p+12l; - printf("%Lf\n%Lf\n%Lf\n\n", lb0, lb1, lb2); - - long double lc0 = 0B110101100.P12L; - long double lc1 = 0b110101100.p-12l; - long double lc2 = 0b110101100.p+12l; - printf("%Lf\n%Lf\n%Lf\n\n", lc0, lc1, lc2); - - long double ld0 = 0B110101100P12L; - long double ld1 = 0b110101100p-12l; - long double ld2 = 0b110101100p+12l; - printf("%Lf\n%Lf\n%Lf\n\n", ld0, ld1, ld2); -#endif - - return 0; -} diff --git a/05/tcc-final-old/tests/tests2/70_floating_point_literals.expect b/05/tcc-final-old/tests/tests2/70_floating_point_literals.expect deleted file mode 100644 index 7eb1efb..0000000 --- a/05/tcc-final-old/tests/tests2/70_floating_point_literals.expect +++ /dev/null @@ -1,53 +0,0 @@ -0.123000 -122999996416.000000 -0.000000 -122999996416.000000 - -123.123001 -123122997002240.000000 -0.000000 -123122997002240.000000 - -123.000000 -123000003231744.000000 -0.000000 -123000003231744.000000 - -123000003231744.000000 -0.000000 -123000003231744.000000 - - -428.000000 -0.000026 -428.000000 - -1756112.000000 -0.104672 -1756592.000000 - -1753088.000000 -0.104492 -1753088.000000 - -1753088.000000 -0.104492 -1753088.000000 - - -3424.000000 -0.000204 -3424.000000 - -1756112.000000 -0.104672 -1756112.000000 - -1753088.000000 -0.104492 -1753088.000000 - -1753088.000000 -0.104492 -1753088.000000 - diff --git a/05/tcc-final-old/tests/tests2/71_macro_empty_arg.c b/05/tcc-final-old/tests/tests2/71_macro_empty_arg.c deleted file mode 100644 index f0d3511..0000000 --- a/05/tcc-final-old/tests/tests2/71_macro_empty_arg.c +++ /dev/null @@ -1,9 +0,0 @@ -#include - -#define T(a,b,c) a b c - -int main(void) -{ - printf("%d", T(1,+,2) T(+,,) T(,2,*) T(,7,) T(,,)); - return 0; -} diff --git a/05/tcc-final-old/tests/tests2/71_macro_empty_arg.expect b/05/tcc-final-old/tests/tests2/71_macro_empty_arg.expect deleted file mode 100644 index 98d9bcb..0000000 --- a/05/tcc-final-old/tests/tests2/71_macro_empty_arg.expect +++ /dev/null @@ -1 +0,0 @@ -17 diff --git a/05/tcc-final-old/tests/tests2/72_long_long_constant.c b/05/tcc-final-old/tests/tests2/72_long_long_constant.c deleted file mode 100644 index 6608213..0000000 --- a/05/tcc-final-old/tests/tests2/72_long_long_constant.c +++ /dev/null @@ -1,19 +0,0 @@ -#include - -int main() -{ - long long int res = 0; - - if (res < -2147483648LL) { - printf("Error: 0 < -2147483648\n"); - return 1; - } - else - if (2147483647LL < res) { - printf("Error: 2147483647 < 0\n"); - return 2; - } - else - printf("long long constant test ok.\n"); - return 0; -} diff --git a/05/tcc-final-old/tests/tests2/72_long_long_constant.expect b/05/tcc-final-old/tests/tests2/72_long_long_constant.expect deleted file mode 100644 index dda9e66..0000000 --- a/05/tcc-final-old/tests/tests2/72_long_long_constant.expect +++ /dev/null @@ -1 +0,0 @@ -long long constant test ok. diff --git a/05/tcc-final-old/tests/tests2/73_arm64.c b/05/tcc-final-old/tests/tests2/73_arm64.c deleted file mode 100644 index 8de61b3..0000000 --- a/05/tcc-final-old/tests/tests2/73_arm64.c +++ /dev/null @@ -1,527 +0,0 @@ -// This program is designed to test some arm64-specific things, such as the -// calling convention, but should give the same results on any architecture. - -#include -#include -#include - -struct s1 { char x[1]; } s1 = { "0" }; -struct s2 { char x[2]; } s2 = { "12" }; -struct s3 { char x[3]; } s3 = { "345" }; -struct s4 { char x[4]; } s4 = { "6789" }; -struct s5 { char x[5]; } s5 = { "abcde" }; -struct s6 { char x[6]; } s6 = { "fghijk" }; -struct s7 { char x[7]; } s7 = { "lmnopqr" }; -struct s8 { char x[8]; } s8 = { "stuvwxyz" }; -struct s9 { char x[9]; } s9 = { "ABCDEFGHI" }; -struct s10 { char x[10]; } s10 = { "JKLMNOPQRS" }; -struct s11 { char x[11]; } s11 = { "TUVWXYZ0123" }; -struct s12 { char x[12]; } s12 = { "456789abcdef" }; -struct s13 { char x[13]; } s13 = { "ghijklmnopqrs" }; -struct s14 { char x[14]; } s14 = { "tuvwxyzABCDEFG" }; -struct s15 { char x[15]; } s15 = { "HIJKLMNOPQRSTUV" }; -struct s16 { char x[16]; } s16 = { "WXYZ0123456789ab" }; -struct s17 { char x[17]; } s17 = { "cdefghijklmnopqrs" }; - -struct hfa11 { float a; } hfa11 = { 11.1 }; -struct hfa12 { float a, b; } hfa12 = { 12.1, 12.2 }; -struct hfa13 { float a, b, c; } hfa13 = { 13.1, 13.2, 13.3 }; -struct hfa14 { float a, b, c, d; } hfa14 = { 14.1, 14.2, 14.3, 14.4 }; - -struct hfa21 { double a; } hfa21 = { 21.1 }; -struct hfa22 { double a, b; } hfa22 = { 22.1, 22.2 }; -struct hfa23 { double a, b, c; } hfa23 = { 23.1, 23.2, 23.3 }; -struct hfa24 { double a, b, c, d; } hfa24 = { 24.1, 24.2, 24.3, 24.4 }; - -struct hfa31 { long double a; } hfa31 = { 31.1 }; -struct hfa32 { long double a, b; } hfa32 = { 32.1, 32.2 }; -struct hfa33 { long double a, b, c; } hfa33 = { 33.1, 33.2, 33.3 }; -struct hfa34 { long double a, b, c, d; } hfa34 = { 34.1, 34.2, 34.3, 34.4 }; - -void fa_s1(struct s1 a) { printf("%.1s\n", a.x); } -void fa_s2(struct s2 a) { printf("%.2s\n", a.x); } -void fa_s3(struct s3 a) { printf("%.3s\n", a.x); } -void fa_s4(struct s4 a) { printf("%.4s\n", a.x); } -void fa_s5(struct s5 a) { printf("%.5s\n", a.x); } -void fa_s6(struct s6 a) { printf("%.6s\n", a.x); } -void fa_s7(struct s7 a) { printf("%.7s\n", a.x); } -void fa_s8(struct s8 a) { printf("%.8s\n", a.x); } -void fa_s9(struct s9 a) { printf("%.9s\n", a.x); } -void fa_s10(struct s10 a) { printf("%.10s\n", a.x); } -void fa_s11(struct s11 a) { printf("%.11s\n", a.x); } -void fa_s12(struct s12 a) { printf("%.12s\n", a.x); } -void fa_s13(struct s13 a) { printf("%.13s\n", a.x); } -void fa_s14(struct s14 a) { printf("%.14s\n", a.x); } -void fa_s15(struct s15 a) { printf("%.15s\n", a.x); } -void fa_s16(struct s16 a) { printf("%.16s\n", a.x); } -void fa_s17(struct s17 a) { printf("%.17s\n", a.x); } - -void fa_hfa11(struct hfa11 a) -{ printf("%.1f\n", a.a); } -void fa_hfa12(struct hfa12 a) -{ printf("%.1f %.1f\n", a.a, a.a); } -void fa_hfa13(struct hfa13 a) -{ printf("%.1f %.1f %.1f\n", a.a, a.b, a.c); } -void fa_hfa14(struct hfa14 a) -{ printf("%.1f %.1f %.1f %.1f\n", a.a, a.b, a.c, a.d); } - -void fa_hfa21(struct hfa21 a) -{ printf("%.1f\n", a.a); } -void fa_hfa22(struct hfa22 a) -{ printf("%.1f %.1f\n", a.a, a.a); } -void fa_hfa23(struct hfa23 a) -{ printf("%.1f %.1f %.1f\n", a.a, a.b, a.c); } -void fa_hfa24(struct hfa24 a) -{ printf("%.1f %.1f %.1f %.1f\n", a.a, a.b, a.c, a.d); } - -void fa_hfa31(struct hfa31 a) -{ printf("%.1Lf\n", a.a); } -void fa_hfa32(struct hfa32 a) -{ printf("%.1Lf %.1Lf\n", a.a, a.a); } -void fa_hfa33(struct hfa33 a) -{ printf("%.1Lf %.1Lf %.1Lf\n", a.a, a.b, a.c); } -void fa_hfa34(struct hfa34 a) -{ printf("%.1Lf %.1Lf %.1Lf %.1Lf\n", a.a, a.b, a.c, a.d); } - -void fa1(struct s8 a, struct s9 b, struct s10 c, struct s11 d, - struct s12 e, struct s13 f) -{ - printf("%.3s %.3s %.3s %.3s %.3s %.3s\n", a.x, b.x, c.x, d.x, e.x, f.x); -} - -void fa2(struct s9 a, struct s10 b, struct s11 c, struct s12 d, - struct s13 e, struct s14 f) -{ - printf("%.3s %.3s %.3s %.3s %.3s %.3s\n", a.x, b.x, c.x, d.x, e.x, f.x); -} - -void fa3(struct hfa14 a, struct hfa23 b, struct hfa32 c) -{ - printf("%.1f %.1f %.1f %.1f %.1Lf %.1Lf\n", - a.a, a.d, b.a, b.c, c.a, c.b); -} - -void fa4(struct s1 a, struct hfa14 b, struct s2 c, struct hfa24 d, - struct s3 e, struct hfa34 f) -{ - printf("%.1s %.1f %.1f %.2s %.1f %.1f %.3s %.1Lf %.1Lf\n", - a.x, b.a, b.d, c.x, d.a, d.d, e.x, f.a, f.d); -} - -void arg(void) -{ - printf("Arguments:\n"); - fa_s1(s1); - fa_s2(s2); - fa_s3(s3); - fa_s4(s4); - fa_s5(s5); - fa_s6(s6); - fa_s7(s7); - fa_s8(s8); - fa_s9(s9); - fa_s10(s10); - fa_s11(s11); - fa_s12(s12); - fa_s13(s13); - fa_s14(s14); - fa_s15(s15); - fa_s16(s16); - fa_s17(s17); - fa_hfa11(hfa11); - fa_hfa12(hfa12); - fa_hfa13(hfa13); - fa_hfa14(hfa14); - fa_hfa21(hfa21); - fa_hfa22(hfa22); - fa_hfa23(hfa23); - fa_hfa24(hfa24); - fa_hfa31(hfa31); - fa_hfa32(hfa32); - fa_hfa33(hfa33); - fa_hfa34(hfa34); - fa1(s8, s9, s10, s11, s12, s13); - fa2(s9, s10, s11, s12, s13, s14); - fa3(hfa14, hfa23, hfa32); - fa4(s1, hfa14, s2, hfa24, s3, hfa34); -} - -struct s1 fr_s1(void) { return s1; } -struct s2 fr_s2(void) { return s2; } -struct s3 fr_s3(void) { return s3; } -struct s4 fr_s4(void) { return s4; } -struct s5 fr_s5(void) { return s5; } -struct s6 fr_s6(void) { return s6; } -struct s7 fr_s7(void) { return s7; } -struct s8 fr_s8(void) { return s8; } -struct s9 fr_s9(void) { return s9; } -struct s10 fr_s10(void) { return s10; } -struct s11 fr_s11(void) { return s11; } -struct s12 fr_s12(void) { return s12; } -struct s13 fr_s13(void) { return s13; } -struct s14 fr_s14(void) { return s14; } -struct s15 fr_s15(void) { return s15; } -struct s16 fr_s16(void) { return s16; } -struct s17 fr_s17(void) { return s17; } - -struct hfa11 fr_hfa11(void) { return hfa11; } -struct hfa12 fr_hfa12(void) { return hfa12; } -struct hfa13 fr_hfa13(void) { return hfa13; } -struct hfa14 fr_hfa14(void) { return hfa14; } - -struct hfa21 fr_hfa21(void) { return hfa21; } -struct hfa22 fr_hfa22(void) { return hfa22; } -struct hfa23 fr_hfa23(void) { return hfa23; } -struct hfa24 fr_hfa24(void) { return hfa24; } - -struct hfa31 fr_hfa31(void) { return hfa31; } -struct hfa32 fr_hfa32(void) { return hfa32; } -struct hfa33 fr_hfa33(void) { return hfa33; } -struct hfa34 fr_hfa34(void) { return hfa34; } - -void ret(void) -{ - struct s1 t1 = fr_s1(); - struct s2 t2 = fr_s2(); - struct s3 t3 = fr_s3(); - struct s4 t4 = fr_s4(); - struct s5 t5 = fr_s5(); - struct s6 t6 = fr_s6(); - struct s7 t7 = fr_s7(); - struct s8 t8 = fr_s8(); - struct s9 t9 = fr_s9(); - struct s10 t10 = fr_s10(); - struct s11 t11 = fr_s11(); - struct s12 t12 = fr_s12(); - struct s13 t13 = fr_s13(); - struct s14 t14 = fr_s14(); - struct s15 t15 = fr_s15(); - struct s16 t16 = fr_s16(); - struct s17 t17 = fr_s17(); - printf("Return values:\n"); - printf("%.1s\n", t1.x); - printf("%.2s\n", t2.x); - printf("%.3s\n", t3.x); - printf("%.4s\n", t4.x); - printf("%.5s\n", t5.x); - printf("%.6s\n", t6.x); - printf("%.7s\n", t7.x); - printf("%.8s\n", t8.x); - printf("%.9s\n", t9.x); - printf("%.10s\n", t10.x); - printf("%.11s\n", t11.x); - printf("%.12s\n", t12.x); - printf("%.13s\n", t13.x); - printf("%.14s\n", t14.x); - printf("%.15s\n", t15.x); - printf("%.16s\n", t16.x); - printf("%.17s\n", t17.x); - printf("%.1f\n", fr_hfa11().a); - printf("%.1f %.1f\n", fr_hfa12().a, fr_hfa12().b); - printf("%.1f %.1f\n", fr_hfa13().a, fr_hfa13().c); - printf("%.1f %.1f\n", fr_hfa14().a, fr_hfa14().d); - printf("%.1f\n", fr_hfa21().a); - printf("%.1f %.1f\n", fr_hfa22().a, fr_hfa22().b); - printf("%.1f %.1f\n", fr_hfa23().a, fr_hfa23().c); - printf("%.1f %.1f\n", fr_hfa24().a, fr_hfa24().d); - printf("%.1Lf\n", fr_hfa31().a); - printf("%.1Lf %.1Lf\n", fr_hfa32().a, fr_hfa32().b); - printf("%.1Lf %.1Lf\n", fr_hfa33().a, fr_hfa33().c); - printf("%.1Lf %.1Lf\n", fr_hfa34().a, fr_hfa34().d); -} - -int match(const char **s, const char *f) -{ - const char *p = *s; - for (p = *s; *f && *f == *p; f++, p++) - ; - if (!*f) { - *s = p - 1; - return 1; - } - return 0; -} - -void myprintf(const char *format, ...) -{ - const char *s; - va_list ap; - va_start(ap, format); - for (s = format; *s; s++) { - if (match(&s, "%7s")) { - struct s7 t7 = va_arg(ap, struct s7); - printf("%.7s", t7.x); - } - else if (match(&s, "%9s")) { - struct s9 t9 = va_arg(ap, struct s9); - printf("%.9s", t9.x); - } - else if (match(&s, "%hfa11")) { - struct hfa11 x = va_arg(ap, struct hfa11); - printf("%.1f,%.1f", x.a, x.a); - } - else if (match(&s, "%hfa12")) { - struct hfa12 x = va_arg(ap, struct hfa12); - printf("%.1f,%.1f", x.a, x.b); - } - else if (match(&s, "%hfa13")) { - struct hfa13 x = va_arg(ap, struct hfa13); - printf("%.1f,%.1f", x.a, x.c); - } - else if (match(&s, "%hfa14")) { - struct hfa14 x = va_arg(ap, struct hfa14); - printf("%.1f,%.1f", x.a, x.d); - } - else if (match(&s, "%hfa21")) { - struct hfa21 x = va_arg(ap, struct hfa21); - printf("%.1f,%.1f", x.a, x.a); - } - else if (match(&s, "%hfa22")) { - struct hfa22 x = va_arg(ap, struct hfa22); - printf("%.1f,%.1f", x.a, x.b); - } - else if (match(&s, "%hfa23")) { - struct hfa23 x = va_arg(ap, struct hfa23); - printf("%.1f,%.1f", x.a, x.c); - } - else if (match(&s, "%hfa24")) { - struct hfa24 x = va_arg(ap, struct hfa24); - printf("%.1f,%.1f", x.a, x.d); - } - else if (match(&s, "%hfa31")) { - struct hfa31 x = va_arg(ap, struct hfa31); - printf("%.1Lf,%.1Lf", x.a, x.a); - } - else if (match(&s, "%hfa32")) { - struct hfa32 x = va_arg(ap, struct hfa32); - printf("%.1Lf,%.1Lf", x.a, x.b); - } - else if (match(&s, "%hfa33")) { - struct hfa33 x = va_arg(ap, struct hfa33); - printf("%.1Lf,%.1Lf", x.a, x.c); - } - else if (match(&s, "%hfa34")) { - struct hfa34 x = va_arg(ap, struct hfa34); - printf("%.1Lf,%.1Lf", x.a, x.d); - } - else - putchar(*s); - } - putchar('\n'); -} - -void stdarg(void) -{ - printf("stdarg:\n"); - myprintf("%9s %9s %9s %9s %9s %9s", s9, s9, s9, s9, s9, s9); - myprintf("%7s %9s %9s %9s %9s %9s", s7, s9, s9, s9, s9, s9); - - myprintf("HFA long double:"); - myprintf("%hfa34 %hfa34 %hfa34 %hfa34", hfa34, hfa34, hfa34, hfa34); - myprintf("%hfa33 %hfa34 %hfa34 %hfa34", hfa33, hfa34, hfa34, hfa34); - myprintf("%hfa32 %hfa34 %hfa34 %hfa34", hfa32, hfa34, hfa34, hfa34); - myprintf("%hfa31 %hfa34 %hfa34 %hfa34", hfa31, hfa34, hfa34, hfa34); - - myprintf("%hfa32 %hfa33 %hfa33 %hfa33 %hfa33", - hfa32, hfa33, hfa33, hfa33, hfa33); - myprintf("%hfa31 %hfa33 %hfa33 %hfa33 %hfa33", - hfa31, hfa33, hfa33, hfa33, hfa33); - myprintf("%hfa33 %hfa33 %hfa33 %hfa33", - hfa33, hfa33, hfa33, hfa33); - - myprintf("%hfa34 %hfa32 %hfa32 %hfa32 %hfa32", - hfa34, hfa32, hfa32, hfa32, hfa32); - myprintf("%hfa33 %hfa32 %hfa32 %hfa32 %hfa32", - hfa33, hfa32, hfa32, hfa32, hfa32); - - myprintf("%hfa34 %hfa32 %hfa31 %hfa31 %hfa31 %hfa31", - hfa34, hfa32, hfa31, hfa31, hfa31, hfa31); - - myprintf("HFA double:"); - myprintf("%hfa24 %hfa24 %hfa24 %hfa24", hfa24, hfa24, hfa24, hfa24); - myprintf("%hfa23 %hfa24 %hfa24 %hfa24", hfa23, hfa24, hfa24, hfa24); - myprintf("%hfa22 %hfa24 %hfa24 %hfa24", hfa22, hfa24, hfa24, hfa24); - myprintf("%hfa21 %hfa24 %hfa24 %hfa24", hfa21, hfa24, hfa24, hfa24); - - myprintf("%hfa22 %hfa23 %hfa23 %hfa23 %hfa23", - hfa22, hfa23, hfa23, hfa23, hfa23); - myprintf("%hfa21 %hfa23 %hfa23 %hfa23 %hfa23", - hfa21, hfa23, hfa23, hfa23, hfa23); - myprintf("%hfa23 %hfa23 %hfa23 %hfa23", - hfa23, hfa23, hfa23, hfa23); - - myprintf("%hfa24 %hfa22 %hfa22 %hfa22 %hfa22", - hfa24, hfa22, hfa22, hfa22, hfa22); - myprintf("%hfa23 %hfa22 %hfa22 %hfa22 %hfa22", - hfa23, hfa22, hfa22, hfa22, hfa22); - - myprintf("%hfa24 %hfa22 %hfa21 %hfa21 %hfa21 %hfa21", - hfa24, hfa22, hfa21, hfa21, hfa21, hfa21); - - myprintf("HFA float:"); - myprintf("%hfa14 %hfa14 %hfa14 %hfa14", hfa14, hfa14, hfa14, hfa14); - myprintf("%hfa13 %hfa14 %hfa14 %hfa14", hfa13, hfa14, hfa14, hfa14); - myprintf("%hfa12 %hfa14 %hfa14 %hfa14", hfa12, hfa14, hfa14, hfa14); - myprintf("%hfa11 %hfa14 %hfa14 %hfa14", hfa11, hfa14, hfa14, hfa14); - - myprintf("%hfa12 %hfa13 %hfa13 %hfa13 %hfa13", - hfa12, hfa13, hfa13, hfa13, hfa13); - myprintf("%hfa11 %hfa13 %hfa13 %hfa13 %hfa13", - hfa11, hfa13, hfa13, hfa13, hfa13); - myprintf("%hfa13 %hfa13 %hfa13 %hfa13", - hfa13, hfa13, hfa13, hfa13); - - myprintf("%hfa14 %hfa12 %hfa12 %hfa12 %hfa12", - hfa14, hfa12, hfa12, hfa12, hfa12); - myprintf("%hfa13 %hfa12 %hfa12 %hfa12 %hfa12", - hfa13, hfa12, hfa12, hfa12, hfa12); - - myprintf("%hfa14 %hfa12 %hfa11 %hfa11 %hfa11 %hfa11", - hfa14, hfa12, hfa11, hfa11, hfa11, hfa11); -} - -void pll(unsigned long long x) -{ - printf("%llx\n", x); -} - -void movi(void) -{ - printf("MOVI:\n"); - pll(0); - pll(0xabcd); - pll(0xabcd0000); - pll(0xabcd00000000); - pll(0xabcd000000000000); - pll(0xffffabcd); - pll(0xabcdffff); - pll(0xffffffffffffabcd); - pll(0xffffffffabcdffff); - pll(0xffffabcdffffffff); - pll(0xabcdffffffffffff); - pll(0xaaaaaaaa); - pll(0x5555555555555555); - pll(0x77777777); - pll(0x3333333333333333); - pll(0xf8f8f8f8); - pll(0x1e1e1e1e1e1e1e1e); - pll(0x3f803f80); - pll(0x01ff01ff01ff01ff); - pll(0x007fffc0); - pll(0x03fff80003fff800); - pll(0x0007fffffffffe00); - - pll(0xabcd1234); - pll(0xabcd00001234); - pll(0xabcd000000001234); - pll(0xabcd12340000); - pll(0xabcd000012340000); - pll(0xabcd123400000000); - pll(0xffffffffabcd1234); - pll(0xffffabcdffff1234); - pll(0xabcdffffffff1234); - pll(0xffffabcd1234ffff); - pll(0xabcdffff1234ffff); - pll(0xabcd1234ffffffff); - - pll(0xffffef0123456789); - pll(0xabcdef012345ffff); - - pll(0xabcdef0123456789); -} - -static uint32_t addip0(uint32_t x) { return x + 0; } -static uint64_t sublp0(uint64_t x) { return x - 0; } -static uint32_t addip123(uint32_t x) { return x + 123; } -static uint64_t addlm123(uint64_t x) { return x + -123; } -static uint64_t sublp4095(uint64_t x) { return x - 4095; } -static uint32_t subim503808(uint32_t x) { return x - -503808; } -static uint64_t addp12345(uint64_t x) { return x + 12345; } -static uint32_t subp12345(uint32_t x) { return x - 12345; } - -static uint32_t mvni(uint32_t x) { return 0xffffffff - x; } -static uint64_t negl(uint64_t x) { return 0 - x; } -static uint32_t rsbi123(uint32_t x) { return 123 - x; } -static uint64_t rsbl123(uint64_t x) { return 123 - x; } - -static uint32_t andi0(uint32_t x) { return x & 0; } -static uint64_t andlm1(uint64_t x) { return x & -1; } -static uint64_t orrl0(uint64_t x) { return x | 0; } -static uint32_t orrim1(uint32_t x) { return x | -1; } -static uint32_t eori0(uint32_t x) { return x ^ 0; } -static uint64_t eorlm1(uint64_t x) { return x ^ -1; } -static uint32_t and0xf0(uint32_t x) { return x & 0xf0; } -static uint64_t orr0xf0(uint64_t x) { return x | 0xf0; } -static uint64_t eor0xf0(uint64_t x) { return x ^ 0xf0; } - -static uint32_t lsli0(uint32_t x) { return x << 0; } -static uint32_t lsri0(uint32_t x) { return x >> 0; } -static int64_t asrl0(int64_t x) { return x >> 0; } -static uint32_t lsli1(uint32_t x) { return x << 1; } -static uint32_t lsli31(uint32_t x) { return x << 31; } -static uint64_t lsll1(uint64_t x) { return x << 1; } -static uint64_t lsll63(uint64_t x) { return x << 63; } -static uint32_t lsri1(uint32_t x) { return x >> 1; } -static uint32_t lsri31(uint32_t x) { return x >> 31; } -static uint64_t lsrl1(uint64_t x) { return x >> 1; } -static uint64_t lsrl63(uint64_t x) { return x >> 63; } -static int32_t asri1(int32_t x) { return x >> 1; } -static int32_t asri31(int32_t x) { return x >> 31; } -static int64_t asrl1(int64_t x) { return x >> 1; } -static int64_t asrl63(int64_t x) { return x >> 63; } - -void opi(void) -{ - int x = 1000; - pll(addip0(x)); - pll(sublp0(x)); - pll(addip123(x)); - pll(addlm123(x)); - pll(sublp4095(x)); - pll(subim503808(x)); - pll(addp12345(x)); - pll(subp12345(x)); - pll(mvni(x)); - pll(negl(x)); - pll(rsbi123(x)); - pll(rsbl123(x)); - pll(andi0(x)); - pll(andlm1(x)); - pll(orrl0(x)); - pll(orrim1(x)); - pll(eori0(x)); - pll(eorlm1(x)); - pll(and0xf0(x)); - pll(orr0xf0(x)); - pll(eor0xf0(x)); - pll(lsli0(x)); - pll(lsri0(x)); - pll(asrl0(x)); - pll(lsli1(x)); - pll(lsli31(x)); - pll(lsll1(x)); - pll(lsll63(x)); - pll(lsri1(x)); - pll(lsri31(x)); - pll(lsrl1(x)); - pll(lsrl63(x)); - pll(asri1(x)); - pll(asri31(x)); - pll(asrl1(x)); - pll(asrl63(x)); -} - -void pcs(void) -{ - arg(); - ret(); - stdarg(); - movi(); - opi(); -} - -int main() -{ - pcs(); - return 0; -} diff --git a/05/tcc-final-old/tests/tests2/73_arm64.expect b/05/tcc-final-old/tests/tests2/73_arm64.expect deleted file mode 100644 index 7bdebd3..0000000 --- a/05/tcc-final-old/tests/tests2/73_arm64.expect +++ /dev/null @@ -1,174 +0,0 @@ -Arguments: -0 -12 -345 -6789 -abcde -fghijk -lmnopqr -stuvwxyz -ABCDEFGHI -JKLMNOPQRS -TUVWXYZ0123 -456789abcdef -ghijklmnopqrs -tuvwxyzABCDEFG -HIJKLMNOPQRSTUV -WXYZ0123456789ab -cdefghijklmnopqrs -11.1 -12.1 12.1 -13.1 13.2 13.3 -14.1 14.2 14.3 14.4 -21.1 -22.1 22.1 -23.1 23.2 23.3 -24.1 24.2 24.3 24.4 -31.1 -32.1 32.1 -33.1 33.2 33.3 -34.1 34.2 34.3 34.4 -stu ABC JKL TUV 456 ghi -ABC JKL TUV 456 ghi tuv -14.1 14.4 23.1 23.3 32.1 32.2 -0 14.1 14.4 12 24.1 24.4 345 34.1 34.4 -Return values: -0 -12 -345 -6789 -abcde -fghijk -lmnopqr -stuvwxyz -ABCDEFGHI -JKLMNOPQRS -TUVWXYZ0123 -456789abcdef -ghijklmnopqrs -tuvwxyzABCDEFG -HIJKLMNOPQRSTUV -WXYZ0123456789ab -cdefghijklmnopqrs -11.1 -12.1 12.2 -13.1 13.3 -14.1 14.4 -21.1 -22.1 22.2 -23.1 23.3 -24.1 24.4 -31.1 -32.1 32.2 -33.1 33.3 -34.1 34.4 -stdarg: -ABCDEFGHI ABCDEFGHI ABCDEFGHI ABCDEFGHI ABCDEFGHI ABCDEFGHI -lmnopqr ABCDEFGHI ABCDEFGHI ABCDEFGHI ABCDEFGHI ABCDEFGHI -HFA long double: -34.1,34.4 34.1,34.4 34.1,34.4 34.1,34.4 -33.1,33.3 34.1,34.4 34.1,34.4 34.1,34.4 -32.1,32.2 34.1,34.4 34.1,34.4 34.1,34.4 -31.1,31.1 34.1,34.4 34.1,34.4 34.1,34.4 -32.1,32.2 33.1,33.3 33.1,33.3 33.1,33.3 33.1,33.3 -31.1,31.1 33.1,33.3 33.1,33.3 33.1,33.3 33.1,33.3 -33.1,33.3 33.1,33.3 33.1,33.3 33.1,33.3 -34.1,34.4 32.1,32.2 32.1,32.2 32.1,32.2 32.1,32.2 -33.1,33.3 32.1,32.2 32.1,32.2 32.1,32.2 32.1,32.2 -34.1,34.4 32.1,32.2 31.1,31.1 31.1,31.1 31.1,31.1 31.1,31.1 -HFA double: -24.1,24.4 24.1,24.4 24.1,24.4 24.1,24.4 -23.1,23.3 24.1,24.4 24.1,24.4 24.1,24.4 -22.1,22.2 24.1,24.4 24.1,24.4 24.1,24.4 -21.1,21.1 24.1,24.4 24.1,24.4 24.1,24.4 -22.1,22.2 23.1,23.3 23.1,23.3 23.1,23.3 23.1,23.3 -21.1,21.1 23.1,23.3 23.1,23.3 23.1,23.3 23.1,23.3 -23.1,23.3 23.1,23.3 23.1,23.3 23.1,23.3 -24.1,24.4 22.1,22.2 22.1,22.2 22.1,22.2 22.1,22.2 -23.1,23.3 22.1,22.2 22.1,22.2 22.1,22.2 22.1,22.2 -24.1,24.4 22.1,22.2 21.1,21.1 21.1,21.1 21.1,21.1 21.1,21.1 -HFA float: -14.1,14.4 14.1,14.4 14.1,14.4 14.1,14.4 -13.1,13.3 14.1,14.4 14.1,14.4 14.1,14.4 -12.1,12.2 14.1,14.4 14.1,14.4 14.1,14.4 -11.1,11.1 14.1,14.4 14.1,14.4 14.1,14.4 -12.1,12.2 13.1,13.3 13.1,13.3 13.1,13.3 13.1,13.3 -11.1,11.1 13.1,13.3 13.1,13.3 13.1,13.3 13.1,13.3 -13.1,13.3 13.1,13.3 13.1,13.3 13.1,13.3 -14.1,14.4 12.1,12.2 12.1,12.2 12.1,12.2 12.1,12.2 -13.1,13.3 12.1,12.2 12.1,12.2 12.1,12.2 12.1,12.2 -14.1,14.4 12.1,12.2 11.1,11.1 11.1,11.1 11.1,11.1 11.1,11.1 -MOVI: -0 -abcd -abcd0000 -abcd00000000 -abcd000000000000 -ffffabcd -abcdffff -ffffffffffffabcd -ffffffffabcdffff -ffffabcdffffffff -abcdffffffffffff -aaaaaaaa -5555555555555555 -77777777 -3333333333333333 -f8f8f8f8 -1e1e1e1e1e1e1e1e -3f803f80 -1ff01ff01ff01ff -7fffc0 -3fff80003fff800 -7fffffffffe00 -abcd1234 -abcd00001234 -abcd000000001234 -abcd12340000 -abcd000012340000 -abcd123400000000 -ffffffffabcd1234 -ffffabcdffff1234 -abcdffffffff1234 -ffffabcd1234ffff -abcdffff1234ffff -abcd1234ffffffff -ffffef0123456789 -abcdef012345ffff -abcdef0123456789 -3e8 -3e8 -463 -36d -fffffffffffff3e9 -7b3e8 -3421 -ffffd3af -fffffc17 -fffffffffffffc18 -fffffc93 -fffffffffffffc93 -0 -3e8 -3e8 -ffffffff -3e8 -fffffffffffffc17 -e0 -3f8 -318 -3e8 -3e8 -3e8 -7d0 -0 -7d0 -0 -1f4 -0 -1f4 -0 -1f4 -0 -1f4 -0 diff --git a/05/tcc-final-old/tests/tests2/75_array_in_struct_init.c b/05/tcc-final-old/tests/tests2/75_array_in_struct_init.c deleted file mode 100644 index 234e3c4..0000000 --- a/05/tcc-final-old/tests/tests2/75_array_in_struct_init.c +++ /dev/null @@ -1,33 +0,0 @@ -#include - -/* This test is a snippet from the J interpreter */ - -typedef long I; -typedef struct{I c[4];I b,e,k;} PT; - -PT cases[] = { - ((I)4194304L +(I)2097152L +(I)67108864L), (I)262144L, (((I)1L +(I)256L +(I)4L +(I)8L +(I)16L +(I)64L +(I)128L +(I)268435456L +(I)536870912L +(I)1024L +(I)4096L +(I)8192L +(I)16384L)+((I)2L +(I)131072L +(I)2048L)+(I)32L +(I)32768L +(I)65536L), -1L, 1,2,1, - ((I)+4194304L +(I)2097152L +(I)67108864L)+( (I)524288L +(I)262144L +(((I)1L +(I)256L +(I)4L +(I)8L +(I)16L +(I)64L +(I)128L +(I)268435456L +(I)536870912L +(I)1024L +(I)4096L +(I)8192L +(I)16384L)+((I)2L +(I)131072L +(I)2048L)+(I)32L +(I)32768L +(I)65536L)), (I)262144L, (I)262144L, (((I)1L +(I)256L +(I)4L +(I)8L +(I)16L +(I)64L +(I)128L +(I)268435456L +(I)536870912L +(I)1024L +(I)4096L +(I)8192L +(I)16384L)+((I)2L +(I)131072L +(I)2048L)+(I)32L +(I)32768L +(I)65536L), 2,3,2, - ((I)4194304L +(I)2097152L +(I)67108864L)+( (I)524288L +(I)262144L +(((I)1L +(I)256L +(I)4L +(I)8L +(I)16L +(I)64L +(I)128L +(I)268435456L +(I)536870912L +(I)1024L +(I)4096L +(I)8192L +(I)16384L)+((I)2L +(I)131072L +(I)2048L)+(I)32L +(I)32768L +(I)65536L)), (((I)1L +(I)256L +(I)4L +(I)8L +(I)16L +(I)64L +(I)128L +(I)268435456L +(I)536870912L +(I)1024L +(I)4096L +(I)8192L +(I)16384L)+((I)2L +(I)131072L +(I)2048L)+(I)32L +(I)32768L +(I)65536L), (I)262144L, (((I)1L +(I)256L +(I)4L +(I)8L +(I)16L +(I)64L +(I)128L +(I)268435456L +(I)536870912L +(I)1024L +(I)4096L +(I)8192L +(I)16384L)+((I)2L +(I)131072L +(I)2048L)+(I)32L +(I)32768L +(I)65536L), 1,3,2, - ((I)4194304L +(I)2097152L +(I)67108864L)+( (I)524288L +(I)262144L +(((I)1L +(I)256L +(I)4L +(I)8L +(I)16L +(I)64L +(I)128L +(I)268435456L +(I)536870912L +(I)1024L +(I)4096L +(I)8192L +(I)16384L)+((I)2L +(I)131072L +(I)2048L)+(I)32L +(I)32768L +(I)65536L)), (I)262144L +(((I)1L +(I)256L +(I)4L +(I)8L +(I)16L +(I)64L +(I)128L +(I)268435456L +(I)536870912L +(I)1024L +(I)4096L +(I)8192L +(I)16384L)+((I)2L +(I)131072L +(I)2048L)+(I)32L +(I)32768L +(I)65536L), (I)524288L, -1L, 1,2,1, - ((I)4194304L +(I)2097152L +(I)67108864L)+( (I)524288L +(I)262144L +(((I)1L +(I)256L +(I)4L +(I)8L +(I)16L +(I)64L +(I)128L +(I)268435456L +(I)536870912L +(I)1024L +(I)4096L +(I)8192L +(I)16384L)+((I)2L +(I)131072L +(I)2048L)+(I)32L +(I)32768L +(I)65536L)), (I)262144L +(((I)1L +(I)256L +(I)4L +(I)8L +(I)16L +(I)64L +(I)128L +(I)268435456L +(I)536870912L +(I)1024L +(I)4096L +(I)8192L +(I)16384L)+((I)2L +(I)131072L +(I)2048L)+(I)32L +(I)32768L +(I)65536L), (I)1048576L, (I)262144L +(((I)1L +(I)256L +(I)4L +(I)8L +(I)16L +(I)64L +(I)128L +(I)268435456L +(I)536870912L +(I)1024L +(I)4096L +(I)8192L +(I)16384L)+((I)2L +(I)131072L +(I)2048L)+(I)32L +(I)32768L +(I)65536L), 1,3,1, - ((I)4194304L +(I)2097152L +(I)67108864L)+( (I)524288L +(I)262144L +(((I)1L +(I)256L +(I)4L +(I)8L +(I)16L +(I)64L +(I)128L +(I)268435456L +(I)536870912L +(I)1024L +(I)4096L +(I)8192L +(I)16384L)+((I)2L +(I)131072L +(I)2048L)+(I)32L +(I)32768L +(I)65536L)), (I)262144L +(((I)1L +(I)256L +(I)4L +(I)8L +(I)16L +(I)64L +(I)128L +(I)268435456L +(I)536870912L +(I)1024L +(I)4096L +(I)8192L +(I)16384L)+((I)2L +(I)131072L +(I)2048L)+(I)32L +(I)32768L +(I)65536L), (I)262144L, (I)262144L, 1,3,1, - ((I)4194304L +(I)2097152L +(I)67108864L), ((I)1048576L +(I)524288L +(I)262144L +(((I)1L +(I)256L +(I)4L +(I)8L +(I)16L +(I)64L +(I)128L +(I)268435456L +(I)536870912L +(I)1024L +(I)4096L +(I)8192L +(I)16384L)+((I)2L +(I)131072L +(I)2048L)+(I)32L +(I)32768L +(I)65536L)), ((I)1048576L +(I)524288L +(I)262144L +(((I)1L +(I)256L +(I)4L +(I)8L +(I)16L +(I)64L +(I)128L +(I)268435456L +(I)536870912L +(I)1024L +(I)4096L +(I)8192L +(I)16384L)+((I)2L +(I)131072L +(I)2048L)+(I)32L +(I)32768L +(I)65536L)), -1L, 1,2,1, - (I)33554432L +(((I)1L +(I)256L +(I)4L +(I)8L +(I)16L +(I)64L +(I)128L +(I)268435456L +(I)536870912L +(I)1024L +(I)4096L +(I)8192L +(I)16384L)+((I)2L +(I)131072L +(I)2048L)+(I)32L +(I)32768L +(I)65536L), (I)2097152L, ((I)1048576L +(I)524288L +(I)262144L +(((I)1L +(I)256L +(I)4L +(I)8L +(I)16L +(I)64L +(I)128L +(I)268435456L +(I)536870912L +(I)1024L +(I)4096L +(I)8192L +(I)16384L)+((I)2L +(I)131072L +(I)2048L)+(I)32L +(I)32768L +(I)65536L)), -1L, 0,2,1, - (I)67108864L, ((I)1048576L +(I)524288L +(I)262144L +(((I)1L +(I)256L +(I)4L +(I)8L +(I)16L +(I)64L +(I)128L +(I)268435456L +(I)536870912L +(I)1024L +(I)4096L +(I)8192L +(I)16384L)+((I)2L +(I)131072L +(I)2048L)+(I)32L +(I)32768L +(I)65536L)), (I)134217728L, -1L, 0,2,0, -}; - -int main() { - int i, j; - - for(j=0; j < sizeof(cases)/sizeof(cases[0]); j++) { - for(i=0; i < sizeof(cases->c)/sizeof(cases->c[0]); i++) - printf("cases[%d].c[%d]=%ld\n", j, i, cases[j].c[i]); - - printf("cases[%d].b=%ld\n", j, cases[j].b); - printf("cases[%d].e=%ld\n", j, cases[j].e); - printf("cases[%d].k=%ld\n", j, cases[j].k); - printf("\n"); - } - return 0; -} diff --git a/05/tcc-final-old/tests/tests2/75_array_in_struct_init.expect b/05/tcc-final-old/tests/tests2/75_array_in_struct_init.expect deleted file mode 100644 index 2b75aa5..0000000 --- a/05/tcc-final-old/tests/tests2/75_array_in_struct_init.expect +++ /dev/null @@ -1,72 +0,0 @@ -cases[0].c[0]=73400320 -cases[0].c[1]=262144 -cases[0].c[2]=805567999 -cases[0].c[3]=-1 -cases[0].b=1 -cases[0].e=2 -cases[0].k=1 - -cases[1].c[0]=879754751 -cases[1].c[1]=262144 -cases[1].c[2]=262144 -cases[1].c[3]=805567999 -cases[1].b=2 -cases[1].e=3 -cases[1].k=2 - -cases[2].c[0]=879754751 -cases[2].c[1]=805567999 -cases[2].c[2]=262144 -cases[2].c[3]=805567999 -cases[2].b=1 -cases[2].e=3 -cases[2].k=2 - -cases[3].c[0]=879754751 -cases[3].c[1]=805830143 -cases[3].c[2]=524288 -cases[3].c[3]=-1 -cases[3].b=1 -cases[3].e=2 -cases[3].k=1 - -cases[4].c[0]=879754751 -cases[4].c[1]=805830143 -cases[4].c[2]=1048576 -cases[4].c[3]=805830143 -cases[4].b=1 -cases[4].e=3 -cases[4].k=1 - -cases[5].c[0]=879754751 -cases[5].c[1]=805830143 -cases[5].c[2]=262144 -cases[5].c[3]=262144 -cases[5].b=1 -cases[5].e=3 -cases[5].k=1 - -cases[6].c[0]=73400320 -cases[6].c[1]=807403007 -cases[6].c[2]=807403007 -cases[6].c[3]=-1 -cases[6].b=1 -cases[6].e=2 -cases[6].k=1 - -cases[7].c[0]=839122431 -cases[7].c[1]=2097152 -cases[7].c[2]=807403007 -cases[7].c[3]=-1 -cases[7].b=0 -cases[7].e=2 -cases[7].k=1 - -cases[8].c[0]=67108864 -cases[8].c[1]=807403007 -cases[8].c[2]=134217728 -cases[8].c[3]=-1 -cases[8].b=0 -cases[8].e=2 -cases[8].k=0 - diff --git a/05/tcc-final-old/tests/tests2/76_dollars_in_identifiers.c b/05/tcc-final-old/tests/tests2/76_dollars_in_identifiers.c deleted file mode 100644 index c5fcf99..0000000 --- a/05/tcc-final-old/tests/tests2/76_dollars_in_identifiers.c +++ /dev/null @@ -1,41 +0,0 @@ -#include - -#define $(x) x -#define $fred 10 -#define joe$ 20 -#define hen$y 30 - -#define $10(x) x*10 -#define _$10(x) x/10 - -int main() -{ - printf("fred=%d\n", $fred); - printf("joe=%d\n", joe$); - printf("henry=%d\n", hen$y); - - printf("fred2=%d\n", $($fred)); - printf("joe2=%d\n", $(joe$)); - printf("henry2=%d\n", $(hen$y)); - - printf("fred10=%d\n", $10($fred)); - printf("joe_10=%d\n", _$10(joe$)); - - int $ = 10; - int a100$ = 100; - int a$$ = 1000; - int a$c$b = 2121; - int $100 = 10000; - const char *$$$ = "money"; - - printf("local=%d\n", $); - printf("a100$=%d\n", a100$); - printf("a$$=%d\n", a$$); - printf("a$c$b=%d\n", a$c$b); - printf("$100=%d\n", $100); - printf("$$$=%s", $$$); - - return 0; -} - -/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ diff --git a/05/tcc-final-old/tests/tests2/76_dollars_in_identifiers.expect b/05/tcc-final-old/tests/tests2/76_dollars_in_identifiers.expect deleted file mode 100644 index 4a20a52..0000000 --- a/05/tcc-final-old/tests/tests2/76_dollars_in_identifiers.expect +++ /dev/null @@ -1,14 +0,0 @@ -fred=10 -joe=20 -henry=30 -fred2=10 -joe2=20 -henry2=30 -fred10=100 -joe_10=2 -local=10 -a100$=100 -a$$=1000 -a$c$b=2121 -$100=10000 -$$$=money diff --git a/05/tcc-final-old/tests/tests2/77_push_pop_macro.c b/05/tcc-final-old/tests/tests2/77_push_pop_macro.c deleted file mode 100644 index d38e0bf..0000000 --- a/05/tcc-final-old/tests/tests2/77_push_pop_macro.c +++ /dev/null @@ -1,30 +0,0 @@ -#include - -int main() -{ - /* must not affect how #pragma ppop_macro works */ - #define pop_macro foobar1 - - /* must not affect how #pragma push_macro works */ - #define push_macro foobar2 - - #undef abort - #define abort "111" - printf("abort = %s\n", abort); - - #pragma push_macro("abort") - #undef abort - #define abort "222" - printf("abort = %s\n", abort); - - #pragma push_macro("abort") - #undef abort - #define abort "333" - printf("abort = %s\n", abort); - - #pragma pop_macro("abort") - printf("abort = %s\n", abort); - - #pragma pop_macro("abort") - printf("abort = %s\n", abort); -} diff --git a/05/tcc-final-old/tests/tests2/77_push_pop_macro.expect b/05/tcc-final-old/tests/tests2/77_push_pop_macro.expect deleted file mode 100644 index d8a5530..0000000 --- a/05/tcc-final-old/tests/tests2/77_push_pop_macro.expect +++ /dev/null @@ -1,5 +0,0 @@ -abort = 111 -abort = 222 -abort = 333 -abort = 222 -abort = 111 diff --git a/05/tcc-final-old/tests/tests2/78_vla_label.c b/05/tcc-final-old/tests/tests2/78_vla_label.c deleted file mode 100644 index 4096495..0000000 --- a/05/tcc-final-old/tests/tests2/78_vla_label.c +++ /dev/null @@ -1,45 +0,0 @@ -#include - -/* This test segfaults as of April 27, 2015. */ -void f1(int argc) -{ - char test[argc]; - if(0) - label: - printf("boom!\n"); - if(argc-- == 0) - return; - goto label; -} - -/* This segfaulted on 2015-11-19. */ -void f2(void) -{ - goto start; - { - int a[1 && 1]; /* not a variable-length array */ - int b[1 || 1]; /* not a variable-length array */ - int c[1 ? 1 : 1]; /* not a variable-length array */ - start: - a[0] = 0; - b[0] = 0; - c[0] = 0; - } -} - -void f3(void) -{ - printf("%d\n", 0 ? printf("x1\n") : 11); - printf("%d\n", 1 ? 12 : printf("x2\n")); - printf("%d\n", 0 && printf("x3\n")); - printf("%d\n", 1 || printf("x4\n")); -} - -int main() -{ - f1(2); - f2(); - f3(); - - return 0; -} diff --git a/05/tcc-final-old/tests/tests2/78_vla_label.expect b/05/tcc-final-old/tests/tests2/78_vla_label.expect deleted file mode 100644 index 3f4063b..0000000 --- a/05/tcc-final-old/tests/tests2/78_vla_label.expect +++ /dev/null @@ -1,6 +0,0 @@ -boom! -boom! -11 -12 -0 -1 diff --git a/05/tcc-final-old/tests/tests2/79_vla_continue.c b/05/tcc-final-old/tests/tests2/79_vla_continue.c deleted file mode 100644 index 91215c9..0000000 --- a/05/tcc-final-old/tests/tests2/79_vla_continue.c +++ /dev/null @@ -1,116 +0,0 @@ -#include - -int f(void) -{ - return 5; -} - -void test1() -{ - int count = 10; - void *addr[10]; - for(;count--;) { - int a[f()]; - - addr[count] = a; - - continue; - } - - if(addr[9] == addr[0]) { - printf("OK\n"); - } else { - printf("NOT OK\n"); - } -} - -void test2() -{ - int count = 10; - void *addr[count]; - for(;count--;) { - int a[f()]; - - addr[count] = a; - - continue; - } - - if(addr[9] == addr[0]) { - printf("OK\n"); - } else { - printf("NOT OK\n"); - } -} - -void test3() -{ - int count = 10; - void *addr[count]; - while(count--) { - int a[f()]; - - addr[count] = a; - - continue; - } - - if(addr[9] == addr[0]) { - printf("OK\n"); - } else { - printf("NOT OK\n"); - } -} - -void test4() -{ - int count = 10; - void *addr[count]; - do { - int a[f()]; - - addr[--count] = a; - - continue; - } while (count); - - if(addr[9] == addr[0]) { - printf("OK\n"); - } else { - printf("NOT OK\n"); - } -} - -void test5() -{ - int count = 10; - int a[f()]; - int c[f()]; - - c[0] = 42; - - for(;count--;) { - int b[f()]; - int i; - for (i=0; i -struct wchar { - char *data; char mem[]; -}; -struct wint { - char *data; int mem[]; -}; -int f1char (void) { - char s[9]="nonono"; - struct wchar q = {"bugs"}; - return !s[0]; -} -int f1int (void) { - char s[9]="nonono"; - struct wint q = {"bugs"}; - return !s[0]; -} -int main (void) { - char s[9]="nonono"; - static struct wchar q = {"bugs", {'c'}}; - //printf ("tcc has %s %s\n", s, q.data); - if (f1char() || f1int()) - printf ("bla\n"); - return !s[0]; -} diff --git a/05/tcc-final-old/tests/tests2/80_flexarray.expect b/05/tcc-final-old/tests/tests2/80_flexarray.expect deleted file mode 100644 index e69de29..0000000 diff --git a/05/tcc-final-old/tests/tests2/81_types.c b/05/tcc-final-old/tests/tests2/81_types.c deleted file mode 100644 index fd6d71b..0000000 --- a/05/tcc-final-old/tests/tests2/81_types.c +++ /dev/null @@ -1,43 +0,0 @@ -/* The following are all valid decls, even though some subtypes - are incomplete. */ -enum E *e; -const enum E *e1; -enum E const *e2; -struct S *s; -const struct S *s1; -struct S const *s2; - -/* Various strangely looking declarators, which are all valid - and have to map to the same numbered typedefs. */ -typedef int (*fptr1)(); -int f1 (int (), int); -typedef int (*fptr2)(int x); -int f2 (int (int x), int); -typedef int (*fptr3)(int); -int f3 (int (int), int); -typedef int (*fptr4[4])(int); -int f4 (int (*[4])(int), int); -typedef int (*fptr5)(fptr1); -int f5 (int (int()), fptr1); -int f1 (fptr1 fp, int i) -{ - return (*fp)(i); -} -int f2 (fptr2 fp, int i) -{ - return (*fp)(i); -} -int f3 (fptr3 fp, int i) -{ - return (*fp)(i); -} -int f4 (fptr4 fp, int i) -{ - return (*fp[i])(i); -} -int f5 (fptr5 fp, fptr1 i) -{ - return fp(i); -} -int f8 (int ([4]), int); -int main () { return 0; } diff --git a/05/tcc-final-old/tests/tests2/81_types.expect b/05/tcc-final-old/tests/tests2/81_types.expect deleted file mode 100644 index e69de29..0000000 diff --git a/05/tcc-final-old/tests/tests2/82_attribs_position.c b/05/tcc-final-old/tests/tests2/82_attribs_position.c deleted file mode 100644 index 7c9f987..0000000 --- a/05/tcc-final-old/tests/tests2/82_attribs_position.c +++ /dev/null @@ -1,19 +0,0 @@ -typedef unsigned short uint16_t; -typedef unsigned char uint8_t; - -typedef union Unaligned16a { - uint16_t u; - uint8_t b[2]; -} __attribute__((packed)) Unaligned16a; - -typedef union __attribute__((packed)) Unaligned16b { - uint16_t u; - uint8_t b[2]; -} Unaligned16b; - -extern void foo (void) __attribute__((stdcall)); -void __attribute__((stdcall)) foo (void) -{ -} - -int main () { return 0; } diff --git a/05/tcc-final-old/tests/tests2/82_attribs_position.expect b/05/tcc-final-old/tests/tests2/82_attribs_position.expect deleted file mode 100644 index e69de29..0000000 diff --git a/05/tcc-final-old/tests/tests2/83_utf8_in_identifiers.c b/05/tcc-final-old/tests/tests2/83_utf8_in_identifiers.c deleted file mode 100644 index 1f86095..0000000 --- a/05/tcc-final-old/tests/tests2/83_utf8_in_identifiers.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -double привет=0.1; -int Lefèvre=2; -int main(){ - printf("привет=%g\n",привет); - printf("Lefèvre=%d\n",Lefèvre); - return 0; -} -// pcc & tcc only diff --git a/05/tcc-final-old/tests/tests2/83_utf8_in_identifiers.expect b/05/tcc-final-old/tests/tests2/83_utf8_in_identifiers.expect deleted file mode 100644 index 1553f5f..0000000 --- a/05/tcc-final-old/tests/tests2/83_utf8_in_identifiers.expect +++ /dev/null @@ -1,2 +0,0 @@ -привет=0.1 -Lefèvre=2 diff --git a/05/tcc-final-old/tests/tests2/84_hex-float.c b/05/tcc-final-old/tests/tests2/84_hex-float.c deleted file mode 100644 index 0ef09bf..0000000 --- a/05/tcc-final-old/tests/tests2/84_hex-float.c +++ /dev/null @@ -1,12 +0,0 @@ -extern int printf(const char *format, ...); - -#define ACPI_TYPE_INVALID 0x1E -#define NUM_NS_TYPES ACPI_TYPE_INVALID+1 -int array[NUM_NS_TYPES]; - -#define n 0xe -int main() -{ - printf("n+1 = %d\n", n+1); -// printf("n+1 = %d\n", 0xe+1); -} diff --git a/05/tcc-final-old/tests/tests2/84_hex-float.expect b/05/tcc-final-old/tests/tests2/84_hex-float.expect deleted file mode 100644 index 2175385..0000000 --- a/05/tcc-final-old/tests/tests2/84_hex-float.expect +++ /dev/null @@ -1 +0,0 @@ -n+1 = 15 diff --git a/05/tcc-final-old/tests/tests2/85_asm-outside-function.c b/05/tcc-final-old/tests/tests2/85_asm-outside-function.c deleted file mode 100644 index dc5639a..0000000 --- a/05/tcc-final-old/tests/tests2/85_asm-outside-function.c +++ /dev/null @@ -1,9 +0,0 @@ -extern int printf (const char *, ...); -extern void vide(void); -__asm__("vide: ret"); - -int main() { - vide(); - printf ("okay\n"); - return 0; -} diff --git a/05/tcc-final-old/tests/tests2/85_asm-outside-function.expect b/05/tcc-final-old/tests/tests2/85_asm-outside-function.expect deleted file mode 100644 index dcf02b2..0000000 --- a/05/tcc-final-old/tests/tests2/85_asm-outside-function.expect +++ /dev/null @@ -1 +0,0 @@ -okay diff --git a/05/tcc-final-old/tests/tests2/86_memory-model.c b/05/tcc-final-old/tests/tests2/86_memory-model.c deleted file mode 100644 index 744c3e2..0000000 --- a/05/tcc-final-old/tests/tests2/86_memory-model.c +++ /dev/null @@ -1,38 +0,0 @@ -#include - -int -main() -{ -#if defined(__LLP64__) - if (sizeof(short) == 2 - && sizeof(int) == 4 - && sizeof(long int) == 4 - && sizeof(long long int) == 8 - && sizeof(void*) == 8) { - (void)printf("Ok\n"); - } else { - (void)printf("KO __LLP64__\n"); - } -#elif defined(__LP64__) - if (sizeof(short) == 2 - && sizeof(int) == 4 - && sizeof(long int) == 8 - && sizeof(long long int) == 8 - && sizeof(void*) == 8) { - (void)printf("Ok\n"); - } else { - (void)printf("KO __LP64__\n"); - } -#elif defined(__ILP32__) - if (sizeof(short) == 2 - && sizeof(int) == 4 - && sizeof(long int) == 4 - && sizeof(void*) == 4) { - (void)printf("Ok\n"); - } else { - (void)printf("KO __ILP32__\n"); - } -#else - (void)printf("KO no __*LP*__ defined.\n"); -#endif -} diff --git a/05/tcc-final-old/tests/tests2/86_memory-model.expect b/05/tcc-final-old/tests/tests2/86_memory-model.expect deleted file mode 100644 index 7326d96..0000000 --- a/05/tcc-final-old/tests/tests2/86_memory-model.expect +++ /dev/null @@ -1 +0,0 @@ -Ok diff --git a/05/tcc-final-old/tests/tests2/87_dead_code.c b/05/tcc-final-old/tests/tests2/87_dead_code.c deleted file mode 100644 index 98d4566..0000000 --- a/05/tcc-final-old/tests/tests2/87_dead_code.c +++ /dev/null @@ -1,122 +0,0 @@ -/* This checks various ways of dead code inside if statements - where there are non-obvious ways of how the code is actually - not dead due to reachable by labels. */ -extern int printf (const char *, ...); -static void kb_wait_1(void) -{ - unsigned long timeout = 2; - do { - /* Here the else arm is a statement expression that's supposed - to be suppressed. The label inside the while would unsuppress - code generation again if not handled correctly. And that - would wreak havoc to the cond-expression because there's no - jump-around emitted, the whole statement expression really - needs to not generate code (perhaps except useless forward jumps). */ - (1 ? - printf("timeout=%ld\n", timeout) : - ({ - int i = 1; - while (1) - while (i--) - some_label: - printf("error\n"); - goto some_label; - }) - ); - timeout--; - } while (timeout); -} -int main (void) -{ - int i = 1; - kb_wait_1(); - - /* Simple test of dead code at first sight which isn't actually dead. */ - if (0) { -yeah: - printf ("yeah\n"); - } else { - printf ("boo\n"); - } - if (i--) - goto yeah; - - /* Some more non-obvious uses where the problems are loops, so that even - the first loop statements aren't actually dead. */ - i = 1; - if (0) { - while (i--) { - printf ("once\n"); -enterloop: - printf ("twice\n"); - } - } - if (i >= 0) - goto enterloop; - - /* The same with statement expressions. One might be tempted to - handle them specially by counting if inside statement exprs and - not unsuppressing code at loops at all then. - See kb_wait_1 for the other side of the medal where that wouldn't work. */ - i = ({ - int j = 1; - if (0) { - while (j--) { - printf ("SEonce\n"); - enterexprloop: - printf ("SEtwice\n"); - } - } - if (j >= 0) - goto enterexprloop; - j; }); - - /* The other two loop forms: */ - i = 1; - if (0) { - for (i = 1; i--;) { - printf ("once2\n"); -enterloop2: - printf ("twice2\n"); - } - } - if (i > 0) - goto enterloop2; - - i = 1; - if (0) { - do { - printf ("once3\n"); -enterloop3: - printf ("twice3\n"); - } while (i--); - } - if (i > 0) - goto enterloop3; - - /* And check that case and default labels have the same effect - of disabling code suppression. */ - i = 41; - switch (i) { - if (0) { - printf ("error\n"); - case 42: - printf ("error2\n"); - case 41: - printf ("caseok\n"); - } - } - - i = 41; - switch (i) { - if (0) { - printf ("error3\n"); - default: - printf ("caseok2\n"); - break; - case 42: - printf ("error4\n"); - } - } - return 0; -} diff --git a/05/tcc-final-old/tests/tests2/87_dead_code.expect b/05/tcc-final-old/tests/tests2/87_dead_code.expect deleted file mode 100644 index 0b3ec1d..0000000 --- a/05/tcc-final-old/tests/tests2/87_dead_code.expect +++ /dev/null @@ -1,18 +0,0 @@ -timeout=2 -timeout=1 -boo -yeah -twice -once -twice -SEtwice -SEonce -SEtwice -twice2 -once2 -twice2 -twice3 -once3 -twice3 -caseok -caseok2 diff --git a/05/tcc-final-old/tests/tests2/88_codeopt.c b/05/tcc-final-old/tests/tests2/88_codeopt.c deleted file mode 100644 index 647626f..0000000 --- a/05/tcc-final-old/tests/tests2/88_codeopt.c +++ /dev/null @@ -1,68 +0,0 @@ -/* Check some way in where code suppression caused various - miscompilations. */ -extern int printf (const char *, ...); -typedef unsigned long size_t; - -size_t _brk_start, _brk_end; -void * extend_brk(size_t size, size_t align) -{ - size_t mask = align - 1; - void *ret = 0; - - do { - if (__builtin_expect(!!(_brk_start == 0), 0)) - do { - printf("wrong1\n"); - } while (0); - } while (0); - _brk_end = (_brk_end + mask) & ~mask; - ret = (void *)_brk_end; - _brk_end += size; - - return ret; -} - -static void get_args (int a, int b) -{ - if (a != 1) - printf("wrong2\n"); - else - printf("okay\n"); -} - -void bla(void) -{ - int __ret = 42; - ({ - if (__builtin_expect(!!(0), 0)) { - if (__builtin_expect(!!__ret, 0)) - printf("wrong3\n"); - int x = !!(__ret); - } - __ret; - }); - get_args(!!__ret, sizeof(__ret)); -} - -_Bool chk(unsigned long addr, unsigned long limit, unsigned long size) -{ - _Bool ret; - /* This just needs to compile, no runtime test. (And it doesn't compile - only with certain internal checking added that's not committed). */ - if (0) - ret = 0 != (!!(addr > limit - size)); -} - -int main() -{ - void *r; - _brk_start = 1024; - _brk_end = 1024; - r = extend_brk (4096, 16); - if (!r) - printf("wrong4\n"); - else - printf("okay\n"); - bla(); - return 0; -} diff --git a/05/tcc-final-old/tests/tests2/88_codeopt.expect b/05/tcc-final-old/tests/tests2/88_codeopt.expect deleted file mode 100644 index 439edfd..0000000 --- a/05/tcc-final-old/tests/tests2/88_codeopt.expect +++ /dev/null @@ -1,2 +0,0 @@ -okay -okay diff --git a/05/tcc-final-old/tests/tests2/89_nocode_wanted.c b/05/tcc-final-old/tests/tests2/89_nocode_wanted.c deleted file mode 100644 index 73e0a4b..0000000 --- a/05/tcc-final-old/tests/tests2/89_nocode_wanted.c +++ /dev/null @@ -1,112 +0,0 @@ -extern int printf(const char *format, ...); -static void kb_wait_1(void) -{ - unsigned long timeout = 2; - do { - (1 ? - printf("timeout=%ld\n", timeout) : - ({ - while (1) - printf("error\n"); - }) - ); - timeout--; - } while (timeout); -} -static void kb_wait_2(void) -{ - unsigned long timeout = 2; - do { - (1 ? - printf("timeout=%ld\n", timeout) : - ({ - for (;;) - printf("error\n"); - }) - ); - timeout--; - } while (timeout); -} -static void kb_wait_2_1(void) -{ - unsigned long timeout = 2; - do { - (1 ? - printf("timeout=%ld\n", timeout) : - ({ - do { - printf("error\n"); - } while (1); - }) - ); - timeout--; - } while (timeout); -} -static void kb_wait_2_2(void) -{ - unsigned long timeout = 2; - do { - (1 ? - printf("timeout=%ld\n", timeout) : - ({ - label: - printf("error\n"); - goto label; - }) - ); - timeout--; - } while (timeout); -} -static void kb_wait_3(void) -{ - unsigned long timeout = 2; - do { - (1 ? - printf("timeout=%ld\n", timeout) : - ({ - int i = 1; - goto label; - i = i + 2; - label: - i = i + 3; - }) - ); - timeout--; - } while (timeout); -} -static void kb_wait_4(void) -{ - unsigned long timeout = 2; - do { - (1 ? - printf("timeout=%ld\n", timeout) : - ({ - switch(timeout) { - case 2: - printf("timeout is 2"); - break; - case 1: - printf("timeout is 1"); - break; - default: - printf("timeout is 0?"); - break; - }; - // return; - }) - ); - timeout--; - } while (timeout); -} -int main() -{ - printf("begin\n"); - kb_wait_1(); - kb_wait_2(); - kb_wait_2_1(); - kb_wait_2_2(); - kb_wait_3(); - kb_wait_4(); - printf("end\n"); - return 0; -} diff --git a/05/tcc-final-old/tests/tests2/89_nocode_wanted.expect b/05/tcc-final-old/tests/tests2/89_nocode_wanted.expect deleted file mode 100644 index c44d4ea..0000000 --- a/05/tcc-final-old/tests/tests2/89_nocode_wanted.expect +++ /dev/null @@ -1,14 +0,0 @@ -begin -timeout=2 -timeout=1 -timeout=2 -timeout=1 -timeout=2 -timeout=1 -timeout=2 -timeout=1 -timeout=2 -timeout=1 -timeout=2 -timeout=1 -end diff --git a/05/tcc-final-old/tests/tests2/90_struct-init.c b/05/tcc-final-old/tests/tests2/90_struct-init.c deleted file mode 100644 index d931e23..0000000 --- a/05/tcc-final-old/tests/tests2/90_struct-init.c +++ /dev/null @@ -1,282 +0,0 @@ -typedef unsigned char u8; -typedef struct {} empty_s; -struct contains_empty { - u8 a; - empty_s empty; - u8 b; -}; -struct contains_empty ce = { { (1) }, (empty_s){}, 022, }; -/* The following decl of 'q' would demonstrate the TCC bug in init_putv when - handling copying compound literals. (Compound literals - aren't acceptable constant initializers in isoc99, but - we accept them like gcc, except for this case) -//char *q = (char *){ "trara" }; */ -struct SS {u8 a[3], b; }; -struct SS sinit16[] = { { 1 }, 2 }; -struct S -{ - u8 a,b; - u8 c[2]; -}; - -struct T -{ - u8 s[16]; - u8 a; -}; - -struct U -{ - u8 a; - struct S s; - u8 b; - struct T t; -}; - -struct V -{ - struct S s; - struct T t; - u8 a; -}; - -struct W -{ - struct V t; - struct S s[]; -}; - -struct S gs = ((struct S){1, 2, 3, 4}); -struct S gs2 = {1, 2, {3, 4}}; -struct T gt = {"hello", 42}; -struct U gu = {3, 5,6,7,8, 4, "huhu", 43}; -struct U gu2 = {3, {5,6,7,8}, 4, {"huhu", 43}}; -/* Optional braces around scalar initializers. Accepted, but with - a warning. */ -struct U gu3 = { {3}, {5,6,7,8,}, 4, {"huhu", 43}}; -/* Many superfluous braces and leaving out one initializer for U.s.c[1] */ -struct U gu4 = { 3, {5,6,7,}, 5, { "bla", {44}} }; -/* Superfluous braces and useless parens around values */ -struct S gs3 = { (1), {(2)}, {(((3))), {4}}}; -/* Superfluous braces, and leaving out braces for V.t, plus cast */ -struct V gv = {{{3},4,{5,6}}, "haha", (u8)45, 46}; -/* Compound literal */ -struct V gv2 = {(struct S){7,8,{9,10}}, {"hihi", 47}, 48}; -/* Parens around compound literal */ -struct V gv3 = {((struct S){7,8,{9,10}}), {"hoho", 49}, 50}; -/* Initialization of a flex array member (warns in GCC) */ -struct W gw = {{1,2,3,4}, {1,2,3,4,5}}; - -union UU { - u8 a; - u8 b; -}; -struct SU { - union UU u; - u8 c; -}; -struct SU gsu = {5,6}; - -/* Unnamed struct/union members aren't ISO C, but it's a widely accepted - extension. See below for further extensions to that under -fms-extension.*/ -union UV { - struct {u8 a,b;}; - struct S s; -}; -union UV guv = {{6,5}}; -union UV guv2 = {{.b = 7, .a = 8}}; -union UV guv3 = {.b = 8, .a = 7}; - -/* Under -fms-extensions also the following is valid: -union UV2 { - struct Anon {u8 a,b;}; // unnamed member, but tagged struct, ... - struct S s; -}; -struct Anon gan = { 10, 11 }; // ... which makes it available here. -union UV2 guv4 = {{4,3}}; // and the other inits from above as well -*/ - -struct in6_addr { - union { - u8 u6_addr8[16]; - unsigned short u6_addr16[8]; - } u; -}; -struct flowi6 { - struct in6_addr saddr, daddr; -}; -struct pkthdr { - struct in6_addr daddr, saddr; -}; -struct pkthdr phdr = { { { 6,5,4,3 } }, { { 9,8,7,6 } } }; - -struct Wrap { - void *func; -}; -int global; -void inc_global (void) -{ - global++; -} - -struct Wrap global_wrap[] = { - ((struct Wrap) {inc_global}), - inc_global, -}; - -#include -void print_ (const char *name, const u8 *p, long size) -{ - printf ("%s:", name); - while (size--) { - printf (" %x", *p++); - } - printf ("\n"); -} -#define print(x) print_(#x, (u8*)&x, sizeof (x)) -#if 1 -void foo (struct W *w, struct pkthdr *phdr_) -{ - struct S ls = {1, 2, 3, 4}; - struct S ls2 = {1, 2, {3, 4}}; - struct T lt = {"hello", 42}; - struct U lu = {3, 5,6,7,8, 4, "huhu", 43}; - struct U lu1 = {3, ls, 4, {"huhu", 43}}; - struct U lu2 = {3, (ls), 4, {"huhu", 43}}; - const struct S *pls = &ls; - struct S ls21 = *pls; - struct U lu22 = {3, *pls, 4, {"huhu", 43}}; - /* Incomplete bracing. */ - struct U lu21 = {3, ls, 4, "huhu", 43}; - /* Optional braces around scalar initializers. Accepted, but with - a warning. */ - struct U lu3 = { 3, {5,6,7,8,}, 4, {"huhu", 43}}; - /* Many superfluous braces and leaving out one initializer for U.s.c[1] */ - struct U lu4 = { 3, {5,6,7,}, 5, { "bla", 44} }; - /* Superfluous braces and useless parens around values */ - struct S ls3 = { (1), (2), {(((3))), 4}}; - /* Superfluous braces, and leaving out braces for V.t, plus cast */ - struct V lv = {{3,4,{5,6}}, "haha", (u8)45, 46}; - /* Compound literal */ - struct V lv2 = {(struct S)w->t.s, {"hihi", 47}, 48}; - /* Parens around compound literal */ - struct V lv3 = {((struct S){7,8,{9,10}}), ((const struct W *)w)->t.t, 50}; - const struct pkthdr *phdr = phdr_; - struct flowi6 flow = { .daddr = phdr->daddr, .saddr = phdr->saddr }; - int elt = 0x42; - /* Range init, overlapping */ - struct T lt2 = { { [1 ... 5] = 9, [6 ... 10] = elt, [4 ... 7] = elt+1 }, 1 }; - print(ls); - print(ls2); - print(lt); - print(lu); - print(lu1); - print(lu2); - print(ls21); - print(lu21); - print(lu22); - print(lu3); - print(lu4); - print(ls3); - print(lv); - print(lv2); - print(lv3); - print(lt2); - print(flow); -} -#endif - -void test_compound_with_relocs (void) -{ - struct Wrap local_wrap[] = { - ((struct Wrap) {inc_global}), - inc_global, - }; - void (*p)(void); - p = global_wrap[0].func; p(); - p = global_wrap[1].func; p(); - p = local_wrap[0].func; p(); - p = local_wrap[1].func; p(); -} - -void sys_ni(void) { printf("ni\n"); } -void sys_one(void) { printf("one\n"); } -void sys_two(void) { printf("two\n"); } -void sys_three(void) { printf("three\n"); } -typedef void (*fptr)(void); -const fptr table[3] = { - [0 ... 2] = &sys_ni, - [0] = sys_one, - [1] = sys_two, - [2] = sys_three, -}; - -void test_multi_relocs(void) -{ - int i; - for (i = 0; i < sizeof(table)/sizeof(table[0]); i++) - table[i](); -} - -/* Following is from GCC gcc.c-torture/execute/20050613-1.c. */ - -struct SEA { int i; int j; int k; int l; }; -struct SEB { struct SEA a; int r[1]; }; -struct SEC { struct SEA a; int r[0]; }; -struct SED { struct SEA a; int r[]; }; - -static void -test_correct_filling (struct SEA *x) -{ - static int i; - if (x->i != 0 || x->j != 5 || x->k != 0 || x->l != 0) - printf("sea_fill%d: wrong\n", i); - else - printf("sea_fill%d: okay\n", i); - i++; -} - -int -test_zero_init (void) -{ - /* The peculiarity here is that only a.j is initialized. That - means that all other members must be zero initialized. TCC - once didn't do that for sub-level designators. */ - struct SEB b = { .a.j = 5 }; - struct SEC c = { .a.j = 5 }; - struct SED d = { .a.j = 5 }; - test_correct_filling (&b.a); - test_correct_filling (&c.a); - test_correct_filling (&d.a); - return 0; -} - -int main() -{ - print(ce); - print(gs); - print(gs2); - print(gt); - print(gu); - print(gu2); - print(gu3); - print(gu4); - print(gs3); - print(gv); - print(gv2); - print(gv3); - print(sinit16); - print(gw); - print(gsu); - print(guv); - print(guv.b); - print(guv2); - print(guv3); - print(phdr); - foo(&gw, &phdr); - //printf("q: %s\n", q); - test_compound_with_relocs(); - test_multi_relocs(); - test_zero_init(); - return 0; -} diff --git a/05/tcc-final-old/tests/tests2/90_struct-init.expect b/05/tcc-final-old/tests/tests2/90_struct-init.expect deleted file mode 100644 index e366121..0000000 --- a/05/tcc-final-old/tests/tests2/90_struct-init.expect +++ /dev/null @@ -1,43 +0,0 @@ -ce: 1 12 -gs: 1 2 3 4 -gs2: 1 2 3 4 -gt: 68 65 6c 6c 6f 0 0 0 0 0 0 0 0 0 0 0 2a -gu: 3 5 6 7 8 4 68 75 68 75 0 0 0 0 0 0 0 0 0 0 0 0 2b -gu2: 3 5 6 7 8 4 68 75 68 75 0 0 0 0 0 0 0 0 0 0 0 0 2b -gu3: 3 5 6 7 8 4 68 75 68 75 0 0 0 0 0 0 0 0 0 0 0 0 2b -gu4: 3 5 6 7 0 5 62 6c 61 0 0 0 0 0 0 0 0 0 0 0 0 0 2c -gs3: 1 2 3 4 -gv: 3 4 5 6 68 61 68 61 0 0 0 0 0 0 0 0 0 0 0 0 2d 2e -gv2: 7 8 9 a 68 69 68 69 0 0 0 0 0 0 0 0 0 0 0 0 2f 30 -gv3: 7 8 9 a 68 6f 68 6f 0 0 0 0 0 0 0 0 0 0 0 0 31 32 -sinit16: 1 0 0 0 2 0 0 0 -gw: 1 2 3 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -gsu: 5 6 -guv: 6 5 0 0 -guv.b: 5 -guv2: 8 7 0 0 -guv3: 7 8 0 0 -phdr: 6 5 4 3 0 0 0 0 0 0 0 0 0 0 0 0 9 8 7 6 0 0 0 0 0 0 0 0 0 0 0 0 -ls: 1 2 3 4 -ls2: 1 2 3 4 -lt: 68 65 6c 6c 6f 0 0 0 0 0 0 0 0 0 0 0 2a -lu: 3 5 6 7 8 4 68 75 68 75 0 0 0 0 0 0 0 0 0 0 0 0 2b -lu1: 3 1 2 3 4 4 68 75 68 75 0 0 0 0 0 0 0 0 0 0 0 0 2b -lu2: 3 1 2 3 4 4 68 75 68 75 0 0 0 0 0 0 0 0 0 0 0 0 2b -ls21: 1 2 3 4 -lu21: 3 1 2 3 4 4 68 75 68 75 0 0 0 0 0 0 0 0 0 0 0 0 2b -lu22: 3 1 2 3 4 4 68 75 68 75 0 0 0 0 0 0 0 0 0 0 0 0 2b -lu3: 3 5 6 7 8 4 68 75 68 75 0 0 0 0 0 0 0 0 0 0 0 0 2b -lu4: 3 5 6 7 0 5 62 6c 61 0 0 0 0 0 0 0 0 0 0 0 0 0 2c -ls3: 1 2 3 4 -lv: 3 4 5 6 68 61 68 61 0 0 0 0 0 0 0 0 0 0 0 0 2d 2e -lv2: 1 2 3 4 68 69 68 69 0 0 0 0 0 0 0 0 0 0 0 0 2f 30 -lv3: 7 8 9 a 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 32 -lt2: 0 9 9 9 43 43 43 43 42 42 42 0 0 0 0 0 1 -flow: 9 8 7 6 0 0 0 0 0 0 0 0 0 0 0 0 6 5 4 3 0 0 0 0 0 0 0 0 0 0 0 0 -one -two -three -sea_fill0: okay -sea_fill1: okay -sea_fill2: okay diff --git a/05/tcc-final-old/tests/tests2/91_ptr_longlong_arith32.c b/05/tcc-final-old/tests/tests2/91_ptr_longlong_arith32.c deleted file mode 100644 index bf07915..0000000 --- a/05/tcc-final-old/tests/tests2/91_ptr_longlong_arith32.c +++ /dev/null @@ -1,15 +0,0 @@ -int printf(const char *, ...); -char t[] = "012345678"; - -int main(void) -{ - char *data = t; - unsigned long long r = 4; - unsigned a = 5; - unsigned long long b = 12; - - *(unsigned*)(data + r) += a - b; - - printf("data = \"%s\"\n", data); - return 0; -} diff --git a/05/tcc-final-old/tests/tests2/91_ptr_longlong_arith32.expect b/05/tcc-final-old/tests/tests2/91_ptr_longlong_arith32.expect deleted file mode 100644 index f91e4b4..0000000 --- a/05/tcc-final-old/tests/tests2/91_ptr_longlong_arith32.expect +++ /dev/null @@ -1 +0,0 @@ -data = "0123-5678" diff --git a/05/tcc-final-old/tests/tests2/92_enum_bitfield.c b/05/tcc-final-old/tests/tests2/92_enum_bitfield.c deleted file mode 100644 index bb6dc35..0000000 --- a/05/tcc-final-old/tests/tests2/92_enum_bitfield.c +++ /dev/null @@ -1,57 +0,0 @@ -/* This checks if enums needing 8 bit but only having positive - values are correctly zero extended (instead of sign extended) - when stored into/loaded from a 8 bit bit-field of enum type (which - itself is implementation defined, so isn't necessarily supported by all - other compilers). */ -enum tree_code { - SOME_CODE = 148, /* has bit 7 set, and hence all further enum values as well */ - LAST_AND_UNUSED_TREE_CODE -}; -typedef union tree_node *tree; -struct tree_common -{ - union tree_node *chain; - union tree_node *type; - enum tree_code code : 8; - unsigned side_effects_flag : 1; -}; -union tree_node -{ - struct tree_common common; - }; -enum c_tree_code { - C_DUMMY_TREE_CODE = LAST_AND_UNUSED_TREE_CODE, - STMT_EXPR, - LAST_C_TREE_CODE -}; -enum cplus_tree_code { - CP_DUMMY_TREE_CODE = LAST_C_TREE_CODE, - AMBIG_CONV, - LAST_CPLUS_TREE_CODE -}; - -extern int printf(const char *, ...); -int blah(){return 0;} - -int convert_like_real (tree convs) -{ - switch (((enum tree_code) (convs)->common.code)) - { - case AMBIG_CONV: /* This has bit 7 set, which must not be the sign - bit in tree_common.code, i.e. the bitfield must - be somehow marked unsigned. */ - return blah(); - default: - break; - }; - printf("unsigned enum bit-fields broken\n"); -} - -int main() -{ - union tree_node convs; - - convs.common.code = AMBIG_CONV; - convert_like_real (&convs); - return 0; -} diff --git a/05/tcc-final-old/tests/tests2/92_enum_bitfield.expect b/05/tcc-final-old/tests/tests2/92_enum_bitfield.expect deleted file mode 100644 index e69de29..0000000 diff --git a/05/tcc-final-old/tests/tests2/93_integer_promotion.c b/05/tcc-final-old/tests/tests2/93_integer_promotion.c deleted file mode 100644 index a1176fc..0000000 --- a/05/tcc-final-old/tests/tests2/93_integer_promotion.c +++ /dev/null @@ -1,71 +0,0 @@ -/* integer promotion */ - -int printf(const char*, ...); -#define promote(s) printf(" %ssigned : %s\n", (s) - 100 < 0 ? " " : "un", #s); - -int main (void) -{ - struct { - unsigned ub:3; - unsigned u:32; - unsigned long long ullb:35; - unsigned long long ull:64; - unsigned char c; - } s = { 1, 1, 1 }; - - promote(s.ub); - promote(s.u); - promote(s.ullb); - promote(s.ull); - promote(s.c); - printf("\n"); - - promote((1 ? s.ub : 1)); - promote((1 ? s.u : 1)); - promote((1 ? s.ullb : 1)); - promote((1 ? s.ull : 1)); - promote((1 ? s.c : 1)); - printf("\n"); - - promote(s.ub << 1); - promote(s.u << 1); - promote(s.ullb << 1); - promote(s.ull << 1); - promote(s.c << 1); - printf("\n"); - - promote(+s.ub); - promote(+s.u); - promote(+s.ullb); - promote(+s.ull); - promote(+s.c); - printf("\n"); - - promote(-s.ub); - promote(-s.u); - promote(-s.ullb); - promote(-s.ull); - promote(-s.c); - printf("\n"); - - promote(~s.ub); - promote(~s.u); - promote(~s.ullb); - promote(~s.ull); - promote(~s.c); - printf("\n"); - - promote(!s.ub); - promote(!s.u); - promote(!s.ullb); - promote(!s.ull); - promote(!s.c); - printf("\n"); - - promote(+(unsigned)s.ub); - promote(-(unsigned)s.ub); - promote(~(unsigned)s.ub); - promote(!(unsigned)s.ub); - - return 0; -} diff --git a/05/tcc-final-old/tests/tests2/93_integer_promotion.expect b/05/tcc-final-old/tests/tests2/93_integer_promotion.expect deleted file mode 100644 index 34b9c14..0000000 --- a/05/tcc-final-old/tests/tests2/93_integer_promotion.expect +++ /dev/null @@ -1,46 +0,0 @@ - signed : s.ub - unsigned : s.u - signed : s.ullb - unsigned : s.ull - signed : s.c - - signed : (1 ? s.ub : 1) - unsigned : (1 ? s.u : 1) - signed : (1 ? s.ullb : 1) - unsigned : (1 ? s.ull : 1) - signed : (1 ? s.c : 1) - - signed : s.ub << 1 - unsigned : s.u << 1 - signed : s.ullb << 1 - unsigned : s.ull << 1 - signed : s.c << 1 - - signed : +s.ub - unsigned : +s.u - signed : +s.ullb - unsigned : +s.ull - signed : +s.c - - signed : -s.ub - unsigned : -s.u - signed : -s.ullb - unsigned : -s.ull - signed : -s.c - - signed : ~s.ub - unsigned : ~s.u - signed : ~s.ullb - unsigned : ~s.ull - signed : ~s.c - - signed : !s.ub - signed : !s.u - signed : !s.ullb - signed : !s.ull - signed : !s.c - - unsigned : +(unsigned)s.ub - unsigned : -(unsigned)s.ub - unsigned : ~(unsigned)s.ub - signed : !(unsigned)s.ub diff --git a/05/tcc-final-old/tests/tests2/94_generic.c b/05/tcc-final-old/tests/tests2/94_generic.c deleted file mode 100644 index d7fb5fc..0000000 --- a/05/tcc-final-old/tests/tests2/94_generic.c +++ /dev/null @@ -1,64 +0,0 @@ -#include - -const int a = 0; - -struct a { - int a; -}; - -struct b { - int a; -}; - -int a_f() -{ - return 20; -} - -int b_f() -{ - return 10; -} - -typedef int int_type1; - -#define gen_sw(a) _Generic(a, const char *: 1, default: 8, int: 123); - -int main() -{ - int i = 0; - signed long int l = 2; - struct b titi; - const int * const ptr; - const char *ti; - int_type1 i2; - - i = _Generic(a, int: a_f, const int: b_f)(); - printf("%d\n", i); - i = _Generic(a, int: a_f() / 2, const int: b_f() / 2); - printf("%d\n", i); - i = _Generic(ptr, int *:1, int * const:2, default:20); - printf("%d\n", i); - i = gen_sw(a); - printf("%d\n", i); - i = _Generic(titi, struct a:1, struct b:2, default:20); - printf("%d\n", i); - i = _Generic(i2, char: 1, int : 0); - printf("%d\n", i); - i = _Generic(a, char:1, int[4]:2, default:5); - printf("%d\n", i); - i = _Generic(17, int :1, int **:2); - printf("%d\n", i); - i = _Generic(17L, int :1, long :2, long long : 3); - printf("%d\n", i); - i = _Generic("17, io", char *: 3, const char *: 1); - printf("%d\n", i); - i = _Generic(ti, const unsigned char *:1, const char *:4, char *:3, - const signed char *:2); - printf("%d\n", i); - printf("%s\n", _Generic(i + 2L, long: "long", int: "int", - long long: "long long")); - i = _Generic(l, long: 1, int: 2); - printf("%d\n", i); - return 0; -} diff --git a/05/tcc-final-old/tests/tests2/94_generic.expect b/05/tcc-final-old/tests/tests2/94_generic.expect deleted file mode 100644 index 9aa9275..0000000 --- a/05/tcc-final-old/tests/tests2/94_generic.expect +++ /dev/null @@ -1,13 +0,0 @@ -20 -10 -20 -123 -2 -0 -5 -1 -2 -3 -4 -long -1 \ No newline at end of file diff --git a/05/tcc-final-old/tests/tests2/95_bitfields.c b/05/tcc-final-old/tests/tests2/95_bitfields.c deleted file mode 100644 index f025c57..0000000 --- a/05/tcc-final-old/tests/tests2/95_bitfields.c +++ /dev/null @@ -1,218 +0,0 @@ -/* ----------------------------------------------------------------------- */ -#if TEST == 1 -{ - struct M P A __s - { - unsigned x : 12; - unsigned char y : 7; - unsigned z : 28; - unsigned a: 4; - unsigned b: 5; - }; - TEST_STRUCT(0x333,0x44,0x555555,6,7); -} - -/* ----------------------------------------------------------------------- */ -#elif TEST == 2 -{ - struct M P __s - { - int x: 12; - char y: 6; - long long z:63; - A char a:4; - long long b:2; - - }; - TEST_STRUCT(3,30,0x123456789abcdef0LL,5,2); -} - -/* ----------------------------------------------------------------------- */ -#elif TEST == 3 -{ - struct M P __s - { - unsigned x:5, y:5, :0, z:5; char a:5; A short b:5; - }; - TEST_STRUCT(21,23,25,6,14); -} - -/* ----------------------------------------------------------------------- */ -#elif TEST == 4 -{ - struct M P __s { - int x : 3; - int : 2; - int y : 1; - int : 0; - int z : 5; - int a : 7; - unsigned int b : 7; - }; - TEST_STRUCT(3,1,15,120,120); -} - -/* ----------------------------------------------------------------------- */ -#elif TEST == 5 -{ - struct M P __s { - long long x : 45; - long long : 2; - long long y : 30; - unsigned long long z : 38; - char a; short b; - }; - TEST_STRUCT(0x123456789ULL, 120<<25, 120, 0x44, 0x77); -} - -/* ----------------------------------------------------------------------- */ -#elif TEST == 6 -{ - struct M P __s { - int a; - signed char b; - int x : 12, y : 4, : 0, : 4, z : 3; - char d; - }; - TEST_STRUCT(1,2,3,4,-3); -} - -/* ----------------------------------------------------------------------- */ -#elif defined PACK - -#if PACK -# pragma pack(push,1) -# define P //_P -#else -# define P -#endif - -printf("\n\n" + 2*top); -#define TEST 1 -#include SELF -top = 0; -#define TEST 2 -#include SELF -#define TEST 3 -#include SELF -#define TEST 4 -#include SELF -#define TEST 5 -#include SELF -#define TEST 6 -#include SELF - -#if PACK -# pragma pack(pop) -#endif - -#undef P -#undef PACK - -/* ----------------------------------------------------------------------- */ -#elif defined ALIGN - -#if ALIGN -# define A _A(16) -#else -# define A -#endif - -#define PACK 0 -#include SELF -#define PACK 1 -#include SELF - -#undef A -#undef ALIGN - -/* ----------------------------------------------------------------------- */ -#elif defined MS_BF - -#if MS_BF -# ifdef __TINYC__ -# pragma comment(option, "-mms-bitfields") -# elif defined __GNUC__ -# define M __attribute__((ms_struct)) -# endif -#else -# ifdef __TINYC__ -# pragma comment(option, "-mno-ms-bitfields") -# elif defined __GNUC__ -# define M __attribute__((gcc_struct)) -# endif -#endif -#ifndef M -# define M -#endif - -#define ALIGN 0 -#include SELF -#define ALIGN 1 -#include SELF - -#undef M -#undef MS_BF - -/* ----------------------------------------------------------------------- */ -#else - -#include -#include -/* some gcc headers #define __attribute__ to empty if it's not gcc */ -#undef __attribute__ - -void dump(void *p, int s) -{ - int i; - for (i = s; --i >= 0;) - printf("%02X", ((unsigned char*)p)[i]); - printf("\n"); -} - -#define pv(m) \ - printf(sizeof (s->m + 0) == 8 ? " %016llx" : " %02x", s->m) - -#define TEST_STRUCT(v1,v2,v3,v4,v5) { \ - struct __s _s, *s = & _s; \ - printf("\n---- TEST %d%s%s%s ----\n" + top, \ - TEST, MS_BF?" - MS-BITFIELDS":"", \ - PACK?" - PACKED":"", \ - ALIGN?" - WITH ALIGN":""); \ - memset(s, 0, sizeof *s); \ - s->x = -1, s->y = -1, s->z = -1, s->a = -1, s->b = -1; \ - printf("bits in use : "), dump(s, sizeof *s); \ - s->x = v1, s->y = v2, s->z = v3, s->a += v4, ++s->a, s->b = v5; \ - printf("bits as set : "), dump(s, sizeof *s); \ - printf("values :"), pv(x), pv(y), pv(z), pv(a), pv(b), printf("\n"); \ - printf("align/size : %d %d\n", alignof(struct __s),sizeof(struct __s)); \ - } - -#ifdef _MSC_VER -# define _A(n) __declspec(align(n)) -# define _P -# define alignof(x) __alignof(x) -#else -# define _A(n) __attribute__((aligned(n))) -# define _P __attribute__((packed)) -# define alignof(x) __alignof__(x) -#endif - -#ifndef MS_BITFIELDS -# define MS_BITFIELDS 0 -#endif - -#define SELF "95_bitfields.c" - -int top = 1; - -int main() -{ -#define MS_BF MS_BITFIELDS -#include SELF - return 0; -} - -/* ----------------------------------------------------------------------- */ -#endif -#undef TEST diff --git a/05/tcc-final-old/tests/tests2/95_bitfields.expect b/05/tcc-final-old/tests/tests2/95_bitfields.expect deleted file mode 100644 index 6a8fd9a..0000000 --- a/05/tcc-final-old/tests/tests2/95_bitfields.expect +++ /dev/null @@ -1,149 +0,0 @@ ----- TEST 1 ---- -bits in use : 0000001FFFFFFFFF007F0FFF -bits as set : 000000076055555500440333 -values : 333 44 555555 06 07 -align/size : 4 12 - ----- TEST 2 ---- -bits in use : 000000000000003F7FFFFFFFFFFFFFFF00000000003F0FFF -bits as set : 0000000000000025123456789ABCDEF000000000001E0003 -values : 03 1e 123456789abcdef0 05 fffffffe -align/size : 8 24 - ----- TEST 3 ---- -bits in use : 001F1F1F000003FF -bits as set : 000E0619000002F5 -values : 15 17 19 06 0e -align/size : 4 8 - ----- TEST 4 ---- -bits in use : 0007FFFF00000027 -bits as set : 00078F0F00000023 -values : 03 ffffffff 0f fffffff8 78 -align/size : 4 8 - ----- TEST 5 ---- -bits in use : FFFFFF3FFFFFFFFF000000003FFFFFFF00001FFFFFFFFFFF -bits as set : 007744000000007800000000300000000000000123456789 -values : 0000000123456789 f0000000 0000000000000078 44 77 -align/size : 8 24 - ----- TEST 6 ---- -bits in use : 0000007000FFFFFFFFFFFFFF -bits as set : 00000030002001FD00000004 -values : 01 02 03 04 fffffffd -align/size : 4 12 - - - ----- TEST 1 - PACKED ---- -bits in use : FFFFFFFFFFFFFF -bits as set : 3B02AAAAAC4333 -values : 333 44 555555 06 07 -align/size : 1 7 - ----- TEST 2 - PACKED ---- -bits in use : 7FFFFFFFFFFFFFFFFFFFFF -bits as set : 4A48D159E26AF37BC1E003 -values : 03 1e 123456789abcdef0 05 fffffffe -align/size : 1 11 - ----- TEST 3 - PACKED ---- -bits in use : 7FFF000003FF -bits as set : 38D9000002F5 -values : 15 17 19 06 0e -align/size : 1 6 - ----- TEST 4 - PACKED ---- -bits in use : 07FFFF00000027 -bits as set : 078F0F00000023 -values : 03 ffffffff 0f fffffff8 78 -align/size : 1 7 - ----- TEST 5 - PACKED ---- -bits in use : FFFFFF07FFFFFFFFFFFFFFFF9FFFFFFFFFFF -bits as set : 007744000000000F18000000000123456789 -values : 0000000123456789 f0000000 0000000000000078 44 77 -align/size : 1 18 - ----- TEST 6 - PACKED ---- -bits in use : 007000FFFFFFFFFFFFFF -bits as set : 0030002001FD00000004 -values : 01 02 03 04 fffffffd -align/size : 1 10 - - - ----- TEST 1 - WITH ALIGN ---- -bits in use : 000000000000001FFFFFFFFF007F0FFF -bits as set : 00000000000000076055555500440333 -values : 333 44 555555 06 07 -align/size : 16 16 - ----- TEST 2 - WITH ALIGN ---- -bits in use : 0000000000000000000000000000003F7FFFFFFFFFFFFFFF00000000003F0FFF -bits as set : 00000000000000000000000000000025123456789ABCDEF000000000001E0003 -values : 03 1e 123456789abcdef0 05 fffffffe -align/size : 16 32 - ----- TEST 3 - WITH ALIGN ---- -bits in use : 0000000000000000000000000000001F000000000000000000001F1F000003FF -bits as set : 0000000000000000000000000000000E000000000000000000000619000002F5 -values : 15 17 19 06 0e -align/size : 16 32 - ----- TEST 4 - WITH ALIGN ---- -bits in use : 0007FFFF00000027 -bits as set : 00078F0F00000023 -values : 03 ffffffff 0f fffffff8 78 -align/size : 4 8 - ----- TEST 5 - WITH ALIGN ---- -bits in use : FFFFFF3FFFFFFFFF000000003FFFFFFF00001FFFFFFFFFFF -bits as set : 007744000000007800000000300000000000000123456789 -values : 0000000123456789 f0000000 0000000000000078 44 77 -align/size : 8 24 - ----- TEST 6 - WITH ALIGN ---- -bits in use : 0000007000FFFFFFFFFFFFFF -bits as set : 00000030002001FD00000004 -values : 01 02 03 04 fffffffd -align/size : 4 12 - - - ----- TEST 1 - PACKED - WITH ALIGN ---- -bits in use : 000000000000000000FFFFFFFFFFFFFF -bits as set : 0000000000000000003B02AAAAAC4333 -values : 333 44 555555 06 07 -align/size : 16 16 - ----- TEST 2 - PACKED - WITH ALIGN ---- -bits in use : 3F01FFFFFFFFFFFFFFFFFFFF -bits as set : 250048D159E26AF37BC1E003 -values : 03 1e 123456789abcdef0 05 fffffffe -align/size : 1 12 - ----- TEST 3 - PACKED - WITH ALIGN ---- -bits in use : 1F03FF000003FF -bits as set : 0E00D9000002F5 -values : 15 17 19 06 0e -align/size : 1 7 - ----- TEST 4 - PACKED - WITH ALIGN ---- -bits in use : 07FFFF00000027 -bits as set : 078F0F00000023 -values : 03 ffffffff 0f fffffff8 78 -align/size : 1 7 - ----- TEST 5 - PACKED - WITH ALIGN ---- -bits in use : FFFFFF07FFFFFFFFFFFFFFFF9FFFFFFFFFFF -bits as set : 007744000000000F18000000000123456789 -values : 0000000123456789 f0000000 0000000000000078 44 77 -align/size : 1 18 - ----- TEST 6 - PACKED - WITH ALIGN ---- -bits in use : 007000FFFFFFFFFFFFFF -bits as set : 0030002001FD00000004 -values : 01 02 03 04 fffffffd -align/size : 1 10 diff --git a/05/tcc-final-old/tests/tests2/95_bitfields_ms.c b/05/tcc-final-old/tests/tests2/95_bitfields_ms.c deleted file mode 100644 index b196fbd..0000000 --- a/05/tcc-final-old/tests/tests2/95_bitfields_ms.c +++ /dev/null @@ -1,2 +0,0 @@ -#define MS_BITFIELDS 1 -#include "95_bitfields.c" diff --git a/05/tcc-final-old/tests/tests2/95_bitfields_ms.expect b/05/tcc-final-old/tests/tests2/95_bitfields_ms.expect deleted file mode 100644 index 8ccafb7..0000000 --- a/05/tcc-final-old/tests/tests2/95_bitfields_ms.expect +++ /dev/null @@ -1,149 +0,0 @@ ----- TEST 1 - MS-BITFIELDS ---- -bits in use : 0000001FFFFFFFFF0000007F00000FFF -bits as set : 00000007605555550000004400000333 -values : 333 44 555555 06 07 -align/size : 4 16 - ----- TEST 2 - MS-BITFIELDS ---- -bits in use : 0000000000000003000000000000000F7FFFFFFFFFFFFFFF0000003F00000FFF -bits as set : 00000000000000020000000000000005123456789ABCDEF00000001E00000003 -values : 03 1e 123456789abcdef0 05 fffffffffffffffe -align/size : 8 32 - ----- TEST 3 - MS-BITFIELDS ---- -bits in use : 001F001F0000001F000003FF -bits as set : 000E000600000019000002F5 -values : 15 17 19 06 0e -align/size : 4 12 - ----- TEST 4 - MS-BITFIELDS ---- -bits in use : 0007FFFF00000027 -bits as set : 00078F0F00000023 -values : 03 ffffffff 0f fffffff8 78 -align/size : 4 8 - ----- TEST 5 - MS-BITFIELDS ---- -bits in use : 00000000FFFF00FF0000003FFFFFFFFF000000003FFFFFFF00001FFFFFFFFFFF -bits as set : 0000000000770044000000000000007800000000300000000000000123456789 -values : 0000000123456789 fffffffff0000000 0000000000000078 44 77 -align/size : 8 32 - ----- TEST 6 - MS-BITFIELDS ---- -bits in use : 00000000000000700000FFFF000000FFFFFFFFFF -bits as set : 000000000000003000002001000000FD00000004 -values : 01 02 03 04 fffffffd -align/size : 4 20 - - - ----- TEST 1 - MS-BITFIELDS - PACKED ---- -bits in use : 0000001FFFFFFFFF7F00000FFF -bits as set : 00000007605555554400000333 -values : 333 44 555555 06 07 -align/size : 1 13 - ----- TEST 2 - MS-BITFIELDS - PACKED ---- -bits in use : 00000000000000030F7FFFFFFFFFFFFFFF3F00000FFF -bits as set : 000000000000000205123456789ABCDEF01E00000003 -values : 03 1e 123456789abcdef0 05 fffffffffffffffe -align/size : 1 22 - ----- TEST 3 - MS-BITFIELDS - PACKED ---- -bits in use : 001F1F0000001F000003FF -bits as set : 000E0600000019000002F5 -values : 15 17 19 06 0e -align/size : 1 11 - ----- TEST 4 - MS-BITFIELDS - PACKED ---- -bits in use : 0007FFFF00000027 -bits as set : 00078F0F00000023 -values : 03 ffffffff 0f fffffff8 78 -align/size : 1 8 - ----- TEST 5 - MS-BITFIELDS - PACKED ---- -bits in use : FFFFFF0000003FFFFFFFFF000000003FFFFFFF00001FFFFFFFFFFF -bits as set : 007744000000000000007800000000300000000000000123456789 -values : 0000000123456789 fffffffff0000000 0000000000000078 44 77 -align/size : 1 27 - ----- TEST 6 - MS-BITFIELDS - PACKED ---- -bits in use : 00000000700000FFFFFFFFFFFFFF -bits as set : 000000003000002001FD00000004 -values : 01 02 03 04 fffffffd -align/size : 1 14 - - - ----- TEST 1 - MS-BITFIELDS - WITH ALIGN ---- -bits in use : 0000001FFFFFFFFF0000007F00000FFF -bits as set : 00000007605555550000004400000333 -values : 333 44 555555 06 07 -align/size : 16 16 - ----- TEST 2 - MS-BITFIELDS - WITH ALIGN ---- -bits in use : 0000000000000003000000000000000F7FFFFFFFFFFFFFFF0000003F00000FFF -bits as set : 00000000000000020000000000000005123456789ABCDEF00000001E00000003 -values : 03 1e 123456789abcdef0 05 fffffffffffffffe -align/size : 16 32 - ----- TEST 3 - MS-BITFIELDS - WITH ALIGN ---- -bits in use : 0000000000000000000000000000001F000000000000001F0000001F000003FF -bits as set : 0000000000000000000000000000000E000000000000000600000019000002F5 -values : 15 17 19 06 0e -align/size : 16 32 - ----- TEST 4 - MS-BITFIELDS - WITH ALIGN ---- -bits in use : 0007FFFF00000027 -bits as set : 00078F0F00000023 -values : 03 ffffffff 0f fffffff8 78 -align/size : 4 8 - ----- TEST 5 - MS-BITFIELDS - WITH ALIGN ---- -bits in use : 00000000FFFF00FF0000003FFFFFFFFF000000003FFFFFFF00001FFFFFFFFFFF -bits as set : 0000000000770044000000000000007800000000300000000000000123456789 -values : 0000000123456789 fffffffff0000000 0000000000000078 44 77 -align/size : 8 32 - ----- TEST 6 - MS-BITFIELDS - WITH ALIGN ---- -bits in use : 00000000000000700000FFFF000000FFFFFFFFFF -bits as set : 000000000000003000002001000000FD00000004 -values : 01 02 03 04 fffffffd -align/size : 4 20 - - - ----- TEST 1 - MS-BITFIELDS - PACKED - WITH ALIGN ---- -bits in use : 0000000000001FFFFFFFFF7F00000FFF -bits as set : 00000000000007605555554400000333 -values : 333 44 555555 06 07 -align/size : 16 16 - ----- TEST 2 - MS-BITFIELDS - PACKED - WITH ALIGN ---- -bits in use : 00000000000000030F0000007FFFFFFFFFFFFFFF3F00000FFF -bits as set : 000000000000000205000000123456789ABCDEF01E00000003 -values : 03 1e 123456789abcdef0 05 fffffffffffffffe -align/size : 16 25 - ----- TEST 3 - MS-BITFIELDS - PACKED - WITH ALIGN ---- -bits in use : 001F000000000000001F0000001F000003FF -bits as set : 000E000000000000000600000019000002F5 -values : 15 17 19 06 0e -align/size : 16 18 - ----- TEST 4 - MS-BITFIELDS - PACKED - WITH ALIGN ---- -bits in use : 0007FFFF00000027 -bits as set : 00078F0F00000023 -values : 03 ffffffff 0f fffffff8 78 -align/size : 1 8 - ----- TEST 5 - MS-BITFIELDS - PACKED - WITH ALIGN ---- -bits in use : FFFFFF0000003FFFFFFFFF000000003FFFFFFF00001FFFFFFFFFFF -bits as set : 007744000000000000007800000000300000000000000123456789 -values : 0000000123456789 fffffffff0000000 0000000000000078 44 77 -align/size : 1 27 - ----- TEST 6 - MS-BITFIELDS - PACKED - WITH ALIGN ---- -bits in use : 00000000700000FFFFFFFFFFFFFF -bits as set : 000000003000002001FD00000004 -values : 01 02 03 04 fffffffd -align/size : 1 14 diff --git a/05/tcc-final-old/tests/tests2/96_nodata_wanted.c b/05/tcc-final-old/tests/tests2/96_nodata_wanted.c deleted file mode 100644 index cc211d3..0000000 --- a/05/tcc-final-old/tests/tests2/96_nodata_wanted.c +++ /dev/null @@ -1,84 +0,0 @@ -/*****************************************************************************/ -/* test 'nodata_wanted' data output suppression */ - -#if defined test_static_data_error -void foo() { - if (1) { - static short w = (int)&foo; /* initializer not computable */ - } -} - -#elif defined test_static_nodata_error -void foo() { - if (0) { - static short w = (int)&foo; /* initializer not computable */ - } -} - -#elif defined test_global_data_error -void foo(); -static short w = (int)&foo; /* initializer not computable */ - - -#elif defined test_local_data_noerror -void foo() { - short w = &foo; /* 2 cast warnings */ -} - -#elif defined test_data_suppression_off || defined test_data_suppression_on - -#if defined test_data_suppression_on -# define SKIP 1 -#else -# define SKIP 0 -#endif - -#include -/* some gcc headers #define __attribute__ to empty if it's not gcc */ -#undef __attribute__ - -int main() -{ - __label__ ts0, te0, ts1, te1; - int tl, dl; - - static char ds0 = 0; - static char de0 = 0; - /* get reference size of empty jmp */ -ts0:; - if (!SKIP) {} -te0:; - dl = -(&de0 - &ds0); - tl = -(&&te0 - &&ts0); - - /* test data and code suppression */ - static char ds1 = 0; -ts1:; - if (!SKIP) { - static void *p = (void*)&main; - static char cc[] = "static string"; - static double d = 8.0; - - static struct __attribute__((packed)) { - unsigned x : 12; - unsigned char y : 7; - unsigned z : 28, a: 4, b: 5; - } s = { 0x333,0x44,0x555555,6,7 }; - - printf("data:\n"); - printf(" %d - %.1f - %.1f - %s - %s\n", - sizeof 8.0, 8.0, d, __FUNCTION__, cc); - printf(" %x %x %x %x %x\n", - s.x, s.y, s.z, s.a, s.b); - } -te1:; - static char de1 = 0; - - dl += &de1 - &ds1; - tl += &&te1 - &&ts1; - printf("size of data/text:\n %s/%s\n", - dl ? "non-zero":"zero", tl ? "non-zero":"zero"); - /*printf("# %d/%d\n", dl, tl);*/ -} - -#endif diff --git a/05/tcc-final-old/tests/tests2/96_nodata_wanted.expect b/05/tcc-final-old/tests/tests2/96_nodata_wanted.expect deleted file mode 100644 index 2749109..0000000 --- a/05/tcc-final-old/tests/tests2/96_nodata_wanted.expect +++ /dev/null @@ -1,23 +0,0 @@ -[test_static_data_error] -96_nodata_wanted.c:7: error: initializer element is not computable at load time - -[test_static_nodata_error] -96_nodata_wanted.c:14: error: initializer element is not computable at load time - -[test_global_data_error] -96_nodata_wanted.c:20: error: initializer element is not computable at load time - -[test_local_data_noerror] -96_nodata_wanted.c:25: warning: assignment makes integer from pointer without a cast -96_nodata_wanted.c:25: warning: nonportable conversion from pointer to char/short - -[test_data_suppression_off] -data: - 8 - 8.0 - 8.0 - main - static string - 333 44 555555 6 7 -size of data/text: - non-zero/non-zero - -[test_data_suppression_on] -size of data/text: - zero/zero diff --git a/05/tcc-final-old/tests/tests2/97_utf8_string_literal.c b/05/tcc-final-old/tests/tests2/97_utf8_string_literal.c deleted file mode 100644 index 96fbab0..0000000 --- a/05/tcc-final-old/tests/tests2/97_utf8_string_literal.c +++ /dev/null @@ -1,12 +0,0 @@ -// this file contains BMP chars encoded in UTF-8 -#include -#include - -int main() -{ - wchar_t s[] = L"hello$$你好¢¢世界€€world"; - wchar_t *p; - for (p = s; *p; p++) printf("%04X ", (unsigned) *p); - printf("\n"); - return 0; -} diff --git a/05/tcc-final-old/tests/tests2/97_utf8_string_literal.expect b/05/tcc-final-old/tests/tests2/97_utf8_string_literal.expect deleted file mode 100644 index 9a1593c..0000000 --- a/05/tcc-final-old/tests/tests2/97_utf8_string_literal.expect +++ /dev/null @@ -1 +0,0 @@ -0068 0065 006C 006C 006F 0024 0024 4F60 597D 00A2 00A2 4E16 754C 20AC 20AC 0077 006F 0072 006C 0064 diff --git a/05/tcc-final-old/tests/tests2/98_al_ax_extend.c b/05/tcc-final-old/tests/tests2/98_al_ax_extend.c deleted file mode 100644 index 9b4e02f..0000000 --- a/05/tcc-final-old/tests/tests2/98_al_ax_extend.c +++ /dev/null @@ -1,41 +0,0 @@ -#include -#include -asm ( - ".text;" - ".globl _us;.globl _ss;.globl _uc;.globl _sc;" - "_us:;_ss:;_uc:;_sc:;" - "movl $0x1234ABCD, %eax;" - "ret;" -); - -#if 1 -#define us _us -#define ss _ss -#define uc _uc -#define sc _sc -#endif - -int main() -{ - unsigned short us(void); - short ss(void); - unsigned char uc(void); - signed char sc(void); - - unsigned short (*fpus)(void) = us; - short (*fpss)(void) = ss; - unsigned char (*fpuc)(void) = uc; - signed char (*fpsc)(void) = sc; - - printf("%08X %08X\n", us() + 1, fpus() + 1); - printf("%08X %08X\n", ss() + 1, fpss() + 1); - printf("%08X %08X\n", uc() + 1, fpuc() + 1); - printf("%08X %08X\n", sc() + 1, fpsc() + 1); - printf("\n"); - printf("%08X %08X\n", fpus() + 1, us() + 1); - printf("%08X %08X\n", fpss() + 1, ss() + 1); - printf("%08X %08X\n", fpuc() + 1, uc() + 1); - printf("%08X %08X\n", fpsc() + 1, sc() + 1); - - return 0; -} diff --git a/05/tcc-final-old/tests/tests2/98_al_ax_extend.expect b/05/tcc-final-old/tests/tests2/98_al_ax_extend.expect deleted file mode 100644 index c5752e8..0000000 --- a/05/tcc-final-old/tests/tests2/98_al_ax_extend.expect +++ /dev/null @@ -1,9 +0,0 @@ -0000ABCE 0000ABCE -FFFFABCE FFFFABCE -000000CE 000000CE -FFFFFFCE FFFFFFCE - -0000ABCE 0000ABCE -FFFFABCE FFFFABCE -000000CE 000000CE -FFFFFFCE FFFFFFCE diff --git a/05/tcc-final-old/tests/tests2/99_fastcall.c b/05/tcc-final-old/tests/tests2/99_fastcall.c deleted file mode 100644 index ee4b67d..0000000 --- a/05/tcc-final-old/tests/tests2/99_fastcall.c +++ /dev/null @@ -1,276 +0,0 @@ -#include -#include - -#ifndef _WIN32 -#define __fastcall __attribute((fastcall)) -#endif - -#if 1 -#define SYMBOL(x) _##x -#else -#define SYMBOL(x) x -#endif - -///////////////////////////////////////////////////////////////////////// -////////// TRAP FRAMEWORK -///////////////////////////////////////////////////////////////////////// -// if you cast 'TRAP' to a function pointer and call it, -// it will save all 8 registers, -// and jump into C-code (previously set using 'SET_TRAP_HANDLER(x)'), -// in C-code you can pop DWORDs from stack and modify registers -// - -void *SYMBOL(trap_handler); - -extern unsigned char SYMBOL(trap)[]; -asm ( - ".text;" - "_trap:;" - "pushl %esp;" - "pusha;" - "addl $0x4, 0xc(%esp);" - "pushl %esp;" - "call *_trap_handler;" - "addl $0x4, %esp;" - "movl 0xc(%esp), %eax;" - "movl %eax, 0x20(%esp);" - "popa;" - "popl %esp;" - "ret;" -); - -struct trapframe { - unsigned edi, esi, ebp, esp, ebx, edx, ecx, eax; -}; - - -#define M_FLOAT(addr) (*(float *)(addr)) -#define M_DWORD(addr) (*(unsigned *)(addr)) -#define M_WORD(addr) (*(unsigned short *)(addr)) -#define M_BYTE(addr) (*(unsigned char *)(addr)) -#define R_EAX ((tf)->eax) -#define R_ECX ((tf)->ecx) -#define R_EDX ((tf)->edx) -#define R_EBX ((tf)->ebx) -#define R_ESP ((tf)->esp) -#define R_EBP ((tf)->ebp) -#define R_ESI ((tf)->esi) -#define R_EDI ((tf)->edi) - -#define ARG(x) (M_DWORD(R_ESP + (x) * 4)) - -#define RETN(x) do { \ - M_DWORD(R_ESP + (x)) = M_DWORD(R_ESP); \ - R_ESP += (x); \ -} while (0) - -#define DUMP() do { \ - unsigned i; \ - printf("EAX: %08X\n", R_EAX); \ - printf("ECX: %08X\n", R_ECX); \ - printf("EDX: %08X\n", R_EDX); \ - printf("EBX: %08X\n", R_EBX); \ - printf("ESP: %08X\n", R_ESP); \ - printf("EBP: %08X\n", R_EBP); \ - printf("ESI: %08X\n", R_ESI); \ - printf("EDI: %08X\n", R_EDI); \ - printf("\n"); \ - printf("[RETADDR]: %08X\n", M_DWORD(R_ESP)); \ - for (i = 1; i <= 8; i++) { \ - printf("[ARG%4d]: %08X\n", i, ARG(i)); \ - } \ -} while (0) - -#define SET_TRAP_HANDLER(x) ((SYMBOL(trap_handler)) = (x)) -#define TRAP ((void *) &SYMBOL(trap)) - - - -///////////////////////////////////////////////////////////////////////// -////////// SAFECALL FRAMEWORK -///////////////////////////////////////////////////////////////////////// -// this framework will convert any calling convention to cdecl -// usage: first set call target with 'SET_SAFECALL_TARGET(x)' -// then cast 'SAFECALL' to target function pointer type and invoke it -// after calling, 'ESPDIFF' is the difference of old and new esp - -void *SYMBOL(sc_call_target); -unsigned SYMBOL(sc_retn_addr); -unsigned SYMBOL(sc_old_esp); -unsigned SYMBOL(sc_new_esp); - -extern unsigned char SYMBOL(safecall)[]; -asm ( - ".text;" - "_safecall:;" - "popl _sc_retn_addr;" - "movl %esp, _sc_old_esp;" - "call *_sc_call_target;" - "movl %esp, _sc_new_esp;" - "movl _sc_old_esp, %esp;" - "jmp *_sc_retn_addr;" -); - -#define SET_SAFECALL_TARGET(x) ((SYMBOL(sc_call_target)) = (x)) -#define SAFECALL ((void *) &SYMBOL(safecall)) -#define ESPDIFF (SYMBOL(sc_new_esp) - SYMBOL(sc_old_esp)) - - -///////////////////////////////////////////////////////////////////////// -////////// TEST FASTCALL INVOKE -///////////////////////////////////////////////////////////////////////// - -void check_fastcall_invoke_0(struct trapframe *tf) -{ - //DUMP(); - RETN(0); -} - -void check_fastcall_invoke_1(struct trapframe *tf) -{ - //DUMP(); - assert(R_ECX == 0x11111111); - RETN(0); -} -void check_fastcall_invoke_2(struct trapframe *tf) -{ - //DUMP(); - assert(R_ECX == 0x11111111); - assert(R_EDX == 0x22222222); - RETN(0); -} -void check_fastcall_invoke_3(struct trapframe *tf) -{ - //DUMP(); - assert(R_ECX == 0x11111111); - assert(R_EDX == 0x22222222); - assert(ARG(1) == 0x33333333); - RETN(1*4); -} -void check_fastcall_invoke_4(struct trapframe *tf) -{ - //DUMP(); - assert(R_ECX == 0x11111111); - assert(R_EDX == 0x22222222); - assert(ARG(1) == 0x33333333); - assert(ARG(2) == 0x44444444); - RETN(2*4); -} - -void check_fastcall_invoke_5(struct trapframe *tf) -{ - //DUMP(); - assert(R_ECX == 0x11111111); - assert(R_EDX == 0x22222222); - assert(ARG(1) == 0x33333333); - assert(ARG(2) == 0x44444444); - assert(ARG(3) == 0x55555555); - RETN(3*4); -} - -void test_fastcall_invoke() -{ - SET_TRAP_HANDLER(check_fastcall_invoke_0); - ((void __fastcall (*)(void)) TRAP)(); - - SET_TRAP_HANDLER(check_fastcall_invoke_1); - ((void __fastcall (*)(unsigned)) TRAP)(0x11111111); - - SET_TRAP_HANDLER(check_fastcall_invoke_2); - ((void __fastcall (*)(unsigned, unsigned)) TRAP)(0x11111111, 0x22222222); - - SET_TRAP_HANDLER(check_fastcall_invoke_3); - ((void __fastcall (*)(unsigned, unsigned, unsigned)) TRAP)(0x11111111, 0x22222222, 0x33333333); - - SET_TRAP_HANDLER(check_fastcall_invoke_4); - ((void __fastcall (*)(unsigned, unsigned, unsigned, unsigned)) TRAP)(0x11111111, 0x22222222, 0x33333333, 0x44444444); - - SET_TRAP_HANDLER(check_fastcall_invoke_5); - ((void __fastcall (*)(unsigned, unsigned, unsigned, unsigned, unsigned)) TRAP)(0x11111111, 0x22222222, 0x33333333, 0x44444444, 0x55555555); -} - - -///////////////////////////////////////////////////////////////////////// -////////// TEST FUNCTION CODE GENERATION -///////////////////////////////////////////////////////////////////////// - -int __fastcall check_fastcall_espdiff_0(void) -{ - return 0; -} - -int __fastcall check_fastcall_espdiff_1(int a) -{ - return a; -} - -int __fastcall check_fastcall_espdiff_2(int a, int b) -{ - return a + b; -} - -int __fastcall check_fastcall_espdiff_3(int a, int b, int c) -{ - return a + b + c; -} - -int __fastcall check_fastcall_espdiff_4(int a, int b, int c, int d) -{ - return a + b + c + d; -} - -int __fastcall check_fastcall_espdiff_5(int a, int b, int c, int d, int e) -{ - return a + b + c + d + e; -} - -void test_fastcall_espdiff() -{ - int x; - SET_SAFECALL_TARGET(check_fastcall_espdiff_0); - x = ((typeof(&check_fastcall_espdiff_0))SAFECALL)(); - assert(x == 0); - assert(ESPDIFF == 0); - - SET_SAFECALL_TARGET(check_fastcall_espdiff_1); - x = ((typeof(&check_fastcall_espdiff_1))SAFECALL)(1); - assert(x == 1); - assert(ESPDIFF == 0); - - SET_SAFECALL_TARGET(check_fastcall_espdiff_2); - x = ((typeof(&check_fastcall_espdiff_2))SAFECALL)(1, 2); - assert(x == 1 + 2); - assert(ESPDIFF == 0); - - SET_SAFECALL_TARGET(check_fastcall_espdiff_3); - x = ((typeof(&check_fastcall_espdiff_3))SAFECALL)(1, 2, 3); - assert(x == 1 + 2 + 3); - assert(ESPDIFF == 1*4); - - SET_SAFECALL_TARGET(check_fastcall_espdiff_4); - x = ((typeof(&check_fastcall_espdiff_4))SAFECALL)(1, 2, 3, 4); - assert(x == 1 + 2 + 3 + 4); - assert(ESPDIFF == 2*4); - - SET_SAFECALL_TARGET(check_fastcall_espdiff_5); - x = ((typeof(&check_fastcall_espdiff_5))SAFECALL)(1, 2, 3, 4, 5); - assert(x == 1 + 2 + 3 + 4 + 5); - assert(ESPDIFF == 3*4); -} - -int main() -{ -#define N 10000 - int i; - - for (i = 1; i <= N; i++) { - test_fastcall_espdiff(); - } - - for (i = 1; i <= N; i++) { - test_fastcall_invoke(); - } - - puts("TEST OK"); - return 0; -} diff --git a/05/tcc-final-old/tests/tests2/99_fastcall.expect b/05/tcc-final-old/tests/tests2/99_fastcall.expect deleted file mode 100644 index 3835d63..0000000 --- a/05/tcc-final-old/tests/tests2/99_fastcall.expect +++ /dev/null @@ -1 +0,0 @@ -TEST OK diff --git a/05/tcc-final-old/tests/tests2/LICENSE b/05/tcc-final-old/tests/tests2/LICENSE deleted file mode 100644 index b08a652..0000000 --- a/05/tcc-final-old/tests/tests2/LICENSE +++ /dev/null @@ -1,37 +0,0 @@ -The tests in this directory are either directly copied from the picoc project or -are subsequently modified and added to for the purpose of TinyCC project. All -these modifications are licensed under the same terms as TinyCC as specified in -the file COPYING. - -=== picoc license === - -Copyright (c) 2009-2011, Zik Saleeba -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - * 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. - - * Neither the name of the Zik Saleeba 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 COPYRIGHT HOLDERS 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 COPYRIGHT -OWNER 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. diff --git a/05/tcc-final-old/tests/tests2/Makefile b/05/tcc-final-old/tests/tests2/Makefile deleted file mode 100644 index 190b2d9..0000000 --- a/05/tcc-final-old/tests/tests2/Makefile +++ /dev/null @@ -1,112 +0,0 @@ -TOP = ../.. -include $(TOP)/Makefile -SRC = $(TOPSRC)/tests/tests2 -VPATH = $(SRC) - -TESTS = $(patsubst %.c,%.test,$(sort $(notdir $(wildcard $(SRC)/*.c)))) - -# some tests do not pass on all platforms, remove them for now -SKIP = 34_array_assignment.test # array assignment is not in C standard -ifeq ($(CONFIG_arm_eabi),yes) # not ARM soft-float - SKIP += 22_floating_point.test -endif -ifdef CONFIG_OSX - SKIP += 40_stdio.test 42_function_pointer.test - FLAGS += -w -endif -ifeq ($(ARCH),x86_64) - SKIP += 73_arm64.test -endif -ifeq (,$(filter i386,$(ARCH))) - SKIP += 98_al_ax_extend.test 99_fastcall.test -endif -ifeq (,$(filter i386 x86_64,$(ARCH))) - SKIP += 85_asm-outside-function.test -endif -ifeq (-$(findstring gcc,$(CC))-,--) - SKIP += $(patsubst %.expect,%.test,$(GEN-ALWAYS)) -endif -ifeq (-$(CONFIG_WIN32)-$(CONFIG_i386)$(CONFIG_arm)-,--yes-) - SKIP += 95_bitfields%.test # type_align is different on 32bit-non-windows -endif - -# Some tests might need arguments -ARGS = -31_args.test : ARGS = arg1 arg2 arg3 arg4 arg5 -46_grep.test : ARGS = '[^* ]*[:a:d: ]+\:\*-/: $$' $(SRC)/46_grep.c - -# And some tests don't test the right thing with -run -NORUN = -42_function_pointer.test : NORUN = true - -# Some tests might need different flags -FLAGS = -76_dollars_in_identifiers.test : FLAGS += -fdollars-in-identifiers - -# These tests run several snippets from the same file one by one -60_errors_and_warnings.test : FLAGS += -dt -96_nodata_wanted.test : FLAGS += -dt - -# Always generate certain .expects (don't put these in the GIT), -GEN-ALWAYS = -# GEN-ALWAYS += 95_bitfields.expect # does not work - -# using the ms compiler for the really ms-compatible bitfields -95_bitfields_ms.test : GEN = $(GEN-MSC) - -# Filter source directory in warnings/errors (out-of-tree builds) -FILTER = 2>&1 | sed 's,$(SRC)/,,g' -# Filter some always-warning -ifeq (-$(findstring arm,$(ARCH))-,-arm-) -FILTER += 2>&1 | grep -v 'warning: soft float ABI currently not supported' -endif - -all test tests2.all: $(filter-out $(SKIP),$(TESTS)) ; - -%.test: %.c %.expect - @echo Test: $*... - @$(if $(NORUN),$(T1),$(T2)) $(if $(NODIFF),,$(T3)) - -T1 = $(TCC) $(FLAGS) $< -o a.exe && ./a.exe $(ARGS) -T2 = $(TCC) $(FLAGS) -run $< $(ARGS) -T3 = $(FILTER) >$*.output 2>&1 || true \ - && diff -Nbu $(filter %.expect,$^) $*.output \ - && rm -f $*.output $(filter $*.expect,$(GEN-ALWAYS)) - -# run single test and update .expect file, e.g. "make tests2.37+" -tests2.%+: - @$(MAKE) $(call F2,$(call F1,$*)) --no-print-directory - -# just run tcc to see the output, e.g. "make tests2.37-" -tests2.%-: - @$(MAKE) $(call F1,$*) NODIFF=true --no-print-directory - -# run single test, e.g. "make tests2.37" -tests2.%: - @$(MAKE) $(call F1,$*) --no-print-directory - -F1 = $(or $(filter $1_%,$(TESTS)),$1_???.test) -F2 = $1 UPDATE="$(patsubst %.test,%.expect,$1)" - -# automatically generate .expect files with gcc: -%.expect : - @echo Generating: $@ - @$(call GEN,$(SRC)/$*.c) $(FILTER) >$@ 2>&1 - @rm -f *.exe *.obj *.pdb - -# using TCC for .expect if -dt in FLAGS -GEN = $(if $(filter -dt,$(FLAGS)),$(GEN-TCC),$(GEN-CC)) -GEN-CC = $(CC) -w -std=gnu99 $(FLAGS) $1 -o a.exe && ./a.exe $(ARGS) -GEN-TCC = $(TCC) $(FLAGS) -run $1 $(ARGS) -GEN-MSC = $(MS-CC) $1 && ./$(basename $@).exe -MS-CC = cl - -# tell make not to delete -.PRECIOUS: %.expect - -# force .expect generation for these files -$(sort $(GEN-ALWAYS) $(UPDATE)) : force -force: - -clean: - rm -f fred.txt *.output a.exe $(GEN-ALWAYS) diff --git a/05/tcc-final-old/tests/vla_test.c b/05/tcc-final-old/tests/vla_test.c deleted file mode 100644 index 3616c46..0000000 --- a/05/tcc-final-old/tests/vla_test.c +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Test that allocating a variable length array in a loop - * does not use up a linear amount of memory - */ - -#include -#include -#include - -#define LOOP_COUNT 1000 -#define ARRAY_SIZE 100 - -/* Overwrite a VLA. This will overwrite the return address if SP is incorrect */ -void smash(char *p, int n) { - memset(p, 0, n); -} - -int test1(int n) { - int i; - char *array_ptrs[LOOP_COUNT]; - - for (i = 0; i < LOOP_COUNT; ++i) { - char test[n]; - smash(test, n); - array_ptrs[i] = test; - } - - return (array_ptrs[0]-array_ptrs[LOOP_COUNT-1] < n) ? 0 : 1; -} - -/* ensure goto does not circumvent array free */ -int test2(int n) { - char *array_ptrs[LOOP_COUNT]; - - int i = 0; -loop:; - char test[n]; - smash(test, n); - if (i >= LOOP_COUNT) - goto end; - array_ptrs[i] = test; - ++i; - goto loop; - -end: - smash(test, n); - char test2[n]; - smash(test2, n); - return (array_ptrs[0] - array_ptrs[LOOP_COUNT-1] < n) ? 0 : 1; -} - -int test3(int n) { - char test[n]; - smash(test, n); - goto label; -label: - smash(test, n); - char test2[n]; - smash(test2, n); - return (test-test2 >= n) ? 0 : 1; -} - -#define RUN_TEST(t) \ - if (!testname || (strcmp(#t, testname) == 0)) { \ - fputs(#t "... ", stdout); \ - fflush(stdout); \ - if (t(ARRAY_SIZE) == 0) { \ - fputs("success\n", stdout); \ - } else { \ - fputs("failure\n", stdout); \ - retval = EXIT_FAILURE; \ - } \ - } - -int main(int argc, char **argv) { - const char *testname = NULL; - int retval = EXIT_SUCCESS; - if (argc > 1) - testname = argv[1]; - RUN_TEST(test1) - RUN_TEST(test2) - RUN_TEST(test3) - return retval; -} diff --git a/05/tcc-final-old/texi2pod.pl b/05/tcc-final-old/texi2pod.pl deleted file mode 100755 index d86e176..0000000 --- a/05/tcc-final-old/texi2pod.pl +++ /dev/null @@ -1,427 +0,0 @@ -#! /usr/bin/perl -w - -# Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. - -# This file is part of GNU CC. - -# GNU CC is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2, or (at your option) -# any later version. - -# GNU CC is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with GNU CC; see the file COPYING. If not, write to -# the Free Software Foundation, 59 Temple Place - Suite 330, -# Boston MA 02111-1307, USA. - -# This does trivial (and I mean _trivial_) conversion of Texinfo -# markup to Perl POD format. It's intended to be used to extract -# something suitable for a manpage from a Texinfo document. - -$output = 0; -$skipping = 0; -%sects = (); -$section = ""; -@icstack = (); -@endwstack = (); -@skstack = (); -@instack = (); -$shift = ""; -%defs = (); -$fnno = 1; -$inf = ""; -$ibase = ""; - -while ($_ = shift) { - if (/^-D(.*)$/) { - if ($1 ne "") { - $flag = $1; - } else { - $flag = shift; - } - $value = ""; - ($flag, $value) = ($flag =~ /^([^=]+)(?:=(.+))?/); - die "no flag specified for -D\n" - unless $flag ne ""; - die "flags may only contain letters, digits, hyphens, dashes and underscores\n" - unless $flag =~ /^[a-zA-Z0-9_-]+$/; - $defs{$flag} = $value; - } elsif (/^-/) { - usage(); - } else { - $in = $_, next unless defined $in; - $out = $_, next unless defined $out; - usage(); - } -} - -if (defined $in) { - $inf = gensym(); - open($inf, "<$in") or die "opening \"$in\": $!\n"; - $ibase = $1 if $in =~ m|^(.+)/[^/]+$|; -} else { - $inf = \*STDIN; -} - -if (defined $out) { - open(STDOUT, ">$out") or die "opening \"$out\": $!\n"; -} - -while(defined $inf) { -while(<$inf>) { - # Certain commands are discarded without further processing. - /^\@(?: - [a-z]+index # @*index: useful only in complete manual - |need # @need: useful only in printed manual - |(?:end\s+)?group # @group .. @end group: ditto - |page # @page: ditto - |node # @node: useful only in .info file - |(?:end\s+)?ifnottex # @ifnottex .. @end ifnottex: use contents - )\b/x and next; - - chomp; - - # Look for filename and title markers. - /^\@setfilename\s+([^.]+)/ and $fn = $1, next; - /^\@settitle\s+([^.]+)/ and $tl = postprocess($1), next; - - # Identify a man title but keep only the one we are interested in. - /^\@c\s+man\s+title\s+([A-Za-z0-9-]+)\s+(.+)/ and do { - if (exists $defs{$1}) { - $fn = $1; - $tl = postprocess($2); - } - next; - }; - - # Look for blocks surrounded by @c man begin SECTION ... @c man end. - # This really oughta be @ifman ... @end ifman and the like, but such - # would require rev'ing all other Texinfo translators. - /^\@c\s+man\s+begin\s+([A-Z]+)\s+([A-Za-z0-9-]+)/ and do { - $output = 1 if exists $defs{$2}; - $sect = $1; - next; - }; - /^\@c\s+man\s+begin\s+([A-Z]+)/ and $sect = $1, $output = 1, next; - /^\@c\s+man\s+end/ and do { - $sects{$sect} = "" unless exists $sects{$sect}; - $sects{$sect} .= postprocess($section); - $section = ""; - $output = 0; - next; - }; - - # handle variables - /^\@set\s+([a-zA-Z0-9_-]+)\s*(.*)$/ and do { - $defs{$1} = $2; - next; - }; - /^\@clear\s+([a-zA-Z0-9_-]+)/ and do { - delete $defs{$1}; - next; - }; - - next unless $output; - - # Discard comments. (Can't do it above, because then we'd never see - # @c man lines.) - /^\@c\b/ and next; - - # End-block handler goes up here because it needs to operate even - # if we are skipping. - /^\@end\s+([a-z]+)/ and do { - # Ignore @end foo, where foo is not an operation which may - # cause us to skip, if we are presently skipping. - my $ended = $1; - next if $skipping && $ended !~ /^(?:ifset|ifclear|ignore|menu|iftex)$/; - - die "\@end $ended without \@$ended at line $.\n" unless defined $endw; - die "\@$endw ended by \@end $ended at line $.\n" unless $ended eq $endw; - - $endw = pop @endwstack; - - if ($ended =~ /^(?:ifset|ifclear|ignore|menu|iftex)$/) { - $skipping = pop @skstack; - next; - } elsif ($ended =~ /^(?:example|smallexample|display)$/) { - $shift = ""; - $_ = ""; # need a paragraph break - } elsif ($ended =~ /^(?:itemize|enumerate|[fv]?table)$/) { - $_ = "\n=back\n"; - $ic = pop @icstack; - } else { - die "unknown command \@end $ended at line $.\n"; - } - }; - - # We must handle commands which can cause skipping even while we - # are skipping, otherwise we will not process nested conditionals - # correctly. - /^\@ifset\s+([a-zA-Z0-9_-]+)/ and do { - push @endwstack, $endw; - push @skstack, $skipping; - $endw = "ifset"; - $skipping = 1 unless exists $defs{$1}; - next; - }; - - /^\@ifclear\s+([a-zA-Z0-9_-]+)/ and do { - push @endwstack, $endw; - push @skstack, $skipping; - $endw = "ifclear"; - $skipping = 1 if exists $defs{$1}; - next; - }; - - /^\@(ignore|menu|iftex)\b/ and do { - push @endwstack, $endw; - push @skstack, $skipping; - $endw = $1; - $skipping = 1; - next; - }; - - next if $skipping; - - # Character entities. First the ones that can be replaced by raw text - # or discarded outright: - s/\@copyright\{\}/(c)/g; - s/\@dots\{\}/.../g; - s/\@enddots\{\}/..../g; - s/\@([.!? ])/$1/g; - s/\@[:-]//g; - s/\@bullet(?:\{\})?/*/g; - s/\@TeX\{\}/TeX/g; - s/\@pounds\{\}/\#/g; - s/\@minus(?:\{\})?/-/g; - s/\\,/,/g; - - # Now the ones that have to be replaced by special escapes - # (which will be turned back into text by unmunge()) - s/&/&/g; - s/\@\{/{/g; - s/\@\}/}/g; - s/\@\@/&at;/g; - - # Inside a verbatim block, handle @var specially. - if ($shift ne "") { - s/\@var\{([^\}]*)\}/<$1>/g; - } - - # POD doesn't interpret E<> inside a verbatim block. - if ($shift eq "") { - s//>/g; - } else { - s//>/g; - } - - # Single line command handlers. - - /^\@include\s+(.+)$/ and do { - push @instack, $inf; - $inf = gensym(); - - # Try cwd and $ibase. - open($inf, "<" . $1) - or open($inf, "<" . $ibase . "/" . $1) - or die "cannot open $1 or $ibase/$1: $!\n"; - next; - }; - - /^\@(?:section|unnumbered|unnumberedsec|center)\s+(.+)$/ - and $_ = "\n=head2 $1\n"; - /^\@subsection\s+(.+)$/ - and $_ = "\n=head3 $1\n"; - - # Block command handlers: - /^\@itemize\s+(\@[a-z]+|\*|-)/ and do { - push @endwstack, $endw; - push @icstack, $ic; - $ic = $1; - $_ = "\n=over 4\n"; - $endw = "itemize"; - }; - - /^\@enumerate(?:\s+([a-zA-Z0-9]+))?/ and do { - push @endwstack, $endw; - push @icstack, $ic; - if (defined $1) { - $ic = $1 . "."; - } else { - $ic = "1."; - } - $_ = "\n=over 4\n"; - $endw = "enumerate"; - }; - - /^\@([fv]?table)\s+(\@[a-z]+)/ and do { - push @endwstack, $endw; - push @icstack, $ic; - $endw = $1; - $ic = $2; - $ic =~ s/\@(?:samp|strong|key|gcctabopt|option|env)/B/; - $ic =~ s/\@(?:code|kbd)/C/; - $ic =~ s/\@(?:dfn|var|emph|cite|i)/I/; - $ic =~ s/\@(?:file)/F/; - $_ = "\n=over 4\n"; - }; - - /^\@((?:small)?example|display)/ and do { - push @endwstack, $endw; - $endw = $1; - $shift = "\t"; - $_ = ""; # need a paragraph break - }; - - /^\@itemx?\s*(.+)?$/ and do { - if (defined $1) { - # Entity escapes prevent munging by the <> processing below. - $_ = "\n=item $ic\<$1\>\n"; - } else { - $_ = "\n=item $ic\n"; - $ic =~ y/A-Ya-y/B-Zb-z/; - $ic =~ s/(\d+)/$1 + 1/eg; - } - }; - - $section .= $shift.$_."\n"; -} -# End of current file. -close($inf); -$inf = pop @instack; -} - -die "No filename or title\n" unless defined $fn && defined $tl; - -$sects{NAME} = "$fn \- $tl\n"; -$sects{FOOTNOTES} .= "=back\n" if exists $sects{FOOTNOTES}; - -for $sect (qw(NAME SYNOPSIS DESCRIPTION OPTIONS ENVIRONMENT FILES - BUGS NOTES FOOTNOTES SEEALSO AUTHOR COPYRIGHT)) { - if(exists $sects{$sect}) { - $head = $sect; - $head =~ s/SEEALSO/SEE ALSO/; - print "=head1 $head\n\n"; - print scalar unmunge ($sects{$sect}); - print "\n"; - } -} - -sub usage -{ - die "usage: $0 [-D toggle...] [infile [outfile]]\n"; -} - -sub postprocess -{ - local $_ = $_[0]; - - # @value{foo} is replaced by whatever 'foo' is defined as. - while (m/(\@value\{([a-zA-Z0-9_-]+)\})/g) { - if (! exists $defs{$2}) { - print STDERR "Option $2 not defined\n"; - s/\Q$1\E//; - } else { - $value = $defs{$2}; - s/\Q$1\E/$value/; - } - } - - # Formatting commands. - # Temporary escape for @r. - s/\@r\{([^\}]*)\}/R<$1>/g; - s/\@(?:dfn|var|emph|cite|i)\{([^\}]*)\}/I<$1>/g; - s/\@(?:code|kbd)\{([^\}]*)\}/C<$1>/g; - s/\@(?:gccoptlist|samp|strong|key|option|env|command|b)\{([^\}]*)\}/B<$1>/g; - s/\@sc\{([^\}]*)\}/\U$1/g; - s/\@file\{([^\}]*)\}/F<$1>/g; - s/\@w\{([^\}]*)\}/S<$1>/g; - s/\@(?:dmn|math)\{([^\}]*)\}/$1/g; - - # Cross references are thrown away, as are @noindent and @refill. - # (@noindent is impossible in .pod, and @refill is unnecessary.) - # @* is also impossible in .pod; we discard it and any newline that - # follows it. Similarly, our macro @gol must be discarded. - - s/\(?\@xref\{(?:[^\}]*)\}(?:[^.<]|(?:<[^<>]*>))*\.\)?//g; - s/\s+\(\@pxref\{(?:[^\}]*)\}\)//g; - s/;\s+\@pxref\{(?:[^\}]*)\}//g; - s/\@noindent\s*//g; - s/\@refill//g; - s/\@gol//g; - s/\@\*\s*\n?//g; - - # @uref can take one, two, or three arguments, with different - # semantics each time. @url and @email are just like @uref with - # one argument, for our purposes. - s/\@(?:uref|url|email)\{([^\},]*)\}/<B<$1>>/g; - s/\@uref\{([^\},]*),([^\},]*)\}/$2 (C<$1>)/g; - s/\@uref\{([^\},]*),([^\},]*),([^\},]*)\}/$3/g; - - # Turn B blah> into B I B to - # match Texinfo semantics of @emph inside @samp. Also handle @r - # inside bold. - s/<//g; - 1 while s/B<((?:[^<>]|I<[^<>]*>)*)R<([^>]*)>/B<$1>${2}B]*)I<([^>]+)>/B<$1>I<$2>B]*)B<([^>]+)>/I<$1>B<$2>I//g; - s/([BI])<(\s+)([^>]+)>/$2$1<$3>/g; - s/([BI])<([^>]+?)(\s+)>/$1<$2>$3/g; - - # Extract footnotes. This has to be done after all other - # processing because otherwise the regexp will choke on formatting - # inside @footnote. - while (/\@footnote/g) { - s/\@footnote\{([^\}]+)\}/[$fnno]/; - add_footnote($1, $fnno); - $fnno++; - } - - return $_; -} - -sub unmunge -{ - # Replace escaped symbols with their equivalents. - local $_ = $_[0]; - - s/</E/g; - s/>/E/g; - s/{/\{/g; - s/}/\}/g; - s/&at;/\@/g; - s/&/&/g; - return $_; -} - -sub add_footnote -{ - unless (exists $sects{FOOTNOTES}) { - $sects{FOOTNOTES} = "\n=over 4\n\n"; - } - - $sects{FOOTNOTES} .= "=item $fnno.\n\n"; $fnno++; - $sects{FOOTNOTES} .= $_[0]; - $sects{FOOTNOTES} .= "\n\n"; -} - -# stolen from Symbol.pm -{ - my $genseq = 0; - sub gensym - { - my $name = "GEN" . $genseq++; - my $ref = \*{$name}; - delete $::{$name}; - return $ref; - } -} diff --git a/05/tcc-final-old/win32/build-tcc.bat b/05/tcc-final-old/win32/build-tcc.bat deleted file mode 100755 index 913b068..0000000 --- a/05/tcc-final-old/win32/build-tcc.bat +++ /dev/null @@ -1,189 +0,0 @@ -@rem ------------------------------------------------------ -@rem batch file to build tcc using mingw, msvc or tcc itself -@rem ------------------------------------------------------ - -@echo off -setlocal -if (%1)==(-clean) goto :cleanup -set CC=gcc -set /p VERSION= < ..\VERSION -set INST= -set BIN= -set DOC=no -set EXES_ONLY=no -goto :a0 -:a2 -shift -:a3 -shift -:a0 -if not (%1)==(-c) goto :a1 -set CC=%~2 -if (%2)==(cl) set CC=@call :cl -goto :a2 -:a1 -if (%1)==(-t) set T=%2&& goto :a2 -if (%1)==(-v) set VERSION=%~2&& goto :a2 -if (%1)==(-i) set INST=%2&& goto :a2 -if (%1)==(-b) set BIN=%2&& goto :a2 -if (%1)==(-d) set DOC=yes&& goto :a3 -if (%1)==(-x) set EXES_ONLY=yes&& goto :a3 -if (%1)==() goto :p1 -:usage -echo usage: build-tcc.bat [ options ... ] -echo options: -echo -c prog use prog (gcc/tcc/cl) to compile tcc -echo -c "prog options" use prog with options to compile tcc -echo -t 32/64 force 32/64 bit default target -echo -v "version" set tcc version -echo -i tccdir install tcc into tccdir -echo -b bindir optionally install binaries into bindir elsewhere -echo -d create tcc-doc.html too (needs makeinfo) -echo -x just create the executables -echo -clean delete all previously produced files and directories -exit /B 1 - -@rem ------------------------------------------------------ -@rem sub-routines - -:cleanup -set LOG=echo -%LOG% removing files: -for %%f in (*tcc.exe libtcc.dll lib\*.a) do call :del_file %%f -for %%f in (..\config.h ..\config.texi) do call :del_file %%f -for %%f in (include\*.h) do @if exist ..\%%f call :del_file %%f -for %%f in (include\tcclib.h examples\libtcc_test.c) do call :del_file %%f -for %%f in (*.o *.obj *.def *.pdb *.lib *.exp *.ilk) do call :del_file %%f -%LOG% removing directories: -for %%f in (doc libtcc) do call :del_dir %%f -%LOG% done. -exit /B 0 -:del_file -if exist %1 del %1 && %LOG% %1 -exit /B 0 -:del_dir -if exist %1 rmdir /Q/S %1 && %LOG% %1 -exit /B 0 - -:cl -@echo off -set CMD=cl -:c0 -set ARG=%1 -set ARG=%ARG:.dll=.lib% -if (%1)==(-shared) set ARG=-LD -if (%1)==(-o) shift && set ARG=-Fe%2 -set CMD=%CMD% %ARG% -shift -if not (%1)==() goto :c0 -echo on -%CMD% -O1 -W2 -Zi -MT -GS- -nologo -link -opt:ref,icf -@exit /B %ERRORLEVEL% - -@rem ------------------------------------------------------ -@rem main program - -:p1 -if not %T%_==_ goto :p2 -set T=32 -if %PROCESSOR_ARCHITECTURE%_==AMD64_ set T=64 -if %PROCESSOR_ARCHITEW6432%_==AMD64_ set T=64 -:p2 -if "%CC:~-3%"=="gcc" set CC=%CC% -Os -s -static -set D32=-DTCC_TARGET_PE -DTCC_TARGET_I386 -set D64=-DTCC_TARGET_PE -DTCC_TARGET_X86_64 -set P32=i386-win32 -set P64=x86_64-win32 -if %T%==64 goto :t64 -set D=%D32% -set DX=%D64% -set PX=%P64% -goto :p3 -:t64 -set D=%D64% -set DX=%D32% -set PX=%P32% -goto :p3 - -:p3 -@echo on - -:config.h -echo>..\config.h #define TCC_VERSION "%VERSION%" -echo>> ..\config.h #ifdef TCC_TARGET_X86_64 -echo>> ..\config.h #define TCC_LIBTCC1 "libtcc1-64.a" -echo>> ..\config.h #else -echo>> ..\config.h #define TCC_LIBTCC1 "libtcc1-32.a" -echo>> ..\config.h #endif - -for %%f in (*tcc.exe *tcc.dll) do @del %%f - -:compiler -%CC% -o libtcc.dll -shared ..\libtcc.c %D% -DLIBTCC_AS_DLL -@if errorlevel 1 goto :the_end -%CC% -o tcc.exe ..\tcc.c libtcc.dll %D% -DONE_SOURCE"=0" -%CC% -o %PX%-tcc.exe ..\tcc.c %DX% - -@if (%EXES_ONLY%)==(yes) goto :files-done - -if not exist libtcc mkdir libtcc -if not exist doc mkdir doc -copy>nul ..\include\*.h include -copy>nul ..\tcclib.h include -copy>nul ..\libtcc.h libtcc -copy>nul ..\tests\libtcc_test.c examples -copy>nul tcc-win32.txt doc - -.\tcc -impdef libtcc.dll -o libtcc\libtcc.def -@if errorlevel 1 goto :the_end - -:libtcc1.a -@set O1=libtcc1.o crt1.o crt1w.o wincrt1.o wincrt1w.o dllcrt1.o dllmain.o chkstk.o bcheck.o -.\tcc -m32 -c ../lib/libtcc1.c -.\tcc -m32 -c lib/crt1.c -.\tcc -m32 -c lib/crt1w.c -.\tcc -m32 -c lib/wincrt1.c -.\tcc -m32 -c lib/wincrt1w.c -.\tcc -m32 -c lib/dllcrt1.c -.\tcc -m32 -c lib/dllmain.c -.\tcc -m32 -c lib/chkstk.S -.\tcc -m32 -w -c ../lib/bcheck.c -.\tcc -m32 -c ../lib/alloca86.S -.\tcc -m32 -c ../lib/alloca86-bt.S -.\tcc -m32 -ar lib/libtcc1-32.a %O1% alloca86.o alloca86-bt.o -@if errorlevel 1 goto :the_end -.\tcc -m64 -c ../lib/libtcc1.c -.\tcc -m64 -c lib/crt1.c -.\tcc -m64 -c lib/crt1w.c -.\tcc -m64 -c lib/wincrt1.c -.\tcc -m64 -c lib/wincrt1w.c -.\tcc -m64 -c lib/dllcrt1.c -.\tcc -m64 -c lib/dllmain.c -.\tcc -m64 -c lib/chkstk.S -.\tcc -m64 -w -c ../lib/bcheck.c -.\tcc -m64 -c ../lib/alloca86_64.S -.\tcc -m64 -c ../lib/alloca86_64-bt.S -.\tcc -m64 -ar lib/libtcc1-64.a %O1% alloca86_64.o alloca86_64-bt.o -@if errorlevel 1 goto :the_end - -:tcc-doc.html -@if not (%DOC%)==(yes) goto :doc-done -echo>..\config.texi @set VERSION %VERSION% -cmd /c makeinfo --html --no-split ../tcc-doc.texi -o doc/tcc-doc.html -:doc-done - -:files-done -for %%f in (*.o *.def) do @del %%f - -:copy-install -@if (%INST%)==() goto :the_end -if not exist %INST% mkdir %INST% -@if (%BIN%)==() set BIN=%INST% -if not exist %BIN% mkdir %BIN% -for %%f in (*tcc.exe *tcc.dll) do @copy>nul %%f %BIN%\%%f -@if not exist %INST%\lib mkdir %INST%\lib -for %%f in (lib\*.a lib\*.def) do @copy>nul %%f %INST%\%%f -for %%f in (include examples libtcc doc) do @xcopy>nul /s/i/q/y %%f %INST%\%%f - -:the_end -exit /B %ERRORLEVEL% diff --git a/05/tcc-final-old/win32/examples/dll.c b/05/tcc-final-old/win32/examples/dll.c deleted file mode 100644 index 052a056..0000000 --- a/05/tcc-final-old/win32/examples/dll.c +++ /dev/null @@ -1,13 +0,0 @@ -//+--------------------------------------------------------------------------- -// -// dll.c - Windows DLL example - dynamically linked part -// - -#include - -__declspec(dllexport) const char *hello_data = "(not set)"; - -__declspec(dllexport) void hello_func (void) -{ - MessageBox (0, hello_data, "From DLL", MB_ICONINFORMATION); -} diff --git a/05/tcc-final-old/win32/examples/fib.c b/05/tcc-final-old/win32/examples/fib.c deleted file mode 100644 index 8da26bc..0000000 --- a/05/tcc-final-old/win32/examples/fib.c +++ /dev/null @@ -1,24 +0,0 @@ -#include -#include // atoi() - -int fib(n) -{ - if (n <= 2) - return 1; - else - return fib(n-1) + fib(n-2); -} - -int main(int argc, char **argv) -{ - int n; - if (argc < 2) { - printf("usage: fib n\n" - "Compute nth Fibonacci number\n"); - return 1; - } - - n = atoi(argv[1]); - printf("fib(%d) = %d\n", n, fib(n)); - return 0; -} diff --git a/05/tcc-final-old/win32/examples/hello_dll.c b/05/tcc-final-old/win32/examples/hello_dll.c deleted file mode 100644 index 4813c5b..0000000 --- a/05/tcc-final-old/win32/examples/hello_dll.c +++ /dev/null @@ -1,20 +0,0 @@ -//+--------------------------------------------------------------------------- -// -// HELLO_DLL.C - Windows DLL example - main application part -// - -#include - -void hello_func (void); -__declspec(dllimport) extern const char *hello_data; - -int WINAPI WinMain( - HINSTANCE hInstance, - HINSTANCE hPrevInstance, - LPSTR lpCmdLine, - int nCmdShow) -{ - hello_data = "Hello World!"; - hello_func(); - return 0; -} diff --git a/05/tcc-final-old/win32/examples/hello_win.c b/05/tcc-final-old/win32/examples/hello_win.c deleted file mode 100644 index 96546e4..0000000 --- a/05/tcc-final-old/win32/examples/hello_win.c +++ /dev/null @@ -1,163 +0,0 @@ -//+--------------------------------------------------------------------------- -// -// HELLO_WIN.C - Windows GUI 'Hello World!' Example -// -//+--------------------------------------------------------------------------- - -#include - -#define APPNAME "HELLO_WIN" - -char szAppName[] = APPNAME; // The name of this application -char szTitle[] = APPNAME; // The title bar text -const char *pWindowText; - -void CenterWindow(HWND hWnd); - -//+--------------------------------------------------------------------------- -// -// Function: WndProc -// -// Synopsis: very unusual type of function - gets called by system to -// process windows messages. -// -// Arguments: same as always. -//---------------------------------------------------------------------------- - -LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) -{ - switch (message) { - - // ----------------------- first and last - case WM_CREATE: - CenterWindow(hwnd); - break; - - case WM_DESTROY: - PostQuitMessage(0); - break; - - // ----------------------- get out of it... - case WM_RBUTTONUP: - DestroyWindow(hwnd); - break; - - case WM_KEYDOWN: - if (VK_ESCAPE == wParam) - DestroyWindow(hwnd); - break; - - // ----------------------- display our minimal info - case WM_PAINT: - { - PAINTSTRUCT ps; - HDC hdc; - RECT rc; - hdc = BeginPaint(hwnd, &ps); - - GetClientRect(hwnd, &rc); - SetTextColor(hdc, RGB(240,240,96)); - SetBkMode(hdc, TRANSPARENT); - DrawText(hdc, pWindowText, -1, &rc, DT_CENTER|DT_SINGLELINE|DT_VCENTER); - - EndPaint(hwnd, &ps); - break; - } - - // ----------------------- let windows do all other stuff - default: - return DefWindowProc(hwnd, message, wParam, lParam); - } - return 0; -} - -//+--------------------------------------------------------------------------- -// -// Function: WinMain -// -// Synopsis: standard entrypoint for GUI Win32 apps -// -//---------------------------------------------------------------------------- -int APIENTRY WinMain( - HINSTANCE hInstance, - HINSTANCE hPrevInstance, - LPSTR lpCmdLine, - int nCmdShow - ) -{ - MSG msg; - WNDCLASS wc; - HWND hwnd; - - pWindowText = lpCmdLine[0] ? lpCmdLine : "Hello Windows!"; - - // Fill in window class structure with parameters that describe - // the main window. - - ZeroMemory(&wc, sizeof wc); - wc.hInstance = hInstance; - wc.lpszClassName = szAppName; - wc.lpfnWndProc = (WNDPROC)WndProc; - wc.style = CS_DBLCLKS|CS_VREDRAW|CS_HREDRAW; - wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); - wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); - wc.hCursor = LoadCursor(NULL, IDC_ARROW); - - if (FALSE == RegisterClass(&wc)) - return 0; - - // create the browser - hwnd = CreateWindow( - szAppName, - szTitle, - WS_OVERLAPPEDWINDOW|WS_VISIBLE, - CW_USEDEFAULT, - CW_USEDEFAULT, - 360,//CW_USEDEFAULT, - 240,//CW_USEDEFAULT, - 0, - 0, - hInstance, - 0); - - if (NULL == hwnd) - return 0; - - // Main message loop: - while (GetMessage(&msg, NULL, 0, 0) > 0) { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - - return msg.wParam; -} - -//+--------------------------------------------------------------------------- - -//+--------------------------------------------------------------------------- - -void CenterWindow(HWND hwnd_self) -{ - HWND hwnd_parent; - RECT rw_self, rc_parent, rw_parent; - int xpos, ypos; - - hwnd_parent = GetParent(hwnd_self); - if (NULL == hwnd_parent) - hwnd_parent = GetDesktopWindow(); - - GetWindowRect(hwnd_parent, &rw_parent); - GetClientRect(hwnd_parent, &rc_parent); - GetWindowRect(hwnd_self, &rw_self); - - xpos = rw_parent.left + (rc_parent.right + rw_self.left - rw_self.right) / 2; - ypos = rw_parent.top + (rc_parent.bottom + rw_self.top - rw_self.bottom) / 2; - - SetWindowPos( - hwnd_self, NULL, - xpos, ypos, 0, 0, - SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE - ); -} - -//+--------------------------------------------------------------------------- diff --git a/05/tcc-final-old/win32/include/_mingw.h b/05/tcc-final-old/win32/include/_mingw.h deleted file mode 100644 index 2fc9798..0000000 --- a/05/tcc-final-old/win32/include/_mingw.h +++ /dev/null @@ -1,170 +0,0 @@ -/* - * _mingw.h - * - * This file is for TinyCC and not part of the Mingw32 package. - * - * THIS SOFTWARE IS NOT COPYRIGHTED - * - * This source code is offered for use in the public domain. You may - * use, modify or distribute it freely. - * - * This code is distributed in the hope that it will be useful but - * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY - * DISCLAIMED. This includes but is not limited to warranties of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - */ - -#ifndef __MINGW_H -#define __MINGW_H - -/* some winapi files define these before including _mingw.h --> */ -#undef __cdecl -#undef _X86_ -#undef WIN32 -/* <-- */ - -#include -#include - -#define __int8 char -#define __int16 short -#define __int32 int -#define __int64 long long -#define _HAVE_INT64 - -#define __cdecl -#define __declspec(x) __attribute__((x)) -#define __unaligned __attribute__((packed)) -#define __fastcall __attribute__((fastcall)) - -#define __MSVCRT__ 1 -#undef _MSVCRT_ -#define __MINGW_IMPORT extern __declspec(dllimport) -#define __MINGW_ATTRIB_NORETURN -#define __MINGW_ATTRIB_CONST -#define __MINGW_ATTRIB_DEPRECATED -#define __MINGW_ATTRIB_MALLOC -#define __MINGW_ATTRIB_PURE -#define __MINGW_ATTRIB_NONNULL(arg) -#define __MINGW_NOTHROW -#define __GNUC_VA_LIST - -#define _CRTIMP extern -#define __CRT_INLINE extern __inline__ - -#define _CRT_ALIGN(x) __attribute__((aligned(x))) -#define DECLSPEC_ALIGN(x) __attribute__((aligned(x))) -#define _CRT_PACKING 8 -#define __CRT_UNALIGNED -#define _CONST_RETURN - -#ifndef _TRUNCATE -#define _TRUNCATE ((size_t)-1) -#endif - -#define __CRT_STRINGIZE(_Value) #_Value -#define _CRT_STRINGIZE(_Value) __CRT_STRINGIZE(_Value) -#define __CRT_WIDE(_String) L ## _String -#define _CRT_WIDE(_String) __CRT_WIDE(_String) - -#ifdef _WIN64 -#define __stdcall -#define _AMD64_ 1 -#define __x86_64 1 -#define _M_X64 100 /* Visual Studio */ -#define _M_AMD64 100 /* Visual Studio */ -#define USE_MINGW_SETJMP_TWO_ARGS -#define mingw_getsp tinyc_getbp -#define __TRY__ -#else -#define __stdcall __attribute__((__stdcall__)) -#define _X86_ 1 -#define _M_IX86 300 /* Visual Studio */ -#define WIN32 1 -#define _USE_32BIT_TIME_T -#ifdef __arm__ -#define __TRY__ -#else -#define __TRY__ void __try__(void**), *_sehrec[6]; __try__(_sehrec); -#endif -#endif - -/* in stddef.h */ -#define _SIZE_T_DEFINED -#define _SSIZE_T_DEFINED -#define _PTRDIFF_T_DEFINED -#define _WCHAR_T_DEFINED -#define _UINTPTR_T_DEFINED -#define _INTPTR_T_DEFINED -#define _INTEGRAL_MAX_BITS 64 - -#ifndef _TIME32_T_DEFINED -#define _TIME32_T_DEFINED -typedef long __time32_t; -#endif - -#ifndef _TIME64_T_DEFINED -#define _TIME64_T_DEFINED -typedef long long __time64_t; -#endif - -#ifndef _TIME_T_DEFINED -#define _TIME_T_DEFINED -#ifdef _USE_32BIT_TIME_T -typedef __time32_t time_t; -#else -typedef __time64_t time_t; -#endif -#endif - -#ifndef _WCTYPE_T_DEFINED -#define _WCTYPE_T_DEFINED -typedef wchar_t wctype_t; -#endif - -#ifndef _WINT_T -#define _WINT_T -typedef __WINT_TYPE__ wint_t; -#endif - -typedef int errno_t; -#define _ERRCODE_DEFINED - -typedef struct threadlocaleinfostruct *pthreadlocinfo; -typedef struct threadmbcinfostruct *pthreadmbcinfo; -typedef struct localeinfo_struct _locale_tstruct,*_locale_t; - -/* for winapi */ -#define _ANONYMOUS_UNION -#define _ANONYMOUS_STRUCT -#define DECLSPEC_NORETURN -#define DECLARE_STDCALL_P(type) __stdcall type -#define NOSERVICE 1 -#define NOMCX 1 -#define NOIME 1 -#define __INTRIN_H_ -#ifndef DUMMYUNIONNAME -# define DUMMYUNIONNAME -# define DUMMYUNIONNAME1 -# define DUMMYUNIONNAME2 -# define DUMMYUNIONNAME3 -# define DUMMYUNIONNAME4 -# define DUMMYUNIONNAME5 -#endif -#ifndef DUMMYSTRUCTNAME -# define DUMMYSTRUCTNAME -#endif -#ifndef WINVER -# define WINVER 0x0502 -#endif -#ifndef _WIN32_WINNT -# define _WIN32_WINNT 0x502 -#endif - -#define __C89_NAMELESS -#define __MINGW_EXTENSION -#define WINAPI_FAMILY_PARTITION(X) 1 -#define MINGW_HAS_SECURE_API - -#endif /* __MINGW_H */ diff --git a/05/tcc-final-old/win32/include/assert.h b/05/tcc-final-old/win32/include/assert.h deleted file mode 100644 index 466d457..0000000 --- a/05/tcc-final-old/win32/include/assert.h +++ /dev/null @@ -1,57 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef __ASSERT_H_ -#define __ASSERT_H_ - -#include <_mingw.h> -#ifdef __cplusplus -#include -#endif - -#ifdef NDEBUG -#ifndef assert -#define assert(_Expression) ((void)0) -#endif -#else - -#ifndef _CRT_TERMINATE_DEFINED -#define _CRT_TERMINATE_DEFINED - void __cdecl __MINGW_NOTHROW exit(int _Code) __MINGW_ATTRIB_NORETURN; - _CRTIMP void __cdecl __MINGW_NOTHROW _exit(int _Code) __MINGW_ATTRIB_NORETURN; -#if !defined __NO_ISOCEXT /* extern stub in static libmingwex.a */ -/* C99 function name */ -void __cdecl _Exit(int) __MINGW_ATTRIB_NORETURN; -__CRT_INLINE __MINGW_ATTRIB_NORETURN void __cdecl _Exit(int status) -{ _exit(status); } -#endif - -#pragma push_macro("abort") -#undef abort - void __cdecl __declspec(noreturn) abort(void); -#pragma pop_macro("abort") - -#endif - -#ifdef __cplusplus -extern "C" { -#endif - - -extern void __cdecl _wassert(const wchar_t *_Message,const wchar_t *_File,unsigned _Line); -extern void __cdecl _assert(const char *, const char *, unsigned); - -#ifdef __cplusplus -} -#endif - -#ifndef assert -//#define assert(_Expression) (void)((!!(_Expression)) || (_wassert(_CRT_WIDE(#_Expression),_CRT_WIDE(__FILE__),__LINE__),0)) -#define assert(e) ((e) ? (void)0 : _assert(#e, __FILE__, __LINE__)) -#endif - -#endif - -#endif diff --git a/05/tcc-final-old/win32/include/conio.h b/05/tcc-final-old/win32/include/conio.h deleted file mode 100644 index 39f779e..0000000 --- a/05/tcc-final-old/win32/include/conio.h +++ /dev/null @@ -1,409 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _INC_CONIO -#define _INC_CONIO - -#include <_mingw.h> - -#ifdef __cplusplus -extern "C" { -#endif - - _CRTIMP char *_cgets(char *_Buffer); - _CRTIMP int __cdecl _cprintf(const char *_Format,...); - _CRTIMP int __cdecl _cputs(const char *_Str); - _CRTIMP int __cdecl _cscanf(const char *_Format,...); - _CRTIMP int __cdecl _cscanf_l(const char *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _getch(void); - _CRTIMP int __cdecl _getche(void); - _CRTIMP int __cdecl _vcprintf(const char *_Format,va_list _ArgList); - _CRTIMP int __cdecl _cprintf_p(const char *_Format,...); - _CRTIMP int __cdecl _vcprintf_p(const char *_Format,va_list _ArgList); - _CRTIMP int __cdecl _cprintf_l(const char *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _vcprintf_l(const char *_Format,_locale_t _Locale,va_list _ArgList); - _CRTIMP int __cdecl _cprintf_p_l(const char *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _vcprintf_p_l(const char *_Format,_locale_t _Locale,va_list _ArgList); - _CRTIMP int __cdecl _kbhit(void); - -#if defined(_X86_) && !defined(__x86_64) - int __cdecl _inp(unsigned short); - unsigned short __cdecl _inpw(unsigned short); - unsigned long __cdecl _inpd(unsigned short); - int __cdecl _outp(unsigned short,int); - unsigned short __cdecl _outpw(unsigned short,unsigned short); - unsigned long __cdecl _outpd(unsigned short,unsigned long); -#endif - - _CRTIMP int __cdecl _putch(int _Ch); - _CRTIMP int __cdecl _ungetch(int _Ch); - _CRTIMP int __cdecl _getch_nolock(void); - _CRTIMP int __cdecl _getche_nolock(void); - _CRTIMP int __cdecl _putch_nolock(int _Ch); - _CRTIMP int __cdecl _ungetch_nolock(int _Ch); - -#ifndef _WCONIO_DEFINED -#define _WCONIO_DEFINED - -#ifndef WEOF -#define WEOF (wint_t)(0xFFFF) -#endif - - _CRTIMP wchar_t *_cgetws(wchar_t *_Buffer); - _CRTIMP wint_t __cdecl _getwch(void); - _CRTIMP wint_t __cdecl _getwche(void); - _CRTIMP wint_t __cdecl _putwch(wchar_t _WCh); - _CRTIMP wint_t __cdecl _ungetwch(wint_t _WCh); - _CRTIMP int __cdecl _cputws(const wchar_t *_String); - _CRTIMP int __cdecl _cwprintf(const wchar_t *_Format,...); - _CRTIMP int __cdecl _cwscanf(const wchar_t *_Format,...); - _CRTIMP int __cdecl _cwscanf_l(const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _vcwprintf(const wchar_t *_Format,va_list _ArgList); - _CRTIMP int __cdecl _cwprintf_p(const wchar_t *_Format,...); - _CRTIMP int __cdecl _vcwprintf_p(const wchar_t *_Format,va_list _ArgList); - _CRTIMP int __cdecl _cwprintf_l(const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _vcwprintf_l(const wchar_t *_Format,_locale_t _Locale,va_list _ArgList); - _CRTIMP int __cdecl _cwprintf_p_l(const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _vcwprintf_p_l(const wchar_t *_Format,_locale_t _Locale,va_list _ArgList); - _CRTIMP wint_t __cdecl _putwch_nolock(wchar_t _WCh); - _CRTIMP wint_t __cdecl _getwch_nolock(void); - _CRTIMP wint_t __cdecl _getwche_nolock(void); - _CRTIMP wint_t __cdecl _ungetwch_nolock(wint_t _WCh); -#endif - -#ifndef NO_OLDNAMES - char *__cdecl cgets(char *_Buffer); - int __cdecl cprintf(const char *_Format,...); - int __cdecl cputs(const char *_Str); - int __cdecl cscanf(const char *_Format,...); - int __cdecl getch(void); - int __cdecl getche(void); - int __cdecl kbhit(void); - int __cdecl putch(int _Ch); - int __cdecl ungetch(int _Ch); - -#if (defined(_X86_) && !defined(__x86_64)) - int __cdecl inp(unsigned short); - unsigned short __cdecl inpw(unsigned short); - int __cdecl outp(unsigned short,int); - unsigned short __cdecl outpw(unsigned short,unsigned short); -#endif - - /* I/O intrin functions. */ - __CRT_INLINE unsigned char __inbyte(unsigned short Port) - { - unsigned char value; - __asm__ __volatile__ ("inb %w1,%b0" - : "=a" (value) - : "Nd" (Port)); - return value; - } - __CRT_INLINE unsigned short __inword(unsigned short Port) - { - unsigned short value; - __asm__ __volatile__ ("inw %w1,%w0" - : "=a" (value) - : "Nd" (Port)); - return value; - } - __CRT_INLINE unsigned long __indword(unsigned short Port) - { - unsigned long value; - __asm__ __volatile__ ("inl %w1,%0" - : "=a" (value) - : "Nd" (Port)); - return value; - } - __CRT_INLINE void __outbyte(unsigned short Port,unsigned char Data) - { - __asm__ __volatile__ ("outb %b0,%w1" - : - : "a" (Data), "Nd" (Port)); - } - __CRT_INLINE void __outword(unsigned short Port,unsigned short Data) - { - __asm__ __volatile__ ("outw %w0,%w1" - : - : "a" (Data), "Nd" (Port)); - } - __CRT_INLINE void __outdword(unsigned short Port,unsigned long Data) - { - __asm__ __volatile__ ("outl %0,%w1" - : - : "a" (Data), "Nd" (Port)); - } - __CRT_INLINE void __inbytestring(unsigned short Port,unsigned char *Buffer,unsigned long Count) - { - __asm__ __volatile__ ( - "cld ; rep ; insb " - : "=D" (Buffer), "=c" (Count) - : "d"(Port), "0"(Buffer), "1" (Count) - ); - } - __CRT_INLINE void __inwordstring(unsigned short Port,unsigned short *Buffer,unsigned long Count) - { - __asm__ __volatile__ ( - "cld ; rep ; insw " - : "=D" (Buffer), "=c" (Count) - : "d"(Port), "0"(Buffer), "1" (Count) - ); - } - __CRT_INLINE void __indwordstring(unsigned short Port,unsigned long *Buffer,unsigned long Count) - { - __asm__ __volatile__ ( - "cld ; rep ; insl " - : "=D" (Buffer), "=c" (Count) - : "d"(Port), "0"(Buffer), "1" (Count) - ); - } - - __CRT_INLINE void __outbytestring(unsigned short Port,unsigned char *Buffer,unsigned long Count) - { - __asm__ __volatile__ ( - "cld ; rep ; outsb " - : "=S" (Buffer), "=c" (Count) - : "d"(Port), "0"(Buffer), "1" (Count) - ); - } - __CRT_INLINE void __outwordstring(unsigned short Port,unsigned short *Buffer,unsigned long Count) - { - __asm__ __volatile__ ( - "cld ; rep ; outsw " - : "=S" (Buffer), "=c" (Count) - : "d"(Port), "0"(Buffer), "1" (Count) - ); - } - __CRT_INLINE void __outdwordstring(unsigned short Port,unsigned long *Buffer,unsigned long Count) - { - __asm__ __volatile__ ( - "cld ; rep ; outsl " - : "=S" (Buffer), "=c" (Count) - : "d"(Port), "0"(Buffer), "1" (Count) - ); - } - - __CRT_INLINE unsigned __int64 __readcr0(void) - { - unsigned __int64 value; - __asm__ __volatile__ ( - "mov %%cr0, %[value]" - : [value] "=q" (value)); - return value; - } - - /* Register sizes are different between 32/64 bit mode. So we have to do this for _WIN64 and _WIN32 - separately. */ - -#ifdef _WIN64 - __CRT_INLINE void __writecr0(unsigned __int64 Data) - { - __asm__ __volatile__ ( - "mov %[Data], %%cr0" - : - : [Data] "q" (Data) - : "memory"); - } - - __CRT_INLINE unsigned __int64 __readcr2(void) - { - unsigned __int64 value; - __asm__ __volatile__ ( - "mov %%cr2, %[value]" - : [value] "=q" (value)); - return value; - } - - __CRT_INLINE void __writecr2(unsigned __int64 Data) - { - __asm__ __volatile__ ( - "mov %[Data], %%cr2" - : - : [Data] "q" (Data) - : "memory"); - } - - __CRT_INLINE unsigned __int64 __readcr3(void) - { - unsigned __int64 value; - __asm__ __volatile__ ( - "mov %%cr3, %[value]" - : [value] "=q" (value)); - return value; - } - - __CRT_INLINE void __writecr3(unsigned __int64 Data) - { - __asm__ __volatile__ ( - "mov %[Data], %%cr3" - : - : [Data] "q" (Data) - : "memory"); - } - - __CRT_INLINE unsigned __int64 __readcr4(void) - { - unsigned __int64 value; - __asm__ __volatile__ ( - "mov %%cr4, %[value]" - : [value] "=q" (value)); - return value; - } - - __CRT_INLINE void __writecr4(unsigned __int64 Data) - { - __asm__ __volatile__ ( - "mov %[Data], %%cr4" - : - : [Data] "q" (Data) - : "memory"); - } - - __CRT_INLINE unsigned __int64 __readcr8(void) - { - unsigned __int64 value; - __asm__ __volatile__ ( - "mov %%cr8, %[value]" - : [value] "=q" (value)); - return value; - } - - __CRT_INLINE void __writecr8(unsigned __int64 Data) - { - __asm__ __volatile__ ( - "mov %[Data], %%cr8" - : - : [Data] "q" (Data) - : "memory"); - } - -#elif defined(_WIN32) - - __CRT_INLINE void __writecr0(unsigned Data) - { - __asm__ __volatile__ ( - "mov %[Data], %%cr0" - : - : [Data] "q" (Data) - : "memory"); - } - - __CRT_INLINE unsigned long __readcr2(void) - { - unsigned long value; - __asm__ __volatile__ ( - "mov %%cr2, %[value]" - : [value] "=q" (value)); - return value; - } - - __CRT_INLINE void __writecr2(unsigned Data) - { - __asm__ __volatile__ ( - "mov %[Data], %%cr2" - : - : [Data] "q" (Data) - : "memory"); - } - - __CRT_INLINE unsigned long __readcr3(void) - { - unsigned long value; - __asm__ __volatile__ ( - "mov %%cr3, %[value]" - : [value] "=q" (value)); - return value; - } - - __CRT_INLINE void __writecr3(unsigned Data) - { - __asm__ __volatile__ ( - "mov %[Data], %%cr3" - : - : [Data] "q" (Data) - : "memory"); - } - - __CRT_INLINE unsigned long __readcr4(void) - { - unsigned long value; - __asm__ __volatile__ ( - "mov %%cr4, %[value]" - : [value] "=q" (value)); - return value; - } - - __CRT_INLINE void __writecr4(unsigned Data) - { - __asm__ __volatile__ ( - "mov %[Data], %%cr4" - : - : [Data] "q" (Data) - : "memory"); - } - - __CRT_INLINE unsigned long __readcr8(void) - { - unsigned long value; __asm__ __volatile__ ( - "mov %%cr8, %[value]" - : [value] "=q" (value)); - return value; - } - - __CRT_INLINE void __writecr8(unsigned Data) - { - __asm__ __volatile__ ( - "mov %[Data], %%cr8" - : - : [Data] "q" (Data) - : "memory"); - } - -#endif - - __CRT_INLINE unsigned __int64 __readmsr(unsigned long msr) - { - unsigned __int64 val1, val2; - __asm__ __volatile__( - "rdmsr" - : "=a" (val1), "=d" (val2) - : "c" (msr)); - return val1 | (val2 << 32); - } - - __CRT_INLINE void __writemsr (unsigned long msr, unsigned __int64 Value) - { - unsigned long val1 = Value, val2 = Value >> 32; - __asm__ __volatile__ ( - "wrmsr" - : - : "c" (msr), "a" (val1), "d" (val2)); - } - - __CRT_INLINE unsigned __int64 __rdtsc(void) - { - unsigned __int64 val1, val2; - __asm__ __volatile__ ( - "rdtsc" - : "=a" (val1), "=d" (val2)); - return val1 | (val2 << 32); - } - - __CRT_INLINE void __cpuid(int CPUInfo[4], int InfoType) - { - __asm__ __volatile__ ( - "cpuid" - : "=a" (CPUInfo [0]), "=b" (CPUInfo [1]), "=c" (CPUInfo [2]), "=d" (CPUInfo [3]) - : "a" (InfoType)); - } - -#endif - -#ifdef __cplusplus -} -#endif - -#include - -#endif diff --git a/05/tcc-final-old/win32/include/ctype.h b/05/tcc-final-old/win32/include/ctype.h deleted file mode 100644 index 7e90100..0000000 --- a/05/tcc-final-old/win32/include/ctype.h +++ /dev/null @@ -1,281 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _INC_CTYPE -#define _INC_CTYPE - -#include <_mingw.h> - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef WEOF -#define WEOF (wint_t)(0xFFFF) -#endif - -#ifndef _CRT_CTYPEDATA_DEFINED -#define _CRT_CTYPEDATA_DEFINED -#ifndef _CTYPE_DISABLE_MACROS - -#ifndef __PCTYPE_FUNC -#define __PCTYPE_FUNC __pctype_func() -#ifdef _MSVCRT_ -#define __pctype_func() (_pctype) -#else -#define __pctype_func() (*_imp___pctype) -#endif -#endif - -#ifndef _pctype -#ifdef _MSVCRT_ - extern unsigned short *_pctype; -#else - extern unsigned short **_imp___pctype; -#define _pctype (*_imp___pctype) -#endif -#endif - -#endif -#endif - -#ifndef _CRT_WCTYPEDATA_DEFINED -#define _CRT_WCTYPEDATA_DEFINED -#ifndef _CTYPE_DISABLE_MACROS -#ifndef _wctype -#ifdef _MSVCRT_ - extern unsigned short *_wctype; -#else - extern unsigned short **_imp___wctype; -#define _wctype (*_imp___wctype) -#endif -#endif -#ifdef _MSVCRT_ -#define __pwctype_func() (_pwctype) -#ifndef _pwctype - extern unsigned short *_pwctype; -#endif -#else -#define __pwctype_func() (*_imp___pwctype) -#ifndef _pwctype - extern unsigned short **_imp___pwctype; -#define _pwctype (*_imp___pwctype) -#endif -#endif -#endif -#endif - - /* CRT stuff */ -#if 1 - extern const unsigned char __newclmap[]; - extern const unsigned char __newcumap[]; - extern pthreadlocinfo __ptlocinfo; - extern pthreadmbcinfo __ptmbcinfo; - extern int __globallocalestatus; - extern int __locale_changed; - extern struct threadlocaleinfostruct __initiallocinfo; - extern _locale_tstruct __initiallocalestructinfo; - pthreadlocinfo __cdecl __updatetlocinfo(void); - pthreadmbcinfo __cdecl __updatetmbcinfo(void); -#endif - -#define _UPPER 0x1 -#define _LOWER 0x2 -#define _DIGIT 0x4 -#define _SPACE 0x8 - -#define _PUNCT 0x10 -#define _CONTROL 0x20 -#define _BLANK 0x40 -#define _HEX 0x80 - -#define _LEADBYTE 0x8000 -#define _ALPHA (0x0100|_UPPER|_LOWER) - -#ifndef _CTYPE_DEFINED -#define _CTYPE_DEFINED - - _CRTIMP int __cdecl _isctype(int _C,int _Type); - _CRTIMP int __cdecl _isctype_l(int _C,int _Type,_locale_t _Locale); - _CRTIMP int __cdecl isalpha(int _C); - _CRTIMP int __cdecl _isalpha_l(int _C,_locale_t _Locale); - _CRTIMP int __cdecl isupper(int _C); - _CRTIMP int __cdecl _isupper_l(int _C,_locale_t _Locale); - _CRTIMP int __cdecl islower(int _C); - _CRTIMP int __cdecl _islower_l(int _C,_locale_t _Locale); - _CRTIMP int __cdecl isdigit(int _C); - _CRTIMP int __cdecl _isdigit_l(int _C,_locale_t _Locale); - _CRTIMP int __cdecl isxdigit(int _C); - _CRTIMP int __cdecl _isxdigit_l(int _C,_locale_t _Locale); - _CRTIMP int __cdecl isspace(int _C); - _CRTIMP int __cdecl _isspace_l(int _C,_locale_t _Locale); - _CRTIMP int __cdecl ispunct(int _C); - _CRTIMP int __cdecl _ispunct_l(int _C,_locale_t _Locale); - _CRTIMP int __cdecl isalnum(int _C); - _CRTIMP int __cdecl _isalnum_l(int _C,_locale_t _Locale); - _CRTIMP int __cdecl isprint(int _C); - _CRTIMP int __cdecl _isprint_l(int _C,_locale_t _Locale); - _CRTIMP int __cdecl isgraph(int _C); - _CRTIMP int __cdecl _isgraph_l(int _C,_locale_t _Locale); - _CRTIMP int __cdecl iscntrl(int _C); - _CRTIMP int __cdecl _iscntrl_l(int _C,_locale_t _Locale); - _CRTIMP int __cdecl toupper(int _C); - _CRTIMP int __cdecl tolower(int _C); - _CRTIMP int __cdecl _tolower(int _C); - _CRTIMP int __cdecl _tolower_l(int _C,_locale_t _Locale); - _CRTIMP int __cdecl _toupper(int _C); - _CRTIMP int __cdecl _toupper_l(int _C,_locale_t _Locale); - _CRTIMP int __cdecl __isascii(int _C); - _CRTIMP int __cdecl __toascii(int _C); - _CRTIMP int __cdecl __iscsymf(int _C); - _CRTIMP int __cdecl __iscsym(int _C); - -#if (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || !defined (NO_OLDNAMES) -int __cdecl isblank(int _C); -#endif -#endif - -#ifndef _WCTYPE_DEFINED -#define _WCTYPE_DEFINED - - int __cdecl iswalpha(wint_t _C); - _CRTIMP int __cdecl _iswalpha_l(wint_t _C,_locale_t _Locale); - int __cdecl iswupper(wint_t _C); - _CRTIMP int __cdecl _iswupper_l(wint_t _C,_locale_t _Locale); - int __cdecl iswlower(wint_t _C); - _CRTIMP int __cdecl _iswlower_l(wint_t _C,_locale_t _Locale); - int __cdecl iswdigit(wint_t _C); - _CRTIMP int __cdecl _iswdigit_l(wint_t _C,_locale_t _Locale); - int __cdecl iswxdigit(wint_t _C); - _CRTIMP int __cdecl _iswxdigit_l(wint_t _C,_locale_t _Locale); - int __cdecl iswspace(wint_t _C); - _CRTIMP int __cdecl _iswspace_l(wint_t _C,_locale_t _Locale); - int __cdecl iswpunct(wint_t _C); - _CRTIMP int __cdecl _iswpunct_l(wint_t _C,_locale_t _Locale); - int __cdecl iswalnum(wint_t _C); - _CRTIMP int __cdecl _iswalnum_l(wint_t _C,_locale_t _Locale); - int __cdecl iswprint(wint_t _C); - _CRTIMP int __cdecl _iswprint_l(wint_t _C,_locale_t _Locale); - int __cdecl iswgraph(wint_t _C); - _CRTIMP int __cdecl _iswgraph_l(wint_t _C,_locale_t _Locale); - int __cdecl iswcntrl(wint_t _C); - _CRTIMP int __cdecl _iswcntrl_l(wint_t _C,_locale_t _Locale); - int __cdecl iswascii(wint_t _C); - int __cdecl isleadbyte(int _C); - _CRTIMP int __cdecl _isleadbyte_l(int _C,_locale_t _Locale); - wint_t __cdecl towupper(wint_t _C); - _CRTIMP wint_t __cdecl _towupper_l(wint_t _C,_locale_t _Locale); - wint_t __cdecl towlower(wint_t _C); - _CRTIMP wint_t __cdecl _towlower_l(wint_t _C,_locale_t _Locale); - int __cdecl iswctype(wint_t _C,wctype_t _Type); - _CRTIMP int __cdecl _iswctype_l(wint_t _C,wctype_t _Type,_locale_t _Locale); - _CRTIMP int __cdecl __iswcsymf(wint_t _C); - _CRTIMP int __cdecl _iswcsymf_l(wint_t _C,_locale_t _Locale); - _CRTIMP int __cdecl __iswcsym(wint_t _C); - _CRTIMP int __cdecl _iswcsym_l(wint_t _C,_locale_t _Locale); - int __cdecl is_wctype(wint_t _C,wctype_t _Type); - -#if (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || !defined (NO_OLDNAMES) -int __cdecl iswblank(wint_t _C); -#endif -#endif - -#ifndef _CTYPE_DISABLE_MACROS - -#ifndef MB_CUR_MAX -#define MB_CUR_MAX ___mb_cur_max_func() -#ifndef __mb_cur_max -#ifdef _MSVCRT_ - extern int __mb_cur_max; -#else -#define __mb_cur_max (*_imp____mb_cur_max) - extern int *_imp____mb_cur_max; -#endif -#endif -#ifdef _MSVCRT_ -#define ___mb_cur_max_func() (__mb_cur_max) -#else -#define ___mb_cur_max_func() (*_imp____mb_cur_max) -#endif -#endif - -#define __chvalidchk(a,b) (__PCTYPE_FUNC[(a)] & (b)) -#define _chvalidchk_l(_Char,_Flag,_Locale) (!_Locale ? __chvalidchk(_Char,_Flag) : ((_locale_t)_Locale)->locinfo->pctype[_Char] & (_Flag)) -#define _ischartype_l(_Char,_Flag,_Locale) (((_Locale)!=NULL && (((_locale_t)(_Locale))->locinfo->mb_cur_max) > 1) ? _isctype_l(_Char,(_Flag),_Locale) : _chvalidchk_l(_Char,_Flag,_Locale)) -#define _isalpha_l(_Char,_Locale) _ischartype_l(_Char,_ALPHA,_Locale) -#define _isupper_l(_Char,_Locale) _ischartype_l(_Char,_UPPER,_Locale) -#define _islower_l(_Char,_Locale) _ischartype_l(_Char,_LOWER,_Locale) -#define _isdigit_l(_Char,_Locale) _ischartype_l(_Char,_DIGIT,_Locale) -#define _isxdigit_l(_Char,_Locale) _ischartype_l(_Char,_HEX,_Locale) -#define _isspace_l(_Char,_Locale) _ischartype_l(_Char,_SPACE,_Locale) -#define _ispunct_l(_Char,_Locale) _ischartype_l(_Char,_PUNCT,_Locale) -#define _isalnum_l(_Char,_Locale) _ischartype_l(_Char,_ALPHA|_DIGIT,_Locale) -#define _isprint_l(_Char,_Locale) _ischartype_l(_Char,_BLANK|_PUNCT|_ALPHA|_DIGIT,_Locale) -#define _isgraph_l(_Char,_Locale) _ischartype_l(_Char,_PUNCT|_ALPHA|_DIGIT,_Locale) -#define _iscntrl_l(_Char,_Locale) _ischartype_l(_Char,_CONTROL,_Locale) -#define _tolower(_Char) ((_Char)-'A'+'a') -#define _toupper(_Char) ((_Char)-'a'+'A') -#define __isascii(_Char) ((unsigned)(_Char) < 0x80) -#define __toascii(_Char) ((_Char) & 0x7f) - -#ifndef _WCTYPE_INLINE_DEFINED -#define _WCTYPE_INLINE_DEFINED - -#undef _CRT_WCTYPE_NOINLINE -#ifndef __cplusplus -#define iswalpha(_c) (iswctype(_c,_ALPHA)) -#define iswupper(_c) (iswctype(_c,_UPPER)) -#define iswlower(_c) (iswctype(_c,_LOWER)) -#define iswdigit(_c) (iswctype(_c,_DIGIT)) -#define iswxdigit(_c) (iswctype(_c,_HEX)) -#define iswspace(_c) (iswctype(_c,_SPACE)) -#define iswpunct(_c) (iswctype(_c,_PUNCT)) -#define iswalnum(_c) (iswctype(_c,_ALPHA|_DIGIT)) -#define iswprint(_c) (iswctype(_c,_BLANK|_PUNCT|_ALPHA|_DIGIT)) -#define iswgraph(_c) (iswctype(_c,_PUNCT|_ALPHA|_DIGIT)) -#define iswcntrl(_c) (iswctype(_c,_CONTROL)) -#define iswascii(_c) ((unsigned)(_c) < 0x80) -#define _iswalpha_l(_c,_p) (_iswctype_l(_c,_ALPHA,_p)) -#define _iswupper_l(_c,_p) (_iswctype_l(_c,_UPPER,_p)) -#define _iswlower_l(_c,_p) (_iswctype_l(_c,_LOWER,_p)) -#define _iswdigit_l(_c,_p) (_iswctype_l(_c,_DIGIT,_p)) -#define _iswxdigit_l(_c,_p) (_iswctype_l(_c,_HEX,_p)) -#define _iswspace_l(_c,_p) (_iswctype_l(_c,_SPACE,_p)) -#define _iswpunct_l(_c,_p) (_iswctype_l(_c,_PUNCT,_p)) -#define _iswalnum_l(_c,_p) (_iswctype_l(_c,_ALPHA|_DIGIT,_p)) -#define _iswprint_l(_c,_p) (_iswctype_l(_c,_BLANK|_PUNCT|_ALPHA|_DIGIT,_p)) -#define _iswgraph_l(_c,_p) (_iswctype_l(_c,_PUNCT|_ALPHA|_DIGIT,_p)) -#define _iswcntrl_l(_c,_p) (_iswctype_l(_c,_CONTROL,_p)) -#endif -#endif - -#define __iscsymf(_c) (isalpha(_c) || ((_c)=='_')) -#define __iscsym(_c) (isalnum(_c) || ((_c)=='_')) -#define __iswcsymf(_c) (iswalpha(_c) || ((_c)=='_')) -#define __iswcsym(_c) (iswalnum(_c) || ((_c)=='_')) -#define _iscsymf_l(_c,_p) (_isalpha_l(_c,_p) || ((_c)=='_')) -#define _iscsym_l(_c,_p) (_isalnum_l(_c,_p) || ((_c)=='_')) -#define _iswcsymf_l(_c,_p) (_iswalpha_l(_c,_p) || ((_c)=='_')) -#define _iswcsym_l(_c,_p) (_iswalnum_l(_c,_p) || ((_c)=='_')) -#endif - -#ifndef NO_OLDNAMES -#ifndef _CTYPE_DEFINED - int __cdecl isascii(int _C); - int __cdecl toascii(int _C); - int __cdecl iscsymf(int _C); - int __cdecl iscsym(int _C); -#else -#define isascii __isascii -#define toascii __toascii -#define iscsymf __iscsymf -#define iscsym __iscsym -#endif -#endif - -#ifdef __cplusplus -} -#endif -#endif diff --git a/05/tcc-final-old/win32/include/dir.h b/05/tcc-final-old/win32/include/dir.h deleted file mode 100644 index f38f750..0000000 --- a/05/tcc-final-old/win32/include/dir.h +++ /dev/null @@ -1,31 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -/* - * dir.h - * - * This file OBSOLESCENT and only provided for backward compatibility. - * Please use io.h instead. - * - * This file is part of the Mingw32 package. - * - * Contributors: - * Created by Colin Peters - * Mumit Khan - * - * THIS SOFTWARE IS NOT COPYRIGHTED - * - * This source code is offered for use in the public domain. You may - * use, modify or distribute it freely. - * - * This code is distributed in the hope that it will be useful but - * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY - * DISCLAIMED. This includes but is not limited to warranties of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - */ - -#include - diff --git a/05/tcc-final-old/win32/include/direct.h b/05/tcc-final-old/win32/include/direct.h deleted file mode 100644 index 99ce69d..0000000 --- a/05/tcc-final-old/win32/include/direct.h +++ /dev/null @@ -1,68 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _INC_DIRECT -#define _INC_DIRECT - -#include <_mingw.h> -#include - -#pragma pack(push,_CRT_PACKING) - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _DISKFREE_T_DEFINED -#define _DISKFREE_T_DEFINED - struct _diskfree_t { - unsigned total_clusters; - unsigned avail_clusters; - unsigned sectors_per_cluster; - unsigned bytes_per_sector; - }; -#endif - - _CRTIMP char *__cdecl _getcwd(char *_DstBuf,int _SizeInBytes); - _CRTIMP char *__cdecl _getdcwd(int _Drive,char *_DstBuf,int _SizeInBytes); - char *__cdecl _getdcwd_nolock(int _Drive,char *_DstBuf,int _SizeInBytes); - _CRTIMP int __cdecl _chdir(const char *_Path); - _CRTIMP int __cdecl _mkdir(const char *_Path); - _CRTIMP int __cdecl _rmdir(const char *_Path); - _CRTIMP int __cdecl _chdrive(int _Drive); - _CRTIMP int __cdecl _getdrive(void); - _CRTIMP unsigned long __cdecl _getdrives(void); - -#ifndef _GETDISKFREE_DEFINED -#define _GETDISKFREE_DEFINED - _CRTIMP unsigned __cdecl _getdiskfree(unsigned _Drive,struct _diskfree_t *_DiskFree); -#endif - -#ifndef _WDIRECT_DEFINED -#define _WDIRECT_DEFINED - _CRTIMP wchar_t *__cdecl _wgetcwd(wchar_t *_DstBuf,int _SizeInWords); - _CRTIMP wchar_t *__cdecl _wgetdcwd(int _Drive,wchar_t *_DstBuf,int _SizeInWords); - wchar_t *__cdecl _wgetdcwd_nolock(int _Drive,wchar_t *_DstBuf,int _SizeInWords); - _CRTIMP int __cdecl _wchdir(const wchar_t *_Path); - _CRTIMP int __cdecl _wmkdir(const wchar_t *_Path); - _CRTIMP int __cdecl _wrmdir(const wchar_t *_Path); -#endif - -#ifndef NO_OLDNAMES - -#define diskfree_t _diskfree_t - - char *__cdecl getcwd(char *_DstBuf,int _SizeInBytes); - int __cdecl chdir(const char *_Path); - int __cdecl mkdir(const char *_Path); - int __cdecl rmdir(const char *_Path); -#endif - -#ifdef __cplusplus -} -#endif - -#pragma pack(pop) -#endif diff --git a/05/tcc-final-old/win32/include/dirent.h b/05/tcc-final-old/win32/include/dirent.h deleted file mode 100644 index cd31f59..0000000 --- a/05/tcc-final-old/win32/include/dirent.h +++ /dev/null @@ -1,135 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -/* All the headers include this file. */ -#include <_mingw.h> - -#ifndef __STRICT_ANSI__ - -#ifndef _DIRENT_H_ -#define _DIRENT_H_ - - -#pragma pack(push,_CRT_PACKING) - -#include - -#ifndef RC_INVOKED - -#ifdef __cplusplus -extern "C" { -#endif - - struct dirent - { - long d_ino; /* Always zero. */ - unsigned short d_reclen; /* Always zero. */ - unsigned short d_namlen; /* Length of name in d_name. */ - char* d_name; /* File name. */ - /* NOTE: The name in the dirent structure points to the name in the - * finddata_t structure in the DIR. */ - }; - - /* - * This is an internal data structure. Good programmers will not use it - * except as an argument to one of the functions below. - * dd_stat field is now int (was short in older versions). - */ - typedef struct - { - /* disk transfer area for this dir */ - struct _finddata_t dd_dta; - - /* dirent struct to return from dir (NOTE: this makes this thread - * safe as long as only one thread uses a particular DIR struct at - * a time) */ - struct dirent dd_dir; - - /* _findnext handle */ - long dd_handle; - - /* - * Status of search: - * 0 = not started yet (next entry to read is first entry) - * -1 = off the end - * positive = 0 based index of next entry - */ - int dd_stat; - - /* given path for dir with search pattern (struct is extended) */ - char dd_name[1]; - } DIR; - - DIR* __cdecl opendir (const char*); - struct dirent* __cdecl readdir (DIR*); - int __cdecl closedir (DIR*); - void __cdecl rewinddir (DIR*); - long __cdecl telldir (DIR*); - void __cdecl seekdir (DIR*, long); - - - /* wide char versions */ - - struct _wdirent - { - long d_ino; /* Always zero. */ - unsigned short d_reclen; /* Always zero. */ - unsigned short d_namlen; /* Length of name in d_name. */ - wchar_t* d_name; /* File name. */ - /* NOTE: The name in the dirent structure points to the name in the * wfinddata_t structure in the _WDIR. */ - }; - - /* - * This is an internal data structure. Good programmers will not use it - * except as an argument to one of the functions below. - */ - typedef struct - { - /* disk transfer area for this dir */ - struct _wfinddata_t dd_dta; - - /* dirent struct to return from dir (NOTE: this makes this thread - * safe as long as only one thread uses a particular DIR struct at - * a time) */ - struct _wdirent dd_dir; - - /* _findnext handle */ - long dd_handle; - - /* - * Status of search: - * 0 = not started yet (next entry to read is first entry) - * -1 = off the end - * positive = 0 based index of next entry - */ - int dd_stat; - - /* given path for dir with search pattern (struct is extended) */ - wchar_t dd_name[1]; - } _WDIR; - - - - _WDIR* __cdecl _wopendir (const wchar_t*); - struct _wdirent* __cdecl _wreaddir (_WDIR*); - int __cdecl _wclosedir (_WDIR*); - void __cdecl _wrewinddir (_WDIR*); - long __cdecl _wtelldir (_WDIR*); - void __cdecl _wseekdir (_WDIR*, long); - - -#ifdef __cplusplus -} -#endif - -#endif /* Not RC_INVOKED */ - -#pragma pack(pop) - -#endif /* Not _DIRENT_H_ */ - - -#endif /* Not __STRICT_ANSI__ */ - diff --git a/05/tcc-final-old/win32/include/dos.h b/05/tcc-final-old/win32/include/dos.h deleted file mode 100644 index 294e8fe..0000000 --- a/05/tcc-final-old/win32/include/dos.h +++ /dev/null @@ -1,55 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _INC_DOS -#define _INC_DOS - -#include <_mingw.h> -#include - -#pragma pack(push,_CRT_PACKING) - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _DISKFREE_T_DEFINED -#define _DISKFREE_T_DEFINED - - struct _diskfree_t { - unsigned total_clusters; - unsigned avail_clusters; - unsigned sectors_per_cluster; - unsigned bytes_per_sector; - }; -#endif - -#define _A_NORMAL 0x00 -#define _A_RDONLY 0x01 -#define _A_HIDDEN 0x02 -#define _A_SYSTEM 0x04 -#define _A_SUBDIR 0x10 -#define _A_ARCH 0x20 - -#ifndef _GETDISKFREE_DEFINED -#define _GETDISKFREE_DEFINED - _CRTIMP unsigned __cdecl _getdiskfree(unsigned _Drive,struct _diskfree_t *_DiskFree); -#endif - -#if (defined(_X86_) && !defined(__x86_64)) - void __cdecl _disable(void); - void __cdecl _enable(void); -#endif - -#ifndef NO_OLDNAMES -#define diskfree_t _diskfree_t -#endif - -#ifdef __cplusplus -} -#endif - -#pragma pack(pop) -#endif diff --git a/05/tcc-final-old/win32/include/errno.h b/05/tcc-final-old/win32/include/errno.h deleted file mode 100644 index c2df015..0000000 --- a/05/tcc-final-old/win32/include/errno.h +++ /dev/null @@ -1,75 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _INC_ERRNO -#define _INC_ERRNO - -#include <_mingw.h> - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _CRT_ERRNO_DEFINED -#define _CRT_ERRNO_DEFINED - _CRTIMP extern int *__cdecl _errno(void); -#define errno (*_errno()) - - errno_t __cdecl _set_errno(int _Value); - errno_t __cdecl _get_errno(int *_Value); -#endif - -#define EPERM 1 -#define ENOENT 2 -#define ESRCH 3 -#define EINTR 4 -#define EIO 5 -#define ENXIO 6 -#define E2BIG 7 -#define ENOEXEC 8 -#define EBADF 9 -#define ECHILD 10 -#define EAGAIN 11 -#define ENOMEM 12 -#define EACCES 13 -#define EFAULT 14 -#define EBUSY 16 -#define EEXIST 17 -#define EXDEV 18 -#define ENODEV 19 -#define ENOTDIR 20 -#define EISDIR 21 -#define ENFILE 23 -#define EMFILE 24 -#define ENOTTY 25 -#define EFBIG 27 -#define ENOSPC 28 -#define ESPIPE 29 -#define EROFS 30 -#define EMLINK 31 -#define EPIPE 32 -#define EDOM 33 -#define EDEADLK 36 -#define ENAMETOOLONG 38 -#define ENOLCK 39 -#define ENOSYS 40 -#define ENOTEMPTY 41 - -#ifndef RC_INVOKED -#if !defined(_SECURECRT_ERRCODE_VALUES_DEFINED) -#define _SECURECRT_ERRCODE_VALUES_DEFINED -#define EINVAL 22 -#define ERANGE 34 -#define EILSEQ 42 -#define STRUNCATE 80 -#endif -#endif - -#define EDEADLOCK EDEADLK - -#ifdef __cplusplus -} -#endif -#endif diff --git a/05/tcc-final-old/win32/include/excpt.h b/05/tcc-final-old/win32/include/excpt.h deleted file mode 100644 index 26cc943..0000000 --- a/05/tcc-final-old/win32/include/excpt.h +++ /dev/null @@ -1,123 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _INC_EXCPT -#define _INC_EXCPT - -#include <_mingw.h> - -#pragma pack(push,_CRT_PACKING) - -#ifdef __cplusplus -extern "C" { -#endif - - struct _EXCEPTION_POINTERS; - -#ifndef EXCEPTION_DISPOSITION -#define EXCEPTION_DISPOSITION int -#endif -#define ExceptionContinueExecution 0 -#define ExceptionContinueSearch 1 -#define ExceptionNestedException 2 -#define ExceptionCollidedUnwind 3 - -#if (defined(_X86_) && !defined(__x86_64)) - struct _EXCEPTION_RECORD; - struct _CONTEXT; - - EXCEPTION_DISPOSITION __cdecl _except_handler(struct _EXCEPTION_RECORD *_ExceptionRecord,void *_EstablisherFrame,struct _CONTEXT *_ContextRecord,void *_DispatcherContext); -#elif defined(__ia64__) - - typedef struct _EXCEPTION_POINTERS *Exception_info_ptr; - struct _EXCEPTION_RECORD; - struct _CONTEXT; - struct _DISPATCHER_CONTEXT; - - _CRTIMP EXCEPTION_DISPOSITION __cdecl __C_specific_handler (struct _EXCEPTION_RECORD *_ExceptionRecord,unsigned __int64 _MemoryStackFp,unsigned __int64 _BackingStoreFp,struct _CONTEXT *_ContextRecord,struct _DISPATCHER_CONTEXT *_DispatcherContext,unsigned __int64 _GlobalPointer); -#elif defined(__x86_64) - - struct _EXCEPTION_RECORD; - struct _CONTEXT; -#endif - -#define GetExceptionCode _exception_code -#define exception_code _exception_code -#define GetExceptionInformation (struct _EXCEPTION_POINTERS *)_exception_info -#define exception_info (struct _EXCEPTION_POINTERS *)_exception_info -#define AbnormalTermination _abnormal_termination -#define abnormal_termination _abnormal_termination - - unsigned long __cdecl _exception_code(void); - void *__cdecl _exception_info(void); - int __cdecl _abnormal_termination(void); - -#define EXCEPTION_EXECUTE_HANDLER 1 -#define EXCEPTION_CONTINUE_SEARCH 0 -#define EXCEPTION_CONTINUE_EXECUTION -1 - - /* CRT stuff */ - typedef void (__cdecl * _PHNDLR)(int); - - struct _XCPT_ACTION { - unsigned long XcptNum; - int SigNum; - _PHNDLR XcptAction; - }; - - extern struct _XCPT_ACTION _XcptActTab[]; - extern int _XcptActTabCount; - extern int _XcptActTabSize; - extern int _First_FPE_Indx; - extern int _Num_FPE; - - int __cdecl __CppXcptFilter(unsigned long _ExceptionNum,struct _EXCEPTION_POINTERS * _ExceptionPtr); - int __cdecl _XcptFilter(unsigned long _ExceptionNum,struct _EXCEPTION_POINTERS * _ExceptionPtr); - - /* - * The type of function that is expected as an exception handler to be - * installed with _try1. - */ - typedef EXCEPTION_DISPOSITION (*PEXCEPTION_HANDLER)(struct _EXCEPTION_RECORD*, void*, struct _CONTEXT*, void*); - -#ifndef HAVE_NO_SEH - /* - * This is not entirely necessary, but it is the structure installed by - * the _try1 primitive below. - */ - typedef struct _EXCEPTION_REGISTRATION { - struct _EXCEPTION_REGISTRATION *prev; - EXCEPTION_DISPOSITION (*handler)(struct _EXCEPTION_RECORD*, void*, struct _CONTEXT*, void*); - } EXCEPTION_REGISTRATION, *PEXCEPTION_REGISTRATION; - - typedef EXCEPTION_REGISTRATION EXCEPTION_REGISTRATION_RECORD; - typedef PEXCEPTION_REGISTRATION PEXCEPTION_REGISTRATION_RECORD; -#endif - -#if (defined(_X86_) && !defined(__x86_64)) -#define __try1(pHandler) \ - __asm__ ("pushl %0;pushl %%fs:0;movl %%esp,%%fs:0;" : : "g" (pHandler)); - -#define __except1 \ - __asm__ ("movl (%%esp),%%eax;movl %%eax,%%fs:0;addl $8,%%esp;" \ - : : : "%eax"); -#elif defined(__x86_64) -#define __try1(pHandler) \ - __asm__ ("pushq %0;pushq %%gs:0;movq %%rsp,%%gs:0;" : : "g" (pHandler)); - -#define __except1 \ - __asm__ ("movq (%%rsp),%%rax;movq %%rax,%%gs:0;addq $16,%%rsp;" \ - : : : "%rax"); -#else -#define __try1(pHandler) -#define __except1 -#endif - -#ifdef __cplusplus -} -#endif - -#pragma pack(pop) -#endif diff --git a/05/tcc-final-old/win32/include/fcntl.h b/05/tcc-final-old/win32/include/fcntl.h deleted file mode 100644 index 9202b08..0000000 --- a/05/tcc-final-old/win32/include/fcntl.h +++ /dev/null @@ -1,52 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#include <_mingw.h> - -#include - -#ifndef _INC_FCNTL -#define _INC_FCNTL - -#define _O_RDONLY 0x0000 -#define _O_WRONLY 0x0001 -#define _O_RDWR 0x0002 -#define _O_APPEND 0x0008 -#define _O_CREAT 0x0100 -#define _O_TRUNC 0x0200 -#define _O_EXCL 0x0400 -#define _O_TEXT 0x4000 -#define _O_BINARY 0x8000 -#define _O_WTEXT 0x10000 -#define _O_U16TEXT 0x20000 -#define _O_U8TEXT 0x40000 -#define _O_ACCMODE (_O_RDONLY|_O_WRONLY|_O_RDWR) - -#define _O_RAW _O_BINARY -#define _O_NOINHERIT 0x0080 -#define _O_TEMPORARY 0x0040 -#define _O_SHORT_LIVED 0x1000 - -#define _O_SEQUENTIAL 0x0020 -#define _O_RANDOM 0x0010 - -#if !defined(NO_OLDNAMES) || defined(_POSIX) -#define O_RDONLY _O_RDONLY -#define O_WRONLY _O_WRONLY -#define O_RDWR _O_RDWR -#define O_APPEND _O_APPEND -#define O_CREAT _O_CREAT -#define O_TRUNC _O_TRUNC -#define O_EXCL _O_EXCL -#define O_TEXT _O_TEXT -#define O_BINARY _O_BINARY -#define O_RAW _O_BINARY -#define O_TEMPORARY _O_TEMPORARY -#define O_NOINHERIT _O_NOINHERIT -#define O_SEQUENTIAL _O_SEQUENTIAL -#define O_RANDOM _O_RANDOM -#define O_ACCMODE _O_ACCMODE -#endif -#endif diff --git a/05/tcc-final-old/win32/include/fenv.h b/05/tcc-final-old/win32/include/fenv.h deleted file mode 100644 index 258f3a5..0000000 --- a/05/tcc-final-old/win32/include/fenv.h +++ /dev/null @@ -1,108 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _FENV_H_ -#define _FENV_H_ - -#include <_mingw.h> - -/* FPU status word exception flags */ -#define FE_INVALID 0x01 -#define FE_DENORMAL 0x02 -#define FE_DIVBYZERO 0x04 -#define FE_OVERFLOW 0x08 -#define FE_UNDERFLOW 0x10 -#define FE_INEXACT 0x20 -#define FE_ALL_EXCEPT (FE_INVALID | FE_DENORMAL | FE_DIVBYZERO \ - | FE_OVERFLOW | FE_UNDERFLOW | FE_INEXACT) - -/* FPU control word rounding flags */ -#define FE_TONEAREST 0x0000 -#define FE_DOWNWARD 0x0400 -#define FE_UPWARD 0x0800 -#define FE_TOWARDZERO 0x0c00 - -/* The MXCSR exception flags are the same as the - FE flags. */ -#define __MXCSR_EXCEPT_FLAG_SHIFT 0 - -/* How much to shift FE status word exception flags - to get MXCSR rounding flags, */ -#define __MXCSR_ROUND_FLAG_SHIFT 3 - -#ifndef RC_INVOKED -/* - For now, support only for the basic abstraction of flags that are - either set or clear. fexcept_t could be structure that holds more - info about the fp environment. -*/ -typedef unsigned short fexcept_t; - -/* This 32-byte struct represents the entire floating point - environment as stored by fnstenv or fstenv, augmented by - the contents of the MXCSR register, as stored by stmxcsr - (if CPU supports it). */ -typedef struct -{ - unsigned short __control_word; - unsigned short __unused0; - unsigned short __status_word; - unsigned short __unused1; - unsigned short __tag_word; - unsigned short __unused2; - unsigned int __ip_offset; /* instruction pointer offset */ - unsigned short __ip_selector; - unsigned short __opcode; - unsigned int __data_offset; - unsigned short __data_selector; - unsigned short __unused3; - unsigned int __mxcsr; /* contents of the MXCSR register */ -} fenv_t; - - -/*The C99 standard (7.6.9) allows us to define implementation-specific macros for - different fp environments */ - -/* The default Intel x87 floating point environment (64-bit mantissa) */ -#define FE_PC64_ENV ((const fenv_t *)-1) - -/* The floating point environment set by MSVCRT _fpreset (53-bit mantissa) */ -#define FE_PC53_ENV ((const fenv_t *)-2) - -/* The FE_DFL_ENV macro is required by standard. - fesetenv will use the environment set at app startup.*/ -#define FE_DFL_ENV ((const fenv_t *) 0) - -#ifdef __cplusplus -extern "C" { -#endif - -/*TODO: Some of these could be inlined */ -/* 7.6.2 Exception */ - -extern int __cdecl feclearexcept (int); -extern int __cdecl fegetexceptflag (fexcept_t * flagp, int excepts); -extern int __cdecl feraiseexcept (int excepts ); -extern int __cdecl fesetexceptflag (const fexcept_t *, int); -extern int __cdecl fetestexcept (int excepts); - -/* 7.6.3 Rounding */ - -extern int __cdecl fegetround (void); -extern int __cdecl fesetround (int mode); - -/* 7.6.4 Environment */ - -extern int __cdecl fegetenv(fenv_t * envp); -extern int __cdecl fesetenv(const fenv_t * ); -extern int __cdecl feupdateenv(const fenv_t *); -extern int __cdecl feholdexcept(fenv_t *); - -#ifdef __cplusplus -} -#endif -#endif /* Not RC_INVOKED */ - -#endif /* ndef _FENV_H */ diff --git a/05/tcc-final-old/win32/include/inttypes.h b/05/tcc-final-old/win32/include/inttypes.h deleted file mode 100644 index 7360091..0000000 --- a/05/tcc-final-old/win32/include/inttypes.h +++ /dev/null @@ -1,297 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -/* 7.8 Format conversion of integer types */ - -#ifndef _INTTYPES_H_ -#define _INTTYPES_H_ - -#include <_mingw.h> -#include -#define __need_wchar_t -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { - intmax_t quot; - intmax_t rem; - } imaxdiv_t; - -#if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS) - -/* 7.8.1 Macros for format specifiers - * - * MS runtime does not yet understand C9x standard "ll" - * length specifier. It appears to treat "ll" as "l". - * The non-standard I64 length specifier causes warning in GCC, - * but understood by MS runtime functions. - */ - -/* fprintf macros for signed types */ -#define PRId8 "d" -#define PRId16 "d" -#define PRId32 "d" -#define PRId64 "I64d" - -#define PRIdLEAST8 "d" -#define PRIdLEAST16 "d" -#define PRIdLEAST32 "d" -#define PRIdLEAST64 "I64d" - -#define PRIdFAST8 "d" -#define PRIdFAST16 "d" -#define PRIdFAST32 "d" -#define PRIdFAST64 "I64d" - -#define PRIdMAX "I64d" - -#define PRIi8 "i" -#define PRIi16 "i" -#define PRIi32 "i" -#define PRIi64 "I64i" - -#define PRIiLEAST8 "i" -#define PRIiLEAST16 "i" -#define PRIiLEAST32 "i" -#define PRIiLEAST64 "I64i" - -#define PRIiFAST8 "i" -#define PRIiFAST16 "i" -#define PRIiFAST32 "i" -#define PRIiFAST64 "I64i" - -#define PRIiMAX "I64i" - -#define PRIo8 "o" -#define PRIo16 "o" -#define PRIo32 "o" -#define PRIo64 "I64o" - -#define PRIoLEAST8 "o" -#define PRIoLEAST16 "o" -#define PRIoLEAST32 "o" -#define PRIoLEAST64 "I64o" - -#define PRIoFAST8 "o" -#define PRIoFAST16 "o" -#define PRIoFAST32 "o" -#define PRIoFAST64 "I64o" - -#define PRIoMAX "I64o" - -/* fprintf macros for unsigned types */ -#define PRIu8 "u" -#define PRIu16 "u" -#define PRIu32 "u" -#define PRIu64 "I64u" - - -#define PRIuLEAST8 "u" -#define PRIuLEAST16 "u" -#define PRIuLEAST32 "u" -#define PRIuLEAST64 "I64u" - -#define PRIuFAST8 "u" -#define PRIuFAST16 "u" -#define PRIuFAST32 "u" -#define PRIuFAST64 "I64u" - -#define PRIuMAX "I64u" - -#define PRIx8 "x" -#define PRIx16 "x" -#define PRIx32 "x" -#define PRIx64 "I64x" - -#define PRIxLEAST8 "x" -#define PRIxLEAST16 "x" -#define PRIxLEAST32 "x" -#define PRIxLEAST64 "I64x" - -#define PRIxFAST8 "x" -#define PRIxFAST16 "x" -#define PRIxFAST32 "x" -#define PRIxFAST64 "I64x" - -#define PRIxMAX "I64x" - -#define PRIX8 "X" -#define PRIX16 "X" -#define PRIX32 "X" -#define PRIX64 "I64X" - -#define PRIXLEAST8 "X" -#define PRIXLEAST16 "X" -#define PRIXLEAST32 "X" -#define PRIXLEAST64 "I64X" - -#define PRIXFAST8 "X" -#define PRIXFAST16 "X" -#define PRIXFAST32 "X" -#define PRIXFAST64 "I64X" - -#define PRIXMAX "I64X" - -/* - * fscanf macros for signed int types - * NOTE: if 32-bit int is used for int_fast8_t and int_fast16_t - * (see stdint.h, 7.18.1.3), FAST8 and FAST16 should have - * no length identifiers - */ - -#define SCNd16 "hd" -#define SCNd32 "d" -#define SCNd64 "I64d" - -#define SCNdLEAST16 "hd" -#define SCNdLEAST32 "d" -#define SCNdLEAST64 "I64d" - -#define SCNdFAST16 "hd" -#define SCNdFAST32 "d" -#define SCNdFAST64 "I64d" - -#define SCNdMAX "I64d" - -#define SCNi16 "hi" -#define SCNi32 "i" -#define SCNi64 "I64i" - -#define SCNiLEAST16 "hi" -#define SCNiLEAST32 "i" -#define SCNiLEAST64 "I64i" - -#define SCNiFAST16 "hi" -#define SCNiFAST32 "i" -#define SCNiFAST64 "I64i" - -#define SCNiMAX "I64i" - -#define SCNo16 "ho" -#define SCNo32 "o" -#define SCNo64 "I64o" - -#define SCNoLEAST16 "ho" -#define SCNoLEAST32 "o" -#define SCNoLEAST64 "I64o" - -#define SCNoFAST16 "ho" -#define SCNoFAST32 "o" -#define SCNoFAST64 "I64o" - -#define SCNoMAX "I64o" - -#define SCNx16 "hx" -#define SCNx32 "x" -#define SCNx64 "I64x" - -#define SCNxLEAST16 "hx" -#define SCNxLEAST32 "x" -#define SCNxLEAST64 "I64x" - -#define SCNxFAST16 "hx" -#define SCNxFAST32 "x" -#define SCNxFAST64 "I64x" - -#define SCNxMAX "I64x" - -/* fscanf macros for unsigned int types */ - -#define SCNu16 "hu" -#define SCNu32 "u" -#define SCNu64 "I64u" - -#define SCNuLEAST16 "hu" -#define SCNuLEAST32 "u" -#define SCNuLEAST64 "I64u" - -#define SCNuFAST16 "hu" -#define SCNuFAST32 "u" -#define SCNuFAST64 "I64u" - -#define SCNuMAX "I64u" - -#ifdef _WIN64 -#define PRIdPTR "I64d" -#define PRIiPTR "I64i" -#define PRIoPTR "I64o" -#define PRIuPTR "I64u" -#define PRIxPTR "I64x" -#define PRIXPTR "I64X" -#define SCNdPTR "I64d" -#define SCNiPTR "I64i" -#define SCNoPTR "I64o" -#define SCNxPTR "I64x" -#define SCNuPTR "I64u" -#else -#define PRIdPTR "d" -#define PRIiPTR "i" -#define PRIoPTR "o" -#define PRIuPTR "u" -#define PRIxPTR "x" -#define PRIXPTR "X" -#define SCNdPTR "d" -#define SCNiPTR "i" -#define SCNoPTR "o" -#define SCNxPTR "x" -#define SCNuPTR "u" -#endif - -#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L -/* - * no length modifier for char types prior to C9x - * MS runtime scanf appears to treat "hh" as "h" - */ - -/* signed char */ -#define SCNd8 "hhd" -#define SCNdLEAST8 "hhd" -#define SCNdFAST8 "hhd" - -#define SCNi8 "hhi" -#define SCNiLEAST8 "hhi" -#define SCNiFAST8 "hhi" - -#define SCNo8 "hho" -#define SCNoLEAST8 "hho" -#define SCNoFAST8 "hho" - -#define SCNx8 "hhx" -#define SCNxLEAST8 "hhx" -#define SCNxFAST8 "hhx" - -/* unsigned char */ -#define SCNu8 "hhu" -#define SCNuLEAST8 "hhu" -#define SCNuFAST8 "hhu" -#endif /* __STDC_VERSION__ >= 199901 */ - -#endif /* !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS) */ - -intmax_t __cdecl imaxabs (intmax_t j); -__CRT_INLINE intmax_t __cdecl imaxabs (intmax_t j) - {return (j >= 0 ? j : -j);} -imaxdiv_t __cdecl imaxdiv (intmax_t numer, intmax_t denom); - -/* 7.8.2 Conversion functions for greatest-width integer types */ - -intmax_t __cdecl strtoimax (const char* __restrict__ nptr, - char** __restrict__ endptr, int base); -uintmax_t __cdecl strtoumax (const char* __restrict__ nptr, - char** __restrict__ endptr, int base); - -intmax_t __cdecl wcstoimax (const wchar_t* __restrict__ nptr, - wchar_t** __restrict__ endptr, int base); -uintmax_t __cdecl wcstoumax (const wchar_t* __restrict__ nptr, - wchar_t** __restrict__ endptr, int base); - -#ifdef __cplusplus -} -#endif - -#endif /* ndef _INTTYPES_H */ diff --git a/05/tcc-final-old/win32/include/io.h b/05/tcc-final-old/win32/include/io.h deleted file mode 100644 index e2aeec3..0000000 --- a/05/tcc-final-old/win32/include/io.h +++ /dev/null @@ -1,418 +0,0 @@ - -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _IO_H_ -#define _IO_H_ - -#include <_mingw.h> -#include - -#pragma pack(push,_CRT_PACKING) - -#ifndef _POSIX_ - -#ifdef __cplusplus -extern "C" { -#endif - -_CRTIMP char* __cdecl _getcwd (char*, int); -#ifndef _FSIZE_T_DEFINED - typedef unsigned long _fsize_t; -#define _FSIZE_T_DEFINED -#endif - -#ifndef _FINDDATA_T_DEFINED - - struct _finddata32_t { - unsigned attrib; - __time32_t time_create; - __time32_t time_access; - __time32_t time_write; - _fsize_t size; - char name[260]; - }; - -/*#if _INTEGRAL_MAX_BITS >= 64*/ - - struct _finddata32i64_t { - unsigned attrib; - __time32_t time_create; - __time32_t time_access; - __time32_t time_write; - __int64 size; - char name[260]; - }; - - struct _finddata64i32_t { - unsigned attrib; - __time64_t time_create; - __time64_t time_access; - __time64_t time_write; - _fsize_t size; - char name[260]; - }; - - struct __finddata64_t { - unsigned attrib; - __time64_t time_create; - __time64_t time_access; - __time64_t time_write; - __int64 size; - char name[260]; - }; -/* #endif */ - -#ifdef _USE_32BIT_TIME_T -#define _finddata_t _finddata32_t -#define _finddatai64_t _finddata32i64_t - -#ifdef _WIN64 -#define _findfirst _findfirst32 -#define _findnext _findnext32 -#else -#define _findfirst32 _findfirst -#define _findnext32 _findnext -#endif -#define _findfirsti64 _findfirst32i64 -#define _findnexti64 _findnext32i64 -#else -#define _finddata_t _finddata64i32_t -#define _finddatai64_t __finddata64_t - -#define _findfirst _findfirst64i32 -#define _findnext _findnext64i32 -#define _findfirsti64 _findfirst64 -#define _findnexti64 _findnext64 -#endif - -#define _FINDDATA_T_DEFINED -#endif - -#ifndef _WFINDDATA_T_DEFINED - - struct _wfinddata32_t { - unsigned attrib; - __time32_t time_create; - __time32_t time_access; - __time32_t time_write; - _fsize_t size; - wchar_t name[260]; - }; - -/* #if _INTEGRAL_MAX_BITS >= 64 */ - - struct _wfinddata32i64_t { - unsigned attrib; - __time32_t time_create; - __time32_t time_access; - __time32_t time_write; - __int64 size; - wchar_t name[260]; - }; - - struct _wfinddata64i32_t { - unsigned attrib; - __time64_t time_create; - __time64_t time_access; - __time64_t time_write; - _fsize_t size; - wchar_t name[260]; - }; - - struct _wfinddata64_t { - unsigned attrib; - __time64_t time_create; - __time64_t time_access; - __time64_t time_write; - __int64 size; - wchar_t name[260]; - }; -/* #endif */ - -#ifdef _USE_32BIT_TIME_T -#define _wfinddata_t _wfinddata32_t -#define _wfinddatai64_t _wfinddata32i64_t - -#define _wfindfirst _wfindfirst32 -#define _wfindnext _wfindnext32 -#define _wfindfirsti64 _wfindfirst32i64 -#define _wfindnexti64 _wfindnext32i64 -#else -#define _wfinddata_t _wfinddata64i32_t -#define _wfinddatai64_t _wfinddata64_t - -#define _wfindfirst _wfindfirst64i32 -#define _wfindnext _wfindnext64i32 -#define _wfindfirsti64 _wfindfirst64 -#define _wfindnexti64 _wfindnext64 -#endif - -#define _WFINDDATA_T_DEFINED -#endif - -#define _A_NORMAL 0x00 -#define _A_RDONLY 0x01 -#define _A_HIDDEN 0x02 -#define _A_SYSTEM 0x04 -#define _A_SUBDIR 0x10 -#define _A_ARCH 0x20 - -#ifndef _SIZE_T_DEFINED -#define _SIZE_T_DEFINED -#undef size_t -#ifdef _WIN64 -#if defined(__GNUC__) && defined(__STRICT_ANSI__) - typedef unsigned int size_t __attribute__ ((mode (DI))); -#else - typedef unsigned __int64 size_t; -#endif -#else - typedef unsigned int size_t; -#endif -#endif - -#ifndef _SSIZE_T_DEFINED -#define _SSIZE_T_DEFINED -#undef ssize_t -#ifdef _WIN64 -#if defined(__GNUC__) && defined(__STRICT_ANSI__) - typedef int ssize_t __attribute__ ((mode (DI))); -#else - typedef __int64 ssize_t; -#endif -#else - typedef int ssize_t; -#endif -#endif - -#ifndef _OFF_T_DEFINED -#define _OFF_T_DEFINED -#ifndef _OFF_T_ -#define _OFF_T_ - typedef long _off_t; -#if !defined(NO_OLDNAMES) || defined(_POSIX) - typedef long off_t; -#endif -#endif -#endif - -#ifndef _OFF64_T_DEFINED -#define _OFF64_T_DEFINED -#if defined(__GNUC__) && defined(__STRICT_ANSI__) - typedef int _off64_t __attribute__ ((mode (DI))); -#if !defined(NO_OLDNAMES) || defined(_POSIX) - typedef int off64_t __attribute__ ((mode (DI))); -#endif -#else - typedef long long _off64_t; -#if !defined(NO_OLDNAMES) || defined(_POSIX) - typedef long long off64_t; -#endif -#endif -#endif - - /* Some defines for _access nAccessMode (MS doesn't define them, but - * it doesn't seem to hurt to add them). */ -#define F_OK 0 /* Check for file existence */ -#define X_OK 1 /* Check for execute permission. */ -#define W_OK 2 /* Check for write permission */ -#define R_OK 4 /* Check for read permission */ - - _CRTIMP int __cdecl _access(const char *_Filename,int _AccessMode); - _CRTIMP int __cdecl _chmod(const char *_Filename,int _Mode); - _CRTIMP int __cdecl _chsize(int _FileHandle,long _Size); - _CRTIMP int __cdecl _close(int _FileHandle); - _CRTIMP int __cdecl _commit(int _FileHandle); - _CRTIMP int __cdecl _creat(const char *_Filename,int _PermissionMode); - _CRTIMP int __cdecl _dup(int _FileHandle); - _CRTIMP int __cdecl _dup2(int _FileHandleSrc,int _FileHandleDst); - _CRTIMP int __cdecl _eof(int _FileHandle); - _CRTIMP long __cdecl _filelength(int _FileHandle); - _CRTIMP intptr_t __cdecl _findfirst32(const char *_Filename,struct _finddata32_t *_FindData); - _CRTIMP int __cdecl _findnext32(intptr_t _FindHandle,struct _finddata32_t *_FindData); - _CRTIMP int __cdecl _findclose(intptr_t _FindHandle); - _CRTIMP int __cdecl _isatty(int _FileHandle); - _CRTIMP int __cdecl _locking(int _FileHandle,int _LockMode,long _NumOfBytes); - _CRTIMP long __cdecl _lseek(int _FileHandle,long _Offset,int _Origin); - _off64_t lseek64(int fd,_off64_t offset, int whence); - _CRTIMP char *__cdecl _mktemp(char *_TemplateName); - _CRTIMP int __cdecl _pipe(int *_PtHandles,unsigned int _PipeSize,int _TextMode); - _CRTIMP int __cdecl _read(int _FileHandle,void *_DstBuf,unsigned int _MaxCharCount); - -#ifndef _CRT_DIRECTORY_DEFINED -#define _CRT_DIRECTORY_DEFINED - int __cdecl remove(const char *_Filename); - int __cdecl rename(const char *_OldFilename,const char *_NewFilename); - _CRTIMP int __cdecl _unlink(const char *_Filename); -#ifndef NO_OLDNAMES - int __cdecl unlink(const char *_Filename); -#endif -#endif - - _CRTIMP int __cdecl _setmode(int _FileHandle,int _Mode); - _CRTIMP long __cdecl _tell(int _FileHandle); - _CRTIMP int __cdecl _umask(int _Mode); - _CRTIMP int __cdecl _write(int _FileHandle,const void *_Buf,unsigned int _MaxCharCount); - -#if _INTEGRAL_MAX_BITS >= 64 - _CRTIMP __int64 __cdecl _filelengthi64(int _FileHandle); - _CRTIMP intptr_t __cdecl _findfirst32i64(const char *_Filename,struct _finddata32i64_t *_FindData); - _CRTIMP intptr_t __cdecl _findfirst64(const char *_Filename,struct __finddata64_t *_FindData); -#ifdef __cplusplus -#include -#endif - intptr_t __cdecl _findfirst64i32(const char *_Filename,struct _finddata64i32_t *_FindData); - __CRT_INLINE intptr_t __cdecl _findfirst64i32(const char *_Filename,struct _finddata64i32_t *_FindData) - { - struct __finddata64_t fd; - intptr_t ret = _findfirst64(_Filename,&fd); - _FindData->attrib=fd.attrib; - _FindData->time_create=fd.time_create; - _FindData->time_access=fd.time_access; - _FindData->time_write=fd.time_write; - _FindData->size=(_fsize_t) fd.size; - strncpy(_FindData->name,fd.name,260); - return ret; - } - _CRTIMP int __cdecl _findnext32i64(intptr_t _FindHandle,struct _finddata32i64_t *_FindData); - _CRTIMP int __cdecl _findnext64(intptr_t _FindHandle,struct __finddata64_t *_FindData); - int __cdecl _findnext64i32(intptr_t _FindHandle,struct _finddata64i32_t *_FindData); - __CRT_INLINE int __cdecl _findnext64i32(intptr_t _FindHandle,struct _finddata64i32_t *_FindData) - { - struct __finddata64_t fd; - int ret = _findnext64(_FindHandle,&fd); - _FindData->attrib=fd.attrib; - _FindData->time_create=fd.time_create; - _FindData->time_access=fd.time_access; - _FindData->time_write=fd.time_write; - _FindData->size=(_fsize_t) fd.size; - strncpy(_FindData->name,fd.name,260); - return ret; - } - __int64 __cdecl _lseeki64(int _FileHandle,__int64 _Offset,int _Origin); - __int64 __cdecl _telli64(int _FileHandle); -#endif -#ifndef NO_OLDNAMES - -#ifndef _UWIN - int __cdecl chdir (const char *); - char *__cdecl getcwd (char *, int); - int __cdecl mkdir (const char *); - char *__cdecl mktemp(char *); - int __cdecl rmdir (const char*); - int __cdecl chmod (const char *, int); -#endif /* _UWIN */ - -#endif /* Not NO_OLDNAMES */ - - _CRTIMP errno_t __cdecl _sopen_s(int *_FileHandle,const char *_Filename,int _OpenFlag,int _ShareFlag,int _PermissionMode); - -#ifndef __cplusplus - _CRTIMP int __cdecl _open(const char *_Filename,int _OpenFlag,...); - _CRTIMP int __cdecl _sopen(const char *_Filename,int _OpenFlag,int _ShareFlag,...); -#else - extern "C++" _CRTIMP int __cdecl _open(const char *_Filename,int _Openflag,int _PermissionMode = 0); - extern "C++" _CRTIMP int __cdecl _sopen(const char *_Filename,int _Openflag,int _ShareFlag,int _PermissionMode = 0); -#endif - -#ifndef _WIO_DEFINED -#define _WIO_DEFINED - _CRTIMP int __cdecl _waccess(const wchar_t *_Filename,int _AccessMode); - _CRTIMP int __cdecl _wchmod(const wchar_t *_Filename,int _Mode); - _CRTIMP int __cdecl _wcreat(const wchar_t *_Filename,int _PermissionMode); - _CRTIMP intptr_t __cdecl _wfindfirst32(const wchar_t *_Filename,struct _wfinddata32_t *_FindData); - _CRTIMP int __cdecl _wfindnext32(intptr_t _FindHandle,struct _wfinddata32_t *_FindData); - _CRTIMP int __cdecl _wunlink(const wchar_t *_Filename); - _CRTIMP int __cdecl _wrename(const wchar_t *_NewFilename,const wchar_t *_OldFilename); - _CRTIMP wchar_t *__cdecl _wmktemp(wchar_t *_TemplateName); - -#if _INTEGRAL_MAX_BITS >= 64 - _CRTIMP intptr_t __cdecl _wfindfirst32i64(const wchar_t *_Filename,struct _wfinddata32i64_t *_FindData); - intptr_t __cdecl _wfindfirst64i32(const wchar_t *_Filename,struct _wfinddata64i32_t *_FindData); - _CRTIMP intptr_t __cdecl _wfindfirst64(const wchar_t *_Filename,struct _wfinddata64_t *_FindData); - _CRTIMP int __cdecl _wfindnext32i64(intptr_t _FindHandle,struct _wfinddata32i64_t *_FindData); - int __cdecl _wfindnext64i32(intptr_t _FindHandle,struct _wfinddata64i32_t *_FindData); - _CRTIMP int __cdecl _wfindnext64(intptr_t _FindHandle,struct _wfinddata64_t *_FindData); -#endif - - _CRTIMP errno_t __cdecl _wsopen_s(int *_FileHandle,const wchar_t *_Filename,int _OpenFlag,int _ShareFlag,int _PermissionFlag); - -#if !defined(__cplusplus) || !(defined(_X86_) && !defined(__x86_64)) - _CRTIMP int __cdecl _wopen(const wchar_t *_Filename,int _OpenFlag,...); - _CRTIMP int __cdecl _wsopen(const wchar_t *_Filename,int _OpenFlag,int _ShareFlag,...); -#else - extern "C++" _CRTIMP int __cdecl _wopen(const wchar_t *_Filename,int _OpenFlag,int _PermissionMode = 0); - extern "C++" _CRTIMP int __cdecl _wsopen(const wchar_t *_Filename,int _OpenFlag,int _ShareFlag,int _PermissionMode = 0); -#endif - -#endif - - int __cdecl __lock_fhandle(int _Filehandle); - void __cdecl _unlock_fhandle(int _Filehandle); - _CRTIMP intptr_t __cdecl _get_osfhandle(int _FileHandle); - _CRTIMP int __cdecl _open_osfhandle(intptr_t _OSFileHandle,int _Flags); - -#ifndef NO_OLDNAMES - int __cdecl access(const char *_Filename,int _AccessMode); - int __cdecl chmod(const char *_Filename,int _AccessMode); - int __cdecl chsize(int _FileHandle,long _Size); - int __cdecl close(int _FileHandle); - int __cdecl creat(const char *_Filename,int _PermissionMode); - int __cdecl dup(int _FileHandle); - int __cdecl dup2(int _FileHandleSrc,int _FileHandleDst); - int __cdecl eof(int _FileHandle); - long __cdecl filelength(int _FileHandle); - int __cdecl isatty(int _FileHandle); - int __cdecl locking(int _FileHandle,int _LockMode,long _NumOfBytes); - long __cdecl lseek(int _FileHandle,long _Offset,int _Origin); - char *__cdecl mktemp(char *_TemplateName); - int __cdecl open(const char *_Filename,int _OpenFlag,...); - int __cdecl read(int _FileHandle,void *_DstBuf,unsigned int _MaxCharCount); - int __cdecl setmode(int _FileHandle,int _Mode); - int __cdecl sopen(const char *_Filename,int _OpenFlag,int _ShareFlag,...); - long __cdecl tell(int _FileHandle); - int __cdecl umask(int _Mode); - int __cdecl write(int _Filehandle,const void *_Buf,unsigned int _MaxCharCount); -#endif - -#ifdef __cplusplus -} -#endif -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/* Misc stuff */ -char *getlogin(void); -#ifdef __USE_MINGW_ALARM -unsigned int alarm(unsigned int seconds); -#endif - -#ifdef __USE_MINGW_ACCESS -/* Old versions of MSVCRT access() just ignored X_OK, while the version - shipped with Vista, returns an error code. This will restore the - old behaviour */ -static inline int __mingw_access (const char *__fname, int __mode) { - return _access (__fname, __mode & ~X_OK); -} - -#define access(__f,__m) __mingw_access (__f, __m) -#endif - - -#ifdef __cplusplus -} -#endif - - -#pragma pack(pop) - -#include - -#endif /* End _IO_H_ */ - diff --git a/05/tcc-final-old/win32/include/limits.h b/05/tcc-final-old/win32/include/limits.h deleted file mode 100644 index fafb04a..0000000 --- a/05/tcc-final-old/win32/include/limits.h +++ /dev/null @@ -1,111 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#include <_mingw.h> - -#ifndef _INC_LIMITS -#define _INC_LIMITS - -/* -* File system limits -* -* TODO: NAME_MAX and OPEN_MAX are file system limits or not? Are they the -* same as FILENAME_MAX and FOPEN_MAX from stdio.h? -* NOTE: Apparently the actual size of PATH_MAX is 260, but a space is -* required for the NUL. TODO: Test? -*/ -#define PATH_MAX (259) - -#define CHAR_BIT 8 -#define SCHAR_MIN (-128) -#define SCHAR_MAX 127 -#define UCHAR_MAX 0xff - -#define CHAR_MIN SCHAR_MIN -#define CHAR_MAX SCHAR_MAX - -#define MB_LEN_MAX 5 -#define SHRT_MIN (-32768) -#define SHRT_MAX 32767 -#define USHRT_MAX 0xffff -#define INT_MIN (-2147483647 - 1) -#define INT_MAX 2147483647 -#define UINT_MAX 0xffffffff -#define LONG_MIN (-2147483647L - 1) -#define LONG_MAX 2147483647L -#define ULONG_MAX 0xffffffffUL -#define LLONG_MAX 9223372036854775807ll -#define LLONG_MIN (-9223372036854775807ll - 1) -#define ULLONG_MAX 0xffffffffffffffffull - -#if _INTEGRAL_MAX_BITS >= 8 -#define _I8_MIN (-127 - 1) -#define _I8_MAX 127i8 -#define _UI8_MAX 0xffu -#endif - -#if _INTEGRAL_MAX_BITS >= 16 -#define _I16_MIN (-32767 - 1) -#define _I16_MAX 32767i16 -#define _UI16_MAX 0xffffu -#endif - -#if _INTEGRAL_MAX_BITS >= 32 -#define _I32_MIN (-2147483647 - 1) -#define _I32_MAX 2147483647 -#define _UI32_MAX 0xffffffffu -#endif - -#if defined(__GNUC__) -#undef LONG_LONG_MAX -#define LONG_LONG_MAX 9223372036854775807ll -#undef LONG_LONG_MIN -#define LONG_LONG_MIN (-LONG_LONG_MAX-1) -#undef ULONG_LONG_MAX -#define ULONG_LONG_MAX (2ull * LONG_LONG_MAX + 1ull) -#endif - -#if _INTEGRAL_MAX_BITS >= 64 -#define _I64_MIN (-9223372036854775807ll - 1) -#define _I64_MAX 9223372036854775807ll -#define _UI64_MAX 0xffffffffffffffffull -#endif - -#ifndef SIZE_MAX -#ifdef _WIN64 -#define SIZE_MAX _UI64_MAX -#else -#define SIZE_MAX UINT_MAX -#endif -#endif - -#ifdef _POSIX_ -#define _POSIX_ARG_MAX 4096 -#define _POSIX_CHILD_MAX 6 -#define _POSIX_LINK_MAX 8 -#define _POSIX_MAX_CANON 255 -#define _POSIX_MAX_INPUT 255 -#define _POSIX_NAME_MAX 14 -#define _POSIX_NGROUPS_MAX 0 -#define _POSIX_OPEN_MAX 16 -#define _POSIX_PATH_MAX 255 -#define _POSIX_PIPE_BUF 512 -#define _POSIX_SSIZE_MAX 32767 -#define _POSIX_STREAM_MAX 8 -#define _POSIX_TZNAME_MAX 3 -#define ARG_MAX 14500 -#define LINK_MAX 1024 -#define MAX_CANON _POSIX_MAX_CANON -#define MAX_INPUT _POSIX_MAX_INPUT -#define NAME_MAX 255 -#define NGROUPS_MAX 16 -#define OPEN_MAX 32 -#define PATH_MAX 512 -#define PIPE_BUF _POSIX_PIPE_BUF -#define SSIZE_MAX _POSIX_SSIZE_MAX -#define STREAM_MAX 20 -#define TZNAME_MAX 10 -#endif -#endif diff --git a/05/tcc-final-old/win32/include/locale.h b/05/tcc-final-old/win32/include/locale.h deleted file mode 100644 index 686aa9b..0000000 --- a/05/tcc-final-old/win32/include/locale.h +++ /dev/null @@ -1,91 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _INC_LOCALE -#define _INC_LOCALE - -#include <_mingw.h> - -#pragma pack(push,_CRT_PACKING) - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef NULL -#ifdef __cplusplus -#define NULL 0 -#else -#define NULL ((void *)0) -#endif -#endif - -#define LC_ALL 0 -#define LC_COLLATE 1 -#define LC_CTYPE 2 -#define LC_MONETARY 3 -#define LC_NUMERIC 4 -#define LC_TIME 5 - -#define LC_MIN LC_ALL -#define LC_MAX LC_TIME - -#ifndef _LCONV_DEFINED -#define _LCONV_DEFINED - struct lconv { - char *decimal_point; - char *thousands_sep; - char *grouping; - char *int_curr_symbol; - char *currency_symbol; - char *mon_decimal_point; - char *mon_thousands_sep; - char *mon_grouping; - char *positive_sign; - char *negative_sign; - char int_frac_digits; - char frac_digits; - char p_cs_precedes; - char p_sep_by_space; - char n_cs_precedes; - char n_sep_by_space; - char p_sign_posn; - char n_sign_posn; - }; -#endif - -#ifndef _CONFIG_LOCALE_SWT -#define _CONFIG_LOCALE_SWT - -#define _ENABLE_PER_THREAD_LOCALE 0x1 -#define _DISABLE_PER_THREAD_LOCALE 0x2 -#define _ENABLE_PER_THREAD_LOCALE_GLOBAL 0x10 -#define _DISABLE_PER_THREAD_LOCALE_GLOBAL 0x20 -#define _ENABLE_PER_THREAD_LOCALE_NEW 0x100 -#define _DISABLE_PER_THREAD_LOCALE_NEW 0x200 - -#endif - - int __cdecl _configthreadlocale(int _Flag); - char *__cdecl setlocale(int _Category,const char *_Locale); - _CRTIMP struct lconv *__cdecl localeconv(void); - _locale_t __cdecl _get_current_locale(void); - _locale_t __cdecl _create_locale(int _Category,const char *_Locale); - void __cdecl _free_locale(_locale_t _Locale); - _locale_t __cdecl __get_current_locale(void); - _locale_t __cdecl __create_locale(int _Category,const char *_Locale); - void __cdecl __free_locale(_locale_t _Locale); - -#ifndef _WLOCALE_DEFINED -#define _WLOCALE_DEFINED - _CRTIMP wchar_t *__cdecl _wsetlocale(int _Category,const wchar_t *_Locale); -#endif - -#ifdef __cplusplus -} -#endif - -#pragma pack(pop) -#endif diff --git a/05/tcc-final-old/win32/include/malloc.h b/05/tcc-final-old/win32/include/malloc.h deleted file mode 100644 index fc783a8..0000000 --- a/05/tcc-final-old/win32/include/malloc.h +++ /dev/null @@ -1,181 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _MALLOC_H_ -#define _MALLOC_H_ - -#include <_mingw.h> - -#pragma pack(push,_CRT_PACKING) - -#ifndef _MM_MALLOC_H_INCLUDED -#define _MM_MALLOC_H_INCLUDED -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef _WIN64 -#define _HEAP_MAXREQ 0xFFFFFFFFFFFFFFE0 -#else -#define _HEAP_MAXREQ 0xFFFFFFE0 -#endif - -#ifndef _STATIC_ASSERT -#define _STATIC_ASSERT(expr) extern void __static_assert_t(int [(expr)?1:-1]) -#endif - -/* Return codes for _heapwalk() */ -#define _HEAPEMPTY (-1) -#define _HEAPOK (-2) -#define _HEAPBADBEGIN (-3) -#define _HEAPBADNODE (-4) -#define _HEAPEND (-5) -#define _HEAPBADPTR (-6) - -/* Values for _heapinfo.useflag */ -#define _FREEENTRY 0 -#define _USEDENTRY 1 - -#ifndef _HEAPINFO_DEFINED -#define _HEAPINFO_DEFINED - /* The structure used to walk through the heap with _heapwalk. */ - typedef struct _heapinfo { - int *_pentry; - size_t _size; - int _useflag; - } _HEAPINFO; -#endif - - extern unsigned int _amblksiz; - -#define _mm_free(a) _aligned_free(a) -#define _mm_malloc(a,b) _aligned_malloc(a,b) - -#ifndef _CRT_ALLOCATION_DEFINED -#define _CRT_ALLOCATION_DEFINED - void *__cdecl calloc(size_t _NumOfElements,size_t _SizeOfElements); - void __cdecl free(void *_Memory); - void *__cdecl malloc(size_t _Size); - void *__cdecl realloc(void *_Memory,size_t _NewSize); - _CRTIMP void *__cdecl _recalloc(void *_Memory,size_t _Count,size_t _Size); - /* _CRTIMP void __cdecl _aligned_free(void *_Memory); - _CRTIMP void *__cdecl _aligned_malloc(size_t _Size,size_t _Alignment); */ - _CRTIMP void *__cdecl _aligned_offset_malloc(size_t _Size,size_t _Alignment,size_t _Offset); - _CRTIMP void *__cdecl _aligned_realloc(void *_Memory,size_t _Size,size_t _Alignment); - _CRTIMP void *__cdecl _aligned_recalloc(void *_Memory,size_t _Count,size_t _Size,size_t _Alignment); - _CRTIMP void *__cdecl _aligned_offset_realloc(void *_Memory,size_t _Size,size_t _Alignment,size_t _Offset); - _CRTIMP void *__cdecl _aligned_offset_recalloc(void *_Memory,size_t _Count,size_t _Size,size_t _Alignment,size_t _Offset); -#endif - -#define _MAX_WAIT_MALLOC_CRT 60000 - - _CRTIMP int __cdecl _resetstkoflw (void); - _CRTIMP unsigned long __cdecl _set_malloc_crt_max_wait(unsigned long _NewValue); - - _CRTIMP void *__cdecl _expand(void *_Memory,size_t _NewSize); - _CRTIMP size_t __cdecl _msize(void *_Memory); -#ifdef __GNUC__ -#undef _alloca -#define _alloca(x) __builtin_alloca((x)) -#else - /* tcc implements alloca internally and exposes it (since commit d778bde7). - /* alloca is declared at include/stddef.h (which is distributed with tcc). - */ -#ifdef _alloca -#undef _alloca -#endif -#define _alloca(x) alloca((x)) -#endif - _CRTIMP size_t __cdecl _get_sbh_threshold(void); - _CRTIMP int __cdecl _set_sbh_threshold(size_t _NewValue); - _CRTIMP errno_t __cdecl _set_amblksiz(size_t _Value); - _CRTIMP errno_t __cdecl _get_amblksiz(size_t *_Value); - _CRTIMP int __cdecl _heapadd(void *_Memory,size_t _Size); - _CRTIMP int __cdecl _heapchk(void); - _CRTIMP int __cdecl _heapmin(void); - _CRTIMP int __cdecl _heapset(unsigned int _Fill); - _CRTIMP int __cdecl _heapwalk(_HEAPINFO *_EntryInfo); - _CRTIMP size_t __cdecl _heapused(size_t *_Used,size_t *_Commit); - _CRTIMP intptr_t __cdecl _get_heap_handle(void); - -#define _ALLOCA_S_THRESHOLD 1024 -#define _ALLOCA_S_STACK_MARKER 0xCCCC -#define _ALLOCA_S_HEAP_MARKER 0xDDDD - -#if(defined(_X86_) && !defined(__x86_64)) -#define _ALLOCA_S_MARKER_SIZE 8 -#elif defined(__ia64__) || defined(__x86_64) -#define _ALLOCA_S_MARKER_SIZE 16 -#endif - -#if !defined(RC_INVOKED) - static __inline void *_MarkAllocaS(void *_Ptr,unsigned int _Marker) { - if(_Ptr) { - *((unsigned int*)_Ptr) = _Marker; - _Ptr = (char*)_Ptr + _ALLOCA_S_MARKER_SIZE; - } - return _Ptr; - } -#endif - -#undef _malloca -#define _malloca(size) \ - ((((size) + _ALLOCA_S_MARKER_SIZE) <= _ALLOCA_S_THRESHOLD) ? \ - _MarkAllocaS(_alloca((size) + _ALLOCA_S_MARKER_SIZE),_ALLOCA_S_STACK_MARKER) : \ - _MarkAllocaS(malloc((size) + _ALLOCA_S_MARKER_SIZE),_ALLOCA_S_HEAP_MARKER)) -#undef _FREEA_INLINE -#define _FREEA_INLINE - -#ifndef RC_INVOKED -#undef _freea - static __inline void __cdecl _freea(void *_Memory) { - unsigned int _Marker; - if(_Memory) { - _Memory = (char*)_Memory - _ALLOCA_S_MARKER_SIZE; - _Marker = *(unsigned int *)_Memory; - if(_Marker==_ALLOCA_S_HEAP_MARKER) { - free(_Memory); - } -#ifdef _ASSERTE - else if(_Marker!=_ALLOCA_S_STACK_MARKER) { - _ASSERTE(("Corrupted pointer passed to _freea",0)); - } -#endif - } - } -#endif /* RC_INVOKED */ - -#ifndef NO_OLDNAMES -#ifdef __GNUC__ -#undef alloca -#define alloca(x) __builtin_alloca((x)) -#endif -#endif - -#ifdef HEAPHOOK -#ifndef _HEAPHOOK_DEFINED -#define _HEAPHOOK_DEFINED - typedef int (__cdecl *_HEAPHOOK)(int,size_t,void *,void **); -#endif - - _CRTIMP _HEAPHOOK __cdecl _setheaphook(_HEAPHOOK _NewHook); - -#define _HEAP_MALLOC 1 -#define _HEAP_CALLOC 2 -#define _HEAP_FREE 3 -#define _HEAP_REALLOC 4 -#define _HEAP_MSIZE 5 -#define _HEAP_EXPAND 6 -#endif - -#ifdef __cplusplus -} -#endif - -#pragma pack(pop) - -#endif /* _MALLOC_H_ */ diff --git a/05/tcc-final-old/win32/include/math.h b/05/tcc-final-old/win32/include/math.h deleted file mode 100644 index 74add20..0000000 --- a/05/tcc-final-old/win32/include/math.h +++ /dev/null @@ -1,737 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _MATH_H_ -#define _MATH_H_ - -#if __GNUC__ >= 3 -#pragma GCC system_header -#endif - -#include <_mingw.h> - -struct exception; - -#pragma pack(push,_CRT_PACKING) - -#define _DOMAIN 1 -#define _SING 2 -#define _OVERFLOW 3 -#define _UNDERFLOW 4 -#define _TLOSS 5 -#define _PLOSS 6 - -#ifndef __STRICT_ANSI__ -#ifndef NO_OLDNAMES -#define DOMAIN _DOMAIN -#define SING _SING -#define OVERFLOW _OVERFLOW -#define UNDERFLOW _UNDERFLOW -#define TLOSS _TLOSS -#define PLOSS _PLOSS -#endif -#endif - -#ifndef __STRICT_ANSI__ -#define M_E 2.71828182845904523536 -#define M_LOG2E 1.44269504088896340736 -#define M_LOG10E 0.434294481903251827651 -#define M_LN2 0.693147180559945309417 -#define M_LN10 2.30258509299404568402 -#define M_PI 3.14159265358979323846 -#define M_PI_2 1.57079632679489661923 -#define M_PI_4 0.785398163397448309616 -#define M_1_PI 0.318309886183790671538 -#define M_2_PI 0.636619772367581343076 -#define M_2_SQRTPI 1.12837916709551257390 -#define M_SQRT2 1.41421356237309504880 -#define M_SQRT1_2 0.707106781186547524401 -#endif - -#ifndef __STRICT_ANSI__ -/* See also float.h */ -#ifndef __MINGW_FPCLASS_DEFINED -#define __MINGW_FPCLASS_DEFINED 1 -#define _FPCLASS_SNAN 0x0001 /* Signaling "Not a Number" */ -#define _FPCLASS_QNAN 0x0002 /* Quiet "Not a Number" */ -#define _FPCLASS_NINF 0x0004 /* Negative Infinity */ -#define _FPCLASS_NN 0x0008 /* Negative Normal */ -#define _FPCLASS_ND 0x0010 /* Negative Denormal */ -#define _FPCLASS_NZ 0x0020 /* Negative Zero */ -#define _FPCLASS_PZ 0x0040 /* Positive Zero */ -#define _FPCLASS_PD 0x0080 /* Positive Denormal */ -#define _FPCLASS_PN 0x0100 /* Positive Normal */ -#define _FPCLASS_PINF 0x0200 /* Positive Infinity */ -#endif -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _EXCEPTION_DEFINED -#define _EXCEPTION_DEFINED - struct _exception { - int type; - char *name; - double arg1; - double arg2; - double retval; - }; -#endif - -#ifndef _COMPLEX_DEFINED -#define _COMPLEX_DEFINED - struct _complex { - double x,y; - }; -#endif - -#define EDOM 33 -#define ERANGE 34 - -#ifndef _HUGE -#ifdef _MSVCRT_ - extern double *_HUGE; -#else - extern double *_imp___HUGE; -#define _HUGE (*_imp___HUGE) -#endif -#endif - -#define HUGE_VAL _HUGE - -#ifndef _CRT_ABS_DEFINED -#define _CRT_ABS_DEFINED - int __cdecl abs(int _X); - long __cdecl labs(long _X); -#endif - double __cdecl acos(double _X); - double __cdecl asin(double _X); - double __cdecl atan(double _X); - double __cdecl atan2(double _Y,double _X); -#ifndef _SIGN_DEFINED -#define _SIGN_DEFINED - _CRTIMP double __cdecl _copysign (double _Number,double _Sign); - _CRTIMP double __cdecl _chgsign (double _X); -#endif - double __cdecl cos(double _X); - double __cdecl cosh(double _X); - double __cdecl exp(double _X); - double __cdecl expm1(double _X); - double __cdecl fabs(double _X); - double __cdecl fmod(double _X,double _Y); - double __cdecl log(double _X); - double __cdecl log10(double _X); - double __cdecl pow(double _X,double _Y); - double __cdecl sin(double _X); - double __cdecl sinh(double _X); - double __cdecl tan(double _X); - double __cdecl tanh(double _X); - double __cdecl sqrt(double _X); -#ifndef _CRT_ATOF_DEFINED -#define _CRT_ATOF_DEFINED - double __cdecl atof(const char *_String); - double __cdecl _atof_l(const char *_String,_locale_t _Locale); -#endif - - _CRTIMP double __cdecl _cabs(struct _complex _ComplexA); - double __cdecl ceil(double _X); - double __cdecl floor(double _X); - double __cdecl frexp(double _X,int *_Y); - double __cdecl _hypot(double _X,double _Y); - _CRTIMP double __cdecl _j0(double _X); - _CRTIMP double __cdecl _j1(double _X); - _CRTIMP double __cdecl _jn(int _X,double _Y); - double __cdecl ldexp(double _X,int _Y); -#ifndef _CRT_MATHERR_DEFINED -#define _CRT_MATHERR_DEFINED - int __cdecl _matherr(struct _exception *_Except); -#endif - double __cdecl modf(double _X,double *_Y); - _CRTIMP double __cdecl _y0(double _X); - _CRTIMP double __cdecl _y1(double _X); - _CRTIMP double __cdecl _yn(int _X,double _Y); - -#if(defined(_X86_) && !defined(__x86_64)) - _CRTIMP int __cdecl _set_SSE2_enable(int _Flag); - /* from libmingwex */ - float __cdecl _hypotf(float _X,float _Y); -#endif - - float frexpf(float _X,int *_Y); - float __cdecl ldexpf(float _X,int _Y); - long double __cdecl ldexpl(long double _X,int _Y); - float __cdecl acosf(float _X); - float __cdecl asinf(float _X); - float __cdecl atanf(float _X); - float __cdecl atan2f(float _X,float _Y); - float __cdecl cosf(float _X); - float __cdecl sinf(float _X); - float __cdecl tanf(float _X); - float __cdecl coshf(float _X); - float __cdecl sinhf(float _X); - float __cdecl tanhf(float _X); - float __cdecl expf(float _X); - float __cdecl expm1f(float _X); - float __cdecl logf(float _X); - float __cdecl log10f(float _X); - float __cdecl modff(float _X,float *_Y); - float __cdecl powf(float _X,float _Y); - float __cdecl sqrtf(float _X); - float __cdecl ceilf(float _X); - float __cdecl floorf(float _X); - float __cdecl fmodf(float _X,float _Y); - float __cdecl _hypotf(float _X,float _Y); - float __cdecl fabsf(float _X); -#if !defined(__ia64__) - /* from libmingwex */ - float __cdecl _copysignf (float _Number,float _Sign); - float __cdecl _chgsignf (float _X); - float __cdecl _logbf(float _X); - float __cdecl _nextafterf(float _X,float _Y); - int __cdecl _finitef(float _X); - int __cdecl _isnanf(float _X); - int __cdecl _fpclassf(float _X); -#endif - -#ifndef __cplusplus - __CRT_INLINE long double __cdecl fabsl (long double x) - { - long double res; - __asm__ ("fabs;" : "=t" (res) : "0" (x)); - return res; - } -#define _hypotl(x,y) ((long double)_hypot((double)(x),(double)(y))) -#define _matherrl _matherr - __CRT_INLINE long double _chgsignl(long double _Number) { return _chgsign((double)(_Number)); } - __CRT_INLINE long double _copysignl(long double _Number,long double _Sign) { return _copysign((double)(_Number),(double)(_Sign)); } - __CRT_INLINE float frexpf(float _X,int *_Y) { return ((float)frexp((double)_X,_Y)); } - -#if !defined (__ia64__) - __CRT_INLINE float __cdecl fabsf (float x) - { - float res; - __asm__ ("fabs;" : "=t" (res) : "0" (x)); - return res; - } - - __CRT_INLINE float __cdecl ldexpf (float x, int expn) { return (float) ldexp (x, expn); } -#endif -#else - // cplusplus - __CRT_INLINE long double __cdecl fabsl (long double x) - { - long double res; - __asm__ ("fabs;" : "=t" (res) : "0" (x)); - return res; - } - __CRT_INLINE long double modfl(long double _X,long double *_Y) { - double _Di,_Df = modf((double)_X,&_Di); - *_Y = (long double)_Di; - return (_Df); - } - __CRT_INLINE long double _chgsignl(long double _Number) { return _chgsign(static_cast(_Number)); } - __CRT_INLINE long double _copysignl(long double _Number,long double _Sign) { return _copysign(static_cast(_Number),static_cast(_Sign)); } - __CRT_INLINE float frexpf(float _X,int *_Y) { return ((float)frexp((double)_X,_Y)); } -#ifndef __ia64__ - __CRT_INLINE float __cdecl fabsf (float x) - { - float res; - __asm__ ("fabs;" : "=t" (res) : "0" (x)); - return res; - } - __CRT_INLINE float __cdecl ldexpf (float x, int expn) { return (float) ldexp (x, expn); } -#ifndef __x86_64 - __CRT_INLINE float acosf(float _X) { return ((float)acos((double)_X)); } - __CRT_INLINE float asinf(float _X) { return ((float)asin((double)_X)); } - __CRT_INLINE float atanf(float _X) { return ((float)atan((double)_X)); } - __CRT_INLINE float atan2f(float _X,float _Y) { return ((float)atan2((double)_X,(double)_Y)); } - __CRT_INLINE float ceilf(float _X) { return ((float)ceil((double)_X)); } - __CRT_INLINE float cosf(float _X) { return ((float)cos((double)_X)); } - __CRT_INLINE float coshf(float _X) { return ((float)cosh((double)_X)); } - __CRT_INLINE float expf(float _X) { return ((float)exp((double)_X)); } - __CRT_INLINE float floorf(float _X) { return ((float)floor((double)_X)); } - __CRT_INLINE float fmodf(float _X,float _Y) { return ((float)fmod((double)_X,(double)_Y)); } - __CRT_INLINE float logf(float _X) { return ((float)log((double)_X)); } - __CRT_INLINE float log10f(float _X) { return ((float)log10((double)_X)); } - __CRT_INLINE float modff(float _X,float *_Y) { - double _Di,_Df = modf((double)_X,&_Di); - *_Y = (float)_Di; - return ((float)_Df); - } - __CRT_INLINE float powf(float _X,float _Y) { return ((float)pow((double)_X,(double)_Y)); } - __CRT_INLINE float sinf(float _X) { return ((float)sin((double)_X)); } - __CRT_INLINE float sinhf(float _X) { return ((float)sinh((double)_X)); } - __CRT_INLINE float sqrtf(float _X) { return ((float)sqrt((double)_X)); } - __CRT_INLINE float tanf(float _X) { return ((float)tan((double)_X)); } - __CRT_INLINE float tanhf(float _X) { return ((float)tanh((double)_X)); } -#endif -#endif -#endif - -#ifndef NO_OLDNAMES -#define matherr _matherr - -#define HUGE _HUGE - /* double __cdecl cabs(struct _complex _X); */ - double __cdecl hypot(double _X,double _Y); - _CRTIMP double __cdecl j0(double _X); - _CRTIMP double __cdecl j1(double _X); - _CRTIMP double __cdecl jn(int _X,double _Y); - _CRTIMP double __cdecl y0(double _X); - _CRTIMP double __cdecl y1(double _X); - _CRTIMP double __cdecl yn(int _X,double _Y); -#endif - -#ifndef __NO_ISOCEXT -#if (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) \ - || !defined __STRICT_ANSI__ || defined __GLIBCPP__ - -#define NAN (0.0F/0.0F) -#define HUGE_VALF (1.0F/0.0F) -#define HUGE_VALL (1.0L/0.0L) -#define INFINITY (1.0F/0.0F) - - -#define FP_NAN 0x0100 -#define FP_NORMAL 0x0400 -#define FP_INFINITE (FP_NAN | FP_NORMAL) -#define FP_ZERO 0x4000 -#define FP_SUBNORMAL (FP_NORMAL | FP_ZERO) - /* 0x0200 is signbit mask */ - - - /* - We can't __CRT_INLINE float or double, because we want to ensure truncation - to semantic type before classification. - (A normal long double value might become subnormal when - converted to double, and zero when converted to float.) - */ - - extern int __cdecl __fpclassifyf (float); - extern int __cdecl __fpclassify (double); - extern int __cdecl __fpclassifyl (long double); - -/* Implemented at tcc/tcc_libm.h */ -#define fpclassify(x) (sizeof (x) == sizeof (float) ? __fpclassifyf (x) \ - : sizeof (x) == sizeof (double) ? __fpclassify (x) \ - : __fpclassifyl (x)) - - /* 7.12.3.2 */ -#define isfinite(x) ((fpclassify(x) & FP_NAN) == 0) - - /* 7.12.3.3 */ -#define isinf(x) (fpclassify(x) == FP_INFINITE) - - /* 7.12.3.4 */ - /* We don't need to worry about truncation here: - A NaN stays a NaN. */ -#define isnan(x) (fpclassify(x) == FP_NAN) - - /* 7.12.3.5 */ -#define isnormal(x) (fpclassify(x) == FP_NORMAL) - - /* 7.12.3.6 The signbit macro */ - - extern int __cdecl __signbitf (float); - extern int __cdecl __signbit (double); - extern int __cdecl __signbitl (long double); - -/* Implemented at tcc/tcc_libm.h */ -#define signbit(x) (sizeof (x) == sizeof (float) ? __signbitf (x) \ - : sizeof (x) == sizeof (double) ? __signbit (x) \ - : __signbitl (x)) - - extern double __cdecl exp2(double); - extern float __cdecl exp2f(float); - extern long double __cdecl exp2l(long double); - -#define FP_ILOGB0 ((int)0x80000000) -#define FP_ILOGBNAN ((int)0x80000000) - extern int __cdecl ilogb (double); - extern int __cdecl ilogbf (float); - extern int __cdecl ilogbl (long double); - - extern double __cdecl log1p(double); - extern float __cdecl log1pf(float); - extern long double __cdecl log1pl(long double); - - extern double __cdecl log2 (double); - extern float __cdecl log2f (float); - extern long double __cdecl log2l (long double); - - extern double __cdecl logb (double); - extern float __cdecl logbf (float); - extern long double __cdecl logbl (long double); - - __CRT_INLINE double __cdecl logb (double x) - { - double res; - __asm__ ("fxtract\n\t" - "fstp %%st" : "=t" (res) : "0" (x)); - return res; - } - - __CRT_INLINE float __cdecl logbf (float x) - { - float res; - __asm__ ("fxtract\n\t" - "fstp %%st" : "=t" (res) : "0" (x)); - return res; - } - - __CRT_INLINE long double __cdecl logbl (long double x) - { - long double res; - __asm__ ("fxtract\n\t" - "fstp %%st" : "=t" (res) : "0" (x)); - return res; - } - - extern long double __cdecl modfl (long double, long double*); - - /* 7.12.6.13 */ - extern double __cdecl scalbn (double, int); - extern float __cdecl scalbnf (float, int); - extern long double __cdecl scalbnl (long double, int); - - extern double __cdecl scalbln (double, long); - extern float __cdecl scalblnf (float, long); - extern long double __cdecl scalblnl (long double, long); - - /* 7.12.7.1 */ - /* Implementations adapted from Cephes versions */ - extern double __cdecl cbrt (double); - extern float __cdecl cbrtf (float); - extern long double __cdecl cbrtl (long double); - - __CRT_INLINE float __cdecl hypotf (float x, float y) - { return (float) hypot (x, y);} - extern long double __cdecl hypotl (long double, long double); - - extern long double __cdecl powl (long double, long double); - extern long double __cdecl expl(long double); - extern long double __cdecl expm1l(long double); - extern long double __cdecl coshl(long double); - extern long double __cdecl fabsl (long double); - extern long double __cdecl acosl(long double); - extern long double __cdecl asinl(long double); - extern long double __cdecl atanl(long double); - extern long double __cdecl atan2l(long double,long double); - extern long double __cdecl sinhl(long double); - extern long double __cdecl tanhl(long double); - - /* 7.12.8.1 The erf functions */ - extern double __cdecl erf (double); - extern float __cdecl erff (float); - /* TODO - extern long double __cdecl erfl (long double); - */ - - /* 7.12.8.2 The erfc functions */ - extern double __cdecl erfc (double); - extern float __cdecl erfcf (float); - /* TODO - extern long double __cdecl erfcl (long double); - */ - - /* 7.12.8.3 The lgamma functions */ - extern double __cdecl lgamma (double); - extern float __cdecl lgammaf (float); - extern long double __cdecl lgammal (long double); - - /* 7.12.8.4 The tgamma functions */ - extern double __cdecl tgamma (double); - extern float __cdecl tgammaf (float); - extern long double __cdecl tgammal (long double); - - extern long double __cdecl ceill (long double); - extern long double __cdecl floorl (long double); - extern long double __cdecl frexpl(long double,int *); - extern long double __cdecl log10l(long double); - extern long double __cdecl logl(long double); - extern long double __cdecl cosl(long double); - extern long double __cdecl sinl(long double); - extern long double __cdecl tanl(long double); - extern long double sqrtl(long double); - - /* 7.12.9.3 */ - extern double __cdecl nearbyint ( double); - extern float __cdecl nearbyintf (float); - extern long double __cdecl nearbyintl (long double); - - /* 7.12.9.4 */ - /* round, using fpu control word settings */ - __CRT_INLINE double __cdecl rint (double x) - { - double retval; - __asm__ ( - "fldl %1\n" - "frndint \n" - "fstl %0\n" : "=m" (retval) : "m" (x)); - return retval; - } - - __CRT_INLINE float __cdecl rintf (float x) - { - float retval; - __asm__ ( - "flds %1\n" - "frndint \n" - "fsts %0\n" : "=m" (retval) : "m" (x)); - return retval; - } - - __CRT_INLINE long double __cdecl rintl (long double x) - { - long double retval; - __asm__ ( - "fldt %1\n" - "frndint \n" - "fstt %0\n" : "=m" (retval) : "m" (x)); - return retval; - } - - /* 7.12.9.5 */ - __CRT_INLINE long __cdecl lrint (double x) - { - long retval; - __asm__ __volatile__ \ - ("fldl %1\n" \ - "fistpl %0" : "=m" (retval) : "m" (x)); \ - return retval; - } - - __CRT_INLINE long __cdecl lrintf (float x) - { - long retval; - __asm__ __volatile__ \ - ("flds %1\n" \ - "fistpl %0" : "=m" (retval) : "m" (x)); \ - return retval; - } - - __CRT_INLINE long __cdecl lrintl (long double x) - { - long retval; - __asm__ __volatile__ \ - ("fldt %1\n" \ - "fistpl %0" : "=m" (retval) : "m" (x)); \ - return retval; - } - - __CRT_INLINE long long __cdecl llrint (double x) - { - long long retval; - __asm__ __volatile__ \ - ("fldl %1\n" \ - "fistpll %0" : "=m" (retval) : "m" (x)); \ - return retval; - } - - __CRT_INLINE long long __cdecl llrintf (float x) - { - long long retval; - __asm__ __volatile__ \ - ("flds %1\n" \ - "fistpll %0" : "=m" (retval) : "m" (x)); \ - return retval; - } - - __CRT_INLINE long long __cdecl llrintl (long double x) - { - long long retval; - __asm__ __volatile__ \ - ("fldt %1\n" \ - "fistpll %0" : "=m" (retval) : "m" (x)); \ - return retval; - } - - #define FE_TONEAREST 0x0000 - #define FE_DOWNWARD 0x0400 - #define FE_UPWARD 0x0800 - #define FE_TOWARDZERO 0x0c00 - - __CRT_INLINE double trunc (double _x) - { - double retval; - unsigned short saved_cw; - unsigned short tmp_cw; - __asm__ ("fnstcw %0;" : "=m" (saved_cw)); /* save FPU control word */ - tmp_cw = (saved_cw & ~(FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | FE_TOWARDZERO)) - | FE_TOWARDZERO; - __asm__ ("fldcw %0;" : : "m" (tmp_cw)); - __asm__ ("fldl %1;" - "frndint;" - "fstl %0;" : "=m" (retval) : "m" (_x)); /* round towards zero */ - __asm__ ("fldcw %0;" : : "m" (saved_cw) ); /* restore saved control word */ - return retval; - } - - /* 7.12.9.6 */ - /* round away from zero, regardless of fpu control word settings */ - extern double __cdecl round (double); - extern float __cdecl roundf (float); - extern long double __cdecl roundl (long double); - - /* 7.12.9.7 */ - extern long __cdecl lround (double); - extern long __cdecl lroundf (float); - extern long __cdecl lroundl (long double); - - extern long long __cdecl llround (double); - extern long long __cdecl llroundf (float); - extern long long __cdecl llroundl (long double); - - /* 7.12.9.8 */ - /* round towards zero, regardless of fpu control word settings */ - extern double __cdecl trunc (double); - extern float __cdecl truncf (float); - extern long double __cdecl truncl (long double); - - extern long double __cdecl fmodl (long double, long double); - - /* 7.12.10.2 */ - extern double __cdecl remainder (double, double); - extern float __cdecl remainderf (float, float); - extern long double __cdecl remainderl (long double, long double); - - /* 7.12.10.3 */ - extern double __cdecl remquo(double, double, int *); - extern float __cdecl remquof(float, float, int *); - extern long double __cdecl remquol(long double, long double, int *); - - /* 7.12.11.1 */ - extern double __cdecl copysign (double, double); /* in libmoldname.a */ - extern float __cdecl copysignf (float, float); - extern long double __cdecl copysignl (long double, long double); - - /* 7.12.11.2 Return a NaN */ - extern double __cdecl nan(const char *tagp); - extern float __cdecl nanf(const char *tagp); - extern long double __cdecl nanl(const char *tagp); - -#ifndef __STRICT_ANSI__ -#define _nan() nan("") -#define _nanf() nanf("") -#define _nanl() nanl("") -#endif - - /* 7.12.11.3 */ - extern double __cdecl nextafter (double, double); /* in libmoldname.a */ - extern float __cdecl nextafterf (float, float); - extern long double __cdecl nextafterl (long double, long double); - - /* 7.12.11.4 The nexttoward functions: TODO */ - - /* 7.12.12.1 */ - /* x > y ? (x - y) : 0.0 */ - extern double __cdecl fdim (double x, double y); - extern float __cdecl fdimf (float x, float y); - extern long double __cdecl fdiml (long double x, long double y); - - /* fmax and fmin. - NaN arguments are treated as missing data: if one argument is a NaN - and the other numeric, then these functions choose the numeric - value. */ - - /* 7.12.12.2 */ - extern double __cdecl fmax (double, double); - extern float __cdecl fmaxf (float, float); - extern long double __cdecl fmaxl (long double, long double); - - /* 7.12.12.3 */ - extern double __cdecl fmin (double, double); - extern float __cdecl fminf (float, float); - extern long double __cdecl fminl (long double, long double); - - /* 7.12.13.1 */ - /* return x * y + z as a ternary op */ - extern double __cdecl fma (double, double, double); - extern float __cdecl fmaf (float, float, float); - extern long double __cdecl fmal (long double, long double, long double); - - -#if 0 // gr: duplicate, see below - /* 7.12.14 */ - /* - * With these functions, comparisons involving quiet NaNs set the FP - * condition code to "unordered". The IEEE floating-point spec - * dictates that the result of floating-point comparisons should be - * false whenever a NaN is involved, with the exception of the != op, - * which always returns true: yes, (NaN != NaN) is true). - */ - -#if __GNUC__ >= 3 - -#define isgreater(x, y) __builtin_isgreater(x, y) -#define isgreaterequal(x, y) __builtin_isgreaterequal(x, y) -#define isless(x, y) __builtin_isless(x, y) -#define islessequal(x, y) __builtin_islessequal(x, y) -#define islessgreater(x, y) __builtin_islessgreater(x, y) -#define isunordered(x, y) __builtin_isunordered(x, y) - -#else - /* helper */ - __CRT_INLINE int __cdecl - __fp_unordered_compare (long double x, long double y){ - unsigned short retval; - __asm__ ("fucom %%st(1);" - "fnstsw;": "=a" (retval) : "t" (x), "u" (y)); - return retval; - } - -#define isgreater(x, y) ((__fp_unordered_compare(x, y) \ - & 0x4500) == 0) -#define isless(x, y) ((__fp_unordered_compare (y, x) \ - & 0x4500) == 0) -#define isgreaterequal(x, y) ((__fp_unordered_compare (x, y) \ - & FP_INFINITE) == 0) -#define islessequal(x, y) ((__fp_unordered_compare(y, x) \ - & FP_INFINITE) == 0) -#define islessgreater(x, y) ((__fp_unordered_compare(x, y) \ - & FP_SUBNORMAL) == 0) -#define isunordered(x, y) ((__fp_unordered_compare(x, y) \ - & 0x4500) == 0x4500) - -#endif -#endif //0 - - -#endif /* __STDC_VERSION__ >= 199901L */ -#endif /* __NO_ISOCEXT */ - -#ifdef __cplusplus -} -extern "C++" { - template inline _Ty _Pow_int(_Ty _X,int _Y) { - unsigned int _N; - if(_Y >= 0) _N = (unsigned int)_Y; - else _N = (unsigned int)(-_Y); - for(_Ty _Z = _Ty(1);;_X *= _X) { - if((_N & 1)!=0) _Z *= _X; - if((_N >>= 1)==0) return (_Y < 0 ? _Ty(1) / _Z : _Z); - } - } -} -#endif - -#pragma pack(pop) - -/* 7.12.14 */ -/* - * With these functions, comparisons involving quiet NaNs set the FP - * condition code to "unordered". The IEEE floating-point spec - * dictates that the result of floating-point comparisons should be - * false whenever a NaN is involved, with the exception of the != op, - * which always returns true: yes, (NaN != NaN) is true). - */ - -/* Mini libm (inline __fpclassify*, __signbit* and variants) */ -#include "tcc/tcc_libm.h" - -#endif /* End _MATH_H_ */ - diff --git a/05/tcc-final-old/win32/include/mem.h b/05/tcc-final-old/win32/include/mem.h deleted file mode 100644 index 2552023..0000000 --- a/05/tcc-final-old/win32/include/mem.h +++ /dev/null @@ -1,13 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -/* - * This file is part of the Mingw32 package. - * - * mem.h maps to string.h - */ -#ifndef __STRICT_ANSI__ -#include -#endif diff --git a/05/tcc-final-old/win32/include/memory.h b/05/tcc-final-old/win32/include/memory.h deleted file mode 100644 index 90d88ae..0000000 --- a/05/tcc-final-old/win32/include/memory.h +++ /dev/null @@ -1,40 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _INC_MEMORY -#define _INC_MEMORY - -#include <_mingw.h> - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _CONST_RETURN -#define _CONST_RETURN -#endif - -#define _WConst_return _CONST_RETURN - -#ifndef _CRT_MEMORY_DEFINED -#define _CRT_MEMORY_DEFINED - _CRTIMP void *__cdecl _memccpy(void *_Dst,const void *_Src,int _Val,size_t _MaxCount); - _CONST_RETURN void *__cdecl memchr(const void *_Buf ,int _Val,size_t _MaxCount); - _CRTIMP int __cdecl _memicmp(const void *_Buf1,const void *_Buf2,size_t _Size); - _CRTIMP int __cdecl _memicmp_l(const void *_Buf1,const void *_Buf2,size_t _Size,_locale_t _Locale); - int __cdecl memcmp(const void *_Buf1,const void *_Buf2,size_t _Size); - void *__cdecl memcpy(void *_Dst,const void *_Src,size_t _Size); - void *__cdecl memset(void *_Dst,int _Val,size_t _Size); - -#ifndef NO_OLDNAMES - void *__cdecl memccpy(void *_Dst,const void *_Src,int _Val,size_t _Size); - int __cdecl memicmp(const void *_Buf1,const void *_Buf2,size_t _Size); -#endif -#endif - -#ifdef __cplusplus -} -#endif -#endif diff --git a/05/tcc-final-old/win32/include/process.h b/05/tcc-final-old/win32/include/process.h deleted file mode 100644 index dadaf2b..0000000 --- a/05/tcc-final-old/win32/include/process.h +++ /dev/null @@ -1,176 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _INC_PROCESS -#define _INC_PROCESS - -#include <_mingw.h> - -/* Includes a definition of _pid_t and pid_t */ -#include - -#ifndef _POSIX_ -#ifdef __cplusplus -extern "C" { -#endif - -#define _P_WAIT 0 -#define _P_NOWAIT 1 -#define _OLD_P_OVERLAY 2 -#define _P_NOWAITO 3 -#define _P_DETACH 4 -#define _P_OVERLAY 2 - -#define _WAIT_CHILD 0 -#define _WAIT_GRANDCHILD 1 - - _CRTIMP uintptr_t __cdecl _beginthread(void (__cdecl *_StartAddress) (void *),unsigned _StackSize,void *_ArgList); - _CRTIMP void __cdecl _endthread(void); - _CRTIMP uintptr_t __cdecl _beginthreadex(void *_Security,unsigned _StackSize,unsigned (__stdcall *_StartAddress) (void *),void *_ArgList,unsigned _InitFlag,unsigned *_ThrdAddr); - _CRTIMP void __cdecl _endthreadex(unsigned _Retval); - -#ifndef _CRT_TERMINATE_DEFINED -#define _CRT_TERMINATE_DEFINED - void __cdecl __MINGW_NOTHROW exit(int _Code) __MINGW_ATTRIB_NORETURN; - _CRTIMP void __cdecl __MINGW_NOTHROW _exit(int _Code) __MINGW_ATTRIB_NORETURN; - -#pragma push_macro("abort") -#undef abort - void __cdecl __declspec(noreturn) abort(void); -#pragma pop_macro("abort") - -#endif - - _CRTIMP void __cdecl __MINGW_NOTHROW _cexit(void); - _CRTIMP void __cdecl __MINGW_NOTHROW _c_exit(void); - _CRTIMP int __cdecl _getpid(void); - _CRTIMP intptr_t __cdecl _cwait(int *_TermStat,intptr_t _ProcHandle,int _Action); - _CRTIMP intptr_t __cdecl _execl(const char *_Filename,const char *_ArgList,...); - _CRTIMP intptr_t __cdecl _execle(const char *_Filename,const char *_ArgList,...); - _CRTIMP intptr_t __cdecl _execlp(const char *_Filename,const char *_ArgList,...); - _CRTIMP intptr_t __cdecl _execlpe(const char *_Filename,const char *_ArgList,...); - _CRTIMP intptr_t __cdecl _execv(const char *_Filename,const char *const *_ArgList); - _CRTIMP intptr_t __cdecl _execve(const char *_Filename,const char *const *_ArgList,const char *const *_Env); - _CRTIMP intptr_t __cdecl _execvp(const char *_Filename,const char *const *_ArgList); - _CRTIMP intptr_t __cdecl _execvpe(const char *_Filename,const char *const *_ArgList,const char *const *_Env); - _CRTIMP intptr_t __cdecl _spawnl(int _Mode,const char *_Filename,const char *_ArgList,...); - _CRTIMP intptr_t __cdecl _spawnle(int _Mode,const char *_Filename,const char *_ArgList,...); - _CRTIMP intptr_t __cdecl _spawnlp(int _Mode,const char *_Filename,const char *_ArgList,...); - _CRTIMP intptr_t __cdecl _spawnlpe(int _Mode,const char *_Filename,const char *_ArgList,...); - _CRTIMP intptr_t __cdecl _spawnv(int _Mode,const char *_Filename,const char *const *_ArgList); - _CRTIMP intptr_t __cdecl _spawnve(int _Mode,const char *_Filename,const char *const *_ArgList,const char *const *_Env); - _CRTIMP intptr_t __cdecl _spawnvp(int _Mode,const char *_Filename,const char *const *_ArgList); - _CRTIMP intptr_t __cdecl _spawnvpe(int _Mode,const char *_Filename,const char *const *_ArgList,const char *const *_Env); - -#ifndef _CRT_SYSTEM_DEFINED -#define _CRT_SYSTEM_DEFINED - int __cdecl system(const char *_Command); -#endif - -#ifndef _WPROCESS_DEFINED -#define _WPROCESS_DEFINED - _CRTIMP intptr_t __cdecl _wexecl(const wchar_t *_Filename,const wchar_t *_ArgList,...); - _CRTIMP intptr_t __cdecl _wexecle(const wchar_t *_Filename,const wchar_t *_ArgList,...); - _CRTIMP intptr_t __cdecl _wexeclp(const wchar_t *_Filename,const wchar_t *_ArgList,...); - _CRTIMP intptr_t __cdecl _wexeclpe(const wchar_t *_Filename,const wchar_t *_ArgList,...); - _CRTIMP intptr_t __cdecl _wexecv(const wchar_t *_Filename,const wchar_t *const *_ArgList); - _CRTIMP intptr_t __cdecl _wexecve(const wchar_t *_Filename,const wchar_t *const *_ArgList,const wchar_t *const *_Env); - _CRTIMP intptr_t __cdecl _wexecvp(const wchar_t *_Filename,const wchar_t *const *_ArgList); - _CRTIMP intptr_t __cdecl _wexecvpe(const wchar_t *_Filename,const wchar_t *const *_ArgList,const wchar_t *const *_Env); - _CRTIMP intptr_t __cdecl _wspawnl(int _Mode,const wchar_t *_Filename,const wchar_t *_ArgList,...); - _CRTIMP intptr_t __cdecl _wspawnle(int _Mode,const wchar_t *_Filename,const wchar_t *_ArgList,...); - _CRTIMP intptr_t __cdecl _wspawnlp(int _Mode,const wchar_t *_Filename,const wchar_t *_ArgList,...); - _CRTIMP intptr_t __cdecl _wspawnlpe(int _Mode,const wchar_t *_Filename,const wchar_t *_ArgList,...); - _CRTIMP intptr_t __cdecl _wspawnv(int _Mode,const wchar_t *_Filename,const wchar_t *const *_ArgList); - _CRTIMP intptr_t __cdecl _wspawnve(int _Mode,const wchar_t *_Filename,const wchar_t *const *_ArgList,const wchar_t *const *_Env); - _CRTIMP intptr_t __cdecl _wspawnvp(int _Mode,const wchar_t *_Filename,const wchar_t *const *_ArgList); - _CRTIMP intptr_t __cdecl _wspawnvpe(int _Mode,const wchar_t *_Filename,const wchar_t *const *_ArgList,const wchar_t *const *_Env); -#ifndef _CRT_WSYSTEM_DEFINED -#define _CRT_WSYSTEM_DEFINED - _CRTIMP int __cdecl _wsystem(const wchar_t *_Command); -#endif -#endif - - void __cdecl __security_init_cookie(void); -#if (defined(_X86_) && !defined(__x86_64)) - void __fastcall __security_check_cookie(uintptr_t _StackCookie); - __declspec(noreturn) void __cdecl __report_gsfailure(void); -#else - void __cdecl __security_check_cookie(uintptr_t _StackCookie); - __declspec(noreturn) void __cdecl __report_gsfailure(uintptr_t _StackCookie); -#endif - extern uintptr_t __security_cookie; - - intptr_t __cdecl _loaddll(char *_Filename); - int __cdecl _unloaddll(intptr_t _Handle); - int (__cdecl *__cdecl _getdllprocaddr(intptr_t _Handle,char *_ProcedureName,intptr_t _Ordinal))(void); - -#ifdef _DECL_DLLMAIN -#ifdef _WINDOWS_ - WINBOOL WINAPI DllMain(HANDLE _HDllHandle,DWORD _Reason,LPVOID _Reserved); - WINBOOL WINAPI _CRT_INIT(HANDLE _HDllHandle,DWORD _Reason,LPVOID _Reserved); - WINBOOL WINAPI _wCRT_INIT(HANDLE _HDllHandle,DWORD _Reason,LPVOID _Reserved); - extern WINBOOL (WINAPI *const _pRawDllMain)(HANDLE,DWORD,LPVOID); -#else - int __stdcall DllMain(void *_HDllHandle,unsigned _Reason,void *_Reserved); - int __stdcall _CRT_INIT(void *_HDllHandle,unsigned _Reason,void *_Reserved); - int __stdcall _wCRT_INIT(void *_HDllHandle,unsigned _Reason,void *_Reserved); - extern int (__stdcall *const _pRawDllMain)(void *,unsigned,void *); -#endif -#endif - -#ifndef NO_OLDNAMES -#define P_WAIT _P_WAIT -#define P_NOWAIT _P_NOWAIT -#define P_OVERLAY _P_OVERLAY -#define OLD_P_OVERLAY _OLD_P_OVERLAY -#define P_NOWAITO _P_NOWAITO -#define P_DETACH _P_DETACH -#define WAIT_CHILD _WAIT_CHILD -#define WAIT_GRANDCHILD _WAIT_GRANDCHILD - - intptr_t __cdecl cwait(int *_TermStat,intptr_t _ProcHandle,int _Action); -#ifdef __GNUC__ - int __cdecl execl(const char *_Filename,const char *_ArgList,...); - int __cdecl execle(const char *_Filename,const char *_ArgList,...); - int __cdecl execlp(const char *_Filename,const char *_ArgList,...); - int __cdecl execlpe(const char *_Filename,const char *_ArgList,...); -#else - intptr_t __cdecl execl(const char *_Filename,const char *_ArgList,...); - intptr_t __cdecl execle(const char *_Filename,const char *_ArgList,...); - intptr_t __cdecl execlp(const char *_Filename,const char *_ArgList,...); - intptr_t __cdecl execlpe(const char *_Filename,const char *_ArgList,...); -#endif - intptr_t __cdecl spawnl(int,const char *_Filename,const char *_ArgList,...); - intptr_t __cdecl spawnle(int,const char *_Filename,const char *_ArgList,...); - intptr_t __cdecl spawnlp(int,const char *_Filename,const char *_ArgList,...); - intptr_t __cdecl spawnlpe(int,const char *_Filename,const char *_ArgList,...); - int __cdecl getpid(void); -#ifdef __GNUC__ - /* Those methods are predefined by gcc builtins to return int. So to prevent - stupid warnings, define them in POSIX way. This is save, because those - methods do not return in success case, so that the return value is not - really dependent to its scalar width. */ - int __cdecl execv(const char *_Filename,const char *const _ArgList[]); - int __cdecl execve(const char *_Filename,const char *const _ArgList[],const char *const _Env[]); - int __cdecl execvp(const char *_Filename,const char *const _ArgList[]); - int __cdecl execvpe(const char *_Filename,const char *const _ArgList[],const char *const _Env[]); -#else - intptr_t __cdecl execv(const char *_Filename,const char *const _ArgList[]); - intptr_t __cdecl execve(const char *_Filename,const char *const _ArgList[],const char *const _Env[]); - intptr_t __cdecl execvp(const char *_Filename,const char *const _ArgList[]); - intptr_t __cdecl execvpe(const char *_Filename,const char *const _ArgList[],const char *const _Env[]); -#endif - intptr_t __cdecl spawnv(int,const char *_Filename,const char *const _ArgList[]); - intptr_t __cdecl spawnve(int,const char *_Filename,const char *const _ArgList[],const char *const _Env[]); - intptr_t __cdecl spawnvp(int,const char *_Filename,const char *const _ArgList[]); - intptr_t __cdecl spawnvpe(int,const char *_Filename,const char *const _ArgList[],char *const _Env[]); -#endif - -#ifdef __cplusplus -} -#endif -#endif -#endif diff --git a/05/tcc-final-old/win32/include/sec_api/conio_s.h b/05/tcc-final-old/win32/include/sec_api/conio_s.h deleted file mode 100644 index 98d97ba..0000000 --- a/05/tcc-final-old/win32/include/sec_api/conio_s.h +++ /dev/null @@ -1,42 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ - -#ifndef _INC_CONIO_S -#define _INC_CONIO_S - -#include - -#if defined(MINGW_HAS_SECURE_API) - -#ifdef __cplusplus -extern "C" { -#endif - - _CRTIMP errno_t __cdecl _cgets_s(char *_Buffer,size_t _Size,size_t *_SizeRead); - _CRTIMP int __cdecl _cprintf_s(const char *_Format,...); - _CRTIMP int __cdecl _cscanf_s(const char *_Format,...); - _CRTIMP int __cdecl _cscanf_s_l(const char *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _vcprintf_s(const char *_Format,va_list _ArgList); - _CRTIMP int __cdecl _cprintf_s_l(const char *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _vcprintf_s_l(const char *_Format,_locale_t _Locale,va_list _ArgList); - -#ifndef _WCONIO_DEFINED_S -#define _WCONIO_DEFINED_S - _CRTIMP errno_t __cdecl _cgetws_s(wchar_t *_Buffer,size_t _SizeInWords,size_t *_SizeRead); - _CRTIMP int __cdecl _cwprintf_s(const wchar_t *_Format,...); - _CRTIMP int __cdecl _cwscanf_s(const wchar_t *_Format,...); - _CRTIMP int __cdecl _cwscanf_s_l(const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _vcwprintf_s(const wchar_t *_Format,va_list _ArgList); - _CRTIMP int __cdecl _cwprintf_s_l(const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _vcwprintf_s_l(const wchar_t *_Format,_locale_t _Locale,va_list _ArgList); -#endif - -#ifdef __cplusplus -} -#endif - -#endif -#endif diff --git a/05/tcc-final-old/win32/include/sec_api/crtdbg_s.h b/05/tcc-final-old/win32/include/sec_api/crtdbg_s.h deleted file mode 100644 index 4598b4f..0000000 --- a/05/tcc-final-old/win32/include/sec_api/crtdbg_s.h +++ /dev/null @@ -1,19 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ - -#ifndef _INC_CRTDBG_S -#define _INC_CRTDBG_S - -#include - -#if defined(MINGW_HAS_SECURE_API) - -#define _dupenv_s_dbg(ps1,size,s2,t,f,l) _dupenv_s(ps1,size,s2) -#define _wdupenv_s_dbg(ps1,size,s2,t,f,l) _wdupenv_s(ps1,size,s2) - -#endif - -#endif diff --git a/05/tcc-final-old/win32/include/sec_api/io_s.h b/05/tcc-final-old/win32/include/sec_api/io_s.h deleted file mode 100644 index ec565a6..0000000 --- a/05/tcc-final-old/win32/include/sec_api/io_s.h +++ /dev/null @@ -1,33 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _INC_IO_S -#define _INC_IO_S - -#include - -#if defined(MINGW_HAS_SECURE_API) - -#ifdef __cplusplus -extern "C" { -#endif - - _CRTIMP errno_t __cdecl _access_s(const char *_Filename,int _AccessMode); - _CRTIMP errno_t __cdecl _chsize_s(int _FileHandle,__int64 _Size); - _CRTIMP errno_t __cdecl _mktemp_s(char *_TemplateName,size_t _Size); - _CRTIMP errno_t __cdecl _umask_s(int _NewMode,int *_OldMode); - -#ifndef _WIO_S_DEFINED -#define _WIO_S_DEFINED - _CRTIMP errno_t __cdecl _waccess_s(const wchar_t *_Filename,int _AccessMode); - _CRTIMP errno_t __cdecl _wmktemp_s(wchar_t *_TemplateName,size_t _SizeInWords); -#endif - -#ifdef __cplusplus -} -#endif - -#endif -#endif diff --git a/05/tcc-final-old/win32/include/sec_api/mbstring_s.h b/05/tcc-final-old/win32/include/sec_api/mbstring_s.h deleted file mode 100644 index 6b2b188..0000000 --- a/05/tcc-final-old/win32/include/sec_api/mbstring_s.h +++ /dev/null @@ -1,52 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _INC_MBSTRING_S -#define _INC_MBSTRING_S - -#include - -#if defined(MINGW_HAS_SECURE_API) - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _MBSTRING_S_DEFINED -#define _MBSTRING_S_DEFINED - _CRTIMP errno_t __cdecl _mbscat_s(unsigned char *_Dst,size_t _DstSizeInBytes,const unsigned char *_Src); - _CRTIMP errno_t __cdecl _mbscat_s_l(unsigned char *_Dst,size_t _DstSizeInBytes,const unsigned char *_Src,_locale_t _Locale); - _CRTIMP errno_t __cdecl _mbscpy_s(unsigned char *_Dst,size_t _DstSizeInBytes,const unsigned char *_Src); - _CRTIMP errno_t __cdecl _mbscpy_s_l(unsigned char *_Dst,size_t _DstSizeInBytes,const unsigned char *_Src,_locale_t _Locale); - _CRTIMP errno_t __cdecl _mbslwr_s(unsigned char *_Str,size_t _SizeInBytes); - _CRTIMP errno_t __cdecl _mbslwr_s_l(unsigned char *_Str,size_t _SizeInBytes,_locale_t _Locale); - _CRTIMP errno_t __cdecl _mbsnbcat_s(unsigned char *_Dst,size_t _DstSizeInBytes,const unsigned char *_Src,size_t _MaxCount); - _CRTIMP errno_t __cdecl _mbsnbcat_s_l(unsigned char *_Dst,size_t _DstSizeInBytes,const unsigned char *_Src,size_t _MaxCount,_locale_t _Locale); - _CRTIMP errno_t __cdecl _mbsnbcpy_s(unsigned char *_Dst,size_t _DstSizeInBytes,const unsigned char *_Src,size_t _MaxCount); - _CRTIMP errno_t __cdecl _mbsnbcpy_s_l(unsigned char *_Dst,size_t _DstSizeInBytes,const unsigned char *_Src,size_t _MaxCount,_locale_t _Locale); - _CRTIMP errno_t __cdecl _mbsnbset_s(unsigned char *_Dst,size_t _DstSizeInBytes,unsigned int _Ch,size_t _MaxCount); - _CRTIMP errno_t __cdecl _mbsnbset_s_l(unsigned char *_Dst,size_t _DstSizeInBytes,unsigned int _Ch,size_t _MaxCount,_locale_t _Locale); - _CRTIMP errno_t __cdecl _mbsncat_s(unsigned char *_Dst,size_t _DstSizeInBytes,const unsigned char *_Src,size_t _MaxCount); - _CRTIMP errno_t __cdecl _mbsncat_s_l(unsigned char *_Dst,size_t _DstSizeInBytes,const unsigned char *_Src,size_t _MaxCount,_locale_t _Locale); - _CRTIMP errno_t __cdecl _mbsncpy_s(unsigned char *_Dst,size_t _DstSizeInBytes,const unsigned char *_Src,size_t _MaxCount); - _CRTIMP errno_t __cdecl _mbsncpy_s_l(unsigned char *_Dst,size_t _DstSizeInBytes,const unsigned char *_Src,size_t _MaxCount,_locale_t _Locale); - _CRTIMP errno_t __cdecl _mbsnset_s(unsigned char *_Dst,size_t _DstSizeInBytes,unsigned int _Val,size_t _MaxCount); - _CRTIMP errno_t __cdecl _mbsnset_s_l(unsigned char *_Dst,size_t _DstSizeInBytes,unsigned int _Val,size_t _MaxCount,_locale_t _Locale); - _CRTIMP errno_t __cdecl _mbsset_s(unsigned char *_Dst,size_t _DstSizeInBytes,unsigned int _Val); - _CRTIMP errno_t __cdecl _mbsset_s_l(unsigned char *_Dst,size_t _DstSizeInBytes,unsigned int _Val,_locale_t _Locale); - _CRTIMP unsigned char *__cdecl _mbstok_s(unsigned char *_Str,const unsigned char *_Delim,unsigned char **_Context); - _CRTIMP unsigned char *__cdecl _mbstok_s_l(unsigned char *_Str,const unsigned char *_Delim,unsigned char **_Context,_locale_t _Locale); - _CRTIMP errno_t __cdecl _mbsupr_s(unsigned char *_Str,size_t _SizeInBytes); - _CRTIMP errno_t __cdecl _mbsupr_s_l(unsigned char *_Str,size_t _SizeInBytes,_locale_t _Locale); - _CRTIMP errno_t __cdecl _mbccpy_s(unsigned char *_Dst,size_t _DstSizeInBytes,int *_PCopied,const unsigned char *_Src); - _CRTIMP errno_t __cdecl _mbccpy_s_l(unsigned char *_Dst,size_t _DstSizeInBytes,int *_PCopied,const unsigned char *_Src,_locale_t _Locale); -#endif - -#ifdef __cplusplus -} -#endif - -#endif -#endif diff --git a/05/tcc-final-old/win32/include/sec_api/search_s.h b/05/tcc-final-old/win32/include/sec_api/search_s.h deleted file mode 100644 index cae8998..0000000 --- a/05/tcc-final-old/win32/include/sec_api/search_s.h +++ /dev/null @@ -1,25 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _INC_SEARCH_S -#define _INC_SEARCH_S - -#include - -#if defined(MINGW_HAS_SECURE_API) - -#ifdef __cplusplus -extern "C" { -#endif - - _CRTIMP void *__cdecl _lfind_s(const void *_Key,const void *_Base,unsigned int *_NumOfElements,size_t _SizeOfElements,int (__cdecl *_PtFuncCompare)(void *,const void *,const void *),void *_Context); - _CRTIMP void *__cdecl _lsearch_s(const void *_Key,void *_Base,unsigned int *_NumOfElements,size_t _SizeOfElements,int (__cdecl *_PtFuncCompare)(void *,const void *,const void *),void *_Context); - -#ifdef __cplusplus -} -#endif - -#endif -#endif diff --git a/05/tcc-final-old/win32/include/sec_api/stdio_s.h b/05/tcc-final-old/win32/include/sec_api/stdio_s.h deleted file mode 100644 index c9b803b..0000000 --- a/05/tcc-final-old/win32/include/sec_api/stdio_s.h +++ /dev/null @@ -1,145 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _INC_STDIO_S -#define _INC_STDIO_S - -#include - -#if defined(MINGW_HAS_SECURE_API) - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _STDIO_S_DEFINED -#define _STDIO_S_DEFINED - _CRTIMP errno_t __cdecl clearerr_s(FILE *_File); - int __cdecl fprintf_s(FILE *_File,const char *_Format,...); - size_t __cdecl fread_s(void *_DstBuf,size_t _DstSize,size_t _ElementSize,size_t _Count,FILE *_File); - _CRTIMP int __cdecl _fscanf_s_l(FILE *_File,const char *_Format,_locale_t _Locale,...); - int __cdecl printf_s(const char *_Format,...); - _CRTIMP int __cdecl _scanf_l(const char *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _scanf_s_l(const char *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _snprintf_s(char *_DstBuf,size_t _DstSize,size_t _MaxCount,const char *_Format,...); - _CRTIMP int __cdecl _snprintf_c(char *_DstBuf,size_t _MaxCount,const char *_Format,...); - _CRTIMP int __cdecl _vsnprintf_c(char *_DstBuf,size_t _MaxCount,const char *_Format,va_list _ArgList); - int __cdecl sprintf_s(char *_DstBuf,size_t _DstSize,const char *_Format,...); - _CRTIMP int __cdecl _fscanf_l(FILE *_File,const char *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _sscanf_l(const char *_Src,const char *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _sscanf_s_l(const char *_Src,const char *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _snscanf_s(const char *_Src,size_t _MaxCount,const char *_Format,...); - _CRTIMP int __cdecl _snscanf_l(const char *_Src,size_t _MaxCount,const char *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _snscanf_s_l(const char *_Src,size_t _MaxCount,const char *_Format,_locale_t _Locale,...); - int __cdecl vfprintf_s(FILE *_File,const char *_Format,va_list _ArgList); - int __cdecl vprintf_s(const char *_Format,va_list _ArgList); - int __cdecl vsnprintf_s(char *_DstBuf,size_t _DstSize,size_t _MaxCount,const char *_Format,va_list _ArgList); - _CRTIMP int __cdecl _vsnprintf_s(char *_DstBuf,size_t _DstSize,size_t _MaxCount,const char *_Format,va_list _ArgList); - int __cdecl vsprintf_s(char *_DstBuf,size_t _Size,const char *_Format,va_list _ArgList); - _CRTIMP int __cdecl _fprintf_p(FILE *_File,const char *_Format,...); - _CRTIMP int __cdecl _printf_p(const char *_Format,...); - _CRTIMP int __cdecl _sprintf_p(char *_Dst,size_t _MaxCount,const char *_Format,...); - _CRTIMP int __cdecl _vfprintf_p(FILE *_File,const char *_Format,va_list _ArgList); - _CRTIMP int __cdecl _vprintf_p(const char *_Format,va_list _ArgList); - _CRTIMP int __cdecl _vsprintf_p(char *_Dst,size_t _MaxCount,const char *_Format,va_list _ArgList); - _CRTIMP int __cdecl _scprintf_p(const char *_Format,...); - _CRTIMP int __cdecl _vscprintf_p(const char *_Format,va_list _ArgList); - _CRTIMP int __cdecl _printf_l(const char *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _printf_p_l(const char *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _vprintf_l(const char *_Format,_locale_t _Locale,va_list _ArgList); - _CRTIMP int __cdecl _vprintf_p_l(const char *_Format,_locale_t _Locale,va_list _ArgList); - _CRTIMP int __cdecl _fprintf_l(FILE *_File,const char *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _fprintf_p_l(FILE *_File,const char *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _vfprintf_l(FILE *_File,const char *_Format,_locale_t _Locale,va_list _ArgList); - _CRTIMP int __cdecl _vfprintf_p_l(FILE *_File,const char *_Format,_locale_t _Locale,va_list _ArgList); - _CRTIMP int __cdecl _sprintf_l(char *_DstBuf,const char *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _sprintf_p_l(char *_DstBuf,size_t _MaxCount,const char *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _vsprintf_l(char *_DstBuf,const char *_Format,_locale_t,va_list _ArgList); - _CRTIMP int __cdecl _vsprintf_p_l(char *_DstBuf,size_t _MaxCount,const char *_Format,_locale_t _Locale,va_list _ArgList); - _CRTIMP int __cdecl _scprintf_l(const char *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _scprintf_p_l(const char *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _vscprintf_l(const char *_Format,_locale_t _Locale,va_list _ArgList); - _CRTIMP int __cdecl _vscprintf_p_l(const char *_Format,_locale_t _Locale,va_list _ArgList); - _CRTIMP int __cdecl _printf_s_l(const char *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _vprintf_s_l(const char *_Format,_locale_t _Locale,va_list _ArgList); - _CRTIMP int __cdecl _fprintf_s_l(FILE *_File,const char *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _vfprintf_s_l(FILE *_File,const char *_Format,_locale_t _Locale,va_list _ArgList); - _CRTIMP int __cdecl _sprintf_s_l(char *_DstBuf,size_t _DstSize,const char *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _vsprintf_s_l(char *_DstBuf,size_t _DstSize,const char *_Format,_locale_t _Locale,va_list _ArgList); - _CRTIMP int __cdecl _snprintf_s_l(char *_DstBuf,size_t _DstSize,size_t _MaxCount,const char *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _vsnprintf_s_l(char *_DstBuf,size_t _DstSize,size_t _MaxCount,const char *_Format,_locale_t _Locale,va_list _ArgList); - _CRTIMP int __cdecl _snprintf_l(char *_DstBuf,size_t _MaxCount,const char *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _snprintf_c_l(char *_DstBuf,size_t _MaxCount,const char *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _vsnprintf_l(char *_DstBuf,size_t _MaxCount,const char *_Format,_locale_t _Locale,va_list _ArgList); - _CRTIMP int __cdecl _vsnprintf_c_l(char *_DstBuf,size_t _MaxCount,const char *,_locale_t _Locale,va_list _ArgList); - -#ifndef _WSTDIO_S_DEFINED -#define _WSTDIO_S_DEFINED - _CRTIMP wchar_t *__cdecl _getws_s(wchar_t *_Str,size_t _SizeInWords); - int __cdecl fwprintf_s(FILE *_File,const wchar_t *_Format,...); - int __cdecl wprintf_s(const wchar_t *_Format,...); - int __cdecl vwprintf_s(const wchar_t *_Format,va_list _ArgList); - int __cdecl swprintf_s(wchar_t *_Dst,size_t _SizeInWords,const wchar_t *_Format,...); - int __cdecl vswprintf_s(wchar_t *_Dst,size_t _SizeInWords,const wchar_t *_Format,va_list _ArgList); - _CRTIMP int __cdecl _snwprintf_s(wchar_t *_DstBuf,size_t _DstSizeInWords,size_t _MaxCount,const wchar_t *_Format,...); - _CRTIMP int __cdecl _vsnwprintf_s(wchar_t *_DstBuf,size_t _DstSizeInWords,size_t _MaxCount,const wchar_t *_Format,va_list _ArgList); - _CRTIMP int __cdecl _wprintf_s_l(const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _vwprintf_s_l(const wchar_t *_Format,_locale_t _Locale,va_list _ArgList); - _CRTIMP int __cdecl _fwprintf_s_l(FILE *_File,const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _vfwprintf_s_l(FILE *_File,const wchar_t *_Format,_locale_t _Locale,va_list _ArgList); - _CRTIMP int __cdecl _swprintf_s_l(wchar_t *_DstBuf,size_t _DstSize,const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _vswprintf_s_l(wchar_t *_DstBuf,size_t _DstSize,const wchar_t *_Format,_locale_t _Locale,va_list _ArgList); - _CRTIMP int __cdecl _snwprintf_s_l(wchar_t *_DstBuf,size_t _DstSize,size_t _MaxCount,const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _vsnwprintf_s_l(wchar_t *_DstBuf,size_t _DstSize,size_t _MaxCount,const wchar_t *_Format,_locale_t _Locale,va_list _ArgList); - _CRTIMP int __cdecl _fwscanf_s_l(FILE *_File,const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _swscanf_s_l(const wchar_t *_Src,const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _snwscanf_s(const wchar_t *_Src,size_t _MaxCount,const wchar_t *_Format,...); - _CRTIMP int __cdecl _snwscanf_s_l(const wchar_t *_Src,size_t _MaxCount,const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _wscanf_s_l(const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP errno_t __cdecl _wfopen_s(FILE **_File,const wchar_t *_Filename,const wchar_t *_Mode); - _CRTIMP errno_t __cdecl _wfreopen_s(FILE **_File,const wchar_t *_Filename,const wchar_t *_Mode,FILE *_OldFile); - _CRTIMP errno_t __cdecl _wtmpnam_s(wchar_t *_DstBuf,size_t _SizeInWords); - _CRTIMP int __cdecl _fwprintf_p(FILE *_File,const wchar_t *_Format,...); - _CRTIMP int __cdecl _wprintf_p(const wchar_t *_Format,...); - _CRTIMP int __cdecl _vfwprintf_p(FILE *_File,const wchar_t *_Format,va_list _ArgList); - _CRTIMP int __cdecl _vwprintf_p(const wchar_t *_Format,va_list _ArgList); - _CRTIMP int __cdecl _swprintf_p(wchar_t *_DstBuf,size_t _MaxCount,const wchar_t *_Format,...); - _CRTIMP int __cdecl _vswprintf_p(wchar_t *_DstBuf,size_t _MaxCount,const wchar_t *_Format,va_list _ArgList); - _CRTIMP int __cdecl _scwprintf_p(const wchar_t *_Format,...); - _CRTIMP int __cdecl _vscwprintf_p(const wchar_t *_Format,va_list _ArgList); - _CRTIMP int __cdecl _wprintf_l(const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _wprintf_p_l(const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _vwprintf_l(const wchar_t *_Format,_locale_t _Locale,va_list _ArgList); - _CRTIMP int __cdecl _vwprintf_p_l(const wchar_t *_Format,_locale_t _Locale,va_list _ArgList); - _CRTIMP int __cdecl _fwprintf_l(FILE *_File,const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _fwprintf_p_l(FILE *_File,const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _vfwprintf_l(FILE *_File,const wchar_t *_Format,_locale_t _Locale,va_list _ArgList); - _CRTIMP int __cdecl _vfwprintf_p_l(FILE *_File,const wchar_t *_Format,_locale_t _Locale,va_list _ArgList); - _CRTIMP int __cdecl _swprintf_c_l(wchar_t *_DstBuf,size_t _MaxCount,const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _swprintf_p_l(wchar_t *_DstBuf,size_t _MaxCount,const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _vswprintf_c_l(wchar_t *_DstBuf,size_t _MaxCount,const wchar_t *_Format,_locale_t _Locale,va_list _ArgList); - _CRTIMP int __cdecl _vswprintf_p_l(wchar_t *_DstBuf,size_t _MaxCount,const wchar_t *_Format,_locale_t _Locale,va_list _ArgList); - _CRTIMP int __cdecl _scwprintf_l(const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _scwprintf_p_l(const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _vscwprintf_p_l(const wchar_t *_Format,_locale_t _Locale,va_list _ArgList); - _CRTIMP int __cdecl _snwprintf_l(wchar_t *_DstBuf,size_t _MaxCount,const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _vsnwprintf_l(wchar_t *_DstBuf,size_t _MaxCount,const wchar_t *_Format,_locale_t _Locale,va_list _ArgList); - _CRTIMP int __cdecl __swprintf_l(wchar_t *_Dest,const wchar_t *_Format,_locale_t _Plocinfo,...); - _CRTIMP int __cdecl __vswprintf_l(wchar_t *_Dest,const wchar_t *_Format,_locale_t _Plocinfo,va_list _Args); - _CRTIMP int __cdecl _vscwprintf_l(const wchar_t *_Format,_locale_t _Locale,va_list _ArgList); - _CRTIMP int __cdecl _fwscanf_l(FILE *_File,const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _swscanf_l(const wchar_t *_Src,const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _snwscanf_l(const wchar_t *_Src,size_t _MaxCount,const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _wscanf_l(const wchar_t *_Format,_locale_t _Locale,...); -#endif -#endif - - _CRTIMP size_t __cdecl _fread_nolock_s(void *_DstBuf,size_t _DstSize,size_t _ElementSize,size_t _Count,FILE *_File); - -#ifdef __cplusplus -} -#endif -#endif -#endif diff --git a/05/tcc-final-old/win32/include/sec_api/stdlib_s.h b/05/tcc-final-old/win32/include/sec_api/stdlib_s.h deleted file mode 100644 index f98262c..0000000 --- a/05/tcc-final-old/win32/include/sec_api/stdlib_s.h +++ /dev/null @@ -1,67 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _INC_STDLIB_S -#define _INC_STDLIB_S - -#include - -#if defined(MINGW_HAS_SECURE_API) - -#ifdef __cplusplus -extern "C" { -#endif - - _CRTIMP errno_t __cdecl _dupenv_s(char **_PBuffer,size_t *_PBufferSizeInBytes,const char *_VarName); - _CRTIMP errno_t __cdecl _itoa_s(int _Value,char *_DstBuf,size_t _Size,int _Radix); -#if _INTEGRAL_MAX_BITS >= 64 - _CRTIMP errno_t __cdecl _i64toa_s(__int64 _Val,char *_DstBuf,size_t _Size,int _Radix); - _CRTIMP errno_t __cdecl _ui64toa_s(unsigned __int64 _Val,char *_DstBuf,size_t _Size,int _Radix); -#endif - _CRTIMP errno_t __cdecl _ltoa_s(long _Val,char *_DstBuf,size_t _Size,int _Radix); - _CRTIMP errno_t __cdecl mbstowcs_s(size_t *_PtNumOfCharConverted,wchar_t *_DstBuf,size_t _SizeInWords,const char *_SrcBuf,size_t _MaxCount); - _CRTIMP errno_t __cdecl _mbstowcs_s_l(size_t *_PtNumOfCharConverted,wchar_t *_DstBuf,size_t _SizeInWords,const char *_SrcBuf,size_t _MaxCount,_locale_t _Locale); - _CRTIMP errno_t __cdecl _ultoa_s(unsigned long _Val,char *_DstBuf,size_t _Size,int _Radix); - _CRTIMP errno_t __cdecl _wctomb_s_l(int *_SizeConverted,char *_MbCh,size_t _SizeInBytes,wchar_t _WCh,_locale_t _Locale); - _CRTIMP errno_t __cdecl wcstombs_s(size_t *_PtNumOfCharConverted,char *_Dst,size_t _DstSizeInBytes,const wchar_t *_Src,size_t _MaxCountInBytes); - _CRTIMP errno_t __cdecl _wcstombs_s_l(size_t *_PtNumOfCharConverted,char *_Dst,size_t _DstSizeInBytes,const wchar_t *_Src,size_t _MaxCountInBytes,_locale_t _Locale); - -#ifndef _WSTDLIB_S_DEFINED -#define _WSTDLIB_S_DEFINED - _CRTIMP errno_t __cdecl _itow_s (int _Val,wchar_t *_DstBuf,size_t _SizeInWords,int _Radix); - _CRTIMP errno_t __cdecl _ltow_s (long _Val,wchar_t *_DstBuf,size_t _SizeInWords,int _Radix); - _CRTIMP errno_t __cdecl _ultow_s (unsigned long _Val,wchar_t *_DstBuf,size_t _SizeInWords,int _Radix); - _CRTIMP errno_t __cdecl _wgetenv_s(size_t *_ReturnSize,wchar_t *_DstBuf,size_t _DstSizeInWords,const wchar_t *_VarName); - _CRTIMP errno_t __cdecl _wdupenv_s(wchar_t **_Buffer,size_t *_BufferSizeInWords,const wchar_t *_VarName); -#if _INTEGRAL_MAX_BITS >= 64 - _CRTIMP errno_t __cdecl _i64tow_s(__int64 _Val,wchar_t *_DstBuf,size_t _SizeInWords,int _Radix); - _CRTIMP errno_t __cdecl _ui64tow_s(unsigned __int64 _Val,wchar_t *_DstBuf,size_t _SizeInWords,int _Radix); -#endif -#endif - -#ifndef _POSIX_ - _CRTIMP errno_t __cdecl _ecvt_s(char *_DstBuf,size_t _Size,double _Val,int _NumOfDights,int *_PtDec,int *_PtSign); - _CRTIMP errno_t __cdecl _fcvt_s(char *_DstBuf,size_t _Size,double _Val,int _NumOfDec,int *_PtDec,int *_PtSign); - _CRTIMP errno_t __cdecl _gcvt_s(char *_DstBuf,size_t _Size,double _Val,int _NumOfDigits); - _CRTIMP errno_t __cdecl _makepath_s(char *_PathResult,size_t _Size,const char *_Drive,const char *_Dir,const char *_Filename,const char *_Ext); - _CRTIMP errno_t __cdecl _putenv_s(const char *_Name,const char *_Value); - _CRTIMP errno_t __cdecl _searchenv_s(const char *_Filename,const char *_EnvVar,char *_ResultPath,size_t _SizeInBytes); - _CRTIMP errno_t __cdecl _splitpath_s(const char *_FullPath,char *_Drive,size_t _DriveSize,char *_Dir,size_t _DirSize,char *_Filename,size_t _FilenameSize,char *_Ext,size_t _ExtSize); - -#ifndef _WSTDLIBP_S_DEFINED -#define _WSTDLIBP_S_DEFINED - _CRTIMP errno_t __cdecl _wmakepath_s(wchar_t *_PathResult,size_t _SizeInWords,const wchar_t *_Drive,const wchar_t *_Dir,const wchar_t *_Filename,const wchar_t *_Ext); - _CRTIMP errno_t __cdecl _wputenv_s(const wchar_t *_Name,const wchar_t *_Value); - _CRTIMP errno_t __cdecl _wsearchenv_s(const wchar_t *_Filename,const wchar_t *_EnvVar,wchar_t *_ResultPath,size_t _SizeInWords); - _CRTIMP errno_t __cdecl _wsplitpath_s(const wchar_t *_FullPath,wchar_t *_Drive,size_t _DriveSizeInWords,wchar_t *_Dir,size_t _DirSizeInWords,wchar_t *_Filename,size_t _FilenameSizeInWords,wchar_t *_Ext,size_t _ExtSizeInWords); -#endif -#endif - -#ifdef __cplusplus -} -#endif - -#endif -#endif diff --git a/05/tcc-final-old/win32/include/sec_api/stralign_s.h b/05/tcc-final-old/win32/include/sec_api/stralign_s.h deleted file mode 100644 index 5b78f58..0000000 --- a/05/tcc-final-old/win32/include/sec_api/stralign_s.h +++ /dev/null @@ -1,30 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef __STRALIGN_H_S_ -#define __STRALIGN_H_S_ - -#include - -#if defined(MINGW_HAS_SECURE_API) - -#ifdef __cplusplus -extern "C" { -#endif - -#if !defined(I_X86_) && defined(_WSTRING_S_DEFINED) -#if defined(__cplusplus) && defined(_WConst_Return) - static __inline PUWSTR ua_wcscpy_s(PUWSTR Destination,size_t DestinationSize,PCUWSTR Source) { - if(WSTR_ALIGNED(Source) && WSTR_ALIGNED(Destination)) return (wcscpy_s((PWSTR)Destination,DestinationSize,(PCWSTR)Source)==0 ? Destination : NULL); - return uaw_wcscpy((PCUWSTR)String,Character); - } -#endif -#endif - -#ifdef __cplusplus -} -#endif -#endif -#endif diff --git a/05/tcc-final-old/win32/include/sec_api/string_s.h b/05/tcc-final-old/win32/include/sec_api/string_s.h deleted file mode 100644 index 9db70e7..0000000 --- a/05/tcc-final-old/win32/include/sec_api/string_s.h +++ /dev/null @@ -1,41 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _INC_STRING_S -#define _INC_STRING_S - -#include - -#if defined(MINGW_HAS_SECURE_API) - -#ifdef __cplusplus -extern "C" { -#endif - - _CRTIMP errno_t __cdecl _strset_s(char *_Dst,size_t _DstSize,int _Value); - _CRTIMP errno_t __cdecl _strerror_s(char *_Buf,size_t _SizeInBytes,const char *_ErrMsg); - _CRTIMP errno_t __cdecl _strlwr_s(char *_Str,size_t _Size); - _CRTIMP errno_t __cdecl _strlwr_s_l(char *_Str,size_t _Size,_locale_t _Locale); - _CRTIMP errno_t __cdecl _strnset_s(char *_Str,size_t _Size,int _Val,size_t _MaxCount); - _CRTIMP errno_t __cdecl _strupr_s(char *_Str,size_t _Size); - _CRTIMP errno_t __cdecl _strupr_s_l(char *_Str,size_t _Size,_locale_t _Locale); -#ifndef _WSTRING_S_DEFINED -#define _WSTRING_S_DEFINED - _CRTIMP wchar_t *__cdecl wcstok_s(wchar_t *_Str,const wchar_t *_Delim,wchar_t **_Context); - _CRTIMP errno_t __cdecl _wcserror_s(wchar_t *_Buf,size_t _SizeInWords,int _ErrNum); - _CRTIMP errno_t __cdecl __wcserror_s(wchar_t *_Buffer,size_t _SizeInWords,const wchar_t *_ErrMsg); - _CRTIMP errno_t __cdecl _wcsnset_s(wchar_t *_Dst,size_t _DstSizeInWords,wchar_t _Val,size_t _MaxCount); - _CRTIMP errno_t __cdecl _wcsset_s(wchar_t *_Str,size_t _SizeInWords,wchar_t _Val); - _CRTIMP errno_t __cdecl _wcslwr_s(wchar_t *_Str,size_t _SizeInWords); - _CRTIMP errno_t __cdecl _wcslwr_s_l(wchar_t *_Str,size_t _SizeInWords,_locale_t _Locale); - _CRTIMP errno_t __cdecl _wcsupr_s(wchar_t *_Str,size_t _Size); - _CRTIMP errno_t __cdecl _wcsupr_s_l(wchar_t *_Str,size_t _Size,_locale_t _Locale); -#endif - -#ifdef __cplusplus -} -#endif -#endif -#endif diff --git a/05/tcc-final-old/win32/include/sec_api/sys/timeb_s.h b/05/tcc-final-old/win32/include/sec_api/sys/timeb_s.h deleted file mode 100644 index af5ef09..0000000 --- a/05/tcc-final-old/win32/include/sec_api/sys/timeb_s.h +++ /dev/null @@ -1,34 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ - -#ifndef _TIMEB_H_S -#define _TIMEB_H_S - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#if defined(MINGW_HAS_SECURE_API) - -#ifdef _USE_32BIT_TIME_T -#define _ftime_s _ftime32_s -#else -#define _ftime_s _ftime64_s -#endif - - _CRTIMP errno_t __cdecl _ftime32_s(struct __timeb32 *_Time); -#if _INTEGRAL_MAX_BITS >= 64 - _CRTIMP errno_t __cdecl _ftime64_s(struct __timeb64 *_Time); -#endif -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/05/tcc-final-old/win32/include/sec_api/tchar_s.h b/05/tcc-final-old/win32/include/sec_api/tchar_s.h deleted file mode 100644 index 343d348..0000000 --- a/05/tcc-final-old/win32/include/sec_api/tchar_s.h +++ /dev/null @@ -1,266 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _INC_TCHAR_S -#define _INC_TCHAR_S - -#include - -#if defined(MINGW_HAS_SECURE_API) - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef _UNICODE - -#define _tprintf_s wprintf_s -#define _tprintf_s_l _wprintf_s_l -#define _tcprintf_s _cwprintf_s -#define _tcprintf_s_l _cwprintf_s_l -#define _vtcprintf_s _vcwprintf_s -#define _vtcprintf_s_l _vcwprintf_s_l -#define _ftprintf_s fwprintf_s -#define _ftprintf_s_l _fwprintf_s_l -#define _stprintf_s swprintf_s -#define _stprintf_s_l _swprintf_s_l -#define _sntprintf_s _snwprintf_s -#define _sntprintf_s_l _snwprintf_s_l -#define _vtprintf_s vwprintf_s -#define _vtprintf_s_l _vwprintf_s_l -#define _vftprintf_s vfwprintf_s -#define _vftprintf_s_l _vfwprintf_s_l -#define _vstprintf_s vswprintf_s -#define _vstprintf_s_l _vswprintf_s_l -#define _vsntprintf_s _vsnwprintf_s -#define _vsntprintf_s_l _vsnwprintf_s_l - -#define _tscanf_s wscanf_s -#define _tscanf_s_l _wscanf_s_l -#define _tcscanf_s _cwscanf_s -#define _tcscanf_s_l _cwscanf_s_l -#define _ftscanf_s fwscanf_s -#define _ftscanf_s_l _fwscanf_s_l -#define _stscanf_s swscanf_s -#define _stscanf_s_l _swscanf_s_l -#define _sntscanf_s _snwscanf_s -#define _sntscanf_s_l _snwscanf_s_l - -#define _cgetts_s _cgetws_s -#define _getts_s _getws_s - -#define _itot_s _itow_s -#define _ltot_s _ltow_s -#define _ultot_s _ultow_s -#define _i64tot_s _i64tow_s -#define _ui64tot_s _ui64tow_s - -#define _tcscat_s wcscat_s -#define _tcscpy_s wcscpy_s -#define _tcsncat_s wcsncat_s -#define _tcsncat_s_l _wcsncat_s_l -#define _tcsncpy_s wcsncpy_s -#define _tcsncpy_s_l _wcsncpy_s_l -#define _tcstok_s wcstok_s -#define _tcstok_s_l _wcstok_s_l -#define _tcserror_s _wcserror_s -#define __tcserror_s __wcserror_s - -#define _tcsnset_s _wcsnset_s -#define _tcsnset_s_l _wcsnset_s_l -#define _tcsset_s _wcsset_s -#define _tcsset_s_l _wcsset_s_l - -#define _tasctime_s _wasctime_s -#define _tctime_s _wctime_s -#define _tctime32_s _wctime32_s -#define _tctime64_s _wctime64_s -#define _tstrdate_s _wstrdate_s -#define _tstrtime_s _wstrtime_s - -#define _tgetenv_s _wgetenv_s -#define _tdupenv_s _wdupenv_s -#define _tmakepath_s _wmakepath_s -#define _tputenv_s _wputenv_s -#define _tsearchenv_s _wsearchenv_s -#define _tsplitpath_s _wsplitpath_s - -#define _tfopen_s _wfopen_s -#define _tfreopen_s _wfreopen_s -#define _ttmpnam_s _wtmpnam_s -#define _taccess_s _waccess_s -#define _tmktemp_s _wmktemp_s - -#define _tcsnccat_s wcsncat_s -#define _tcsnccat_s_l _wcsncat_s_l -#define _tcsnccpy_s wcsncpy_s -#define _tcsnccpy_s_l _wcsncpy_s_l - -#define _tcslwr_s _wcslwr_s -#define _tcslwr_s_l _wcslwr_s_l -#define _tcsupr_s _wcsupr_s -#define _tcsupr_s_l _wcsupr_s_l - -#define _wcstok_s_l(_String,_Delimiters,_Current_position,_Locale) (wcstok_s(_String,_Delimiters,_Current_position)) -#define _wcsnset_s_l(_Destination,_Destination_size_chars,_Value,_Count,_Locale) (_wcsnset_s(_Destination,_Destination_size_chars,_Value,_Count)) -#define _wcsset_s_l(_Destination,_Destination_size_chars,_Value,_Locale) (_wcsset_s(_Destination,_Destination_size_chars,_Value)) - -#else - -#define _tprintf_s printf_s -#define _tprintf_s_l _printf_s_l -#define _tcprintf_s _cprintf_s -#define _tcprintf_s_l _cprintf_s_l -#define _vtcprintf_s _vcprintf_s -#define _vtcprintf_s_l _vcprintf_s_l -#define _ftprintf_s fprintf_s -#define _ftprintf_s_l _fprintf_s_l -#define _stprintf_s sprintf_s -#define _stprintf_s_l _sprintf_s_l -#define _sntprintf_s _snprintf_s -#define _sntprintf_s_l _snprintf_s_l -#define _vtprintf_s vprintf_s -#define _vtprintf_s_l _vprintf_s_l -#define _vftprintf_s vfprintf_s -#define _vftprintf_s_l _vfprintf_s_l -#define _vstprintf_s vsprintf_s -#define _vstprintf_s_l _vsprintf_s_l -#define _vsntprintf_s _vsnprintf_s -#define _vsntprintf_s_l _vsnprintf_s_l -#define _tscanf_s scanf_s -#define _tscanf_s_l _scanf_s_l -#define _tcscanf_s _cscanf_s -#define _tcscanf_s_l _cscanf_s_l -#define _ftscanf_s fscanf_s -#define _ftscanf_s_l _fscanf_s_l -#define _stscanf_s sscanf_s -#define _stscanf_s_l _sscanf_s_l -#define _sntscanf_s _snscanf_s -#define _sntscanf_s_l _snscanf_s_l - -#define _getts_s gets_s -#define _cgetts_s _cgets_s -#define _itot_s _itoa_s -#define _ltot_s _ltoa_s -#define _ultot_s _ultoa_s -#define _i64tot_s _i64toa_s -#define _ui64tot_s _ui64toa_s - -#define _tcscat_s strcat_s -#define _tcscpy_s strcpy_s -#define _tcserror_s strerror_s -#define __tcserror_s _strerror_s - -#define _tasctime_s asctime_s -#define _tctime_s ctime_s -#define _tctime32_s _ctime32_s -#define _tctime64_s _ctime64_s -#define _tstrdate_s _strdate_s -#define _tstrtime_s _strtime_s - -#define _tgetenv_s getenv_s -#define _tdupenv_s _dupenv_s -#define _tmakepath_s _makepath_s -#define _tputenv_s _putenv_s -#define _tsearchenv_s _searchenv_s -#define _tsplitpath_s _splitpath_s - -#define _tfopen_s fopen_s -#define _tfreopen_s freopen_s -#define _ttmpnam_s tmpnam_s -#define _tmktemp_s _mktemp_s - -#ifndef _POSIX_ -#define _taccess_s _access_s -#endif - -#define _tsopen_s _sopen_s - -#ifdef _MBCS - -#ifdef _MB_MAP_DIRECT - -#define _tcsncat_s _mbsnbcat_s -#define _tcsncat_s_l _mbsnbcat_s_l -#define _tcsncpy_s _mbsnbcpy_s -#define _tcsncpy_s_l _mbsnbcpy_s_l -#define _tcstok_s _mbstok_s -#define _tcstok_s_l _mbstok_s_l - -#define _tcsnset_s _mbsnbset_s -#define _tcsnset_s_l _mbsnbset_s_l -#define _tcsset_s _mbsset_s -#define _tcsset_s_l _mbsset_s_l - -#define _tcsnccat_s _mbsncat_s -#define _tcsnccat_s_l _mbsncat_s_l -#define _tcsnccpy_s _mbsncpy_s -#define _tcsnccpy_s_l _mbsncpy_s_l -#define _tcsncset_s _mbsnset_s -#define _tcsncset_s_l _mbsnset_s_l - -#define _tcslwr_s _mbslwr_s -#define _tcslwr_s_l _mbslwr_s_l -#define _tcsupr_s _mbsupr_s -#define _tcsupr_s_l _mbsupr_s_l - -#define _tccpy_s _mbccpy_s -#define _tccpy_s_l _mbccpy_s_l -#else - - _CRTIMP char *__cdecl _tcsncat_s(char *_Dst,size_t _DstSizeInChars,const char *_Src,size_t _MaxCount); - _CRTIMP char *__cdecl _tcsncat_s_l(char *_Dst,size_t _DstSizeInChars,const char *_Src,size_t _MaxCount,_locale_t _Locale); - _CRTIMP char *__cdecl _tcsncpy_s(char *_Dst,size_t _DstSizeInChars,const char *_Src,size_t _MaxCount); - _CRTIMP char *__cdecl _tcsncpy_s_l(char *_Dst,size_t _DstSizeInChars,const char *_Src,size_t _MaxCount,_locale_t _Locale); - _CRTIMP char *__cdecl _tcstok_s(char *_Str,const char *_Delim,char **_Context); - _CRTIMP char *__cdecl _tcstok_s_l(char *_Str,const char *_Delim,char **_Context,_locale_t _Locale); - _CRTIMP errno_t __cdecl _tcsset_s(char *_Str,size_t _SizeInChars,unsigned int _Val); - _CRTIMP errno_t __cdecl _tcsset_s_l(char *_Str,size_t _SizeInChars,unsigned int,_locale_t _Locale); - _CRTIMP char *__cdecl _tcsnccat_s(char *_Dst,size_t _DstSizeInChars,const char *_Src,size_t _MaxCount); - _CRTIMP char *__cdecl _tcsnccat_s_l(char *_Dst,size_t _DstSizeInChars,const char *_Src,size_t _MaxCount,_locale_t _Locale); - _CRTIMP char *__cdecl _tcsnccpy_s(char *_Dst,size_t _DstSizeInChars,const char *_Src,size_t _MaxCount); - _CRTIMP char *__cdecl _tcsnccpy_s_l(char *_Dst,size_t _DstSizeInChars,const char *_Src,size_t _MaxCount,_locale_t _Locale); - _CRTIMP char *__cdecl _tcslwr_s(char *_Str,size_t _SizeInChars); - _CRTIMP char *__cdecl _tcslwr_s_l(char *_Str,size_t _SizeInChars,_locale_t _Locale); - _CRTIMP char *__cdecl _tcsupr_s(char *_Str,size_t _SizeInChars); - _CRTIMP char *__cdecl _tcsupr_s_l(char *_Str,size_t _SizeInChars,_locale_t _Locale); - -#endif - -#else - -#define _tcsncat_s strncat_s -#define _tcsncat_s_l _strncat_s_l -#define _tcsncpy_s strncpy_s -#define _tcsncpy_s_l _strncpy_s_l -#define _tcstok_s strtok_s -#define _tcstok_s_l _strtok_s_l - -#define _tcsnset_s _strnset_s -#define _tcsnset_s_l _strnset_s_l -#define _tcsset_s _strset_s -#define _tcsset_s _strset_s -#define _tcsset_s_l _strset_s_l - -#define _tcsnccat_s strncat_s -#define _tcsnccat_s_l _strncat_s_l -#define _tcsnccpy_s strncpy_s -#define _tcsnccpy_s_l _strncpy_s_l - -#define _tcslwr_s _strlwr_s -#define _tcslwr_s_l _strlwr_s_l -#define _tcsupr_s _strupr_s -#define _tcsupr_s_l _strupr_s_l - -#define _strnset_s_l(_Destination,_Destination_size_chars,_Value,_Count,_Locale) (_strnset_s(_Destination,_Destination_size_chars,_Value,_Count)) -#define _strset_s_l(_Destination,_Destination_size_chars,_Value,_Locale) (_strset_s(_Destination,_Destination_size_chars,_Value)) -#endif -#endif - -#ifdef __cplusplus -} -#endif -#endif -#endif diff --git a/05/tcc-final-old/win32/include/sec_api/time_s.h b/05/tcc-final-old/win32/include/sec_api/time_s.h deleted file mode 100644 index 9603b94..0000000 --- a/05/tcc-final-old/win32/include/sec_api/time_s.h +++ /dev/null @@ -1,61 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _TIME_H__S -#define _TIME_H__S - -#include - -#if defined(MINGW_HAS_SECURE_API) - -#ifdef __cplusplus -extern "C" { -#endif - - _CRTIMP errno_t __cdecl _ctime32_s(char *_Buf,size_t _SizeInBytes,const __time32_t *_Time); - _CRTIMP errno_t __cdecl _gmtime32_s(struct tm *_Tm,const __time32_t *_Time); - _CRTIMP errno_t __cdecl _localtime32_s(struct tm *_Tm,const __time32_t *_Time); - _CRTIMP errno_t __cdecl _strdate_s(char *_Buf,size_t _SizeInBytes); - _CRTIMP errno_t __cdecl _strtime_s(char *_Buf ,size_t _SizeInBytes); -#if _INTEGRAL_MAX_BITS >= 64 - _CRTIMP errno_t __cdecl _ctime64_s(char *_Buf,size_t _SizeInBytes,const __time64_t *_Time); - _CRTIMP errno_t __cdecl _gmtime64_s(struct tm *_Tm,const __time64_t *_Time); - _CRTIMP errno_t __cdecl _localtime64_s(struct tm *_Tm,const __time64_t *_Time); -#endif - -#ifndef _WTIME_S_DEFINED -#define _WTIME_S_DEFINED - _CRTIMP errno_t __cdecl _wasctime_s(wchar_t *_Buf,size_t _SizeInWords,const struct tm *_Tm); - _CRTIMP errno_t __cdecl _wctime32_s(wchar_t *_Buf,size_t _SizeInWords,const __time32_t *_Time); - _CRTIMP errno_t __cdecl _wstrdate_s(wchar_t *_Buf,size_t _SizeInWords); - _CRTIMP errno_t __cdecl _wstrtime_s(wchar_t *_Buf,size_t _SizeInWords); -#if _INTEGRAL_MAX_BITS >= 64 - _CRTIMP errno_t __cdecl _wctime64_s(wchar_t *_Buf,size_t _SizeInWords,const __time64_t *_Time); -#endif - -#if !defined (RC_INVOKED) && !defined (_INC_WTIME_S_INL) -#define _INC_WTIME_S_INL -#ifdef _USE_32BIT_TIME_T -__CRT_INLINE errno_t __cdecl _wctime_s(wchar_t *_Buffer,size_t _SizeInWords,const time_t *_Time) { return _wctime32_s(_Buffer,_SizeInWords,_Time); } -#else -__CRT_INLINE errno_t __cdecl _wctime_s(wchar_t *_Buffer,size_t _SizeInWords,const time_t *_Time) { return _wctime64_s(_Buffer,_SizeInWords,_Time); } -#endif -#endif -#endif - -#ifndef RC_INVOKED -#ifdef _USE_32BIT_TIME_T -__CRT_INLINE errno_t __cdecl localtime_s(struct tm *_Tm,const time_t *_Time) { return _localtime32_s(_Tm,_Time); } -#else -__CRT_INLINE errno_t __cdecl localtime_s(struct tm *_Tm,const time_t *_Time) { return _localtime64_s(_Tm,_Time); } -#endif -#endif - -#ifdef __cplusplus -} -#endif - -#endif -#endif diff --git a/05/tcc-final-old/win32/include/sec_api/wchar_s.h b/05/tcc-final-old/win32/include/sec_api/wchar_s.h deleted file mode 100644 index 94251aa..0000000 --- a/05/tcc-final-old/win32/include/sec_api/wchar_s.h +++ /dev/null @@ -1,128 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _INC_WCHAR_S -#define _INC_WCHAR_S - -#include - -#if defined(MINGW_HAS_SECURE_API) - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _WIO_S_DEFINED -#define _WIO_S_DEFINED - _CRTIMP errno_t __cdecl _waccess_s(const wchar_t *_Filename,int _AccessMode); - _CRTIMP errno_t __cdecl _wmktemp_s(wchar_t *_TemplateName,size_t _SizeInWords); -#endif - -#ifndef _WCONIO_S_DEFINED -#define _WCONIO_S_DEFINED - _CRTIMP errno_t __cdecl _cgetws_s(wchar_t *_Buffer,size_t _SizeInWords,size_t *_SizeRead); - _CRTIMP int __cdecl _cwprintf_s(const wchar_t *_Format,...); - _CRTIMP int __cdecl _cwscanf_s(const wchar_t *_Format,...); - _CRTIMP int __cdecl _cwscanf_s_l(const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _vcwprintf_s(const wchar_t *_Format,va_list _ArgList); - _CRTIMP int __cdecl _cwprintf_s_l(const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _vcwprintf_s_l(const wchar_t *_Format,_locale_t _Locale,va_list _ArgList); -#endif - -#ifndef _WSTDIO_S_DEFINED -#define _WSTDIO_S_DEFINED - _CRTIMP wchar_t *__cdecl _getws_s(wchar_t *_Str,size_t _SizeInWords); - int __cdecl fwprintf_s(FILE *_File,const wchar_t *_Format,...); - int __cdecl wprintf_s(const wchar_t *_Format,...); - int __cdecl vfwprintf_s(FILE *_File,const wchar_t *_Format,va_list _ArgList); - int __cdecl vwprintf_s(const wchar_t *_Format,va_list _ArgList); - int __cdecl swprintf_s(wchar_t *_Dst,size_t _SizeInWords,const wchar_t *_Format,...); - int __cdecl vswprintf_s(wchar_t *_Dst,size_t _SizeInWords,const wchar_t *_Format,va_list _ArgList); - _CRTIMP int __cdecl _snwprintf_s(wchar_t *_DstBuf,size_t _DstSizeInWords,size_t _MaxCount,const wchar_t *_Format,...); - _CRTIMP int __cdecl _vsnwprintf_s(wchar_t *_DstBuf,size_t _DstSizeInWords,size_t _MaxCount,const wchar_t *_Format,va_list _ArgList); - _CRTIMP int __cdecl _wprintf_s_l(const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _vwprintf_s_l(const wchar_t *_Format,_locale_t _Locale,va_list _ArgList); - _CRTIMP int __cdecl _fwprintf_s_l(FILE *_File,const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _vfwprintf_s_l(FILE *_File,const wchar_t *_Format,_locale_t _Locale,va_list _ArgList); - _CRTIMP int __cdecl _swprintf_s_l(wchar_t *_DstBuf,size_t _DstSize,const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _vswprintf_s_l(wchar_t *_DstBuf,size_t _DstSize,const wchar_t *_Format,_locale_t _Locale,va_list _ArgList); - _CRTIMP int __cdecl _snwprintf_s_l(wchar_t *_DstBuf,size_t _DstSize,size_t _MaxCount,const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _vsnwprintf_s_l(wchar_t *_DstBuf,size_t _DstSize,size_t _MaxCount,const wchar_t *_Format,_locale_t _Locale,va_list _ArgList); - _CRTIMP int __cdecl _fwscanf_s_l(FILE *_File,const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _swscanf_s_l(const wchar_t *_Src,const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _snwscanf_s(const wchar_t *_Src,size_t _MaxCount,const wchar_t *_Format,...); - _CRTIMP int __cdecl _snwscanf_s_l(const wchar_t *_Src,size_t _MaxCount,const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _wscanf_s_l(const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP errno_t __cdecl _wfopen_s(FILE **_File,const wchar_t *_Filename,const wchar_t *_Mode); - _CRTIMP errno_t __cdecl _wfreopen_s(FILE **_File,const wchar_t *_Filename,const wchar_t *_Mode,FILE *_OldFile); - _CRTIMP errno_t __cdecl _wtmpnam_s(wchar_t *_DstBuf,size_t _SizeInWords); -#endif - -#ifndef _WSTDLIB_S_DEFINED -#define _WSTDLIB_S_DEFINED - _CRTIMP errno_t __cdecl _itow_s (int _Val,wchar_t *_DstBuf,size_t _SizeInWords,int _Radix); - _CRTIMP errno_t __cdecl _ltow_s (long _Val,wchar_t *_DstBuf,size_t _SizeInWords,int _Radix); - _CRTIMP errno_t __cdecl _ultow_s (unsigned long _Val,wchar_t *_DstBuf,size_t _SizeInWords,int _Radix); - _CRTIMP errno_t __cdecl _wgetenv_s(size_t *_ReturnSize,wchar_t *_DstBuf,size_t _DstSizeInWords,const wchar_t *_VarName); - _CRTIMP errno_t __cdecl _wdupenv_s(wchar_t **_Buffer,size_t *_BufferSizeInWords,const wchar_t *_VarName); -#if _INTEGRAL_MAX_BITS >= 64 - _CRTIMP errno_t __cdecl _i64tow_s(__int64 _Val,wchar_t *_DstBuf,size_t _SizeInWords,int _Radix); - _CRTIMP errno_t __cdecl _ui64tow_s(unsigned __int64 _Val,wchar_t *_DstBuf,size_t _SizeInWords,int _Radix); -#endif -#endif - -#ifndef _POSIX_ -#ifndef _WSTDLIBP_S_DEFINED -#define _WSTDLIBP_S_DEFINED - _CRTIMP errno_t __cdecl _wmakepath_s(wchar_t *_PathResult,size_t _SizeInWords,const wchar_t *_Drive,const wchar_t *_Dir,const wchar_t *_Filename,const wchar_t *_Ext); - _CRTIMP errno_t __cdecl _wputenv_s(const wchar_t *_Name,const wchar_t *_Value); - _CRTIMP errno_t __cdecl _wsearchenv_s(const wchar_t *_Filename,const wchar_t *_EnvVar,wchar_t *_ResultPath,size_t _SizeInWords); - _CRTIMP errno_t __cdecl _wsplitpath_s(const wchar_t *_FullPath,wchar_t *_Drive,size_t _DriveSizeInWords,wchar_t *_Dir,size_t _DirSizeInWords,wchar_t *_Filename,size_t _FilenameSizeInWords,wchar_t *_Ext,size_t _ExtSizeInWords); -#endif -#endif - -#ifndef _WSTRING_S_DEFINED -#define _WSTRING_S_DEFINED - _CRTIMP wchar_t *__cdecl wcstok_s(wchar_t *_Str,const wchar_t *_Delim,wchar_t **_Context); - _CRTIMP errno_t __cdecl _wcserror_s(wchar_t *_Buf,size_t _SizeInWords,int _ErrNum); - _CRTIMP errno_t __cdecl __wcserror_s(wchar_t *_Buffer,size_t _SizeInWords,const wchar_t *_ErrMsg); - _CRTIMP errno_t __cdecl _wcsnset_s(wchar_t *_Dst,size_t _DstSizeInWords,wchar_t _Val,size_t _MaxCount); - _CRTIMP errno_t __cdecl _wcsset_s(wchar_t *_Str,size_t _SizeInWords,wchar_t _Val); - _CRTIMP errno_t __cdecl _wcslwr_s(wchar_t *_Str,size_t _SizeInWords); - _CRTIMP errno_t __cdecl _wcslwr_s_l(wchar_t *_Str,size_t _SizeInWords,_locale_t _Locale); - _CRTIMP errno_t __cdecl _wcsupr_s(wchar_t *_Str,size_t _Size); - _CRTIMP errno_t __cdecl _wcsupr_s_l(wchar_t *_Str,size_t _Size,_locale_t _Locale); -#endif - -#ifndef _WTIME_S_DEFINED -#define _WTIME_S_DEFINED - _CRTIMP errno_t __cdecl _wasctime_s(wchar_t *_Buf,size_t _SizeInWords,const struct tm *_Tm); - _CRTIMP errno_t __cdecl _wctime32_s(wchar_t *_Buf,size_t _SizeInWords,const __time32_t *_Time); - _CRTIMP errno_t __cdecl _wstrdate_s(wchar_t *_Buf,size_t _SizeInWords); - _CRTIMP errno_t __cdecl _wstrtime_s(wchar_t *_Buf,size_t _SizeInWords); -#if _INTEGRAL_MAX_BITS >= 64 - _CRTIMP errno_t __cdecl _wctime64_s(wchar_t *_Buf,size_t _SizeInWords,const __time64_t *_Time); -#endif - -#if !defined (RC_INVOKED) && !defined (_INC_WTIME_S_INL) -#define _INC_WTIME_S_INL -#ifdef _USE_32BIT_TIME_T -__CRT_INLINE errno_t __cdecl _wctime_s(wchar_t *_Buffer,size_t _SizeInWords,const time_t *_Time) { return _wctime32_s(_Buffer,_SizeInWords,_Time); } -#else -__CRT_INLINE errno_t __cdecl _wctime_s(wchar_t *_Buffer,size_t _SizeInWords,const time_t *_Time) { return _wctime64_s(_Buffer,_SizeInWords,_Time); } -#endif -#endif -#endif - - _CRTIMP errno_t __cdecl mbsrtowcs_s(size_t *_Retval,wchar_t *_Dst,size_t _SizeInWords,const char **_PSrc,size_t _N,mbstate_t *_State); - _CRTIMP errno_t __cdecl wcrtomb_s(size_t *_Retval,char *_Dst,size_t _SizeInBytes,wchar_t _Ch,mbstate_t *_State); - _CRTIMP errno_t __cdecl wcsrtombs_s(size_t *_Retval,char *_Dst,size_t _SizeInBytes,const wchar_t **_Src,size_t _Size,mbstate_t *_State); - -#ifdef __cplusplus -} -#endif - -#endif -#endif diff --git a/05/tcc-final-old/win32/include/setjmp.h b/05/tcc-final-old/win32/include/setjmp.h deleted file mode 100644 index e4f142a..0000000 --- a/05/tcc-final-old/win32/include/setjmp.h +++ /dev/null @@ -1,160 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _INC_SETJMP -#define _INC_SETJMP - -#include <_mingw.h> - -#pragma pack(push,_CRT_PACKING) - -#ifdef __cplusplus -extern "C" { -#endif - -#if (defined(_X86_) && !defined(__x86_64)) - -#define _JBLEN 16 -#define _JBTYPE int - - typedef struct __JUMP_BUFFER { - unsigned long Ebp; - unsigned long Ebx; - unsigned long Edi; - unsigned long Esi; - unsigned long Esp; - unsigned long Eip; - unsigned long Registration; - unsigned long TryLevel; - unsigned long Cookie; - unsigned long UnwindFunc; - unsigned long UnwindData[6]; - } _JUMP_BUFFER; -#elif defined(__ia64__) - typedef _CRT_ALIGN(16) struct _SETJMP_FLOAT128 { - __int64 LowPart; - __int64 HighPart; - } SETJMP_FLOAT128; - -#define _JBLEN 33 - typedef SETJMP_FLOAT128 _JBTYPE; - - typedef struct __JUMP_BUFFER { - - unsigned long iAReserved[6]; - - unsigned long Registration; - unsigned long TryLevel; - unsigned long Cookie; - unsigned long UnwindFunc; - - unsigned long UnwindData[6]; - - SETJMP_FLOAT128 FltS0; - SETJMP_FLOAT128 FltS1; - SETJMP_FLOAT128 FltS2; - SETJMP_FLOAT128 FltS3; - SETJMP_FLOAT128 FltS4; - SETJMP_FLOAT128 FltS5; - SETJMP_FLOAT128 FltS6; - SETJMP_FLOAT128 FltS7; - SETJMP_FLOAT128 FltS8; - SETJMP_FLOAT128 FltS9; - SETJMP_FLOAT128 FltS10; - SETJMP_FLOAT128 FltS11; - SETJMP_FLOAT128 FltS12; - SETJMP_FLOAT128 FltS13; - SETJMP_FLOAT128 FltS14; - SETJMP_FLOAT128 FltS15; - SETJMP_FLOAT128 FltS16; - SETJMP_FLOAT128 FltS17; - SETJMP_FLOAT128 FltS18; - SETJMP_FLOAT128 FltS19; - __int64 FPSR; - __int64 StIIP; - __int64 BrS0; - __int64 BrS1; - __int64 BrS2; - __int64 BrS3; - __int64 BrS4; - __int64 IntS0; - __int64 IntS1; - __int64 IntS2; - __int64 IntS3; - __int64 RsBSP; - __int64 RsPFS; - __int64 ApUNAT; - __int64 ApLC; - __int64 IntSp; - __int64 IntNats; - __int64 Preds; - - } _JUMP_BUFFER; -#elif defined(__x86_64) - typedef _CRT_ALIGN(16) struct _SETJMP_FLOAT128 { - unsigned __int64 Part[2]; - } SETJMP_FLOAT128; - -#define _JBLEN 16 - typedef SETJMP_FLOAT128 _JBTYPE; - - typedef struct _JUMP_BUFFER { - unsigned __int64 Frame; - unsigned __int64 Rbx; - unsigned __int64 Rsp; - unsigned __int64 Rbp; - unsigned __int64 Rsi; - unsigned __int64 Rdi; - unsigned __int64 R12; - unsigned __int64 R13; - unsigned __int64 R14; - unsigned __int64 R15; - unsigned __int64 Rip; - unsigned __int64 Spare; - SETJMP_FLOAT128 Xmm6; - SETJMP_FLOAT128 Xmm7; - SETJMP_FLOAT128 Xmm8; - SETJMP_FLOAT128 Xmm9; - SETJMP_FLOAT128 Xmm10; - SETJMP_FLOAT128 Xmm11; - SETJMP_FLOAT128 Xmm12; - SETJMP_FLOAT128 Xmm13; - SETJMP_FLOAT128 Xmm14; - SETJMP_FLOAT128 Xmm15; - } _JUMP_BUFFER; -#endif -#ifndef _JMP_BUF_DEFINED - typedef _JBTYPE jmp_buf[_JBLEN]; -#define _JMP_BUF_DEFINED -#endif - - void * __cdecl __attribute__ ((__nothrow__)) mingw_getsp(void); - -#ifdef USE_MINGW_SETJMP_TWO_ARGS -#ifndef _INC_SETJMPEX -#define setjmp(BUF) _setjmp((BUF),mingw_getsp()) - int __cdecl __attribute__ ((__nothrow__)) _setjmp(jmp_buf _Buf,void *_Ctx); -#else -#undef setjmp -#define setjmp(BUF) _setjmpex((BUF),mingw_getsp()) -#define setjmpex(BUF) _setjmpex((BUF),mingw_getsp()) - int __cdecl __attribute__ ((__nothrow__)) _setjmpex(jmp_buf _Buf,void *_Ctx); -#endif -#else -#ifndef _INC_SETJMPEX -#define setjmp _setjmp -#endif - int __cdecl __attribute__ ((__nothrow__)) setjmp(jmp_buf _Buf); -#endif - - __declspec(noreturn) __attribute__ ((__nothrow__)) void __cdecl ms_longjmp(jmp_buf _Buf,int _Value)/* throw(...)*/; - __declspec(noreturn) __attribute__ ((__nothrow__)) void __cdecl longjmp(jmp_buf _Buf,int _Value); - -#ifdef __cplusplus -} -#endif - -#pragma pack(pop) -#endif diff --git a/05/tcc-final-old/win32/include/share.h b/05/tcc-final-old/win32/include/share.h deleted file mode 100644 index 358855f..0000000 --- a/05/tcc-final-old/win32/include/share.h +++ /dev/null @@ -1,28 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _INC_SHARE -#define _INC_SHARE - -#ifndef _WIN32 -#error Only Win32 target is supported! -#endif - -#define _SH_COMPAT 0x00 -#define _SH_DENYRW 0x10 -#define _SH_DENYWR 0x20 -#define _SH_DENYRD 0x30 -#define _SH_DENYNO 0x40 -#define _SH_SECURE 0x80 - -#ifndef NO_OLDNAMES -#define SH_COMPAT _SH_COMPAT -#define SH_DENYRW _SH_DENYRW -#define SH_DENYWR _SH_DENYWR -#define SH_DENYRD _SH_DENYRD -#define SH_DENYNO _SH_DENYNO -#endif - -#endif diff --git a/05/tcc-final-old/win32/include/signal.h b/05/tcc-final-old/win32/include/signal.h deleted file mode 100644 index a518f6b..0000000 --- a/05/tcc-final-old/win32/include/signal.h +++ /dev/null @@ -1,63 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _INC_SIGNAL -#define _INC_SIGNAL - -#include <_mingw.h> - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _SIG_ATOMIC_T_DEFINED -#define _SIG_ATOMIC_T_DEFINED - typedef int sig_atomic_t; -#endif - -#define NSIG 23 - -#define SIGHUP 1 /* hangup */ -#define SIGINT 2 -#define SIGQUIT 3 /* quit */ -#define SIGILL 4 -#define SIGTRAP 5 /* trace trap (not reset when caught) */ -#define SIGIOT 6 /* IOT instruction */ -#define SIGABRT 6 /* used by abort, replace SIGIOT in the future */ -#define SIGEMT 7 /* EMT instruction */ -#define SIGFPE 8 -#define SIGKILL 9 /* kill (cannot be caught or ignored) */ -#define SIGBUS 10 /* bus error */ -#define SIGSEGV 11 -#define SIGSYS 12 /* bad argument to system call */ -#define SIGPIPE 13 /* write on a pipe with no one to read it */ -#ifdef __USE_MINGW_ALARM -#define SIGALRM 14 /* alarm clock */ -#endif -#define SIGTERM 15 -#define SIGBREAK 21 -#define SIGABRT2 22 - -#define SIGABRT_COMPAT 6 - - typedef void (*__p_sig_fn_t)(int); - -#define SIG_DFL (__p_sig_fn_t)0 -#define SIG_IGN (__p_sig_fn_t)1 -#define SIG_GET (__p_sig_fn_t)2 -#define SIG_SGE (__p_sig_fn_t)3 -#define SIG_ACK (__p_sig_fn_t)4 -#define SIG_ERR (__p_sig_fn_t)-1 - - extern void **__cdecl __pxcptinfoptrs(void); -#define _pxcptinfoptrs (*__pxcptinfoptrs()) - - __p_sig_fn_t __cdecl signal(int _SigNum,__p_sig_fn_t _Func); - int __cdecl raise(int _SigNum); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/05/tcc-final-old/win32/include/stdint.h b/05/tcc-final-old/win32/include/stdint.h deleted file mode 100644 index cde32b6..0000000 --- a/05/tcc-final-old/win32/include/stdint.h +++ /dev/null @@ -1,212 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -/* ISO C9x 7.18 Integer types - * Based on ISO/IEC SC22/WG14 9899 Committee draft (SC22 N2794) - * - * THIS SOFTWARE IS NOT COPYRIGHTED - * - * Contributor: Danny Smith - * - * This source code is offered for use in the public domain. You may - * use, modify or distribute it freely. - * - * This code is distributed in the hope that it will be useful but - * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY - * DISCLAIMED. This includes but is not limited to warranties of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * Date: 2000-12-02 - */ - - -#ifndef _STDINT_H -#define _STDINT_H - -#include <_mingw.h> - -#define __need_wint_t -#define __need_wchar_t -#include "stddef.h" - -#ifndef __int8_t_defined -#define __int8_t_defined -/* 7.18.1.1 Exact-width integer types */ -typedef signed char int8_t; -typedef unsigned char uint8_t; -typedef short int16_t; -typedef unsigned short uint16_t; -typedef int int32_t; -typedef unsigned uint32_t; -typedef long long int64_t; -typedef unsigned long long uint64_t; -#endif - -/* 7.18.1.2 Minimum-width integer types */ -typedef signed char int_least8_t; -typedef unsigned char uint_least8_t; -typedef short int_least16_t; -typedef unsigned short uint_least16_t; -typedef int int_least32_t; -typedef unsigned uint_least32_t; -typedef long long int_least64_t; -typedef unsigned long long uint_least64_t; - -/* 7.18.1.3 Fastest minimum-width integer types - * Not actually guaranteed to be fastest for all purposes - * Here we use the exact-width types for 8 and 16-bit ints. - */ -typedef char int_fast8_t; -typedef unsigned char uint_fast8_t; -typedef short int_fast16_t; -typedef unsigned short uint_fast16_t; -typedef int int_fast32_t; -typedef unsigned int uint_fast32_t; -typedef long long int_fast64_t; -typedef unsigned long long uint_fast64_t; - -/* 7.18.1.5 Greatest-width integer types */ -typedef long long intmax_t; -typedef unsigned long long uintmax_t; - -/* 7.18.2 Limits of specified-width integer types */ -#if !defined ( __cplusplus) || defined (__STDC_LIMIT_MACROS) - -/* 7.18.2.1 Limits of exact-width integer types */ -#define INT8_MIN (-128) -#define INT16_MIN (-32768) -#define INT32_MIN (-2147483647 - 1) -#define INT64_MIN (-9223372036854775807LL - 1) - -#define INT8_MAX 127 -#define INT16_MAX 32767 -#define INT32_MAX 2147483647 -#define INT64_MAX 9223372036854775807LL - -#define UINT8_MAX 0xff /* 255U */ -#define UINT16_MAX 0xffff /* 65535U */ -#define UINT32_MAX 0xffffffff /* 4294967295U */ -#define UINT64_MAX 0xffffffffffffffffULL /* 18446744073709551615ULL */ - -/* 7.18.2.2 Limits of minimum-width integer types */ -#define INT_LEAST8_MIN INT8_MIN -#define INT_LEAST16_MIN INT16_MIN -#define INT_LEAST32_MIN INT32_MIN -#define INT_LEAST64_MIN INT64_MIN - -#define INT_LEAST8_MAX INT8_MAX -#define INT_LEAST16_MAX INT16_MAX -#define INT_LEAST32_MAX INT32_MAX -#define INT_LEAST64_MAX INT64_MAX - -#define UINT_LEAST8_MAX UINT8_MAX -#define UINT_LEAST16_MAX UINT16_MAX -#define UINT_LEAST32_MAX UINT32_MAX -#define UINT_LEAST64_MAX UINT64_MAX - -/* 7.18.2.3 Limits of fastest minimum-width integer types */ -#define INT_FAST8_MIN INT8_MIN -#define INT_FAST16_MIN INT16_MIN -#define INT_FAST32_MIN INT32_MIN -#define INT_FAST64_MIN INT64_MIN - -#define INT_FAST8_MAX INT8_MAX -#define INT_FAST16_MAX INT16_MAX -#define INT_FAST32_MAX INT32_MAX -#define INT_FAST64_MAX INT64_MAX - -#define UINT_FAST8_MAX UINT8_MAX -#define UINT_FAST16_MAX UINT16_MAX -#define UINT_FAST32_MAX UINT32_MAX -#define UINT_FAST64_MAX UINT64_MAX - -/* 7.18.2.4 Limits of integer types capable of holding - object pointers */ -#ifdef _WIN64 -#define INTPTR_MIN INT64_MIN -#define INTPTR_MAX INT64_MAX -#define UINTPTR_MAX UINT64_MAX -#else -#define INTPTR_MIN INT32_MIN -#define INTPTR_MAX INT32_MAX -#define UINTPTR_MAX UINT32_MAX -#endif - -/* 7.18.2.5 Limits of greatest-width integer types */ -#define INTMAX_MIN INT64_MIN -#define INTMAX_MAX INT64_MAX -#define UINTMAX_MAX UINT64_MAX - -/* 7.18.3 Limits of other integer types */ -#ifdef _WIN64 -#define PTRDIFF_MIN INT64_MIN -#define PTRDIFF_MAX INT64_MAX -#else -#define PTRDIFF_MIN INT32_MIN -#define PTRDIFF_MAX INT32_MAX -#endif - -#define SIG_ATOMIC_MIN INT32_MIN -#define SIG_ATOMIC_MAX INT32_MAX - -#ifndef SIZE_MAX -#ifdef _WIN64 -#define SIZE_MAX UINT64_MAX -#else -#define SIZE_MAX UINT32_MAX -#endif -#endif - -#ifndef WCHAR_MIN /* also in wchar.h */ -#define WCHAR_MIN 0 -#define WCHAR_MAX ((wchar_t)-1) /* UINT16_MAX */ -#endif - -/* - * wint_t is unsigned short for compatibility with MS runtime - */ -#define WINT_MIN 0 -#define WINT_MAX ((wint_t)-1) /* UINT16_MAX */ - -#endif /* !defined ( __cplusplus) || defined __STDC_LIMIT_MACROS */ - - -/* 7.18.4 Macros for integer constants */ -#if !defined ( __cplusplus) || defined (__STDC_CONSTANT_MACROS) - -/* 7.18.4.1 Macros for minimum-width integer constants - - According to Douglas Gwyn : - "This spec was changed in ISO/IEC 9899:1999 TC1; in ISO/IEC - 9899:1999 as initially published, the expansion was required - to be an integer constant of precisely matching type, which - is impossible to accomplish for the shorter types on most - platforms, because C99 provides no standard way to designate - an integer constant with width less than that of type int. - TC1 changed this to require just an integer constant - *expression* with *promoted* type." - - The trick used here is from Clive D W Feather. -*/ - -#define INT8_C(val) (INT_LEAST8_MAX-INT_LEAST8_MAX+(val)) -#define INT16_C(val) (INT_LEAST16_MAX-INT_LEAST16_MAX+(val)) -#define INT32_C(val) (INT_LEAST32_MAX-INT_LEAST32_MAX+(val)) -/* The 'trick' doesn't work in C89 for long long because, without - suffix, (val) will be evaluated as int, not intmax_t */ -#define INT64_C(val) val##LL - -#define UINT8_C(val) (UINT_LEAST8_MAX-UINT_LEAST8_MAX+(val)) -#define UINT16_C(val) (UINT_LEAST16_MAX-UINT_LEAST16_MAX+(val)) -#define UINT32_C(val) (UINT_LEAST32_MAX-UINT_LEAST32_MAX+(val)) -#define UINT64_C(val) val##ULL - -/* 7.18.4.2 Macros for greatest-width integer constants */ -#define INTMAX_C(val) val##LL -#define UINTMAX_C(val) val##ULL - -#endif /* !defined ( __cplusplus) || defined __STDC_CONSTANT_MACROS */ - -#endif diff --git a/05/tcc-final-old/win32/include/stdio.h b/05/tcc-final-old/win32/include/stdio.h deleted file mode 100644 index da88793..0000000 --- a/05/tcc-final-old/win32/include/stdio.h +++ /dev/null @@ -1,429 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _INC_STDIO -#define _INC_STDIO - -#include <_mingw.h> - -#pragma pack(push,_CRT_PACKING) - -#ifdef __cplusplus -extern "C" { -#endif - -#define BUFSIZ 512 -#define _NFILE _NSTREAM_ -#define _NSTREAM_ 512 -#define _IOB_ENTRIES 20 -#define EOF (-1) - -#ifndef _FILE_DEFINED - struct _iobuf { - char *_ptr; - int _cnt; - char *_base; - int _flag; - int _file; - int _charbuf; - int _bufsiz; - char *_tmpfname; - }; - typedef struct _iobuf FILE; -#define _FILE_DEFINED -#endif - -#ifdef _POSIX_ -#define _P_tmpdir "/" -#define _wP_tmpdir L"/" -#else -#define _P_tmpdir "\\" -#define _wP_tmpdir L"\\" -#endif - -#define L_tmpnam (sizeof(_P_tmpdir) + 12) - -#ifdef _POSIX_ -#define L_ctermid 9 -#define L_cuserid 32 -#endif - -#define SEEK_CUR 1 -#define SEEK_END 2 -#define SEEK_SET 0 - -#define STDIN_FILENO 0 -#define STDOUT_FILENO 1 -#define STDERR_FILENO 2 - -#define FILENAME_MAX 260 -#define FOPEN_MAX 20 -#define _SYS_OPEN 20 -#define TMP_MAX 32767 - -#ifndef NULL -#ifdef __cplusplus -#define NULL 0 -#else -#define NULL ((void *)0) -#endif -#endif - -#ifndef _OFF_T_DEFINED -#define _OFF_T_DEFINED -#ifndef _OFF_T_ -#define _OFF_T_ - typedef long _off_t; -#if !defined(NO_OLDNAMES) || defined(_POSIX) - typedef long off_t; -#endif -#endif -#endif - -#ifndef _OFF64_T_DEFINED -#define _OFF64_T_DEFINED - typedef long long _off64_t; -#if !defined(NO_OLDNAMES) || defined(_POSIX) - typedef long long off64_t; -#endif -#endif - -#ifndef _STDIO_DEFINED -#ifdef _WIN64 - _CRTIMP FILE *__cdecl __iob_func(void); -#else -#ifdef _MSVCRT_ -extern FILE _iob[]; /* A pointer to an array of FILE */ -#define __iob_func() (_iob) -#else -extern FILE (*_imp___iob)[]; /* A pointer to an array of FILE */ -#define __iob_func() (*_imp___iob) -#define _iob __iob_func() -#endif -#endif -#endif - -#ifndef _FPOS_T_DEFINED -#define _FPOS_T_DEFINED -#undef _FPOSOFF - -#if (!defined(NO_OLDNAMES) || defined(__GNUC__)) && _INTEGRAL_MAX_BITS >= 64 - typedef __int64 fpos_t; -#define _FPOSOFF(fp) ((long)(fp)) -#else - typedef long long fpos_t; -#define _FPOSOFF(fp) ((long)(fp)) -#endif - -#endif - -#ifndef _STDSTREAM_DEFINED -#define _STDSTREAM_DEFINED - -#define stdin (&__iob_func()[0]) -#define stdout (&__iob_func()[1]) -#define stderr (&__iob_func()[2]) -#endif - -#define _IOREAD 0x0001 -#define _IOWRT 0x0002 - -#define _IOFBF 0x0000 -#define _IOLBF 0x0040 -#define _IONBF 0x0004 - -#define _IOMYBUF 0x0008 -#define _IOEOF 0x0010 -#define _IOERR 0x0020 -#define _IOSTRG 0x0040 -#define _IORW 0x0080 -#ifdef _POSIX_ -#define _IOAPPEND 0x0200 -#endif - -#define _TWO_DIGIT_EXPONENT 0x1 - -#ifndef _STDIO_DEFINED - - _CRTIMP int __cdecl _filbuf(FILE *_File); - _CRTIMP int __cdecl _flsbuf(int _Ch,FILE *_File); -#ifdef _POSIX_ - _CRTIMP FILE *__cdecl _fsopen(const char *_Filename,const char *_Mode); -#else - _CRTIMP FILE *__cdecl _fsopen(const char *_Filename,const char *_Mode,int _ShFlag); -#endif - void __cdecl clearerr(FILE *_File); - int __cdecl fclose(FILE *_File); - _CRTIMP int __cdecl _fcloseall(void); -#ifdef _POSIX_ - FILE *__cdecl fdopen(int _FileHandle,const char *_Mode); -#else - _CRTIMP FILE *__cdecl _fdopen(int _FileHandle,const char *_Mode); -#endif - int __cdecl feof(FILE *_File); - int __cdecl ferror(FILE *_File); - int __cdecl fflush(FILE *_File); - int __cdecl fgetc(FILE *_File); - _CRTIMP int __cdecl _fgetchar(void); - int __cdecl fgetpos(FILE *_File ,fpos_t *_Pos); - char *__cdecl fgets(char *_Buf,int _MaxCount,FILE *_File); -#ifdef _POSIX_ - int __cdecl fileno(FILE *_File); -#else - _CRTIMP int __cdecl _fileno(FILE *_File); -#endif - _CRTIMP char *__cdecl _tempnam(const char *_DirName,const char *_FilePrefix); - _CRTIMP int __cdecl _flushall(void); - FILE *__cdecl fopen(const char *_Filename,const char *_Mode); - FILE *fopen64(const char *filename,const char *mode); - int __cdecl fprintf(FILE *_File,const char *_Format,...); - int __cdecl fputc(int _Ch,FILE *_File); - _CRTIMP int __cdecl _fputchar(int _Ch); - int __cdecl fputs(const char *_Str,FILE *_File); - size_t __cdecl fread(void *_DstBuf,size_t _ElementSize,size_t _Count,FILE *_File); - FILE *__cdecl freopen(const char *_Filename,const char *_Mode,FILE *_File); - int __cdecl fscanf(FILE *_File,const char *_Format,...); - int __cdecl fsetpos(FILE *_File,const fpos_t *_Pos); - int __cdecl fseek(FILE *_File,long _Offset,int _Origin); - int fseeko64(FILE* stream, _off64_t offset, int whence); - long __cdecl ftell(FILE *_File); - _off64_t ftello64(FILE * stream); - int __cdecl _fseeki64(FILE *_File,__int64 _Offset,int _Origin); - __int64 __cdecl _ftelli64(FILE *_File); - size_t __cdecl fwrite(const void *_Str,size_t _Size,size_t _Count,FILE *_File); - int __cdecl getc(FILE *_File); - int __cdecl getchar(void); - _CRTIMP int __cdecl _getmaxstdio(void); - char *__cdecl gets(char *_Buffer); - int __cdecl _getw(FILE *_File); -#ifndef _CRT_PERROR_DEFINED -#define _CRT_PERROR_DEFINED - void __cdecl perror(const char *_ErrMsg); -#endif - _CRTIMP int __cdecl _pclose(FILE *_File); - _CRTIMP FILE *__cdecl _popen(const char *_Command,const char *_Mode); -#if !defined(NO_OLDNAMES) && !defined(popen) -#define popen _popen -#define pclose _pclose -#endif - int __cdecl printf(const char *_Format,...); - int __cdecl putc(int _Ch,FILE *_File); - int __cdecl putchar(int _Ch); - int __cdecl puts(const char *_Str); - _CRTIMP int __cdecl _putw(int _Word,FILE *_File); -#ifndef _CRT_DIRECTORY_DEFINED -#define _CRT_DIRECTORY_DEFINED - int __cdecl remove(const char *_Filename); - int __cdecl rename(const char *_OldFilename,const char *_NewFilename); - _CRTIMP int __cdecl _unlink(const char *_Filename); -#ifndef NO_OLDNAMES - int __cdecl unlink(const char *_Filename); -#endif -#endif - void __cdecl rewind(FILE *_File); - _CRTIMP int __cdecl _rmtmp(void); - int __cdecl scanf(const char *_Format,...); - void __cdecl setbuf(FILE *_File,char *_Buffer); - _CRTIMP int __cdecl _setmaxstdio(int _Max); - _CRTIMP unsigned int __cdecl _set_output_format(unsigned int _Format); - _CRTIMP unsigned int __cdecl _get_output_format(void); - int __cdecl setvbuf(FILE *_File,char *_Buf,int _Mode,size_t _Size); - _CRTIMP int __cdecl _scprintf(const char *_Format,...); - int __cdecl sscanf(const char *_Src,const char *_Format,...); - _CRTIMP int __cdecl _snscanf(const char *_Src,size_t _MaxCount,const char *_Format,...); - FILE *__cdecl tmpfile(void); - char *__cdecl tmpnam(char *_Buffer); - int __cdecl ungetc(int _Ch,FILE *_File); - int __cdecl vfprintf(FILE *_File,const char *_Format,va_list _ArgList); - int __cdecl vprintf(const char *_Format,va_list _ArgList); - /* Make sure macros are not defined. */ -#pragma push_macro("vsnprintf") -#pragma push_macro("snprintf") -# undef vsnprintf -# undef snprintf - extern - __attribute__((format(gnu_printf, 3, 0))) __attribute__((nonnull (3))) - int __mingw_vsnprintf(char *_DstBuf,size_t _MaxCount,const char *_Format,va_list _ArgList); - extern - __attribute__((format(gnu_printf, 3, 4))) __attribute__((nonnull (3))) - int __mingw_snprintf(char* s, size_t n, const char* format, ...); - int __cdecl vsnprintf(char *_DstBuf,size_t _MaxCount,const char *_Format,va_list _ArgList); - _CRTIMP int __cdecl _snprintf(char *_Dest,size_t _Count,const char *_Format,...); - _CRTIMP int __cdecl _vsnprintf(char *_Dest,size_t _Count,const char *_Format,va_list _Args); - int __cdecl sprintf(char *_Dest,const char *_Format,...); - int __cdecl vsprintf(char *_Dest,const char *_Format,va_list _Args); -#ifndef __NO_ISOCEXT /* externs in libmingwex.a */ - int __cdecl snprintf(char* s, size_t n, const char* format, ...); - __CRT_INLINE int __cdecl vsnprintf (char* s, size_t n, const char* format,va_list arg) { - return _vsnprintf ( s, n, format, arg); - } - int __cdecl vscanf(const char * Format, va_list argp); - int __cdecl vfscanf (FILE * fp, const char * Format,va_list argp); - int __cdecl vsscanf (const char * _Str,const char * Format,va_list argp); -#endif -/* Restore may prior defined macros snprintf/vsnprintf. */ -#pragma pop_macro("snprintf") -#pragma pop_macro("vsnprintf") -/* Check if vsnprintf and snprintf are defaulting to gnu-style. */ -# if defined(USE_MINGW_GNU_SNPRINTF) && USE_MINGW_GNU_SNPRINTF -# ifndef vsnprint -# define vsnprintf __mingw_vsnprintf -# endif -# ifndef snprintf -# define snprintf __mingw_snprintf -# endif -# endif - _CRTIMP int __cdecl _vscprintf(const char *_Format,va_list _ArgList); - _CRTIMP int __cdecl _set_printf_count_output(int _Value); - _CRTIMP int __cdecl _get_printf_count_output(void); - -#ifndef _WSTDIO_DEFINED - -#ifndef WEOF -#define WEOF (wint_t)(0xFFFF) -#endif - -#ifdef _POSIX_ - _CRTIMP FILE *__cdecl _wfsopen(const wchar_t *_Filename,const wchar_t *_Mode); -#else - _CRTIMP FILE *__cdecl _wfsopen(const wchar_t *_Filename,const wchar_t *_Mode,int _ShFlag); -#endif - wint_t __cdecl fgetwc(FILE *_File); - _CRTIMP wint_t __cdecl _fgetwchar(void); - wint_t __cdecl fputwc(wchar_t _Ch,FILE *_File); - _CRTIMP wint_t __cdecl _fputwchar(wchar_t _Ch); - wint_t __cdecl getwc(FILE *_File); - wint_t __cdecl getwchar(void); - wint_t __cdecl putwc(wchar_t _Ch,FILE *_File); - wint_t __cdecl putwchar(wchar_t _Ch); - wint_t __cdecl ungetwc(wint_t _Ch,FILE *_File); - wchar_t *__cdecl fgetws(wchar_t *_Dst,int _SizeInWords,FILE *_File); - int __cdecl fputws(const wchar_t *_Str,FILE *_File); - _CRTIMP wchar_t *__cdecl _getws(wchar_t *_String); - _CRTIMP int __cdecl _putws(const wchar_t *_Str); - int __cdecl fwprintf(FILE *_File,const wchar_t *_Format,...); - int __cdecl wprintf(const wchar_t *_Format,...); - _CRTIMP int __cdecl _scwprintf(const wchar_t *_Format,...); - int __cdecl vfwprintf(FILE *_File,const wchar_t *_Format,va_list _ArgList); - int __cdecl vwprintf(const wchar_t *_Format,va_list _ArgList); - _CRTIMP int __cdecl swprintf(wchar_t*, const wchar_t*, ...); - _CRTIMP int __cdecl vswprintf(wchar_t*, const wchar_t*,va_list); - _CRTIMP int __cdecl _swprintf_c(wchar_t *_DstBuf,size_t _SizeInWords,const wchar_t *_Format,...); - _CRTIMP int __cdecl _vswprintf_c(wchar_t *_DstBuf,size_t _SizeInWords,const wchar_t *_Format,va_list _ArgList); - _CRTIMP int __cdecl _snwprintf(wchar_t *_Dest,size_t _Count,const wchar_t *_Format,...); - _CRTIMP int __cdecl _vsnwprintf(wchar_t *_Dest,size_t _Count,const wchar_t *_Format,va_list _Args); -#ifndef __NO_ISOCEXT /* externs in libmingwex.a */ - int __cdecl snwprintf (wchar_t* s, size_t n, const wchar_t* format, ...); - __CRT_INLINE int __cdecl vsnwprintf (wchar_t* s, size_t n, const wchar_t* format, va_list arg) { return _vsnwprintf(s,n,format,arg); } - int __cdecl vwscanf (const wchar_t *, va_list); - int __cdecl vfwscanf (FILE *,const wchar_t *,va_list); - int __cdecl vswscanf (const wchar_t *,const wchar_t *,va_list); -#endif - _CRTIMP int __cdecl _swprintf(wchar_t *_Dest,const wchar_t *_Format,...); - _CRTIMP int __cdecl _vswprintf(wchar_t *_Dest,const wchar_t *_Format,va_list _Args); - -#ifndef RC_INVOKED -#include -#endif - -#ifdef _CRT_NON_CONFORMING_SWPRINTFS -#ifndef __cplusplus -#define swprintf _swprintf -#define vswprintf _vswprintf -#define _swprintf_l __swprintf_l -#define _vswprintf_l __vswprintf_l -#endif -#endif - - _CRTIMP wchar_t *__cdecl _wtempnam(const wchar_t *_Directory,const wchar_t *_FilePrefix); - _CRTIMP int __cdecl _vscwprintf(const wchar_t *_Format,va_list _ArgList); - int __cdecl fwscanf(FILE *_File,const wchar_t *_Format,...); - int __cdecl swscanf(const wchar_t *_Src,const wchar_t *_Format,...); - _CRTIMP int __cdecl _snwscanf(const wchar_t *_Src,size_t _MaxCount,const wchar_t *_Format,...); - int __cdecl wscanf(const wchar_t *_Format,...); - _CRTIMP FILE *__cdecl _wfdopen(int _FileHandle ,const wchar_t *_Mode); - _CRTIMP FILE *__cdecl _wfopen(const wchar_t *_Filename,const wchar_t *_Mode); - _CRTIMP FILE *__cdecl _wfreopen(const wchar_t *_Filename,const wchar_t *_Mode,FILE *_OldFile); -#ifndef _CRT_WPERROR_DEFINED -#define _CRT_WPERROR_DEFINED - _CRTIMP void __cdecl _wperror(const wchar_t *_ErrMsg); -#endif - _CRTIMP FILE *__cdecl _wpopen(const wchar_t *_Command,const wchar_t *_Mode); -#if !defined(NO_OLDNAMES) && !defined(wpopen) -#define wpopen _wpopen -#endif - _CRTIMP int __cdecl _wremove(const wchar_t *_Filename); - _CRTIMP wchar_t *__cdecl _wtmpnam(wchar_t *_Buffer); - _CRTIMP wint_t __cdecl _fgetwc_nolock(FILE *_File); - _CRTIMP wint_t __cdecl _fputwc_nolock(wchar_t _Ch,FILE *_File); - _CRTIMP wint_t __cdecl _ungetwc_nolock(wint_t _Ch,FILE *_File); - -#undef _CRT_GETPUTWCHAR_NOINLINE - -#if !defined(__cplusplus) || defined(_CRT_GETPUTWCHAR_NOINLINE) -#define getwchar() fgetwc(stdin) -#define putwchar(_c) fputwc((_c),stdout) -#else - __CRT_INLINE wint_t __cdecl getwchar() { return (fgetwc(stdin)); } - __CRT_INLINE wint_t __cdecl putwchar(wchar_t _C) { return (fputwc(_C,stdout)); } -#endif - -#define getwc(_stm) fgetwc(_stm) -#define putwc(_c,_stm) fputwc(_c,_stm) -#define _putwc_nolock(_c,_stm) _fputwc_nolock(_c,_stm) -#define _getwc_nolock(_stm) _fgetwc_nolock(_stm) - -#define _WSTDIO_DEFINED -#endif - -#define _STDIO_DEFINED -#endif - -#define _fgetc_nolock(_stream) (--(_stream)->_cnt >= 0 ? 0xff & *(_stream)->_ptr++ : _filbuf(_stream)) -#define _fputc_nolock(_c,_stream) (--(_stream)->_cnt >= 0 ? 0xff & (*(_stream)->_ptr++ = (char)(_c)) : _flsbuf((_c),(_stream))) -#define _getc_nolock(_stream) _fgetc_nolock(_stream) -#define _putc_nolock(_c,_stream) _fputc_nolock(_c,_stream) -#define _getchar_nolock() _getc_nolock(stdin) -#define _putchar_nolock(_c) _putc_nolock((_c),stdout) -#define _getwchar_nolock() _getwc_nolock(stdin) -#define _putwchar_nolock(_c) _putwc_nolock((_c),stdout) - - _CRTIMP void __cdecl _lock_file(FILE *_File); - _CRTIMP void __cdecl _unlock_file(FILE *_File); - _CRTIMP int __cdecl _fclose_nolock(FILE *_File); - _CRTIMP int __cdecl _fflush_nolock(FILE *_File); - _CRTIMP size_t __cdecl _fread_nolock(void *_DstBuf,size_t _ElementSize,size_t _Count,FILE *_File); - _CRTIMP int __cdecl _fseek_nolock(FILE *_File,long _Offset,int _Origin); - _CRTIMP long __cdecl _ftell_nolock(FILE *_File); - _CRTIMP int __cdecl _fseeki64_nolock(FILE *_File,__int64 _Offset,int _Origin); - _CRTIMP __int64 __cdecl _ftelli64_nolock(FILE *_File); - _CRTIMP size_t __cdecl _fwrite_nolock(const void *_DstBuf,size_t _Size,size_t _Count,FILE *_File); - _CRTIMP int __cdecl _ungetc_nolock(int _Ch,FILE *_File); - -#if !defined(NO_OLDNAMES) || !defined(_POSIX) -#define P_tmpdir _P_tmpdir -#define SYS_OPEN _SYS_OPEN - - char *__cdecl tempnam(const char *_Directory,const char *_FilePrefix); - int __cdecl fcloseall(void); - FILE *__cdecl fdopen(int _FileHandle,const char *_Format); - int __cdecl fgetchar(void); - int __cdecl fileno(FILE *_File); - int __cdecl flushall(void); - int __cdecl fputchar(int _Ch); - int __cdecl getw(FILE *_File); - int __cdecl putw(int _Ch,FILE *_File); - int __cdecl rmtmp(void); -#endif - -#ifdef __cplusplus -} -#endif - -#pragma pack(pop) - -#include - -#endif diff --git a/05/tcc-final-old/win32/include/stdlib.h b/05/tcc-final-old/win32/include/stdlib.h deleted file mode 100644 index 96765b2..0000000 --- a/05/tcc-final-old/win32/include/stdlib.h +++ /dev/null @@ -1,580 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _INC_STDLIB -#define _INC_STDLIB - -#include <_mingw.h> -#include - -#pragma pack(push,_CRT_PACKING) - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef NULL -#ifdef __cplusplus -#define NULL 0 -#else -#define NULL ((void *)0) -#endif -#endif - -#define EXIT_SUCCESS 0 -#define EXIT_FAILURE 1 - -#ifndef _ONEXIT_T_DEFINED -#define _ONEXIT_T_DEFINED - - typedef int (__cdecl *_onexit_t)(void); - -#ifndef NO_OLDNAMES -#define onexit_t _onexit_t -#endif -#endif - -#ifndef _DIV_T_DEFINED -#define _DIV_T_DEFINED - - typedef struct _div_t { - int quot; - int rem; - } div_t; - - typedef struct _ldiv_t { - long quot; - long rem; - } ldiv_t; -#endif - -#ifndef _CRT_DOUBLE_DEC -#define _CRT_DOUBLE_DEC - -#pragma pack(4) - typedef struct { - unsigned char ld[10]; - } _LDOUBLE; -#pragma pack() - -#define _PTR_LD(x) ((unsigned char *)(&(x)->ld)) - - typedef struct { - double x; - } _CRT_DOUBLE; - - typedef struct { - float f; - } _CRT_FLOAT; - -#pragma push_macro("long") -#undef long - - typedef struct { - long double x; - } _LONGDOUBLE; - -#pragma pop_macro("long") - -#pragma pack(4) - typedef struct { - unsigned char ld12[12]; - } _LDBL12; -#pragma pack() -#endif - -#define RAND_MAX 0x7fff - -#ifndef MB_CUR_MAX -#define MB_CUR_MAX ___mb_cur_max_func() -#ifndef __mb_cur_max -#ifdef _MSVCRT_ - extern int __mb_cur_max; -#else -#define __mb_cur_max (*_imp____mb_cur_max) - extern int *_imp____mb_cur_max; -#endif -#endif -#ifdef _MSVCRT_ - extern int __mbcur_max; -#define ___mb_cur_max_func() (__mb_cur_max) -#else - extern int* _imp____mbcur_max; -#define ___mb_cur_max_func() (*_imp____mb_cur_max) -#endif -#endif - -#define __max(a,b) (((a) > (b)) ? (a) : (b)) -#define __min(a,b) (((a) < (b)) ? (a) : (b)) - -#define _MAX_PATH 260 -#define _MAX_DRIVE 3 -#define _MAX_DIR 256 -#define _MAX_FNAME 256 -#define _MAX_EXT 256 - -#define _OUT_TO_DEFAULT 0 -#define _OUT_TO_STDERR 1 -#define _OUT_TO_MSGBOX 2 -#define _REPORT_ERRMODE 3 - -#define _WRITE_ABORT_MSG 0x1 -#define _CALL_REPORTFAULT 0x2 - -#define _MAX_ENV 32767 - - typedef void (__cdecl *_purecall_handler)(void); - - _CRTIMP _purecall_handler __cdecl _set_purecall_handler(_purecall_handler _Handler); - _CRTIMP _purecall_handler __cdecl _get_purecall_handler(void); - - typedef void (__cdecl *_invalid_parameter_handler)(const wchar_t *,const wchar_t *,const wchar_t *,unsigned int,uintptr_t); - _invalid_parameter_handler __cdecl _set_invalid_parameter_handler(_invalid_parameter_handler _Handler); - _invalid_parameter_handler __cdecl _get_invalid_parameter_handler(void); - -#ifndef _CRT_ERRNO_DEFINED -#define _CRT_ERRNO_DEFINED - _CRTIMP extern int *__cdecl _errno(void); -#define errno (*_errno()) - errno_t __cdecl _set_errno(int _Value); - errno_t __cdecl _get_errno(int *_Value); -#endif - _CRTIMP unsigned long *__cdecl __doserrno(void); -#define _doserrno (*__doserrno()) - errno_t __cdecl _set_doserrno(unsigned long _Value); - errno_t __cdecl _get_doserrno(unsigned long *_Value); -#ifdef _MSVCRT_ - extern char *_sys_errlist[]; - extern int _sys_nerr; -#else - _CRTIMP char *_sys_errlist[1]; - _CRTIMP int _sys_nerr; -#endif -#if (defined(_X86_) && !defined(__x86_64)) - _CRTIMP int *__cdecl __p___argc(void); - _CRTIMP char ***__cdecl __p___argv(void); - _CRTIMP wchar_t ***__cdecl __p___wargv(void); - _CRTIMP char ***__cdecl __p__environ(void); - _CRTIMP wchar_t ***__cdecl __p__wenviron(void); - _CRTIMP char **__cdecl __p__pgmptr(void); - _CRTIMP wchar_t **__cdecl __p__wpgmptr(void); -#endif -#ifndef __argc -#ifdef _MSVCRT_ - extern int __argc; -#else -#define __argc (*_imp____argc) - extern int *_imp____argc; -#endif -#endif -#ifndef __argv -#ifdef _MSVCRT_ - extern char **__argv; -#else -#define __argv (*_imp____argv) - extern char ***_imp____argv; -#endif -#endif -#ifndef __wargv -#ifdef _MSVCRT_ - extern wchar_t **__wargv; -#else -#define __wargv (*_imp____wargv) - extern wchar_t ***_imp____wargv; -#endif -#endif - -#ifdef _POSIX_ - extern char **environ; -#else -#ifndef _environ -#ifdef _MSVCRT_ - extern char **_environ; -#else -#define _environ (*_imp___environ) - extern char ***_imp___environ; -#endif -#endif - -#ifndef _wenviron -#ifdef _MSVCRT_ - extern wchar_t **_wenviron; -#else -#define _wenviron (*_imp___wenviron) - extern wchar_t ***_imp___wenviron; -#endif -#endif -#endif -#ifndef _pgmptr -#ifdef _MSVCRT_ - extern char *_pgmptr; -#else -#define _pgmptr (*_imp___pgmptr) - extern char **_imp___pgmptr; -#endif -#endif - -#ifndef _wpgmptr -#ifdef _MSVCRT_ - extern wchar_t *_wpgmptr; -#else -#define _wpgmptr (*_imp___wpgmptr) - extern wchar_t **_imp___wpgmptr; -#endif -#endif - errno_t __cdecl _get_pgmptr(char **_Value); - errno_t __cdecl _get_wpgmptr(wchar_t **_Value); -#ifndef _fmode -#ifdef _MSVCRT_ - extern int _fmode; -#else -#define _fmode (*_imp___fmode) - extern int *_imp___fmode; -#endif -#endif - _CRTIMP errno_t __cdecl _set_fmode(int _Mode); - _CRTIMP errno_t __cdecl _get_fmode(int *_PMode); - -#ifndef _osplatform -#ifdef _MSVCRT_ - extern unsigned int _osplatform; -#else -#define _osplatform (*_imp___osplatform) - extern unsigned int *_imp___osplatform; -#endif -#endif - -#ifndef _osver -#ifdef _MSVCRT_ - extern unsigned int _osver; -#else -#define _osver (*_imp___osver) - extern unsigned int *_imp___osver; -#endif -#endif - -#ifndef _winver -#ifdef _MSVCRT_ - extern unsigned int _winver; -#else -#define _winver (*_imp___winver) - extern unsigned int *_imp___winver; -#endif -#endif - -#ifndef _winmajor -#ifdef _MSVCRT_ - extern unsigned int _winmajor; -#else -#define _winmajor (*_imp___winmajor) - extern unsigned int *_imp___winmajor; -#endif -#endif - -#ifndef _winminor -#ifdef _MSVCRT_ - extern unsigned int _winminor; -#else -#define _winminor (*_imp___winminor) - extern unsigned int *_imp___winminor; -#endif -#endif - - errno_t __cdecl _get_osplatform(unsigned int *_Value); - errno_t __cdecl _get_osver(unsigned int *_Value); - errno_t __cdecl _get_winver(unsigned int *_Value); - errno_t __cdecl _get_winmajor(unsigned int *_Value); - errno_t __cdecl _get_winminor(unsigned int *_Value); -#ifndef _countof -#ifndef __cplusplus -#define _countof(_Array) (sizeof(_Array) / sizeof(_Array[0])) -#else - extern "C++" { - template char (*__countof_helper(UNALIGNED _CountofType (&_Array)[_SizeOfArray]))[_SizeOfArray]; -#define _countof(_Array) sizeof(*__countof_helper(_Array)) - } -#endif -#endif - -#ifndef _CRT_TERMINATE_DEFINED -#define _CRT_TERMINATE_DEFINED - void __cdecl __MINGW_NOTHROW exit(int _Code) __MINGW_ATTRIB_NORETURN; - _CRTIMP void __cdecl __MINGW_NOTHROW _exit(int _Code) __MINGW_ATTRIB_NORETURN; -#if !defined __NO_ISOCEXT /* extern stub in static libmingwex.a */ - /* C99 function name */ - void __cdecl _Exit(int) __MINGW_ATTRIB_NORETURN; - __CRT_INLINE __MINGW_ATTRIB_NORETURN void __cdecl _Exit(int status) - { _exit(status); } -#endif - -#pragma push_macro("abort") -#undef abort - void __cdecl __declspec(noreturn) abort(void); -#pragma pop_macro("abort") - -#endif - - _CRTIMP unsigned int __cdecl _set_abort_behavior(unsigned int _Flags,unsigned int _Mask); - -#ifndef _CRT_ABS_DEFINED -#define _CRT_ABS_DEFINED - int __cdecl abs(int _X); - long __cdecl labs(long _X); -#endif - -#if _INTEGRAL_MAX_BITS >= 64 - __int64 __cdecl _abs64(__int64); -#endif - int __cdecl atexit(void (__cdecl *)(void)); -#ifndef _CRT_ATOF_DEFINED -#define _CRT_ATOF_DEFINED - double __cdecl atof(const char *_String); - double __cdecl _atof_l(const char *_String,_locale_t _Locale); -#endif - int __cdecl atoi(const char *_Str); - _CRTIMP int __cdecl _atoi_l(const char *_Str,_locale_t _Locale); - long __cdecl atol(const char *_Str); - _CRTIMP long __cdecl _atol_l(const char *_Str,_locale_t _Locale); -#ifndef _CRT_ALGO_DEFINED -#define _CRT_ALGO_DEFINED - void *__cdecl bsearch(const void *_Key,const void *_Base,size_t _NumOfElements,size_t _SizeOfElements,int (__cdecl *_PtFuncCompare)(const void *,const void *)); - void __cdecl qsort(void *_Base,size_t _NumOfElements,size_t _SizeOfElements,int (__cdecl *_PtFuncCompare)(const void *,const void *)); -#endif - unsigned short __cdecl _byteswap_ushort(unsigned short _Short); - /*unsigned long __cdecl _byteswap_ulong (unsigned long _Long); */ -#if _INTEGRAL_MAX_BITS >= 64 - unsigned __int64 __cdecl _byteswap_uint64(unsigned __int64 _Int64); -#endif - div_t __cdecl div(int _Numerator,int _Denominator); - char *__cdecl getenv(const char *_VarName); - _CRTIMP char *__cdecl _itoa(int _Value,char *_Dest,int _Radix); -#if _INTEGRAL_MAX_BITS >= 64 - _CRTIMP char *__cdecl _i64toa(__int64 _Val,char *_DstBuf,int _Radix); - _CRTIMP char *__cdecl _ui64toa(unsigned __int64 _Val,char *_DstBuf,int _Radix); - _CRTIMP __int64 __cdecl _atoi64(const char *_String); - _CRTIMP __int64 __cdecl _atoi64_l(const char *_String,_locale_t _Locale); - _CRTIMP __int64 __cdecl _strtoi64(const char *_String,char **_EndPtr,int _Radix); - _CRTIMP __int64 __cdecl _strtoi64_l(const char *_String,char **_EndPtr,int _Radix,_locale_t _Locale); - _CRTIMP unsigned __int64 __cdecl _strtoui64(const char *_String,char **_EndPtr,int _Radix); - _CRTIMP unsigned __int64 __cdecl _strtoui64_l(const char *_String,char **_EndPtr,int _Radix,_locale_t _Locale); -#endif - ldiv_t __cdecl ldiv(long _Numerator,long _Denominator); - _CRTIMP char *__cdecl _ltoa(long _Value,char *_Dest,int _Radix); - int __cdecl mblen(const char *_Ch,size_t _MaxCount); - _CRTIMP int __cdecl _mblen_l(const char *_Ch,size_t _MaxCount,_locale_t _Locale); - _CRTIMP size_t __cdecl _mbstrlen(const char *_Str); - _CRTIMP size_t __cdecl _mbstrlen_l(const char *_Str,_locale_t _Locale); - _CRTIMP size_t __cdecl _mbstrnlen(const char *_Str,size_t _MaxCount); - _CRTIMP size_t __cdecl _mbstrnlen_l(const char *_Str,size_t _MaxCount,_locale_t _Locale); - int __cdecl mbtowc(wchar_t *_DstCh,const char *_SrcCh,size_t _SrcSizeInBytes); - _CRTIMP int __cdecl _mbtowc_l(wchar_t *_DstCh,const char *_SrcCh,size_t _SrcSizeInBytes,_locale_t _Locale); - size_t __cdecl mbstowcs(wchar_t *_Dest,const char *_Source,size_t _MaxCount); - _CRTIMP size_t __cdecl _mbstowcs_l(wchar_t *_Dest,const char *_Source,size_t _MaxCount,_locale_t _Locale); - int __cdecl rand(void); - _CRTIMP int __cdecl _set_error_mode(int _Mode); - void __cdecl srand(unsigned int _Seed); - double __cdecl strtod(const char *_Str,char **_EndPtr); - float __cdecl strtof(const char *nptr, char **endptr); -#if !defined __NO_ISOCEXT /* in libmingwex.a */ - float __cdecl strtof (const char * __restrict__, char ** __restrict__); - long double __cdecl strtold(const char * __restrict__, char ** __restrict__); -#endif /* __NO_ISOCEXT */ - _CRTIMP double __cdecl _strtod_l(const char *_Str,char **_EndPtr,_locale_t _Locale); - long __cdecl strtol(const char *_Str,char **_EndPtr,int _Radix); - _CRTIMP long __cdecl _strtol_l(const char *_Str,char **_EndPtr,int _Radix,_locale_t _Locale); - unsigned long __cdecl strtoul(const char *_Str,char **_EndPtr,int _Radix); - _CRTIMP unsigned long __cdecl _strtoul_l(const char *_Str,char **_EndPtr,int _Radix,_locale_t _Locale); -#ifndef _CRT_SYSTEM_DEFINED -#define _CRT_SYSTEM_DEFINED - int __cdecl system(const char *_Command); -#endif - _CRTIMP char *__cdecl _ultoa(unsigned long _Value,char *_Dest,int _Radix); - int __cdecl wctomb(char *_MbCh,wchar_t _WCh); - _CRTIMP int __cdecl _wctomb_l(char *_MbCh,wchar_t _WCh,_locale_t _Locale); - size_t __cdecl wcstombs(char *_Dest,const wchar_t *_Source,size_t _MaxCount); - _CRTIMP size_t __cdecl _wcstombs_l(char *_Dest,const wchar_t *_Source,size_t _MaxCount,_locale_t _Locale); - -#ifndef _CRT_ALLOCATION_DEFINED -#define _CRT_ALLOCATION_DEFINED - void *__cdecl calloc(size_t _NumOfElements,size_t _SizeOfElements); - void __cdecl free(void *_Memory); - void *__cdecl malloc(size_t _Size); - void *__cdecl realloc(void *_Memory,size_t _NewSize); - _CRTIMP void *__cdecl _recalloc(void *_Memory,size_t _Count,size_t _Size); - //_CRTIMP void __cdecl _aligned_free(void *_Memory); - //_CRTIMP void *__cdecl _aligned_malloc(size_t _Size,size_t _Alignment); - _CRTIMP void *__cdecl _aligned_offset_malloc(size_t _Size,size_t _Alignment,size_t _Offset); - _CRTIMP void *__cdecl _aligned_realloc(void *_Memory,size_t _Size,size_t _Alignment); - _CRTIMP void *__cdecl _aligned_recalloc(void *_Memory,size_t _Count,size_t _Size,size_t _Alignment); - _CRTIMP void *__cdecl _aligned_offset_realloc(void *_Memory,size_t _Size,size_t _Alignment,size_t _Offset); - _CRTIMP void *__cdecl _aligned_offset_recalloc(void *_Memory,size_t _Count,size_t _Size,size_t _Alignment,size_t _Offset); -#endif - -#ifndef _WSTDLIB_DEFINED -#define _WSTDLIB_DEFINED - - _CRTIMP wchar_t *__cdecl _itow(int _Value,wchar_t *_Dest,int _Radix); - _CRTIMP wchar_t *__cdecl _ltow(long _Value,wchar_t *_Dest,int _Radix); - _CRTIMP wchar_t *__cdecl _ultow(unsigned long _Value,wchar_t *_Dest,int _Radix); - double __cdecl wcstod(const wchar_t *_Str,wchar_t **_EndPtr); - float __cdecl wcstof(const wchar_t *nptr, wchar_t **endptr); -#if !defined __NO_ISOCEXT /* in libmingwex.a */ - float __cdecl wcstof( const wchar_t * __restrict__, wchar_t ** __restrict__); - long double __cdecl wcstold(const wchar_t * __restrict__, wchar_t ** __restrict__); -#endif /* __NO_ISOCEXT */ - _CRTIMP double __cdecl _wcstod_l(const wchar_t *_Str,wchar_t **_EndPtr,_locale_t _Locale); - long __cdecl wcstol(const wchar_t *_Str,wchar_t **_EndPtr,int _Radix); - _CRTIMP long __cdecl _wcstol_l(const wchar_t *_Str,wchar_t **_EndPtr,int _Radix,_locale_t _Locale); - unsigned long __cdecl wcstoul(const wchar_t *_Str,wchar_t **_EndPtr,int _Radix); - _CRTIMP unsigned long __cdecl _wcstoul_l(const wchar_t *_Str,wchar_t **_EndPtr,int _Radix,_locale_t _Locale); - _CRTIMP wchar_t *__cdecl _wgetenv(const wchar_t *_VarName); -#ifndef _CRT_WSYSTEM_DEFINED -#define _CRT_WSYSTEM_DEFINED - _CRTIMP int __cdecl _wsystem(const wchar_t *_Command); -#endif - _CRTIMP double __cdecl _wtof(const wchar_t *_Str); - _CRTIMP double __cdecl _wtof_l(const wchar_t *_Str,_locale_t _Locale); - _CRTIMP int __cdecl _wtoi(const wchar_t *_Str); - _CRTIMP int __cdecl _wtoi_l(const wchar_t *_Str,_locale_t _Locale); - _CRTIMP long __cdecl _wtol(const wchar_t *_Str); - _CRTIMP long __cdecl _wtol_l(const wchar_t *_Str,_locale_t _Locale); - -#if _INTEGRAL_MAX_BITS >= 64 - _CRTIMP wchar_t *__cdecl _i64tow(__int64 _Val,wchar_t *_DstBuf,int _Radix); - _CRTIMP wchar_t *__cdecl _ui64tow(unsigned __int64 _Val,wchar_t *_DstBuf,int _Radix); - _CRTIMP __int64 __cdecl _wtoi64(const wchar_t *_Str); - _CRTIMP __int64 __cdecl _wtoi64_l(const wchar_t *_Str,_locale_t _Locale); - _CRTIMP __int64 __cdecl _wcstoi64(const wchar_t *_Str,wchar_t **_EndPtr,int _Radix); - _CRTIMP __int64 __cdecl _wcstoi64_l(const wchar_t *_Str,wchar_t **_EndPtr,int _Radix,_locale_t _Locale); - _CRTIMP unsigned __int64 __cdecl _wcstoui64(const wchar_t *_Str,wchar_t **_EndPtr,int _Radix); - _CRTIMP unsigned __int64 __cdecl _wcstoui64_l(const wchar_t *_Str ,wchar_t **_EndPtr,int _Radix,_locale_t _Locale); -#endif -#endif - -#ifndef _POSIX_ -#define _CVTBUFSIZE (309+40) - _CRTIMP char *__cdecl _fullpath(char *_FullPath,const char *_Path,size_t _SizeInBytes); - _CRTIMP char *__cdecl _ecvt(double _Val,int _NumOfDigits,int *_PtDec,int *_PtSign); - _CRTIMP char *__cdecl _fcvt(double _Val,int _NumOfDec,int *_PtDec,int *_PtSign); - _CRTIMP char *__cdecl _gcvt(double _Val,int _NumOfDigits,char *_DstBuf); - _CRTIMP int __cdecl _atodbl(_CRT_DOUBLE *_Result,char *_Str); - _CRTIMP int __cdecl _atoldbl(_LDOUBLE *_Result,char *_Str); - _CRTIMP int __cdecl _atoflt(_CRT_FLOAT *_Result,char *_Str); - _CRTIMP int __cdecl _atodbl_l(_CRT_DOUBLE *_Result,char *_Str,_locale_t _Locale); - _CRTIMP int __cdecl _atoldbl_l(_LDOUBLE *_Result,char *_Str,_locale_t _Locale); - _CRTIMP int __cdecl _atoflt_l(_CRT_FLOAT *_Result,char *_Str,_locale_t _Locale); - unsigned long __cdecl _lrotl(unsigned long _Val,int _Shift); - unsigned long __cdecl _lrotr(unsigned long _Val,int _Shift); - _CRTIMP void __cdecl _makepath(char *_Path,const char *_Drive,const char *_Dir,const char *_Filename,const char *_Ext); - _onexit_t __cdecl _onexit(_onexit_t _Func); - -#ifndef _CRT_PERROR_DEFINED -#define _CRT_PERROR_DEFINED - void __cdecl perror(const char *_ErrMsg); -#endif - _CRTIMP int __cdecl _putenv(const char *_EnvString); - unsigned int __cdecl _rotl(unsigned int _Val,int _Shift); -#if _INTEGRAL_MAX_BITS >= 64 - unsigned __int64 __cdecl _rotl64(unsigned __int64 _Val,int _Shift); -#endif - unsigned int __cdecl _rotr(unsigned int _Val,int _Shift); -#if _INTEGRAL_MAX_BITS >= 64 - unsigned __int64 __cdecl _rotr64(unsigned __int64 _Val,int _Shift); -#endif - _CRTIMP void __cdecl _searchenv(const char *_Filename,const char *_EnvVar,char *_ResultPath); - _CRTIMP void __cdecl _splitpath(const char *_FullPath,char *_Drive,char *_Dir,char *_Filename,char *_Ext); - _CRTIMP void __cdecl _swab(char *_Buf1,char *_Buf2,int _SizeInBytes); - -#ifndef _WSTDLIBP_DEFINED -#define _WSTDLIBP_DEFINED - _CRTIMP wchar_t *__cdecl _wfullpath(wchar_t *_FullPath,const wchar_t *_Path,size_t _SizeInWords); - _CRTIMP void __cdecl _wmakepath(wchar_t *_ResultPath,const wchar_t *_Drive,const wchar_t *_Dir,const wchar_t *_Filename,const wchar_t *_Ext); -#ifndef _CRT_WPERROR_DEFINED -#define _CRT_WPERROR_DEFINED - _CRTIMP void __cdecl _wperror(const wchar_t *_ErrMsg); -#endif - _CRTIMP int __cdecl _wputenv(const wchar_t *_EnvString); - _CRTIMP void __cdecl _wsearchenv(const wchar_t *_Filename,const wchar_t *_EnvVar,wchar_t *_ResultPath); - _CRTIMP void __cdecl _wsplitpath(const wchar_t *_FullPath,wchar_t *_Drive,wchar_t *_Dir,wchar_t *_Filename,wchar_t *_Ext); -#endif - - _CRTIMP void __cdecl _beep(unsigned _Frequency,unsigned _Duration) __MINGW_ATTRIB_DEPRECATED; - /* Not to be confused with _set_error_mode (int). */ - _CRTIMP void __cdecl _seterrormode(int _Mode) __MINGW_ATTRIB_DEPRECATED; - _CRTIMP void __cdecl _sleep(unsigned long _Duration) __MINGW_ATTRIB_DEPRECATED; -#endif - -#ifndef NO_OLDNAMES -#ifndef _POSIX_ -#if 0 -#ifndef __cplusplus -#ifndef NOMINMAX -#ifndef max -#define max(a,b) (((a) > (b)) ? (a) : (b)) -#endif -#ifndef min -#define min(a,b) (((a) < (b)) ? (a) : (b)) -#endif -#endif -#endif -#endif - -#define sys_errlist _sys_errlist -#define sys_nerr _sys_nerr -#define environ _environ - char *__cdecl ecvt(double _Val,int _NumOfDigits,int *_PtDec,int *_PtSign); - char *__cdecl fcvt(double _Val,int _NumOfDec,int *_PtDec,int *_PtSign); - char *__cdecl gcvt(double _Val,int _NumOfDigits,char *_DstBuf); - char *__cdecl itoa(int _Val,char *_DstBuf,int _Radix); - char *__cdecl ltoa(long _Val,char *_DstBuf,int _Radix); - int __cdecl putenv(const char *_EnvString); - void __cdecl swab(char *_Buf1,char *_Buf2,int _SizeInBytes); - char *__cdecl ultoa(unsigned long _Val,char *_Dstbuf,int _Radix); - onexit_t __cdecl onexit(onexit_t _Func); -#endif -#endif - -#if !defined __NO_ISOCEXT /* externs in static libmingwex.a */ - - typedef struct { long long quot, rem; } lldiv_t; - - lldiv_t __cdecl lldiv(long long, long long); - - __CRT_INLINE long long __cdecl llabs(long long _j) { return (_j >= 0 ? _j : -_j); } - - long long __cdecl strtoll(const char* __restrict__, char** __restrict, int); - unsigned long long __cdecl strtoull(const char* __restrict__, char** __restrict__, int); - - /* these are stubs for MS _i64 versions */ - long long __cdecl atoll (const char *); - -#ifndef __STRICT_ANSI__ - long long __cdecl wtoll (const wchar_t *); - char *__cdecl lltoa (long long, char *, int); - char *__cdecl ulltoa (unsigned long long , char *, int); - wchar_t *__cdecl lltow (long long, wchar_t *, int); - wchar_t *__cdecl ulltow (unsigned long long, wchar_t *, int); - - /* __CRT_INLINE using non-ansi functions */ - __CRT_INLINE long long __cdecl atoll (const char * _c) { return _atoi64 (_c); } - __CRT_INLINE char *__cdecl lltoa (long long _n, char * _c, int _i) { return _i64toa (_n, _c, _i); } - __CRT_INLINE char *__cdecl ulltoa (unsigned long long _n, char * _c, int _i) { return _ui64toa (_n, _c, _i); } - __CRT_INLINE long long __cdecl wtoll (const wchar_t * _w) { return _wtoi64 (_w); } - __CRT_INLINE wchar_t *__cdecl lltow (long long _n, wchar_t * _w, int _i) { return _i64tow (_n, _w, _i); } - __CRT_INLINE wchar_t *__cdecl ulltow (unsigned long long _n, wchar_t * _w, int _i) { return _ui64tow (_n, _w, _i); } -#endif /* (__STRICT_ANSI__) */ - -#endif /* !__NO_ISOCEXT */ - -#ifdef __cplusplus -} -#endif - -#pragma pack(pop) - -#include -#include - -#endif diff --git a/05/tcc-final-old/win32/include/string.h b/05/tcc-final-old/win32/include/string.h deleted file mode 100644 index 3249dc3..0000000 --- a/05/tcc-final-old/win32/include/string.h +++ /dev/null @@ -1,164 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _INC_STRING -#define _INC_STRING - -#include <_mingw.h> - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _NLSCMP_DEFINED -#define _NLSCMP_DEFINED -#define _NLSCMPERROR 2147483647 -#endif - -#ifndef NULL -#ifdef __cplusplus -#define NULL 0 -#else -#define NULL ((void *)0) -#endif -#endif - -#define _WConst_return _CONST_RETURN - -#ifndef _CRT_MEMORY_DEFINED -#define _CRT_MEMORY_DEFINED - _CRTIMP void *__cdecl _memccpy(void *_Dst,const void *_Src,int _Val,size_t _MaxCount); - _CONST_RETURN void *__cdecl memchr(const void *_Buf ,int _Val,size_t _MaxCount); - _CRTIMP int __cdecl _memicmp(const void *_Buf1,const void *_Buf2,size_t _Size); - _CRTIMP int __cdecl _memicmp_l(const void *_Buf1,const void *_Buf2,size_t _Size,_locale_t _Locale); - int __cdecl memcmp(const void *_Buf1,const void *_Buf2,size_t _Size); - void *__cdecl memcpy(void *_Dst,const void *_Src,size_t _Size); - void *__cdecl memset(void *_Dst,int _Val,size_t _Size); -#ifndef NO_OLDNAMES - void *__cdecl memccpy(void *_Dst,const void *_Src,int _Val,size_t _Size); - int __cdecl memicmp(const void *_Buf1,const void *_Buf2,size_t _Size); -#endif -#endif - char *__cdecl _strset(char *_Str,int _Val); - char *__cdecl strcpy(char *_Dest,const char *_Source); - char *__cdecl strcat(char *_Dest,const char *_Source); - int __cdecl strcmp(const char *_Str1,const char *_Str2); - size_t __cdecl strlen(const char *_Str); -#if 0 - size_t __cdecl strnlen(const char *_Str,size_t _MaxCount); -#endif - void *__cdecl memmove(void *_Dst,const void *_Src,size_t _Size); - _CRTIMP char *__cdecl _strdup(const char *_Src); - _CONST_RETURN char *__cdecl strchr(const char *_Str,int _Val); - _CRTIMP int __cdecl _stricmp(const char *_Str1,const char *_Str2); - _CRTIMP int __cdecl _strcmpi(const char *_Str1,const char *_Str2); - _CRTIMP int __cdecl _stricmp_l(const char *_Str1,const char *_Str2,_locale_t _Locale); - int __cdecl strcoll(const char *_Str1,const char *_Str2); - _CRTIMP int __cdecl _strcoll_l(const char *_Str1,const char *_Str2,_locale_t _Locale); - _CRTIMP int __cdecl _stricoll(const char *_Str1,const char *_Str2); - _CRTIMP int __cdecl _stricoll_l(const char *_Str1,const char *_Str2,_locale_t _Locale); - _CRTIMP int __cdecl _strncoll (const char *_Str1,const char *_Str2,size_t _MaxCount); - _CRTIMP int __cdecl _strncoll_l(const char *_Str1,const char *_Str2,size_t _MaxCount,_locale_t _Locale); - _CRTIMP int __cdecl _strnicoll (const char *_Str1,const char *_Str2,size_t _MaxCount); - _CRTIMP int __cdecl _strnicoll_l(const char *_Str1,const char *_Str2,size_t _MaxCount,_locale_t _Locale); - size_t __cdecl strcspn(const char *_Str,const char *_Control); - _CRTIMP char *__cdecl _strerror(const char *_ErrMsg); - char *__cdecl strerror(int); - _CRTIMP char *__cdecl _strlwr(char *_String); - char *strlwr_l(char *_String,_locale_t _Locale); - char *__cdecl strncat(char *_Dest,const char *_Source,size_t _Count); - int __cdecl strncmp(const char *_Str1,const char *_Str2,size_t _MaxCount); - _CRTIMP int __cdecl _strnicmp(const char *_Str1,const char *_Str2,size_t _MaxCount); - _CRTIMP int __cdecl _strnicmp_l(const char *_Str1,const char *_Str2,size_t _MaxCount,_locale_t _Locale); - char *strncpy(char *_Dest,const char *_Source,size_t _Count); - _CRTIMP char *__cdecl _strnset(char *_Str,int _Val,size_t _MaxCount); - _CONST_RETURN char *__cdecl strpbrk(const char *_Str,const char *_Control); - _CONST_RETURN char *__cdecl strrchr(const char *_Str,int _Ch); - _CRTIMP char *__cdecl _strrev(char *_Str); - size_t __cdecl strspn(const char *_Str,const char *_Control); - _CONST_RETURN char *__cdecl strstr(const char *_Str,const char *_SubStr); - char *__cdecl strtok(char *_Str,const char *_Delim); - _CRTIMP char *__cdecl _strupr(char *_String); - _CRTIMP char *_strupr_l(char *_String,_locale_t _Locale); - size_t __cdecl strxfrm(char *_Dst,const char *_Src,size_t _MaxCount); - _CRTIMP size_t __cdecl _strxfrm_l(char *_Dst,const char *_Src,size_t _MaxCount,_locale_t _Locale); - -#ifndef NO_OLDNAMES - char *__cdecl strdup(const char *_Src); - int __cdecl strcmpi(const char *_Str1,const char *_Str2); - int __cdecl stricmp(const char *_Str1,const char *_Str2); - char *__cdecl strlwr(char *_Str); - int __cdecl strnicmp(const char *_Str1,const char *_Str,size_t _MaxCount); - __CRT_INLINE int __cdecl strncasecmp (const char *__sz1, const char *__sz2, size_t __sizeMaxCompare) { return _strnicmp (__sz1, __sz2, __sizeMaxCompare); } - __CRT_INLINE int __cdecl strcasecmp (const char *__sz1, const char *__sz2) { return _stricmp (__sz1, __sz2); } - char *__cdecl strnset(char *_Str,int _Val,size_t _MaxCount); - char *__cdecl strrev(char *_Str); - char *__cdecl strset(char *_Str,int _Val); - char *__cdecl strupr(char *_Str); -#endif - -#ifndef _WSTRING_DEFINED -#define _WSTRING_DEFINED - - _CRTIMP wchar_t *__cdecl _wcsdup(const wchar_t *_Str); - wchar_t *__cdecl wcscat(wchar_t *_Dest,const wchar_t *_Source); - _CONST_RETURN wchar_t *__cdecl wcschr(const wchar_t *_Str,wchar_t _Ch); - int __cdecl wcscmp(const wchar_t *_Str1,const wchar_t *_Str2); - wchar_t *__cdecl wcscpy(wchar_t *_Dest,const wchar_t *_Source); - size_t __cdecl wcscspn(const wchar_t *_Str,const wchar_t *_Control); - size_t __cdecl wcslen(const wchar_t *_Str); - size_t __cdecl wcsnlen(const wchar_t *_Src,size_t _MaxCount); - wchar_t *wcsncat(wchar_t *_Dest,const wchar_t *_Source,size_t _Count); - int __cdecl wcsncmp(const wchar_t *_Str1,const wchar_t *_Str2,size_t _MaxCount); - wchar_t *wcsncpy(wchar_t *_Dest,const wchar_t *_Source,size_t _Count); - _CONST_RETURN wchar_t *__cdecl wcspbrk(const wchar_t *_Str,const wchar_t *_Control); - _CONST_RETURN wchar_t *__cdecl wcsrchr(const wchar_t *_Str,wchar_t _Ch); - size_t __cdecl wcsspn(const wchar_t *_Str,const wchar_t *_Control); - _CONST_RETURN wchar_t *__cdecl wcsstr(const wchar_t *_Str,const wchar_t *_SubStr); - wchar_t *__cdecl wcstok(wchar_t *_Str,const wchar_t *_Delim); - _CRTIMP wchar_t *__cdecl _wcserror(int _ErrNum); - _CRTIMP wchar_t *__cdecl __wcserror(const wchar_t *_Str); - _CRTIMP int __cdecl _wcsicmp(const wchar_t *_Str1,const wchar_t *_Str2); - _CRTIMP int __cdecl _wcsicmp_l(const wchar_t *_Str1,const wchar_t *_Str2,_locale_t _Locale); - _CRTIMP int __cdecl _wcsnicmp(const wchar_t *_Str1,const wchar_t *_Str2,size_t _MaxCount); - _CRTIMP int __cdecl _wcsnicmp_l(const wchar_t *_Str1,const wchar_t *_Str2,size_t _MaxCount,_locale_t _Locale); - _CRTIMP wchar_t *__cdecl _wcsnset(wchar_t *_Str,wchar_t _Val,size_t _MaxCount); - _CRTIMP wchar_t *__cdecl _wcsrev(wchar_t *_Str); - _CRTIMP wchar_t *__cdecl _wcsset(wchar_t *_Str,wchar_t _Val); - _CRTIMP wchar_t *__cdecl _wcslwr(wchar_t *_String); - _CRTIMP wchar_t *_wcslwr_l(wchar_t *_String,_locale_t _Locale); - _CRTIMP wchar_t *__cdecl _wcsupr(wchar_t *_String); - _CRTIMP wchar_t *_wcsupr_l(wchar_t *_String,_locale_t _Locale); - size_t __cdecl wcsxfrm(wchar_t *_Dst,const wchar_t *_Src,size_t _MaxCount); - _CRTIMP size_t __cdecl _wcsxfrm_l(wchar_t *_Dst,const wchar_t *_Src,size_t _MaxCount,_locale_t _Locale); - int __cdecl wcscoll(const wchar_t *_Str1,const wchar_t *_Str2); - _CRTIMP int __cdecl _wcscoll_l(const wchar_t *_Str1,const wchar_t *_Str2,_locale_t _Locale); - _CRTIMP int __cdecl _wcsicoll(const wchar_t *_Str1,const wchar_t *_Str2); - _CRTIMP int __cdecl _wcsicoll_l(const wchar_t *_Str1,const wchar_t *_Str2,_locale_t _Locale); - _CRTIMP int __cdecl _wcsncoll(const wchar_t *_Str1,const wchar_t *_Str2,size_t _MaxCount); - _CRTIMP int __cdecl _wcsncoll_l(const wchar_t *_Str1,const wchar_t *_Str2,size_t _MaxCount,_locale_t _Locale); - _CRTIMP int __cdecl _wcsnicoll(const wchar_t *_Str1,const wchar_t *_Str2,size_t _MaxCount); - _CRTIMP int __cdecl _wcsnicoll_l(const wchar_t *_Str1,const wchar_t *_Str2,size_t _MaxCount,_locale_t _Locale); - -#ifndef NO_OLDNAMES - wchar_t *__cdecl wcsdup(const wchar_t *_Str); -#define wcswcs wcsstr - int __cdecl wcsicmp(const wchar_t *_Str1,const wchar_t *_Str2); - int __cdecl wcsnicmp(const wchar_t *_Str1,const wchar_t *_Str2,size_t _MaxCount); - wchar_t *__cdecl wcsnset(wchar_t *_Str,wchar_t _Val,size_t _MaxCount); - wchar_t *__cdecl wcsrev(wchar_t *_Str); - wchar_t *__cdecl wcsset(wchar_t *_Str,wchar_t _Val); - wchar_t *__cdecl wcslwr(wchar_t *_Str); - wchar_t *__cdecl wcsupr(wchar_t *_Str); - int __cdecl wcsicoll(const wchar_t *_Str1,const wchar_t *_Str2); -#endif -#endif - -#ifdef __cplusplus -} -#endif - -#include -#endif diff --git a/05/tcc-final-old/win32/include/sys/fcntl.h b/05/tcc-final-old/win32/include/sys/fcntl.h deleted file mode 100644 index 29fd55a..0000000 --- a/05/tcc-final-old/win32/include/sys/fcntl.h +++ /dev/null @@ -1,13 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -/* - * This file is part of the Mingw32 package. - * - * This fcntl.h maps to the root fcntl.h - */ -#ifndef __STRICT_ANSI__ -#include -#endif diff --git a/05/tcc-final-old/win32/include/sys/file.h b/05/tcc-final-old/win32/include/sys/file.h deleted file mode 100644 index 370f352..0000000 --- a/05/tcc-final-old/win32/include/sys/file.h +++ /dev/null @@ -1,14 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -/* - * This file is part of the Mingw32 package. - * - * This file.h maps to the root fcntl.h - * TODO? - */ -#ifndef __STRICT_ANSI__ -#include -#endif diff --git a/05/tcc-final-old/win32/include/sys/locking.h b/05/tcc-final-old/win32/include/sys/locking.h deleted file mode 100644 index e3fc85b..0000000 --- a/05/tcc-final-old/win32/include/sys/locking.h +++ /dev/null @@ -1,30 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _INC_LOCKING -#define _INC_LOCKING - -#ifndef _WIN32 -#error Only Win32 target is supported! -#endif - -/* All the headers include this file. */ -#include <_mingw.h> - -#define _LK_UNLCK 0 -#define _LK_LOCK 1 -#define _LK_NBLCK 2 -#define _LK_RLCK 3 -#define _LK_NBRLCK 4 - -#ifndef NO_OLDNAMES -#define LK_UNLCK _LK_UNLCK -#define LK_LOCK _LK_LOCK -#define LK_NBLCK _LK_NBLCK -#define LK_RLCK _LK_RLCK -#define LK_NBRLCK _LK_NBRLCK -#endif - -#endif diff --git a/05/tcc-final-old/win32/include/sys/stat.h b/05/tcc-final-old/win32/include/sys/stat.h deleted file mode 100644 index 344d4a2..0000000 --- a/05/tcc-final-old/win32/include/sys/stat.h +++ /dev/null @@ -1,290 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _INC_STAT -#define _INC_STAT - -#ifndef _WIN32 -#error Only Win32 target is supported! -#endif - -#include <_mingw.h> -#include - -#pragma pack(push,_CRT_PACKING) - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _CRTIMP -#define _CRTIMP __declspec(dllimport) -#endif - -#include - -#ifndef __TINYC__ /* gr */ -#ifdef _USE_32BIT_TIME_T -#ifdef _WIN64 -#undef _USE_32BIT_TIME_T -#endif -#else -#if _INTEGRAL_MAX_BITS < 64 -#define _USE_32BIT_TIME_T -#endif -#endif -#endif - -#ifndef _TIME32_T_DEFINED - typedef long __time32_t; -#define _TIME32_T_DEFINED -#endif - -#ifndef _TIME64_T_DEFINED -#if _INTEGRAL_MAX_BITS >= 64 - typedef __int64 __time64_t; -#endif -#define _TIME64_T_DEFINED -#endif - -#ifndef _TIME_T_DEFINED -#ifdef _USE_32BIT_TIME_T - typedef __time32_t time_t; -#else - typedef __time64_t time_t; -#endif -#define _TIME_T_DEFINED -#endif - -#ifndef _WCHAR_T_DEFINED - typedef unsigned short wchar_t; -#define _WCHAR_T_DEFINED -#endif - -#ifndef _STAT_DEFINED - -#ifdef _USE_32BIT_TIME_T -#ifndef _WIN64 -#define _fstat32 _fstat -#define _stat32 _stat -#define _wstat32 _wstat -#else -#define _fstat _fstat32 -#define _stat _stat32 -#define _wstat _wstat32 -#endif -#define _fstati64 _fstat32i64 -#define _stati64 _stat32i64 -#define _wstati64 _wstat32i64 -#else -#define _fstat _fstat64i32 -#define _fstati64 _fstat64 -#define _stat _stat64i32 -#define _stati64 _stat64 -#define _wstat _wstat64i32 -#define _wstati64 _wstat64 -#endif - - struct _stat32 { - _dev_t st_dev; - _ino_t st_ino; - unsigned short st_mode; - short st_nlink; - short st_uid; - short st_gid; - _dev_t st_rdev; - _off_t st_size; - __time32_t st_atime; - __time32_t st_mtime; - __time32_t st_ctime; - }; - -#ifndef NO_OLDNAMES - struct stat { - _dev_t st_dev; - _ino_t st_ino; - unsigned short st_mode; - short st_nlink; - short st_uid; - short st_gid; - _dev_t st_rdev; - _off_t st_size; - time_t st_atime; - time_t st_mtime; - time_t st_ctime; - }; -#endif - -#if _INTEGRAL_MAX_BITS >= 64 - struct _stat32i64 { - _dev_t st_dev; - _ino_t st_ino; - unsigned short st_mode; - short st_nlink; - short st_uid; - short st_gid; - _dev_t st_rdev; - __int64 st_size; - __time32_t st_atime; - __time32_t st_mtime; - __time32_t st_ctime; - }; - - struct _stat64i32 { - _dev_t st_dev; - _ino_t st_ino; - unsigned short st_mode; - short st_nlink; - short st_uid; - short st_gid; - _dev_t st_rdev; - _off_t st_size; - __time64_t st_atime; - __time64_t st_mtime; - __time64_t st_ctime; - }; - - struct _stat64 { - _dev_t st_dev; - _ino_t st_ino; - unsigned short st_mode; - short st_nlink; - short st_uid; - short st_gid; - _dev_t st_rdev; - __int64 st_size; - __time64_t st_atime; - __time64_t st_mtime; - __time64_t st_ctime; - }; -#endif - -#define __stat64 _stat64 - -#define _STAT_DEFINED -#endif - -#define _S_IFMT 0xF000 -#define _S_IFDIR 0x4000 -#define _S_IFCHR 0x2000 -#define _S_IFIFO 0x1000 -#define _S_IFREG 0x8000 -#define _S_IREAD 0x0100 -#define _S_IWRITE 0x0080 -#define _S_IEXEC 0x0040 - - _CRTIMP int __cdecl _fstat32(int _FileDes,struct _stat32 *_Stat); - _CRTIMP int __cdecl _stat32(const char *_Name,struct _stat32 *_Stat); -#if _INTEGRAL_MAX_BITS >= 64 - _CRTIMP int __cdecl _fstat64(int _FileDes,struct _stat64 *_Stat); - _CRTIMP int __cdecl _fstat32i64(int _FileDes,struct _stat32i64 *_Stat); - int __cdecl _fstat64i32(int _FileDes,struct _stat64i32 *_Stat); - __CRT_INLINE int __cdecl _fstat64i32(int _FileDes,struct _stat64i32 *_Stat) - { - struct _stat64 st; - int ret=_fstat64(_FileDes,&st); - _Stat->st_dev=st.st_dev; - _Stat->st_ino=st.st_ino; - _Stat->st_mode=st.st_mode; - _Stat->st_nlink=st.st_nlink; - _Stat->st_uid=st.st_uid; - _Stat->st_gid=st.st_gid; - _Stat->st_rdev=st.st_rdev; - _Stat->st_size=(_off_t) st.st_size; - _Stat->st_atime=st.st_atime; - _Stat->st_mtime=st.st_mtime; - _Stat->st_ctime=st.st_ctime; - return ret; - } - _CRTIMP int __cdecl _stat64(const char *_Name,struct _stat64 *_Stat); - _CRTIMP int __cdecl _stat32i64(const char *_Name,struct _stat32i64 *_Stat); - int __cdecl _stat64i32(const char *_Name,struct _stat64i32 *_Stat); - __CRT_INLINE int __cdecl _stat64i32(const char *_Name,struct _stat64i32 *_Stat) - { - struct _stat64 st; - int ret=_stat64(_Name,&st); - _Stat->st_dev=st.st_dev; - _Stat->st_ino=st.st_ino; - _Stat->st_mode=st.st_mode; - _Stat->st_nlink=st.st_nlink; - _Stat->st_uid=st.st_uid; - _Stat->st_gid=st.st_gid; - _Stat->st_rdev=st.st_rdev; - _Stat->st_size=(_off_t) st.st_size; - _Stat->st_atime=st.st_atime; - _Stat->st_mtime=st.st_mtime; - _Stat->st_ctime=st.st_ctime; - return ret; - } -#endif - -#ifndef _WSTAT_DEFINED -#define _WSTAT_DEFINED - _CRTIMP int __cdecl _wstat32(const wchar_t *_Name,struct _stat32 *_Stat); -#if _INTEGRAL_MAX_BITS >= 64 - _CRTIMP int __cdecl _wstat32i64(const wchar_t *_Name,struct _stat32i64 *_Stat); - int __cdecl _wstat64i32(const wchar_t *_Name,struct _stat64i32 *_Stat); - _CRTIMP int __cdecl _wstat64(const wchar_t *_Name,struct _stat64 *_Stat); -#endif -#endif - -#ifndef NO_OLDNAMES -#define _S_IFBLK 0x3000 /* Block: Is this ever set under w32? */ - -#define S_IFMT _S_IFMT -#define S_IFDIR _S_IFDIR -#define S_IFCHR _S_IFCHR -#define S_IFREG _S_IFREG -#define S_IREAD _S_IREAD -#define S_IWRITE _S_IWRITE -#define S_IEXEC _S_IEXEC -#define S_IFIFO _S_IFIFO -#define S_IFBLK _S_IFBLK - -#define _S_IRWXU (_S_IREAD | _S_IWRITE | _S_IEXEC) -#define _S_IXUSR _S_IEXEC -#define _S_IWUSR _S_IWRITE - -#define S_IRWXU _S_IRWXU -#define S_IXUSR _S_IXUSR -#define S_IWUSR _S_IWUSR -#define S_IRUSR _S_IRUSR -#define _S_IRUSR _S_IREAD - -#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) -#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) -#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) -#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) -#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) - -#endif - -#if !defined (RC_INVOKED) && !defined (NO_OLDNAMES) -int __cdecl stat(const char *_Filename,struct stat *_Stat); -int __cdecl fstat(int _Desc,struct stat *_Stat); -int __cdecl wstat(const wchar_t *_Filename,struct stat *_Stat); -#ifdef _USE_32BIT_TIME_T -__CRT_INLINE int __cdecl fstat(int _Desc,struct stat *_Stat) { - return _fstat32(_Desc,(struct _stat32 *)_Stat); -} -__CRT_INLINE int __cdecl stat(const char *_Filename,struct stat *_Stat) { - return _stat32(_Filename,(struct _stat32 *)_Stat); -} -#else -__CRT_INLINE int __cdecl fstat(int _Desc,struct stat *_Stat) { - return _fstat64i32(_Desc,(struct _stat64i32 *)_Stat); -} -__CRT_INLINE int __cdecl stat(const char *_Filename,struct stat *_Stat) { - return _stat64i32(_Filename,(struct _stat64i32 *)_Stat); -} -#endif -#endif - -#ifdef __cplusplus -} -#endif - -#pragma pack(pop) -#endif diff --git a/05/tcc-final-old/win32/include/sys/time.h b/05/tcc-final-old/win32/include/sys/time.h deleted file mode 100644 index 8ccab83..0000000 --- a/05/tcc-final-old/win32/include/sys/time.h +++ /dev/null @@ -1,69 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ - -#ifndef _SYS_TIME_H_ -#define _SYS_TIME_H_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef __STRICT_ANSI__ -#ifndef _TIMEVAL_DEFINED /* also in winsock[2].h */ -#define _TIMEVAL_DEFINED -struct timeval { - long tv_sec; - long tv_usec; -}; -#define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) -#define timercmp(tvp, uvp, cmp) \ - (((tvp)->tv_sec != (uvp)->tv_sec) ? \ - ((tvp)->tv_sec cmp (uvp)->tv_sec) : \ - ((tvp)->tv_usec cmp (uvp)->tv_usec)) -#define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0 -#endif /* _TIMEVAL_DEFINED */ - -#ifndef _TIMEZONE_DEFINED /* also in sys/time.h */ -#define _TIMEZONE_DEFINED -/* Provided for compatibility with code that assumes that - the presence of gettimeofday function implies a definition - of struct timezone. */ -struct timezone -{ - int tz_minuteswest; /* of Greenwich */ - int tz_dsttime; /* type of dst correction to apply */ -}; - - extern int __cdecl mingw_gettimeofday (struct timeval *p, struct timezone *z); - -#endif - -/* - Implementation as per: - The Open Group Base Specifications, Issue 6 - IEEE Std 1003.1, 2004 Edition - - The timezone pointer arg is ignored. Errors are ignored. -*/ -#ifndef _GETTIMEOFDAY_DEFINED -#define _GETTIMEOFDAY_DEFINED -int __cdecl gettimeofday(struct timeval *__restrict__, - void *__restrict__ /* tzp (unused) */); -#endif - -#endif /* __STRICT_ANSI__ */ - -#ifdef __cplusplus -} -#endif - -/* Adding timespec definition. */ -#include - - -#endif /* _SYS_TIME_H_ */ diff --git a/05/tcc-final-old/win32/include/sys/timeb.h b/05/tcc-final-old/win32/include/sys/timeb.h deleted file mode 100644 index 3483773..0000000 --- a/05/tcc-final-old/win32/include/sys/timeb.h +++ /dev/null @@ -1,133 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _TIMEB_H_ -#define _TIMEB_H_ - -#include <_mingw.h> - -#ifndef _WIN32 -#error Only Win32 target is supported! -#endif - -#pragma pack(push,_CRT_PACKING) - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _CRTIMP -#define _CRTIMP __declspec(dllimport) -#endif - -#ifndef __TINYC__ /* gr */ -#ifdef _USE_32BIT_TIME_T -#ifdef _WIN64 -#undef _USE_32BIT_TIME_T -#endif -#else -#if _INTEGRAL_MAX_BITS < 64 -#define _USE_32BIT_TIME_T -#endif -#endif -#endif - -#ifndef _TIME32_T_DEFINED - typedef long __time32_t; -#define _TIME32_T_DEFINED -#endif - -#ifndef _TIME64_T_DEFINED -#if _INTEGRAL_MAX_BITS >= 64 - typedef __int64 __time64_t; -#endif -#define _TIME64_T_DEFINED -#endif - -#ifndef _TIME_T_DEFINED -#ifdef _USE_32BIT_TIME_T - typedef __time32_t time_t; -#else - typedef __time64_t time_t; -#endif -#define _TIME_T_DEFINED -#endif - -#ifndef _TIMEB_DEFINED -#define _TIMEB_DEFINED - - struct __timeb32 { - __time32_t time; - unsigned short millitm; - short timezone; - short dstflag; - }; - -#ifndef NO_OLDNAMES - struct timeb { - time_t time; - unsigned short millitm; - short timezone; - short dstflag; - }; -#endif - -#if _INTEGRAL_MAX_BITS >= 64 - struct __timeb64 { - __time64_t time; - unsigned short millitm; - short timezone; - short dstflag; - }; -#endif - -#ifdef _USE_32BIT_TIME_T -#define _timeb __timeb32 -//gr #define _ftime _ftime32 -#define _ftime32 _ftime -#else -#define _timeb __timeb64 -#define _ftime _ftime64 -#endif -#endif - - _CRTIMP void __cdecl _ftime32(struct __timeb32 *_Time); -#if _INTEGRAL_MAX_BITS >= 64 - _CRTIMP void __cdecl _ftime64(struct __timeb64 *_Time); -#endif - -#ifndef _TIMESPEC_DEFINED -#define _TIMESPEC_DEFINED -struct timespec { - time_t tv_sec; /* Seconds */ - long tv_nsec; /* Nanoseconds */ -}; - -struct itimerspec { - struct timespec it_interval; /* Timer period */ - struct timespec it_value; /* Timer expiration */ -}; -#endif - -#if !defined (RC_INVOKED) && !defined (NO_OLDNAMES) -#ifdef _USE_32BIT_TIME_T -__CRT_INLINE void __cdecl ftime(struct timeb *_Tmb) { - _ftime32((struct __timeb32 *)_Tmb); -} -#else -__CRT_INLINE void __cdecl ftime(struct timeb *_Tmb) { - _ftime64((struct __timeb64 *)_Tmb); -} -#endif -#endif - -#ifdef __cplusplus -} -#endif - -#pragma pack(pop) - -#include -#endif diff --git a/05/tcc-final-old/win32/include/sys/types.h b/05/tcc-final-old/win32/include/sys/types.h deleted file mode 100644 index 7379b0f..0000000 --- a/05/tcc-final-old/win32/include/sys/types.h +++ /dev/null @@ -1,118 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _INC_TYPES -#define _INC_TYPES - -#ifndef _WIN32 -#error Only Win32 target is supported! -#endif - -#include <_mingw.h> - -#ifndef __TINYC__ /* gr */ -#ifdef _USE_32BIT_TIME_T -#ifdef _WIN64 -#undef _USE_32BIT_TIME_T -#endif -#else -#if _INTEGRAL_MAX_BITS < 64 -#define _USE_32BIT_TIME_T -#endif -#endif -#endif - -#ifndef _TIME32_T_DEFINED -#define _TIME32_T_DEFINED -typedef long __time32_t; -#endif - -#ifndef _TIME64_T_DEFINED -#define _TIME64_T_DEFINED -#if _INTEGRAL_MAX_BITS >= 64 -typedef __int64 __time64_t; -#endif -#endif - -#ifndef _TIME_T_DEFINED -#define _TIME_T_DEFINED -#ifdef _USE_32BIT_TIME_T -typedef __time32_t time_t; -#else -typedef __time64_t time_t; -#endif -#endif - -#ifndef _INO_T_DEFINED -#define _INO_T_DEFINED -typedef unsigned short _ino_t; -#ifndef NO_OLDNAMES -typedef unsigned short ino_t; -#endif -#endif - -#ifndef _DEV_T_DEFINED -#define _DEV_T_DEFINED -typedef unsigned int _dev_t; -#ifndef NO_OLDNAMES -typedef unsigned int dev_t; -#endif -#endif - -#ifndef _PID_T_ -#define _PID_T_ -#ifndef _WIN64 -typedef int _pid_t; -#else -typedef __int64 _pid_t; -#endif - -#ifndef NO_OLDNAMES -typedef _pid_t pid_t; -#endif -#endif /* Not _PID_T_ */ - -#ifndef _MODE_T_ -#define _MODE_T_ -typedef unsigned short _mode_t; - -#ifndef NO_OLDNAMES -typedef _mode_t mode_t; -#endif -#endif /* Not _MODE_T_ */ - -#ifndef _OFF_T_DEFINED -#define _OFF_T_DEFINED -#ifndef _OFF_T_ -#define _OFF_T_ - typedef long _off_t; -#if !defined(NO_OLDNAMES) || defined(_POSIX) - typedef long off_t; -#endif -#endif -#endif - -#ifndef _OFF64_T_DEFINED -#define _OFF64_T_DEFINED - typedef long long _off64_t; -#if !defined(NO_OLDNAMES) || defined(_POSIX) - typedef long long off64_t; -#endif -#endif - -#ifndef _TIMESPEC_DEFINED -#define _TIMESPEC_DEFINED -struct timespec { - time_t tv_sec; /* Seconds */ - long tv_nsec; /* Nanoseconds */ -}; - -struct itimerspec { - struct timespec it_interval; /* Timer period */ - struct timespec it_value; /* Timer expiration */ -}; -#endif - -#endif diff --git a/05/tcc-final-old/win32/include/sys/unistd.h b/05/tcc-final-old/win32/include/sys/unistd.h deleted file mode 100644 index 31006d3..0000000 --- a/05/tcc-final-old/win32/include/sys/unistd.h +++ /dev/null @@ -1,14 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -/* - * This file is part of the Mingw32 package. - * - * unistd.h maps (roughly) to io.h - */ -#ifndef __STRICT_ANSI__ -#include -#endif - diff --git a/05/tcc-final-old/win32/include/sys/utime.h b/05/tcc-final-old/win32/include/sys/utime.h deleted file mode 100644 index fec8304..0000000 --- a/05/tcc-final-old/win32/include/sys/utime.h +++ /dev/null @@ -1,146 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _INC_UTIME -#define _INC_UTIME - -#ifndef _WIN32 -#error Only Win32 target is supported! -#endif - -#include <_mingw.h> - -#pragma pack(push,_CRT_PACKING) - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _CRTIMP -#define _CRTIMP __declspec(dllimport) -#endif - -#ifndef _WCHAR_T_DEFINED - typedef unsigned short wchar_t; -#define _WCHAR_T_DEFINED -#endif - -#ifndef __TINYC__ /* gr */ -#ifdef _USE_32BIT_TIME_T -#ifdef _WIN64 -#undef _USE_32BIT_TIME_T -#endif -#else -#if _INTEGRAL_MAX_BITS < 64 -#define _USE_32BIT_TIME_T -#endif -#endif -#endif - -#ifndef _TIME32_T_DEFINED -#define _TIME32_T_DEFINED - typedef long __time32_t; -#endif - -#ifndef _TIME64_T_DEFINED -#define _TIME64_T_DEFINED -#if _INTEGRAL_MAX_BITS >= 64 - typedef __int64 __time64_t; -#endif -#endif - -#ifndef _TIME_T_DEFINED -#define _TIME_T_DEFINED -#ifdef _USE_32BIT_TIME_T - typedef __time32_t time_t; -#else - typedef __time64_t time_t; -#endif -#endif - -#ifndef _UTIMBUF_DEFINED -#define _UTIMBUF_DEFINED - - struct _utimbuf { - time_t actime; - time_t modtime; - }; - - struct __utimbuf32 { - __time32_t actime; - __time32_t modtime; - }; - -#if _INTEGRAL_MAX_BITS >= 64 - struct __utimbuf64 { - __time64_t actime; - __time64_t modtime; - }; -#endif - -#ifndef NO_OLDNAMES - struct utimbuf { - time_t actime; - time_t modtime; - }; - - struct utimbuf32 { - __time32_t actime; - __time32_t modtime; - }; -#endif -#endif - - _CRTIMP int __cdecl _utime32(const char *_Filename,struct __utimbuf32 *_Time); - _CRTIMP int __cdecl _futime32(int _FileDes,struct __utimbuf32 *_Time); - _CRTIMP int __cdecl _wutime32(const wchar_t *_Filename,struct __utimbuf32 *_Time); -#if _INTEGRAL_MAX_BITS >= 64 - _CRTIMP int __cdecl _utime64(const char *_Filename,struct __utimbuf64 *_Time); - _CRTIMP int __cdecl _futime64(int _FileDes,struct __utimbuf64 *_Time); - _CRTIMP int __cdecl _wutime64(const wchar_t *_Filename,struct __utimbuf64 *_Time); -#endif - -#ifndef RC_INVOKED -#ifdef _USE_32BIT_TIME_T -__CRT_INLINE int __cdecl _utime(const char *_Filename,struct _utimbuf *_Utimbuf) { - return _utime32(_Filename,(struct __utimbuf32 *)_Utimbuf); -} -__CRT_INLINE int __cdecl _futime(int _Desc,struct _utimbuf *_Utimbuf) { - return _futime32(_Desc,(struct __utimbuf32 *)_Utimbuf); -} -__CRT_INLINE int __cdecl _wutime(const wchar_t *_Filename,struct _utimbuf *_Utimbuf) { - return _wutime32(_Filename,(struct __utimbuf32 *)_Utimbuf); -} -#else -__CRT_INLINE int __cdecl _utime(const char *_Filename,struct _utimbuf *_Utimbuf) { - return _utime64(_Filename,(struct __utimbuf64 *)_Utimbuf); -} -__CRT_INLINE int __cdecl _futime(int _Desc,struct _utimbuf *_Utimbuf) { - return _futime64(_Desc,(struct __utimbuf64 *)_Utimbuf); -} -__CRT_INLINE int __cdecl _wutime(const wchar_t *_Filename,struct _utimbuf *_Utimbuf) { - return _wutime64(_Filename,(struct __utimbuf64 *)_Utimbuf); -} -#endif - -#ifndef NO_OLDNAMES -#ifdef _USE_32BIT_TIME_T -__CRT_INLINE int __cdecl utime(const char *_Filename,struct utimbuf *_Utimbuf) { - return _utime32(_Filename,(struct __utimbuf32 *)_Utimbuf); -} -#else -__CRT_INLINE int __cdecl utime(const char *_Filename,struct utimbuf *_Utimbuf) { - return _utime64(_Filename,(struct __utimbuf64 *)_Utimbuf); -} -#endif -#endif -#endif - -#ifdef __cplusplus -} -#endif - -#pragma pack(pop) -#endif diff --git a/05/tcc-final-old/win32/include/tchar.h b/05/tcc-final-old/win32/include/tchar.h deleted file mode 100644 index cd44bec..0000000 --- a/05/tcc-final-old/win32/include/tchar.h +++ /dev/null @@ -1,1102 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#include <_mingw.h> - -#ifndef _INC_TCHAR -#define _INC_TCHAR - -#ifdef _STRSAFE_H_INCLUDED_ -#error Need to include strsafe.h after tchar.h -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -#define _ftcscat _tcscat -#define _ftcschr _tcschr -#define _ftcscpy _tcscpy -#define _ftcscspn _tcscspn -#define _ftcslen _tcslen -#define _ftcsncat _tcsncat -#define _ftcsncpy _tcsncpy -#define _ftcspbrk _tcspbrk -#define _ftcsrchr _tcsrchr -#define _ftcsspn _tcsspn -#define _ftcsstr _tcsstr -#define _ftcstok _tcstok - -#define _ftcsdup _tcsdup -#define _ftcsnset _tcsnset -#define _ftcsrev _tcsrev -#define _ftcsset _tcsset - -#define _ftcscmp _tcscmp -#define _ftcsicmp _tcsicmp -#define _ftcsnccmp _tcsnccmp -#define _ftcsncmp _tcsncmp -#define _ftcsncicmp _tcsncicmp -#define _ftcsnicmp _tcsnicmp - -#define _ftcscoll _tcscoll -#define _ftcsicoll _tcsicoll -#define _ftcsnccoll _tcsnccoll -#define _ftcsncoll _tcsncoll -#define _ftcsncicoll _tcsncicoll -#define _ftcsnicoll _tcsnicoll - -#define _ftcsclen _tcsclen -#define _ftcsnccat _tcsnccat -#define _ftcsnccpy _tcsnccpy -#define _ftcsncset _tcsncset - -#define _ftcsdec _tcsdec -#define _ftcsinc _tcsinc -#define _ftcsnbcnt _tcsnbcnt -#define _ftcsnccnt _tcsnccnt -#define _ftcsnextc _tcsnextc -#define _ftcsninc _tcsninc -#define _ftcsspnp _tcsspnp - -#define _ftcslwr _tcslwr -#define _ftcsupr _tcsupr - -#define _ftclen _tclen -#define _ftccpy _tccpy -#define _ftccmp _tccmp - -#ifndef _CONST_RETURN -#ifdef __cplusplus -#define _CONST_RETURN const -#define _CRT_CONST_CORRECT_OVERLOADS -#else -#define _CONST_RETURN -#endif -#endif - -#define _WConst_return _CONST_RETURN - -#ifdef _UNICODE - -#ifdef __cplusplus -} -#endif - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _WCTYPE_T_DEFINED -#define _WCTYPE_T_DEFINED - typedef unsigned short wint_t; - typedef unsigned short wctype_t; -#endif - -#ifndef __TCHAR_DEFINED -#define __TCHAR_DEFINED - typedef wchar_t _TCHAR; - typedef wchar_t _TSCHAR; - typedef wchar_t _TUCHAR; - typedef wchar_t _TXCHAR; - typedef wint_t _TINT; -#endif - -#ifndef _TCHAR_DEFINED -#define _TCHAR_DEFINED -#ifndef NO_OLDNAMES - typedef wchar_t TCHAR; -#endif -#endif - -#define _TEOF WEOF - -#define __T(x) L##x - -#define _tmain wmain -#define _tWinMain wWinMain -#define _tenviron _wenviron -#define __targv __wargv - -#define _tprintf wprintf -#define _tprintf_l _wprintf_l -#define _tprintf_p _wprintf_p -#define _tprintf_p_l _wprintf_p_l -#define _tcprintf _cwprintf -#define _tcprintf_l _cwprintf_l -#define _tcprintf_p _cwprintf_p -#define _tcprintf_p_l _cwprintf_p_l -#define _vtcprintf _vcwprintf -#define _vtcprintf_l _vcwprintf_l -#define _vtcprintf_p _vcwprintf_p -#define _vtcprintf_p_l _vcwprintf_p_l -#define _ftprintf fwprintf -#define _ftprintf_l _fwprintf_l -#define _ftprintf_p _fwprintf_p -#define _ftprintf_p_l _fwprintf_p_l -#define _stprintf swprintf -#define _stprintf_l __swprintf_l -#define _stprintf_p _swprintf_p -#define _stprintf_p_l _swprintf_p_l -#define _sctprintf _scwprintf -#define _sctprintf_l _scwprintf_l -#define _sctprintf_p _scwprintf_p -#define _sctprintf_p_l _scwprintf_p_l -#define _sntprintf _snwprintf -#define _sntprintf_l _snwprintf_l -#define _vtprintf vwprintf -#define _vtprintf_l _vwprintf_l -#define _vtprintf_p _vwprintf_p -#define _vtprintf_p_l _vwprintf_p_l -#define _vftprintf vfwprintf -#define _vftprintf_l _vfwprintf_l -#define _vftprintf_p _vfwprintf_p -#define _vftprintf_p_l _vfwprintf_p_l -#define _vstprintf vswprintf -#define _vstprintf_l _vswprintf_l -#define _vstprintf_p _vswprintf_p -#define _vstprintf_p_l _vswprintf_p_l -#define _vsctprintf _vscwprintf -#define _vsctprintf_l _vscwprintf_l -#define _vsctprintf_p _vscwprintf_p -#define _vsctprintf_p_l _vscwprintf_p_l -#define _vsntprintf _vsnwprintf -#define _vsntprintf_l _vsnwprintf_l - -#define _tscanf wscanf -#define _tscanf_l _wscanf_l -#define _tcscanf _cwscanf -#define _tcscanf_l _cwscanf_l -#define _ftscanf fwscanf -#define _ftscanf_l _fwscanf_l -#define _stscanf swscanf -#define _stscanf_l _swscanf_l -#define _sntscanf _snwscanf -#define _sntscanf_l _snwscanf_l - -#define _fgettc fgetwc -#define _fgettc_nolock _fgetwc_nolock -#define _fgettchar _fgetwchar -#define _fgetts fgetws -#define _fputtc fputwc -#define _fputtc_nolock _fputwc_nolock -#define _fputtchar _fputwchar -#define _fputts fputws -#define _cputts _cputws -#define _cgetts _cgetws -#define _gettc getwc -#define _gettc_nolock _getwc_nolock -#define _gettch _getwch -#define _gettch_nolock _getwch_nolock -#define _gettche _getwche -#define _gettche_nolock _getwche_nolock -#define _gettchar getwchar -#define _gettchar_nolock _getwchar_nolock -#define _getts _getws -#define _puttc putwc -#define _puttc_nolock _putwc_nolock -#define _puttchar putwchar -#define _puttchar_nolock _putwchar_nolock -#define _puttch _putwch -#define _puttch_nolock _putwch_nolock -#define _putts _putws -#define _ungettc ungetwc -#define _ungettc_nolock _ungetwc_nolock -#define _ungettch _ungetwch -#define _ungettch_nolock _ungetwch_nolock - -#define _tcstod wcstod -#define _tcstol wcstol -#define _tcstoul wcstoul -#define _tcstoi64 _wcstoi64 -#define _tcstoui64 _wcstoui64 -#define _tstof _wtof -#define _tstol _wtol -#define _tstoi _wtoi -#define _tstoi64 _wtoi64 -#define _tcstod_l _wcstod_l -#define _tcstol_l _wcstol_l -#define _tcstoul_l _wcstoul_l -#define _tcstoi64_l _wcstoi64_l -#define _tcstoui64_l _wcstoui64_l -#define _tstof_l _wtof_l -#define _tstol_l _wtol_l -#define _tstoi_l _wtoi_l -#define _tstoi64_l _wtoi64_l - -#define _itot _itow -#define _ltot _ltow -#define _ultot _ultow -#define _ttoi _wtoi -#define _ttol _wtol - -#define _ttoi64 _wtoi64 -#define _i64tot _i64tow -#define _ui64tot _ui64tow - -#define _tcscat wcscat -#define _tcschr wcschr -#define _tcscpy wcscpy -#define _tcscspn wcscspn -#define _tcslen wcslen -#define _tcsnlen wcsnlen -#define _tcsncat wcsncat -#define _tcsncat_l _wcsncat_l -#define _tcsncpy wcsncpy -#define _tcsncpy_l _wcsncpy_l -#define _tcspbrk wcspbrk -#define _tcsrchr wcsrchr -#define _tcsspn wcsspn -#define _tcsstr wcsstr -#define _tcstok wcstok -#define _tcstok_l _wcstok_l -#define _tcserror _wcserror -#define __tcserror __wcserror - -#define _tcsdup _wcsdup -#define _tcsnset _wcsnset -#define _tcsnset_l _wcsnset_l -#define _tcsrev _wcsrev -#define _tcsset _wcsset -#define _tcsset_l _wcsset_l - -#define _tcscmp wcscmp -#define _tcsicmp _wcsicmp -#define _tcsicmp_l _wcsicmp_l -#define _tcsnccmp wcsncmp -#define _tcsncmp wcsncmp -#define _tcsncicmp _wcsnicmp -#define _tcsncicmp_l _wcsnicmp_l -#define _tcsnicmp _wcsnicmp -#define _tcsnicmp_l _wcsnicmp_l - -#define _tcscoll wcscoll -#define _tcscoll_l _wcscoll_l -#define _tcsicoll _wcsicoll -#define _tcsicoll_l _wcsicoll_l -#define _tcsnccoll _wcsncoll -#define _tcsnccoll_l _wcsncoll_l -#define _tcsncoll _wcsncoll -#define _tcsncoll_l _wcsncoll_l -#define _tcsncicoll _wcsnicoll -#define _tcsncicoll_l _wcsnicoll_l -#define _tcsnicoll _wcsnicoll -#define _tcsnicoll_l _wcsnicoll_l - -#define _texecl _wexecl -#define _texecle _wexecle -#define _texeclp _wexeclp -#define _texeclpe _wexeclpe -#define _texecv _wexecv -#define _texecve _wexecve -#define _texecvp _wexecvp -#define _texecvpe _wexecvpe - -#define _tspawnl _wspawnl -#define _tspawnle _wspawnle -#define _tspawnlp _wspawnlp -#define _tspawnlpe _wspawnlpe -#define _tspawnv _wspawnv -#define _tspawnve _wspawnve -#define _tspawnvp _wspawnvp -#define _tspawnvp _wspawnvp -#define _tspawnvpe _wspawnvpe - -#define _tsystem _wsystem - -#define _tasctime _wasctime -#define _tctime _wctime -#define _tctime32 _wctime32 -#define _tctime64 _wctime64 -#define _tstrdate _wstrdate -#define _tstrtime _wstrtime -#define _tutime _wutime -#define _tutime32 _wutime32 -#define _tutime64 _wutime64 -#define _tcsftime wcsftime -#define _tcsftime_l _wcsftime_l - -#define _tchdir _wchdir -#define _tgetcwd _wgetcwd -#define _tgetdcwd _wgetdcwd -#define _tgetdcwd_nolock _wgetdcwd_nolock -#define _tmkdir _wmkdir -#define _trmdir _wrmdir - -#define _tfullpath _wfullpath -#define _tgetenv _wgetenv -#define _tmakepath _wmakepath -#define _tpgmptr _wpgmptr -#define _get_tpgmptr _get_wpgmptr -#define _tputenv _wputenv -#define _tsearchenv _wsearchenv -#define _tsplitpath _wsplitpath - -#define _tfdopen _wfdopen -#define _tfsopen _wfsopen -#define _tfopen _wfopen -#define _tfreopen _wfreopen -#define _tperror _wperror -#define _tpopen _wpopen -#define _ttempnam _wtempnam -#define _ttmpnam _wtmpnam - -#define _taccess _waccess -#define _tchmod _wchmod -#define _tcreat _wcreat -#define _tfindfirst _wfindfirst -#define _tfindfirst32 _wfindfirst32 -#define _tfindfirst64 _wfindfirst64 -#define _tfindfirsti64 _wfindfirsti64 -#define _tfindfirst32i64 _wfindfirst32i64 -#define _tfindfirst64i32 _wfindfirst64i32 -#define _tfindnext _wfindnext -#define _tfindnext32 _wfindnext32 -#define _tfindnext64 _wfindnext64 -#define _tfindnexti64 _wfindnexti64 -#define _tfindnext32i64 _wfindnext32i64 -#define _tfindnext64i32 _wfindnext64i32 -#define _tmktemp _wmktemp -#define _topen _wopen -#define _tremove _wremove -#define _trename _wrename -#define _tsopen _wsopen -#define _tunlink _wunlink - -#define _tfinddata_t _wfinddata_t -#define _tfinddata32_t _wfinddata32_t -#define _tfinddata64_t _wfinddata64_t -#define _tfinddatai64_t _wfinddatai64_t -#define _tfinddata32i64_t _wfinddata32i64_t -#define _tfinddata64i32_t _wfinddata64i32_t - -#define _tstat _wstat -#define _tstat32 _wstat32 -#define _tstat32i64 _wstat32i64 -#define _tstat64 _wstat64 -#define _tstat64i32 _wstat64i32 -#define _tstati64 _wstati64 - -#define _tsetlocale _wsetlocale - -#define _tcsclen wcslen -#define _tcscnlen wcsnlen -#define _tcsclen_l(_String,_Locale) wcslen(_String) -#define _tcscnlen_l(_String,_Max_count,_Locale) wcsnlen_l((_String),(_Max_count)) -#define _tcsnccat wcsncat -#define _tcsnccat_l _wcsncat_l -#define _tcsnccpy wcsncpy -#define _tcsnccpy_l _wcsncpy_l -#define _tcsncset _wcsnset - -#define _tcsdec _wcsdec -#define _tcsinc _wcsinc -#define _tcsnbcnt _wcsncnt -#define _tcsnccnt _wcsncnt -#define _tcsnextc _wcsnextc -#define _tcsninc _wcsninc -#define _tcsspnp _wcsspnp - -#define _tcslwr _wcslwr -#define _tcslwr_l _wcslwr_l -#define _tcsupr _wcsupr -#define _tcsupr_l _wcsupr_l -#define _tcsxfrm wcsxfrm -#define _tcsxfrm_l _wcsxfrm_l - -#define _tclen(_pc) (1) -#define _tccpy(_pc1,_cpc2) ((*(_pc1) = *(_cpc2))) -#define _tccmp(_cpc1,_cpc2) ((*(_cpc1))-(*(_cpc2))) - -#define _istalnum iswalnum -#define _istalnum_l _iswalnum_l -#define _istalpha iswalpha -#define _istalpha_l _iswalpha_l -#define _istascii iswascii -#define _istcntrl iswcntrl -#define _istcntrl_l _iswcntrl_l -#define _istdigit iswdigit -#define _istdigit_l _iswdigit_l -#define _istgraph iswgraph -#define _istgraph_l _iswgraph_l -#define _istlower iswlower -#define _istlower_l _iswlower_l -#define _istprint iswprint -#define _istprint_l _iswprint_l -#define _istpunct iswpunct -#define _istpunct_l _iswpunct_l -#define _istspace iswspace -#define _istspace_l _iswspace_l -#define _istupper iswupper -#define _istupper_l _iswupper_l -#define _istxdigit iswxdigit -#define _istxdigit_l _iswxdigit_l - -#define _totupper towupper -#define _totupper_l _towupper_l -#define _totlower towlower -#define _totlower_l _towlower_l - -#define _istlegal(_Char) (1) -#define _istlead(_Char) (0) -#define _istleadbyte(_Char) (0) -#define _istleadbyte_l(_Char,_Locale) (0) - -#define _wcsdec(_cpc1,_cpc2) ((_cpc1)>=(_cpc2) ? NULL : (_cpc2)-1) -#define _wcsinc(_pc) ((_pc)+1) -#define _wcsnextc(_cpc) ((unsigned int) *(_cpc)) -#define _wcsninc(_pc,_sz) (((_pc)+(_sz))) - _CRTIMP size_t __cdecl __wcsncnt(const wchar_t *_Str,size_t _MaxCount); -#define _wcsncnt(_cpc,_sz) (__wcsncnt(_cpc,_sz)) -#define _wcsspnp(_cpc1,_cpc2) (!_cpc1 ? NULL : ((*((_cpc1)+wcsspn(_cpc1,_cpc2))) ? ((_cpc1)+wcsspn(_cpc1,_cpc2)) : NULL)) -#define _wcsncpy_l(_Destination,_Source,_Count,_Locale) (wcsncpy(_Destination,_Source,_Count)) -#define _wcsncat_l(_Destination,_Source,_Count,_Locale) (wcsncat(_Destination,_Source,_Count)) -#define _wcstok_l(_String,_Delimiters,_Locale) (wcstok(_String,_Delimiters)) -#define _wcsnset_l(_Destination,_Value,_Count,_Locale) (_wcsnset(_Destination,_Value,_Count)) -#define _wcsset_l(_Destination,_Value,_Locale) (_wcsset(_Destination,_Value)) - - /* dirent structures and functions */ -#define _tdirent _wdirent -#define _TDIR _WDIR -#define _topendir _wopendir -#define _tclosedir _wclosedir -#define _treaddir _wreaddir -#define _trewinddir _wrewinddir -#define _ttelldir _wtelldir -#define _tseekdir _wseekdir - -#else - -#ifdef __cplusplus -} -#endif - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define _TEOF EOF - -#define __T(x) x - -#define _tmain main -#define _tWinMain WinMain -#ifdef _POSIX_ -#define _tenviron environ -#else -#define _tenviron _environ -#endif -#define __targv __argv - -#define _tprintf printf -#define _tprintf_l _printf_l -#define _tprintf_p _printf_p -#define _tprintf_p_l _printf_p_l -#define _tcprintf _cprintf -#define _tcprintf_l _cprintf_l -#define _tcprintf_p _cprintf_p -#define _tcprintf_p_l _cprintf_p_l -#define _vtcprintf _vcprintf -#define _vtcprintf_l _vcprintf_l -#define _vtcprintf_p _vcprintf_p -#define _vtcprintf_p_l _vcprintf_p_l -#define _ftprintf fprintf -#define _ftprintf_l _fprintf_l -#define _ftprintf_p _fprintf_p -#define _ftprintf_p_l _fprintf_p_l -#define _stprintf sprintf -#define _stprintf_l _sprintf_l -#define _stprintf_p _sprintf_p -#define _stprintf_p_l _sprintf_p_l -#define _sctprintf _scprintf -#define _sctprintf_l _scprintf_l -#define _sctprintf_p _scprintf_p -#define _sctprintf_p_l _scprintf_p_l -#define _sntprintf _snprintf -#define _sntprintf_l _snprintf_l -#define _vtprintf vprintf -#define _vtprintf_l _vprintf_l -#define _vtprintf_p _vprintf_p -#define _vtprintf_p_l _vprintf_p_l -#define _vftprintf vfprintf -#define _vftprintf_l _vfprintf_l -#define _vftprintf_p _vfprintf_p -#define _vftprintf_p_l _vfprintf_p_l -#define _vstprintf vsprintf -#define _vstprintf_l _vsprintf_l -#define _vstprintf_p _vsprintf_p -#define _vstprintf_p_l _vsprintf_p_l -#define _vsctprintf _vscprintf -#define _vsctprintf_l _vscprintf_l -#define _vsctprintf_p _vscprintf_p -#define _vsctprintf_p_l _vscprintf_p_l -#define _vsntprintf _vsnprintf -#define _vsntprintf_l _vsnprintf_l - -#define _tscanf scanf -#define _tscanf_l _scanf_l -#define _tcscanf _cscanf -#define _tcscanf_l _cscanf_l -#define _ftscanf fscanf -#define _ftscanf_l _fscanf_l -#define _stscanf sscanf -#define _stscanf_l _sscanf_l -#define _sntscanf _snscanf -#define _sntscanf_l _snscanf_l - -#define _fgettc fgetc -#define _fgettc_nolock _fgetc_nolock -#define _fgettchar _fgetchar -#define _fgetts fgets -#define _fputtc fputc -#define _fputtc_nolock _fputc_nolock -#define _fputtchar _fputchar -#define _fputts fputs -#define _cputts _cputs -#define _gettc getc -#define _gettc_nolock _getc_nolock -#define _gettch _getch -#define _gettch_nolock _getch_nolock -#define _gettche _getche -#define _gettche_nolock _getche_nolock -#define _gettchar getchar -#define _gettchar_nolock _getchar_nolock -#define _getts gets -#define _cgetts _cgets -#define _puttc putc -#define _puttc_nolock _putc_nolock -#define _puttchar putchar -#define _puttchar_nolock _putchar_nolock -#define _puttch _putch -#define _puttch_nolock _putch_nolock -#define _putts puts -#define _ungettc ungetc -#define _ungettc_nolock _ungetc_nolock -#define _ungettch _ungetch -#define _ungettch_nolock _ungetch_nolock - -#define _tcstod strtod -#define _tcstol strtol -#define _tcstoul strtoul -#define _tstof atof -#define _tstol atol -#define _tstoi atoi -#define _tstoi64 _atoi64 -#define _tcstod_l _strtod_l -#define _tcstol_l _strtol_l -#define _tcstoul_l _strtoul_l -#define _tstof_l _atof_l -#define _tstol_l _atol_l -#define _tstoi_l _atoi_l -#define _tstoi64_l _atoi64_l - -#define _itot _itoa -#define _ltot _ltoa -#define _ultot _ultoa -#define _ttoi atoi -#define _ttol atol - -#define _ttoi64 _atoi64 -#define _tcstoi64 _strtoi64 -#define _tcstoi64_l _strtoi64_l -#define _tcstoui64 _strtoui64 -#define _tcstoui64_l _strtoui64_l -#define _i64tot _i64toa -#define _ui64tot _ui64toa - -#define _tcscat strcat -#define _tcscpy strcpy -#define _tcsdup _strdup -#define _tcslen strlen -#if 0 -#define _tcsnlen strnlen -#endif -#define _tcsxfrm strxfrm -#define _tcsxfrm_l _strxfrm_l -#define _tcserror strerror -#define __tcserror _strerror - -#define _texecl _execl -#define _texecle _execle -#define _texeclp _execlp -#define _texeclpe _execlpe -#define _texecv _execv -#define _texecve _execve -#define _texecvp _execvp -#define _texecvpe _execvpe - -#define _tspawnl _spawnl -#define _tspawnle _spawnle -#define _tspawnlp _spawnlp -#define _tspawnlpe _spawnlpe -#define _tspawnv _spawnv -#define _tspawnve _spawnve -#define _tspawnvp _spawnvp -#define _tspawnvpe _spawnvpe - -#define _tsystem system - -#define _tasctime asctime -#define _tctime ctime -#define _tctime32 _ctime32 -#define _tctime64 _ctime64 -#define _tstrdate _strdate -#define _tstrtime _strtime -#define _tutime _utime -#define _tutime32 _utime32 -#define _tutime64 _utime64 -#define _tcsftime strftime -#define _tcsftime_l _strftime_l - -#define _tchdir _chdir -#define _tgetcwd _getcwd -#define _tgetdcwd _getdcwd -#define _tgetdcwd_nolock _getdcwd_nolock -#define _tmkdir _mkdir -#define _trmdir _rmdir - -#define _tfullpath _fullpath -#define _tgetenv getenv -#define _tmakepath _makepath -#define _tpgmptr _pgmptr -#define _get_tpgmptr _get_pgmptr -#define _tputenv _putenv -#define _tsearchenv _searchenv -#define _tsplitpath _splitpath - -#ifdef _POSIX_ -#define _tfdopen fdopen -#else -#define _tfdopen _fdopen -#endif -#define _tfsopen _fsopen -#define _tfopen fopen -#define _tfreopen freopen -#define _tperror perror -#define _tpopen _popen -#define _ttempnam _tempnam -#define _ttmpnam tmpnam - -#define _tchmod _chmod -#define _tcreat _creat -#define _tfindfirst _findfirst -#define _tfindfirst32 _findfirst32 -#define _tfindfirst64 _findfirst64 -#define _tfindfirsti64 _findfirsti64 -#define _tfindfirst32i64 _findfirst32i64 -#define _tfindfirst64i32 _findfirst64i32 -#define _tfindnext _findnext -#define _tfindnext32 _findnext32 -#define _tfindnext64 _findnext64 -#define _tfindnexti64 _findnexti64 -#define _tfindnext32i64 _findnext32i64 -#define _tfindnext64i32 _findnext64i32 -#define _tmktemp _mktemp - -#ifdef _POSIX_ -#define _topen open -#define _taccess access -#else -#define _topen _open -#define _taccess _access -#endif - -#define _tremove remove -#define _trename rename -#define _tsopen _sopen -#define _tunlink _unlink - -#define _tfinddata_t _finddata_t -#define _tfinddata32_t _finddata32_t -#define _tfinddata64_t __finddata64_t -#define _tfinddatai64_t _finddatai64_t -#define _tfinddata32i64_t _finddata32i64_t -#define _tfinddata64i32_t _finddata64i32_t - -#define _istascii __isascii -#define _istcntrl iscntrl -#define _istcntrl_l _iscntrl_l -#define _istxdigit isxdigit -#define _istxdigit_l _isxdigit_l - -#define _tstat _stat -#define _tstat32 _stat32 -#define _tstat32i64 _stat32i64 -#define _tstat64 _stat64 -#define _tstat64i32 _stat64i32 -#define _tstati64 _stati64 - -#define _tsetlocale setlocale - -#ifdef _MBCS - -#ifdef __cplusplus -} -#endif - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef __TCHAR_DEFINED - typedef char _TCHAR; - typedef signed char _TSCHAR; - typedef unsigned char _TUCHAR; - typedef unsigned char _TXCHAR; - typedef unsigned int _TINT; -#define __TCHAR_DEFINED -#endif - -#ifndef _TCHAR_DEFINED -#ifndef NO_OLDNAMES - typedef char TCHAR; -#endif -#define _TCHAR_DEFINED -#endif - -#ifdef _MB_MAP_DIRECT - -#define _tcschr _mbschr -#define _tcscspn _mbscspn -#define _tcsncat _mbsnbcat -#define _tcsncat_l _mbsnbcat_l -#define _tcsncpy _mbsnbcpy -#define _tcsncpy_l _mbsnbcpy_l -#define _tcspbrk _mbspbrk -#define _tcsrchr _mbsrchr -#define _tcsspn _mbsspn -#define _tcsstr _mbsstr -#define _tcstok _mbstok -#define _tcstok_l _mbstok_l - -#define _tcsnset _mbsnbset -#define _tcsnset_l _mbsnbset_l -#define _tcsrev _mbsrev -#define _tcsset _mbsset -#define _tcsset_l _mbsset_l - -#define _tcscmp _mbscmp -#define _tcsicmp _mbsicmp -#define _tcsicmp_l _mbsicmp_l -#define _tcsnccmp _mbsncmp -#define _tcsncmp _mbsnbcmp -#define _tcsncicmp _mbsnicmp -#define _tcsncicmp_l _mbsnicmp_l -#define _tcsnicmp _mbsnbicmp -#define _tcsnicmp_l _mbsnbicmp_l - -#define _tcscoll _mbscoll -#define _tcscoll_l _mbscoll_l -#define _tcsicoll _mbsicoll -#define _tcsicoll_l _mbsicoll_l -#define _tcsnccoll _mbsncoll -#define _tcsnccoll_l _mbsncoll_l -#define _tcsncoll _mbsnbcoll -#define _tcsncoll_l _mbsnbcoll_l -#define _tcsncicoll _mbsnicoll -#define _tcsncicoll_l _mbsnicoll_l -#define _tcsnicoll _mbsnbicoll -#define _tcsnicoll_l _mbsnbicoll_l - -#define _tcsclen _mbslen -#define _tcscnlen _mbsnlen -#define _tcsclen_l _mbslen_l -#define _tcscnlen_l _mbsnlen_l -#define _tcsnccat _mbsncat -#define _tcsnccat_l _mbsncat_l -#define _tcsnccpy _mbsncpy -#define _tcsnccpy_l _mbsncpy_l -#define _tcsncset _mbsnset -#define _tcsncset_l _mbsnset_l - -#define _tcsdec _mbsdec -#define _tcsinc _mbsinc -#define _tcsnbcnt _mbsnbcnt -#define _tcsnccnt _mbsnccnt -#define _tcsnextc _mbsnextc -#define _tcsninc _mbsninc -#define _tcsspnp _mbsspnp - -#define _tcslwr _mbslwr -#define _tcslwr_l _mbslwr_l -#define _tcsupr _mbsupr -#define _tcsupr_l _mbsupr_l - -#define _tclen _mbclen -#define _tccpy _mbccpy -#define _tccpy_l _mbccpy_l -#else - - _CRTIMP _CONST_RETURN char *__cdecl _tcschr(const char *_Str,unsigned int _Val); - _CRTIMP size_t __cdecl _tcscspn(const char *_Str,const char *_Control); - _CRTIMP char *__cdecl _tcsncat(char *_Dst,const char *_Src,size_t _MaxCount); - _CRTIMP char *__cdecl _tcsncat_l(char *_Dst,const char *_Src,size_t _MaxCount,_locale_t _Locale); - _CRTIMP char *__cdecl _tcsncpy(char *_Dst,const char *_Src,size_t _MaxCount); - _CRTIMP char *__cdecl _tcsncpy_l(char *_Dst,const char *_Src,size_t _MaxCount,_locale_t _Locale); - _CRTIMP _CONST_RETURN char *__cdecl _tcspbrk(const char *_Str,const char *_Control); - _CRTIMP _CONST_RETURN char *__cdecl _tcsrchr(const char *_Str,unsigned int _Ch); - _CRTIMP size_t __cdecl _tcsspn(const char *_Str,const char *_Control); - _CRTIMP _CONST_RETURN char *__cdecl _tcsstr(const char *_Str,const char *_Substr); - _CRTIMP char *__cdecl _tcstok(char *_Str,const char *_Delim); - _CRTIMP char *__cdecl _tcstok_l(char *_Str,const char *_Delim,_locale_t _Locale); - _CRTIMP char *__cdecl _tcsnset(char *_Str,unsigned int _Val,size_t _MaxCount); - _CRTIMP char *__cdecl _tcsrev(char *_Str); - _CRTIMP char *__cdecl _tcsset(char *_Str,unsigned int _Val); - _CRTIMP char *__cdecl _tcsset_l(char *_Str,unsigned int _Val,_locale_t _Locale); - _CRTIMP int __cdecl _tcscmp(const char *_Str1,const char *_Str); - _CRTIMP int __cdecl _tcsicmp(const char *_Str1,const char *_Str2); - _CRTIMP int __cdecl _tcsicmp_l(const char *_Str1,const char *_Str2,_locale_t _Locale); - _CRTIMP int __cdecl _tcsnccmp(const char *_Str1,const char *_Str2,size_t _MaxCount); - _CRTIMP int __cdecl _tcsncmp(const char *_Str1,const char *_Str2,size_t _MaxCount); - _CRTIMP int __cdecl _tcsncicmp(const char *_Str1,const char *_Str2,size_t _MaxCount); - _CRTIMP int __cdecl _tcsncicmp_l(const char *_Str1,const char *_Str2,size_t _MaxCount,_locale_t _Locale); - _CRTIMP int __cdecl _tcsnicmp(const char *_Str1,const char *_Str2,size_t _MaxCount); - _CRTIMP int __cdecl _tcsnicmp_l(const char *_Str1,const char *_Str2,size_t _MaxCount,_locale_t _Locale); - _CRTIMP int __cdecl _tcscoll(const char *_Str1,const char *_Str2); - _CRTIMP int __cdecl _tcscoll_l(const char *_Str1,const char *_Str2,_locale_t _Locale); - _CRTIMP int __cdecl _tcsicoll(const char *_Str1,const char *_Str2); - _CRTIMP int __cdecl _tcsicoll_l(const char *_Str1,const char *_Str2,_locale_t _Locale); - _CRTIMP int __cdecl _tcsnccoll(const char *_Str1,const char *_Str2,size_t _MaxCount); - _CRTIMP int __cdecl _tcsnccoll_l(const char *_Str1,const char *_Str2,size_t _MaxCount,_locale_t _Locale); - _CRTIMP int __cdecl _tcsncoll(const char *_Str1,const char *_Str2,size_t _MaxCount); - _CRTIMP int __cdecl _tcsncoll_l(const char *_Str1,const char *_Str2,size_t _MaxCount,_locale_t _Locale); - _CRTIMP int __cdecl _tcsncicoll(const char *_Str1,const char *_Str2,size_t _MaxCount); - _CRTIMP int __cdecl _tcsncicoll_l(const char *_Str1,const char *_Str2,size_t _MaxCount,_locale_t _Locale); - _CRTIMP int __cdecl _tcsnicoll(const char *_Str1,const char *_Str2,size_t _MaxCount); - _CRTIMP int __cdecl _tcsnicoll_l(const char *_Str1,const char *_Str2,size_t _MaxCount,_locale_t _Locale); - _CRTIMP size_t __cdecl _tcsclen(const char *_Str); - _CRTIMP size_t __cdecl _tcscnlen(const char *_Str,size_t _MaxCount); - _CRTIMP size_t __cdecl _tcsclen_l(const char *_Str,_locale_t _Locale); - _CRTIMP size_t __cdecl _tcscnlen_l(const char *_Str,size_t _MaxCount,_locale_t _Locale); - _CRTIMP char *__cdecl _tcsnccat(char *_Dst,const char *_Src,size_t _MaxCount); - _CRTIMP char *__cdecl _tcsnccat_l(char *_Dst,const char *_Src,size_t _MaxCount,_locale_t _Locale); - _CRTIMP char *__cdecl _tcsnccpy(char *_Dst,const char *_Src,size_t _MaxCount); - _CRTIMP char *__cdecl _tcsnccpy_l(char *_Dst,const char *_Src,size_t _MaxCount,_locale_t _Locale); - _CRTIMP char *__cdecl _tcsncset(char *_Str,unsigned int _Val,size_t _MaxCount); - _CRTIMP char *__cdecl _tcsdec(const char *_Start,const char *_Pos); - _CRTIMP char *__cdecl _tcsinc(const char *_Ptr); - _CRTIMP size_t __cdecl _tcsnbcnt(const char *_Str,size_t _MaxCount); - _CRTIMP size_t __cdecl _tcsnccnt(const char *_Str,size_t _MaxCount); - _CRTIMP unsigned int __cdecl _tcsnextc (const char *_Str); - _CRTIMP char *__cdecl _tcsninc(const char *_Ptr,size_t _Count); - _CRTIMP char *__cdecl _tcsspnp(const char *_Str1,const char *_Str2); - _CRTIMP char *__cdecl _tcslwr(char *_Str); - _CRTIMP char *__cdecl _tcslwr_l(char *_Str,_locale_t _Locale); - _CRTIMP char *__cdecl _tcsupr(char *_Str); - _CRTIMP char *__cdecl _tcsupr_l(char *_Str,_locale_t _Locale); - _CRTIMP size_t __cdecl _tclen(const char *_Str); - _CRTIMP void __cdecl _tccpy(char *_DstCh,const char *_SrcCh); - -#ifdef __cplusplus -#ifndef _CPP_TCHAR_INLINES_DEFINED -#define _CPP_TCHAR_INLINES_DEFINED - extern "C++" { - extern inline char *__cdecl _tcschr(char *_S,unsigned int _C) { return ((char *)_tcschr((const char *)_S,_C)); } - extern inline char *__cdecl _tcspbrk(char *_S,const char *_P) { return ((char *)_tcspbrk((const char *)_S,_P)); } - extern inline char *__cdecl _tcsrchr(char *_S,unsigned int _C) { return ((char *)_tcsrchr((const char *)_S,_C)); } - extern inline char *__cdecl _tcsstr(char *_S,const char *_P) { return ((char *)_tcsstr((const char *)_S,_P)); } - } -#endif -#endif -#endif - -#define _tccmp(_cp1,_cp2) _tcsnccmp(_cp1,_cp2,1) - -#define _istalnum _ismbcalnum -#define _istalnum_l _ismbcalnum_l -#define _istalpha _ismbcalpha -#define _istalpha_l _ismbcalpha_l -#define _istdigit _ismbcdigit -#define _istdigit_l _ismbcdigit_l -#define _istgraph _ismbcgraph -#define _istgraph_l _ismbcgraph_l -#define _istlegal _ismbclegal -#define _istlegal_l _ismbclegal_l -#define _istlower _ismbclower -#define _istlower_l _ismbclower_l -#define _istprint _ismbcprint -#define _istprint_l _ismbcprint_l -#define _istpunct _ismbcpunct -#define _istpunct_l _ismbcpunct_l -#define _istspace _ismbcspace -#define _istspace_l _ismbcspace_l -#define _istupper _ismbcupper -#define _istupper_l _ismbcupper_l - -#define _totupper _mbctoupper -#define _totupper_l _mbctoupper_l -#define _totlower _mbctolower -#define _totlower_l _mbctolower_l - -#define _istlead _ismbblead -#define _istleadbyte isleadbyte -#define _istleadbyte_l _isleadbyte_l -#else - -#ifndef __TCHAR_DEFINED -#define __TCHAR_DEFINED - typedef char _TCHAR; - typedef signed char _TSCHAR; - typedef unsigned char _TUCHAR; - typedef char _TXCHAR; - typedef int _TINT; -#endif - -#ifndef _TCHAR_DEFINED -#define _TCHAR_DEFINED -#ifndef NO_OLDNAMES - typedef char TCHAR; -#endif -#endif - -#define _tcschr strchr -#define _tcscspn strcspn -#define _tcsncat strncat -#define _tcsncat_l _strncat_l -#define _tcsncpy strncpy -#define _tcsncpy_l _strncpy_l -#define _tcspbrk strpbrk -#define _tcsrchr strrchr -#define _tcsspn strspn -#define _tcsstr strstr -#define _tcstok strtok -#define _tcstok_l _strtok_l - -#define _tcsnset _strnset -#define _tcsnset_l _strnset_l -#define _tcsrev _strrev -#define _tcsset _strset - -#define _tcscmp strcmp -#define _tcsicmp _stricmp -#define _tcsicmp_l _stricmp_l -#define _tcsnccmp strncmp -#define _tcsncmp strncmp -#define _tcsncicmp _strnicmp -#define _tcsncicmp_l _strnicmp_l -#define _tcsnicmp _strnicmp -#define _tcsnicmp_l _strnicmp_l - -#define _tcscoll strcoll -#define _tcscoll_l _strcoll_l -#define _tcsicoll _stricoll -#define _tcsicoll_l _stricoll_l -#define _tcsnccoll _strncoll -#define _tcsnccoll_l _strncoll_l -#define _tcsncoll _strncoll -#define _tcsncoll_l _strncoll_l -#define _tcsncicoll _strnicoll -#define _tcsncicoll_l _strnicoll_l -#define _tcsnicoll _strnicoll -#define _tcsnicoll_l _strnicoll_l - -#define _tcsclen strlen -#define _tcscnlen strnlen -#define _tcsclen_l(_String,_Locale) strlen(_String) -#define _tcscnlen_l(_String,_Max_count,_Locale) strnlen_l((_String),(_Max_count)) -#define _tcsnccat strncat -#define _tcsnccat_l _strncat_l -#define _tcsnccpy strncpy -#define _tcsnccpy_l _strncpy_l -#define _tcsncset _strnset - -#define _tcsdec _strdec -#define _tcsinc _strinc -#define _tcsnbcnt _strncnt -#define _tcsnccnt _strncnt -#define _tcsnextc _strnextc -#define _tcsninc _strninc -#define _tcsspnp _strspnp - -#define _tcslwr _strlwr -#define _tcslwr_l _strlwr_l -#define _tcsupr _strupr -#define _tcsupr_l _strupr_l -#define _tcsxfrm strxfrm -#define _tcsxfrm_l _strxfrm_l - -#define _istlead(_Char) (0) -#define _istleadbyte(_Char) (0) -#define _istleadbyte_l(_Char,_Locale) (0) - -#define _tclen(_pc) (1) -#define _tccpy(_pc1,_cpc2) (*(_pc1) = *(_cpc2)) -#define _tccmp(_cpc1,_cpc2) (((unsigned char)*(_cpc1))-((unsigned char)*(_cpc2))) - - /* dirent structures and functions */ -#define _tdirent dirent -#define _TDIR DIR -#define _topendir opendir -#define _tclosedir closedir -#define _treaddir readdir -#define _trewinddir rewinddir -#define _ttelldir telldir -#define _tseekdir seekdir - -#define _istalnum isalnum -#define _istalnum_l _isalnum_l -#define _istalpha isalpha -#define _istalpha_l _isalpha_l -#define _istdigit isdigit -#define _istdigit_l _isdigit_l -#define _istgraph isgraph -#define _istgraph_l _isgraph_l -#define _istlower islower -#define _istlower_l _islower_l -#define _istprint isprint -#define _istprint_l _isprint_l -#define _istpunct ispunct -#define _istpunct_l _ispunct_l -#define _istspace isspace -#define _istspace_l _isspace_l -#define _istupper isupper -#define _istupper_l _isupper_l - -#define _totupper toupper -#define _totupper_l _toupper_l -#define _totlower tolower -#define _totlower_l _tolower_l - -#define _istlegal(_c) (1) - -#ifndef NULL -#ifdef __cplusplus -#define NULL 0 -#else -#define NULL ((void *)0) -#endif -#endif - -#define _strdec(_cpc1,_cpc2) ((_cpc1)>=(_cpc2) ? NULL : (_cpc2)-1) -#define _strinc(_pc) ((_pc)+1) -#define _strnextc(_cpc) ((unsigned int) *(const unsigned char *)(_cpc)) -#define _strninc(_pc,_sz) (((_pc)+(_sz))) - _CRTIMP size_t __cdecl __strncnt(const char *_Str,size_t _Cnt); -#define _strncnt(_cpc,_sz) (__strncnt(_cpc,_sz)) -#define _strspnp(_cpc1,_cpc2) (!_cpc1 ? NULL : ((*((_cpc1)+strspn(_cpc1,_cpc2))) ? ((_cpc1)+strspn(_cpc1,_cpc2)) : NULL)) - -#define _strncpy_l(_Destination,_Source,_Count,_Locale) (strncpy(_Destination,_Source,_Count)) -#define _strncat_l(_Destination,_Source,_Count,_Locale) (strncat(_Destination,_Source,_Count)) -#define _strtok_l(_String,_Delimiters,_Locale) (strtok(_String,_Delimiters)) -#define _strnset_l(_Destination,_Value,_Count,_Locale) (_strnset(_Destination,_Value,_Count)) -#define _strset_l(_Destination,_Value,_Locale) (_strset(_Destination,_Value)) -#endif -#endif - -#define _T(x) __T(x) -#define _TEXT(x) __T(x) - -#ifdef __cplusplus -} -#endif - -#include -#endif diff --git a/05/tcc-final-old/win32/include/time.h b/05/tcc-final-old/win32/include/time.h deleted file mode 100644 index 6c72e26..0000000 --- a/05/tcc-final-old/win32/include/time.h +++ /dev/null @@ -1,287 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _TIME_H_ -#define _TIME_H_ - -#include <_mingw.h> - -#ifndef _WIN32 -#error Only Win32 target is supported! -#endif - -#pragma pack(push,_CRT_PACKING) - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _CRTIMP -#define _CRTIMP __declspec(dllimport) -#endif - -#ifndef _WCHAR_T_DEFINED -#define _WCHAR_T_DEFINED - typedef unsigned short wchar_t; -#endif - -#ifndef _TIME32_T_DEFINED -#define _TIME32_T_DEFINED - typedef long __time32_t; -#endif - -#ifndef _TIME64_T_DEFINED -#define _TIME64_T_DEFINED -#if _INTEGRAL_MAX_BITS >= 64 -#if defined(__GNUC__) && defined(__STRICT_ANSI__) - typedef int _time64_t __attribute__ ((mode (DI))); -#else - typedef __int64 __time64_t; -#endif -#endif -#endif - -#ifndef _TIME_T_DEFINED -#define _TIME_T_DEFINED -#ifdef _USE_32BIT_TIME_T - typedef __time32_t time_t; -#else - typedef __time64_t time_t; -#endif -#endif - -#ifndef _CLOCK_T_DEFINED -#define _CLOCK_T_DEFINED - typedef long clock_t; -#endif - -#ifndef _SIZE_T_DEFINED -#define _SIZE_T_DEFINED -#undef size_t -#ifdef _WIN64 -#if defined(__GNUC__) && defined(__STRICT_ANSI__) - typedef unsigned int size_t __attribute__ ((mode (DI))); -#else - typedef unsigned __int64 size_t; -#endif -#else - typedef unsigned int size_t; -#endif -#endif - -#ifndef _SSIZE_T_DEFINED -#define _SSIZE_T_DEFINED -#undef ssize_t -#ifdef _WIN64 -#if defined(__GNUC__) && defined(__STRICT_ANSI__) - typedef int ssize_t __attribute__ ((mode (DI))); -#else - typedef __int64 ssize_t; -#endif -#else - typedef int ssize_t; -#endif -#endif - -#ifndef NULL -#ifdef __cplusplus -#define NULL 0 -#else -#define NULL ((void *)0) -#endif -#endif - -#ifdef _USE_32BIT_TIME_T -#define _localtime32 localtime -#define _difftime32 difftime -#define _ctime32 ctime -#define _gmtime32 gmtime -#define _mktime32 mktime -#define _time32 time -#endif - -#ifndef _TM_DEFINED -#define _TM_DEFINED - struct tm { - int tm_sec; - int tm_min; - int tm_hour; - int tm_mday; - int tm_mon; - int tm_year; - int tm_wday; - int tm_yday; - int tm_isdst; - }; -#endif - -#define CLOCKS_PER_SEC 1000 - - __MINGW_IMPORT int _daylight; - __MINGW_IMPORT long _dstbias; - __MINGW_IMPORT long _timezone; - __MINGW_IMPORT char * _tzname[2]; - _CRTIMP errno_t __cdecl _get_daylight(int *_Daylight); - _CRTIMP errno_t __cdecl _get_dstbias(long *_Daylight_savings_bias); - _CRTIMP errno_t __cdecl _get_timezone(long *_Timezone); - _CRTIMP errno_t __cdecl _get_tzname(size_t *_ReturnValue,char *_Buffer,size_t _SizeInBytes,int _Index); - char *__cdecl asctime(const struct tm *_Tm); - _CRTIMP char *__cdecl _ctime32(const __time32_t *_Time); - clock_t __cdecl clock(void); - _CRTIMP double __cdecl _difftime32(__time32_t _Time1,__time32_t _Time2); - _CRTIMP struct tm *__cdecl _gmtime32(const __time32_t *_Time); - _CRTIMP struct tm *__cdecl _localtime32(const __time32_t *_Time); - size_t __cdecl strftime(char *_Buf,size_t _SizeInBytes,const char *_Format,const struct tm *_Tm); - _CRTIMP size_t __cdecl _strftime_l(char *_Buf,size_t _Max_size,const char *_Format,const struct tm *_Tm,_locale_t _Locale); - _CRTIMP char *__cdecl _strdate(char *_Buffer); - _CRTIMP char *__cdecl _strtime(char *_Buffer); - _CRTIMP __time32_t __cdecl _time32(__time32_t *_Time); - _CRTIMP __time32_t __cdecl _mktime32(struct tm *_Tm); - _CRTIMP __time32_t __cdecl _mkgmtime32(struct tm *_Tm); -#if defined (_POSIX_) || defined(__GNUC__) - void __cdecl tzset(void); -#else - _CRTIMP void __cdecl _tzset(void); -#endif - -#if _INTEGRAL_MAX_BITS >= 64 - double __cdecl _difftime64(__time64_t _Time1,__time64_t _Time2); - _CRTIMP char *__cdecl _ctime64(const __time64_t *_Time); - _CRTIMP struct tm *__cdecl _gmtime64(const __time64_t *_Time); - _CRTIMP struct tm *__cdecl _localtime64(const __time64_t *_Time); - _CRTIMP __time64_t __cdecl _mktime64(struct tm *_Tm); - _CRTIMP __time64_t __cdecl _mkgmtime64(struct tm *_Tm); - _CRTIMP __time64_t __cdecl _time64(__time64_t *_Time); -#endif - unsigned __cdecl _getsystime(struct tm *_Tm); - unsigned __cdecl _setsystime(struct tm *_Tm,unsigned _MilliSec); - -#ifndef _SIZE_T_DEFINED -#define _SIZE_T_DEFINED -#ifdef _WIN64 -#if defined(__GNUC__) && defined(__STRICT_ANSI__) - typedef unsigned int size_t __attribute__ ((mode (DI))); -#else - typedef unsigned __int64 size_t; -#endif -#else - typedef unsigned long size_t; -#endif -#endif - -#ifndef _SSIZE_T_DEFINED -#define _SSIZE_T_DEFINED -#ifdef _WIN64 -#if defined(__GNUC__) && defined(__STRICT_ANSI__) - typedef int ssize_t __attribute__ ((mode (DI))); -#else - typedef __int64 ssize_t; -#endif -#else - typedef long ssize_t; -#endif -#endif - -#ifndef _WTIME_DEFINED - _CRTIMP wchar_t *__cdecl _wasctime(const struct tm *_Tm); - _CRTIMP wchar_t *__cdecl _wctime32(const __time32_t *_Time); - size_t __cdecl wcsftime(wchar_t *_Buf,size_t _SizeInWords,const wchar_t *_Format,const struct tm *_Tm); - _CRTIMP size_t __cdecl _wcsftime_l(wchar_t *_Buf,size_t _SizeInWords,const wchar_t *_Format,const struct tm *_Tm,_locale_t _Locale); - _CRTIMP wchar_t *__cdecl _wstrdate(wchar_t *_Buffer); - _CRTIMP wchar_t *__cdecl _wstrtime(wchar_t *_Buffer); -#if _INTEGRAL_MAX_BITS >= 64 - _CRTIMP wchar_t *__cdecl _wctime64(const __time64_t *_Time); -#endif - -#if !defined (RC_INVOKED) && !defined (_INC_WTIME_INL) -#define _INC_WTIME_INL -#ifdef _USE_32BIT_TIME_T -__CRT_INLINE wchar_t *__cdecl _wctime(const time_t *_Time) { return _wctime32(_Time); } -#else -__CRT_INLINE wchar_t *__cdecl _wctime(const time_t *_Time) { return _wctime64(_Time); } -#endif -#endif - -#define _WTIME_DEFINED -#endif - -#ifndef RC_INVOKED -double __cdecl difftime(time_t _Time1,time_t _Time2); -char *__cdecl ctime(const time_t *_Time); -struct tm *__cdecl gmtime(const time_t *_Time); -struct tm *__cdecl localtime(const time_t *_Time); -struct tm *__cdecl localtime_r(const time_t *_Time,struct tm *); - -time_t __cdecl mktime(struct tm *_Tm); -time_t __cdecl _mkgmtime(struct tm *_Tm); -time_t __cdecl time(time_t *_Time); - -#ifdef _USE_32BIT_TIME_T -#if 0 -__CRT_INLINE double __cdecl difftime(time_t _Time1,time_t _Time2) { return _difftime32(_Time1,_Time2); } -__CRT_INLINE char *__cdecl ctime(const time_t *_Time) { return _ctime32(_Time); } -__CRT_INLINE struct tm *__cdecl gmtime(const time_t *_Time) { return _gmtime32(_Time); } -__CRT_INLINE struct tm *__cdecl localtime(const time_t *_Time) { return _localtime32(_Time); } -__CRT_INLINE time_t __cdecl mktime(struct tm *_Tm) { return _mktime32(_Tm); } -__CRT_INLINE time_t __cdecl _mkgmtime(struct tm *_Tm) { return _mkgmtime32(_Tm); } -__CRT_INLINE time_t __cdecl time(time_t *_Time) { return _time32(_Time); } -#endif -#else -__CRT_INLINE double __cdecl difftime(time_t _Time1,time_t _Time2) { return _difftime64(_Time1,_Time2); } -__CRT_INLINE char *__cdecl ctime(const time_t *_Time) { return _ctime64(_Time); } -__CRT_INLINE struct tm *__cdecl gmtime(const time_t *_Time) { return _gmtime64(_Time); } -__CRT_INLINE struct tm *__cdecl localtime(const time_t *_Time) { return _localtime64(_Time); } -__CRT_INLINE time_t __cdecl mktime(struct tm *_Tm) { return _mktime64(_Tm); } -__CRT_INLINE time_t __cdecl _mkgmtime(struct tm *_Tm) { return _mkgmtime64(_Tm); } -__CRT_INLINE time_t __cdecl time(time_t *_Time) { return _time64(_Time); } -#endif -#endif - -#if !defined(NO_OLDNAMES) || defined(_POSIX) -#define CLK_TCK CLOCKS_PER_SEC - - __MINGW_IMPORT int daylight; - __MINGW_IMPORT long dstbias; - __MINGW_IMPORT long timezone; - __MINGW_IMPORT char *tzname[2]; - void __cdecl tzset(void); -#endif - -#ifndef _TIMEVAL_DEFINED /* also in winsock[2].h */ -#define _TIMEVAL_DEFINED -struct timeval { - long tv_sec; - long tv_usec; -}; -#define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) -#define timercmp(tvp,uvp,cmp) ((tvp)->tv_sec cmp (uvp)->tv_sec || (tvp)->tv_sec==(uvp)->tv_sec && (tvp)->tv_usec cmp (uvp)->tv_usec) -#define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0 -#endif /* _TIMEVAL_DEFINED */ - -#ifndef __STRICT_ANSI__ -#ifndef _TIMEZONE_DEFINED /* also in sys/time.h */ -#define _TIMEZONE_DEFINED -struct timezone { - int tz_minuteswest; - int tz_dsttime; -}; - - extern int __cdecl mingw_gettimeofday (struct timeval *p, struct timezone *z); -#endif -#endif /* __STRICT_ANSI__ */ - -#ifdef __cplusplus -} -#endif - -#pragma pack(pop) - -#include - -/* Adding timespec definition. */ -#include - -#endif /* End _TIME_H_ */ - diff --git a/05/tcc-final-old/win32/include/vadefs.h b/05/tcc-final-old/win32/include/vadefs.h deleted file mode 100644 index 749b0bd..0000000 --- a/05/tcc-final-old/win32/include/vadefs.h +++ /dev/null @@ -1,11 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _INC_VADEFS -#define _INC_VADEFS - -//!__TINYC__: GNUC specific stuff removed - -#endif diff --git a/05/tcc-final-old/win32/include/values.h b/05/tcc-final-old/win32/include/values.h deleted file mode 100644 index 1cd643c..0000000 --- a/05/tcc-final-old/win32/include/values.h +++ /dev/null @@ -1,4 +0,0 @@ -/* - * TODO: Nothing here yet. Should provide UNIX compatibility constants - * comparable to those in limits.h and float.h. - */ diff --git a/05/tcc-final-old/win32/include/wchar.h b/05/tcc-final-old/win32/include/wchar.h deleted file mode 100644 index 389196f..0000000 --- a/05/tcc-final-old/win32/include/wchar.h +++ /dev/null @@ -1,873 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _INC_WCHAR -#define _INC_WCHAR - -#include <_mingw.h> - -#pragma pack(push,_CRT_PACKING) - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef WCHAR_MIN /* also at stdint.h */ -#define WCHAR_MIN 0 -#define WCHAR_MAX ((wchar_t) -1) /* UINT16_MAX */ -#endif - -#ifndef __GNUC_VA_LIST -#define __GNUC_VA_LIST - typedef __builtin_va_list __gnuc_va_list; -#endif - -#ifndef _VA_LIST_DEFINED -#define _VA_LIST_DEFINED - typedef __gnuc_va_list va_list; -#endif - -#ifndef WEOF -#define WEOF (wint_t)(0xFFFF) -#endif - -#ifndef _FILE_DEFINED - struct _iobuf { - char *_ptr; - int _cnt; - char *_base; - int _flag; - int _file; - int _charbuf; - int _bufsiz; - char *_tmpfname; - }; - typedef struct _iobuf FILE; -#define _FILE_DEFINED -#endif - -#ifndef _STDIO_DEFINED -#ifdef _WIN64 - _CRTIMP FILE *__cdecl __iob_func(void); -#else -#ifdef _MSVCRT_ -extern FILE _iob[]; /* A pointer to an array of FILE */ -#define __iob_func() (_iob) -#else -extern FILE (*_imp___iob)[]; /* A pointer to an array of FILE */ -#define __iob_func() (*_imp___iob) -#define _iob __iob_func() -#endif -#endif - -#define _iob __iob_func() -#endif - -#ifndef _STDSTREAM_DEFINED -#define stdin (&__iob_func()[0]) -#define stdout (&__iob_func()[1]) -#define stderr (&__iob_func()[2]) -#define _STDSTREAM_DEFINED -#endif - -#ifndef _FSIZE_T_DEFINED - typedef unsigned long _fsize_t; -#define _FSIZE_T_DEFINED -#endif - -#ifndef _WFINDDATA_T_DEFINED - struct _wfinddata32_t { - unsigned attrib; - __time32_t time_create; - __time32_t time_access; - __time32_t time_write; - _fsize_t size; - wchar_t name[260]; - }; - -/* #if _INTEGRAL_MAX_BITS >= 64 */ - - struct _wfinddata32i64_t { - unsigned attrib; - __time32_t time_create; - __time32_t time_access; - __time32_t time_write; - __int64 size; - wchar_t name[260]; - }; - - struct _wfinddata64i32_t { - unsigned attrib; - __time64_t time_create; - __time64_t time_access; - __time64_t time_write; - _fsize_t size; - wchar_t name[260]; - }; - - struct _wfinddata64_t { - unsigned attrib; - __time64_t time_create; - __time64_t time_access; - __time64_t time_write; - __int64 size; - wchar_t name[260]; - }; -/* #endif */ - -#ifdef _USE_32BIT_TIME_T -#define _wfinddata_t _wfinddata32_t -#define _wfinddatai64_t _wfinddata32i64_t - -#define _wfindfirst _wfindfirst32 -#define _wfindnext _wfindnext32 -#define _wfindfirsti64 _wfindfirst32i64 -#define _wfindnexti64 _wfindnext32i64 -#else -#define _wfinddata_t _wfinddata64i32_t -#define _wfinddatai64_t _wfinddata64_t - -#define _wfindfirst _wfindfirst64i32 -#define _wfindnext _wfindnext64i32 -#define _wfindfirsti64 _wfindfirst64 -#define _wfindnexti64 _wfindnext64 -#endif - -#define _WFINDDATA_T_DEFINED -#endif - -#ifndef NULL -#ifdef __cplusplus -#define NULL 0 -#else -#define NULL ((void *)0) -#endif -#endif - -#ifndef _CONST_RETURN -#define _CONST_RETURN -#endif - -#define _WConst_return _CONST_RETURN - -#ifndef _CRT_CTYPEDATA_DEFINED -#define _CRT_CTYPEDATA_DEFINED -#ifndef _CTYPE_DISABLE_MACROS - -#ifndef __PCTYPE_FUNC -#define __PCTYPE_FUNC __pctype_func() -#ifdef _MSVCRT_ -#define __pctype_func() (_pctype) -#else -#define __pctype_func() (*_imp___pctype) -#endif -#endif - -#ifndef _pctype -#ifdef _MSVCRT_ - extern unsigned short *_pctype; -#else - extern unsigned short **_imp___pctype; -#define _pctype (*_imp___pctype) -#endif -#endif -#endif -#endif - -#ifndef _CRT_WCTYPEDATA_DEFINED -#define _CRT_WCTYPEDATA_DEFINED -#ifndef _CTYPE_DISABLE_MACROS -#ifndef _wctype -#ifdef _MSVCRT_ - extern unsigned short *_wctype; -#else - extern unsigned short **_imp___wctype; -#define _wctype (*_imp___wctype) -#endif -#endif - -#ifdef _MSVCRT_ -#define __pwctype_func() (_pwctype) -#else -#define __pwctype_func() (*_imp___pwctype) -#endif - -#ifndef _pwctype -#ifdef _MSVCRT_ - extern unsigned short *_pwctype; -#else - extern unsigned short **_imp___pwctype; -#define _pwctype (*_imp___pwctype) -#endif -#endif - -#endif -#endif - -#define _UPPER 0x1 -#define _LOWER 0x2 -#define _DIGIT 0x4 -#define _SPACE 0x8 - -#define _PUNCT 0x10 -#define _CONTROL 0x20 -#define _BLANK 0x40 -#define _HEX 0x80 - -#define _LEADBYTE 0x8000 -#define _ALPHA (0x0100|_UPPER|_LOWER) - -#ifndef _WCTYPE_DEFINED -#define _WCTYPE_DEFINED - - int __cdecl iswalpha(wint_t _C); - _CRTIMP int __cdecl _iswalpha_l(wint_t _C,_locale_t _Locale); - int __cdecl iswupper(wint_t _C); - _CRTIMP int __cdecl _iswupper_l(wint_t _C,_locale_t _Locale); - int __cdecl iswlower(wint_t _C); - _CRTIMP int __cdecl _iswlower_l(wint_t _C,_locale_t _Locale); - int __cdecl iswdigit(wint_t _C); - _CRTIMP int __cdecl _iswdigit_l(wint_t _C,_locale_t _Locale); - int __cdecl iswxdigit(wint_t _C); - _CRTIMP int __cdecl _iswxdigit_l(wint_t _C,_locale_t _Locale); - int __cdecl iswspace(wint_t _C); - _CRTIMP int __cdecl _iswspace_l(wint_t _C,_locale_t _Locale); - int __cdecl iswpunct(wint_t _C); - _CRTIMP int __cdecl _iswpunct_l(wint_t _C,_locale_t _Locale); - int __cdecl iswalnum(wint_t _C); - _CRTIMP int __cdecl _iswalnum_l(wint_t _C,_locale_t _Locale); - int __cdecl iswprint(wint_t _C); - _CRTIMP int __cdecl _iswprint_l(wint_t _C,_locale_t _Locale); - int __cdecl iswgraph(wint_t _C); - _CRTIMP int __cdecl _iswgraph_l(wint_t _C,_locale_t _Locale); - int __cdecl iswcntrl(wint_t _C); - _CRTIMP int __cdecl _iswcntrl_l(wint_t _C,_locale_t _Locale); - int __cdecl iswascii(wint_t _C); - int __cdecl isleadbyte(int _C); - _CRTIMP int __cdecl _isleadbyte_l(int _C,_locale_t _Locale); - wint_t __cdecl towupper(wint_t _C); - _CRTIMP wint_t __cdecl _towupper_l(wint_t _C,_locale_t _Locale); - wint_t __cdecl towlower(wint_t _C); - _CRTIMP wint_t __cdecl _towlower_l(wint_t _C,_locale_t _Locale); - int __cdecl iswctype(wint_t _C,wctype_t _Type); - _CRTIMP int __cdecl _iswctype_l(wint_t _C,wctype_t _Type,_locale_t _Locale); - _CRTIMP int __cdecl __iswcsymf(wint_t _C); - _CRTIMP int __cdecl _iswcsymf_l(wint_t _C,_locale_t _Locale); - _CRTIMP int __cdecl __iswcsym(wint_t _C); - _CRTIMP int __cdecl _iswcsym_l(wint_t _C,_locale_t _Locale); - int __cdecl is_wctype(wint_t _C,wctype_t _Type); -#endif - -#ifndef _WDIRECT_DEFINED -#define _WDIRECT_DEFINED - - _CRTIMP wchar_t *__cdecl _wgetcwd(wchar_t *_DstBuf,int _SizeInWords); - _CRTIMP wchar_t *__cdecl _wgetdcwd(int _Drive,wchar_t *_DstBuf,int _SizeInWords); - wchar_t *__cdecl _wgetdcwd_nolock(int _Drive,wchar_t *_DstBuf,int _SizeInWords); - _CRTIMP int __cdecl _wchdir(const wchar_t *_Path); - _CRTIMP int __cdecl _wmkdir(const wchar_t *_Path); - _CRTIMP int __cdecl _wrmdir(const wchar_t *_Path); -#endif - -#ifndef _WIO_DEFINED -#define _WIO_DEFINED - - _CRTIMP int __cdecl _waccess(const wchar_t *_Filename,int _AccessMode); - _CRTIMP int __cdecl _wchmod(const wchar_t *_Filename,int _Mode); - _CRTIMP int __cdecl _wcreat(const wchar_t *_Filename,int _PermissionMode); - _CRTIMP intptr_t __cdecl _wfindfirst32(const wchar_t *_Filename,struct _wfinddata32_t *_FindData); - _CRTIMP int __cdecl _wfindnext32(intptr_t _FindHandle,struct _wfinddata32_t *_FindData); - _CRTIMP int __cdecl _wunlink(const wchar_t *_Filename); - _CRTIMP int __cdecl _wrename(const wchar_t *_NewFilename,const wchar_t *_OldFilename); - _CRTIMP wchar_t *__cdecl _wmktemp(wchar_t *_TemplateName); -#if _INTEGRAL_MAX_BITS >= 64 - _CRTIMP intptr_t __cdecl _wfindfirst32i64(const wchar_t *_Filename,struct _wfinddata32i64_t *_FindData); - intptr_t __cdecl _wfindfirst64i32(const wchar_t *_Filename,struct _wfinddata64i32_t *_FindData); - _CRTIMP intptr_t __cdecl _wfindfirst64(const wchar_t *_Filename,struct _wfinddata64_t *_FindData); - _CRTIMP int __cdecl _wfindnext32i64(intptr_t _FindHandle,struct _wfinddata32i64_t *_FindData); - int __cdecl _wfindnext64i32(intptr_t _FindHandle,struct _wfinddata64i32_t *_FindData); - _CRTIMP int __cdecl _wfindnext64(intptr_t _FindHandle,struct _wfinddata64_t *_FindData); -#endif - _CRTIMP errno_t __cdecl _wsopen_s(int *_FileHandle,const wchar_t *_Filename,int _OpenFlag,int _ShareFlag,int _PermissionFlag); -#if !defined(__cplusplus) || !(defined(_X86_) && !defined(__x86_64)) - _CRTIMP int __cdecl _wopen(const wchar_t *_Filename,int _OpenFlag,...); - _CRTIMP int __cdecl _wsopen(const wchar_t *_Filename,int _OpenFlag,int _ShareFlag,...); -#else - extern "C++" _CRTIMP int __cdecl _wopen(const wchar_t *_Filename,int _OpenFlag,int _PermissionMode = 0); - extern "C++" _CRTIMP int __cdecl _wsopen(const wchar_t *_Filename,int _OpenFlag,int _ShareFlag,int _PermissionMode = 0); -#endif -#endif - -#ifndef _WLOCALE_DEFINED -#define _WLOCALE_DEFINED - _CRTIMP wchar_t *__cdecl _wsetlocale(int _Category,const wchar_t *_Locale); -#endif - -#ifndef _WPROCESS_DEFINED -#define _WPROCESS_DEFINED - - _CRTIMP intptr_t __cdecl _wexecl(const wchar_t *_Filename,const wchar_t *_ArgList,...); - _CRTIMP intptr_t __cdecl _wexecle(const wchar_t *_Filename,const wchar_t *_ArgList,...); - _CRTIMP intptr_t __cdecl _wexeclp(const wchar_t *_Filename,const wchar_t *_ArgList,...); - _CRTIMP intptr_t __cdecl _wexeclpe(const wchar_t *_Filename,const wchar_t *_ArgList,...); - _CRTIMP intptr_t __cdecl _wexecv(const wchar_t *_Filename,const wchar_t *const *_ArgList); - _CRTIMP intptr_t __cdecl _wexecve(const wchar_t *_Filename,const wchar_t *const *_ArgList,const wchar_t *const *_Env); - _CRTIMP intptr_t __cdecl _wexecvp(const wchar_t *_Filename,const wchar_t *const *_ArgList); - _CRTIMP intptr_t __cdecl _wexecvpe(const wchar_t *_Filename,const wchar_t *const *_ArgList,const wchar_t *const *_Env); - _CRTIMP intptr_t __cdecl _wspawnl(int _Mode,const wchar_t *_Filename,const wchar_t *_ArgList,...); - _CRTIMP intptr_t __cdecl _wspawnle(int _Mode,const wchar_t *_Filename,const wchar_t *_ArgList,...); - _CRTIMP intptr_t __cdecl _wspawnlp(int _Mode,const wchar_t *_Filename,const wchar_t *_ArgList,...); - _CRTIMP intptr_t __cdecl _wspawnlpe(int _Mode,const wchar_t *_Filename,const wchar_t *_ArgList,...); - _CRTIMP intptr_t __cdecl _wspawnv(int _Mode,const wchar_t *_Filename,const wchar_t *const *_ArgList); - _CRTIMP intptr_t __cdecl _wspawnve(int _Mode,const wchar_t *_Filename,const wchar_t *const *_ArgList,const wchar_t *const *_Env); - _CRTIMP intptr_t __cdecl _wspawnvp(int _Mode,const wchar_t *_Filename,const wchar_t *const *_ArgList); - _CRTIMP intptr_t __cdecl _wspawnvpe(int _Mode,const wchar_t *_Filename,const wchar_t *const *_ArgList,const wchar_t *const *_Env); -#ifndef _CRT_WSYSTEM_DEFINED -#define _CRT_WSYSTEM_DEFINED - _CRTIMP int __cdecl _wsystem(const wchar_t *_Command); -#endif -#endif - -#ifndef _WCTYPE_INLINE_DEFINED -#undef _CRT_WCTYPE_NOINLINE -#if !defined(__cplusplus) || defined(_CRT_WCTYPE_NOINLINE) -#define iswalpha(_c) (iswctype(_c,_ALPHA)) -#define iswupper(_c) (iswctype(_c,_UPPER)) -#define iswlower(_c) (iswctype(_c,_LOWER)) -#define iswdigit(_c) (iswctype(_c,_DIGIT)) -#define iswxdigit(_c) (iswctype(_c,_HEX)) -#define iswspace(_c) (iswctype(_c,_SPACE)) -#define iswpunct(_c) (iswctype(_c,_PUNCT)) -#define iswalnum(_c) (iswctype(_c,_ALPHA|_DIGIT)) -#define iswprint(_c) (iswctype(_c,_BLANK|_PUNCT|_ALPHA|_DIGIT)) -#define iswgraph(_c) (iswctype(_c,_PUNCT|_ALPHA|_DIGIT)) -#define iswcntrl(_c) (iswctype(_c,_CONTROL)) -#define iswascii(_c) ((unsigned)(_c) < 0x80) - -#define _iswalpha_l(_c,_p) (_iswctype_l(_c,_ALPHA,_p)) -#define _iswupper_l(_c,_p) (_iswctype_l(_c,_UPPER,_p)) -#define _iswlower_l(_c,_p) (_iswctype_l(_c,_LOWER,_p)) -#define _iswdigit_l(_c,_p) (_iswctype_l(_c,_DIGIT,_p)) -#define _iswxdigit_l(_c,_p) (_iswctype_l(_c,_HEX,_p)) -#define _iswspace_l(_c,_p) (_iswctype_l(_c,_SPACE,_p)) -#define _iswpunct_l(_c,_p) (_iswctype_l(_c,_PUNCT,_p)) -#define _iswalnum_l(_c,_p) (_iswctype_l(_c,_ALPHA|_DIGIT,_p)) -#define _iswprint_l(_c,_p) (_iswctype_l(_c,_BLANK|_PUNCT|_ALPHA|_DIGIT,_p)) -#define _iswgraph_l(_c,_p) (_iswctype_l(_c,_PUNCT|_ALPHA|_DIGIT,_p)) -#define _iswcntrl_l(_c,_p) (_iswctype_l(_c,_CONTROL,_p)) -#ifndef _CTYPE_DISABLE_MACROS -#define isleadbyte(_c) (__PCTYPE_FUNC[(unsigned char)(_c)] & _LEADBYTE) -#endif -#endif -#define _WCTYPE_INLINE_DEFINED -#endif - -#if !defined(_POSIX_) || defined(__GNUC__) -#ifndef _INO_T_DEFINED -#define _INO_T_DEFINED - typedef unsigned short _ino_t; -#ifndef NO_OLDNAMES - typedef unsigned short ino_t; -#endif -#endif - -#ifndef _DEV_T_DEFINED -#define _DEV_T_DEFINED - typedef unsigned int _dev_t; -#ifndef NO_OLDNAMES - typedef unsigned int dev_t; -#endif -#endif - -#ifndef _OFF_T_DEFINED -#define _OFF_T_DEFINED -#ifndef _OFF_T_ -#define _OFF_T_ - typedef long _off_t; -#if !defined(NO_OLDNAMES) || defined(_POSIX) - typedef long off_t; -#endif -#endif -#endif - -#ifndef _OFF64_T_DEFINED -#define _OFF64_T_DEFINED - typedef long long _off64_t; -#if !defined(NO_OLDNAMES) || defined(_POSIX) - typedef long long off64_t; -#endif -#endif - -#ifndef _STAT_DEFINED -#define _STAT_DEFINED - -#ifdef _USE_32BIT_TIME_T -#ifdef WIN64 -#define _fstat _fstat32 -#define _stat _stat32 -#define _wstat _wstat32 -#else -#define _fstat32 _fstat -#define _stat32 _stat -#define _wstat32 _wstat -#endif -#define _fstati64 _fstat32i64 -#define _stati64 _stat32i64 -#define _wstati64 _wstat32i64 -#else -#define _fstat _fstat64i32 -#define _fstati64 _fstat64 -#define _stat _stat64i32 -#define _stati64 _stat64 -#define _wstat _wstat64i32 -#define _wstati64 _wstat64 -#endif - - struct _stat32 { - _dev_t st_dev; - _ino_t st_ino; - unsigned short st_mode; - short st_nlink; - short st_uid; - short st_gid; - _dev_t st_rdev; - _off_t st_size; - __time32_t st_atime; - __time32_t st_mtime; - __time32_t st_ctime; - }; - -#ifndef NO_OLDNAMES - struct stat { - _dev_t st_dev; - _ino_t st_ino; - unsigned short st_mode; - short st_nlink; - short st_uid; - short st_gid; - _dev_t st_rdev; - _off_t st_size; - time_t st_atime; - time_t st_mtime; - time_t st_ctime; - }; -#endif - -#if _INTEGRAL_MAX_BITS >= 64 - - struct _stat32i64 { - _dev_t st_dev; - _ino_t st_ino; - unsigned short st_mode; - short st_nlink; - short st_uid; - short st_gid; - _dev_t st_rdev; - __int64 st_size; - __time32_t st_atime; - __time32_t st_mtime; - __time32_t st_ctime; - }; - - struct _stat64i32 { - _dev_t st_dev; - _ino_t st_ino; - unsigned short st_mode; - short st_nlink; - short st_uid; - short st_gid; - _dev_t st_rdev; - _off_t st_size; - __time64_t st_atime; - __time64_t st_mtime; - __time64_t st_ctime; - }; - - struct _stat64 { - _dev_t st_dev; - _ino_t st_ino; - unsigned short st_mode; - short st_nlink; - short st_uid; - short st_gid; - _dev_t st_rdev; - __int64 st_size; - __time64_t st_atime; - __time64_t st_mtime; - __time64_t st_ctime; - }; -#endif - -#define __stat64 _stat64 - -#endif - -#ifndef _WSTAT_DEFINED -#define _WSTAT_DEFINED - - _CRTIMP int __cdecl _wstat32(const wchar_t *_Name,struct _stat32 *_Stat); -#if _INTEGRAL_MAX_BITS >= 64 - _CRTIMP int __cdecl _wstat32i64(const wchar_t *_Name,struct _stat32i64 *_Stat); - int __cdecl _wstat64i32(const wchar_t *_Name,struct _stat64i32 *_Stat); - _CRTIMP int __cdecl _wstat64(const wchar_t *_Name,struct _stat64 *_Stat); -#endif -#endif -#endif - -#ifndef _WCONIO_DEFINED -#define _WCONIO_DEFINED - -#ifndef WEOF -#define WEOF (wint_t)(0xFFFF) -#endif - - _CRTIMP wchar_t *_cgetws(wchar_t *_Buffer); - _CRTIMP wint_t __cdecl _getwch(void); - _CRTIMP wint_t __cdecl _getwche(void); - _CRTIMP wint_t __cdecl _putwch(wchar_t _WCh); - _CRTIMP wint_t __cdecl _ungetwch(wint_t _WCh); - _CRTIMP int __cdecl _cputws(const wchar_t *_String); - _CRTIMP int __cdecl _cwprintf(const wchar_t *_Format,...); - _CRTIMP int __cdecl _cwscanf(const wchar_t *_Format,...); - _CRTIMP int __cdecl _cwscanf_l(const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _vcwprintf(const wchar_t *_Format,va_list _ArgList); - _CRTIMP int __cdecl _cwprintf_p(const wchar_t *_Format,...); - _CRTIMP int __cdecl _vcwprintf_p(const wchar_t *_Format,va_list _ArgList); - - _CRTIMP int __cdecl _cwprintf_l(const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _vcwprintf_l(const wchar_t *_Format,_locale_t _Locale,va_list _ArgList); - _CRTIMP int __cdecl _cwprintf_p_l(const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _vcwprintf_p_l(const wchar_t *_Format,_locale_t _Locale,va_list _ArgList); - wint_t __cdecl _putwch_nolock(wchar_t _WCh); - wint_t __cdecl _getwch_nolock(void); - wint_t __cdecl _getwche_nolock(void); - wint_t __cdecl _ungetwch_nolock(wint_t _WCh); -#endif - -#ifndef _WSTDIO_DEFINED -#define _WSTDIO_DEFINED - -#ifndef WEOF -#define WEOF (wint_t)(0xFFFF) -#endif - -#ifdef _POSIX_ - _CRTIMP FILE *__cdecl _wfsopen(const wchar_t *_Filename,const wchar_t *_Mode); -#else - _CRTIMP FILE *__cdecl _wfsopen(const wchar_t *_Filename,const wchar_t *_Mode,int _ShFlag); -#endif - - wint_t __cdecl fgetwc(FILE *_File); - _CRTIMP wint_t __cdecl _fgetwchar(void); - wint_t __cdecl fputwc(wchar_t _Ch,FILE *_File); - _CRTIMP wint_t __cdecl _fputwchar(wchar_t _Ch); - wint_t __cdecl getwc(FILE *_File); - wint_t __cdecl getwchar(void); - wint_t __cdecl putwc(wchar_t _Ch,FILE *_File); - wint_t __cdecl putwchar(wchar_t _Ch); - wint_t __cdecl ungetwc(wint_t _Ch,FILE *_File); - wchar_t *__cdecl fgetws(wchar_t *_Dst,int _SizeInWords,FILE *_File); - int __cdecl fputws(const wchar_t *_Str,FILE *_File); - _CRTIMP wchar_t *__cdecl _getws(wchar_t *_String); - _CRTIMP int __cdecl _putws(const wchar_t *_Str); - int __cdecl fwprintf(FILE *_File,const wchar_t *_Format,...); - int __cdecl wprintf(const wchar_t *_Format,...); - _CRTIMP int __cdecl _scwprintf(const wchar_t *_Format,...); - int __cdecl vfwprintf(FILE *_File,const wchar_t *_Format,va_list _ArgList); - int __cdecl vwprintf(const wchar_t *_Format,va_list _ArgList); - _CRTIMP int __cdecl swprintf(wchar_t*, const wchar_t*, ...); - _CRTIMP int __cdecl vswprintf(wchar_t*, const wchar_t*,va_list); - _CRTIMP int __cdecl _swprintf_c(wchar_t *_DstBuf,size_t _SizeInWords,const wchar_t *_Format,...); - _CRTIMP int __cdecl _vswprintf_c(wchar_t *_DstBuf,size_t _SizeInWords,const wchar_t *_Format,va_list _ArgList); - _CRTIMP int __cdecl _snwprintf(wchar_t *_Dest,size_t _Count,const wchar_t *_Format,...); - _CRTIMP int __cdecl _vsnwprintf(wchar_t *_Dest,size_t _Count,const wchar_t *_Format,va_list _Args); -#ifndef __NO_ISOCEXT /* externs in libmingwex.a */ - int __cdecl snwprintf (wchar_t *s, size_t n, const wchar_t * format, ...); - __CRT_INLINE int __cdecl vsnwprintf (wchar_t *s, size_t n, const wchar_t *format, va_list arg) { return _vsnwprintf(s,n,format,arg); } - int __cdecl vwscanf (const wchar_t *, va_list); - int __cdecl vfwscanf (FILE *,const wchar_t *,va_list); - int __cdecl vswscanf (const wchar_t *,const wchar_t *,va_list); -#endif - _CRTIMP int __cdecl _fwprintf_p(FILE *_File,const wchar_t *_Format,...); - _CRTIMP int __cdecl _wprintf_p(const wchar_t *_Format,...); - _CRTIMP int __cdecl _vfwprintf_p(FILE *_File,const wchar_t *_Format,va_list _ArgList); - _CRTIMP int __cdecl _vwprintf_p(const wchar_t *_Format,va_list _ArgList); - _CRTIMP int __cdecl _swprintf_p(wchar_t *_DstBuf,size_t _MaxCount,const wchar_t *_Format,...); - _CRTIMP int __cdecl _vswprintf_p(wchar_t *_DstBuf,size_t _MaxCount,const wchar_t *_Format,va_list _ArgList); - _CRTIMP int __cdecl _scwprintf_p(const wchar_t *_Format,...); - _CRTIMP int __cdecl _vscwprintf_p(const wchar_t *_Format,va_list _ArgList); - _CRTIMP int __cdecl _wprintf_l(const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _wprintf_p_l(const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _vwprintf_l(const wchar_t *_Format,_locale_t _Locale,va_list _ArgList); - _CRTIMP int __cdecl _vwprintf_p_l(const wchar_t *_Format,_locale_t _Locale,va_list _ArgList); - _CRTIMP int __cdecl _fwprintf_l(FILE *_File,const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _fwprintf_p_l(FILE *_File,const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _vfwprintf_l(FILE *_File,const wchar_t *_Format,_locale_t _Locale,va_list _ArgList); - _CRTIMP int __cdecl _vfwprintf_p_l(FILE *_File,const wchar_t *_Format,_locale_t _Locale,va_list _ArgList); - _CRTIMP int __cdecl _swprintf_c_l(wchar_t *_DstBuf,size_t _MaxCount,const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _swprintf_p_l(wchar_t *_DstBuf,size_t _MaxCount,const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _vswprintf_c_l(wchar_t *_DstBuf,size_t _MaxCount,const wchar_t *_Format,_locale_t _Locale,va_list _ArgList); - _CRTIMP int __cdecl _vswprintf_p_l(wchar_t *_DstBuf,size_t _MaxCount,const wchar_t *_Format,_locale_t _Locale,va_list _ArgList); - _CRTIMP int __cdecl _scwprintf_l(const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _scwprintf_p_l(const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _vscwprintf_p_l(const wchar_t *_Format,_locale_t _Locale,va_list _ArgList); - _CRTIMP int __cdecl _snwprintf_l(wchar_t *_DstBuf,size_t _MaxCount,const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _vsnwprintf_l(wchar_t *_DstBuf,size_t _MaxCount,const wchar_t *_Format,_locale_t _Locale,va_list _ArgList); - _CRTIMP int __cdecl _swprintf(wchar_t *_Dest,const wchar_t *_Format,...); - _CRTIMP int __cdecl _vswprintf(wchar_t *_Dest,const wchar_t *_Format,va_list _Args); - _CRTIMP int __cdecl __swprintf_l(wchar_t *_Dest,const wchar_t *_Format,_locale_t _Plocinfo,...); - _CRTIMP int __cdecl __vswprintf_l(wchar_t *_Dest,const wchar_t *_Format,_locale_t _Plocinfo,va_list _Args); -#ifndef RC_INVOKED -#include -#endif - -#ifdef _CRT_NON_CONFORMING_SWPRINTFS -#ifndef __cplusplus -#define swprintf _swprintf -#define vswprintf _vswprintf -#define _swprintf_l __swprintf_l -#define _vswprintf_l __vswprintf_l -#endif -#endif - - _CRTIMP wchar_t *__cdecl _wtempnam(const wchar_t *_Directory,const wchar_t *_FilePrefix); - _CRTIMP int __cdecl _vscwprintf(const wchar_t *_Format,va_list _ArgList); - _CRTIMP int __cdecl _vscwprintf_l(const wchar_t *_Format,_locale_t _Locale,va_list _ArgList); - int __cdecl fwscanf(FILE *_File,const wchar_t *_Format,...); - _CRTIMP int __cdecl _fwscanf_l(FILE *_File,const wchar_t *_Format,_locale_t _Locale,...); - int __cdecl swscanf(const wchar_t *_Src,const wchar_t *_Format,...); - _CRTIMP int __cdecl _swscanf_l(const wchar_t *_Src,const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP int __cdecl _snwscanf(const wchar_t *_Src,size_t _MaxCount,const wchar_t *_Format,...); - _CRTIMP int __cdecl _snwscanf_l(const wchar_t *_Src,size_t _MaxCount,const wchar_t *_Format,_locale_t _Locale,...); - int __cdecl wscanf(const wchar_t *_Format,...); - _CRTIMP int __cdecl _wscanf_l(const wchar_t *_Format,_locale_t _Locale,...); - _CRTIMP FILE *__cdecl _wfdopen(int _FileHandle ,const wchar_t *_Mode); - _CRTIMP FILE *__cdecl _wfopen(const wchar_t *_Filename,const wchar_t *_Mode); - _CRTIMP FILE *__cdecl _wfreopen(const wchar_t *_Filename,const wchar_t *_Mode,FILE *_OldFile); - -#ifndef _CRT_WPERROR_DEFINED -#define _CRT_WPERROR_DEFINED - _CRTIMP void __cdecl _wperror(const wchar_t *_ErrMsg); -#endif - _CRTIMP FILE *__cdecl _wpopen(const wchar_t *_Command,const wchar_t *_Mode); -#if !defined(NO_OLDNAMES) && !defined(wpopen) -#define wpopen _wpopen -#endif - _CRTIMP int __cdecl _wremove(const wchar_t *_Filename); - _CRTIMP wchar_t *__cdecl _wtmpnam(wchar_t *_Buffer); - _CRTIMP wint_t __cdecl _fgetwc_nolock(FILE *_File); - _CRTIMP wint_t __cdecl _fputwc_nolock(wchar_t _Ch,FILE *_File); - _CRTIMP wint_t __cdecl _ungetwc_nolock(wint_t _Ch,FILE *_File); - -#undef _CRT_GETPUTWCHAR_NOINLINE - -#if !defined(__cplusplus) || defined(_CRT_GETPUTWCHAR_NOINLINE) -#define getwchar() fgetwc(stdin) -#define putwchar(_c) fputwc((_c),stdout) -#else - __CRT_INLINE wint_t __cdecl getwchar() {return (fgetwc(stdin)); } - __CRT_INLINE wint_t __cdecl putwchar(wchar_t _C) {return (fputwc(_C,stdout)); } -#endif - -#define getwc(_stm) fgetwc(_stm) -#define putwc(_c,_stm) fputwc(_c,_stm) -#define _putwc_nolock(_c,_stm) _fputwc_nolock(_c,_stm) -#define _getwc_nolock(_c) _fgetwc_nolock(_c) -#endif - -#ifndef _WSTDLIB_DEFINED -#define _WSTDLIB_DEFINED - - _CRTIMP wchar_t *__cdecl _itow(int _Value,wchar_t *_Dest,int _Radix); - _CRTIMP wchar_t *__cdecl _ltow(long _Value,wchar_t *_Dest,int _Radix); - _CRTIMP wchar_t *__cdecl _ultow(unsigned long _Value,wchar_t *_Dest,int _Radix); - double __cdecl wcstod(const wchar_t *_Str,wchar_t **_EndPtr); - _CRTIMP double __cdecl _wcstod_l(const wchar_t *_Str,wchar_t **_EndPtr,_locale_t _Locale); - float __cdecl wcstof( const wchar_t *nptr, wchar_t **endptr); -#if !defined __NO_ISOCEXT /* in libmingwex.a */ - float __cdecl wcstof (const wchar_t * __restrict__, wchar_t ** __restrict__); - long double __cdecl wcstold (const wchar_t * __restrict__, wchar_t ** __restrict__); -#endif /* __NO_ISOCEXT */ - long __cdecl wcstol(const wchar_t *_Str,wchar_t **_EndPtr,int _Radix); - _CRTIMP long __cdecl _wcstol_l(const wchar_t *_Str,wchar_t **_EndPtr,int _Radix,_locale_t _Locale); - unsigned long __cdecl wcstoul(const wchar_t *_Str,wchar_t **_EndPtr,int _Radix); - _CRTIMP unsigned long __cdecl _wcstoul_l(const wchar_t *_Str,wchar_t **_EndPtr,int _Radix,_locale_t _Locale); - _CRTIMP wchar_t *__cdecl _wgetenv(const wchar_t *_VarName); -#ifndef _CRT_WSYSTEM_DEFINED -#define _CRT_WSYSTEM_DEFINED - _CRTIMP int __cdecl _wsystem(const wchar_t *_Command); -#endif - _CRTIMP double __cdecl _wtof(const wchar_t *_Str); - _CRTIMP double __cdecl _wtof_l(const wchar_t *_Str,_locale_t _Locale); - _CRTIMP int __cdecl _wtoi(const wchar_t *_Str); - _CRTIMP int __cdecl _wtoi_l(const wchar_t *_Str,_locale_t _Locale); - _CRTIMP long __cdecl _wtol(const wchar_t *_Str); - _CRTIMP long __cdecl _wtol_l(const wchar_t *_Str,_locale_t _Locale); - -#if _INTEGRAL_MAX_BITS >= 64 - _CRTIMP wchar_t *__cdecl _i64tow(__int64 _Val,wchar_t *_DstBuf,int _Radix); - _CRTIMP wchar_t *__cdecl _ui64tow(unsigned __int64 _Val,wchar_t *_DstBuf,int _Radix); - _CRTIMP __int64 __cdecl _wtoi64(const wchar_t *_Str); - _CRTIMP __int64 __cdecl _wtoi64_l(const wchar_t *_Str,_locale_t _Locale); - _CRTIMP __int64 __cdecl _wcstoi64(const wchar_t *_Str,wchar_t **_EndPtr,int _Radix); - _CRTIMP __int64 __cdecl _wcstoi64_l(const wchar_t *_Str,wchar_t **_EndPtr,int _Radix,_locale_t _Locale); - _CRTIMP unsigned __int64 __cdecl _wcstoui64(const wchar_t *_Str,wchar_t **_EndPtr,int _Radix); - _CRTIMP unsigned __int64 __cdecl _wcstoui64_l(const wchar_t *_Str,wchar_t **_EndPtr,int _Radix,_locale_t _Locale); -#endif -#endif - -#ifndef _POSIX_ -#ifndef _WSTDLIBP_DEFINED -#define _WSTDLIBP_DEFINED - _CRTIMP wchar_t *__cdecl _wfullpath(wchar_t *_FullPath,const wchar_t *_Path,size_t _SizeInWords); - _CRTIMP void __cdecl _wmakepath(wchar_t *_ResultPath,const wchar_t *_Drive,const wchar_t *_Dir,const wchar_t *_Filename,const wchar_t *_Ext); -#ifndef _CRT_WPERROR_DEFINED -#define _CRT_WPERROR_DEFINED - _CRTIMP void __cdecl _wperror(const wchar_t *_ErrMsg); -#endif - _CRTIMP int __cdecl _wputenv(const wchar_t *_EnvString); - _CRTIMP void __cdecl _wsearchenv(const wchar_t *_Filename,const wchar_t *_EnvVar,wchar_t *_ResultPath); - _CRTIMP void __cdecl _wsplitpath(const wchar_t *_FullPath,wchar_t *_Drive,wchar_t *_Dir,wchar_t *_Filename,wchar_t *_Ext); -#endif -#endif - -#ifndef _WSTRING_DEFINED -#define _WSTRING_DEFINED - _CRTIMP wchar_t *__cdecl _wcsdup(const wchar_t *_Str); - wchar_t *__cdecl wcscat(wchar_t *_Dest,const wchar_t *_Source); - _CONST_RETURN wchar_t *__cdecl wcschr(const wchar_t *_Str,wchar_t _Ch); - int __cdecl wcscmp(const wchar_t *_Str1,const wchar_t *_Str2); - wchar_t *__cdecl wcscpy(wchar_t *_Dest,const wchar_t *_Source); - size_t __cdecl wcscspn(const wchar_t *_Str,const wchar_t *_Control); - size_t __cdecl wcslen(const wchar_t *_Str); - size_t __cdecl wcsnlen(const wchar_t *_Src,size_t _MaxCount); - wchar_t *__cdecl wcsncat(wchar_t *_Dest,const wchar_t *_Source,size_t _Count); - int __cdecl wcsncmp(const wchar_t *_Str1,const wchar_t *_Str2,size_t _MaxCount); - wchar_t *__cdecl wcsncpy(wchar_t *_Dest,const wchar_t *_Source,size_t _Count); - _CONST_RETURN wchar_t *__cdecl wcspbrk(const wchar_t *_Str,const wchar_t *_Control); - _CONST_RETURN wchar_t *__cdecl wcsrchr(const wchar_t *_Str,wchar_t _Ch); - size_t __cdecl wcsspn(const wchar_t *_Str,const wchar_t *_Control); - _CONST_RETURN wchar_t *__cdecl wcsstr(const wchar_t *_Str,const wchar_t *_SubStr); - wchar_t *__cdecl wcstok(wchar_t *_Str,const wchar_t *_Delim); - _CRTIMP wchar_t *__cdecl _wcserror(int _ErrNum); - _CRTIMP wchar_t *__cdecl __wcserror(const wchar_t *_Str); - _CRTIMP int __cdecl _wcsicmp(const wchar_t *_Str1,const wchar_t *_Str2); - _CRTIMP int __cdecl _wcsicmp_l(const wchar_t *_Str1,const wchar_t *_Str2,_locale_t _Locale); - _CRTIMP int __cdecl _wcsnicmp(const wchar_t *_Str1,const wchar_t *_Str2,size_t _MaxCount); - _CRTIMP int __cdecl _wcsnicmp_l(const wchar_t *_Str1,const wchar_t *_Str2,size_t _MaxCount,_locale_t _Locale); - _CRTIMP wchar_t *__cdecl _wcsnset(wchar_t *_Str,wchar_t _Val,size_t _MaxCount); - _CRTIMP wchar_t *__cdecl _wcsrev(wchar_t *_Str); - _CRTIMP wchar_t *__cdecl _wcsset(wchar_t *_Str,wchar_t _Val); - _CRTIMP wchar_t *__cdecl _wcslwr(wchar_t *_String); - _CRTIMP wchar_t *_wcslwr_l(wchar_t *_String,_locale_t _Locale); - _CRTIMP wchar_t *__cdecl _wcsupr(wchar_t *_String); - _CRTIMP wchar_t *_wcsupr_l(wchar_t *_String,_locale_t _Locale); - size_t __cdecl wcsxfrm(wchar_t *_Dst,const wchar_t *_Src,size_t _MaxCount); - _CRTIMP size_t __cdecl _wcsxfrm_l(wchar_t *_Dst,const wchar_t *_Src,size_t _MaxCount,_locale_t _Locale); - int __cdecl wcscoll(const wchar_t *_Str1,const wchar_t *_Str2); - _CRTIMP int __cdecl _wcscoll_l(const wchar_t *_Str1,const wchar_t *_Str2,_locale_t _Locale); - _CRTIMP int __cdecl _wcsicoll(const wchar_t *_Str1,const wchar_t *_Str2); - _CRTIMP int __cdecl _wcsicoll_l(const wchar_t *_Str1,const wchar_t *_Str2,_locale_t _Locale); - _CRTIMP int __cdecl _wcsncoll(const wchar_t *_Str1,const wchar_t *_Str2,size_t _MaxCount); - _CRTIMP int __cdecl _wcsncoll_l(const wchar_t *_Str1,const wchar_t *_Str2,size_t _MaxCount,_locale_t _Locale); - _CRTIMP int __cdecl _wcsnicoll(const wchar_t *_Str1,const wchar_t *_Str2,size_t _MaxCount); - _CRTIMP int __cdecl _wcsnicoll_l(const wchar_t *_Str1,const wchar_t *_Str2,size_t _MaxCount,_locale_t _Locale); - -#ifndef NO_OLDNAMES - wchar_t *__cdecl wcsdup(const wchar_t *_Str); -#define wcswcs wcsstr - int __cdecl wcsicmp(const wchar_t *_Str1,const wchar_t *_Str2); - int __cdecl wcsnicmp(const wchar_t *_Str1,const wchar_t *_Str2,size_t _MaxCount); - wchar_t *__cdecl wcsnset(wchar_t *_Str,wchar_t _Val,size_t _MaxCount); - wchar_t *__cdecl wcsrev(wchar_t *_Str); - wchar_t *__cdecl wcsset(wchar_t *_Str,wchar_t _Val); - wchar_t *__cdecl wcslwr(wchar_t *_Str); - wchar_t *__cdecl wcsupr(wchar_t *_Str); - int __cdecl wcsicoll(const wchar_t *_Str1,const wchar_t *_Str2); -#endif -#endif - -#ifndef _TM_DEFINED -#define _TM_DEFINED - struct tm { - int tm_sec; - int tm_min; - int tm_hour; - int tm_mday; - int tm_mon; - int tm_year; - int tm_wday; - int tm_yday; - int tm_isdst; - }; -#endif - -#ifndef _WTIME_DEFINED -#define _WTIME_DEFINED - - _CRTIMP wchar_t *__cdecl _wasctime(const struct tm *_Tm); - _CRTIMP wchar_t *__cdecl _wctime32(const __time32_t *_Time); - size_t __cdecl wcsftime(wchar_t *_Buf,size_t _SizeInWords,const wchar_t *_Format,const struct tm *_Tm); - _CRTIMP size_t __cdecl _wcsftime_l(wchar_t *_Buf,size_t _SizeInWords,const wchar_t *_Format,const struct tm *_Tm,_locale_t _Locale); - _CRTIMP wchar_t *__cdecl _wstrdate(wchar_t *_Buffer); - _CRTIMP wchar_t *__cdecl _wstrtime(wchar_t *_Buffer); -#if _INTEGRAL_MAX_BITS >= 64 - _CRTIMP wchar_t *__cdecl _wctime64(const __time64_t *_Time); -#endif - -#if !defined (RC_INVOKED) && !defined (_INC_WTIME_INL) -#define _INC_WTIME_INL -#ifdef _USE_32BIT_TIME_T -__CRT_INLINE wchar_t *__cdecl _wctime(const time_t *_Time) { return _wctime32(_Time); } -#else -__CRT_INLINE wchar_t *__cdecl _wctime(const time_t *_Time) { return _wctime64(_Time); } -#endif -#endif -#endif - - typedef int mbstate_t; - typedef wchar_t _Wint_t; - - wint_t __cdecl btowc(int); - size_t __cdecl mbrlen(const char *_Ch,size_t _SizeInBytes,mbstate_t *_State); - size_t __cdecl mbrtowc(wchar_t *_DstCh,const char *_SrcCh,size_t _SizeInBytes,mbstate_t *_State); - size_t __cdecl mbsrtowcs(wchar_t *_Dest,const char **_PSrc,size_t _Count,mbstate_t *_State); - size_t __cdecl wcrtomb(char *_Dest,wchar_t _Source,mbstate_t *_State); - size_t __cdecl wcsrtombs(char *_Dest,const wchar_t **_PSource,size_t _Count,mbstate_t *_State); - int __cdecl wctob(wint_t _WCh); - -#ifndef __NO_ISOCEXT /* these need static lib libmingwex.a */ - wchar_t *__cdecl wmemset(wchar_t *s, wchar_t c, size_t n); - _CONST_RETURN wchar_t *__cdecl wmemchr(const wchar_t *s, wchar_t c, size_t n); - int wmemcmp(const wchar_t *s1, const wchar_t *s2,size_t n); - wchar_t *__cdecl wmemcpy(wchar_t *s1,const wchar_t *s2,size_t n); - wchar_t *__cdecl wmemmove(wchar_t *s1, const wchar_t *s2, size_t n); - long long __cdecl wcstoll(const wchar_t *nptr,wchar_t **endptr, int base); - unsigned long long __cdecl wcstoull(const wchar_t *nptr,wchar_t **endptr, int base); -#endif /* __NO_ISOCEXT */ - - void *__cdecl memmove(void *_Dst,const void *_Src,size_t _MaxCount); - void *__cdecl memcpy(void *_Dst,const void *_Src,size_t _MaxCount); - __CRT_INLINE int __cdecl fwide(FILE *_F,int _M) { (void)_F; return (_M); } - __CRT_INLINE int __cdecl mbsinit(const mbstate_t *_P) { return (!_P || *_P==0); } - __CRT_INLINE _CONST_RETURN wchar_t *__cdecl wmemchr(const wchar_t *_S,wchar_t _C,size_t _N) { for (;0<_N;++_S,--_N) if (*_S==_C) return (_CONST_RETURN wchar_t *)(_S); return (0); } - __CRT_INLINE int __cdecl wmemcmp(const wchar_t *_S1,const wchar_t *_S2,size_t _N) { for (; 0 < _N; ++_S1,++_S2,--_N) if (*_S1!=*_S2) return (*_S1 < *_S2 ? -1 : +1); return (0); } - __CRT_INLINE wchar_t *__cdecl wmemcpy(wchar_t *_S1,const wchar_t *_S2,size_t _N) { return (wchar_t *)memcpy(_S1,_S2,_N*sizeof(wchar_t)); } - __CRT_INLINE wchar_t *__cdecl wmemmove(wchar_t *_S1,const wchar_t *_S2,size_t _N) { return (wchar_t *)memmove(_S1,_S2,_N*sizeof(wchar_t)); } - __CRT_INLINE wchar_t *__cdecl wmemset(wchar_t *_S,wchar_t _C,size_t _N) { - wchar_t *_Su = _S; - for (;0<_N;++_Su,--_N) { - *_Su = _C; - } - return (_S); - } -#ifdef __cplusplus -} -#endif - -#pragma pack(pop) - -#include -#endif diff --git a/05/tcc-final-old/win32/include/wctype.h b/05/tcc-final-old/win32/include/wctype.h deleted file mode 100644 index a44cb38..0000000 --- a/05/tcc-final-old/win32/include/wctype.h +++ /dev/null @@ -1,172 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _INC_WCTYPE -#define _INC_WCTYPE - -#ifndef _WIN32 -#error Only Win32 target is supported! -#endif - -#include <_mingw.h> - -#pragma pack(push,_CRT_PACKING) - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _CRTIMP -#define _CRTIMP __declspec(dllimport) -#endif - -#ifndef _WCHAR_T_DEFINED - typedef unsigned short wchar_t; -#define _WCHAR_T_DEFINED -#endif - -#ifndef _WCTYPE_T_DEFINED - typedef unsigned short wint_t; - typedef unsigned short wctype_t; -#define _WCTYPE_T_DEFINED -#endif - -#ifndef WEOF -#define WEOF (wint_t)(0xFFFF) -#endif - -#ifndef _CRT_CTYPEDATA_DEFINED -#define _CRT_CTYPEDATA_DEFINED -#ifndef _CTYPE_DISABLE_MACROS - -#ifndef __PCTYPE_FUNC -#define __PCTYPE_FUNC __pctype_func() -#ifdef _MSVCRT_ -#define __pctype_func() (_pctype) -#else -#define __pctype_func() (*_imp___pctype) -#endif -#endif - -#ifndef _pctype -#ifdef _MSVCRT_ - extern unsigned short *_pctype; -#else - extern unsigned short **_imp___pctype; -#define _pctype (*_imp___pctype) -#endif -#endif - -#endif -#endif - -#ifndef _CRT_WCTYPEDATA_DEFINED -#define _CRT_WCTYPEDATA_DEFINED -#ifndef _CTYPE_DISABLE_MACROS -#ifndef _wctype -#ifdef _MSVCRT_ - extern unsigned short *_wctype; -#else - extern unsigned short **_imp___wctype; -#define _wctype (*_imp___wctype) -#endif -#endif - -#ifndef _pwctype -#ifdef _MSVCRT_ - extern unsigned short *_pwctype; -#else - extern unsigned short **_imp___pwctype; -#define _pwctype (*_imp___pwctype) -#define __pwctype_func() (*_imp___pwctype) -#endif -#endif -#endif -#endif - -#define _UPPER 0x1 -#define _LOWER 0x2 -#define _DIGIT 0x4 -#define _SPACE 0x8 - -#define _PUNCT 0x10 -#define _CONTROL 0x20 -#define _BLANK 0x40 -#define _HEX 0x80 - -#define _LEADBYTE 0x8000 -#define _ALPHA (0x0100|_UPPER|_LOWER) - -#ifndef _WCTYPE_DEFINED -#define _WCTYPE_DEFINED - - int __cdecl iswalpha(wint_t); - int __cdecl iswupper(wint_t); - int __cdecl iswlower(wint_t); - int __cdecl iswdigit(wint_t); - int __cdecl iswxdigit(wint_t); - int __cdecl iswspace(wint_t); - int __cdecl iswpunct(wint_t); - int __cdecl iswalnum(wint_t); - int __cdecl iswprint(wint_t); - int __cdecl iswgraph(wint_t); - int __cdecl iswcntrl(wint_t); - int __cdecl iswascii(wint_t); - int __cdecl isleadbyte(int); - wint_t __cdecl towupper(wint_t); - wint_t __cdecl towlower(wint_t); - int __cdecl iswctype(wint_t,wctype_t); - _CRTIMP int __cdecl __iswcsymf(wint_t); - _CRTIMP int __cdecl __iswcsym(wint_t); - int __cdecl is_wctype(wint_t,wctype_t); -#if (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || !defined (NO_OLDNAMES) -int __cdecl isblank(int _C); -#endif -#endif - -#ifndef _WCTYPE_INLINE_DEFINED -#define _WCTYPE_INLINE_DEFINED -#ifndef __cplusplus -#define iswalpha(_c) (iswctype(_c,_ALPHA)) -#define iswupper(_c) (iswctype(_c,_UPPER)) -#define iswlower(_c) (iswctype(_c,_LOWER)) -#define iswdigit(_c) (iswctype(_c,_DIGIT)) -#define iswxdigit(_c) (iswctype(_c,_HEX)) -#define iswspace(_c) (iswctype(_c,_SPACE)) -#define iswpunct(_c) (iswctype(_c,_PUNCT)) -#define iswalnum(_c) (iswctype(_c,_ALPHA|_DIGIT)) -#define iswprint(_c) (iswctype(_c,_BLANK|_PUNCT|_ALPHA|_DIGIT)) -#define iswgraph(_c) (iswctype(_c,_PUNCT|_ALPHA|_DIGIT)) -#define iswcntrl(_c) (iswctype(_c,_CONTROL)) -#define iswascii(_c) ((unsigned)(_c) < 0x80) -#define isleadbyte(c) (__pctype_func()[(unsigned char)(c)] & _LEADBYTE) -#else - __CRT_INLINE int __cdecl iswalpha(wint_t _C) {return (iswctype(_C,_ALPHA)); } - __CRT_INLINE int __cdecl iswupper(wint_t _C) {return (iswctype(_C,_UPPER)); } - __CRT_INLINE int __cdecl iswlower(wint_t _C) {return (iswctype(_C,_LOWER)); } - __CRT_INLINE int __cdecl iswdigit(wint_t _C) {return (iswctype(_C,_DIGIT)); } - __CRT_INLINE int __cdecl iswxdigit(wint_t _C) {return (iswctype(_C,_HEX)); } - __CRT_INLINE int __cdecl iswspace(wint_t _C) {return (iswctype(_C,_SPACE)); } - __CRT_INLINE int __cdecl iswpunct(wint_t _C) {return (iswctype(_C,_PUNCT)); } - __CRT_INLINE int __cdecl iswalnum(wint_t _C) {return (iswctype(_C,_ALPHA|_DIGIT)); } - __CRT_INLINE int __cdecl iswprint(wint_t _C) {return (iswctype(_C,_BLANK|_PUNCT|_ALPHA|_DIGIT)); } - __CRT_INLINE int __cdecl iswgraph(wint_t _C) {return (iswctype(_C,_PUNCT|_ALPHA|_DIGIT)); } - __CRT_INLINE int __cdecl iswcntrl(wint_t _C) {return (iswctype(_C,_CONTROL)); } - __CRT_INLINE int __cdecl iswascii(wint_t _C) {return ((unsigned)(_C) < 0x80); } - __CRT_INLINE int __cdecl isleadbyte(int _C) {return (__pctype_func()[(unsigned char)(_C)] & _LEADBYTE); } -#endif -#endif - - typedef wchar_t wctrans_t; - wint_t __cdecl towctrans(wint_t,wctrans_t); - wctrans_t __cdecl wctrans(const char *); - wctype_t __cdecl wctype(const char *); - -#ifdef __cplusplus -} -#endif - -#pragma pack(pop) -#endif diff --git a/05/tcc-final-old/win32/include/winapi/basetsd.h b/05/tcc-final-old/win32/include/winapi/basetsd.h deleted file mode 100644 index 47d78c4..0000000 --- a/05/tcc-final-old/win32/include/winapi/basetsd.h +++ /dev/null @@ -1,149 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _BASETSD_H_ -#define _BASETSD_H_ - -#if (defined(__x86_64) || defined(__ia64__)) && !defined(RC_INVOKED) -typedef unsigned __int64 POINTER_64_INT; -#else -typedef unsigned long POINTER_64_INT; -#endif - -#define POINTER_32 -#define POINTER_64 -#define FIRMWARE_PTR - -#ifdef __cplusplus -extern "C" { -#endif - - typedef signed char INT8,*PINT8; - typedef signed short INT16,*PINT16; - typedef signed int INT32,*PINT32; - typedef signed __int64 INT64,*PINT64; - typedef unsigned char UINT8,*PUINT8; - typedef unsigned short UINT16,*PUINT16; - typedef unsigned int UINT32,*PUINT32; - typedef unsigned __int64 UINT64,*PUINT64; - typedef signed int LONG32,*PLONG32; - typedef unsigned int ULONG32,*PULONG32; - typedef unsigned int DWORD32,*PDWORD32; - -#ifndef _W64 -#define _W64 -#endif - -#ifdef _WIN64 - typedef __int64 INT_PTR,*PINT_PTR; - typedef unsigned __int64 UINT_PTR,*PUINT_PTR; - typedef __int64 LONG_PTR,*PLONG_PTR; - typedef unsigned __int64 ULONG_PTR,*PULONG_PTR; -#define __int3264 __int64 -#else - typedef int INT_PTR,*PINT_PTR; - typedef unsigned int UINT_PTR,*PUINT_PTR; - typedef long LONG_PTR,*PLONG_PTR; - typedef unsigned long ULONG_PTR,*PULONG_PTR; -#define __int3264 __int32 -#endif - -#ifdef _WIN64 -#define ADDRESS_TAG_BIT 0x40000000000ULL - typedef __int64 SHANDLE_PTR; - typedef unsigned __int64 HANDLE_PTR; - typedef unsigned int UHALF_PTR,*PUHALF_PTR; - typedef int HALF_PTR,*PHALF_PTR; - - static __inline unsigned long HandleToULong(const void *h) { return((unsigned long) (ULONG_PTR) h); } - static __inline long HandleToLong(const void *h) { return((long) (LONG_PTR) h); } - static __inline void *ULongToHandle(const unsigned long h) { return((void *) (UINT_PTR) h); } - static __inline void *LongToHandle(const long h) { return((void *) (INT_PTR) h); } - static __inline unsigned long PtrToUlong(const void *p) { return((unsigned long) (ULONG_PTR) p); } - static __inline unsigned int PtrToUint(const void *p) { return((unsigned int) (UINT_PTR) p); } - static __inline unsigned short PtrToUshort(const void *p) { return((unsigned short) (unsigned long) (ULONG_PTR) p); } - static __inline long PtrToLong(const void *p) { return((long) (LONG_PTR) p); } - static __inline int PtrToInt(const void *p) { return((int) (INT_PTR) p); } - static __inline short PtrToShort(const void *p) { return((short) (long) (LONG_PTR) p); } - static __inline void *IntToPtr(const int i) { return((void *)(INT_PTR)i); } - static __inline void *UIntToPtr(const unsigned int ui) { return((void *)(UINT_PTR)ui); } - static __inline void *LongToPtr(const long l) { return((void *)(LONG_PTR)l); } - static __inline void *ULongToPtr(const unsigned long ul) { return((void *)(ULONG_PTR)ul); } - -#define PtrToPtr64(p) ((void *) p) -#define Ptr64ToPtr(p) ((void *) p) -#define HandleToHandle64(h) (PtrToPtr64(h)) -#define Handle64ToHandle(h) (Ptr64ToPtr(h)) - - static __inline void *Ptr32ToPtr(const void *p) { return (void *)p; } - static __inline void *Handle32ToHandle(const void *h) { return((void *) h); } - static __inline void *PtrToPtr32(const void *p) { return((void *) (ULONG_PTR) p); } - -#define HandleToHandle32(h) (PtrToPtr32(h)) -#else - -#define ADDRESS_TAG_BIT 0x80000000UL - - typedef unsigned short UHALF_PTR,*PUHALF_PTR; - typedef short HALF_PTR,*PHALF_PTR; - typedef long SHANDLE_PTR; - typedef unsigned long HANDLE_PTR; - -#define HandleToULong(h) ((ULONG)(ULONG_PTR)(h)) -#define HandleToLong(h) ((LONG)(LONG_PTR) (h)) -#define ULongToHandle(ul) ((HANDLE)(ULONG_PTR) (ul)) -#define LongToHandle(h) ((HANDLE)(LONG_PTR) (h)) -#define PtrToUlong(p) ((ULONG)(ULONG_PTR) (p)) -#define PtrToLong(p) ((LONG)(LONG_PTR) (p)) -#define PtrToUint(p) ((UINT)(UINT_PTR) (p)) -#define PtrToInt(p) ((INT)(INT_PTR) (p)) -#define PtrToUshort(p) ((unsigned short)(ULONG_PTR)(p)) -#define PtrToShort(p) ((short)(LONG_PTR)(p)) -#define IntToPtr(i) ((VOID *)(INT_PTR)((int)i)) -#define UIntToPtr(ui) ((VOID *)(UINT_PTR)((unsigned int)ui)) -#define LongToPtr(l) ((VOID *)(LONG_PTR)((long)l)) -#define ULongToPtr(ul) ((VOID *)(ULONG_PTR)((unsigned long)ul)) - - static __inline void *PtrToPtr64(const void *p) { return((void *) (ULONG_PTR)p); } - static __inline void *Ptr64ToPtr(const void *p) { return((void *) (ULONG_PTR) p); } - static __inline void *HandleToHandle64(const void *h) { return((void *) h); } - static __inline void *Handle64ToHandle(const void *h) { return((void *) (ULONG_PTR) h); } - -#define Ptr32ToPtr(p) ((void *) p) -#define Handle32ToHandle(h) (Ptr32ToPtr(h)) -#define PtrToPtr32(p) ((void *) p) -#define HandleToHandle32(h) (PtrToPtr32(h)) -#endif - -#define HandleToUlong(h) HandleToULong(h) -#define UlongToHandle(ul) ULongToHandle(ul) -#define UlongToPtr(ul) ULongToPtr(ul) -#define UintToPtr(ui) UIntToPtr(ui) - -#define MAXUINT_PTR (~((UINT_PTR)0)) -#define MAXINT_PTR ((INT_PTR)(MAXUINT_PTR >> 1)) -#define MININT_PTR (~MAXINT_PTR) - -#define MAXULONG_PTR (~((ULONG_PTR)0)) -#define MAXLONG_PTR ((LONG_PTR)(MAXULONG_PTR >> 1)) -#define MINLONG_PTR (~MAXLONG_PTR) - -#define MAXUHALF_PTR ((UHALF_PTR)~0) -#define MAXHALF_PTR ((HALF_PTR)(MAXUHALF_PTR >> 1)) -#define MINHALF_PTR (~MAXHALF_PTR) - - typedef ULONG_PTR SIZE_T,*PSIZE_T; - typedef LONG_PTR SSIZE_T,*PSSIZE_T; - typedef ULONG_PTR DWORD_PTR,*PDWORD_PTR; - typedef __int64 LONG64,*PLONG64; - typedef unsigned __int64 ULONG64,*PULONG64; - typedef unsigned __int64 DWORD64,*PDWORD64; - typedef ULONG_PTR KAFFINITY; - typedef KAFFINITY *PKAFFINITY; - -#ifdef __cplusplus -} -#endif -#endif diff --git a/05/tcc-final-old/win32/include/winapi/basetyps.h b/05/tcc-final-old/win32/include/winapi/basetyps.h deleted file mode 100644 index 376665e..0000000 --- a/05/tcc-final-old/win32/include/winapi/basetyps.h +++ /dev/null @@ -1,85 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#if !defined(_BASETYPS_H_) -#define _BASETYPS_H_ - -#ifdef __cplusplus -#define EXTERN_C extern "C" -#else -#define EXTERN_C extern -#endif - -#define STDMETHODCALLTYPE WINAPI -#define STDMETHODVCALLTYPE __cdecl - -#define STDAPICALLTYPE WINAPI -#define STDAPIVCALLTYPE __cdecl - -#define STDAPI EXTERN_C HRESULT WINAPI -#define STDAPI_(type) EXTERN_C type WINAPI - -#define STDMETHODIMP HRESULT WINAPI -#define STDMETHODIMP_(type) type WINAPI - -#define STDAPIV EXTERN_C HRESULT STDAPIVCALLTYPE -#define STDAPIV_(type) EXTERN_C type STDAPIVCALLTYPE - -#define STDMETHODIMPV HRESULT STDMETHODVCALLTYPE -#define STDMETHODIMPV_(type) type STDMETHODVCALLTYPE - -#if defined(__cplusplus) && !defined(CINTERFACE) - -#define __STRUCT__ struct -#define STDMETHOD(method) virtual HRESULT WINAPI method -#define STDMETHOD_(type,method) virtual type WINAPI method -#define STDMETHODV(method) virtual HRESULT STDMETHODVCALLTYPE method -#define STDMETHODV_(type,method) virtual type STDMETHODVCALLTYPE method -#define PURE = 0 -#define THIS_ -#define THIS void -#define DECLARE_INTERFACE(iface) __STRUCT__ iface -#define DECLARE_INTERFACE_(iface,baseiface) __STRUCT__ iface : public baseiface -#else - -#ifndef __OBJC__ -#define interface struct -#endif - -#define STDMETHOD(method) HRESULT (WINAPI *method) -#define STDMETHOD_(type,method) type (WINAPI *method) -#define STDMETHODV(method) HRESULT (STDMETHODVCALLTYPE *method) -#define STDMETHODV_(type,method) type (STDMETHODVCALLTYPE *method) - -#define PURE -#define THIS_ INTERFACE *This, -#define THIS INTERFACE *This -#ifdef CONST_VTABLE -#define DECLARE_INTERFACE(iface) typedef struct iface { \ - const struct iface##Vtbl *lpVtbl; } iface; \ - typedef const struct iface##Vtbl iface##Vtbl; \ - const struct iface##Vtbl -#else -#define DECLARE_INTERFACE(iface) typedef struct iface { \ - struct iface##Vtbl *lpVtbl; \ - } iface; \ - typedef struct iface##Vtbl iface##Vtbl; \ - struct iface##Vtbl -#endif -#define DECLARE_INTERFACE_(iface,baseiface) DECLARE_INTERFACE(iface) -#endif - -#include - -#ifndef _ERROR_STATUS_T_DEFINED -#define _ERROR_STATUS_T_DEFINED -typedef unsigned long error_status_t; -#endif - -#ifndef _WCHAR_T_DEFINED -typedef unsigned short wchar_t; -#define _WCHAR_T_DEFINED -#endif -#endif diff --git a/05/tcc-final-old/win32/include/winapi/guiddef.h b/05/tcc-final-old/win32/include/winapi/guiddef.h deleted file mode 100644 index 4e7909a..0000000 --- a/05/tcc-final-old/win32/include/winapi/guiddef.h +++ /dev/null @@ -1,156 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef GUID_DEFINED -#define GUID_DEFINED -typedef struct _GUID { - unsigned long Data1; - unsigned short Data2; - unsigned short Data3; - unsigned char Data4[8 ]; -} GUID; -#endif - -#ifndef UUID_DEFINED -#define UUID_DEFINED -typedef GUID UUID; -#endif - -#ifndef FAR -#define FAR -#endif - -#ifndef DECLSPEC_SELECTANY -#define DECLSPEC_SELECTANY __declspec(selectany) -#endif - -#ifndef EXTERN_C -#ifdef __cplusplus -#define EXTERN_C extern "C" -#else -#define EXTERN_C extern -#endif -#endif - -#ifdef DEFINE_GUID -#undef DEFINE_GUID -#endif - -#ifdef INITGUID -#ifdef __cplusplus -#define DEFINE_GUID(name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) EXTERN_C const GUID DECLSPEC_SELECTANY name = { l,w1,w2,{ b1,b2,b3,b4,b5,b6,b7,b8 } } -#else -#define DEFINE_GUID(name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) const GUID DECLSPEC_SELECTANY name = { l,w1,w2,{ b1,b2,b3,b4,b5,b6,b7,b8 } } -#endif -#else -#define DEFINE_GUID(name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) EXTERN_C const GUID name -#endif - -#define DEFINE_OLEGUID(name,l,w1,w2) DEFINE_GUID(name,l,w1,w2,0xC0,0,0,0,0,0,0,0x46) - -#ifndef _GUIDDEF_H_ -#define _GUIDDEF_H_ - -#ifndef __LPGUID_DEFINED__ -#define __LPGUID_DEFINED__ -typedef GUID *LPGUID; -#endif - -#ifndef __LPCGUID_DEFINED__ -#define __LPCGUID_DEFINED__ -typedef const GUID *LPCGUID; -#endif - -#ifndef __IID_DEFINED__ -#define __IID_DEFINED__ - -typedef GUID IID; -typedef IID *LPIID; -#define IID_NULL GUID_NULL -#define IsEqualIID(riid1,riid2) IsEqualGUID(riid1,riid2) -typedef GUID CLSID; -typedef CLSID *LPCLSID; -#define CLSID_NULL GUID_NULL -#define IsEqualCLSID(rclsid1,rclsid2) IsEqualGUID(rclsid1,rclsid2) -typedef GUID FMTID; -typedef FMTID *LPFMTID; -#define FMTID_NULL GUID_NULL -#define IsEqualFMTID(rfmtid1,rfmtid2) IsEqualGUID(rfmtid1,rfmtid2) - -#ifdef __midl_proxy -#define __MIDL_CONST -#else -#define __MIDL_CONST const -#endif - -#ifndef _REFGUID_DEFINED -#define _REFGUID_DEFINED -#ifdef __cplusplus -#define REFGUID const GUID & -#else -#define REFGUID const GUID *__MIDL_CONST -#endif -#endif - -#ifndef _REFIID_DEFINED -#define _REFIID_DEFINED -#ifdef __cplusplus -#define REFIID const IID & -#else -#define REFIID const IID *__MIDL_CONST -#endif -#endif - -#ifndef _REFCLSID_DEFINED -#define _REFCLSID_DEFINED -#ifdef __cplusplus -#define REFCLSID const IID & -#else -#define REFCLSID const IID *__MIDL_CONST -#endif -#endif - -#ifndef _REFFMTID_DEFINED -#define _REFFMTID_DEFINED -#ifdef __cplusplus -#define REFFMTID const IID & -#else -#define REFFMTID const IID *__MIDL_CONST -#endif -#endif -#endif - -#ifndef _SYS_GUID_OPERATORS_ -#define _SYS_GUID_OPERATORS_ -#include - -#ifdef __cplusplus -__inline int InlineIsEqualGUID(REFGUID rguid1,REFGUID rguid2) { - return (((unsigned long *) &rguid1)[0]==((unsigned long *) &rguid2)[0] && ((unsigned long *) &rguid1)[1]==((unsigned long *) &rguid2)[1] && - ((unsigned long *) &rguid1)[2]==((unsigned long *) &rguid2)[2] && ((unsigned long *) &rguid1)[3]==((unsigned long *) &rguid2)[3]); -} -__inline int IsEqualGUID(REFGUID rguid1,REFGUID rguid2) { return !memcmp(&rguid1,&rguid2,sizeof(GUID)); } -#else -#define InlineIsEqualGUID(rguid1,rguid2) (((unsigned long *) rguid1)[0]==((unsigned long *) rguid2)[0] && ((unsigned long *) rguid1)[1]==((unsigned long *) rguid2)[1] && ((unsigned long *) rguid1)[2]==((unsigned long *) rguid2)[2] && ((unsigned long *) rguid1)[3]==((unsigned long *) rguid2)[3]) -#define IsEqualGUID(rguid1,rguid2) (!memcmp(rguid1,rguid2,sizeof(GUID))) -#endif - -#ifdef __INLINE_ISEQUAL_GUID -#undef IsEqualGUID -#define IsEqualGUID(rguid1,rguid2) InlineIsEqualGUID(rguid1,rguid2) -#endif - -#define IsEqualIID(riid1,riid2) IsEqualGUID(riid1,riid2) -#define IsEqualCLSID(rclsid1,rclsid2) IsEqualGUID(rclsid1,rclsid2) - -#if !defined _SYS_GUID_OPERATOR_EQ_ && !defined _NO_SYS_GUID_OPERATOR_EQ_ -#define _SYS_GUID_OPERATOR_EQ_ -#ifdef __cplusplus -__inline int operator==(REFGUID guidOne,REFGUID guidOther) { return IsEqualGUID(guidOne,guidOther); } -__inline int operator!=(REFGUID guidOne,REFGUID guidOther) { return !(guidOne==guidOther); } -#endif -#endif -#endif -#endif diff --git a/05/tcc-final-old/win32/include/winapi/poppack.h b/05/tcc-final-old/win32/include/winapi/poppack.h deleted file mode 100644 index b08cba2..0000000 --- a/05/tcc-final-old/win32/include/winapi/poppack.h +++ /dev/null @@ -1,8 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#if !(defined(lint) || defined(RC_INVOKED)) -#pragma pack(pop) -#endif diff --git a/05/tcc-final-old/win32/include/winapi/pshpack1.h b/05/tcc-final-old/win32/include/winapi/pshpack1.h deleted file mode 100644 index d18d9e8..0000000 --- a/05/tcc-final-old/win32/include/winapi/pshpack1.h +++ /dev/null @@ -1,8 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#if !(defined(lint) || defined(RC_INVOKED)) -#pragma pack(push,1) -#endif diff --git a/05/tcc-final-old/win32/include/winapi/pshpack2.h b/05/tcc-final-old/win32/include/winapi/pshpack2.h deleted file mode 100644 index 7de16fd..0000000 --- a/05/tcc-final-old/win32/include/winapi/pshpack2.h +++ /dev/null @@ -1,8 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#if !(defined(lint) || defined(RC_INVOKED)) -#pragma pack(push,2) -#endif diff --git a/05/tcc-final-old/win32/include/winapi/pshpack4.h b/05/tcc-final-old/win32/include/winapi/pshpack4.h deleted file mode 100644 index 1c8e61d..0000000 --- a/05/tcc-final-old/win32/include/winapi/pshpack4.h +++ /dev/null @@ -1,8 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#if !(defined(lint) || defined(RC_INVOKED)) -#pragma pack(push,4) -#endif diff --git a/05/tcc-final-old/win32/include/winapi/pshpack8.h b/05/tcc-final-old/win32/include/winapi/pshpack8.h deleted file mode 100644 index 70a3c7f..0000000 --- a/05/tcc-final-old/win32/include/winapi/pshpack8.h +++ /dev/null @@ -1,8 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#if !(defined(lint) || defined(RC_INVOKED)) -#pragma pack(push,8) -#endif diff --git a/05/tcc-final-old/win32/include/winapi/winbase.h b/05/tcc-final-old/win32/include/winapi/winbase.h deleted file mode 100644 index 4a38006..0000000 --- a/05/tcc-final-old/win32/include/winapi/winbase.h +++ /dev/null @@ -1,2951 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _WINBASE_ -#define _WINBASE_ - -#define WINADVAPI DECLSPEC_IMPORT -#define WINBASEAPI DECLSPEC_IMPORT -#define ZAWPROXYAPI DECLSPEC_IMPORT - -#ifdef __cplusplus -extern "C" { -#endif - -#define DefineHandleTable(w) ((w),TRUE) -#define LimitEmsPages(dw) -#define SetSwapAreaSize(w) (w) -#define LockSegment(w) GlobalFix((HANDLE)(w)) -#define UnlockSegment(w) GlobalUnfix((HANDLE)(w)) -#define GetCurrentTime() GetTickCount() - -#define Yield() - -#define INVALID_HANDLE_VALUE ((HANDLE)(LONG_PTR)-1) -#define INVALID_FILE_SIZE ((DWORD)0xffffffff) -#define INVALID_SET_FILE_POINTER ((DWORD)-1) -#define INVALID_FILE_ATTRIBUTES ((DWORD)-1) - -#define FILE_BEGIN 0 -#define FILE_CURRENT 1 -#define FILE_END 2 - -#define TIME_ZONE_ID_INVALID ((DWORD)0xffffffff) - -#define WAIT_FAILED ((DWORD)0xffffffff) -#define WAIT_OBJECT_0 ((STATUS_WAIT_0) + 0) -#define WAIT_ABANDONED ((STATUS_ABANDONED_WAIT_0) + 0) -#define WAIT_ABANDONED_0 ((STATUS_ABANDONED_WAIT_0) + 0) -#define WAIT_IO_COMPLETION STATUS_USER_APC -#define STILL_ACTIVE STATUS_PENDING -#define EXCEPTION_ACCESS_VIOLATION STATUS_ACCESS_VIOLATION -#define EXCEPTION_DATATYPE_MISALIGNMENT STATUS_DATATYPE_MISALIGNMENT -#define EXCEPTION_BREAKPOINT STATUS_BREAKPOINT -#define EXCEPTION_SINGLE_STEP STATUS_SINGLE_STEP -#define EXCEPTION_ARRAY_BOUNDS_EXCEEDED STATUS_ARRAY_BOUNDS_EXCEEDED -#define EXCEPTION_FLT_DENORMAL_OPERAND STATUS_FLOAT_DENORMAL_OPERAND -#define EXCEPTION_FLT_DIVIDE_BY_ZERO STATUS_FLOAT_DIVIDE_BY_ZERO -#define EXCEPTION_FLT_INEXACT_RESULT STATUS_FLOAT_INEXACT_RESULT -#define EXCEPTION_FLT_INVALID_OPERATION STATUS_FLOAT_INVALID_OPERATION -#define EXCEPTION_FLT_OVERFLOW STATUS_FLOAT_OVERFLOW -#define EXCEPTION_FLT_STACK_CHECK STATUS_FLOAT_STACK_CHECK -#define EXCEPTION_FLT_UNDERFLOW STATUS_FLOAT_UNDERFLOW -#define EXCEPTION_INT_DIVIDE_BY_ZERO STATUS_INTEGER_DIVIDE_BY_ZERO -#define EXCEPTION_INT_OVERFLOW STATUS_INTEGER_OVERFLOW -#define EXCEPTION_PRIV_INSTRUCTION STATUS_PRIVILEGED_INSTRUCTION -#define EXCEPTION_IN_PAGE_ERROR STATUS_IN_PAGE_ERROR -#define EXCEPTION_ILLEGAL_INSTRUCTION STATUS_ILLEGAL_INSTRUCTION -#define EXCEPTION_NONCONTINUABLE_EXCEPTION STATUS_NONCONTINUABLE_EXCEPTION -#define EXCEPTION_STACK_OVERFLOW STATUS_STACK_OVERFLOW -#define EXCEPTION_INVALID_DISPOSITION STATUS_INVALID_DISPOSITION -#define EXCEPTION_GUARD_PAGE STATUS_GUARD_PAGE_VIOLATION -#define EXCEPTION_INVALID_HANDLE STATUS_INVALID_HANDLE -#define EXCEPTION_POSSIBLE_DEADLOCK STATUS_POSSIBLE_DEADLOCK -#define CONTROL_C_EXIT STATUS_CONTROL_C_EXIT -#define MoveMemory RtlMoveMemory -#define CopyMemory RtlCopyMemory -#define FillMemory RtlFillMemory -#define ZeroMemory RtlZeroMemory -#define SecureZeroMemory RtlSecureZeroMemory - -#define FILE_FLAG_WRITE_THROUGH 0x80000000 -#define FILE_FLAG_OVERLAPPED 0x40000000 -#define FILE_FLAG_NO_BUFFERING 0x20000000 -#define FILE_FLAG_RANDOM_ACCESS 0x10000000 -#define FILE_FLAG_SEQUENTIAL_SCAN 0x8000000 -#define FILE_FLAG_DELETE_ON_CLOSE 0x4000000 -#define FILE_FLAG_BACKUP_SEMANTICS 0x2000000 -#define FILE_FLAG_POSIX_SEMANTICS 0x1000000 -#define FILE_FLAG_OPEN_REPARSE_POINT 0x200000 -#define FILE_FLAG_OPEN_NO_RECALL 0x100000 -#define FILE_FLAG_FIRST_PIPE_INSTANCE 0x80000 - -#define CREATE_NEW 1 -#define CREATE_ALWAYS 2 -#define OPEN_EXISTING 3 -#define OPEN_ALWAYS 4 -#define TRUNCATE_EXISTING 5 - -#define PROGRESS_CONTINUE 0 -#define PROGRESS_CANCEL 1 -#define PROGRESS_STOP 2 -#define PROGRESS_QUIET 3 - -#define CALLBACK_CHUNK_FINISHED 0x0 -#define CALLBACK_STREAM_SWITCH 0x1 - -#define COPY_FILE_FAIL_IF_EXISTS 0x1 -#define COPY_FILE_RESTARTABLE 0x2 -#define COPY_FILE_OPEN_SOURCE_FOR_WRITE 0x4 -#define COPY_FILE_ALLOW_DECRYPTED_DESTINATION 0x8 - -#define REPLACEFILE_WRITE_THROUGH 0x1 -#define REPLACEFILE_IGNORE_MERGE_ERRORS 0x2 - -#define PIPE_ACCESS_INBOUND 0x1 -#define PIPE_ACCESS_OUTBOUND 0x2 -#define PIPE_ACCESS_DUPLEX 0x3 - -#define PIPE_CLIENT_END 0x0 -#define PIPE_SERVER_END 0x1 - -#define PIPE_WAIT 0x0 -#define PIPE_NOWAIT 0x1 -#define PIPE_READMODE_BYTE 0x0 -#define PIPE_READMODE_MESSAGE 0x2 -#define PIPE_TYPE_BYTE 0x0 -#define PIPE_TYPE_MESSAGE 0x4 - -#define PIPE_UNLIMITED_INSTANCES 255 - -#define SECURITY_ANONYMOUS (SecurityAnonymous << 16) -#define SECURITY_IDENTIFICATION (SecurityIdentification << 16) -#define SECURITY_IMPERSONATION (SecurityImpersonation << 16) -#define SECURITY_DELEGATION (SecurityDelegation << 16) - -#define SECURITY_CONTEXT_TRACKING 0x40000 -#define SECURITY_EFFECTIVE_ONLY 0x80000 - -#define SECURITY_SQOS_PRESENT 0x100000 -#define SECURITY_VALID_SQOS_FLAGS 0x1f0000 - - typedef struct _OVERLAPPED { - ULONG_PTR Internal; - ULONG_PTR InternalHigh; - union { - struct { - DWORD Offset; - DWORD OffsetHigh; - }; - PVOID Pointer; - }; - HANDLE hEvent; - } OVERLAPPED,*LPOVERLAPPED; - - typedef struct _SECURITY_ATTRIBUTES { - DWORD nLength; - LPVOID lpSecurityDescriptor; - WINBOOL bInheritHandle; - } SECURITY_ATTRIBUTES,*PSECURITY_ATTRIBUTES,*LPSECURITY_ATTRIBUTES; - - typedef struct _PROCESS_INFORMATION { - HANDLE hProcess; - HANDLE hThread; - DWORD dwProcessId; - DWORD dwThreadId; - } PROCESS_INFORMATION,*PPROCESS_INFORMATION,*LPPROCESS_INFORMATION; - -#ifndef _FILETIME_ -#define _FILETIME_ - typedef struct _FILETIME { - DWORD dwLowDateTime; - DWORD dwHighDateTime; - } FILETIME,*PFILETIME,*LPFILETIME; -#endif - - typedef struct _SYSTEMTIME { - WORD wYear; - WORD wMonth; - WORD wDayOfWeek; - WORD wDay; - WORD wHour; - WORD wMinute; - WORD wSecond; - WORD wMilliseconds; - } SYSTEMTIME,*PSYSTEMTIME,*LPSYSTEMTIME; - - typedef DWORD (WINAPI *PTHREAD_START_ROUTINE)(LPVOID lpThreadParameter); - typedef PTHREAD_START_ROUTINE LPTHREAD_START_ROUTINE; - typedef VOID (WINAPI *PFIBER_START_ROUTINE)(LPVOID lpFiberParameter); - typedef PFIBER_START_ROUTINE LPFIBER_START_ROUTINE; - - typedef RTL_CRITICAL_SECTION CRITICAL_SECTION; - typedef PRTL_CRITICAL_SECTION PCRITICAL_SECTION; - typedef PRTL_CRITICAL_SECTION LPCRITICAL_SECTION; - typedef RTL_CRITICAL_SECTION_DEBUG CRITICAL_SECTION_DEBUG; - typedef PRTL_CRITICAL_SECTION_DEBUG PCRITICAL_SECTION_DEBUG; - typedef PRTL_CRITICAL_SECTION_DEBUG LPCRITICAL_SECTION_DEBUG; - - WINBASEAPI PVOID WINAPI EncodePointer(PVOID Ptr); - WINBASEAPI PVOID WINAPI DecodePointer(PVOID Ptr); - WINBASEAPI PVOID WINAPI EncodeSystemPointer(PVOID Ptr); - WINBASEAPI PVOID WINAPI DecodeSystemPointer(PVOID Ptr); - -#ifdef I_X86_ - typedef PLDT_ENTRY LPLDT_ENTRY; -#else - typedef LPVOID LPLDT_ENTRY; -#endif - -#define MUTEX_MODIFY_STATE MUTANT_QUERY_STATE -#define MUTEX_ALL_ACCESS MUTANT_ALL_ACCESS - -#define SP_SERIALCOMM ((DWORD)0x1) - -#define PST_UNSPECIFIED ((DWORD)0x0) -#define PST_RS232 ((DWORD)0x1) -#define PST_PARALLELPORT ((DWORD)0x2) -#define PST_RS422 ((DWORD)0x3) -#define PST_RS423 ((DWORD)0x4) -#define PST_RS449 ((DWORD)0x5) -#define PST_MODEM ((DWORD)0x6) -#define PST_FAX ((DWORD)0x21) -#define PST_SCANNER ((DWORD)0x22) -#define PST_NETWORK_BRIDGE ((DWORD)0x100) -#define PST_LAT ((DWORD)0x101) -#define PST_TCPIP_TELNET ((DWORD)0x102) -#define PST_X25 ((DWORD)0x103) - -#define PCF_DTRDSR ((DWORD)0x1) -#define PCF_RTSCTS ((DWORD)0x2) -#define PCF_RLSD ((DWORD)0x4) -#define PCF_PARITY_CHECK ((DWORD)0x8) -#define PCF_XONXOFF ((DWORD)0x10) -#define PCF_SETXCHAR ((DWORD)0x20) -#define PCF_TOTALTIMEOUTS ((DWORD)0x40) -#define PCF_INTTIMEOUTS ((DWORD)0x80) -#define PCF_SPECIALCHARS ((DWORD)0x100) -#define PCF_16BITMODE ((DWORD)0x200) - -#define SP_PARITY ((DWORD)0x1) -#define SP_BAUD ((DWORD)0x2) -#define SP_DATABITS ((DWORD)0x4) -#define SP_STOPBITS ((DWORD)0x8) -#define SP_HANDSHAKING ((DWORD)0x10) -#define SP_PARITY_CHECK ((DWORD)0x20) -#define SP_RLSD ((DWORD)0x40) - -#define BAUD_075 ((DWORD)0x1) -#define BAUD_110 ((DWORD)0x2) -#define BAUD_134_5 ((DWORD)0x4) -#define BAUD_150 ((DWORD)0x8) -#define BAUD_300 ((DWORD)0x10) -#define BAUD_600 ((DWORD)0x20) -#define BAUD_1200 ((DWORD)0x40) -#define BAUD_1800 ((DWORD)0x80) -#define BAUD_2400 ((DWORD)0x100) -#define BAUD_4800 ((DWORD)0x200) -#define BAUD_7200 ((DWORD)0x400) -#define BAUD_9600 ((DWORD)0x800) -#define BAUD_14400 ((DWORD)0x1000) -#define BAUD_19200 ((DWORD)0x2000) -#define BAUD_38400 ((DWORD)0x4000) -#define BAUD_56K ((DWORD)0x8000) -#define BAUD_128K ((DWORD)0x10000) -#define BAUD_115200 ((DWORD)0x20000) -#define BAUD_57600 ((DWORD)0x40000) -#define BAUD_USER ((DWORD)0x10000000) - -#define DATABITS_5 ((WORD)0x1) -#define DATABITS_6 ((WORD)0x2) -#define DATABITS_7 ((WORD)0x4) -#define DATABITS_8 ((WORD)0x8) -#define DATABITS_16 ((WORD)0x10) -#define DATABITS_16X ((WORD)0x20) - -#define STOPBITS_10 ((WORD)0x1) -#define STOPBITS_15 ((WORD)0x2) -#define STOPBITS_20 ((WORD)0x4) -#define PARITY_NONE ((WORD)0x100) -#define PARITY_ODD ((WORD)0x200) -#define PARITY_EVEN ((WORD)0x400) -#define PARITY_MARK ((WORD)0x800) -#define PARITY_SPACE ((WORD)0x1000) - - typedef struct _COMMPROP { - WORD wPacketLength; - WORD wPacketVersion; - DWORD dwServiceMask; - DWORD dwReserved1; - DWORD dwMaxTxQueue; - DWORD dwMaxRxQueue; - DWORD dwMaxBaud; - DWORD dwProvSubType; - DWORD dwProvCapabilities; - DWORD dwSettableParams; - DWORD dwSettableBaud; - WORD wSettableData; - WORD wSettableStopParity; - DWORD dwCurrentTxQueue; - DWORD dwCurrentRxQueue; - DWORD dwProvSpec1; - DWORD dwProvSpec2; - WCHAR wcProvChar[1]; - } COMMPROP,*LPCOMMPROP; - -#define COMMPROP_INITIALIZED ((DWORD)0xE73CF52E) - - typedef struct _COMSTAT { - DWORD fCtsHold : 1; - DWORD fDsrHold : 1; - DWORD fRlsdHold : 1; - DWORD fXoffHold : 1; - DWORD fXoffSent : 1; - DWORD fEof : 1; - DWORD fTxim : 1; - DWORD fReserved : 25; - DWORD cbInQue; - DWORD cbOutQue; - } COMSTAT,*LPCOMSTAT; - -#define DTR_CONTROL_DISABLE 0x0 -#define DTR_CONTROL_ENABLE 0x1 -#define DTR_CONTROL_HANDSHAKE 0x2 - -#define RTS_CONTROL_DISABLE 0x0 -#define RTS_CONTROL_ENABLE 0x1 -#define RTS_CONTROL_HANDSHAKE 0x2 -#define RTS_CONTROL_TOGGLE 0x3 - - typedef struct _DCB { - DWORD DCBlength; - DWORD BaudRate; - DWORD fBinary: 1; - DWORD fParity: 1; - DWORD fOutxCtsFlow:1; - DWORD fOutxDsrFlow:1; - DWORD fDtrControl:2; - DWORD fDsrSensitivity:1; - DWORD fTXContinueOnXoff: 1; - DWORD fOutX: 1; - DWORD fInX: 1; - DWORD fErrorChar: 1; - DWORD fNull: 1; - DWORD fRtsControl:2; - DWORD fAbortOnError:1; - DWORD fDummy2:17; - WORD wReserved; - WORD XonLim; - WORD XoffLim; - BYTE ByteSize; - BYTE Parity; - BYTE StopBits; - char XonChar; - char XoffChar; - char ErrorChar; - char EofChar; - char EvtChar; - WORD wReserved1; - } DCB,*LPDCB; - - typedef struct _COMMTIMEOUTS { - DWORD ReadIntervalTimeout; - DWORD ReadTotalTimeoutMultiplier; - DWORD ReadTotalTimeoutConstant; - DWORD WriteTotalTimeoutMultiplier; - DWORD WriteTotalTimeoutConstant; - } COMMTIMEOUTS,*LPCOMMTIMEOUTS; - - typedef struct _COMMCONFIG { - DWORD dwSize; - WORD wVersion; - WORD wReserved; - DCB dcb; - DWORD dwProviderSubType; - DWORD dwProviderOffset; - DWORD dwProviderSize; - WCHAR wcProviderData[1]; - } COMMCONFIG,*LPCOMMCONFIG; - - typedef struct _SYSTEM_INFO { - union { - DWORD dwOemId; - struct { - WORD wProcessorArchitecture; - WORD wReserved; - }; - }; - DWORD dwPageSize; - LPVOID lpMinimumApplicationAddress; - LPVOID lpMaximumApplicationAddress; - DWORD_PTR dwActiveProcessorMask; - DWORD dwNumberOfProcessors; - DWORD dwProcessorType; - DWORD dwAllocationGranularity; - WORD wProcessorLevel; - WORD wProcessorRevision; - } SYSTEM_INFO,*LPSYSTEM_INFO; - -#define FreeModule(hLibModule) FreeLibrary((hLibModule)) -#define MakeProcInstance(lpProc,hInstance) (lpProc) -#define FreeProcInstance(lpProc) (lpProc) - -#define GMEM_FIXED 0x0 -#define GMEM_MOVEABLE 0x2 -#define GMEM_NOCOMPACT 0x10 -#define GMEM_NODISCARD 0x20 -#define GMEM_ZEROINIT 0x40 -#define GMEM_MODIFY 0x80 -#define GMEM_DISCARDABLE 0x100 -#define GMEM_NOT_BANKED 0x1000 -#define GMEM_SHARE 0x2000 -#define GMEM_DDESHARE 0x2000 -#define GMEM_NOTIFY 0x4000 -#define GMEM_LOWER GMEM_NOT_BANKED -#define GMEM_VALID_FLAGS 0x7F72 -#define GMEM_INVALID_HANDLE 0x8000 - -#define GHND (GMEM_MOVEABLE | GMEM_ZEROINIT) -#define GPTR (GMEM_FIXED | GMEM_ZEROINIT) - -#define GlobalLRUNewest(h) ((HANDLE)(h)) -#define GlobalLRUOldest(h) ((HANDLE)(h)) -#define GlobalDiscard(h) GlobalReAlloc((h),0,GMEM_MOVEABLE) - -#define GMEM_DISCARDED 0x4000 -#define GMEM_LOCKCOUNT 0xff - - typedef struct _MEMORYSTATUS { - DWORD dwLength; - DWORD dwMemoryLoad; - SIZE_T dwTotalPhys; - SIZE_T dwAvailPhys; - SIZE_T dwTotalPageFile; - SIZE_T dwAvailPageFile; - SIZE_T dwTotalVirtual; - SIZE_T dwAvailVirtual; - } MEMORYSTATUS,*LPMEMORYSTATUS; - -#define LMEM_FIXED 0x0 -#define LMEM_MOVEABLE 0x2 -#define LMEM_NOCOMPACT 0x10 -#define LMEM_NODISCARD 0x20 -#define LMEM_ZEROINIT 0x40 -#define LMEM_MODIFY 0x80 -#define LMEM_DISCARDABLE 0xf00 -#define LMEM_VALID_FLAGS 0xf72 -#define LMEM_INVALID_HANDLE 0x8000 - -#define LHND (LMEM_MOVEABLE | LMEM_ZEROINIT) -#define LPTR (LMEM_FIXED | LMEM_ZEROINIT) - -#define NONZEROLHND (LMEM_MOVEABLE) -#define NONZEROLPTR (LMEM_FIXED) - -#define LocalDiscard(h) LocalReAlloc((h),0,LMEM_MOVEABLE) - -#define LMEM_DISCARDED 0x4000 -#define LMEM_LOCKCOUNT 0xff - -#define DEBUG_PROCESS 0x1 -#define DEBUG_ONLY_THIS_PROCESS 0x2 -#define CREATE_SUSPENDED 0x4 -#define DETACHED_PROCESS 0x8 -#define CREATE_NEW_CONSOLE 0x10 -#define NORMAL_PRIORITY_CLASS 0x20 -#define IDLE_PRIORITY_CLASS 0x40 -#define HIGH_PRIORITY_CLASS 0x80 -#define REALTIME_PRIORITY_CLASS 0x100 -#define CREATE_NEW_PROCESS_GROUP 0x200 -#define CREATE_UNICODE_ENVIRONMENT 0x400 -#define CREATE_SEPARATE_WOW_VDM 0x800 -#define CREATE_SHARED_WOW_VDM 0x1000 -#define CREATE_FORCEDOS 0x2000 -#define BELOW_NORMAL_PRIORITY_CLASS 0x4000 -#define ABOVE_NORMAL_PRIORITY_CLASS 0x8000 -#define STACK_SIZE_PARAM_IS_A_RESERVATION 0x10000 - -#define CREATE_BREAKAWAY_FROM_JOB 0x1000000 -#define CREATE_PRESERVE_CODE_AUTHZ_LEVEL 0x2000000 - -#define CREATE_DEFAULT_ERROR_MODE 0x4000000 -#define CREATE_NO_WINDOW 0x8000000 - -#define PROFILE_USER 0x10000000 -#define PROFILE_KERNEL 0x20000000 -#define PROFILE_SERVER 0x40000000 - -#define CREATE_IGNORE_SYSTEM_DEFAULT 0x80000000 - -#define THREAD_PRIORITY_LOWEST THREAD_BASE_PRIORITY_MIN -#define THREAD_PRIORITY_BELOW_NORMAL (THREAD_PRIORITY_LOWEST+1) -#define THREAD_PRIORITY_NORMAL 0 -#define THREAD_PRIORITY_HIGHEST THREAD_BASE_PRIORITY_MAX -#define THREAD_PRIORITY_ABOVE_NORMAL (THREAD_PRIORITY_HIGHEST-1) -#define THREAD_PRIORITY_ERROR_RETURN (MAXLONG) - -#define THREAD_PRIORITY_TIME_CRITICAL THREAD_BASE_PRIORITY_LOWRT -#define THREAD_PRIORITY_IDLE THREAD_BASE_PRIORITY_IDLE - -#define EXCEPTION_DEBUG_EVENT 1 -#define CREATE_THREAD_DEBUG_EVENT 2 -#define CREATE_PROCESS_DEBUG_EVENT 3 -#define EXIT_THREAD_DEBUG_EVENT 4 -#define EXIT_PROCESS_DEBUG_EVENT 5 -#define LOAD_DLL_DEBUG_EVENT 6 -#define UNLOAD_DLL_DEBUG_EVENT 7 -#define OUTPUT_DEBUG_STRING_EVENT 8 -#define RIP_EVENT 9 - - typedef struct _EXCEPTION_DEBUG_INFO { - EXCEPTION_RECORD ExceptionRecord; - DWORD dwFirstChance; - } EXCEPTION_DEBUG_INFO,*LPEXCEPTION_DEBUG_INFO; - - typedef struct _CREATE_THREAD_DEBUG_INFO { - HANDLE hThread; - LPVOID lpThreadLocalBase; - LPTHREAD_START_ROUTINE lpStartAddress; - } CREATE_THREAD_DEBUG_INFO,*LPCREATE_THREAD_DEBUG_INFO; - - typedef struct _CREATE_PROCESS_DEBUG_INFO { - HANDLE hFile; - HANDLE hProcess; - HANDLE hThread; - LPVOID lpBaseOfImage; - DWORD dwDebugInfoFileOffset; - DWORD nDebugInfoSize; - LPVOID lpThreadLocalBase; - LPTHREAD_START_ROUTINE lpStartAddress; - LPVOID lpImageName; - WORD fUnicode; - } CREATE_PROCESS_DEBUG_INFO,*LPCREATE_PROCESS_DEBUG_INFO; - - typedef struct _EXIT_THREAD_DEBUG_INFO { - DWORD dwExitCode; - } EXIT_THREAD_DEBUG_INFO,*LPEXIT_THREAD_DEBUG_INFO; - - typedef struct _EXIT_PROCESS_DEBUG_INFO { - DWORD dwExitCode; - } EXIT_PROCESS_DEBUG_INFO,*LPEXIT_PROCESS_DEBUG_INFO; - - typedef struct _LOAD_DLL_DEBUG_INFO { - HANDLE hFile; - LPVOID lpBaseOfDll; - DWORD dwDebugInfoFileOffset; - DWORD nDebugInfoSize; - LPVOID lpImageName; - WORD fUnicode; - } LOAD_DLL_DEBUG_INFO,*LPLOAD_DLL_DEBUG_INFO; - - typedef struct _UNLOAD_DLL_DEBUG_INFO { - LPVOID lpBaseOfDll; - } UNLOAD_DLL_DEBUG_INFO,*LPUNLOAD_DLL_DEBUG_INFO; - - typedef struct _OUTPUT_DEBUG_STRING_INFO { - LPSTR lpDebugStringData; - WORD fUnicode; - WORD nDebugStringLength; - } OUTPUT_DEBUG_STRING_INFO,*LPOUTPUT_DEBUG_STRING_INFO; - - typedef struct _RIP_INFO { - DWORD dwError; - DWORD dwType; - } RIP_INFO,*LPRIP_INFO; - - typedef struct _DEBUG_EVENT { - DWORD dwDebugEventCode; - DWORD dwProcessId; - DWORD dwThreadId; - union { - EXCEPTION_DEBUG_INFO Exception; - CREATE_THREAD_DEBUG_INFO CreateThread; - CREATE_PROCESS_DEBUG_INFO CreateProcessInfo; - EXIT_THREAD_DEBUG_INFO ExitThread; - EXIT_PROCESS_DEBUG_INFO ExitProcess; - LOAD_DLL_DEBUG_INFO LoadDll; - UNLOAD_DLL_DEBUG_INFO UnloadDll; - OUTPUT_DEBUG_STRING_INFO DebugString; - RIP_INFO RipInfo; - } u; - } DEBUG_EVENT,*LPDEBUG_EVENT; - - typedef PCONTEXT LPCONTEXT; - typedef PEXCEPTION_RECORD LPEXCEPTION_RECORD; - typedef PEXCEPTION_POINTERS LPEXCEPTION_POINTERS; - -#define DRIVE_UNKNOWN 0 -#define DRIVE_NO_ROOT_DIR 1 -#define DRIVE_REMOVABLE 2 -#define DRIVE_FIXED 3 -#define DRIVE_REMOTE 4 -#define DRIVE_CDROM 5 -#define DRIVE_RAMDISK 6 - -#define GetFreeSpace(w) (0x100000L) -#define FILE_TYPE_UNKNOWN 0x0 -#define FILE_TYPE_DISK 0x1 -#define FILE_TYPE_CHAR 0x2 -#define FILE_TYPE_PIPE 0x3 -#define FILE_TYPE_REMOTE 0x8000 - -#define STD_INPUT_HANDLE ((DWORD)-10) -#define STD_OUTPUT_HANDLE ((DWORD)-11) -#define STD_ERROR_HANDLE ((DWORD)-12) - -#define NOPARITY 0 -#define ODDPARITY 1 -#define EVENPARITY 2 -#define MARKPARITY 3 -#define SPACEPARITY 4 - -#define ONESTOPBIT 0 -#define ONE5STOPBITS 1 -#define TWOSTOPBITS 2 - -#define IGNORE 0 -#define INFINITE 0xffffffff - -#define CBR_110 110 -#define CBR_300 300 -#define CBR_600 600 -#define CBR_1200 1200 -#define CBR_2400 2400 -#define CBR_4800 4800 -#define CBR_9600 9600 -#define CBR_14400 14400 -#define CBR_19200 19200 -#define CBR_38400 38400 -#define CBR_56000 56000 -#define CBR_57600 57600 -#define CBR_115200 115200 -#define CBR_128000 128000 -#define CBR_256000 256000 - -#define CE_RXOVER 0x1 -#define CE_OVERRUN 0x2 -#define CE_RXPARITY 0x4 -#define CE_FRAME 0x8 -#define CE_BREAK 0x10 -#define CE_TXFULL 0x100 -#define CE_PTO 0x200 -#define CE_IOE 0x400 -#define CE_DNS 0x800 -#define CE_OOP 0x1000 -#define CE_MODE 0x8000 - -#define IE_BADID (-1) -#define IE_OPEN (-2) -#define IE_NOPEN (-3) -#define IE_MEMORY (-4) -#define IE_DEFAULT (-5) -#define IE_HARDWARE (-10) -#define IE_BYTESIZE (-11) -#define IE_BAUDRATE (-12) - -#define EV_RXCHAR 0x1 -#define EV_RXFLAG 0x2 -#define EV_TXEMPTY 0x4 -#define EV_CTS 0x8 -#define EV_DSR 0x10 -#define EV_RLSD 0x20 -#define EV_BREAK 0x40 -#define EV_ERR 0x80 -#define EV_RING 0x100 -#define EV_PERR 0x200 -#define EV_RX80FULL 0x400 -#define EV_EVENT1 0x800 -#define EV_EVENT2 0x1000 - -#define SETXOFF 1 -#define SETXON 2 -#define SETRTS 3 -#define CLRRTS 4 -#define SETDTR 5 -#define CLRDTR 6 -#define RESETDEV 7 -#define SETBREAK 8 -#define CLRBREAK 9 - -#define PURGE_TXABORT 0x1 -#define PURGE_RXABORT 0x2 -#define PURGE_TXCLEAR 0x4 -#define PURGE_RXCLEAR 0x8 - -#define LPTx 0x80 - -#define MS_CTS_ON ((DWORD)0x10) -#define MS_DSR_ON ((DWORD)0x20) -#define MS_RING_ON ((DWORD)0x40) -#define MS_RLSD_ON ((DWORD)0x80) - -#define S_QUEUEEMPTY 0 -#define S_THRESHOLD 1 -#define S_ALLTHRESHOLD 2 - -#define S_NORMAL 0 -#define S_LEGATO 1 -#define S_STACCATO 2 - -#define S_PERIOD512 0 -#define S_PERIOD1024 1 -#define S_PERIOD2048 2 -#define S_PERIODVOICE 3 -#define S_WHITE512 4 -#define S_WHITE1024 5 -#define S_WHITE2048 6 -#define S_WHITEVOICE 7 - -#define S_SERDVNA (-1) -#define S_SEROFM (-2) -#define S_SERMACT (-3) -#define S_SERQFUL (-4) -#define S_SERBDNT (-5) -#define S_SERDLN (-6) -#define S_SERDCC (-7) -#define S_SERDTP (-8) -#define S_SERDVL (-9) -#define S_SERDMD (-10) -#define S_SERDSH (-11) -#define S_SERDPT (-12) -#define S_SERDFQ (-13) -#define S_SERDDR (-14) -#define S_SERDSR (-15) -#define S_SERDST (-16) - -#define NMPWAIT_WAIT_FOREVER 0xffffffff -#define NMPWAIT_NOWAIT 0x1 -#define NMPWAIT_USE_DEFAULT_WAIT 0x0 - -#define FS_CASE_IS_PRESERVED FILE_CASE_PRESERVED_NAMES -#define FS_CASE_SENSITIVE FILE_CASE_SENSITIVE_SEARCH -#define FS_UNICODE_STORED_ON_DISK FILE_UNICODE_ON_DISK -#define FS_PERSISTENT_ACLS FILE_PERSISTENT_ACLS -#define FS_VOL_IS_COMPRESSED FILE_VOLUME_IS_COMPRESSED -#define FS_FILE_COMPRESSION FILE_FILE_COMPRESSION -#define FS_FILE_ENCRYPTION FILE_SUPPORTS_ENCRYPTION - -#define FILE_MAP_COPY SECTION_QUERY -#define FILE_MAP_WRITE SECTION_MAP_WRITE -#define FILE_MAP_READ SECTION_MAP_READ -#define FILE_MAP_ALL_ACCESS SECTION_ALL_ACCESS -#define FILE_MAP_EXECUTE SECTION_MAP_EXECUTE_EXPLICIT - -#define OF_READ 0x0 -#define OF_WRITE 0x1 -#define OF_READWRITE 0x2 -#define OF_SHARE_COMPAT 0x0 -#define OF_SHARE_EXCLUSIVE 0x10 -#define OF_SHARE_DENY_WRITE 0x20 -#define OF_SHARE_DENY_READ 0x30 -#define OF_SHARE_DENY_NONE 0x40 -#define OF_PARSE 0x100 -#define OF_DELETE 0x200 -#define OF_VERIFY 0x400 -#define OF_CANCEL 0x800 -#define OF_CREATE 0x1000 -#define OF_PROMPT 0x2000 -#define OF_EXIST 0x4000 -#define OF_REOPEN 0x8000 - -#define OFS_MAXPATHNAME 128 - typedef struct _OFSTRUCT { - BYTE cBytes; - BYTE fFixedDisk; - WORD nErrCode; - WORD Reserved1; - WORD Reserved2; - CHAR szPathName[OFS_MAXPATHNAME]; - } OFSTRUCT,*LPOFSTRUCT,*POFSTRUCT; - -#ifndef NOWINBASEINTERLOCK - -#ifndef _NTOS_ - -#if defined(__ia64__) && !defined(RC_INVOKED) - -#define InterlockedIncrement _InterlockedIncrement -#define InterlockedIncrementAcquire _InterlockedIncrement_acq -#define InterlockedIncrementRelease _InterlockedIncrement_rel -#define InterlockedDecrement _InterlockedDecrement -#define InterlockedDecrementAcquire _InterlockedDecrement_acq -#define InterlockedDecrementRelease _InterlockedDecrement_rel -#define InterlockedExchange _InterlockedExchange -#define InterlockedExchangeAdd _InterlockedExchangeAdd -#define InterlockedCompareExchange _InterlockedCompareExchange -#define InterlockedCompareExchangeAcquire _InterlockedCompareExchange_acq -#define InterlockedCompareExchangeRelease _InterlockedCompareExchange_rel -#define InterlockedExchangePointer _InterlockedExchangePointer -#define InterlockedCompareExchangePointer _InterlockedCompareExchangePointer -#define InterlockedCompareExchangePointerRelease _InterlockedCompareExchangePointer_rel -#define InterlockedCompareExchangePointerAcquire _InterlockedCompareExchangePointer_acq - -#define InterlockedIncrement64 _InterlockedIncrement64 -#define InterlockedDecrement64 _InterlockedDecrement64 -#define InterlockedExchange64 _InterlockedExchange64 -#define InterlockedExchangeAcquire64 _InterlockedExchange64_acq -#define InterlockedExchangeAdd64 _InterlockedExchangeAdd64 -#define InterlockedCompareExchange64 _InterlockedCompareExchange64 -#define InterlockedCompareExchangeAcquire64 _InterlockedCompareExchange64_acq -#define InterlockedCompareExchangeRelease64 _InterlockedCompareExchange64_rel - - LONGLONG __cdecl InterlockedIncrement64(LONGLONG volatile *Addend); - LONGLONG __cdecl InterlockedDecrement64(LONGLONG volatile *Addend); - LONG __cdecl InterlockedIncrementAcquire(LONG volatile *Addend); - LONG __cdecl InterlockedDecrementAcquire(LONG volatile *Addend); - LONG __cdecl InterlockedIncrementRelease(LONG volatile *Addend); - LONG __cdecl InterlockedDecrementRelease(LONG volatile *Addend); - LONGLONG __cdecl InterlockedExchange64 (LONGLONG volatile *Target,LONGLONG Value); - LONGLONG __cdecl InterlockedExchangeAcquire64 (LONGLONG volatile *Target,LONGLONG Value); - LONGLONG __cdecl InterlockedExchangeAdd64 (LONGLONG volatile *Addend,LONGLONG Value); - LONGLONG __cdecl InterlockedCompareExchange64 (LONGLONG volatile *Destination,LONGLONG ExChange,LONGLONG Comperand); - LONGLONG __cdecl InterlockedCompareExchangeAcquire64 (LONGLONG volatile *Destination,LONGLONG ExChange,LONGLONG Comperand); - LONGLONG __cdecl InterlockedCompareExchangeRelease64 (LONGLONG volatile *Destination,LONGLONG ExChange,LONGLONG Comperand); - LONG __cdecl InterlockedIncrement(LONG volatile *lpAddend); - LONG __cdecl InterlockedDecrement(LONG volatile *lpAddend); - LONG __cdecl InterlockedExchange(LONG volatile *Target,LONG Value); - LONG __cdecl InterlockedExchangeAdd(LONG volatile *Addend,LONG Value); - LONG __cdecl InterlockedCompareExchange(LONG volatile *Destination,LONG ExChange,LONG Comperand); - LONG __cdecl InterlockedCompareExchangeRelease(LONG volatile *Destination,LONG ExChange,LONG Comperand); - LONG __cdecl InterlockedCompareExchangeAcquire(LONG volatile *Destination,LONG ExChange,LONG Comperand); - PVOID __cdecl InterlockedExchangePointer(PVOID volatile *Target,PVOID Value); - PVOID __cdecl InterlockedCompareExchangePointer(PVOID volatile *Destination,PVOID ExChange,PVOID Comperand); - PVOID __cdecl InterlockedCompareExchangePointerAcquire(PVOID volatile *Destination,PVOID Exchange,PVOID Comperand); - PVOID __cdecl InterlockedCompareExchangePointerRelease(PVOID volatile *Destination,PVOID Exchange,PVOID Comperand); - -#ifndef InterlockedAnd -#define InterlockedAnd InterlockedAnd_Inline - __CRT_INLINE LONG InterlockedAnd_Inline(LONG volatile *Target,LONG Set) { - LONG i; - LONG j; - j = *Target; - do { - i = j; - j = InterlockedCompareExchange(Target,i & Set,i); - } while(i!=j); - return j; - } -#endif - -#ifndef InterlockedOr -#define InterlockedOr InterlockedOr_Inline - - __CRT_INLINE LONG InterlockedOr_Inline(LONG volatile *Target,LONG Set) { - LONG i; - LONG j; - j = *Target; - do { - i = j; - j = InterlockedCompareExchange(Target,i | Set,i); - } while(i!=j); - return j; - } -#endif - -#ifndef InterlockedXor -#define InterlockedXor InterlockedXor_Inline - - __CRT_INLINE LONG InterlockedXor_Inline(LONG volatile *Target,LONG Set) { - LONG i; - LONG j; - j = *Target; - do { - i = j; - j = InterlockedCompareExchange(Target,i ^ Set,i); - } while(i!=j); - return j; - } -#endif - -#ifndef !defined (InterlockedAnd64) -#define InterlockedAnd64 InterlockedAnd64_Inline - - __CRT_INLINE LONGLONG InterlockedAnd64_Inline (LONGLONG volatile *Destination,LONGLONG Value) { - LONGLONG Old; - do { - Old = *Destination; - } while(InterlockedCompareExchange64(Destination,Old & Value,Old)!=Old); - return Old; - } -#endif - -#ifndef InterlockedOr64 -#define InterlockedOr64 InterlockedOr64_Inline - - __CRT_INLINE LONGLONG InterlockedOr64_Inline (LONGLONG volatile *Destination,LONGLONG Value) { - LONGLONG Old; - do { - Old = *Destination; - } while(InterlockedCompareExchange64(Destination,Old | Value,Old)!=Old); - return Old; - } -#endif - -#ifndef InterlockedXor64 -#define InterlockedXor64 InterlockedXor64_Inline - - __CRT_INLINE LONGLONG InterlockedXor64_Inline (LONGLONG volatile *Destination,LONGLONG Value) { - LONGLONG Old; - do { - Old = *Destination; - } while(InterlockedCompareExchange64(Destination,Old ^ Value,Old)!=Old); - return Old; - } -#endif - -#ifndef InterlockedBitTestAndSet -#define InterlockedBitTestAndSet InterlockedBitTestAndSet_Inline - - __CRT_INLINE BOOLEAN InterlockedBitTestAndSet_Inline(LONG *Base,LONG Bit) { - LONG tBit; - tBit = 1<<(Bit & (sizeof (*Base)*8-1)); - return (BOOLEAN)((InterlockedOr(&Base[Bit/(sizeof(*Base)*8)],tBit)&tBit)!=0); - } -#endif - -#ifndef InterlockedBitTestAndReset -#define InterlockedBitTestAndReset InterlockedBitTestAndReset_Inline - - __CRT_INLINE BOOLEAN InterlockedBitTestAndReset_Inline(LONG *Base,LONG Bit) { - LONG tBit; - tBit = 1<<(Bit & (sizeof (*Base)*8-1)); - return (BOOLEAN)((InterlockedAnd(&Base[Bit/(sizeof(*Base)*8)],~tBit)&tBit)!=0); - } -#endif - -#ifndef InterlockedBitTestAndComplement -#define InterlockedBitTestAndComplement InterlockedBitTestAndComplement_Inline - - __CRT_INLINE BOOLEAN InterlockedBitTestAndComplement_Inline(LONG *Base,LONG Bit) { - LONG tBit; - tBit = 1<<(Bit & (sizeof (*Base)*8-1)); - return (BOOLEAN)((InterlockedXor(&Base[Bit/(sizeof(*Base)*8)],tBit)&tBit)!=0); - } -#endif -#elif defined(__x86_64) && !defined(RC_INVOKED) - -#define InterlockedIncrement _InterlockedIncrement -#define InterlockedIncrementAcquire InterlockedIncrement -#define InterlockedIncrementRelease InterlockedIncrement -#define InterlockedDecrement _InterlockedDecrement -#define InterlockedDecrementAcquire InterlockedDecrement -#define InterlockedDecrementRelease InterlockedDecrement -#define InterlockedExchange _InterlockedExchange -#define InterlockedExchangeAdd _InterlockedExchangeAdd -#define InterlockedCompareExchange _InterlockedCompareExchange -#define InterlockedCompareExchangeAcquire InterlockedCompareExchange -#define InterlockedCompareExchangeRelease InterlockedCompareExchange -#define InterlockedExchangePointer _InterlockedExchangePointer -#define InterlockedCompareExchangePointer _InterlockedCompareExchangePointer -#define InterlockedCompareExchangePointerAcquire _InterlockedCompareExchangePointer -#define InterlockedCompareExchangePointerRelease _InterlockedCompareExchangePointer -#define InterlockedAnd64 _InterlockedAnd64 -#define InterlockedOr64 _InterlockedOr64 -#define InterlockedXor64 _InterlockedXor64 -#define InterlockedIncrement64 _InterlockedIncrement64 -#define InterlockedDecrement64 _InterlockedDecrement64 -#define InterlockedExchange64 _InterlockedExchange64 -#define InterlockedExchangeAdd64 _InterlockedExchangeAdd64 -#define InterlockedCompareExchange64 _InterlockedCompareExchange64 -#define InterlockedCompareExchangeAcquire64 InterlockedCompareExchange64 -#define InterlockedCompareExchangeRelease64 InterlockedCompareExchange64 - - LONG InterlockedIncrement(LONG volatile *Addend); - LONG InterlockedDecrement(LONG volatile *Addend); - LONG InterlockedExchange(LONG volatile *Target,LONG Value); - LONG InterlockedExchangeAdd(LONG volatile *Addend,LONG Value); - LONG InterlockedCompareExchange(LONG volatile *Destination,LONG ExChange,LONG Comperand); - PVOID InterlockedCompareExchangePointer(PVOID volatile *Destination,PVOID Exchange,PVOID Comperand); - PVOID InterlockedExchangePointer(PVOID volatile *Target,PVOID Value); - LONG64 InterlockedAnd64(LONG64 volatile *Destination,LONG64 Value); - LONG64 InterlockedOr64(LONG64 volatile *Destination,LONG64 Value); - LONG64 InterlockedXor64(LONG64 volatile *Destination,LONG64 Value); - LONG64 InterlockedIncrement64(LONG64 volatile *Addend); - LONG64 InterlockedDecrement64(LONG64 volatile *Addend); - LONG64 InterlockedExchange64(LONG64 volatile *Target,LONG64 Value); - LONG64 InterlockedExchangeAdd64(LONG64 volatile *Addend,LONG64 Value); - LONG64 InterlockedCompareExchange64(LONG64 volatile *Destination,LONG64 ExChange,LONG64 Comperand); -#else - LONG WINAPI InterlockedIncrement(LONG volatile *lpAddend); - LONG WINAPI InterlockedDecrement(LONG volatile *lpAddend); - LONG WINAPI InterlockedExchange(LONG volatile *Target,LONG Value); - -#define InterlockedExchangePointer(Target,Value) (PVOID)InterlockedExchange((PLONG)(Target),(LONG)(Value)) - - LONG WINAPI InterlockedExchangeAdd(LONG volatile *Addend,LONG Value); - LONG WINAPI InterlockedCompareExchange(LONG volatile *Destination,LONG Exchange,LONG Comperand); - LONGLONG WINAPI InterlockedCompareExchange64(LONGLONG volatile *Destination,LONGLONG Exchange,LONGLONG Comperand); - - __CRT_INLINE LONGLONG InterlockedAnd64 (LONGLONG volatile *Destination,LONGLONG Value) { - LONGLONG Old; - do { - Old = *Destination; - } while(InterlockedCompareExchange64(Destination,Old & Value,Old)!=Old); - return Old; - } - - __CRT_INLINE LONGLONG InterlockedOr64 (LONGLONG volatile *Destination,LONGLONG Value) { - LONGLONG Old; - do { - Old = *Destination; - } while(InterlockedCompareExchange64(Destination,Old | Value,Old)!=Old); - return Old; - } - - __CRT_INLINE LONGLONG InterlockedXor64 (LONGLONG volatile *Destination,LONGLONG Value) { - LONGLONG Old; - do { - Old = *Destination; - } while(InterlockedCompareExchange64(Destination,Old ^ Value,Old)!=Old); - - return Old; - } - - __CRT_INLINE LONGLONG InterlockedIncrement64(LONGLONG volatile *Addend) { - LONGLONG Old; - do { - Old = *Addend; - } while(InterlockedCompareExchange64(Addend,Old + 1,Old)!=Old); - return Old + 1; - } - - __CRT_INLINE LONGLONG InterlockedDecrement64(LONGLONG volatile *Addend) { - LONGLONG Old; - do { - Old = *Addend; - } while(InterlockedCompareExchange64(Addend,Old - 1,Old)!=Old); - return Old - 1; - } - - __CRT_INLINE LONGLONG InterlockedExchange64(LONGLONG volatile *Target,LONGLONG Value) { - LONGLONG Old; - do { - Old = *Target; - } while(InterlockedCompareExchange64(Target,Value,Old)!=Old); - return Old; - } - - __CRT_INLINE LONGLONG InterlockedExchangeAdd64(LONGLONG volatile *Addend,LONGLONG Value) { - LONGLONG Old; - do { - Old = *Addend; - } while(InterlockedCompareExchange64(Addend,Old + Value,Old)!=Old); - return Old; - } - -#ifdef __cplusplus - __CRT_INLINE PVOID __cdecl __InlineInterlockedCompareExchangePointer(PVOID volatile *Destination,PVOID ExChange,PVOID Comperand) { - return((PVOID)(LONG_PTR)InterlockedCompareExchange((LONG volatile *)Destination,(LONG)(LONG_PTR)ExChange,(LONG)(LONG_PTR)Comperand)); - } -#define InterlockedCompareExchangePointer __InlineInterlockedCompareExchangePointer -#else -#define InterlockedCompareExchangePointer(Destination,ExChange,Comperand)(PVOID)(LONG_PTR)InterlockedCompareExchange((LONG volatile *)(Destination),(LONG)(LONG_PTR)(ExChange),(LONG)(LONG_PTR)(Comperand)) -#endif - -#define InterlockedIncrementAcquire InterlockedIncrement -#define InterlockedIncrementRelease InterlockedIncrement -#define InterlockedDecrementAcquire InterlockedDecrement -#define InterlockedDecrementRelease InterlockedDecrement -#define InterlockedIncrementAcquire InterlockedIncrement -#define InterlockedIncrementRelease InterlockedIncrement -#define InterlockedCompareExchangeAcquire InterlockedCompareExchange -#define InterlockedCompareExchangeRelease InterlockedCompareExchange -#define InterlockedCompareExchangeAcquire64 InterlockedCompareExchange64 -#define InterlockedCompareExchangeRelease64 InterlockedCompareExchange64 -#define InterlockedCompareExchangePointerAcquire InterlockedCompareExchangePointer -#define InterlockedCompareExchangePointerRelease InterlockedCompareExchangePointer -#endif - -#if defined(_SLIST_HEADER_) && !defined(_NTOSP_) - WINBASEAPI VOID WINAPI InitializeSListHead(PSLIST_HEADER ListHead); - WINBASEAPI PSLIST_ENTRY WINAPI InterlockedPopEntrySList(PSLIST_HEADER ListHead); - WINBASEAPI PSLIST_ENTRY WINAPI InterlockedPushEntrySList(PSLIST_HEADER ListHead,PSLIST_ENTRY ListEntry); - WINBASEAPI PSLIST_ENTRY WINAPI InterlockedFlushSList(PSLIST_HEADER ListHead); - WINBASEAPI USHORT WINAPI QueryDepthSList(PSLIST_HEADER ListHead); -#endif -#endif -#endif - - WINBASEAPI WINBOOL WINAPI FreeResource(HGLOBAL hResData); - WINBASEAPI LPVOID WINAPI LockResource(HGLOBAL hResData); - -#define UnlockResource(hResData) ((hResData),0) -#define MAXINTATOM 0xC000 -#define MAKEINTATOM(i) (LPTSTR)((ULONG_PTR)((WORD)(i))) -#define INVALID_ATOM ((ATOM)0) - - int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd); - WINBASEAPI WINBOOL WINAPI FreeLibrary(HMODULE hLibModule); - WINBASEAPI DECLSPEC_NORETURN VOID WINAPI FreeLibraryAndExitThread(HMODULE hLibModule,DWORD dwExitCode); - WINBASEAPI WINBOOL WINAPI DisableThreadLibraryCalls(HMODULE hLibModule); - WINBASEAPI FARPROC WINAPI GetProcAddress(HMODULE hModule,LPCSTR lpProcName); - WINBASEAPI DWORD WINAPI GetVersion(VOID); - WINBASEAPI HGLOBAL WINAPI GlobalAlloc(UINT uFlags,SIZE_T dwBytes); - WINBASEAPI HGLOBAL WINAPI GlobalReAlloc(HGLOBAL hMem,SIZE_T dwBytes,UINT uFlags); - WINBASEAPI SIZE_T WINAPI GlobalSize(HGLOBAL hMem); - WINBASEAPI UINT WINAPI GlobalFlags(HGLOBAL hMem); - WINBASEAPI LPVOID WINAPI GlobalLock(HGLOBAL hMem); - WINBASEAPI HGLOBAL WINAPI GlobalHandle(LPCVOID pMem); - WINBASEAPI WINBOOL WINAPI GlobalUnlock(HGLOBAL hMem); - WINBASEAPI HGLOBAL WINAPI GlobalFree(HGLOBAL hMem); - WINBASEAPI SIZE_T WINAPI GlobalCompact(DWORD dwMinFree); - WINBASEAPI VOID WINAPI GlobalFix(HGLOBAL hMem); - WINBASEAPI VOID WINAPI GlobalUnfix(HGLOBAL hMem); - WINBASEAPI LPVOID WINAPI GlobalWire(HGLOBAL hMem); - WINBASEAPI WINBOOL WINAPI GlobalUnWire(HGLOBAL hMem); - WINBASEAPI VOID WINAPI GlobalMemoryStatus(LPMEMORYSTATUS lpBuffer); - - typedef struct _MEMORYSTATUSEX { - DWORD dwLength; - DWORD dwMemoryLoad; - DWORDLONG ullTotalPhys; - DWORDLONG ullAvailPhys; - DWORDLONG ullTotalPageFile; - DWORDLONG ullAvailPageFile; - DWORDLONG ullTotalVirtual; - DWORDLONG ullAvailVirtual; - DWORDLONG ullAvailExtendedVirtual; - } MEMORYSTATUSEX,*LPMEMORYSTATUSEX; - - WINBASEAPI WINBOOL WINAPI GlobalMemoryStatusEx(LPMEMORYSTATUSEX lpBuffer); - WINBASEAPI HLOCAL WINAPI LocalAlloc(UINT uFlags,SIZE_T uBytes); - WINBASEAPI HLOCAL WINAPI LocalReAlloc(HLOCAL hMem,SIZE_T uBytes,UINT uFlags); - WINBASEAPI LPVOID WINAPI LocalLock(HLOCAL hMem); - WINBASEAPI HLOCAL WINAPI LocalHandle(LPCVOID pMem); - WINBASEAPI WINBOOL WINAPI LocalUnlock(HLOCAL hMem); - WINBASEAPI SIZE_T WINAPI LocalSize(HLOCAL hMem); - WINBASEAPI UINT WINAPI LocalFlags(HLOCAL hMem); - WINBASEAPI HLOCAL WINAPI LocalFree(HLOCAL hMem); - WINBASEAPI SIZE_T WINAPI LocalShrink(HLOCAL hMem,UINT cbNewSize); - WINBASEAPI SIZE_T WINAPI LocalCompact(UINT uMinFree); - WINBASEAPI WINBOOL WINAPI FlushInstructionCache(HANDLE hProcess,LPCVOID lpBaseAddress,SIZE_T dwSize); - WINBASEAPI LPVOID WINAPI VirtualAlloc(LPVOID lpAddress,SIZE_T dwSize,DWORD flAllocationType,DWORD flProtect); - WINBASEAPI WINBOOL WINAPI VirtualFree(LPVOID lpAddress,SIZE_T dwSize,DWORD dwFreeType); - WINBASEAPI WINBOOL WINAPI VirtualProtect(LPVOID lpAddress,SIZE_T dwSize,DWORD flNewProtect,PDWORD lpflOldProtect); - WINBASEAPI SIZE_T WINAPI VirtualQuery(LPCVOID lpAddress,PMEMORY_BASIC_INFORMATION lpBuffer,SIZE_T dwLength); - WINBASEAPI LPVOID WINAPI VirtualAllocEx(HANDLE hProcess,LPVOID lpAddress,SIZE_T dwSize,DWORD flAllocationType,DWORD flProtect); - WINBASEAPI UINT WINAPI GetWriteWatch(DWORD dwFlags,PVOID lpBaseAddress,SIZE_T dwRegionSize,PVOID *lpAddresses,ULONG_PTR *lpdwCount,PULONG lpdwGranularity); - WINBASEAPI UINT WINAPI ResetWriteWatch(LPVOID lpBaseAddress,SIZE_T dwRegionSize); - WINBASEAPI SIZE_T WINAPI GetLargePageMinimum(VOID); - WINBASEAPI UINT WINAPI EnumSystemFirmwareTables(DWORD FirmwareTableProviderSignature,PVOID pFirmwareTableEnumBuffer,DWORD BufferSize); - WINBASEAPI UINT WINAPI GetSystemFirmwareTable(DWORD FirmwareTableProviderSignature,DWORD FirmwareTableID,PVOID pFirmwareTableBuffer,DWORD BufferSize); - WINBASEAPI WINBOOL WINAPI VirtualFreeEx(HANDLE hProcess,LPVOID lpAddress,SIZE_T dwSize,DWORD dwFreeType); - WINBASEAPI WINBOOL WINAPI VirtualProtectEx(HANDLE hProcess,LPVOID lpAddress,SIZE_T dwSize,DWORD flNewProtect,PDWORD lpflOldProtect); - WINBASEAPI SIZE_T WINAPI VirtualQueryEx(HANDLE hProcess,LPCVOID lpAddress,PMEMORY_BASIC_INFORMATION lpBuffer,SIZE_T dwLength); - WINBASEAPI HANDLE WINAPI HeapCreate(DWORD flOptions,SIZE_T dwInitialSize,SIZE_T dwMaximumSize); - WINBASEAPI WINBOOL WINAPI HeapDestroy(HANDLE hHeap); - WINBASEAPI LPVOID WINAPI HeapAlloc(HANDLE hHeap,DWORD dwFlags,SIZE_T dwBytes); - WINBASEAPI LPVOID WINAPI HeapReAlloc(HANDLE hHeap,DWORD dwFlags,LPVOID lpMem,SIZE_T dwBytes); - WINBASEAPI WINBOOL WINAPI HeapFree(HANDLE hHeap,DWORD dwFlags,LPVOID lpMem); - WINBASEAPI SIZE_T WINAPI HeapSize(HANDLE hHeap,DWORD dwFlags,LPCVOID lpMem); - WINBASEAPI WINBOOL WINAPI HeapValidate(HANDLE hHeap,DWORD dwFlags,LPCVOID lpMem); - WINBASEAPI SIZE_T WINAPI HeapCompact(HANDLE hHeap,DWORD dwFlags); - WINBASEAPI HANDLE WINAPI GetProcessHeap(VOID); - WINBASEAPI DWORD WINAPI GetProcessHeaps(DWORD NumberOfHeaps,PHANDLE ProcessHeaps); - - typedef struct _PROCESS_HEAP_ENTRY { - PVOID lpData; - DWORD cbData; - BYTE cbOverhead; - BYTE iRegionIndex; - WORD wFlags; - union { - struct { - HANDLE hMem; - DWORD dwReserved[3]; - } Block; - struct { - DWORD dwCommittedSize; - DWORD dwUnCommittedSize; - LPVOID lpFirstBlock; - LPVOID lpLastBlock; - } Region; - }; - } PROCESS_HEAP_ENTRY,*LPPROCESS_HEAP_ENTRY,*PPROCESS_HEAP_ENTRY; - -#define PROCESS_HEAP_REGION 0x1 -#define PROCESS_HEAP_UNCOMMITTED_RANGE 0x2 -#define PROCESS_HEAP_ENTRY_BUSY 0x4 -#define PROCESS_HEAP_ENTRY_MOVEABLE 0x10 -#define PROCESS_HEAP_ENTRY_DDESHARE 0x20 - - WINBASEAPI WINBOOL WINAPI HeapLock(HANDLE hHeap); - WINBASEAPI WINBOOL WINAPI HeapUnlock(HANDLE hHeap); - WINBASEAPI WINBOOL WINAPI HeapWalk(HANDLE hHeap,LPPROCESS_HEAP_ENTRY lpEntry); - WINBASEAPI WINBOOL WINAPI HeapSetInformation(HANDLE HeapHandle,HEAP_INFORMATION_CLASS HeapInformationClass,PVOID HeapInformation,SIZE_T HeapInformationLength); - WINBASEAPI WINBOOL WINAPI HeapQueryInformation(HANDLE HeapHandle,HEAP_INFORMATION_CLASS HeapInformationClass,PVOID HeapInformation,SIZE_T HeapInformationLength,PSIZE_T ReturnLength); - -#define SCS_32BIT_BINARY 0 -#define SCS_DOS_BINARY 1 -#define SCS_WOW_BINARY 2 -#define SCS_PIF_BINARY 3 -#define SCS_POSIX_BINARY 4 -#define SCS_OS216_BINARY 5 -#define SCS_64BIT_BINARY 6 - -#ifdef UNICODE -#define GetBinaryType GetBinaryTypeW -#define GetShortPathName GetShortPathNameW -#define GetLongPathName GetLongPathNameW -#define GetEnvironmentStrings GetEnvironmentStringsW -#define SetEnvironmentStrings SetEnvironmentStringsW -#define FreeEnvironmentStrings FreeEnvironmentStringsW -#else -#define GetBinaryType GetBinaryTypeA -#define GetShortPathName GetShortPathNameA -#define GetLongPathName GetLongPathNameA -#define GetEnvironmentStringsA GetEnvironmentStrings -#define SetEnvironmentStrings SetEnvironmentStringsA -#define FreeEnvironmentStrings FreeEnvironmentStringsA -#endif - -#ifdef _WIN64 -#define SCS_THIS_PLATFORM_BINARY SCS_64BIT_BINARY -#else -#define SCS_THIS_PLATFORM_BINARY SCS_32BIT_BINARY -#endif - - WINBASEAPI WINBOOL WINAPI GetBinaryTypeA(LPCSTR lpApplicationName,LPDWORD lpBinaryType); - WINBASEAPI WINBOOL WINAPI GetBinaryTypeW(LPCWSTR lpApplicationName,LPDWORD lpBinaryType); - WINBASEAPI DWORD WINAPI GetShortPathNameA(LPCSTR lpszLongPath,LPSTR lpszShortPath,DWORD cchBuffer); - WINBASEAPI DWORD WINAPI GetShortPathNameW(LPCWSTR lpszLongPath,LPWSTR lpszShortPath,DWORD cchBuffer); - WINBASEAPI DWORD WINAPI GetLongPathNameA(LPCSTR lpszShortPath,LPSTR lpszLongPath,DWORD cchBuffer); - WINBASEAPI DWORD WINAPI GetLongPathNameW(LPCWSTR lpszShortPath,LPWSTR lpszLongPath,DWORD cchBuffer); - WINBASEAPI WINBOOL WINAPI GetProcessAffinityMask(HANDLE hProcess,PDWORD_PTR lpProcessAffinityMask,PDWORD_PTR lpSystemAffinityMask); - WINBASEAPI WINBOOL WINAPI SetProcessAffinityMask(HANDLE hProcess,DWORD_PTR dwProcessAffinityMask); - WINBASEAPI WINBOOL WINAPI GetProcessHandleCount(HANDLE hProcess,PDWORD pdwHandleCount); - WINBASEAPI WINBOOL WINAPI GetProcessTimes(HANDLE hProcess,LPFILETIME lpCreationTime,LPFILETIME lpExitTime,LPFILETIME lpKernelTime,LPFILETIME lpUserTime); - WINBASEAPI WINBOOL WINAPI GetProcessIoCounters(HANDLE hProcess,PIO_COUNTERS lpIoCounters); - WINBASEAPI WINBOOL WINAPI GetProcessWorkingSetSize(HANDLE hProcess,PSIZE_T lpMinimumWorkingSetSize,PSIZE_T lpMaximumWorkingSetSize); - WINBASEAPI WINBOOL WINAPI GetProcessWorkingSetSizeEx(HANDLE hProcess,PSIZE_T lpMinimumWorkingSetSize,PSIZE_T lpMaximumWorkingSetSize,PDWORD Flags); - WINBASEAPI WINBOOL WINAPI SetProcessWorkingSetSize(HANDLE hProcess,SIZE_T dwMinimumWorkingSetSize,SIZE_T dwMaximumWorkingSetSize); - WINBASEAPI WINBOOL WINAPI SetProcessWorkingSetSizeEx(HANDLE hProcess,SIZE_T dwMinimumWorkingSetSize,SIZE_T dwMaximumWorkingSetSize,DWORD Flags); - WINBASEAPI HANDLE WINAPI OpenProcess(DWORD dwDesiredAccess,WINBOOL bInheritHandle,DWORD dwProcessId); - WINBASEAPI HANDLE WINAPI GetCurrentProcess(VOID); - WINBASEAPI DWORD WINAPI GetCurrentProcessId(VOID); - WINBASEAPI DECLSPEC_NORETURN VOID WINAPI ExitProcess(UINT uExitCode); - WINBASEAPI WINBOOL WINAPI TerminateProcess(HANDLE hProcess,UINT uExitCode); - WINBASEAPI WINBOOL WINAPI GetExitCodeProcess(HANDLE hProcess,LPDWORD lpExitCode); - WINBASEAPI VOID WINAPI FatalExit(int ExitCode); - /* WINBASEAPI LPCH WINAPI GetEnvironmentStrings(VOID); */ - WINBASEAPI LPWCH WINAPI GetEnvironmentStringsW(VOID); - WINBASEAPI WINBOOL WINAPI SetEnvironmentStringsA(LPCH NewEnvironment); - WINBASEAPI WINBOOL WINAPI SetEnvironmentStringsW(LPWCH NewEnvironment); - WINBASEAPI WINBOOL WINAPI FreeEnvironmentStringsA(LPCH); - WINBASEAPI WINBOOL WINAPI FreeEnvironmentStringsW(LPWCH); - WINBASEAPI VOID WINAPI RaiseException(DWORD dwExceptionCode,DWORD dwExceptionFlags,DWORD nNumberOfArguments,CONST ULONG_PTR *lpArguments); - WINBASEAPI LONG WINAPI UnhandledExceptionFilter(struct _EXCEPTION_POINTERS *ExceptionInfo); - - typedef LONG (WINAPI *PTOP_LEVEL_EXCEPTION_FILTER)(struct _EXCEPTION_POINTERS *ExceptionInfo); - typedef PTOP_LEVEL_EXCEPTION_FILTER LPTOP_LEVEL_EXCEPTION_FILTER; - - WINBASEAPI LPTOP_LEVEL_EXCEPTION_FILTER WINAPI SetUnhandledExceptionFilter(LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter); - -#define FIBER_FLAG_FLOAT_SWITCH 0x1 - - WINBASEAPI LPVOID WINAPI CreateFiber(SIZE_T dwStackSize,LPFIBER_START_ROUTINE lpStartAddress,LPVOID lpParameter); - WINBASEAPI LPVOID WINAPI CreateFiberEx(SIZE_T dwStackCommitSize,SIZE_T dwStackReserveSize,DWORD dwFlags,LPFIBER_START_ROUTINE lpStartAddress,LPVOID lpParameter); - WINBASEAPI VOID WINAPI DeleteFiber(LPVOID lpFiber); - WINBASEAPI LPVOID WINAPI ConvertThreadToFiber(LPVOID lpParameter); - WINBASEAPI LPVOID WINAPI ConvertThreadToFiberEx(LPVOID lpParameter,DWORD dwFlags); - WINBASEAPI WINBOOL WINAPI ConvertFiberToThread(VOID); - WINBASEAPI VOID WINAPI SwitchToFiber(LPVOID lpFiber); - WINBASEAPI WINBOOL WINAPI SwitchToThread(VOID); - WINBASEAPI HANDLE WINAPI CreateThread(LPSECURITY_ATTRIBUTES lpThreadAttributes,SIZE_T dwStackSize,LPTHREAD_START_ROUTINE lpStartAddress,LPVOID lpParameter,DWORD dwCreationFlags,LPDWORD lpThreadId); - WINBASEAPI HANDLE WINAPI CreateRemoteThread(HANDLE hProcess,LPSECURITY_ATTRIBUTES lpThreadAttributes,SIZE_T dwStackSize,LPTHREAD_START_ROUTINE lpStartAddress,LPVOID lpParameter,DWORD dwCreationFlags,LPDWORD lpThreadId); - WINBASEAPI HANDLE WINAPI GetCurrentThread(VOID); - WINBASEAPI DWORD WINAPI GetCurrentThreadId(VOID); - WINBASEAPI WINBOOL WINAPI SetThreadStackGuarantee (PULONG StackSizeInBytes); - WINBASEAPI DWORD WINAPI GetProcessIdOfThread(HANDLE Thread); - WINBASEAPI DWORD WINAPI GetThreadId(HANDLE Thread); - WINBASEAPI DWORD WINAPI GetProcessId(HANDLE Process); - WINBASEAPI DWORD WINAPI GetCurrentProcessorNumber(VOID); - WINBASEAPI DWORD_PTR WINAPI SetThreadAffinityMask(HANDLE hThread,DWORD_PTR dwThreadAffinityMask); - WINBASEAPI DWORD WINAPI SetThreadIdealProcessor(HANDLE hThread,DWORD dwIdealProcessor); - WINBASEAPI WINBOOL WINAPI SetProcessPriorityBoost(HANDLE hProcess,WINBOOL bDisablePriorityBoost); - WINBASEAPI WINBOOL WINAPI GetProcessPriorityBoost(HANDLE hProcess,PBOOL pDisablePriorityBoost); - WINBASEAPI WINBOOL WINAPI RequestWakeupLatency(LATENCY_TIME latency); - WINBASEAPI WINBOOL WINAPI IsSystemResumeAutomatic(VOID); - WINBASEAPI HANDLE WINAPI OpenThread(DWORD dwDesiredAccess,WINBOOL bInheritHandle,DWORD dwThreadId); - WINBASEAPI WINBOOL WINAPI SetThreadPriority(HANDLE hThread,int nPriority); - WINBASEAPI WINBOOL WINAPI SetThreadPriorityBoost(HANDLE hThread,WINBOOL bDisablePriorityBoost); - WINBASEAPI WINBOOL WINAPI GetThreadPriorityBoost(HANDLE hThread,PBOOL pDisablePriorityBoost); - WINBASEAPI int WINAPI GetThreadPriority(HANDLE hThread); - WINBASEAPI WINBOOL WINAPI GetThreadTimes(HANDLE hThread,LPFILETIME lpCreationTime,LPFILETIME lpExitTime,LPFILETIME lpKernelTime,LPFILETIME lpUserTime); - WINBASEAPI WINBOOL WINAPI GetThreadIOPendingFlag(HANDLE hThread,PBOOL lpIOIsPending); - WINBASEAPI DECLSPEC_NORETURN VOID WINAPI ExitThread(DWORD dwExitCode); - WINBASEAPI WINBOOL WINAPI TerminateThread(HANDLE hThread,DWORD dwExitCode); - WINBASEAPI WINBOOL WINAPI GetExitCodeThread(HANDLE hThread,LPDWORD lpExitCode); - WINBASEAPI WINBOOL WINAPI GetThreadSelectorEntry(HANDLE hThread,DWORD dwSelector,LPLDT_ENTRY lpSelectorEntry); - WINBASEAPI EXECUTION_STATE WINAPI SetThreadExecutionState(EXECUTION_STATE esFlags); - WINBASEAPI DWORD WINAPI GetLastError(VOID); - WINBASEAPI VOID WINAPI SetLastError(DWORD dwErrCode); - -#ifndef RC_INVOKED -#ifdef WINBASE_DECLARE_RESTORE_LAST_ERROR - WINBASEAPI VOID WINAPI RestoreLastError(DWORD dwErrCode); - - typedef VOID (WINAPI *PRESTORE_LAST_ERROR)(DWORD); - -#define RESTORE_LAST_ERROR_NAME_A "RestoreLastError" -#define RESTORE_LAST_ERROR_NAME_W L"RestoreLastError" -#define RESTORE_LAST_ERROR_NAME TEXT("RestoreLastError") -#endif -#endif - -#define HasOverlappedIoCompleted(lpOverlapped) (((DWORD)(lpOverlapped)->Internal)!=STATUS_PENDING) - - WINBASEAPI WINBOOL WINAPI GetOverlappedResult(HANDLE hFile,LPOVERLAPPED lpOverlapped,LPDWORD lpNumberOfBytesTransferred,WINBOOL bWait); - WINBASEAPI HANDLE WINAPI CreateIoCompletionPort(HANDLE FileHandle,HANDLE ExistingCompletionPort,ULONG_PTR CompletionKey,DWORD NumberOfConcurrentThreads); - WINBASEAPI WINBOOL WINAPI GetQueuedCompletionStatus(HANDLE CompletionPort,LPDWORD lpNumberOfBytesTransferred,PULONG_PTR lpCompletionKey,LPOVERLAPPED *lpOverlapped,DWORD dwMilliseconds); - WINBASEAPI WINBOOL WINAPI PostQueuedCompletionStatus(HANDLE CompletionPort,DWORD dwNumberOfBytesTransferred,ULONG_PTR dwCompletionKey,LPOVERLAPPED lpOverlapped); - -#define SEM_FAILCRITICALERRORS 0x1 -#define SEM_NOGPFAULTERRORBOX 0x2 -#define SEM_NOALIGNMENTFAULTEXCEPT 0x4 -#define SEM_NOOPENFILEERRORBOX 0x8000 - - WINBASEAPI UINT WINAPI SetErrorMode(UINT uMode); - WINBASEAPI WINBOOL WINAPI ReadProcessMemory(HANDLE hProcess,LPCVOID lpBaseAddress,LPVOID lpBuffer,SIZE_T nSize,SIZE_T *lpNumberOfBytesRead); - WINBASEAPI WINBOOL WINAPI WriteProcessMemory(HANDLE hProcess,LPVOID lpBaseAddress,LPCVOID lpBuffer,SIZE_T nSize,SIZE_T *lpNumberOfBytesWritten); - WINBASEAPI WINBOOL WINAPI GetThreadContext(HANDLE hThread,LPCONTEXT lpContext); - WINBASEAPI WINBOOL WINAPI SetThreadContext(HANDLE hThread,CONST CONTEXT *lpContext); - WINBASEAPI DWORD WINAPI SuspendThread(HANDLE hThread); - WINBASEAPI DWORD WINAPI ResumeThread(HANDLE hThread); - - typedef VOID (WINAPI *PAPCFUNC)(ULONG_PTR dwParam); - - WINBASEAPI DWORD WINAPI QueueUserAPC(PAPCFUNC pfnAPC,HANDLE hThread,ULONG_PTR dwData); - WINBASEAPI WINBOOL WINAPI IsDebuggerPresent(VOID); - WINBASEAPI WINBOOL WINAPI CheckRemoteDebuggerPresent(HANDLE hProcess,PBOOL pbDebuggerPresent); - WINBASEAPI VOID WINAPI DebugBreak(VOID); - WINBASEAPI WINBOOL WINAPI WaitForDebugEvent(LPDEBUG_EVENT lpDebugEvent,DWORD dwMilliseconds); - WINBASEAPI WINBOOL WINAPI ContinueDebugEvent(DWORD dwProcessId,DWORD dwThreadId,DWORD dwContinueStatus); - WINBASEAPI WINBOOL WINAPI DebugActiveProcess(DWORD dwProcessId); - WINBASEAPI WINBOOL WINAPI DebugActiveProcessStop(DWORD dwProcessId); - WINBASEAPI WINBOOL WINAPI DebugSetProcessKillOnExit(WINBOOL KillOnExit); - WINBASEAPI WINBOOL WINAPI DebugBreakProcess(HANDLE Process); - WINBASEAPI VOID WINAPI InitializeCriticalSection(LPCRITICAL_SECTION lpCriticalSection); - WINBASEAPI VOID WINAPI EnterCriticalSection(LPCRITICAL_SECTION lpCriticalSection); - WINBASEAPI VOID WINAPI LeaveCriticalSection(LPCRITICAL_SECTION lpCriticalSection); - WINBASEAPI WINBOOL WINAPI InitializeCriticalSectionAndSpinCount(LPCRITICAL_SECTION lpCriticalSection,DWORD dwSpinCount); - WINBASEAPI DWORD WINAPI SetCriticalSectionSpinCount(LPCRITICAL_SECTION lpCriticalSection,DWORD dwSpinCount); - WINBASEAPI WINBOOL WINAPI TryEnterCriticalSection(LPCRITICAL_SECTION lpCriticalSection); - WINBASEAPI VOID WINAPI DeleteCriticalSection(LPCRITICAL_SECTION lpCriticalSection); - WINBASEAPI WINBOOL WINAPI SetEvent(HANDLE hEvent); - WINBASEAPI WINBOOL WINAPI ResetEvent(HANDLE hEvent); - WINBASEAPI WINBOOL WINAPI PulseEvent(HANDLE hEvent); - WINBASEAPI WINBOOL WINAPI ReleaseSemaphore(HANDLE hSemaphore,LONG lReleaseCount,LPLONG lpPreviousCount); - WINBASEAPI WINBOOL WINAPI ReleaseMutex(HANDLE hMutex); - WINBASEAPI DWORD WINAPI WaitForSingleObject(HANDLE hHandle,DWORD dwMilliseconds); - WINBASEAPI DWORD WINAPI WaitForMultipleObjects(DWORD nCount,CONST HANDLE *lpHandles,WINBOOL bWaitAll,DWORD dwMilliseconds); - WINBASEAPI VOID WINAPI Sleep(DWORD dwMilliseconds); - WINBASEAPI HGLOBAL WINAPI LoadResource(HMODULE hModule,HRSRC hResInfo); - WINBASEAPI DWORD WINAPI SizeofResource(HMODULE hModule,HRSRC hResInfo); - WINBASEAPI ATOM WINAPI GlobalDeleteAtom(ATOM nAtom); - WINBASEAPI WINBOOL WINAPI InitAtomTable(DWORD nSize); - WINBASEAPI ATOM WINAPI DeleteAtom(ATOM nAtom); - WINBASEAPI UINT WINAPI SetHandleCount(UINT uNumber); - WINBASEAPI DWORD WINAPI GetLogicalDrives(VOID); - WINBASEAPI WINBOOL WINAPI LockFile(HANDLE hFile,DWORD dwFileOffsetLow,DWORD dwFileOffsetHigh,DWORD nNumberOfBytesToLockLow,DWORD nNumberOfBytesToLockHigh); - WINBASEAPI WINBOOL WINAPI UnlockFile(HANDLE hFile,DWORD dwFileOffsetLow,DWORD dwFileOffsetHigh,DWORD nNumberOfBytesToUnlockLow,DWORD nNumberOfBytesToUnlockHigh); - WINBASEAPI WINBOOL WINAPI LockFileEx(HANDLE hFile,DWORD dwFlags,DWORD dwReserved,DWORD nNumberOfBytesToLockLow,DWORD nNumberOfBytesToLockHigh,LPOVERLAPPED lpOverlapped); - -#define LOCKFILE_FAIL_IMMEDIATELY 0x1 -#define LOCKFILE_EXCLUSIVE_LOCK 0x2 - - WINBASEAPI WINBOOL WINAPI UnlockFileEx(HANDLE hFile,DWORD dwReserved,DWORD nNumberOfBytesToUnlockLow,DWORD nNumberOfBytesToUnlockHigh,LPOVERLAPPED lpOverlapped); - - typedef struct _BY_HANDLE_FILE_INFORMATION { - DWORD dwFileAttributes; - FILETIME ftCreationTime; - FILETIME ftLastAccessTime; - FILETIME ftLastWriteTime; - DWORD dwVolumeSerialNumber; - DWORD nFileSizeHigh; - DWORD nFileSizeLow; - DWORD nNumberOfLinks; - DWORD nFileIndexHigh; - DWORD nFileIndexLow; - } BY_HANDLE_FILE_INFORMATION,*PBY_HANDLE_FILE_INFORMATION,*LPBY_HANDLE_FILE_INFORMATION; - -#ifdef UNICODE -#define SetFileShortName SetFileShortNameW -#else -#define SetFileShortName SetFileShortNameA -#endif - - WINBASEAPI WINBOOL WINAPI GetFileInformationByHandle(HANDLE hFile,LPBY_HANDLE_FILE_INFORMATION lpFileInformation); - WINBASEAPI DWORD WINAPI GetFileType(HANDLE hFile); - WINBASEAPI DWORD WINAPI GetFileSize(HANDLE hFile,LPDWORD lpFileSizeHigh); - WINBASEAPI WINBOOL WINAPI GetFileSizeEx(HANDLE hFile,PLARGE_INTEGER lpFileSize); - WINBASEAPI HANDLE WINAPI GetStdHandle(DWORD nStdHandle); - WINBASEAPI WINBOOL WINAPI SetStdHandle(DWORD nStdHandle,HANDLE hHandle); - WINBASEAPI WINBOOL WINAPI WriteFile(HANDLE hFile,LPCVOID lpBuffer,DWORD nNumberOfBytesToWrite,LPDWORD lpNumberOfBytesWritten,LPOVERLAPPED lpOverlapped); - WINBASEAPI WINBOOL WINAPI ReadFile(HANDLE hFile,LPVOID lpBuffer,DWORD nNumberOfBytesToRead,LPDWORD lpNumberOfBytesRead,LPOVERLAPPED lpOverlapped); - WINBASEAPI WINBOOL WINAPI FlushFileBuffers(HANDLE hFile); - WINBASEAPI WINBOOL WINAPI DeviceIoControl(HANDLE hDevice,DWORD dwIoControlCode,LPVOID lpInBuffer,DWORD nInBufferSize,LPVOID lpOutBuffer,DWORD nOutBufferSize,LPDWORD lpBytesReturned,LPOVERLAPPED lpOverlapped); - WINBASEAPI WINBOOL WINAPI RequestDeviceWakeup(HANDLE hDevice); - WINBASEAPI WINBOOL WINAPI CancelDeviceWakeupRequest(HANDLE hDevice); - WINBASEAPI WINBOOL WINAPI GetDevicePowerState(HANDLE hDevice,WINBOOL *pfOn); - WINBASEAPI WINBOOL WINAPI SetMessageWaitingIndicator(HANDLE hMsgIndicator,ULONG ulMsgCount); - WINBASEAPI WINBOOL WINAPI SetEndOfFile(HANDLE hFile); - WINBASEAPI DWORD WINAPI SetFilePointer(HANDLE hFile,LONG lDistanceToMove,PLONG lpDistanceToMoveHigh,DWORD dwMoveMethod); - WINBASEAPI WINBOOL WINAPI SetFilePointerEx(HANDLE hFile,LARGE_INTEGER liDistanceToMove,PLARGE_INTEGER lpNewFilePointer,DWORD dwMoveMethod); - WINBASEAPI WINBOOL WINAPI FindClose(HANDLE hFindFile); - WINBASEAPI WINBOOL WINAPI GetFileTime(HANDLE hFile,LPFILETIME lpCreationTime,LPFILETIME lpLastAccessTime,LPFILETIME lpLastWriteTime); - WINBASEAPI WINBOOL WINAPI SetFileTime(HANDLE hFile,CONST FILETIME *lpCreationTime,CONST FILETIME *lpLastAccessTime,CONST FILETIME *lpLastWriteTime); - WINBASEAPI WINBOOL WINAPI SetFileValidData(HANDLE hFile,LONGLONG ValidDataLength); - WINBASEAPI WINBOOL WINAPI SetFileShortNameA(HANDLE hFile,LPCSTR lpShortName); - WINBASEAPI WINBOOL WINAPI SetFileShortNameW(HANDLE hFile,LPCWSTR lpShortName); - WINBASEAPI WINBOOL WINAPI CloseHandle(HANDLE hObject); - WINBASEAPI WINBOOL WINAPI DuplicateHandle(HANDLE hSourceProcessHandle,HANDLE hSourceHandle,HANDLE hTargetProcessHandle,LPHANDLE lpTargetHandle,DWORD dwDesiredAccess,WINBOOL bInheritHandle,DWORD dwOptions); - WINBASEAPI WINBOOL WINAPI GetHandleInformation(HANDLE hObject,LPDWORD lpdwFlags); - WINBASEAPI WINBOOL WINAPI SetHandleInformation(HANDLE hObject,DWORD dwMask,DWORD dwFlags); - -#define HANDLE_FLAG_INHERIT 0x1 -#define HANDLE_FLAG_PROTECT_FROM_CLOSE 0x2 - -#define HINSTANCE_ERROR 32 - - WINBASEAPI DWORD WINAPI LoadModule(LPCSTR lpModuleName,LPVOID lpParameterBlock); - WINBASEAPI UINT WINAPI WinExec(LPCSTR lpCmdLine,UINT uCmdShow); - WINBASEAPI WINBOOL WINAPI ClearCommBreak(HANDLE hFile); - WINBASEAPI WINBOOL WINAPI ClearCommError(HANDLE hFile,LPDWORD lpErrors,LPCOMSTAT lpStat); - WINBASEAPI WINBOOL WINAPI SetupComm(HANDLE hFile,DWORD dwInQueue,DWORD dwOutQueue); - WINBASEAPI WINBOOL WINAPI EscapeCommFunction(HANDLE hFile,DWORD dwFunc); - WINBASEAPI WINBOOL WINAPI GetCommConfig(HANDLE hCommDev,LPCOMMCONFIG lpCC,LPDWORD lpdwSize); - WINBASEAPI WINBOOL WINAPI GetCommMask(HANDLE hFile,LPDWORD lpEvtMask); - WINBASEAPI WINBOOL WINAPI GetCommProperties(HANDLE hFile,LPCOMMPROP lpCommProp); - WINBASEAPI WINBOOL WINAPI GetCommModemStatus(HANDLE hFile,LPDWORD lpModemStat); - WINBASEAPI WINBOOL WINAPI GetCommState(HANDLE hFile,LPDCB lpDCB); - WINBASEAPI WINBOOL WINAPI GetCommTimeouts(HANDLE hFile,LPCOMMTIMEOUTS lpCommTimeouts); - WINBASEAPI WINBOOL WINAPI PurgeComm(HANDLE hFile,DWORD dwFlags); - WINBASEAPI WINBOOL WINAPI SetCommBreak(HANDLE hFile); - WINBASEAPI WINBOOL WINAPI SetCommConfig(HANDLE hCommDev,LPCOMMCONFIG lpCC,DWORD dwSize); - WINBASEAPI WINBOOL WINAPI SetCommMask(HANDLE hFile,DWORD dwEvtMask); - WINBASEAPI WINBOOL WINAPI SetCommState(HANDLE hFile,LPDCB lpDCB); - WINBASEAPI WINBOOL WINAPI SetCommTimeouts(HANDLE hFile,LPCOMMTIMEOUTS lpCommTimeouts); - WINBASEAPI WINBOOL WINAPI TransmitCommChar(HANDLE hFile,char cChar); - WINBASEAPI WINBOOL WINAPI WaitCommEvent(HANDLE hFile,LPDWORD lpEvtMask,LPOVERLAPPED lpOverlapped); - WINBASEAPI DWORD WINAPI SetTapePosition(HANDLE hDevice,DWORD dwPositionMethod,DWORD dwPartition,DWORD dwOffsetLow,DWORD dwOffsetHigh,WINBOOL bImmediate); - WINBASEAPI DWORD WINAPI GetTapePosition(HANDLE hDevice,DWORD dwPositionType,LPDWORD lpdwPartition,LPDWORD lpdwOffsetLow,LPDWORD lpdwOffsetHigh); - WINBASEAPI DWORD WINAPI PrepareTape(HANDLE hDevice,DWORD dwOperation,WINBOOL bImmediate); - WINBASEAPI DWORD WINAPI EraseTape(HANDLE hDevice,DWORD dwEraseType,WINBOOL bImmediate); - WINBASEAPI DWORD WINAPI CreateTapePartition(HANDLE hDevice,DWORD dwPartitionMethod,DWORD dwCount,DWORD dwSize); - WINBASEAPI DWORD WINAPI WriteTapemark(HANDLE hDevice,DWORD dwTapemarkType,DWORD dwTapemarkCount,WINBOOL bImmediate); - WINBASEAPI DWORD WINAPI GetTapeStatus(HANDLE hDevice); - WINBASEAPI DWORD WINAPI GetTapeParameters(HANDLE hDevice,DWORD dwOperation,LPDWORD lpdwSize,LPVOID lpTapeInformation); - -#define GET_TAPE_MEDIA_INFORMATION 0 -#define GET_TAPE_DRIVE_INFORMATION 1 - - WINBASEAPI DWORD WINAPI SetTapeParameters(HANDLE hDevice,DWORD dwOperation,LPVOID lpTapeInformation); - -#define SET_TAPE_MEDIA_INFORMATION 0 -#define SET_TAPE_DRIVE_INFORMATION 1 - - WINBASEAPI WINBOOL WINAPI Beep(DWORD dwFreq,DWORD dwDuration); - WINBASEAPI int WINAPI MulDiv(int nNumber,int nNumerator,int nDenominator); - WINBASEAPI VOID WINAPI GetSystemTime(LPSYSTEMTIME lpSystemTime); - WINBASEAPI VOID WINAPI GetSystemTimeAsFileTime(LPFILETIME lpSystemTimeAsFileTime); - WINBASEAPI WINBOOL WINAPI SetSystemTime(CONST SYSTEMTIME *lpSystemTime); - WINBASEAPI VOID WINAPI GetLocalTime(LPSYSTEMTIME lpSystemTime); - WINBASEAPI WINBOOL WINAPI SetLocalTime(CONST SYSTEMTIME *lpSystemTime); - WINBASEAPI VOID WINAPI GetSystemInfo(LPSYSTEM_INFO lpSystemInfo); - WINBASEAPI WINBOOL WINAPI SetSystemFileCacheSize(SIZE_T MinimumFileCacheSize,SIZE_T MaximumFileCacheSize,DWORD Flags); - WINBASEAPI WINBOOL WINAPI GetSystemFileCacheSize(PSIZE_T lpMinimumFileCacheSize,PSIZE_T lpMaximumFileCacheSize,PDWORD lpFlags); - WINBASEAPI WINBOOL WINAPI GetSystemRegistryQuota(PDWORD pdwQuotaAllowed,PDWORD pdwQuotaUsed); - WINBOOL WINAPI GetSystemTimes(LPFILETIME lpIdleTime,LPFILETIME lpKernelTime,LPFILETIME lpUserTime); - WINBASEAPI VOID WINAPI GetNativeSystemInfo(LPSYSTEM_INFO lpSystemInfo); - WINBASEAPI WINBOOL WINAPI IsProcessorFeaturePresent(DWORD ProcessorFeature); - - typedef struct _TIME_ZONE_INFORMATION { - LONG Bias; - WCHAR StandardName[32]; - SYSTEMTIME StandardDate; - LONG StandardBias; - WCHAR DaylightName[32]; - SYSTEMTIME DaylightDate; - LONG DaylightBias; - } TIME_ZONE_INFORMATION,*PTIME_ZONE_INFORMATION,*LPTIME_ZONE_INFORMATION; - -#ifdef UNICODE -#define FormatMessage FormatMessageW -#else -#define FormatMessage FormatMessageA -#endif - - WINBASEAPI WINBOOL WINAPI SystemTimeToTzSpecificLocalTime(LPTIME_ZONE_INFORMATION lpTimeZoneInformation,LPSYSTEMTIME lpUniversalTime,LPSYSTEMTIME lpLocalTime); - WINBASEAPI WINBOOL WINAPI TzSpecificLocalTimeToSystemTime(LPTIME_ZONE_INFORMATION lpTimeZoneInformation,LPSYSTEMTIME lpLocalTime,LPSYSTEMTIME lpUniversalTime); - WINBASEAPI DWORD WINAPI GetTimeZoneInformation(LPTIME_ZONE_INFORMATION lpTimeZoneInformation); - WINBASEAPI WINBOOL WINAPI SetTimeZoneInformation(CONST TIME_ZONE_INFORMATION *lpTimeZoneInformation); - WINBASEAPI WINBOOL WINAPI SystemTimeToFileTime(CONST SYSTEMTIME *lpSystemTime,LPFILETIME lpFileTime); - WINBASEAPI WINBOOL WINAPI FileTimeToLocalFileTime(CONST FILETIME *lpFileTime,LPFILETIME lpLocalFileTime); - WINBASEAPI WINBOOL WINAPI LocalFileTimeToFileTime(CONST FILETIME *lpLocalFileTime,LPFILETIME lpFileTime); - WINBASEAPI WINBOOL WINAPI FileTimeToSystemTime(CONST FILETIME *lpFileTime,LPSYSTEMTIME lpSystemTime); - WINBASEAPI LONG WINAPI CompareFileTime(CONST FILETIME *lpFileTime1,CONST FILETIME *lpFileTime2); - WINBASEAPI WINBOOL WINAPI FileTimeToDosDateTime(CONST FILETIME *lpFileTime,LPWORD lpFatDate,LPWORD lpFatTime); - WINBASEAPI WINBOOL WINAPI DosDateTimeToFileTime(WORD wFatDate,WORD wFatTime,LPFILETIME lpFileTime); - WINBASEAPI DWORD WINAPI GetTickCount(VOID); - WINBASEAPI WINBOOL WINAPI SetSystemTimeAdjustment(DWORD dwTimeAdjustment,WINBOOL bTimeAdjustmentDisabled); - WINBASEAPI WINBOOL WINAPI GetSystemTimeAdjustment(PDWORD lpTimeAdjustment,PDWORD lpTimeIncrement,PBOOL lpTimeAdjustmentDisabled); - WINBASEAPI DWORD WINAPI FormatMessageA(DWORD dwFlags,LPCVOID lpSource,DWORD dwMessageId,DWORD dwLanguageId,LPSTR lpBuffer,DWORD nSize,va_list *Arguments); - WINBASEAPI DWORD WINAPI FormatMessageW(DWORD dwFlags,LPCVOID lpSource,DWORD dwMessageId,DWORD dwLanguageId,LPWSTR lpBuffer,DWORD nSize,va_list *Arguments); - -#define FORMAT_MESSAGE_ALLOCATE_BUFFER 0x100 -#define FORMAT_MESSAGE_IGNORE_INSERTS 0x200 -#define FORMAT_MESSAGE_FROM_STRING 0x400 -#define FORMAT_MESSAGE_FROM_HMODULE 0x800 -#define FORMAT_MESSAGE_FROM_SYSTEM 0x1000 -#define FORMAT_MESSAGE_ARGUMENT_ARRAY 0x2000 -#define FORMAT_MESSAGE_MAX_WIDTH_MASK 0xff - -#ifdef UNICODE -#define CreateMailslot CreateMailslotW -#define EncryptFile EncryptFileW -#define DecryptFile DecryptFileW -#define FileEncryptionStatus FileEncryptionStatusW -#else -#define CreateMailslot CreateMailslotA -#define EncryptFile EncryptFileA -#define DecryptFile DecryptFileA -#define FileEncryptionStatus FileEncryptionStatusA -#endif - - WINBASEAPI WINBOOL WINAPI CreatePipe(PHANDLE hReadPipe,PHANDLE hWritePipe,LPSECURITY_ATTRIBUTES lpPipeAttributes,DWORD nSize); - WINBASEAPI WINBOOL WINAPI ConnectNamedPipe(HANDLE hNamedPipe,LPOVERLAPPED lpOverlapped); - WINBASEAPI WINBOOL WINAPI DisconnectNamedPipe(HANDLE hNamedPipe); - WINBASEAPI WINBOOL WINAPI SetNamedPipeHandleState(HANDLE hNamedPipe,LPDWORD lpMode,LPDWORD lpMaxCollectionCount,LPDWORD lpCollectDataTimeout); - WINBASEAPI WINBOOL WINAPI GetNamedPipeInfo(HANDLE hNamedPipe,LPDWORD lpFlags,LPDWORD lpOutBufferSize,LPDWORD lpInBufferSize,LPDWORD lpMaxInstances); - WINBASEAPI WINBOOL WINAPI PeekNamedPipe(HANDLE hNamedPipe,LPVOID lpBuffer,DWORD nBufferSize,LPDWORD lpBytesRead,LPDWORD lpTotalBytesAvail,LPDWORD lpBytesLeftThisMessage); - WINBASEAPI WINBOOL WINAPI TransactNamedPipe(HANDLE hNamedPipe,LPVOID lpInBuffer,DWORD nInBufferSize,LPVOID lpOutBuffer,DWORD nOutBufferSize,LPDWORD lpBytesRead,LPOVERLAPPED lpOverlapped); - WINBASEAPI HANDLE WINAPI CreateMailslotA(LPCSTR lpName,DWORD nMaxMessageSize,DWORD lReadTimeout,LPSECURITY_ATTRIBUTES lpSecurityAttributes); - WINBASEAPI HANDLE WINAPI CreateMailslotW(LPCWSTR lpName,DWORD nMaxMessageSize,DWORD lReadTimeout,LPSECURITY_ATTRIBUTES lpSecurityAttributes); - WINBASEAPI WINBOOL WINAPI GetMailslotInfo(HANDLE hMailslot,LPDWORD lpMaxMessageSize,LPDWORD lpNextSize,LPDWORD lpMessageCount,LPDWORD lpReadTimeout); - WINBASEAPI WINBOOL WINAPI SetMailslotInfo(HANDLE hMailslot,DWORD lReadTimeout); - WINBASEAPI LPVOID WINAPI MapViewOfFile(HANDLE hFileMappingObject,DWORD dwDesiredAccess,DWORD dwFileOffsetHigh,DWORD dwFileOffsetLow,SIZE_T dwNumberOfBytesToMap); - WINBASEAPI WINBOOL WINAPI FlushViewOfFile(LPCVOID lpBaseAddress,SIZE_T dwNumberOfBytesToFlush); - WINBASEAPI WINBOOL WINAPI UnmapViewOfFile(LPCVOID lpBaseAddress); - WINADVAPI WINBOOL WINAPI EncryptFileA(LPCSTR lpFileName); - WINADVAPI WINBOOL WINAPI EncryptFileW(LPCWSTR lpFileName); - WINADVAPI WINBOOL WINAPI DecryptFileA(LPCSTR lpFileName,DWORD dwReserved); - WINADVAPI WINBOOL WINAPI DecryptFileW(LPCWSTR lpFileName,DWORD dwReserved); - -#define FILE_ENCRYPTABLE 0 -#define FILE_IS_ENCRYPTED 1 -#define FILE_SYSTEM_ATTR 2 -#define FILE_ROOT_DIR 3 -#define FILE_SYSTEM_DIR 4 -#define FILE_UNKNOWN 5 -#define FILE_SYSTEM_NOT_SUPPORT 6 -#define FILE_USER_DISALLOWED 7 -#define FILE_READ_ONLY 8 -#define FILE_DIR_DISALLOWED 9 - - WINADVAPI WINBOOL WINAPI FileEncryptionStatusA(LPCSTR lpFileName,LPDWORD lpStatus); - WINADVAPI WINBOOL WINAPI FileEncryptionStatusW(LPCWSTR lpFileName,LPDWORD lpStatus); - -#define EFS_USE_RECOVERY_KEYS (0x1) - - typedef DWORD (WINAPI *PFE_EXPORT_FUNC)(PBYTE pbData,PVOID pvCallbackContext,ULONG ulLength); - typedef DWORD (WINAPI *PFE_IMPORT_FUNC)(PBYTE pbData,PVOID pvCallbackContext,PULONG ulLength); - -#define CREATE_FOR_IMPORT (1) -#define CREATE_FOR_DIR (2) -#define OVERWRITE_HIDDEN (4) - -#ifdef UNICODE -#define OpenEncryptedFileRaw OpenEncryptedFileRawW -#define lstrcmp lstrcmpW -#define lstrcmpi lstrcmpiW -#define lstrcpyn lstrcpynW -#define lstrcpy lstrcpyW -#define lstrcat lstrcatW -#define lstrlen lstrlenW -#else -#define OpenEncryptedFileRaw OpenEncryptedFileRawA -#define lstrcmp lstrcmpA -#define lstrcmpi lstrcmpiA -#define lstrcpyn lstrcpynA -#define lstrcpy lstrcpyA -#define lstrcat lstrcatA -#define lstrlen lstrlenA -#endif - - WINADVAPI DWORD WINAPI OpenEncryptedFileRawA(LPCSTR lpFileName,ULONG ulFlags,PVOID *pvContext); - WINADVAPI DWORD WINAPI OpenEncryptedFileRawW(LPCWSTR lpFileName,ULONG ulFlags,PVOID *pvContext); - WINADVAPI DWORD WINAPI ReadEncryptedFileRaw(PFE_EXPORT_FUNC pfExportCallback,PVOID pvCallbackContext,PVOID pvContext); - WINADVAPI DWORD WINAPI WriteEncryptedFileRaw(PFE_IMPORT_FUNC pfImportCallback,PVOID pvCallbackContext,PVOID pvContext); - WINADVAPI VOID WINAPI CloseEncryptedFileRaw(PVOID pvContext); - WINBASEAPI int WINAPI lstrcmpA(LPCSTR lpString1,LPCSTR lpString2); - WINBASEAPI int WINAPI lstrcmpW(LPCWSTR lpString1,LPCWSTR lpString2); - WINBASEAPI int WINAPI lstrcmpiA(LPCSTR lpString1,LPCSTR lpString2); - WINBASEAPI int WINAPI lstrcmpiW(LPCWSTR lpString1,LPCWSTR lpString2); - WINBASEAPI LPSTR WINAPI lstrcpynA(LPSTR lpString1,LPCSTR lpString2,int iMaxLength); - WINBASEAPI LPWSTR WINAPI lstrcpynW(LPWSTR lpString1,LPCWSTR lpString2,int iMaxLength); - WINBASEAPI LPSTR WINAPI lstrcpyA(LPSTR lpString1,LPCSTR lpString2); - WINBASEAPI LPWSTR WINAPI lstrcpyW(LPWSTR lpString1,LPCWSTR lpString2); - WINBASEAPI LPSTR WINAPI lstrcatA(LPSTR lpString1,LPCSTR lpString2); - WINBASEAPI LPWSTR WINAPI lstrcatW(LPWSTR lpString1,LPCWSTR lpString2); - WINBASEAPI int WINAPI lstrlenA(LPCSTR lpString); - WINBASEAPI int WINAPI lstrlenW(LPCWSTR lpString); - WINBASEAPI HFILE WINAPI OpenFile(LPCSTR lpFileName,LPOFSTRUCT lpReOpenBuff,UINT uStyle); - WINBASEAPI HFILE WINAPI _lopen(LPCSTR lpPathName,int iReadWrite); - WINBASEAPI HFILE WINAPI _lcreat(LPCSTR lpPathName,int iAttribute); - WINBASEAPI UINT WINAPI _lread(HFILE hFile,LPVOID lpBuffer,UINT uBytes); - WINBASEAPI UINT WINAPI _lwrite(HFILE hFile,LPCCH lpBuffer,UINT uBytes); - WINBASEAPI long WINAPI _hread(HFILE hFile,LPVOID lpBuffer,long lBytes); - WINBASEAPI long WINAPI _hwrite(HFILE hFile,LPCCH lpBuffer,long lBytes); - WINBASEAPI HFILE WINAPI _lclose(HFILE hFile); - WINBASEAPI LONG WINAPI _llseek(HFILE hFile,LONG lOffset,int iOrigin); - WINADVAPI WINBOOL WINAPI IsTextUnicode(CONST VOID *lpv,int iSize,LPINT lpiResult); - -#define FLS_OUT_OF_INDEXES ((DWORD)0xffffffff) - - WINBASEAPI DWORD WINAPI FlsAlloc(PFLS_CALLBACK_FUNCTION lpCallback); - WINBASEAPI PVOID WINAPI FlsGetValue(DWORD dwFlsIndex); - WINBASEAPI WINBOOL WINAPI FlsSetValue(DWORD dwFlsIndex,PVOID lpFlsData); - WINBASEAPI WINBOOL WINAPI FlsFree(DWORD dwFlsIndex); - -#define TLS_OUT_OF_INDEXES ((DWORD)0xffffffff) - - WINBASEAPI DWORD WINAPI TlsAlloc(VOID); - WINBASEAPI LPVOID WINAPI TlsGetValue(DWORD dwTlsIndex); - WINBASEAPI WINBOOL WINAPI TlsSetValue(DWORD dwTlsIndex,LPVOID lpTlsValue); - WINBASEAPI WINBOOL WINAPI TlsFree(DWORD dwTlsIndex); - - typedef VOID (WINAPI *LPOVERLAPPED_COMPLETION_ROUTINE)(DWORD dwErrorCode,DWORD dwNumberOfBytesTransfered,LPOVERLAPPED lpOverlapped); - - WINBASEAPI DWORD WINAPI SleepEx(DWORD dwMilliseconds,WINBOOL bAlertable); - WINBASEAPI DWORD WINAPI WaitForSingleObjectEx(HANDLE hHandle,DWORD dwMilliseconds,WINBOOL bAlertable); - WINBASEAPI DWORD WINAPI WaitForMultipleObjectsEx(DWORD nCount,CONST HANDLE *lpHandles,WINBOOL bWaitAll,DWORD dwMilliseconds,WINBOOL bAlertable); - WINBASEAPI DWORD WINAPI SignalObjectAndWait(HANDLE hObjectToSignal,HANDLE hObjectToWaitOn,DWORD dwMilliseconds,WINBOOL bAlertable); - WINBASEAPI WINBOOL WINAPI ReadFileEx(HANDLE hFile,LPVOID lpBuffer,DWORD nNumberOfBytesToRead,LPOVERLAPPED lpOverlapped,LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine); - WINBASEAPI WINBOOL WINAPI WriteFileEx(HANDLE hFile,LPCVOID lpBuffer,DWORD nNumberOfBytesToWrite,LPOVERLAPPED lpOverlapped,LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine); - WINBASEAPI WINBOOL WINAPI BackupRead(HANDLE hFile,LPBYTE lpBuffer,DWORD nNumberOfBytesToRead,LPDWORD lpNumberOfBytesRead,WINBOOL bAbort,WINBOOL bProcessSecurity,LPVOID *lpContext); - WINBASEAPI WINBOOL WINAPI BackupSeek(HANDLE hFile,DWORD dwLowBytesToSeek,DWORD dwHighBytesToSeek,LPDWORD lpdwLowByteSeeked,LPDWORD lpdwHighByteSeeked,LPVOID *lpContext); - WINBASEAPI WINBOOL WINAPI BackupWrite(HANDLE hFile,LPBYTE lpBuffer,DWORD nNumberOfBytesToWrite,LPDWORD lpNumberOfBytesWritten,WINBOOL bAbort,WINBOOL bProcessSecurity,LPVOID *lpContext); - - typedef struct _WIN32_STREAM_ID { - DWORD dwStreamId; - DWORD dwStreamAttributes; - LARGE_INTEGER Size; - DWORD dwStreamNameSize; - WCHAR cStreamName[ANYSIZE_ARRAY]; - } WIN32_STREAM_ID,*LPWIN32_STREAM_ID; - -#define BACKUP_INVALID 0x0 -#define BACKUP_DATA 0x1 -#define BACKUP_EA_DATA 0x2 -#define BACKUP_SECURITY_DATA 0x3 -#define BACKUP_ALTERNATE_DATA 0x4 -#define BACKUP_LINK 0x5 -#define BACKUP_PROPERTY_DATA 0x6 -#define BACKUP_OBJECT_ID 0x7 -#define BACKUP_REPARSE_DATA 0x8 -#define BACKUP_SPARSE_BLOCK 0x9 - -#define STREAM_NORMAL_ATTRIBUTE 0x0 -#define STREAM_MODIFIED_WHEN_READ 0x1 -#define STREAM_CONTAINS_SECURITY 0x2 -#define STREAM_CONTAINS_PROPERTIES 0x4 -#define STREAM_SPARSE_ATTRIBUTE 0x8 - - WINBASEAPI WINBOOL WINAPI ReadFileScatter(HANDLE hFile,FILE_SEGMENT_ELEMENT aSegmentArray[],DWORD nNumberOfBytesToRead,LPDWORD lpReserved,LPOVERLAPPED lpOverlapped); - WINBASEAPI WINBOOL WINAPI WriteFileGather(HANDLE hFile,FILE_SEGMENT_ELEMENT aSegmentArray[],DWORD nNumberOfBytesToWrite,LPDWORD lpReserved,LPOVERLAPPED lpOverlapped); - -#define STARTF_USESHOWWINDOW 0x1 -#define STARTF_USESIZE 0x2 -#define STARTF_USEPOSITION 0x4 -#define STARTF_USECOUNTCHARS 0x8 -#define STARTF_USEFILLATTRIBUTE 0x10 -#define STARTF_RUNFULLSCREEN 0x20 -#define STARTF_FORCEONFEEDBACK 0x40 -#define STARTF_FORCEOFFFEEDBACK 0x80 -#define STARTF_USESTDHANDLES 0x100 - -#define STARTF_USEHOTKEY 0x200 - - typedef struct _STARTUPINFOA { - DWORD cb; - LPSTR lpReserved; - LPSTR lpDesktop; - LPSTR lpTitle; - DWORD dwX; - DWORD dwY; - DWORD dwXSize; - DWORD dwYSize; - DWORD dwXCountChars; - DWORD dwYCountChars; - DWORD dwFillAttribute; - DWORD dwFlags; - WORD wShowWindow; - WORD cbReserved2; - LPBYTE lpReserved2; - HANDLE hStdInput; - HANDLE hStdOutput; - HANDLE hStdError; - } STARTUPINFOA,*LPSTARTUPINFOA; - - typedef struct _STARTUPINFOW { - DWORD cb; - LPWSTR lpReserved; - LPWSTR lpDesktop; - LPWSTR lpTitle; - DWORD dwX; - DWORD dwY; - DWORD dwXSize; - DWORD dwYSize; - DWORD dwXCountChars; - DWORD dwYCountChars; - DWORD dwFillAttribute; - DWORD dwFlags; - WORD wShowWindow; - WORD cbReserved2; - LPBYTE lpReserved2; - HANDLE hStdInput; - HANDLE hStdOutput; - HANDLE hStdError; - } STARTUPINFOW,*LPSTARTUPINFOW; - -#ifdef UNICODE - typedef STARTUPINFOW STARTUPINFO; - typedef LPSTARTUPINFOW LPSTARTUPINFO; -#else - typedef STARTUPINFOA STARTUPINFO; - typedef LPSTARTUPINFOA LPSTARTUPINFO; -#endif - -#define SHUTDOWN_NORETRY 0x1 - - typedef struct _WIN32_FIND_DATAA { - DWORD dwFileAttributes; - FILETIME ftCreationTime; - FILETIME ftLastAccessTime; - FILETIME ftLastWriteTime; - DWORD nFileSizeHigh; - DWORD nFileSizeLow; - DWORD dwReserved0; - DWORD dwReserved1; - CHAR cFileName[MAX_PATH]; - CHAR cAlternateFileName[14]; - } WIN32_FIND_DATAA,*PWIN32_FIND_DATAA,*LPWIN32_FIND_DATAA; - - typedef struct _WIN32_FIND_DATAW { - DWORD dwFileAttributes; - FILETIME ftCreationTime; - FILETIME ftLastAccessTime; - FILETIME ftLastWriteTime; - DWORD nFileSizeHigh; - DWORD nFileSizeLow; - DWORD dwReserved0; - DWORD dwReserved1; - WCHAR cFileName[MAX_PATH]; - WCHAR cAlternateFileName[14]; - } WIN32_FIND_DATAW,*PWIN32_FIND_DATAW,*LPWIN32_FIND_DATAW; - -#ifdef UNICODE - typedef WIN32_FIND_DATAW WIN32_FIND_DATA; - typedef PWIN32_FIND_DATAW PWIN32_FIND_DATA; - typedef LPWIN32_FIND_DATAW LPWIN32_FIND_DATA; -#else - typedef WIN32_FIND_DATAA WIN32_FIND_DATA; - typedef PWIN32_FIND_DATAA PWIN32_FIND_DATA; - typedef LPWIN32_FIND_DATAA LPWIN32_FIND_DATA; -#endif - - typedef struct _WIN32_FILE_ATTRIBUTE_DATA { - DWORD dwFileAttributes; - FILETIME ftCreationTime; - FILETIME ftLastAccessTime; - FILETIME ftLastWriteTime; - DWORD nFileSizeHigh; - DWORD nFileSizeLow; - } WIN32_FILE_ATTRIBUTE_DATA,*LPWIN32_FILE_ATTRIBUTE_DATA; - -#ifdef UNICODE -#define CreateMutex CreateMutexW -#define OpenMutex OpenMutexW -#define CreateEvent CreateEventW -#define OpenEvent OpenEventW -#define CreateSemaphore CreateSemaphoreW -#define OpenSemaphore OpenSemaphoreW -#else -#define CreateMutex CreateMutexA -#define OpenMutex OpenMutexA -#define CreateEvent CreateEventA -#define OpenEvent OpenEventA -#define CreateSemaphore CreateSemaphoreA -#define OpenSemaphore OpenSemaphoreA -#endif - - WINBASEAPI HANDLE WINAPI CreateMutexA(LPSECURITY_ATTRIBUTES lpMutexAttributes,WINBOOL bInitialOwner,LPCSTR lpName); - WINBASEAPI HANDLE WINAPI CreateMutexW(LPSECURITY_ATTRIBUTES lpMutexAttributes,WINBOOL bInitialOwner,LPCWSTR lpName); - WINBASEAPI HANDLE WINAPI OpenMutexA(DWORD dwDesiredAccess,WINBOOL bInheritHandle,LPCSTR lpName); - WINBASEAPI HANDLE WINAPI OpenMutexW(DWORD dwDesiredAccess,WINBOOL bInheritHandle,LPCWSTR lpName); - WINBASEAPI HANDLE WINAPI CreateEventA(LPSECURITY_ATTRIBUTES lpEventAttributes,WINBOOL bManualReset,WINBOOL bInitialState,LPCSTR lpName); - WINBASEAPI HANDLE WINAPI CreateEventW(LPSECURITY_ATTRIBUTES lpEventAttributes,WINBOOL bManualReset,WINBOOL bInitialState,LPCWSTR lpName); - WINBASEAPI HANDLE WINAPI OpenEventA(DWORD dwDesiredAccess,WINBOOL bInheritHandle,LPCSTR lpName); - WINBASEAPI HANDLE WINAPI OpenEventW(DWORD dwDesiredAccess,WINBOOL bInheritHandle,LPCWSTR lpName); - WINBASEAPI HANDLE WINAPI CreateSemaphoreA(LPSECURITY_ATTRIBUTES lpSemaphoreAttributes,LONG lInitialCount,LONG lMaximumCount,LPCSTR lpName); - WINBASEAPI HANDLE WINAPI CreateSemaphoreW(LPSECURITY_ATTRIBUTES lpSemaphoreAttributes,LONG lInitialCount,LONG lMaximumCount,LPCWSTR lpName); - WINBASEAPI HANDLE WINAPI OpenSemaphoreA(DWORD dwDesiredAccess,WINBOOL bInheritHandle,LPCSTR lpName); - WINBASEAPI HANDLE WINAPI OpenSemaphoreW(DWORD dwDesiredAccess,WINBOOL bInheritHandle,LPCWSTR lpName); - - typedef VOID (WINAPI *PTIMERAPCROUTINE)(LPVOID lpArgToCompletionRoutine,DWORD dwTimerLowValue,DWORD dwTimerHighValue); - -#ifdef UNICODE -#define CreateWaitableTimer CreateWaitableTimerW -#define OpenWaitableTimer OpenWaitableTimerW -#define CreateFileMapping CreateFileMappingW -#define OpenFileMapping OpenFileMappingW -#define GetLogicalDriveStrings GetLogicalDriveStringsW -#define LoadLibrary LoadLibraryW -#define LoadLibraryEx LoadLibraryExW -#define GetModuleFileName GetModuleFileNameW -#define GetModuleHandle GetModuleHandleW -#else -#define CreateWaitableTimer CreateWaitableTimerA -#define OpenWaitableTimer OpenWaitableTimerA -#define CreateFileMapping CreateFileMappingA -#define OpenFileMapping OpenFileMappingA -#define GetLogicalDriveStrings GetLogicalDriveStringsA -#define LoadLibrary LoadLibraryA -#define LoadLibraryEx LoadLibraryExA -#define GetModuleFileName GetModuleFileNameA -#define GetModuleHandle GetModuleHandleA -#endif - - WINBASEAPI HANDLE WINAPI CreateWaitableTimerA(LPSECURITY_ATTRIBUTES lpTimerAttributes,WINBOOL bManualReset,LPCSTR lpTimerName); - WINBASEAPI HANDLE WINAPI CreateWaitableTimerW(LPSECURITY_ATTRIBUTES lpTimerAttributes,WINBOOL bManualReset,LPCWSTR lpTimerName); - WINBASEAPI HANDLE WINAPI OpenWaitableTimerA(DWORD dwDesiredAccess,WINBOOL bInheritHandle,LPCSTR lpTimerName); - WINBASEAPI HANDLE WINAPI OpenWaitableTimerW(DWORD dwDesiredAccess,WINBOOL bInheritHandle,LPCWSTR lpTimerName); - WINBASEAPI WINBOOL WINAPI SetWaitableTimer(HANDLE hTimer,const LARGE_INTEGER *lpDueTime,LONG lPeriod,PTIMERAPCROUTINE pfnCompletionRoutine,LPVOID lpArgToCompletionRoutine,WINBOOL fResume); - WINBASEAPI WINBOOL WINAPI CancelWaitableTimer(HANDLE hTimer); - WINBASEAPI HANDLE WINAPI CreateFileMappingA(HANDLE hFile,LPSECURITY_ATTRIBUTES lpFileMappingAttributes,DWORD flProtect,DWORD dwMaximumSizeHigh,DWORD dwMaximumSizeLow,LPCSTR lpName); - WINBASEAPI HANDLE WINAPI CreateFileMappingW(HANDLE hFile,LPSECURITY_ATTRIBUTES lpFileMappingAttributes,DWORD flProtect,DWORD dwMaximumSizeHigh,DWORD dwMaximumSizeLow,LPCWSTR lpName); - WINBASEAPI HANDLE WINAPI OpenFileMappingA(DWORD dwDesiredAccess,WINBOOL bInheritHandle,LPCSTR lpName); - WINBASEAPI HANDLE WINAPI OpenFileMappingW(DWORD dwDesiredAccess,WINBOOL bInheritHandle,LPCWSTR lpName); - WINBASEAPI DWORD WINAPI GetLogicalDriveStringsA(DWORD nBufferLength,LPSTR lpBuffer); - WINBASEAPI DWORD WINAPI GetLogicalDriveStringsW(DWORD nBufferLength,LPWSTR lpBuffer); - - typedef enum _MEMORY_RESOURCE_NOTIFICATION_TYPE { - LowMemoryResourceNotification,HighMemoryResourceNotification - } MEMORY_RESOURCE_NOTIFICATION_TYPE; - - WINBASEAPI HANDLE WINAPI CreateMemoryResourceNotification(MEMORY_RESOURCE_NOTIFICATION_TYPE NotificationType); - WINBASEAPI WINBOOL WINAPI QueryMemoryResourceNotification(HANDLE ResourceNotificationHandle,PBOOL ResourceState); - WINBASEAPI HMODULE WINAPI LoadLibraryA(LPCSTR lpLibFileName); - WINBASEAPI HMODULE WINAPI LoadLibraryW(LPCWSTR lpLibFileName); - WINBASEAPI HMODULE WINAPI LoadLibraryExA(LPCSTR lpLibFileName,HANDLE hFile,DWORD dwFlags); - WINBASEAPI HMODULE WINAPI LoadLibraryExW(LPCWSTR lpLibFileName,HANDLE hFile,DWORD dwFlags); - -#define DONT_RESOLVE_DLL_REFERENCES 0x1 -#define LOAD_LIBRARY_AS_DATAFILE 0x2 -#define LOAD_WITH_ALTERED_SEARCH_PATH 0x8 -#define LOAD_IGNORE_CODE_AUTHZ_LEVEL 0x10 -#define LOAD_LINRARY_AS_IMAGE_RESOURCE 0x20 -#define LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE 0x40 - - WINBASEAPI DWORD WINAPI GetModuleFileNameA(HMODULE hModule,LPCH lpFilename,DWORD nSize); - WINBASEAPI DWORD WINAPI GetModuleFileNameW(HMODULE hModule,LPWCH lpFilename,DWORD nSize); - WINBASEAPI HMODULE WINAPI GetModuleHandleA(LPCSTR lpModuleName); - WINBASEAPI HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName); - -#ifndef RC_INVOKED -#define GET_MODULE_HANDLE_EX_FLAG_PIN (0x1) -#define GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT (0x2) -#define GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS (0x4) - - typedef WINBOOL (WINAPI *PGET_MODULE_HANDLE_EXA)(DWORD dwFlags,LPCSTR lpModuleName,HMODULE *phModule); - typedef WINBOOL (WINAPI *PGET_MODULE_HANDLE_EXW)(DWORD dwFlags,LPCWSTR lpModuleName,HMODULE *phModule); - -#ifdef UNICODE -#define PGET_MODULE_HANDLE_EX PGET_MODULE_HANDLE_EXW -#define GetModuleHandleEx GetModuleHandleExW -#else -#define PGET_MODULE_HANDLE_EX PGET_MODULE_HANDLE_EXA -#define GetModuleHandleEx GetModuleHandleExA -#endif - - WINBASEAPI WINBOOL WINAPI GetModuleHandleExA(DWORD dwFlags,LPCSTR lpModuleName,HMODULE *phModule); - WINBASEAPI WINBOOL WINAPI GetModuleHandleExW(DWORD dwFlags,LPCWSTR lpModuleName,HMODULE *phModule); -#endif - -#ifdef UNICODE -#define NeedCurrentDirectoryForExePath NeedCurrentDirectoryForExePathW -#define CreateProcess CreateProcessW -#define FatalAppExit FatalAppExitW -#define GetStartupInfo GetStartupInfoW -#define GetCommandLine GetCommandLineW -#define GetEnvironmentVariable GetEnvironmentVariableW -#define SetEnvironmentVariable SetEnvironmentVariableW -#define ExpandEnvironmentStrings ExpandEnvironmentStringsW -#define GetFirmwareEnvironmentVariable GetFirmwareEnvironmentVariableW -#define SetFirmwareEnvironmentVariable SetFirmwareEnvironmentVariableW -#define OutputDebugString OutputDebugStringW -#define FindResource FindResourceW -#define FindResourceEx FindResourceExW -#else -#define NeedCurrentDirectoryForExePath NeedCurrentDirectoryForExePathA -#define CreateProcess CreateProcessA -#define FatalAppExit FatalAppExitA -#define GetStartupInfo GetStartupInfoA -#define GetCommandLine GetCommandLineA -#define GetEnvironmentVariable GetEnvironmentVariableA -#define SetEnvironmentVariable SetEnvironmentVariableA -#define ExpandEnvironmentStrings ExpandEnvironmentStringsA -#define GetFirmwareEnvironmentVariable GetFirmwareEnvironmentVariableA -#define SetFirmwareEnvironmentVariable SetFirmwareEnvironmentVariableA -#define OutputDebugString OutputDebugStringA -#define FindResource FindResourceA -#define FindResourceEx FindResourceExA -#endif - - WINBASEAPI WINBOOL WINAPI NeedCurrentDirectoryForExePathA(LPCSTR ExeName); - WINBASEAPI WINBOOL WINAPI NeedCurrentDirectoryForExePathW(LPCWSTR ExeName); - WINBASEAPI WINBOOL WINAPI CreateProcessA(LPCSTR lpApplicationName,LPSTR lpCommandLine,LPSECURITY_ATTRIBUTES lpProcessAttributes,LPSECURITY_ATTRIBUTES lpThreadAttributes,WINBOOL bInheritHandles,DWORD dwCreationFlags,LPVOID lpEnvironment,LPCSTR lpCurrentDirectory,LPSTARTUPINFOA lpStartupInfo,LPPROCESS_INFORMATION lpProcessInformation); - WINBASEAPI WINBOOL WINAPI CreateProcessW(LPCWSTR lpApplicationName,LPWSTR lpCommandLine,LPSECURITY_ATTRIBUTES lpProcessAttributes,LPSECURITY_ATTRIBUTES lpThreadAttributes,WINBOOL bInheritHandles,DWORD dwCreationFlags,LPVOID lpEnvironment,LPCWSTR lpCurrentDirectory,LPSTARTUPINFOW lpStartupInfo,LPPROCESS_INFORMATION lpProcessInformation); - WINBASEAPI DWORD WINAPI AddLocalAlternateComputerNameA(LPCSTR lpDnsFQHostname,ULONG ulFlags); - WINBASEAPI DWORD WINAPI AddLocalAlternateComputerNameW(LPCWSTR lpDnsFQHostname,ULONG ulFlags); - WINBASEAPI WINBOOL WINAPI SetProcessShutdownParameters(DWORD dwLevel,DWORD dwFlags); - WINBASEAPI WINBOOL WINAPI GetProcessShutdownParameters(LPDWORD lpdwLevel,LPDWORD lpdwFlags); - WINBASEAPI DWORD WINAPI GetProcessVersion(DWORD ProcessId); - WINBASEAPI VOID WINAPI FatalAppExitA(UINT uAction,LPCSTR lpMessageText); - WINBASEAPI VOID WINAPI FatalAppExitW(UINT uAction,LPCWSTR lpMessageText); - WINBASEAPI VOID WINAPI GetStartupInfoA(LPSTARTUPINFOA lpStartupInfo); - WINBASEAPI VOID WINAPI GetStartupInfoW(LPSTARTUPINFOW lpStartupInfo); - WINBASEAPI LPSTR WINAPI GetCommandLineA(VOID); - WINBASEAPI LPWSTR WINAPI GetCommandLineW(VOID); - WINBASEAPI DWORD WINAPI GetEnvironmentVariableA(LPCSTR lpName,LPSTR lpBuffer,DWORD nSize); - WINBASEAPI DWORD WINAPI GetEnvironmentVariableW(LPCWSTR lpName,LPWSTR lpBuffer,DWORD nSize); - WINBASEAPI WINBOOL WINAPI SetEnvironmentVariableA(LPCSTR lpName,LPCSTR lpValue); - WINBASEAPI WINBOOL WINAPI SetEnvironmentVariableW(LPCWSTR lpName,LPCWSTR lpValue); - WINBASEAPI DWORD WINAPI ExpandEnvironmentStringsA(LPCSTR lpSrc,LPSTR lpDst,DWORD nSize); - WINBASEAPI DWORD WINAPI ExpandEnvironmentStringsW(LPCWSTR lpSrc,LPWSTR lpDst,DWORD nSize); - WINBASEAPI DWORD WINAPI GetFirmwareEnvironmentVariableA(LPCSTR lpName,LPCSTR lpGuid,PVOID pBuffer,DWORD nSize); - WINBASEAPI DWORD WINAPI GetFirmwareEnvironmentVariableW(LPCWSTR lpName,LPCWSTR lpGuid,PVOID pBuffer,DWORD nSize); - WINBASEAPI WINBOOL WINAPI SetFirmwareEnvironmentVariableA(LPCSTR lpName,LPCSTR lpGuid,PVOID pValue,DWORD nSize); - WINBASEAPI WINBOOL WINAPI SetFirmwareEnvironmentVariableW(LPCWSTR lpName,LPCWSTR lpGuid,PVOID pValue,DWORD nSize); - WINBASEAPI VOID WINAPI OutputDebugStringA(LPCSTR lpOutputString); - WINBASEAPI VOID WINAPI OutputDebugStringW(LPCWSTR lpOutputString); - WINBASEAPI HRSRC WINAPI FindResourceA(HMODULE hModule,LPCSTR lpName,LPCSTR lpType); - WINBASEAPI HRSRC WINAPI FindResourceW(HMODULE hModule,LPCWSTR lpName,LPCWSTR lpType); - WINBASEAPI HRSRC WINAPI FindResourceExA(HMODULE hModule,LPCSTR lpType,LPCSTR lpName,WORD wLanguage); - WINBASEAPI HRSRC WINAPI FindResourceExW(HMODULE hModule,LPCWSTR lpType,LPCWSTR lpName,WORD wLanguage); - -#ifdef UNICODE -#define ENUMRESTYPEPROC ENUMRESTYPEPROCW -#define ENUMRESNAMEPROC ENUMRESNAMEPROCW -#define ENUMRESLANGPROC ENUMRESLANGPROCW -#define EnumResourceTypes EnumResourceTypesW -#define EnumResourceNames EnumResourceNamesW -#define EnumResourceLanguages EnumResourceLanguagesW -#define BeginUpdateResource BeginUpdateResourceW -#define UpdateResource UpdateResourceW -#define EndUpdateResource EndUpdateResourceW -#define GlobalAddAtom GlobalAddAtomW -#define GlobalFindAtom GlobalFindAtomW -#define GlobalGetAtomName GlobalGetAtomNameW -#define AddAtom AddAtomW -#define FindAtom FindAtomW -#define GetAtomName GetAtomNameW -#define GetProfileInt GetProfileIntW -#define GetProfileString GetProfileStringW -#define WriteProfileString WriteProfileStringW -#define GetProfileSection GetProfileSectionW -#define WriteProfileSection WriteProfileSectionW -#define GetPrivateProfileInt GetPrivateProfileIntW -#define GetPrivateProfileString GetPrivateProfileStringW -#define WritePrivateProfileString WritePrivateProfileStringW -#define GetPrivateProfileSection GetPrivateProfileSectionW -#define WritePrivateProfileSection WritePrivateProfileSectionW -#define GetPrivateProfileSectionNames GetPrivateProfileSectionNamesW -#define GetPrivateProfileStruct GetPrivateProfileStructW -#define WritePrivateProfileStruct WritePrivateProfileStructW -#define GetDriveType GetDriveTypeW -#define GetSystemDirectory GetSystemDirectoryW -#define GetTempPath GetTempPathW -#define GetTempFileName GetTempFileNameW -#define GetWindowsDirectory GetWindowsDirectoryW -#define GetSystemWindowsDirectory GetSystemWindowsDirectoryW -#define AddLocalAlternateComputerName AddLocalAlternateComputerNameW -#else -#define ENUMRESTYPEPROC ENUMRESTYPEPROCA -#define ENUMRESNAMEPROC ENUMRESNAMEPROCA -#define ENUMRESLANGPROC ENUMRESLANGPROCA -#define EnumResourceTypes EnumResourceTypesA -#define EnumResourceNames EnumResourceNamesA -#define EnumResourceLanguages EnumResourceLanguagesA -#define BeginUpdateResource BeginUpdateResourceA -#define UpdateResource UpdateResourceA -#define EndUpdateResource EndUpdateResourceA -#define GlobalAddAtom GlobalAddAtomA -#define GlobalFindAtom GlobalFindAtomA -#define GlobalGetAtomName GlobalGetAtomNameA -#define AddAtom AddAtomA -#define FindAtom FindAtomA -#define GetAtomName GetAtomNameA -#define GetProfileInt GetProfileIntA -#define GetProfileString GetProfileStringA -#define WriteProfileString WriteProfileStringA -#define GetProfileSection GetProfileSectionA -#define WriteProfileSection WriteProfileSectionA -#define GetPrivateProfileInt GetPrivateProfileIntA -#define GetPrivateProfileString GetPrivateProfileStringA -#define WritePrivateProfileString WritePrivateProfileStringA -#define GetPrivateProfileSection GetPrivateProfileSectionA -#define WritePrivateProfileSection WritePrivateProfileSectionA -#define GetPrivateProfileSectionNames GetPrivateProfileSectionNamesA -#define GetPrivateProfileStruct GetPrivateProfileStructA -#define WritePrivateProfileStruct WritePrivateProfileStructA -#define GetDriveType GetDriveTypeA -#define GetSystemDirectory GetSystemDirectoryA -#define GetTempPath GetTempPathA -#define GetTempFileName GetTempFileNameA -#define GetWindowsDirectory GetWindowsDirectoryA -#define GetSystemWindowsDirectory GetSystemWindowsDirectoryA -#define AddLocalAlternateComputerName AddLocalAlternateComputerNameA -#endif - - typedef WINBOOL (CALLBACK *ENUMRESTYPEPROCA)(HMODULE hModule,LPSTR lpType,LONG_PTR lParam); - typedef WINBOOL (CALLBACK *ENUMRESTYPEPROCW)(HMODULE hModule,LPWSTR lpType,LONG_PTR lParam); - typedef WINBOOL (CALLBACK *ENUMRESNAMEPROCA)(HMODULE hModule,LPCSTR lpType,LPSTR lpName,LONG_PTR lParam); - typedef WINBOOL (CALLBACK *ENUMRESNAMEPROCW)(HMODULE hModule,LPCWSTR lpType,LPWSTR lpName,LONG_PTR lParam); - typedef WINBOOL (CALLBACK *ENUMRESLANGPROCA)(HMODULE hModule,LPCSTR lpType,LPCSTR lpName,WORD wLanguage,LONG_PTR lParam); - typedef WINBOOL (CALLBACK *ENUMRESLANGPROCW)(HMODULE hModule,LPCWSTR lpType,LPCWSTR lpName,WORD wLanguage,LONG_PTR lParam); - - WINBASEAPI WINBOOL WINAPI EnumResourceTypesA(HMODULE hModule,ENUMRESTYPEPROCA lpEnumFunc,LONG_PTR lParam); - WINBASEAPI WINBOOL WINAPI EnumResourceTypesW(HMODULE hModule,ENUMRESTYPEPROCW lpEnumFunc,LONG_PTR lParam); - WINBASEAPI WINBOOL WINAPI EnumResourceNamesA(HMODULE hModule,LPCSTR lpType,ENUMRESNAMEPROCA lpEnumFunc,LONG_PTR lParam); - WINBASEAPI WINBOOL WINAPI EnumResourceNamesW(HMODULE hModule,LPCWSTR lpType,ENUMRESNAMEPROCW lpEnumFunc,LONG_PTR lParam); - WINBASEAPI WINBOOL WINAPI EnumResourceLanguagesA(HMODULE hModule,LPCSTR lpType,LPCSTR lpName,ENUMRESLANGPROCA lpEnumFunc,LONG_PTR lParam); - WINBASEAPI WINBOOL WINAPI EnumResourceLanguagesW(HMODULE hModule,LPCWSTR lpType,LPCWSTR lpName,ENUMRESLANGPROCW lpEnumFunc,LONG_PTR lParam); - WINBASEAPI HANDLE WINAPI BeginUpdateResourceA(LPCSTR pFileName,WINBOOL bDeleteExistingResources); - WINBASEAPI HANDLE WINAPI BeginUpdateResourceW(LPCWSTR pFileName,WINBOOL bDeleteExistingResources); - WINBASEAPI WINBOOL WINAPI UpdateResourceA(HANDLE hUpdate,LPCSTR lpType,LPCSTR lpName,WORD wLanguage,LPVOID lpData,DWORD cb); - WINBASEAPI WINBOOL WINAPI UpdateResourceW(HANDLE hUpdate,LPCWSTR lpType,LPCWSTR lpName,WORD wLanguage,LPVOID lpData,DWORD cb); - WINBASEAPI WINBOOL WINAPI EndUpdateResourceA(HANDLE hUpdate,WINBOOL fDiscard); - WINBASEAPI WINBOOL WINAPI EndUpdateResourceW(HANDLE hUpdate,WINBOOL fDiscard); - WINBASEAPI ATOM WINAPI GlobalAddAtomA(LPCSTR lpString); - WINBASEAPI ATOM WINAPI GlobalAddAtomW(LPCWSTR lpString); - WINBASEAPI ATOM WINAPI GlobalFindAtomA(LPCSTR lpString); - WINBASEAPI ATOM WINAPI GlobalFindAtomW(LPCWSTR lpString); - WINBASEAPI UINT WINAPI GlobalGetAtomNameA(ATOM nAtom,LPSTR lpBuffer,int nSize); - WINBASEAPI UINT WINAPI GlobalGetAtomNameW(ATOM nAtom,LPWSTR lpBuffer,int nSize); - WINBASEAPI ATOM WINAPI AddAtomA(LPCSTR lpString); - WINBASEAPI ATOM WINAPI AddAtomW(LPCWSTR lpString); - WINBASEAPI ATOM WINAPI FindAtomA(LPCSTR lpString); - WINBASEAPI ATOM WINAPI FindAtomW(LPCWSTR lpString); - WINBASEAPI UINT WINAPI GetAtomNameA(ATOM nAtom,LPSTR lpBuffer,int nSize); - WINBASEAPI UINT WINAPI GetAtomNameW(ATOM nAtom,LPWSTR lpBuffer,int nSize); - WINBASEAPI UINT WINAPI GetProfileIntA(LPCSTR lpAppName,LPCSTR lpKeyName,INT nDefault); - WINBASEAPI UINT WINAPI GetProfileIntW(LPCWSTR lpAppName,LPCWSTR lpKeyName,INT nDefault); - WINBASEAPI DWORD WINAPI GetProfileStringA(LPCSTR lpAppName,LPCSTR lpKeyName,LPCSTR lpDefault,LPSTR lpReturnedString,DWORD nSize); - WINBASEAPI DWORD WINAPI GetProfileStringW(LPCWSTR lpAppName,LPCWSTR lpKeyName,LPCWSTR lpDefault,LPWSTR lpReturnedString,DWORD nSize); - WINBASEAPI WINBOOL WINAPI WriteProfileStringA(LPCSTR lpAppName,LPCSTR lpKeyName,LPCSTR lpString); - WINBASEAPI WINBOOL WINAPI WriteProfileStringW(LPCWSTR lpAppName,LPCWSTR lpKeyName,LPCWSTR lpString); - WINBASEAPI DWORD WINAPI GetProfileSectionA(LPCSTR lpAppName,LPSTR lpReturnedString,DWORD nSize); - WINBASEAPI DWORD WINAPI GetProfileSectionW(LPCWSTR lpAppName,LPWSTR lpReturnedString,DWORD nSize); - WINBASEAPI WINBOOL WINAPI WriteProfileSectionA(LPCSTR lpAppName,LPCSTR lpString); - WINBASEAPI WINBOOL WINAPI WriteProfileSectionW(LPCWSTR lpAppName,LPCWSTR lpString); - WINBASEAPI UINT WINAPI GetPrivateProfileIntA(LPCSTR lpAppName,LPCSTR lpKeyName,INT nDefault,LPCSTR lpFileName); - WINBASEAPI UINT WINAPI GetPrivateProfileIntW(LPCWSTR lpAppName,LPCWSTR lpKeyName,INT nDefault,LPCWSTR lpFileName); - WINBASEAPI DWORD WINAPI GetPrivateProfileStringA(LPCSTR lpAppName,LPCSTR lpKeyName,LPCSTR lpDefault,LPSTR lpReturnedString,DWORD nSize,LPCSTR lpFileName); - WINBASEAPI DWORD WINAPI GetPrivateProfileStringW(LPCWSTR lpAppName,LPCWSTR lpKeyName,LPCWSTR lpDefault,LPWSTR lpReturnedString,DWORD nSize,LPCWSTR lpFileName); - WINBASEAPI WINBOOL WINAPI WritePrivateProfileStringA(LPCSTR lpAppName,LPCSTR lpKeyName,LPCSTR lpString,LPCSTR lpFileName); - WINBASEAPI WINBOOL WINAPI WritePrivateProfileStringW(LPCWSTR lpAppName,LPCWSTR lpKeyName,LPCWSTR lpString,LPCWSTR lpFileName); - WINBASEAPI DWORD WINAPI GetPrivateProfileSectionA(LPCSTR lpAppName,LPSTR lpReturnedString,DWORD nSize,LPCSTR lpFileName); - WINBASEAPI DWORD WINAPI GetPrivateProfileSectionW(LPCWSTR lpAppName,LPWSTR lpReturnedString,DWORD nSize,LPCWSTR lpFileName); - WINBASEAPI WINBOOL WINAPI WritePrivateProfileSectionA(LPCSTR lpAppName,LPCSTR lpString,LPCSTR lpFileName); - WINBASEAPI WINBOOL WINAPI WritePrivateProfileSectionW(LPCWSTR lpAppName,LPCWSTR lpString,LPCWSTR lpFileName); - WINBASEAPI DWORD WINAPI GetPrivateProfileSectionNamesA(LPSTR lpszReturnBuffer,DWORD nSize,LPCSTR lpFileName); - WINBASEAPI DWORD WINAPI GetPrivateProfileSectionNamesW(LPWSTR lpszReturnBuffer,DWORD nSize,LPCWSTR lpFileName); - WINBASEAPI WINBOOL WINAPI GetPrivateProfileStructA(LPCSTR lpszSection,LPCSTR lpszKey,LPVOID lpStruct,UINT uSizeStruct,LPCSTR szFile); - WINBASEAPI WINBOOL WINAPI GetPrivateProfileStructW(LPCWSTR lpszSection,LPCWSTR lpszKey,LPVOID lpStruct,UINT uSizeStruct,LPCWSTR szFile); - WINBASEAPI WINBOOL WINAPI WritePrivateProfileStructA(LPCSTR lpszSection,LPCSTR lpszKey,LPVOID lpStruct,UINT uSizeStruct,LPCSTR szFile); - WINBASEAPI WINBOOL WINAPI WritePrivateProfileStructW(LPCWSTR lpszSection,LPCWSTR lpszKey,LPVOID lpStruct,UINT uSizeStruct,LPCWSTR szFile); - WINBASEAPI UINT WINAPI GetDriveTypeA(LPCSTR lpRootPathName); - WINBASEAPI UINT WINAPI GetDriveTypeW(LPCWSTR lpRootPathName); - WINBASEAPI UINT WINAPI GetSystemDirectoryA(LPSTR lpBuffer,UINT uSize); - WINBASEAPI UINT WINAPI GetSystemDirectoryW(LPWSTR lpBuffer,UINT uSize); - WINBASEAPI DWORD WINAPI GetTempPathA(DWORD nBufferLength,LPSTR lpBuffer); - WINBASEAPI DWORD WINAPI GetTempPathW(DWORD nBufferLength,LPWSTR lpBuffer); - WINBASEAPI UINT WINAPI GetTempFileNameA(LPCSTR lpPathName,LPCSTR lpPrefixString,UINT uUnique,LPSTR lpTempFileName); - WINBASEAPI UINT WINAPI GetTempFileNameW(LPCWSTR lpPathName,LPCWSTR lpPrefixString,UINT uUnique,LPWSTR lpTempFileName); - WINBASEAPI UINT WINAPI GetWindowsDirectoryA(LPSTR lpBuffer,UINT uSize); - WINBASEAPI UINT WINAPI GetWindowsDirectoryW(LPWSTR lpBuffer,UINT uSize); - WINBASEAPI UINT WINAPI GetSystemWindowsDirectoryA(LPSTR lpBuffer,UINT uSize); - WINBASEAPI UINT WINAPI GetSystemWindowsDirectoryW(LPWSTR lpBuffer,UINT uSize); - -#ifndef RC_INVOKED -#ifdef UNICODE -#define GetSystemWow64Directory GetSystemWow64DirectoryW -#else -#define GetSystemWow64Directory GetSystemWow64DirectoryA -#endif - - WINBASEAPI UINT WINAPI GetSystemWow64DirectoryA(LPSTR lpBuffer,UINT uSize); - WINBASEAPI UINT WINAPI GetSystemWow64DirectoryW(LPWSTR lpBuffer,UINT uSize); - WINBASEAPI BOOLEAN WINAPI Wow64EnableWow64FsRedirection(BOOLEAN Wow64FsEnableRedirection); - WINBASEAPI WINBOOL WINAPI Wow64DisableWow64FsRedirection(PVOID *OldValue); - WINBASEAPI WINBOOL WINAPI Wow64RevertWow64FsRedirection(PVOID OlValue); - - typedef UINT (WINAPI *PGET_SYSTEM_WOW64_DIRECTORY_A)(LPSTR lpBuffer,UINT uSize); - typedef UINT (WINAPI *PGET_SYSTEM_WOW64_DIRECTORY_W)(LPWSTR lpBuffer,UINT uSize); - -#define GET_SYSTEM_WOW64_DIRECTORY_NAME_A_A "GetSystemWow64DirectoryA" -#define GET_SYSTEM_WOW64_DIRECTORY_NAME_A_W L"GetSystemWow64DirectoryA" -#define GET_SYSTEM_WOW64_DIRECTORY_NAME_A_T TEXT("GetSystemWow64DirectoryA") -#define GET_SYSTEM_WOW64_DIRECTORY_NAME_W_A "GetSystemWow64DirectoryW" -#define GET_SYSTEM_WOW64_DIRECTORY_NAME_W_W L"GetSystemWow64DirectoryW" -#define GET_SYSTEM_WOW64_DIRECTORY_NAME_W_T TEXT("GetSystemWow64DirectoryW") - -#ifdef UNICODE -#define GET_SYSTEM_WOW64_DIRECTORY_NAME_T_A GET_SYSTEM_WOW64_DIRECTORY_NAME_W_A -#define GET_SYSTEM_WOW64_DIRECTORY_NAME_T_W GET_SYSTEM_WOW64_DIRECTORY_NAME_W_W -#define GET_SYSTEM_WOW64_DIRECTORY_NAME_T_T GET_SYSTEM_WOW64_DIRECTORY_NAME_W_T -#else -#define GET_SYSTEM_WOW64_DIRECTORY_NAME_T_A GET_SYSTEM_WOW64_DIRECTORY_NAME_A_A -#define GET_SYSTEM_WOW64_DIRECTORY_NAME_T_W GET_SYSTEM_WOW64_DIRECTORY_NAME_A_W -#define GET_SYSTEM_WOW64_DIRECTORY_NAME_T_T GET_SYSTEM_WOW64_DIRECTORY_NAME_A_T -#endif -#endif - -#ifdef UNICODE -#define SetCurrentDirectory SetCurrentDirectoryW -#define GetCurrentDirectory GetCurrentDirectoryW -#define SetDllDirectory SetDllDirectoryW -#define GetDllDirectory GetDllDirectoryW -#define GetDiskFreeSpace GetDiskFreeSpaceW -#define GetDiskFreeSpaceEx GetDiskFreeSpaceExW -#define CreateDirectory CreateDirectoryW -#define CreateDirectoryEx CreateDirectoryExW -#define RemoveDirectory RemoveDirectoryW -#define GetFullPathName GetFullPathNameW -#define DefineDosDevice DefineDosDeviceW -#define QueryDosDevice QueryDosDeviceW -#define CreateFile CreateFileW -#define SetFileAttributes SetFileAttributesW -#define GetFileAttributes GetFileAttributesW -#else -#define SetCurrentDirectory SetCurrentDirectoryA -#define GetCurrentDirectory GetCurrentDirectoryA -#define SetDllDirectory SetDllDirectoryA -#define GetDllDirectory GetDllDirectoryA -#define GetDiskFreeSpace GetDiskFreeSpaceA -#define GetDiskFreeSpaceEx GetDiskFreeSpaceExA -#define CreateDirectory CreateDirectoryA -#define CreateDirectoryEx CreateDirectoryExA -#define RemoveDirectory RemoveDirectoryA -#define GetFullPathName GetFullPathNameA -#define DefineDosDevice DefineDosDeviceA -#define QueryDosDevice QueryDosDeviceA -#define CreateFile CreateFileA -#define SetFileAttributes SetFileAttributesA -#define GetFileAttributes GetFileAttributesA -#endif - - WINBASEAPI WINBOOL WINAPI SetCurrentDirectoryA(LPCSTR lpPathName); - WINBASEAPI WINBOOL WINAPI SetCurrentDirectoryW(LPCWSTR lpPathName); - WINBASEAPI DWORD WINAPI GetCurrentDirectoryA(DWORD nBufferLength,LPSTR lpBuffer); - WINBASEAPI DWORD WINAPI GetCurrentDirectoryW(DWORD nBufferLength,LPWSTR lpBuffer); - WINBASEAPI WINBOOL WINAPI SetDllDirectoryA(LPCSTR lpPathName); - WINBASEAPI WINBOOL WINAPI SetDllDirectoryW(LPCWSTR lpPathName); - WINBASEAPI DWORD WINAPI GetDllDirectoryA(DWORD nBufferLength,LPSTR lpBuffer); - WINBASEAPI DWORD WINAPI GetDllDirectoryW(DWORD nBufferLength,LPWSTR lpBuffer); - WINBASEAPI WINBOOL WINAPI GetDiskFreeSpaceA(LPCSTR lpRootPathName,LPDWORD lpSectorsPerCluster,LPDWORD lpBytesPerSector,LPDWORD lpNumberOfFreeClusters,LPDWORD lpTotalNumberOfClusters); - WINBASEAPI WINBOOL WINAPI GetDiskFreeSpaceW(LPCWSTR lpRootPathName,LPDWORD lpSectorsPerCluster,LPDWORD lpBytesPerSector,LPDWORD lpNumberOfFreeClusters,LPDWORD lpTotalNumberOfClusters); - WINBASEAPI WINBOOL WINAPI GetDiskFreeSpaceExA(LPCSTR lpDirectoryName,PULARGE_INTEGER lpFreeBytesAvailableToCaller,PULARGE_INTEGER lpTotalNumberOfBytes,PULARGE_INTEGER lpTotalNumberOfFreeBytes); - WINBASEAPI WINBOOL WINAPI GetDiskFreeSpaceExW(LPCWSTR lpDirectoryName,PULARGE_INTEGER lpFreeBytesAvailableToCaller,PULARGE_INTEGER lpTotalNumberOfBytes,PULARGE_INTEGER lpTotalNumberOfFreeBytes); - WINBASEAPI WINBOOL WINAPI CreateDirectoryA(LPCSTR lpPathName,LPSECURITY_ATTRIBUTES lpSecurityAttributes); - WINBASEAPI WINBOOL WINAPI CreateDirectoryW(LPCWSTR lpPathName,LPSECURITY_ATTRIBUTES lpSecurityAttributes); - WINBASEAPI WINBOOL WINAPI CreateDirectoryExA(LPCSTR lpTemplateDirectory,LPCSTR lpNewDirectory,LPSECURITY_ATTRIBUTES lpSecurityAttributes); - WINBASEAPI WINBOOL WINAPI CreateDirectoryExW(LPCWSTR lpTemplateDirectory,LPCWSTR lpNewDirectory,LPSECURITY_ATTRIBUTES lpSecurityAttributes); - WINBASEAPI WINBOOL WINAPI RemoveDirectoryA(LPCSTR lpPathName); - WINBASEAPI WINBOOL WINAPI RemoveDirectoryW(LPCWSTR lpPathName); - WINBASEAPI DWORD WINAPI GetFullPathNameA(LPCSTR lpFileName,DWORD nBufferLength,LPSTR lpBuffer,LPSTR *lpFilePart); - WINBASEAPI DWORD WINAPI GetFullPathNameW(LPCWSTR lpFileName,DWORD nBufferLength,LPWSTR lpBuffer,LPWSTR *lpFilePart); - -#define DDD_RAW_TARGET_PATH 0x1 -#define DDD_REMOVE_DEFINITION 0x2 -#define DDD_EXACT_MATCH_ON_REMOVE 0x4 -#define DDD_NO_BROADCAST_SYSTEM 0x8 -#define DDD_LUID_BROADCAST_DRIVE 0x10 - - WINBASEAPI WINBOOL WINAPI DefineDosDeviceA(DWORD dwFlags,LPCSTR lpDeviceName,LPCSTR lpTargetPath); - WINBASEAPI WINBOOL WINAPI DefineDosDeviceW(DWORD dwFlags,LPCWSTR lpDeviceName,LPCWSTR lpTargetPath); - WINBASEAPI DWORD WINAPI QueryDosDeviceA(LPCSTR lpDeviceName,LPSTR lpTargetPath,DWORD ucchMax); - WINBASEAPI DWORD WINAPI QueryDosDeviceW(LPCWSTR lpDeviceName,LPWSTR lpTargetPath,DWORD ucchMax); - -#define EXPAND_LOCAL_DRIVES - - WINBASEAPI HANDLE WINAPI CreateFileA(LPCSTR lpFileName,DWORD dwDesiredAccess,DWORD dwShareMode,LPSECURITY_ATTRIBUTES lpSecurityAttributes,DWORD dwCreationDisposition,DWORD dwFlagsAndAttributes,HANDLE hTemplateFile); - WINBASEAPI HANDLE WINAPI CreateFileW(LPCWSTR lpFileName,DWORD dwDesiredAccess,DWORD dwShareMode,LPSECURITY_ATTRIBUTES lpSecurityAttributes,DWORD dwCreationDisposition,DWORD dwFlagsAndAttributes,HANDLE hTemplateFile); - WINBASEAPI HANDLE WINAPI ReOpenFile(HANDLE hOriginalFile,DWORD dwDesiredAccess,DWORD dwShareMode,DWORD dwFlagsAndAttributes); - WINBASEAPI WINBOOL WINAPI SetFileAttributesA(LPCSTR lpFileName,DWORD dwFileAttributes); - WINBASEAPI WINBOOL WINAPI SetFileAttributesW(LPCWSTR lpFileName,DWORD dwFileAttributes); - WINBASEAPI DWORD WINAPI GetFileAttributesA(LPCSTR lpFileName); - WINBASEAPI DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName); - - typedef enum _GET_FILEEX_INFO_LEVELS { - GetFileExInfoStandard,GetFileExMaxInfoLevel - } GET_FILEEX_INFO_LEVELS; - -#ifdef UNICODE -#define GetFileAttributesEx GetFileAttributesExW -#define GetCompressedFileSize GetCompressedFileSizeW -#define DeleteFile DeleteFileW -#define CheckNameLegalDOS8Dot3 CheckNameLegalDOS8Dot3W -#else -#define GetFileAttributesEx GetFileAttributesExA -#define GetCompressedFileSize GetCompressedFileSizeA -#define DeleteFile DeleteFileA -#define CheckNameLegalDOS8Dot3 CheckNameLegalDOS8Dot3A -#endif - - WINBASEAPI WINBOOL WINAPI GetFileAttributesExA(LPCSTR lpFileName,GET_FILEEX_INFO_LEVELS fInfoLevelId,LPVOID lpFileInformation); - WINBASEAPI WINBOOL WINAPI GetFileAttributesExW(LPCWSTR lpFileName,GET_FILEEX_INFO_LEVELS fInfoLevelId,LPVOID lpFileInformation); - WINBASEAPI DWORD WINAPI GetCompressedFileSizeA(LPCSTR lpFileName,LPDWORD lpFileSizeHigh); - WINBASEAPI DWORD WINAPI GetCompressedFileSizeW(LPCWSTR lpFileName,LPDWORD lpFileSizeHigh); - WINBASEAPI WINBOOL WINAPI DeleteFileA(LPCSTR lpFileName); - WINBASEAPI WINBOOL WINAPI DeleteFileW(LPCWSTR lpFileName); - WINBASEAPI WINBOOL WINAPI CheckNameLegalDOS8Dot3A(LPCSTR lpName,LPSTR lpOemName,DWORD OemNameSize,PBOOL pbNameContainsSpaces,PBOOL pbNameLegal); - WINBASEAPI WINBOOL WINAPI CheckNameLegalDOS8Dot3W(LPCWSTR lpName,LPSTR lpOemName,DWORD OemNameSize,PBOOL pbNameContainsSpaces,PBOOL pbNameLegal); - - typedef enum _FINDEX_INFO_LEVELS { - FindExInfoStandard,FindExInfoMaxInfoLevel - } FINDEX_INFO_LEVELS; - - typedef enum _FINDEX_SEARCH_OPS { - FindExSearchNameMatch,FindExSearchLimitToDirectories,FindExSearchLimitToDevices,FindExSearchMaxSearchOp - } FINDEX_SEARCH_OPS; - -#define FIND_FIRST_EX_CASE_SENSITIVE 0x1 - -#ifdef UNICODE -#define FindFirstFileEx FindFirstFileExW -#define FindFirstFile FindFirstFileW -#define FindNextFile FindNextFileW -#define SearchPath SearchPathW -#define CopyFile CopyFileW -#define CopyFileEx CopyFileExW -#define MoveFile MoveFileW -#define MoveFileEx MoveFileExW -#define MoveFileWithProgress MoveFileWithProgressW -#define ReplaceFile ReplaceFileW -#define CreateHardLink CreateHardLinkW -#define CreateNamedPipe CreateNamedPipeW -#define GetNamedPipeHandleState GetNamedPipeHandleStateW -#define CallNamedPipe CallNamedPipeW -#define WaitNamedPipe WaitNamedPipeW -#define SetVolumeLabel SetVolumeLabelW -#define GetVolumeInformation GetVolumeInformationW -#define ClearEventLog ClearEventLogW -#define BackupEventLog BackupEventLogW -#define OpenEventLog OpenEventLogW -#define RegisterEventSource RegisterEventSourceW -#define OpenBackupEventLog OpenBackupEventLogW -#define ReadEventLog ReadEventLogW -#define ReportEvent ReportEventW -#define AccessCheckAndAuditAlarm AccessCheckAndAuditAlarmW -#define AccessCheckByTypeAndAuditAlarm AccessCheckByTypeAndAuditAlarmW -#define AccessCheckByTypeResultListAndAuditAlarm AccessCheckByTypeResultListAndAuditAlarmW -#define AccessCheckByTypeResultListAndAuditAlarmByHandle AccessCheckByTypeResultListAndAuditAlarmByHandleW -#define ObjectOpenAuditAlarm ObjectOpenAuditAlarmW -#define ObjectPrivilegeAuditAlarm ObjectPrivilegeAuditAlarmW -#define ObjectCloseAuditAlarm ObjectCloseAuditAlarmW -#define ObjectDeleteAuditAlarm ObjectDeleteAuditAlarmW -#define PrivilegedServiceAuditAlarm PrivilegedServiceAuditAlarmW -#define SetFileSecurity SetFileSecurityW -#define GetFileSecurity GetFileSecurityW -#define FindFirstChangeNotification FindFirstChangeNotificationW -#define IsBadStringPtr IsBadStringPtrW -#define LookupAccountSid LookupAccountSidW -#define LookupAccountName LookupAccountNameW -#define LookupPrivilegeValue LookupPrivilegeValueW -#define LookupPrivilegeName LookupPrivilegeNameW -#define LookupPrivilegeDisplayName LookupPrivilegeDisplayNameW -#define BuildCommDCB BuildCommDCBW -#define BuildCommDCBAndTimeouts BuildCommDCBAndTimeoutsW -#define CommConfigDialog CommConfigDialogW -#define GetDefaultCommConfig GetDefaultCommConfigW -#define SetDefaultCommConfig SetDefaultCommConfigW -#define GetComputerName GetComputerNameW -#define SetComputerName SetComputerNameW -#define GetComputerNameEx GetComputerNameExW -#define SetComputerNameEx SetComputerNameExW -#define DnsHostnameToComputerName DnsHostnameToComputerNameW -#define GetUserName GetUserNameW -#else -#define FindFirstFileEx FindFirstFileExA -#define FindFirstFile FindFirstFileA -#define FindNextFile FindNextFileA -#define SearchPath SearchPathA -#define CopyFile CopyFileA -#define CopyFileEx CopyFileExA -#define MoveFile MoveFileA -#define MoveFileEx MoveFileExA -#define MoveFileWithProgress MoveFileWithProgressA -#define ReplaceFile ReplaceFileA -#define CreateHardLink CreateHardLinkA -#define CreateNamedPipe CreateNamedPipeA -#define GetNamedPipeHandleState GetNamedPipeHandleStateA -#define CallNamedPipe CallNamedPipeA -#define WaitNamedPipe WaitNamedPipeA -#define SetVolumeLabel SetVolumeLabelA -#define GetVolumeInformation GetVolumeInformationA -#define ClearEventLog ClearEventLogA -#define BackupEventLog BackupEventLogA -#define OpenEventLog OpenEventLogA -#define RegisterEventSource RegisterEventSourceA -#define OpenBackupEventLog OpenBackupEventLogA -#define ReadEventLog ReadEventLogA -#define ReportEvent ReportEventA -#define AccessCheckAndAuditAlarm AccessCheckAndAuditAlarmA -#define AccessCheckByTypeAndAuditAlarm AccessCheckByTypeAndAuditAlarmA -#define AccessCheckByTypeResultListAndAuditAlarm AccessCheckByTypeResultListAndAuditAlarmA -#define AccessCheckByTypeResultListAndAuditAlarmByHandle AccessCheckByTypeResultListAndAuditAlarmByHandleA -#define ObjectOpenAuditAlarm ObjectOpenAuditAlarmA -#define ObjectPrivilegeAuditAlarm ObjectPrivilegeAuditAlarmA -#define ObjectCloseAuditAlarm ObjectCloseAuditAlarmA -#define ObjectDeleteAuditAlarm ObjectDeleteAuditAlarmA -#define PrivilegedServiceAuditAlarm PrivilegedServiceAuditAlarmA -#define SetFileSecurity SetFileSecurityA -#define GetFileSecurity GetFileSecurityA -#define FindFirstChangeNotification FindFirstChangeNotificationA -#define IsBadStringPtr IsBadStringPtrA -#define LookupAccountSid LookupAccountSidA -#define LookupAccountName LookupAccountNameA -#define LookupPrivilegeValue LookupPrivilegeValueA -#define LookupPrivilegeName LookupPrivilegeNameA -#define LookupPrivilegeDisplayName LookupPrivilegeDisplayNameA -#define BuildCommDCB BuildCommDCBA -#define BuildCommDCBAndTimeouts BuildCommDCBAndTimeoutsA -#define CommConfigDialog CommConfigDialogA -#define GetDefaultCommConfig GetDefaultCommConfigA -#define SetDefaultCommConfig SetDefaultCommConfigA -#define GetComputerName GetComputerNameA -#define SetComputerName SetComputerNameA -#define GetComputerNameEx GetComputerNameExA -#define SetComputerNameEx SetComputerNameExA -#define DnsHostnameToComputerName DnsHostnameToComputerNameA -#define GetUserName GetUserNameA -#endif - - WINBASEAPI HANDLE WINAPI FindFirstFileExA(LPCSTR lpFileName,FINDEX_INFO_LEVELS fInfoLevelId,LPVOID lpFindFileData,FINDEX_SEARCH_OPS fSearchOp,LPVOID lpSearchFilter,DWORD dwAdditionalFlags); - WINBASEAPI HANDLE WINAPI FindFirstFileExW(LPCWSTR lpFileName,FINDEX_INFO_LEVELS fInfoLevelId,LPVOID lpFindFileData,FINDEX_SEARCH_OPS fSearchOp,LPVOID lpSearchFilter,DWORD dwAdditionalFlags); - WINBASEAPI HANDLE WINAPI FindFirstFileA(LPCSTR lpFileName,LPWIN32_FIND_DATAA lpFindFileData); - WINBASEAPI HANDLE WINAPI FindFirstFileW(LPCWSTR lpFileName,LPWIN32_FIND_DATAW lpFindFileData); - WINBASEAPI WINBOOL WINAPI FindNextFileA(HANDLE hFindFile,LPWIN32_FIND_DATAA lpFindFileData); - WINBASEAPI WINBOOL WINAPI FindNextFileW(HANDLE hFindFile,LPWIN32_FIND_DATAW lpFindFileData); - WINBASEAPI DWORD WINAPI SearchPathA(LPCSTR lpPath,LPCSTR lpFileName,LPCSTR lpExtension,DWORD nBufferLength,LPSTR lpBuffer,LPSTR *lpFilePart); - WINBASEAPI DWORD WINAPI SearchPathW(LPCWSTR lpPath,LPCWSTR lpFileName,LPCWSTR lpExtension,DWORD nBufferLength,LPWSTR lpBuffer,LPWSTR *lpFilePart); - WINBASEAPI WINBOOL WINAPI CopyFileA(LPCSTR lpExistingFileName,LPCSTR lpNewFileName,WINBOOL bFailIfExists); - WINBASEAPI WINBOOL WINAPI CopyFileW(LPCWSTR lpExistingFileName,LPCWSTR lpNewFileName,WINBOOL bFailIfExists); - - typedef DWORD (WINAPI *LPPROGRESS_ROUTINE)(LARGE_INTEGER TotalFileSize,LARGE_INTEGER TotalBytesTransferred,LARGE_INTEGER StreamSize,LARGE_INTEGER StreamBytesTransferred,DWORD dwStreamNumber,DWORD dwCallbackReason,HANDLE hSourceFile,HANDLE hDestinationFile,LPVOID lpData); - - WINBASEAPI WINBOOL WINAPI CopyFileExA(LPCSTR lpExistingFileName,LPCSTR lpNewFileName,LPPROGRESS_ROUTINE lpProgressRoutine,LPVOID lpData,LPBOOL pbCancel,DWORD dwCopyFlags); - WINBASEAPI WINBOOL WINAPI CopyFileExW(LPCWSTR lpExistingFileName,LPCWSTR lpNewFileName,LPPROGRESS_ROUTINE lpProgressRoutine,LPVOID lpData,LPBOOL pbCancel,DWORD dwCopyFlags); - WINBASEAPI WINBOOL WINAPI MoveFileA(LPCSTR lpExistingFileName,LPCSTR lpNewFileName); - WINBASEAPI WINBOOL WINAPI MoveFileW(LPCWSTR lpExistingFileName,LPCWSTR lpNewFileName); - WINBASEAPI WINBOOL WINAPI MoveFileExA(LPCSTR lpExistingFileName,LPCSTR lpNewFileName,DWORD dwFlags); - WINBASEAPI WINBOOL WINAPI MoveFileExW(LPCWSTR lpExistingFileName,LPCWSTR lpNewFileName,DWORD dwFlags); - WINBASEAPI WINBOOL WINAPI MoveFileWithProgressA(LPCSTR lpExistingFileName,LPCSTR lpNewFileName,LPPROGRESS_ROUTINE lpProgressRoutine,LPVOID lpData,DWORD dwFlags); - WINBASEAPI WINBOOL WINAPI MoveFileWithProgressW(LPCWSTR lpExistingFileName,LPCWSTR lpNewFileName,LPPROGRESS_ROUTINE lpProgressRoutine,LPVOID lpData,DWORD dwFlags); - -#define MOVEFILE_REPLACE_EXISTING 0x1 -#define MOVEFILE_COPY_ALLOWED 0x2 -#define MOVEFILE_DELAY_UNTIL_REBOOT 0x4 -#define MOVEFILE_WRITE_THROUGH 0x8 -#define MOVEFILE_CREATE_HARDLINK 0x10 -#define MOVEFILE_FAIL_IF_NOT_TRACKABLE 0x20 - - WINBASEAPI WINBOOL WINAPI ReplaceFileA(LPCSTR lpReplacedFileName,LPCSTR lpReplacementFileName,LPCSTR lpBackupFileName,DWORD dwReplaceFlags,LPVOID lpExclude,LPVOID lpReserved); - WINBASEAPI WINBOOL WINAPI ReplaceFileW(LPCWSTR lpReplacedFileName,LPCWSTR lpReplacementFileName,LPCWSTR lpBackupFileName,DWORD dwReplaceFlags,LPVOID lpExclude,LPVOID lpReserved); - WINBASEAPI WINBOOL WINAPI CreateHardLinkA(LPCSTR lpFileName,LPCSTR lpExistingFileName,LPSECURITY_ATTRIBUTES lpSecurityAttributes); - WINBASEAPI WINBOOL WINAPI CreateHardLinkW(LPCWSTR lpFileName,LPCWSTR lpExistingFileName,LPSECURITY_ATTRIBUTES lpSecurityAttributes); - - typedef enum _STREAM_INFO_LEVELS { - FindStreamInfoStandard,FindStreamInfoMaxInfoLevel - } STREAM_INFO_LEVELS; - - typedef struct _WIN32_FIND_STREAM_DATA { - LARGE_INTEGER StreamSize; - WCHAR cStreamName[MAX_PATH + 36]; - } WIN32_FIND_STREAM_DATA,*PWIN32_FIND_STREAM_DATA; - - HANDLE WINAPI FindFirstStreamW(LPCWSTR lpFileName,STREAM_INFO_LEVELS InfoLevel,LPVOID lpFindStreamData,DWORD dwFlags); - WINBOOL WINAPI FindNextStreamW(HANDLE hFindStream,LPVOID lpFindStreamData); - WINBASEAPI HANDLE WINAPI CreateNamedPipeA(LPCSTR lpName,DWORD dwOpenMode,DWORD dwPipeMode,DWORD nMaxInstances,DWORD nOutBufferSize,DWORD nInBufferSize,DWORD nDefaultTimeOut,LPSECURITY_ATTRIBUTES lpSecurityAttributes); - WINBASEAPI HANDLE WINAPI CreateNamedPipeW(LPCWSTR lpName,DWORD dwOpenMode,DWORD dwPipeMode,DWORD nMaxInstances,DWORD nOutBufferSize,DWORD nInBufferSize,DWORD nDefaultTimeOut,LPSECURITY_ATTRIBUTES lpSecurityAttributes); - WINBASEAPI WINBOOL WINAPI GetNamedPipeHandleStateA(HANDLE hNamedPipe,LPDWORD lpState,LPDWORD lpCurInstances,LPDWORD lpMaxCollectionCount,LPDWORD lpCollectDataTimeout,LPSTR lpUserName,DWORD nMaxUserNameSize); - WINBASEAPI WINBOOL WINAPI GetNamedPipeHandleStateW(HANDLE hNamedPipe,LPDWORD lpState,LPDWORD lpCurInstances,LPDWORD lpMaxCollectionCount,LPDWORD lpCollectDataTimeout,LPWSTR lpUserName,DWORD nMaxUserNameSize); - WINBASEAPI WINBOOL WINAPI CallNamedPipeA(LPCSTR lpNamedPipeName,LPVOID lpInBuffer,DWORD nInBufferSize,LPVOID lpOutBuffer,DWORD nOutBufferSize,LPDWORD lpBytesRead,DWORD nTimeOut); - WINBASEAPI WINBOOL WINAPI CallNamedPipeW(LPCWSTR lpNamedPipeName,LPVOID lpInBuffer,DWORD nInBufferSize,LPVOID lpOutBuffer,DWORD nOutBufferSize,LPDWORD lpBytesRead,DWORD nTimeOut); - WINBASEAPI WINBOOL WINAPI WaitNamedPipeA(LPCSTR lpNamedPipeName,DWORD nTimeOut); - WINBASEAPI WINBOOL WINAPI WaitNamedPipeW(LPCWSTR lpNamedPipeName,DWORD nTimeOut); - WINBASEAPI WINBOOL WINAPI SetVolumeLabelA(LPCSTR lpRootPathName,LPCSTR lpVolumeName); - WINBASEAPI WINBOOL WINAPI SetVolumeLabelW(LPCWSTR lpRootPathName,LPCWSTR lpVolumeName); - WINBASEAPI VOID WINAPI SetFileApisToOEM(VOID); - WINBASEAPI VOID WINAPI SetFileApisToANSI(VOID); - WINBASEAPI WINBOOL WINAPI AreFileApisANSI(VOID); - WINBASEAPI WINBOOL WINAPI GetVolumeInformationA(LPCSTR lpRootPathName,LPSTR lpVolumeNameBuffer,DWORD nVolumeNameSize,LPDWORD lpVolumeSerialNumber,LPDWORD lpMaximumComponentLength,LPDWORD lpFileSystemFlags,LPSTR lpFileSystemNameBuffer,DWORD nFileSystemNameSize); - WINBASEAPI WINBOOL WINAPI GetVolumeInformationW(LPCWSTR lpRootPathName,LPWSTR lpVolumeNameBuffer,DWORD nVolumeNameSize,LPDWORD lpVolumeSerialNumber,LPDWORD lpMaximumComponentLength,LPDWORD lpFileSystemFlags,LPWSTR lpFileSystemNameBuffer,DWORD nFileSystemNameSize); - WINBASEAPI WINBOOL WINAPI CancelIo(HANDLE hFile); - WINADVAPI WINBOOL WINAPI ClearEventLogA(HANDLE hEventLog,LPCSTR lpBackupFileName); - WINADVAPI WINBOOL WINAPI ClearEventLogW(HANDLE hEventLog,LPCWSTR lpBackupFileName); - WINADVAPI WINBOOL WINAPI BackupEventLogA(HANDLE hEventLog,LPCSTR lpBackupFileName); - WINADVAPI WINBOOL WINAPI BackupEventLogW(HANDLE hEventLog,LPCWSTR lpBackupFileName); - WINADVAPI WINBOOL WINAPI CloseEventLog(HANDLE hEventLog); - WINADVAPI WINBOOL WINAPI DeregisterEventSource(HANDLE hEventLog); - WINADVAPI WINBOOL WINAPI NotifyChangeEventLog(HANDLE hEventLog,HANDLE hEvent); - WINADVAPI WINBOOL WINAPI GetNumberOfEventLogRecords(HANDLE hEventLog,PDWORD NumberOfRecords); - WINADVAPI WINBOOL WINAPI GetOldestEventLogRecord(HANDLE hEventLog,PDWORD OldestRecord); - WINADVAPI HANDLE WINAPI OpenEventLogA(LPCSTR lpUNCServerName,LPCSTR lpSourceName); - WINADVAPI HANDLE WINAPI OpenEventLogW(LPCWSTR lpUNCServerName,LPCWSTR lpSourceName); - WINADVAPI HANDLE WINAPI RegisterEventSourceA(LPCSTR lpUNCServerName,LPCSTR lpSourceName); - WINADVAPI HANDLE WINAPI RegisterEventSourceW(LPCWSTR lpUNCServerName,LPCWSTR lpSourceName); - WINADVAPI HANDLE WINAPI OpenBackupEventLogA(LPCSTR lpUNCServerName,LPCSTR lpFileName); - WINADVAPI HANDLE WINAPI OpenBackupEventLogW(LPCWSTR lpUNCServerName,LPCWSTR lpFileName); - WINADVAPI WINBOOL WINAPI ReadEventLogA(HANDLE hEventLog,DWORD dwReadFlags,DWORD dwRecordOffset,LPVOID lpBuffer,DWORD nNumberOfBytesToRead,DWORD *pnBytesRead,DWORD *pnMinNumberOfBytesNeeded); - WINADVAPI WINBOOL WINAPI ReadEventLogW(HANDLE hEventLog,DWORD dwReadFlags,DWORD dwRecordOffset,LPVOID lpBuffer,DWORD nNumberOfBytesToRead,DWORD *pnBytesRead,DWORD *pnMinNumberOfBytesNeeded); - WINADVAPI WINBOOL WINAPI ReportEventA(HANDLE hEventLog,WORD wType,WORD wCategory,DWORD dwEventID,PSID lpUserSid,WORD wNumStrings,DWORD dwDataSize,LPCSTR *lpStrings,LPVOID lpRawData); - WINADVAPI WINBOOL WINAPI ReportEventW(HANDLE hEventLog,WORD wType,WORD wCategory,DWORD dwEventID,PSID lpUserSid,WORD wNumStrings,DWORD dwDataSize,LPCWSTR *lpStrings,LPVOID lpRawData); - -#define EVENTLOG_FULL_INFO 0 - - typedef struct _EVENTLOG_FULL_INFORMATION { - DWORD dwFull; - } EVENTLOG_FULL_INFORMATION,*LPEVENTLOG_FULL_INFORMATION; - - WINADVAPI WINBOOL WINAPI GetEventLogInformation(HANDLE hEventLog,DWORD dwInfoLevel,LPVOID lpBuffer,DWORD cbBufSize,LPDWORD pcbBytesNeeded); - WINADVAPI WINBOOL WINAPI DuplicateToken(HANDLE ExistingTokenHandle,SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,PHANDLE DuplicateTokenHandle); - WINADVAPI WINBOOL WINAPI GetKernelObjectSecurity(HANDLE Handle,SECURITY_INFORMATION RequestedInformation,PSECURITY_DESCRIPTOR pSecurityDescriptor,DWORD nLength,LPDWORD lpnLengthNeeded); - WINADVAPI WINBOOL WINAPI ImpersonateNamedPipeClient(HANDLE hNamedPipe); - WINADVAPI WINBOOL WINAPI ImpersonateSelf(SECURITY_IMPERSONATION_LEVEL ImpersonationLevel); - WINADVAPI WINBOOL WINAPI RevertToSelf(VOID); - WINADVAPI WINBOOL WINAPI SetThreadToken (PHANDLE Thread,HANDLE Token); - WINADVAPI WINBOOL WINAPI AccessCheck(PSECURITY_DESCRIPTOR pSecurityDescriptor,HANDLE ClientToken,DWORD DesiredAccess,PGENERIC_MAPPING GenericMapping,PPRIVILEGE_SET PrivilegeSet,LPDWORD PrivilegeSetLength,LPDWORD GrantedAccess,LPBOOL AccessStatus); - WINADVAPI WINBOOL WINAPI AccessCheckByType(PSECURITY_DESCRIPTOR pSecurityDescriptor,PSID PrincipalSelfSid,HANDLE ClientToken,DWORD DesiredAccess,POBJECT_TYPE_LIST ObjectTypeList,DWORD ObjectTypeListLength,PGENERIC_MAPPING GenericMapping,PPRIVILEGE_SET PrivilegeSet,LPDWORD PrivilegeSetLength,LPDWORD GrantedAccess,LPBOOL AccessStatus); - WINADVAPI WINBOOL WINAPI AccessCheckByTypeResultList(PSECURITY_DESCRIPTOR pSecurityDescriptor,PSID PrincipalSelfSid,HANDLE ClientToken,DWORD DesiredAccess,POBJECT_TYPE_LIST ObjectTypeList,DWORD ObjectTypeListLength,PGENERIC_MAPPING GenericMapping,PPRIVILEGE_SET PrivilegeSet,LPDWORD PrivilegeSetLength,LPDWORD GrantedAccessList,LPDWORD AccessStatusList); - WINADVAPI WINBOOL WINAPI OpenProcessToken(HANDLE ProcessHandle,DWORD DesiredAccess,PHANDLE TokenHandle); - WINADVAPI WINBOOL WINAPI OpenThreadToken(HANDLE ThreadHandle,DWORD DesiredAccess,WINBOOL OpenAsSelf,PHANDLE TokenHandle); - WINADVAPI WINBOOL WINAPI GetTokenInformation(HANDLE TokenHandle,TOKEN_INFORMATION_CLASS TokenInformationClass,LPVOID TokenInformation,DWORD TokenInformationLength,PDWORD ReturnLength); - WINADVAPI WINBOOL WINAPI SetTokenInformation(HANDLE TokenHandle,TOKEN_INFORMATION_CLASS TokenInformationClass,LPVOID TokenInformation,DWORD TokenInformationLength); - WINADVAPI WINBOOL WINAPI AdjustTokenPrivileges(HANDLE TokenHandle,WINBOOL DisableAllPrivileges,PTOKEN_PRIVILEGES NewState,DWORD BufferLength,PTOKEN_PRIVILEGES PreviousState,PDWORD ReturnLength); - WINADVAPI WINBOOL WINAPI AdjustTokenGroups(HANDLE TokenHandle,WINBOOL ResetToDefault,PTOKEN_GROUPS NewState,DWORD BufferLength,PTOKEN_GROUPS PreviousState,PDWORD ReturnLength); - WINADVAPI WINBOOL WINAPI PrivilegeCheck(HANDLE ClientToken,PPRIVILEGE_SET RequiredPrivileges,LPBOOL pfResult); - WINADVAPI WINBOOL WINAPI AccessCheckAndAuditAlarmA(LPCSTR SubsystemName,LPVOID HandleId,LPSTR ObjectTypeName,LPSTR ObjectName,PSECURITY_DESCRIPTOR SecurityDescriptor,DWORD DesiredAccess,PGENERIC_MAPPING GenericMapping,WINBOOL ObjectCreation,LPDWORD GrantedAccess,LPBOOL AccessStatus,LPBOOL pfGenerateOnClose); - WINADVAPI WINBOOL WINAPI AccessCheckAndAuditAlarmW(LPCWSTR SubsystemName,LPVOID HandleId,LPWSTR ObjectTypeName,LPWSTR ObjectName,PSECURITY_DESCRIPTOR SecurityDescriptor,DWORD DesiredAccess,PGENERIC_MAPPING GenericMapping,WINBOOL ObjectCreation,LPDWORD GrantedAccess,LPBOOL AccessStatus,LPBOOL pfGenerateOnClose); - WINADVAPI WINBOOL WINAPI AccessCheckByTypeAndAuditAlarmA(LPCSTR SubsystemName,LPVOID HandleId,LPCSTR ObjectTypeName,LPCSTR ObjectName,PSECURITY_DESCRIPTOR SecurityDescriptor,PSID PrincipalSelfSid,DWORD DesiredAccess,AUDIT_EVENT_TYPE AuditType,DWORD Flags,POBJECT_TYPE_LIST ObjectTypeList,DWORD ObjectTypeListLength,PGENERIC_MAPPING GenericMapping,WINBOOL ObjectCreation,LPDWORD GrantedAccess,LPBOOL AccessStatus,LPBOOL pfGenerateOnClose); - WINADVAPI WINBOOL WINAPI AccessCheckByTypeAndAuditAlarmW(LPCWSTR SubsystemName,LPVOID HandleId,LPCWSTR ObjectTypeName,LPCWSTR ObjectName,PSECURITY_DESCRIPTOR SecurityDescriptor,PSID PrincipalSelfSid,DWORD DesiredAccess,AUDIT_EVENT_TYPE AuditType,DWORD Flags,POBJECT_TYPE_LIST ObjectTypeList,DWORD ObjectTypeListLength,PGENERIC_MAPPING GenericMapping,WINBOOL ObjectCreation,LPDWORD GrantedAccess,LPBOOL AccessStatus,LPBOOL pfGenerateOnClose); - WINADVAPI WINBOOL WINAPI AccessCheckByTypeResultListAndAuditAlarmA(LPCSTR SubsystemName,LPVOID HandleId,LPCSTR ObjectTypeName,LPCSTR ObjectName,PSECURITY_DESCRIPTOR SecurityDescriptor,PSID PrincipalSelfSid,DWORD DesiredAccess,AUDIT_EVENT_TYPE AuditType,DWORD Flags,POBJECT_TYPE_LIST ObjectTypeList,DWORD ObjectTypeListLength,PGENERIC_MAPPING GenericMapping,WINBOOL ObjectCreation,LPDWORD GrantedAccess,LPDWORD AccessStatusList,LPBOOL pfGenerateOnClose); - WINADVAPI WINBOOL WINAPI AccessCheckByTypeResultListAndAuditAlarmW(LPCWSTR SubsystemName,LPVOID HandleId,LPCWSTR ObjectTypeName,LPCWSTR ObjectName,PSECURITY_DESCRIPTOR SecurityDescriptor,PSID PrincipalSelfSid,DWORD DesiredAccess,AUDIT_EVENT_TYPE AuditType,DWORD Flags,POBJECT_TYPE_LIST ObjectTypeList,DWORD ObjectTypeListLength,PGENERIC_MAPPING GenericMapping,WINBOOL ObjectCreation,LPDWORD GrantedAccess,LPDWORD AccessStatusList,LPBOOL pfGenerateOnClose); - WINADVAPI WINBOOL WINAPI AccessCheckByTypeResultListAndAuditAlarmByHandleA(LPCSTR SubsystemName,LPVOID HandleId,HANDLE ClientToken,LPCSTR ObjectTypeName,LPCSTR ObjectName,PSECURITY_DESCRIPTOR SecurityDescriptor,PSID PrincipalSelfSid,DWORD DesiredAccess,AUDIT_EVENT_TYPE AuditType,DWORD Flags,POBJECT_TYPE_LIST ObjectTypeList,DWORD ObjectTypeListLength,PGENERIC_MAPPING GenericMapping,WINBOOL ObjectCreation,LPDWORD GrantedAccess,LPDWORD AccessStatusList,LPBOOL pfGenerateOnClose); - WINADVAPI WINBOOL WINAPI AccessCheckByTypeResultListAndAuditAlarmByHandleW(LPCWSTR SubsystemName,LPVOID HandleId,HANDLE ClientToken,LPCWSTR ObjectTypeName,LPCWSTR ObjectName,PSECURITY_DESCRIPTOR SecurityDescriptor,PSID PrincipalSelfSid,DWORD DesiredAccess,AUDIT_EVENT_TYPE AuditType,DWORD Flags,POBJECT_TYPE_LIST ObjectTypeList,DWORD ObjectTypeListLength,PGENERIC_MAPPING GenericMapping,WINBOOL ObjectCreation,LPDWORD GrantedAccess,LPDWORD AccessStatusList,LPBOOL pfGenerateOnClose); - WINADVAPI WINBOOL WINAPI ObjectOpenAuditAlarmA(LPCSTR SubsystemName,LPVOID HandleId,LPSTR ObjectTypeName,LPSTR ObjectName,PSECURITY_DESCRIPTOR pSecurityDescriptor,HANDLE ClientToken,DWORD DesiredAccess,DWORD GrantedAccess,PPRIVILEGE_SET Privileges,WINBOOL ObjectCreation,WINBOOL AccessGranted,LPBOOL GenerateOnClose); - WINADVAPI WINBOOL WINAPI ObjectOpenAuditAlarmW(LPCWSTR SubsystemName,LPVOID HandleId,LPWSTR ObjectTypeName,LPWSTR ObjectName,PSECURITY_DESCRIPTOR pSecurityDescriptor,HANDLE ClientToken,DWORD DesiredAccess,DWORD GrantedAccess,PPRIVILEGE_SET Privileges,WINBOOL ObjectCreation,WINBOOL AccessGranted,LPBOOL GenerateOnClose); - WINADVAPI WINBOOL WINAPI ObjectPrivilegeAuditAlarmA(LPCSTR SubsystemName,LPVOID HandleId,HANDLE ClientToken,DWORD DesiredAccess,PPRIVILEGE_SET Privileges,WINBOOL AccessGranted); - WINADVAPI WINBOOL WINAPI ObjectPrivilegeAuditAlarmW(LPCWSTR SubsystemName,LPVOID HandleId,HANDLE ClientToken,DWORD DesiredAccess,PPRIVILEGE_SET Privileges,WINBOOL AccessGranted); - WINADVAPI WINBOOL WINAPI ObjectCloseAuditAlarmA(LPCSTR SubsystemName,LPVOID HandleId,WINBOOL GenerateOnClose); - WINADVAPI WINBOOL WINAPI ObjectCloseAuditAlarmW(LPCWSTR SubsystemName,LPVOID HandleId,WINBOOL GenerateOnClose); - WINADVAPI WINBOOL WINAPI ObjectDeleteAuditAlarmA(LPCSTR SubsystemName,LPVOID HandleId,WINBOOL GenerateOnClose); - WINADVAPI WINBOOL WINAPI ObjectDeleteAuditAlarmW(LPCWSTR SubsystemName,LPVOID HandleId,WINBOOL GenerateOnClose); - WINADVAPI WINBOOL WINAPI PrivilegedServiceAuditAlarmA(LPCSTR SubsystemName,LPCSTR ServiceName,HANDLE ClientToken,PPRIVILEGE_SET Privileges,WINBOOL AccessGranted); - WINADVAPI WINBOOL WINAPI PrivilegedServiceAuditAlarmW(LPCWSTR SubsystemName,LPCWSTR ServiceName,HANDLE ClientToken,PPRIVILEGE_SET Privileges,WINBOOL AccessGranted); - WINADVAPI WINBOOL WINAPI IsWellKnownSid(PSID pSid,WELL_KNOWN_SID_TYPE WellKnownSidType); - WINADVAPI WINBOOL WINAPI CreateWellKnownSid(WELL_KNOWN_SID_TYPE WellKnownSidType,PSID DomainSid,PSID pSid,DWORD *cbSid); - WINADVAPI WINBOOL WINAPI EqualDomainSid(PSID pSid1,PSID pSid2,WINBOOL *pfEqual); - WINADVAPI WINBOOL WINAPI GetWindowsAccountDomainSid(PSID pSid,PSID pDomainSid,DWORD *cbDomainSid); - WINADVAPI WINBOOL WINAPI IsValidSid(PSID pSid); - WINADVAPI WINBOOL WINAPI EqualSid(PSID pSid1,PSID pSid2); - WINADVAPI WINBOOL WINAPI EqualPrefixSid(PSID pSid1,PSID pSid2); - WINADVAPI DWORD WINAPI GetSidLengthRequired (UCHAR nSubAuthorityCount); - WINADVAPI WINBOOL WINAPI AllocateAndInitializeSid(PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,BYTE nSubAuthorityCount,DWORD nSubAuthority0,DWORD nSubAuthority1,DWORD nSubAuthority2,DWORD nSubAuthority3,DWORD nSubAuthority4,DWORD nSubAuthority5,DWORD nSubAuthority6,DWORD nSubAuthority7,PSID *pSid); - WINADVAPI PVOID WINAPI FreeSid(PSID pSid); - WINADVAPI WINBOOL WINAPI InitializeSid(PSID Sid,PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,BYTE nSubAuthorityCount); - WINADVAPI PSID_IDENTIFIER_AUTHORITY WINAPI GetSidIdentifierAuthority(PSID pSid); - WINADVAPI PDWORD WINAPI GetSidSubAuthority(PSID pSid,DWORD nSubAuthority); - WINADVAPI PUCHAR WINAPI GetSidSubAuthorityCount(PSID pSid); - WINADVAPI DWORD WINAPI GetLengthSid(PSID pSid); - WINADVAPI WINBOOL WINAPI CopySid(DWORD nDestinationSidLength,PSID pDestinationSid,PSID pSourceSid); - WINADVAPI WINBOOL WINAPI AreAllAccessesGranted(DWORD GrantedAccess,DWORD DesiredAccess); - WINADVAPI WINBOOL WINAPI AreAnyAccessesGranted(DWORD GrantedAccess,DWORD DesiredAccess); - WINADVAPI VOID WINAPI MapGenericMask(PDWORD AccessMask,PGENERIC_MAPPING GenericMapping); - WINADVAPI WINBOOL WINAPI IsValidAcl(PACL pAcl); - WINADVAPI WINBOOL WINAPI InitializeAcl(PACL pAcl,DWORD nAclLength,DWORD dwAclRevision); - WINADVAPI WINBOOL WINAPI GetAclInformation(PACL pAcl,LPVOID pAclInformation,DWORD nAclInformationLength,ACL_INFORMATION_CLASS dwAclInformationClass); - WINADVAPI WINBOOL WINAPI SetAclInformation(PACL pAcl,LPVOID pAclInformation,DWORD nAclInformationLength,ACL_INFORMATION_CLASS dwAclInformationClass); - WINADVAPI WINBOOL WINAPI AddAce(PACL pAcl,DWORD dwAceRevision,DWORD dwStartingAceIndex,LPVOID pAceList,DWORD nAceListLength); - WINADVAPI WINBOOL WINAPI DeleteAce(PACL pAcl,DWORD dwAceIndex); - WINADVAPI WINBOOL WINAPI GetAce(PACL pAcl,DWORD dwAceIndex,LPVOID *pAce); - WINADVAPI WINBOOL WINAPI AddAccessAllowedAce(PACL pAcl,DWORD dwAceRevision,DWORD AccessMask,PSID pSid); - WINADVAPI WINBOOL WINAPI AddAccessAllowedAceEx(PACL pAcl,DWORD dwAceRevision,DWORD AceFlags,DWORD AccessMask,PSID pSid); - WINADVAPI WINBOOL WINAPI AddAccessDeniedAce(PACL pAcl,DWORD dwAceRevision,DWORD AccessMask,PSID pSid); - WINADVAPI WINBOOL WINAPI AddAccessDeniedAceEx(PACL pAcl,DWORD dwAceRevision,DWORD AceFlags,DWORD AccessMask,PSID pSid); - WINADVAPI WINBOOL WINAPI AddAuditAccessAce(PACL pAcl,DWORD dwAceRevision,DWORD dwAccessMask,PSID pSid,WINBOOL bAuditSuccess,WINBOOL bAuditFailure); - WINADVAPI WINBOOL WINAPI AddAuditAccessAceEx(PACL pAcl,DWORD dwAceRevision,DWORD AceFlags,DWORD dwAccessMask,PSID pSid,WINBOOL bAuditSuccess,WINBOOL bAuditFailure); - WINADVAPI WINBOOL WINAPI AddAccessAllowedObjectAce(PACL pAcl,DWORD dwAceRevision,DWORD AceFlags,DWORD AccessMask,GUID *ObjectTypeGuid,GUID *InheritedObjectTypeGuid,PSID pSid); - WINADVAPI WINBOOL WINAPI AddAccessDeniedObjectAce(PACL pAcl,DWORD dwAceRevision,DWORD AceFlags,DWORD AccessMask,GUID *ObjectTypeGuid,GUID *InheritedObjectTypeGuid,PSID pSid); - WINADVAPI WINBOOL WINAPI AddAuditAccessObjectAce(PACL pAcl,DWORD dwAceRevision,DWORD AceFlags,DWORD AccessMask,GUID *ObjectTypeGuid,GUID *InheritedObjectTypeGuid,PSID pSid,WINBOOL bAuditSuccess,WINBOOL bAuditFailure); - WINADVAPI WINBOOL WINAPI FindFirstFreeAce(PACL pAcl,LPVOID *pAce); - WINADVAPI WINBOOL WINAPI InitializeSecurityDescriptor(PSECURITY_DESCRIPTOR pSecurityDescriptor,DWORD dwRevision); - WINADVAPI WINBOOL WINAPI IsValidSecurityDescriptor(PSECURITY_DESCRIPTOR pSecurityDescriptor); - WINADVAPI DWORD WINAPI GetSecurityDescriptorLength(PSECURITY_DESCRIPTOR pSecurityDescriptor); - WINADVAPI WINBOOL WINAPI GetSecurityDescriptorControl(PSECURITY_DESCRIPTOR pSecurityDescriptor,PSECURITY_DESCRIPTOR_CONTROL pControl,LPDWORD lpdwRevision); - WINADVAPI WINBOOL WINAPI SetSecurityDescriptorControl(PSECURITY_DESCRIPTOR pSecurityDescriptor,SECURITY_DESCRIPTOR_CONTROL ControlBitsOfInterest,SECURITY_DESCRIPTOR_CONTROL ControlBitsToSet); - WINADVAPI WINBOOL WINAPI SetSecurityDescriptorDacl(PSECURITY_DESCRIPTOR pSecurityDescriptor,WINBOOL bDaclPresent,PACL pDacl,WINBOOL bDaclDefaulted); - WINADVAPI WINBOOL WINAPI GetSecurityDescriptorDacl(PSECURITY_DESCRIPTOR pSecurityDescriptor,LPBOOL lpbDaclPresent,PACL *pDacl,LPBOOL lpbDaclDefaulted); - WINADVAPI WINBOOL WINAPI SetSecurityDescriptorSacl(PSECURITY_DESCRIPTOR pSecurityDescriptor,WINBOOL bSaclPresent,PACL pSacl,WINBOOL bSaclDefaulted); - WINADVAPI WINBOOL WINAPI GetSecurityDescriptorSacl(PSECURITY_DESCRIPTOR pSecurityDescriptor,LPBOOL lpbSaclPresent,PACL *pSacl,LPBOOL lpbSaclDefaulted); - WINADVAPI WINBOOL WINAPI SetSecurityDescriptorOwner(PSECURITY_DESCRIPTOR pSecurityDescriptor,PSID pOwner,WINBOOL bOwnerDefaulted); - WINADVAPI WINBOOL WINAPI GetSecurityDescriptorOwner(PSECURITY_DESCRIPTOR pSecurityDescriptor,PSID *pOwner,LPBOOL lpbOwnerDefaulted); - WINADVAPI WINBOOL WINAPI SetSecurityDescriptorGroup(PSECURITY_DESCRIPTOR pSecurityDescriptor,PSID pGroup,WINBOOL bGroupDefaulted); - WINADVAPI WINBOOL WINAPI GetSecurityDescriptorGroup(PSECURITY_DESCRIPTOR pSecurityDescriptor,PSID *pGroup,LPBOOL lpbGroupDefaulted); - WINADVAPI DWORD WINAPI SetSecurityDescriptorRMControl(PSECURITY_DESCRIPTOR SecurityDescriptor,PUCHAR RMControl); - WINADVAPI DWORD WINAPI GetSecurityDescriptorRMControl(PSECURITY_DESCRIPTOR SecurityDescriptor,PUCHAR RMControl); - WINADVAPI WINBOOL WINAPI CreatePrivateObjectSecurity(PSECURITY_DESCRIPTOR ParentDescriptor,PSECURITY_DESCRIPTOR CreatorDescriptor,PSECURITY_DESCRIPTOR *NewDescriptor,WINBOOL IsDirectoryObject,HANDLE Token,PGENERIC_MAPPING GenericMapping); - WINADVAPI WINBOOL WINAPI ConvertToAutoInheritPrivateObjectSecurity(PSECURITY_DESCRIPTOR ParentDescriptor,PSECURITY_DESCRIPTOR CurrentSecurityDescriptor,PSECURITY_DESCRIPTOR *NewSecurityDescriptor,GUID *ObjectType,BOOLEAN IsDirectoryObject,PGENERIC_MAPPING GenericMapping); - WINADVAPI WINBOOL WINAPI CreatePrivateObjectSecurityEx(PSECURITY_DESCRIPTOR ParentDescriptor,PSECURITY_DESCRIPTOR CreatorDescriptor,PSECURITY_DESCRIPTOR *NewDescriptor,GUID *ObjectType,WINBOOL IsContainerObject,ULONG AutoInheritFlags,HANDLE Token,PGENERIC_MAPPING GenericMapping); - WINADVAPI WINBOOL WINAPI CreatePrivateObjectSecurityWithMultipleInheritance(PSECURITY_DESCRIPTOR ParentDescriptor,PSECURITY_DESCRIPTOR CreatorDescriptor,PSECURITY_DESCRIPTOR *NewDescriptor,GUID **ObjectTypes,ULONG GuidCount,WINBOOL IsContainerObject,ULONG AutoInheritFlags,HANDLE Token,PGENERIC_MAPPING GenericMapping); - WINADVAPI WINBOOL WINAPI SetPrivateObjectSecurity (SECURITY_INFORMATION SecurityInformation,PSECURITY_DESCRIPTOR ModificationDescriptor,PSECURITY_DESCRIPTOR *ObjectsSecurityDescriptor,PGENERIC_MAPPING GenericMapping,HANDLE Token); - WINADVAPI WINBOOL WINAPI SetPrivateObjectSecurityEx (SECURITY_INFORMATION SecurityInformation,PSECURITY_DESCRIPTOR ModificationDescriptor,PSECURITY_DESCRIPTOR *ObjectsSecurityDescriptor,ULONG AutoInheritFlags,PGENERIC_MAPPING GenericMapping,HANDLE Token); - WINADVAPI WINBOOL WINAPI GetPrivateObjectSecurity(PSECURITY_DESCRIPTOR ObjectDescriptor,SECURITY_INFORMATION SecurityInformation,PSECURITY_DESCRIPTOR ResultantDescriptor,DWORD DescriptorLength,PDWORD ReturnLength); - WINADVAPI WINBOOL WINAPI DestroyPrivateObjectSecurity(PSECURITY_DESCRIPTOR *ObjectDescriptor); - WINADVAPI WINBOOL WINAPI MakeSelfRelativeSD(PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor,PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor,LPDWORD lpdwBufferLength); - WINADVAPI WINBOOL WINAPI MakeAbsoluteSD(PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor,PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor,LPDWORD lpdwAbsoluteSecurityDescriptorSize,PACL pDacl,LPDWORD lpdwDaclSize,PACL pSacl,LPDWORD lpdwSaclSize,PSID pOwner,LPDWORD lpdwOwnerSize,PSID pPrimaryGroup,LPDWORD lpdwPrimaryGroupSize); - WINADVAPI WINBOOL WINAPI MakeAbsoluteSD2(PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor,LPDWORD lpdwBufferSize); - WINADVAPI WINBOOL WINAPI SetFileSecurityA(LPCSTR lpFileName,SECURITY_INFORMATION SecurityInformation,PSECURITY_DESCRIPTOR pSecurityDescriptor); - WINADVAPI WINBOOL WINAPI SetFileSecurityW(LPCWSTR lpFileName,SECURITY_INFORMATION SecurityInformation,PSECURITY_DESCRIPTOR pSecurityDescriptor); - WINADVAPI WINBOOL WINAPI GetFileSecurityA(LPCSTR lpFileName,SECURITY_INFORMATION RequestedInformation,PSECURITY_DESCRIPTOR pSecurityDescriptor,DWORD nLength,LPDWORD lpnLengthNeeded); - WINADVAPI WINBOOL WINAPI GetFileSecurityW(LPCWSTR lpFileName,SECURITY_INFORMATION RequestedInformation,PSECURITY_DESCRIPTOR pSecurityDescriptor,DWORD nLength,LPDWORD lpnLengthNeeded); - WINADVAPI WINBOOL WINAPI SetKernelObjectSecurity(HANDLE Handle,SECURITY_INFORMATION SecurityInformation,PSECURITY_DESCRIPTOR SecurityDescriptor); - WINBASEAPI HANDLE WINAPI FindFirstChangeNotificationA(LPCSTR lpPathName,WINBOOL bWatchSubtree,DWORD dwNotifyFilter); - WINBASEAPI HANDLE WINAPI FindFirstChangeNotificationW(LPCWSTR lpPathName,WINBOOL bWatchSubtree,DWORD dwNotifyFilter); - WINBASEAPI WINBOOL WINAPI FindNextChangeNotification(HANDLE hChangeHandle); - WINBASEAPI WINBOOL WINAPI FindCloseChangeNotification(HANDLE hChangeHandle); - WINBASEAPI WINBOOL WINAPI ReadDirectoryChangesW(HANDLE hDirectory,LPVOID lpBuffer,DWORD nBufferLength,WINBOOL bWatchSubtree,DWORD dwNotifyFilter,LPDWORD lpBytesReturned,LPOVERLAPPED lpOverlapped,LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine); - WINBASEAPI WINBOOL WINAPI VirtualLock(LPVOID lpAddress,SIZE_T dwSize); - WINBASEAPI WINBOOL WINAPI VirtualUnlock(LPVOID lpAddress,SIZE_T dwSize); - WINBASEAPI LPVOID WINAPI MapViewOfFileEx(HANDLE hFileMappingObject,DWORD dwDesiredAccess,DWORD dwFileOffsetHigh,DWORD dwFileOffsetLow,SIZE_T dwNumberOfBytesToMap,LPVOID lpBaseAddress); - WINBASEAPI WINBOOL WINAPI SetPriorityClass(HANDLE hProcess,DWORD dwPriorityClass); - WINBASEAPI DWORD WINAPI GetPriorityClass(HANDLE hProcess); - WINBASEAPI WINBOOL WINAPI IsBadReadPtr(CONST VOID *lp,UINT_PTR ucb); - WINBASEAPI WINBOOL WINAPI IsBadWritePtr(LPVOID lp,UINT_PTR ucb); - WINBASEAPI WINBOOL WINAPI IsBadHugeReadPtr(CONST VOID *lp,UINT_PTR ucb); - WINBASEAPI WINBOOL WINAPI IsBadHugeWritePtr(LPVOID lp,UINT_PTR ucb); - WINBASEAPI WINBOOL WINAPI IsBadCodePtr(FARPROC lpfn); - WINBASEAPI WINBOOL WINAPI IsBadStringPtrA(LPCSTR lpsz,UINT_PTR ucchMax); - WINBASEAPI WINBOOL WINAPI IsBadStringPtrW(LPCWSTR lpsz,UINT_PTR ucchMax); - WINADVAPI WINBOOL WINAPI LookupAccountSidA(LPCSTR lpSystemName,PSID Sid,LPSTR Name,LPDWORD cchName,LPSTR ReferencedDomainName,LPDWORD cchReferencedDomainName,PSID_NAME_USE peUse); - WINADVAPI WINBOOL WINAPI LookupAccountSidW(LPCWSTR lpSystemName,PSID Sid,LPWSTR Name,LPDWORD cchName,LPWSTR ReferencedDomainName,LPDWORD cchReferencedDomainName,PSID_NAME_USE peUse); - WINADVAPI WINBOOL WINAPI LookupAccountNameA(LPCSTR lpSystemName,LPCSTR lpAccountName,PSID Sid,LPDWORD cbSid,LPSTR ReferencedDomainName,LPDWORD cchReferencedDomainName,PSID_NAME_USE peUse); - WINADVAPI WINBOOL WINAPI LookupAccountNameW(LPCWSTR lpSystemName,LPCWSTR lpAccountName,PSID Sid,LPDWORD cbSid,LPWSTR ReferencedDomainName,LPDWORD cchReferencedDomainName,PSID_NAME_USE peUse); - WINADVAPI WINBOOL WINAPI LookupPrivilegeValueA(LPCSTR lpSystemName,LPCSTR lpName,PLUID lpLuid); - WINADVAPI WINBOOL WINAPI LookupPrivilegeValueW(LPCWSTR lpSystemName,LPCWSTR lpName,PLUID lpLuid); - WINADVAPI WINBOOL WINAPI LookupPrivilegeNameA(LPCSTR lpSystemName,PLUID lpLuid,LPSTR lpName,LPDWORD cchName); - WINADVAPI WINBOOL WINAPI LookupPrivilegeNameW(LPCWSTR lpSystemName,PLUID lpLuid,LPWSTR lpName,LPDWORD cchName); - WINADVAPI WINBOOL WINAPI LookupPrivilegeDisplayNameA(LPCSTR lpSystemName,LPCSTR lpName,LPSTR lpDisplayName,LPDWORD cchDisplayName,LPDWORD lpLanguageId); - WINADVAPI WINBOOL WINAPI LookupPrivilegeDisplayNameW(LPCWSTR lpSystemName,LPCWSTR lpName,LPWSTR lpDisplayName,LPDWORD cchDisplayName,LPDWORD lpLanguageId); - WINADVAPI WINBOOL WINAPI AllocateLocallyUniqueId(PLUID Luid); - WINBASEAPI WINBOOL WINAPI BuildCommDCBA(LPCSTR lpDef,LPDCB lpDCB); - WINBASEAPI WINBOOL WINAPI BuildCommDCBW(LPCWSTR lpDef,LPDCB lpDCB); - WINBASEAPI WINBOOL WINAPI BuildCommDCBAndTimeoutsA(LPCSTR lpDef,LPDCB lpDCB,LPCOMMTIMEOUTS lpCommTimeouts); - WINBASEAPI WINBOOL WINAPI BuildCommDCBAndTimeoutsW(LPCWSTR lpDef,LPDCB lpDCB,LPCOMMTIMEOUTS lpCommTimeouts); - WINBASEAPI WINBOOL WINAPI CommConfigDialogA(LPCSTR lpszName,HWND hWnd,LPCOMMCONFIG lpCC); - WINBASEAPI WINBOOL WINAPI CommConfigDialogW(LPCWSTR lpszName,HWND hWnd,LPCOMMCONFIG lpCC); - WINBASEAPI WINBOOL WINAPI GetDefaultCommConfigA(LPCSTR lpszName,LPCOMMCONFIG lpCC,LPDWORD lpdwSize); - WINBASEAPI WINBOOL WINAPI GetDefaultCommConfigW(LPCWSTR lpszName,LPCOMMCONFIG lpCC,LPDWORD lpdwSize); - WINBASEAPI WINBOOL WINAPI SetDefaultCommConfigA(LPCSTR lpszName,LPCOMMCONFIG lpCC,DWORD dwSize); - WINBASEAPI WINBOOL WINAPI SetDefaultCommConfigW(LPCWSTR lpszName,LPCOMMCONFIG lpCC,DWORD dwSize); - -#define MAX_COMPUTERNAME_LENGTH 15 - - WINBASEAPI WINBOOL WINAPI GetComputerNameA(LPSTR lpBuffer,LPDWORD nSize); - WINBASEAPI WINBOOL WINAPI GetComputerNameW(LPWSTR lpBuffer,LPDWORD nSize); - WINBASEAPI WINBOOL WINAPI SetComputerNameA(LPCSTR lpComputerName); - WINBASEAPI WINBOOL WINAPI SetComputerNameW(LPCWSTR lpComputerName); - - typedef enum _COMPUTER_NAME_FORMAT { - ComputerNameNetBIOS,ComputerNameDnsHostname,ComputerNameDnsDomain,ComputerNameDnsFullyQualified,ComputerNamePhysicalNetBIOS,ComputerNamePhysicalDnsHostname,ComputerNamePhysicalDnsDomain,ComputerNamePhysicalDnsFullyQualified,ComputerNameMax - } COMPUTER_NAME_FORMAT; - - WINBASEAPI WINBOOL WINAPI GetComputerNameExA(COMPUTER_NAME_FORMAT NameType,LPSTR lpBuffer,LPDWORD nSize); - WINBASEAPI WINBOOL WINAPI GetComputerNameExW(COMPUTER_NAME_FORMAT NameType,LPWSTR lpBuffer,LPDWORD nSize); - WINBASEAPI WINBOOL WINAPI SetComputerNameExA(COMPUTER_NAME_FORMAT NameType,LPCSTR lpBuffer); - WINBASEAPI WINBOOL WINAPI SetComputerNameExW(COMPUTER_NAME_FORMAT NameType,LPCWSTR lpBuffer); - WINBASEAPI WINBOOL WINAPI DnsHostnameToComputerNameA(LPCSTR Hostname,LPSTR ComputerName,LPDWORD nSize); - WINBASEAPI WINBOOL WINAPI DnsHostnameToComputerNameW(LPCWSTR Hostname,LPWSTR ComputerName,LPDWORD nSize); - WINADVAPI WINBOOL WINAPI GetUserNameA(LPSTR lpBuffer,LPDWORD pcbBuffer); - WINADVAPI WINBOOL WINAPI GetUserNameW(LPWSTR lpBuffer,LPDWORD pcbBuffer); - -#define LOGON32_LOGON_INTERACTIVE 2 -#define LOGON32_LOGON_NETWORK 3 -#define LOGON32_LOGON_BATCH 4 -#define LOGON32_LOGON_SERVICE 5 -#define LOGON32_LOGON_UNLOCK 7 -#define LOGON32_LOGON_NETWORK_CLEARTEXT 8 -#define LOGON32_LOGON_NEW_CREDENTIALS 9 - -#define LOGON32_PROVIDER_DEFAULT 0 -#define LOGON32_PROVIDER_WINNT35 1 -#define LOGON32_PROVIDER_WINNT40 2 -#define LOGON32_PROVIDER_WINNT50 3 - -#ifdef UNICODE -#define LogonUser LogonUserW -#define LogonUserEx LogonUserExW -#define CreateProcessAsUser CreateProcessAsUserW -#else -#define LogonUser LogonUserA -#define LogonUserEx LogonUserExA -#define CreateProcessAsUser CreateProcessAsUserA -#endif - - WINADVAPI WINBOOL WINAPI LogonUserA(LPCSTR lpszUsername,LPCSTR lpszDomain,LPCSTR lpszPassword,DWORD dwLogonType,DWORD dwLogonProvider,PHANDLE phToken); - WINADVAPI WINBOOL WINAPI LogonUserW(LPCWSTR lpszUsername,LPCWSTR lpszDomain,LPCWSTR lpszPassword,DWORD dwLogonType,DWORD dwLogonProvider,PHANDLE phToken); - WINADVAPI WINBOOL WINAPI LogonUserExA(LPCSTR lpszUsername,LPCSTR lpszDomain,LPCSTR lpszPassword,DWORD dwLogonType,DWORD dwLogonProvider,PHANDLE phToken,PSID *ppLogonSid,PVOID *ppProfileBuffer,LPDWORD pdwProfileLength,PQUOTA_LIMITS pQuotaLimits); - WINADVAPI WINBOOL WINAPI LogonUserExW(LPCWSTR lpszUsername,LPCWSTR lpszDomain,LPCWSTR lpszPassword,DWORD dwLogonType,DWORD dwLogonProvider,PHANDLE phToken,PSID *ppLogonSid,PVOID *ppProfileBuffer,LPDWORD pdwProfileLength,PQUOTA_LIMITS pQuotaLimits); - WINADVAPI WINBOOL WINAPI ImpersonateLoggedOnUser(HANDLE hToken); - WINADVAPI WINBOOL WINAPI CreateProcessAsUserA(HANDLE hToken,LPCSTR lpApplicationName,LPSTR lpCommandLine,LPSECURITY_ATTRIBUTES lpProcessAttributes,LPSECURITY_ATTRIBUTES lpThreadAttributes,WINBOOL bInheritHandles,DWORD dwCreationFlags,LPVOID lpEnvironment,LPCSTR lpCurrentDirectory,LPSTARTUPINFOA lpStartupInfo,LPPROCESS_INFORMATION lpProcessInformation); - WINADVAPI WINBOOL WINAPI CreateProcessAsUserW(HANDLE hToken,LPCWSTR lpApplicationName,LPWSTR lpCommandLine,LPSECURITY_ATTRIBUTES lpProcessAttributes,LPSECURITY_ATTRIBUTES lpThreadAttributes,WINBOOL bInheritHandles,DWORD dwCreationFlags,LPVOID lpEnvironment,LPCWSTR lpCurrentDirectory,LPSTARTUPINFOW lpStartupInfo,LPPROCESS_INFORMATION lpProcessInformation); - -#define LOGON_WITH_PROFILE 0x1 -#define LOGON_NETCREDENTIALS_ONLY 0x2 -#define LOGON_ZERO_PASSWORD_BUFFER 0x80000000 - - WINADVAPI WINBOOL WINAPI CreateProcessWithLogonW(LPCWSTR lpUsername,LPCWSTR lpDomain,LPCWSTR lpPassword,DWORD dwLogonFlags,LPCWSTR lpApplicationName,LPWSTR lpCommandLine,DWORD dwCreationFlags,LPVOID lpEnvironment,LPCWSTR lpCurrentDirectory,LPSTARTUPINFOW lpStartupInfo,LPPROCESS_INFORMATION lpProcessInformation); - WINADVAPI WINBOOL WINAPI CreateProcessWithTokenW(HANDLE hToken,DWORD dwLogonFlags,LPCWSTR lpApplicationName,LPWSTR lpCommandLine,DWORD dwCreationFlags,LPVOID lpEnvironment,LPCWSTR lpCurrentDirectory,LPSTARTUPINFOW lpStartupInfo,LPPROCESS_INFORMATION lpProcessInformation); - WINADVAPI WINBOOL WINAPI ImpersonateAnonymousToken(HANDLE ThreadHandle); - WINADVAPI WINBOOL WINAPI DuplicateTokenEx(HANDLE hExistingToken,DWORD dwDesiredAccess,LPSECURITY_ATTRIBUTES lpTokenAttributes,SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,TOKEN_TYPE TokenType,PHANDLE phNewToken); - WINADVAPI WINBOOL WINAPI CreateRestrictedToken(HANDLE ExistingTokenHandle,DWORD Flags,DWORD DisableSidCount,PSID_AND_ATTRIBUTES SidsToDisable,DWORD DeletePrivilegeCount,PLUID_AND_ATTRIBUTES PrivilegesToDelete,DWORD RestrictedSidCount,PSID_AND_ATTRIBUTES SidsToRestrict,PHANDLE NewTokenHandle); - WINADVAPI WINBOOL WINAPI IsTokenRestricted(HANDLE TokenHandle); - WINADVAPI WINBOOL WINAPI IsTokenUntrusted(HANDLE TokenHandle); - WINADVAPI WINBOOL WINAPI CheckTokenMembership(HANDLE TokenHandle,PSID SidToCheck,PBOOL IsMember); - - typedef WAITORTIMERCALLBACKFUNC WAITORTIMERCALLBACK; - - WINBASEAPI WINBOOL WINAPI RegisterWaitForSingleObject(PHANDLE phNewWaitObject,HANDLE hObject,WAITORTIMERCALLBACK Callback,PVOID Context,ULONG dwMilliseconds,ULONG dwFlags); - WINBASEAPI HANDLE WINAPI RegisterWaitForSingleObjectEx(HANDLE hObject,WAITORTIMERCALLBACK Callback,PVOID Context,ULONG dwMilliseconds,ULONG dwFlags); - WINBASEAPI WINBOOL WINAPI UnregisterWait(HANDLE WaitHandle); - WINBASEAPI WINBOOL WINAPI UnregisterWaitEx(HANDLE WaitHandle,HANDLE CompletionEvent); - WINBASEAPI WINBOOL WINAPI QueueUserWorkItem(LPTHREAD_START_ROUTINE Function,PVOID Context,ULONG Flags); - WINBASEAPI WINBOOL WINAPI BindIoCompletionCallback(HANDLE FileHandle,LPOVERLAPPED_COMPLETION_ROUTINE Function,ULONG Flags); - WINBASEAPI HANDLE WINAPI CreateTimerQueue(VOID); - WINBASEAPI WINBOOL WINAPI CreateTimerQueueTimer(PHANDLE phNewTimer,HANDLE TimerQueue,WAITORTIMERCALLBACK Callback,PVOID Parameter,DWORD DueTime,DWORD Period,ULONG Flags); - WINBASEAPI WINBOOL WINAPI ChangeTimerQueueTimer(HANDLE TimerQueue,HANDLE Timer,ULONG DueTime,ULONG Period); - WINBASEAPI WINBOOL WINAPI DeleteTimerQueueTimer(HANDLE TimerQueue,HANDLE Timer,HANDLE CompletionEvent); - WINBASEAPI WINBOOL WINAPI DeleteTimerQueueEx(HANDLE TimerQueue,HANDLE CompletionEvent); - WINBASEAPI HANDLE WINAPI SetTimerQueueTimer(HANDLE TimerQueue,WAITORTIMERCALLBACK Callback,PVOID Parameter,DWORD DueTime,DWORD Period,WINBOOL PreferIo); - WINBASEAPI WINBOOL WINAPI CancelTimerQueueTimer(HANDLE TimerQueue,HANDLE Timer); - WINBASEAPI WINBOOL WINAPI DeleteTimerQueue(HANDLE TimerQueue); - -#define HW_PROFILE_GUIDLEN 39 -#define MAX_PROFILE_LEN 80 - -#define DOCKINFO_UNDOCKED (0x1) -#define DOCKINFO_DOCKED (0x2) -#define DOCKINFO_USER_SUPPLIED (0x4) -#define DOCKINFO_USER_UNDOCKED (DOCKINFO_USER_SUPPLIED | DOCKINFO_UNDOCKED) -#define DOCKINFO_USER_DOCKED (DOCKINFO_USER_SUPPLIED | DOCKINFO_DOCKED) - - typedef struct tagHW_PROFILE_INFOA { - DWORD dwDockInfo; - CHAR szHwProfileGuid[HW_PROFILE_GUIDLEN]; - CHAR szHwProfileName[MAX_PROFILE_LEN]; - } HW_PROFILE_INFOA,*LPHW_PROFILE_INFOA; - - typedef struct tagHW_PROFILE_INFOW { - DWORD dwDockInfo; - WCHAR szHwProfileGuid[HW_PROFILE_GUIDLEN]; - WCHAR szHwProfileName[MAX_PROFILE_LEN]; - } HW_PROFILE_INFOW,*LPHW_PROFILE_INFOW; - -#ifdef UNICODE - typedef HW_PROFILE_INFOW HW_PROFILE_INFO; - typedef LPHW_PROFILE_INFOW LPHW_PROFILE_INFO; -#else - typedef HW_PROFILE_INFOA HW_PROFILE_INFO; - typedef LPHW_PROFILE_INFOA LPHW_PROFILE_INFO; -#endif - -#ifdef UNICODE -#define GetCurrentHwProfile GetCurrentHwProfileW -#define GetVersionEx GetVersionExW -#define VerifyVersionInfo VerifyVersionInfoW -#else -#define GetCurrentHwProfile GetCurrentHwProfileA -#define GetVersionEx GetVersionExA -#define VerifyVersionInfo VerifyVersionInfoA -#endif - - WINADVAPI WINBOOL WINAPI GetCurrentHwProfileA (LPHW_PROFILE_INFOA lpHwProfileInfo); - WINADVAPI WINBOOL WINAPI GetCurrentHwProfileW (LPHW_PROFILE_INFOW lpHwProfileInfo); - WINBASEAPI WINBOOL WINAPI QueryPerformanceCounter(LARGE_INTEGER *lpPerformanceCount); - WINBASEAPI WINBOOL WINAPI QueryPerformanceFrequency(LARGE_INTEGER *lpFrequency); - WINBASEAPI WINBOOL WINAPI GetVersionExA(LPOSVERSIONINFOA lpVersionInformation); - WINBASEAPI WINBOOL WINAPI GetVersionExW(LPOSVERSIONINFOW lpVersionInformation); - WINBASEAPI WINBOOL WINAPI VerifyVersionInfoA(LPOSVERSIONINFOEXA lpVersionInformation,DWORD dwTypeMask,DWORDLONG dwlConditionMask); - WINBASEAPI WINBOOL WINAPI VerifyVersionInfoW(LPOSVERSIONINFOEXW lpVersionInformation,DWORD dwTypeMask,DWORDLONG dwlConditionMask); - -#include - -#define TC_NORMAL 0 -#define TC_HARDERR 1 -#define TC_GP_TRAP 2 -#define TC_SIGNAL 3 - -#define AC_LINE_OFFLINE 0x0 -#define AC_LINE_ONLINE 0x1 -#define AC_LINE_BACKUP_POWER 0x2 -#define AC_LINE_UNKNOWN 0xff - -#define BATTERY_FLAG_HIGH 0x1 -#define BATTERY_FLAG_LOW 0x2 -#define BATTERY_FLAG_CRITICAL 0x4 -#define BATTERY_FLAG_CHARGING 0x8 -#define BATTERY_FLAG_NO_BATTERY 0x80 -#define BATTERY_FLAG_UNKNOWN 0xff - -#define BATTERY_PERCENTAGE_UNKNOWN 0xff - -#define BATTERY_LIFE_UNKNOWN 0xffffffff - - typedef struct _SYSTEM_POWER_STATUS { - BYTE ACLineStatus; - BYTE BatteryFlag; - BYTE BatteryLifePercent; - BYTE Reserved1; - DWORD BatteryLifeTime; - DWORD BatteryFullLifeTime; - } SYSTEM_POWER_STATUS,*LPSYSTEM_POWER_STATUS; - -#ifdef UNICODE -#define CreateJobObject CreateJobObjectW -#define OpenJobObject OpenJobObjectW -#define FindFirstVolume FindFirstVolumeW -#define FindNextVolume FindNextVolumeW -#define FindFirstVolumeMountPoint FindFirstVolumeMountPointW -#define FindNextVolumeMountPoint FindNextVolumeMountPointW -#define SetVolumeMountPoint SetVolumeMountPointW -#define DeleteVolumeMountPoint DeleteVolumeMountPointW -#define GetVolumeNameForVolumeMountPoint GetVolumeNameForVolumeMountPointW -#define GetVolumePathName GetVolumePathNameW -#define GetVolumePathNamesForVolumeName GetVolumePathNamesForVolumeNameW -#else -#define CreateJobObject CreateJobObjectA -#define OpenJobObject OpenJobObjectA -#define FindFirstVolume FindFirstVolumeA -#define FindNextVolume FindNextVolumeA -#define FindFirstVolumeMountPoint FindFirstVolumeMountPointA -#define FindNextVolumeMountPoint FindNextVolumeMountPointA -#define SetVolumeMountPoint SetVolumeMountPointA -#define DeleteVolumeMountPoint DeleteVolumeMountPointA -#define GetVolumeNameForVolumeMountPoint GetVolumeNameForVolumeMountPointA -#define GetVolumePathName GetVolumePathNameA -#define GetVolumePathNamesForVolumeName GetVolumePathNamesForVolumeNameA -#endif - - WINBOOL WINAPI GetSystemPowerStatus(LPSYSTEM_POWER_STATUS lpSystemPowerStatus); - WINBOOL WINAPI SetSystemPowerState(WINBOOL fSuspend,WINBOOL fForce); - WINBASEAPI WINBOOL WINAPI AllocateUserPhysicalPages(HANDLE hProcess,PULONG_PTR NumberOfPages,PULONG_PTR PageArray); - WINBASEAPI WINBOOL WINAPI FreeUserPhysicalPages(HANDLE hProcess,PULONG_PTR NumberOfPages,PULONG_PTR PageArray); - WINBASEAPI WINBOOL WINAPI MapUserPhysicalPages(PVOID VirtualAddress,ULONG_PTR NumberOfPages,PULONG_PTR PageArray); - WINBASEAPI WINBOOL WINAPI MapUserPhysicalPagesScatter(PVOID *VirtualAddresses,ULONG_PTR NumberOfPages,PULONG_PTR PageArray); - WINBASEAPI HANDLE WINAPI CreateJobObjectA(LPSECURITY_ATTRIBUTES lpJobAttributes,LPCSTR lpName); - WINBASEAPI HANDLE WINAPI CreateJobObjectW(LPSECURITY_ATTRIBUTES lpJobAttributes,LPCWSTR lpName); - WINBASEAPI HANDLE WINAPI OpenJobObjectA(DWORD dwDesiredAccess,WINBOOL bInheritHandle,LPCSTR lpName); - WINBASEAPI HANDLE WINAPI OpenJobObjectW(DWORD dwDesiredAccess,WINBOOL bInheritHandle,LPCWSTR lpName); - WINBASEAPI WINBOOL WINAPI AssignProcessToJobObject(HANDLE hJob,HANDLE hProcess); - WINBASEAPI WINBOOL WINAPI TerminateJobObject(HANDLE hJob,UINT uExitCode); - WINBASEAPI WINBOOL WINAPI QueryInformationJobObject(HANDLE hJob,JOBOBJECTINFOCLASS JobObjectInformationClass,LPVOID lpJobObjectInformation,DWORD cbJobObjectInformationLength,LPDWORD lpReturnLength); - WINBASEAPI WINBOOL WINAPI SetInformationJobObject(HANDLE hJob,JOBOBJECTINFOCLASS JobObjectInformationClass,LPVOID lpJobObjectInformation,DWORD cbJobObjectInformationLength); - WINBASEAPI WINBOOL WINAPI IsProcessInJob(HANDLE ProcessHandle,HANDLE JobHandle,PBOOL Result); - WINBASEAPI WINBOOL WINAPI CreateJobSet(ULONG NumJob,PJOB_SET_ARRAY UserJobSet,ULONG Flags); - WINBASEAPI PVOID WINAPI AddVectoredExceptionHandler (ULONG First,PVECTORED_EXCEPTION_HANDLER Handler); - WINBASEAPI ULONG WINAPI RemoveVectoredExceptionHandler(PVOID Handle); - WINBASEAPI PVOID WINAPI AddVectoredContinueHandler (ULONG First,PVECTORED_EXCEPTION_HANDLER Handler); - WINBASEAPI ULONG WINAPI RemoveVectoredContinueHandler(PVOID Handle); - WINBASEAPI HANDLE WINAPI FindFirstVolumeA(LPSTR lpszVolumeName,DWORD cchBufferLength); - WINBASEAPI HANDLE WINAPI FindFirstVolumeW(LPWSTR lpszVolumeName,DWORD cchBufferLength); - WINBASEAPI WINBOOL WINAPI FindNextVolumeA(HANDLE hFindVolume,LPSTR lpszVolumeName,DWORD cchBufferLength); - WINBASEAPI WINBOOL WINAPI FindNextVolumeW(HANDLE hFindVolume,LPWSTR lpszVolumeName,DWORD cchBufferLength); - WINBASEAPI WINBOOL WINAPI FindVolumeClose(HANDLE hFindVolume); - WINBASEAPI HANDLE WINAPI FindFirstVolumeMountPointA(LPCSTR lpszRootPathName,LPSTR lpszVolumeMountPoint,DWORD cchBufferLength); - WINBASEAPI HANDLE WINAPI FindFirstVolumeMountPointW(LPCWSTR lpszRootPathName,LPWSTR lpszVolumeMountPoint,DWORD cchBufferLength); - WINBASEAPI WINBOOL WINAPI FindNextVolumeMountPointA(HANDLE hFindVolumeMountPoint,LPSTR lpszVolumeMountPoint,DWORD cchBufferLength); - WINBASEAPI WINBOOL WINAPI FindNextVolumeMountPointW(HANDLE hFindVolumeMountPoint,LPWSTR lpszVolumeMountPoint,DWORD cchBufferLength); - WINBASEAPI WINBOOL WINAPI FindVolumeMountPointClose(HANDLE hFindVolumeMountPoint); - WINBASEAPI WINBOOL WINAPI SetVolumeMountPointA(LPCSTR lpszVolumeMountPoint,LPCSTR lpszVolumeName); - WINBASEAPI WINBOOL WINAPI SetVolumeMountPointW(LPCWSTR lpszVolumeMountPoint,LPCWSTR lpszVolumeName); - WINBASEAPI WINBOOL WINAPI DeleteVolumeMountPointA(LPCSTR lpszVolumeMountPoint); - WINBASEAPI WINBOOL WINAPI DeleteVolumeMountPointW(LPCWSTR lpszVolumeMountPoint); - WINBASEAPI WINBOOL WINAPI GetVolumeNameForVolumeMountPointA(LPCSTR lpszVolumeMountPoint,LPSTR lpszVolumeName,DWORD cchBufferLength); - WINBASEAPI WINBOOL WINAPI GetVolumeNameForVolumeMountPointW(LPCWSTR lpszVolumeMountPoint,LPWSTR lpszVolumeName,DWORD cchBufferLength); - WINBASEAPI WINBOOL WINAPI GetVolumePathNameA(LPCSTR lpszFileName,LPSTR lpszVolumePathName,DWORD cchBufferLength); - WINBASEAPI WINBOOL WINAPI GetVolumePathNameW(LPCWSTR lpszFileName,LPWSTR lpszVolumePathName,DWORD cchBufferLength); - WINBASEAPI WINBOOL WINAPI GetVolumePathNamesForVolumeNameA(LPCSTR lpszVolumeName,LPCH lpszVolumePathNames,DWORD cchBufferLength,PDWORD lpcchReturnLength); - WINBASEAPI WINBOOL WINAPI GetVolumePathNamesForVolumeNameW(LPCWSTR lpszVolumeName,LPWCH lpszVolumePathNames,DWORD cchBufferLength,PDWORD lpcchReturnLength); - -#define ACTCTX_FLAG_PROCESSOR_ARCHITECTURE_VALID 0x1 -#define ACTCTX_FLAG_LANGID_VALID 0x2 -#define ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID 0x4 -#define ACTCTX_FLAG_RESOURCE_NAME_VALID 0x8 -#define ACTCTX_FLAG_SET_PROCESS_DEFAULT 0x10 -#define ACTCTX_FLAG_APPLICATION_NAME_VALID 0x20 -#define ACTCTX_FLAG_SOURCE_IS_ASSEMBLYREF 0x40 -#define ACTCTX_FLAG_HMODULE_VALID 0x80 - - typedef struct tagACTCTXA { - ULONG cbSize; - DWORD dwFlags; - LPCSTR lpSource; - USHORT wProcessorArchitecture; - LANGID wLangId; - LPCSTR lpAssemblyDirectory; - LPCSTR lpResourceName; - LPCSTR lpApplicationName; - HMODULE hModule; - } ACTCTXA,*PACTCTXA; - - typedef struct tagACTCTXW { - ULONG cbSize; - DWORD dwFlags; - LPCWSTR lpSource; - USHORT wProcessorArchitecture; - LANGID wLangId; - LPCWSTR lpAssemblyDirectory; - LPCWSTR lpResourceName; - LPCWSTR lpApplicationName; - HMODULE hModule; - } ACTCTXW,*PACTCTXW; - - typedef const ACTCTXA *PCACTCTXA; - typedef const ACTCTXW *PCACTCTXW; - -#ifdef UNICODE - typedef ACTCTXW ACTCTX; - typedef PACTCTXW PACTCTX; - typedef PCACTCTXW PCACTCTX; -#else - typedef ACTCTXA ACTCTX; - typedef PACTCTXA PACTCTX; - typedef PCACTCTXA PCACTCTX; -#endif - -#ifdef UNICODE -#define CreateActCtx CreateActCtxW -#else -#define CreateActCtx CreateActCtxA -#endif - - WINBASEAPI HANDLE WINAPI CreateActCtxA(PCACTCTXA pActCtx); - WINBASEAPI HANDLE WINAPI CreateActCtxW(PCACTCTXW pActCtx); - WINBASEAPI VOID WINAPI AddRefActCtx(HANDLE hActCtx); - WINBASEAPI VOID WINAPI ReleaseActCtx(HANDLE hActCtx); - WINBASEAPI WINBOOL WINAPI ZombifyActCtx(HANDLE hActCtx); - WINBASEAPI WINBOOL WINAPI ActivateActCtx(HANDLE hActCtx,ULONG_PTR *lpCookie); - -#define DEACTIVATE_ACTCTX_FLAG_FORCE_EARLY_DEACTIVATION (0x1) - - WINBASEAPI WINBOOL WINAPI DeactivateActCtx(DWORD dwFlags,ULONG_PTR ulCookie); - WINBASEAPI WINBOOL WINAPI GetCurrentActCtx(HANDLE *lphActCtx); - - typedef struct tagACTCTX_SECTION_KEYED_DATA_2600 { - ULONG cbSize; - ULONG ulDataFormatVersion; - PVOID lpData; - ULONG ulLength; - PVOID lpSectionGlobalData; - ULONG ulSectionGlobalDataLength; - PVOID lpSectionBase; - ULONG ulSectionTotalLength; - HANDLE hActCtx; - ULONG ulAssemblyRosterIndex; - } ACTCTX_SECTION_KEYED_DATA_2600,*PACTCTX_SECTION_KEYED_DATA_2600; - - typedef const ACTCTX_SECTION_KEYED_DATA_2600 *PCACTCTX_SECTION_KEYED_DATA_2600; - - typedef struct tagACTCTX_SECTION_KEYED_DATA_ASSEMBLY_METADATA { - PVOID lpInformation; - PVOID lpSectionBase; - ULONG ulSectionLength; - PVOID lpSectionGlobalDataBase; - ULONG ulSectionGlobalDataLength; - } ACTCTX_SECTION_KEYED_DATA_ASSEMBLY_METADATA,*PACTCTX_SECTION_KEYED_DATA_ASSEMBLY_METADATA; - - typedef const ACTCTX_SECTION_KEYED_DATA_ASSEMBLY_METADATA *PCACTCTX_SECTION_KEYED_DATA_ASSEMBLY_METADATA; - - typedef struct tagACTCTX_SECTION_KEYED_DATA { - ULONG cbSize; - ULONG ulDataFormatVersion; - PVOID lpData; - ULONG ulLength; - PVOID lpSectionGlobalData; - ULONG ulSectionGlobalDataLength; - PVOID lpSectionBase; - ULONG ulSectionTotalLength; - HANDLE hActCtx; - ULONG ulAssemblyRosterIndex; - - ULONG ulFlags; - ACTCTX_SECTION_KEYED_DATA_ASSEMBLY_METADATA AssemblyMetadata; - } ACTCTX_SECTION_KEYED_DATA,*PACTCTX_SECTION_KEYED_DATA; - - typedef const ACTCTX_SECTION_KEYED_DATA *PCACTCTX_SECTION_KEYED_DATA; - -#define FIND_ACTCTX_SECTION_KEY_RETURN_HACTCTX 0x1 -#define FIND_ACTCTX_SECTION_KEY_RETURN_FLAGS 0x2 -#define FIND_ACTCTX_SECTION_KEY_RETURN_ASSEMBLY_METADATA 0x4 - -#ifdef UNICODE -#define FindActCtxSectionString FindActCtxSectionStringW -#else -#define FindActCtxSectionString FindActCtxSectionStringA -#endif - - WINBASEAPI WINBOOL WINAPI FindActCtxSectionStringA(DWORD dwFlags,const GUID *lpExtensionGuid,ULONG ulSectionId,LPCSTR lpStringToFind,PACTCTX_SECTION_KEYED_DATA ReturnedData); - WINBASEAPI WINBOOL WINAPI FindActCtxSectionStringW(DWORD dwFlags,const GUID *lpExtensionGuid,ULONG ulSectionId,LPCWSTR lpStringToFind,PACTCTX_SECTION_KEYED_DATA ReturnedData); - WINBASEAPI WINBOOL WINAPI FindActCtxSectionGuid(DWORD dwFlags,const GUID *lpExtensionGuid,ULONG ulSectionId,const GUID *lpGuidToFind,PACTCTX_SECTION_KEYED_DATA ReturnedData); - -#ifndef RC_INVOKED -#ifndef ACTIVATION_CONTEXT_BASIC_INFORMATION_DEFINED - - typedef struct _ACTIVATION_CONTEXT_BASIC_INFORMATION { - HANDLE hActCtx; - DWORD dwFlags; - } ACTIVATION_CONTEXT_BASIC_INFORMATION,*PACTIVATION_CONTEXT_BASIC_INFORMATION; - - typedef const struct _ACTIVATION_CONTEXT_BASIC_INFORMATION *PCACTIVATION_CONTEXT_BASIC_INFORMATION; - -#define ACTIVATION_CONTEXT_BASIC_INFORMATION_DEFINED 1 -#endif -#endif - -#define QUERY_ACTCTX_FLAG_USE_ACTIVE_ACTCTX 0x4 -#define QUERY_ACTCTX_FLAG_ACTCTX_IS_HMODULE 0x8 -#define QUERY_ACTCTX_FLAG_ACTCTX_IS_ADDRESS 0x10 -#define QUERY_ACTCTX_FLAG_NO_ADDREF 0x80000000 - - WINBASEAPI WINBOOL WINAPI QueryActCtxW(DWORD dwFlags,HANDLE hActCtx,PVOID pvSubInstance,ULONG ulInfoClass,PVOID pvBuffer,SIZE_T cbBuffer,SIZE_T *pcbWrittenOrRequired); - - typedef WINBOOL (WINAPI *PQUERYACTCTXW_FUNC)(DWORD dwFlags,HANDLE hActCtx,PVOID pvSubInstance,ULONG ulInfoClass,PVOID pvBuffer,SIZE_T cbBuffer,SIZE_T *pcbWrittenOrRequired); - - WINBASEAPI WINBOOL WINAPI ProcessIdToSessionId(DWORD dwProcessId,DWORD *pSessionId); - WINBASEAPI DWORD WINAPI WTSGetActiveConsoleSessionId(); - WINBASEAPI WINBOOL WINAPI IsWow64Process(HANDLE hProcess,PBOOL Wow64Process); - WINBASEAPI WINBOOL WINAPI GetLogicalProcessorInformation(PSYSTEM_LOGICAL_PROCESSOR_INFORMATION Buffer,PDWORD ReturnedLength); - WINBASEAPI WINBOOL WINAPI GetNumaHighestNodeNumber(PULONG HighestNodeNumber); - WINBASEAPI WINBOOL WINAPI GetNumaProcessorNode(UCHAR Processor,PUCHAR NodeNumber); - WINBASEAPI WINBOOL WINAPI GetNumaNodeProcessorMask(UCHAR Node,PULONGLONG ProcessorMask); - WINBASEAPI WINBOOL WINAPI GetNumaAvailableMemoryNode(UCHAR Node,PULONGLONG AvailableBytes); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/05/tcc-final-old/win32/include/winapi/wincon.h b/05/tcc-final-old/win32/include/winapi/wincon.h deleted file mode 100644 index a3501ee..0000000 --- a/05/tcc-final-old/win32/include/winapi/wincon.h +++ /dev/null @@ -1,301 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _WINCON_ -#define _WINCON_ - -#ifdef __cplusplus -extern "C" { -#endif - - typedef struct _COORD { - SHORT X; - SHORT Y; - } COORD,*PCOORD; - - typedef struct _SMALL_RECT { - SHORT Left; - SHORT Top; - SHORT Right; - SHORT Bottom; - } SMALL_RECT,*PSMALL_RECT; - - typedef struct _KEY_EVENT_RECORD { - WINBOOL bKeyDown; - WORD wRepeatCount; - WORD wVirtualKeyCode; - WORD wVirtualScanCode; - union { - WCHAR UnicodeChar; - CHAR AsciiChar; - } uChar; - DWORD dwControlKeyState; - } KEY_EVENT_RECORD,*PKEY_EVENT_RECORD; - -#define RIGHT_ALT_PRESSED 0x1 -#define LEFT_ALT_PRESSED 0x2 -#define RIGHT_CTRL_PRESSED 0x4 -#define LEFT_CTRL_PRESSED 0x8 -#define SHIFT_PRESSED 0x10 -#define NUMLOCK_ON 0x20 -#define SCROLLLOCK_ON 0x40 -#define CAPSLOCK_ON 0x80 -#define ENHANCED_KEY 0x100 -#define NLS_DBCSCHAR 0x10000 -#define NLS_ALPHANUMERIC 0x0 -#define NLS_KATAKANA 0x20000 -#define NLS_HIRAGANA 0x40000 -#define NLS_ROMAN 0x400000 -#define NLS_IME_CONVERSION 0x800000 -#define NLS_IME_DISABLE 0x20000000 - - typedef struct _MOUSE_EVENT_RECORD { - COORD dwMousePosition; - DWORD dwButtonState; - DWORD dwControlKeyState; - DWORD dwEventFlags; - } MOUSE_EVENT_RECORD,*PMOUSE_EVENT_RECORD; - -#define FROM_LEFT_1ST_BUTTON_PRESSED 0x1 -#define RIGHTMOST_BUTTON_PRESSED 0x2 -#define FROM_LEFT_2ND_BUTTON_PRESSED 0x4 -#define FROM_LEFT_3RD_BUTTON_PRESSED 0x8 -#define FROM_LEFT_4TH_BUTTON_PRESSED 0x10 - -#define MOUSE_MOVED 0x1 -#define DOUBLE_CLICK 0x2 -#define MOUSE_WHEELED 0x4 - - typedef struct _WINDOW_BUFFER_SIZE_RECORD { - COORD dwSize; - } WINDOW_BUFFER_SIZE_RECORD,*PWINDOW_BUFFER_SIZE_RECORD; - - typedef struct _MENU_EVENT_RECORD { - UINT dwCommandId; - } MENU_EVENT_RECORD,*PMENU_EVENT_RECORD; - - typedef struct _FOCUS_EVENT_RECORD { - WINBOOL bSetFocus; - } FOCUS_EVENT_RECORD,*PFOCUS_EVENT_RECORD; - - typedef struct _INPUT_RECORD { - WORD EventType; - union { - KEY_EVENT_RECORD KeyEvent; - MOUSE_EVENT_RECORD MouseEvent; - WINDOW_BUFFER_SIZE_RECORD WindowBufferSizeEvent; - MENU_EVENT_RECORD MenuEvent; - FOCUS_EVENT_RECORD FocusEvent; - } Event; - } INPUT_RECORD,*PINPUT_RECORD; - -#define KEY_EVENT 0x1 -#define MOUSE_EVENT 0x2 -#define WINDOW_BUFFER_SIZE_EVENT 0x4 -#define MENU_EVENT 0x8 -#define FOCUS_EVENT 0x10 - - typedef struct _CHAR_INFO { - union { - WCHAR UnicodeChar; - CHAR AsciiChar; - } Char; - WORD Attributes; - } CHAR_INFO,*PCHAR_INFO; - -#define FOREGROUND_BLUE 0x1 -#define FOREGROUND_GREEN 0x2 -#define FOREGROUND_RED 0x4 -#define FOREGROUND_INTENSITY 0x8 -#define BACKGROUND_BLUE 0x10 -#define BACKGROUND_GREEN 0x20 -#define BACKGROUND_RED 0x40 -#define BACKGROUND_INTENSITY 0x80 -#define COMMON_LVB_LEADING_BYTE 0x100 -#define COMMON_LVB_TRAILING_BYTE 0x200 -#define COMMON_LVB_GRID_HORIZONTAL 0x400 -#define COMMON_LVB_GRID_LVERTICAL 0x800 -#define COMMON_LVB_GRID_RVERTICAL 0x1000 -#define COMMON_LVB_REVERSE_VIDEO 0x4000 -#define COMMON_LVB_UNDERSCORE 0x8000 - -#define COMMON_LVB_SBCSDBCS 0x300 - - typedef struct _CONSOLE_SCREEN_BUFFER_INFO { - COORD dwSize; - COORD dwCursorPosition; - WORD wAttributes; - SMALL_RECT srWindow; - COORD dwMaximumWindowSize; - } CONSOLE_SCREEN_BUFFER_INFO,*PCONSOLE_SCREEN_BUFFER_INFO; - - typedef struct _CONSOLE_CURSOR_INFO { - DWORD dwSize; - WINBOOL bVisible; - } CONSOLE_CURSOR_INFO,*PCONSOLE_CURSOR_INFO; - - typedef struct _CONSOLE_FONT_INFO { - DWORD nFont; - COORD dwFontSize; - } CONSOLE_FONT_INFO,*PCONSOLE_FONT_INFO; - - typedef struct _CONSOLE_SELECTION_INFO { - DWORD dwFlags; - COORD dwSelectionAnchor; - SMALL_RECT srSelection; - } CONSOLE_SELECTION_INFO,*PCONSOLE_SELECTION_INFO; - -#define CONSOLE_NO_SELECTION 0x0 -#define CONSOLE_SELECTION_IN_PROGRESS 0x1 -#define CONSOLE_SELECTION_NOT_EMPTY 0x2 -#define CONSOLE_MOUSE_SELECTION 0x4 -#define CONSOLE_MOUSE_DOWN 0x8 - - typedef WINBOOL (WINAPI *PHANDLER_ROUTINE)(DWORD CtrlType); - -#define CTRL_C_EVENT 0 -#define CTRL_BREAK_EVENT 1 -#define CTRL_CLOSE_EVENT 2 - -#define CTRL_LOGOFF_EVENT 5 -#define CTRL_SHUTDOWN_EVENT 6 - -#define ENABLE_PROCESSED_INPUT 0x1 -#define ENABLE_LINE_INPUT 0x2 -#define ENABLE_ECHO_INPUT 0x4 -#define ENABLE_WINDOW_INPUT 0x8 -#define ENABLE_MOUSE_INPUT 0x10 - -#define ENABLE_PROCESSED_OUTPUT 0x1 -#define ENABLE_WRAP_AT_EOL_OUTPUT 0x2 - -#ifdef UNICODE -#define PeekConsoleInput PeekConsoleInputW -#define ReadConsoleInput ReadConsoleInputW -#define WriteConsoleInput WriteConsoleInputW -#define ReadConsoleOutput ReadConsoleOutputW -#define WriteConsoleOutput WriteConsoleOutputW -#define ReadConsoleOutputCharacter ReadConsoleOutputCharacterW -#define WriteConsoleOutputCharacter WriteConsoleOutputCharacterW -#define FillConsoleOutputCharacter FillConsoleOutputCharacterW -#define ScrollConsoleScreenBuffer ScrollConsoleScreenBufferW -#define GetConsoleTitle GetConsoleTitleW -#define SetConsoleTitle SetConsoleTitleW -#define ReadConsole ReadConsoleW -#define WriteConsole WriteConsoleW -#define AddConsoleAlias AddConsoleAliasW -#define GetConsoleAlias GetConsoleAliasW -#define GetConsoleAliasesLength GetConsoleAliasesLengthW -#define GetConsoleAliasExesLength GetConsoleAliasExesLengthW -#define GetConsoleAliases GetConsoleAliasesW -#define GetConsoleAliasExes GetConsoleAliasExesW -#else -#define PeekConsoleInput PeekConsoleInputA -#define ReadConsoleInput ReadConsoleInputA -#define WriteConsoleInput WriteConsoleInputA -#define ReadConsoleOutput ReadConsoleOutputA -#define WriteConsoleOutput WriteConsoleOutputA -#define ReadConsoleOutputCharacter ReadConsoleOutputCharacterA -#define WriteConsoleOutputCharacter WriteConsoleOutputCharacterA -#define FillConsoleOutputCharacter FillConsoleOutputCharacterA -#define ScrollConsoleScreenBuffer ScrollConsoleScreenBufferA -#define GetConsoleTitle GetConsoleTitleA -#define SetConsoleTitle SetConsoleTitleA -#define ReadConsole ReadConsoleA -#define WriteConsole WriteConsoleA -#define AddConsoleAlias AddConsoleAliasA -#define GetConsoleAlias GetConsoleAliasA -#define GetConsoleAliasesLength GetConsoleAliasesLengthA -#define GetConsoleAliasExesLength GetConsoleAliasExesLengthA -#define GetConsoleAliases GetConsoleAliasesA -#define GetConsoleAliasExes GetConsoleAliasExesA -#endif - - WINBASEAPI WINBOOL WINAPI PeekConsoleInputA(HANDLE hConsoleInput,PINPUT_RECORD lpBuffer,DWORD nLength,LPDWORD lpNumberOfEventsRead); - WINBASEAPI WINBOOL WINAPI PeekConsoleInputW(HANDLE hConsoleInput,PINPUT_RECORD lpBuffer,DWORD nLength,LPDWORD lpNumberOfEventsRead); - WINBASEAPI WINBOOL WINAPI ReadConsoleInputA(HANDLE hConsoleInput,PINPUT_RECORD lpBuffer,DWORD nLength,LPDWORD lpNumberOfEventsRead); - WINBASEAPI WINBOOL WINAPI ReadConsoleInputW(HANDLE hConsoleInput,PINPUT_RECORD lpBuffer,DWORD nLength,LPDWORD lpNumberOfEventsRead); - WINBASEAPI WINBOOL WINAPI WriteConsoleInputA(HANDLE hConsoleInput,CONST INPUT_RECORD *lpBuffer,DWORD nLength,LPDWORD lpNumberOfEventsWritten); - WINBASEAPI WINBOOL WINAPI WriteConsoleInputW(HANDLE hConsoleInput,CONST INPUT_RECORD *lpBuffer,DWORD nLength,LPDWORD lpNumberOfEventsWritten); - WINBASEAPI WINBOOL WINAPI ReadConsoleOutputA(HANDLE hConsoleOutput,PCHAR_INFO lpBuffer,COORD dwBufferSize,COORD dwBufferCoord,PSMALL_RECT lpReadRegion); - WINBASEAPI WINBOOL WINAPI ReadConsoleOutputW(HANDLE hConsoleOutput,PCHAR_INFO lpBuffer,COORD dwBufferSize,COORD dwBufferCoord,PSMALL_RECT lpReadRegion); - WINBASEAPI WINBOOL WINAPI WriteConsoleOutputA(HANDLE hConsoleOutput,CONST CHAR_INFO *lpBuffer,COORD dwBufferSize,COORD dwBufferCoord,PSMALL_RECT lpWriteRegion); - WINBASEAPI WINBOOL WINAPI WriteConsoleOutputW(HANDLE hConsoleOutput,CONST CHAR_INFO *lpBuffer,COORD dwBufferSize,COORD dwBufferCoord,PSMALL_RECT lpWriteRegion); - WINBASEAPI WINBOOL WINAPI ReadConsoleOutputCharacterA(HANDLE hConsoleOutput,LPSTR lpCharacter,DWORD nLength,COORD dwReadCoord,LPDWORD lpNumberOfCharsRead); - WINBASEAPI WINBOOL WINAPI ReadConsoleOutputCharacterW(HANDLE hConsoleOutput,LPWSTR lpCharacter,DWORD nLength,COORD dwReadCoord,LPDWORD lpNumberOfCharsRead); - WINBASEAPI WINBOOL WINAPI ReadConsoleOutputAttribute(HANDLE hConsoleOutput,LPWORD lpAttribute,DWORD nLength,COORD dwReadCoord,LPDWORD lpNumberOfAttrsRead); - WINBASEAPI WINBOOL WINAPI WriteConsoleOutputCharacterA(HANDLE hConsoleOutput,LPCSTR lpCharacter,DWORD nLength,COORD dwWriteCoord,LPDWORD lpNumberOfCharsWritten); - WINBASEAPI WINBOOL WINAPI WriteConsoleOutputCharacterW(HANDLE hConsoleOutput,LPCWSTR lpCharacter,DWORD nLength,COORD dwWriteCoord,LPDWORD lpNumberOfCharsWritten); - WINBASEAPI WINBOOL WINAPI WriteConsoleOutputAttribute(HANDLE hConsoleOutput,CONST WORD *lpAttribute,DWORD nLength,COORD dwWriteCoord,LPDWORD lpNumberOfAttrsWritten); - WINBASEAPI WINBOOL WINAPI FillConsoleOutputCharacterA(HANDLE hConsoleOutput,CHAR cCharacter,DWORD nLength,COORD dwWriteCoord,LPDWORD lpNumberOfCharsWritten); - WINBASEAPI WINBOOL WINAPI FillConsoleOutputCharacterW(HANDLE hConsoleOutput,WCHAR cCharacter,DWORD nLength,COORD dwWriteCoord,LPDWORD lpNumberOfCharsWritten); - WINBASEAPI WINBOOL WINAPI FillConsoleOutputAttribute(HANDLE hConsoleOutput,WORD wAttribute,DWORD nLength,COORD dwWriteCoord,LPDWORD lpNumberOfAttrsWritten); - WINBASEAPI WINBOOL WINAPI GetConsoleMode(HANDLE hConsoleHandle,LPDWORD lpMode); - WINBASEAPI WINBOOL WINAPI GetNumberOfConsoleInputEvents(HANDLE hConsoleInput,LPDWORD lpNumberOfEvents); - WINBASEAPI WINBOOL WINAPI GetConsoleScreenBufferInfo(HANDLE hConsoleOutput,PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo); - WINBASEAPI COORD WINAPI GetLargestConsoleWindowSize(HANDLE hConsoleOutput); - WINBASEAPI WINBOOL WINAPI GetConsoleCursorInfo(HANDLE hConsoleOutput,PCONSOLE_CURSOR_INFO lpConsoleCursorInfo); - WINBASEAPI WINBOOL WINAPI GetCurrentConsoleFont(HANDLE hConsoleOutput,WINBOOL bMaximumWindow,PCONSOLE_FONT_INFO lpConsoleCurrentFont); - WINBASEAPI COORD WINAPI GetConsoleFontSize(HANDLE hConsoleOutput,DWORD nFont); - WINBASEAPI WINBOOL WINAPI GetConsoleSelectionInfo(PCONSOLE_SELECTION_INFO lpConsoleSelectionInfo); - WINBASEAPI WINBOOL WINAPI GetNumberOfConsoleMouseButtons(LPDWORD lpNumberOfMouseButtons); - WINBASEAPI WINBOOL WINAPI SetConsoleMode(HANDLE hConsoleHandle,DWORD dwMode); - WINBASEAPI WINBOOL WINAPI SetConsoleActiveScreenBuffer(HANDLE hConsoleOutput); - WINBASEAPI WINBOOL WINAPI FlushConsoleInputBuffer(HANDLE hConsoleInput); - WINBASEAPI WINBOOL WINAPI SetConsoleScreenBufferSize(HANDLE hConsoleOutput,COORD dwSize); - WINBASEAPI WINBOOL WINAPI SetConsoleCursorPosition(HANDLE hConsoleOutput,COORD dwCursorPosition); - WINBASEAPI WINBOOL WINAPI SetConsoleCursorInfo(HANDLE hConsoleOutput,CONST CONSOLE_CURSOR_INFO *lpConsoleCursorInfo); - WINBASEAPI WINBOOL WINAPI ScrollConsoleScreenBufferA(HANDLE hConsoleOutput,CONST SMALL_RECT *lpScrollRectangle,CONST SMALL_RECT *lpClipRectangle,COORD dwDestinationOrigin,CONST CHAR_INFO *lpFill); - WINBASEAPI WINBOOL WINAPI ScrollConsoleScreenBufferW(HANDLE hConsoleOutput,CONST SMALL_RECT *lpScrollRectangle,CONST SMALL_RECT *lpClipRectangle,COORD dwDestinationOrigin,CONST CHAR_INFO *lpFill); - WINBASEAPI WINBOOL WINAPI SetConsoleWindowInfo(HANDLE hConsoleOutput,WINBOOL bAbsolute,CONST SMALL_RECT *lpConsoleWindow); - WINBASEAPI WINBOOL WINAPI SetConsoleTextAttribute(HANDLE hConsoleOutput,WORD wAttributes); - WINBASEAPI WINBOOL WINAPI SetConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine,WINBOOL Add); - WINBASEAPI WINBOOL WINAPI GenerateConsoleCtrlEvent(DWORD dwCtrlEvent,DWORD dwProcessGroupId); - WINBASEAPI WINBOOL WINAPI AllocConsole(VOID); - WINBASEAPI WINBOOL WINAPI FreeConsole(VOID); - WINBASEAPI WINBOOL WINAPI AttachConsole(DWORD dwProcessId); - -#define ATTACH_PARENT_PROCESS ((DWORD)-1) - - WINBASEAPI DWORD WINAPI GetConsoleTitleA(LPSTR lpConsoleTitle,DWORD nSize); - WINBASEAPI DWORD WINAPI GetConsoleTitleW(LPWSTR lpConsoleTitle,DWORD nSize); - WINBASEAPI WINBOOL WINAPI SetConsoleTitleA(LPCSTR lpConsoleTitle); - WINBASEAPI WINBOOL WINAPI SetConsoleTitleW(LPCWSTR lpConsoleTitle); - WINBASEAPI WINBOOL WINAPI ReadConsoleA(HANDLE hConsoleInput,LPVOID lpBuffer,DWORD nNumberOfCharsToRead,LPDWORD lpNumberOfCharsRead,LPVOID lpReserved); - WINBASEAPI WINBOOL WINAPI ReadConsoleW(HANDLE hConsoleInput,LPVOID lpBuffer,DWORD nNumberOfCharsToRead,LPDWORD lpNumberOfCharsRead,LPVOID lpReserved); - WINBASEAPI WINBOOL WINAPI WriteConsoleA(HANDLE hConsoleOutput,CONST VOID *lpBuffer,DWORD nNumberOfCharsToWrite,LPDWORD lpNumberOfCharsWritten,LPVOID lpReserved); - WINBASEAPI WINBOOL WINAPI WriteConsoleW(HANDLE hConsoleOutput,CONST VOID *lpBuffer,DWORD nNumberOfCharsToWrite,LPDWORD lpNumberOfCharsWritten,LPVOID lpReserved); - -#define CONSOLE_TEXTMODE_BUFFER 1 - - WINBASEAPI HANDLE WINAPI CreateConsoleScreenBuffer(DWORD dwDesiredAccess,DWORD dwShareMode,CONST SECURITY_ATTRIBUTES *lpSecurityAttributes,DWORD dwFlags,LPVOID lpScreenBufferData); - WINBASEAPI UINT WINAPI GetConsoleCP(VOID); - WINBASEAPI WINBOOL WINAPI SetConsoleCP(UINT wCodePageID); - WINBASEAPI UINT WINAPI GetConsoleOutputCP(VOID); - WINBASEAPI WINBOOL WINAPI SetConsoleOutputCP(UINT wCodePageID); - -#define CONSOLE_FULLSCREEN 1 -#define CONSOLE_FULLSCREEN_HARDWARE 2 - - WINBASEAPI WINBOOL WINAPI GetConsoleDisplayMode(LPDWORD lpModeFlags); - WINBASEAPI HWND WINAPI GetConsoleWindow(VOID); - WINBASEAPI DWORD WINAPI GetConsoleProcessList(LPDWORD lpdwProcessList,DWORD dwProcessCount); - WINBASEAPI WINBOOL WINAPI AddConsoleAliasA(LPSTR Source,LPSTR Target,LPSTR ExeName); - WINBASEAPI WINBOOL WINAPI AddConsoleAliasW(LPWSTR Source,LPWSTR Target,LPWSTR ExeName); - WINBASEAPI DWORD WINAPI GetConsoleAliasA(LPSTR Source,LPSTR TargetBuffer,DWORD TargetBufferLength,LPSTR ExeName); - WINBASEAPI DWORD WINAPI GetConsoleAliasW(LPWSTR Source,LPWSTR TargetBuffer,DWORD TargetBufferLength,LPWSTR ExeName); - WINBASEAPI DWORD WINAPI GetConsoleAliasesLengthA(LPSTR ExeName); - WINBASEAPI DWORD WINAPI GetConsoleAliasesLengthW(LPWSTR ExeName); - WINBASEAPI DWORD WINAPI GetConsoleAliasExesLengthA(VOID); - WINBASEAPI DWORD WINAPI GetConsoleAliasExesLengthW(VOID); - WINBASEAPI DWORD WINAPI GetConsoleAliasesA(LPSTR AliasBuffer,DWORD AliasBufferLength,LPSTR ExeName); - WINBASEAPI DWORD WINAPI GetConsoleAliasesW(LPWSTR AliasBuffer,DWORD AliasBufferLength,LPWSTR ExeName); - WINBASEAPI DWORD WINAPI GetConsoleAliasExesA(LPSTR ExeNameBuffer,DWORD ExeNameBufferLength); - WINBASEAPI DWORD WINAPI GetConsoleAliasExesW(LPWSTR ExeNameBuffer,DWORD ExeNameBufferLength); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/05/tcc-final-old/win32/include/winapi/windef.h b/05/tcc-final-old/win32/include/winapi/windef.h deleted file mode 100644 index d63bdef..0000000 --- a/05/tcc-final-old/win32/include/winapi/windef.h +++ /dev/null @@ -1,293 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _WINDEF_ -#define _WINDEF_ - -#ifndef STRICT -#define STRICT 1 -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef WINVER -#define WINVER 0x0502 -#endif - -#ifndef BASETYPES -#define BASETYPES - typedef unsigned long ULONG; - typedef ULONG *PULONG; - typedef unsigned short USHORT; - typedef USHORT *PUSHORT; - typedef unsigned char UCHAR; - typedef UCHAR *PUCHAR; - typedef char *PSZ; -#endif - -#define MAX_PATH 260 - -#ifndef NULL -#ifdef __cplusplus -#define NULL 0 -#else -#define NULL ((void *)0) -#endif -#endif - -#ifndef FALSE -#define FALSE 0 -#endif - -#ifndef TRUE -#define TRUE 1 -#endif - -#ifndef IN -#define IN -#endif - -#ifndef OUT -#define OUT -#endif - -#ifndef OPTIONAL -#define OPTIONAL -#endif - -#undef far -#undef near -#undef pascal - -#define far -#define near -#define pascal __stdcall - -#define cdecl -#ifndef CDECL -#define CDECL -#endif -#ifndef CALLBACK -#define CALLBACK __stdcall -#endif -#ifndef WINAPI -#define WINAPI __stdcall -#endif -#define WINAPIV __cdecl -#define APIENTRY WINAPI -#define APIPRIVATE WINAPI -#define PASCAL WINAPI -#define WINAPI_INLINE WINAPI - -#undef FAR -#undef NEAR -#define FAR -#define NEAR -#ifndef CONST -#define CONST const -#endif - - typedef unsigned long DWORD; - typedef int WINBOOL; -#define BOOL WINBOOL - typedef unsigned char BYTE; - typedef unsigned short WORD; - typedef float FLOAT; - typedef FLOAT *PFLOAT; - typedef WINBOOL *PBOOL; - typedef WINBOOL *LPBOOL; - typedef BYTE *PBYTE; - typedef BYTE *LPBYTE; - typedef int *PINT; - typedef int *LPINT; - typedef WORD *PWORD; - typedef WORD *LPWORD; - typedef long *LPLONG; - typedef DWORD *PDWORD; - typedef DWORD *LPDWORD; - typedef void *LPVOID; -# ifndef _LPCVOID_DEFINED -#define _LPCVOID_DEFINED -typedef CONST void *LPCVOID; -#endif - typedef int INT; - typedef unsigned int UINT; - typedef unsigned int *PUINT; - -#ifndef NT_INCLUDED -#include -#endif - -//gr #include - - typedef UINT_PTR WPARAM; - typedef LONG_PTR LPARAM; - typedef LONG_PTR LRESULT; - -#ifndef __cplusplus -#ifndef NOMINMAX -#ifndef max -#define max(a,b) (((a) > (b)) ? (a) : (b)) -#endif - -#ifndef min -#define min(a,b) (((a) < (b)) ? (a) : (b)) -#endif -#endif -#endif - -#define MAKEWORD(a,b) ((WORD)(((BYTE)((DWORD_PTR)(a) & 0xff)) | ((WORD)((BYTE)((DWORD_PTR)(b) & 0xff))) << 8)) -#define MAKELONG(a,b) ((LONG)(((WORD)((DWORD_PTR)(a) & 0xffff)) | ((DWORD)((WORD)((DWORD_PTR)(b) & 0xffff))) << 16)) -#define LOWORD(l) ((WORD)((DWORD_PTR)(l) & 0xffff)) -#define HIWORD(l) ((WORD)((DWORD_PTR)(l) >> 16)) -#define LOBYTE(w) ((BYTE)((DWORD_PTR)(w) & 0xff)) -#define HIBYTE(w) ((BYTE)((DWORD_PTR)(w) >> 8)) - -#ifndef WIN_INTERNAL - DECLARE_HANDLE (HWND); - DECLARE_HANDLE (HHOOK); -#ifdef WINABLE - DECLARE_HANDLE (HEVENT); -#endif -#endif - - typedef WORD ATOM; - - typedef HANDLE *SPHANDLE; - typedef HANDLE *LPHANDLE; - typedef HANDLE HGLOBAL; - typedef HANDLE HLOCAL; - typedef HANDLE GLOBALHANDLE; - typedef HANDLE LOCALHANDLE; -#ifdef _WIN64 - typedef INT_PTR (WINAPI *FARPROC)(); - typedef INT_PTR (WINAPI *NEARPROC)(); - typedef INT_PTR (WINAPI *PROC)(); -#else - typedef int (WINAPI *FARPROC)(); - typedef int (WINAPI *NEARPROC)(); - typedef int (WINAPI *PROC)(); -#endif - - typedef void *HGDIOBJ; - - DECLARE_HANDLE(HKEY); - typedef HKEY *PHKEY; - - DECLARE_HANDLE(HACCEL); - DECLARE_HANDLE(HBITMAP); - DECLARE_HANDLE(HBRUSH); - DECLARE_HANDLE(HCOLORSPACE); - DECLARE_HANDLE(HDC); - DECLARE_HANDLE(HGLRC); - DECLARE_HANDLE(HDESK); - DECLARE_HANDLE(HENHMETAFILE); - DECLARE_HANDLE(HFONT); - DECLARE_HANDLE(HICON); - DECLARE_HANDLE(HMENU); - DECLARE_HANDLE(HMETAFILE); - DECLARE_HANDLE(HINSTANCE); - typedef HINSTANCE HMODULE; - DECLARE_HANDLE(HPALETTE); - DECLARE_HANDLE(HPEN); - DECLARE_HANDLE(HRGN); - DECLARE_HANDLE(HRSRC); - DECLARE_HANDLE(HSTR); - DECLARE_HANDLE(HTASK); - DECLARE_HANDLE(HWINSTA); - DECLARE_HANDLE(HKL); - DECLARE_HANDLE(HMONITOR); - DECLARE_HANDLE(HWINEVENTHOOK); - DECLARE_HANDLE(HUMPD); - - typedef int HFILE; - typedef HICON HCURSOR; - typedef DWORD COLORREF; - typedef DWORD *LPCOLORREF; - -#define HFILE_ERROR ((HFILE)-1) - - typedef struct tagRECT { - LONG left; - LONG top; - LONG right; - LONG bottom; - } RECT,*PRECT,*NPRECT,*LPRECT; - - typedef const RECT *LPCRECT; - - typedef struct _RECTL { - LONG left; - LONG top; - LONG right; - LONG bottom; - } RECTL,*PRECTL,*LPRECTL; - - typedef const RECTL *LPCRECTL; - - typedef struct tagPOINT { - LONG x; - LONG y; - } POINT,*PPOINT,*NPPOINT,*LPPOINT; - - typedef struct _POINTL { - LONG x; - LONG y; - } POINTL,*PPOINTL; - - typedef struct tagSIZE { - LONG cx; - LONG cy; - } SIZE,*PSIZE,*LPSIZE; - - typedef SIZE SIZEL; - typedef SIZE *PSIZEL,*LPSIZEL; - - typedef struct tagPOINTS { - SHORT x; - SHORT y; - } POINTS,*PPOINTS,*LPPOINTS; - - typedef struct _FILETIME { - DWORD dwLowDateTime; - DWORD dwHighDateTime; - } FILETIME,*PFILETIME,*LPFILETIME; -#define _FILETIME_ - -#define DM_UPDATE 1 -#define DM_COPY 2 -#define DM_PROMPT 4 -#define DM_MODIFY 8 - -#define DM_IN_BUFFER DM_MODIFY -#define DM_IN_PROMPT DM_PROMPT -#define DM_OUT_BUFFER DM_COPY -#define DM_OUT_DEFAULT DM_UPDATE - -#define DC_FIELDS 1 -#define DC_PAPERS 2 -#define DC_PAPERSIZE 3 -#define DC_MINEXTENT 4 -#define DC_MAXEXTENT 5 -#define DC_BINS 6 -#define DC_DUPLEX 7 -#define DC_SIZE 8 -#define DC_EXTRA 9 -#define DC_VERSION 10 -#define DC_DRIVER 11 -#define DC_BINNAMES 12 -#define DC_ENUMRESOLUTIONS 13 -#define DC_FILEDEPENDENCIES 14 -#define DC_TRUETYPE 15 -#define DC_PAPERNAMES 16 -#define DC_ORIENTATION 17 -#define DC_COPIES 18 - -#ifdef __cplusplus -} -#endif -#endif diff --git a/05/tcc-final-old/win32/include/winapi/windows.h b/05/tcc-final-old/win32/include/winapi/windows.h deleted file mode 100644 index 2660d7f..0000000 --- a/05/tcc-final-old/win32/include/winapi/windows.h +++ /dev/null @@ -1,127 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _WINDOWS_ -#define _WINDOWS_ - -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN 1 -#endif - -#ifndef WINVER -#define WINVER 0x0502 -#endif - -#include <_mingw.h> - -#ifndef _INC_WINDOWS -#define _INC_WINDOWS - -#if defined(RC_INVOKED) && !defined(NOWINRES) - -#include -#else - -#ifdef RC_INVOKED -#define NOATOM -#define NOGDI -#define NOGDICAPMASKS -#define NOMETAFILE -#define NOMINMAX -#define NOMSG -#define NOOPENFILE -#define NORASTEROPS -#define NOSCROLL -#define NOSOUND -#define NOSYSMETRICS -#define NOTEXTMETRIC -#define NOWH -#define NOCOMM -#define NOKANJI -#define NOCRYPT -#define NOMCX -#endif - -#if !defined(I_X86_) && !defined(_IA64_) && !defined(_AMD64_) && (defined(_X86_) && !defined(__x86_64)) -#define I_X86_ -#endif - -#if !defined(I_X86_) && !defined(_IA64_) && !defined(_AMD64_) && defined(__x86_64) -#define _AMD64_ -#endif - -#if !defined(I_X86_) && !(defined(_X86_) && !defined(__x86_64)) && !defined(_AMD64_) && defined(__ia64__) -#if !defined(_IA64_) -#define _IA64_ -#endif -#endif - -#ifndef RC_INVOKED -#include -#include -#endif - -#include -#include -#include -#include -//gr #include -#include -#include -#include -//gr #include - -#ifndef WIN32_LEAN_AND_MEAN -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifndef NOCRYPT -#include -#include -#include -#endif - -#ifndef NOUSER -#ifndef NOGDI -#include -#ifdef INC_OLE1 -#include -#else -#include -#endif -#include -#endif -#endif -#endif - -//gr #include - -#ifdef INC_OLE2 -#include -#endif - -#ifndef NOSERVICE -#include -#endif - -#ifndef NOMCX -#include -#endif - -#ifndef NOIME -#include -#endif - -#endif -#endif -#endif diff --git a/05/tcc-final-old/win32/include/winapi/winerror.h b/05/tcc-final-old/win32/include/winapi/winerror.h deleted file mode 100644 index 77d85ed..0000000 --- a/05/tcc-final-old/win32/include/winapi/winerror.h +++ /dev/null @@ -1,3166 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _WINERROR_ -#define _WINERROR_ - -#define FACILITY_WINDOWSUPDATE 36 -#define FACILITY_WINDOWS_CE 24 -#define FACILITY_WINDOWS 8 -#define FACILITY_URT 19 -#define FACILITY_UMI 22 -#define FACILITY_SXS 23 -#define FACILITY_STORAGE 3 -#define FACILITY_STATE_MANAGEMENT 34 -#define FACILITY_SSPI 9 -#define FACILITY_SCARD 16 -#define FACILITY_SETUPAPI 15 -#define FACILITY_SECURITY 9 -#define FACILITY_RPC 1 -#define FACILITY_WIN32 7 -#define FACILITY_CONTROL 10 -#define FACILITY_NULL 0 -#define FACILITY_METADIRECTORY 35 -#define FACILITY_MSMQ 14 -#define FACILITY_MEDIASERVER 13 -#define FACILITY_INTERNET 12 -#define FACILITY_ITF 4 -#define FACILITY_HTTP 25 -#define FACILITY_DPLAY 21 -#define FACILITY_DISPATCH 2 -#define FACILITY_DIRECTORYSERVICE 37 -#define FACILITY_CONFIGURATION 33 -#define FACILITY_COMPLUS 17 -#define FACILITY_CERT 11 -#define FACILITY_BACKGROUNDCOPY 32 -#define FACILITY_ACS 20 -#define FACILITY_AAF 18 -#define ERROR_SUCCESS 0L -#define NO_ERROR 0L -#define SEC_E_OK ((HRESULT)0x00000000L) -#define ERROR_INVALID_FUNCTION 1L -#define ERROR_FILE_NOT_FOUND 2L -#define ERROR_PATH_NOT_FOUND 3L -#define ERROR_TOO_MANY_OPEN_FILES 4L -#define ERROR_ACCESS_DENIED 5L -#define ERROR_INVALID_HANDLE 6L -#define ERROR_ARENA_TRASHED 7L -#define ERROR_NOT_ENOUGH_MEMORY 8L -#define ERROR_INVALID_BLOCK 9L -#define ERROR_BAD_ENVIRONMENT 10L -#define ERROR_BAD_FORMAT 11L -#define ERROR_INVALID_ACCESS 12L -#define ERROR_INVALID_DATA 13L -#define ERROR_OUTOFMEMORY 14L -#define ERROR_INVALID_DRIVE 15L -#define ERROR_CURRENT_DIRECTORY 16L -#define ERROR_NOT_SAME_DEVICE 17L -#define ERROR_NO_MORE_FILES 18L -#define ERROR_WRITE_PROTECT 19L -#define ERROR_BAD_UNIT 20L -#define ERROR_NOT_READY 21L -#define ERROR_BAD_COMMAND 22L -#define ERROR_CRC 23L -#define ERROR_BAD_LENGTH 24L -#define ERROR_SEEK 25L -#define ERROR_NOT_DOS_DISK 26L -#define ERROR_SECTOR_NOT_FOUND 27L -#define ERROR_OUT_OF_PAPER 28L -#define ERROR_WRITE_FAULT 29L -#define ERROR_READ_FAULT 30L -#define ERROR_GEN_FAILURE 31L -#define ERROR_SHARING_VIOLATION 32L -#define ERROR_LOCK_VIOLATION 33L -#define ERROR_WRONG_DISK 34L -#define ERROR_SHARING_BUFFER_EXCEEDED 36L -#define ERROR_HANDLE_EOF 38L -#define ERROR_HANDLE_DISK_FULL 39L -#define ERROR_NOT_SUPPORTED 50L -#define ERROR_REM_NOT_LIST 51L -#define ERROR_DUP_NAME 52L -#define ERROR_BAD_NETPATH 53L -#define ERROR_NETWORK_BUSY 54L -#define ERROR_DEV_NOT_EXIST 55L -#define ERROR_TOO_MANY_CMDS 56L -#define ERROR_ADAP_HDW_ERR 57L -#define ERROR_BAD_NET_RESP 58L -#define ERROR_UNEXP_NET_ERR 59L -#define ERROR_BAD_REM_ADAP 60L -#define ERROR_PRINTQ_FULL 61L -#define ERROR_NO_SPOOL_SPACE 62L -#define ERROR_PRINT_CANCELLED 63L -#define ERROR_NETNAME_DELETED 64L -#define ERROR_NETWORK_ACCESS_DENIED 65L -#define ERROR_BAD_DEV_TYPE 66L -#define ERROR_BAD_NET_NAME 67L -#define ERROR_TOO_MANY_NAMES 68L -#define ERROR_TOO_MANY_SESS 69L -#define ERROR_SHARING_PAUSED 70L -#define ERROR_REQ_NOT_ACCEP 71L -#define ERROR_REDIR_PAUSED 72L -#define ERROR_FILE_EXISTS 80L -#define ERROR_CANNOT_MAKE 82L -#define ERROR_FAIL_I24 83L -#define ERROR_OUT_OF_STRUCTURES 84L -#define ERROR_ALREADY_ASSIGNED 85L -#define ERROR_INVALID_PASSWORD 86L -#define ERROR_INVALID_PARAMETER 87L -#define ERROR_NET_WRITE_FAULT 88L -#define ERROR_NO_PROC_SLOTS 89L -#define ERROR_TOO_MANY_SEMAPHORES 100L -#define ERROR_EXCL_SEM_ALREADY_OWNED 101L -#define ERROR_SEM_IS_SET 102L -#define ERROR_TOO_MANY_SEM_REQUESTS 103L -#define ERROR_INVALID_AT_INTERRUPT_TIME 104L -#define ERROR_SEM_OWNER_DIED 105L -#define ERROR_SEM_USER_LIMIT 106L -#define ERROR_DISK_CHANGE 107L -#define ERROR_DRIVE_LOCKED 108L -#define ERROR_BROKEN_PIPE 109L -#define ERROR_OPEN_FAILED 110L -#define ERROR_BUFFER_OVERFLOW 111L -#define ERROR_DISK_FULL 112L -#define ERROR_NO_MORE_SEARCH_HANDLES 113L -#define ERROR_INVALID_TARGET_HANDLE 114L -#define ERROR_INVALID_CATEGORY 117L -#define ERROR_INVALID_VERIFY_SWITCH 118L -#define ERROR_BAD_DRIVER_LEVEL 119L -#define ERROR_CALL_NOT_IMPLEMENTED 120L -#define ERROR_SEM_TIMEOUT 121L -#define ERROR_INSUFFICIENT_BUFFER 122L -#define ERROR_INVALID_NAME 123L -#define ERROR_INVALID_LEVEL 124L -#define ERROR_NO_VOLUME_LABEL 125L -#define ERROR_MOD_NOT_FOUND 126L -#define ERROR_PROC_NOT_FOUND 127L -#define ERROR_WAIT_NO_CHILDREN 128L -#define ERROR_CHILD_NOT_COMPLETE 129L -#define ERROR_DIRECT_ACCESS_HANDLE 130L -#define ERROR_NEGATIVE_SEEK 131L -#define ERROR_SEEK_ON_DEVICE 132L -#define ERROR_IS_JOIN_TARGET 133L -#define ERROR_IS_JOINED 134L -#define ERROR_IS_SUBSTED 135L -#define ERROR_NOT_JOINED 136L -#define ERROR_NOT_SUBSTED 137L -#define ERROR_JOIN_TO_JOIN 138L -#define ERROR_SUBST_TO_SUBST 139L -#define ERROR_JOIN_TO_SUBST 140L -#define ERROR_SUBST_TO_JOIN 141L -#define ERROR_BUSY_DRIVE 142L -#define ERROR_SAME_DRIVE 143L -#define ERROR_DIR_NOT_ROOT 144L -#define ERROR_DIR_NOT_EMPTY 145L -#define ERROR_IS_SUBST_PATH 146L -#define ERROR_IS_JOIN_PATH 147L -#define ERROR_PATH_BUSY 148L -#define ERROR_IS_SUBST_TARGET 149L -#define ERROR_SYSTEM_TRACE 150L -#define ERROR_INVALID_EVENT_COUNT 151L -#define ERROR_TOO_MANY_MUXWAITERS 152L -#define ERROR_INVALID_LIST_FORMAT 153L -#define ERROR_LABEL_TOO_LONG 154L -#define ERROR_TOO_MANY_TCBS 155L -#define ERROR_SIGNAL_REFUSED 156L -#define ERROR_DISCARDED 157L -#define ERROR_NOT_LOCKED 158L -#define ERROR_BAD_THREADID_ADDR 159L -#define ERROR_BAD_ARGUMENTS 160L -#define ERROR_BAD_PATHNAME 161L -#define ERROR_SIGNAL_PENDING 162L -#define ERROR_MAX_THRDS_REACHED 164L -#define ERROR_LOCK_FAILED 167L -#define ERROR_BUSY 170L -#define ERROR_CANCEL_VIOLATION 173L -#define ERROR_ATOMIC_LOCKS_NOT_SUPPORTED 174L -#define ERROR_INVALID_SEGMENT_NUMBER 180L -#define ERROR_INVALID_ORDINAL 182L -#define ERROR_ALREADY_EXISTS 183L -#define ERROR_INVALID_FLAG_NUMBER 186L -#define ERROR_SEM_NOT_FOUND 187L -#define ERROR_INVALID_STARTING_CODESEG 188L -#define ERROR_INVALID_STACKSEG 189L -#define ERROR_INVALID_MODULETYPE 190L -#define ERROR_INVALID_EXE_SIGNATURE 191L -#define ERROR_EXE_MARKED_INVALID 192L -#define ERROR_BAD_EXE_FORMAT 193L -#define ERROR_ITERATED_DATA_EXCEEDS_64k 194L -#define ERROR_INVALID_MINALLOCSIZE 195L -#define ERROR_DYNLINK_FROM_INVALID_RING 196L -#define ERROR_IOPL_NOT_ENABLED 197L -#define ERROR_INVALID_SEGDPL 198L -#define ERROR_AUTODATASEG_EXCEEDS_64k 199L -#define ERROR_RING2SEG_MUST_BE_MOVABLE 200L -#define ERROR_RELOC_CHAIN_XEEDS_SEGLIM 201L -#define ERROR_INFLOOP_IN_RELOC_CHAIN 202L -#define ERROR_ENVVAR_NOT_FOUND 203L -#define ERROR_NO_SIGNAL_SENT 205L -#define ERROR_FILENAME_EXCED_RANGE 206L -#define ERROR_RING2_STACK_IN_USE 207L -#define ERROR_META_EXPANSION_TOO_LONG 208L -#define ERROR_INVALID_SIGNAL_NUMBER 209L -#define ERROR_THREAD_1_INACTIVE 210L -#define ERROR_LOCKED 212L -#define ERROR_TOO_MANY_MODULES 214L -#define ERROR_NESTING_NOT_ALLOWED 215L -#define ERROR_EXE_MACHINE_TYPE_MISMATCH 216L -#define ERROR_EXE_CANNOT_MODIFY_SIGNED_BINARY 217L -#define ERROR_EXE_CANNOT_MODIFY_STRONG_SIGNED_BINARY 218L -#define ERROR_BAD_PIPE 230L -#define ERROR_PIPE_BUSY 231L -#define ERROR_NO_DATA 232L -#define ERROR_PIPE_NOT_CONNECTED 233L -#define ERROR_MORE_DATA 234L -#define ERROR_VC_DISCONNECTED 240L -#define ERROR_INVALID_EA_NAME 254L -#define ERROR_EA_LIST_INCONSISTENT 255L -#define WAIT_TIMEOUT 258L -#define ERROR_NO_MORE_ITEMS 259L -#define ERROR_CANNOT_COPY 266L -#define ERROR_DIRECTORY 267L -#define ERROR_EAS_DIDNT_FIT 275L -#define ERROR_EA_FILE_CORRUPT 276L -#define ERROR_EA_TABLE_FULL 277L -#define ERROR_INVALID_EA_HANDLE 278L -#define ERROR_EAS_NOT_SUPPORTED 282L -#define ERROR_NOT_OWNER 288L -#define ERROR_TOO_MANY_POSTS 298L -#define ERROR_PARTIAL_COPY 299L -#define ERROR_OPLOCK_NOT_GRANTED 300L -#define ERROR_INVALID_OPLOCK_PROTOCOL 301L -#define ERROR_DISK_TOO_FRAGMENTED 302L -#define ERROR_DELETE_PENDING 303L -#define ERROR_MR_MID_NOT_FOUND 317L -#define ERROR_SCOPE_NOT_FOUND 318L -#define ERROR_INVALID_ADDRESS 487L -#define ERROR_ARITHMETIC_OVERFLOW 534L -#define ERROR_PIPE_CONNECTED 535L -#define ERROR_PIPE_LISTENING 536L -#define ERROR_EA_ACCESS_DENIED 994L -#define ERROR_OPERATION_ABORTED 995L -#define ERROR_IO_INCOMPLETE 996L -#define ERROR_IO_PENDING 997L -#define ERROR_NOACCESS 998L -#define ERROR_SWAPERROR 999L -#define ERROR_STACK_OVERFLOW 1001L -#define ERROR_INVALID_MESSAGE 1002L -#define ERROR_CAN_NOT_COMPLETE 1003L -#define ERROR_INVALID_FLAGS 1004L -#define ERROR_UNRECOGNIZED_VOLUME 1005L -#define ERROR_FILE_INVALID 1006L -#define ERROR_FULLSCREEN_MODE 1007L -#define ERROR_NO_TOKEN 1008L -#define ERROR_BADDB 1009L -#define ERROR_BADKEY 1010L -#define ERROR_CANTOPEN 1011L -#define ERROR_CANTREAD 1012L -#define ERROR_CANTWRITE 1013L -#define ERROR_REGISTRY_RECOVERED 1014L -#define ERROR_REGISTRY_CORRUPT 1015L -#define ERROR_REGISTRY_IO_FAILED 1016L -#define ERROR_NOT_REGISTRY_FILE 1017L -#define ERROR_KEY_DELETED 1018L -#define ERROR_NO_LOG_SPACE 1019L -#define ERROR_KEY_HAS_CHILDREN 1020L -#define ERROR_CHILD_MUST_BE_VOLATILE 1021L -#define ERROR_NOTIFY_ENUM_DIR 1022L -#define ERROR_DEPENDENT_SERVICES_RUNNING 1051L -#define ERROR_INVALID_SERVICE_CONTROL 1052L -#define ERROR_SERVICE_REQUEST_TIMEOUT 1053L -#define ERROR_SERVICE_NO_THREAD 1054L -#define ERROR_SERVICE_DATABASE_LOCKED 1055L -#define ERROR_SERVICE_ALREADY_RUNNING 1056L -#define ERROR_INVALID_SERVICE_ACCOUNT 1057L -#define ERROR_SERVICE_DISABLED 1058L -#define ERROR_CIRCULAR_DEPENDENCY 1059L -#define ERROR_SERVICE_DOES_NOT_EXIST 1060L -#define ERROR_SERVICE_CANNOT_ACCEPT_CTRL 1061L -#define ERROR_SERVICE_NOT_ACTIVE 1062L -#define ERROR_FAILED_SERVICE_CONTROLLER_CONNECT 1063L -#define ERROR_EXCEPTION_IN_SERVICE 1064L -#define ERROR_DATABASE_DOES_NOT_EXIST 1065L -#define ERROR_SERVICE_SPECIFIC_ERROR 1066L -#define ERROR_PROCESS_ABORTED 1067L -#define ERROR_SERVICE_DEPENDENCY_FAIL 1068L -#define ERROR_SERVICE_LOGON_FAILED 1069L -#define ERROR_SERVICE_START_HANG 1070L -#define ERROR_INVALID_SERVICE_LOCK 1071L -#define ERROR_SERVICE_MARKED_FOR_DELETE 1072L -#define ERROR_SERVICE_EXISTS 1073L -#define ERROR_ALREADY_RUNNING_LKG 1074L -#define ERROR_SERVICE_DEPENDENCY_DELETED 1075L -#define ERROR_BOOT_ALREADY_ACCEPTED 1076L -#define ERROR_SERVICE_NEVER_STARTED 1077L -#define ERROR_DUPLICATE_SERVICE_NAME 1078L -#define ERROR_DIFFERENT_SERVICE_ACCOUNT 1079L -#define ERROR_CANNOT_DETECT_DRIVER_FAILURE 1080L -#define ERROR_CANNOT_DETECT_PROCESS_ABORT 1081L -#define ERROR_NO_RECOVERY_PROGRAM 1082L -#define ERROR_SERVICE_NOT_IN_EXE 1083L -#define ERROR_NOT_SAFEBOOT_SERVICE 1084L -#define ERROR_END_OF_MEDIA 1100L -#define ERROR_FILEMARK_DETECTED 1101L -#define ERROR_BEGINNING_OF_MEDIA 1102L -#define ERROR_SETMARK_DETECTED 1103L -#define ERROR_NO_DATA_DETECTED 1104L -#define ERROR_PARTITION_FAILURE 1105L -#define ERROR_INVALID_BLOCK_LENGTH 1106L -#define ERROR_DEVICE_NOT_PARTITIONED 1107L -#define ERROR_UNABLE_TO_LOCK_MEDIA 1108L -#define ERROR_UNABLE_TO_UNLOAD_MEDIA 1109L -#define ERROR_MEDIA_CHANGED 1110L -#define ERROR_BUS_RESET 1111L -#define ERROR_NO_MEDIA_IN_DRIVE 1112L -#define ERROR_NO_UNICODE_TRANSLATION 1113L -#define ERROR_DLL_INIT_FAILED 1114L -#define ERROR_SHUTDOWN_IN_PROGRESS 1115L -#define ERROR_NO_SHUTDOWN_IN_PROGRESS 1116L -#define ERROR_IO_DEVICE 1117L -#define ERROR_SERIAL_NO_DEVICE 1118L -#define ERROR_IRQ_BUSY 1119L -#define ERROR_MORE_WRITES 1120L -#define ERROR_COUNTER_TIMEOUT 1121L -#define ERROR_FLOPPY_ID_MARK_NOT_FOUND 1122L -#define ERROR_FLOPPY_WRONG_CYLINDER 1123L -#define ERROR_FLOPPY_UNKNOWN_ERROR 1124L -#define ERROR_FLOPPY_BAD_REGISTERS 1125L -#define ERROR_DISK_RECALIBRATE_FAILED 1126L -#define ERROR_DISK_OPERATION_FAILED 1127L -#define ERROR_DISK_RESET_FAILED 1128L -#define ERROR_EOM_OVERFLOW 1129L -#define ERROR_NOT_ENOUGH_SERVER_MEMORY 1130L -#define ERROR_POSSIBLE_DEADLOCK 1131L -#define ERROR_MAPPED_ALIGNMENT 1132L -#define ERROR_SET_POWER_STATE_VETOED 1140L -#define ERROR_SET_POWER_STATE_FAILED 1141L -#define ERROR_TOO_MANY_LINKS 1142L -#define ERROR_OLD_WIN_VERSION 1150L -#define ERROR_APP_WRONG_OS 1151L -#define ERROR_SINGLE_INSTANCE_APP 1152L -#define ERROR_RMODE_APP 1153L -#define ERROR_INVALID_DLL 1154L -#define ERROR_NO_ASSOCIATION 1155L -#define ERROR_DDE_FAIL 1156L -#define ERROR_DLL_NOT_FOUND 1157L -#define ERROR_NO_MORE_USER_HANDLES 1158L -#define ERROR_MESSAGE_SYNC_ONLY 1159L -#define ERROR_SOURCE_ELEMENT_EMPTY 1160L -#define ERROR_DESTINATION_ELEMENT_FULL 1161L -#define ERROR_ILLEGAL_ELEMENT_ADDRESS 1162L -#define ERROR_MAGAZINE_NOT_PRESENT 1163L -#define ERROR_DEVICE_REINITIALIZATION_NEEDED 1164L -#define ERROR_DEVICE_REQUIRES_CLEANING 1165L -#define ERROR_DEVICE_DOOR_OPEN 1166L -#define ERROR_DEVICE_NOT_CONNECTED 1167L -#define ERROR_NOT_FOUND 1168L -#define ERROR_NO_MATCH 1169L -#define ERROR_SET_NOT_FOUND 1170L -#define ERROR_POINT_NOT_FOUND 1171L -#define ERROR_NO_TRACKING_SERVICE 1172L -#define ERROR_NO_VOLUME_ID 1173L -#define ERROR_UNABLE_TO_REMOVE_REPLACED 1175L -#define ERROR_UNABLE_TO_MOVE_REPLACEMENT 1176L -#define ERROR_UNABLE_TO_MOVE_REPLACEMENT_2 1177L -#define ERROR_JOURNAL_DELETE_IN_PROGRESS 1178L -#define ERROR_JOURNAL_NOT_ACTIVE 1179L -#define ERROR_POTENTIAL_FILE_FOUND 1180L -#define ERROR_JOURNAL_ENTRY_DELETED 1181L -#define ERROR_BAD_DEVICE 1200L -#define ERROR_CONNECTION_UNAVAIL 1201L -#define ERROR_DEVICE_ALREADY_REMEMBERED 1202L -#define ERROR_NO_NET_OR_BAD_PATH 1203L -#define ERROR_BAD_PROVIDER 1204L -#define ERROR_CANNOT_OPEN_PROFILE 1205L -#define ERROR_BAD_PROFILE 1206L -#define ERROR_NOT_CONTAINER 1207L -#define ERROR_EXTENDED_ERROR 1208L -#define ERROR_INVALID_GROUPNAME 1209L -#define ERROR_INVALID_COMPUTERNAME 1210L -#define ERROR_INVALID_EVENTNAME 1211L -#define ERROR_INVALID_DOMAINNAME 1212L -#define ERROR_INVALID_SERVICENAME 1213L -#define ERROR_INVALID_NETNAME 1214L -#define ERROR_INVALID_SHARENAME 1215L -#define ERROR_INVALID_PASSWORDNAME 1216L -#define ERROR_INVALID_MESSAGENAME 1217L -#define ERROR_INVALID_MESSAGEDEST 1218L -#define ERROR_SESSION_CREDENTIAL_CONFLICT 1219L -#define ERROR_REMOTE_SESSION_LIMIT_EXCEEDED 1220L -#define ERROR_DUP_DOMAINNAME 1221L -#define ERROR_NO_NETWORK 1222L -#define ERROR_CANCELLED 1223L -#define ERROR_USER_MAPPED_FILE 1224L -#define ERROR_CONNECTION_REFUSED 1225L -#define ERROR_GRACEFUL_DISCONNECT 1226L -#define ERROR_ADDRESS_ALREADY_ASSOCIATED 1227L -#define ERROR_ADDRESS_NOT_ASSOCIATED 1228L -#define ERROR_CONNECTION_INVALID 1229L -#define ERROR_CONNECTION_ACTIVE 1230L -#define ERROR_NETWORK_UNREACHABLE 1231L -#define ERROR_HOST_UNREACHABLE 1232L -#define ERROR_PROTOCOL_UNREACHABLE 1233L -#define ERROR_PORT_UNREACHABLE 1234L -#define ERROR_REQUEST_ABORTED 1235L -#define ERROR_CONNECTION_ABORTED 1236L -#define ERROR_RETRY 1237L -#define ERROR_CONNECTION_COUNT_LIMIT 1238L -#define ERROR_LOGIN_TIME_RESTRICTION 1239L -#define ERROR_LOGIN_WKSTA_RESTRICTION 1240L -#define ERROR_INCORRECT_ADDRESS 1241L -#define ERROR_ALREADY_REGISTERED 1242L -#define ERROR_SERVICE_NOT_FOUND 1243L -#define ERROR_NOT_AUTHENTICATED 1244L -#define ERROR_NOT_LOGGED_ON 1245L -#define ERROR_CONTINUE 1246L -#define ERROR_ALREADY_INITIALIZED 1247L -#define ERROR_NO_MORE_DEVICES 1248L -#define ERROR_NO_SUCH_SITE 1249L -#define ERROR_DOMAIN_CONTROLLER_EXISTS 1250L -#define ERROR_ONLY_IF_CONNECTED 1251L -#define ERROR_OVERRIDE_NOCHANGES 1252L -#define ERROR_BAD_USER_PROFILE 1253L -#define ERROR_NOT_SUPPORTED_ON_SBS 1254L -#define ERROR_SERVER_SHUTDOWN_IN_PROGRESS 1255L -#define ERROR_HOST_DOWN 1256L -#define ERROR_NON_ACCOUNT_SID 1257L -#define ERROR_NON_DOMAIN_SID 1258L -#define ERROR_APPHELP_BLOCK 1259L -#define ERROR_ACCESS_DISABLED_BY_POLICY 1260L -#define ERROR_REG_NAT_CONSUMPTION 1261L -#define ERROR_CSCSHARE_OFFLINE 1262L -#define ERROR_PKINIT_FAILURE 1263L -#define ERROR_SMARTCARD_SUBSYSTEM_FAILURE 1264L -#define ERROR_DOWNGRADE_DETECTED 1265L -#define ERROR_MACHINE_LOCKED 1271L -#define ERROR_CALLBACK_SUPPLIED_INVALID_DATA 1273L -#define ERROR_SYNC_FOREGROUND_REFRESH_REQUIRED 1274L -#define ERROR_DRIVER_BLOCKED 1275L -#define ERROR_INVALID_IMPORT_OF_NON_DLL 1276L -#define ERROR_ACCESS_DISABLED_WEBBLADE 1277L -#define ERROR_ACCESS_DISABLED_WEBBLADE_TAMPER 1278L -#define ERROR_RECOVERY_FAILURE 1279L -#define ERROR_ALREADY_FIBER 1280L -#define ERROR_ALREADY_THREAD 1281L -#define ERROR_STACK_BUFFER_OVERRUN 1282L -#define ERROR_PARAMETER_QUOTA_EXCEEDED 1283L -#define ERROR_DEBUGGER_INACTIVE 1284L -#define ERROR_DELAY_LOAD_FAILED 1285L -#define ERROR_VDM_DISALLOWED 1286L -#define ERROR_UNIDENTIFIED_ERROR 1287L -#define ERROR_NOT_ALL_ASSIGNED 1300L -#define ERROR_SOME_NOT_MAPPED 1301L -#define ERROR_NO_QUOTAS_FOR_ACCOUNT 1302L -#define ERROR_LOCAL_USER_SESSION_KEY 1303L -#define ERROR_NULL_LM_PASSWORD 1304L -#define ERROR_UNKNOWN_REVISION 1305L -#define ERROR_REVISION_MISMATCH 1306L -#define ERROR_INVALID_OWNER 1307L -#define ERROR_INVALID_PRIMARY_GROUP 1308L -#define ERROR_NO_IMPERSONATION_TOKEN 1309L -#define ERROR_CANT_DISABLE_MANDATORY 1310L -#define ERROR_NO_LOGON_SERVERS 1311L -#define ERROR_NO_SUCH_LOGON_SESSION 1312L -#define ERROR_NO_SUCH_PRIVILEGE 1313L -#define ERROR_PRIVILEGE_NOT_HELD 1314L -#define ERROR_INVALID_ACCOUNT_NAME 1315L -#define ERROR_USER_EXISTS 1316L -#define ERROR_NO_SUCH_USER 1317L -#define ERROR_GROUP_EXISTS 1318L -#define ERROR_NO_SUCH_GROUP 1319L -#define ERROR_MEMBER_IN_GROUP 1320L -#define ERROR_MEMBER_NOT_IN_GROUP 1321L -#define ERROR_LAST_ADMIN 1322L -#define ERROR_WRONG_PASSWORD 1323L -#define ERROR_ILL_FORMED_PASSWORD 1324L -#define ERROR_PASSWORD_RESTRICTION 1325L -#define ERROR_LOGON_FAILURE 1326L -#define ERROR_ACCOUNT_RESTRICTION 1327L -#define ERROR_INVALID_LOGON_HOURS 1328L -#define ERROR_INVALID_WORKSTATION 1329L -#define ERROR_PASSWORD_EXPIRED 1330L -#define ERROR_ACCOUNT_DISABLED 1331L -#define ERROR_NONE_MAPPED 1332L -#define ERROR_TOO_MANY_LUIDS_REQUESTED 1333L -#define ERROR_LUIDS_EXHAUSTED 1334L -#define ERROR_INVALID_SUB_AUTHORITY 1335L -#define ERROR_INVALID_ACL 1336L -#define ERROR_INVALID_SID 1337L -#define ERROR_INVALID_SECURITY_DESCR 1338L -#define ERROR_BAD_INHERITANCE_ACL 1340L -#define ERROR_SERVER_DISABLED 1341L -#define ERROR_SERVER_NOT_DISABLED 1342L -#define ERROR_INVALID_ID_AUTHORITY 1343L -#define ERROR_ALLOTTED_SPACE_EXCEEDED 1344L -#define ERROR_INVALID_GROUP_ATTRIBUTES 1345L -#define ERROR_BAD_IMPERSONATION_LEVEL 1346L -#define ERROR_CANT_OPEN_ANONYMOUS 1347L -#define ERROR_BAD_VALIDATION_CLASS 1348L -#define ERROR_BAD_TOKEN_TYPE 1349L -#define ERROR_NO_SECURITY_ON_OBJECT 1350L -#define ERROR_CANT_ACCESS_DOMAIN_INFO 1351L -#define ERROR_INVALID_SERVER_STATE 1352L -#define ERROR_INVALID_DOMAIN_STATE 1353L -#define ERROR_INVALID_DOMAIN_ROLE 1354L -#define ERROR_NO_SUCH_DOMAIN 1355L -#define ERROR_DOMAIN_EXISTS 1356L -#define ERROR_DOMAIN_LIMIT_EXCEEDED 1357L -#define ERROR_INTERNAL_DB_CORRUPTION 1358L -#define ERROR_INTERNAL_ERROR 1359L -#define ERROR_GENERIC_NOT_MAPPED 1360L -#define ERROR_BAD_DESCRIPTOR_FORMAT 1361L -#define ERROR_NOT_LOGON_PROCESS 1362L -#define ERROR_LOGON_SESSION_EXISTS 1363L -#define ERROR_NO_SUCH_PACKAGE 1364L -#define ERROR_BAD_LOGON_SESSION_STATE 1365L -#define ERROR_LOGON_SESSION_COLLISION 1366L -#define ERROR_INVALID_LOGON_TYPE 1367L -#define ERROR_CANNOT_IMPERSONATE 1368L -#define ERROR_RXACT_INVALID_STATE 1369L -#define ERROR_RXACT_COMMIT_FAILURE 1370L -#define ERROR_SPECIAL_ACCOUNT 1371L -#define ERROR_SPECIAL_GROUP 1372L -#define ERROR_SPECIAL_USER 1373L -#define ERROR_MEMBERS_PRIMARY_GROUP 1374L -#define ERROR_TOKEN_ALREADY_IN_USE 1375L -#define ERROR_NO_SUCH_ALIAS 1376L -#define ERROR_MEMBER_NOT_IN_ALIAS 1377L -#define ERROR_MEMBER_IN_ALIAS 1378L -#define ERROR_ALIAS_EXISTS 1379L -#define ERROR_LOGON_NOT_GRANTED 1380L -#define ERROR_TOO_MANY_SECRETS 1381L -#define ERROR_SECRET_TOO_LONG 1382L -#define ERROR_INTERNAL_DB_ERROR 1383L -#define ERROR_TOO_MANY_CONTEXT_IDS 1384L -#define ERROR_LOGON_TYPE_NOT_GRANTED 1385L -#define ERROR_NT_CROSS_ENCRYPTION_REQUIRED 1386L -#define ERROR_NO_SUCH_MEMBER 1387L -#define ERROR_INVALID_MEMBER 1388L -#define ERROR_TOO_MANY_SIDS 1389L -#define ERROR_LM_CROSS_ENCRYPTION_REQUIRED 1390L -#define ERROR_NO_INHERITANCE 1391L -#define ERROR_FILE_CORRUPT 1392L -#define ERROR_DISK_CORRUPT 1393L -#define ERROR_NO_USER_SESSION_KEY 1394L -#define ERROR_LICENSE_QUOTA_EXCEEDED 1395L -#define ERROR_WRONG_TARGET_NAME 1396L -#define ERROR_MUTUAL_AUTH_FAILED 1397L -#define ERROR_TIME_SKEW 1398L -#define ERROR_CURRENT_DOMAIN_NOT_ALLOWED 1399L -#define ERROR_INVALID_WINDOW_HANDLE 1400L -#define ERROR_INVALID_MENU_HANDLE 1401L -#define ERROR_INVALID_CURSOR_HANDLE 1402L -#define ERROR_INVALID_ACCEL_HANDLE 1403L -#define ERROR_INVALID_HOOK_HANDLE 1404L -#define ERROR_INVALID_DWP_HANDLE 1405L -#define ERROR_TLW_WITH_WSCHILD 1406L -#define ERROR_CANNOT_FIND_WND_CLASS 1407L -#define ERROR_WINDOW_OF_OTHER_THREAD 1408L -#define ERROR_HOTKEY_ALREADY_REGISTERED 1409L -#define ERROR_CLASS_ALREADY_EXISTS 1410L -#define ERROR_CLASS_DOES_NOT_EXIST 1411L -#define ERROR_CLASS_HAS_WINDOWS 1412L -#define ERROR_INVALID_INDEX 1413L -#define ERROR_INVALID_ICON_HANDLE 1414L -#define ERROR_PRIVATE_DIALOG_INDEX 1415L -#define ERROR_LISTBOX_ID_NOT_FOUND 1416L -#define ERROR_NO_WILDCARD_CHARACTERS 1417L -#define ERROR_CLIPBOARD_NOT_OPEN 1418L -#define ERROR_HOTKEY_NOT_REGISTERED 1419L -#define ERROR_WINDOW_NOT_DIALOG 1420L -#define ERROR_CONTROL_ID_NOT_FOUND 1421L -#define ERROR_INVALID_COMBOBOX_MESSAGE 1422L -#define ERROR_WINDOW_NOT_COMBOBOX 1423L -#define ERROR_INVALID_EDIT_HEIGHT 1424L -#define ERROR_DC_NOT_FOUND 1425L -#define ERROR_INVALID_HOOK_FILTER 1426L -#define ERROR_INVALID_FILTER_PROC 1427L -#define ERROR_HOOK_NEEDS_HMOD 1428L -#define ERROR_GLOBAL_ONLY_HOOK 1429L -#define ERROR_JOURNAL_HOOK_SET 1430L -#define ERROR_HOOK_NOT_INSTALLED 1431L -#define ERROR_INVALID_LB_MESSAGE 1432L -#define ERROR_SETCOUNT_ON_BAD_LB 1433L -#define ERROR_LB_WITHOUT_TABSTOPS 1434L -#define ERROR_DESTROY_OBJECT_OF_OTHER_THREAD 1435L -#define ERROR_CHILD_WINDOW_MENU 1436L -#define ERROR_NO_SYSTEM_MENU 1437L -#define ERROR_INVALID_MSGBOX_STYLE 1438L -#define ERROR_INVALID_SPI_VALUE 1439L -#define ERROR_SCREEN_ALREADY_LOCKED 1440L -#define ERROR_HWNDS_HAVE_DIFF_PARENT 1441L -#define ERROR_NOT_CHILD_WINDOW 1442L -#define ERROR_INVALID_GW_COMMAND 1443L -#define ERROR_INVALID_THREAD_ID 1444L -#define ERROR_NON_MDICHILD_WINDOW 1445L -#define ERROR_POPUP_ALREADY_ACTIVE 1446L -#define ERROR_NO_SCROLLBARS 1447L -#define ERROR_INVALID_SCROLLBAR_RANGE 1448L -#define ERROR_INVALID_SHOWWIN_COMMAND 1449L -#define ERROR_NO_SYSTEM_RESOURCES 1450L -#define ERROR_NONPAGED_SYSTEM_RESOURCES 1451L -#define ERROR_PAGED_SYSTEM_RESOURCES 1452L -#define ERROR_WORKING_SET_QUOTA 1453L -#define ERROR_PAGEFILE_QUOTA 1454L -#define ERROR_COMMITMENT_LIMIT 1455L -#define ERROR_MENU_ITEM_NOT_FOUND 1456L -#define ERROR_INVALID_KEYBOARD_HANDLE 1457L -#define ERROR_HOOK_TYPE_NOT_ALLOWED 1458L -#define ERROR_REQUIRES_INTERACTIVE_WINDOWSTATION 1459L -#define ERROR_TIMEOUT 1460L -#define ERROR_INVALID_MONITOR_HANDLE 1461L -#define ERROR_INCORRECT_SIZE 1462L -#define ERROR_EVENTLOG_FILE_CORRUPT 1500L -#define ERROR_EVENTLOG_CANT_START 1501L -#define ERROR_LOG_FILE_FULL 1502L -#define ERROR_EVENTLOG_FILE_CHANGED 1503L -#define ERROR_INSTALL_SERVICE_FAILURE 1601L -#define ERROR_INSTALL_USEREXIT 1602L -#define ERROR_INSTALL_FAILURE 1603L -#define ERROR_INSTALL_SUSPEND 1604L -#define ERROR_UNKNOWN_PRODUCT 1605L -#define ERROR_UNKNOWN_FEATURE 1606L -#define ERROR_UNKNOWN_COMPONENT 1607L -#define ERROR_UNKNOWN_PROPERTY 1608L -#define ERROR_INVALID_HANDLE_STATE 1609L -#define ERROR_BAD_CONFIGURATION 1610L -#define ERROR_INDEX_ABSENT 1611L -#define ERROR_INSTALL_SOURCE_ABSENT 1612L -#define ERROR_INSTALL_PACKAGE_VERSION 1613L -#define ERROR_PRODUCT_UNINSTALLED 1614L -#define ERROR_BAD_QUERY_SYNTAX 1615L -#define ERROR_INVALID_FIELD 1616L -#define ERROR_DEVICE_REMOVED 1617L -#define ERROR_INSTALL_ALREADY_RUNNING 1618L -#define ERROR_INSTALL_PACKAGE_OPEN_FAILED 1619L -#define ERROR_INSTALL_PACKAGE_INVALID 1620L -#define ERROR_INSTALL_UI_FAILURE 1621L -#define ERROR_INSTALL_LOG_FAILURE 1622L -#define ERROR_INSTALL_LANGUAGE_UNSUPPORTED 1623L -#define ERROR_INSTALL_TRANSFORM_FAILURE 1624L -#define ERROR_INSTALL_PACKAGE_REJECTED 1625L -#define ERROR_FUNCTION_NOT_CALLED 1626L -#define ERROR_FUNCTION_FAILED 1627L -#define ERROR_INVALID_TABLE 1628L -#define ERROR_DATATYPE_MISMATCH 1629L -#define ERROR_UNSUPPORTED_TYPE 1630L -#define ERROR_CREATE_FAILED 1631L -#define ERROR_INSTALL_TEMP_UNWRITABLE 1632L -#define ERROR_INSTALL_PLATFORM_UNSUPPORTED 1633L -#define ERROR_INSTALL_NOTUSED 1634L -#define ERROR_PATCH_PACKAGE_OPEN_FAILED 1635L -#define ERROR_PATCH_PACKAGE_INVALID 1636L -#define ERROR_PATCH_PACKAGE_UNSUPPORTED 1637L -#define ERROR_PRODUCT_VERSION 1638L -#define ERROR_INVALID_COMMAND_LINE 1639L -#define ERROR_INSTALL_REMOTE_DISALLOWED 1640L -#define ERROR_SUCCESS_REBOOT_INITIATED 1641L -#define ERROR_PATCH_TARGET_NOT_FOUND 1642L -#define ERROR_PATCH_PACKAGE_REJECTED 1643L -#define ERROR_INSTALL_TRANSFORM_REJECTED 1644L -#define ERROR_INSTALL_REMOTE_PROHIBITED 1645L -#define RPC_S_INVALID_STRING_BINDING 1700L -#define RPC_S_WRONG_KIND_OF_BINDING 1701L -#define RPC_S_INVALID_BINDING 1702L -#define RPC_S_PROTSEQ_NOT_SUPPORTED 1703L -#define RPC_S_INVALID_RPC_PROTSEQ 1704L -#define RPC_S_INVALID_STRING_UUID 1705L -#define RPC_S_INVALID_ENDPOINT_FORMAT 1706L -#define RPC_S_INVALID_NET_ADDR 1707L -#define RPC_S_NO_ENDPOINT_FOUND 1708L -#define RPC_S_INVALID_TIMEOUT 1709L -#define RPC_S_OBJECT_NOT_FOUND 1710L -#define RPC_S_ALREADY_REGISTERED 1711L -#define RPC_S_TYPE_ALREADY_REGISTERED 1712L -#define RPC_S_ALREADY_LISTENING 1713L -#define RPC_S_NO_PROTSEQS_REGISTERED 1714L -#define RPC_S_NOT_LISTENING 1715L -#define RPC_S_UNKNOWN_MGR_TYPE 1716L -#define RPC_S_UNKNOWN_IF 1717L -#define RPC_S_NO_BINDINGS 1718L -#define RPC_S_NO_PROTSEQS 1719L -#define RPC_S_CANT_CREATE_ENDPOINT 1720L -#define RPC_S_OUT_OF_RESOURCES 1721L -#define RPC_S_SERVER_UNAVAILABLE 1722L -#define RPC_S_SERVER_TOO_BUSY 1723L -#define RPC_S_INVALID_NETWORK_OPTIONS 1724L -#define RPC_S_NO_CALL_ACTIVE 1725L -#define RPC_S_CALL_FAILED 1726L -#define RPC_S_CALL_FAILED_DNE 1727L -#define RPC_S_PROTOCOL_ERROR 1728L -#define RPC_S_UNSUPPORTED_TRANS_SYN 1730L -#define RPC_S_UNSUPPORTED_TYPE 1732L -#define RPC_S_INVALID_TAG 1733L -#define RPC_S_INVALID_BOUND 1734L -#define RPC_S_NO_ENTRY_NAME 1735L -#define RPC_S_INVALID_NAME_SYNTAX 1736L -#define RPC_S_UNSUPPORTED_NAME_SYNTAX 1737L -#define RPC_S_UUID_NO_ADDRESS 1739L -#define RPC_S_DUPLICATE_ENDPOINT 1740L -#define RPC_S_UNKNOWN_AUTHN_TYPE 1741L -#define RPC_S_MAX_CALLS_TOO_SMALL 1742L -#define RPC_S_STRING_TOO_LONG 1743L -#define RPC_S_PROTSEQ_NOT_FOUND 1744L -#define RPC_S_PROCNUM_OUT_OF_RANGE 1745L -#define RPC_S_BINDING_HAS_NO_AUTH 1746L -#define RPC_S_UNKNOWN_AUTHN_SERVICE 1747L -#define RPC_S_UNKNOWN_AUTHN_LEVEL 1748L -#define RPC_S_INVALID_AUTH_IDENTITY 1749L -#define RPC_S_UNKNOWN_AUTHZ_SERVICE 1750L -#define EPT_S_INVALID_ENTRY 1751L -#define EPT_S_CANT_PERFORM_OP 1752L -#define EPT_S_NOT_REGISTERED 1753L -#define RPC_S_NOTHING_TO_EXPORT 1754L -#define RPC_S_INCOMPLETE_NAME 1755L -#define RPC_S_INVALID_VERS_OPTION 1756L -#define RPC_S_NO_MORE_MEMBERS 1757L -#define RPC_S_NOT_ALL_OBJS_UNEXPORTED 1758L -#define RPC_S_INTERFACE_NOT_FOUND 1759L -#define RPC_S_ENTRY_ALREADY_EXISTS 1760L -#define RPC_S_ENTRY_NOT_FOUND 1761L -#define RPC_S_NAME_SERVICE_UNAVAILABLE 1762L -#define RPC_S_INVALID_NAF_ID 1763L -#define RPC_S_CANNOT_SUPPORT 1764L -#define RPC_S_NO_CONTEXT_AVAILABLE 1765L -#define RPC_S_INTERNAL_ERROR 1766L -#define RPC_S_ZERO_DIVIDE 1767L -#define RPC_S_ADDRESS_ERROR 1768L -#define RPC_S_FP_DIV_ZERO 1769L -#define RPC_S_FP_UNDERFLOW 1770L -#define RPC_S_FP_OVERFLOW 1771L -#define RPC_X_NO_MORE_ENTRIES 1772L -#define RPC_X_SS_CHAR_TRANS_OPEN_FAIL 1773L -#define RPC_X_SS_CHAR_TRANS_SHORT_FILE 1774L -#define RPC_X_SS_IN_NULL_CONTEXT 1775L -#define RPC_X_SS_CONTEXT_DAMAGED 1777L -#define RPC_X_SS_HANDLES_MISMATCH 1778L -#define RPC_X_SS_CANNOT_GET_CALL_HANDLE 1779L -#define RPC_X_NULL_REF_POINTER 1780L -#define RPC_X_ENUM_VALUE_OUT_OF_RANGE 1781L -#define RPC_X_BYTE_COUNT_TOO_SMALL 1782L -#define RPC_X_BAD_STUB_DATA 1783L -#define ERROR_INVALID_USER_BUFFER 1784L -#define ERROR_UNRECOGNIZED_MEDIA 1785L -#define ERROR_NO_TRUST_LSA_SECRET 1786L -#define ERROR_NO_TRUST_SAM_ACCOUNT 1787L -#define ERROR_TRUSTED_DOMAIN_FAILURE 1788L -#define ERROR_TRUSTED_RELATIONSHIP_FAILURE 1789L -#define ERROR_TRUST_FAILURE 1790L -#define RPC_S_CALL_IN_PROGRESS 1791L -#define ERROR_NETLOGON_NOT_STARTED 1792L -#define ERROR_ACCOUNT_EXPIRED 1793L -#define ERROR_REDIRECTOR_HAS_OPEN_HANDLES 1794L -#define ERROR_PRINTER_DRIVER_ALREADY_INSTALLED 1795L -#define ERROR_UNKNOWN_PORT 1796L -#define ERROR_UNKNOWN_PRINTER_DRIVER 1797L -#define ERROR_UNKNOWN_PRINTPROCESSOR 1798L -#define ERROR_INVALID_SEPARATOR_FILE 1799L -#define ERROR_INVALID_PRIORITY 1800L -#define ERROR_INVALID_PRINTER_NAME 1801L -#define ERROR_PRINTER_ALREADY_EXISTS 1802L -#define ERROR_INVALID_PRINTER_COMMAND 1803L -#define ERROR_INVALID_DATATYPE 1804L -#define ERROR_INVALID_ENVIRONMENT 1805L -#define RPC_S_NO_MORE_BINDINGS 1806L -#define ERROR_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT 1807L -#define ERROR_NOLOGON_WORKSTATION_TRUST_ACCOUNT 1808L -#define ERROR_NOLOGON_SERVER_TRUST_ACCOUNT 1809L -#define ERROR_DOMAIN_TRUST_INCONSISTENT 1810L -#define ERROR_SERVER_HAS_OPEN_HANDLES 1811L -#define ERROR_RESOURCE_DATA_NOT_FOUND 1812L -#define ERROR_RESOURCE_TYPE_NOT_FOUND 1813L -#define ERROR_RESOURCE_NAME_NOT_FOUND 1814L -#define ERROR_RESOURCE_LANG_NOT_FOUND 1815L -#define ERROR_NOT_ENOUGH_QUOTA 1816L -#define RPC_S_NO_INTERFACES 1817L -#define RPC_S_CALL_CANCELLED 1818L -#define RPC_S_BINDING_INCOMPLETE 1819L -#define RPC_S_COMM_FAILURE 1820L -#define RPC_S_UNSUPPORTED_AUTHN_LEVEL 1821L -#define RPC_S_NO_PRINC_NAME 1822L -#define RPC_S_NOT_RPC_ERROR 1823L -#define RPC_S_UUID_LOCAL_ONLY 1824L -#define RPC_S_SEC_PKG_ERROR 1825L -#define RPC_S_NOT_CANCELLED 1826L -#define RPC_X_INVALID_ES_ACTION 1827L -#define RPC_X_WRONG_ES_VERSION 1828L -#define RPC_X_WRONG_STUB_VERSION 1829L -#define RPC_X_INVALID_PIPE_OBJECT 1830L -#define RPC_X_WRONG_PIPE_ORDER 1831L -#define RPC_X_WRONG_PIPE_VERSION 1832L -#define RPC_S_GROUP_MEMBER_NOT_FOUND 1898L -#define EPT_S_CANT_CREATE 1899L -#define RPC_S_INVALID_OBJECT 1900L -#define ERROR_INVALID_TIME 1901L -#define ERROR_INVALID_FORM_NAME 1902L -#define ERROR_INVALID_FORM_SIZE 1903L -#define ERROR_ALREADY_WAITING 1904L -#define ERROR_PRINTER_DELETED 1905L -#define ERROR_INVALID_PRINTER_STATE 1906L -#define ERROR_PASSWORD_MUST_CHANGE 1907L -#define ERROR_DOMAIN_CONTROLLER_NOT_FOUND 1908L -#define ERROR_ACCOUNT_LOCKED_OUT 1909L -#define OR_INVALID_OXID 1910L -#define OR_INVALID_OID 1911L -#define OR_INVALID_SET 1912L -#define RPC_S_SEND_INCOMPLETE 1913L -#define RPC_S_INVALID_ASYNC_HANDLE 1914L -#define RPC_S_INVALID_ASYNC_CALL 1915L -#define RPC_X_PIPE_CLOSED 1916L -#define RPC_X_PIPE_DISCIPLINE_ERROR 1917L -#define RPC_X_PIPE_EMPTY 1918L -#define ERROR_NO_SITENAME 1919L -#define ERROR_CANT_ACCESS_FILE 1920L -#define ERROR_CANT_RESOLVE_FILENAME 1921L -#define RPC_S_ENTRY_TYPE_MISMATCH 1922L -#define RPC_S_NOT_ALL_OBJS_EXPORTED 1923L -#define RPC_S_INTERFACE_NOT_EXPORTED 1924L -#define RPC_S_PROFILE_NOT_ADDED 1925L -#define RPC_S_PRF_ELT_NOT_ADDED 1926L -#define RPC_S_PRF_ELT_NOT_REMOVED 1927L -#define RPC_S_GRP_ELT_NOT_ADDED 1928L -#define RPC_S_GRP_ELT_NOT_REMOVED 1929L -#define ERROR_KM_DRIVER_BLOCKED 1930L -#define ERROR_CONTEXT_EXPIRED 1931L -#define ERROR_PER_USER_TRUST_QUOTA_EXCEEDED 1932L -#define ERROR_ALL_USER_TRUST_QUOTA_EXCEEDED 1933L -#define ERROR_USER_DELETE_TRUST_QUOTA_EXCEEDED 1934L -#define ERROR_AUTHENTICATION_FIREWALL_FAILED 1935L -#define ERROR_REMOTE_PRINT_CONNECTIONS_BLOCKED 1936L -#define ERROR_INVALID_PIXEL_FORMAT 2000L -#define ERROR_BAD_DRIVER 2001L -#define ERROR_INVALID_WINDOW_STYLE 2002L -#define ERROR_METAFILE_NOT_SUPPORTED 2003L -#define ERROR_TRANSFORM_NOT_SUPPORTED 2004L -#define ERROR_CLIPPING_NOT_SUPPORTED 2005L -#define ERROR_INVALID_CMM 2010L -#define ERROR_INVALID_PROFILE 2011L -#define ERROR_TAG_NOT_FOUND 2012L -#define ERROR_TAG_NOT_PRESENT 2013L -#define ERROR_DUPLICATE_TAG 2014L -#define ERROR_PROFILE_NOT_ASSOCIATED_WITH_DEVICE 2015L -#define ERROR_PROFILE_NOT_FOUND 2016L -#define ERROR_INVALID_COLORSPACE 2017L -#define ERROR_ICM_NOT_ENABLED 2018L -#define ERROR_DELETING_ICM_XFORM 2019L -#define ERROR_INVALID_TRANSFORM 2020L -#define ERROR_COLORSPACE_MISMATCH 2021L -#define ERROR_INVALID_COLORINDEX 2022L -#define ERROR_CONNECTED_OTHER_PASSWORD 2108L -#define ERROR_CONNECTED_OTHER_PASSWORD_DEFAULT 2109L -#define ERROR_BAD_USERNAME 2202L -#define ERROR_NOT_CONNECTED 2250L -#define ERROR_OPEN_FILES 2401L -#define ERROR_ACTIVE_CONNECTIONS 2402L -#define ERROR_DEVICE_IN_USE 2404L -#define ERROR_UNKNOWN_PRINT_MONITOR 3000L -#define ERROR_PRINTER_DRIVER_IN_USE 3001L -#define ERROR_SPOOL_FILE_NOT_FOUND 3002L -#define ERROR_SPL_NO_STARTDOC 3003L -#define ERROR_SPL_NO_ADDJOB 3004L -#define ERROR_PRINT_PROCESSOR_ALREADY_INSTALLED 3005L -#define ERROR_PRINT_MONITOR_ALREADY_INSTALLED 3006L -#define ERROR_INVALID_PRINT_MONITOR 3007L -#define ERROR_PRINT_MONITOR_IN_USE 3008L -#define ERROR_PRINTER_HAS_JOBS_QUEUED 3009L -#define ERROR_SUCCESS_REBOOT_REQUIRED 3010L -#define ERROR_SUCCESS_RESTART_REQUIRED 3011L -#define ERROR_PRINTER_NOT_FOUND 3012L -#define ERROR_PRINTER_DRIVER_WARNED 3013L -#define ERROR_PRINTER_DRIVER_BLOCKED 3014L -#define ERROR_WINS_INTERNAL 4000L -#define ERROR_CAN_NOT_DEL_LOCAL_WINS 4001L -#define ERROR_STATIC_INIT 4002L -#define ERROR_INC_BACKUP 4003L -#define ERROR_FULL_BACKUP 4004L -#define ERROR_REC_NON_EXISTENT 4005L -#define ERROR_RPL_NOT_ALLOWED 4006L -#define ERROR_DHCP_ADDRESS_CONFLICT 4100L -#define ERROR_WMI_GUID_NOT_FOUND 4200L -#define ERROR_WMI_INSTANCE_NOT_FOUND 4201L -#define ERROR_WMI_ITEMID_NOT_FOUND 4202L -#define ERROR_WMI_TRY_AGAIN 4203L -#define ERROR_WMI_DP_NOT_FOUND 4204L -#define ERROR_WMI_UNRESOLVED_INSTANCE_REF 4205L -#define ERROR_WMI_ALREADY_ENABLED 4206L -#define ERROR_WMI_GUID_DISCONNECTED 4207L -#define ERROR_WMI_SERVER_UNAVAILABLE 4208L -#define ERROR_WMI_DP_FAILED 4209L -#define ERROR_WMI_INVALID_MOF 4210L -#define ERROR_WMI_INVALID_REGINFO 4211L -#define ERROR_WMI_ALREADY_DISABLED 4212L -#define ERROR_WMI_READ_ONLY 4213L -#define ERROR_WMI_SET_FAILURE 4214L -#define ERROR_INVALID_MEDIA 4300L -#define ERROR_INVALID_LIBRARY 4301L -#define ERROR_INVALID_MEDIA_POOL 4302L -#define ERROR_DRIVE_MEDIA_MISMATCH 4303L -#define ERROR_MEDIA_OFFLINE 4304L -#define ERROR_LIBRARY_OFFLINE 4305L -#define ERROR_EMPTY 4306L -#define ERROR_NOT_EMPTY 4307L -#define ERROR_MEDIA_UNAVAILABLE 4308L -#define ERROR_RESOURCE_DISABLED 4309L -#define ERROR_INVALID_CLEANER 4310L -#define ERROR_UNABLE_TO_CLEAN 4311L -#define ERROR_OBJECT_NOT_FOUND 4312L -#define ERROR_DATABASE_FAILURE 4313L -#define ERROR_DATABASE_FULL 4314L -#define ERROR_MEDIA_INCOMPATIBLE 4315L -#define ERROR_RESOURCE_NOT_PRESENT 4316L -#define ERROR_INVALID_OPERATION 4317L -#define ERROR_MEDIA_NOT_AVAILABLE 4318L -#define ERROR_DEVICE_NOT_AVAILABLE 4319L -#define ERROR_REQUEST_REFUSED 4320L -#define ERROR_INVALID_DRIVE_OBJECT 4321L -#define ERROR_LIBRARY_FULL 4322L -#define ERROR_MEDIUM_NOT_ACCESSIBLE 4323L -#define ERROR_UNABLE_TO_LOAD_MEDIUM 4324L -#define ERROR_UNABLE_TO_INVENTORY_DRIVE 4325L -#define ERROR_UNABLE_TO_INVENTORY_SLOT 4326L -#define ERROR_UNABLE_TO_INVENTORY_TRANSPORT 4327L -#define ERROR_TRANSPORT_FULL 4328L -#define ERROR_CONTROLLING_IEPORT 4329L -#define ERROR_UNABLE_TO_EJECT_MOUNTED_MEDIA 4330L -#define ERROR_CLEANER_SLOT_SET 4331L -#define ERROR_CLEANER_SLOT_NOT_SET 4332L -#define ERROR_CLEANER_CARTRIDGE_SPENT 4333L -#define ERROR_UNEXPECTED_OMID 4334L -#define ERROR_CANT_DELETE_LAST_ITEM 4335L -#define ERROR_MESSAGE_EXCEEDS_MAX_SIZE 4336L -#define ERROR_VOLUME_CONTAINS_SYS_FILES 4337L -#define ERROR_INDIGENOUS_TYPE 4338L -#define ERROR_NO_SUPPORTING_DRIVES 4339L -#define ERROR_CLEANER_CARTRIDGE_INSTALLED 4340L -#define ERROR_IEPORT_FULL 4341L -#define ERROR_FILE_OFFLINE 4350L -#define ERROR_REMOTE_STORAGE_NOT_ACTIVE 4351L -#define ERROR_REMOTE_STORAGE_MEDIA_ERROR 4352L -#define ERROR_NOT_A_REPARSE_POINT 4390L -#define ERROR_REPARSE_ATTRIBUTE_CONFLICT 4391L -#define ERROR_INVALID_REPARSE_DATA 4392L -#define ERROR_REPARSE_TAG_INVALID 4393L -#define ERROR_REPARSE_TAG_MISMATCH 4394L -#define ERROR_VOLUME_NOT_SIS_ENABLED 4500L -#define ERROR_DEPENDENT_RESOURCE_EXISTS 5001L -#define ERROR_DEPENDENCY_NOT_FOUND 5002L -#define ERROR_DEPENDENCY_ALREADY_EXISTS 5003L -#define ERROR_RESOURCE_NOT_ONLINE 5004L -#define ERROR_HOST_NODE_NOT_AVAILABLE 5005L -#define ERROR_RESOURCE_NOT_AVAILABLE 5006L -#define ERROR_RESOURCE_NOT_FOUND 5007L -#define ERROR_SHUTDOWN_CLUSTER 5008L -#define ERROR_CANT_EVICT_ACTIVE_NODE 5009L -#define ERROR_OBJECT_ALREADY_EXISTS 5010L -#define ERROR_OBJECT_IN_LIST 5011L -#define ERROR_GROUP_NOT_AVAILABLE 5012L -#define ERROR_GROUP_NOT_FOUND 5013L -#define ERROR_GROUP_NOT_ONLINE 5014L -#define ERROR_HOST_NODE_NOT_RESOURCE_OWNER 5015L -#define ERROR_HOST_NODE_NOT_GROUP_OWNER 5016L -#define ERROR_RESMON_CREATE_FAILED 5017L -#define ERROR_RESMON_ONLINE_FAILED 5018L -#define ERROR_RESOURCE_ONLINE 5019L -#define ERROR_QUORUM_RESOURCE 5020L -#define ERROR_NOT_QUORUM_CAPABLE 5021L -#define ERROR_CLUSTER_SHUTTING_DOWN 5022L -#define ERROR_INVALID_STATE 5023L -#define ERROR_RESOURCE_PROPERTIES_STORED 5024L -#define ERROR_NOT_QUORUM_CLASS 5025L -#define ERROR_CORE_RESOURCE 5026L -#define ERROR_QUORUM_RESOURCE_ONLINE_FAILED 5027L -#define ERROR_QUORUMLOG_OPEN_FAILED 5028L -#define ERROR_CLUSTERLOG_CORRUPT 5029L -#define ERROR_CLUSTERLOG_RECORD_EXCEEDS_MAXSIZE 5030L -#define ERROR_CLUSTERLOG_EXCEEDS_MAXSIZE 5031L -#define ERROR_CLUSTERLOG_CHKPOINT_NOT_FOUND 5032L -#define ERROR_CLUSTERLOG_NOT_ENOUGH_SPACE 5033L -#define ERROR_QUORUM_OWNER_ALIVE 5034L -#define ERROR_NETWORK_NOT_AVAILABLE 5035L -#define ERROR_NODE_NOT_AVAILABLE 5036L -#define ERROR_ALL_NODES_NOT_AVAILABLE 5037L -#define ERROR_RESOURCE_FAILED 5038L -#define ERROR_CLUSTER_INVALID_NODE 5039L -#define ERROR_CLUSTER_NODE_EXISTS 5040L -#define ERROR_CLUSTER_JOIN_IN_PROGRESS 5041L -#define ERROR_CLUSTER_NODE_NOT_FOUND 5042L -#define ERROR_CLUSTER_LOCAL_NODE_NOT_FOUND 5043L -#define ERROR_CLUSTER_NETWORK_EXISTS 5044L -#define ERROR_CLUSTER_NETWORK_NOT_FOUND 5045L -#define ERROR_CLUSTER_NETINTERFACE_EXISTS 5046L -#define ERROR_CLUSTER_NETINTERFACE_NOT_FOUND 5047L -#define ERROR_CLUSTER_INVALID_REQUEST 5048L -#define ERROR_CLUSTER_INVALID_NETWORK_PROVIDER 5049L -#define ERROR_CLUSTER_NODE_DOWN 5050L -#define ERROR_CLUSTER_NODE_UNREACHABLE 5051L -#define ERROR_CLUSTER_NODE_NOT_MEMBER 5052L -#define ERROR_CLUSTER_JOIN_NOT_IN_PROGRESS 5053L -#define ERROR_CLUSTER_INVALID_NETWORK 5054L -#define ERROR_CLUSTER_NODE_UP 5056L -#define ERROR_CLUSTER_IPADDR_IN_USE 5057L -#define ERROR_CLUSTER_NODE_NOT_PAUSED 5058L -#define ERROR_CLUSTER_NO_SECURITY_CONTEXT 5059L -#define ERROR_CLUSTER_NETWORK_NOT_INTERNAL 5060L -#define ERROR_CLUSTER_NODE_ALREADY_UP 5061L -#define ERROR_CLUSTER_NODE_ALREADY_DOWN 5062L -#define ERROR_CLUSTER_NETWORK_ALREADY_ONLINE 5063L -#define ERROR_CLUSTER_NETWORK_ALREADY_OFFLINE 5064L -#define ERROR_CLUSTER_NODE_ALREADY_MEMBER 5065L -#define ERROR_CLUSTER_LAST_INTERNAL_NETWORK 5066L -#define ERROR_CLUSTER_NETWORK_HAS_DEPENDENTS 5067L -#define ERROR_INVALID_OPERATION_ON_QUORUM 5068L -#define ERROR_DEPENDENCY_NOT_ALLOWED 5069L -#define ERROR_CLUSTER_NODE_PAUSED 5070L -#define ERROR_NODE_CANT_HOST_RESOURCE 5071L -#define ERROR_CLUSTER_NODE_NOT_READY 5072L -#define ERROR_CLUSTER_NODE_SHUTTING_DOWN 5073L -#define ERROR_CLUSTER_JOIN_ABORTED 5074L -#define ERROR_CLUSTER_INCOMPATIBLE_VERSIONS 5075L -#define ERROR_CLUSTER_MAXNUM_OF_RESOURCES_EXCEEDED 5076L -#define ERROR_CLUSTER_SYSTEM_CONFIG_CHANGED 5077L -#define ERROR_CLUSTER_RESOURCE_TYPE_NOT_FOUND 5078L -#define ERROR_CLUSTER_RESTYPE_NOT_SUPPORTED 5079L -#define ERROR_CLUSTER_RESNAME_NOT_FOUND 5080L -#define ERROR_CLUSTER_NO_RPC_PACKAGES_REGISTERED 5081L -#define ERROR_CLUSTER_OWNER_NOT_IN_PREFLIST 5082L -#define ERROR_CLUSTER_DATABASE_SEQMISMATCH 5083L -#define ERROR_RESMON_INVALID_STATE 5084L -#define ERROR_CLUSTER_GUM_NOT_LOCKER 5085L -#define ERROR_QUORUM_DISK_NOT_FOUND 5086L -#define ERROR_DATABASE_BACKUP_CORRUPT 5087L -#define ERROR_CLUSTER_NODE_ALREADY_HAS_DFS_ROOT 5088L -#define ERROR_RESOURCE_PROPERTY_UNCHANGEABLE 5089L -#define ERROR_CLUSTER_MEMBERSHIP_INVALID_STATE 5890L -#define ERROR_CLUSTER_QUORUMLOG_NOT_FOUND 5891L -#define ERROR_CLUSTER_MEMBERSHIP_HALT 5892L -#define ERROR_CLUSTER_INSTANCE_ID_MISMATCH 5893L -#define ERROR_CLUSTER_NETWORK_NOT_FOUND_FOR_IP 5894L -#define ERROR_CLUSTER_PROPERTY_DATA_TYPE_MISMATCH 5895L -#define ERROR_CLUSTER_EVICT_WITHOUT_CLEANUP 5896L -#define ERROR_CLUSTER_PARAMETER_MISMATCH 5897L -#define ERROR_NODE_CANNOT_BE_CLUSTERED 5898L -#define ERROR_CLUSTER_WRONG_OS_VERSION 5899L -#define ERROR_CLUSTER_CANT_CREATE_DUP_CLUSTER_NAME 5900L -#define ERROR_CLUSCFG_ALREADY_COMMITTED 5901L -#define ERROR_CLUSCFG_ROLLBACK_FAILED 5902L -#define ERROR_CLUSCFG_SYSTEM_DISK_DRIVE_LETTER_CONFLICT 5903L -#define ERROR_CLUSTER_OLD_VERSION 5904L -#define ERROR_CLUSTER_MISMATCHED_COMPUTER_ACCT_NAME 5905L -#define ERROR_ENCRYPTION_FAILED 6000L -#define ERROR_DECRYPTION_FAILED 6001L -#define ERROR_FILE_ENCRYPTED 6002L -#define ERROR_NO_RECOVERY_POLICY 6003L -#define ERROR_NO_EFS 6004L -#define ERROR_WRONG_EFS 6005L -#define ERROR_NO_USER_KEYS 6006L -#define ERROR_FILE_NOT_ENCRYPTED 6007L -#define ERROR_NOT_EXPORT_FORMAT 6008L -#define ERROR_FILE_READ_ONLY 6009L -#define ERROR_DIR_EFS_DISALLOWED 6010L -#define ERROR_EFS_SERVER_NOT_TRUSTED 6011L -#define ERROR_BAD_RECOVERY_POLICY 6012L -#define ERROR_EFS_ALG_BLOB_TOO_BIG 6013L -#define ERROR_VOLUME_NOT_SUPPORT_EFS 6014L -#define ERROR_EFS_DISABLED 6015L -#define ERROR_EFS_VERSION_NOT_SUPPORT 6016L -#define ERROR_NO_BROWSER_SERVERS_FOUND 6118L -#define SCHED_E_SERVICE_NOT_LOCALSYSTEM 6200L -#define ERROR_CTX_WINSTATION_NAME_INVALID 7001L -#define ERROR_CTX_INVALID_PD 7002L -#define ERROR_CTX_PD_NOT_FOUND 7003L -#define ERROR_CTX_WD_NOT_FOUND 7004L -#define ERROR_CTX_CANNOT_MAKE_EVENTLOG_ENTRY 7005L -#define ERROR_CTX_SERVICE_NAME_COLLISION 7006L -#define ERROR_CTX_CLOSE_PENDING 7007L -#define ERROR_CTX_NO_OUTBUF 7008L -#define ERROR_CTX_MODEM_INF_NOT_FOUND 7009L -#define ERROR_CTX_INVALID_MODEMNAME 7010L -#define ERROR_CTX_MODEM_RESPONSE_ERROR 7011L -#define ERROR_CTX_MODEM_RESPONSE_TIMEOUT 7012L -#define ERROR_CTX_MODEM_RESPONSE_NO_CARRIER 7013L -#define ERROR_CTX_MODEM_RESPONSE_NO_DIALTONE 7014L -#define ERROR_CTX_MODEM_RESPONSE_BUSY 7015L -#define ERROR_CTX_MODEM_RESPONSE_VOICE 7016L -#define ERROR_CTX_TD_ERROR 7017L -#define ERROR_CTX_WINSTATION_NOT_FOUND 7022L -#define ERROR_CTX_WINSTATION_ALREADY_EXISTS 7023L -#define ERROR_CTX_WINSTATION_BUSY 7024L -#define ERROR_CTX_BAD_VIDEO_MODE 7025L -#define ERROR_CTX_GRAPHICS_INVALID 7035L -#define ERROR_CTX_LOGON_DISABLED 7037L -#define ERROR_CTX_NOT_CONSOLE 7038L -#define ERROR_CTX_CLIENT_QUERY_TIMEOUT 7040L -#define ERROR_CTX_CONSOLE_DISCONNECT 7041L -#define ERROR_CTX_CONSOLE_CONNECT 7042L -#define ERROR_CTX_SHADOW_DENIED 7044L -#define ERROR_CTX_WINSTATION_ACCESS_DENIED 7045L -#define ERROR_CTX_INVALID_WD 7049L -#define ERROR_CTX_SHADOW_INVALID 7050L -#define ERROR_CTX_SHADOW_DISABLED 7051L -#define ERROR_CTX_CLIENT_LICENSE_IN_USE 7052L -#define ERROR_CTX_CLIENT_LICENSE_NOT_SET 7053L -#define ERROR_CTX_LICENSE_NOT_AVAILABLE 7054L -#define ERROR_CTX_LICENSE_CLIENT_INVALID 7055L -#define ERROR_CTX_LICENSE_EXPIRED 7056L -#define ERROR_CTX_SHADOW_NOT_RUNNING 7057L -#define ERROR_CTX_SHADOW_ENDED_BY_MODE_CHANGE 7058L -#define ERROR_ACTIVATION_COUNT_EXCEEDED 7059L -#define FRS_ERR_INVALID_API_SEQUENCE 8001L -#define FRS_ERR_STARTING_SERVICE 8002L -#define FRS_ERR_STOPPING_SERVICE 8003L -#define FRS_ERR_INTERNAL_API 8004L -#define FRS_ERR_INTERNAL 8005L -#define FRS_ERR_SERVICE_COMM 8006L -#define FRS_ERR_INSUFFICIENT_PRIV 8007L -#define FRS_ERR_AUTHENTICATION 8008L -#define FRS_ERR_PARENT_INSUFFICIENT_PRIV 8009L -#define FRS_ERR_PARENT_AUTHENTICATION 8010L -#define FRS_ERR_CHILD_TO_PARENT_COMM 8011L -#define FRS_ERR_PARENT_TO_CHILD_COMM 8012L -#define FRS_ERR_SYSVOL_POPULATE 8013L -#define FRS_ERR_SYSVOL_POPULATE_TIMEOUT 8014L -#define FRS_ERR_SYSVOL_IS_BUSY 8015L -#define FRS_ERR_SYSVOL_DEMOTE 8016L -#define FRS_ERR_INVALID_SERVICE_PARAMETER 8017L -#define DS_S_SUCCESS NO_ERROR -#define ERROR_DS_NOT_INSTALLED 8200L -#define ERROR_DS_MEMBERSHIP_EVALUATED_LOCALLY 8201L -#define ERROR_DS_NO_ATTRIBUTE_OR_VALUE 8202L -#define ERROR_DS_INVALID_ATTRIBUTE_SYNTAX 8203L -#define ERROR_DS_ATTRIBUTE_TYPE_UNDEFINED 8204L -#define ERROR_DS_ATTRIBUTE_OR_VALUE_EXISTS 8205L -#define ERROR_DS_BUSY 8206L -#define ERROR_DS_UNAVAILABLE 8207L -#define ERROR_DS_NO_RIDS_ALLOCATED 8208L -#define ERROR_DS_NO_MORE_RIDS 8209L -#define ERROR_DS_INCORRECT_ROLE_OWNER 8210L -#define ERROR_DS_RIDMGR_INIT_ERROR 8211L -#define ERROR_DS_OBJ_CLASS_VIOLATION 8212L -#define ERROR_DS_CANT_ON_NON_LEAF 8213L -#define ERROR_DS_CANT_ON_RDN 8214L -#define ERROR_DS_CANT_MOD_OBJ_CLASS 8215L -#define ERROR_DS_CROSS_DOM_MOVE_ERROR 8216L -#define ERROR_DS_GC_NOT_AVAILABLE 8217L -#define ERROR_SHARED_POLICY 8218L -#define ERROR_POLICY_OBJECT_NOT_FOUND 8219L -#define ERROR_POLICY_ONLY_IN_DS 8220L -#define ERROR_PROMOTION_ACTIVE 8221L -#define ERROR_NO_PROMOTION_ACTIVE 8222L -#define ERROR_DS_OPERATIONS_ERROR 8224L -#define ERROR_DS_PROTOCOL_ERROR 8225L -#define ERROR_DS_TIMELIMIT_EXCEEDED 8226L -#define ERROR_DS_SIZELIMIT_EXCEEDED 8227L -#define ERROR_DS_ADMIN_LIMIT_EXCEEDED 8228L -#define ERROR_DS_COMPARE_FALSE 8229L -#define ERROR_DS_COMPARE_TRUE 8230L -#define ERROR_DS_AUTH_METHOD_NOT_SUPPORTED 8231L -#define ERROR_DS_STRONG_AUTH_REQUIRED 8232L -#define ERROR_DS_INAPPROPRIATE_AUTH 8233L -#define ERROR_DS_AUTH_UNKNOWN 8234L -#define ERROR_DS_REFERRAL 8235L -#define ERROR_DS_UNAVAILABLE_CRIT_EXTENSION 8236L -#define ERROR_DS_CONFIDENTIALITY_REQUIRED 8237L -#define ERROR_DS_INAPPROPRIATE_MATCHING 8238L -#define ERROR_DS_CONSTRAINT_VIOLATION 8239L -#define ERROR_DS_NO_SUCH_OBJECT 8240L -#define ERROR_DS_ALIAS_PROBLEM 8241L -#define ERROR_DS_INVALID_DN_SYNTAX 8242L -#define ERROR_DS_IS_LEAF 8243L -#define ERROR_DS_ALIAS_DEREF_PROBLEM 8244L -#define ERROR_DS_UNWILLING_TO_PERFORM 8245L -#define ERROR_DS_LOOP_DETECT 8246L -#define ERROR_DS_NAMING_VIOLATION 8247L -#define ERROR_DS_OBJECT_RESULTS_TOO_LARGE 8248L -#define ERROR_DS_AFFECTS_MULTIPLE_DSAS 8249L -#define ERROR_DS_SERVER_DOWN 8250L -#define ERROR_DS_LOCAL_ERROR 8251L -#define ERROR_DS_ENCODING_ERROR 8252L -#define ERROR_DS_DECODING_ERROR 8253L -#define ERROR_DS_FILTER_UNKNOWN 8254L -#define ERROR_DS_PARAM_ERROR 8255L -#define ERROR_DS_NOT_SUPPORTED 8256L -#define ERROR_DS_NO_RESULTS_RETURNED 8257L -#define ERROR_DS_CONTROL_NOT_FOUND 8258L -#define ERROR_DS_CLIENT_LOOP 8259L -#define ERROR_DS_REFERRAL_LIMIT_EXCEEDED 8260L -#define ERROR_DS_SORT_CONTROL_MISSING 8261L -#define ERROR_DS_OFFSET_RANGE_ERROR 8262L -#define ERROR_DS_ROOT_MUST_BE_NC 8301L -#define ERROR_DS_ADD_REPLICA_INHIBITED 8302L -#define ERROR_DS_ATT_NOT_DEF_IN_SCHEMA 8303L -#define ERROR_DS_MAX_OBJ_SIZE_EXCEEDED 8304L -#define ERROR_DS_OBJ_STRING_NAME_EXISTS 8305L -#define ERROR_DS_NO_RDN_DEFINED_IN_SCHEMA 8306L -#define ERROR_DS_RDN_DOESNT_MATCH_SCHEMA 8307L -#define ERROR_DS_NO_REQUESTED_ATTS_FOUND 8308L -#define ERROR_DS_USER_BUFFER_TO_SMALL 8309L -#define ERROR_DS_ATT_IS_NOT_ON_OBJ 8310L -#define ERROR_DS_ILLEGAL_MOD_OPERATION 8311L -#define ERROR_DS_OBJ_TOO_LARGE 8312L -#define ERROR_DS_BAD_INSTANCE_TYPE 8313L -#define ERROR_DS_MASTERDSA_REQUIRED 8314L -#define ERROR_DS_OBJECT_CLASS_REQUIRED 8315L -#define ERROR_DS_MISSING_REQUIRED_ATT 8316L -#define ERROR_DS_ATT_NOT_DEF_FOR_CLASS 8317L -#define ERROR_DS_ATT_ALREADY_EXISTS 8318L -#define ERROR_DS_CANT_ADD_ATT_VALUES 8320L -#define ERROR_DS_SINGLE_VALUE_CONSTRAINT 8321L -#define ERROR_DS_RANGE_CONSTRAINT 8322L -#define ERROR_DS_ATT_VAL_ALREADY_EXISTS 8323L -#define ERROR_DS_CANT_REM_MISSING_ATT 8324L -#define ERROR_DS_CANT_REM_MISSING_ATT_VAL 8325L -#define ERROR_DS_ROOT_CANT_BE_SUBREF 8326L -#define ERROR_DS_NO_CHAINING 8327L -#define ERROR_DS_NO_CHAINED_EVAL 8328L -#define ERROR_DS_NO_PARENT_OBJECT 8329L -#define ERROR_DS_PARENT_IS_AN_ALIAS 8330L -#define ERROR_DS_CANT_MIX_MASTER_AND_REPS 8331L -#define ERROR_DS_CHILDREN_EXIST 8332L -#define ERROR_DS_OBJ_NOT_FOUND 8333L -#define ERROR_DS_ALIASED_OBJ_MISSING 8334L -#define ERROR_DS_BAD_NAME_SYNTAX 8335L -#define ERROR_DS_ALIAS_POINTS_TO_ALIAS 8336L -#define ERROR_DS_CANT_DEREF_ALIAS 8337L -#define ERROR_DS_OUT_OF_SCOPE 8338L -#define ERROR_DS_OBJECT_BEING_REMOVED 8339L -#define ERROR_DS_CANT_DELETE_DSA_OBJ 8340L -#define ERROR_DS_GENERIC_ERROR 8341L -#define ERROR_DS_DSA_MUST_BE_INT_MASTER 8342L -#define ERROR_DS_CLASS_NOT_DSA 8343L -#define ERROR_DS_INSUFF_ACCESS_RIGHTS 8344L -#define ERROR_DS_ILLEGAL_SUPERIOR 8345L -#define ERROR_DS_ATTRIBUTE_OWNED_BY_SAM 8346L -#define ERROR_DS_NAME_TOO_MANY_PARTS 8347L -#define ERROR_DS_NAME_TOO_LONG 8348L -#define ERROR_DS_NAME_VALUE_TOO_LONG 8349L -#define ERROR_DS_NAME_UNPARSEABLE 8350L -#define ERROR_DS_NAME_TYPE_UNKNOWN 8351L -#define ERROR_DS_NOT_AN_OBJECT 8352L -#define ERROR_DS_SEC_DESC_TOO_SHORT 8353L -#define ERROR_DS_SEC_DESC_INVALID 8354L -#define ERROR_DS_NO_DELETED_NAME 8355L -#define ERROR_DS_SUBREF_MUST_HAVE_PARENT 8356L -#define ERROR_DS_NCNAME_MUST_BE_NC 8357L -#define ERROR_DS_CANT_ADD_SYSTEM_ONLY 8358L -#define ERROR_DS_CLASS_MUST_BE_CONCRETE 8359L -#define ERROR_DS_INVALID_DMD 8360L -#define ERROR_DS_OBJ_GUID_EXISTS 8361L -#define ERROR_DS_NOT_ON_BACKLINK 8362L -#define ERROR_DS_NO_CROSSREF_FOR_NC 8363L -#define ERROR_DS_SHUTTING_DOWN 8364L -#define ERROR_DS_UNKNOWN_OPERATION 8365L -#define ERROR_DS_INVALID_ROLE_OWNER 8366L -#define ERROR_DS_COULDNT_CONTACT_FSMO 8367L -#define ERROR_DS_CROSS_NC_DN_RENAME 8368L -#define ERROR_DS_CANT_MOD_SYSTEM_ONLY 8369L -#define ERROR_DS_REPLICATOR_ONLY 8370L -#define ERROR_DS_OBJ_CLASS_NOT_DEFINED 8371L -#define ERROR_DS_OBJ_CLASS_NOT_SUBCLASS 8372L -#define ERROR_DS_NAME_REFERENCE_INVALID 8373L -#define ERROR_DS_CROSS_REF_EXISTS 8374L -#define ERROR_DS_CANT_DEL_MASTER_CROSSREF 8375L -#define ERROR_DS_SUBTREE_NOTIFY_NOT_NC_HEAD 8376L -#define ERROR_DS_NOTIFY_FILTER_TOO_COMPLEX 8377L -#define ERROR_DS_DUP_RDN 8378L -#define ERROR_DS_DUP_OID 8379L -#define ERROR_DS_DUP_MAPI_ID 8380L -#define ERROR_DS_DUP_SCHEMA_ID_GUID 8381L -#define ERROR_DS_DUP_LDAP_DISPLAY_NAME 8382L -#define ERROR_DS_SEMANTIC_ATT_TEST 8383L -#define ERROR_DS_SYNTAX_MISMATCH 8384L -#define ERROR_DS_EXISTS_IN_MUST_HAVE 8385L -#define ERROR_DS_EXISTS_IN_MAY_HAVE 8386L -#define ERROR_DS_NONEXISTENT_MAY_HAVE 8387L -#define ERROR_DS_NONEXISTENT_MUST_HAVE 8388L -#define ERROR_DS_AUX_CLS_TEST_FAIL 8389L -#define ERROR_DS_NONEXISTENT_POSS_SUP 8390L -#define ERROR_DS_SUB_CLS_TEST_FAIL 8391L -#define ERROR_DS_BAD_RDN_ATT_ID_SYNTAX 8392L -#define ERROR_DS_EXISTS_IN_AUX_CLS 8393L -#define ERROR_DS_EXISTS_IN_SUB_CLS 8394L -#define ERROR_DS_EXISTS_IN_POSS_SUP 8395L -#define ERROR_DS_RECALCSCHEMA_FAILED 8396L -#define ERROR_DS_TREE_DELETE_NOT_FINISHED 8397L -#define ERROR_DS_CANT_DELETE 8398L -#define ERROR_DS_ATT_SCHEMA_REQ_ID 8399L -#define ERROR_DS_BAD_ATT_SCHEMA_SYNTAX 8400L -#define ERROR_DS_CANT_CACHE_ATT 8401L -#define ERROR_DS_CANT_CACHE_CLASS 8402L -#define ERROR_DS_CANT_REMOVE_ATT_CACHE 8403L -#define ERROR_DS_CANT_REMOVE_CLASS_CACHE 8404L -#define ERROR_DS_CANT_RETRIEVE_DN 8405L -#define ERROR_DS_MISSING_SUPREF 8406L -#define ERROR_DS_CANT_RETRIEVE_INSTANCE 8407L -#define ERROR_DS_CODE_INCONSISTENCY 8408L -#define ERROR_DS_DATABASE_ERROR 8409L -#define ERROR_DS_GOVERNSID_MISSING 8410L -#define ERROR_DS_MISSING_EXPECTED_ATT 8411L -#define ERROR_DS_NCNAME_MISSING_CR_REF 8412L -#define ERROR_DS_SECURITY_CHECKING_ERROR 8413L -#define ERROR_DS_SCHEMA_NOT_LOADED 8414L -#define ERROR_DS_SCHEMA_ALLOC_FAILED 8415L -#define ERROR_DS_ATT_SCHEMA_REQ_SYNTAX 8416L -#define ERROR_DS_GCVERIFY_ERROR 8417L -#define ERROR_DS_DRA_SCHEMA_MISMATCH 8418L -#define ERROR_DS_CANT_FIND_DSA_OBJ 8419L -#define ERROR_DS_CANT_FIND_EXPECTED_NC 8420L -#define ERROR_DS_CANT_FIND_NC_IN_CACHE 8421L -#define ERROR_DS_CANT_RETRIEVE_CHILD 8422L -#define ERROR_DS_SECURITY_ILLEGAL_MODIFY 8423L -#define ERROR_DS_CANT_REPLACE_HIDDEN_REC 8424L -#define ERROR_DS_BAD_HIERARCHY_FILE 8425L -#define ERROR_DS_BUILD_HIERARCHY_TABLE_FAILED 8426L -#define ERROR_DS_CONFIG_PARAM_MISSING 8427L -#define ERROR_DS_COUNTING_AB_INDICES_FAILED 8428L -#define ERROR_DS_HIERARCHY_TABLE_MALLOC_FAILED 8429L -#define ERROR_DS_INTERNAL_FAILURE 8430L -#define ERROR_DS_UNKNOWN_ERROR 8431L -#define ERROR_DS_ROOT_REQUIRES_CLASS_TOP 8432L -#define ERROR_DS_REFUSING_FSMO_ROLES 8433L -#define ERROR_DS_MISSING_FSMO_SETTINGS 8434L -#define ERROR_DS_UNABLE_TO_SURRENDER_ROLES 8435L -#define ERROR_DS_DRA_GENERIC 8436L -#define ERROR_DS_DRA_INVALID_PARAMETER 8437L -#define ERROR_DS_DRA_BUSY 8438L -#define ERROR_DS_DRA_BAD_DN 8439L -#define ERROR_DS_DRA_BAD_NC 8440L -#define ERROR_DS_DRA_DN_EXISTS 8441L -#define ERROR_DS_DRA_INTERNAL_ERROR 8442L -#define ERROR_DS_DRA_INCONSISTENT_DIT 8443L -#define ERROR_DS_DRA_CONNECTION_FAILED 8444L -#define ERROR_DS_DRA_BAD_INSTANCE_TYPE 8445L -#define ERROR_DS_DRA_OUT_OF_MEM 8446L -#define ERROR_DS_DRA_MAIL_PROBLEM 8447L -#define ERROR_DS_DRA_REF_ALREADY_EXISTS 8448L -#define ERROR_DS_DRA_REF_NOT_FOUND 8449L -#define ERROR_DS_DRA_OBJ_IS_REP_SOURCE 8450L -#define ERROR_DS_DRA_DB_ERROR 8451L -#define ERROR_DS_DRA_NO_REPLICA 8452L -#define ERROR_DS_DRA_ACCESS_DENIED 8453L -#define ERROR_DS_DRA_NOT_SUPPORTED 8454L -#define ERROR_DS_DRA_RPC_CANCELLED 8455L -#define ERROR_DS_DRA_SOURCE_DISABLED 8456L -#define ERROR_DS_DRA_SINK_DISABLED 8457L -#define ERROR_DS_DRA_NAME_COLLISION 8458L -#define ERROR_DS_DRA_SOURCE_REINSTALLED 8459L -#define ERROR_DS_DRA_MISSING_PARENT 8460L -#define ERROR_DS_DRA_PREEMPTED 8461L -#define ERROR_DS_DRA_ABANDON_SYNC 8462L -#define ERROR_DS_DRA_SHUTDOWN 8463L -#define ERROR_DS_DRA_INCOMPATIBLE_PARTIAL_SET 8464L -#define ERROR_DS_DRA_SOURCE_IS_PARTIAL_REPLICA 8465L -#define ERROR_DS_DRA_EXTN_CONNECTION_FAILED 8466L -#define ERROR_DS_INSTALL_SCHEMA_MISMATCH 8467L -#define ERROR_DS_DUP_LINK_ID 8468L -#define ERROR_DS_NAME_ERROR_RESOLVING 8469L -#define ERROR_DS_NAME_ERROR_NOT_FOUND 8470L -#define ERROR_DS_NAME_ERROR_NOT_UNIQUE 8471L -#define ERROR_DS_NAME_ERROR_NO_MAPPING 8472L -#define ERROR_DS_NAME_ERROR_DOMAIN_ONLY 8473L -#define ERROR_DS_NAME_ERROR_NO_SYNTACTICAL_MAPPING 8474L -#define ERROR_DS_CONSTRUCTED_ATT_MOD 8475L -#define ERROR_DS_WRONG_OM_OBJ_CLASS 8476L -#define ERROR_DS_DRA_REPL_PENDING 8477L -#define ERROR_DS_DS_REQUIRED 8478L -#define ERROR_DS_INVALID_LDAP_DISPLAY_NAME 8479L -#define ERROR_DS_NON_BASE_SEARCH 8480L -#define ERROR_DS_CANT_RETRIEVE_ATTS 8481L -#define ERROR_DS_BACKLINK_WITHOUT_LINK 8482L -#define ERROR_DS_EPOCH_MISMATCH 8483L -#define ERROR_DS_SRC_NAME_MISMATCH 8484L -#define ERROR_DS_SRC_AND_DST_NC_IDENTICAL 8485L -#define ERROR_DS_DST_NC_MISMATCH 8486L -#define ERROR_DS_NOT_AUTHORITIVE_FOR_DST_NC 8487L -#define ERROR_DS_SRC_GUID_MISMATCH 8488L -#define ERROR_DS_CANT_MOVE_DELETED_OBJECT 8489L -#define ERROR_DS_PDC_OPERATION_IN_PROGRESS 8490L -#define ERROR_DS_CROSS_DOMAIN_CLEANUP_REQD 8491L -#define ERROR_DS_ILLEGAL_XDOM_MOVE_OPERATION 8492L -#define ERROR_DS_CANT_WITH_ACCT_GROUP_MEMBERSHPS 8493L -#define ERROR_DS_NC_MUST_HAVE_NC_PARENT 8494L -#define ERROR_DS_CR_IMPOSSIBLE_TO_VALIDATE 8495L -#define ERROR_DS_DST_DOMAIN_NOT_NATIVE 8496L -#define ERROR_DS_MISSING_INFRASTRUCTURE_CONTAINER 8497L -#define ERROR_DS_CANT_MOVE_ACCOUNT_GROUP 8498L -#define ERROR_DS_CANT_MOVE_RESOURCE_GROUP 8499L -#define ERROR_DS_INVALID_SEARCH_FLAG 8500L -#define ERROR_DS_NO_TREE_DELETE_ABOVE_NC 8501L -#define ERROR_DS_COULDNT_LOCK_TREE_FOR_DELETE 8502L -#define ERROR_DS_COULDNT_IDENTIFY_OBJECTS_FOR_TREE_DELETE 8503L -#define ERROR_DS_SAM_INIT_FAILURE 8504L -#define ERROR_DS_SENSITIVE_GROUP_VIOLATION 8505L -#define ERROR_DS_CANT_MOD_PRIMARYGROUPID 8506L -#define ERROR_DS_ILLEGAL_BASE_SCHEMA_MOD 8507L -#define ERROR_DS_NONSAFE_SCHEMA_CHANGE 8508L -#define ERROR_DS_SCHEMA_UPDATE_DISALLOWED 8509L -#define ERROR_DS_CANT_CREATE_UNDER_SCHEMA 8510L -#define ERROR_DS_INSTALL_NO_SRC_SCH_VERSION 8511L -#define ERROR_DS_INSTALL_NO_SCH_VERSION_IN_INIFILE 8512L -#define ERROR_DS_INVALID_GROUP_TYPE 8513L -#define ERROR_DS_NO_NEST_GLOBALGROUP_IN_MIXEDDOMAIN 8514L -#define ERROR_DS_NO_NEST_LOCALGROUP_IN_MIXEDDOMAIN 8515L -#define ERROR_DS_GLOBAL_CANT_HAVE_LOCAL_MEMBER 8516L -#define ERROR_DS_GLOBAL_CANT_HAVE_UNIVERSAL_MEMBER 8517L -#define ERROR_DS_UNIVERSAL_CANT_HAVE_LOCAL_MEMBER 8518L -#define ERROR_DS_GLOBAL_CANT_HAVE_CROSSDOMAIN_MEMBER 8519L -#define ERROR_DS_LOCAL_CANT_HAVE_CROSSDOMAIN_LOCAL_MEMBER 8520L -#define ERROR_DS_HAVE_PRIMARY_MEMBERS 8521L -#define ERROR_DS_STRING_SD_CONVERSION_FAILED 8522L -#define ERROR_DS_NAMING_MASTER_GC 8523L -#define ERROR_DS_DNS_LOOKUP_FAILURE 8524L -#define ERROR_DS_COULDNT_UPDATE_SPNS 8525L -#define ERROR_DS_CANT_RETRIEVE_SD 8526L -#define ERROR_DS_KEY_NOT_UNIQUE 8527L -#define ERROR_DS_WRONG_LINKED_ATT_SYNTAX 8528L -#define ERROR_DS_SAM_NEED_BOOTKEY_PASSWORD 8529L -#define ERROR_DS_SAM_NEED_BOOTKEY_FLOPPY 8530L -#define ERROR_DS_CANT_START 8531L -#define ERROR_DS_INIT_FAILURE 8532L -#define ERROR_DS_NO_PKT_PRIVACY_ON_CONNECTION 8533L -#define ERROR_DS_SOURCE_DOMAIN_IN_FOREST 8534L -#define ERROR_DS_DESTINATION_DOMAIN_NOT_IN_FOREST 8535L -#define ERROR_DS_DESTINATION_AUDITING_NOT_ENABLED 8536L -#define ERROR_DS_CANT_FIND_DC_FOR_SRC_DOMAIN 8537L -#define ERROR_DS_SRC_OBJ_NOT_GROUP_OR_USER 8538L -#define ERROR_DS_SRC_SID_EXISTS_IN_FOREST 8539L -#define ERROR_DS_SRC_AND_DST_OBJECT_CLASS_MISMATCH 8540L -#define ERROR_SAM_INIT_FAILURE 8541L -#define ERROR_DS_DRA_SCHEMA_INFO_SHIP 8542L -#define ERROR_DS_DRA_SCHEMA_CONFLICT 8543L -#define ERROR_DS_DRA_EARLIER_SCHEMA_CONFLICT 8544L -#define ERROR_DS_DRA_OBJ_NC_MISMATCH 8545L -#define ERROR_DS_NC_STILL_HAS_DSAS 8546L -#define ERROR_DS_GC_REQUIRED 8547L -#define ERROR_DS_LOCAL_MEMBER_OF_LOCAL_ONLY 8548L -#define ERROR_DS_NO_FPO_IN_UNIVERSAL_GROUPS 8549L -#define ERROR_DS_CANT_ADD_TO_GC 8550L -#define ERROR_DS_NO_CHECKPOINT_WITH_PDC 8551L -#define ERROR_DS_SOURCE_AUDITING_NOT_ENABLED 8552L -#define ERROR_DS_CANT_CREATE_IN_NONDOMAIN_NC 8553L -#define ERROR_DS_INVALID_NAME_FOR_SPN 8554L -#define ERROR_DS_FILTER_USES_CONTRUCTED_ATTRS 8555L -#define ERROR_DS_UNICODEPWD_NOT_IN_QUOTES 8556L -#define ERROR_DS_MACHINE_ACCOUNT_QUOTA_EXCEEDED 8557L -#define ERROR_DS_MUST_BE_RUN_ON_DST_DC 8558L -#define ERROR_DS_SRC_DC_MUST_BE_SP4_OR_GREATER 8559L -#define ERROR_DS_CANT_TREE_DELETE_CRITICAL_OBJ 8560L -#define ERROR_DS_INIT_FAILURE_CONSOLE 8561L -#define ERROR_DS_SAM_INIT_FAILURE_CONSOLE 8562L -#define ERROR_DS_FOREST_VERSION_TOO_HIGH 8563L -#define ERROR_DS_DOMAIN_VERSION_TOO_HIGH 8564L -#define ERROR_DS_FOREST_VERSION_TOO_LOW 8565L -#define ERROR_DS_DOMAIN_VERSION_TOO_LOW 8566L -#define ERROR_DS_INCOMPATIBLE_VERSION 8567L -#define ERROR_DS_LOW_DSA_VERSION 8568L -#define ERROR_DS_NO_BEHAVIOR_VERSION_IN_MIXEDDOMAIN 8569L -#define ERROR_DS_NOT_SUPPORTED_SORT_ORDER 8570L -#define ERROR_DS_NAME_NOT_UNIQUE 8571L -#define ERROR_DS_MACHINE_ACCOUNT_CREATED_PRENT4 8572L -#define ERROR_DS_OUT_OF_VERSION_STORE 8573L -#define ERROR_DS_INCOMPATIBLE_CONTROLS_USED 8574L -#define ERROR_DS_NO_REF_DOMAIN 8575L -#define ERROR_DS_RESERVED_LINK_ID 8576L -#define ERROR_DS_LINK_ID_NOT_AVAILABLE 8577L -#define ERROR_DS_AG_CANT_HAVE_UNIVERSAL_MEMBER 8578L -#define ERROR_DS_MODIFYDN_DISALLOWED_BY_INSTANCE_TYPE 8579L -#define ERROR_DS_NO_OBJECT_MOVE_IN_SCHEMA_NC 8580L -#define ERROR_DS_MODIFYDN_DISALLOWED_BY_FLAG 8581L -#define ERROR_DS_MODIFYDN_WRONG_GRANDPARENT 8582L -#define ERROR_DS_NAME_ERROR_TRUST_REFERRAL 8583L -#define ERROR_NOT_SUPPORTED_ON_STANDARD_SERVER 8584L -#define ERROR_DS_CANT_ACCESS_REMOTE_PART_OF_AD 8585L -#define ERROR_DS_CR_IMPOSSIBLE_TO_VALIDATE_V2 8586L -#define ERROR_DS_THREAD_LIMIT_EXCEEDED 8587L -#define ERROR_DS_NOT_CLOSEST 8588L -#define ERROR_DS_CANT_DERIVE_SPN_WITHOUT_SERVER_REF 8589L -#define ERROR_DS_SINGLE_USER_MODE_FAILED 8590L -#define ERROR_DS_NTDSCRIPT_SYNTAX_ERROR 8591L -#define ERROR_DS_NTDSCRIPT_PROCESS_ERROR 8592L -#define ERROR_DS_DIFFERENT_REPL_EPOCHS 8593L -#define ERROR_DS_DRS_EXTENSIONS_CHANGED 8594L -#define ERROR_DS_REPLICA_SET_CHANGE_NOT_ALLOWED_ON_DISABLED_CR 8595L -#define ERROR_DS_NO_MSDS_INTID 8596L -#define ERROR_DS_DUP_MSDS_INTID 8597L -#define ERROR_DS_EXISTS_IN_RDNATTID 8598L -#define ERROR_DS_AUTHORIZATION_FAILED 8599L -#define ERROR_DS_INVALID_SCRIPT 8600L -#define ERROR_DS_REMOTE_CROSSREF_OP_FAILED 8601L -#define ERROR_DS_CROSS_REF_BUSY 8602L -#define ERROR_DS_CANT_DERIVE_SPN_FOR_DELETED_DOMAIN 8603L -#define ERROR_DS_CANT_DEMOTE_WITH_WRITEABLE_NC 8604L -#define ERROR_DS_DUPLICATE_ID_FOUND 8605L -#define ERROR_DS_INSUFFICIENT_ATTR_TO_CREATE_OBJECT 8606L -#define ERROR_DS_GROUP_CONVERSION_ERROR 8607L -#define ERROR_DS_CANT_MOVE_APP_BASIC_GROUP 8608L -#define ERROR_DS_CANT_MOVE_APP_QUERY_GROUP 8609L -#define ERROR_DS_ROLE_NOT_VERIFIED 8610L -#define ERROR_DS_WKO_CONTAINER_CANNOT_BE_SPECIAL 8611L -#define ERROR_DS_DOMAIN_RENAME_IN_PROGRESS 8612L -#define ERROR_DS_EXISTING_AD_CHILD_NC 8613L -#define ERROR_DS_REPL_LIFETIME_EXCEEDED 8614L -#define ERROR_DS_DISALLOWED_IN_SYSTEM_CONTAINER 8615L -#define ERROR_DS_LDAP_SEND_QUEUE_FULL 8616L -#define ERROR_DS_DRA_OUT_SCHEDULE_WINDOW 8617L -#define DNS_ERROR_RESPONSE_CODES_BASE 9000 -#define DNS_ERROR_RCODE_NO_ERROR NO_ERROR -#define DNS_ERROR_MASK 0x00002328 -#define DNS_ERROR_RCODE_FORMAT_ERROR 9001L -#define DNS_ERROR_RCODE_SERVER_FAILURE 9002L -#define DNS_ERROR_RCODE_NAME_ERROR 9003L -#define DNS_ERROR_RCODE_NOT_IMPLEMENTED 9004L -#define DNS_ERROR_RCODE_REFUSED 9005L -#define DNS_ERROR_RCODE_YXDOMAIN 9006L -#define DNS_ERROR_RCODE_YXRRSET 9007L -#define DNS_ERROR_RCODE_NXRRSET 9008L -#define DNS_ERROR_RCODE_NOTAUTH 9009L -#define DNS_ERROR_RCODE_NOTZONE 9010L -#define DNS_ERROR_RCODE_BADSIG 9016L -#define DNS_ERROR_RCODE_BADKEY 9017L -#define DNS_ERROR_RCODE_BADTIME 9018L -#define DNS_ERROR_RCODE_LAST DNS_ERROR_RCODE_BADTIME -#define DNS_ERROR_PACKET_FMT_BASE 9500 -#define DNS_INFO_NO_RECORDS 9501L -#define DNS_ERROR_BAD_PACKET 9502L -#define DNS_ERROR_NO_PACKET 9503L -#define DNS_ERROR_RCODE 9504L -#define DNS_ERROR_UNSECURE_PACKET 9505L -#define DNS_STATUS_PACKET_UNSECURE DNS_ERROR_UNSECURE_PACKET -#define DNS_ERROR_NO_MEMORY ERROR_OUTOFMEMORY -#define DNS_ERROR_INVALID_NAME ERROR_INVALID_NAME -#define DNS_ERROR_INVALID_DATA ERROR_INVALID_DATA -#define DNS_ERROR_GENERAL_API_BASE 9550 -#define DNS_ERROR_INVALID_TYPE 9551L -#define DNS_ERROR_INVALID_IP_ADDRESS 9552L -#define DNS_ERROR_INVALID_PROPERTY 9553L -#define DNS_ERROR_TRY_AGAIN_LATER 9554L -#define DNS_ERROR_NOT_UNIQUE 9555L -#define DNS_ERROR_NON_RFC_NAME 9556L -#define DNS_STATUS_FQDN 9557L -#define DNS_STATUS_DOTTED_NAME 9558L -#define DNS_STATUS_SINGLE_PART_NAME 9559L -#define DNS_ERROR_INVALID_NAME_CHAR 9560L -#define DNS_ERROR_NUMERIC_NAME 9561L -#define DNS_ERROR_NOT_ALLOWED_ON_ROOT_SERVER 9562L -#define DNS_ERROR_NOT_ALLOWED_UNDER_DELEGATION 9563L -#define DNS_ERROR_CANNOT_FIND_ROOT_HINTS 9564L -#define DNS_ERROR_INCONSISTENT_ROOT_HINTS 9565L -#define DNS_ERROR_ZONE_BASE 9600 -#define DNS_ERROR_ZONE_DOES_NOT_EXIST 9601L -#define DNS_ERROR_NO_ZONE_INFO 9602L -#define DNS_ERROR_INVALID_ZONE_OPERATION 9603L -#define DNS_ERROR_ZONE_CONFIGURATION_ERROR 9604L -#define DNS_ERROR_ZONE_HAS_NO_SOA_RECORD 9605L -#define DNS_ERROR_ZONE_HAS_NO_NS_RECORDS 9606L -#define DNS_ERROR_ZONE_LOCKED 9607L -#define DNS_ERROR_ZONE_CREATION_FAILED 9608L -#define DNS_ERROR_ZONE_ALREADY_EXISTS 9609L -#define DNS_ERROR_AUTOZONE_ALREADY_EXISTS 9610L -#define DNS_ERROR_INVALID_ZONE_TYPE 9611L -#define DNS_ERROR_SECONDARY_REQUIRES_MASTER_IP 9612L -#define DNS_ERROR_ZONE_NOT_SECONDARY 9613L -#define DNS_ERROR_NEED_SECONDARY_ADDRESSES 9614L -#define DNS_ERROR_WINS_INIT_FAILED 9615L -#define DNS_ERROR_NEED_WINS_SERVERS 9616L -#define DNS_ERROR_NBSTAT_INIT_FAILED 9617L -#define DNS_ERROR_SOA_DELETE_INVALID 9618L -#define DNS_ERROR_FORWARDER_ALREADY_EXISTS 9619L -#define DNS_ERROR_ZONE_REQUIRES_MASTER_IP 9620L -#define DNS_ERROR_ZONE_IS_SHUTDOWN 9621L -#define DNS_ERROR_DATAFILE_BASE 9650 -#define DNS_ERROR_PRIMARY_REQUIRES_DATAFILE 9651L -#define DNS_ERROR_INVALID_DATAFILE_NAME 9652L -#define DNS_ERROR_DATAFILE_OPEN_FAILURE 9653L -#define DNS_ERROR_FILE_WRITEBACK_FAILED 9654L -#define DNS_ERROR_DATAFILE_PARSING 9655L -#define DNS_ERROR_DATABASE_BASE 9700 -#define DNS_ERROR_RECORD_DOES_NOT_EXIST 9701L -#define DNS_ERROR_RECORD_FORMAT 9702L -#define DNS_ERROR_NODE_CREATION_FAILED 9703L -#define DNS_ERROR_UNKNOWN_RECORD_TYPE 9704L -#define DNS_ERROR_RECORD_TIMED_OUT 9705L -#define DNS_ERROR_NAME_NOT_IN_ZONE 9706L -#define DNS_ERROR_CNAME_LOOP 9707L -#define DNS_ERROR_NODE_IS_CNAME 9708L -#define DNS_ERROR_CNAME_COLLISION 9709L -#define DNS_ERROR_RECORD_ONLY_AT_ZONE_ROOT 9710L -#define DNS_ERROR_RECORD_ALREADY_EXISTS 9711L -#define DNS_ERROR_SECONDARY_DATA 9712L -#define DNS_ERROR_NO_CREATE_CACHE_DATA 9713L -#define DNS_ERROR_NAME_DOES_NOT_EXIST 9714L -#define DNS_WARNING_PTR_CREATE_FAILED 9715L -#define DNS_WARNING_DOMAIN_UNDELETED 9716L -#define DNS_ERROR_DS_UNAVAILABLE 9717L -#define DNS_ERROR_DS_ZONE_ALREADY_EXISTS 9718L -#define DNS_ERROR_NO_BOOTFILE_IF_DS_ZONE 9719L -#define DNS_ERROR_OPERATION_BASE 9750 -#define DNS_INFO_AXFR_COMPLETE 9751L -#define DNS_ERROR_AXFR 9752L -#define DNS_INFO_ADDED_LOCAL_WINS 9753L -#define DNS_ERROR_SECURE_BASE 9800 -#define DNS_STATUS_CONTINUE_NEEDED 9801L -#define DNS_ERROR_SETUP_BASE 9850 -#define DNS_ERROR_NO_TCPIP 9851L -#define DNS_ERROR_NO_DNS_SERVERS 9852L -#define DNS_ERROR_DP_BASE 9900 -#define DNS_ERROR_DP_DOES_NOT_EXIST 9901L -#define DNS_ERROR_DP_ALREADY_EXISTS 9902L -#define DNS_ERROR_DP_NOT_ENLISTED 9903L -#define DNS_ERROR_DP_ALREADY_ENLISTED 9904L -#define DNS_ERROR_DP_NOT_AVAILABLE 9905L -#define DNS_ERROR_DP_FSMO_ERROR 9906L - -#ifndef WSABASEERR -#define WSABASEERR 10000 -#define WSAEINTR 10004L -#define WSAEBADF 10009L -#define WSAEACCES 10013L -#define WSAEFAULT 10014L -#define WSAEINVAL 10022L -#define WSAEMFILE 10024L -#define WSAEWOULDBLOCK 10035L -#define WSAEINPROGRESS 10036L -#define WSAEALREADY 10037L -#define WSAENOTSOCK 10038L -#define WSAEDESTADDRREQ 10039L -#define WSAEMSGSIZE 10040L -#define WSAEPROTOTYPE 10041L -#define WSAENOPROTOOPT 10042L -#define WSAEPROTONOSUPPORT 10043L -#define WSAESOCKTNOSUPPORT 10044L -#define WSAEOPNOTSUPP 10045L -#define WSAEPFNOSUPPORT 10046L -#define WSAEAFNOSUPPORT 10047L -#define WSAEADDRINUSE 10048L -#define WSAEADDRNOTAVAIL 10049L -#define WSAENETDOWN 10050L -#define WSAENETUNREACH 10051L -#define WSAENETRESET 10052L -#define WSAECONNABORTED 10053L -#define WSAECONNRESET 10054L -#define WSAENOBUFS 10055L -#define WSAEISCONN 10056L -#define WSAENOTCONN 10057L -#define WSAESHUTDOWN 10058L -#define WSAETOOMANYREFS 10059L -#define WSAETIMEDOUT 10060L -#define WSAECONNREFUSED 10061L -#define WSAELOOP 10062L -#define WSAENAMETOOLONG 10063L -#define WSAEHOSTDOWN 10064L -#define WSAEHOSTUNREACH 10065L -#define WSAENOTEMPTY 10066L -#define WSAEPROCLIM 10067L -#define WSAEUSERS 10068L -#define WSAEDQUOT 10069L -#define WSAESTALE 10070L -#define WSAEREMOTE 10071L -#define WSASYSNOTREADY 10091L -#define WSAVERNOTSUPPORTED 10092L -#define WSANOTINITIALISED 10093L -#define WSAEDISCON 10101L -#define WSAENOMORE 10102L -#define WSAECANCELLED 10103L -#define WSAEINVALIDPROCTABLE 10104L -#define WSAEINVALIDPROVIDER 10105L -#define WSAEPROVIDERFAILEDINIT 10106L -#define WSASYSCALLFAILURE 10107L -#define WSASERVICE_NOT_FOUND 10108L -#define WSATYPE_NOT_FOUND 10109L -#define WSA_E_NO_MORE 10110L -#define WSA_E_CANCELLED 10111L -#define WSAEREFUSED 10112L -#ifndef WSAHOST_NOT_FOUND -#define WSAHOST_NOT_FOUND 11001L -#endif -#ifndef WSATRY_AGAIN -#define WSATRY_AGAIN 11002L -#endif -#ifndef WSANO_RECOVERY -#define WSANO_RECOVERY 11003L -#endif -#ifndef WSANO_DATA -#define WSANO_DATA 11004L -#endif -#ifndef WSA_QOS_RECEIVERS -#define WSA_QOS_RECEIVERS 11005L -#endif -#ifndef WSA_QOS_SENDERS -#define WSA_QOS_SENDERS 11006L -#endif -#ifndef WSA_QOS_NO_SENDERS -#define WSA_QOS_NO_SENDERS 11007L -#endif -#ifndef WSA_QOS_NO_RECEIVERS -#define WSA_QOS_NO_RECEIVERS 11008L -#endif -#ifndef WSA_QOS_REQUEST_CONFIRMED -#define WSA_QOS_REQUEST_CONFIRMED 11009L -#endif -#ifndef WSA_QOS_ADMISSION_FAILURE -#define WSA_QOS_ADMISSION_FAILURE 11010L -#endif -#ifndef WSA_QOS_POLICY_FAILURE -#define WSA_QOS_POLICY_FAILURE 11011L -#endif -#ifndef WSA_QOS_BAD_STYLE -#define WSA_QOS_BAD_STYLE 11012L -#endif -#ifndef WSA_QOS_BAD_OBJECT -#define WSA_QOS_BAD_OBJECT 11013L -#endif -#ifndef WSA_QOS_TRAFFIC_CTRL_ERROR -#define WSA_QOS_TRAFFIC_CTRL_ERROR 11014L -#endif -#ifndef WSA_QOS_GENERIC_ERROR -#define WSA_QOS_GENERIC_ERROR 11015L -#endif -#ifndef WSA_QOS_ESERVICETYPE -#define WSA_QOS_ESERVICETYPE 11016L -#endif -#ifndef WSA_QOS_EFLOWSPEC -#define WSA_QOS_EFLOWSPEC 11017L -#endif -#ifndef WSA_QOS_EPROVSPECBUF -#define WSA_QOS_EPROVSPECBUF 11018L -#endif -#ifndef WSA_QOS_EFILTERSTYLE -#define WSA_QOS_EFILTERSTYLE 11019L -#endif -#ifndef WSA_QOS_EFILTERTYPE -#define WSA_QOS_EFILTERTYPE 11020L -#endif -#ifndef WSA_QOS_EFILTERCOUNT -#define WSA_QOS_EFILTERCOUNT 11021L -#endif -#ifndef WSA_QOS_EOBJLENGTH -#define WSA_QOS_EOBJLENGTH 11022L -#endif -#ifndef WSA_QOS_EFLOWCOUNT -#define WSA_QOS_EFLOWCOUNT 11023L -#endif -#ifndef WSA_QOS_EUNKNOWNPSOBJ -#define WSA_QOS_EUNKNOWNPSOBJ 11024L -#endif -#ifndef WSA_QOS_EPOLICYOBJ -#define WSA_QOS_EPOLICYOBJ 11025L -#endif -#ifndef WSA_QOS_EFLOWDESC -#define WSA_QOS_EFLOWDESC 11026L -#endif -#ifndef WSA_QOS_EPSFLOWSPEC -#define WSA_QOS_EPSFLOWSPEC 11027L -#endif -#ifndef WSA_QOS_EPSFILTERSPEC -#define WSA_QOS_EPSFILTERSPEC 11028L -#endif -#ifndef WSA_QOS_ESDMODEOBJ -#define WSA_QOS_ESDMODEOBJ 11029L -#endif -#ifndef WSA_QOS_ESHAPERATEOBJ -#define WSA_QOS_ESHAPERATEOBJ 11030L -#endif -#ifndef WSA_QOS_RESERVED_PETYPE -#define WSA_QOS_RESERVED_PETYPE 11031L -#endif -#endif /* WSABASEERR */ - -#define ERROR_SXS_SECTION_NOT_FOUND 14000L -#define ERROR_SXS_CANT_GEN_ACTCTX 14001L -#define ERROR_SXS_INVALID_ACTCTXDATA_FORMAT 14002L -#define ERROR_SXS_ASSEMBLY_NOT_FOUND 14003L -#define ERROR_SXS_MANIFEST_FORMAT_ERROR 14004L -#define ERROR_SXS_MANIFEST_PARSE_ERROR 14005L -#define ERROR_SXS_ACTIVATION_CONTEXT_DISABLED 14006L -#define ERROR_SXS_KEY_NOT_FOUND 14007L -#define ERROR_SXS_VERSION_CONFLICT 14008L -#define ERROR_SXS_WRONG_SECTION_TYPE 14009L -#define ERROR_SXS_THREAD_QUERIES_DISABLED 14010L -#define ERROR_SXS_PROCESS_DEFAULT_ALREADY_SET 14011L -#define ERROR_SXS_UNKNOWN_ENCODING_GROUP 14012L -#define ERROR_SXS_UNKNOWN_ENCODING 14013L -#define ERROR_SXS_INVALID_XML_NAMESPACE_URI 14014L -#define ERROR_SXS_ROOT_MANIFEST_DEPENDENCY_NOT_INSTALLED 14015L -#define ERROR_SXS_LEAF_MANIFEST_DEPENDENCY_NOT_INSTALLED 14016L -#define ERROR_SXS_INVALID_ASSEMBLY_IDENTITY_ATTRIBUTE 14017L -#define ERROR_SXS_MANIFEST_MISSING_REQUIRED_DEFAULT_NAMESPACE 14018L -#define ERROR_SXS_MANIFEST_INVALID_REQUIRED_DEFAULT_NAMESPACE 14019L -#define ERROR_SXS_PRIVATE_MANIFEST_CROSS_PATH_WITH_REPARSE_POINT 14020L -#define ERROR_SXS_DUPLICATE_DLL_NAME 14021L -#define ERROR_SXS_DUPLICATE_WINDOWCLASS_NAME 14022L -#define ERROR_SXS_DUPLICATE_CLSID 14023L -#define ERROR_SXS_DUPLICATE_IID 14024L -#define ERROR_SXS_DUPLICATE_TLBID 14025L -#define ERROR_SXS_DUPLICATE_PROGID 14026L -#define ERROR_SXS_DUPLICATE_ASSEMBLY_NAME 14027L -#define ERROR_SXS_FILE_HASH_MISMATCH 14028L -#define ERROR_SXS_POLICY_PARSE_ERROR 14029L -#define ERROR_SXS_XML_E_MISSINGQUOTE 14030L -#define ERROR_SXS_XML_E_COMMENTSYNTAX 14031L -#define ERROR_SXS_XML_E_BADSTARTNAMECHAR 14032L -#define ERROR_SXS_XML_E_BADNAMECHAR 14033L -#define ERROR_SXS_XML_E_BADCHARINSTRING 14034L -#define ERROR_SXS_XML_E_XMLDECLSYNTAX 14035L -#define ERROR_SXS_XML_E_BADCHARDATA 14036L -#define ERROR_SXS_XML_E_MISSINGWHITESPACE 14037L -#define ERROR_SXS_XML_E_EXPECTINGTAGEND 14038L -#define ERROR_SXS_XML_E_MISSINGSEMICOLON 14039L -#define ERROR_SXS_XML_E_UNBALANCEDPAREN 14040L -#define ERROR_SXS_XML_E_INTERNALERROR 14041L -#define ERROR_SXS_XML_E_UNEXPECTED_WHITESPACE 14042L -#define ERROR_SXS_XML_E_INCOMPLETE_ENCODING 14043L -#define ERROR_SXS_XML_E_MISSING_PAREN 14044L -#define ERROR_SXS_XML_E_EXPECTINGCLOSEQUOTE 14045L -#define ERROR_SXS_XML_E_MULTIPLE_COLONS 14046L -#define ERROR_SXS_XML_E_INVALID_DECIMAL 14047L -#define ERROR_SXS_XML_E_INVALID_HEXIDECIMAL 14048L -#define ERROR_SXS_XML_E_INVALID_UNICODE 14049L -#define ERROR_SXS_XML_E_WHITESPACEORQUESTIONMARK 14050L -#define ERROR_SXS_XML_E_UNEXPECTEDENDTAG 14051L -#define ERROR_SXS_XML_E_UNCLOSEDTAG 14052L -#define ERROR_SXS_XML_E_DUPLICATEATTRIBUTE 14053L -#define ERROR_SXS_XML_E_MULTIPLEROOTS 14054L -#define ERROR_SXS_XML_E_INVALIDATROOTLEVEL 14055L -#define ERROR_SXS_XML_E_BADXMLDECL 14056L -#define ERROR_SXS_XML_E_MISSINGROOT 14057L -#define ERROR_SXS_XML_E_UNEXPECTEDEOF 14058L -#define ERROR_SXS_XML_E_BADPEREFINSUBSET 14059L -#define ERROR_SXS_XML_E_UNCLOSEDSTARTTAG 14060L -#define ERROR_SXS_XML_E_UNCLOSEDENDTAG 14061L -#define ERROR_SXS_XML_E_UNCLOSEDSTRING 14062L -#define ERROR_SXS_XML_E_UNCLOSEDCOMMENT 14063L -#define ERROR_SXS_XML_E_UNCLOSEDDECL 14064L -#define ERROR_SXS_XML_E_UNCLOSEDCDATA 14065L -#define ERROR_SXS_XML_E_RESERVEDNAMESPACE 14066L -#define ERROR_SXS_XML_E_INVALIDENCODING 14067L -#define ERROR_SXS_XML_E_INVALIDSWITCH 14068L -#define ERROR_SXS_XML_E_BADXMLCASE 14069L -#define ERROR_SXS_XML_E_INVALID_STANDALONE 14070L -#define ERROR_SXS_XML_E_UNEXPECTED_STANDALONE 14071L -#define ERROR_SXS_XML_E_INVALID_VERSION 14072L -#define ERROR_SXS_XML_E_MISSINGEQUALS 14073L -#define ERROR_SXS_PROTECTION_RECOVERY_FAILED 14074L -#define ERROR_SXS_PROTECTION_PUBLIC_KEY_TOO_SHORT 14075L -#define ERROR_SXS_PROTECTION_CATALOG_NOT_VALID 14076L -#define ERROR_SXS_UNTRANSLATABLE_HRESULT 14077L -#define ERROR_SXS_PROTECTION_CATALOG_FILE_MISSING 14078L -#define ERROR_SXS_MISSING_ASSEMBLY_IDENTITY_ATTRIBUTE 14079L -#define ERROR_SXS_INVALID_ASSEMBLY_IDENTITY_ATTRIBUTE_NAME 14080L -#define ERROR_IPSEC_QM_POLICY_EXISTS 13000L -#define ERROR_IPSEC_QM_POLICY_NOT_FOUND 13001L -#define ERROR_IPSEC_QM_POLICY_IN_USE 13002L -#define ERROR_IPSEC_MM_POLICY_EXISTS 13003L -#define ERROR_IPSEC_MM_POLICY_NOT_FOUND 13004L -#define ERROR_IPSEC_MM_POLICY_IN_USE 13005L -#define ERROR_IPSEC_MM_FILTER_EXISTS 13006L -#define ERROR_IPSEC_MM_FILTER_NOT_FOUND 13007L -#define ERROR_IPSEC_TRANSPORT_FILTER_EXISTS 13008L -#define ERROR_IPSEC_TRANSPORT_FILTER_NOT_FOUND 13009L -#define ERROR_IPSEC_MM_AUTH_EXISTS 13010L -#define ERROR_IPSEC_MM_AUTH_NOT_FOUND 13011L -#define ERROR_IPSEC_MM_AUTH_IN_USE 13012L -#define ERROR_IPSEC_DEFAULT_MM_POLICY_NOT_FOUND 13013L -#define ERROR_IPSEC_DEFAULT_MM_AUTH_NOT_FOUND 13014L -#define ERROR_IPSEC_DEFAULT_QM_POLICY_NOT_FOUND 13015L -#define ERROR_IPSEC_TUNNEL_FILTER_EXISTS 13016L -#define ERROR_IPSEC_TUNNEL_FILTER_NOT_FOUND 13017L -#define ERROR_IPSEC_MM_FILTER_PENDING_DELETION 13018L -#define ERROR_IPSEC_TRANSPORT_FILTER_PENDING_DELETION 13019L -#define ERROR_IPSEC_TUNNEL_FILTER_PENDING_DELETION 13020L -#define ERROR_IPSEC_MM_POLICY_PENDING_DELETION 13021L -#define ERROR_IPSEC_MM_AUTH_PENDING_DELETION 13022L -#define ERROR_IPSEC_QM_POLICY_PENDING_DELETION 13023L -#define WARNING_IPSEC_MM_POLICY_PRUNED 13024L -#define WARNING_IPSEC_QM_POLICY_PRUNED 13025L -#define ERROR_IPSEC_IKE_NEG_STATUS_BEGIN 13800L -#define ERROR_IPSEC_IKE_AUTH_FAIL 13801L -#define ERROR_IPSEC_IKE_ATTRIB_FAIL 13802L -#define ERROR_IPSEC_IKE_NEGOTIATION_PENDING 13803L -#define ERROR_IPSEC_IKE_GENERAL_PROCESSING_ERROR 13804L -#define ERROR_IPSEC_IKE_TIMED_OUT 13805L -#define ERROR_IPSEC_IKE_NO_CERT 13806L -#define ERROR_IPSEC_IKE_SA_DELETED 13807L -#define ERROR_IPSEC_IKE_SA_REAPED 13808L -#define ERROR_IPSEC_IKE_MM_ACQUIRE_DROP 13809L -#define ERROR_IPSEC_IKE_QM_ACQUIRE_DROP 13810L -#define ERROR_IPSEC_IKE_QUEUE_DROP_MM 13811L -#define ERROR_IPSEC_IKE_QUEUE_DROP_NO_MM 13812L -#define ERROR_IPSEC_IKE_DROP_NO_RESPONSE 13813L -#define ERROR_IPSEC_IKE_MM_DELAY_DROP 13814L -#define ERROR_IPSEC_IKE_QM_DELAY_DROP 13815L -#define ERROR_IPSEC_IKE_ERROR 13816L -#define ERROR_IPSEC_IKE_CRL_FAILED 13817L -#define ERROR_IPSEC_IKE_INVALID_KEY_USAGE 13818L -#define ERROR_IPSEC_IKE_INVALID_CERT_TYPE 13819L -#define ERROR_IPSEC_IKE_NO_PRIVATE_KEY 13820L -#define ERROR_IPSEC_IKE_DH_FAIL 13822L -#define ERROR_IPSEC_IKE_INVALID_HEADER 13824L -#define ERROR_IPSEC_IKE_NO_POLICY 13825L -#define ERROR_IPSEC_IKE_INVALID_SIGNATURE 13826L -#define ERROR_IPSEC_IKE_KERBEROS_ERROR 13827L -#define ERROR_IPSEC_IKE_NO_PUBLIC_KEY 13828L -#define ERROR_IPSEC_IKE_PROCESS_ERR 13829L -#define ERROR_IPSEC_IKE_PROCESS_ERR_SA 13830L -#define ERROR_IPSEC_IKE_PROCESS_ERR_PROP 13831L -#define ERROR_IPSEC_IKE_PROCESS_ERR_TRANS 13832L -#define ERROR_IPSEC_IKE_PROCESS_ERR_KE 13833L -#define ERROR_IPSEC_IKE_PROCESS_ERR_ID 13834L -#define ERROR_IPSEC_IKE_PROCESS_ERR_CERT 13835L -#define ERROR_IPSEC_IKE_PROCESS_ERR_CERT_REQ 13836L -#define ERROR_IPSEC_IKE_PROCESS_ERR_HASH 13837L -#define ERROR_IPSEC_IKE_PROCESS_ERR_SIG 13838L -#define ERROR_IPSEC_IKE_PROCESS_ERR_NONCE 13839L -#define ERROR_IPSEC_IKE_PROCESS_ERR_NOTIFY 13840L -#define ERROR_IPSEC_IKE_PROCESS_ERR_DELETE 13841L -#define ERROR_IPSEC_IKE_PROCESS_ERR_VENDOR 13842L -#define ERROR_IPSEC_IKE_INVALID_PAYLOAD 13843L -#define ERROR_IPSEC_IKE_LOAD_SOFT_SA 13844L -#define ERROR_IPSEC_IKE_SOFT_SA_TORN_DOWN 13845L -#define ERROR_IPSEC_IKE_INVALID_COOKIE 13846L -#define ERROR_IPSEC_IKE_NO_PEER_CERT 13847L -#define ERROR_IPSEC_IKE_PEER_CRL_FAILED 13848L -#define ERROR_IPSEC_IKE_POLICY_CHANGE 13849L -#define ERROR_IPSEC_IKE_NO_MM_POLICY 13850L -#define ERROR_IPSEC_IKE_NOTCBPRIV 13851L -#define ERROR_IPSEC_IKE_SECLOADFAIL 13852L -#define ERROR_IPSEC_IKE_FAILSSPINIT 13853L -#define ERROR_IPSEC_IKE_FAILQUERYSSP 13854L -#define ERROR_IPSEC_IKE_SRVACQFAIL 13855L -#define ERROR_IPSEC_IKE_SRVQUERYCRED 13856L -#define ERROR_IPSEC_IKE_GETSPIFAIL 13857L -#define ERROR_IPSEC_IKE_INVALID_FILTER 13858L -#define ERROR_IPSEC_IKE_OUT_OF_MEMORY 13859L -#define ERROR_IPSEC_IKE_ADD_UPDATE_KEY_FAILED 13860L -#define ERROR_IPSEC_IKE_INVALID_POLICY 13861L -#define ERROR_IPSEC_IKE_UNKNOWN_DOI 13862L -#define ERROR_IPSEC_IKE_INVALID_SITUATION 13863L -#define ERROR_IPSEC_IKE_DH_FAILURE 13864L -#define ERROR_IPSEC_IKE_INVALID_GROUP 13865L -#define ERROR_IPSEC_IKE_ENCRYPT 13866L -#define ERROR_IPSEC_IKE_DECRYPT 13867L -#define ERROR_IPSEC_IKE_POLICY_MATCH 13868L -#define ERROR_IPSEC_IKE_UNSUPPORTED_ID 13869L -#define ERROR_IPSEC_IKE_INVALID_HASH 13870L -#define ERROR_IPSEC_IKE_INVALID_HASH_ALG 13871L -#define ERROR_IPSEC_IKE_INVALID_HASH_SIZE 13872L -#define ERROR_IPSEC_IKE_INVALID_ENCRYPT_ALG 13873L -#define ERROR_IPSEC_IKE_INVALID_AUTH_ALG 13874L -#define ERROR_IPSEC_IKE_INVALID_SIG 13875L -#define ERROR_IPSEC_IKE_LOAD_FAILED 13876L -#define ERROR_IPSEC_IKE_RPC_DELETE 13877L -#define ERROR_IPSEC_IKE_BENIGN_REINIT 13878L -#define ERROR_IPSEC_IKE_INVALID_RESPONDER_LIFETIME_NOTIFY 13879L -#define ERROR_IPSEC_IKE_INVALID_CERT_KEYLEN 13881L -#define ERROR_IPSEC_IKE_MM_LIMIT 13882L -#define ERROR_IPSEC_IKE_NEGOTIATION_DISABLED 13883L -#define ERROR_IPSEC_IKE_NEG_STATUS_END 13884L -#define SEVERITY_SUCCESS 0 -#define SEVERITY_ERROR 1 -#define SUCCEEDED(hr) ((HRESULT)(hr) >= 0) -#define FAILED(hr) ((HRESULT)(hr) < 0) -#define IS_ERROR(Status) ((unsigned long)(Status) >> 31==SEVERITY_ERROR) -#define HRESULT_CODE(hr) ((hr) & 0xFFFF) -#define SCODE_CODE(sc) ((sc) & 0xFFFF) -#define HRESULT_FACILITY(hr) (((hr) >> 16) & 0x1fff) -#define SCODE_FACILITY(sc) (((sc) >> 16) & 0x1fff) -#define HRESULT_SEVERITY(hr) (((hr) >> 31) & 0x1) -#define SCODE_SEVERITY(sc) (((sc) >> 31) & 0x1) -#define MAKE_HRESULT(sev,fac,code) ((HRESULT) (((unsigned long)(sev)<<31) | ((unsigned long)(fac)<<16) | ((unsigned long)(code)))) -#define MAKE_SCODE(sev,fac,code) ((SCODE) (((unsigned long)(sev)<<31) | ((unsigned long)(fac)<<16) | ((unsigned long)(code)))) -#define FACILITY_NT_BIT 0x10000000 -#define __HRESULT_FROM_WIN32(x) ((HRESULT)(x) <= 0 ? ((HRESULT)(x)) : ((HRESULT) (((x) & 0x0000FFFF) | (FACILITY_WIN32 << 16) | 0x80000000))) -#ifdef INLINE_HRESULT_FROM_WIN32 -#ifndef _HRESULT_DEFINED -#define _HRESULT_DEFINED -typedef long HRESULT; -#endif -__CRT_INLINE HRESULT HRESULT_FROM_WIN32(long x) { return x <= 0 ? (HRESULT)x : (HRESULT) (((x) & 0x0000FFFF) | (FACILITY_WIN32 << 16) | 0x80000000);} -#else -#define HRESULT_FROM_WIN32(x) __HRESULT_FROM_WIN32(x) -#endif -#define HRESULT_FROM_NT(x) ((HRESULT) ((x) | FACILITY_NT_BIT)) -#define GetScode(hr) ((SCODE) (hr)) -#define ResultFromScode(sc) ((HRESULT) (sc)) -#define PropagateResult(hrPrevious,scBase) ((HRESULT) scBase) -#ifdef RC_INVOKED -#define _HRESULT_TYPEDEF_(_sc) _sc -#else -#define _HRESULT_TYPEDEF_(_sc) ((HRESULT)_sc) -#endif -#define NOERROR 0 -#define E_UNEXPECTED _HRESULT_TYPEDEF_(0x8000FFFFL) -#define E_NOTIMPL _HRESULT_TYPEDEF_(0x80004001L) -#define E_OUTOFMEMORY _HRESULT_TYPEDEF_(0x8007000EL) -#define E_INVALIDARG _HRESULT_TYPEDEF_(0x80070057L) -#define E_NOINTERFACE _HRESULT_TYPEDEF_(0x80004002L) -#define E_POINTER _HRESULT_TYPEDEF_(0x80004003L) -#define E_HANDLE _HRESULT_TYPEDEF_(0x80070006L) -#define E_ABORT _HRESULT_TYPEDEF_(0x80004004L) -#define E_FAIL _HRESULT_TYPEDEF_(0x80004005L) -#define E_ACCESSDENIED _HRESULT_TYPEDEF_(0x80070005L) -#define E_PENDING _HRESULT_TYPEDEF_(0x8000000AL) -#define CO_E_INIT_TLS _HRESULT_TYPEDEF_(0x80004006L) -#define CO_E_INIT_SHARED_ALLOCATOR _HRESULT_TYPEDEF_(0x80004007L) -#define CO_E_INIT_MEMORY_ALLOCATOR _HRESULT_TYPEDEF_(0x80004008L) -#define CO_E_INIT_CLASS_CACHE _HRESULT_TYPEDEF_(0x80004009L) -#define CO_E_INIT_RPC_CHANNEL _HRESULT_TYPEDEF_(0x8000400AL) -#define CO_E_INIT_TLS_SET_CHANNEL_CONTROL _HRESULT_TYPEDEF_(0x8000400BL) -#define CO_E_INIT_TLS_CHANNEL_CONTROL _HRESULT_TYPEDEF_(0x8000400CL) -#define CO_E_INIT_UNACCEPTED_USER_ALLOCATOR _HRESULT_TYPEDEF_(0x8000400DL) -#define CO_E_INIT_SCM_MUTEX_EXISTS _HRESULT_TYPEDEF_(0x8000400EL) -#define CO_E_INIT_SCM_FILE_MAPPING_EXISTS _HRESULT_TYPEDEF_(0x8000400FL) -#define CO_E_INIT_SCM_MAP_VIEW_OF_FILE _HRESULT_TYPEDEF_(0x80004010L) -#define CO_E_INIT_SCM_EXEC_FAILURE _HRESULT_TYPEDEF_(0x80004011L) -#define CO_E_INIT_ONLY_SINGLE_THREADED _HRESULT_TYPEDEF_(0x80004012L) -#define CO_E_CANT_REMOTE _HRESULT_TYPEDEF_(0x80004013L) -#define CO_E_BAD_SERVER_NAME _HRESULT_TYPEDEF_(0x80004014L) -#define CO_E_WRONG_SERVER_IDENTITY _HRESULT_TYPEDEF_(0x80004015L) -#define CO_E_OLE1DDE_DISABLED _HRESULT_TYPEDEF_(0x80004016L) -#define CO_E_RUNAS_SYNTAX _HRESULT_TYPEDEF_(0x80004017L) -#define CO_E_CREATEPROCESS_FAILURE _HRESULT_TYPEDEF_(0x80004018L) -#define CO_E_RUNAS_CREATEPROCESS_FAILURE _HRESULT_TYPEDEF_(0x80004019L) -#define CO_E_RUNAS_LOGON_FAILURE _HRESULT_TYPEDEF_(0x8000401AL) -#define CO_E_LAUNCH_PERMSSION_DENIED _HRESULT_TYPEDEF_(0x8000401BL) -#define CO_E_START_SERVICE_FAILURE _HRESULT_TYPEDEF_(0x8000401CL) -#define CO_E_REMOTE_COMMUNICATION_FAILURE _HRESULT_TYPEDEF_(0x8000401DL) -#define CO_E_SERVER_START_TIMEOUT _HRESULT_TYPEDEF_(0x8000401EL) -#define CO_E_CLSREG_INCONSISTENT _HRESULT_TYPEDEF_(0x8000401FL) -#define CO_E_IIDREG_INCONSISTENT _HRESULT_TYPEDEF_(0x80004020L) -#define CO_E_NOT_SUPPORTED _HRESULT_TYPEDEF_(0x80004021L) -#define CO_E_RELOAD_DLL _HRESULT_TYPEDEF_(0x80004022L) -#define CO_E_MSI_ERROR _HRESULT_TYPEDEF_(0x80004023L) -#define CO_E_ATTEMPT_TO_CREATE_OUTSIDE_CLIENT_CONTEXT _HRESULT_TYPEDEF_(0x80004024L) -#define CO_E_SERVER_PAUSED _HRESULT_TYPEDEF_(0x80004025L) -#define CO_E_SERVER_NOT_PAUSED _HRESULT_TYPEDEF_(0x80004026L) -#define CO_E_CLASS_DISABLED _HRESULT_TYPEDEF_(0x80004027L) -#define CO_E_CLRNOTAVAILABLE _HRESULT_TYPEDEF_(0x80004028L) -#define CO_E_ASYNC_WORK_REJECTED _HRESULT_TYPEDEF_(0x80004029L) -#define CO_E_SERVER_INIT_TIMEOUT _HRESULT_TYPEDEF_(0x8000402AL) -#define CO_E_NO_SECCTX_IN_ACTIVATE _HRESULT_TYPEDEF_(0x8000402BL) -#define CO_E_TRACKER_CONFIG _HRESULT_TYPEDEF_(0x80004030L) -#define CO_E_THREADPOOL_CONFIG _HRESULT_TYPEDEF_(0x80004031L) -#define CO_E_SXS_CONFIG _HRESULT_TYPEDEF_(0x80004032L) -#define CO_E_MALFORMED_SPN _HRESULT_TYPEDEF_(0x80004033L) -#define S_OK ((HRESULT)0x00000000L) -#define S_FALSE ((HRESULT)0x00000001L) -#define OLE_E_FIRST ((HRESULT)0x80040000L) -#define OLE_E_LAST ((HRESULT)0x800400FFL) -#define OLE_S_FIRST ((HRESULT)0x00040000L) -#define OLE_S_LAST ((HRESULT)0x000400FFL) -#define OLE_E_OLEVERB _HRESULT_TYPEDEF_(0x80040000L) -#define OLE_E_ADVF _HRESULT_TYPEDEF_(0x80040001L) -#define OLE_E_ENUM_NOMORE _HRESULT_TYPEDEF_(0x80040002L) -#define OLE_E_ADVISENOTSUPPORTED _HRESULT_TYPEDEF_(0x80040003L) -#define OLE_E_NOCONNECTION _HRESULT_TYPEDEF_(0x80040004L) -#define OLE_E_NOTRUNNING _HRESULT_TYPEDEF_(0x80040005L) -#define OLE_E_NOCACHE _HRESULT_TYPEDEF_(0x80040006L) -#define OLE_E_BLANK _HRESULT_TYPEDEF_(0x80040007L) -#define OLE_E_CLASSDIFF _HRESULT_TYPEDEF_(0x80040008L) -#define OLE_E_CANT_GETMONIKER _HRESULT_TYPEDEF_(0x80040009L) -#define OLE_E_CANT_BINDTOSOURCE _HRESULT_TYPEDEF_(0x8004000AL) -#define OLE_E_STATIC _HRESULT_TYPEDEF_(0x8004000BL) -#define OLE_E_PROMPTSAVECANCELLED _HRESULT_TYPEDEF_(0x8004000CL) -#define OLE_E_INVALIDRECT _HRESULT_TYPEDEF_(0x8004000DL) -#define OLE_E_WRONGCOMPOBJ _HRESULT_TYPEDEF_(0x8004000EL) -#define OLE_E_INVALIDHWND _HRESULT_TYPEDEF_(0x8004000FL) -#define OLE_E_NOT_INPLACEACTIVE _HRESULT_TYPEDEF_(0x80040010L) -#define OLE_E_CANTCONVERT _HRESULT_TYPEDEF_(0x80040011L) -#define OLE_E_NOSTORAGE _HRESULT_TYPEDEF_(0x80040012L) -#define DV_E_FORMATETC _HRESULT_TYPEDEF_(0x80040064L) -#define DV_E_DVTARGETDEVICE _HRESULT_TYPEDEF_(0x80040065L) -#define DV_E_STGMEDIUM _HRESULT_TYPEDEF_(0x80040066L) -#define DV_E_STATDATA _HRESULT_TYPEDEF_(0x80040067L) -#define DV_E_LINDEX _HRESULT_TYPEDEF_(0x80040068L) -#define DV_E_TYMED _HRESULT_TYPEDEF_(0x80040069L) -#define DV_E_CLIPFORMAT _HRESULT_TYPEDEF_(0x8004006AL) -#define DV_E_DVASPECT _HRESULT_TYPEDEF_(0x8004006BL) -#define DV_E_DVTARGETDEVICE_SIZE _HRESULT_TYPEDEF_(0x8004006CL) -#define DV_E_NOIVIEWOBJECT _HRESULT_TYPEDEF_(0x8004006DL) -#define DRAGDROP_E_FIRST 0x80040100L -#define DRAGDROP_E_LAST 0x8004010FL -#define DRAGDROP_S_FIRST 0x00040100L -#define DRAGDROP_S_LAST 0x0004010FL -#define DRAGDROP_E_NOTREGISTERED _HRESULT_TYPEDEF_(0x80040100L) -#define DRAGDROP_E_ALREADYREGISTERED _HRESULT_TYPEDEF_(0x80040101L) -#define DRAGDROP_E_INVALIDHWND _HRESULT_TYPEDEF_(0x80040102L) -#define CLASSFACTORY_E_FIRST 0x80040110L -#define CLASSFACTORY_E_LAST 0x8004011FL -#define CLASSFACTORY_S_FIRST 0x00040110L -#define CLASSFACTORY_S_LAST 0x0004011FL -#define CLASS_E_NOAGGREGATION _HRESULT_TYPEDEF_(0x80040110L) -#define CLASS_E_CLASSNOTAVAILABLE _HRESULT_TYPEDEF_(0x80040111L) -#define CLASS_E_NOTLICENSED _HRESULT_TYPEDEF_(0x80040112L) -#define MARSHAL_E_FIRST 0x80040120L -#define MARSHAL_E_LAST 0x8004012FL -#define MARSHAL_S_FIRST 0x00040120L -#define MARSHAL_S_LAST 0x0004012FL -#define DATA_E_FIRST 0x80040130L -#define DATA_E_LAST 0x8004013FL -#define DATA_S_FIRST 0x00040130L -#define DATA_S_LAST 0x0004013FL -#define VIEW_E_FIRST 0x80040140L -#define VIEW_E_LAST 0x8004014FL -#define VIEW_S_FIRST 0x00040140L -#define VIEW_S_LAST 0x0004014FL -#define VIEW_E_DRAW _HRESULT_TYPEDEF_(0x80040140L) -#define REGDB_E_FIRST 0x80040150L -#define REGDB_E_LAST 0x8004015FL -#define REGDB_S_FIRST 0x00040150L -#define REGDB_S_LAST 0x0004015FL -#define REGDB_E_READREGDB _HRESULT_TYPEDEF_(0x80040150L) -#define REGDB_E_WRITEREGDB _HRESULT_TYPEDEF_(0x80040151L) -#define REGDB_E_KEYMISSING _HRESULT_TYPEDEF_(0x80040152L) -#define REGDB_E_INVALIDVALUE _HRESULT_TYPEDEF_(0x80040153L) -#define REGDB_E_CLASSNOTREG _HRESULT_TYPEDEF_(0x80040154L) -#define REGDB_E_IIDNOTREG _HRESULT_TYPEDEF_(0x80040155L) -#define REGDB_E_BADTHREADINGMODEL _HRESULT_TYPEDEF_(0x80040156L) -#define CAT_E_FIRST 0x80040160L -#define CAT_E_LAST 0x80040161L -#define CAT_E_CATIDNOEXIST _HRESULT_TYPEDEF_(0x80040160L) -#define CAT_E_NODESCRIPTION _HRESULT_TYPEDEF_(0x80040161L) -#define CS_E_FIRST 0x80040164L -#define CS_E_LAST 0x8004016FL -#define CS_E_PACKAGE_NOTFOUND _HRESULT_TYPEDEF_(0x80040164L) -#define CS_E_NOT_DELETABLE _HRESULT_TYPEDEF_(0x80040165L) -#define CS_E_CLASS_NOTFOUND _HRESULT_TYPEDEF_(0x80040166L) -#define CS_E_INVALID_VERSION _HRESULT_TYPEDEF_(0x80040167L) -#define CS_E_NO_CLASSSTORE _HRESULT_TYPEDEF_(0x80040168L) -#define CS_E_OBJECT_NOTFOUND _HRESULT_TYPEDEF_(0x80040169L) -#define CS_E_OBJECT_ALREADY_EXISTS _HRESULT_TYPEDEF_(0x8004016AL) -#define CS_E_INVALID_PATH _HRESULT_TYPEDEF_(0x8004016BL) -#define CS_E_NETWORK_ERROR _HRESULT_TYPEDEF_(0x8004016CL) -#define CS_E_ADMIN_LIMIT_EXCEEDED _HRESULT_TYPEDEF_(0x8004016DL) -#define CS_E_SCHEMA_MISMATCH _HRESULT_TYPEDEF_(0x8004016EL) -#define CS_E_INTERNAL_ERROR _HRESULT_TYPEDEF_(0x8004016FL) -#define CACHE_E_FIRST 0x80040170L -#define CACHE_E_LAST 0x8004017FL -#define CACHE_S_FIRST 0x00040170L -#define CACHE_S_LAST 0x0004017FL -#define CACHE_E_NOCACHE_UPDATED _HRESULT_TYPEDEF_(0x80040170L) -#define OLEOBJ_E_FIRST 0x80040180L -#define OLEOBJ_E_LAST 0x8004018FL -#define OLEOBJ_S_FIRST 0x00040180L -#define OLEOBJ_S_LAST 0x0004018FL -#define OLEOBJ_E_NOVERBS _HRESULT_TYPEDEF_(0x80040180L) -#define OLEOBJ_E_INVALIDVERB _HRESULT_TYPEDEF_(0x80040181L) -#define CLIENTSITE_E_FIRST 0x80040190L -#define CLIENTSITE_E_LAST 0x8004019FL -#define CLIENTSITE_S_FIRST 0x00040190L -#define CLIENTSITE_S_LAST 0x0004019FL -#define INPLACE_E_NOTUNDOABLE _HRESULT_TYPEDEF_(0x800401A0L) -#define INPLACE_E_NOTOOLSPACE _HRESULT_TYPEDEF_(0x800401A1L) -#define INPLACE_E_FIRST 0x800401A0L -#define INPLACE_E_LAST 0x800401AFL -#define INPLACE_S_FIRST 0x000401A0L -#define INPLACE_S_LAST 0x000401AFL -#define ENUM_E_FIRST 0x800401B0L -#define ENUM_E_LAST 0x800401BFL -#define ENUM_S_FIRST 0x000401B0L -#define ENUM_S_LAST 0x000401BFL -#define CONVERT10_E_FIRST 0x800401C0L -#define CONVERT10_E_LAST 0x800401CFL -#define CONVERT10_S_FIRST 0x000401C0L -#define CONVERT10_S_LAST 0x000401CFL -#define CONVERT10_E_OLESTREAM_GET _HRESULT_TYPEDEF_(0x800401C0L) -#define CONVERT10_E_OLESTREAM_PUT _HRESULT_TYPEDEF_(0x800401C1L) -#define CONVERT10_E_OLESTREAM_FMT _HRESULT_TYPEDEF_(0x800401C2L) -#define CONVERT10_E_OLESTREAM_BITMAP_TO_DIB _HRESULT_TYPEDEF_(0x800401C3L) -#define CONVERT10_E_STG_FMT _HRESULT_TYPEDEF_(0x800401C4L) -#define CONVERT10_E_STG_NO_STD_STREAM _HRESULT_TYPEDEF_(0x800401C5L) -#define CONVERT10_E_STG_DIB_TO_BITMAP _HRESULT_TYPEDEF_(0x800401C6L) -#define CLIPBRD_E_FIRST 0x800401D0L -#define CLIPBRD_E_LAST 0x800401DFL -#define CLIPBRD_S_FIRST 0x000401D0L -#define CLIPBRD_S_LAST 0x000401DFL -#define CLIPBRD_E_CANT_OPEN _HRESULT_TYPEDEF_(0x800401D0L) -#define CLIPBRD_E_CANT_EMPTY _HRESULT_TYPEDEF_(0x800401D1L) -#define CLIPBRD_E_CANT_SET _HRESULT_TYPEDEF_(0x800401D2L) -#define CLIPBRD_E_BAD_DATA _HRESULT_TYPEDEF_(0x800401D3L) -#define CLIPBRD_E_CANT_CLOSE _HRESULT_TYPEDEF_(0x800401D4L) -#define MK_E_FIRST 0x800401E0L -#define MK_E_LAST 0x800401EFL -#define MK_S_FIRST 0x000401E0L -#define MK_S_LAST 0x000401EFL -#define MK_E_CONNECTMANUALLY _HRESULT_TYPEDEF_(0x800401E0L) -#define MK_E_EXCEEDEDDEADLINE _HRESULT_TYPEDEF_(0x800401E1L) -#define MK_E_NEEDGENERIC _HRESULT_TYPEDEF_(0x800401E2L) -#define MK_E_UNAVAILABLE _HRESULT_TYPEDEF_(0x800401E3L) -#define MK_E_SYNTAX _HRESULT_TYPEDEF_(0x800401E4L) -#define MK_E_NOOBJECT _HRESULT_TYPEDEF_(0x800401E5L) -#define MK_E_INVALIDEXTENSION _HRESULT_TYPEDEF_(0x800401E6L) -#define MK_E_INTERMEDIATEINTERFACENOTSUPPORTED _HRESULT_TYPEDEF_(0x800401E7L) -#define MK_E_NOTBINDABLE _HRESULT_TYPEDEF_(0x800401E8L) -#define MK_E_NOTBOUND _HRESULT_TYPEDEF_(0x800401E9L) -#define MK_E_CANTOPENFILE _HRESULT_TYPEDEF_(0x800401EAL) -#define MK_E_MUSTBOTHERUSER _HRESULT_TYPEDEF_(0x800401EBL) -#define MK_E_NOINVERSE _HRESULT_TYPEDEF_(0x800401ECL) -#define MK_E_NOSTORAGE _HRESULT_TYPEDEF_(0x800401EDL) -#define MK_E_NOPREFIX _HRESULT_TYPEDEF_(0x800401EEL) -#define MK_E_ENUMERATION_FAILED _HRESULT_TYPEDEF_(0x800401EFL) -#define CO_E_FIRST 0x800401F0L -#define CO_E_LAST 0x800401FFL -#define CO_S_FIRST 0x000401F0L -#define CO_S_LAST 0x000401FFL -#define CO_E_NOTINITIALIZED _HRESULT_TYPEDEF_(0x800401F0L) -#define CO_E_ALREADYINITIALIZED _HRESULT_TYPEDEF_(0x800401F1L) -#define CO_E_CANTDETERMINECLASS _HRESULT_TYPEDEF_(0x800401F2L) -#define CO_E_CLASSSTRING _HRESULT_TYPEDEF_(0x800401F3L) -#define CO_E_IIDSTRING _HRESULT_TYPEDEF_(0x800401F4L) -#define CO_E_APPNOTFOUND _HRESULT_TYPEDEF_(0x800401F5L) -#define CO_E_APPSINGLEUSE _HRESULT_TYPEDEF_(0x800401F6L) -#define CO_E_ERRORINAPP _HRESULT_TYPEDEF_(0x800401F7L) -#define CO_E_DLLNOTFOUND _HRESULT_TYPEDEF_(0x800401F8L) -#define CO_E_ERRORINDLL _HRESULT_TYPEDEF_(0x800401F9L) -#define CO_E_WRONGOSFORAPP _HRESULT_TYPEDEF_(0x800401FAL) -#define CO_E_OBJNOTREG _HRESULT_TYPEDEF_(0x800401FBL) -#define CO_E_OBJISREG _HRESULT_TYPEDEF_(0x800401FCL) -#define CO_E_OBJNOTCONNECTED _HRESULT_TYPEDEF_(0x800401FDL) -#define CO_E_APPDIDNTREG _HRESULT_TYPEDEF_(0x800401FEL) -#define CO_E_RELEASED _HRESULT_TYPEDEF_(0x800401FFL) -#define EVENT_E_FIRST 0x80040200L -#define EVENT_E_LAST 0x8004021FL -#define EVENT_S_FIRST 0x00040200L -#define EVENT_S_LAST 0x0004021FL -#define EVENT_S_SOME_SUBSCRIBERS_FAILED _HRESULT_TYPEDEF_(0x00040200L) -#define EVENT_E_ALL_SUBSCRIBERS_FAILED _HRESULT_TYPEDEF_(0x80040201L) -#define EVENT_S_NOSUBSCRIBERS _HRESULT_TYPEDEF_(0x00040202L) -#define EVENT_E_QUERYSYNTAX _HRESULT_TYPEDEF_(0x80040203L) -#define EVENT_E_QUERYFIELD _HRESULT_TYPEDEF_(0x80040204L) -#define EVENT_E_INTERNALEXCEPTION _HRESULT_TYPEDEF_(0x80040205L) -#define EVENT_E_INTERNALERROR _HRESULT_TYPEDEF_(0x80040206L) -#define EVENT_E_INVALID_PER_USER_SID _HRESULT_TYPEDEF_(0x80040207L) -#define EVENT_E_USER_EXCEPTION _HRESULT_TYPEDEF_(0x80040208L) -#define EVENT_E_TOO_MANY_METHODS _HRESULT_TYPEDEF_(0x80040209L) -#define EVENT_E_MISSING_EVENTCLASS _HRESULT_TYPEDEF_(0x8004020AL) -#define EVENT_E_NOT_ALL_REMOVED _HRESULT_TYPEDEF_(0x8004020BL) -#define EVENT_E_COMPLUS_NOT_INSTALLED _HRESULT_TYPEDEF_(0x8004020CL) -#define EVENT_E_CANT_MODIFY_OR_DELETE_UNCONFIGURED_OBJECT _HRESULT_TYPEDEF_(0x8004020DL) -#define EVENT_E_CANT_MODIFY_OR_DELETE_CONFIGURED_OBJECT _HRESULT_TYPEDEF_(0x8004020EL) -#define EVENT_E_INVALID_EVENT_CLASS_PARTITION _HRESULT_TYPEDEF_(0x8004020FL) -#define EVENT_E_PER_USER_SID_NOT_LOGGED_ON _HRESULT_TYPEDEF_(0x80040210L) -#define XACT_E_FIRST 0x8004D000 -#define XACT_E_LAST 0x8004D029 -#define XACT_S_FIRST 0x0004D000 -#define XACT_S_LAST 0x0004D010 -#define XACT_E_ALREADYOTHERSINGLEPHASE _HRESULT_TYPEDEF_(0x8004D000L) -#define XACT_E_CANTRETAIN _HRESULT_TYPEDEF_(0x8004D001L) -#define XACT_E_COMMITFAILED _HRESULT_TYPEDEF_(0x8004D002L) -#define XACT_E_COMMITPREVENTED _HRESULT_TYPEDEF_(0x8004D003L) -#define XACT_E_HEURISTICABORT _HRESULT_TYPEDEF_(0x8004D004L) -#define XACT_E_HEURISTICCOMMIT _HRESULT_TYPEDEF_(0x8004D005L) -#define XACT_E_HEURISTICDAMAGE _HRESULT_TYPEDEF_(0x8004D006L) -#define XACT_E_HEURISTICDANGER _HRESULT_TYPEDEF_(0x8004D007L) -#define XACT_E_ISOLATIONLEVEL _HRESULT_TYPEDEF_(0x8004D008L) -#define XACT_E_NOASYNC _HRESULT_TYPEDEF_(0x8004D009L) -#define XACT_E_NOENLIST _HRESULT_TYPEDEF_(0x8004D00AL) -#define XACT_E_NOISORETAIN _HRESULT_TYPEDEF_(0x8004D00BL) -#define XACT_E_NORESOURCE _HRESULT_TYPEDEF_(0x8004D00CL) -#define XACT_E_NOTCURRENT _HRESULT_TYPEDEF_(0x8004D00DL) -#define XACT_E_NOTRANSACTION _HRESULT_TYPEDEF_(0x8004D00EL) -#define XACT_E_NOTSUPPORTED _HRESULT_TYPEDEF_(0x8004D00FL) -#define XACT_E_UNKNOWNRMGRID _HRESULT_TYPEDEF_(0x8004D010L) -#define XACT_E_WRONGSTATE _HRESULT_TYPEDEF_(0x8004D011L) -#define XACT_E_WRONGUOW _HRESULT_TYPEDEF_(0x8004D012L) -#define XACT_E_XTIONEXISTS _HRESULT_TYPEDEF_(0x8004D013L) -#define XACT_E_NOIMPORTOBJECT _HRESULT_TYPEDEF_(0x8004D014L) -#define XACT_E_INVALIDCOOKIE _HRESULT_TYPEDEF_(0x8004D015L) -#define XACT_E_INDOUBT _HRESULT_TYPEDEF_(0x8004D016L) -#define XACT_E_NOTIMEOUT _HRESULT_TYPEDEF_(0x8004D017L) -#define XACT_E_ALREADYINPROGRESS _HRESULT_TYPEDEF_(0x8004D018L) -#define XACT_E_ABORTED _HRESULT_TYPEDEF_(0x8004D019L) -#define XACT_E_LOGFULL _HRESULT_TYPEDEF_(0x8004D01AL) -#define XACT_E_TMNOTAVAILABLE _HRESULT_TYPEDEF_(0x8004D01BL) -#define XACT_E_CONNECTION_DOWN _HRESULT_TYPEDEF_(0x8004D01CL) -#define XACT_E_CONNECTION_DENIED _HRESULT_TYPEDEF_(0x8004D01DL) -#define XACT_E_REENLISTTIMEOUT _HRESULT_TYPEDEF_(0x8004D01EL) -#define XACT_E_TIP_CONNECT_FAILED _HRESULT_TYPEDEF_(0x8004D01FL) -#define XACT_E_TIP_PROTOCOL_ERROR _HRESULT_TYPEDEF_(0x8004D020L) -#define XACT_E_TIP_PULL_FAILED _HRESULT_TYPEDEF_(0x8004D021L) -#define XACT_E_DEST_TMNOTAVAILABLE _HRESULT_TYPEDEF_(0x8004D022L) -#define XACT_E_TIP_DISABLED _HRESULT_TYPEDEF_(0x8004D023L) -#define XACT_E_NETWORK_TX_DISABLED _HRESULT_TYPEDEF_(0x8004D024L) -#define XACT_E_PARTNER_NETWORK_TX_DISABLED _HRESULT_TYPEDEF_(0x8004D025L) -#define XACT_E_XA_TX_DISABLED _HRESULT_TYPEDEF_(0x8004D026L) -#define XACT_E_UNABLE_TO_READ_DTC_CONFIG _HRESULT_TYPEDEF_(0x8004D027L) -#define XACT_E_UNABLE_TO_LOAD_DTC_PROXY _HRESULT_TYPEDEF_(0x8004D028L) -#define XACT_E_ABORTING _HRESULT_TYPEDEF_(0x8004D029L) -#define XACT_E_CLERKNOTFOUND _HRESULT_TYPEDEF_(0x8004D080L) -#define XACT_E_CLERKEXISTS _HRESULT_TYPEDEF_(0x8004D081L) -#define XACT_E_RECOVERYINPROGRESS _HRESULT_TYPEDEF_(0x8004D082L) -#define XACT_E_TRANSACTIONCLOSED _HRESULT_TYPEDEF_(0x8004D083L) -#define XACT_E_INVALIDLSN _HRESULT_TYPEDEF_(0x8004D084L) -#define XACT_E_REPLAYREQUEST _HRESULT_TYPEDEF_(0x8004D085L) -#define XACT_S_ASYNC _HRESULT_TYPEDEF_(0x0004D000L) -#define XACT_S_DEFECT _HRESULT_TYPEDEF_(0x0004D001L) -#define XACT_S_READONLY _HRESULT_TYPEDEF_(0x0004D002L) -#define XACT_S_SOMENORETAIN _HRESULT_TYPEDEF_(0x0004D003L) -#define XACT_S_OKINFORM _HRESULT_TYPEDEF_(0x0004D004L) -#define XACT_S_MADECHANGESCONTENT _HRESULT_TYPEDEF_(0x0004D005L) -#define XACT_S_MADECHANGESINFORM _HRESULT_TYPEDEF_(0x0004D006L) -#define XACT_S_ALLNORETAIN _HRESULT_TYPEDEF_(0x0004D007L) -#define XACT_S_ABORTING _HRESULT_TYPEDEF_(0x0004D008L) -#define XACT_S_SINGLEPHASE _HRESULT_TYPEDEF_(0x0004D009L) -#define XACT_S_LOCALLY_OK _HRESULT_TYPEDEF_(0x0004D00AL) -#define XACT_S_LASTRESOURCEMANAGER _HRESULT_TYPEDEF_(0x0004D010L) -#define CONTEXT_E_FIRST 0x8004E000L -#define CONTEXT_E_LAST 0x8004E02FL -#define CONTEXT_S_FIRST 0x0004E000L -#define CONTEXT_S_LAST 0x0004E02FL -#define CONTEXT_E_ABORTED _HRESULT_TYPEDEF_(0x8004E002L) -#define CONTEXT_E_ABORTING _HRESULT_TYPEDEF_(0x8004E003L) -#define CONTEXT_E_NOCONTEXT _HRESULT_TYPEDEF_(0x8004E004L) -#define CONTEXT_E_WOULD_DEADLOCK _HRESULT_TYPEDEF_(0x8004E005L) -#define CONTEXT_E_SYNCH_TIMEOUT _HRESULT_TYPEDEF_(0x8004E006L) -#define CONTEXT_E_OLDREF _HRESULT_TYPEDEF_(0x8004E007L) -#define CONTEXT_E_ROLENOTFOUND _HRESULT_TYPEDEF_(0x8004E00CL) -#define CONTEXT_E_TMNOTAVAILABLE _HRESULT_TYPEDEF_(0x8004E00FL) -#define CO_E_ACTIVATIONFAILED _HRESULT_TYPEDEF_(0x8004E021L) -#define CO_E_ACTIVATIONFAILED_EVENTLOGGED _HRESULT_TYPEDEF_(0x8004E022L) -#define CO_E_ACTIVATIONFAILED_CATALOGERROR _HRESULT_TYPEDEF_(0x8004E023L) -#define CO_E_ACTIVATIONFAILED_TIMEOUT _HRESULT_TYPEDEF_(0x8004E024L) -#define CO_E_INITIALIZATIONFAILED _HRESULT_TYPEDEF_(0x8004E025L) -#define CONTEXT_E_NOJIT _HRESULT_TYPEDEF_(0x8004E026L) -#define CONTEXT_E_NOTRANSACTION _HRESULT_TYPEDEF_(0x8004E027L) -#define CO_E_THREADINGMODEL_CHANGED _HRESULT_TYPEDEF_(0x8004E028L) -#define CO_E_NOIISINTRINSICS _HRESULT_TYPEDEF_(0x8004E029L) -#define CO_E_NOCOOKIES _HRESULT_TYPEDEF_(0x8004E02AL) -#define CO_E_DBERROR _HRESULT_TYPEDEF_(0x8004E02BL) -#define CO_E_NOTPOOLED _HRESULT_TYPEDEF_(0x8004E02CL) -#define CO_E_NOTCONSTRUCTED _HRESULT_TYPEDEF_(0x8004E02DL) -#define CO_E_NOSYNCHRONIZATION _HRESULT_TYPEDEF_(0x8004E02EL) -#define CO_E_ISOLEVELMISMATCH _HRESULT_TYPEDEF_(0x8004E02FL) -#define OLE_S_USEREG _HRESULT_TYPEDEF_(0x00040000L) -#define OLE_S_STATIC _HRESULT_TYPEDEF_(0x00040001L) -#define OLE_S_MAC_CLIPFORMAT _HRESULT_TYPEDEF_(0x00040002L) -#define DRAGDROP_S_DROP _HRESULT_TYPEDEF_(0x00040100L) -#define DRAGDROP_S_CANCEL _HRESULT_TYPEDEF_(0x00040101L) -#define DRAGDROP_S_USEDEFAULTCURSORS _HRESULT_TYPEDEF_(0x00040102L) -#define DATA_S_SAMEFORMATETC _HRESULT_TYPEDEF_(0x00040130L) -#define VIEW_S_ALREADY_FROZEN _HRESULT_TYPEDEF_(0x00040140L) -#define CACHE_S_FORMATETC_NOTSUPPORTED _HRESULT_TYPEDEF_(0x00040170L) -#define CACHE_S_SAMECACHE _HRESULT_TYPEDEF_(0x00040171L) -#define CACHE_S_SOMECACHES_NOTUPDATED _HRESULT_TYPEDEF_(0x00040172L) -#define OLEOBJ_S_INVALIDVERB _HRESULT_TYPEDEF_(0x00040180L) -#define OLEOBJ_S_CANNOT_DOVERB_NOW _HRESULT_TYPEDEF_(0x00040181L) -#define OLEOBJ_S_INVALIDHWND _HRESULT_TYPEDEF_(0x00040182L) -#define INPLACE_S_TRUNCATED _HRESULT_TYPEDEF_(0x000401A0L) -#define CONVERT10_S_NO_PRESENTATION _HRESULT_TYPEDEF_(0x000401C0L) -#define MK_S_REDUCED_TO_SELF _HRESULT_TYPEDEF_(0x000401E2L) -#define MK_S_ME _HRESULT_TYPEDEF_(0x000401E4L) -#define MK_S_HIM _HRESULT_TYPEDEF_(0x000401E5L) -#define MK_S_US _HRESULT_TYPEDEF_(0x000401E6L) -#define MK_S_MONIKERALREADYREGISTERED _HRESULT_TYPEDEF_(0x000401E7L) -#define SCHED_S_TASK_READY _HRESULT_TYPEDEF_(0x00041300L) -#define SCHED_S_TASK_RUNNING _HRESULT_TYPEDEF_(0x00041301L) -#define SCHED_S_TASK_DISABLED _HRESULT_TYPEDEF_(0x00041302L) -#define SCHED_S_TASK_HAS_NOT_RUN _HRESULT_TYPEDEF_(0x00041303L) -#define SCHED_S_TASK_NO_MORE_RUNS _HRESULT_TYPEDEF_(0x00041304L) -#define SCHED_S_TASK_NOT_SCHEDULED _HRESULT_TYPEDEF_(0x00041305L) -#define SCHED_S_TASK_TERMINATED _HRESULT_TYPEDEF_(0x00041306L) -#define SCHED_S_TASK_NO_VALID_TRIGGERS _HRESULT_TYPEDEF_(0x00041307L) -#define SCHED_S_EVENT_TRIGGER _HRESULT_TYPEDEF_(0x00041308L) -#define SCHED_E_TRIGGER_NOT_FOUND _HRESULT_TYPEDEF_(0x80041309L) -#define SCHED_E_TASK_NOT_READY _HRESULT_TYPEDEF_(0x8004130AL) -#define SCHED_E_TASK_NOT_RUNNING _HRESULT_TYPEDEF_(0x8004130BL) -#define SCHED_E_SERVICE_NOT_INSTALLED _HRESULT_TYPEDEF_(0x8004130CL) -#define SCHED_E_CANNOT_OPEN_TASK _HRESULT_TYPEDEF_(0x8004130DL) -#define SCHED_E_INVALID_TASK _HRESULT_TYPEDEF_(0x8004130EL) -#define SCHED_E_ACCOUNT_INFORMATION_NOT_SET _HRESULT_TYPEDEF_(0x8004130FL) -#define SCHED_E_ACCOUNT_NAME_NOT_FOUND _HRESULT_TYPEDEF_(0x80041310L) -#define SCHED_E_ACCOUNT_DBASE_CORRUPT _HRESULT_TYPEDEF_(0x80041311L) -#define SCHED_E_NO_SECURITY_SERVICES _HRESULT_TYPEDEF_(0x80041312L) -#define SCHED_E_UNKNOWN_OBJECT_VERSION _HRESULT_TYPEDEF_(0x80041313L) -#define SCHED_E_UNSUPPORTED_ACCOUNT_OPTION _HRESULT_TYPEDEF_(0x80041314L) -#define SCHED_E_SERVICE_NOT_RUNNING _HRESULT_TYPEDEF_(0x80041315L) -#define CO_E_CLASS_CREATE_FAILED _HRESULT_TYPEDEF_(0x80080001L) -#define CO_E_SCM_ERROR _HRESULT_TYPEDEF_(0x80080002L) -#define CO_E_SCM_RPC_FAILURE _HRESULT_TYPEDEF_(0x80080003L) -#define CO_E_BAD_PATH _HRESULT_TYPEDEF_(0x80080004L) -#define CO_E_SERVER_EXEC_FAILURE _HRESULT_TYPEDEF_(0x80080005L) -#define CO_E_OBJSRV_RPC_FAILURE _HRESULT_TYPEDEF_(0x80080006L) -#define MK_E_NO_NORMALIZED _HRESULT_TYPEDEF_(0x80080007L) -#define CO_E_SERVER_STOPPING _HRESULT_TYPEDEF_(0x80080008L) -#define MEM_E_INVALID_ROOT _HRESULT_TYPEDEF_(0x80080009L) -#define MEM_E_INVALID_LINK _HRESULT_TYPEDEF_(0x80080010L) -#define MEM_E_INVALID_SIZE _HRESULT_TYPEDEF_(0x80080011L) -#define CO_S_NOTALLINTERFACES _HRESULT_TYPEDEF_(0x00080012L) -#define CO_S_MACHINENAMENOTFOUND _HRESULT_TYPEDEF_(0x00080013L) -#define DISP_E_UNKNOWNINTERFACE _HRESULT_TYPEDEF_(0x80020001L) -#define DISP_E_MEMBERNOTFOUND _HRESULT_TYPEDEF_(0x80020003L) -#define DISP_E_PARAMNOTFOUND _HRESULT_TYPEDEF_(0x80020004L) -#define DISP_E_TYPEMISMATCH _HRESULT_TYPEDEF_(0x80020005L) -#define DISP_E_UNKNOWNNAME _HRESULT_TYPEDEF_(0x80020006L) -#define DISP_E_NONAMEDARGS _HRESULT_TYPEDEF_(0x80020007L) -#define DISP_E_BADVARTYPE _HRESULT_TYPEDEF_(0x80020008L) -#define DISP_E_EXCEPTION _HRESULT_TYPEDEF_(0x80020009L) -#define DISP_E_OVERFLOW _HRESULT_TYPEDEF_(0x8002000AL) -#define DISP_E_BADINDEX _HRESULT_TYPEDEF_(0x8002000BL) -#define DISP_E_UNKNOWNLCID _HRESULT_TYPEDEF_(0x8002000CL) -#define DISP_E_ARRAYISLOCKED _HRESULT_TYPEDEF_(0x8002000DL) -#define DISP_E_BADPARAMCOUNT _HRESULT_TYPEDEF_(0x8002000EL) -#define DISP_E_PARAMNOTOPTIONAL _HRESULT_TYPEDEF_(0x8002000FL) -#define DISP_E_BADCALLEE _HRESULT_TYPEDEF_(0x80020010L) -#define DISP_E_NOTACOLLECTION _HRESULT_TYPEDEF_(0x80020011L) -#define DISP_E_DIVBYZERO _HRESULT_TYPEDEF_(0x80020012L) -#define DISP_E_BUFFERTOOSMALL _HRESULT_TYPEDEF_(0x80020013L) -#define TYPE_E_BUFFERTOOSMALL _HRESULT_TYPEDEF_(0x80028016L) -#define TYPE_E_FIELDNOTFOUND _HRESULT_TYPEDEF_(0x80028017L) -#define TYPE_E_INVDATAREAD _HRESULT_TYPEDEF_(0x80028018L) -#define TYPE_E_UNSUPFORMAT _HRESULT_TYPEDEF_(0x80028019L) -#define TYPE_E_REGISTRYACCESS _HRESULT_TYPEDEF_(0x8002801CL) -#define TYPE_E_LIBNOTREGISTERED _HRESULT_TYPEDEF_(0x8002801DL) -#define TYPE_E_UNDEFINEDTYPE _HRESULT_TYPEDEF_(0x80028027L) -#define TYPE_E_QUALIFIEDNAMEDISALLOWED _HRESULT_TYPEDEF_(0x80028028L) -#define TYPE_E_INVALIDSTATE _HRESULT_TYPEDEF_(0x80028029L) -#define TYPE_E_WRONGTYPEKIND _HRESULT_TYPEDEF_(0x8002802AL) -#define TYPE_E_ELEMENTNOTFOUND _HRESULT_TYPEDEF_(0x8002802BL) -#define TYPE_E_AMBIGUOUSNAME _HRESULT_TYPEDEF_(0x8002802CL) -#define TYPE_E_NAMECONFLICT _HRESULT_TYPEDEF_(0x8002802DL) -#define TYPE_E_UNKNOWNLCID _HRESULT_TYPEDEF_(0x8002802EL) -#define TYPE_E_DLLFUNCTIONNOTFOUND _HRESULT_TYPEDEF_(0x8002802FL) -#define TYPE_E_BADMODULEKIND _HRESULT_TYPEDEF_(0x800288BDL) -#define TYPE_E_SIZETOOBIG _HRESULT_TYPEDEF_(0x800288C5L) -#define TYPE_E_DUPLICATEID _HRESULT_TYPEDEF_(0x800288C6L) -#define TYPE_E_INVALIDID _HRESULT_TYPEDEF_(0x800288CFL) -#define TYPE_E_TYPEMISMATCH _HRESULT_TYPEDEF_(0x80028CA0L) -#define TYPE_E_OUTOFBOUNDS _HRESULT_TYPEDEF_(0x80028CA1L) -#define TYPE_E_IOERROR _HRESULT_TYPEDEF_(0x80028CA2L) -#define TYPE_E_CANTCREATETMPFILE _HRESULT_TYPEDEF_(0x80028CA3L) -#define TYPE_E_CANTLOADLIBRARY _HRESULT_TYPEDEF_(0x80029C4AL) -#define TYPE_E_INCONSISTENTPROPFUNCS _HRESULT_TYPEDEF_(0x80029C83L) -#define TYPE_E_CIRCULARTYPE _HRESULT_TYPEDEF_(0x80029C84L) -#define STG_E_INVALIDFUNCTION _HRESULT_TYPEDEF_(0x80030001L) -#define STG_E_FILENOTFOUND _HRESULT_TYPEDEF_(0x80030002L) -#define STG_E_PATHNOTFOUND _HRESULT_TYPEDEF_(0x80030003L) -#define STG_E_TOOMANYOPENFILES _HRESULT_TYPEDEF_(0x80030004L) -#define STG_E_ACCESSDENIED _HRESULT_TYPEDEF_(0x80030005L) -#define STG_E_INVALIDHANDLE _HRESULT_TYPEDEF_(0x80030006L) -#define STG_E_INSUFFICIENTMEMORY _HRESULT_TYPEDEF_(0x80030008L) -#define STG_E_INVALIDPOINTER _HRESULT_TYPEDEF_(0x80030009L) -#define STG_E_NOMOREFILES _HRESULT_TYPEDEF_(0x80030012L) -#define STG_E_DISKISWRITEPROTECTED _HRESULT_TYPEDEF_(0x80030013L) -#define STG_E_SEEKERROR _HRESULT_TYPEDEF_(0x80030019L) -#define STG_E_WRITEFAULT _HRESULT_TYPEDEF_(0x8003001DL) -#define STG_E_READFAULT _HRESULT_TYPEDEF_(0x8003001EL) -#define STG_E_SHAREVIOLATION _HRESULT_TYPEDEF_(0x80030020L) -#define STG_E_LOCKVIOLATION _HRESULT_TYPEDEF_(0x80030021L) -#define STG_E_FILEALREADYEXISTS _HRESULT_TYPEDEF_(0x80030050L) -#define STG_E_INVALIDPARAMETER _HRESULT_TYPEDEF_(0x80030057L) -#define STG_E_MEDIUMFULL _HRESULT_TYPEDEF_(0x80030070L) -#define STG_E_PROPSETMISMATCHED _HRESULT_TYPEDEF_(0x800300F0L) -#define STG_E_ABNORMALAPIEXIT _HRESULT_TYPEDEF_(0x800300FAL) -#define STG_E_INVALIDHEADER _HRESULT_TYPEDEF_(0x800300FBL) -#define STG_E_INVALIDNAME _HRESULT_TYPEDEF_(0x800300FCL) -#define STG_E_UNKNOWN _HRESULT_TYPEDEF_(0x800300FDL) -#define STG_E_UNIMPLEMENTEDFUNCTION _HRESULT_TYPEDEF_(0x800300FEL) -#define STG_E_INVALIDFLAG _HRESULT_TYPEDEF_(0x800300FFL) -#define STG_E_INUSE _HRESULT_TYPEDEF_(0x80030100L) -#define STG_E_NOTCURRENT _HRESULT_TYPEDEF_(0x80030101L) -#define STG_E_REVERTED _HRESULT_TYPEDEF_(0x80030102L) -#define STG_E_CANTSAVE _HRESULT_TYPEDEF_(0x80030103L) -#define STG_E_OLDFORMAT _HRESULT_TYPEDEF_(0x80030104L) -#define STG_E_OLDDLL _HRESULT_TYPEDEF_(0x80030105L) -#define STG_E_SHAREREQUIRED _HRESULT_TYPEDEF_(0x80030106L) -#define STG_E_NOTFILEBASEDSTORAGE _HRESULT_TYPEDEF_(0x80030107L) -#define STG_E_EXTANTMARSHALLINGS _HRESULT_TYPEDEF_(0x80030108L) -#define STG_E_DOCFILECORRUPT _HRESULT_TYPEDEF_(0x80030109L) -#define STG_E_BADBASEADDRESS _HRESULT_TYPEDEF_(0x80030110L) -#define STG_E_DOCFILETOOLARGE _HRESULT_TYPEDEF_(0x80030111L) -#define STG_E_NOTSIMPLEFORMAT _HRESULT_TYPEDEF_(0x80030112L) -#define STG_E_INCOMPLETE _HRESULT_TYPEDEF_(0x80030201L) -#define STG_E_TERMINATED _HRESULT_TYPEDEF_(0x80030202L) -#define STG_S_CONVERTED _HRESULT_TYPEDEF_(0x00030200L) -#define STG_S_BLOCK _HRESULT_TYPEDEF_(0x00030201L) -#define STG_S_RETRYNOW _HRESULT_TYPEDEF_(0x00030202L) -#define STG_S_MONITORING _HRESULT_TYPEDEF_(0x00030203L) -#define STG_S_MULTIPLEOPENS _HRESULT_TYPEDEF_(0x00030204L) -#define STG_S_CONSOLIDATIONFAILED _HRESULT_TYPEDEF_(0x00030205L) -#define STG_S_CANNOTCONSOLIDATE _HRESULT_TYPEDEF_(0x00030206L) -#define STG_E_STATUS_COPY_PROTECTION_FAILURE _HRESULT_TYPEDEF_(0x80030305L) -#define STG_E_CSS_AUTHENTICATION_FAILURE _HRESULT_TYPEDEF_(0x80030306L) -#define STG_E_CSS_KEY_NOT_PRESENT _HRESULT_TYPEDEF_(0x80030307L) -#define STG_E_CSS_KEY_NOT_ESTABLISHED _HRESULT_TYPEDEF_(0x80030308L) -#define STG_E_CSS_SCRAMBLED_SECTOR _HRESULT_TYPEDEF_(0x80030309L) -#define STG_E_CSS_REGION_MISMATCH _HRESULT_TYPEDEF_(0x8003030AL) -#define STG_E_RESETS_EXHAUSTED _HRESULT_TYPEDEF_(0x8003030BL) -#define RPC_E_CALL_REJECTED _HRESULT_TYPEDEF_(0x80010001L) -#define RPC_E_CALL_CANCELED _HRESULT_TYPEDEF_(0x80010002L) -#define RPC_E_CANTPOST_INSENDCALL _HRESULT_TYPEDEF_(0x80010003L) -#define RPC_E_CANTCALLOUT_INASYNCCALL _HRESULT_TYPEDEF_(0x80010004L) -#define RPC_E_CANTCALLOUT_INEXTERNALCALL _HRESULT_TYPEDEF_(0x80010005L) -#define RPC_E_CONNECTION_TERMINATED _HRESULT_TYPEDEF_(0x80010006L) -#define RPC_E_SERVER_DIED _HRESULT_TYPEDEF_(0x80010007L) -#define RPC_E_CLIENT_DIED _HRESULT_TYPEDEF_(0x80010008L) -#define RPC_E_INVALID_DATAPACKET _HRESULT_TYPEDEF_(0x80010009L) -#define RPC_E_CANTTRANSMIT_CALL _HRESULT_TYPEDEF_(0x8001000AL) -#define RPC_E_CLIENT_CANTMARSHAL_DATA _HRESULT_TYPEDEF_(0x8001000BL) -#define RPC_E_CLIENT_CANTUNMARSHAL_DATA _HRESULT_TYPEDEF_(0x8001000CL) -#define RPC_E_SERVER_CANTMARSHAL_DATA _HRESULT_TYPEDEF_(0x8001000DL) -#define RPC_E_SERVER_CANTUNMARSHAL_DATA _HRESULT_TYPEDEF_(0x8001000EL) -#define RPC_E_INVALID_DATA _HRESULT_TYPEDEF_(0x8001000FL) -#define RPC_E_INVALID_PARAMETER _HRESULT_TYPEDEF_(0x80010010L) -#define RPC_E_CANTCALLOUT_AGAIN _HRESULT_TYPEDEF_(0x80010011L) -#define RPC_E_SERVER_DIED_DNE _HRESULT_TYPEDEF_(0x80010012L) -#define RPC_E_SYS_CALL_FAILED _HRESULT_TYPEDEF_(0x80010100L) -#define RPC_E_OUT_OF_RESOURCES _HRESULT_TYPEDEF_(0x80010101L) -#define RPC_E_ATTEMPTED_MULTITHREAD _HRESULT_TYPEDEF_(0x80010102L) -#define RPC_E_NOT_REGISTERED _HRESULT_TYPEDEF_(0x80010103L) -#define RPC_E_FAULT _HRESULT_TYPEDEF_(0x80010104L) -#define RPC_E_SERVERFAULT _HRESULT_TYPEDEF_(0x80010105L) -#define RPC_E_CHANGED_MODE _HRESULT_TYPEDEF_(0x80010106L) -#define RPC_E_INVALIDMETHOD _HRESULT_TYPEDEF_(0x80010107L) -#define RPC_E_DISCONNECTED _HRESULT_TYPEDEF_(0x80010108L) -#define RPC_E_RETRY _HRESULT_TYPEDEF_(0x80010109L) -#define RPC_E_SERVERCALL_RETRYLATER _HRESULT_TYPEDEF_(0x8001010AL) -#define RPC_E_SERVERCALL_REJECTED _HRESULT_TYPEDEF_(0x8001010BL) -#define RPC_E_INVALID_CALLDATA _HRESULT_TYPEDEF_(0x8001010CL) -#define RPC_E_CANTCALLOUT_ININPUTSYNCCALL _HRESULT_TYPEDEF_(0x8001010DL) -#define RPC_E_WRONG_THREAD _HRESULT_TYPEDEF_(0x8001010EL) -#define RPC_E_THREAD_NOT_INIT _HRESULT_TYPEDEF_(0x8001010FL) -#define RPC_E_VERSION_MISMATCH _HRESULT_TYPEDEF_(0x80010110L) -#define RPC_E_INVALID_HEADER _HRESULT_TYPEDEF_(0x80010111L) -#define RPC_E_INVALID_EXTENSION _HRESULT_TYPEDEF_(0x80010112L) -#define RPC_E_INVALID_IPID _HRESULT_TYPEDEF_(0x80010113L) -#define RPC_E_INVALID_OBJECT _HRESULT_TYPEDEF_(0x80010114L) -#define RPC_S_CALLPENDING _HRESULT_TYPEDEF_(0x80010115L) -#define RPC_S_WAITONTIMER _HRESULT_TYPEDEF_(0x80010116L) -#define RPC_E_CALL_COMPLETE _HRESULT_TYPEDEF_(0x80010117L) -#define RPC_E_UNSECURE_CALL _HRESULT_TYPEDEF_(0x80010118L) -#define RPC_E_TOO_LATE _HRESULT_TYPEDEF_(0x80010119L) -#define RPC_E_NO_GOOD_SECURITY_PACKAGES _HRESULT_TYPEDEF_(0x8001011AL) -#define RPC_E_ACCESS_DENIED _HRESULT_TYPEDEF_(0x8001011BL) -#define RPC_E_REMOTE_DISABLED _HRESULT_TYPEDEF_(0x8001011CL) -#define RPC_E_INVALID_OBJREF _HRESULT_TYPEDEF_(0x8001011DL) -#define RPC_E_NO_CONTEXT _HRESULT_TYPEDEF_(0x8001011EL) -#define RPC_E_TIMEOUT _HRESULT_TYPEDEF_(0x8001011FL) -#define RPC_E_NO_SYNC _HRESULT_TYPEDEF_(0x80010120L) -#define RPC_E_FULLSIC_REQUIRED _HRESULT_TYPEDEF_(0x80010121L) -#define RPC_E_INVALID_STD_NAME _HRESULT_TYPEDEF_(0x80010122L) -#define CO_E_FAILEDTOIMPERSONATE _HRESULT_TYPEDEF_(0x80010123L) -#define CO_E_FAILEDTOGETSECCTX _HRESULT_TYPEDEF_(0x80010124L) -#define CO_E_FAILEDTOOPENTHREADTOKEN _HRESULT_TYPEDEF_(0x80010125L) -#define CO_E_FAILEDTOGETTOKENINFO _HRESULT_TYPEDEF_(0x80010126L) -#define CO_E_TRUSTEEDOESNTMATCHCLIENT _HRESULT_TYPEDEF_(0x80010127L) -#define CO_E_FAILEDTOQUERYCLIENTBLANKET _HRESULT_TYPEDEF_(0x80010128L) -#define CO_E_FAILEDTOSETDACL _HRESULT_TYPEDEF_(0x80010129L) -#define CO_E_ACCESSCHECKFAILED _HRESULT_TYPEDEF_(0x8001012AL) -#define CO_E_NETACCESSAPIFAILED _HRESULT_TYPEDEF_(0x8001012BL) -#define CO_E_WRONGTRUSTEENAMESYNTAX _HRESULT_TYPEDEF_(0x8001012CL) -#define CO_E_INVALIDSID _HRESULT_TYPEDEF_(0x8001012DL) -#define CO_E_CONVERSIONFAILED _HRESULT_TYPEDEF_(0x8001012EL) -#define CO_E_NOMATCHINGSIDFOUND _HRESULT_TYPEDEF_(0x8001012FL) -#define CO_E_LOOKUPACCSIDFAILED _HRESULT_TYPEDEF_(0x80010130L) -#define CO_E_NOMATCHINGNAMEFOUND _HRESULT_TYPEDEF_(0x80010131L) -#define CO_E_LOOKUPACCNAMEFAILED _HRESULT_TYPEDEF_(0x80010132L) -#define CO_E_SETSERLHNDLFAILED _HRESULT_TYPEDEF_(0x80010133L) -#define CO_E_FAILEDTOGETWINDIR _HRESULT_TYPEDEF_(0x80010134L) -#define CO_E_PATHTOOLONG _HRESULT_TYPEDEF_(0x80010135L) -#define CO_E_FAILEDTOGENUUID _HRESULT_TYPEDEF_(0x80010136L) -#define CO_E_FAILEDTOCREATEFILE _HRESULT_TYPEDEF_(0x80010137L) -#define CO_E_FAILEDTOCLOSEHANDLE _HRESULT_TYPEDEF_(0x80010138L) -#define CO_E_EXCEEDSYSACLLIMIT _HRESULT_TYPEDEF_(0x80010139L) -#define CO_E_ACESINWRONGORDER _HRESULT_TYPEDEF_(0x8001013AL) -#define CO_E_INCOMPATIBLESTREAMVERSION _HRESULT_TYPEDEF_(0x8001013BL) -#define CO_E_FAILEDTOOPENPROCESSTOKEN _HRESULT_TYPEDEF_(0x8001013CL) -#define CO_E_DECODEFAILED _HRESULT_TYPEDEF_(0x8001013DL) -#define CO_E_ACNOTINITIALIZED _HRESULT_TYPEDEF_(0x8001013FL) -#define CO_E_CANCEL_DISABLED _HRESULT_TYPEDEF_(0x80010140L) -#define RPC_E_UNEXPECTED _HRESULT_TYPEDEF_(0x8001FFFFL) -#define ERROR_AUDITING_DISABLED _HRESULT_TYPEDEF_(0xC0090001L) -#define ERROR_ALL_SIDS_FILTERED _HRESULT_TYPEDEF_(0xC0090002L) -#define NTE_BAD_UID _HRESULT_TYPEDEF_(0x80090001L) -#define NTE_BAD_HASH _HRESULT_TYPEDEF_(0x80090002L) -#define NTE_BAD_KEY _HRESULT_TYPEDEF_(0x80090003L) -#define NTE_BAD_LEN _HRESULT_TYPEDEF_(0x80090004L) -#define NTE_BAD_DATA _HRESULT_TYPEDEF_(0x80090005L) -#define NTE_BAD_SIGNATURE _HRESULT_TYPEDEF_(0x80090006L) -#define NTE_BAD_VER _HRESULT_TYPEDEF_(0x80090007L) -#define NTE_BAD_ALGID _HRESULT_TYPEDEF_(0x80090008L) -#define NTE_BAD_FLAGS _HRESULT_TYPEDEF_(0x80090009L) -#define NTE_BAD_TYPE _HRESULT_TYPEDEF_(0x8009000AL) -#define NTE_BAD_KEY_STATE _HRESULT_TYPEDEF_(0x8009000BL) -#define NTE_BAD_HASH_STATE _HRESULT_TYPEDEF_(0x8009000CL) -#define NTE_NO_KEY _HRESULT_TYPEDEF_(0x8009000DL) -#define NTE_NO_MEMORY _HRESULT_TYPEDEF_(0x8009000EL) -#define NTE_EXISTS _HRESULT_TYPEDEF_(0x8009000FL) -#define NTE_PERM _HRESULT_TYPEDEF_(0x80090010L) -#define NTE_NOT_FOUND _HRESULT_TYPEDEF_(0x80090011L) -#define NTE_DOUBLE_ENCRYPT _HRESULT_TYPEDEF_(0x80090012L) -#define NTE_BAD_PROVIDER _HRESULT_TYPEDEF_(0x80090013L) -#define NTE_BAD_PROV_TYPE _HRESULT_TYPEDEF_(0x80090014L) -#define NTE_BAD_PUBLIC_KEY _HRESULT_TYPEDEF_(0x80090015L) -#define NTE_BAD_KEYSET _HRESULT_TYPEDEF_(0x80090016L) -#define NTE_PROV_TYPE_NOT_DEF _HRESULT_TYPEDEF_(0x80090017L) -#define NTE_PROV_TYPE_ENTRY_BAD _HRESULT_TYPEDEF_(0x80090018L) -#define NTE_KEYSET_NOT_DEF _HRESULT_TYPEDEF_(0x80090019L) -#define NTE_KEYSET_ENTRY_BAD _HRESULT_TYPEDEF_(0x8009001AL) -#define NTE_PROV_TYPE_NO_MATCH _HRESULT_TYPEDEF_(0x8009001BL) -#define NTE_SIGNATURE_FILE_BAD _HRESULT_TYPEDEF_(0x8009001CL) -#define NTE_PROVIDER_DLL_FAIL _HRESULT_TYPEDEF_(0x8009001DL) -#define NTE_PROV_DLL_NOT_FOUND _HRESULT_TYPEDEF_(0x8009001EL) -#define NTE_BAD_KEYSET_PARAM _HRESULT_TYPEDEF_(0x8009001FL) -#define NTE_FAIL _HRESULT_TYPEDEF_(0x80090020L) -#define NTE_SYS_ERR _HRESULT_TYPEDEF_(0x80090021L) -#define NTE_SILENT_CONTEXT _HRESULT_TYPEDEF_(0x80090022L) -#define NTE_TOKEN_KEYSET_STORAGE_FULL _HRESULT_TYPEDEF_(0x80090023L) -#define NTE_TEMPORARY_PROFILE _HRESULT_TYPEDEF_(0x80090024L) -#define NTE_FIXEDPARAMETER _HRESULT_TYPEDEF_(0x80090025L) -#define SEC_E_INSUFFICIENT_MEMORY _HRESULT_TYPEDEF_(0x80090300L) -#define SEC_E_INVALID_HANDLE _HRESULT_TYPEDEF_(0x80090301L) -#define SEC_E_UNSUPPORTED_FUNCTION _HRESULT_TYPEDEF_(0x80090302L) -#define SEC_E_TARGET_UNKNOWN _HRESULT_TYPEDEF_(0x80090303L) -#define SEC_E_INTERNAL_ERROR _HRESULT_TYPEDEF_(0x80090304L) -#define SEC_E_SECPKG_NOT_FOUND _HRESULT_TYPEDEF_(0x80090305L) -#define SEC_E_NOT_OWNER _HRESULT_TYPEDEF_(0x80090306L) -#define SEC_E_CANNOT_INSTALL _HRESULT_TYPEDEF_(0x80090307L) -#define SEC_E_INVALID_TOKEN _HRESULT_TYPEDEF_(0x80090308L) -#define SEC_E_CANNOT_PACK _HRESULT_TYPEDEF_(0x80090309L) -#define SEC_E_QOP_NOT_SUPPORTED _HRESULT_TYPEDEF_(0x8009030AL) -#define SEC_E_NO_IMPERSONATION _HRESULT_TYPEDEF_(0x8009030BL) -#define SEC_E_LOGON_DENIED _HRESULT_TYPEDEF_(0x8009030CL) -#define SEC_E_UNKNOWN_CREDENTIALS _HRESULT_TYPEDEF_(0x8009030DL) -#define SEC_E_NO_CREDENTIALS _HRESULT_TYPEDEF_(0x8009030EL) -#define SEC_E_MESSAGE_ALTERED _HRESULT_TYPEDEF_(0x8009030FL) -#define SEC_E_OUT_OF_SEQUENCE _HRESULT_TYPEDEF_(0x80090310L) -#define SEC_E_NO_AUTHENTICATING_AUTHORITY _HRESULT_TYPEDEF_(0x80090311L) -#define SEC_I_CONTINUE_NEEDED _HRESULT_TYPEDEF_(0x00090312L) -#define SEC_I_COMPLETE_NEEDED _HRESULT_TYPEDEF_(0x00090313L) -#define SEC_I_COMPLETE_AND_CONTINUE _HRESULT_TYPEDEF_(0x00090314L) -#define SEC_I_LOCAL_LOGON _HRESULT_TYPEDEF_(0x00090315L) -#define SEC_E_BAD_PKGID _HRESULT_TYPEDEF_(0x80090316L) -#define SEC_E_CONTEXT_EXPIRED _HRESULT_TYPEDEF_(0x80090317L) -#define SEC_I_CONTEXT_EXPIRED _HRESULT_TYPEDEF_(0x00090317L) -#define SEC_E_INCOMPLETE_MESSAGE _HRESULT_TYPEDEF_(0x80090318L) -#define SEC_E_INCOMPLETE_CREDENTIALS _HRESULT_TYPEDEF_(0x80090320L) -#define SEC_E_BUFFER_TOO_SMALL _HRESULT_TYPEDEF_(0x80090321L) -#define SEC_I_INCOMPLETE_CREDENTIALS _HRESULT_TYPEDEF_(0x00090320L) -#define SEC_I_RENEGOTIATE _HRESULT_TYPEDEF_(0x00090321L) -#define SEC_E_WRONG_PRINCIPAL _HRESULT_TYPEDEF_(0x80090322L) -#define SEC_I_NO_LSA_CONTEXT _HRESULT_TYPEDEF_(0x00090323L) -#define SEC_E_TIME_SKEW _HRESULT_TYPEDEF_(0x80090324L) -#define SEC_E_UNTRUSTED_ROOT _HRESULT_TYPEDEF_(0x80090325L) -#define SEC_E_ILLEGAL_MESSAGE _HRESULT_TYPEDEF_(0x80090326L) -#define SEC_E_CERT_UNKNOWN _HRESULT_TYPEDEF_(0x80090327L) -#define SEC_E_CERT_EXPIRED _HRESULT_TYPEDEF_(0x80090328L) -#define SEC_E_ENCRYPT_FAILURE _HRESULT_TYPEDEF_(0x80090329L) -#define SEC_E_DECRYPT_FAILURE _HRESULT_TYPEDEF_(0x80090330L) -#define SEC_E_ALGORITHM_MISMATCH _HRESULT_TYPEDEF_(0x80090331L) -#define SEC_E_SECURITY_QOS_FAILED _HRESULT_TYPEDEF_(0x80090332L) -#define SEC_E_UNFINISHED_CONTEXT_DELETED _HRESULT_TYPEDEF_(0x80090333L) -#define SEC_E_NO_TGT_REPLY _HRESULT_TYPEDEF_(0x80090334L) -#define SEC_E_NO_IP_ADDRESSES _HRESULT_TYPEDEF_(0x80090335L) -#define SEC_E_WRONG_CREDENTIAL_HANDLE _HRESULT_TYPEDEF_(0x80090336L) -#define SEC_E_CRYPTO_SYSTEM_INVALID _HRESULT_TYPEDEF_(0x80090337L) -#define SEC_E_MAX_REFERRALS_EXCEEDED _HRESULT_TYPEDEF_(0x80090338L) -#define SEC_E_MUST_BE_KDC _HRESULT_TYPEDEF_(0x80090339L) -#define SEC_E_STRONG_CRYPTO_NOT_SUPPORTED _HRESULT_TYPEDEF_(0x8009033AL) -#define SEC_E_TOO_MANY_PRINCIPALS _HRESULT_TYPEDEF_(0x8009033BL) -#define SEC_E_NO_PA_DATA _HRESULT_TYPEDEF_(0x8009033CL) -#define SEC_E_PKINIT_NAME_MISMATCH _HRESULT_TYPEDEF_(0x8009033DL) -#define SEC_E_SMARTCARD_LOGON_REQUIRED _HRESULT_TYPEDEF_(0x8009033EL) -#define SEC_E_SHUTDOWN_IN_PROGRESS _HRESULT_TYPEDEF_(0x8009033FL) -#define SEC_E_KDC_INVALID_REQUEST _HRESULT_TYPEDEF_(0x80090340L) -#define SEC_E_KDC_UNABLE_TO_REFER _HRESULT_TYPEDEF_(0x80090341L) -#define SEC_E_KDC_UNKNOWN_ETYPE _HRESULT_TYPEDEF_(0x80090342L) -#define SEC_E_UNSUPPORTED_PREAUTH _HRESULT_TYPEDEF_(0x80090343L) -#define SEC_E_DELEGATION_REQUIRED _HRESULT_TYPEDEF_(0x80090345L) -#define SEC_E_BAD_BINDINGS _HRESULT_TYPEDEF_(0x80090346L) -#define SEC_E_MULTIPLE_ACCOUNTS _HRESULT_TYPEDEF_(0x80090347L) -#define SEC_E_NO_KERB_KEY _HRESULT_TYPEDEF_(0x80090348L) -#define SEC_E_CERT_WRONG_USAGE _HRESULT_TYPEDEF_(0x80090349L) -#define SEC_E_DOWNGRADE_DETECTED _HRESULT_TYPEDEF_(0x80090350L) -#define SEC_E_SMARTCARD_CERT_REVOKED _HRESULT_TYPEDEF_(0x80090351L) -#define SEC_E_ISSUING_CA_UNTRUSTED _HRESULT_TYPEDEF_(0x80090352L) -#define SEC_E_REVOCATION_OFFLINE_C _HRESULT_TYPEDEF_(0x80090353L) -#define SEC_E_PKINIT_CLIENT_FAILURE _HRESULT_TYPEDEF_(0x80090354L) -#define SEC_E_SMARTCARD_CERT_EXPIRED _HRESULT_TYPEDEF_(0x80090355L) -#define SEC_E_NO_S4U_PROT_SUPPORT _HRESULT_TYPEDEF_(0x80090356L) -#define SEC_E_CROSSREALM_DELEGATION_FAILURE _HRESULT_TYPEDEF_(0x80090357L) -#define SEC_E_REVOCATION_OFFLINE_KDC _HRESULT_TYPEDEF_(0x80090358L) -#define SEC_E_ISSUING_CA_UNTRUSTED_KDC _HRESULT_TYPEDEF_(0x80090359L) -#define SEC_E_KDC_CERT_EXPIRED _HRESULT_TYPEDEF_(0x8009035AL) -#define SEC_E_KDC_CERT_REVOKED _HRESULT_TYPEDEF_(0x8009035BL) -#define SEC_E_NO_SPM SEC_E_INTERNAL_ERROR -#define SEC_E_NOT_SUPPORTED SEC_E_UNSUPPORTED_FUNCTION -#define CRYPT_E_MSG_ERROR _HRESULT_TYPEDEF_(0x80091001L) -#define CRYPT_E_UNKNOWN_ALGO _HRESULT_TYPEDEF_(0x80091002L) -#define CRYPT_E_OID_FORMAT _HRESULT_TYPEDEF_(0x80091003L) -#define CRYPT_E_INVALID_MSG_TYPE _HRESULT_TYPEDEF_(0x80091004L) -#define CRYPT_E_UNEXPECTED_ENCODING _HRESULT_TYPEDEF_(0x80091005L) -#define CRYPT_E_AUTH_ATTR_MISSING _HRESULT_TYPEDEF_(0x80091006L) -#define CRYPT_E_HASH_VALUE _HRESULT_TYPEDEF_(0x80091007L) -#define CRYPT_E_INVALID_INDEX _HRESULT_TYPEDEF_(0x80091008L) -#define CRYPT_E_ALREADY_DECRYPTED _HRESULT_TYPEDEF_(0x80091009L) -#define CRYPT_E_NOT_DECRYPTED _HRESULT_TYPEDEF_(0x8009100AL) -#define CRYPT_E_RECIPIENT_NOT_FOUND _HRESULT_TYPEDEF_(0x8009100BL) -#define CRYPT_E_CONTROL_TYPE _HRESULT_TYPEDEF_(0x8009100CL) -#define CRYPT_E_ISSUER_SERIALNUMBER _HRESULT_TYPEDEF_(0x8009100DL) -#define CRYPT_E_SIGNER_NOT_FOUND _HRESULT_TYPEDEF_(0x8009100EL) -#define CRYPT_E_ATTRIBUTES_MISSING _HRESULT_TYPEDEF_(0x8009100FL) -#define CRYPT_E_STREAM_MSG_NOT_READY _HRESULT_TYPEDEF_(0x80091010L) -#define CRYPT_E_STREAM_INSUFFICIENT_DATA _HRESULT_TYPEDEF_(0x80091011L) -#define CRYPT_I_NEW_PROTECTION_REQUIRED _HRESULT_TYPEDEF_(0x00091012L) -#define CRYPT_E_BAD_LEN _HRESULT_TYPEDEF_(0x80092001L) -#define CRYPT_E_BAD_ENCODE _HRESULT_TYPEDEF_(0x80092002L) -#define CRYPT_E_FILE_ERROR _HRESULT_TYPEDEF_(0x80092003L) -#define CRYPT_E_NOT_FOUND _HRESULT_TYPEDEF_(0x80092004L) -#define CRYPT_E_EXISTS _HRESULT_TYPEDEF_(0x80092005L) -#define CRYPT_E_NO_PROVIDER _HRESULT_TYPEDEF_(0x80092006L) -#define CRYPT_E_SELF_SIGNED _HRESULT_TYPEDEF_(0x80092007L) -#define CRYPT_E_DELETED_PREV _HRESULT_TYPEDEF_(0x80092008L) -#define CRYPT_E_NO_MATCH _HRESULT_TYPEDEF_(0x80092009L) -#define CRYPT_E_UNEXPECTED_MSG_TYPE _HRESULT_TYPEDEF_(0x8009200AL) -#define CRYPT_E_NO_KEY_PROPERTY _HRESULT_TYPEDEF_(0x8009200BL) -#define CRYPT_E_NO_DECRYPT_CERT _HRESULT_TYPEDEF_(0x8009200CL) -#define CRYPT_E_BAD_MSG _HRESULT_TYPEDEF_(0x8009200DL) -#define CRYPT_E_NO_SIGNER _HRESULT_TYPEDEF_(0x8009200EL) -#define CRYPT_E_PENDING_CLOSE _HRESULT_TYPEDEF_(0x8009200FL) -#define CRYPT_E_REVOKED _HRESULT_TYPEDEF_(0x80092010L) -#define CRYPT_E_NO_REVOCATION_DLL _HRESULT_TYPEDEF_(0x80092011L) -#define CRYPT_E_NO_REVOCATION_CHECK _HRESULT_TYPEDEF_(0x80092012L) -#define CRYPT_E_REVOCATION_OFFLINE _HRESULT_TYPEDEF_(0x80092013L) -#define CRYPT_E_NOT_IN_REVOCATION_DATABASE _HRESULT_TYPEDEF_(0x80092014L) -#define CRYPT_E_INVALID_NUMERIC_STRING _HRESULT_TYPEDEF_(0x80092020L) -#define CRYPT_E_INVALID_PRINTABLE_STRING _HRESULT_TYPEDEF_(0x80092021L) -#define CRYPT_E_INVALID_IA5_STRING _HRESULT_TYPEDEF_(0x80092022L) -#define CRYPT_E_INVALID_X500_STRING _HRESULT_TYPEDEF_(0x80092023L) -#define CRYPT_E_NOT_CHAR_STRING _HRESULT_TYPEDEF_(0x80092024L) -#define CRYPT_E_FILERESIZED _HRESULT_TYPEDEF_(0x80092025L) -#define CRYPT_E_SECURITY_SETTINGS _HRESULT_TYPEDEF_(0x80092026L) -#define CRYPT_E_NO_VERIFY_USAGE_DLL _HRESULT_TYPEDEF_(0x80092027L) -#define CRYPT_E_NO_VERIFY_USAGE_CHECK _HRESULT_TYPEDEF_(0x80092028L) -#define CRYPT_E_VERIFY_USAGE_OFFLINE _HRESULT_TYPEDEF_(0x80092029L) -#define CRYPT_E_NOT_IN_CTL _HRESULT_TYPEDEF_(0x8009202AL) -#define CRYPT_E_NO_TRUSTED_SIGNER _HRESULT_TYPEDEF_(0x8009202BL) -#define CRYPT_E_MISSING_PUBKEY_PARA _HRESULT_TYPEDEF_(0x8009202CL) -#define CRYPT_E_OSS_ERROR _HRESULT_TYPEDEF_(0x80093000L) -#define OSS_MORE_BUF _HRESULT_TYPEDEF_(0x80093001L) -#define OSS_NEGATIVE_UINTEGER _HRESULT_TYPEDEF_(0x80093002L) -#define OSS_PDU_RANGE _HRESULT_TYPEDEF_(0x80093003L) -#define OSS_MORE_INPUT _HRESULT_TYPEDEF_(0x80093004L) -#define OSS_DATA_ERROR _HRESULT_TYPEDEF_(0x80093005L) -#define OSS_BAD_ARG _HRESULT_TYPEDEF_(0x80093006L) -#define OSS_BAD_VERSION _HRESULT_TYPEDEF_(0x80093007L) -#define OSS_OUT_MEMORY _HRESULT_TYPEDEF_(0x80093008L) -#define OSS_PDU_MISMATCH _HRESULT_TYPEDEF_(0x80093009L) -#define OSS_LIMITED _HRESULT_TYPEDEF_(0x8009300AL) -#define OSS_BAD_PTR _HRESULT_TYPEDEF_(0x8009300BL) -#define OSS_BAD_TIME _HRESULT_TYPEDEF_(0x8009300CL) -#define OSS_INDEFINITE_NOT_SUPPORTED _HRESULT_TYPEDEF_(0x8009300DL) -#define OSS_MEM_ERROR _HRESULT_TYPEDEF_(0x8009300EL) -#define OSS_BAD_TABLE _HRESULT_TYPEDEF_(0x8009300FL) -#define OSS_TOO_LONG _HRESULT_TYPEDEF_(0x80093010L) -#define OSS_CONSTRAINT_VIOLATED _HRESULT_TYPEDEF_(0x80093011L) -#define OSS_FATAL_ERROR _HRESULT_TYPEDEF_(0x80093012L) -#define OSS_ACCESS_SERIALIZATION_ERROR _HRESULT_TYPEDEF_(0x80093013L) -#define OSS_NULL_TBL _HRESULT_TYPEDEF_(0x80093014L) -#define OSS_NULL_FCN _HRESULT_TYPEDEF_(0x80093015L) -#define OSS_BAD_ENCRULES _HRESULT_TYPEDEF_(0x80093016L) -#define OSS_UNAVAIL_ENCRULES _HRESULT_TYPEDEF_(0x80093017L) -#define OSS_CANT_OPEN_TRACE_WINDOW _HRESULT_TYPEDEF_(0x80093018L) -#define OSS_UNIMPLEMENTED _HRESULT_TYPEDEF_(0x80093019L) -#define OSS_OID_DLL_NOT_LINKED _HRESULT_TYPEDEF_(0x8009301AL) -#define OSS_CANT_OPEN_TRACE_FILE _HRESULT_TYPEDEF_(0x8009301BL) -#define OSS_TRACE_FILE_ALREADY_OPEN _HRESULT_TYPEDEF_(0x8009301CL) -#define OSS_TABLE_MISMATCH _HRESULT_TYPEDEF_(0x8009301DL) -#define OSS_TYPE_NOT_SUPPORTED _HRESULT_TYPEDEF_(0x8009301EL) -#define OSS_REAL_DLL_NOT_LINKED _HRESULT_TYPEDEF_(0x8009301FL) -#define OSS_REAL_CODE_NOT_LINKED _HRESULT_TYPEDEF_(0x80093020L) -#define OSS_OUT_OF_RANGE _HRESULT_TYPEDEF_(0x80093021L) -#define OSS_COPIER_DLL_NOT_LINKED _HRESULT_TYPEDEF_(0x80093022L) -#define OSS_CONSTRAINT_DLL_NOT_LINKED _HRESULT_TYPEDEF_(0x80093023L) -#define OSS_COMPARATOR_DLL_NOT_LINKED _HRESULT_TYPEDEF_(0x80093024L) -#define OSS_COMPARATOR_CODE_NOT_LINKED _HRESULT_TYPEDEF_(0x80093025L) -#define OSS_MEM_MGR_DLL_NOT_LINKED _HRESULT_TYPEDEF_(0x80093026L) -#define OSS_PDV_DLL_NOT_LINKED _HRESULT_TYPEDEF_(0x80093027L) -#define OSS_PDV_CODE_NOT_LINKED _HRESULT_TYPEDEF_(0x80093028L) -#define OSS_API_DLL_NOT_LINKED _HRESULT_TYPEDEF_(0x80093029L) -#define OSS_BERDER_DLL_NOT_LINKED _HRESULT_TYPEDEF_(0x8009302AL) -#define OSS_PER_DLL_NOT_LINKED _HRESULT_TYPEDEF_(0x8009302BL) -#define OSS_OPEN_TYPE_ERROR _HRESULT_TYPEDEF_(0x8009302CL) -#define OSS_MUTEX_NOT_CREATED _HRESULT_TYPEDEF_(0x8009302DL) -#define OSS_CANT_CLOSE_TRACE_FILE _HRESULT_TYPEDEF_(0x8009302EL) -#define CRYPT_E_ASN1_ERROR _HRESULT_TYPEDEF_(0x80093100L) -#define CRYPT_E_ASN1_INTERNAL _HRESULT_TYPEDEF_(0x80093101L) -#define CRYPT_E_ASN1_EOD _HRESULT_TYPEDEF_(0x80093102L) -#define CRYPT_E_ASN1_CORRUPT _HRESULT_TYPEDEF_(0x80093103L) -#define CRYPT_E_ASN1_LARGE _HRESULT_TYPEDEF_(0x80093104L) -#define CRYPT_E_ASN1_CONSTRAINT _HRESULT_TYPEDEF_(0x80093105L) -#define CRYPT_E_ASN1_MEMORY _HRESULT_TYPEDEF_(0x80093106L) -#define CRYPT_E_ASN1_OVERFLOW _HRESULT_TYPEDEF_(0x80093107L) -#define CRYPT_E_ASN1_BADPDU _HRESULT_TYPEDEF_(0x80093108L) -#define CRYPT_E_ASN1_BADARGS _HRESULT_TYPEDEF_(0x80093109L) -#define CRYPT_E_ASN1_BADREAL _HRESULT_TYPEDEF_(0x8009310AL) -#define CRYPT_E_ASN1_BADTAG _HRESULT_TYPEDEF_(0x8009310BL) -#define CRYPT_E_ASN1_CHOICE _HRESULT_TYPEDEF_(0x8009310CL) -#define CRYPT_E_ASN1_RULE _HRESULT_TYPEDEF_(0x8009310DL) -#define CRYPT_E_ASN1_UTF8 _HRESULT_TYPEDEF_(0x8009310EL) -#define CRYPT_E_ASN1_PDU_TYPE _HRESULT_TYPEDEF_(0x80093133L) -#define CRYPT_E_ASN1_NYI _HRESULT_TYPEDEF_(0x80093134L) -#define CRYPT_E_ASN1_EXTENDED _HRESULT_TYPEDEF_(0x80093201L) -#define CRYPT_E_ASN1_NOEOD _HRESULT_TYPEDEF_(0x80093202L) -#define CERTSRV_E_BAD_REQUESTSUBJECT _HRESULT_TYPEDEF_(0x80094001L) -#define CERTSRV_E_NO_REQUEST _HRESULT_TYPEDEF_(0x80094002L) -#define CERTSRV_E_BAD_REQUESTSTATUS _HRESULT_TYPEDEF_(0x80094003L) -#define CERTSRV_E_PROPERTY_EMPTY _HRESULT_TYPEDEF_(0x80094004L) -#define CERTSRV_E_INVALID_CA_CERTIFICATE _HRESULT_TYPEDEF_(0x80094005L) -#define CERTSRV_E_SERVER_SUSPENDED _HRESULT_TYPEDEF_(0x80094006L) -#define CERTSRV_E_ENCODING_LENGTH _HRESULT_TYPEDEF_(0x80094007L) -#define CERTSRV_E_ROLECONFLICT _HRESULT_TYPEDEF_(0x80094008L) -#define CERTSRV_E_RESTRICTEDOFFICER _HRESULT_TYPEDEF_(0x80094009L) -#define CERTSRV_E_KEY_ARCHIVAL_NOT_CONFIGURED _HRESULT_TYPEDEF_(0x8009400AL) -#define CERTSRV_E_NO_VALID_KRA _HRESULT_TYPEDEF_(0x8009400BL) -#define CERTSRV_E_BAD_REQUEST_KEY_ARCHIVAL _HRESULT_TYPEDEF_(0x8009400CL) -#define CERTSRV_E_NO_CAADMIN_DEFINED _HRESULT_TYPEDEF_(0x8009400DL) -#define CERTSRV_E_BAD_RENEWAL_CERT_ATTRIBUTE _HRESULT_TYPEDEF_(0x8009400EL) -#define CERTSRV_E_NO_DB_SESSIONS _HRESULT_TYPEDEF_(0x8009400FL) -#define CERTSRV_E_ALIGNMENT_FAULT _HRESULT_TYPEDEF_(0x80094010L) -#define CERTSRV_E_ENROLL_DENIED _HRESULT_TYPEDEF_(0x80094011L) -#define CERTSRV_E_TEMPLATE_DENIED _HRESULT_TYPEDEF_(0x80094012L) -#define CERTSRV_E_DOWNLEVEL_DC_SSL_OR_UPGRADE _HRESULT_TYPEDEF_(0x80094013L) -#define CERTSRV_E_UNSUPPORTED_CERT_TYPE _HRESULT_TYPEDEF_(0x80094800L) -#define CERTSRV_E_NO_CERT_TYPE _HRESULT_TYPEDEF_(0x80094801L) -#define CERTSRV_E_TEMPLATE_CONFLICT _HRESULT_TYPEDEF_(0x80094802L) -#define CERTSRV_E_SUBJECT_ALT_NAME_REQUIRED _HRESULT_TYPEDEF_(0x80094803L) -#define CERTSRV_E_ARCHIVED_KEY_REQUIRED _HRESULT_TYPEDEF_(0x80094804L) -#define CERTSRV_E_SMIME_REQUIRED _HRESULT_TYPEDEF_(0x80094805L) -#define CERTSRV_E_BAD_RENEWAL_SUBJECT _HRESULT_TYPEDEF_(0x80094806L) -#define CERTSRV_E_BAD_TEMPLATE_VERSION _HRESULT_TYPEDEF_(0x80094807L) -#define CERTSRV_E_TEMPLATE_POLICY_REQUIRED _HRESULT_TYPEDEF_(0x80094808L) -#define CERTSRV_E_SIGNATURE_POLICY_REQUIRED _HRESULT_TYPEDEF_(0x80094809L) -#define CERTSRV_E_SIGNATURE_COUNT _HRESULT_TYPEDEF_(0x8009480AL) -#define CERTSRV_E_SIGNATURE_REJECTED _HRESULT_TYPEDEF_(0x8009480BL) -#define CERTSRV_E_ISSUANCE_POLICY_REQUIRED _HRESULT_TYPEDEF_(0x8009480CL) -#define CERTSRV_E_SUBJECT_UPN_REQUIRED _HRESULT_TYPEDEF_(0x8009480DL) -#define CERTSRV_E_SUBJECT_DIRECTORY_GUID_REQUIRED _HRESULT_TYPEDEF_(0x8009480EL) -#define CERTSRV_E_SUBJECT_DNS_REQUIRED _HRESULT_TYPEDEF_(0x8009480FL) -#define CERTSRV_E_ARCHIVED_KEY_UNEXPECTED _HRESULT_TYPEDEF_(0x80094810L) -#define CERTSRV_E_KEY_LENGTH _HRESULT_TYPEDEF_(0x80094811L) -#define CERTSRV_E_SUBJECT_EMAIL_REQUIRED _HRESULT_TYPEDEF_(0x80094812L) -#define CERTSRV_E_UNKNOWN_CERT_TYPE _HRESULT_TYPEDEF_(0x80094813L) -#define CERTSRV_E_CERT_TYPE_OVERLAP _HRESULT_TYPEDEF_(0x80094814L) -#define XENROLL_E_KEY_NOT_EXPORTABLE _HRESULT_TYPEDEF_(0x80095000L) -#define XENROLL_E_CANNOT_ADD_ROOT_CERT _HRESULT_TYPEDEF_(0x80095001L) -#define XENROLL_E_RESPONSE_KA_HASH_NOT_FOUND _HRESULT_TYPEDEF_(0x80095002L) -#define XENROLL_E_RESPONSE_UNEXPECTED_KA_HASH _HRESULT_TYPEDEF_(0x80095003L) -#define XENROLL_E_RESPONSE_KA_HASH_MISMATCH _HRESULT_TYPEDEF_(0x80095004L) -#define XENROLL_E_KEYSPEC_SMIME_MISMATCH _HRESULT_TYPEDEF_(0x80095005L) -#define TRUST_E_SYSTEM_ERROR _HRESULT_TYPEDEF_(0x80096001L) -#define TRUST_E_NO_SIGNER_CERT _HRESULT_TYPEDEF_(0x80096002L) -#define TRUST_E_COUNTER_SIGNER _HRESULT_TYPEDEF_(0x80096003L) -#define TRUST_E_CERT_SIGNATURE _HRESULT_TYPEDEF_(0x80096004L) -#define TRUST_E_TIME_STAMP _HRESULT_TYPEDEF_(0x80096005L) -#define TRUST_E_BAD_DIGEST _HRESULT_TYPEDEF_(0x80096010L) -#define TRUST_E_BASIC_CONSTRAINTS _HRESULT_TYPEDEF_(0x80096019L) -#define TRUST_E_FINANCIAL_CRITERIA _HRESULT_TYPEDEF_(0x8009601EL) -#define MSSIPOTF_E_OUTOFMEMRANGE _HRESULT_TYPEDEF_(0x80097001L) -#define MSSIPOTF_E_CANTGETOBJECT _HRESULT_TYPEDEF_(0x80097002L) -#define MSSIPOTF_E_NOHEADTABLE _HRESULT_TYPEDEF_(0x80097003L) -#define MSSIPOTF_E_BAD_MAGICNUMBER _HRESULT_TYPEDEF_(0x80097004L) -#define MSSIPOTF_E_BAD_OFFSET_TABLE _HRESULT_TYPEDEF_(0x80097005L) -#define MSSIPOTF_E_TABLE_TAGORDER _HRESULT_TYPEDEF_(0x80097006L) -#define MSSIPOTF_E_TABLE_LONGWORD _HRESULT_TYPEDEF_(0x80097007L) -#define MSSIPOTF_E_BAD_FIRST_TABLE_PLACEMENT _HRESULT_TYPEDEF_(0x80097008L) -#define MSSIPOTF_E_TABLES_OVERLAP _HRESULT_TYPEDEF_(0x80097009L) -#define MSSIPOTF_E_TABLE_PADBYTES _HRESULT_TYPEDEF_(0x8009700AL) -#define MSSIPOTF_E_FILETOOSMALL _HRESULT_TYPEDEF_(0x8009700BL) -#define MSSIPOTF_E_TABLE_CHECKSUM _HRESULT_TYPEDEF_(0x8009700CL) -#define MSSIPOTF_E_FILE_CHECKSUM _HRESULT_TYPEDEF_(0x8009700DL) -#define MSSIPOTF_E_FAILED_POLICY _HRESULT_TYPEDEF_(0x80097010L) -#define MSSIPOTF_E_FAILED_HINTS_CHECK _HRESULT_TYPEDEF_(0x80097011L) -#define MSSIPOTF_E_NOT_OPENTYPE _HRESULT_TYPEDEF_(0x80097012L) -#define MSSIPOTF_E_FILE _HRESULT_TYPEDEF_(0x80097013L) -#define MSSIPOTF_E_CRYPT _HRESULT_TYPEDEF_(0x80097014L) -#define MSSIPOTF_E_BADVERSION _HRESULT_TYPEDEF_(0x80097015L) -#define MSSIPOTF_E_DSIG_STRUCTURE _HRESULT_TYPEDEF_(0x80097016L) -#define MSSIPOTF_E_PCONST_CHECK _HRESULT_TYPEDEF_(0x80097017L) -#define MSSIPOTF_E_STRUCTURE _HRESULT_TYPEDEF_(0x80097018L) -#define NTE_OP_OK 0 -#define TRUST_E_PROVIDER_UNKNOWN _HRESULT_TYPEDEF_(0x800B0001L) -#define TRUST_E_ACTION_UNKNOWN _HRESULT_TYPEDEF_(0x800B0002L) -#define TRUST_E_SUBJECT_FORM_UNKNOWN _HRESULT_TYPEDEF_(0x800B0003L) -#define TRUST_E_SUBJECT_NOT_TRUSTED _HRESULT_TYPEDEF_(0x800B0004L) -#define DIGSIG_E_ENCODE _HRESULT_TYPEDEF_(0x800B0005L) -#define DIGSIG_E_DECODE _HRESULT_TYPEDEF_(0x800B0006L) -#define DIGSIG_E_EXTENSIBILITY _HRESULT_TYPEDEF_(0x800B0007L) -#define DIGSIG_E_CRYPTO _HRESULT_TYPEDEF_(0x800B0008L) -#define PERSIST_E_SIZEDEFINITE _HRESULT_TYPEDEF_(0x800B0009L) -#define PERSIST_E_SIZEINDEFINITE _HRESULT_TYPEDEF_(0x800B000AL) -#define PERSIST_E_NOTSELFSIZING _HRESULT_TYPEDEF_(0x800B000BL) -#define TRUST_E_NOSIGNATURE _HRESULT_TYPEDEF_(0x800B0100L) -#define CERT_E_EXPIRED _HRESULT_TYPEDEF_(0x800B0101L) -#define CERT_E_VALIDITYPERIODNESTING _HRESULT_TYPEDEF_(0x800B0102L) -#define CERT_E_ROLE _HRESULT_TYPEDEF_(0x800B0103L) -#define CERT_E_PATHLENCONST _HRESULT_TYPEDEF_(0x800B0104L) -#define CERT_E_CRITICAL _HRESULT_TYPEDEF_(0x800B0105L) -#define CERT_E_PURPOSE _HRESULT_TYPEDEF_(0x800B0106L) -#define CERT_E_ISSUERCHAINING _HRESULT_TYPEDEF_(0x800B0107L) -#define CERT_E_MALFORMED _HRESULT_TYPEDEF_(0x800B0108L) -#define CERT_E_UNTRUSTEDROOT _HRESULT_TYPEDEF_(0x800B0109L) -#define CERT_E_CHAINING _HRESULT_TYPEDEF_(0x800B010AL) -#define TRUST_E_FAIL _HRESULT_TYPEDEF_(0x800B010BL) -#define CERT_E_REVOKED _HRESULT_TYPEDEF_(0x800B010CL) -#define CERT_E_UNTRUSTEDTESTROOT _HRESULT_TYPEDEF_(0x800B010DL) -#define CERT_E_REVOCATION_FAILURE _HRESULT_TYPEDEF_(0x800B010EL) -#define CERT_E_CN_NO_MATCH _HRESULT_TYPEDEF_(0x800B010FL) -#define CERT_E_WRONG_USAGE _HRESULT_TYPEDEF_(0x800B0110L) -#define TRUST_E_EXPLICIT_DISTRUST _HRESULT_TYPEDEF_(0x800B0111L) -#define CERT_E_UNTRUSTEDCA _HRESULT_TYPEDEF_(0x800B0112L) -#define CERT_E_INVALID_POLICY _HRESULT_TYPEDEF_(0x800B0113L) -#define CERT_E_INVALID_NAME _HRESULT_TYPEDEF_(0x800B0114L) -#define HRESULT_FROM_SETUPAPI(x) ((((x) & (APPLICATION_ERROR_MASK|ERROR_SEVERITY_ERROR))==(APPLICATION_ERROR_MASK|ERROR_SEVERITY_ERROR)) ? ((HRESULT) (((x) & 0x0000FFFF) | (FACILITY_SETUPAPI << 16) | 0x80000000)) : HRESULT_FROM_WIN32(x)) -#define SPAPI_E_EXPECTED_SECTION_NAME _HRESULT_TYPEDEF_(0x800F0000L) -#define SPAPI_E_BAD_SECTION_NAME_LINE _HRESULT_TYPEDEF_(0x800F0001L) -#define SPAPI_E_SECTION_NAME_TOO_LONG _HRESULT_TYPEDEF_(0x800F0002L) -#define SPAPI_E_GENERAL_SYNTAX _HRESULT_TYPEDEF_(0x800F0003L) -#define SPAPI_E_WRONG_INF_STYLE _HRESULT_TYPEDEF_(0x800F0100L) -#define SPAPI_E_SECTION_NOT_FOUND _HRESULT_TYPEDEF_(0x800F0101L) -#define SPAPI_E_LINE_NOT_FOUND _HRESULT_TYPEDEF_(0x800F0102L) -#define SPAPI_E_NO_BACKUP _HRESULT_TYPEDEF_(0x800F0103L) -#define SPAPI_E_NO_ASSOCIATED_CLASS _HRESULT_TYPEDEF_(0x800F0200L) -#define SPAPI_E_CLASS_MISMATCH _HRESULT_TYPEDEF_(0x800F0201L) -#define SPAPI_E_DUPLICATE_FOUND _HRESULT_TYPEDEF_(0x800F0202L) -#define SPAPI_E_NO_DRIVER_SELECTED _HRESULT_TYPEDEF_(0x800F0203L) -#define SPAPI_E_KEY_DOES_NOT_EXIST _HRESULT_TYPEDEF_(0x800F0204L) -#define SPAPI_E_INVALID_DEVINST_NAME _HRESULT_TYPEDEF_(0x800F0205L) -#define SPAPI_E_INVALID_CLASS _HRESULT_TYPEDEF_(0x800F0206L) -#define SPAPI_E_DEVINST_ALREADY_EXISTS _HRESULT_TYPEDEF_(0x800F0207L) -#define SPAPI_E_DEVINFO_NOT_REGISTERED _HRESULT_TYPEDEF_(0x800F0208L) -#define SPAPI_E_INVALID_REG_PROPERTY _HRESULT_TYPEDEF_(0x800F0209L) -#define SPAPI_E_NO_INF _HRESULT_TYPEDEF_(0x800F020AL) -#define SPAPI_E_NO_SUCH_DEVINST _HRESULT_TYPEDEF_(0x800F020BL) -#define SPAPI_E_CANT_LOAD_CLASS_ICON _HRESULT_TYPEDEF_(0x800F020CL) -#define SPAPI_E_INVALID_CLASS_INSTALLER _HRESULT_TYPEDEF_(0x800F020DL) -#define SPAPI_E_DI_DO_DEFAULT _HRESULT_TYPEDEF_(0x800F020EL) -#define SPAPI_E_DI_NOFILECOPY _HRESULT_TYPEDEF_(0x800F020FL) -#define SPAPI_E_INVALID_HWPROFILE _HRESULT_TYPEDEF_(0x800F0210L) -#define SPAPI_E_NO_DEVICE_SELECTED _HRESULT_TYPEDEF_(0x800F0211L) -#define SPAPI_E_DEVINFO_LIST_LOCKED _HRESULT_TYPEDEF_(0x800F0212L) -#define SPAPI_E_DEVINFO_DATA_LOCKED _HRESULT_TYPEDEF_(0x800F0213L) -#define SPAPI_E_DI_BAD_PATH _HRESULT_TYPEDEF_(0x800F0214L) -#define SPAPI_E_NO_CLASSINSTALL_PARAMS _HRESULT_TYPEDEF_(0x800F0215L) -#define SPAPI_E_FILEQUEUE_LOCKED _HRESULT_TYPEDEF_(0x800F0216L) -#define SPAPI_E_BAD_SERVICE_INSTALLSECT _HRESULT_TYPEDEF_(0x800F0217L) -#define SPAPI_E_NO_CLASS_DRIVER_LIST _HRESULT_TYPEDEF_(0x800F0218L) -#define SPAPI_E_NO_ASSOCIATED_SERVICE _HRESULT_TYPEDEF_(0x800F0219L) -#define SPAPI_E_NO_DEFAULT_DEVICE_INTERFACE _HRESULT_TYPEDEF_(0x800F021AL) -#define SPAPI_E_DEVICE_INTERFACE_ACTIVE _HRESULT_TYPEDEF_(0x800F021BL) -#define SPAPI_E_DEVICE_INTERFACE_REMOVED _HRESULT_TYPEDEF_(0x800F021CL) -#define SPAPI_E_BAD_INTERFACE_INSTALLSECT _HRESULT_TYPEDEF_(0x800F021DL) -#define SPAPI_E_NO_SUCH_INTERFACE_CLASS _HRESULT_TYPEDEF_(0x800F021EL) -#define SPAPI_E_INVALID_REFERENCE_STRING _HRESULT_TYPEDEF_(0x800F021FL) -#define SPAPI_E_INVALID_MACHINENAME _HRESULT_TYPEDEF_(0x800F0220L) -#define SPAPI_E_REMOTE_COMM_FAILURE _HRESULT_TYPEDEF_(0x800F0221L) -#define SPAPI_E_MACHINE_UNAVAILABLE _HRESULT_TYPEDEF_(0x800F0222L) -#define SPAPI_E_NO_CONFIGMGR_SERVICES _HRESULT_TYPEDEF_(0x800F0223L) -#define SPAPI_E_INVALID_PROPPAGE_PROVIDER _HRESULT_TYPEDEF_(0x800F0224L) -#define SPAPI_E_NO_SUCH_DEVICE_INTERFACE _HRESULT_TYPEDEF_(0x800F0225L) -#define SPAPI_E_DI_POSTPROCESSING_REQUIRED _HRESULT_TYPEDEF_(0x800F0226L) -#define SPAPI_E_INVALID_COINSTALLER _HRESULT_TYPEDEF_(0x800F0227L) -#define SPAPI_E_NO_COMPAT_DRIVERS _HRESULT_TYPEDEF_(0x800F0228L) -#define SPAPI_E_NO_DEVICE_ICON _HRESULT_TYPEDEF_(0x800F0229L) -#define SPAPI_E_INVALID_INF_LOGCONFIG _HRESULT_TYPEDEF_(0x800F022AL) -#define SPAPI_E_DI_DONT_INSTALL _HRESULT_TYPEDEF_(0x800F022BL) -#define SPAPI_E_INVALID_FILTER_DRIVER _HRESULT_TYPEDEF_(0x800F022CL) -#define SPAPI_E_NON_WINDOWS_NT_DRIVER _HRESULT_TYPEDEF_(0x800F022DL) -#define SPAPI_E_NON_WINDOWS_DRIVER _HRESULT_TYPEDEF_(0x800F022EL) -#define SPAPI_E_NO_CATALOG_FOR_OEM_INF _HRESULT_TYPEDEF_(0x800F022FL) -#define SPAPI_E_DEVINSTALL_QUEUE_NONNATIVE _HRESULT_TYPEDEF_(0x800F0230L) -#define SPAPI_E_NOT_DISABLEABLE _HRESULT_TYPEDEF_(0x800F0231L) -#define SPAPI_E_CANT_REMOVE_DEVINST _HRESULT_TYPEDEF_(0x800F0232L) -#define SPAPI_E_INVALID_TARGET _HRESULT_TYPEDEF_(0x800F0233L) -#define SPAPI_E_DRIVER_NONNATIVE _HRESULT_TYPEDEF_(0x800F0234L) -#define SPAPI_E_IN_WOW64 _HRESULT_TYPEDEF_(0x800F0235L) -#define SPAPI_E_SET_SYSTEM_RESTORE_POINT _HRESULT_TYPEDEF_(0x800F0236L) -#define SPAPI_E_INCORRECTLY_COPIED_INF _HRESULT_TYPEDEF_(0x800F0237L) -#define SPAPI_E_SCE_DISABLED _HRESULT_TYPEDEF_(0x800F0238L) -#define SPAPI_E_UNKNOWN_EXCEPTION _HRESULT_TYPEDEF_(0x800F0239L) -#define SPAPI_E_PNP_REGISTRY_ERROR _HRESULT_TYPEDEF_(0x800F023AL) -#define SPAPI_E_REMOTE_REQUEST_UNSUPPORTED _HRESULT_TYPEDEF_(0x800F023BL) -#define SPAPI_E_NOT_AN_INSTALLED_OEM_INF _HRESULT_TYPEDEF_(0x800F023CL) -#define SPAPI_E_INF_IN_USE_BY_DEVICES _HRESULT_TYPEDEF_(0x800F023DL) -#define SPAPI_E_DI_FUNCTION_OBSOLETE _HRESULT_TYPEDEF_(0x800F023EL) -#define SPAPI_E_NO_AUTHENTICODE_CATALOG _HRESULT_TYPEDEF_(0x800F023FL) -#define SPAPI_E_AUTHENTICODE_DISALLOWED _HRESULT_TYPEDEF_(0x800F0240L) -#define SPAPI_E_AUTHENTICODE_TRUSTED_PUBLISHER _HRESULT_TYPEDEF_(0x800F0241L) -#define SPAPI_E_AUTHENTICODE_TRUST_NOT_ESTABLISHED _HRESULT_TYPEDEF_(0x800F0242L) -#define SPAPI_E_AUTHENTICODE_PUBLISHER_NOT_TRUSTED _HRESULT_TYPEDEF_(0x800F0243L) -#define SPAPI_E_SIGNATURE_OSATTRIBUTE_MISMATCH _HRESULT_TYPEDEF_(0x800F0244L) -#define SPAPI_E_ONLY_VALIDATE_VIA_AUTHENTICODE _HRESULT_TYPEDEF_(0x800F0245L) -#define SPAPI_E_UNRECOVERABLE_STACK_OVERFLOW _HRESULT_TYPEDEF_(0x800F0300L) -#define SPAPI_E_ERROR_NOT_INSTALLED _HRESULT_TYPEDEF_(0x800F1000L) -#define SCARD_S_SUCCESS NO_ERROR -#define SCARD_F_INTERNAL_ERROR _HRESULT_TYPEDEF_(0x80100001L) -#define SCARD_E_CANCELLED _HRESULT_TYPEDEF_(0x80100002L) -#define SCARD_E_INVALID_HANDLE _HRESULT_TYPEDEF_(0x80100003L) -#define SCARD_E_INVALID_PARAMETER _HRESULT_TYPEDEF_(0x80100004L) -#define SCARD_E_INVALID_TARGET _HRESULT_TYPEDEF_(0x80100005L) -#define SCARD_E_NO_MEMORY _HRESULT_TYPEDEF_(0x80100006L) -#define SCARD_F_WAITED_TOO_LONG _HRESULT_TYPEDEF_(0x80100007L) -#define SCARD_E_INSUFFICIENT_BUFFER _HRESULT_TYPEDEF_(0x80100008L) -#define SCARD_E_UNKNOWN_READER _HRESULT_TYPEDEF_(0x80100009L) -#define SCARD_E_TIMEOUT _HRESULT_TYPEDEF_(0x8010000AL) -#define SCARD_E_SHARING_VIOLATION _HRESULT_TYPEDEF_(0x8010000BL) -#define SCARD_E_NO_SMARTCARD _HRESULT_TYPEDEF_(0x8010000CL) -#define SCARD_E_UNKNOWN_CARD _HRESULT_TYPEDEF_(0x8010000DL) -#define SCARD_E_CANT_DISPOSE _HRESULT_TYPEDEF_(0x8010000EL) -#define SCARD_E_PROTO_MISMATCH _HRESULT_TYPEDEF_(0x8010000FL) -#define SCARD_E_NOT_READY _HRESULT_TYPEDEF_(0x80100010L) -#define SCARD_E_INVALID_VALUE _HRESULT_TYPEDEF_(0x80100011L) -#define SCARD_E_SYSTEM_CANCELLED _HRESULT_TYPEDEF_(0x80100012L) -#define SCARD_F_COMM_ERROR _HRESULT_TYPEDEF_(0x80100013L) -#define SCARD_F_UNKNOWN_ERROR _HRESULT_TYPEDEF_(0x80100014L) -#define SCARD_E_INVALID_ATR _HRESULT_TYPEDEF_(0x80100015L) -#define SCARD_E_NOT_TRANSACTED _HRESULT_TYPEDEF_(0x80100016L) -#define SCARD_E_READER_UNAVAILABLE _HRESULT_TYPEDEF_(0x80100017L) -#define SCARD_P_SHUTDOWN _HRESULT_TYPEDEF_(0x80100018L) -#define SCARD_E_PCI_TOO_SMALL _HRESULT_TYPEDEF_(0x80100019L) -#define SCARD_E_READER_UNSUPPORTED _HRESULT_TYPEDEF_(0x8010001AL) -#define SCARD_E_DUPLICATE_READER _HRESULT_TYPEDEF_(0x8010001BL) -#define SCARD_E_CARD_UNSUPPORTED _HRESULT_TYPEDEF_(0x8010001CL) -#define SCARD_E_NO_SERVICE _HRESULT_TYPEDEF_(0x8010001DL) -#define SCARD_E_SERVICE_STOPPED _HRESULT_TYPEDEF_(0x8010001EL) -#define SCARD_E_UNEXPECTED _HRESULT_TYPEDEF_(0x8010001FL) -#define SCARD_E_ICC_INSTALLATION _HRESULT_TYPEDEF_(0x80100020L) -#define SCARD_E_ICC_CREATEORDER _HRESULT_TYPEDEF_(0x80100021L) -#define SCARD_E_UNSUPPORTED_FEATURE _HRESULT_TYPEDEF_(0x80100022L) -#define SCARD_E_DIR_NOT_FOUND _HRESULT_TYPEDEF_(0x80100023L) -#define SCARD_E_FILE_NOT_FOUND _HRESULT_TYPEDEF_(0x80100024L) -#define SCARD_E_NO_DIR _HRESULT_TYPEDEF_(0x80100025L) -#define SCARD_E_NO_FILE _HRESULT_TYPEDEF_(0x80100026L) -#define SCARD_E_NO_ACCESS _HRESULT_TYPEDEF_(0x80100027L) -#define SCARD_E_WRITE_TOO_MANY _HRESULT_TYPEDEF_(0x80100028L) -#define SCARD_E_BAD_SEEK _HRESULT_TYPEDEF_(0x80100029L) -#define SCARD_E_INVALID_CHV _HRESULT_TYPEDEF_(0x8010002AL) -#define SCARD_E_UNKNOWN_RES_MNG _HRESULT_TYPEDEF_(0x8010002BL) -#define SCARD_E_NO_SUCH_CERTIFICATE _HRESULT_TYPEDEF_(0x8010002CL) -#define SCARD_E_CERTIFICATE_UNAVAILABLE _HRESULT_TYPEDEF_(0x8010002DL) -#define SCARD_E_NO_READERS_AVAILABLE _HRESULT_TYPEDEF_(0x8010002EL) -#define SCARD_E_COMM_DATA_LOST _HRESULT_TYPEDEF_(0x8010002FL) -#define SCARD_E_NO_KEY_CONTAINER _HRESULT_TYPEDEF_(0x80100030L) -#define SCARD_E_SERVER_TOO_BUSY _HRESULT_TYPEDEF_(0x80100031L) -#define SCARD_W_UNSUPPORTED_CARD _HRESULT_TYPEDEF_(0x80100065L) -#define SCARD_W_UNRESPONSIVE_CARD _HRESULT_TYPEDEF_(0x80100066L) -#define SCARD_W_UNPOWERED_CARD _HRESULT_TYPEDEF_(0x80100067L) -#define SCARD_W_RESET_CARD _HRESULT_TYPEDEF_(0x80100068L) -#define SCARD_W_REMOVED_CARD _HRESULT_TYPEDEF_(0x80100069L) -#define SCARD_W_SECURITY_VIOLATION _HRESULT_TYPEDEF_(0x8010006AL) -#define SCARD_W_WRONG_CHV _HRESULT_TYPEDEF_(0x8010006BL) -#define SCARD_W_CHV_BLOCKED _HRESULT_TYPEDEF_(0x8010006CL) -#define SCARD_W_EOF _HRESULT_TYPEDEF_(0x8010006DL) -#define SCARD_W_CANCELLED_BY_USER _HRESULT_TYPEDEF_(0x8010006EL) -#define SCARD_W_CARD_NOT_AUTHENTICATED _HRESULT_TYPEDEF_(0x8010006FL) -#define COMADMIN_E_OBJECTERRORS _HRESULT_TYPEDEF_(0x80110401L) -#define COMADMIN_E_OBJECTINVALID _HRESULT_TYPEDEF_(0x80110402L) -#define COMADMIN_E_KEYMISSING _HRESULT_TYPEDEF_(0x80110403L) -#define COMADMIN_E_ALREADYINSTALLED _HRESULT_TYPEDEF_(0x80110404L) -#define COMADMIN_E_APP_FILE_WRITEFAIL _HRESULT_TYPEDEF_(0x80110407L) -#define COMADMIN_E_APP_FILE_READFAIL _HRESULT_TYPEDEF_(0x80110408L) -#define COMADMIN_E_APP_FILE_VERSION _HRESULT_TYPEDEF_(0x80110409L) -#define COMADMIN_E_BADPATH _HRESULT_TYPEDEF_(0x8011040AL) -#define COMADMIN_E_APPLICATIONEXISTS _HRESULT_TYPEDEF_(0x8011040BL) -#define COMADMIN_E_ROLEEXISTS _HRESULT_TYPEDEF_(0x8011040CL) -#define COMADMIN_E_CANTCOPYFILE _HRESULT_TYPEDEF_(0x8011040DL) -#define COMADMIN_E_NOUSER _HRESULT_TYPEDEF_(0x8011040FL) -#define COMADMIN_E_INVALIDUSERIDS _HRESULT_TYPEDEF_(0x80110410L) -#define COMADMIN_E_NOREGISTRYCLSID _HRESULT_TYPEDEF_(0x80110411L) -#define COMADMIN_E_BADREGISTRYPROGID _HRESULT_TYPEDEF_(0x80110412L) -#define COMADMIN_E_AUTHENTICATIONLEVEL _HRESULT_TYPEDEF_(0x80110413L) -#define COMADMIN_E_USERPASSWDNOTVALID _HRESULT_TYPEDEF_(0x80110414L) -#define COMADMIN_E_CLSIDORIIDMISMATCH _HRESULT_TYPEDEF_(0x80110418L) -#define COMADMIN_E_REMOTEINTERFACE _HRESULT_TYPEDEF_(0x80110419L) -#define COMADMIN_E_DLLREGISTERSERVER _HRESULT_TYPEDEF_(0x8011041AL) -#define COMADMIN_E_NOSERVERSHARE _HRESULT_TYPEDEF_(0x8011041BL) -#define COMADMIN_E_DLLLOADFAILED _HRESULT_TYPEDEF_(0x8011041DL) -#define COMADMIN_E_BADREGISTRYLIBID _HRESULT_TYPEDEF_(0x8011041EL) -#define COMADMIN_E_APPDIRNOTFOUND _HRESULT_TYPEDEF_(0x8011041FL) -#define COMADMIN_E_REGISTRARFAILED _HRESULT_TYPEDEF_(0x80110423L) -#define COMADMIN_E_COMPFILE_DOESNOTEXIST _HRESULT_TYPEDEF_(0x80110424L) -#define COMADMIN_E_COMPFILE_LOADDLLFAIL _HRESULT_TYPEDEF_(0x80110425L) -#define COMADMIN_E_COMPFILE_GETCLASSOBJ _HRESULT_TYPEDEF_(0x80110426L) -#define COMADMIN_E_COMPFILE_CLASSNOTAVAIL _HRESULT_TYPEDEF_(0x80110427L) -#define COMADMIN_E_COMPFILE_BADTLB _HRESULT_TYPEDEF_(0x80110428L) -#define COMADMIN_E_COMPFILE_NOTINSTALLABLE _HRESULT_TYPEDEF_(0x80110429L) -#define COMADMIN_E_NOTCHANGEABLE _HRESULT_TYPEDEF_(0x8011042AL) -#define COMADMIN_E_NOTDELETEABLE _HRESULT_TYPEDEF_(0x8011042BL) -#define COMADMIN_E_SESSION _HRESULT_TYPEDEF_(0x8011042CL) -#define COMADMIN_E_COMP_MOVE_LOCKED _HRESULT_TYPEDEF_(0x8011042DL) -#define COMADMIN_E_COMP_MOVE_BAD_DEST _HRESULT_TYPEDEF_(0x8011042EL) -#define COMADMIN_E_REGISTERTLB _HRESULT_TYPEDEF_(0x80110430L) -#define COMADMIN_E_SYSTEMAPP _HRESULT_TYPEDEF_(0x80110433L) -#define COMADMIN_E_COMPFILE_NOREGISTRAR _HRESULT_TYPEDEF_(0x80110434L) -#define COMADMIN_E_COREQCOMPINSTALLED _HRESULT_TYPEDEF_(0x80110435L) -#define COMADMIN_E_SERVICENOTINSTALLED _HRESULT_TYPEDEF_(0x80110436L) -#define COMADMIN_E_PROPERTYSAVEFAILED _HRESULT_TYPEDEF_(0x80110437L) -#define COMADMIN_E_OBJECTEXISTS _HRESULT_TYPEDEF_(0x80110438L) -#define COMADMIN_E_COMPONENTEXISTS _HRESULT_TYPEDEF_(0x80110439L) -#define COMADMIN_E_REGFILE_CORRUPT _HRESULT_TYPEDEF_(0x8011043BL) -#define COMADMIN_E_PROPERTY_OVERFLOW _HRESULT_TYPEDEF_(0x8011043CL) -#define COMADMIN_E_NOTINREGISTRY _HRESULT_TYPEDEF_(0x8011043EL) -#define COMADMIN_E_OBJECTNOTPOOLABLE _HRESULT_TYPEDEF_(0x8011043FL) -#define COMADMIN_E_APPLID_MATCHES_CLSID _HRESULT_TYPEDEF_(0x80110446L) -#define COMADMIN_E_ROLE_DOES_NOT_EXIST _HRESULT_TYPEDEF_(0x80110447L) -#define COMADMIN_E_START_APP_NEEDS_COMPONENTS _HRESULT_TYPEDEF_(0x80110448L) -#define COMADMIN_E_REQUIRES_DIFFERENT_PLATFORM _HRESULT_TYPEDEF_(0x80110449L) -#define COMADMIN_E_CAN_NOT_EXPORT_APP_PROXY _HRESULT_TYPEDEF_(0x8011044AL) -#define COMADMIN_E_CAN_NOT_START_APP _HRESULT_TYPEDEF_(0x8011044BL) -#define COMADMIN_E_CAN_NOT_EXPORT_SYS_APP _HRESULT_TYPEDEF_(0x8011044CL) -#define COMADMIN_E_CANT_SUBSCRIBE_TO_COMPONENT _HRESULT_TYPEDEF_(0x8011044DL) -#define COMADMIN_E_EVENTCLASS_CANT_BE_SUBSCRIBER _HRESULT_TYPEDEF_(0x8011044EL) -#define COMADMIN_E_LIB_APP_PROXY_INCOMPATIBLE _HRESULT_TYPEDEF_(0x8011044FL) -#define COMADMIN_E_BASE_PARTITION_ONLY _HRESULT_TYPEDEF_(0x80110450L) -#define COMADMIN_E_START_APP_DISABLED _HRESULT_TYPEDEF_(0x80110451L) -#define COMADMIN_E_CAT_DUPLICATE_PARTITION_NAME _HRESULT_TYPEDEF_(0x80110457L) -#define COMADMIN_E_CAT_INVALID_PARTITION_NAME _HRESULT_TYPEDEF_(0x80110458L) -#define COMADMIN_E_CAT_PARTITION_IN_USE _HRESULT_TYPEDEF_(0x80110459L) -#define COMADMIN_E_FILE_PARTITION_DUPLICATE_FILES _HRESULT_TYPEDEF_(0x8011045AL) -#define COMADMIN_E_CAT_IMPORTED_COMPONENTS_NOT_ALLOWED _HRESULT_TYPEDEF_(0x8011045BL) -#define COMADMIN_E_AMBIGUOUS_APPLICATION_NAME _HRESULT_TYPEDEF_(0x8011045CL) -#define COMADMIN_E_AMBIGUOUS_PARTITION_NAME _HRESULT_TYPEDEF_(0x8011045DL) -#define COMADMIN_E_REGDB_NOTINITIALIZED _HRESULT_TYPEDEF_(0x80110472L) -#define COMADMIN_E_REGDB_NOTOPEN _HRESULT_TYPEDEF_(0x80110473L) -#define COMADMIN_E_REGDB_SYSTEMERR _HRESULT_TYPEDEF_(0x80110474L) -#define COMADMIN_E_REGDB_ALREADYRUNNING _HRESULT_TYPEDEF_(0x80110475L) -#define COMADMIN_E_MIG_VERSIONNOTSUPPORTED _HRESULT_TYPEDEF_(0x80110480L) -#define COMADMIN_E_MIG_SCHEMANOTFOUND _HRESULT_TYPEDEF_(0x80110481L) -#define COMADMIN_E_CAT_BITNESSMISMATCH _HRESULT_TYPEDEF_(0x80110482L) -#define COMADMIN_E_CAT_UNACCEPTABLEBITNESS _HRESULT_TYPEDEF_(0x80110483L) -#define COMADMIN_E_CAT_WRONGAPPBITNESS _HRESULT_TYPEDEF_(0x80110484L) -#define COMADMIN_E_CAT_PAUSE_RESUME_NOT_SUPPORTED _HRESULT_TYPEDEF_(0x80110485L) -#define COMADMIN_E_CAT_SERVERFAULT _HRESULT_TYPEDEF_(0x80110486L) -#define COMQC_E_APPLICATION_NOT_QUEUED _HRESULT_TYPEDEF_(0x80110600L) -#define COMQC_E_NO_QUEUEABLE_INTERFACES _HRESULT_TYPEDEF_(0x80110601L) -#define COMQC_E_QUEUING_SERVICE_NOT_AVAILABLE _HRESULT_TYPEDEF_(0x80110602L) -#define COMQC_E_NO_IPERSISTSTREAM _HRESULT_TYPEDEF_(0x80110603L) -#define COMQC_E_BAD_MESSAGE _HRESULT_TYPEDEF_(0x80110604L) -#define COMQC_E_UNAUTHENTICATED _HRESULT_TYPEDEF_(0x80110605L) -#define COMQC_E_UNTRUSTED_ENQUEUER _HRESULT_TYPEDEF_(0x80110606L) -#define MSDTC_E_DUPLICATE_RESOURCE _HRESULT_TYPEDEF_(0x80110701L) -#define COMADMIN_E_OBJECT_PARENT_MISSING _HRESULT_TYPEDEF_(0x80110808L) -#define COMADMIN_E_OBJECT_DOES_NOT_EXIST _HRESULT_TYPEDEF_(0x80110809L) -#define COMADMIN_E_APP_NOT_RUNNING _HRESULT_TYPEDEF_(0x8011080AL) -#define COMADMIN_E_INVALID_PARTITION _HRESULT_TYPEDEF_(0x8011080BL) -#define COMADMIN_E_SVCAPP_NOT_POOLABLE_OR_RECYCLABLE _HRESULT_TYPEDEF_(0x8011080DL) -#define COMADMIN_E_USER_IN_SET _HRESULT_TYPEDEF_(0x8011080EL) -#define COMADMIN_E_CANTRECYCLELIBRARYAPPS _HRESULT_TYPEDEF_(0x8011080FL) -#define COMADMIN_E_CANTRECYCLESERVICEAPPS _HRESULT_TYPEDEF_(0x80110811L) -#define COMADMIN_E_PROCESSALREADYRECYCLED _HRESULT_TYPEDEF_(0x80110812L) -#define COMADMIN_E_PAUSEDPROCESSMAYNOTBERECYCLED _HRESULT_TYPEDEF_(0x80110813L) -#define COMADMIN_E_CANTMAKEINPROCSERVICE _HRESULT_TYPEDEF_(0x80110814L) -#define COMADMIN_E_PROGIDINUSEBYCLSID _HRESULT_TYPEDEF_(0x80110815L) -#define COMADMIN_E_DEFAULT_PARTITION_NOT_IN_SET _HRESULT_TYPEDEF_(0x80110816L) -#define COMADMIN_E_RECYCLEDPROCESSMAYNOTBEPAUSED _HRESULT_TYPEDEF_(0x80110817L) -#define COMADMIN_E_PARTITION_ACCESSDENIED _HRESULT_TYPEDEF_(0x80110818L) -#define COMADMIN_E_PARTITION_MSI_ONLY _HRESULT_TYPEDEF_(0x80110819L) -#define COMADMIN_E_LEGACYCOMPS_NOT_ALLOWED_IN_1_0_FORMAT _HRESULT_TYPEDEF_(0x8011081AL) -#define COMADMIN_E_LEGACYCOMPS_NOT_ALLOWED_IN_NONBASE_PARTITIONS _HRESULT_TYPEDEF_(0x8011081BL) -#define COMADMIN_E_COMP_MOVE_SOURCE _HRESULT_TYPEDEF_(0x8011081CL) -#define COMADMIN_E_COMP_MOVE_DEST _HRESULT_TYPEDEF_(0x8011081DL) -#define COMADMIN_E_COMP_MOVE_PRIVATE _HRESULT_TYPEDEF_(0x8011081EL) -#define COMADMIN_E_BASEPARTITION_REQUIRED_IN_SET _HRESULT_TYPEDEF_(0x8011081FL) -#define COMADMIN_E_CANNOT_ALIAS_EVENTCLASS _HRESULT_TYPEDEF_(0x80110820L) -#define COMADMIN_E_PRIVATE_ACCESSDENIED _HRESULT_TYPEDEF_(0x80110821L) -#define COMADMIN_E_SAFERINVALID _HRESULT_TYPEDEF_(0x80110822L) -#define COMADMIN_E_REGISTRY_ACCESSDENIED _HRESULT_TYPEDEF_(0x80110823L) -#define COMADMIN_E_PARTITIONS_DISABLED _HRESULT_TYPEDEF_(0x80110824L) -#endif /* _WINERROR_ */ diff --git a/05/tcc-final-old/win32/include/winapi/wingdi.h b/05/tcc-final-old/win32/include/winapi/wingdi.h deleted file mode 100644 index 63d3891..0000000 --- a/05/tcc-final-old/win32/include/winapi/wingdi.h +++ /dev/null @@ -1,4080 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _WINGDI_ -#define _WINGDI_ - -#define WINGDIAPI DECLSPEC_IMPORT -#define WINSPOOLAPI DECLSPEC_IMPORT - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef WINVER -#define WINVER 0x0502 -#endif - -#ifndef NOGDI -#ifndef NORASTEROPS -#define R2_BLACK 1 -#define R2_NOTMERGEPEN 2 -#define R2_MASKNOTPEN 3 -#define R2_NOTCOPYPEN 4 -#define R2_MASKPENNOT 5 -#define R2_NOT 6 -#define R2_XORPEN 7 -#define R2_NOTMASKPEN 8 -#define R2_MASKPEN 9 -#define R2_NOTXORPEN 10 -#define R2_NOP 11 -#define R2_MERGENOTPEN 12 -#define R2_COPYPEN 13 -#define R2_MERGEPENNOT 14 -#define R2_MERGEPEN 15 -#define R2_WHITE 16 -#define R2_LAST 16 - -#define SRCCOPY (DWORD)0x00CC0020 -#define SRCPAINT (DWORD)0x00EE0086 -#define SRCAND (DWORD)0x008800C6 -#define SRCINVERT (DWORD)0x00660046 -#define SRCERASE (DWORD)0x00440328 -#define NOTSRCCOPY (DWORD)0x00330008 -#define NOTSRCERASE (DWORD)0x001100A6 -#define MERGECOPY (DWORD)0x00C000CA -#define MERGEPAINT (DWORD)0x00BB0226 -#define PATCOPY (DWORD)0x00F00021 -#define PATPAINT (DWORD)0x00FB0A09 -#define PATINVERT (DWORD)0x005A0049 -#define DSTINVERT (DWORD)0x00550009 -#define BLACKNESS (DWORD)0x00000042 -#define WHITENESS (DWORD)0x00FF0062 -#define NOMIRRORBITMAP (DWORD)0x80000000 -#define CAPTUREBLT (DWORD)0x40000000 -#define MAKEROP4(fore,back) (DWORD)((((back) << 8) & 0xFF000000) | (fore)) -#endif - -#define GDI_ERROR (0xFFFFFFFFL) -#define HGDI_ERROR (LongToHandle(0xFFFFFFFFL)) - -#define ERROR 0 -#define NULLREGION 1 -#define SIMPLEREGION 2 -#define COMPLEXREGION 3 -#define RGN_ERROR ERROR - -#define RGN_AND 1 -#define RGN_OR 2 -#define RGN_XOR 3 -#define RGN_DIFF 4 -#define RGN_COPY 5 -#define RGN_MIN RGN_AND -#define RGN_MAX RGN_COPY - -#define BLACKONWHITE 1 -#define WHITEONBLACK 2 -#define COLORONCOLOR 3 -#define HALFTONE 4 -#define MAXSTRETCHBLTMODE 4 - -#define STRETCH_ANDSCANS BLACKONWHITE -#define STRETCH_ORSCANS WHITEONBLACK -#define STRETCH_DELETESCANS COLORONCOLOR -#define STRETCH_HALFTONE HALFTONE - -#define ALTERNATE 1 -#define WINDING 2 -#define POLYFILL_LAST 2 - -#define LAYOUT_RTL 0x00000001 -#define LAYOUT_BTT 0x00000002 -#define LAYOUT_VBH 0x00000004 -#define LAYOUT_ORIENTATIONMASK (LAYOUT_RTL | LAYOUT_BTT | LAYOUT_VBH) -#define LAYOUT_BITMAPORIENTATIONPRESERVED 0x00000008 - -#define TA_NOUPDATECP 0 -#define TA_UPDATECP 1 - -#define TA_LEFT 0 -#define TA_RIGHT 2 -#define TA_CENTER 6 - -#define TA_TOP 0 -#define TA_BOTTOM 8 -#define TA_BASELINE 24 -#define TA_RTLREADING 256 -#define TA_MASK (TA_BASELINE+TA_CENTER+TA_UPDATECP+TA_RTLREADING) - -#define VTA_BASELINE TA_BASELINE -#define VTA_LEFT TA_BOTTOM -#define VTA_RIGHT TA_TOP -#define VTA_CENTER TA_CENTER -#define VTA_BOTTOM TA_RIGHT -#define VTA_TOP TA_LEFT - -#define ETO_OPAQUE 0x0002 -#define ETO_CLIPPED 0x0004 -#define ETO_GLYPH_INDEX 0x0010 -#define ETO_RTLREADING 0x0080 -#define ETO_NUMERICSLOCAL 0x0400 -#define ETO_NUMERICSLATIN 0x0800 -#define ETO_IGNORELANGUAGE 0x1000 -#define ETO_PDY 0x2000 - -#define ASPECT_FILTERING 0x0001 - -#define DCB_RESET 0x0001 -#define DCB_ACCUMULATE 0x0002 -#define DCB_DIRTY DCB_ACCUMULATE -#define DCB_SET (DCB_RESET | DCB_ACCUMULATE) -#define DCB_ENABLE 0x0004 -#define DCB_DISABLE 0x0008 - -#ifndef NOMETAFILE - -#define META_SETBKCOLOR 0x0201 -#define META_SETBKMODE 0x0102 -#define META_SETMAPMODE 0x0103 -#define META_SETROP2 0x0104 -#define META_SETRELABS 0x0105 -#define META_SETPOLYFILLMODE 0x0106 -#define META_SETSTRETCHBLTMODE 0x0107 -#define META_SETTEXTCHAREXTRA 0x0108 -#define META_SETTEXTCOLOR 0x0209 -#define META_SETTEXTJUSTIFICATION 0x020A -#define META_SETWINDOWORG 0x020B -#define META_SETWINDOWEXT 0x020C -#define META_SETVIEWPORTORG 0x020D -#define META_SETVIEWPORTEXT 0x020E -#define META_OFFSETWINDOWORG 0x020F -#define META_SCALEWINDOWEXT 0x0410 -#define META_OFFSETVIEWPORTORG 0x0211 -#define META_SCALEVIEWPORTEXT 0x0412 -#define META_LINETO 0x0213 -#define META_MOVETO 0x0214 -#define META_EXCLUDECLIPRECT 0x0415 -#define META_INTERSECTCLIPRECT 0x0416 -#define META_ARC 0x0817 -#define META_ELLIPSE 0x0418 -#define META_FLOODFILL 0x0419 -#define META_PIE 0x081A -#define META_RECTANGLE 0x041B -#define META_ROUNDRECT 0x061C -#define META_PATBLT 0x061D -#define META_SAVEDC 0x001E -#define META_SETPIXEL 0x041F -#define META_OFFSETCLIPRGN 0x0220 -#define META_TEXTOUT 0x0521 -#define META_BITBLT 0x0922 -#define META_STRETCHBLT 0x0B23 -#define META_POLYGON 0x0324 -#define META_POLYLINE 0x0325 -#define META_ESCAPE 0x0626 -#define META_RESTOREDC 0x0127 -#define META_FILLREGION 0x0228 -#define META_FRAMEREGION 0x0429 -#define META_INVERTREGION 0x012A -#define META_PAINTREGION 0x012B -#define META_SELECTCLIPREGION 0x012C -#define META_SELECTOBJECT 0x012D -#define META_SETTEXTALIGN 0x012E -#define META_CHORD 0x0830 -#define META_SETMAPPERFLAGS 0x0231 -#define META_EXTTEXTOUT 0x0a32 -#define META_SETDIBTODEV 0x0d33 -#define META_SELECTPALETTE 0x0234 -#define META_REALIZEPALETTE 0x0035 -#define META_ANIMATEPALETTE 0x0436 -#define META_SETPALENTRIES 0x0037 -#define META_POLYPOLYGON 0x0538 -#define META_RESIZEPALETTE 0x0139 -#define META_DIBBITBLT 0x0940 -#define META_DIBSTRETCHBLT 0x0b41 -#define META_DIBCREATEPATTERNBRUSH 0x0142 -#define META_STRETCHDIB 0x0f43 -#define META_EXTFLOODFILL 0x0548 -#define META_SETLAYOUT 0x0149 -#define META_DELETEOBJECT 0x01f0 -#define META_CREATEPALETTE 0x00f7 -#define META_CREATEPATTERNBRUSH 0x01F9 -#define META_CREATEPENINDIRECT 0x02FA -#define META_CREATEFONTINDIRECT 0x02FB -#define META_CREATEBRUSHINDIRECT 0x02FC -#define META_CREATEREGION 0x06FF - - typedef struct _DRAWPATRECT { - POINT ptPosition; - POINT ptSize; - WORD wStyle; - WORD wPattern; - } DRAWPATRECT,*PDRAWPATRECT; -#endif - -#define NEWFRAME 1 -#define ABORTDOC 2 -#define NEXTBAND 3 -#define SETCOLORTABLE 4 -#define GETCOLORTABLE 5 -#define FLUSHOUTPUT 6 -#define DRAFTMODE 7 -#define QUERYESCSUPPORT 8 -#define SETABORTPROC 9 -#define STARTDOC 10 -#define ENDDOC 11 -#define GETPHYSPAGESIZE 12 -#define GETPRINTINGOFFSET 13 -#define GETSCALINGFACTOR 14 -#define MFCOMMENT 15 -#define GETPENWIDTH 16 -#define SETCOPYCOUNT 17 -#define SELECTPAPERSOURCE 18 -#define DEVICEDATA 19 -#define PASSTHROUGH 19 -#define GETTECHNOLGY 20 -#define GETTECHNOLOGY 20 -#define SETLINECAP 21 -#define SETLINEJOIN 22 -#define SETMITERLIMIT 23 -#define BANDINFO 24 -#define DRAWPATTERNRECT 25 -#define GETVECTORPENSIZE 26 -#define GETVECTORBRUSHSIZE 27 -#define ENABLEDUPLEX 28 -#define GETSETPAPERBINS 29 -#define GETSETPRINTORIENT 30 -#define ENUMPAPERBINS 31 -#define SETDIBSCALING 32 -#define EPSPRINTING 33 -#define ENUMPAPERMETRICS 34 -#define GETSETPAPERMETRICS 35 -#define POSTSCRIPT_DATA 37 -#define POSTSCRIPT_IGNORE 38 -#define MOUSETRAILS 39 -#define GETDEVICEUNITS 42 - -#define GETEXTENDEDTEXTMETRICS 256 -#define GETEXTENTTABLE 257 -#define GETPAIRKERNTABLE 258 -#define GETTRACKKERNTABLE 259 -#define EXTTEXTOUT 512 -#define GETFACENAME 513 -#define DOWNLOADFACE 514 -#define ENABLERELATIVEWIDTHS 768 -#define ENABLEPAIRKERNING 769 -#define SETKERNTRACK 770 -#define SETALLJUSTVALUES 771 -#define SETCHARSET 772 - -#define STRETCHBLT 2048 -#define METAFILE_DRIVER 2049 -#define GETSETSCREENPARAMS 3072 -#define QUERYDIBSUPPORT 3073 -#define BEGIN_PATH 4096 -#define CLIP_TO_PATH 4097 -#define END_PATH 4098 -#define EXT_DEVICE_CAPS 4099 -#define RESTORE_CTM 4100 -#define SAVE_CTM 4101 -#define SET_ARC_DIRECTION 4102 -#define SET_BACKGROUND_COLOR 4103 -#define SET_POLY_MODE 4104 -#define SET_SCREEN_ANGLE 4105 -#define SET_SPREAD 4106 -#define TRANSFORM_CTM 4107 -#define SET_CLIP_BOX 4108 -#define SET_BOUNDS 4109 -#define SET_MIRROR_MODE 4110 -#define OPENCHANNEL 4110 -#define DOWNLOADHEADER 4111 -#define CLOSECHANNEL 4112 -#define POSTSCRIPT_PASSTHROUGH 4115 -#define ENCAPSULATED_POSTSCRIPT 4116 - -#define POSTSCRIPT_IDENTIFY 4117 -#define POSTSCRIPT_INJECTION 4118 - -#define CHECKJPEGFORMAT 4119 -#define CHECKPNGFORMAT 4120 - -#define GET_PS_FEATURESETTING 4121 - -#define SPCLPASSTHROUGH2 4568 - -#define PSIDENT_GDICENTRIC 0 -#define PSIDENT_PSCENTRIC 1 - - typedef struct _PSINJECTDATA { - DWORD DataBytes; - WORD InjectionPoint; - WORD PageNumber; - } PSINJECTDATA,*PPSINJECTDATA; - -#define PSINJECT_BEGINSTREAM 1 -#define PSINJECT_PSADOBE 2 -#define PSINJECT_PAGESATEND 3 -#define PSINJECT_PAGES 4 - -#define PSINJECT_DOCNEEDEDRES 5 -#define PSINJECT_DOCSUPPLIEDRES 6 -#define PSINJECT_PAGEORDER 7 -#define PSINJECT_ORIENTATION 8 -#define PSINJECT_BOUNDINGBOX 9 -#define PSINJECT_DOCUMENTPROCESSCOLORS 10 - -#define PSINJECT_COMMENTS 11 -#define PSINJECT_BEGINDEFAULTS 12 -#define PSINJECT_ENDDEFAULTS 13 -#define PSINJECT_BEGINPROLOG 14 -#define PSINJECT_ENDPROLOG 15 -#define PSINJECT_BEGINSETUP 16 -#define PSINJECT_ENDSETUP 17 -#define PSINJECT_TRAILER 18 -#define PSINJECT_EOF 19 -#define PSINJECT_ENDSTREAM 20 -#define PSINJECT_DOCUMENTPROCESSCOLORSATEND 21 - -#define PSINJECT_PAGENUMBER 100 -#define PSINJECT_BEGINPAGESETUP 101 -#define PSINJECT_ENDPAGESETUP 102 -#define PSINJECT_PAGETRAILER 103 -#define PSINJECT_PLATECOLOR 104 - -#define PSINJECT_SHOWPAGE 105 -#define PSINJECT_PAGEBBOX 106 -#define PSINJECT_ENDPAGECOMMENTS 107 - -#define PSINJECT_VMSAVE 200 -#define PSINJECT_VMRESTORE 201 - -#define FEATURESETTING_NUP 0 -#define FEATURESETTING_OUTPUT 1 -#define FEATURESETTING_PSLEVEL 2 -#define FEATURESETTING_CUSTPAPER 3 -#define FEATURESETTING_MIRROR 4 -#define FEATURESETTING_NEGATIVE 5 -#define FEATURESETTING_PROTOCOL 6 - -#define FEATURESETTING_PRIVATE_BEGIN 0x1000 -#define FEATURESETTING_PRIVATE_END 0x1FFF - - typedef struct _PSFEATURE_OUTPUT { - WINBOOL bPageIndependent; - WINBOOL bSetPageDevice; - } PSFEATURE_OUTPUT,*PPSFEATURE_OUTPUT; - - typedef struct _PSFEATURE_CUSTPAPER { - LONG lOrientation; - LONG lWidth; - LONG lHeight; - LONG lWidthOffset; - LONG lHeightOffset; - } PSFEATURE_CUSTPAPER,*PPSFEATURE_CUSTPAPER; - -#define PSPROTOCOL_ASCII 0 -#define PSPROTOCOL_BCP 1 -#define PSPROTOCOL_TBCP 2 -#define PSPROTOCOL_BINARY 3 - -#define QDI_SETDIBITS 1 -#define QDI_GETDIBITS 2 -#define QDI_DIBTOSCREEN 4 -#define QDI_STRETCHDIB 8 - -#define SP_NOTREPORTED 0x4000 -#define SP_ERROR (-1) -#define SP_APPABORT (-2) -#define SP_USERABORT (-3) -#define SP_OUTOFDISK (-4) -#define SP_OUTOFMEMORY (-5) - -#define PR_JOBSTATUS 0x0000 - -#define OBJ_PEN 1 -#define OBJ_BRUSH 2 -#define OBJ_DC 3 -#define OBJ_METADC 4 -#define OBJ_PAL 5 -#define OBJ_FONT 6 -#define OBJ_BITMAP 7 -#define OBJ_REGION 8 -#define OBJ_METAFILE 9 -#define OBJ_MEMDC 10 -#define OBJ_EXTPEN 11 -#define OBJ_ENHMETADC 12 -#define OBJ_ENHMETAFILE 13 -#define OBJ_COLORSPACE 14 - -#define MWT_IDENTITY 1 -#define MWT_LEFTMULTIPLY 2 -#define MWT_RIGHTMULTIPLY 3 - -#define MWT_MIN MWT_IDENTITY -#define MWT_MAX MWT_RIGHTMULTIPLY - -#define _XFORM_ - typedef struct tagXFORM { - FLOAT eM11; - FLOAT eM12; - FLOAT eM21; - FLOAT eM22; - FLOAT eDx; - FLOAT eDy; - } XFORM,*PXFORM,*LPXFORM; - - typedef struct tagBITMAP { - LONG bmType; - LONG bmWidth; - LONG bmHeight; - LONG bmWidthBytes; - WORD bmPlanes; - WORD bmBitsPixel; - LPVOID bmBits; - } BITMAP,*PBITMAP,*NPBITMAP,*LPBITMAP; - -#include - typedef struct tagRGBTRIPLE { - BYTE rgbtBlue; - BYTE rgbtGreen; - BYTE rgbtRed; - } RGBTRIPLE; -#include - - typedef struct tagRGBQUAD { - BYTE rgbBlue; - BYTE rgbGreen; - BYTE rgbRed; - BYTE rgbReserved; - } RGBQUAD; - typedef RGBQUAD *LPRGBQUAD; - -#define CS_ENABLE 0x00000001L -#define CS_DISABLE 0x00000002L -#define CS_DELETE_TRANSFORM 0x00000003L - -//!__TINYC__: #define LCS_SIGNATURE 'PSOC' -//!__TINYC__: #define LCS_sRGB 'sRGB' -//!__TINYC__: #define LCS_WINDOWS_COLOR_SPACE 'Win ' - - typedef LONG LCSCSTYPE; -#define LCS_CALIBRATED_RGB 0x00000000L - - typedef LONG LCSGAMUTMATCH; -#define LCS_GM_BUSINESS 0x00000001L -#define LCS_GM_GRAPHICS 0x00000002L -#define LCS_GM_IMAGES 0x00000004L -#define LCS_GM_ABS_COLORIMETRIC 0x00000008L - -#define CM_OUT_OF_GAMUT 255 -#define CM_IN_GAMUT 0 - -#define ICM_ADDPROFILE 1 -#define ICM_DELETEPROFILE 2 -#define ICM_QUERYPROFILE 3 -#define ICM_SETDEFAULTPROFILE 4 -#define ICM_REGISTERICMATCHER 5 -#define ICM_UNREGISTERICMATCHER 6 -#define ICM_QUERYMATCH 7 - -#define GetKValue(cmyk) ((BYTE)(cmyk)) -#define GetYValue(cmyk) ((BYTE)((cmyk)>> 8)) -#define GetMValue(cmyk) ((BYTE)((cmyk)>>16)) -#define GetCValue(cmyk) ((BYTE)((cmyk)>>24)) - -#define CMYK(c,m,y,k) ((COLORREF)((((BYTE)(k)|((WORD)((BYTE)(y))<<8))|(((DWORD)(BYTE)(m))<<16))|(((DWORD)(BYTE)(c))<<24))) - - typedef long FXPT16DOT16,*LPFXPT16DOT16; - typedef long FXPT2DOT30,*LPFXPT2DOT30; - - typedef struct tagCIEXYZ { - FXPT2DOT30 ciexyzX; - FXPT2DOT30 ciexyzY; - FXPT2DOT30 ciexyzZ; - } CIEXYZ; - typedef CIEXYZ *LPCIEXYZ; - - typedef struct tagICEXYZTRIPLE { - CIEXYZ ciexyzRed; - CIEXYZ ciexyzGreen; - CIEXYZ ciexyzBlue; - } CIEXYZTRIPLE; - - typedef CIEXYZTRIPLE *LPCIEXYZTRIPLE; - - typedef struct tagLOGCOLORSPACEA { - DWORD lcsSignature; - DWORD lcsVersion; - DWORD lcsSize; - LCSCSTYPE lcsCSType; - LCSGAMUTMATCH lcsIntent; - CIEXYZTRIPLE lcsEndpoints; - DWORD lcsGammaRed; - DWORD lcsGammaGreen; - DWORD lcsGammaBlue; - CHAR lcsFilename[MAX_PATH]; - } LOGCOLORSPACEA,*LPLOGCOLORSPACEA; - - typedef struct tagLOGCOLORSPACEW { - DWORD lcsSignature; - DWORD lcsVersion; - DWORD lcsSize; - LCSCSTYPE lcsCSType; - LCSGAMUTMATCH lcsIntent; - CIEXYZTRIPLE lcsEndpoints; - DWORD lcsGammaRed; - DWORD lcsGammaGreen; - DWORD lcsGammaBlue; - WCHAR lcsFilename[MAX_PATH]; - } LOGCOLORSPACEW,*LPLOGCOLORSPACEW; - -#ifdef UNICODE - typedef LOGCOLORSPACEW LOGCOLORSPACE; - typedef LPLOGCOLORSPACEW LPLOGCOLORSPACE; -#else - typedef LOGCOLORSPACEA LOGCOLORSPACE; - typedef LPLOGCOLORSPACEA LPLOGCOLORSPACE; -#endif - - typedef struct tagBITMAPCOREHEADER { - DWORD bcSize; - WORD bcWidth; - WORD bcHeight; - WORD bcPlanes; - WORD bcBitCount; - } BITMAPCOREHEADER,*LPBITMAPCOREHEADER,*PBITMAPCOREHEADER; - - typedef struct tagBITMAPINFOHEADER { - DWORD biSize; - LONG biWidth; - LONG biHeight; - WORD biPlanes; - WORD biBitCount; - DWORD biCompression; - DWORD biSizeImage; - LONG biXPelsPerMeter; - LONG biYPelsPerMeter; - DWORD biClrUsed; - DWORD biClrImportant; - } BITMAPINFOHEADER,*LPBITMAPINFOHEADER,*PBITMAPINFOHEADER; - - typedef struct { - DWORD bV4Size; - LONG bV4Width; - LONG bV4Height; - WORD bV4Planes; - WORD bV4BitCount; - DWORD bV4V4Compression; - DWORD bV4SizeImage; - LONG bV4XPelsPerMeter; - LONG bV4YPelsPerMeter; - DWORD bV4ClrUsed; - DWORD bV4ClrImportant; - DWORD bV4RedMask; - DWORD bV4GreenMask; - DWORD bV4BlueMask; - DWORD bV4AlphaMask; - DWORD bV4CSType; - CIEXYZTRIPLE bV4Endpoints; - DWORD bV4GammaRed; - DWORD bV4GammaGreen; - DWORD bV4GammaBlue; - } BITMAPV4HEADER,*LPBITMAPV4HEADER,*PBITMAPV4HEADER; - - typedef struct { - DWORD bV5Size; - LONG bV5Width; - LONG bV5Height; - WORD bV5Planes; - WORD bV5BitCount; - DWORD bV5Compression; - DWORD bV5SizeImage; - LONG bV5XPelsPerMeter; - LONG bV5YPelsPerMeter; - DWORD bV5ClrUsed; - DWORD bV5ClrImportant; - DWORD bV5RedMask; - DWORD bV5GreenMask; - DWORD bV5BlueMask; - DWORD bV5AlphaMask; - DWORD bV5CSType; - CIEXYZTRIPLE bV5Endpoints; - DWORD bV5GammaRed; - DWORD bV5GammaGreen; - DWORD bV5GammaBlue; - DWORD bV5Intent; - DWORD bV5ProfileData; - DWORD bV5ProfileSize; - DWORD bV5Reserved; - } BITMAPV5HEADER,*LPBITMAPV5HEADER,*PBITMAPV5HEADER; - -//!__TINYC__: #define PROFILE_LINKED 'LINK' -//!__TINYC__: #define PROFILE_EMBEDDED 'MBED' - -#define BI_RGB 0L -#define BI_RLE8 1L -#define BI_RLE4 2L -#define BI_BITFIELDS 3L -#define BI_JPEG 4L -#define BI_PNG 5L - - typedef struct tagBITMAPINFO { - BITMAPINFOHEADER bmiHeader; - RGBQUAD bmiColors[1]; - } BITMAPINFO,*LPBITMAPINFO,*PBITMAPINFO; - - typedef struct tagBITMAPCOREINFO { - BITMAPCOREHEADER bmciHeader; - RGBTRIPLE bmciColors[1]; - } BITMAPCOREINFO,*LPBITMAPCOREINFO,*PBITMAPCOREINFO; - -#include - typedef struct tagBITMAPFILEHEADER { - WORD bfType; - DWORD bfSize; - WORD bfReserved1; - WORD bfReserved2; - DWORD bfOffBits; - } BITMAPFILEHEADER,*LPBITMAPFILEHEADER,*PBITMAPFILEHEADER; -#include - -#define MAKEPOINTS(l) (*((POINTS *)&(l))) - -#ifndef NOFONTSIG - typedef struct tagFONTSIGNATURE { - DWORD fsUsb[4]; - DWORD fsCsb[2]; - } FONTSIGNATURE,*PFONTSIGNATURE,*LPFONTSIGNATURE; - - typedef struct tagCHARSETINFO { - UINT ciCharset; - UINT ciACP; - FONTSIGNATURE fs; - } CHARSETINFO,*PCHARSETINFO,*NPCHARSETINFO,*LPCHARSETINFO; - -#define TCI_SRCCHARSET 1 -#define TCI_SRCCODEPAGE 2 -#define TCI_SRCFONTSIG 3 -#define TCI_SRCLOCALE 0x1000 - - typedef struct tagLOCALESIGNATURE { - DWORD lsUsb[4]; - DWORD lsCsbDefault[2]; - DWORD lsCsbSupported[2]; - } LOCALESIGNATURE,*PLOCALESIGNATURE,*LPLOCALESIGNATURE; -#endif - - -#ifndef NOMETAFILE - typedef struct tagHANDLETABLE { - HGDIOBJ objectHandle[1]; - } HANDLETABLE,*PHANDLETABLE,*LPHANDLETABLE; - - typedef struct tagMETARECORD { - DWORD rdSize; - WORD rdFunction; - WORD rdParm[1]; - } METARECORD; - typedef struct tagMETARECORD UNALIGNED *PMETARECORD; - typedef struct tagMETARECORD UNALIGNED *LPMETARECORD; - - typedef struct tagMETAFILEPICT { - LONG mm; - LONG xExt; - LONG yExt; - HMETAFILE hMF; - } METAFILEPICT,*LPMETAFILEPICT; - -#include - typedef struct tagMETAHEADER { - WORD mtType; - WORD mtHeaderSize; - WORD mtVersion; - DWORD mtSize; - WORD mtNoObjects; - DWORD mtMaxRecord; - WORD mtNoParameters; - } METAHEADER; - typedef struct tagMETAHEADER UNALIGNED *PMETAHEADER; - typedef struct tagMETAHEADER UNALIGNED *LPMETAHEADER; - -#include - - typedef struct tagENHMETARECORD { - DWORD iType; - DWORD nSize; - DWORD dParm[1]; - } ENHMETARECORD,*PENHMETARECORD,*LPENHMETARECORD; - - typedef struct tagENHMETAHEADER { - DWORD iType; - DWORD nSize; - RECTL rclBounds; - RECTL rclFrame; - DWORD dSignature; - DWORD nVersion; - DWORD nBytes; - DWORD nRecords; - WORD nHandles; - WORD sReserved; - DWORD nDescription; - DWORD offDescription; - DWORD nPalEntries; - SIZEL szlDevice; - SIZEL szlMillimeters; - DWORD cbPixelFormat; - DWORD offPixelFormat; - DWORD bOpenGL; - SIZEL szlMicrometers; - } ENHMETAHEADER,*PENHMETAHEADER,*LPENHMETAHEADER; -#endif - -#ifndef NOTEXTMETRIC -#define TMPF_FIXED_PITCH 0x01 -#define TMPF_VECTOR 0x02 -#define TMPF_DEVICE 0x08 -#define TMPF_TRUETYPE 0x04 - -#ifdef UNICODE - typedef WCHAR BCHAR; -#else - typedef BYTE BCHAR; -#endif - -#ifndef _TEXTMETRIC_DEFINED -#define _TEXTMETRIC_DEFINED - typedef struct tagTEXTMETRICA { - LONG tmHeight; - LONG tmAscent; - LONG tmDescent; - LONG tmInternalLeading; - LONG tmExternalLeading; - LONG tmAveCharWidth; - LONG tmMaxCharWidth; - LONG tmWeight; - LONG tmOverhang; - LONG tmDigitizedAspectX; - LONG tmDigitizedAspectY; - BYTE tmFirstChar; - BYTE tmLastChar; - BYTE tmDefaultChar; - BYTE tmBreakChar; - BYTE tmItalic; - BYTE tmUnderlined; - BYTE tmStruckOut; - BYTE tmPitchAndFamily; - BYTE tmCharSet; - } TEXTMETRICA,*PTEXTMETRICA,*NPTEXTMETRICA,*LPTEXTMETRICA; - - typedef struct tagTEXTMETRICW { - LONG tmHeight; - LONG tmAscent; - LONG tmDescent; - LONG tmInternalLeading; - LONG tmExternalLeading; - LONG tmAveCharWidth; - LONG tmMaxCharWidth; - LONG tmWeight; - LONG tmOverhang; - LONG tmDigitizedAspectX; - LONG tmDigitizedAspectY; - WCHAR tmFirstChar; - WCHAR tmLastChar; - WCHAR tmDefaultChar; - WCHAR tmBreakChar; - BYTE tmItalic; - BYTE tmUnderlined; - BYTE tmStruckOut; - BYTE tmPitchAndFamily; - BYTE tmCharSet; - } TEXTMETRICW,*PTEXTMETRICW,*NPTEXTMETRICW,*LPTEXTMETRICW; -#ifdef UNICODE - typedef TEXTMETRICW TEXTMETRIC; - typedef PTEXTMETRICW PTEXTMETRIC; - typedef NPTEXTMETRICW NPTEXTMETRIC; - typedef LPTEXTMETRICW LPTEXTMETRIC; -#else - typedef TEXTMETRICA TEXTMETRIC; - typedef PTEXTMETRICA PTEXTMETRIC; - typedef NPTEXTMETRICA NPTEXTMETRIC; - typedef LPTEXTMETRICA LPTEXTMETRIC; -#endif -#endif - -#define NTM_REGULAR 0x00000040L -#define NTM_BOLD 0x00000020L -#define NTM_ITALIC 0x00000001L - -#define NTM_NONNEGATIVE_AC 0x00010000 -#define NTM_PS_OPENTYPE 0x00020000 -#define NTM_TT_OPENTYPE 0x00040000 -#define NTM_MULTIPLEMASTER 0x00080000 -#define NTM_TYPE1 0x00100000 -#define NTM_DSIG 0x00200000 - -#include - typedef struct tagNEWTEXTMETRICA { - LONG tmHeight; - LONG tmAscent; - LONG tmDescent; - LONG tmInternalLeading; - LONG tmExternalLeading; - LONG tmAveCharWidth; - LONG tmMaxCharWidth; - LONG tmWeight; - LONG tmOverhang; - LONG tmDigitizedAspectX; - LONG tmDigitizedAspectY; - BYTE tmFirstChar; - BYTE tmLastChar; - BYTE tmDefaultChar; - BYTE tmBreakChar; - BYTE tmItalic; - BYTE tmUnderlined; - BYTE tmStruckOut; - BYTE tmPitchAndFamily; - BYTE tmCharSet; - DWORD ntmFlags; - UINT ntmSizeEM; - UINT ntmCellHeight; - UINT ntmAvgWidth; - } NEWTEXTMETRICA,*PNEWTEXTMETRICA,*NPNEWTEXTMETRICA,*LPNEWTEXTMETRICA; - - typedef struct tagNEWTEXTMETRICW { - LONG tmHeight; - LONG tmAscent; - LONG tmDescent; - LONG tmInternalLeading; - LONG tmExternalLeading; - LONG tmAveCharWidth; - LONG tmMaxCharWidth; - LONG tmWeight; - LONG tmOverhang; - LONG tmDigitizedAspectX; - LONG tmDigitizedAspectY; - WCHAR tmFirstChar; - WCHAR tmLastChar; - WCHAR tmDefaultChar; - WCHAR tmBreakChar; - BYTE tmItalic; - BYTE tmUnderlined; - BYTE tmStruckOut; - BYTE tmPitchAndFamily; - BYTE tmCharSet; - DWORD ntmFlags; - UINT ntmSizeEM; - UINT ntmCellHeight; - UINT ntmAvgWidth; - } NEWTEXTMETRICW,*PNEWTEXTMETRICW,*NPNEWTEXTMETRICW,*LPNEWTEXTMETRICW; -#ifdef UNICODE - typedef NEWTEXTMETRICW NEWTEXTMETRIC; - typedef PNEWTEXTMETRICW PNEWTEXTMETRIC; - typedef NPNEWTEXTMETRICW NPNEWTEXTMETRIC; - typedef LPNEWTEXTMETRICW LPNEWTEXTMETRIC; -#else - typedef NEWTEXTMETRICA NEWTEXTMETRIC; - typedef PNEWTEXTMETRICA PNEWTEXTMETRIC; - typedef NPNEWTEXTMETRICA NPNEWTEXTMETRIC; - typedef LPNEWTEXTMETRICA LPNEWTEXTMETRIC; -#endif -#include - - typedef struct tagNEWTEXTMETRICEXA { - NEWTEXTMETRICA ntmTm; - FONTSIGNATURE ntmFontSig; - } NEWTEXTMETRICEXA; - - typedef struct tagNEWTEXTMETRICEXW { - NEWTEXTMETRICW ntmTm; - FONTSIGNATURE ntmFontSig; - } NEWTEXTMETRICEXW; -#ifdef UNICODE - typedef NEWTEXTMETRICEXW NEWTEXTMETRICEX; -#else - typedef NEWTEXTMETRICEXA NEWTEXTMETRICEX; -#endif -#endif - - typedef struct tagPELARRAY { - LONG paXCount; - LONG paYCount; - LONG paXExt; - LONG paYExt; - BYTE paRGBs; - } PELARRAY,*PPELARRAY,*NPPELARRAY,*LPPELARRAY; - - typedef struct tagLOGBRUSH { - UINT lbStyle; - COLORREF lbColor; - ULONG_PTR lbHatch; - } LOGBRUSH,*PLOGBRUSH,*NPLOGBRUSH,*LPLOGBRUSH; - - typedef struct tagLOGBRUSH32 { - UINT lbStyle; - COLORREF lbColor; - ULONG lbHatch; - } LOGBRUSH32,*PLOGBRUSH32,*NPLOGBRUSH32,*LPLOGBRUSH32; - - typedef LOGBRUSH PATTERN; - typedef PATTERN *PPATTERN; - typedef PATTERN *NPPATTERN; - typedef PATTERN *LPPATTERN; - - typedef struct tagLOGPEN { - UINT lopnStyle; - POINT lopnWidth; - COLORREF lopnColor; - } LOGPEN,*PLOGPEN,*NPLOGPEN,*LPLOGPEN; - - typedef struct tagEXTLOGPEN { - DWORD elpPenStyle; - DWORD elpWidth; - UINT elpBrushStyle; - COLORREF elpColor; - ULONG_PTR elpHatch; - DWORD elpNumEntries; - DWORD elpStyleEntry[1]; - } EXTLOGPEN,*PEXTLOGPEN,*NPEXTLOGPEN,*LPEXTLOGPEN; - -#ifndef _PALETTEENTRY_DEFINED -#define _PALETTEENTRY_DEFINED - typedef struct tagPALETTEENTRY { - BYTE peRed; - BYTE peGreen; - BYTE peBlue; - BYTE peFlags; - } PALETTEENTRY,*PPALETTEENTRY,*LPPALETTEENTRY; -#endif - -#ifndef _LOGPALETTE_DEFINED -#define _LOGPALETTE_DEFINED - - typedef struct tagLOGPALETTE { - WORD palVersion; - WORD palNumEntries; - PALETTEENTRY palPalEntry[1]; - } LOGPALETTE,*PLOGPALETTE,*NPLOGPALETTE,*LPLOGPALETTE; -#endif - -#define LF_FACESIZE 32 - - typedef struct tagLOGFONTA { - LONG lfHeight; - LONG lfWidth; - LONG lfEscapement; - LONG lfOrientation; - LONG lfWeight; - BYTE lfItalic; - BYTE lfUnderline; - BYTE lfStrikeOut; - BYTE lfCharSet; - BYTE lfOutPrecision; - BYTE lfClipPrecision; - BYTE lfQuality; - BYTE lfPitchAndFamily; - CHAR lfFaceName[LF_FACESIZE]; - } LOGFONTA,*PLOGFONTA,*NPLOGFONTA,*LPLOGFONTA; - - typedef struct tagLOGFONTW { - LONG lfHeight; - LONG lfWidth; - LONG lfEscapement; - LONG lfOrientation; - LONG lfWeight; - BYTE lfItalic; - BYTE lfUnderline; - BYTE lfStrikeOut; - BYTE lfCharSet; - BYTE lfOutPrecision; - BYTE lfClipPrecision; - BYTE lfQuality; - BYTE lfPitchAndFamily; - WCHAR lfFaceName[LF_FACESIZE]; - } LOGFONTW,*PLOGFONTW,*NPLOGFONTW,*LPLOGFONTW; -#ifdef UNICODE - typedef LOGFONTW LOGFONT; - typedef PLOGFONTW PLOGFONT; - typedef NPLOGFONTW NPLOGFONT; - typedef LPLOGFONTW LPLOGFONT; -#else - typedef LOGFONTA LOGFONT; - typedef PLOGFONTA PLOGFONT; - typedef NPLOGFONTA NPLOGFONT; - typedef LPLOGFONTA LPLOGFONT; -#endif - -#define LF_FULLFACESIZE 64 - - typedef struct tagENUMLOGFONTA { - LOGFONTA elfLogFont; - BYTE elfFullName[LF_FULLFACESIZE]; - BYTE elfStyle[LF_FACESIZE]; - } ENUMLOGFONTA,*LPENUMLOGFONTA; - - typedef struct tagENUMLOGFONTW { - LOGFONTW elfLogFont; - WCHAR elfFullName[LF_FULLFACESIZE]; - WCHAR elfStyle[LF_FACESIZE]; - } ENUMLOGFONTW,*LPENUMLOGFONTW; -#ifdef UNICODE - typedef ENUMLOGFONTW ENUMLOGFONT; - typedef LPENUMLOGFONTW LPENUMLOGFONT; -#else - typedef ENUMLOGFONTA ENUMLOGFONT; - typedef LPENUMLOGFONTA LPENUMLOGFONT; -#endif - - typedef struct tagENUMLOGFONTEXA { - LOGFONTA elfLogFont; - BYTE elfFullName[LF_FULLFACESIZE]; - BYTE elfStyle[LF_FACESIZE]; - BYTE elfScript[LF_FACESIZE]; - } ENUMLOGFONTEXA,*LPENUMLOGFONTEXA; - - typedef struct tagENUMLOGFONTEXW { - LOGFONTW elfLogFont; - WCHAR elfFullName[LF_FULLFACESIZE]; - WCHAR elfStyle[LF_FACESIZE]; - WCHAR elfScript[LF_FACESIZE]; - } ENUMLOGFONTEXW,*LPENUMLOGFONTEXW; -#ifdef UNICODE - typedef ENUMLOGFONTEXW ENUMLOGFONTEX; - typedef LPENUMLOGFONTEXW LPENUMLOGFONTEX; -#else - typedef ENUMLOGFONTEXA ENUMLOGFONTEX; - typedef LPENUMLOGFONTEXA LPENUMLOGFONTEX; -#endif - -#define OUT_DEFAULT_PRECIS 0 -#define OUT_STRING_PRECIS 1 -#define OUT_CHARACTER_PRECIS 2 -#define OUT_STROKE_PRECIS 3 -#define OUT_TT_PRECIS 4 -#define OUT_DEVICE_PRECIS 5 -#define OUT_RASTER_PRECIS 6 -#define OUT_TT_ONLY_PRECIS 7 -#define OUT_OUTLINE_PRECIS 8 -#define OUT_SCREEN_OUTLINE_PRECIS 9 -#define OUT_PS_ONLY_PRECIS 10 - -#define CLIP_DEFAULT_PRECIS 0 -#define CLIP_CHARACTER_PRECIS 1 -#define CLIP_STROKE_PRECIS 2 -#define CLIP_MASK 0xf -#define CLIP_LH_ANGLES (1<<4) -#define CLIP_TT_ALWAYS (2<<4) -#define CLIP_DFA_DISABLE (4<<4) -#define CLIP_EMBEDDED (8<<4) - -#define DEFAULT_QUALITY 0 -#define DRAFT_QUALITY 1 -#define PROOF_QUALITY 2 -#define NONANTIALIASED_QUALITY 3 -#define ANTIALIASED_QUALITY 4 - -#define CLEARTYPE_QUALITY 5 -#define CLEARTYPE_NATURAL_QUALITY 6 - -#define DEFAULT_PITCH 0 -#define FIXED_PITCH 1 -#define VARIABLE_PITCH 2 -#define MONO_FONT 8 - -#define ANSI_CHARSET 0 -#define DEFAULT_CHARSET 1 -#define SYMBOL_CHARSET 2 -#define SHIFTJIS_CHARSET 128 -#define HANGEUL_CHARSET 129 -#define HANGUL_CHARSET 129 -#define GB2312_CHARSET 134 -#define CHINESEBIG5_CHARSET 136 -#define OEM_CHARSET 255 -#define JOHAB_CHARSET 130 -#define HEBREW_CHARSET 177 -#define ARABIC_CHARSET 178 -#define GREEK_CHARSET 161 -#define TURKISH_CHARSET 162 -#define VIETNAMESE_CHARSET 163 -#define THAI_CHARSET 222 -#define EASTEUROPE_CHARSET 238 -#define RUSSIAN_CHARSET 204 - -#define MAC_CHARSET 77 -#define BALTIC_CHARSET 186 - -#define FS_LATIN1 0x00000001L -#define FS_LATIN2 0x00000002L -#define FS_CYRILLIC 0x00000004L -#define FS_GREEK 0x00000008L -#define FS_TURKISH 0x00000010L -#define FS_HEBREW 0x00000020L -#define FS_ARABIC 0x00000040L -#define FS_BALTIC 0x00000080L -#define FS_VIETNAMESE 0x00000100L -#define FS_THAI 0x00010000L -#define FS_JISJAPAN 0x00020000L -#define FS_CHINESESIMP 0x00040000L -#define FS_WANSUNG 0x00080000L -#define FS_CHINESETRAD 0x00100000L -#define FS_JOHAB 0x00200000L -#define FS_SYMBOL 0x80000000L - -#define FF_DONTCARE (0<<4) -#define FF_ROMAN (1<<4) - -#define FF_SWISS (2<<4) - -#define FF_MODERN (3<<4) - -#define FF_SCRIPT (4<<4) -#define FF_DECORATIVE (5<<4) - -#define FW_DONTCARE 0 -#define FW_THIN 100 -#define FW_EXTRALIGHT 200 -#define FW_LIGHT 300 -#define FW_NORMAL 400 -#define FW_MEDIUM 500 -#define FW_SEMIBOLD 600 -#define FW_BOLD 700 -#define FW_EXTRABOLD 800 -#define FW_HEAVY 900 - -#define FW_ULTRALIGHT FW_EXTRALIGHT -#define FW_REGULAR FW_NORMAL -#define FW_DEMIBOLD FW_SEMIBOLD -#define FW_ULTRABOLD FW_EXTRABOLD -#define FW_BLACK FW_HEAVY - -#define PANOSE_COUNT 10 -#define PAN_FAMILYTYPE_INDEX 0 -#define PAN_SERIFSTYLE_INDEX 1 -#define PAN_WEIGHT_INDEX 2 -#define PAN_PROPORTION_INDEX 3 -#define PAN_CONTRAST_INDEX 4 -#define PAN_STROKEVARIATION_INDEX 5 -#define PAN_ARMSTYLE_INDEX 6 -#define PAN_LETTERFORM_INDEX 7 -#define PAN_MIDLINE_INDEX 8 -#define PAN_XHEIGHT_INDEX 9 - -#define PAN_CULTURE_LATIN 0 - - typedef struct tagPANOSE { - BYTE bFamilyType; - BYTE bSerifStyle; - BYTE bWeight; - BYTE bProportion; - BYTE bContrast; - BYTE bStrokeVariation; - BYTE bArmStyle; - BYTE bLetterform; - BYTE bMidline; - BYTE bXHeight; - } PANOSE,*LPPANOSE; - -#define PAN_ANY 0 -#define PAN_NO_FIT 1 - -#define PAN_FAMILY_TEXT_DISPLAY 2 -#define PAN_FAMILY_SCRIPT 3 -#define PAN_FAMILY_DECORATIVE 4 -#define PAN_FAMILY_PICTORIAL 5 - -#define PAN_SERIF_COVE 2 -#define PAN_SERIF_OBTUSE_COVE 3 -#define PAN_SERIF_SQUARE_COVE 4 -#define PAN_SERIF_OBTUSE_SQUARE_COVE 5 -#define PAN_SERIF_SQUARE 6 -#define PAN_SERIF_THIN 7 -#define PAN_SERIF_BONE 8 -#define PAN_SERIF_EXAGGERATED 9 -#define PAN_SERIF_TRIANGLE 10 -#define PAN_SERIF_NORMAL_SANS 11 -#define PAN_SERIF_OBTUSE_SANS 12 -#define PAN_SERIF_PERP_SANS 13 -#define PAN_SERIF_FLARED 14 -#define PAN_SERIF_ROUNDED 15 - -#define PAN_WEIGHT_VERY_LIGHT 2 -#define PAN_WEIGHT_LIGHT 3 -#define PAN_WEIGHT_THIN 4 -#define PAN_WEIGHT_BOOK 5 -#define PAN_WEIGHT_MEDIUM 6 -#define PAN_WEIGHT_DEMI 7 -#define PAN_WEIGHT_BOLD 8 -#define PAN_WEIGHT_HEAVY 9 -#define PAN_WEIGHT_BLACK 10 -#define PAN_WEIGHT_NORD 11 - -#define PAN_PROP_OLD_STYLE 2 -#define PAN_PROP_MODERN 3 -#define PAN_PROP_EVEN_WIDTH 4 -#define PAN_PROP_EXPANDED 5 -#define PAN_PROP_CONDENSED 6 -#define PAN_PROP_VERY_EXPANDED 7 -#define PAN_PROP_VERY_CONDENSED 8 -#define PAN_PROP_MONOSPACED 9 - -#define PAN_CONTRAST_NONE 2 -#define PAN_CONTRAST_VERY_LOW 3 -#define PAN_CONTRAST_LOW 4 -#define PAN_CONTRAST_MEDIUM_LOW 5 -#define PAN_CONTRAST_MEDIUM 6 -#define PAN_CONTRAST_MEDIUM_HIGH 7 -#define PAN_CONTRAST_HIGH 8 -#define PAN_CONTRAST_VERY_HIGH 9 - -#define PAN_STROKE_GRADUAL_DIAG 2 -#define PAN_STROKE_GRADUAL_TRAN 3 -#define PAN_STROKE_GRADUAL_VERT 4 -#define PAN_STROKE_GRADUAL_HORZ 5 -#define PAN_STROKE_RAPID_VERT 6 -#define PAN_STROKE_RAPID_HORZ 7 -#define PAN_STROKE_INSTANT_VERT 8 - -#define PAN_STRAIGHT_ARMS_HORZ 2 -#define PAN_STRAIGHT_ARMS_WEDGE 3 -#define PAN_STRAIGHT_ARMS_VERT 4 -#define PAN_STRAIGHT_ARMS_SINGLE_SERIF 5 -#define PAN_STRAIGHT_ARMS_DOUBLE_SERIF 6 -#define PAN_BENT_ARMS_HORZ 7 -#define PAN_BENT_ARMS_WEDGE 8 -#define PAN_BENT_ARMS_VERT 9 -#define PAN_BENT_ARMS_SINGLE_SERIF 10 -#define PAN_BENT_ARMS_DOUBLE_SERIF 11 - -#define PAN_LETT_NORMAL_CONTACT 2 -#define PAN_LETT_NORMAL_WEIGHTED 3 -#define PAN_LETT_NORMAL_BOXED 4 -#define PAN_LETT_NORMAL_FLATTENED 5 -#define PAN_LETT_NORMAL_ROUNDED 6 -#define PAN_LETT_NORMAL_OFF_CENTER 7 -#define PAN_LETT_NORMAL_SQUARE 8 -#define PAN_LETT_OBLIQUE_CONTACT 9 -#define PAN_LETT_OBLIQUE_WEIGHTED 10 -#define PAN_LETT_OBLIQUE_BOXED 11 -#define PAN_LETT_OBLIQUE_FLATTENED 12 -#define PAN_LETT_OBLIQUE_ROUNDED 13 -#define PAN_LETT_OBLIQUE_OFF_CENTER 14 -#define PAN_LETT_OBLIQUE_SQUARE 15 - -#define PAN_MIDLINE_STANDARD_TRIMMED 2 -#define PAN_MIDLINE_STANDARD_POINTED 3 -#define PAN_MIDLINE_STANDARD_SERIFED 4 -#define PAN_MIDLINE_HIGH_TRIMMED 5 -#define PAN_MIDLINE_HIGH_POINTED 6 -#define PAN_MIDLINE_HIGH_SERIFED 7 -#define PAN_MIDLINE_CONSTANT_TRIMMED 8 -#define PAN_MIDLINE_CONSTANT_POINTED 9 -#define PAN_MIDLINE_CONSTANT_SERIFED 10 -#define PAN_MIDLINE_LOW_TRIMMED 11 -#define PAN_MIDLINE_LOW_POINTED 12 -#define PAN_MIDLINE_LOW_SERIFED 13 - -#define PAN_XHEIGHT_CONSTANT_SMALL 2 -#define PAN_XHEIGHT_CONSTANT_STD 3 -#define PAN_XHEIGHT_CONSTANT_LARGE 4 -#define PAN_XHEIGHT_DUCKING_SMALL 5 -#define PAN_XHEIGHT_DUCKING_STD 6 -#define PAN_XHEIGHT_DUCKING_LARGE 7 - -#define ELF_VENDOR_SIZE 4 - - typedef struct tagEXTLOGFONTA { - LOGFONTA elfLogFont; - BYTE elfFullName[LF_FULLFACESIZE]; - BYTE elfStyle[LF_FACESIZE]; - DWORD elfVersion; - DWORD elfStyleSize; - DWORD elfMatch; - DWORD elfReserved; - BYTE elfVendorId[ELF_VENDOR_SIZE]; - DWORD elfCulture; - PANOSE elfPanose; - } EXTLOGFONTA,*PEXTLOGFONTA,*NPEXTLOGFONTA,*LPEXTLOGFONTA; - - typedef struct tagEXTLOGFONTW { - LOGFONTW elfLogFont; - WCHAR elfFullName[LF_FULLFACESIZE]; - WCHAR elfStyle[LF_FACESIZE]; - DWORD elfVersion; - DWORD elfStyleSize; - DWORD elfMatch; - DWORD elfReserved; - BYTE elfVendorId[ELF_VENDOR_SIZE]; - DWORD elfCulture; - PANOSE elfPanose; - } EXTLOGFONTW,*PEXTLOGFONTW,*NPEXTLOGFONTW,*LPEXTLOGFONTW; -#ifdef UNICODE - typedef EXTLOGFONTW EXTLOGFONT; - typedef PEXTLOGFONTW PEXTLOGFONT; - typedef NPEXTLOGFONTW NPEXTLOGFONT; - typedef LPEXTLOGFONTW LPEXTLOGFONT; -#else - typedef EXTLOGFONTA EXTLOGFONT; - typedef PEXTLOGFONTA PEXTLOGFONT; - typedef NPEXTLOGFONTA NPEXTLOGFONT; - typedef LPEXTLOGFONTA LPEXTLOGFONT; -#endif - -#define ELF_VERSION 0 -#define ELF_CULTURE_LATIN 0 - -#define RASTER_FONTTYPE 0x0001 -#define DEVICE_FONTTYPE 0x002 -#define TRUETYPE_FONTTYPE 0x004 - -#define RGB(r,g,b) ((COLORREF)(((BYTE)(r)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(b))<<16))) -#define PALETTERGB(r,g,b) (0x02000000 | RGB(r,g,b)) -#define PALETTEINDEX(i) ((COLORREF)(0x01000000 | (DWORD)(WORD)(i))) - -#define PC_RESERVED 0x01 -#define PC_EXPLICIT 0x02 -#define PC_NOCOLLAPSE 0x04 - -#define GetRValue(rgb) (LOBYTE(rgb)) -#define GetGValue(rgb) (LOBYTE(((WORD)(rgb)) >> 8)) -#define GetBValue(rgb) (LOBYTE((rgb)>>16)) - -#define TRANSPARENT 1 -#define OPAQUE 2 -#define BKMODE_LAST 2 - -#define GM_COMPATIBLE 1 -#define GM_ADVANCED 2 -#define GM_LAST 2 - -#define PT_CLOSEFIGURE 0x01 -#define PT_LINETO 0x02 -#define PT_BEZIERTO 0x04 -#define PT_MOVETO 0x06 - -#define MM_TEXT 1 -#define MM_LOMETRIC 2 -#define MM_HIMETRIC 3 -#define MM_LOENGLISH 4 -#define MM_HIENGLISH 5 -#define MM_TWIPS 6 -#define MM_ISOTROPIC 7 -#define MM_ANISOTROPIC 8 - -#define MM_MIN MM_TEXT -#define MM_MAX MM_ANISOTROPIC -#define MM_MAX_FIXEDSCALE MM_TWIPS - -#define ABSOLUTE 1 -#define RELATIVE 2 - -#define WHITE_BRUSH 0 -#define LTGRAY_BRUSH 1 -#define GRAY_BRUSH 2 -#define DKGRAY_BRUSH 3 -#define BLACK_BRUSH 4 -#define NULL_BRUSH 5 -#define HOLLOW_BRUSH NULL_BRUSH -#define WHITE_PEN 6 -#define BLACK_PEN 7 -#define NULL_PEN 8 -#define OEM_FIXED_FONT 10 -#define ANSI_FIXED_FONT 11 -#define ANSI_VAR_FONT 12 -#define SYSTEM_FONT 13 -#define DEVICE_DEFAULT_FONT 14 -#define DEFAULT_PALETTE 15 -#define SYSTEM_FIXED_FONT 16 - -#define DEFAULT_GUI_FONT 17 - -#define DC_BRUSH 18 -#define DC_PEN 19 - -#define STOCK_LAST 19 - -#define CLR_INVALID 0xFFFFFFFF - -#define BS_SOLID 0 -#define BS_NULL 1 -#define BS_HOLLOW BS_NULL -#define BS_HATCHED 2 -#define BS_PATTERN 3 -#define BS_INDEXED 4 -#define BS_DIBPATTERN 5 -#define BS_DIBPATTERNPT 6 -#define BS_PATTERN8X8 7 -#define BS_DIBPATTERN8X8 8 -#define BS_MONOPATTERN 9 - -#define HS_HORIZONTAL 0 -#define HS_VERTICAL 1 -#define HS_FDIAGONAL 2 -#define HS_BDIAGONAL 3 -#define HS_CROSS 4 -#define HS_DIAGCROSS 5 - -#define PS_SOLID 0 -#define PS_DASH 1 -#define PS_DOT 2 -#define PS_DASHDOT 3 -#define PS_DASHDOTDOT 4 -#define PS_NULL 5 -#define PS_INSIDEFRAME 6 -#define PS_USERSTYLE 7 -#define PS_ALTERNATE 8 -#define PS_STYLE_MASK 0x0000000F - -#define PS_ENDCAP_ROUND 0x00000000 -#define PS_ENDCAP_SQUARE 0x00000100 -#define PS_ENDCAP_FLAT 0x00000200 -#define PS_ENDCAP_MASK 0x00000F00 - -#define PS_JOIN_ROUND 0x00000000 -#define PS_JOIN_BEVEL 0x00001000 -#define PS_JOIN_MITER 0x00002000 -#define PS_JOIN_MASK 0x0000F000 - -#define PS_COSMETIC 0x00000000 -#define PS_GEOMETRIC 0x00010000 -#define PS_TYPE_MASK 0x000F0000 - -#define AD_COUNTERCLOCKWISE 1 -#define AD_CLOCKWISE 2 - -#define DRIVERVERSION 0 -#define TECHNOLOGY 2 -#define HORZSIZE 4 -#define VERTSIZE 6 -#define HORZRES 8 -#define VERTRES 10 -#define BITSPIXEL 12 -#define PLANES 14 -#define NUMBRUSHES 16 -#define NUMPENS 18 -#define NUMMARKERS 20 -#define NUMFONTS 22 -#define NUMCOLORS 24 -#define PDEVICESIZE 26 -#define CURVECAPS 28 -#define LINECAPS 30 -#define POLYGONALCAPS 32 -#define TEXTCAPS 34 -#define CLIPCAPS 36 -#define RASTERCAPS 38 -#define ASPECTX 40 -#define ASPECTY 42 -#define ASPECTXY 44 - -#define LOGPIXELSX 88 -#define LOGPIXELSY 90 - -#define SIZEPALETTE 104 -#define NUMRESERVED 106 -#define COLORRES 108 - -#define PHYSICALWIDTH 110 -#define PHYSICALHEIGHT 111 -#define PHYSICALOFFSETX 112 -#define PHYSICALOFFSETY 113 -#define SCALINGFACTORX 114 -#define SCALINGFACTORY 115 - -#define VREFRESH 116 - -#define DESKTOPVERTRES 117 - -#define DESKTOPHORZRES 118 - -#define BLTALIGNMENT 119 - -#define SHADEBLENDCAPS 120 -#define COLORMGMTCAPS 121 - -#ifndef NOGDICAPMASKS -#define DT_PLOTTER 0 -#define DT_RASDISPLAY 1 -#define DT_RASPRINTER 2 -#define DT_RASCAMERA 3 -#define DT_CHARSTREAM 4 -#define DT_METAFILE 5 -#define DT_DISPFILE 6 - -#define CC_NONE 0 -#define CC_CIRCLES 1 -#define CC_PIE 2 -#define CC_CHORD 4 -#define CC_ELLIPSES 8 -#define CC_WIDE 16 -#define CC_STYLED 32 -#define CC_WIDESTYLED 64 -#define CC_INTERIORS 128 -#define CC_ROUNDRECT 256 - -#define LC_NONE 0 -#define LC_POLYLINE 2 -#define LC_MARKER 4 -#define LC_POLYMARKER 8 -#define LC_WIDE 16 -#define LC_STYLED 32 -#define LC_WIDESTYLED 64 -#define LC_INTERIORS 128 - -#define PC_NONE 0 -#define PC_POLYGON 1 -#define PC_RECTANGLE 2 -#define PC_WINDPOLYGON 4 -#define PC_TRAPEZOID 4 -#define PC_SCANLINE 8 -#define PC_WIDE 16 -#define PC_STYLED 32 -#define PC_WIDESTYLED 64 -#define PC_INTERIORS 128 -#define PC_POLYPOLYGON 256 -#define PC_PATHS 512 - -#define CP_NONE 0 -#define CP_RECTANGLE 1 -#define CP_REGION 2 - -#define TC_OP_CHARACTER 0x00000001 -#define TC_OP_STROKE 0x00000002 -#define TC_CP_STROKE 0x00000004 -#define TC_CR_90 0x00000008 -#define TC_CR_ANY 0x00000010 -#define TC_SF_X_YINDEP 0x00000020 -#define TC_SA_DOUBLE 0x00000040 -#define TC_SA_INTEGER 0x00000080 -#define TC_SA_CONTIN 0x00000100 -#define TC_EA_DOUBLE 0x00000200 -#define TC_IA_ABLE 0x00000400 -#define TC_UA_ABLE 0x00000800 -#define TC_SO_ABLE 0x00001000 -#define TC_RA_ABLE 0x00002000 -#define TC_VA_ABLE 0x00004000 -#define TC_RESERVED 0x00008000 -#define TC_SCROLLBLT 0x00010000 -#endif - -#define RC_NONE -#define RC_BITBLT 1 -#define RC_BANDING 2 -#define RC_SCALING 4 -#define RC_BITMAP64 8 -#define RC_GDI20_OUTPUT 0x0010 -#define RC_GDI20_STATE 0x0020 -#define RC_SAVEBITMAP 0x0040 -#define RC_DI_BITMAP 0x0080 -#define RC_PALETTE 0x0100 -#define RC_DIBTODEV 0x0200 -#define RC_BIGFONT 0x0400 -#define RC_STRETCHBLT 0x0800 -#define RC_FLOODFILL 0x1000 -#define RC_STRETCHDIB 0x2000 -#define RC_OP_DX_OUTPUT 0x4000 -#define RC_DEVBITS 0x8000 - -#define SB_NONE 0x00000000 -#define SB_CONST_ALPHA 0x00000001 -#define SB_PIXEL_ALPHA 0x00000002 -#define SB_PREMULT_ALPHA 0x00000004 - -#define SB_GRAD_RECT 0x00000010 -#define SB_GRAD_TRI 0x00000020 - -#define CM_NONE 0x00000000 -#define CM_DEVICE_ICM 0x00000001 -#define CM_GAMMA_RAMP 0x00000002 -#define CM_CMYK_COLOR 0x00000004 - -#define DIB_RGB_COLORS 0 -#define DIB_PAL_COLORS 1 - -#define SYSPAL_ERROR 0 -#define SYSPAL_STATIC 1 -#define SYSPAL_NOSTATIC 2 -#define SYSPAL_NOSTATIC256 3 - -#define CBM_INIT 0x04L - -#define FLOODFILLBORDER 0 -#define FLOODFILLSURFACE 1 - -#define CCHDEVICENAME 32 - -#define CCHFORMNAME 32 - - typedef struct _devicemodeA { - BYTE dmDeviceName[CCHDEVICENAME]; - WORD dmSpecVersion; - WORD dmDriverVersion; - WORD dmSize; - WORD dmDriverExtra; - DWORD dmFields; - union { - struct { - short dmOrientation; - short dmPaperSize; - short dmPaperLength; - short dmPaperWidth; - short dmScale; - short dmCopies; - short dmDefaultSource; - short dmPrintQuality; - }; - struct { - POINTL dmPosition; - DWORD dmDisplayOrientation; - DWORD dmDisplayFixedOutput; - }; - }; - short dmColor; - short dmDuplex; - short dmYResolution; - short dmTTOption; - short dmCollate; - BYTE dmFormName[CCHFORMNAME]; - WORD dmLogPixels; - DWORD dmBitsPerPel; - DWORD dmPelsWidth; - DWORD dmPelsHeight; - union { - DWORD dmDisplayFlags; - DWORD dmNup; - }; - DWORD dmDisplayFrequency; - DWORD dmICMMethod; - DWORD dmICMIntent; - DWORD dmMediaType; - DWORD dmDitherType; - DWORD dmReserved1; - DWORD dmReserved2; - DWORD dmPanningWidth; - DWORD dmPanningHeight; - } DEVMODEA,*PDEVMODEA,*NPDEVMODEA,*LPDEVMODEA; - - typedef struct _devicemodeW { - WCHAR dmDeviceName[CCHDEVICENAME]; - WORD dmSpecVersion; - WORD dmDriverVersion; - WORD dmSize; - WORD dmDriverExtra; - DWORD dmFields; - union { - struct { - short dmOrientation; - short dmPaperSize; - short dmPaperLength; - short dmPaperWidth; - short dmScale; - short dmCopies; - short dmDefaultSource; - short dmPrintQuality; - }; - struct { - POINTL dmPosition; - DWORD dmDisplayOrientation; - DWORD dmDisplayFixedOutput; - }; - }; - short dmColor; - short dmDuplex; - short dmYResolution; - short dmTTOption; - short dmCollate; - WCHAR dmFormName[CCHFORMNAME]; - WORD dmLogPixels; - DWORD dmBitsPerPel; - DWORD dmPelsWidth; - DWORD dmPelsHeight; - union { - DWORD dmDisplayFlags; - DWORD dmNup; - }; - DWORD dmDisplayFrequency; - DWORD dmICMMethod; - DWORD dmICMIntent; - DWORD dmMediaType; - DWORD dmDitherType; - DWORD dmReserved1; - DWORD dmReserved2; - DWORD dmPanningWidth; - DWORD dmPanningHeight; - } DEVMODEW,*PDEVMODEW,*NPDEVMODEW,*LPDEVMODEW; -#ifdef UNICODE - typedef DEVMODEW DEVMODE; - typedef PDEVMODEW PDEVMODE; - typedef NPDEVMODEW NPDEVMODE; - typedef LPDEVMODEW LPDEVMODE; -#else - typedef DEVMODEA DEVMODE; - typedef PDEVMODEA PDEVMODE; - typedef NPDEVMODEA NPDEVMODE; - typedef LPDEVMODEA LPDEVMODE; -#endif - -#define DM_SPECVERSION 0x0401 - -#define DM_ORIENTATION 0x00000001L -#define DM_PAPERSIZE 0x00000002L -#define DM_PAPERLENGTH 0x00000004L -#define DM_PAPERWIDTH 0x00000008L -#define DM_SCALE 0x00000010L -#define DM_POSITION 0x00000020L -#define DM_NUP 0x00000040L -#define DM_DISPLAYORIENTATION 0x00000080L -#define DM_COPIES 0x00000100L -#define DM_DEFAULTSOURCE 0x00000200L -#define DM_PRINTQUALITY 0x00000400L -#define DM_COLOR 0x00000800L -#define DM_DUPLEX 0x00001000L -#define DM_YRESOLUTION 0x00002000L -#define DM_TTOPTION 0x00004000L -#define DM_COLLATE 0x00008000L -#define DM_FORMNAME 0x00010000L -#define DM_LOGPIXELS 0x00020000L -#define DM_BITSPERPEL 0x00040000L -#define DM_PELSWIDTH 0x00080000L -#define DM_PELSHEIGHT 0x00100000L -#define DM_DISPLAYFLAGS 0x00200000L -#define DM_DISPLAYFREQUENCY 0x00400000L -#define DM_ICMMETHOD 0x00800000L -#define DM_ICMINTENT 0x01000000L -#define DM_MEDIATYPE 0x02000000L -#define DM_DITHERTYPE 0x04000000L -#define DM_PANNINGWIDTH 0x08000000L -#define DM_PANNINGHEIGHT 0x10000000L -#define DM_DISPLAYFIXEDOUTPUT 0x20000000L - -#define DMORIENT_PORTRAIT 1 -#define DMORIENT_LANDSCAPE 2 - -#define DMPAPER_FIRST DMPAPER_LETTER -#define DMPAPER_LETTER 1 -#define DMPAPER_LETTERSMALL 2 -#define DMPAPER_TABLOID 3 -#define DMPAPER_LEDGER 4 -#define DMPAPER_LEGAL 5 -#define DMPAPER_STATEMENT 6 -#define DMPAPER_EXECUTIVE 7 -#define DMPAPER_A3 8 -#define DMPAPER_A4 9 -#define DMPAPER_A4SMALL 10 -#define DMPAPER_A5 11 -#define DMPAPER_B4 12 -#define DMPAPER_B5 13 -#define DMPAPER_FOLIO 14 -#define DMPAPER_QUARTO 15 -#define DMPAPER_10X14 16 -#define DMPAPER_11X17 17 -#define DMPAPER_NOTE 18 -#define DMPAPER_ENV_9 19 -#define DMPAPER_ENV_10 20 -#define DMPAPER_ENV_11 21 -#define DMPAPER_ENV_12 22 -#define DMPAPER_ENV_14 23 -#define DMPAPER_CSHEET 24 -#define DMPAPER_DSHEET 25 -#define DMPAPER_ESHEET 26 -#define DMPAPER_ENV_DL 27 -#define DMPAPER_ENV_C5 28 -#define DMPAPER_ENV_C3 29 -#define DMPAPER_ENV_C4 30 -#define DMPAPER_ENV_C6 31 -#define DMPAPER_ENV_C65 32 -#define DMPAPER_ENV_B4 33 -#define DMPAPER_ENV_B5 34 -#define DMPAPER_ENV_B6 35 -#define DMPAPER_ENV_ITALY 36 -#define DMPAPER_ENV_MONARCH 37 -#define DMPAPER_ENV_PERSONAL 38 -#define DMPAPER_FANFOLD_US 39 -#define DMPAPER_FANFOLD_STD_GERMAN 40 -#define DMPAPER_FANFOLD_LGL_GERMAN 41 -#define DMPAPER_ISO_B4 42 -#define DMPAPER_JAPANESE_POSTCARD 43 -#define DMPAPER_9X11 44 -#define DMPAPER_10X11 45 -#define DMPAPER_15X11 46 -#define DMPAPER_ENV_INVITE 47 -#define DMPAPER_RESERVED_48 48 -#define DMPAPER_RESERVED_49 49 -#define DMPAPER_LETTER_EXTRA 50 -#define DMPAPER_LEGAL_EXTRA 51 -#define DMPAPER_TABLOID_EXTRA 52 -#define DMPAPER_A4_EXTRA 53 -#define DMPAPER_LETTER_TRANSVERSE 54 -#define DMPAPER_A4_TRANSVERSE 55 -#define DMPAPER_LETTER_EXTRA_TRANSVERSE 56 -#define DMPAPER_A_PLUS 57 -#define DMPAPER_B_PLUS 58 -#define DMPAPER_LETTER_PLUS 59 -#define DMPAPER_A4_PLUS 60 -#define DMPAPER_A5_TRANSVERSE 61 -#define DMPAPER_B5_TRANSVERSE 62 -#define DMPAPER_A3_EXTRA 63 -#define DMPAPER_A5_EXTRA 64 -#define DMPAPER_B5_EXTRA 65 -#define DMPAPER_A2 66 -#define DMPAPER_A3_TRANSVERSE 67 -#define DMPAPER_A3_EXTRA_TRANSVERSE 68 -#define DMPAPER_DBL_JAPANESE_POSTCARD 69 -#define DMPAPER_A6 70 -#define DMPAPER_JENV_KAKU2 71 -#define DMPAPER_JENV_KAKU3 72 -#define DMPAPER_JENV_CHOU3 73 -#define DMPAPER_JENV_CHOU4 74 -#define DMPAPER_LETTER_ROTATED 75 -#define DMPAPER_A3_ROTATED 76 -#define DMPAPER_A4_ROTATED 77 -#define DMPAPER_A5_ROTATED 78 -#define DMPAPER_B4_JIS_ROTATED 79 -#define DMPAPER_B5_JIS_ROTATED 80 -#define DMPAPER_JAPANESE_POSTCARD_ROTATED 81 -#define DMPAPER_DBL_JAPANESE_POSTCARD_ROTATED 82 -#define DMPAPER_A6_ROTATED 83 -#define DMPAPER_JENV_KAKU2_ROTATED 84 -#define DMPAPER_JENV_KAKU3_ROTATED 85 -#define DMPAPER_JENV_CHOU3_ROTATED 86 -#define DMPAPER_JENV_CHOU4_ROTATED 87 -#define DMPAPER_B6_JIS 88 -#define DMPAPER_B6_JIS_ROTATED 89 -#define DMPAPER_12X11 90 -#define DMPAPER_JENV_YOU4 91 -#define DMPAPER_JENV_YOU4_ROTATED 92 -#define DMPAPER_P16K 93 -#define DMPAPER_P32K 94 -#define DMPAPER_P32KBIG 95 -#define DMPAPER_PENV_1 96 -#define DMPAPER_PENV_2 97 -#define DMPAPER_PENV_3 98 -#define DMPAPER_PENV_4 99 -#define DMPAPER_PENV_5 100 -#define DMPAPER_PENV_6 101 -#define DMPAPER_PENV_7 102 -#define DMPAPER_PENV_8 103 -#define DMPAPER_PENV_9 104 -#define DMPAPER_PENV_10 105 -#define DMPAPER_P16K_ROTATED 106 -#define DMPAPER_P32K_ROTATED 107 -#define DMPAPER_P32KBIG_ROTATED 108 -#define DMPAPER_PENV_1_ROTATED 109 -#define DMPAPER_PENV_2_ROTATED 110 -#define DMPAPER_PENV_3_ROTATED 111 -#define DMPAPER_PENV_4_ROTATED 112 -#define DMPAPER_PENV_5_ROTATED 113 -#define DMPAPER_PENV_6_ROTATED 114 -#define DMPAPER_PENV_7_ROTATED 115 -#define DMPAPER_PENV_8_ROTATED 116 -#define DMPAPER_PENV_9_ROTATED 117 -#define DMPAPER_PENV_10_ROTATED 118 - -#define DMPAPER_LAST DMPAPER_PENV_10_ROTATED - -#define DMPAPER_USER 256 - -#define DMBIN_FIRST DMBIN_UPPER -#define DMBIN_UPPER 1 -#define DMBIN_ONLYONE 1 -#define DMBIN_LOWER 2 -#define DMBIN_MIDDLE 3 -#define DMBIN_MANUAL 4 -#define DMBIN_ENVELOPE 5 -#define DMBIN_ENVMANUAL 6 -#define DMBIN_AUTO 7 -#define DMBIN_TRACTOR 8 -#define DMBIN_SMALLFMT 9 -#define DMBIN_LARGEFMT 10 -#define DMBIN_LARGECAPACITY 11 -#define DMBIN_CASSETTE 14 -#define DMBIN_FORMSOURCE 15 -#define DMBIN_LAST DMBIN_FORMSOURCE - -#define DMBIN_USER 256 - -#define DMRES_DRAFT (-1) -#define DMRES_LOW (-2) -#define DMRES_MEDIUM (-3) -#define DMRES_HIGH (-4) - -#define DMCOLOR_MONOCHROME 1 -#define DMCOLOR_COLOR 2 - -#define DMDUP_SIMPLEX 1 -#define DMDUP_VERTICAL 2 -#define DMDUP_HORIZONTAL 3 - -#define DMTT_BITMAP 1 -#define DMTT_DOWNLOAD 2 -#define DMTT_SUBDEV 3 -#define DMTT_DOWNLOAD_OUTLINE 4 - -#define DMCOLLATE_FALSE 0 -#define DMCOLLATE_TRUE 1 - -#define DMDO_DEFAULT 0 -#define DMDO_90 1 -#define DMDO_180 2 -#define DMDO_270 3 - -#define DMDFO_DEFAULT 0 -#define DMDFO_STRETCH 1 -#define DMDFO_CENTER 2 - -#define DMDISPLAYFLAGS_TEXTMODE 0x00000004 - -#define DMNUP_SYSTEM 1 -#define DMNUP_ONEUP 2 - -#define DMICMMETHOD_NONE 1 -#define DMICMMETHOD_SYSTEM 2 -#define DMICMMETHOD_DRIVER 3 -#define DMICMMETHOD_DEVICE 4 - -#define DMICMMETHOD_USER 256 - -#define DMICM_SATURATE 1 -#define DMICM_CONTRAST 2 -#define DMICM_COLORIMETRIC 3 -#define DMICM_ABS_COLORIMETRIC 4 - -#define DMICM_USER 256 - -#define DMMEDIA_STANDARD 1 -#define DMMEDIA_TRANSPARENCY 2 -#define DMMEDIA_GLOSSY 3 - -#define DMMEDIA_USER 256 - -#define DMDITHER_NONE 1 -#define DMDITHER_COARSE 2 -#define DMDITHER_FINE 3 -#define DMDITHER_LINEART 4 -#define DMDITHER_ERRORDIFFUSION 5 -#define DMDITHER_RESERVED6 6 -#define DMDITHER_RESERVED7 7 -#define DMDITHER_RESERVED8 8 -#define DMDITHER_RESERVED9 9 -#define DMDITHER_GRAYSCALE 10 - -#define DMDITHER_USER 256 - - typedef struct _DISPLAY_DEVICEA { - DWORD cb; - CHAR DeviceName[32]; - CHAR DeviceString[128]; - DWORD StateFlags; - CHAR DeviceID[128]; - CHAR DeviceKey[128]; - } DISPLAY_DEVICEA,*PDISPLAY_DEVICEA,*LPDISPLAY_DEVICEA; - typedef struct _DISPLAY_DEVICEW { - DWORD cb; - WCHAR DeviceName[32]; - WCHAR DeviceString[128]; - DWORD StateFlags; - WCHAR DeviceID[128]; - WCHAR DeviceKey[128]; - } DISPLAY_DEVICEW,*PDISPLAY_DEVICEW,*LPDISPLAY_DEVICEW; -#ifdef UNICODE - typedef DISPLAY_DEVICEW DISPLAY_DEVICE; - typedef PDISPLAY_DEVICEW PDISPLAY_DEVICE; - typedef LPDISPLAY_DEVICEW LPDISPLAY_DEVICE; -#else - typedef DISPLAY_DEVICEA DISPLAY_DEVICE; - typedef PDISPLAY_DEVICEA PDISPLAY_DEVICE; - typedef LPDISPLAY_DEVICEA LPDISPLAY_DEVICE; -#endif - -#define DISPLAY_DEVICE_ATTACHED_TO_DESKTOP 0x00000001 -#define DISPLAY_DEVICE_MULTI_DRIVER 0x00000002 -#define DISPLAY_DEVICE_PRIMARY_DEVICE 0x00000004 -#define DISPLAY_DEVICE_MIRRORING_DRIVER 0x00000008 -#define DISPLAY_DEVICE_VGA_COMPATIBLE 0x00000010 -#define DISPLAY_DEVICE_REMOVABLE 0x00000020 -#define DISPLAY_DEVICE_MODESPRUNED 0x08000000 -#define DISPLAY_DEVICE_REMOTE 0x04000000 -#define DISPLAY_DEVICE_DISCONNECT 0x02000000 - -#define DISPLAY_DEVICE_ACTIVE 0x00000001 -#define DISPLAY_DEVICE_ATTACHED 0x00000002 - -#define RDH_RECTANGLES 1 - - typedef struct _RGNDATAHEADER { - DWORD dwSize; - DWORD iType; - DWORD nCount; - DWORD nRgnSize; - RECT rcBound; - } RGNDATAHEADER,*PRGNDATAHEADER; - - typedef struct _RGNDATA { - RGNDATAHEADER rdh; - char Buffer[1]; - } RGNDATA,*PRGNDATA,*NPRGNDATA,*LPRGNDATA; - -#define SYSRGN 4 - - typedef struct _ABC { - int abcA; - UINT abcB; - int abcC; - } ABC,*PABC,*NPABC,*LPABC; - - typedef struct _ABCFLOAT { - FLOAT abcfA; - FLOAT abcfB; - FLOAT abcfC; - } ABCFLOAT,*PABCFLOAT,*NPABCFLOAT,*LPABCFLOAT; - -#ifndef NOTEXTMETRIC - - typedef struct _OUTLINETEXTMETRICA { - UINT otmSize; - TEXTMETRICA otmTextMetrics; - BYTE otmFiller; - PANOSE otmPanoseNumber; - UINT otmfsSelection; - UINT otmfsType; - int otmsCharSlopeRise; - int otmsCharSlopeRun; - int otmItalicAngle; - UINT otmEMSquare; - int otmAscent; - int otmDescent; - UINT otmLineGap; - UINT otmsCapEmHeight; - UINT otmsXHeight; - RECT otmrcFontBox; - int otmMacAscent; - int otmMacDescent; - UINT otmMacLineGap; - UINT otmusMinimumPPEM; - POINT otmptSubscriptSize; - POINT otmptSubscriptOffset; - POINT otmptSuperscriptSize; - POINT otmptSuperscriptOffset; - UINT otmsStrikeoutSize; - int otmsStrikeoutPosition; - int otmsUnderscoreSize; - int otmsUnderscorePosition; - PSTR otmpFamilyName; - PSTR otmpFaceName; - PSTR otmpStyleName; - PSTR otmpFullName; - } OUTLINETEXTMETRICA,*POUTLINETEXTMETRICA,*NPOUTLINETEXTMETRICA,*LPOUTLINETEXTMETRICA; - - typedef struct _OUTLINETEXTMETRICW { - UINT otmSize; - TEXTMETRICW otmTextMetrics; - BYTE otmFiller; - PANOSE otmPanoseNumber; - UINT otmfsSelection; - UINT otmfsType; - int otmsCharSlopeRise; - int otmsCharSlopeRun; - int otmItalicAngle; - UINT otmEMSquare; - int otmAscent; - int otmDescent; - UINT otmLineGap; - UINT otmsCapEmHeight; - UINT otmsXHeight; - RECT otmrcFontBox; - int otmMacAscent; - int otmMacDescent; - UINT otmMacLineGap; - UINT otmusMinimumPPEM; - POINT otmptSubscriptSize; - POINT otmptSubscriptOffset; - POINT otmptSuperscriptSize; - POINT otmptSuperscriptOffset; - UINT otmsStrikeoutSize; - int otmsStrikeoutPosition; - int otmsUnderscoreSize; - int otmsUnderscorePosition; - PSTR otmpFamilyName; - PSTR otmpFaceName; - PSTR otmpStyleName; - PSTR otmpFullName; - } OUTLINETEXTMETRICW,*POUTLINETEXTMETRICW,*NPOUTLINETEXTMETRICW,*LPOUTLINETEXTMETRICW; -#ifdef UNICODE - typedef OUTLINETEXTMETRICW OUTLINETEXTMETRIC; - typedef POUTLINETEXTMETRICW POUTLINETEXTMETRIC; - typedef NPOUTLINETEXTMETRICW NPOUTLINETEXTMETRIC; - typedef LPOUTLINETEXTMETRICW LPOUTLINETEXTMETRIC; -#else - typedef OUTLINETEXTMETRICA OUTLINETEXTMETRIC; - typedef POUTLINETEXTMETRICA POUTLINETEXTMETRIC; - typedef NPOUTLINETEXTMETRICA NPOUTLINETEXTMETRIC; - typedef LPOUTLINETEXTMETRICA LPOUTLINETEXTMETRIC; -#endif -#endif - - typedef struct tagPOLYTEXTA { - int x; - int y; - UINT n; - LPCSTR lpstr; - UINT uiFlags; - RECT rcl; - int *pdx; - } POLYTEXTA,*PPOLYTEXTA,*NPPOLYTEXTA,*LPPOLYTEXTA; - - typedef struct tagPOLYTEXTW { - int x; - int y; - UINT n; - LPCWSTR lpstr; - UINT uiFlags; - RECT rcl; - int *pdx; - } POLYTEXTW,*PPOLYTEXTW,*NPPOLYTEXTW,*LPPOLYTEXTW; -#ifdef UNICODE - typedef POLYTEXTW POLYTEXT; - typedef PPOLYTEXTW PPOLYTEXT; - typedef NPPOLYTEXTW NPPOLYTEXT; - typedef LPPOLYTEXTW LPPOLYTEXT; -#else - typedef POLYTEXTA POLYTEXT; - typedef PPOLYTEXTA PPOLYTEXT; - typedef NPPOLYTEXTA NPPOLYTEXT; - typedef LPPOLYTEXTA LPPOLYTEXT; -#endif - - typedef struct _FIXED { - WORD fract; - short value; - } FIXED; - - typedef struct _MAT2 { - FIXED eM11; - FIXED eM12; - FIXED eM21; - FIXED eM22; - } MAT2,*LPMAT2; - - typedef struct _GLYPHMETRICS { - UINT gmBlackBoxX; - UINT gmBlackBoxY; - POINT gmptGlyphOrigin; - short gmCellIncX; - short gmCellIncY; - } GLYPHMETRICS,*LPGLYPHMETRICS; - -#define GGO_METRICS 0 -#define GGO_BITMAP 1 -#define GGO_NATIVE 2 -#define GGO_BEZIER 3 - -#define GGO_GRAY2_BITMAP 4 -#define GGO_GRAY4_BITMAP 5 -#define GGO_GRAY8_BITMAP 6 -#define GGO_GLYPH_INDEX 0x0080 -#define GGO_UNHINTED 0x0100 - -#define TT_POLYGON_TYPE 24 - -#define TT_PRIM_LINE 1 -#define TT_PRIM_QSPLINE 2 -#define TT_PRIM_CSPLINE 3 - - typedef struct tagPOINTFX { - FIXED x; - FIXED y; - } POINTFX,*LPPOINTFX; - - typedef struct tagTTPOLYCURVE { - WORD wType; - WORD cpfx; - POINTFX apfx[1]; - } TTPOLYCURVE,*LPTTPOLYCURVE; - - typedef struct tagTTPOLYGONHEADER { - DWORD cb; - DWORD dwType; - POINTFX pfxStart; - } TTPOLYGONHEADER,*LPTTPOLYGONHEADER; - -#define GCP_DBCS 0x0001 -#define GCP_REORDER 0x0002 -#define GCP_USEKERNING 0x0008 -#define GCP_GLYPHSHAPE 0x0010 -#define GCP_LIGATE 0x0020 - -#define GCP_DIACRITIC 0x0100 -#define GCP_KASHIDA 0x0400 -#define GCP_ERROR 0x8000 -#define FLI_MASK 0x103B - -#define GCP_JUSTIFY 0x00010000L - -#define FLI_GLYPHS 0x00040000L -#define GCP_CLASSIN 0x00080000L -#define GCP_MAXEXTENT 0x00100000L -#define GCP_JUSTIFYIN 0x00200000L -#define GCP_DISPLAYZWG 0x00400000L -#define GCP_SYMSWAPOFF 0x00800000L -#define GCP_NUMERICOVERRIDE 0x01000000L -#define GCP_NEUTRALOVERRIDE 0x02000000L -#define GCP_NUMERICSLATIN 0x04000000L -#define GCP_NUMERICSLOCAL 0x08000000L - -#define GCPCLASS_LATIN 1 -#define GCPCLASS_HEBREW 2 -#define GCPCLASS_ARABIC 2 -#define GCPCLASS_NEUTRAL 3 -#define GCPCLASS_LOCALNUMBER 4 -#define GCPCLASS_LATINNUMBER 5 -#define GCPCLASS_LATINNUMERICTERMINATOR 6 -#define GCPCLASS_LATINNUMERICSEPARATOR 7 -#define GCPCLASS_NUMERICSEPARATOR 8 -#define GCPCLASS_PREBOUNDLTR 0x80 -#define GCPCLASS_PREBOUNDRTL 0x40 -#define GCPCLASS_POSTBOUNDLTR 0x20 -#define GCPCLASS_POSTBOUNDRTL 0x10 - -#define GCPGLYPH_LINKBEFORE 0x8000 -#define GCPGLYPH_LINKAFTER 0x4000 - - typedef struct tagGCP_RESULTSA { - DWORD lStructSize; - LPSTR lpOutString; - UINT *lpOrder; - int *lpDx; - int *lpCaretPos; - LPSTR lpClass; - LPWSTR lpGlyphs; - UINT nGlyphs; - int nMaxFit; - } GCP_RESULTSA,*LPGCP_RESULTSA; - typedef struct tagGCP_RESULTSW { - DWORD lStructSize; - LPWSTR lpOutString; - UINT *lpOrder; - int *lpDx; - int *lpCaretPos; - LPSTR lpClass; - LPWSTR lpGlyphs; - UINT nGlyphs; - int nMaxFit; - } GCP_RESULTSW,*LPGCP_RESULTSW; -#ifdef UNICODE - typedef GCP_RESULTSW GCP_RESULTS; - typedef LPGCP_RESULTSW LPGCP_RESULTS; -#else - typedef GCP_RESULTSA GCP_RESULTS; - typedef LPGCP_RESULTSA LPGCP_RESULTS; -#endif - - typedef struct _RASTERIZER_STATUS { - short nSize; - short wFlags; - short nLanguageID; - } RASTERIZER_STATUS,*LPRASTERIZER_STATUS; - -#define TT_AVAILABLE 0x0001 -#define TT_ENABLED 0x0002 - - typedef struct tagPIXELFORMATDESCRIPTOR { - WORD nSize; - WORD nVersion; - DWORD dwFlags; - BYTE iPixelType; - BYTE cColorBits; - BYTE cRedBits; - BYTE cRedShift; - BYTE cGreenBits; - BYTE cGreenShift; - BYTE cBlueBits; - BYTE cBlueShift; - BYTE cAlphaBits; - BYTE cAlphaShift; - BYTE cAccumBits; - BYTE cAccumRedBits; - BYTE cAccumGreenBits; - BYTE cAccumBlueBits; - BYTE cAccumAlphaBits; - BYTE cDepthBits; - BYTE cStencilBits; - BYTE cAuxBuffers; - BYTE iLayerType; - BYTE bReserved; - DWORD dwLayerMask; - DWORD dwVisibleMask; - DWORD dwDamageMask; - } PIXELFORMATDESCRIPTOR,*PPIXELFORMATDESCRIPTOR,*LPPIXELFORMATDESCRIPTOR; - -#define PFD_TYPE_RGBA 0 -#define PFD_TYPE_COLORINDEX 1 - -#define PFD_MAIN_PLANE 0 -#define PFD_OVERLAY_PLANE 1 -#define PFD_UNDERLAY_PLANE (-1) - -#define PFD_DOUBLEBUFFER 0x00000001 -#define PFD_STEREO 0x00000002 -#define PFD_DRAW_TO_WINDOW 0x00000004 -#define PFD_DRAW_TO_BITMAP 0x00000008 -#define PFD_SUPPORT_GDI 0x00000010 -#define PFD_SUPPORT_OPENGL 0x00000020 -#define PFD_GENERIC_FORMAT 0x00000040 -#define PFD_NEED_PALETTE 0x00000080 -#define PFD_NEED_SYSTEM_PALETTE 0x00000100 -#define PFD_SWAP_EXCHANGE 0x00000200 -#define PFD_SWAP_COPY 0x00000400 -#define PFD_SWAP_LAYER_BUFFERS 0x00000800 -#define PFD_GENERIC_ACCELERATED 0x00001000 -#define PFD_SUPPORT_DIRECTDRAW 0x00002000 - -#define PFD_DEPTH_DONTCARE 0x20000000 -#define PFD_DOUBLEBUFFER_DONTCARE 0x40000000 -#define PFD_STEREO_DONTCARE 0x80000000 - -#ifndef NOTEXTMETRIC - typedef int (CALLBACK *OLDFONTENUMPROCA)(CONST LOGFONTA *,CONST TEXTMETRICA *,DWORD,LPARAM); - typedef int (CALLBACK *OLDFONTENUMPROCW)(CONST LOGFONTW *,CONST TEXTMETRICW *,DWORD,LPARAM); -#ifdef UNICODE -#define OLDFONTENUMPROC OLDFONTENUMPROCW -#else -#define OLDFONTENUMPROC OLDFONTENUMPROCA -#endif -#else - typedef int (CALLBACK *OLDFONTENUMPROCA)(CONST LOGFONTA *,CONST VOID *,DWORD,LPARAM); - typedef int (CALLBACK *OLDFONTENUMPROCW)(CONST LOGFONTW *,CONST VOID *,DWORD,LPARAM); -#ifdef UNICODE -#define OLDFONTENUMPROC OLDFONTENUMPROCW -#else -#define OLDFONTENUMPROC OLDFONTENUMPROCA -#endif -#endif - - typedef OLDFONTENUMPROCA FONTENUMPROCA; - typedef OLDFONTENUMPROCW FONTENUMPROCW; -#ifdef UNICODE - typedef FONTENUMPROCW FONTENUMPROC; -#else - typedef FONTENUMPROCA FONTENUMPROC; -#endif - - typedef int (CALLBACK *GOBJENUMPROC)(LPVOID,LPARAM); - typedef VOID (CALLBACK *LINEDDAPROC)(int,int,LPARAM); - -#ifdef UNICODE -#define AddFontResource AddFontResourceW -#define CopyMetaFile CopyMetaFileW -#define CreateDC CreateDCW -#define CreateFontIndirect CreateFontIndirectW -#define CreateFont CreateFontW -#define CreateIC CreateICW -#define CreateMetaFile CreateMetaFileW -#define CreateScalableFontResource CreateScalableFontResourceW -#else -#define AddFontResource AddFontResourceA -#define CopyMetaFile CopyMetaFileA -#define CreateDC CreateDCA -#define CreateFontIndirect CreateFontIndirectA -#define CreateFont CreateFontA -#define CreateIC CreateICA -#define CreateMetaFile CreateMetaFileA -#define CreateScalableFontResource CreateScalableFontResourceA -#endif - - WINGDIAPI int WINAPI AddFontResourceA(LPCSTR); - WINGDIAPI int WINAPI AddFontResourceW(LPCWSTR); - WINGDIAPI WINBOOL WINAPI AnimatePalette(HPALETTE hPal,UINT iStartIndex,UINT cEntries,CONST PALETTEENTRY *ppe); - WINGDIAPI WINBOOL WINAPI Arc(HDC hdc,int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4); - WINGDIAPI WINBOOL WINAPI BitBlt(HDC hdc,int x,int y,int cx,int cy,HDC hdcSrc,int x1,int y1,DWORD rop); - WINGDIAPI WINBOOL WINAPI CancelDC(HDC hdc); - WINGDIAPI WINBOOL WINAPI Chord(HDC hdc,int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4); - WINGDIAPI int WINAPI ChoosePixelFormat(HDC hdc,CONST PIXELFORMATDESCRIPTOR *ppfd); - WINGDIAPI HMETAFILE WINAPI CloseMetaFile(HDC hdc); - WINGDIAPI int WINAPI CombineRgn(HRGN hrgnDst,HRGN hrgnSrc1,HRGN hrgnSrc2,int iMode); - WINGDIAPI HMETAFILE WINAPI CopyMetaFileA(HMETAFILE,LPCSTR); - WINGDIAPI HMETAFILE WINAPI CopyMetaFileW(HMETAFILE,LPCWSTR); - WINGDIAPI HBITMAP WINAPI CreateBitmap(int nWidth,int nHeight,UINT nPlanes,UINT nBitCount,CONST VOID *lpBits); - WINGDIAPI HBITMAP WINAPI CreateBitmapIndirect(CONST BITMAP *pbm); - WINGDIAPI HBRUSH WINAPI CreateBrushIndirect(CONST LOGBRUSH *plbrush); - WINGDIAPI HBITMAP WINAPI CreateCompatibleBitmap(HDC hdc,int cx,int cy); - WINGDIAPI HBITMAP WINAPI CreateDiscardableBitmap(HDC hdc,int cx,int cy); - WINGDIAPI HDC WINAPI CreateCompatibleDC(HDC hdc); - WINGDIAPI HDC WINAPI CreateDCA(LPCSTR pwszDriver,LPCSTR pwszDevice,LPCSTR pszPort,CONST DEVMODEA *pdm); - WINGDIAPI HDC WINAPI CreateDCW(LPCWSTR pwszDriver,LPCWSTR pwszDevice,LPCWSTR pszPort,CONST DEVMODEW *pdm); - WINGDIAPI HBITMAP WINAPI CreateDIBitmap(HDC hdc,CONST BITMAPINFOHEADER *pbmih,DWORD flInit,CONST VOID *pjBits,CONST BITMAPINFO *pbmi,UINT iUsage); - WINGDIAPI HBRUSH WINAPI CreateDIBPatternBrush(HGLOBAL h,UINT iUsage); - WINGDIAPI HBRUSH WINAPI CreateDIBPatternBrushPt(CONST VOID *lpPackedDIB,UINT iUsage); - WINGDIAPI HRGN WINAPI CreateEllipticRgn(int x1,int y1,int x2,int y2); - WINGDIAPI HRGN WINAPI CreateEllipticRgnIndirect(CONST RECT *lprect); - WINGDIAPI HFONT WINAPI CreateFontIndirectA(CONST LOGFONTA *lplf); - WINGDIAPI HFONT WINAPI CreateFontIndirectW(CONST LOGFONTW *lplf); - WINGDIAPI HFONT WINAPI CreateFontA(int cHeight,int cWidth,int cEscapement,int cOrientation,int cWeight,DWORD bItalic,DWORD bUnderline,DWORD bStrikeOut,DWORD iCharSet,DWORD iOutPrecision,DWORD iClipPrecision,DWORD iQuality,DWORD iPitchAndFamily,LPCSTR pszFaceName); - WINGDIAPI HFONT WINAPI CreateFontW(int cHeight,int cWidth,int cEscapement,int cOrientation,int cWeight,DWORD bItalic,DWORD bUnderline,DWORD bStrikeOut,DWORD iCharSet,DWORD iOutPrecision,DWORD iClipPrecision,DWORD iQuality,DWORD iPitchAndFamily,LPCWSTR pszFaceName); - WINGDIAPI HBRUSH WINAPI CreateHatchBrush(int iHatch,COLORREF color); - WINGDIAPI HDC WINAPI CreateICA(LPCSTR pszDriver,LPCSTR pszDevice,LPCSTR pszPort,CONST DEVMODEA *pdm); - WINGDIAPI HDC WINAPI CreateICW(LPCWSTR pszDriver,LPCWSTR pszDevice,LPCWSTR pszPort,CONST DEVMODEW *pdm); - WINGDIAPI HDC WINAPI CreateMetaFileA(LPCSTR pszFile); - WINGDIAPI HDC WINAPI CreateMetaFileW(LPCWSTR pszFile); - WINGDIAPI HPALETTE WINAPI CreatePalette(CONST LOGPALETTE *plpal); - WINGDIAPI HPEN WINAPI CreatePen(int iStyle,int cWidth,COLORREF color); - WINGDIAPI HPEN WINAPI CreatePenIndirect(CONST LOGPEN *plpen); - WINGDIAPI HRGN WINAPI CreatePolyPolygonRgn(CONST POINT *pptl,CONST INT *pc,int cPoly,int iMode); - WINGDIAPI HBRUSH WINAPI CreatePatternBrush(HBITMAP hbm); - WINGDIAPI HRGN WINAPI CreateRectRgn(int x1,int y1,int x2,int y2); - WINGDIAPI HRGN WINAPI CreateRectRgnIndirect(CONST RECT *lprect); - WINGDIAPI HRGN WINAPI CreateRoundRectRgn(int x1,int y1,int x2,int y2,int w,int h); - WINGDIAPI WINBOOL WINAPI CreateScalableFontResourceA(DWORD fdwHidden,LPCSTR lpszFont,LPCSTR lpszFile,LPCSTR lpszPath); - WINGDIAPI WINBOOL WINAPI CreateScalableFontResourceW(DWORD fdwHidden,LPCWSTR lpszFont,LPCWSTR lpszFile,LPCWSTR lpszPath); - WINGDIAPI HBRUSH WINAPI CreateSolidBrush(COLORREF color); - WINGDIAPI WINBOOL WINAPI DeleteDC(HDC hdc); - WINGDIAPI WINBOOL WINAPI DeleteMetaFile(HMETAFILE hmf); - WINGDIAPI WINBOOL WINAPI DeleteObject(HGDIOBJ ho); - WINGDIAPI int WINAPI DescribePixelFormat(HDC hdc,int iPixelFormat,UINT nBytes,LPPIXELFORMATDESCRIPTOR ppfd); - - typedef UINT (CALLBACK *LPFNDEVMODE)(HWND,HMODULE,LPDEVMODE,LPSTR,LPSTR,LPDEVMODE,LPSTR,UINT); - typedef DWORD (CALLBACK *LPFNDEVCAPS)(LPSTR,LPSTR,UINT,LPSTR,LPDEVMODE); - -#define DM_UPDATE 1 -#define DM_COPY 2 -#define DM_PROMPT 4 -#define DM_MODIFY 8 - -#define DM_IN_BUFFER DM_MODIFY -#define DM_IN_PROMPT DM_PROMPT -#define DM_OUT_BUFFER DM_COPY -#define DM_OUT_DEFAULT DM_UPDATE - -#define DC_FIELDS 1 -#define DC_PAPERS 2 -#define DC_PAPERSIZE 3 -#define DC_MINEXTENT 4 -#define DC_MAXEXTENT 5 -#define DC_BINS 6 -#define DC_DUPLEX 7 -#define DC_SIZE 8 -#define DC_EXTRA 9 -#define DC_VERSION 10 -#define DC_DRIVER 11 -#define DC_BINNAMES 12 -#define DC_ENUMRESOLUTIONS 13 -#define DC_FILEDEPENDENCIES 14 -#define DC_TRUETYPE 15 -#define DC_PAPERNAMES 16 -#define DC_ORIENTATION 17 -#define DC_COPIES 18 -#define DC_BINADJUST 19 -#define DC_EMF_COMPLIANT 20 -#define DC_DATATYPE_PRODUCED 21 -#define DC_COLLATE 22 -#define DC_MANUFACTURER 23 -#define DC_MODEL 24 -#define DC_PERSONALITY 25 -#define DC_PRINTRATE 26 -#define DC_PRINTRATEUNIT 27 -#define PRINTRATEUNIT_PPM 1 -#define PRINTRATEUNIT_CPS 2 -#define PRINTRATEUNIT_LPM 3 -#define PRINTRATEUNIT_IPM 4 -#define DC_PRINTERMEM 28 -#define DC_MEDIAREADY 29 -#define DC_STAPLE 30 -#define DC_PRINTRATEPPM 31 -#define DC_COLORDEVICE 32 -#define DC_NUP 33 -#define DC_MEDIATYPENAMES 34 -#define DC_MEDIATYPES 35 - -#define DCTT_BITMAP 0x0000001L -#define DCTT_DOWNLOAD 0x0000002L -#define DCTT_SUBDEV 0x0000004L -#define DCTT_DOWNLOAD_OUTLINE 0x0000008L - -#define DCBA_FACEUPNONE 0x0000 -#define DCBA_FACEUPCENTER 0x0001 -#define DCBA_FACEUPLEFT 0x0002 -#define DCBA_FACEUPRIGHT 0x0003 -#define DCBA_FACEDOWNNONE 0x0100 -#define DCBA_FACEDOWNCENTER 0x0101 -#define DCBA_FACEDOWNLEFT 0x0102 -#define DCBA_FACEDOWNRIGHT 0x0103 - -#ifdef UNICODE -#define DeviceCapabilities DeviceCapabilitiesW -#define EnumFontFamiliesEx EnumFontFamiliesExW -#define EnumFontFamilies EnumFontFamiliesW -#define EnumFonts EnumFontsW -#define GetCharWidth GetCharWidthW -#define GetCharWidth32 GetCharWidth32W -#define GetCharWidthFloat GetCharWidthFloatW -#define GetCharABCWidths GetCharABCWidthsW -#define GetCharABCWidthsFloat GetCharABCWidthsFloatW -#define GetGlyphOutline GetGlyphOutlineW -#define GetMetaFile GetMetaFileW -#else -#define DeviceCapabilities DeviceCapabilitiesA -#define EnumFontFamiliesEx EnumFontFamiliesExA -#define EnumFontFamilies EnumFontFamiliesA -#define EnumFonts EnumFontsA -#define GetCharWidth GetCharWidthA -#define GetCharWidth32 GetCharWidth32A -#define GetCharWidthFloat GetCharWidthFloatA -#define GetCharABCWidths GetCharABCWidthsA -#define GetCharABCWidthsFloat GetCharABCWidthsFloatA -#define GetGlyphOutline GetGlyphOutlineA -#define GetMetaFile GetMetaFileA -#endif - - WINSPOOLAPI int WINAPI DeviceCapabilitiesA(LPCSTR pDevice,LPCSTR pPort,WORD fwCapability,LPSTR pOutput,CONST DEVMODEA *pDevMode); - WINSPOOLAPI int WINAPI DeviceCapabilitiesW(LPCWSTR pDevice,LPCWSTR pPort,WORD fwCapability,LPWSTR pOutput,CONST DEVMODEW *pDevMode); - WINGDIAPI int WINAPI DrawEscape(HDC hdc,int iEscape,int cjIn,LPCSTR lpIn); - WINGDIAPI WINBOOL WINAPI Ellipse(HDC hdc,int left,int top,int right,int bottom); - WINGDIAPI int WINAPI EnumFontFamiliesExA(HDC hdc,LPLOGFONTA lpLogfont,FONTENUMPROCA lpProc,LPARAM lParam,DWORD dwFlags); - WINGDIAPI int WINAPI EnumFontFamiliesExW(HDC hdc,LPLOGFONTW lpLogfont,FONTENUMPROCW lpProc,LPARAM lParam,DWORD dwFlags); - WINGDIAPI int WINAPI EnumFontFamiliesA(HDC hdc,LPCSTR lpLogfont,FONTENUMPROCA lpProc,LPARAM lParam); - WINGDIAPI int WINAPI EnumFontFamiliesW(HDC hdc,LPCWSTR lpLogfont,FONTENUMPROCW lpProc,LPARAM lParam); - WINGDIAPI int WINAPI EnumFontsA(HDC hdc,LPCSTR lpLogfont,FONTENUMPROCA lpProc,LPARAM lParam); - WINGDIAPI int WINAPI EnumFontsW(HDC hdc,LPCWSTR lpLogfont,FONTENUMPROCW lpProc,LPARAM lParam); - WINGDIAPI int WINAPI EnumObjects(HDC hdc,int nType,GOBJENUMPROC lpFunc,LPARAM lParam); - WINGDIAPI WINBOOL WINAPI EqualRgn(HRGN hrgn1,HRGN hrgn2); - WINGDIAPI int WINAPI Escape(HDC hdc,int iEscape,int cjIn,LPCSTR pvIn,LPVOID pvOut); - WINGDIAPI int WINAPI ExtEscape(HDC hdc,int iEscape,int cjInput,LPCSTR lpInData,int cjOutput,LPSTR lpOutData); - WINGDIAPI int WINAPI ExcludeClipRect(HDC hdc,int left,int top,int right,int bottom); - WINGDIAPI HRGN WINAPI ExtCreateRegion(CONST XFORM *lpx,DWORD nCount,CONST RGNDATA *lpData); - WINGDIAPI WINBOOL WINAPI ExtFloodFill(HDC hdc,int x,int y,COLORREF color,UINT type); - WINGDIAPI WINBOOL WINAPI FillRgn(HDC hdc,HRGN hrgn,HBRUSH hbr); - WINGDIAPI WINBOOL WINAPI FloodFill(HDC hdc,int x,int y,COLORREF color); - WINGDIAPI WINBOOL WINAPI FrameRgn(HDC hdc,HRGN hrgn,HBRUSH hbr,int w,int h); - WINGDIAPI int WINAPI GetROP2(HDC hdc); - WINGDIAPI WINBOOL WINAPI GetAspectRatioFilterEx(HDC hdc,LPSIZE lpsize); - WINGDIAPI COLORREF WINAPI GetBkColor(HDC hdc); - WINGDIAPI COLORREF WINAPI GetDCBrushColor(HDC hdc); - WINGDIAPI COLORREF WINAPI GetDCPenColor(HDC hdc); - WINGDIAPI int WINAPI GetBkMode(HDC hdc); - WINGDIAPI LONG WINAPI GetBitmapBits(HBITMAP hbit,LONG cb,LPVOID lpvBits); - WINGDIAPI WINBOOL WINAPI GetBitmapDimensionEx(HBITMAP hbit,LPSIZE lpsize); - WINGDIAPI UINT WINAPI GetBoundsRect(HDC hdc,LPRECT lprect,UINT flags); - WINGDIAPI WINBOOL WINAPI GetBrushOrgEx(HDC hdc,LPPOINT lppt); - WINGDIAPI WINBOOL WINAPI GetCharWidthA(HDC hdc,UINT iFirst,UINT iLast,LPINT lpBuffer); - WINGDIAPI WINBOOL WINAPI GetCharWidthW(HDC hdc,UINT iFirst,UINT iLast,LPINT lpBuffer); - WINGDIAPI WINBOOL WINAPI GetCharWidth32A(HDC hdc,UINT iFirst,UINT iLast,LPINT lpBuffer); - WINGDIAPI WINBOOL WINAPI GetCharWidth32W(HDC hdc,UINT iFirst,UINT iLast,LPINT lpBuffer); - WINGDIAPI WINBOOL WINAPI GetCharWidthFloatA(HDC hdc,UINT iFirst,UINT iLast,PFLOAT lpBuffer); - WINGDIAPI WINBOOL WINAPI GetCharWidthFloatW(HDC hdc,UINT iFirst,UINT iLast,PFLOAT lpBuffer); - WINGDIAPI WINBOOL WINAPI GetCharABCWidthsA(HDC hdc,UINT wFirst,UINT wLast,LPABC lpABC); - WINGDIAPI WINBOOL WINAPI GetCharABCWidthsW(HDC hdc,UINT wFirst,UINT wLast,LPABC lpABC); - WINGDIAPI WINBOOL WINAPI GetCharABCWidthsFloatA(HDC hdc,UINT iFirst,UINT iLast,LPABCFLOAT lpABC); - WINGDIAPI WINBOOL WINAPI GetCharABCWidthsFloatW(HDC hdc,UINT iFirst,UINT iLast,LPABCFLOAT lpABC); - WINGDIAPI int WINAPI GetClipBox(HDC hdc,LPRECT lprect); - WINGDIAPI int WINAPI GetClipRgn(HDC hdc,HRGN hrgn); - WINGDIAPI int WINAPI GetMetaRgn(HDC hdc,HRGN hrgn); - WINGDIAPI HGDIOBJ WINAPI GetCurrentObject(HDC hdc,UINT type); - WINGDIAPI WINBOOL WINAPI GetCurrentPositionEx(HDC hdc,LPPOINT lppt); - WINGDIAPI int WINAPI GetDeviceCaps(HDC hdc,int index); - WINGDIAPI int WINAPI GetDIBits(HDC hdc,HBITMAP hbm,UINT start,UINT cLines,LPVOID lpvBits,LPBITMAPINFO lpbmi,UINT usage); - WINGDIAPI DWORD WINAPI GetFontData (HDC hdc,DWORD dwTable,DWORD dwOffset,PVOID pvBuffer,DWORD cjBuffer); - WINGDIAPI DWORD WINAPI GetGlyphOutlineA(HDC hdc,UINT uChar,UINT fuFormat,LPGLYPHMETRICS lpgm,DWORD cjBuffer,LPVOID pvBuffer,CONST MAT2 *lpmat2); - WINGDIAPI DWORD WINAPI GetGlyphOutlineW(HDC hdc,UINT uChar,UINT fuFormat,LPGLYPHMETRICS lpgm,DWORD cjBuffer,LPVOID pvBuffer,CONST MAT2 *lpmat2); - WINGDIAPI int WINAPI GetGraphicsMode(HDC hdc); - WINGDIAPI int WINAPI GetMapMode(HDC hdc); - WINGDIAPI UINT WINAPI GetMetaFileBitsEx(HMETAFILE hMF,UINT cbBuffer,LPVOID lpData); - WINGDIAPI HMETAFILE WINAPI GetMetaFileA(LPCSTR lpName); - WINGDIAPI HMETAFILE WINAPI GetMetaFileW(LPCWSTR lpName); - WINGDIAPI COLORREF WINAPI GetNearestColor(HDC hdc,COLORREF color); - WINGDIAPI UINT WINAPI GetNearestPaletteIndex(HPALETTE h,COLORREF color); - WINGDIAPI DWORD WINAPI GetObjectType(HGDIOBJ h); - -#ifndef NOTEXTMETRIC -#ifdef UNICODE -#define GetOutlineTextMetrics GetOutlineTextMetricsW -#else -#define GetOutlineTextMetrics GetOutlineTextMetricsA -#endif - - WINGDIAPI UINT WINAPI GetOutlineTextMetricsA(HDC hdc,UINT cjCopy,LPOUTLINETEXTMETRICA potm); - WINGDIAPI UINT WINAPI GetOutlineTextMetricsW(HDC hdc,UINT cjCopy,LPOUTLINETEXTMETRICW potm); -#endif - -#ifdef UNICODE -#define GetTextExtentPoint GetTextExtentPointW -#define GetTextExtentPoint32 GetTextExtentPoint32W -#define GetTextExtentExPoint GetTextExtentExPointW -#define GetCharacterPlacement GetCharacterPlacementW -#else -#define GetTextExtentPoint GetTextExtentPointA -#define GetTextExtentPoint32 GetTextExtentPoint32A -#define GetTextExtentExPoint GetTextExtentExPointA -#define GetCharacterPlacement GetCharacterPlacementA -#endif - - WINGDIAPI UINT WINAPI GetPaletteEntries(HPALETTE hpal,UINT iStart,UINT cEntries,LPPALETTEENTRY pPalEntries); - WINGDIAPI COLORREF WINAPI GetPixel(HDC hdc,int x,int y); - WINGDIAPI int WINAPI GetPixelFormat(HDC hdc); - WINGDIAPI int WINAPI GetPolyFillMode(HDC hdc); - WINGDIAPI WINBOOL WINAPI GetRasterizerCaps(LPRASTERIZER_STATUS lpraststat,UINT cjBytes); - WINGDIAPI int WINAPI GetRandomRgn (HDC hdc,HRGN hrgn,INT i); - WINGDIAPI DWORD WINAPI GetRegionData(HRGN hrgn,DWORD nCount,LPRGNDATA lpRgnData); - WINGDIAPI int WINAPI GetRgnBox(HRGN hrgn,LPRECT lprc); - WINGDIAPI HGDIOBJ WINAPI GetStockObject(int i); - WINGDIAPI int WINAPI GetStretchBltMode(HDC hdc); - WINGDIAPI UINT WINAPI GetSystemPaletteEntries(HDC hdc,UINT iStart,UINT cEntries,LPPALETTEENTRY pPalEntries); - WINGDIAPI UINT WINAPI GetSystemPaletteUse(HDC hdc); - WINGDIAPI int WINAPI GetTextCharacterExtra(HDC hdc); - WINGDIAPI UINT WINAPI GetTextAlign(HDC hdc); - WINGDIAPI COLORREF WINAPI GetTextColor(HDC hdc); - WINGDIAPI WINBOOL WINAPI GetTextExtentPointA(HDC hdc,LPCSTR lpString,int c,LPSIZE lpsz); - WINGDIAPI WINBOOL WINAPI GetTextExtentPointW(HDC hdc,LPCWSTR lpString,int c,LPSIZE lpsz); - WINGDIAPI WINBOOL WINAPI GetTextExtentPoint32A(HDC hdc,LPCSTR lpString,int c,LPSIZE psizl); - WINGDIAPI WINBOOL WINAPI GetTextExtentPoint32W(HDC hdc,LPCWSTR lpString,int c,LPSIZE psizl); - WINGDIAPI WINBOOL WINAPI GetTextExtentExPointA(HDC hdc,LPCSTR lpszString,int cchString,int nMaxExtent,LPINT lpnFit,LPINT lpnDx,LPSIZE lpSize); - WINGDIAPI WINBOOL WINAPI GetTextExtentExPointW(HDC hdc,LPCWSTR lpszString,int cchString,int nMaxExtent,LPINT lpnFit,LPINT lpnDx,LPSIZE lpSize); - WINGDIAPI int WINAPI GetTextCharset(HDC hdc); - WINGDIAPI int WINAPI GetTextCharsetInfo(HDC hdc,LPFONTSIGNATURE lpSig,DWORD dwFlags); - WINGDIAPI WINBOOL WINAPI TranslateCharsetInfo(DWORD *lpSrc,LPCHARSETINFO lpCs,DWORD dwFlags); - WINGDIAPI DWORD WINAPI GetFontLanguageInfo(HDC hdc); - WINGDIAPI DWORD WINAPI GetCharacterPlacementA(HDC hdc,LPCSTR lpString,int nCount,int nMexExtent,LPGCP_RESULTSA lpResults,DWORD dwFlags); - WINGDIAPI DWORD WINAPI GetCharacterPlacementW(HDC hdc,LPCWSTR lpString,int nCount,int nMexExtent,LPGCP_RESULTSW lpResults,DWORD dwFlags); - - typedef struct tagWCRANGE { - WCHAR wcLow; - USHORT cGlyphs; - } WCRANGE,*PWCRANGE,*LPWCRANGE; - - typedef struct tagGLYPHSET { - DWORD cbThis; - DWORD flAccel; - DWORD cGlyphsSupported; - DWORD cRanges; - WCRANGE ranges[1]; - } GLYPHSET,*PGLYPHSET,*LPGLYPHSET; - -#define GS_8BIT_INDICES 0x00000001 - -#define GGI_MARK_NONEXISTING_GLYPHS 0X0001 - -#ifdef UNICODE -#define GetGlyphIndices GetGlyphIndicesW -#else -#define GetGlyphIndices GetGlyphIndicesA -#endif - - WINGDIAPI DWORD WINAPI GetFontUnicodeRanges(HDC hdc,LPGLYPHSET lpgs); - WINGDIAPI DWORD WINAPI GetGlyphIndicesA(HDC hdc,LPCSTR lpstr,int c,LPWORD pgi,DWORD fl); - WINGDIAPI DWORD WINAPI GetGlyphIndicesW(HDC hdc,LPCWSTR lpstr,int c,LPWORD pgi,DWORD fl); - WINGDIAPI WINBOOL WINAPI GetTextExtentPointI(HDC hdc,LPWORD pgiIn,int cgi,LPSIZE psize); - WINGDIAPI WINBOOL WINAPI GetTextExtentExPointI (HDC hdc,LPWORD lpwszString,int cwchString,int nMaxExtent,LPINT lpnFit,LPINT lpnDx,LPSIZE lpSize); - WINGDIAPI WINBOOL WINAPI GetCharWidthI(HDC hdc,UINT giFirst,UINT cgi,LPWORD pgi,LPINT piWidths); - WINGDIAPI WINBOOL WINAPI GetCharABCWidthsI(HDC hdc,UINT giFirst,UINT cgi,LPWORD pgi,LPABC pabc); - -#define STAMP_DESIGNVECTOR (0x8000000 + 'd' + ('v' << 8)) -#define STAMP_AXESLIST (0x8000000 + 'a' + ('l' << 8)) -#define MM_MAX_NUMAXES 16 - - typedef struct tagDESIGNVECTOR { - DWORD dvReserved; - DWORD dvNumAxes; - LONG dvValues[MM_MAX_NUMAXES]; - } DESIGNVECTOR,*PDESIGNVECTOR,*LPDESIGNVECTOR; - -#ifdef UNICODE -#define AddFontResourceEx AddFontResourceExW -#define RemoveFontResourceEx RemoveFontResourceExW -#else -#define AddFontResourceEx AddFontResourceExA -#define RemoveFontResourceEx RemoveFontResourceExA -#endif - - WINGDIAPI int WINAPI AddFontResourceExA(LPCSTR name,DWORD fl,PVOID res); - WINGDIAPI int WINAPI AddFontResourceExW(LPCWSTR name,DWORD fl,PVOID res); - WINGDIAPI WINBOOL WINAPI RemoveFontResourceExA(LPCSTR name,DWORD fl,PVOID pdv); - WINGDIAPI WINBOOL WINAPI RemoveFontResourceExW(LPCWSTR name,DWORD fl,PVOID pdv); - WINGDIAPI HANDLE WINAPI AddFontMemResourceEx(PVOID pFileView,DWORD cjSize,PVOID pvResrved,DWORD *pNumFonts); - WINGDIAPI WINBOOL WINAPI RemoveFontMemResourceEx(HANDLE h); - -#define FR_PRIVATE 0x10 -#define FR_NOT_ENUM 0x20 - -#define MM_MAX_AXES_NAMELEN 16 - - typedef struct tagAXISINFOA { - LONG axMinValue; - LONG axMaxValue; - BYTE axAxisName[MM_MAX_AXES_NAMELEN]; - } AXISINFOA,*PAXISINFOA,*LPAXISINFOA; - - typedef struct tagAXISINFOW { - LONG axMinValue; - LONG axMaxValue; - WCHAR axAxisName[MM_MAX_AXES_NAMELEN]; - } AXISINFOW,*PAXISINFOW,*LPAXISINFOW; -#ifdef UNICODE - typedef AXISINFOW AXISINFO; - typedef PAXISINFOW PAXISINFO; - typedef LPAXISINFOW LPAXISINFO; -#else - typedef AXISINFOA AXISINFO; - typedef PAXISINFOA PAXISINFO; - typedef LPAXISINFOA LPAXISINFO; -#endif - - typedef struct tagAXESLISTA { - DWORD axlReserved; - DWORD axlNumAxes; - AXISINFOA axlAxisInfo[MM_MAX_NUMAXES]; - } AXESLISTA,*PAXESLISTA,*LPAXESLISTA; - - typedef struct tagAXESLISTW { - DWORD axlReserved; - DWORD axlNumAxes; - AXISINFOW axlAxisInfo[MM_MAX_NUMAXES]; - } AXESLISTW,*PAXESLISTW,*LPAXESLISTW; -#ifdef UNICODE - typedef AXESLISTW AXESLIST; - typedef PAXESLISTW PAXESLIST; - typedef LPAXESLISTW LPAXESLIST; -#else - typedef AXESLISTA AXESLIST; - typedef PAXESLISTA PAXESLIST; - typedef LPAXESLISTA LPAXESLIST; -#endif - - typedef struct tagENUMLOGFONTEXDVA { - ENUMLOGFONTEXA elfEnumLogfontEx; - DESIGNVECTOR elfDesignVector; - } ENUMLOGFONTEXDVA,*PENUMLOGFONTEXDVA,*LPENUMLOGFONTEXDVA; - - typedef struct tagENUMLOGFONTEXDVW { - ENUMLOGFONTEXW elfEnumLogfontEx; - DESIGNVECTOR elfDesignVector; - } ENUMLOGFONTEXDVW,*PENUMLOGFONTEXDVW,*LPENUMLOGFONTEXDVW; -#ifdef UNICODE - typedef ENUMLOGFONTEXDVW ENUMLOGFONTEXDV; - typedef PENUMLOGFONTEXDVW PENUMLOGFONTEXDV; - typedef LPENUMLOGFONTEXDVW LPENUMLOGFONTEXDV; -#else - typedef ENUMLOGFONTEXDVA ENUMLOGFONTEXDV; - typedef PENUMLOGFONTEXDVA PENUMLOGFONTEXDV; - typedef LPENUMLOGFONTEXDVA LPENUMLOGFONTEXDV; -#endif - -#ifdef UNICODE -#define CreateFontIndirectEx CreateFontIndirectExW -#else -#define CreateFontIndirectEx CreateFontIndirectExA -#endif - - WINGDIAPI HFONT WINAPI CreateFontIndirectExA(CONST ENUMLOGFONTEXDVA *); - WINGDIAPI HFONT WINAPI CreateFontIndirectExW(CONST ENUMLOGFONTEXDVW *); - -#ifndef NOTEXTMETRIC - typedef struct tagENUMTEXTMETRICA { - NEWTEXTMETRICEXA etmNewTextMetricEx; - AXESLISTA etmAxesList; - } ENUMTEXTMETRICA,*PENUMTEXTMETRICA,*LPENUMTEXTMETRICA; - typedef struct tagENUMTEXTMETRICW - { - NEWTEXTMETRICEXW etmNewTextMetricEx; - AXESLISTW etmAxesList; - } ENUMTEXTMETRICW,*PENUMTEXTMETRICW,*LPENUMTEXTMETRICW; -#ifdef UNICODE - typedef ENUMTEXTMETRICW ENUMTEXTMETRIC; - typedef PENUMTEXTMETRICW PENUMTEXTMETRIC; - typedef LPENUMTEXTMETRICW LPENUMTEXTMETRIC; -#else - typedef ENUMTEXTMETRICA ENUMTEXTMETRIC; - typedef PENUMTEXTMETRICA PENUMTEXTMETRIC; - typedef LPENUMTEXTMETRICA LPENUMTEXTMETRIC; -#endif -#endif - -#ifdef UNICODE -#define ResetDC ResetDCW -#define RemoveFontResource RemoveFontResourceW -#else -#define ResetDC ResetDCA -#define RemoveFontResource RemoveFontResourceA -#endif - - WINGDIAPI WINBOOL WINAPI GetViewportExtEx(HDC hdc,LPSIZE lpsize); - WINGDIAPI WINBOOL WINAPI GetViewportOrgEx(HDC hdc,LPPOINT lppoint); - WINGDIAPI WINBOOL WINAPI GetWindowExtEx(HDC hdc,LPSIZE lpsize); - WINGDIAPI WINBOOL WINAPI GetWindowOrgEx(HDC hdc,LPPOINT lppoint); - WINGDIAPI int WINAPI IntersectClipRect(HDC hdc,int left,int top,int right,int bottom); - WINGDIAPI WINBOOL WINAPI InvertRgn(HDC hdc,HRGN hrgn); - WINGDIAPI WINBOOL WINAPI LineDDA(int xStart,int yStart,int xEnd,int yEnd,LINEDDAPROC lpProc,LPARAM data); - WINGDIAPI WINBOOL WINAPI LineTo(HDC hdc,int x,int y); - WINGDIAPI WINBOOL WINAPI MaskBlt(HDC hdcDest,int xDest,int yDest,int width,int height,HDC hdcSrc,int xSrc,int ySrc,HBITMAP hbmMask,int xMask,int yMask,DWORD rop); - WINGDIAPI WINBOOL WINAPI PlgBlt(HDC hdcDest,CONST POINT *lpPoint,HDC hdcSrc,int xSrc,int ySrc,int width,int height,HBITMAP hbmMask,int xMask,int yMask); - WINGDIAPI int WINAPI OffsetClipRgn(HDC hdc,int x,int y); - WINGDIAPI int WINAPI OffsetRgn(HRGN hrgn,int x,int y); - WINGDIAPI WINBOOL WINAPI PatBlt(HDC hdc,int x,int y,int w,int h,DWORD rop); - WINGDIAPI WINBOOL WINAPI Pie(HDC hdc,int left,int top,int right,int bottom,int xr1,int yr1,int xr2,int yr2); - WINGDIAPI WINBOOL WINAPI PlayMetaFile(HDC hdc,HMETAFILE hmf); - WINGDIAPI WINBOOL WINAPI PaintRgn(HDC hdc,HRGN hrgn); - WINGDIAPI WINBOOL WINAPI PolyPolygon(HDC hdc,CONST POINT *apt,CONST INT *asz,int csz); - WINGDIAPI WINBOOL WINAPI PtInRegion(HRGN hrgn,int x,int y); - WINGDIAPI WINBOOL WINAPI PtVisible(HDC hdc,int x,int y); - WINGDIAPI WINBOOL WINAPI RectInRegion(HRGN hrgn,CONST RECT *lprect); - WINGDIAPI WINBOOL WINAPI RectVisible(HDC hdc,CONST RECT *lprect); - WINGDIAPI WINBOOL WINAPI Rectangle(HDC hdc,int left,int top,int right,int bottom); - WINGDIAPI WINBOOL WINAPI RestoreDC(HDC hdc,int nSavedDC); - WINGDIAPI HDC WINAPI ResetDCA(HDC hdc,CONST DEVMODEA *lpdm); - WINGDIAPI HDC WINAPI ResetDCW(HDC hdc,CONST DEVMODEW *lpdm); - WINGDIAPI UINT WINAPI RealizePalette(HDC hdc); - WINGDIAPI WINBOOL WINAPI RemoveFontResourceA(LPCSTR lpFileName); - WINGDIAPI WINBOOL WINAPI RemoveFontResourceW(LPCWSTR lpFileName); - WINGDIAPI WINBOOL WINAPI RoundRect(HDC hdc,int left,int top,int right,int bottom,int width,int height); - WINGDIAPI WINBOOL WINAPI ResizePalette(HPALETTE hpal,UINT n); - WINGDIAPI int WINAPI SaveDC(HDC hdc); - WINGDIAPI int WINAPI SelectClipRgn(HDC hdc,HRGN hrgn); - WINGDIAPI int WINAPI ExtSelectClipRgn(HDC hdc,HRGN hrgn,int mode); - WINGDIAPI int WINAPI SetMetaRgn(HDC hdc); - WINGDIAPI HGDIOBJ WINAPI SelectObject(HDC hdc,HGDIOBJ h); - WINGDIAPI HPALETTE WINAPI SelectPalette(HDC hdc,HPALETTE hPal,WINBOOL bForceBkgd); - WINGDIAPI COLORREF WINAPI SetBkColor(HDC hdc,COLORREF color); - WINGDIAPI COLORREF WINAPI SetDCBrushColor(HDC hdc,COLORREF color); - WINGDIAPI COLORREF WINAPI SetDCPenColor(HDC hdc,COLORREF color); - WINGDIAPI int WINAPI SetBkMode(HDC hdc,int mode); - WINGDIAPI LONG WINAPI SetBitmapBits(HBITMAP hbm,DWORD cb,CONST VOID *pvBits); - WINGDIAPI UINT WINAPI SetBoundsRect(HDC hdc,CONST RECT *lprect,UINT flags); - WINGDIAPI int WINAPI SetDIBits(HDC hdc,HBITMAP hbm,UINT start,UINT cLines,CONST VOID *lpBits,CONST BITMAPINFO *lpbmi,UINT ColorUse); - WINGDIAPI int WINAPI SetDIBitsToDevice(HDC hdc,int xDest,int yDest,DWORD w,DWORD h,int xSrc,int ySrc,UINT StartScan,UINT cLines,CONST VOID *lpvBits,CONST BITMAPINFO *lpbmi,UINT ColorUse); - WINGDIAPI DWORD WINAPI SetMapperFlags(HDC hdc,DWORD flags); - WINGDIAPI int WINAPI SetGraphicsMode(HDC hdc,int iMode); - WINGDIAPI int WINAPI SetMapMode(HDC hdc,int iMode); - WINGDIAPI DWORD WINAPI SetLayout(HDC hdc,DWORD l); - WINGDIAPI DWORD WINAPI GetLayout(HDC hdc); - WINGDIAPI HMETAFILE WINAPI SetMetaFileBitsEx(UINT cbBuffer,CONST BYTE *lpData); - WINGDIAPI UINT WINAPI SetPaletteEntries(HPALETTE hpal,UINT iStart,UINT cEntries,CONST PALETTEENTRY *pPalEntries); - WINGDIAPI COLORREF WINAPI SetPixel(HDC hdc,int x,int y,COLORREF color); - WINGDIAPI WINBOOL WINAPI SetPixelV(HDC hdc,int x,int y,COLORREF color); - WINGDIAPI WINBOOL WINAPI SetPixelFormat(HDC hdc,int format,CONST PIXELFORMATDESCRIPTOR *ppfd); - WINGDIAPI int WINAPI SetPolyFillMode(HDC hdc,int mode); - WINGDIAPI WINBOOL WINAPI StretchBlt(HDC hdcDest,int xDest,int yDest,int wDest,int hDest,HDC hdcSrc,int xSrc,int ySrc,int wSrc,int hSrc,DWORD rop); - WINGDIAPI WINBOOL WINAPI SetRectRgn(HRGN hrgn,int left,int top,int right,int bottom); - WINGDIAPI int WINAPI StretchDIBits(HDC hdc,int xDest,int yDest,int DestWidth,int DestHeight,int xSrc,int ySrc,int SrcWidth,int SrcHeight,CONST VOID *lpBits,CONST BITMAPINFO *lpbmi,UINT iUsage,DWORD rop); - WINGDIAPI int WINAPI SetROP2(HDC hdc,int rop2); - WINGDIAPI int WINAPI SetStretchBltMode(HDC hdc,int mode); - WINGDIAPI UINT WINAPI SetSystemPaletteUse(HDC hdc,UINT use); - WINGDIAPI int WINAPI SetTextCharacterExtra(HDC hdc,int extra); - WINGDIAPI COLORREF WINAPI SetTextColor(HDC hdc,COLORREF color); - WINGDIAPI UINT WINAPI SetTextAlign(HDC hdc,UINT align); - WINGDIAPI WINBOOL WINAPI SetTextJustification(HDC hdc,int extra,int count); - WINGDIAPI WINBOOL WINAPI UpdateColors(HDC hdc); - - typedef USHORT COLOR16; - - typedef struct _TRIVERTEX { - LONG x; - LONG y; - COLOR16 Red; - COLOR16 Green; - COLOR16 Blue; - COLOR16 Alpha; - } TRIVERTEX,*PTRIVERTEX,*LPTRIVERTEX; - - typedef struct _GRADIENT_TRIANGLE { - ULONG Vertex1; - ULONG Vertex2; - ULONG Vertex3; - } GRADIENT_TRIANGLE,*PGRADIENT_TRIANGLE,*LPGRADIENT_TRIANGLE; - - typedef struct _GRADIENT_RECT { - ULONG UpperLeft; - ULONG LowerRight; - } GRADIENT_RECT,*PGRADIENT_RECT,*LPGRADIENT_RECT; - - typedef struct _BLENDFUNCTION { - BYTE BlendOp; - BYTE BlendFlags; - BYTE SourceConstantAlpha; - BYTE AlphaFormat; - } BLENDFUNCTION,*PBLENDFUNCTION; - -#define AC_SRC_OVER 0x00 -#define AC_SRC_ALPHA 0x01 - - WINGDIAPI WINBOOL WINAPI AlphaBlend(HDC hdcDest,int xoriginDest,int yoriginDest,int wDest,int hDest,HDC hdcSrc,int xoriginSrc,int yoriginSrc,int wSrc,int hSrc,BLENDFUNCTION ftn); - WINGDIAPI WINBOOL WINAPI TransparentBlt(HDC hdcDest,int xoriginDest,int yoriginDest,int wDest,int hDest,HDC hdcSrc,int xoriginSrc,int yoriginSrc,int wSrc,int hSrc,UINT crTransparent); - -#define GRADIENT_FILL_RECT_H 0x00000000 -#define GRADIENT_FILL_RECT_V 0x00000001 -#define GRADIENT_FILL_TRIANGLE 0x00000002 -#define GRADIENT_FILL_OP_FLAG 0x000000ff - - WINGDIAPI WINBOOL WINAPI GradientFill(HDC hdc,PTRIVERTEX pVertex,ULONG nVertex,PVOID pMesh,ULONG nMesh,ULONG ulMode); - -#ifndef NOMETAFILE - -#ifdef UNICODE -#define CopyEnhMetaFile CopyEnhMetaFileW -#define CreateEnhMetaFile CreateEnhMetaFileW -#define GetEnhMetaFile GetEnhMetaFileW -#define GetEnhMetaFileDescription GetEnhMetaFileDescriptionW -#else -#define CopyEnhMetaFile CopyEnhMetaFileA -#define CreateEnhMetaFile CreateEnhMetaFileA -#define GetEnhMetaFile GetEnhMetaFileA -#define GetEnhMetaFileDescription GetEnhMetaFileDescriptionA -#endif - - WINGDIAPI WINBOOL WINAPI PlayMetaFileRecord(HDC hdc,LPHANDLETABLE lpHandleTable,LPMETARECORD lpMR,UINT noObjs); - - typedef int (CALLBACK *MFENUMPROC)(HDC hdc,HANDLETABLE *lpht,METARECORD *lpMR,int nObj,LPARAM param); - - WINGDIAPI WINBOOL WINAPI EnumMetaFile(HDC hdc,HMETAFILE hmf,MFENUMPROC proc,LPARAM param); - - typedef int (CALLBACK *ENHMFENUMPROC)(HDC hdc,HANDLETABLE *lpht,CONST ENHMETARECORD *lpmr,int hHandles,LPARAM data); - - WINGDIAPI HENHMETAFILE WINAPI CloseEnhMetaFile(HDC hdc); - WINGDIAPI HENHMETAFILE WINAPI CopyEnhMetaFileA(HENHMETAFILE hEnh,LPCSTR lpFileName); - WINGDIAPI HENHMETAFILE WINAPI CopyEnhMetaFileW(HENHMETAFILE hEnh,LPCWSTR lpFileName); - WINGDIAPI HDC WINAPI CreateEnhMetaFileA(HDC hdc,LPCSTR lpFilename,CONST RECT *lprc,LPCSTR lpDesc); - WINGDIAPI HDC WINAPI CreateEnhMetaFileW(HDC hdc,LPCWSTR lpFilename,CONST RECT *lprc,LPCWSTR lpDesc); - WINGDIAPI WINBOOL WINAPI DeleteEnhMetaFile(HENHMETAFILE hmf); - WINGDIAPI WINBOOL WINAPI EnumEnhMetaFile(HDC hdc,HENHMETAFILE hmf,ENHMFENUMPROC proc,LPVOID param,CONST RECT *lpRect); - WINGDIAPI HENHMETAFILE WINAPI GetEnhMetaFileA(LPCSTR lpName); - WINGDIAPI HENHMETAFILE WINAPI GetEnhMetaFileW(LPCWSTR lpName); - WINGDIAPI UINT WINAPI GetEnhMetaFileBits(HENHMETAFILE hEMF,UINT nSize,LPBYTE lpData); - WINGDIAPI UINT WINAPI GetEnhMetaFileDescriptionA(HENHMETAFILE hemf,UINT cchBuffer,LPSTR lpDescription); - WINGDIAPI UINT WINAPI GetEnhMetaFileDescriptionW(HENHMETAFILE hemf,UINT cchBuffer,LPWSTR lpDescription); - WINGDIAPI UINT WINAPI GetEnhMetaFileHeader(HENHMETAFILE hemf,UINT nSize,LPENHMETAHEADER lpEnhMetaHeader); - WINGDIAPI UINT WINAPI GetEnhMetaFilePaletteEntries(HENHMETAFILE hemf,UINT nNumEntries,LPPALETTEENTRY lpPaletteEntries); - WINGDIAPI UINT WINAPI GetEnhMetaFilePixelFormat(HENHMETAFILE hemf,UINT cbBuffer,PIXELFORMATDESCRIPTOR *ppfd); - WINGDIAPI UINT WINAPI GetWinMetaFileBits(HENHMETAFILE hemf,UINT cbData16,LPBYTE pData16,INT iMapMode,HDC hdcRef); - WINGDIAPI WINBOOL WINAPI PlayEnhMetaFile(HDC hdc,HENHMETAFILE hmf,CONST RECT *lprect); - WINGDIAPI WINBOOL WINAPI PlayEnhMetaFileRecord(HDC hdc,LPHANDLETABLE pht,CONST ENHMETARECORD *pmr,UINT cht); - WINGDIAPI HENHMETAFILE WINAPI SetEnhMetaFileBits(UINT nSize,CONST BYTE *pb); - WINGDIAPI HENHMETAFILE WINAPI SetWinMetaFileBits(UINT nSize,CONST BYTE *lpMeta16Data,HDC hdcRef,CONST METAFILEPICT *lpMFP); - WINGDIAPI WINBOOL WINAPI GdiComment(HDC hdc,UINT nSize,CONST BYTE *lpData); -#endif - -#ifndef NOTEXTMETRIC -#ifdef UNICODE -#define GetTextMetrics GetTextMetricsW -#else -#define GetTextMetrics GetTextMetricsA -#endif - - WINGDIAPI WINBOOL WINAPI GetTextMetricsA(HDC hdc,LPTEXTMETRICA lptm); - WINGDIAPI WINBOOL WINAPI GetTextMetricsW(HDC hdc,LPTEXTMETRICW lptm); -#endif - - typedef struct tagDIBSECTION { - BITMAP dsBm; - BITMAPINFOHEADER dsBmih; - DWORD dsBitfields[3]; - HANDLE dshSection; - DWORD dsOffset; - } DIBSECTION,*LPDIBSECTION,*PDIBSECTION; - - WINGDIAPI WINBOOL WINAPI AngleArc(HDC hdc,int x,int y,DWORD r,FLOAT StartAngle,FLOAT SweepAngle); - WINGDIAPI WINBOOL WINAPI PolyPolyline(HDC hdc,CONST POINT *apt,CONST DWORD *asz,DWORD csz); - WINGDIAPI WINBOOL WINAPI GetWorldTransform(HDC hdc,LPXFORM lpxf); - WINGDIAPI WINBOOL WINAPI SetWorldTransform(HDC hdc,CONST XFORM *lpxf); - WINGDIAPI WINBOOL WINAPI ModifyWorldTransform(HDC hdc,CONST XFORM *lpxf,DWORD mode); - WINGDIAPI WINBOOL WINAPI CombineTransform(LPXFORM lpxfOut,CONST XFORM *lpxf1,CONST XFORM *lpxf2); - WINGDIAPI HBITMAP WINAPI CreateDIBSection(HDC hdc,CONST BITMAPINFO *lpbmi,UINT usage,VOID **ppvBits,HANDLE hSection,DWORD offset); - WINGDIAPI UINT WINAPI GetDIBColorTable(HDC hdc,UINT iStart,UINT cEntries,RGBQUAD *prgbq); - WINGDIAPI UINT WINAPI SetDIBColorTable(HDC hdc,UINT iStart,UINT cEntries,CONST RGBQUAD *prgbq); - -#define CA_NEGATIVE 0x0001 -#define CA_LOG_FILTER 0x0002 - -#define ILLUMINANT_DEVICE_DEFAULT 0 -#define ILLUMINANT_A 1 -#define ILLUMINANT_B 2 -#define ILLUMINANT_C 3 -#define ILLUMINANT_D50 4 -#define ILLUMINANT_D55 5 -#define ILLUMINANT_D65 6 -#define ILLUMINANT_D75 7 -#define ILLUMINANT_F2 8 -#define ILLUMINANT_MAX_INDEX ILLUMINANT_F2 - -#define ILLUMINANT_TUNGSTEN ILLUMINANT_A -#define ILLUMINANT_DAYLIGHT ILLUMINANT_C -#define ILLUMINANT_FLUORESCENT ILLUMINANT_F2 -#define ILLUMINANT_NTSC ILLUMINANT_C - -#define RGB_GAMMA_MIN (WORD)02500 -#define RGB_GAMMA_MAX (WORD)65000 - -#define REFERENCE_WHITE_MIN (WORD)6000 -#define REFERENCE_WHITE_MAX (WORD)10000 -#define REFERENCE_BLACK_MIN (WORD)0 -#define REFERENCE_BLACK_MAX (WORD)4000 - -#define COLOR_ADJ_MIN (SHORT)-100 -#define COLOR_ADJ_MAX (SHORT)100 - - typedef struct tagCOLORADJUSTMENT { - WORD caSize; - WORD caFlags; - WORD caIlluminantIndex; - WORD caRedGamma; - WORD caGreenGamma; - WORD caBlueGamma; - WORD caReferenceBlack; - WORD caReferenceWhite; - SHORT caContrast; - SHORT caBrightness; - SHORT caColorfulness; - SHORT caRedGreenTint; - } COLORADJUSTMENT,*PCOLORADJUSTMENT,*LPCOLORADJUSTMENT; - - WINGDIAPI WINBOOL WINAPI SetColorAdjustment(HDC hdc,CONST COLORADJUSTMENT *lpca); - WINGDIAPI WINBOOL WINAPI GetColorAdjustment(HDC hdc,LPCOLORADJUSTMENT lpca); - WINGDIAPI HPALETTE WINAPI CreateHalftonePalette(HDC hdc); - - typedef WINBOOL (CALLBACK *ABORTPROC)(HDC,int); - - typedef struct _DOCINFOA { - int cbSize; - LPCSTR lpszDocName; - LPCSTR lpszOutput; - LPCSTR lpszDatatype; - DWORD fwType; - } DOCINFOA,*LPDOCINFOA; - - typedef struct _DOCINFOW { - int cbSize; - LPCWSTR lpszDocName; - LPCWSTR lpszOutput; - LPCWSTR lpszDatatype; - DWORD fwType; - } DOCINFOW,*LPDOCINFOW; - -#ifdef UNICODE - typedef DOCINFOW DOCINFO; - typedef LPDOCINFOW LPDOCINFO; -#else - typedef DOCINFOA DOCINFO; - typedef LPDOCINFOA LPDOCINFO; -#endif - -#define DI_APPBANDING 0x00000001 -#define DI_ROPS_READ_DESTINATION 0x00000002 - -#ifdef UNICODE -#define StartDoc StartDocW -#define GetObject GetObjectW -#define TextOut TextOutW -#define ExtTextOut ExtTextOutW -#define PolyTextOut PolyTextOutW -#define GetTextFace GetTextFaceW -#else -#define StartDoc StartDocA -#define GetObject GetObjectA -#define TextOut TextOutA -#define ExtTextOut ExtTextOutA -#define PolyTextOut PolyTextOutA -#define GetTextFace GetTextFaceA -#endif - - WINGDIAPI int WINAPI StartDocA(HDC hdc,CONST DOCINFOA *lpdi); - WINGDIAPI int WINAPI StartDocW(HDC hdc,CONST DOCINFOW *lpdi); - WINGDIAPI int WINAPI EndDoc(HDC hdc); - WINGDIAPI int WINAPI StartPage(HDC hdc); - WINGDIAPI int WINAPI EndPage(HDC hdc); - WINGDIAPI int WINAPI AbortDoc(HDC hdc); - WINGDIAPI int WINAPI SetAbortProc(HDC hdc,ABORTPROC proc); - WINGDIAPI WINBOOL WINAPI AbortPath(HDC hdc); - WINGDIAPI WINBOOL WINAPI ArcTo(HDC hdc,int left,int top,int right,int bottom,int xr1,int yr1,int xr2,int yr2); - WINGDIAPI WINBOOL WINAPI BeginPath(HDC hdc); - WINGDIAPI WINBOOL WINAPI CloseFigure(HDC hdc); - WINGDIAPI WINBOOL WINAPI EndPath(HDC hdc); - WINGDIAPI WINBOOL WINAPI FillPath(HDC hdc); - WINGDIAPI WINBOOL WINAPI FlattenPath(HDC hdc); - WINGDIAPI int WINAPI GetPath(HDC hdc,LPPOINT apt,LPBYTE aj,int cpt); - WINGDIAPI HRGN WINAPI PathToRegion(HDC hdc); - WINGDIAPI WINBOOL WINAPI PolyDraw(HDC hdc,CONST POINT *apt,CONST BYTE *aj,int cpt); - WINGDIAPI WINBOOL WINAPI SelectClipPath(HDC hdc,int mode); - WINGDIAPI int WINAPI SetArcDirection(HDC hdc,int dir); - WINGDIAPI WINBOOL WINAPI SetMiterLimit(HDC hdc,FLOAT limit,PFLOAT old); - WINGDIAPI WINBOOL WINAPI StrokeAndFillPath(HDC hdc); - WINGDIAPI WINBOOL WINAPI StrokePath(HDC hdc); - WINGDIAPI WINBOOL WINAPI WidenPath(HDC hdc); - WINGDIAPI HPEN WINAPI ExtCreatePen(DWORD iPenStyle,DWORD cWidth,CONST LOGBRUSH *plbrush,DWORD cStyle,CONST DWORD *pstyle); - WINGDIAPI WINBOOL WINAPI GetMiterLimit(HDC hdc,PFLOAT plimit); - WINGDIAPI int WINAPI GetArcDirection(HDC hdc); - WINGDIAPI int WINAPI GetObjectA(HANDLE h,int c,LPVOID pv); - WINGDIAPI int WINAPI GetObjectW(HANDLE h,int c,LPVOID pv); - WINGDIAPI WINBOOL WINAPI MoveToEx(HDC hdc,int x,int y,LPPOINT lppt); - WINGDIAPI WINBOOL WINAPI TextOutA(HDC hdc,int x,int y,LPCSTR lpString,int c); - WINGDIAPI WINBOOL WINAPI TextOutW(HDC hdc,int x,int y,LPCWSTR lpString,int c); - WINGDIAPI WINBOOL WINAPI ExtTextOutA(HDC hdc,int x,int y,UINT options,CONST RECT *lprect,LPCSTR lpString,UINT c,CONST INT *lpDx); - WINGDIAPI WINBOOL WINAPI ExtTextOutW(HDC hdc,int x,int y,UINT options,CONST RECT *lprect,LPCWSTR lpString,UINT c,CONST INT *lpDx); - WINGDIAPI WINBOOL WINAPI PolyTextOutA(HDC hdc,CONST POLYTEXTA *ppt,int nstrings); - WINGDIAPI WINBOOL WINAPI PolyTextOutW(HDC hdc,CONST POLYTEXTW *ppt,int nstrings); - WINGDIAPI HRGN WINAPI CreatePolygonRgn(CONST POINT *pptl,int cPoint,int iMode); - WINGDIAPI WINBOOL WINAPI DPtoLP(HDC hdc,LPPOINT lppt,int c); - WINGDIAPI WINBOOL WINAPI LPtoDP(HDC hdc,LPPOINT lppt,int c); - WINGDIAPI WINBOOL WINAPI Polygon(HDC hdc,CONST POINT *apt,int cpt); - WINGDIAPI WINBOOL WINAPI Polyline(HDC hdc,CONST POINT *apt,int cpt); - WINGDIAPI WINBOOL WINAPI PolyBezier(HDC hdc,CONST POINT *apt,DWORD cpt); - WINGDIAPI WINBOOL WINAPI PolyBezierTo(HDC hdc,CONST POINT *apt,DWORD cpt); - WINGDIAPI WINBOOL WINAPI PolylineTo(HDC hdc,CONST POINT *apt,DWORD cpt); - WINGDIAPI WINBOOL WINAPI SetViewportExtEx(HDC hdc,int x,int y,LPSIZE lpsz); - WINGDIAPI WINBOOL WINAPI SetViewportOrgEx(HDC hdc,int x,int y,LPPOINT lppt); - WINGDIAPI WINBOOL WINAPI SetWindowExtEx(HDC hdc,int x,int y,LPSIZE lpsz); - WINGDIAPI WINBOOL WINAPI SetWindowOrgEx(HDC hdc,int x,int y,LPPOINT lppt); - WINGDIAPI WINBOOL WINAPI OffsetViewportOrgEx(HDC hdc,int x,int y,LPPOINT lppt); - WINGDIAPI WINBOOL WINAPI OffsetWindowOrgEx(HDC hdc,int x,int y,LPPOINT lppt); - WINGDIAPI WINBOOL WINAPI ScaleViewportExtEx(HDC hdc,int xn,int dx,int yn,int yd,LPSIZE lpsz); - WINGDIAPI WINBOOL WINAPI ScaleWindowExtEx(HDC hdc,int xn,int xd,int yn,int yd,LPSIZE lpsz); - WINGDIAPI WINBOOL WINAPI SetBitmapDimensionEx(HBITMAP hbm,int w,int h,LPSIZE lpsz); - WINGDIAPI WINBOOL WINAPI SetBrushOrgEx(HDC hdc,int x,int y,LPPOINT lppt); - WINGDIAPI int WINAPI GetTextFaceA(HDC hdc,int c,LPSTR lpName); - WINGDIAPI int WINAPI GetTextFaceW(HDC hdc,int c,LPWSTR lpName); - -#define FONTMAPPER_MAX 10 - - typedef struct tagKERNINGPAIR { - WORD wFirst; - WORD wSecond; - int iKernAmount; - } KERNINGPAIR,*LPKERNINGPAIR; - -#ifdef UNICODE -#define GetKerningPairs GetKerningPairsW -#else -#define GetKerningPairs GetKerningPairsA -#endif - - WINGDIAPI DWORD WINAPI GetKerningPairsA(HDC hdc,DWORD nPairs,LPKERNINGPAIR lpKernPair); - WINGDIAPI DWORD WINAPI GetKerningPairsW(HDC hdc,DWORD nPairs,LPKERNINGPAIR lpKernPair); - WINGDIAPI WINBOOL WINAPI GetDCOrgEx(HDC hdc,LPPOINT lppt); - WINGDIAPI WINBOOL WINAPI FixBrushOrgEx(HDC hdc,int x,int y,LPPOINT ptl); - WINGDIAPI WINBOOL WINAPI UnrealizeObject(HGDIOBJ h); - WINGDIAPI WINBOOL WINAPI GdiFlush(); - WINGDIAPI DWORD WINAPI GdiSetBatchLimit(DWORD dw); - WINGDIAPI DWORD WINAPI GdiGetBatchLimit(); - -#define ICM_OFF 1 -#define ICM_ON 2 -#define ICM_QUERY 3 -#define ICM_DONE_OUTSIDEDC 4 - - typedef int (CALLBACK *ICMENUMPROCA)(LPSTR,LPARAM); - typedef int (CALLBACK *ICMENUMPROCW)(LPWSTR,LPARAM); - -#ifdef UNICODE -#define ICMENUMPROC ICMENUMPROCW -#define EnumICMProfiles EnumICMProfilesW -#define UpdateICMRegKey UpdateICMRegKeyW -#define GetLogColorSpace GetLogColorSpaceW -#define CreateColorSpace CreateColorSpaceW -#define GetICMProfile GetICMProfileW -#define SetICMProfile SetICMProfileW -#else -#define ICMENUMPROC ICMENUMPROCA -#define EnumICMProfiles EnumICMProfilesA -#define UpdateICMRegKey UpdateICMRegKeyA -#define GetLogColorSpace GetLogColorSpaceA -#define CreateColorSpace CreateColorSpaceA -#define GetICMProfile GetICMProfileA -#define SetICMProfile SetICMProfileA -#endif - - WINGDIAPI int WINAPI SetICMMode(HDC hdc,int mode); - WINGDIAPI WINBOOL WINAPI CheckColorsInGamut(HDC hdc,LPVOID lpRGBTriple,LPVOID dlpBuffer,DWORD nCount); - WINGDIAPI HCOLORSPACE WINAPI GetColorSpace(HDC hdc); - WINGDIAPI WINBOOL WINAPI GetLogColorSpaceA(HCOLORSPACE hColorSpace,LPLOGCOLORSPACEA lpBuffer,DWORD nSize); - WINGDIAPI WINBOOL WINAPI GetLogColorSpaceW(HCOLORSPACE hColorSpace,LPLOGCOLORSPACEW lpBuffer,DWORD nSize); - WINGDIAPI HCOLORSPACE WINAPI CreateColorSpaceA(LPLOGCOLORSPACEA lplcs); - WINGDIAPI HCOLORSPACE WINAPI CreateColorSpaceW(LPLOGCOLORSPACEW lplcs); - WINGDIAPI HCOLORSPACE WINAPI SetColorSpace(HDC hdc,HCOLORSPACE hcs); - WINGDIAPI WINBOOL WINAPI DeleteColorSpace(HCOLORSPACE hcs); - WINGDIAPI WINBOOL WINAPI GetICMProfileA(HDC hdc,LPDWORD pBufSize,LPSTR pszFilename); - WINGDIAPI WINBOOL WINAPI GetICMProfileW(HDC hdc,LPDWORD pBufSize,LPWSTR pszFilename); - WINGDIAPI WINBOOL WINAPI SetICMProfileA(HDC hdc,LPSTR lpFileName); - WINGDIAPI WINBOOL WINAPI SetICMProfileW(HDC hdc,LPWSTR lpFileName); - WINGDIAPI WINBOOL WINAPI GetDeviceGammaRamp(HDC hdc,LPVOID lpRamp); - WINGDIAPI WINBOOL WINAPI SetDeviceGammaRamp(HDC hdc,LPVOID lpRamp); - WINGDIAPI WINBOOL WINAPI ColorMatchToTarget(HDC hdc,HDC hdcTarget,DWORD action); - WINGDIAPI int WINAPI EnumICMProfilesA(HDC hdc,ICMENUMPROCA proc,LPARAM param); - WINGDIAPI int WINAPI EnumICMProfilesW(HDC hdc,ICMENUMPROCW proc,LPARAM param); - WINGDIAPI WINBOOL WINAPI UpdateICMRegKeyA(DWORD reserved,LPSTR lpszCMID,LPSTR lpszFileName,UINT command); - WINGDIAPI WINBOOL WINAPI UpdateICMRegKeyW(DWORD reserved,LPWSTR lpszCMID,LPWSTR lpszFileName,UINT command); - WINGDIAPI WINBOOL WINAPI ColorCorrectPalette(HDC hdc,HPALETTE hPal,DWORD deFirst,DWORD num); - -#ifndef NOMETAFILE - -#define ENHMETA_SIGNATURE 0x464D4520 -#define ENHMETA_STOCK_OBJECT 0x80000000 - -#define EMR_HEADER 1 -#define EMR_POLYBEZIER 2 -#define EMR_POLYGON 3 -#define EMR_POLYLINE 4 -#define EMR_POLYBEZIERTO 5 -#define EMR_POLYLINETO 6 -#define EMR_POLYPOLYLINE 7 -#define EMR_POLYPOLYGON 8 -#define EMR_SETWINDOWEXTEX 9 -#define EMR_SETWINDOWORGEX 10 -#define EMR_SETVIEWPORTEXTEX 11 -#define EMR_SETVIEWPORTORGEX 12 -#define EMR_SETBRUSHORGEX 13 -#define EMR_EOF 14 -#define EMR_SETPIXELV 15 -#define EMR_SETMAPPERFLAGS 16 -#define EMR_SETMAPMODE 17 -#define EMR_SETBKMODE 18 -#define EMR_SETPOLYFILLMODE 19 -#define EMR_SETROP2 20 -#define EMR_SETSTRETCHBLTMODE 21 -#define EMR_SETTEXTALIGN 22 -#define EMR_SETCOLORADJUSTMENT 23 -#define EMR_SETTEXTCOLOR 24 -#define EMR_SETBKCOLOR 25 -#define EMR_OFFSETCLIPRGN 26 -#define EMR_MOVETOEX 27 -#define EMR_SETMETARGN 28 -#define EMR_EXCLUDECLIPRECT 29 -#define EMR_INTERSECTCLIPRECT 30 -#define EMR_SCALEVIEWPORTEXTEX 31 -#define EMR_SCALEWINDOWEXTEX 32 -#define EMR_SAVEDC 33 -#define EMR_RESTOREDC 34 -#define EMR_SETWORLDTRANSFORM 35 -#define EMR_MODIFYWORLDTRANSFORM 36 -#define EMR_SELECTOBJECT 37 -#define EMR_CREATEPEN 38 -#define EMR_CREATEBRUSHINDIRECT 39 -#define EMR_DELETEOBJECT 40 -#define EMR_ANGLEARC 41 -#define EMR_ELLIPSE 42 -#define EMR_RECTANGLE 43 -#define EMR_ROUNDRECT 44 -#define EMR_ARC 45 -#define EMR_CHORD 46 -#define EMR_PIE 47 -#define EMR_SELECTPALETTE 48 -#define EMR_CREATEPALETTE 49 -#define EMR_SETPALETTEENTRIES 50 -#define EMR_RESIZEPALETTE 51 -#define EMR_REALIZEPALETTE 52 -#define EMR_EXTFLOODFILL 53 -#define EMR_LINETO 54 -#define EMR_ARCTO 55 -#define EMR_POLYDRAW 56 -#define EMR_SETARCDIRECTION 57 -#define EMR_SETMITERLIMIT 58 -#define EMR_BEGINPATH 59 -#define EMR_ENDPATH 60 -#define EMR_CLOSEFIGURE 61 -#define EMR_FILLPATH 62 -#define EMR_STROKEANDFILLPATH 63 -#define EMR_STROKEPATH 64 -#define EMR_FLATTENPATH 65 -#define EMR_WIDENPATH 66 -#define EMR_SELECTCLIPPATH 67 -#define EMR_ABORTPATH 68 - -#define EMR_GDICOMMENT 70 -#define EMR_FILLRGN 71 -#define EMR_FRAMERGN 72 -#define EMR_INVERTRGN 73 -#define EMR_PAINTRGN 74 -#define EMR_EXTSELECTCLIPRGN 75 -#define EMR_BITBLT 76 -#define EMR_STRETCHBLT 77 -#define EMR_MASKBLT 78 -#define EMR_PLGBLT 79 -#define EMR_SETDIBITSTODEVICE 80 -#define EMR_STRETCHDIBITS 81 -#define EMR_EXTCREATEFONTINDIRECTW 82 -#define EMR_EXTTEXTOUTA 83 -#define EMR_EXTTEXTOUTW 84 -#define EMR_POLYBEZIER16 85 -#define EMR_POLYGON16 86 -#define EMR_POLYLINE16 87 -#define EMR_POLYBEZIERTO16 88 -#define EMR_POLYLINETO16 89 -#define EMR_POLYPOLYLINE16 90 -#define EMR_POLYPOLYGON16 91 -#define EMR_POLYDRAW16 92 -#define EMR_CREATEMONOBRUSH 93 -#define EMR_CREATEDIBPATTERNBRUSHPT 94 -#define EMR_EXTCREATEPEN 95 -#define EMR_POLYTEXTOUTA 96 -#define EMR_POLYTEXTOUTW 97 - -#define EMR_SETICMMODE 98 -#define EMR_CREATECOLORSPACE 99 -#define EMR_SETCOLORSPACE 100 -#define EMR_DELETECOLORSPACE 101 -#define EMR_GLSRECORD 102 -#define EMR_GLSBOUNDEDRECORD 103 -#define EMR_PIXELFORMAT 104 -#define EMR_RESERVED_105 105 -#define EMR_RESERVED_106 106 -#define EMR_RESERVED_107 107 -#define EMR_RESERVED_108 108 -#define EMR_RESERVED_109 109 -#define EMR_RESERVED_110 110 -#define EMR_COLORCORRECTPALETTE 111 -#define EMR_SETICMPROFILEA 112 -#define EMR_SETICMPROFILEW 113 -#define EMR_ALPHABLEND 114 -#define EMR_SETLAYOUT 115 -#define EMR_TRANSPARENTBLT 116 -#define EMR_RESERVED_117 117 -#define EMR_GRADIENTFILL 118 -#define EMR_RESERVED_119 119 -#define EMR_RESERVED_120 120 -#define EMR_COLORMATCHTOTARGETW 121 -#define EMR_CREATECOLORSPACEW 122 - -#define EMR_MIN 1 - -#define EMR_MAX 122 - - typedef struct tagEMR { - DWORD iType; - DWORD nSize; - } EMR,*PEMR; - - typedef struct tagEMRTEXT { - POINTL ptlReference; - DWORD nChars; - DWORD offString; - DWORD fOptions; - RECTL rcl; - DWORD offDx; - } EMRTEXT,*PEMRTEXT; - - typedef struct tagABORTPATH { - EMR emr; - } EMRABORTPATH,*PEMRABORTPATH,EMRBEGINPATH,*PEMRBEGINPATH,EMRENDPATH,*PEMRENDPATH,EMRCLOSEFIGURE,*PEMRCLOSEFIGURE,EMRFLATTENPATH,*PEMRFLATTENPATH,EMRWIDENPATH,*PEMRWIDENPATH,EMRSETMETARGN,*PEMRSETMETARGN,EMRSAVEDC,*PEMRSAVEDC,EMRREALIZEPALETTE,*PEMRREALIZEPALETTE; - - typedef struct tagEMRSELECTCLIPPATH { - EMR emr; - DWORD iMode; - } EMRSELECTCLIPPATH,*PEMRSELECTCLIPPATH,EMRSETBKMODE,*PEMRSETBKMODE,EMRSETMAPMODE,*PEMRSETMAPMODE,EMRSETLAYOUT,*PEMRSETLAYOUT, - EMRSETPOLYFILLMODE,*PEMRSETPOLYFILLMODE,EMRSETROP2,*PEMRSETROP2,EMRSETSTRETCHBLTMODE,*PEMRSETSTRETCHBLTMODE,EMRSETICMMODE, - *PEMRSETICMMODE,EMRSETTEXTALIGN,*PEMRSETTEXTALIGN; - - typedef struct tagEMRSETMITERLIMIT { - EMR emr; - FLOAT eMiterLimit; - } EMRSETMITERLIMIT,*PEMRSETMITERLIMIT; - - typedef struct tagEMRRESTOREDC { - EMR emr; - LONG iRelative; - } EMRRESTOREDC,*PEMRRESTOREDC; - - typedef struct tagEMRSETARCDIRECTION { - EMR emr; - DWORD iArcDirection; - - } EMRSETARCDIRECTION,*PEMRSETARCDIRECTION; - - typedef struct tagEMRSETMAPPERFLAGS { - EMR emr; - DWORD dwFlags; - } EMRSETMAPPERFLAGS,*PEMRSETMAPPERFLAGS; - - typedef struct tagEMRSETTEXTCOLOR { - EMR emr; - COLORREF crColor; - } EMRSETBKCOLOR,*PEMRSETBKCOLOR,EMRSETTEXTCOLOR,*PEMRSETTEXTCOLOR; - - typedef struct tagEMRSELECTOBJECT { - EMR emr; - DWORD ihObject; - } EMRSELECTOBJECT,*PEMRSELECTOBJECT,EMRDELETEOBJECT,*PEMRDELETEOBJECT; - - typedef struct tagEMRSELECTPALETTE { - EMR emr; - DWORD ihPal; - } EMRSELECTPALETTE,*PEMRSELECTPALETTE; - - typedef struct tagEMRRESIZEPALETTE { - EMR emr; - DWORD ihPal; - DWORD cEntries; - } EMRRESIZEPALETTE,*PEMRRESIZEPALETTE; - - typedef struct tagEMRSETPALETTEENTRIES { - EMR emr; - DWORD ihPal; - DWORD iStart; - DWORD cEntries; - PALETTEENTRY aPalEntries[1]; - } EMRSETPALETTEENTRIES,*PEMRSETPALETTEENTRIES; - - typedef struct tagEMRSETCOLORADJUSTMENT { - EMR emr; - COLORADJUSTMENT ColorAdjustment; - } EMRSETCOLORADJUSTMENT,*PEMRSETCOLORADJUSTMENT; - - typedef struct tagEMRGDICOMMENT { - EMR emr; - DWORD cbData; - BYTE Data[1]; - } EMRGDICOMMENT,*PEMRGDICOMMENT; - - typedef struct tagEMREOF { - EMR emr; - DWORD nPalEntries; - DWORD offPalEntries; - DWORD nSizeLast; - } EMREOF,*PEMREOF; - - typedef struct tagEMRLINETO { - EMR emr; - POINTL ptl; - } EMRLINETO,*PEMRLINETO,EMRMOVETOEX,*PEMRMOVETOEX; - - typedef struct tagEMROFFSETCLIPRGN { - EMR emr; - POINTL ptlOffset; - } EMROFFSETCLIPRGN,*PEMROFFSETCLIPRGN; - - typedef struct tagEMRFILLPATH { - EMR emr; - RECTL rclBounds; - } EMRFILLPATH,*PEMRFILLPATH,EMRSTROKEANDFILLPATH,*PEMRSTROKEANDFILLPATH,EMRSTROKEPATH,*PEMRSTROKEPATH; - - typedef struct tagEMREXCLUDECLIPRECT { - EMR emr; - RECTL rclClip; - } EMREXCLUDECLIPRECT,*PEMREXCLUDECLIPRECT,EMRINTERSECTCLIPRECT,*PEMRINTERSECTCLIPRECT; - - typedef struct tagEMRSETVIEWPORTORGEX { - EMR emr; - POINTL ptlOrigin; - } EMRSETVIEWPORTORGEX,*PEMRSETVIEWPORTORGEX,EMRSETWINDOWORGEX,*PEMRSETWINDOWORGEX,EMRSETBRUSHORGEX,*PEMRSETBRUSHORGEX; - - typedef struct tagEMRSETVIEWPORTEXTEX { - EMR emr; - SIZEL szlExtent; - } EMRSETVIEWPORTEXTEX,*PEMRSETVIEWPORTEXTEX,EMRSETWINDOWEXTEX,*PEMRSETWINDOWEXTEX; - - typedef struct tagEMRSCALEVIEWPORTEXTEX { - EMR emr; - LONG xNum; - LONG xDenom; - LONG yNum; - LONG yDenom; - } EMRSCALEVIEWPORTEXTEX,*PEMRSCALEVIEWPORTEXTEX,EMRSCALEWINDOWEXTEX,*PEMRSCALEWINDOWEXTEX; - - typedef struct tagEMRSETWORLDTRANSFORM { - EMR emr; - XFORM xform; - } EMRSETWORLDTRANSFORM,*PEMRSETWORLDTRANSFORM; - - typedef struct tagEMRMODIFYWORLDTRANSFORM { - EMR emr; - XFORM xform; - DWORD iMode; - } EMRMODIFYWORLDTRANSFORM,*PEMRMODIFYWORLDTRANSFORM; - - typedef struct tagEMRSETPIXELV { - EMR emr; - POINTL ptlPixel; - COLORREF crColor; - } EMRSETPIXELV,*PEMRSETPIXELV; - - typedef struct tagEMREXTFLOODFILL { - EMR emr; - POINTL ptlStart; - COLORREF crColor; - DWORD iMode; - } EMREXTFLOODFILL,*PEMREXTFLOODFILL; - - typedef struct tagEMRELLIPSE { - EMR emr; - RECTL rclBox; - } EMRELLIPSE,*PEMRELLIPSE,EMRRECTANGLE,*PEMRRECTANGLE; - - typedef struct tagEMRROUNDRECT { - EMR emr; - RECTL rclBox; - SIZEL szlCorner; - } EMRROUNDRECT,*PEMRROUNDRECT; - - typedef struct tagEMRARC { - EMR emr; - RECTL rclBox; - POINTL ptlStart; - POINTL ptlEnd; - } EMRARC,*PEMRARC,EMRARCTO,*PEMRARCTO,EMRCHORD,*PEMRCHORD,EMRPIE,*PEMRPIE; - - typedef struct tagEMRANGLEARC { - EMR emr; - POINTL ptlCenter; - DWORD nRadius; - FLOAT eStartAngle; - FLOAT eSweepAngle; - } EMRANGLEARC,*PEMRANGLEARC; - - typedef struct tagEMRPOLYLINE { - EMR emr; - RECTL rclBounds; - DWORD cptl; - POINTL aptl[1]; - } EMRPOLYLINE,*PEMRPOLYLINE,EMRPOLYBEZIER,*PEMRPOLYBEZIER,EMRPOLYGON,*PEMRPOLYGON,EMRPOLYBEZIERTO,*PEMRPOLYBEZIERTO,EMRPOLYLINETO,*PEMRPOLYLINETO; - - typedef struct tagEMRPOLYLINE16 { - EMR emr; - RECTL rclBounds; - DWORD cpts; - POINTS apts[1]; - } EMRPOLYLINE16,*PEMRPOLYLINE16,EMRPOLYBEZIER16,*PEMRPOLYBEZIER16,EMRPOLYGON16,*PEMRPOLYGON16,EMRPOLYBEZIERTO16,*PEMRPOLYBEZIERTO16,EMRPOLYLINETO16,*PEMRPOLYLINETO16; - - typedef struct tagEMRPOLYDRAW { - EMR emr; - RECTL rclBounds; - DWORD cptl; - POINTL aptl[1]; - BYTE abTypes[1]; - } EMRPOLYDRAW,*PEMRPOLYDRAW; - - typedef struct tagEMRPOLYDRAW16 { - EMR emr; - RECTL rclBounds; - DWORD cpts; - POINTS apts[1]; - BYTE abTypes[1]; - } EMRPOLYDRAW16,*PEMRPOLYDRAW16; - - typedef struct tagEMRPOLYPOLYLINE { - EMR emr; - RECTL rclBounds; - DWORD nPolys; - DWORD cptl; - DWORD aPolyCounts[1]; - POINTL aptl[1]; - } EMRPOLYPOLYLINE,*PEMRPOLYPOLYLINE,EMRPOLYPOLYGON,*PEMRPOLYPOLYGON; - - typedef struct tagEMRPOLYPOLYLINE16 { - EMR emr; - RECTL rclBounds; - DWORD nPolys; - DWORD cpts; - DWORD aPolyCounts[1]; - POINTS apts[1]; - } EMRPOLYPOLYLINE16,*PEMRPOLYPOLYLINE16,EMRPOLYPOLYGON16,*PEMRPOLYPOLYGON16; - - typedef struct tagEMRINVERTRGN { - EMR emr; - RECTL rclBounds; - DWORD cbRgnData; - BYTE RgnData[1]; - } EMRINVERTRGN,*PEMRINVERTRGN,EMRPAINTRGN,*PEMRPAINTRGN; - - typedef struct tagEMRFILLRGN { - EMR emr; - RECTL rclBounds; - DWORD cbRgnData; - DWORD ihBrush; - BYTE RgnData[1]; - } EMRFILLRGN,*PEMRFILLRGN; - - typedef struct tagEMRFRAMERGN { - EMR emr; - RECTL rclBounds; - DWORD cbRgnData; - DWORD ihBrush; - SIZEL szlStroke; - BYTE RgnData[1]; - } EMRFRAMERGN,*PEMRFRAMERGN; - - typedef struct tagEMREXTSELECTCLIPRGN { - EMR emr; - DWORD cbRgnData; - DWORD iMode; - BYTE RgnData[1]; - } EMREXTSELECTCLIPRGN,*PEMREXTSELECTCLIPRGN; - - typedef struct tagEMREXTTEXTOUTA { - EMR emr; - RECTL rclBounds; - DWORD iGraphicsMode; - FLOAT exScale; - FLOAT eyScale; - EMRTEXT emrtext; - } EMREXTTEXTOUTA,*PEMREXTTEXTOUTA,EMREXTTEXTOUTW,*PEMREXTTEXTOUTW; - - typedef struct tagEMRPOLYTEXTOUTA { - EMR emr; - RECTL rclBounds; - DWORD iGraphicsMode; - FLOAT exScale; - FLOAT eyScale; - LONG cStrings; - EMRTEXT aemrtext[1]; - } EMRPOLYTEXTOUTA,*PEMRPOLYTEXTOUTA,EMRPOLYTEXTOUTW,*PEMRPOLYTEXTOUTW; - - typedef struct tagEMRBITBLT { - EMR emr; - RECTL rclBounds; - LONG xDest; - LONG yDest; - LONG cxDest; - LONG cyDest; - DWORD dwRop; - LONG xSrc; - LONG ySrc; - XFORM xformSrc; - COLORREF crBkColorSrc; - DWORD iUsageSrc; - DWORD offBmiSrc; - DWORD cbBmiSrc; - DWORD offBitsSrc; - DWORD cbBitsSrc; - } EMRBITBLT,*PEMRBITBLT; - - typedef struct tagEMRSTRETCHBLT { - EMR emr; - RECTL rclBounds; - LONG xDest; - LONG yDest; - LONG cxDest; - LONG cyDest; - DWORD dwRop; - LONG xSrc; - LONG ySrc; - XFORM xformSrc; - COLORREF crBkColorSrc; - DWORD iUsageSrc; - DWORD offBmiSrc; - DWORD cbBmiSrc; - DWORD offBitsSrc; - DWORD cbBitsSrc; - LONG cxSrc; - LONG cySrc; - } EMRSTRETCHBLT,*PEMRSTRETCHBLT; - - typedef struct tagEMRMASKBLT { - EMR emr; - RECTL rclBounds; - LONG xDest; - LONG yDest; - LONG cxDest; - LONG cyDest; - DWORD dwRop; - LONG xSrc; - LONG ySrc; - XFORM xformSrc; - COLORREF crBkColorSrc; - DWORD iUsageSrc; - DWORD offBmiSrc; - DWORD cbBmiSrc; - DWORD offBitsSrc; - DWORD cbBitsSrc; - LONG xMask; - LONG yMask; - DWORD iUsageMask; - DWORD offBmiMask; - DWORD cbBmiMask; - DWORD offBitsMask; - DWORD cbBitsMask; - } EMRMASKBLT,*PEMRMASKBLT; - - typedef struct tagEMRPLGBLT { - EMR emr; - RECTL rclBounds; - POINTL aptlDest[3]; - LONG xSrc; - LONG ySrc; - LONG cxSrc; - LONG cySrc; - XFORM xformSrc; - COLORREF crBkColorSrc; - DWORD iUsageSrc; - DWORD offBmiSrc; - DWORD cbBmiSrc; - DWORD offBitsSrc; - DWORD cbBitsSrc; - LONG xMask; - LONG yMask; - DWORD iUsageMask; - DWORD offBmiMask; - DWORD cbBmiMask; - DWORD offBitsMask; - DWORD cbBitsMask; - } EMRPLGBLT,*PEMRPLGBLT; - - typedef struct tagEMRSETDIBITSTODEVICE { - EMR emr; - RECTL rclBounds; - LONG xDest; - LONG yDest; - LONG xSrc; - LONG ySrc; - LONG cxSrc; - LONG cySrc; - DWORD offBmiSrc; - DWORD cbBmiSrc; - DWORD offBitsSrc; - DWORD cbBitsSrc; - DWORD iUsageSrc; - DWORD iStartScan; - DWORD cScans; - } EMRSETDIBITSTODEVICE,*PEMRSETDIBITSTODEVICE; - - typedef struct tagEMRSTRETCHDIBITS { - EMR emr; - RECTL rclBounds; - LONG xDest; - LONG yDest; - LONG xSrc; - LONG ySrc; - LONG cxSrc; - LONG cySrc; - DWORD offBmiSrc; - DWORD cbBmiSrc; - DWORD offBitsSrc; - DWORD cbBitsSrc; - DWORD iUsageSrc; - DWORD dwRop; - LONG cxDest; - LONG cyDest; - } EMRSTRETCHDIBITS,*PEMRSTRETCHDIBITS; - - typedef struct tagEMREXTCREATEFONTINDIRECTW { - EMR emr; - DWORD ihFont; - EXTLOGFONTW elfw; - } EMREXTCREATEFONTINDIRECTW,*PEMREXTCREATEFONTINDIRECTW; - - typedef struct tagEMRCREATEPALETTE { - EMR emr; - DWORD ihPal; - LOGPALETTE lgpl; - } EMRCREATEPALETTE,*PEMRCREATEPALETTE; - - typedef struct tagEMRCREATEPEN { - EMR emr; - DWORD ihPen; - LOGPEN lopn; - } EMRCREATEPEN,*PEMRCREATEPEN; - - typedef struct tagEMREXTCREATEPEN { - EMR emr; - DWORD ihPen; - DWORD offBmi; - DWORD cbBmi; - DWORD offBits; - DWORD cbBits; - EXTLOGPEN elp; - } EMREXTCREATEPEN,*PEMREXTCREATEPEN; - - typedef struct tagEMRCREATEBRUSHINDIRECT { - EMR emr; - DWORD ihBrush; - LOGBRUSH32 lb; - } EMRCREATEBRUSHINDIRECT,*PEMRCREATEBRUSHINDIRECT; - - typedef struct tagEMRCREATEMONOBRUSH { - EMR emr; - DWORD ihBrush; - DWORD iUsage; - DWORD offBmi; - DWORD cbBmi; - DWORD offBits; - DWORD cbBits; - } EMRCREATEMONOBRUSH,*PEMRCREATEMONOBRUSH; - - typedef struct tagEMRCREATEDIBPATTERNBRUSHPT { - EMR emr; - DWORD ihBrush; - DWORD iUsage; - DWORD offBmi; - DWORD cbBmi; - DWORD offBits; - DWORD cbBits; - } EMRCREATEDIBPATTERNBRUSHPT,*PEMRCREATEDIBPATTERNBRUSHPT; - - typedef struct tagEMRFORMAT { - DWORD dSignature; - DWORD nVersion; - DWORD cbData; - DWORD offData; - } EMRFORMAT,*PEMRFORMAT; - - typedef struct tagEMRGLSRECORD { - EMR emr; - DWORD cbData; - BYTE Data[1]; - } EMRGLSRECORD,*PEMRGLSRECORD; - - typedef struct tagEMRGLSBOUNDEDRECORD { - EMR emr; - RECTL rclBounds; - DWORD cbData; - BYTE Data[1]; - } EMRGLSBOUNDEDRECORD,*PEMRGLSBOUNDEDRECORD; - - typedef struct tagEMRPIXELFORMAT { - EMR emr; - PIXELFORMATDESCRIPTOR pfd; - } EMRPIXELFORMAT,*PEMRPIXELFORMAT; - - typedef struct tagEMRCREATECOLORSPACE { - EMR emr; - DWORD ihCS; - LOGCOLORSPACEA lcs; - } EMRCREATECOLORSPACE,*PEMRCREATECOLORSPACE; - - typedef struct tagEMRSETCOLORSPACE { - EMR emr; - DWORD ihCS; - } EMRSETCOLORSPACE,*PEMRSETCOLORSPACE,EMRSELECTCOLORSPACE,*PEMRSELECTCOLORSPACE,EMRDELETECOLORSPACE,*PEMRDELETECOLORSPACE; - - typedef struct tagEMREXTESCAPE { - EMR emr; - INT iEscape; - INT cbEscData; - BYTE EscData[1]; - } EMREXTESCAPE,*PEMREXTESCAPE,EMRDRAWESCAPE,*PEMRDRAWESCAPE; - - typedef struct tagEMRNAMEDESCAPE { - EMR emr; - INT iEscape; - INT cbDriver; - INT cbEscData; - BYTE EscData[1]; - } EMRNAMEDESCAPE,*PEMRNAMEDESCAPE; - -#define SETICMPROFILE_EMBEDED 0x00000001 - - typedef struct tagEMRSETICMPROFILE { - EMR emr; - DWORD dwFlags; - DWORD cbName; - DWORD cbData; - BYTE Data[1]; - } EMRSETICMPROFILE,*PEMRSETICMPROFILE,EMRSETICMPROFILEA,*PEMRSETICMPROFILEA,EMRSETICMPROFILEW,*PEMRSETICMPROFILEW; - -#define CREATECOLORSPACE_EMBEDED 0x00000001 - - typedef struct tagEMRCREATECOLORSPACEW { - EMR emr; - DWORD ihCS; - LOGCOLORSPACEW lcs; - DWORD dwFlags; - DWORD cbData; - BYTE Data[1]; - } EMRCREATECOLORSPACEW,*PEMRCREATECOLORSPACEW; - -#define COLORMATCHTOTARGET_EMBEDED 0x00000001 - - typedef struct tagCOLORMATCHTOTARGET { - EMR emr; - DWORD dwAction; - DWORD dwFlags; - DWORD cbName; - DWORD cbData; - BYTE Data[1]; - } EMRCOLORMATCHTOTARGET,*PEMRCOLORMATCHTOTARGET; - - typedef struct tagCOLORCORRECTPALETTE { - EMR emr; - DWORD ihPalette; - DWORD nFirstEntry; - DWORD nPalEntries; - DWORD nReserved; - } EMRCOLORCORRECTPALETTE,*PEMRCOLORCORRECTPALETTE; - - typedef struct tagEMRALPHABLEND { - EMR emr; - RECTL rclBounds; - LONG xDest; - LONG yDest; - LONG cxDest; - LONG cyDest; - DWORD dwRop; - LONG xSrc; - LONG ySrc; - XFORM xformSrc; - COLORREF crBkColorSrc; - DWORD iUsageSrc; - DWORD offBmiSrc; - DWORD cbBmiSrc; - DWORD offBitsSrc; - DWORD cbBitsSrc; - LONG cxSrc; - LONG cySrc; - } EMRALPHABLEND,*PEMRALPHABLEND; - - typedef struct tagEMRGRADIENTFILL { - EMR emr; - RECTL rclBounds; - DWORD nVer; - DWORD nTri; - ULONG ulMode; - TRIVERTEX Ver[1]; - } EMRGRADIENTFILL,*PEMRGRADIENTFILL; - - typedef struct tagEMRTRANSPARENTBLT { - EMR emr; - RECTL rclBounds; - LONG xDest; - LONG yDest; - LONG cxDest; - LONG cyDest; - DWORD dwRop; - LONG xSrc; - LONG ySrc; - XFORM xformSrc; - COLORREF crBkColorSrc; - DWORD iUsageSrc; - DWORD offBmiSrc; - DWORD cbBmiSrc; - DWORD offBitsSrc; - DWORD cbBitsSrc; - LONG cxSrc; - LONG cySrc; - } EMRTRANSPARENTBLT,*PEMRTRANSPARENTBLT; - -#define GDICOMMENT_IDENTIFIER 0x43494447 -#define GDICOMMENT_WINDOWS_METAFILE 0x80000001 -#define GDICOMMENT_BEGINGROUP 0x00000002 -#define GDICOMMENT_ENDGROUP 0x00000003 -#define GDICOMMENT_MULTIFORMATS 0x40000004 -#define EPS_SIGNATURE 0x46535045 -#define GDICOMMENT_UNICODE_STRING 0x00000040 -#define GDICOMMENT_UNICODE_END 0x00000080 -#endif - -#ifdef UNICODE -#define wglUseFontBitmaps wglUseFontBitmapsW -#else -#define wglUseFontBitmaps wglUseFontBitmapsA -#endif - - WINGDIAPI WINBOOL WINAPI wglCopyContext(HGLRC,HGLRC,UINT); - WINGDIAPI HGLRC WINAPI wglCreateContext(HDC); - WINGDIAPI HGLRC WINAPI wglCreateLayerContext(HDC,int); - WINGDIAPI WINBOOL WINAPI wglDeleteContext(HGLRC); - WINGDIAPI HGLRC WINAPI wglGetCurrentContext(VOID); - WINGDIAPI HDC WINAPI wglGetCurrentDC(VOID); - WINGDIAPI PROC WINAPI wglGetProcAddress(LPCSTR); - WINGDIAPI WINBOOL WINAPI wglMakeCurrent(HDC,HGLRC); - WINGDIAPI WINBOOL WINAPI wglShareLists(HGLRC,HGLRC); - WINGDIAPI WINBOOL WINAPI wglUseFontBitmapsA(HDC,DWORD,DWORD,DWORD); - WINGDIAPI WINBOOL WINAPI wglUseFontBitmapsW(HDC,DWORD,DWORD,DWORD); - WINGDIAPI WINBOOL WINAPI SwapBuffers(HDC); - - typedef struct _POINTFLOAT { - FLOAT x; - FLOAT y; - } POINTFLOAT,*PPOINTFLOAT; - - typedef struct _GLYPHMETRICSFLOAT { - FLOAT gmfBlackBoxX; - FLOAT gmfBlackBoxY; - POINTFLOAT gmfptGlyphOrigin; - FLOAT gmfCellIncX; - FLOAT gmfCellIncY; - } GLYPHMETRICSFLOAT,*PGLYPHMETRICSFLOAT,*LPGLYPHMETRICSFLOAT; - -#define WGL_FONT_LINES 0 -#define WGL_FONT_POLYGONS 1 - -#ifdef UNICODE -#define wglUseFontOutlines wglUseFontOutlinesW -#else -#define wglUseFontOutlines wglUseFontOutlinesA -#endif - - WINGDIAPI WINBOOL WINAPI wglUseFontOutlinesA(HDC,DWORD,DWORD,DWORD,FLOAT,FLOAT,int,LPGLYPHMETRICSFLOAT); - WINGDIAPI WINBOOL WINAPI wglUseFontOutlinesW(HDC,DWORD,DWORD,DWORD,FLOAT,FLOAT,int,LPGLYPHMETRICSFLOAT); - - typedef struct tagLAYERPLANEDESCRIPTOR { - WORD nSize; - WORD nVersion; - DWORD dwFlags; - BYTE iPixelType; - BYTE cColorBits; - BYTE cRedBits; - BYTE cRedShift; - BYTE cGreenBits; - BYTE cGreenShift; - BYTE cBlueBits; - BYTE cBlueShift; - BYTE cAlphaBits; - BYTE cAlphaShift; - BYTE cAccumBits; - BYTE cAccumRedBits; - BYTE cAccumGreenBits; - BYTE cAccumBlueBits; - BYTE cAccumAlphaBits; - BYTE cDepthBits; - BYTE cStencilBits; - BYTE cAuxBuffers; - BYTE iLayerPlane; - BYTE bReserved; - COLORREF crTransparent; - } LAYERPLANEDESCRIPTOR,*PLAYERPLANEDESCRIPTOR,*LPLAYERPLANEDESCRIPTOR; - -#define LPD_DOUBLEBUFFER 0x00000001 -#define LPD_STEREO 0x00000002 -#define LPD_SUPPORT_GDI 0x00000010 -#define LPD_SUPPORT_OPENGL 0x00000020 -#define LPD_SHARE_DEPTH 0x00000040 -#define LPD_SHARE_STENCIL 0x00000080 -#define LPD_SHARE_ACCUM 0x00000100 -#define LPD_SWAP_EXCHANGE 0x00000200 -#define LPD_SWAP_COPY 0x00000400 -#define LPD_TRANSPARENT 0x00001000 - -#define LPD_TYPE_RGBA 0 -#define LPD_TYPE_COLORINDEX 1 - -#define WGL_SWAP_MAIN_PLANE 0x00000001 -#define WGL_SWAP_OVERLAY1 0x00000002 -#define WGL_SWAP_OVERLAY2 0x00000004 -#define WGL_SWAP_OVERLAY3 0x00000008 -#define WGL_SWAP_OVERLAY4 0x00000010 -#define WGL_SWAP_OVERLAY5 0x00000020 -#define WGL_SWAP_OVERLAY6 0x00000040 -#define WGL_SWAP_OVERLAY7 0x00000080 -#define WGL_SWAP_OVERLAY8 0x00000100 -#define WGL_SWAP_OVERLAY9 0x00000200 -#define WGL_SWAP_OVERLAY10 0x00000400 -#define WGL_SWAP_OVERLAY11 0x00000800 -#define WGL_SWAP_OVERLAY12 0x00001000 -#define WGL_SWAP_OVERLAY13 0x00002000 -#define WGL_SWAP_OVERLAY14 0x00004000 -#define WGL_SWAP_OVERLAY15 0x00008000 -#define WGL_SWAP_UNDERLAY1 0x00010000 -#define WGL_SWAP_UNDERLAY2 0x00020000 -#define WGL_SWAP_UNDERLAY3 0x00040000 -#define WGL_SWAP_UNDERLAY4 0x00080000 -#define WGL_SWAP_UNDERLAY5 0x00100000 -#define WGL_SWAP_UNDERLAY6 0x00200000 -#define WGL_SWAP_UNDERLAY7 0x00400000 -#define WGL_SWAP_UNDERLAY8 0x00800000 -#define WGL_SWAP_UNDERLAY9 0x01000000 -#define WGL_SWAP_UNDERLAY10 0x02000000 -#define WGL_SWAP_UNDERLAY11 0x04000000 -#define WGL_SWAP_UNDERLAY12 0x08000000 -#define WGL_SWAP_UNDERLAY13 0x10000000 -#define WGL_SWAP_UNDERLAY14 0x20000000 -#define WGL_SWAP_UNDERLAY15 0x40000000 - - WINGDIAPI WINBOOL WINAPI wglDescribeLayerPlane(HDC,int,int,UINT,LPLAYERPLANEDESCRIPTOR); - WINGDIAPI int WINAPI wglSetLayerPaletteEntries(HDC,int,int,int,CONST COLORREF *); - WINGDIAPI int WINAPI wglGetLayerPaletteEntries(HDC,int,int,int,COLORREF *); - WINGDIAPI WINBOOL WINAPI wglRealizeLayerPalette(HDC,int,WINBOOL); - WINGDIAPI WINBOOL WINAPI wglSwapLayerBuffers(HDC,UINT); - - typedef struct _WGLSWAP { - HDC hdc; - UINT uiFlags; - } WGLSWAP,*PWGLSWAP,*LPWGLSWAP; - -#define WGL_SWAPMULTIPLE_MAX 16 - - WINGDIAPI DWORD WINAPI wglSwapMultipleBuffers(UINT,CONST WGLSWAP *); -#endif - -#ifdef __cplusplus -} -#endif -#endif diff --git a/05/tcc-final-old/win32/include/winapi/winnt.h b/05/tcc-final-old/win32/include/winapi/winnt.h deleted file mode 100644 index 4cf685d..0000000 --- a/05/tcc-final-old/win32/include/winapi/winnt.h +++ /dev/null @@ -1,5835 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _WINNT_ -#define _WINNT_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#define ANYSIZE_ARRAY 1 - -//gr #include - -#define RESTRICTED_POINTER - -#ifndef __CRT_UNALIGNED -#define __CRT_UNALIGNED -#endif - -#if defined(__ia64__) || defined(__x86_64) -#define UNALIGNED __CRT_UNALIGNED -#ifdef _WIN64 -#define UNALIGNED64 __CRT_UNALIGNED -#else -#define UNALIGNED64 -#endif -#else -#define UNALIGNED -#define UNALIGNED64 -#endif - -#if !defined(I_X86_) && !defined(_IA64_) && !defined(_AMD64_) && (defined(_X86_) && !defined(__x86_64)) -#define I_X86_ -#endif - -#if !defined(I_X86_) && !defined(_IA64_) && !defined(_AMD64_) && defined(__x86_64) -#define _AMD64_ -#endif - -#if !defined(I_X86_) && !(defined(_X86_) && !defined(__x86_64)) && !defined(_AMD64_) && defined(__ia64__) -#if !defined(_IA64_) -#define _IA64_ -#endif -#endif - - -#ifdef _WIN64 -#define MAX_NATURAL_ALIGNMENT sizeof(ULONGLONG) -#define MEMORY_ALLOCATION_ALIGNMENT 16 -#else -#define MAX_NATURAL_ALIGNMENT sizeof(DWORD) -#define MEMORY_ALLOCATION_ALIGNMENT 8 -#endif - -#ifdef __cplusplus -#define TYPE_ALIGNMENT(t) __alignof__ (t) -#else -#define TYPE_ALIGNMENT(t) FIELD_OFFSET(struct { char x; t test; },test) -#endif - -#ifdef _WIN64 -#ifdef _AMD64_ -#define PROBE_ALIGNMENT(_s) TYPE_ALIGNMENT(DWORD) -#elif defined(_IA64_) -#define PROBE_ALIGNMENT(_s) (TYPE_ALIGNMENT(_s) > TYPE_ALIGNMENT(DWORD) ? TYPE_ALIGNMENT(_s) : TYPE_ALIGNMENT(DWORD)) -#else -#error No Target Architecture -#endif -#define PROBE_ALIGNMENT32(_s) TYPE_ALIGNMENT(DWORD) -#else -#define PROBE_ALIGNMENT(_s) TYPE_ALIGNMENT(DWORD) -#endif - -#define C_ASSERT(e) typedef char __C_ASSERT__[(e)?1:-1] - -#include - -#if defined(_X86_) || defined(__ia64__) || defined(__x86_64) -#define DECLSPEC_IMPORT __declspec(dllimport) -#else -#define DECLSPEC_IMPORT -#endif - -#ifndef DECLSPEC_NORETURN -#define DECLSPEC_NORETURN __declspec(noreturn) -#endif - -#ifndef DECLSPEC_ALIGN -#define DECLSPEC_ALIGN(x) __attribute__ ((aligned(x))) -#endif - -#ifndef SYSTEM_CACHE_ALIGNMENT_SIZE -#if defined(_AMD64_) || defined(I_X86_) -#define SYSTEM_CACHE_ALIGNMENT_SIZE 64 -#else -#define SYSTEM_CACHE_ALIGNMENT_SIZE 128 -#endif -#endif - -#ifndef DECLSPEC_CACHEALIGN -#define DECLSPEC_CACHEALIGN DECLSPEC_ALIGN(SYSTEM_CACHE_ALIGNMENT_SIZE) -#endif - -#ifndef DECLSPEC_UUID -#define DECLSPEC_UUID(x) -#endif - -#ifndef DECLSPEC_NOVTABLE -#define DECLSPEC_NOVTABLE -#endif - -#ifndef DECLSPEC_SELECTANY -#define DECLSPEC_SELECTANY __declspec(selectany) -#endif - -#ifndef NOP_FUNCTION -#define NOP_FUNCTION (void)0 -#endif - -#ifndef DECLSPEC_NOINLINE -#define DECLSPEC_NOINLINE -#endif - -#ifndef FORCEINLINE -#define FORCEINLINE static __inline__ -#endif - -#ifndef DECLSPEC_DEPRECATED -#define DECLSPEC_DEPRECATED __declspec(deprecated) -#define DEPRECATE_SUPPORTED -#endif - -#define DECLSPEC_DEPRECATED_DDK -#define PRAGMA_DEPRECATED_DDK 0 - - typedef void *PVOID; - typedef void *PVOID64; - -#define NTAPI __stdcall -#define NTSYSAPI DECLSPEC_IMPORT -#define NTSYSCALLAPI DECLSPEC_IMPORT - -#ifndef VOID -#define VOID void - typedef char CHAR; - typedef short SHORT; - typedef long LONG; -#endif - - typedef wchar_t WCHAR; - typedef WCHAR *PWCHAR,*LPWCH,*PWCH; - typedef CONST WCHAR *LPCWCH,*PCWCH; - typedef WCHAR *NWPSTR,*LPWSTR,*PWSTR; - typedef PWSTR *PZPWSTR; - typedef CONST PWSTR *PCZPWSTR; - typedef WCHAR UNALIGNED *LPUWSTR,*PUWSTR; - typedef CONST WCHAR *LPCWSTR,*PCWSTR; - typedef PCWSTR *PZPCWSTR; - typedef CONST WCHAR UNALIGNED *LPCUWSTR,*PCUWSTR; - typedef CHAR *PCHAR,*LPCH,*PCH; - typedef CONST CHAR *LPCCH,*PCCH; - typedef CHAR *NPSTR,*LPSTR,*PSTR; - typedef PSTR *PZPSTR; - typedef CONST PSTR *PCZPSTR; - typedef CONST CHAR *LPCSTR,*PCSTR; - typedef PCSTR *PZPCSTR; - -#ifdef UNICODE -#ifndef _TCHAR_DEFINED -#define _TCHAR_DEFINED - typedef WCHAR TCHAR,*PTCHAR; - typedef WCHAR TBYTE ,*PTBYTE; -#endif - - typedef LPWSTR LPTCH,PTCH; - typedef LPWSTR PTSTR,LPTSTR; - typedef LPCWSTR PCTSTR,LPCTSTR; - typedef LPUWSTR PUTSTR,LPUTSTR; - typedef LPCUWSTR PCUTSTR,LPCUTSTR; - typedef LPWSTR LP; -#define __TEXT(quote) L##quote -#else -#ifndef _TCHAR_DEFINED -#define _TCHAR_DEFINED - typedef char TCHAR,*PTCHAR; - typedef unsigned char TBYTE ,*PTBYTE; -#endif - - typedef LPSTR LPTCH,PTCH; - typedef LPSTR PTSTR,LPTSTR,PUTSTR,LPUTSTR; - typedef LPCSTR PCTSTR,LPCTSTR,PCUTSTR,LPCUTSTR; -#define __TEXT(quote) quote -#endif - -#define TEXT(quote) __TEXT(quote) - - typedef SHORT *PSHORT; - typedef LONG *PLONG; - - typedef void *HANDLE; -#define DECLARE_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name - typedef HANDLE *PHANDLE; - - typedef BYTE FCHAR; - typedef WORD FSHORT; - typedef DWORD FLONG; - -#ifndef _HRESULT_DEFINED -#define _HRESULT_DEFINED - typedef LONG HRESULT; -#endif - -#ifdef __cplusplus -#define EXTERN_C extern "C" -#else -#define EXTERN_C extern -#endif - -#define STDMETHODCALLTYPE WINAPI -#define STDMETHODVCALLTYPE __cdecl -#define STDAPICALLTYPE WINAPI -#define STDAPIVCALLTYPE __cdecl -#define STDAPI EXTERN_C HRESULT WINAPI -#define STDAPI_(type) EXTERN_C type WINAPI -#define STDMETHODIMP HRESULT WINAPI -#define STDMETHODIMP_(type) type WINAPI -#define STDAPIV EXTERN_C HRESULT STDAPIVCALLTYPE -#define STDAPIV_(type) EXTERN_C type STDAPIVCALLTYPE -#define STDMETHODIMPV HRESULT STDMETHODVCALLTYPE -#define STDMETHODIMPV_(type) type STDMETHODVCALLTYPE - - typedef char CCHAR; -#ifndef _LCID_DEFINED -#define _LCID_DEFINED -typedef DWORD LCID; -#endif - typedef PDWORD PLCID; -#ifndef _LANGID_DEFINED -#define _LANGID_DEFINED - typedef WORD LANGID; -#endif -#define APPLICATION_ERROR_MASK 0x20000000 -#define ERROR_SEVERITY_SUCCESS 0x00000000 -#define ERROR_SEVERITY_INFORMATIONAL 0x40000000 -#define ERROR_SEVERITY_WARNING 0x80000000 -#define ERROR_SEVERITY_ERROR 0xC0000000 - -#ifdef __ia64__ - __declspec(align(16)) -#endif - typedef struct _FLOAT128 { - __int64 LowPart; - __int64 HighPart; - } FLOAT128; - - typedef FLOAT128 *PFLOAT128; - -#define _ULONGLONG_ -#if((!(defined(_X86_) && !defined(__x86_64)) || (defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 64))) - typedef __int64 LONGLONG; - typedef unsigned __int64 ULONGLONG; - -#define MAXLONGLONG (0x7fffffffffffffff) -#else - - typedef double LONGLONG; - typedef double ULONGLONG; -#endif - - typedef LONGLONG *PLONGLONG; - typedef ULONGLONG *PULONGLONG; - - typedef LONGLONG USN; - - typedef union _LARGE_INTEGER { - struct { - DWORD LowPart; - LONG HighPart; - }; - struct { - DWORD LowPart; - LONG HighPart; - } u; - LONGLONG QuadPart; - } LARGE_INTEGER; - - typedef LARGE_INTEGER *PLARGE_INTEGER; - - typedef union _ULARGE_INTEGER { - struct { - DWORD LowPart; - DWORD HighPart; - }; - struct { - DWORD LowPart; - DWORD HighPart; - } u; - ULONGLONG QuadPart; - } ULARGE_INTEGER; - - typedef ULARGE_INTEGER *PULARGE_INTEGER; - - typedef struct _LUID { - DWORD LowPart; - LONG HighPart; - } LUID,*PLUID; - -#define _DWORDLONG_ - typedef ULONGLONG DWORDLONG; - typedef DWORDLONG *PDWORDLONG; - -#ifdef RC_INVOKED -#define Int32x32To64(a,b) ((LONGLONG)((LONG)(a)) *(LONGLONG)((LONG)(b))) -#define UInt32x32To64(a,b) ((ULONGLONG)((DWORD)(a)) *(ULONGLONG)((DWORD)(b))) -#define Int64ShrlMod32(a,b) ((ULONGLONG)(a) >> (b)) -#elif (defined(_X86_) && !defined(__x86_64)) -#define Int32x32To64(a,b) (LONGLONG)((LONGLONG)(LONG)(a) *(LONG)(b)) -#define UInt32x32To64(a,b) (ULONGLONG)((ULONGLONG)(DWORD)(a) *(DWORD)(b)) -#define Int64ShrlMod32(a,b) ((DWORDLONG)(a)>>(b)) -#elif defined(__ia64__) || defined(__x86_64) -#define Int32x32To64(a,b) ((LONGLONG)((LONG)(a)) *(LONGLONG)((LONG)(b))) -#define UInt32x32To64(a,b) ((ULONGLONG)((DWORD)(a)) *(ULONGLONG)((DWORD)(b))) -#define Int64ShrlMod32(a,b) ((ULONGLONG)(a) >> (b)) -#else -#error Must define a target architecture. -#endif - -#define Int64ShraMod32(a,b) ((LONGLONG)(a) >> (b)) -#define Int64ShllMod32(a,b) ((ULONGLONG)(a) << (b)) - -#ifdef __cplusplus - extern "C" { -#endif - -#ifdef __x86_64 - -#define RotateLeft8 _rotl8 -#define RotateLeft16 _rotl16 -#define RotateRight8 _rotr8 -#define RotateRight16 _rotr16 - - unsigned char __cdecl _rotl8(unsigned char Value,unsigned char Shift); - unsigned short __cdecl _rotl16(unsigned short Value,unsigned char Shift); - unsigned char __cdecl _rotr8(unsigned char Value,unsigned char Shift); - unsigned short __cdecl _rotr16(unsigned short Value,unsigned char Shift); -#endif - -#define RotateLeft32 _rotl -#define RotateLeft64 _rotl64 -#define RotateRight32 _rotr -#define RotateRight64 _rotr64 - - unsigned int __cdecl _rotl(unsigned int Value,int Shift); - unsigned __int64 __cdecl _rotl64(unsigned __int64 Value,int Shift); - unsigned int __cdecl _rotr(unsigned int Value,int Shift); - unsigned __int64 __cdecl _rotr64(unsigned __int64 Value,int Shift); -#ifdef __cplusplus - } -#endif - -#define ANSI_NULL ((CHAR)0) -#define UNICODE_NULL ((WCHAR)0) -#define UNICODE_STRING_MAX_BYTES ((WORD) 65534) -#define UNICODE_STRING_MAX_CHARS (32767) - -#ifndef _BOOLEAN_ -#define _BOOLEAN_ - typedef BYTE BOOLEAN; -#endif - typedef BOOLEAN *PBOOLEAN; - - typedef struct _LIST_ENTRY { - struct _LIST_ENTRY *Flink; - struct _LIST_ENTRY *Blink; - } LIST_ENTRY,*PLIST_ENTRY,*RESTRICTED_POINTER PRLIST_ENTRY; - - typedef struct _SINGLE_LIST_ENTRY { - struct _SINGLE_LIST_ENTRY *Next; - } SINGLE_LIST_ENTRY,*PSINGLE_LIST_ENTRY; - - typedef struct LIST_ENTRY32 { - DWORD Flink; - DWORD Blink; - } LIST_ENTRY32; - typedef LIST_ENTRY32 *PLIST_ENTRY32; - - typedef struct LIST_ENTRY64 { - ULONGLONG Flink; - ULONGLONG Blink; - } LIST_ENTRY64; - typedef LIST_ENTRY64 *PLIST_ENTRY64; - -#include - -#ifndef __OBJECTID_DEFINED -#define __OBJECTID_DEFINED - typedef struct _OBJECTID { - GUID Lineage; - DWORD Uniquifier; - } OBJECTID; -#endif - -#define MINCHAR 0x80 -#define MAXCHAR 0x7f -#define MINSHORT 0x8000 -#define MAXSHORT 0x7fff -#define MINLONG 0x80000000 -#define MAXLONG 0x7fffffff -#define MAXBYTE 0xff -#define MAXWORD 0xffff -#define MAXDWORD 0xffffffff - -#define FIELD_OFFSET(type,field) ((LONG)(LONG_PTR)&(((type *)0)->field)) -#define RTL_FIELD_SIZE(type,field) (sizeof(((type *)0)->field)) -#define RTL_SIZEOF_THROUGH_FIELD(type,field) (FIELD_OFFSET(type,field) + RTL_FIELD_SIZE(type,field)) -#define RTL_CONTAINS_FIELD(Struct,Size,Field) ((((PCHAR)(&(Struct)->Field)) + sizeof((Struct)->Field)) <= (((PCHAR)(Struct))+(Size))) -#define RTL_NUMBER_OF_V1(A) (sizeof(A)/sizeof((A)[0])) -#define RTL_NUMBER_OF_V2(A) RTL_NUMBER_OF_V1(A) - -#ifdef ENABLE_RTL_NUMBER_OF_V2 -#define RTL_NUMBER_OF(A) RTL_NUMBER_OF_V2(A) -#else -#define RTL_NUMBER_OF(A) RTL_NUMBER_OF_V1(A) -#endif - -#define ARRAYSIZE(A) RTL_NUMBER_OF_V2(A) -#define _ARRAYSIZE(A) RTL_NUMBER_OF_V1(A) - -#define RTL_FIELD_TYPE(type,field) (((type*)0)->field) -#define RTL_NUMBER_OF_FIELD(type,field) (RTL_NUMBER_OF(RTL_FIELD_TYPE(type,field))) -#define RTL_PADDING_BETWEEN_FIELDS(T,F1,F2) ((FIELD_OFFSET(T,F2) > FIELD_OFFSET(T,F1)) ? (FIELD_OFFSET(T,F2) - FIELD_OFFSET(T,F1) - RTL_FIELD_SIZE(T,F1)) : (FIELD_OFFSET(T,F1) - FIELD_OFFSET(T,F2) - RTL_FIELD_SIZE(T,F2))) - -#ifdef __cplusplus -#define RTL_CONST_CAST(type) const_cast -#else -#define RTL_CONST_CAST(type) (type) -#endif - -#define RTL_BITS_OF(sizeOfArg) (sizeof(sizeOfArg) *8) -#define RTL_BITS_OF_FIELD(type,field) (RTL_BITS_OF(RTL_FIELD_TYPE(type,field))) -#define CONTAINING_RECORD(address,type,field) ((type *)((PCHAR)(address) - (ULONG_PTR)(&((type *)0)->field))) - -#define VER_SERVER_NT 0x80000000 -#define VER_WORKSTATION_NT 0x40000000 -#define VER_SUITE_SMALLBUSINESS 0x00000001 -#define VER_SUITE_ENTERPRISE 0x00000002 -#define VER_SUITE_BACKOFFICE 0x00000004 -#define VER_SUITE_COMMUNICATIONS 0x00000008 -#define VER_SUITE_TERMINAL 0x00000010 -#define VER_SUITE_SMALLBUSINESS_RESTRICTED 0x00000020 -#define VER_SUITE_EMBEDDEDNT 0x00000040 -#define VER_SUITE_DATACENTER 0x00000080 -#define VER_SUITE_SINGLEUSERTS 0x00000100 -#define VER_SUITE_PERSONAL 0x00000200 -#define VER_SUITE_BLADE 0x00000400 -#define VER_SUITE_EMBEDDED_RESTRICTED 0x00000800 -#define VER_SUITE_SECURITY_APPLIANCE 0x00001000 -#define VER_SUITE_STORAGE_SERVER 0x00002000 -#define VER_SUITE_COMPUTE_SERVER 0x00004000 - -#define PRODUCT_UNDEFINED 0x0 - -#define PRODUCT_ULTIMATE 0x1 -#define PRODUCT_HOME_BASIC 0x2 -#define PRODUCT_HOME_PREMIUM 0x3 -#define PRODUCT_ENTERPRISE 0x4 -#define PRODUCT_HOME_BASIC_N 0x5 -#define PRODUCT_BUSINESS 0x6 -#define PRODUCT_STANDARD_SERVER 0x7 -#define PRODUCT_DATACENTER_SERVER 0x8 -#define PRODUCT_SMALLBUSINESS_SERVER 0x9 -#define PRODUCT_ENTERPRISE_SERVER 0xa -#define PRODUCT_STARTER 0xb -#define PRODUCT_DATACENTER_SERVER_CORE 0xc -#define PRODUCT_STANDARD_SERVER_CORE 0xd -#define PRODUCT_ENTERPRISE_SERVER_CORE 0xe -#define PRODUCT_ENTERPRISE_SERVER_IA64 0xf -#define PRODUCT_BUSINESS_N 0x10 -#define PRODUCT_WEB_SERVER 0x11 -#define PRODUCT_CLUSTER_SERVER 0x12 -#define PRODUCT_HOME_SERVER 0x13 -#define PRODUCT_STORAGE_EXPRESS_SERVER 0x14 -#define PRODUCT_STORAGE_STANDARD_SERVER 0x15 -#define PRODUCT_STORAGE_WORKGROUP_SERVER 0x16 -#define PRODUCT_STORAGE_ENTERPRISE_SERVER 0x17 -#define PRODUCT_SERVER_FOR_SMALLBUSINESS 0x18 -#define PRODUCT_SMALLBUSINESS_SERVER_PREMIUM 0x19 - -#define PRODUCT_UNLICENSED 0xabcdabcd - -#define LANG_NEUTRAL 0x00 -#define LANG_INVARIANT 0x7f - -#define LANG_AFRIKAANS 0x36 -#define LANG_ALBANIAN 0x1c -#define LANG_ALSATIAN 0x84 -#define LANG_AMHARIC 0x5e -#define LANG_ARABIC 0x01 -#define LANG_ARMENIAN 0x2b -#define LANG_ASSAMESE 0x4d -#define LANG_AZERI 0x2c -#define LANG_BASHKIR 0x6d -#define LANG_BASQUE 0x2d -#define LANG_BELARUSIAN 0x23 -#define LANG_BENGALI 0x45 -#define LANG_BRETON 0x7e -#define LANG_BOSNIAN 0x1a -#define LANG_BOSNIAN_NEUTRAL 0x781a -#define LANG_BULGARIAN 0x02 -#define LANG_CATALAN 0x03 -#define LANG_CHINESE 0x04 -#define LANG_CHINESE_SIMPLIFIED 0x04 -#define LANG_CHINESE_TRADITIONAL 0x7c04 -#define LANG_CORSICAN 0x83 -#define LANG_CROATIAN 0x1a -#define LANG_CZECH 0x05 -#define LANG_DANISH 0x06 -#define LANG_DARI 0x8c -#define LANG_DIVEHI 0x65 -#define LANG_DUTCH 0x13 -#define LANG_ENGLISH 0x09 -#define LANG_ESTONIAN 0x25 -#define LANG_FAEROESE 0x38 -#define LANG_FARSI 0x29 -#define LANG_FILIPINO 0x64 -#define LANG_FINNISH 0x0b -#define LANG_FRENCH 0x0c -#define LANG_FRISIAN 0x62 -#define LANG_GALICIAN 0x56 -#define LANG_GEORGIAN 0x37 -#define LANG_GERMAN 0x07 -#define LANG_GREEK 0x08 -#define LANG_GREENLANDIC 0x6f -#define LANG_GUJARATI 0x47 -#define LANG_HAUSA 0x68 -#define LANG_HEBREW 0x0d -#define LANG_HINDI 0x39 -#define LANG_HUNGARIAN 0x0e -#define LANG_ICELANDIC 0x0f -#define LANG_IGBO 0x70 -#define LANG_INDONESIAN 0x21 -#define LANG_INUKTITUT 0x5d -#define LANG_IRISH 0x3c -#define LANG_ITALIAN 0x10 -#define LANG_JAPANESE 0x11 -#define LANG_KANNADA 0x4b -#define LANG_KASHMIRI 0x60 -#define LANG_KAZAK 0x3f -#define LANG_KHMER 0x53 -#define LANG_KICHE 0x86 -#define LANG_KINYARWANDA 0x87 -#define LANG_KONKANI 0x57 -#define LANG_KOREAN 0x12 -#define LANG_KYRGYZ 0x40 -#define LANG_LAO 0x54 -#define LANG_LATVIAN 0x26 -#define LANG_LITHUANIAN 0x27 -#define LANG_LOWER_SORBIAN 0x2e -#define LANG_LUXEMBOURGISH 0x6e -#define LANG_MACEDONIAN 0x2f -#define LANG_MALAY 0x3e -#define LANG_MALAYALAM 0x4c -#define LANG_MALTESE 0x3a -#define LANG_MANIPURI 0x58 -#define LANG_MAORI 0x81 -#define LANG_MAPUDUNGUN 0x7a -#define LANG_MARATHI 0x4e -#define LANG_MOHAWK 0x7c -#define LANG_MONGOLIAN 0x50 -#define LANG_NEPALI 0x61 -#define LANG_NORWEGIAN 0x14 -#define LANG_OCCITAN 0x82 -#define LANG_ORIYA 0x48 -#define LANG_PASHTO 0x63 -#define LANG_PERSIAN 0x29 -#define LANG_POLISH 0x15 -#define LANG_PORTUGUESE 0x16 -#define LANG_PUNJABI 0x46 -#define LANG_QUECHUA 0x6b -#define LANG_ROMANIAN 0x18 -#define LANG_RUSSIAN 0x19 -#define LANG_SAMI 0x3b -#define LANG_ROMANSH 0x17 -#define LANG_SANSKRIT 0x4f -#define LANG_SERBIAN 0x1a -#define LANG_SERBIAN_NEUTRAL 0x7c1a -#define LANG_SINDHI 0x59 -#define LANG_SINHALESE 0x5b -#define LANG_SLOVAK 0x1b -#define LANG_SLOVENIAN 0x24 -#define LANG_SOTHO 0x6c -#define LANG_SPANISH 0x0a -#define LANG_SWAHILI 0x41 -#define LANG_SWEDISH 0x1d -#define LANG_SYRIAC 0x5a -#define LANG_TAJIK 0x28 -#define LANG_TAMAZIGHT 0x5f -#define LANG_TAMIL 0x49 -#define LANG_TATAR 0x44 -#define LANG_TELUGU 0x4a -#define LANG_THAI 0x1e -#define LANG_TIBETAN 0x51 -#define LANG_TIGRIGNA 0x73 -#define LANG_TSWANA 0x32 -#define LANG_TURKISH 0x1f -#define LANG_TURKMEN 0x42 -#define LANG_UIGHUR 0x80 -#define LANG_UKRAINIAN 0x22 -#define LANG_UPPER_SORBIAN 0x2e -#define LANG_URDU 0x20 -#define LANG_UZBEK 0x43 -#define LANG_VIETNAMESE 0x2a -#define LANG_WELSH 0x52 -#define LANG_WOLOF 0x88 -#define LANG_XHOSA 0x34 -#define LANG_YAKUT 0x85 -#define LANG_YI 0x78 -#define LANG_YORUBA 0x6a -#define LANG_ZULU 0x35 - -#define SUBLANG_NEUTRAL 0x0 -#define SUBLANG_DEFAULT 0x1 -#define SUBLANG_SYS_DEFAULT 0x2 -#define SUBLANG_CUSTOM_DEFAULT 0x3 -#define SUBLANG_CUSTOM_UNSPECIFIED 0x4 -#define SUBLANG_UI_CUSTOM_DEFAULT 0x5 - -#define SUBLANG_ARABIC_SAUDI_ARABIA 0x01 -#define SUBLANG_ARABIC_IRAQ 0x02 -#define SUBLANG_ARABIC_EGYPT 0x03 -#define SUBLANG_ARABIC_LIBYA 0x04 -#define SUBLANG_ARABIC_ALGERIA 0x05 -#define SUBLANG_ARABIC_MOROCCO 0x06 -#define SUBLANG_ARABIC_TUNISIA 0x07 -#define SUBLANG_ARABIC_OMAN 0x08 -#define SUBLANG_ARABIC_YEMEN 0x09 -#define SUBLANG_ARABIC_SYRIA 0x0a -#define SUBLANG_ARABIC_JORDAN 0x0b -#define SUBLANG_ARABIC_LEBANON 0x0c -#define SUBLANG_ARABIC_KUWAIT 0x0d -#define SUBLANG_ARABIC_UAE 0x0e -#define SUBLANG_ARABIC_BAHRAIN 0x0f -#define SUBLANG_ARABIC_QATAR 0x10 -#define SUBLANG_AZERI_LATIN 0x01 -#define SUBLANG_AZERI_CYRILLIC 0x02 -#define SUBLANG_CHINESE_TRADITIONAL 0x01 -#define SUBLANG_CHINESE_SIMPLIFIED 0x02 -#define SUBLANG_CHINESE_HONGKONG 0x03 -#define SUBLANG_CHINESE_SINGAPORE 0x04 -#define SUBLANG_CHINESE_MACAU 0x05 -#define SUBLANG_DUTCH 0x01 -#define SUBLANG_DUTCH_BELGIAN 0x02 -#define SUBLANG_ENGLISH_US 0x01 -#define SUBLANG_ENGLISH_UK 0x02 -#define SUBLANG_ENGLISH_AUS 0x03 -#define SUBLANG_ENGLISH_CAN 0x04 -#define SUBLANG_ENGLISH_NZ 0x05 -#define SUBLANG_ENGLISH_EIRE 0x06 -#define SUBLANG_ENGLISH_SOUTH_AFRICA 0x07 -#define SUBLANG_ENGLISH_JAMAICA 0x08 -#define SUBLANG_ENGLISH_CARIBBEAN 0x09 -#define SUBLANG_ENGLISH_BELIZE 0x0a -#define SUBLANG_ENGLISH_TRINIDAD 0x0b -#define SUBLANG_ENGLISH_ZIMBABWE 0x0c -#define SUBLANG_ENGLISH_PHILIPPINES 0x0d -#define SUBLANG_FRENCH 0x01 -#define SUBLANG_FRENCH_BELGIAN 0x02 -#define SUBLANG_FRENCH_CANADIAN 0x03 -#define SUBLANG_FRENCH_SWISS 0x04 -#define SUBLANG_FRENCH_LUXEMBOURG 0x05 -#define SUBLANG_FRENCH_MONACO 0x06 -#define SUBLANG_GERMAN 0x01 -#define SUBLANG_GERMAN_SWISS 0x02 -#define SUBLANG_GERMAN_AUSTRIAN 0x03 -#define SUBLANG_GERMAN_LUXEMBOURG 0x04 -#define SUBLANG_GERMAN_LIECHTENSTEIN 0x05 -#define SUBLANG_ITALIAN 0x01 -#define SUBLANG_ITALIAN_SWISS 0x02 -#define SUBLANG_KASHMIRI_SASIA 0x02 -#define SUBLANG_KASHMIRI_INDIA 0x02 -#define SUBLANG_KOREAN 0x01 -#define SUBLANG_LITHUANIAN 0x01 -#define SUBLANG_MALAY_MALAYSIA 0x01 -#define SUBLANG_MALAY_BRUNEI_DARUSSALAM 0x02 -#define SUBLANG_NEPALI_INDIA 0x02 -#define SUBLANG_NORWEGIAN_BOKMAL 0x01 -#define SUBLANG_NORWEGIAN_NYNORSK 0x02 -#define SUBLANG_PORTUGUESE 0x02 -#define SUBLANG_PORTUGUESE_BRAZILIAN 0x01 -#define SUBLANG_SERBIAN_LATIN 0x02 -#define SUBLANG_SERBIAN_CYRILLIC 0x03 -#define SUBLANG_SPANISH 0x01 -#define SUBLANG_SPANISH_MEXICAN 0x02 -#define SUBLANG_SPANISH_MODERN 0x03 -#define SUBLANG_SPANISH_GUATEMALA 0x04 -#define SUBLANG_SPANISH_COSTA_RICA 0x05 -#define SUBLANG_SPANISH_PANAMA 0x06 -#define SUBLANG_SPANISH_DOMINICAN_REPUBLIC 0x07 -#define SUBLANG_SPANISH_VENEZUELA 0x08 -#define SUBLANG_SPANISH_COLOMBIA 0x09 -#define SUBLANG_SPANISH_PERU 0x0a -#define SUBLANG_SPANISH_ARGENTINA 0x0b -#define SUBLANG_SPANISH_ECUADOR 0x0c -#define SUBLANG_SPANISH_CHILE 0x0d -#define SUBLANG_SPANISH_URUGUAY 0x0e -#define SUBLANG_SPANISH_PARAGUAY 0x0f -#define SUBLANG_SPANISH_BOLIVIA 0x10 -#define SUBLANG_SPANISH_EL_SALVADOR 0x11 -#define SUBLANG_SPANISH_HONDURAS 0x12 -#define SUBLANG_SPANISH_NICARAGUA 0x13 -#define SUBLANG_SPANISH_PUERTO_RICO 0x14 -#define SUBLANG_SWEDISH 0x01 -#define SUBLANG_SWEDISH_FINLAND 0x02 -#define SUBLANG_URDU_PAKISTAN 0x01 -#define SUBLANG_URDU_INDIA 0x02 -#define SUBLANG_UZBEK_LATIN 0x01 -#define SUBLANG_UZBEK_CYRILLIC 0x02 - -#define SORT_DEFAULT 0x0 -#define SORT_INVARIANT_MATH 0x1 - -#define SORT_JAPANESE_XJIS 0x0 -#define SORT_JAPANESE_UNICODE 0x1 -#define SORT_JAPANESE_RADICALSTROKE 0x4 - -#define SORT_CHINESE_BIG5 0x0 -#define SORT_CHINESE_PRCP 0x0 -#define SORT_CHINESE_UNICODE 0x1 -#define SORT_CHINESE_PRC 0x2 -#define SORT_CHINESE_BOPOMOFO 0x3 - -#define SORT_KOREAN_KSC 0x0 -#define SORT_KOREAN_UNICODE 0x1 - -#define SORT_GERMAN_PHONE_BOOK 0x1 - -#define SORT_HUNGARIAN_DEFAULT 0x0 -#define SORT_HUNGARIAN_TECHNICAL 0x1 - -#define SORT_GEORGIAN_TRADITIONAL 0x0 -#define SORT_GEORGIAN_MODERN 0x1 - -#define MAKELANGID(p,s) ((((WORD)(s)) << 10) | (WORD)(p)) -#define PRIMARYLANGID(lgid) ((WORD)(lgid) & 0x3ff) -#define SUBLANGID(lgid) ((WORD)(lgid) >> 10) - -#define NLS_VALID_LOCALE_MASK 0x000fffff - -#define MAKELCID(lgid,srtid) ((DWORD)((((DWORD)((WORD)(srtid))) << 16) | ((DWORD)((WORD)(lgid))))) -#define MAKESORTLCID(lgid,srtid,ver) ((DWORD)((MAKELCID(lgid,srtid)) | (((DWORD)((WORD)(ver))) << 20))) -#define LANGIDFROMLCID(lcid) ((WORD)(lcid)) -#define SORTIDFROMLCID(lcid) ((WORD)((((DWORD)(lcid)) >> 16) & 0xf)) -#define SORTVERSIONFROMLCID(lcid) ((WORD)((((DWORD)(lcid)) >> 20) & 0xf)) - -#define LOCALE_NAME_MAX_LENGTH 85 -#define LANG_SYSTEM_DEFAULT (MAKELANGID(LANG_NEUTRAL,SUBLANG_SYS_DEFAULT)) -#define LANG_USER_DEFAULT (MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT)) - -#define LOCALE_SYSTEM_DEFAULT (MAKELCID(LANG_SYSTEM_DEFAULT,SORT_DEFAULT)) -#define LOCALE_USER_DEFAULT (MAKELCID(LANG_USER_DEFAULT,SORT_DEFAULT)) - -#define LOCALE_NEUTRAL (MAKELCID(MAKELANGID(LANG_NEUTRAL,SUBLANG_NEUTRAL),SORT_DEFAULT)) - -#define LOCALE_CUSTOM_DEFAULT (MAKELCID(MAKELANGID(LANG_NEUTRAL, SUBLANG_CUSTOM_DEFAULT), SORT_DEFAULT)) -#define LOCALE_CUSTOM_UNSPECIFIED (MAKELCID(MAKELANGID(LANG_NEUTRAL, SUBLANG_CUSTOM_UNSPECIFIED), SORT_DEFAULT)) -#define LOCALE_CUSTOM_UI_DEFAULT (MAKELCID(MAKELANGID(LANG_NEUTRAL, SUBLANG_UI_CUSTOM_DEFAULT), SORT_DEFAULT)) - -#define LOCALE_INVARIANT (MAKELCID(MAKELANGID(LANG_INVARIANT,SUBLANG_NEUTRAL),SORT_DEFAULT)) - -#define UNREFERENCED_PARAMETER(P) (P) -#define DBG_UNREFERENCED_PARAMETER(P) (P) -#define DBG_UNREFERENCED_LOCAL_VARIABLE(V) (V) - -#define DEFAULT_UNREACHABLE - -#ifndef WIN32_NO_STATUS -#define STATUS_WAIT_0 ((DWORD)0x00000000L) -#define STATUS_ABANDONED_WAIT_0 ((DWORD)0x00000080L) -#define STATUS_USER_APC ((DWORD)0x000000C0L) -#define STATUS_TIMEOUT ((DWORD)0x00000102L) -#define STATUS_PENDING ((DWORD)0x00000103L) -#define DBG_EXCEPTION_HANDLED ((DWORD)0x00010001L) -#define DBG_CONTINUE ((DWORD)0x00010002L) -#define STATUS_SEGMENT_NOTIFICATION ((DWORD)0x40000005L) -#define DBG_TERMINATE_THREAD ((DWORD)0x40010003L) -#define DBG_TERMINATE_PROCESS ((DWORD)0x40010004L) -#define DBG_CONTROL_C ((DWORD)0x40010005L) -#define DBG_CONTROL_BREAK ((DWORD)0x40010008L) -#define DBG_COMMAND_EXCEPTION ((DWORD)0x40010009L) -#define STATUS_GUARD_PAGE_VIOLATION ((DWORD)0x80000001L) -#define STATUS_DATATYPE_MISALIGNMENT ((DWORD)0x80000002L) -#define STATUS_BREAKPOINT ((DWORD)0x80000003L) -#define STATUS_SINGLE_STEP ((DWORD)0x80000004L) -#define DBG_EXCEPTION_NOT_HANDLED ((DWORD)0x80010001L) -#define STATUS_ACCESS_VIOLATION ((DWORD)0xC0000005L) -#define STATUS_IN_PAGE_ERROR ((DWORD)0xC0000006L) -#define STATUS_INVALID_HANDLE ((DWORD)0xC0000008L) -#define STATUS_NO_MEMORY ((DWORD)0xC0000017L) -#define STATUS_ILLEGAL_INSTRUCTION ((DWORD)0xC000001DL) -#define STATUS_NONCONTINUABLE_EXCEPTION ((DWORD)0xC0000025L) -#define STATUS_INVALID_DISPOSITION ((DWORD)0xC0000026L) -#define STATUS_ARRAY_BOUNDS_EXCEEDED ((DWORD)0xC000008CL) -#define STATUS_FLOAT_DENORMAL_OPERAND ((DWORD)0xC000008DL) -#define STATUS_FLOAT_DIVIDE_BY_ZERO ((DWORD)0xC000008EL) -#define STATUS_FLOAT_INEXACT_RESULT ((DWORD)0xC000008FL) -#define STATUS_FLOAT_INVALID_OPERATION ((DWORD)0xC0000090L) -#define STATUS_FLOAT_OVERFLOW ((DWORD)0xC0000091L) -#define STATUS_FLOAT_STACK_CHECK ((DWORD)0xC0000092L) -#define STATUS_FLOAT_UNDERFLOW ((DWORD)0xC0000093L) -#define STATUS_INTEGER_DIVIDE_BY_ZERO ((DWORD)0xC0000094L) -#define STATUS_INTEGER_OVERFLOW ((DWORD)0xC0000095L) -#define STATUS_PRIVILEGED_INSTRUCTION ((DWORD)0xC0000096L) -#define STATUS_STACK_OVERFLOW ((DWORD)0xC00000FDL) -#define STATUS_CONTROL_C_EXIT ((DWORD)0xC000013AL) -#define STATUS_FLOAT_MULTIPLE_FAULTS ((DWORD)0xC00002B4L) -#define STATUS_FLOAT_MULTIPLE_TRAPS ((DWORD)0xC00002B5L) -#define STATUS_REG_NAT_CONSUMPTION ((DWORD)0xC00002C9L) -#define STATUS_SXS_EARLY_DEACTIVATION ((DWORD)0xC015000FL) -#define STATUS_SXS_INVALID_DEACTIVATION ((DWORD)0xC0150010L) -#endif - -#define MAXIMUM_WAIT_OBJECTS 64 -#define MAXIMUM_SUSPEND_COUNT MAXCHAR - - typedef ULONG_PTR KSPIN_LOCK; - typedef KSPIN_LOCK *PKSPIN_LOCK; - -#ifdef _AMD64_ - -#if defined(__x86_64) && !defined(RC_INVOKED) - -#ifdef __cplusplus - extern "C" { -#endif - -#define BitTest _bittest -#define BitTestAndComplement _bittestandcomplement -#define BitTestAndSet _bittestandset -#define BitTestAndReset _bittestandreset -#define InterlockedBitTestAndSet _interlockedbittestandset -#define InterlockedBitTestAndReset _interlockedbittestandreset -#define BitTest64 _bittest64 -#define BitTestAndComplement64 _bittestandcomplement64 -#define BitTestAndSet64 _bittestandset64 -#define BitTestAndReset64 _bittestandreset64 -#define InterlockedBitTestAndSet64 _interlockedbittestandset64 -#define InterlockedBitTestAndReset64 _interlockedbittestandreset64 - - __CRT_INLINE BOOLEAN _bittest(LONG const *Base,LONG Offset) { - int old = 0; - __asm__ __volatile__("btl %2,%1\n\tsbbl %0,%0 " - :"=r" (old),"=m" ((*(volatile long *) Base)) - :"Ir" (Offset)); - return (BOOLEAN) (old!=0); - } - __CRT_INLINE BOOLEAN _bittestandcomplement(LONG *Base,LONG Offset) { - int old = 0; - __asm__ __volatile__("btcl %2,%1\n\tsbbl %0,%0 " - :"=r" (old),"=m" ((*(volatile long *) Base)) - :"Ir" (Offset)); - return (BOOLEAN) (old!=0); - } - __CRT_INLINE BOOLEAN InterlockedBitTestAndComplement(LONG *Base,LONG Bit) { - int old = 0; - __asm__ __volatile__("lock ; btcl %2,%1\n\tsbbl %0,%0 " - :"=r" (old),"=m" ((*(volatile long *) Base)) - :"Ir" (Bit)); - return (BOOLEAN) (old!=0); - } - __CRT_INLINE BOOLEAN _bittestandset(LONG *Base,LONG Offset) { - int old = 0; - __asm__ __volatile__("btsl %2,%1\n\tsbbl %0,%0 " - :"=r" (old),"=m" ((*(volatile long *) Base)) - :"Ir" (Offset)); - return (BOOLEAN) (old!=0); - } - __CRT_INLINE BOOLEAN _bittestandreset(LONG *Base,LONG Offset) { - int old = 0; - __asm__ __volatile__("btrl %2,%1\n\tsbbl %0,%0 " - :"=r" (old),"=m" ((*(volatile long *) Base)) - :"Ir" (Offset)); - return (BOOLEAN) (old!=0); - } - __CRT_INLINE BOOLEAN _interlockedbittestandset(LONG *Base,LONG Offset) { - int old = 0; - __asm__ __volatile__("lock ; btsl %2,%1\n\tsbbl %0,%0 " - :"=r" (old),"=m" ((*(volatile long *) Base)) - :"Ir" (Offset)); - return (BOOLEAN) (old!=0); - } - __CRT_INLINE BOOLEAN _interlockedbittestandreset(LONG *Base,LONG Offset) { - int old = 0; - __asm__ __volatile__("lock ; btrl %2,%1\n\tsbbl %0,%0 " - :"=r" (old),"=m" ((*(volatile long *) Base)) - :"Ir" (Offset)); - return (BOOLEAN) (old!=0); - } - __CRT_INLINE BOOLEAN _bittest64(LONG64 const *Base,LONG64 Offset) { - int old = 0; - __asm__ __volatile__("btq %2,%1\n\tsbbl %0,%0 " - :"=r" (old),"=m" ((*(volatile long long *) Base)) - :"Ir" (Offset)); - return (BOOLEAN) (old!=0); - } - __CRT_INLINE BOOLEAN _bittestandcomplement64(LONG64 *Base,LONG64 Offset) { - int old = 0; - __asm__ __volatile__("btcq %2,%1\n\tsbbl %0,%0 " - :"=r" (old),"=m" ((*(volatile long long *) Base)) - :"Ir" (Offset)); - return (BOOLEAN) (old!=0); - } - __CRT_INLINE BOOLEAN _bittestandset64(LONG64 *Base,LONG64 Offset) { - int old = 0; - __asm__ __volatile__("btsq %2,%1\n\tsbbl %0,%0 " - :"=r" (old),"=m" ((*(volatile long long *) Base)) - :"Ir" (Offset)); - return (BOOLEAN) (old!=0); - } - __CRT_INLINE BOOLEAN _bittestandreset64(LONG64 *Base,LONG64 Offset) { - int old = 0; - __asm__ __volatile__("btrq %2,%1\n\tsbbl %0,%0 " - :"=r" (old),"=m" ((*(volatile long long *) Base)) - :"Ir" (Offset)); - return (BOOLEAN) (old!=0); - } - __CRT_INLINE BOOLEAN _interlockedbittestandset64(LONG64 *Base,LONG64 Offset) { - int old = 0; - __asm__ __volatile__("lock ; btsq %2,%1\n\tsbbl %0,%0 " - :"=r" (old),"=m" ((*(volatile long long *) Base)) - :"Ir" (Offset)); - return (BOOLEAN) (old!=0); - } - __CRT_INLINE BOOLEAN _interlockedbittestandreset64(LONG64 *Base,LONG64 Offset) { - int old = 0; - __asm__ __volatile__("lock ; btrq %2,%1\n\tsbbl %0,%0 " - :"=r" (old),"=m" ((*(volatile long long *) Base)) - :"Ir" (Offset)); - return (BOOLEAN) (old!=0); - } -#define BitScanForward _BitScanForward -#define BitScanReverse _BitScanReverse -#define BitScanForward64 _BitScanForward64 -#define BitScanReverse64 _BitScanReverse64 - - __CRT_INLINE BOOLEAN _BitScanForward(DWORD *Index,DWORD Mask) { - __asm__ __volatile__("bsfl %1,%0" : "=r" (Mask),"=m" ((*(volatile long *)Index))); - return Mask!=0; - } - __CRT_INLINE BOOLEAN _BitScanReverse(DWORD *Index,DWORD Mask) { - __asm__ __volatile__("bsrl %1,%0" : "=r" (Mask),"=m" ((*(volatile long *)Index))); - return Mask!=0; - } - __CRT_INLINE BOOLEAN _BitScanForward64(DWORD *Index,DWORD64 Mask) { - __asm__ __volatile__("bsfq %1,%0" : "=r" (Mask),"=m" ((*(volatile long long *)Index))); - return Mask!=0; - } - __CRT_INLINE BOOLEAN _BitScanReverse64(DWORD *Index,DWORD64 Mask) { - __asm__ __volatile__("bsrq %1,%0" : "=r" (Mask),"=m" ((*(volatile long long *)Index))); - return Mask!=0; - } - -#define InterlockedIncrement16 _InterlockedIncrement16 -#define InterlockedDecrement16 _InterlockedDecrement16 -#define InterlockedCompareExchange16 _InterlockedCompareExchange16 - -#define InterlockedAnd _InterlockedAnd -#define InterlockedOr _InterlockedOr -#define InterlockedXor _InterlockedXor -#define InterlockedIncrement _InterlockedIncrement -#define InterlockedIncrementAcquire InterlockedIncrement -#define InterlockedIncrementRelease InterlockedIncrement -#define InterlockedDecrement _InterlockedDecrement -#define InterlockedDecrementAcquire InterlockedDecrement -#define InterlockedDecrementRelease InterlockedDecrement -#define InterlockedAdd _InterlockedAdd -#define InterlockedExchange _InterlockedExchange -#define InterlockedExchangeAdd _InterlockedExchangeAdd -#define InterlockedCompareExchange _InterlockedCompareExchange -#define InterlockedCompareExchangeAcquire InterlockedCompareExchange -#define InterlockedCompareExchangeRelease InterlockedCompareExchange - -#define InterlockedAnd64 _InterlockedAnd64 -#define InterlockedAndAffinity InterlockedAnd64 -#define InterlockedOr64 _InterlockedOr64 -#define InterlockedOrAffinity InterlockedOr64 -#define InterlockedXor64 _InterlockedXor64 -#define InterlockedIncrement64 _InterlockedIncrement64 -#define InterlockedDecrement64 _InterlockedDecrement64 -#define InterlockedAdd64 _InterlockedAdd64 -#define InterlockedExchange64 _InterlockedExchange64 -#define InterlockedExchangeAcquire64 InterlockedExchange64 -#define InterlockedExchangeAdd64 _InterlockedExchangeAdd64 -#define InterlockedCompareExchange64 _InterlockedCompareExchange64 -#define InterlockedCompareExchangeAcquire64 InterlockedCompareExchange64 -#define InterlockedCompareExchangeRelease64 InterlockedCompareExchange64 - -#define InterlockedExchangePointer _InterlockedExchangePointer -#define InterlockedCompareExchangePointer _InterlockedCompareExchangePointer -#define InterlockedCompareExchangePointerAcquire _InterlockedCompareExchangePointer -#define InterlockedCompareExchangePointerRelease _InterlockedCompareExchangePointer - -#define InterlockedExchangeAddSizeT(a,b) InterlockedExchangeAdd64((LONG64 *)a,b) -#define InterlockedIncrementSizeT(a) InterlockedIncrement64((LONG64 *)a) -#define InterlockedDecrementSizeT(a) InterlockedDecrement64((LONG64 *)a) - - __CRT_INLINE SHORT InterlockedIncrement16(SHORT volatile *Addend) { - unsigned char c; - unsigned char s; - __asm__ __volatile__( - "lock ; addw $1,%0; sete %1 ; sets %2" - :"=m" (*Addend), "=qm" (c), "=qm" (s) - :"m" (*Addend) : "memory"); - return (c != 0 ? 0 : (s != 0 ? -1 : 1)); - } - __CRT_INLINE SHORT InterlockedDecrement16(SHORT volatile *Addend) { - unsigned char c; - unsigned char s; - __asm__ __volatile__( - "lock ; subw $1,%0; sete %1 ; sets %2" - :"=m" (*Addend), "=qm" (c), "=qm" (s) - :"m" (*Addend) : "memory"); - return (c != 0 ? 0 : (s != 0 ? -1 : 1)); - } - __CRT_INLINE SHORT InterlockedCompareExchange16(SHORT volatile *Destination,SHORT ExChange,SHORT Comperand) { - SHORT prev; - __asm__ __volatile__("lock ; cmpxchgw %w1,%2" - :"=a"(prev) - :"q"(ExChange), "m"(*Destination), "0"(Comperand) - : "memory"); - return prev; - } - __CRT_INLINE LONG InterlockedAnd(LONG volatile *Destination,LONG Value) { - __asm__ __volatile__("lock ; andl %0,%1" - : :"r"(Value),"m"(*Destination) - : "memory"); - return *Destination; - } - __CRT_INLINE LONG InterlockedOr(LONG volatile *Destination,LONG Value) { - __asm__ __volatile__("lock ; orl %0,%1" - : : "r"(Value),"m"(*Destination) : "memory"); - return *Destination; - } - __CRT_INLINE LONG InterlockedXor(LONG volatile *Destination,LONG Value) { - __asm__ __volatile__("lock ; xorl %0,%1" - : : "r"(Value),"m"(*Destination) : "memory"); - return *Destination; - } - // $$$$ - __CRT_INLINE LONG64 InterlockedAnd64(LONG64 volatile *Destination,LONG64 Value) { - __asm__ __volatile__("lock ; andq %0,%1" - : : "r"(Value),"m"(*Destination) : "memory"); - return *Destination; - } - __CRT_INLINE LONG64 InterlockedOr64(LONG64 volatile *Destination,LONG64 Value) { - __asm__ __volatile__("lock ; orq %0,%1" - : : "r"(Value),"m"(*Destination) : "memory"); - return *Destination; - } - __CRT_INLINE LONG64 InterlockedXor64(LONG64 volatile *Destination,LONG64 Value) { - __asm__ __volatile__("lock ; xorq %0,%1" - : : "r"(Value),"m"(*Destination) : "memory"); - return *Destination; - } - __CRT_INLINE LONG InterlockedIncrement(LONG volatile *Addend) { - unsigned char c; - unsigned char s; - __asm__ __volatile__( - "lock ; addl $1,%0; sete %1 ; sets %2" - :"=m" (*Addend), "=qm" (c), "=qm" (s) - :"m" (*Addend) : "memory"); - return (c != 0 ? 0 : (s != 0 ? -1 : 1)); - } - __CRT_INLINE LONG InterlockedDecrement(LONG volatile *Addend) { - unsigned char c; - unsigned char s; - __asm__ __volatile__( - "lock ; subl $1,%0; sete %1 ; sets %2" - :"=m" (*Addend), "=qm" (c), "=qm" (s) - :"m" (*Addend) : "memory"); - return (c != 0 ? 0 : (s != 0 ? -1 : 1)); - } - __CRT_INLINE LONG InterlockedExchange(LONG volatile *Target,LONG Value) { - __asm__ __volatile("lock ; xchgl %0,%1" - : "=r"(Value) - : "m"(*Target),"0"(Value) - : "memory"); - return Value; - } - LONG InterlockedExchangeAdd(LONG volatile *Addend,LONG Value); - -#ifndef _X86AMD64_ - __CRT_INLINE LONG InterlockedAdd(LONG volatile *Addend,LONG Value) { return InterlockedExchangeAdd(Addend,Value) + Value; } -#endif - __CRT_INLINE LONG InterlockedCompareExchange(LONG volatile *Destination,LONG ExChange,LONG Comperand) { - LONG prev; - __asm__ __volatile__("lock ; cmpxchgl %1,%2" : "=a" (prev) : "q" (ExChange),"m" (*Destination), "0" (Comperand) : "memory"); - return prev; - } - __CRT_INLINE LONG64 InterlockedIncrement64(LONG64 volatile *Addend) { - unsigned char c; - unsigned char s; - __asm__ __volatile__( - "lock ; addq $1,%0; sete %1 ; sets %2" - :"=m" (*Addend), "=qm" (c), "=qm" (s) - :"m" (*Addend) : "memory"); - return (c != 0 ? 0 : (s != 0 ? -1 : 1)); - } - __CRT_INLINE LONG64 InterlockedDecrement64(LONG64 volatile *Addend) { - unsigned char c; - unsigned char s; - __asm__ __volatile__( - "lock ; subq $1,%0; sete %1 ; sets %2" - :"=m" (*Addend), "=qm" (c), "=qm" (s) - :"m" (*Addend) : "memory"); - return (c != 0 ? 0 : (s != 0 ? -1 : 1)); - } - __CRT_INLINE LONG64 InterlockedExchange64(LONG64 volatile *Target,LONG64 Value) { - __asm__ __volatile("lock ; xchgq %0,%1" - : "=r"(Value) - : "m"(*Target),"0"(Value) - : "memory"); - return Value; - } - LONG64 InterlockedExchangeAdd64(LONG64 volatile *Addend,LONG64 Value); - -#ifndef _X86AMD64_ - __CRT_INLINE LONG64 InterlockedAdd64(LONG64 volatile *Addend,LONG64 Value) { return InterlockedExchangeAdd64(Addend,Value) + Value; } -#endif - - __CRT_INLINE LONG64 InterlockedCompareExchange64(LONG64 volatile *Destination,LONG64 ExChange,LONG64 Comperand) { - LONG64 prev; - __asm__ __volatile__("lock ; cmpxchgq %1,%2" : "=a" (prev) : "q" (ExChange),"m" (*Destination), "0" (Comperand) : "memory"); - return prev; - } - __CRT_INLINE PVOID InterlockedCompareExchangePointer(PVOID volatile *Destination,PVOID ExChange,PVOID Comperand) { - PVOID prev; - __asm__ __volatile__("lock ; cmpxchgq %1,%2" : "=a" (prev) : "q" (ExChange),"m" (*Destination), "0" (Comperand) : "memory"); - return prev; - } - __CRT_INLINE PVOID InterlockedExchangePointer(PVOID volatile *Target,PVOID Value) { - __asm__ __volatile("lock ; xchgq %0,%1" - : "=r"(Value) - : "m"(*Target),"0"(Value) - : "memory"); - return Value; - } - -#define CacheLineFlush(Address) _mm_clflush(Address) - - VOID _ReadWriteBarrier(VOID); - -#define FastFence __faststorefence -#define LoadFence _mm_lfence -#define MemoryFence _mm_mfence -#define StoreFence _mm_sfence - - VOID __faststorefence(VOID); - VOID _m_prefetchw(volatile CONST VOID *Source); - -//!__TINYC__: #include - -#define YieldProcessor _mm_pause -#define MemoryBarrier __faststorefence -#define PreFetchCacheLine(l,a) _mm_prefetch((CHAR CONST *) a,l) -#define PrefetchForWrite(p) _m_prefetchw(p) -#define ReadForWriteAccess(p) (_m_prefetchw(p),*(p)) - -#define PF_TEMPORAL_LEVEL_1 _MM_HINT_T0 -#define PF_TEMPORAL_LEVEL_2 _MM_HINT_T1 -#define PF_TEMPORAL_LEVEL_3 _MM_HINT_T2 -#define PF_NON_TEMPORAL_LEVEL_ALL _MM_HINT_NTA - -#define ReadMxCsr _mm_getcsr -#define WriteMxCsr _mm_setcsr - - VOID __int2c(VOID); - -#define DbgRaiseAssertionFailure() __int2c() -#define GetCallersEflags() __getcallerseflags() - - unsigned __int32 __getcallerseflags(VOID); - -#define GetSegmentLimit __segmentlimit - - DWORD __segmentlimit(DWORD Selector); - -#define ReadTimeStampCounter() __rdtsc() - - DWORD64 __rdtsc(VOID); - VOID __movsb(PBYTE Destination,BYTE const *Source,SIZE_T Count); - VOID __movsw(PWORD Destination,WORD const *Source,SIZE_T Count); - VOID __movsd(PDWORD Destination,DWORD const *Source,SIZE_T Count); - VOID __movsq(PDWORD64 Destination,DWORD64 const *Source,SIZE_T Count); - VOID __stosb(PBYTE Destination,BYTE Value,SIZE_T Count); - VOID __stosw(PWORD Destination,WORD Value,SIZE_T Count); - VOID __stosd(PDWORD Destination,DWORD Value,SIZE_T Count); - VOID __stosq(PDWORD64 Destination,DWORD64 Value,SIZE_T Count); - -#define MultiplyHigh __mulh -#define UnsignedMultiplyHigh __umulh - - LONGLONG MultiplyHigh(LONGLONG Multiplier,LONGLONG Multiplicand); - ULONGLONG UnsignedMultiplyHigh(ULONGLONG Multiplier,ULONGLONG Multiplicand); - -#define ShiftLeft128 __shiftleft128 -#define ShiftRight128 __shiftright128 - - DWORD64 ShiftLeft128(DWORD64 LowPart,DWORD64 HighPart,BYTE Shift); - DWORD64 ShiftRight128(DWORD64 LowPart,DWORD64 HighPart,BYTE Shift); - -#define Multiply128 _mul128 - - LONG64 Multiply128(LONG64 Multiplier,LONG64 Multiplicand,LONG64 *HighProduct); - -#define UnsignedMultiply128 _umul128 - - DWORD64 UnsignedMultiply128(DWORD64 Multiplier,DWORD64 Multiplicand,DWORD64 *HighProduct); - - __CRT_INLINE LONG64 MultiplyExtract128(LONG64 Multiplier,LONG64 Multiplicand,BYTE Shift) { - LONG64 extractedProduct; - LONG64 highProduct; - LONG64 lowProduct; - lowProduct = Multiply128(Multiplier,Multiplicand,&highProduct); - extractedProduct = (LONG64)ShiftRight128((LONG64)lowProduct,(LONG64)highProduct,Shift); - return extractedProduct; - } - - __CRT_INLINE DWORD64 UnsignedMultiplyExtract128(DWORD64 Multiplier,DWORD64 Multiplicand,BYTE Shift) { - DWORD64 extractedProduct; - DWORD64 highProduct; - DWORD64 lowProduct; - lowProduct = UnsignedMultiply128(Multiplier,Multiplicand,&highProduct); - extractedProduct = ShiftRight128(lowProduct,highProduct,Shift); - return extractedProduct; - } - - __CRT_INLINE BYTE __readgsbyte(DWORD Offset) { - BYTE ret; - __asm__ volatile ("movb %%gs:%1,%0" - : "=r" (ret) ,"=m" ((*(volatile long *) (DWORD64) Offset))); - return ret; - } - __CRT_INLINE WORD __readgsword(DWORD Offset) { - WORD ret; - __asm__ volatile ("movw %%gs:%1,%0" - : "=r" (ret) ,"=m" ((*(volatile long *) (DWORD64) Offset))); - return ret; - } - __CRT_INLINE DWORD __readgsdword(DWORD Offset) { - DWORD ret; - __asm__ volatile ("movl %%gs:%1,%0" - : "=r" (ret) ,"=m" ((*(volatile long *) (DWORD64) Offset))); - return ret; - } - __CRT_INLINE DWORD64 __readgsqword(DWORD Offset) { - void *ret; - __asm__ volatile ("movq %%gs:%1,%0" - : "=r" (ret) ,"=m" ((*(volatile long *) (DWORD64) Offset))); - return (DWORD64) ret; - } - __CRT_INLINE VOID __writegsbyte(DWORD Offset,BYTE Data) { - __asm__ volatile ("movb %0,%%gs:%1" - : "=r" (Data) ,"=m" ((*(volatile long *) (DWORD64) Offset))); - } - __CRT_INLINE VOID __writegsword(DWORD Offset,WORD Data) { - __asm__ volatile ("movw %0,%%gs:%1" - : "=r" (Data) ,"=m" ((*(volatile long *) (DWORD64) Offset))); - } - __CRT_INLINE VOID __writegsdword(DWORD Offset,DWORD Data) { - __asm__ volatile ("movl %0,%%gs:%1" - : "=r" (Data) ,"=m" ((*(volatile long *) (DWORD64) Offset))); - } - __CRT_INLINE VOID __writegsqword(DWORD Offset,DWORD64 Data) { - __asm__ volatile ("movq %0,%%gs:%1" - : "=r" (Data) ,"=m" ((*(volatile long *) (DWORD64) Offset))); - } - -#ifdef __cplusplus - } -#endif -#endif - -#define EXCEPTION_READ_FAULT 0 -#define EXCEPTION_WRITE_FAULT 1 -#define EXCEPTION_EXECUTE_FAULT 8 - -#if !defined(RC_INVOKED) - -#define CONTEXT_AMD64 0x100000 - -#define CONTEXT_CONTROL (CONTEXT_AMD64 | 0x1L) -#define CONTEXT_INTEGER (CONTEXT_AMD64 | 0x2L) -#define CONTEXT_SEGMENTS (CONTEXT_AMD64 | 0x4L) -#define CONTEXT_FLOATING_POINT (CONTEXT_AMD64 | 0x8L) -#define CONTEXT_DEBUG_REGISTERS (CONTEXT_AMD64 | 0x10L) - -#define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT) -#define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS) - -#define CONTEXT_EXCEPTION_ACTIVE 0x8000000 -#define CONTEXT_SERVICE_ACTIVE 0x10000000 -#define CONTEXT_EXCEPTION_REQUEST 0x40000000 -#define CONTEXT_EXCEPTION_REPORTING 0x80000000 -#endif - -#define INITIAL_MXCSR 0x1f80 -#define INITIAL_FPCSR 0x027f - - typedef DECLSPEC_ALIGN(16) struct _M128A { - ULONGLONG Low; - LONGLONG High; - } M128A,*PM128A; - - typedef struct _XMM_SAVE_AREA32 { - WORD ControlWord; - WORD StatusWord; - BYTE TagWord; - BYTE Reserved1; - WORD ErrorOpcode; - DWORD ErrorOffset; - WORD ErrorSelector; - WORD Reserved2; - DWORD DataOffset; - WORD DataSelector; - WORD Reserved3; - DWORD MxCsr; - DWORD MxCsr_Mask; - M128A FloatRegisters[8]; - M128A XmmRegisters[16]; - BYTE Reserved4[96]; - } XMM_SAVE_AREA32,*PXMM_SAVE_AREA32; - -#define LEGACY_SAVE_AREA_LENGTH sizeof(XMM_SAVE_AREA32) - - typedef DECLSPEC_ALIGN(16) struct _CONTEXT { - DWORD64 P1Home; - DWORD64 P2Home; - DWORD64 P3Home; - DWORD64 P4Home; - DWORD64 P5Home; - DWORD64 P6Home; - DWORD ContextFlags; - DWORD MxCsr; - WORD SegCs; - WORD SegDs; - WORD SegEs; - WORD SegFs; - WORD SegGs; - WORD SegSs; - DWORD EFlags; - DWORD64 Dr0; - DWORD64 Dr1; - DWORD64 Dr2; - DWORD64 Dr3; - DWORD64 Dr6; - DWORD64 Dr7; - DWORD64 Rax; - DWORD64 Rcx; - DWORD64 Rdx; - DWORD64 Rbx; - DWORD64 Rsp; - DWORD64 Rbp; - DWORD64 Rsi; - DWORD64 Rdi; - DWORD64 R8; - DWORD64 R9; - DWORD64 R10; - DWORD64 R11; - DWORD64 R12; - DWORD64 R13; - DWORD64 R14; - DWORD64 R15; - DWORD64 Rip; - union { - XMM_SAVE_AREA32 FltSave; - XMM_SAVE_AREA32 FloatSave; - struct { - M128A Header[2]; - M128A Legacy[8]; - M128A Xmm0; - M128A Xmm1; - M128A Xmm2; - M128A Xmm3; - M128A Xmm4; - M128A Xmm5; - M128A Xmm6; - M128A Xmm7; - M128A Xmm8; - M128A Xmm9; - M128A Xmm10; - M128A Xmm11; - M128A Xmm12; - M128A Xmm13; - M128A Xmm14; - M128A Xmm15; - }; - }; - M128A VectorRegister[26]; - DWORD64 VectorControl; - DWORD64 DebugControl; - DWORD64 LastBranchToRip; - DWORD64 LastBranchFromRip; - DWORD64 LastExceptionToRip; - DWORD64 LastExceptionFromRip; - } CONTEXT,*PCONTEXT; - -#define RUNTIME_FUNCTION_INDIRECT 0x1 - - typedef struct _RUNTIME_FUNCTION { - DWORD BeginAddress; - DWORD EndAddress; - DWORD UnwindData; - } RUNTIME_FUNCTION,*PRUNTIME_FUNCTION; - - typedef PRUNTIME_FUNCTION (*PGET_RUNTIME_FUNCTION_CALLBACK)(DWORD64 ControlPc,PVOID Context); - typedef DWORD (*POUT_OF_PROCESS_FUNCTION_TABLE_CALLBACK)(HANDLE Process,PVOID TableAddress,PDWORD Entries,PRUNTIME_FUNCTION *Functions); - -#define OUT_OF_PROCESS_FUNCTION_TABLE_CALLBACK_EXPORT_NAME "OutOfProcessFunctionTableCallback" - - NTSYSAPI VOID __cdecl RtlRestoreContext (PCONTEXT ContextRecord,struct _EXCEPTION_RECORD *ExceptionRecord); - NTSYSAPI BOOLEAN __cdecl RtlAddFunctionTable(PRUNTIME_FUNCTION FunctionTable,DWORD EntryCount,DWORD64 BaseAddress); - NTSYSAPI BOOLEAN __cdecl RtlInstallFunctionTableCallback(DWORD64 TableIdentifier,DWORD64 BaseAddress,DWORD Length,PGET_RUNTIME_FUNCTION_CALLBACK Callback,PVOID Context,PCWSTR OutOfProcessCallbackDll); - NTSYSAPI BOOLEAN __cdecl RtlDeleteFunctionTable(PRUNTIME_FUNCTION FunctionTable); -#endif - -#ifdef I_X86_ -#if(defined(_X86_) && !defined(__x86_64)) && !defined(RC_INVOKED) -#ifdef __cplusplus - extern "C" { -#endif - - __CRT_INLINE BOOLEAN InterlockedBitTestAndSet(LONG *Base,LONG Bit) { - int old = 0; - __asm__ __volatile__("lock ; btsl %2,%1\n\tsbbl %0,%0 " - :"=r" (old),"=m" ((*(volatile long *) Base)) - :"Ir" (Bit)); - return (BOOLEAN) (old!=0); - } - - __CRT_INLINE BOOLEAN InterlockedBitTestAndReset(LONG *Base,LONG Bit) { - int old = 0; - __asm__ __volatile__("lock ; btrl %2,%1\n\tsbbl %0,%0 " - :"=r" (old),"=m" ((*(volatile long *) Base)) - :"Ir" (Bit)); - return (BOOLEAN) (old!=0); - } - - __CRT_INLINE BOOLEAN InterlockedBitTestAndComplement(LONG *Base,LONG Bit) { - int old = 0; - __asm__ __volatile__("lock ; btcl %2,%1\n\tsbbl %0,%0 " - :"=r" (old),"=m" ((*(volatile long *) Base)) - :"Ir" (Bit)); - return (BOOLEAN) (old!=0); - } - -#ifdef _PREFIX_ - BYTE __readfsbyte(DWORD Offset); - WORD __readfsword(DWORD Offset); - DWORD __readfsdword(DWORD Offset); - VOID __writefsbyte(DWORD Offset,BYTE Data); - VOID __writefsword(DWORD Offset,WORD Data); - VOID __writefsdword(DWORD Offset,DWORD Data); -#endif - -#ifdef __cplusplus - } -#endif -#endif - -#if(defined(_X86_) && !defined(__x86_64)) - __CRT_INLINE VOID MemoryBarrier(VOID) { - LONG Barrier; - __asm__ __volatile__("xchgl %eax,%0 " - :"=r" (Barrier)); - } -#define YieldProcessor() __asm__ __volatile__("rep nop "); - -#define PreFetchCacheLine(l,a) -#define ReadForWriteAccess(p) (*(p)) - -#define PF_TEMPORAL_LEVEL_1 -#define PF_NON_TEMPORAL_LEVEL_ALL - - __CRT_INLINE VOID DbgRaiseAssertionFailure(void) { - __asm__ __volatile__("int 0x2c "); - } - PVOID GetCurrentFiber(void); - __CRT_INLINE PVOID GetCurrentFiber(void) - { - void *ret; - __asm__ volatile ("movl %%fs:0x10,%0" - : "=r" (ret)); - return ret; - } - PVOID GetFiberData(void); - __CRT_INLINE PVOID GetFiberData(void) - { - void *ret; - __asm__ volatile ("movl %%fs:0x10,%0\n" - "movl (%0),%0" - : "=r" (ret)); - return ret; - } -#endif - -#define EXCEPTION_READ_FAULT 0 -#define EXCEPTION_WRITE_FAULT 1 -#define EXCEPTION_EXECUTE_FAULT 8 - -#define SIZE_OF_80387_REGISTERS 80 - -#if !defined(RC_INVOKED) - -#define CONTEXT_i386 0x00010000 -#define CONTEXT_i486 0x00010000 - -#define CONTEXT_CONTROL (CONTEXT_i386 | 0x00000001L) -#define CONTEXT_INTEGER (CONTEXT_i386 | 0x00000002L) -#define CONTEXT_SEGMENTS (CONTEXT_i386 | 0x00000004L) -#define CONTEXT_FLOATING_POINT (CONTEXT_i386 | 0x00000008L) -#define CONTEXT_DEBUG_REGISTERS (CONTEXT_i386 | 0x00000010L) -#define CONTEXT_EXTENDED_REGISTERS (CONTEXT_i386 | 0x00000020L) - -#define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS) - -#define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS | CONTEXT_EXTENDED_REGISTERS) -#endif - -#define MAXIMUM_SUPPORTED_EXTENSION 512 - - typedef struct _FLOATING_SAVE_AREA { - DWORD ControlWord; - DWORD StatusWord; - DWORD TagWord; - DWORD ErrorOffset; - DWORD ErrorSelector; - DWORD DataOffset; - DWORD DataSelector; - BYTE RegisterArea[SIZE_OF_80387_REGISTERS]; - DWORD Cr0NpxState; - } FLOATING_SAVE_AREA; - - typedef FLOATING_SAVE_AREA *PFLOATING_SAVE_AREA; - - typedef struct _CONTEXT { - DWORD ContextFlags; - DWORD Dr0; - DWORD Dr1; - DWORD Dr2; - DWORD Dr3; - DWORD Dr6; - DWORD Dr7; - FLOATING_SAVE_AREA FloatSave; - DWORD SegGs; - DWORD SegFs; - DWORD SegEs; - DWORD SegDs; - - DWORD Edi; - DWORD Esi; - DWORD Ebx; - DWORD Edx; - DWORD Ecx; - DWORD Eax; - DWORD Ebp; - DWORD Eip; - DWORD SegCs; - DWORD EFlags; - DWORD Esp; - DWORD SegSs; - BYTE ExtendedRegisters[MAXIMUM_SUPPORTED_EXTENSION]; - } CONTEXT; - - typedef CONTEXT *PCONTEXT; -#endif - -#ifndef _LDT_ENTRY_DEFINED -#define _LDT_ENTRY_DEFINED - - typedef struct _LDT_ENTRY { - WORD LimitLow; - WORD BaseLow; - union { - struct { - BYTE BaseMid; - BYTE Flags1; - BYTE Flags2; - BYTE BaseHi; - } Bytes; - struct { - DWORD BaseMid : 8; - DWORD Type : 5; - DWORD Dpl : 2; - DWORD Pres : 1; - DWORD LimitHi : 4; - DWORD Sys : 1; - DWORD Reserved_0 : 1; - DWORD Default_Big : 1; - DWORD Granularity : 1; - DWORD BaseHi : 8; - } Bits; - } HighWord; - } LDT_ENTRY,*PLDT_ENTRY; -#endif - -#if defined(__ia64__) && !defined(RC_INVOKED) - -#ifdef __cplusplus - extern "C" { -#endif - - BOOLEAN BitScanForward64(DWORD *Index,DWORD64 Mask); - BOOLEAN BitScanReverse64(DWORD *Index,DWORD64 Mask); - -#ifdef __cplusplus - } -#endif -#endif - -#if !defined(GENUTIL) && !defined(_GENIA64_) && defined(_IA64_) - - void *_cdecl _rdteb(void); -#ifdef __ia64__ - -#define NtCurrentTeb() ((struct _TEB *)_rdteb()) -#define GetCurrentFiber() (((PNT_TIB)NtCurrentTeb())->FiberData) -#define GetFiberData() (*(PVOID *)(GetCurrentFiber())) - -#ifdef __cplusplus - extern "C" { -#endif - - void __break(int); - void __yield(void); - void __mf(void); - void __lfetch(int Level,VOID CONST *Address); - void __lfetchfault(int Level,VOID CONST *Address); - void __lfetch_excl(int Level,VOID CONST *Address); - void __lfetchfault_excl(int Level,VOID CONST *Address); - -#define MD_LFHINT_NONE 0x00 -#define MD_LFHINT_NT1 0x01 -#define MD_LFHINT_NT2 0x02 -#define MD_LFHINT_NTA 0x03 - -#ifdef __cplusplus - } -#endif - -#define YieldProcessor __yield -#define MemoryBarrier __mf -#define PreFetchCacheLine __lfetch -#define ReadForWriteAccess(p) (*(p)) -#define DbgRaiseAssertionFailure() __break(ASSERT_BREAKPOINT) - -#define PF_TEMPORAL_LEVEL_1 MD_LFHINT_NONE -#define PF_NON_TEMPORAL_LEVEL_ALL MD_LFHINT_NTA - -#define UnsignedMultiplyHigh __UMULH - - ULONGLONG UnsignedMultiplyHigh(ULONGLONG Multiplier,ULONGLONG Multiplicand); -#else - struct _TEB *NtCurrentTeb(void); -#endif -#endif - -#ifdef _IA64_ - -#define EXCEPTION_READ_FAULT 0 -#define EXCEPTION_WRITE_FAULT 1 -#define EXCEPTION_EXECUTE_FAULT 2 - -#if !defined(RC_INVOKED) - -#define CONTEXT_IA64 0x00080000 - -#define CONTEXT_CONTROL (CONTEXT_IA64 | 0x00000001L) -#define CONTEXT_LOWER_FLOATING_POINT (CONTEXT_IA64 | 0x00000002L) -#define CONTEXT_HIGHER_FLOATING_POINT (CONTEXT_IA64 | 0x00000004L) -#define CONTEXT_INTEGER (CONTEXT_IA64 | 0x00000008L) -#define CONTEXT_DEBUG (CONTEXT_IA64 | 0x00000010L) -#define CONTEXT_IA32_CONTROL (CONTEXT_IA64 | 0x00000020L) - -#define CONTEXT_FLOATING_POINT (CONTEXT_LOWER_FLOATING_POINT | CONTEXT_HIGHER_FLOATING_POINT) -#define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER | CONTEXT_IA32_CONTROL) -#define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER | CONTEXT_DEBUG | CONTEXT_IA32_CONTROL) - -#define CONTEXT_EXCEPTION_ACTIVE 0x8000000 -#define CONTEXT_SERVICE_ACTIVE 0x10000000 -#define CONTEXT_EXCEPTION_REQUEST 0x40000000 -#define CONTEXT_EXCEPTION_REPORTING 0x80000000 -#endif - - typedef struct _CONTEXT { - DWORD ContextFlags; - DWORD Fill1[3]; - ULONGLONG DbI0; - ULONGLONG DbI1; - ULONGLONG DbI2; - ULONGLONG DbI3; - ULONGLONG DbI4; - ULONGLONG DbI5; - ULONGLONG DbI6; - ULONGLONG DbI7; - ULONGLONG DbD0; - ULONGLONG DbD1; - ULONGLONG DbD2; - ULONGLONG DbD3; - ULONGLONG DbD4; - ULONGLONG DbD5; - ULONGLONG DbD6; - ULONGLONG DbD7; - FLOAT128 FltS0; - FLOAT128 FltS1; - FLOAT128 FltS2; - FLOAT128 FltS3; - FLOAT128 FltT0; - FLOAT128 FltT1; - FLOAT128 FltT2; - FLOAT128 FltT3; - FLOAT128 FltT4; - FLOAT128 FltT5; - FLOAT128 FltT6; - FLOAT128 FltT7; - FLOAT128 FltT8; - FLOAT128 FltT9; - FLOAT128 FltS4; - FLOAT128 FltS5; - FLOAT128 FltS6; - FLOAT128 FltS7; - FLOAT128 FltS8; - FLOAT128 FltS9; - FLOAT128 FltS10; - FLOAT128 FltS11; - FLOAT128 FltS12; - FLOAT128 FltS13; - FLOAT128 FltS14; - FLOAT128 FltS15; - FLOAT128 FltS16; - FLOAT128 FltS17; - FLOAT128 FltS18; - FLOAT128 FltS19; - FLOAT128 FltF32; - FLOAT128 FltF33; - FLOAT128 FltF34; - FLOAT128 FltF35; - FLOAT128 FltF36; - FLOAT128 FltF37; - FLOAT128 FltF38; - FLOAT128 FltF39; - FLOAT128 FltF40; - FLOAT128 FltF41; - FLOAT128 FltF42; - FLOAT128 FltF43; - FLOAT128 FltF44; - FLOAT128 FltF45; - FLOAT128 FltF46; - FLOAT128 FltF47; - FLOAT128 FltF48; - FLOAT128 FltF49; - FLOAT128 FltF50; - FLOAT128 FltF51; - FLOAT128 FltF52; - FLOAT128 FltF53; - FLOAT128 FltF54; - FLOAT128 FltF55; - FLOAT128 FltF56; - FLOAT128 FltF57; - FLOAT128 FltF58; - FLOAT128 FltF59; - FLOAT128 FltF60; - FLOAT128 FltF61; - FLOAT128 FltF62; - FLOAT128 FltF63; - FLOAT128 FltF64; - FLOAT128 FltF65; - FLOAT128 FltF66; - FLOAT128 FltF67; - FLOAT128 FltF68; - FLOAT128 FltF69; - FLOAT128 FltF70; - FLOAT128 FltF71; - FLOAT128 FltF72; - FLOAT128 FltF73; - FLOAT128 FltF74; - FLOAT128 FltF75; - FLOAT128 FltF76; - FLOAT128 FltF77; - FLOAT128 FltF78; - FLOAT128 FltF79; - FLOAT128 FltF80; - FLOAT128 FltF81; - FLOAT128 FltF82; - FLOAT128 FltF83; - FLOAT128 FltF84; - FLOAT128 FltF85; - FLOAT128 FltF86; - FLOAT128 FltF87; - FLOAT128 FltF88; - FLOAT128 FltF89; - FLOAT128 FltF90; - FLOAT128 FltF91; - FLOAT128 FltF92; - FLOAT128 FltF93; - FLOAT128 FltF94; - FLOAT128 FltF95; - FLOAT128 FltF96; - FLOAT128 FltF97; - FLOAT128 FltF98; - FLOAT128 FltF99; - FLOAT128 FltF100; - FLOAT128 FltF101; - FLOAT128 FltF102; - FLOAT128 FltF103; - FLOAT128 FltF104; - FLOAT128 FltF105; - FLOAT128 FltF106; - FLOAT128 FltF107; - FLOAT128 FltF108; - FLOAT128 FltF109; - FLOAT128 FltF110; - FLOAT128 FltF111; - FLOAT128 FltF112; - FLOAT128 FltF113; - FLOAT128 FltF114; - FLOAT128 FltF115; - FLOAT128 FltF116; - FLOAT128 FltF117; - FLOAT128 FltF118; - FLOAT128 FltF119; - FLOAT128 FltF120; - FLOAT128 FltF121; - FLOAT128 FltF122; - FLOAT128 FltF123; - FLOAT128 FltF124; - FLOAT128 FltF125; - FLOAT128 FltF126; - FLOAT128 FltF127; - ULONGLONG StFPSR; - ULONGLONG IntGp; - ULONGLONG IntT0; - ULONGLONG IntT1; - ULONGLONG IntS0; - ULONGLONG IntS1; - ULONGLONG IntS2; - ULONGLONG IntS3; - ULONGLONG IntV0; - ULONGLONG IntT2; - ULONGLONG IntT3; - ULONGLONG IntT4; - ULONGLONG IntSp; - ULONGLONG IntTeb; - ULONGLONG IntT5; - ULONGLONG IntT6; - ULONGLONG IntT7; - ULONGLONG IntT8; - ULONGLONG IntT9; - ULONGLONG IntT10; - ULONGLONG IntT11; - ULONGLONG IntT12; - ULONGLONG IntT13; - ULONGLONG IntT14; - ULONGLONG IntT15; - ULONGLONG IntT16; - ULONGLONG IntT17; - ULONGLONG IntT18; - ULONGLONG IntT19; - ULONGLONG IntT20; - ULONGLONG IntT21; - ULONGLONG IntT22; - ULONGLONG IntNats; - ULONGLONG Preds; - ULONGLONG BrRp; - ULONGLONG BrS0; - ULONGLONG BrS1; - ULONGLONG BrS2; - ULONGLONG BrS3; - ULONGLONG BrS4; - ULONGLONG BrT0; - ULONGLONG BrT1; - ULONGLONG ApUNAT; - ULONGLONG ApLC; - ULONGLONG ApEC; - ULONGLONG ApCCV; - ULONGLONG ApDCR; - ULONGLONG RsPFS; - ULONGLONG RsBSP; - ULONGLONG RsBSPSTORE; - ULONGLONG RsRSC; - ULONGLONG RsRNAT; - ULONGLONG StIPSR; - ULONGLONG StIIP; - ULONGLONG StIFS; - ULONGLONG StFCR; - ULONGLONG Eflag; - ULONGLONG SegCSD; - ULONGLONG SegSSD; - ULONGLONG Cflag; - ULONGLONG StFSR; - ULONGLONG StFIR; - ULONGLONG StFDR; - ULONGLONG UNUSEDPACK; - } CONTEXT,*PCONTEXT; - - typedef struct _PLABEL_DESCRIPTOR { - ULONGLONG EntryPoint; - ULONGLONG GlobalPointer; - } PLABEL_DESCRIPTOR,*PPLABEL_DESCRIPTOR; - - typedef struct _RUNTIME_FUNCTION { - DWORD BeginAddress; - DWORD EndAddress; - DWORD UnwindInfoAddress; - } RUNTIME_FUNCTION,*PRUNTIME_FUNCTION; - - typedef PRUNTIME_FUNCTION (*PGET_RUNTIME_FUNCTION_CALLBACK)(DWORD64 ControlPc,PVOID Context); - typedef DWORD (*POUT_OF_PROCESS_FUNCTION_TABLE_CALLBACK)(HANDLE Process,PVOID TableAddress,PDWORD Entries,PRUNTIME_FUNCTION *Functions); - -#define OUT_OF_PROCESS_FUNCTION_TABLE_CALLBACK_EXPORT_NAME "OutOfProcessFunctionTableCallback" - - BOOLEAN RtlAddFunctionTable(PRUNTIME_FUNCTION FunctionTable,DWORD EntryCount,ULONGLONG BaseAddress,ULONGLONG TargetGp); - BOOLEAN RtlInstallFunctionTableCallback(DWORD64 TableIdentifier,DWORD64 BaseAddress,DWORD Length,DWORD64 TargetGp,PGET_RUNTIME_FUNCTION_CALLBACK Callback,PVOID Context,PCWSTR OutOfProcessCallbackDll); - BOOLEAN RtlDeleteFunctionTable(PRUNTIME_FUNCTION FunctionTable); - VOID RtlRestoreContext (PCONTEXT ContextRecord,struct _EXCEPTION_RECORD *ExceptionRecord); - VOID __jump_unwind(ULONGLONG TargetMsFrame,ULONGLONG TargetBsFrame,ULONGLONG TargetPc); -#endif - -#define EXCEPTION_NONCONTINUABLE 0x1 -#define EXCEPTION_MAXIMUM_PARAMETERS 15 - - typedef struct _EXCEPTION_RECORD { - DWORD ExceptionCode; - DWORD ExceptionFlags; - struct _EXCEPTION_RECORD *ExceptionRecord; - PVOID ExceptionAddress; - DWORD NumberParameters; - ULONG_PTR ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS]; - } EXCEPTION_RECORD; - - typedef EXCEPTION_RECORD *PEXCEPTION_RECORD; - - typedef struct _EXCEPTION_RECORD32 { - DWORD ExceptionCode; - DWORD ExceptionFlags; - DWORD ExceptionRecord; - DWORD ExceptionAddress; - DWORD NumberParameters; - DWORD ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS]; - } EXCEPTION_RECORD32,*PEXCEPTION_RECORD32; - - typedef struct _EXCEPTION_RECORD64 { - DWORD ExceptionCode; - DWORD ExceptionFlags; - DWORD64 ExceptionRecord; - DWORD64 ExceptionAddress; - DWORD NumberParameters; - DWORD __unusedAlignment; - DWORD64 ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS]; - } EXCEPTION_RECORD64,*PEXCEPTION_RECORD64; - - typedef struct _EXCEPTION_POINTERS { - PEXCEPTION_RECORD ExceptionRecord; - PCONTEXT ContextRecord; - } EXCEPTION_POINTERS,*PEXCEPTION_POINTERS; - -#ifdef __x86_64 - - typedef EXCEPTION_DISPOSITION NTAPI EXCEPTION_ROUTINE (struct _EXCEPTION_RECORD *ExceptionRecord, PVOID EstablisherFrame, struct _CONTEXT *ContextRecord, PVOID DispatcherContext); -#ifndef __PEXCEPTION_ROUTINE_DEFINED -#define __PEXCEPTION_ROUTINE_DEFINED - typedef EXCEPTION_ROUTINE *PEXCEPTION_ROUTINE; -#endif - - /* http://msdn.microsoft.com/en-us/library/ms680597(VS.85).aspx */ - -#define UNWIND_HISTORY_TABLE_SIZE 12 - - typedef struct _UNWIND_HISTORY_TABLE_ENTRY { - ULONG64 ImageBase; - PRUNTIME_FUNCTION FunctionEntry; - } UNWIND_HISTORY_TABLE_ENTRY, *PUNWIND_HISTORY_TABLE_ENTRY; - -#define UNWIND_HISTORY_TABLE_NONE 0 -#define UNWIND_HISTORY_TABLE_GLOBAL 1 -#define UNWIND_HISTORY_TABLE_LOCAL 2 - - typedef struct _UNWIND_HISTORY_TABLE { - ULONG Count; - UCHAR Search; - ULONG64 LowAddress; - ULONG64 HighAddress; - UNWIND_HISTORY_TABLE_ENTRY Entry[UNWIND_HISTORY_TABLE_SIZE]; - } UNWIND_HISTORY_TABLE, *PUNWIND_HISTORY_TABLE; - - /* http://msdn.microsoft.com/en-us/library/b6sf5kbd(VS.80).aspx */ - - struct _DISPATCHER_CONTEXT; - typedef struct _DISPATCHER_CONTEXT DISPATCHER_CONTEXT; - typedef struct _DISPATCHER_CONTEXT *PDISPATCHER_CONTEXT; - - struct _DISPATCHER_CONTEXT { - ULONG64 ControlPc; - ULONG64 ImageBase; - PRUNTIME_FUNCTION FunctionEntry; - ULONG64 EstablisherFrame; - ULONG64 TargetIp; - PCONTEXT ContextRecord; - PEXCEPTION_ROUTINE LanguageHandler; - PVOID HandlerData; - /* http://www.nynaeve.net/?p=99 */ - PUNWIND_HISTORY_TABLE HistoryTable; - ULONG ScopeIndex; - ULONG Fill0; - }; - - /* http://msdn.microsoft.com/en-us/library/ms680617(VS.85).aspx */ - - typedef struct _KNONVOLATILE_CONTEXT_POINTERS - { - PM128A FloatingContext[16]; - PULONG64 IntegerContext[16]; - } KNONVOLATILE_CONTEXT_POINTERS, *PKNONVOLATILE_CONTEXT_POINTERS; -#endif /* defined(__x86_64) */ - - typedef PVOID PACCESS_TOKEN; - typedef PVOID PSECURITY_DESCRIPTOR; - typedef PVOID PSID; - - typedef DWORD ACCESS_MASK; - typedef ACCESS_MASK *PACCESS_MASK; - -#define DELETE (0x00010000L) -#define READ_CONTROL (0x00020000L) -#define WRITE_DAC (0x00040000L) -#define WRITE_OWNER (0x00080000L) -#define SYNCHRONIZE (0x00100000L) - -#define STANDARD_RIGHTS_REQUIRED (0x000F0000L) -#define STANDARD_RIGHTS_READ (READ_CONTROL) -#define STANDARD_RIGHTS_WRITE (READ_CONTROL) -#define STANDARD_RIGHTS_EXECUTE (READ_CONTROL) -#define STANDARD_RIGHTS_ALL (0x001F0000L) - -#define SPECIFIC_RIGHTS_ALL (0x0000FFFFL) - -#define ACCESS_SYSTEM_SECURITY (0x01000000L) - -#define MAXIMUM_ALLOWED (0x02000000L) - -#define GENERIC_READ (0x80000000L) -#define GENERIC_WRITE (0x40000000L) -#define GENERIC_EXECUTE (0x20000000L) -#define GENERIC_ALL (0x10000000L) - - typedef struct _GENERIC_MAPPING { - ACCESS_MASK GenericRead; - ACCESS_MASK GenericWrite; - ACCESS_MASK GenericExecute; - ACCESS_MASK GenericAll; - } GENERIC_MAPPING; - typedef GENERIC_MAPPING *PGENERIC_MAPPING; - -#include - - typedef struct _LUID_AND_ATTRIBUTES { - LUID Luid; - DWORD Attributes; - } LUID_AND_ATTRIBUTES,*PLUID_AND_ATTRIBUTES; - typedef LUID_AND_ATTRIBUTES LUID_AND_ATTRIBUTES_ARRAY[ANYSIZE_ARRAY]; - typedef LUID_AND_ATTRIBUTES_ARRAY *PLUID_AND_ATTRIBUTES_ARRAY; - -#include - -#ifndef SID_IDENTIFIER_AUTHORITY_DEFINED -#define SID_IDENTIFIER_AUTHORITY_DEFINED - typedef struct _SID_IDENTIFIER_AUTHORITY { - BYTE Value[6]; - } SID_IDENTIFIER_AUTHORITY,*PSID_IDENTIFIER_AUTHORITY; -#endif - -#ifndef SID_DEFINED -#define SID_DEFINED - typedef struct _SID { - BYTE Revision; - BYTE SubAuthorityCount; - SID_IDENTIFIER_AUTHORITY IdentifierAuthority; - DWORD SubAuthority[ANYSIZE_ARRAY]; - } SID,*PISID; -#endif - -#define SID_REVISION (1) -#define SID_MAX_SUB_AUTHORITIES (15) -#define SID_RECOMMENDED_SUB_AUTHORITIES (1) - -#define SECURITY_MAX_SID_SIZE (sizeof(SID) - sizeof(DWORD) + (SID_MAX_SUB_AUTHORITIES *sizeof(DWORD))) - - typedef enum _SID_NAME_USE { - SidTypeUser = 1,SidTypeGroup,SidTypeDomain,SidTypeAlias,SidTypeWellKnownGroup,SidTypeDeletedAccount,SidTypeInvalid,SidTypeUnknown,SidTypeComputer - } SID_NAME_USE,*PSID_NAME_USE; - - typedef struct _SID_AND_ATTRIBUTES { - PSID Sid; - DWORD Attributes; - } SID_AND_ATTRIBUTES,*PSID_AND_ATTRIBUTES; - - typedef SID_AND_ATTRIBUTES SID_AND_ATTRIBUTES_ARRAY[ANYSIZE_ARRAY]; - typedef SID_AND_ATTRIBUTES_ARRAY *PSID_AND_ATTRIBUTES_ARRAY; - -#define SECURITY_NULL_SID_AUTHORITY {0,0,0,0,0,0} -#define SECURITY_WORLD_SID_AUTHORITY {0,0,0,0,0,1} -#define SECURITY_LOCAL_SID_AUTHORITY {0,0,0,0,0,2} -#define SECURITY_CREATOR_SID_AUTHORITY {0,0,0,0,0,3} -#define SECURITY_NON_UNIQUE_AUTHORITY {0,0,0,0,0,4} -#define SECURITY_RESOURCE_MANAGER_AUTHORITY {0,0,0,0,0,9} - -#define SECURITY_NULL_RID (0x00000000L) -#define SECURITY_WORLD_RID (0x00000000L) -#define SECURITY_LOCAL_RID (0x00000000L) - -#define SECURITY_CREATOR_OWNER_RID (0x00000000L) -#define SECURITY_CREATOR_GROUP_RID (0x00000001L) - -#define SECURITY_CREATOR_OWNER_SERVER_RID (0x00000002L) -#define SECURITY_CREATOR_GROUP_SERVER_RID (0x00000003L) - -#define SECURITY_NT_AUTHORITY {0,0,0,0,0,5} - -#define SECURITY_DIALUP_RID (0x00000001L) -#define SECURITY_NETWORK_RID (0x00000002L) -#define SECURITY_BATCH_RID (0x00000003L) -#define SECURITY_INTERACTIVE_RID (0x00000004L) -#define SECURITY_LOGON_IDS_RID (0x00000005L) -#define SECURITY_LOGON_IDS_RID_COUNT (3L) -#define SECURITY_SERVICE_RID (0x00000006L) -#define SECURITY_ANONYMOUS_LOGON_RID (0x00000007L) -#define SECURITY_PROXY_RID (0x00000008L) -#define SECURITY_ENTERPRISE_CONTROLLERS_RID (0x00000009L) -#define SECURITY_SERVER_LOGON_RID SECURITY_ENTERPRISE_CONTROLLERS_RID -#define SECURITY_PRINCIPAL_SELF_RID (0x0000000AL) -#define SECURITY_AUTHENTICATED_USER_RID (0x0000000BL) -#define SECURITY_RESTRICTED_CODE_RID (0x0000000CL) -#define SECURITY_TERMINAL_SERVER_RID (0x0000000DL) -#define SECURITY_REMOTE_LOGON_RID (0x0000000EL) -#define SECURITY_THIS_ORGANIZATION_RID (0x0000000FL) -#define SECURITY_IUSER_RID (0x00000011L) - -#define SECURITY_LOCAL_SYSTEM_RID (0x00000012L) -#define SECURITY_LOCAL_SERVICE_RID (0x00000013L) -#define SECURITY_NETWORK_SERVICE_RID (0x00000014L) - -#define SECURITY_NT_NON_UNIQUE (0x00000015L) -#define SECURITY_NT_NON_UNIQUE_SUB_AUTH_COUNT (3L) - -#define SECURITY_ENTERPRISE_READONLY_CONTROLLERS_RID (0x00000016L) - -#define SECURITY_BUILTIN_DOMAIN_RID (0x00000020L) -#define SECURITY_WRITE_RESTRICTED_CODE_RID (0x00000021L) - -#define SECURITY_PACKAGE_BASE_RID (0x00000040L) -#define SECURITY_PACKAGE_RID_COUNT (2L) -#define SECURITY_PACKAGE_NTLM_RID (0x0000000AL) -#define SECURITY_PACKAGE_SCHANNEL_RID (0x0000000EL) -#define SECURITY_PACKAGE_DIGEST_RID (0x00000015L) - -#define SECURITY_SERVICE_ID_BASE_RID (0x00000050L) -#define SECURITY_SERVICE_ID_RID_COUNT (6L) - -#define SECURITY_RESERVED_ID_BASE_RID (0x00000051L) - -#define SECURITY_MAX_ALWAYS_FILTERED (0x000003E7L) -#define SECURITY_MIN_NEVER_FILTERED (0x000003E8L) - -#define SECURITY_OTHER_ORGANIZATION_RID (0x000003E8L) - -#define FOREST_USER_RID_MAX (0x000001F3L) - -#define DOMAIN_USER_RID_ADMIN (0x000001F4L) -#define DOMAIN_USER_RID_GUEST (0x000001F5L) -#define DOMAIN_USER_RID_KRBTGT (0x000001F6L) - -#define DOMAIN_USER_RID_MAX (0x000003E7L) - -#define DOMAIN_GROUP_RID_ADMINS (0x00000200L) -#define DOMAIN_GROUP_RID_USERS (0x00000201L) -#define DOMAIN_GROUP_RID_GUESTS (0x00000202L) -#define DOMAIN_GROUP_RID_COMPUTERS (0x00000203L) -#define DOMAIN_GROUP_RID_CONTROLLERS (0x00000204L) -#define DOMAIN_GROUP_RID_CERT_ADMINS (0x00000205L) -#define DOMAIN_GROUP_RID_SCHEMA_ADMINS (0x00000206L) -#define DOMAIN_GROUP_RID_ENTERPRISE_ADMINS (0x00000207L) -#define DOMAIN_GROUP_RID_POLICY_ADMINS (0x00000208L) -#define DOMAIN_GROUP_RID_READONLY_CONTROLLERS (0x00000209L) - -#define DOMAIN_ALIAS_RID_ADMINS (0x00000220L) -#define DOMAIN_ALIAS_RID_USERS (0x00000221L) -#define DOMAIN_ALIAS_RID_GUESTS (0x00000222L) -#define DOMAIN_ALIAS_RID_POWER_USERS (0x00000223L) - -#define DOMAIN_ALIAS_RID_ACCOUNT_OPS (0x00000224L) -#define DOMAIN_ALIAS_RID_SYSTEM_OPS (0x00000225L) -#define DOMAIN_ALIAS_RID_PRINT_OPS (0x00000226L) -#define DOMAIN_ALIAS_RID_BACKUP_OPS (0x00000227L) - -#define DOMAIN_ALIAS_RID_REPLICATOR (0x00000228L) -#define DOMAIN_ALIAS_RID_RAS_SERVERS (0x00000229L) -#define DOMAIN_ALIAS_RID_PREW2KCOMPACCESS (0x0000022AL) -#define DOMAIN_ALIAS_RID_REMOTE_DESKTOP_USERS (0x0000022BL) -#define DOMAIN_ALIAS_RID_NETWORK_CONFIGURATION_OPS (0x0000022CL) -#define DOMAIN_ALIAS_RID_INCOMING_FOREST_TRUST_BUILDERS (0x0000022DL) - -#define DOMAIN_ALIAS_RID_MONITORING_USERS (0x0000022EL) -#define DOMAIN_ALIAS_RID_LOGGING_USERS (0x0000022FL) -#define DOMAIN_ALIAS_RID_AUTHORIZATIONACCESS (0x00000230L) -#define DOMAIN_ALIAS_RID_TS_LICENSE_SERVERS (0x00000231L) -#define DOMAIN_ALIAS_RID_DCOM_USERS (0x00000232L) - -#define DOMAIN_ALIAS_RID_IUSERS (0x00000238L) -#define DOMAIN_ALIAS_RID_CRYPTO_OPERATORS (0x00000239L) -#define DOMAIN_ALIAS_RID_CACHEABLE_PRINCIPALS_GROUP (0x0000023BL) -#define DOMAIN_ALIAS_RID_NON_CACHEABLE_PRINCIPALS_GROUP (0x0000023CL) -#define DOMAIN_ALIAS_RID_EVENT_LOG_READERS_GROUP (0x0000023DL) - -#define SECURITY_MANDATORY_LABEL_AUTHORITY {0,0,0,0,0,16} -#define SECURITY_MANDATORY_UNTRUSTED_RID (0x00000000L) -#define SECURITY_MANDATORY_LOW_RID (0x00001000L) -#define SECURITY_MANDATORY_MEDIUM_RID (0x00002000L) -#define SECURITY_MANDATORY_HIGH_RID (0x00003000L) -#define SECURITY_MANDATORY_SYSTEM_RID (0x00004000L) -#define SECURITY_MANDATORY_PROTECTED_PROCESS_RID (0x00005000L) - -#define SECURITY_MANDATORY_MAXIMUM_USER_RID SECURITY_MANDATORY_SYSTEM_RID - -#define MANDATORY_LEVEL_TO_MANDATORY_RID(IL) (IL * 0x1000) - - typedef enum { - WinNullSid = 0,WinWorldSid = 1,WinLocalSid = 2,WinCreatorOwnerSid = 3,WinCreatorGroupSid = 4,WinCreatorOwnerServerSid = 5,WinCreatorGroupServerSid = 6,WinNtAuthoritySid = 7,WinDialupSid = 8,WinNetworkSid = 9,WinBatchSid = 10,WinInteractiveSid = 11,WinServiceSid = 12,WinAnonymousSid = 13,WinProxySid = 14,WinEnterpriseControllersSid = 15,WinSelfSid = 16,WinAuthenticatedUserSid = 17,WinRestrictedCodeSid = 18,WinTerminalServerSid = 19,WinRemoteLogonIdSid = 20,WinLogonIdsSid = 21,WinLocalSystemSid = 22,WinLocalServiceSid = 23,WinNetworkServiceSid = 24,WinBuiltinDomainSid = 25,WinBuiltinAdministratorsSid = 26,WinBuiltinUsersSid = 27,WinBuiltinGuestsSid = 28,WinBuiltinPowerUsersSid = 29,WinBuiltinAccountOperatorsSid = 30,WinBuiltinSystemOperatorsSid = 31,WinBuiltinPrintOperatorsSid = 32,WinBuiltinBackupOperatorsSid = 33,WinBuiltinReplicatorSid = 34,WinBuiltinPreWindows2000CompatibleAccessSid = 35,WinBuiltinRemoteDesktopUsersSid = 36,WinBuiltinNetworkConfigurationOperatorsSid = 37,WinAccountAdministratorSid = 38,WinAccountGuestSid = 39,WinAccountKrbtgtSid = 40,WinAccountDomainAdminsSid = 41,WinAccountDomainUsersSid = 42,WinAccountDomainGuestsSid = 43,WinAccountComputersSid = 44,WinAccountControllersSid = 45,WinAccountCertAdminsSid = 46,WinAccountSchemaAdminsSid = 47,WinAccountEnterpriseAdminsSid = 48,WinAccountPolicyAdminsSid = 49,WinAccountRasAndIasServersSid = 50,WinNTLMAuthenticationSid = 51,WinDigestAuthenticationSid = 52,WinSChannelAuthenticationSid = 53,WinThisOrganizationSid = 54,WinOtherOrganizationSid = 55,WinBuiltinIncomingForestTrustBuildersSid = 56,WinBuiltinPerfMonitoringUsersSid = 57,WinBuiltinPerfLoggingUsersSid = 58,WinBuiltinAuthorizationAccessSid = 59,WinBuiltinTerminalServerLicenseServersSid = 60,WinBuiltinDCOMUsersSid = 61 - } WELL_KNOWN_SID_TYPE; - -#define SYSTEM_LUID { 0x3E7,0x0 } -#define ANONYMOUS_LOGON_LUID { 0x3e6,0x0 } -#define LOCALSERVICE_LUID { 0x3e5,0x0 } -#define NETWORKSERVICE_LUID { 0x3e4,0x0 } -#define IUSER_LUID { 0x3e3, 0x0 } - -#define SE_GROUP_MANDATORY (0x00000001L) -#define SE_GROUP_ENABLED_BY_DEFAULT (0x00000002L) -#define SE_GROUP_ENABLED (0x00000004L) -#define SE_GROUP_OWNER (0x00000008L) -#define SE_GROUP_USE_FOR_DENY_ONLY (0x00000010L) -#define SE_GROUP_INTEGRITY (0x00000020L) -#define SE_GROUP_INTEGRITY_ENABLED (0x00000040L) -#define SE_GROUP_LOGON_ID (0xC0000000L) -#define SE_GROUP_RESOURCE (0x20000000L) - -#define ACL_REVISION (2) -#define ACL_REVISION_DS (4) - -#define ACL_REVISION1 (1) -#define MIN_ACL_REVISION ACL_REVISION2 -#define ACL_REVISION2 (2) -#define ACL_REVISION3 (3) -#define ACL_REVISION4 (4) -#define MAX_ACL_REVISION ACL_REVISION4 - - typedef struct _ACL { - BYTE AclRevision; - BYTE Sbz1; - WORD AclSize; - WORD AceCount; - WORD Sbz2; - } ACL; - typedef ACL *PACL; - - typedef struct _ACE_HEADER { - BYTE AceType; - BYTE AceFlags; - WORD AceSize; - } ACE_HEADER; - typedef ACE_HEADER *PACE_HEADER; - -#define ACCESS_MIN_MS_ACE_TYPE (0x0) -#define ACCESS_ALLOWED_ACE_TYPE (0x0) -#define ACCESS_DENIED_ACE_TYPE (0x1) -#define SYSTEM_AUDIT_ACE_TYPE (0x2) -#define SYSTEM_ALARM_ACE_TYPE (0x3) -#define ACCESS_MAX_MS_V2_ACE_TYPE (0x3) - -#define ACCESS_ALLOWED_COMPOUND_ACE_TYPE (0x4) -#define ACCESS_MAX_MS_V3_ACE_TYPE (0x4) - -#define ACCESS_MIN_MS_OBJECT_ACE_TYPE (0x5) -#define ACCESS_ALLOWED_OBJECT_ACE_TYPE (0x5) -#define ACCESS_DENIED_OBJECT_ACE_TYPE (0x6) -#define SYSTEM_AUDIT_OBJECT_ACE_TYPE (0x7) -#define SYSTEM_ALARM_OBJECT_ACE_TYPE (0x8) -#define ACCESS_MAX_MS_OBJECT_ACE_TYPE (0x8) - -#define ACCESS_MAX_MS_V4_ACE_TYPE (0x8) -#define ACCESS_MAX_MS_ACE_TYPE (0x8) - -#define ACCESS_ALLOWED_CALLBACK_ACE_TYPE (0x9) -#define ACCESS_DENIED_CALLBACK_ACE_TYPE (0xA) -#define ACCESS_ALLOWED_CALLBACK_OBJECT_ACE_TYPE (0xB) -#define ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE (0xC) -#define SYSTEM_AUDIT_CALLBACK_ACE_TYPE (0xD) -#define SYSTEM_ALARM_CALLBACK_ACE_TYPE (0xE) -#define SYSTEM_AUDIT_CALLBACK_OBJECT_ACE_TYPE (0xF) -#define SYSTEM_ALARM_CALLBACK_OBJECT_ACE_TYPE (0x10) - -#define SYSTEM_MANDATORY_LABEL_ACE_TYPE (0x11) -#define ACCESS_MAX_MS_V5_ACE_TYPE (0x11) - -#define OBJECT_INHERIT_ACE (0x1) -#define CONTAINER_INHERIT_ACE (0x2) -#define NO_PROPAGATE_INHERIT_ACE (0x4) -#define INHERIT_ONLY_ACE (0x8) -#define INHERITED_ACE (0x10) -#define VALID_INHERIT_FLAGS (0x1F) - -#define SUCCESSFUL_ACCESS_ACE_FLAG (0x40) -#define FAILED_ACCESS_ACE_FLAG (0x80) - - typedef struct _ACCESS_ALLOWED_ACE { - ACE_HEADER Header; - ACCESS_MASK Mask; - DWORD SidStart; - } ACCESS_ALLOWED_ACE; - - typedef ACCESS_ALLOWED_ACE *PACCESS_ALLOWED_ACE; - - typedef struct _ACCESS_DENIED_ACE { - ACE_HEADER Header; - ACCESS_MASK Mask; - DWORD SidStart; - } ACCESS_DENIED_ACE; - typedef ACCESS_DENIED_ACE *PACCESS_DENIED_ACE; - - typedef struct _SYSTEM_AUDIT_ACE { - ACE_HEADER Header; - ACCESS_MASK Mask; - DWORD SidStart; - } SYSTEM_AUDIT_ACE; - typedef SYSTEM_AUDIT_ACE *PSYSTEM_AUDIT_ACE; - - typedef struct _SYSTEM_ALARM_ACE { - ACE_HEADER Header; - ACCESS_MASK Mask; - DWORD SidStart; - } SYSTEM_ALARM_ACE; - typedef SYSTEM_ALARM_ACE *PSYSTEM_ALARM_ACE; - - typedef struct _ACCESS_ALLOWED_OBJECT_ACE { - ACE_HEADER Header; - ACCESS_MASK Mask; - DWORD Flags; - GUID ObjectType; - GUID InheritedObjectType; - DWORD SidStart; - } ACCESS_ALLOWED_OBJECT_ACE,*PACCESS_ALLOWED_OBJECT_ACE; - - typedef struct _ACCESS_DENIED_OBJECT_ACE { - ACE_HEADER Header; - ACCESS_MASK Mask; - DWORD Flags; - GUID ObjectType; - GUID InheritedObjectType; - DWORD SidStart; - } ACCESS_DENIED_OBJECT_ACE,*PACCESS_DENIED_OBJECT_ACE; - - typedef struct _SYSTEM_AUDIT_OBJECT_ACE { - ACE_HEADER Header; - ACCESS_MASK Mask; - DWORD Flags; - GUID ObjectType; - GUID InheritedObjectType; - DWORD SidStart; - } SYSTEM_AUDIT_OBJECT_ACE,*PSYSTEM_AUDIT_OBJECT_ACE; - - typedef struct _SYSTEM_ALARM_OBJECT_ACE { - ACE_HEADER Header; - ACCESS_MASK Mask; - DWORD Flags; - GUID ObjectType; - GUID InheritedObjectType; - DWORD SidStart; - } SYSTEM_ALARM_OBJECT_ACE,*PSYSTEM_ALARM_OBJECT_ACE; - - typedef struct _ACCESS_ALLOWED_CALLBACK_ACE { - ACE_HEADER Header; - ACCESS_MASK Mask; - DWORD SidStart; - - } ACCESS_ALLOWED_CALLBACK_ACE,*PACCESS_ALLOWED_CALLBACK_ACE; - - typedef struct _ACCESS_DENIED_CALLBACK_ACE { - ACE_HEADER Header; - ACCESS_MASK Mask; - DWORD SidStart; - - } ACCESS_DENIED_CALLBACK_ACE,*PACCESS_DENIED_CALLBACK_ACE; - - typedef struct _SYSTEM_AUDIT_CALLBACK_ACE { - ACE_HEADER Header; - ACCESS_MASK Mask; - DWORD SidStart; - - } SYSTEM_AUDIT_CALLBACK_ACE,*PSYSTEM_AUDIT_CALLBACK_ACE; - - typedef struct _SYSTEM_ALARM_CALLBACK_ACE { - ACE_HEADER Header; - ACCESS_MASK Mask; - DWORD SidStart; - - } SYSTEM_ALARM_CALLBACK_ACE,*PSYSTEM_ALARM_CALLBACK_ACE; - - typedef struct _ACCESS_ALLOWED_CALLBACK_OBJECT_ACE { - ACE_HEADER Header; - ACCESS_MASK Mask; - DWORD Flags; - GUID ObjectType; - GUID InheritedObjectType; - DWORD SidStart; - - } ACCESS_ALLOWED_CALLBACK_OBJECT_ACE,*PACCESS_ALLOWED_CALLBACK_OBJECT_ACE; - - typedef struct _ACCESS_DENIED_CALLBACK_OBJECT_ACE { - ACE_HEADER Header; - ACCESS_MASK Mask; - DWORD Flags; - GUID ObjectType; - GUID InheritedObjectType; - DWORD SidStart; - - } ACCESS_DENIED_CALLBACK_OBJECT_ACE,*PACCESS_DENIED_CALLBACK_OBJECT_ACE; - - typedef struct _SYSTEM_AUDIT_CALLBACK_OBJECT_ACE { - ACE_HEADER Header; - ACCESS_MASK Mask; - DWORD Flags; - GUID ObjectType; - GUID InheritedObjectType; - DWORD SidStart; - - } SYSTEM_AUDIT_CALLBACK_OBJECT_ACE,*PSYSTEM_AUDIT_CALLBACK_OBJECT_ACE; - - typedef struct _SYSTEM_ALARM_CALLBACK_OBJECT_ACE { - ACE_HEADER Header; - ACCESS_MASK Mask; - DWORD Flags; - GUID ObjectType; - GUID InheritedObjectType; - DWORD SidStart; - - } SYSTEM_ALARM_CALLBACK_OBJECT_ACE,*PSYSTEM_ALARM_CALLBACK_OBJECT_ACE; - -#define ACE_OBJECT_TYPE_PRESENT 0x1 -#define ACE_INHERITED_OBJECT_TYPE_PRESENT 0x2 - - typedef enum _ACL_INFORMATION_CLASS { - AclRevisionInformation = 1,AclSizeInformation - } ACL_INFORMATION_CLASS; - - typedef struct _ACL_REVISION_INFORMATION { - DWORD AclRevision; - } ACL_REVISION_INFORMATION; - typedef ACL_REVISION_INFORMATION *PACL_REVISION_INFORMATION; - - typedef struct _ACL_SIZE_INFORMATION { - DWORD AceCount; - DWORD AclBytesInUse; - DWORD AclBytesFree; - } ACL_SIZE_INFORMATION; - typedef ACL_SIZE_INFORMATION *PACL_SIZE_INFORMATION; - -#define SECURITY_DESCRIPTOR_REVISION (1) -#define SECURITY_DESCRIPTOR_REVISION1 (1) - -#define SECURITY_DESCRIPTOR_MIN_LENGTH (sizeof(SECURITY_DESCRIPTOR)) - - typedef WORD SECURITY_DESCRIPTOR_CONTROL,*PSECURITY_DESCRIPTOR_CONTROL; - -#define SE_OWNER_DEFAULTED (0x0001) -#define SE_GROUP_DEFAULTED (0x0002) -#define SE_DACL_PRESENT (0x0004) -#define SE_DACL_DEFAULTED (0x0008) -#define SE_SACL_PRESENT (0x0010) -#define SE_SACL_DEFAULTED (0x0020) -#define SE_DACL_AUTO_INHERIT_REQ (0x0100) -#define SE_SACL_AUTO_INHERIT_REQ (0x0200) -#define SE_DACL_AUTO_INHERITED (0x0400) -#define SE_SACL_AUTO_INHERITED (0x0800) -#define SE_DACL_PROTECTED (0x1000) -#define SE_SACL_PROTECTED (0x2000) -#define SE_RM_CONTROL_VALID (0x4000) -#define SE_SELF_RELATIVE (0x8000) - - typedef struct _SECURITY_DESCRIPTOR_RELATIVE { - BYTE Revision; - BYTE Sbz1; - SECURITY_DESCRIPTOR_CONTROL Control; - DWORD Owner; - DWORD Group; - DWORD Sacl; - DWORD Dacl; - } SECURITY_DESCRIPTOR_RELATIVE,*PISECURITY_DESCRIPTOR_RELATIVE; - - typedef struct _SECURITY_DESCRIPTOR { - BYTE Revision; - BYTE Sbz1; - SECURITY_DESCRIPTOR_CONTROL Control; - PSID Owner; - PSID Group; - PACL Sacl; - PACL Dacl; - - } SECURITY_DESCRIPTOR,*PISECURITY_DESCRIPTOR; - - typedef struct _OBJECT_TYPE_LIST { - WORD Level; - WORD Sbz; - GUID *ObjectType; - } OBJECT_TYPE_LIST,*POBJECT_TYPE_LIST; - -#define ACCESS_OBJECT_GUID 0 -#define ACCESS_PROPERTY_SET_GUID 1 -#define ACCESS_PROPERTY_GUID 2 - -#define ACCESS_MAX_LEVEL 4 - - typedef enum _AUDIT_EVENT_TYPE { - AuditEventObjectAccess,AuditEventDirectoryServiceAccess - } AUDIT_EVENT_TYPE,*PAUDIT_EVENT_TYPE; - -#define AUDIT_ALLOW_NO_PRIVILEGE 0x1 - -#define ACCESS_DS_SOURCE_A "DS" -#define ACCESS_DS_SOURCE_W L"DS" -#define ACCESS_DS_OBJECT_TYPE_NAME_A "Directory Service Object" -#define ACCESS_DS_OBJECT_TYPE_NAME_W L"Directory Service Object" - -#define SE_PRIVILEGE_ENABLED_BY_DEFAULT (0x00000001L) -#define SE_PRIVILEGE_ENABLED (0x00000002L) -#define SE_PRIVILEGE_REMOVED (0X00000004L) -#define SE_PRIVILEGE_USED_FOR_ACCESS (0x80000000L) - -#define PRIVILEGE_SET_ALL_NECESSARY (1) - - typedef struct _PRIVILEGE_SET { - DWORD PrivilegeCount; - DWORD Control; - LUID_AND_ATTRIBUTES Privilege[ANYSIZE_ARRAY]; - } PRIVILEGE_SET,*PPRIVILEGE_SET; - -#define SE_CREATE_TOKEN_NAME TEXT("SeCreateTokenPrivilege") -#define SE_ASSIGNPRIMARYTOKEN_NAME TEXT("SeAssignPrimaryTokenPrivilege") -#define SE_LOCK_MEMORY_NAME TEXT("SeLockMemoryPrivilege") -#define SE_INCREASE_QUOTA_NAME TEXT("SeIncreaseQuotaPrivilege") -#define SE_UNSOLICITED_INPUT_NAME TEXT("SeUnsolicitedInputPrivilege") -#define SE_MACHINE_ACCOUNT_NAME TEXT("SeMachineAccountPrivilege") -#define SE_TCB_NAME TEXT("SeTcbPrivilege") -#define SE_SECURITY_NAME TEXT("SeSecurityPrivilege") -#define SE_TAKE_OWNERSHIP_NAME TEXT("SeTakeOwnershipPrivilege") -#define SE_LOAD_DRIVER_NAME TEXT("SeLoadDriverPrivilege") -#define SE_SYSTEM_PROFILE_NAME TEXT("SeSystemProfilePrivilege") -#define SE_SYSTEMTIME_NAME TEXT("SeSystemtimePrivilege") -#define SE_PROF_SINGLE_PROCESS_NAME TEXT("SeProfileSingleProcessPrivilege") -#define SE_INC_BASE_PRIORITY_NAME TEXT("SeIncreaseBasePriorityPrivilege") -#define SE_CREATE_PAGEFILE_NAME TEXT("SeCreatePagefilePrivilege") -#define SE_CREATE_PERMANENT_NAME TEXT("SeCreatePermanentPrivilege") -#define SE_BACKUP_NAME TEXT("SeBackupPrivilege") -#define SE_RESTORE_NAME TEXT("SeRestorePrivilege") -#define SE_SHUTDOWN_NAME TEXT("SeShutdownPrivilege") -#define SE_DEBUG_NAME TEXT("SeDebugPrivilege") -#define SE_AUDIT_NAME TEXT("SeAuditPrivilege") -#define SE_SYSTEM_ENVIRONMENT_NAME TEXT("SeSystemEnvironmentPrivilege") -#define SE_CHANGE_NOTIFY_NAME TEXT("SeChangeNotifyPrivilege") -#define SE_REMOTE_SHUTDOWN_NAME TEXT("SeRemoteShutdownPrivilege") -#define SE_UNDOCK_NAME TEXT("SeUndockPrivilege") -#define SE_SYNC_AGENT_NAME TEXT("SeSyncAgentPrivilege") -#define SE_ENABLE_DELEGATION_NAME TEXT("SeEnableDelegationPrivilege") -#define SE_MANAGE_VOLUME_NAME TEXT("SeManageVolumePrivilege") -#define SE_IMPERSONATE_NAME TEXT("SeImpersonatePrivilege") -#define SE_CREATE_GLOBAL_NAME TEXT("SeCreateGlobalPrivilege") - - typedef enum _SECURITY_IMPERSONATION_LEVEL { - SecurityAnonymous,SecurityIdentification,SecurityImpersonation,SecurityDelegation - } SECURITY_IMPERSONATION_LEVEL,*PSECURITY_IMPERSONATION_LEVEL; - -#define SECURITY_MAX_IMPERSONATION_LEVEL SecurityDelegation -#define SECURITY_MIN_IMPERSONATION_LEVEL SecurityAnonymous -#define DEFAULT_IMPERSONATION_LEVEL SecurityImpersonation -#define VALID_IMPERSONATION_LEVEL(L) (((L) >= SECURITY_MIN_IMPERSONATION_LEVEL) && ((L) <= SECURITY_MAX_IMPERSONATION_LEVEL)) - -#define TOKEN_ASSIGN_PRIMARY (0x0001) -#define TOKEN_DUPLICATE (0x0002) -#define TOKEN_IMPERSONATE (0x0004) -#define TOKEN_QUERY (0x0008) -#define TOKEN_QUERY_SOURCE (0x0010) -#define TOKEN_ADJUST_PRIVILEGES (0x0020) -#define TOKEN_ADJUST_GROUPS (0x0040) -#define TOKEN_ADJUST_DEFAULT (0x0080) -#define TOKEN_ADJUST_SESSIONID (0x0100) - -#define TOKEN_ALL_ACCESS_P (STANDARD_RIGHTS_REQUIRED | TOKEN_ASSIGN_PRIMARY | TOKEN_DUPLICATE | TOKEN_IMPERSONATE | TOKEN_QUERY | TOKEN_QUERY_SOURCE | TOKEN_ADJUST_PRIVILEGES | TOKEN_ADJUST_GROUPS | TOKEN_ADJUST_DEFAULT) -#define TOKEN_ALL_ACCESS (TOKEN_ALL_ACCESS_P | TOKEN_ADJUST_SESSIONID) -#define TOKEN_READ (STANDARD_RIGHTS_READ | TOKEN_QUERY) - -#define TOKEN_WRITE (STANDARD_RIGHTS_WRITE | TOKEN_ADJUST_PRIVILEGES | TOKEN_ADJUST_GROUPS | TOKEN_ADJUST_DEFAULT) - -#define TOKEN_EXECUTE (STANDARD_RIGHTS_EXECUTE) - - typedef enum _TOKEN_TYPE { - TokenPrimary = 1,TokenImpersonation - } TOKEN_TYPE; - typedef TOKEN_TYPE *PTOKEN_TYPE; - - typedef enum _TOKEN_INFORMATION_CLASS { - TokenUser = 1,TokenGroups,TokenPrivileges,TokenOwner,TokenPrimaryGroup,TokenDefaultDacl,TokenSource,TokenType,TokenImpersonationLevel, - TokenStatistics,TokenRestrictedSids,TokenSessionId,TokenGroupsAndPrivileges,TokenSessionReference,TokenSandBoxInert,TokenAuditPolicy, - TokenOrigin,MaxTokenInfoClass - } TOKEN_INFORMATION_CLASS,*PTOKEN_INFORMATION_CLASS; - - typedef struct _TOKEN_USER { - SID_AND_ATTRIBUTES User; - } TOKEN_USER,*PTOKEN_USER; - - typedef struct _TOKEN_GROUPS { - DWORD GroupCount; - SID_AND_ATTRIBUTES Groups[ANYSIZE_ARRAY]; - } TOKEN_GROUPS,*PTOKEN_GROUPS; - - typedef struct _TOKEN_PRIVILEGES { - DWORD PrivilegeCount; - LUID_AND_ATTRIBUTES Privileges[ANYSIZE_ARRAY]; - } TOKEN_PRIVILEGES,*PTOKEN_PRIVILEGES; - - typedef struct _TOKEN_OWNER { - PSID Owner; - } TOKEN_OWNER,*PTOKEN_OWNER; - - typedef struct _TOKEN_PRIMARY_GROUP { - PSID PrimaryGroup; - } TOKEN_PRIMARY_GROUP,*PTOKEN_PRIMARY_GROUP; - - typedef struct _TOKEN_DEFAULT_DACL { - PACL DefaultDacl; - } TOKEN_DEFAULT_DACL,*PTOKEN_DEFAULT_DACL; - - typedef struct _TOKEN_GROUPS_AND_PRIVILEGES { - DWORD SidCount; - DWORD SidLength; - PSID_AND_ATTRIBUTES Sids; - DWORD RestrictedSidCount; - DWORD RestrictedSidLength; - PSID_AND_ATTRIBUTES RestrictedSids; - DWORD PrivilegeCount; - DWORD PrivilegeLength; - PLUID_AND_ATTRIBUTES Privileges; - LUID AuthenticationId; - } TOKEN_GROUPS_AND_PRIVILEGES,*PTOKEN_GROUPS_AND_PRIVILEGES; - -#define TOKEN_AUDIT_SUCCESS_INCLUDE 0x1 -#define TOKEN_AUDIT_SUCCESS_EXCLUDE 0x2 -#define TOKEN_AUDIT_FAILURE_INCLUDE 0x4 -#define TOKEN_AUDIT_FAILURE_EXCLUDE 0x8 - -#define VALID_AUDIT_POLICY_BITS (TOKEN_AUDIT_SUCCESS_INCLUDE | TOKEN_AUDIT_SUCCESS_EXCLUDE | TOKEN_AUDIT_FAILURE_INCLUDE | TOKEN_AUDIT_FAILURE_EXCLUDE) -#define VALID_TOKEN_AUDIT_POLICY_ELEMENT(P) ((((P).PolicyMask & ~VALID_AUDIT_POLICY_BITS)==0) && ((P).Category <= AuditEventMaxType)) - - typedef struct _TOKEN_AUDIT_POLICY_ELEMENT { - DWORD Category; - DWORD PolicyMask; - } TOKEN_AUDIT_POLICY_ELEMENT,*PTOKEN_AUDIT_POLICY_ELEMENT; - - typedef struct _TOKEN_AUDIT_POLICY { - DWORD PolicyCount; - TOKEN_AUDIT_POLICY_ELEMENT Policy[ANYSIZE_ARRAY]; - } TOKEN_AUDIT_POLICY,*PTOKEN_AUDIT_POLICY; - -#define PER_USER_AUDITING_POLICY_SIZE(p) (sizeof(TOKEN_AUDIT_POLICY) + (((p)->PolicyCount > ANYSIZE_ARRAY) ? (sizeof(TOKEN_AUDIT_POLICY_ELEMENT) *((p)->PolicyCount - ANYSIZE_ARRAY)) : 0)) -#define PER_USER_AUDITING_POLICY_SIZE_BY_COUNT(C) (sizeof(TOKEN_AUDIT_POLICY) + (((C) > ANYSIZE_ARRAY) ? (sizeof(TOKEN_AUDIT_POLICY_ELEMENT) *((C) - ANYSIZE_ARRAY)) : 0)) - -#define TOKEN_SOURCE_LENGTH 8 - - typedef struct _TOKEN_SOURCE { - CHAR SourceName[TOKEN_SOURCE_LENGTH]; - LUID SourceIdentifier; - } TOKEN_SOURCE,*PTOKEN_SOURCE; - - typedef struct _TOKEN_STATISTICS { - LUID TokenId; - LUID AuthenticationId; - LARGE_INTEGER ExpirationTime; - TOKEN_TYPE TokenType; - SECURITY_IMPERSONATION_LEVEL ImpersonationLevel; - DWORD DynamicCharged; - DWORD DynamicAvailable; - DWORD GroupCount; - DWORD PrivilegeCount; - LUID ModifiedId; - } TOKEN_STATISTICS,*PTOKEN_STATISTICS; - - typedef struct _TOKEN_CONTROL { - LUID TokenId; - LUID AuthenticationId; - LUID ModifiedId; - TOKEN_SOURCE TokenSource; - } TOKEN_CONTROL,*PTOKEN_CONTROL; - - typedef struct _TOKEN_ORIGIN { - LUID OriginatingLogonSession; - } TOKEN_ORIGIN,*PTOKEN_ORIGIN; - -#define SECURITY_DYNAMIC_TRACKING (TRUE) -#define SECURITY_STATIC_TRACKING (FALSE) - - typedef BOOLEAN SECURITY_CONTEXT_TRACKING_MODE,*PSECURITY_CONTEXT_TRACKING_MODE; - - typedef struct _SECURITY_QUALITY_OF_SERVICE { - DWORD Length; - SECURITY_IMPERSONATION_LEVEL ImpersonationLevel; - SECURITY_CONTEXT_TRACKING_MODE ContextTrackingMode; - BOOLEAN EffectiveOnly; - } SECURITY_QUALITY_OF_SERVICE,*PSECURITY_QUALITY_OF_SERVICE; - - typedef struct _SE_IMPERSONATION_STATE { - PACCESS_TOKEN Token; - BOOLEAN CopyOnOpen; - BOOLEAN EffectiveOnly; - SECURITY_IMPERSONATION_LEVEL Level; - } SE_IMPERSONATION_STATE,*PSE_IMPERSONATION_STATE; - -#define DISABLE_MAX_PRIVILEGE 0x1 -#define SANDBOX_INERT 0x2 - - typedef DWORD SECURITY_INFORMATION,*PSECURITY_INFORMATION; - -#define OWNER_SECURITY_INFORMATION (0x00000001L) -#define GROUP_SECURITY_INFORMATION (0x00000002L) -#define DACL_SECURITY_INFORMATION (0x00000004L) -#define SACL_SECURITY_INFORMATION (0x00000008L) - -#define PROTECTED_DACL_SECURITY_INFORMATION (0x80000000L) -#define PROTECTED_SACL_SECURITY_INFORMATION (0x40000000L) -#define UNPROTECTED_DACL_SECURITY_INFORMATION (0x20000000L) -#define UNPROTECTED_SACL_SECURITY_INFORMATION (0x10000000L) - -#define PROCESS_TERMINATE (0x0001) -#define PROCESS_CREATE_THREAD (0x0002) -#define PROCESS_SET_SESSIONID (0x0004) -#define PROCESS_VM_OPERATION (0x0008) -#define PROCESS_VM_READ (0x0010) -#define PROCESS_VM_WRITE (0x0020) -#define PROCESS_DUP_HANDLE (0x0040) -#define PROCESS_CREATE_PROCESS (0x0080) -#define PROCESS_SET_QUOTA (0x0100) -#define PROCESS_SET_INFORMATION (0x0200) -#define PROCESS_QUERY_INFORMATION (0x0400) -#define PROCESS_SUSPEND_RESUME (0x0800) -#define PROCESS_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0xFFF) - -#ifdef _WIN64 -#define MAXIMUM_PROCESSORS 64 -#else -#define MAXIMUM_PROCESSORS 32 -#endif - -#define THREAD_TERMINATE (0x0001) -#define THREAD_SUSPEND_RESUME (0x0002) -#define THREAD_GET_CONTEXT (0x0008) -#define THREAD_SET_CONTEXT (0x0010) -#define THREAD_SET_INFORMATION (0x0020) -#define THREAD_QUERY_INFORMATION (0x0040) -#define THREAD_SET_THREAD_TOKEN (0x0080) -#define THREAD_IMPERSONATE (0x0100) -#define THREAD_DIRECT_IMPERSONATION (0x0200) - -#define THREAD_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x3FF) - -#define JOB_OBJECT_ASSIGN_PROCESS (0x0001) -#define JOB_OBJECT_SET_ATTRIBUTES (0x0002) -#define JOB_OBJECT_QUERY (0x0004) -#define JOB_OBJECT_TERMINATE (0x0008) -#define JOB_OBJECT_SET_SECURITY_ATTRIBUTES (0x0010) -#define JOB_OBJECT_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x1F) - - typedef struct _JOB_SET_ARRAY { - HANDLE JobHandle; - DWORD MemberLevel; - DWORD Flags; - } JOB_SET_ARRAY,*PJOB_SET_ARRAY; - -#define FLS_MAXIMUM_AVAILABLE 128 -#define TLS_MINIMUM_AVAILABLE 64 - -#ifndef _NT_TIB_DEFINED -#define _NT_TIB_DEFINED - typedef struct _NT_TIB { - struct _EXCEPTION_REGISTRATION_RECORD *ExceptionList; - PVOID StackBase; - PVOID StackLimit; - PVOID SubSystemTib; - union { - PVOID FiberData; - DWORD Version; - }; - PVOID ArbitraryUserPointer; - struct _NT_TIB *Self; - } NT_TIB; - typedef NT_TIB *PNT_TIB; -#endif - - typedef struct _NT_TIB32 { - DWORD ExceptionList; - DWORD StackBase; - DWORD StackLimit; - DWORD SubSystemTib; - union { - DWORD FiberData; - DWORD Version; - }; - DWORD ArbitraryUserPointer; - DWORD Self; - } NT_TIB32,*PNT_TIB32; - - typedef struct _NT_TIB64 { - DWORD64 ExceptionList; - DWORD64 StackBase; - DWORD64 StackLimit; - DWORD64 SubSystemTib; - union { - DWORD64 FiberData; - DWORD Version; - }; - DWORD64 ArbitraryUserPointer; - DWORD64 Self; - } NT_TIB64,*PNT_TIB64; - -#if !defined(I_X86_) && !defined(_IA64_) && !defined(_AMD64_) -#define WX86 -#endif - -#define THREAD_BASE_PRIORITY_LOWRT 15 -#define THREAD_BASE_PRIORITY_MAX 2 -#define THREAD_BASE_PRIORITY_MIN (-2) -#define THREAD_BASE_PRIORITY_IDLE (-15) - - typedef struct _QUOTA_LIMITS { - SIZE_T PagedPoolLimit; - SIZE_T NonPagedPoolLimit; - SIZE_T MinimumWorkingSetSize; - SIZE_T MaximumWorkingSetSize; - SIZE_T PagefileLimit; - LARGE_INTEGER TimeLimit; - } QUOTA_LIMITS,*PQUOTA_LIMITS; - -#define QUOTA_LIMITS_HARDWS_MIN_ENABLE 0x00000001 -#define QUOTA_LIMITS_HARDWS_MIN_DISABLE 0x00000002 -#define QUOTA_LIMITS_HARDWS_MAX_ENABLE 0x00000004 -#define QUOTA_LIMITS_HARDWS_MAX_DISABLE 0x00000008 - - typedef struct _QUOTA_LIMITS_EX { - SIZE_T PagedPoolLimit; - SIZE_T NonPagedPoolLimit; - SIZE_T MinimumWorkingSetSize; - SIZE_T MaximumWorkingSetSize; - SIZE_T PagefileLimit; - LARGE_INTEGER TimeLimit; - SIZE_T Reserved1; - SIZE_T Reserved2; - SIZE_T Reserved3; - SIZE_T Reserved4; - DWORD Flags; - DWORD Reserved5; - } QUOTA_LIMITS_EX,*PQUOTA_LIMITS_EX; - - typedef struct _IO_COUNTERS { - ULONGLONG ReadOperationCount; - ULONGLONG WriteOperationCount; - ULONGLONG OtherOperationCount; - ULONGLONG ReadTransferCount; - ULONGLONG WriteTransferCount; - ULONGLONG OtherTransferCount; - } IO_COUNTERS; - typedef IO_COUNTERS *PIO_COUNTERS; - - typedef struct _JOBOBJECT_BASIC_ACCOUNTING_INFORMATION { - LARGE_INTEGER TotalUserTime; - LARGE_INTEGER TotalKernelTime; - LARGE_INTEGER ThisPeriodTotalUserTime; - LARGE_INTEGER ThisPeriodTotalKernelTime; - DWORD TotalPageFaultCount; - DWORD TotalProcesses; - DWORD ActiveProcesses; - DWORD TotalTerminatedProcesses; - } JOBOBJECT_BASIC_ACCOUNTING_INFORMATION,*PJOBOBJECT_BASIC_ACCOUNTING_INFORMATION; - - typedef struct _JOBOBJECT_BASIC_LIMIT_INFORMATION { - LARGE_INTEGER PerProcessUserTimeLimit; - LARGE_INTEGER PerJobUserTimeLimit; - DWORD LimitFlags; - SIZE_T MinimumWorkingSetSize; - SIZE_T MaximumWorkingSetSize; - DWORD ActiveProcessLimit; - ULONG_PTR Affinity; - DWORD PriorityClass; - DWORD SchedulingClass; - } JOBOBJECT_BASIC_LIMIT_INFORMATION,*PJOBOBJECT_BASIC_LIMIT_INFORMATION; - - typedef struct _JOBOBJECT_EXTENDED_LIMIT_INFORMATION { - JOBOBJECT_BASIC_LIMIT_INFORMATION BasicLimitInformation; - IO_COUNTERS IoInfo; - SIZE_T ProcessMemoryLimit; - SIZE_T JobMemoryLimit; - SIZE_T PeakProcessMemoryUsed; - SIZE_T PeakJobMemoryUsed; - } JOBOBJECT_EXTENDED_LIMIT_INFORMATION,*PJOBOBJECT_EXTENDED_LIMIT_INFORMATION; - - typedef struct _JOBOBJECT_BASIC_PROCESS_ID_LIST { - DWORD NumberOfAssignedProcesses; - DWORD NumberOfProcessIdsInList; - ULONG_PTR ProcessIdList[1]; - } JOBOBJECT_BASIC_PROCESS_ID_LIST,*PJOBOBJECT_BASIC_PROCESS_ID_LIST; - - typedef struct _JOBOBJECT_BASIC_UI_RESTRICTIONS { - DWORD UIRestrictionsClass; - } JOBOBJECT_BASIC_UI_RESTRICTIONS,*PJOBOBJECT_BASIC_UI_RESTRICTIONS; - - typedef struct _JOBOBJECT_SECURITY_LIMIT_INFORMATION { - DWORD SecurityLimitFlags; - HANDLE JobToken; - PTOKEN_GROUPS SidsToDisable; - PTOKEN_PRIVILEGES PrivilegesToDelete; - PTOKEN_GROUPS RestrictedSids; - } JOBOBJECT_SECURITY_LIMIT_INFORMATION,*PJOBOBJECT_SECURITY_LIMIT_INFORMATION; - - typedef struct _JOBOBJECT_END_OF_JOB_TIME_INFORMATION { - DWORD EndOfJobTimeAction; - } JOBOBJECT_END_OF_JOB_TIME_INFORMATION,*PJOBOBJECT_END_OF_JOB_TIME_INFORMATION; - - typedef struct _JOBOBJECT_ASSOCIATE_COMPLETION_PORT { - PVOID CompletionKey; - HANDLE CompletionPort; - } JOBOBJECT_ASSOCIATE_COMPLETION_PORT,*PJOBOBJECT_ASSOCIATE_COMPLETION_PORT; - - typedef struct _JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION { - JOBOBJECT_BASIC_ACCOUNTING_INFORMATION BasicInfo; - IO_COUNTERS IoInfo; - } JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION,*PJOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION; - - typedef struct _JOBOBJECT_JOBSET_INFORMATION { - DWORD MemberLevel; - } JOBOBJECT_JOBSET_INFORMATION,*PJOBOBJECT_JOBSET_INFORMATION; - -#define JOB_OBJECT_TERMINATE_AT_END_OF_JOB 0 -#define JOB_OBJECT_POST_AT_END_OF_JOB 1 - -#define JOB_OBJECT_MSG_END_OF_JOB_TIME 1 -#define JOB_OBJECT_MSG_END_OF_PROCESS_TIME 2 -#define JOB_OBJECT_MSG_ACTIVE_PROCESS_LIMIT 3 -#define JOB_OBJECT_MSG_ACTIVE_PROCESS_ZERO 4 -#define JOB_OBJECT_MSG_NEW_PROCESS 6 -#define JOB_OBJECT_MSG_EXIT_PROCESS 7 -#define JOB_OBJECT_MSG_ABNORMAL_EXIT_PROCESS 8 -#define JOB_OBJECT_MSG_PROCESS_MEMORY_LIMIT 9 -#define JOB_OBJECT_MSG_JOB_MEMORY_LIMIT 10 - -#define JOB_OBJECT_LIMIT_WORKINGSET 0x00000001 -#define JOB_OBJECT_LIMIT_PROCESS_TIME 0x00000002 -#define JOB_OBJECT_LIMIT_JOB_TIME 0x00000004 -#define JOB_OBJECT_LIMIT_ACTIVE_PROCESS 0x00000008 -#define JOB_OBJECT_LIMIT_AFFINITY 0x00000010 -#define JOB_OBJECT_LIMIT_PRIORITY_CLASS 0x00000020 -#define JOB_OBJECT_LIMIT_PRESERVE_JOB_TIME 0x00000040 -#define JOB_OBJECT_LIMIT_SCHEDULING_CLASS 0x00000080 - -#define JOB_OBJECT_LIMIT_PROCESS_MEMORY 0x00000100 -#define JOB_OBJECT_LIMIT_JOB_MEMORY 0x00000200 -#define JOB_OBJECT_LIMIT_DIE_ON_UNHANDLED_EXCEPTION 0x00000400 -#define JOB_OBJECT_LIMIT_BREAKAWAY_OK 0x00000800 -#define JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK 0x00001000 -#define JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE 0x00002000 - -#define JOB_OBJECT_LIMIT_RESERVED2 0x00004000 -#define JOB_OBJECT_LIMIT_RESERVED3 0x00008000 -#define JOB_OBJECT_LIMIT_RESERVED4 0x00010000 -#define JOB_OBJECT_LIMIT_RESERVED5 0x00020000 -#define JOB_OBJECT_LIMIT_RESERVED6 0x00040000 - -#define JOB_OBJECT_LIMIT_VALID_FLAGS 0x0007ffff - -#define JOB_OBJECT_BASIC_LIMIT_VALID_FLAGS 0x000000ff -#define JOB_OBJECT_EXTENDED_LIMIT_VALID_FLAGS 0x00003fff -#define JOB_OBJECT_RESERVED_LIMIT_VALID_FLAGS 0x0007ffff - -#define JOB_OBJECT_UILIMIT_NONE 0x00000000 - -#define JOB_OBJECT_UILIMIT_HANDLES 0x00000001 -#define JOB_OBJECT_UILIMIT_READCLIPBOARD 0x00000002 -#define JOB_OBJECT_UILIMIT_WRITECLIPBOARD 0x00000004 -#define JOB_OBJECT_UILIMIT_SYSTEMPARAMETERS 0x00000008 -#define JOB_OBJECT_UILIMIT_DISPLAYSETTINGS 0x00000010 -#define JOB_OBJECT_UILIMIT_GLOBALATOMS 0x00000020 -#define JOB_OBJECT_UILIMIT_DESKTOP 0x00000040 -#define JOB_OBJECT_UILIMIT_EXITWINDOWS 0x00000080 - -#define JOB_OBJECT_UILIMIT_ALL 0x000000FF - -#define JOB_OBJECT_UI_VALID_FLAGS 0x000000FF - -#define JOB_OBJECT_SECURITY_NO_ADMIN 0x00000001 -#define JOB_OBJECT_SECURITY_RESTRICTED_TOKEN 0x00000002 -#define JOB_OBJECT_SECURITY_ONLY_TOKEN 0x00000004 -#define JOB_OBJECT_SECURITY_FILTER_TOKENS 0x00000008 - -#define JOB_OBJECT_SECURITY_VALID_FLAGS 0x0000000f - - typedef enum _JOBOBJECTINFOCLASS { - JobObjectBasicAccountingInformation = 1,JobObjectBasicLimitInformation,JobObjectBasicProcessIdList,JobObjectBasicUIRestrictions, - JobObjectSecurityLimitInformation,JobObjectEndOfJobTimeInformation,JobObjectAssociateCompletionPortInformation, - JobObjectBasicAndIoAccountingInformation,JobObjectExtendedLimitInformation,JobObjectJobSetInformation,MaxJobObjectInfoClass - } JOBOBJECTINFOCLASS; - -#define EVENT_MODIFY_STATE 0x0002 -#define EVENT_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3) - -#define MUTANT_QUERY_STATE 0x0001 - -#define MUTANT_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE| MUTANT_QUERY_STATE) -#define SEMAPHORE_MODIFY_STATE 0x0002 -#define SEMAPHORE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3) - -#define TIMER_QUERY_STATE 0x0001 -#define TIMER_MODIFY_STATE 0x0002 - -#define TIMER_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE| TIMER_QUERY_STATE|TIMER_MODIFY_STATE) - -#define TIME_ZONE_ID_UNKNOWN 0 -#define TIME_ZONE_ID_STANDARD 1 -#define TIME_ZONE_ID_DAYLIGHT 2 - - typedef enum _LOGICAL_PROCESSOR_RELATIONSHIP { - RelationProcessorCore,RelationNumaNode,RelationCache - } LOGICAL_PROCESSOR_RELATIONSHIP; - -#define LTP_PC_SMT 0x1 - - typedef enum _PROCESSOR_CACHE_TYPE { - CacheUnified,CacheInstruction,CacheData,CacheTrace - } PROCESSOR_CACHE_TYPE; - -#define CACHE_FULLY_ASSOCIATIVE 0xFF - - typedef struct _CACHE_DESCRIPTOR { - BYTE Level; - BYTE Associativity; - WORD LineSize; - DWORD Size; - PROCESSOR_CACHE_TYPE Type; - } CACHE_DESCRIPTOR,*PCACHE_DESCRIPTOR; - - typedef struct _SYSTEM_LOGICAL_PROCESSOR_INFORMATION { - ULONG_PTR ProcessorMask; - LOGICAL_PROCESSOR_RELATIONSHIP Relationship; - union { - struct { - BYTE Flags; - } ProcessorCore; - struct { - DWORD NodeNumber; - } NumaNode; - CACHE_DESCRIPTOR Cache; - ULONGLONG Reserved[2]; - }; - } SYSTEM_LOGICAL_PROCESSOR_INFORMATION,*PSYSTEM_LOGICAL_PROCESSOR_INFORMATION; - -#define PROCESSOR_INTEL_386 386 -#define PROCESSOR_INTEL_486 486 -#define PROCESSOR_INTEL_PENTIUM 586 -#define PROCESSOR_INTEL_IA64 2200 -#define PROCESSOR_AMD_X8664 8664 -#define PROCESSOR_MIPS_R4000 4000 -#define PROCESSOR_ALPHA_21064 21064 -#define PROCESSOR_PPC_601 601 -#define PROCESSOR_PPC_603 603 -#define PROCESSOR_PPC_604 604 -#define PROCESSOR_PPC_620 620 -#define PROCESSOR_HITACHI_SH3 10003 -#define PROCESSOR_HITACHI_SH3E 10004 -#define PROCESSOR_HITACHI_SH4 10005 -#define PROCESSOR_MOTOROLA_821 821 -#define PROCESSOR_SHx_SH3 103 -#define PROCESSOR_SHx_SH4 104 -#define PROCESSOR_STRONGARM 2577 -#define PROCESSOR_ARM720 1824 -#define PROCESSOR_ARM820 2080 -#define PROCESSOR_ARM920 2336 -#define PROCESSOR_ARM_7TDMI 70001 -#define PROCESSOR_OPTIL 0x494f - -#define PROCESSOR_ARCHITECTURE_INTEL 0 -#define PROCESSOR_ARCHITECTURE_MIPS 1 -#define PROCESSOR_ARCHITECTURE_ALPHA 2 -#define PROCESSOR_ARCHITECTURE_PPC 3 -#define PROCESSOR_ARCHITECTURE_SHX 4 -#define PROCESSOR_ARCHITECTURE_ARM 5 -#define PROCESSOR_ARCHITECTURE_IA64 6 -#define PROCESSOR_ARCHITECTURE_ALPHA64 7 -#define PROCESSOR_ARCHITECTURE_MSIL 8 -#define PROCESSOR_ARCHITECTURE_AMD64 9 -#define PROCESSOR_ARCHITECTURE_IA32_ON_WIN64 10 - -#define PROCESSOR_ARCHITECTURE_UNKNOWN 0xFFFF - -#define PF_FLOATING_POINT_PRECISION_ERRATA 0 -#define PF_FLOATING_POINT_EMULATED 1 -#define PF_COMPARE_EXCHANGE_DOUBLE 2 -#define PF_MMX_INSTRUCTIONS_AVAILABLE 3 -#define PF_PPC_MOVEMEM_64BIT_OK 4 -#define PF_ALPHA_BYTE_INSTRUCTIONS 5 -#define PF_XMMI_INSTRUCTIONS_AVAILABLE 6 -#define PF_3DNOW_INSTRUCTIONS_AVAILABLE 7 -#define PF_RDTSC_INSTRUCTION_AVAILABLE 8 -#define PF_PAE_ENABLED 9 -#define PF_XMMI64_INSTRUCTIONS_AVAILABLE 10 -#define PF_SSE_DAZ_MODE_AVAILABLE 11 -#define PF_NX_ENABLED 12 - - typedef struct _MEMORY_BASIC_INFORMATION { - PVOID BaseAddress; - PVOID AllocationBase; - DWORD AllocationProtect; - SIZE_T RegionSize; - DWORD State; - DWORD Protect; - DWORD Type; - } MEMORY_BASIC_INFORMATION,*PMEMORY_BASIC_INFORMATION; - - typedef struct _MEMORY_BASIC_INFORMATION32 { - DWORD BaseAddress; - DWORD AllocationBase; - DWORD AllocationProtect; - DWORD RegionSize; - DWORD State; - DWORD Protect; - DWORD Type; - } MEMORY_BASIC_INFORMATION32,*PMEMORY_BASIC_INFORMATION32; - - typedef DECLSPEC_ALIGN(16) struct _MEMORY_BASIC_INFORMATION64 { - ULONGLONG BaseAddress; - ULONGLONG AllocationBase; - DWORD AllocationProtect; - DWORD __alignment1; - ULONGLONG RegionSize; - DWORD State; - DWORD Protect; - DWORD Type; - DWORD __alignment2; - } MEMORY_BASIC_INFORMATION64,*PMEMORY_BASIC_INFORMATION64; - -#define SECTION_QUERY 0x0001 -#define SECTION_MAP_WRITE 0x0002 -#define SECTION_MAP_READ 0x0004 -#define SECTION_MAP_EXECUTE 0x0008 -#define SECTION_EXTEND_SIZE 0x0010 -#define SECTION_MAP_EXECUTE_EXPLICIT 0x0020 - -#define SECTION_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SECTION_QUERY| SECTION_MAP_WRITE | SECTION_MAP_READ | SECTION_MAP_EXECUTE | SECTION_EXTEND_SIZE) -#define PAGE_NOACCESS 0x01 -#define PAGE_READONLY 0x02 -#define PAGE_READWRITE 0x04 -#define PAGE_WRITECOPY 0x08 -#define PAGE_EXECUTE 0x10 -#define PAGE_EXECUTE_READ 0x20 -#define PAGE_EXECUTE_READWRITE 0x40 -#define PAGE_EXECUTE_WRITECOPY 0x80 -#define PAGE_GUARD 0x100 -#define PAGE_NOCACHE 0x200 -#define PAGE_WRITECOMBINE 0x400 -#define MEM_COMMIT 0x1000 -#define MEM_RESERVE 0x2000 -#define MEM_DECOMMIT 0x4000 -#define MEM_RELEASE 0x8000 -#define MEM_FREE 0x10000 -#define MEM_PRIVATE 0x20000 -#define MEM_MAPPED 0x40000 -#define MEM_RESET 0x80000 -#define MEM_TOP_DOWN 0x100000 -#define MEM_WRITE_WATCH 0x200000 -#define MEM_PHYSICAL 0x400000 -#define MEM_LARGE_PAGES 0x20000000 -#define MEM_4MB_PAGES 0x80000000 -#define SEC_FILE 0x800000 -#define SEC_IMAGE 0x1000000 -#define SEC_RESERVE 0x4000000 -#define SEC_COMMIT 0x8000000 -#define SEC_NOCACHE 0x10000000 -#define SEC_LARGE_PAGES 0x80000000 -#define MEM_IMAGE SEC_IMAGE -#define WRITE_WATCH_FLAG_RESET 0x01 - -#define FILE_READ_DATA (0x0001) -#define FILE_LIST_DIRECTORY (0x0001) - -#define FILE_WRITE_DATA (0x0002) -#define FILE_ADD_FILE (0x0002) - -#define FILE_APPEND_DATA (0x0004) -#define FILE_ADD_SUBDIRECTORY (0x0004) -#define FILE_CREATE_PIPE_INSTANCE (0x0004) - -#define FILE_READ_EA (0x0008) - -#define FILE_WRITE_EA (0x0010) - -#define FILE_EXECUTE (0x0020) -#define FILE_TRAVERSE (0x0020) - -#define FILE_DELETE_CHILD (0x0040) - -#define FILE_READ_ATTRIBUTES (0x0080) - -#define FILE_WRITE_ATTRIBUTES (0x0100) - -#define FILE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x1FF) -#define FILE_GENERIC_READ (STANDARD_RIGHTS_READ | FILE_READ_DATA | FILE_READ_ATTRIBUTES | FILE_READ_EA | SYNCHRONIZE) -#define FILE_GENERIC_WRITE (STANDARD_RIGHTS_WRITE | FILE_WRITE_DATA | FILE_WRITE_ATTRIBUTES | FILE_WRITE_EA | FILE_APPEND_DATA | SYNCHRONIZE) -#define FILE_GENERIC_EXECUTE (STANDARD_RIGHTS_EXECUTE | FILE_READ_ATTRIBUTES | FILE_EXECUTE | SYNCHRONIZE) - -#define FILE_SHARE_READ 0x00000001 -#define FILE_SHARE_WRITE 0x00000002 -#define FILE_SHARE_DELETE 0x00000004 -#define FILE_ATTRIBUTE_READONLY 0x00000001 -#define FILE_ATTRIBUTE_HIDDEN 0x00000002 -#define FILE_ATTRIBUTE_SYSTEM 0x00000004 -#define FILE_ATTRIBUTE_DIRECTORY 0x00000010 -#define FILE_ATTRIBUTE_ARCHIVE 0x00000020 -#define FILE_ATTRIBUTE_DEVICE 0x00000040 -#define FILE_ATTRIBUTE_NORMAL 0x00000080 -#define FILE_ATTRIBUTE_TEMPORARY 0x00000100 -#define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200 -#define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400 -#define FILE_ATTRIBUTE_COMPRESSED 0x00000800 -#define FILE_ATTRIBUTE_OFFLINE 0x00001000 -#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000 -#define FILE_ATTRIBUTE_ENCRYPTED 0x00004000 -#define FILE_NOTIFY_CHANGE_FILE_NAME 0x00000001 -#define FILE_NOTIFY_CHANGE_DIR_NAME 0x00000002 -#define FILE_NOTIFY_CHANGE_ATTRIBUTES 0x00000004 -#define FILE_NOTIFY_CHANGE_SIZE 0x00000008 -#define FILE_NOTIFY_CHANGE_LAST_WRITE 0x00000010 -#define FILE_NOTIFY_CHANGE_LAST_ACCESS 0x00000020 -#define FILE_NOTIFY_CHANGE_CREATION 0x00000040 -#define FILE_NOTIFY_CHANGE_SECURITY 0x00000100 -#define FILE_ACTION_ADDED 0x00000001 -#define FILE_ACTION_REMOVED 0x00000002 -#define FILE_ACTION_MODIFIED 0x00000003 -#define FILE_ACTION_RENAMED_OLD_NAME 0x00000004 -#define FILE_ACTION_RENAMED_NEW_NAME 0x00000005 -#define MAILSLOT_NO_MESSAGE ((DWORD)-1) -#define MAILSLOT_WAIT_FOREVER ((DWORD)-1) -#define FILE_CASE_SENSITIVE_SEARCH 0x00000001 -#define FILE_CASE_PRESERVED_NAMES 0x00000002 -#define FILE_UNICODE_ON_DISK 0x00000004 -#define FILE_PERSISTENT_ACLS 0x00000008 -#define FILE_FILE_COMPRESSION 0x00000010 -#define FILE_VOLUME_QUOTAS 0x00000020 -#define FILE_SUPPORTS_SPARSE_FILES 0x00000040 -#define FILE_SUPPORTS_REPARSE_POINTS 0x00000080 -#define FILE_SUPPORTS_REMOTE_STORAGE 0x00000100 -#define FILE_VOLUME_IS_COMPRESSED 0x00008000 -#define FILE_SUPPORTS_OBJECT_IDS 0x00010000 -#define FILE_SUPPORTS_ENCRYPTION 0x00020000 -#define FILE_NAMED_STREAMS 0x00040000 -#define FILE_READ_ONLY_VOLUME 0x00080000 - - typedef struct _FILE_NOTIFY_INFORMATION { - DWORD NextEntryOffset; - DWORD Action; - DWORD FileNameLength; - WCHAR FileName[1]; - } FILE_NOTIFY_INFORMATION,*PFILE_NOTIFY_INFORMATION; - - typedef union _FILE_SEGMENT_ELEMENT { - PVOID64 Buffer; - ULONGLONG Alignment; - }FILE_SEGMENT_ELEMENT,*PFILE_SEGMENT_ELEMENT; - - typedef struct _REPARSE_GUID_DATA_BUFFER { - DWORD ReparseTag; - WORD ReparseDataLength; - WORD Reserved; - GUID ReparseGuid; - struct { - BYTE DataBuffer[1]; - } GenericReparseBuffer; - } REPARSE_GUID_DATA_BUFFER,*PREPARSE_GUID_DATA_BUFFER; - -#define REPARSE_GUID_DATA_BUFFER_HEADER_SIZE FIELD_OFFSET(REPARSE_GUID_DATA_BUFFER,GenericReparseBuffer) - -#define MAXIMUM_REPARSE_DATA_BUFFER_SIZE (16 *1024) - -#define IO_REPARSE_TAG_RESERVED_ZERO (0) -#define IO_REPARSE_TAG_RESERVED_ONE (1) - -#define IO_REPARSE_TAG_RESERVED_RANGE IO_REPARSE_TAG_RESERVED_ONE - -#define IsReparseTagMicrosoft(_tag) (((_tag) & 0x80000000)) -#define IsReparseTagNameSurrogate(_tag) (((_tag) & 0x20000000)) - -#define IO_REPARSE_TAG_MOUNT_POINT (0xA0000003L) -#define IO_REPARSE_TAG_HSM (0xC0000004L) -#define IO_REPARSE_TAG_SIS (0x80000007L) -#define IO_REPARSE_TAG_DFS (0x8000000AL) -#define IO_REPARSE_TAG_FILTER_MANAGER (0x8000000BL) -#define IO_COMPLETION_MODIFY_STATE 0x0002 -#define IO_COMPLETION_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3) -#define DUPLICATE_CLOSE_SOURCE 0x00000001 -#define DUPLICATE_SAME_ACCESS 0x00000002 - - typedef enum _SYSTEM_POWER_STATE { - PowerSystemUnspecified = 0,PowerSystemWorking = 1,PowerSystemSleeping1 = 2,PowerSystemSleeping2 = 3,PowerSystemSleeping3 = 4,PowerSystemHibernate = 5,PowerSystemShutdown = 6,PowerSystemMaximum = 7 - } SYSTEM_POWER_STATE,*PSYSTEM_POWER_STATE; - -#define POWER_SYSTEM_MAXIMUM 7 - - typedef enum { - PowerActionNone = 0,PowerActionReserved,PowerActionSleep,PowerActionHibernate,PowerActionShutdown,PowerActionShutdownReset,PowerActionShutdownOff,PowerActionWarmEject - } POWER_ACTION,*PPOWER_ACTION; - - typedef enum _DEVICE_POWER_STATE { - PowerDeviceUnspecified = 0,PowerDeviceD0,PowerDeviceD1,PowerDeviceD2,PowerDeviceD3,PowerDeviceMaximum - } DEVICE_POWER_STATE,*PDEVICE_POWER_STATE; - -#define ES_SYSTEM_REQUIRED ((DWORD)0x00000001) -#define ES_DISPLAY_REQUIRED ((DWORD)0x00000002) -#define ES_USER_PRESENT ((DWORD)0x00000004) -#define ES_CONTINUOUS ((DWORD)0x80000000) - - typedef DWORD EXECUTION_STATE; - - typedef enum { - LT_DONT_CARE,LT_LOWEST_LATENCY - } LATENCY_TIME; - -#define PDCAP_D0_SUPPORTED 0x00000001 -#define PDCAP_D1_SUPPORTED 0x00000002 -#define PDCAP_D2_SUPPORTED 0x00000004 -#define PDCAP_D3_SUPPORTED 0x00000008 -#define PDCAP_WAKE_FROM_D0_SUPPORTED 0x00000010 -#define PDCAP_WAKE_FROM_D1_SUPPORTED 0x00000020 -#define PDCAP_WAKE_FROM_D2_SUPPORTED 0x00000040 -#define PDCAP_WAKE_FROM_D3_SUPPORTED 0x00000080 -#define PDCAP_WARM_EJECT_SUPPORTED 0x00000100 - - typedef struct CM_Power_Data_s { - DWORD PD_Size; - DEVICE_POWER_STATE PD_MostRecentPowerState; - DWORD PD_Capabilities; - DWORD PD_D1Latency; - DWORD PD_D2Latency; - DWORD PD_D3Latency; - DEVICE_POWER_STATE PD_PowerStateMapping[POWER_SYSTEM_MAXIMUM]; - SYSTEM_POWER_STATE PD_DeepestSystemWake; - } CM_POWER_DATA,*PCM_POWER_DATA; - - typedef enum { - SystemPowerPolicyAc,SystemPowerPolicyDc,VerifySystemPolicyAc,VerifySystemPolicyDc,SystemPowerCapabilities,SystemBatteryState,SystemPowerStateHandler,ProcessorStateHandler,SystemPowerPolicyCurrent,AdministratorPowerPolicy,SystemReserveHiberFile,ProcessorInformation,SystemPowerInformation,ProcessorStateHandler2,LastWakeTime,LastSleepTime,SystemExecutionState,SystemPowerStateNotifyHandler,ProcessorPowerPolicyAc,ProcessorPowerPolicyDc,VerifyProcessorPowerPolicyAc,VerifyProcessorPowerPolicyDc,ProcessorPowerPolicyCurrent,SystemPowerStateLogging,SystemPowerLoggingEntry - } POWER_INFORMATION_LEVEL; - - typedef struct { - DWORD Granularity; - DWORD Capacity; - } BATTERY_REPORTING_SCALE,*PBATTERY_REPORTING_SCALE; - - typedef struct { - POWER_ACTION Action; - DWORD Flags; - DWORD EventCode; - } POWER_ACTION_POLICY,*PPOWER_ACTION_POLICY; - -#define POWER_ACTION_QUERY_ALLOWED 0x00000001 -#define POWER_ACTION_UI_ALLOWED 0x00000002 -#define POWER_ACTION_OVERRIDE_APPS 0x00000004 -#define POWER_ACTION_LIGHTEST_FIRST 0x10000000 -#define POWER_ACTION_LOCK_CONSOLE 0x20000000 -#define POWER_ACTION_DISABLE_WAKES 0x40000000 -#define POWER_ACTION_CRITICAL 0x80000000 - -#define POWER_LEVEL_USER_NOTIFY_TEXT 0x00000001 -#define POWER_LEVEL_USER_NOTIFY_SOUND 0x00000002 -#define POWER_LEVEL_USER_NOTIFY_EXEC 0x00000004 -#define POWER_USER_NOTIFY_BUTTON 0x00000008 -#define POWER_USER_NOTIFY_SHUTDOWN 0x00000010 -#define POWER_FORCE_TRIGGER_RESET 0x80000000 - - typedef struct { - BOOLEAN Enable; - BYTE Spare[3]; - DWORD BatteryLevel; - POWER_ACTION_POLICY PowerPolicy; - SYSTEM_POWER_STATE MinSystemState; - } SYSTEM_POWER_LEVEL,*PSYSTEM_POWER_LEVEL; - -#define NUM_DISCHARGE_POLICIES 4 -#define DISCHARGE_POLICY_CRITICAL 0 -#define DISCHARGE_POLICY_LOW 1 - -#define PO_THROTTLE_NONE 0 -#define PO_THROTTLE_CONSTANT 1 -#define PO_THROTTLE_DEGRADE 2 -#define PO_THROTTLE_ADAPTIVE 3 -#define PO_THROTTLE_MAXIMUM 4 - - typedef struct _SYSTEM_POWER_POLICY { - DWORD Revision; - POWER_ACTION_POLICY PowerButton; - POWER_ACTION_POLICY SleepButton; - POWER_ACTION_POLICY LidClose; - SYSTEM_POWER_STATE LidOpenWake; - DWORD Reserved; - POWER_ACTION_POLICY Idle; - DWORD IdleTimeout; - BYTE IdleSensitivity; - BYTE DynamicThrottle; - BYTE Spare2[2]; - SYSTEM_POWER_STATE MinSleep; - SYSTEM_POWER_STATE MaxSleep; - SYSTEM_POWER_STATE ReducedLatencySleep; - DWORD WinLogonFlags; - DWORD Spare3; - DWORD DozeS4Timeout; - DWORD BroadcastCapacityResolution; - SYSTEM_POWER_LEVEL DischargePolicy[NUM_DISCHARGE_POLICIES]; - DWORD VideoTimeout; - BOOLEAN VideoDimDisplay; - DWORD VideoReserved[3]; - DWORD SpindownTimeout; - BOOLEAN OptimizeForPower; - BYTE FanThrottleTolerance; - BYTE ForcedThrottle; - BYTE MinThrottle; - POWER_ACTION_POLICY OverThrottled; - } SYSTEM_POWER_POLICY,*PSYSTEM_POWER_POLICY; - - typedef struct _PROCESSOR_POWER_POLICY_INFO { - DWORD TimeCheck; - DWORD DemoteLimit; - DWORD PromoteLimit; - BYTE DemotePercent; - BYTE PromotePercent; - BYTE Spare[2]; - DWORD AllowDemotion:1; - DWORD AllowPromotion:1; - DWORD Reserved:30; - } PROCESSOR_POWER_POLICY_INFO,*PPROCESSOR_POWER_POLICY_INFO; - - typedef struct _PROCESSOR_POWER_POLICY { - DWORD Revision; - BYTE DynamicThrottle; - BYTE Spare[3]; - DWORD DisableCStates:1; - DWORD Reserved:31; - DWORD PolicyCount; - PROCESSOR_POWER_POLICY_INFO Policy[3]; - } PROCESSOR_POWER_POLICY,*PPROCESSOR_POWER_POLICY; - - typedef struct _ADMINISTRATOR_POWER_POLICY { - SYSTEM_POWER_STATE MinSleep; - SYSTEM_POWER_STATE MaxSleep; - DWORD MinVideoTimeout; - DWORD MaxVideoTimeout; - DWORD MinSpindownTimeout; - DWORD MaxSpindownTimeout; - } ADMINISTRATOR_POWER_POLICY,*PADMINISTRATOR_POWER_POLICY; - - typedef struct { - BOOLEAN PowerButtonPresent; - BOOLEAN SleepButtonPresent; - BOOLEAN LidPresent; - BOOLEAN SystemS1; - BOOLEAN SystemS2; - BOOLEAN SystemS3; - BOOLEAN SystemS4; - BOOLEAN SystemS5; - BOOLEAN HiberFilePresent; - BOOLEAN FullWake; - BOOLEAN VideoDimPresent; - BOOLEAN ApmPresent; - BOOLEAN UpsPresent; - BOOLEAN ThermalControl; - BOOLEAN ProcessorThrottle; - BYTE ProcessorMinThrottle; - BYTE ProcessorMaxThrottle; - BYTE spare2[4]; - BOOLEAN DiskSpinDown; - BYTE spare3[8]; - BOOLEAN SystemBatteriesPresent; - BOOLEAN BatteriesAreShortTerm; - BATTERY_REPORTING_SCALE BatteryScale[3]; - SYSTEM_POWER_STATE AcOnLineWake; - SYSTEM_POWER_STATE SoftLidWake; - SYSTEM_POWER_STATE RtcWake; - SYSTEM_POWER_STATE MinDeviceWakeState; - SYSTEM_POWER_STATE DefaultLowLatencyWake; - } SYSTEM_POWER_CAPABILITIES,*PSYSTEM_POWER_CAPABILITIES; - - typedef struct { - BOOLEAN AcOnLine; - BOOLEAN BatteryPresent; - BOOLEAN Charging; - BOOLEAN Discharging; - BOOLEAN Spare1[4]; - DWORD MaxCapacity; - DWORD RemainingCapacity; - DWORD Rate; - DWORD EstimatedTime; - DWORD DefaultAlert1; - DWORD DefaultAlert2; - } SYSTEM_BATTERY_STATE,*PSYSTEM_BATTERY_STATE; - -#include "pshpack4.h" - -#define IMAGE_DOS_SIGNATURE 0x5A4D -#define IMAGE_OS2_SIGNATURE 0x454E -#define IMAGE_OS2_SIGNATURE_LE 0x454C -#define IMAGE_VXD_SIGNATURE 0x454C -#define IMAGE_NT_SIGNATURE 0x00004550 - -#include "pshpack2.h" - - typedef struct _IMAGE_DOS_HEADER { - WORD e_magic; - WORD e_cblp; - WORD e_cp; - WORD e_crlc; - WORD e_cparhdr; - WORD e_minalloc; - WORD e_maxalloc; - WORD e_ss; - WORD e_sp; - WORD e_csum; - WORD e_ip; - WORD e_cs; - WORD e_lfarlc; - WORD e_ovno; - WORD e_res[4]; - WORD e_oemid; - WORD e_oeminfo; - WORD e_res2[10]; - LONG e_lfanew; - } IMAGE_DOS_HEADER,*PIMAGE_DOS_HEADER; - - typedef struct _IMAGE_OS2_HEADER { - WORD ne_magic; - CHAR ne_ver; - CHAR ne_rev; - WORD ne_enttab; - WORD ne_cbenttab; - LONG ne_crc; - WORD ne_flags; - WORD ne_autodata; - WORD ne_heap; - WORD ne_stack; - LONG ne_csip; - LONG ne_sssp; - WORD ne_cseg; - WORD ne_cmod; - WORD ne_cbnrestab; - WORD ne_segtab; - WORD ne_rsrctab; - WORD ne_restab; - WORD ne_modtab; - WORD ne_imptab; - LONG ne_nrestab; - WORD ne_cmovent; - WORD ne_align; - WORD ne_cres; - BYTE ne_exetyp; - BYTE ne_flagsothers; - WORD ne_pretthunks; - WORD ne_psegrefbytes; - WORD ne_swaparea; - WORD ne_expver; - } IMAGE_OS2_HEADER,*PIMAGE_OS2_HEADER; - - typedef struct _IMAGE_VXD_HEADER { - WORD e32_magic; - BYTE e32_border; - BYTE e32_worder; - DWORD e32_level; - WORD e32_cpu; - WORD e32_os; - DWORD e32_ver; - DWORD e32_mflags; - DWORD e32_mpages; - DWORD e32_startobj; - DWORD e32_eip; - DWORD e32_stackobj; - DWORD e32_esp; - DWORD e32_pagesize; - DWORD e32_lastpagesize; - DWORD e32_fixupsize; - DWORD e32_fixupsum; - DWORD e32_ldrsize; - DWORD e32_ldrsum; - DWORD e32_objtab; - DWORD e32_objcnt; - DWORD e32_objmap; - DWORD e32_itermap; - DWORD e32_rsrctab; - DWORD e32_rsrccnt; - DWORD e32_restab; - DWORD e32_enttab; - DWORD e32_dirtab; - DWORD e32_dircnt; - DWORD e32_fpagetab; - DWORD e32_frectab; - DWORD e32_impmod; - DWORD e32_impmodcnt; - DWORD e32_impproc; - DWORD e32_pagesum; - DWORD e32_datapage; - DWORD e32_preload; - DWORD e32_nrestab; - DWORD e32_cbnrestab; - DWORD e32_nressum; - DWORD e32_autodata; - DWORD e32_debuginfo; - DWORD e32_debuglen; - DWORD e32_instpreload; - DWORD e32_instdemand; - DWORD e32_heapsize; - BYTE e32_res3[12]; - DWORD e32_winresoff; - DWORD e32_winreslen; - WORD e32_devid; - WORD e32_ddkver; - } IMAGE_VXD_HEADER,*PIMAGE_VXD_HEADER; - -#include "poppack.h" - - typedef struct _IMAGE_FILE_HEADER { - WORD Machine; - WORD NumberOfSections; - DWORD TimeDateStamp; - DWORD PointerToSymbolTable; - DWORD NumberOfSymbols; - WORD SizeOfOptionalHeader; - WORD Characteristics; - } IMAGE_FILE_HEADER,*PIMAGE_FILE_HEADER; - -#define IMAGE_SIZEOF_FILE_HEADER 20 - -#define IMAGE_FILE_RELOCS_STRIPPED 0x0001 -#define IMAGE_FILE_EXECUTABLE_IMAGE 0x0002 -#define IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004 -#define IMAGE_FILE_LOCAL_SYMS_STRIPPED 0x0008 -#define IMAGE_FILE_AGGRESIVE_WS_TRIM 0x0010 -#define IMAGE_FILE_LARGE_ADDRESS_AWARE 0x0020 -#define IMAGE_FILE_BYTES_REVERSED_LO 0x0080 -#define IMAGE_FILE_32BIT_MACHINE 0x0100 -#define IMAGE_FILE_DEBUG_STRIPPED 0x0200 -#define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP 0x0400 -#define IMAGE_FILE_NET_RUN_FROM_SWAP 0x0800 -#define IMAGE_FILE_SYSTEM 0x1000 -#define IMAGE_FILE_DLL 0x2000 -#define IMAGE_FILE_UP_SYSTEM_ONLY 0x4000 -#define IMAGE_FILE_BYTES_REVERSED_HI 0x8000 - -#define IMAGE_FILE_MACHINE_UNKNOWN 0 -#define IMAGE_FILE_MACHINE_I386 0x014c -#define IMAGE_FILE_MACHINE_R3000 0x0162 -#define IMAGE_FILE_MACHINE_R4000 0x0166 -#define IMAGE_FILE_MACHINE_R10000 0x0168 -#define IMAGE_FILE_MACHINE_WCEMIPSV2 0x0169 -#define IMAGE_FILE_MACHINE_ALPHA 0x0184 -#define IMAGE_FILE_MACHINE_SH3 0x01a2 -#define IMAGE_FILE_MACHINE_SH3DSP 0x01a3 -#define IMAGE_FILE_MACHINE_SH3E 0x01a4 -#define IMAGE_FILE_MACHINE_SH4 0x01a6 -#define IMAGE_FILE_MACHINE_SH5 0x01a8 -#define IMAGE_FILE_MACHINE_ARM 0x01c0 -#define IMAGE_FILE_MACHINE_THUMB 0x01c2 -#define IMAGE_FILE_MACHINE_AM33 0x01d3 -#define IMAGE_FILE_MACHINE_POWERPC 0x01F0 -#define IMAGE_FILE_MACHINE_POWERPCFP 0x01f1 -#define IMAGE_FILE_MACHINE_IA64 0x0200 -#define IMAGE_FILE_MACHINE_MIPS16 0x0266 -#define IMAGE_FILE_MACHINE_ALPHA64 0x0284 -#define IMAGE_FILE_MACHINE_MIPSFPU 0x0366 -#define IMAGE_FILE_MACHINE_MIPSFPU16 0x0466 -#define IMAGE_FILE_MACHINE_AXP64 IMAGE_FILE_MACHINE_ALPHA64 -#define IMAGE_FILE_MACHINE_TRICORE 0x0520 -#define IMAGE_FILE_MACHINE_CEF 0x0CEF -#define IMAGE_FILE_MACHINE_EBC 0x0EBC -#define IMAGE_FILE_MACHINE_AMD64 0x8664 -#define IMAGE_FILE_MACHINE_M32R 0x9041 -#define IMAGE_FILE_MACHINE_CEE 0xC0EE - - typedef struct _IMAGE_DATA_DIRECTORY { - DWORD VirtualAddress; - DWORD Size; - } IMAGE_DATA_DIRECTORY,*PIMAGE_DATA_DIRECTORY; - -#define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16 - - typedef struct _IMAGE_OPTIONAL_HEADER { - - WORD Magic; - BYTE MajorLinkerVersion; - BYTE MinorLinkerVersion; - DWORD SizeOfCode; - DWORD SizeOfInitializedData; - DWORD SizeOfUninitializedData; - DWORD AddressOfEntryPoint; - DWORD BaseOfCode; - DWORD BaseOfData; - DWORD ImageBase; - DWORD SectionAlignment; - DWORD FileAlignment; - WORD MajorOperatingSystemVersion; - WORD MinorOperatingSystemVersion; - WORD MajorImageVersion; - WORD MinorImageVersion; - WORD MajorSubsystemVersion; - WORD MinorSubsystemVersion; - DWORD Win32VersionValue; - DWORD SizeOfImage; - DWORD SizeOfHeaders; - DWORD CheckSum; - WORD Subsystem; - WORD DllCharacteristics; - DWORD SizeOfStackReserve; - DWORD SizeOfStackCommit; - DWORD SizeOfHeapReserve; - DWORD SizeOfHeapCommit; - DWORD LoaderFlags; - DWORD NumberOfRvaAndSizes; - IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; - } IMAGE_OPTIONAL_HEADER32,*PIMAGE_OPTIONAL_HEADER32; - - typedef struct _IMAGE_ROM_OPTIONAL_HEADER { - WORD Magic; - BYTE MajorLinkerVersion; - BYTE MinorLinkerVersion; - DWORD SizeOfCode; - DWORD SizeOfInitializedData; - DWORD SizeOfUninitializedData; - DWORD AddressOfEntryPoint; - DWORD BaseOfCode; - DWORD BaseOfData; - DWORD BaseOfBss; - DWORD GprMask; - DWORD CprMask[4]; - DWORD GpValue; - } IMAGE_ROM_OPTIONAL_HEADER,*PIMAGE_ROM_OPTIONAL_HEADER; - - typedef struct _IMAGE_OPTIONAL_HEADER64 { - WORD Magic; - BYTE MajorLinkerVersion; - BYTE MinorLinkerVersion; - DWORD SizeOfCode; - DWORD SizeOfInitializedData; - DWORD SizeOfUninitializedData; - DWORD AddressOfEntryPoint; - DWORD BaseOfCode; - ULONGLONG ImageBase; - DWORD SectionAlignment; - DWORD FileAlignment; - WORD MajorOperatingSystemVersion; - WORD MinorOperatingSystemVersion; - WORD MajorImageVersion; - WORD MinorImageVersion; - WORD MajorSubsystemVersion; - WORD MinorSubsystemVersion; - DWORD Win32VersionValue; - DWORD SizeOfImage; - DWORD SizeOfHeaders; - DWORD CheckSum; - WORD Subsystem; - WORD DllCharacteristics; - ULONGLONG SizeOfStackReserve; - ULONGLONG SizeOfStackCommit; - ULONGLONG SizeOfHeapReserve; - ULONGLONG SizeOfHeapCommit; - DWORD LoaderFlags; - DWORD NumberOfRvaAndSizes; - IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; - } IMAGE_OPTIONAL_HEADER64,*PIMAGE_OPTIONAL_HEADER64; - -#define IMAGE_SIZEOF_ROM_OPTIONAL_HEADER 56 -#define IMAGE_SIZEOF_STD_OPTIONAL_HEADER 28 -#define IMAGE_SIZEOF_NT_OPTIONAL32_HEADER 224 -#define IMAGE_SIZEOF_NT_OPTIONAL64_HEADER 240 - -#define IMAGE_NT_OPTIONAL_HDR32_MAGIC 0x10b -#define IMAGE_NT_OPTIONAL_HDR64_MAGIC 0x20b -#define IMAGE_ROM_OPTIONAL_HDR_MAGIC 0x107 - -#ifdef _WIN64 - typedef IMAGE_OPTIONAL_HEADER64 IMAGE_OPTIONAL_HEADER; - typedef PIMAGE_OPTIONAL_HEADER64 PIMAGE_OPTIONAL_HEADER; -#define IMAGE_SIZEOF_NT_OPTIONAL_HEADER IMAGE_SIZEOF_NT_OPTIONAL64_HEADER -#define IMAGE_NT_OPTIONAL_HDR_MAGIC IMAGE_NT_OPTIONAL_HDR64_MAGIC -#else - typedef IMAGE_OPTIONAL_HEADER32 IMAGE_OPTIONAL_HEADER; - typedef PIMAGE_OPTIONAL_HEADER32 PIMAGE_OPTIONAL_HEADER; -#define IMAGE_SIZEOF_NT_OPTIONAL_HEADER IMAGE_SIZEOF_NT_OPTIONAL32_HEADER -#define IMAGE_NT_OPTIONAL_HDR_MAGIC IMAGE_NT_OPTIONAL_HDR32_MAGIC -#endif - - typedef struct _IMAGE_NT_HEADERS64 { - DWORD Signature; - IMAGE_FILE_HEADER FileHeader; - IMAGE_OPTIONAL_HEADER64 OptionalHeader; - } IMAGE_NT_HEADERS64,*PIMAGE_NT_HEADERS64; - - typedef struct _IMAGE_NT_HEADERS { - DWORD Signature; - IMAGE_FILE_HEADER FileHeader; - IMAGE_OPTIONAL_HEADER32 OptionalHeader; - } IMAGE_NT_HEADERS32,*PIMAGE_NT_HEADERS32; - - typedef struct _IMAGE_ROM_HEADERS { - IMAGE_FILE_HEADER FileHeader; - IMAGE_ROM_OPTIONAL_HEADER OptionalHeader; - } IMAGE_ROM_HEADERS,*PIMAGE_ROM_HEADERS; - -#ifdef _WIN64 - typedef IMAGE_NT_HEADERS64 IMAGE_NT_HEADERS; - typedef PIMAGE_NT_HEADERS64 PIMAGE_NT_HEADERS; -#else - typedef IMAGE_NT_HEADERS32 IMAGE_NT_HEADERS; - typedef PIMAGE_NT_HEADERS32 PIMAGE_NT_HEADERS; -#endif - -#define IMAGE_FIRST_SECTION(ntheader) ((PIMAGE_SECTION_HEADER) ((ULONG_PTR)ntheader + FIELD_OFFSET(IMAGE_NT_HEADERS,OptionalHeader) + ((PIMAGE_NT_HEADERS)(ntheader))->FileHeader.SizeOfOptionalHeader)) - -#define IMAGE_SUBSYSTEM_UNKNOWN 0 -#define IMAGE_SUBSYSTEM_NATIVE 1 -#define IMAGE_SUBSYSTEM_WINDOWS_GUI 2 -#define IMAGE_SUBSYSTEM_WINDOWS_CUI 3 -#define IMAGE_SUBSYSTEM_OS2_CUI 5 -#define IMAGE_SUBSYSTEM_POSIX_CUI 7 -#define IMAGE_SUBSYSTEM_NATIVE_WINDOWS 8 -#define IMAGE_SUBSYSTEM_WINDOWS_CE_GUI 9 -#define IMAGE_SUBSYSTEM_EFI_APPLICATION 10 -#define IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER 11 -#define IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER 12 -#define IMAGE_SUBSYSTEM_EFI_ROM 13 -#define IMAGE_SUBSYSTEM_XBOX 14 - -#define IMAGE_DLLCHARACTERISTICS_NO_ISOLATION 0x0200 -#define IMAGE_DLLCHARACTERISTICS_NO_SEH 0x0400 -#define IMAGE_DLLCHARACTERISTICS_NO_BIND 0x0800 -#define IMAGE_DLLCHARACTERISTICS_WDM_DRIVER 0x2000 -#define IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE 0x8000 - -#define IMAGE_DIRECTORY_ENTRY_EXPORT 0 -#define IMAGE_DIRECTORY_ENTRY_IMPORT 1 -#define IMAGE_DIRECTORY_ENTRY_RESOURCE 2 -#define IMAGE_DIRECTORY_ENTRY_EXCEPTION 3 -#define IMAGE_DIRECTORY_ENTRY_SECURITY 4 -#define IMAGE_DIRECTORY_ENTRY_BASERELOC 5 -#define IMAGE_DIRECTORY_ENTRY_DEBUG 6 - -#define IMAGE_DIRECTORY_ENTRY_ARCHITECTURE 7 -#define IMAGE_DIRECTORY_ENTRY_GLOBALPTR 8 -#define IMAGE_DIRECTORY_ENTRY_TLS 9 -#define IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG 10 -#define IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT 11 -#define IMAGE_DIRECTORY_ENTRY_IAT 12 -#define IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT 13 -#define IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR 14 - - typedef struct ANON_OBJECT_HEADER { - WORD Sig1; - WORD Sig2; - WORD Version; - WORD Machine; - DWORD TimeDateStamp; - CLSID ClassID; - DWORD SizeOfData; - } ANON_OBJECT_HEADER; - -#define IMAGE_SIZEOF_SHORT_NAME 8 - - typedef struct _IMAGE_SECTION_HEADER { - BYTE Name[IMAGE_SIZEOF_SHORT_NAME]; - union { - DWORD PhysicalAddress; - DWORD VirtualSize; - } Misc; - DWORD VirtualAddress; - DWORD SizeOfRawData; - DWORD PointerToRawData; - DWORD PointerToRelocations; - DWORD PointerToLinenumbers; - WORD NumberOfRelocations; - WORD NumberOfLinenumbers; - DWORD Characteristics; - } IMAGE_SECTION_HEADER,*PIMAGE_SECTION_HEADER; - -#define IMAGE_SIZEOF_SECTION_HEADER 40 - -#define IMAGE_SCN_TYPE_NO_PAD 0x00000008 - -#define IMAGE_SCN_CNT_CODE 0x00000020 -#define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040 -#define IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080 -#define IMAGE_SCN_LNK_OTHER 0x00000100 -#define IMAGE_SCN_LNK_INFO 0x00000200 -#define IMAGE_SCN_LNK_REMOVE 0x00000800 -#define IMAGE_SCN_LNK_COMDAT 0x00001000 -#define IMAGE_SCN_NO_DEFER_SPEC_EXC 0x00004000 -#define IMAGE_SCN_GPREL 0x00008000 -#define IMAGE_SCN_MEM_FARDATA 0x00008000 -#define IMAGE_SCN_MEM_PURGEABLE 0x00020000 -#define IMAGE_SCN_MEM_16BIT 0x00020000 -#define IMAGE_SCN_MEM_LOCKED 0x00040000 -#define IMAGE_SCN_MEM_PRELOAD 0x00080000 - -#define IMAGE_SCN_ALIGN_1BYTES 0x00100000 -#define IMAGE_SCN_ALIGN_2BYTES 0x00200000 -#define IMAGE_SCN_ALIGN_4BYTES 0x00300000 -#define IMAGE_SCN_ALIGN_8BYTES 0x00400000 -#define IMAGE_SCN_ALIGN_16BYTES 0x00500000 -#define IMAGE_SCN_ALIGN_32BYTES 0x00600000 -#define IMAGE_SCN_ALIGN_64BYTES 0x00700000 -#define IMAGE_SCN_ALIGN_128BYTES 0x00800000 -#define IMAGE_SCN_ALIGN_256BYTES 0x00900000 -#define IMAGE_SCN_ALIGN_512BYTES 0x00A00000 -#define IMAGE_SCN_ALIGN_1024BYTES 0x00B00000 -#define IMAGE_SCN_ALIGN_2048BYTES 0x00C00000 -#define IMAGE_SCN_ALIGN_4096BYTES 0x00D00000 -#define IMAGE_SCN_ALIGN_8192BYTES 0x00E00000 - -#define IMAGE_SCN_ALIGN_MASK 0x00F00000 - -#define IMAGE_SCN_LNK_NRELOC_OVFL 0x01000000 -#define IMAGE_SCN_MEM_DISCARDABLE 0x02000000 -#define IMAGE_SCN_MEM_NOT_CACHED 0x04000000 -#define IMAGE_SCN_MEM_NOT_PAGED 0x08000000 -#define IMAGE_SCN_MEM_SHARED 0x10000000 -#define IMAGE_SCN_MEM_EXECUTE 0x20000000 -#define IMAGE_SCN_MEM_READ 0x40000000 -#define IMAGE_SCN_MEM_WRITE 0x80000000 - -#define IMAGE_SCN_SCALE_INDEX 0x00000001 - -#include "pshpack2.h" - - typedef struct _IMAGE_SYMBOL { - union { - BYTE ShortName[8]; - struct { - DWORD Short; - DWORD Long; - } Name; - DWORD LongName[2]; - } N; - DWORD Value; - SHORT SectionNumber; - WORD Type; - BYTE StorageClass; - BYTE NumberOfAuxSymbols; - } IMAGE_SYMBOL; - typedef IMAGE_SYMBOL UNALIGNED *PIMAGE_SYMBOL; - -#define IMAGE_SIZEOF_SYMBOL 18 - -#define IMAGE_SYM_UNDEFINED (SHORT)0 -#define IMAGE_SYM_ABSOLUTE (SHORT)-1 -#define IMAGE_SYM_DEBUG (SHORT)-2 -#define IMAGE_SYM_SECTION_MAX 0xFEFF - -#define IMAGE_SYM_TYPE_NULL 0x0000 -#define IMAGE_SYM_TYPE_VOID 0x0001 -#define IMAGE_SYM_TYPE_CHAR 0x0002 -#define IMAGE_SYM_TYPE_SHORT 0x0003 -#define IMAGE_SYM_TYPE_INT 0x0004 -#define IMAGE_SYM_TYPE_LONG 0x0005 -#define IMAGE_SYM_TYPE_FLOAT 0x0006 -#define IMAGE_SYM_TYPE_DOUBLE 0x0007 -#define IMAGE_SYM_TYPE_STRUCT 0x0008 -#define IMAGE_SYM_TYPE_UNION 0x0009 -#define IMAGE_SYM_TYPE_ENUM 0x000A -#define IMAGE_SYM_TYPE_MOE 0x000B -#define IMAGE_SYM_TYPE_BYTE 0x000C -#define IMAGE_SYM_TYPE_WORD 0x000D -#define IMAGE_SYM_TYPE_UINT 0x000E -#define IMAGE_SYM_TYPE_DWORD 0x000F -#define IMAGE_SYM_TYPE_PCODE 0x8000 - -#define IMAGE_SYM_DTYPE_NULL 0 -#define IMAGE_SYM_DTYPE_POINTER 1 -#define IMAGE_SYM_DTYPE_FUNCTION 2 -#define IMAGE_SYM_DTYPE_ARRAY 3 - -#define IMAGE_SYM_CLASS_END_OF_FUNCTION (BYTE)-1 -#define IMAGE_SYM_CLASS_NULL 0x0000 -#define IMAGE_SYM_CLASS_AUTOMATIC 0x0001 -#define IMAGE_SYM_CLASS_EXTERNAL 0x0002 -#define IMAGE_SYM_CLASS_STATIC 0x0003 -#define IMAGE_SYM_CLASS_REGISTER 0x0004 -#define IMAGE_SYM_CLASS_EXTERNAL_DEF 0x0005 -#define IMAGE_SYM_CLASS_LABEL 0x0006 -#define IMAGE_SYM_CLASS_UNDEFINED_LABEL 0x0007 -#define IMAGE_SYM_CLASS_MEMBER_OF_STRUCT 0x0008 -#define IMAGE_SYM_CLASS_ARGUMENT 0x0009 -#define IMAGE_SYM_CLASS_STRUCT_TAG 0x000A -#define IMAGE_SYM_CLASS_MEMBER_OF_UNION 0x000B -#define IMAGE_SYM_CLASS_UNION_TAG 0x000C -#define IMAGE_SYM_CLASS_TYPE_DEFINITION 0x000D -#define IMAGE_SYM_CLASS_UNDEFINED_STATIC 0x000E -#define IMAGE_SYM_CLASS_ENUM_TAG 0x000F -#define IMAGE_SYM_CLASS_MEMBER_OF_ENUM 0x0010 -#define IMAGE_SYM_CLASS_REGISTER_PARAM 0x0011 -#define IMAGE_SYM_CLASS_BIT_FIELD 0x0012 -#define IMAGE_SYM_CLASS_FAR_EXTERNAL 0x0044 -#define IMAGE_SYM_CLASS_BLOCK 0x0064 -#define IMAGE_SYM_CLASS_FUNCTION 0x0065 -#define IMAGE_SYM_CLASS_END_OF_STRUCT 0x0066 -#define IMAGE_SYM_CLASS_FILE 0x0067 -#define IMAGE_SYM_CLASS_SECTION 0x0068 -#define IMAGE_SYM_CLASS_WEAK_EXTERNAL 0x0069 -#define IMAGE_SYM_CLASS_CLR_TOKEN 0x006B - -#define N_BTMASK 0x000F -#define N_TMASK 0x0030 -#define N_TMASK1 0x00C0 -#define N_TMASK2 0x00F0 -#define N_BTSHFT 4 -#define N_TSHIFT 2 - -#define BTYPE(x) ((x) & N_BTMASK) - -#ifndef ISPTR -#define ISPTR(x) (((x) & N_TMASK)==(IMAGE_SYM_DTYPE_POINTER << N_BTSHFT)) -#endif - -#ifndef ISFCN -#define ISFCN(x) (((x) & N_TMASK)==(IMAGE_SYM_DTYPE_FUNCTION << N_BTSHFT)) -#endif - -#ifndef ISARY -#define ISARY(x) (((x) & N_TMASK)==(IMAGE_SYM_DTYPE_ARRAY << N_BTSHFT)) -#endif - -#ifndef ISTAG -#define ISTAG(x) ((x)==IMAGE_SYM_CLASS_STRUCT_TAG || (x)==IMAGE_SYM_CLASS_UNION_TAG || (x)==IMAGE_SYM_CLASS_ENUM_TAG) -#endif - -#ifndef INCREF -#define INCREF(x) ((((x)&~N_BTMASK)<>N_TSHIFT)&~N_BTMASK)|((x)&N_BTMASK)) -#endif - - typedef union _IMAGE_AUX_SYMBOL { - struct { - DWORD TagIndex; - union { - struct { - WORD Linenumber; - WORD Size; - } LnSz; - DWORD TotalSize; - } Misc; - union { - struct { - DWORD PointerToLinenumber; - DWORD PointerToNextFunction; - } Function; - struct { - WORD Dimension[4]; - } Array; - } FcnAry; - WORD TvIndex; - } Sym; - struct { - BYTE Name[IMAGE_SIZEOF_SYMBOL]; - } File; - struct { - DWORD Length; - WORD NumberOfRelocations; - WORD NumberOfLinenumbers; - DWORD CheckSum; - SHORT Number; - BYTE Selection; - } Section; - } IMAGE_AUX_SYMBOL; - typedef IMAGE_AUX_SYMBOL UNALIGNED *PIMAGE_AUX_SYMBOL; - -#define IMAGE_SIZEOF_AUX_SYMBOL 18 - - typedef enum IMAGE_AUX_SYMBOL_TYPE { - IMAGE_AUX_SYMBOL_TYPE_TOKEN_DEF = 1 - } IMAGE_AUX_SYMBOL_TYPE; - -#include - - typedef struct IMAGE_AUX_SYMBOL_TOKEN_DEF { - BYTE bAuxType; - BYTE bReserved; - DWORD SymbolTableIndex; - BYTE rgbReserved[12]; - } IMAGE_AUX_SYMBOL_TOKEN_DEF; - - typedef IMAGE_AUX_SYMBOL_TOKEN_DEF UNALIGNED *PIMAGE_AUX_SYMBOL_TOKEN_DEF; - -#include - -#define IMAGE_COMDAT_SELECT_NODUPLICATES 1 -#define IMAGE_COMDAT_SELECT_ANY 2 -#define IMAGE_COMDAT_SELECT_SAME_SIZE 3 -#define IMAGE_COMDAT_SELECT_EXACT_MATCH 4 -#define IMAGE_COMDAT_SELECT_ASSOCIATIVE 5 -#define IMAGE_COMDAT_SELECT_LARGEST 6 -#define IMAGE_COMDAT_SELECT_NEWEST 7 - -#define IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY 1 -#define IMAGE_WEAK_EXTERN_SEARCH_LIBRARY 2 -#define IMAGE_WEAK_EXTERN_SEARCH_ALIAS 3 - - typedef struct _IMAGE_RELOCATION { - union { - DWORD VirtualAddress; - DWORD RelocCount; - }; - DWORD SymbolTableIndex; - WORD Type; - } IMAGE_RELOCATION; - typedef IMAGE_RELOCATION UNALIGNED *PIMAGE_RELOCATION; - -#define IMAGE_SIZEOF_RELOCATION 10 - -#define IMAGE_REL_I386_ABSOLUTE 0x0000 -#define IMAGE_REL_I386_DIR16 0x0001 -#define IMAGE_REL_I386_REL16 0x0002 -#define IMAGE_REL_I386_DIR32 0x0006 -#define IMAGE_REL_I386_DIR32NB 0x0007 -#define IMAGE_REL_I386_SEG12 0x0009 -#define IMAGE_REL_I386_SECTION 0x000A -#define IMAGE_REL_I386_SECREL 0x000B -#define IMAGE_REL_I386_TOKEN 0x000C -#define IMAGE_REL_I386_SECREL7 0x000D -#define IMAGE_REL_I386_REL32 0x0014 - -#define IMAGE_REL_MIPS_ABSOLUTE 0x0000 -#define IMAGE_REL_MIPS_REFHALF 0x0001 -#define IMAGE_REL_MIPS_REFWORD 0x0002 -#define IMAGE_REL_MIPS_JMPADDR 0x0003 -#define IMAGE_REL_MIPS_REFHI 0x0004 -#define IMAGE_REL_MIPS_REFLO 0x0005 -#define IMAGE_REL_MIPS_GPREL 0x0006 -#define IMAGE_REL_MIPS_LITERAL 0x0007 -#define IMAGE_REL_MIPS_SECTION 0x000A -#define IMAGE_REL_MIPS_SECREL 0x000B -#define IMAGE_REL_MIPS_SECRELLO 0x000C -#define IMAGE_REL_MIPS_SECRELHI 0x000D -#define IMAGE_REL_MIPS_TOKEN 0x000E -#define IMAGE_REL_MIPS_JMPADDR16 0x0010 -#define IMAGE_REL_MIPS_REFWORDNB 0x0022 -#define IMAGE_REL_MIPS_PAIR 0x0025 - -#define IMAGE_REL_ALPHA_ABSOLUTE 0x0000 -#define IMAGE_REL_ALPHA_REFLONG 0x0001 -#define IMAGE_REL_ALPHA_REFQUAD 0x0002 -#define IMAGE_REL_ALPHA_GPREL32 0x0003 -#define IMAGE_REL_ALPHA_LITERAL 0x0004 -#define IMAGE_REL_ALPHA_LITUSE 0x0005 -#define IMAGE_REL_ALPHA_GPDISP 0x0006 -#define IMAGE_REL_ALPHA_BRADDR 0x0007 -#define IMAGE_REL_ALPHA_HINT 0x0008 -#define IMAGE_REL_ALPHA_INLINE_REFLONG 0x0009 -#define IMAGE_REL_ALPHA_REFHI 0x000A -#define IMAGE_REL_ALPHA_REFLO 0x000B -#define IMAGE_REL_ALPHA_PAIR 0x000C -#define IMAGE_REL_ALPHA_MATCH 0x000D -#define IMAGE_REL_ALPHA_SECTION 0x000E -#define IMAGE_REL_ALPHA_SECREL 0x000F -#define IMAGE_REL_ALPHA_REFLONGNB 0x0010 -#define IMAGE_REL_ALPHA_SECRELLO 0x0011 -#define IMAGE_REL_ALPHA_SECRELHI 0x0012 -#define IMAGE_REL_ALPHA_REFQ3 0x0013 -#define IMAGE_REL_ALPHA_REFQ2 0x0014 -#define IMAGE_REL_ALPHA_REFQ1 0x0015 -#define IMAGE_REL_ALPHA_GPRELLO 0x0016 -#define IMAGE_REL_ALPHA_GPRELHI 0x0017 - -#define IMAGE_REL_PPC_ABSOLUTE 0x0000 -#define IMAGE_REL_PPC_ADDR64 0x0001 -#define IMAGE_REL_PPC_ADDR32 0x0002 -#define IMAGE_REL_PPC_ADDR24 0x0003 -#define IMAGE_REL_PPC_ADDR16 0x0004 -#define IMAGE_REL_PPC_ADDR14 0x0005 -#define IMAGE_REL_PPC_REL24 0x0006 -#define IMAGE_REL_PPC_REL14 0x0007 -#define IMAGE_REL_PPC_TOCREL16 0x0008 -#define IMAGE_REL_PPC_TOCREL14 0x0009 -#define IMAGE_REL_PPC_ADDR32NB 0x000A -#define IMAGE_REL_PPC_SECREL 0x000B -#define IMAGE_REL_PPC_SECTION 0x000C -#define IMAGE_REL_PPC_IFGLUE 0x000D -#define IMAGE_REL_PPC_IMGLUE 0x000E -#define IMAGE_REL_PPC_SECREL16 0x000F -#define IMAGE_REL_PPC_REFHI 0x0010 -#define IMAGE_REL_PPC_REFLO 0x0011 -#define IMAGE_REL_PPC_PAIR 0x0012 -#define IMAGE_REL_PPC_SECRELLO 0x0013 -#define IMAGE_REL_PPC_SECRELHI 0x0014 -#define IMAGE_REL_PPC_GPREL 0x0015 -#define IMAGE_REL_PPC_TOKEN 0x0016 -#define IMAGE_REL_PPC_TYPEMASK 0x00FF -#define IMAGE_REL_PPC_NEG 0x0100 -#define IMAGE_REL_PPC_BRTAKEN 0x0200 -#define IMAGE_REL_PPC_BRNTAKEN 0x0400 -#define IMAGE_REL_PPC_TOCDEFN 0x0800 - -#define IMAGE_REL_SH3_ABSOLUTE 0x0000 -#define IMAGE_REL_SH3_DIRECT16 0x0001 -#define IMAGE_REL_SH3_DIRECT32 0x0002 -#define IMAGE_REL_SH3_DIRECT8 0x0003 -#define IMAGE_REL_SH3_DIRECT8_WORD 0x0004 -#define IMAGE_REL_SH3_DIRECT8_LONG 0x0005 -#define IMAGE_REL_SH3_DIRECT4 0x0006 -#define IMAGE_REL_SH3_DIRECT4_WORD 0x0007 -#define IMAGE_REL_SH3_DIRECT4_LONG 0x0008 -#define IMAGE_REL_SH3_PCREL8_WORD 0x0009 -#define IMAGE_REL_SH3_PCREL8_LONG 0x000A -#define IMAGE_REL_SH3_PCREL12_WORD 0x000B -#define IMAGE_REL_SH3_STARTOF_SECTION 0x000C -#define IMAGE_REL_SH3_SIZEOF_SECTION 0x000D -#define IMAGE_REL_SH3_SECTION 0x000E -#define IMAGE_REL_SH3_SECREL 0x000F -#define IMAGE_REL_SH3_DIRECT32_NB 0x0010 -#define IMAGE_REL_SH3_GPREL4_LONG 0x0011 -#define IMAGE_REL_SH3_TOKEN 0x0012 - -#define IMAGE_REL_SHM_PCRELPT 0x0013 -#define IMAGE_REL_SHM_REFLO 0x0014 -#define IMAGE_REL_SHM_REFHALF 0x0015 -#define IMAGE_REL_SHM_RELLO 0x0016 -#define IMAGE_REL_SHM_RELHALF 0x0017 -#define IMAGE_REL_SHM_PAIR 0x0018 - -#define IMAGE_REL_SH_NOMODE 0x8000 - -#define IMAGE_REL_ARM_ABSOLUTE 0x0000 -#define IMAGE_REL_ARM_ADDR32 0x0001 -#define IMAGE_REL_ARM_ADDR32NB 0x0002 -#define IMAGE_REL_ARM_BRANCH24 0x0003 -#define IMAGE_REL_ARM_BRANCH11 0x0004 -#define IMAGE_REL_ARM_TOKEN 0x0005 -#define IMAGE_REL_ARM_GPREL12 0x0006 -#define IMAGE_REL_ARM_GPREL7 0x0007 -#define IMAGE_REL_ARM_BLX24 0x0008 -#define IMAGE_REL_ARM_BLX11 0x0009 -#define IMAGE_REL_ARM_SECTION 0x000E -#define IMAGE_REL_ARM_SECREL 0x000F - -#define IMAGE_REL_AM_ABSOLUTE 0x0000 -#define IMAGE_REL_AM_ADDR32 0x0001 -#define IMAGE_REL_AM_ADDR32NB 0x0002 -#define IMAGE_REL_AM_CALL32 0x0003 -#define IMAGE_REL_AM_FUNCINFO 0x0004 -#define IMAGE_REL_AM_REL32_1 0x0005 -#define IMAGE_REL_AM_REL32_2 0x0006 -#define IMAGE_REL_AM_SECREL 0x0007 -#define IMAGE_REL_AM_SECTION 0x0008 -#define IMAGE_REL_AM_TOKEN 0x0009 - -#define IMAGE_REL_AMD64_ABSOLUTE 0x0000 -#define IMAGE_REL_AMD64_ADDR64 0x0001 -#define IMAGE_REL_AMD64_ADDR32 0x0002 -#define IMAGE_REL_AMD64_ADDR32NB 0x0003 -#define IMAGE_REL_AMD64_REL32 0x0004 -#define IMAGE_REL_AMD64_REL32_1 0x0005 -#define IMAGE_REL_AMD64_REL32_2 0x0006 -#define IMAGE_REL_AMD64_REL32_3 0x0007 -#define IMAGE_REL_AMD64_REL32_4 0x0008 -#define IMAGE_REL_AMD64_REL32_5 0x0009 -#define IMAGE_REL_AMD64_SECTION 0x000A -#define IMAGE_REL_AMD64_SECREL 0x000B -#define IMAGE_REL_AMD64_SECREL7 0x000C -#define IMAGE_REL_AMD64_TOKEN 0x000D -#define IMAGE_REL_AMD64_SREL32 0x000E -#define IMAGE_REL_AMD64_PAIR 0x000F -#define IMAGE_REL_AMD64_SSPAN32 0x0010 - -#define IMAGE_REL_IA64_ABSOLUTE 0x0000 -#define IMAGE_REL_IA64_IMM14 0x0001 -#define IMAGE_REL_IA64_IMM22 0x0002 -#define IMAGE_REL_IA64_IMM64 0x0003 -#define IMAGE_REL_IA64_DIR32 0x0004 -#define IMAGE_REL_IA64_DIR64 0x0005 -#define IMAGE_REL_IA64_PCREL21B 0x0006 -#define IMAGE_REL_IA64_PCREL21M 0x0007 -#define IMAGE_REL_IA64_PCREL21F 0x0008 -#define IMAGE_REL_IA64_GPREL22 0x0009 -#define IMAGE_REL_IA64_LTOFF22 0x000A -#define IMAGE_REL_IA64_SECTION 0x000B -#define IMAGE_REL_IA64_SECREL22 0x000C -#define IMAGE_REL_IA64_SECREL64I 0x000D -#define IMAGE_REL_IA64_SECREL32 0x000E - -#define IMAGE_REL_IA64_DIR32NB 0x0010 -#define IMAGE_REL_IA64_SREL14 0x0011 -#define IMAGE_REL_IA64_SREL22 0x0012 -#define IMAGE_REL_IA64_SREL32 0x0013 -#define IMAGE_REL_IA64_UREL32 0x0014 -#define IMAGE_REL_IA64_PCREL60X 0x0015 -#define IMAGE_REL_IA64_PCREL60B 0x0016 -#define IMAGE_REL_IA64_PCREL60F 0x0017 -#define IMAGE_REL_IA64_PCREL60I 0x0018 -#define IMAGE_REL_IA64_PCREL60M 0x0019 -#define IMAGE_REL_IA64_IMMGPREL64 0x001A -#define IMAGE_REL_IA64_TOKEN 0x001B -#define IMAGE_REL_IA64_GPREL32 0x001C -#define IMAGE_REL_IA64_ADDEND 0x001F - -#define IMAGE_REL_CEF_ABSOLUTE 0x0000 -#define IMAGE_REL_CEF_ADDR32 0x0001 -#define IMAGE_REL_CEF_ADDR64 0x0002 -#define IMAGE_REL_CEF_ADDR32NB 0x0003 -#define IMAGE_REL_CEF_SECTION 0x0004 -#define IMAGE_REL_CEF_SECREL 0x0005 -#define IMAGE_REL_CEF_TOKEN 0x0006 - -#define IMAGE_REL_CEE_ABSOLUTE 0x0000 -#define IMAGE_REL_CEE_ADDR32 0x0001 -#define IMAGE_REL_CEE_ADDR64 0x0002 -#define IMAGE_REL_CEE_ADDR32NB 0x0003 -#define IMAGE_REL_CEE_SECTION 0x0004 -#define IMAGE_REL_CEE_SECREL 0x0005 -#define IMAGE_REL_CEE_TOKEN 0x0006 - -#define IMAGE_REL_M32R_ABSOLUTE 0x0000 -#define IMAGE_REL_M32R_ADDR32 0x0001 -#define IMAGE_REL_M32R_ADDR32NB 0x0002 -#define IMAGE_REL_M32R_ADDR24 0x0003 -#define IMAGE_REL_M32R_GPREL16 0x0004 -#define IMAGE_REL_M32R_PCREL24 0x0005 -#define IMAGE_REL_M32R_PCREL16 0x0006 -#define IMAGE_REL_M32R_PCREL8 0x0007 -#define IMAGE_REL_M32R_REFHALF 0x0008 -#define IMAGE_REL_M32R_REFHI 0x0009 -#define IMAGE_REL_M32R_REFLO 0x000A -#define IMAGE_REL_M32R_PAIR 0x000B -#define IMAGE_REL_M32R_SECTION 0x000C -#define IMAGE_REL_M32R_SECREL32 0x000D -#define IMAGE_REL_M32R_TOKEN 0x000E - -#define EXT_IMM64(Value,Address,Size,InstPos,ValPos) Value |= (((ULONGLONG)((*(Address) >> InstPos) & (((ULONGLONG)1 << Size) - 1))) << ValPos) -#define INS_IMM64(Value,Address,Size,InstPos,ValPos) *(PDWORD)Address = (*(PDWORD)Address & ~(((1 << Size) - 1) << InstPos)) | ((DWORD)((((ULONGLONG)Value >> ValPos) & (((ULONGLONG)1 << Size) - 1))) << InstPos) - -#define EMARCH_ENC_I17_IMM7B_INST_WORD_X 3 -#define EMARCH_ENC_I17_IMM7B_SIZE_X 7 -#define EMARCH_ENC_I17_IMM7B_INST_WORD_POS_X 4 -#define EMARCH_ENC_I17_IMM7B_VAL_POS_X 0 - -#define EMARCH_ENC_I17_IMM9D_INST_WORD_X 3 -#define EMARCH_ENC_I17_IMM9D_SIZE_X 9 -#define EMARCH_ENC_I17_IMM9D_INST_WORD_POS_X 18 -#define EMARCH_ENC_I17_IMM9D_VAL_POS_X 7 - -#define EMARCH_ENC_I17_IMM5C_INST_WORD_X 3 -#define EMARCH_ENC_I17_IMM5C_SIZE_X 5 -#define EMARCH_ENC_I17_IMM5C_INST_WORD_POS_X 13 -#define EMARCH_ENC_I17_IMM5C_VAL_POS_X 16 - -#define EMARCH_ENC_I17_IC_INST_WORD_X 3 -#define EMARCH_ENC_I17_IC_SIZE_X 1 -#define EMARCH_ENC_I17_IC_INST_WORD_POS_X 12 -#define EMARCH_ENC_I17_IC_VAL_POS_X 21 - -#define EMARCH_ENC_I17_IMM41a_INST_WORD_X 1 -#define EMARCH_ENC_I17_IMM41a_SIZE_X 10 -#define EMARCH_ENC_I17_IMM41a_INST_WORD_POS_X 14 -#define EMARCH_ENC_I17_IMM41a_VAL_POS_X 22 - -#define EMARCH_ENC_I17_IMM41b_INST_WORD_X 1 -#define EMARCH_ENC_I17_IMM41b_SIZE_X 8 -#define EMARCH_ENC_I17_IMM41b_INST_WORD_POS_X 24 -#define EMARCH_ENC_I17_IMM41b_VAL_POS_X 32 - -#define EMARCH_ENC_I17_IMM41c_INST_WORD_X 2 -#define EMARCH_ENC_I17_IMM41c_SIZE_X 23 -#define EMARCH_ENC_I17_IMM41c_INST_WORD_POS_X 0 -#define EMARCH_ENC_I17_IMM41c_VAL_POS_X 40 - -#define EMARCH_ENC_I17_SIGN_INST_WORD_X 3 -#define EMARCH_ENC_I17_SIGN_SIZE_X 1 -#define EMARCH_ENC_I17_SIGN_INST_WORD_POS_X 27 -#define EMARCH_ENC_I17_SIGN_VAL_POS_X 63 - -#define X3_OPCODE_INST_WORD_X 3 -#define X3_OPCODE_SIZE_X 4 -#define X3_OPCODE_INST_WORD_POS_X 28 -#define X3_OPCODE_SIGN_VAL_POS_X 0 - -#define X3_I_INST_WORD_X 3 -#define X3_I_SIZE_X 1 -#define X3_I_INST_WORD_POS_X 27 -#define X3_I_SIGN_VAL_POS_X 59 - -#define X3_D_WH_INST_WORD_X 3 -#define X3_D_WH_SIZE_X 3 -#define X3_D_WH_INST_WORD_POS_X 24 -#define X3_D_WH_SIGN_VAL_POS_X 0 - -#define X3_IMM20_INST_WORD_X 3 -#define X3_IMM20_SIZE_X 20 -#define X3_IMM20_INST_WORD_POS_X 4 -#define X3_IMM20_SIGN_VAL_POS_X 0 - -#define X3_IMM39_1_INST_WORD_X 2 -#define X3_IMM39_1_SIZE_X 23 -#define X3_IMM39_1_INST_WORD_POS_X 0 -#define X3_IMM39_1_SIGN_VAL_POS_X 36 - -#define X3_IMM39_2_INST_WORD_X 1 -#define X3_IMM39_2_SIZE_X 16 -#define X3_IMM39_2_INST_WORD_POS_X 16 -#define X3_IMM39_2_SIGN_VAL_POS_X 20 - -#define X3_P_INST_WORD_X 3 -#define X3_P_SIZE_X 4 -#define X3_P_INST_WORD_POS_X 0 -#define X3_P_SIGN_VAL_POS_X 0 - -#define X3_TMPLT_INST_WORD_X 0 -#define X3_TMPLT_SIZE_X 4 -#define X3_TMPLT_INST_WORD_POS_X 0 -#define X3_TMPLT_SIGN_VAL_POS_X 0 - -#define X3_BTYPE_QP_INST_WORD_X 2 -#define X3_BTYPE_QP_SIZE_X 9 -#define X3_BTYPE_QP_INST_WORD_POS_X 23 -#define X3_BTYPE_QP_INST_VAL_POS_X 0 - -#define X3_EMPTY_INST_WORD_X 1 -#define X3_EMPTY_SIZE_X 2 -#define X3_EMPTY_INST_WORD_POS_X 14 -#define X3_EMPTY_INST_VAL_POS_X 0 - - typedef struct _IMAGE_LINENUMBER { - union { - DWORD SymbolTableIndex; - DWORD VirtualAddress; - } Type; - WORD Linenumber; - } IMAGE_LINENUMBER; - typedef IMAGE_LINENUMBER UNALIGNED *PIMAGE_LINENUMBER; - -#define IMAGE_SIZEOF_LINENUMBER 6 - -#include "poppack.h" - - typedef struct _IMAGE_BASE_RELOCATION { - DWORD VirtualAddress; - DWORD SizeOfBlock; - - } IMAGE_BASE_RELOCATION; - typedef IMAGE_BASE_RELOCATION UNALIGNED *PIMAGE_BASE_RELOCATION; - -#define IMAGE_SIZEOF_BASE_RELOCATION 8 - -#define IMAGE_REL_BASED_ABSOLUTE 0 -#define IMAGE_REL_BASED_HIGH 1 -#define IMAGE_REL_BASED_LOW 2 -#define IMAGE_REL_BASED_HIGHLOW 3 -#define IMAGE_REL_BASED_HIGHADJ 4 -#define IMAGE_REL_BASED_MIPS_JMPADDR 5 -#define IMAGE_REL_BASED_MIPS_JMPADDR16 9 -#define IMAGE_REL_BASED_IA64_IMM64 9 -#define IMAGE_REL_BASED_DIR64 10 - -#define IMAGE_ARCHIVE_START_SIZE 8 -#define IMAGE_ARCHIVE_START "!\n" -#define IMAGE_ARCHIVE_END "`\n" -#define IMAGE_ARCHIVE_PAD "\n" -#define IMAGE_ARCHIVE_LINKER_MEMBER "/ " -#define IMAGE_ARCHIVE_LONGNAMES_MEMBER "// " - - typedef struct _IMAGE_ARCHIVE_MEMBER_HEADER { - BYTE Name[16]; - BYTE Date[12]; - BYTE UserID[6]; - BYTE GroupID[6]; - BYTE Mode[8]; - BYTE Size[10]; - BYTE EndHeader[2]; - } IMAGE_ARCHIVE_MEMBER_HEADER,*PIMAGE_ARCHIVE_MEMBER_HEADER; - -#define IMAGE_SIZEOF_ARCHIVE_MEMBER_HDR 60 - - typedef struct _IMAGE_EXPORT_DIRECTORY { - DWORD Characteristics; - DWORD TimeDateStamp; - WORD MajorVersion; - WORD MinorVersion; - DWORD Name; - DWORD Base; - DWORD NumberOfFunctions; - DWORD NumberOfNames; - DWORD AddressOfFunctions; - DWORD AddressOfNames; - DWORD AddressOfNameOrdinals; - } IMAGE_EXPORT_DIRECTORY,*PIMAGE_EXPORT_DIRECTORY; - - typedef struct _IMAGE_IMPORT_BY_NAME { - WORD Hint; - BYTE Name[1]; - } IMAGE_IMPORT_BY_NAME,*PIMAGE_IMPORT_BY_NAME; - -#include "pshpack8.h" - - typedef struct _IMAGE_THUNK_DATA64 { - union { - ULONGLONG ForwarderString; - ULONGLONG Function; - ULONGLONG Ordinal; - ULONGLONG AddressOfData; - } u1; - } IMAGE_THUNK_DATA64; - typedef IMAGE_THUNK_DATA64 *PIMAGE_THUNK_DATA64; - -#include "poppack.h" - - typedef struct _IMAGE_THUNK_DATA32 { - union { - DWORD ForwarderString; - DWORD Function; - DWORD Ordinal; - DWORD AddressOfData; - } u1; - } IMAGE_THUNK_DATA32; - typedef IMAGE_THUNK_DATA32 *PIMAGE_THUNK_DATA32; - -#define IMAGE_ORDINAL_FLAG64 0x8000000000000000ull -#define IMAGE_ORDINAL_FLAG32 0x80000000 -#define IMAGE_ORDINAL64(Ordinal) (Ordinal & 0xffffull) -#define IMAGE_ORDINAL32(Ordinal) (Ordinal & 0xffff) -#define IMAGE_SNAP_BY_ORDINAL64(Ordinal) ((Ordinal & IMAGE_ORDINAL_FLAG64)!=0) -#define IMAGE_SNAP_BY_ORDINAL32(Ordinal) ((Ordinal & IMAGE_ORDINAL_FLAG32)!=0) - - typedef VOID - (NTAPI *PIMAGE_TLS_CALLBACK)(PVOID DllHandle,DWORD Reason,PVOID Reserved); - - typedef struct _IMAGE_TLS_DIRECTORY64 { - ULONGLONG StartAddressOfRawData; - ULONGLONG EndAddressOfRawData; - ULONGLONG AddressOfIndex; - ULONGLONG AddressOfCallBacks; - DWORD SizeOfZeroFill; - DWORD Characteristics; - } IMAGE_TLS_DIRECTORY64; - typedef IMAGE_TLS_DIRECTORY64 *PIMAGE_TLS_DIRECTORY64; - - typedef struct _IMAGE_TLS_DIRECTORY32 { - DWORD StartAddressOfRawData; - DWORD EndAddressOfRawData; - DWORD AddressOfIndex; - DWORD AddressOfCallBacks; - DWORD SizeOfZeroFill; - DWORD Characteristics; - } IMAGE_TLS_DIRECTORY32; - typedef IMAGE_TLS_DIRECTORY32 *PIMAGE_TLS_DIRECTORY32; - -#ifdef _WIN64 -#define IMAGE_ORDINAL_FLAG IMAGE_ORDINAL_FLAG64 -#define IMAGE_ORDINAL(Ordinal) IMAGE_ORDINAL64(Ordinal) - typedef IMAGE_THUNK_DATA64 IMAGE_THUNK_DATA; - typedef PIMAGE_THUNK_DATA64 PIMAGE_THUNK_DATA; -#define IMAGE_SNAP_BY_ORDINAL(Ordinal) IMAGE_SNAP_BY_ORDINAL64(Ordinal) - typedef IMAGE_TLS_DIRECTORY64 IMAGE_TLS_DIRECTORY; - typedef PIMAGE_TLS_DIRECTORY64 PIMAGE_TLS_DIRECTORY; -#else -#define IMAGE_ORDINAL_FLAG IMAGE_ORDINAL_FLAG32 -#define IMAGE_ORDINAL(Ordinal) IMAGE_ORDINAL32(Ordinal) - typedef IMAGE_THUNK_DATA32 IMAGE_THUNK_DATA; - typedef PIMAGE_THUNK_DATA32 PIMAGE_THUNK_DATA; -#define IMAGE_SNAP_BY_ORDINAL(Ordinal) IMAGE_SNAP_BY_ORDINAL32(Ordinal) - typedef IMAGE_TLS_DIRECTORY32 IMAGE_TLS_DIRECTORY; - typedef PIMAGE_TLS_DIRECTORY32 PIMAGE_TLS_DIRECTORY; -#endif - - typedef struct _IMAGE_IMPORT_DESCRIPTOR { - union { - DWORD Characteristics; - DWORD OriginalFirstThunk; - }; - DWORD TimeDateStamp; - - DWORD ForwarderChain; - DWORD Name; - DWORD FirstThunk; - } IMAGE_IMPORT_DESCRIPTOR; - typedef IMAGE_IMPORT_DESCRIPTOR UNALIGNED *PIMAGE_IMPORT_DESCRIPTOR; - - typedef struct _IMAGE_BOUND_IMPORT_DESCRIPTOR { - DWORD TimeDateStamp; - WORD OffsetModuleName; - WORD NumberOfModuleForwarderRefs; - } IMAGE_BOUND_IMPORT_DESCRIPTOR,*PIMAGE_BOUND_IMPORT_DESCRIPTOR; - - typedef struct _IMAGE_BOUND_FORWARDER_REF { - DWORD TimeDateStamp; - WORD OffsetModuleName; - WORD Reserved; - } IMAGE_BOUND_FORWARDER_REF,*PIMAGE_BOUND_FORWARDER_REF; - - typedef struct _IMAGE_RESOURCE_DIRECTORY { - DWORD Characteristics; - DWORD TimeDateStamp; - WORD MajorVersion; - WORD MinorVersion; - WORD NumberOfNamedEntries; - WORD NumberOfIdEntries; - } IMAGE_RESOURCE_DIRECTORY,*PIMAGE_RESOURCE_DIRECTORY; - -#define IMAGE_RESOURCE_NAME_IS_STRING 0x80000000 -#define IMAGE_RESOURCE_DATA_IS_DIRECTORY 0x80000000 - - typedef struct _IMAGE_RESOURCE_DIRECTORY_ENTRY { - union { - struct { - DWORD NameOffset:31; - DWORD NameIsString:1; - }; - DWORD Name; - WORD Id; - }; - union { - DWORD OffsetToData; - struct { - DWORD OffsetToDirectory:31; - DWORD DataIsDirectory:1; - }; - }; - } IMAGE_RESOURCE_DIRECTORY_ENTRY,*PIMAGE_RESOURCE_DIRECTORY_ENTRY; - - typedef struct _IMAGE_RESOURCE_DIRECTORY_STRING { - WORD Length; - CHAR NameString[1]; - } IMAGE_RESOURCE_DIRECTORY_STRING,*PIMAGE_RESOURCE_DIRECTORY_STRING; - - typedef struct _IMAGE_RESOURCE_DIR_STRING_U { - WORD Length; - WCHAR NameString[1]; - } IMAGE_RESOURCE_DIR_STRING_U,*PIMAGE_RESOURCE_DIR_STRING_U; - - typedef struct _IMAGE_RESOURCE_DATA_ENTRY { - DWORD OffsetToData; - DWORD Size; - DWORD CodePage; - DWORD Reserved; - } IMAGE_RESOURCE_DATA_ENTRY,*PIMAGE_RESOURCE_DATA_ENTRY; - - typedef struct { - DWORD Size; - DWORD TimeDateStamp; - WORD MajorVersion; - WORD MinorVersion; - DWORD GlobalFlagsClear; - DWORD GlobalFlagsSet; - DWORD CriticalSectionDefaultTimeout; - DWORD DeCommitFreeBlockThreshold; - DWORD DeCommitTotalFreeThreshold; - DWORD LockPrefixTable; - DWORD MaximumAllocationSize; - DWORD VirtualMemoryThreshold; - DWORD ProcessHeapFlags; - DWORD ProcessAffinityMask; - WORD CSDVersion; - WORD Reserved1; - DWORD EditList; - DWORD SecurityCookie; - DWORD SEHandlerTable; - DWORD SEHandlerCount; - } IMAGE_LOAD_CONFIG_DIRECTORY32,*PIMAGE_LOAD_CONFIG_DIRECTORY32; - - typedef struct { - DWORD Size; - DWORD TimeDateStamp; - WORD MajorVersion; - WORD MinorVersion; - DWORD GlobalFlagsClear; - DWORD GlobalFlagsSet; - DWORD CriticalSectionDefaultTimeout; - ULONGLONG DeCommitFreeBlockThreshold; - ULONGLONG DeCommitTotalFreeThreshold; - ULONGLONG LockPrefixTable; - ULONGLONG MaximumAllocationSize; - ULONGLONG VirtualMemoryThreshold; - ULONGLONG ProcessAffinityMask; - DWORD ProcessHeapFlags; - WORD CSDVersion; - WORD Reserved1; - ULONGLONG EditList; - ULONGLONG SecurityCookie; - ULONGLONG SEHandlerTable; - ULONGLONG SEHandlerCount; - } IMAGE_LOAD_CONFIG_DIRECTORY64,*PIMAGE_LOAD_CONFIG_DIRECTORY64; - -#ifdef _WIN64 - typedef IMAGE_LOAD_CONFIG_DIRECTORY64 IMAGE_LOAD_CONFIG_DIRECTORY; - typedef PIMAGE_LOAD_CONFIG_DIRECTORY64 PIMAGE_LOAD_CONFIG_DIRECTORY; -#else - typedef IMAGE_LOAD_CONFIG_DIRECTORY32 IMAGE_LOAD_CONFIG_DIRECTORY; - typedef PIMAGE_LOAD_CONFIG_DIRECTORY32 PIMAGE_LOAD_CONFIG_DIRECTORY; -#endif - - typedef struct _IMAGE_CE_RUNTIME_FUNCTION_ENTRY { - DWORD FuncStart; - DWORD PrologLen : 8; - DWORD FuncLen : 22; - DWORD ThirtyTwoBit : 1; - DWORD ExceptionFlag : 1; - } IMAGE_CE_RUNTIME_FUNCTION_ENTRY,*PIMAGE_CE_RUNTIME_FUNCTION_ENTRY; - - typedef struct _IMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY { - ULONGLONG BeginAddress; - ULONGLONG EndAddress; - ULONGLONG ExceptionHandler; - ULONGLONG HandlerData; - ULONGLONG PrologEndAddress; - } IMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY,*PIMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY; - - typedef struct _IMAGE_ALPHA_RUNTIME_FUNCTION_ENTRY { - DWORD BeginAddress; - DWORD EndAddress; - DWORD ExceptionHandler; - DWORD HandlerData; - DWORD PrologEndAddress; - } IMAGE_ALPHA_RUNTIME_FUNCTION_ENTRY,*PIMAGE_ALPHA_RUNTIME_FUNCTION_ENTRY; - - typedef struct _IMAGE_RUNTIME_FUNCTION_ENTRY { - DWORD BeginAddress; - DWORD EndAddress; - DWORD UnwindInfoAddress; - } _IMAGE_RUNTIME_FUNCTION_ENTRY,*_PIMAGE_RUNTIME_FUNCTION_ENTRY; - - typedef _IMAGE_RUNTIME_FUNCTION_ENTRY IMAGE_IA64_RUNTIME_FUNCTION_ENTRY; - typedef _PIMAGE_RUNTIME_FUNCTION_ENTRY PIMAGE_IA64_RUNTIME_FUNCTION_ENTRY; - - typedef _IMAGE_RUNTIME_FUNCTION_ENTRY IMAGE_RUNTIME_FUNCTION_ENTRY; - typedef _PIMAGE_RUNTIME_FUNCTION_ENTRY PIMAGE_RUNTIME_FUNCTION_ENTRY; - - typedef struct _IMAGE_DEBUG_DIRECTORY { - DWORD Characteristics; - DWORD TimeDateStamp; - WORD MajorVersion; - WORD MinorVersion; - DWORD Type; - DWORD SizeOfData; - DWORD AddressOfRawData; - DWORD PointerToRawData; - } IMAGE_DEBUG_DIRECTORY,*PIMAGE_DEBUG_DIRECTORY; - -#define IMAGE_DEBUG_TYPE_UNKNOWN 0 -#define IMAGE_DEBUG_TYPE_COFF 1 -#define IMAGE_DEBUG_TYPE_CODEVIEW 2 -#define IMAGE_DEBUG_TYPE_FPO 3 -#define IMAGE_DEBUG_TYPE_MISC 4 -#define IMAGE_DEBUG_TYPE_EXCEPTION 5 -#define IMAGE_DEBUG_TYPE_FIXUP 6 -#define IMAGE_DEBUG_TYPE_OMAP_TO_SRC 7 -#define IMAGE_DEBUG_TYPE_OMAP_FROM_SRC 8 -#define IMAGE_DEBUG_TYPE_BORLAND 9 -#define IMAGE_DEBUG_TYPE_RESERVED10 10 -#define IMAGE_DEBUG_TYPE_CLSID 11 - - typedef struct _IMAGE_COFF_SYMBOLS_HEADER { - DWORD NumberOfSymbols; - DWORD LvaToFirstSymbol; - DWORD NumberOfLinenumbers; - DWORD LvaToFirstLinenumber; - DWORD RvaToFirstByteOfCode; - DWORD RvaToLastByteOfCode; - DWORD RvaToFirstByteOfData; - DWORD RvaToLastByteOfData; - } IMAGE_COFF_SYMBOLS_HEADER,*PIMAGE_COFF_SYMBOLS_HEADER; - -#define FRAME_FPO 0 -#define FRAME_TRAP 1 -#define FRAME_TSS 2 -#define FRAME_NONFPO 3 - - typedef struct _FPO_DATA { - DWORD ulOffStart; - DWORD cbProcSize; - DWORD cdwLocals; - WORD cdwParams; - WORD cbProlog : 8; - WORD cbRegs : 3; - WORD fHasSEH : 1; - WORD fUseBP : 1; - WORD reserved : 1; - WORD cbFrame : 2; - } FPO_DATA,*PFPO_DATA; -#define SIZEOF_RFPO_DATA 16 - -#define IMAGE_DEBUG_MISC_EXENAME 1 - - typedef struct _IMAGE_DEBUG_MISC { - DWORD DataType; - DWORD Length; - BOOLEAN Unicode; - BYTE Reserved[3]; - BYTE Data[1]; - } IMAGE_DEBUG_MISC,*PIMAGE_DEBUG_MISC; - - typedef struct _IMAGE_FUNCTION_ENTRY { - DWORD StartingAddress; - DWORD EndingAddress; - DWORD EndOfPrologue; - } IMAGE_FUNCTION_ENTRY,*PIMAGE_FUNCTION_ENTRY; - - typedef struct _IMAGE_FUNCTION_ENTRY64 { - ULONGLONG StartingAddress; - ULONGLONG EndingAddress; - union { - ULONGLONG EndOfPrologue; - ULONGLONG UnwindInfoAddress; - }; - } IMAGE_FUNCTION_ENTRY64,*PIMAGE_FUNCTION_ENTRY64; - - typedef struct _IMAGE_SEPARATE_DEBUG_HEADER { - WORD Signature; - WORD Flags; - WORD Machine; - WORD Characteristics; - DWORD TimeDateStamp; - DWORD CheckSum; - DWORD ImageBase; - DWORD SizeOfImage; - DWORD NumberOfSections; - DWORD ExportedNamesSize; - DWORD DebugDirectorySize; - DWORD SectionAlignment; - DWORD Reserved[2]; - } IMAGE_SEPARATE_DEBUG_HEADER,*PIMAGE_SEPARATE_DEBUG_HEADER; - - typedef struct _NON_PAGED_DEBUG_INFO { - WORD Signature; - WORD Flags; - DWORD Size; - WORD Machine; - WORD Characteristics; - DWORD TimeDateStamp; - DWORD CheckSum; - DWORD SizeOfImage; - ULONGLONG ImageBase; - - } NON_PAGED_DEBUG_INFO,*PNON_PAGED_DEBUG_INFO; - -#define IMAGE_SEPARATE_DEBUG_SIGNATURE 0x4944 -#define NON_PAGED_DEBUG_SIGNATURE 0x494E - -#define IMAGE_SEPARATE_DEBUG_FLAGS_MASK 0x8000 -#define IMAGE_SEPARATE_DEBUG_MISMATCH 0x8000 - - typedef struct _ImageArchitectureHeader { - unsigned int AmaskValue: 1; - int Adummy1 :7; - unsigned int AmaskShift: 8; - int Adummy2 :16; - DWORD FirstEntryRVA; - } IMAGE_ARCHITECTURE_HEADER,*PIMAGE_ARCHITECTURE_HEADER; - - typedef struct _ImageArchitectureEntry { - DWORD FixupInstRVA; - DWORD NewInst; - } IMAGE_ARCHITECTURE_ENTRY,*PIMAGE_ARCHITECTURE_ENTRY; - -#include "poppack.h" - -#define IMPORT_OBJECT_HDR_SIG2 0xffff - - typedef struct IMPORT_OBJECT_HEADER { - WORD Sig1; - WORD Sig2; - WORD Version; - WORD Machine; - DWORD TimeDateStamp; - DWORD SizeOfData; - union { - WORD Ordinal; - WORD Hint; - }; - WORD Type : 2; - WORD NameType : 3; - WORD Reserved : 11; - } IMPORT_OBJECT_HEADER; - - typedef enum IMPORT_OBJECT_TYPE { - IMPORT_OBJECT_CODE = 0,IMPORT_OBJECT_DATA = 1,IMPORT_OBJECT_CONST = 2 - } IMPORT_OBJECT_TYPE; - - typedef enum IMPORT_OBJECT_NAME_TYPE { - IMPORT_OBJECT_ORDINAL = 0,IMPORT_OBJECT_NAME = 1,IMPORT_OBJECT_NAME_NO_PREFIX = 2,IMPORT_OBJECT_NAME_UNDECORATE = 3 - } IMPORT_OBJECT_NAME_TYPE; - -#ifndef __IMAGE_COR20_HEADER_DEFINED__ -#define __IMAGE_COR20_HEADER_DEFINED__ - typedef enum ReplacesCorHdrNumericDefines { - COMIMAGE_FLAGS_ILONLY =0x00000001,COMIMAGE_FLAGS_32BITREQUIRED =0x00000002,COMIMAGE_FLAGS_IL_LIBRARY =0x00000004, - COMIMAGE_FLAGS_STRONGNAMESIGNED =0x00000008,COMIMAGE_FLAGS_TRACKDEBUGDATA =0x00010000,COR_VERSION_MAJOR_V2 =2, - COR_VERSION_MAJOR =COR_VERSION_MAJOR_V2,COR_VERSION_MINOR =0,COR_DELETED_NAME_LENGTH =8,COR_VTABLEGAP_NAME_LENGTH =8, - NATIVE_TYPE_MAX_CB =1,COR_ILMETHOD_SECT_SMALL_MAX_DATASIZE=0xFF,IMAGE_COR_MIH_METHODRVA =0x01,IMAGE_COR_MIH_EHRVA =0x02, - IMAGE_COR_MIH_BASICBLOCK =0x08,COR_VTABLE_32BIT =0x01,COR_VTABLE_64BIT =0x02,COR_VTABLE_FROM_UNMANAGED =0x04, - COR_VTABLE_CALL_MOST_DERIVED =0x10,IMAGE_COR_EATJ_THUNK_SIZE =32,MAX_CLASS_NAME =1024,MAX_PACKAGE_NAME =1024 - } ReplacesCorHdrNumericDefines; - - typedef struct IMAGE_COR20_HEADER { - DWORD cb; - WORD MajorRuntimeVersion; - WORD MinorRuntimeVersion; - IMAGE_DATA_DIRECTORY MetaData; - DWORD Flags; - DWORD EntryPointToken; - IMAGE_DATA_DIRECTORY Resources; - IMAGE_DATA_DIRECTORY StrongNameSignature; - IMAGE_DATA_DIRECTORY CodeManagerTable; - IMAGE_DATA_DIRECTORY VTableFixups; - IMAGE_DATA_DIRECTORY ExportAddressTableJumps; - IMAGE_DATA_DIRECTORY ManagedNativeHeader; - } IMAGE_COR20_HEADER,*PIMAGE_COR20_HEADER; -#endif - -#if defined (__x86_64) - NTSYSAPI PRUNTIME_FUNCTION NTAPI RtlLookupFunctionEntry (DWORD64 ControlPc, PDWORD64 ImageBase, PUNWIND_HISTORY_TABLE HistoryTable); - NTSYSAPI VOID NTAPI RtlUnwindEx (PVOID TargetFrame, PVOID TargetIp, PEXCEPTION_RECORD ExceptionRecord, PVOID ReturnValue, PCONTEXT ContextRecord, PUNWIND_HISTORY_TABLE HistoryTable); -#endif - -#include - -#ifndef _SLIST_HEADER_ -#define _SLIST_HEADER_ - -#ifdef _WIN64 - typedef struct _SLIST_ENTRY *PSLIST_ENTRY; - typedef DECLSPEC_ALIGN(16) struct _SLIST_ENTRY { - PSLIST_ENTRY Next; - } SLIST_ENTRY; -#else - -#define SLIST_ENTRY SINGLE_LIST_ENTRY -#define _SLIST_ENTRY _SINGLE_LIST_ENTRY -#define PSLIST_ENTRY PSINGLE_LIST_ENTRY -#endif - -#if defined(_WIN64) - - typedef DECLSPEC_ALIGN(16) struct _SLIST_HEADER { - ULONGLONG Alignment; - ULONGLONG Region; - } SLIST_HEADER; - - typedef struct _SLIST_HEADER *PSLIST_HEADER; -#else - - typedef union _SLIST_HEADER { - ULONGLONG Alignment; - struct { - SLIST_ENTRY Next; - WORD Depth; - WORD Sequence; - }; - } SLIST_HEADER,*PSLIST_HEADER; -#endif -#endif - - NTSYSAPI VOID NTAPI RtlInitializeSListHead(PSLIST_HEADER ListHead); - NTSYSAPI PSLIST_ENTRY NTAPI RtlFirstEntrySList(const SLIST_HEADER *ListHead); - NTSYSAPI PSLIST_ENTRY NTAPI RtlInterlockedPopEntrySList(PSLIST_HEADER ListHead); - NTSYSAPI PSLIST_ENTRY NTAPI RtlInterlockedPushEntrySList(PSLIST_HEADER ListHead,PSLIST_ENTRY ListEntry); - NTSYSAPI PSLIST_ENTRY NTAPI RtlInterlockedFlushSList(PSLIST_HEADER ListHead); - NTSYSAPI WORD NTAPI RtlQueryDepthSList(PSLIST_HEADER ListHead); - -#define HEAP_NO_SERIALIZE 0x00000001 -#define HEAP_GROWABLE 0x00000002 -#define HEAP_GENERATE_EXCEPTIONS 0x00000004 -#define HEAP_ZERO_MEMORY 0x00000008 -#define HEAP_REALLOC_IN_PLACE_ONLY 0x00000010 -#define HEAP_TAIL_CHECKING_ENABLED 0x00000020 -#define HEAP_FREE_CHECKING_ENABLED 0x00000040 -#define HEAP_DISABLE_COALESCE_ON_FREE 0x00000080 -#define HEAP_CREATE_ALIGN_16 0x00010000 -#define HEAP_CREATE_ENABLE_TRACING 0x00020000 -#define HEAP_CREATE_ENABLE_EXECUTE 0x00040000 -#define HEAP_MAXIMUM_TAG 0x0FFF -#define HEAP_PSEUDO_TAG_FLAG 0x8000 -#define HEAP_TAG_SHIFT 18 -#define HEAP_MAKE_TAG_FLAGS(b,o) ((DWORD)((b) + ((o) << 18))) - - NTSYSAPI VOID NTAPI RtlCaptureContext(PCONTEXT ContextRecord); - -#define IS_TEXT_UNICODE_ASCII16 0x0001 -#define IS_TEXT_UNICODE_REVERSE_ASCII16 0x0010 - -#define IS_TEXT_UNICODE_STATISTICS 0x0002 -#define IS_TEXT_UNICODE_REVERSE_STATISTICS 0x0020 - -#define IS_TEXT_UNICODE_CONTROLS 0x0004 -#define IS_TEXT_UNICODE_REVERSE_CONTROLS 0x0040 - -#define IS_TEXT_UNICODE_SIGNATURE 0x0008 -#define IS_TEXT_UNICODE_REVERSE_SIGNATURE 0x0080 - -#define IS_TEXT_UNICODE_ILLEGAL_CHARS 0x0100 -#define IS_TEXT_UNICODE_ODD_LENGTH 0x0200 -#define IS_TEXT_UNICODE_DBCS_LEADBYTE 0x0400 -#define IS_TEXT_UNICODE_NULL_BYTES 0x1000 - -#define IS_TEXT_UNICODE_UNICODE_MASK 0x000F -#define IS_TEXT_UNICODE_REVERSE_MASK 0x00F0 -#define IS_TEXT_UNICODE_NOT_UNICODE_MASK 0x0F00 -#define IS_TEXT_UNICODE_NOT_ASCII_MASK 0xF000 - -#define COMPRESSION_FORMAT_NONE (0x0000) -#define COMPRESSION_FORMAT_DEFAULT (0x0001) -#define COMPRESSION_FORMAT_LZNT1 (0x0002) -#define COMPRESSION_ENGINE_STANDARD (0x0000) -#define COMPRESSION_ENGINE_MAXIMUM (0x0100) -#define COMPRESSION_ENGINE_HIBER (0x0200) - -#if _DBG_MEMCPY_INLINE_ && !defined(_MEMCPY_INLINE_) && !defined(_CRTBLD) -#define _MEMCPY_INLINE_ - __CRT_INLINE PVOID __cdecl memcpy_inline(void *dst,const void *src,size_t size) { - if(((char *)dst > (char *)src) && ((char *)dst < ((char *)src + size))) { - __debugbreak(); - } - return memcpy(dst,src,size); - } -#define memcpy memcpy_inline -#endif - - NTSYSAPI SIZE_T NTAPI RtlCompareMemory(const VOID *Source1,const VOID *Source2,SIZE_T Length); - -#define RtlEqualMemory(Destination,Source,Length) (!memcmp((Destination),(Source),(Length))) -#define RtlMoveMemory(Destination,Source,Length) memmove((Destination),(Source),(Length)) -#define RtlCopyMemory(Destination,Source,Length) memcpy((Destination),(Source),(Length)) -#define RtlFillMemory(Destination,Length,Fill) memset((Destination),(Fill),(Length)) -#define RtlZeroMemory(Destination,Length) memset((Destination),0,(Length)) - - __CRT_INLINE PVOID RtlSecureZeroMemory(PVOID ptr,SIZE_T cnt) { - volatile char *vptr =(volatile char *)ptr; -#ifdef __x86_64 - __stosb((PBYTE)((DWORD64)vptr),0,cnt); -#else - while(cnt) { - *vptr = 0; - vptr++; - cnt--; - } -#endif - return ptr; - } - - typedef struct _MESSAGE_RESOURCE_ENTRY { - WORD Length; - WORD Flags; - BYTE Text[1]; - } MESSAGE_RESOURCE_ENTRY,*PMESSAGE_RESOURCE_ENTRY; - -#define MESSAGE_RESOURCE_UNICODE 0x0001 - - typedef struct _MESSAGE_RESOURCE_BLOCK { - DWORD LowId; - DWORD HighId; - DWORD OffsetToEntries; - } MESSAGE_RESOURCE_BLOCK,*PMESSAGE_RESOURCE_BLOCK; - - typedef struct _MESSAGE_RESOURCE_DATA { - DWORD NumberOfBlocks; - MESSAGE_RESOURCE_BLOCK Blocks[1]; - } MESSAGE_RESOURCE_DATA,*PMESSAGE_RESOURCE_DATA; - - typedef struct _OSVERSIONINFOA { - DWORD dwOSVersionInfoSize; - DWORD dwMajorVersion; - DWORD dwMinorVersion; - DWORD dwBuildNumber; - DWORD dwPlatformId; - CHAR szCSDVersion[128]; - } OSVERSIONINFOA,*POSVERSIONINFOA,*LPOSVERSIONINFOA; - - typedef struct _OSVERSIONINFOW { - DWORD dwOSVersionInfoSize; - DWORD dwMajorVersion; - DWORD dwMinorVersion; - DWORD dwBuildNumber; - DWORD dwPlatformId; - WCHAR szCSDVersion[128]; - } OSVERSIONINFOW,*POSVERSIONINFOW,*LPOSVERSIONINFOW,RTL_OSVERSIONINFOW,*PRTL_OSVERSIONINFOW; - -#ifdef UNICODE - typedef OSVERSIONINFOW OSVERSIONINFO; - typedef POSVERSIONINFOW POSVERSIONINFO; - typedef LPOSVERSIONINFOW LPOSVERSIONINFO; -#else - typedef OSVERSIONINFOA OSVERSIONINFO; - typedef POSVERSIONINFOA POSVERSIONINFO; - typedef LPOSVERSIONINFOA LPOSVERSIONINFO; -#endif - - typedef struct _OSVERSIONINFOEXA { - DWORD dwOSVersionInfoSize; - DWORD dwMajorVersion; - DWORD dwMinorVersion; - DWORD dwBuildNumber; - DWORD dwPlatformId; - CHAR szCSDVersion[128]; - WORD wServicePackMajor; - WORD wServicePackMinor; - WORD wSuiteMask; - BYTE wProductType; - BYTE wReserved; - } OSVERSIONINFOEXA,*POSVERSIONINFOEXA,*LPOSVERSIONINFOEXA; - - typedef struct _OSVERSIONINFOEXW { - DWORD dwOSVersionInfoSize; - DWORD dwMajorVersion; - DWORD dwMinorVersion; - DWORD dwBuildNumber; - DWORD dwPlatformId; - WCHAR szCSDVersion[128]; - WORD wServicePackMajor; - WORD wServicePackMinor; - WORD wSuiteMask; - BYTE wProductType; - BYTE wReserved; - } OSVERSIONINFOEXW,*POSVERSIONINFOEXW,*LPOSVERSIONINFOEXW,RTL_OSVERSIONINFOEXW,*PRTL_OSVERSIONINFOEXW; -#ifdef UNICODE - typedef OSVERSIONINFOEXW OSVERSIONINFOEX; - typedef POSVERSIONINFOEXW POSVERSIONINFOEX; - typedef LPOSVERSIONINFOEXW LPOSVERSIONINFOEX; -#else - typedef OSVERSIONINFOEXA OSVERSIONINFOEX; - typedef POSVERSIONINFOEXA POSVERSIONINFOEX; - typedef LPOSVERSIONINFOEXA LPOSVERSIONINFOEX; -#endif - -#define VER_EQUAL 1 -#define VER_GREATER 2 -#define VER_GREATER_EQUAL 3 -#define VER_LESS 4 -#define VER_LESS_EQUAL 5 -#define VER_AND 6 -#define VER_OR 7 - -#define VER_CONDITION_MASK 7 -#define VER_NUM_BITS_PER_CONDITION_MASK 3 - -#define VER_MINORVERSION 0x0000001 -#define VER_MAJORVERSION 0x0000002 -#define VER_BUILDNUMBER 0x0000004 -#define VER_PLATFORMID 0x0000008 -#define VER_SERVICEPACKMINOR 0x0000010 -#define VER_SERVICEPACKMAJOR 0x0000020 -#define VER_SUITENAME 0x0000040 -#define VER_PRODUCT_TYPE 0x0000080 - -#define VER_NT_WORKSTATION 0x0000001 -#define VER_NT_DOMAIN_CONTROLLER 0x0000002 -#define VER_NT_SERVER 0x0000003 - -#define VER_PLATFORM_WIN32s 0 -#define VER_PLATFORM_WIN32_WINDOWS 1 -#define VER_PLATFORM_WIN32_NT 2 - -#define VER_SET_CONDITION(_m_,_t_,_c_) ((_m_)=VerSetConditionMask((_m_),(_t_),(_c_))) - - NTSYSAPI ULONGLONG NTAPI VerSetConditionMask(ULONGLONG ConditionMask,DWORD TypeMask,BYTE Condition); - - typedef struct _RTL_CRITICAL_SECTION_DEBUG { - WORD Type; - WORD CreatorBackTraceIndex; - struct _RTL_CRITICAL_SECTION *CriticalSection; - LIST_ENTRY ProcessLocksList; - DWORD EntryCount; - DWORD ContentionCount; - DWORD Spare[2]; - } RTL_CRITICAL_SECTION_DEBUG,*PRTL_CRITICAL_SECTION_DEBUG,RTL_RESOURCE_DEBUG,*PRTL_RESOURCE_DEBUG; - -#define RTL_CRITSECT_TYPE 0 -#define RTL_RESOURCE_TYPE 1 - - typedef struct _RTL_CRITICAL_SECTION { - PRTL_CRITICAL_SECTION_DEBUG DebugInfo; - LONG LockCount; - LONG RecursionCount; - HANDLE OwningThread; - HANDLE LockSemaphore; - ULONG_PTR SpinCount; - } RTL_CRITICAL_SECTION,*PRTL_CRITICAL_SECTION; - - typedef VOID (NTAPI *RTL_VERIFIER_DLL_LOAD_CALLBACK) (PWSTR DllName,PVOID DllBase,SIZE_T DllSize,PVOID Reserved); - typedef VOID (NTAPI *RTL_VERIFIER_DLL_UNLOAD_CALLBACK) (PWSTR DllName,PVOID DllBase,SIZE_T DllSize,PVOID Reserved); - typedef VOID (NTAPI *RTL_VERIFIER_NTDLLHEAPFREE_CALLBACK)(PVOID AllocationBase,SIZE_T AllocationSize); - - typedef struct _RTL_VERIFIER_THUNK_DESCRIPTOR { - PCHAR ThunkName; - PVOID ThunkOldAddress; - PVOID ThunkNewAddress; - } RTL_VERIFIER_THUNK_DESCRIPTOR,*PRTL_VERIFIER_THUNK_DESCRIPTOR; - - typedef struct _RTL_VERIFIER_DLL_DESCRIPTOR { - PWCHAR DllName; - DWORD DllFlags; - PVOID DllAddress; - PRTL_VERIFIER_THUNK_DESCRIPTOR DllThunks; - } RTL_VERIFIER_DLL_DESCRIPTOR,*PRTL_VERIFIER_DLL_DESCRIPTOR; - - typedef struct _RTL_VERIFIER_PROVIDER_DESCRIPTOR { - DWORD Length; - PRTL_VERIFIER_DLL_DESCRIPTOR ProviderDlls; - RTL_VERIFIER_DLL_LOAD_CALLBACK ProviderDllLoadCallback; - RTL_VERIFIER_DLL_UNLOAD_CALLBACK ProviderDllUnloadCallback; - PWSTR VerifierImage; - DWORD VerifierFlags; - DWORD VerifierDebug; - PVOID RtlpGetStackTraceAddress; - PVOID RtlpDebugPageHeapCreate; - PVOID RtlpDebugPageHeapDestroy; - RTL_VERIFIER_NTDLLHEAPFREE_CALLBACK ProviderNtdllHeapFreeCallback; - } RTL_VERIFIER_PROVIDER_DESCRIPTOR,*PRTL_VERIFIER_PROVIDER_DESCRIPTOR; - -#define RTL_VRF_FLG_FULL_PAGE_HEAP 0x00000001 -#define RTL_VRF_FLG_RESERVED_DONOTUSE 0x00000002 -#define RTL_VRF_FLG_HANDLE_CHECKS 0x00000004 -#define RTL_VRF_FLG_STACK_CHECKS 0x00000008 -#define RTL_VRF_FLG_APPCOMPAT_CHECKS 0x00000010 -#define RTL_VRF_FLG_TLS_CHECKS 0x00000020 -#define RTL_VRF_FLG_DIRTY_STACKS 0x00000040 -#define RTL_VRF_FLG_RPC_CHECKS 0x00000080 -#define RTL_VRF_FLG_COM_CHECKS 0x00000100 -#define RTL_VRF_FLG_DANGEROUS_APIS 0x00000200 -#define RTL_VRF_FLG_RACE_CHECKS 0x00000400 -#define RTL_VRF_FLG_DEADLOCK_CHECKS 0x00000800 -#define RTL_VRF_FLG_FIRST_CHANCE_EXCEPTION_CHECKS 0x00001000 -#define RTL_VRF_FLG_VIRTUAL_MEM_CHECKS 0x00002000 -#define RTL_VRF_FLG_ENABLE_LOGGING 0x00004000 -#define RTL_VRF_FLG_FAST_FILL_HEAP 0x00008000 -#define RTL_VRF_FLG_VIRTUAL_SPACE_TRACKING 0x00010000 -#define RTL_VRF_FLG_ENABLED_SYSTEM_WIDE 0x00020000 -#define RTL_VRF_FLG_MISCELLANEOUS_CHECKS 0x00020000 -#define RTL_VRF_FLG_LOCK_CHECKS 0x00040000 - -#define APPLICATION_VERIFIER_INTERNAL_ERROR 0x80000000 -#define APPLICATION_VERIFIER_INTERNAL_WARNING 0x40000000 -#define APPLICATION_VERIFIER_NO_BREAK 0x20000000 -#define APPLICATION_VERIFIER_CONTINUABLE_BREAK 0x10000000 - -#define APPLICATION_VERIFIER_UNKNOWN_ERROR 0x0001 -#define APPLICATION_VERIFIER_ACCESS_VIOLATION 0x0002 -#define APPLICATION_VERIFIER_UNSYNCHRONIZED_ACCESS 0x0003 -#define APPLICATION_VERIFIER_EXTREME_SIZE_REQUEST 0x0004 -#define APPLICATION_VERIFIER_BAD_HEAP_HANDLE 0x0005 -#define APPLICATION_VERIFIER_SWITCHED_HEAP_HANDLE 0x0006 -#define APPLICATION_VERIFIER_DOUBLE_FREE 0x0007 -#define APPLICATION_VERIFIER_CORRUPTED_HEAP_BLOCK 0x0008 -#define APPLICATION_VERIFIER_DESTROY_PROCESS_HEAP 0x0009 -#define APPLICATION_VERIFIER_UNEXPECTED_EXCEPTION 0x000A -#define APPLICATION_VERIFIER_CORRUPTED_HEAP_BLOCK_EXCEPTION_RAISED_FOR_HEADER 0x000B -#define APPLICATION_VERIFIER_CORRUPTED_HEAP_BLOCK_EXCEPTION_RAISED_FOR_PROBING 0x000C -#define APPLICATION_VERIFIER_CORRUPTED_HEAP_BLOCK_HEADER 0x000D -#define APPLICATION_VERIFIER_CORRUPTED_FREED_HEAP_BLOCK 0x000E -#define APPLICATION_VERIFIER_CORRUPTED_HEAP_BLOCK_SUFFIX 0x000F -#define APPLICATION_VERIFIER_CORRUPTED_HEAP_BLOCK_START_STAMP 0x0010 -#define APPLICATION_VERIFIER_CORRUPTED_HEAP_BLOCK_END_STAMP 0x0011 -#define APPLICATION_VERIFIER_CORRUPTED_HEAP_BLOCK_PREFIX 0x0012 -#define APPLICATION_VERIFIER_FIRST_CHANCE_ACCESS_VIOLATION 0x0013 -#define APPLICATION_VERIFIER_CORRUPTED_HEAP_LIST 0x0014 - -#define APPLICATION_VERIFIER_TERMINATE_THREAD_CALL 0x0100 -#define APPLICATION_VERIFIER_STACK_OVERFLOW 0x0101 -#define APPLICATION_VERIFIER_INVALID_EXIT_PROCESS_CALL 0x0102 - -#define APPLICATION_VERIFIER_EXIT_THREAD_OWNS_LOCK 0x0200 -#define APPLICATION_VERIFIER_LOCK_IN_UNLOADED_DLL 0x0201 -#define APPLICATION_VERIFIER_LOCK_IN_FREED_HEAP 0x0202 -#define APPLICATION_VERIFIER_LOCK_DOUBLE_INITIALIZE 0x0203 -#define APPLICATION_VERIFIER_LOCK_IN_FREED_MEMORY 0x0204 -#define APPLICATION_VERIFIER_LOCK_CORRUPTED 0x0205 -#define APPLICATION_VERIFIER_LOCK_INVALID_OWNER 0x0206 -#define APPLICATION_VERIFIER_LOCK_INVALID_RECURSION_COUNT 0x0207 -#define APPLICATION_VERIFIER_LOCK_INVALID_LOCK_COUNT 0x0208 -#define APPLICATION_VERIFIER_LOCK_OVER_RELEASED 0x0209 -#define APPLICATION_VERIFIER_LOCK_NOT_INITIALIZED 0x0210 -#define APPLICATION_VERIFIER_LOCK_ALREADY_INITIALIZED 0x0211 -#define APPLICATION_VERIFIER_LOCK_IN_FREED_VMEM 0x0212 -#define APPLICATION_VERIFIER_LOCK_IN_UNMAPPED_MEM 0x0213 -#define APPLICATION_VERIFIER_THREAD_NOT_LOCK_OWNER 0x0214 - -#define APPLICATION_VERIFIER_INVALID_HANDLE 0x0300 -#define APPLICATION_VERIFIER_INVALID_TLS_VALUE 0x0301 -#define APPLICATION_VERIFIER_INCORRECT_WAIT_CALL 0x0302 -#define APPLICATION_VERIFIER_NULL_HANDLE 0x0303 -#define APPLICATION_VERIFIER_WAIT_IN_DLLMAIN 0x0304 - -#define APPLICATION_VERIFIER_COM_ERROR 0x0400 -#define APPLICATION_VERIFIER_COM_API_IN_DLLMAIN 0x0401 -#define APPLICATION_VERIFIER_COM_UNHANDLED_EXCEPTION 0x0402 -#define APPLICATION_VERIFIER_COM_UNBALANCED_COINIT 0x0403 -#define APPLICATION_VERIFIER_COM_UNBALANCED_OLEINIT 0x0404 -#define APPLICATION_VERIFIER_COM_UNBALANCED_SWC 0x0405 -#define APPLICATION_VERIFIER_COM_NULL_DACL 0x0406 -#define APPLICATION_VERIFIER_COM_UNSAFE_IMPERSONATION 0x0407 -#define APPLICATION_VERIFIER_COM_SMUGGLED_WRAPPER 0x0408 -#define APPLICATION_VERIFIER_COM_SMUGGLED_PROXY 0x0409 -#define APPLICATION_VERIFIER_COM_CF_SUCCESS_WITH_NULL 0x040A -#define APPLICATION_VERIFIER_COM_GCO_SUCCESS_WITH_NULL 0x040B -#define APPLICATION_VERIFIER_COM_OBJECT_IN_FREED_MEMORY 0x040C -#define APPLICATION_VERIFIER_COM_OBJECT_IN_UNLOADED_DLL 0x040D -#define APPLICATION_VERIFIER_COM_VTBL_IN_FREED_MEMORY 0x040E -#define APPLICATION_VERIFIER_COM_VTBL_IN_UNLOADED_DLL 0x040F -#define APPLICATION_VERIFIER_COM_HOLDING_LOCKS_ON_CALL 0x0410 - -#define APPLICATION_VERIFIER_RPC_ERROR 0x0500 - -#define APPLICATION_VERIFIER_INVALID_FREEMEM 0x0600 -#define APPLICATION_VERIFIER_INVALID_ALLOCMEM 0x0601 -#define APPLICATION_VERIFIER_INVALID_MAPVIEW 0x0602 -#define APPLICATION_VERIFIER_PROBE_INVALID_ADDRESS 0x0603 -#define APPLICATION_VERIFIER_PROBE_FREE_MEM 0x0604 -#define APPLICATION_VERIFIER_PROBE_GUARD_PAGE 0x0605 -#define APPLICATION_VERIFIER_PROBE_NULL 0x0606 -#define APPLICATION_VERIFIER_PROBE_INVALID_START_OR_SIZE 0x0607 -#define APPLICATION_VERIFIER_SIZE_HEAP_UNEXPECTED_EXCEPTION 0x0618 - -#define VERIFIER_STOP(Code,Msg,P1,S1,P2,S2,P3,S3,P4,S4) { RtlApplicationVerifierStop ((Code),(Msg),(ULONG_PTR)(P1),(S1),(ULONG_PTR)(P2),(S2),(ULONG_PTR)(P3),(S3),(ULONG_PTR)(P4),(S4)); } - - VOID NTAPI RtlApplicationVerifierStop(ULONG_PTR Code,PSTR Message,ULONG_PTR Param1,PSTR Description1,ULONG_PTR Param2,PSTR Description2,ULONG_PTR Param3,PSTR Description3,ULONG_PTR Param4,PSTR Description4); - - typedef LONG (NTAPI *PVECTORED_EXCEPTION_HANDLER)(struct _EXCEPTION_POINTERS *ExceptionInfo); -#define SEF_DACL_AUTO_INHERIT 0x01 -#define SEF_SACL_AUTO_INHERIT 0x02 -#define SEF_DEFAULT_DESCRIPTOR_FOR_OBJECT 0x04 -#define SEF_AVOID_PRIVILEGE_CHECK 0x08 -#define SEF_AVOID_OWNER_CHECK 0x10 -#define SEF_DEFAULT_OWNER_FROM_PARENT 0x20 -#define SEF_DEFAULT_GROUP_FROM_PARENT 0x40 - - typedef enum _HEAP_INFORMATION_CLASS { - HeapCompatibilityInformation - } HEAP_INFORMATION_CLASS; - - NTSYSAPI DWORD NTAPI RtlSetHeapInformation(PVOID HeapHandle,HEAP_INFORMATION_CLASS HeapInformationClass,PVOID HeapInformation,SIZE_T HeapInformationLength); - NTSYSAPI DWORD NTAPI RtlQueryHeapInformation(PVOID HeapHandle,HEAP_INFORMATION_CLASS HeapInformationClass,PVOID HeapInformation,SIZE_T HeapInformationLength,PSIZE_T ReturnLength); - DWORD NTAPI RtlMultipleAllocateHeap(PVOID HeapHandle,DWORD Flags,SIZE_T Size,DWORD Count,PVOID *Array); - DWORD NTAPI RtlMultipleFreeHeap(PVOID HeapHandle,DWORD Flags,DWORD Count,PVOID *Array); - -#define WT_EXECUTEDEFAULT 0x00000000 -#define WT_EXECUTEINIOTHREAD 0x00000001 -#define WT_EXECUTEINUITHREAD 0x00000002 -#define WT_EXECUTEINWAITTHREAD 0x00000004 -#define WT_EXECUTEONLYONCE 0x00000008 -#define WT_EXECUTEINTIMERTHREAD 0x00000020 -#define WT_EXECUTELONGFUNCTION 0x00000010 -#define WT_EXECUTEINPERSISTENTIOTHREAD 0x00000040 -#define WT_EXECUTEINPERSISTENTTHREAD 0x00000080 -#define WT_TRANSFER_IMPERSONATION 0x00000100 -#define WT_SET_MAX_THREADPOOL_THREADS(Flags,Limit) ((Flags) |= (Limit)<<16) - typedef VOID (NTAPI *WAITORTIMERCALLBACKFUNC)(PVOID,BOOLEAN); - typedef VOID (NTAPI *WORKERCALLBACKFUNC)(PVOID); - typedef VOID (NTAPI *APC_CALLBACK_FUNCTION)(DWORD ,PVOID,PVOID); - typedef - VOID - (NTAPI *PFLS_CALLBACK_FUNCTION)(PVOID lpFlsData); -#define WT_EXECUTEINLONGTHREAD 0x00000010 -#define WT_EXECUTEDELETEWAIT 0x00000008 - - typedef enum _ACTIVATION_CONTEXT_INFO_CLASS { - ActivationContextBasicInformation = 1,ActivationContextDetailedInformation = 2,AssemblyDetailedInformationInActivationContext = 3,FileInformationInAssemblyOfAssemblyInActivationContext = 4,MaxActivationContextInfoClass,AssemblyDetailedInformationInActivationContxt = 3,FileInformationInAssemblyOfAssemblyInActivationContxt = 4 - } ACTIVATION_CONTEXT_INFO_CLASS; - -#define ACTIVATIONCONTEXTINFOCLASS ACTIVATION_CONTEXT_INFO_CLASS - - typedef struct _ACTIVATION_CONTEXT_QUERY_INDEX { - DWORD ulAssemblyIndex; - DWORD ulFileIndexInAssembly; - } ACTIVATION_CONTEXT_QUERY_INDEX,*PACTIVATION_CONTEXT_QUERY_INDEX; - - typedef const struct _ACTIVATION_CONTEXT_QUERY_INDEX *PCACTIVATION_CONTEXT_QUERY_INDEX; - -#define ACTIVATION_CONTEXT_PATH_TYPE_NONE (1) -#define ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE (2) -#define ACTIVATION_CONTEXT_PATH_TYPE_URL (3) -#define ACTIVATION_CONTEXT_PATH_TYPE_ASSEMBLYREF (4) - - typedef struct _ASSEMBLY_FILE_DETAILED_INFORMATION { - DWORD ulFlags; - DWORD ulFilenameLength; - DWORD ulPathLength; - - PCWSTR lpFileName; - PCWSTR lpFilePath; - } ASSEMBLY_FILE_DETAILED_INFORMATION,*PASSEMBLY_FILE_DETAILED_INFORMATION; - typedef const ASSEMBLY_FILE_DETAILED_INFORMATION *PCASSEMBLY_FILE_DETAILED_INFORMATION; - -#define _ASSEMBLY_DLL_REDIRECTION_DETAILED_INFORMATION _ASSEMBLY_FILE_DETAILED_INFORMATION -#define ASSEMBLY_DLL_REDIRECTION_DETAILED_INFORMATION ASSEMBLY_FILE_DETAILED_INFORMATION -#define PASSEMBLY_DLL_REDIRECTION_DETAILED_INFORMATION PASSEMBLY_FILE_DETAILED_INFORMATION -#define PCASSEMBLY_DLL_REDIRECTION_DETAILED_INFORMATION PCASSEMBLY_FILE_DETAILED_INFORMATION - - typedef struct _ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION { - DWORD ulFlags; - DWORD ulEncodedAssemblyIdentityLength; - DWORD ulManifestPathType; - DWORD ulManifestPathLength; - LARGE_INTEGER liManifestLastWriteTime; - DWORD ulPolicyPathType; - DWORD ulPolicyPathLength; - LARGE_INTEGER liPolicyLastWriteTime; - DWORD ulMetadataSatelliteRosterIndex; - DWORD ulManifestVersionMajor; - DWORD ulManifestVersionMinor; - DWORD ulPolicyVersionMajor; - DWORD ulPolicyVersionMinor; - DWORD ulAssemblyDirectoryNameLength; - PCWSTR lpAssemblyEncodedAssemblyIdentity; - PCWSTR lpAssemblyManifestPath; - PCWSTR lpAssemblyPolicyPath; - PCWSTR lpAssemblyDirectoryName; - DWORD ulFileCount; - } ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION,*PACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION; - - typedef const struct _ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION *PCACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION; - - typedef struct _ACTIVATION_CONTEXT_DETAILED_INFORMATION { - DWORD dwFlags; - DWORD ulFormatVersion; - DWORD ulAssemblyCount; - DWORD ulRootManifestPathType; - DWORD ulRootManifestPathChars; - DWORD ulRootConfigurationPathType; - DWORD ulRootConfigurationPathChars; - DWORD ulAppDirPathType; - DWORD ulAppDirPathChars; - PCWSTR lpRootManifestPath; - PCWSTR lpRootConfigurationPath; - PCWSTR lpAppDirPath; - } ACTIVATION_CONTEXT_DETAILED_INFORMATION,*PACTIVATION_CONTEXT_DETAILED_INFORMATION; - - typedef const struct _ACTIVATION_CONTEXT_DETAILED_INFORMATION *PCACTIVATION_CONTEXT_DETAILED_INFORMATION; - -#define DLL_PROCESS_ATTACH 1 -#define DLL_THREAD_ATTACH 2 -#define DLL_THREAD_DETACH 3 -#define DLL_PROCESS_DETACH 0 -#define DLL_PROCESS_VERIFIER 4 - -#define EVENTLOG_SEQUENTIAL_READ 0x0001 -#define EVENTLOG_SEEK_READ 0x0002 -#define EVENTLOG_FORWARDS_READ 0x0004 -#define EVENTLOG_BACKWARDS_READ 0x0008 - -#define EVENTLOG_SUCCESS 0x0000 -#define EVENTLOG_ERROR_TYPE 0x0001 -#define EVENTLOG_WARNING_TYPE 0x0002 -#define EVENTLOG_INFORMATION_TYPE 0x0004 -#define EVENTLOG_AUDIT_SUCCESS 0x0008 -#define EVENTLOG_AUDIT_FAILURE 0x0010 - -#define EVENTLOG_START_PAIRED_EVENT 0x0001 -#define EVENTLOG_END_PAIRED_EVENT 0x0002 -#define EVENTLOG_END_ALL_PAIRED_EVENTS 0x0004 -#define EVENTLOG_PAIRED_EVENT_ACTIVE 0x0008 -#define EVENTLOG_PAIRED_EVENT_INACTIVE 0x0010 - - typedef struct _EVENTLOGRECORD { - DWORD Length; - DWORD Reserved; - DWORD RecordNumber; - DWORD TimeGenerated; - DWORD TimeWritten; - DWORD EventID; - WORD EventType; - WORD NumStrings; - WORD EventCategory; - WORD ReservedFlags; - DWORD ClosingRecordNumber; - DWORD StringOffset; - DWORD UserSidLength; - DWORD UserSidOffset; - DWORD DataLength; - DWORD DataOffset; - } EVENTLOGRECORD,*PEVENTLOGRECORD; - -#define MAXLOGICALLOGNAMESIZE 256 - - typedef struct _EVENTSFORLOGFILE{ - DWORD ulSize; - WCHAR szLogicalLogFile[MAXLOGICALLOGNAMESIZE]; - DWORD ulNumRecords; - EVENTLOGRECORD pEventLogRecords[]; - } EVENTSFORLOGFILE,*PEVENTSFORLOGFILE; - - typedef struct _PACKEDEVENTINFO{ - DWORD ulSize; - DWORD ulNumEventsForLogFile; - DWORD ulOffsets[]; - } PACKEDEVENTINFO,*PPACKEDEVENTINFO; - -#define KEY_QUERY_VALUE (0x0001) -#define KEY_SET_VALUE (0x0002) -#define KEY_CREATE_SUB_KEY (0x0004) -#define KEY_ENUMERATE_SUB_KEYS (0x0008) -#define KEY_NOTIFY (0x0010) -#define KEY_CREATE_LINK (0x0020) -#define KEY_WOW64_32KEY (0x0200) -#define KEY_WOW64_64KEY (0x0100) -#define KEY_WOW64_RES (0x0300) - -#define KEY_READ ((STANDARD_RIGHTS_READ | KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS | KEY_NOTIFY) & (~SYNCHRONIZE)) -#define KEY_WRITE ((STANDARD_RIGHTS_WRITE | KEY_SET_VALUE | KEY_CREATE_SUB_KEY) & (~SYNCHRONIZE)) -#define KEY_EXECUTE ((KEY_READ) & (~SYNCHRONIZE)) -#define KEY_ALL_ACCESS ((STANDARD_RIGHTS_ALL | KEY_QUERY_VALUE | KEY_SET_VALUE | KEY_CREATE_SUB_KEY | KEY_ENUMERATE_SUB_KEYS | KEY_NOTIFY | KEY_CREATE_LINK) & (~SYNCHRONIZE)) -#define REG_OPTION_RESERVED (0x00000000L) - -#define REG_OPTION_NON_VOLATILE (0x00000000L) -#define REG_OPTION_VOLATILE (0x00000001L) -#define REG_OPTION_CREATE_LINK (0x00000002L) -#define REG_OPTION_BACKUP_RESTORE (0x00000004L) -#define REG_OPTION_OPEN_LINK (0x00000008L) -#define REG_LEGAL_OPTION (REG_OPTION_RESERVED | REG_OPTION_NON_VOLATILE | REG_OPTION_VOLATILE | REG_OPTION_CREATE_LINK | REG_OPTION_BACKUP_RESTORE | REG_OPTION_OPEN_LINK) -#define REG_CREATED_NEW_KEY (0x00000001L) -#define REG_OPENED_EXISTING_KEY (0x00000002L) -#define REG_STANDARD_FORMAT 1 -#define REG_LATEST_FORMAT 2 -#define REG_NO_COMPRESSION 4 -#define REG_WHOLE_HIVE_VOLATILE (0x00000001L) -#define REG_REFRESH_HIVE (0x00000002L) -#define REG_NO_LAZY_FLUSH (0x00000004L) -#define REG_FORCE_RESTORE (0x00000008L) -#define REG_FORCE_UNLOAD 1 - -#define REG_NOTIFY_CHANGE_NAME (0x00000001L) -#define REG_NOTIFY_CHANGE_ATTRIBUTES (0x00000002L) -#define REG_NOTIFY_CHANGE_LAST_SET (0x00000004L) -#define REG_NOTIFY_CHANGE_SECURITY (0x00000008L) - -#define REG_LEGAL_CHANGE_FILTER (REG_NOTIFY_CHANGE_NAME | REG_NOTIFY_CHANGE_ATTRIBUTES | REG_NOTIFY_CHANGE_LAST_SET | REG_NOTIFY_CHANGE_SECURITY) - -#define REG_NONE (0) -#define REG_SZ (1) -#define REG_EXPAND_SZ (2) - -#define REG_BINARY (3) -#define REG_DWORD (4) -#define REG_DWORD_LITTLE_ENDIAN (4) -#define REG_DWORD_BIG_ENDIAN (5) -#define REG_LINK (6) -#define REG_MULTI_SZ (7) -#define REG_RESOURCE_LIST (8) -#define REG_FULL_RESOURCE_DESCRIPTOR (9) -#define REG_RESOURCE_REQUIREMENTS_LIST (10) -#define REG_QWORD (11) -#define REG_QWORD_LITTLE_ENDIAN (11) - -#define SERVICE_KERNEL_DRIVER 0x00000001 -#define SERVICE_FILE_SYSTEM_DRIVER 0x00000002 -#define SERVICE_ADAPTER 0x00000004 -#define SERVICE_RECOGNIZER_DRIVER 0x00000008 - -#define SERVICE_DRIVER (SERVICE_KERNEL_DRIVER | SERVICE_FILE_SYSTEM_DRIVER | SERVICE_RECOGNIZER_DRIVER) - -#define SERVICE_WIN32_OWN_PROCESS 0x00000010 -#define SERVICE_WIN32_SHARE_PROCESS 0x00000020 -#define SERVICE_WIN32 (SERVICE_WIN32_OWN_PROCESS | SERVICE_WIN32_SHARE_PROCESS) - -#define SERVICE_INTERACTIVE_PROCESS 0x00000100 - -#define SERVICE_TYPE_ALL (SERVICE_WIN32 | SERVICE_ADAPTER | SERVICE_DRIVER | SERVICE_INTERACTIVE_PROCESS) - -#define SERVICE_BOOT_START 0x00000000 -#define SERVICE_SYSTEM_START 0x00000001 -#define SERVICE_AUTO_START 0x00000002 -#define SERVICE_DEMAND_START 0x00000003 -#define SERVICE_DISABLED 0x00000004 - -#define SERVICE_ERROR_IGNORE 0x00000000 -#define SERVICE_ERROR_NORMAL 0x00000001 -#define SERVICE_ERROR_SEVERE 0x00000002 -#define SERVICE_ERROR_CRITICAL 0x00000003 - - typedef enum _CM_SERVICE_NODE_TYPE { - DriverType = SERVICE_KERNEL_DRIVER,FileSystemType = SERVICE_FILE_SYSTEM_DRIVER,Win32ServiceOwnProcess = SERVICE_WIN32_OWN_PROCESS, - Win32ServiceShareProcess = SERVICE_WIN32_SHARE_PROCESS,AdapterType = SERVICE_ADAPTER,RecognizerType = SERVICE_RECOGNIZER_DRIVER - } SERVICE_NODE_TYPE; - - typedef enum _CM_SERVICE_LOAD_TYPE { - BootLoad = SERVICE_BOOT_START,SystemLoad = SERVICE_SYSTEM_START,AutoLoad = SERVICE_AUTO_START,DemandLoad = SERVICE_DEMAND_START, - DisableLoad = SERVICE_DISABLED - } SERVICE_LOAD_TYPE; - - typedef enum _CM_ERROR_CONTROL_TYPE { - IgnoreError = SERVICE_ERROR_IGNORE,NormalError = SERVICE_ERROR_NORMAL,SevereError = SERVICE_ERROR_SEVERE,CriticalError = SERVICE_ERROR_CRITICAL - } SERVICE_ERROR_TYPE; - -#define TAPE_ERASE_SHORT 0L -#define TAPE_ERASE_LONG 1L - - typedef struct _TAPE_ERASE { - DWORD Type; - BOOLEAN Immediate; - } TAPE_ERASE,*PTAPE_ERASE; - -#define TAPE_LOAD 0L -#define TAPE_UNLOAD 1L -#define TAPE_TENSION 2L -#define TAPE_LOCK 3L -#define TAPE_UNLOCK 4L -#define TAPE_FORMAT 5L - - typedef struct _TAPE_PREPARE { - DWORD Operation; - BOOLEAN Immediate; - } TAPE_PREPARE,*PTAPE_PREPARE; - -#define TAPE_SETMARKS 0L -#define TAPE_FILEMARKS 1L -#define TAPE_SHORT_FILEMARKS 2L -#define TAPE_LONG_FILEMARKS 3L - - typedef struct _TAPE_WRITE_MARKS { - DWORD Type; - DWORD Count; - BOOLEAN Immediate; - } TAPE_WRITE_MARKS,*PTAPE_WRITE_MARKS; - -#define TAPE_ABSOLUTE_POSITION 0L -#define TAPE_LOGICAL_POSITION 1L -#define TAPE_PSEUDO_LOGICAL_POSITION 2L - - typedef struct _TAPE_GET_POSITION { - DWORD Type; - DWORD Partition; - LARGE_INTEGER Offset; - } TAPE_GET_POSITION,*PTAPE_GET_POSITION; - -#define TAPE_REWIND 0L -#define TAPE_ABSOLUTE_BLOCK 1L -#define TAPE_LOGICAL_BLOCK 2L -#define TAPE_PSEUDO_LOGICAL_BLOCK 3L -#define TAPE_SPACE_END_OF_DATA 4L -#define TAPE_SPACE_RELATIVE_BLOCKS 5L -#define TAPE_SPACE_FILEMARKS 6L -#define TAPE_SPACE_SEQUENTIAL_FMKS 7L -#define TAPE_SPACE_SETMARKS 8L -#define TAPE_SPACE_SEQUENTIAL_SMKS 9L - - typedef struct _TAPE_SET_POSITION { - DWORD Method; - DWORD Partition; - LARGE_INTEGER Offset; - BOOLEAN Immediate; - } TAPE_SET_POSITION,*PTAPE_SET_POSITION; - -#define TAPE_DRIVE_FIXED 0x00000001 -#define TAPE_DRIVE_SELECT 0x00000002 -#define TAPE_DRIVE_INITIATOR 0x00000004 - -#define TAPE_DRIVE_ERASE_SHORT 0x00000010 -#define TAPE_DRIVE_ERASE_LONG 0x00000020 -#define TAPE_DRIVE_ERASE_BOP_ONLY 0x00000040 -#define TAPE_DRIVE_ERASE_IMMEDIATE 0x00000080 - -#define TAPE_DRIVE_TAPE_CAPACITY 0x00000100 -#define TAPE_DRIVE_TAPE_REMAINING 0x00000200 -#define TAPE_DRIVE_FIXED_BLOCK 0x00000400 -#define TAPE_DRIVE_VARIABLE_BLOCK 0x00000800 - -#define TAPE_DRIVE_WRITE_PROTECT 0x00001000 -#define TAPE_DRIVE_EOT_WZ_SIZE 0x00002000 - -#define TAPE_DRIVE_ECC 0x00010000 -#define TAPE_DRIVE_COMPRESSION 0x00020000 -#define TAPE_DRIVE_PADDING 0x00040000 -#define TAPE_DRIVE_REPORT_SMKS 0x00080000 - -#define TAPE_DRIVE_GET_ABSOLUTE_BLK 0x00100000 -#define TAPE_DRIVE_GET_LOGICAL_BLK 0x00200000 -#define TAPE_DRIVE_SET_EOT_WZ_SIZE 0x00400000 - -#define TAPE_DRIVE_EJECT_MEDIA 0x01000000 -#define TAPE_DRIVE_CLEAN_REQUESTS 0x02000000 -#define TAPE_DRIVE_SET_CMP_BOP_ONLY 0x04000000 - -#define TAPE_DRIVE_RESERVED_BIT 0x80000000 - -#define TAPE_DRIVE_LOAD_UNLOAD 0x80000001 -#define TAPE_DRIVE_TENSION 0x80000002 -#define TAPE_DRIVE_LOCK_UNLOCK 0x80000004 -#define TAPE_DRIVE_REWIND_IMMEDIATE 0x80000008 - -#define TAPE_DRIVE_SET_BLOCK_SIZE 0x80000010 -#define TAPE_DRIVE_LOAD_UNLD_IMMED 0x80000020 -#define TAPE_DRIVE_TENSION_IMMED 0x80000040 -#define TAPE_DRIVE_LOCK_UNLK_IMMED 0x80000080 - -#define TAPE_DRIVE_SET_ECC 0x80000100 -#define TAPE_DRIVE_SET_COMPRESSION 0x80000200 -#define TAPE_DRIVE_SET_PADDING 0x80000400 -#define TAPE_DRIVE_SET_REPORT_SMKS 0x80000800 - -#define TAPE_DRIVE_ABSOLUTE_BLK 0x80001000 -#define TAPE_DRIVE_ABS_BLK_IMMED 0x80002000 -#define TAPE_DRIVE_LOGICAL_BLK 0x80004000 -#define TAPE_DRIVE_LOG_BLK_IMMED 0x80008000 - -#define TAPE_DRIVE_END_OF_DATA 0x80010000 -#define TAPE_DRIVE_RELATIVE_BLKS 0x80020000 -#define TAPE_DRIVE_FILEMARKS 0x80040000 -#define TAPE_DRIVE_SEQUENTIAL_FMKS 0x80080000 - -#define TAPE_DRIVE_SETMARKS 0x80100000 -#define TAPE_DRIVE_SEQUENTIAL_SMKS 0x80200000 -#define TAPE_DRIVE_REVERSE_POSITION 0x80400000 -#define TAPE_DRIVE_SPACE_IMMEDIATE 0x80800000 - -#define TAPE_DRIVE_WRITE_SETMARKS 0x81000000 -#define TAPE_DRIVE_WRITE_FILEMARKS 0x82000000 -#define TAPE_DRIVE_WRITE_SHORT_FMKS 0x84000000 -#define TAPE_DRIVE_WRITE_LONG_FMKS 0x88000000 - -#define TAPE_DRIVE_WRITE_MARK_IMMED 0x90000000 -#define TAPE_DRIVE_FORMAT 0xA0000000 -#define TAPE_DRIVE_FORMAT_IMMEDIATE 0xC0000000 -#define TAPE_DRIVE_HIGH_FEATURES 0x80000000 - - typedef struct _TAPE_GET_DRIVE_PARAMETERS { - BOOLEAN ECC; - BOOLEAN Compression; - BOOLEAN DataPadding; - BOOLEAN ReportSetmarks; - DWORD DefaultBlockSize; - DWORD MaximumBlockSize; - DWORD MinimumBlockSize; - DWORD MaximumPartitionCount; - DWORD FeaturesLow; - DWORD FeaturesHigh; - DWORD EOTWarningZoneSize; - } TAPE_GET_DRIVE_PARAMETERS,*PTAPE_GET_DRIVE_PARAMETERS; - - typedef struct _TAPE_SET_DRIVE_PARAMETERS { - BOOLEAN ECC; - BOOLEAN Compression; - BOOLEAN DataPadding; - BOOLEAN ReportSetmarks; - DWORD EOTWarningZoneSize; - } TAPE_SET_DRIVE_PARAMETERS,*PTAPE_SET_DRIVE_PARAMETERS; - - typedef struct _TAPE_GET_MEDIA_PARAMETERS { - LARGE_INTEGER Capacity; - LARGE_INTEGER Remaining; - DWORD BlockSize; - DWORD PartitionCount; - BOOLEAN WriteProtected; - } TAPE_GET_MEDIA_PARAMETERS,*PTAPE_GET_MEDIA_PARAMETERS; - - typedef struct _TAPE_SET_MEDIA_PARAMETERS { - DWORD BlockSize; - } TAPE_SET_MEDIA_PARAMETERS,*PTAPE_SET_MEDIA_PARAMETERS; - -#define TAPE_FIXED_PARTITIONS 0L -#define TAPE_SELECT_PARTITIONS 1L -#define TAPE_INITIATOR_PARTITIONS 2L - - typedef struct _TAPE_CREATE_PARTITION { - DWORD Method; - DWORD Count; - DWORD Size; - } TAPE_CREATE_PARTITION,*PTAPE_CREATE_PARTITION; - -#define TAPE_QUERY_DRIVE_PARAMETERS 0L -#define TAPE_QUERY_MEDIA_CAPACITY 1L -#define TAPE_CHECK_FOR_DRIVE_PROBLEM 2L -#define TAPE_QUERY_IO_ERROR_DATA 3L -#define TAPE_QUERY_DEVICE_ERROR_DATA 4L - - typedef struct _TAPE_WMI_OPERATIONS { - DWORD Method; - DWORD DataBufferSize; - PVOID DataBuffer; - } TAPE_WMI_OPERATIONS,*PTAPE_WMI_OPERATIONS; - - typedef enum _TAPE_DRIVE_PROBLEM_TYPE { - TapeDriveProblemNone,TapeDriveReadWriteWarning,TapeDriveReadWriteError,TapeDriveReadWarning,TapeDriveWriteWarning,TapeDriveReadError,TapeDriveWriteError,TapeDriveHardwareError,TapeDriveUnsupportedMedia,TapeDriveScsiConnectionError,TapeDriveTimetoClean,TapeDriveCleanDriveNow,TapeDriveMediaLifeExpired,TapeDriveSnappedTape - } TAPE_DRIVE_PROBLEM_TYPE; - -#if defined(__x86_64) - __CRT_INLINE struct _TEB *NtCurrentTeb(VOID) { return (struct _TEB *)__readgsqword(FIELD_OFFSET(NT_TIB,Self)); } - __CRT_INLINE PVOID GetCurrentFiber(VOID) { return(PVOID)__readgsqword(FIELD_OFFSET(NT_TIB,FiberData)); } - __CRT_INLINE PVOID GetFiberData(VOID) { - return *(PVOID *)GetCurrentFiber(); - } -#endif - -#if(defined(_X86_) && !defined(__x86_64)) -#define PcTeb 0x18 - __CRT_INLINE struct _TEB *NtCurrentTeb(void) { - struct _TEB *ret; - __asm__ volatile ("movl %%fs:0x18,%0" - : "=r" (ret)); - return ret; - } -#endif - -#define ACTIVATION_CONTEXT_SECTION_ASSEMBLY_INFORMATION (1) -#define ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION (2) -#define ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION (3) -#define ACTIVATION_CONTEXT_SECTION_COM_SERVER_REDIRECTION (4) -#define ACTIVATION_CONTEXT_SECTION_COM_INTERFACE_REDIRECTION (5) -#define ACTIVATION_CONTEXT_SECTION_COM_TYPE_LIBRARY_REDIRECTION (6) -#define ACTIVATION_CONTEXT_SECTION_COM_PROGID_REDIRECTION (7) -#define ACTIVATION_CONTEXT_SECTION_GLOBAL_OBJECT_RENAME_TABLE (8) -#define ACTIVATION_CONTEXT_SECTION_CLR_SURROGATES (9) -#define ACTIVATION_CONTEXT_SECTION_APPLICATION_SETTINGS (10) - -#ifdef __cplusplus - } -#endif -#endif diff --git a/05/tcc-final-old/win32/include/winapi/winreg.h b/05/tcc-final-old/win32/include/winapi/winreg.h deleted file mode 100644 index f158d28..0000000 --- a/05/tcc-final-old/win32/include/winapi/winreg.h +++ /dev/null @@ -1,272 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _WINREG_ -#define _WINREG_ - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef WINVER -#define WINVER 0x0502 -#endif - -#define RRF_RT_REG_NONE 0x00000001 -#define RRF_RT_REG_SZ 0x00000002 -#define RRF_RT_REG_EXPAND_SZ 0x00000004 -#define RRF_RT_REG_BINARY 0x00000008 -#define RRF_RT_REG_DWORD 0x00000010 -#define RRF_RT_REG_MULTI_SZ 0x00000020 -#define RRF_RT_REG_QWORD 0x00000040 - -#define RRF_RT_DWORD (RRF_RT_REG_BINARY | RRF_RT_REG_DWORD) -#define RRF_RT_QWORD (RRF_RT_REG_BINARY | RRF_RT_REG_QWORD) -#define RRF_RT_ANY 0x0000ffff - -#define RRF_NOEXPAND 0x10000000 -#define RRF_ZEROONFAILURE 0x20000000 - - typedef ACCESS_MASK REGSAM; - -#define HKEY_CLASSES_ROOT ((HKEY) (ULONG_PTR)((LONG)0x80000000)) -#define HKEY_CURRENT_USER ((HKEY) (ULONG_PTR)((LONG)0x80000001)) -#define HKEY_LOCAL_MACHINE ((HKEY) (ULONG_PTR)((LONG)0x80000002)) -#define HKEY_USERS ((HKEY) (ULONG_PTR)((LONG)0x80000003)) -#define HKEY_PERFORMANCE_DATA ((HKEY) (ULONG_PTR)((LONG)0x80000004)) -#define HKEY_PERFORMANCE_TEXT ((HKEY) (ULONG_PTR)((LONG)0x80000050)) -#define HKEY_PERFORMANCE_NLSTEXT ((HKEY) (ULONG_PTR)((LONG)0x80000060)) -#define HKEY_CURRENT_CONFIG ((HKEY) (ULONG_PTR)((LONG)0x80000005)) -#define HKEY_DYN_DATA ((HKEY) (ULONG_PTR)((LONG)0x80000006)) - -#define REG_SECURE_CONNECTION 1 - -#ifndef _PROVIDER_STRUCTS_DEFINED -#define _PROVIDER_STRUCTS_DEFINED - -#define PROVIDER_KEEPS_VALUE_LENGTH 0x1 - struct val_context { - int valuelen; - LPVOID value_context; - LPVOID val_buff_ptr; - }; - - typedef struct val_context *PVALCONTEXT; - - typedef struct pvalueA { - LPSTR pv_valuename; - int pv_valuelen; - LPVOID pv_value_context; - DWORD pv_type; - }PVALUEA,*PPVALUEA; - - typedef struct pvalueW { - LPWSTR pv_valuename; - int pv_valuelen; - LPVOID pv_value_context; - DWORD pv_type; - }PVALUEW,*PPVALUEW; - -#ifdef UNICODE - typedef PVALUEW PVALUE; - typedef PPVALUEW PPVALUE; -#else - typedef PVALUEA PVALUE; - typedef PPVALUEA PPVALUE; -#endif - - typedef DWORD __cdecl QUERYHANDLER(LPVOID keycontext,PVALCONTEXT val_list,DWORD num_vals,LPVOID outputbuffer,DWORD *total_outlen,DWORD input_blen); - - typedef QUERYHANDLER *PQUERYHANDLER; - - typedef struct provider_info { - PQUERYHANDLER pi_R0_1val; - PQUERYHANDLER pi_R0_allvals; - PQUERYHANDLER pi_R3_1val; - PQUERYHANDLER pi_R3_allvals; - DWORD pi_flags; - LPVOID pi_key_context; - } REG_PROVIDER; - - typedef struct provider_info *PPROVIDER; - - typedef struct value_entA { - LPSTR ve_valuename; - DWORD ve_valuelen; - DWORD_PTR ve_valueptr; - DWORD ve_type; - } VALENTA,*PVALENTA; - - typedef struct value_entW { - LPWSTR ve_valuename; - DWORD ve_valuelen; - DWORD_PTR ve_valueptr; - DWORD ve_type; - } VALENTW,*PVALENTW; - -#ifdef UNICODE - typedef VALENTW VALENT; - typedef PVALENTW PVALENT; -#else - typedef VALENTA VALENT; - typedef PVALENTA PVALENT; -#endif -#endif - -#define WIN31_CLASS NULL - -#ifdef UNICODE -#define RegConnectRegistry RegConnectRegistryW -#define RegConnectRegistryEx RegConnectRegistryExW -#define RegCreateKey RegCreateKeyW -#define RegCreateKeyEx RegCreateKeyExW -#define RegDeleteKey RegDeleteKeyW -#define RegDeleteKeyEx RegDeleteKeyExW -#define RegDeleteValue RegDeleteValueW -#define RegEnumKey RegEnumKeyW -#define RegEnumKeyEx RegEnumKeyExW -#define RegEnumValue RegEnumValueW -#define RegLoadKey RegLoadKeyW -#define RegOpenKey RegOpenKeyW -#define RegOpenKeyEx RegOpenKeyExW -#define RegQueryInfoKey RegQueryInfoKeyW -#define RegQueryValue RegQueryValueW -#define RegQueryMultipleValues RegQueryMultipleValuesW -#define RegQueryValueEx RegQueryValueExW -#define RegReplaceKey RegReplaceKeyW -#define RegRestoreKey RegRestoreKeyW -#define RegSaveKey RegSaveKeyW -#define RegSetValue RegSetValueW -#define RegSetValueEx RegSetValueExW -#define RegUnLoadKey RegUnLoadKeyW -#define RegGetValue RegGetValueW -#define InitiateSystemShutdown InitiateSystemShutdownW -#define AbortSystemShutdown AbortSystemShutdownW -#else -#define RegConnectRegistry RegConnectRegistryA -#define RegConnectRegistryEx RegConnectRegistryExA -#define RegCreateKey RegCreateKeyA -#define RegCreateKeyEx RegCreateKeyExA -#define RegDeleteKey RegDeleteKeyA -#define RegDeleteKeyEx RegDeleteKeyExA -#define RegDeleteValue RegDeleteValueA -#define RegEnumKey RegEnumKeyA -#define RegEnumKeyEx RegEnumKeyExA -#define RegEnumValue RegEnumValueA -#define RegLoadKey RegLoadKeyA -#define RegOpenKey RegOpenKeyA -#define RegOpenKeyEx RegOpenKeyExA -#define RegQueryInfoKey RegQueryInfoKeyA -#define RegQueryValue RegQueryValueA -#define RegQueryMultipleValues RegQueryMultipleValuesA -#define RegQueryValueEx RegQueryValueExA -#define RegReplaceKey RegReplaceKeyA -#define RegRestoreKey RegRestoreKeyA -#define RegSaveKey RegSaveKeyA -#define RegSetValue RegSetValueA -#define RegSetValueEx RegSetValueExA -#define RegUnLoadKey RegUnLoadKeyA -#define RegGetValue RegGetValueA -#define InitiateSystemShutdown InitiateSystemShutdownA -#define AbortSystemShutdown AbortSystemShutdownA -#endif - - WINADVAPI LONG WINAPI RegCloseKey(HKEY hKey); - WINADVAPI LONG WINAPI RegOverridePredefKey(HKEY hKey,HKEY hNewHKey); - WINADVAPI LONG WINAPI RegOpenUserClassesRoot(HANDLE hToken,DWORD dwOptions,REGSAM samDesired,PHKEY phkResult); - WINADVAPI LONG WINAPI RegOpenCurrentUser(REGSAM samDesired,PHKEY phkResult); - WINADVAPI LONG WINAPI RegDisablePredefinedCache(); - WINADVAPI LONG WINAPI RegConnectRegistryA(LPCSTR lpMachineName,HKEY hKey,PHKEY phkResult); - WINADVAPI LONG WINAPI RegConnectRegistryW(LPCWSTR lpMachineName,HKEY hKey,PHKEY phkResult); - WINADVAPI LONG WINAPI RegConnectRegistryExA(LPCSTR lpMachineName,HKEY hKey,ULONG Flags,PHKEY phkResult); - WINADVAPI LONG WINAPI RegConnectRegistryExW(LPCWSTR lpMachineName,HKEY hKey,ULONG Flags,PHKEY phkResult); - WINADVAPI LONG WINAPI RegCreateKeyA(HKEY hKey,LPCSTR lpSubKey,PHKEY phkResult); - WINADVAPI LONG WINAPI RegCreateKeyW(HKEY hKey,LPCWSTR lpSubKey,PHKEY phkResult); - WINADVAPI LONG WINAPI RegCreateKeyExA(HKEY hKey,LPCSTR lpSubKey,DWORD Reserved,LPSTR lpClass,DWORD dwOptions,REGSAM samDesired,LPSECURITY_ATTRIBUTES lpSecurityAttributes,PHKEY phkResult,LPDWORD lpdwDisposition); - WINADVAPI LONG WINAPI RegCreateKeyExW(HKEY hKey,LPCWSTR lpSubKey,DWORD Reserved,LPWSTR lpClass,DWORD dwOptions,REGSAM samDesired,LPSECURITY_ATTRIBUTES lpSecurityAttributes,PHKEY phkResult,LPDWORD lpdwDisposition); - WINADVAPI LONG WINAPI RegDeleteKeyA(HKEY hKey,LPCSTR lpSubKey); - WINADVAPI LONG WINAPI RegDeleteKeyW(HKEY hKey,LPCWSTR lpSubKey); - WINADVAPI LONG WINAPI RegDeleteKeyExA(HKEY hKey,LPCSTR lpSubKey,REGSAM samDesired,DWORD Reserved); - WINADVAPI LONG WINAPI RegDeleteKeyExW(HKEY hKey,LPCWSTR lpSubKey,REGSAM samDesired,DWORD Reserved); - WINADVAPI LONG WINAPI RegDisableReflectionKey(HKEY hBase); - WINADVAPI LONG WINAPI RegEnableReflectionKey(HKEY hBase); - WINADVAPI LONG WINAPI RegQueryReflectionKey(HKEY hBase,WINBOOL *bIsReflectionDisabled); - WINADVAPI LONG WINAPI RegDeleteValueA(HKEY hKey,LPCSTR lpValueName); - WINADVAPI LONG WINAPI RegDeleteValueW(HKEY hKey,LPCWSTR lpValueName); - WINADVAPI LONG WINAPI RegEnumKeyA(HKEY hKey,DWORD dwIndex,LPSTR lpName,DWORD cchName); - WINADVAPI LONG WINAPI RegEnumKeyW(HKEY hKey,DWORD dwIndex,LPWSTR lpName,DWORD cchName); - WINADVAPI LONG WINAPI RegEnumKeyExA(HKEY hKey,DWORD dwIndex,LPSTR lpName,LPDWORD lpcchName,LPDWORD lpReserved,LPSTR lpClass,LPDWORD lpcchClass,PFILETIME lpftLastWriteTime); - WINADVAPI LONG WINAPI RegEnumKeyExW(HKEY hKey,DWORD dwIndex,LPWSTR lpName,LPDWORD lpcchName,LPDWORD lpReserved,LPWSTR lpClass,LPDWORD lpcchClass,PFILETIME lpftLastWriteTime); - WINADVAPI LONG WINAPI RegEnumValueA(HKEY hKey,DWORD dwIndex,LPSTR lpValueName,LPDWORD lpcchValueName,LPDWORD lpReserved,LPDWORD lpType,LPBYTE lpData,LPDWORD lpcbData); - WINADVAPI LONG WINAPI RegEnumValueW(HKEY hKey,DWORD dwIndex,LPWSTR lpValueName,LPDWORD lpcchValueName,LPDWORD lpReserved,LPDWORD lpType,LPBYTE lpData,LPDWORD lpcbData); - WINADVAPI LONG WINAPI RegFlushKey(HKEY hKey); - WINADVAPI LONG WINAPI RegGetKeySecurity(HKEY hKey,SECURITY_INFORMATION SecurityInformation,PSECURITY_DESCRIPTOR pSecurityDescriptor,LPDWORD lpcbSecurityDescriptor); - WINADVAPI LONG WINAPI RegLoadKeyA(HKEY hKey,LPCSTR lpSubKey,LPCSTR lpFile); - WINADVAPI LONG WINAPI RegLoadKeyW(HKEY hKey,LPCWSTR lpSubKey,LPCWSTR lpFile); - WINADVAPI LONG WINAPI RegNotifyChangeKeyValue(HKEY hKey,WINBOOL bWatchSubtree,DWORD dwNotifyFilter,HANDLE hEvent,WINBOOL fAsynchronous); - WINADVAPI LONG WINAPI RegOpenKeyA(HKEY hKey,LPCSTR lpSubKey,PHKEY phkResult); - WINADVAPI LONG WINAPI RegOpenKeyW(HKEY hKey,LPCWSTR lpSubKey,PHKEY phkResult); - WINADVAPI LONG WINAPI RegOpenKeyExA(HKEY hKey,LPCSTR lpSubKey,DWORD ulOptions,REGSAM samDesired,PHKEY phkResult); - WINADVAPI LONG WINAPI RegOpenKeyExW(HKEY hKey,LPCWSTR lpSubKey,DWORD ulOptions,REGSAM samDesired,PHKEY phkResult); - WINADVAPI LONG WINAPI RegQueryInfoKeyA(HKEY hKey,LPSTR lpClass,LPDWORD lpcchClass,LPDWORD lpReserved,LPDWORD lpcSubKeys,LPDWORD lpcbMaxSubKeyLen,LPDWORD lpcbMaxClassLen,LPDWORD lpcValues,LPDWORD lpcbMaxValueNameLen,LPDWORD lpcbMaxValueLen,LPDWORD lpcbSecurityDescriptor,PFILETIME lpftLastWriteTime); - WINADVAPI LONG WINAPI RegQueryInfoKeyW(HKEY hKey,LPWSTR lpClass,LPDWORD lpcchClass,LPDWORD lpReserved,LPDWORD lpcSubKeys,LPDWORD lpcbMaxSubKeyLen,LPDWORD lpcbMaxClassLen,LPDWORD lpcValues,LPDWORD lpcbMaxValueNameLen,LPDWORD lpcbMaxValueLen,LPDWORD lpcbSecurityDescriptor,PFILETIME lpftLastWriteTime); - WINADVAPI LONG WINAPI RegQueryValueA(HKEY hKey,LPCSTR lpSubKey,LPSTR lpData,PLONG lpcbData); - WINADVAPI LONG WINAPI RegQueryValueW(HKEY hKey,LPCWSTR lpSubKey,LPWSTR lpData,PLONG lpcbData); - WINADVAPI LONG WINAPI RegQueryMultipleValuesA(HKEY hKey,PVALENTA val_list,DWORD num_vals,LPSTR lpValueBuf,LPDWORD ldwTotsize); - WINADVAPI LONG WINAPI RegQueryMultipleValuesW(HKEY hKey,PVALENTW val_list,DWORD num_vals,LPWSTR lpValueBuf,LPDWORD ldwTotsize); - WINADVAPI LONG WINAPI RegQueryValueExA(HKEY hKey,LPCSTR lpValueName,LPDWORD lpReserved,LPDWORD lpType,LPBYTE lpData,LPDWORD lpcbData); - WINADVAPI LONG WINAPI RegQueryValueExW(HKEY hKey,LPCWSTR lpValueName,LPDWORD lpReserved,LPDWORD lpType,LPBYTE lpData,LPDWORD lpcbData); - WINADVAPI LONG WINAPI RegReplaceKeyA(HKEY hKey,LPCSTR lpSubKey,LPCSTR lpNewFile,LPCSTR lpOldFile); - WINADVAPI LONG WINAPI RegReplaceKeyW(HKEY hKey,LPCWSTR lpSubKey,LPCWSTR lpNewFile,LPCWSTR lpOldFile); - WINADVAPI LONG WINAPI RegRestoreKeyA(HKEY hKey,LPCSTR lpFile,DWORD dwFlags); - WINADVAPI LONG WINAPI RegRestoreKeyW(HKEY hKey,LPCWSTR lpFile,DWORD dwFlags); - WINADVAPI LONG WINAPI RegSaveKeyA(HKEY hKey,LPCSTR lpFile,LPSECURITY_ATTRIBUTES lpSecurityAttributes); - WINADVAPI LONG WINAPI RegSaveKeyW(HKEY hKey,LPCWSTR lpFile,LPSECURITY_ATTRIBUTES lpSecurityAttributes); - WINADVAPI LONG WINAPI RegSetKeySecurity(HKEY hKey,SECURITY_INFORMATION SecurityInformation,PSECURITY_DESCRIPTOR pSecurityDescriptor); - WINADVAPI LONG WINAPI RegSetValueA(HKEY hKey,LPCSTR lpSubKey,DWORD dwType,LPCSTR lpData,DWORD cbData); - WINADVAPI LONG WINAPI RegSetValueW(HKEY hKey,LPCWSTR lpSubKey,DWORD dwType,LPCWSTR lpData,DWORD cbData); - WINADVAPI LONG WINAPI RegSetValueExA(HKEY hKey,LPCSTR lpValueName,DWORD Reserved,DWORD dwType,CONST BYTE *lpData,DWORD cbData); - WINADVAPI LONG WINAPI RegSetValueExW(HKEY hKey,LPCWSTR lpValueName,DWORD Reserved,DWORD dwType,CONST BYTE *lpData,DWORD cbData); - WINADVAPI LONG WINAPI RegUnLoadKeyA(HKEY hKey,LPCSTR lpSubKey); - WINADVAPI LONG WINAPI RegUnLoadKeyW(HKEY hKey,LPCWSTR lpSubKey); - WINADVAPI LONG WINAPI RegGetValueA(HKEY hkey,LPCSTR lpSubKey,LPCSTR lpValue,DWORD dwFlags,LPDWORD pdwType,PVOID pvData,LPDWORD pcbData); - WINADVAPI LONG WINAPI RegGetValueW(HKEY hkey,LPCWSTR lpSubKey,LPCWSTR lpValue,DWORD dwFlags,LPDWORD pdwType,PVOID pvData,LPDWORD pcbData); - WINADVAPI WINBOOL WINAPI InitiateSystemShutdownA(LPSTR lpMachineName,LPSTR lpMessage,DWORD dwTimeout,WINBOOL bForceAppsClosed,WINBOOL bRebootAfterShutdown); - WINADVAPI WINBOOL WINAPI InitiateSystemShutdownW(LPWSTR lpMachineName,LPWSTR lpMessage,DWORD dwTimeout,WINBOOL bForceAppsClosed,WINBOOL bRebootAfterShutdown); - WINADVAPI WINBOOL WINAPI AbortSystemShutdownA(LPSTR lpMachineName); - WINADVAPI WINBOOL WINAPI AbortSystemShutdownW(LPWSTR lpMachineName); - -//gr #include - -#define REASON_SWINSTALL SHTDN_REASON_MAJOR_SOFTWARE|SHTDN_REASON_MINOR_INSTALLATION -#define REASON_HWINSTALL SHTDN_REASON_MAJOR_HARDWARE|SHTDN_REASON_MINOR_INSTALLATION -#define REASON_SERVICEHANG SHTDN_REASON_MAJOR_SOFTWARE|SHTDN_REASON_MINOR_HUNG -#define REASON_UNSTABLE SHTDN_REASON_MAJOR_SYSTEM|SHTDN_REASON_MINOR_UNSTABLE -#define REASON_SWHWRECONF SHTDN_REASON_MAJOR_SOFTWARE|SHTDN_REASON_MINOR_RECONFIG -#define REASON_OTHER SHTDN_REASON_MAJOR_OTHER|SHTDN_REASON_MINOR_OTHER -#define REASON_UNKNOWN SHTDN_REASON_UNKNOWN -#define REASON_LEGACY_API SHTDN_REASON_LEGACY_API -#define REASON_PLANNED_FLAG SHTDN_REASON_FLAG_PLANNED - -#define MAX_SHUTDOWN_TIMEOUT (10*365*24*60*60) - -#ifdef UNICODE -#define InitiateSystemShutdownEx InitiateSystemShutdownExW -#define RegSaveKeyEx RegSaveKeyExW -#else -#define InitiateSystemShutdownEx InitiateSystemShutdownExA -#define RegSaveKeyEx RegSaveKeyExA -#endif - - WINADVAPI WINBOOL WINAPI InitiateSystemShutdownExA(LPSTR lpMachineName,LPSTR lpMessage,DWORD dwTimeout,WINBOOL bForceAppsClosed,WINBOOL bRebootAfterShutdown,DWORD dwReason); - WINADVAPI WINBOOL WINAPI InitiateSystemShutdownExW(LPWSTR lpMachineName,LPWSTR lpMessage,DWORD dwTimeout,WINBOOL bForceAppsClosed,WINBOOL bRebootAfterShutdown,DWORD dwReason); - WINADVAPI LONG WINAPI RegSaveKeyExA(HKEY hKey,LPCSTR lpFile,LPSECURITY_ATTRIBUTES lpSecurityAttributes,DWORD Flags); - WINADVAPI LONG WINAPI RegSaveKeyExW(HKEY hKey,LPCWSTR lpFile,LPSECURITY_ATTRIBUTES lpSecurityAttributes,DWORD Flags); - WINADVAPI LONG WINAPI Wow64Win32ApiEntry (DWORD dwFuncNumber,DWORD dwFlag,DWORD dwRes); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/05/tcc-final-old/win32/include/winapi/winuser.h b/05/tcc-final-old/win32/include/winapi/winuser.h deleted file mode 100644 index 4cd9ffb..0000000 --- a/05/tcc-final-old/win32/include/winapi/winuser.h +++ /dev/null @@ -1,5651 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _WINUSER_ -#define _WINUSER_ - -#define WINUSERAPI DECLSPEC_IMPORT - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef WINVER -#define WINVER 0x0502 -#endif - -#include - -#ifndef NOUSER - typedef HANDLE HDWP; - typedef VOID MENUTEMPLATEA; - typedef VOID MENUTEMPLATEW; - typedef PVOID LPMENUTEMPLATEA; - typedef PVOID LPMENUTEMPLATEW; - -#ifdef UNICODE - typedef MENUTEMPLATEW MENUTEMPLATE; - typedef LPMENUTEMPLATEW LPMENUTEMPLATE; -#else - typedef MENUTEMPLATEA MENUTEMPLATE; - typedef LPMENUTEMPLATEA LPMENUTEMPLATE; -#endif - - typedef LRESULT (CALLBACK *WNDPROC)(HWND,UINT,WPARAM,LPARAM); - typedef INT_PTR (CALLBACK *DLGPROC)(HWND,UINT,WPARAM,LPARAM); - typedef VOID (CALLBACK *TIMERPROC)(HWND,UINT,UINT_PTR,DWORD); - typedef WINBOOL (CALLBACK *GRAYSTRINGPROC)(HDC,LPARAM,int); - typedef WINBOOL (CALLBACK *WNDENUMPROC)(HWND,LPARAM); - typedef LRESULT (CALLBACK *HOOKPROC)(int code,WPARAM wParam,LPARAM lParam); - typedef VOID (CALLBACK *SENDASYNCPROC)(HWND,UINT,ULONG_PTR,LRESULT); - typedef WINBOOL (CALLBACK *PROPENUMPROCA)(HWND,LPCSTR,HANDLE); - typedef WINBOOL (CALLBACK *PROPENUMPROCW)(HWND,LPCWSTR,HANDLE); - typedef WINBOOL (CALLBACK *PROPENUMPROCEXA)(HWND,LPSTR,HANDLE,ULONG_PTR); - typedef WINBOOL (CALLBACK *PROPENUMPROCEXW)(HWND,LPWSTR,HANDLE,ULONG_PTR); - typedef int (CALLBACK *EDITWORDBREAKPROCA)(LPSTR lpch,int ichCurrent,int cch,int code); - typedef int (CALLBACK *EDITWORDBREAKPROCW)(LPWSTR lpch,int ichCurrent,int cch,int code); - typedef WINBOOL (CALLBACK *DRAWSTATEPROC)(HDC hdc,LPARAM lData,WPARAM wData,int cx,int cy); - -#ifdef UNICODE - typedef PROPENUMPROCW PROPENUMPROC; - typedef PROPENUMPROCEXW PROPENUMPROCEX; - typedef EDITWORDBREAKPROCW EDITWORDBREAKPROC; -#else - typedef PROPENUMPROCA PROPENUMPROC; - typedef PROPENUMPROCEXA PROPENUMPROCEX; - typedef EDITWORDBREAKPROCA EDITWORDBREAKPROC; -#endif - - typedef WINBOOL (CALLBACK *NAMEENUMPROCA)(LPSTR,LPARAM); - typedef WINBOOL (CALLBACK *NAMEENUMPROCW)(LPWSTR,LPARAM); - typedef NAMEENUMPROCA WINSTAENUMPROCA; - typedef NAMEENUMPROCA DESKTOPENUMPROCA; - typedef NAMEENUMPROCW WINSTAENUMPROCW; - typedef NAMEENUMPROCW DESKTOPENUMPROCW; - -#ifdef UNICODE - typedef WINSTAENUMPROCW WINSTAENUMPROC; - typedef DESKTOPENUMPROCW DESKTOPENUMPROC; -#else - typedef WINSTAENUMPROCA WINSTAENUMPROC; - typedef DESKTOPENUMPROCA DESKTOPENUMPROC; -#endif - -#define IS_INTRESOURCE(_r) ((((ULONG_PTR)(_r)) >> 16)==0) -#define MAKEINTRESOURCEA(i) ((LPSTR)((ULONG_PTR)((WORD)(i)))) -#define MAKEINTRESOURCEW(i) ((LPWSTR)((ULONG_PTR)((WORD)(i)))) -#ifdef UNICODE -#define MAKEINTRESOURCE MAKEINTRESOURCEW -#else -#define MAKEINTRESOURCE MAKEINTRESOURCEA -#endif - -#ifndef NORESOURCE - -#define RT_CURSOR MAKEINTRESOURCE(1) -#define RT_BITMAP MAKEINTRESOURCE(2) -#define RT_ICON MAKEINTRESOURCE(3) -#define RT_MENU MAKEINTRESOURCE(4) -#define RT_DIALOG MAKEINTRESOURCE(5) -#define RT_STRING MAKEINTRESOURCE(6) -#define RT_FONTDIR MAKEINTRESOURCE(7) -#define RT_FONT MAKEINTRESOURCE(8) -#define RT_ACCELERATOR MAKEINTRESOURCE(9) -#define RT_RCDATA MAKEINTRESOURCE(10) -#define RT_MESSAGETABLE MAKEINTRESOURCE(11) - -#define DIFFERENCE 11 -#define RT_GROUP_CURSOR MAKEINTRESOURCE((ULONG_PTR)RT_CURSOR + DIFFERENCE) -#define RT_GROUP_ICON MAKEINTRESOURCE((ULONG_PTR)RT_ICON + DIFFERENCE) -#define RT_VERSION MAKEINTRESOURCE(16) -#define RT_DLGINCLUDE MAKEINTRESOURCE(17) -#define RT_PLUGPLAY MAKEINTRESOURCE(19) -#define RT_VXD MAKEINTRESOURCE(20) -#define RT_ANICURSOR MAKEINTRESOURCE(21) -#define RT_ANIICON MAKEINTRESOURCE(22) -#define RT_HTML MAKEINTRESOURCE(23) -#ifdef RC_INVOKED -#define RT_MANIFEST 24 -#define CREATEPROCESS_MANIFEST_RESOURCE_ID 1 -#define ISOLATIONAWARE_MANIFEST_RESOURCE_ID 2 -#define ISOLATIONAWARE_NOSTATICIMPORT_MANIFEST_RESOURCE_ID 3 -#define MINIMUM_RESERVED_MANIFEST_RESOURCE_ID 1 -#define MAXIMUM_RESERVED_MANIFEST_RESOURCE_ID 16 -#else -#define RT_MANIFEST MAKEINTRESOURCE(24) -#define CREATEPROCESS_MANIFEST_RESOURCE_ID MAKEINTRESOURCE(1) -#define ISOLATIONAWARE_MANIFEST_RESOURCE_ID MAKEINTRESOURCE(2) -#define ISOLATIONAWARE_NOSTATICIMPORT_MANIFEST_RESOURCE_ID MAKEINTRESOURCE(3) -#define MINIMUM_RESERVED_MANIFEST_RESOURCE_ID MAKEINTRESOURCE(1) -#define MAXIMUM_RESERVED_MANIFEST_RESOURCE_ID MAKEINTRESOURCE(16) -#endif -#endif - -#ifdef UNICODE -#define wvsprintf wvsprintfW -#define wsprintf wsprintfW -#else -#define wvsprintf wvsprintfA -#define wsprintf wsprintfA -#endif - - WINUSERAPI int WINAPI wvsprintfA(LPSTR,LPCSTR,va_list arglist); - WINUSERAPI int WINAPI wvsprintfW(LPWSTR,LPCWSTR,va_list arglist); - WINUSERAPI int WINAPIV wsprintfA(LPSTR,LPCSTR,...); - WINUSERAPI int WINAPIV wsprintfW(LPWSTR,LPCWSTR,...); - -#define SETWALLPAPER_DEFAULT ((LPWSTR)-1) - -#ifndef NOSCROLL -#define SB_HORZ 0 -#define SB_VERT 1 -#define SB_CTL 2 -#define SB_BOTH 3 - -#define SB_LINEUP 0 -#define SB_LINELEFT 0 -#define SB_LINEDOWN 1 -#define SB_LINERIGHT 1 -#define SB_PAGEUP 2 -#define SB_PAGELEFT 2 -#define SB_PAGEDOWN 3 -#define SB_PAGERIGHT 3 -#define SB_THUMBPOSITION 4 -#define SB_THUMBTRACK 5 -#define SB_TOP 6 -#define SB_LEFT 6 -#define SB_BOTTOM 7 -#define SB_RIGHT 7 -#define SB_ENDSCROLL 8 -#endif - -#ifndef NOSHOWWINDOW -#define SW_HIDE 0 -#define SW_SHOWNORMAL 1 -#define SW_NORMAL 1 -#define SW_SHOWMINIMIZED 2 -#define SW_SHOWMAXIMIZED 3 -#define SW_MAXIMIZE 3 -#define SW_SHOWNOACTIVATE 4 -#define SW_SHOW 5 -#define SW_MINIMIZE 6 -#define SW_SHOWMINNOACTIVE 7 -#define SW_SHOWNA 8 -#define SW_RESTORE 9 -#define SW_SHOWDEFAULT 10 -#define SW_FORCEMINIMIZE 11 -#define SW_MAX 11 - -#define HIDE_WINDOW 0 -#define SHOW_OPENWINDOW 1 -#define SHOW_ICONWINDOW 2 -#define SHOW_FULLSCREEN 3 -#define SHOW_OPENNOACTIVATE 4 - -#define SW_PARENTCLOSING 1 -#define SW_OTHERZOOM 2 -#define SW_PARENTOPENING 3 -#define SW_OTHERUNZOOM 4 -#endif - -#define AW_HOR_POSITIVE 0x00000001 -#define AW_HOR_NEGATIVE 0x00000002 -#define AW_VER_POSITIVE 0x00000004 -#define AW_VER_NEGATIVE 0x00000008 -#define AW_CENTER 0x00000010 -#define AW_HIDE 0x00010000 -#define AW_ACTIVATE 0x00020000 -#define AW_SLIDE 0x00040000 -#define AW_BLEND 0x00080000 - -#define KF_EXTENDED 0x0100 -#define KF_DLGMODE 0x0800 -#define KF_MENUMODE 0x1000 -#define KF_ALTDOWN 0x2000 -#define KF_REPEAT 0x4000 -#define KF_UP 0x8000 - -#ifndef NOVIRTUALKEYCODES - -#define VK_LBUTTON 0x01 -#define VK_RBUTTON 0x02 -#define VK_CANCEL 0x03 -#define VK_MBUTTON 0x04 -#define VK_XBUTTON1 0x05 -#define VK_XBUTTON2 0x06 -#define VK_BACK 0x08 -#define VK_TAB 0x09 -#define VK_CLEAR 0x0C -#define VK_RETURN 0x0D -#define VK_SHIFT 0x10 -#define VK_CONTROL 0x11 -#define VK_MENU 0x12 -#define VK_PAUSE 0x13 -#define VK_CAPITAL 0x14 -#define VK_KANA 0x15 -#define VK_HANGEUL 0x15 -#define VK_HANGUL 0x15 -#define VK_JUNJA 0x17 -#define VK_FINAL 0x18 -#define VK_HANJA 0x19 -#define VK_KANJI 0x19 -#define VK_ESCAPE 0x1B -#define VK_CONVERT 0x1C -#define VK_NONCONVERT 0x1D -#define VK_ACCEPT 0x1E -#define VK_MODECHANGE 0x1F -#define VK_SPACE 0x20 -#define VK_PRIOR 0x21 -#define VK_NEXT 0x22 -#define VK_END 0x23 -#define VK_HOME 0x24 -#define VK_LEFT 0x25 -#define VK_UP 0x26 -#define VK_RIGHT 0x27 -#define VK_DOWN 0x28 -#define VK_SELECT 0x29 -#define VK_PRINT 0x2A -#define VK_EXECUTE 0x2B -#define VK_SNAPSHOT 0x2C -#define VK_INSERT 0x2D -#define VK_DELETE 0x2E -#define VK_HELP 0x2F - -#define VK_LWIN 0x5B -#define VK_RWIN 0x5C -#define VK_APPS 0x5D -#define VK_SLEEP 0x5F -#define VK_NUMPAD0 0x60 -#define VK_NUMPAD1 0x61 -#define VK_NUMPAD2 0x62 -#define VK_NUMPAD3 0x63 -#define VK_NUMPAD4 0x64 -#define VK_NUMPAD5 0x65 -#define VK_NUMPAD6 0x66 -#define VK_NUMPAD7 0x67 -#define VK_NUMPAD8 0x68 -#define VK_NUMPAD9 0x69 -#define VK_MULTIPLY 0x6A -#define VK_ADD 0x6B -#define VK_SEPARATOR 0x6C -#define VK_SUBTRACT 0x6D -#define VK_DECIMAL 0x6E -#define VK_DIVIDE 0x6F -#define VK_F1 0x70 -#define VK_F2 0x71 -#define VK_F3 0x72 -#define VK_F4 0x73 -#define VK_F5 0x74 -#define VK_F6 0x75 -#define VK_F7 0x76 -#define VK_F8 0x77 -#define VK_F9 0x78 -#define VK_F10 0x79 -#define VK_F11 0x7A -#define VK_F12 0x7B -#define VK_F13 0x7C -#define VK_F14 0x7D -#define VK_F15 0x7E -#define VK_F16 0x7F -#define VK_F17 0x80 -#define VK_F18 0x81 -#define VK_F19 0x82 -#define VK_F20 0x83 -#define VK_F21 0x84 -#define VK_F22 0x85 -#define VK_F23 0x86 -#define VK_F24 0x87 -#define VK_NUMLOCK 0x90 -#define VK_SCROLL 0x91 -#define VK_OEM_NEC_EQUAL 0x92 -#define VK_OEM_FJ_JISHO 0x92 -#define VK_OEM_FJ_MASSHOU 0x93 -#define VK_OEM_FJ_TOUROKU 0x94 -#define VK_OEM_FJ_LOYA 0x95 -#define VK_OEM_FJ_ROYA 0x96 -#define VK_LSHIFT 0xA0 -#define VK_RSHIFT 0xA1 -#define VK_LCONTROL 0xA2 -#define VK_RCONTROL 0xA3 -#define VK_LMENU 0xA4 -#define VK_RMENU 0xA5 -#define VK_BROWSER_BACK 0xA6 -#define VK_BROWSER_FORWARD 0xA7 -#define VK_BROWSER_REFRESH 0xA8 -#define VK_BROWSER_STOP 0xA9 -#define VK_BROWSER_SEARCH 0xAA -#define VK_BROWSER_FAVORITES 0xAB -#define VK_BROWSER_HOME 0xAC -#define VK_VOLUME_MUTE 0xAD -#define VK_VOLUME_DOWN 0xAE -#define VK_VOLUME_UP 0xAF -#define VK_MEDIA_NEXT_TRACK 0xB0 -#define VK_MEDIA_PREV_TRACK 0xB1 -#define VK_MEDIA_STOP 0xB2 -#define VK_MEDIA_PLAY_PAUSE 0xB3 -#define VK_LAUNCH_MAIL 0xB4 -#define VK_LAUNCH_MEDIA_SELECT 0xB5 -#define VK_LAUNCH_APP1 0xB6 -#define VK_LAUNCH_APP2 0xB7 -#define VK_OEM_1 0xBA -#define VK_OEM_PLUS 0xBB -#define VK_OEM_COMMA 0xBC -#define VK_OEM_MINUS 0xBD -#define VK_OEM_PERIOD 0xBE -#define VK_OEM_2 0xBF -#define VK_OEM_3 0xC0 -#define VK_OEM_4 0xDB -#define VK_OEM_5 0xDC -#define VK_OEM_6 0xDD -#define VK_OEM_7 0xDE -#define VK_OEM_8 0xDF -#define VK_OEM_AX 0xE1 -#define VK_OEM_102 0xE2 -#define VK_ICO_HELP 0xE3 -#define VK_ICO_00 0xE4 -#define VK_PROCESSKEY 0xE5 -#define VK_ICO_CLEAR 0xE6 -#define VK_PACKET 0xE7 -#define VK_OEM_RESET 0xE9 -#define VK_OEM_JUMP 0xEA -#define VK_OEM_PA1 0xEB -#define VK_OEM_PA2 0xEC -#define VK_OEM_PA3 0xED -#define VK_OEM_WSCTRL 0xEE -#define VK_OEM_CUSEL 0xEF -#define VK_OEM_ATTN 0xF0 -#define VK_OEM_FINISH 0xF1 -#define VK_OEM_COPY 0xF2 -#define VK_OEM_AUTO 0xF3 -#define VK_OEM_ENLW 0xF4 -#define VK_OEM_BACKTAB 0xF5 -#define VK_ATTN 0xF6 -#define VK_CRSEL 0xF7 -#define VK_EXSEL 0xF8 -#define VK_EREOF 0xF9 -#define VK_PLAY 0xFA -#define VK_ZOOM 0xFB -#define VK_NONAME 0xFC -#define VK_PA1 0xFD -#define VK_OEM_CLEAR 0xFE -#endif - -#ifndef NOWH - -#define WH_MIN (-1) -#define WH_MSGFILTER (-1) -#define WH_JOURNALRECORD 0 -#define WH_JOURNALPLAYBACK 1 -#define WH_KEYBOARD 2 -#define WH_GETMESSAGE 3 -#define WH_CALLWNDPROC 4 -#define WH_CBT 5 -#define WH_SYSMSGFILTER 6 -#define WH_MOUSE 7 -#define WH_HARDWARE 8 -#define WH_DEBUG 9 -#define WH_SHELL 10 -#define WH_FOREGROUNDIDLE 11 -#define WH_CALLWNDPROCRET 12 - -#define WH_KEYBOARD_LL 13 -#define WH_MOUSE_LL 14 - -#define WH_MAX 14 - -#define WH_MINHOOK WH_MIN -#define WH_MAXHOOK WH_MAX - -#define HC_ACTION 0 -#define HC_GETNEXT 1 -#define HC_SKIP 2 -#define HC_NOREMOVE 3 -#define HC_NOREM HC_NOREMOVE -#define HC_SYSMODALON 4 -#define HC_SYSMODALOFF 5 - -#define HCBT_MOVESIZE 0 -#define HCBT_MINMAX 1 -#define HCBT_QS 2 -#define HCBT_CREATEWND 3 -#define HCBT_DESTROYWND 4 -#define HCBT_ACTIVATE 5 -#define HCBT_CLICKSKIPPED 6 -#define HCBT_KEYSKIPPED 7 -#define HCBT_SYSCOMMAND 8 -#define HCBT_SETFOCUS 9 - - typedef struct tagCBT_CREATEWNDA { - struct tagCREATESTRUCTA *lpcs; - HWND hwndInsertAfter; - } CBT_CREATEWNDA,*LPCBT_CREATEWNDA; - - typedef struct tagCBT_CREATEWNDW { - struct tagCREATESTRUCTW *lpcs; - HWND hwndInsertAfter; - } CBT_CREATEWNDW,*LPCBT_CREATEWNDW; -#ifdef UNICODE - typedef CBT_CREATEWNDW CBT_CREATEWND; - typedef LPCBT_CREATEWNDW LPCBT_CREATEWND; -#else - typedef CBT_CREATEWNDA CBT_CREATEWND; - typedef LPCBT_CREATEWNDA LPCBT_CREATEWND; -#endif - - typedef struct tagCBTACTIVATESTRUCT - { - WINBOOL fMouse; - HWND hWndActive; - } CBTACTIVATESTRUCT,*LPCBTACTIVATESTRUCT; - - typedef struct tagWTSSESSION_NOTIFICATION { - DWORD cbSize; - DWORD dwSessionId; - - } WTSSESSION_NOTIFICATION,*PWTSSESSION_NOTIFICATION; - -#define WTS_CONSOLE_CONNECT 0x1 -#define WTS_CONSOLE_DISCONNECT 0x2 -#define WTS_REMOTE_CONNECT 0x3 -#define WTS_REMOTE_DISCONNECT 0x4 -#define WTS_SESSION_LOGON 0x5 -#define WTS_SESSION_LOGOFF 0x6 -#define WTS_SESSION_LOCK 0x7 -#define WTS_SESSION_UNLOCK 0x8 -#define WTS_SESSION_REMOTE_CONTROL 0x9 - -#define MSGF_DIALOGBOX 0 -#define MSGF_MESSAGEBOX 1 -#define MSGF_MENU 2 -#define MSGF_SCROLLBAR 5 -#define MSGF_NEXTWINDOW 6 -#define MSGF_MAX 8 -#define MSGF_USER 4096 - -#define HSHELL_WINDOWCREATED 1 -#define HSHELL_WINDOWDESTROYED 2 -#define HSHELL_ACTIVATESHELLWINDOW 3 - -#define HSHELL_WINDOWACTIVATED 4 -#define HSHELL_GETMINRECT 5 -#define HSHELL_REDRAW 6 -#define HSHELL_TASKMAN 7 -#define HSHELL_LANGUAGE 8 -#define HSHELL_SYSMENU 9 -#define HSHELL_ENDTASK 10 -#define HSHELL_ACCESSIBILITYSTATE 11 -#define HSHELL_APPCOMMAND 12 -#define HSHELL_WINDOWREPLACED 13 -#define HSHELL_WINDOWREPLACING 14 -#define HSHELL_HIGHBIT 0x8000 -#define HSHELL_FLASH (HSHELL_REDRAW|HSHELL_HIGHBIT) -#define HSHELL_RUDEAPPACTIVATED (HSHELL_WINDOWACTIVATED|HSHELL_HIGHBIT) - -#define ACCESS_STICKYKEYS 0x0001 -#define ACCESS_FILTERKEYS 0x0002 -#define ACCESS_MOUSEKEYS 0x0003 - -#define APPCOMMAND_BROWSER_BACKWARD 1 -#define APPCOMMAND_BROWSER_FORWARD 2 -#define APPCOMMAND_BROWSER_REFRESH 3 -#define APPCOMMAND_BROWSER_STOP 4 -#define APPCOMMAND_BROWSER_SEARCH 5 -#define APPCOMMAND_BROWSER_FAVORITES 6 -#define APPCOMMAND_BROWSER_HOME 7 -#define APPCOMMAND_VOLUME_MUTE 8 -#define APPCOMMAND_VOLUME_DOWN 9 -#define APPCOMMAND_VOLUME_UP 10 -#define APPCOMMAND_MEDIA_NEXTTRACK 11 -#define APPCOMMAND_MEDIA_PREVIOUSTRACK 12 -#define APPCOMMAND_MEDIA_STOP 13 -#define APPCOMMAND_MEDIA_PLAY_PAUSE 14 -#define APPCOMMAND_LAUNCH_MAIL 15 -#define APPCOMMAND_LAUNCH_MEDIA_SELECT 16 -#define APPCOMMAND_LAUNCH_APP1 17 -#define APPCOMMAND_LAUNCH_APP2 18 -#define APPCOMMAND_BASS_DOWN 19 -#define APPCOMMAND_BASS_BOOST 20 -#define APPCOMMAND_BASS_UP 21 -#define APPCOMMAND_TREBLE_DOWN 22 -#define APPCOMMAND_TREBLE_UP 23 -#define APPCOMMAND_MICROPHONE_VOLUME_MUTE 24 -#define APPCOMMAND_MICROPHONE_VOLUME_DOWN 25 -#define APPCOMMAND_MICROPHONE_VOLUME_UP 26 -#define APPCOMMAND_HELP 27 -#define APPCOMMAND_FIND 28 -#define APPCOMMAND_NEW 29 -#define APPCOMMAND_OPEN 30 -#define APPCOMMAND_CLOSE 31 -#define APPCOMMAND_SAVE 32 -#define APPCOMMAND_PRINT 33 -#define APPCOMMAND_UNDO 34 -#define APPCOMMAND_REDO 35 -#define APPCOMMAND_COPY 36 -#define APPCOMMAND_CUT 37 -#define APPCOMMAND_PASTE 38 -#define APPCOMMAND_REPLY_TO_MAIL 39 -#define APPCOMMAND_FORWARD_MAIL 40 -#define APPCOMMAND_SEND_MAIL 41 -#define APPCOMMAND_SPELL_CHECK 42 -#define APPCOMMAND_DICTATE_OR_COMMAND_CONTROL_TOGGLE 43 -#define APPCOMMAND_MIC_ON_OFF_TOGGLE 44 -#define APPCOMMAND_CORRECTION_LIST 45 -#define APPCOMMAND_MEDIA_PLAY 46 -#define APPCOMMAND_MEDIA_PAUSE 47 -#define APPCOMMAND_MEDIA_RECORD 48 -#define APPCOMMAND_MEDIA_FAST_FORWARD 49 -#define APPCOMMAND_MEDIA_REWIND 50 -#define APPCOMMAND_MEDIA_CHANNEL_UP 51 -#define APPCOMMAND_MEDIA_CHANNEL_DOWN 52 - -#define FAPPCOMMAND_MOUSE 0x8000 -#define FAPPCOMMAND_KEY 0 -#define FAPPCOMMAND_OEM 0x1000 -#define FAPPCOMMAND_MASK 0xF000 - -#define GET_APPCOMMAND_LPARAM(lParam) ((short)(HIWORD(lParam) & ~FAPPCOMMAND_MASK)) -#define GET_DEVICE_LPARAM(lParam) ((WORD)(HIWORD(lParam) & FAPPCOMMAND_MASK)) -#define GET_MOUSEORKEY_LPARAM GET_DEVICE_LPARAM -#define GET_FLAGS_LPARAM(lParam) (LOWORD(lParam)) -#define GET_KEYSTATE_LPARAM(lParam) GET_FLAGS_LPARAM(lParam) - - typedef struct { - HWND hwnd; - RECT rc; - } SHELLHOOKINFO,*LPSHELLHOOKINFO; - - typedef struct tagEVENTMSG { - UINT message; - UINT paramL; - UINT paramH; - DWORD time; - HWND hwnd; - } EVENTMSG,*PEVENTMSGMSG,*NPEVENTMSGMSG,*LPEVENTMSGMSG; - - typedef struct tagEVENTMSG *PEVENTMSG,*NPEVENTMSG,*LPEVENTMSG; - - typedef struct tagCWPSTRUCT { - LPARAM lParam; - WPARAM wParam; - UINT message; - HWND hwnd; - } CWPSTRUCT,*PCWPSTRUCT,*NPCWPSTRUCT,*LPCWPSTRUCT; - - typedef struct tagCWPRETSTRUCT { - LRESULT lResult; - LPARAM lParam; - WPARAM wParam; - UINT message; - HWND hwnd; - } CWPRETSTRUCT,*PCWPRETSTRUCT,*NPCWPRETSTRUCT,*LPCWPRETSTRUCT; - -#define LLKHF_EXTENDED (KF_EXTENDED >> 8) -#define LLKHF_INJECTED 0x00000010 -#define LLKHF_ALTDOWN (KF_ALTDOWN >> 8) -#define LLKHF_UP (KF_UP >> 8) - -#define LLMHF_INJECTED 0x00000001 - - typedef struct tagKBDLLHOOKSTRUCT { - DWORD vkCode; - DWORD scanCode; - DWORD flags; - DWORD time; - ULONG_PTR dwExtraInfo; - } KBDLLHOOKSTRUCT,*LPKBDLLHOOKSTRUCT,*PKBDLLHOOKSTRUCT; - - typedef struct tagMSLLHOOKSTRUCT { - POINT pt; - DWORD mouseData; - DWORD flags; - DWORD time; - ULONG_PTR dwExtraInfo; - } MSLLHOOKSTRUCT,*LPMSLLHOOKSTRUCT,*PMSLLHOOKSTRUCT; - - typedef struct tagDEBUGHOOKINFO { - DWORD idThread; - DWORD idThreadInstaller; - LPARAM lParam; - WPARAM wParam; - int code; - } DEBUGHOOKINFO,*PDEBUGHOOKINFO,*NPDEBUGHOOKINFO,*LPDEBUGHOOKINFO; - - typedef struct tagMOUSEHOOKSTRUCT { - POINT pt; - HWND hwnd; - UINT wHitTestCode; - ULONG_PTR dwExtraInfo; - } MOUSEHOOKSTRUCT,*LPMOUSEHOOKSTRUCT,*PMOUSEHOOKSTRUCT; - -#ifdef __cplusplus - typedef struct tagMOUSEHOOKSTRUCTEX : public tagMOUSEHOOKSTRUCT { - DWORD mouseData; - } MOUSEHOOKSTRUCTEX,*LPMOUSEHOOKSTRUCTEX,*PMOUSEHOOKSTRUCTEX; -#else - typedef struct tagMOUSEHOOKSTRUCTEX { - MOUSEHOOKSTRUCT _unnamed; - DWORD mouseData; - } MOUSEHOOKSTRUCTEX,*LPMOUSEHOOKSTRUCTEX,*PMOUSEHOOKSTRUCTEX; -#endif - - typedef struct tagHARDWAREHOOKSTRUCT { - HWND hwnd; - UINT message; - WPARAM wParam; - LPARAM lParam; - } HARDWAREHOOKSTRUCT,*LPHARDWAREHOOKSTRUCT,*PHARDWAREHOOKSTRUCT; -#endif - -#define HKL_PREV 0 -#define HKL_NEXT 1 - -#define KLF_ACTIVATE 0x00000001 -#define KLF_SUBSTITUTE_OK 0x00000002 -#define KLF_REORDER 0x00000008 -#define KLF_REPLACELANG 0x00000010 -#define KLF_NOTELLSHELL 0x00000080 -#define KLF_SETFORPROCESS 0x00000100 -#define KLF_SHIFTLOCK 0x00010000 -#define KLF_RESET 0x40000000 - -#define INPUTLANGCHANGE_SYSCHARSET 0x0001 -#define INPUTLANGCHANGE_FORWARD 0x0002 -#define INPUTLANGCHANGE_BACKWARD 0x0004 - -#define KL_NAMELENGTH 9 - -#ifdef UNICODE -#define LoadKeyboardLayout LoadKeyboardLayoutW -#define GetKeyboardLayoutName GetKeyboardLayoutNameW -#else -#define LoadKeyboardLayout LoadKeyboardLayoutA -#define GetKeyboardLayoutName GetKeyboardLayoutNameA -#endif - - WINUSERAPI HKL WINAPI LoadKeyboardLayoutA(LPCSTR pwszKLID,UINT Flags); - WINUSERAPI HKL WINAPI LoadKeyboardLayoutW(LPCWSTR pwszKLID,UINT Flags); - WINUSERAPI HKL WINAPI ActivateKeyboardLayout(HKL hkl,UINT Flags); - WINUSERAPI int WINAPI ToUnicodeEx(UINT wVirtKey,UINT wScanCode,CONST BYTE *lpKeyState,LPWSTR pwszBuff,int cchBuff,UINT wFlags,HKL dwhkl); - WINUSERAPI WINBOOL WINAPI UnloadKeyboardLayout(HKL hkl); - WINUSERAPI WINBOOL WINAPI GetKeyboardLayoutNameA(LPSTR pwszKLID); - WINUSERAPI WINBOOL WINAPI GetKeyboardLayoutNameW(LPWSTR pwszKLID); - WINUSERAPI int WINAPI GetKeyboardLayoutList(int nBuff,HKL *lpList); - WINUSERAPI HKL WINAPI GetKeyboardLayout(DWORD idThread); - - typedef struct tagMOUSEMOVEPOINT { - int x; - int y; - DWORD time; - ULONG_PTR dwExtraInfo; - } MOUSEMOVEPOINT,*PMOUSEMOVEPOINT,*LPMOUSEMOVEPOINT; - -#define GMMP_USE_DISPLAY_POINTS 1 -#define GMMP_USE_HIGH_RESOLUTION_POINTS 2 - - WINUSERAPI int WINAPI GetMouseMovePointsEx(UINT cbSize,LPMOUSEMOVEPOINT lppt,LPMOUSEMOVEPOINT lpptBuf,int nBufPoints,DWORD resolution); - -#ifndef NODESKTOP - -#define DESKTOP_READOBJECTS 0x0001L -#define DESKTOP_CREATEWINDOW 0x0002L -#define DESKTOP_CREATEMENU 0x0004L -#define DESKTOP_HOOKCONTROL 0x0008L -#define DESKTOP_JOURNALRECORD 0x0010L -#define DESKTOP_JOURNALPLAYBACK 0x0020L -#define DESKTOP_ENUMERATE 0x0040L -#define DESKTOP_WRITEOBJECTS 0x0080L -#define DESKTOP_SWITCHDESKTOP 0x0100L - -#define DF_ALLOWOTHERACCOUNTHOOK 0x0001L - -#ifdef _WINGDI_ -#ifndef NOGDI -#ifdef UNICODE -#define CreateDesktop CreateDesktopW -#else -#define CreateDesktop CreateDesktopA -#endif - - WINUSERAPI HDESK WINAPI CreateDesktopA(LPCSTR lpszDesktop,LPCSTR lpszDevice,LPDEVMODEA pDevmode,DWORD dwFlags,ACCESS_MASK dwDesiredAccess,LPSECURITY_ATTRIBUTES lpsa); - WINUSERAPI HDESK WINAPI CreateDesktopW(LPCWSTR lpszDesktop,LPCWSTR lpszDevice,LPDEVMODEW pDevmode,DWORD dwFlags,ACCESS_MASK dwDesiredAccess,LPSECURITY_ATTRIBUTES lpsa); -#endif -#endif - -#ifdef UNICODE -#define OpenDesktop OpenDesktopW -#define EnumDesktops EnumDesktopsW -#else -#define OpenDesktop OpenDesktopA -#define EnumDesktops EnumDesktopsA -#endif - - WINUSERAPI HDESK WINAPI OpenDesktopA(LPCSTR lpszDesktop,DWORD dwFlags,WINBOOL fInherit,ACCESS_MASK dwDesiredAccess); - WINUSERAPI HDESK WINAPI OpenDesktopW(LPCWSTR lpszDesktop,DWORD dwFlags,WINBOOL fInherit,ACCESS_MASK dwDesiredAccess); - WINUSERAPI HDESK WINAPI OpenInputDesktop(DWORD dwFlags,WINBOOL fInherit,ACCESS_MASK dwDesiredAccess); - WINUSERAPI WINBOOL WINAPI EnumDesktopsA(HWINSTA hwinsta,DESKTOPENUMPROCA lpEnumFunc,LPARAM lParam); - WINUSERAPI WINBOOL WINAPI EnumDesktopsW(HWINSTA hwinsta,DESKTOPENUMPROCW lpEnumFunc,LPARAM lParam); - WINUSERAPI WINBOOL WINAPI EnumDesktopWindows(HDESK hDesktop,WNDENUMPROC lpfn,LPARAM lParam); - WINUSERAPI WINBOOL WINAPI SwitchDesktop(HDESK hDesktop); - WINUSERAPI WINBOOL WINAPI SetThreadDesktop(HDESK hDesktop); - WINUSERAPI WINBOOL WINAPI CloseDesktop(HDESK hDesktop); - WINUSERAPI HDESK WINAPI GetThreadDesktop(DWORD dwThreadId); -#endif - -#ifndef NOWINDOWSTATION -#define WINSTA_ENUMDESKTOPS 0x0001L -#define WINSTA_READATTRIBUTES 0x0002L -#define WINSTA_ACCESSCLIPBOARD 0x0004L -#define WINSTA_CREATEDESKTOP 0x0008L -#define WINSTA_WRITEATTRIBUTES 0x0010L -#define WINSTA_ACCESSGLOBALATOMS 0x0020L -#define WINSTA_EXITWINDOWS 0x0040L -#define WINSTA_ENUMERATE 0x0100L -#define WINSTA_READSCREEN 0x0200L -#define WINSTA_ALL_ACCESS (WINSTA_ENUMDESKTOPS | WINSTA_READATTRIBUTES | WINSTA_ACCESSCLIPBOARD | WINSTA_CREATEDESKTOP | WINSTA_WRITEATTRIBUTES | WINSTA_ACCESSGLOBALATOMS | WINSTA_EXITWINDOWS | WINSTA_ENUMERATE | WINSTA_READSCREEN) - -#define CWF_CREATE_ONLY 0x0001L - -#define WSF_VISIBLE 0x0001L - -#ifdef UNICODE -#define CreateWindowStation CreateWindowStationW -#define OpenWindowStation OpenWindowStationW -#define EnumWindowStations EnumWindowStationsW -#else -#define CreateWindowStation CreateWindowStationA -#define OpenWindowStation OpenWindowStationA -#define EnumWindowStations EnumWindowStationsA -#endif - - WINUSERAPI HWINSTA WINAPI CreateWindowStationA(LPCSTR lpwinsta,DWORD dwFlags,ACCESS_MASK dwDesiredAccess,LPSECURITY_ATTRIBUTES lpsa); - WINUSERAPI HWINSTA WINAPI CreateWindowStationW(LPCWSTR lpwinsta,DWORD dwFlags,ACCESS_MASK dwDesiredAccess,LPSECURITY_ATTRIBUTES lpsa); - WINUSERAPI HWINSTA WINAPI OpenWindowStationA(LPCSTR lpszWinSta,WINBOOL fInherit,ACCESS_MASK dwDesiredAccess); - WINUSERAPI HWINSTA WINAPI OpenWindowStationW(LPCWSTR lpszWinSta,WINBOOL fInherit,ACCESS_MASK dwDesiredAccess); - WINUSERAPI WINBOOL WINAPI EnumWindowStationsA(WINSTAENUMPROCA lpEnumFunc,LPARAM lParam); - WINUSERAPI WINBOOL WINAPI EnumWindowStationsW(WINSTAENUMPROCW lpEnumFunc,LPARAM lParam); - WINUSERAPI WINBOOL WINAPI CloseWindowStation(HWINSTA hWinSta); - WINUSERAPI WINBOOL WINAPI SetProcessWindowStation(HWINSTA hWinSta); - WINUSERAPI HWINSTA WINAPI GetProcessWindowStation(VOID); -#endif - -#ifndef NOSECURITY - WINUSERAPI WINBOOL WINAPI SetUserObjectSecurity(HANDLE hObj,PSECURITY_INFORMATION pSIRequested,PSECURITY_DESCRIPTOR pSID); - WINUSERAPI WINBOOL WINAPI GetUserObjectSecurity(HANDLE hObj,PSECURITY_INFORMATION pSIRequested,PSECURITY_DESCRIPTOR pSID,DWORD nLength,LPDWORD lpnLengthNeeded); - -#define UOI_FLAGS 1 -#define UOI_NAME 2 -#define UOI_TYPE 3 -#define UOI_USER_SID 4 - - typedef struct tagUSEROBJECTFLAGS { - WINBOOL fInherit; - WINBOOL fReserved; - DWORD dwFlags; - } USEROBJECTFLAGS,*PUSEROBJECTFLAGS; - -#ifdef UNICODE -#define GetUserObjectInformation GetUserObjectInformationW -#define SetUserObjectInformation SetUserObjectInformationW -#else -#define GetUserObjectInformation GetUserObjectInformationA -#define SetUserObjectInformation SetUserObjectInformationA -#endif - - WINUSERAPI WINBOOL WINAPI GetUserObjectInformationA(HANDLE hObj,int nIndex,PVOID pvInfo,DWORD nLength,LPDWORD lpnLengthNeeded); - WINUSERAPI WINBOOL WINAPI GetUserObjectInformationW(HANDLE hObj,int nIndex,PVOID pvInfo,DWORD nLength,LPDWORD lpnLengthNeeded); - WINUSERAPI WINBOOL WINAPI SetUserObjectInformationA(HANDLE hObj,int nIndex,PVOID pvInfo,DWORD nLength); - WINUSERAPI WINBOOL WINAPI SetUserObjectInformationW(HANDLE hObj,int nIndex,PVOID pvInfo,DWORD nLength); -#endif - - typedef struct tagWNDCLASSEXA { - UINT cbSize; - UINT style; - WNDPROC lpfnWndProc; - int cbClsExtra; - int cbWndExtra; - HINSTANCE hInstance; - HICON hIcon; - HCURSOR hCursor; - HBRUSH hbrBackground; - LPCSTR lpszMenuName; - LPCSTR lpszClassName; - HICON hIconSm; - } WNDCLASSEXA,*PWNDCLASSEXA,*NPWNDCLASSEXA,*LPWNDCLASSEXA; - - typedef struct tagWNDCLASSEXW { - UINT cbSize; - UINT style; - WNDPROC lpfnWndProc; - int cbClsExtra; - int cbWndExtra; - HINSTANCE hInstance; - HICON hIcon; - HCURSOR hCursor; - HBRUSH hbrBackground; - LPCWSTR lpszMenuName; - LPCWSTR lpszClassName; - - HICON hIconSm; - } WNDCLASSEXW,*PWNDCLASSEXW,*NPWNDCLASSEXW,*LPWNDCLASSEXW; - -#ifdef UNICODE - typedef WNDCLASSEXW WNDCLASSEX; - typedef PWNDCLASSEXW PWNDCLASSEX; - typedef NPWNDCLASSEXW NPWNDCLASSEX; - typedef LPWNDCLASSEXW LPWNDCLASSEX; -#else - typedef WNDCLASSEXA WNDCLASSEX; - typedef PWNDCLASSEXA PWNDCLASSEX; - typedef NPWNDCLASSEXA NPWNDCLASSEX; - typedef LPWNDCLASSEXA LPWNDCLASSEX; -#endif - - typedef struct tagWNDCLASSA { - UINT style; - WNDPROC lpfnWndProc; - int cbClsExtra; - int cbWndExtra; - HINSTANCE hInstance; - HICON hIcon; - HCURSOR hCursor; - HBRUSH hbrBackground; - LPCSTR lpszMenuName; - LPCSTR lpszClassName; - } WNDCLASSA,*PWNDCLASSA,*NPWNDCLASSA,*LPWNDCLASSA; - - typedef struct tagWNDCLASSW { - UINT style; - WNDPROC lpfnWndProc; - int cbClsExtra; - int cbWndExtra; - HINSTANCE hInstance; - HICON hIcon; - HCURSOR hCursor; - HBRUSH hbrBackground; - LPCWSTR lpszMenuName; - LPCWSTR lpszClassName; - } WNDCLASSW,*PWNDCLASSW,*NPWNDCLASSW,*LPWNDCLASSW; - -#ifdef UNICODE - typedef WNDCLASSW WNDCLASS; - typedef PWNDCLASSW PWNDCLASS; - typedef NPWNDCLASSW NPWNDCLASS; - typedef LPWNDCLASSW LPWNDCLASS; -#else - typedef WNDCLASSA WNDCLASS; - typedef PWNDCLASSA PWNDCLASS; - typedef NPWNDCLASSA NPWNDCLASS; - typedef LPWNDCLASSA LPWNDCLASS; -#endif - - WINUSERAPI WINBOOL WINAPI IsHungAppWindow(HWND hwnd); - WINUSERAPI VOID WINAPI DisableProcessWindowsGhosting(VOID); - -#ifndef NOMSG - typedef struct tagMSG { - HWND hwnd; - UINT message; - WPARAM wParam; - LPARAM lParam; - DWORD time; - POINT pt; - } MSG,*PMSG,*NPMSG,*LPMSG; - -#define POINTSTOPOINT(pt,pts) { (pt).x = (LONG)(SHORT)LOWORD(*(LONG*)&pts); (pt).y = (LONG)(SHORT)HIWORD(*(LONG*)&pts); } - -#define POINTTOPOINTS(pt) (MAKELONG((short)((pt).x),(short)((pt).y))) -#define MAKEWPARAM(l,h) ((WPARAM)(DWORD)MAKELONG(l,h)) -#define MAKELPARAM(l,h) ((LPARAM)(DWORD)MAKELONG(l,h)) -#define MAKELRESULT(l,h) ((LRESULT)(DWORD)MAKELONG(l,h)) -#endif - -#ifndef NOWINOFFSETS -#define GWL_WNDPROC (-4) -#define GWL_HINSTANCE (-6) -#define GWL_HWNDPARENT (-8) -#define GWL_STYLE (-16) -#define GWL_EXSTYLE (-20) -#define GWL_USERDATA (-21) -#define GWL_ID (-12) - -#ifdef _WIN64 -#undef GWL_WNDPROC -#undef GWL_HINSTANCE -#undef GWL_HWNDPARENT -#undef GWL_USERDATA -#endif - -#define GWLP_WNDPROC (-4) -#define GWLP_HINSTANCE (-6) -#define GWLP_HWNDPARENT (-8) -#define GWLP_USERDATA (-21) -#define GWLP_ID (-12) - -#define GCL_MENUNAME (-8) -#define GCL_HBRBACKGROUND (-10) -#define GCL_HCURSOR (-12) -#define GCL_HICON (-14) -#define GCL_HMODULE (-16) -#define GCL_CBWNDEXTRA (-18) -#define GCL_CBCLSEXTRA (-20) -#define GCL_WNDPROC (-24) -#define GCL_STYLE (-26) -#define GCW_ATOM (-32) -#define GCL_HICONSM (-34) - -#ifdef _WIN64 - -#undef GCL_MENUNAME -#undef GCL_HBRBACKGROUND -#undef GCL_HCURSOR -#undef GCL_HICON -#undef GCL_HMODULE -#undef GCL_WNDPROC -#undef GCL_HICONSM -#endif - -#define GCLP_MENUNAME (-8) -#define GCLP_HBRBACKGROUND (-10) -#define GCLP_HCURSOR (-12) -#define GCLP_HICON (-14) -#define GCLP_HMODULE (-16) -#define GCLP_WNDPROC (-24) -#define GCLP_HICONSM (-34) -#endif - -#ifndef NOWINMESSAGES - -#define WM_NULL 0x0000 -#define WM_CREATE 0x0001 -#define WM_DESTROY 0x0002 -#define WM_MOVE 0x0003 -#define WM_SIZE 0x0005 - -#define WM_ACTIVATE 0x0006 - -#define WA_INACTIVE 0 -#define WA_ACTIVE 1 -#define WA_CLICKACTIVE 2 - -#define WM_SETFOCUS 0x0007 -#define WM_KILLFOCUS 0x0008 -#define WM_ENABLE 0x000A -#define WM_SETREDRAW 0x000B -#define WM_SETTEXT 0x000C -#define WM_GETTEXT 0x000D -#define WM_GETTEXTLENGTH 0x000E -#define WM_PAINT 0x000F -#define WM_CLOSE 0x0010 -#ifndef _WIN32_WCE -#define WM_QUERYENDSESSION 0x0011 -#define WM_QUERYOPEN 0x0013 -#define WM_ENDSESSION 0x0016 -#endif -#define WM_QUIT 0x0012 -#define WM_ERASEBKGND 0x0014 -#define WM_SYSCOLORCHANGE 0x0015 -#define WM_SHOWWINDOW 0x0018 -#define WM_WININICHANGE 0x001A -#define WM_SETTINGCHANGE WM_WININICHANGE -#define WM_DEVMODECHANGE 0x001B -#define WM_ACTIVATEAPP 0x001C -#define WM_FONTCHANGE 0x001D -#define WM_TIMECHANGE 0x001E -#define WM_CANCELMODE 0x001F -#define WM_SETCURSOR 0x0020 -#define WM_MOUSEACTIVATE 0x0021 -#define WM_CHILDACTIVATE 0x0022 -#define WM_QUEUESYNC 0x0023 - -#define WM_GETMINMAXINFO 0x0024 - - typedef struct tagMINMAXINFO { - POINT ptReserved; - POINT ptMaxSize; - POINT ptMaxPosition; - POINT ptMinTrackSize; - POINT ptMaxTrackSize; - } MINMAXINFO,*PMINMAXINFO,*LPMINMAXINFO; - -#define WM_PAINTICON 0x0026 -#define WM_ICONERASEBKGND 0x0027 -#define WM_NEXTDLGCTL 0x0028 -#define WM_SPOOLERSTATUS 0x002A -#define WM_DRAWITEM 0x002B -#define WM_MEASUREITEM 0x002C -#define WM_DELETEITEM 0x002D -#define WM_VKEYTOITEM 0x002E -#define WM_CHARTOITEM 0x002F -#define WM_SETFONT 0x0030 -#define WM_GETFONT 0x0031 -#define WM_SETHOTKEY 0x0032 -#define WM_GETHOTKEY 0x0033 -#define WM_QUERYDRAGICON 0x0037 -#define WM_COMPAREITEM 0x0039 -#ifndef _WIN32_WCE -#define WM_GETOBJECT 0x003D -#endif -#define WM_COMPACTING 0x0041 -#define WM_COMMNOTIFY 0x0044 -#define WM_WINDOWPOSCHANGING 0x0046 -#define WM_WINDOWPOSCHANGED 0x0047 - -#define WM_POWER 0x0048 - -#define PWR_OK 1 -#define PWR_FAIL (-1) -#define PWR_SUSPENDREQUEST 1 -#define PWR_SUSPENDRESUME 2 -#define PWR_CRITICALRESUME 3 - -#define WM_COPYDATA 0x004A -#define WM_CANCELJOURNAL 0x004B - - typedef struct tagCOPYDATASTRUCT { - ULONG_PTR dwData; - DWORD cbData; - PVOID lpData; - } COPYDATASTRUCT,*PCOPYDATASTRUCT; - - typedef struct tagMDINEXTMENU { - HMENU hmenuIn; - HMENU hmenuNext; - HWND hwndNext; - } MDINEXTMENU,*PMDINEXTMENU,*LPMDINEXTMENU; - -#define WM_NOTIFY 0x004E -#define WM_INPUTLANGCHANGEREQUEST 0x0050 -#define WM_INPUTLANGCHANGE 0x0051 -#define WM_TCARD 0x0052 -#define WM_HELP 0x0053 -#define WM_USERCHANGED 0x0054 -#define WM_NOTIFYFORMAT 0x0055 - -#define NFR_ANSI 1 -#define NFR_UNICODE 2 -#define NF_QUERY 3 -#define NF_REQUERY 4 - -#define WM_CONTEXTMENU 0x007B -#define WM_STYLECHANGING 0x007C -#define WM_STYLECHANGED 0x007D -#define WM_DISPLAYCHANGE 0x007E -#define WM_GETICON 0x007F -#define WM_SETICON 0x0080 - -#define WM_NCCREATE 0x0081 -#define WM_NCDESTROY 0x0082 -#define WM_NCCALCSIZE 0x0083 -#define WM_NCHITTEST 0x0084 -#define WM_NCPAINT 0x0085 -#define WM_NCACTIVATE 0x0086 -#define WM_GETDLGCODE 0x0087 -#ifndef _WIN32_WCE -#define WM_SYNCPAINT 0x0088 -#endif -#define WM_NCMOUSEMOVE 0x00A0 -#define WM_NCLBUTTONDOWN 0x00A1 -#define WM_NCLBUTTONUP 0x00A2 -#define WM_NCLBUTTONDBLCLK 0x00A3 -#define WM_NCRBUTTONDOWN 0x00A4 -#define WM_NCRBUTTONUP 0x00A5 -#define WM_NCRBUTTONDBLCLK 0x00A6 -#define WM_NCMBUTTONDOWN 0x00A7 -#define WM_NCMBUTTONUP 0x00A8 -#define WM_NCMBUTTONDBLCLK 0x00A9 - -#define WM_NCXBUTTONDOWN 0x00AB -#define WM_NCXBUTTONUP 0x00AC -#define WM_NCXBUTTONDBLCLK 0x00AD -#define WM_INPUT 0x00FF -#define WM_KEYFIRST 0x0100 -#define WM_KEYDOWN 0x0100 -#define WM_KEYUP 0x0101 -#define WM_CHAR 0x0102 -#define WM_DEADCHAR 0x0103 -#define WM_SYSKEYDOWN 0x0104 -#define WM_SYSKEYUP 0x0105 -#define WM_SYSCHAR 0x0106 -#define WM_SYSDEADCHAR 0x0107 -#define WM_UNICHAR 0x0109 -#define WM_KEYLAST 0x0109 -#define UNICODE_NOCHAR 0xFFFF -#define WM_IME_STARTCOMPOSITION 0x010D -#define WM_IME_ENDCOMPOSITION 0x010E -#define WM_IME_COMPOSITION 0x010F -#define WM_IME_KEYLAST 0x010F -#define WM_INITDIALOG 0x0110 -#define WM_COMMAND 0x0111 -#define WM_SYSCOMMAND 0x0112 -#define WM_TIMER 0x0113 -#define WM_HSCROLL 0x0114 -#define WM_VSCROLL 0x0115 -#define WM_INITMENU 0x0116 -#define WM_INITMENUPOPUP 0x0117 -#define WM_MENUSELECT 0x011F -#define WM_MENUCHAR 0x0120 -#define WM_ENTERIDLE 0x0121 -#ifndef _WIN32_WCE -#define WM_MENURBUTTONUP 0x0122 -#define WM_MENUDRAG 0x0123 -#define WM_MENUGETOBJECT 0x0124 -#define WM_UNINITMENUPOPUP 0x0125 -#define WM_MENUCOMMAND 0x0126 - -#ifndef _WIN32_WCE -#define WM_CHANGEUISTATE 0x0127 -#define WM_UPDATEUISTATE 0x0128 -#define WM_QUERYUISTATE 0x0129 - -#define UIS_SET 1 -#define UIS_CLEAR 2 -#define UIS_INITIALIZE 3 - -#define UISF_HIDEFOCUS 0x1 -#define UISF_HIDEACCEL 0x2 -#define UISF_ACTIVE 0x4 -#endif -#endif - -#define WM_CTLCOLORMSGBOX 0x0132 -#define WM_CTLCOLOREDIT 0x0133 -#define WM_CTLCOLORLISTBOX 0x0134 -#define WM_CTLCOLORBTN 0x0135 -#define WM_CTLCOLORDLG 0x0136 -#define WM_CTLCOLORSCROLLBAR 0x0137 -#define WM_CTLCOLORSTATIC 0x0138 -#define MN_GETHMENU 0x01E1 - -#define WM_MOUSEFIRST 0x0200 -#define WM_MOUSEMOVE 0x0200 -#define WM_LBUTTONDOWN 0x0201 -#define WM_LBUTTONUP 0x0202 -#define WM_LBUTTONDBLCLK 0x0203 -#define WM_RBUTTONDOWN 0x0204 -#define WM_RBUTTONUP 0x0205 -#define WM_RBUTTONDBLCLK 0x0206 -#define WM_MBUTTONDOWN 0x0207 -#define WM_MBUTTONUP 0x0208 -#define WM_MBUTTONDBLCLK 0x0209 -#define WM_MOUSEWHEEL 0x020A -#define WM_XBUTTONDOWN 0x020B -#define WM_XBUTTONUP 0x020C -#define WM_XBUTTONDBLCLK 0x020D -#define WM_MOUSELAST 0x020D - -#define WHEEL_DELTA 120 -#define GET_WHEEL_DELTA_WPARAM(wParam) ((short)HIWORD(wParam)) - -#define WHEEL_PAGESCROLL (UINT_MAX) - -#define GET_KEYSTATE_WPARAM(wParam) (LOWORD(wParam)) -#define GET_NCHITTEST_WPARAM(wParam) ((short)LOWORD(wParam)) -#define GET_XBUTTON_WPARAM(wParam) (HIWORD(wParam)) - -#define XBUTTON1 0x0001 -#define XBUTTON2 0x0002 - -#define WM_PARENTNOTIFY 0x0210 -#define WM_ENTERMENULOOP 0x0211 -#define WM_EXITMENULOOP 0x0212 - -#define WM_NEXTMENU 0x0213 -#define WM_SIZING 0x0214 -#define WM_CAPTURECHANGED 0x0215 -#define WM_MOVING 0x0216 - -#define WM_POWERBROADCAST 0x0218 - -#ifndef _WIN32_WCE -#define PBT_APMQUERYSUSPEND 0x0000 -#define PBT_APMQUERYSTANDBY 0x0001 - -#define PBT_APMQUERYSUSPENDFAILED 0x0002 -#define PBT_APMQUERYSTANDBYFAILED 0x0003 - -#define PBT_APMSUSPEND 0x0004 -#define PBT_APMSTANDBY 0x0005 - -#define PBT_APMRESUMECRITICAL 0x0006 -#define PBT_APMRESUMESUSPEND 0x0007 -#define PBT_APMRESUMESTANDBY 0x0008 - -#define PBTF_APMRESUMEFROMFAILURE 0x00000001 - -#define PBT_APMBATTERYLOW 0x0009 -#define PBT_APMPOWERSTATUSCHANGE 0x000A - -#define PBT_APMOEMEVENT 0x000B -#define PBT_APMRESUMEAUTOMATIC 0x0012 -#endif - -#define WM_DEVICECHANGE 0x0219 - -#define WM_MDICREATE 0x0220 -#define WM_MDIDESTROY 0x0221 -#define WM_MDIACTIVATE 0x0222 -#define WM_MDIRESTORE 0x0223 -#define WM_MDINEXT 0x0224 -#define WM_MDIMAXIMIZE 0x0225 -#define WM_MDITILE 0x0226 -#define WM_MDICASCADE 0x0227 -#define WM_MDIICONARRANGE 0x0228 -#define WM_MDIGETACTIVE 0x0229 - -#define WM_MDISETMENU 0x0230 -#define WM_ENTERSIZEMOVE 0x0231 -#define WM_EXITSIZEMOVE 0x0232 -#define WM_DROPFILES 0x0233 -#define WM_MDIREFRESHMENU 0x0234 - -#define WM_IME_SETCONTEXT 0x0281 -#define WM_IME_NOTIFY 0x0282 -#define WM_IME_CONTROL 0x0283 -#define WM_IME_COMPOSITIONFULL 0x0284 -#define WM_IME_SELECT 0x0285 -#define WM_IME_CHAR 0x0286 -#define WM_IME_REQUEST 0x0288 -#define WM_IME_KEYDOWN 0x0290 -#define WM_IME_KEYUP 0x0291 - -#define WM_MOUSEHOVER 0x02A1 -#define WM_MOUSELEAVE 0x02A3 -#define WM_NCMOUSEHOVER 0x02A0 -#define WM_NCMOUSELEAVE 0x02A2 -#define WM_WTSSESSION_CHANGE 0x02B1 -#define WM_TABLET_FIRST 0x02c0 -#define WM_TABLET_LAST 0x02df -#define WM_CUT 0x0300 -#define WM_COPY 0x0301 -#define WM_PASTE 0x0302 -#define WM_CLEAR 0x0303 -#define WM_UNDO 0x0304 -#define WM_RENDERFORMAT 0x0305 -#define WM_RENDERALLFORMATS 0x0306 -#define WM_DESTROYCLIPBOARD 0x0307 -#define WM_DRAWCLIPBOARD 0x0308 -#define WM_PAINTCLIPBOARD 0x0309 -#define WM_VSCROLLCLIPBOARD 0x030A -#define WM_SIZECLIPBOARD 0x030B -#define WM_ASKCBFORMATNAME 0x030C -#define WM_CHANGECBCHAIN 0x030D -#define WM_HSCROLLCLIPBOARD 0x030E -#define WM_QUERYNEWPALETTE 0x030F -#define WM_PALETTEISCHANGING 0x0310 -#define WM_PALETTECHANGED 0x0311 -#define WM_HOTKEY 0x0312 -#define WM_PRINT 0x0317 -#define WM_PRINTCLIENT 0x0318 -#define WM_APPCOMMAND 0x0319 -#define WM_THEMECHANGED 0x031A -#define WM_HANDHELDFIRST 0x0358 -#define WM_HANDHELDLAST 0x035F -#define WM_AFXFIRST 0x0360 -#define WM_AFXLAST 0x037F -#define WM_PENWINFIRST 0x0380 -#define WM_PENWINLAST 0x038F -#define WM_APP 0x8000 -#define WM_USER 0x0400 - -#define WMSZ_LEFT 1 -#define WMSZ_RIGHT 2 -#define WMSZ_TOP 3 -#define WMSZ_TOPLEFT 4 -#define WMSZ_TOPRIGHT 5 -#define WMSZ_BOTTOM 6 -#define WMSZ_BOTTOMLEFT 7 -#define WMSZ_BOTTOMRIGHT 8 - -#ifndef NONCMESSAGES - -#define HTERROR (-2) -#define HTTRANSPARENT (-1) -#define HTNOWHERE 0 -#define HTCLIENT 1 -#define HTCAPTION 2 -#define HTSYSMENU 3 -#define HTGROWBOX 4 -#define HTSIZE HTGROWBOX -#define HTMENU 5 -#define HTHSCROLL 6 -#define HTVSCROLL 7 -#define HTMINBUTTON 8 -#define HTMAXBUTTON 9 -#define HTLEFT 10 -#define HTRIGHT 11 -#define HTTOP 12 -#define HTTOPLEFT 13 -#define HTTOPRIGHT 14 -#define HTBOTTOM 15 -#define HTBOTTOMLEFT 16 -#define HTBOTTOMRIGHT 17 -#define HTBORDER 18 -#define HTREDUCE HTMINBUTTON -#define HTZOOM HTMAXBUTTON -#define HTSIZEFIRST HTLEFT -#define HTSIZELAST HTBOTTOMRIGHT -#define HTOBJECT 19 -#define HTCLOSE 20 -#define HTHELP 21 - -#define SMTO_NORMAL 0x0000 -#define SMTO_BLOCK 0x0001 -#define SMTO_ABORTIFHUNG 0x0002 -#define SMTO_NOTIMEOUTIFNOTHUNG 0x0008 -#endif - -#define MA_ACTIVATE 1 -#define MA_ACTIVATEANDEAT 2 -#define MA_NOACTIVATE 3 -#define MA_NOACTIVATEANDEAT 4 - -#define ICON_SMALL 0 -#define ICON_BIG 1 -#define ICON_SMALL2 2 - -#ifdef UNICODE -#define RegisterWindowMessage RegisterWindowMessageW -#else -#define RegisterWindowMessage RegisterWindowMessageA -#endif - - WINUSERAPI UINT WINAPI RegisterWindowMessageA(LPCSTR lpString); - WINUSERAPI UINT WINAPI RegisterWindowMessageW(LPCWSTR lpString); - -#define SIZE_RESTORED 0 -#define SIZE_MINIMIZED 1 -#define SIZE_MAXIMIZED 2 -#define SIZE_MAXSHOW 3 -#define SIZE_MAXHIDE 4 - -#define SIZENORMAL SIZE_RESTORED -#define SIZEICONIC SIZE_MINIMIZED -#define SIZEFULLSCREEN SIZE_MAXIMIZED -#define SIZEZOOMSHOW SIZE_MAXSHOW -#define SIZEZOOMHIDE SIZE_MAXHIDE - - typedef struct tagWINDOWPOS { - HWND hwnd; - HWND hwndInsertAfter; - int x; - int y; - int cx; - int cy; - UINT flags; - } WINDOWPOS,*LPWINDOWPOS,*PWINDOWPOS; - - typedef struct tagNCCALCSIZE_PARAMS { - RECT rgrc[3]; - PWINDOWPOS lppos; - } NCCALCSIZE_PARAMS,*LPNCCALCSIZE_PARAMS; - -#define WVR_ALIGNTOP 0x0010 -#define WVR_ALIGNLEFT 0x0020 -#define WVR_ALIGNBOTTOM 0x0040 -#define WVR_ALIGNRIGHT 0x0080 -#define WVR_HREDRAW 0x0100 -#define WVR_VREDRAW 0x0200 -#define WVR_REDRAW (WVR_HREDRAW | WVR_VREDRAW) -#define WVR_VALIDRECTS 0x0400 - -#ifndef NOKEYSTATES - -#define MK_LBUTTON 0x0001 -#define MK_RBUTTON 0x0002 -#define MK_SHIFT 0x0004 -#define MK_CONTROL 0x0008 -#define MK_MBUTTON 0x0010 -#define MK_XBUTTON1 0x0020 -#define MK_XBUTTON2 0x0040 -#endif - -#ifndef NOTRACKMOUSEEVENT -#define TME_HOVER 0x00000001 -#define TME_LEAVE 0x00000002 -#define TME_NONCLIENT 0x00000010 -#define TME_QUERY 0x40000000 -#define TME_CANCEL 0x80000000 - -#define HOVER_DEFAULT 0xFFFFFFFF -#endif - - typedef struct tagTRACKMOUSEEVENT { - DWORD cbSize; - DWORD dwFlags; - HWND hwndTrack; - DWORD dwHoverTime; - } TRACKMOUSEEVENT,*LPTRACKMOUSEEVENT; - - WINUSERAPI WINBOOL WINAPI TrackMouseEvent(LPTRACKMOUSEEVENT lpEventTrack); -#endif - -#ifndef NOWINSTYLES - -#define WS_OVERLAPPED 0x00000000L -#define WS_POPUP 0x80000000L -#define WS_CHILD 0x40000000L -#define WS_MINIMIZE 0x20000000L -#define WS_VISIBLE 0x10000000L -#define WS_DISABLED 0x08000000L -#define WS_CLIPSIBLINGS 0x04000000L -#define WS_CLIPCHILDREN 0x02000000L -#define WS_MAXIMIZE 0x01000000L -#define WS_CAPTION 0x00C00000L -#define WS_BORDER 0x00800000L -#define WS_DLGFRAME 0x00400000L -#define WS_VSCROLL 0x00200000L -#define WS_HSCROLL 0x00100000L -#define WS_SYSMENU 0x00080000L -#define WS_THICKFRAME 0x00040000L -#define WS_GROUP 0x00020000L -#define WS_TABSTOP 0x00010000L -#define WS_MINIMIZEBOX 0x00020000L -#define WS_MAXIMIZEBOX 0x00010000L -#define WS_TILED WS_OVERLAPPED -#define WS_ICONIC WS_MINIMIZE -#define WS_SIZEBOX WS_THICKFRAME -#define WS_TILEDWINDOW WS_OVERLAPPEDWINDOW -#define WS_OVERLAPPEDWINDOW (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX) -#define WS_POPUPWINDOW (WS_POPUP | WS_BORDER | WS_SYSMENU) -#define WS_CHILDWINDOW (WS_CHILD) - -#define WS_EX_DLGMODALFRAME 0x00000001L -#define WS_EX_NOPARENTNOTIFY 0x00000004L -#define WS_EX_TOPMOST 0x00000008L -#define WS_EX_ACCEPTFILES 0x00000010L -#define WS_EX_TRANSPARENT 0x00000020L -#define WS_EX_MDICHILD 0x00000040L -#define WS_EX_TOOLWINDOW 0x00000080L -#define WS_EX_WINDOWEDGE 0x00000100L -#define WS_EX_CLIENTEDGE 0x00000200L -#define WS_EX_CONTEXTHELP 0x00000400L -#define WS_EX_RIGHT 0x00001000L -#define WS_EX_LEFT 0x00000000L -#define WS_EX_RTLREADING 0x00002000L -#define WS_EX_LTRREADING 0x00000000L -#define WS_EX_LEFTSCROLLBAR 0x00004000L -#define WS_EX_RIGHTSCROLLBAR 0x00000000L -#define WS_EX_CONTROLPARENT 0x00010000L -#define WS_EX_STATICEDGE 0x00020000L -#define WS_EX_APPWINDOW 0x00040000L -#define WS_EX_OVERLAPPEDWINDOW (WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE) -#define WS_EX_PALETTEWINDOW (WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST) -#define WS_EX_LAYERED 0x00080000 -#define WS_EX_NOINHERITLAYOUT 0x00100000L -#define WS_EX_LAYOUTRTL 0x00400000L -#define WS_EX_COMPOSITED 0x02000000L -#define WS_EX_NOACTIVATE 0x08000000L - -#define CS_VREDRAW 0x0001 -#define CS_HREDRAW 0x0002 -#define CS_DBLCLKS 0x0008 -#define CS_OWNDC 0x0020 -#define CS_CLASSDC 0x0040 -#define CS_PARENTDC 0x0080 -#define CS_NOCLOSE 0x0200 -#define CS_SAVEBITS 0x0800 -#define CS_BYTEALIGNCLIENT 0x1000 -#define CS_BYTEALIGNWINDOW 0x2000 -#define CS_GLOBALCLASS 0x4000 -#define CS_IME 0x00010000 -#define CS_DROPSHADOW 0x00020000 -#endif - -#define PRF_CHECKVISIBLE 0x00000001L -#define PRF_NONCLIENT 0x00000002L -#define PRF_CLIENT 0x00000004L -#define PRF_ERASEBKGND 0x00000008L -#define PRF_CHILDREN 0x00000010L -#define PRF_OWNED 0x00000020L - -#define BDR_RAISEDOUTER 0x0001 -#define BDR_SUNKENOUTER 0x0002 -#define BDR_RAISEDINNER 0x0004 -#define BDR_SUNKENINNER 0x0008 - -#define BDR_OUTER (BDR_RAISEDOUTER | BDR_SUNKENOUTER) -#define BDR_INNER (BDR_RAISEDINNER | BDR_SUNKENINNER) -#define BDR_RAISED (BDR_RAISEDOUTER | BDR_RAISEDINNER) -#define BDR_SUNKEN (BDR_SUNKENOUTER | BDR_SUNKENINNER) - -#define EDGE_RAISED (BDR_RAISEDOUTER | BDR_RAISEDINNER) -#define EDGE_SUNKEN (BDR_SUNKENOUTER | BDR_SUNKENINNER) -#define EDGE_ETCHED (BDR_SUNKENOUTER | BDR_RAISEDINNER) -#define EDGE_BUMP (BDR_RAISEDOUTER | BDR_SUNKENINNER) - -#define BF_LEFT 0x0001 -#define BF_TOP 0x0002 -#define BF_RIGHT 0x0004 -#define BF_BOTTOM 0x0008 - -#define BF_TOPLEFT (BF_TOP | BF_LEFT) -#define BF_TOPRIGHT (BF_TOP | BF_RIGHT) -#define BF_BOTTOMLEFT (BF_BOTTOM | BF_LEFT) -#define BF_BOTTOMRIGHT (BF_BOTTOM | BF_RIGHT) -#define BF_RECT (BF_LEFT | BF_TOP | BF_RIGHT | BF_BOTTOM) - -#define BF_DIAGONAL 0x0010 - -#define BF_DIAGONAL_ENDTOPRIGHT (BF_DIAGONAL | BF_TOP | BF_RIGHT) -#define BF_DIAGONAL_ENDTOPLEFT (BF_DIAGONAL | BF_TOP | BF_LEFT) -#define BF_DIAGONAL_ENDBOTTOMLEFT (BF_DIAGONAL | BF_BOTTOM | BF_LEFT) -#define BF_DIAGONAL_ENDBOTTOMRIGHT (BF_DIAGONAL | BF_BOTTOM | BF_RIGHT) - -#define BF_MIDDLE 0x0800 -#define BF_SOFT 0x1000 -#define BF_ADJUST 0x2000 -#define BF_FLAT 0x4000 -#define BF_MONO 0x8000 - - WINUSERAPI WINBOOL WINAPI DrawEdge(HDC hdc,LPRECT qrc,UINT edge,UINT grfFlags); - -#define DFC_CAPTION 1 -#define DFC_MENU 2 -#define DFC_SCROLL 3 -#define DFC_BUTTON 4 -#define DFC_POPUPMENU 5 - -#define DFCS_CAPTIONCLOSE 0x0000 -#define DFCS_CAPTIONMIN 0x0001 -#define DFCS_CAPTIONMAX 0x0002 -#define DFCS_CAPTIONRESTORE 0x0003 -#define DFCS_CAPTIONHELP 0x0004 - -#define DFCS_MENUARROW 0x0000 -#define DFCS_MENUCHECK 0x0001 -#define DFCS_MENUBULLET 0x0002 -#define DFCS_MENUARROWRIGHT 0x0004 -#define DFCS_SCROLLUP 0x0000 -#define DFCS_SCROLLDOWN 0x0001 -#define DFCS_SCROLLLEFT 0x0002 -#define DFCS_SCROLLRIGHT 0x0003 -#define DFCS_SCROLLCOMBOBOX 0x0005 -#define DFCS_SCROLLSIZEGRIP 0x0008 -#define DFCS_SCROLLSIZEGRIPRIGHT 0x0010 - -#define DFCS_BUTTONCHECK 0x0000 -#define DFCS_BUTTONRADIOIMAGE 0x0001 -#define DFCS_BUTTONRADIOMASK 0x0002 -#define DFCS_BUTTONRADIO 0x0004 -#define DFCS_BUTTON3STATE 0x0008 -#define DFCS_BUTTONPUSH 0x0010 - -#define DFCS_INACTIVE 0x0100 -#define DFCS_PUSHED 0x0200 -#define DFCS_CHECKED 0x0400 - -#define DFCS_TRANSPARENT 0x0800 -#define DFCS_HOT 0x1000 - -#define DFCS_ADJUSTRECT 0x2000 -#define DFCS_FLAT 0x4000 -#define DFCS_MONO 0x8000 - - WINUSERAPI WINBOOL WINAPI DrawFrameControl(HDC,LPRECT,UINT,UINT); - -#define DC_ACTIVE 0x0001 -#define DC_SMALLCAP 0x0002 -#define DC_ICON 0x0004 -#define DC_TEXT 0x0008 -#define DC_INBUTTON 0x0010 -#define DC_GRADIENT 0x0020 -#define DC_BUTTONS 0x1000 - - WINUSERAPI WINBOOL WINAPI DrawCaption(HWND hwnd,HDC hdc,CONST RECT *lprect,UINT flags); - -#define IDANI_OPEN 1 -#define IDANI_CAPTION 3 - - WINUSERAPI WINBOOL WINAPI DrawAnimatedRects(HWND hwnd,int idAni,CONST RECT *lprcFrom,CONST RECT *lprcTo); - -#ifndef NOCLIPBOARD - -#define CF_TEXT 1 -#define CF_BITMAP 2 -#define CF_METAFILEPICT 3 -#define CF_SYLK 4 -#define CF_DIF 5 -#define CF_TIFF 6 -#define CF_OEMTEXT 7 -#define CF_DIB 8 -#define CF_PALETTE 9 -#define CF_PENDATA 10 -#define CF_RIFF 11 -#define CF_WAVE 12 -#define CF_UNICODETEXT 13 -#define CF_ENHMETAFILE 14 -#define CF_HDROP 15 -#define CF_LOCALE 16 -#define CF_DIBV5 17 -#define CF_MAX 18 - -#define CF_OWNERDISPLAY 0x0080 -#define CF_DSPTEXT 0x0081 -#define CF_DSPBITMAP 0x0082 -#define CF_DSPMETAFILEPICT 0x0083 -#define CF_DSPENHMETAFILE 0x008E - -#define CF_PRIVATEFIRST 0x0200 -#define CF_PRIVATELAST 0x02FF - -#define CF_GDIOBJFIRST 0x0300 -#define CF_GDIOBJLAST 0x03FF -#endif - -#define FVIRTKEY TRUE -#define FNOINVERT 0x02 -#define FSHIFT 0x04 -#define FCONTROL 0x08 -#define FALT 0x10 - - typedef struct tagACCEL { - BYTE fVirt; - WORD key; - WORD cmd; - } ACCEL,*LPACCEL; - - typedef struct tagPAINTSTRUCT { - HDC hdc; - WINBOOL fErase; - RECT rcPaint; - WINBOOL fRestore; - WINBOOL fIncUpdate; - BYTE rgbReserved[32]; - } PAINTSTRUCT,*PPAINTSTRUCT,*NPPAINTSTRUCT,*LPPAINTSTRUCT; - - typedef struct tagCREATESTRUCTA { - LPVOID lpCreateParams; - HINSTANCE hInstance; - HMENU hMenu; - HWND hwndParent; - int cy; - int cx; - int y; - int x; - LONG style; - LPCSTR lpszName; - LPCSTR lpszClass; - DWORD dwExStyle; - } CREATESTRUCTA,*LPCREATESTRUCTA; - - typedef struct tagCREATESTRUCTW { - LPVOID lpCreateParams; - HINSTANCE hInstance; - HMENU hMenu; - HWND hwndParent; - int cy; - int cx; - int y; - int x; - LONG style; - LPCWSTR lpszName; - LPCWSTR lpszClass; - DWORD dwExStyle; - } CREATESTRUCTW,*LPCREATESTRUCTW; - -#ifdef UNICODE - typedef CREATESTRUCTW CREATESTRUCT; - typedef LPCREATESTRUCTW LPCREATESTRUCT; -#else - typedef CREATESTRUCTA CREATESTRUCT; - typedef LPCREATESTRUCTA LPCREATESTRUCT; -#endif - - typedef struct tagWINDOWPLACEMENT { - UINT length; - UINT flags; - UINT showCmd; - POINT ptMinPosition; - POINT ptMaxPosition; - RECT rcNormalPosition; - } WINDOWPLACEMENT; - typedef WINDOWPLACEMENT *PWINDOWPLACEMENT,*LPWINDOWPLACEMENT; - -#define WPF_SETMINPOSITION 0x0001 -#define WPF_RESTORETOMAXIMIZED 0x0002 -#define WPF_ASYNCWINDOWPLACEMENT 0x0004 - - typedef struct tagNMHDR { - HWND hwndFrom; - UINT_PTR idFrom; - UINT code; - } NMHDR; - - typedef NMHDR *LPNMHDR; - - typedef struct tagSTYLESTRUCT { - DWORD styleOld; - DWORD styleNew; - } STYLESTRUCT,*LPSTYLESTRUCT; - -#define ODT_MENU 1 -#define ODT_LISTBOX 2 -#define ODT_COMBOBOX 3 -#define ODT_BUTTON 4 -#define ODT_STATIC 5 - -#define ODA_DRAWENTIRE 0x0001 -#define ODA_SELECT 0x0002 -#define ODA_FOCUS 0x0004 - -#define ODS_SELECTED 0x0001 -#define ODS_GRAYED 0x0002 -#define ODS_DISABLED 0x0004 -#define ODS_CHECKED 0x0008 -#define ODS_FOCUS 0x0010 -#define ODS_DEFAULT 0x0020 -#define ODS_COMBOBOXEDIT 0x1000 -#define ODS_HOTLIGHT 0x0040 -#define ODS_INACTIVE 0x0080 -#define ODS_NOACCEL 0x0100 -#define ODS_NOFOCUSRECT 0x0200 - - typedef struct tagMEASUREITEMSTRUCT { - UINT CtlType; - UINT CtlID; - UINT itemID; - UINT itemWidth; - UINT itemHeight; - ULONG_PTR itemData; - } MEASUREITEMSTRUCT,*PMEASUREITEMSTRUCT,*LPMEASUREITEMSTRUCT; - - typedef struct tagDRAWITEMSTRUCT { - UINT CtlType; - UINT CtlID; - UINT itemID; - UINT itemAction; - UINT itemState; - HWND hwndItem; - HDC hDC; - RECT rcItem; - ULONG_PTR itemData; - } DRAWITEMSTRUCT,*PDRAWITEMSTRUCT,*LPDRAWITEMSTRUCT; - - typedef struct tagDELETEITEMSTRUCT { - UINT CtlType; - UINT CtlID; - UINT itemID; - HWND hwndItem; - ULONG_PTR itemData; - } DELETEITEMSTRUCT,*PDELETEITEMSTRUCT,*LPDELETEITEMSTRUCT; - - typedef struct tagCOMPAREITEMSTRUCT { - UINT CtlType; - UINT CtlID; - HWND hwndItem; - UINT itemID1; - ULONG_PTR itemData1; - UINT itemID2; - ULONG_PTR itemData2; - DWORD dwLocaleId; - } COMPAREITEMSTRUCT,*PCOMPAREITEMSTRUCT,*LPCOMPAREITEMSTRUCT; - -#ifndef NOMSG -#ifdef UNICODE -#define GetMessage GetMessageW -#define DispatchMessage DispatchMessageW -#define PeekMessage PeekMessageW -#else -#define GetMessage GetMessageA -#define DispatchMessage DispatchMessageA -#define PeekMessage PeekMessageA -#endif - - WINUSERAPI WINBOOL WINAPI GetMessageA(LPMSG lpMsg,HWND hWnd,UINT wMsgFilterMin,UINT wMsgFilterMax); - WINUSERAPI WINBOOL WINAPI GetMessageW(LPMSG lpMsg,HWND hWnd,UINT wMsgFilterMin,UINT wMsgFilterMax); - WINUSERAPI WINBOOL WINAPI TranslateMessage(CONST MSG *lpMsg); - WINUSERAPI LRESULT WINAPI DispatchMessageA(CONST MSG *lpMsg); - WINUSERAPI LRESULT WINAPI DispatchMessageW(CONST MSG *lpMsg); - WINUSERAPI WINBOOL WINAPI SetMessageQueue(int cMessagesMax); - WINUSERAPI WINBOOL WINAPI PeekMessageA(LPMSG lpMsg,HWND hWnd,UINT wMsgFilterMin,UINT wMsgFilterMax,UINT wRemoveMsg); - WINUSERAPI WINBOOL WINAPI PeekMessageW(LPMSG lpMsg,HWND hWnd,UINT wMsgFilterMin,UINT wMsgFilterMax,UINT wRemoveMsg); - -#define PM_NOREMOVE 0x0000 -#define PM_REMOVE 0x0001 -#define PM_NOYIELD 0x0002 -#define PM_QS_INPUT (QS_INPUT << 16) -#define PM_QS_POSTMESSAGE ((QS_POSTMESSAGE | QS_HOTKEY | QS_TIMER) << 16) -#define PM_QS_PAINT (QS_PAINT << 16) -#define PM_QS_SENDMESSAGE (QS_SENDMESSAGE << 16) -#endif - - WINUSERAPI WINBOOL WINAPI RegisterHotKey(HWND hWnd,int id,UINT fsModifiers,UINT vk); - WINUSERAPI WINBOOL WINAPI UnregisterHotKey(HWND hWnd,int id); - -#define MOD_ALT 0x0001 -#define MOD_CONTROL 0x0002 -#define MOD_SHIFT 0x0004 -#define MOD_WIN 0x0008 - -#define IDHOT_SNAPWINDOW (-1) -#define IDHOT_SNAPDESKTOP (-2) - -#ifdef WIN_INTERNAL -#ifndef LSTRING -#define NOLSTRING -#endif -#ifndef LFILEIO -#define NOLFILEIO -#endif -#endif - -#define ENDSESSION_LOGOFF 0x80000000 - -#define EWX_LOGOFF 0 -#define EWX_SHUTDOWN 0x00000001 -#define EWX_REBOOT 0x00000002 -#define EWX_FORCE 0x00000004 -#define EWX_POWEROFF 0x00000008 -#define EWX_FORCEIFHUNG 0x00000010 - -#define ExitWindows(dwReserved,Code) ExitWindowsEx(EWX_LOGOFF,0xFFFFFFFF) - -#ifdef UNICODE -#define SendMessage SendMessageW -#define SendMessageTimeout SendMessageTimeoutW -#define SendNotifyMessage SendNotifyMessageW -#define SendMessageCallback SendMessageCallbackW -#else -#define SendMessage SendMessageA -#define SendMessageTimeout SendMessageTimeoutA -#define SendNotifyMessage SendNotifyMessageA -#define SendMessageCallback SendMessageCallbackA -#endif - - WINUSERAPI WINBOOL WINAPI ExitWindowsEx(UINT uFlags,DWORD dwReason); - WINUSERAPI WINBOOL WINAPI SwapMouseButton(WINBOOL fSwap); - WINUSERAPI DWORD WINAPI GetMessagePos(VOID); - WINUSERAPI LONG WINAPI GetMessageTime(VOID); - WINUSERAPI LPARAM WINAPI GetMessageExtraInfo(VOID); - WINUSERAPI WINBOOL WINAPI IsWow64Message(VOID); - WINUSERAPI LPARAM WINAPI SetMessageExtraInfo(LPARAM lParam); - WINUSERAPI LRESULT WINAPI SendMessageA(HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam); - WINUSERAPI LRESULT WINAPI SendMessageW(HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam); - WINUSERAPI LRESULT WINAPI SendMessageTimeoutA(HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam,UINT fuFlags,UINT uTimeout,PDWORD_PTR lpdwResult); - WINUSERAPI LRESULT WINAPI SendMessageTimeoutW(HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam,UINT fuFlags,UINT uTimeout,PDWORD_PTR lpdwResult); - WINUSERAPI WINBOOL WINAPI SendNotifyMessageA(HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam); - WINUSERAPI WINBOOL WINAPI SendNotifyMessageW(HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam); - WINUSERAPI WINBOOL WINAPI SendMessageCallbackA(HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam,SENDASYNCPROC lpResultCallBack,ULONG_PTR dwData); - WINUSERAPI WINBOOL WINAPI SendMessageCallbackW(HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam,SENDASYNCPROC lpResultCallBack,ULONG_PTR dwData); - - typedef struct { - UINT cbSize; - HDESK hdesk; - HWND hwnd; - LUID luid; - } BSMINFO,*PBSMINFO; - -#ifdef UNICODE -#define BroadcastSystemMessageEx BroadcastSystemMessageExW -#define BroadcastSystemMessage BroadcastSystemMessageW -#else -#define BroadcastSystemMessageEx BroadcastSystemMessageExA -#define BroadcastSystemMessage BroadcastSystemMessageA -#endif - - WINUSERAPI long WINAPI BroadcastSystemMessageExA(DWORD flags,LPDWORD lpInfo,UINT Msg,WPARAM wParam,LPARAM lParam,PBSMINFO pbsmInfo); - WINUSERAPI long WINAPI BroadcastSystemMessageExW(DWORD flags,LPDWORD lpInfo,UINT Msg,WPARAM wParam,LPARAM lParam,PBSMINFO pbsmInfo); - WINUSERAPI long WINAPI BroadcastSystemMessageA(DWORD flags,LPDWORD lpInfo,UINT Msg,WPARAM wParam,LPARAM lParam); - WINUSERAPI long WINAPI BroadcastSystemMessageW(DWORD flags,LPDWORD lpInfo,UINT Msg,WPARAM wParam,LPARAM lParam); - -#define BSM_ALLCOMPONENTS 0x00000000 -#define BSM_VXDS 0x00000001 -#define BSM_NETDRIVER 0x00000002 -#define BSM_INSTALLABLEDRIVERS 0x00000004 -#define BSM_APPLICATIONS 0x00000008 -#define BSM_ALLDESKTOPS 0x00000010 - -#define BSF_QUERY 0x00000001 -#define BSF_IGNORECURRENTTASK 0x00000002 -#define BSF_FLUSHDISK 0x00000004 -#define BSF_NOHANG 0x00000008 -#define BSF_POSTMESSAGE 0x00000010 -#define BSF_FORCEIFHUNG 0x00000020 -#define BSF_NOTIMEOUTIFNOTHUNG 0x00000040 -#define BSF_ALLOWSFW 0x00000080 -#define BSF_SENDNOTIFYMESSAGE 0x00000100 -#define BSF_RETURNHDESK 0x00000200 -#define BSF_LUID 0x00000400 - -#define BROADCAST_QUERY_DENY 0x424D5144 - - typedef PVOID HDEVNOTIFY; - typedef HDEVNOTIFY *PHDEVNOTIFY; - -#define DEVICE_NOTIFY_WINDOW_HANDLE 0x00000000 -#define DEVICE_NOTIFY_SERVICE_HANDLE 0x00000001 -#define DEVICE_NOTIFY_ALL_INTERFACE_CLASSES 0x00000004 - -#ifdef UNICODE -#define RegisterDeviceNotification RegisterDeviceNotificationW -#define PostMessage PostMessageW -#define PostThreadMessage PostThreadMessageW -#define PostAppMessage PostAppMessageW -#define DefWindowProc DefWindowProcW -#define CallWindowProc CallWindowProcW -#define RegisterClass RegisterClassW -#define UnregisterClass UnregisterClassW -#define GetClassInfo GetClassInfoW -#define RegisterClassEx RegisterClassExW -#define GetClassInfoEx GetClassInfoExW -#else -#define RegisterDeviceNotification RegisterDeviceNotificationA -#define PostMessage PostMessageA -#define PostThreadMessage PostThreadMessageA -#define PostAppMessage PostAppMessageA -#define DefWindowProc DefWindowProcA -#define CallWindowProc CallWindowProcA -#define RegisterClass RegisterClassA -#define UnregisterClass UnregisterClassA -#define GetClassInfo GetClassInfoA -#define RegisterClassEx RegisterClassExA -#define GetClassInfoEx GetClassInfoExA -#endif - - WINUSERAPI HDEVNOTIFY WINAPI RegisterDeviceNotificationA(HANDLE hRecipient,LPVOID NotificationFilter,DWORD Flags); - WINUSERAPI HDEVNOTIFY WINAPI RegisterDeviceNotificationW(HANDLE hRecipient,LPVOID NotificationFilter,DWORD Flags); - WINUSERAPI WINBOOL WINAPI UnregisterDeviceNotification(HDEVNOTIFY Handle); - WINUSERAPI WINBOOL WINAPI PostMessageA(HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam); - WINUSERAPI WINBOOL WINAPI PostMessageW(HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam); - WINUSERAPI WINBOOL WINAPI PostThreadMessageA(DWORD idThread,UINT Msg,WPARAM wParam,LPARAM lParam); - WINUSERAPI WINBOOL WINAPI PostThreadMessageW(DWORD idThread,UINT Msg,WPARAM wParam,LPARAM lParam); -#define PostAppMessageA(idThread,wMsg,wParam,lParam) PostThreadMessageA((DWORD)idThread,wMsg,wParam,lParam) -#define PostAppMessageW(idThread,wMsg,wParam,lParam) PostThreadMessageW((DWORD)idThread,wMsg,wParam,lParam) - -#define HWND_BROADCAST ((HWND)0xffff) -#define HWND_MESSAGE ((HWND)-3) - - WINUSERAPI WINBOOL WINAPI AttachThreadInput(DWORD idAttach,DWORD idAttachTo,WINBOOL fAttach); - WINUSERAPI WINBOOL WINAPI ReplyMessage(LRESULT lResult); - WINUSERAPI WINBOOL WINAPI WaitMessage(VOID); - WINUSERAPI DWORD WINAPI WaitForInputIdle(HANDLE hProcess,DWORD dwMilliseconds); - WINUSERAPI LRESULT WINAPI DefWindowProcA(HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam); - WINUSERAPI LRESULT WINAPI DefWindowProcW(HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam); - WINUSERAPI VOID WINAPI PostQuitMessage(int nExitCode); - WINUSERAPI LRESULT WINAPI CallWindowProcA(WNDPROC lpPrevWndFunc,HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam); - WINUSERAPI LRESULT WINAPI CallWindowProcW(WNDPROC lpPrevWndFunc,HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam); - WINUSERAPI WINBOOL WINAPI InSendMessage(VOID); - WINUSERAPI DWORD WINAPI InSendMessageEx(LPVOID lpReserved); - -#define ISMEX_NOSEND 0x00000000 -#define ISMEX_SEND 0x00000001 -#define ISMEX_NOTIFY 0x00000002 -#define ISMEX_CALLBACK 0x00000004 -#define ISMEX_REPLIED 0x00000008 - - WINUSERAPI UINT WINAPI GetDoubleClickTime(VOID); - WINUSERAPI WINBOOL WINAPI SetDoubleClickTime(UINT); - WINUSERAPI ATOM WINAPI RegisterClassA(CONST WNDCLASSA *lpWndClass); - WINUSERAPI ATOM WINAPI RegisterClassW(CONST WNDCLASSW *lpWndClass); - WINUSERAPI WINBOOL WINAPI UnregisterClassA(LPCSTR lpClassName,HINSTANCE hInstance); - WINUSERAPI WINBOOL WINAPI UnregisterClassW(LPCWSTR lpClassName,HINSTANCE hInstance); - WINUSERAPI WINBOOL WINAPI GetClassInfoA(HINSTANCE hInstance,LPCSTR lpClassName,LPWNDCLASSA lpWndClass); - WINUSERAPI WINBOOL WINAPI GetClassInfoW(HINSTANCE hInstance,LPCWSTR lpClassName,LPWNDCLASSW lpWndClass); - WINUSERAPI ATOM WINAPI RegisterClassExA(CONST WNDCLASSEXA *); - WINUSERAPI ATOM WINAPI RegisterClassExW(CONST WNDCLASSEXW *); - WINUSERAPI WINBOOL WINAPI GetClassInfoExA(HINSTANCE hInstance,LPCSTR lpszClass,LPWNDCLASSEXA lpwcx); - WINUSERAPI WINBOOL WINAPI GetClassInfoExW(HINSTANCE hInstance,LPCWSTR lpszClass,LPWNDCLASSEXW lpwcx); - -#define CW_USEDEFAULT ((int)0x80000000) - -#define HWND_DESKTOP ((HWND)0) - - typedef BOOLEAN (WINAPI *PREGISTERCLASSNAMEW)(LPCWSTR); - -#ifdef UNICODE -#define CreateWindowEx CreateWindowExW -#define CreateWindow CreateWindowW -#else -#define CreateWindowEx CreateWindowExA -#define CreateWindow CreateWindowA -#endif - - WINUSERAPI HWND WINAPI CreateWindowExA(DWORD dwExStyle,LPCSTR lpClassName,LPCSTR lpWindowName,DWORD dwStyle,int X,int Y,int nWidth,int nHeight,HWND hWndParent,HMENU hMenu,HINSTANCE hInstance,LPVOID lpParam); - WINUSERAPI HWND WINAPI CreateWindowExW(DWORD dwExStyle,LPCWSTR lpClassName,LPCWSTR lpWindowName,DWORD dwStyle,int X,int Y,int nWidth,int nHeight,HWND hWndParent,HMENU hMenu,HINSTANCE hInstance,LPVOID lpParam); -#define CreateWindowA(lpClassName,lpWindowName,dwStyle,x,y,nWidth,nHeight,hWndParent,hMenu,hInstance,lpParam) CreateWindowExA(0L,lpClassName,lpWindowName,dwStyle,x,y,nWidth,nHeight,hWndParent,hMenu,hInstance,lpParam) -#define CreateWindowW(lpClassName,lpWindowName,dwStyle,x,y,nWidth,nHeight,hWndParent,hMenu,hInstance,lpParam) CreateWindowExW(0L,lpClassName,lpWindowName,dwStyle,x,y,nWidth,nHeight,hWndParent,hMenu,hInstance,lpParam) - WINUSERAPI WINBOOL WINAPI IsWindow(HWND hWnd); - WINUSERAPI WINBOOL WINAPI IsMenu(HMENU hMenu); - WINUSERAPI WINBOOL WINAPI IsChild(HWND hWndParent,HWND hWnd); - WINUSERAPI WINBOOL WINAPI DestroyWindow(HWND hWnd); - WINUSERAPI WINBOOL WINAPI ShowWindow(HWND hWnd,int nCmdShow); - WINUSERAPI WINBOOL WINAPI AnimateWindow(HWND hWnd,DWORD dwTime,DWORD dwFlags); - -#if defined(_WINGDI_) && !defined(NOGDI) - WINUSERAPI WINBOOL WINAPI UpdateLayeredWindow(HWND hWnd,HDC hdcDst,POINT *pptDst,SIZE *psize,HDC hdcSrc,POINT *pptSrc,COLORREF crKey,BLENDFUNCTION *pblend,DWORD dwFlags); - - typedef struct tagUPDATELAYEREDWINDOWINFO { - DWORD cbSize; - HDC hdcDst; - POINT CONST *pptDst; - SIZE CONST *psize; - HDC hdcSrc; - POINT CONST *pptSrc; - COLORREF crKey; - BLENDFUNCTION CONST *pblend; - DWORD dwFlags; - RECT CONST *prcDirty; - } UPDATELAYEREDWINDOWINFO,*PUPDATELAYEREDWINDOWINFO; - - WINUSERAPI WINBOOL WINAPI UpdateLayeredWindowIndirect(HWND hWnd,UPDATELAYEREDWINDOWINFO CONST *pULWInfo); - WINUSERAPI WINBOOL WINAPI GetLayeredWindowAttributes(HWND hwnd,COLORREF *pcrKey,BYTE *pbAlpha,DWORD *pdwFlags); - -#define PW_CLIENTONLY 0x00000001 - - WINUSERAPI WINBOOL WINAPI PrintWindow(HWND hwnd,HDC hdcBlt,UINT nFlags); - WINUSERAPI WINBOOL WINAPI SetLayeredWindowAttributes(HWND hwnd,COLORREF crKey,BYTE bAlpha,DWORD dwFlags); - -#define LWA_COLORKEY 0x00000001 -#define LWA_ALPHA 0x00000002 - -#define ULW_COLORKEY 0x00000001 -#define ULW_ALPHA 0x00000002 -#define ULW_OPAQUE 0x00000004 - -#define ULW_EX_NORESIZE 0x00000008 - - WINUSERAPI WINBOOL WINAPI ShowWindowAsync(HWND hWnd,int nCmdShow); - WINUSERAPI WINBOOL WINAPI FlashWindow(HWND hWnd,WINBOOL bInvert); - - typedef struct { - UINT cbSize; - HWND hwnd; - DWORD dwFlags; - UINT uCount; - DWORD dwTimeout; - } FLASHWINFO,*PFLASHWINFO; - - WINUSERAPI WINBOOL WINAPI FlashWindowEx(PFLASHWINFO pfwi); - -#define FLASHW_STOP 0 -#define FLASHW_CAPTION 0x00000001 -#define FLASHW_TRAY 0x00000002 -#define FLASHW_ALL (FLASHW_CAPTION | FLASHW_TRAY) -#define FLASHW_TIMER 0x00000004 -#define FLASHW_TIMERNOFG 0x0000000C - - WINUSERAPI WINBOOL WINAPI ShowOwnedPopups(HWND hWnd,WINBOOL fShow); - WINUSERAPI WINBOOL WINAPI OpenIcon(HWND hWnd); - WINUSERAPI WINBOOL WINAPI CloseWindow(HWND hWnd); - WINUSERAPI WINBOOL WINAPI MoveWindow(HWND hWnd,int X,int Y,int nWidth,int nHeight,WINBOOL bRepaint); - WINUSERAPI WINBOOL WINAPI SetWindowPos(HWND hWnd,HWND hWndInsertAfter,int X,int Y,int cx,int cy,UINT uFlags); - WINUSERAPI WINBOOL WINAPI GetWindowPlacement(HWND hWnd,WINDOWPLACEMENT *lpwndpl); - WINUSERAPI WINBOOL WINAPI SetWindowPlacement(HWND hWnd,CONST WINDOWPLACEMENT *lpwndpl); - -#ifndef NODEFERWINDOWPOS - WINUSERAPI HDWP WINAPI BeginDeferWindowPos(int nNumWindows); - WINUSERAPI HDWP WINAPI DeferWindowPos(HDWP hWinPosInfo,HWND hWnd,HWND hWndInsertAfter,int x,int y,int cx,int cy,UINT uFlags); - WINUSERAPI WINBOOL WINAPI EndDeferWindowPos(HDWP hWinPosInfo); -#endif - - WINUSERAPI WINBOOL WINAPI IsWindowVisible(HWND hWnd); - WINUSERAPI WINBOOL WINAPI IsIconic(HWND hWnd); - WINUSERAPI WINBOOL WINAPI AnyPopup(VOID); - WINUSERAPI WINBOOL WINAPI BringWindowToTop(HWND hWnd); - WINUSERAPI WINBOOL WINAPI IsZoomed(HWND hWnd); - -#define SWP_NOSIZE 0x0001 -#define SWP_NOMOVE 0x0002 -#define SWP_NOZORDER 0x0004 -#define SWP_NOREDRAW 0x0008 -#define SWP_NOACTIVATE 0x0010 -#define SWP_FRAMECHANGED 0x0020 -#define SWP_SHOWWINDOW 0x0040 -#define SWP_HIDEWINDOW 0x0080 -#define SWP_NOCOPYBITS 0x0100 -#define SWP_NOOWNERZORDER 0x0200 -#define SWP_NOSENDCHANGING 0x0400 - -#define SWP_DRAWFRAME SWP_FRAMECHANGED -#define SWP_NOREPOSITION SWP_NOOWNERZORDER -#define SWP_DEFERERASE 0x2000 -#define SWP_ASYNCWINDOWPOS 0x4000 - -#define HWND_TOP ((HWND)0) -#define HWND_BOTTOM ((HWND)1) -#define HWND_TOPMOST ((HWND)-1) -#define HWND_NOTOPMOST ((HWND)-2) - -#ifndef NOCTLMGR - -#include - - typedef struct { - DWORD style; - DWORD dwExtendedStyle; - WORD cdit; - short x; - short y; - short cx; - short cy; - } DLGTEMPLATE; - - typedef DLGTEMPLATE *LPDLGTEMPLATEA; - typedef DLGTEMPLATE *LPDLGTEMPLATEW; - -#ifdef UNICODE - typedef LPDLGTEMPLATEW LPDLGTEMPLATE; -#else - typedef LPDLGTEMPLATEA LPDLGTEMPLATE; -#endif - - typedef CONST DLGTEMPLATE *LPCDLGTEMPLATEA; - typedef CONST DLGTEMPLATE *LPCDLGTEMPLATEW; - -#ifdef UNICODE - typedef LPCDLGTEMPLATEW LPCDLGTEMPLATE; -#else - typedef LPCDLGTEMPLATEA LPCDLGTEMPLATE; -#endif - - typedef struct { - DWORD style; - DWORD dwExtendedStyle; - short x; - short y; - short cx; - short cy; - WORD id; - } DLGITEMTEMPLATE; - - typedef DLGITEMTEMPLATE *PDLGITEMTEMPLATEA; - typedef DLGITEMTEMPLATE *PDLGITEMTEMPLATEW; - -#ifdef UNICODE - typedef PDLGITEMTEMPLATEW PDLGITEMTEMPLATE; -#else - typedef PDLGITEMTEMPLATEA PDLGITEMTEMPLATE; -#endif - - typedef DLGITEMTEMPLATE *LPDLGITEMTEMPLATEA; - typedef DLGITEMTEMPLATE *LPDLGITEMTEMPLATEW; - -#ifdef UNICODE - typedef LPDLGITEMTEMPLATEW LPDLGITEMTEMPLATE; -#else - typedef LPDLGITEMTEMPLATEA LPDLGITEMTEMPLATE; -#endif - -#include - -#ifdef UNICODE -#define CreateDialogParam CreateDialogParamW -#define CreateDialogIndirectParam CreateDialogIndirectParamW -#define CreateDialog CreateDialogW -#define CreateDialogIndirect CreateDialogIndirectW -#define DialogBoxParam DialogBoxParamW -#define DialogBoxIndirectParam DialogBoxIndirectParamW -#define DialogBox DialogBoxW -#define DialogBoxIndirect DialogBoxIndirectW -#define SetDlgItemText SetDlgItemTextW -#define GetDlgItemText GetDlgItemTextW -#define SendDlgItemMessage SendDlgItemMessageW -#define DefDlgProc DefDlgProcW -#else -#define CreateDialogParam CreateDialogParamA -#define CreateDialogIndirectParam CreateDialogIndirectParamA -#define CreateDialog CreateDialogA -#define CreateDialogIndirect CreateDialogIndirectA -#define DialogBoxParam DialogBoxParamA -#define DialogBoxIndirectParam DialogBoxIndirectParamA -#define DialogBox DialogBoxA -#define DialogBoxIndirect DialogBoxIndirectA -#define SetDlgItemText SetDlgItemTextA -#define GetDlgItemText GetDlgItemTextA -#define SendDlgItemMessage SendDlgItemMessageA -#define DefDlgProc DefDlgProcA -#endif - - WINUSERAPI HWND WINAPI CreateDialogParamA(HINSTANCE hInstance,LPCSTR lpTemplateName,HWND hWndParent,DLGPROC lpDialogFunc,LPARAM dwInitParam); - WINUSERAPI HWND WINAPI CreateDialogParamW(HINSTANCE hInstance,LPCWSTR lpTemplateName,HWND hWndParent,DLGPROC lpDialogFunc,LPARAM dwInitParam); - WINUSERAPI HWND WINAPI CreateDialogIndirectParamA(HINSTANCE hInstance,LPCDLGTEMPLATEA lpTemplate,HWND hWndParent,DLGPROC lpDialogFunc,LPARAM dwInitParam); - WINUSERAPI HWND WINAPI CreateDialogIndirectParamW(HINSTANCE hInstance,LPCDLGTEMPLATEW lpTemplate,HWND hWndParent,DLGPROC lpDialogFunc,LPARAM dwInitParam); -#define CreateDialogA(hInstance,lpName,hWndParent,lpDialogFunc) CreateDialogParamA(hInstance,lpName,hWndParent,lpDialogFunc,0L) -#define CreateDialogW(hInstance,lpName,hWndParent,lpDialogFunc) CreateDialogParamW(hInstance,lpName,hWndParent,lpDialogFunc,0L) -#define CreateDialogIndirectA(hInstance,lpTemplate,hWndParent,lpDialogFunc) CreateDialogIndirectParamA(hInstance,lpTemplate,hWndParent,lpDialogFunc,0L) -#define CreateDialogIndirectW(hInstance,lpTemplate,hWndParent,lpDialogFunc) CreateDialogIndirectParamW(hInstance,lpTemplate,hWndParent,lpDialogFunc,0L) - WINUSERAPI INT_PTR WINAPI DialogBoxParamA(HINSTANCE hInstance,LPCSTR lpTemplateName,HWND hWndParent,DLGPROC lpDialogFunc,LPARAM dwInitParam); - WINUSERAPI INT_PTR WINAPI DialogBoxParamW(HINSTANCE hInstance,LPCWSTR lpTemplateName,HWND hWndParent,DLGPROC lpDialogFunc,LPARAM dwInitParam); - WINUSERAPI INT_PTR WINAPI DialogBoxIndirectParamA(HINSTANCE hInstance,LPCDLGTEMPLATEA hDialogTemplate,HWND hWndParent,DLGPROC lpDialogFunc,LPARAM dwInitParam); - WINUSERAPI INT_PTR WINAPI DialogBoxIndirectParamW(HINSTANCE hInstance,LPCDLGTEMPLATEW hDialogTemplate,HWND hWndParent,DLGPROC lpDialogFunc,LPARAM dwInitParam); -#define DialogBoxA(hInstance,lpTemplate,hWndParent,lpDialogFunc) DialogBoxParamA(hInstance,lpTemplate,hWndParent,lpDialogFunc,0L) -#define DialogBoxW(hInstance,lpTemplate,hWndParent,lpDialogFunc) DialogBoxParamW(hInstance,lpTemplate,hWndParent,lpDialogFunc,0L) -#define DialogBoxIndirectA(hInstance,lpTemplate,hWndParent,lpDialogFunc) DialogBoxIndirectParamA(hInstance,lpTemplate,hWndParent,lpDialogFunc,0L) -#define DialogBoxIndirectW(hInstance,lpTemplate,hWndParent,lpDialogFunc) DialogBoxIndirectParamW(hInstance,lpTemplate,hWndParent,lpDialogFunc,0L) - WINUSERAPI WINBOOL WINAPI EndDialog(HWND hDlg,INT_PTR nResult); - WINUSERAPI HWND WINAPI GetDlgItem(HWND hDlg,int nIDDlgItem); - WINUSERAPI WINBOOL WINAPI SetDlgItemInt(HWND hDlg,int nIDDlgItem,UINT uValue,WINBOOL bSigned); - WINUSERAPI UINT WINAPI GetDlgItemInt(HWND hDlg,int nIDDlgItem,WINBOOL *lpTranslated,WINBOOL bSigned); - WINUSERAPI WINBOOL WINAPI SetDlgItemTextA(HWND hDlg,int nIDDlgItem,LPCSTR lpString); - WINUSERAPI WINBOOL WINAPI SetDlgItemTextW(HWND hDlg,int nIDDlgItem,LPCWSTR lpString); - WINUSERAPI UINT WINAPI GetDlgItemTextA(HWND hDlg,int nIDDlgItem,LPSTR lpString,int cchMax); - WINUSERAPI UINT WINAPI GetDlgItemTextW(HWND hDlg,int nIDDlgItem,LPWSTR lpString,int cchMax); - WINUSERAPI WINBOOL WINAPI CheckDlgButton(HWND hDlg,int nIDButton,UINT uCheck); - WINUSERAPI WINBOOL WINAPI CheckRadioButton(HWND hDlg,int nIDFirstButton,int nIDLastButton,int nIDCheckButton); - WINUSERAPI UINT WINAPI IsDlgButtonChecked(HWND hDlg,int nIDButton); - WINUSERAPI LRESULT WINAPI SendDlgItemMessageA(HWND hDlg,int nIDDlgItem,UINT Msg,WPARAM wParam,LPARAM lParam); - WINUSERAPI LRESULT WINAPI SendDlgItemMessageW(HWND hDlg,int nIDDlgItem,UINT Msg,WPARAM wParam,LPARAM lParam); - WINUSERAPI HWND WINAPI GetNextDlgGroupItem(HWND hDlg,HWND hCtl,WINBOOL bPrevious); - WINUSERAPI HWND WINAPI GetNextDlgTabItem(HWND hDlg,HWND hCtl,WINBOOL bPrevious); - WINUSERAPI int WINAPI GetDlgCtrlID(HWND hWnd); - WINUSERAPI long WINAPI GetDialogBaseUnits(VOID); - WINUSERAPI LRESULT WINAPI DefDlgProcA(HWND hDlg,UINT Msg,WPARAM wParam,LPARAM lParam); - WINUSERAPI LRESULT WINAPI DefDlgProcW(HWND hDlg,UINT Msg,WPARAM wParam,LPARAM lParam); - -#define DLGWINDOWEXTRA 30 -#endif - -#ifndef NOMSG - -#ifdef UNICODE -#define CallMsgFilter CallMsgFilterW -#else -#define CallMsgFilter CallMsgFilterA -#endif - - WINUSERAPI WINBOOL WINAPI CallMsgFilterA(LPMSG lpMsg,int nCode); - WINUSERAPI WINBOOL WINAPI CallMsgFilterW(LPMSG lpMsg,int nCode); -#endif - -#ifndef NOCLIPBOARD - -#ifdef UNICODE -#define RegisterClipboardFormat RegisterClipboardFormatW -#define GetClipboardFormatName GetClipboardFormatNameW -#else -#define RegisterClipboardFormat RegisterClipboardFormatA -#define GetClipboardFormatName GetClipboardFormatNameA -#endif - - WINUSERAPI WINBOOL WINAPI OpenClipboard(HWND hWndNewOwner); - WINUSERAPI WINBOOL WINAPI CloseClipboard(VOID); - WINUSERAPI DWORD WINAPI GetClipboardSequenceNumber(VOID); - WINUSERAPI HWND WINAPI GetClipboardOwner(VOID); - WINUSERAPI HWND WINAPI SetClipboardViewer(HWND hWndNewViewer); - WINUSERAPI HWND WINAPI GetClipboardViewer(VOID); - WINUSERAPI WINBOOL WINAPI ChangeClipboardChain(HWND hWndRemove,HWND hWndNewNext); - WINUSERAPI HANDLE WINAPI SetClipboardData(UINT uFormat,HANDLE hMem); - WINUSERAPI HANDLE WINAPI GetClipboardData(UINT uFormat); - WINUSERAPI UINT WINAPI RegisterClipboardFormatA(LPCSTR lpszFormat); - WINUSERAPI UINT WINAPI RegisterClipboardFormatW(LPCWSTR lpszFormat); - WINUSERAPI int WINAPI CountClipboardFormats(VOID); - WINUSERAPI UINT WINAPI EnumClipboardFormats(UINT format); - WINUSERAPI int WINAPI GetClipboardFormatNameA(UINT format,LPSTR lpszFormatName,int cchMaxCount); - WINUSERAPI int WINAPI GetClipboardFormatNameW(UINT format,LPWSTR lpszFormatName,int cchMaxCount); - WINUSERAPI WINBOOL WINAPI EmptyClipboard(VOID); - WINUSERAPI WINBOOL WINAPI IsClipboardFormatAvailable(UINT format); - WINUSERAPI int WINAPI GetPriorityClipboardFormat(UINT *paFormatPriorityList,int cFormats); - WINUSERAPI HWND WINAPI GetOpenClipboardWindow(VOID); -#endif - -#ifdef UNICODE -#define CharToOem CharToOemW -#define OemToChar OemToCharW -#define CharToOemBuff CharToOemBuffW -#define OemToCharBuff OemToCharBuffW -#define CharUpper CharUpperW -#define CharUpperBuff CharUpperBuffW -#define CharLower CharLowerW -#define CharLowerBuff CharLowerBuffW -#define CharNext CharNextW -#define CharPrev CharPrevW -#else -#define CharToOem CharToOemA -#define OemToChar OemToCharA -#define CharToOemBuff CharToOemBuffA -#define OemToCharBuff OemToCharBuffA -#define CharUpper CharUpperA -#define CharUpperBuff CharUpperBuffA -#define CharLower CharLowerA -#define CharLowerBuff CharLowerBuffA -#define CharNext CharNextA -#define CharPrev CharPrevA -#endif - - WINUSERAPI WINBOOL WINAPI CharToOemA(LPCSTR lpszSrc,LPSTR lpszDst); - WINUSERAPI WINBOOL WINAPI CharToOemW(LPCWSTR lpszSrc,LPSTR lpszDst); - WINUSERAPI WINBOOL WINAPI OemToCharA(LPCSTR lpszSrc,LPSTR lpszDst); - WINUSERAPI WINBOOL WINAPI OemToCharW(LPCSTR lpszSrc,LPWSTR lpszDst); - WINUSERAPI WINBOOL WINAPI CharToOemBuffA(LPCSTR lpszSrc,LPSTR lpszDst,DWORD cchDstLength); - WINUSERAPI WINBOOL WINAPI CharToOemBuffW(LPCWSTR lpszSrc,LPSTR lpszDst,DWORD cchDstLength); - WINUSERAPI WINBOOL WINAPI OemToCharBuffA(LPCSTR lpszSrc,LPSTR lpszDst,DWORD cchDstLength); - WINUSERAPI WINBOOL WINAPI OemToCharBuffW(LPCSTR lpszSrc,LPWSTR lpszDst,DWORD cchDstLength); - WINUSERAPI LPSTR WINAPI CharUpperA(LPSTR lpsz); - WINUSERAPI LPWSTR WINAPI CharUpperW(LPWSTR lpsz); - WINUSERAPI DWORD WINAPI CharUpperBuffA(LPSTR lpsz,DWORD cchLength); - WINUSERAPI DWORD WINAPI CharUpperBuffW(LPWSTR lpsz,DWORD cchLength); - WINUSERAPI LPSTR WINAPI CharLowerA(LPSTR lpsz); - WINUSERAPI LPWSTR WINAPI CharLowerW(LPWSTR lpsz); - WINUSERAPI DWORD WINAPI CharLowerBuffA(LPSTR lpsz,DWORD cchLength); - WINUSERAPI DWORD WINAPI CharLowerBuffW(LPWSTR lpsz,DWORD cchLength); - WINUSERAPI LPSTR WINAPI CharNextA(LPCSTR lpsz); - WINUSERAPI LPWSTR WINAPI CharNextW(LPCWSTR lpsz); - WINUSERAPI LPSTR WINAPI CharPrevA(LPCSTR lpszStart,LPCSTR lpszCurrent); - WINUSERAPI LPWSTR WINAPI CharPrevW(LPCWSTR lpszStart,LPCWSTR lpszCurrent); - WINUSERAPI LPSTR WINAPI CharNextExA(WORD CodePage,LPCSTR lpCurrentChar,DWORD dwFlags); - WINUSERAPI LPSTR WINAPI CharPrevExA(WORD CodePage,LPCSTR lpStart,LPCSTR lpCurrentChar,DWORD dwFlags); - -#define AnsiToOem CharToOemA -#define OemToAnsi OemToCharA -#define AnsiToOemBuff CharToOemBuffA -#define OemToAnsiBuff OemToCharBuffA -#define AnsiUpper CharUpperA -#define AnsiUpperBuff CharUpperBuffA -#define AnsiLower CharLowerA -#define AnsiLowerBuff CharLowerBuffA -#define AnsiNext CharNextA -#define AnsiPrev CharPrevA - -#ifndef NOLANGUAGE - -#ifdef UNICODE -#define IsCharAlpha IsCharAlphaW -#define IsCharAlphaNumeric IsCharAlphaNumericW -#define IsCharUpper IsCharUpperW -#define IsCharLower IsCharLowerW -#else -#define IsCharAlpha IsCharAlphaA -#define IsCharAlphaNumeric IsCharAlphaNumericA -#define IsCharUpper IsCharUpperA -#define IsCharLower IsCharLowerA -#endif - - WINUSERAPI WINBOOL WINAPI IsCharAlphaA(CHAR ch); - WINUSERAPI WINBOOL WINAPI IsCharAlphaW(WCHAR ch); - WINUSERAPI WINBOOL WINAPI IsCharAlphaNumericA(CHAR ch); - WINUSERAPI WINBOOL WINAPI IsCharAlphaNumericW(WCHAR ch); - WINUSERAPI WINBOOL WINAPI IsCharUpperA(CHAR ch); - WINUSERAPI WINBOOL WINAPI IsCharUpperW(WCHAR ch); - WINUSERAPI WINBOOL WINAPI IsCharLowerA(CHAR ch); - WINUSERAPI WINBOOL WINAPI IsCharLowerW(WCHAR ch); -#endif - -#ifdef UNICODE -#define GetKeyNameText GetKeyNameTextW -#define VkKeyScan VkKeyScanW -#define VkKeyScanEx VkKeyScanExW -#else -#define GetKeyNameText GetKeyNameTextA -#define VkKeyScan VkKeyScanA -#define VkKeyScanEx VkKeyScanExA -#endif - - WINUSERAPI HWND WINAPI SetFocus(HWND hWnd); - WINUSERAPI HWND WINAPI GetActiveWindow(VOID); - WINUSERAPI HWND WINAPI GetFocus(VOID); - WINUSERAPI UINT WINAPI GetKBCodePage(VOID); - WINUSERAPI SHORT WINAPI GetKeyState(int nVirtKey); - WINUSERAPI SHORT WINAPI GetAsyncKeyState(int vKey); - WINUSERAPI WINBOOL WINAPI GetKeyboardState(PBYTE lpKeyState); - WINUSERAPI WINBOOL WINAPI SetKeyboardState(LPBYTE lpKeyState); - WINUSERAPI int WINAPI GetKeyNameTextA(LONG lParam,LPSTR lpString,int cchSize); - WINUSERAPI int WINAPI GetKeyNameTextW(LONG lParam,LPWSTR lpString,int cchSize); - WINUSERAPI int WINAPI GetKeyboardType(int nTypeFlag); - WINUSERAPI int WINAPI ToAscii(UINT uVirtKey,UINT uScanCode,CONST BYTE *lpKeyState,LPWORD lpChar,UINT uFlags); - WINUSERAPI int WINAPI ToAsciiEx(UINT uVirtKey,UINT uScanCode,CONST BYTE *lpKeyState,LPWORD lpChar,UINT uFlags,HKL dwhkl); - WINUSERAPI int WINAPI ToUnicode(UINT wVirtKey,UINT wScanCode,CONST BYTE *lpKeyState,LPWSTR pwszBuff,int cchBuff,UINT wFlags); - WINUSERAPI DWORD WINAPI OemKeyScan(WORD wOemChar); - WINUSERAPI SHORT WINAPI VkKeyScanA(CHAR ch); - WINUSERAPI SHORT WINAPI VkKeyScanW(WCHAR ch); - WINUSERAPI SHORT WINAPI VkKeyScanExA(CHAR ch,HKL dwhkl); - WINUSERAPI SHORT WINAPI VkKeyScanExW(WCHAR ch,HKL dwhkl); - -#define KEYEVENTF_EXTENDEDKEY 0x0001 -#define KEYEVENTF_KEYUP 0x0002 -#define KEYEVENTF_UNICODE 0x0004 -#define KEYEVENTF_SCANCODE 0x0008 - - WINUSERAPI VOID WINAPI keybd_event(BYTE bVk,BYTE bScan,DWORD dwFlags,ULONG_PTR dwExtraInfo); - -#define MOUSEEVENTF_MOVE 0x0001 -#define MOUSEEVENTF_LEFTDOWN 0x0002 -#define MOUSEEVENTF_LEFTUP 0x0004 -#define MOUSEEVENTF_RIGHTDOWN 0x0008 -#define MOUSEEVENTF_RIGHTUP 0x0010 -#define MOUSEEVENTF_MIDDLEDOWN 0x0020 -#define MOUSEEVENTF_MIDDLEUP 0x0040 -#define MOUSEEVENTF_XDOWN 0x0080 -#define MOUSEEVENTF_XUP 0x0100 -#define MOUSEEVENTF_WHEEL 0x0800 -#define MOUSEEVENTF_VIRTUALDESK 0x4000 -#define MOUSEEVENTF_ABSOLUTE 0x8000 - - WINUSERAPI VOID WINAPI mouse_event(DWORD dwFlags,DWORD dx,DWORD dy,DWORD dwData,ULONG_PTR dwExtraInfo); - - typedef struct tagMOUSEINPUT { - LONG dx; - LONG dy; - DWORD mouseData; - DWORD dwFlags; - DWORD time; - ULONG_PTR dwExtraInfo; - } MOUSEINPUT,*PMOUSEINPUT,*LPMOUSEINPUT; - - typedef struct tagKEYBDINPUT { - WORD wVk; - WORD wScan; - DWORD dwFlags; - DWORD time; - ULONG_PTR dwExtraInfo; - } KEYBDINPUT,*PKEYBDINPUT,*LPKEYBDINPUT; - - typedef struct tagHARDWAREINPUT { - DWORD uMsg; - WORD wParamL; - WORD wParamH; - } HARDWAREINPUT,*PHARDWAREINPUT,*LPHARDWAREINPUT; - -#define INPUT_MOUSE 0 -#define INPUT_KEYBOARD 1 -#define INPUT_HARDWARE 2 - - typedef struct tagINPUT { - DWORD type; - union { - MOUSEINPUT mi; - KEYBDINPUT ki; - HARDWAREINPUT hi; - }; - } INPUT,*PINPUT,*LPINPUT; - - WINUSERAPI UINT WINAPI SendInput(UINT cInputs,LPINPUT pInputs,int cbSize); - - typedef struct tagLASTINPUTINFO { - UINT cbSize; - DWORD dwTime; - } LASTINPUTINFO,*PLASTINPUTINFO; - -#ifdef UNICODE -#define MapVirtualKey MapVirtualKeyW -#define MapVirtualKeyEx MapVirtualKeyExW -#else -#define MapVirtualKey MapVirtualKeyA -#define MapVirtualKeyEx MapVirtualKeyExA -#endif - - WINUSERAPI WINBOOL WINAPI GetLastInputInfo(PLASTINPUTINFO plii); - WINUSERAPI UINT WINAPI MapVirtualKeyA(UINT uCode,UINT uMapType); - WINUSERAPI UINT WINAPI MapVirtualKeyW(UINT uCode,UINT uMapType); - WINUSERAPI UINT WINAPI MapVirtualKeyExA(UINT uCode,UINT uMapType,HKL dwhkl); - WINUSERAPI UINT WINAPI MapVirtualKeyExW(UINT uCode,UINT uMapType,HKL dwhkl); - WINUSERAPI WINBOOL WINAPI GetInputState(VOID); - WINUSERAPI DWORD WINAPI GetQueueStatus(UINT flags); - WINUSERAPI HWND WINAPI GetCapture(VOID); - WINUSERAPI HWND WINAPI SetCapture(HWND hWnd); - WINUSERAPI WINBOOL WINAPI ReleaseCapture(VOID); - WINUSERAPI DWORD WINAPI MsgWaitForMultipleObjects(DWORD nCount,CONST HANDLE *pHandles,WINBOOL fWaitAll,DWORD dwMilliseconds,DWORD dwWakeMask); - WINUSERAPI DWORD WINAPI MsgWaitForMultipleObjectsEx(DWORD nCount,CONST HANDLE *pHandles,DWORD dwMilliseconds,DWORD dwWakeMask,DWORD dwFlags); - -#define MWMO_WAITALL 0x0001 -#define MWMO_ALERTABLE 0x0002 -#define MWMO_INPUTAVAILABLE 0x0004 - -#define QS_KEY 0x0001 -#define QS_MOUSEMOVE 0x0002 -#define QS_MOUSEBUTTON 0x0004 -#define QS_POSTMESSAGE 0x0008 -#define QS_TIMER 0x0010 -#define QS_PAINT 0x0020 -#define QS_SENDMESSAGE 0x0040 -#define QS_HOTKEY 0x0080 -#define QS_ALLPOSTMESSAGE 0x0100 -#define QS_RAWINPUT 0x0400 -#define QS_MOUSE (QS_MOUSEMOVE | QS_MOUSEBUTTON) -#define QS_INPUT (QS_MOUSE | QS_KEY | QS_RAWINPUT) -#define QS_ALLEVENTS (QS_INPUT | QS_POSTMESSAGE | QS_TIMER | QS_PAINT | QS_HOTKEY) -#define QS_ALLINPUT (QS_INPUT | QS_POSTMESSAGE | QS_TIMER | QS_PAINT | QS_HOTKEY | QS_SENDMESSAGE) - -#define USER_TIMER_MAXIMUM 0x7FFFFFFF -#define USER_TIMER_MINIMUM 0x0000000A - -#ifdef UNICODE -#define LoadAccelerators LoadAcceleratorsW -#define CreateAcceleratorTable CreateAcceleratorTableW -#define CopyAcceleratorTable CopyAcceleratorTableW -#else -#define LoadAccelerators LoadAcceleratorsA -#define CreateAcceleratorTable CreateAcceleratorTableA -#define CopyAcceleratorTable CopyAcceleratorTableA -#endif - - WINUSERAPI UINT_PTR WINAPI SetTimer(HWND hWnd,UINT_PTR nIDEvent,UINT uElapse,TIMERPROC lpTimerFunc); - WINUSERAPI WINBOOL WINAPI KillTimer(HWND hWnd,UINT_PTR uIDEvent); - WINUSERAPI WINBOOL WINAPI IsWindowUnicode(HWND hWnd); - WINUSERAPI WINBOOL WINAPI EnableWindow(HWND hWnd,WINBOOL bEnable); - WINUSERAPI WINBOOL WINAPI IsWindowEnabled(HWND hWnd); - WINUSERAPI HACCEL WINAPI LoadAcceleratorsA(HINSTANCE hInstance,LPCSTR lpTableName); - WINUSERAPI HACCEL WINAPI LoadAcceleratorsW(HINSTANCE hInstance,LPCWSTR lpTableName); - WINUSERAPI HACCEL WINAPI CreateAcceleratorTableA(LPACCEL paccel,int cAccel); - WINUSERAPI HACCEL WINAPI CreateAcceleratorTableW(LPACCEL paccel,int cAccel); - WINUSERAPI WINBOOL WINAPI DestroyAcceleratorTable(HACCEL hAccel); - WINUSERAPI int WINAPI CopyAcceleratorTableA(HACCEL hAccelSrc,LPACCEL lpAccelDst,int cAccelEntries); - WINUSERAPI int WINAPI CopyAcceleratorTableW(HACCEL hAccelSrc,LPACCEL lpAccelDst,int cAccelEntries); - -#ifndef NOMSG - -#ifdef UNICODE -#define TranslateAccelerator TranslateAcceleratorW -#else -#define TranslateAccelerator TranslateAcceleratorA -#endif - - WINUSERAPI int WINAPI TranslateAcceleratorA(HWND hWnd,HACCEL hAccTable,LPMSG lpMsg); - WINUSERAPI int WINAPI TranslateAcceleratorW(HWND hWnd,HACCEL hAccTable,LPMSG lpMsg); -#endif - -#ifndef NOSYSMETRICS - -#define SM_CXSCREEN 0 -#define SM_CYSCREEN 1 -#define SM_CXVSCROLL 2 -#define SM_CYHSCROLL 3 -#define SM_CYCAPTION 4 -#define SM_CXBORDER 5 -#define SM_CYBORDER 6 -#define SM_CXDLGFRAME 7 -#define SM_CYDLGFRAME 8 -#define SM_CYVTHUMB 9 -#define SM_CXHTHUMB 10 -#define SM_CXICON 11 -#define SM_CYICON 12 -#define SM_CXCURSOR 13 -#define SM_CYCURSOR 14 -#define SM_CYMENU 15 -#define SM_CXFULLSCREEN 16 -#define SM_CYFULLSCREEN 17 -#define SM_CYKANJIWINDOW 18 -#define SM_MOUSEPRESENT 19 -#define SM_CYVSCROLL 20 -#define SM_CXHSCROLL 21 -#define SM_DEBUG 22 -#define SM_SWAPBUTTON 23 -#define SM_RESERVED1 24 -#define SM_RESERVED2 25 -#define SM_RESERVED3 26 -#define SM_RESERVED4 27 -#define SM_CXMIN 28 -#define SM_CYMIN 29 -#define SM_CXSIZE 30 -#define SM_CYSIZE 31 -#define SM_CXFRAME 32 -#define SM_CYFRAME 33 -#define SM_CXMINTRACK 34 -#define SM_CYMINTRACK 35 -#define SM_CXDOUBLECLK 36 -#define SM_CYDOUBLECLK 37 -#define SM_CXICONSPACING 38 -#define SM_CYICONSPACING 39 -#define SM_MENUDROPALIGNMENT 40 -#define SM_PENWINDOWS 41 -#define SM_DBCSENABLED 42 -#define SM_CMOUSEBUTTONS 43 - -#define SM_CXFIXEDFRAME SM_CXDLGFRAME -#define SM_CYFIXEDFRAME SM_CYDLGFRAME -#define SM_CXSIZEFRAME SM_CXFRAME -#define SM_CYSIZEFRAME SM_CYFRAME - -#define SM_SECURE 44 -#define SM_CXEDGE 45 -#define SM_CYEDGE 46 -#define SM_CXMINSPACING 47 -#define SM_CYMINSPACING 48 -#define SM_CXSMICON 49 -#define SM_CYSMICON 50 -#define SM_CYSMCAPTION 51 -#define SM_CXSMSIZE 52 -#define SM_CYSMSIZE 53 -#define SM_CXMENUSIZE 54 -#define SM_CYMENUSIZE 55 -#define SM_ARRANGE 56 -#define SM_CXMINIMIZED 57 -#define SM_CYMINIMIZED 58 -#define SM_CXMAXTRACK 59 -#define SM_CYMAXTRACK 60 -#define SM_CXMAXIMIZED 61 -#define SM_CYMAXIMIZED 62 -#define SM_NETWORK 63 -#define SM_CLEANBOOT 67 -#define SM_CXDRAG 68 -#define SM_CYDRAG 69 -#define SM_SHOWSOUNDS 70 -#define SM_CXMENUCHECK 71 -#define SM_CYMENUCHECK 72 -#define SM_SLOWMACHINE 73 -#define SM_MIDEASTENABLED 74 -#define SM_MOUSEWHEELPRESENT 75 -#define SM_XVIRTUALSCREEN 76 -#define SM_YVIRTUALSCREEN 77 -#define SM_CXVIRTUALSCREEN 78 -#define SM_CYVIRTUALSCREEN 79 -#define SM_CMONITORS 80 -#define SM_SAMEDISPLAYFORMAT 81 -#define SM_IMMENABLED 82 -#define SM_CXFOCUSBORDER 83 -#define SM_CYFOCUSBORDER 84 -#define SM_TABLETPC 86 -#define SM_MEDIACENTER 87 -#define SM_STARTER 88 -#define SM_SERVERR2 89 -#define SM_CMETRICS 90 -#define SM_REMOTESESSION 0x1000 -#define SM_SHUTTINGDOWN 0x2000 -#define SM_REMOTECONTROL 0x2001 -#define SM_CARETBLINKINGENABLED 0x2002 - - WINUSERAPI int WINAPI GetSystemMetrics(int nIndex); -#endif - -#ifndef NOMENUS - -#ifdef UNICODE -#define LoadMenu LoadMenuW -#define LoadMenuIndirect LoadMenuIndirectW -#define ChangeMenu ChangeMenuW -#define GetMenuString GetMenuStringW -#define InsertMenu InsertMenuW -#define AppendMenu AppendMenuW -#define ModifyMenu ModifyMenuW -#else -#define LoadMenu LoadMenuA -#define LoadMenuIndirect LoadMenuIndirectA -#define ChangeMenu ChangeMenuA -#define GetMenuString GetMenuStringA -#define InsertMenu InsertMenuA -#define AppendMenu AppendMenuA -#define ModifyMenu ModifyMenuA -#endif - - WINUSERAPI HMENU WINAPI LoadMenuA(HINSTANCE hInstance,LPCSTR lpMenuName); - WINUSERAPI HMENU WINAPI LoadMenuW(HINSTANCE hInstance,LPCWSTR lpMenuName); - WINUSERAPI HMENU WINAPI LoadMenuIndirectA(CONST MENUTEMPLATEA *lpMenuTemplate); - WINUSERAPI HMENU WINAPI LoadMenuIndirectW(CONST MENUTEMPLATEW *lpMenuTemplate); - WINUSERAPI HMENU WINAPI GetMenu(HWND hWnd); - WINUSERAPI WINBOOL WINAPI SetMenu(HWND hWnd,HMENU hMenu); - WINUSERAPI WINBOOL WINAPI ChangeMenuA(HMENU hMenu,UINT cmd,LPCSTR lpszNewItem,UINT cmdInsert,UINT flags); - WINUSERAPI WINBOOL WINAPI ChangeMenuW(HMENU hMenu,UINT cmd,LPCWSTR lpszNewItem,UINT cmdInsert,UINT flags); - WINUSERAPI WINBOOL WINAPI HiliteMenuItem(HWND hWnd,HMENU hMenu,UINT uIDHiliteItem,UINT uHilite); - WINUSERAPI int WINAPI GetMenuStringA(HMENU hMenu,UINT uIDItem,LPSTR lpString,int cchMax,UINT flags); - WINUSERAPI int WINAPI GetMenuStringW(HMENU hMenu,UINT uIDItem,LPWSTR lpString,int cchMax,UINT flags); - WINUSERAPI UINT WINAPI GetMenuState(HMENU hMenu,UINT uId,UINT uFlags); - WINUSERAPI WINBOOL WINAPI DrawMenuBar(HWND hWnd); - -#define PMB_ACTIVE 0x00000001 - - WINUSERAPI HMENU WINAPI GetSystemMenu(HWND hWnd,WINBOOL bRevert); - WINUSERAPI HMENU WINAPI CreateMenu(VOID); - WINUSERAPI HMENU WINAPI CreatePopupMenu(VOID); - WINUSERAPI WINBOOL WINAPI DestroyMenu(HMENU hMenu); - WINUSERAPI DWORD WINAPI CheckMenuItem(HMENU hMenu,UINT uIDCheckItem,UINT uCheck); - WINUSERAPI WINBOOL WINAPI EnableMenuItem(HMENU hMenu,UINT uIDEnableItem,UINT uEnable); - WINUSERAPI HMENU WINAPI GetSubMenu(HMENU hMenu,int nPos); - WINUSERAPI UINT WINAPI GetMenuItemID(HMENU hMenu,int nPos); - WINUSERAPI int WINAPI GetMenuItemCount(HMENU hMenu); - WINUSERAPI WINBOOL WINAPI InsertMenuA(HMENU hMenu,UINT uPosition,UINT uFlags,UINT_PTR uIDNewItem,LPCSTR lpNewItem); - WINUSERAPI WINBOOL WINAPI InsertMenuW(HMENU hMenu,UINT uPosition,UINT uFlags,UINT_PTR uIDNewItem,LPCWSTR lpNewItem); - WINUSERAPI WINBOOL WINAPI AppendMenuA(HMENU hMenu,UINT uFlags,UINT_PTR uIDNewItem,LPCSTR lpNewItem); - WINUSERAPI WINBOOL WINAPI AppendMenuW(HMENU hMenu,UINT uFlags,UINT_PTR uIDNewItem,LPCWSTR lpNewItem); - WINUSERAPI WINBOOL WINAPI ModifyMenuA(HMENU hMnu,UINT uPosition,UINT uFlags,UINT_PTR uIDNewItem,LPCSTR lpNewItem); - WINUSERAPI WINBOOL WINAPI ModifyMenuW(HMENU hMnu,UINT uPosition,UINT uFlags,UINT_PTR uIDNewItem,LPCWSTR lpNewItem); - WINUSERAPI WINBOOL WINAPI RemoveMenu(HMENU hMenu,UINT uPosition,UINT uFlags); - WINUSERAPI WINBOOL WINAPI DeleteMenu(HMENU hMenu,UINT uPosition,UINT uFlags); - WINUSERAPI WINBOOL WINAPI SetMenuItemBitmaps(HMENU hMenu,UINT uPosition,UINT uFlags,HBITMAP hBitmapUnchecked,HBITMAP hBitmapChecked); - WINUSERAPI LONG WINAPI GetMenuCheckMarkDimensions(VOID); - WINUSERAPI WINBOOL WINAPI TrackPopupMenu(HMENU hMenu,UINT uFlags,int x,int y,int nReserved,HWND hWnd,CONST RECT *prcRect); - -#define MNC_IGNORE 0 -#define MNC_CLOSE 1 -#define MNC_EXECUTE 2 -#define MNC_SELECT 3 - - typedef struct tagTPMPARAMS { - UINT cbSize; - RECT rcExclude; - } TPMPARAMS; - - typedef TPMPARAMS *LPTPMPARAMS; - - WINUSERAPI WINBOOL WINAPI TrackPopupMenuEx(HMENU,UINT,int,int,HWND,LPTPMPARAMS); - -#define MNS_NOCHECK 0x80000000 -#define MNS_MODELESS 0x40000000 -#define MNS_DRAGDROP 0x20000000 -#define MNS_AUTODISMISS 0x10000000 -#define MNS_NOTIFYBYPOS 0x08000000 -#define MNS_CHECKORBMP 0x04000000 - -#define MIM_MAXHEIGHT 0x00000001 -#define MIM_BACKGROUND 0x00000002 -#define MIM_HELPID 0x00000004 -#define MIM_MENUDATA 0x00000008 -#define MIM_STYLE 0x00000010 -#define MIM_APPLYTOSUBMENUS 0x80000000 - - typedef struct tagMENUINFO { - DWORD cbSize; - DWORD fMask; - DWORD dwStyle; - UINT cyMax; - HBRUSH hbrBack; - DWORD dwContextHelpID; - ULONG_PTR dwMenuData; - } MENUINFO,*LPMENUINFO; - - typedef MENUINFO CONST *LPCMENUINFO; - - WINUSERAPI WINBOOL WINAPI GetMenuInfo(HMENU,LPMENUINFO); - WINUSERAPI WINBOOL WINAPI SetMenuInfo(HMENU,LPCMENUINFO); - WINUSERAPI WINBOOL WINAPI EndMenu(VOID); - -#define MND_CONTINUE 0 -#define MND_ENDMENU 1 - - typedef struct tagMENUGETOBJECTINFO { - DWORD dwFlags; - UINT uPos; - HMENU hmenu; - PVOID riid; - PVOID pvObj; - } MENUGETOBJECTINFO,*PMENUGETOBJECTINFO; - -#define MNGOF_TOPGAP 0x00000001 -#define MNGOF_BOTTOMGAP 0x00000002 - -#define MNGO_NOINTERFACE 0x00000000 -#define MNGO_NOERROR 0x00000001 - -#define MIIM_STATE 0x00000001 -#define MIIM_ID 0x00000002 -#define MIIM_SUBMENU 0x00000004 -#define MIIM_CHECKMARKS 0x00000008 -#define MIIM_TYPE 0x00000010 -#define MIIM_DATA 0x00000020 - -#define MIIM_STRING 0x00000040 -#define MIIM_BITMAP 0x00000080 -#define MIIM_FTYPE 0x00000100 - -#define HBMMENU_CALLBACK ((HBITMAP) -1) -#define HBMMENU_SYSTEM ((HBITMAP) 1) -#define HBMMENU_MBAR_RESTORE ((HBITMAP) 2) -#define HBMMENU_MBAR_MINIMIZE ((HBITMAP) 3) -#define HBMMENU_MBAR_CLOSE ((HBITMAP) 5) -#define HBMMENU_MBAR_CLOSE_D ((HBITMAP) 6) -#define HBMMENU_MBAR_MINIMIZE_D ((HBITMAP) 7) -#define HBMMENU_POPUP_CLOSE ((HBITMAP) 8) -#define HBMMENU_POPUP_RESTORE ((HBITMAP) 9) -#define HBMMENU_POPUP_MAXIMIZE ((HBITMAP) 10) -#define HBMMENU_POPUP_MINIMIZE ((HBITMAP) 11) - - typedef struct tagMENUITEMINFOA { - UINT cbSize; - UINT fMask; - UINT fType; - UINT fState; - UINT wID; - HMENU hSubMenu; - HBITMAP hbmpChecked; - HBITMAP hbmpUnchecked; - ULONG_PTR dwItemData; - LPSTR dwTypeData; - UINT cch; - HBITMAP hbmpItem; - } MENUITEMINFOA,*LPMENUITEMINFOA; - - typedef struct tagMENUITEMINFOW { - UINT cbSize; - UINT fMask; - UINT fType; - UINT fState; - UINT wID; - HMENU hSubMenu; - HBITMAP hbmpChecked; - HBITMAP hbmpUnchecked; - ULONG_PTR dwItemData; - LPWSTR dwTypeData; - UINT cch; - HBITMAP hbmpItem; - } MENUITEMINFOW,*LPMENUITEMINFOW; - -#ifdef UNICODE - typedef MENUITEMINFOW MENUITEMINFO; - typedef LPMENUITEMINFOW LPMENUITEMINFO; -#else - typedef MENUITEMINFOA MENUITEMINFO; - typedef LPMENUITEMINFOA LPMENUITEMINFO; -#endif - typedef MENUITEMINFOA CONST *LPCMENUITEMINFOA; - typedef MENUITEMINFOW CONST *LPCMENUITEMINFOW; -#ifdef UNICODE - typedef LPCMENUITEMINFOW LPCMENUITEMINFO; -#else - typedef LPCMENUITEMINFOA LPCMENUITEMINFO; -#endif - -#ifdef UNICODE -#define InsertMenuItem InsertMenuItemW -#define GetMenuItemInfo GetMenuItemInfoW -#define SetMenuItemInfo SetMenuItemInfoW -#else -#define InsertMenuItem InsertMenuItemA -#define GetMenuItemInfo GetMenuItemInfoA -#define SetMenuItemInfo SetMenuItemInfoA -#endif - - WINUSERAPI WINBOOL WINAPI InsertMenuItemA(HMENU hmenu,UINT item,WINBOOL fByPosition,LPCMENUITEMINFOA lpmi); - WINUSERAPI WINBOOL WINAPI InsertMenuItemW(HMENU hmenu,UINT item,WINBOOL fByPosition,LPCMENUITEMINFOW lpmi); - WINUSERAPI WINBOOL WINAPI GetMenuItemInfoA(HMENU hmenu,UINT item,WINBOOL fByPosition,LPMENUITEMINFOA lpmii); - WINUSERAPI WINBOOL WINAPI GetMenuItemInfoW(HMENU hmenu,UINT item,WINBOOL fByPosition,LPMENUITEMINFOW lpmii); - WINUSERAPI WINBOOL WINAPI SetMenuItemInfoA(HMENU hmenu,UINT item,WINBOOL fByPositon,LPCMENUITEMINFOA lpmii); - WINUSERAPI WINBOOL WINAPI SetMenuItemInfoW(HMENU hmenu,UINT item,WINBOOL fByPositon,LPCMENUITEMINFOW lpmii); - -#define GMDI_USEDISABLED 0x0001L -#define GMDI_GOINTOPOPUPS 0x0002L - - WINUSERAPI UINT WINAPI GetMenuDefaultItem(HMENU hMenu,UINT fByPos,UINT gmdiFlags); - WINUSERAPI WINBOOL WINAPI SetMenuDefaultItem(HMENU hMenu,UINT uItem,UINT fByPos); - WINUSERAPI WINBOOL WINAPI GetMenuItemRect(HWND hWnd,HMENU hMenu,UINT uItem,LPRECT lprcItem); - WINUSERAPI int WINAPI MenuItemFromPoint(HWND hWnd,HMENU hMenu,POINT ptScreen); - -#define TPM_LEFTBUTTON 0x0000L -#define TPM_RIGHTBUTTON 0x0002L -#define TPM_LEFTALIGN 0x0000L -#define TPM_CENTERALIGN 0x0004L -#define TPM_RIGHTALIGN 0x0008L -#define TPM_TOPALIGN 0x0000L -#define TPM_VCENTERALIGN 0x0010L -#define TPM_BOTTOMALIGN 0x0020L - -#define TPM_HORIZONTAL 0x0000L -#define TPM_VERTICAL 0x0040L -#define TPM_NONOTIFY 0x0080L -#define TPM_RETURNCMD 0x0100L -#define TPM_RECURSE 0x0001L -#define TPM_HORPOSANIMATION 0x0400L -#define TPM_HORNEGANIMATION 0x0800L -#define TPM_VERPOSANIMATION 0x1000L -#define TPM_VERNEGANIMATION 0x2000L -#define TPM_NOANIMATION 0x4000L -#define TPM_LAYOUTRTL 0x8000L -#endif - - typedef struct tagDROPSTRUCT { - HWND hwndSource; - HWND hwndSink; - DWORD wFmt; - ULONG_PTR dwData; - POINT ptDrop; - DWORD dwControlData; - } DROPSTRUCT,*PDROPSTRUCT,*LPDROPSTRUCT; - -#define DOF_EXECUTABLE 0x8001 -#define DOF_DOCUMENT 0x8002 -#define DOF_DIRECTORY 0x8003 -#define DOF_MULTIPLE 0x8004 -#define DOF_PROGMAN 0x0001 -#define DOF_SHELLDATA 0x0002 - -#define DO_DROPFILE 0x454C4946L -#define DO_PRINTFILE 0x544E5250L - - WINUSERAPI DWORD WINAPI DragObject(HWND hwndParent,HWND hwndFrom,UINT fmt,ULONG_PTR data,HCURSOR hcur); - WINUSERAPI WINBOOL WINAPI DragDetect(HWND hwnd,POINT pt); - WINUSERAPI WINBOOL WINAPI DrawIcon(HDC hDC,int X,int Y,HICON hIcon); - -#ifndef NODRAWTEXT - -#define DT_TOP 0x00000000 -#define DT_LEFT 0x00000000 -#define DT_CENTER 0x00000001 -#define DT_RIGHT 0x00000002 -#define DT_VCENTER 0x00000004 -#define DT_BOTTOM 0x00000008 -#define DT_WORDBREAK 0x00000010 -#define DT_SINGLELINE 0x00000020 -#define DT_EXPANDTABS 0x00000040 -#define DT_TABSTOP 0x00000080 -#define DT_NOCLIP 0x00000100 -#define DT_EXTERNALLEADING 0x00000200 -#define DT_CALCRECT 0x00000400 -#define DT_NOPREFIX 0x00000800 -#define DT_INTERNAL 0x00001000 - -#define DT_EDITCONTROL 0x00002000 -#define DT_PATH_ELLIPSIS 0x00004000 -#define DT_END_ELLIPSIS 0x00008000 -#define DT_MODIFYSTRING 0x00010000 -#define DT_RTLREADING 0x00020000 -#define DT_WORD_ELLIPSIS 0x00040000 -#define DT_NOFULLWIDTHCHARBREAK 0x00080000 -#define DT_HIDEPREFIX 0x00100000 -#define DT_PREFIXONLY 0x00200000 - - typedef struct tagDRAWTEXTPARAMS { - UINT cbSize; - int iTabLength; - int iLeftMargin; - int iRightMargin; - UINT uiLengthDrawn; - } DRAWTEXTPARAMS,*LPDRAWTEXTPARAMS; - -#ifdef UNICODE -#define DrawText DrawTextW -#define DrawTextEx DrawTextExW -#else -#define DrawText DrawTextA -#define DrawTextEx DrawTextExA -#endif - - WINUSERAPI int WINAPI DrawTextA(HDC hdc,LPCSTR lpchText,int cchText,LPRECT lprc,UINT format); - WINUSERAPI int WINAPI DrawTextW(HDC hdc,LPCWSTR lpchText,int cchText,LPRECT lprc,UINT format); - WINUSERAPI int WINAPI DrawTextExA(HDC hdc,LPSTR lpchText,int cchText,LPRECT lprc,UINT format,LPDRAWTEXTPARAMS lpdtp); - WINUSERAPI int WINAPI DrawTextExW(HDC hdc,LPWSTR lpchText,int cchText,LPRECT lprc,UINT format,LPDRAWTEXTPARAMS lpdtp); -#endif - -#ifdef UNICODE -#define GrayString GrayStringW -#define DrawState DrawStateW -#define TabbedTextOut TabbedTextOutW -#define GetTabbedTextExtent GetTabbedTextExtentW -#else -#define GrayString GrayStringA -#define DrawState DrawStateA -#define TabbedTextOut TabbedTextOutA -#define GetTabbedTextExtent GetTabbedTextExtentA -#endif - - WINUSERAPI WINBOOL WINAPI GrayStringA(HDC hDC,HBRUSH hBrush,GRAYSTRINGPROC lpOutputFunc,LPARAM lpData,int nCount,int X,int Y,int nWidth,int nHeight); - WINUSERAPI WINBOOL WINAPI GrayStringW(HDC hDC,HBRUSH hBrush,GRAYSTRINGPROC lpOutputFunc,LPARAM lpData,int nCount,int X,int Y,int nWidth,int nHeight); - -#define DST_COMPLEX 0x0000 -#define DST_TEXT 0x0001 -#define DST_PREFIXTEXT 0x0002 -#define DST_ICON 0x0003 -#define DST_BITMAP 0x0004 - -#define DSS_NORMAL 0x0000 -#define DSS_UNION 0x0010 -#define DSS_DISABLED 0x0020 -#define DSS_MONO 0x0080 -#define DSS_HIDEPREFIX 0x0200 -#define DSS_PREFIXONLY 0x0400 -#define DSS_RIGHT 0x8000 - - WINUSERAPI WINBOOL WINAPI DrawStateA(HDC hdc,HBRUSH hbrFore,DRAWSTATEPROC qfnCallBack,LPARAM lData,WPARAM wData,int x,int y,int cx,int cy,UINT uFlags); - WINUSERAPI WINBOOL WINAPI DrawStateW(HDC hdc,HBRUSH hbrFore,DRAWSTATEPROC qfnCallBack,LPARAM lData,WPARAM wData,int x,int y,int cx,int cy,UINT uFlags); - WINUSERAPI LONG WINAPI TabbedTextOutA(HDC hdc,int x,int y,LPCSTR lpString,int chCount,int nTabPositions,CONST INT *lpnTabStopPositions,int nTabOrigin); - WINUSERAPI LONG WINAPI TabbedTextOutW(HDC hdc,int x,int y,LPCWSTR lpString,int chCount,int nTabPositions,CONST INT *lpnTabStopPositions,int nTabOrigin); - WINUSERAPI DWORD WINAPI GetTabbedTextExtentA(HDC hdc,LPCSTR lpString,int chCount,int nTabPositions,CONST INT *lpnTabStopPositions); - WINUSERAPI DWORD WINAPI GetTabbedTextExtentW(HDC hdc,LPCWSTR lpString,int chCount,int nTabPositions,CONST INT *lpnTabStopPositions); - WINUSERAPI WINBOOL WINAPI UpdateWindow(HWND hWnd); - WINUSERAPI HWND WINAPI SetActiveWindow(HWND hWnd); - WINUSERAPI HWND WINAPI GetForegroundWindow(VOID); - WINUSERAPI WINBOOL WINAPI PaintDesktop(HDC hdc); - WINUSERAPI VOID WINAPI SwitchToThisWindow(HWND hwnd,WINBOOL fUnknown); - WINUSERAPI WINBOOL WINAPI SetForegroundWindow(HWND hWnd); - WINUSERAPI WINBOOL WINAPI AllowSetForegroundWindow(DWORD dwProcessId); - -#define ASFW_ANY ((DWORD)-1) - - WINUSERAPI WINBOOL WINAPI LockSetForegroundWindow(UINT uLockCode); - -#define LSFW_LOCK 1 -#define LSFW_UNLOCK 2 - - WINUSERAPI HWND WINAPI WindowFromDC(HDC hDC); - WINUSERAPI HDC WINAPI GetDC(HWND hWnd); - WINUSERAPI HDC WINAPI GetDCEx(HWND hWnd,HRGN hrgnClip,DWORD flags); - -#define DCX_WINDOW 0x00000001L -#define DCX_CACHE 0x00000002L -#define DCX_NORESETATTRS 0x00000004L -#define DCX_CLIPCHILDREN 0x00000008L -#define DCX_CLIPSIBLINGS 0x00000010L -#define DCX_PARENTCLIP 0x00000020L -#define DCX_EXCLUDERGN 0x00000040L -#define DCX_INTERSECTRGN 0x00000080L -#define DCX_EXCLUDEUPDATE 0x00000100L -#define DCX_INTERSECTUPDATE 0x00000200L -#define DCX_LOCKWINDOWUPDATE 0x00000400L - -#define DCX_VALIDATE 0x00200000L - - WINUSERAPI HDC WINAPI GetWindowDC(HWND hWnd); - WINUSERAPI int WINAPI ReleaseDC(HWND hWnd,HDC hDC); - WINUSERAPI HDC WINAPI BeginPaint(HWND hWnd,LPPAINTSTRUCT lpPaint); - WINUSERAPI WINBOOL WINAPI EndPaint(HWND hWnd,CONST PAINTSTRUCT *lpPaint); - WINUSERAPI WINBOOL WINAPI GetUpdateRect(HWND hWnd,LPRECT lpRect,WINBOOL bErase); - WINUSERAPI int WINAPI GetUpdateRgn(HWND hWnd,HRGN hRgn,WINBOOL bErase); - WINUSERAPI int WINAPI SetWindowRgn(HWND hWnd,HRGN hRgn,WINBOOL bRedraw); - WINUSERAPI int WINAPI GetWindowRgn(HWND hWnd,HRGN hRgn); - WINUSERAPI int WINAPI GetWindowRgnBox(HWND hWnd,LPRECT lprc); - WINUSERAPI int WINAPI ExcludeUpdateRgn(HDC hDC,HWND hWnd); - WINUSERAPI WINBOOL WINAPI InvalidateRect(HWND hWnd,CONST RECT *lpRect,WINBOOL bErase); - WINUSERAPI WINBOOL WINAPI ValidateRect(HWND hWnd,CONST RECT *lpRect); - WINUSERAPI WINBOOL WINAPI InvalidateRgn(HWND hWnd,HRGN hRgn,WINBOOL bErase); - WINUSERAPI WINBOOL WINAPI ValidateRgn(HWND hWnd,HRGN hRgn); - WINUSERAPI WINBOOL WINAPI RedrawWindow(HWND hWnd,CONST RECT *lprcUpdate,HRGN hrgnUpdate,UINT flags); - -#define RDW_INVALIDATE 0x0001 -#define RDW_INTERNALPAINT 0x0002 -#define RDW_ERASE 0x0004 - -#define RDW_VALIDATE 0x0008 -#define RDW_NOINTERNALPAINT 0x0010 -#define RDW_NOERASE 0x0020 - -#define RDW_NOCHILDREN 0x0040 -#define RDW_ALLCHILDREN 0x0080 - -#define RDW_UPDATENOW 0x0100 -#define RDW_ERASENOW 0x0200 - -#define RDW_FRAME 0x0400 -#define RDW_NOFRAME 0x0800 - - WINUSERAPI WINBOOL WINAPI LockWindowUpdate(HWND hWndLock); - WINUSERAPI WINBOOL WINAPI ScrollWindow(HWND hWnd,int XAmount,int YAmount,CONST RECT *lpRect,CONST RECT *lpClipRect); - WINUSERAPI WINBOOL WINAPI ScrollDC(HDC hDC,int dx,int dy,CONST RECT *lprcScroll,CONST RECT *lprcClip,HRGN hrgnUpdate,LPRECT lprcUpdate); - WINUSERAPI int WINAPI ScrollWindowEx(HWND hWnd,int dx,int dy,CONST RECT *prcScroll,CONST RECT *prcClip,HRGN hrgnUpdate,LPRECT prcUpdate,UINT flags); - -#define SW_SCROLLCHILDREN 0x0001 -#define SW_INVALIDATE 0x0002 -#define SW_ERASE 0x0004 -#define SW_SMOOTHSCROLL 0x0010 - -#ifndef NOSCROLL - WINUSERAPI int WINAPI SetScrollPos(HWND hWnd,int nBar,int nPos,WINBOOL bRedraw); - WINUSERAPI int WINAPI GetScrollPos(HWND hWnd,int nBar); - WINUSERAPI WINBOOL WINAPI SetScrollRange(HWND hWnd,int nBar,int nMinPos,int nMaxPos,WINBOOL bRedraw); - WINUSERAPI WINBOOL WINAPI GetScrollRange(HWND hWnd,int nBar,LPINT lpMinPos,LPINT lpMaxPos); - WINUSERAPI WINBOOL WINAPI ShowScrollBar(HWND hWnd,int wBar,WINBOOL bShow); - WINUSERAPI WINBOOL WINAPI EnableScrollBar(HWND hWnd,UINT wSBflags,UINT wArrows); - -#define ESB_ENABLE_BOTH 0x0000 -#define ESB_DISABLE_BOTH 0x0003 - -#define ESB_DISABLE_LEFT 0x0001 -#define ESB_DISABLE_RIGHT 0x0002 - -#define ESB_DISABLE_UP 0x0001 -#define ESB_DISABLE_DOWN 0x0002 - -#define ESB_DISABLE_LTUP ESB_DISABLE_LEFT -#define ESB_DISABLE_RTDN ESB_DISABLE_RIGHT -#endif - -#ifdef UNICODE -#define SetProp SetPropW -#define GetProp GetPropW -#define RemoveProp RemovePropW -#define EnumPropsEx EnumPropsExW -#define EnumProps EnumPropsW -#define SetWindowText SetWindowTextW -#define GetWindowText GetWindowTextW -#define GetWindowTextLength GetWindowTextLengthW -#else -#define SetProp SetPropA -#define GetProp GetPropA -#define RemoveProp RemovePropA -#define EnumPropsEx EnumPropsExA -#define EnumProps EnumPropsA -#define SetWindowText SetWindowTextA -#define GetWindowText GetWindowTextA -#define GetWindowTextLength GetWindowTextLengthA -#endif - - WINUSERAPI WINBOOL WINAPI SetPropA(HWND hWnd,LPCSTR lpString,HANDLE hData); - WINUSERAPI WINBOOL WINAPI SetPropW(HWND hWnd,LPCWSTR lpString,HANDLE hData); - WINUSERAPI HANDLE WINAPI GetPropA(HWND hWnd,LPCSTR lpString); - WINUSERAPI HANDLE WINAPI GetPropW(HWND hWnd,LPCWSTR lpString); - WINUSERAPI HANDLE WINAPI RemovePropA(HWND hWnd,LPCSTR lpString); - WINUSERAPI HANDLE WINAPI RemovePropW(HWND hWnd,LPCWSTR lpString); - WINUSERAPI int WINAPI EnumPropsExA(HWND hWnd,PROPENUMPROCEXA lpEnumFunc,LPARAM lParam); - WINUSERAPI int WINAPI EnumPropsExW(HWND hWnd,PROPENUMPROCEXW lpEnumFunc,LPARAM lParam); - WINUSERAPI int WINAPI EnumPropsA(HWND hWnd,PROPENUMPROCA lpEnumFunc); - WINUSERAPI int WINAPI EnumPropsW(HWND hWnd,PROPENUMPROCW lpEnumFunc); - WINUSERAPI WINBOOL WINAPI SetWindowTextA(HWND hWnd,LPCSTR lpString); - WINUSERAPI WINBOOL WINAPI SetWindowTextW(HWND hWnd,LPCWSTR lpString); - WINUSERAPI int WINAPI GetWindowTextA(HWND hWnd,LPSTR lpString,int nMaxCount); - WINUSERAPI int WINAPI GetWindowTextW(HWND hWnd,LPWSTR lpString,int nMaxCount); - WINUSERAPI int WINAPI GetWindowTextLengthA(HWND hWnd); - WINUSERAPI int WINAPI GetWindowTextLengthW(HWND hWnd); - WINUSERAPI WINBOOL WINAPI GetClientRect(HWND hWnd,LPRECT lpRect); - WINUSERAPI WINBOOL WINAPI GetWindowRect(HWND hWnd,LPRECT lpRect); - WINUSERAPI WINBOOL WINAPI AdjustWindowRect(LPRECT lpRect,DWORD dwStyle,WINBOOL bMenu); - WINUSERAPI WINBOOL WINAPI AdjustWindowRectEx(LPRECT lpRect,DWORD dwStyle,WINBOOL bMenu,DWORD dwExStyle); - -#define HELPINFO_WINDOW 0x0001 -#define HELPINFO_MENUITEM 0x0002 - - typedef struct tagHELPINFO { - UINT cbSize; - int iContextType; - int iCtrlId; - HANDLE hItemHandle; - DWORD_PTR dwContextId; - POINT MousePos; - } HELPINFO,*LPHELPINFO; - - WINUSERAPI WINBOOL WINAPI SetWindowContextHelpId(HWND,DWORD); - WINUSERAPI DWORD WINAPI GetWindowContextHelpId(HWND); - WINUSERAPI WINBOOL WINAPI SetMenuContextHelpId(HMENU,DWORD); - WINUSERAPI DWORD WINAPI GetMenuContextHelpId(HMENU); - -#ifndef NOMB - -#define MB_OK 0x00000000L -#define MB_OKCANCEL 0x00000001L -#define MB_ABORTRETRYIGNORE 0x00000002L -#define MB_YESNOCANCEL 0x00000003L -#define MB_YESNO 0x00000004L -#define MB_RETRYCANCEL 0x00000005L -#define MB_CANCELTRYCONTINUE 0x00000006L -#define MB_ICONHAND 0x00000010L -#define MB_ICONQUESTION 0x00000020L -#define MB_ICONEXCLAMATION 0x00000030L -#define MB_ICONASTERISK 0x00000040L -#define MB_USERICON 0x00000080L -#define MB_ICONWARNING MB_ICONEXCLAMATION -#define MB_ICONERROR MB_ICONHAND -#define MB_ICONINFORMATION MB_ICONASTERISK -#define MB_ICONSTOP MB_ICONHAND -#define MB_DEFBUTTON1 0x00000000L -#define MB_DEFBUTTON2 0x00000100L -#define MB_DEFBUTTON3 0x00000200L -#define MB_DEFBUTTON4 0x00000300L -#define MB_APPLMODAL 0x00000000L -#define MB_SYSTEMMODAL 0x00001000L -#define MB_TASKMODAL 0x00002000L -#define MB_HELP 0x00004000L -#define MB_NOFOCUS 0x00008000L -#define MB_SETFOREGROUND 0x00010000L -#define MB_DEFAULT_DESKTOP_ONLY 0x00020000L -#define MB_TOPMOST 0x00040000L -#define MB_RIGHT 0x00080000L -#define MB_RTLREADING 0x00100000L -#define MB_SERVICE_NOTIFICATION 0x00200000L -#define MB_SERVICE_NOTIFICATION_NT3X 0x00040000L -#define MB_TYPEMASK 0x0000000FL -#define MB_ICONMASK 0x000000F0L -#define MB_DEFMASK 0x00000F00L -#define MB_MODEMASK 0x00003000L -#define MB_MISCMASK 0x0000C000L - -#ifdef UNICODE -#define MessageBox MessageBoxW -#define MessageBoxEx MessageBoxExW -#else -#define MessageBox MessageBoxA -#define MessageBoxEx MessageBoxExA -#endif - - WINUSERAPI int WINAPI MessageBoxA(HWND hWnd,LPCSTR lpText,LPCSTR lpCaption,UINT uType); - WINUSERAPI int WINAPI MessageBoxW(HWND hWnd,LPCWSTR lpText,LPCWSTR lpCaption,UINT uType); - WINUSERAPI int WINAPI MessageBoxExA(HWND hWnd,LPCSTR lpText,LPCSTR lpCaption,UINT uType,WORD wLanguageId); - WINUSERAPI int WINAPI MessageBoxExW(HWND hWnd,LPCWSTR lpText,LPCWSTR lpCaption,UINT uType,WORD wLanguageId); - - typedef VOID (CALLBACK *MSGBOXCALLBACK)(LPHELPINFO lpHelpInfo); - - typedef struct tagMSGBOXPARAMSA { - UINT cbSize; - HWND hwndOwner; - HINSTANCE hInstance; - LPCSTR lpszText; - LPCSTR lpszCaption; - DWORD dwStyle; - LPCSTR lpszIcon; - DWORD_PTR dwContextHelpId; - MSGBOXCALLBACK lpfnMsgBoxCallback; - DWORD dwLanguageId; - } MSGBOXPARAMSA,*PMSGBOXPARAMSA,*LPMSGBOXPARAMSA; - - typedef struct tagMSGBOXPARAMSW { - UINT cbSize; - HWND hwndOwner; - HINSTANCE hInstance; - LPCWSTR lpszText; - LPCWSTR lpszCaption; - DWORD dwStyle; - LPCWSTR lpszIcon; - DWORD_PTR dwContextHelpId; - MSGBOXCALLBACK lpfnMsgBoxCallback; - DWORD dwLanguageId; - } MSGBOXPARAMSW,*PMSGBOXPARAMSW,*LPMSGBOXPARAMSW; - -#ifdef UNICODE - typedef MSGBOXPARAMSW MSGBOXPARAMS; - typedef PMSGBOXPARAMSW PMSGBOXPARAMS; - typedef LPMSGBOXPARAMSW LPMSGBOXPARAMS; -#else - typedef MSGBOXPARAMSA MSGBOXPARAMS; - typedef PMSGBOXPARAMSA PMSGBOXPARAMS; - typedef LPMSGBOXPARAMSA LPMSGBOXPARAMS; -#endif - -#ifdef UNICODE -#define MessageBoxIndirect MessageBoxIndirectW -#else -#define MessageBoxIndirect MessageBoxIndirectA -#endif - - WINUSERAPI int WINAPI MessageBoxIndirectA(CONST MSGBOXPARAMSA *lpmbp); - WINUSERAPI int WINAPI MessageBoxIndirectW(CONST MSGBOXPARAMSW *lpmbp); - WINUSERAPI WINBOOL WINAPI MessageBeep(UINT uType); -#endif - - WINUSERAPI int WINAPI ShowCursor(WINBOOL bShow); - WINUSERAPI WINBOOL WINAPI SetCursorPos(int X,int Y); - WINUSERAPI HCURSOR WINAPI SetCursor(HCURSOR hCursor); - WINUSERAPI WINBOOL WINAPI GetCursorPos(LPPOINT lpPoint); - WINUSERAPI WINBOOL WINAPI ClipCursor(CONST RECT *lpRect); - WINUSERAPI WINBOOL WINAPI GetClipCursor(LPRECT lpRect); - WINUSERAPI HCURSOR WINAPI GetCursor(VOID); - WINUSERAPI WINBOOL WINAPI CreateCaret(HWND hWnd,HBITMAP hBitmap,int nWidth,int nHeight); - WINUSERAPI UINT WINAPI GetCaretBlinkTime(VOID); - WINUSERAPI WINBOOL WINAPI SetCaretBlinkTime(UINT uMSeconds); - WINUSERAPI WINBOOL WINAPI DestroyCaret(VOID); - WINUSERAPI WINBOOL WINAPI HideCaret(HWND hWnd); - WINUSERAPI WINBOOL WINAPI ShowCaret(HWND hWnd); - WINUSERAPI WINBOOL WINAPI SetCaretPos(int X,int Y); - WINUSERAPI WINBOOL WINAPI GetCaretPos(LPPOINT lpPoint); - WINUSERAPI WINBOOL WINAPI ClientToScreen(HWND hWnd,LPPOINT lpPoint); - WINUSERAPI WINBOOL WINAPI ScreenToClient(HWND hWnd,LPPOINT lpPoint); - WINUSERAPI int WINAPI MapWindowPoints(HWND hWndFrom,HWND hWndTo,LPPOINT lpPoints,UINT cPoints); - WINUSERAPI HWND WINAPI WindowFromPoint(POINT Point); - WINUSERAPI HWND WINAPI ChildWindowFromPoint(HWND hWndParent,POINT Point); - -#define CWP_ALL 0x0000 -#define CWP_SKIPINVISIBLE 0x0001 -#define CWP_SKIPDISABLED 0x0002 -#define CWP_SKIPTRANSPARENT 0x0004 - - WINUSERAPI HWND WINAPI ChildWindowFromPointEx(HWND hwnd,POINT pt,UINT flags); - -#ifndef NOCOLOR - -#define CTLCOLOR_MSGBOX 0 -#define CTLCOLOR_EDIT 1 -#define CTLCOLOR_LISTBOX 2 -#define CTLCOLOR_BTN 3 -#define CTLCOLOR_DLG 4 -#define CTLCOLOR_SCROLLBAR 5 -#define CTLCOLOR_STATIC 6 -#define CTLCOLOR_MAX 7 - -#define COLOR_SCROLLBAR 0 -#define COLOR_BACKGROUND 1 -#define COLOR_ACTIVECAPTION 2 -#define COLOR_INACTIVECAPTION 3 -#define COLOR_MENU 4 -#define COLOR_WINDOW 5 -#define COLOR_WINDOWFRAME 6 -#define COLOR_MENUTEXT 7 -#define COLOR_WINDOWTEXT 8 -#define COLOR_CAPTIONTEXT 9 -#define COLOR_ACTIVEBORDER 10 -#define COLOR_INACTIVEBORDER 11 -#define COLOR_APPWORKSPACE 12 -#define COLOR_HIGHLIGHT 13 -#define COLOR_HIGHLIGHTTEXT 14 -#define COLOR_BTNFACE 15 -#define COLOR_BTNSHADOW 16 -#define COLOR_GRAYTEXT 17 -#define COLOR_BTNTEXT 18 -#define COLOR_INACTIVECAPTIONTEXT 19 -#define COLOR_BTNHIGHLIGHT 20 - -#define COLOR_3DDKSHADOW 21 -#define COLOR_3DLIGHT 22 -#define COLOR_INFOTEXT 23 -#define COLOR_INFOBK 24 - -#define COLOR_HOTLIGHT 26 -#define COLOR_GRADIENTACTIVECAPTION 27 -#define COLOR_GRADIENTINACTIVECAPTION 28 -#define COLOR_MENUHILIGHT 29 -#define COLOR_MENUBAR 30 - -#define COLOR_DESKTOP COLOR_BACKGROUND -#define COLOR_3DFACE COLOR_BTNFACE -#define COLOR_3DSHADOW COLOR_BTNSHADOW -#define COLOR_3DHIGHLIGHT COLOR_BTNHIGHLIGHT -#define COLOR_3DHILIGHT COLOR_BTNHIGHLIGHT -#define COLOR_BTNHILIGHT COLOR_BTNHIGHLIGHT - - WINUSERAPI DWORD WINAPI GetSysColor(int nIndex); - WINUSERAPI HBRUSH WINAPI GetSysColorBrush(int nIndex); - WINUSERAPI WINBOOL WINAPI SetSysColors(int cElements,CONST INT *lpaElements,CONST COLORREF *lpaRgbValues); -#endif - - WINUSERAPI WINBOOL WINAPI DrawFocusRect(HDC hDC,CONST RECT *lprc); - WINUSERAPI int WINAPI FillRect(HDC hDC,CONST RECT *lprc,HBRUSH hbr); - WINUSERAPI int WINAPI FrameRect(HDC hDC,CONST RECT *lprc,HBRUSH hbr); - WINUSERAPI WINBOOL WINAPI InvertRect(HDC hDC,CONST RECT *lprc); - WINUSERAPI WINBOOL WINAPI SetRect(LPRECT lprc,int xLeft,int yTop,int xRight,int yBottom); - WINUSERAPI WINBOOL WINAPI SetRectEmpty(LPRECT lprc); - WINUSERAPI WINBOOL WINAPI CopyRect(LPRECT lprcDst,CONST RECT *lprcSrc); - WINUSERAPI WINBOOL WINAPI InflateRect(LPRECT lprc,int dx,int dy); - WINUSERAPI WINBOOL WINAPI IntersectRect(LPRECT lprcDst,CONST RECT *lprcSrc1,CONST RECT *lprcSrc2); - WINUSERAPI WINBOOL WINAPI UnionRect(LPRECT lprcDst,CONST RECT *lprcSrc1,CONST RECT *lprcSrc2); - WINUSERAPI WINBOOL WINAPI SubtractRect(LPRECT lprcDst,CONST RECT *lprcSrc1,CONST RECT *lprcSrc2); - WINUSERAPI WINBOOL WINAPI OffsetRect(LPRECT lprc,int dx,int dy); - WINUSERAPI WINBOOL WINAPI IsRectEmpty(CONST RECT *lprc); - WINUSERAPI WINBOOL WINAPI EqualRect(CONST RECT *lprc1,CONST RECT *lprc2); - WINUSERAPI WINBOOL WINAPI PtInRect(CONST RECT *lprc,POINT pt); - -#ifndef NOWINOFFSETS - -#ifdef UNICODE -#define GetWindowLong GetWindowLongW -#define SetWindowLong SetWindowLongW -#else -#define GetWindowLong GetWindowLongA -#define SetWindowLong SetWindowLongA -#endif - - WINUSERAPI WORD WINAPI GetWindowWord(HWND hWnd,int nIndex); - WINUSERAPI WORD WINAPI SetWindowWord(HWND hWnd,int nIndex,WORD wNewWord); - WINUSERAPI LONG WINAPI GetWindowLongA(HWND hWnd,int nIndex); - WINUSERAPI LONG WINAPI GetWindowLongW(HWND hWnd,int nIndex); - WINUSERAPI LONG WINAPI SetWindowLongA(HWND hWnd,int nIndex,LONG dwNewLong); - WINUSERAPI LONG WINAPI SetWindowLongW(HWND hWnd,int nIndex,LONG dwNewLong); - -#ifdef _WIN64 - -#ifdef UNICODE -#define GetWindowLongPtr GetWindowLongPtrW -#define SetWindowLongPtr SetWindowLongPtrW -#else -#define GetWindowLongPtr GetWindowLongPtrA -#define SetWindowLongPtr SetWindowLongPtrA -#endif - - WINUSERAPI LONG_PTR WINAPI GetWindowLongPtrA(HWND hWnd,int nIndex); - WINUSERAPI LONG_PTR WINAPI GetWindowLongPtrW(HWND hWnd,int nIndex); - WINUSERAPI LONG_PTR WINAPI SetWindowLongPtrA(HWND hWnd,int nIndex,LONG_PTR dwNewLong); - WINUSERAPI LONG_PTR WINAPI SetWindowLongPtrW(HWND hWnd,int nIndex,LONG_PTR dwNewLong); -#else - -#ifdef UNICODE -#define GetWindowLongPtr GetWindowLongPtrW -#define SetWindowLongPtr SetWindowLongPtrW -#else -#define GetWindowLongPtr GetWindowLongPtrA -#define SetWindowLongPtr SetWindowLongPtrA -#endif - -#define GetWindowLongPtrA GetWindowLongA -#define GetWindowLongPtrW GetWindowLongW -#define SetWindowLongPtrA SetWindowLongA -#define SetWindowLongPtrW SetWindowLongW -#endif - -#ifdef UNICODE -#define GetClassLong GetClassLongW -#define SetClassLong SetClassLongW -#else -#define GetClassLong GetClassLongA -#define SetClassLong SetClassLongA -#endif - - WINUSERAPI WORD WINAPI GetClassWord(HWND hWnd,int nIndex); - WINUSERAPI WORD WINAPI SetClassWord(HWND hWnd,int nIndex,WORD wNewWord); - WINUSERAPI DWORD WINAPI GetClassLongA(HWND hWnd,int nIndex); - WINUSERAPI DWORD WINAPI GetClassLongW(HWND hWnd,int nIndex); - WINUSERAPI DWORD WINAPI SetClassLongA(HWND hWnd,int nIndex,LONG dwNewLong); - WINUSERAPI DWORD WINAPI SetClassLongW(HWND hWnd,int nIndex,LONG dwNewLong); - -#ifdef _WIN64 - -#ifdef UNICODE -#define GetClassLongPtr GetClassLongPtrW -#define SetClassLongPtr SetClassLongPtrW -#else -#define GetClassLongPtr GetClassLongPtrA -#define SetClassLongPtr SetClassLongPtrA -#endif - - WINUSERAPI ULONG_PTR WINAPI GetClassLongPtrA(HWND hWnd,int nIndex); - WINUSERAPI ULONG_PTR WINAPI GetClassLongPtrW(HWND hWnd,int nIndex); - WINUSERAPI ULONG_PTR WINAPI SetClassLongPtrA(HWND hWnd,int nIndex,LONG_PTR dwNewLong); - WINUSERAPI ULONG_PTR WINAPI SetClassLongPtrW(HWND hWnd,int nIndex,LONG_PTR dwNewLong); -#else -#ifdef UNICODE -#define GetClassLongPtr GetClassLongPtrW -#define SetClassLongPtr SetClassLongPtrW -#else -#define GetClassLongPtr GetClassLongPtrA -#define SetClassLongPtr SetClassLongPtrA -#endif - -#define GetClassLongPtrA GetClassLongA -#define GetClassLongPtrW GetClassLongW -#define SetClassLongPtrA SetClassLongA -#define SetClassLongPtrW SetClassLongW -#endif -#endif - -#ifdef UNICODE -#define FindWindow FindWindowW -#define FindWindowEx FindWindowExW -#define GetClassName GetClassNameW -#else -#define FindWindow FindWindowA -#define FindWindowEx FindWindowExA -#define GetClassName GetClassNameA -#endif - - WINUSERAPI WINBOOL WINAPI GetProcessDefaultLayout(DWORD *pdwDefaultLayout); - WINUSERAPI WINBOOL WINAPI SetProcessDefaultLayout(DWORD dwDefaultLayout); - WINUSERAPI HWND WINAPI GetDesktopWindow(VOID); - WINUSERAPI HWND WINAPI GetParent(HWND hWnd); - WINUSERAPI HWND WINAPI SetParent(HWND hWndChild,HWND hWndNewParent); - WINUSERAPI WINBOOL WINAPI EnumChildWindows(HWND hWndParent,WNDENUMPROC lpEnumFunc,LPARAM lParam); - WINUSERAPI HWND WINAPI FindWindowA(LPCSTR lpClassName,LPCSTR lpWindowName); - WINUSERAPI HWND WINAPI FindWindowW(LPCWSTR lpClassName,LPCWSTR lpWindowName); - WINUSERAPI HWND WINAPI FindWindowExA(HWND hWndParent,HWND hWndChildAfter,LPCSTR lpszClass,LPCSTR lpszWindow); - WINUSERAPI HWND WINAPI FindWindowExW(HWND hWndParent,HWND hWndChildAfter,LPCWSTR lpszClass,LPCWSTR lpszWindow); - WINUSERAPI HWND WINAPI GetShellWindow(VOID); - WINUSERAPI WINBOOL WINAPI RegisterShellHookWindow(HWND hwnd); - WINUSERAPI WINBOOL WINAPI DeregisterShellHookWindow(HWND hwnd); - WINUSERAPI WINBOOL WINAPI EnumWindows(WNDENUMPROC lpEnumFunc,LPARAM lParam); - WINUSERAPI WINBOOL WINAPI EnumThreadWindows(DWORD dwThreadId,WNDENUMPROC lpfn,LPARAM lParam); - -#define EnumTaskWindows(hTask,lpfn,lParam) EnumThreadWindows(HandleToUlong(hTask),lpfn,lParam) - - WINUSERAPI int WINAPI GetClassNameA(HWND hWnd,LPSTR lpClassName,int nMaxCount); - WINUSERAPI int WINAPI GetClassNameW(HWND hWnd,LPWSTR lpClassName,int nMaxCount); - WINUSERAPI HWND WINAPI GetTopWindow(HWND hWnd); - -#define GetNextWindow(hWnd,wCmd) GetWindow(hWnd,wCmd) -#define GetSysModalWindow() (NULL) -#define SetSysModalWindow(hWnd) (NULL) - - WINUSERAPI DWORD WINAPI GetWindowThreadProcessId(HWND hWnd,LPDWORD lpdwProcessId); - WINUSERAPI WINBOOL WINAPI IsGUIThread(WINBOOL bConvert); - -#define GetWindowTask(hWnd) ((HANDLE)(DWORD_PTR)GetWindowThreadProcessId(hWnd,NULL)) - - WINUSERAPI HWND WINAPI GetLastActivePopup(HWND hWnd); - -#define GW_HWNDFIRST 0 -#define GW_HWNDLAST 1 -#define GW_HWNDNEXT 2 -#define GW_HWNDPREV 3 -#define GW_OWNER 4 -#define GW_CHILD 5 -#define GW_ENABLEDPOPUP 6 -#define GW_MAX 6 - - WINUSERAPI HWND WINAPI GetWindow(HWND hWnd,UINT uCmd); - -#ifndef NOWH - -#ifdef UNICODE -#define SetWindowsHook SetWindowsHookW -#define SetWindowsHookEx SetWindowsHookExW -#else -#define SetWindowsHook SetWindowsHookA -#define SetWindowsHookEx SetWindowsHookExA -#endif - - WINUSERAPI HHOOK WINAPI SetWindowsHookA(int nFilterType,HOOKPROC pfnFilterProc); - WINUSERAPI HHOOK WINAPI SetWindowsHookW(int nFilterType,HOOKPROC pfnFilterProc); - WINUSERAPI WINBOOL WINAPI UnhookWindowsHook(int nCode,HOOKPROC pfnFilterProc); - WINUSERAPI HHOOK WINAPI SetWindowsHookExA(int idHook,HOOKPROC lpfn,HINSTANCE hmod,DWORD dwThreadId); - WINUSERAPI HHOOK WINAPI SetWindowsHookExW(int idHook,HOOKPROC lpfn,HINSTANCE hmod,DWORD dwThreadId); - WINUSERAPI WINBOOL WINAPI UnhookWindowsHookEx(HHOOK hhk); - WINUSERAPI LRESULT WINAPI CallNextHookEx(HHOOK hhk,int nCode,WPARAM wParam,LPARAM lParam); -#define DefHookProc(nCode,wParam,lParam,phhk) CallNextHookEx(*phhk,nCode,wParam,lParam) -#endif - -#ifndef NOMENUS - -#define MF_INSERT 0x00000000L -#define MF_CHANGE 0x00000080L -#define MF_APPEND 0x00000100L -#define MF_DELETE 0x00000200L -#define MF_REMOVE 0x00001000L -#define MF_BYCOMMAND 0x00000000L -#define MF_BYPOSITION 0x00000400L -#define MF_SEPARATOR 0x00000800L -#define MF_ENABLED 0x00000000L -#define MF_GRAYED 0x00000001L -#define MF_DISABLED 0x00000002L -#define MF_UNCHECKED 0x00000000L -#define MF_CHECKED 0x00000008L -#define MF_USECHECKBITMAPS 0x00000200L -#define MF_STRING 0x00000000L -#define MF_BITMAP 0x00000004L -#define MF_OWNERDRAW 0x00000100L -#define MF_POPUP 0x00000010L -#define MF_MENUBARBREAK 0x00000020L -#define MF_MENUBREAK 0x00000040L -#define MF_UNHILITE 0x00000000L -#define MF_HILITE 0x00000080L -#define MF_DEFAULT 0x00001000L -#define MF_SYSMENU 0x00002000L -#define MF_HELP 0x00004000L -#define MF_RIGHTJUSTIFY 0x00004000L -#define MF_MOUSESELECT 0x00008000L -#define MF_END 0x00000080L - -#define MFT_STRING MF_STRING -#define MFT_BITMAP MF_BITMAP -#define MFT_MENUBARBREAK MF_MENUBARBREAK -#define MFT_MENUBREAK MF_MENUBREAK -#define MFT_OWNERDRAW MF_OWNERDRAW -#define MFT_RADIOCHECK 0x00000200L -#define MFT_SEPARATOR MF_SEPARATOR -#define MFT_RIGHTORDER 0x00002000L -#define MFT_RIGHTJUSTIFY MF_RIGHTJUSTIFY - -#define MFS_GRAYED 0x00000003L -#define MFS_DISABLED MFS_GRAYED -#define MFS_CHECKED MF_CHECKED -#define MFS_HILITE MF_HILITE -#define MFS_ENABLED MF_ENABLED -#define MFS_UNCHECKED MF_UNCHECKED -#define MFS_UNHILITE MF_UNHILITE -#define MFS_DEFAULT MF_DEFAULT - - WINUSERAPI WINBOOL WINAPI CheckMenuRadioItem(HMENU hmenu,UINT first,UINT last,UINT check,UINT flags); - - typedef struct { - WORD versionNumber; - WORD offset; - } MENUITEMTEMPLATEHEADER,*PMENUITEMTEMPLATEHEADER; - - typedef struct { - WORD mtOption; - WORD mtID; - WCHAR mtString[1]; - } MENUITEMTEMPLATE,*PMENUITEMTEMPLATE; -#define MF_END 0x00000080L -#endif - -#ifndef NOSYSCOMMANDS - -#define SC_SIZE 0xF000 -#define SC_MOVE 0xF010 -#define SC_MINIMIZE 0xF020 -#define SC_MAXIMIZE 0xF030 -#define SC_NEXTWINDOW 0xF040 -#define SC_PREVWINDOW 0xF050 -#define SC_CLOSE 0xF060 -#define SC_VSCROLL 0xF070 -#define SC_HSCROLL 0xF080 -#define SC_MOUSEMENU 0xF090 -#define SC_KEYMENU 0xF100 -#define SC_ARRANGE 0xF110 -#define SC_RESTORE 0xF120 -#define SC_TASKLIST 0xF130 -#define SC_SCREENSAVE 0xF140 -#define SC_HOTKEY 0xF150 -#define SC_DEFAULT 0xF160 -#define SC_MONITORPOWER 0xF170 -#define SC_CONTEXTHELP 0xF180 -#define SC_SEPARATOR 0xF00F -#define SC_ICON SC_MINIMIZE -#define SC_ZOOM SC_MAXIMIZE -#endif - -#ifdef UNICODE -#define LoadBitmap LoadBitmapW -#define LoadCursor LoadCursorW -#define LoadCursorFromFile LoadCursorFromFileW -#else -#define LoadBitmap LoadBitmapA -#define LoadCursor LoadCursorA -#define LoadCursorFromFile LoadCursorFromFileA -#endif - - WINUSERAPI HBITMAP WINAPI LoadBitmapA(HINSTANCE hInstance,LPCSTR lpBitmapName); - WINUSERAPI HBITMAP WINAPI LoadBitmapW(HINSTANCE hInstance,LPCWSTR lpBitmapName); - WINUSERAPI HCURSOR WINAPI LoadCursorA(HINSTANCE hInstance,LPCSTR lpCursorName); - WINUSERAPI HCURSOR WINAPI LoadCursorW(HINSTANCE hInstance,LPCWSTR lpCursorName); - WINUSERAPI HCURSOR WINAPI LoadCursorFromFileA(LPCSTR lpFileName); - WINUSERAPI HCURSOR WINAPI LoadCursorFromFileW(LPCWSTR lpFileName); - WINUSERAPI HCURSOR WINAPI CreateCursor(HINSTANCE hInst,int xHotSpot,int yHotSpot,int nWidth,int nHeight,CONST VOID *pvANDPlane,CONST VOID *pvXORPlane); - WINUSERAPI WINBOOL WINAPI DestroyCursor(HCURSOR hCursor); - -#define CopyCursor(pcur) ((HCURSOR)CopyIcon((HICON)(pcur))) - -#define IDC_ARROW MAKEINTRESOURCE(32512) -#define IDC_IBEAM MAKEINTRESOURCE(32513) -#define IDC_WAIT MAKEINTRESOURCE(32514) -#define IDC_CROSS MAKEINTRESOURCE(32515) -#define IDC_UPARROW MAKEINTRESOURCE(32516) -#define IDC_SIZE MAKEINTRESOURCE(32640) -#define IDC_ICON MAKEINTRESOURCE(32641) -#define IDC_SIZENWSE MAKEINTRESOURCE(32642) -#define IDC_SIZENESW MAKEINTRESOURCE(32643) -#define IDC_SIZEWE MAKEINTRESOURCE(32644) -#define IDC_SIZENS MAKEINTRESOURCE(32645) -#define IDC_SIZEALL MAKEINTRESOURCE(32646) -#define IDC_NO MAKEINTRESOURCE(32648) -#define IDC_HAND MAKEINTRESOURCE(32649) -#define IDC_APPSTARTING MAKEINTRESOURCE(32650) -#define IDC_HELP MAKEINTRESOURCE(32651) - - WINUSERAPI WINBOOL WINAPI SetSystemCursor(HCURSOR hcur,DWORD id); - - typedef struct _ICONINFO { - WINBOOL fIcon; - DWORD xHotspot; - DWORD yHotspot; - HBITMAP hbmMask; - HBITMAP hbmColor; - } ICONINFO; - typedef ICONINFO *PICONINFO; - -#ifdef UNICODE -#define LoadIcon LoadIconW -#define PrivateExtractIcons PrivateExtractIconsW -#else -#define LoadIcon LoadIconA -#define PrivateExtractIcons PrivateExtractIconsA -#endif - - WINUSERAPI HICON WINAPI LoadIconA(HINSTANCE hInstance,LPCSTR lpIconName); - WINUSERAPI HICON WINAPI LoadIconW(HINSTANCE hInstance,LPCWSTR lpIconName); - WINUSERAPI UINT WINAPI PrivateExtractIconsA(LPCSTR szFileName,int nIconIndex,int cxIcon,int cyIcon,HICON *phicon,UINT *piconid,UINT nIcons,UINT flags); - WINUSERAPI UINT WINAPI PrivateExtractIconsW(LPCWSTR szFileName,int nIconIndex,int cxIcon,int cyIcon,HICON *phicon,UINT *piconid,UINT nIcons,UINT flags); - WINUSERAPI HICON WINAPI CreateIcon(HINSTANCE hInstance,int nWidth,int nHeight,BYTE cPlanes,BYTE cBitsPixel,CONST BYTE *lpbANDbits,CONST BYTE *lpbXORbits); - WINUSERAPI WINBOOL WINAPI DestroyIcon(HICON hIcon); - WINUSERAPI int WINAPI LookupIconIdFromDirectory(PBYTE presbits,WINBOOL fIcon); - WINUSERAPI int WINAPI LookupIconIdFromDirectoryEx(PBYTE presbits,WINBOOL fIcon,int cxDesired,int cyDesired,UINT Flags); - WINUSERAPI HICON WINAPI CreateIconFromResource(PBYTE presbits,DWORD dwResSize,WINBOOL fIcon,DWORD dwVer); - WINUSERAPI HICON WINAPI CreateIconFromResourceEx(PBYTE presbits,DWORD dwResSize,WINBOOL fIcon,DWORD dwVer,int cxDesired,int cyDesired,UINT Flags); - - typedef struct tagCURSORSHAPE { - int xHotSpot; - int yHotSpot; - int cx; - int cy; - int cbWidth; - BYTE Planes; - BYTE BitsPixel; - } CURSORSHAPE,*LPCURSORSHAPE; - -#define IMAGE_BITMAP 0 -#define IMAGE_ICON 1 -#define IMAGE_CURSOR 2 -#define IMAGE_ENHMETAFILE 3 - -#define LR_DEFAULTCOLOR 0x0000 -#define LR_MONOCHROME 0x0001 -#define LR_COLOR 0x0002 -#define LR_COPYRETURNORG 0x0004 -#define LR_COPYDELETEORG 0x0008 -#define LR_LOADFROMFILE 0x0010 -#define LR_LOADTRANSPARENT 0x0020 -#define LR_DEFAULTSIZE 0x0040 -#define LR_VGACOLOR 0x0080 -#define LR_LOADMAP3DCOLORS 0x1000 -#define LR_CREATEDIBSECTION 0x2000 -#define LR_COPYFROMRESOURCE 0x4000 -#define LR_SHARED 0x8000 - -#ifdef UNICODE -#define LoadImage LoadImageW -#else -#define LoadImage LoadImageA -#endif - - WINUSERAPI HANDLE WINAPI LoadImageA(HINSTANCE hInst,LPCSTR name,UINT type,int cx,int cy,UINT fuLoad); - WINUSERAPI HANDLE WINAPI LoadImageW(HINSTANCE hInst,LPCWSTR name,UINT type,int cx,int cy,UINT fuLoad); - WINUSERAPI HANDLE WINAPI CopyImage(HANDLE h,UINT type,int cx,int cy,UINT flags); - -#define DI_MASK 0x0001 -#define DI_IMAGE 0x0002 -#define DI_NORMAL 0x0003 -#define DI_COMPAT 0x0004 -#define DI_DEFAULTSIZE 0x0008 -#define DI_NOMIRROR 0x0010 - - WINUSERAPI WINBOOL WINAPI DrawIconEx(HDC hdc,int xLeft,int yTop,HICON hIcon,int cxWidth,int cyWidth,UINT istepIfAniCur,HBRUSH hbrFlickerFreeDraw,UINT diFlags); - WINUSERAPI HICON WINAPI CreateIconIndirect(PICONINFO piconinfo); - WINUSERAPI HICON WINAPI CopyIcon(HICON hIcon); - WINUSERAPI WINBOOL WINAPI GetIconInfo(HICON hIcon,PICONINFO piconinfo); - -#define RES_ICON 1 -#define RES_CURSOR 2 - -#ifdef OEMRESOURCE - -#define OBM_CLOSE 32754 -#define OBM_UPARROW 32753 -#define OBM_DNARROW 32752 -#define OBM_RGARROW 32751 -#define OBM_LFARROW 32750 -#define OBM_REDUCE 32749 -#define OBM_ZOOM 32748 -#define OBM_RESTORE 32747 -#define OBM_REDUCED 32746 -#define OBM_ZOOMD 32745 -#define OBM_RESTORED 32744 -#define OBM_UPARROWD 32743 -#define OBM_DNARROWD 32742 -#define OBM_RGARROWD 32741 -#define OBM_LFARROWD 32740 -#define OBM_MNARROW 32739 -#define OBM_COMBO 32738 -#define OBM_UPARROWI 32737 -#define OBM_DNARROWI 32736 -#define OBM_RGARROWI 32735 -#define OBM_LFARROWI 32734 - -#define OBM_OLD_CLOSE 32767 -#define OBM_SIZE 32766 -#define OBM_OLD_UPARROW 32765 -#define OBM_OLD_DNARROW 32764 -#define OBM_OLD_RGARROW 32763 -#define OBM_OLD_LFARROW 32762 -#define OBM_BTSIZE 32761 -#define OBM_CHECK 32760 -#define OBM_CHECKBOXES 32759 -#define OBM_BTNCORNERS 32758 -#define OBM_OLD_REDUCE 32757 -#define OBM_OLD_ZOOM 32756 -#define OBM_OLD_RESTORE 32755 - -#define OCR_NORMAL 32512 -#define OCR_IBEAM 32513 -#define OCR_WAIT 32514 -#define OCR_CROSS 32515 -#define OCR_UP 32516 -#define OCR_SIZE 32640 -#define OCR_ICON 32641 -#define OCR_SIZENWSE 32642 -#define OCR_SIZENESW 32643 -#define OCR_SIZEWE 32644 -#define OCR_SIZENS 32645 -#define OCR_SIZEALL 32646 -#define OCR_ICOCUR 32647 -#define OCR_NO 32648 -#define OCR_HAND 32649 -#define OCR_APPSTARTING 32650 - -#define OIC_SAMPLE 32512 -#define OIC_HAND 32513 -#define OIC_QUES 32514 -#define OIC_BANG 32515 -#define OIC_NOTE 32516 -#define OIC_WINLOGO 32517 -#define OIC_WARNING OIC_BANG -#define OIC_ERROR OIC_HAND -#define OIC_INFORMATION OIC_NOTE -#endif - -#define ORD_LANGDRIVER 1 - -#ifndef NOICONS - -#ifdef RC_INVOKED -#define IDI_APPLICATION 32512 -#define IDI_HAND 32513 -#define IDI_QUESTION 32514 -#define IDI_EXCLAMATION 32515 -#define IDI_ASTERISK 32516 -#define IDI_WINLOGO 32517 -#else -#define IDI_APPLICATION MAKEINTRESOURCE(32512) -#define IDI_HAND MAKEINTRESOURCE(32513) -#define IDI_QUESTION MAKEINTRESOURCE(32514) -#define IDI_EXCLAMATION MAKEINTRESOURCE(32515) -#define IDI_ASTERISK MAKEINTRESOURCE(32516) -#define IDI_WINLOGO MAKEINTRESOURCE(32517) -#endif - -#define IDI_WARNING IDI_EXCLAMATION -#define IDI_ERROR IDI_HAND -#define IDI_INFORMATION IDI_ASTERISK -#endif - -#ifdef UNICODE -#define LoadString LoadStringW -#else -#define LoadString LoadStringA -#endif - - WINUSERAPI int WINAPI LoadStringA(HINSTANCE hInstance,UINT uID,LPSTR lpBuffer,int cchBufferMax); - WINUSERAPI int WINAPI LoadStringW(HINSTANCE hInstance,UINT uID,LPWSTR lpBuffer,int cchBufferMax); - -#define IDOK 1 -#define IDCANCEL 2 -#define IDABORT 3 -#define IDRETRY 4 -#define IDIGNORE 5 -#define IDYES 6 -#define IDNO 7 -#define IDCLOSE 8 -#define IDHELP 9 -#define IDTRYAGAIN 10 -#define IDCONTINUE 11 - -#ifndef IDTIMEOUT -#define IDTIMEOUT 32000 -#endif - -#ifndef NOCTLMGR - -#ifndef NOWINSTYLES -#define ES_LEFT 0x0000L -#define ES_CENTER 0x0001L -#define ES_RIGHT 0x0002L -#define ES_MULTILINE 0x0004L -#define ES_UPPERCASE 0x0008L -#define ES_LOWERCASE 0x0010L -#define ES_PASSWORD 0x0020L -#define ES_AUTOVSCROLL 0x0040L -#define ES_AUTOHSCROLL 0x0080L -#define ES_NOHIDESEL 0x0100L -#define ES_OEMCONVERT 0x0400L -#define ES_READONLY 0x0800L -#define ES_WANTRETURN 0x1000L -#define ES_NUMBER 0x2000L -#endif - -#define EN_SETFOCUS 0x0100 -#define EN_KILLFOCUS 0x0200 -#define EN_CHANGE 0x0300 -#define EN_UPDATE 0x0400 -#define EN_ERRSPACE 0x0500 -#define EN_MAXTEXT 0x0501 -#define EN_HSCROLL 0x0601 -#define EN_VSCROLL 0x0602 -#define EN_ALIGN_LTR_EC 0x0700 -#define EN_ALIGN_RTL_EC 0x0701 - -#define EC_LEFTMARGIN 0x0001 -#define EC_RIGHTMARGIN 0x0002 -#define EC_USEFONTINFO 0xffff - -#define EMSIS_COMPOSITIONSTRING 0x0001 - -#define EIMES_GETCOMPSTRATONCE 0x0001 -#define EIMES_CANCELCOMPSTRINFOCUS 0x0002 -#define EIMES_COMPLETECOMPSTRKILLFOCUS 0x0004 - -#ifndef NOWINMESSAGES - -#define EM_GETSEL 0x00B0 -#define EM_SETSEL 0x00B1 -#define EM_GETRECT 0x00B2 -#define EM_SETRECT 0x00B3 -#define EM_SETRECTNP 0x00B4 -#define EM_SCROLL 0x00B5 -#define EM_LINESCROLL 0x00B6 -#define EM_SCROLLCARET 0x00B7 -#define EM_GETMODIFY 0x00B8 -#define EM_SETMODIFY 0x00B9 -#define EM_GETLINECOUNT 0x00BA -#define EM_LINEINDEX 0x00BB -#define EM_SETHANDLE 0x00BC -#define EM_GETHANDLE 0x00BD -#define EM_GETTHUMB 0x00BE -#define EM_LINELENGTH 0x00C1 -#define EM_REPLACESEL 0x00C2 -#define EM_GETLINE 0x00C4 -#define EM_LIMITTEXT 0x00C5 -#define EM_CANUNDO 0x00C6 -#define EM_UNDO 0x00C7 -#define EM_FMTLINES 0x00C8 -#define EM_LINEFROMCHAR 0x00C9 -#define EM_SETTABSTOPS 0x00CB -#define EM_SETPASSWORDCHAR 0x00CC -#define EM_EMPTYUNDOBUFFER 0x00CD -#define EM_GETFIRSTVISIBLELINE 0x00CE -#define EM_SETREADONLY 0x00CF -#define EM_SETWORDBREAKPROC 0x00D0 -#define EM_GETWORDBREAKPROC 0x00D1 -#define EM_GETPASSWORDCHAR 0x00D2 -#define EM_SETMARGINS 0x00D3 -#define EM_GETMARGINS 0x00D4 -#define EM_SETLIMITTEXT EM_LIMITTEXT -#define EM_GETLIMITTEXT 0x00D5 -#define EM_POSFROMCHAR 0x00D6 -#define EM_CHARFROMPOS 0x00D7 -#define EM_SETIMESTATUS 0x00D8 -#define EM_GETIMESTATUS 0x00D9 -#endif - -#define WB_LEFT 0 -#define WB_RIGHT 1 -#define WB_ISDELIMITER 2 - -#define BS_PUSHBUTTON 0x00000000L -#define BS_DEFPUSHBUTTON 0x00000001L -#define BS_CHECKBOX 0x00000002L -#define BS_AUTOCHECKBOX 0x00000003L -#define BS_RADIOBUTTON 0x00000004L -#define BS_3STATE 0x00000005L -#define BS_AUTO3STATE 0x00000006L -#define BS_GROUPBOX 0x00000007L -#define BS_USERBUTTON 0x00000008L -#define BS_AUTORADIOBUTTON 0x00000009L -#define BS_PUSHBOX 0x0000000AL -#define BS_OWNERDRAW 0x0000000BL -#define BS_TYPEMASK 0x0000000FL -#define BS_LEFTTEXT 0x00000020L -#define BS_TEXT 0x00000000L -#define BS_ICON 0x00000040L -#define BS_BITMAP 0x00000080L -#define BS_LEFT 0x00000100L -#define BS_RIGHT 0x00000200L -#define BS_CENTER 0x00000300L -#define BS_TOP 0x00000400L -#define BS_BOTTOM 0x00000800L -#define BS_VCENTER 0x00000C00L -#define BS_PUSHLIKE 0x00001000L -#define BS_MULTILINE 0x00002000L -#define BS_NOTIFY 0x00004000L -#define BS_FLAT 0x00008000L -#define BS_RIGHTBUTTON BS_LEFTTEXT - -#define BN_CLICKED 0 -#define BN_PAINT 1 -#define BN_HILITE 2 -#define BN_UNHILITE 3 -#define BN_DISABLE 4 -#define BN_DOUBLECLICKED 5 -#define BN_PUSHED BN_HILITE -#define BN_UNPUSHED BN_UNHILITE -#define BN_DBLCLK BN_DOUBLECLICKED -#define BN_SETFOCUS 6 -#define BN_KILLFOCUS 7 - -#define BM_GETCHECK 0x00F0 -#define BM_SETCHECK 0x00F1 -#define BM_GETSTATE 0x00F2 -#define BM_SETSTATE 0x00F3 -#define BM_SETSTYLE 0x00F4 -#define BM_CLICK 0x00F5 -#define BM_GETIMAGE 0x00F6 -#define BM_SETIMAGE 0x00F7 - -#define BST_UNCHECKED 0x0000 -#define BST_CHECKED 0x0001 -#define BST_INDETERMINATE 0x0002 -#define BST_PUSHED 0x0004 -#define BST_FOCUS 0x0008 - -#define SS_LEFT 0x00000000L -#define SS_CENTER 0x00000001L -#define SS_RIGHT 0x00000002L -#define SS_ICON 0x00000003L -#define SS_BLACKRECT 0x00000004L -#define SS_GRAYRECT 0x00000005L -#define SS_WHITERECT 0x00000006L -#define SS_BLACKFRAME 0x00000007L -#define SS_GRAYFRAME 0x00000008L -#define SS_WHITEFRAME 0x00000009L -#define SS_USERITEM 0x0000000AL -#define SS_SIMPLE 0x0000000BL -#define SS_LEFTNOWORDWRAP 0x0000000CL -#define SS_OWNERDRAW 0x0000000DL -#define SS_BITMAP 0x0000000EL -#define SS_ENHMETAFILE 0x0000000FL -#define SS_ETCHEDHORZ 0x00000010L -#define SS_ETCHEDVERT 0x00000011L -#define SS_ETCHEDFRAME 0x00000012L -#define SS_TYPEMASK 0x0000001FL -#define SS_REALSIZECONTROL 0x00000040L -#define SS_NOPREFIX 0x00000080L -#define SS_NOTIFY 0x00000100L -#define SS_CENTERIMAGE 0x00000200L -#define SS_RIGHTJUST 0x00000400L -#define SS_REALSIZEIMAGE 0x00000800L -#define SS_SUNKEN 0x00001000L -#define SS_EDITCONTROL 0x00002000L -#define SS_ENDELLIPSIS 0x00004000L -#define SS_PATHELLIPSIS 0x00008000L -#define SS_WORDELLIPSIS 0x0000C000L -#define SS_ELLIPSISMASK 0x0000C000L - -#ifndef NOWINMESSAGES - -#define STM_SETICON 0x0170 -#define STM_GETICON 0x0171 -#define STM_SETIMAGE 0x0172 -#define STM_GETIMAGE 0x0173 -#define STN_CLICKED 0 -#define STN_DBLCLK 1 -#define STN_ENABLE 2 -#define STN_DISABLE 3 -#define STM_MSGMAX 0x0174 -#endif - -#define WC_DIALOG (MAKEINTATOM(0x8002)) - -#define DWL_MSGRESULT 0 -#define DWL_DLGPROC 4 -#define DWL_USER 8 - -#ifdef _WIN64 - -#undef DWL_MSGRESULT -#undef DWL_DLGPROC -#undef DWL_USER -#endif - -#define DWLP_MSGRESULT 0 -#define DWLP_DLGPROC DWLP_MSGRESULT + sizeof(LRESULT) -#define DWLP_USER DWLP_DLGPROC + sizeof(DLGPROC) - -#ifndef NOMSG - -#ifdef UNICODE -#define IsDialogMessage IsDialogMessageW -#else -#define IsDialogMessage IsDialogMessageA -#endif - - WINUSERAPI WINBOOL WINAPI IsDialogMessageA(HWND hDlg,LPMSG lpMsg); - WINUSERAPI WINBOOL WINAPI IsDialogMessageW(HWND hDlg,LPMSG lpMsg); -#endif - -#ifdef UNICODE -#define DlgDirList DlgDirListW -#define DlgDirSelectEx DlgDirSelectExW -#define DlgDirListComboBox DlgDirListComboBoxW -#define DlgDirSelectComboBoxEx DlgDirSelectComboBoxExW -#else -#define DlgDirList DlgDirListA -#define DlgDirSelectEx DlgDirSelectExA -#define DlgDirListComboBox DlgDirListComboBoxA -#define DlgDirSelectComboBoxEx DlgDirSelectComboBoxExA -#endif - - WINUSERAPI WINBOOL WINAPI MapDialogRect(HWND hDlg,LPRECT lpRect); - WINUSERAPI int WINAPI DlgDirListA(HWND hDlg,LPSTR lpPathSpec,int nIDListBox,int nIDStaticPath,UINT uFileType); - WINUSERAPI int WINAPI DlgDirListW(HWND hDlg,LPWSTR lpPathSpec,int nIDListBox,int nIDStaticPath,UINT uFileType); - -#define DDL_READWRITE 0x0000 -#define DDL_READONLY 0x0001 -#define DDL_HIDDEN 0x0002 -#define DDL_SYSTEM 0x0004 -#define DDL_DIRECTORY 0x0010 -#define DDL_ARCHIVE 0x0020 - -#define DDL_POSTMSGS 0x2000 -#define DDL_DRIVES 0x4000 -#define DDL_EXCLUSIVE 0x8000 - - WINUSERAPI WINBOOL WINAPI DlgDirSelectExA(HWND hwndDlg,LPSTR lpString,int chCount,int idListBox); - WINUSERAPI WINBOOL WINAPI DlgDirSelectExW(HWND hwndDlg,LPWSTR lpString,int chCount,int idListBox); - WINUSERAPI int WINAPI DlgDirListComboBoxA(HWND hDlg,LPSTR lpPathSpec,int nIDComboBox,int nIDStaticPath,UINT uFiletype); - WINUSERAPI int WINAPI DlgDirListComboBoxW(HWND hDlg,LPWSTR lpPathSpec,int nIDComboBox,int nIDStaticPath,UINT uFiletype); - WINUSERAPI WINBOOL WINAPI DlgDirSelectComboBoxExA(HWND hwndDlg,LPSTR lpString,int cchOut,int idComboBox); - WINUSERAPI WINBOOL WINAPI DlgDirSelectComboBoxExW(HWND hwndDlg,LPWSTR lpString,int cchOut,int idComboBox); - -#define DS_ABSALIGN 0x01L -#define DS_SYSMODAL 0x02L -#define DS_LOCALEDIT 0x20L -#define DS_SETFONT 0x40L -#define DS_MODALFRAME 0x80L -#define DS_NOIDLEMSG 0x100L -#define DS_SETFOREGROUND 0x200L - -#define DS_3DLOOK 0x0004L -#define DS_FIXEDSYS 0x0008L -#define DS_NOFAILCREATE 0x0010L -#define DS_CONTROL 0x0400L -#define DS_CENTER 0x0800L -#define DS_CENTERMOUSE 0x1000L -#define DS_CONTEXTHELP 0x2000L - -#define DS_SHELLFONT (DS_SETFONT | DS_FIXEDSYS) - -#if(_WIN32_WCE >= 0x0500) -#define DS_USEPIXELS 0x8000L -#endif - -#define DM_GETDEFID (WM_USER+0) -#define DM_SETDEFID (WM_USER+1) -#define DM_REPOSITION (WM_USER+2) - -#define DC_HASDEFID 0x534B - -#define DLGC_WANTARROWS 0x0001 -#define DLGC_WANTTAB 0x0002 -#define DLGC_WANTALLKEYS 0x0004 -#define DLGC_WANTMESSAGE 0x0004 -#define DLGC_HASSETSEL 0x0008 -#define DLGC_DEFPUSHBUTTON 0x0010 -#define DLGC_UNDEFPUSHBUTTON 0x0020 -#define DLGC_RADIOBUTTON 0x0040 -#define DLGC_WANTCHARS 0x0080 -#define DLGC_STATIC 0x0100 -#define DLGC_BUTTON 0x2000 - -#define LB_CTLCODE 0L - -#define LB_OKAY 0 -#define LB_ERR (-1) -#define LB_ERRSPACE (-2) - -#define LBN_ERRSPACE (-2) -#define LBN_SELCHANGE 1 -#define LBN_DBLCLK 2 -#define LBN_SELCANCEL 3 -#define LBN_SETFOCUS 4 -#define LBN_KILLFOCUS 5 - -#ifndef NOWINMESSAGES - -#define LB_ADDSTRING 0x0180 -#define LB_INSERTSTRING 0x0181 -#define LB_DELETESTRING 0x0182 -#define LB_SELITEMRANGEEX 0x0183 -#define LB_RESETCONTENT 0x0184 -#define LB_SETSEL 0x0185 -#define LB_SETCURSEL 0x0186 -#define LB_GETSEL 0x0187 -#define LB_GETCURSEL 0x0188 -#define LB_GETTEXT 0x0189 -#define LB_GETTEXTLEN 0x018A -#define LB_GETCOUNT 0x018B -#define LB_SELECTSTRING 0x018C -#define LB_DIR 0x018D -#define LB_GETTOPINDEX 0x018E -#define LB_FINDSTRING 0x018F -#define LB_GETSELCOUNT 0x0190 -#define LB_GETSELITEMS 0x0191 -#define LB_SETTABSTOPS 0x0192 -#define LB_GETHORIZONTALEXTENT 0x0193 -#define LB_SETHORIZONTALEXTENT 0x0194 -#define LB_SETCOLUMNWIDTH 0x0195 -#define LB_ADDFILE 0x0196 -#define LB_SETTOPINDEX 0x0197 -#define LB_GETITEMRECT 0x0198 -#define LB_GETITEMDATA 0x0199 -#define LB_SETITEMDATA 0x019A -#define LB_SELITEMRANGE 0x019B -#define LB_SETANCHORINDEX 0x019C -#define LB_GETANCHORINDEX 0x019D -#define LB_SETCARETINDEX 0x019E -#define LB_GETCARETINDEX 0x019F -#define LB_SETITEMHEIGHT 0x01A0 -#define LB_GETITEMHEIGHT 0x01A1 -#define LB_FINDSTRINGEXACT 0x01A2 -#define LB_SETLOCALE 0x01A5 -#define LB_GETLOCALE 0x01A6 -#define LB_SETCOUNT 0x01A7 -#define LB_INITSTORAGE 0x01A8 -#define LB_ITEMFROMPOINT 0x01A9 -#if(_WIN32_WCE >= 0x0400) -#define LB_MULTIPLEADDSTRING 0x01B1 -#endif -#define LB_GETLISTBOXINFO 0x01B2 -#define LB_MSGMAX 0x01B3 -#endif - -#ifndef NOWINSTYLES - -#define LBS_NOTIFY 0x0001L -#define LBS_SORT 0x0002L -#define LBS_NOREDRAW 0x0004L -#define LBS_MULTIPLESEL 0x0008L -#define LBS_OWNERDRAWFIXED 0x0010L -#define LBS_OWNERDRAWVARIABLE 0x0020L -#define LBS_HASSTRINGS 0x0040L -#define LBS_USETABSTOPS 0x0080L -#define LBS_NOINTEGRALHEIGHT 0x0100L -#define LBS_MULTICOLUMN 0x0200L -#define LBS_WANTKEYBOARDINPUT 0x0400L -#define LBS_EXTENDEDSEL 0x0800L -#define LBS_DISABLENOSCROLL 0x1000L -#define LBS_NODATA 0x2000L -#define LBS_NOSEL 0x4000L -#define LBS_COMBOBOX 0x8000L - -#define LBS_STANDARD (LBS_NOTIFY | LBS_SORT | WS_VSCROLL | WS_BORDER) -#endif - -#define CB_OKAY 0 -#define CB_ERR (-1) -#define CB_ERRSPACE (-2) - -#define CBN_ERRSPACE (-1) -#define CBN_SELCHANGE 1 -#define CBN_DBLCLK 2 -#define CBN_SETFOCUS 3 -#define CBN_KILLFOCUS 4 -#define CBN_EDITCHANGE 5 -#define CBN_EDITUPDATE 6 -#define CBN_DROPDOWN 7 -#define CBN_CLOSEUP 8 -#define CBN_SELENDOK 9 -#define CBN_SELENDCANCEL 10 - -#ifndef NOWINSTYLES - -#define CBS_SIMPLE 0x0001L -#define CBS_DROPDOWN 0x0002L -#define CBS_DROPDOWNLIST 0x0003L -#define CBS_OWNERDRAWFIXED 0x0010L -#define CBS_OWNERDRAWVARIABLE 0x0020L -#define CBS_AUTOHSCROLL 0x0040L -#define CBS_OEMCONVERT 0x0080L -#define CBS_SORT 0x0100L -#define CBS_HASSTRINGS 0x0200L -#define CBS_NOINTEGRALHEIGHT 0x0400L -#define CBS_DISABLENOSCROLL 0x0800L -#define CBS_UPPERCASE 0x2000L -#define CBS_LOWERCASE 0x4000L -#endif - -#ifndef NOWINMESSAGES -#define CB_GETEDITSEL 0x0140 -#define CB_LIMITTEXT 0x0141 -#define CB_SETEDITSEL 0x0142 -#define CB_ADDSTRING 0x0143 -#define CB_DELETESTRING 0x0144 -#define CB_DIR 0x0145 -#define CB_GETCOUNT 0x0146 -#define CB_GETCURSEL 0x0147 -#define CB_GETLBTEXT 0x0148 -#define CB_GETLBTEXTLEN 0x0149 -#define CB_INSERTSTRING 0x014A -#define CB_RESETCONTENT 0x014B -#define CB_FINDSTRING 0x014C -#define CB_SELECTSTRING 0x014D -#define CB_SETCURSEL 0x014E -#define CB_SHOWDROPDOWN 0x014F -#define CB_GETITEMDATA 0x0150 -#define CB_SETITEMDATA 0x0151 -#define CB_GETDROPPEDCONTROLRECT 0x0152 -#define CB_SETITEMHEIGHT 0x0153 -#define CB_GETITEMHEIGHT 0x0154 -#define CB_SETEXTENDEDUI 0x0155 -#define CB_GETEXTENDEDUI 0x0156 -#define CB_GETDROPPEDSTATE 0x0157 -#define CB_FINDSTRINGEXACT 0x0158 -#define CB_SETLOCALE 0x0159 -#define CB_GETLOCALE 0x015A -#define CB_GETTOPINDEX 0x015b -#define CB_SETTOPINDEX 0x015c -#define CB_GETHORIZONTALEXTENT 0x015d -#define CB_SETHORIZONTALEXTENT 0x015e -#define CB_GETDROPPEDWIDTH 0x015f -#define CB_SETDROPPEDWIDTH 0x0160 -#define CB_INITSTORAGE 0x0161 -#if(_WIN32_WCE >= 0x0400) -#define CB_MULTIPLEADDSTRING 0x0163 -#endif -#define CB_GETCOMBOBOXINFO 0x0164 -#define CB_MSGMAX 0x0165 -#endif - -#ifndef NOWINSTYLES - -#define SBS_HORZ 0x0000L -#define SBS_VERT 0x0001L -#define SBS_TOPALIGN 0x0002L -#define SBS_LEFTALIGN 0x0002L -#define SBS_BOTTOMALIGN 0x0004L -#define SBS_RIGHTALIGN 0x0004L -#define SBS_SIZEBOXTOPLEFTALIGN 0x0002L -#define SBS_SIZEBOXBOTTOMRIGHTALIGN 0x0004L -#define SBS_SIZEBOX 0x0008L -#define SBS_SIZEGRIP 0x0010L -#endif - -#ifndef NOWINMESSAGES -#define SBM_SETPOS 0x00E0 -#define SBM_GETPOS 0x00E1 -#define SBM_SETRANGE 0x00E2 -#define SBM_SETRANGEREDRAW 0x00E6 -#define SBM_GETRANGE 0x00E3 -#define SBM_ENABLE_ARROWS 0x00E4 -#define SBM_SETSCROLLINFO 0x00E9 -#define SBM_GETSCROLLINFO 0x00EA -#define SBM_GETSCROLLBARINFO 0x00EB - -#define SIF_RANGE 0x0001 -#define SIF_PAGE 0x0002 -#define SIF_POS 0x0004 -#define SIF_DISABLENOSCROLL 0x0008 -#define SIF_TRACKPOS 0x0010 -#define SIF_ALL (SIF_RANGE | SIF_PAGE | SIF_POS | SIF_TRACKPOS) - - typedef struct tagSCROLLINFO { - UINT cbSize; - UINT fMask; - int nMin; - int nMax; - UINT nPage; - int nPos; - int nTrackPos; - } SCROLLINFO,*LPSCROLLINFO; - typedef SCROLLINFO CONST *LPCSCROLLINFO; - - WINUSERAPI int WINAPI SetScrollInfo(HWND hwnd,int nBar,LPCSCROLLINFO lpsi,WINBOOL redraw); - WINUSERAPI WINBOOL WINAPI GetScrollInfo(HWND hwnd,int nBar,LPSCROLLINFO lpsi); -#endif -#endif - -#ifndef NOMDI - -#define MDIS_ALLCHILDSTYLES 0x0001 - -#define MDITILE_VERTICAL 0x0000 -#define MDITILE_HORIZONTAL 0x0001 -#define MDITILE_SKIPDISABLED 0x0002 -#define MDITILE_ZORDER 0x0004 - - typedef struct tagMDICREATESTRUCTA { - LPCSTR szClass; - LPCSTR szTitle; - HANDLE hOwner; - int x; - int y; - int cx; - int cy; - DWORD style; - LPARAM lParam; - } MDICREATESTRUCTA,*LPMDICREATESTRUCTA; - - typedef struct tagMDICREATESTRUCTW { - LPCWSTR szClass; - LPCWSTR szTitle; - HANDLE hOwner; - int x; - int y; - int cx; - int cy; - DWORD style; - LPARAM lParam; - } MDICREATESTRUCTW,*LPMDICREATESTRUCTW; - -#ifdef UNICODE - typedef MDICREATESTRUCTW MDICREATESTRUCT; - typedef LPMDICREATESTRUCTW LPMDICREATESTRUCT; -#else - typedef MDICREATESTRUCTA MDICREATESTRUCT; - typedef LPMDICREATESTRUCTA LPMDICREATESTRUCT; -#endif - - typedef struct tagCLIENTCREATESTRUCT { - HANDLE hWindowMenu; - UINT idFirstChild; - } CLIENTCREATESTRUCT,*LPCLIENTCREATESTRUCT; - -#ifdef UNICODE -#define DefFrameProc DefFrameProcW -#define DefMDIChildProc DefMDIChildProcW -#define CreateMDIWindow CreateMDIWindowW -#else -#define DefFrameProc DefFrameProcA -#define DefMDIChildProc DefMDIChildProcA -#define CreateMDIWindow CreateMDIWindowA -#endif - - WINUSERAPI LRESULT WINAPI DefFrameProcA(HWND hWnd,HWND hWndMDIClient,UINT uMsg,WPARAM wParam,LPARAM lParam); - WINUSERAPI LRESULT WINAPI DefFrameProcW(HWND hWnd,HWND hWndMDIClient,UINT uMsg,WPARAM wParam,LPARAM lParam); - WINUSERAPI LRESULT WINAPI DefMDIChildProcA(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam); - WINUSERAPI LRESULT WINAPI DefMDIChildProcW(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam); - -#ifndef NOMSG - WINUSERAPI WINBOOL WINAPI TranslateMDISysAccel(HWND hWndClient,LPMSG lpMsg); -#endif - - WINUSERAPI UINT WINAPI ArrangeIconicWindows(HWND hWnd); - WINUSERAPI HWND WINAPI CreateMDIWindowA(LPCSTR lpClassName,LPCSTR lpWindowName,DWORD dwStyle,int X,int Y,int nWidth,int nHeight,HWND hWndParent,HINSTANCE hInstance,LPARAM lParam); - WINUSERAPI HWND WINAPI CreateMDIWindowW(LPCWSTR lpClassName,LPCWSTR lpWindowName,DWORD dwStyle,int X,int Y,int nWidth,int nHeight,HWND hWndParent,HINSTANCE hInstance,LPARAM lParam); - WINUSERAPI WORD WINAPI TileWindows(HWND hwndParent,UINT wHow,CONST RECT *lpRect,UINT cKids,const HWND *lpKids); - WINUSERAPI WORD WINAPI CascadeWindows(HWND hwndParent,UINT wHow,CONST RECT *lpRect,UINT cKids,const HWND *lpKids); -#endif -#endif - -#ifndef NOHELP - - typedef DWORD HELPPOLY; - typedef struct tagMULTIKEYHELPA { - DWORD mkSize; - CHAR mkKeylist; - CHAR szKeyphrase[1]; - } MULTIKEYHELPA,*PMULTIKEYHELPA,*LPMULTIKEYHELPA; - - typedef struct tagMULTIKEYHELPW { - DWORD mkSize; - WCHAR mkKeylist; - WCHAR szKeyphrase[1]; - } MULTIKEYHELPW,*PMULTIKEYHELPW,*LPMULTIKEYHELPW; - -#ifdef UNICODE - typedef MULTIKEYHELPW MULTIKEYHELP; - typedef PMULTIKEYHELPW PMULTIKEYHELP; - typedef LPMULTIKEYHELPW LPMULTIKEYHELP; -#else - typedef MULTIKEYHELPA MULTIKEYHELP; - typedef PMULTIKEYHELPA PMULTIKEYHELP; - typedef LPMULTIKEYHELPA LPMULTIKEYHELP; -#endif - - typedef struct tagHELPWININFOA { - int wStructSize; - int x; - int y; - int dx; - int dy; - int wMax; - CHAR rgchMember[2]; - } HELPWININFOA,*PHELPWININFOA,*LPHELPWININFOA; - - typedef struct tagHELPWININFOW { - int wStructSize; - int x; - int y; - int dx; - int dy; - int wMax; - WCHAR rgchMember[2]; - } HELPWININFOW,*PHELPWININFOW,*LPHELPWININFOW; - -#ifdef UNICODE - typedef HELPWININFOW HELPWININFO; - typedef PHELPWININFOW PHELPWININFO; - typedef LPHELPWININFOW LPHELPWININFO; -#else - typedef HELPWININFOA HELPWININFO; - typedef PHELPWININFOA PHELPWININFO; - typedef LPHELPWININFOA LPHELPWININFO; -#endif - -#define HELP_CONTEXT 0x0001L -#define HELP_QUIT 0x0002L -#define HELP_INDEX 0x0003L -#define HELP_CONTENTS 0x0003L -#define HELP_HELPONHELP 0x0004L -#define HELP_SETINDEX 0x0005L -#define HELP_SETCONTENTS 0x0005L -#define HELP_CONTEXTPOPUP 0x0008L -#define HELP_FORCEFILE 0x0009L -#define HELP_KEY 0x0101L -#define HELP_COMMAND 0x0102L -#define HELP_PARTIALKEY 0x0105L -#define HELP_MULTIKEY 0x0201L -#define HELP_SETWINPOS 0x0203L -#define HELP_CONTEXTMENU 0x000a -#define HELP_FINDER 0x000b -#define HELP_WM_HELP 0x000c -#define HELP_SETPOPUP_POS 0x000d - -#define HELP_TCARD 0x8000 -#define HELP_TCARD_DATA 0x0010 -#define HELP_TCARD_OTHER_CALLER 0x0011 - -#define IDH_NO_HELP 28440 -#define IDH_MISSING_CONTEXT 28441 -#define IDH_GENERIC_HELP_BUTTON 28442 -#define IDH_OK 28443 -#define IDH_CANCEL 28444 -#define IDH_HELP 28445 - -#ifdef UNICODE -#define WinHelp WinHelpW -#else -#define WinHelp WinHelpA -#endif - - WINUSERAPI WINBOOL WINAPI WinHelpA(HWND hWndMain,LPCSTR lpszHelp,UINT uCommand,ULONG_PTR dwData); - WINUSERAPI WINBOOL WINAPI WinHelpW(HWND hWndMain,LPCWSTR lpszHelp,UINT uCommand,ULONG_PTR dwData); -#endif - -#define GR_GDIOBJECTS 0 -#define GR_USEROBJECTS 1 - - WINUSERAPI DWORD WINAPI GetGuiResources(HANDLE hProcess,DWORD uiFlags); - -#ifndef NOSYSPARAMSINFO - -#define SPI_GETBEEP 0x0001 -#define SPI_SETBEEP 0x0002 -#define SPI_GETMOUSE 0x0003 -#define SPI_SETMOUSE 0x0004 -#define SPI_GETBORDER 0x0005 -#define SPI_SETBORDER 0x0006 -#define SPI_GETKEYBOARDSPEED 0x000A -#define SPI_SETKEYBOARDSPEED 0x000B -#define SPI_LANGDRIVER 0x000C -#define SPI_ICONHORIZONTALSPACING 0x000D -#define SPI_GETSCREENSAVETIMEOUT 0x000E -#define SPI_SETSCREENSAVETIMEOUT 0x000F -#define SPI_GETSCREENSAVEACTIVE 0x0010 -#define SPI_SETSCREENSAVEACTIVE 0x0011 -#define SPI_GETGRIDGRANULARITY 0x0012 -#define SPI_SETGRIDGRANULARITY 0x0013 -#define SPI_SETDESKWALLPAPER 0x0014 -#define SPI_SETDESKPATTERN 0x0015 -#define SPI_GETKEYBOARDDELAY 0x0016 -#define SPI_SETKEYBOARDDELAY 0x0017 -#define SPI_ICONVERTICALSPACING 0x0018 -#define SPI_GETICONTITLEWRAP 0x0019 -#define SPI_SETICONTITLEWRAP 0x001A -#define SPI_GETMENUDROPALIGNMENT 0x001B -#define SPI_SETMENUDROPALIGNMENT 0x001C -#define SPI_SETDOUBLECLKWIDTH 0x001D -#define SPI_SETDOUBLECLKHEIGHT 0x001E -#define SPI_GETICONTITLELOGFONT 0x001F -#define SPI_SETDOUBLECLICKTIME 0x0020 -#define SPI_SETMOUSEBUTTONSWAP 0x0021 -#define SPI_SETICONTITLELOGFONT 0x0022 -#define SPI_GETFASTTASKSWITCH 0x0023 -#define SPI_SETFASTTASKSWITCH 0x0024 -#define SPI_SETDRAGFULLWINDOWS 0x0025 -#define SPI_GETDRAGFULLWINDOWS 0x0026 -#define SPI_GETNONCLIENTMETRICS 0x0029 -#define SPI_SETNONCLIENTMETRICS 0x002A -#define SPI_GETMINIMIZEDMETRICS 0x002B -#define SPI_SETMINIMIZEDMETRICS 0x002C -#define SPI_GETICONMETRICS 0x002D -#define SPI_SETICONMETRICS 0x002E -#define SPI_SETWORKAREA 0x002F -#define SPI_GETWORKAREA 0x0030 -#define SPI_SETPENWINDOWS 0x0031 - -#define SPI_GETHIGHCONTRAST 0x0042 -#define SPI_SETHIGHCONTRAST 0x0043 -#define SPI_GETKEYBOARDPREF 0x0044 -#define SPI_SETKEYBOARDPREF 0x0045 -#define SPI_GETSCREENREADER 0x0046 -#define SPI_SETSCREENREADER 0x0047 -#define SPI_GETANIMATION 0x0048 -#define SPI_SETANIMATION 0x0049 -#define SPI_GETFONTSMOOTHING 0x004A -#define SPI_SETFONTSMOOTHING 0x004B -#define SPI_SETDRAGWIDTH 0x004C -#define SPI_SETDRAGHEIGHT 0x004D -#define SPI_SETHANDHELD 0x004E -#define SPI_GETLOWPOWERTIMEOUT 0x004F -#define SPI_GETPOWEROFFTIMEOUT 0x0050 -#define SPI_SETLOWPOWERTIMEOUT 0x0051 -#define SPI_SETPOWEROFFTIMEOUT 0x0052 -#define SPI_GETLOWPOWERACTIVE 0x0053 -#define SPI_GETPOWEROFFACTIVE 0x0054 -#define SPI_SETLOWPOWERACTIVE 0x0055 -#define SPI_SETPOWEROFFACTIVE 0x0056 -#define SPI_SETCURSORS 0x0057 -#define SPI_SETICONS 0x0058 -#define SPI_GETDEFAULTINPUTLANG 0x0059 -#define SPI_SETDEFAULTINPUTLANG 0x005A -#define SPI_SETLANGTOGGLE 0x005B -#define SPI_GETWINDOWSEXTENSION 0x005C -#define SPI_SETMOUSETRAILS 0x005D -#define SPI_GETMOUSETRAILS 0x005E -#define SPI_SETSCREENSAVERRUNNING 0x0061 -#define SPI_SCREENSAVERRUNNING SPI_SETSCREENSAVERRUNNING -#define SPI_GETFILTERKEYS 0x0032 -#define SPI_SETFILTERKEYS 0x0033 -#define SPI_GETTOGGLEKEYS 0x0034 -#define SPI_SETTOGGLEKEYS 0x0035 -#define SPI_GETMOUSEKEYS 0x0036 -#define SPI_SETMOUSEKEYS 0x0037 -#define SPI_GETSHOWSOUNDS 0x0038 -#define SPI_SETSHOWSOUNDS 0x0039 -#define SPI_GETSTICKYKEYS 0x003A -#define SPI_SETSTICKYKEYS 0x003B -#define SPI_GETACCESSTIMEOUT 0x003C -#define SPI_SETACCESSTIMEOUT 0x003D -#define SPI_GETSERIALKEYS 0x003E -#define SPI_SETSERIALKEYS 0x003F -#define SPI_GETSOUNDSENTRY 0x0040 -#define SPI_SETSOUNDSENTRY 0x0041 -#define SPI_GETSNAPTODEFBUTTON 0x005F -#define SPI_SETSNAPTODEFBUTTON 0x0060 -#define SPI_GETMOUSEHOVERWIDTH 0x0062 -#define SPI_SETMOUSEHOVERWIDTH 0x0063 -#define SPI_GETMOUSEHOVERHEIGHT 0x0064 -#define SPI_SETMOUSEHOVERHEIGHT 0x0065 -#define SPI_GETMOUSEHOVERTIME 0x0066 -#define SPI_SETMOUSEHOVERTIME 0x0067 -#define SPI_GETWHEELSCROLLLINES 0x0068 -#define SPI_SETWHEELSCROLLLINES 0x0069 -#define SPI_GETMENUSHOWDELAY 0x006A -#define SPI_SETMENUSHOWDELAY 0x006B -#define SPI_GETSHOWIMEUI 0x006E -#define SPI_SETSHOWIMEUI 0x006F -#define SPI_GETMOUSESPEED 0x0070 -#define SPI_SETMOUSESPEED 0x0071 -#define SPI_GETSCREENSAVERRUNNING 0x0072 -#define SPI_GETDESKWALLPAPER 0x0073 - -#define SPI_GETACTIVEWINDOWTRACKING 0x1000 -#define SPI_SETACTIVEWINDOWTRACKING 0x1001 -#define SPI_GETMENUANIMATION 0x1002 -#define SPI_SETMENUANIMATION 0x1003 -#define SPI_GETCOMBOBOXANIMATION 0x1004 -#define SPI_SETCOMBOBOXANIMATION 0x1005 -#define SPI_GETLISTBOXSMOOTHSCROLLING 0x1006 -#define SPI_SETLISTBOXSMOOTHSCROLLING 0x1007 -#define SPI_GETGRADIENTCAPTIONS 0x1008 -#define SPI_SETGRADIENTCAPTIONS 0x1009 -#define SPI_GETKEYBOARDCUES 0x100A -#define SPI_SETKEYBOARDCUES 0x100B -#define SPI_GETMENUUNDERLINES SPI_GETKEYBOARDCUES -#define SPI_SETMENUUNDERLINES SPI_SETKEYBOARDCUES -#define SPI_GETACTIVEWNDTRKZORDER 0x100C -#define SPI_SETACTIVEWNDTRKZORDER 0x100D -#define SPI_GETHOTTRACKING 0x100E -#define SPI_SETHOTTRACKING 0x100F -#define SPI_GETMENUFADE 0x1012 -#define SPI_SETMENUFADE 0x1013 -#define SPI_GETSELECTIONFADE 0x1014 -#define SPI_SETSELECTIONFADE 0x1015 -#define SPI_GETTOOLTIPANIMATION 0x1016 -#define SPI_SETTOOLTIPANIMATION 0x1017 -#define SPI_GETTOOLTIPFADE 0x1018 -#define SPI_SETTOOLTIPFADE 0x1019 -#define SPI_GETCURSORSHADOW 0x101A -#define SPI_SETCURSORSHADOW 0x101B -#define SPI_GETMOUSESONAR 0x101C -#define SPI_SETMOUSESONAR 0x101D -#define SPI_GETMOUSECLICKLOCK 0x101E -#define SPI_SETMOUSECLICKLOCK 0x101F -#define SPI_GETMOUSEVANISH 0x1020 -#define SPI_SETMOUSEVANISH 0x1021 -#define SPI_GETFLATMENU 0x1022 -#define SPI_SETFLATMENU 0x1023 -#define SPI_GETDROPSHADOW 0x1024 -#define SPI_SETDROPSHADOW 0x1025 -#define SPI_GETBLOCKSENDINPUTRESETS 0x1026 -#define SPI_SETBLOCKSENDINPUTRESETS 0x1027 -#define SPI_GETUIEFFECTS 0x103E -#define SPI_SETUIEFFECTS 0x103F -#define SPI_GETFOREGROUNDLOCKTIMEOUT 0x2000 -#define SPI_SETFOREGROUNDLOCKTIMEOUT 0x2001 -#define SPI_GETACTIVEWNDTRKTIMEOUT 0x2002 -#define SPI_SETACTIVEWNDTRKTIMEOUT 0x2003 -#define SPI_GETFOREGROUNDFLASHCOUNT 0x2004 -#define SPI_SETFOREGROUNDFLASHCOUNT 0x2005 -#define SPI_GETCARETWIDTH 0x2006 -#define SPI_SETCARETWIDTH 0x2007 -#define SPI_GETMOUSECLICKLOCKTIME 0x2008 -#define SPI_SETMOUSECLICKLOCKTIME 0x2009 -#define SPI_GETFONTSMOOTHINGTYPE 0x200A -#define SPI_SETFONTSMOOTHINGTYPE 0x200B - -#define FE_FONTSMOOTHINGSTANDARD 0x0001 -#define FE_FONTSMOOTHINGCLEARTYPE 0x0002 -#define FE_FONTSMOOTHINGDOCKING 0x8000 - -#define SPI_GETFONTSMOOTHINGCONTRAST 0x200C -#define SPI_SETFONTSMOOTHINGCONTRAST 0x200D -#define SPI_GETFOCUSBORDERWIDTH 0x200E -#define SPI_SETFOCUSBORDERWIDTH 0x200F -#define SPI_GETFOCUSBORDERHEIGHT 0x2010 -#define SPI_SETFOCUSBORDERHEIGHT 0x2011 -#define SPI_GETFONTSMOOTHINGORIENTATION 0x2012 -#define SPI_SETFONTSMOOTHINGORIENTATION 0x2013 - -#define FE_FONTSMOOTHINGORIENTATIONBGR 0x0000 -#define FE_FONTSMOOTHINGORIENTATIONRGB 0x0001 - -#define SPIF_UPDATEINIFILE 0x0001 -#define SPIF_SENDWININICHANGE 0x0002 -#define SPIF_SENDCHANGE SPIF_SENDWININICHANGE - -#define METRICS_USEDEFAULT -1 -#ifdef _WINGDI_ -#ifndef NOGDI - typedef struct tagNONCLIENTMETRICSA { - UINT cbSize; - int iBorderWidth; - int iScrollWidth; - int iScrollHeight; - int iCaptionWidth; - int iCaptionHeight; - LOGFONTA lfCaptionFont; - int iSmCaptionWidth; - int iSmCaptionHeight; - LOGFONTA lfSmCaptionFont; - int iMenuWidth; - int iMenuHeight; - LOGFONTA lfMenuFont; - LOGFONTA lfStatusFont; - LOGFONTA lfMessageFont; - } NONCLIENTMETRICSA,*PNONCLIENTMETRICSA,*LPNONCLIENTMETRICSA; - - typedef struct tagNONCLIENTMETRICSW { - UINT cbSize; - int iBorderWidth; - int iScrollWidth; - int iScrollHeight; - int iCaptionWidth; - int iCaptionHeight; - LOGFONTW lfCaptionFont; - int iSmCaptionWidth; - int iSmCaptionHeight; - LOGFONTW lfSmCaptionFont; - int iMenuWidth; - int iMenuHeight; - LOGFONTW lfMenuFont; - LOGFONTW lfStatusFont; - LOGFONTW lfMessageFont; - } NONCLIENTMETRICSW,*PNONCLIENTMETRICSW,*LPNONCLIENTMETRICSW; - -#ifdef UNICODE - typedef NONCLIENTMETRICSW NONCLIENTMETRICS; - typedef PNONCLIENTMETRICSW PNONCLIENTMETRICS; - typedef LPNONCLIENTMETRICSW LPNONCLIENTMETRICS; -#else - typedef NONCLIENTMETRICSA NONCLIENTMETRICS; - typedef PNONCLIENTMETRICSA PNONCLIENTMETRICS; - typedef LPNONCLIENTMETRICSA LPNONCLIENTMETRICS; -#endif -#endif -#endif - -#define ARW_BOTTOMLEFT 0x0000L -#define ARW_BOTTOMRIGHT 0x0001L -#define ARW_TOPLEFT 0x0002L -#define ARW_TOPRIGHT 0x0003L -#define ARW_STARTMASK 0x0003L -#define ARW_STARTRIGHT 0x0001L -#define ARW_STARTTOP 0x0002L - -#define ARW_LEFT 0x0000L -#define ARW_RIGHT 0x0000L -#define ARW_UP 0x0004L -#define ARW_DOWN 0x0004L -#define ARW_HIDE 0x0008L - - typedef struct tagMINIMIZEDMETRICS { - UINT cbSize; - int iWidth; - int iHorzGap; - int iVertGap; - int iArrange; - } MINIMIZEDMETRICS,*PMINIMIZEDMETRICS,*LPMINIMIZEDMETRICS; - -#ifdef _WINGDI_ -#ifndef NOGDI - typedef struct tagICONMETRICSA { - UINT cbSize; - int iHorzSpacing; - int iVertSpacing; - int iTitleWrap; - LOGFONTA lfFont; - } ICONMETRICSA,*PICONMETRICSA,*LPICONMETRICSA; - - typedef struct tagICONMETRICSW { - UINT cbSize; - int iHorzSpacing; - int iVertSpacing; - int iTitleWrap; - LOGFONTW lfFont; - } ICONMETRICSW,*PICONMETRICSW,*LPICONMETRICSW; - -#ifdef UNICODE - typedef ICONMETRICSW ICONMETRICS; - typedef PICONMETRICSW PICONMETRICS; - typedef LPICONMETRICSW LPICONMETRICS; -#else - typedef ICONMETRICSA ICONMETRICS; - typedef PICONMETRICSA PICONMETRICS; - typedef LPICONMETRICSA LPICONMETRICS; -#endif -#endif -#endif - - typedef struct tagANIMATIONINFO { - UINT cbSize; - int iMinAnimate; - } ANIMATIONINFO,*LPANIMATIONINFO; - - typedef struct tagSERIALKEYSA { - UINT cbSize; - DWORD dwFlags; - LPSTR lpszActivePort; - LPSTR lpszPort; - UINT iBaudRate; - UINT iPortState; - UINT iActive; - } SERIALKEYSA,*LPSERIALKEYSA; - - typedef struct tagSERIALKEYSW { - UINT cbSize; - DWORD dwFlags; - LPWSTR lpszActivePort; - LPWSTR lpszPort; - UINT iBaudRate; - UINT iPortState; - UINT iActive; - } SERIALKEYSW,*LPSERIALKEYSW; - -#ifdef UNICODE - typedef SERIALKEYSW SERIALKEYS; - typedef LPSERIALKEYSW LPSERIALKEYS; -#else - typedef SERIALKEYSA SERIALKEYS; - typedef LPSERIALKEYSA LPSERIALKEYS; -#endif - -#define SERKF_SERIALKEYSON 0x00000001 -#define SERKF_AVAILABLE 0x00000002 -#define SERKF_INDICATOR 0x00000004 - - typedef struct tagHIGHCONTRASTA { - UINT cbSize; - DWORD dwFlags; - LPSTR lpszDefaultScheme; - } HIGHCONTRASTA,*LPHIGHCONTRASTA; - - typedef struct tagHIGHCONTRASTW { - UINT cbSize; - DWORD dwFlags; - LPWSTR lpszDefaultScheme; - } HIGHCONTRASTW,*LPHIGHCONTRASTW; - -#ifdef UNICODE - typedef HIGHCONTRASTW HIGHCONTRAST; - typedef LPHIGHCONTRASTW LPHIGHCONTRAST; -#else - typedef HIGHCONTRASTA HIGHCONTRAST; - typedef LPHIGHCONTRASTA LPHIGHCONTRAST; -#endif - -#define HCF_HIGHCONTRASTON 0x00000001 -#define HCF_AVAILABLE 0x00000002 -#define HCF_HOTKEYACTIVE 0x00000004 -#define HCF_CONFIRMHOTKEY 0x00000008 -#define HCF_HOTKEYSOUND 0x00000010 -#define HCF_INDICATOR 0x00000020 -#define HCF_HOTKEYAVAILABLE 0x00000040 -#define HCF_LOGONDESKTOP 0x00000100 -#define HCF_DEFAULTDESKTOP 0x00000200 - -#define CDS_UPDATEREGISTRY 0x00000001 -#define CDS_TEST 0x00000002 -#define CDS_FULLSCREEN 0x00000004 -#define CDS_GLOBAL 0x00000008 -#define CDS_SET_PRIMARY 0x00000010 -#define CDS_VIDEOPARAMETERS 0x00000020 -#define CDS_RESET 0x40000000 -#define CDS_NORESET 0x10000000 - -//gr #include - -#define DISP_CHANGE_SUCCESSFUL 0 -#define DISP_CHANGE_RESTART 1 -#define DISP_CHANGE_FAILED -1 -#define DISP_CHANGE_BADMODE -2 -#define DISP_CHANGE_NOTUPDATED -3 -#define DISP_CHANGE_BADFLAGS -4 -#define DISP_CHANGE_BADPARAM -5 -#define DISP_CHANGE_BADDUALVIEW -6 - -#ifdef _WINGDI_ -#ifndef NOGDI - -#ifdef UNICODE -#define ChangeDisplaySettings ChangeDisplaySettingsW -#define ChangeDisplaySettingsEx ChangeDisplaySettingsExW -#define EnumDisplaySettings EnumDisplaySettingsW -#define EnumDisplaySettingsEx EnumDisplaySettingsExW -#define EnumDisplayDevices EnumDisplayDevicesW -#else -#define ChangeDisplaySettings ChangeDisplaySettingsA -#define ChangeDisplaySettingsEx ChangeDisplaySettingsExA -#define EnumDisplaySettings EnumDisplaySettingsA -#define EnumDisplaySettingsEx EnumDisplaySettingsExA -#define EnumDisplayDevices EnumDisplayDevicesA -#endif - - WINUSERAPI LONG WINAPI ChangeDisplaySettingsA(LPDEVMODEA lpDevMode,DWORD dwFlags); - WINUSERAPI LONG WINAPI ChangeDisplaySettingsW(LPDEVMODEW lpDevMode,DWORD dwFlags); - WINUSERAPI LONG WINAPI ChangeDisplaySettingsExA(LPCSTR lpszDeviceName,LPDEVMODEA lpDevMode,HWND hwnd,DWORD dwflags,LPVOID lParam); - WINUSERAPI LONG WINAPI ChangeDisplaySettingsExW(LPCWSTR lpszDeviceName,LPDEVMODEW lpDevMode,HWND hwnd,DWORD dwflags,LPVOID lParam); - -#define ENUM_CURRENT_SETTINGS ((DWORD)-1) -#define ENUM_REGISTRY_SETTINGS ((DWORD)-2) - - WINUSERAPI WINBOOL WINAPI EnumDisplaySettingsA(LPCSTR lpszDeviceName,DWORD iModeNum,LPDEVMODEA lpDevMode); - WINUSERAPI WINBOOL WINAPI EnumDisplaySettingsW(LPCWSTR lpszDeviceName,DWORD iModeNum,LPDEVMODEW lpDevMode); - WINUSERAPI WINBOOL WINAPI EnumDisplaySettingsExA(LPCSTR lpszDeviceName,DWORD iModeNum,LPDEVMODEA lpDevMode,DWORD dwFlags); - WINUSERAPI WINBOOL WINAPI EnumDisplaySettingsExW(LPCWSTR lpszDeviceName,DWORD iModeNum,LPDEVMODEW lpDevMode,DWORD dwFlags); - -#define EDS_RAWMODE 0x00000002 - - WINUSERAPI WINBOOL WINAPI EnumDisplayDevicesA(LPCSTR lpDevice,DWORD iDevNum,PDISPLAY_DEVICEA lpDisplayDevice,DWORD dwFlags); - WINUSERAPI WINBOOL WINAPI EnumDisplayDevicesW(LPCWSTR lpDevice,DWORD iDevNum,PDISPLAY_DEVICEW lpDisplayDevice,DWORD dwFlags); -#endif -#endif - -#ifdef UNICODE -#define SystemParametersInfo SystemParametersInfoW -#else -#define SystemParametersInfo SystemParametersInfoA -#endif - - WINUSERAPI WINBOOL WINAPI SystemParametersInfoA(UINT uiAction,UINT uiParam,PVOID pvParam,UINT fWinIni); - WINUSERAPI WINBOOL WINAPI SystemParametersInfoW(UINT uiAction,UINT uiParam,PVOID pvParam,UINT fWinIni); -#endif - - typedef struct tagFILTERKEYS { - UINT cbSize; - DWORD dwFlags; - DWORD iWaitMSec; - DWORD iDelayMSec; - DWORD iRepeatMSec; - DWORD iBounceMSec; - } FILTERKEYS,*LPFILTERKEYS; - -#define FKF_FILTERKEYSON 0x00000001 -#define FKF_AVAILABLE 0x00000002 -#define FKF_HOTKEYACTIVE 0x00000004 -#define FKF_CONFIRMHOTKEY 0x00000008 -#define FKF_HOTKEYSOUND 0x00000010 -#define FKF_INDICATOR 0x00000020 -#define FKF_CLICKON 0x00000040 - - typedef struct tagSTICKYKEYS { - UINT cbSize; - DWORD dwFlags; - } STICKYKEYS,*LPSTICKYKEYS; - -#define SKF_STICKYKEYSON 0x00000001 -#define SKF_AVAILABLE 0x00000002 -#define SKF_HOTKEYACTIVE 0x00000004 -#define SKF_CONFIRMHOTKEY 0x00000008 -#define SKF_HOTKEYSOUND 0x00000010 -#define SKF_INDICATOR 0x00000020 -#define SKF_AUDIBLEFEEDBACK 0x00000040 -#define SKF_TRISTATE 0x00000080 -#define SKF_TWOKEYSOFF 0x00000100 -#define SKF_LALTLATCHED 0x10000000 -#define SKF_LCTLLATCHED 0x04000000 -#define SKF_LSHIFTLATCHED 0x01000000 -#define SKF_RALTLATCHED 0x20000000 -#define SKF_RCTLLATCHED 0x08000000 -#define SKF_RSHIFTLATCHED 0x02000000 -#define SKF_LWINLATCHED 0x40000000 -#define SKF_RWINLATCHED 0x80000000 -#define SKF_LALTLOCKED 0x00100000 -#define SKF_LCTLLOCKED 0x00040000 -#define SKF_LSHIFTLOCKED 0x00010000 -#define SKF_RALTLOCKED 0x00200000 -#define SKF_RCTLLOCKED 0x00080000 -#define SKF_RSHIFTLOCKED 0x00020000 -#define SKF_LWINLOCKED 0x00400000 -#define SKF_RWINLOCKED 0x00800000 - - typedef struct tagMOUSEKEYS { - UINT cbSize; - DWORD dwFlags; - DWORD iMaxSpeed; - DWORD iTimeToMaxSpeed; - DWORD iCtrlSpeed; - DWORD dwReserved1; - DWORD dwReserved2; - } MOUSEKEYS,*LPMOUSEKEYS; - -#define MKF_MOUSEKEYSON 0x00000001 -#define MKF_AVAILABLE 0x00000002 -#define MKF_HOTKEYACTIVE 0x00000004 -#define MKF_CONFIRMHOTKEY 0x00000008 -#define MKF_HOTKEYSOUND 0x00000010 -#define MKF_INDICATOR 0x00000020 -#define MKF_MODIFIERS 0x00000040 -#define MKF_REPLACENUMBERS 0x00000080 -#define MKF_LEFTBUTTONSEL 0x10000000 -#define MKF_RIGHTBUTTONSEL 0x20000000 -#define MKF_LEFTBUTTONDOWN 0x01000000 -#define MKF_RIGHTBUTTONDOWN 0x02000000 -#define MKF_MOUSEMODE 0x80000000 - - typedef struct tagACCESSTIMEOUT { - UINT cbSize; - DWORD dwFlags; - DWORD iTimeOutMSec; - } ACCESSTIMEOUT,*LPACCESSTIMEOUT; - -#define ATF_TIMEOUTON 0x00000001 -#define ATF_ONOFFFEEDBACK 0x00000002 - -#define SSGF_NONE 0 -#define SSGF_DISPLAY 3 - -#define SSTF_NONE 0 -#define SSTF_CHARS 1 -#define SSTF_BORDER 2 -#define SSTF_DISPLAY 3 - -#define SSWF_NONE 0 -#define SSWF_TITLE 1 -#define SSWF_WINDOW 2 -#define SSWF_DISPLAY 3 -#define SSWF_CUSTOM 4 - - typedef struct tagSOUNDSENTRYA { - UINT cbSize; - DWORD dwFlags; - DWORD iFSTextEffect; - DWORD iFSTextEffectMSec; - DWORD iFSTextEffectColorBits; - DWORD iFSGrafEffect; - DWORD iFSGrafEffectMSec; - DWORD iFSGrafEffectColor; - DWORD iWindowsEffect; - DWORD iWindowsEffectMSec; - LPSTR lpszWindowsEffectDLL; - DWORD iWindowsEffectOrdinal; - } SOUNDSENTRYA,*LPSOUNDSENTRYA; - - typedef struct tagSOUNDSENTRYW { - UINT cbSize; - DWORD dwFlags; - DWORD iFSTextEffect; - DWORD iFSTextEffectMSec; - DWORD iFSTextEffectColorBits; - DWORD iFSGrafEffect; - DWORD iFSGrafEffectMSec; - DWORD iFSGrafEffectColor; - DWORD iWindowsEffect; - DWORD iWindowsEffectMSec; - LPWSTR lpszWindowsEffectDLL; - DWORD iWindowsEffectOrdinal; - } SOUNDSENTRYW,*LPSOUNDSENTRYW; - -#ifdef UNICODE - typedef SOUNDSENTRYW SOUNDSENTRY; - typedef LPSOUNDSENTRYW LPSOUNDSENTRY; -#else - typedef SOUNDSENTRYA SOUNDSENTRY; - typedef LPSOUNDSENTRYA LPSOUNDSENTRY; -#endif - -#define SSF_SOUNDSENTRYON 0x00000001 -#define SSF_AVAILABLE 0x00000002 -#define SSF_INDICATOR 0x00000004 - - typedef struct tagTOGGLEKEYS { - UINT cbSize; - DWORD dwFlags; - } TOGGLEKEYS,*LPTOGGLEKEYS; - -#define TKF_TOGGLEKEYSON 0x00000001 -#define TKF_AVAILABLE 0x00000002 -#define TKF_HOTKEYACTIVE 0x00000004 -#define TKF_CONFIRMHOTKEY 0x00000008 -#define TKF_HOTKEYSOUND 0x00000010 -#define TKF_INDICATOR 0x00000020 - - WINUSERAPI VOID WINAPI SetDebugErrorLevel(DWORD dwLevel); - -#define SLE_ERROR 0x00000001 -#define SLE_MINORERROR 0x00000002 -#define SLE_WARNING 0x00000003 - - WINUSERAPI VOID WINAPI SetLastErrorEx(DWORD dwErrCode,DWORD dwType); - WINUSERAPI int WINAPI InternalGetWindowText(HWND hWnd,LPWSTR pString,int cchMaxCount); - -#ifdef WINNT - WINUSERAPI WINBOOL WINAPI EndTask(HWND hWnd,WINBOOL fShutDown,WINBOOL fForce); -#endif - -#define MONITOR_DEFAULTTONULL 0x00000000 -#define MONITOR_DEFAULTTOPRIMARY 0x00000001 -#define MONITOR_DEFAULTTONEAREST 0x00000002 - - WINUSERAPI HMONITOR WINAPI MonitorFromPoint(POINT pt,DWORD dwFlags); - WINUSERAPI HMONITOR WINAPI MonitorFromRect(LPCRECT lprc,DWORD dwFlags); - WINUSERAPI HMONITOR WINAPI MonitorFromWindow(HWND hwnd,DWORD dwFlags); - -#define MONITORINFOF_PRIMARY 0x00000001 - -#ifndef CCHDEVICENAME -#define CCHDEVICENAME 32 -#endif - - typedef struct tagMONITORINFO { - DWORD cbSize; - RECT rcMonitor; - RECT rcWork; - DWORD dwFlags; - } MONITORINFO,*LPMONITORINFO; - -#ifdef __cplusplus - typedef struct tagMONITORINFOEXA : public tagMONITORINFO { - CHAR szDevice[CCHDEVICENAME]; - } MONITORINFOEXA,*LPMONITORINFOEXA; - - typedef struct tagMONITORINFOEXW : public tagMONITORINFO { - WCHAR szDevice[CCHDEVICENAME]; - } MONITORINFOEXW,*LPMONITORINFOEXW; - -#ifdef UNICODE - typedef MONITORINFOEXW MONITORINFOEX; - typedef LPMONITORINFOEXW LPMONITORINFOEX; -#else - typedef MONITORINFOEXA MONITORINFOEX; - typedef LPMONITORINFOEXA LPMONITORINFOEX; -#endif -#else - typedef struct tagMONITORINFOEXA { - MONITORINFO mi; - CHAR szDevice[CCHDEVICENAME]; - } MONITORINFOEXA,*LPMONITORINFOEXA; - - typedef struct tagMONITORINFOEXW { - MONITORINFO mi; - WCHAR szDevice[CCHDEVICENAME]; - } MONITORINFOEXW,*LPMONITORINFOEXW; -#ifdef UNICODE - typedef MONITORINFOEXW MONITORINFOEX; - typedef LPMONITORINFOEXW LPMONITORINFOEX; -#else - typedef MONITORINFOEXA MONITORINFOEX; - typedef LPMONITORINFOEXA LPMONITORINFOEX; -#endif -#endif - -#ifdef UNICODE -#define GetMonitorInfo GetMonitorInfoW -#else -#define GetMonitorInfo GetMonitorInfoA -#endif - - WINUSERAPI WINBOOL WINAPI GetMonitorInfoA(HMONITOR hMonitor,LPMONITORINFO lpmi); - WINUSERAPI WINBOOL WINAPI GetMonitorInfoW(HMONITOR hMonitor,LPMONITORINFO lpmi); - - typedef WINBOOL (CALLBACK *MONITORENUMPROC)(HMONITOR,HDC,LPRECT,LPARAM); - - WINUSERAPI WINBOOL WINAPI EnumDisplayMonitors(HDC hdc,LPCRECT lprcClip,MONITORENUMPROC lpfnEnum,LPARAM dwData); - -#ifndef NOWINABLE - WINUSERAPI VOID WINAPI NotifyWinEvent(DWORD event,HWND hwnd,LONG idObject,LONG idChild); - - typedef VOID (CALLBACK *WINEVENTPROC)(HWINEVENTHOOK hWinEventHook,DWORD event,HWND hwnd,LONG idObject,LONG idChild,DWORD idEventThread,DWORD dwmsEventTime); - - WINUSERAPI HWINEVENTHOOK WINAPI SetWinEventHook(DWORD eventMin,DWORD eventMax,HMODULE hmodWinEventProc,WINEVENTPROC pfnWinEventProc,DWORD idProcess,DWORD idThread,DWORD dwFlags); - WINUSERAPI WINBOOL WINAPI IsWinEventHookInstalled(DWORD event); - -#define WINEVENT_OUTOFCONTEXT 0x0000 -#define WINEVENT_SKIPOWNTHREAD 0x0001 -#define WINEVENT_SKIPOWNPROCESS 0x0002 -#define WINEVENT_INCONTEXT 0x0004 - - WINUSERAPI WINBOOL WINAPI UnhookWinEvent(HWINEVENTHOOK hWinEventHook); - -#define CHILDID_SELF 0 -#define INDEXID_OBJECT 0 -#define INDEXID_CONTAINER 0 - -#define OBJID_WINDOW ((LONG)0x00000000) -#define OBJID_SYSMENU ((LONG)0xFFFFFFFF) -#define OBJID_TITLEBAR ((LONG)0xFFFFFFFE) -#define OBJID_MENU ((LONG)0xFFFFFFFD) -#define OBJID_CLIENT ((LONG)0xFFFFFFFC) -#define OBJID_VSCROLL ((LONG)0xFFFFFFFB) -#define OBJID_HSCROLL ((LONG)0xFFFFFFFA) -#define OBJID_SIZEGRIP ((LONG)0xFFFFFFF9) -#define OBJID_CARET ((LONG)0xFFFFFFF8) -#define OBJID_CURSOR ((LONG)0xFFFFFFF7) -#define OBJID_ALERT ((LONG)0xFFFFFFF6) -#define OBJID_SOUND ((LONG)0xFFFFFFF5) -#define OBJID_QUERYCLASSNAMEIDX ((LONG)0xFFFFFFF4) -#define OBJID_NATIVEOM ((LONG)0xFFFFFFF0) - -#define EVENT_MIN 0x00000001 -#define EVENT_MAX 0x7FFFFFFF - -#define EVENT_SYSTEM_SOUND 0x0001 -#define EVENT_SYSTEM_ALERT 0x0002 -#define EVENT_SYSTEM_FOREGROUND 0x0003 -#define EVENT_SYSTEM_MENUSTART 0x0004 -#define EVENT_SYSTEM_MENUEND 0x0005 -#define EVENT_SYSTEM_MENUPOPUPSTART 0x0006 -#define EVENT_SYSTEM_MENUPOPUPEND 0x0007 -#define EVENT_SYSTEM_CAPTURESTART 0x0008 -#define EVENT_SYSTEM_CAPTUREEND 0x0009 -#define EVENT_SYSTEM_MOVESIZESTART 0x000A -#define EVENT_SYSTEM_MOVESIZEEND 0x000B -#define EVENT_SYSTEM_CONTEXTHELPSTART 0x000C -#define EVENT_SYSTEM_CONTEXTHELPEND 0x000D -#define EVENT_SYSTEM_DRAGDROPSTART 0x000E -#define EVENT_SYSTEM_DRAGDROPEND 0x000F -#define EVENT_SYSTEM_DIALOGSTART 0x0010 -#define EVENT_SYSTEM_DIALOGEND 0x0011 -#define EVENT_SYSTEM_SCROLLINGSTART 0x0012 -#define EVENT_SYSTEM_SCROLLINGEND 0x0013 -#define EVENT_SYSTEM_SWITCHSTART 0x0014 -#define EVENT_SYSTEM_SWITCHEND 0x0015 -#define EVENT_SYSTEM_MINIMIZESTART 0x0016 -#define EVENT_SYSTEM_MINIMIZEEND 0x0017 - -#define EVENT_CONSOLE_CARET 0x4001 -#define EVENT_CONSOLE_UPDATE_REGION 0x4002 -#define EVENT_CONSOLE_UPDATE_SIMPLE 0x4003 -#define EVENT_CONSOLE_UPDATE_SCROLL 0x4004 -#define EVENT_CONSOLE_LAYOUT 0x4005 -#define EVENT_CONSOLE_START_APPLICATION 0x4006 -#define EVENT_CONSOLE_END_APPLICATION 0x4007 - -#define CONSOLE_APPLICATION_16BIT 0x0001 - -#define CONSOLE_CARET_SELECTION 0x0001 -#define CONSOLE_CARET_VISIBLE 0x0002 - -#define EVENT_OBJECT_CREATE 0x8000 -#define EVENT_OBJECT_DESTROY 0x8001 -#define EVENT_OBJECT_SHOW 0x8002 -#define EVENT_OBJECT_HIDE 0x8003 -#define EVENT_OBJECT_REORDER 0x8004 - -#define EVENT_OBJECT_FOCUS 0x8005 -#define EVENT_OBJECT_SELECTION 0x8006 -#define EVENT_OBJECT_SELECTIONADD 0x8007 -#define EVENT_OBJECT_SELECTIONREMOVE 0x8008 -#define EVENT_OBJECT_SELECTIONWITHIN 0x8009 - -#define EVENT_OBJECT_STATECHANGE 0x800A - -#define EVENT_OBJECT_LOCATIONCHANGE 0x800B - -#define EVENT_OBJECT_NAMECHANGE 0x800C -#define EVENT_OBJECT_DESCRIPTIONCHANGE 0x800D -#define EVENT_OBJECT_VALUECHANGE 0x800E -#define EVENT_OBJECT_PARENTCHANGE 0x800F -#define EVENT_OBJECT_HELPCHANGE 0x8010 -#define EVENT_OBJECT_DEFACTIONCHANGE 0x8011 -#define EVENT_OBJECT_ACCELERATORCHANGE 0x8012 - -#define SOUND_SYSTEM_STARTUP 1 -#define SOUND_SYSTEM_SHUTDOWN 2 -#define SOUND_SYSTEM_BEEP 3 -#define SOUND_SYSTEM_ERROR 4 -#define SOUND_SYSTEM_QUESTION 5 -#define SOUND_SYSTEM_WARNING 6 -#define SOUND_SYSTEM_INFORMATION 7 -#define SOUND_SYSTEM_MAXIMIZE 8 -#define SOUND_SYSTEM_MINIMIZE 9 -#define SOUND_SYSTEM_RESTOREUP 10 -#define SOUND_SYSTEM_RESTOREDOWN 11 -#define SOUND_SYSTEM_APPSTART 12 -#define SOUND_SYSTEM_FAULT 13 -#define SOUND_SYSTEM_APPEND 14 -#define SOUND_SYSTEM_MENUCOMMAND 15 -#define SOUND_SYSTEM_MENUPOPUP 16 -#define CSOUND_SYSTEM 16 - -#define ALERT_SYSTEM_INFORMATIONAL 1 -#define ALERT_SYSTEM_WARNING 2 -#define ALERT_SYSTEM_ERROR 3 -#define ALERT_SYSTEM_QUERY 4 -#define ALERT_SYSTEM_CRITICAL 5 -#define CALERT_SYSTEM 6 - - typedef struct tagGUITHREADINFO { - DWORD cbSize; - DWORD flags; - HWND hwndActive; - HWND hwndFocus; - HWND hwndCapture; - HWND hwndMenuOwner; - HWND hwndMoveSize; - HWND hwndCaret; - RECT rcCaret; - } GUITHREADINFO,*PGUITHREADINFO,*LPGUITHREADINFO; - -#define GUI_CARETBLINKING 0x00000001 -#define GUI_INMOVESIZE 0x00000002 -#define GUI_INMENUMODE 0x00000004 -#define GUI_SYSTEMMENUMODE 0x00000008 -#define GUI_POPUPMENUMODE 0x00000010 -#define GUI_16BITTASK 0x00000020 - -#ifdef UNICODE -#define GetWindowModuleFileName GetWindowModuleFileNameW -#else -#define GetWindowModuleFileName GetWindowModuleFileNameA -#endif - - WINUSERAPI WINBOOL WINAPI GetGUIThreadInfo(DWORD idThread,PGUITHREADINFO pgui); - WINUSERAPI UINT WINAPI GetWindowModuleFileNameA(HWND hwnd,LPSTR pszFileName,UINT cchFileNameMax); - WINUSERAPI UINT WINAPI GetWindowModuleFileNameW(HWND hwnd,LPWSTR pszFileName,UINT cchFileNameMax); - -#ifndef NO_STATE_FLAGS -#define STATE_SYSTEM_UNAVAILABLE 0x00000001 -#define STATE_SYSTEM_SELECTED 0x00000002 -#define STATE_SYSTEM_FOCUSED 0x00000004 -#define STATE_SYSTEM_PRESSED 0x00000008 -#define STATE_SYSTEM_CHECKED 0x00000010 -#define STATE_SYSTEM_MIXED 0x00000020 -#define STATE_SYSTEM_INDETERMINATE STATE_SYSTEM_MIXED -#define STATE_SYSTEM_READONLY 0x00000040 -#define STATE_SYSTEM_HOTTRACKED 0x00000080 -#define STATE_SYSTEM_DEFAULT 0x00000100 -#define STATE_SYSTEM_EXPANDED 0x00000200 -#define STATE_SYSTEM_COLLAPSED 0x00000400 -#define STATE_SYSTEM_BUSY 0x00000800 -#define STATE_SYSTEM_FLOATING 0x00001000 -#define STATE_SYSTEM_MARQUEED 0x00002000 -#define STATE_SYSTEM_ANIMATED 0x00004000 -#define STATE_SYSTEM_INVISIBLE 0x00008000 -#define STATE_SYSTEM_OFFSCREEN 0x00010000 -#define STATE_SYSTEM_SIZEABLE 0x00020000 -#define STATE_SYSTEM_MOVEABLE 0x00040000 -#define STATE_SYSTEM_SELFVOICING 0x00080000 -#define STATE_SYSTEM_FOCUSABLE 0x00100000 -#define STATE_SYSTEM_SELECTABLE 0x00200000 -#define STATE_SYSTEM_LINKED 0x00400000 -#define STATE_SYSTEM_TRAVERSED 0x00800000 -#define STATE_SYSTEM_MULTISELECTABLE 0x01000000 -#define STATE_SYSTEM_EXTSELECTABLE 0x02000000 -#define STATE_SYSTEM_ALERT_LOW 0x04000000 -#define STATE_SYSTEM_ALERT_MEDIUM 0x08000000 -#define STATE_SYSTEM_ALERT_HIGH 0x10000000 -#define STATE_SYSTEM_PROTECTED 0x20000000 -#define STATE_SYSTEM_VALID 0x3FFFFFFF -#endif - -#define CCHILDREN_TITLEBAR 5 -#define CCHILDREN_SCROLLBAR 5 - - typedef struct tagCURSORINFO { - DWORD cbSize; - DWORD flags; - HCURSOR hCursor; - POINT ptScreenPos; - } CURSORINFO,*PCURSORINFO,*LPCURSORINFO; - -#define CURSOR_SHOWING 0x00000001 - - WINUSERAPI WINBOOL WINAPI GetCursorInfo(PCURSORINFO pci); - - typedef struct tagWINDOWINFO { - DWORD cbSize; - RECT rcWindow; - RECT rcClient; - DWORD dwStyle; - DWORD dwExStyle; - DWORD dwWindowStatus; - UINT cxWindowBorders; - UINT cyWindowBorders; - ATOM atomWindowType; - WORD wCreatorVersion; - } WINDOWINFO,*PWINDOWINFO,*LPWINDOWINFO; - -#define WS_ACTIVECAPTION 0x0001 - - WINUSERAPI WINBOOL WINAPI GetWindowInfo(HWND hwnd,PWINDOWINFO pwi); - - typedef struct tagTITLEBARINFO { - DWORD cbSize; - RECT rcTitleBar; - DWORD rgstate[CCHILDREN_TITLEBAR + 1]; - } TITLEBARINFO,*PTITLEBARINFO,*LPTITLEBARINFO; - - WINUSERAPI WINBOOL WINAPI GetTitleBarInfo(HWND hwnd,PTITLEBARINFO pti); - - typedef struct tagMENUBARINFO { - DWORD cbSize; - RECT rcBar; - HMENU hMenu; - HWND hwndMenu; - WINBOOL fBarFocused:1; - WINBOOL fFocused:1; - } MENUBARINFO,*PMENUBARINFO,*LPMENUBARINFO; - - WINUSERAPI WINBOOL WINAPI GetMenuBarInfo(HWND hwnd,LONG idObject,LONG idItem,PMENUBARINFO pmbi); - - typedef struct tagSCROLLBARINFO { - DWORD cbSize; - RECT rcScrollBar; - int dxyLineButton; - int xyThumbTop; - int xyThumbBottom; - int reserved; - DWORD rgstate[CCHILDREN_SCROLLBAR + 1]; - } SCROLLBARINFO,*PSCROLLBARINFO,*LPSCROLLBARINFO; - - WINUSERAPI WINBOOL WINAPI GetScrollBarInfo(HWND hwnd,LONG idObject,PSCROLLBARINFO psbi); - - typedef struct tagCOMBOBOXINFO { - DWORD cbSize; - RECT rcItem; - RECT rcButton; - DWORD stateButton; - HWND hwndCombo; - HWND hwndItem; - HWND hwndList; - } COMBOBOXINFO,*PCOMBOBOXINFO,*LPCOMBOBOXINFO; - - WINUSERAPI WINBOOL WINAPI GetComboBoxInfo(HWND hwndCombo,PCOMBOBOXINFO pcbi); - -#define GA_PARENT 1 -#define GA_ROOT 2 -#define GA_ROOTOWNER 3 - - WINUSERAPI HWND WINAPI GetAncestor(HWND hwnd,UINT gaFlags); - WINUSERAPI HWND WINAPI RealChildWindowFromPoint(HWND hwndParent,POINT ptParentClientCoords); - WINUSERAPI UINT WINAPI RealGetWindowClassA(HWND hwnd,LPSTR ptszClassName,UINT cchClassNameMax); - WINUSERAPI UINT WINAPI RealGetWindowClassW(HWND hwnd,LPWSTR ptszClassName,UINT cchClassNameMax); -#ifdef UNICODE -#define RealGetWindowClass RealGetWindowClassW -#else -#define RealGetWindowClass RealGetWindowClassA -#endif - - typedef struct tagALTTABINFO { - DWORD cbSize; - int cItems; - int cColumns; - int cRows; - int iColFocus; - int iRowFocus; - int cxItem; - int cyItem; - POINT ptStart; - } ALTTABINFO,*PALTTABINFO,*LPALTTABINFO; - -#ifdef UNICODE -#define GetAltTabInfo GetAltTabInfoW -#else -#define GetAltTabInfo GetAltTabInfoA -#endif - - WINUSERAPI WINBOOL WINAPI GetAltTabInfoA(HWND hwnd,int iItem,PALTTABINFO pati,LPSTR pszItemText,UINT cchItemText); - WINUSERAPI WINBOOL WINAPI GetAltTabInfoW(HWND hwnd,int iItem,PALTTABINFO pati,LPWSTR pszItemText,UINT cchItemText); - WINUSERAPI DWORD WINAPI GetListBoxInfo(HWND hwnd); -#endif - - WINUSERAPI WINBOOL WINAPI LockWorkStation(VOID); - WINUSERAPI WINBOOL WINAPI UserHandleGrantAccess(HANDLE hUserHandle,HANDLE hJob,WINBOOL bGrant); - - DECLARE_HANDLE(HRAWINPUT); - -#define GET_RAWINPUT_CODE_WPARAM(wParam) ((wParam) & 0xff) - -#define RIM_INPUT 0 -#define RIM_INPUTSINK 1 - - typedef struct tagRAWINPUTHEADER { - DWORD dwType; - DWORD dwSize; - HANDLE hDevice; - WPARAM wParam; - } RAWINPUTHEADER,*PRAWINPUTHEADER,*LPRAWINPUTHEADER; - -#define RIM_TYPEMOUSE 0 -#define RIM_TYPEKEYBOARD 1 -#define RIM_TYPEHID 2 - - typedef struct tagRAWMOUSE { - USHORT usFlags; - union { - ULONG ulButtons; - struct { - USHORT usButtonFlags; - USHORT usButtonData; - }; - }; - ULONG ulRawButtons; - LONG lLastX; - LONG lLastY; - ULONG ulExtraInformation; - } RAWMOUSE,*PRAWMOUSE,*LPRAWMOUSE; - -#define RI_MOUSE_LEFT_BUTTON_DOWN 0x0001 -#define RI_MOUSE_LEFT_BUTTON_UP 0x0002 -#define RI_MOUSE_RIGHT_BUTTON_DOWN 0x0004 -#define RI_MOUSE_RIGHT_BUTTON_UP 0x0008 -#define RI_MOUSE_MIDDLE_BUTTON_DOWN 0x0010 -#define RI_MOUSE_MIDDLE_BUTTON_UP 0x0020 - -#define RI_MOUSE_BUTTON_1_DOWN RI_MOUSE_LEFT_BUTTON_DOWN -#define RI_MOUSE_BUTTON_1_UP RI_MOUSE_LEFT_BUTTON_UP -#define RI_MOUSE_BUTTON_2_DOWN RI_MOUSE_RIGHT_BUTTON_DOWN -#define RI_MOUSE_BUTTON_2_UP RI_MOUSE_RIGHT_BUTTON_UP -#define RI_MOUSE_BUTTON_3_DOWN RI_MOUSE_MIDDLE_BUTTON_DOWN -#define RI_MOUSE_BUTTON_3_UP RI_MOUSE_MIDDLE_BUTTON_UP - -#define RI_MOUSE_BUTTON_4_DOWN 0x0040 -#define RI_MOUSE_BUTTON_4_UP 0x0080 -#define RI_MOUSE_BUTTON_5_DOWN 0x0100 -#define RI_MOUSE_BUTTON_5_UP 0x0200 - -#define RI_MOUSE_WHEEL 0x0400 - -#define MOUSE_MOVE_RELATIVE 0 -#define MOUSE_MOVE_ABSOLUTE 1 -#define MOUSE_VIRTUAL_DESKTOP 0x02 -#define MOUSE_ATTRIBUTES_CHANGED 0x04 - - typedef struct tagRAWKEYBOARD { - USHORT MakeCode; - USHORT Flags; - USHORT Reserved; - USHORT VKey; - UINT Message; - ULONG ExtraInformation; - } RAWKEYBOARD,*PRAWKEYBOARD,*LPRAWKEYBOARD; - -#define KEYBOARD_OVERRUN_MAKE_CODE 0xFF - -#define RI_KEY_MAKE 0 -#define RI_KEY_BREAK 1 -#define RI_KEY_E0 2 -#define RI_KEY_E1 4 -#define RI_KEY_TERMSRV_SET_LED 8 -#define RI_KEY_TERMSRV_SHADOW 0x10 - - typedef struct tagRAWHID { - DWORD dwSizeHid; - DWORD dwCount; - BYTE bRawData[1]; - } RAWHID,*PRAWHID,*LPRAWHID; - - typedef struct tagRAWINPUT { - RAWINPUTHEADER header; - union { - RAWMOUSE mouse; - RAWKEYBOARD keyboard; - RAWHID hid; - } data; - } RAWINPUT,*PRAWINPUT,*LPRAWINPUT; - -#ifdef _WIN64 -#define RAWINPUT_ALIGN(x) (((x) + sizeof(QWORD) - 1) & ~(sizeof(QWORD) - 1)) -#else -#define RAWINPUT_ALIGN(x) (((x) + sizeof(DWORD) - 1) & ~(sizeof(DWORD) - 1)) -#endif - -#define NEXTRAWINPUTBLOCK(ptr) ((PRAWINPUT)RAWINPUT_ALIGN((ULONG_PTR)((PBYTE)(ptr) + (ptr)->header.dwSize))) - -#define RID_INPUT 0x10000003 -#define RID_HEADER 0x10000005 - - WINUSERAPI UINT WINAPI GetRawInputData(HRAWINPUT hRawInput,UINT uiCommand,LPVOID pData,PUINT pcbSize,UINT cbSizeHeader); - -#define RIDI_PREPARSEDDATA 0x20000005 -#define RIDI_DEVICENAME 0x20000007 -#define RIDI_DEVICEINFO 0x2000000b - - typedef struct tagRID_DEVICE_INFO_MOUSE { - DWORD dwId; - DWORD dwNumberOfButtons; - DWORD dwSampleRate; - } RID_DEVICE_INFO_MOUSE,*PRID_DEVICE_INFO_MOUSE; - - typedef struct tagRID_DEVICE_INFO_KEYBOARD { - DWORD dwType; - DWORD dwSubType; - DWORD dwKeyboardMode; - DWORD dwNumberOfFunctionKeys; - DWORD dwNumberOfIndicators; - DWORD dwNumberOfKeysTotal; - } RID_DEVICE_INFO_KEYBOARD,*PRID_DEVICE_INFO_KEYBOARD; - - typedef struct tagRID_DEVICE_INFO_HID { - DWORD dwVendorId; - DWORD dwProductId; - DWORD dwVersionNumber; - USHORT usUsagePage; - USHORT usUsage; - } RID_DEVICE_INFO_HID,*PRID_DEVICE_INFO_HID; - - typedef struct tagRID_DEVICE_INFO { - DWORD cbSize; - DWORD dwType; - union { - RID_DEVICE_INFO_MOUSE mouse; - RID_DEVICE_INFO_KEYBOARD keyboard; - RID_DEVICE_INFO_HID hid; - }; - } RID_DEVICE_INFO,*PRID_DEVICE_INFO,*LPRID_DEVICE_INFO; - -#ifdef UNICODE -#define GetRawInputDeviceInfo GetRawInputDeviceInfoW -#else -#define GetRawInputDeviceInfo GetRawInputDeviceInfoA -#endif - - WINUSERAPI UINT WINAPI GetRawInputDeviceInfoA(HANDLE hDevice,UINT uiCommand,LPVOID pData,PUINT pcbSize); - WINUSERAPI UINT WINAPI GetRawInputDeviceInfoW(HANDLE hDevice,UINT uiCommand,LPVOID pData,PUINT pcbSize); - WINUSERAPI UINT WINAPI GetRawInputBuffer(PRAWINPUT pData,PUINT pcbSize,UINT cbSizeHeader); - - typedef struct tagRAWINPUTDEVICE { - USHORT usUsagePage; - USHORT usUsage; - DWORD dwFlags; - HWND hwndTarget; - } RAWINPUTDEVICE,*PRAWINPUTDEVICE,*LPRAWINPUTDEVICE; - - typedef CONST RAWINPUTDEVICE *PCRAWINPUTDEVICE; - -#define RIDEV_REMOVE 0x00000001 -#define RIDEV_EXCLUDE 0x00000010 -#define RIDEV_PAGEONLY 0x00000020 -#define RIDEV_NOLEGACY 0x00000030 -#define RIDEV_INPUTSINK 0x00000100 -#define RIDEV_CAPTUREMOUSE 0x00000200 -#define RIDEV_NOHOTKEYS 0x00000200 -#define RIDEV_APPKEYS 0x00000400 -#define RIDEV_EXMODEMASK 0x000000F0 -#define RIDEV_EXMODE(mode) ((mode) & RIDEV_EXMODEMASK) - - WINUSERAPI WINBOOL WINAPI RegisterRawInputDevices(PCRAWINPUTDEVICE pRawInputDevices,UINT uiNumDevices,UINT cbSize); - WINUSERAPI UINT WINAPI GetRegisteredRawInputDevices(PRAWINPUTDEVICE pRawInputDevices,PUINT puiNumDevices,UINT cbSize); - - typedef struct tagRAWINPUTDEVICELIST { - HANDLE hDevice; - DWORD dwType; - } RAWINPUTDEVICELIST,*PRAWINPUTDEVICELIST; - - WINUSERAPI UINT WINAPI GetRawInputDeviceList(PRAWINPUTDEVICELIST pRawInputDeviceList,PUINT puiNumDevices,UINT cbSize); - WINUSERAPI LRESULT WINAPI DefRawInputProc(PRAWINPUT *paRawInput,INT nInput,UINT cbSizeHeader); - -#endif /* NOUSER */ - -#ifdef __cplusplus -} -#endif -#endif diff --git a/05/tcc-final-old/win32/include/winapi/winver.h b/05/tcc-final-old/win32/include/winapi/winver.h deleted file mode 100644 index 5c0f036..0000000 --- a/05/tcc-final-old/win32/include/winapi/winver.h +++ /dev/null @@ -1,160 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef VER_H -#define VER_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define VS_FILE_INFO RT_VERSION -#define VS_VERSION_INFO 1 -#define VS_USER_DEFINED 100 - -#define VS_FFI_SIGNATURE 0xFEEF04BDL -#define VS_FFI_STRUCVERSION 0x00010000L -#define VS_FFI_FILEFLAGSMASK 0x0000003FL - -#define VS_FF_DEBUG 0x00000001L -#define VS_FF_PRERELEASE 0x00000002L -#define VS_FF_PATCHED 0x00000004L -#define VS_FF_PRIVATEBUILD 0x00000008L -#define VS_FF_INFOINFERRED 0x00000010L -#define VS_FF_SPECIALBUILD 0x00000020L - -#define VOS_UNKNOWN 0x00000000L -#define VOS_DOS 0x00010000L -#define VOS_OS216 0x00020000L -#define VOS_OS232 0x00030000L -#define VOS_NT 0x00040000L -#define VOS_WINCE 0x00050000L - -#define VOS__BASE 0x00000000L -#define VOS__WINDOWS16 0x00000001L -#define VOS__PM16 0x00000002L -#define VOS__PM32 0x00000003L -#define VOS__WINDOWS32 0x00000004L - -#define VOS_DOS_WINDOWS16 0x00010001L -#define VOS_DOS_WINDOWS32 0x00010004L -#define VOS_OS216_PM16 0x00020002L -#define VOS_OS232_PM32 0x00030003L -#define VOS_NT_WINDOWS32 0x00040004L - -#define VFT_UNKNOWN 0x00000000L -#define VFT_APP 0x00000001L -#define VFT_DLL 0x00000002L -#define VFT_DRV 0x00000003L -#define VFT_FONT 0x00000004L -#define VFT_VXD 0x00000005L -#define VFT_STATIC_LIB 0x00000007L - -#define VFT2_UNKNOWN 0x00000000L -#define VFT2_DRV_PRINTER 0x00000001L -#define VFT2_DRV_KEYBOARD 0x00000002L -#define VFT2_DRV_LANGUAGE 0x00000003L -#define VFT2_DRV_DISPLAY 0x00000004L -#define VFT2_DRV_MOUSE 0x00000005L -#define VFT2_DRV_NETWORK 0x00000006L -#define VFT2_DRV_SYSTEM 0x00000007L -#define VFT2_DRV_INSTALLABLE 0x00000008L -#define VFT2_DRV_SOUND 0x00000009L -#define VFT2_DRV_COMM 0x0000000AL -#define VFT2_DRV_INPUTMETHOD 0x0000000BL -#define VFT2_DRV_VERSIONED_PRINTER 0x0000000CL - -#define VFT2_FONT_RASTER 0x00000001L -#define VFT2_FONT_VECTOR 0x00000002L -#define VFT2_FONT_TRUETYPE 0x00000003L - -#define VFFF_ISSHAREDFILE 0x0001 - -#define VFF_CURNEDEST 0x0001 -#define VFF_FILEINUSE 0x0002 -#define VFF_BUFFTOOSMALL 0x0004 - -#define VIFF_FORCEINSTALL 0x0001 -#define VIFF_DONTDELETEOLD 0x0002 - -#define VIF_TEMPFILE 0x00000001L -#define VIF_MISMATCH 0x00000002L -#define VIF_SRCOLD 0x00000004L - -#define VIF_DIFFLANG 0x00000008L -#define VIF_DIFFCODEPG 0x00000010L -#define VIF_DIFFTYPE 0x00000020L - -#define VIF_WRITEPROT 0x00000040L -#define VIF_FILEINUSE 0x00000080L -#define VIF_OUTOFSPACE 0x00000100L -#define VIF_ACCESSVIOLATION 0x00000200L -#define VIF_SHARINGVIOLATION 0x00000400L -#define VIF_CANNOTCREATE 0x00000800L -#define VIF_CANNOTDELETE 0x00001000L -#define VIF_CANNOTRENAME 0x00002000L -#define VIF_CANNOTDELETECUR 0x00004000L -#define VIF_OUTOFMEMORY 0x00008000L - -#define VIF_CANNOTREADSRC 0x00010000L -#define VIF_CANNOTREADDST 0x00020000L - -#define VIF_BUFFTOOSMALL 0x00040000L -#define VIF_CANNOTLOADLZ32 0x00080000L -#define VIF_CANNOTLOADCABINET 0x00100000L - -#ifndef RC_INVOKED - - typedef struct tagVS_FIXEDFILEINFO - { - DWORD dwSignature; - DWORD dwStrucVersion; - DWORD dwFileVersionMS; - DWORD dwFileVersionLS; - DWORD dwProductVersionMS; - DWORD dwProductVersionLS; - DWORD dwFileFlagsMask; - DWORD dwFileFlags; - DWORD dwFileOS; - DWORD dwFileType; - DWORD dwFileSubtype; - DWORD dwFileDateMS; - DWORD dwFileDateLS; - } VS_FIXEDFILEINFO; - -#ifdef UNICODE -#define VerFindFile VerFindFileW -#define VerInstallFile VerInstallFileW -#define GetFileVersionInfoSize GetFileVersionInfoSizeW -#define GetFileVersionInfo GetFileVersionInfoW -#define VerLanguageName VerLanguageNameW -#define VerQueryValue VerQueryValueW -#else -#define VerFindFile VerFindFileA -#define VerInstallFile VerInstallFileA -#define GetFileVersionInfoSize GetFileVersionInfoSizeA -#define GetFileVersionInfo GetFileVersionInfoA -#define VerLanguageName VerLanguageNameA -#define VerQueryValue VerQueryValueA -#endif - - DWORD WINAPI VerFindFileA(DWORD uFlags,LPSTR szFileName,LPSTR szWinDir,LPSTR szAppDir,LPSTR szCurDir,PUINT lpuCurDirLen,LPSTR szDestDir,PUINT lpuDestDirLen); - DWORD WINAPI VerFindFileW(DWORD uFlags,LPWSTR szFileName,LPWSTR szWinDir,LPWSTR szAppDir,LPWSTR szCurDir,PUINT lpuCurDirLen,LPWSTR szDestDir,PUINT lpuDestDirLen); - DWORD WINAPI VerInstallFileA(DWORD uFlags,LPSTR szSrcFileName,LPSTR szDestFileName,LPSTR szSrcDir,LPSTR szDestDir,LPSTR szCurDir,LPSTR szTmpFile,PUINT lpuTmpFileLen); - DWORD WINAPI VerInstallFileW(DWORD uFlags,LPWSTR szSrcFileName,LPWSTR szDestFileName,LPWSTR szSrcDir,LPWSTR szDestDir,LPWSTR szCurDir,LPWSTR szTmpFile,PUINT lpuTmpFileLen); - DWORD WINAPI GetFileVersionInfoSizeA(LPCSTR lptstrFilename,LPDWORD lpdwHandle); - DWORD WINAPI GetFileVersionInfoSizeW(LPCWSTR lptstrFilename,LPDWORD lpdwHandle); - WINBOOL WINAPI GetFileVersionInfoA(LPCSTR lptstrFilename,DWORD dwHandle,DWORD dwLen,LPVOID lpData); - WINBOOL WINAPI GetFileVersionInfoW(LPCWSTR lptstrFilename,DWORD dwHandle,DWORD dwLen,LPVOID lpData); - DWORD WINAPI VerLanguageNameA(DWORD wLang,LPSTR szLang,DWORD nSize); - DWORD WINAPI VerLanguageNameW(DWORD wLang,LPWSTR szLang,DWORD nSize); - WINBOOL WINAPI VerQueryValueA(const LPVOID pBlock,LPSTR lpSubBlock,LPVOID *lplpBuffer,PUINT puLen); - WINBOOL WINAPI VerQueryValueW(const LPVOID pBlock,LPWSTR lpSubBlock,LPVOID *lplpBuffer,PUINT puLen); -#endif - -#ifdef __cplusplus -} -#endif -#endif diff --git a/05/tcc-final-old/win32/lib/chkstk.S b/05/tcc-final-old/win32/lib/chkstk.S deleted file mode 100644 index ec5c07f..0000000 --- a/05/tcc-final-old/win32/lib/chkstk.S +++ /dev/null @@ -1,191 +0,0 @@ -/* ---------------------------------------------- */ -/* chkstk86.s */ - -/* ---------------------------------------------- */ -#ifndef __x86_64__ -/* ---------------------------------------------- */ - -.globl __chkstk - -__chkstk: - xchg (%esp),%ebp /* store ebp, get ret.addr */ - push %ebp /* push ret.addr */ - lea 4(%esp),%ebp /* setup frame ptr */ - push %ecx /* save ecx */ - mov %ebp,%ecx -P0: - sub $4096,%ecx - test %eax,(%ecx) - sub $4096,%eax - cmp $4096,%eax - jge P0 - sub %eax,%ecx - test %eax,(%ecx) - - mov %esp,%eax - mov %ecx,%esp - mov (%eax),%ecx /* restore ecx */ - jmp *4(%eax) - -/* ---------------------------------------------- */ -#else -/* ---------------------------------------------- */ - -.globl __chkstk - -__chkstk: - xchg (%rsp),%rbp /* store ebp, get ret.addr */ - push %rbp /* push ret.addr */ - lea 8(%rsp),%rbp /* setup frame ptr */ - push %rcx /* save ecx */ - mov %rbp,%rcx - movslq %eax,%rax -P0: - sub $4096,%rcx - test %rax,(%rcx) - sub $4096,%rax - cmp $4096,%rax - jge P0 - sub %rax,%rcx - test %rax,(%rcx) - - mov %rsp,%rax - mov %rcx,%rsp - mov (%rax),%rcx /* restore ecx */ - jmp *8(%rax) - -/* ---------------------------------------------- */ -/* setjmp/longjmp support */ - -.globl tinyc_getbp -tinyc_getbp: - mov %rbp,%rax - ret - -/* ---------------------------------------------- */ -#endif -/* ---------------------------------------------- */ - - -/* ---------------------------------------------- */ -#ifndef __x86_64__ -/* ---------------------------------------------- */ - -/* - int _except_handler3( - PEXCEPTION_RECORD exception_record, - PEXCEPTION_REGISTRATION registration, - PCONTEXT context, - PEXCEPTION_REGISTRATION dispatcher - ); - - int __cdecl _XcptFilter( - unsigned long xcptnum, - PEXCEPTION_POINTERS pxcptinfoptrs - ); - - struct _sehrec { - void *esp; // 0 - void *exception_pointers; // 1 - void *prev; // 2 - void *handler; // 3 - void *scopetable; // 4 - int trylevel; // 5 - void *ebp // 6 - }; - - // this is what the assembler code below means: - __try - { - // ... - } - __except (_XcptFilter(GetExceptionCode(), GetExceptionInformation())) - { - exit(GetExceptionCode()); - } -*/ - -.globl _exception_info -_exception_info: - mov 1*4-24(%ebp),%eax - ret - -.globl _exception_code -_exception_code: - call _exception_info - mov (%eax),%eax - mov (%eax),%eax - ret - -seh_filter: - call _exception_info - push %eax - call _exception_code - push %eax - call _XcptFilter - add $ 8,%esp - ret - -seh_except: - mov 0*4-24(%ebp),%esp - call _exception_code - push %eax - call _exit - -// msvcrt wants scopetables aligned and in read-only segment (using .text) -.align 4 -seh_scopetable: - .long -1 - .long seh_filter - .long seh_except - -seh_handler: - jmp _except_handler3 - -.globl ___try__ -___try__: -.globl __try__ -__try__: - push %ebp - mov 8(%esp),%ebp - -// void *esp; - lea 12(%esp),%eax - mov %eax,0*4(%ebp) - -// void *exception_pointers; - xor %eax,%eax - mov %eax,1*4(%ebp) - -// void *prev; - mov %fs:0,%eax - mov %eax,2*4(%ebp) - -// void *handler; - mov $ seh_handler,%eax - mov %eax,3*4(%ebp) - -// void *scopetable; - mov $ seh_scopetable,%eax - mov %eax,4*4(%ebp) - -// int trylevel; - xor %eax,%eax - mov %eax,5*4(%ebp) - -// register new SEH - lea 2*4(%ebp),%eax - mov %eax,%fs:0 - - pop %ebp - ret - -/* ---------------------------------------------- */ -#else -/* ---------------------------------------------- */ - -/* SEH on x86-64 not implemented */ - -/* ---------------------------------------------- */ -#endif -/* ---------------------------------------------- */ diff --git a/05/tcc-final-old/win32/lib/crt1.c b/05/tcc-final-old/win32/lib/crt1.c deleted file mode 100644 index 0e04fc0..0000000 --- a/05/tcc-final-old/win32/lib/crt1.c +++ /dev/null @@ -1,79 +0,0 @@ -// ============================================= -// crt1.c - -// _UNICODE for tchar.h, UNICODE for API -#include - -#include -#include - -#define _UNKNOWN_APP 0 -#define _CONSOLE_APP 1 -#define _GUI_APP 2 - -#define _MCW_PC 0x00030000 // Precision Control -#define _PC_24 0x00020000 // 24 bits -#define _PC_53 0x00010000 // 53 bits -#define _PC_64 0x00000000 // 64 bits - -#ifdef _UNICODE -#define __tgetmainargs __wgetmainargs -#define _tstart _wstart -#define _tmain wmain -#define _runtmain _runwmain -#else -#define __tgetmainargs __getmainargs -#define _tstart _start -#define _tmain main -#define _runtmain _runmain -#endif - -typedef struct { int newmode; } _startupinfo; -int __cdecl __tgetmainargs(int *pargc, _TCHAR ***pargv, _TCHAR ***penv, int globb, _startupinfo*); -void __cdecl __set_app_type(int apptype); -unsigned int __cdecl _controlfp(unsigned int new_value, unsigned int mask); -extern int _tmain(int argc, _TCHAR * argv[], _TCHAR * env[]); - -/* Allow command-line globbing with "int _dowildcard = 1;" in the user source */ -int _dowildcard; - -void _tstart(void) -{ - __TRY__ - _startupinfo start_info = {0}; - - // Sets the current application type - __set_app_type(_CONSOLE_APP); - - // Set default FP precision to 53 bits (8-byte double) - // _MCW_PC (Precision control) is not supported on ARM -#if defined __i386__ || defined __x86_64__ - _controlfp(_PC_53, _MCW_PC); -#endif - - __tgetmainargs( &__argc, &__targv, &_tenviron, _dowildcard, &start_info); - exit(_tmain(__argc, __targv, _tenviron)); -} - -int _runtmain(int argc, /* as tcc passed in */ char **argv) -{ -#ifdef UNICODE - _startupinfo start_info = {0}; - - __tgetmainargs(&__argc, &__targv, &_tenviron, _dowildcard, &start_info); - /* may be wrong when tcc has received wildcards (*.c) */ - if (argc < __argc) { - __targv += __argc - argc; - __argc = argc; - } -#else - __argc = argc; - __targv = argv; -#endif -#if defined __i386__ || defined __x86_64__ - _controlfp(_PC_53, _MCW_PC); -#endif - return _tmain(__argc, __targv, _tenviron); -} - -// ============================================= diff --git a/05/tcc-final-old/win32/lib/crt1w.c b/05/tcc-final-old/win32/lib/crt1w.c deleted file mode 100644 index 2b8bbc8..0000000 --- a/05/tcc-final-old/win32/lib/crt1w.c +++ /dev/null @@ -1,3 +0,0 @@ -#define _UNICODE 1 -#define UNICODE 1 -#include "crt1.c" diff --git a/05/tcc-final-old/win32/lib/dllcrt1.c b/05/tcc-final-old/win32/lib/dllcrt1.c deleted file mode 100644 index ba1dbd0..0000000 --- a/05/tcc-final-old/win32/lib/dllcrt1.c +++ /dev/null @@ -1,13 +0,0 @@ -//+--------------------------------------------------------------------------- - -#include - -BOOL WINAPI DllMain (HINSTANCE hDll, DWORD dwReason, LPVOID lpReserved); - -BOOL WINAPI _dllstart(HINSTANCE hDll, DWORD dwReason, LPVOID lpReserved) -{ - BOOL bRet; - bRet = DllMain (hDll, dwReason, lpReserved); - return bRet; -} - diff --git a/05/tcc-final-old/win32/lib/dllmain.c b/05/tcc-final-old/win32/lib/dllmain.c deleted file mode 100644 index 2c25b98..0000000 --- a/05/tcc-final-old/win32/lib/dllmain.c +++ /dev/null @@ -1,9 +0,0 @@ -//+--------------------------------------------------------------------------- - -#include - -BOOL WINAPI DllMain (HINSTANCE hDll, DWORD dwReason, LPVOID lpReserved) -{ - return TRUE; -} - diff --git a/05/tcc-final-old/win32/lib/gdi32.def b/05/tcc-final-old/win32/lib/gdi32.def deleted file mode 100644 index 02766da..0000000 --- a/05/tcc-final-old/win32/lib/gdi32.def +++ /dev/null @@ -1,337 +0,0 @@ -LIBRARY gdi32.dll - -EXPORTS -AbortDoc -AbortPath -AddFontResourceA -AddFontResourceW -AngleArc -AnimatePalette -Arc -ArcTo -BeginPath -BitBlt -ByeByeGDI -CancelDC -CheckColorsInGamut -ChoosePixelFormat -Chord -CloseEnhMetaFile -CloseFigure -CloseMetaFile -ColorCorrectPalette -ColorMatchToTarget -CombineRgn -CombineTransform -CopyEnhMetaFileA -CopyEnhMetaFileW -CopyMetaFileA -CopyMetaFileW -CreateBitmap -CreateBitmapIndirect -CreateBrushIndirect -CreateColorSpaceA -CreateColorSpaceW -CreateCompatibleBitmap -CreateCompatibleDC -CreateDCA -CreateDCW -CreateDIBPatternBrush -CreateDIBPatternBrushPt -CreateDIBSection -CreateDIBitmap -CreateDiscardableBitmap -CreateEllipticRgn -CreateEllipticRgnIndirect -CreateEnhMetaFileA -CreateEnhMetaFileW -CreateFontA -CreateFontIndirectA -CreateFontIndirectW -CreateFontW -CreateHalftonePalette -CreateHatchBrush -CreateICA -CreateICW -CreateMetaFileA -CreateMetaFileW -CreatePalette -CreatePatternBrush -CreatePen -CreatePenIndirect -CreatePolyPolygonRgn -CreatePolygonRgn -CreateRectRgn -CreateRectRgnIndirect -CreateRoundRectRgn -CreateScalableFontResourceA -CreateScalableFontResourceW -CreateSolidBrush -DPtoLP -DeleteColorSpace -DeleteDC -DeleteEnhMetaFile -DeleteMetaFile -DeleteObject -DescribePixelFormat -DeviceCapabilitiesEx -DeviceCapabilitiesExA -DeviceCapabilitiesExW -DrawEscape -Ellipse -EnableEUDC -EndDoc -EndPage -EndPath -EnumEnhMetaFile -EnumFontFamiliesA -EnumFontFamiliesExA -EnumFontFamiliesExW -EnumFontFamiliesW -EnumFontsA -EnumFontsW -EnumICMProfilesA -EnumICMProfilesW -EnumMetaFile -EnumObjects -EqualRgn -Escape -ExcludeClipRect -ExtCreatePen -ExtCreateRegion -ExtEscape -ExtFloodFill -ExtSelectClipRgn -ExtTextOutA -ExtTextOutW -FillPath -FillRgn -FixBrushOrgEx -FlattenPath -FloodFill -FrameRgn -GdiComment -GdiFlush -GdiGetBatchLimit -GdiPlayDCScript -GdiPlayJournal -GdiPlayScript -GdiSetBatchLimit -GetArcDirection -GetAspectRatioFilterEx -GetBitmapBits -GetBitmapDimensionEx -GetBkColor -GetBkMode -GetBoundsRect -GetBrushOrgEx -GetCharABCWidthsA -GetCharABCWidthsFloatA -GetCharABCWidthsFloatW -GetCharABCWidthsW -GetCharWidth32A -GetCharWidth32W -GetCharWidthA -GetCharWidthFloatA -GetCharWidthFloatW -GetCharWidthW -GetCharacterPlacementA -GetCharacterPlacementW -GetClipBox -GetClipRgn -GetColorAdjustment -GetColorSpace -GetCurrentObject -GetCurrentPositionEx -GetDCOrgEx -GetDIBColorTable -GetDIBits -GetDeviceCaps -GetDeviceGammaRamp -GetEnhMetaFileA -GetEnhMetaFileBits -GetEnhMetaFileDescriptionA -GetEnhMetaFileDescriptionW -GetEnhMetaFileHeader -GetEnhMetaFilePaletteEntries -GetEnhMetaFileW -GetFontData -GetFontLanguageInfo -GetFontResourceInfo -GetGlyphOutline -GetGlyphOutlineA -GetGlyphOutlineW -GetGraphicsMode -GetICMProfileA -GetICMProfileW -GetKerningPairs -GetKerningPairsA -GetKerningPairsW -GetLayout -GetLogColorSpaceA -GetLogColorSpaceW -GetMapMode -GetMetaFileA -GetMetaFileBitsEx -GetMetaFileW -GetMetaRgn -GetMiterLimit -GetNearestColor -GetNearestPaletteIndex -GetObjectA -GetObjectType -GetObjectW -GetOutlineTextMetricsA -GetOutlineTextMetricsW -GetPaletteEntries -GetPath -GetPixel -GetPixelFormat -GetPolyFillMode -GetROP2 -GetRandomRgn -GetRasterizerCaps -GetRegionData -GetRgnBox -GetStockObject -GetStretchBltMode -GetSystemPaletteEntries -GetSystemPaletteUse -GetTextAlign -GetTextCharacterExtra -GetTextCharset -GetTextCharsetInfo -GetTextColor -GetTextExtentExPointA -GetTextExtentExPointW -GetTextExtentPoint32A -GetTextExtentPoint32W -GetTextExtentPointA -GetTextExtentPointW -GetTextFaceA -GetTextFaceW -GetTextMetricsA -GetTextMetricsW -GetViewportExtEx -GetViewportOrgEx -GetWinMetaFileBits -GetWindowExtEx -GetWindowOrgEx -GetWorldTransform -IntersectClipRect -InvertRgn -LPtoDP -LineDDA -LineTo -MaskBlt -ModifyWorldTransform -MoveToEx -OffsetClipRgn -OffsetRgn -OffsetViewportOrgEx -OffsetWindowOrgEx -PaintRgn -PatBlt -PathToRegion -Pie -PlayEnhMetaFile -PlayEnhMetaFileRecord -PlayMetaFile -PlayMetaFileRecord -PlgBlt -PolyBezier -PolyBezierTo -PolyDraw -PolyPolygon -PolyPolyline -PolyTextOutA -PolyTextOutW -Polygon -Polyline -PolylineTo -PtInRegion -PtVisible -RealizePalette -RectInRegion -RectVisible -Rectangle -RemoveFontResourceA -RemoveFontResourceW -ResetDCA -ResetDCW -ResizePalette -RestoreDC -RoundRect -SaveDC -ScaleViewportExtEx -ScaleWindowExtEx -SelectClipPath -SelectClipRgn -SelectObject -SelectPalette -SetAbortProc -SetArcDirection -SetBitmapBits -SetBitmapDimensionEx -SetBkColor -SetBkMode -SetBoundsRect -SetBrushOrgEx -SetColorAdjustment -SetColorSpace -SetDIBColorTable -SetDIBits -SetDIBitsToDevice -SetDeviceGammaRamp -SetEnhMetaFileBits -SetFontEnumeration -SetGraphicsMode -SetICMMode -SetICMProfileA -SetICMProfileW -SetLayout -SetMagicColors -SetMapMode -SetMapperFlags -SetMetaFileBitsEx -SetMetaRgn -SetMiterLimit -SetObjectOwner -SetPaletteEntries -SetPixel -SetPixelFormat -SetPixelV -SetPolyFillMode -SetROP2 -SetRectRgn -SetStretchBltMode -SetSystemPaletteUse -SetTextAlign -SetTextCharacterExtra -SetTextColor -SetTextJustification -SetViewportExtEx -SetViewportOrgEx -SetWinMetaFileBits -SetWindowExtEx -SetWindowOrgEx -SetWorldTransform -StartDocA -StartDocW -StartPage -StretchBlt -StretchDIBits -StrokeAndFillPath -StrokePath -SwapBuffers -TextOutA -TextOutW -TranslateCharsetInfo -UnrealizeObject -UpdateColors -UpdateICMRegKeyA -UpdateICMRegKeyW -WidenPath -gdiPlaySpoolStream -pfnRealizePalette -pfnSelectPalette diff --git a/05/tcc-final-old/win32/lib/kernel32.def b/05/tcc-final-old/win32/lib/kernel32.def deleted file mode 100644 index f03e17b..0000000 --- a/05/tcc-final-old/win32/lib/kernel32.def +++ /dev/null @@ -1,770 +0,0 @@ -LIBRARY kernel32.dll - -EXPORTS -AddAtomA -AddAtomW -AllocConsole -AllocLSCallback -AllocSLCallback -AreFileApisANSI -BackupRead -BackupSeek -BackupWrite -Beep -BeginUpdateResourceA -BeginUpdateResourceW -BuildCommDCBA -BuildCommDCBAndTimeoutsA -BuildCommDCBAndTimeoutsW -BuildCommDCBW -CallNamedPipeA -CallNamedPipeW -Callback12 -Callback16 -Callback20 -Callback24 -Callback28 -Callback32 -Callback36 -Callback4 -Callback40 -Callback44 -Callback48 -Callback52 -Callback56 -Callback60 -Callback64 -Callback8 -CancelDeviceWakeupRequest -CancelIo -CancelWaitableTimer -ClearCommBreak -ClearCommError -CloseHandle -CloseProfileUserMapping -CloseSystemHandle -CommConfigDialogA -CommConfigDialogW -CompareFileTime -CompareStringA -CompareStringW -ConnectNamedPipe -ContinueDebugEvent -ConvertDefaultLocale -ConvertThreadToFiber -ConvertToGlobalHandle -CopyFileA -CopyFileExA -CopyFileExW -CopyFileW -CreateConsoleScreenBuffer -CreateDirectoryA -CreateDirectoryExA -CreateDirectoryExW -CreateDirectoryW -CreateEventA -CreateEventW -CreateFiber -CreateFileA -CreateFileMappingA -CreateFileMappingW -CreateFileW -CreateIoCompletionPort -CreateKernelThread -CreateMailslotA -CreateMailslotW -CreateMutexA -CreateMutexW -CreateNamedPipeA -CreateNamedPipeW -CreatePipe -CreateProcessA -CreateProcessW -CreateRemoteThread -CreateSemaphoreA -CreateSemaphoreW -CreateSocketHandle -CreateTapePartition -CreateThread -CreateToolhelp32Snapshot -CreateWaitableTimerA -CreateWaitableTimerW -DebugActiveProcess -DebugBreak -DefineDosDeviceA -DefineDosDeviceW -DeleteAtom -DeleteCriticalSection -DeleteFiber -DeleteFileA -DeleteFileW -DeviceIoControl -DisableThreadLibraryCalls -DisconnectNamedPipe -DosDateTimeToFileTime -DuplicateHandle -EndUpdateResourceA -EndUpdateResourceW -EnterCriticalSection -EnumCalendarInfoA -EnumCalendarInfoExA -EnumCalendarInfoExW -EnumCalendarInfoW -EnumDateFormatsA -EnumDateFormatsExA -EnumDateFormatsExW -EnumDateFormatsW -EnumLanguageGroupLocalesA -EnumLanguageGroupLocalesW -EnumResourceLanguagesA -EnumResourceLanguagesW -EnumResourceNamesA -EnumResourceNamesW -EnumResourceTypesA -EnumResourceTypesW -EnumSystemCodePagesA -EnumSystemCodePagesW -EnumSystemGeoID -EnumSystemLanguageGroupsA -EnumSystemLanguageGroupsW -EnumSystemLocalesA -EnumSystemLocalesW -EnumTimeFormatsA -EnumTimeFormatsW -EnumUILanguagesA -EnumUILanguagesW -EraseTape -EscapeCommFunction -ExitProcess -ExitThread -ExpandEnvironmentStringsA -ExpandEnvironmentStringsW -FT_Exit0 -FT_Exit12 -FT_Exit16 -FT_Exit20 -FT_Exit24 -FT_Exit28 -FT_Exit32 -FT_Exit36 -FT_Exit4 -FT_Exit40 -FT_Exit44 -FT_Exit48 -FT_Exit52 -FT_Exit56 -FT_Exit8 -FT_Prolog -FT_Thunk -FatalAppExitA -FatalAppExitW -FatalExit -FileTimeToDosDateTime -FileTimeToLocalFileTime -FileTimeToSystemTime -FillConsoleOutputAttribute -FillConsoleOutputCharacterA -FillConsoleOutputCharacterW -FindAtomA -FindAtomW -FindClose -FindCloseChangeNotification -FindFirstChangeNotificationA -FindFirstChangeNotificationW -FindFirstFileA -FindFirstFileExA -FindFirstFileExW -FindFirstFileW -FindNextChangeNotification -FindNextFileA -FindNextFileW -FindResourceA -FindResourceExA -FindResourceExW -FindResourceW -FlushConsoleInputBuffer -FlushFileBuffers -FlushInstructionCache -FlushViewOfFile -FoldStringA -FoldStringW -FormatMessageA -FormatMessageW -FreeConsole -FreeEnvironmentStringsA -FreeEnvironmentStringsW -FreeLSCallback -FreeLibrary -FreeLibraryAndExitThread -FreeResource -FreeSLCallback -GenerateConsoleCtrlEvent -GetACP -GetAtomNameA -GetAtomNameW -GetBinaryType -GetBinaryTypeA -GetBinaryTypeW -GetCPInfo -GetCPInfoExA -GetCPInfoExW -GetCalendarInfoA -GetCalendarInfoW -GetCommConfig -GetCommMask -GetCommModemStatus -GetCommProperties -GetCommState -GetCommTimeouts -GetCommandLineA -GetCommandLineW -GetCompressedFileSizeA -GetCompressedFileSizeW -GetComputerNameA -GetComputerNameW -GetConsoleCP -GetConsoleCursorInfo -GetConsoleMode -GetConsoleOutputCP -GetConsoleScreenBufferInfo -GetConsoleTitleA -GetConsoleTitleW -GetCurrencyFormatA -GetCurrencyFormatW -GetCurrentDirectoryA -GetCurrentDirectoryW -GetCurrentProcess -GetCurrentProcessId -GetCurrentThread -GetCurrentThreadId -GetDateFormatA -GetDateFormatW -GetDaylightFlag -GetDefaultCommConfigA -GetDefaultCommConfigW -GetDevicePowerState -GetDiskFreeSpaceA -GetDiskFreeSpaceExA -GetDiskFreeSpaceExW -GetDiskFreeSpaceW -GetDriveTypeA -GetDriveTypeW -GetEnvironmentStrings -GetEnvironmentStringsA -GetEnvironmentStringsW -GetEnvironmentVariableA -GetEnvironmentVariableW -GetErrorMode -GetExitCodeProcess -GetExitCodeThread -GetFileAttributesA -GetFileAttributesExA -GetFileAttributesExW -GetFileAttributesW -GetFileInformationByHandle -GetFileSize -GetFileTime -GetFileType -GetFullPathNameA -GetFullPathNameW -GetGeoInfoA -GetGeoInfoW -GetHandleContext -GetHandleInformation -GetLSCallbackTarget -GetLSCallbackTemplate -GetLargestConsoleWindowSize -GetLastError -GetLocalTime -GetLocaleInfoA -GetLocaleInfoW -GetLogicalDriveStringsA -GetLogicalDriveStringsW -GetLogicalDrives -GetLongPathNameA -GetLongPathNameW -GetMailslotInfo -GetModuleFileNameA -GetModuleFileNameW -GetModuleHandleA -GetModuleHandleW -GetModuleHandleExA -GetModuleHandleExW -GetNamedPipeHandleStateA -GetNamedPipeHandleStateW -GetNamedPipeInfo -GetNumberFormatA -GetNumberFormatW -GetNumberOfConsoleInputEvents -GetNumberOfConsoleMouseButtons -GetOEMCP -GetOverlappedResult -GetPriorityClass -GetPrivateProfileIntA -GetPrivateProfileIntW -GetPrivateProfileSectionA -GetPrivateProfileSectionNamesA -GetPrivateProfileSectionNamesW -GetPrivateProfileSectionW -GetPrivateProfileStringA -GetPrivateProfileStringW -GetPrivateProfileStructA -GetPrivateProfileStructW -GetProcAddress -GetProcessAffinityMask -GetProcessFlags -GetProcessHeap -GetProcessHeaps -GetProcessPriorityBoost -GetProcessShutdownParameters -GetProcessTimes -GetProcessVersion -GetProcessWorkingSetSize -GetProductName -GetProfileIntA -GetProfileIntW -GetProfileSectionA -GetProfileSectionW -GetProfileStringA -GetProfileStringW -GetQueuedCompletionStatus -GetSLCallbackTarget -GetSLCallbackTemplate -GetShortPathNameA -GetShortPathNameW -GetStartupInfoA -GetStartupInfoW -GetStdHandle -GetStringTypeA -GetStringTypeExA -GetStringTypeExW -GetStringTypeW -GetSystemDefaultLCID -GetSystemDefaultLangID -GetSystemDefaultUILanguage -GetSystemDirectoryA -GetSystemDirectoryW -GetSystemInfo -GetSystemPowerStatus -GetSystemTime -GetSystemTimeAdjustment -GetSystemTimeAsFileTime -GetTapeParameters -GetTapePosition -GetTapeStatus -GetTempFileNameA -GetTempFileNameW -GetTempPathA -GetTempPathW -GetThreadContext -GetThreadLocale -GetThreadPriority -GetThreadPriorityBoost -GetThreadSelectorEntry -GetThreadTimes -GetTickCount -GetTimeFormatA -GetTimeFormatW -GetTimeZoneInformation -GetUserDefaultLCID -GetUserDefaultLangID -GetUserDefaultUILanguage -GetUserGeoID -GetVersion -GetVersionExA -GetVersionExW -GetVolumeInformationA -GetVolumeInformationW -GetWindowsDirectoryA -GetWindowsDirectoryW -GetWriteWatch -GlobalAddAtomA -GlobalAddAtomW -GlobalAlloc -GlobalCompact -GlobalDeleteAtom -GlobalFindAtomA -GlobalFindAtomW -GlobalFix -GlobalFlags -GlobalFree -GlobalGetAtomNameA -GlobalGetAtomNameW -GlobalHandle -GlobalLock -GlobalMemoryStatus -GlobalReAlloc -GlobalSize -GlobalUnWire -GlobalUnfix -GlobalUnlock -GlobalWire -Heap32First -Heap32ListFirst -Heap32ListNext -Heap32Next -HeapAlloc -HeapCompact -HeapCreate -HeapDestroy -HeapFree -HeapLock -HeapReAlloc -HeapSetFlags -HeapSize -HeapUnlock -HeapValidate -HeapWalk -InitAtomTable -InitializeCriticalSection -InitializeCriticalSectionAndSpinCount -InterlockedCompareExchange -InterlockedDecrement -InterlockedExchange -InterlockedExchangeAdd -InterlockedIncrement -InvalidateNLSCache -IsBadCodePtr -IsBadHugeReadPtr -IsBadHugeWritePtr -IsBadReadPtr -IsBadStringPtrA -IsBadStringPtrW -IsBadWritePtr -IsDBCSLeadByte -IsDBCSLeadByteEx -IsDebuggerPresent -IsLSCallback -IsProcessorFeaturePresent -IsSLCallback -IsSystemResumeAutomatic -IsValidCodePage -IsValidLanguageGroup -IsValidLocale -K32Thk1632Epilog -K32Thk1632Prolog -K32_NtCreateFile -K32_RtlNtStatusToDosError -LCMapStringA -LCMapStringW -LeaveCriticalSection -LoadLibraryA -LoadLibraryExA -LoadLibraryExW -LoadLibraryW -LoadModule -LoadResource -LocalAlloc -LocalCompact -LocalFileTimeToFileTime -LocalFlags -LocalFree -LocalHandle -LocalLock -LocalReAlloc -LocalShrink -LocalSize -LocalUnlock -LockFile -LockFileEx -LockResource -MakeCriticalSectionGlobal -MapHInstLS -MapHInstLS_PN -MapHInstSL -MapHInstSL_PN -MapHModuleLS -MapHModuleSL -MapLS -MapSL -MapSLFix -MapViewOfFile -MapViewOfFileEx -Module32First -Module32Next -MoveFileA -MoveFileExA -MoveFileExW -MoveFileW -MulDiv -MultiByteToWideChar -NotifyNLSUserCache -OpenEventA -OpenEventW -OpenFile -OpenFileMappingA -OpenFileMappingW -OpenMutexA -OpenMutexW -OpenProcess -OpenProfileUserMapping -OpenSemaphoreA -OpenSemaphoreW -OpenThread -OpenVxDHandle -OpenWaitableTimerA -OpenWaitableTimerW -OutputDebugStringA -OutputDebugStringW -PeekConsoleInputA -PeekConsoleInputW -PeekNamedPipe -PostQueuedCompletionStatus -PrepareTape -Process32First -Process32Next -PulseEvent -PurgeComm -QT_Thunk -QueryDosDeviceA -QueryDosDeviceW -QueryNumberOfEventLogRecords -QueryOldestEventLogRecord -QueryPerformanceCounter -QueryPerformanceFrequency -QueueUserAPC -RaiseException -ReadConsoleA -ReadConsoleInputA -ReadConsoleInputW -ReadConsoleOutputA -ReadConsoleOutputAttribute -ReadConsoleOutputCharacterA -ReadConsoleOutputCharacterW -ReadConsoleOutputW -ReadConsoleW -ReadDirectoryChangesW -ReadFile -ReadFileEx -ReadFileScatter -ReadProcessMemory -RegisterServiceProcess -RegisterSysMsgHandler -ReinitializeCriticalSection -ReleaseMutex -ReleaseSemaphore -RemoveDirectoryA -RemoveDirectoryW -RequestDeviceWakeup -RequestWakeupLatency -ResetEvent -ResetNLSUserInfoCache -ResetWriteWatch -ResumeThread -RtlAddFunctionTable -RtlDeleteFunctionTable -RtlFillMemory -RtlInstallFunctionTableCallback -RtlMoveMemory -RtlUnwind -RtlUnwindEx -RtlZeroMemory -SMapLS -SMapLS_IP_EBP_12 -SMapLS_IP_EBP_16 -SMapLS_IP_EBP_20 -SMapLS_IP_EBP_24 -SMapLS_IP_EBP_28 -SMapLS_IP_EBP_32 -SMapLS_IP_EBP_36 -SMapLS_IP_EBP_40 -SMapLS_IP_EBP_8 -SUnMapLS -SUnMapLS_IP_EBP_12 -SUnMapLS_IP_EBP_16 -SUnMapLS_IP_EBP_20 -SUnMapLS_IP_EBP_24 -SUnMapLS_IP_EBP_28 -SUnMapLS_IP_EBP_32 -SUnMapLS_IP_EBP_36 -SUnMapLS_IP_EBP_40 -SUnMapLS_IP_EBP_8 -ScrollConsoleScreenBufferA -ScrollConsoleScreenBufferW -SearchPathA -SearchPathW -SetCalendarInfoA -SetCalendarInfoW -SetCommBreak -SetCommConfig -SetCommMask -SetCommState -SetCommTimeouts -SetComputerNameA -SetComputerNameW -SetConsoleActiveScreenBuffer -SetConsoleCP -SetConsoleCtrlHandler -SetConsoleCursorInfo -SetConsoleCursorPosition -SetConsoleMode -SetConsoleOutputCP -SetConsoleScreenBufferSize -SetConsoleTextAttribute -SetConsoleTitleA -SetConsoleTitleW -SetConsoleWindowInfo -SetCriticalSectionSpinCount -SetCurrentDirectoryA -SetCurrentDirectoryW -SetDaylightFlag -SetDefaultCommConfigA -SetDefaultCommConfigW -SetEndOfFile -SetEnvironmentVariableA -SetEnvironmentVariableW -SetErrorMode -SetEvent -SetFileApisToANSI -SetFileApisToOEM -SetFileAttributesA -SetFileAttributesW -SetFilePointer -SetFilePointerEx -SetFileTime -SetHandleContext -SetHandleCount -SetHandleInformation -SetLastError -SetLocalTime -SetLocaleInfoA -SetLocaleInfoW -SetMailslotInfo -SetMessageWaitingIndicator -SetNamedPipeHandleState -SetPriorityClass -SetProcessAffinityMask -SetProcessPriorityBoost -SetProcessShutdownParameters -SetProcessWorkingSetSize -SetStdHandle -SetSystemPowerState -SetSystemTime -SetSystemTimeAdjustment -SetTapeParameters -SetTapePosition -SetThreadAffinityMask -SetThreadContext -SetThreadExecutionState -SetThreadIdealProcessor -SetThreadLocale -SetThreadPriority -SetThreadPriorityBoost -SetTimeZoneInformation -SetUnhandledExceptionFilter -SetUserGeoID -SetVolumeLabelA -SetVolumeLabelW -SetWaitableTimer -SetupComm -SignalObjectAndWait -SignalSysMsgHandlers -SizeofResource -Sleep -SleepEx -SuspendThread -SwitchToFiber -SwitchToThread -SystemTimeToFileTime -SystemTimeToTzSpecificLocalTime -TerminateProcess -TerminateThread -Thread32First -Thread32Next -ThunkConnect32 -TlsAlloc -TlsAllocInternal -TlsFree -TlsFreeInternal -TlsGetValue -TlsSetValue -Toolhelp32ReadProcessMemory -TransactNamedPipe -TransmitCommChar -TryEnterCriticalSection -UTRegister -UTUnRegister -UnMapLS -UnMapSLFixArray -UnhandledExceptionFilter -UninitializeCriticalSection -UnlockFile -UnlockFileEx -UnmapViewOfFile -UpdateResourceA -UpdateResourceW -VerLanguageNameA -VerLanguageNameW -VirtualAlloc -VirtualAllocEx -VirtualFree -VirtualFreeEx -VirtualLock -VirtualProtect -VirtualProtectEx -VirtualQuery -VirtualQueryEx -VirtualUnlock -WaitCommEvent -WaitForDebugEvent -WaitForMultipleObjects -WaitForMultipleObjectsEx -WaitForSingleObject -WaitForSingleObjectEx -WaitNamedPipeA -WaitNamedPipeW -WideCharToMultiByte -WinExec -WriteConsoleA -WriteConsoleInputA -WriteConsoleInputW -WriteConsoleOutputA -WriteConsoleOutputAttribute -WriteConsoleOutputCharacterA -WriteConsoleOutputCharacterW -WriteConsoleOutputW -WriteConsoleW -WriteFile -WriteFileEx -WriteFileGather -WritePrivateProfileSectionA -WritePrivateProfileSectionW -WritePrivateProfileStringA -WritePrivateProfileStringW -WritePrivateProfileStructA -WritePrivateProfileStructW -WriteProcessMemory -WriteProfileSectionA -WriteProfileSectionW -WriteProfileStringA -WriteProfileStringW -WriteTapemark -_DebugOut -_DebugPrintf -_hread -_hwrite -_lclose -_lcreat -_llseek -_lopen -_lread -_lwrite -dprintf -lstrcat -lstrcatA -lstrcatW -lstrcmp -lstrcmpA -lstrcmpW -lstrcmpi -lstrcmpiA -lstrcmpiW -lstrcpy -lstrcpyA -lstrcpyW -lstrcpyn -lstrcpynA -lstrcpynW -lstrlen -lstrlenA -lstrlenW diff --git a/05/tcc-final-old/win32/lib/msvcrt.def b/05/tcc-final-old/win32/lib/msvcrt.def deleted file mode 100644 index 742acb8..0000000 --- a/05/tcc-final-old/win32/lib/msvcrt.def +++ /dev/null @@ -1,1399 +0,0 @@ -LIBRARY msvcrt.dll - -EXPORTS -$I10_OUTPUT -??0__non_rtti_object@@QAE@ABV0@@Z -??0__non_rtti_object@@QAE@PBD@Z -??0bad_cast@@AAE@PBQBD@Z -??0bad_cast@@QAE@ABQBD@Z -??0bad_cast@@QAE@ABV0@@Z -??0bad_cast@@QAE@PBD@Z -??0bad_typeid@@QAE@ABV0@@Z -??0bad_typeid@@QAE@PBD@Z -??0exception@@QAE@ABQBD@Z -??0exception@@QAE@ABQBDH@Z -??0exception@@QAE@ABV0@@Z -??0exception@@QAE@XZ -??1__non_rtti_object@@UAE@XZ -??1bad_cast@@UAE@XZ -??1bad_typeid@@UAE@XZ -??1exception@@UAE@XZ -??1type_info@@UAE@XZ -??2@YAPAXI@Z -??2@YAPAXIHPBDH@Z -??3@YAXPAX@Z -??4__non_rtti_object@@QAEAAV0@ABV0@@Z -??4bad_cast@@QAEAAV0@ABV0@@Z -??4bad_typeid@@QAEAAV0@ABV0@@Z -??4exception@@QAEAAV0@ABV0@@Z -??8type_info@@QBEHABV0@@Z -??9type_info@@QBEHABV0@@Z -??_7__non_rtti_object@@6B@ -??_7bad_cast@@6B@ -??_7bad_typeid@@6B@ -??_7exception@@6B@ -??_E__non_rtti_object@@UAEPAXI@Z -??_Ebad_cast@@UAEPAXI@Z -??_Ebad_typeid@@UAEPAXI@Z -??_Eexception@@UAEPAXI@Z -??_Fbad_cast@@QAEXXZ -??_Fbad_typeid@@QAEXXZ -??_G__non_rtti_object@@UAEPAXI@Z -??_Gbad_cast@@UAEPAXI@Z -??_Gbad_typeid@@UAEPAXI@Z -??_Gexception@@UAEPAXI@Z -??_U@YAPAXI@Z -??_U@YAPAXIHPBDH@Z -??_V@YAXPAX@Z -?_query_new_handler@@YAP6AHI@ZXZ -?_query_new_mode@@YAHXZ -?_set_new_handler@@YAP6AHI@ZP6AHI@Z@Z -?_set_new_mode@@YAHH@Z -?_set_se_translator@@YAP6AXIPAU_EXCEPTION_POINTERS@@@ZP6AXI0@Z@Z -?before@type_info@@QBEHABV1@@Z -?name@type_info@@QBEPBDXZ -?raw_name@type_info@@QBEPBDXZ -?set_new_handler@@YAP6AXXZP6AXXZ@Z -?set_terminate@@YAP6AXXZP6AXXZ@Z -?set_unexpected@@YAP6AXXZP6AXXZ@Z -?terminate@@YAXXZ -?unexpected@@YAXXZ -?what@exception@@UBEPBDXZ -_CIacos -_CIasin -_CIatan -_CIatan2 -_CIcos -_CIcosh -_CIexp -_CIfmod -_CIlog -_CIlog10 -_CIpow -_CIsin -_CIsinh -_CIsqrt -_CItan -_CItanh -_CrtCheckMemory -_CrtDbgBreak -_CrtDbgReport -_CrtDbgReportV -_CrtDbgReportW -_CrtDbgReportWV -_CrtDoForAllClientObjects -_CrtDumpMemoryLeaks -_CrtIsMemoryBlock -_CrtIsValidHeapPointer -_CrtIsValidPointer -_CrtMemCheckpoint -_CrtMemDifference -_CrtMemDumpAllObjectsSince -_CrtMemDumpStatistics -_CrtReportBlockType -_CrtSetAllocHook -_CrtSetBreakAlloc -_CrtSetDbgBlockType -_CrtSetDbgFlag -_CrtSetDumpClient -_CrtSetReportFile -_CrtSetReportHook -_CrtSetReportHook2 -_CrtSetReportMode -_CxxThrowException -_EH_prolog -_Getdays -_Getmonths -_Gettnames -_HUGE -_Strftime -_XcptFilter -__CppXcptFilter -__CxxCallUnwindDelDtor -__CxxCallUnwindDtor -__CxxCallUnwindVecDtor -__CxxDetectRethrow -__CxxExceptionFilter -__CxxFrameHandler -__CxxFrameHandler2 -__CxxFrameHandler3 -__CxxLongjmpUnwind -__CxxQueryExceptionSize -__CxxRegisterExceptionObject -__CxxUnregisterExceptionObject -__DestructExceptionObject -__RTCastToVoid -__RTDynamicCast -__RTtypeid -__STRINGTOLD -___lc_codepage_func -___lc_collate_cp_func -___lc_handle_func -___mb_cur_max_func -___setlc_active_func -___unguarded_readlc_active_add_func -__argc -__argv -__badioinfo -__crtCompareStringA -__crtCompareStringW -__crtGetLocaleInfoW -__crtGetStringTypeW -__crtLCMapStringA -__crtLCMapStringW -__daylight -__dllonexit -__doserrno -__dstbias -__fpecode -__getmainargs -__initenv -__iob_func -__isascii -__iscsym -__iscsymf -__lc_codepage -__lc_collate_cp -__lc_handle -__lconv_init -__libm_sse2_acos -__libm_sse2_acosf -__libm_sse2_asin -__libm_sse2_asinf -__libm_sse2_atan -__libm_sse2_atan2 -__libm_sse2_atanf -__libm_sse2_cos -__libm_sse2_cosf -__libm_sse2_exp -__libm_sse2_expf -__libm_sse2_log -__libm_sse2_log10 -__libm_sse2_log10f -__libm_sse2_logf -__libm_sse2_pow -__libm_sse2_powf -__libm_sse2_sin -__libm_sse2_sinf -__libm_sse2_tan -__libm_sse2_tanf -__mb_cur_max -__p___argc -__p___argv -__p___initenv -__p___mb_cur_max -__p___wargv -__p___winitenv -__p__acmdln -__p__amblksiz -__p__commode -__p__daylight -__p__dstbias -__p__environ -__p__fileinfo -__p__fmode -__p__iob -__p__mbcasemap -__p__mbctype -__p__osver -__p__pctype -__p__pgmptr -__p__pwctype -__p__timezone -__p__tzname -__p__wcmdln -__p__wenviron -__p__winmajor -__p__winminor -__p__winver -__p__wpgmptr -__pctype_func -__pioinfo -__pwctype_func -__pxcptinfoptrs -__set_app_type -__setlc_active -__setusermatherr -__strncnt -__threadhandle -__threadid -__toascii -__unDName -__unDNameEx -__uncaught_exception -__unguarded_readlc_active -__wargv -__wcserror -__wcserror_s -__wcsncnt -__wgetmainargs -__winitenv -_abnormal_termination -_abs64 -_access -_access_s -_acmdln -_adj_fdiv_m16i -_adj_fdiv_m32 -_adj_fdiv_m32i -_adj_fdiv_m64 -_adj_fdiv_r -_adj_fdivr_m16i -_adj_fdivr_m32 -_adj_fdivr_m32i -_adj_fdivr_m64 -_adj_fpatan -_adj_fprem -_adj_fprem1 -_adj_fptan -_adjust_fdiv -_aexit_rtn -_aligned_free -_aligned_free_dbg -_aligned_malloc -_aligned_malloc_dbg -_aligned_offset_malloc -_aligned_offset_malloc_dbg -_aligned_offset_realloc -_aligned_offset_realloc_dbg -_aligned_realloc -_aligned_realloc_dbg -_amsg_exit -_assert -_atodbl -_atodbl_l -_atof_l -_atoflt_l -_atoi64 -_atoi64_l -_atoi_l -_atol_l -_atoldbl -_atoldbl_l -_beep -_beginthread -_beginthreadex -_c_exit -_cabs -_callnewh -_calloc_dbg -_cexit -_cgets -_cgets_s -_cgetws -_cgetws_s -_chdir -_chdrive -_chgsign -_chkesp -_chmod -_chsize -_chsize_s -_chvalidator -_chvalidator_l -_clearfp -_close -_commit -_commode -_control87 -_controlfp -_controlfp_s -_copysign -_cprintf -_cprintf_l -_cprintf_p -_cprintf_p_l -_cprintf_s -_cprintf_s_l -_cputs -_cputws -_creat -_crtAssertBusy -_crtBreakAlloc -_crtDbgFlag -_cscanf -_cscanf_l -_cscanf_s -_cscanf_s_l -_ctime32 -_ctime32_s -_ctime64 -_ctime64_s -_ctype -_cwait -_cwprintf -_cwprintf_l -_cwprintf_p -_cwprintf_p_l -_cwprintf_s -_cwprintf_s_l -_cwscanf -_cwscanf_l -_cwscanf_s -_cwscanf_s_l -_daylight -_difftime32 -_difftime64 -_dstbias -_dup -_dup2 -_ecvt -_ecvt_s -_endthread -_endthreadex -_environ -_eof -_errno -_except_handler2 -_except_handler3 -_except_handler4_common -_execl -_execle -_execlp -_execlpe -_execv -_execve -_execvp -_execvpe -_exit -_expand -_expand_dbg -_fcloseall -_fcvt -_fcvt_s -_fdopen -_fgetchar -_fgetwchar -_filbuf -_fileinfo -_filelength -_filelengthi64 -_fileno -_findclose -_findfirst -_findfirst64 -_findfirsti64 -_findnext -_findnext64 -_findnexti64 -_finite -_flsbuf -_flushall -_fmode -_fpclass -_fpieee_flt -_fpreset -_fprintf_l -_fprintf_p -_fprintf_p_l -_fprintf_s_l -_fputchar -_fputwchar -_free_dbg -_freea -_freea_s -_fscanf_l -_fscanf_s_l -_fseeki64 -_fsopen -_fstat -_fstat64 -_fstati64 -_ftime -_ftime32 -_ftime32_s -_ftime64 -_ftime64_s -_ftol -_ftol2 -_ftol2_sse -_ftol2_sse_excpt -_fullpath -_fullpath_dbg -_futime -_futime32 -_futime64 -_fwprintf_l -_fwprintf_p -_fwprintf_p_l -_fwprintf_s_l -_fwscanf_l -_fwscanf_s_l -_gcvt -_gcvt_s -_get_doserrno -_get_environ -_get_errno -_get_fileinfo -_get_fmode -_get_heap_handle -_get_osfhandle -_get_osplatform -_get_osver -_get_output_format -_get_pgmptr -_get_sbh_threshold -_get_wenviron -_get_winmajor -_get_winminor -_get_winver -_get_wpgmptr -_getch -_getche -_getcwd -_getdcwd -_getdiskfree -_getdllprocaddr -_getdrive -_getdrives -_getmaxstdio -_getmbcp -_getpid -_getsystime -_getw -_getwch -_getwche -_getws -_global_unwind2 -_gmtime32 -_gmtime32_s -_gmtime64 -_gmtime64_s -_heapadd -_heapchk -_heapmin -_heapset -_heapused -_heapwalk -_hypot -_i64toa -_i64toa_s -_i64tow -_i64tow_s -_initterm -_initterm_e -_inp -_inpd -_inpw -_invalid_parameter -_iob -_isalnum_l -_isalpha_l -_isatty -_iscntrl_l -_isctype -_isctype_l -_isdigit_l -_isgraph_l -_isleadbyte_l -_islower_l -_ismbbalnum -_ismbbalnum_l -_ismbbalpha -_ismbbalpha_l -_ismbbgraph -_ismbbgraph_l -_ismbbkalnum -_ismbbkalnum_l -_ismbbkana -_ismbbkana_l -_ismbbkprint -_ismbbkprint_l -_ismbbkpunct -_ismbbkpunct_l -_ismbblead -_ismbblead_l -_ismbbprint -_ismbbprint_l -_ismbbpunct -_ismbbpunct_l -_ismbbtrail -_ismbbtrail_l -_ismbcalnum -_ismbcalnum_l -_ismbcalpha -_ismbcalpha_l -_ismbcdigit -_ismbcdigit_l -_ismbcgraph -_ismbcgraph_l -_ismbchira -_ismbchira_l -_ismbckata -_ismbckata_l -_ismbcl0 -_ismbcl0_l -_ismbcl1 -_ismbcl1_l -_ismbcl2 -_ismbcl2_l -_ismbclegal -_ismbclegal_l -_ismbclower -_ismbclower_l -_ismbcprint -_ismbcprint_l -_ismbcpunct -_ismbcpunct_l -_ismbcspace -_ismbcspace_l -_ismbcsymbol -_ismbcsymbol_l -_ismbcupper -_ismbcupper_l -_ismbslead -_ismbslead_l -_ismbstrail -_ismbstrail_l -_isnan -_isprint_l -_isspace_l -_isupper_l -_iswalnum_l -_iswalpha_l -_iswcntrl_l -_iswctype_l -_iswdigit_l -_iswgraph_l -_iswlower_l -_iswprint_l -_iswpunct_l -_iswspace_l -_iswupper_l -_iswxdigit_l -_isxdigit_l -_itoa -_itoa_s -_itow -_itow_s -_j0 -_j1 -_jn -_kbhit -_lfind -_lfind_s -_loaddll -_local_unwind2 -_local_unwind4 -_localtime32 -_localtime32_s -_localtime64 -_localtime64_s -_lock -_locking -_logb -_longjmpex -_lrotl -_lrotr -_lsearch -_lsearch_s -_lseek -_lseeki64 -_ltoa -_ltoa_s -_ltow -_ltow_s -_makepath -_makepath_s -_malloc_dbg -_mbbtombc -_mbbtombc_l -_mbbtype -_mbcasemap -_mbccpy -_mbccpy_l -_mbccpy_s -_mbccpy_s_l -_mbcjistojms -_mbcjistojms_l -_mbcjmstojis -_mbcjmstojis_l -_mbclen -_mbclen_l -_mbctohira -_mbctohira_l -_mbctokata -_mbctokata_l -_mbctolower -_mbctolower_l -_mbctombb -_mbctombb_l -_mbctoupper -_mbctoupper_l -_mbctype -_mblen_l -_mbsbtype -_mbsbtype_l -_mbscat -_mbscat_s -_mbscat_s_l -_mbschr -_mbschr_l -_mbscmp -_mbscmp_l -_mbscoll -_mbscoll_l -_mbscpy -_mbscpy_s -_mbscpy_s_l -_mbscspn -_mbscspn_l -_mbsdec -_mbsdec_l -_mbsdup -_mbsicmp -_mbsicmp_l -_mbsicoll -_mbsicoll_l -_mbsinc -_mbsinc_l -_mbslen -_mbslen_l -_mbslwr -_mbslwr_l -_mbslwr_s -_mbslwr_s_l -_mbsnbcat -_mbsnbcat_l -_mbsnbcat_s -_mbsnbcat_s_l -_mbsnbcmp -_mbsnbcmp_l -_mbsnbcnt -_mbsnbcnt_l -_mbsnbcoll -_mbsnbcoll_l -_mbsnbcpy -_mbsnbcpy_l -_mbsnbcpy_s -_mbsnbcpy_s_l -_mbsnbicmp -_mbsnbicmp_l -_mbsnbicoll -_mbsnbicoll_l -_mbsnbset -_mbsnbset_l -_mbsnbset_s -_mbsnbset_s_l -_mbsncat -_mbsncat_l -_mbsncat_s -_mbsncat_s_l -_mbsnccnt -_mbsnccnt_l -_mbsncmp -_mbsncmp_l -_mbsncoll -_mbsncoll_l -_mbsncpy -_mbsncpy_l -_mbsncpy_s -_mbsncpy_s_l -_mbsnextc -_mbsnextc_l -_mbsnicmp -_mbsnicmp_l -_mbsnicoll -_mbsnicoll_l -_mbsninc -_mbsninc_l -_mbsnlen -_mbsnlen_l -_mbsnset -_mbsnset_l -_mbsnset_s -_mbsnset_s_l -_mbspbrk -_mbspbrk_l -_mbsrchr -_mbsrchr_l -_mbsrev -_mbsrev_l -_mbsset -_mbsset_l -_mbsset_s -_mbsset_s_l -_mbsspn -_mbsspn_l -_mbsspnp -_mbsspnp_l -_mbsstr -_mbsstr_l -_mbstok -_mbstok_l -_mbstok_s -_mbstok_s_l -_mbstowcs_l -_mbstowcs_s_l -_mbstrlen -_mbstrlen_l -_mbstrnlen -_mbstrnlen_l -_mbsupr -_mbsupr_l -_mbsupr_s -_mbsupr_s_l -_mbtowc_l -_memccpy -_memicmp -_memicmp_l -_mkdir -_mkgmtime -_mkgmtime32 -_mkgmtime64 -_mktemp -_mktemp_s -_mktime32 -_mktime64 -_msize -_msize_debug -_nextafter -_onexit -_open -_open_osfhandle -_osplatform -_osver -_outp -_outpd -_outpw -_pclose -_pctype -_pgmptr -_pipe -_popen -_printf_l -_printf_p -_printf_p_l -_printf_s_l -_purecall -_putch -_putenv -_putenv_s -_putw -_putwch -_putws -_pwctype -_read -_realloc_dbg -_resetstkoflw -_rmdir -_rmtmp -_rotl -_rotl64 -_rotr -_rotr64 -_safe_fdiv -_safe_fdivr -_safe_fprem -_safe_fprem1 -_scalb -_scanf_l -_scanf_s_l -_scprintf -_scprintf_l -_scprintf_p_l -_scwprintf -_scwprintf_l -_scwprintf_p_l -_searchenv -_searchenv_s -_seh_longjmp_unwind -_seh_longjmp_unwind4 -_set_SSE2_enable -_set_controlfp -_set_doserrno -_set_errno -_set_error_mode -_set_fileinfo -_set_fmode -_set_output_format -_set_sbh_threshold -_seterrormode -_setjmp -_setjmp3 -_setmaxstdio -_setmbcp -_setmode -_setsystime -_sleep -_snprintf -_snprintf_c -_snprintf_c_l -_snprintf_l -_snprintf_s -_snprintf_s_l -_snscanf -_snscanf_l -_snscanf_s -_snscanf_s_l -_snwprintf -_snwprintf_l -_snwprintf_s -_snwprintf_s_l -_snwscanf -_snwscanf_l -_snwscanf_s -_snwscanf_s_l -_sopen -_sopen_s -_spawnl -_spawnle -_spawnlp -_spawnlpe -_spawnv -_spawnve -_spawnvp -_spawnvpe -_splitpath -_splitpath_s -_sprintf_l -_sprintf_p_l -_sprintf_s_l -_sscanf_l -_sscanf_s_l -_stat -_stat64 -_stati64 -_statusfp -_strcmpi -_strcoll_l -_strdate -_strdate_s -_strdup -_strdup_dbg -_strerror -_strerror_s -_stricmp -_stricmp_l -_stricoll -_stricoll_l -_strlwr -_strlwr_l -_strlwr_s -_strlwr_s_l -_strncoll -_strncoll_l -_strnicmp -_strnicmp_l -_strnicoll -_strnicoll_l -_strnset -_strnset_s -_strrev -_strset -_strset_s -_strtime -_strtime_s -_strtod_l -_strtoi64 -_strtoi64_l -_strtol_l -_strtoui64 -_strtoui64_l -_strtoul_l -_strupr -_strupr_l -_strupr_s -_strupr_s_l -_strxfrm_l -_swab -_swprintf -_swprintf_c -_swprintf_c_l -_swprintf_p_l -_swprintf_s_l -_swscanf_l -_swscanf_s_l -_sys_errlist -_sys_nerr -_tell -_telli64 -_tempnam -_tempnam_dbg -_time32 -_time64 -_timezone -_tolower -_tolower_l -_toupper -_toupper_l -_towlower_l -_towupper_l -_tzname -_tzset -_ui64toa -_ui64toa_s -_ui64tow -_ui64tow_s -_ultoa -_ultoa_s -_ultow -_ultow_s -_umask -_umask_s -_ungetch -_ungetwch -_unlink -_unloaddll -_unlock -_utime -_utime32 -_utime64 -_vcprintf -_vcprintf_l -_vcprintf_p -_vcprintf_p_l -_vcprintf_s -_vcprintf_s_l -_vcwprintf -_vcwprintf_l -_vcwprintf_p -_vcwprintf_p_l -_vcwprintf_s -_vcwprintf_s_l -_vfprintf_l -_vfprintf_p -_vfprintf_p_l -_vfprintf_s_l -_vfwprintf_l -_vfwprintf_p -_vfwprintf_p_l -_vfwprintf_s_l -_vprintf_l -_vprintf_p -_vprintf_p_l -_vprintf_s_l -_vscprintf -_vscprintf_l -_vscprintf_p_l -_vscwprintf -_vscwprintf_l -_vscwprintf_p_l -_vsnprintf -_vsnprintf_c -_vsnprintf_c_l -_vsnprintf_l -_vsnprintf_s -_vsnprintf_s_l -_vsnwprintf -_vsnwprintf_l -_vsnwprintf_s -_vsnwprintf_s_l -_vsprintf_l -_vsprintf_p -_vsprintf_p_l -_vsprintf_s_l -_vswprintf -_vswprintf_c -_vswprintf_c_l -_vswprintf_l -_vswprintf_p_l -_vswprintf_s_l -_vwprintf_l -_vwprintf_p -_vwprintf_p_l -_vwprintf_s_l -_waccess -_waccess_s -_wasctime -_wasctime_s -_wassert -_wchdir -_wchmod -_wcmdln -_wcreat -_wcscoll_l -_wcsdup -_wcsdup_dbg -_wcserror -_wcserror_s -_wcsftime_l -_wcsicmp -_wcsicmp_l -_wcsicoll -_wcsicoll_l -_wcslwr -_wcslwr_l -_wcslwr_s -_wcslwr_s_l -_wcsncoll -_wcsncoll_l -_wcsnicmp -_wcsnicmp_l -_wcsnicoll -_wcsnicoll_l -_wcsnset -_wcsnset_s -_wcsrev -_wcsset -_wcsset_s -_wcstoi64 -_wcstoi64_l -_wcstol_l -_wcstombs_l -_wcstombs_s_l -_wcstoui64 -_wcstoui64_l -_wcstoul_l -_wcsupr -_wcsupr_l -_wcsupr_s -_wcsupr_s_l -_wcsxfrm_l -_wctime -_wctime32 -_wctime32_s -_wctime64 -_wctime64_s -_wctomb_l -_wctomb_s_l -_wctype -_wenviron -_wexecl -_wexecle -_wexeclp -_wexeclpe -_wexecv -_wexecve -_wexecvp -_wexecvpe -_wfdopen -_wfindfirst -_wfindfirst64 -_wfindfirsti64 -_wfindnext -_wfindnext64 -_wfindnexti64 -_wfopen -_wfopen_s -_wfreopen -_wfreopen_s -_wfsopen -_wfullpath -_wfullpath_dbg -_wgetcwd -_wgetdcwd -_wgetenv -_wgetenv_s -_winmajor -_winminor -_winput_s -_winver -_wmakepath -_wmakepath_s -_wmkdir -_wmktemp -_wmktemp_s -_wopen -_woutput_s -_wperror -_wpgmptr -_wpopen -_wprintf_l -_wprintf_p -_wprintf_p_l -_wprintf_s_l -_wputenv -_wputenv_s -_wremove -_wrename -_write -_wrmdir -_wscanf_l -_wscanf_s_l -_wsearchenv -_wsearchenv_s -_wsetlocale -_wsopen -_wsopen_s -_wspawnl -_wspawnle -_wspawnlp -_wspawnlpe -_wspawnv -_wspawnve -_wspawnvp -_wspawnvpe -_wsplitpath -_wsplitpath_s -_wstat -_wstat64 -_wstati64 -_wstrdate -_wstrdate_s -_wstrtime -_wstrtime_s -_wsystem -_wtempnam -_wtempnam_dbg -_wtmpnam -_wtmpnam_s -_wtof -_wtof_l -_wtoi -_wtoi64 -_wtoi64_l -_wtoi_l -_wtol -_wtol_l -_wunlink -_wutime -_wutime32 -_wutime64 -_y0 -_y1 -_yn -abort -abs -acos -asctime -asctime_s -asin -atan -atan2 -atexit -atof -atoi -atol -bsearch -bsearch_s -btowc -calloc -ceil -clearerr -clearerr_s -clock -cos -cosh -ctime -difftime -div -exit -exp -fabs -fclose -feof -ferror -fflush -fgetc -fgetpos -fgets -fgetwc -fgetws -floor -fmod -fopen -fopen_s -fprintf -fprintf_s -fputc -fputs -fputwc -fputws -fread -free -freopen -freopen_s -frexp -fscanf -fscanf_s -fseek -fsetpos -ftell -fwprintf -fwprintf_s -fwrite -fwscanf -fwscanf_s -getc -getchar -getenv -getenv_s -gets -getwc -getwchar -gmtime -is_wctype -isalnum -isalpha -iscntrl -isdigit -isgraph -isleadbyte -islower -isprint -ispunct -isspace -isupper -iswalnum -iswalpha -iswascii -iswcntrl -iswctype -iswdigit -iswgraph -iswlower -iswprint -iswpunct -iswspace -iswupper -iswxdigit -isxdigit -labs -ldexp -ldiv -localeconv -localtime -log -log10 -longjmp -malloc -mblen -mbrlen -mbrtowc -mbsdup_dbg -mbsrtowcs -mbsrtowcs_s -mbstowcs -mbstowcs_s -mbtowc -memchr -memcmp -memcpy -memcpy_s -memmove -memmove_s -memset -mktime -modf -perror -pow -printf -printf_s -putc -putchar -puts -putwc -putwchar -qsort -qsort_s -raise -rand -rand_s -realloc -remove -rename -rewind -scanf -scanf_s -setbuf -setlocale -setvbuf -signal -sin -sinh -sprintf -sprintf_s -sqrt -srand -sscanf -sscanf_s -strcat -strcat_s -strchr -strcmp -strcoll -strcpy -strcpy_s -strcspn -strerror -strerror_s -strftime -strlen -strncat -strncat_s -strncmp -strncpy -strncpy_s -strnlen -strpbrk -strrchr -strspn -strstr -strtod -strtok -strtok_s -strtol -strtoul -strxfrm -swprintf -swprintf_s -swscanf -swscanf_s -system -tan -tanh -time -tmpfile -tmpfile_s -tmpnam -tmpnam_s -tolower -toupper -towlower -towupper -ungetc -ungetwc -utime -vfprintf -vfprintf_s -vfwprintf -vfwprintf_s -vprintf -vprintf_s -vsnprintf -vsprintf -vsprintf_s -vswprintf -vswprintf_s -vwprintf -vwprintf_s -wcrtomb -wcrtomb_s -wcscat -wcscat_s -wcschr -wcscmp -wcscoll -wcscpy -wcscpy_s -wcscspn -wcsftime -wcslen -wcsncat -wcsncat_s -wcsncmp -wcsncpy -wcsncpy_s -wcsnlen -wcspbrk -wcsrchr -wcsrtombs -wcsrtombs_s -wcsspn -wcsstr -wcstod -wcstok -wcstok_s -wcstol -wcstombs -wcstombs_s -wcstoul -wcsxfrm -wctob -wctomb -wctomb_s -wprintf -wprintf_s -wscanf -wscanf_s diff --git a/05/tcc-final-old/win32/lib/user32.def b/05/tcc-final-old/win32/lib/user32.def deleted file mode 100644 index a034dac..0000000 --- a/05/tcc-final-old/win32/lib/user32.def +++ /dev/null @@ -1,658 +0,0 @@ -LIBRARY user32.dll - -EXPORTS -ActivateKeyboardLayout -AdjustWindowRect -AdjustWindowRectEx -AlignRects -AllowSetForegroundWindow -AnimateWindow -AnyPopup -AppendMenuA -AppendMenuW -ArrangeIconicWindows -AttachThreadInput -BeginDeferWindowPos -BeginPaint -BlockInput -BringWindowToTop -BroadcastSystemMessage -BroadcastSystemMessageA -BroadcastSystemMessageW -CalcChildScroll -CallMsgFilter -CallMsgFilterA -CallMsgFilterW -CallNextHookEx -CallWindowProcA -CallWindowProcW -CascadeChildWindows -CascadeWindows -ChangeClipboardChain -ChangeDisplaySettingsA -ChangeDisplaySettingsExA -ChangeDisplaySettingsExW -ChangeDisplaySettingsW -ChangeMenuA -ChangeMenuW -CharLowerA -CharLowerBuffA -CharLowerBuffW -CharLowerW -CharNextA -CharNextExA -CharNextExW -CharNextW -CharPrevA -CharPrevExA -CharPrevExW -CharPrevW -CharToOemA -CharToOemBuffA -CharToOemBuffW -CharToOemW -CharUpperA -CharUpperBuffA -CharUpperBuffW -CharUpperW -CheckDlgButton -CheckMenuItem -CheckMenuRadioItem -CheckRadioButton -ChildWindowFromPoint -ChildWindowFromPointEx -ClientThreadConnect -ClientToScreen -ClipCursor -CloseClipboard -CloseDesktop -CloseWindow -CloseWindowStation -CopyAcceleratorTableA -CopyAcceleratorTableW -CopyIcon -CopyImage -CopyRect -CountClipboardFormats -CreateAcceleratorTableA -CreateAcceleratorTableW -CreateCaret -CreateCursor -CreateDesktopA -CreateDesktopW -CreateDialogIndirectParamA -CreateDialogIndirectParamW -CreateDialogParamA -CreateDialogParamW -CreateIcon -CreateIconFromResource -CreateIconFromResourceEx -CreateIconIndirect -CreateMDIWindowA -CreateMDIWindowW -CreateMenu -CreatePopupMenu -CreateWindowExA -CreateWindowExW -CreateWindowStationA -CreateWindowStationW -DdeAbandonTransaction -DdeAccessData -DdeAddData -DdeClientTransaction -DdeCmpStringHandles -DdeConnect -DdeConnectList -DdeCreateDataHandle -DdeCreateStringHandleA -DdeCreateStringHandleW -DdeDisconnect -DdeDisconnectList -DdeEnableCallback -DdeFreeDataHandle -DdeFreeStringHandle -DdeGetData -DdeGetLastError -DdeImpersonateClient -DdeInitializeA -DdeInitializeW -DdeKeepStringHandle -DdeNameService -DdePostAdvise -DdeQueryConvInfo -DdeQueryNextServer -DdeQueryStringA -DdeQueryStringW -DdeReconnect -DdeSetQualityOfService -DdeSetUserHandle -DdeUnaccessData -DdeUninitialize -DefDlgProcA -DefDlgProcW -DefFrameProcA -DefFrameProcW -DefMDIChildProcA -DefMDIChildProcW -DefWindowProcA -DefWindowProcW -DeferWindowPos -DeleteMenu -DestroyAcceleratorTable -DestroyCaret -DestroyCursor -DestroyIcon -DestroyMenu -DestroyWindow -DialogBoxIndirectParamA -DialogBoxIndirectParamW -DialogBoxParamA -DialogBoxParamW -DispatchMessageA -DispatchMessageW -DlgDirListA -DlgDirListComboBoxA -DlgDirListComboBoxW -DlgDirListW -DlgDirSelectComboBoxExA -DlgDirSelectComboBoxExW -DlgDirSelectExA -DlgDirSelectExW -DragDetect -DragObject -DrawAnimatedRects -DrawCaption -DrawCaptionTempA -DrawCaptionTempW -DrawEdge -DrawFocusRect -DrawFrame -DrawFrameControl -DrawIcon -DrawIconEx -DrawMenuBar -DrawMenuBarTemp -DrawStateA -DrawStateW -DrawTextA -DrawTextExA -DrawTextExW -DrawTextW -EditWndProc -EmptyClipboard -EnableMenuItem -EnableScrollBar -EnableWindow -EndDeferWindowPos -EndDialog -EndMenu -EndPaint -EndTask -EnumChildWindows -EnumClipboardFormats -EnumDesktopWindows -EnumDesktopsA -EnumDesktopsW -EnumDisplayDevicesA -EnumDisplayDevicesW -EnumDisplayMonitors -EnumDisplaySettingsA -EnumDisplaySettingsExA -EnumDisplaySettingsExW -EnumDisplaySettingsW -EnumPropsA -EnumPropsExA -EnumPropsExW -EnumPropsW -EnumThreadWindows -EnumWindowStationsA -EnumWindowStationsW -EnumWindows -EqualRect -ExcludeUpdateRgn -ExitWindowsEx -FillRect -FindWindowA -FindWindowExA -FindWindowExW -FindWindowW -FlashWindow -FlashWindowEx -FrameRect -FreeDDElParam -GetActiveWindow -GetAltTabInfo -GetAncestor -GetAsyncKeyState -GetCapture -GetCaretBlinkTime -GetCaretPos -GetClassInfoA -GetClassInfoExA -GetClassInfoExW -GetClassInfoW -GetClassLongA -GetClassLongW -GetClassNameA -GetClassNameW -GetClassWord -GetClientRect -GetClipCursor -GetClipboardData -GetClipboardFormatNameA -GetClipboardFormatNameW -GetClipboardOwner -GetClipboardSequenceNumber -GetClipboardViewer -GetComboBoxInfo -GetCursor -GetCursorInfo -GetCursorPos -GetDC -GetDCEx -GetDesktopWindow -GetDialogBaseUnits -GetDlgCtrlID -GetDlgItem -GetDlgItemInt -GetDlgItemTextA -GetDlgItemTextW -GetDoubleClickTime -GetFocus -GetForegroundWindow -GetGUIThreadInfo -GetGuiResources -GetIconInfo -GetInputDesktop -GetInputState -GetInternalWindowPos -GetKBCodePage -GetKeyNameTextA -GetKeyNameTextW -GetKeyState -GetKeyboardLayout -GetKeyboardLayoutList -GetKeyboardLayoutNameA -GetKeyboardLayoutNameW -GetKeyboardState -GetKeyboardType -GetLastActivePopup -GetListBoxInfo -GetMenu -GetMenuBarInfo -GetMenuCheckMarkDimensions -GetMenuContextHelpId -GetMenuDefaultItem -GetMenuInfo -GetMenuItemCount -GetMenuItemID -GetMenuItemInfoA -GetMenuItemInfoW -GetMenuItemRect -GetMenuState -GetMenuStringA -GetMenuStringW -GetMessageA -GetMessageExtraInfo -GetMessagePos -GetMessageTime -GetMessageW -GetMonitorInfoA -GetMonitorInfoW -GetMouseMovePoints -GetMouseMovePointsEx -GetNextDlgGroupItem -GetNextDlgTabItem -GetNextQueueWindow -GetOpenClipboardWindow -GetParent -GetPriorityClipboardFormat -GetProcessDefaultLayout -GetProcessWindowStation -GetPropA -GetPropW -GetQueueStatus -GetScrollBarInfo -GetScrollInfo -GetScrollPos -GetScrollRange -GetShellWindow -GetSubMenu -GetSysColor -GetSysColorBrush -GetSystemMenu -GetSystemMetrics -GetTabbedTextExtentA -GetTabbedTextExtentW -GetThreadDesktop -GetTitleBarInfo -GetTopWindow -GetUpdateRect -GetUpdateRgn -GetUserObjectInformationA -GetUserObjectInformationW -GetUserObjectSecurity -GetWindow -GetWindowContextHelpId -GetWindowDC -GetWindowInfo -GetWindowLongPtrA -GetWindowLongPtrW -SetWindowLongPtrA -SetWindowLongPtrW -GetWindowLongA -GetWindowLongW -GetWindowModuleFileNameA -GetWindowModuleFileNameW -GetWindowPlacement -GetWindowRect -GetWindowRgn -GetWindowTextA -GetWindowTextLengthA -GetWindowTextLengthW -GetWindowTextW -GetWindowThreadProcessId -GetWindowWord -GrayStringA -GrayStringW -HasSystemSleepStarted -HideCaret -HiliteMenuItem -IMPGetIMEA -IMPGetIMEW -IMPQueryIMEA -IMPQueryIMEW -IMPSetIMEA -IMPSetIMEW -ImpersonateDdeClientWindow -InSendMessage -InSendMessageEx -InflateRect -InitSharedTable -InitTask -InsertMenuA -InsertMenuItemA -InsertMenuItemW -InsertMenuW -InternalGetWindowText -IntersectRect -InvalidateRect -InvalidateRgn -InvertRect -IsCharAlphaA -IsCharAlphaNumericA -IsCharAlphaNumericW -IsCharAlphaW -IsCharLowerA -IsCharLowerW -IsCharUpperA -IsCharUpperW -IsChild -IsClipboardFormatAvailable -IsDialogMessage -IsDialogMessageA -IsDialogMessageW -IsDlgButtonChecked -IsHungThread -IsIconic -IsMenu -IsRectEmpty -IsWindow -IsWindowEnabled -IsWindowUnicode -IsWindowVisible -IsZoomed -KillTimer -LoadAcceleratorsA -LoadAcceleratorsW -LoadBitmapA -LoadBitmapW -LoadCursorA -LoadCursorFromFileA -LoadCursorFromFileW -LoadCursorW -LoadIconA -LoadIconW -LoadImageA -LoadImageW -LoadKeyboardLayoutA -LoadKeyboardLayoutW -LoadMenuA -LoadMenuIndirectA -LoadMenuIndirectW -LoadMenuW -LoadStringA -LoadStringW -LockSetForegroundWindow -LockWindowStation -LockWindowUpdate -LookupIconIdFromDirectory -LookupIconIdFromDirectoryEx -MapDialogRect -MapVirtualKeyA -MapVirtualKeyExA -MapVirtualKeyExW -MapVirtualKeyW -MapWindowPoints -MenuItemFromPoint -MessageBeep -MessageBoxA -MessageBoxExA -MessageBoxExW -MessageBoxIndirectA -MessageBoxIndirectW -MessageBoxW -ModifyAccess -ModifyMenuA -ModifyMenuW -MonitorFromPoint -MonitorFromRect -MonitorFromWindow -MoveWindow -MsgWaitForMultipleObjects -MsgWaitForMultipleObjectsEx -NotifyWinEvent -OemKeyScan -OemToCharA -OemToCharBuffA -OemToCharBuffW -OemToCharW -OffsetRect -OpenClipboard -OpenDesktopA -OpenDesktopW -OpenIcon -OpenInputDesktop -OpenWindowStationA -OpenWindowStationW -PackDDElParam -PaintDesktop -PeekMessageA -PeekMessageW -PlaySoundEvent -PostMessageA -PostMessageW -PostQuitMessage -PostThreadMessageA -PostThreadMessageW -PtInRect -RealChildWindowFromPoint -RealGetWindowClass -RedrawWindow -RegisterClassA -RegisterClassExA -RegisterClassExW -RegisterClassW -RegisterClipboardFormatA -RegisterClipboardFormatW -RegisterDeviceNotificationA -RegisterDeviceNotificationW -RegisterHotKey -RegisterLogonProcess -RegisterNetworkCapabilities -RegisterSystemThread -RegisterTasklist -RegisterWindowMessageA -RegisterWindowMessageW -ReleaseCapture -ReleaseDC -RemoveMenu -RemovePropA -RemovePropW -ReplyMessage -ReuseDDElParam -ScreenToClient -ScrollDC -ScrollWindow -ScrollWindowEx -SendDlgItemMessageA -SendDlgItemMessageW -SendIMEMessageExA -SendIMEMessageExW -SendInput -SendMessageA -SendMessageCallbackA -SendMessageCallbackW -SendMessageTimeoutA -SendMessageTimeoutW -SendMessageW -SendNotifyMessageA -SendNotifyMessageW -SetActiveWindow -SetCapture -SetCaretBlinkTime -SetCaretPos -SetClassLongA -SetClassLongW -SetClassWord -SetClipboardData -SetClipboardViewer -SetCursor -SetCursorPos -SetDebugErrorLevel -SetDeskWallpaper -SetDesktopBitmap -SetDlgItemInt -SetDlgItemTextA -SetDlgItemTextW -SetDoubleClickTime -SetFocus -SetForegroundWindow -SetInternalWindowPos -SetKeyboardState -SetLastErrorEx -SetLogonNotifyWindow -SetMenu -SetMenuContextHelpId -SetMenuDefaultItem -SetMenuInfo -SetMenuItemBitmaps -SetMenuItemInfoA -SetMenuItemInfoW -SetMessageExtraInfo -SetMessageQueue -SetParent -SetProcessDefaultLayout -SetProcessWindowStation -SetPropA -SetPropW -SetRect -SetRectEmpty -SetScrollInfo -SetScrollPos -SetScrollRange -SetShellWindow -SetSysColors -SetSysColorsTemp -SetSystemCursor -SetThreadDesktop -SetTimer -SetUserObjectInformationA -SetUserObjectInformationW -SetUserObjectSecurity -SetWinEventHook -SetWindowContextHelpId -SetWindowFullScreenState -SetWindowLongA -SetWindowLongW -SetWindowPlacement -SetWindowPos -SetWindowRgn -SetWindowTextA -SetWindowTextW -SetWindowWord -SetWindowsHookA -SetWindowsHookExA -SetWindowsHookExW -SetWindowsHookW -ShowCaret -ShowCursor -ShowOwnedPopups -ShowScrollBar -ShowWindow -ShowWindowAsync -SubtractRect -SwapMouseButton -SwitchDesktop -SwitchToThisWindow -SysErrorBox -SystemParametersInfoA -SystemParametersInfoW -TabbedTextOutA -TabbedTextOutW -TileChildWindows -TileWindows -ToAscii -ToAsciiEx -ToUnicode -ToUnicodeEx -TrackMouseEvent -TrackPopupMenu -TrackPopupMenuEx -TranslateAccelerator -TranslateAcceleratorA -TranslateAcceleratorW -TranslateMDISysAccel -TranslateMessage -UnhookWinEvent -UnhookWindowsHook -UnhookWindowsHookEx -UnionRect -UnloadKeyboardLayout -UnlockWindowStation -UnpackDDElParam -UnregisterClassA -UnregisterClassW -UnregisterDeviceNotification -UnregisterHotKey -UpdateWindow -UserClientDllInitialize -UserIsSystemResumeAutomatic -UserSetDeviceHoldState -UserSignalProc -UserTickleTimer -ValidateRect -ValidateRgn -VkKeyScanA -VkKeyScanExA -VkKeyScanExW -VkKeyScanW -WINNLSEnableIME -WINNLSGetEnableStatus -WINNLSGetIMEHotkey -WNDPROC_CALLBACK -WaitForInputIdle -WaitMessage -WinHelpA -WinHelpW -WinOldAppHackoMatic -WindowFromDC -WindowFromPoint -YieldTask -_SetProcessDefaultLayout -keybd_event -mouse_event -wsprintfA -wsprintfW -wvsprintfA -wvsprintfW diff --git a/05/tcc-final-old/win32/lib/wincrt1.c b/05/tcc-final-old/win32/lib/wincrt1.c deleted file mode 100644 index ce3a63f..0000000 --- a/05/tcc-final-old/win32/lib/wincrt1.c +++ /dev/null @@ -1,75 +0,0 @@ -//+--------------------------------------------------------------------------- - -// _UNICODE for tchar.h, UNICODE for API -#include - -#include -#include - -#define __UNKNOWN_APP 0 -#define __CONSOLE_APP 1 -#define __GUI_APP 2 -void __set_app_type(int); -void _controlfp(unsigned a, unsigned b); - -#ifdef _UNICODE -#define __tgetmainargs __wgetmainargs -#define _twinstart _wwinstart -#define _runtwinmain _runwwinmain -int APIENTRY wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int); -#else -#define __tgetmainargs __getmainargs -#define _twinstart _winstart -#define _runtwinmain _runwinmain -#endif - -typedef struct { int newmode; } _startupinfo; -int __cdecl __tgetmainargs(int *pargc, _TCHAR ***pargv, _TCHAR ***penv, int globb, _startupinfo*); - -static int go_winmain(TCHAR *arg1) -{ - STARTUPINFO si; - _TCHAR *szCmd, *p; - int fShow; - - GetStartupInfo(&si); - if (si.dwFlags & STARTF_USESHOWWINDOW) - fShow = si.wShowWindow; - else - fShow = SW_SHOWDEFAULT; - - szCmd = NULL, p = GetCommandLine(); - if (arg1) - szCmd = _tcsstr(p, arg1); - if (NULL == szCmd) - szCmd = _tcsdup(__T("")); - else if (szCmd > p && szCmd[-1] == __T('"')) - --szCmd; -#if defined __i386__ || defined __x86_64__ - _controlfp(0x10000, 0x30000); -#endif - return _tWinMain(GetModuleHandle(NULL), NULL, szCmd, fShow); -} - -int _twinstart(void) -{ - __TRY__ - _startupinfo start_info_con = {0}; - __set_app_type(__GUI_APP); - __tgetmainargs(&__argc, &__targv, &_tenviron, 0, &start_info_con); - exit(go_winmain(__argc > 1 ? __targv[1] : NULL)); -} - -int _runtwinmain(int argc, /* as tcc passed in */ char **argv) -{ -#ifdef UNICODE - _startupinfo start_info = {0}; - __tgetmainargs(&__argc, &__targv, &_tenviron, 0, &start_info); - /* may be wrong when tcc has received wildcards (*.c) */ - if (argc < __argc) - __targv += __argc - argc, __argc = argc; -#else - __argc = argc, __targv = argv; -#endif - return go_winmain(__argc > 1 ? __targv[1] : NULL); -} diff --git a/05/tcc-final-old/win32/lib/wincrt1w.c b/05/tcc-final-old/win32/lib/wincrt1w.c deleted file mode 100644 index a7d349e..0000000 --- a/05/tcc-final-old/win32/lib/wincrt1w.c +++ /dev/null @@ -1,3 +0,0 @@ -#define _UNICODE 1 -#define UNICODE 1 -#include "wincrt1.c" diff --git a/05/tcc-final-old/win32/tcc-win32.txt b/05/tcc-final-old/win32/tcc-win32.txt deleted file mode 100644 index ab73007..0000000 --- a/05/tcc-final-old/win32/tcc-win32.txt +++ /dev/null @@ -1,168 +0,0 @@ - - TinyCC - ====== - - This file contains specific information for usage of TinyCC - under MS-Windows. See tcc-doc.html to have all the features. - - - Installation from the binary ZIP package: - ----------------------------------------- - Unzip the package to a directory of your choice. - - - Set the system PATH: - -------------------- - To be able to invoke the compiler from everywhere on your computer by - just typing "tcc", please add the directory containing tcc.exe to your - system PATH. - - - Include and library search paths - -------------------------------- - On windows, the standard "include" and "lib" directories are searched - relatively from the location of the executables (tcc.exe, libtcc.dll). - - - Examples: - --------- - Open a console window (DOS box) and 'cd' to the examples directory. - - For the 'Fibonacci' example type: - - tcc fib.c - - For the 'Hello Windows' GUI example type: - - tcc hello_win.c - - For the 'Hello DLL' example type - - tcc -shared dll.c - tcc -impdef dll.dll (optional) - tcc hello_dll.c dll.def - - - Using libtcc as JIT compiler in your program - -------------------------------------------- - Check out the 'libtcc_test' example: - - - Running it from source: - tcc -I libtcc libtcc/libtcc.def -run examples/libtcc_test.c - - - Compiling with TCC: - tcc examples/libtcc_test.c -I libtcc libtcc/libtcc.def - - - Compiling with MinGW: - gcc examples/libtcc_test.c -I libtcc libtcc.dll -o libtcc_test.exe - - - Compiling with MSVC: - lib /def:libtcc\libtcc.def /out:libtcc.lib - cl /MD examples/libtcc_test.c -I libtcc libtcc.lib - - - Import Definition Files: - ------------------------ - To link with Windows system DLLs, TCC uses import definition - files (.def) instead of libraries. - - The now built-in 'tiny_impdef' program may be used to make - additional .def files for any DLL. For example - - tcc -impdef [-v] opengl32.dll [-o opengl32.def] - - Put opengl32.def into the tcc/lib directory. Specify -lopengl32 at - the TCC commandline to link a program that uses opengl32.dll. - - - Header Files: - ------------- - The system header files (except _mingw.h) are from the MinGW - distribution: - - http://www.mingw.org/ - - From the windows headers, only a minimal set is included. If you need - more, get MinGW's "w32api" package. Extract the files from "include" - into your "tcc/include/winapi" directory. - - - Resource Files: - --------------- - TCC can link windows resources in coff format as generated by MinGW's - windres.exe. For example: - - windres -O coff app.rc -o appres.o - tcc app.c appres.o -o app.exe - - - Tiny Libmaker: - -------------- - The now built-in tiny_libmaker tool by Timovj Lahde can be used as - 'ar' replacement to make a library from several object files: - - tcc -ar [rcsv] library objectfiles ... - - - Compilation from source: - ------------------------ - * You can use the MinGW and MSYS tools available at - http://www.mingw.org - http://www.mingw-w64.org - http://www.msys2.org - - Untar the TCC archive and type in the MSYS shell: - ./configure [--prefix installpath] - make - make install - - The default install location is c:\Program Files\tcc - - Cygwin can be used too with its mingw cross-compiler installed: - ./configure --cross-prefix=i686-w64-mingw32- - (the prefix may vary) - - * Alternatively you can compile TCC with just GCC from MinGW using - > build-tcc.bat (from the win32 directory) - - Also MSVC can be used with the "VSTools Developer Command Prompt": - > build-tcc.bat -c cl - - or with an existing tcc (needs to be in a different directory) - > build-tcc.bat -c some-tcc-dir\tcc.exe - - Also you can copy/install everything into another directory: - > build-tcc.bat -i - - Limitations: - ------------ - - On the object file level, currently TCC supports only the ELF format, - not COFF as used by MinGW and MSVC. It is not possible to exchange - object files or libraries between TCC and these compilers. - - However libraries for TCC from objects by TCC can be made using - tcc -ar lib.a files.o ,,, - - - No leading underscore is generated in the ELF symbols. - - Documentation and License: - -------------------------- - TCC is distributed under the GNU Lesser General Public License. (See - COPYING file or http://www.gnu.org/licenses/lgpl-2.1.html) - - TinyCC homepage is at: - - http://fabrice.bellard.free.fr/tcc/ - - - WinAPI Help and 3rd-party tools: - -------------------------------- - The Windows API documentation (Win95) in a single .hlp file is - available on the lcc-win32 site as "win32hlp.exe" or from other - locations as "win32hlp_big.zip". - - A nice RAD tool to create windows resources (dialog boxes etc.) is - "ResEd", available at the RadASM website. - - - --- grischka diff --git a/05/tcc-final-old/x86_64-asm.h b/05/tcc-final-old/x86_64-asm.h deleted file mode 100644 index cb9eb16..0000000 --- a/05/tcc-final-old/x86_64-asm.h +++ /dev/null @@ -1,525 +0,0 @@ - DEF_ASM_OP0(clc, 0xf8) /* must be first OP0 */ - DEF_ASM_OP0(cld, 0xfc) - DEF_ASM_OP0(cli, 0xfa) - DEF_ASM_OP0(clts, 0x0f06) - DEF_ASM_OP0(cmc, 0xf5) - DEF_ASM_OP0(lahf, 0x9f) - DEF_ASM_OP0(sahf, 0x9e) - DEF_ASM_OP0(pushfq, 0x9c) - DEF_ASM_OP0(popfq, 0x9d) - DEF_ASM_OP0(pushf, 0x9c) - DEF_ASM_OP0(popf, 0x9d) - DEF_ASM_OP0(stc, 0xf9) - DEF_ASM_OP0(std, 0xfd) - DEF_ASM_OP0(sti, 0xfb) - DEF_ASM_OP0(aaa, 0x37) - DEF_ASM_OP0(aas, 0x3f) - DEF_ASM_OP0(daa, 0x27) - DEF_ASM_OP0(das, 0x2f) - DEF_ASM_OP0(aad, 0xd50a) - DEF_ASM_OP0(aam, 0xd40a) - DEF_ASM_OP0(cbw, 0x6698) - DEF_ASM_OP0(cwd, 0x6699) - DEF_ASM_OP0(cwde, 0x98) - DEF_ASM_OP0(cdq, 0x99) - DEF_ASM_OP0(cbtw, 0x6698) - DEF_ASM_OP0(cwtl, 0x98) - DEF_ASM_OP0(cwtd, 0x6699) - DEF_ASM_OP0(cltd, 0x99) - DEF_ASM_OP0(cqto, 0x4899) - DEF_ASM_OP0(int3, 0xcc) - DEF_ASM_OP0(into, 0xce) - DEF_ASM_OP0(iret, 0xcf) - DEF_ASM_OP0(rsm, 0x0faa) - DEF_ASM_OP0(hlt, 0xf4) - DEF_ASM_OP0(wait, 0x9b) - DEF_ASM_OP0(nop, 0x90) - DEF_ASM_OP0(pause, 0xf390) - DEF_ASM_OP0(xlat, 0xd7) - - /* strings */ -ALT(DEF_ASM_OP0L(cmpsb, 0xa6, 0, OPC_BWLX)) -ALT(DEF_ASM_OP0L(scmpb, 0xa6, 0, OPC_BWLX)) - -ALT(DEF_ASM_OP0L(insb, 0x6c, 0, OPC_BWL)) -ALT(DEF_ASM_OP0L(outsb, 0x6e, 0, OPC_BWL)) - -ALT(DEF_ASM_OP0L(lodsb, 0xac, 0, OPC_BWLX)) -ALT(DEF_ASM_OP0L(slodb, 0xac, 0, OPC_BWLX)) - -ALT(DEF_ASM_OP0L(movsb, 0xa4, 0, OPC_BWLX)) -ALT(DEF_ASM_OP0L(smovb, 0xa4, 0, OPC_BWLX)) - -ALT(DEF_ASM_OP0L(scasb, 0xae, 0, OPC_BWLX)) -ALT(DEF_ASM_OP0L(sscab, 0xae, 0, OPC_BWLX)) - -ALT(DEF_ASM_OP0L(stosb, 0xaa, 0, OPC_BWLX)) -ALT(DEF_ASM_OP0L(sstob, 0xaa, 0, OPC_BWLX)) - - /* bits */ - -ALT(DEF_ASM_OP2(bsfw, 0x0fbc, 0, OPC_MODRM | OPC_WLX, OPT_REGW | OPT_EA, OPT_REGW)) -ALT(DEF_ASM_OP2(bsrw, 0x0fbd, 0, OPC_MODRM | OPC_WLX, OPT_REGW | OPT_EA, OPT_REGW)) - -ALT(DEF_ASM_OP2(btw, 0x0fa3, 0, OPC_MODRM | OPC_WLX, OPT_REGW, OPT_REGW | OPT_EA)) -ALT(DEF_ASM_OP2(btw, 0x0fba, 4, OPC_MODRM | OPC_WLX, OPT_IM8, OPT_REGW | OPT_EA)) - -ALT(DEF_ASM_OP2(btsw, 0x0fab, 0, OPC_MODRM | OPC_WLX, OPT_REGW, OPT_REGW | OPT_EA)) -ALT(DEF_ASM_OP2(btsw, 0x0fba, 5, OPC_MODRM | OPC_WLX, OPT_IM8, OPT_REGW | OPT_EA)) - -ALT(DEF_ASM_OP2(btrw, 0x0fb3, 0, OPC_MODRM | OPC_WLX, OPT_REGW, OPT_REGW | OPT_EA)) -ALT(DEF_ASM_OP2(btrw, 0x0fba, 6, OPC_MODRM | OPC_WLX, OPT_IM8, OPT_REGW | OPT_EA)) - -ALT(DEF_ASM_OP2(btcw, 0x0fbb, 0, OPC_MODRM | OPC_WLX, OPT_REGW, OPT_REGW | OPT_EA)) -ALT(DEF_ASM_OP2(btcw, 0x0fba, 7, OPC_MODRM | OPC_WLX, OPT_IM8, OPT_REGW | OPT_EA)) - - /* prefixes */ - DEF_ASM_OP0(lock, 0xf0) - DEF_ASM_OP0(rep, 0xf3) - DEF_ASM_OP0(repe, 0xf3) - DEF_ASM_OP0(repz, 0xf3) - DEF_ASM_OP0(repne, 0xf2) - DEF_ASM_OP0(repnz, 0xf2) - - DEF_ASM_OP0(invd, 0x0f08) - DEF_ASM_OP0(wbinvd, 0x0f09) - DEF_ASM_OP0(cpuid, 0x0fa2) - DEF_ASM_OP0(wrmsr, 0x0f30) - DEF_ASM_OP0(rdtsc, 0x0f31) - DEF_ASM_OP0(rdmsr, 0x0f32) - DEF_ASM_OP0(rdpmc, 0x0f33) - - DEF_ASM_OP0(syscall, 0x0f05) - DEF_ASM_OP0(sysret, 0x0f07) - DEF_ASM_OP0L(sysretq, 0x480f07, 0, 0) - DEF_ASM_OP0(ud2, 0x0f0b) - - /* NOTE: we took the same order as gas opcode definition order */ -/* Right now we can't express the fact that 0xa1/0xa3 can't use $eax and a - 32 bit moffset as operands. -ALT(DEF_ASM_OP2(movb, 0xa0, 0, OPC_BWLX, OPT_ADDR, OPT_EAX)) -ALT(DEF_ASM_OP2(movb, 0xa2, 0, OPC_BWLX, OPT_EAX, OPT_ADDR)) */ -ALT(DEF_ASM_OP2(movb, 0x88, 0, OPC_MODRM | OPC_BWLX, OPT_REG, OPT_EA | OPT_REG)) -ALT(DEF_ASM_OP2(movb, 0x8a, 0, OPC_MODRM | OPC_BWLX, OPT_EA | OPT_REG, OPT_REG)) -/* The moves are special: the 0xb8 form supports IM64 (the only insn that - does) with REG64. It doesn't support IM32 with REG64, it would use - the full movabs form (64bit immediate). For IM32->REG64 we prefer - the 0xc7 opcode. So disallow all 64bit forms and code the rest by hand. */ -ALT(DEF_ASM_OP2(movb, 0xb0, 0, OPC_REG | OPC_BWLX, OPT_IM, OPT_REG)) -ALT(DEF_ASM_OP2(mov, 0xb8, 0, OPC_REG, OPT_IM64, OPT_REG64)) -ALT(DEF_ASM_OP2(movq, 0xb8, 0, OPC_REG, OPT_IM64, OPT_REG64)) -ALT(DEF_ASM_OP2(movb, 0xc6, 0, OPC_MODRM | OPC_BWLX, OPT_IM, OPT_REG | OPT_EA)) - -ALT(DEF_ASM_OP2(movw, 0x8c, 0, OPC_MODRM | OPC_WLX, OPT_SEG, OPT_EA | OPT_REG)) -ALT(DEF_ASM_OP2(movw, 0x8e, 0, OPC_MODRM | OPC_WLX, OPT_EA | OPT_REG, OPT_SEG)) - -ALT(DEF_ASM_OP2(movw, 0x0f20, 0, OPC_MODRM | OPC_WLX, OPT_CR, OPT_REG64)) -ALT(DEF_ASM_OP2(movw, 0x0f21, 0, OPC_MODRM | OPC_WLX, OPT_DB, OPT_REG64)) -ALT(DEF_ASM_OP2(movw, 0x0f22, 0, OPC_MODRM | OPC_WLX, OPT_REG64, OPT_CR)) -ALT(DEF_ASM_OP2(movw, 0x0f23, 0, OPC_MODRM | OPC_WLX, OPT_REG64, OPT_DB)) - -ALT(DEF_ASM_OP2(movsbw, 0x660fbe, 0, OPC_MODRM, OPT_REG8 | OPT_EA, OPT_REG16)) -ALT(DEF_ASM_OP2(movsbl, 0x0fbe, 0, OPC_MODRM, OPT_REG8 | OPT_EA, OPT_REG32)) -ALT(DEF_ASM_OP2(movsbq, 0x0fbe, 0, OPC_MODRM, OPT_REG8 | OPT_EA, OPT_REGW)) -ALT(DEF_ASM_OP2(movswl, 0x0fbf, 0, OPC_MODRM, OPT_REG16 | OPT_EA, OPT_REG32)) -ALT(DEF_ASM_OP2(movswq, 0x0fbf, 0, OPC_MODRM, OPT_REG16 | OPT_EA, OPT_REG)) -ALT(DEF_ASM_OP2(movslq, 0x63, 0, OPC_MODRM, OPT_REG32 | OPT_EA, OPT_REG)) -ALT(DEF_ASM_OP2(movzbw, 0x0fb6, 0, OPC_MODRM | OPC_WLX, OPT_REG8 | OPT_EA, OPT_REGW)) -ALT(DEF_ASM_OP2(movzwl, 0x0fb7, 0, OPC_MODRM, OPT_REG16 | OPT_EA, OPT_REG32)) -ALT(DEF_ASM_OP2(movzwq, 0x0fb7, 0, OPC_MODRM, OPT_REG16 | OPT_EA, OPT_REG)) - -ALT(DEF_ASM_OP1(pushq, 0x6a, 0, 0, OPT_IM8S)) -ALT(DEF_ASM_OP1(push, 0x6a, 0, 0, OPT_IM8S)) -ALT(DEF_ASM_OP1(pushw, 0x666a, 0, 0, OPT_IM8S)) -ALT(DEF_ASM_OP1(pushw, 0x50, 0, OPC_REG | OPC_WLX, OPT_REG64)) -ALT(DEF_ASM_OP1(pushw, 0x50, 0, OPC_REG | OPC_WLX, OPT_REG16)) -ALT(DEF_ASM_OP1(pushw, 0xff, 6, OPC_MODRM | OPC_WLX, OPT_REG64 | OPT_EA)) -ALT(DEF_ASM_OP1(pushw, 0x6668, 0, 0, OPT_IM16)) -ALT(DEF_ASM_OP1(pushw, 0x68, 0, OPC_WLX, OPT_IM32)) -ALT(DEF_ASM_OP1(pushw, 0x06, 0, OPC_WLX, OPT_SEG)) - -ALT(DEF_ASM_OP1(popw, 0x58, 0, OPC_REG | OPC_WLX, OPT_REG64)) -ALT(DEF_ASM_OP1(popw, 0x58, 0, OPC_REG | OPC_WLX, OPT_REG16)) -ALT(DEF_ASM_OP1(popw, 0x8f, 0, OPC_MODRM | OPC_WLX, OPT_REGW | OPT_EA)) -ALT(DEF_ASM_OP1(popw, 0x07, 0, OPC_WLX, OPT_SEG)) - -ALT(DEF_ASM_OP2(xchgw, 0x90, 0, OPC_REG | OPC_WLX, OPT_REGW, OPT_EAX)) -ALT(DEF_ASM_OP2(xchgw, 0x90, 0, OPC_REG | OPC_WLX, OPT_EAX, OPT_REGW)) -ALT(DEF_ASM_OP2(xchgb, 0x86, 0, OPC_MODRM | OPC_BWLX, OPT_REG, OPT_EA | OPT_REG)) -ALT(DEF_ASM_OP2(xchgb, 0x86, 0, OPC_MODRM | OPC_BWLX, OPT_EA | OPT_REG, OPT_REG)) - -ALT(DEF_ASM_OP2(inb, 0xe4, 0, OPC_BWL, OPT_IM8, OPT_EAX)) -ALT(DEF_ASM_OP1(inb, 0xe4, 0, OPC_BWL, OPT_IM8)) -ALT(DEF_ASM_OP2(inb, 0xec, 0, OPC_BWL, OPT_DX, OPT_EAX)) -ALT(DEF_ASM_OP1(inb, 0xec, 0, OPC_BWL, OPT_DX)) - -ALT(DEF_ASM_OP2(outb, 0xe6, 0, OPC_BWL, OPT_EAX, OPT_IM8)) -ALT(DEF_ASM_OP1(outb, 0xe6, 0, OPC_BWL, OPT_IM8)) -ALT(DEF_ASM_OP2(outb, 0xee, 0, OPC_BWL, OPT_EAX, OPT_DX)) -ALT(DEF_ASM_OP1(outb, 0xee, 0, OPC_BWL, OPT_DX)) - -ALT(DEF_ASM_OP2(leaw, 0x8d, 0, OPC_MODRM | OPC_WLX, OPT_EA, OPT_REG)) - -ALT(DEF_ASM_OP2(les, 0xc4, 0, OPC_MODRM, OPT_EA, OPT_REG32)) -ALT(DEF_ASM_OP2(lds, 0xc5, 0, OPC_MODRM, OPT_EA, OPT_REG32)) -ALT(DEF_ASM_OP2(lss, 0x0fb2, 0, OPC_MODRM, OPT_EA, OPT_REG32)) -ALT(DEF_ASM_OP2(lfs, 0x0fb4, 0, OPC_MODRM, OPT_EA, OPT_REG32)) -ALT(DEF_ASM_OP2(lgs, 0x0fb5, 0, OPC_MODRM, OPT_EA, OPT_REG32)) - - /* arith */ -ALT(DEF_ASM_OP2(addb, 0x00, 0, OPC_ARITH | OPC_MODRM | OPC_BWLX, OPT_REG, OPT_EA | OPT_REG)) /* XXX: use D bit ? */ -ALT(DEF_ASM_OP2(addb, 0x02, 0, OPC_ARITH | OPC_MODRM | OPC_BWLX, OPT_EA | OPT_REG, OPT_REG)) -ALT(DEF_ASM_OP2(addb, 0x04, 0, OPC_ARITH | OPC_BWLX, OPT_IM, OPT_EAX)) -ALT(DEF_ASM_OP2(addw, 0x83, 0, OPC_ARITH | OPC_MODRM | OPC_WLX, OPT_IM8S, OPT_EA | OPT_REGW)) -ALT(DEF_ASM_OP2(addb, 0x80, 0, OPC_ARITH | OPC_MODRM | OPC_BWLX, OPT_IM, OPT_EA | OPT_REG)) - -ALT(DEF_ASM_OP2(testb, 0x84, 0, OPC_MODRM | OPC_BWLX, OPT_REG, OPT_EA | OPT_REG)) -ALT(DEF_ASM_OP2(testb, 0x84, 0, OPC_MODRM | OPC_BWLX, OPT_EA | OPT_REG, OPT_REG)) -ALT(DEF_ASM_OP2(testb, 0xa8, 0, OPC_BWLX, OPT_IM, OPT_EAX)) -ALT(DEF_ASM_OP2(testb, 0xf6, 0, OPC_MODRM | OPC_BWLX, OPT_IM, OPT_EA | OPT_REG)) - -ALT(DEF_ASM_OP1(incb, 0xfe, 0, OPC_MODRM | OPC_BWLX, OPT_REG | OPT_EA)) -ALT(DEF_ASM_OP1(decb, 0xfe, 1, OPC_MODRM | OPC_BWLX, OPT_REG | OPT_EA)) - -ALT(DEF_ASM_OP1(notb, 0xf6, 2, OPC_MODRM | OPC_BWLX, OPT_REG | OPT_EA)) -ALT(DEF_ASM_OP1(negb, 0xf6, 3, OPC_MODRM | OPC_BWLX, OPT_REG | OPT_EA)) - -ALT(DEF_ASM_OP1(mulb, 0xf6, 4, OPC_MODRM | OPC_BWLX, OPT_REG | OPT_EA)) -ALT(DEF_ASM_OP1(imulb, 0xf6, 5, OPC_MODRM | OPC_BWLX, OPT_REG | OPT_EA)) - -ALT(DEF_ASM_OP2(imulw, 0x0faf, 0, OPC_MODRM | OPC_WLX, OPT_REG | OPT_EA, OPT_REG)) -ALT(DEF_ASM_OP3(imulw, 0x6b, 0, OPC_MODRM | OPC_WLX, OPT_IM8S, OPT_REGW | OPT_EA, OPT_REGW)) -ALT(DEF_ASM_OP2(imulw, 0x6b, 0, OPC_MODRM | OPC_WLX, OPT_IM8S, OPT_REGW)) -ALT(DEF_ASM_OP3(imulw, 0x69, 0, OPC_MODRM | OPC_WLX, OPT_IMW, OPT_REGW | OPT_EA, OPT_REGW)) -ALT(DEF_ASM_OP2(imulw, 0x69, 0, OPC_MODRM | OPC_WLX, OPT_IMW, OPT_REGW)) - -ALT(DEF_ASM_OP1(divb, 0xf6, 6, OPC_MODRM | OPC_BWLX, OPT_REG | OPT_EA)) -ALT(DEF_ASM_OP2(divb, 0xf6, 6, OPC_MODRM | OPC_BWLX, OPT_REG | OPT_EA, OPT_EAX)) -ALT(DEF_ASM_OP1(idivb, 0xf6, 7, OPC_MODRM | OPC_BWLX, OPT_REG | OPT_EA)) -ALT(DEF_ASM_OP2(idivb, 0xf6, 7, OPC_MODRM | OPC_BWLX, OPT_REG | OPT_EA, OPT_EAX)) - - /* shifts */ -ALT(DEF_ASM_OP2(rolb, 0xc0, 0, OPC_MODRM | OPC_BWLX | OPC_SHIFT, OPT_IM8, OPT_EA | OPT_REG)) -ALT(DEF_ASM_OP2(rolb, 0xd2, 0, OPC_MODRM | OPC_BWLX | OPC_SHIFT, OPT_CL, OPT_EA | OPT_REG)) -ALT(DEF_ASM_OP1(rolb, 0xd0, 0, OPC_MODRM | OPC_BWLX | OPC_SHIFT, OPT_EA | OPT_REG)) - -ALT(DEF_ASM_OP3(shldw, 0x0fa4, 0, OPC_MODRM | OPC_WLX, OPT_IM8, OPT_REGW, OPT_EA | OPT_REGW)) -ALT(DEF_ASM_OP3(shldw, 0x0fa5, 0, OPC_MODRM | OPC_WLX, OPT_CL, OPT_REGW, OPT_EA | OPT_REGW)) -ALT(DEF_ASM_OP2(shldw, 0x0fa5, 0, OPC_MODRM | OPC_WLX, OPT_REGW, OPT_EA | OPT_REGW)) -ALT(DEF_ASM_OP3(shrdw, 0x0fac, 0, OPC_MODRM | OPC_WLX, OPT_IM8, OPT_REGW, OPT_EA | OPT_REGW)) -ALT(DEF_ASM_OP3(shrdw, 0x0fad, 0, OPC_MODRM | OPC_WLX, OPT_CL, OPT_REGW, OPT_EA | OPT_REGW)) -ALT(DEF_ASM_OP2(shrdw, 0x0fad, 0, OPC_MODRM | OPC_WLX, OPT_REGW, OPT_EA | OPT_REGW)) - -ALT(DEF_ASM_OP1(call, 0xff, 2, OPC_MODRM, OPT_INDIR)) -ALT(DEF_ASM_OP1(call, 0xe8, 0, 0, OPT_DISP)) -ALT(DEF_ASM_OP1(jmp, 0xff, 4, OPC_MODRM, OPT_INDIR)) -ALT(DEF_ASM_OP1(jmp, 0xeb, 0, 0, OPT_DISP8)) - -ALT(DEF_ASM_OP1(lcall, 0xff, 3, OPC_MODRM, OPT_EA)) -ALT(DEF_ASM_OP1(ljmp, 0xff, 5, OPC_MODRM, OPT_EA)) - DEF_ASM_OP1(ljmpw, 0x66ff, 5, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(ljmpl, 0xff, 5, OPC_MODRM, OPT_EA) - -ALT(DEF_ASM_OP1(int, 0xcd, 0, 0, OPT_IM8)) -ALT(DEF_ASM_OP1(seto, 0x0f90, 0, OPC_MODRM | OPC_TEST, OPT_REG8 | OPT_EA)) -ALT(DEF_ASM_OP1(setob, 0x0f90, 0, OPC_MODRM | OPC_TEST, OPT_REG8 | OPT_EA)) - DEF_ASM_OP2(enter, 0xc8, 0, 0, OPT_IM16, OPT_IM8) - DEF_ASM_OP0(leave, 0xc9) - DEF_ASM_OP0(ret, 0xc3) - DEF_ASM_OP0(retq, 0xc3) -ALT(DEF_ASM_OP1(retq, 0xc2, 0, 0, OPT_IM16)) -ALT(DEF_ASM_OP1(ret, 0xc2, 0, 0, OPT_IM16)) - DEF_ASM_OP0(lret, 0xcb) -ALT(DEF_ASM_OP1(lret, 0xca, 0, 0, OPT_IM16)) - -ALT(DEF_ASM_OP1(jo, 0x70, 0, OPC_TEST, OPT_DISP8)) - DEF_ASM_OP1(loopne, 0xe0, 0, 0, OPT_DISP8) - DEF_ASM_OP1(loopnz, 0xe0, 0, 0, OPT_DISP8) - DEF_ASM_OP1(loope, 0xe1, 0, 0, OPT_DISP8) - DEF_ASM_OP1(loopz, 0xe1, 0, 0, OPT_DISP8) - DEF_ASM_OP1(loop, 0xe2, 0, 0, OPT_DISP8) - DEF_ASM_OP1(jecxz, 0x67e3, 0, 0, OPT_DISP8) - - /* float */ - /* specific fcomp handling */ -ALT(DEF_ASM_OP0L(fcomp, 0xd8d9, 0, 0)) - -ALT(DEF_ASM_OP1(fadd, 0xd8c0, 0, OPC_FARITH | OPC_REG, OPT_ST)) -ALT(DEF_ASM_OP2(fadd, 0xd8c0, 0, OPC_FARITH | OPC_REG, OPT_ST, OPT_ST0)) -ALT(DEF_ASM_OP2(fadd, 0xdcc0, 0, OPC_FARITH | OPC_REG, OPT_ST0, OPT_ST)) -ALT(DEF_ASM_OP2(fmul, 0xdcc8, 0, OPC_FARITH | OPC_REG, OPT_ST0, OPT_ST)) -ALT(DEF_ASM_OP0L(fadd, 0xdec1, 0, OPC_FARITH)) -ALT(DEF_ASM_OP1(faddp, 0xdec0, 0, OPC_FARITH | OPC_REG, OPT_ST)) -ALT(DEF_ASM_OP2(faddp, 0xdec0, 0, OPC_FARITH | OPC_REG, OPT_ST, OPT_ST0)) -ALT(DEF_ASM_OP2(faddp, 0xdec0, 0, OPC_FARITH | OPC_REG, OPT_ST0, OPT_ST)) -ALT(DEF_ASM_OP0L(faddp, 0xdec1, 0, OPC_FARITH)) -ALT(DEF_ASM_OP1(fadds, 0xd8, 0, OPC_FARITH | OPC_MODRM, OPT_EA)) -ALT(DEF_ASM_OP1(fiaddl, 0xda, 0, OPC_FARITH | OPC_MODRM, OPT_EA)) -ALT(DEF_ASM_OP1(faddl, 0xdc, 0, OPC_FARITH | OPC_MODRM, OPT_EA)) -ALT(DEF_ASM_OP1(fiadds, 0xde, 0, OPC_FARITH | OPC_MODRM, OPT_EA)) - - DEF_ASM_OP0(fucompp, 0xdae9) - DEF_ASM_OP0(ftst, 0xd9e4) - DEF_ASM_OP0(fxam, 0xd9e5) - DEF_ASM_OP0(fld1, 0xd9e8) - DEF_ASM_OP0(fldl2t, 0xd9e9) - DEF_ASM_OP0(fldl2e, 0xd9ea) - DEF_ASM_OP0(fldpi, 0xd9eb) - DEF_ASM_OP0(fldlg2, 0xd9ec) - DEF_ASM_OP0(fldln2, 0xd9ed) - DEF_ASM_OP0(fldz, 0xd9ee) - - DEF_ASM_OP0(f2xm1, 0xd9f0) - DEF_ASM_OP0(fyl2x, 0xd9f1) - DEF_ASM_OP0(fptan, 0xd9f2) - DEF_ASM_OP0(fpatan, 0xd9f3) - DEF_ASM_OP0(fxtract, 0xd9f4) - DEF_ASM_OP0(fprem1, 0xd9f5) - DEF_ASM_OP0(fdecstp, 0xd9f6) - DEF_ASM_OP0(fincstp, 0xd9f7) - DEF_ASM_OP0(fprem, 0xd9f8) - DEF_ASM_OP0(fyl2xp1, 0xd9f9) - DEF_ASM_OP0(fsqrt, 0xd9fa) - DEF_ASM_OP0(fsincos, 0xd9fb) - DEF_ASM_OP0(frndint, 0xd9fc) - DEF_ASM_OP0(fscale, 0xd9fd) - DEF_ASM_OP0(fsin, 0xd9fe) - DEF_ASM_OP0(fcos, 0xd9ff) - DEF_ASM_OP0(fchs, 0xd9e0) - DEF_ASM_OP0(fabs, 0xd9e1) - DEF_ASM_OP0(fninit, 0xdbe3) - DEF_ASM_OP0(fnclex, 0xdbe2) - DEF_ASM_OP0(fnop, 0xd9d0) - DEF_ASM_OP0(fwait, 0x9b) - - /* fp load */ - DEF_ASM_OP1(fld, 0xd9c0, 0, OPC_REG, OPT_ST) - DEF_ASM_OP1(fldl, 0xd9c0, 0, OPC_REG, OPT_ST) - DEF_ASM_OP1(flds, 0xd9, 0, OPC_MODRM, OPT_EA) -ALT(DEF_ASM_OP1(fldl, 0xdd, 0, OPC_MODRM, OPT_EA)) - DEF_ASM_OP1(fildl, 0xdb, 0, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(fildq, 0xdf, 5, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(fildll, 0xdf, 5, OPC_MODRM,OPT_EA) - DEF_ASM_OP1(fldt, 0xdb, 5, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(fbld, 0xdf, 4, OPC_MODRM, OPT_EA) - - /* fp store */ - DEF_ASM_OP1(fst, 0xddd0, 0, OPC_REG, OPT_ST) - DEF_ASM_OP1(fstl, 0xddd0, 0, OPC_REG, OPT_ST) - DEF_ASM_OP1(fsts, 0xd9, 2, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(fstps, 0xd9, 3, OPC_MODRM, OPT_EA) -ALT(DEF_ASM_OP1(fstl, 0xdd, 2, OPC_MODRM, OPT_EA)) - DEF_ASM_OP1(fstpl, 0xdd, 3, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(fist, 0xdf, 2, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(fistp, 0xdf, 3, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(fistl, 0xdb, 2, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(fistpl, 0xdb, 3, OPC_MODRM, OPT_EA) - - DEF_ASM_OP1(fstp, 0xddd8, 0, OPC_REG, OPT_ST) - DEF_ASM_OP1(fistpq, 0xdf, 7, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(fistpll, 0xdf, 7, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(fstpt, 0xdb, 7, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(fbstp, 0xdf, 6, OPC_MODRM, OPT_EA) - - /* exchange */ - DEF_ASM_OP0(fxch, 0xd9c9) -ALT(DEF_ASM_OP1(fxch, 0xd9c8, 0, OPC_REG, OPT_ST)) - - /* misc FPU */ - DEF_ASM_OP1(fucom, 0xdde0, 0, OPC_REG, OPT_ST ) - DEF_ASM_OP1(fucomp, 0xdde8, 0, OPC_REG, OPT_ST ) - - DEF_ASM_OP0L(finit, 0xdbe3, 0, OPC_FWAIT) - DEF_ASM_OP1(fldcw, 0xd9, 5, OPC_MODRM, OPT_EA ) - DEF_ASM_OP1(fnstcw, 0xd9, 7, OPC_MODRM, OPT_EA ) - DEF_ASM_OP1(fstcw, 0xd9, 7, OPC_MODRM | OPC_FWAIT, OPT_EA ) - DEF_ASM_OP0(fnstsw, 0xdfe0) -ALT(DEF_ASM_OP1(fnstsw, 0xdfe0, 0, 0, OPT_EAX )) -ALT(DEF_ASM_OP1(fnstsw, 0xdd, 7, OPC_MODRM, OPT_EA )) - DEF_ASM_OP1(fstsw, 0xdfe0, 0, OPC_FWAIT, OPT_EAX ) -ALT(DEF_ASM_OP0L(fstsw, 0xdfe0, 0, OPC_FWAIT)) -ALT(DEF_ASM_OP1(fstsw, 0xdd, 7, OPC_MODRM | OPC_FWAIT, OPT_EA )) - DEF_ASM_OP0L(fclex, 0xdbe2, 0, OPC_FWAIT) - DEF_ASM_OP1(fnstenv, 0xd9, 6, OPC_MODRM, OPT_EA ) - DEF_ASM_OP1(fstenv, 0xd9, 6, OPC_MODRM | OPC_FWAIT, OPT_EA ) - DEF_ASM_OP1(fldenv, 0xd9, 4, OPC_MODRM, OPT_EA ) - DEF_ASM_OP1(fnsave, 0xdd, 6, OPC_MODRM, OPT_EA ) - DEF_ASM_OP1(fsave, 0xdd, 6, OPC_MODRM | OPC_FWAIT, OPT_EA ) - DEF_ASM_OP1(frstor, 0xdd, 4, OPC_MODRM, OPT_EA ) - DEF_ASM_OP1(ffree, 0xddc0, 4, OPC_REG, OPT_ST ) - DEF_ASM_OP1(ffreep, 0xdfc0, 4, OPC_REG, OPT_ST ) - DEF_ASM_OP1(fxsave, 0x0fae, 0, OPC_MODRM, OPT_EA ) - DEF_ASM_OP1(fxrstor, 0x0fae, 1, OPC_MODRM, OPT_EA ) - /* The *q forms of fxrstor/fxsave use a REX prefix. - If the operand would use extended registers we would have to modify - it instead of generating a second one. Currently that's no - problem with TCC, we don't use extended registers. */ - DEF_ASM_OP1(fxsaveq, 0x0fae, 0, OPC_MODRM | OPC_48, OPT_EA ) - DEF_ASM_OP1(fxrstorq, 0x0fae, 1, OPC_MODRM | OPC_48, OPT_EA ) - - /* segments */ - DEF_ASM_OP2(arpl, 0x63, 0, OPC_MODRM, OPT_REG16, OPT_REG16 | OPT_EA) -ALT(DEF_ASM_OP2(larw, 0x0f02, 0, OPC_MODRM | OPC_WLX, OPT_REG | OPT_EA, OPT_REG)) - DEF_ASM_OP1(lgdt, 0x0f01, 2, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(lgdtq, 0x0f01, 2, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(lidt, 0x0f01, 3, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(lidtq, 0x0f01, 3, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(lldt, 0x0f00, 2, OPC_MODRM, OPT_EA | OPT_REG) - DEF_ASM_OP1(lmsw, 0x0f01, 6, OPC_MODRM, OPT_EA | OPT_REG) -ALT(DEF_ASM_OP2(lslw, 0x0f03, 0, OPC_MODRM | OPC_WLX, OPT_EA | OPT_REG, OPT_REG)) - DEF_ASM_OP1(ltr, 0x0f00, 3, OPC_MODRM, OPT_EA | OPT_REG16) - DEF_ASM_OP1(sgdt, 0x0f01, 0, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(sgdtq, 0x0f01, 0, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(sidt, 0x0f01, 1, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(sidtq, 0x0f01, 1, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(sldt, 0x0f00, 0, OPC_MODRM, OPT_REG | OPT_EA) - DEF_ASM_OP1(smsw, 0x0f01, 4, OPC_MODRM, OPT_REG | OPT_EA) - DEF_ASM_OP1(str, 0x0f00, 1, OPC_MODRM, OPT_REG32 | OPT_EA) -ALT(DEF_ASM_OP1(str, 0x660f00, 1, OPC_MODRM, OPT_REG16)) -ALT(DEF_ASM_OP1(str, 0x0f00, 1, OPC_MODRM | OPC_48, OPT_REG64)) - DEF_ASM_OP1(verr, 0x0f00, 4, OPC_MODRM, OPT_REG | OPT_EA) - DEF_ASM_OP1(verw, 0x0f00, 5, OPC_MODRM, OPT_REG | OPT_EA) - DEF_ASM_OP0L(swapgs, 0x0f01, 7, OPC_MODRM) - - /* 486 */ - /* bswap can't be applied to 16bit regs */ - DEF_ASM_OP1(bswap, 0x0fc8, 0, OPC_REG, OPT_REG32 ) - DEF_ASM_OP1(bswapl, 0x0fc8, 0, OPC_REG, OPT_REG32 ) - DEF_ASM_OP1(bswapq, 0x0fc8, 0, OPC_REG | OPC_48, OPT_REG64 ) - -ALT(DEF_ASM_OP2(xaddb, 0x0fc0, 0, OPC_MODRM | OPC_BWLX, OPT_REG, OPT_REG | OPT_EA )) -ALT(DEF_ASM_OP2(cmpxchgb, 0x0fb0, 0, OPC_MODRM | OPC_BWLX, OPT_REG, OPT_REG | OPT_EA )) - DEF_ASM_OP1(invlpg, 0x0f01, 7, OPC_MODRM, OPT_EA ) - - /* pentium */ - DEF_ASM_OP1(cmpxchg8b, 0x0fc7, 1, OPC_MODRM, OPT_EA ) - - /* AMD 64 */ - DEF_ASM_OP1(cmpxchg16b, 0x0fc7, 1, OPC_MODRM | OPC_48, OPT_EA ) - - /* pentium pro */ -ALT(DEF_ASM_OP2(cmovo, 0x0f40, 0, OPC_MODRM | OPC_TEST | OPC_WLX, OPT_REGW | OPT_EA, OPT_REGW)) - - DEF_ASM_OP2(fcmovb, 0xdac0, 0, OPC_REG, OPT_ST, OPT_ST0 ) - DEF_ASM_OP2(fcmove, 0xdac8, 0, OPC_REG, OPT_ST, OPT_ST0 ) - DEF_ASM_OP2(fcmovbe, 0xdad0, 0, OPC_REG, OPT_ST, OPT_ST0 ) - DEF_ASM_OP2(fcmovu, 0xdad8, 0, OPC_REG, OPT_ST, OPT_ST0 ) - DEF_ASM_OP2(fcmovnb, 0xdbc0, 0, OPC_REG, OPT_ST, OPT_ST0 ) - DEF_ASM_OP2(fcmovne, 0xdbc8, 0, OPC_REG, OPT_ST, OPT_ST0 ) - DEF_ASM_OP2(fcmovnbe, 0xdbd0, 0, OPC_REG, OPT_ST, OPT_ST0 ) - DEF_ASM_OP2(fcmovnu, 0xdbd8, 0, OPC_REG, OPT_ST, OPT_ST0 ) - - DEF_ASM_OP2(fucomi, 0xdbe8, 0, OPC_REG, OPT_ST, OPT_ST0 ) - DEF_ASM_OP2(fcomi, 0xdbf0, 0, OPC_REG, OPT_ST, OPT_ST0 ) - DEF_ASM_OP2(fucomip, 0xdfe8, 0, OPC_REG, OPT_ST, OPT_ST0 ) - DEF_ASM_OP2(fcomip, 0xdff0, 0, OPC_REG, OPT_ST, OPT_ST0 ) - - /* mmx */ - DEF_ASM_OP0(emms, 0x0f77) /* must be last OP0 */ - DEF_ASM_OP2(movd, 0x0f6e, 0, OPC_MODRM, OPT_EA | OPT_REG32, OPT_MMXSSE ) - /* movd shouldn't accept REG64, but AMD64 spec uses it for 32 and 64 bit - moves, so let's be compatible. */ -ALT(DEF_ASM_OP2(movd, 0x0f6e, 0, OPC_MODRM, OPT_EA | OPT_REG64, OPT_MMXSSE )) -ALT(DEF_ASM_OP2(movq, 0x0f6e, 0, OPC_MODRM | OPC_48, OPT_REG64, OPT_MMXSSE )) -ALT(DEF_ASM_OP2(movq, 0x0f6f, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )) -ALT(DEF_ASM_OP2(movd, 0x0f7e, 0, OPC_MODRM, OPT_MMXSSE, OPT_EA | OPT_REG32 )) -ALT(DEF_ASM_OP2(movd, 0x0f7e, 0, OPC_MODRM, OPT_MMXSSE, OPT_EA | OPT_REG64 )) -ALT(DEF_ASM_OP2(movq, 0x0f7f, 0, OPC_MODRM, OPT_MMX, OPT_EA | OPT_MMX )) -ALT(DEF_ASM_OP2(movq, 0x660fd6, 0, OPC_MODRM, OPT_SSE, OPT_EA | OPT_SSE )) -ALT(DEF_ASM_OP2(movq, 0xf30f7e, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE )) -ALT(DEF_ASM_OP2(movq, 0x0f7e, 0, OPC_MODRM, OPT_MMXSSE, OPT_EA | OPT_REG64 )) - - DEF_ASM_OP2(packssdw, 0x0f6b, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(packsswb, 0x0f63, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(packuswb, 0x0f67, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(paddb, 0x0ffc, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(paddw, 0x0ffd, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(paddd, 0x0ffe, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(paddsb, 0x0fec, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(paddsw, 0x0fed, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(paddusb, 0x0fdc, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(paddusw, 0x0fdd, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pand, 0x0fdb, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pandn, 0x0fdf, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pcmpeqb, 0x0f74, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pcmpeqw, 0x0f75, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pcmpeqd, 0x0f76, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pcmpgtb, 0x0f64, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pcmpgtw, 0x0f65, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pcmpgtd, 0x0f66, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pmaddwd, 0x0ff5, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pmulhw, 0x0fe5, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pmullw, 0x0fd5, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(por, 0x0feb, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(psllw, 0x0ff1, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) -ALT(DEF_ASM_OP2(psllw, 0x0f71, 6, OPC_MODRM, OPT_IM8, OPT_MMXSSE )) - DEF_ASM_OP2(pslld, 0x0ff2, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) -ALT(DEF_ASM_OP2(pslld, 0x0f72, 6, OPC_MODRM, OPT_IM8, OPT_MMXSSE )) - DEF_ASM_OP2(psllq, 0x0ff3, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) -ALT(DEF_ASM_OP2(psllq, 0x0f73, 6, OPC_MODRM, OPT_IM8, OPT_MMXSSE )) - DEF_ASM_OP2(psraw, 0x0fe1, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) -ALT(DEF_ASM_OP2(psraw, 0x0f71, 4, OPC_MODRM, OPT_IM8, OPT_MMXSSE )) - DEF_ASM_OP2(psrad, 0x0fe2, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) -ALT(DEF_ASM_OP2(psrad, 0x0f72, 4, OPC_MODRM, OPT_IM8, OPT_MMXSSE )) - DEF_ASM_OP2(psrlw, 0x0fd1, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) -ALT(DEF_ASM_OP2(psrlw, 0x0f71, 2, OPC_MODRM, OPT_IM8, OPT_MMXSSE )) - DEF_ASM_OP2(psrld, 0x0fd2, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) -ALT(DEF_ASM_OP2(psrld, 0x0f72, 2, OPC_MODRM, OPT_IM8, OPT_MMXSSE )) - DEF_ASM_OP2(psrlq, 0x0fd3, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) -ALT(DEF_ASM_OP2(psrlq, 0x0f73, 2, OPC_MODRM, OPT_IM8, OPT_MMXSSE )) - DEF_ASM_OP2(psubb, 0x0ff8, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(psubw, 0x0ff9, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(psubd, 0x0ffa, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(psubsb, 0x0fe8, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(psubsw, 0x0fe9, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(psubusb, 0x0fd8, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(psubusw, 0x0fd9, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(punpckhbw, 0x0f68, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(punpckhwd, 0x0f69, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(punpckhdq, 0x0f6a, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(punpcklbw, 0x0f60, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(punpcklwd, 0x0f61, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(punpckldq, 0x0f62, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pxor, 0x0fef, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - - /* sse */ - DEF_ASM_OP2(movups, 0x0f10, 0, OPC_MODRM, OPT_EA | OPT_REG32, OPT_SSE ) -ALT(DEF_ASM_OP2(movups, 0x0f11, 0, OPC_MODRM, OPT_SSE, OPT_EA | OPT_REG32 )) - DEF_ASM_OP2(movaps, 0x0f28, 0, OPC_MODRM, OPT_EA | OPT_REG32, OPT_SSE ) -ALT(DEF_ASM_OP2(movaps, 0x0f29, 0, OPC_MODRM, OPT_SSE, OPT_EA | OPT_REG32 )) - DEF_ASM_OP2(movhps, 0x0f16, 0, OPC_MODRM, OPT_EA | OPT_REG32, OPT_SSE ) -ALT(DEF_ASM_OP2(movhps, 0x0f17, 0, OPC_MODRM, OPT_SSE, OPT_EA | OPT_REG32 )) - DEF_ASM_OP2(addps, 0x0f58, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE ) - DEF_ASM_OP2(cvtpi2ps, 0x0f2a, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_SSE ) - DEF_ASM_OP2(cvtps2pi, 0x0f2d, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_MMX ) - DEF_ASM_OP2(cvttps2pi, 0x0f2c, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_MMX ) - DEF_ASM_OP2(divps, 0x0f5e, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE ) - DEF_ASM_OP2(maxps, 0x0f5f, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE ) - DEF_ASM_OP2(minps, 0x0f5d, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE ) - DEF_ASM_OP2(mulps, 0x0f59, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE ) - DEF_ASM_OP2(pavgb, 0x0fe0, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE ) - DEF_ASM_OP2(pavgw, 0x0fe3, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE ) - DEF_ASM_OP2(pmaxsw, 0x0fee, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pmaxub, 0x0fde, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pminsw, 0x0fea, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pminub, 0x0fda, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(rcpss, 0x0f53, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE ) - DEF_ASM_OP2(rsqrtps, 0x0f52, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE ) - DEF_ASM_OP2(sqrtps, 0x0f51, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE ) - DEF_ASM_OP2(subps, 0x0f5c, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE ) - - DEF_ASM_OP1(prefetchnta, 0x0f18, 0, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(prefetcht0, 0x0f18, 1, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(prefetcht1, 0x0f18, 2, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(prefetcht2, 0x0f18, 3, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(prefetchw, 0x0f0d, 1, OPC_MODRM, OPT_EA) - DEF_ASM_OP0L(lfence, 0x0fae, 5, OPC_MODRM) - DEF_ASM_OP0L(mfence, 0x0fae, 6, OPC_MODRM) - DEF_ASM_OP0L(sfence, 0x0fae, 7, OPC_MODRM) - DEF_ASM_OP1(clflush, 0x0fae, 7, OPC_MODRM, OPT_EA) -#undef ALT -#undef DEF_ASM_OP0 -#undef DEF_ASM_OP0L -#undef DEF_ASM_OP1 -#undef DEF_ASM_OP2 -#undef DEF_ASM_OP3 diff --git a/05/tcc-final-old/x86_64-gen.c b/05/tcc-final-old/x86_64-gen.c deleted file mode 100644 index e33a38a..0000000 --- a/05/tcc-final-old/x86_64-gen.c +++ /dev/null @@ -1,2258 +0,0 @@ -/* - * x86-64 code generator for TCC - * - * Copyright (c) 2008 Shinichiro Hamaji - * - * Based on i386-gen.c by Fabrice Bellard - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifdef TARGET_DEFS_ONLY - -/* number of available registers */ -#define NB_REGS 25 -#define NB_ASM_REGS 16 -#define CONFIG_TCC_ASM - -/* a register can belong to several classes. The classes must be - sorted from more general to more precise (see gv2() code which does - assumptions on it). */ -#define RC_INT 0x0001 /* generic integer register */ -#define RC_FLOAT 0x0002 /* generic float register */ -#define RC_RAX 0x0004 -#define RC_RCX 0x0008 -#define RC_RDX 0x0010 -#define RC_ST0 0x0080 /* only for long double */ -#define RC_R8 0x0100 -#define RC_R9 0x0200 -#define RC_R10 0x0400 -#define RC_R11 0x0800 -#define RC_XMM0 0x1000 -#define RC_XMM1 0x2000 -#define RC_XMM2 0x4000 -#define RC_XMM3 0x8000 -#define RC_XMM4 0x10000 -#define RC_XMM5 0x20000 -#define RC_XMM6 0x40000 -#define RC_XMM7 0x80000 -#define RC_IRET RC_RAX /* function return: integer register */ -#define RC_LRET RC_RDX /* function return: second integer register */ -#define RC_FRET RC_XMM0 /* function return: float register */ -#define RC_QRET RC_XMM1 /* function return: second float register */ - -/* pretty names for the registers */ -enum { - TREG_RAX = 0, - TREG_RCX = 1, - TREG_RDX = 2, - TREG_RSP = 4, - TREG_RSI = 6, - TREG_RDI = 7, - - TREG_R8 = 8, - TREG_R9 = 9, - TREG_R10 = 10, - TREG_R11 = 11, - - TREG_XMM0 = 16, - TREG_XMM1 = 17, - TREG_XMM2 = 18, - TREG_XMM3 = 19, - TREG_XMM4 = 20, - TREG_XMM5 = 21, - TREG_XMM6 = 22, - TREG_XMM7 = 23, - - TREG_ST0 = 24, - - TREG_MEM = 0x20 -}; - -#define REX_BASE(reg) (((reg) >> 3) & 1) -#define REG_VALUE(reg) ((reg) & 7) - -/* return registers for function */ -#define REG_IRET TREG_RAX /* single word int return register */ -#define REG_LRET TREG_RDX /* second word return register (for long long) */ -#define REG_FRET TREG_XMM0 /* float return register */ -#define REG_QRET TREG_XMM1 /* second float return register */ - -/* defined if function parameters must be evaluated in reverse order */ -#define INVERT_FUNC_PARAMS - -/* pointer size, in bytes */ -#define PTR_SIZE 8 - -/* long double size and alignment, in bytes */ -#define LDOUBLE_SIZE 16 -#define LDOUBLE_ALIGN 16 -/* maximum alignment (for aligned attribute support) */ -#define MAX_ALIGN 16 - -/******************************************************/ -#else /* ! TARGET_DEFS_ONLY */ -/******************************************************/ -#include "tcc.h" -#include - -ST_DATA const int reg_classes[NB_REGS] = { - /* eax */ RC_INT | RC_RAX, - /* ecx */ RC_INT | RC_RCX, - /* edx */ RC_INT | RC_RDX, - 0, - 0, - 0, - 0, - 0, - RC_R8, - RC_R9, - RC_R10, - RC_R11, - 0, - 0, - 0, - 0, - /* xmm0 */ RC_FLOAT | RC_XMM0, - /* xmm1 */ RC_FLOAT | RC_XMM1, - /* xmm2 */ RC_FLOAT | RC_XMM2, - /* xmm3 */ RC_FLOAT | RC_XMM3, - /* xmm4 */ RC_FLOAT | RC_XMM4, - /* xmm5 */ RC_FLOAT | RC_XMM5, - /* xmm6 an xmm7 are included so gv() can be used on them, - but they are not tagged with RC_FLOAT because they are - callee saved on Windows */ - RC_XMM6, - RC_XMM7, - /* st0 */ RC_ST0 -}; - -static unsigned long func_sub_sp_offset; -static int func_ret_sub; - -/* XXX: make it faster ? */ -ST_FUNC void g(int c) -{ - int ind1; - if (nocode_wanted) - return; - ind1 = ind + 1; - if (ind1 > cur_text_section->data_allocated) - section_realloc(cur_text_section, ind1); - cur_text_section->data[ind] = c; - ind = ind1; -} - -ST_FUNC void o(unsigned int c) -{ - while (c) { - g(c); - c = c >> 8; - } -} - -ST_FUNC void gen_le16(int v) -{ - g(v); - g(v >> 8); -} - -ST_FUNC void gen_le32(int c) -{ - g(c); - g(c >> 8); - g(c >> 16); - g(c >> 24); -} - -ST_FUNC void gen_le64(int64_t c) -{ - g(c); - g(c >> 8); - g(c >> 16); - g(c >> 24); - g(c >> 32); - g(c >> 40); - g(c >> 48); - g(c >> 56); -} - -static void orex(int ll, int r, int r2, int b) -{ - if ((r & VT_VALMASK) >= VT_CONST) - r = 0; - if ((r2 & VT_VALMASK) >= VT_CONST) - r2 = 0; - if (ll || REX_BASE(r) || REX_BASE(r2)) - o(0x40 | REX_BASE(r) | (REX_BASE(r2) << 2) | (ll << 3)); - o(b); -} - -/* output a symbol and patch all calls to it */ -ST_FUNC void gsym_addr(int t, int a) -{ - while (t) { - unsigned char *ptr = cur_text_section->data + t; - uint32_t n = read32le(ptr); /* next value */ - write32le(ptr, a - t - 4); - t = n; - } -} - -void gsym(int t) -{ - gsym_addr(t, ind); -} - - -static int is64_type(int t) -{ - return ((t & VT_BTYPE) == VT_PTR || - (t & VT_BTYPE) == VT_FUNC || - (t & VT_BTYPE) == VT_LLONG); -} - -/* instruction + 4 bytes data. Return the address of the data */ -static int oad(int c, int s) -{ - int t; - if (nocode_wanted) - return s; - o(c); - t = ind; - gen_le32(s); - return t; -} - -/* generate jmp to a label */ -#define gjmp2(instr,lbl) oad(instr,lbl) - -ST_FUNC void gen_addr32(int r, Sym *sym, int c) -{ - if (r & VT_SYM) - greloca(cur_text_section, sym, ind, R_X86_64_32S, c), c=0; - gen_le32(c); -} - -/* output constant with relocation if 'r & VT_SYM' is true */ -ST_FUNC void gen_addr64(int r, Sym *sym, int64_t c) -{ - if (r & VT_SYM) - greloca(cur_text_section, sym, ind, R_X86_64_64, c), c=0; - gen_le64(c); -} - -/* output constant with relocation if 'r & VT_SYM' is true */ -ST_FUNC void gen_addrpc32(int r, Sym *sym, int c) -{ - if (r & VT_SYM) - greloca(cur_text_section, sym, ind, R_X86_64_PC32, c-4), c=4; - gen_le32(c-4); -} - -/* output got address with relocation */ -static void gen_gotpcrel(int r, Sym *sym, int c) -{ -#ifdef TCC_TARGET_PE - tcc_error("internal error: no GOT on PE: %s %x %x | %02x %02x %02x\n", - get_tok_str(sym->v, NULL), c, r, - cur_text_section->data[ind-3], - cur_text_section->data[ind-2], - cur_text_section->data[ind-1] - ); -#endif - greloca(cur_text_section, sym, ind, R_X86_64_GOTPCREL, -4); - gen_le32(0); - if (c) { - /* we use add c, %xxx for displacement */ - orex(1, r, 0, 0x81); - o(0xc0 + REG_VALUE(r)); - gen_le32(c); - } -} - -static void gen_modrm_impl(int op_reg, int r, Sym *sym, int c, int is_got) -{ - op_reg = REG_VALUE(op_reg) << 3; - if ((r & VT_VALMASK) == VT_CONST) { - /* constant memory reference */ - if (!(r & VT_SYM)) { - /* Absolute memory reference */ - o(0x04 | op_reg); /* [sib] | destreg */ - oad(0x25, c); /* disp32 */ - } else { - o(0x05 | op_reg); /* (%rip)+disp32 | destreg */ - if (is_got) { - gen_gotpcrel(r, sym, c); - } else { - gen_addrpc32(r, sym, c); - } - } - } else if ((r & VT_VALMASK) == VT_LOCAL) { - /* currently, we use only ebp as base */ - if (c == (char)c) { - /* short reference */ - o(0x45 | op_reg); - g(c); - } else { - oad(0x85 | op_reg, c); - } - } else if ((r & VT_VALMASK) >= TREG_MEM) { - if (c) { - g(0x80 | op_reg | REG_VALUE(r)); - gen_le32(c); - } else { - g(0x00 | op_reg | REG_VALUE(r)); - } - } else { - g(0x00 | op_reg | REG_VALUE(r)); - } -} - -/* generate a modrm reference. 'op_reg' contains the additional 3 - opcode bits */ -static void gen_modrm(int op_reg, int r, Sym *sym, int c) -{ - gen_modrm_impl(op_reg, r, sym, c, 0); -} - -/* generate a modrm reference. 'op_reg' contains the additional 3 - opcode bits */ -static void gen_modrm64(int opcode, int op_reg, int r, Sym *sym, int c) -{ - int is_got; - is_got = (op_reg & TREG_MEM) && !(sym->type.t & VT_STATIC); - orex(1, r, op_reg, opcode); - gen_modrm_impl(op_reg, r, sym, c, is_got); -} - - -/* load 'r' from value 'sv' */ -void load(int r, SValue *sv) -{ - int v, t, ft, fc, fr; - SValue v1; - -#ifdef TCC_TARGET_PE - SValue v2; - sv = pe_getimport(sv, &v2); -#endif - - fr = sv->r; - ft = sv->type.t & ~VT_DEFSIGN; - fc = sv->c.i; - if (fc != sv->c.i && (fr & VT_SYM)) - tcc_error("64 bit addend in load"); - - ft &= ~(VT_VOLATILE | VT_CONSTANT); - -#ifndef TCC_TARGET_PE - /* we use indirect access via got */ - if ((fr & VT_VALMASK) == VT_CONST && (fr & VT_SYM) && - (fr & VT_LVAL) && !(sv->sym->type.t & VT_STATIC)) { - /* use the result register as a temporal register */ - int tr = r | TREG_MEM; - if (is_float(ft)) { - /* we cannot use float registers as a temporal register */ - tr = get_reg(RC_INT) | TREG_MEM; - } - gen_modrm64(0x8b, tr, fr, sv->sym, 0); - - /* load from the temporal register */ - fr = tr | VT_LVAL; - } -#endif - - v = fr & VT_VALMASK; - if (fr & VT_LVAL) { - int b, ll; - if (v == VT_LLOCAL) { - v1.type.t = VT_PTR; - v1.r = VT_LOCAL | VT_LVAL; - v1.c.i = fc; - fr = r; - if (!(reg_classes[fr] & (RC_INT|RC_R11))) - fr = get_reg(RC_INT); - load(fr, &v1); - } - if (fc != sv->c.i) { - /* If the addends doesn't fit into a 32bit signed - we must use a 64bit move. We've checked above - that this doesn't have a sym associated. */ - v1.type.t = VT_LLONG; - v1.r = VT_CONST; - v1.c.i = sv->c.i; - fr = r; - if (!(reg_classes[fr] & (RC_INT|RC_R11))) - fr = get_reg(RC_INT); - load(fr, &v1); - fc = 0; - } - ll = 0; - /* Like GCC we can load from small enough properly sized - structs and unions as well. - XXX maybe move to generic operand handling, but should - occur only with asm, so tccasm.c might also be a better place */ - if ((ft & VT_BTYPE) == VT_STRUCT) { - int align; - switch (type_size(&sv->type, &align)) { - case 1: ft = VT_BYTE; break; - case 2: ft = VT_SHORT; break; - case 4: ft = VT_INT; break; - case 8: ft = VT_LLONG; break; - default: - tcc_error("invalid aggregate type for register load"); - break; - } - } - if ((ft & VT_BTYPE) == VT_FLOAT) { - b = 0x6e0f66; - r = REG_VALUE(r); /* movd */ - } else if ((ft & VT_BTYPE) == VT_DOUBLE) { - b = 0x7e0ff3; /* movq */ - r = REG_VALUE(r); - } else if ((ft & VT_BTYPE) == VT_LDOUBLE) { - b = 0xdb, r = 5; /* fldt */ - } else if ((ft & VT_TYPE) == VT_BYTE || (ft & VT_TYPE) == VT_BOOL) { - b = 0xbe0f; /* movsbl */ - } else if ((ft & VT_TYPE) == (VT_BYTE | VT_UNSIGNED)) { - b = 0xb60f; /* movzbl */ - } else if ((ft & VT_TYPE) == VT_SHORT) { - b = 0xbf0f; /* movswl */ - } else if ((ft & VT_TYPE) == (VT_SHORT | VT_UNSIGNED)) { - b = 0xb70f; /* movzwl */ - } else { - assert(((ft & VT_BTYPE) == VT_INT) - || ((ft & VT_BTYPE) == VT_LLONG) - || ((ft & VT_BTYPE) == VT_PTR) - || ((ft & VT_BTYPE) == VT_FUNC) - ); - ll = is64_type(ft); - b = 0x8b; - } - if (ll) { - gen_modrm64(b, r, fr, sv->sym, fc); - } else { - orex(ll, fr, r, b); - gen_modrm(r, fr, sv->sym, fc); - } - } else { - if (v == VT_CONST) { - if (fr & VT_SYM) { -#ifdef TCC_TARGET_PE - orex(1,0,r,0x8d); - o(0x05 + REG_VALUE(r) * 8); /* lea xx(%rip), r */ - gen_addrpc32(fr, sv->sym, fc); -#else - if (sv->sym->type.t & VT_STATIC) { - orex(1,0,r,0x8d); - o(0x05 + REG_VALUE(r) * 8); /* lea xx(%rip), r */ - gen_addrpc32(fr, sv->sym, fc); - } else { - orex(1,0,r,0x8b); - o(0x05 + REG_VALUE(r) * 8); /* mov xx(%rip), r */ - gen_gotpcrel(r, sv->sym, fc); - } -#endif - } else if (is64_type(ft)) { - orex(1,r,0, 0xb8 + REG_VALUE(r)); /* mov $xx, r */ - gen_le64(sv->c.i); - } else { - orex(0,r,0, 0xb8 + REG_VALUE(r)); /* mov $xx, r */ - gen_le32(fc); - } - } else if (v == VT_LOCAL) { - orex(1,0,r,0x8d); /* lea xxx(%ebp), r */ - gen_modrm(r, VT_LOCAL, sv->sym, fc); - } else if (v == VT_CMP) { - orex(0,r,0,0); - if ((fc & ~0x100) != TOK_NE) - oad(0xb8 + REG_VALUE(r), 0); /* mov $0, r */ - else - oad(0xb8 + REG_VALUE(r), 1); /* mov $1, r */ - if (fc & 0x100) - { - /* This was a float compare. If the parity bit is - set the result was unordered, meaning false for everything - except TOK_NE, and true for TOK_NE. */ - fc &= ~0x100; - o(0x037a + (REX_BASE(r) << 8)); - } - orex(0,r,0, 0x0f); /* setxx %br */ - o(fc); - o(0xc0 + REG_VALUE(r)); - } else if (v == VT_JMP || v == VT_JMPI) { - t = v & 1; - orex(0,r,0,0); - oad(0xb8 + REG_VALUE(r), t); /* mov $1, r */ - o(0x05eb + (REX_BASE(r) << 8)); /* jmp after */ - gsym(fc); - orex(0,r,0,0); - oad(0xb8 + REG_VALUE(r), t ^ 1); /* mov $0, r */ - } else if (v != r) { - if ((r >= TREG_XMM0) && (r <= TREG_XMM7)) { - if (v == TREG_ST0) { - /* gen_cvt_ftof(VT_DOUBLE); */ - o(0xf0245cdd); /* fstpl -0x10(%rsp) */ - /* movsd -0x10(%rsp),%xmmN */ - o(0x100ff2); - o(0x44 + REG_VALUE(r)*8); /* %xmmN */ - o(0xf024); - } else { - assert((v >= TREG_XMM0) && (v <= TREG_XMM7)); - if ((ft & VT_BTYPE) == VT_FLOAT) { - o(0x100ff3); - } else { - assert((ft & VT_BTYPE) == VT_DOUBLE); - o(0x100ff2); - } - o(0xc0 + REG_VALUE(v) + REG_VALUE(r)*8); - } - } else if (r == TREG_ST0) { - assert((v >= TREG_XMM0) && (v <= TREG_XMM7)); - /* gen_cvt_ftof(VT_LDOUBLE); */ - /* movsd %xmmN,-0x10(%rsp) */ - o(0x110ff2); - o(0x44 + REG_VALUE(r)*8); /* %xmmN */ - o(0xf024); - o(0xf02444dd); /* fldl -0x10(%rsp) */ - } else { - orex(1,r,v, 0x89); - o(0xc0 + REG_VALUE(r) + REG_VALUE(v) * 8); /* mov v, r */ - } - } - } -} - -/* store register 'r' in lvalue 'v' */ -void store(int r, SValue *v) -{ - int fr, bt, ft, fc; - int op64 = 0; - /* store the REX prefix in this variable when PIC is enabled */ - int pic = 0; - -#ifdef TCC_TARGET_PE - SValue v2; - v = pe_getimport(v, &v2); -#endif - - fr = v->r & VT_VALMASK; - ft = v->type.t; - fc = v->c.i; - if (fc != v->c.i && (fr & VT_SYM)) - tcc_error("64 bit addend in store"); - ft &= ~(VT_VOLATILE | VT_CONSTANT); - bt = ft & VT_BTYPE; - -#ifndef TCC_TARGET_PE - /* we need to access the variable via got */ - if (fr == VT_CONST && (v->r & VT_SYM)) { - /* mov xx(%rip), %r11 */ - o(0x1d8b4c); - gen_gotpcrel(TREG_R11, v->sym, v->c.i); - pic = is64_type(bt) ? 0x49 : 0x41; - } -#endif - - /* XXX: incorrect if float reg to reg */ - if (bt == VT_FLOAT) { - o(0x66); - o(pic); - o(0x7e0f); /* movd */ - r = REG_VALUE(r); - } else if (bt == VT_DOUBLE) { - o(0x66); - o(pic); - o(0xd60f); /* movq */ - r = REG_VALUE(r); - } else if (bt == VT_LDOUBLE) { - o(0xc0d9); /* fld %st(0) */ - o(pic); - o(0xdb); /* fstpt */ - r = 7; - } else { - if (bt == VT_SHORT) - o(0x66); - o(pic); - if (bt == VT_BYTE || bt == VT_BOOL) - orex(0, 0, r, 0x88); - else if (is64_type(bt)) - op64 = 0x89; - else - orex(0, 0, r, 0x89); - } - if (pic) { - /* xxx r, (%r11) where xxx is mov, movq, fld, or etc */ - if (op64) - o(op64); - o(3 + (r << 3)); - } else if (op64) { - if (fr == VT_CONST || fr == VT_LOCAL || (v->r & VT_LVAL)) { - gen_modrm64(op64, r, v->r, v->sym, fc); - } else if (fr != r) { - /* XXX: don't we really come here? */ - abort(); - o(0xc0 + fr + r * 8); /* mov r, fr */ - } - } else { - if (fr == VT_CONST || fr == VT_LOCAL || (v->r & VT_LVAL)) { - gen_modrm(r, v->r, v->sym, fc); - } else if (fr != r) { - /* XXX: don't we really come here? */ - abort(); - o(0xc0 + fr + r * 8); /* mov r, fr */ - } - } -} - -/* 'is_jmp' is '1' if it is a jump */ -static void gcall_or_jmp(int is_jmp) -{ - int r; - if ((vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST && - ((vtop->r & VT_SYM) || (vtop->c.i-4) == (int)(vtop->c.i-4))) { - /* constant case */ - if (vtop->r & VT_SYM) { - /* relocation case */ -#ifdef TCC_TARGET_PE - greloca(cur_text_section, vtop->sym, ind + 1, R_X86_64_PC32, (int)(vtop->c.i-4)); -#else - greloca(cur_text_section, vtop->sym, ind + 1, R_X86_64_PLT32, (int)(vtop->c.i-4)); -#endif - } else { - /* put an empty PC32 relocation */ - put_elf_reloca(symtab_section, cur_text_section, - ind + 1, R_X86_64_PC32, 0, (int)(vtop->c.i-4)); - } - oad(0xe8 + is_jmp, 0); /* call/jmp im */ - } else { - /* otherwise, indirect call */ - r = TREG_R11; - load(r, vtop); - o(0x41); /* REX */ - o(0xff); /* call/jmp *r */ - o(0xd0 + REG_VALUE(r) + (is_jmp << 4)); - } -} - -#if defined(CONFIG_TCC_BCHECK) -#ifndef TCC_TARGET_PE -static addr_t func_bound_offset; -static unsigned long func_bound_ind; -#endif - -static void gen_static_call(int v) -{ - Sym *sym = external_global_sym(v, &func_old_type, 0); - oad(0xe8, 0); - greloca(cur_text_section, sym, ind-4, R_X86_64_PC32, -4); -} - -/* generate a bounded pointer addition */ -ST_FUNC void gen_bounded_ptr_add(void) -{ - /* save all temporary registers */ - save_regs(0); - - /* prepare fast x86_64 function call */ - gv(RC_RAX); - o(0xc68948); // mov %rax,%rsi ## second arg in %rsi, this must be size - vtop--; - - gv(RC_RAX); - o(0xc78948); // mov %rax,%rdi ## first arg in %rdi, this must be ptr - vtop--; - - /* do a fast function call */ - gen_static_call(TOK___bound_ptr_add); - - /* returned pointer is in rax */ - vtop++; - vtop->r = TREG_RAX | VT_BOUNDED; - - - /* relocation offset of the bounding function call point */ - vtop->c.i = (cur_text_section->reloc->data_offset - sizeof(ElfW(Rela))); -} - -/* patch pointer addition in vtop so that pointer dereferencing is - also tested */ -ST_FUNC void gen_bounded_ptr_deref(void) -{ - addr_t func; - int size, align; - ElfW(Rela) *rel; - Sym *sym; - - size = 0; - /* XXX: put that code in generic part of tcc */ - if (!is_float(vtop->type.t)) { - if (vtop->r & VT_LVAL_BYTE) - size = 1; - else if (vtop->r & VT_LVAL_SHORT) - size = 2; - } - if (!size) - size = type_size(&vtop->type, &align); - switch(size) { - case 1: func = TOK___bound_ptr_indir1; break; - case 2: func = TOK___bound_ptr_indir2; break; - case 4: func = TOK___bound_ptr_indir4; break; - case 8: func = TOK___bound_ptr_indir8; break; - case 12: func = TOK___bound_ptr_indir12; break; - case 16: func = TOK___bound_ptr_indir16; break; - default: - tcc_error("unhandled size when dereferencing bounded pointer"); - func = 0; - break; - } - - sym = external_global_sym(func, &func_old_type, 0); - if (!sym->c) - put_extern_sym(sym, NULL, 0, 0); - - /* patch relocation */ - /* XXX: find a better solution ? */ - - rel = (ElfW(Rela) *)(cur_text_section->reloc->data + vtop->c.i); - rel->r_info = ELF64_R_INFO(sym->c, ELF64_R_TYPE(rel->r_info)); -} -#endif - -#ifdef TCC_TARGET_PE - -#define REGN 4 -static const uint8_t arg_regs[REGN] = { - TREG_RCX, TREG_RDX, TREG_R8, TREG_R9 -}; - -/* Prepare arguments in R10 and R11 rather than RCX and RDX - because gv() will not ever use these */ -static int arg_prepare_reg(int idx) { - if (idx == 0 || idx == 1) - /* idx=0: r10, idx=1: r11 */ - return idx + 10; - else - return arg_regs[idx]; -} - -static int func_scratch, func_alloca; - -/* Generate function call. The function address is pushed first, then - all the parameters in call order. This functions pops all the - parameters and the function address. */ - -static void gen_offs_sp(int b, int r, int d) -{ - orex(1,0,r & 0x100 ? 0 : r, b); - if (d == (char)d) { - o(0x2444 | (REG_VALUE(r) << 3)); - g(d); - } else { - o(0x2484 | (REG_VALUE(r) << 3)); - gen_le32(d); - } -} - -static int using_regs(int size) -{ - return !(size > 8 || (size & (size - 1))); -} - -/* Return the number of registers needed to return the struct, or 0 if - returning via struct pointer. */ -ST_FUNC int gfunc_sret(CType *vt, int variadic, CType *ret, int *ret_align, int *regsize) -{ - int size, align; - *ret_align = 1; // Never have to re-align return values for x86-64 - *regsize = 8; - size = type_size(vt, &align); - if (!using_regs(size)) - return 0; - if (size == 8) - ret->t = VT_LLONG; - else if (size == 4) - ret->t = VT_INT; - else if (size == 2) - ret->t = VT_SHORT; - else - ret->t = VT_BYTE; - ret->ref = NULL; - return 1; -} - -static int is_sse_float(int t) { - int bt; - bt = t & VT_BTYPE; - return bt == VT_DOUBLE || bt == VT_FLOAT; -} - -static int gfunc_arg_size(CType *type) { - int align; - if (type->t & (VT_ARRAY|VT_BITFIELD)) - return 8; - return type_size(type, &align); -} - -void gfunc_call(int nb_args) -{ - int size, r, args_size, i, d, bt, struct_size; - int arg; - - args_size = (nb_args < REGN ? REGN : nb_args) * PTR_SIZE; - arg = nb_args; - - /* for struct arguments, we need to call memcpy and the function - call breaks register passing arguments we are preparing. - So, we process arguments which will be passed by stack first. */ - struct_size = args_size; - for(i = 0; i < nb_args; i++) { - SValue *sv; - - --arg; - sv = &vtop[-i]; - bt = (sv->type.t & VT_BTYPE); - size = gfunc_arg_size(&sv->type); - - if (using_regs(size)) - continue; /* arguments smaller than 8 bytes passed in registers or on stack */ - - if (bt == VT_STRUCT) { - /* align to stack align size */ - size = (size + 15) & ~15; - /* generate structure store */ - r = get_reg(RC_INT); - gen_offs_sp(0x8d, r, struct_size); - struct_size += size; - - /* generate memcpy call */ - vset(&sv->type, r | VT_LVAL, 0); - vpushv(sv); - vstore(); - --vtop; - } else if (bt == VT_LDOUBLE) { - gv(RC_ST0); - gen_offs_sp(0xdb, 0x107, struct_size); - struct_size += 16; - } - } - - if (func_scratch < struct_size) - func_scratch = struct_size; - - arg = nb_args; - struct_size = args_size; - - for(i = 0; i < nb_args; i++) { - --arg; - bt = (vtop->type.t & VT_BTYPE); - - size = gfunc_arg_size(&vtop->type); - if (!using_regs(size)) { - /* align to stack align size */ - size = (size + 15) & ~15; - if (arg >= REGN) { - d = get_reg(RC_INT); - gen_offs_sp(0x8d, d, struct_size); - gen_offs_sp(0x89, d, arg*8); - } else { - d = arg_prepare_reg(arg); - gen_offs_sp(0x8d, d, struct_size); - } - struct_size += size; - } else { - if (is_sse_float(vtop->type.t)) { - if (tcc_state->nosse) - tcc_error("SSE disabled"); - gv(RC_XMM0); /* only use one float register */ - if (arg >= REGN) { - /* movq %xmm0, j*8(%rsp) */ - gen_offs_sp(0xd60f66, 0x100, arg*8); - } else { - /* movaps %xmm0, %xmmN */ - o(0x280f); - o(0xc0 + (arg << 3)); - d = arg_prepare_reg(arg); - /* mov %xmm0, %rxx */ - o(0x66); - orex(1,d,0, 0x7e0f); - o(0xc0 + REG_VALUE(d)); - } - } else { - if (bt == VT_STRUCT) { - vtop->type.ref = NULL; - vtop->type.t = size > 4 ? VT_LLONG : size > 2 ? VT_INT - : size > 1 ? VT_SHORT : VT_BYTE; - } - - r = gv(RC_INT); - if (arg >= REGN) { - gen_offs_sp(0x89, r, arg*8); - } else { - d = arg_prepare_reg(arg); - orex(1,d,r,0x89); /* mov */ - o(0xc0 + REG_VALUE(r) * 8 + REG_VALUE(d)); - } - } - } - vtop--; - } - save_regs(0); - - /* Copy R10 and R11 into RCX and RDX, respectively */ - if (nb_args > 0) { - o(0xd1894c); /* mov %r10, %rcx */ - if (nb_args > 1) { - o(0xda894c); /* mov %r11, %rdx */ - } - } - - gcall_or_jmp(0); - - if ((vtop->r & VT_SYM) && vtop->sym->v == TOK_alloca) { - /* need to add the "func_scratch" area after alloca */ - o(0x0548), gen_le32(func_alloca), func_alloca = ind - 4; - } - - /* other compilers don't clear the upper bits when returning char/short */ - bt = vtop->type.ref->type.t & (VT_BTYPE | VT_UNSIGNED); - if (bt == (VT_BYTE | VT_UNSIGNED)) - o(0xc0b60f); /* movzbl %al, %eax */ - else if (bt == VT_BYTE) - o(0xc0be0f); /* movsbl %al, %eax */ - else if (bt == VT_SHORT) - o(0x98); /* cwtl */ - else if (bt == (VT_SHORT | VT_UNSIGNED)) - o(0xc0b70f); /* movzbl %al, %eax */ -#if 0 /* handled in gen_cast() */ - else if (bt == VT_INT) - o(0x9848); /* cltq */ - else if (bt == (VT_INT | VT_UNSIGNED)) - o(0xc089); /* mov %eax,%eax */ -#endif - vtop--; -} - - -#define FUNC_PROLOG_SIZE 11 - -/* generate function prolog of type 't' */ -void gfunc_prolog(CType *func_type) -{ - int addr, reg_param_index, bt, size; - Sym *sym; - CType *type; - - func_ret_sub = 0; - func_scratch = 0; - func_alloca = 0; - loc = 0; - - addr = PTR_SIZE * 2; - ind += FUNC_PROLOG_SIZE; - func_sub_sp_offset = ind; - reg_param_index = 0; - - sym = func_type->ref; - - /* if the function returns a structure, then add an - implicit pointer parameter */ - func_vt = sym->type; - func_var = (sym->f.func_type == FUNC_ELLIPSIS); - size = gfunc_arg_size(&func_vt); - if (!using_regs(size)) { - gen_modrm64(0x89, arg_regs[reg_param_index], VT_LOCAL, NULL, addr); - func_vc = addr; - reg_param_index++; - addr += 8; - } - - /* define parameters */ - while ((sym = sym->next) != NULL) { - type = &sym->type; - bt = type->t & VT_BTYPE; - size = gfunc_arg_size(type); - if (!using_regs(size)) { - if (reg_param_index < REGN) { - gen_modrm64(0x89, arg_regs[reg_param_index], VT_LOCAL, NULL, addr); - } - sym_push(sym->v & ~SYM_FIELD, type, VT_LLOCAL | VT_LVAL, addr); - } else { - if (reg_param_index < REGN) { - /* save arguments passed by register */ - if ((bt == VT_FLOAT) || (bt == VT_DOUBLE)) { - if (tcc_state->nosse) - tcc_error("SSE disabled"); - o(0xd60f66); /* movq */ - gen_modrm(reg_param_index, VT_LOCAL, NULL, addr); - } else { - gen_modrm64(0x89, arg_regs[reg_param_index], VT_LOCAL, NULL, addr); - } - } - sym_push(sym->v & ~SYM_FIELD, type, VT_LOCAL | VT_LVAL, addr); - } - addr += 8; - reg_param_index++; - } - - while (reg_param_index < REGN) { - if (func_type->ref->f.func_type == FUNC_ELLIPSIS) { - gen_modrm64(0x89, arg_regs[reg_param_index], VT_LOCAL, NULL, addr); - addr += 8; - } - reg_param_index++; - } -} - -/* generate function epilog */ -void gfunc_epilog(void) -{ - int v, saved_ind; - - o(0xc9); /* leave */ - if (func_ret_sub == 0) { - o(0xc3); /* ret */ - } else { - o(0xc2); /* ret n */ - g(func_ret_sub); - g(func_ret_sub >> 8); - } - - saved_ind = ind; - ind = func_sub_sp_offset - FUNC_PROLOG_SIZE; - /* align local size to word & save local variables */ - func_scratch = (func_scratch + 15) & -16; - v = (func_scratch + -loc + 15) & -16; - - if (v >= 4096) { - Sym *sym = external_global_sym(TOK___chkstk, &func_old_type, 0); - oad(0xb8, v); /* mov stacksize, %eax */ - oad(0xe8, 0); /* call __chkstk, (does the stackframe too) */ - greloca(cur_text_section, sym, ind-4, R_X86_64_PC32, -4); - o(0x90); /* fill for FUNC_PROLOG_SIZE = 11 bytes */ - } else { - o(0xe5894855); /* push %rbp, mov %rsp, %rbp */ - o(0xec8148); /* sub rsp, stacksize */ - gen_le32(v); - } - - /* add the "func_scratch" area after each alloca seen */ - while (func_alloca) { - unsigned char *ptr = cur_text_section->data + func_alloca; - func_alloca = read32le(ptr); - write32le(ptr, func_scratch); - } - - cur_text_section->data_offset = saved_ind; - pe_add_unwind_data(ind, saved_ind, v); - ind = cur_text_section->data_offset; -} - -#else - -static void gadd_sp(int val) -{ - if (val == (char)val) { - o(0xc48348); - g(val); - } else { - oad(0xc48148, val); /* add $xxx, %rsp */ - } -} - -typedef enum X86_64_Mode { - x86_64_mode_none, - x86_64_mode_memory, - x86_64_mode_integer, - x86_64_mode_sse, - x86_64_mode_x87 -} X86_64_Mode; - -static X86_64_Mode classify_x86_64_merge(X86_64_Mode a, X86_64_Mode b) -{ - if (a == b) - return a; - else if (a == x86_64_mode_none) - return b; - else if (b == x86_64_mode_none) - return a; - else if ((a == x86_64_mode_memory) || (b == x86_64_mode_memory)) - return x86_64_mode_memory; - else if ((a == x86_64_mode_integer) || (b == x86_64_mode_integer)) - return x86_64_mode_integer; - else if ((a == x86_64_mode_x87) || (b == x86_64_mode_x87)) - return x86_64_mode_memory; - else - return x86_64_mode_sse; -} - -static X86_64_Mode classify_x86_64_inner(CType *ty) -{ - X86_64_Mode mode; - Sym *f; - - switch (ty->t & VT_BTYPE) { - case VT_VOID: return x86_64_mode_none; - - case VT_INT: - case VT_BYTE: - case VT_SHORT: - case VT_LLONG: - case VT_BOOL: - case VT_PTR: - case VT_FUNC: - return x86_64_mode_integer; - - case VT_FLOAT: - case VT_DOUBLE: return x86_64_mode_sse; - - case VT_LDOUBLE: return x86_64_mode_x87; - - case VT_STRUCT: - f = ty->ref; - - mode = x86_64_mode_none; - for (f = f->next; f; f = f->next) - mode = classify_x86_64_merge(mode, classify_x86_64_inner(&f->type)); - - return mode; - } - assert(0); - return 0; -} - -static X86_64_Mode classify_x86_64_arg(CType *ty, CType *ret, int *psize, int *palign, int *reg_count) -{ - X86_64_Mode mode; - int size, align, ret_t = 0; - - if (ty->t & (VT_BITFIELD|VT_ARRAY)) { - *psize = 8; - *palign = 8; - *reg_count = 1; - ret_t = ty->t; - mode = x86_64_mode_integer; - } else { - size = type_size(ty, &align); - *psize = (size + 7) & ~7; - *palign = (align + 7) & ~7; - - if (size > 16) { - mode = x86_64_mode_memory; - } else { - mode = classify_x86_64_inner(ty); - switch (mode) { - case x86_64_mode_integer: - if (size > 8) { - *reg_count = 2; - ret_t = VT_QLONG; - } else { - *reg_count = 1; - ret_t = (size > 4) ? VT_LLONG : VT_INT; - } - break; - - case x86_64_mode_x87: - *reg_count = 1; - ret_t = VT_LDOUBLE; - break; - - case x86_64_mode_sse: - if (size > 8) { - *reg_count = 2; - ret_t = VT_QFLOAT; - } else { - *reg_count = 1; - ret_t = (size > 4) ? VT_DOUBLE : VT_FLOAT; - } - break; - default: break; /* nothing to be done for x86_64_mode_memory and x86_64_mode_none*/ - } - } - } - - if (ret) { - ret->ref = NULL; - ret->t = ret_t; - } - - return mode; -} - -ST_FUNC int classify_x86_64_va_arg(CType *ty) -{ - /* This definition must be synced with stdarg.h */ - enum __va_arg_type { - __va_gen_reg, __va_float_reg, __va_stack - }; - int size, align, reg_count; - X86_64_Mode mode = classify_x86_64_arg(ty, NULL, &size, &align, ®_count); - switch (mode) { - default: return __va_stack; - case x86_64_mode_integer: return __va_gen_reg; - case x86_64_mode_sse: return __va_float_reg; - } -} - -/* Return the number of registers needed to return the struct, or 0 if - returning via struct pointer. */ -ST_FUNC int gfunc_sret(CType *vt, int variadic, CType *ret, int *ret_align, int *regsize) -{ - int size, align, reg_count; - *ret_align = 1; // Never have to re-align return values for x86-64 - *regsize = 8; - return (classify_x86_64_arg(vt, ret, &size, &align, ®_count) != x86_64_mode_memory); -} - -#define REGN 6 -static const uint8_t arg_regs[REGN] = { - TREG_RDI, TREG_RSI, TREG_RDX, TREG_RCX, TREG_R8, TREG_R9 -}; - -static int arg_prepare_reg(int idx) { - if (idx == 2 || idx == 3) - /* idx=2: r10, idx=3: r11 */ - return idx + 8; - else - return arg_regs[idx]; -} - -/* Generate function call. The function address is pushed first, then - all the parameters in call order. This functions pops all the - parameters and the function address. */ -void gfunc_call(int nb_args) -{ - X86_64_Mode mode; - CType type; - int size, align, r, args_size, stack_adjust, i, reg_count; - int nb_reg_args = 0; - int nb_sse_args = 0; - int sse_reg, gen_reg; - char _onstack[nb_args], *onstack = _onstack; - - /* calculate the number of integer/float register arguments, remember - arguments to be passed via stack (in onstack[]), and also remember - if we have to align the stack pointer to 16 (onstack[i] == 2). Needs - to be done in a left-to-right pass over arguments. */ - stack_adjust = 0; - for(i = nb_args - 1; i >= 0; i--) { - mode = classify_x86_64_arg(&vtop[-i].type, NULL, &size, &align, ®_count); - if (mode == x86_64_mode_sse && nb_sse_args + reg_count <= 8) { - nb_sse_args += reg_count; - onstack[i] = 0; - } else if (mode == x86_64_mode_integer && nb_reg_args + reg_count <= REGN) { - nb_reg_args += reg_count; - onstack[i] = 0; - } else if (mode == x86_64_mode_none) { - onstack[i] = 0; - } else { - if (align == 16 && (stack_adjust &= 15)) { - onstack[i] = 2; - stack_adjust = 0; - } else - onstack[i] = 1; - stack_adjust += size; - } - } - - if (nb_sse_args && tcc_state->nosse) - tcc_error("SSE disabled but floating point arguments passed"); - - /* fetch cpu flag before generating any code */ - if (vtop >= vstack && (vtop->r & VT_VALMASK) == VT_CMP) - gv(RC_INT); - - /* for struct arguments, we need to call memcpy and the function - call breaks register passing arguments we are preparing. - So, we process arguments which will be passed by stack first. */ - gen_reg = nb_reg_args; - sse_reg = nb_sse_args; - args_size = 0; - stack_adjust &= 15; - for (i = 0; i < nb_args;) { - mode = classify_x86_64_arg(&vtop[-i].type, NULL, &size, &align, ®_count); - if (!onstack[i]) { - ++i; - continue; - } - /* Possibly adjust stack to align SSE boundary. We're processing - args from right to left while allocating happens left to right - (stack grows down), so the adjustment needs to happen _after_ - an argument that requires it. */ - if (stack_adjust) { - o(0x50); /* push %rax; aka sub $8,%rsp */ - args_size += 8; - stack_adjust = 0; - } - if (onstack[i] == 2) - stack_adjust = 1; - - vrotb(i+1); - - switch (vtop->type.t & VT_BTYPE) { - case VT_STRUCT: - /* allocate the necessary size on stack */ - o(0x48); - oad(0xec81, size); /* sub $xxx, %rsp */ - /* generate structure store */ - r = get_reg(RC_INT); - orex(1, r, 0, 0x89); /* mov %rsp, r */ - o(0xe0 + REG_VALUE(r)); - vset(&vtop->type, r | VT_LVAL, 0); - vswap(); - vstore(); - break; - - case VT_LDOUBLE: - gv(RC_ST0); - oad(0xec8148, size); /* sub $xxx, %rsp */ - o(0x7cdb); /* fstpt 0(%rsp) */ - g(0x24); - g(0x00); - break; - - case VT_FLOAT: - case VT_DOUBLE: - assert(mode == x86_64_mode_sse); - r = gv(RC_FLOAT); - o(0x50); /* push $rax */ - /* movq %xmmN, (%rsp) */ - o(0xd60f66); - o(0x04 + REG_VALUE(r)*8); - o(0x24); - break; - - default: - assert(mode == x86_64_mode_integer); - /* simple type */ - /* XXX: implicit cast ? */ - r = gv(RC_INT); - orex(0,r,0,0x50 + REG_VALUE(r)); /* push r */ - break; - } - args_size += size; - - vpop(); - --nb_args; - onstack++; - } - - /* XXX This should be superfluous. */ - save_regs(0); /* save used temporary registers */ - - /* then, we prepare register passing arguments. - Note that we cannot set RDX and RCX in this loop because gv() - may break these temporary registers. Let's use R10 and R11 - instead of them */ - assert(gen_reg <= REGN); - assert(sse_reg <= 8); - for(i = 0; i < nb_args; i++) { - mode = classify_x86_64_arg(&vtop->type, &type, &size, &align, ®_count); - /* Alter stack entry type so that gv() knows how to treat it */ - vtop->type = type; - if (mode == x86_64_mode_sse) { - if (reg_count == 2) { - sse_reg -= 2; - gv(RC_FRET); /* Use pair load into xmm0 & xmm1 */ - if (sse_reg) { /* avoid redundant movaps %xmm0, %xmm0 */ - /* movaps %xmm0, %xmmN */ - o(0x280f); - o(0xc0 + (sse_reg << 3)); - /* movaps %xmm1, %xmmN */ - o(0x280f); - o(0xc1 + ((sse_reg+1) << 3)); - } - } else { - assert(reg_count == 1); - --sse_reg; - /* Load directly to register */ - gv(RC_XMM0 << sse_reg); - } - } else if (mode == x86_64_mode_integer) { - /* simple type */ - /* XXX: implicit cast ? */ - int d; - gen_reg -= reg_count; - r = gv(RC_INT); - d = arg_prepare_reg(gen_reg); - orex(1,d,r,0x89); /* mov */ - o(0xc0 + REG_VALUE(r) * 8 + REG_VALUE(d)); - if (reg_count == 2) { - d = arg_prepare_reg(gen_reg+1); - orex(1,d,vtop->r2,0x89); /* mov */ - o(0xc0 + REG_VALUE(vtop->r2) * 8 + REG_VALUE(d)); - } - } - vtop--; - } - assert(gen_reg == 0); - assert(sse_reg == 0); - - /* We shouldn't have many operands on the stack anymore, but the - call address itself is still there, and it might be in %eax - (or edx/ecx) currently, which the below writes would clobber. - So evict all remaining operands here. */ - save_regs(0); - - /* Copy R10 and R11 into RDX and RCX, respectively */ - if (nb_reg_args > 2) { - o(0xd2894c); /* mov %r10, %rdx */ - if (nb_reg_args > 3) { - o(0xd9894c); /* mov %r11, %rcx */ - } - } - - if (vtop->type.ref->f.func_type != FUNC_NEW) /* implies FUNC_OLD or FUNC_ELLIPSIS */ - oad(0xb8, nb_sse_args < 8 ? nb_sse_args : 8); /* mov nb_sse_args, %eax */ - gcall_or_jmp(0); - if (args_size) - gadd_sp(args_size); - vtop--; -} - - -#define FUNC_PROLOG_SIZE 11 - -static void push_arg_reg(int i) { - loc -= 8; - gen_modrm64(0x89, arg_regs[i], VT_LOCAL, NULL, loc); -} - -/* generate function prolog of type 't' */ -void gfunc_prolog(CType *func_type) -{ - X86_64_Mode mode; - int i, addr, align, size, reg_count; - int param_addr = 0, reg_param_index, sse_param_index; - Sym *sym; - CType *type; - - sym = func_type->ref; - addr = PTR_SIZE * 2; - loc = 0; - ind += FUNC_PROLOG_SIZE; - func_sub_sp_offset = ind; - func_ret_sub = 0; - - if (sym->f.func_type == FUNC_ELLIPSIS) { - int seen_reg_num, seen_sse_num, seen_stack_size; - seen_reg_num = seen_sse_num = 0; - /* frame pointer and return address */ - seen_stack_size = PTR_SIZE * 2; - /* count the number of seen parameters */ - sym = func_type->ref; - while ((sym = sym->next) != NULL) { - type = &sym->type; - mode = classify_x86_64_arg(type, NULL, &size, &align, ®_count); - switch (mode) { - default: - stack_arg: - seen_stack_size = ((seen_stack_size + align - 1) & -align) + size; - break; - - case x86_64_mode_integer: - if (seen_reg_num + reg_count > REGN) - goto stack_arg; - seen_reg_num += reg_count; - break; - - case x86_64_mode_sse: - if (seen_sse_num + reg_count > 8) - goto stack_arg; - seen_sse_num += reg_count; - break; - } - } - - loc -= 16; - /* movl $0x????????, -0x10(%rbp) */ - o(0xf045c7); - gen_le32(seen_reg_num * 8); - /* movl $0x????????, -0xc(%rbp) */ - o(0xf445c7); - gen_le32(seen_sse_num * 16 + 48); - /* movl $0x????????, -0x8(%rbp) */ - o(0xf845c7); - gen_le32(seen_stack_size); - - /* save all register passing arguments */ - for (i = 0; i < 8; i++) { - loc -= 16; - if (!tcc_state->nosse) { - o(0xd60f66); /* movq */ - gen_modrm(7 - i, VT_LOCAL, NULL, loc); - } - /* movq $0, loc+8(%rbp) */ - o(0x85c748); - gen_le32(loc + 8); - gen_le32(0); - } - for (i = 0; i < REGN; i++) { - push_arg_reg(REGN-1-i); - } - } - - sym = func_type->ref; - reg_param_index = 0; - sse_param_index = 0; - - /* if the function returns a structure, then add an - implicit pointer parameter */ - func_vt = sym->type; - mode = classify_x86_64_arg(&func_vt, NULL, &size, &align, ®_count); - if (mode == x86_64_mode_memory) { - push_arg_reg(reg_param_index); - func_vc = loc; - reg_param_index++; - } - /* define parameters */ - while ((sym = sym->next) != NULL) { - type = &sym->type; - mode = classify_x86_64_arg(type, NULL, &size, &align, ®_count); - switch (mode) { - case x86_64_mode_sse: - if (tcc_state->nosse) - tcc_error("SSE disabled but floating point arguments used"); - if (sse_param_index + reg_count <= 8) { - /* save arguments passed by register */ - loc -= reg_count * 8; - param_addr = loc; - for (i = 0; i < reg_count; ++i) { - o(0xd60f66); /* movq */ - gen_modrm(sse_param_index, VT_LOCAL, NULL, param_addr + i*8); - ++sse_param_index; - } - } else { - addr = (addr + align - 1) & -align; - param_addr = addr; - addr += size; - } - break; - - case x86_64_mode_memory: - case x86_64_mode_x87: - addr = (addr + align - 1) & -align; - param_addr = addr; - addr += size; - break; - - case x86_64_mode_integer: { - if (reg_param_index + reg_count <= REGN) { - /* save arguments passed by register */ - loc -= reg_count * 8; - param_addr = loc; - for (i = 0; i < reg_count; ++i) { - gen_modrm64(0x89, arg_regs[reg_param_index], VT_LOCAL, NULL, param_addr + i*8); - ++reg_param_index; - } - } else { - addr = (addr + align - 1) & -align; - param_addr = addr; - addr += size; - } - break; - } - default: break; /* nothing to be done for x86_64_mode_none */ - } - sym_push(sym->v & ~SYM_FIELD, type, - VT_LOCAL | VT_LVAL, param_addr); - } - -#ifdef CONFIG_TCC_BCHECK - /* leave some room for bound checking code */ - if (tcc_state->do_bounds_check) { - func_bound_offset = lbounds_section->data_offset; - func_bound_ind = ind; - oad(0xb8, 0); /* lbound section pointer */ - o(0xc78948); /* mov %rax,%rdi ## first arg in %rdi, this must be ptr */ - oad(0xb8, 0); /* call to function */ - } -#endif -} - -/* generate function epilog */ -void gfunc_epilog(void) -{ - int v, saved_ind; - -#ifdef CONFIG_TCC_BCHECK - if (tcc_state->do_bounds_check - && func_bound_offset != lbounds_section->data_offset) - { - addr_t saved_ind; - addr_t *bounds_ptr; - Sym *sym_data; - - /* add end of table info */ - bounds_ptr = section_ptr_add(lbounds_section, sizeof(addr_t)); - *bounds_ptr = 0; - - /* generate bound local allocation */ - sym_data = get_sym_ref(&char_pointer_type, lbounds_section, - func_bound_offset, lbounds_section->data_offset); - saved_ind = ind; - ind = func_bound_ind; - greloca(cur_text_section, sym_data, ind + 1, R_X86_64_64, 0); - ind = ind + 5 + 3; - gen_static_call(TOK___bound_local_new); - ind = saved_ind; - - /* generate bound check local freeing */ - o(0x5250); /* save returned value, if any */ - greloca(cur_text_section, sym_data, ind + 1, R_X86_64_64, 0); - oad(0xb8, 0); /* mov xxx, %rax */ - o(0xc78948); /* mov %rax,%rdi # first arg in %rdi, this must be ptr */ - gen_static_call(TOK___bound_local_delete); - o(0x585a); /* restore returned value, if any */ - } -#endif - o(0xc9); /* leave */ - if (func_ret_sub == 0) { - o(0xc3); /* ret */ - } else { - o(0xc2); /* ret n */ - g(func_ret_sub); - g(func_ret_sub >> 8); - } - /* align local size to word & save local variables */ - v = (-loc + 15) & -16; - saved_ind = ind; - ind = func_sub_sp_offset - FUNC_PROLOG_SIZE; - o(0xe5894855); /* push %rbp, mov %rsp, %rbp */ - o(0xec8148); /* sub rsp, stacksize */ - gen_le32(v); - ind = saved_ind; -} - -#endif /* not PE */ - -/* generate a jump to a label */ -int gjmp(int t) -{ - return gjmp2(0xe9, t); -} - -/* generate a jump to a fixed address */ -void gjmp_addr(int a) -{ - int r; - r = a - ind - 2; - if (r == (char)r) { - g(0xeb); - g(r); - } else { - oad(0xe9, a - ind - 5); - } -} - -ST_FUNC void gtst_addr(int inv, int a) -{ - int v = vtop->r & VT_VALMASK; - if (v == VT_CMP) { - inv ^= (vtop--)->c.i; - a -= ind + 2; - if (a == (char)a) { - g(inv - 32); - g(a); - } else { - g(0x0f); - oad(inv - 16, a - 4); - } - } else if ((v & ~1) == VT_JMP) { - if ((v & 1) != inv) { - gjmp_addr(a); - gsym(vtop->c.i); - } else { - gsym(vtop->c.i); - o(0x05eb); - gjmp_addr(a); - } - vtop--; - } -} - -/* generate a test. set 'inv' to invert test. Stack entry is popped */ -ST_FUNC int gtst(int inv, int t) -{ - int v = vtop->r & VT_VALMASK; - - if (nocode_wanted) { - ; - } else if (v == VT_CMP) { - /* fast case : can jump directly since flags are set */ - if (vtop->c.i & 0x100) - { - /* This was a float compare. If the parity flag is set - the result was unordered. For anything except != this - means false and we don't jump (anding both conditions). - For != this means true (oring both). - Take care about inverting the test. We need to jump - to our target if the result was unordered and test wasn't NE, - otherwise if unordered we don't want to jump. */ - vtop->c.i &= ~0x100; - if (inv == (vtop->c.i == TOK_NE)) - o(0x067a); /* jp +6 */ - else - { - g(0x0f); - t = gjmp2(0x8a, t); /* jp t */ - } - } - g(0x0f); - t = gjmp2((vtop->c.i - 16) ^ inv, t); - } else if (v == VT_JMP || v == VT_JMPI) { - /* && or || optimization */ - if ((v & 1) == inv) { - /* insert vtop->c jump list in t */ - uint32_t n1, n = vtop->c.i; - if (n) { - while ((n1 = read32le(cur_text_section->data + n))) - n = n1; - write32le(cur_text_section->data + n, t); - t = vtop->c.i; - } - } else { - t = gjmp(t); - gsym(vtop->c.i); - } - } - vtop--; - return t; -} - -/* generate an integer binary operation */ -void gen_opi(int op) -{ - int r, fr, opc, c; - int ll, uu, cc; - - ll = is64_type(vtop[-1].type.t); - uu = (vtop[-1].type.t & VT_UNSIGNED) != 0; - cc = (vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST; - - switch(op) { - case '+': - case TOK_ADDC1: /* add with carry generation */ - opc = 0; - gen_op8: - if (cc && (!ll || (int)vtop->c.i == vtop->c.i)) { - /* constant case */ - vswap(); - r = gv(RC_INT); - vswap(); - c = vtop->c.i; - if (c == (char)c) { - /* XXX: generate inc and dec for smaller code ? */ - orex(ll, r, 0, 0x83); - o(0xc0 | (opc << 3) | REG_VALUE(r)); - g(c); - } else { - orex(ll, r, 0, 0x81); - oad(0xc0 | (opc << 3) | REG_VALUE(r), c); - } - } else { - gv2(RC_INT, RC_INT); - r = vtop[-1].r; - fr = vtop[0].r; - orex(ll, r, fr, (opc << 3) | 0x01); - o(0xc0 + REG_VALUE(r) + REG_VALUE(fr) * 8); - } - vtop--; - if (op >= TOK_ULT && op <= TOK_GT) { - vtop->r = VT_CMP; - vtop->c.i = op; - } - break; - case '-': - case TOK_SUBC1: /* sub with carry generation */ - opc = 5; - goto gen_op8; - case TOK_ADDC2: /* add with carry use */ - opc = 2; - goto gen_op8; - case TOK_SUBC2: /* sub with carry use */ - opc = 3; - goto gen_op8; - case '&': - opc = 4; - goto gen_op8; - case '^': - opc = 6; - goto gen_op8; - case '|': - opc = 1; - goto gen_op8; - case '*': - gv2(RC_INT, RC_INT); - r = vtop[-1].r; - fr = vtop[0].r; - orex(ll, fr, r, 0xaf0f); /* imul fr, r */ - o(0xc0 + REG_VALUE(fr) + REG_VALUE(r) * 8); - vtop--; - break; - case TOK_SHL: - opc = 4; - goto gen_shift; - case TOK_SHR: - opc = 5; - goto gen_shift; - case TOK_SAR: - opc = 7; - gen_shift: - opc = 0xc0 | (opc << 3); - if (cc) { - /* constant case */ - vswap(); - r = gv(RC_INT); - vswap(); - orex(ll, r, 0, 0xc1); /* shl/shr/sar $xxx, r */ - o(opc | REG_VALUE(r)); - g(vtop->c.i & (ll ? 63 : 31)); - } else { - /* we generate the shift in ecx */ - gv2(RC_INT, RC_RCX); - r = vtop[-1].r; - orex(ll, r, 0, 0xd3); /* shl/shr/sar %cl, r */ - o(opc | REG_VALUE(r)); - } - vtop--; - break; - case TOK_UDIV: - case TOK_UMOD: - uu = 1; - goto divmod; - case '/': - case '%': - case TOK_PDIV: - uu = 0; - divmod: - /* first operand must be in eax */ - /* XXX: need better constraint for second operand */ - gv2(RC_RAX, RC_RCX); - r = vtop[-1].r; - fr = vtop[0].r; - vtop--; - save_reg(TREG_RDX); - orex(ll, 0, 0, uu ? 0xd231 : 0x99); /* xor %edx,%edx : cqto */ - orex(ll, fr, 0, 0xf7); /* div fr, %eax */ - o((uu ? 0xf0 : 0xf8) + REG_VALUE(fr)); - if (op == '%' || op == TOK_UMOD) - r = TREG_RDX; - else - r = TREG_RAX; - vtop->r = r; - break; - default: - opc = 7; - goto gen_op8; - } -} - -void gen_opl(int op) -{ - gen_opi(op); -} - -/* generate a floating point operation 'v = t1 op t2' instruction. The - two operands are guaranteed to have the same floating point type */ -/* XXX: need to use ST1 too */ -void gen_opf(int op) -{ - int a, ft, fc, swapped, r; - int float_type = - (vtop->type.t & VT_BTYPE) == VT_LDOUBLE ? RC_ST0 : RC_FLOAT; - - /* convert constants to memory references */ - if ((vtop[-1].r & (VT_VALMASK | VT_LVAL)) == VT_CONST) { - vswap(); - gv(float_type); - vswap(); - } - if ((vtop[0].r & (VT_VALMASK | VT_LVAL)) == VT_CONST) - gv(float_type); - - /* must put at least one value in the floating point register */ - if ((vtop[-1].r & VT_LVAL) && - (vtop[0].r & VT_LVAL)) { - vswap(); - gv(float_type); - vswap(); - } - swapped = 0; - /* swap the stack if needed so that t1 is the register and t2 is - the memory reference */ - if (vtop[-1].r & VT_LVAL) { - vswap(); - swapped = 1; - } - if ((vtop->type.t & VT_BTYPE) == VT_LDOUBLE) { - if (op >= TOK_ULT && op <= TOK_GT) { - /* load on stack second operand */ - load(TREG_ST0, vtop); - save_reg(TREG_RAX); /* eax is used by FP comparison code */ - if (op == TOK_GE || op == TOK_GT) - swapped = !swapped; - else if (op == TOK_EQ || op == TOK_NE) - swapped = 0; - if (swapped) - o(0xc9d9); /* fxch %st(1) */ - if (op == TOK_EQ || op == TOK_NE) - o(0xe9da); /* fucompp */ - else - o(0xd9de); /* fcompp */ - o(0xe0df); /* fnstsw %ax */ - if (op == TOK_EQ) { - o(0x45e480); /* and $0x45, %ah */ - o(0x40fC80); /* cmp $0x40, %ah */ - } else if (op == TOK_NE) { - o(0x45e480); /* and $0x45, %ah */ - o(0x40f480); /* xor $0x40, %ah */ - op = TOK_NE; - } else if (op == TOK_GE || op == TOK_LE) { - o(0x05c4f6); /* test $0x05, %ah */ - op = TOK_EQ; - } else { - o(0x45c4f6); /* test $0x45, %ah */ - op = TOK_EQ; - } - vtop--; - vtop->r = VT_CMP; - vtop->c.i = op; - } else { - /* no memory reference possible for long double operations */ - load(TREG_ST0, vtop); - swapped = !swapped; - - switch(op) { - default: - case '+': - a = 0; - break; - case '-': - a = 4; - if (swapped) - a++; - break; - case '*': - a = 1; - break; - case '/': - a = 6; - if (swapped) - a++; - break; - } - ft = vtop->type.t; - fc = vtop->c.i; - o(0xde); /* fxxxp %st, %st(1) */ - o(0xc1 + (a << 3)); - vtop--; - } - } else { - if (op >= TOK_ULT && op <= TOK_GT) { - /* if saved lvalue, then we must reload it */ - r = vtop->r; - fc = vtop->c.i; - if ((r & VT_VALMASK) == VT_LLOCAL) { - SValue v1; - r = get_reg(RC_INT); - v1.type.t = VT_PTR; - v1.r = VT_LOCAL | VT_LVAL; - v1.c.i = fc; - load(r, &v1); - fc = 0; - } - - if (op == TOK_EQ || op == TOK_NE) { - swapped = 0; - } else { - if (op == TOK_LE || op == TOK_LT) - swapped = !swapped; - if (op == TOK_LE || op == TOK_GE) { - op = 0x93; /* setae */ - } else { - op = 0x97; /* seta */ - } - } - - if (swapped) { - gv(RC_FLOAT); - vswap(); - } - assert(!(vtop[-1].r & VT_LVAL)); - - if ((vtop->type.t & VT_BTYPE) == VT_DOUBLE) - o(0x66); - if (op == TOK_EQ || op == TOK_NE) - o(0x2e0f); /* ucomisd */ - else - o(0x2f0f); /* comisd */ - - if (vtop->r & VT_LVAL) { - gen_modrm(vtop[-1].r, r, vtop->sym, fc); - } else { - o(0xc0 + REG_VALUE(vtop[0].r) + REG_VALUE(vtop[-1].r)*8); - } - - vtop--; - vtop->r = VT_CMP; - vtop->c.i = op | 0x100; - } else { - assert((vtop->type.t & VT_BTYPE) != VT_LDOUBLE); - switch(op) { - default: - case '+': - a = 0; - break; - case '-': - a = 4; - break; - case '*': - a = 1; - break; - case '/': - a = 6; - break; - } - ft = vtop->type.t; - fc = vtop->c.i; - assert((ft & VT_BTYPE) != VT_LDOUBLE); - - r = vtop->r; - /* if saved lvalue, then we must reload it */ - if ((vtop->r & VT_VALMASK) == VT_LLOCAL) { - SValue v1; - r = get_reg(RC_INT); - v1.type.t = VT_PTR; - v1.r = VT_LOCAL | VT_LVAL; - v1.c.i = fc; - load(r, &v1); - fc = 0; - } - - assert(!(vtop[-1].r & VT_LVAL)); - if (swapped) { - assert(vtop->r & VT_LVAL); - gv(RC_FLOAT); - vswap(); - } - - if ((ft & VT_BTYPE) == VT_DOUBLE) { - o(0xf2); - } else { - o(0xf3); - } - o(0x0f); - o(0x58 + a); - - if (vtop->r & VT_LVAL) { - gen_modrm(vtop[-1].r, r, vtop->sym, fc); - } else { - o(0xc0 + REG_VALUE(vtop[0].r) + REG_VALUE(vtop[-1].r)*8); - } - - vtop--; - } - } -} - -/* convert integers to fp 't' type. Must handle 'int', 'unsigned int' - and 'long long' cases. */ -void gen_cvt_itof(int t) -{ - if ((t & VT_BTYPE) == VT_LDOUBLE) { - save_reg(TREG_ST0); - gv(RC_INT); - if ((vtop->type.t & VT_BTYPE) == VT_LLONG) { - /* signed long long to float/double/long double (unsigned case - is handled generically) */ - o(0x50 + (vtop->r & VT_VALMASK)); /* push r */ - o(0x242cdf); /* fildll (%rsp) */ - o(0x08c48348); /* add $8, %rsp */ - } else if ((vtop->type.t & (VT_BTYPE | VT_UNSIGNED)) == - (VT_INT | VT_UNSIGNED)) { - /* unsigned int to float/double/long double */ - o(0x6a); /* push $0 */ - g(0x00); - o(0x50 + (vtop->r & VT_VALMASK)); /* push r */ - o(0x242cdf); /* fildll (%rsp) */ - o(0x10c48348); /* add $16, %rsp */ - } else { - /* int to float/double/long double */ - o(0x50 + (vtop->r & VT_VALMASK)); /* push r */ - o(0x2404db); /* fildl (%rsp) */ - o(0x08c48348); /* add $8, %rsp */ - } - vtop->r = TREG_ST0; - } else { - int r = get_reg(RC_FLOAT); - gv(RC_INT); - o(0xf2 + ((t & VT_BTYPE) == VT_FLOAT?1:0)); - if ((vtop->type.t & (VT_BTYPE | VT_UNSIGNED)) == - (VT_INT | VT_UNSIGNED) || - (vtop->type.t & VT_BTYPE) == VT_LLONG) { - o(0x48); /* REX */ - } - o(0x2a0f); - o(0xc0 + (vtop->r & VT_VALMASK) + REG_VALUE(r)*8); /* cvtsi2sd */ - vtop->r = r; - } -} - -/* convert from one floating point type to another */ -void gen_cvt_ftof(int t) -{ - int ft, bt, tbt; - - ft = vtop->type.t; - bt = ft & VT_BTYPE; - tbt = t & VT_BTYPE; - - if (bt == VT_FLOAT) { - gv(RC_FLOAT); - if (tbt == VT_DOUBLE) { - o(0x140f); /* unpcklps */ - o(0xc0 + REG_VALUE(vtop->r)*9); - o(0x5a0f); /* cvtps2pd */ - o(0xc0 + REG_VALUE(vtop->r)*9); - } else if (tbt == VT_LDOUBLE) { - save_reg(RC_ST0); - /* movss %xmm0,-0x10(%rsp) */ - o(0x110ff3); - o(0x44 + REG_VALUE(vtop->r)*8); - o(0xf024); - o(0xf02444d9); /* flds -0x10(%rsp) */ - vtop->r = TREG_ST0; - } - } else if (bt == VT_DOUBLE) { - gv(RC_FLOAT); - if (tbt == VT_FLOAT) { - o(0x140f66); /* unpcklpd */ - o(0xc0 + REG_VALUE(vtop->r)*9); - o(0x5a0f66); /* cvtpd2ps */ - o(0xc0 + REG_VALUE(vtop->r)*9); - } else if (tbt == VT_LDOUBLE) { - save_reg(RC_ST0); - /* movsd %xmm0,-0x10(%rsp) */ - o(0x110ff2); - o(0x44 + REG_VALUE(vtop->r)*8); - o(0xf024); - o(0xf02444dd); /* fldl -0x10(%rsp) */ - vtop->r = TREG_ST0; - } - } else { - int r; - gv(RC_ST0); - r = get_reg(RC_FLOAT); - if (tbt == VT_DOUBLE) { - o(0xf0245cdd); /* fstpl -0x10(%rsp) */ - /* movsd -0x10(%rsp),%xmm0 */ - o(0x100ff2); - o(0x44 + REG_VALUE(r)*8); - o(0xf024); - vtop->r = r; - } else if (tbt == VT_FLOAT) { - o(0xf0245cd9); /* fstps -0x10(%rsp) */ - /* movss -0x10(%rsp),%xmm0 */ - o(0x100ff3); - o(0x44 + REG_VALUE(r)*8); - o(0xf024); - vtop->r = r; - } - } -} - -/* convert fp to int 't' type */ -void gen_cvt_ftoi(int t) -{ - int ft, bt, size, r; - ft = vtop->type.t; - bt = ft & VT_BTYPE; - if (bt == VT_LDOUBLE) { - gen_cvt_ftof(VT_DOUBLE); - bt = VT_DOUBLE; - } - - gv(RC_FLOAT); - if (t != VT_INT) - size = 8; - else - size = 4; - - r = get_reg(RC_INT); - if (bt == VT_FLOAT) { - o(0xf3); - } else if (bt == VT_DOUBLE) { - o(0xf2); - } else { - assert(0); - } - orex(size == 8, r, 0, 0x2c0f); /* cvttss2si or cvttsd2si */ - o(0xc0 + REG_VALUE(vtop->r) + REG_VALUE(r)*8); - vtop->r = r; -} - -/* computed goto support */ -void ggoto(void) -{ - gcall_or_jmp(1); - vtop--; -} - -/* Save the stack pointer onto the stack and return the location of its address */ -ST_FUNC void gen_vla_sp_save(int addr) { - /* mov %rsp,addr(%rbp)*/ - gen_modrm64(0x89, TREG_RSP, VT_LOCAL, NULL, addr); -} - -/* Restore the SP from a location on the stack */ -ST_FUNC void gen_vla_sp_restore(int addr) { - gen_modrm64(0x8b, TREG_RSP, VT_LOCAL, NULL, addr); -} - -#ifdef TCC_TARGET_PE -/* Save result of gen_vla_alloc onto the stack */ -ST_FUNC void gen_vla_result(int addr) { - /* mov %rax,addr(%rbp)*/ - gen_modrm64(0x89, TREG_RAX, VT_LOCAL, NULL, addr); -} -#endif - -/* Subtract from the stack pointer, and push the resulting value onto the stack */ -ST_FUNC void gen_vla_alloc(CType *type, int align) { -#ifdef TCC_TARGET_PE - /* alloca does more than just adjust %rsp on Windows */ - vpush_global_sym(&func_old_type, TOK_alloca); - vswap(); /* Move alloca ref past allocation size */ - gfunc_call(1); -#else - int r; - r = gv(RC_INT); /* allocation size */ - /* sub r,%rsp */ - o(0x2b48); - o(0xe0 | REG_VALUE(r)); - /* We align to 16 bytes rather than align */ - /* and ~15, %rsp */ - o(0xf0e48348); - vpop(); -#endif -} - - -/* end of x86-64 code generator */ -/*************************************************************/ -#endif /* ! TARGET_DEFS_ONLY */ -/******************************************************/ diff --git a/05/tcc-final-old/x86_64-link.c b/05/tcc-final-old/x86_64-link.c deleted file mode 100644 index a96144c..0000000 --- a/05/tcc-final-old/x86_64-link.c +++ /dev/null @@ -1,298 +0,0 @@ -#ifdef TARGET_DEFS_ONLY - -#define EM_TCC_TARGET EM_X86_64 - -/* relocation type for 32 bit data relocation */ -#define R_DATA_32 R_X86_64_32S -#define R_DATA_PTR R_X86_64_64 -#define R_JMP_SLOT R_X86_64_JUMP_SLOT -#define R_GLOB_DAT R_X86_64_GLOB_DAT -#define R_COPY R_X86_64_COPY -#define R_RELATIVE R_X86_64_RELATIVE - -#define R_NUM R_X86_64_NUM - -#define ELF_START_ADDR 0x400000 -#define ELF_PAGE_SIZE 0x200000 - -#define PCRELATIVE_DLLPLT 1 -#define RELOCATE_DLLPLT 1 - -#else /* !TARGET_DEFS_ONLY */ - -#include "tcc.h" - -/* Returns 1 for a code relocation, 0 for a data relocation. For unknown - relocations, returns -1. */ -int code_reloc (int reloc_type) -{ - switch (reloc_type) { - case R_X86_64_32: - case R_X86_64_32S: - case R_X86_64_64: - case R_X86_64_GOTPC32: - case R_X86_64_GOTPC64: - case R_X86_64_GOTPCREL: - case R_X86_64_GOTPCRELX: - case R_X86_64_REX_GOTPCRELX: - case R_X86_64_GOTTPOFF: - case R_X86_64_GOT32: - case R_X86_64_GOT64: - case R_X86_64_GLOB_DAT: - case R_X86_64_COPY: - case R_X86_64_RELATIVE: - case R_X86_64_GOTOFF64: - return 0; - - case R_X86_64_PC32: - case R_X86_64_PC64: - case R_X86_64_PLT32: - case R_X86_64_PLTOFF64: - case R_X86_64_JUMP_SLOT: - return 1; - } - - tcc_error ("Unknown relocation type: %d", reloc_type); - return -1; -} - -/* Returns an enumerator to describe whether and when the relocation needs a - GOT and/or PLT entry to be created. See tcc.h for a description of the - different values. */ -int gotplt_entry_type (int reloc_type) -{ - switch (reloc_type) { - case R_X86_64_GLOB_DAT: - case R_X86_64_JUMP_SLOT: - case R_X86_64_COPY: - case R_X86_64_RELATIVE: - return NO_GOTPLT_ENTRY; - - /* The following relocs wouldn't normally need GOT or PLT - slots, but we need them for simplicity in the link - editor part. See our caller for comments. */ - case R_X86_64_32: - case R_X86_64_32S: - case R_X86_64_64: - case R_X86_64_PC32: - case R_X86_64_PC64: - return AUTO_GOTPLT_ENTRY; - - case R_X86_64_GOTTPOFF: - return BUILD_GOT_ONLY; - - case R_X86_64_GOT32: - case R_X86_64_GOT64: - case R_X86_64_GOTPC32: - case R_X86_64_GOTPC64: - case R_X86_64_GOTOFF64: - case R_X86_64_GOTPCREL: - case R_X86_64_GOTPCRELX: - case R_X86_64_REX_GOTPCRELX: - case R_X86_64_PLT32: - case R_X86_64_PLTOFF64: - return ALWAYS_GOTPLT_ENTRY; - } - - tcc_error ("Unknown relocation type: %d", reloc_type); - return -1; -} - -ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr) -{ - Section *plt = s1->plt; - uint8_t *p; - int modrm; - unsigned plt_offset, relofs; - - modrm = 0x25; - - /* empty PLT: create PLT0 entry that pushes the library identifier - (GOT + PTR_SIZE) and jumps to ld.so resolution routine - (GOT + 2 * PTR_SIZE) */ - if (plt->data_offset == 0) { - p = section_ptr_add(plt, 16); - p[0] = 0xff; /* pushl got + PTR_SIZE */ - p[1] = modrm + 0x10; - write32le(p + 2, PTR_SIZE); - p[6] = 0xff; /* jmp *(got + PTR_SIZE * 2) */ - p[7] = modrm; - write32le(p + 8, PTR_SIZE * 2); - } - plt_offset = plt->data_offset; - - /* The PLT slot refers to the relocation entry it needs via offset. - The reloc entry is created below, so its offset is the current - data_offset */ - relofs = s1->got->reloc ? s1->got->reloc->data_offset : 0; - - /* Jump to GOT entry where ld.so initially put the address of ip + 4 */ - p = section_ptr_add(plt, 16); - p[0] = 0xff; /* jmp *(got + x) */ - p[1] = modrm; - write32le(p + 2, got_offset); - p[6] = 0x68; /* push $xxx */ - /* On x86-64, the relocation is referred to by _index_ */ - write32le(p + 7, relofs / sizeof (ElfW_Rel)); - p[11] = 0xe9; /* jmp plt_start */ - write32le(p + 12, -(plt->data_offset)); - return plt_offset; -} - -/* relocate the PLT: compute addresses and offsets in the PLT now that final - address for PLT and GOT are known (see fill_program_header) */ -ST_FUNC void relocate_plt(TCCState *s1) -{ - uint8_t *p, *p_end; - - if (!s1->plt) - return; - - p = s1->plt->data; - p_end = p + s1->plt->data_offset; - - if (p < p_end) { - int x = s1->got->sh_addr - s1->plt->sh_addr - 6; - add32le(p + 2, x); - add32le(p + 8, x - 6); - p += 16; - while (p < p_end) { - add32le(p + 2, x + s1->plt->data - p); - p += 16; - } - } -} - -static ElfW_Rel *qrel; /* ptr to next reloc entry reused */ - -void relocate_init(Section *sr) -{ - qrel = (ElfW_Rel *) sr->data; -} - -void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val) -{ - int sym_index, esym_index; - - sym_index = ELFW(R_SYM)(rel->r_info); - - switch (type) { - case R_X86_64_64: - if (s1->output_type == TCC_OUTPUT_DLL) { - esym_index = s1->sym_attrs[sym_index].dyn_index; - qrel->r_offset = rel->r_offset; - if (esym_index) { - qrel->r_info = ELFW(R_INFO)(esym_index, R_X86_64_64); - qrel->r_addend = rel->r_addend; - qrel++; - break; - } else { - qrel->r_info = ELFW(R_INFO)(0, R_X86_64_RELATIVE); - qrel->r_addend = read64le(ptr) + val; - qrel++; - } - } - add64le(ptr, val); - break; - case R_X86_64_32: - case R_X86_64_32S: - if (s1->output_type == TCC_OUTPUT_DLL) { - /* XXX: this logic may depend on TCC's codegen - now TCC uses R_X86_64_32 even for a 64bit pointer */ - qrel->r_info = ELFW(R_INFO)(0, R_X86_64_RELATIVE); - /* Use sign extension! */ - qrel->r_addend = (int)read32le(ptr) + val; - qrel++; - } - add32le(ptr, val); - break; - - case R_X86_64_PC32: - if (s1->output_type == TCC_OUTPUT_DLL) { - /* DLL relocation */ - esym_index = s1->sym_attrs[sym_index].dyn_index; - if (esym_index) { - qrel->r_offset = rel->r_offset; - qrel->r_info = ELFW(R_INFO)(esym_index, R_X86_64_PC32); - /* Use sign extension! */ - qrel->r_addend = (int)read32le(ptr) + rel->r_addend; - qrel++; - break; - } - } - goto plt32pc32; - - case R_X86_64_PLT32: - /* fallthrough: val already holds the PLT slot address */ - - plt32pc32: - { - long long diff; - diff = (long long)val - addr; - if (diff < -2147483648LL || diff > 2147483647LL) { - tcc_error("internal error: relocation failed"); - } - add32le(ptr, diff); - } - break; - - case R_X86_64_PLTOFF64: - add64le(ptr, val - s1->got->sh_addr + rel->r_addend); - break; - - case R_X86_64_PC64: - if (s1->output_type == TCC_OUTPUT_DLL) { - /* DLL relocation */ - esym_index = s1->sym_attrs[sym_index].dyn_index; - if (esym_index) { - qrel->r_offset = rel->r_offset; - qrel->r_info = ELFW(R_INFO)(esym_index, R_X86_64_PC64); - qrel->r_addend = read64le(ptr) + rel->r_addend; - qrel++; - break; - } - } - add64le(ptr, val - addr); - break; - - case R_X86_64_GLOB_DAT: - case R_X86_64_JUMP_SLOT: - /* They don't need addend */ - write64le(ptr, val - rel->r_addend); - break; - case R_X86_64_GOTPCREL: - case R_X86_64_GOTPCRELX: - case R_X86_64_REX_GOTPCRELX: - add32le(ptr, s1->got->sh_addr - addr + - s1->sym_attrs[sym_index].got_offset - 4); - break; - case R_X86_64_GOTPC32: - add32le(ptr, s1->got->sh_addr - addr + rel->r_addend); - break; - case R_X86_64_GOTPC64: - add64le(ptr, s1->got->sh_addr - addr + rel->r_addend); - break; - case R_X86_64_GOTTPOFF: - add32le(ptr, val - s1->got->sh_addr); - break; - case R_X86_64_GOT32: - /* we load the got offset */ - add32le(ptr, s1->sym_attrs[sym_index].got_offset); - break; - case R_X86_64_GOT64: - /* we load the got offset */ - add64le(ptr, s1->sym_attrs[sym_index].got_offset); - break; - case R_X86_64_GOTOFF64: - add64le(ptr, val - s1->got->sh_addr); - break; - case R_X86_64_RELATIVE: -#ifdef TCC_TARGET_PE - add32le(ptr, val - s1->pe_imagebase); -#endif - /* do nothing */ - break; - } -} - -#endif /* !TARGET_DEFS_ONLY */ diff --git a/05/tcc-final/.gitignore b/05/tcc-final/.gitignore deleted file mode 100644 index 3bff153..0000000 --- a/05/tcc-final/.gitignore +++ /dev/null @@ -1,64 +0,0 @@ -*~ -\#* -.#* -*.o -*.a -*.exe -*.dll -*.obj -*.pdb -*.lib -*.exp -*.log -*.bz2 -*.zip -.gdb_history -a.out -tcc_g -tcc -*-tcc -libtcc*.def - -config*.h -*_.h -config*.mak -config.texi -conftest* -c2str -tags -TAGS -tcc.1 -*.pod -tcc-doc.html -tcc-doc.info - -win32/doc -win32/examples/libtcc_test.c -win32/libtcc -win32/lib/32 -win32/lib/64 -win32/include/float.h -win32/include/stdalign.h -win32/include/stdarg.h -win32/include/stdbool.h -win32/include/stddef.h -win32/include/stdnoreturn.h -win32/include/varargs.h -win32/include/tcclib.h - -tests/tcctest[1234] -tests/tcctest.gcc -tests/*.out* -tests/*.ref -tests/*.txt -tests/*.gcc -tests/*-cc* -tests/*-tcc* -tests/libtcc_test -tests/libtcc_test_mt -tests/asm-c-connect -tests/asm-c-connect-sep -tests/vla_test -tests/hello -tests/tests2/fred.txt -libtcc.dylib diff --git a/05/tcc-final/COPYING b/05/tcc-final/COPYING deleted file mode 100644 index 223ede7..0000000 --- a/05/tcc-final/COPYING +++ /dev/null @@ -1,504 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 2.1, February 1999 - - Copyright (C) 1991, 1999 Free Software Foundation, Inc. - 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -[This is the first released version of the Lesser GPL. It also counts - as the successor of the GNU Library Public License, version 2, hence - the version number 2.1.] - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Lesser General Public License, applies to some -specially designated software packages--typically libraries--of the -Free Software Foundation and other authors who decide to use it. You -can use it too, but we suggest you first think carefully about whether -this license or the ordinary General Public License is the better -strategy to use in any particular case, based on the explanations below. - - When we speak of free software, we are referring to freedom of use, -not price. Our General Public Licenses are designed to make sure that -you have the freedom to distribute copies of free software (and charge -for this service if you wish); that you receive source code or can get -it if you want it; that you can change the software and use pieces of -it in new free programs; and that you are informed that you can do -these things. - - To protect your rights, we need to make restrictions that forbid -distributors to deny you these rights or to ask you to surrender these -rights. These restrictions translate to certain responsibilities for -you if you distribute copies of the library or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link other code with the library, you must provide -complete object files to the recipients, so that they can relink them -with the library after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - We protect your rights with a two-step method: (1) we copyright the -library, and (2) we offer you this license, which gives you legal -permission to copy, distribute and/or modify the library. - - To protect each distributor, we want to make it very clear that -there is no warranty for the free library. Also, if the library is -modified by someone else and passed on, the recipients should know -that what they have is not the original version, so that the original -author's reputation will not be affected by problems that might be -introduced by others. - - Finally, software patents pose a constant threat to the existence of -any free program. We wish to make sure that a company cannot -effectively restrict the users of a free program by obtaining a -restrictive license from a patent holder. Therefore, we insist that -any patent license obtained for a version of the library must be -consistent with the full freedom of use specified in this license. - - Most GNU software, including some libraries, is covered by the -ordinary GNU General Public License. This license, the GNU Lesser -General Public License, applies to certain designated libraries, and -is quite different from the ordinary General Public License. We use -this license for certain libraries in order to permit linking those -libraries into non-free programs. - - When a program is linked with a library, whether statically or using -a shared library, the combination of the two is legally speaking a -combined work, a derivative of the original library. The ordinary -General Public License therefore permits such linking only if the -entire combination fits its criteria of freedom. The Lesser General -Public License permits more lax criteria for linking other code with -the library. - - We call this license the "Lesser" General Public License because it -does Less to protect the user's freedom than the ordinary General -Public License. It also provides other free software developers Less -of an advantage over competing non-free programs. These disadvantages -are the reason we use the ordinary General Public License for many -libraries. However, the Lesser license provides advantages in certain -special circumstances. - - For example, on rare occasions, there may be a special need to -encourage the widest possible use of a certain library, so that it becomes -a de-facto standard. To achieve this, non-free programs must be -allowed to use the library. A more frequent case is that a free -library does the same job as widely used non-free libraries. In this -case, there is little to gain by limiting the free library to free -software only, so we use the Lesser General Public License. - - In other cases, permission to use a particular library in non-free -programs enables a greater number of people to use a large body of -free software. For example, permission to use the GNU C Library in -non-free programs enables many more people to use the whole GNU -operating system, as well as its variant, the GNU/Linux operating -system. - - Although the Lesser General Public License is Less protective of the -users' freedom, it does ensure that the user of a program that is -linked with the Library has the freedom and the wherewithal to run -that program using a modified version of the Library. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, whereas the latter must -be combined with the library in order to run. - - GNU LESSER GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library or other -program which contains a notice placed by the copyright holder or -other authorized party saying it may be distributed under the terms of -this Lesser General Public License (also called "this License"). -Each licensee is addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also combine or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (1) uses at run time a - copy of the library already present on the user's computer system, - rather than copying library functions into the executable, and (2) - will operate properly with a modified version of the library, if - the user installs one, as long as the modified version is - interface-compatible with the version that the work was made with. - - c) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - d) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - e) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the materials to be distributed need not include anything that is -normally distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties with -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Lesser General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Libraries - - If you develop a new library, and you want it to be of the greatest -possible use to the public, we recommend making it free software that -everyone can redistribute and change. You can do so by permitting -redistribution under these terms (or, alternatively, under the terms of the -ordinary General Public License). - - To apply these terms, attach the following notices to the library. It is -safest to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least the -"copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -Also add information on how to contact you by electronic and paper mail. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the library, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the - library `Frob' (a library for tweaking knobs) written by James Random Hacker. - - , 1 April 1990 - Ty Coon, President of Vice - -That's all there is to it! - - diff --git a/05/tcc-final/Changelog b/05/tcc-final/Changelog deleted file mode 100644 index 17f5bde..0000000 --- a/05/tcc-final/Changelog +++ /dev/null @@ -1,439 +0,0 @@ -Version 0.9.27: - -User interface: -- -x[c|a|n] filetype option (Sergey Korshunoff) -- -P[1], -dD, -dM preprocessor options (Sergey Korshunoff) -- -Wl,-(no-)whole-archive linker option (Reuben Thomas) -- -mms-bitfields option (David Mertens) -- -include option (Michael Matz) -- -mno-sse on x86-64 disables use of SSE instructions -- @listfile support (Vlad Vissoultchev) -- tcc -ar/-impdef - formerly tiny_xxx tools integrated (grischka) -- CPATH, C_INCLUDE_PATH and LIBRARY_PATH environment variables support - (Andrew Aladjev, Urs Janssen) - -Platforms: -- new AARCH64 (arm64) target (Edmund Grimley Evans) -- vastly improved support for ARM hard float calling convention - (Thomas Preud'homme, Daniel Glöckner) -- provide a runtime library for ARM (Thomas Preud'homme) -- many x86_64 ABI fixes incl. XMM register passing and tests (James Lyon) -- ABI tests with native compiler using libtcc (James Lyon) -- UNICODE startup code supports wmain and wWinMain (YX Hao) -- shared libraries for x86_64 (Michael Matz) -- Bootstrap native Windows 32/64 compiler using Cygwin+gcc (Christian Jullien) - -Features: -- VLA (variable length array) improved (James Lyon, Pip Cet) -- import functions by ordinal in .def files on windows (YX Hao) -- x86/x86_64 assembler much improved (Michael Matz) -- simple dead code suppression (Edmund Grimley Evans, Michael Matz, grischka) -- implement round/fmin/fmax etc. math on windows (Avi Halachmi) -- #pragma once support (Sergey Korshunoff, Vlad Vissoultchev, ...) -- switch/case code improved (Zdenek Pavlas) -- ~15% faster by TinyAlloc fast memory allocator (Vlad Vissoultchev) -- standard conforming (and GCC compatible) struct initialization - (Michael Matz) -- bit-field layout made compatible with GCC (Michael Matz) -- UTF8 in string literals supported (Zdenek Pavlas) -_ _Generic(...) supported (Matthias Gatto) - -Licensing: -- TinyCC partly relicensed to MIT license (See RELICENSING file). - -version 0.9.26: - -User interface: -- -MD/-MF (automatically generate dependencies for make) -- -pthread option (same as -D_REENTRANT -lpthread) (Henry Kroll III) -- -m32/-m64 to re-exec cross compiler (Henry Kroll III) -- -Wl, Mimic all GNU -option forms supported by ld (Kirill Smelkov) -- new LIBTCCAPI tcc_set_options() (grischka) - -Platforms: -- Many improvements for x86-64 target (Shinichiro Hamaji, Michael Matz, grischka) -- x86-64 assembler (Frederic Feret) -- Many improvements for ARM target (Daniel Glöckner, Thomas Preud'homme) -- Support WinCE PE ARM (Timo VJ Lahde) -- Support ARM hardfloat calling convention (Thomas Preud'homme) -- Support SELinux (Security-Enhanced Linux) (Henry Kroll III) -- Support Debian GNU/kFreeBSD kernels (Pierre Chifflier) -- Support GNU/Hurd kernels (Thomas Preud'homme) -- Support OSX (tcc -run only) (Milutin Jovanovic) -- Support multiarch configuration (Thomas Preud'homme) -- Support out-of-tree build (Akim Demaille) - -Features: -- C99 variable length arrays (Thomas Preud'homme & Joe Soroka) -- Asm labels for variables and functions (Thomas Preud'homme) -- STT_GNU_IFUNC (Indirect functions as externals) (Thomas Preud'homme) -- More tests (tests2) (Milutin Jovanovic) - -version 0.9.25: - -- first support for x86-64 target (Shinichiro Hamaji) -- support µClibc -- split tcc.c into tcc.h libtcc.c tccpp.c tccgen.c tcc.c -- improved preprocess output with linenumbers and spaces preserved -- tcc_relocate now copies code into user buffer -- fix bitfields with non-int types and in unions -- improve ARM cross-compiling (Daniel Glöckner) -- link stabstr sections from multiple objects -- better (still limited) support for multiple TCCStates - -version 0.9.24: - -- added verbosity levels -v, -vv, -vvv -- Accept standard input as an inputstream (Hanzac Chen) -- Support c89 compilers other than gcc (Hanzac Chen) -- -soname linker option (Marc Andre Tanner) -- Just warn about unknown directives, ignore quotes in #error/#warning -- Define __STDC_VERSION__=199901L (477) -- Switch to newer tccpe.c (includes support for resources) -- Handle backslashes within #include/#error/#warning -- Import changesets (part 4) 428,457,460,467: defines for openbsd etc. -- Use _WIN32 for a windows hosted tcc and define it for the PE target, - otherwise define __unix / __linux (Detlef Riekenberg) -- Import changesets (part 3) 409,410: ARM EABI by Daniel Glöckner -- Some in-between fixes: - TCC -E no longer hangs with macro calls involving newlines. - (next_nomacro1 now advances the read-pointer with TOK_LINEFEED) - Global cast (int g_i = 1LL;) no longer crashes tcc. - (nocode_wanted is initially 1, and only 0 for gen_function) - On win32 now tcc.exe finds 'include' & 'lib' even if itself is in 'bin'. - (new function w32_tcc_lib_path removes 'bin' if detected) - Added quick build batch file for mingw (win32/build-tcc.bat) - Last added case label optimization (455) produced wrong code. Reverted. - -- Import more changesets from Rob Landley's fork (part 2): - 487: Handle long long constants in gen_opic() (Rob Landley) - 484: Handle parentheses within __attribute__((...)) (Rob Landley) - 480: Remove a goto in decl_initializer_alloc (Rob Landley) - 475: Fix dereferences in inline assembly output (Joshua Phillips) - 474: Cast ptrs to ints of different sizes correctly (Joshua Phillips) - 473: Fix size of structs with empty array member (Joshua Phillips) - 470: No warning for && and || with mixed pointers/integers (Rob Landley) - 469: Fix symbol visibility problems in the linker (Vincent Pit) - 468: Allow && and || involving pointer arguments (Rob Landley) - 455: Optimize case labels with no code in between (Zdenek Pavlas) - 450: Implement alloca for x86 (grischka) - 415: Parse unicode escape sequences (Axel Liljencrantz) - 407: Add a simple va_copy() in stdarg.h (Hasso Tepper) - 400: Allow typedef names as symbols (Dave Dodge) - -- Import some changesets from Rob Landley's fork (part 1): - 462: Use LGPL with bcheck.c and il-gen.c - 458: Fix global compound literals (in unary: case '&':) (Andrew Johnson) - 456: Use return code from tcc_output_file in main() (Michael Somos) - 442: Fix indirections with function pointers (***fn)() (grischka) - 441: Fix LL left shift in libtcc1.c:__shldi3 (grischka) - 440: Pass structures and function ptrs through ?: (grischka) - 439: Keep rvalue in bit assignment (bit2 = bit1 = x) (grischka) - 438: Degrade nonportable pointer assignment to warning (grischka) - 437: Call 'saveregs()' before jumping with logical and/or/not (grischka) - 435: Put local static variables into global memory (grischka) - 432/434: Cast double and ptr to bool (grischka) - 420: Zero pad x87 tenbyte long doubles (Felix Nawothnig) - 417: Make 'sizeof' unsigned (Rob Landley) - 397: Fix save_reg for longlongs (Daniel Glöckner) - 396: Fix "invalid relocation entry" problem on ubuntu - (Bernhard Fischer) - -- ignore AS_NEEDED ld command -- mark executable sections as executable when running in memory -- added support for win32 wchar_t (Filip Navara) -- segment override prefix support (Filip Navara) -- normalized slashes in paths (Filip Navara) -- windows style fastcall (Filip Navara) -- support for empty input register section in asm (Filip Navara) -- anonymous union/struct support (Filip Navara) -- fixed parsing of function parameters -- workaround for function pointers in conditional expressions (Dave Dodge) -- initial '-E' option support to use the C preprocessor alone -- discard type qualifiers when comparing function parameters (Dave Dodge) -- Bug fix: A long long value used as a test expression ignores the - upper 32 bits at runtime (Dave Dodge) -- fixed multiple concatenation of PPNUM tokens (initial patch by Dave Dodge) -- fixed multiple typedef specifiers handling -- fixed sign extension in some type conversions (Dave Dodge) - -version 0.9.23: - -- initial PE executable format for windows version (grischka) -- '#pragma pack' support (grischka) -- '#include_next' support (Bernhard Fischer) -- ignore '-pipe' option -- added -f[no-]leading-underscore -- preprocessor function macro parsing fix (grischka) - -version 0.9.22: - -- simple memory optimisations: kernel compilation is 30% faster -- linker symbol definitions fixes -- gcc 3.4 fixes -- fixed value stack full error -- 'packed' attribute support for variables and structure fields -- ignore 'const' and 'volatile' in function prototypes -- allow '_Bool' in bit fields - -version 0.9.21: - -- ARM target support (Daniel Glöckner) -- added '-funsigned-char, '-fsigned-char' and - '-Wimplicit-function-declaration' -- fixed assignment of const struct in struct -- line comment fix (reported by Bertram Felgenhauer) -- initial TMS320C67xx target support (TK) -- win32 configure -- regparm() attribute -- many built-in assembler fixes -- added '.org', '.fill' and '.previous' assembler directives -- '-fno-common' option -- '-Ttext' linker option -- section alignment fixes -- bit fields fixes -- do not generate code for unused inline functions -- '-oformat' linker option. -- added 'binary' output format. - -version 0.9.20: - -- added '-w' option -- added '.gnu.linkonce' ELF sections support -- fixed libc linking when running in memory (avoid 'stat' function - errors). -- extended '-run' option to be able to give several arguments to a C - script. - -version 0.9.19: - -- "alacarte" linking (Dave Long) -- simpler function call -- more strict type checks -- added 'const' and 'volatile' support and associated warnings -- added -Werror, -Wunsupported, -Wwrite-strings, -Wall. -- added __builtin_types_compatible_p() and __builtin_constant_p() -- chars support in assembler (Dave Long) -- .string, .globl, .section, .text, .data and .bss asm directive - support (Dave Long) -- man page generated from tcc-doc.texi -- fixed macro argument substitution -- fixed zero argument macro parsing -- changed license to LGPL -- added -rdynamic option support - -version 0.9.18: - -- header fix (time.h) -- fixed inline asm without operand case -- fixed 'default:' or 'case x:' with '}' after (incorrect C construct accepted - by gcc) -- added 'A' inline asm constraint. - -version 0.9.17: - -- PLT generation fix -- tcc doc fixes (Peter Lund) -- struct parse fix (signaled by Pedro A. Aranda Gutierrez) -- better _Bool lvalue support (signaled by Alex Measday) -- function parameters must be converted to pointers (signaled by Neil Brown) -- sanitized string and character constant parsing -- fixed comment parse (signaled by Damian M Gryski) -- fixed macro function bug (signaled by Philippe Ribet) -- added configure (initial patch by Mitchell N Charity) -- added '-run' and '-v' options (initial patch by vlindos) -- added real date report in __DATE__ and __TIME__ macros - -version 0.9.16: - -- added assembler language support -- added GCC inline asm() support -- fixed multiple variable definitions : uninitialized variables are - created as COMMON symbols. -- optimized macro processing -- added GCC statement expressions support -- added GCC local labels support -- fixed array declaration in old style function parameters -- support casts in static structure initializations -- added various __xxx[__] keywords for GCC compatibility -- ignore __extension__ GCC in an expression or in a type (still not perfect) -- added '? :' GCC extension support - -version 0.9.15: - -- compilation fixes for glibc 2.2, gcc 2.95.3 and gcc 3.2. -- FreeBSD compile fixes. Makefile patches still missing (Carl Drougge). -- fixed file type guessing if '.' is in the path. -- fixed tcc_compile_string() -- add a dummy page in ELF files to fix RX/RW accesses (pageexec at - freemail dot hu). - -version 0.9.14: - -- added #warning. error message if invalid preprocessing directive. -- added CType structure to ease typing (faster parse). -- suppressed secondary hash tables (faster parse). -- rewrote parser by optimizing common cases (faster parse). -- fixed signed long long comparisons. -- fixed 'int a(), b();' declaration case. -- fixed structure init without '{}'. -- correct alignment support in structures. -- empty structures support. -- gcc testsuite now supported. -- output only warning if implicit integer/pointer conversions. -- added static bitfield init. - -version 0.9.13: - -- correct preprocessing token pasting (## operator) in all cases (added - preprocessing number token). -- fixed long long register spill. -- fixed signed long long '>>'. -- removed memory leaks. -- better error handling : processing can continue on link errors. A - custom callback can be added to display error messages. Most - errors do not call exit() now. -- ignore -O, -W, -m and -f options -- added old style function declarations -- added GCC __alignof__ support. -- added GCC typeof support. -- added GCC computed gotos support. -- added stack backtrace in runtime error message. Improved runtime - error position display. - -version 0.9.12: - -- more fixes for || and && handling. -- improved '? :' type handling. -- fixed bound checking generation with structures -- force '#endif' to be in same file as matching '#if' -- #include file optimization with '#ifndef #endif' construct detection -- macro handling optimization -- added tcc_relocate() and tcc_get_symbol() in libtcc. - -version 0.9.11: - -- stdarg.h fix for double type (thanks to Philippe Ribet). -- correct white space characters and added MSDOS newline support. -- fixed invalid implicit function call type declaration. -- special macros such as __LINE__ are defined if tested with defined(). -- fixed '!' operator with relocated address. -- added symbol + offset relocation (fixes some static variable initializers) -- '-l' option can be specified anywhere. '-c' option yields default - output name. added '-r' option for relocatable output. -- fixed '\nnn' octal parsing. -- fixed local extern variables declarations. - -version 0.9.10: - -- fixed lvalue type when saved in local stack. -- fixed '#include' syntax when using macros. -- fixed '#line' bug. -- removed size limit on strings. Unified string constants handling - with variable declarations. -- added correct support for '\xX' in wchar_t strings. -- added support for bound checking in generated executables -- fixed -I include order. -- fixed incorrect function displayed in runtime error. - -version 0.9.9: - -- fixed preprocessor expression parsing for #if/#elif. -- relocated debug info (.stab section). -- relocated bounds info (.bounds section). -- fixed cast to char of char constants ('\377' is -1 instead of 255) -- fixed implicit cast for unary plus. -- strings and '__func__' have now 'char[]' type instead of 'char *' - (fixes sizeof() return value). -- added __start_xxx and __stop_xxx symbols in linker. -- better DLL creation support (option -shared begins to work). -- ELF sections and hash tables are resized dynamically. -- executables and DLLs are stripped by default. - -version 0.9.8: - -- First version of full ELF linking support (generate objects, static - executable, dynamic executable, dynamic libraries). Dynamic library - support is not finished (need PIC support in compiler and some - patches in symbol exporting). -- First version of ELF loader for object (.o) and archive (.a) files. -- Support of simple GNU ld scripts (GROUP and FILE commands) -- Separated runtime library and bound check code from TCC (smaller - compiler core). -- fixed register reload in float compare. -- fixed implicit char/short to int casting. -- allow array type for address of ('&') operator. -- fixed unused || or && result. -- added GCC style variadic macro support. -- optimized bound checking code for array access. -- tcc includes are now in $(prefix)/lib/tcc/include. -- more command line options - more consistent handling of multiple - input files. -- added tcc man page (thanks to Cyril Bouthors). -- uClibc Makefile update -- converted documentation to texinfo format. -- added developper's guide in documentation. - -version 0.9.7: - -- added library API for easy dynamic compilation (see libtcc.h - first - draft). -- fixed long long register spill bug. -- fixed '? :' register spill bug. - -version 0.9.6: - -- added floating point constant propagation (fixes negative floating - point constants bug). - -version 0.9.5: - - - uClibc patches (submitted by Alfonso Martone). - - error reporting fix - - added CONFIG_TCC_BCHECK to get smaller code if needed. - -version 0.9.4: - - - windows port (currently cannot use -g, -b and dll functions). - - faster and simpler I/O handling. - - '-D' option works in all cases. - - preprocessor fixes (#elif and empty macro args) - - floating point fixes - - first code for CIL generation (does not work yet) - -version 0.9.3: - - - better and smaller code generator. - - full ISOC99 64 bit 'long long' support. - - full 32 bit 'float', 64 bit 'double' and 96 bit 'long double' support. - - added '-U' option. - - added assembly sections support. - - even faster startup time by mmaping sections instead of mallocing them. - - added GNUC __attribute__ keyword support (currently supports - 'section' and 'aligned' attributes). - - added ELF file output (only usable for debugging now) - - added debug symbol generation (STAB format). - - added integrated runtime error analysis ('-g' option: print clear - run time error messages instead of "Segmentation fault"). - - added first version of tiny memory and bound checker ('-b' option). - -version 0.9.2: - - - even faster parsing. - - various syntax parsing fixes. - - fixed external relocation handling for variables or functions pointers. - - better function pointers type handling. - - can compile multiple files (-i option). - - ANSI C bit fields are supported. - - beginning of float/double/long double support. - - beginning of long long support. - -version 0.9.1: - - - full ISOC99 initializers handling. - - compound literals. - - structures handle in assignments and as function param or return value. - - wide chars and strings. - - macro bug fix - -version 0.9: - - initial version. diff --git a/05/tcc-final/CodingStyle b/05/tcc-final/CodingStyle deleted file mode 100644 index 93d1324..0000000 --- a/05/tcc-final/CodingStyle +++ /dev/null @@ -1,71 +0,0 @@ - -In general, use the same coding style as the surrounding code. - -However, do not make any unnecessary changes as that complicates -the VCS (git) history and makes it harder to merge patches. So -do not modify code just to make it conform to a coding style. - - Indentation - -Turn on a "fill tabs with spaces" option in your editor. - -Remove tabs and trailing spaces from any lines that are modified. - -Note that some files are indented with 2 spaces (when they -have large indentation) while most are indented with 4 spaces. - - Language - -TCC is mostly implemented in C90. Do not use any non-C90 features -that are not already in use. - -Non-C90 features currently in use, as revealed by -./configure --extra-cflags="-std=c90 -Wpedantic": - -- long long (including "LL" constants) -- inline -- very long string constants -- assignment between function pointer and 'void *' -- "//" comments -- empty macro arguments (DEF_ASMTEST in i386-tok.h) -- unnamed struct and union fields (in struct Sym), a C11 feature - - Testing - -A simple "make test" is sufficient for some simple changes. However, -before committing a change consider performing some of the following -additional tests: - -- Build and run "make test" on several architectures. - -- Build with ./configure --enable-cross. - -- If the generation of relocations has been changed, try compiling - with TCC and linking with GCC/Clang. If the linker has been - modified, try compiling with GCC/Clang and linking with TCC. - -- Test with ASan/UBSan to detect memory corruption and undefined behaviour: - -make clean -./configure -make -make test -cp libtcc.a libtcc.a.hide - -make clean -./configure --extra-cflags="-fsanitize=address,undefined -g" -make -cp libtcc.a.hide libtcc.a -make test - -- Test with Valgrind to detect some uses of uninitialised values: - -make clean -./configure -make -# On Intel, because Valgrind does floating-point arithmetic differently: -( cd tests && gcc -I.. tcctest.c && valgrind -q ./a.out > test.ref ) -make test TCC="valgrind -q --leak-check=full `pwd`/tcc -B`pwd` -I`pwd`" - - (Because of how VLAs are implemented, invalid reads are expected - with 79_vla_continue.) diff --git a/05/tcc-final/Makefile b/05/tcc-final/Makefile deleted file mode 100644 index 211fb49..0000000 --- a/05/tcc-final/Makefile +++ /dev/null @@ -1,489 +0,0 @@ -# -------------------------------------------------------------------------- -# -# Tiny C Compiler Makefile -# - -ifndef TOP - TOP = . - INCLUDED = no -endif - -ifeq ($(findstring $(MAKECMDGOALS),clean distclean),) - include $(TOP)/config.mak -endif - -ifeq (-$(GCC_MAJOR)-$(findstring $(GCC_MINOR),56789)-,-4--) - CFLAGS += -D_FORTIFY_SOURCE=0 -endif - -LIBTCC = libtcc.a -LIBTCC1 = libtcc1.a -LINK_LIBTCC = -LIBS = -CFLAGS += -I$(TOP) -CFLAGS += $(CPPFLAGS) -VPATH = $(TOPSRC) - -ifdef CONFIG_WIN32 - CFG = -win - ifneq ($(CONFIG_static),yes) - LIBTCC = libtcc$(DLLSUF) - LIBTCCDEF = libtcc.def - endif - NATIVE_TARGET = $(ARCH)-win$(if $(findstring arm,$(ARCH)),ce,32) -else - CFG = -unx - LIBS=-lm -lpthread - ifneq ($(CONFIG_ldl),no) - LIBS+=-ldl - endif - # make libtcc as static or dynamic library? - ifeq ($(CONFIG_static),no) - LIBTCC=libtcc$(DLLSUF) - export LD_LIBRARY_PATH := $(CURDIR)/$(TOP) - ifneq ($(CONFIG_rpath),no) - ifndef CONFIG_OSX - LINK_LIBTCC += -Wl,-rpath,"$(libdir)" - else - # macOS doesn't support env-vars libdir out of the box - which we need for - # `make test' when libtcc.dylib is used (configure --disable-static), so - # we bake a relative path into the binary. $libdir is used after install. - LINK_LIBTCC += -Wl,-rpath,"@executable_path/$(TOP)" -Wl,-rpath,"$(libdir)" - DYLIBVER += -current_version $(VERSION) - DYLIBVER += -compatibility_version $(VERSION) - endif - endif - endif - NATIVE_TARGET = $(ARCH) - ifdef CONFIG_OSX - NATIVE_TARGET = $(ARCH)-osx - ifneq ($(CC_NAME),tcc) - LDFLAGS += -flat_namespace -undefined warning - endif - export MACOSX_DEPLOYMENT_TARGET := 10.6 - endif -endif - -# run local version of tcc with local libraries and includes -TCCFLAGS-unx = -B$(TOP) -I$(TOPSRC)/include -I$(TOPSRC) -I$(TOP) -TCCFLAGS-win = -B$(TOPSRC)/win32 -I$(TOPSRC)/include -I$(TOPSRC) -I$(TOP) -L$(TOP) -TCCFLAGS = $(TCCFLAGS$(CFG)) -TCC = $(TOP)/tcc$(EXESUF) $(TCCFLAGS) - -CFLAGS_P = $(CFLAGS) -pg -static -DCONFIG_TCC_STATIC -DTCC_PROFILE -LIBS_P = $(LIBS) -LDFLAGS_P = $(LDFLAGS) - -CONFIG_$(ARCH) = yes -NATIVE_DEFINES_$(CONFIG_i386) += -DTCC_TARGET_I386 -NATIVE_DEFINES_$(CONFIG_x86_64) += -DTCC_TARGET_X86_64 -NATIVE_DEFINES_$(CONFIG_WIN32) += -DTCC_TARGET_PE -NATIVE_DEFINES_$(CONFIG_OSX) += -DTCC_TARGET_MACHO -NATIVE_DEFINES_$(CONFIG_uClibc) += -DTCC_UCLIBC -NATIVE_DEFINES_$(CONFIG_musl) += -DTCC_MUSL -NATIVE_DEFINES_$(CONFIG_libgcc) += -DCONFIG_USE_LIBGCC -NATIVE_DEFINES_$(CONFIG_selinux) += -DHAVE_SELINUX -NATIVE_DEFINES_$(CONFIG_arm) += -DTCC_TARGET_ARM -NATIVE_DEFINES_$(CONFIG_arm_eabihf) += -DTCC_ARM_EABI -DTCC_ARM_HARDFLOAT -NATIVE_DEFINES_$(CONFIG_arm_eabi) += -DTCC_ARM_EABI -NATIVE_DEFINES_$(CONFIG_arm_vfp) += -DTCC_ARM_VFP -NATIVE_DEFINES_$(CONFIG_arm64) += -DTCC_TARGET_ARM64 -NATIVE_DEFINES_$(CONFIG_riscv64) += -DTCC_TARGET_RISCV64 -NATIVE_DEFINES_$(CONFIG_BSD) += -DTARGETOS_$(TARGETOS) -NATIVE_DEFINES_$(CONFIG_pie) += -DCONFIG_TCC_PIE -NATIVE_DEFINES_no_$(CONFIG_bcheck) += -DCONFIG_TCC_BCHECK=0 -NATIVE_DEFINES_no_$(CONFIG_backtrace) += -DCONFIG_TCC_BACKTRACE=0 -NATIVE_DEFINES += $(NATIVE_DEFINES_yes) $(NATIVE_DEFINES_no_no) - -DEF-i386 = -DTCC_TARGET_I386 -DEF-i386-win32 = -DTCC_TARGET_I386 -DTCC_TARGET_PE -DEF-i386-OpenBSD = $(DEF-i386) -DTARGETOS_OpenBSD -DEF-x86_64 = -DTCC_TARGET_X86_64 -DEF-x86_64-win32 = -DTCC_TARGET_X86_64 -DTCC_TARGET_PE -DEF-x86_64-osx = -DTCC_TARGET_X86_64 -DTCC_TARGET_MACHO -DEF-arm-fpa = -DTCC_TARGET_ARM -DEF-arm-fpa-ld = -DTCC_TARGET_ARM -DLDOUBLE_SIZE=12 -DEF-arm-vfp = -DTCC_TARGET_ARM -DTCC_ARM_VFP -DEF-arm-eabi = -DTCC_TARGET_ARM -DTCC_ARM_VFP -DTCC_ARM_EABI -DEF-arm-eabihf = $(DEF-arm-eabi) -DTCC_ARM_HARDFLOAT -DEF-arm = $(DEF-arm-eabihf) -DEF-arm-NetBSD = $(DEF-arm-eabihf) -DTARGETOS_NetBSD -DEF-arm-wince = $(DEF-arm-eabihf) -DTCC_TARGET_PE -DEF-arm64 = -DTCC_TARGET_ARM64 -DEF-arm64-osx = $(DEF-arm64) -DTCC_TARGET_MACHO -DEF-arm64-FreeBSD = $(DEF-arm64) -DTARGETOS_FreeBSD -DEF-arm64-NetBSD = $(DEF-arm64) -DTARGETOS_NetBSD -DEF-arm64-OpenBSD = $(DEF-arm64) -DTARGETOS_OpenBSD -DEF-riscv64 = -DTCC_TARGET_RISCV64 -DEF-c67 = -DTCC_TARGET_C67 -w # disable warnigs -DEF-x86_64-FreeBSD = $(DEF-x86_64) -DTARGETOS_FreeBSD -DEF-x86_64-NetBSD = $(DEF-x86_64) -DTARGETOS_NetBSD -DEF-x86_64-OpenBSD = $(DEF-x86_64) -DTARGETOS_OpenBSD - -DEF-$(NATIVE_TARGET) = $(NATIVE_DEFINES) - -ifeq ($(INCLUDED),no) -# -------------------------------------------------------------------------- -# running top Makefile - -PROGS = tcc$(EXESUF) -TCCLIBS = $(LIBTCCDEF) $(LIBTCC) $(LIBTCC1) -TCCDOCS = tcc.1 tcc-doc.html tcc-doc.info - -all: $(PROGS) $(TCCLIBS) $(TCCDOCS) - -# cross compiler targets to build -TCC_X = i386 x86_64 i386-win32 x86_64-win32 x86_64-osx arm arm64 arm-wince c67 -TCC_X += riscv64 arm64-osx -# TCC_X += arm-fpa arm-fpa-ld arm-vfp arm-eabi - -# cross libtcc1.a targets to build -LIBTCC1_X = i386 x86_64 i386-win32 x86_64-win32 x86_64-osx arm arm64 arm-wince -LIBTCC1_X += riscv64 arm64-osx - -PROGS_CROSS = $(foreach X,$(TCC_X),$X-tcc$(EXESUF)) -LIBTCC1_CROSS = $(foreach X,$(LIBTCC1_X),$X-libtcc1.a) - -# build cross compilers & libs -cross: $(LIBTCC1_CROSS) $(PROGS_CROSS) - -# build specific cross compiler & lib -cross-%: %-tcc$(EXESUF) %-libtcc1.a ; - -install: ; @$(MAKE) --no-print-directory install$(CFG) -install-strip: ; @$(MAKE) --no-print-directory install$(CFG) CONFIG_strip=yes -uninstall: ; @$(MAKE) --no-print-directory uninstall$(CFG) - -ifdef CONFIG_cross -all : cross -endif - -# -------------------------------------------- - -T = $(or $(CROSS_TARGET),$(NATIVE_TARGET),unknown) -X = $(if $(CROSS_TARGET),$(CROSS_TARGET)-) - -DEFINES += $(DEF-$T) $(DEF-all) -DEFINES += $(if $(ROOT-$T),-DCONFIG_SYSROOT="\"$(ROOT-$T)\"") -DEFINES += $(if $(CRT-$T),-DCONFIG_TCC_CRTPREFIX="\"$(CRT-$T)\"") -DEFINES += $(if $(LIB-$T),-DCONFIG_TCC_LIBPATHS="\"$(LIB-$T)\"") -DEFINES += $(if $(INC-$T),-DCONFIG_TCC_SYSINCLUDEPATHS="\"$(INC-$T)\"") -DEFINES += $(DEF-$(or $(findstring win,$T),unx)) - -ifneq ($(X),) -ifeq ($(CONFIG_WIN32),yes) -DEF-win += -DTCC_LIBTCC1="\"$(X)libtcc1.a\"" -DEF-unx += -DTCC_LIBTCC1="\"lib/$(X)libtcc1.a\"" -else -DEF-all += -DTCC_LIBTCC1="\"$(X)libtcc1.a\"" -DEF-win += -DCONFIG_TCCDIR="\"$(tccdir)/win32\"" -endif -endif - -# include custom configuration (see make help) --include config-extra.mak - -CORE_FILES = tcc.c tcctools.c libtcc.c tccpp.c tccgen.c tccdbg.c tccelf.c tccasm.c tccrun.c -CORE_FILES += tcc.h config.h libtcc.h tcctok.h -i386_FILES = $(CORE_FILES) i386-gen.c i386-link.c i386-asm.c i386-asm.h i386-tok.h -i386-win32_FILES = $(i386_FILES) tccpe.c -x86_64_FILES = $(CORE_FILES) x86_64-gen.c x86_64-link.c i386-asm.c x86_64-asm.h -x86_64-win32_FILES = $(x86_64_FILES) tccpe.c -x86_64-osx_FILES = $(x86_64_FILES) tccmacho.c -arm_FILES = $(CORE_FILES) arm-gen.c arm-link.c arm-asm.c arm-tok.h -arm-wince_FILES = $(arm_FILES) tccpe.c -arm-eabihf_FILES = $(arm_FILES) -arm-fpa_FILES = $(arm_FILES) -arm-fpa-ld_FILES = $(arm_FILES) -arm-vfp_FILES = $(arm_FILES) -arm-eabi_FILES = $(arm_FILES) -arm-eabihf_FILES = $(arm_FILES) -arm64_FILES = $(CORE_FILES) arm64-gen.c arm64-link.c arm64-asm.c -arm64-osx_FILES = $(arm64_FILES) tccmacho.c -c67_FILES = $(CORE_FILES) c67-gen.c c67-link.c tcccoff.c -riscv64_FILES = $(CORE_FILES) riscv64-gen.c riscv64-link.c riscv64-asm.c - -TCCDEFS_H$(subst yes,,$(CONFIG_predefs)) = tccdefs_.h - -# libtcc sources -LIBTCC_SRC = $(filter-out tcc.c tcctools.c,$(filter %.c,$($T_FILES))) - -ifeq ($(ONE_SOURCE),yes) -LIBTCC_OBJ = $(X)libtcc.o -LIBTCC_INC = $($T_FILES) -TCC_FILES = $(X)tcc.o -tcc.o : DEFINES += -DONE_SOURCE=0 -$(X)tcc.o $(X)libtcc.o : $(TCCDEFS_H) -else -LIBTCC_OBJ = $(patsubst %.c,$(X)%.o,$(LIBTCC_SRC)) -LIBTCC_INC = $(filter %.h %-gen.c %-link.c,$($T_FILES)) -TCC_FILES = $(X)tcc.o $(LIBTCC_OBJ) -$(TCC_FILES) : DEFINES += -DONE_SOURCE=0 -$(X)tccpp.o : $(TCCDEFS_H) -endif - -GITHASH := $(shell git rev-parse >/dev/null 2>&1 && git rev-parse --short HEAD || echo no) -ifneq ($(GITHASH),no) -DEF_GITHASH := -DTCC_GITHASH="\"$(shell git rev-parse --abbrev-ref HEAD):$(GITHASH)$(shell git diff --quiet || echo '-mod')\"" -endif - -ifeq ($(CONFIG_debug),yes) -CFLAGS += -g -LDFLAGS += -g -else -ifndef CONFIG_OSX -LDFLAGS += -s -endif -endif - -# convert "include/tccdefs.h" to "tccdefs_.h" -%_.h : include/%.h conftest.c - $S$(CC) -DC2STR $(filter %.c,$^) -o c2str.exe && ./c2str.exe $< $@ - -# target specific object rule -$(X)%.o : %.c $(LIBTCC_INC) - $S$(CC) -o $@ -c $< $(DEFINES) $(CFLAGS) - -# additional dependencies -$(X)tcc.o : tcctools.c -$(X)tcc.o : DEFINES += $(DEF_GITHASH) - -# Host Tiny C Compiler -tcc$(EXESUF): tcc.o $(LIBTCC) - $S$(CC) -o $@ $^ $(LIBS) $(LDFLAGS) $(LINK_LIBTCC) - -# Cross Tiny C Compilers -# (the TCCDEFS_H dependency is only necessary for parallel makes, -# ala 'make -j x86_64-tcc i386-tcc tcc', which would create multiple -# c2str.exe and tccdefs_.h files in parallel, leading to access errors. -# This forces it to be made only once. Make normally tracks multiple paths -# to the same goals and only remakes it once, but that doesn't work over -# sub-makes like in this target) -%-tcc$(EXESUF): $(TCCDEFS_H) FORCE - @$(MAKE) --no-print-directory $@ CROSS_TARGET=$* ONE_SOURCE=$(or $(ONE_SOURCE),yes) - -$(CROSS_TARGET)-tcc$(EXESUF): $(TCC_FILES) - $S$(CC) -o $@ $^ $(LIBS) $(LDFLAGS) - -# profiling version -tcc_p$(EXESUF): $($T_FILES) - $S$(CC) -o $@ $< $(DEFINES) $(CFLAGS_P) $(LIBS_P) $(LDFLAGS_P) - -# static libtcc library -libtcc.a: $(LIBTCC_OBJ) - $S$(AR) rcs $@ $^ - -# dynamic libtcc library -libtcc.so: $(LIBTCC_OBJ) - $S$(CC) -shared -Wl,-soname,$@ -o $@ $^ $(LDFLAGS) - -libtcc.so: CFLAGS+=-fPIC -libtcc.so: LDFLAGS+=-fPIC - -# OSX dynamic libtcc library -libtcc.dylib: $(LIBTCC_OBJ) - $S$(CC) -dynamiclib $(DYLIBVER) -install_name @rpath/$@ -o $@ $^ $(LDFLAGS) - -# OSX libtcc.dylib (without rpath/ prefix) -libtcc.osx: $(LIBTCC_OBJ) - $S$(CC) -shared -install_name libtcc.dylib -o libtcc.dylib $^ $(LDFLAGS) - -# windows dynamic libtcc library -libtcc.dll : $(LIBTCC_OBJ) - $S$(CC) -shared -o $@ $^ $(LDFLAGS) -libtcc.dll : DEFINES += -DLIBTCC_AS_DLL - -# import file for windows libtcc.dll -libtcc.def : libtcc.dll tcc$(EXESUF) - $S$(XTCC) -impdef $< -o $@ -XTCC ?= ./tcc$(EXESUF) - -# TinyCC runtime libraries -libtcc1.a : tcc$(EXESUF) FORCE - @$(MAKE) -C lib - -# Cross libtcc1.a -%-libtcc1.a : %-tcc$(EXESUF) FORCE - @$(MAKE) -C lib CROSS_TARGET=$* - -.PRECIOUS: %-libtcc1.a -FORCE: - -run-if = $(if $(shell which $1),$S $1 $2) -S = $(if $(findstring yes,$(SILENT)),@$(info * $@)) - -# -------------------------------------------------------------------------- -# documentation and man page -tcc-doc.html: tcc-doc.texi - $(call run-if,makeinfo,--no-split --html --number-sections -o $@ $<) - -tcc-doc.info: tcc-doc.texi - $(call run-if,makeinfo,$< || true) - -tcc.1 : tcc-doc.pod - $(call run-if,pod2man,--section=1 --center="Tiny C Compiler" \ - --release="$(VERSION)" $< >$@ && rm -f $<) -%.pod : %.texi - $(call run-if,perl,$(TOPSRC)/texi2pod.pl $< $@) - -doc : $(TCCDOCS) - -# -------------------------------------------------------------------------- -# install - -INSTALL = install -m644 -INSTALLBIN = install -m755 $(STRIP_$(CONFIG_strip)) -STRIP_yes = -s - -LIBTCC1_W = $(filter %-win32-libtcc1.a %-wince-libtcc1.a,$(LIBTCC1_CROSS)) -LIBTCC1_U = $(filter-out $(LIBTCC1_W),$(LIBTCC1_CROSS)) -IB = $(if $1,$(IM) mkdir -p $2 && $(INSTALLBIN) $1 $2) -IBw = $(call IB,$(wildcard $1),$2) -IF = $(if $1,$(IM) mkdir -p $2 && $(INSTALL) $1 $2) -IFw = $(call IF,$(wildcard $1),$2) -IR = $(IM) mkdir -p $2 && cp -r $1/. $2 -IM = $(info -> $2 : $1)@ - -B_O = bcheck.o bt-exe.o bt-log.o bt-dll.o - -# install progs & libs -install-unx: - $(call IBw,$(PROGS) $(PROGS_CROSS),"$(bindir)") - $(call IFw,$(LIBTCC1) $(B_O) $(LIBTCC1_U),"$(tccdir)") - $(call IF,$(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h,"$(tccdir)/include") - $(call $(if $(findstring .so,$(LIBTCC)),IBw,IFw),$(LIBTCC),"$(libdir)") - $(call IF,$(TOPSRC)/libtcc.h,"$(includedir)") - $(call IFw,tcc.1,"$(mandir)/man1") - $(call IFw,tcc-doc.info,"$(infodir)") - $(call IFw,tcc-doc.html,"$(docdir)") -ifneq "$(wildcard $(LIBTCC1_W))" "" - $(call IFw,$(TOPSRC)/win32/lib/*.def $(LIBTCC1_W),"$(tccdir)/win32/lib") - $(call IR,$(TOPSRC)/win32/include,"$(tccdir)/win32/include") - $(call IF,$(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h,"$(tccdir)/win32/include") -endif - -# uninstall -uninstall-unx: - @rm -fv $(foreach P,$(PROGS) $(PROGS_CROSS),"$(bindir)/$P") - @rm -fv "$(libdir)/libtcc.a" "$(libdir)/libtcc.so" "$(libdir)/libtcc.dylib" "$(includedir)/libtcc.h" - @rm -fv "$(mandir)/man1/tcc.1" "$(infodir)/tcc-doc.info" - @rm -fv "$(docdir)/tcc-doc.html" - @rm -frv "$(tccdir)" - -# install progs & libs on windows -install-win: - $(call IBw,$(PROGS) $(PROGS_CROSS) $(subst libtcc.a,,$(LIBTCC)),"$(bindir)") - $(call IF,$(TOPSRC)/win32/lib/*.def,"$(tccdir)/lib") - $(call IFw,libtcc1.a $(B_O) $(LIBTCC1_W),"$(tccdir)/lib") - $(call IF,$(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h,"$(tccdir)/include") - $(call IR,$(TOPSRC)/win32/include,"$(tccdir)/include") - $(call IR,$(TOPSRC)/win32/examples,"$(tccdir)/examples") - $(call IF,$(TOPSRC)/tests/libtcc_test.c,"$(tccdir)/examples") - $(call IFw,$(TOPSRC)/libtcc.h $(subst .dll,.def,$(LIBTCC)),"$(libdir)") - $(call IFw,$(TOPSRC)/win32/tcc-win32.txt tcc-doc.html,"$(docdir)") -ifneq "$(wildcard $(LIBTCC1_U))" "" - $(call IFw,$(LIBTCC1_U),"$(tccdir)/lib") - $(call IF,$(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h,"$(tccdir)/lib/include") -endif - -# the msys-git shell works to configure && make except it does not have install -ifeq ($(CONFIG_WIN32)-$(shell which install || echo no),yes-no) -install-win : INSTALL = cp -install-win : INSTALLBIN = cp -endif - -# uninstall on windows -uninstall-win: - @rm -fv $(foreach P,libtcc.dll $(PROGS) *-tcc.exe,"$(bindir)"/$P) - @rm -fr $(foreach P,doc examples include lib libtcc,"$(tccdir)/$P"/*) - @rm -frv $(foreach P,doc examples include lib libtcc,"$(tccdir)/$P") - -# -------------------------------------------------------------------------- -# other stuff - -TAGFILES = *.[ch] include/*.h lib/*.[chS] -tags : ; ctags $(TAGFILES) -# cannot have both tags and TAGS on windows -ETAGS : ; etags $(TAGFILES) - -# create release tarball from *current* git branch (including tcc-doc.html -# and converting two files to CRLF) -TCC-VERSION = tcc-$(VERSION) -TCC-VERSION = tinycc-mob-$(shell git rev-parse --short=7 HEAD) -tar: tcc-doc.html - mkdir -p $(TCC-VERSION) - ( cd $(TCC-VERSION) && git --git-dir ../.git checkout -f ) - cp tcc-doc.html $(TCC-VERSION) - for f in tcc-win32.txt build-tcc.bat ; do \ - cat win32/$$f | sed 's,\(.*\),\1\r,g' > $(TCC-VERSION)/win32/$$f ; \ - done - tar cjf $(TCC-VERSION).tar.bz2 $(TCC-VERSION) - rm -rf $(TCC-VERSION) - git reset - -config.mak: - $(if $(wildcard $@),,@echo "Please run ./configure." && exit 1) - -# run all tests -test: - @$(MAKE) -C tests -# run test(s) from tests2 subdir (see make help) -tests2.%: - @$(MAKE) -C tests/tests2 $@ - -testspp.%: - @$(MAKE) -C tests/pp $@ - -clean: - @rm -f tcc$(EXESUF) tcc_p$(EXESUF) *-tcc$(EXESUF) tags ETAGS *.pod - @rm -f *.o *.a *.so* *.out *.log lib*.def *.exe *.dll a.out *.dylib *_.h - @$(MAKE) -s -C lib $@ - @$(MAKE) -s -C tests $@ - -distclean: clean - @rm -fv config.h config.mak config.texi - @rm -fv $(TCCDOCS) - -.PHONY: all clean test tar tags ETAGS doc distclean install uninstall FORCE - -help: - @echo "make" - @echo " build native compiler (from separate objects)" - @echo "" - @echo "make cross" - @echo " build cross compilers (from one source)" - @echo "" - @echo "make ONE_SOURCE=no/yes SILENT=no/yes" - @echo " force building from separate/one object(s), less/more silently" - @echo "" - @echo "make cross-TARGET" - @echo " build one specific cross compiler for 'TARGET'. Currently supported:" - @echo " $(wordlist 1,6,$(TCC_X))" - @echo " $(wordlist 7,99,$(TCC_X))" - @echo "" - @echo "make test" - @echo " run all tests" - @echo "" - @echo "make tests2.all / make tests2.37 / make tests2.37+" - @echo " run all/single test(s) from tests2, optionally update .expect" - @echo "" - @echo "make testspp.all / make testspp.17" - @echo " run all/single test(s) from tests/pp" - @echo "" - @echo "Other supported make targets:" - @echo " install install-strip doc clean tags ETAGS tar distclean help" - @echo "" - @echo "Custom configuration:" - @echo " The makefile includes a file 'config-extra.mak' if it is present." - @echo " This file may contain some custom configuration. For example:" - @echo " NATIVE_DEFINES += -D..." - @echo " Or for example to configure the search paths for a cross-compiler" - @echo " that expects the linux files in /i386-linux:" - @echo " ROOT-i386 = {B}/i386-linux" - @echo " CRT-i386 = {B}/i386-linux/usr/lib" - @echo " LIB-i386 = {B}/i386-linux/lib:{B}/i386-linux/usr/lib" - @echo " INC-i386 = {B}/lib/include:{B}/i386-linux/usr/include" - @echo " DEF-i386 += -D__linux__" - -# -------------------------------------------------------------------------- -endif # ($(INCLUDED),no) diff --git a/05/tcc-final/README b/05/tcc-final/README deleted file mode 100644 index 809dd8d..0000000 --- a/05/tcc-final/README +++ /dev/null @@ -1,96 +0,0 @@ -Tiny C Compiler - C Scripting Everywhere - The Smallest ANSI C compiler ------------------------------------------------------------------------ - -Features: --------- - -- SMALL! You can compile and execute C code everywhere, for example on - rescue disks. - -- FAST! tcc generates optimized x86 code. No byte code - overhead. Compile, assemble and link about 7 times faster than 'gcc - -O0'. - -- UNLIMITED! Any C dynamic library can be used directly. TCC is - heading toward full ISOC99 compliance. TCC can of course compile - itself. - -- SAFE! tcc includes an optional memory and bound checker. Bound - checked code can be mixed freely with standard code. - -- Compile and execute C source directly. No linking or assembly - necessary. Full C preprocessor included. - -- C script supported : just add '#!/usr/local/bin/tcc -run' at the first - line of your C source, and execute it directly from the command - line. - -Documentation: -------------- - -1) Installation on a i386/x86_64/arm/aarch64/riscv64 - Linux/macOS/FreeBSD/NetBSD/OpenBSD hosts. - - ./configure - make - make test - make install - - Notes: For FreeBSD, NetBSD and OpenBSD, gmake should be used instead of make. - For Windows read tcc-win32.txt. - -makeinfo must be installed to compile the doc. By default, tcc is -installed in /usr/local/bin. ./configure --help shows configuration -options. - - -2) Introduction - -We assume here that you know ANSI C. Look at the example ex1.c to know -what the programs look like. - -The include file can be used if you want a small basic libc -include support (especially useful for floppy disks). Of course, you -can also use standard headers, although they are slower to compile. - -You can begin your C script with '#!/usr/local/bin/tcc -run' on the first -line and set its execute bits (chmod a+x your_script). Then, you can -launch the C code as a shell or perl script :-) The command line -arguments are put in 'argc' and 'argv' of the main functions, as in -ANSI C. - -3) Examples - -ex1.c: simplest example (hello world). Can also be launched directly -as a script: './ex1.c'. - -ex2.c: more complicated example: find a number with the four -operations given a list of numbers (benchmark). - -ex3.c: compute fibonacci numbers (benchmark). - -ex4.c: more complicated: X11 program. Very complicated test in fact -because standard headers are being used ! As for ex1.c, can also be launched -directly as a script: './ex4.c'. - -ex5.c: 'hello world' with standard glibc headers. - -tcc.c: TCC can of course compile itself. Used to check the code -generator. - -tcctest.c: auto test for TCC which tests many subtle possible bugs. Used -when doing 'make test'. - -4) Full Documentation - -Please read tcc-doc.html to have all the features of TCC. - -Additional information is available for the Windows port in tcc-win32.txt. - -License: -------- - -TCC is distributed under the GNU Lesser General Public License (see -COPYING file). - -Fabrice Bellard. diff --git a/05/tcc-final/RELICENSING b/05/tcc-final/RELICENSING deleted file mode 100644 index 6c69612..0000000 --- a/05/tcc-final/RELICENSING +++ /dev/null @@ -1,63 +0,0 @@ - - Relicensing TinyCC - ------------------ - - The authors listed below hereby confirm their agreement to relicense TinyCC - including their past contributions under the following terms: - - - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - - - Author (name) I agree (YES/NO) Files/Features (optional) - ------------------------------------------------------------------------------ - Adam Sampson YES makefiles - Daniel Glöckner NO arm-gen.c - Daniel Glöckner YES not arm-gen.c - Danny Milosavljevic YES arm-asm.c riscv64-asm.c - Edmund Grimley Evans YES arm64 - Fabrice Bellard YES original author - Frédéric Féret YES x86 64/16 bit asm - grischka YES tccpe.c - Henry Kroll YES - Herman ten Brugge YES - Joe Soroka YES - Kirill Smelkov YES - mingodad YES - Pip Cet YES - Shinichiro Hamaji YES x86_64-gen.c - Vincent Lefèvre YES - Thomas Preud'homme YES arm-gen.c - Timo VJ Lähde (Timppa) ? tiny_libmaker.c - TK ? tcccoff.c c67-gen.c - Tyge Løvset YES tgmath.h, Windows tcc_libm.h math.h - Urs Janssen YES - waddlesplash YES - Christian Jullien YES Windows Cygwin build and tests - - - ------------------------------------------------------------------------------ - - Please add yourself to the list above (rsp. replace the question mark) - and (after fetching the latest version) commit to the "mob" branch with - commit message: - - Relicensing TinyCC - - Thanks. diff --git a/05/tcc-final/TODO b/05/tcc-final/TODO deleted file mode 100644 index d810088..0000000 --- a/05/tcc-final/TODO +++ /dev/null @@ -1,100 +0,0 @@ -TODO list: - -Bugs: - -- i386 fastcall is mostly wrong -- FPU st(0) is left unclean (kwisatz haderach). Incompatible with - optimized gcc/msc code -- see transparent union pb in /urs/include/sys/socket.h -- precise behaviour of typeof with arrays ? (__put_user macro) - but should suffice for most cases) -- handle '? x, y : z' in unsized variable initialization (',' is - considered incorrectly as separator in preparser) -- transform functions to function pointers in function parameters - (net/ipv4/ip_output.c) -- fix function pointer type display -- check section alignment in C -- fix invalid cast in comparison 'if (v == (int8_t)v)' -- finish varargs.h support (gcc 3.2 testsuite issue) -- fix static functions declared inside block -- fix multiple unions init -- make libtcc fully reentrant (except for the compilation stage itself). -- struct/union/enum definitions in nested scopes (see also Debian bug #770657) -- __STDC_IEC_559__: float f(void) { static float x = 0.0 / 0.0; return x; } -- memory may be leaked after errors (longjmp). - -Portability: - -- it is assumed that int is 32-bit and sizeof(int) == 4 -- int is used when host or target size_t would make more sense -- TCC handles target floating-point (fp) values using the host's fp - arithmetic, which is simple and fast but may lead to exceptions - and inaccuracy and wrong representations when cross-compiling - -Linking: - -- static linking (-static) does not work - -Bound checking: - -- fix bound exit on RedHat 7.3 -- setjmp is not supported properly in bound checking. -- fix bound check code with '&' on local variables (currently done - only for local arrays). -- bound checking and float/long long/struct copy code. bound - checking and symbol + offset optimization - -Missing features: - -- disable-asm and disable-bcheck options -- __builtin_expect() -- atexit (Nigel Horne) -- C99: add complex types (gcc 3.2 testsuite issue) -- postfix compound literals (see 20010124-1.c) -- interactive mode / integrated debugger - -Optimizations: - -- suppress specific anonymous symbol handling -- more parse optimizations (=even faster compilation) -- memory alloc optimizations (=even faster compilation) -- optimize VT_LOCAL + const -- better local variables handling (needed for other targets) - -Not critical: - -- C99: fix multiple compound literals inits in blocks (ISOC99 - normative example - only relevant when using gotos! -> must add - boolean variable to tell if compound literal was already - initialized). -- add PowerPC generator and improve codegen for RISC (need - to suppress VT_LOCAL and use a base register instead). -- fix preprocessor symbol redefinition -- add portable byte code generator and interpreter for other - unsupported architectures. -- C++: variable declaration in for, minimal 'class' support. -- win32: __intxx. use resolve for bchecked malloc et al. - check exception code (exception filter func). -- handle void (__attribute__() *ptr)() -- VLAs are implemented in a way that is not compatible with signals: - http://lists.gnu.org/archive/html/tinycc-devel/2015-11/msg00018.html - -Fixed (probably): - -- bug with defines: - #define spin_lock(lock) do { } while (0) - #define wq_spin_lock spin_lock - #define TEST() wq_spin_lock(a) -- typedefs can be structure fields -- see bugfixes.diff + improvement.diff from Daniel Glockner -- long long constant evaluation -- add alloca() -- gcc '-E' option. -- #include_next support for /usr/include/limits ? -- function pointers/lvalues in ? : (linux kernel net/core/dev.c) -- win32: add __stdcall, check GetModuleHandle for dlls. -- macro substitution with nested definitions (ShangHongzhang) -- with "-run" and libtcc, a PLT is now built. -- '-E' option was improved -- packed attribute is now supported -- ARM and ARM64 code generators have been added. diff --git a/05/tcc-final/USES b/05/tcc-final/USES deleted file mode 100644 index 6d7a2d1..0000000 --- a/05/tcc-final/USES +++ /dev/null @@ -1,20 +0,0 @@ -The following software are known to use or support tcc builds. -Feel free to complete this list (*). - -Name Short Description ----- ----------------- -bigz An infinite precision Z & Q library. -gawk GNU awk. -gmp Library for arbitrary precision arithmetic. -gnumake GNU makefile. -mpfr Multiple-precision floating-point library. -mpc Complex floating-point library with exact rounding. -mpv A free, open source, and cross-platform media player. -openlisp ISLISP ISO/IEC 13816 Lisp interpreter and compiler. -s-nail BSD Mail/POSIX mailx: send and receive Internet mail. -sqlite Embbedable SQL engine. -st Simple Terminal. -tcc Tiny CC which compiles itself. -zlib Lossless data-compression library. - -(*) This list is ordered by name. diff --git a/05/tcc-final/VERSION b/05/tcc-final/VERSION deleted file mode 100644 index 9a54223..0000000 --- a/05/tcc-final/VERSION +++ /dev/null @@ -1 +0,0 @@ -0.9.27 diff --git a/05/tcc-final/arm-asm.c b/05/tcc-final/arm-asm.c deleted file mode 100644 index a6dec4c..0000000 --- a/05/tcc-final/arm-asm.c +++ /dev/null @@ -1,3235 +0,0 @@ -/* - * ARM specific functions for TCC assembler - * - * Copyright (c) 2001, 2002 Fabrice Bellard - * Copyright (c) 2020 Danny Milosavljevic - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifdef TARGET_DEFS_ONLY - -#define CONFIG_TCC_ASM -#define NB_ASM_REGS 16 - -ST_FUNC void g(int c); -ST_FUNC void gen_le16(int c); -ST_FUNC void gen_le32(int c); - -/*************************************************************/ -#else -/*************************************************************/ - -#define USING_GLOBALS -#include "tcc.h" - -enum { - OPT_REG32, - OPT_REGSET32, - OPT_IM8, - OPT_IM8N, - OPT_IM32, - OPT_VREG32, - OPT_VREG64, -}; -#define OP_REG32 (1 << OPT_REG32) -#define OP_VREG32 (1 << OPT_VREG32) -#define OP_VREG64 (1 << OPT_VREG64) -#define OP_REG (OP_REG32 | OP_VREG32 | OP_VREG64) -#define OP_IM32 (1 << OPT_IM32) -#define OP_IM8 (1 << OPT_IM8) -#define OP_IM8N (1 << OPT_IM8N) -#define OP_REGSET32 (1 << OPT_REGSET32) - -typedef struct Operand { - uint32_t type; - union { - uint8_t reg; - uint16_t regset; - ExprValue e; - }; -} Operand; - -/* Read the VFP register referred to by token T. - If OK, returns its number. - If not OK, returns -1. */ -static int asm_parse_vfp_regvar(int t, int double_precision) -{ - if (double_precision) { - if (t >= TOK_ASM_d0 && t <= TOK_ASM_d15) - return t - TOK_ASM_d0; - } else { - if (t >= TOK_ASM_s0 && t <= TOK_ASM_s31) - return t - TOK_ASM_s0; - } - return -1; -} - -/* Parse a text containing operand and store the result in OP */ -static void parse_operand(TCCState *s1, Operand *op) -{ - ExprValue e; - int8_t reg; - uint16_t regset = 0; - - op->type = 0; - - if (tok == '{') { // regset literal - next(); // skip '{' - while (tok != '}' && tok != TOK_EOF) { - reg = asm_parse_regvar(tok); - if (reg == -1) { - expect("register"); - return; - } else - next(); // skip register name - - if ((1 << reg) < regset) - tcc_warning("registers will be processed in ascending order by hardware--but are not specified in ascending order here"); - regset |= 1 << reg; - if (tok != ',') - break; - next(); // skip ',' - } - if (tok != '}') - expect("'}'"); - next(); // skip '}' - if (regset == 0) { - // ARM instructions don't support empty regset. - tcc_error("empty register list is not supported"); - } else { - op->type = OP_REGSET32; - op->regset = regset; - } - return; - } else if ((reg = asm_parse_regvar(tok)) != -1) { - next(); // skip register name - op->type = OP_REG32; - op->reg = (uint8_t) reg; - return; - } else if ((reg = asm_parse_vfp_regvar(tok, 0)) != -1) { - next(); // skip register name - op->type = OP_VREG32; - op->reg = (uint8_t) reg; - return; - } else if ((reg = asm_parse_vfp_regvar(tok, 1)) != -1) { - next(); // skip register name - op->type = OP_VREG64; - op->reg = (uint8_t) reg; - return; - } else if (tok == '#' || tok == '$') { - /* constant value */ - next(); // skip '#' or '$' - } - asm_expr(s1, &e); - op->type = OP_IM32; - op->e = e; - if (!op->e.sym) { - if ((int) op->e.v < 0 && (int) op->e.v >= -255) - op->type = OP_IM8N; - else if (op->e.v == (uint8_t)op->e.v) - op->type = OP_IM8; - } else - expect("operand"); -} - -/* XXX: make it faster ? */ -ST_FUNC void g(int c) -{ - int ind1; - if (nocode_wanted) - return; - ind1 = ind + 1; - if (ind1 > cur_text_section->data_allocated) - section_realloc(cur_text_section, ind1); - cur_text_section->data[ind] = c; - ind = ind1; -} - -ST_FUNC void gen_le16 (int i) -{ - g(i); - g(i>>8); -} - -ST_FUNC void gen_le32 (int i) -{ - int ind1; - if (nocode_wanted) - return; - ind1 = ind + 4; - if (ind1 > cur_text_section->data_allocated) - section_realloc(cur_text_section, ind1); - cur_text_section->data[ind++] = i & 0xFF; - cur_text_section->data[ind++] = (i >> 8) & 0xFF; - cur_text_section->data[ind++] = (i >> 16) & 0xFF; - cur_text_section->data[ind++] = (i >> 24) & 0xFF; -} - -ST_FUNC void gen_expr32(ExprValue *pe) -{ - gen_le32(pe->v); -} - -static uint32_t condition_code_of_token(int token) { - if (token < TOK_ASM_nopeq) { - expect("condition-enabled instruction"); - return 0; - } else - return (token - TOK_ASM_nopeq) & 15; -} - -static void asm_emit_opcode(int token, uint32_t opcode) { - gen_le32((condition_code_of_token(token) << 28) | opcode); -} - -static void asm_emit_unconditional_opcode(uint32_t opcode) { - gen_le32(opcode); -} - -static void asm_emit_coprocessor_opcode(uint32_t high_nibble, uint8_t cp_number, uint8_t cp_opcode, uint8_t cp_destination_register, uint8_t cp_n_operand_register, uint8_t cp_m_operand_register, uint8_t cp_opcode2, int inter_processor_transfer) -{ - uint32_t opcode = 0xe000000; - if (inter_processor_transfer) - opcode |= 1 << 4; - //assert(cp_opcode < 16); - opcode |= cp_opcode << 20; - //assert(cp_n_operand_register < 16); - opcode |= cp_n_operand_register << 16; - //assert(cp_destination_register < 16); - opcode |= cp_destination_register << 12; - //assert(cp_number < 16); - opcode |= cp_number << 8; - //assert(cp_information < 8); - opcode |= cp_opcode2 << 5; - //assert(cp_m_operand_register < 16); - opcode |= cp_m_operand_register; - asm_emit_unconditional_opcode((high_nibble << 28) | opcode); -} - -static void asm_nullary_opcode(int token) -{ - switch (ARM_INSTRUCTION_GROUP(token)) { - case TOK_ASM_nopeq: - asm_emit_opcode(token, 0xd << 21); // mov r0, r0 - break; - case TOK_ASM_wfeeq: - asm_emit_opcode(token, 0x320f002); - case TOK_ASM_wfieq: - asm_emit_opcode(token, 0x320f003); - break; - default: - expect("nullary instruction"); - } -} - -static void asm_unary_opcode(TCCState *s1, int token) -{ - Operand op; - parse_operand(s1, &op); - - switch (ARM_INSTRUCTION_GROUP(token)) { - case TOK_ASM_swieq: - case TOK_ASM_svceq: - if (op.type != OP_IM8) - expect("immediate 8-bit unsigned integer"); - else { - /* Note: Dummy operand (ignored by processor): ARM ref documented 0...255, ARM instruction set documented 24 bit */ - asm_emit_opcode(token, (0xf << 24) | op.e.v); - } - break; - default: - expect("unary instruction"); - } -} - -static void asm_binary_opcode(TCCState *s1, int token) -{ - Operand ops[2]; - Operand rotation; - uint32_t encoded_rotation = 0; - uint64_t amount; - parse_operand(s1, &ops[0]); - if (tok == ',') - next(); - else - expect("','"); - parse_operand(s1, &ops[1]); - if (ops[0].type != OP_REG32) { - expect("(destination operand) register"); - return; - } - - if (ops[0].reg == 15) { - tcc_error("'%s' does not support 'pc' as operand", get_tok_str(token, NULL)); - return; - } - - if (ops[0].reg == 13) - tcc_warning("Using 'sp' as operand with '%s' is deprecated by ARM", get_tok_str(token, NULL)); - - if (ops[1].type != OP_REG32) { - switch (ARM_INSTRUCTION_GROUP(token)) { - case TOK_ASM_movteq: - case TOK_ASM_movweq: - if (ops[1].type == OP_IM8 || ops[1].type == OP_IM8N || ops[1].type == OP_IM32) { - if (ops[1].e.v >= 0 && ops[1].e.v <= 0xFFFF) { - uint16_t immediate_value = ops[1].e.v; - switch (ARM_INSTRUCTION_GROUP(token)) { - case TOK_ASM_movteq: - asm_emit_opcode(token, 0x3400000 | (ops[0].reg << 12) | (immediate_value & 0xF000) << 4 | (immediate_value & 0xFFF)); - break; - case TOK_ASM_movweq: - asm_emit_opcode(token, 0x3000000 | (ops[0].reg << 12) | (immediate_value & 0xF000) << 4 | (immediate_value & 0xFFF)); - break; - } - } else - expect("(source operand) immediate 16 bit value"); - } else - expect("(source operand) immediate"); - break; - default: - expect("(source operand) register"); - } - return; - } - - if (ops[1].reg == 15) { - tcc_error("'%s' does not support 'pc' as operand", get_tok_str(token, NULL)); - return; - } - - if (ops[1].reg == 13) - tcc_warning("Using 'sp' as operand with '%s' is deprecated by ARM", get_tok_str(token, NULL)); - - if (tok == ',') { - next(); // skip ',' - if (tok == TOK_ASM_ror) { - next(); // skip 'ror' - parse_operand(s1, &rotation); - if (rotation.type != OP_IM8) { - expect("immediate value for rotation"); - return; - } else { - amount = rotation.e.v; - switch (amount) { - case 8: - encoded_rotation = 1 << 10; - break; - case 16: - encoded_rotation = 2 << 10; - break; - case 24: - encoded_rotation = 3 << 10; - break; - default: - expect("'8' or '16' or '24'"); - return; - } - } - } - } - switch (ARM_INSTRUCTION_GROUP(token)) { - case TOK_ASM_clzeq: - if (encoded_rotation) - tcc_error("clz does not support rotation"); - asm_emit_opcode(token, 0x16f0f10 | (ops[0].reg << 12) | ops[1].reg); - break; - case TOK_ASM_sxtbeq: - asm_emit_opcode(token, 0x6af0070 | (ops[0].reg << 12) | ops[1].reg | encoded_rotation); - break; - case TOK_ASM_sxtheq: - asm_emit_opcode(token, 0x6bf0070 | (ops[0].reg << 12) | ops[1].reg | encoded_rotation); - break; - case TOK_ASM_uxtbeq: - asm_emit_opcode(token, 0x6ef0070 | (ops[0].reg << 12) | ops[1].reg | encoded_rotation); - break; - case TOK_ASM_uxtheq: - asm_emit_opcode(token, 0x6ff0070 | (ops[0].reg << 12) | ops[1].reg | encoded_rotation); - break; - default: - expect("binary instruction"); - } -} - -static void asm_coprocessor_opcode(TCCState *s1, int token) { - uint8_t coprocessor; - Operand opcode1; - Operand opcode2; - uint8_t registers[3]; - unsigned int i; - uint8_t high_nibble; - uint8_t mrc = 0; - - if (tok >= TOK_ASM_p0 && tok <= TOK_ASM_p15) { - coprocessor = tok - TOK_ASM_p0; - next(); - } else { - expect("'p'"); - return; - } - - if (tok == ',') - next(); - else - expect("','"); - - parse_operand(s1, &opcode1); - if (opcode1.type != OP_IM8 || opcode1.e.v > 15) { - tcc_error("opcode1 of instruction '%s' must be an immediate value between 0 and 15", get_tok_str(token, NULL)); - return; - } - - for (i = 0; i < 3; ++i) { - if (tok == ',') - next(); - else - expect("','"); - if (i == 0 && token != TOK_ASM_cdp2 && (ARM_INSTRUCTION_GROUP(token) == TOK_ASM_mrceq || ARM_INSTRUCTION_GROUP(token) == TOK_ASM_mcreq)) { - if (tok >= TOK_ASM_r0 && tok <= TOK_ASM_r15) { - registers[i] = tok - TOK_ASM_r0; - next(); - } else { - expect("'r'"); - return; - } - } else { - if (tok >= TOK_ASM_c0 && tok <= TOK_ASM_c15) { - registers[i] = tok - TOK_ASM_c0; - next(); - } else { - expect("'c'"); - return; - } - } - } - if (tok == ',') { - next(); - parse_operand(s1, &opcode2); - } else { - opcode2.type = OP_IM8; - opcode2.e.v = 0; - } - if (opcode2.type != OP_IM8 || opcode2.e.v > 15) { - tcc_error("opcode2 of instruction '%s' must be an immediate value between 0 and 15", get_tok_str(token, NULL)); - return; - } - - if (token == TOK_ASM_cdp2) { - high_nibble = 0xF; - asm_emit_coprocessor_opcode(high_nibble, coprocessor, opcode1.e.v, registers[0], registers[1], registers[2], opcode2.e.v, 0); - return; - } else - high_nibble = condition_code_of_token(token); - - switch (ARM_INSTRUCTION_GROUP(token)) { - case TOK_ASM_cdpeq: - asm_emit_coprocessor_opcode(high_nibble, coprocessor, opcode1.e.v, registers[0], registers[1], registers[2], opcode2.e.v, 0); - break; - case TOK_ASM_mrceq: - // opcode1 encoding changes! highest and lowest bit gone. - mrc = 1; - /* fallthrough */ - case TOK_ASM_mcreq: - // opcode1 encoding changes! highest and lowest bit gone. - if (opcode1.e.v > 7) { - tcc_error("opcode1 of instruction '%s' must be an immediate value between 0 and 7", get_tok_str(token, NULL)); - return; - } - asm_emit_coprocessor_opcode(high_nibble, coprocessor, (opcode1.e.v << 1) | mrc, registers[0], registers[1], registers[2], opcode2.e.v, 1); - break; - default: - expect("known instruction"); - } -} - -/* data processing and single data transfer instructions only */ -#define ENCODE_RN(register_index) ((register_index) << 16) -#define ENCODE_RD(register_index) ((register_index) << 12) -#define ENCODE_SET_CONDITION_CODES (1 << 20) - -/* Note: For data processing instructions, "1" means immediate. - Note: For single data transfer instructions, "0" means immediate. */ -#define ENCODE_IMMEDIATE_FLAG (1 << 25) - -#define ENCODE_BARREL_SHIFTER_SHIFT_BY_REGISTER (1 << 4) -#define ENCODE_BARREL_SHIFTER_MODE_LSL (0 << 5) -#define ENCODE_BARREL_SHIFTER_MODE_LSR (1 << 5) -#define ENCODE_BARREL_SHIFTER_MODE_ASR (2 << 5) -#define ENCODE_BARREL_SHIFTER_MODE_ROR (3 << 5) -#define ENCODE_BARREL_SHIFTER_REGISTER(register_index) ((register_index) << 8) -#define ENCODE_BARREL_SHIFTER_IMMEDIATE(value) ((value) << 7) - -static void asm_block_data_transfer_opcode(TCCState *s1, int token) -{ - uint32_t opcode; - int op0_exclam = 0; - Operand ops[2]; - int nb_ops = 1; - parse_operand(s1, &ops[0]); - if (tok == '!') { - op0_exclam = 1; - next(); // skip '!' - } - if (tok == ',') { - next(); // skip comma - parse_operand(s1, &ops[1]); - ++nb_ops; - } - if (nb_ops < 1) { - expect("at least one operand"); - return; - } else if (ops[nb_ops - 1].type != OP_REGSET32) { - expect("(last operand) register list"); - return; - } - - // block data transfer: 1 0 0 P U S W L << 20 (general case): - // operands: - // Rn: bits 19...16 base register - // Register List: bits 15...0 - - switch (ARM_INSTRUCTION_GROUP(token)) { - case TOK_ASM_pusheq: // TODO: Optimize 1-register case to: str ?, [sp, #-4]! - // Instruction: 1 I=0 P=1 U=0 S=0 W=1 L=0 << 20, op 1101 - // operands: - // Rn: base register - // Register List: bits 15...0 - if (nb_ops != 1) - expect("exactly one operand"); - else - asm_emit_opcode(token, (0x92d << 16) | ops[0].regset); // TODO: base register ? - break; - case TOK_ASM_popeq: // TODO: Optimize 1-register case to: ldr ?, [sp], #4 - // Instruction: 1 I=0 P=0 U=1 S=0 W=0 L=1 << 20, op 1101 - // operands: - // Rn: base register - // Register List: bits 15...0 - if (nb_ops != 1) - expect("exactly one operand"); - else - asm_emit_opcode(token, (0x8bd << 16) | ops[0].regset); // TODO: base register ? - break; - case TOK_ASM_stmdaeq: - case TOK_ASM_ldmdaeq: - case TOK_ASM_stmeq: - case TOK_ASM_ldmeq: - case TOK_ASM_stmiaeq: - case TOK_ASM_ldmiaeq: - case TOK_ASM_stmdbeq: - case TOK_ASM_ldmdbeq: - case TOK_ASM_stmibeq: - case TOK_ASM_ldmibeq: - switch (ARM_INSTRUCTION_GROUP(token)) { - case TOK_ASM_stmdaeq: // post-decrement store - opcode = 0x80 << 20; - break; - case TOK_ASM_ldmdaeq: // post-decrement load - opcode = 0x81 << 20; - break; - case TOK_ASM_stmeq: // post-increment store - case TOK_ASM_stmiaeq: // post-increment store - opcode = 0x88 << 20; - break; - case TOK_ASM_ldmeq: // post-increment load - case TOK_ASM_ldmiaeq: // post-increment load - opcode = 0x89 << 20; - break; - case TOK_ASM_stmdbeq: // pre-decrement store - opcode = 0x90 << 20; - break; - case TOK_ASM_ldmdbeq: // pre-decrement load - opcode = 0x91 << 20; - break; - case TOK_ASM_stmibeq: // pre-increment store - opcode = 0x98 << 20; - break; - case TOK_ASM_ldmibeq: // pre-increment load - opcode = 0x99 << 20; - break; - default: - tcc_error("internal error: This place should not be reached (fallback in asm_block_data_transfer_opcode)"); - } - // operands: - // Rn: first operand - // Register List: lower bits - if (nb_ops != 2) - expect("exactly two operands"); - else if (ops[0].type != OP_REG32) - expect("(first operand) register"); - else { - if (op0_exclam) - opcode |= 1 << 21; // writeback - asm_emit_opcode(token, opcode | ENCODE_RN(ops[0].reg) | ops[1].regset); - } - break; - default: - expect("block data transfer instruction"); - } -} - -/* Parses shift directive and returns the parts that would have to be set in the opcode because of it. - Does not encode the actual shift amount. - It's not an error if there is no shift directive. - - NB_SHIFT: will be set to 1 iff SHIFT is filled. Note that for rrx, there's no need to fill SHIFT. - SHIFT: will be filled in with the shift operand to use, if any. */ -static uint32_t asm_parse_optional_shift(TCCState* s1, int* nb_shift, Operand* shift) -{ - uint32_t opcode = 0; - *nb_shift = 0; - switch (tok) { - case TOK_ASM_asl: - case TOK_ASM_lsl: - case TOK_ASM_asr: - case TOK_ASM_lsr: - case TOK_ASM_ror: - switch (tok) { - case TOK_ASM_asl: - /* fallthrough */ - case TOK_ASM_lsl: - opcode = ENCODE_BARREL_SHIFTER_MODE_LSL; - break; - case TOK_ASM_asr: - opcode = ENCODE_BARREL_SHIFTER_MODE_ASR; - break; - case TOK_ASM_lsr: - opcode = ENCODE_BARREL_SHIFTER_MODE_LSR; - break; - case TOK_ASM_ror: - opcode = ENCODE_BARREL_SHIFTER_MODE_ROR; - break; - } - next(); - parse_operand(s1, shift); - *nb_shift = 1; - break; - case TOK_ASM_rrx: - next(); - opcode = ENCODE_BARREL_SHIFTER_MODE_ROR; - break; - } - return opcode; -} - -static uint32_t asm_encode_shift(Operand* shift) -{ - uint64_t amount; - uint32_t operands = 0; - switch (shift->type) { - case OP_REG32: - if (shift->reg == 15) - tcc_error("r15 cannot be used as a shift count"); - else { - operands = ENCODE_BARREL_SHIFTER_SHIFT_BY_REGISTER; - operands |= ENCODE_BARREL_SHIFTER_REGISTER(shift->reg); - } - break; - case OP_IM8: - amount = shift->e.v; - if (amount > 0 && amount < 32) - operands = ENCODE_BARREL_SHIFTER_IMMEDIATE(amount); - else - tcc_error("shift count out of range"); - break; - default: - tcc_error("unknown shift amount"); - } - return operands; -} - -static void asm_data_processing_opcode(TCCState *s1, int token) -{ - Operand ops[3]; - int nb_ops; - Operand shift = {0}; - int nb_shift = 0; - uint32_t operands = 0; - - /* modulo 16 entries per instruction for the different condition codes */ - uint32_t opcode_idx = (ARM_INSTRUCTION_GROUP(token) - TOK_ASM_andeq) >> 4; - uint32_t opcode_nos = opcode_idx >> 1; // without "s"; "OpCode" in ARM docs - - for (nb_ops = 0; nb_ops < sizeof(ops)/sizeof(ops[0]); ) { - if (tok == TOK_ASM_asl || tok == TOK_ASM_lsl || tok == TOK_ASM_lsr || tok == TOK_ASM_asr || tok == TOK_ASM_ror || tok == TOK_ASM_rrx) - break; - parse_operand(s1, &ops[nb_ops]); - ++nb_ops; - if (tok != ',') - break; - next(); // skip ',' - } - if (tok == ',') - next(); - operands |= asm_parse_optional_shift(s1, &nb_shift, &shift); - if (nb_ops < 2) - expect("at least two operands"); - else if (nb_ops == 2) { - memcpy(&ops[2], &ops[1], sizeof(ops[1])); // move ops[2] - memcpy(&ops[1], &ops[0], sizeof(ops[0])); // ops[1] was implicit - nb_ops = 3; - } else if (nb_ops == 3) { - if (opcode_nos == 0xd || opcode_nos == 0xf || opcode_nos == 0xa || opcode_nos == 0xb || opcode_nos == 0x8 || opcode_nos == 0x9) { // mov, mvn, cmp, cmn, tst, teq - tcc_error("'%s' cannot be used with three operands", get_tok_str(token, NULL)); - return; - } - } - if (nb_ops != 3) { - expect("two or three operands"); - return; - } else { - uint32_t opcode = 0; - uint32_t immediate_value; - uint8_t half_immediate_rotation; - if (nb_shift && shift.type == OP_REG32) { - if ((ops[0].type == OP_REG32 && ops[0].reg == 15) || - (ops[1].type == OP_REG32 && ops[1].reg == 15)) { - tcc_error("Using the 'pc' register in data processing instructions that have a register-controlled shift is not implemented by ARM"); - return; - } - } - - // data processing (general case): - // operands: - // Rn: bits 19...16 (first operand) - // Rd: bits 15...12 (destination) - // Operand2: bits 11...0 (second operand); depending on I that's either a register or an immediate - // operator: - // bits 24...21: "OpCode"--see below - - /* operations in the token list are ordered by opcode */ - opcode = opcode_nos << 21; // drop "s" - if (ops[0].type != OP_REG32) - expect("(destination operand) register"); - else if (opcode_nos == 0xa || opcode_nos == 0xb || opcode_nos == 0x8 || opcode_nos == 0x9) // cmp, cmn, tst, teq - operands |= ENCODE_SET_CONDITION_CODES; // force S set, otherwise it's a completely different instruction. - else - operands |= ENCODE_RD(ops[0].reg); - if (ops[1].type != OP_REG32) - expect("(first source operand) register"); - else if (!(opcode_nos == 0xd || opcode_nos == 0xf)) // not: mov, mvn (those have only one source operand) - operands |= ENCODE_RN(ops[1].reg); - switch (ops[2].type) { - case OP_REG32: - operands |= ops[2].reg; - break; - case OP_IM8: - case OP_IM32: - operands |= ENCODE_IMMEDIATE_FLAG; - immediate_value = ops[2].e.v; - for (half_immediate_rotation = 0; half_immediate_rotation < 16; ++half_immediate_rotation) { - if (immediate_value >= 0x00 && immediate_value < 0x100) - break; - // rotate left by two - immediate_value = ((immediate_value & 0x3FFFFFFF) << 2) | ((immediate_value & 0xC0000000) >> 30); - } - if (half_immediate_rotation >= 16) { - /* fallthrough */ - } else { - operands |= immediate_value; - operands |= half_immediate_rotation << 8; - break; - } - case OP_IM8N: // immediate negative value - operands |= ENCODE_IMMEDIATE_FLAG; - immediate_value = ops[2].e.v; - /* Instruction swapping: - 0001 = EOR - Rd:= Op1 EOR Op2 -> difficult - 0011 = RSB - Rd:= Op2 - Op1 -> difficult - 0111 = RSC - Rd:= Op2 - Op1 + C -> difficult - 1000 = TST - CC on: Op1 AND Op2 -> difficult - 1001 = TEQ - CC on: Op1 EOR Op2 -> difficult - 1100 = ORR - Rd:= Op1 OR Op2 -> difficult - */ - switch (opcode_nos) { - case 0x0: // AND - Rd:= Op1 AND Op2 - opcode = 0xe << 21; // BIC - immediate_value = ~immediate_value; - break; - case 0x2: // SUB - Rd:= Op1 - Op2 - opcode = 0x4 << 21; // ADD - immediate_value = -immediate_value; - break; - case 0x4: // ADD - Rd:= Op1 + Op2 - opcode = 0x2 << 21; // SUB - immediate_value = -immediate_value; - break; - case 0x5: // ADC - Rd:= Op1 + Op2 + C - opcode = 0x6 << 21; // SBC - immediate_value = ~immediate_value; - break; - case 0x6: // SBC - Rd:= Op1 - Op2 + C - opcode = 0x5 << 21; // ADC - immediate_value = ~immediate_value; - break; - case 0xa: // CMP - CC on: Op1 - Op2 - opcode = 0xb << 21; // CMN - immediate_value = -immediate_value; - break; - case 0xb: // CMN - CC on: Op1 + Op2 - opcode = 0xa << 21; // CMP - immediate_value = -immediate_value; - break; - case 0xd: // MOV - Rd:= Op2 - opcode = 0xf << 21; // MVN - immediate_value = ~immediate_value; - break; - case 0xe: // BIC - Rd:= Op1 AND NOT Op2 - opcode = 0x0 << 21; // AND - immediate_value = ~immediate_value; - break; - case 0xf: // MVN - Rd:= NOT Op2 - opcode = 0xd << 21; // MOV - immediate_value = ~immediate_value; - break; - default: - tcc_error("cannot use '%s' with a negative immediate value", get_tok_str(token, NULL)); - } - for (half_immediate_rotation = 0; half_immediate_rotation < 16; ++half_immediate_rotation) { - if (immediate_value >= 0x00 && immediate_value < 0x100) - break; - // rotate left by two - immediate_value = ((immediate_value & 0x3FFFFFFF) << 2) | ((immediate_value & 0xC0000000) >> 30); - } - if (half_immediate_rotation >= 16) { - immediate_value = ops[2].e.v; - tcc_error("immediate value 0x%X cannot be encoded into ARM immediate", (unsigned) immediate_value); - return; - } - operands |= immediate_value; - operands |= half_immediate_rotation << 8; - break; - default: - expect("(second source operand) register or immediate value"); - } - - if (nb_shift) { - if (operands & ENCODE_IMMEDIATE_FLAG) - tcc_error("immediate rotation not implemented"); - else - operands |= asm_encode_shift(&shift); - } - - /* S=0 and S=1 entries alternate one after another, in that order */ - opcode |= (opcode_idx & 1) ? ENCODE_SET_CONDITION_CODES : 0; - asm_emit_opcode(token, opcode | operands); - } -} - -static void asm_shift_opcode(TCCState *s1, int token) -{ - Operand ops[3]; - int nb_ops; - int definitely_neutral = 0; - uint32_t opcode = 0xd << 21; // MOV - uint32_t operands = 0; - - for (nb_ops = 0; nb_ops < sizeof(ops)/sizeof(ops[0]); ++nb_ops) { - parse_operand(s1, &ops[nb_ops]); - if (tok != ',') { - ++nb_ops; - break; - } - next(); // skip ',' - } - if (nb_ops < 2) { - expect("at least two operands"); - return; - } - - if (ops[0].type != OP_REG32) { - expect("(destination operand) register"); - return; - } else - operands |= ENCODE_RD(ops[0].reg); - - if (nb_ops == 2) { - switch (ARM_INSTRUCTION_GROUP(token)) { - case TOK_ASM_rrxseq: - opcode |= ENCODE_SET_CONDITION_CODES; - /* fallthrough */ - case TOK_ASM_rrxeq: - if (ops[1].type == OP_REG32) { - operands |= ops[1].reg; - operands |= ENCODE_BARREL_SHIFTER_MODE_ROR; - asm_emit_opcode(token, opcode | operands); - } else - tcc_error("(first source operand) register"); - return; - default: - memcpy(&ops[2], &ops[1], sizeof(ops[1])); // move ops[2] - memcpy(&ops[1], &ops[0], sizeof(ops[0])); // ops[1] was implicit - nb_ops = 3; - } - } - if (nb_ops != 3) { - expect("two or three operands"); - return; - } - - switch (ARM_INSTRUCTION_GROUP(token)) { - case TOK_ASM_lslseq: - case TOK_ASM_lsrseq: - case TOK_ASM_asrseq: - case TOK_ASM_rorseq: - opcode |= ENCODE_SET_CONDITION_CODES; - break; - } - - switch (ops[1].type) { - case OP_REG32: - operands |= ops[1].reg; - break; - case OP_IM8: - operands |= ENCODE_IMMEDIATE_FLAG; - operands |= ops[1].e.v; - tcc_error("Using an immediate value as the source operand is not possible with '%s' instruction on ARM", get_tok_str(token, NULL)); - return; - } - - switch (ops[2].type) { - case OP_REG32: - if ((ops[0].type == OP_REG32 && ops[0].reg == 15) || - (ops[1].type == OP_REG32 && ops[1].reg == 15)) { - tcc_error("Using the 'pc' register in data processing instructions that have a register-controlled shift is not implemented by ARM"); - } - operands |= asm_encode_shift(&ops[2]); - break; - case OP_IM8: - if (ops[2].e.v) - operands |= asm_encode_shift(&ops[2]); - else - definitely_neutral = 1; - break; - } - - if (!definitely_neutral) switch (ARM_INSTRUCTION_GROUP(token)) { - case TOK_ASM_lslseq: - case TOK_ASM_lsleq: - operands |= ENCODE_BARREL_SHIFTER_MODE_LSL; - break; - case TOK_ASM_lsrseq: - case TOK_ASM_lsreq: - operands |= ENCODE_BARREL_SHIFTER_MODE_LSR; - break; - case TOK_ASM_asrseq: - case TOK_ASM_asreq: - operands |= ENCODE_BARREL_SHIFTER_MODE_ASR; - break; - case TOK_ASM_rorseq: - case TOK_ASM_roreq: - operands |= ENCODE_BARREL_SHIFTER_MODE_ROR; - break; - default: - expect("shift instruction"); - return; - } - asm_emit_opcode(token, opcode | operands); -} - -static void asm_multiplication_opcode(TCCState *s1, int token) -{ - Operand ops[4]; - int nb_ops = 0; - uint32_t opcode = 0x90; - - for (nb_ops = 0; nb_ops < sizeof(ops)/sizeof(ops[0]); ++nb_ops) { - parse_operand(s1, &ops[nb_ops]); - if (tok != ',') { - ++nb_ops; - break; - } - next(); // skip ',' - } - if (nb_ops < 2) - expect("at least two operands"); - else if (nb_ops == 2) { - switch (ARM_INSTRUCTION_GROUP(token)) { - case TOK_ASM_mulseq: - case TOK_ASM_muleq: - memcpy(&ops[2], &ops[0], sizeof(ops[1])); // ARM is actually like this! - break; - default: - expect("at least three operands"); - return; - } - nb_ops = 3; - } - - // multiply (special case): - // operands: - // Rd: bits 19...16 - // Rm: bits 3...0 - // Rs: bits 11...8 - // Rn: bits 15...12 - - if (ops[0].type == OP_REG32) - opcode |= ops[0].reg << 16; - else - expect("(destination operand) register"); - if (ops[1].type == OP_REG32) - opcode |= ops[1].reg; - else - expect("(first source operand) register"); - if (ops[2].type == OP_REG32) - opcode |= ops[2].reg << 8; - else - expect("(second source operand) register"); - if (nb_ops > 3) { - if (ops[3].type == OP_REG32) - opcode |= ops[3].reg << 12; - else - expect("(third source operand) register"); - } - - switch (ARM_INSTRUCTION_GROUP(token)) { - case TOK_ASM_mulseq: - opcode |= 1 << 20; // Status - /* fallthrough */ - case TOK_ASM_muleq: - if (nb_ops != 3) - expect("three operands"); - else { - asm_emit_opcode(token, opcode); - } - break; - case TOK_ASM_mlaseq: - opcode |= 1 << 20; // Status - /* fallthrough */ - case TOK_ASM_mlaeq: - if (nb_ops != 4) - expect("four operands"); - else { - opcode |= 1 << 21; // Accumulate - asm_emit_opcode(token, opcode); - } - break; - default: - expect("known multiplication instruction"); - } -} - -static void asm_long_multiplication_opcode(TCCState *s1, int token) -{ - Operand ops[4]; - int nb_ops = 0; - uint32_t opcode = 0x90 | (1 << 23); - - for (nb_ops = 0; nb_ops < sizeof(ops)/sizeof(ops[0]); ++nb_ops) { - parse_operand(s1, &ops[nb_ops]); - if (tok != ',') { - ++nb_ops; - break; - } - next(); // skip ',' - } - if (nb_ops != 4) { - expect("four operands"); - return; - } - - // long multiply (special case): - // operands: - // RdLo: bits 15...12 - // RdHi: bits 19...16 - // Rs: bits 11...8 - // Rm: bits 3...0 - - if (ops[0].type == OP_REG32) - opcode |= ops[0].reg << 12; - else - expect("(destination lo accumulator) register"); - if (ops[1].type == OP_REG32) - opcode |= ops[1].reg << 16; - else - expect("(destination hi accumulator) register"); - if (ops[2].type == OP_REG32) - opcode |= ops[2].reg; - else - expect("(first source operand) register"); - if (ops[3].type == OP_REG32) - opcode |= ops[3].reg << 8; - else - expect("(second source operand) register"); - - switch (ARM_INSTRUCTION_GROUP(token)) { - case TOK_ASM_smullseq: - opcode |= 1 << 20; // Status - /* fallthrough */ - case TOK_ASM_smulleq: - opcode |= 1 << 22; // signed - asm_emit_opcode(token, opcode); - break; - case TOK_ASM_umullseq: - opcode |= 1 << 20; // Status - /* fallthrough */ - case TOK_ASM_umulleq: - asm_emit_opcode(token, opcode); - break; - case TOK_ASM_smlalseq: - opcode |= 1 << 20; // Status - /* fallthrough */ - case TOK_ASM_smlaleq: - opcode |= 1 << 22; // signed - opcode |= 1 << 21; // Accumulate - asm_emit_opcode(token, opcode); - break; - case TOK_ASM_umlalseq: - opcode |= 1 << 20; // Status - /* fallthrough */ - case TOK_ASM_umlaleq: - opcode |= 1 << 21; // Accumulate - asm_emit_opcode(token, opcode); - break; - default: - expect("known long multiplication instruction"); - } -} - -static void asm_single_data_transfer_opcode(TCCState *s1, int token) -{ - Operand ops[3]; - Operand strex_operand; - Operand shift; - int nb_shift = 0; - int exclam = 0; - int closed_bracket = 0; - int op2_minus = 0; - uint32_t opcode = 0; - // Note: ldr r0, [r4, #4] ; simple offset: r0 = *(int*)(r4+4); r4 unchanged - // Note: ldr r0, [r4, #4]! ; pre-indexed: r0 = *(int*)(r4+4); r4 = r4+4 - // Note: ldr r0, [r4], #4 ; post-indexed: r0 = *(int*)(r4+0); r4 = r4+4 - - parse_operand(s1, &ops[0]); - if (ops[0].type == OP_REG32) - opcode |= ENCODE_RD(ops[0].reg); - else { - expect("(destination operand) register"); - return; - } - if (tok != ',') - expect("at least two arguments"); - else - next(); // skip ',' - - switch (ARM_INSTRUCTION_GROUP(token)) { - case TOK_ASM_strexbeq: - case TOK_ASM_strexeq: - parse_operand(s1, &strex_operand); - if (strex_operand.type != OP_REG32) { - expect("register"); - return; - } - if (tok != ',') - expect("at least three arguments"); - else - next(); // skip ',' - break; - } - - if (tok != '[') - expect("'['"); - else - next(); // skip '[' - - parse_operand(s1, &ops[1]); - if (ops[1].type == OP_REG32) - opcode |= ENCODE_RN(ops[1].reg); - else { - expect("(first source operand) register"); - return; - } - if (tok == ']') { - next(); - closed_bracket = 1; - // exclam = 1; // implicit in hardware; don't do it in software - } - if (tok == ',') { - next(); // skip ',' - if (tok == '-') { - op2_minus = 1; - next(); - } - parse_operand(s1, &ops[2]); - if (ops[2].type == OP_REG32) { - if (ops[2].reg == 15) { - tcc_error("Using 'pc' for register offset in '%s' is not implemented by ARM", get_tok_str(token, NULL)); - return; - } - if (tok == ',') { - next(); - opcode |= asm_parse_optional_shift(s1, &nb_shift, &shift); - if (opcode == 0) - expect("shift directive, or no comma"); - } - } - } else { - // end of input expression in brackets--assume 0 offset - ops[2].type = OP_IM8; - ops[2].e.v = 0; - opcode |= 1 << 24; // add offset before transfer - } - if (!closed_bracket) { - if (tok != ']') - expect("']'"); - else - next(); // skip ']' - opcode |= 1 << 24; // add offset before transfer - if (tok == '!') { - exclam = 1; - next(); // skip '!' - } - } - - // single data transfer: 0 1 I P U B W L << 20 (general case): - // operands: - // Rd: destination operand [ok] - // Rn: first source operand [ok] - // Operand2: bits 11...0 [ok] - // I: immediate operand? [ok] - // P: Pre/post indexing is PRE: Add offset before transfer [ok] - // U: Up/down is up? (*adds* offset to base) [ok] - // B: Byte/word is byte? [ok] - // W: Write address back into base? [ok] - // L: Load/store is load? [ok] - if (exclam) - opcode |= 1 << 21; // write offset back into register - - if (ops[2].type == OP_IM32 || ops[2].type == OP_IM8 || ops[2].type == OP_IM8N) { - int v = ops[2].e.v; - if (op2_minus) - tcc_error("minus before '#' not supported for immediate values"); - if (v >= 0) { - opcode |= 1 << 23; // up - if (v >= 0x1000) - tcc_error("offset out of range for '%s'", get_tok_str(token, NULL)); - else - opcode |= v; - } else { // down - if (v <= -0x1000) - tcc_error("offset out of range for '%s'", get_tok_str(token, NULL)); - else - opcode |= -v; - } - } else if (ops[2].type == OP_REG32) { - if (!op2_minus) - opcode |= 1 << 23; // up - opcode |= ENCODE_IMMEDIATE_FLAG; /* if set, it means it's NOT immediate */ - opcode |= ops[2].reg; - } else - expect("register"); - - switch (ARM_INSTRUCTION_GROUP(token)) { - case TOK_ASM_strbeq: - opcode |= 1 << 22; // B - /* fallthrough */ - case TOK_ASM_streq: - opcode |= 1 << 26; // Load/Store - if (nb_shift) - opcode |= asm_encode_shift(&shift); - asm_emit_opcode(token, opcode); - break; - case TOK_ASM_ldrbeq: - opcode |= 1 << 22; // B - /* fallthrough */ - case TOK_ASM_ldreq: - opcode |= 1 << 20; // L - opcode |= 1 << 26; // Load/Store - if (nb_shift) - opcode |= asm_encode_shift(&shift); - asm_emit_opcode(token, opcode); - break; - case TOK_ASM_strexbeq: - opcode |= 1 << 22; // B - /* fallthrough */ - case TOK_ASM_strexeq: - if ((opcode & 0xFFF) || nb_shift) { - tcc_error("neither offset nor shift allowed with 'strex'"); - return; - } else if (opcode & ENCODE_IMMEDIATE_FLAG) { // if set, it means it's NOT immediate - tcc_error("offset not allowed with 'strex'"); - return; - } - if ((opcode & (1 << 24)) == 0) { // add offset after transfer - tcc_error("adding offset after transfer not allowed with 'strex'"); - return; - } - - opcode |= 0xf90; // Used to mean: barrel shifter is enabled, barrel shift register is r15, mode is LSL - opcode |= strex_operand.reg; - asm_emit_opcode(token, opcode); - break; - case TOK_ASM_ldrexbeq: - opcode |= 1 << 22; // B - /* fallthrough */ - case TOK_ASM_ldrexeq: - if ((opcode & 0xFFF) || nb_shift) { - tcc_error("neither offset nor shift allowed with 'ldrex'"); - return; - } else if (opcode & ENCODE_IMMEDIATE_FLAG) { // if set, it means it's NOT immediate - tcc_error("offset not allowed with 'ldrex'"); - return; - } - if ((opcode & (1 << 24)) == 0) { // add offset after transfer - tcc_error("adding offset after transfer not allowed with 'ldrex'"); - return; - } - opcode |= 1 << 20; // L - opcode |= 0x00f; - opcode |= 0xf90; // Used to mean: barrel shifter is enabled, barrel shift register is r15, mode is LSL - asm_emit_opcode(token, opcode); - break; - default: - expect("data transfer instruction"); - } -} - -// Note: Only call this using a VFP register if you know exactly what you are doing (i.e. cp_number is 10 or 11 and you are doing a vmov) -static void asm_emit_coprocessor_data_transfer(uint32_t high_nibble, uint8_t cp_number, uint8_t CRd, const Operand* Rn, const Operand* offset, int offset_minus, int preincrement, int writeback, int long_transfer, int load) { - uint32_t opcode = 0x0; - opcode |= 1 << 26; // Load/Store - opcode |= 1 << 27; // coprocessor - - if (long_transfer) - opcode |= 1 << 22; // long transfer - - if (load) - opcode |= 1 << 20; // L - - opcode |= cp_number << 8; - - //assert(CRd < 16); - opcode |= ENCODE_RD(CRd); - - if (Rn->type != OP_REG32) { - expect("register"); - return; - } - //assert(Rn->reg < 16); - opcode |= ENCODE_RN(Rn->reg); - if (preincrement) - opcode |= 1 << 24; // add offset before transfer - - if (writeback) - opcode |= 1 << 21; // write offset back into register - - if (offset->type == OP_IM8 || offset->type == OP_IM8N || offset->type == OP_IM32) { - int v = offset->e.v; - if (offset_minus) - tcc_error("minus before '#' not supported for immediate values"); - if (offset->type == OP_IM8N || v < 0) - v = -v; - else - opcode |= 1 << 23; // up - if (v & 3) { - tcc_error("immediate offset must be a multiple of 4"); - return; - } - v >>= 2; - if (v > 255) { - tcc_error("immediate offset must be between -1020 and 1020"); - return; - } - opcode |= v; - } else if (offset->type == OP_REG32) { - if (!offset_minus) - opcode |= 1 << 23; // up - opcode |= ENCODE_IMMEDIATE_FLAG; /* if set, it means it's NOT immediate */ - opcode |= offset->reg; - tcc_error("Using register offset to register address is not possible here"); - return; - } else if (offset->type == OP_VREG64) { - opcode |= 16; - opcode |= offset->reg; - } else - expect("immediate or register"); - - asm_emit_unconditional_opcode((high_nibble << 28) | opcode); -} - -// Almost exactly the same as asm_single_data_transfer_opcode. -// Difference: Offsets are smaller and multiples of 4; no shifts, no STREX, ENCODE_IMMEDIATE_FLAG is inverted again. -static void asm_coprocessor_data_transfer_opcode(TCCState *s1, int token) -{ - Operand ops[3]; - uint8_t coprocessor; - uint8_t coprocessor_destination_register; - int preincrement = 0; - int exclam = 0; - int closed_bracket = 0; - int op2_minus = 0; - int long_transfer = 0; - // Note: ldc p1, c0, [r4, #4] ; simple offset: r0 = *(int*)(r4+4); r4 unchanged - // Note: ldc p2, c0, [r4, #4]! ; pre-indexed: r0 = *(int*)(r4+4); r4 = r4+4 - // Note: ldc p3, c0, [r4], #4 ; post-indexed: r0 = *(int*)(r4+0); r4 = r4+4 - - if (tok >= TOK_ASM_p0 && tok <= TOK_ASM_p15) { - coprocessor = tok - TOK_ASM_p0; - next(); - } else { - expect("'c'"); - return; - } - - if (tok == ',') - next(); - else - expect("','"); - - if (tok >= TOK_ASM_c0 && tok <= TOK_ASM_c15) { - coprocessor_destination_register = tok - TOK_ASM_c0; - next(); - } else { - expect("'c'"); - return; - } - - if (tok == ',') - next(); - else - expect("','"); - - if (tok != '[') - expect("'['"); - else - next(); // skip '[' - - parse_operand(s1, &ops[1]); - if (ops[1].type != OP_REG32) { - expect("(first source operand) register"); - return; - } - if (tok == ']') { - next(); - closed_bracket = 1; - // exclam = 1; // implicit in hardware; don't do it in software - } - if (tok == ',') { - next(); // skip ',' - if (tok == '-') { - op2_minus = 1; - next(); - } - parse_operand(s1, &ops[2]); - if (ops[2].type == OP_REG32) { - if (ops[2].reg == 15) { - tcc_error("Using 'pc' for register offset in '%s' is not implemented by ARM", get_tok_str(token, NULL)); - return; - } - } else if (ops[2].type == OP_VREG64) { - tcc_error("'%s' does not support VFP register operand", get_tok_str(token, NULL)); - return; - } - } else { - // end of input expression in brackets--assume 0 offset - ops[2].type = OP_IM8; - ops[2].e.v = 0; - preincrement = 1; // add offset before transfer - } - if (!closed_bracket) { - if (tok != ']') - expect("']'"); - else - next(); // skip ']' - preincrement = 1; // add offset before transfer - if (tok == '!') { - exclam = 1; - next(); // skip '!' - } - } - - // TODO: Support options. - - if (token == TOK_ASM_ldc2 || token == TOK_ASM_stc2 || token == TOK_ASM_ldc2l || token == TOK_ASM_stc2l) { - switch (token) { - case TOK_ASM_ldc2l: - long_transfer = 1; // long transfer - /* fallthrough */ - case TOK_ASM_ldc2: - asm_emit_coprocessor_data_transfer(0xF, coprocessor, coprocessor_destination_register, &ops[1], &ops[2], op2_minus, preincrement, exclam, long_transfer, 1); - break; - case TOK_ASM_stc2l: - long_transfer = 1; // long transfer - /* fallthrough */ - case TOK_ASM_stc2: - asm_emit_coprocessor_data_transfer(0xF, coprocessor, coprocessor_destination_register, &ops[1], &ops[2], op2_minus, preincrement, exclam, long_transfer, 0); - break; - } - } else switch (ARM_INSTRUCTION_GROUP(token)) { - case TOK_ASM_stcleq: - long_transfer = 1; - /* fallthrough */ - case TOK_ASM_stceq: - asm_emit_coprocessor_data_transfer(condition_code_of_token(token), coprocessor, coprocessor_destination_register, &ops[1], &ops[2], op2_minus, preincrement, exclam, long_transfer, 0); - break; - case TOK_ASM_ldcleq: - long_transfer = 1; - /* fallthrough */ - case TOK_ASM_ldceq: - asm_emit_coprocessor_data_transfer(condition_code_of_token(token), coprocessor, coprocessor_destination_register, &ops[1], &ops[2], op2_minus, preincrement, exclam, long_transfer, 1); - break; - default: - expect("coprocessor data transfer instruction"); - } -} - -#if defined(TCC_ARM_VFP) -#define CP_SINGLE_PRECISION_FLOAT 10 -#define CP_DOUBLE_PRECISION_FLOAT 11 - -static void asm_floating_point_single_data_transfer_opcode(TCCState *s1, int token) -{ - Operand ops[3]; - uint8_t coprocessor = 0; - uint8_t coprocessor_destination_register = 0; - int long_transfer = 0; - // Note: vldr p1, c0, [r4, #4] ; simple offset: r0 = *(int*)(r4+4); r4 unchanged - // Note: Not allowed: vldr p2, c0, [r4, #4]! ; pre-indexed: r0 = *(int*)(r4+4); r4 = r4+4 - // Note: Not allowed: vldr p3, c0, [r4], #4 ; post-indexed: r0 = *(int*)(r4+0); r4 = r4+4 - - parse_operand(s1, &ops[0]); - if (ops[0].type == OP_VREG32) { - coprocessor = CP_SINGLE_PRECISION_FLOAT; - coprocessor_destination_register = ops[0].reg; - long_transfer = coprocessor_destination_register & 1; - coprocessor_destination_register >>= 1; - } else if (ops[0].type == OP_VREG64) { - coprocessor = CP_DOUBLE_PRECISION_FLOAT; - coprocessor_destination_register = ops[0].reg; - next(); - } else { - expect("floating point register"); - return; - } - - if (tok == ',') - next(); - else - expect("','"); - - if (tok != '[') - expect("'['"); - else - next(); // skip '[' - - parse_operand(s1, &ops[1]); - if (ops[1].type != OP_REG32) { - expect("(first source operand) register"); - return; - } - if (tok == ',') { - next(); // skip ',' - parse_operand(s1, &ops[2]); - if (ops[2].type != OP_IM8 && ops[2].type != OP_IM8N) { - expect("immediate offset"); - return; - } - } else { - // end of input expression in brackets--assume 0 offset - ops[2].type = OP_IM8; - ops[2].e.v = 0; - } - if (tok != ']') - expect("']'"); - else - next(); // skip ']' - - switch (ARM_INSTRUCTION_GROUP(token)) { - case TOK_ASM_vldreq: - asm_emit_coprocessor_data_transfer(condition_code_of_token(token), coprocessor, coprocessor_destination_register, &ops[1], &ops[2], 0, 1, 0, long_transfer, 1); - break; - case TOK_ASM_vstreq: - asm_emit_coprocessor_data_transfer(condition_code_of_token(token), coprocessor, coprocessor_destination_register, &ops[1], &ops[2], 0, 1, 0, long_transfer, 0); - break; - default: - expect("floating point data transfer instruction"); - } -} - -static void asm_floating_point_block_data_transfer_opcode(TCCState *s1, int token) -{ - uint8_t coprocessor = 0; - int first_regset_register; - int last_regset_register; - uint8_t regset_item_count; - uint8_t extra_register_bit = 0; - int op0_exclam = 0; - int load = 0; - int preincrement = 0; - Operand ops[1]; - Operand offset; - switch (ARM_INSTRUCTION_GROUP(token)) { - case TOK_ASM_vpusheq: - case TOK_ASM_vpopeq: - ops[0].type = OP_REG32; - ops[0].reg = 13; // sp - op0_exclam = 1; - break; - default: - parse_operand(s1, &ops[0]); - if (tok == '!') { - op0_exclam = 1; - next(); // skip '!' - } - if (tok == ',') - next(); // skip comma - else { - expect("','"); - return; - } - } - - if (tok != '{') { - expect("'{'"); - return; - } - next(); // skip '{' - first_regset_register = asm_parse_vfp_regvar(tok, 1); - if ((first_regset_register = asm_parse_vfp_regvar(tok, 1)) != -1) { - coprocessor = CP_DOUBLE_PRECISION_FLOAT; - next(); - } else if ((first_regset_register = asm_parse_vfp_regvar(tok, 0)) != -1) { - coprocessor = CP_SINGLE_PRECISION_FLOAT; - next(); - } else { - expect("floating-point register"); - return; - } - - if (tok == '-') { - next(); - if ((last_regset_register = asm_parse_vfp_regvar(tok, coprocessor == CP_DOUBLE_PRECISION_FLOAT)) != -1) - next(); - else { - expect("floating-point register"); - return; - } - } else - last_regset_register = first_regset_register; - - if (last_regset_register < first_regset_register) { - tcc_error("registers will be processed in ascending order by hardware--but are not specified in ascending order here"); - return; - } - if (tok != '}') { - expect("'}'"); - return; - } - next(); // skip '}' - - // Note: 0 (one down) is not implemented by us regardless. - regset_item_count = last_regset_register - first_regset_register + 1; - if (coprocessor == CP_DOUBLE_PRECISION_FLOAT) - regset_item_count <<= 1; - else { - extra_register_bit = first_regset_register & 1; - first_regset_register >>= 1; - } - offset.type = OP_IM8; - offset.e.v = regset_item_count << 2; - switch (ARM_INSTRUCTION_GROUP(token)) { - case TOK_ASM_vstmeq: // post-increment store - case TOK_ASM_vstmiaeq: // post-increment store - break; - case TOK_ASM_vpopeq: - case TOK_ASM_vldmeq: // post-increment load - case TOK_ASM_vldmiaeq: // post-increment load - load = 1; - break; - case TOK_ASM_vldmdbeq: // pre-decrement load - load = 1; - /* fallthrough */ - case TOK_ASM_vpusheq: - case TOK_ASM_vstmdbeq: // pre-decrement store - offset.type = OP_IM8N; - offset.e.v = -offset.e.v; - preincrement = 1; - break; - default: - expect("floating point block data transfer instruction"); - return; - } - if (ops[0].type != OP_REG32) - expect("(first operand) register"); - else if (ops[0].reg == 15) - tcc_error("'%s' does not support 'pc' as operand", get_tok_str(token, NULL)); - else if (!op0_exclam && ARM_INSTRUCTION_GROUP(token) != TOK_ASM_vldmeq && ARM_INSTRUCTION_GROUP(token) != TOK_ASM_vldmiaeq && ARM_INSTRUCTION_GROUP(token) != TOK_ASM_vstmeq && ARM_INSTRUCTION_GROUP(token) != TOK_ASM_vstmiaeq) - tcc_error("first operand of '%s' should have an exclamation mark", get_tok_str(token, NULL)); - else - asm_emit_coprocessor_data_transfer(condition_code_of_token(token), coprocessor, first_regset_register, &ops[0], &offset, 0, preincrement, op0_exclam, extra_register_bit, load); -} - -#define VMOV_FRACTIONAL_DIGITS 7 -#define VMOV_ONE 10000000 /* pow(10, VMOV_FRACTIONAL_DIGITS) */ - -static uint32_t vmov_parse_fractional_part(const char* s) -{ - uint32_t result = 0; - int i; - for (i = 0; i < VMOV_FRACTIONAL_DIGITS; ++i) { - char c = *s; - result *= 10; - if (c >= '0' && c <= '9') { - result += (c - '0'); - ++s; - } - } - if (*s) - expect("decimal numeral"); - return result; -} - -static int vmov_linear_approx_index(uint32_t beginning, uint32_t end, uint32_t value) -{ - int i; - uint32_t k; - uint32_t xvalue; - - k = (end - beginning)/16; - for (xvalue = beginning, i = 0; i < 16; ++i, xvalue += k) { - if (value == xvalue) - return i; - } - //assert(0); - return -1; -} - -static uint32_t vmov_parse_immediate_value() { - uint32_t value; - unsigned long integral_value; - const char *p; - - if (tok != TOK_PPNUM) { - expect("immediate value"); - return 0; - } - p = tokc.str.data; - errno = 0; - integral_value = strtoul(p, (char **)&p, 0); - - if (errno || integral_value >= 32) { - tcc_error("invalid floating-point immediate value"); - return 0; - } - - value = (uint32_t) integral_value * VMOV_ONE; - if (*p == '.') { - ++p; - value += vmov_parse_fractional_part(p); - } - next(); - return value; -} - -static uint8_t vmov_encode_immediate_value(uint32_t value) -{ - uint32_t limit; - uint32_t end = 0; - uint32_t beginning = 0; - int r = -1; - int n; - int i; - - limit = 32 * VMOV_ONE; - for (i = 0; i < 8; ++i) { - if (value < limit) { - end = limit; - limit >>= 1; - beginning = limit; - r = i; - } else - limit >>= 1; - } - if (r == -1 || value < beginning || value > end) { - tcc_error("invalid decimal number for vmov: %d", value); - return 0; - } - n = vmov_linear_approx_index(beginning, end, value); - return n | (((3 - r) & 0x7) << 4); -} - -// Not standalone. -static void asm_floating_point_immediate_data_processing_opcode_tail(TCCState *s1, int token, uint8_t coprocessor, uint8_t CRd) { - uint8_t opcode1 = 0; - uint8_t opcode2 = 0; - uint8_t operands[3] = {0, 0, 0}; - uint32_t immediate_value = 0; - int op_minus = 0; - uint8_t code; - - operands[0] = CRd; - - if (tok == '#' || tok == '$') { - next(); - } - if (tok == '-') { - op_minus = 1; - next(); - } - immediate_value = vmov_parse_immediate_value(); - - opcode1 = 11; // "Other" instruction - switch (ARM_INSTRUCTION_GROUP(token)) { - case TOK_ASM_vcmpeq_f32: - case TOK_ASM_vcmpeq_f64: - opcode2 = 2; - operands[1] = 5; - if (immediate_value) { - expect("Immediate value 0"); - return; - } - break; - case TOK_ASM_vcmpeeq_f32: - case TOK_ASM_vcmpeeq_f64: - opcode2 = 6; - operands[1] = 5; - if (immediate_value) { - expect("Immediate value 0"); - return; - } - break; - case TOK_ASM_vmoveq_f32: - case TOK_ASM_vmoveq_f64: - opcode2 = 0; - if (op_minus) - operands[1] = 0x8; - else - operands[1] = 0x0; - code = vmov_encode_immediate_value(immediate_value); - operands[1] |= code >> 4; - operands[2] = code & 0xF; - break; - default: - expect("known floating point with immediate instruction"); - return; - } - - if (coprocessor == CP_SINGLE_PRECISION_FLOAT) { - if (operands[0] & 1) - opcode1 |= 4; - operands[0] >>= 1; - } - - asm_emit_coprocessor_opcode(condition_code_of_token(token), coprocessor, opcode1, operands[0], operands[1], operands[2], opcode2, 0); -} - -static void asm_floating_point_reg_arm_reg_transfer_opcode_tail(TCCState *s1, int token, int coprocessor, int nb_arm_regs, int nb_ops, Operand ops[3]) { - uint8_t opcode1 = 0; - uint8_t opcode2 = 0; - switch (coprocessor) { - case CP_SINGLE_PRECISION_FLOAT: - // "vmov.f32 r2, s3" or "vmov.f32 s3, r2" - if (nb_ops != 2 || nb_arm_regs != 1) { - tcc_error("vmov.f32 only implemented for one VFP register operand and one ARM register operands"); - return; - } - if (ops[0].type != OP_REG32) { // determine mode: load or store - // need to swap operands 0 and 1 - memcpy(&ops[2], &ops[1], sizeof(ops[2])); - memcpy(&ops[1], &ops[0], sizeof(ops[1])); - memcpy(&ops[0], &ops[2], sizeof(ops[0])); - } else - opcode1 |= 1; - - if (ops[1].type == OP_VREG32) { - if (ops[1].reg & 1) - opcode2 |= 4; - ops[1].reg >>= 1; - } - - if (ops[0].type == OP_VREG32) { - if (ops[0].reg & 1) - opcode1 |= 4; - ops[0].reg >>= 1; - } - - asm_emit_coprocessor_opcode(condition_code_of_token(token), coprocessor, opcode1, ops[0].reg, (ops[1].type == OP_IM8) ? ops[1].e.v : ops[1].reg, 0x10, opcode2, 0); - break; - case CP_DOUBLE_PRECISION_FLOAT: - if (nb_ops != 3 || nb_arm_regs != 2) { - tcc_error("vmov.f32 only implemented for one VFP register operand and two ARM register operands"); - return; - } - // Determine whether it's a store into a VFP register (vmov "d1, r2, r3") rather than "vmov r2, r3, d1" - if (ops[0].type == OP_VREG64) { - if (ops[2].type == OP_REG32) { - Operand temp; - // need to rotate operand list to the left - memcpy(&temp, &ops[0], sizeof(temp)); - memcpy(&ops[0], &ops[1], sizeof(ops[0])); - memcpy(&ops[1], &ops[2], sizeof(ops[1])); - memcpy(&ops[2], &temp, sizeof(ops[2])); - } else { - tcc_error("vmov.f64 only implemented for one VFP register operand and two ARM register operands"); - return; - } - } else if (ops[0].type != OP_REG32 || ops[1].type != OP_REG32 || ops[2].type != OP_VREG64) { - tcc_error("vmov.f64 only implemented for one VFP register operand and two ARM register operands"); - return; - } else { - opcode1 |= 1; - } - asm_emit_coprocessor_data_transfer(condition_code_of_token(token), coprocessor, ops[0].reg, &ops[1], &ops[2], 0, 0, 0, 1, opcode1); - break; - default: - tcc_internal_error("unknown coprocessor"); - } -} - -static void asm_floating_point_vcvt_data_processing_opcode(TCCState *s1, int token) { - uint8_t coprocessor = 0; - Operand ops[3]; - uint8_t opcode1 = 11; - uint8_t opcode2 = 2; - - switch (ARM_INSTRUCTION_GROUP(token)) { - case TOK_ASM_vcvtreq_s32_f64: - case TOK_ASM_vcvtreq_u32_f64: - case TOK_ASM_vcvteq_s32_f64: - case TOK_ASM_vcvteq_u32_f64: - case TOK_ASM_vcvteq_f64_s32: - case TOK_ASM_vcvteq_f64_u32: - case TOK_ASM_vcvteq_f32_f64: - coprocessor = CP_DOUBLE_PRECISION_FLOAT; - break; - case TOK_ASM_vcvtreq_s32_f32: - case TOK_ASM_vcvtreq_u32_f32: - case TOK_ASM_vcvteq_s32_f32: - case TOK_ASM_vcvteq_u32_f32: - case TOK_ASM_vcvteq_f32_s32: - case TOK_ASM_vcvteq_f32_u32: - case TOK_ASM_vcvteq_f64_f32: - coprocessor = CP_SINGLE_PRECISION_FLOAT; - break; - default: - tcc_error("Unknown coprocessor for instruction '%s'", get_tok_str(token, NULL)); - return; - } - - parse_operand(s1, &ops[0]); - ops[1].type = OP_IM8; - ops[1].e.v = 8; - /* floating-point -> integer */ - switch (ARM_INSTRUCTION_GROUP(token)) { - case TOK_ASM_vcvtreq_s32_f32: - case TOK_ASM_vcvtreq_s32_f64: - case TOK_ASM_vcvteq_s32_f32: - case TOK_ASM_vcvteq_s32_f64: - ops[1].e.v |= 1; // signed - /* fall through */ - case TOK_ASM_vcvteq_u32_f32: - case TOK_ASM_vcvteq_u32_f64: - case TOK_ASM_vcvtreq_u32_f32: - case TOK_ASM_vcvtreq_u32_f64: - ops[1].e.v |= 4; // to_integer (opc2) - break; - /* floating-point size conversion */ - case TOK_ASM_vcvteq_f64_f32: - case TOK_ASM_vcvteq_f32_f64: - ops[1].e.v = 7; - break; - } - - if (tok == ',') - next(); - else - expect("','"); - parse_operand(s1, &ops[2]); - - switch (ARM_INSTRUCTION_GROUP(token)) { - /* floating-point -> integer */ - case TOK_ASM_vcvteq_s32_f32: - case TOK_ASM_vcvteq_s32_f64: - case TOK_ASM_vcvteq_u32_f32: - case TOK_ASM_vcvteq_u32_f64: - opcode2 |= 4; // round_zero - break; - - /* integer -> floating-point */ - case TOK_ASM_vcvteq_f64_s32: - case TOK_ASM_vcvteq_f32_s32: - opcode2 |= 4; // signed--special - break; - - /* floating-point size conversion */ - case TOK_ASM_vcvteq_f64_f32: - case TOK_ASM_vcvteq_f32_f64: - opcode2 |= 4; // always set - break; - } - - switch (ARM_INSTRUCTION_GROUP(token)) { - case TOK_ASM_vcvteq_f64_u32: - case TOK_ASM_vcvteq_f64_s32: - case TOK_ASM_vcvteq_f64_f32: - if (ops[0].type == OP_VREG64 && ops[2].type == OP_VREG32) { - } else { - expect("d, s"); - return; - } - break; - default: - if (coprocessor == CP_SINGLE_PRECISION_FLOAT) { - if (ops[0].type == OP_VREG32 && ops[2].type == OP_VREG32) { - } else { - expect("s, s"); - return; - } - } else if (coprocessor == CP_DOUBLE_PRECISION_FLOAT) { - if (ops[0].type == OP_VREG32 && ops[2].type == OP_VREG64) { - } else { - expect("s, d"); - return; - } - } - } - - if (ops[2].type == OP_VREG32) { - if (ops[2].reg & 1) - opcode2 |= 1; - ops[2].reg >>= 1; - } - if (ops[0].type == OP_VREG32) { - if (ops[0].reg & 1) - opcode1 |= 4; - ops[0].reg >>= 1; - } - asm_emit_coprocessor_opcode(condition_code_of_token(token), coprocessor, opcode1, ops[0].reg, (ops[1].type == OP_IM8) ? ops[1].e.v : ops[1].reg, (ops[2].type == OP_IM8) ? ops[2].e.v : ops[2].reg, opcode2, 0); -} - -static void asm_floating_point_data_processing_opcode(TCCState *s1, int token) { - uint8_t coprocessor = CP_SINGLE_PRECISION_FLOAT; - uint8_t opcode1 = 0; - uint8_t opcode2 = 0; // (0 || 2) | register selection - Operand ops[3]; - uint8_t nb_ops = 0; - int vmov = 0; - int nb_arm_regs = 0; - -/* TODO: - Instruction opcode opcode2 Reason - ============================================================= - - 1?00 ?1? Undefined - VFNMS 1?01 ?0? Must be unconditional - VFNMA 1?01 ?1? Must be unconditional - VFMA 1?10 ?0? Must be unconditional - VFMS 1?10 ?1? Must be unconditional - - VMOV Fd, Fm - VMOV Sn, Sm, Rd, Rn - VMOV Rd, Rn, Sn, Sm - VMOV Dn[0], Rd - VMOV Rd, Dn[0] - VMOV Dn[1], Rd - VMOV Rd, Dn[1] -*/ - - switch (ARM_INSTRUCTION_GROUP(token)) { - case TOK_ASM_vmlaeq_f64: - case TOK_ASM_vmlseq_f64: - case TOK_ASM_vnmlseq_f64: - case TOK_ASM_vnmlaeq_f64: - case TOK_ASM_vmuleq_f64: - case TOK_ASM_vnmuleq_f64: - case TOK_ASM_vaddeq_f64: - case TOK_ASM_vsubeq_f64: - case TOK_ASM_vdiveq_f64: - case TOK_ASM_vnegeq_f64: - case TOK_ASM_vabseq_f64: - case TOK_ASM_vsqrteq_f64: - case TOK_ASM_vcmpeq_f64: - case TOK_ASM_vcmpeeq_f64: - case TOK_ASM_vmoveq_f64: - coprocessor = CP_DOUBLE_PRECISION_FLOAT; - } - - switch (ARM_INSTRUCTION_GROUP(token)) { - case TOK_ASM_vmoveq_f32: - case TOK_ASM_vmoveq_f64: - vmov = 1; - break; - } - - for (nb_ops = 0; nb_ops < 3; ) { - // Note: Necessary because parse_operand can't parse decimal numerals. - if (nb_ops == 1 && (tok == '#' || tok == '$' || tok == TOK_PPNUM || tok == '-')) { - asm_floating_point_immediate_data_processing_opcode_tail(s1, token, coprocessor, ops[0].reg); - return; - } - parse_operand(s1, &ops[nb_ops]); - if (vmov && ops[nb_ops].type == OP_REG32) { - ++nb_arm_regs; - } else if (ops[nb_ops].type == OP_VREG32) { - if (coprocessor != CP_SINGLE_PRECISION_FLOAT) { - expect("'s'"); - return; - } - } else if (ops[nb_ops].type == OP_VREG64) { - if (coprocessor != CP_DOUBLE_PRECISION_FLOAT) { - expect("'d'"); - return; - } - } else { - expect("floating point register"); - return; - } - ++nb_ops; - if (tok == ',') - next(); - else - break; - } - - if (nb_arm_regs == 0) { - if (nb_ops == 2) { // implicit - memcpy(&ops[2], &ops[1], sizeof(ops[1])); // move ops[2] - memcpy(&ops[1], &ops[0], sizeof(ops[0])); // ops[1] was implicit - nb_ops = 3; - } - if (nb_ops < 3) { - tcc_error("Not enough operands for '%s' (%u)", get_tok_str(token, NULL), nb_ops); - return; - } - } - - switch (ARM_INSTRUCTION_GROUP(token)) { - case TOK_ASM_vmlaeq_f32: - case TOK_ASM_vmlaeq_f64: - opcode1 = 0; - opcode2 = 0; - break; - case TOK_ASM_vmlseq_f32: - case TOK_ASM_vmlseq_f64: - opcode1 = 0; - opcode2 = 2; - break; - case TOK_ASM_vnmlseq_f32: - case TOK_ASM_vnmlseq_f64: - opcode1 = 1; - opcode2 = 0; - break; - case TOK_ASM_vnmlaeq_f32: - case TOK_ASM_vnmlaeq_f64: - opcode1 = 1; - opcode2 = 2; - break; - case TOK_ASM_vmuleq_f32: - case TOK_ASM_vmuleq_f64: - opcode1 = 2; - opcode2 = 0; - break; - case TOK_ASM_vnmuleq_f32: - case TOK_ASM_vnmuleq_f64: - opcode1 = 2; - opcode2 = 2; - break; - case TOK_ASM_vaddeq_f32: - case TOK_ASM_vaddeq_f64: - opcode1 = 3; - opcode2 = 0; - break; - case TOK_ASM_vsubeq_f32: - case TOK_ASM_vsubeq_f64: - opcode1 = 3; - opcode2 = 2; - break; - case TOK_ASM_vdiveq_f32: - case TOK_ASM_vdiveq_f64: - opcode1 = 8; - opcode2 = 0; - break; - case TOK_ASM_vnegeq_f32: - case TOK_ASM_vnegeq_f64: - opcode1 = 11; // Other" instruction - opcode2 = 2; - ops[1].type = OP_IM8; - ops[1].e.v = 1; - break; - case TOK_ASM_vabseq_f32: - case TOK_ASM_vabseq_f64: - opcode1 = 11; // "Other" instruction - opcode2 = 6; - ops[1].type = OP_IM8; - ops[1].e.v = 0; - break; - case TOK_ASM_vsqrteq_f32: - case TOK_ASM_vsqrteq_f64: - opcode1 = 11; // "Other" instruction - opcode2 = 6; - ops[1].type = OP_IM8; - ops[1].e.v = 1; - break; - case TOK_ASM_vcmpeq_f32: - case TOK_ASM_vcmpeq_f64: - opcode1 = 11; // "Other" instruction - opcode2 = 2; - ops[1].type = OP_IM8; - ops[1].e.v = 4; - break; - case TOK_ASM_vcmpeeq_f32: - case TOK_ASM_vcmpeeq_f64: - opcode1 = 11; // "Other" instruction - opcode2 = 6; - ops[1].type = OP_IM8; - ops[1].e.v = 4; - break; - case TOK_ASM_vmoveq_f32: - case TOK_ASM_vmoveq_f64: - if (nb_arm_regs > 0) { // vmov.f32 r2, s3 or similar - asm_floating_point_reg_arm_reg_transfer_opcode_tail(s1, token, coprocessor, nb_arm_regs, nb_ops, ops); - return; - } else { - opcode1 = 11; // "Other" instruction - opcode2 = 2; - ops[1].type = OP_IM8; - ops[1].e.v = 0; - } - break; - default: - expect("known floating point instruction"); - return; - } - - if (coprocessor == CP_SINGLE_PRECISION_FLOAT) { - if (ops[2].type == OP_VREG32) { - if (ops[2].reg & 1) - opcode2 |= 1; - ops[2].reg >>= 1; - } - - if (ops[1].type == OP_VREG32) { - if (ops[1].reg & 1) - opcode2 |= 4; - ops[1].reg >>= 1; - } - - if (ops[0].type == OP_VREG32) { - if (ops[0].reg & 1) - opcode1 |= 4; - ops[0].reg >>= 1; - } - } - - asm_emit_coprocessor_opcode(condition_code_of_token(token), coprocessor, opcode1, ops[0].reg, (ops[1].type == OP_IM8) ? ops[1].e.v : ops[1].reg, (ops[2].type == OP_IM8) ? ops[2].e.v : ops[2].reg, opcode2, 0); -} - -static int asm_parse_vfp_status_regvar(int t) -{ - switch (t) { - case TOK_ASM_fpsid: - return 0; - case TOK_ASM_fpscr: - return 1; - case TOK_ASM_fpexc: - return 8; - default: - return -1; - } -} - -static void asm_floating_point_status_register_opcode(TCCState* s1, int token) -{ - uint8_t coprocessor = CP_SINGLE_PRECISION_FLOAT; - uint8_t opcode; - int vfp_sys_reg = -1; - Operand arm_operand; - switch (ARM_INSTRUCTION_GROUP(token)) { - case TOK_ASM_vmrseq: - opcode = 0xf; - if (tok == TOK_ASM_apsr_nzcv) { - arm_operand.type = OP_REG32; - arm_operand.reg = 15; // not PC - next(); // skip apsr_nzcv - } else { - parse_operand(s1, &arm_operand); - if (arm_operand.type == OP_REG32 && arm_operand.reg == 15) { - tcc_error("'%s' does not support 'pc' as operand", get_tok_str(token, NULL)); - return; - } - } - - if (tok != ',') - expect("','"); - else - next(); // skip ',' - vfp_sys_reg = asm_parse_vfp_status_regvar(tok); - next(); // skip vfp sys reg - if (arm_operand.type == OP_REG32 && arm_operand.reg == 15 && vfp_sys_reg != 1) { - tcc_error("'%s' only supports the variant 'vmrs apsr_nzcv, fpscr' here", get_tok_str(token, NULL)); - return; - } - break; - case TOK_ASM_vmsreq: - opcode = 0xe; - vfp_sys_reg = asm_parse_vfp_status_regvar(tok); - next(); // skip vfp sys reg - if (tok != ',') - expect("','"); - else - next(); // skip ',' - parse_operand(s1, &arm_operand); - if (arm_operand.type == OP_REG32 && arm_operand.reg == 15) { - tcc_error("'%s' does not support 'pc' as operand", get_tok_str(token, NULL)); - return; - } - break; - default: - expect("floating point status register instruction"); - return; - } - if (vfp_sys_reg == -1) { - expect("VFP system register"); - return; - } - if (arm_operand.type != OP_REG32) { - expect("ARM register"); - return; - } - asm_emit_coprocessor_opcode(condition_code_of_token(token), coprocessor, opcode, arm_operand.reg, vfp_sys_reg, 0x10, 0, 0); -} - -#endif - -static void asm_misc_single_data_transfer_opcode(TCCState *s1, int token) -{ - Operand ops[3]; - int exclam = 0; - int closed_bracket = 0; - int op2_minus = 0; - uint32_t opcode = (1 << 7) | (1 << 4); - - /* Note: - The argument syntax is exactly the same as in arm_single_data_transfer_opcode, except that there's no STREX argument form. - The main difference between this function and asm_misc_single_data_transfer_opcode is that the immediate values here must be smaller. - Also, the combination (P=0, W=1) is unpredictable here. - The immediate flag has moved to bit index 22--and its meaning has flipped. - The immediate value itself has been split into two parts: one at bits 11...8, one at bits 3...0 - bit 26 (Load/Store instruction) is unset here. - bits 7 and 4 are set here. */ - - // Here: 0 0 0 P U I W L << 20 - // [compare single data transfer: 0 1 I P U B W L << 20] - - parse_operand(s1, &ops[0]); - if (ops[0].type == OP_REG32) - opcode |= ENCODE_RD(ops[0].reg); - else { - expect("(destination operand) register"); - return; - } - if (tok != ',') - expect("at least two arguments"); - else - next(); // skip ',' - - if (tok != '[') - expect("'['"); - else - next(); // skip '[' - - parse_operand(s1, &ops[1]); - if (ops[1].type == OP_REG32) - opcode |= ENCODE_RN(ops[1].reg); - else { - expect("(first source operand) register"); - return; - } - if (tok == ']') { - next(); - closed_bracket = 1; - // exclam = 1; // implicit in hardware; don't do it in software - } - if (tok == ',') { - next(); // skip ',' - if (tok == '-') { - op2_minus = 1; - next(); - } - parse_operand(s1, &ops[2]); - } else { - // end of input expression in brackets--assume 0 offset - ops[2].type = OP_IM8; - ops[2].e.v = 0; - opcode |= 1 << 24; // add offset before transfer - } - if (!closed_bracket) { - if (tok != ']') - expect("']'"); - else - next(); // skip ']' - opcode |= 1 << 24; // add offset before transfer - if (tok == '!') { - exclam = 1; - next(); // skip '!' - } - } - - if (exclam) { - if ((opcode & (1 << 24)) == 0) { - tcc_error("result of '%s' would be unpredictable here", get_tok_str(token, NULL)); - return; - } - opcode |= 1 << 21; // write offset back into register - } - - if (ops[2].type == OP_IM32 || ops[2].type == OP_IM8 || ops[2].type == OP_IM8N) { - int v = ops[2].e.v; - if (op2_minus) - tcc_error("minus before '#' not supported for immediate values"); - if (v >= 0) { - opcode |= 1 << 23; // up - if (v >= 0x100) - tcc_error("offset out of range for '%s'", get_tok_str(token, NULL)); - else { - // bits 11...8: immediate hi nibble - // bits 3...0: immediate lo nibble - opcode |= (v & 0xF0) << 4; - opcode |= v & 0xF; - } - } else { // down - if (v <= -0x100) - tcc_error("offset out of range for '%s'", get_tok_str(token, NULL)); - else { - v = -v; - // bits 11...8: immediate hi nibble - // bits 3...0: immediate lo nibble - opcode |= (v & 0xF0) << 4; - opcode |= v & 0xF; - } - } - opcode |= 1 << 22; // not ENCODE_IMMEDIATE_FLAG; - } else if (ops[2].type == OP_REG32) { - if (!op2_minus) - opcode |= 1 << 23; // up - opcode |= ops[2].reg; - } else - expect("register"); - - switch (ARM_INSTRUCTION_GROUP(token)) { - case TOK_ASM_ldrsheq: - opcode |= 1 << 5; // halfword, not byte - /* fallthrough */ - case TOK_ASM_ldrsbeq: - opcode |= 1 << 6; // sign extend - opcode |= 1 << 20; // L - asm_emit_opcode(token, opcode); - break; - case TOK_ASM_ldrheq: - opcode |= 1 << 5; // halfword, not byte - opcode |= 1 << 20; // L - asm_emit_opcode(token, opcode); - break; - case TOK_ASM_strheq: - opcode |= 1 << 5; // halfword, not byte - asm_emit_opcode(token, opcode); - break; - } -} - -/* Note: almost dupe of encbranch in arm-gen.c */ -static uint32_t encbranchoffset(int pos, int addr, int fail) -{ - addr-=pos+8; - addr/=4; - if(addr>=0x7fffff || addr<-0x800000) { - if(fail) - tcc_error("branch offset is too far"); - return 0; - } - return /*not 0x0A000000|*/(addr&0xffffff); -} - -static void asm_branch_opcode(TCCState *s1, int token) -{ - int jmp_disp = 0; - Operand op; - ExprValue e; - ElfSym *esym; - - switch (ARM_INSTRUCTION_GROUP(token)) { - case TOK_ASM_beq: - case TOK_ASM_bleq: - asm_expr(s1, &e); - esym = elfsym(e.sym); - if (!esym || esym->st_shndx != cur_text_section->sh_num) { - tcc_error("invalid branch target"); - return; - } - jmp_disp = encbranchoffset(ind, e.v + esym->st_value, 1); - break; - default: - parse_operand(s1, &op); - break; - } - switch (ARM_INSTRUCTION_GROUP(token)) { - case TOK_ASM_beq: - asm_emit_opcode(token, (0xa << 24) | (jmp_disp & 0xffffff)); - break; - case TOK_ASM_bleq: - asm_emit_opcode(token, (0xb << 24) | (jmp_disp & 0xffffff)); - break; - case TOK_ASM_bxeq: - if (op.type != OP_REG32) - expect("register"); - else - asm_emit_opcode(token, (0x12fff1 << 4) | op.reg); - break; - case TOK_ASM_blxeq: - if (op.type != OP_REG32) - expect("register"); - else - asm_emit_opcode(token, (0x12fff3 << 4) | op.reg); - break; - default: - expect("branch instruction"); - } -} - -ST_FUNC void asm_opcode(TCCState *s1, int token) -{ - while (token == TOK_LINEFEED) { - next(); - token = tok; - } - if (token == TOK_EOF) - return; - if (token < TOK_ASM_nopeq) { // no condition code - switch (token) { - case TOK_ASM_cdp2: - asm_coprocessor_opcode(s1, token); - return; - case TOK_ASM_ldc2: - case TOK_ASM_ldc2l: - case TOK_ASM_stc2: - case TOK_ASM_stc2l: - asm_coprocessor_data_transfer_opcode(s1, token); - return; - default: - expect("instruction"); - return; - } - } - - switch (ARM_INSTRUCTION_GROUP(token)) { - case TOK_ASM_pusheq: - case TOK_ASM_popeq: - case TOK_ASM_stmdaeq: - case TOK_ASM_ldmdaeq: - case TOK_ASM_stmeq: - case TOK_ASM_ldmeq: - case TOK_ASM_stmiaeq: - case TOK_ASM_ldmiaeq: - case TOK_ASM_stmdbeq: - case TOK_ASM_ldmdbeq: - case TOK_ASM_stmibeq: - case TOK_ASM_ldmibeq: - asm_block_data_transfer_opcode(s1, token); - return; - case TOK_ASM_nopeq: - case TOK_ASM_wfeeq: - case TOK_ASM_wfieq: - asm_nullary_opcode(token); - return; - case TOK_ASM_swieq: - case TOK_ASM_svceq: - asm_unary_opcode(s1, token); - return; - case TOK_ASM_beq: - case TOK_ASM_bleq: - case TOK_ASM_bxeq: - case TOK_ASM_blxeq: - asm_branch_opcode(s1, token); - return; - case TOK_ASM_clzeq: - case TOK_ASM_sxtbeq: - case TOK_ASM_sxtheq: - case TOK_ASM_uxtbeq: - case TOK_ASM_uxtheq: - case TOK_ASM_movteq: - case TOK_ASM_movweq: - asm_binary_opcode(s1, token); - return; - - case TOK_ASM_ldreq: - case TOK_ASM_ldrbeq: - case TOK_ASM_streq: - case TOK_ASM_strbeq: - case TOK_ASM_ldrexeq: - case TOK_ASM_ldrexbeq: - case TOK_ASM_strexeq: - case TOK_ASM_strexbeq: - asm_single_data_transfer_opcode(s1, token); - return; - - case TOK_ASM_ldrheq: - case TOK_ASM_ldrsheq: - case TOK_ASM_ldrsbeq: - case TOK_ASM_strheq: - asm_misc_single_data_transfer_opcode(s1, token); - return; - - case TOK_ASM_andeq: - case TOK_ASM_eoreq: - case TOK_ASM_subeq: - case TOK_ASM_rsbeq: - case TOK_ASM_addeq: - case TOK_ASM_adceq: - case TOK_ASM_sbceq: - case TOK_ASM_rsceq: - case TOK_ASM_tsteq: - case TOK_ASM_teqeq: - case TOK_ASM_cmpeq: - case TOK_ASM_cmneq: - case TOK_ASM_orreq: - case TOK_ASM_moveq: - case TOK_ASM_biceq: - case TOK_ASM_mvneq: - case TOK_ASM_andseq: - case TOK_ASM_eorseq: - case TOK_ASM_subseq: - case TOK_ASM_rsbseq: - case TOK_ASM_addseq: - case TOK_ASM_adcseq: - case TOK_ASM_sbcseq: - case TOK_ASM_rscseq: -// case TOK_ASM_tstseq: -// case TOK_ASM_teqseq: -// case TOK_ASM_cmpseq: -// case TOK_ASM_cmnseq: - case TOK_ASM_orrseq: - case TOK_ASM_movseq: - case TOK_ASM_bicseq: - case TOK_ASM_mvnseq: - asm_data_processing_opcode(s1, token); - return; - - case TOK_ASM_lsleq: - case TOK_ASM_lslseq: - case TOK_ASM_lsreq: - case TOK_ASM_lsrseq: - case TOK_ASM_asreq: - case TOK_ASM_asrseq: - case TOK_ASM_roreq: - case TOK_ASM_rorseq: - case TOK_ASM_rrxseq: - case TOK_ASM_rrxeq: - asm_shift_opcode(s1, token); - return; - - case TOK_ASM_muleq: - case TOK_ASM_mulseq: - case TOK_ASM_mlaeq: - case TOK_ASM_mlaseq: - asm_multiplication_opcode(s1, token); - return; - - case TOK_ASM_smulleq: - case TOK_ASM_smullseq: - case TOK_ASM_umulleq: - case TOK_ASM_umullseq: - case TOK_ASM_smlaleq: - case TOK_ASM_smlalseq: - case TOK_ASM_umlaleq: - case TOK_ASM_umlalseq: - asm_long_multiplication_opcode(s1, token); - return; - - case TOK_ASM_cdpeq: - case TOK_ASM_mcreq: - case TOK_ASM_mrceq: - asm_coprocessor_opcode(s1, token); - return; - - case TOK_ASM_ldceq: - case TOK_ASM_ldcleq: - case TOK_ASM_stceq: - case TOK_ASM_stcleq: - asm_coprocessor_data_transfer_opcode(s1, token); - return; - -#if defined(TCC_ARM_VFP) - case TOK_ASM_vldreq: - case TOK_ASM_vstreq: - asm_floating_point_single_data_transfer_opcode(s1, token); - return; - - case TOK_ASM_vmlaeq_f32: - case TOK_ASM_vmlseq_f32: - case TOK_ASM_vnmlseq_f32: - case TOK_ASM_vnmlaeq_f32: - case TOK_ASM_vmuleq_f32: - case TOK_ASM_vnmuleq_f32: - case TOK_ASM_vaddeq_f32: - case TOK_ASM_vsubeq_f32: - case TOK_ASM_vdiveq_f32: - case TOK_ASM_vnegeq_f32: - case TOK_ASM_vabseq_f32: - case TOK_ASM_vsqrteq_f32: - case TOK_ASM_vcmpeq_f32: - case TOK_ASM_vcmpeeq_f32: - case TOK_ASM_vmoveq_f32: - case TOK_ASM_vmlaeq_f64: - case TOK_ASM_vmlseq_f64: - case TOK_ASM_vnmlseq_f64: - case TOK_ASM_vnmlaeq_f64: - case TOK_ASM_vmuleq_f64: - case TOK_ASM_vnmuleq_f64: - case TOK_ASM_vaddeq_f64: - case TOK_ASM_vsubeq_f64: - case TOK_ASM_vdiveq_f64: - case TOK_ASM_vnegeq_f64: - case TOK_ASM_vabseq_f64: - case TOK_ASM_vsqrteq_f64: - case TOK_ASM_vcmpeq_f64: - case TOK_ASM_vcmpeeq_f64: - case TOK_ASM_vmoveq_f64: - asm_floating_point_data_processing_opcode(s1, token); - return; - - case TOK_ASM_vcvtreq_s32_f32: - case TOK_ASM_vcvtreq_s32_f64: - case TOK_ASM_vcvteq_s32_f32: - case TOK_ASM_vcvteq_s32_f64: - case TOK_ASM_vcvtreq_u32_f32: - case TOK_ASM_vcvtreq_u32_f64: - case TOK_ASM_vcvteq_u32_f32: - case TOK_ASM_vcvteq_u32_f64: - case TOK_ASM_vcvteq_f64_s32: - case TOK_ASM_vcvteq_f32_s32: - case TOK_ASM_vcvteq_f64_u32: - case TOK_ASM_vcvteq_f32_u32: - case TOK_ASM_vcvteq_f64_f32: - case TOK_ASM_vcvteq_f32_f64: - asm_floating_point_vcvt_data_processing_opcode(s1, token); - return; - - case TOK_ASM_vpusheq: - case TOK_ASM_vpopeq: - case TOK_ASM_vldmeq: - case TOK_ASM_vldmiaeq: - case TOK_ASM_vldmdbeq: - case TOK_ASM_vstmeq: - case TOK_ASM_vstmiaeq: - case TOK_ASM_vstmdbeq: - asm_floating_point_block_data_transfer_opcode(s1, token); - return; - - case TOK_ASM_vmsreq: - case TOK_ASM_vmrseq: - asm_floating_point_status_register_opcode(s1, token); - return; -#endif - - default: - expect("known instruction"); - } -} - -ST_FUNC void subst_asm_operand(CString *add_str, SValue *sv, int modifier) -{ - int r, reg, size, val; - char buf[64]; - - r = sv->r; - if ((r & VT_VALMASK) == VT_CONST) { - if (!(r & VT_LVAL) && modifier != 'c' && modifier != 'n' && - modifier != 'P') - cstr_ccat(add_str, '#'); - if (r & VT_SYM) { - const char *name = get_tok_str(sv->sym->v, NULL); - if (sv->sym->v >= SYM_FIRST_ANOM) { - /* In case of anonymous symbols ("L.42", used - for static data labels) we can't find them - in the C symbol table when later looking up - this name. So enter them now into the asm label - list when we still know the symbol. */ - get_asm_sym(tok_alloc(name, strlen(name))->tok, sv->sym); - } - if (tcc_state->leading_underscore) - cstr_ccat(add_str, '_'); - cstr_cat(add_str, name, -1); - if ((uint32_t) sv->c.i == 0) - goto no_offset; - cstr_ccat(add_str, '+'); - } - val = sv->c.i; - if (modifier == 'n') - val = -val; - snprintf(buf, sizeof(buf), "%d", (int) sv->c.i); - cstr_cat(add_str, buf, -1); - no_offset:; - } else if ((r & VT_VALMASK) == VT_LOCAL) { - snprintf(buf, sizeof(buf), "[fp,#%d]", (int) sv->c.i); - cstr_cat(add_str, buf, -1); - } else if (r & VT_LVAL) { - reg = r & VT_VALMASK; - if (reg >= VT_CONST) - tcc_internal_error(""); - snprintf(buf, sizeof(buf), "[%s]", - get_tok_str(TOK_ASM_r0 + reg, NULL)); - cstr_cat(add_str, buf, -1); - } else { - /* register case */ - reg = r & VT_VALMASK; - if (reg >= VT_CONST) - tcc_internal_error(""); - - /* choose register operand size */ - if ((sv->type.t & VT_BTYPE) == VT_BYTE || - (sv->type.t & VT_BTYPE) == VT_BOOL) - size = 1; - else if ((sv->type.t & VT_BTYPE) == VT_SHORT) - size = 2; - else - size = 4; - - if (modifier == 'b') { - size = 1; - } else if (modifier == 'w') { - size = 2; - } else if (modifier == 'k') { - size = 4; - } - - switch (size) { - default: - reg = TOK_ASM_r0 + reg; - break; - } - snprintf(buf, sizeof(buf), "%s", get_tok_str(reg, NULL)); - cstr_cat(add_str, buf, -1); - } -} - -/* generate prolog and epilog code for asm statement */ -ST_FUNC void asm_gen_code(ASMOperand *operands, int nb_operands, - int nb_outputs, int is_output, - uint8_t *clobber_regs, - int out_reg) -{ - uint8_t regs_allocated[NB_ASM_REGS]; - ASMOperand *op; - int i, reg; - uint32_t saved_regset = 0; - - // TODO: Check non-E ABI. - // Note: Technically, r13 (sp) is also callee-saved--but that does not matter yet - static const uint8_t reg_saved[] = { 4, 5, 6, 7, 8, 9 /* Note: sometimes special reg "sb" */ , 10, 11 }; - - /* mark all used registers */ - memcpy(regs_allocated, clobber_regs, sizeof(regs_allocated)); - for(i = 0; i < nb_operands;i++) { - op = &operands[i]; - if (op->reg >= 0) - regs_allocated[op->reg] = 1; - } - for(i = 0; i < sizeof(reg_saved)/sizeof(reg_saved[0]); i++) { - reg = reg_saved[i]; - if (regs_allocated[reg]) - saved_regset |= 1 << reg; - } - - if (!is_output) { // prolog - /* generate reg save code */ - if (saved_regset) - gen_le32(0xe92d0000 | saved_regset); // push {...} - - /* generate load code */ - for(i = 0; i < nb_operands; i++) { - op = &operands[i]; - if (op->reg >= 0) { - if ((op->vt->r & VT_VALMASK) == VT_LLOCAL && - op->is_memory) { - /* memory reference case (for both input and - output cases) */ - SValue sv; - sv = *op->vt; - sv.r = (sv.r & ~VT_VALMASK) | VT_LOCAL | VT_LVAL; - sv.type.t = VT_PTR; - load(op->reg, &sv); - } else if (i >= nb_outputs || op->is_rw) { // not write-only - /* load value in register */ - load(op->reg, op->vt); - if (op->is_llong) - tcc_error("long long not implemented"); - } - } - } - } else { // epilog - /* generate save code */ - for(i = 0 ; i < nb_outputs; i++) { - op = &operands[i]; - if (op->reg >= 0) { - if ((op->vt->r & VT_VALMASK) == VT_LLOCAL) { - if (!op->is_memory) { - SValue sv; - sv = *op->vt; - sv.r = (sv.r & ~VT_VALMASK) | VT_LOCAL; - sv.type.t = VT_PTR; - load(out_reg, &sv); - - sv = *op->vt; - sv.r = (sv.r & ~VT_VALMASK) | out_reg; - store(op->reg, &sv); - } - } else { - store(op->reg, op->vt); - if (op->is_llong) - tcc_error("long long not implemented"); - } - } - } - - /* generate reg restore code */ - if (saved_regset) - gen_le32(0xe8bd0000 | saved_regset); // pop {...} - } -} - -/* return the constraint priority (we allocate first the lowest - numbered constraints) */ -static inline int constraint_priority(const char *str) -{ - int priority, c, pr; - - /* we take the lowest priority */ - priority = 0; - for(;;) { - c = *str; - if (c == '\0') - break; - str++; - switch(c) { - case 'l': // in ARM mode, that's an alias for 'r' [ARM]. - case 'r': // register [general] - case 'p': // valid memory address for load,store [general] - pr = 3; - break; - case 'M': // integer constant for shifts [ARM] - case 'I': // integer valid for data processing instruction immediate - case 'J': // integer in range -4095...4095 - - case 'i': // immediate integer operand, including symbolic constants [general] - case 'm': // memory operand [general] - case 'g': // general-purpose-register, memory, immediate integer [general] - pr = 4; - break; - default: - tcc_error("unknown constraint '%c'", c); - pr = 0; - } - if (pr > priority) - priority = pr; - } - return priority; -} - -static const char *skip_constraint_modifiers(const char *p) -{ - /* Constraint modifier: - = Operand is written to by this instruction - + Operand is both read and written to by this instruction - % Instruction is commutative for this operand and the following operand. - - Per-alternative constraint modifier: - & Operand is clobbered before the instruction is done using the input operands - */ - while (*p == '=' || *p == '&' || *p == '+' || *p == '%') - p++; - return p; -} - -#define REG_OUT_MASK 0x01 -#define REG_IN_MASK 0x02 - -#define is_reg_allocated(reg) (regs_allocated[reg] & reg_mask) - -ST_FUNC void asm_compute_constraints(ASMOperand *operands, - int nb_operands, int nb_outputs, - const uint8_t *clobber_regs, - int *pout_reg) -{ - /* overall format: modifier, then ,-seperated list of alternatives; all operands for a single instruction must have the same number of alternatives */ - /* TODO: Simple constraints - whitespace ignored - o memory operand that is offsetable - V memory but not offsetable - < memory operand with autodecrement addressing is allowed. Restrictions apply. - > memory operand with autoincrement addressing is allowed. Restrictions apply. - n immediate integer operand with a known numeric value - E immediate floating operand (const_double) is allowed, but only if target=host - F immediate floating operand (const_double or const_vector) is allowed - s immediate integer operand whose value is not an explicit integer - X any operand whatsoever - 0...9 (postfix); (can also be more than 1 digit number); an operand that matches the specified operand number is allowed - */ - - /* TODO: ARM constraints: - k the stack pointer register - G the floating-point constant 0.0 - Q memory reference where the exact address is in a single register ("m" is preferable for asm statements) - R an item in the constant pool - S symbol in the text segment of the current file -[ Uv memory reference suitable for VFP load/store insns (reg+constant offset)] -[ Uy memory reference suitable for iWMMXt load/store instructions] - Uq memory reference suitable for the ARMv4 ldrsb instruction - */ - ASMOperand *op; - int sorted_op[MAX_ASM_OPERANDS]; - int i, j, k, p1, p2, tmp, reg, c, reg_mask; - const char *str; - uint8_t regs_allocated[NB_ASM_REGS]; - - /* init fields */ - for (i = 0; i < nb_operands; i++) { - op = &operands[i]; - op->input_index = -1; - op->ref_index = -1; - op->reg = -1; - op->is_memory = 0; - op->is_rw = 0; - } - /* compute constraint priority and evaluate references to output - constraints if input constraints */ - for (i = 0; i < nb_operands; i++) { - op = &operands[i]; - str = op->constraint; - str = skip_constraint_modifiers(str); - if (isnum(*str) || *str == '[') { - /* this is a reference to another constraint */ - k = find_constraint(operands, nb_operands, str, NULL); - if ((unsigned) k >= i || i < nb_outputs) - tcc_error("invalid reference in constraint %d ('%s')", - i, str); - op->ref_index = k; - if (operands[k].input_index >= 0) - tcc_error("cannot reference twice the same operand"); - operands[k].input_index = i; - op->priority = 5; - } else if ((op->vt->r & VT_VALMASK) == VT_LOCAL - && op->vt->sym - && (reg = op->vt->sym->r & VT_VALMASK) < VT_CONST) { - op->priority = 1; - op->reg = reg; - } else { - op->priority = constraint_priority(str); - } - } - - /* sort operands according to their priority */ - for (i = 0; i < nb_operands; i++) - sorted_op[i] = i; - for (i = 0; i < nb_operands - 1; i++) { - for (j = i + 1; j < nb_operands; j++) { - p1 = operands[sorted_op[i]].priority; - p2 = operands[sorted_op[j]].priority; - if (p2 < p1) { - tmp = sorted_op[i]; - sorted_op[i] = sorted_op[j]; - sorted_op[j] = tmp; - } - } - } - - for (i = 0; i < NB_ASM_REGS; i++) { - if (clobber_regs[i]) - regs_allocated[i] = REG_IN_MASK | REG_OUT_MASK; - else - regs_allocated[i] = 0; - } - /* sp cannot be used */ - regs_allocated[13] = REG_IN_MASK | REG_OUT_MASK; - /* fp cannot be used yet */ - regs_allocated[11] = REG_IN_MASK | REG_OUT_MASK; - - /* allocate registers and generate corresponding asm moves */ - for (i = 0; i < nb_operands; i++) { - j = sorted_op[i]; - op = &operands[j]; - str = op->constraint; - /* no need to allocate references */ - if (op->ref_index >= 0) - continue; - /* select if register is used for output, input or both */ - if (op->input_index >= 0) { - reg_mask = REG_IN_MASK | REG_OUT_MASK; - } else if (j < nb_outputs) { - reg_mask = REG_OUT_MASK; - } else { - reg_mask = REG_IN_MASK; - } - if (op->reg >= 0) { - if (is_reg_allocated(op->reg)) - tcc_error - ("asm regvar requests register that's taken already"); - reg = op->reg; - goto reg_found; - } - try_next: - c = *str++; - switch (c) { - case '=': // Operand is written-to - goto try_next; - case '+': // Operand is both READ and written-to - op->is_rw = 1; - /* FALL THRU */ - case '&': // Operand is clobbered before the instruction is done using the input operands - if (j >= nb_outputs) - tcc_error("'%c' modifier can only be applied to outputs", - c); - reg_mask = REG_IN_MASK | REG_OUT_MASK; - goto try_next; - case 'l': // In non-thumb mode, alias for 'r'--otherwise r0-r7 [ARM] - case 'r': // general-purpose register - case 'p': // loadable/storable address - /* any general register */ - for (reg = 0; reg <= 8; reg++) { - if (!is_reg_allocated(reg)) - goto reg_found; - } - goto try_next; - reg_found: - /* now we can reload in the register */ - op->is_llong = 0; - op->reg = reg; - regs_allocated[reg] |= reg_mask; - break; - case 'I': // integer that is valid as an data processing instruction immediate (0...255, rotated by a multiple of two) - case 'J': // integer in the range -4095 to 4095 [ARM] - case 'K': // integer that satisfies constraint I when inverted (one's complement) - case 'L': // integer that satisfies constraint I when inverted (two's complement) - case 'i': // immediate integer operand, including symbolic constants - if (!((op->vt->r & (VT_VALMASK | VT_LVAL)) == VT_CONST)) - goto try_next; - break; - case 'M': // integer in the range 0 to 32 - if (! - ((op->vt->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == - VT_CONST)) - goto try_next; - break; - case 'm': // memory operand - case 'g': - /* nothing special to do because the operand is already in - memory, except if the pointer itself is stored in a - memory variable (VT_LLOCAL case) */ - /* XXX: fix constant case */ - /* if it is a reference to a memory zone, it must lie - in a register, so we reserve the register in the - input registers and a load will be generated - later */ - if (j < nb_outputs || c == 'm') { - if ((op->vt->r & VT_VALMASK) == VT_LLOCAL) { - /* any general register */ - for (reg = 0; reg <= 8; reg++) { - if (!(regs_allocated[reg] & REG_IN_MASK)) - goto reg_found1; - } - goto try_next; - reg_found1: - /* now we can reload in the register */ - regs_allocated[reg] |= REG_IN_MASK; - op->reg = reg; - op->is_memory = 1; - } - } - break; - default: - tcc_error("asm constraint %d ('%s') could not be satisfied", - j, op->constraint); - break; - } - /* if a reference is present for that operand, we assign it too */ - if (op->input_index >= 0) { - operands[op->input_index].reg = op->reg; - operands[op->input_index].is_llong = op->is_llong; - } - } - - /* compute out_reg. It is used to store outputs registers to memory - locations references by pointers (VT_LLOCAL case) */ - *pout_reg = -1; - for (i = 0; i < nb_operands; i++) { - op = &operands[i]; - if (op->reg >= 0 && - (op->vt->r & VT_VALMASK) == VT_LLOCAL && !op->is_memory) { - for (reg = 0; reg <= 8; reg++) { - if (!(regs_allocated[reg] & REG_OUT_MASK)) - goto reg_found2; - } - tcc_error("could not find free output register for reloading"); - reg_found2: - *pout_reg = reg; - break; - } - } - - /* print sorted constraints */ -#ifdef ASM_DEBUG - for (i = 0; i < nb_operands; i++) { - j = sorted_op[i]; - op = &operands[j]; - printf("%%%d [%s]: \"%s\" r=0x%04x reg=%d\n", - j, - op->id ? get_tok_str(op->id, NULL) : "", - op->constraint, op->vt->r, op->reg); - } - if (*pout_reg >= 0) - printf("out_reg=%d\n", *pout_reg); -#endif -} - -ST_FUNC void asm_clobber(uint8_t *clobber_regs, const char *str) -{ - int reg; - TokenSym *ts; - - if (!strcmp(str, "memory") || - !strcmp(str, "cc") || - !strcmp(str, "flags")) - return; - ts = tok_alloc(str, strlen(str)); - reg = asm_parse_regvar(ts->tok); - if (reg == -1) { - tcc_error("invalid clobber register '%s'", str); - } - clobber_regs[reg] = 1; -} - -/* If T refers to a register then return the register number and type. - Otherwise return -1. */ -ST_FUNC int asm_parse_regvar (int t) -{ - if (t >= TOK_ASM_r0 && t <= TOK_ASM_pc) { /* register name */ - switch (t) { - case TOK_ASM_fp: - return TOK_ASM_r11 - TOK_ASM_r0; - case TOK_ASM_ip: - return TOK_ASM_r12 - TOK_ASM_r0; - case TOK_ASM_sp: - return TOK_ASM_r13 - TOK_ASM_r0; - case TOK_ASM_lr: - return TOK_ASM_r14 - TOK_ASM_r0; - case TOK_ASM_pc: - return TOK_ASM_r15 - TOK_ASM_r0; - default: - return t - TOK_ASM_r0; - } - } else - return -1; -} - -/*************************************************************/ -#endif /* ndef TARGET_DEFS_ONLY */ diff --git a/05/tcc-final/arm-gen.c b/05/tcc-final/arm-gen.c deleted file mode 100644 index e0d98d0..0000000 --- a/05/tcc-final/arm-gen.c +++ /dev/null @@ -1,2391 +0,0 @@ -/* - * ARMv4 code generator for TCC - * - * Copyright (c) 2003 Daniel Glöckner - * Copyright (c) 2012 Thomas Preud'homme - * - * Based on i386-gen.c by Fabrice Bellard - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifdef TARGET_DEFS_ONLY - -#if defined(TCC_ARM_EABI) && !defined(TCC_ARM_VFP) -#error "Currently TinyCC only supports float computation with VFP instructions" -#endif - -/* number of available registers */ -#ifdef TCC_ARM_VFP -#define NB_REGS 13 -#else -#define NB_REGS 9 -#endif - -#ifndef TCC_CPU_VERSION -# define TCC_CPU_VERSION 5 -#endif - -/* a register can belong to several classes. The classes must be - sorted from more general to more precise (see gv2() code which does - assumptions on it). */ -#define RC_INT 0x0001 /* generic integer register */ -#define RC_FLOAT 0x0002 /* generic float register */ -#define RC_R0 0x0004 -#define RC_R1 0x0008 -#define RC_R2 0x0010 -#define RC_R3 0x0020 -#define RC_R12 0x0040 -#define RC_F0 0x0080 -#define RC_F1 0x0100 -#define RC_F2 0x0200 -#define RC_F3 0x0400 -#ifdef TCC_ARM_VFP -#define RC_F4 0x0800 -#define RC_F5 0x1000 -#define RC_F6 0x2000 -#define RC_F7 0x4000 -#endif -#define RC_IRET RC_R0 /* function return: integer register */ -#define RC_IRE2 RC_R1 /* function return: second integer register */ -#define RC_FRET RC_F0 /* function return: float register */ - -/* pretty names for the registers */ -enum { - TREG_R0 = 0, - TREG_R1, - TREG_R2, - TREG_R3, - TREG_R12, - TREG_F0, - TREG_F1, - TREG_F2, - TREG_F3, -#ifdef TCC_ARM_VFP - TREG_F4, - TREG_F5, - TREG_F6, - TREG_F7, -#endif - TREG_SP = 13, - TREG_LR, -}; - -#ifdef TCC_ARM_VFP -#define T2CPR(t) (((t) & VT_BTYPE) != VT_FLOAT ? 0x100 : 0) -#endif - -/* return registers for function */ -#define REG_IRET TREG_R0 /* single word int return register */ -#define REG_IRE2 TREG_R1 /* second word return register (for long long) */ -#define REG_FRET TREG_F0 /* float return register */ - -#ifdef TCC_ARM_EABI -#define TOK___divdi3 TOK___aeabi_ldivmod -#define TOK___moddi3 TOK___aeabi_ldivmod -#define TOK___udivdi3 TOK___aeabi_uldivmod -#define TOK___umoddi3 TOK___aeabi_uldivmod -#endif - -/* defined if function parameters must be evaluated in reverse order */ -#define INVERT_FUNC_PARAMS - -/* defined if structures are passed as pointers. Otherwise structures - are directly pushed on stack. */ -/* #define FUNC_STRUCT_PARAM_AS_PTR */ - -/* pointer size, in bytes */ -#define PTR_SIZE 4 - -/* long double size and alignment, in bytes */ -#ifdef TCC_ARM_VFP -#define LDOUBLE_SIZE 8 -#endif - -#ifndef LDOUBLE_SIZE -#define LDOUBLE_SIZE 8 -#endif - -#ifdef TCC_ARM_EABI -#define LDOUBLE_ALIGN 8 -#else -#define LDOUBLE_ALIGN 4 -#endif - -/* maximum alignment (for aligned attribute support) */ -#define MAX_ALIGN 8 - -#define CHAR_IS_UNSIGNED - -#ifdef TCC_ARM_HARDFLOAT -# define ARM_FLOAT_ABI ARM_HARD_FLOAT -#else -# define ARM_FLOAT_ABI ARM_SOFTFP_FLOAT -#endif - -/******************************************************/ -#else /* ! TARGET_DEFS_ONLY */ -/******************************************************/ -#define USING_GLOBALS -#include "tcc.h" - -ST_DATA const char * const target_machine_defs = - "__arm__\0" - "__arm\0" - "arm\0" - "__arm_elf__\0" - "__arm_elf\0" - "arm_elf\0" - "__ARM_ARCH_4__\0" - "__ARMEL__\0" - "__APCS_32__\0" -#if defined TCC_ARM_EABI - "__ARM_EABI__\0" -#endif - ; - -enum float_abi float_abi; - -ST_DATA const int reg_classes[NB_REGS] = { - /* r0 */ RC_INT | RC_R0, - /* r1 */ RC_INT | RC_R1, - /* r2 */ RC_INT | RC_R2, - /* r3 */ RC_INT | RC_R3, - /* r12 */ RC_INT | RC_R12, - /* f0 */ RC_FLOAT | RC_F0, - /* f1 */ RC_FLOAT | RC_F1, - /* f2 */ RC_FLOAT | RC_F2, - /* f3 */ RC_FLOAT | RC_F3, -#ifdef TCC_ARM_VFP - /* d4/s8 */ RC_FLOAT | RC_F4, -/* d5/s10 */ RC_FLOAT | RC_F5, -/* d6/s12 */ RC_FLOAT | RC_F6, -/* d7/s14 */ RC_FLOAT | RC_F7, -#endif -}; - -static int func_sub_sp_offset, last_itod_magic; -static int leaffunc; - -#if defined(CONFIG_TCC_BCHECK) -static addr_t func_bound_offset; -static unsigned long func_bound_ind; -ST_DATA int func_bound_add_epilog; -#endif - -#if defined(TCC_ARM_EABI) && defined(TCC_ARM_VFP) -static CType float_type, double_type, func_float_type, func_double_type; -ST_FUNC void arm_init(struct TCCState *s) -{ - float_type.t = VT_FLOAT; - double_type.t = VT_DOUBLE; - func_float_type.t = VT_FUNC; - func_float_type.ref = sym_push(SYM_FIELD, &float_type, FUNC_CDECL, FUNC_OLD); - func_double_type.t = VT_FUNC; - func_double_type.ref = sym_push(SYM_FIELD, &double_type, FUNC_CDECL, FUNC_OLD); - - float_abi = s->float_abi; -#ifndef TCC_ARM_HARDFLOAT -// XXX: Works on OpenBSD -// # warning "soft float ABI currently not supported: default to softfp" -#endif -} -#else -#define func_float_type func_old_type -#define func_double_type func_old_type -#define func_ldouble_type func_old_type -ST_FUNC void arm_init(struct TCCState *s) -{ -#if 0 -#if !defined (TCC_ARM_VFP) - tcc_warning("Support for FPA is deprecated and will be removed in next" - " release"); -#endif -#if !defined (TCC_ARM_EABI) - tcc_warning("Support for OABI is deprecated and will be removed in next" - " release"); -#endif -#endif -} -#endif - -#define CHECK_R(r) ((r) >= TREG_R0 && (r) <= TREG_LR) - -static int two2mask(int a,int b) { - if (!CHECK_R(a) || !CHECK_R(b)) - tcc_error("compiler error! registers %i,%i is not valid",a,b); - return (reg_classes[a]|reg_classes[b])&~(RC_INT|RC_FLOAT); -} - -static int regmask(int r) { - if (!CHECK_R(r)) - tcc_error("compiler error! register %i is not valid",r); - return reg_classes[r]&~(RC_INT|RC_FLOAT); -} - -/******************************************************/ - -#if defined(TCC_ARM_EABI) && !defined(CONFIG_TCC_ELFINTERP) -const char *default_elfinterp(struct TCCState *s) -{ - if (s->float_abi == ARM_HARD_FLOAT) - return "/lib/ld-linux-armhf.so.3"; - else - return "/lib/ld-linux.so.3"; -} -#endif - -void o(uint32_t i) -{ - /* this is a good place to start adding big-endian support*/ - int ind1; - if (nocode_wanted) - return; - ind1 = ind + 4; - if (!cur_text_section) - tcc_error("compiler error! This happens f.ex. if the compiler\n" - "can't evaluate constant expressions outside of a function."); - if (ind1 > cur_text_section->data_allocated) - section_realloc(cur_text_section, ind1); - cur_text_section->data[ind++] = i&255; - i>>=8; - cur_text_section->data[ind++] = i&255; - i>>=8; - cur_text_section->data[ind++] = i&255; - i>>=8; - cur_text_section->data[ind++] = i; -} - -static uint32_t stuff_const(uint32_t op, uint32_t c) -{ - int try_neg=0; - uint32_t nc = 0, negop = 0; - - switch(op&0x1F00000) - { - case 0x800000: //add - case 0x400000: //sub - try_neg=1; - negop=op^0xC00000; - nc=-c; - break; - case 0x1A00000: //mov - case 0x1E00000: //mvn - try_neg=1; - negop=op^0x400000; - nc=~c; - break; - case 0x200000: //xor - if(c==~0) - return (op&0xF010F000)|((op>>16)&0xF)|0x1E00000; - break; - case 0x0: //and - if(c==~0) - return (op&0xF010F000)|((op>>16)&0xF)|0x1A00000; - case 0x1C00000: //bic - try_neg=1; - negop=op^0x1C00000; - nc=~c; - break; - case 0x1800000: //orr - if(c==~0) - return (op&0xFFF0FFFF)|0x1E00000; - break; - } - do { - uint32_t m; - int i; - if(c<256) /* catch undefined <<32 */ - return op|c; - for(i=2;i<32;i+=2) { - m=(0xff>>i)|(0xff<<(32-i)); - if(!(c&~m)) - return op|(i<<7)|(c<>(32-i)); - } - op=negop; - c=nc; - } while(try_neg--); - return 0; -} - - -//only add,sub -void stuff_const_harder(uint32_t op, uint32_t v) { - uint32_t x; - x=stuff_const(op,v); - if(x) - o(x); - else { - uint32_t a[16], nv, no, o2, n2; - int i,j,k; - a[0]=0xff; - o2=(op&0xfff0ffff)|((op&0xf000)<<4);; - for(i=1;i<16;i++) - a[i]=(a[i-1]>>2)|(a[i-1]<<30); - for(i=0;i<12;i++) - for(j=i<4?i+12:15;j>=i+4;j--) - if((v&(a[i]|a[j]))==v) { - o(stuff_const(op,v&a[i])); - o(stuff_const(o2,v&a[j])); - return; - } - no=op^0xC00000; - n2=o2^0xC00000; - nv=-v; - for(i=0;i<12;i++) - for(j=i<4?i+12:15;j>=i+4;j--) - if((nv&(a[i]|a[j]))==nv) { - o(stuff_const(no,nv&a[i])); - o(stuff_const(n2,nv&a[j])); - return; - } - for(i=0;i<8;i++) - for(j=i+4;j<12;j++) - for(k=i<4?i+12:15;k>=j+4;k--) - if((v&(a[i]|a[j]|a[k]))==v) { - o(stuff_const(op,v&a[i])); - o(stuff_const(o2,v&a[j])); - o(stuff_const(o2,v&a[k])); - return; - } - no=op^0xC00000; - nv=-v; - for(i=0;i<8;i++) - for(j=i+4;j<12;j++) - for(k=i<4?i+12:15;k>=j+4;k--) - if((nv&(a[i]|a[j]|a[k]))==nv) { - o(stuff_const(no,nv&a[i])); - o(stuff_const(n2,nv&a[j])); - o(stuff_const(n2,nv&a[k])); - return; - } - o(stuff_const(op,v&a[0])); - o(stuff_const(o2,v&a[4])); - o(stuff_const(o2,v&a[8])); - o(stuff_const(o2,v&a[12])); - } -} - -uint32_t encbranch(int pos, int addr, int fail) -{ - addr-=pos+8; - addr/=4; - if(addr>=0x1000000 || addr<-0x1000000) { - if(fail) - tcc_error("FIXME: function bigger than 32MB"); - return 0; - } - return 0x0A000000|(addr&0xffffff); -} - -int decbranch(int pos) -{ - int x; - x=*(uint32_t *)(cur_text_section->data + pos); - x&=0x00ffffff; - if(x&0x800000) - x-=0x1000000; - return x*4+pos+8; -} - -/* output a symbol and patch all calls to it */ -void gsym_addr(int t, int a) -{ - uint32_t *x; - int lt; - while(t) { - x=(uint32_t *)(cur_text_section->data + t); - t=decbranch(lt=t); - if(a==lt+4) - *x=0xE1A00000; // nop - else { - *x &= 0xff000000; - *x |= encbranch(lt,a,1); - } - } -} - -#ifdef TCC_ARM_VFP -static uint32_t vfpr(int r) -{ - if(rTREG_F7) - tcc_error("compiler error! register %i is no vfp register",r); - return r - TREG_F0; -} -#else -static uint32_t fpr(int r) -{ - if(rTREG_F3) - tcc_error("compiler error! register %i is no fpa register",r); - return r - TREG_F0; -} -#endif - -static uint32_t intr(int r) -{ - if(r == TREG_R12) - return 12; - if(r >= TREG_R0 && r <= TREG_R3) - return r - TREG_R0; - if (!(r >= TREG_SP && r <= TREG_LR)) - tcc_error("compiler error! register %i is no int register",r); - return r + (13 - TREG_SP); -} - -static void calcaddr(uint32_t *base, int *off, int *sgn, int maxoff, unsigned shift) -{ - if(*off>maxoff || *off&((1<r & VT_SYM) - greloc(cur_text_section, sv->sym, ind, R_ARM_ABS32); - o(sv->c.i); -#else - if(sv->r & VT_SYM) { - if (sv->sym->type.t & VT_STATIC) { - greloc(cur_text_section, sv->sym, ind, R_ARM_REL32); - o(sv->c.i - 12); - o(0xe080000f | (intr(r)<<12) | (intr(r)<<16)); // add rx,rx,pc - } - else { - greloc(cur_text_section, sv->sym, ind, R_ARM_GOT_PREL); - o(-12); - o(0xe080000f | (intr(r)<<12) | (intr(r)<<16)); // add rx,rx,pc - o(0xe5900000 | (intr(r)<<12) | (intr(r)<<16)); // ldr rx,[rx] - if (sv->c.i) - stuff_const_harder(0xe2800000 | (intr(r)<<12) | (intr(r)<<16), - sv->c.i); - } - } - else - o(sv->c.i); -#endif -} - -/* load 'r' from value 'sv' */ -void load(int r, SValue *sv) -{ - int v, ft, fc, fr, sign; - uint32_t op; - SValue v1; - - fr = sv->r; - ft = sv->type.t; - fc = sv->c.i; - - if(fc>=0) - sign=0; - else { - sign=1; - fc=-fc; - } - - v = fr & VT_VALMASK; - if (fr & VT_LVAL) { - uint32_t base = 0xB; // fp - if(v == VT_LLOCAL) { - v1.type.t = VT_PTR; - v1.r = VT_LOCAL | VT_LVAL; - v1.c.i = sv->c.i; - load(TREG_LR, &v1); - base = 14; /* lr */ - fc=sign=0; - v=VT_LOCAL; - } else if(v == VT_CONST) { - v1.type.t = VT_PTR; - v1.r = fr&~VT_LVAL; - v1.c.i = sv->c.i; - v1.sym=sv->sym; - load(TREG_LR, &v1); - base = 14; /* lr */ - fc=sign=0; - v=VT_LOCAL; - } else if(v < VT_CONST) { - base=intr(v); - fc=sign=0; - v=VT_LOCAL; - } - if(v == VT_LOCAL) { - if(is_float(ft)) { - calcaddr(&base,&fc,&sign,1020,2); -#ifdef TCC_ARM_VFP - op=0xED100A00; /* flds */ - if(!sign) - op|=0x800000; - if ((ft & VT_BTYPE) != VT_FLOAT) - op|=0x100; /* flds -> fldd */ - o(op|(vfpr(r)<<12)|(fc>>2)|(base<<16)); -#else - op=0xED100100; - if(!sign) - op|=0x800000; -#if LDOUBLE_SIZE == 8 - if ((ft & VT_BTYPE) != VT_FLOAT) - op|=0x8000; -#else - if ((ft & VT_BTYPE) == VT_DOUBLE) - op|=0x8000; - else if ((ft & VT_BTYPE) == VT_LDOUBLE) - op|=0x400000; -#endif - o(op|(fpr(r)<<12)|(fc>>2)|(base<<16)); -#endif - } else if((ft & (VT_BTYPE|VT_UNSIGNED)) == VT_BYTE - || (ft & VT_BTYPE) == VT_SHORT) { - calcaddr(&base,&fc,&sign,255,0); - op=0xE1500090; - if ((ft & VT_BTYPE) == VT_SHORT) - op|=0x20; - if ((ft & VT_UNSIGNED) == 0) - op|=0x40; - if(!sign) - op|=0x800000; - o(op|(intr(r)<<12)|(base<<16)|((fc&0xf0)<<4)|(fc&0xf)); - } else { - calcaddr(&base,&fc,&sign,4095,0); - op=0xE5100000; - if(!sign) - op|=0x800000; - if ((ft & VT_BTYPE) == VT_BYTE || (ft & VT_BTYPE) == VT_BOOL) - op|=0x400000; - o(op|(intr(r)<<12)|fc|(base<<16)); - } - return; - } - } else { - if (v == VT_CONST) { - op=stuff_const(0xE3A00000|(intr(r)<<12),sv->c.i); - if (fr & VT_SYM || !op) - load_value(sv, r); - else - o(op); - return; - } else if (v == VT_LOCAL) { - op=stuff_const(0xE28B0000|(intr(r)<<12),sv->c.i); - if (fr & VT_SYM || !op) { - load_value(sv, r); - o(0xE08B0000|(intr(r)<<12)|intr(r)); - } else - o(op); - return; - } else if(v == VT_CMP) { - o(mapcc(sv->c.i)|0x3A00001|(intr(r)<<12)); - o(mapcc(negcc(sv->c.i))|0x3A00000|(intr(r)<<12)); - return; - } else if (v == VT_JMP || v == VT_JMPI) { - int t; - t = v & 1; - o(0xE3A00000|(intr(r)<<12)|t); - o(0xEA000000); - gsym(sv->c.i); - o(0xE3A00000|(intr(r)<<12)|(t^1)); - return; - } else if (v < VT_CONST) { - if(is_float(ft)) -#ifdef TCC_ARM_VFP - o(0xEEB00A40|(vfpr(r)<<12)|vfpr(v)|T2CPR(ft)); /* fcpyX */ -#else - o(0xEE008180|(fpr(r)<<12)|fpr(v)); -#endif - else - o(0xE1A00000|(intr(r)<<12)|intr(v)); - return; - } - } - tcc_error("load unimplemented!"); -} - -/* store register 'r' in lvalue 'v' */ -void store(int r, SValue *sv) -{ - SValue v1; - int v, ft, fc, fr, sign; - uint32_t op; - - fr = sv->r; - ft = sv->type.t; - fc = sv->c.i; - - if(fc>=0) - sign=0; - else { - sign=1; - fc=-fc; - } - - v = fr & VT_VALMASK; - if (fr & VT_LVAL || fr == VT_LOCAL) { - uint32_t base = 0xb; /* fp */ - if(v < VT_CONST) { - base=intr(v); - v=VT_LOCAL; - fc=sign=0; - } else if(v == VT_CONST) { - v1.type.t = ft; - v1.r = fr&~VT_LVAL; - v1.c.i = sv->c.i; - v1.sym=sv->sym; - load(TREG_LR, &v1); - base = 14; /* lr */ - fc=sign=0; - v=VT_LOCAL; - } - if(v == VT_LOCAL) { - if(is_float(ft)) { - calcaddr(&base,&fc,&sign,1020,2); -#ifdef TCC_ARM_VFP - op=0xED000A00; /* fsts */ - if(!sign) - op|=0x800000; - if ((ft & VT_BTYPE) != VT_FLOAT) - op|=0x100; /* fsts -> fstd */ - o(op|(vfpr(r)<<12)|(fc>>2)|(base<<16)); -#else - op=0xED000100; - if(!sign) - op|=0x800000; -#if LDOUBLE_SIZE == 8 - if ((ft & VT_BTYPE) != VT_FLOAT) - op|=0x8000; -#else - if ((ft & VT_BTYPE) == VT_DOUBLE) - op|=0x8000; - if ((ft & VT_BTYPE) == VT_LDOUBLE) - op|=0x400000; -#endif - o(op|(fpr(r)<<12)|(fc>>2)|(base<<16)); -#endif - return; - } else if((ft & VT_BTYPE) == VT_SHORT) { - calcaddr(&base,&fc,&sign,255,0); - op=0xE14000B0; - if(!sign) - op|=0x800000; - o(op|(intr(r)<<12)|(base<<16)|((fc&0xf0)<<4)|(fc&0xf)); - } else { - calcaddr(&base,&fc,&sign,4095,0); - op=0xE5000000; - if(!sign) - op|=0x800000; - if ((ft & VT_BTYPE) == VT_BYTE || (ft & VT_BTYPE) == VT_BOOL) - op|=0x400000; - o(op|(intr(r)<<12)|fc|(base<<16)); - } - return; - } - } - tcc_error("store unimplemented"); -} - -static void gadd_sp(int val) -{ - stuff_const_harder(0xE28DD000,val); -} - -/* 'is_jmp' is '1' if it is a jump */ -static void gcall_or_jmp(int is_jmp) -{ - int r; - uint32_t x; - if ((vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST) { - /* constant case */ - if(vtop->r & VT_SYM){ - x=encbranch(ind,ind+vtop->c.i,0); - if(x) { - /* relocation case */ - greloc(cur_text_section, vtop->sym, ind, R_ARM_PC24); - o(x|(is_jmp?0xE0000000:0xE1000000)); - } else { - r = TREG_LR; - load_value(vtop, r); - if(is_jmp) - o(0xE1A0F000 | intr(r)); // mov pc, r - else - o(0xe12fff30 | intr(r)); // blx r - } - }else{ - if(!is_jmp) - o(0xE28FE004); // add lr,pc,#4 - o(0xE51FF004); // ldr pc,[pc,#-4] - o(vtop->c.i); - } - } else { - /* otherwise, indirect call */ -#ifdef CONFIG_TCC_BCHECK - vtop->r &= ~VT_MUSTBOUND; -#endif - r = gv(RC_INT); - if(!is_jmp) - o(0xE1A0E00F); // mov lr,pc - o(0xE1A0F000|intr(r)); // mov pc,r - } -} - -#if defined(CONFIG_TCC_BCHECK) - -static void gen_bounds_call(int v) -{ - Sym *sym = external_helper_sym(v); - - greloc(cur_text_section, sym, ind, R_ARM_PC24); - o(0xebfffffe); -} - -static void gen_bounds_prolog(void) -{ - /* leave some room for bound checking code */ - func_bound_offset = lbounds_section->data_offset; - func_bound_ind = ind; - func_bound_add_epilog = 0; - o(0xe1a00000); /* ld r0,lbounds_section->data_offset */ - o(0xe1a00000); - o(0xe1a00000); - o(0xe1a00000); - o(0xe1a00000); /* call __bound_local_new */ -} - -static void gen_bounds_epilog(void) -{ - addr_t saved_ind; - addr_t *bounds_ptr; - Sym *sym_data; - int offset_modified = func_bound_offset != lbounds_section->data_offset; - - if (!offset_modified && !func_bound_add_epilog) - return; - - /* add end of table info */ - bounds_ptr = section_ptr_add(lbounds_section, sizeof(addr_t)); - *bounds_ptr = 0; - - sym_data = get_sym_ref(&char_pointer_type, lbounds_section, - func_bound_offset, PTR_SIZE); - - /* generate bound local allocation */ - if (offset_modified) { - saved_ind = ind; - ind = func_bound_ind; - o(0xe59f0000); /* ldr r0, [pc] */ - o(0xea000000); /* b $+4 */ - greloc(cur_text_section, sym_data, ind, R_ARM_REL32); - o(-12); /* lbounds_section->data_offset */ - o(0xe080000f); /* add r0,r0,pc */ - gen_bounds_call(TOK___bound_local_new); - ind = saved_ind; - } - - /* generate bound check local freeing */ - o(0xe92d0003); /* push {r0,r1} */ - o(0xed2d0b04); /* vpush {d0,d1} */ - o(0xe59f0000); /* ldr r0, [pc] */ - o(0xea000000); /* b $+4 */ - greloc(cur_text_section, sym_data, ind, R_ARM_REL32); - o(-12); /* lbounds_section->data_offset */ - o(0xe080000f); /* add r0,r0,pc */ - gen_bounds_call(TOK___bound_local_delete); - o(0xecbd0b04); /* vpop {d0,d1} */ - o(0xe8bd0003); /* pop {r0,r1} */ -} -#endif - -static int unalias_ldbl(int btype) -{ -#if LDOUBLE_SIZE == 8 - if (btype == VT_LDOUBLE) - btype = VT_DOUBLE; -#endif - return btype; -} - -/* Return whether a structure is an homogeneous float aggregate or not. - The answer is true if all the elements of the structure are of the same - primitive float type and there is less than 4 elements. - - type: the type corresponding to the structure to be tested */ -static int is_hgen_float_aggr(CType *type) -{ - if ((type->t & VT_BTYPE) == VT_STRUCT) { - struct Sym *ref; - int btype, nb_fields = 0; - - ref = type->ref->next; - if (ref) { - btype = unalias_ldbl(ref->type.t & VT_BTYPE); - if (btype == VT_FLOAT || btype == VT_DOUBLE) { - for(; ref && btype == unalias_ldbl(ref->type.t & VT_BTYPE); ref = ref->next, nb_fields++); - return !ref && nb_fields <= 4; - } - } - } - return 0; -} - -struct avail_regs { - signed char avail[3]; /* 3 holes max with only float and double alignments */ - int first_hole; /* first available hole */ - int last_hole; /* last available hole (none if equal to first_hole) */ - int first_free_reg; /* next free register in the sequence, hole excluded */ -}; - -/* Find suitable registers for a VFP Co-Processor Register Candidate (VFP CPRC - param) according to the rules described in the procedure call standard for - the ARM architecture (AAPCS). If found, the registers are assigned to this - VFP CPRC parameter. Registers are allocated in sequence unless a hole exists - and the parameter is a single float. - - avregs: opaque structure to keep track of available VFP co-processor regs - align: alignment constraints for the param, as returned by type_size() - size: size of the parameter, as returned by type_size() */ -int assign_vfpreg(struct avail_regs *avregs, int align, int size) -{ - int first_reg = 0; - - if (avregs->first_free_reg == -1) - return -1; - if (align >> 3) { /* double alignment */ - first_reg = avregs->first_free_reg; - /* alignment constraint not respected so use next reg and record hole */ - if (first_reg & 1) - avregs->avail[avregs->last_hole++] = first_reg++; - } else { /* no special alignment (float or array of float) */ - /* if single float and a hole is available, assign the param to it */ - if (size == 4 && avregs->first_hole != avregs->last_hole) - return avregs->avail[avregs->first_hole++]; - else - first_reg = avregs->first_free_reg; - } - if (first_reg + size / 4 <= 16) { - avregs->first_free_reg = first_reg + size / 4; - return first_reg; - } - avregs->first_free_reg = -1; - return -1; -} - -/* Returns whether all params need to be passed in core registers or not. - This is the case for function part of the runtime ABI. */ -int floats_in_core_regs(SValue *sval) -{ - if (!sval->sym) - return 0; - - switch (sval->sym->v) { - case TOK___floatundisf: - case TOK___floatundidf: - case TOK___fixunssfdi: - case TOK___fixunsdfdi: -#ifndef TCC_ARM_VFP - case TOK___fixunsxfdi: -#endif - case TOK___floatdisf: - case TOK___floatdidf: - case TOK___fixsfdi: - case TOK___fixdfdi: - return 1; - - default: - return 0; - } -} - -/* Return the number of registers needed to return the struct, or 0 if - returning via struct pointer. */ -ST_FUNC int gfunc_sret(CType *vt, int variadic, CType *ret, int *ret_align, int *regsize) { -#ifdef TCC_ARM_EABI - int size, align; - size = type_size(vt, &align); - if (float_abi == ARM_HARD_FLOAT && !variadic && - (is_float(vt->t) || is_hgen_float_aggr(vt))) { - *ret_align = 8; - *regsize = 8; - ret->ref = NULL; - ret->t = VT_DOUBLE; - return (size + 7) >> 3; - } else if (size > 0 && size <= 4) { - *ret_align = 4; - *regsize = 4; - ret->ref = NULL; - ret->t = VT_INT; - return 1; - } else - return 0; -#else - return 0; -#endif -} - -/* Parameters are classified according to how they are copied to their final - destination for the function call. Because the copying is performed class - after class according to the order in the union below, it is important that - some constraints about the order of the members of this union are respected: - - CORE_STRUCT_CLASS must come after STACK_CLASS; - - CORE_CLASS must come after STACK_CLASS, CORE_STRUCT_CLASS and - VFP_STRUCT_CLASS; - - VFP_STRUCT_CLASS must come after VFP_CLASS. - See the comment for the main loop in copy_params() for the reason. */ -enum reg_class { - STACK_CLASS = 0, - CORE_STRUCT_CLASS, - VFP_CLASS, - VFP_STRUCT_CLASS, - CORE_CLASS, - NB_CLASSES -}; - -struct param_plan { - int start; /* first reg or addr used depending on the class */ - int end; /* last reg used or next free addr depending on the class */ - SValue *sval; /* pointer to SValue on the value stack */ - struct param_plan *prev; /* previous element in this class */ -}; - -struct plan { - struct param_plan *pplans; /* array of all the param plans */ - struct param_plan *clsplans[NB_CLASSES]; /* per class lists of param plans */ - int nb_plans; -}; - -static void add_param_plan(struct plan* plan, int cls, int start, int end, SValue *v) -{ - struct param_plan *p = &plan->pplans[plan->nb_plans++]; - p->prev = plan->clsplans[cls]; - plan->clsplans[cls] = p; - p->start = start, p->end = end, p->sval = v; -} - -/* Assign parameters to registers and stack with alignment according to the - rules in the procedure call standard for the ARM architecture (AAPCS). - The overall assignment is recorded in an array of per parameter structures - called parameter plans. The parameter plans are also further organized in a - number of linked lists, one per class of parameter (see the comment for the - definition of union reg_class). - - nb_args: number of parameters of the function for which a call is generated - float_abi: float ABI in use for this function call - plan: the structure where the overall assignment is recorded - todo: a bitmap that record which core registers hold a parameter - - Returns the amount of stack space needed for parameter passing - - Note: this function allocated an array in plan->pplans with tcc_malloc. It - is the responsibility of the caller to free this array once used (ie not - before copy_params). */ -static int assign_regs(int nb_args, int float_abi, struct plan *plan, int *todo) -{ - int i, size, align; - int ncrn /* next core register number */, nsaa /* next stacked argument address*/; - struct avail_regs avregs = {{0}}; - - ncrn = nsaa = 0; - *todo = 0; - - for(i = nb_args; i-- ;) { - int j, start_vfpreg = 0; - CType type = vtop[-i].type; - type.t &= ~VT_ARRAY; - size = type_size(&type, &align); - size = (size + 3) & ~3; - align = (align + 3) & ~3; - switch(vtop[-i].type.t & VT_BTYPE) { - case VT_STRUCT: - case VT_FLOAT: - case VT_DOUBLE: - case VT_LDOUBLE: - if (float_abi == ARM_HARD_FLOAT) { - int is_hfa = 0; /* Homogeneous float aggregate */ - - if (is_float(vtop[-i].type.t) - || (is_hfa = is_hgen_float_aggr(&vtop[-i].type))) { - int end_vfpreg; - - start_vfpreg = assign_vfpreg(&avregs, align, size); - end_vfpreg = start_vfpreg + ((size - 1) >> 2); - if (start_vfpreg >= 0) { - add_param_plan(plan, is_hfa ? VFP_STRUCT_CLASS : VFP_CLASS, - start_vfpreg, end_vfpreg, &vtop[-i]); - continue; - } else - break; - } - } - ncrn = (ncrn + (align-1)/4) & ~((align/4) - 1); - if (ncrn + size/4 <= 4 || (ncrn < 4 && start_vfpreg != -1)) { - /* The parameter is allocated both in core register and on stack. As - * such, it can be of either class: it would either be the last of - * CORE_STRUCT_CLASS or the first of STACK_CLASS. */ - for (j = ncrn; j < 4 && j < ncrn + size / 4; j++) - *todo|=(1< 4) - nsaa = (ncrn - 4) * 4; - } else { - ncrn = 4; - break; - } - continue; - default: - if (ncrn < 4) { - int is_long = (vtop[-i].type.t & VT_BTYPE) == VT_LLONG; - - if (is_long) { - ncrn = (ncrn + 1) & -2; - if (ncrn == 4) - break; - } - add_param_plan(plan, CORE_CLASS, ncrn, ncrn + is_long, &vtop[-i]); - ncrn += 1 + is_long; - continue; - } - } - nsaa = (nsaa + (align - 1)) & ~(align - 1); - add_param_plan(plan, STACK_CLASS, nsaa, nsaa + size, &vtop[-i]); - nsaa += size; /* size already rounded up before */ - } - return nsaa; -} - -/* Copy parameters to their final destination (core reg, VFP reg or stack) for - function call. - - nb_args: number of parameters the function take - plan: the overall assignment plan for parameters - todo: a bitmap indicating what core reg will hold a parameter - - Returns the number of SValue added by this function on the value stack */ -static int copy_params(int nb_args, struct plan *plan, int todo) -{ - int size, align, r, i, nb_extra_sval = 0; - struct param_plan *pplan; - int pass = 0; - - /* Several constraints require parameters to be copied in a specific order: - - structures are copied to the stack before being loaded in a reg; - - floats loaded to an odd numbered VFP reg are first copied to the - preceding even numbered VFP reg and then moved to the next VFP reg. - - It is thus important that: - - structures assigned to core regs must be copied after parameters - assigned to the stack but before structures assigned to VFP regs because - a structure can lie partly in core registers and partly on the stack; - - parameters assigned to the stack and all structures be copied before - parameters assigned to a core reg since copying a parameter to the stack - require using a core reg; - - parameters assigned to VFP regs be copied before structures assigned to - VFP regs as the copy might use an even numbered VFP reg that already - holds part of a structure. */ -again: - for(i = 0; i < NB_CLASSES; i++) { - for(pplan = plan->clsplans[i]; pplan; pplan = pplan->prev) { - - if (pass - && (i != CORE_CLASS || pplan->sval->r < VT_CONST)) - continue; - - vpushv(pplan->sval); - pplan->sval->r = pplan->sval->r2 = VT_CONST; /* disable entry */ - switch(i) { - case STACK_CLASS: - case CORE_STRUCT_CLASS: - case VFP_STRUCT_CLASS: - if ((pplan->sval->type.t & VT_BTYPE) == VT_STRUCT) { - int padding = 0; - size = type_size(&pplan->sval->type, &align); - /* align to stack align size */ - size = (size + 3) & ~3; - if (i == STACK_CLASS && pplan->prev) - padding = pplan->start - pplan->prev->end; - size += padding; /* Add padding if any */ - /* allocate the necessary size on stack */ - gadd_sp(-size); - /* generate structure store */ - r = get_reg(RC_INT); - o(0xE28D0000|(intr(r)<<12)|padding); /* add r, sp, padding */ - vset(&vtop->type, r | VT_LVAL, 0); - vswap(); - /* XXX: optimize. Save all register because memcpy can use them */ - o(0xED2D0A00|(0&1)<<22|(0>>1)<<12|16); /* vpush {s0-s15} */ - vstore(); /* memcpy to current sp + potential padding */ - o(0xECBD0A00|(0&1)<<22|(0>>1)<<12|16); /* vpop {s0-s15} */ - - /* Homogeneous float aggregate are loaded to VFP registers - immediately since there is no way of loading data in multiple - non consecutive VFP registers as what is done for other - structures (see the use of todo). */ - if (i == VFP_STRUCT_CLASS) { - int first = pplan->start, nb = pplan->end - first + 1; - /* vpop.32 {pplan->start, ..., pplan->end} */ - o(0xECBD0A00|(first&1)<<22|(first>>1)<<12|nb); - /* No need to write the register used to a SValue since VFP regs - cannot be used for gcall_or_jmp */ - } - } else { - if (is_float(pplan->sval->type.t)) { -#ifdef TCC_ARM_VFP - r = vfpr(gv(RC_FLOAT)) << 12; - if ((pplan->sval->type.t & VT_BTYPE) == VT_FLOAT) - size = 4; - else { - size = 8; - r |= 0x101; /* vpush.32 -> vpush.64 */ - } - o(0xED2D0A01 + r); /* vpush */ -#else - r = fpr(gv(RC_FLOAT)) << 12; - if ((pplan->sval->type.t & VT_BTYPE) == VT_FLOAT) - size = 4; - else if ((pplan->sval->type.t & VT_BTYPE) == VT_DOUBLE) - size = 8; - else - size = LDOUBLE_SIZE; - - if (size == 12) - r |= 0x400000; - else if(size == 8) - r|=0x8000; - - o(0xED2D0100|r|(size>>2)); /* some kind of vpush for FPA */ -#endif - } else { - /* simple type (currently always same size) */ - /* XXX: implicit cast ? */ - size=4; - if ((pplan->sval->type.t & VT_BTYPE) == VT_LLONG) { - lexpand(); - size = 8; - r = gv(RC_INT); - o(0xE52D0004|(intr(r)<<12)); /* push r */ - vtop--; - } - r = gv(RC_INT); - o(0xE52D0004|(intr(r)<<12)); /* push r */ - } - if (i == STACK_CLASS && pplan->prev) - gadd_sp(pplan->prev->end - pplan->start); /* Add padding if any */ - } - break; - - case VFP_CLASS: - gv(regmask(TREG_F0 + (pplan->start >> 1))); - if (pplan->start & 1) { /* Must be in upper part of double register */ - o(0xEEF00A40|((pplan->start>>1)<<12)|(pplan->start>>1)); /* vmov.f32 s(n+1), sn */ - vtop->r = VT_CONST; /* avoid being saved on stack by gv for next float */ - } - break; - - case CORE_CLASS: - if ((pplan->sval->type.t & VT_BTYPE) == VT_LLONG) { - lexpand(); - gv(regmask(pplan->end)); - pplan->sval->r2 = vtop->r; - vtop--; - } - gv(regmask(pplan->start)); - /* Mark register as used so that gcall_or_jmp use another one - (regs >=4 are free as never used to pass parameters) */ - pplan->sval->r = vtop->r; - break; - } - vtop--; - } - } - - /* second pass to restore registers that were saved on stack by accident. - Maybe redundant after the "lvalue_save" patch in tccgen.c:gv() */ - if (++pass < 2) - goto again; - - /* Manually free remaining registers since next parameters are loaded - * manually, without the help of gv(int). */ - save_regs(nb_args); - - if(todo) { - o(0xE8BD0000|todo); /* pop {todo} */ - for(pplan = plan->clsplans[CORE_STRUCT_CLASS]; pplan; pplan = pplan->prev) { - int r; - pplan->sval->r = pplan->start; - /* An SValue can only pin 2 registers at best (r and r2) but a structure - can occupy more than 2 registers. Thus, we need to push on the value - stack some fake parameter to have on SValue for each registers used - by a structure (r2 is not used). */ - for (r = pplan->start + 1; r <= pplan->end; r++) { - if (todo & (1 << r)) { - nb_extra_sval++; - vpushi(0); - vtop->r = r; - } - } - } - } - return nb_extra_sval; -} - -/* Generate function call. The function address is pushed first, then - all the parameters in call order. This functions pops all the - parameters and the function address. */ -void gfunc_call(int nb_args) -{ - int r, args_size; - int def_float_abi = float_abi; - int todo; - struct plan plan; -#ifdef TCC_ARM_EABI - int variadic; -#endif - -#ifdef CONFIG_TCC_BCHECK - if (tcc_state->do_bounds_check) - gbound_args(nb_args); -#endif - -#ifdef TCC_ARM_EABI - if (float_abi == ARM_HARD_FLOAT) { - variadic = (vtop[-nb_args].type.ref->f.func_type == FUNC_ELLIPSIS); - if (variadic || floats_in_core_regs(&vtop[-nb_args])) - float_abi = ARM_SOFTFP_FLOAT; - } -#endif - /* cannot let cpu flags if other instruction are generated. Also avoid leaving - VT_JMP anywhere except on the top of the stack because it would complicate - the code generator. */ - r = vtop->r & VT_VALMASK; - if (r == VT_CMP || (r & ~1) == VT_JMP) - gv(RC_INT); - - memset(&plan, 0, sizeof plan); - if (nb_args) - plan.pplans = tcc_malloc(nb_args * sizeof(*plan.pplans)); - - args_size = assign_regs(nb_args, float_abi, &plan, &todo); - -#ifdef TCC_ARM_EABI - if (args_size & 7) { /* Stack must be 8 byte aligned at fct call for EABI */ - args_size = (args_size + 7) & ~7; - o(0xE24DD004); /* sub sp, sp, #4 */ - } -#endif - - nb_args += copy_params(nb_args, &plan, todo); - tcc_free(plan.pplans); - - /* Move fct SValue on top as required by gcall_or_jmp */ - vrotb(nb_args + 1); - gcall_or_jmp(0); - if (args_size) - gadd_sp(args_size); /* pop all parameters passed on the stack */ -#if defined(TCC_ARM_EABI) && defined(TCC_ARM_VFP) - if(float_abi == ARM_SOFTFP_FLOAT && is_float(vtop->type.ref->type.t)) { - if((vtop->type.ref->type.t & VT_BTYPE) == VT_FLOAT) { - o(0xEE000A10); /*vmov s0, r0 */ - } else { - o(0xEE000B10); /* vmov.32 d0[0], r0 */ - o(0xEE201B10); /* vmov.32 d0[1], r1 */ - } - } -#endif - vtop -= nb_args + 1; /* Pop all params and fct address from value stack */ - leaffunc = 0; /* we are calling a function, so we aren't in a leaf function */ - float_abi = def_float_abi; -} - -/* generate function prolog of type 't' */ -void gfunc_prolog(Sym *func_sym) -{ - CType *func_type = &func_sym->type; - Sym *sym,*sym2; - int n, nf, size, align, rs, struct_ret = 0; - int addr, pn, sn; /* pn=core, sn=stack */ - CType ret_type; - -#ifdef TCC_ARM_EABI - struct avail_regs avregs = {{0}}; -#endif - - sym = func_type->ref; - - n = nf = 0; - if ((func_vt.t & VT_BTYPE) == VT_STRUCT && - !gfunc_sret(&func_vt, func_var, &ret_type, &align, &rs)) - { - n++; - struct_ret = 1; - func_vc = 12; /* Offset from fp of the place to store the result */ - } - for(sym2 = sym->next; sym2 && (n < 4 || nf < 16); sym2 = sym2->next) { - size = type_size(&sym2->type, &align); -#ifdef TCC_ARM_EABI - if (float_abi == ARM_HARD_FLOAT && !func_var && - (is_float(sym2->type.t) || is_hgen_float_aggr(&sym2->type))) { - int tmpnf = assign_vfpreg(&avregs, align, size); - tmpnf += (size + 3) / 4; - nf = (tmpnf > nf) ? tmpnf : nf; - } else -#endif - if (n < 4) - n += (size + 3) / 4; - } - o(0xE1A0C00D); /* mov ip,sp */ - if (func_var) - n=4; - if (n) { - if(n>4) - n=4; -#ifdef TCC_ARM_EABI - n=(n+1)&-2; -#endif - o(0xE92D0000|((1<16) - nf=16; - nf=(nf+1)&-2; /* nf => HARDFLOAT => EABI */ - o(0xED2D0A00|nf); /* save s0-s15 on stack if needed */ - } - o(0xE92D5800); /* save fp, ip, lr */ - o(0xE1A0B00D); /* mov fp, sp */ - func_sub_sp_offset = ind; - o(0xE1A00000); /* nop, leave space for stack adjustment in epilog */ - -#ifdef TCC_ARM_EABI - if (float_abi == ARM_HARD_FLOAT) { - func_vc += nf * 4; - memset(&avregs, 0, sizeof avregs); - } -#endif - pn = struct_ret, sn = 0; - while ((sym = sym->next)) { - CType *type; - type = &sym->type; - size = type_size(type, &align); - size = (size + 3) >> 2; - align = (align + 3) & ~3; -#ifdef TCC_ARM_EABI - if (float_abi == ARM_HARD_FLOAT && !func_var && (is_float(sym->type.t) - || is_hgen_float_aggr(&sym->type))) { - int fpn = assign_vfpreg(&avregs, align, size << 2); - if (fpn >= 0) - addr = fpn * 4; - else - goto from_stack; - } else -#endif - if (pn < 4) { -#ifdef TCC_ARM_EABI - pn = (pn + (align-1)/4) & -(align/4); -#endif - addr = (nf + pn) * 4; - pn += size; - if (!sn && pn > 4) - sn = (pn - 4); - } else { -#ifdef TCC_ARM_EABI -from_stack: - sn = (sn + (align-1)/4) & -(align/4); -#endif - addr = (n + nf + sn) * 4; - sn += size; - } - sym_push(sym->v & ~SYM_FIELD, type, VT_LOCAL | VT_LVAL, - addr + 12); - } - last_itod_magic=0; - leaffunc = 1; - loc = 0; -#ifdef CONFIG_TCC_BCHECK - if (tcc_state->do_bounds_check) - gen_bounds_prolog(); -#endif -} - -/* generate function epilog */ -void gfunc_epilog(void) -{ - uint32_t x; - int diff; - -#ifdef CONFIG_TCC_BCHECK - if (tcc_state->do_bounds_check) - gen_bounds_epilog(); -#endif - /* Copy float return value to core register if base standard is used and - float computation is made with VFP */ -#if defined(TCC_ARM_EABI) && defined(TCC_ARM_VFP) - if ((float_abi == ARM_SOFTFP_FLOAT || func_var) && is_float(func_vt.t)) { - if((func_vt.t & VT_BTYPE) == VT_FLOAT) - o(0xEE100A10); /* fmrs r0, s0 */ - else { - o(0xEE100B10); /* fmrdl r0, d0 */ - o(0xEE301B10); /* fmrdh r1, d0 */ - } - } -#endif - o(0xE89BA800); /* restore fp, sp, pc */ - diff = (-loc + 3) & -4; -#ifdef TCC_ARM_EABI - if(!leaffunc) - diff = ((diff + 11) & -8) - 4; -#endif - if(diff > 0) { - x=stuff_const(0xE24BD000, diff); /* sub sp,fp,# */ - if(x) - *(uint32_t *)(cur_text_section->data + func_sub_sp_offset) = x; - else { - int addr; - addr=ind; - o(0xE59FC004); /* ldr ip,[pc+4] */ - o(0xE04BD00C); /* sub sp,fp,ip */ - o(0xE1A0F00E); /* mov pc,lr */ - o(diff); - *(uint32_t *)(cur_text_section->data + func_sub_sp_offset) = 0xE1000000|encbranch(func_sub_sp_offset,addr,1); - } - } -} - -ST_FUNC void gen_fill_nops(int bytes) -{ - if ((bytes & 3)) - tcc_error("alignment of code section not multiple of 4"); - while (bytes > 0) { - o(0xE1A00000); - bytes -= 4; - } -} - -/* generate a jump to a label */ -ST_FUNC int gjmp(int t) -{ - int r; - if (nocode_wanted) - return t; - r=ind; - o(0xE0000000|encbranch(r,t,1)); - return r; -} - -/* generate a jump to a fixed address */ -ST_FUNC void gjmp_addr(int a) -{ - gjmp(a); -} - -ST_FUNC int gjmp_cond(int op, int t) -{ - int r; - if (nocode_wanted) - return t; - r=ind; - op=mapcc(op); - op|=encbranch(r,t,1); - o(op); - return r; -} - -ST_FUNC int gjmp_append(int n, int t) -{ - uint32_t *x; - int p,lp; - if(n) { - p = n; - do { - p = decbranch(lp=p); - } while(p); - x = (uint32_t *)(cur_text_section->data + lp); - *x &= 0xff000000; - *x |= encbranch(lp,t,1); - t = n; - } - return t; -} - -/* generate an integer binary operation */ -void gen_opi(int op) -{ - int c, func = 0; - uint32_t opc = 0, r, fr; - unsigned short retreg = REG_IRET; - - c=0; - switch(op) { - case '+': - opc = 0x8; - c=1; - break; - case TOK_ADDC1: /* add with carry generation */ - opc = 0x9; - c=1; - break; - case '-': - opc = 0x4; - c=1; - break; - case TOK_SUBC1: /* sub with carry generation */ - opc = 0x5; - c=1; - break; - case TOK_ADDC2: /* add with carry use */ - opc = 0xA; - c=1; - break; - case TOK_SUBC2: /* sub with carry use */ - opc = 0xC; - c=1; - break; - case '&': - opc = 0x0; - c=1; - break; - case '^': - opc = 0x2; - c=1; - break; - case '|': - opc = 0x18; - c=1; - break; - case '*': - gv2(RC_INT, RC_INT); - r = vtop[-1].r; - fr = vtop[0].r; - vtop--; - o(0xE0000090|(intr(r)<<16)|(intr(r)<<8)|intr(fr)); - return; - case TOK_SHL: - opc = 0; - c=2; - break; - case TOK_SHR: - opc = 1; - c=2; - break; - case TOK_SAR: - opc = 2; - c=2; - break; - case '/': - case TOK_PDIV: - func=TOK___divsi3; - c=3; - break; - case TOK_UDIV: - func=TOK___udivsi3; - c=3; - break; - case '%': -#ifdef TCC_ARM_EABI - func=TOK___aeabi_idivmod; - retreg=REG_IRE2; -#else - func=TOK___modsi3; -#endif - c=3; - break; - case TOK_UMOD: -#ifdef TCC_ARM_EABI - func=TOK___aeabi_uidivmod; - retreg=REG_IRE2; -#else - func=TOK___umodsi3; -#endif - c=3; - break; - case TOK_UMULL: - gv2(RC_INT, RC_INT); - r=intr(vtop[-1].r2=get_reg(RC_INT)); - c=vtop[-1].r; - vtop[-1].r=get_reg_ex(RC_INT,regmask(c)); - vtop--; - o(0xE0800090|(r<<16)|(intr(vtop->r)<<12)|(intr(c)<<8)|intr(vtop[1].r)); - return; - default: - opc = 0x15; - c=1; - break; - } - switch(c) { - case 1: - if((vtop[-1].r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) { - if(opc == 4 || opc == 5 || opc == 0xc) { - vswap(); - opc|=2; // sub -> rsb - } - } - if ((vtop->r & VT_VALMASK) == VT_CMP || - (vtop->r & (VT_VALMASK & ~1)) == VT_JMP) - gv(RC_INT); - vswap(); - c=intr(gv(RC_INT)); - vswap(); - opc=0xE0000000|(opc<<20); - if((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) { - uint32_t x; - x=stuff_const(opc|0x2000000|(c<<16),vtop->c.i); - if(x) { - if ((x & 0xfff00000) == 0xe3500000) // cmp rx,#c - o(x); - else { - r=intr(vtop[-1].r=get_reg_ex(RC_INT,regmask(vtop[-1].r))); - o(x|(r<<12)); - } - goto done; - } - } - fr=intr(gv(RC_INT)); -#ifdef CONFIG_TCC_BCHECK - if ((vtop[-1].r & VT_VALMASK) >= VT_CONST) { - vswap(); - c=intr(gv(RC_INT)); - vswap(); - } -#endif - if ((opc & 0xfff00000) == 0xe1500000) // cmp rx,ry - o(opc|(c<<16)|fr); - else { - r=intr(vtop[-1].r=get_reg_ex(RC_INT,two2mask(vtop->r,vtop[-1].r))); - o(opc|(c<<16)|(r<<12)|fr); - } -done: - vtop--; - if (op >= TOK_ULT && op <= TOK_GT) - vset_VT_CMP(op); - break; - case 2: - opc=0xE1A00000|(opc<<5); - if ((vtop->r & VT_VALMASK) == VT_CMP || - (vtop->r & (VT_VALMASK & ~1)) == VT_JMP) - gv(RC_INT); - vswap(); - r=intr(gv(RC_INT)); - vswap(); - if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) { - fr=intr(vtop[-1].r=get_reg_ex(RC_INT,regmask(vtop[-1].r))); - c = vtop->c.i & 0x1f; - o(opc|r|(c<<7)|(fr<<12)); - } else { - fr=intr(gv(RC_INT)); -#ifdef CONFIG_TCC_BCHECK - if ((vtop[-1].r & VT_VALMASK) >= VT_CONST) { - vswap(); - r=intr(gv(RC_INT)); - vswap(); - } -#endif - c=intr(vtop[-1].r=get_reg_ex(RC_INT,two2mask(vtop->r,vtop[-1].r))); - o(opc|r|(c<<12)|(fr<<8)|0x10); - } - vtop--; - break; - case 3: - vpush_helper_func(func); - vrott(3); - gfunc_call(2); - vpushi(0); - vtop->r = retreg; - break; - default: - tcc_error("gen_opi %i unimplemented!",op); - } -} - -#ifdef TCC_ARM_VFP -static int is_zero(int i) -{ - if((vtop[i].r & (VT_VALMASK | VT_LVAL | VT_SYM)) != VT_CONST) - return 0; - if (vtop[i].type.t == VT_FLOAT) - return (vtop[i].c.f == 0.f); - else if (vtop[i].type.t == VT_DOUBLE) - return (vtop[i].c.d == 0.0); - return (vtop[i].c.ld == 0.l); -} - -/* generate a floating point operation 'v = t1 op t2' instruction. The - * two operands are guaranteed to have the same floating point type */ -void gen_opf(int op) -{ - uint32_t x; - int fneg=0,r; - x=0xEE000A00|T2CPR(vtop->type.t); - switch(op) { - case '+': - if(is_zero(-1)) - vswap(); - if(is_zero(0)) { - vtop--; - return; - } - x|=0x300000; - break; - case '-': - x|=0x300040; - if(is_zero(0)) { - vtop--; - return; - } - if(is_zero(-1)) { - x|=0x810000; /* fsubX -> fnegX */ - vswap(); - vtop--; - fneg=1; - } - break; - case '*': - x|=0x200000; - break; - case '/': - x|=0x800000; - break; - default: - if(op < TOK_ULT || op > TOK_GT) { - tcc_error("unknown fp op %x!",op); - return; - } - if(is_zero(-1)) { - vswap(); - switch(op) { - case TOK_LT: op=TOK_GT; break; - case TOK_GE: op=TOK_ULE; break; - case TOK_LE: op=TOK_GE; break; - case TOK_GT: op=TOK_ULT; break; - } - } - x|=0xB40040; /* fcmpX */ - if(op!=TOK_EQ && op!=TOK_NE) - x|=0x80; /* fcmpX -> fcmpeX */ - if(is_zero(0)) { - vtop--; - o(x|0x10000|(vfpr(gv(RC_FLOAT))<<12)); /* fcmp(e)X -> fcmp(e)zX */ - } else { - gv2(RC_FLOAT,RC_FLOAT); - x|=vfpr(vtop[0].r); - o(x|(vfpr(vtop[-1].r) << 12)); - vtop--; - } - o(0xEEF1FA10); /* fmstat */ - - switch(op) { - case TOK_LE: op=TOK_ULE; break; - case TOK_LT: op=TOK_ULT; break; - case TOK_UGE: op=TOK_GE; break; - case TOK_UGT: op=TOK_GT; break; - } - vset_VT_CMP(op); - return; - } - r=gv(RC_FLOAT); - x|=vfpr(r); - r=regmask(r); - if(!fneg) { - int r2; - vswap(); - r2=gv(RC_FLOAT); - x|=vfpr(r2)<<16; - r|=regmask(r2); -#ifdef CONFIG_TCC_BCHECK - if ((vtop[-1].r & VT_VALMASK) >= VT_CONST) { - vswap(); - r=gv(RC_FLOAT); - vswap(); - x=(x&~0xf)|vfpr(r); - } -#endif - } - vtop->r=get_reg_ex(RC_FLOAT,r); - if(!fneg) - vtop--; - o(x|(vfpr(vtop->r)<<12)); -} - -#else -static uint32_t is_fconst() -{ - long double f; - uint32_t r; - if((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) != VT_CONST) - return 0; - if (vtop->type.t == VT_FLOAT) - f = vtop->c.f; - else if (vtop->type.t == VT_DOUBLE) - f = vtop->c.d; - else - f = vtop->c.ld; - if(!ieee_finite(f)) - return 0; - r=0x8; - if(f<0.0) { - r=0x18; - f=-f; - } - if(f==0.0) - return r; - if(f==1.0) - return r|1; - if(f==2.0) - return r|2; - if(f==3.0) - return r|3; - if(f==4.0) - return r|4; - if(f==5.0) - return r|5; - if(f==0.5) - return r|6; - if(f==10.0) - return r|7; - return 0; -} - -/* generate a floating point operation 'v = t1 op t2' instruction. The - two operands are guaranteed to have the same floating point type */ -void gen_opf(int op) -{ - uint32_t x, r, r2, c1, c2; - //fputs("gen_opf\n",stderr); - vswap(); - c1 = is_fconst(); - vswap(); - c2 = is_fconst(); - x=0xEE000100; -#if LDOUBLE_SIZE == 8 - if ((vtop->type.t & VT_BTYPE) != VT_FLOAT) - x|=0x80; -#else - if ((vtop->type.t & VT_BTYPE) == VT_DOUBLE) - x|=0x80; - else if ((vtop->type.t & VT_BTYPE) == VT_LDOUBLE) - x|=0x80000; -#endif - switch(op) - { - case '+': - if(!c2) { - vswap(); - c2=c1; - } - vswap(); - r=fpr(gv(RC_FLOAT)); - vswap(); - if(c2) { - if(c2>0xf) - x|=0x200000; // suf - r2=c2&0xf; - } else { - r2=fpr(gv(RC_FLOAT)); -#ifdef CONFIG_TCC_BCHECK - if ((vtop[-1].r & VT_VALMASK) >= VT_CONST) { - vswap(); - r=fpr(gv(RC_FLOAT)); - vswap(); - } -#endif - } - break; - case '-': - if(c2) { - if(c2<=0xf) - x|=0x200000; // suf - r2=c2&0xf; - vswap(); - r=fpr(gv(RC_FLOAT)); - vswap(); - } else if(c1 && c1<=0xf) { - x|=0x300000; // rsf - r2=c1; - r=fpr(gv(RC_FLOAT)); - vswap(); - } else { - x|=0x200000; // suf - vswap(); - r=fpr(gv(RC_FLOAT)); - vswap(); - r2=fpr(gv(RC_FLOAT)); -#ifdef CONFIG_TCC_BCHECK - if ((vtop[-1].r & VT_VALMASK) >= VT_CONST) { - vswap(); - r=fpr(gv(RC_FLOAT)); - vswap(); - } -#endif - } - break; - case '*': - if(!c2 || c2>0xf) { - vswap(); - c2=c1; - } - vswap(); - r=fpr(gv(RC_FLOAT)); - vswap(); - if(c2 && c2<=0xf) - r2=c2; - else { - r2=fpr(gv(RC_FLOAT)); -#ifdef CONFIG_TCC_BCHECK - if ((vtop[-1].r & VT_VALMASK) >= VT_CONST) { - vswap(); - r=fpr(gv(RC_FLOAT)); - vswap(); - } -#endif - } - x|=0x100000; // muf - break; - case '/': - if(c2 && c2<=0xf) { - x|=0x400000; // dvf - r2=c2; - vswap(); - r=fpr(gv(RC_FLOAT)); - vswap(); - } else if(c1 && c1<=0xf) { - x|=0x500000; // rdf - r2=c1; - r=fpr(gv(RC_FLOAT)); - vswap(); - } else { - x|=0x400000; // dvf - vswap(); - r=fpr(gv(RC_FLOAT)); - vswap(); - r2=fpr(gv(RC_FLOAT)); -#ifdef CONFIG_TCC_BCHECK - if ((vtop[-1].r & VT_VALMASK) >= VT_CONST) { - vswap(); - r=fpr(gv(RC_FLOAT)); - vswap(); - } -#endif - } - break; - default: - if(op >= TOK_ULT && op <= TOK_GT) { - x|=0xd0f110; // cmfe -/* bug (intention?) in Linux FPU emulator - doesn't set carry if equal */ - switch(op) { - case TOK_ULT: - case TOK_UGE: - case TOK_ULE: - case TOK_UGT: - tcc_error("unsigned comparison on floats?"); - break; - case TOK_LT: - op=TOK_Nset; - break; - case TOK_LE: - op=TOK_ULE; /* correct in unordered case only if AC bit in FPSR set */ - break; - case TOK_EQ: - case TOK_NE: - x&=~0x400000; // cmfe -> cmf - break; - } - if(c1 && !c2) { - c2=c1; - vswap(); - switch(op) { - case TOK_Nset: - op=TOK_GT; - break; - case TOK_GE: - op=TOK_ULE; - break; - case TOK_ULE: - op=TOK_GE; - break; - case TOK_GT: - op=TOK_Nset; - break; - } - } - vswap(); - r=fpr(gv(RC_FLOAT)); - vswap(); - if(c2) { - if(c2>0xf) - x|=0x200000; - r2=c2&0xf; - } else { - r2=fpr(gv(RC_FLOAT)); -#ifdef CONFIG_TCC_BCHECK - if ((vtop[-1].r & VT_VALMASK) >= VT_CONST) { - vswap(); - r=fpr(gv(RC_FLOAT)); - vswap(); - } -#endif - } - --vtop; - vset_VT_CMP(op); - ++vtop; - } else { - tcc_error("unknown fp op %x!",op); - return; - } - } - if(vtop[-1].r == VT_CMP) - c1=15; - else { - c1=vtop->r; - if(r2&0x8) - c1=vtop[-1].r; - vtop[-1].r=get_reg_ex(RC_FLOAT,two2mask(vtop[-1].r,c1)); - c1=fpr(vtop[-1].r); - } - vtop--; - o(x|(r<<16)|(c1<<12)|r2); -} -#endif - -/* convert integers to fp 't' type. Must handle 'int', 'unsigned int' - and 'long long' cases. */ -ST_FUNC void gen_cvt_itof(int t) -{ - uint32_t r, r2; - int bt; - bt=vtop->type.t & VT_BTYPE; - if(bt == VT_INT || bt == VT_SHORT || bt == VT_BYTE) { -#ifndef TCC_ARM_VFP - uint32_t dsize = 0; -#endif - r=intr(gv(RC_INT)); -#ifdef TCC_ARM_VFP - r2=vfpr(vtop->r=get_reg(RC_FLOAT)); - o(0xEE000A10|(r<<12)|(r2<<16)); /* fmsr */ - r2|=r2<<12; - if(!(vtop->type.t & VT_UNSIGNED)) - r2|=0x80; /* fuitoX -> fsituX */ - o(0xEEB80A40|r2|T2CPR(t)); /* fYitoX*/ -#else - r2=fpr(vtop->r=get_reg(RC_FLOAT)); - if((t & VT_BTYPE) != VT_FLOAT) - dsize=0x80; /* flts -> fltd */ - o(0xEE000110|dsize|(r2<<16)|(r<<12)); /* flts */ - if((vtop->type.t & (VT_UNSIGNED|VT_BTYPE)) == (VT_UNSIGNED|VT_INT)) { - uint32_t off = 0; - o(0xE3500000|(r<<12)); /* cmp */ - r=fpr(get_reg(RC_FLOAT)); - if(last_itod_magic) { - off=ind+8-last_itod_magic; - off/=4; - if(off>255) - off=0; - } - o(0xBD1F0100|(r<<12)|off); /* ldflts */ - if(!off) { - o(0xEA000000); /* b */ - last_itod_magic=ind; - o(0x4F800000); /* 4294967296.0f */ - } - o(0xBE000100|dsize|(r2<<16)|(r2<<12)|r); /* adflt */ - } -#endif - return; - } else if(bt == VT_LLONG) { - int func; - CType *func_type = 0; - if((t & VT_BTYPE) == VT_FLOAT) { - func_type = &func_float_type; - if(vtop->type.t & VT_UNSIGNED) - func=TOK___floatundisf; - else - func=TOK___floatdisf; -#if LDOUBLE_SIZE != 8 - } else if((t & VT_BTYPE) == VT_LDOUBLE) { - func_type = &func_ldouble_type; - if(vtop->type.t & VT_UNSIGNED) - func=TOK___floatundixf; - else - func=TOK___floatdixf; - } else if((t & VT_BTYPE) == VT_DOUBLE) { -#else - } else if((t & VT_BTYPE) == VT_DOUBLE || (t & VT_BTYPE) == VT_LDOUBLE) { -#endif - func_type = &func_double_type; - if(vtop->type.t & VT_UNSIGNED) - func=TOK___floatundidf; - else - func=TOK___floatdidf; - } - if(func_type) { - vpushsym(func_type, external_helper_sym(func)); - vswap(); - gfunc_call(1); - vpushi(0); - vtop->r=TREG_F0; - return; - } - } - tcc_error("unimplemented gen_cvt_itof %x!",vtop->type.t); -} - -/* convert fp to int 't' type */ -void gen_cvt_ftoi(int t) -{ - uint32_t r, r2; - int u, func = 0; - u=t&VT_UNSIGNED; - t&=VT_BTYPE; - r2=vtop->type.t & VT_BTYPE; - if(t==VT_INT) { -#ifdef TCC_ARM_VFP - r=vfpr(gv(RC_FLOAT)); - u=u?0:0x10000; - o(0xEEBC0AC0|(r<<12)|r|T2CPR(r2)|u); /* ftoXizY */ - r2=intr(vtop->r=get_reg(RC_INT)); - o(0xEE100A10|(r<<16)|(r2<<12)); - return; -#else - if(u) { - if(r2 == VT_FLOAT) - func=TOK___fixunssfsi; -#if LDOUBLE_SIZE != 8 - else if(r2 == VT_LDOUBLE) - func=TOK___fixunsxfsi; - else if(r2 == VT_DOUBLE) -#else - else if(r2 == VT_LDOUBLE || r2 == VT_DOUBLE) -#endif - func=TOK___fixunsdfsi; - } else { - r=fpr(gv(RC_FLOAT)); - r2=intr(vtop->r=get_reg(RC_INT)); - o(0xEE100170|(r2<<12)|r); - return; - } -#endif - } else if(t == VT_LLONG) { // unsigned handled in gen_cvt_ftoi1 - if(r2 == VT_FLOAT) - func=TOK___fixsfdi; -#if LDOUBLE_SIZE != 8 - else if(r2 == VT_LDOUBLE) - func=TOK___fixxfdi; - else if(r2 == VT_DOUBLE) -#else - else if(r2 == VT_LDOUBLE || r2 == VT_DOUBLE) -#endif - func=TOK___fixdfdi; - } - if(func) { - vpush_helper_func(func); - vswap(); - gfunc_call(1); - vpushi(0); - if(t == VT_LLONG) - vtop->r2 = REG_IRE2; - vtop->r = REG_IRET; - return; - } - tcc_error("unimplemented gen_cvt_ftoi!"); -} - -/* convert from one floating point type to another */ -void gen_cvt_ftof(int t) -{ -#ifdef TCC_ARM_VFP - if(((vtop->type.t & VT_BTYPE) == VT_FLOAT) != ((t & VT_BTYPE) == VT_FLOAT)) { - uint32_t r = vfpr(gv(RC_FLOAT)); - o(0xEEB70AC0|(r<<12)|r|T2CPR(vtop->type.t)); - } -#else - /* all we have to do on i386 and FPA ARM is to put the float in a register */ - gv(RC_FLOAT); -#endif -} - -/* increment tcov counter */ -ST_FUNC void gen_increment_tcov (SValue *sv) -{ - int r1, r2; - - vpushv(sv); - vtop->r = r1 = get_reg(RC_INT); - r2 = get_reg(RC_INT); - o(0xE59F0000 | (intr(r1)<<12)); // ldr r1,[pc] - o(0xEA000000); // b $+4 - greloc(cur_text_section, sv->sym, ind, R_ARM_REL32); - o(-12); - o(0xe080000f | (intr(r1)<<16) | (intr(r1)<<12)); // add r1,r1,pc - o(0xe5900000 | (intr(r1)<<16) | (intr(r2)<<12)); // ldr r2, [r1] - o(0xe2900001 | (intr(r2)<<16) | (intr(r2)<<12)); // adds r2, r2, #1 - o(0xe5800000 | (intr(r1)<<16) | (intr(r2)<<12)); // str r2, [r1] - o(0xe2800004 | (intr(r1)<<16) | (intr(r1)<<12)); // add r1, r1, #4 - o(0xe5900000 | (intr(r1)<<16) | (intr(r2)<<12)); // ldr r2, [r1] - o(0xe2a00000 | (intr(r2)<<16) | (intr(r2)<<12)); // adc r2, r2, #0 - o(0xe5800000 | (intr(r1)<<16) | (intr(r2)<<12)); // str r2, [r1] - vpop(); -} - -/* computed goto support */ -void ggoto(void) -{ - gcall_or_jmp(1); - vtop--; -} - -/* Save the stack pointer onto the stack and return the location of its address */ -ST_FUNC void gen_vla_sp_save(int addr) { - SValue v; - v.type.t = VT_PTR; - v.r = VT_LOCAL | VT_LVAL; - v.c.i = addr; - store(TREG_SP, &v); -} - -/* Restore the SP from a location on the stack */ -ST_FUNC void gen_vla_sp_restore(int addr) { - SValue v; - v.type.t = VT_PTR; - v.r = VT_LOCAL | VT_LVAL; - v.c.i = addr; - load(TREG_SP, &v); -} - -/* Subtract from the stack pointer, and push the resulting value onto the stack */ -ST_FUNC void gen_vla_alloc(CType *type, int align) { - int r; -#if defined(CONFIG_TCC_BCHECK) - if (tcc_state->do_bounds_check) - vpushv(vtop); -#endif - r = intr(gv(RC_INT)); -#if defined(CONFIG_TCC_BCHECK) - if (tcc_state->do_bounds_check) - o(0xe2800001 | (r<<16)|(r<<12)); /* add r,r,#1 */ -#endif - o(0xE04D0000|(r<<12)|r); /* sub r, sp, r */ -#ifdef TCC_ARM_EABI - if (align < 8) - align = 8; -#else - if (align < 4) - align = 4; -#endif - if (align & (align - 1)) - tcc_error("alignment is not a power of 2: %i", align); - o(stuff_const(0xE3C0D000|(r<<16), align - 1)); /* bic sp, r, #align-1 */ - vpop(); -#if defined(CONFIG_TCC_BCHECK) - if (tcc_state->do_bounds_check) { - vpushi(0); - vtop->r = TREG_R0; - o(0xe1a0000d | (vtop->r << 12)); // mov r0,sp - vswap(); - vpush_helper_func(TOK___bound_new_region); - vrott(3); - gfunc_call(2); - func_bound_add_epilog = 1; - } -#endif -} - -/* end of ARM code generator */ -/*************************************************************/ -#endif -/*************************************************************/ diff --git a/05/tcc-final/arm-link.c b/05/tcc-final/arm-link.c deleted file mode 100644 index 18fc428..0000000 --- a/05/tcc-final/arm-link.c +++ /dev/null @@ -1,444 +0,0 @@ -#ifdef TARGET_DEFS_ONLY - -#define EM_TCC_TARGET EM_ARM - -/* relocation type for 32 bit data relocation */ -#define R_DATA_32 R_ARM_ABS32 -#define R_DATA_PTR R_ARM_ABS32 -#define R_JMP_SLOT R_ARM_JUMP_SLOT -#define R_GLOB_DAT R_ARM_GLOB_DAT -#define R_COPY R_ARM_COPY -#define R_RELATIVE R_ARM_RELATIVE - -#define R_NUM R_ARM_NUM - -#define ELF_START_ADDR 0x00010000 -#define ELF_PAGE_SIZE 0x10000 - -#define PCRELATIVE_DLLPLT 1 -#define RELOCATE_DLLPLT 1 - -enum float_abi { - ARM_SOFTFP_FLOAT, - ARM_HARD_FLOAT, -}; - -#else /* !TARGET_DEFS_ONLY */ - -#include "tcc.h" - -#ifdef NEED_RELOC_TYPE -/* Returns 1 for a code relocation, 0 for a data relocation. For unknown - relocations, returns -1. */ -int code_reloc (int reloc_type) -{ - switch (reloc_type) { - case R_ARM_MOVT_ABS: - case R_ARM_MOVW_ABS_NC: - case R_ARM_THM_MOVT_ABS: - case R_ARM_THM_MOVW_ABS_NC: - case R_ARM_ABS32: - case R_ARM_REL32: - case R_ARM_GOTPC: - case R_ARM_GOTOFF: - case R_ARM_GOT32: - case R_ARM_GOT_PREL: - case R_ARM_COPY: - case R_ARM_GLOB_DAT: - case R_ARM_NONE: - case R_ARM_TARGET1: - case R_ARM_MOVT_PREL: - case R_ARM_MOVW_PREL_NC: - return 0; - - case R_ARM_PC24: - case R_ARM_CALL: - case R_ARM_JUMP24: - case R_ARM_PLT32: - case R_ARM_THM_PC22: - case R_ARM_THM_JUMP24: - case R_ARM_PREL31: - case R_ARM_V4BX: - case R_ARM_JUMP_SLOT: - return 1; - } - return -1; -} - -/* Returns an enumerator to describe whether and when the relocation needs a - GOT and/or PLT entry to be created. See tcc.h for a description of the - different values. */ -int gotplt_entry_type (int reloc_type) -{ - switch (reloc_type) { - case R_ARM_NONE: - case R_ARM_COPY: - case R_ARM_GLOB_DAT: - case R_ARM_JUMP_SLOT: - return NO_GOTPLT_ENTRY; - - case R_ARM_PC24: - case R_ARM_CALL: - case R_ARM_JUMP24: - case R_ARM_PLT32: - case R_ARM_THM_PC22: - case R_ARM_THM_JUMP24: - case R_ARM_MOVT_ABS: - case R_ARM_MOVW_ABS_NC: - case R_ARM_THM_MOVT_ABS: - case R_ARM_THM_MOVW_ABS_NC: - case R_ARM_PREL31: - case R_ARM_ABS32: - case R_ARM_REL32: - case R_ARM_V4BX: - case R_ARM_TARGET1: - case R_ARM_MOVT_PREL: - case R_ARM_MOVW_PREL_NC: - return AUTO_GOTPLT_ENTRY; - - case R_ARM_GOTPC: - case R_ARM_GOTOFF: - return BUILD_GOT_ONLY; - - case R_ARM_GOT32: - case R_ARM_GOT_PREL: - return ALWAYS_GOTPLT_ENTRY; - } - return -1; -} - -#ifdef NEED_BUILD_GOT -ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr) -{ - Section *plt = s1->plt; - uint8_t *p; - unsigned plt_offset; - - /* when building a DLL, GOT entry accesses must be done relative to - start of GOT (see x86_64 example above) */ - - /* empty PLT: create PLT0 entry that push address of call site and - jump to ld.so resolution routine (GOT + 8) */ - if (plt->data_offset == 0) { - p = section_ptr_add(plt, 20); - write32le(p, 0xe52de004); /* push {lr} */ - write32le(p+4, 0xe59fe004); /* ldr lr, [pc, #4] */ - write32le(p+8, 0xe08fe00e); /* add lr, pc, lr */ - write32le(p+12, 0xe5bef008); /* ldr pc, [lr, #8]! */ - /* p+16 is set in relocate_plt */ - } - plt_offset = plt->data_offset; - - if (attr->plt_thumb_stub) { - p = section_ptr_add(plt, 4); - write32le(p, 0x4778); /* bx pc */ - write32le(p+2, 0x46c0); /* nop */ - } - p = section_ptr_add(plt, 16); - /* save GOT offset for relocate_plt */ - write32le(p + 4, got_offset); - return plt_offset; -} - -/* relocate the PLT: compute addresses and offsets in the PLT now that final - address for PLT and GOT are known (see fill_program_header) */ -ST_FUNC void relocate_plt(TCCState *s1) -{ - uint8_t *p, *p_end; - - if (!s1->plt) - return; - - p = s1->plt->data; - p_end = p + s1->plt->data_offset; - - if (p < p_end) { - int x = s1->got->sh_addr - s1->plt->sh_addr - 12; - write32le(s1->plt->data + 16, x - 4); - p += 20; - while (p < p_end) { - unsigned off = x + read32le(p + 4) + (s1->plt->data - p) + 4; - if (read32le(p) == 0x46c04778) /* PLT Thumb stub present */ - p += 4; - write32le(p, 0xe28fc200 | ((off >> 28) & 0xf)); // add ip, pc, #0xN0000000 - write32le(p + 4, 0xe28cc600 | ((off >> 20) & 0xff)); // add ip, pc, #0xNN00000 - write32le(p + 8, 0xe28cca00 | ((off >> 12) & 0xff)); // add ip, ip, #0xNN000 - write32le(p + 12, 0xe5bcf000 | (off & 0xfff)); // ldr pc, [ip, #0xNNN]! - p += 16; - } - } - - if (s1->plt->reloc) { - ElfW_Rel *rel; - p = s1->got->data; - for_each_elem(s1->plt->reloc, 0, rel, ElfW_Rel) { - write32le(p + rel->r_offset, s1->plt->sh_addr); - } - } -} -#endif -#endif - -void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val) -{ - ElfW(Sym) *sym; - int sym_index, esym_index; - - sym_index = ELFW(R_SYM)(rel->r_info); - sym = &((ElfW(Sym) *)symtab_section->data)[sym_index]; - - switch(type) { - case R_ARM_PC24: - case R_ARM_CALL: - case R_ARM_JUMP24: - case R_ARM_PLT32: - { - int x, is_thumb, is_call, h, blx_avail, is_bl, th_ko; - x = (*(int *) ptr) & 0xffffff; -#ifdef DEBUG_RELOC - printf ("reloc %d: x=0x%x val=0x%x ", type, x, val); -#endif - (*(int *)ptr) &= 0xff000000; - if (x & 0x800000) - x -= 0x1000000; - x <<= 2; - blx_avail = (TCC_CPU_VERSION >= 5); - is_thumb = val & 1; - is_bl = (*(unsigned *) ptr) >> 24 == 0xeb; - is_call = (type == R_ARM_CALL || (type == R_ARM_PC24 && is_bl)); - x += val - addr; -#ifdef DEBUG_RELOC - printf (" newx=0x%x name=%s\n", x, - (char *) symtab_section->link->data + sym->st_name); -#endif - h = x & 2; - th_ko = (x & 3) && (!blx_avail || !is_call); - if (th_ko || x >= 0x2000000 || x < -0x2000000) - tcc_error("can't relocate value at %x,%d",addr, type); - x >>= 2; - x &= 0xffffff; - /* Only reached if blx is avail and it is a call */ - if (is_thumb) { - x |= h << 24; - (*(int *)ptr) = 0xfa << 24; /* bl -> blx */ - } - (*(int *) ptr) |= x; - } - return; - /* Since these relocations only concern Thumb-2 and blx instruction was - introduced before Thumb-2, we can assume blx is available and not - guard its use */ - case R_ARM_THM_PC22: - case R_ARM_THM_JUMP24: - { - int x, hi, lo, s, j1, j2, i1, i2, imm10, imm11; - int to_thumb, is_call, to_plt, blx_bit = 1 << 12; - Section *plt; - - /* weak reference */ - if (sym->st_shndx == SHN_UNDEF && - ELFW(ST_BIND)(sym->st_info) == STB_WEAK) - return; - - /* Get initial offset */ - hi = (*(uint16_t *)ptr); - lo = (*(uint16_t *)(ptr+2)); - s = (hi >> 10) & 1; - j1 = (lo >> 13) & 1; - j2 = (lo >> 11) & 1; - i1 = (j1 ^ s) ^ 1; - i2 = (j2 ^ s) ^ 1; - imm10 = hi & 0x3ff; - imm11 = lo & 0x7ff; - x = (s << 24) | (i1 << 23) | (i2 << 22) | - (imm10 << 12) | (imm11 << 1); - if (x & 0x01000000) - x -= 0x02000000; - - /* Relocation infos */ - to_thumb = val & 1; - plt = s1->plt; - to_plt = (val >= plt->sh_addr) && - (val < plt->sh_addr + plt->data_offset); - is_call = (type == R_ARM_THM_PC22); - - if (!to_thumb && !to_plt && !is_call) { - int index; - uint8_t *p; - char *name, buf[1024]; - Section *text; - - name = (char *) symtab_section->link->data + sym->st_name; - text = s1->sections[sym->st_shndx]; - /* Modify reloc to target a thumb stub to switch to ARM */ - snprintf(buf, sizeof(buf), "%s_from_thumb", name); - index = put_elf_sym(symtab_section, - text->data_offset + 1, - sym->st_size, sym->st_info, 0, - sym->st_shndx, buf); - to_thumb = 1; - val = text->data_offset + 1; - rel->r_info = ELFW(R_INFO)(index, type); - /* Create a thumb stub function to switch to ARM mode */ - put_elf_reloc(symtab_section, text, - text->data_offset + 4, R_ARM_JUMP24, - sym_index); - p = section_ptr_add(text, 8); - write32le(p, 0x4778); /* bx pc */ - write32le(p+2, 0x46c0); /* nop */ - write32le(p+4, 0xeafffffe); /* b $sym */ - } - - /* Compute final offset */ - x += val - addr; - if (!to_thumb && is_call) { - blx_bit = 0; /* bl -> blx */ - x = (x + 3) & -4; /* Compute offset from aligned PC */ - } - - /* Check that relocation is possible - * offset must not be out of range - * if target is to be entered in arm mode: - - bit 1 must not set - - instruction must be a call (bl) or a jump to PLT */ - if (!to_thumb || x >= 0x1000000 || x < -0x1000000) - if (to_thumb || (val & 2) || (!is_call && !to_plt)) - tcc_error("can't relocate value at %x,%d",addr, type); - - /* Compute and store final offset */ - s = (x >> 24) & 1; - i1 = (x >> 23) & 1; - i2 = (x >> 22) & 1; - j1 = s ^ (i1 ^ 1); - j2 = s ^ (i2 ^ 1); - imm10 = (x >> 12) & 0x3ff; - imm11 = (x >> 1) & 0x7ff; - (*(uint16_t *)ptr) = (uint16_t) ((hi & 0xf800) | - (s << 10) | imm10); - (*(uint16_t *)(ptr+2)) = (uint16_t) ((lo & 0xc000) | - (j1 << 13) | blx_bit | (j2 << 11) | - imm11); - } - return; - case R_ARM_MOVT_ABS: - case R_ARM_MOVW_ABS_NC: - { - int x, imm4, imm12; - if (type == R_ARM_MOVT_ABS) - val >>= 16; - imm12 = val & 0xfff; - imm4 = (val >> 12) & 0xf; - x = (imm4 << 16) | imm12; - if (type == R_ARM_THM_MOVT_ABS) - *(int *)ptr |= x; - else - *(int *)ptr += x; - } - return; - case R_ARM_MOVT_PREL: - case R_ARM_MOVW_PREL_NC: - { - int insn = *(int *)ptr; - int addend = ((insn >> 4) & 0xf000) | (insn & 0xfff); - - addend = (addend ^ 0x8000) - 0x8000; - val += addend - addr; - if (type == R_ARM_MOVT_PREL) - val >>= 16; - *(int *)ptr = (insn & 0xfff0f000) | - ((val & 0xf000) << 4) | (val & 0xfff); - } - return; - case R_ARM_THM_MOVT_ABS: - case R_ARM_THM_MOVW_ABS_NC: - { - int x, i, imm4, imm3, imm8; - if (type == R_ARM_THM_MOVT_ABS) - val >>= 16; - imm8 = val & 0xff; - imm3 = (val >> 8) & 0x7; - i = (val >> 11) & 1; - imm4 = (val >> 12) & 0xf; - x = (imm3 << 28) | (imm8 << 16) | (i << 10) | imm4; - if (type == R_ARM_THM_MOVT_ABS) - *(int *)ptr |= x; - else - *(int *)ptr += x; - } - return; - case R_ARM_PREL31: - { - int x; - x = (*(int *)ptr) & 0x7fffffff; - (*(int *)ptr) &= 0x80000000; - x = (x * 2) / 2; - x += val - addr; - if((x^(x>>1))&0x40000000) - tcc_error("can't relocate value at %x,%d",addr, type); - (*(int *)ptr) |= x & 0x7fffffff; - } - return; - case R_ARM_ABS32: - case R_ARM_TARGET1: - if (s1->output_type == TCC_OUTPUT_DLL) { - esym_index = get_sym_attr(s1, sym_index, 0)->dyn_index; - qrel->r_offset = rel->r_offset; - if (esym_index) { - qrel->r_info = ELFW(R_INFO)(esym_index, R_ARM_ABS32); - qrel++; - return; - } else { - qrel->r_info = ELFW(R_INFO)(0, R_ARM_RELATIVE); - qrel++; - } - } - *(int *)ptr += val; - return; - case R_ARM_REL32: - *(int *)ptr += val - addr; - return; - case R_ARM_GOTPC: - *(int *)ptr += s1->got->sh_addr - addr; - return; - case R_ARM_GOTOFF: - *(int *)ptr += val - s1->got->sh_addr; - return; - case R_ARM_GOT32: - /* we load the got offset */ - *(int *)ptr += get_sym_attr(s1, sym_index, 0)->got_offset; - return; - case R_ARM_GOT_PREL: - /* we load the pc relative got offset */ - *(int *)ptr += s1->got->sh_addr + - get_sym_attr(s1, sym_index, 0)->got_offset - - addr; - return; - case R_ARM_COPY: - return; - case R_ARM_V4BX: - /* trade Thumb support for ARMv4 support */ - if ((0x0ffffff0 & *(int*)ptr) == 0x012FFF10) - *(int*)ptr ^= 0xE12FFF10 ^ 0xE1A0F000; /* BX Rm -> MOV PC, Rm */ - return; - case R_ARM_GLOB_DAT: - case R_ARM_JUMP_SLOT: - *(addr_t *)ptr = val; - return; - case R_ARM_NONE: - /* Nothing to do. Normally used to indicate a dependency - on a certain symbol (like for exception handling under EABI). */ - return; - case R_ARM_RELATIVE: -#ifdef TCC_TARGET_PE - add32le(ptr, val - s1->pe_imagebase); -#endif - /* do nothing */ - return; - default: - fprintf(stderr,"FIXME: handle reloc type %d at %x [%p] to %x\n", - type, (unsigned)addr, ptr, (unsigned)val); - return; - } -} - -#endif /* !TARGET_DEFS_ONLY */ diff --git a/05/tcc-final/arm-tok.h b/05/tcc-final/arm-tok.h deleted file mode 100644 index 297b105..0000000 --- a/05/tcc-final/arm-tok.h +++ /dev/null @@ -1,383 +0,0 @@ -/* ------------------------------------------------------------------ */ -/* WARNING: relative order of tokens is important. */ - -/* register */ - - DEF_ASM(r0) - DEF_ASM(r1) - DEF_ASM(r2) - DEF_ASM(r3) - DEF_ASM(r4) - DEF_ASM(r5) - DEF_ASM(r6) - DEF_ASM(r7) - DEF_ASM(r8) - DEF_ASM(r9) - DEF_ASM(r10) - DEF_ASM(r11) /* fp */ - DEF_ASM(r12) /* ip[c] */ - DEF_ASM(r13) /* sp */ - DEF_ASM(r14) /* lr */ - DEF_ASM(r15) /* pc */ - -/* register macros */ - - DEF_ASM(fp) /* alias for r11 */ - DEF_ASM(ip) /* alias for r12 */ - DEF_ASM(sp) /* alias for r13 */ - DEF_ASM(lr) /* alias for r14 */ - DEF_ASM(pc) /* alias for r15 */ - - /* coprocessors */ - - DEF_ASM(p0) - DEF_ASM(p1) - DEF_ASM(p2) - DEF_ASM(p3) - DEF_ASM(p4) - DEF_ASM(p5) - DEF_ASM(p6) - DEF_ASM(p7) - DEF_ASM(p8) - DEF_ASM(p9) - DEF_ASM(p10) - DEF_ASM(p11) - DEF_ASM(p12) - DEF_ASM(p13) - DEF_ASM(p14) - DEF_ASM(p15) - - /* coprocessor registers */ - - DEF_ASM(c0) - DEF_ASM(c1) - DEF_ASM(c2) - DEF_ASM(c3) - DEF_ASM(c4) - DEF_ASM(c5) - DEF_ASM(c6) - DEF_ASM(c7) - DEF_ASM(c8) - DEF_ASM(c9) - DEF_ASM(c10) - DEF_ASM(c11) - DEF_ASM(c12) - DEF_ASM(c13) - DEF_ASM(c14) - DEF_ASM(c15) - - /* single-precision VFP registers */ - - DEF_ASM(s0) - DEF_ASM(s1) - DEF_ASM(s2) - DEF_ASM(s3) - DEF_ASM(s4) - DEF_ASM(s5) - DEF_ASM(s6) - DEF_ASM(s7) - DEF_ASM(s8) - DEF_ASM(s9) - DEF_ASM(s10) - DEF_ASM(s11) - DEF_ASM(s12) - DEF_ASM(s13) - DEF_ASM(s14) - DEF_ASM(s15) - DEF_ASM(s16) - DEF_ASM(s17) - DEF_ASM(s18) - DEF_ASM(s19) - DEF_ASM(s20) - DEF_ASM(s21) - DEF_ASM(s22) - DEF_ASM(s23) - DEF_ASM(s24) - DEF_ASM(s25) - DEF_ASM(s26) - DEF_ASM(s27) - DEF_ASM(s28) - DEF_ASM(s29) - DEF_ASM(s30) - DEF_ASM(s31) - - /* double-precision VFP registers */ - - DEF_ASM(d0) - DEF_ASM(d1) - DEF_ASM(d2) - DEF_ASM(d3) - DEF_ASM(d4) - DEF_ASM(d5) - DEF_ASM(d6) - DEF_ASM(d7) - DEF_ASM(d8) - DEF_ASM(d9) - DEF_ASM(d10) - DEF_ASM(d11) - DEF_ASM(d12) - DEF_ASM(d13) - DEF_ASM(d14) - DEF_ASM(d15) - - /* VFP status registers */ - - DEF_ASM(fpsid) - DEF_ASM(fpscr) - DEF_ASM(fpexc) - - /* VFP magical ARM register */ - - DEF_ASM(apsr_nzcv) - - /* data processing directives */ - - DEF_ASM(asl) - - /* instructions that have no condition code */ - - DEF_ASM(cdp2) - DEF_ASM(ldc2) - DEF_ASM(ldc2l) - DEF_ASM(stc2) - DEF_ASM(stc2l) - -#define ARM_INSTRUCTION_GROUP(tok) ((((tok) - TOK_ASM_nopeq) & 0xFFFFFFF0) + TOK_ASM_nopeq) - -/* Note: condition code is 4 bits */ -#define DEF_ASM_CONDED(x) \ - DEF(TOK_ASM_ ## x ## eq, #x "eq") \ - DEF(TOK_ASM_ ## x ## ne, #x "ne") \ - DEF(TOK_ASM_ ## x ## cs, #x "cs") \ - DEF(TOK_ASM_ ## x ## cc, #x "cc") \ - DEF(TOK_ASM_ ## x ## mi, #x "mi") \ - DEF(TOK_ASM_ ## x ## pl, #x "pl") \ - DEF(TOK_ASM_ ## x ## vs, #x "vs") \ - DEF(TOK_ASM_ ## x ## vc, #x "vc") \ - DEF(TOK_ASM_ ## x ## hi, #x "hi") \ - DEF(TOK_ASM_ ## x ## ls, #x "ls") \ - DEF(TOK_ASM_ ## x ## ge, #x "ge") \ - DEF(TOK_ASM_ ## x ## lt, #x "lt") \ - DEF(TOK_ASM_ ## x ## gt, #x "gt") \ - DEF(TOK_ASM_ ## x ## le, #x "le") \ - DEF(TOK_ASM_ ## x, #x) \ - DEF(TOK_ASM_ ## x ## rsvd, #x "rsvd") - -/* Note: condition code is 4 bits */ -#define DEF_ASM_CONDED_WITH_SUFFIX(x, y) \ - DEF(TOK_ASM_ ## x ## eq ## _ ## y, #x "eq." #y) \ - DEF(TOK_ASM_ ## x ## ne ## _ ## y, #x "ne." #y) \ - DEF(TOK_ASM_ ## x ## cs ## _ ## y, #x "cs." #y) \ - DEF(TOK_ASM_ ## x ## cc ## _ ## y, #x "cc." #y) \ - DEF(TOK_ASM_ ## x ## mi ## _ ## y, #x "mi." #y) \ - DEF(TOK_ASM_ ## x ## pl ## _ ## y, #x "pl." #y) \ - DEF(TOK_ASM_ ## x ## vs ## _ ## y, #x "vs." #y) \ - DEF(TOK_ASM_ ## x ## vc ## _ ## y, #x "vc." #y) \ - DEF(TOK_ASM_ ## x ## hi ## _ ## y, #x "hi." #y) \ - DEF(TOK_ASM_ ## x ## ls ## _ ## y, #x "ls." #y) \ - DEF(TOK_ASM_ ## x ## ge ## _ ## y, #x "ge." #y) \ - DEF(TOK_ASM_ ## x ## lt ## _ ## y, #x "lt." #y) \ - DEF(TOK_ASM_ ## x ## gt ## _ ## y, #x "gt." #y) \ - DEF(TOK_ASM_ ## x ## le ## _ ## y, #x "le." #y) \ - DEF(TOK_ASM_ ## x ## _ ## y, #x "." #y) \ - DEF(TOK_ASM_ ## x ## rsvd ## _ ## y, #x "rsvd." #y) - -#define DEF_ASM_CONDED_VFP_F32_F64(x) \ - DEF_ASM_CONDED_WITH_SUFFIX(x, f32) \ - DEF_ASM_CONDED_WITH_SUFFIX(x, f64) - -#define DEF_ASM_CONDED_WITH_TWO_SUFFIXES(x, y, z) \ - DEF(TOK_ASM_ ## x ## eq ## _ ## y ## _ ## z, #x "eq." #y "." #z) \ - DEF(TOK_ASM_ ## x ## ne ## _ ## y ## _ ## z, #x "ne." #y "." #z) \ - DEF(TOK_ASM_ ## x ## cs ## _ ## y ## _ ## z, #x "cs." #y "." #z) \ - DEF(TOK_ASM_ ## x ## cc ## _ ## y ## _ ## z, #x "cc." #y "." #z) \ - DEF(TOK_ASM_ ## x ## mi ## _ ## y ## _ ## z, #x "mi." #y "." #z) \ - DEF(TOK_ASM_ ## x ## pl ## _ ## y ## _ ## z, #x "pl." #y "." #z) \ - DEF(TOK_ASM_ ## x ## vs ## _ ## y ## _ ## z, #x "vs." #y "." #z) \ - DEF(TOK_ASM_ ## x ## vc ## _ ## y ## _ ## z, #x "vc." #y "." #z) \ - DEF(TOK_ASM_ ## x ## hi ## _ ## y ## _ ## z, #x "hi." #y "." #z) \ - DEF(TOK_ASM_ ## x ## ls ## _ ## y ## _ ## z, #x "ls." #y "." #z) \ - DEF(TOK_ASM_ ## x ## ge ## _ ## y ## _ ## z, #x "ge." #y "." #z) \ - DEF(TOK_ASM_ ## x ## lt ## _ ## y ## _ ## z, #x "lt." #y "." #z) \ - DEF(TOK_ASM_ ## x ## gt ## _ ## y ## _ ## z, #x "gt." #y "." #z) \ - DEF(TOK_ASM_ ## x ## le ## _ ## y ## _ ## z, #x "le." #y "." #z) \ - DEF(TOK_ASM_ ## x ## _ ## y ## _ ## z, #x "." #y "." #z) \ - DEF(TOK_ASM_ ## x ## rsvd ## _ ## y ## _ ## z, #x "rsvd." #y "." #z) - -/* Note: add new tokens after nop (MUST always use DEF_ASM_CONDED) */ - - DEF_ASM_CONDED(nop) - DEF_ASM_CONDED(wfe) - DEF_ASM_CONDED(wfi) - DEF_ASM_CONDED(swi) - DEF_ASM_CONDED(svc) - - /* misc */ - DEF_ASM_CONDED(clz) - - /* size conversion */ - - DEF_ASM_CONDED(sxtb) - DEF_ASM_CONDED(sxth) - DEF_ASM_CONDED(uxtb) - DEF_ASM_CONDED(uxth) - DEF_ASM_CONDED(movt) - DEF_ASM_CONDED(movw) - - /* multiplication */ - - DEF_ASM_CONDED(mul) - DEF_ASM_CONDED(muls) - DEF_ASM_CONDED(mla) - DEF_ASM_CONDED(mlas) - DEF_ASM_CONDED(smull) - DEF_ASM_CONDED(smulls) - DEF_ASM_CONDED(umull) - DEF_ASM_CONDED(umulls) - DEF_ASM_CONDED(smlal) - DEF_ASM_CONDED(smlals) - DEF_ASM_CONDED(umlal) - DEF_ASM_CONDED(umlals) - - /* load/store */ - - DEF_ASM_CONDED(ldr) - DEF_ASM_CONDED(ldrb) - DEF_ASM_CONDED(str) - DEF_ASM_CONDED(strb) - DEF_ASM_CONDED(ldrex) - DEF_ASM_CONDED(ldrexb) - DEF_ASM_CONDED(strex) - DEF_ASM_CONDED(strexb) - DEF_ASM_CONDED(ldrh) - DEF_ASM_CONDED(ldrsh) - DEF_ASM_CONDED(ldrsb) - DEF_ASM_CONDED(strh) - - DEF_ASM_CONDED(stmda) - DEF_ASM_CONDED(ldmda) - DEF_ASM_CONDED(stm) - DEF_ASM_CONDED(ldm) - DEF_ASM_CONDED(stmia) - DEF_ASM_CONDED(ldmia) - DEF_ASM_CONDED(stmdb) - DEF_ASM_CONDED(ldmdb) - DEF_ASM_CONDED(stmib) - DEF_ASM_CONDED(ldmib) - - DEF_ASM_CONDED(ldc) - DEF_ASM_CONDED(ldcl) - DEF_ASM_CONDED(stc) - DEF_ASM_CONDED(stcl) - - /* instruction macros */ - - DEF_ASM_CONDED(push) - DEF_ASM_CONDED(pop) - - /* branches */ - - DEF_ASM_CONDED(b) - DEF_ASM_CONDED(bl) - DEF_ASM_CONDED(bx) - DEF_ASM_CONDED(blx) - - /* data processing instructions; order is important */ - - DEF_ASM_CONDED(and) - DEF_ASM_CONDED(ands) - DEF_ASM_CONDED(eor) - DEF_ASM_CONDED(eors) - DEF_ASM_CONDED(sub) - DEF_ASM_CONDED(subs) - DEF_ASM_CONDED(rsb) - DEF_ASM_CONDED(rsbs) - DEF_ASM_CONDED(add) - DEF_ASM_CONDED(adds) - DEF_ASM_CONDED(adc) - DEF_ASM_CONDED(adcs) - DEF_ASM_CONDED(sbc) - DEF_ASM_CONDED(sbcs) - DEF_ASM_CONDED(rsc) - DEF_ASM_CONDED(rscs) - DEF_ASM_CONDED(tst) - DEF_ASM_CONDED(tsts) // necessary here--but not useful to the user - DEF_ASM_CONDED(teq) - DEF_ASM_CONDED(teqs) // necessary here--but not useful to the user - DEF_ASM_CONDED(cmp) - DEF_ASM_CONDED(cmps) // necessary here--but not useful to the user - DEF_ASM_CONDED(cmn) - DEF_ASM_CONDED(cmns) // necessary here--but not useful to the user - DEF_ASM_CONDED(orr) - DEF_ASM_CONDED(orrs) - DEF_ASM_CONDED(mov) - DEF_ASM_CONDED(movs) - DEF_ASM_CONDED(bic) - DEF_ASM_CONDED(bics) - DEF_ASM_CONDED(mvn) - DEF_ASM_CONDED(mvns) - - DEF_ASM_CONDED(lsl) - DEF_ASM_CONDED(lsls) - DEF_ASM_CONDED(lsr) - DEF_ASM_CONDED(lsrs) - DEF_ASM_CONDED(asr) - DEF_ASM_CONDED(asrs) - DEF_ASM_CONDED(ror) - DEF_ASM_CONDED(rors) - DEF_ASM_CONDED(rrx) - DEF_ASM_CONDED(rrxs) - - DEF_ASM_CONDED(cdp) - DEF_ASM_CONDED(mcr) - DEF_ASM_CONDED(mrc) - - // Floating point high-level instructions - - DEF_ASM_CONDED(vldr) - DEF_ASM_CONDED(vstr) - - DEF_ASM_CONDED_VFP_F32_F64(vmla) - DEF_ASM_CONDED_VFP_F32_F64(vmls) - DEF_ASM_CONDED_VFP_F32_F64(vnmls) - DEF_ASM_CONDED_VFP_F32_F64(vnmla) - DEF_ASM_CONDED_VFP_F32_F64(vmul) - DEF_ASM_CONDED_VFP_F32_F64(vnmul) - DEF_ASM_CONDED_VFP_F32_F64(vadd) - DEF_ASM_CONDED_VFP_F32_F64(vsub) - DEF_ASM_CONDED_VFP_F32_F64(vdiv) - DEF_ASM_CONDED_VFP_F32_F64(vneg) - DEF_ASM_CONDED_VFP_F32_F64(vabs) - DEF_ASM_CONDED_VFP_F32_F64(vsqrt) - DEF_ASM_CONDED_VFP_F32_F64(vcmp) - DEF_ASM_CONDED_VFP_F32_F64(vcmpe) - DEF_ASM_CONDED_VFP_F32_F64(vmov) - - DEF_ASM_CONDED_WITH_TWO_SUFFIXES(vcvtr, s32, f64) - DEF_ASM_CONDED_WITH_TWO_SUFFIXES(vcvtr, s32, f32) - DEF_ASM_CONDED_WITH_TWO_SUFFIXES(vcvtr, u32, f64) - DEF_ASM_CONDED_WITH_TWO_SUFFIXES(vcvtr, u32, f32) - - DEF_ASM_CONDED_WITH_TWO_SUFFIXES(vcvt, s32, f64) - DEF_ASM_CONDED_WITH_TWO_SUFFIXES(vcvt, s32, f32) - DEF_ASM_CONDED_WITH_TWO_SUFFIXES(vcvt, u32, f64) - DEF_ASM_CONDED_WITH_TWO_SUFFIXES(vcvt, u32, f32) - - DEF_ASM_CONDED_WITH_TWO_SUFFIXES(vcvt, f64, s32) - DEF_ASM_CONDED_WITH_TWO_SUFFIXES(vcvt, f32, s32) - DEF_ASM_CONDED_WITH_TWO_SUFFIXES(vcvt, f64, u32) - DEF_ASM_CONDED_WITH_TWO_SUFFIXES(vcvt, f32, u32) - - DEF_ASM_CONDED_WITH_TWO_SUFFIXES(vcvt, f64, f32) - DEF_ASM_CONDED_WITH_TWO_SUFFIXES(vcvt, f32, f64) - - DEF_ASM_CONDED(vpush) - DEF_ASM_CONDED(vpop) - DEF_ASM_CONDED(vldm) - DEF_ASM_CONDED(vldmia) - DEF_ASM_CONDED(vldmdb) - DEF_ASM_CONDED(vstm) - DEF_ASM_CONDED(vstmia) - DEF_ASM_CONDED(vstmdb) - DEF_ASM_CONDED(vmsr) - DEF_ASM_CONDED(vmrs) diff --git a/05/tcc-final/arm64-asm.c b/05/tcc-final/arm64-asm.c deleted file mode 100644 index a97fd64..0000000 --- a/05/tcc-final/arm64-asm.c +++ /dev/null @@ -1,94 +0,0 @@ -/*************************************************************/ -/* - * ARM64 dummy assembler for TCC - * - */ - -#ifdef TARGET_DEFS_ONLY - -#define CONFIG_TCC_ASM -#define NB_ASM_REGS 16 - -ST_FUNC void g(int c); -ST_FUNC void gen_le16(int c); -ST_FUNC void gen_le32(int c); - -/*************************************************************/ -#else -/*************************************************************/ -#define USING_GLOBALS -#include "tcc.h" - -static void asm_error(void) -{ - tcc_error("ARM asm not implemented."); -} - -/* XXX: make it faster ? */ -ST_FUNC void g(int c) -{ - int ind1; - if (nocode_wanted) - return; - ind1 = ind + 1; - if (ind1 > cur_text_section->data_allocated) - section_realloc(cur_text_section, ind1); - cur_text_section->data[ind] = c; - ind = ind1; -} - -ST_FUNC void gen_le16 (int i) -{ - g(i); - g(i>>8); -} - -ST_FUNC void gen_le32 (int i) -{ - gen_le16(i); - gen_le16(i>>16); -} - -ST_FUNC void gen_expr32(ExprValue *pe) -{ - gen_le32(pe->v); -} - -ST_FUNC void asm_opcode(TCCState *s1, int opcode) -{ - asm_error(); -} - -ST_FUNC void subst_asm_operand(CString *add_str, SValue *sv, int modifier) -{ - asm_error(); -} - -/* generate prolog and epilog code for asm statement */ -ST_FUNC void asm_gen_code(ASMOperand *operands, int nb_operands, - int nb_outputs, int is_output, - uint8_t *clobber_regs, - int out_reg) -{ -} - -ST_FUNC void asm_compute_constraints(ASMOperand *operands, - int nb_operands, int nb_outputs, - const uint8_t *clobber_regs, - int *pout_reg) -{ -} - -ST_FUNC void asm_clobber(uint8_t *clobber_regs, const char *str) -{ - asm_error(); -} - -ST_FUNC int asm_parse_regvar (int t) -{ - asm_error(); - return -1; -} - -/*************************************************************/ -#endif /* ndef TARGET_DEFS_ONLY */ diff --git a/05/tcc-final/arm64-gen.c b/05/tcc-final/arm64-gen.c deleted file mode 100644 index 8232f2a..0000000 --- a/05/tcc-final/arm64-gen.c +++ /dev/null @@ -1,2141 +0,0 @@ -/* - * A64 code generator for TCC - * - * Copyright (c) 2014-2015 Edmund Grimley Evans - * - * Copying and distribution of this file, with or without modification, - * are permitted in any medium without royalty provided the copyright - * notice and this notice are preserved. This file is offered as-is, - * without any warranty. - */ - -#ifdef TARGET_DEFS_ONLY - -// Number of registers available to allocator: -#define NB_REGS 28 // x0-x18, x30, v0-v7 - -#define TREG_R(x) (x) // x = 0..18 -#define TREG_R30 19 -#define TREG_F(x) (x + 20) // x = 0..7 - -// Register classes sorted from more general to more precise: -#define RC_INT (1 << 0) -#define RC_FLOAT (1 << 1) -#define RC_R(x) (1 << (2 + (x))) // x = 0..18 -#define RC_R30 (1 << 21) -#define RC_F(x) (1 << (22 + (x))) // x = 0..7 - -#define RC_IRET (RC_R(0)) // int return register class -#define RC_FRET (RC_F(0)) // float return register class - -#define REG_IRET (TREG_R(0)) // int return register number -#define REG_FRET (TREG_F(0)) // float return register number - -#define PTR_SIZE 8 - -#define LDOUBLE_SIZE 16 -#define LDOUBLE_ALIGN 16 - -#define MAX_ALIGN 16 - -#define CHAR_IS_UNSIGNED - -/* define if return values need to be extended explicitely - at caller side (for interfacing with non-TCC compilers) */ -#define PROMOTE_RET -/******************************************************/ -#else /* ! TARGET_DEFS_ONLY */ -/******************************************************/ -#define USING_GLOBALS -#include "tcc.h" -#include - -ST_DATA const char * const target_machine_defs = -#if defined(__APPLE__) - "__aarch64__\0" - "__arm64__\0" -#else - "__aarch64__\0" -#endif - ; - -ST_DATA const int reg_classes[NB_REGS] = { - RC_INT | RC_R(0), - RC_INT | RC_R(1), - RC_INT | RC_R(2), - RC_INT | RC_R(3), - RC_INT | RC_R(4), - RC_INT | RC_R(5), - RC_INT | RC_R(6), - RC_INT | RC_R(7), - RC_INT | RC_R(8), - RC_INT | RC_R(9), - RC_INT | RC_R(10), - RC_INT | RC_R(11), - RC_INT | RC_R(12), - RC_INT | RC_R(13), - RC_INT | RC_R(14), - RC_INT | RC_R(15), - RC_INT | RC_R(16), - RC_INT | RC_R(17), - RC_INT | RC_R(18), - RC_R30, // not in RC_INT as we make special use of x30 - RC_FLOAT | RC_F(0), - RC_FLOAT | RC_F(1), - RC_FLOAT | RC_F(2), - RC_FLOAT | RC_F(3), - RC_FLOAT | RC_F(4), - RC_FLOAT | RC_F(5), - RC_FLOAT | RC_F(6), - RC_FLOAT | RC_F(7) -}; - -#if defined(CONFIG_TCC_BCHECK) -static addr_t func_bound_offset; -static unsigned long func_bound_ind; -ST_DATA int func_bound_add_epilog; -#endif - -#define IS_FREG(x) ((x) >= TREG_F(0)) - -static uint32_t intr(int r) -{ - assert(TREG_R(0) <= r && r <= TREG_R30); - return r < TREG_R30 ? r : 30; -} - -static uint32_t fltr(int r) -{ - assert(TREG_F(0) <= r && r <= TREG_F(7)); - return r - TREG_F(0); -} - -// Add an instruction to text section: -ST_FUNC void o(unsigned int c) -{ - int ind1 = ind + 4; - if (nocode_wanted) - return; - if (ind1 > cur_text_section->data_allocated) - section_realloc(cur_text_section, ind1); - write32le(cur_text_section->data + ind, c); - ind = ind1; -} - -static int arm64_encode_bimm64(uint64_t x) -{ - int neg = x & 1; - int rep, pos, len; - - if (neg) - x = ~x; - if (!x) - return -1; - - if (x >> 2 == (x & (((uint64_t)1 << (64 - 2)) - 1))) - rep = 2, x &= ((uint64_t)1 << 2) - 1; - else if (x >> 4 == (x & (((uint64_t)1 << (64 - 4)) - 1))) - rep = 4, x &= ((uint64_t)1 << 4) - 1; - else if (x >> 8 == (x & (((uint64_t)1 << (64 - 8)) - 1))) - rep = 8, x &= ((uint64_t)1 << 8) - 1; - else if (x >> 16 == (x & (((uint64_t)1 << (64 - 16)) - 1))) - rep = 16, x &= ((uint64_t)1 << 16) - 1; - else if (x >> 32 == (x & (((uint64_t)1 << (64 - 32)) - 1))) - rep = 32, x &= ((uint64_t)1 << 32) - 1; - else - rep = 64; - - pos = 0; - if (!(x & (((uint64_t)1 << 32) - 1))) x >>= 32, pos += 32; - if (!(x & (((uint64_t)1 << 16) - 1))) x >>= 16, pos += 16; - if (!(x & (((uint64_t)1 << 8) - 1))) x >>= 8, pos += 8; - if (!(x & (((uint64_t)1 << 4) - 1))) x >>= 4, pos += 4; - if (!(x & (((uint64_t)1 << 2) - 1))) x >>= 2, pos += 2; - if (!(x & (((uint64_t)1 << 1) - 1))) x >>= 1, pos += 1; - - len = 0; - if (!(~x & (((uint64_t)1 << 32) - 1))) x >>= 32, len += 32; - if (!(~x & (((uint64_t)1 << 16) - 1))) x >>= 16, len += 16; - if (!(~x & (((uint64_t)1 << 8) - 1))) x >>= 8, len += 8; - if (!(~x & (((uint64_t)1 << 4) - 1))) x >>= 4, len += 4; - if (!(~x & (((uint64_t)1 << 2) - 1))) x >>= 2, len += 2; - if (!(~x & (((uint64_t)1 << 1) - 1))) x >>= 1, len += 1; - - if (x) - return -1; - if (neg) { - pos = (pos + len) & (rep - 1); - len = rep - len; - } - return ((0x1000 & rep << 6) | (((rep - 1) ^ 31) << 1 & 63) | - ((rep - pos) & (rep - 1)) << 6 | (len - 1)); -} - -static uint32_t arm64_movi(int r, uint64_t x) -{ - uint64_t m = 0xffff; - int e; - if (!(x & ~m)) - return 0x52800000 | r | x << 5; // movz w(r),#(x) - if (!(x & ~(m << 16))) - return 0x52a00000 | r | x >> 11; // movz w(r),#(x >> 16),lsl #16 - if (!(x & ~(m << 32))) - return 0xd2c00000 | r | x >> 27; // movz x(r),#(x >> 32),lsl #32 - if (!(x & ~(m << 48))) - return 0xd2e00000 | r | x >> 43; // movz x(r),#(x >> 48),lsl #48 - if ((x & ~m) == m << 16) - return (0x12800000 | r | - (~x << 5 & 0x1fffe0)); // movn w(r),#(~x) - if ((x & ~(m << 16)) == m) - return (0x12a00000 | r | - (~x >> 11 & 0x1fffe0)); // movn w(r),#(~x >> 16),lsl #16 - if (!~(x | m)) - return (0x92800000 | r | - (~x << 5 & 0x1fffe0)); // movn x(r),#(~x) - if (!~(x | m << 16)) - return (0x92a00000 | r | - (~x >> 11 & 0x1fffe0)); // movn x(r),#(~x >> 16),lsl #16 - if (!~(x | m << 32)) - return (0x92c00000 | r | - (~x >> 27 & 0x1fffe0)); // movn x(r),#(~x >> 32),lsl #32 - if (!~(x | m << 48)) - return (0x92e00000 | r | - (~x >> 43 & 0x1fffe0)); // movn x(r),#(~x >> 32),lsl #32 - if (!(x >> 32) && (e = arm64_encode_bimm64(x | x << 32)) >= 0) - return 0x320003e0 | r | (uint32_t)e << 10; // movi w(r),#(x) - if ((e = arm64_encode_bimm64(x)) >= 0) - return 0xb20003e0 | r | (uint32_t)e << 10; // movi x(r),#(x) - return 0; -} - -static void arm64_movimm(int r, uint64_t x) -{ - uint32_t i; - if ((i = arm64_movi(r, x))) - o(i); // a single MOV - else { - // MOVZ/MOVN and 1-3 MOVKs - int z = 0, m = 0; - uint32_t mov1 = 0xd2800000; // movz - uint64_t x1 = x; - for (i = 0; i < 64; i += 16) { - z += !(x >> i & 0xffff); - m += !(~x >> i & 0xffff); - } - if (m > z) { - x1 = ~x; - mov1 = 0x92800000; // movn - } - for (i = 0; i < 64; i += 16) - if (x1 >> i & 0xffff) { - o(mov1 | r | (x1 >> i & 0xffff) << 5 | i << 17); - // movz/movn x(r),#(*),lsl #(i) - break; - } - for (i += 16; i < 64; i += 16) - if (x1 >> i & 0xffff) - o(0xf2800000 | r | (x >> i & 0xffff) << 5 | i << 17); - // movk x(r),#(*),lsl #(i) - } -} - -// Patch all branches in list pointed to by t to branch to a: -ST_FUNC void gsym_addr(int t_, int a_) -{ - uint32_t t = t_; - uint32_t a = a_; - while (t) { - unsigned char *ptr = cur_text_section->data + t; - uint32_t next = read32le(ptr); - if (a - t + 0x8000000 >= 0x10000000) - tcc_error("branch out of range"); - write32le(ptr, (a - t == 4 ? 0xd503201f : // nop - 0x14000000 | ((a - t) >> 2 & 0x3ffffff))); // b - t = next; - } -} - -static int arm64_type_size(int t) -{ - /* - * case values are in increasing order (from 1 to 11). - * which 'may' help compiler optimizers. See tcc.h - */ - switch (t & VT_BTYPE) { - case VT_BYTE: return 0; - case VT_SHORT: return 1; - case VT_INT: return 2; - case VT_LLONG: return 3; - case VT_PTR: return 3; - case VT_FUNC: return 3; - case VT_STRUCT: return 3; - case VT_FLOAT: return 2; - case VT_DOUBLE: return 3; - case VT_LDOUBLE: return 4; - case VT_BOOL: return 0; - } - assert(0); - return 0; -} - -static void arm64_spoff(int reg, uint64_t off) -{ - uint32_t sub = off >> 63; - if (sub) - off = -off; - if (off < 4096) - o(0x910003e0 | sub << 30 | reg | off << 10); - // (add|sub) x(reg),sp,#(off) - else { - arm64_movimm(30, off); // use x30 for offset - o(0x8b3e63e0 | sub << 30 | reg); // (add|sub) x(reg),sp,x30 - } -} - -/* invert 0: return value to use for store/load */ -/* invert 1: return value to use for arm64_sym */ -static uint64_t arm64_check_offset(int invert, int sz_, uint64_t off) -{ - uint32_t sz = sz_; - if (!(off & ~((uint32_t)0xfff << sz)) || - (off < 256 || -off <= 256)) - return invert ? off : 0ul; - else if ((off & ((uint32_t)0xfff << sz))) - return invert ? off & ((uint32_t)0xfff << sz) - : off & ~((uint32_t)0xfff << sz); - else if (off & 0x1ff) - return invert ? off & 0x1ff : off & ~0x1ff; - else - return invert ? 0ul : off; -} - -static void arm64_ldrx(int sg, int sz_, int dst, int bas, uint64_t off) -{ - uint32_t sz = sz_; - if (sz >= 2) - sg = 0; - if (!(off & ~((uint32_t)0xfff << sz))) - o(0x39400000 | dst | bas << 5 | off << (10 - sz) | - (uint32_t)!!sg << 23 | sz << 30); // ldr(*) x(dst),[x(bas),#(off)] - else if (off < 256 || -off <= 256) - o(0x38400000 | dst | bas << 5 | (off & 511) << 12 | - (uint32_t)!!sg << 23 | sz << 30); // ldur(*) x(dst),[x(bas),#(off)] - else { - arm64_movimm(30, off); // use x30 for offset - o(0x38206800 | dst | bas << 5 | (uint32_t)30 << 16 | - (uint32_t)(!!sg + 1) << 22 | sz << 30); // ldr(*) x(dst),[x(bas),x30] - } -} - -static void arm64_ldrv(int sz_, int dst, int bas, uint64_t off) -{ - uint32_t sz = sz_; - if (!(off & ~((uint32_t)0xfff << sz))) - o(0x3d400000 | dst | bas << 5 | off << (10 - sz) | - (sz & 4) << 21 | (sz & 3) << 30); // ldr (s|d|q)(dst),[x(bas),#(off)] - else if (off < 256 || -off <= 256) - o(0x3c400000 | dst | bas << 5 | (off & 511) << 12 | - (sz & 4) << 21 | (sz & 3) << 30); // ldur (s|d|q)(dst),[x(bas),#(off)] - else { - arm64_movimm(30, off); // use x30 for offset - o(0x3c606800 | dst | bas << 5 | (uint32_t)30 << 16 | - sz << 30 | (sz & 4) << 21); // ldr (s|d|q)(dst),[x(bas),x30] - } -} - -static void arm64_ldrs(int reg_, int size) -{ - uint32_t reg = reg_; - // Use x30 for intermediate value in some cases. - switch (size) { - default: assert(0); break; - case 0: - /* Can happen with zero size structs */ - break; - case 1: - arm64_ldrx(0, 0, reg, reg, 0); - break; - case 2: - arm64_ldrx(0, 1, reg, reg, 0); - break; - case 3: - arm64_ldrx(0, 1, 30, reg, 0); - arm64_ldrx(0, 0, reg, reg, 2); - o(0x2a0043c0 | reg | reg << 16); // orr x(reg),x30,x(reg),lsl #16 - break; - case 4: - arm64_ldrx(0, 2, reg, reg, 0); - break; - case 5: - arm64_ldrx(0, 2, 30, reg, 0); - arm64_ldrx(0, 0, reg, reg, 4); - o(0xaa0083c0 | reg | reg << 16); // orr x(reg),x30,x(reg),lsl #32 - break; - case 6: - arm64_ldrx(0, 2, 30, reg, 0); - arm64_ldrx(0, 1, reg, reg, 4); - o(0xaa0083c0 | reg | reg << 16); // orr x(reg),x30,x(reg),lsl #32 - break; - case 7: - arm64_ldrx(0, 2, 30, reg, 0); - arm64_ldrx(0, 2, reg, reg, 3); - o(0x53087c00 | reg | reg << 5); // lsr w(reg), w(reg), #8 - o(0xaa0083c0 | reg | reg << 16); // orr x(reg),x30,x(reg),lsl #32 - break; - case 8: - arm64_ldrx(0, 3, reg, reg, 0); - break; - case 9: - arm64_ldrx(0, 0, reg + 1, reg, 8); - arm64_ldrx(0, 3, reg, reg, 0); - break; - case 10: - arm64_ldrx(0, 1, reg + 1, reg, 8); - arm64_ldrx(0, 3, reg, reg, 0); - break; - case 11: - arm64_ldrx(0, 2, reg + 1, reg, 7); - o(0x53087c00 | (reg+1) | (reg+1) << 5); // lsr w(reg+1), w(reg+1), #8 - arm64_ldrx(0, 3, reg, reg, 0); - break; - case 12: - arm64_ldrx(0, 2, reg + 1, reg, 8); - arm64_ldrx(0, 3, reg, reg, 0); - break; - case 13: - arm64_ldrx(0, 3, reg + 1, reg, 5); - o(0xd358fc00 | (reg+1) | (reg+1) << 5); // lsr x(reg+1), x(reg+1), #24 - arm64_ldrx(0, 3, reg, reg, 0); - break; - case 14: - arm64_ldrx(0, 3, reg + 1, reg, 6); - o(0xd350fc00 | (reg+1) | (reg+1) << 5); // lsr x(reg+1), x(reg+1), #16 - arm64_ldrx(0, 3, reg, reg, 0); - break; - case 15: - arm64_ldrx(0, 3, reg + 1, reg, 7); - o(0xd348fc00 | (reg+1) | (reg+1) << 5); // lsr x(reg+1), x(reg+1), #8 - arm64_ldrx(0, 3, reg, reg, 0); - break; - case 16: - o(0xa9400000 | reg | (reg+1) << 10 | reg << 5); - // ldp x(reg),x(reg+1),[x(reg)] - break; - } -} - -static void arm64_strx(int sz_, int dst, int bas, uint64_t off) -{ - uint32_t sz = sz_; - if (!(off & ~((uint32_t)0xfff << sz))) - o(0x39000000 | dst | bas << 5 | off << (10 - sz) | sz << 30); - // str(*) x(dst),[x(bas],#(off)] - else if (off < 256 || -off <= 256) - o(0x38000000 | dst | bas << 5 | (off & 511) << 12 | sz << 30); - // stur(*) x(dst),[x(bas],#(off)] - else { - arm64_movimm(30, off); // use x30 for offset - o(0x38206800 | dst | bas << 5 | (uint32_t)30 << 16 | sz << 30); - // str(*) x(dst),[x(bas),x30] - } -} - -static void arm64_strv(int sz_, int dst, int bas, uint64_t off) -{ - uint32_t sz = sz_; - if (!(off & ~((uint32_t)0xfff << sz))) - o(0x3d000000 | dst | bas << 5 | off << (10 - sz) | - (sz & 4) << 21 | (sz & 3) << 30); // str (s|d|q)(dst),[x(bas),#(off)] - else if (off < 256 || -off <= 256) - o(0x3c000000 | dst | bas << 5 | (off & 511) << 12 | - (sz & 4) << 21 | (sz & 3) << 30); // stur (s|d|q)(dst),[x(bas),#(off)] - else { - arm64_movimm(30, off); // use x30 for offset - o(0x3c206800 | dst | bas << 5 | (uint32_t)30 << 16 | - sz << 30 | (sz & 4) << 21); // str (s|d|q)(dst),[x(bas),x30] - } -} - -static void arm64_sym(int r, Sym *sym, unsigned long addend) -{ - greloca(cur_text_section, sym, ind, R_AARCH64_ADR_GOT_PAGE, 0); - o(0x90000000 | r); // adrp xr, #sym - greloca(cur_text_section, sym, ind, R_AARCH64_LD64_GOT_LO12_NC, 0); - o(0xf9400000 | r | (r << 5)); // ld xr,[xr, #sym] - if (addend) { - // add xr, xr, #addend - if (addend & 0xffful) - o(0x91000000 | r | r << 5 | (addend & 0xfff) << 10); - if (addend > 0xffful) { - // add xr, xr, #addend, lsl #12 - if (addend & 0xfff000ul) - o(0x91400000 | r | r << 5 | ((addend >> 12) & 0xfff) << 10); - if (addend > 0xfffffful) { - /* very unlikely */ - int t = r ? 0 : 1; - o(0xf81f0fe0 | t); /* str xt, [sp, #-16]! */ - arm64_movimm(t, addend & ~0xfffffful); // use xt for addent - o(0x91000000 | r | (t << 5)); /* add xr, xt, #0 */ - o(0xf84107e0 | t); /* ldr xt, [sp], #16 */ - } - } - } -} - -static void arm64_load_cmp(int r, SValue *sv); - -ST_FUNC void load(int r, SValue *sv) -{ - int svtt = sv->type.t; - int svr = sv->r & ~VT_BOUNDED; - int svrv = svr & VT_VALMASK; - uint64_t svcul = (uint32_t)sv->c.i; - svcul = svcul >> 31 & 1 ? svcul - ((uint64_t)1 << 32) : svcul; - - if (svr == (VT_LOCAL | VT_LVAL)) { - if (IS_FREG(r)) - arm64_ldrv(arm64_type_size(svtt), fltr(r), 29, svcul); - else - arm64_ldrx(!(svtt & VT_UNSIGNED), arm64_type_size(svtt), - intr(r), 29, svcul); - return; - } - - if (svr == (VT_CONST | VT_LVAL)) { - if (sv->sym) - arm64_sym(30, sv->sym, // use x30 for address - arm64_check_offset(0, arm64_type_size(svtt), sv->c.i)); - else - arm64_movimm (30, sv->c.i); - if (IS_FREG(r)) - arm64_ldrv(arm64_type_size(svtt), fltr(r), 30, - arm64_check_offset(1, arm64_type_size(svtt), sv->c.i)); - else - arm64_ldrx(!(svtt&VT_UNSIGNED), arm64_type_size(svtt), intr(r), 30, - arm64_check_offset(1, arm64_type_size(svtt), sv->c.i)); - return; - } - - if ((svr & ~VT_VALMASK) == VT_LVAL && svrv < VT_CONST) { - if ((svtt & VT_BTYPE) != VT_VOID) { - if (IS_FREG(r)) - arm64_ldrv(arm64_type_size(svtt), fltr(r), intr(svrv), 0); - else - arm64_ldrx(!(svtt & VT_UNSIGNED), arm64_type_size(svtt), - intr(r), intr(svrv), 0); - } - return; - } - - if (svr == (VT_CONST | VT_LVAL | VT_SYM)) { - arm64_sym(30, sv->sym, // use x30 for address - arm64_check_offset(0, arm64_type_size(svtt), svcul)); - if (IS_FREG(r)) - arm64_ldrv(arm64_type_size(svtt), fltr(r), 30, - arm64_check_offset(1, arm64_type_size(svtt), svcul)); - else - arm64_ldrx(!(svtt&VT_UNSIGNED), arm64_type_size(svtt), intr(r), 30, - arm64_check_offset(1, arm64_type_size(svtt), svcul)); - return; - } - - if (svr == (VT_CONST | VT_SYM)) { - arm64_sym(intr(r), sv->sym, svcul); - return; - } - - if (svr == VT_CONST) { - if ((svtt & VT_BTYPE) != VT_VOID) - arm64_movimm(intr(r), arm64_type_size(svtt) == 3 ? - sv->c.i : (uint32_t)svcul); - return; - } - - if (svr < VT_CONST) { - if (IS_FREG(r) && IS_FREG(svr)) - if (svtt == VT_LDOUBLE) - o(0x4ea01c00 | fltr(r) | fltr(svr) << 5); - // mov v(r).16b,v(svr).16b - else - o(0x1e604000 | fltr(r) | fltr(svr) << 5); // fmov d(r),d(svr) - else if (!IS_FREG(r) && !IS_FREG(svr)) - o(0xaa0003e0 | intr(r) | intr(svr) << 16); // mov x(r),x(svr) - else - assert(0); - return; - } - - if (svr == VT_LOCAL) { - if (-svcul < 0x1000) - o(0xd10003a0 | intr(r) | -svcul << 10); // sub x(r),x29,#... - else { - arm64_movimm(30, -svcul); // use x30 for offset - o(0xcb0003a0 | intr(r) | (uint32_t)30 << 16); // sub x(r),x29,x30 - } - return; - } - - if (svr == VT_JMP || svr == VT_JMPI) { - int t = (svr == VT_JMPI); - arm64_movimm(intr(r), t); - o(0x14000002); // b .+8 - gsym(svcul); - arm64_movimm(intr(r), t ^ 1); - return; - } - - if (svr == (VT_LLOCAL | VT_LVAL)) { - arm64_ldrx(0, 3, 30, 29, svcul); // use x30 for offset - if (IS_FREG(r)) - arm64_ldrv(arm64_type_size(svtt), fltr(r), 30, 0); - else - arm64_ldrx(!(svtt & VT_UNSIGNED), arm64_type_size(svtt), - intr(r), 30, 0); - return; - } - - if (svr == VT_CMP) { - arm64_load_cmp(r, sv); - return; - } - - printf("load(%x, (%x, %x, %lx))\n", r, svtt, sv->r, (long)svcul); - assert(0); -} - -ST_FUNC void store(int r, SValue *sv) -{ - int svtt = sv->type.t; - int svr = sv->r & ~VT_BOUNDED; - int svrv = svr & VT_VALMASK; - uint64_t svcul = (uint32_t)sv->c.i; - svcul = svcul >> 31 & 1 ? svcul - ((uint64_t)1 << 32) : svcul; - - if (svr == (VT_LOCAL | VT_LVAL)) { - if (IS_FREG(r)) - arm64_strv(arm64_type_size(svtt), fltr(r), 29, svcul); - else - arm64_strx(arm64_type_size(svtt), intr(r), 29, svcul); - return; - } - - if (svr == (VT_CONST | VT_LVAL)) { - if (sv->sym) - arm64_sym(30, sv->sym, // use x30 for address - arm64_check_offset(0, arm64_type_size(svtt), sv->c.i)); - else - arm64_movimm (30, sv->c.i); - if (IS_FREG(r)) - arm64_strv(arm64_type_size(svtt), fltr(r), 30, - arm64_check_offset(1, arm64_type_size(svtt), sv->c.i)); - else - arm64_strx(arm64_type_size(svtt), intr(r), 30, - arm64_check_offset(1, arm64_type_size(svtt), sv->c.i)); - return; - } - - if ((svr & ~VT_VALMASK) == VT_LVAL && svrv < VT_CONST) { - if (IS_FREG(r)) - arm64_strv(arm64_type_size(svtt), fltr(r), intr(svrv), 0); - else - arm64_strx(arm64_type_size(svtt), intr(r), intr(svrv), 0); - return; - } - - if (svr == (VT_CONST | VT_LVAL | VT_SYM)) { - arm64_sym(30, sv->sym, // use x30 for address - arm64_check_offset(0, arm64_type_size(svtt), svcul)); - if (IS_FREG(r)) - arm64_strv(arm64_type_size(svtt), fltr(r), 30, - arm64_check_offset(1, arm64_type_size(svtt), svcul)); - else - arm64_strx(arm64_type_size(svtt), intr(r), 30, - arm64_check_offset(1, arm64_type_size(svtt), svcul)); - return; - } - - printf("store(%x, (%x, %x, %lx))\n", r, svtt, sv->r, (long)svcul); - assert(0); -} - -static void arm64_gen_bl_or_b(int b) -{ - if ((vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST && (vtop->r & VT_SYM)) { - greloca(cur_text_section, vtop->sym, ind, - b ? R_AARCH64_JUMP26 : R_AARCH64_CALL26, 0); - o(0x14000000 | (uint32_t)!b << 31); // b/bl . - } - else { -#ifdef CONFIG_TCC_BCHECK - vtop->r &= ~VT_MUSTBOUND; -#endif - o(0xd61f0000 | (uint32_t)!b << 21 | intr(gv(RC_R30)) << 5); // br/blr - } -} - -#if defined(CONFIG_TCC_BCHECK) - -static void gen_bounds_call(int v) -{ - Sym *sym = external_helper_sym(v); - - greloca(cur_text_section, sym, ind, R_AARCH64_CALL26, 0); - o(0x94000000); // bl -} - -static void gen_bounds_prolog(void) -{ - /* leave some room for bound checking code */ - func_bound_offset = lbounds_section->data_offset; - func_bound_ind = ind; - func_bound_add_epilog = 0; - o(0xd503201f); /* nop -> mov x0, lbound section pointer */ - o(0xd503201f); - o(0xd503201f); - o(0xd503201f); /* nop -> call __bound_local_new */ -} - -static void gen_bounds_epilog(void) -{ - addr_t saved_ind; - addr_t *bounds_ptr; - Sym *sym_data; - int offset_modified = func_bound_offset != lbounds_section->data_offset; - - if (!offset_modified && !func_bound_add_epilog) - return; - - /* add end of table info */ - bounds_ptr = section_ptr_add(lbounds_section, sizeof(addr_t)); - *bounds_ptr = 0; - - sym_data = get_sym_ref(&char_pointer_type, lbounds_section, - func_bound_offset, PTR_SIZE); - - /* generate bound local allocation */ - if (offset_modified) { - saved_ind = ind; - ind = func_bound_ind; - greloca(cur_text_section, sym_data, ind, R_AARCH64_ADR_GOT_PAGE, 0); - o(0x90000000 | 0); // adrp x0, #sym_data - greloca(cur_text_section, sym_data, ind, R_AARCH64_LD64_GOT_LO12_NC, 0); - o(0xf9400000 | 0 | (0 << 5)); // ld x0,[x0, #sym_data] - gen_bounds_call(TOK___bound_local_new); - ind = saved_ind; - } - - /* generate bound check local freeing */ - o(0xa9bf07e0); /* stp x0, x1, [sp, #-16]! */ - o(0x3c9f0fe0); /* str q0, [sp, #-16]! */ - greloca(cur_text_section, sym_data, ind, R_AARCH64_ADR_GOT_PAGE, 0); - o(0x90000000 | 0); // adrp x0, #sym_data - greloca(cur_text_section, sym_data, ind, R_AARCH64_LD64_GOT_LO12_NC, 0); - o(0xf9400000 | 0 | (0 << 5)); // ld x0,[x0, #sym_data] - gen_bounds_call(TOK___bound_local_delete); - o(0x3cc107e0); /* ldr q0, [sp], #16 */ - o(0xa8c107e0); /* ldp x0, x1, [sp], #16 */ -} -#endif - -static int arm64_hfa_aux(CType *type, int *fsize, int num) -{ - if (is_float(type->t)) { - int a, n = type_size(type, &a); - if (num >= 4 || (*fsize && *fsize != n)) - return -1; - *fsize = n; - return num + 1; - } - else if ((type->t & VT_BTYPE) == VT_STRUCT) { - int is_struct = 0; // rather than union - Sym *field; - for (field = type->ref->next; field; field = field->next) - if (field->c) { - is_struct = 1; - break; - } - if (is_struct) { - int num0 = num; - for (field = type->ref->next; field; field = field->next) { - if (field->c != (num - num0) * *fsize) - return -1; - num = arm64_hfa_aux(&field->type, fsize, num); - if (num == -1) - return -1; - } - if (type->ref->c != (num - num0) * *fsize) - return -1; - return num; - } - else { // union - int num0 = num; - for (field = type->ref->next; field; field = field->next) { - int num1 = arm64_hfa_aux(&field->type, fsize, num0); - if (num1 == -1) - return -1; - num = num1 < num ? num : num1; - } - if (type->ref->c != (num - num0) * *fsize) - return -1; - return num; - } - } - else if ((type->t & VT_ARRAY) && ((type->t & VT_BTYPE) != VT_PTR)) { - int num1; - if (!type->ref->c) - return num; - num1 = arm64_hfa_aux(&type->ref->type, fsize, num); - if (num1 == -1 || (num1 != num && type->ref->c > 4)) - return -1; - num1 = num + type->ref->c * (num1 - num); - if (num1 > 4) - return -1; - return num1; - } - return -1; -} - -static int arm64_hfa(CType *type, unsigned *fsize) -{ - if ((type->t & VT_BTYPE) == VT_STRUCT || - ((type->t & VT_ARRAY) && ((type->t & VT_BTYPE) != VT_PTR))) { - int sz = 0; - int n = arm64_hfa_aux(type, &sz, 0); - if (0 < n && n <= 4) { - if (fsize) - *fsize = sz; - return n; - } - } - return 0; -} - -static unsigned long arm64_pcs_aux(int n, CType **type, unsigned long *a) -{ - int nx = 0; // next integer register - int nv = 0; // next vector register - unsigned long ns = 32; // next stack offset - int i; - - for (i = 0; i < n; i++) { - int hfa = arm64_hfa(type[i], 0); - int size, align; - - if ((type[i]->t & VT_ARRAY) || - (type[i]->t & VT_BTYPE) == VT_FUNC) - size = align = 8; - else - size = type_size(type[i], &align); - - if (hfa) - // B.2 - ; - else if (size > 16) { - // B.3: replace with pointer - if (nx < 8) - a[i] = nx++ << 1 | 1; - else { - ns = (ns + 7) & ~7; - a[i] = ns | 1; - ns += 8; - } - continue; - } - else if ((type[i]->t & VT_BTYPE) == VT_STRUCT) - // B.4 - size = (size + 7) & ~7; - - // C.1 - if (is_float(type[i]->t) && nv < 8) { - a[i] = 16 + (nv++ << 1); - continue; - } - - // C.2 - if (hfa && nv + hfa <= 8) { - a[i] = 16 + (nv << 1); - nv += hfa; - continue; - } - - // C.3 - if (hfa) { - nv = 8; - size = (size + 7) & ~7; - } - - // C.4 - if (hfa || (type[i]->t & VT_BTYPE) == VT_LDOUBLE) { - ns = (ns + 7) & ~7; - ns = (ns + align - 1) & -align; - } - - // C.5 - if ((type[i]->t & VT_BTYPE) == VT_FLOAT) - size = 8; - - // C.6 - if (hfa || is_float(type[i]->t)) { - a[i] = ns; - ns += size; - continue; - } - - // C.7 - if ((type[i]->t & VT_BTYPE) != VT_STRUCT && size <= 8 && nx < 8) { - a[i] = nx++ << 1; - continue; - } - - // C.8 - if (align == 16) - nx = (nx + 1) & ~1; - - // C.9 - if ((type[i]->t & VT_BTYPE) != VT_STRUCT && size == 16 && nx < 7) { - a[i] = nx << 1; - nx += 2; - continue; - } - - // C.10 - if ((type[i]->t & VT_BTYPE) == VT_STRUCT && size <= (8 - nx) * 8) { - a[i] = nx << 1; - nx += (size + 7) >> 3; - continue; - } - - // C.11 - nx = 8; - - // C.12 - ns = (ns + 7) & ~7; - ns = (ns + align - 1) & -align; - - // C.13 - if ((type[i]->t & VT_BTYPE) == VT_STRUCT) { - a[i] = ns; - ns += size; - continue; - } - - // C.14 - if (size < 8) - size = 8; - - // C.15 - a[i] = ns; - ns += size; - } - - return ns - 32; -} - -static unsigned long arm64_pcs(int n, CType **type, unsigned long *a) -{ - unsigned long stack; - - // Return type: - if ((type[0]->t & VT_BTYPE) == VT_VOID) - a[0] = -1; - else { - arm64_pcs_aux(1, type, a); - assert(a[0] == 0 || a[0] == 1 || a[0] == 16); - } - - // Argument types: - stack = arm64_pcs_aux(n, type + 1, a + 1); - - if (0) { - int i; - for (i = 0; i <= n; i++) { - if (!i) - printf("arm64_pcs return: "); - else - printf("arm64_pcs arg %d: ", i); - if (a[i] == (unsigned long)-1) - printf("void\n"); - else if (a[i] == 1 && !i) - printf("X8 pointer\n"); - else if (a[i] < 16) - printf("X%lu%s\n", a[i] / 2, a[i] & 1 ? " pointer" : ""); - else if (a[i] < 32) - printf("V%lu\n", a[i] / 2 - 8); - else - printf("stack %lu%s\n", - (a[i] - 32) & ~1, a[i] & 1 ? " pointer" : ""); - } - } - - return stack; -} - -ST_FUNC void gfunc_call(int nb_args) -{ - CType *return_type; - CType **t; - unsigned long *a, *a1; - unsigned long stack; - int i; - -#ifdef CONFIG_TCC_BCHECK - if (tcc_state->do_bounds_check) - gbound_args(nb_args); -#endif - - return_type = &vtop[-nb_args].type.ref->type; - if ((return_type->t & VT_BTYPE) == VT_STRUCT) - --nb_args; - - t = tcc_malloc((nb_args + 1) * sizeof(*t)); - a = tcc_malloc((nb_args + 1) * sizeof(*a)); - a1 = tcc_malloc((nb_args + 1) * sizeof(*a1)); - - t[0] = return_type; - for (i = 0; i < nb_args; i++) - t[nb_args - i] = &vtop[-i].type; - - stack = arm64_pcs(nb_args, t, a); - - // Allocate space for structs replaced by pointer: - for (i = nb_args; i; i--) - if (a[i] & 1) { - SValue *arg = &vtop[i - nb_args]; - int align, size = type_size(&arg->type, &align); - assert((arg->type.t & VT_BTYPE) == VT_STRUCT); - stack = (stack + align - 1) & -align; - a1[i] = stack; - stack += size; - } - - stack = (stack + 15) >> 4 << 4; - - /* fetch cpu flag before generating any code */ - if ((vtop->r & VT_VALMASK) == VT_CMP) - gv(RC_INT); - - if (stack >= 0x1000000) // 16Mb - tcc_error("stack size too big %lu", stack); - if (stack & 0xfff) - o(0xd10003ff | (stack & 0xfff) << 10); // sub sp,sp,#(n) - if (stack >> 12) - o(0xd14003ff | (stack >> 12) << 10); - - // First pass: set all values on stack - for (i = nb_args; i; i--) { - vpushv(vtop - nb_args + i); - - if (a[i] & 1) { - // struct replaced by pointer - int r = get_reg(RC_INT); - arm64_spoff(intr(r), a1[i]); - vset(&vtop->type, r | VT_LVAL, 0); - vswap(); - vstore(); - if (a[i] >= 32) { - // pointer on stack - r = get_reg(RC_INT); - arm64_spoff(intr(r), a1[i]); - arm64_strx(3, intr(r), 31, (a[i] - 32) >> 1 << 1); - } - } - else if (a[i] >= 32) { - // value on stack - if ((vtop->type.t & VT_BTYPE) == VT_STRUCT) { - int r = get_reg(RC_INT); - arm64_spoff(intr(r), a[i] - 32); - vset(&vtop->type, r | VT_LVAL, 0); - vswap(); - vstore(); - } - else if (is_float(vtop->type.t)) { - gv(RC_FLOAT); - arm64_strv(arm64_type_size(vtop[0].type.t), - fltr(vtop[0].r), 31, a[i] - 32); - } - else { - gv(RC_INT); - arm64_strx(arm64_type_size(vtop[0].type.t), - intr(vtop[0].r), 31, a[i] - 32); - } - } - - --vtop; - } - - // Second pass: assign values to registers - for (i = nb_args; i; i--, vtop--) { - if (a[i] < 16 && !(a[i] & 1)) { - // value in general-purpose registers - if ((vtop->type.t & VT_BTYPE) == VT_STRUCT) { - int align, size = type_size(&vtop->type, &align); - if (size) { - vtop->type.t = VT_PTR; - gaddrof(); - gv(RC_R(a[i] / 2)); - arm64_ldrs(a[i] / 2, size); - } - } - else - gv(RC_R(a[i] / 2)); - } - else if (a[i] < 16) - // struct replaced by pointer in register - arm64_spoff(a[i] / 2, a1[i]); - else if (a[i] < 32) { - // value in floating-point registers - if ((vtop->type.t & VT_BTYPE) == VT_STRUCT) { - uint32_t j, sz, n = arm64_hfa(&vtop->type, &sz); - vtop->type.t = VT_PTR; - gaddrof(); - gv(RC_R30); - for (j = 0; j < n; j++) - o(0x3d4003c0 | - (sz & 16) << 19 | -(sz & 8) << 27 | (sz & 4) << 29 | - (a[i] / 2 - 8 + j) | - j << 10); // ldr ([sdq])(*),[x30,#(j * sz)] - } - else - gv(RC_F(a[i] / 2 - 8)); - } - } - - if ((return_type->t & VT_BTYPE) == VT_STRUCT) { - if (a[0] == 1) { - // indirect return: set x8 and discard the stack value - gv(RC_R(8)); - --vtop; - } - else - // return in registers: keep the address for after the call - vswap(); - } - - save_regs(0); - arm64_gen_bl_or_b(0); - --vtop; - if (stack & 0xfff) - o(0x910003ff | (stack & 0xfff) << 10); // add sp,sp,#(n) - if (stack >> 12) - o(0x914003ff | (stack >> 12) << 10); - - { - int rt = return_type->t; - int bt = rt & VT_BTYPE; - if (bt == VT_STRUCT && !(a[0] & 1)) { - // A struct was returned in registers, so write it out: - gv(RC_R(8)); - --vtop; - if (a[0] == 0) { - int align, size = type_size(return_type, &align); - assert(size <= 16); - if (size > 8) - o(0xa9000500); // stp x0,x1,[x8] - else if (size) - arm64_strx(size > 4 ? 3 : size > 2 ? 2 : size > 1, 0, 8, 0); - - } - else if (a[0] == 16) { - uint32_t j, sz, n = arm64_hfa(return_type, &sz); - for (j = 0; j < n; j++) - o(0x3d000100 | - (sz & 16) << 19 | -(sz & 8) << 27 | (sz & 4) << 29 | - (a[i] / 2 - 8 + j) | - j << 10); // str ([sdq])(*),[x8,#(j * sz)] - } - } - } - - tcc_free(a1); - tcc_free(a); - tcc_free(t); -} - -static unsigned long arm64_func_va_list_stack; -static int arm64_func_va_list_gr_offs; -static int arm64_func_va_list_vr_offs; -static int arm64_func_sub_sp_offset; - -ST_FUNC void gfunc_prolog(Sym *func_sym) -{ - CType *func_type = &func_sym->type; - int n = 0; - int i = 0; - Sym *sym; - CType **t; - unsigned long *a; - int use_x8 = 0; - int last_int = 0; - int last_float = 0; - - func_vc = 144; // offset of where x8 is stored - - for (sym = func_type->ref; sym; sym = sym->next) - ++n; - t = n ? tcc_malloc(n * sizeof(*t)) : NULL; - a = n ? tcc_malloc(n * sizeof(*a)) : NULL; - - for (sym = func_type->ref; sym; sym = sym->next) - t[i++] = &sym->type; - - arm64_func_va_list_stack = arm64_pcs(n - 1, t, a); - - if (func_sym->type.ref->f.func_type == FUNC_ELLIPSIS) { - use_x8 = 1; - last_int = 4; - last_float = 4; - } - if (a && a[0] == 1) - use_x8 = 1; - for (i = 1, sym = func_type->ref->next; sym; i++, sym = sym->next) { - if (a[i] == 1) - use_x8 = 1; - if (a[i] < 16) { - int last, align, size = type_size(&sym->type, &align); - last = a[i] / 4 + 1 + (size - 1) / 8; - last_int = last > last_int ? last : last_int; - } - else if (a[i] < 32) { - int last, hfa = arm64_hfa(&sym->type, 0); - last = a[i] / 4 - 3 + (hfa ? hfa - 1 : 0); - last_float = last > last_float ? last : last_float; - } - } - - last_int = last_int > 4 ? 4 : last_int; - last_float = last_float > 4 ? 4 : last_float; - - o(0xa9b27bfd); // stp x29,x30,[sp,#-224]! - for (i = 0; i < last_float; i++) - // stp q0,q1,[sp,#16], stp q2,q3,[sp,#48] - // stp q4,q5,[sp,#80], stp q6,q7,[sp,#112] - o(0xad0087e0 + i * 0x10000 + (i << 11) + (i << 1)); - if (use_x8) - o(0xa90923e8); // stp x8,x8,[sp,#144] - for (i = 0; i < last_int; i++) - // stp x0,x1,[sp,#160], stp x2,x3,[sp,#176] - // stp x4,x5,[sp,#192], stp x6,x7,[sp,#208] - o(0xa90a07e0 + i * 0x10000 + (i << 11) + (i << 1)); - - arm64_func_va_list_gr_offs = -64; - arm64_func_va_list_vr_offs = -128; - - for (i = 1, sym = func_type->ref->next; sym; i++, sym = sym->next) { - int off = (a[i] < 16 ? 160 + a[i] / 2 * 8 : - a[i] < 32 ? 16 + (a[i] - 16) / 2 * 16 : - 224 + ((a[i] - 32) >> 1 << 1)); - sym_push(sym->v & ~SYM_FIELD, &sym->type, - (a[i] & 1 ? VT_LLOCAL : VT_LOCAL) | VT_LVAL, - off); - - if (a[i] < 16) { - int align, size = type_size(&sym->type, &align); - arm64_func_va_list_gr_offs = (a[i] / 2 - 7 + - (!(a[i] & 1) && size > 8)) * 8; - } - else if (a[i] < 32) { - uint32_t hfa = arm64_hfa(&sym->type, 0); - arm64_func_va_list_vr_offs = (a[i] / 2 - 16 + - (hfa ? hfa : 1)) * 16; - } - - // HFAs of float and double need to be written differently: - if (16 <= a[i] && a[i] < 32 && (sym->type.t & VT_BTYPE) == VT_STRUCT) { - uint32_t j, sz, k = arm64_hfa(&sym->type, &sz); - if (sz < 16) - for (j = 0; j < k; j++) { - o(0x3d0003e0 | -(sz & 8) << 27 | (sz & 4) << 29 | - ((a[i] - 16) / 2 + j) | (off / sz + j) << 10); - // str ([sdq])(*),[sp,#(j * sz)] - } - } - } - - tcc_free(a); - tcc_free(t); - - o(0x910003fd); // mov x29,sp - arm64_func_sub_sp_offset = ind; - // In gfunc_epilog these will be replaced with code to decrement SP: - o(0xd503201f); // nop - o(0xd503201f); // nop - loc = 0; -#ifdef CONFIG_TCC_BCHECK - if (tcc_state->do_bounds_check) - gen_bounds_prolog(); -#endif -} - -ST_FUNC void gen_va_start(void) -{ - int r; - --vtop; // we don't need the "arg" - gaddrof(); - r = intr(gv(RC_INT)); - - if (arm64_func_va_list_stack) { - //xx could use add (immediate) here - arm64_movimm(30, arm64_func_va_list_stack + 224); - o(0x8b1e03be); // add x30,x29,x30 - } - else - o(0x910383be); // add x30,x29,#224 - o(0xf900001e | r << 5); // str x30,[x(r)] - - if (arm64_func_va_list_gr_offs) { - if (arm64_func_va_list_stack) - o(0x910383be); // add x30,x29,#224 - o(0xf900041e | r << 5); // str x30,[x(r),#8] - } - - if (arm64_func_va_list_vr_offs) { - o(0x910243be); // add x30,x29,#144 - o(0xf900081e | r << 5); // str x30,[x(r),#16] - } - - arm64_movimm(30, arm64_func_va_list_gr_offs); - o(0xb900181e | r << 5); // str w30,[x(r),#24] - - arm64_movimm(30, arm64_func_va_list_vr_offs); - o(0xb9001c1e | r << 5); // str w30,[x(r),#28] - - --vtop; -} - -ST_FUNC void gen_va_arg(CType *t) -{ - int align, size = type_size(t, &align); - unsigned fsize, hfa = arm64_hfa(t, &fsize); - uint32_t r0, r1; - - if (is_float(t->t)) { - hfa = 1; - fsize = size; - } - - gaddrof(); - r0 = intr(gv(RC_INT)); - r1 = get_reg(RC_INT); - vtop[0].r = r1 | VT_LVAL; - r1 = intr(r1); - - if (!hfa) { - uint32_t n = size > 16 ? 8 : (size + 7) & -8; - o(0xb940181e | r0 << 5); // ldr w30,[x(r0),#24] // __gr_offs - if (align == 16) { - assert(0); // this path untested but needed for __uint128_t - o(0x11003fde); // add w30,w30,#15 - o(0x121c6fde); // and w30,w30,#-16 - } - o(0x310003c0 | r1 | n << 10); // adds w(r1),w30,#(n) - o(0x540000ad); // b.le .+20 - o(0xf9400000 | r1 | r0 << 5); // ldr x(r1),[x(r0)] // __stack - o(0x9100001e | r1 << 5 | n << 10); // add x30,x(r1),#(n) - o(0xf900001e | r0 << 5); // str x30,[x(r0)] // __stack - o(0x14000004); // b .+16 - o(0xb9001800 | r1 | r0 << 5); // str w(r1),[x(r0),#24] // __gr_offs - o(0xf9400400 | r1 | r0 << 5); // ldr x(r1),[x(r0),#8] // __gr_top - o(0x8b3ec000 | r1 | r1 << 5); // add x(r1),x(r1),w30,sxtw - if (size > 16) - o(0xf9400000 | r1 | r1 << 5); // ldr x(r1),[x(r1)] - } - else { - uint32_t rsz = hfa << 4; - uint32_t ssz = (size + 7) & -(uint32_t)8; - uint32_t b1, b2; - o(0xb9401c1e | r0 << 5); // ldr w30,[x(r0),#28] // __vr_offs - o(0x310003c0 | r1 | rsz << 10); // adds w(r1),w30,#(rsz) - b1 = ind; o(0x5400000d); // b.le lab1 - o(0xf9400000 | r1 | r0 << 5); // ldr x(r1),[x(r0)] // __stack - if (fsize == 16) { - o(0x91003c00 | r1 | r1 << 5); // add x(r1),x(r1),#15 - o(0x927cec00 | r1 | r1 << 5); // and x(r1),x(r1),#-16 - } - o(0x9100001e | r1 << 5 | ssz << 10); // add x30,x(r1),#(ssz) - o(0xf900001e | r0 << 5); // str x30,[x(r0)] // __stack - b2 = ind; o(0x14000000); // b lab2 - // lab1: - write32le(cur_text_section->data + b1, 0x5400000d | (ind - b1) << 3); - o(0xb9001c00 | r1 | r0 << 5); // str w(r1),[x(r0),#28] // __vr_offs - o(0xf9400800 | r1 | r0 << 5); // ldr x(r1),[x(r0),#16] // __vr_top - if (hfa == 1 || fsize == 16) - o(0x8b3ec000 | r1 | r1 << 5); // add x(r1),x(r1),w30,sxtw - else { - // We need to change the layout of this HFA. - // Get some space on the stack using global variable "loc": - loc = (loc - size) & -(uint32_t)align; - o(0x8b3ec000 | 30 | r1 << 5); // add x30,x(r1),w30,sxtw - arm64_movimm(r1, loc); - o(0x8b0003a0 | r1 | r1 << 16); // add x(r1),x29,x(r1) - o(0x4c402bdc | (uint32_t)fsize << 7 | - (uint32_t)(hfa == 2) << 15 | - (uint32_t)(hfa == 3) << 14); // ld1 {v28.(4s|2d),...},[x30] - o(0x0d00801c | r1 << 5 | (fsize == 8) << 10 | - (uint32_t)(hfa != 2) << 13 | - (uint32_t)(hfa != 3) << 21); // st(hfa) {v28.(s|d),...}[0],[x(r1)] - } - // lab2: - write32le(cur_text_section->data + b2, 0x14000000 | (ind - b2) >> 2); - } -} - -ST_FUNC int gfunc_sret(CType *vt, int variadic, CType *ret, - int *align, int *regsize) -{ - return 0; -} - -ST_FUNC void gfunc_return(CType *func_type) -{ - CType *t = func_type; - unsigned long a; - - arm64_pcs(0, &t, &a); - switch (a) { - case -1: - break; - case 0: - if ((func_type->t & VT_BTYPE) == VT_STRUCT) { - int align, size = type_size(func_type, &align); - gaddrof(); - gv(RC_R(0)); - arm64_ldrs(0, size); - } - else - gv(RC_IRET); - break; - case 1: { - CType type = *func_type; - mk_pointer(&type); - vset(&type, VT_LOCAL | VT_LVAL, func_vc); - indir(); - vswap(); - vstore(); - break; - } - case 16: - if ((func_type->t & VT_BTYPE) == VT_STRUCT) { - uint32_t j, sz, n = arm64_hfa(&vtop->type, &sz); - gaddrof(); - gv(RC_R(0)); - for (j = 0; j < n; j++) - o(0x3d400000 | - (sz & 16) << 19 | -(sz & 8) << 27 | (sz & 4) << 29 | - j | j << 10); // ldr ([sdq])(*),[x0,#(j * sz)] - } - else - gv(RC_FRET); - break; - default: - assert(0); - } - vtop--; -} - -ST_FUNC void gfunc_epilog(void) -{ -#ifdef CONFIG_TCC_BCHECK - if (tcc_state->do_bounds_check) - gen_bounds_epilog(); -#endif - - if (loc) { - // Insert instructions to subtract size of stack frame from SP. - unsigned char *ptr = cur_text_section->data + arm64_func_sub_sp_offset; - uint64_t diff = (-loc + 15) & ~15; - if (!(diff >> 24)) { - if (diff & 0xfff) // sub sp,sp,#(diff & 0xfff) - write32le(ptr, 0xd10003ff | (diff & 0xfff) << 10); - if (diff >> 12) // sub sp,sp,#(diff >> 12),lsl #12 - write32le(ptr + 4, 0xd14003ff | (diff >> 12) << 10); - } - else { - // In this case we may subtract more than necessary, - // but always less than 17/16 of what we were aiming for. - int i = 0; - int j = 0; - while (diff >> 20) { - diff = (diff + 0xffff) >> 16; - ++i; - } - while (diff >> 16) { - diff = (diff + 1) >> 1; - ++j; - } - write32le(ptr, 0xd2800010 | diff << 5 | i << 21); - // mov x16,#(diff),lsl #(16 * i) - write32le(ptr + 4, 0xcb3063ff | j << 10); - // sub sp,sp,x16,lsl #(j) - } - } - o(0x910003bf); // mov sp,x29 - o(0xa8ce7bfd); // ldp x29,x30,[sp],#224 - - o(0xd65f03c0); // ret -} - -ST_FUNC void gen_fill_nops(int bytes) -{ - if ((bytes & 3)) - tcc_error("alignment of code section not multiple of 4"); - while (bytes > 0) { - o(0xd503201f); // nop - bytes -= 4; - } -} - -// Generate forward branch to label: -ST_FUNC int gjmp(int t) -{ - int r = ind; - if (nocode_wanted) - return t; - o(t); - return r; -} - -// Generate branch to known address: -ST_FUNC void gjmp_addr(int a) -{ - assert(a - ind + 0x8000000 < 0x10000000); - o(0x14000000 | ((a - ind) >> 2 & 0x3ffffff)); -} - -ST_FUNC int gjmp_append(int n, int t) -{ - void *p; - /* insert vtop->c jump list in t */ - if (n) { - uint32_t n1 = n, n2; - while ((n2 = read32le(p = cur_text_section->data + n1))) - n1 = n2; - write32le(p, t); - t = n; - } - return t; -} - -void arm64_vset_VT_CMP(int op) -{ - if (op >= TOK_ULT && op <= TOK_GT) { - vtop->cmp_r = vtop->r; - vset_VT_CMP(0x80); - } -} - -static void arm64_gen_opil(int op, uint32_t l); - -static void arm64_load_cmp(int r, SValue *sv) -{ - sv->r = sv->cmp_r; - if (sv->c.i & 1) { - vpushi(1); - arm64_gen_opil('^', 0); - } - if (r != sv->r) { - load(r, sv); - sv->r = r; - } -} - -ST_FUNC int gjmp_cond(int op, int t) -{ - int bt = vtop->type.t & VT_BTYPE; - - int inv = op & 1; - vtop->r = vtop->cmp_r; - - if (bt == VT_LDOUBLE) { - uint32_t a, b, f = fltr(gv(RC_FLOAT)); - a = get_reg(RC_INT); - vpushi(0); - vtop[0].r = a; - b = get_reg(RC_INT); - a = intr(a); - b = intr(b); - o(0x4e083c00 | a | f << 5); // mov x(a),v(f).d[0] - o(0x4e183c00 | b | f << 5); // mov x(b),v(f).d[1] - o(0xaa000400 | a | a << 5 | b << 16); // orr x(a),x(a),x(b),lsl #1 - o(0xb4000040 | a | !!inv << 24); // cbz/cbnz x(a),.+8 - --vtop; - } - else if (bt == VT_FLOAT || bt == VT_DOUBLE) { - uint32_t a = fltr(gv(RC_FLOAT)); - o(0x1e202008 | a << 5 | (bt != VT_FLOAT) << 22); // fcmp - o(0x54000040 | !!inv); // b.eq/b.ne .+8 - } - else { - uint32_t ll = (bt == VT_PTR || bt == VT_LLONG); - uint32_t a = intr(gv(RC_INT)); - o(0x34000040 | a | !!inv << 24 | ll << 31); // cbz/cbnz wA,.+8 - } - return gjmp(t); -} - -static int arm64_iconst(uint64_t *val, SValue *sv) -{ - if ((sv->r & (VT_VALMASK | VT_LVAL | VT_SYM)) != VT_CONST) - return 0; - if (val) { - int t = sv->type.t; - int bt = t & VT_BTYPE; - *val = ((bt == VT_LLONG || bt == VT_PTR) ? sv->c.i : - (uint32_t)sv->c.i | - (t & VT_UNSIGNED ? 0 : -(sv->c.i & 0x80000000))); - } - return 1; -} - -static int arm64_gen_opic(int op, uint32_t l, int rev, uint64_t val, - uint32_t x, uint32_t a) -{ - if (op == '-' && !rev) { - val = -val; - op = '+'; - } - val = l ? val : (uint32_t)val; - - switch (op) { - - case '+': { - uint32_t s = l ? val >> 63 : val >> 31; - val = s ? -val : val; - val = l ? val : (uint32_t)val; - if (!(val & ~(uint64_t)0xfff)) - o(0x11000000 | l << 31 | s << 30 | x | a << 5 | val << 10); - else if (!(val & ~(uint64_t)0xfff000)) - o(0x11400000 | l << 31 | s << 30 | x | a << 5 | val >> 12 << 10); - else { - arm64_movimm(30, val); // use x30 - o(0x0b1e0000 | l << 31 | s << 30 | x | a << 5); - } - return 1; - } - - case '-': - if (!val) - o(0x4b0003e0 | l << 31 | x | a << 16); // neg - else if (val == (l ? (uint64_t)-1 : (uint32_t)-1)) - o(0x2a2003e0 | l << 31 | x | a << 16); // mvn - else { - arm64_movimm(30, val); // use x30 - o(0x4b0003c0 | l << 31 | x | a << 16); // sub - } - return 1; - - case '^': - if (val == -1 || (val == 0xffffffff && !l)) { - o(0x2a2003e0 | l << 31 | x | a << 16); // mvn - return 1; - } - // fall through - case '&': - case '|': { - int e = arm64_encode_bimm64(l ? val : val | val << 32); - if (e < 0) - return 0; - o((op == '&' ? 0x12000000 : - op == '|' ? 0x32000000 : 0x52000000) | - l << 31 | x | a << 5 | (uint32_t)e << 10); - return 1; - } - - case TOK_SAR: - case TOK_SHL: - case TOK_SHR: { - uint32_t n = 32 << l; - val = val & (n - 1); - if (rev) - return 0; - if (!val) { - // tcc_warning("shift count >= width of type"); - o(0x2a0003e0 | l << 31 | a << 16); - return 1; - } - else if (op == TOK_SHL) - o(0x53000000 | l << 31 | l << 22 | x | a << 5 | - (n - val) << 16 | (n - 1 - val) << 10); // lsl - else - o(0x13000000 | (op == TOK_SHR) << 30 | l << 31 | l << 22 | - x | a << 5 | val << 16 | (n - 1) << 10); // lsr/asr - return 1; - } - - } - return 0; -} - -static void arm64_gen_opil(int op, uint32_t l) -{ - uint32_t x, a, b; - - // Special treatment for operations with a constant operand: - { - uint64_t val; - int rev = 1; - - if (arm64_iconst(0, &vtop[0])) { - vswap(); - rev = 0; - } - if (arm64_iconst(&val, &vtop[-1])) { - gv(RC_INT); - a = intr(vtop[0].r); - --vtop; - x = get_reg(RC_INT); - ++vtop; - if (arm64_gen_opic(op, l, rev, val, intr(x), a)) { - vtop[0].r = x; - vswap(); - --vtop; - return; - } - } - if (!rev) - vswap(); - } - - gv2(RC_INT, RC_INT); - assert(vtop[-1].r < VT_CONST && vtop[0].r < VT_CONST); - a = intr(vtop[-1].r); - b = intr(vtop[0].r); - vtop -= 2; - x = get_reg(RC_INT); - ++vtop; - vtop[0].r = x; - x = intr(x); - - switch (op) { - case '%': - // Use x30 for quotient: - o(0x1ac00c00 | l << 31 | 30 | a << 5 | b << 16); // sdiv - o(0x1b008000 | l << 31 | x | (uint32_t)30 << 5 | - b << 16 | a << 10); // msub - break; - case '&': - o(0x0a000000 | l << 31 | x | a << 5 | b << 16); // and - break; - case '*': - o(0x1b007c00 | l << 31 | x | a << 5 | b << 16); // mul - break; - case '+': - o(0x0b000000 | l << 31 | x | a << 5 | b << 16); // add - break; - case '-': - o(0x4b000000 | l << 31 | x | a << 5 | b << 16); // sub - break; - case '/': - o(0x1ac00c00 | l << 31 | x | a << 5 | b << 16); // sdiv - break; - case '^': - o(0x4a000000 | l << 31 | x | a << 5 | b << 16); // eor - break; - case '|': - o(0x2a000000 | l << 31 | x | a << 5 | b << 16); // orr - break; - case TOK_EQ: - o(0x6b00001f | l << 31 | a << 5 | b << 16); // cmp - o(0x1a9f17e0 | x); // cset wA,eq - break; - case TOK_GE: - o(0x6b00001f | l << 31 | a << 5 | b << 16); // cmp - o(0x1a9fb7e0 | x); // cset wA,ge - break; - case TOK_GT: - o(0x6b00001f | l << 31 | a << 5 | b << 16); // cmp - o(0x1a9fd7e0 | x); // cset wA,gt - break; - case TOK_LE: - o(0x6b00001f | l << 31 | a << 5 | b << 16); // cmp - o(0x1a9fc7e0 | x); // cset wA,le - break; - case TOK_LT: - o(0x6b00001f | l << 31 | a << 5 | b << 16); // cmp - o(0x1a9fa7e0 | x); // cset wA,lt - break; - case TOK_NE: - o(0x6b00001f | l << 31 | a << 5 | b << 16); // cmp - o(0x1a9f07e0 | x); // cset wA,ne - break; - case TOK_SAR: - o(0x1ac02800 | l << 31 | x | a << 5 | b << 16); // asr - break; - case TOK_SHL: - o(0x1ac02000 | l << 31 | x | a << 5 | b << 16); // lsl - break; - case TOK_SHR: - o(0x1ac02400 | l << 31 | x | a << 5 | b << 16); // lsr - break; - case TOK_UDIV: - case TOK_PDIV: - o(0x1ac00800 | l << 31 | x | a << 5 | b << 16); // udiv - break; - case TOK_UGE: - o(0x6b00001f | l << 31 | a << 5 | b << 16); // cmp - o(0x1a9f37e0 | x); // cset wA,cs - break; - case TOK_UGT: - o(0x6b00001f | l << 31 | a << 5 | b << 16); // cmp - o(0x1a9f97e0 | x); // cset wA,hi - break; - case TOK_ULT: - o(0x6b00001f | l << 31 | a << 5 | b << 16); // cmp - o(0x1a9f27e0 | x); // cset wA,cc - break; - case TOK_ULE: - o(0x6b00001f | l << 31 | a << 5 | b << 16); // cmp - o(0x1a9f87e0 | x); // cset wA,ls - break; - case TOK_UMOD: - // Use x30 for quotient: - o(0x1ac00800 | l << 31 | 30 | a << 5 | b << 16); // udiv - o(0x1b008000 | l << 31 | x | (uint32_t)30 << 5 | - b << 16 | a << 10); // msub - break; - default: - assert(0); - } -} - -ST_FUNC void gen_opi(int op) -{ - arm64_gen_opil(op, 0); - arm64_vset_VT_CMP(op); -} - -ST_FUNC void gen_opl(int op) -{ - arm64_gen_opil(op, 1); - arm64_vset_VT_CMP(op); -} - -ST_FUNC void gen_opf(int op) -{ - uint32_t x, a, b, dbl; - - if (vtop[0].type.t == VT_LDOUBLE) { - CType type = vtop[0].type; - int func = 0; - int cond = -1; - switch (op) { - case '*': func = TOK___multf3; break; - case '+': func = TOK___addtf3; break; - case '-': func = TOK___subtf3; break; - case '/': func = TOK___divtf3; break; - case TOK_EQ: func = TOK___eqtf2; cond = 1; break; - case TOK_NE: func = TOK___netf2; cond = 0; break; - case TOK_LT: func = TOK___lttf2; cond = 10; break; - case TOK_GE: func = TOK___getf2; cond = 11; break; - case TOK_LE: func = TOK___letf2; cond = 12; break; - case TOK_GT: func = TOK___gttf2; cond = 13; break; - default: assert(0); break; - } - vpush_helper_func(func); - vrott(3); - gfunc_call(2); - vpushi(0); - vtop->r = cond < 0 ? REG_FRET : REG_IRET; - if (cond < 0) - vtop->type = type; - else { - o(0x7100001f); // cmp w0,#0 - o(0x1a9f07e0 | (uint32_t)cond << 12); // cset w0,(cond) - } - return; - } - - dbl = vtop[0].type.t != VT_FLOAT; - gv2(RC_FLOAT, RC_FLOAT); - assert(vtop[-1].r < VT_CONST && vtop[0].r < VT_CONST); - a = fltr(vtop[-1].r); - b = fltr(vtop[0].r); - vtop -= 2; - switch (op) { - case TOK_EQ: case TOK_NE: - case TOK_LT: case TOK_GE: case TOK_LE: case TOK_GT: - x = get_reg(RC_INT); - ++vtop; - vtop[0].r = x; - x = intr(x); - break; - default: - x = get_reg(RC_FLOAT); - ++vtop; - vtop[0].r = x; - x = fltr(x); - break; - } - - switch (op) { - case '*': - o(0x1e200800 | dbl << 22 | x | a << 5 | b << 16); // fmul - break; - case '+': - o(0x1e202800 | dbl << 22 | x | a << 5 | b << 16); // fadd - break; - case '-': - o(0x1e203800 | dbl << 22 | x | a << 5 | b << 16); // fsub - break; - case '/': - o(0x1e201800 | dbl << 22 | x | a << 5 | b << 16); // fdiv - break; - case TOK_EQ: - o(0x1e202000 | dbl << 22 | a << 5 | b << 16); // fcmp - o(0x1a9f17e0 | x); // cset w(x),eq - break; - case TOK_GE: - o(0x1e202000 | dbl << 22 | a << 5 | b << 16); // fcmp - o(0x1a9fb7e0 | x); // cset w(x),ge - break; - case TOK_GT: - o(0x1e202000 | dbl << 22 | a << 5 | b << 16); // fcmp - o(0x1a9fd7e0 | x); // cset w(x),gt - break; - case TOK_LE: - o(0x1e202000 | dbl << 22 | a << 5 | b << 16); // fcmp - o(0x1a9f87e0 | x); // cset w(x),ls - break; - case TOK_LT: - o(0x1e202000 | dbl << 22 | a << 5 | b << 16); // fcmp - o(0x1a9f57e0 | x); // cset w(x),mi - break; - case TOK_NE: - o(0x1e202000 | dbl << 22 | a << 5 | b << 16); // fcmp - o(0x1a9f07e0 | x); // cset w(x),ne - break; - default: - assert(0); - } - arm64_vset_VT_CMP(op); -} - -// Generate sign extension from 32 to 64 bits: -ST_FUNC void gen_cvt_sxtw(void) -{ - uint32_t r = intr(gv(RC_INT)); - o(0x93407c00 | r | r << 5); // sxtw x(r),w(r) -} - -/* char/short to int conversion */ -ST_FUNC void gen_cvt_csti(int t) -{ - int r = intr(gv(RC_INT)); - o(0x13001c00 - | ((t & VT_BTYPE) == VT_SHORT) << 13 - | (uint32_t)!!(t & VT_UNSIGNED) << 30 - | r | r << 5); // [su]xt[bh] w(r),w(r) -} - -ST_FUNC void gen_cvt_itof(int t) -{ - if (t == VT_LDOUBLE) { - int f = vtop->type.t; - int func = (f & VT_BTYPE) == VT_LLONG ? - (f & VT_UNSIGNED ? TOK___floatunditf : TOK___floatditf) : - (f & VT_UNSIGNED ? TOK___floatunsitf : TOK___floatsitf); - vpush_helper_func(func); - vrott(2); - gfunc_call(1); - vpushi(0); - vtop->type.t = t; - vtop->r = REG_FRET; - return; - } - else { - int d, n = intr(gv(RC_INT)); - int s = !(vtop->type.t & VT_UNSIGNED); - uint32_t l = ((vtop->type.t & VT_BTYPE) == VT_LLONG); - --vtop; - d = get_reg(RC_FLOAT); - ++vtop; - vtop[0].r = d; - o(0x1e220000 | (uint32_t)!s << 16 | - (uint32_t)(t != VT_FLOAT) << 22 | fltr(d) | - l << 31 | n << 5); // [us]cvtf [sd](d),[wx](n) - } -} - -ST_FUNC void gen_cvt_ftoi(int t) -{ - if ((vtop->type.t & VT_BTYPE) == VT_LDOUBLE) { - int func = (t & VT_BTYPE) == VT_LLONG ? - (t & VT_UNSIGNED ? TOK___fixunstfdi : TOK___fixtfdi) : - (t & VT_UNSIGNED ? TOK___fixunstfsi : TOK___fixtfsi); - vpush_helper_func(func); - vrott(2); - gfunc_call(1); - vpushi(0); - vtop->type.t = t; - vtop->r = REG_IRET; - return; - } - else { - int d, n = fltr(gv(RC_FLOAT)); - uint32_t l = ((vtop->type.t & VT_BTYPE) != VT_FLOAT); - --vtop; - d = get_reg(RC_INT); - ++vtop; - vtop[0].r = d; - o(0x1e380000 | - (uint32_t)!!(t & VT_UNSIGNED) << 16 | - (uint32_t)((t & VT_BTYPE) == VT_LLONG) << 31 | intr(d) | - l << 22 | n << 5); // fcvtz[su] [wx](d),[sd](n) - } -} - -ST_FUNC void gen_cvt_ftof(int t) -{ - int f = vtop[0].type.t & VT_BTYPE; - assert(t == VT_FLOAT || t == VT_DOUBLE || t == VT_LDOUBLE); - assert(f == VT_FLOAT || f == VT_DOUBLE || f == VT_LDOUBLE); - if (t == f) - return; - - if (t == VT_LDOUBLE || f == VT_LDOUBLE) { - int func = (t == VT_LDOUBLE) ? - (f == VT_FLOAT ? TOK___extendsftf2 : TOK___extenddftf2) : - (t == VT_FLOAT ? TOK___trunctfsf2 : TOK___trunctfdf2); - vpush_helper_func(func); - vrott(2); - gfunc_call(1); - vpushi(0); - vtop->type.t = t; - vtop->r = REG_FRET; - } - else { - int x, a; - gv(RC_FLOAT); - assert(vtop[0].r < VT_CONST); - a = fltr(vtop[0].r); - --vtop; - x = get_reg(RC_FLOAT); - ++vtop; - vtop[0].r = x; - x = fltr(x); - - if (f == VT_FLOAT) - o(0x1e22c000 | x | a << 5); // fcvt d(x),s(a) - else - o(0x1e624000 | x | a << 5); // fcvt s(x),d(a) - } -} - -/* increment tcov counter */ -ST_FUNC void gen_increment_tcov (SValue *sv) -{ - int r1, r2; - - vpushv(sv); - vtop->r = r1 = get_reg(RC_INT); - r2 = get_reg(RC_INT); - greloca(cur_text_section, sv->sym, ind, R_AARCH64_ADR_GOT_PAGE, 0); - o(0x90000000 | r1); // adrp r1, #sym - greloca(cur_text_section, sv->sym, ind, R_AARCH64_LD64_GOT_LO12_NC, 0); - o(0xf9400000 | r1 | (r1 << 5)); // ld xr,[xr, #sym] - o(0xf9400000 | (intr(r1)<<5) | intr(r2)); // ldr r2, [r1] - o(0x91000400 | (intr(r2)<<5) | intr(r2)); // add r2, r2, #1 - o(0xf9000000 | (intr(r1)<<5) | intr(r2)); // str r2, [r1] - vpop(); -} - -ST_FUNC void ggoto(void) -{ - arm64_gen_bl_or_b(1); - --vtop; -} - -ST_FUNC void gen_clear_cache(void) -{ - uint32_t beg, end, dsz, isz, p, lab1, b1; - gv2(RC_INT, RC_INT); - vpushi(0); - vtop->r = get_reg(RC_INT); - vpushi(0); - vtop->r = get_reg(RC_INT); - vpushi(0); - vtop->r = get_reg(RC_INT); - beg = intr(vtop[-4].r); // x0 - end = intr(vtop[-3].r); // x1 - dsz = intr(vtop[-2].r); // x2 - isz = intr(vtop[-1].r); // x3 - p = intr(vtop[0].r); // x4 - vtop -= 5; - - o(0xd53b0020 | isz); // mrs x(isz),ctr_el0 - o(0x52800080 | p); // mov w(p),#4 - o(0x53104c00 | dsz | isz << 5); // ubfx w(dsz),w(isz),#16,#4 - o(0x1ac02000 | dsz | p << 5 | dsz << 16); // lsl w(dsz),w(p),w(dsz) - o(0x12000c00 | isz | isz << 5); // and w(isz),w(isz),#15 - o(0x1ac02000 | isz | p << 5 | isz << 16); // lsl w(isz),w(p),w(isz) - o(0x51000400 | p | dsz << 5); // sub w(p),w(dsz),#1 - o(0x8a240004 | p | beg << 5 | p << 16); // bic x(p),x(beg),x(p) - b1 = ind; o(0x14000000); // b - lab1 = ind; - o(0xd50b7b20 | p); // dc cvau,x(p) - o(0x8b000000 | p | p << 5 | dsz << 16); // add x(p),x(p),x(dsz) - write32le(cur_text_section->data + b1, 0x14000000 | (ind - b1) >> 2); - o(0xeb00001f | p << 5 | end << 16); // cmp x(p),x(end) - o(0x54ffffa3 | ((lab1 - ind) << 3 & 0xffffe0)); // b.cc lab1 - o(0xd5033b9f); // dsb ish - o(0x51000400 | p | isz << 5); // sub w(p),w(isz),#1 - o(0x8a240004 | p | beg << 5 | p << 16); // bic x(p),x(beg),x(p) - b1 = ind; o(0x14000000); // b - lab1 = ind; - o(0xd50b7520 | p); // ic ivau,x(p) - o(0x8b000000 | p | p << 5 | isz << 16); // add x(p),x(p),x(isz) - write32le(cur_text_section->data + b1, 0x14000000 | (ind - b1) >> 2); - o(0xeb00001f | p << 5 | end << 16); // cmp x(p),x(end) - o(0x54ffffa3 | ((lab1 - ind) << 3 & 0xffffe0)); // b.cc lab1 - o(0xd5033b9f); // dsb ish - o(0xd5033fdf); // isb -} - -ST_FUNC void gen_vla_sp_save(int addr) { - uint32_t r = intr(get_reg(RC_INT)); - o(0x910003e0 | r); // mov x(r),sp - arm64_strx(3, r, 29, addr); -} - -ST_FUNC void gen_vla_sp_restore(int addr) { - // Use x30 because this function can be called when there - // is a live return value in x0 but there is nothing on - // the value stack to prevent get_reg from returning x0. - uint32_t r = 30; - arm64_ldrx(0, 3, r, 29, addr); - o(0x9100001f | r << 5); // mov sp,x(r) -} - -ST_FUNC void gen_vla_alloc(CType *type, int align) { - uint32_t r; -#if defined(CONFIG_TCC_BCHECK) - if (tcc_state->do_bounds_check) - vpushv(vtop); -#endif - r = intr(gv(RC_INT)); -#if defined(CONFIG_TCC_BCHECK) - if (tcc_state->do_bounds_check) - o(0x91004000 | r | r << 5); // add x(r),x(r),#15+1 - else -#endif - o(0x91003c00 | r | r << 5); // add x(r),x(r),#15 - o(0x927cec00 | r | r << 5); // bic x(r),x(r),#15 - o(0xcb2063ff | r << 16); // sub sp,sp,x(r) - vpop(); -#if defined(CONFIG_TCC_BCHECK) - if (tcc_state->do_bounds_check) { - vpushi(0); - vtop->r = TREG_R(0); - o(0x910003e0 | vtop->r); // mov r0,sp - vswap(); - vpush_helper_func(TOK___bound_new_region); - vrott(3); - gfunc_call(2); - func_bound_add_epilog = 1; - } -#endif -} - -/* end of A64 code generator */ -/*************************************************************/ -#endif -/*************************************************************/ diff --git a/05/tcc-final/arm64-link.c b/05/tcc-final/arm64-link.c deleted file mode 100644 index baf13fe..0000000 --- a/05/tcc-final/arm64-link.c +++ /dev/null @@ -1,322 +0,0 @@ -#ifdef TARGET_DEFS_ONLY - -#define EM_TCC_TARGET EM_AARCH64 - -#define R_DATA_32 R_AARCH64_ABS32 -#define R_DATA_PTR R_AARCH64_ABS64 -#define R_JMP_SLOT R_AARCH64_JUMP_SLOT -#define R_GLOB_DAT R_AARCH64_GLOB_DAT -#define R_COPY R_AARCH64_COPY -#define R_RELATIVE R_AARCH64_RELATIVE - -#define R_NUM R_AARCH64_NUM - -#define ELF_START_ADDR 0x00400000 -#define ELF_PAGE_SIZE 0x10000 - -#define PCRELATIVE_DLLPLT 1 -#define RELOCATE_DLLPLT 1 - -#else /* !TARGET_DEFS_ONLY */ - -#include "tcc.h" - -#ifdef NEED_RELOC_TYPE -/* Returns 1 for a code relocation, 0 for a data relocation. For unknown - relocations, returns -1. */ -int code_reloc (int reloc_type) -{ - switch (reloc_type) { - case R_AARCH64_ABS32: - case R_AARCH64_ABS64: - case R_AARCH64_PREL32: - case R_AARCH64_MOVW_UABS_G0_NC: - case R_AARCH64_MOVW_UABS_G1_NC: - case R_AARCH64_MOVW_UABS_G2_NC: - case R_AARCH64_MOVW_UABS_G3: - case R_AARCH64_ADR_PREL_PG_HI21: - case R_AARCH64_ADD_ABS_LO12_NC: - case R_AARCH64_ADR_GOT_PAGE: - case R_AARCH64_LD64_GOT_LO12_NC: - case R_AARCH64_LDST128_ABS_LO12_NC: - case R_AARCH64_LDST64_ABS_LO12_NC: - case R_AARCH64_LDST32_ABS_LO12_NC: - case R_AARCH64_LDST16_ABS_LO12_NC: - case R_AARCH64_LDST8_ABS_LO12_NC: - case R_AARCH64_GLOB_DAT: - case R_AARCH64_COPY: - return 0; - - case R_AARCH64_JUMP26: - case R_AARCH64_CALL26: - case R_AARCH64_JUMP_SLOT: - return 1; - } - return -1; -} - -/* Returns an enumerator to describe whether and when the relocation needs a - GOT and/or PLT entry to be created. See tcc.h for a description of the - different values. */ -int gotplt_entry_type (int reloc_type) -{ - switch (reloc_type) { - case R_AARCH64_PREL32: - case R_AARCH64_MOVW_UABS_G0_NC: - case R_AARCH64_MOVW_UABS_G1_NC: - case R_AARCH64_MOVW_UABS_G2_NC: - case R_AARCH64_MOVW_UABS_G3: - case R_AARCH64_ADR_PREL_PG_HI21: - case R_AARCH64_ADD_ABS_LO12_NC: - case R_AARCH64_LDST128_ABS_LO12_NC: - case R_AARCH64_LDST64_ABS_LO12_NC: - case R_AARCH64_LDST32_ABS_LO12_NC: - case R_AARCH64_LDST16_ABS_LO12_NC: - case R_AARCH64_LDST8_ABS_LO12_NC: - case R_AARCH64_GLOB_DAT: - case R_AARCH64_JUMP_SLOT: - case R_AARCH64_COPY: - return NO_GOTPLT_ENTRY; - - case R_AARCH64_ABS32: - case R_AARCH64_ABS64: - case R_AARCH64_JUMP26: - case R_AARCH64_CALL26: - return AUTO_GOTPLT_ENTRY; - - case R_AARCH64_ADR_GOT_PAGE: - case R_AARCH64_LD64_GOT_LO12_NC: - return ALWAYS_GOTPLT_ENTRY; - } - return -1; -} - -#ifdef NEED_BUILD_GOT -ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr) -{ - Section *plt = s1->plt; - uint8_t *p; - unsigned plt_offset; - - if (plt->data_offset == 0) { - section_ptr_add(plt, 32); - } - plt_offset = plt->data_offset; - - p = section_ptr_add(plt, 16); - write32le(p, got_offset); - write32le(p + 4, (uint64_t) got_offset >> 32); - return plt_offset; -} - -/* relocate the PLT: compute addresses and offsets in the PLT now that final - address for PLT and GOT are known (see fill_program_header) */ -ST_FUNC void relocate_plt(TCCState *s1) -{ - uint8_t *p, *p_end; - - if (!s1->plt) - return; - - p = s1->plt->data; - p_end = p + s1->plt->data_offset; - - if (p < p_end) { - uint64_t plt = s1->plt->sh_addr; - uint64_t got = s1->got->sh_addr + 16; - uint64_t off = (got >> 12) - (plt >> 12); - if ((off + ((uint32_t)1 << 20)) >> 21) - tcc_error("Failed relocating PLT (off=0x%lx, got=0x%lx, plt=0x%lx)", (long)off, (long)got, (long)plt); - write32le(p, 0xa9bf7bf0); // stp x16,x30,[sp,#-16]! - write32le(p + 4, (0x90000010 | // adrp x16,... - (off & 0x1ffffc) << 3 | (off & 3) << 29)); - write32le(p + 8, (0xf9400211 | // ldr x17,[x16,#...] - (got & 0xff8) << 7)); - write32le(p + 12, (0x91000210 | // add x16,x16,#... - (got & 0xfff) << 10)); - write32le(p + 16, 0xd61f0220); // br x17 - write32le(p + 20, 0xd503201f); // nop - write32le(p + 24, 0xd503201f); // nop - write32le(p + 28, 0xd503201f); // nop - p += 32; - got = s1->got->sh_addr; - while (p < p_end) { - uint64_t pc = plt + (p - s1->plt->data); - uint64_t addr = got + read64le(p); - uint64_t off = (addr >> 12) - (pc >> 12); - if ((off + ((uint32_t)1 << 20)) >> 21) - tcc_error("Failed relocating PLT (off=0x%lx, addr=0x%lx, pc=0x%lx)", (long)off, (long)addr, (long)pc); - write32le(p, (0x90000010 | // adrp x16,... - (off & 0x1ffffc) << 3 | (off & 3) << 29)); - write32le(p + 4, (0xf9400211 | // ldr x17,[x16,#...] - (addr & 0xff8) << 7)); - write32le(p + 8, (0x91000210 | // add x16,x16,#... - (addr & 0xfff) << 10)); - write32le(p + 12, 0xd61f0220); // br x17 - p += 16; - } - } - - if (s1->plt->reloc) { - ElfW_Rel *rel; - p = s1->got->data; - for_each_elem(s1->plt->reloc, 0, rel, ElfW_Rel) { - write64le(p + rel->r_offset, s1->plt->sh_addr); - } - } -} -#endif -#endif - -void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val) -{ - int sym_index = ELFW(R_SYM)(rel->r_info), esym_index; -#ifdef DEBUG_RELOC - ElfW(Sym) *sym = &((ElfW(Sym) *)symtab_section->data)[sym_index]; -#endif - - switch(type) { - case R_AARCH64_ABS64: - if (s1->output_type == TCC_OUTPUT_DLL) { - esym_index = get_sym_attr(s1, sym_index, 0)->dyn_index; - qrel->r_offset = rel->r_offset; - if (esym_index) { - qrel->r_info = ELFW(R_INFO)(esym_index, R_AARCH64_ABS64); - qrel->r_addend = rel->r_addend; - qrel++; - break; - } else { - qrel->r_info = ELFW(R_INFO)(0, R_AARCH64_RELATIVE); - qrel->r_addend = read64le(ptr) + val; - qrel++; - } - } - add64le(ptr, val); - return; - case R_AARCH64_ABS32: - if (s1->output_type == TCC_OUTPUT_DLL) { - /* XXX: this logic may depend on TCC's codegen - now TCC uses R_AARCH64_RELATIVE even for a 64bit pointer */ - qrel->r_offset = rel->r_offset; - qrel->r_info = ELFW(R_INFO)(0, R_AARCH64_RELATIVE); - /* Use sign extension! */ - qrel->r_addend = (int)read32le(ptr) + val; - qrel++; - } - add32le(ptr, val); - return; - case R_AARCH64_PREL32: - if (s1->output_type == TCC_OUTPUT_DLL) { - /* DLL relocation */ - esym_index = get_sym_attr(s1, sym_index, 0)->dyn_index; - if (esym_index) { - qrel->r_offset = rel->r_offset; - qrel->r_info = ELFW(R_INFO)(esym_index, R_AARCH64_PREL32); - /* Use sign extension! */ - qrel->r_addend = (int)read32le(ptr) + rel->r_addend; - qrel++; - break; - } - } - write32le(ptr, val - addr); - return; - case R_AARCH64_MOVW_UABS_G0_NC: - write32le(ptr, ((read32le(ptr) & 0xffe0001f) | - (val & 0xffff) << 5)); - return; - case R_AARCH64_MOVW_UABS_G1_NC: - write32le(ptr, ((read32le(ptr) & 0xffe0001f) | - (val >> 16 & 0xffff) << 5)); - return; - case R_AARCH64_MOVW_UABS_G2_NC: - write32le(ptr, ((read32le(ptr) & 0xffe0001f) | - (val >> 32 & 0xffff) << 5)); - return; - case R_AARCH64_MOVW_UABS_G3: - write32le(ptr, ((read32le(ptr) & 0xffe0001f) | - (val >> 48 & 0xffff) << 5)); - return; - case R_AARCH64_ADR_PREL_PG_HI21: { - uint64_t off = (val >> 12) - (addr >> 12); - if ((off + ((uint64_t)1 << 20)) >> 21) - tcc_error("R_AARCH64_ADR_PREL_PG_HI21 relocation failed"); - write32le(ptr, ((read32le(ptr) & 0x9f00001f) | - (off & 0x1ffffc) << 3 | (off & 3) << 29)); - return; - } - case R_AARCH64_ADD_ABS_LO12_NC: - case R_AARCH64_LDST8_ABS_LO12_NC: - write32le(ptr, ((read32le(ptr) & 0xffc003ff) | - (val & 0xfff) << 10)); - return; - case R_AARCH64_LDST16_ABS_LO12_NC: - write32le(ptr, ((read32le(ptr) & 0xffc003ff) | - (val & 0xffe) << 9)); - return; - case R_AARCH64_LDST32_ABS_LO12_NC: - write32le(ptr, ((read32le(ptr) & 0xffc003ff) | - (val & 0xffc) << 8)); - return; - case R_AARCH64_LDST64_ABS_LO12_NC: - write32le(ptr, ((read32le(ptr) & 0xffc003ff) | - (val & 0xff8) << 7)); - return; - case R_AARCH64_LDST128_ABS_LO12_NC: - write32le(ptr, ((read32le(ptr) & 0xffc003ff) | - (val & 0xff0) << 6)); - return; - case R_AARCH64_JUMP26: - case R_AARCH64_CALL26: -#ifdef DEBUG_RELOC - printf ("reloc %d @ 0x%lx: val=0x%lx name=%s\n", type, addr, val, - (char *) symtab_section->link->data + sym->st_name); -#endif - if (((val - addr) + ((uint64_t)1 << 27)) & ~(uint64_t)0xffffffc) - tcc_error("R_AARCH64_(JUMP|CALL)26 relocation failed" - " (val=%lx, addr=%lx)", (long)val, (long)addr); - write32le(ptr, (0x14000000 | - (uint32_t)(type == R_AARCH64_CALL26) << 31 | - ((val - addr) >> 2 & 0x3ffffff))); - return; - case R_AARCH64_ADR_GOT_PAGE: { - uint64_t off = - (((s1->got->sh_addr + - get_sym_attr(s1, sym_index, 0)->got_offset) >> 12) - (addr >> 12)); - if ((off + ((uint64_t)1 << 20)) >> 21) - tcc_error("R_AARCH64_ADR_GOT_PAGE relocation failed"); - write32le(ptr, ((read32le(ptr) & 0x9f00001f) | - (off & 0x1ffffc) << 3 | (off & 3) << 29)); - return; - } - case R_AARCH64_LD64_GOT_LO12_NC: - write32le(ptr, - ((read32le(ptr) & 0xfff803ff) | - ((s1->got->sh_addr + - get_sym_attr(s1, sym_index, 0)->got_offset) & 0xff8) << 7)); - return; - case R_AARCH64_COPY: - return; - case R_AARCH64_GLOB_DAT: - case R_AARCH64_JUMP_SLOT: - /* They don't need addend */ -#ifdef DEBUG_RELOC - printf ("reloc %d @ 0x%lx: val=0x%lx name=%s\n", type, addr, - val - rel->r_addend, - (char *) symtab_section->link->data + sym->st_name); -#endif - write64le(ptr, val - rel->r_addend); - return; - case R_AARCH64_RELATIVE: -#ifdef TCC_TARGET_PE - add32le(ptr, val - s1->pe_imagebase); -#endif - /* do nothing */ - return; - default: - fprintf(stderr, "FIXME: handle reloc type %x at %x [%p] to %x\n", - type, (unsigned)addr, ptr, (unsigned)val); - return; - } -} - -#endif /* !TARGET_DEFS_ONLY */ diff --git a/05/tcc-final/c67-gen.c b/05/tcc-final/c67-gen.c deleted file mode 100644 index 9490a27..0000000 --- a/05/tcc-final/c67-gen.c +++ /dev/null @@ -1,2543 +0,0 @@ -/* - * TMS320C67xx code generator for TCC - * - * Copyright (c) 2001, 2002 Fabrice Bellard - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifdef TARGET_DEFS_ONLY - -/* #define ASSEMBLY_LISTING_C67 */ - -/* number of available registers */ -#define NB_REGS 24 - -/* a register can belong to several classes. The classes must be - sorted from more general to more precise (see gv2() code which does - assumptions on it). */ -#define RC_INT 0x0001 /* generic integer register */ -#define RC_FLOAT 0x0002 /* generic float register */ -#define RC_EAX 0x0004 -#define RC_ST0 0x0008 -#define RC_ECX 0x0010 -#define RC_EDX 0x0020 -#define RC_INT_BSIDE 0x00000040 /* generic integer register on b side */ -#define RC_C67_A4 0x00000100 -#define RC_C67_A5 0x00000200 -#define RC_C67_B4 0x00000400 -#define RC_C67_B5 0x00000800 -#define RC_C67_A6 0x00001000 -#define RC_C67_A7 0x00002000 -#define RC_C67_B6 0x00004000 -#define RC_C67_B7 0x00008000 -#define RC_C67_A8 0x00010000 -#define RC_C67_A9 0x00020000 -#define RC_C67_B8 0x00040000 -#define RC_C67_B9 0x00080000 -#define RC_C67_A10 0x00100000 -#define RC_C67_A11 0x00200000 -#define RC_C67_B10 0x00400000 -#define RC_C67_B11 0x00800000 -#define RC_C67_A12 0x01000000 -#define RC_C67_A13 0x02000000 -#define RC_C67_B12 0x04000000 -#define RC_C67_B13 0x08000000 -#define RC_IRET RC_C67_A4 /* function return: integer register */ -#define RC_IRE2 RC_C67_A5 /* function return: second integer register */ -#define RC_FRET RC_C67_A4 /* function return: float register */ - -/* pretty names for the registers */ -enum { - TREG_EAX = 0, // really A2 - TREG_ECX, // really A3 - TREG_EDX, // really B0 - TREG_ST0, // really B1 - TREG_C67_A4, - TREG_C67_A5, - TREG_C67_B4, - TREG_C67_B5, - TREG_C67_A6, - TREG_C67_A7, - TREG_C67_B6, - TREG_C67_B7, - TREG_C67_A8, - TREG_C67_A9, - TREG_C67_B8, - TREG_C67_B9, - TREG_C67_A10, - TREG_C67_A11, - TREG_C67_B10, - TREG_C67_B11, - TREG_C67_A12, - TREG_C67_A13, - TREG_C67_B12, - TREG_C67_B13, -}; - -/* return registers for function */ -#define REG_IRET TREG_C67_A4 /* single word int return register */ -#define REG_IRE2 TREG_C67_A5 /* second word return register (for long long) */ -#define REG_FRET TREG_C67_A4 /* float return register */ - -/* defined if function parameters must be evaluated in reverse order */ -/* #define INVERT_FUNC_PARAMS */ - -/* defined if structures are passed as pointers. Otherwise structures - are directly pushed on stack. */ -/* #define FUNC_STRUCT_PARAM_AS_PTR */ - -/* pointer size, in bytes */ -#define PTR_SIZE 4 - -/* long double size and alignment, in bytes */ -#define LDOUBLE_SIZE 12 -#define LDOUBLE_ALIGN 4 -/* maximum alignment (for aligned attribute support) */ -#define MAX_ALIGN 8 - -#undef CONFIG_TCC_BCHECK - -/******************************************************/ -#else /* ! TARGET_DEFS_ONLY */ -/******************************************************/ -#define USING_GLOBALS -#include "tcc.h" - -ST_DATA const char * const target_machine_defs = - "__C67__\0" - ; - -ST_DATA const int reg_classes[NB_REGS] = { - /* eax */ RC_INT | RC_FLOAT | RC_EAX, - // only allow even regs for floats (allow for doubles) - /* ecx */ RC_INT | RC_ECX, - /* edx */ RC_INT | RC_INT_BSIDE | RC_FLOAT | RC_EDX, - // only allow even regs for floats (allow for doubles) - /* st0 */ RC_INT | RC_INT_BSIDE | RC_ST0, - /* A4 */ RC_C67_A4, - /* A5 */ RC_C67_A5, - /* B4 */ RC_C67_B4, - /* B5 */ RC_C67_B5, - /* A6 */ RC_C67_A6, - /* A7 */ RC_C67_A7, - /* B6 */ RC_C67_B6, - /* B7 */ RC_C67_B7, - /* A8 */ RC_C67_A8, - /* A9 */ RC_C67_A9, - /* B8 */ RC_C67_B8, - /* B9 */ RC_C67_B9, - /* A10 */ RC_C67_A10, - /* A11 */ RC_C67_A11, - /* B10 */ RC_C67_B10, - /* B11 */ RC_C67_B11, - /* A12 */ RC_C67_A10, - /* A13 */ RC_C67_A11, - /* B12 */ RC_C67_B10, - /* B13 */ RC_C67_B11 -}; - -// although tcc thinks it is passing parameters on the stack, -// the C67 really passes up to the first 10 params in special -// regs or regs pairs (for 64 bit params). So keep track of -// the stack offsets so we can translate to the appropriate -// reg (pair) - -#define NoCallArgsPassedOnStack 10 -int NoOfCurFuncArgs; -int TranslateStackToReg[NoCallArgsPassedOnStack]; -int ParamLocOnStack[NoCallArgsPassedOnStack]; -int TotalBytesPushedOnStack; - -#ifndef FALSE -# define FALSE 0 -# define TRUE 1 -#endif - -#undef BOOL -#define BOOL int - -#define ALWAYS_ASSERT(x) \ -do {\ - if (!(x))\ - tcc_error("internal compiler error file at %s:%d", __FILE__, __LINE__);\ -} while (0) - -/******************************************************/ -static unsigned long func_sub_sp_offset; -static int func_ret_sub; - -static BOOL C67_invert_test; -static int C67_compare_reg; - -#ifdef ASSEMBLY_LISTING_C67 -FILE *f = NULL; -#endif - -void C67_g(int c) -{ - int ind1; - if (nocode_wanted) - return; -#ifdef ASSEMBLY_LISTING_C67 - fprintf(f, " %08X", c); -#endif - ind1 = ind + 4; - if (ind1 > (int) cur_text_section->data_allocated) - section_realloc(cur_text_section, ind1); - cur_text_section->data[ind] = c & 0xff; - cur_text_section->data[ind + 1] = (c >> 8) & 0xff; - cur_text_section->data[ind + 2] = (c >> 16) & 0xff; - cur_text_section->data[ind + 3] = (c >> 24) & 0xff; - ind = ind1; -} - - -/* output a symbol and patch all calls to it */ -void gsym_addr(int t, int a) -{ - int n, *ptr; - while (t) { - ptr = (int *) (cur_text_section->data + t); - { - Sym *sym; - - // extract 32 bit address from MVKH/MVKL - n = ((*ptr >> 7) & 0xffff); - n |= ((*(ptr + 1) >> 7) & 0xffff) << 16; - - // define a label that will be relocated - - sym = get_sym_ref(&char_pointer_type, cur_text_section, a, 0); - greloc(cur_text_section, sym, t, R_C60LO16); - greloc(cur_text_section, sym, t + 4, R_C60HI16); - - // clear out where the pointer was - - *ptr &= ~(0xffff << 7); - *(ptr + 1) &= ~(0xffff << 7); - } - t = n; - } -} - -// these are regs that tcc doesn't really know about, -// but assign them unique values so the mapping routines -// can distinguish them - -#define C67_A0 105 -#define C67_SP 106 -#define C67_B3 107 -#define C67_FP 108 -#define C67_B2 109 -#define C67_CREG_ZERO -1 /* Special code for no condition reg test */ - - -int ConvertRegToRegClass(int r) -{ - // only works for A4-B13 - - return RC_C67_A4 << (r - TREG_C67_A4); -} - - -// map TCC reg to C67 reg number - -int C67_map_regn(int r) -{ - if (r == 0) // normal tcc regs - return 0x2; // A2 - else if (r == 1) // normal tcc regs - return 3; // A3 - else if (r == 2) // normal tcc regs - return 0; // B0 - else if (r == 3) // normal tcc regs - return 1; // B1 - else if (r >= TREG_C67_A4 && r <= TREG_C67_B13) // these form a pattern of alt pairs - return (((r & 0xfffffffc) >> 1) | (r & 1)) + 2; - else if (r == C67_A0) - return 0; // set to A0 (offset reg) - else if (r == C67_B2) - return 2; // set to B2 (offset reg) - else if (r == C67_B3) - return 3; // set to B3 (return address reg) - else if (r == C67_SP) - return 15; // set to SP (B15) (offset reg) - else if (r == C67_FP) - return 15; // set to FP (A15) (offset reg) - else if (r == C67_CREG_ZERO) - return 0; // Special code for no condition reg test - else - ALWAYS_ASSERT(FALSE); - - return 0; -} - -// mapping from tcc reg number to -// C67 register to condition code field -// -// valid condition code regs are: -// -// tcc reg 2 ->B0 -> 1 -// tcc reg 3 ->B1 -> 2 -// tcc reg 0 -> A2 -> 5 -// tcc reg 1 -> A3 -> X -// tcc reg B2 -> 3 - -int C67_map_regc(int r) -{ - if (r == 0) // normal tcc regs - return 0x5; - else if (r == 2) // normal tcc regs - return 0x1; - else if (r == 3) // normal tcc regs - return 0x2; - else if (r == C67_B2) // normal tcc regs - return 0x3; - else if (r == C67_CREG_ZERO) - return 0; // Special code for no condition reg test - else - ALWAYS_ASSERT(FALSE); - - return 0; -} - - -// map TCC reg to C67 reg side A or B - -int C67_map_regs(int r) -{ - if (r == 0) // normal tcc regs - return 0x0; - else if (r == 1) // normal tcc regs - return 0x0; - else if (r == 2) // normal tcc regs - return 0x1; - else if (r == 3) // normal tcc regs - return 0x1; - else if (r >= TREG_C67_A4 && r <= TREG_C67_B13) // these form a pattern of alt pairs - return (r & 2) >> 1; - else if (r == C67_A0) - return 0; // set to A side - else if (r == C67_B2) - return 1; // set to B side - else if (r == C67_B3) - return 1; // set to B side - else if (r == C67_SP) - return 0x1; // set to SP (B15) B side - else if (r == C67_FP) - return 0x0; // set to FP (A15) A side - else - ALWAYS_ASSERT(FALSE); - - return 0; -} - -int C67_map_S12(char *s) -{ - if (strstr(s, ".S1") != NULL) - return 0; - else if (strcmp(s, ".S2")) - return 1; - else - ALWAYS_ASSERT(FALSE); - - return 0; -} - -int C67_map_D12(char *s) -{ - if (strstr(s, ".D1") != NULL) - return 0; - else if (strcmp(s, ".D2")) - return 1; - else - ALWAYS_ASSERT(FALSE); - - return 0; -} - - - -void C67_asm(const char *s, int a, int b, int c) -{ - BOOL xpath; - -#ifdef ASSEMBLY_LISTING_C67 - if (!f) { - f = fopen("TCC67_out.txt", "wt"); - } - fprintf(f, "%04X ", ind); -#endif - - if (strstr(s, "MVKL") == s) { - C67_g((C67_map_regn(b) << 23) | - ((a & 0xffff) << 7) | (0x0a << 2) | (C67_map_regs(b) << 1)); - } else if (strstr(s, "MVKH") == s) { - C67_g((C67_map_regn(b) << 23) | - (((a >> 16) & 0xffff) << 7) | - (0x1a << 2) | (C67_map_regs(b) << 1)); - } else if (strstr(s, "STW.D SP POST DEC") == s) { - C67_g((C67_map_regn(a) << 23) | //src - (15 << 18) | //SP B15 - (2 << 13) | //ucst5 (must keep 8 byte boundary !!) - (0xa << 9) | //mode a = post dec ucst - (0 << 8) | //r (LDDW bit 0) - (1 << 7) | //y D1/D2 use B side - (7 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(a) << 1) | //side of src - (0 << 0)); //parallel - } else if (strstr(s, "STB.D *+SP[A0]") == s) { - C67_g((C67_map_regn(a) << 23) | //src - (15 << 18) | //base reg A15 - (0 << 13) | //offset reg A0 - (5 << 9) | //mode 5 = pos offset, base reg + off reg - (0 << 8) | //r (LDDW bit 0) - (0 << 7) | //y D1/D2 A side - (3 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(a) << 1) | //side of src - (0 << 0)); //parallel - } else if (strstr(s, "STH.D *+SP[A0]") == s) { - C67_g((C67_map_regn(a) << 23) | //src - (15 << 18) | //base reg A15 - (0 << 13) | //offset reg A0 - (5 << 9) | //mode 5 = pos offset, base reg + off reg - (0 << 8) | //r (LDDW bit 0) - (0 << 7) | //y D1/D2 A side - (5 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(a) << 1) | //side of src - (0 << 0)); //parallel - } else if (strstr(s, "STB.D *+SP[A0]") == s) { - C67_g((C67_map_regn(a) << 23) | //src - (15 << 18) | //base reg A15 - (0 << 13) | //offset reg A0 - (5 << 9) | //mode 5 = pos offset, base reg + off reg - (0 << 8) | //r (LDDW bit 0) - (0 << 7) | //y D1/D2 A side - (3 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(a) << 1) | //side of src - (0 << 0)); //parallel - } else if (strstr(s, "STH.D *+SP[A0]") == s) { - C67_g((C67_map_regn(a) << 23) | //src - (15 << 18) | //base reg A15 - (0 << 13) | //offset reg A0 - (5 << 9) | //mode 5 = pos offset, base reg + off reg - (0 << 8) | //r (LDDW bit 0) - (0 << 7) | //y D1/D2 A side - (5 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(a) << 1) | //side of src - (0 << 0)); //parallel - } else if (strstr(s, "STW.D *+SP[A0]") == s) { - C67_g((C67_map_regn(a) << 23) | //src - (15 << 18) | //base reg A15 - (0 << 13) | //offset reg A0 - (5 << 9) | //mode 5 = pos offset, base reg + off reg - (0 << 8) | //r (LDDW bit 0) - (0 << 7) | //y D1/D2 A side - (7 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(a) << 1) | //side of src - (0 << 0)); //parallel - } else if (strstr(s, "STW.D *") == s) { - C67_g((C67_map_regn(a) << 23) | //src - (C67_map_regn(b) << 18) | //base reg A0 - (0 << 13) | //cst5 - (1 << 9) | //mode 1 = pos cst offset - (0 << 8) | //r (LDDW bit 0) - (C67_map_regs(b) << 7) | //y D1/D2 base reg side - (7 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(a) << 1) | //side of src - (0 << 0)); //parallel - } else if (strstr(s, "STH.D *") == s) { - C67_g((C67_map_regn(a) << 23) | //src - (C67_map_regn(b) << 18) | //base reg A0 - (0 << 13) | //cst5 - (1 << 9) | //mode 1 = pos cst offset - (0 << 8) | //r (LDDW bit 0) - (C67_map_regs(b) << 7) | //y D1/D2 base reg side - (5 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(a) << 1) | //side of src - (0 << 0)); //parallel - } else if (strstr(s, "STB.D *") == s) { - C67_g((C67_map_regn(a) << 23) | //src - (C67_map_regn(b) << 18) | //base reg A0 - (0 << 13) | //cst5 - (1 << 9) | //mode 1 = pos cst offset - (0 << 8) | //r (LDDW bit 0) - (C67_map_regs(b) << 7) | //y D1/D2 base reg side - (3 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(a) << 1) | //side of src - (0 << 0)); //parallel - } else if (strstr(s, "STW.D +*") == s) { - ALWAYS_ASSERT(c < 32); - C67_g((C67_map_regn(a) << 23) | //src - (C67_map_regn(b) << 18) | //base reg A0 - (c << 13) | //cst5 - (1 << 9) | //mode 1 = pos cst offset - (0 << 8) | //r (LDDW bit 0) - (C67_map_regs(b) << 7) | //y D1/D2 base reg side - (7 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(a) << 1) | //side of src - (0 << 0)); //parallel - } else if (strstr(s, "LDW.D SP PRE INC") == s) { - C67_g((C67_map_regn(a) << 23) | //dst - (15 << 18) | //base reg B15 - (2 << 13) | //ucst5 (must keep 8 byte boundary) - (9 << 9) | //mode 9 = pre inc ucst5 - (0 << 8) | //r (LDDW bit 0) - (1 << 7) | //y D1/D2 B side - (6 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(a) << 1) | //side of dst - (0 << 0)); //parallel - } else if (strstr(s, "LDDW.D SP PRE INC") == s) { - C67_g((C67_map_regn(a) << 23) | //dst - (15 << 18) | //base reg B15 - (1 << 13) | //ucst5 (must keep 8 byte boundary) - (9 << 9) | //mode 9 = pre inc ucst5 - (1 << 8) | //r (LDDW bit 1) - (1 << 7) | //y D1/D2 B side - (6 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(a) << 1) | //side of dst - (0 << 0)); //parallel - } else if (strstr(s, "LDW.D *+SP[A0]") == s) { - C67_g((C67_map_regn(a) << 23) | //dst - (15 << 18) | //base reg A15 - (0 << 13) | //offset reg A0 - (5 << 9) | //mode 5 = pos offset, base reg + off reg - (0 << 8) | //r (LDDW bit 0) - (0 << 7) | //y D1/D2 A side - (6 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(a) << 1) | //side of dst - (0 << 0)); //parallel - } else if (strstr(s, "LDDW.D *+SP[A0]") == s) { - C67_g((C67_map_regn(a) << 23) | //dst - (15 << 18) | //base reg A15 - (0 << 13) | //offset reg A0 - (5 << 9) | //mode 5 = pos offset, base reg + off reg - (1 << 8) | //r (LDDW bit 1) - (0 << 7) | //y D1/D2 A side - (6 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(a) << 1) | //side of dst - (0 << 0)); //parallel - } else if (strstr(s, "LDH.D *+SP[A0]") == s) { - C67_g((C67_map_regn(a) << 23) | //dst - (15 << 18) | //base reg A15 - (0 << 13) | //offset reg A0 - (5 << 9) | //mode 5 = pos offset, base reg + off reg - (0 << 8) | //r (LDDW bit 0) - (0 << 7) | //y D1/D2 A side - (4 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(a) << 1) | //side of dst - (0 << 0)); //parallel - } else if (strstr(s, "LDB.D *+SP[A0]") == s) { - C67_g((C67_map_regn(a) << 23) | //dst - (15 << 18) | //base reg A15 - (0 << 13) | //offset reg A0 - (5 << 9) | //mode 5 = pos offset, base reg + off reg - (0 << 8) | //r (LDDW bit 0) - (0 << 7) | //y D1/D2 A side - (2 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(a) << 1) | //side of dst - (0 << 0)); //parallel - } else if (strstr(s, "LDHU.D *+SP[A0]") == s) { - C67_g((C67_map_regn(a) << 23) | //dst - (15 << 18) | //base reg A15 - (0 << 13) | //offset reg A0 - (5 << 9) | //mode 5 = pos offset, base reg + off reg - (0 << 8) | //r (LDDW bit 0) - (0 << 7) | //y D1/D2 A side - (0 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(a) << 1) | //side of dst - (0 << 0)); //parallel - } else if (strstr(s, "LDBU.D *+SP[A0]") == s) { - C67_g((C67_map_regn(a) << 23) | //dst - (15 << 18) | //base reg A15 - (0 << 13) | //offset reg A0 - (5 << 9) | //mode 5 = pos offset, base reg + off reg - (0 << 8) | //r (LDDW bit 0) - (0 << 7) | //y D1/D2 A side - (1 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(a) << 1) | //side of dst - (0 << 0)); //parallel - } else if (strstr(s, "LDW.D *") == s) { - C67_g((C67_map_regn(b) << 23) | //dst - (C67_map_regn(a) << 18) | //base reg A15 - (0 << 13) | //cst5 - (1 << 9) | //mode 1 = pos cst offset - (0 << 8) | //r (LDDW bit 0) - (C67_map_regs(a) << 7) | //y D1/D2 src side - (6 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(b) << 1) | //side of dst - (0 << 0)); //parallel - } else if (strstr(s, "LDDW.D *") == s) { - C67_g((C67_map_regn(b) << 23) | //dst - (C67_map_regn(a) << 18) | //base reg A15 - (0 << 13) | //cst5 - (1 << 9) | //mode 1 = pos cst offset - (1 << 8) | //r (LDDW bit 1) - (C67_map_regs(a) << 7) | //y D1/D2 src side - (6 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(b) << 1) | //side of dst - (0 << 0)); //parallel - } else if (strstr(s, "LDH.D *") == s) { - C67_g((C67_map_regn(b) << 23) | //dst - (C67_map_regn(a) << 18) | //base reg A15 - (0 << 13) | //cst5 - (1 << 9) | //mode 1 = pos cst offset - (0 << 8) | //r (LDDW bit 0) - (C67_map_regs(a) << 7) | //y D1/D2 src side - (4 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(b) << 1) | //side of dst - (0 << 0)); //parallel - } else if (strstr(s, "LDB.D *") == s) { - C67_g((C67_map_regn(b) << 23) | //dst - (C67_map_regn(a) << 18) | //base reg A15 - (0 << 13) | //cst5 - (1 << 9) | //mode 1 = pos cst offset - (0 << 8) | //r (LDDW bit 0) - (C67_map_regs(a) << 7) | //y D1/D2 src side - (2 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(b) << 1) | //side of dst - (0 << 0)); //parallel - } else if (strstr(s, "LDHU.D *") == s) { - C67_g((C67_map_regn(b) << 23) | //dst - (C67_map_regn(a) << 18) | //base reg A15 - (0 << 13) | //cst5 - (1 << 9) | //mode 1 = pos cst offset - (0 << 8) | //r (LDDW bit 0) - (C67_map_regs(a) << 7) | //y D1/D2 src side - (0 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(b) << 1) | //side of dst - (0 << 0)); //parallel - } else if (strstr(s, "LDBU.D *") == s) { - C67_g((C67_map_regn(b) << 23) | //dst - (C67_map_regn(a) << 18) | //base reg A15 - (0 << 13) | //cst5 - (1 << 9) | //mode 1 = pos cst offset - (0 << 8) | //r (LDDW bit 0) - (C67_map_regs(a) << 7) | //y D1/D2 src side - (1 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(b) << 1) | //side of dst - (0 << 0)); //parallel - } else if (strstr(s, "LDW.D +*") == s) { - C67_g((C67_map_regn(b) << 23) | //dst - (C67_map_regn(a) << 18) | //base reg A15 - (1 << 13) | //cst5 - (1 << 9) | //mode 1 = pos cst offset - (0 << 8) | //r (LDDW bit 0) - (C67_map_regs(a) << 7) | //y D1/D2 src side - (6 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU - (1 << 2) | //opcode - (C67_map_regs(b) << 1) | //side of dst - (0 << 0)); //parallel - } else if (strstr(s, "CMPLTSP") == s) { - xpath = C67_map_regs(a) ^ C67_map_regs(b); - ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a)); - - C67_g((C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x use cross path for src2 - (0x3a << 6) | //opcode - (0x8 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side for reg c - (0 << 0)); //parallel - } else if (strstr(s, "CMPGTSP") == s) { - xpath = C67_map_regs(a) ^ C67_map_regs(b); - ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a)); - - C67_g((C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x use cross path for src2 - (0x39 << 6) | //opcode - (0x8 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side for reg c - (0 << 0)); //parallel - } else if (strstr(s, "CMPEQSP") == s) { - xpath = C67_map_regs(a) ^ C67_map_regs(b); - ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a)); - - C67_g((C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x use cross path for src2 - (0x38 << 6) | //opcode - (0x8 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side for reg c - (0 << 0)); //parallel - } - - else if (strstr(s, "CMPLTDP") == s) { - xpath = C67_map_regs(a) ^ C67_map_regs(b); - ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a)); - - C67_g((C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x use cross path for src2 - (0x2a << 6) | //opcode - (0x8 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side for reg c - (0 << 0)); //parallel - } else if (strstr(s, "CMPGTDP") == s) { - xpath = C67_map_regs(a) ^ C67_map_regs(b); - ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a)); - - C67_g((C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x use cross path for src2 - (0x29 << 6) | //opcode - (0x8 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side for reg c - (0 << 0)); //parallel - } else if (strstr(s, "CMPEQDP") == s) { - xpath = C67_map_regs(a) ^ C67_map_regs(b); - ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a)); - - C67_g((C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x use cross path for src2 - (0x28 << 6) | //opcode - (0x8 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side for reg c - (0 << 0)); //parallel - } else if (strstr(s, "CMPLT") == s) { - xpath = C67_map_regs(a) ^ C67_map_regs(b); - ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a)); - - C67_g((C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x use cross path for src2 - (0x57 << 5) | //opcode - (0x6 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side for reg c - (0 << 0)); //parallel - } else if (strstr(s, "CMPGT") == s) { - xpath = C67_map_regs(a) ^ C67_map_regs(b); - ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a)); - - C67_g((C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x use cross path for src2 - (0x47 << 5) | //opcode - (0x6 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side for reg c - (0 << 0)); //parallel - } else if (strstr(s, "CMPEQ") == s) { - xpath = C67_map_regs(a) ^ C67_map_regs(b); - ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a)); - - C67_g((C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x use cross path for src2 - (0x53 << 5) | //opcode - (0x6 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side for reg c - (0 << 0)); //parallel - } else if (strstr(s, "CMPLTU") == s) { - xpath = C67_map_regs(a) ^ C67_map_regs(b); - ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a)); - - C67_g((C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x use cross path for src2 - (0x5f << 5) | //opcode - (0x6 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side for reg c - (0 << 0)); //parallel - } else if (strstr(s, "CMPGTU") == s) { - xpath = C67_map_regs(a) ^ C67_map_regs(b); - ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a)); - - C67_g((C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x use cross path for src2 - (0x4f << 5) | //opcode - (0x6 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side for reg c - (0 << 0)); //parallel - } else if (strstr(s, "B DISP") == s) { - C67_g((0 << 29) | //creg - (0 << 28) | //z - (a << 7) | //cnst - (0x4 << 2) | //opcode fixed - (0 << 1) | //S0/S1 - (0 << 0)); //parallel - } else if (strstr(s, "B.") == s) { - xpath = C67_map_regs(c) ^ 1; - - C67_g((C67_map_regc(b) << 29) | //creg - (a << 28) | //inv - (0 << 23) | //dst - (C67_map_regn(c) << 18) | //src2 - (0 << 13) | // - (xpath << 12) | //x cross path if !B side - (0xd << 6) | //opcode - (0x8 << 2) | //opcode fixed - (1 << 1) | //must be S2 - (0 << 0)); //parallel - } else if (strstr(s, "MV.L") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 - (0 << 13) | //src1 (cst5) - (xpath << 12) | //x cross path if opposite sides - (0x2 << 5) | //opcode - (0x6 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "SPTRUNC.L") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 - (0 << 13) | //src1 NA - (xpath << 12) | //x cross path if opposite sides - (0xb << 5) | //opcode - (0x6 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "DPTRUNC.L") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - ((C67_map_regn(b) + 1) << 18) | //src2 WEIRD CPU must specify odd reg for some reason - (0 << 13) | //src1 NA - (xpath << 12) | //x cross path if opposite sides - (0x1 << 5) | //opcode - (0x6 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "INTSP.L") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 - (0 << 13) | //src1 NA - (xpath << 12) | //x cross path if opposite sides - (0x4a << 5) | //opcode - (0x6 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "INTSPU.L") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 - (0 << 13) | //src1 NA - (xpath << 12) | //x cross path if opposite sides - (0x49 << 5) | //opcode - (0x6 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "INTDP.L") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 - (0 << 13) | //src1 NA - (xpath << 12) | //x cross path if opposite sides - (0x39 << 5) | //opcode - (0x6 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "INTDPU.L") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - ((C67_map_regn(b) + 1) << 18) | //src2 WEIRD CPU must specify odd reg for some reason - (0 << 13) | //src1 NA - (xpath << 12) | //x cross path if opposite sides - (0x3b << 5) | //opcode - (0x6 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "SPDP.L") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 - (0 << 13) | //src1 NA - (xpath << 12) | //x cross path if opposite sides - (0x2 << 6) | //opcode - (0x8 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "DPSP.L") == s) { - ALWAYS_ASSERT(C67_map_regs(b) == C67_map_regs(c)); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - ((C67_map_regn(b) + 1) << 18) | //src2 WEIRD CPU must specify odd reg for some reason - (0 << 13) | //src1 NA - (0 << 12) | //x cross path if opposite sides - (0x9 << 5) | //opcode - (0x6 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "ADD.L") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c)); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 (possible x path) - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x cross path if opposite sides - (0x3 << 5) | //opcode - (0x6 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "SUB.L") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c)); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 (possible x path) - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x cross path if opposite sides - (0x7 << 5) | //opcode - (0x6 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "OR.L") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c)); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 (possible x path) - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x cross path if opposite sides - (0x7f << 5) | //opcode - (0x6 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "AND.L") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c)); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 (possible x path) - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x cross path if opposite sides - (0x7b << 5) | //opcode - (0x6 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "XOR.L") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c)); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 (possible x path) - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x cross path if opposite sides - (0x6f << 5) | //opcode - (0x6 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "ADDSP.L") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c)); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 (possible x path) - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x cross path if opposite sides - (0x10 << 5) | //opcode - (0x6 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "ADDDP.L") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c)); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 (possible x path) - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x cross path if opposite sides - (0x18 << 5) | //opcode - (0x6 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "SUBSP.L") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c)); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 (possible x path) - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x cross path if opposite sides - (0x11 << 5) | //opcode - (0x6 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "SUBDP.L") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c)); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 (possible x path) - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x cross path if opposite sides - (0x19 << 5) | //opcode - (0x6 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "MPYSP.M") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c)); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 (possible x path) - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x cross path if opposite sides - (0x1c << 7) | //opcode - (0x0 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "MPYDP.M") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c)); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 (possible x path) - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x cross path if opposite sides - (0x0e << 7) | //opcode - (0x0 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "MPYI.M") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c)); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 - (C67_map_regn(a) << 13) | //src1 (cst5) - (xpath << 12) | //x cross path if opposite sides - (0x4 << 7) | //opcode - (0x0 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "SHR.S") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a)); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x cross path if opposite sides - (0x37 << 6) | //opcode - (0x8 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "SHRU.S") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a)); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x cross path if opposite sides - (0x27 << 6) | //opcode - (0x8 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "SHL.S") == s) { - xpath = C67_map_regs(b) ^ C67_map_regs(c); - - ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a)); - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(c) << 23) | //dst - (C67_map_regn(b) << 18) | //src2 - (C67_map_regn(a) << 13) | //src1 - (xpath << 12) | //x cross path if opposite sides - (0x33 << 6) | //opcode - (0x8 << 2) | //opcode fixed - (C67_map_regs(c) << 1) | //side of dest - (0 << 0)); //parallel - } else if (strstr(s, "||ADDK") == s) { - xpath = 0; // no xpath required just use the side of the src/dst - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(b) << 23) | //dst - (a << 07) | //scst16 - (0x14 << 2) | //opcode fixed - (C67_map_regs(b) << 1) | //side of dst - (1 << 0)); //parallel - } else if (strstr(s, "ADDK") == s) { - xpath = 0; // no xpath required just use the side of the src/dst - - C67_g((0 << 29) | //creg - (0 << 28) | //inv - (C67_map_regn(b) << 23) | //dst - (a << 07) | //scst16 - (0x14 << 2) | //opcode fixed - (C67_map_regs(b) << 1) | //side of dst - (0 << 0)); //parallel - } else if (strstr(s, "NOP") == s) { - C67_g(((a - 1) << 13) | //no of cycles - (0 << 0)); //parallel - } else - ALWAYS_ASSERT(FALSE); - -#ifdef ASSEMBLY_LISTING_C67 - fprintf(f, " %s %d %d %d\n", s, a, b, c); -#endif - -} - -//r=reg to load, fr=from reg, symbol for relocation, constant - -void C67_MVKL(int r, int fc) -{ - C67_asm("MVKL.", fc, r, 0); -} - -void C67_MVKH(int r, int fc) -{ - C67_asm("MVKH.", fc, r, 0); -} - -void C67_STB_SP_A0(int r) -{ - C67_asm("STB.D *+SP[A0]", r, 0, 0); // STB r,*+SP[A0] -} - -void C67_STH_SP_A0(int r) -{ - C67_asm("STH.D *+SP[A0]", r, 0, 0); // STH r,*+SP[A0] -} - -void C67_STW_SP_A0(int r) -{ - C67_asm("STW.D *+SP[A0]", r, 0, 0); // STW r,*+SP[A0] -} - -void C67_STB_PTR(int r, int r2) -{ - C67_asm("STB.D *", r, r2, 0); // STB r, *r2 -} - -void C67_STH_PTR(int r, int r2) -{ - C67_asm("STH.D *", r, r2, 0); // STH r, *r2 -} - -void C67_STW_PTR(int r, int r2) -{ - C67_asm("STW.D *", r, r2, 0); // STW r, *r2 -} - -void C67_STW_PTR_PRE_INC(int r, int r2, int n) -{ - C67_asm("STW.D +*", r, r2, n); // STW r, *+r2 -} - -void C67_PUSH(int r) -{ - C67_asm("STW.D SP POST DEC", r, 0, 0); // STW r,*SP-- -} - -void C67_LDW_SP_A0(int r) -{ - C67_asm("LDW.D *+SP[A0]", r, 0, 0); // LDW *+SP[A0],r -} - -void C67_LDDW_SP_A0(int r) -{ - C67_asm("LDDW.D *+SP[A0]", r, 0, 0); // LDDW *+SP[A0],r -} - -void C67_LDH_SP_A0(int r) -{ - C67_asm("LDH.D *+SP[A0]", r, 0, 0); // LDH *+SP[A0],r -} - -void C67_LDB_SP_A0(int r) -{ - C67_asm("LDB.D *+SP[A0]", r, 0, 0); // LDB *+SP[A0],r -} - -void C67_LDHU_SP_A0(int r) -{ - C67_asm("LDHU.D *+SP[A0]", r, 0, 0); // LDHU *+SP[A0],r -} - -void C67_LDBU_SP_A0(int r) -{ - C67_asm("LDBU.D *+SP[A0]", r, 0, 0); // LDBU *+SP[A0],r -} - -void C67_LDW_PTR(int r, int r2) -{ - C67_asm("LDW.D *", r, r2, 0); // LDW *r,r2 -} - -void C67_LDDW_PTR(int r, int r2) -{ - C67_asm("LDDW.D *", r, r2, 0); // LDDW *r,r2 -} - -void C67_LDH_PTR(int r, int r2) -{ - C67_asm("LDH.D *", r, r2, 0); // LDH *r,r2 -} - -void C67_LDB_PTR(int r, int r2) -{ - C67_asm("LDB.D *", r, r2, 0); // LDB *r,r2 -} - -void C67_LDHU_PTR(int r, int r2) -{ - C67_asm("LDHU.D *", r, r2, 0); // LDHU *r,r2 -} - -void C67_LDBU_PTR(int r, int r2) -{ - C67_asm("LDBU.D *", r, r2, 0); // LDBU *r,r2 -} - -void C67_LDW_PTR_PRE_INC(int r, int r2) -{ - C67_asm("LDW.D +*", r, r2, 0); // LDW *+r,r2 -} - -void C67_POP(int r) -{ - C67_asm("LDW.D SP PRE INC", r, 0, 0); // LDW *++SP,r -} - -void C67_POP_DW(int r) -{ - C67_asm("LDDW.D SP PRE INC", r, 0, 0); // LDDW *++SP,r -} - -void C67_CMPLT(int s1, int s2, int dst) -{ - C67_asm("CMPLT.L1", s1, s2, dst); -} - -void C67_CMPGT(int s1, int s2, int dst) -{ - C67_asm("CMPGT.L1", s1, s2, dst); -} - -void C67_CMPEQ(int s1, int s2, int dst) -{ - C67_asm("CMPEQ.L1", s1, s2, dst); -} - -void C67_CMPLTU(int s1, int s2, int dst) -{ - C67_asm("CMPLTU.L1", s1, s2, dst); -} - -void C67_CMPGTU(int s1, int s2, int dst) -{ - C67_asm("CMPGTU.L1", s1, s2, dst); -} - - -void C67_CMPLTSP(int s1, int s2, int dst) -{ - C67_asm("CMPLTSP.S1", s1, s2, dst); -} - -void C67_CMPGTSP(int s1, int s2, int dst) -{ - C67_asm("CMPGTSP.S1", s1, s2, dst); -} - -void C67_CMPEQSP(int s1, int s2, int dst) -{ - C67_asm("CMPEQSP.S1", s1, s2, dst); -} - -void C67_CMPLTDP(int s1, int s2, int dst) -{ - C67_asm("CMPLTDP.S1", s1, s2, dst); -} - -void C67_CMPGTDP(int s1, int s2, int dst) -{ - C67_asm("CMPGTDP.S1", s1, s2, dst); -} - -void C67_CMPEQDP(int s1, int s2, int dst) -{ - C67_asm("CMPEQDP.S1", s1, s2, dst); -} - - -void C67_IREG_B_REG(int inv, int r1, int r2) // [!R] B r2 -{ - C67_asm("B.S2", inv, r1, r2); -} - - -// call with how many 32 bit words to skip -// (0 would branch to the branch instruction) - -void C67_B_DISP(int disp) // B +2 Branch with constant displacement -{ - // Branch point is relative to the 8 word fetch packet - // - // we will assume the text section always starts on an 8 word (32 byte boundary) - // - // so add in how many words into the fetch packet the branch is - - - C67_asm("B DISP", disp + ((ind & 31) >> 2), 0, 0); -} - -void C67_NOP(int n) -{ - C67_asm("NOP", n, 0, 0); -} - -void C67_ADDK(int n, int r) -{ - ALWAYS_ASSERT(abs(n) < 32767); - - C67_asm("ADDK", n, r, 0); -} - -void C67_ADDK_PARALLEL(int n, int r) -{ - ALWAYS_ASSERT(abs(n) < 32767); - - C67_asm("||ADDK", n, r, 0); -} - -void C67_Adjust_ADDK(int *inst, int n) -{ - ALWAYS_ASSERT(abs(n) < 32767); - - *inst = (*inst & (~(0xffff << 7))) | ((n & 0xffff) << 7); -} - -void C67_MV(int r, int v) -{ - C67_asm("MV.L", 0, r, v); -} - - -void C67_DPTRUNC(int r, int v) -{ - C67_asm("DPTRUNC.L", 0, r, v); -} - -void C67_SPTRUNC(int r, int v) -{ - C67_asm("SPTRUNC.L", 0, r, v); -} - -void C67_INTSP(int r, int v) -{ - C67_asm("INTSP.L", 0, r, v); -} - -void C67_INTDP(int r, int v) -{ - C67_asm("INTDP.L", 0, r, v); -} - -void C67_INTSPU(int r, int v) -{ - C67_asm("INTSPU.L", 0, r, v); -} - -void C67_INTDPU(int r, int v) -{ - C67_asm("INTDPU.L", 0, r, v); -} - -void C67_SPDP(int r, int v) -{ - C67_asm("SPDP.L", 0, r, v); -} - -void C67_DPSP(int r, int v) // note regs must be on the same side -{ - C67_asm("DPSP.L", 0, r, v); -} - -void C67_ADD(int r, int v) -{ - C67_asm("ADD.L", v, r, v); -} - -void C67_SUB(int r, int v) -{ - C67_asm("SUB.L", v, r, v); -} - -void C67_AND(int r, int v) -{ - C67_asm("AND.L", v, r, v); -} - -void C67_OR(int r, int v) -{ - C67_asm("OR.L", v, r, v); -} - -void C67_XOR(int r, int v) -{ - C67_asm("XOR.L", v, r, v); -} - -void C67_ADDSP(int r, int v) -{ - C67_asm("ADDSP.L", v, r, v); -} - -void C67_SUBSP(int r, int v) -{ - C67_asm("SUBSP.L", v, r, v); -} - -void C67_MPYSP(int r, int v) -{ - C67_asm("MPYSP.M", v, r, v); -} - -void C67_ADDDP(int r, int v) -{ - C67_asm("ADDDP.L", v, r, v); -} - -void C67_SUBDP(int r, int v) -{ - C67_asm("SUBDP.L", v, r, v); -} - -void C67_MPYDP(int r, int v) -{ - C67_asm("MPYDP.M", v, r, v); -} - -void C67_MPYI(int r, int v) -{ - C67_asm("MPYI.M", v, r, v); -} - -void C67_SHL(int r, int v) -{ - C67_asm("SHL.S", r, v, v); -} - -void C67_SHRU(int r, int v) -{ - C67_asm("SHRU.S", r, v, v); -} - -void C67_SHR(int r, int v) -{ - C67_asm("SHR.S", r, v, v); -} - - - -/* load 'r' from value 'sv' */ -void load(int r, SValue * sv) -{ - int v, t, ft, fc, fr, size = 0, element; - BOOL Unsigned = FALSE; - SValue v1; - - fr = sv->r; - ft = sv->type.t; - fc = sv->c.i; - - v = fr & VT_VALMASK; - if (fr & VT_LVAL) { - if (v == VT_LLOCAL) { - v1.type.t = VT_INT; - v1.r = VT_LOCAL | VT_LVAL; - v1.c.i = fc; - load(r, &v1); - fr = r; - } else if ((ft & VT_BTYPE) == VT_LDOUBLE) { - tcc_error("long double not supported"); - } else if ((ft & VT_TYPE) == VT_BYTE) { - size = 1; - } else if ((ft & VT_TYPE) == (VT_BYTE | VT_UNSIGNED)) { - size = 1; - Unsigned = TRUE; - } else if ((ft & VT_TYPE) == VT_SHORT) { - size = 2; - } else if ((ft & VT_TYPE) == (VT_SHORT | VT_UNSIGNED)) { - size = 2; - Unsigned = TRUE; - } else if ((ft & VT_BTYPE) == VT_DOUBLE) { - size = 8; - } else { - size = 4; - } - - // check if fc is a positive reference on the stack, - // if it is tcc is referencing what it thinks is a parameter - // on the stack, so check if it is really in a register. - - - if (v == VT_LOCAL && fc > 0) { - int stack_pos = 8; - - for (t = 0; t < NoCallArgsPassedOnStack; t++) { - if (fc == stack_pos) - break; - - stack_pos += TranslateStackToReg[t]; - } - - // param has been pushed on stack, get it like a local var - - fc = ParamLocOnStack[t] - 8; - } - - if ((fr & VT_VALMASK) < VT_CONST) // check for pure indirect - { - if (size == 1) { - if (Unsigned) - C67_LDBU_PTR(v, r); // LDBU *v,r - else - C67_LDB_PTR(v, r); // LDB *v,r - } else if (size == 2) { - if (Unsigned) - C67_LDHU_PTR(v, r); // LDHU *v,r - else - C67_LDH_PTR(v, r); // LDH *v,r - } else if (size == 4) { - C67_LDW_PTR(v, r); // LDW *v,r - } else if (size == 8) { - C67_LDDW_PTR(v, r); // LDDW *v,r - } - - C67_NOP(4); // NOP 4 - return; - } else if (fr & VT_SYM) { - greloc(cur_text_section, sv->sym, ind, R_C60LO16); // rem the inst need to be patched - greloc(cur_text_section, sv->sym, ind + 4, R_C60HI16); - - - C67_MVKL(C67_A0, fc); //r=reg to load, constant - C67_MVKH(C67_A0, fc); //r=reg to load, constant - - - if (size == 1) { - if (Unsigned) - C67_LDBU_PTR(C67_A0, r); // LDBU *A0,r - else - C67_LDB_PTR(C67_A0, r); // LDB *A0,r - } else if (size == 2) { - if (Unsigned) - C67_LDHU_PTR(C67_A0, r); // LDHU *A0,r - else - C67_LDH_PTR(C67_A0, r); // LDH *A0,r - } else if (size == 4) { - C67_LDW_PTR(C67_A0, r); // LDW *A0,r - } else if (size == 8) { - C67_LDDW_PTR(C67_A0, r); // LDDW *A0,r - } - - C67_NOP(4); // NOP 4 - return; - } else { - element = size; - - // divide offset in bytes to create element index - C67_MVKL(C67_A0, (fc / element) + 8 / element); //r=reg to load, constant - C67_MVKH(C67_A0, (fc / element) + 8 / element); //r=reg to load, constant - - if (size == 1) { - if (Unsigned) - C67_LDBU_SP_A0(r); // LDBU r, SP[A0] - else - C67_LDB_SP_A0(r); // LDB r, SP[A0] - } else if (size == 2) { - if (Unsigned) - C67_LDHU_SP_A0(r); // LDHU r, SP[A0] - else - C67_LDH_SP_A0(r); // LDH r, SP[A0] - } else if (size == 4) { - C67_LDW_SP_A0(r); // LDW r, SP[A0] - } else if (size == 8) { - C67_LDDW_SP_A0(r); // LDDW r, SP[A0] - } - - - C67_NOP(4); // NOP 4 - return; - } - } else { - if (v == VT_CONST) { - if (fr & VT_SYM) { - greloc(cur_text_section, sv->sym, ind, R_C60LO16); // rem the inst need to be patched - greloc(cur_text_section, sv->sym, ind + 4, R_C60HI16); - } - C67_MVKL(r, fc); //r=reg to load, constant - C67_MVKH(r, fc); //r=reg to load, constant - } else if (v == VT_LOCAL) { - C67_MVKL(r, fc + 8); //r=reg to load, constant C67 stack points to next free - C67_MVKH(r, fc + 8); //r=reg to load, constant - C67_ADD(C67_FP, r); // MV v,r v -> r - } else if (v == VT_CMP) { - C67_MV(C67_compare_reg, r); // MV v,r v -> r - } else if (v == VT_JMP || v == VT_JMPI) { - t = v & 1; - C67_B_DISP(4); // Branch with constant displacement, skip over this branch, load, nop, load - C67_MVKL(r, t); // r=reg to load, 0 or 1 (do this while branching) - C67_NOP(4); // NOP 4 - gsym(fc); // modifies other branches to branch here - C67_MVKL(r, t ^ 1); // r=reg to load, 0 or 1 - } else if (v != r) { - C67_MV(v, r); // MV v,r v -> r - - if ((ft & VT_BTYPE) == VT_DOUBLE) - C67_MV(v + 1, r + 1); // MV v,r v -> r - } - } -} - - -/* store register 'r' in lvalue 'v' */ -void store(int r, SValue * v) -{ - int fr, bt, ft, fc, size, t, element; - - ft = v->type.t; - fc = v->c.i; - fr = v->r & VT_VALMASK; - bt = ft & VT_BTYPE; - /* XXX: incorrect if float reg to reg */ - - if (bt == VT_LDOUBLE) { - tcc_error("long double not supported"); - } else { - if (bt == VT_SHORT) - size = 2; - else if (bt == VT_BYTE) - size = 1; - else if (bt == VT_DOUBLE) - size = 8; - else - size = 4; - - if ((v->r & VT_VALMASK) == VT_CONST) { - /* constant memory reference */ - - if (v->r & VT_SYM) { - greloc(cur_text_section, v->sym, ind, R_C60LO16); // rem the inst need to be patched - greloc(cur_text_section, v->sym, ind + 4, R_C60HI16); - } - C67_MVKL(C67_A0, fc); //r=reg to load, constant - C67_MVKH(C67_A0, fc); //r=reg to load, constant - - if (size == 1) - C67_STB_PTR(r, C67_A0); // STB r, *A0 - else if (size == 2) - C67_STH_PTR(r, C67_A0); // STH r, *A0 - else if (size == 4 || size == 8) - C67_STW_PTR(r, C67_A0); // STW r, *A0 - - if (size == 8) - C67_STW_PTR_PRE_INC(r + 1, C67_A0, 1); // STW r, *+A0[1] - } else if ((v->r & VT_VALMASK) == VT_LOCAL) { - // check case of storing to passed argument that - // tcc thinks is on the stack but for C67 is - // passed as a reg. However it may have been - // saved to the stack, if that reg was required - // for a call to a child function - - if (fc > 0) // argument ?? - { - // walk through sizes and figure which param - - int stack_pos = 8; - - for (t = 0; t < NoCallArgsPassedOnStack; t++) { - if (fc == stack_pos) - break; - - stack_pos += TranslateStackToReg[t]; - } - - // param has been pushed on stack, get it like a local var - fc = ParamLocOnStack[t] - 8; - } - - if (size == 8) - element = 4; - else - element = size; - - // divide offset in bytes to create word index - C67_MVKL(C67_A0, (fc / element) + 8 / element); //r=reg to load, constant - C67_MVKH(C67_A0, (fc / element) + 8 / element); //r=reg to load, constant - - - - if (size == 1) - C67_STB_SP_A0(r); // STB r, SP[A0] - else if (size == 2) - C67_STH_SP_A0(r); // STH r, SP[A0] - else if (size == 4 || size == 8) - C67_STW_SP_A0(r); // STW r, SP[A0] - - if (size == 8) { - C67_ADDK(1, C67_A0); // ADDK 1,A0 - C67_STW_SP_A0(r + 1); // STW r, SP[A0] - } - } else { - if (size == 1) - C67_STB_PTR(r, fr); // STB r, *fr - else if (size == 2) - C67_STH_PTR(r, fr); // STH r, *fr - else if (size == 4 || size == 8) - C67_STW_PTR(r, fr); // STW r, *fr - - if (size == 8) { - C67_STW_PTR_PRE_INC(r + 1, fr, 1); // STW r, *+fr[1] - } - } - } -} - -/* 'is_jmp' is '1' if it is a jump */ -static void gcall_or_jmp(int is_jmp) -{ - int r; - Sym *sym; - - if ((vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST) { - /* constant case */ - if (vtop->r & VT_SYM) { - /* relocation case */ - - // get add into A0, then start the jump B3 - - greloc(cur_text_section, vtop->sym, ind, R_C60LO16); // rem the inst need to be patched - greloc(cur_text_section, vtop->sym, ind + 4, R_C60HI16); - - C67_MVKL(C67_A0, 0); //r=reg to load, constant - C67_MVKH(C67_A0, 0); //r=reg to load, constant - C67_IREG_B_REG(0, C67_CREG_ZERO, C67_A0); // B.S2x A0 - - if (is_jmp) { - C67_NOP(5); // simple jump, just put NOP - } else { - // Call, must load return address into B3 during delay slots - - sym = get_sym_ref(&char_pointer_type, cur_text_section, ind + 12, 0); // symbol for return address - greloc(cur_text_section, sym, ind, R_C60LO16); // rem the inst need to be patched - greloc(cur_text_section, sym, ind + 4, R_C60HI16); - C67_MVKL(C67_B3, 0); //r=reg to load, constant - C67_MVKH(C67_B3, 0); //r=reg to load, constant - C67_NOP(3); // put remaining NOPs - } - } else { - /* put an empty PC32 relocation */ - ALWAYS_ASSERT(FALSE); - } - } else { - /* otherwise, indirect call */ - r = gv(RC_INT); - C67_IREG_B_REG(0, C67_CREG_ZERO, r); // B.S2x r - - if (is_jmp) { - C67_NOP(5); // simple jump, just put NOP - } else { - // Call, must load return address into B3 during delay slots - - sym = get_sym_ref(&char_pointer_type, cur_text_section, ind + 12, 0); // symbol for return address - greloc(cur_text_section, sym, ind, R_C60LO16); // rem the inst need to be patched - greloc(cur_text_section, sym, ind + 4, R_C60HI16); - C67_MVKL(C67_B3, 0); //r=reg to load, constant - C67_MVKH(C67_B3, 0); //r=reg to load, constant - C67_NOP(3); // put remaining NOPs - } - } -} - -/* Return the number of registers needed to return the struct, or 0 if - returning via struct pointer. */ -ST_FUNC int gfunc_sret(CType *vt, int variadic, CType *ret, int *ret_align, int *regsize) { - *ret_align = 1; // Never have to re-align return values for x86-64 - return 0; -} - -/* generate function call with address in (vtop->t, vtop->c) and free function - context. Stack entry is popped */ -void gfunc_call(int nb_args) -{ - int i, r, size = 0; - int args_sizes[NoCallArgsPassedOnStack]; - - if (nb_args > NoCallArgsPassedOnStack) { - tcc_error("more than 10 function params not currently supported"); - // handle more than 10, put some on the stack - } - - for (i = 0; i < nb_args; i++) { - if ((vtop->type.t & VT_BTYPE) == VT_STRUCT) { - ALWAYS_ASSERT(FALSE); - } else { - /* simple type (currently always same size) */ - /* XXX: implicit cast ? */ - - - if ((vtop->type.t & VT_BTYPE) == VT_LLONG) { - tcc_error("long long not supported"); - } else if ((vtop->type.t & VT_BTYPE) == VT_LDOUBLE) { - tcc_error("long double not supported"); - } else if ((vtop->type.t & VT_BTYPE) == VT_DOUBLE) { - size = 8; - } else { - size = 4; - } - - // put the parameter into the corresponding reg (pair) - - r = gv(RC_C67_A4 << (2 * i)); - - // must put on stack because with 1 pass compiler , no way to tell - // if an up coming nested call might overwrite these regs - - C67_PUSH(r); - - if (size == 8) { - C67_STW_PTR_PRE_INC(r + 1, C67_SP, 3); // STW r, *+SP[3] (go back and put the other) - } - args_sizes[i] = size; - } - vtop--; - } - // POP all the params on the stack into registers for the - // immediate call (in reverse order) - - for (i = nb_args - 1; i >= 0; i--) { - - if (args_sizes[i] == 8) - C67_POP_DW(TREG_C67_A4 + i * 2); - else - C67_POP(TREG_C67_A4 + i * 2); - } - gcall_or_jmp(0); - vtop--; -} - - -// to be compatible with Code Composer for the C67 -// the first 10 parameters must be passed in registers -// (pairs for 64 bits) starting wit; A4:A5, then B4:B5 and -// ending with B12:B13. -// -// When a call is made, if the caller has its parameters -// in regs A4-B13 these must be saved before/as the call -// parameters are loaded and restored upon return (or if/when needed). - -/* generate function prolog of type 't' */ -void gfunc_prolog(Sym *func_sym) -{ - CType *func_type = &func_sym->type; - int addr, align, size, func_call, i; - Sym *sym; - CType *type; - - sym = func_type->ref; - func_call = sym->f.func_call; - addr = 8; - /* if the function returns a structure, then add an - implicit pointer parameter */ - if ((func_vt.t & VT_BTYPE) == VT_STRUCT) { - func_vc = addr; - addr += 4; - } - - NoOfCurFuncArgs = 0; - - /* define parameters */ - while ((sym = sym->next) != NULL) { - type = &sym->type; - sym_push(sym->v & ~SYM_FIELD, type, VT_LOCAL | VT_LVAL, addr); - size = type_size(type, &align); - size = (size + 3) & ~3; - - // keep track of size of arguments so - // we can translate where tcc thinks they - // are on the stack into the appropriate reg - - TranslateStackToReg[NoOfCurFuncArgs] = size; - NoOfCurFuncArgs++; - -#ifdef FUNC_STRUCT_PARAM_AS_PTR - /* structs are passed as pointer */ - if ((type->t & VT_BTYPE) == VT_STRUCT) { - size = 4; - } -#endif - addr += size; - } - func_ret_sub = 0; - /* pascal type call ? */ - if (func_call == FUNC_STDCALL) - func_ret_sub = addr - 8; - - C67_MV(C67_FP, C67_A0); // move FP -> A0 - C67_MV(C67_SP, C67_FP); // move SP -> FP - - // place all the args passed in regs onto the stack - - loc = 0; - for (i = 0; i < NoOfCurFuncArgs; i++) { - - ParamLocOnStack[i] = loc; // remember where the param is - loc += -8; - - C67_PUSH(TREG_C67_A4 + i * 2); - - if (TranslateStackToReg[i] == 8) { - C67_STW_PTR_PRE_INC(TREG_C67_A4 + i * 2 + 1, C67_SP, 3); // STW r, *+SP[1] (go back and put the other) - } - } - - TotalBytesPushedOnStack = -loc; - - func_sub_sp_offset = ind; // remember where we put the stack instruction - C67_ADDK(0, C67_SP); // ADDK.L2 loc,SP (just put zero temporarily) - - C67_PUSH(C67_A0); - C67_PUSH(C67_B3); -} - -/* generate function epilog */ -void gfunc_epilog(void) -{ - { - int local = (-loc + 7) & -8; // stack must stay aligned to 8 bytes for LDDW instr - C67_POP(C67_B3); - C67_NOP(4); // NOP wait for load - C67_IREG_B_REG(0, C67_CREG_ZERO, C67_B3); // B.S2 B3 - C67_POP(C67_FP); - C67_ADDK(local, C67_SP); // ADDK.L2 loc,SP - C67_Adjust_ADDK((int *) (cur_text_section->data + - func_sub_sp_offset), - -local + TotalBytesPushedOnStack); - C67_NOP(3); // NOP - } -} - -ST_FUNC void gen_fill_nops(int bytes) -{ - if ((bytes & 3)) - tcc_error("alignment of code section not multiple of 4"); - while (bytes > 0) { - C67_NOP(4); - bytes -= 4; - } -} - -/* generate a jump to a label */ -int gjmp(int t) -{ - int ind1 = ind; - if (nocode_wanted) - return t; - - C67_MVKL(C67_A0, t); //r=reg to load, constant - C67_MVKH(C67_A0, t); //r=reg to load, constant - C67_IREG_B_REG(0, C67_CREG_ZERO, C67_A0); // [!R] B.S2x A0 - C67_NOP(5); - return ind1; -} - -/* generate a jump to a fixed address */ -void gjmp_addr(int a) -{ - Sym *sym; - // I guess this routine is used for relative short - // local jumps, for now just handle it as the general - // case - - // define a label that will be relocated - - sym = get_sym_ref(&char_pointer_type, cur_text_section, a, 0); - greloc(cur_text_section, sym, ind, R_C60LO16); - greloc(cur_text_section, sym, ind + 4, R_C60HI16); - - gjmp(0); // place a zero there later the symbol will be added to it -} - -/* generate a test. set 'inv' to invert test. Stack entry is popped */ -ST_FUNC int gjmp_cond(int op, int t) -{ - int ind1; - int inv = op & 1; - if (nocode_wanted) - return t; - - /* fast case : can jump directly since flags are set */ - // C67 uses B2 sort of as flags register - ind1 = ind; - C67_MVKL(C67_A0, t); //r=reg to load, constant - C67_MVKH(C67_A0, t); //r=reg to load, constant - - if (C67_compare_reg != TREG_EAX && // check if not already in a conditional test reg - C67_compare_reg != TREG_EDX && - C67_compare_reg != TREG_ST0 && C67_compare_reg != C67_B2) { - C67_MV(C67_compare_reg, C67_B2); - C67_compare_reg = C67_B2; - } - - C67_IREG_B_REG(C67_invert_test ^ inv, C67_compare_reg, C67_A0); // [!R] B.S2x A0 - C67_NOP(5); - t = ind1; //return where we need to patch - - return t; -} - -ST_FUNC int gjmp_append(int n0, int t) -{ - if (n0) { - int n = n0, *p; - /* insert vtop->c jump list in t */ - - // I guess the idea is to traverse to the - // null at the end of the list and store t - // there - while (n != 0) { - p = (int *) (cur_text_section->data + n); - - // extract 32 bit address from MVKH/MVKL - n = ((*p >> 7) & 0xffff); - n |= ((*(p + 1) >> 7) & 0xffff) << 16; - } - *p |= (t & 0xffff) << 7; - *(p + 1) |= ((t >> 16) & 0xffff) << 7; - t = n0; - } - return t; -} - -/* generate an integer binary operation */ -void gen_opi(int op) -{ - int r, fr, opc, t; - - switch (op) { - case '+': - case TOK_ADDC1: /* add with carry generation */ - opc = 0; - gen_op8: - - -// C67 can't do const compares, must load into a reg -// so just go to gv2 directly - tktk - - - - if (op >= TOK_ULT && op <= TOK_GT) - gv2(RC_INT_BSIDE, RC_INT); // make sure r (src1) is on the B Side of CPU - else - gv2(RC_INT, RC_INT); - - r = vtop[-1].r; - fr = vtop[0].r; - - C67_compare_reg = C67_B2; - - - if (op == TOK_LT) { - C67_CMPLT(r, fr, C67_B2); - C67_invert_test = FALSE; - } else if (op == TOK_GE) { - C67_CMPLT(r, fr, C67_B2); - C67_invert_test = TRUE; - } else if (op == TOK_GT) { - C67_CMPGT(r, fr, C67_B2); - C67_invert_test = FALSE; - } else if (op == TOK_LE) { - C67_CMPGT(r, fr, C67_B2); - C67_invert_test = TRUE; - } else if (op == TOK_EQ) { - C67_CMPEQ(r, fr, C67_B2); - C67_invert_test = FALSE; - } else if (op == TOK_NE) { - C67_CMPEQ(r, fr, C67_B2); - C67_invert_test = TRUE; - } else if (op == TOK_ULT) { - C67_CMPLTU(r, fr, C67_B2); - C67_invert_test = FALSE; - } else if (op == TOK_UGE) { - C67_CMPLTU(r, fr, C67_B2); - C67_invert_test = TRUE; - } else if (op == TOK_UGT) { - C67_CMPGTU(r, fr, C67_B2); - C67_invert_test = FALSE; - } else if (op == TOK_ULE) { - C67_CMPGTU(r, fr, C67_B2); - C67_invert_test = TRUE; - } else if (op == '+') - C67_ADD(fr, r); // ADD r,fr,r - else if (op == '-') - C67_SUB(fr, r); // SUB r,fr,r - else if (op == '&') - C67_AND(fr, r); // AND r,fr,r - else if (op == '|') - C67_OR(fr, r); // OR r,fr,r - else if (op == '^') - C67_XOR(fr, r); // XOR r,fr,r - else - ALWAYS_ASSERT(FALSE); - - vtop--; - if (op >= TOK_ULT && op <= TOK_GT) - vset_VT_CMP(0x80); - break; - case '-': - case TOK_SUBC1: /* sub with carry generation */ - opc = 5; - goto gen_op8; - case TOK_ADDC2: /* add with carry use */ - opc = 2; - goto gen_op8; - case TOK_SUBC2: /* sub with carry use */ - opc = 3; - goto gen_op8; - case '&': - opc = 4; - goto gen_op8; - case '^': - opc = 6; - goto gen_op8; - case '|': - opc = 1; - goto gen_op8; - case '*': - case TOK_UMULL: - gv2(RC_INT, RC_INT); - r = vtop[-1].r; - fr = vtop[0].r; - vtop--; - C67_MPYI(fr, r); // 32 bit multiply fr,r,fr - C67_NOP(8); // NOP 8 for worst case - break; - case TOK_SHL: - gv2(RC_INT_BSIDE, RC_INT_BSIDE); // shift amount must be on same side as dst - r = vtop[-1].r; - fr = vtop[0].r; - vtop--; - C67_SHL(fr, r); // arithmetic/logical shift - break; - - case TOK_SHR: - gv2(RC_INT_BSIDE, RC_INT_BSIDE); // shift amount must be on same side as dst - r = vtop[-1].r; - fr = vtop[0].r; - vtop--; - C67_SHRU(fr, r); // logical shift - break; - - case TOK_SAR: - gv2(RC_INT_BSIDE, RC_INT_BSIDE); // shift amount must be on same side as dst - r = vtop[-1].r; - fr = vtop[0].r; - vtop--; - C67_SHR(fr, r); // arithmetic shift - break; - - case '/': - t = TOK__divi; - call_func: - vswap(); - /* call generic idiv function */ - vpush_helper_func(t); - vrott(3); - gfunc_call(2); - vpushi(0); - vtop->r = REG_IRET; - vtop->r2 = VT_CONST; - break; - case TOK_UDIV: - case TOK_PDIV: - t = TOK__divu; - goto call_func; - case '%': - t = TOK__remi; - goto call_func; - case TOK_UMOD: - t = TOK__remu; - goto call_func; - - default: - opc = 7; - goto gen_op8; - } -} - -/* generate a floating point operation 'v = t1 op t2' instruction. The - two operands are guaranteed to have the same floating point type */ -/* XXX: need to use ST1 too */ -void gen_opf(int op) -{ - int ft, fc, fr, r; - - if (op >= TOK_ULT && op <= TOK_GT) - gv2(RC_EDX, RC_EAX); // make sure src2 is on b side - else - gv2(RC_FLOAT, RC_FLOAT); // make sure src2 is on b side - - ft = vtop->type.t; - fc = vtop->c.i; - r = vtop->r; - fr = vtop[-1].r; - - - if ((ft & VT_BTYPE) == VT_LDOUBLE) - tcc_error("long doubles not supported"); - - if (op >= TOK_ULT && op <= TOK_GT) { - - r = vtop[-1].r; - fr = vtop[0].r; - - C67_compare_reg = C67_B2; - - if (op == TOK_LT) { - if ((ft & VT_BTYPE) == VT_DOUBLE) - C67_CMPLTDP(r, fr, C67_B2); - else - C67_CMPLTSP(r, fr, C67_B2); - - C67_invert_test = FALSE; - } else if (op == TOK_GE) { - if ((ft & VT_BTYPE) == VT_DOUBLE) - C67_CMPLTDP(r, fr, C67_B2); - else - C67_CMPLTSP(r, fr, C67_B2); - - C67_invert_test = TRUE; - } else if (op == TOK_GT) { - if ((ft & VT_BTYPE) == VT_DOUBLE) - C67_CMPGTDP(r, fr, C67_B2); - else - C67_CMPGTSP(r, fr, C67_B2); - - C67_invert_test = FALSE; - } else if (op == TOK_LE) { - if ((ft & VT_BTYPE) == VT_DOUBLE) - C67_CMPGTDP(r, fr, C67_B2); - else - C67_CMPGTSP(r, fr, C67_B2); - - C67_invert_test = TRUE; - } else if (op == TOK_EQ) { - if ((ft & VT_BTYPE) == VT_DOUBLE) - C67_CMPEQDP(r, fr, C67_B2); - else - C67_CMPEQSP(r, fr, C67_B2); - - C67_invert_test = FALSE; - } else if (op == TOK_NE) { - if ((ft & VT_BTYPE) == VT_DOUBLE) - C67_CMPEQDP(r, fr, C67_B2); - else - C67_CMPEQSP(r, fr, C67_B2); - - C67_invert_test = TRUE; - } else { - ALWAYS_ASSERT(FALSE); - } - vset_VT_CMP(0x80); - } else { - if (op == '+') { - if ((ft & VT_BTYPE) == VT_DOUBLE) { - C67_ADDDP(r, fr); // ADD fr,r,fr - C67_NOP(6); - } else { - C67_ADDSP(r, fr); // ADD fr,r,fr - C67_NOP(3); - } - vtop--; - } else if (op == '-') { - if ((ft & VT_BTYPE) == VT_DOUBLE) { - C67_SUBDP(r, fr); // SUB fr,r,fr - C67_NOP(6); - } else { - C67_SUBSP(r, fr); // SUB fr,r,fr - C67_NOP(3); - } - vtop--; - } else if (op == '*') { - if ((ft & VT_BTYPE) == VT_DOUBLE) { - C67_MPYDP(r, fr); // MPY fr,r,fr - C67_NOP(9); - } else { - C67_MPYSP(r, fr); // MPY fr,r,fr - C67_NOP(3); - } - vtop--; - } else if (op == '/') { - if ((ft & VT_BTYPE) == VT_DOUBLE) { - // must call intrinsic DP floating point divide - vswap(); - /* call generic idiv function */ - vpush_helper_func(TOK__divd); - vrott(3); - gfunc_call(2); - vpushi(0); - vtop->r = REG_FRET; - vtop->r2 = REG_IRE2; - - } else { - // must call intrinsic SP floating point divide - vswap(); - /* call generic idiv function */ - vpush_helper_func(TOK__divf); - vrott(3); - gfunc_call(2); - vpushi(0); - vtop->r = REG_FRET; - vtop->r2 = VT_CONST; - } - } else - ALWAYS_ASSERT(FALSE); - - - } -} - - -/* convert integers to fp 't' type. Must handle 'int', 'unsigned int' - and 'long long' cases. */ -void gen_cvt_itof(int t) -{ - int r; - - gv(RC_INT); - r = vtop->r; - - if ((t & VT_BTYPE) == VT_DOUBLE) { - if (t & VT_UNSIGNED) - C67_INTDPU(r, r); - else - C67_INTDP(r, r); - - C67_NOP(4); - vtop->type.t = VT_DOUBLE; - } else { - if (t & VT_UNSIGNED) - C67_INTSPU(r, r); - else - C67_INTSP(r, r); - C67_NOP(3); - vtop->type.t = VT_FLOAT; - } - -} - -/* convert fp to int 't' type */ -/* XXX: handle long long case */ -void gen_cvt_ftoi(int t) -{ - int r; - - gv(RC_FLOAT); - r = vtop->r; - - if (t != VT_INT) - tcc_error("long long not supported"); - else { - if ((vtop->type.t & VT_BTYPE) == VT_DOUBLE) { - C67_DPTRUNC(r, r); - C67_NOP(3); - } else { - C67_SPTRUNC(r, r); - C67_NOP(3); - } - - vtop->type.t = VT_INT; - - } -} - -/* convert from one floating point type to another */ -void gen_cvt_ftof(int t) -{ - int r, r2; - - if ((vtop->type.t & VT_BTYPE) == VT_DOUBLE && - (t & VT_BTYPE) == VT_FLOAT) { - // convert double to float - - gv(RC_FLOAT); // get it in a register pair - - r = vtop->r; - - C67_DPSP(r, r); // convert it to SP same register - C67_NOP(3); - - vtop->type.t = VT_FLOAT; - vtop->r2 = VT_CONST; // set this as unused - } else if ((vtop->type.t & VT_BTYPE) == VT_FLOAT && - (t & VT_BTYPE) == VT_DOUBLE) { - // convert float to double - - gv(RC_FLOAT); // get it in a register - - r = vtop->r; - - if (r == TREG_EAX) { // make sure the paired reg is avail - r2 = get_reg(RC_ECX); - } else if (r == TREG_EDX) { - r2 = get_reg(RC_ST0); - } else { - ALWAYS_ASSERT(FALSE); - r2 = 0; /* avoid warning */ - } - - C67_SPDP(r, r); // convert it to DP same register - C67_NOP(1); - - vtop->type.t = VT_DOUBLE; - vtop->r2 = r2; // set this as unused - } else { - ALWAYS_ASSERT(FALSE); - } -} - -/* computed goto support */ -void ggoto(void) -{ - gcall_or_jmp(1); - vtop--; -} - -/* Save the stack pointer onto the stack and return the location of its address */ -ST_FUNC void gen_vla_sp_save(int addr) { - tcc_error("variable length arrays unsupported for this target"); -} - -/* Restore the SP from a location on the stack */ -ST_FUNC void gen_vla_sp_restore(int addr) { - tcc_error("variable length arrays unsupported for this target"); -} - -/* Subtract from the stack pointer, and push the resulting value onto the stack */ -ST_FUNC void gen_vla_alloc(CType *type, int align) { - tcc_error("variable length arrays unsupported for this target"); -} - -/* end of C67 code generator */ -/*************************************************************/ -#endif -/*************************************************************/ diff --git a/05/tcc-final/c67-link.c b/05/tcc-final/c67-link.c deleted file mode 100644 index 514689c..0000000 --- a/05/tcc-final/c67-link.c +++ /dev/null @@ -1,125 +0,0 @@ -#ifdef TARGET_DEFS_ONLY - -#define EM_TCC_TARGET EM_C60 - -/* relocation type for 32 bit data relocation */ -#define R_DATA_32 R_C60_32 -#define R_DATA_PTR R_C60_32 -#define R_JMP_SLOT R_C60_JMP_SLOT -#define R_GLOB_DAT R_C60_GLOB_DAT -#define R_COPY R_C60_COPY -#define R_RELATIVE R_C60_RELATIVE - -#define R_NUM R_C60_NUM - -#define ELF_START_ADDR 0x00000400 -#define ELF_PAGE_SIZE 0x1000 - -#define PCRELATIVE_DLLPLT 0 -#define RELOCATE_DLLPLT 0 - -#else /* !TARGET_DEFS_ONLY */ - -#include "tcc.h" - -/* Returns 1 for a code relocation, 0 for a data relocation. For unknown - relocations, returns -1. */ -int code_reloc (int reloc_type) -{ - switch (reloc_type) { - case R_C60_32: - case R_C60LO16: - case R_C60HI16: - case R_C60_GOT32: - case R_C60_GOTOFF: - case R_C60_GOTPC: - case R_C60_COPY: - return 0; - - case R_C60_PLT32: - return 1; - } - return -1; -} - -/* Returns an enumerator to describe whether and when the relocation needs a - GOT and/or PLT entry to be created. See tcc.h for a description of the - different values. */ -int gotplt_entry_type (int reloc_type) -{ - switch (reloc_type) { - case R_C60_32: - case R_C60LO16: - case R_C60HI16: - case R_C60_COPY: - return NO_GOTPLT_ENTRY; - - case R_C60_GOTOFF: - case R_C60_GOTPC: - return BUILD_GOT_ONLY; - - case R_C60_PLT32: - case R_C60_GOT32: - return ALWAYS_GOTPLT_ENTRY; - } - return -1; -} - -ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr) -{ - tcc_error("C67 got not implemented"); - return 0; -} - -/* relocate the PLT: compute addresses and offsets in the PLT now that final - address for PLT and GOT are known (see fill_program_header) */ -ST_FUNC void relocate_plt(TCCState *s1) -{ - uint8_t *p, *p_end; - - if (!s1->plt) - return; - - p = s1->plt->data; - p_end = p + s1->plt->data_offset; - - if (p < p_end) { - /* XXX: TODO */ - while (p < p_end) { - /* XXX: TODO */ - } - } -} - -void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val) -{ - switch(type) { - case R_C60_32: - *(int *)ptr += val; - break; - case R_C60LO16: - { - uint32_t orig; - - /* put the low 16 bits of the absolute address add to what is - already there */ - orig = ((*(int *)(ptr )) >> 7) & 0xffff; - orig |= (((*(int *)(ptr+4)) >> 7) & 0xffff) << 16; - - /* patch both at once - assumes always in pairs Low - High */ - *(int *) ptr = (*(int *) ptr & (~(0xffff << 7)) ) | - (((val+orig) & 0xffff) << 7); - *(int *)(ptr+4) = (*(int *)(ptr+4) & (~(0xffff << 7)) ) | - ((((val+orig)>>16) & 0xffff) << 7); - } - break; - case R_C60HI16: - break; - default: - fprintf(stderr,"FIXME: handle reloc type %x at %x [%p] to %x\n", - type, (unsigned) addr, ptr, (unsigned) val); - break; - } -} - -#endif /* !TARGET_DEFS_ONLY */ diff --git a/05/tcc-final/coff.h b/05/tcc-final/coff.h deleted file mode 100644 index e8e6185..0000000 --- a/05/tcc-final/coff.h +++ /dev/null @@ -1,446 +0,0 @@ -/**************************************************************************/ -/* COFF.H */ -/* COFF data structures and related definitions used by the linker */ -/**************************************************************************/ - -/*------------------------------------------------------------------------*/ -/* COFF FILE HEADER */ -/*------------------------------------------------------------------------*/ -struct filehdr { - unsigned short f_magic; /* magic number */ - unsigned short f_nscns; /* number of sections */ - long f_timdat; /* time & date stamp */ - long f_symptr; /* file pointer to symtab */ - long f_nsyms; /* number of symtab entries */ - unsigned short f_opthdr; /* sizeof(optional hdr) */ - unsigned short f_flags; /* flags */ - unsigned short f_TargetID; /* for C6x = 0x0099 */ - }; - -/*------------------------------------------------------------------------*/ -/* File header flags */ -/*------------------------------------------------------------------------*/ -#define F_RELFLG 0x01 /* relocation info stripped from file */ -#define F_EXEC 0x02 /* file is executable (no unresolved refs) */ -#define F_LNNO 0x04 /* line numbers stripped from file */ -#define F_LSYMS 0x08 /* local symbols stripped from file */ -#define F_GSP10 0x10 /* 34010 version */ -#define F_GSP20 0x20 /* 34020 version */ -#define F_SWABD 0x40 /* bytes swabbed (in names) */ -#define F_AR16WR 0x80 /* byte ordering of an AR16WR (PDP-11) */ -#define F_LITTLE 0x100 /* byte ordering of an AR32WR (vax) */ -#define F_BIG 0x200 /* byte ordering of an AR32W (3B, maxi) */ -#define F_PATCH 0x400 /* contains "patch" list in optional header */ -#define F_NODF 0x400 - -#define F_VERSION (F_GSP10 | F_GSP20) -#define F_BYTE_ORDER (F_LITTLE | F_BIG) -#define FILHDR struct filehdr - -/* #define FILHSZ sizeof(FILHDR) */ -#define FILHSZ 22 /* above rounds to align on 4 bytes which causes problems */ - -#define COFF_C67_MAGIC 0x00c2 - -/*------------------------------------------------------------------------*/ -/* Macros to recognize magic numbers */ -/*------------------------------------------------------------------------*/ -#define ISMAGIC(x) (((unsigned short)(x))==(unsigned short)magic) -#define ISARCHIVE(x) ((((unsigned short)(x))==(unsigned short)ARTYPE)) -#define BADMAGIC(x) (((unsigned short)(x) & 0x8080) && !ISMAGIC(x)) - - -/*------------------------------------------------------------------------*/ -/* OPTIONAL FILE HEADER */ -/*------------------------------------------------------------------------*/ -typedef struct aouthdr { - short magic; /* see magic.h */ - short vstamp; /* version stamp */ - long tsize; /* text size in bytes, padded to FW bdry*/ - long dsize; /* initialized data " " */ - long bsize; /* uninitialized data " " */ - long entrypt; /* entry pt. */ - long text_start; /* base of text used for this file */ - long data_start; /* base of data used for this file */ -} AOUTHDR; - -#define AOUTSZ sizeof(AOUTHDR) - -/*----------------------------------------------------------------------*/ -/* When a UNIX aout header is to be built in the optional header, */ -/* the following magic numbers can appear in that header: */ -/* */ -/* AOUT1MAGIC : default : readonly sharable text segment */ -/* AOUT2MAGIC: : writable text segment */ -/* PAGEMAGIC : : configured for paging */ -/*----------------------------------------------------------------------*/ -#define AOUT1MAGIC 0410 -#define AOUT2MAGIC 0407 -#define PAGEMAGIC 0413 - - -/*------------------------------------------------------------------------*/ -/* COMMON ARCHIVE FILE STRUCTURES */ -/* */ -/* ARCHIVE File Organization: */ -/* _______________________________________________ */ -/* |__________ARCHIVE_MAGIC_STRING_______________| */ -/* |__________ARCHIVE_FILE_MEMBER_1______________| */ -/* | | */ -/* | Archive File Header "ar_hdr" | */ -/* |.............................................| */ -/* | Member Contents | */ -/* | 1. External symbol directory | */ -/* | 2. Text file | */ -/* |_____________________________________________| */ -/* |________ARCHIVE_FILE_MEMBER_2________________| */ -/* | "ar_hdr" | */ -/* |.............................................| */ -/* | Member Contents (.o or text file) | */ -/* |_____________________________________________| */ -/* | . . . | */ -/* | . . . | */ -/* | . . . | */ -/* |_____________________________________________| */ -/* |________ARCHIVE_FILE_MEMBER_n________________| */ -/* | "ar_hdr" | */ -/* |.............................................| */ -/* | Member Contents | */ -/* |_____________________________________________| */ -/* */ -/*------------------------------------------------------------------------*/ - -#define COFF_ARMAG "!\n" -#define SARMAG 8 -#define ARFMAG "`\n" - -struct ar_hdr /* archive file member header - printable ascii */ -{ - char ar_name[16]; /* file member name - `/' terminated */ - char ar_date[12]; /* file member date - decimal */ - char ar_uid[6]; /* file member user id - decimal */ - char ar_gid[6]; /* file member group id - decimal */ - char ar_mode[8]; /* file member mode - octal */ - char ar_size[10]; /* file member size - decimal */ - char ar_fmag[2]; /* ARFMAG - string to end header */ -}; - - -/*------------------------------------------------------------------------*/ -/* SECTION HEADER */ -/*------------------------------------------------------------------------*/ -struct scnhdr { - char s_name[8]; /* section name */ - long s_paddr; /* physical address */ - long s_vaddr; /* virtual address */ - long s_size; /* section size */ - long s_scnptr; /* file ptr to raw data for section */ - long s_relptr; /* file ptr to relocation */ - long s_lnnoptr; /* file ptr to line numbers */ - unsigned int s_nreloc; /* number of relocation entries */ - unsigned int s_nlnno; /* number of line number entries */ - unsigned int s_flags; /* flags */ - unsigned short s_reserved; /* reserved byte */ - unsigned short s_page; /* memory page id */ - }; - -#define SCNHDR struct scnhdr -#define SCNHSZ sizeof(SCNHDR) - -/*------------------------------------------------------------------------*/ -/* Define constants for names of "special" sections */ -/*------------------------------------------------------------------------*/ -/* #define _TEXT ".text" */ -#define _DATA ".data" -#define _BSS ".bss" -#define _CINIT ".cinit" -#define _TV ".tv" - -/*------------------------------------------------------------------------*/ -/* The low 4 bits of s_flags is used as a section "type" */ -/*------------------------------------------------------------------------*/ -#define STYP_REG 0x00 /* "regular" : allocated, relocated, loaded */ -#define STYP_DSECT 0x01 /* "dummy" : not allocated, relocated, not loaded */ -#define STYP_NOLOAD 0x02 /* "noload" : allocated, relocated, not loaded */ -#define STYP_GROUP 0x04 /* "grouped" : formed of input sections */ -#define STYP_PAD 0x08 /* "padding" : not allocated, not relocated, loaded */ -#define STYP_COPY 0x10 /* "copy" : used for C init tables - - not allocated, relocated, - loaded; reloc & lineno - entries processed normally */ -#define STYP_TEXT 0x20 /* section contains text only */ -#define STYP_DATA 0x40 /* section contains data only */ -#define STYP_BSS 0x80 /* section contains bss only */ - -#define STYP_ALIGN 0x100 /* align flag passed by old version assemblers */ -#define ALIGN_MASK 0x0F00 /* part of s_flags that is used for align vals */ -#define ALIGNSIZE(x) (1 << ((x & ALIGN_MASK) >> 8)) - - -/*------------------------------------------------------------------------*/ -/* RELOCATION ENTRIES */ -/*------------------------------------------------------------------------*/ -struct reloc -{ - long r_vaddr; /* (virtual) address of reference */ - short r_symndx; /* index into symbol table */ - unsigned short r_disp; /* additional bits for address calculation */ - unsigned short r_type; /* relocation type */ -}; - -#define RELOC struct reloc -#define RELSZ 10 /* sizeof(RELOC) */ - -/*--------------------------------------------------------------------------*/ -/* define all relocation types */ -/*--------------------------------------------------------------------------*/ - -#define R_ABS 0 /* absolute address - no relocation */ -#define R_DIR16 01 /* UNUSED */ -#define R_REL16 02 /* UNUSED */ -#define R_DIR24 04 /* UNUSED */ -#define R_REL24 05 /* 24 bits, direct */ -#define R_DIR32 06 /* UNUSED */ -#define R_RELBYTE 017 /* 8 bits, direct */ -#define R_RELWORD 020 /* 16 bits, direct */ -#define R_RELLONG 021 /* 32 bits, direct */ -#define R_PCRBYTE 022 /* 8 bits, PC-relative */ -#define R_PCRWORD 023 /* 16 bits, PC-relative */ -#define R_PCRLONG 024 /* 32 bits, PC-relative */ -#define R_OCRLONG 030 /* GSP: 32 bits, one's complement direct */ -#define R_GSPPCR16 031 /* GSP: 16 bits, PC relative (in words) */ -#define R_GSPOPR32 032 /* GSP: 32 bits, direct big-endian */ -#define R_PARTLS16 040 /* Brahma: 16 bit offset of 24 bit address*/ -#define R_PARTMS8 041 /* Brahma: 8 bit page of 24 bit address */ -#define R_PARTLS7 050 /* DSP: 7 bit offset of 16 bit address */ -#define R_PARTMS9 051 /* DSP: 9 bit page of 16 bit address */ -#define R_REL13 052 /* DSP: 13 bits, direct */ - - -/*------------------------------------------------------------------------*/ -/* LINE NUMBER ENTRIES */ -/*------------------------------------------------------------------------*/ -struct lineno -{ - union - { - long l_symndx ; /* sym. table index of function name - iff l_lnno == 0 */ - long l_paddr ; /* (physical) address of line number */ - } l_addr ; - unsigned short l_lnno ; /* line number */ -}; - -#define LINENO struct lineno -#define LINESZ 6 /* sizeof(LINENO) */ - - -/*------------------------------------------------------------------------*/ -/* STORAGE CLASSES */ -/*------------------------------------------------------------------------*/ -#define C_EFCN -1 /* physical end of function */ -#define C_NULL 0 -#define C_AUTO 1 /* automatic variable */ -#define C_EXT 2 /* external symbol */ -#define C_STAT 3 /* static */ -#define C_REG 4 /* register variable */ -#define C_EXTDEF 5 /* external definition */ -#define C_LABEL 6 /* label */ -#define C_ULABEL 7 /* undefined label */ -#define C_MOS 8 /* member of structure */ -#define C_ARG 9 /* function argument */ -#define C_STRTAG 10 /* structure tag */ -#define C_MOU 11 /* member of union */ -#define C_UNTAG 12 /* union tag */ -#define C_TPDEF 13 /* type definition */ -#define C_USTATIC 14 /* undefined static */ -#define C_ENTAG 15 /* enumeration tag */ -#define C_MOE 16 /* member of enumeration */ -#define C_REGPARM 17 /* register parameter */ -#define C_FIELD 18 /* bit field */ - -#define C_BLOCK 100 /* ".bb" or ".eb" */ -#define C_FCN 101 /* ".bf" or ".ef" */ -#define C_EOS 102 /* end of structure */ -#define C_FILE 103 /* file name */ -#define C_LINE 104 /* dummy sclass for line number entry */ -#define C_ALIAS 105 /* duplicate tag */ -#define C_HIDDEN 106 /* special storage class for external */ - /* symbols in dmert public libraries */ - -/*------------------------------------------------------------------------*/ -/* SYMBOL TABLE ENTRIES */ -/*------------------------------------------------------------------------*/ - -#define SYMNMLEN 8 /* Number of characters in a symbol name */ -#define FILNMLEN 14 /* Number of characters in a file name */ -#define DIMNUM 4 /* Number of array dimensions in auxiliary entry */ - - -struct syment -{ - union - { - char _n_name[SYMNMLEN]; /* old COFF version */ - struct - { - long _n_zeroes; /* new == 0 */ - long _n_offset; /* offset into string table */ - } _n_n; - char *_n_nptr[2]; /* allows for overlaying */ - } _n; - long n_value; /* value of symbol */ - short n_scnum; /* section number */ - unsigned short n_type; /* type and derived type */ - char n_sclass; /* storage class */ - char n_numaux; /* number of aux. entries */ -}; - -#define n_name _n._n_name -#define n_nptr _n._n_nptr[1] -#define n_zeroes _n._n_n._n_zeroes -#define n_offset _n._n_n._n_offset - -/*------------------------------------------------------------------------*/ -/* Relocatable symbols have a section number of the */ -/* section in which they are defined. Otherwise, section */ -/* numbers have the following meanings: */ -/*------------------------------------------------------------------------*/ -#define N_UNDEF 0 /* undefined symbol */ -#define N_ABS -1 /* value of symbol is absolute */ -#define N_DEBUG -2 /* special debugging symbol */ -#define N_TV (unsigned short)-3 /* needs transfer vector (preload) */ -#define P_TV (unsigned short)-4 /* needs transfer vector (postload) */ - - -/*------------------------------------------------------------------------*/ -/* The fundamental type of a symbol packed into the low */ -/* 4 bits of the word. */ -/*------------------------------------------------------------------------*/ -#define _EF ".ef" - -#define T_NULL 0 /* no type info */ -#define T_ARG 1 /* function argument (only used by compiler) */ -#define T_CHAR 2 /* character */ -#define T_SHORT 3 /* short integer */ -#define T_INT 4 /* integer */ -#define T_LONG 5 /* long integer */ -#define T_FLOAT 6 /* floating point */ -#define T_DOUBLE 7 /* double word */ -#define T_STRUCT 8 /* structure */ -#define T_UNION 9 /* union */ -#define T_ENUM 10 /* enumeration */ -#define T_MOE 11 /* member of enumeration */ -#define T_UCHAR 12 /* unsigned character */ -#define T_USHORT 13 /* unsigned short */ -#define T_UINT 14 /* unsigned integer */ -#define T_ULONG 15 /* unsigned long */ - -/*------------------------------------------------------------------------*/ -/* derived types are: */ -/*------------------------------------------------------------------------*/ -#define DT_NON 0 /* no derived type */ -#define DT_PTR 1 /* pointer */ -#define DT_FCN 2 /* function */ -#define DT_ARY 3 /* array */ - -#define MKTYPE(basic, d1,d2,d3,d4,d5,d6) \ - ((basic) | ((d1) << 4) | ((d2) << 6) | ((d3) << 8) |\ - ((d4) << 10) | ((d5) << 12) | ((d6) << 14)) - -/*------------------------------------------------------------------------*/ -/* type packing constants and macros */ -/*------------------------------------------------------------------------*/ -#define N_BTMASK_COFF 017 -#define N_TMASK_COFF 060 -#define N_TMASK1_COFF 0300 -#define N_TMASK2_COFF 0360 -#define N_BTSHFT_COFF 4 -#define N_TSHIFT_COFF 2 - -#define BTYPE_COFF(x) ((x) & N_BTMASK_COFF) -#define ISINT(x) (((x) >= T_CHAR && (x) <= T_LONG) || \ - ((x) >= T_UCHAR && (x) <= T_ULONG) || (x) == T_ENUM) -#define ISFLT_COFF(x) ((x) == T_DOUBLE || (x) == T_FLOAT) -#define ISPTR_COFF(x) (((x) & N_TMASK_COFF) == (DT_PTR << N_BTSHFT_COFF)) -#define ISFCN_COFF(x) (((x) & N_TMASK_COFF) == (DT_FCN << N_BTSHFT_COFF)) -#define ISARY_COFF(x) (((x) & N_TMASK_COFF) == (DT_ARY << N_BTSHFT_COFF)) -#define ISTAG_COFF(x) ((x)==C_STRTAG || (x)==C_UNTAG || (x)==C_ENTAG) - -#define INCREF_COFF(x) ((((x)&~N_BTMASK_COFF)<>N_TSHIFT_COFF)&~N_BTMASK_COFF)|((x)&N_BTMASK_COFF)) - - -/*------------------------------------------------------------------------*/ -/* AUXILIARY SYMBOL ENTRY */ -/*------------------------------------------------------------------------*/ -union auxent -{ - struct - { - long x_tagndx; /* str, un, or enum tag indx */ - union - { - struct - { - unsigned short x_lnno; /* declaration line number */ - unsigned short x_size; /* str, union, array size */ - } x_lnsz; - long x_fsize; /* size of function */ - } x_misc; - union - { - struct /* if ISFCN, tag, or .bb */ - { - long x_lnnoptr; /* ptr to fcn line # */ - long x_endndx; /* entry ndx past block end */ - } x_fcn; - struct /* if ISARY, up to 4 dimen. */ - { - unsigned short x_dimen[DIMNUM]; - } x_ary; - } x_fcnary; - unsigned short x_regcount; /* number of registers used by func */ - } x_sym; - struct - { - char x_fname[FILNMLEN]; - } x_file; - struct - { - long x_scnlen; /* section length */ - unsigned short x_nreloc; /* number of relocation entries */ - unsigned short x_nlinno; /* number of line numbers */ - } x_scn; -}; - -#define SYMENT struct syment -#define SYMESZ 18 /* sizeof(SYMENT) */ - -#define AUXENT union auxent -#define AUXESZ 18 /* sizeof(AUXENT) */ - -/*------------------------------------------------------------------------*/ -/* NAMES OF "SPECIAL" SYMBOLS */ -/*------------------------------------------------------------------------*/ -#define _STEXT ".text" -#define _ETEXT "etext" -#define _SDATA ".data" -#define _EDATA "edata" -#define _SBSS ".bss" -#define _END "end" -#define _CINITPTR "cinit" - -/*--------------------------------------------------------------------------*/ -/* ENTRY POINT SYMBOLS */ -/*--------------------------------------------------------------------------*/ -#define _START "_start" -#define _MAIN "_main" - /* _CSTART "_c_int00" (defined in params.h) */ - - -#define _TVORIG "_tvorig" -#define _TORIGIN "_torigin" -#define _DORIGIN "_dorigin" - -#define _SORIGIN "_sorigin" diff --git a/05/tcc-final/configure b/05/tcc-final/configure deleted file mode 100755 index cd96ea3..0000000 --- a/05/tcc-final/configure +++ /dev/null @@ -1,574 +0,0 @@ -#!/bin/sh -# -# tcc configure script (c) 2003 Fabrice Bellard - -# set temporary file name -# if test ! -z "$TMPDIR" ; then -# TMPDIR1="${TMPDIR}" -# elif test ! -z "$TEMPDIR" ; then -# TMPDIR1="${TEMPDIR}" -# else -# TMPDIR1="/tmp" -# fi -# -# bashism: TMPN="${TMPDIR1}/tcc-conf-${RANDOM}-$$-${RANDOM}.c" - -TMPN="./conftest-$$" -TMPH=$TMPN.h - -# default parameters -prefix="" -execprefix="" -bindir="" -libdir="" -tccdir="" -includedir="" -mandir="" -infodir="" -sysroot="" -cross_prefix="" -test -z "$CC" && CC="gcc" -test -z "$cc" && cc="$CC" -ar="ar" -bigendian="no" -mingw32="no" -LIBSUF=".a" -EXESUF="" -DLLSUF=".so" -tcc_usrinclude="" -tcc_sysincludepaths="" -tcc_libpaths="" -tcc_crtprefix="" -tcc_elfinterp="" -triplet= -tcc_lddir= -confvars= -suggest="yes" -gcc_major=0 -gcc_minor=0 -cc_name="$cc" -ar_set= -darwin= -cpu= -cpuver= -dwarf= - -# OS specific -cpu_sys=`uname -m` -targetos=`uname` - -case $targetos in - Darwin) - darwin=yes - confvars="$confvars OSX dll=no" - cc=`which cc` - cc=`readlink $cc || echo clang` - tcc_usrinclude="`xcrun --show-sdk-path`/usr/include" - DLLSUF=".dylib" - ;; - Windows_NT|MINGW*|MSYS*|CYGWIN*) - mingw32=yes - targetos=WIN32 - ;; - DragonFly|OpenBSD|FreeBSD|NetBSD) - confvars="$confvars BSD ldl=no" - ;; - *) - ;; -esac - -# find source path -source_path=${0%configure} -source_path=${source_path%/} -source_path_used="yes" -if test -z "$source_path" -o "$source_path" = "." ; then - source_path=`pwd` - source_path_used="no" -fi - -for opt do - eval opt=\"$opt\" - case "$opt" in - --prefix=*) prefix=`echo $opt | cut -d '=' -f 2-` - ;; - --exec-prefix=*) execprefix=`echo $opt | cut -d '=' -f 2-` - ;; - --tccdir=*) tccdir=`echo $opt | cut -d '=' -f 2-` - ;; - --bindir=*) bindir=`echo $opt | cut -d '=' -f 2-` - ;; - --libdir=*) libdir=`echo $opt | cut -d '=' -f 2-` - ;; - --includedir=*) includedir=`echo $opt | cut -d '=' -f 2-` - ;; - --sharedir=*) sharedir=`echo $opt | cut -d '=' -f 2-` - ;; - --mandir=*) mandir=`echo $opt | cut -d '=' -f 2-` - ;; - --infodir=*) infodir=`echo $opt | cut -d '=' -f 2-` - ;; - --docdir=*) docdir=`echo $opt | cut -d '=' -f 2-` - ;; - --sysroot=*) sysroot=`echo $opt | cut -d '=' -f 2-` - ;; - --source-path=*) source_path=`echo $opt | cut -d '=' -f 2-` - ;; - --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2-` - ;; - --cc=*) cc=`echo $opt | cut -d '=' -f 2-` - ;; - --ar=*) ar=`echo $opt | cut -d '=' -f 2-` ; ar_set="yes" - ;; - --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}" - ;; - --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}" - ;; - --extra-libs=*) extralibs="${opt#--extra-libs=}" - ;; - --sysincludepaths=*) tcc_sysincludepaths=`echo $opt | cut -d '=' -f 2-` - ;; - --libpaths=*) tcc_libpaths=`echo $opt | cut -d '=' -f 2-` - ;; - --crtprefix=*) tcc_crtprefix=`echo $opt | cut -d '=' -f 2-` - ;; - --elfinterp=*) tcc_elfinterp=`echo $opt | cut -d '=' -f 2-` - ;; - --triplet=*) triplet=`echo $opt | cut -d '=' -f 2-` - ;; - --cpu=*) cpu=`echo $opt | cut -d '=' -f 2-` - ;; - --dwarf=*) dwarf=`echo $opt | cut -d '=' -f 2-` - ;; - --enable-cross) confvars="$confvars cross" - ;; - --disable-static) confvars="$confvars static=no" - ;; - --enable-static) confvars="$confvars static" - ;; - --disable-rpath) confvars="$confvars rpath=no" - ;; - --debug) confvars="$confvars debug" - ;; - --with-libgcc) confvars="$confvars libgcc" - ;; - --with-selinux) confvars="$confvars selinux" - ;; - --config-mingw32*) mingw32=$(echo "$opt=yes" | cut -d '=' -f 2) - ;; - --config-*) confvars="$confvars ${opt#--config-}"; suggest="no" - ;; - --help|-h) show_help="yes" - ;; - *) echo "configure: WARNING: unrecognized option $opt" - ;; - esac -done - -cc="${cross_prefix}${cc}" -ar="${cross_prefix}${ar}" - -# Checking for CFLAGS -test -z "$CFLAGS" && CFLAGS="-Wall -O2" - -# on OSX M1 with --cpu=x86_64, build a tcc to run under rosetta entirely -if test "$darwin" = "yes" -a "$cpu" = "x86_64" -a "$cpu_sys" = "arm64"; then - CFLAGS="$CFLAGS -arch $cpu" - LDFLAGS="$LDFLAGS -arch $cpu" -fi - -# checking for cpu -test -z "$cpu" && cpu="$cpu_sys" - -case "$cpu" in - x86|i386|i486|i586|i686|i86pc|BePC|i686-AT386) - cpu="i386" - ;; - x86_64|amd64|x86-64) - cpu="x86_64" - ;; - evbarm) - case "`uname -p`" in - aarch64|arm64) - cpu="arm64" - ;; - earmv*) - cpu="arm" - ;; - esac - ;; - aarch64|arm64|evbarm) - cpu="arm64" - ;; - arm*) - case "$cpu" in - arm|armv4l) - cpuver=4 - ;; - armv5tel|armv5tejl) - cpuver=5 - ;; - armv6j|armv6l) - cpuver=6 - ;; - armv7|armv7a|armv7l) - cpuver=7 - ;; - esac - cpu="arm" - ;; - alpha) - cpu="alpha" - ;; - "Power Macintosh"|ppc|ppc64) - cpu="ppc" - ;; - mips) - cpu="mips" - ;; - s390) - cpu="s390" - ;; - riscv64) - cpu="riscv64" - ;; - *) - echo "Unsupported CPU" - exit 1 - ;; -esac - -if test "$mingw32" = "yes" ; then - if test "$source_path_used" = "no"; then - source_path="." - fi - test -z "$prefix" && prefix="C:/Program Files/tcc" - test -z "$tccdir" && tccdir="${prefix}" && tccdir_auto="yes" - test -z "$bindir" && bindir="${tccdir}" - test -z "$docdir" && docdir="${tccdir}/doc" - test -z "$libdir" && libdir="${tccdir}/libtcc" - confvars="$confvars WIN32" - LIBSUF=".lib" - EXESUF=".exe" - DLLSUF=".dll" -else - if test -z "$prefix" ; then - prefix="/usr/local" - fi - if test -z "$sharedir" ; then - sharedir="${prefix}/share" - fi - if test x"$execprefix" = x""; then - execprefix="${prefix}" - fi - if test x"$libdir" = x""; then - libdir="${execprefix}/lib" - fi - if test x"$bindir" = x""; then - bindir="${execprefix}/bin" - fi - if test x"$docdir" = x""; then - docdir="${sharedir}/doc" - fi - if test x"$mandir" = x""; then - mandir="${sharedir}/man" - fi - if test x"$infodir" = x""; then - infodir="${sharedir}/info" - fi - if test x"$tccdir" = x""; then - tccdir="${libdir}/tcc" - fi - if test x"$includedir" = x""; then - includedir="${prefix}/include" - fi -fi # mingw32 - -if test x"$show_help" = "xyes" ; then -cat << EOF -Usage: configure [options] -Options: [defaults in brackets after descriptions] - -Standard options: - --help print this message - --prefix=PREFIX install in PREFIX [$prefix] - --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX - [same as prefix] - --bindir=DIR user executables in DIR [EPREFIX/bin] - --libdir=DIR object code libraries in DIR [EPREFIX/lib] - --tccdir=DIR installation directory [EPREFIX/lib/tcc] - --includedir=DIR C header files in DIR [PREFIX/include] - --sharedir=DIR documentation root DIR [PREFIX/share] - --docdir=DIR documentation in DIR [SHAREDIR/doc/tcc] - --mandir=DIR man documentation in DIR [SHAREDIR/man] - --infodir=DIR info documentation in DIR [SHAREDIR/info] - -Advanced options (experts only): - --source-path=PATH path of source code [$source_path] - --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix] - --sysroot=PREFIX prepend PREFIX to library/include paths [$sysroot] - --cc=CC use C compiler CC [$cc] - --ar=AR create archives using AR [$ar] - --extra-cflags= specify compiler flags [$CFLAGS] - --extra-ldflags= specify linker options [$LDFLAGS] - --cpu=CPU CPU [$cpu] - - --debug include debug info with resulting binaries - --disable-static make libtcc.so instead of libtcc.a - --enable-static make libtcc.a instead of libtcc.dll (win32) - --disable-rpath disable use of -rpath with libtcc.so - --with-libgcc use libgcc_s.so.1 instead of libtcc1.a - --with-selinux use mmap for executable memory (tcc -run) - --enable-cross build cross compilers (see also 'make help') - - --sysincludepaths=... specify system include paths, colon separated - --libpaths=... specify system library paths, colon separated - --crtprefix=... specify locations of crt?.o, colon separated - --elfinterp=... specify elf interpreter - --triplet=... specify system library/include directory triplet - - --config-uClibc,-musl enable system specific configurations - --config-mingw32 build on windows using msys, busybox, etc. - --config-backtrace=no disable stack backtraces (with -run or -bt) - --config-bcheck=no disable bounds checker (-b) - --config-predefs=no do not compile tccdefs.h, instead just include - --dwarf=x Use dwarf debug info instead of stabs (x=2..5) -EOF -exit 1 -fi - -if test -z "$cross_prefix" ; then - CONFTEST=./conftest$EXESUF - if ! $cc -o $CONFTEST $source_path/conftest.c 2>/dev/null ; then - echo "configure: error: '$cc' failed to compile conftest.c." - else - cc_name="$($CONFTEST compiler)" - gcc_major="$($CONFTEST version)" - gcc_minor="$($CONFTEST minor)" - bigendian="$($CONFTEST bigendian)" - _triplet="$($CONFTEST triplet)" - fi - if test "$mingw32" = "no" ; then - - if test -z "$triplet"; then - if test -n "$_triplet" -a -f "/usr/lib/$_triplet/crti.o" ; then - triplet="$_triplet" - fi - fi - - if test -z "$triplet"; then - if test $cpu = "x86_64" -o $cpu = "arm64" -o $cpu = "riscv64" ; then - if test -f "/usr/lib64/crti.o" ; then - tcc_lddir="lib64" - fi - fi - fi - - if test "$cpu" = "arm" ; then - if test "${triplet%eabihf}" != "$triplet" ; then - confvars="$confvars arm_eabihf arm_vfp" - elif test "${triplet%eabi}" != "$triplet" ; then - confvars="$confvars arm_eabi arm_vfp" - elif test "${_triplet%eabihf}" != "$_triplet" ; then - confvars="$confvars arm_eabihf arm_vfp" - elif test "${_triplet%eabi}" != "$_triplet" ; then - confvars="$confvars arm_eabi arm_vfp" - fi - if grep -s -q "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo ; then - confvars="$confvars arm_vfp" - fi - fi - - if test "$suggest" = "yes"; then - if test -f "/lib/ld-uClibc.so.0" ; then - echo "Perhaps you want ./configure --config-uClibc" - fi - if test -f "/lib/ld-musl-$cpu.so.1"; then - echo "Perhaps you want ./configure --config-musl" - fi - fi - else # mingw32 = yes - if test "$cc_name" = "gcc"; then - # avoid mingw dependencies such as 'libgcc_s_dw2-1.dll' - test -z "$LDFLAGS" && LDFLAGS="-static" - fi - fi -else - # if cross compiling, cannot launch a program, so make a static guess - case $cpu in - ppc|mips|s390) bigendian=yes;; - esac -fi - -if test "$bigendian" = "yes" ; then - confvars="$confvars BIGENDIAN" -fi - -# a final configuration tuning -if test "$cc_name" != "tcc"; then - OPT1="-Wdeclaration-after-statement -fno-strict-aliasing" - # we want -Wno- but gcc does not always reject unknown -Wno- options - OPT2="-Wpointer-sign -Wsign-compare -Wunused-result -Wformat-truncation" - OPT2="$OPT2 -Wstringop-truncation" - if test "$cc_name" = "clang"; then - OPT1="$OPT1 -fheinous-gnu-extensions" - OPT2="$OPT2 -Wstring-plus-int" - fi - $cc $OPT1 $OPT2 -o a.out -c -xc - < /dev/null > cc_msg.txt 2>&1 - for o in $OPT1; do # enable these options - if ! grep -q -- $o cc_msg.txt; then CFLAGS="$CFLAGS $o"; fi - done - for o in $OPT2; do # disable these options - if ! grep -q -- $o cc_msg.txt; then CFLAGS="$CFLAGS -Wno-${o#-W*}"; fi - done - # cat cc_msg.txt - # echo $CFLAGS - rm -f cc_msg.txt a.out -else # cc is tcc - test "$ar_set" || ar="$cc -ar" -fi - -fcho() { if test -n "$2"; then echo "$1$2"; fi } - -fcho "Binary directory " "$bindir" -fcho "TinyCC directory " "$tccdir" -fcho "Library directory " "$libdir" -fcho "Include directory " "$includedir" -fcho "Manual directory " "$mandir" -fcho "Info directory " "$infodir" -fcho "Doc directory " "$docdir" -fcho "Target root prefix " "$sysroot" -fcho "/usr/include dir " "$tcc_usrinclude" -echo "Source path $source_path" -echo "C compiler $cc ($gcc_major.$gcc_minor)" -echo "Target OS $targetos" -echo "CPU $cpu" -fcho "Triplet " "$triplet" -fcho "Config " "${confvars# }" -echo "Creating config.mak and config.h" - -cat >config.mak <> $TMPH - echo "# define $1 $v" >> $TMPH - echo "#endif" >> $TMPH - fi -} - -print_mak() { - local v="$2" - if test -n "$v"; then - test "$3" = "num" || v="\"\\\"$v\\\"\"" - echo "NATIVE_DEFINES+=-D$1=$v" >> config.mak - fi -} - -echo "/* Automatically generated by configure - do not modify */" > $TMPH - -print_inc CONFIG_SYSROOT "$sysroot" -test "$tccdir_auto" = "yes" || print_inc CONFIG_TCCDIR "$tccdir" -print_inc DWARF_VERSION "$dwarf" num -print_mak CONFIG_USR_INCLUDE "$tcc_usrinclude" -print_mak CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths" -print_mak CONFIG_TCC_LIBPATHS "$tcc_libpaths" -print_mak CONFIG_TCC_CRTPREFIX "$tcc_crtprefix" -print_mak CONFIG_TCC_ELFINTERP "$tcc_elfinterp" -print_mak CONFIG_LDDIR "$tcc_lddir" -print_mak CONFIG_TRIPLET "$triplet" -print_mak TCC_CPU_VERSION "$cpuver" num - -echo "ARCH=$cpu" >> config.mak -echo "TARGETOS=$targetos" >> config.mak - -predefs="1" -for v in $confvars ; do - test "$v" = "predefs=no" && predefs="" - if test "${v%=*}" = "$v"; then - echo "CONFIG_$v=yes" >> config.mak - else - echo "CONFIG_$v" >> config.mak - fi -done -print_inc CONFIG_TCC_PREDEFS "$predefs" num - -version=`head $source_path/VERSION` -echo "VERSION = $version" >> config.mak -echo "#define TCC_VERSION \"$version\"" >> $TMPH -echo "@set VERSION $version" > config.texi - -if test "$source_path_used" = "yes" ; then - case $source_path in - /*) echo "TOPSRC=$source_path";; - *) echo "TOPSRC=\$(TOP)/$source_path";; - esac >>config.mak -else - echo 'TOPSRC=$(TOP)' >>config.mak -fi -cat >>$TMPH </dev/null 2>&1 -if test $? -ne 0 ; then - mv -f $TMPH config.h -else - echo "config.h is unchanged" -fi - -rm -f $TMPN* $CONFTEST - -# --------------------------------------------------------------------------- -# build tree in object directory if source path is different from current one - -fn_makelink() -{ - tgt=$1/$2 - case $2 in - */*) dn=${2%/*} - test -d $dn || mkdir -p $dn - case $1 in - /*) ;; - *) while test $dn ; do - tgt=../$tgt; dn=${dn#${dn%%/*}}; dn=${dn#/} - done - ;; - esac - ;; - esac - - ln -sfn $tgt $2 || ( echo "ln failed. Using cp instead."; cp -f $1/$2 $2 ) -} - -if test "$source_path_used" = "yes" ; then - FILES="Makefile lib/Makefile tests/Makefile tests/tests2/Makefile tests/pp/Makefile" - for f in $FILES ; do - fn_makelink $source_path $f - done -fi - -# --------------------------------------------------------------------------- diff --git a/05/tcc-final/dwarf.h b/05/tcc-final/dwarf.h deleted file mode 100644 index c961bc3..0000000 --- a/05/tcc-final/dwarf.h +++ /dev/null @@ -1,1046 +0,0 @@ -/* This file defines standard DWARF types, structures, and macros. - Copyright (C) 2000-2011, 2014, 2016, 2017, 2018 Red Hat, Inc. - This file is part of elfutils. - - This file is free software; you can redistribute it and/or modify - it under the terms of either - - * the GNU Lesser General Public License as published by the Free - Software Foundation; either version 3 of the License, or (at - your option) any later version - - or - - * the GNU General Public License as published by the Free - Software Foundation; either version 2 of the License, or (at - your option) any later version - - or both in parallel, as here. - - elfutils is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received copies of the GNU General Public License and - the GNU Lesser General Public License along with this program. If - not, see . */ - -#ifndef _DWARF_H -#define _DWARF_H 1 - -/* DWARF Unit Header Types. */ -enum - { - DW_UT_compile = 0x01, - DW_UT_type = 0x02, - DW_UT_partial = 0x03, - DW_UT_skeleton = 0x04, - DW_UT_split_compile = 0x05, - DW_UT_split_type = 0x06, - - DW_UT_lo_user = 0x80, - DW_UT_hi_user = 0xff - }; - -/* DWARF tags. */ -enum - { - DW_TAG_array_type = 0x01, - DW_TAG_class_type = 0x02, - DW_TAG_entry_point = 0x03, - DW_TAG_enumeration_type = 0x04, - DW_TAG_formal_parameter = 0x05, - /* 0x06 reserved. */ - /* 0x07 reserved. */ - DW_TAG_imported_declaration = 0x08, - /* 0x09 reserved. */ - DW_TAG_label = 0x0a, - DW_TAG_lexical_block = 0x0b, - /* 0x0c reserved. */ - DW_TAG_member = 0x0d, - /* 0x0e reserved. */ - DW_TAG_pointer_type = 0x0f, - DW_TAG_reference_type = 0x10, - DW_TAG_compile_unit = 0x11, - DW_TAG_string_type = 0x12, - DW_TAG_structure_type = 0x13, - /* 0x14 reserved. */ - DW_TAG_subroutine_type = 0x15, - DW_TAG_typedef = 0x16, - DW_TAG_union_type = 0x17, - DW_TAG_unspecified_parameters = 0x18, - DW_TAG_variant = 0x19, - DW_TAG_common_block = 0x1a, - DW_TAG_common_inclusion = 0x1b, - DW_TAG_inheritance = 0x1c, - DW_TAG_inlined_subroutine = 0x1d, - DW_TAG_module = 0x1e, - DW_TAG_ptr_to_member_type = 0x1f, - DW_TAG_set_type = 0x20, - DW_TAG_subrange_type = 0x21, - DW_TAG_with_stmt = 0x22, - DW_TAG_access_declaration = 0x23, - DW_TAG_base_type = 0x24, - DW_TAG_catch_block = 0x25, - DW_TAG_const_type = 0x26, - DW_TAG_constant = 0x27, - DW_TAG_enumerator = 0x28, - DW_TAG_file_type = 0x29, - DW_TAG_friend = 0x2a, - DW_TAG_namelist = 0x2b, - DW_TAG_namelist_item = 0x2c, - DW_TAG_packed_type = 0x2d, - DW_TAG_subprogram = 0x2e, - DW_TAG_template_type_parameter = 0x2f, - DW_TAG_template_value_parameter = 0x30, - DW_TAG_thrown_type = 0x31, - DW_TAG_try_block = 0x32, - DW_TAG_variant_part = 0x33, - DW_TAG_variable = 0x34, - DW_TAG_volatile_type = 0x35, - DW_TAG_dwarf_procedure = 0x36, - DW_TAG_restrict_type = 0x37, - DW_TAG_interface_type = 0x38, - DW_TAG_namespace = 0x39, - DW_TAG_imported_module = 0x3a, - DW_TAG_unspecified_type = 0x3b, - DW_TAG_partial_unit = 0x3c, - DW_TAG_imported_unit = 0x3d, - /* 0x3e reserved. Was DW_TAG_mutable_type. */ - DW_TAG_condition = 0x3f, - DW_TAG_shared_type = 0x40, - DW_TAG_type_unit = 0x41, - DW_TAG_rvalue_reference_type = 0x42, - DW_TAG_template_alias = 0x43, - DW_TAG_coarray_type = 0x44, - DW_TAG_generic_subrange = 0x45, - DW_TAG_dynamic_type = 0x46, - DW_TAG_atomic_type = 0x47, - DW_TAG_call_site = 0x48, - DW_TAG_call_site_parameter = 0x49, - DW_TAG_skeleton_unit = 0x4a, - DW_TAG_immutable_type = 0x4b, - - DW_TAG_lo_user = 0x4080, - - DW_TAG_MIPS_loop = 0x4081, - DW_TAG_format_label = 0x4101, - DW_TAG_function_template = 0x4102, - DW_TAG_class_template = 0x4103, - - DW_TAG_GNU_BINCL = 0x4104, - DW_TAG_GNU_EINCL = 0x4105, - - DW_TAG_GNU_template_template_param = 0x4106, - DW_TAG_GNU_template_parameter_pack = 0x4107, - DW_TAG_GNU_formal_parameter_pack = 0x4108, - DW_TAG_GNU_call_site = 0x4109, - DW_TAG_GNU_call_site_parameter = 0x410a, - - DW_TAG_hi_user = 0xffff - }; - - -/* Children determination encodings. */ -enum - { - DW_CHILDREN_no = 0, - DW_CHILDREN_yes = 1 - }; - - -/* DWARF attributes encodings. */ -enum - { - DW_AT_sibling = 0x01, - DW_AT_location = 0x02, - DW_AT_name = 0x03, - /* 0x04 reserved. */ - /* 0x05 reserved. */ - /* 0x06 reserved. */ - /* 0x07 reserved. */ - /* 0x08 reserved. */ - DW_AT_ordering = 0x09, - /* 0x0a reserved. */ - DW_AT_byte_size = 0x0b, - DW_AT_bit_offset = 0x0c, /* Deprecated in DWARF4. */ - DW_AT_bit_size = 0x0d, - /* 0x0e reserved. */ - /* 0x0f reserved. */ - DW_AT_stmt_list = 0x10, - DW_AT_low_pc = 0x11, - DW_AT_high_pc = 0x12, - DW_AT_language = 0x13, - /* 0x14 reserved. */ - DW_AT_discr = 0x15, - DW_AT_discr_value = 0x16, - DW_AT_visibility = 0x17, - DW_AT_import = 0x18, - DW_AT_string_length = 0x19, - DW_AT_common_reference = 0x1a, - DW_AT_comp_dir = 0x1b, - DW_AT_const_value = 0x1c, - DW_AT_containing_type = 0x1d, - DW_AT_default_value = 0x1e, - /* 0x1f reserved. */ - DW_AT_inline = 0x20, - DW_AT_is_optional = 0x21, - DW_AT_lower_bound = 0x22, - /* 0x23 reserved. */ - /* 0x24 reserved. */ - DW_AT_producer = 0x25, - /* 0x26 reserved. */ - DW_AT_prototyped = 0x27, - /* 0x28 reserved. */ - /* 0x29 reserved. */ - DW_AT_return_addr = 0x2a, - /* 0x2b reserved. */ - DW_AT_start_scope = 0x2c, - /* 0x2d reserved. */ - DW_AT_bit_stride = 0x2e, - DW_AT_upper_bound = 0x2f, - /* 0x30 reserved. */ - DW_AT_abstract_origin = 0x31, - DW_AT_accessibility = 0x32, - DW_AT_address_class = 0x33, - DW_AT_artificial = 0x34, - DW_AT_base_types = 0x35, - DW_AT_calling_convention = 0x36, - DW_AT_count = 0x37, - DW_AT_data_member_location = 0x38, - DW_AT_decl_column = 0x39, - DW_AT_decl_file = 0x3a, - DW_AT_decl_line = 0x3b, - DW_AT_declaration = 0x3c, - DW_AT_discr_list = 0x3d, - DW_AT_encoding = 0x3e, - DW_AT_external = 0x3f, - DW_AT_frame_base = 0x40, - DW_AT_friend = 0x41, - DW_AT_identifier_case = 0x42, - DW_AT_macro_info = 0x43, /* Deprecated in DWARF5. */ - DW_AT_namelist_item = 0x44, - DW_AT_priority = 0x45, - DW_AT_segment = 0x46, - DW_AT_specification = 0x47, - DW_AT_static_link = 0x48, - DW_AT_type = 0x49, - DW_AT_use_location = 0x4a, - DW_AT_variable_parameter = 0x4b, - DW_AT_virtuality = 0x4c, - DW_AT_vtable_elem_location = 0x4d, - DW_AT_allocated = 0x4e, - DW_AT_associated = 0x4f, - DW_AT_data_location = 0x50, - DW_AT_byte_stride = 0x51, - DW_AT_entry_pc = 0x52, - DW_AT_use_UTF8 = 0x53, - DW_AT_extension = 0x54, - DW_AT_ranges = 0x55, - DW_AT_trampoline = 0x56, - DW_AT_call_column = 0x57, - DW_AT_call_file = 0x58, - DW_AT_call_line = 0x59, - DW_AT_description = 0x5a, - DW_AT_binary_scale = 0x5b, - DW_AT_decimal_scale = 0x5c, - DW_AT_small = 0x5d, - DW_AT_decimal_sign = 0x5e, - DW_AT_digit_count = 0x5f, - DW_AT_picture_string = 0x60, - DW_AT_mutable = 0x61, - DW_AT_threads_scaled = 0x62, - DW_AT_explicit = 0x63, - DW_AT_object_pointer = 0x64, - DW_AT_endianity = 0x65, - DW_AT_elemental = 0x66, - DW_AT_pure = 0x67, - DW_AT_recursive = 0x68, - DW_AT_signature = 0x69, - DW_AT_main_subprogram = 0x6a, - DW_AT_data_bit_offset = 0x6b, - DW_AT_const_expr = 0x6c, - DW_AT_enum_class = 0x6d, - DW_AT_linkage_name = 0x6e, - DW_AT_string_length_bit_size = 0x6f, - DW_AT_string_length_byte_size = 0x70, - DW_AT_rank = 0x71, - DW_AT_str_offsets_base = 0x72, - DW_AT_addr_base = 0x73, - DW_AT_rnglists_base = 0x74, - /* 0x75 reserved. */ - DW_AT_dwo_name = 0x76, - DW_AT_reference = 0x77, - DW_AT_rvalue_reference = 0x78, - DW_AT_macros = 0x79, - DW_AT_call_all_calls = 0x7a, - DW_AT_call_all_source_calls = 0x7b, - DW_AT_call_all_tail_calls = 0x7c, - DW_AT_call_return_pc = 0x7d, - DW_AT_call_value = 0x7e, - DW_AT_call_origin = 0x7f, - DW_AT_call_parameter = 0x80, - DW_AT_call_pc = 0x81, - DW_AT_call_tail_call = 0x82, - DW_AT_call_target = 0x83, - DW_AT_call_target_clobbered = 0x84, - DW_AT_call_data_location = 0x85, - DW_AT_call_data_value = 0x86, - DW_AT_noreturn = 0x87, - DW_AT_alignment = 0x88, - DW_AT_export_symbols = 0x89, - DW_AT_deleted = 0x8a, - DW_AT_defaulted = 0x8b, - DW_AT_loclists_base = 0x8c, - - DW_AT_lo_user = 0x2000, - - DW_AT_MIPS_fde = 0x2001, - DW_AT_MIPS_loop_begin = 0x2002, - DW_AT_MIPS_tail_loop_begin = 0x2003, - DW_AT_MIPS_epilog_begin = 0x2004, - DW_AT_MIPS_loop_unroll_factor = 0x2005, - DW_AT_MIPS_software_pipeline_depth = 0x2006, - DW_AT_MIPS_linkage_name = 0x2007, - DW_AT_MIPS_stride = 0x2008, - DW_AT_MIPS_abstract_name = 0x2009, - DW_AT_MIPS_clone_origin = 0x200a, - DW_AT_MIPS_has_inlines = 0x200b, - DW_AT_MIPS_stride_byte = 0x200c, - DW_AT_MIPS_stride_elem = 0x200d, - DW_AT_MIPS_ptr_dopetype = 0x200e, - DW_AT_MIPS_allocatable_dopetype = 0x200f, - DW_AT_MIPS_assumed_shape_dopetype = 0x2010, - DW_AT_MIPS_assumed_size = 0x2011, - - /* GNU extensions. */ - DW_AT_sf_names = 0x2101, - DW_AT_src_info = 0x2102, - DW_AT_mac_info = 0x2103, - DW_AT_src_coords = 0x2104, - DW_AT_body_begin = 0x2105, - DW_AT_body_end = 0x2106, - DW_AT_GNU_vector = 0x2107, - DW_AT_GNU_guarded_by = 0x2108, - DW_AT_GNU_pt_guarded_by = 0x2109, - DW_AT_GNU_guarded = 0x210a, - DW_AT_GNU_pt_guarded = 0x210b, - DW_AT_GNU_locks_excluded = 0x210c, - DW_AT_GNU_exclusive_locks_required = 0x210d, - DW_AT_GNU_shared_locks_required = 0x210e, - DW_AT_GNU_odr_signature = 0x210f, - DW_AT_GNU_template_name = 0x2110, - DW_AT_GNU_call_site_value = 0x2111, - DW_AT_GNU_call_site_data_value = 0x2112, - DW_AT_GNU_call_site_target = 0x2113, - DW_AT_GNU_call_site_target_clobbered = 0x2114, - DW_AT_GNU_tail_call = 0x2115, - DW_AT_GNU_all_tail_call_sites = 0x2116, - DW_AT_GNU_all_call_sites = 0x2117, - DW_AT_GNU_all_source_call_sites = 0x2118, - DW_AT_GNU_locviews = 0x2137, - DW_AT_GNU_entry_view = 0x2138, - DW_AT_GNU_macros = 0x2119, - DW_AT_GNU_deleted = 0x211a, - /* GNU Debug Fission extensions. */ - DW_AT_GNU_dwo_name = 0x2130, - DW_AT_GNU_dwo_id = 0x2131, - DW_AT_GNU_ranges_base = 0x2132, - DW_AT_GNU_addr_base = 0x2133, - DW_AT_GNU_pubnames = 0x2134, - DW_AT_GNU_pubtypes = 0x2135, - - /* https://gcc.gnu.org/wiki/DW_AT_GNU_numerator_denominator */ - DW_AT_GNU_numerator = 0x2303, - DW_AT_GNU_denominator = 0x2304, - /* https://gcc.gnu.org/wiki/DW_AT_GNU_bias */ - DW_AT_GNU_bias = 0x2305, - - DW_AT_hi_user = 0x3fff - }; - -/* Old unofficially attribute names. Should not be used. - Will not appear in known-dwarf.h */ - -/* DWARF1 array subscripts and element data types. */ -#define DW_AT_subscr_data 0x0a -/* DWARF1 enumeration literals. */ -#define DW_AT_element_list 0x0f -/* DWARF1 reference for variable to member structure, class or union. */ -#define DW_AT_member 0x14 - -/* DWARF form encodings. */ -enum - { - DW_FORM_addr = 0x01, - DW_FORM_block2 = 0x03, - DW_FORM_block4 = 0x04, - DW_FORM_data2 = 0x05, - DW_FORM_data4 = 0x06, - DW_FORM_data8 = 0x07, - DW_FORM_string = 0x08, - DW_FORM_block = 0x09, - DW_FORM_block1 = 0x0a, - DW_FORM_data1 = 0x0b, - DW_FORM_flag = 0x0c, - DW_FORM_sdata = 0x0d, - DW_FORM_strp = 0x0e, - DW_FORM_udata = 0x0f, - DW_FORM_ref_addr = 0x10, - DW_FORM_ref1 = 0x11, - DW_FORM_ref2 = 0x12, - DW_FORM_ref4 = 0x13, - DW_FORM_ref8 = 0x14, - DW_FORM_ref_udata = 0x15, - DW_FORM_indirect = 0x16, - DW_FORM_sec_offset = 0x17, - DW_FORM_exprloc = 0x18, - DW_FORM_flag_present = 0x19, - DW_FORM_strx = 0x1a, - DW_FORM_addrx = 0x1b, - DW_FORM_ref_sup4 = 0x1c, - DW_FORM_strp_sup = 0x1d, - DW_FORM_data16 = 0x1e, - DW_FORM_line_strp = 0x1f, - DW_FORM_ref_sig8 = 0x20, - DW_FORM_implicit_const = 0x21, - DW_FORM_loclistx = 0x22, - DW_FORM_rnglistx = 0x23, - DW_FORM_ref_sup8 = 0x24, - DW_FORM_strx1 = 0x25, - DW_FORM_strx2 = 0x26, - DW_FORM_strx3 = 0x27, - DW_FORM_strx4 = 0x28, - DW_FORM_addrx1 = 0x29, - DW_FORM_addrx2 = 0x2a, - DW_FORM_addrx3 = 0x2b, - DW_FORM_addrx4 = 0x2c, - - /* GNU Debug Fission extensions. */ - DW_FORM_GNU_addr_index = 0x1f01, - DW_FORM_GNU_str_index = 0x1f02, - - DW_FORM_GNU_ref_alt = 0x1f20, /* offset in alternate .debuginfo. */ - DW_FORM_GNU_strp_alt = 0x1f21 /* offset in alternate .debug_str. */ - }; - - -/* DWARF location operation encodings. */ -enum - { - DW_OP_addr = 0x03, /* Constant address. */ - DW_OP_deref = 0x06, - DW_OP_const1u = 0x08, /* Unsigned 1-byte constant. */ - DW_OP_const1s = 0x09, /* Signed 1-byte constant. */ - DW_OP_const2u = 0x0a, /* Unsigned 2-byte constant. */ - DW_OP_const2s = 0x0b, /* Signed 2-byte constant. */ - DW_OP_const4u = 0x0c, /* Unsigned 4-byte constant. */ - DW_OP_const4s = 0x0d, /* Signed 4-byte constant. */ - DW_OP_const8u = 0x0e, /* Unsigned 8-byte constant. */ - DW_OP_const8s = 0x0f, /* Signed 8-byte constant. */ - DW_OP_constu = 0x10, /* Unsigned LEB128 constant. */ - DW_OP_consts = 0x11, /* Signed LEB128 constant. */ - DW_OP_dup = 0x12, - DW_OP_drop = 0x13, - DW_OP_over = 0x14, - DW_OP_pick = 0x15, /* 1-byte stack index. */ - DW_OP_swap = 0x16, - DW_OP_rot = 0x17, - DW_OP_xderef = 0x18, - DW_OP_abs = 0x19, - DW_OP_and = 0x1a, - DW_OP_div = 0x1b, - DW_OP_minus = 0x1c, - DW_OP_mod = 0x1d, - DW_OP_mul = 0x1e, - DW_OP_neg = 0x1f, - DW_OP_not = 0x20, - DW_OP_or = 0x21, - DW_OP_plus = 0x22, - DW_OP_plus_uconst = 0x23, /* Unsigned LEB128 addend. */ - DW_OP_shl = 0x24, - DW_OP_shr = 0x25, - DW_OP_shra = 0x26, - DW_OP_xor = 0x27, - DW_OP_bra = 0x28, /* Signed 2-byte constant. */ - DW_OP_eq = 0x29, - DW_OP_ge = 0x2a, - DW_OP_gt = 0x2b, - DW_OP_le = 0x2c, - DW_OP_lt = 0x2d, - DW_OP_ne = 0x2e, - DW_OP_skip = 0x2f, /* Signed 2-byte constant. */ - DW_OP_lit0 = 0x30, /* Literal 0. */ - DW_OP_lit1 = 0x31, /* Literal 1. */ - DW_OP_lit2 = 0x32, /* Literal 2. */ - DW_OP_lit3 = 0x33, /* Literal 3. */ - DW_OP_lit4 = 0x34, /* Literal 4. */ - DW_OP_lit5 = 0x35, /* Literal 5. */ - DW_OP_lit6 = 0x36, /* Literal 6. */ - DW_OP_lit7 = 0x37, /* Literal 7. */ - DW_OP_lit8 = 0x38, /* Literal 8. */ - DW_OP_lit9 = 0x39, /* Literal 9. */ - DW_OP_lit10 = 0x3a, /* Literal 10. */ - DW_OP_lit11 = 0x3b, /* Literal 11. */ - DW_OP_lit12 = 0x3c, /* Literal 12. */ - DW_OP_lit13 = 0x3d, /* Literal 13. */ - DW_OP_lit14 = 0x3e, /* Literal 14. */ - DW_OP_lit15 = 0x3f, /* Literal 15. */ - DW_OP_lit16 = 0x40, /* Literal 16. */ - DW_OP_lit17 = 0x41, /* Literal 17. */ - DW_OP_lit18 = 0x42, /* Literal 18. */ - DW_OP_lit19 = 0x43, /* Literal 19. */ - DW_OP_lit20 = 0x44, /* Literal 20. */ - DW_OP_lit21 = 0x45, /* Literal 21. */ - DW_OP_lit22 = 0x46, /* Literal 22. */ - DW_OP_lit23 = 0x47, /* Literal 23. */ - DW_OP_lit24 = 0x48, /* Literal 24. */ - DW_OP_lit25 = 0x49, /* Literal 25. */ - DW_OP_lit26 = 0x4a, /* Literal 26. */ - DW_OP_lit27 = 0x4b, /* Literal 27. */ - DW_OP_lit28 = 0x4c, /* Literal 28. */ - DW_OP_lit29 = 0x4d, /* Literal 29. */ - DW_OP_lit30 = 0x4e, /* Literal 30. */ - DW_OP_lit31 = 0x4f, /* Literal 31. */ - DW_OP_reg0 = 0x50, /* Register 0. */ - DW_OP_reg1 = 0x51, /* Register 1. */ - DW_OP_reg2 = 0x52, /* Register 2. */ - DW_OP_reg3 = 0x53, /* Register 3. */ - DW_OP_reg4 = 0x54, /* Register 4. */ - DW_OP_reg5 = 0x55, /* Register 5. */ - DW_OP_reg6 = 0x56, /* Register 6. */ - DW_OP_reg7 = 0x57, /* Register 7. */ - DW_OP_reg8 = 0x58, /* Register 8. */ - DW_OP_reg9 = 0x59, /* Register 9. */ - DW_OP_reg10 = 0x5a, /* Register 10. */ - DW_OP_reg11 = 0x5b, /* Register 11. */ - DW_OP_reg12 = 0x5c, /* Register 12. */ - DW_OP_reg13 = 0x5d, /* Register 13. */ - DW_OP_reg14 = 0x5e, /* Register 14. */ - DW_OP_reg15 = 0x5f, /* Register 15. */ - DW_OP_reg16 = 0x60, /* Register 16. */ - DW_OP_reg17 = 0x61, /* Register 17. */ - DW_OP_reg18 = 0x62, /* Register 18. */ - DW_OP_reg19 = 0x63, /* Register 19. */ - DW_OP_reg20 = 0x64, /* Register 20. */ - DW_OP_reg21 = 0x65, /* Register 21. */ - DW_OP_reg22 = 0x66, /* Register 22. */ - DW_OP_reg23 = 0x67, /* Register 24. */ - DW_OP_reg24 = 0x68, /* Register 24. */ - DW_OP_reg25 = 0x69, /* Register 25. */ - DW_OP_reg26 = 0x6a, /* Register 26. */ - DW_OP_reg27 = 0x6b, /* Register 27. */ - DW_OP_reg28 = 0x6c, /* Register 28. */ - DW_OP_reg29 = 0x6d, /* Register 29. */ - DW_OP_reg30 = 0x6e, /* Register 30. */ - DW_OP_reg31 = 0x6f, /* Register 31. */ - DW_OP_breg0 = 0x70, /* Base register 0. */ - DW_OP_breg1 = 0x71, /* Base register 1. */ - DW_OP_breg2 = 0x72, /* Base register 2. */ - DW_OP_breg3 = 0x73, /* Base register 3. */ - DW_OP_breg4 = 0x74, /* Base register 4. */ - DW_OP_breg5 = 0x75, /* Base register 5. */ - DW_OP_breg6 = 0x76, /* Base register 6. */ - DW_OP_breg7 = 0x77, /* Base register 7. */ - DW_OP_breg8 = 0x78, /* Base register 8. */ - DW_OP_breg9 = 0x79, /* Base register 9. */ - DW_OP_breg10 = 0x7a, /* Base register 10. */ - DW_OP_breg11 = 0x7b, /* Base register 11. */ - DW_OP_breg12 = 0x7c, /* Base register 12. */ - DW_OP_breg13 = 0x7d, /* Base register 13. */ - DW_OP_breg14 = 0x7e, /* Base register 14. */ - DW_OP_breg15 = 0x7f, /* Base register 15. */ - DW_OP_breg16 = 0x80, /* Base register 16. */ - DW_OP_breg17 = 0x81, /* Base register 17. */ - DW_OP_breg18 = 0x82, /* Base register 18. */ - DW_OP_breg19 = 0x83, /* Base register 19. */ - DW_OP_breg20 = 0x84, /* Base register 20. */ - DW_OP_breg21 = 0x85, /* Base register 21. */ - DW_OP_breg22 = 0x86, /* Base register 22. */ - DW_OP_breg23 = 0x87, /* Base register 23. */ - DW_OP_breg24 = 0x88, /* Base register 24. */ - DW_OP_breg25 = 0x89, /* Base register 25. */ - DW_OP_breg26 = 0x8a, /* Base register 26. */ - DW_OP_breg27 = 0x8b, /* Base register 27. */ - DW_OP_breg28 = 0x8c, /* Base register 28. */ - DW_OP_breg29 = 0x8d, /* Base register 29. */ - DW_OP_breg30 = 0x8e, /* Base register 30. */ - DW_OP_breg31 = 0x8f, /* Base register 31. */ - DW_OP_regx = 0x90, /* Unsigned LEB128 register. */ - DW_OP_fbreg = 0x91, /* Signed LEB128 offset. */ - DW_OP_bregx = 0x92, /* ULEB128 register followed by SLEB128 off. */ - DW_OP_piece = 0x93, /* ULEB128 size of piece addressed. */ - DW_OP_deref_size = 0x94, /* 1-byte size of data retrieved. */ - DW_OP_xderef_size = 0x95, /* 1-byte size of data retrieved. */ - DW_OP_nop = 0x96, - DW_OP_push_object_address = 0x97, - DW_OP_call2 = 0x98, - DW_OP_call4 = 0x99, - DW_OP_call_ref = 0x9a, - DW_OP_form_tls_address = 0x9b,/* TLS offset to address in current thread */ - DW_OP_call_frame_cfa = 0x9c,/* CFA as determined by CFI. */ - DW_OP_bit_piece = 0x9d, /* ULEB128 size and ULEB128 offset in bits. */ - DW_OP_implicit_value = 0x9e, /* DW_FORM_block follows opcode. */ - DW_OP_stack_value = 0x9f, /* No operands, special like DW_OP_piece. */ - - DW_OP_implicit_pointer = 0xa0, - DW_OP_addrx = 0xa1, - DW_OP_constx = 0xa2, - DW_OP_entry_value = 0xa3, - DW_OP_const_type = 0xa4, - DW_OP_regval_type = 0xa5, - DW_OP_deref_type = 0xa6, - DW_OP_xderef_type = 0xa7, - DW_OP_convert = 0xa8, - DW_OP_reinterpret = 0xa9, - - /* GNU extensions. */ - DW_OP_GNU_push_tls_address = 0xe0, - DW_OP_GNU_uninit = 0xf0, - DW_OP_GNU_encoded_addr = 0xf1, - DW_OP_GNU_implicit_pointer = 0xf2, - DW_OP_GNU_entry_value = 0xf3, - DW_OP_GNU_const_type = 0xf4, - DW_OP_GNU_regval_type = 0xf5, - DW_OP_GNU_deref_type = 0xf6, - DW_OP_GNU_convert = 0xf7, - DW_OP_GNU_reinterpret = 0xf9, - DW_OP_GNU_parameter_ref = 0xfa, - - /* GNU Debug Fission extensions. */ - DW_OP_GNU_addr_index = 0xfb, - DW_OP_GNU_const_index = 0xfc, - - DW_OP_GNU_variable_value = 0xfd, - - DW_OP_lo_user = 0xe0, /* Implementation-defined range start. */ - DW_OP_hi_user = 0xff /* Implementation-defined range end. */ - }; - - -/* DWARF base type encodings. */ -enum - { - DW_ATE_void = 0x0, - DW_ATE_address = 0x1, - DW_ATE_boolean = 0x2, - DW_ATE_complex_float = 0x3, - DW_ATE_float = 0x4, - DW_ATE_signed = 0x5, - DW_ATE_signed_char = 0x6, - DW_ATE_unsigned = 0x7, - DW_ATE_unsigned_char = 0x8, - DW_ATE_imaginary_float = 0x9, - DW_ATE_packed_decimal = 0xa, - DW_ATE_numeric_string = 0xb, - DW_ATE_edited = 0xc, - DW_ATE_signed_fixed = 0xd, - DW_ATE_unsigned_fixed = 0xe, - DW_ATE_decimal_float = 0xf, - DW_ATE_UTF = 0x10, - DW_ATE_UCS = 0x11, - DW_ATE_ASCII = 0x12, - - DW_ATE_lo_user = 0x80, - DW_ATE_hi_user = 0xff - }; - - -/* DWARF decimal sign encodings. */ -enum - { - DW_DS_unsigned = 1, - DW_DS_leading_overpunch = 2, - DW_DS_trailing_overpunch = 3, - DW_DS_leading_separate = 4, - DW_DS_trailing_separate = 5, - }; - - -/* DWARF endianity encodings. */ -enum - { - DW_END_default = 0, - DW_END_big = 1, - DW_END_little = 2, - - DW_END_lo_user = 0x40, - DW_END_hi_user = 0xff - }; - - -/* DWARF accessibility encodings. */ -enum - { - DW_ACCESS_public = 1, - DW_ACCESS_protected = 2, - DW_ACCESS_private = 3 - }; - - -/* DWARF visibility encodings. */ -enum - { - DW_VIS_local = 1, - DW_VIS_exported = 2, - DW_VIS_qualified = 3 - }; - - -/* DWARF virtuality encodings. */ -enum - { - DW_VIRTUALITY_none = 0, - DW_VIRTUALITY_virtual = 1, - DW_VIRTUALITY_pure_virtual = 2 - }; - - -/* DWARF language encodings. */ -enum - { - DW_LANG_C89 = 0x0001, /* ISO C:1989 */ - DW_LANG_C = 0x0002, /* C */ - DW_LANG_Ada83 = 0x0003, /* ISO Ada:1983 */ - DW_LANG_C_plus_plus = 0x0004, /* ISO C++:1998 */ - DW_LANG_Cobol74 = 0x0005, /* ISO Cobol:1974 */ - DW_LANG_Cobol85 = 0x0006, /* ISO Cobol:1985 */ - DW_LANG_Fortran77 = 0x0007, /* ISO FORTRAN 77 */ - DW_LANG_Fortran90 = 0x0008, /* ISO Fortran 90 */ - DW_LANG_Pascal83 = 0x0009, /* ISO Pascal:1983 */ - DW_LANG_Modula2 = 0x000a, /* ISO Modula-2:1996 */ - DW_LANG_Java = 0x000b, /* Java */ - DW_LANG_C99 = 0x000c, /* ISO C:1999 */ - DW_LANG_Ada95 = 0x000d, /* ISO Ada:1995 */ - DW_LANG_Fortran95 = 0x000e, /* ISO Fortran 95 */ - DW_LANG_PLI = 0x000f, /* ISO PL/1:1976 */ - DW_LANG_ObjC = 0x0010, /* Objective-C */ - DW_LANG_ObjC_plus_plus = 0x0011, /* Objective-C++ */ - DW_LANG_UPC = 0x0012, /* Unified Parallel C */ - DW_LANG_D = 0x0013, /* D */ - DW_LANG_Python = 0x0014, /* Python */ - DW_LANG_OpenCL = 0x0015, /* OpenCL */ - DW_LANG_Go = 0x0016, /* Go */ - DW_LANG_Modula3 = 0x0017, /* Modula-3 */ - DW_LANG_Haskell = 0x0018, /* Haskell */ - DW_LANG_C_plus_plus_03 = 0x0019, /* ISO C++:2003 */ - DW_LANG_C_plus_plus_11 = 0x001a, /* ISO C++:2011 */ - DW_LANG_OCaml = 0x001b, /* OCaml */ - DW_LANG_Rust = 0x001c, /* Rust */ - DW_LANG_C11 = 0x001d, /* ISO C:2011 */ - DW_LANG_Swift = 0x001e, /* Swift */ - DW_LANG_Julia = 0x001f, /* Julia */ - DW_LANG_Dylan = 0x0020, /* Dylan */ - DW_LANG_C_plus_plus_14 = 0x0021, /* ISO C++:2014 */ - DW_LANG_Fortran03 = 0x0022, /* ISO/IEC 1539-1:2004 */ - DW_LANG_Fortran08 = 0x0023, /* ISO/IEC 1539-1:2010 */ - DW_LANG_RenderScript = 0x0024, /* RenderScript Kernal Language */ - DW_LANG_BLISS = 0x0025, /* BLISS */ - - DW_LANG_lo_user = 0x8000, - DW_LANG_Mips_Assembler = 0x8001, /* Assembler */ - DW_LANG_hi_user = 0xffff - }; - -/* Old (typo) '1' != 'I'. */ -#define DW_LANG_PL1 DW_LANG_PLI - -/* DWARF identifier case encodings. */ -enum - { - DW_ID_case_sensitive = 0, - DW_ID_up_case = 1, - DW_ID_down_case = 2, - DW_ID_case_insensitive = 3 - }; - - -/* DWARF calling conventions encodings. - Used as values of DW_AT_calling_convention for subroutines - (normal, program or nocall) or structures, unions and class types - (normal, reference or value). */ -enum - { - DW_CC_normal = 0x1, - DW_CC_program = 0x2, - DW_CC_nocall = 0x3, - DW_CC_pass_by_reference = 0x4, - DW_CC_pass_by_value = 0x5, - DW_CC_lo_user = 0x40, - DW_CC_hi_user = 0xff - }; - - -/* DWARF inline encodings. */ -enum - { - DW_INL_not_inlined = 0, - DW_INL_inlined = 1, - DW_INL_declared_not_inlined = 2, - DW_INL_declared_inlined = 3 - }; - - -/* DWARF ordering encodings. */ -enum - { - DW_ORD_row_major = 0, - DW_ORD_col_major = 1 - }; - - -/* DWARF discriminant descriptor encodings. */ -enum - { - DW_DSC_label = 0, - DW_DSC_range = 1 - }; - -/* DWARF defaulted member function encodings. */ -enum - { - DW_DEFAULTED_no = 0, - DW_DEFAULTED_in_class = 1, - DW_DEFAULTED_out_of_class = 2 - }; - -/* DWARF line content descriptions. */ -enum - { - DW_LNCT_path = 0x1, - DW_LNCT_directory_index = 0x2, - DW_LNCT_timestamp = 0x3, - DW_LNCT_size = 0x4, - DW_LNCT_MD5 = 0x5, - DW_LNCT_lo_user = 0x2000, - DW_LNCT_hi_user = 0x3fff - }; - -/* DWARF standard opcode encodings. */ -enum - { - DW_LNS_copy = 1, - DW_LNS_advance_pc = 2, - DW_LNS_advance_line = 3, - DW_LNS_set_file = 4, - DW_LNS_set_column = 5, - DW_LNS_negate_stmt = 6, - DW_LNS_set_basic_block = 7, - DW_LNS_const_add_pc = 8, - DW_LNS_fixed_advance_pc = 9, - DW_LNS_set_prologue_end = 10, - DW_LNS_set_epilogue_begin = 11, - DW_LNS_set_isa = 12 - }; - - -/* DWARF extended opcode encodings. */ -enum - { - DW_LNE_end_sequence = 1, - DW_LNE_set_address = 2, - DW_LNE_define_file = 3, - DW_LNE_set_discriminator = 4, - - DW_LNE_lo_user = 128, - - DW_LNE_NVIDIA_inlined_call = 144, - DW_LNE_NVIDIA_set_function_name = 145, - - DW_LNE_hi_user = 255 - }; - - -/* DWARF macinfo type encodings. */ -enum - { - DW_MACINFO_define = 1, - DW_MACINFO_undef = 2, - DW_MACINFO_start_file = 3, - DW_MACINFO_end_file = 4, - DW_MACINFO_vendor_ext = 255 - }; - - -/* DWARF debug_macro type encodings. */ -enum - { - DW_MACRO_define = 0x01, - DW_MACRO_undef = 0x02, - DW_MACRO_start_file = 0x03, - DW_MACRO_end_file = 0x04, - DW_MACRO_define_strp = 0x05, - DW_MACRO_undef_strp = 0x06, - DW_MACRO_import = 0x07, - DW_MACRO_define_sup = 0x08, - DW_MACRO_undef_sup = 0x09, - DW_MACRO_import_sup = 0x0a, - DW_MACRO_define_strx = 0x0b, - DW_MACRO_undef_strx = 0x0c, - DW_MACRO_lo_user = 0xe0, - DW_MACRO_hi_user = 0xff - }; - -/* Old GNU extension names for DWARF5 debug_macro type encodings. - There are no equivalents for the supplementary object file (sup) - and indirect string references (strx). */ -#define DW_MACRO_GNU_define DW_MACRO_define -#define DW_MACRO_GNU_undef DW_MACRO_undef -#define DW_MACRO_GNU_start_file DW_MACRO_start_file -#define DW_MACRO_GNU_end_file DW_MACRO_end_file -#define DW_MACRO_GNU_define_indirect DW_MACRO_define_strp -#define DW_MACRO_GNU_undef_indirect DW_MACRO_undef_strp -#define DW_MACRO_GNU_transparent_include DW_MACRO_import -#define DW_MACRO_GNU_lo_user DW_MACRO_lo_user -#define DW_MACRO_GNU_hi_user DW_MACRO_hi_user - - -/* Range list entry encoding. */ -enum - { - DW_RLE_end_of_list = 0x0, - DW_RLE_base_addressx = 0x1, - DW_RLE_startx_endx = 0x2, - DW_RLE_startx_length = 0x3, - DW_RLE_offset_pair = 0x4, - DW_RLE_base_address = 0x5, - DW_RLE_start_end = 0x6, - DW_RLE_start_length = 0x7 - }; - - -/* Location list entry encoding. */ -enum - { - DW_LLE_end_of_list = 0x0, - DW_LLE_base_addressx = 0x1, - DW_LLE_startx_endx = 0x2, - DW_LLE_startx_length = 0x3, - DW_LLE_offset_pair = 0x4, - DW_LLE_default_location = 0x5, - DW_LLE_base_address = 0x6, - DW_LLE_start_end = 0x7, - DW_LLE_start_length = 0x8 - }; - - -/* GNU DebugFission list entry encodings (.debug_loc.dwo). */ -enum - { - DW_LLE_GNU_end_of_list_entry = 0x0, - DW_LLE_GNU_base_address_selection_entry = 0x1, - DW_LLE_GNU_start_end_entry = 0x2, - DW_LLE_GNU_start_length_entry = 0x3 - }; - -/* DWARF5 package file section identifiers. */ -enum - { - DW_SECT_INFO = 1, - /* Reserved = 2, */ - DW_SECT_ABBREV = 3, - DW_SECT_LINE = 4, - DW_SECT_LOCLISTS = 5, - DW_SECT_STR_OFFSETS = 6, - DW_SECT_MACRO = 7, - DW_SECT_RNGLISTS = 8, - }; - - -/* DWARF call frame instruction encodings. */ -enum - { - DW_CFA_advance_loc = 0x40, - DW_CFA_offset = 0x80, - DW_CFA_restore = 0xc0, - DW_CFA_extended = 0, - - DW_CFA_nop = 0x00, - DW_CFA_set_loc = 0x01, - DW_CFA_advance_loc1 = 0x02, - DW_CFA_advance_loc2 = 0x03, - DW_CFA_advance_loc4 = 0x04, - DW_CFA_offset_extended = 0x05, - DW_CFA_restore_extended = 0x06, - DW_CFA_undefined = 0x07, - DW_CFA_same_value = 0x08, - DW_CFA_register = 0x09, - DW_CFA_remember_state = 0x0a, - DW_CFA_restore_state = 0x0b, - DW_CFA_def_cfa = 0x0c, - DW_CFA_def_cfa_register = 0x0d, - DW_CFA_def_cfa_offset = 0x0e, - DW_CFA_def_cfa_expression = 0x0f, - DW_CFA_expression = 0x10, - DW_CFA_offset_extended_sf = 0x11, - DW_CFA_def_cfa_sf = 0x12, - DW_CFA_def_cfa_offset_sf = 0x13, - DW_CFA_val_offset = 0x14, - DW_CFA_val_offset_sf = 0x15, - DW_CFA_val_expression = 0x16, - - DW_CFA_low_user = 0x1c, - DW_CFA_MIPS_advance_loc8 = 0x1d, - DW_CFA_GNU_window_save = 0x2d, - DW_CFA_AARCH64_negate_ra_state = 0x2d, - DW_CFA_GNU_args_size = 0x2e, - DW_CFA_GNU_negative_offset_extended = 0x2f, - DW_CFA_high_user = 0x3f - }; - -/* ID indicating CIE as opposed to FDE in .debug_frame. */ -enum - { - DW_CIE_ID_32 = 0xffffffffU, /* In 32-bit format CIE header. */ - DW_CIE_ID_64 = 0xffffffffffffffffULL /* In 64-bit format CIE header. */ - }; - - -/* Information for GNU unwind information. */ -enum - { - DW_EH_PE_absptr = 0x00, - DW_EH_PE_omit = 0xff, - - /* FDE data encoding. */ - DW_EH_PE_uleb128 = 0x01, - DW_EH_PE_udata2 = 0x02, - DW_EH_PE_udata4 = 0x03, - DW_EH_PE_udata8 = 0x04, - DW_EH_PE_sleb128 = 0x09, - DW_EH_PE_sdata2 = 0x0a, - DW_EH_PE_sdata4 = 0x0b, - DW_EH_PE_sdata8 = 0x0c, - DW_EH_PE_signed = 0x08, - - /* FDE flags. */ - DW_EH_PE_pcrel = 0x10, - DW_EH_PE_textrel = 0x20, - DW_EH_PE_datarel = 0x30, - DW_EH_PE_funcrel = 0x40, - DW_EH_PE_aligned = 0x50, - - DW_EH_PE_indirect = 0x80 - }; - - -/* DWARF XXX. */ -#define DW_ADDR_none 0 - -/* Section 7.2.2 of the DWARF3 specification defines a range of escape - codes that can appear in the length field of certain DWARF structures. - - These defines enumerate the minimum and maximum values of this range. - Currently only the maximum value is used (to indicate that 64-bit - values are going to be used in the dwarf data that accompanies the - structure). The other values are reserved. - - Note: There is a typo in DWARF3 spec (published Dec 20, 2005). In - sections 7.4, 7.5.1, 7.19, 7.20 the minimum escape code is referred to - as 0xffffff00 whereas in fact it should be 0xfffffff0. */ -#define DWARF3_LENGTH_MIN_ESCAPE_CODE 0xfffffff0u -#define DWARF3_LENGTH_MAX_ESCAPE_CODE 0xffffffffu -#define DWARF3_LENGTH_64_BIT DWARF3_LENGTH_MAX_ESCAPE_CODE - -#endif /* dwarf.h */ diff --git a/05/tcc-final/elf.h b/05/tcc-final/elf.h deleted file mode 100644 index 19271e5..0000000 --- a/05/tcc-final/elf.h +++ /dev/null @@ -1,3319 +0,0 @@ -/* This file defines standard ELF types, structures, and macros. - Copyright (C) 1995-2012 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#ifndef _ELF_H -#define _ELF_H 1 - -#ifndef _WIN32 -#include -#else -#ifndef __int8_t_defined -#define __int8_t_defined -typedef signed char int8_t; -typedef short int int16_t; -typedef int int32_t; -typedef long long int int64_t; -typedef unsigned char uint8_t; -typedef unsigned short int uint16_t; -typedef unsigned int uint32_t; -typedef unsigned long long int uint64_t; -#endif -#endif - -/* Standard ELF types. */ - -/* Type for a 16-bit quantity. */ -typedef uint16_t Elf32_Half; -typedef uint16_t Elf64_Half; - -/* Types for signed and unsigned 32-bit quantities. */ -typedef uint32_t Elf32_Word; -typedef int32_t Elf32_Sword; -typedef uint32_t Elf64_Word; -typedef int32_t Elf64_Sword; - -/* Types for signed and unsigned 64-bit quantities. */ -typedef uint64_t Elf32_Xword; -typedef int64_t Elf32_Sxword; -typedef uint64_t Elf64_Xword; -typedef int64_t Elf64_Sxword; - -/* Type of addresses. */ -typedef uint32_t Elf32_Addr; -typedef uint64_t Elf64_Addr; - -/* Type of file offsets. */ -typedef uint32_t Elf32_Off; -typedef uint64_t Elf64_Off; - -/* Type for section indices, which are 16-bit quantities. */ -typedef uint16_t Elf32_Section; -typedef uint16_t Elf64_Section; - -/* Type for version symbol information. */ -typedef Elf32_Half Elf32_Versym; -typedef Elf64_Half Elf64_Versym; - - -/* The ELF file header. This appears at the start of every ELF file. */ - -#define EI_NIDENT (16) - -typedef struct -{ - unsigned char e_ident[EI_NIDENT]; /* Magic number and other info */ - Elf32_Half e_type; /* Object file type */ - Elf32_Half e_machine; /* Architecture */ - Elf32_Word e_version; /* Object file version */ - Elf32_Addr e_entry; /* Entry point virtual address */ - Elf32_Off e_phoff; /* Program header table file offset */ - Elf32_Off e_shoff; /* Section header table file offset */ - Elf32_Word e_flags; /* Processor-specific flags */ - Elf32_Half e_ehsize; /* ELF header size in bytes */ - Elf32_Half e_phentsize; /* Program header table entry size */ - Elf32_Half e_phnum; /* Program header table entry count */ - Elf32_Half e_shentsize; /* Section header table entry size */ - Elf32_Half e_shnum; /* Section header table entry count */ - Elf32_Half e_shstrndx; /* Section header string table index */ -} Elf32_Ehdr; - -typedef struct -{ - unsigned char e_ident[EI_NIDENT]; /* Magic number and other info */ - Elf64_Half e_type; /* Object file type */ - Elf64_Half e_machine; /* Architecture */ - Elf64_Word e_version; /* Object file version */ - Elf64_Addr e_entry; /* Entry point virtual address */ - Elf64_Off e_phoff; /* Program header table file offset */ - Elf64_Off e_shoff; /* Section header table file offset */ - Elf64_Word e_flags; /* Processor-specific flags */ - Elf64_Half e_ehsize; /* ELF header size in bytes */ - Elf64_Half e_phentsize; /* Program header table entry size */ - Elf64_Half e_phnum; /* Program header table entry count */ - Elf64_Half e_shentsize; /* Section header table entry size */ - Elf64_Half e_shnum; /* Section header table entry count */ - Elf64_Half e_shstrndx; /* Section header string table index */ -} Elf64_Ehdr; - -/* Fields in the e_ident array. The EI_* macros are indices into the - array. The macros under each EI_* macro are the values the byte - may have. */ - -#define EI_MAG0 0 /* File identification byte 0 index */ -#define ELFMAG0 0x7f /* Magic number byte 0 */ - -#define EI_MAG1 1 /* File identification byte 1 index */ -#define ELFMAG1 'E' /* Magic number byte 1 */ - -#define EI_MAG2 2 /* File identification byte 2 index */ -#define ELFMAG2 'L' /* Magic number byte 2 */ - -#define EI_MAG3 3 /* File identification byte 3 index */ -#define ELFMAG3 'F' /* Magic number byte 3 */ - -/* Conglomeration of the identification bytes, for easy testing as a word. */ -#define ELFMAG "\177ELF" -#define SELFMAG 4 - -#define EI_CLASS 4 /* File class byte index */ -#define ELFCLASSNONE 0 /* Invalid class */ -#define ELFCLASS32 1 /* 32-bit objects */ -#define ELFCLASS64 2 /* 64-bit objects */ -#define ELFCLASSNUM 3 - -#define EI_DATA 5 /* Data encoding byte index */ -#define ELFDATANONE 0 /* Invalid data encoding */ -#define ELFDATA2LSB 1 /* 2's complement, little endian */ -#define ELFDATA2MSB 2 /* 2's complement, big endian */ -#define ELFDATANUM 3 - -#define EI_VERSION 6 /* File version byte index */ - /* Value must be EV_CURRENT */ - -#define EI_OSABI 7 /* OS ABI identification */ -#define ELFOSABI_NONE 0 /* UNIX System V ABI */ -#define ELFOSABI_SYSV 0 /* Alias. */ -#define ELFOSABI_HPUX 1 /* HP-UX */ -#define ELFOSABI_NETBSD 2 /* NetBSD. */ -#define ELFOSABI_GNU 3 /* Object uses GNU ELF extensions. */ -#define ELFOSABI_LINUX ELFOSABI_GNU /* Compatibility alias. */ -#define ELFOSABI_SOLARIS 6 /* Sun Solaris. */ -#define ELFOSABI_AIX 7 /* IBM AIX. */ -#define ELFOSABI_IRIX 8 /* SGI Irix. */ -#define ELFOSABI_FREEBSD 9 /* FreeBSD. */ -#define ELFOSABI_TRU64 10 /* Compaq TRU64 UNIX. */ -#define ELFOSABI_MODESTO 11 /* Novell Modesto. */ -#define ELFOSABI_OPENBSD 12 /* OpenBSD. */ -#define ELFOSABI_OPENVMS 13 -#define ELFOSABI_NSK 14 /* Hewlett-Packard Non-Stop Kernel. */ -#define ELFOSABI_AROS 15 /* Amiga Research OS. */ -#define ELFOSABI_FENIXOS 16 /* FenixOS. */ -#define ELFOSABI_ARM_AEABI 64 /* ARM EABI. */ -#define ELFOSABI_C6000_LINUX 65 /* Linux TMS320C6000. */ -#define ELFOSABI_ARM 97 /* ARM */ -#define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */ - -#define EI_ABIVERSION 8 /* ABI version */ - -#define EI_PAD 9 /* Byte index of padding bytes */ - -/* Legal values for e_type (object file type). */ - -#define ET_NONE 0 /* No file type */ -#define ET_REL 1 /* Relocatable file */ -#define ET_EXEC 2 /* Executable file */ -#define ET_DYN 3 /* Shared object file */ -#define ET_CORE 4 /* Core file */ -#define ET_NUM 5 /* Number of defined types */ -#define ET_LOOS 0xfe00 /* OS-specific range start */ -#define ET_HIOS 0xfeff /* OS-specific range end */ -#define ET_LOPROC 0xff00 /* Processor-specific range start */ -#define ET_HIPROC 0xffff /* Processor-specific range end */ - -/* Legal values for e_machine (architecture). */ - -#define EM_NONE 0 /* No machine */ -#define EM_M32 1 /* AT&T WE 32100 */ -#define EM_SPARC 2 /* SUN SPARC */ -#define EM_386 3 /* Intel 80386 */ -#define EM_68K 4 /* Motorola m68k family */ -#define EM_88K 5 /* Motorola m88k family */ -#define EM_860 7 /* Intel 80860 */ -#define EM_MIPS 8 /* MIPS R3000 big-endian */ -#define EM_S370 9 /* IBM System/370 */ -#define EM_MIPS_RS3_LE 10 /* MIPS R3000 little-endian */ - -#define EM_PARISC 15 /* HPPA */ -#define EM_VPP500 17 /* Fujitsu VPP500 */ -#define EM_SPARC32PLUS 18 /* Sun's "v8plus" */ -#define EM_960 19 /* Intel 80960 */ -#define EM_PPC 20 /* PowerPC */ -#define EM_PPC64 21 /* PowerPC 64-bit */ -#define EM_S390 22 /* IBM S390 */ - -#define EM_V800 36 /* NEC V800 series */ -#define EM_FR20 37 /* Fujitsu FR20 */ -#define EM_RH32 38 /* TRW RH-32 */ -#define EM_RCE 39 /* Motorola RCE */ -#define EM_ARM 40 /* ARM */ -#define EM_FAKE_ALPHA 41 /* Digital Alpha */ -#define EM_SH 42 /* Hitachi SH */ -#define EM_SPARCV9 43 /* SPARC v9 64-bit */ -#define EM_TRICORE 44 /* Siemens Tricore */ -#define EM_ARC 45 /* Argonaut RISC Core */ -#define EM_H8_300 46 /* Hitachi H8/300 */ -#define EM_H8_300H 47 /* Hitachi H8/300H */ -#define EM_H8S 48 /* Hitachi H8S */ -#define EM_H8_500 49 /* Hitachi H8/500 */ -#define EM_IA_64 50 /* Intel Merced */ -#define EM_MIPS_X 51 /* Stanford MIPS-X */ -#define EM_COLDFIRE 52 /* Motorola Coldfire */ -#define EM_68HC12 53 /* Motorola M68HC12 */ -#define EM_MMA 54 /* Fujitsu MMA Multimedia Accelerator*/ -#define EM_PCP 55 /* Siemens PCP */ -#define EM_NCPU 56 /* Sony nCPU embedded RISC */ -#define EM_NDR1 57 /* Denso NDR1 microprocessor */ -#define EM_STARCORE 58 /* Motorola Start*Core processor */ -#define EM_ME16 59 /* Toyota ME16 processor */ -#define EM_ST100 60 /* STMicroelectronic ST100 processor */ -#define EM_TINYJ 61 /* Advanced Logic Corp. Tinyj emb.fam*/ -#define EM_X86_64 62 /* AMD x86-64 architecture */ -#define EM_PDSP 63 /* Sony DSP Processor */ - -#define EM_FX66 66 /* Siemens FX66 microcontroller */ -#define EM_ST9PLUS 67 /* STMicroelectronics ST9+ 8/16 mc */ -#define EM_ST7 68 /* STMicroelectronics ST7 8 bit mc */ -#define EM_68HC16 69 /* Motorola MC68HC16 microcontroller */ -#define EM_68HC11 70 /* Motorola MC68HC11 microcontroller */ -#define EM_68HC08 71 /* Motorola MC68HC08 microcontroller */ -#define EM_68HC05 72 /* Motorola MC68HC05 microcontroller */ -#define EM_SVX 73 /* Silicon Graphics SVx */ -#define EM_ST19 74 /* STMicroelectronics ST19 8 bit mc */ -#define EM_VAX 75 /* Digital VAX */ -#define EM_CRIS 76 /* Axis Communications 32-bit embedded processor */ -#define EM_JAVELIN 77 /* Infineon Technologies 32-bit embedded processor */ -#define EM_FIREPATH 78 /* Element 14 64-bit DSP Processor */ -#define EM_ZSP 79 /* LSI Logic 16-bit DSP Processor */ -#define EM_MMIX 80 /* Donald Knuth's educational 64-bit processor */ -#define EM_HUANY 81 /* Harvard University machine-independent object files */ -#define EM_PRISM 82 /* SiTera Prism */ -#define EM_AVR 83 /* Atmel AVR 8-bit microcontroller */ -#define EM_FR30 84 /* Fujitsu FR30 */ -#define EM_D10V 85 /* Mitsubishi D10V */ -#define EM_D30V 86 /* Mitsubishi D30V */ -#define EM_V850 87 /* NEC v850 */ -#define EM_M32R 88 /* Mitsubishi M32R */ -#define EM_MN10300 89 /* Matsushita MN10300 */ -#define EM_MN10200 90 /* Matsushita MN10200 */ -#define EM_PJ 91 /* picoJava */ -#define EM_OPENRISC 92 /* OpenRISC 32-bit embedded processor */ -#define EM_ARC_A5 93 /* ARC Cores Tangent-A5 */ -#define EM_XTENSA 94 /* Tensilica Xtensa Architecture */ -#define EM_AARCH64 183 /* ARM AARCH64 */ -#define EM_TILEPRO 188 /* Tilera TILEPro */ -#define EM_TILEGX 191 /* Tilera TILE-Gx */ -#define EM_RISCV 243 /* RISC-V */ -#define EM_NUM 253 - -/* If it is necessary to assign new unofficial EM_* values, please - pick large random numbers (0x8523, 0xa7f2, etc.) to minimize the - chances of collision with official or non-GNU unofficial values. */ - -#define EM_ALPHA 0x9026 -#define EM_C60 0x9c60 - -/* Legal values for e_version (version). */ - -#define EV_NONE 0 /* Invalid ELF version */ -#define EV_CURRENT 1 /* Current version */ -#define EV_NUM 2 - -/* Section header. */ - -typedef struct -{ - Elf32_Word sh_name; /* Section name (string tbl index) */ - Elf32_Word sh_type; /* Section type */ - Elf32_Word sh_flags; /* Section flags */ - Elf32_Addr sh_addr; /* Section virtual addr at execution */ - Elf32_Off sh_offset; /* Section file offset */ - Elf32_Word sh_size; /* Section size in bytes */ - Elf32_Word sh_link; /* Link to another section */ - Elf32_Word sh_info; /* Additional section information */ - Elf32_Word sh_addralign; /* Section alignment */ - Elf32_Word sh_entsize; /* Entry size if section holds table */ -} Elf32_Shdr; - -typedef struct -{ - Elf64_Word sh_name; /* Section name (string tbl index) */ - Elf64_Word sh_type; /* Section type */ - Elf64_Xword sh_flags; /* Section flags */ - Elf64_Addr sh_addr; /* Section virtual addr at execution */ - Elf64_Off sh_offset; /* Section file offset */ - Elf64_Xword sh_size; /* Section size in bytes */ - Elf64_Word sh_link; /* Link to another section */ - Elf64_Word sh_info; /* Additional section information */ - Elf64_Xword sh_addralign; /* Section alignment */ - Elf64_Xword sh_entsize; /* Entry size if section holds table */ -} Elf64_Shdr; - -/* Special section indices. */ - -#define SHN_UNDEF 0 /* Undefined section */ -#define SHN_LORESERVE 0xff00 /* Start of reserved indices */ -#define SHN_LOPROC 0xff00 /* Start of processor-specific */ -#define SHN_BEFORE 0xff00 /* Order section before all others - (Solaris). */ -#define SHN_AFTER 0xff01 /* Order section after all others - (Solaris). */ -#define SHN_HIPROC 0xff1f /* End of processor-specific */ -#define SHN_LOOS 0xff20 /* Start of OS-specific */ -#define SHN_HIOS 0xff3f /* End of OS-specific */ -#define SHN_ABS 0xfff1 /* Associated symbol is absolute */ -#define SHN_COMMON 0xfff2 /* Associated symbol is common */ -#define SHN_XINDEX 0xffff /* Index is in extra table. */ -#define SHN_HIRESERVE 0xffff /* End of reserved indices */ - -/* Legal values for sh_type (section type). */ - -#define SHT_NULL 0 /* Section header table entry unused */ -#define SHT_PROGBITS 1 /* Program data */ -#define SHT_SYMTAB 2 /* Symbol table */ -#define SHT_STRTAB 3 /* String table */ -#define SHT_RELA 4 /* Relocation entries with addends */ -#define SHT_HASH 5 /* Symbol hash table */ -#define SHT_DYNAMIC 6 /* Dynamic linking information */ -#define SHT_NOTE 7 /* Notes */ -#define SHT_NOBITS 8 /* Program space with no data (bss) */ -#define SHT_REL 9 /* Relocation entries, no addends */ -#define SHT_SHLIB 10 /* Reserved */ -#define SHT_DYNSYM 11 /* Dynamic linker symbol table */ -#define SHT_INIT_ARRAY 14 /* Array of constructors */ -#define SHT_FINI_ARRAY 15 /* Array of destructors */ -#define SHT_PREINIT_ARRAY 16 /* Array of pre-constructors */ -#define SHT_GROUP 17 /* Section group */ -#define SHT_SYMTAB_SHNDX 18 /* Extended section indices */ -#define SHT_NUM 19 /* Number of defined types. */ -#define SHT_LOOS 0x60000000 /* Start OS-specific. */ -#define SHT_GNU_ATTRIBUTES 0x6ffffff5 /* Object attributes. */ -#define SHT_GNU_HASH 0x6ffffff6 /* GNU-style hash table. */ -#define SHT_GNU_LIBLIST 0x6ffffff7 /* Prelink library list */ -#define SHT_CHECKSUM 0x6ffffff8 /* Checksum for DSO content. */ -#define SHT_LOSUNW 0x6ffffffa /* Sun-specific low bound. */ -#define SHT_SUNW_move 0x6ffffffa -#define SHT_SUNW_COMDAT 0x6ffffffb -#define SHT_SUNW_syminfo 0x6ffffffc -#define SHT_GNU_verdef 0x6ffffffd /* Version definition section. */ -#define SHT_GNU_verneed 0x6ffffffe /* Version needs section. */ -#define SHT_GNU_versym 0x6fffffff /* Version symbol table. */ -#define SHT_HISUNW 0x6fffffff /* Sun-specific high bound. */ -#define SHT_HIOS 0x6fffffff /* End OS-specific type */ -#define SHT_LOPROC 0x70000000 /* Start of processor-specific */ -#define SHT_HIPROC 0x7fffffff /* End of processor-specific */ -#define SHT_LOUSER 0x80000000 /* Start of application-specific */ -#define SHT_HIUSER 0x8fffffff /* End of application-specific */ - -/* Legal values for sh_flags (section flags). */ - -#define SHF_WRITE (1 << 0) /* Writable */ -#define SHF_ALLOC (1 << 1) /* Occupies memory during execution */ -#define SHF_EXECINSTR (1 << 2) /* Executable */ -#define SHF_MERGE (1 << 4) /* Might be merged */ -#define SHF_STRINGS (1 << 5) /* Contains nul-terminated strings */ -#define SHF_INFO_LINK (1 << 6) /* `sh_info' contains SHT index */ -#define SHF_LINK_ORDER (1 << 7) /* Preserve order after combining */ -#define SHF_OS_NONCONFORMING (1 << 8) /* Non-standard OS specific handling - required */ -#define SHF_GROUP (1 << 9) /* Section is member of a group. */ -#define SHF_TLS (1 << 10) /* Section hold thread-local data. */ -#define SHF_COMPRESSED (1 << 11) /* Section with compressed data. */ -#define SHF_MASKOS 0x0ff00000 /* OS-specific. */ -#define SHF_MASKPROC 0xf0000000 /* Processor-specific */ -#define SHF_ORDERED (1 << 30) /* Special ordering requirement - (Solaris). */ -#define SHF_EXCLUDE (1U << 31) /* Section is excluded unless - referenced or allocated (Solaris).*/ - -/* Section group handling. */ -#define GRP_COMDAT 0x1 /* Mark group as COMDAT. */ - -/* Symbol table entry. */ - -typedef struct -{ - Elf32_Word st_name; /* Symbol name (string tbl index) */ - Elf32_Addr st_value; /* Symbol value */ - Elf32_Word st_size; /* Symbol size */ - unsigned char st_info; /* Symbol type and binding */ - unsigned char st_other; /* Symbol visibility */ - Elf32_Section st_shndx; /* Section index */ -} Elf32_Sym; - -typedef struct -{ - Elf64_Word st_name; /* Symbol name (string tbl index) */ - unsigned char st_info; /* Symbol type and binding */ - unsigned char st_other; /* Symbol visibility */ - Elf64_Section st_shndx; /* Section index */ - Elf64_Addr st_value; /* Symbol value */ - Elf64_Xword st_size; /* Symbol size */ -} Elf64_Sym; - -/* The syminfo section if available contains additional information about - every dynamic symbol. */ - -typedef struct -{ - Elf32_Half si_boundto; /* Direct bindings, symbol bound to */ - Elf32_Half si_flags; /* Per symbol flags */ -} Elf32_Syminfo; - -typedef struct -{ - Elf64_Half si_boundto; /* Direct bindings, symbol bound to */ - Elf64_Half si_flags; /* Per symbol flags */ -} Elf64_Syminfo; - -/* Possible values for si_boundto. */ -#define SYMINFO_BT_SELF 0xffff /* Symbol bound to self */ -#define SYMINFO_BT_PARENT 0xfffe /* Symbol bound to parent */ -#define SYMINFO_BT_LOWRESERVE 0xff00 /* Beginning of reserved entries */ - -/* Possible bitmasks for si_flags. */ -#define SYMINFO_FLG_DIRECT 0x0001 /* Direct bound symbol */ -#define SYMINFO_FLG_PASSTHRU 0x0002 /* Pass-thru symbol for translator */ -#define SYMINFO_FLG_COPY 0x0004 /* Symbol is a copy-reloc */ -#define SYMINFO_FLG_LAZYLOAD 0x0008 /* Symbol bound to object to be lazy - loaded */ -/* Syminfo version values. */ -#define SYMINFO_NONE 0 -#define SYMINFO_CURRENT 1 -#define SYMINFO_NUM 2 - - -/* How to extract and insert information held in the st_info field. */ - -#define ELF32_ST_BIND(val) (((unsigned char) (val)) >> 4) -#define ELF32_ST_TYPE(val) ((val) & 0xf) -#define ELF32_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf)) - -/* Both Elf32_Sym and Elf64_Sym use the same one-byte st_info field. */ -#define ELF64_ST_BIND(val) ELF32_ST_BIND (val) -#define ELF64_ST_TYPE(val) ELF32_ST_TYPE (val) -#define ELF64_ST_INFO(bind, type) ELF32_ST_INFO ((bind), (type)) - -/* Legal values for ST_BIND subfield of st_info (symbol binding). */ - -#define STB_LOCAL 0 /* Local symbol */ -#define STB_GLOBAL 1 /* Global symbol */ -#define STB_WEAK 2 /* Weak symbol */ -#define STB_NUM 3 /* Number of defined types. */ -#define STB_LOOS 10 /* Start of OS-specific */ -#define STB_GNU_UNIQUE 10 /* Unique symbol. */ -#define STB_HIOS 12 /* End of OS-specific */ -#define STB_LOPROC 13 /* Start of processor-specific */ -#define STB_HIPROC 15 /* End of processor-specific */ - -/* Legal values for ST_TYPE subfield of st_info (symbol type). */ - -#define STT_NOTYPE 0 /* Symbol type is unspecified */ -#define STT_OBJECT 1 /* Symbol is a data object */ -#define STT_FUNC 2 /* Symbol is a code object */ -#define STT_SECTION 3 /* Symbol associated with a section */ -#define STT_FILE 4 /* Symbol's name is file name */ -#define STT_COMMON 5 /* Symbol is a common data object */ -#define STT_TLS 6 /* Symbol is thread-local data object*/ -#define STT_NUM 7 /* Number of defined types. */ -#define STT_LOOS 10 /* Start of OS-specific */ -#define STT_GNU_IFUNC 10 /* Symbol is indirect code object */ -#define STT_HIOS 12 /* End of OS-specific */ -#define STT_LOPROC 13 /* Start of processor-specific */ -#define STT_HIPROC 15 /* End of processor-specific */ - - -/* Symbol table indices are found in the hash buckets and chain table - of a symbol hash table section. This special index value indicates - the end of a chain, meaning no further symbols are found in that bucket. */ - -#define STN_UNDEF 0 /* End of a chain. */ - - -/* How to extract and insert information held in the st_other field. */ - -#define ELF32_ST_VISIBILITY(o) ((o) & 0x03) - -/* For ELF64 the definitions are the same. */ -#define ELF64_ST_VISIBILITY(o) ELF32_ST_VISIBILITY (o) - -/* Symbol visibility specification encoded in the st_other field. */ -#define STV_DEFAULT 0 /* Default symbol visibility rules */ -#define STV_INTERNAL 1 /* Processor specific hidden class */ -#define STV_HIDDEN 2 /* Sym unavailable in other modules */ -#define STV_PROTECTED 3 /* Not preemptible, not exported */ - - -/* Relocation table entry without addend (in section of type SHT_REL). */ - -typedef struct -{ - Elf32_Addr r_offset; /* Address */ - Elf32_Word r_info; /* Relocation type and symbol index */ -} Elf32_Rel; - -/* I have seen two different definitions of the Elf64_Rel and - Elf64_Rela structures, so we'll leave them out until Novell (or - whoever) gets their act together. */ -/* The following, at least, is used on Sparc v9, MIPS, and Alpha. */ - -typedef struct -{ - Elf64_Addr r_offset; /* Address */ - Elf64_Xword r_info; /* Relocation type and symbol index */ -} Elf64_Rel; - -/* Relocation table entry with addend (in section of type SHT_RELA). */ - -typedef struct -{ - Elf32_Addr r_offset; /* Address */ - Elf32_Word r_info; /* Relocation type and symbol index */ - Elf32_Sword r_addend; /* Addend */ -} Elf32_Rela; - -typedef struct -{ - Elf64_Addr r_offset; /* Address */ - Elf64_Xword r_info; /* Relocation type and symbol index */ - Elf64_Sxword r_addend; /* Addend */ -} Elf64_Rela; - -/* How to extract and insert information held in the r_info field. */ - -#define ELF32_R_SYM(val) ((val) >> 8) -#define ELF32_R_TYPE(val) ((val) & 0xff) -#define ELF32_R_INFO(sym, type) (((sym) << 8) + ((type) & 0xff)) - -#define ELF64_R_SYM(i) ((i) >> 32) -#define ELF64_R_TYPE(i) ((i) & 0xffffffff) -#define ELF64_R_INFO(sym,type) ((((Elf64_Xword) (sym)) << 32) + (type)) - -/* Program segment header. */ - -typedef struct -{ - Elf32_Word p_type; /* Segment type */ - Elf32_Off p_offset; /* Segment file offset */ - Elf32_Addr p_vaddr; /* Segment virtual address */ - Elf32_Addr p_paddr; /* Segment physical address */ - Elf32_Word p_filesz; /* Segment size in file */ - Elf32_Word p_memsz; /* Segment size in memory */ - Elf32_Word p_flags; /* Segment flags */ - Elf32_Word p_align; /* Segment alignment */ -} Elf32_Phdr; - -typedef struct -{ - Elf64_Word p_type; /* Segment type */ - Elf64_Word p_flags; /* Segment flags */ - Elf64_Off p_offset; /* Segment file offset */ - Elf64_Addr p_vaddr; /* Segment virtual address */ - Elf64_Addr p_paddr; /* Segment physical address */ - Elf64_Xword p_filesz; /* Segment size in file */ - Elf64_Xword p_memsz; /* Segment size in memory */ - Elf64_Xword p_align; /* Segment alignment */ -} Elf64_Phdr; - -/* Special value for e_phnum. This indicates that the real number of - program headers is too large to fit into e_phnum. Instead the real - value is in the field sh_info of section 0. */ - -#define PN_XNUM 0xffff - -/* Legal values for p_type (segment type). */ - -#define PT_NULL 0 /* Program header table entry unused */ -#define PT_LOAD 1 /* Loadable program segment */ -#define PT_DYNAMIC 2 /* Dynamic linking information */ -#define PT_INTERP 3 /* Program interpreter */ -#define PT_NOTE 4 /* Auxiliary information */ -#define PT_SHLIB 5 /* Reserved */ -#define PT_PHDR 6 /* Entry for header table itself */ -#define PT_TLS 7 /* Thread-local storage segment */ -#define PT_NUM 8 /* Number of defined types */ -#define PT_LOOS 0x60000000 /* Start of OS-specific */ -#define PT_GNU_EH_FRAME 0x6474e550 /* GCC .eh_frame_hdr segment */ -#define PT_GNU_STACK 0x6474e551 /* Indicates stack executability */ -#define PT_GNU_RELRO 0x6474e552 /* Read-only after relocation */ -#define PT_LOSUNW 0x6ffffffa -#define PT_SUNWBSS 0x6ffffffa /* Sun Specific segment */ -#define PT_SUNWSTACK 0x6ffffffb /* Stack segment */ -#define PT_HISUNW 0x6fffffff -#define PT_HIOS 0x6fffffff /* End of OS-specific */ -#define PT_LOPROC 0x70000000 /* Start of processor-specific */ -#define PT_HIPROC 0x7fffffff /* End of processor-specific */ - -/* Legal values for p_flags (segment flags). */ - -#define PF_X (1 << 0) /* Segment is executable */ -#define PF_W (1 << 1) /* Segment is writable */ -#define PF_R (1 << 2) /* Segment is readable */ -#define PF_MASKOS 0x0ff00000 /* OS-specific */ -#define PF_MASKPROC 0xf0000000 /* Processor-specific */ - -/* Legal values for note segment descriptor types for core files. */ - -#define NT_PRSTATUS 1 /* Contains copy of prstatus struct */ -#define NT_FPREGSET 2 /* Contains copy of fpregset struct */ -#define NT_PRPSINFO 3 /* Contains copy of prpsinfo struct */ -#define NT_PRXREG 4 /* Contains copy of prxregset struct */ -#define NT_TASKSTRUCT 4 /* Contains copy of task structure */ -#define NT_PLATFORM 5 /* String from sysinfo(SI_PLATFORM) */ -#define NT_AUXV 6 /* Contains copy of auxv array */ -#define NT_GWINDOWS 7 /* Contains copy of gwindows struct */ -#define NT_ASRS 8 /* Contains copy of asrset struct */ -#define NT_PSTATUS 10 /* Contains copy of pstatus struct */ -#define NT_PSINFO 13 /* Contains copy of psinfo struct */ -#define NT_PRCRED 14 /* Contains copy of prcred struct */ -#define NT_UTSNAME 15 /* Contains copy of utsname struct */ -#define NT_LWPSTATUS 16 /* Contains copy of lwpstatus struct */ -#define NT_LWPSINFO 17 /* Contains copy of lwpinfo struct */ -#define NT_PRFPXREG 20 /* Contains copy of fprxregset struct */ -#define NT_PRXFPREG 0x46e62b7f /* Contains copy of user_fxsr_struct */ -#define NT_PPC_VMX 0x100 /* PowerPC Altivec/VMX registers */ -#define NT_PPC_SPE 0x101 /* PowerPC SPE/EVR registers */ -#define NT_PPC_VSX 0x102 /* PowerPC VSX registers */ -#define NT_386_TLS 0x200 /* i386 TLS slots (struct user_desc) */ -#define NT_386_IOPERM 0x201 /* x86 io permission bitmap (1=deny) */ -#define NT_X86_XSTATE 0x202 /* x86 extended state using xsave */ -#define NT_S390_HIGH_GPRS 0x300 /* s390 upper register halves */ -#define NT_S390_TIMER 0x301 /* s390 timer register */ -#define NT_S390_TODCMP 0x302 /* s390 TOD clock comparator register */ -#define NT_S390_TODPREG 0x303 /* s390 TOD programmable register */ -#define NT_S390_CTRS 0x304 /* s390 control registers */ -#define NT_S390_PREFIX 0x305 /* s390 prefix register */ -#define NT_S390_LAST_BREAK 0x306 /* s390 breaking event address */ -#define NT_S390_SYSTEM_CALL 0x307 /* s390 system call restart data */ -#define NT_ARM_VFP 0x400 /* ARM VFP/NEON registers */ -#define NT_ARM_TLS 0x401 /* ARM TLS register */ -#define NT_ARM_HW_BREAK 0x402 /* ARM hardware breakpoint registers */ -#define NT_ARM_HW_WATCH 0x403 /* ARM hardware watchpoint registers */ - -/* Legal values for the note segment descriptor types for object files. */ - -#define NT_VERSION 1 /* Contains a version string. */ - - -/* Dynamic section entry. */ - -typedef struct -{ - Elf32_Sword d_tag; /* Dynamic entry type */ - union - { - Elf32_Word d_val; /* Integer value */ - Elf32_Addr d_ptr; /* Address value */ - } d_un; -} Elf32_Dyn; - -typedef struct -{ - Elf64_Sxword d_tag; /* Dynamic entry type */ - union - { - Elf64_Xword d_val; /* Integer value */ - Elf64_Addr d_ptr; /* Address value */ - } d_un; -} Elf64_Dyn; - -/* Legal values for d_tag (dynamic entry type). */ - -#define DT_NULL 0 /* Marks end of dynamic section */ -#define DT_NEEDED 1 /* Name of needed library */ -#define DT_PLTRELSZ 2 /* Size in bytes of PLT relocs */ -#define DT_PLTGOT 3 /* Processor defined value */ -#define DT_HASH 4 /* Address of symbol hash table */ -#define DT_STRTAB 5 /* Address of string table */ -#define DT_SYMTAB 6 /* Address of symbol table */ -#define DT_RELA 7 /* Address of Rela relocs */ -#define DT_RELASZ 8 /* Total size of Rela relocs */ -#define DT_RELAENT 9 /* Size of one Rela reloc */ -#define DT_STRSZ 10 /* Size of string table */ -#define DT_SYMENT 11 /* Size of one symbol table entry */ -#define DT_INIT 12 /* Address of init function */ -#define DT_FINI 13 /* Address of termination function */ -#define DT_SONAME 14 /* Name of shared object */ -#define DT_RPATH 15 /* Library search path (deprecated) */ -#define DT_SYMBOLIC 16 /* Start symbol search here */ -#define DT_REL 17 /* Address of Rel relocs */ -#define DT_RELSZ 18 /* Total size of Rel relocs */ -#define DT_RELENT 19 /* Size of one Rel reloc */ -#define DT_PLTREL 20 /* Type of reloc in PLT */ -#define DT_DEBUG 21 /* For debugging; unspecified */ -#define DT_TEXTREL 22 /* Reloc might modify .text */ -#define DT_JMPREL 23 /* Address of PLT relocs */ -#define DT_BIND_NOW 24 /* Process relocations of object */ -#define DT_INIT_ARRAY 25 /* Array with addresses of init fct */ -#define DT_FINI_ARRAY 26 /* Array with addresses of fini fct */ -#define DT_INIT_ARRAYSZ 27 /* Size in bytes of DT_INIT_ARRAY */ -#define DT_FINI_ARRAYSZ 28 /* Size in bytes of DT_FINI_ARRAY */ -#define DT_RUNPATH 29 /* Library search path */ -#define DT_FLAGS 30 /* Flags for the object being loaded */ -#define DT_ENCODING 32 /* Start of encoded range */ -#define DT_PREINIT_ARRAY 32 /* Array with addresses of preinit fct*/ -#define DT_PREINIT_ARRAYSZ 33 /* size in bytes of DT_PREINIT_ARRAY */ -#define DT_NUM 34 /* Number used */ -#define DT_LOOS 0x6000000d /* Start of OS-specific */ -#define DT_HIOS 0x6ffff000 /* End of OS-specific */ -#define DT_LOPROC 0x70000000 /* Start of processor-specific */ -#define DT_HIPROC 0x7fffffff /* End of processor-specific */ -#define DT_PROCNUM DT_MIPS_NUM /* Most used by any processor */ - -/* DT_* entries which fall between DT_VALRNGHI & DT_VALRNGLO use the - Dyn.d_un.d_val field of the Elf*_Dyn structure. This follows Sun's - approach. */ -#define DT_VALRNGLO 0x6ffffd00 -#define DT_GNU_PRELINKED 0x6ffffdf5 /* Prelinking timestamp */ -#define DT_GNU_CONFLICTSZ 0x6ffffdf6 /* Size of conflict section */ -#define DT_GNU_LIBLISTSZ 0x6ffffdf7 /* Size of library list */ -#define DT_CHECKSUM 0x6ffffdf8 -#define DT_PLTPADSZ 0x6ffffdf9 -#define DT_MOVEENT 0x6ffffdfa -#define DT_MOVESZ 0x6ffffdfb -#define DT_FEATURE_1 0x6ffffdfc /* Feature selection (DTF_*). */ -#define DT_POSFLAG_1 0x6ffffdfd /* Flags for DT_* entries, effecting - the following DT_* entry. */ -#define DT_SYMINSZ 0x6ffffdfe /* Size of syminfo table (in bytes) */ -#define DT_SYMINENT 0x6ffffdff /* Entry size of syminfo */ -#define DT_VALRNGHI 0x6ffffdff -#define DT_VALTAGIDX(tag) (DT_VALRNGHI - (tag)) /* Reverse order! */ -#define DT_VALNUM 12 - -/* DT_* entries which fall between DT_ADDRRNGHI & DT_ADDRRNGLO use the - Dyn.d_un.d_ptr field of the Elf*_Dyn structure. - - If any adjustment is made to the ELF object after it has been - built these entries will need to be adjusted. */ -#define DT_ADDRRNGLO 0x6ffffe00 -#define DT_GNU_HASH 0x6ffffef5 /* GNU-style hash table. */ -#define DT_TLSDESC_PLT 0x6ffffef6 -#define DT_TLSDESC_GOT 0x6ffffef7 -#define DT_GNU_CONFLICT 0x6ffffef8 /* Start of conflict section */ -#define DT_GNU_LIBLIST 0x6ffffef9 /* Library list */ -#define DT_CONFIG 0x6ffffefa /* Configuration information. */ -#define DT_DEPAUDIT 0x6ffffefb /* Dependency auditing. */ -#define DT_AUDIT 0x6ffffefc /* Object auditing. */ -#define DT_PLTPAD 0x6ffffefd /* PLT padding. */ -#define DT_MOVETAB 0x6ffffefe /* Move table. */ -#define DT_SYMINFO 0x6ffffeff /* Syminfo table. */ -#define DT_ADDRRNGHI 0x6ffffeff -#define DT_ADDRTAGIDX(tag) (DT_ADDRRNGHI - (tag)) /* Reverse order! */ -#define DT_ADDRNUM 11 - -/* The versioning entry types. The next are defined as part of the - GNU extension. */ -#define DT_VERSYM 0x6ffffff0 - -#define DT_RELACOUNT 0x6ffffff9 -#define DT_RELCOUNT 0x6ffffffa - -/* These were chosen by Sun. */ -#define DT_FLAGS_1 0x6ffffffb /* State flags, see DF_1_* below. */ -#define DT_VERDEF 0x6ffffffc /* Address of version definition - table */ -#define DT_VERDEFNUM 0x6ffffffd /* Number of version definitions */ -#define DT_VERNEED 0x6ffffffe /* Address of table with needed - versions */ -#define DT_VERNEEDNUM 0x6fffffff /* Number of needed versions */ -#define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */ -#define DT_VERSIONTAGNUM 16 - -/* Sun added these machine-independent extensions in the "processor-specific" - range. Be compatible. */ -#define DT_AUXILIARY 0x7ffffffd /* Shared object to load before self */ -#define DT_FILTER 0x7fffffff /* Shared object to get values from */ -#define DT_EXTRATAGIDX(tag) ((Elf32_Word)-((Elf32_Sword) (tag) <<1>>1)-1) -#define DT_EXTRANUM 3 - -/* Values of `d_un.d_val' in the DT_FLAGS entry. */ -#define DF_ORIGIN 0x00000001 /* Object may use DF_ORIGIN */ -#define DF_SYMBOLIC 0x00000002 /* Symbol resolutions starts here */ -#define DF_TEXTREL 0x00000004 /* Object contains text relocations */ -#define DF_BIND_NOW 0x00000008 /* No lazy binding for this object */ -#define DF_STATIC_TLS 0x00000010 /* Module uses the static TLS model */ - -/* State flags selectable in the `d_un.d_val' element of the DT_FLAGS_1 - entry in the dynamic section. */ -#define DF_1_NOW 0x00000001 /* Set RTLD_NOW for this object. */ -#define DF_1_GLOBAL 0x00000002 /* Set RTLD_GLOBAL for this object. */ -#define DF_1_GROUP 0x00000004 /* Set RTLD_GROUP for this object. */ -#define DF_1_NODELETE 0x00000008 /* Set RTLD_NODELETE for this object.*/ -#define DF_1_LOADFLTR 0x00000010 /* Trigger filtee loading at runtime.*/ -#define DF_1_INITFIRST 0x00000020 /* Set RTLD_INITFIRST for this object*/ -#define DF_1_NOOPEN 0x00000040 /* Set RTLD_NOOPEN for this object. */ -#define DF_1_ORIGIN 0x00000080 /* $ORIGIN must be handled. */ -#define DF_1_DIRECT 0x00000100 /* Direct binding enabled. */ -#define DF_1_TRANS 0x00000200 -#define DF_1_INTERPOSE 0x00000400 /* Object is used to interpose. */ -#define DF_1_NODEFLIB 0x00000800 /* Ignore default lib search path. */ -#define DF_1_NODUMP 0x00001000 /* Object can't be dldump'ed. */ -#define DF_1_CONFALT 0x00002000 /* Configuration alternative created.*/ -#define DF_1_ENDFILTEE 0x00004000 /* Filtee terminates filters search. */ -#define DF_1_DISPRELDNE 0x00008000 /* Disp reloc applied at build time. */ -#define DF_1_DISPRELPND 0x00010000 /* Disp reloc applied at run-time. */ -#define DF_1_NODIRECT 0x00020000 /* Object has no-direct binding. */ -#define DF_1_IGNMULDEF 0x00040000 -#define DF_1_NOKSYMS 0x00080000 -#define DF_1_NOHDR 0x00100000 -#define DF_1_EDITED 0x00200000 /* Object is modified after built. */ -#define DF_1_NORELOC 0x00400000 -#define DF_1_SYMINTPOSE 0x00800000 /* Object has individual interposers. */ -#define DF_1_GLOBAUDIT 0x01000000 /* Global auditing required. */ -#define DF_1_SINGLETON 0x02000000 /* Singleton symbols are used. */ - -/* Flags for the feature selection in DT_FEATURE_1. */ -#define DTF_1_PARINIT 0x00000001 -#define DTF_1_CONFEXP 0x00000002 - -/* Flags in the DT_POSFLAG_1 entry effecting only the next DT_* entry. */ -#define DF_P1_LAZYLOAD 0x00000001 /* Lazyload following object. */ -#define DF_P1_GROUPPERM 0x00000002 /* Symbols from next object are not - generally available. */ - -/* Version definition sections. */ - -typedef struct -{ - Elf32_Half vd_version; /* Version revision */ - Elf32_Half vd_flags; /* Version information */ - Elf32_Half vd_ndx; /* Version Index */ - Elf32_Half vd_cnt; /* Number of associated aux entries */ - Elf32_Word vd_hash; /* Version name hash value */ - Elf32_Word vd_aux; /* Offset in bytes to verdaux array */ - Elf32_Word vd_next; /* Offset in bytes to next verdef - entry */ -} Elf32_Verdef; - -typedef struct -{ - Elf64_Half vd_version; /* Version revision */ - Elf64_Half vd_flags; /* Version information */ - Elf64_Half vd_ndx; /* Version Index */ - Elf64_Half vd_cnt; /* Number of associated aux entries */ - Elf64_Word vd_hash; /* Version name hash value */ - Elf64_Word vd_aux; /* Offset in bytes to verdaux array */ - Elf64_Word vd_next; /* Offset in bytes to next verdef - entry */ -} Elf64_Verdef; - - -/* Legal values for vd_version (version revision). */ -#define VER_DEF_NONE 0 /* No version */ -#define VER_DEF_CURRENT 1 /* Current version */ -#define VER_DEF_NUM 2 /* Given version number */ - -/* Legal values for vd_flags (version information flags). */ -#define VER_FLG_BASE 0x1 /* Version definition of file itself */ -#define VER_FLG_WEAK 0x2 /* Weak version identifier */ - -/* Versym symbol index values. */ -#define VER_NDX_LOCAL 0 /* Symbol is local. */ -#define VER_NDX_GLOBAL 1 /* Symbol is global. */ -#define VER_NDX_LORESERVE 0xff00 /* Beginning of reserved entries. */ -#define VER_NDX_ELIMINATE 0xff01 /* Symbol is to be eliminated. */ - -/* Auxiliary version information. */ - -typedef struct -{ - Elf32_Word vda_name; /* Version or dependency names */ - Elf32_Word vda_next; /* Offset in bytes to next verdaux - entry */ -} Elf32_Verdaux; - -typedef struct -{ - Elf64_Word vda_name; /* Version or dependency names */ - Elf64_Word vda_next; /* Offset in bytes to next verdaux - entry */ -} Elf64_Verdaux; - - -/* Version dependency section. */ - -typedef struct -{ - Elf32_Half vn_version; /* Version of structure */ - Elf32_Half vn_cnt; /* Number of associated aux entries */ - Elf32_Word vn_file; /* Offset of filename for this - dependency */ - Elf32_Word vn_aux; /* Offset in bytes to vernaux array */ - Elf32_Word vn_next; /* Offset in bytes to next verneed - entry */ -} Elf32_Verneed; - -typedef struct -{ - Elf64_Half vn_version; /* Version of structure */ - Elf64_Half vn_cnt; /* Number of associated aux entries */ - Elf64_Word vn_file; /* Offset of filename for this - dependency */ - Elf64_Word vn_aux; /* Offset in bytes to vernaux array */ - Elf64_Word vn_next; /* Offset in bytes to next verneed - entry */ -} Elf64_Verneed; - - -/* Legal values for vn_version (version revision). */ -#define VER_NEED_NONE 0 /* No version */ -#define VER_NEED_CURRENT 1 /* Current version */ -#define VER_NEED_NUM 2 /* Given version number */ - -/* Auxiliary needed version information. */ - -typedef struct -{ - Elf32_Word vna_hash; /* Hash value of dependency name */ - Elf32_Half vna_flags; /* Dependency specific information */ - Elf32_Half vna_other; /* Unused */ - Elf32_Word vna_name; /* Dependency name string offset */ - Elf32_Word vna_next; /* Offset in bytes to next vernaux - entry */ -} Elf32_Vernaux; - -typedef struct -{ - Elf64_Word vna_hash; /* Hash value of dependency name */ - Elf64_Half vna_flags; /* Dependency specific information */ - Elf64_Half vna_other; /* Unused */ - Elf64_Word vna_name; /* Dependency name string offset */ - Elf64_Word vna_next; /* Offset in bytes to next vernaux - entry */ -} Elf64_Vernaux; - - -/* Legal values for vna_flags. */ -#define VER_FLG_WEAK 0x2 /* Weak version identifier */ - - -/* Auxiliary vector. */ - -/* This vector is normally only used by the program interpreter. The - usual definition in an ABI supplement uses the name auxv_t. The - vector is not usually defined in a standard file, but it - can't hurt. We rename it to avoid conflicts. The sizes of these - types are an arrangement between the exec server and the program - interpreter, so we don't fully specify them here. */ - -typedef struct -{ - uint32_t a_type; /* Entry type */ - union - { - uint32_t a_val; /* Integer value */ - /* We use to have pointer elements added here. We cannot do that, - though, since it does not work when using 32-bit definitions - on 64-bit platforms and vice versa. */ - } a_un; -} Elf32_auxv_t; - -typedef struct -{ - uint64_t a_type; /* Entry type */ - union - { - uint64_t a_val; /* Integer value */ - /* We use to have pointer elements added here. We cannot do that, - though, since it does not work when using 32-bit definitions - on 64-bit platforms and vice versa. */ - } a_un; -} Elf64_auxv_t; - -/* Legal values for a_type (entry type). */ - -#define AT_NULL 0 /* End of vector */ -#define AT_IGNORE 1 /* Entry should be ignored */ -#define AT_EXECFD 2 /* File descriptor of program */ -#define AT_PHDR 3 /* Program headers for program */ -#define AT_PHENT 4 /* Size of program header entry */ -#define AT_PHNUM 5 /* Number of program headers */ -#define AT_PAGESZ 6 /* System page size */ -#define AT_BASE 7 /* Base address of interpreter */ -#define AT_FLAGS 8 /* Flags */ -#define AT_ENTRY 9 /* Entry point of program */ -#define AT_NOTELF 10 /* Program is not ELF */ -#define AT_UID 11 /* Real uid */ -#define AT_EUID 12 /* Effective uid */ -#define AT_GID 13 /* Real gid */ -#define AT_EGID 14 /* Effective gid */ -#define AT_CLKTCK 17 /* Frequency of times() */ - -/* Some more special a_type values describing the hardware. */ -#define AT_PLATFORM 15 /* String identifying platform. */ -#define AT_HWCAP 16 /* Machine dependent hints about - processor capabilities. */ - -/* This entry gives some information about the FPU initialization - performed by the kernel. */ -#define AT_FPUCW 18 /* Used FPU control word. */ - -/* Cache block sizes. */ -#define AT_DCACHEBSIZE 19 /* Data cache block size. */ -#define AT_ICACHEBSIZE 20 /* Instruction cache block size. */ -#define AT_UCACHEBSIZE 21 /* Unified cache block size. */ - -/* A special ignored value for PPC, used by the kernel to control the - interpretation of the AUXV. Must be > 16. */ -#define AT_IGNOREPPC 22 /* Entry should be ignored. */ - -#define AT_SECURE 23 /* Boolean, was exec setuid-like? */ - -#define AT_BASE_PLATFORM 24 /* String identifying real platforms.*/ - -#define AT_RANDOM 25 /* Address of 16 random bytes. */ - -#define AT_EXECFN 31 /* Filename of executable. */ - -/* Pointer to the global system page used for system calls and other - nice things. */ -#define AT_SYSINFO 32 -#define AT_SYSINFO_EHDR 33 - -/* Shapes of the caches. Bits 0-3 contains associativity; bits 4-7 contains - log2 of line size; mask those to get cache size. */ -#define AT_L1I_CACHESHAPE 34 -#define AT_L1D_CACHESHAPE 35 -#define AT_L2_CACHESHAPE 36 -#define AT_L3_CACHESHAPE 37 - -/* Note section contents. Each entry in the note section begins with - a header of a fixed form. */ - -typedef struct -{ - Elf32_Word n_namesz; /* Length of the note's name. */ - Elf32_Word n_descsz; /* Length of the note's descriptor. */ - Elf32_Word n_type; /* Type of the note. */ -} Elf32_Nhdr; - -typedef struct -{ - Elf64_Word n_namesz; /* Length of the note's name. */ - Elf64_Word n_descsz; /* Length of the note's descriptor. */ - Elf64_Word n_type; /* Type of the note. */ -} Elf64_Nhdr; - -/* Known names of notes. */ - -/* Solaris entries in the note section have this name. */ -#define ELF_NOTE_SOLARIS "SUNW Solaris" - -/* Note entries for GNU systems have this name. */ -#define ELF_NOTE_GNU "GNU" - - -/* Defined types of notes for Solaris. */ - -/* Value of descriptor (one word) is desired pagesize for the binary. */ -#define ELF_NOTE_PAGESIZE_HINT 1 - - -/* Defined note types for GNU systems. */ - -/* ABI information. The descriptor consists of words: - word 0: OS descriptor - word 1: major version of the ABI - word 2: minor version of the ABI - word 3: subminor version of the ABI -*/ -#define NT_GNU_ABI_TAG 1 -#define ELF_NOTE_ABI NT_GNU_ABI_TAG /* Old name. */ - -/* Known OSes. These values can appear in word 0 of an - NT_GNU_ABI_TAG note section entry. */ -#define ELF_NOTE_OS_LINUX 0 -#define ELF_NOTE_OS_GNU 1 -#define ELF_NOTE_OS_SOLARIS2 2 -#define ELF_NOTE_OS_FREEBSD 3 - -/* Synthetic hwcap information. The descriptor begins with two words: - word 0: number of entries - word 1: bitmask of enabled entries - Then follow variable-length entries, one byte followed by a - '\0'-terminated hwcap name string. The byte gives the bit - number to test if enabled, (1U << bit) & bitmask. */ -#define NT_GNU_HWCAP 2 - -/* Build ID bits as generated by ld --build-id. - The descriptor consists of any nonzero number of bytes. */ -#define NT_GNU_BUILD_ID 3 - -/* Version note generated by GNU gold containing a version string. */ -#define NT_GNU_GOLD_VERSION 4 - - -/* Move records. */ -typedef struct -{ - Elf32_Xword m_value; /* Symbol value. */ - Elf32_Word m_info; /* Size and index. */ - Elf32_Word m_poffset; /* Symbol offset. */ - Elf32_Half m_repeat; /* Repeat count. */ - Elf32_Half m_stride; /* Stride info. */ -} Elf32_Move; - -typedef struct -{ - Elf64_Xword m_value; /* Symbol value. */ - Elf64_Xword m_info; /* Size and index. */ - Elf64_Xword m_poffset; /* Symbol offset. */ - Elf64_Half m_repeat; /* Repeat count. */ - Elf64_Half m_stride; /* Stride info. */ -} Elf64_Move; - -/* Macro to construct move records. */ -#define ELF32_M_SYM(info) ((info) >> 8) -#define ELF32_M_SIZE(info) ((unsigned char) (info)) -#define ELF32_M_INFO(sym, size) (((sym) << 8) + (unsigned char) (size)) - -#define ELF64_M_SYM(info) ELF32_M_SYM (info) -#define ELF64_M_SIZE(info) ELF32_M_SIZE (info) -#define ELF64_M_INFO(sym, size) ELF32_M_INFO (sym, size) - - -/* Motorola 68k specific definitions. */ - -/* Values for Elf32_Ehdr.e_flags. */ -#define EF_CPU32 0x00810000 - -/* m68k relocs. */ - -#define R_68K_NONE 0 /* No reloc */ -#define R_68K_32 1 /* Direct 32 bit */ -#define R_68K_16 2 /* Direct 16 bit */ -#define R_68K_8 3 /* Direct 8 bit */ -#define R_68K_PC32 4 /* PC relative 32 bit */ -#define R_68K_PC16 5 /* PC relative 16 bit */ -#define R_68K_PC8 6 /* PC relative 8 bit */ -#define R_68K_GOT32 7 /* 32 bit PC relative GOT entry */ -#define R_68K_GOT16 8 /* 16 bit PC relative GOT entry */ -#define R_68K_GOT8 9 /* 8 bit PC relative GOT entry */ -#define R_68K_GOT32O 10 /* 32 bit GOT offset */ -#define R_68K_GOT16O 11 /* 16 bit GOT offset */ -#define R_68K_GOT8O 12 /* 8 bit GOT offset */ -#define R_68K_PLT32 13 /* 32 bit PC relative PLT address */ -#define R_68K_PLT16 14 /* 16 bit PC relative PLT address */ -#define R_68K_PLT8 15 /* 8 bit PC relative PLT address */ -#define R_68K_PLT32O 16 /* 32 bit PLT offset */ -#define R_68K_PLT16O 17 /* 16 bit PLT offset */ -#define R_68K_PLT8O 18 /* 8 bit PLT offset */ -#define R_68K_COPY 19 /* Copy symbol at runtime */ -#define R_68K_GLOB_DAT 20 /* Create GOT entry */ -#define R_68K_JMP_SLOT 21 /* Create PLT entry */ -#define R_68K_RELATIVE 22 /* Adjust by program base */ -#define R_68K_TLS_GD32 25 /* 32 bit GOT offset for GD */ -#define R_68K_TLS_GD16 26 /* 16 bit GOT offset for GD */ -#define R_68K_TLS_GD8 27 /* 8 bit GOT offset for GD */ -#define R_68K_TLS_LDM32 28 /* 32 bit GOT offset for LDM */ -#define R_68K_TLS_LDM16 29 /* 16 bit GOT offset for LDM */ -#define R_68K_TLS_LDM8 30 /* 8 bit GOT offset for LDM */ -#define R_68K_TLS_LDO32 31 /* 32 bit module-relative offset */ -#define R_68K_TLS_LDO16 32 /* 16 bit module-relative offset */ -#define R_68K_TLS_LDO8 33 /* 8 bit module-relative offset */ -#define R_68K_TLS_IE32 34 /* 32 bit GOT offset for IE */ -#define R_68K_TLS_IE16 35 /* 16 bit GOT offset for IE */ -#define R_68K_TLS_IE8 36 /* 8 bit GOT offset for IE */ -#define R_68K_TLS_LE32 37 /* 32 bit offset relative to - static TLS block */ -#define R_68K_TLS_LE16 38 /* 16 bit offset relative to - static TLS block */ -#define R_68K_TLS_LE8 39 /* 8 bit offset relative to - static TLS block */ -#define R_68K_TLS_DTPMOD32 40 /* 32 bit module number */ -#define R_68K_TLS_DTPREL32 41 /* 32 bit module-relative offset */ -#define R_68K_TLS_TPREL32 42 /* 32 bit TP-relative offset */ -/* Keep this the last entry. */ -#define R_68K_NUM 43 - -/* Intel 80386 specific definitions. */ - -/* i386 relocs. */ - -#define R_386_NONE 0 /* No reloc */ -#define R_386_32 1 /* Direct 32 bit */ -#define R_386_PC32 2 /* PC relative 32 bit */ -#define R_386_GOT32 3 /* 32 bit GOT entry */ -#define R_386_PLT32 4 /* 32 bit PLT address */ -#define R_386_COPY 5 /* Copy symbol at runtime */ -#define R_386_GLOB_DAT 6 /* Create GOT entry */ -#define R_386_JMP_SLOT 7 /* Create PLT entry */ -#define R_386_RELATIVE 8 /* Adjust by program base */ -#define R_386_GOTOFF 9 /* 32 bit offset to GOT */ -#define R_386_GOTPC 10 /* 32 bit PC relative offset to GOT */ -#define R_386_32PLT 11 -#define R_386_TLS_TPOFF 14 /* Offset in static TLS block */ -#define R_386_TLS_IE 15 /* Address of GOT entry for static TLS - block offset */ -#define R_386_TLS_GOTIE 16 /* GOT entry for static TLS block - offset */ -#define R_386_TLS_LE 17 /* Offset relative to static TLS - block */ -#define R_386_TLS_GD 18 /* Direct 32 bit for GNU version of - general dynamic thread local data */ -#define R_386_TLS_LDM 19 /* Direct 32 bit for GNU version of - local dynamic thread local data - in LE code */ -#define R_386_16 20 -#define R_386_PC16 21 -#define R_386_8 22 -#define R_386_PC8 23 -#define R_386_TLS_GD_32 24 /* Direct 32 bit for general dynamic - thread local data */ -#define R_386_TLS_GD_PUSH 25 /* Tag for pushl in GD TLS code */ -#define R_386_TLS_GD_CALL 26 /* Relocation for call to - __tls_get_addr() */ -#define R_386_TLS_GD_POP 27 /* Tag for popl in GD TLS code */ -#define R_386_TLS_LDM_32 28 /* Direct 32 bit for local dynamic - thread local data in LE code */ -#define R_386_TLS_LDM_PUSH 29 /* Tag for pushl in LDM TLS code */ -#define R_386_TLS_LDM_CALL 30 /* Relocation for call to - __tls_get_addr() in LDM code */ -#define R_386_TLS_LDM_POP 31 /* Tag for popl in LDM TLS code */ -#define R_386_TLS_LDO_32 32 /* Offset relative to TLS block */ -#define R_386_TLS_IE_32 33 /* GOT entry for negated static TLS - block offset */ -#define R_386_TLS_LE_32 34 /* Negated offset relative to static - TLS block */ -#define R_386_TLS_DTPMOD32 35 /* ID of module containing symbol */ -#define R_386_TLS_DTPOFF32 36 /* Offset in TLS block */ -#define R_386_TLS_TPOFF32 37 /* Negated offset in static TLS block */ -/* 38? */ -#define R_386_TLS_GOTDESC 39 /* GOT offset for TLS descriptor. */ -#define R_386_TLS_DESC_CALL 40 /* Marker of call through TLS - descriptor for - relaxation. */ -#define R_386_TLS_DESC 41 /* TLS descriptor containing - pointer to code and to - argument, returning the TLS - offset for the symbol. */ -#define R_386_IRELATIVE 42 /* Adjust indirectly by program base */ -#define R_386_GOT32X 43 /* 32 bit GOT entry, relaxable */ -/* Keep this the last entry. */ -#define R_386_NUM 44 - -/* SUN SPARC specific definitions. */ - -/* Legal values for ST_TYPE subfield of st_info (symbol type). */ - -#define STT_SPARC_REGISTER 13 /* Global register reserved to app. */ - -/* Values for Elf64_Ehdr.e_flags. */ - -#define EF_SPARCV9_MM 3 -#define EF_SPARCV9_TSO 0 -#define EF_SPARCV9_PSO 1 -#define EF_SPARCV9_RMO 2 -#define EF_SPARC_LEDATA 0x800000 /* little endian data */ -#define EF_SPARC_EXT_MASK 0xFFFF00 -#define EF_SPARC_32PLUS 0x000100 /* generic V8+ features */ -#define EF_SPARC_SUN_US1 0x000200 /* Sun UltraSPARC1 extensions */ -#define EF_SPARC_HAL_R1 0x000400 /* HAL R1 extensions */ -#define EF_SPARC_SUN_US3 0x000800 /* Sun UltraSPARCIII extensions */ - -/* SPARC relocs. */ - -#define R_SPARC_NONE 0 /* No reloc */ -#define R_SPARC_8 1 /* Direct 8 bit */ -#define R_SPARC_16 2 /* Direct 16 bit */ -#define R_SPARC_32 3 /* Direct 32 bit */ -#define R_SPARC_DISP8 4 /* PC relative 8 bit */ -#define R_SPARC_DISP16 5 /* PC relative 16 bit */ -#define R_SPARC_DISP32 6 /* PC relative 32 bit */ -#define R_SPARC_WDISP30 7 /* PC relative 30 bit shifted */ -#define R_SPARC_WDISP22 8 /* PC relative 22 bit shifted */ -#define R_SPARC_HI22 9 /* High 22 bit */ -#define R_SPARC_22 10 /* Direct 22 bit */ -#define R_SPARC_13 11 /* Direct 13 bit */ -#define R_SPARC_LO10 12 /* Truncated 10 bit */ -#define R_SPARC_GOT10 13 /* Truncated 10 bit GOT entry */ -#define R_SPARC_GOT13 14 /* 13 bit GOT entry */ -#define R_SPARC_GOT22 15 /* 22 bit GOT entry shifted */ -#define R_SPARC_PC10 16 /* PC relative 10 bit truncated */ -#define R_SPARC_PC22 17 /* PC relative 22 bit shifted */ -#define R_SPARC_WPLT30 18 /* 30 bit PC relative PLT address */ -#define R_SPARC_COPY 19 /* Copy symbol at runtime */ -#define R_SPARC_GLOB_DAT 20 /* Create GOT entry */ -#define R_SPARC_JMP_SLOT 21 /* Create PLT entry */ -#define R_SPARC_RELATIVE 22 /* Adjust by program base */ -#define R_SPARC_UA32 23 /* Direct 32 bit unaligned */ - -/* Additional Sparc64 relocs. */ - -#define R_SPARC_PLT32 24 /* Direct 32 bit ref to PLT entry */ -#define R_SPARC_HIPLT22 25 /* High 22 bit PLT entry */ -#define R_SPARC_LOPLT10 26 /* Truncated 10 bit PLT entry */ -#define R_SPARC_PCPLT32 27 /* PC rel 32 bit ref to PLT entry */ -#define R_SPARC_PCPLT22 28 /* PC rel high 22 bit PLT entry */ -#define R_SPARC_PCPLT10 29 /* PC rel trunc 10 bit PLT entry */ -#define R_SPARC_10 30 /* Direct 10 bit */ -#define R_SPARC_11 31 /* Direct 11 bit */ -#define R_SPARC_64 32 /* Direct 64 bit */ -#define R_SPARC_OLO10 33 /* 10bit with secondary 13bit addend */ -#define R_SPARC_HH22 34 /* Top 22 bits of direct 64 bit */ -#define R_SPARC_HM10 35 /* High middle 10 bits of ... */ -#define R_SPARC_LM22 36 /* Low middle 22 bits of ... */ -#define R_SPARC_PC_HH22 37 /* Top 22 bits of pc rel 64 bit */ -#define R_SPARC_PC_HM10 38 /* High middle 10 bit of ... */ -#define R_SPARC_PC_LM22 39 /* Low middle 22 bits of ... */ -#define R_SPARC_WDISP16 40 /* PC relative 16 bit shifted */ -#define R_SPARC_WDISP19 41 /* PC relative 19 bit shifted */ -#define R_SPARC_GLOB_JMP 42 /* was part of v9 ABI but was removed */ -#define R_SPARC_7 43 /* Direct 7 bit */ -#define R_SPARC_5 44 /* Direct 5 bit */ -#define R_SPARC_6 45 /* Direct 6 bit */ -#define R_SPARC_DISP64 46 /* PC relative 64 bit */ -#define R_SPARC_PLT64 47 /* Direct 64 bit ref to PLT entry */ -#define R_SPARC_HIX22 48 /* High 22 bit complemented */ -#define R_SPARC_LOX10 49 /* Truncated 11 bit complemented */ -#define R_SPARC_H44 50 /* Direct high 12 of 44 bit */ -#define R_SPARC_M44 51 /* Direct mid 22 of 44 bit */ -#define R_SPARC_L44 52 /* Direct low 10 of 44 bit */ -#define R_SPARC_REGISTER 53 /* Global register usage */ -#define R_SPARC_UA64 54 /* Direct 64 bit unaligned */ -#define R_SPARC_UA16 55 /* Direct 16 bit unaligned */ -#define R_SPARC_TLS_GD_HI22 56 -#define R_SPARC_TLS_GD_LO10 57 -#define R_SPARC_TLS_GD_ADD 58 -#define R_SPARC_TLS_GD_CALL 59 -#define R_SPARC_TLS_LDM_HI22 60 -#define R_SPARC_TLS_LDM_LO10 61 -#define R_SPARC_TLS_LDM_ADD 62 -#define R_SPARC_TLS_LDM_CALL 63 -#define R_SPARC_TLS_LDO_HIX22 64 -#define R_SPARC_TLS_LDO_LOX10 65 -#define R_SPARC_TLS_LDO_ADD 66 -#define R_SPARC_TLS_IE_HI22 67 -#define R_SPARC_TLS_IE_LO10 68 -#define R_SPARC_TLS_IE_LD 69 -#define R_SPARC_TLS_IE_LDX 70 -#define R_SPARC_TLS_IE_ADD 71 -#define R_SPARC_TLS_LE_HIX22 72 -#define R_SPARC_TLS_LE_LOX10 73 -#define R_SPARC_TLS_DTPMOD32 74 -#define R_SPARC_TLS_DTPMOD64 75 -#define R_SPARC_TLS_DTPOFF32 76 -#define R_SPARC_TLS_DTPOFF64 77 -#define R_SPARC_TLS_TPOFF32 78 -#define R_SPARC_TLS_TPOFF64 79 -#define R_SPARC_GOTDATA_HIX22 80 -#define R_SPARC_GOTDATA_LOX10 81 -#define R_SPARC_GOTDATA_OP_HIX22 82 -#define R_SPARC_GOTDATA_OP_LOX10 83 -#define R_SPARC_GOTDATA_OP 84 -#define R_SPARC_H34 85 -#define R_SPARC_SIZE32 86 -#define R_SPARC_SIZE64 87 -#define R_SPARC_WDISP10 88 -#define R_SPARC_JMP_IREL 248 -#define R_SPARC_IRELATIVE 249 -#define R_SPARC_GNU_VTINHERIT 250 -#define R_SPARC_GNU_VTENTRY 251 -#define R_SPARC_REV32 252 -/* Keep this the last entry. */ -#define R_SPARC_NUM 253 - -/* For Sparc64, legal values for d_tag of Elf64_Dyn. */ - -#define DT_SPARC_REGISTER 0x70000001 -#define DT_SPARC_NUM 2 - -/* MIPS R3000 specific definitions. */ - -/* Legal values for e_flags field of Elf32_Ehdr. */ - -#define EF_MIPS_NOREORDER 1 /* A .noreorder directive was used */ -#define EF_MIPS_PIC 2 /* Contains PIC code */ -#define EF_MIPS_CPIC 4 /* Uses PIC calling sequence */ -#define EF_MIPS_XGOT 8 -#define EF_MIPS_64BIT_WHIRL 16 -#define EF_MIPS_ABI2 32 -#define EF_MIPS_ABI_ON32 64 -#define EF_MIPS_ARCH 0xf0000000 /* MIPS architecture level */ - -/* Legal values for MIPS architecture level. */ - -#define EF_MIPS_ARCH_1 0x00000000 /* -mips1 code. */ -#define EF_MIPS_ARCH_2 0x10000000 /* -mips2 code. */ -#define EF_MIPS_ARCH_3 0x20000000 /* -mips3 code. */ -#define EF_MIPS_ARCH_4 0x30000000 /* -mips4 code. */ -#define EF_MIPS_ARCH_5 0x40000000 /* -mips5 code. */ -#define EF_MIPS_ARCH_32 0x60000000 /* MIPS32 code. */ -#define EF_MIPS_ARCH_64 0x70000000 /* MIPS64 code. */ - -/* The following are non-official names and should not be used. */ - -#define E_MIPS_ARCH_1 0x00000000 /* -mips1 code. */ -#define E_MIPS_ARCH_2 0x10000000 /* -mips2 code. */ -#define E_MIPS_ARCH_3 0x20000000 /* -mips3 code. */ -#define E_MIPS_ARCH_4 0x30000000 /* -mips4 code. */ -#define E_MIPS_ARCH_5 0x40000000 /* -mips5 code. */ -#define E_MIPS_ARCH_32 0x60000000 /* MIPS32 code. */ -#define E_MIPS_ARCH_64 0x70000000 /* MIPS64 code. */ - -/* Special section indices. */ - -#define SHN_MIPS_ACOMMON 0xff00 /* Allocated common symbols */ -#define SHN_MIPS_TEXT 0xff01 /* Allocated test symbols. */ -#define SHN_MIPS_DATA 0xff02 /* Allocated data symbols. */ -#define SHN_MIPS_SCOMMON 0xff03 /* Small common symbols */ -#define SHN_MIPS_SUNDEFINED 0xff04 /* Small undefined symbols */ - -/* Legal values for sh_type field of Elf32_Shdr. */ - -#define SHT_MIPS_LIBLIST 0x70000000 /* Shared objects used in link */ -#define SHT_MIPS_MSYM 0x70000001 -#define SHT_MIPS_CONFLICT 0x70000002 /* Conflicting symbols */ -#define SHT_MIPS_GPTAB 0x70000003 /* Global data area sizes */ -#define SHT_MIPS_UCODE 0x70000004 /* Reserved for SGI/MIPS compilers */ -#define SHT_MIPS_DEBUG 0x70000005 /* MIPS ECOFF debugging information*/ -#define SHT_MIPS_REGINFO 0x70000006 /* Register usage information */ -#define SHT_MIPS_PACKAGE 0x70000007 -#define SHT_MIPS_PACKSYM 0x70000008 -#define SHT_MIPS_RELD 0x70000009 -#define SHT_MIPS_IFACE 0x7000000b -#define SHT_MIPS_CONTENT 0x7000000c -#define SHT_MIPS_OPTIONS 0x7000000d /* Miscellaneous options. */ -#define SHT_MIPS_SHDR 0x70000010 -#define SHT_MIPS_FDESC 0x70000011 -#define SHT_MIPS_EXTSYM 0x70000012 -#define SHT_MIPS_DENSE 0x70000013 -#define SHT_MIPS_PDESC 0x70000014 -#define SHT_MIPS_LOCSYM 0x70000015 -#define SHT_MIPS_AUXSYM 0x70000016 -#define SHT_MIPS_OPTSYM 0x70000017 -#define SHT_MIPS_LOCSTR 0x70000018 -#define SHT_MIPS_LINE 0x70000019 -#define SHT_MIPS_RFDESC 0x7000001a -#define SHT_MIPS_DELTASYM 0x7000001b -#define SHT_MIPS_DELTAINST 0x7000001c -#define SHT_MIPS_DELTACLASS 0x7000001d -#define SHT_MIPS_DWARF 0x7000001e /* DWARF debugging information. */ -#define SHT_MIPS_DELTADECL 0x7000001f -#define SHT_MIPS_SYMBOL_LIB 0x70000020 -#define SHT_MIPS_EVENTS 0x70000021 /* Event section. */ -#define SHT_MIPS_TRANSLATE 0x70000022 -#define SHT_MIPS_PIXIE 0x70000023 -#define SHT_MIPS_XLATE 0x70000024 -#define SHT_MIPS_XLATE_DEBUG 0x70000025 -#define SHT_MIPS_WHIRL 0x70000026 -#define SHT_MIPS_EH_REGION 0x70000027 -#define SHT_MIPS_XLATE_OLD 0x70000028 -#define SHT_MIPS_PDR_EXCEPTION 0x70000029 - -/* Legal values for sh_flags field of Elf32_Shdr. */ - -#define SHF_MIPS_GPREL 0x10000000 /* Must be part of global data area */ -#define SHF_MIPS_MERGE 0x20000000 -#define SHF_MIPS_ADDR 0x40000000 -#define SHF_MIPS_STRINGS 0x80000000 -#define SHF_MIPS_NOSTRIP 0x08000000 -#define SHF_MIPS_LOCAL 0x04000000 -#define SHF_MIPS_NAMES 0x02000000 -#define SHF_MIPS_NODUPE 0x01000000 - - -/* Symbol tables. */ - -/* MIPS specific values for `st_other'. */ -#define STO_MIPS_DEFAULT 0x0 -#define STO_MIPS_INTERNAL 0x1 -#define STO_MIPS_HIDDEN 0x2 -#define STO_MIPS_PROTECTED 0x3 -#define STO_MIPS_PLT 0x8 -#define STO_MIPS_SC_ALIGN_UNUSED 0xff - -/* MIPS specific values for `st_info'. */ -#define STB_MIPS_SPLIT_COMMON 13 - -/* Entries found in sections of type SHT_MIPS_GPTAB. */ - -typedef union -{ - struct - { - Elf32_Word gt_current_g_value; /* -G value used for compilation */ - Elf32_Word gt_unused; /* Not used */ - } gt_header; /* First entry in section */ - struct - { - Elf32_Word gt_g_value; /* If this value were used for -G */ - Elf32_Word gt_bytes; /* This many bytes would be used */ - } gt_entry; /* Subsequent entries in section */ -} Elf32_gptab; - -/* Entry found in sections of type SHT_MIPS_REGINFO. */ - -typedef struct -{ - Elf32_Word ri_gprmask; /* General registers used */ - Elf32_Word ri_cprmask[4]; /* Coprocessor registers used */ - Elf32_Sword ri_gp_value; /* $gp register value */ -} Elf32_RegInfo; - -/* Entries found in sections of type SHT_MIPS_OPTIONS. */ - -typedef struct -{ - unsigned char kind; /* Determines interpretation of the - variable part of descriptor. */ - unsigned char size; /* Size of descriptor, including header. */ - Elf32_Section section; /* Section header index of section affected, - 0 for global options. */ - Elf32_Word info; /* Kind-specific information. */ -} Elf_Options; - -/* Values for `kind' field in Elf_Options. */ - -#define ODK_NULL 0 /* Undefined. */ -#define ODK_REGINFO 1 /* Register usage information. */ -#define ODK_EXCEPTIONS 2 /* Exception processing options. */ -#define ODK_PAD 3 /* Section padding options. */ -#define ODK_HWPATCH 4 /* Hardware workarounds performed */ -#define ODK_FILL 5 /* record the fill value used by the linker. */ -#define ODK_TAGS 6 /* reserve space for desktop tools to write. */ -#define ODK_HWAND 7 /* HW workarounds. 'AND' bits when merging. */ -#define ODK_HWOR 8 /* HW workarounds. 'OR' bits when merging. */ - -/* Values for `info' in Elf_Options for ODK_EXCEPTIONS entries. */ - -#define OEX_FPU_MIN 0x1f /* FPE's which MUST be enabled. */ -#define OEX_FPU_MAX 0x1f00 /* FPE's which MAY be enabled. */ -#define OEX_PAGE0 0x10000 /* page zero must be mapped. */ -#define OEX_SMM 0x20000 /* Force sequential memory mode? */ -#define OEX_FPDBUG 0x40000 /* Force floating point debug mode? */ -#define OEX_PRECISEFP OEX_FPDBUG -#define OEX_DISMISS 0x80000 /* Dismiss invalid address faults? */ - -#define OEX_FPU_INVAL 0x10 -#define OEX_FPU_DIV0 0x08 -#define OEX_FPU_OFLO 0x04 -#define OEX_FPU_UFLO 0x02 -#define OEX_FPU_INEX 0x01 - -/* Masks for `info' in Elf_Options for an ODK_HWPATCH entry. */ - -#define OHW_R4KEOP 0x1 /* R4000 end-of-page patch. */ -#define OHW_R8KPFETCH 0x2 /* may need R8000 prefetch patch. */ -#define OHW_R5KEOP 0x4 /* R5000 end-of-page patch. */ -#define OHW_R5KCVTL 0x8 /* R5000 cvt.[ds].l bug. clean=1. */ - -#define OPAD_PREFIX 0x1 -#define OPAD_POSTFIX 0x2 -#define OPAD_SYMBOL 0x4 - -/* Entry found in `.options' section. */ - -typedef struct -{ - Elf32_Word hwp_flags1; /* Extra flags. */ - Elf32_Word hwp_flags2; /* Extra flags. */ -} Elf_Options_Hw; - -/* Masks for `info' in ElfOptions for ODK_HWAND and ODK_HWOR entries. */ - -#define OHWA0_R4KEOP_CHECKED 0x00000001 -#define OHWA1_R4KEOP_CLEAN 0x00000002 - -/* MIPS relocs. */ - -#define R_MIPS_NONE 0 /* No reloc */ -#define R_MIPS_16 1 /* Direct 16 bit */ -#define R_MIPS_32 2 /* Direct 32 bit */ -#define R_MIPS_REL32 3 /* PC relative 32 bit */ -#define R_MIPS_26 4 /* Direct 26 bit shifted */ -#define R_MIPS_HI16 5 /* High 16 bit */ -#define R_MIPS_LO16 6 /* Low 16 bit */ -#define R_MIPS_GPREL16 7 /* GP relative 16 bit */ -#define R_MIPS_LITERAL 8 /* 16 bit literal entry */ -#define R_MIPS_GOT16 9 /* 16 bit GOT entry */ -#define R_MIPS_PC16 10 /* PC relative 16 bit */ -#define R_MIPS_CALL16 11 /* 16 bit GOT entry for function */ -#define R_MIPS_GPREL32 12 /* GP relative 32 bit */ - -#define R_MIPS_SHIFT5 16 -#define R_MIPS_SHIFT6 17 -#define R_MIPS_64 18 -#define R_MIPS_GOT_DISP 19 -#define R_MIPS_GOT_PAGE 20 -#define R_MIPS_GOT_OFST 21 -#define R_MIPS_GOT_HI16 22 -#define R_MIPS_GOT_LO16 23 -#define R_MIPS_SUB 24 -#define R_MIPS_INSERT_A 25 -#define R_MIPS_INSERT_B 26 -#define R_MIPS_DELETE 27 -#define R_MIPS_HIGHER 28 -#define R_MIPS_HIGHEST 29 -#define R_MIPS_CALL_HI16 30 -#define R_MIPS_CALL_LO16 31 -#define R_MIPS_SCN_DISP 32 -#define R_MIPS_REL16 33 -#define R_MIPS_ADD_IMMEDIATE 34 -#define R_MIPS_PJUMP 35 -#define R_MIPS_RELGOT 36 -#define R_MIPS_JALR 37 -#define R_MIPS_TLS_DTPMOD32 38 /* Module number 32 bit */ -#define R_MIPS_TLS_DTPREL32 39 /* Module-relative offset 32 bit */ -#define R_MIPS_TLS_DTPMOD64 40 /* Module number 64 bit */ -#define R_MIPS_TLS_DTPREL64 41 /* Module-relative offset 64 bit */ -#define R_MIPS_TLS_GD 42 /* 16 bit GOT offset for GD */ -#define R_MIPS_TLS_LDM 43 /* 16 bit GOT offset for LDM */ -#define R_MIPS_TLS_DTPREL_HI16 44 /* Module-relative offset, high 16 bits */ -#define R_MIPS_TLS_DTPREL_LO16 45 /* Module-relative offset, low 16 bits */ -#define R_MIPS_TLS_GOTTPREL 46 /* 16 bit GOT offset for IE */ -#define R_MIPS_TLS_TPREL32 47 /* TP-relative offset, 32 bit */ -#define R_MIPS_TLS_TPREL64 48 /* TP-relative offset, 64 bit */ -#define R_MIPS_TLS_TPREL_HI16 49 /* TP-relative offset, high 16 bits */ -#define R_MIPS_TLS_TPREL_LO16 50 /* TP-relative offset, low 16 bits */ -#define R_MIPS_GLOB_DAT 51 -#define R_MIPS_COPY 126 -#define R_MIPS_JUMP_SLOT 127 -/* Keep this the last entry. */ -#define R_MIPS_NUM 128 - -/* Legal values for p_type field of Elf32_Phdr. */ - -#define PT_MIPS_REGINFO 0x70000000 /* Register usage information */ -#define PT_MIPS_RTPROC 0x70000001 /* Runtime procedure table. */ -#define PT_MIPS_OPTIONS 0x70000002 - -/* Special program header types. */ - -#define PF_MIPS_LOCAL 0x10000000 - -/* Legal values for d_tag field of Elf32_Dyn. */ - -#define DT_MIPS_RLD_VERSION 0x70000001 /* Runtime linker interface version */ -#define DT_MIPS_TIME_STAMP 0x70000002 /* Timestamp */ -#define DT_MIPS_ICHECKSUM 0x70000003 /* Checksum */ -#define DT_MIPS_IVERSION 0x70000004 /* Version string (string tbl index) */ -#define DT_MIPS_FLAGS 0x70000005 /* Flags */ -#define DT_MIPS_BASE_ADDRESS 0x70000006 /* Base address */ -#define DT_MIPS_MSYM 0x70000007 -#define DT_MIPS_CONFLICT 0x70000008 /* Address of CONFLICT section */ -#define DT_MIPS_LIBLIST 0x70000009 /* Address of LIBLIST section */ -#define DT_MIPS_LOCAL_GOTNO 0x7000000a /* Number of local GOT entries */ -#define DT_MIPS_CONFLICTNO 0x7000000b /* Number of CONFLICT entries */ -#define DT_MIPS_LIBLISTNO 0x70000010 /* Number of LIBLIST entries */ -#define DT_MIPS_SYMTABNO 0x70000011 /* Number of DYNSYM entries */ -#define DT_MIPS_UNREFEXTNO 0x70000012 /* First external DYNSYM */ -#define DT_MIPS_GOTSYM 0x70000013 /* First GOT entry in DYNSYM */ -#define DT_MIPS_HIPAGENO 0x70000014 /* Number of GOT page table entries */ -#define DT_MIPS_RLD_MAP 0x70000016 /* Address of run time loader map. */ -#define DT_MIPS_DELTA_CLASS 0x70000017 /* Delta C++ class definition. */ -#define DT_MIPS_DELTA_CLASS_NO 0x70000018 /* Number of entries in - DT_MIPS_DELTA_CLASS. */ -#define DT_MIPS_DELTA_INSTANCE 0x70000019 /* Delta C++ class instances. */ -#define DT_MIPS_DELTA_INSTANCE_NO 0x7000001a /* Number of entries in - DT_MIPS_DELTA_INSTANCE. */ -#define DT_MIPS_DELTA_RELOC 0x7000001b /* Delta relocations. */ -#define DT_MIPS_DELTA_RELOC_NO 0x7000001c /* Number of entries in - DT_MIPS_DELTA_RELOC. */ -#define DT_MIPS_DELTA_SYM 0x7000001d /* Delta symbols that Delta - relocations refer to. */ -#define DT_MIPS_DELTA_SYM_NO 0x7000001e /* Number of entries in - DT_MIPS_DELTA_SYM. */ -#define DT_MIPS_DELTA_CLASSSYM 0x70000020 /* Delta symbols that hold the - class declaration. */ -#define DT_MIPS_DELTA_CLASSSYM_NO 0x70000021 /* Number of entries in - DT_MIPS_DELTA_CLASSSYM. */ -#define DT_MIPS_CXX_FLAGS 0x70000022 /* Flags indicating for C++ flavor. */ -#define DT_MIPS_PIXIE_INIT 0x70000023 -#define DT_MIPS_SYMBOL_LIB 0x70000024 -#define DT_MIPS_LOCALPAGE_GOTIDX 0x70000025 -#define DT_MIPS_LOCAL_GOTIDX 0x70000026 -#define DT_MIPS_HIDDEN_GOTIDX 0x70000027 -#define DT_MIPS_PROTECTED_GOTIDX 0x70000028 -#define DT_MIPS_OPTIONS 0x70000029 /* Address of .options. */ -#define DT_MIPS_INTERFACE 0x7000002a /* Address of .interface. */ -#define DT_MIPS_DYNSTR_ALIGN 0x7000002b -#define DT_MIPS_INTERFACE_SIZE 0x7000002c /* Size of the .interface section. */ -#define DT_MIPS_RLD_TEXT_RESOLVE_ADDR 0x7000002d /* Address of rld_text_rsolve - function stored in GOT. */ -#define DT_MIPS_PERF_SUFFIX 0x7000002e /* Default suffix of dso to be added - by rld on dlopen() calls. */ -#define DT_MIPS_COMPACT_SIZE 0x7000002f /* (O32)Size of compact rel section. */ -#define DT_MIPS_GP_VALUE 0x70000030 /* GP value for aux GOTs. */ -#define DT_MIPS_AUX_DYNAMIC 0x70000031 /* Address of aux .dynamic. */ -/* The address of .got.plt in an executable using the new non-PIC ABI. */ -#define DT_MIPS_PLTGOT 0x70000032 -/* The base of the PLT in an executable using the new non-PIC ABI if that - PLT is writable. For a non-writable PLT, this is omitted or has a zero - value. */ -#define DT_MIPS_RWPLT 0x70000034 -#define DT_MIPS_NUM 0x35 - -/* Legal values for DT_MIPS_FLAGS Elf32_Dyn entry. */ - -#define RHF_NONE 0 /* No flags */ -#define RHF_QUICKSTART (1 << 0) /* Use quickstart */ -#define RHF_NOTPOT (1 << 1) /* Hash size not power of 2 */ -#define RHF_NO_LIBRARY_REPLACEMENT (1 << 2) /* Ignore LD_LIBRARY_PATH */ -#define RHF_NO_MOVE (1 << 3) -#define RHF_SGI_ONLY (1 << 4) -#define RHF_GUARANTEE_INIT (1 << 5) -#define RHF_DELTA_C_PLUS_PLUS (1 << 6) -#define RHF_GUARANTEE_START_INIT (1 << 7) -#define RHF_PIXIE (1 << 8) -#define RHF_DEFAULT_DELAY_LOAD (1 << 9) -#define RHF_REQUICKSTART (1 << 10) -#define RHF_REQUICKSTARTED (1 << 11) -#define RHF_CORD (1 << 12) -#define RHF_NO_UNRES_UNDEF (1 << 13) -#define RHF_RLD_ORDER_SAFE (1 << 14) - -/* Entries found in sections of type SHT_MIPS_LIBLIST. */ - -typedef struct -{ - Elf32_Word l_name; /* Name (string table index) */ - Elf32_Word l_time_stamp; /* Timestamp */ - Elf32_Word l_checksum; /* Checksum */ - Elf32_Word l_version; /* Interface version */ - Elf32_Word l_flags; /* Flags */ -} Elf32_Lib; - -typedef struct -{ - Elf64_Word l_name; /* Name (string table index) */ - Elf64_Word l_time_stamp; /* Timestamp */ - Elf64_Word l_checksum; /* Checksum */ - Elf64_Word l_version; /* Interface version */ - Elf64_Word l_flags; /* Flags */ -} Elf64_Lib; - - -/* Legal values for l_flags. */ - -#define LL_NONE 0 -#define LL_EXACT_MATCH (1 << 0) /* Require exact match */ -#define LL_IGNORE_INT_VER (1 << 1) /* Ignore interface version */ -#define LL_REQUIRE_MINOR (1 << 2) -#define LL_EXPORTS (1 << 3) -#define LL_DELAY_LOAD (1 << 4) -#define LL_DELTA (1 << 5) - -/* Entries found in sections of type SHT_MIPS_CONFLICT. */ - -typedef Elf32_Addr Elf32_Conflict; - - -/* HPPA specific definitions. */ - -/* Legal values for e_flags field of Elf32_Ehdr. */ - -#define EF_PARISC_TRAPNIL 0x00010000 /* Trap nil pointer dereference. */ -#define EF_PARISC_EXT 0x00020000 /* Program uses arch. extensions. */ -#define EF_PARISC_LSB 0x00040000 /* Program expects little endian. */ -#define EF_PARISC_WIDE 0x00080000 /* Program expects wide mode. */ -#define EF_PARISC_NO_KABP 0x00100000 /* No kernel assisted branch - prediction. */ -#define EF_PARISC_LAZYSWAP 0x00400000 /* Allow lazy swapping. */ -#define EF_PARISC_ARCH 0x0000ffff /* Architecture version. */ - -/* Defined values for `e_flags & EF_PARISC_ARCH' are: */ - -#define EFA_PARISC_1_0 0x020b /* PA-RISC 1.0 big-endian. */ -#define EFA_PARISC_1_1 0x0210 /* PA-RISC 1.1 big-endian. */ -#define EFA_PARISC_2_0 0x0214 /* PA-RISC 2.0 big-endian. */ - -/* Additional section indices. */ - -#define SHN_PARISC_ANSI_COMMON 0xff00 /* Section for tentatively declared - symbols in ANSI C. */ -#define SHN_PARISC_HUGE_COMMON 0xff01 /* Common blocks in huge model. */ - -/* Legal values for sh_type field of Elf32_Shdr. */ - -#define SHT_PARISC_EXT 0x70000000 /* Contains product specific ext. */ -#define SHT_PARISC_UNWIND 0x70000001 /* Unwind information. */ -#define SHT_PARISC_DOC 0x70000002 /* Debug info for optimized code. */ - -/* Legal values for sh_flags field of Elf32_Shdr. */ - -#define SHF_PARISC_SHORT 0x20000000 /* Section with short addressing. */ -#define SHF_PARISC_HUGE 0x40000000 /* Section far from gp. */ -#define SHF_PARISC_SBP 0x80000000 /* Static branch prediction code. */ - -/* Legal values for ST_TYPE subfield of st_info (symbol type). */ - -#define STT_PARISC_MILLICODE 13 /* Millicode function entry point. */ - -#define STT_HP_OPAQUE (STT_LOOS + 0x1) -#define STT_HP_STUB (STT_LOOS + 0x2) - -/* HPPA relocs. */ - -#define R_PARISC_NONE 0 /* No reloc. */ -#define R_PARISC_DIR32 1 /* Direct 32-bit reference. */ -#define R_PARISC_DIR21L 2 /* Left 21 bits of eff. address. */ -#define R_PARISC_DIR17R 3 /* Right 17 bits of eff. address. */ -#define R_PARISC_DIR17F 4 /* 17 bits of eff. address. */ -#define R_PARISC_DIR14R 6 /* Right 14 bits of eff. address. */ -#define R_PARISC_PCREL32 9 /* 32-bit rel. address. */ -#define R_PARISC_PCREL21L 10 /* Left 21 bits of rel. address. */ -#define R_PARISC_PCREL17R 11 /* Right 17 bits of rel. address. */ -#define R_PARISC_PCREL17F 12 /* 17 bits of rel. address. */ -#define R_PARISC_PCREL14R 14 /* Right 14 bits of rel. address. */ -#define R_PARISC_DPREL21L 18 /* Left 21 bits of rel. address. */ -#define R_PARISC_DPREL14R 22 /* Right 14 bits of rel. address. */ -#define R_PARISC_GPREL21L 26 /* GP-relative, left 21 bits. */ -#define R_PARISC_GPREL14R 30 /* GP-relative, right 14 bits. */ -#define R_PARISC_LTOFF21L 34 /* LT-relative, left 21 bits. */ -#define R_PARISC_LTOFF14R 38 /* LT-relative, right 14 bits. */ -#define R_PARISC_SECREL32 41 /* 32 bits section rel. address. */ -#define R_PARISC_SEGBASE 48 /* No relocation, set segment base. */ -#define R_PARISC_SEGREL32 49 /* 32 bits segment rel. address. */ -#define R_PARISC_PLTOFF21L 50 /* PLT rel. address, left 21 bits. */ -#define R_PARISC_PLTOFF14R 54 /* PLT rel. address, right 14 bits. */ -#define R_PARISC_LTOFF_FPTR32 57 /* 32 bits LT-rel. function pointer. */ -#define R_PARISC_LTOFF_FPTR21L 58 /* LT-rel. fct ptr, left 21 bits. */ -#define R_PARISC_LTOFF_FPTR14R 62 /* LT-rel. fct ptr, right 14 bits. */ -#define R_PARISC_FPTR64 64 /* 64 bits function address. */ -#define R_PARISC_PLABEL32 65 /* 32 bits function address. */ -#define R_PARISC_PLABEL21L 66 /* Left 21 bits of fdesc address. */ -#define R_PARISC_PLABEL14R 70 /* Right 14 bits of fdesc address. */ -#define R_PARISC_PCREL64 72 /* 64 bits PC-rel. address. */ -#define R_PARISC_PCREL22F 74 /* 22 bits PC-rel. address. */ -#define R_PARISC_PCREL14WR 75 /* PC-rel. address, right 14 bits. */ -#define R_PARISC_PCREL14DR 76 /* PC rel. address, right 14 bits. */ -#define R_PARISC_PCREL16F 77 /* 16 bits PC-rel. address. */ -#define R_PARISC_PCREL16WF 78 /* 16 bits PC-rel. address. */ -#define R_PARISC_PCREL16DF 79 /* 16 bits PC-rel. address. */ -#define R_PARISC_DIR64 80 /* 64 bits of eff. address. */ -#define R_PARISC_DIR14WR 83 /* 14 bits of eff. address. */ -#define R_PARISC_DIR14DR 84 /* 14 bits of eff. address. */ -#define R_PARISC_DIR16F 85 /* 16 bits of eff. address. */ -#define R_PARISC_DIR16WF 86 /* 16 bits of eff. address. */ -#define R_PARISC_DIR16DF 87 /* 16 bits of eff. address. */ -#define R_PARISC_GPREL64 88 /* 64 bits of GP-rel. address. */ -#define R_PARISC_GPREL14WR 91 /* GP-rel. address, right 14 bits. */ -#define R_PARISC_GPREL14DR 92 /* GP-rel. address, right 14 bits. */ -#define R_PARISC_GPREL16F 93 /* 16 bits GP-rel. address. */ -#define R_PARISC_GPREL16WF 94 /* 16 bits GP-rel. address. */ -#define R_PARISC_GPREL16DF 95 /* 16 bits GP-rel. address. */ -#define R_PARISC_LTOFF64 96 /* 64 bits LT-rel. address. */ -#define R_PARISC_LTOFF14WR 99 /* LT-rel. address, right 14 bits. */ -#define R_PARISC_LTOFF14DR 100 /* LT-rel. address, right 14 bits. */ -#define R_PARISC_LTOFF16F 101 /* 16 bits LT-rel. address. */ -#define R_PARISC_LTOFF16WF 102 /* 16 bits LT-rel. address. */ -#define R_PARISC_LTOFF16DF 103 /* 16 bits LT-rel. address. */ -#define R_PARISC_SECREL64 104 /* 64 bits section rel. address. */ -#define R_PARISC_SEGREL64 112 /* 64 bits segment rel. address. */ -#define R_PARISC_PLTOFF14WR 115 /* PLT-rel. address, right 14 bits. */ -#define R_PARISC_PLTOFF14DR 116 /* PLT-rel. address, right 14 bits. */ -#define R_PARISC_PLTOFF16F 117 /* 16 bits LT-rel. address. */ -#define R_PARISC_PLTOFF16WF 118 /* 16 bits PLT-rel. address. */ -#define R_PARISC_PLTOFF16DF 119 /* 16 bits PLT-rel. address. */ -#define R_PARISC_LTOFF_FPTR64 120 /* 64 bits LT-rel. function ptr. */ -#define R_PARISC_LTOFF_FPTR14WR 123 /* LT-rel. fct. ptr., right 14 bits. */ -#define R_PARISC_LTOFF_FPTR14DR 124 /* LT-rel. fct. ptr., right 14 bits. */ -#define R_PARISC_LTOFF_FPTR16F 125 /* 16 bits LT-rel. function ptr. */ -#define R_PARISC_LTOFF_FPTR16WF 126 /* 16 bits LT-rel. function ptr. */ -#define R_PARISC_LTOFF_FPTR16DF 127 /* 16 bits LT-rel. function ptr. */ -#define R_PARISC_LORESERVE 128 -#define R_PARISC_COPY 128 /* Copy relocation. */ -#define R_PARISC_IPLT 129 /* Dynamic reloc, imported PLT */ -#define R_PARISC_EPLT 130 /* Dynamic reloc, exported PLT */ -#define R_PARISC_TPREL32 153 /* 32 bits TP-rel. address. */ -#define R_PARISC_TPREL21L 154 /* TP-rel. address, left 21 bits. */ -#define R_PARISC_TPREL14R 158 /* TP-rel. address, right 14 bits. */ -#define R_PARISC_LTOFF_TP21L 162 /* LT-TP-rel. address, left 21 bits. */ -#define R_PARISC_LTOFF_TP14R 166 /* LT-TP-rel. address, right 14 bits.*/ -#define R_PARISC_LTOFF_TP14F 167 /* 14 bits LT-TP-rel. address. */ -#define R_PARISC_TPREL64 216 /* 64 bits TP-rel. address. */ -#define R_PARISC_TPREL14WR 219 /* TP-rel. address, right 14 bits. */ -#define R_PARISC_TPREL14DR 220 /* TP-rel. address, right 14 bits. */ -#define R_PARISC_TPREL16F 221 /* 16 bits TP-rel. address. */ -#define R_PARISC_TPREL16WF 222 /* 16 bits TP-rel. address. */ -#define R_PARISC_TPREL16DF 223 /* 16 bits TP-rel. address. */ -#define R_PARISC_LTOFF_TP64 224 /* 64 bits LT-TP-rel. address. */ -#define R_PARISC_LTOFF_TP14WR 227 /* LT-TP-rel. address, right 14 bits.*/ -#define R_PARISC_LTOFF_TP14DR 228 /* LT-TP-rel. address, right 14 bits.*/ -#define R_PARISC_LTOFF_TP16F 229 /* 16 bits LT-TP-rel. address. */ -#define R_PARISC_LTOFF_TP16WF 230 /* 16 bits LT-TP-rel. address. */ -#define R_PARISC_LTOFF_TP16DF 231 /* 16 bits LT-TP-rel. address. */ -#define R_PARISC_GNU_VTENTRY 232 -#define R_PARISC_GNU_VTINHERIT 233 -#define R_PARISC_TLS_GD21L 234 /* GD 21-bit left. */ -#define R_PARISC_TLS_GD14R 235 /* GD 14-bit right. */ -#define R_PARISC_TLS_GDCALL 236 /* GD call to __t_g_a. */ -#define R_PARISC_TLS_LDM21L 237 /* LD module 21-bit left. */ -#define R_PARISC_TLS_LDM14R 238 /* LD module 14-bit right. */ -#define R_PARISC_TLS_LDMCALL 239 /* LD module call to __t_g_a. */ -#define R_PARISC_TLS_LDO21L 240 /* LD offset 21-bit left. */ -#define R_PARISC_TLS_LDO14R 241 /* LD offset 14-bit right. */ -#define R_PARISC_TLS_DTPMOD32 242 /* DTP module 32-bit. */ -#define R_PARISC_TLS_DTPMOD64 243 /* DTP module 64-bit. */ -#define R_PARISC_TLS_DTPOFF32 244 /* DTP offset 32-bit. */ -#define R_PARISC_TLS_DTPOFF64 245 /* DTP offset 32-bit. */ -#define R_PARISC_TLS_LE21L R_PARISC_TPREL21L -#define R_PARISC_TLS_LE14R R_PARISC_TPREL14R -#define R_PARISC_TLS_IE21L R_PARISC_LTOFF_TP21L -#define R_PARISC_TLS_IE14R R_PARISC_LTOFF_TP14R -#define R_PARISC_TLS_TPREL32 R_PARISC_TPREL32 -#define R_PARISC_TLS_TPREL64 R_PARISC_TPREL64 -#define R_PARISC_HIRESERVE 255 - -/* Legal values for p_type field of Elf32_Phdr/Elf64_Phdr. */ - -#define PT_HP_TLS (PT_LOOS + 0x0) -#define PT_HP_CORE_NONE (PT_LOOS + 0x1) -#define PT_HP_CORE_VERSION (PT_LOOS + 0x2) -#define PT_HP_CORE_KERNEL (PT_LOOS + 0x3) -#define PT_HP_CORE_COMM (PT_LOOS + 0x4) -#define PT_HP_CORE_PROC (PT_LOOS + 0x5) -#define PT_HP_CORE_LOADABLE (PT_LOOS + 0x6) -#define PT_HP_CORE_STACK (PT_LOOS + 0x7) -#define PT_HP_CORE_SHM (PT_LOOS + 0x8) -#define PT_HP_CORE_MMF (PT_LOOS + 0x9) -#define PT_HP_PARALLEL (PT_LOOS + 0x10) -#define PT_HP_FASTBIND (PT_LOOS + 0x11) -#define PT_HP_OPT_ANNOT (PT_LOOS + 0x12) -#define PT_HP_HSL_ANNOT (PT_LOOS + 0x13) -#define PT_HP_STACK (PT_LOOS + 0x14) - -#define PT_PARISC_ARCHEXT 0x70000000 -#define PT_PARISC_UNWIND 0x70000001 - -/* Legal values for p_flags field of Elf32_Phdr/Elf64_Phdr. */ - -#define PF_PARISC_SBP 0x08000000 - -#define PF_HP_PAGE_SIZE 0x00100000 -#define PF_HP_FAR_SHARED 0x00200000 -#define PF_HP_NEAR_SHARED 0x00400000 -#define PF_HP_CODE 0x01000000 -#define PF_HP_MODIFY 0x02000000 -#define PF_HP_LAZYSWAP 0x04000000 -#define PF_HP_SBP 0x08000000 - - -/* Alpha specific definitions. */ - -/* Legal values for e_flags field of Elf64_Ehdr. */ - -#define EF_ALPHA_32BIT 1 /* All addresses must be < 2GB. */ -#define EF_ALPHA_CANRELAX 2 /* Relocations for relaxing exist. */ - -/* Legal values for sh_type field of Elf64_Shdr. */ - -/* These two are primarily concerned with ECOFF debugging info. */ -#define SHT_ALPHA_DEBUG 0x70000001 -#define SHT_ALPHA_REGINFO 0x70000002 - -/* Legal values for sh_flags field of Elf64_Shdr. */ - -#define SHF_ALPHA_GPREL 0x10000000 - -/* Legal values for st_other field of Elf64_Sym. */ -#define STO_ALPHA_NOPV 0x80 /* No PV required. */ -#define STO_ALPHA_STD_GPLOAD 0x88 /* PV only used for initial ldgp. */ - -/* Alpha relocs. */ - -#define R_ALPHA_NONE 0 /* No reloc */ -#define R_ALPHA_REFLONG 1 /* Direct 32 bit */ -#define R_ALPHA_REFQUAD 2 /* Direct 64 bit */ -#define R_ALPHA_GPREL32 3 /* GP relative 32 bit */ -#define R_ALPHA_LITERAL 4 /* GP relative 16 bit w/optimization */ -#define R_ALPHA_LITUSE 5 /* Optimization hint for LITERAL */ -#define R_ALPHA_GPDISP 6 /* Add displacement to GP */ -#define R_ALPHA_BRADDR 7 /* PC+4 relative 23 bit shifted */ -#define R_ALPHA_HINT 8 /* PC+4 relative 16 bit shifted */ -#define R_ALPHA_SREL16 9 /* PC relative 16 bit */ -#define R_ALPHA_SREL32 10 /* PC relative 32 bit */ -#define R_ALPHA_SREL64 11 /* PC relative 64 bit */ -#define R_ALPHA_GPRELHIGH 17 /* GP relative 32 bit, high 16 bits */ -#define R_ALPHA_GPRELLOW 18 /* GP relative 32 bit, low 16 bits */ -#define R_ALPHA_GPREL16 19 /* GP relative 16 bit */ -#define R_ALPHA_COPY 24 /* Copy symbol at runtime */ -#define R_ALPHA_GLOB_DAT 25 /* Create GOT entry */ -#define R_ALPHA_JMP_SLOT 26 /* Create PLT entry */ -#define R_ALPHA_RELATIVE 27 /* Adjust by program base */ -#define R_ALPHA_TLS_GD_HI 28 -#define R_ALPHA_TLSGD 29 -#define R_ALPHA_TLS_LDM 30 -#define R_ALPHA_DTPMOD64 31 -#define R_ALPHA_GOTDTPREL 32 -#define R_ALPHA_DTPREL64 33 -#define R_ALPHA_DTPRELHI 34 -#define R_ALPHA_DTPRELLO 35 -#define R_ALPHA_DTPREL16 36 -#define R_ALPHA_GOTTPREL 37 -#define R_ALPHA_TPREL64 38 -#define R_ALPHA_TPRELHI 39 -#define R_ALPHA_TPRELLO 40 -#define R_ALPHA_TPREL16 41 -/* Keep this the last entry. */ -#define R_ALPHA_NUM 46 - -/* Magic values of the LITUSE relocation addend. */ -#define LITUSE_ALPHA_ADDR 0 -#define LITUSE_ALPHA_BASE 1 -#define LITUSE_ALPHA_BYTOFF 2 -#define LITUSE_ALPHA_JSR 3 -#define LITUSE_ALPHA_TLS_GD 4 -#define LITUSE_ALPHA_TLS_LDM 5 - -/* Legal values for d_tag of Elf64_Dyn. */ -#define DT_ALPHA_PLTRO (DT_LOPROC + 0) -#define DT_ALPHA_NUM 1 - -/* PowerPC specific declarations */ - -/* Values for Elf32/64_Ehdr.e_flags. */ -#define EF_PPC_EMB 0x80000000 /* PowerPC embedded flag */ - -/* Cygnus local bits below */ -#define EF_PPC_RELOCATABLE 0x00010000 /* PowerPC -mrelocatable flag*/ -#define EF_PPC_RELOCATABLE_LIB 0x00008000 /* PowerPC -mrelocatable-lib - flag */ - -/* PowerPC relocations defined by the ABIs */ -#define R_PPC_NONE 0 -#define R_PPC_ADDR32 1 /* 32bit absolute address */ -#define R_PPC_ADDR24 2 /* 26bit address, 2 bits ignored. */ -#define R_PPC_ADDR16 3 /* 16bit absolute address */ -#define R_PPC_ADDR16_LO 4 /* lower 16bit of absolute address */ -#define R_PPC_ADDR16_HI 5 /* high 16bit of absolute address */ -#define R_PPC_ADDR16_HA 6 /* adjusted high 16bit */ -#define R_PPC_ADDR14 7 /* 16bit address, 2 bits ignored */ -#define R_PPC_ADDR14_BRTAKEN 8 -#define R_PPC_ADDR14_BRNTAKEN 9 -#define R_PPC_REL24 10 /* PC relative 26 bit */ -#define R_PPC_REL14 11 /* PC relative 16 bit */ -#define R_PPC_REL14_BRTAKEN 12 -#define R_PPC_REL14_BRNTAKEN 13 -#define R_PPC_GOT16 14 -#define R_PPC_GOT16_LO 15 -#define R_PPC_GOT16_HI 16 -#define R_PPC_GOT16_HA 17 -#define R_PPC_PLTREL24 18 -#define R_PPC_COPY 19 -#define R_PPC_GLOB_DAT 20 -#define R_PPC_JMP_SLOT 21 -#define R_PPC_RELATIVE 22 -#define R_PPC_LOCAL24PC 23 -#define R_PPC_UADDR32 24 -#define R_PPC_UADDR16 25 -#define R_PPC_REL32 26 -#define R_PPC_PLT32 27 -#define R_PPC_PLTREL32 28 -#define R_PPC_PLT16_LO 29 -#define R_PPC_PLT16_HI 30 -#define R_PPC_PLT16_HA 31 -#define R_PPC_SDAREL16 32 -#define R_PPC_SECTOFF 33 -#define R_PPC_SECTOFF_LO 34 -#define R_PPC_SECTOFF_HI 35 -#define R_PPC_SECTOFF_HA 36 - -/* PowerPC relocations defined for the TLS access ABI. */ -#define R_PPC_TLS 67 /* none (sym+add)@tls */ -#define R_PPC_DTPMOD32 68 /* word32 (sym+add)@dtpmod */ -#define R_PPC_TPREL16 69 /* half16* (sym+add)@tprel */ -#define R_PPC_TPREL16_LO 70 /* half16 (sym+add)@tprel@l */ -#define R_PPC_TPREL16_HI 71 /* half16 (sym+add)@tprel@h */ -#define R_PPC_TPREL16_HA 72 /* half16 (sym+add)@tprel@ha */ -#define R_PPC_TPREL32 73 /* word32 (sym+add)@tprel */ -#define R_PPC_DTPREL16 74 /* half16* (sym+add)@dtprel */ -#define R_PPC_DTPREL16_LO 75 /* half16 (sym+add)@dtprel@l */ -#define R_PPC_DTPREL16_HI 76 /* half16 (sym+add)@dtprel@h */ -#define R_PPC_DTPREL16_HA 77 /* half16 (sym+add)@dtprel@ha */ -#define R_PPC_DTPREL32 78 /* word32 (sym+add)@dtprel */ -#define R_PPC_GOT_TLSGD16 79 /* half16* (sym+add)@got@tlsgd */ -#define R_PPC_GOT_TLSGD16_LO 80 /* half16 (sym+add)@got@tlsgd@l */ -#define R_PPC_GOT_TLSGD16_HI 81 /* half16 (sym+add)@got@tlsgd@h */ -#define R_PPC_GOT_TLSGD16_HA 82 /* half16 (sym+add)@got@tlsgd@ha */ -#define R_PPC_GOT_TLSLD16 83 /* half16* (sym+add)@got@tlsld */ -#define R_PPC_GOT_TLSLD16_LO 84 /* half16 (sym+add)@got@tlsld@l */ -#define R_PPC_GOT_TLSLD16_HI 85 /* half16 (sym+add)@got@tlsld@h */ -#define R_PPC_GOT_TLSLD16_HA 86 /* half16 (sym+add)@got@tlsld@ha */ -#define R_PPC_GOT_TPREL16 87 /* half16* (sym+add)@got@tprel */ -#define R_PPC_GOT_TPREL16_LO 88 /* half16 (sym+add)@got@tprel@l */ -#define R_PPC_GOT_TPREL16_HI 89 /* half16 (sym+add)@got@tprel@h */ -#define R_PPC_GOT_TPREL16_HA 90 /* half16 (sym+add)@got@tprel@ha */ -#define R_PPC_GOT_DTPREL16 91 /* half16* (sym+add)@got@dtprel */ -#define R_PPC_GOT_DTPREL16_LO 92 /* half16* (sym+add)@got@dtprel@l */ -#define R_PPC_GOT_DTPREL16_HI 93 /* half16* (sym+add)@got@dtprel@h */ -#define R_PPC_GOT_DTPREL16_HA 94 /* half16* (sym+add)@got@dtprel@ha */ - -/* The remaining relocs are from the Embedded ELF ABI, and are not - in the SVR4 ELF ABI. */ -#define R_PPC_EMB_NADDR32 101 -#define R_PPC_EMB_NADDR16 102 -#define R_PPC_EMB_NADDR16_LO 103 -#define R_PPC_EMB_NADDR16_HI 104 -#define R_PPC_EMB_NADDR16_HA 105 -#define R_PPC_EMB_SDAI16 106 -#define R_PPC_EMB_SDA2I16 107 -#define R_PPC_EMB_SDA2REL 108 -#define R_PPC_EMB_SDA21 109 /* 16 bit offset in SDA */ -#define R_PPC_EMB_MRKREF 110 -#define R_PPC_EMB_RELSEC16 111 -#define R_PPC_EMB_RELST_LO 112 -#define R_PPC_EMB_RELST_HI 113 -#define R_PPC_EMB_RELST_HA 114 -#define R_PPC_EMB_BIT_FLD 115 -#define R_PPC_EMB_RELSDA 116 /* 16 bit relative offset in SDA */ - -/* Diab tool relocations. */ -#define R_PPC_DIAB_SDA21_LO 180 /* like EMB_SDA21, but lower 16 bit */ -#define R_PPC_DIAB_SDA21_HI 181 /* like EMB_SDA21, but high 16 bit */ -#define R_PPC_DIAB_SDA21_HA 182 /* like EMB_SDA21, adjusted high 16 */ -#define R_PPC_DIAB_RELSDA_LO 183 /* like EMB_RELSDA, but lower 16 bit */ -#define R_PPC_DIAB_RELSDA_HI 184 /* like EMB_RELSDA, but high 16 bit */ -#define R_PPC_DIAB_RELSDA_HA 185 /* like EMB_RELSDA, adjusted high 16 */ - -/* GNU extension to support local ifunc. */ -#define R_PPC_IRELATIVE 248 - -/* GNU relocs used in PIC code sequences. */ -#define R_PPC_REL16 249 /* half16 (sym+add-.) */ -#define R_PPC_REL16_LO 250 /* half16 (sym+add-.)@l */ -#define R_PPC_REL16_HI 251 /* half16 (sym+add-.)@h */ -#define R_PPC_REL16_HA 252 /* half16 (sym+add-.)@ha */ - -/* This is a phony reloc to handle any old fashioned TOC16 references - that may still be in object files. */ -#define R_PPC_TOC16 255 - -/* PowerPC specific values for the Dyn d_tag field. */ -#define DT_PPC_GOT (DT_LOPROC + 0) -#define DT_PPC_NUM 1 - -/* PowerPC64 relocations defined by the ABIs */ -#define R_PPC64_NONE R_PPC_NONE -#define R_PPC64_ADDR32 R_PPC_ADDR32 /* 32bit absolute address */ -#define R_PPC64_ADDR24 R_PPC_ADDR24 /* 26bit address, word aligned */ -#define R_PPC64_ADDR16 R_PPC_ADDR16 /* 16bit absolute address */ -#define R_PPC64_ADDR16_LO R_PPC_ADDR16_LO /* lower 16bits of address */ -#define R_PPC64_ADDR16_HI R_PPC_ADDR16_HI /* high 16bits of address. */ -#define R_PPC64_ADDR16_HA R_PPC_ADDR16_HA /* adjusted high 16bits. */ -#define R_PPC64_ADDR14 R_PPC_ADDR14 /* 16bit address, word aligned */ -#define R_PPC64_ADDR14_BRTAKEN R_PPC_ADDR14_BRTAKEN -#define R_PPC64_ADDR14_BRNTAKEN R_PPC_ADDR14_BRNTAKEN -#define R_PPC64_REL24 R_PPC_REL24 /* PC-rel. 26 bit, word aligned */ -#define R_PPC64_REL14 R_PPC_REL14 /* PC relative 16 bit */ -#define R_PPC64_REL14_BRTAKEN R_PPC_REL14_BRTAKEN -#define R_PPC64_REL14_BRNTAKEN R_PPC_REL14_BRNTAKEN -#define R_PPC64_GOT16 R_PPC_GOT16 -#define R_PPC64_GOT16_LO R_PPC_GOT16_LO -#define R_PPC64_GOT16_HI R_PPC_GOT16_HI -#define R_PPC64_GOT16_HA R_PPC_GOT16_HA - -#define R_PPC64_COPY R_PPC_COPY -#define R_PPC64_GLOB_DAT R_PPC_GLOB_DAT -#define R_PPC64_JMP_SLOT R_PPC_JMP_SLOT -#define R_PPC64_RELATIVE R_PPC_RELATIVE - -#define R_PPC64_UADDR32 R_PPC_UADDR32 -#define R_PPC64_UADDR16 R_PPC_UADDR16 -#define R_PPC64_REL32 R_PPC_REL32 -#define R_PPC64_PLT32 R_PPC_PLT32 -#define R_PPC64_PLTREL32 R_PPC_PLTREL32 -#define R_PPC64_PLT16_LO R_PPC_PLT16_LO -#define R_PPC64_PLT16_HI R_PPC_PLT16_HI -#define R_PPC64_PLT16_HA R_PPC_PLT16_HA - -#define R_PPC64_SECTOFF R_PPC_SECTOFF -#define R_PPC64_SECTOFF_LO R_PPC_SECTOFF_LO -#define R_PPC64_SECTOFF_HI R_PPC_SECTOFF_HI -#define R_PPC64_SECTOFF_HA R_PPC_SECTOFF_HA -#define R_PPC64_ADDR30 37 /* word30 (S + A - P) >> 2 */ -#define R_PPC64_ADDR64 38 /* doubleword64 S + A */ -#define R_PPC64_ADDR16_HIGHER 39 /* half16 #higher(S + A) */ -#define R_PPC64_ADDR16_HIGHERA 40 /* half16 #highera(S + A) */ -#define R_PPC64_ADDR16_HIGHEST 41 /* half16 #highest(S + A) */ -#define R_PPC64_ADDR16_HIGHESTA 42 /* half16 #highesta(S + A) */ -#define R_PPC64_UADDR64 43 /* doubleword64 S + A */ -#define R_PPC64_REL64 44 /* doubleword64 S + A - P */ -#define R_PPC64_PLT64 45 /* doubleword64 L + A */ -#define R_PPC64_PLTREL64 46 /* doubleword64 L + A - P */ -#define R_PPC64_TOC16 47 /* half16* S + A - .TOC */ -#define R_PPC64_TOC16_LO 48 /* half16 #lo(S + A - .TOC.) */ -#define R_PPC64_TOC16_HI 49 /* half16 #hi(S + A - .TOC.) */ -#define R_PPC64_TOC16_HA 50 /* half16 #ha(S + A - .TOC.) */ -#define R_PPC64_TOC 51 /* doubleword64 .TOC */ -#define R_PPC64_PLTGOT16 52 /* half16* M + A */ -#define R_PPC64_PLTGOT16_LO 53 /* half16 #lo(M + A) */ -#define R_PPC64_PLTGOT16_HI 54 /* half16 #hi(M + A) */ -#define R_PPC64_PLTGOT16_HA 55 /* half16 #ha(M + A) */ - -#define R_PPC64_ADDR16_DS 56 /* half16ds* (S + A) >> 2 */ -#define R_PPC64_ADDR16_LO_DS 57 /* half16ds #lo(S + A) >> 2 */ -#define R_PPC64_GOT16_DS 58 /* half16ds* (G + A) >> 2 */ -#define R_PPC64_GOT16_LO_DS 59 /* half16ds #lo(G + A) >> 2 */ -#define R_PPC64_PLT16_LO_DS 60 /* half16ds #lo(L + A) >> 2 */ -#define R_PPC64_SECTOFF_DS 61 /* half16ds* (R + A) >> 2 */ -#define R_PPC64_SECTOFF_LO_DS 62 /* half16ds #lo(R + A) >> 2 */ -#define R_PPC64_TOC16_DS 63 /* half16ds* (S + A - .TOC.) >> 2 */ -#define R_PPC64_TOC16_LO_DS 64 /* half16ds #lo(S + A - .TOC.) >> 2 */ -#define R_PPC64_PLTGOT16_DS 65 /* half16ds* (M + A) >> 2 */ -#define R_PPC64_PLTGOT16_LO_DS 66 /* half16ds #lo(M + A) >> 2 */ - -/* PowerPC64 relocations defined for the TLS access ABI. */ -#define R_PPC64_TLS 67 /* none (sym+add)@tls */ -#define R_PPC64_DTPMOD64 68 /* doubleword64 (sym+add)@dtpmod */ -#define R_PPC64_TPREL16 69 /* half16* (sym+add)@tprel */ -#define R_PPC64_TPREL16_LO 70 /* half16 (sym+add)@tprel@l */ -#define R_PPC64_TPREL16_HI 71 /* half16 (sym+add)@tprel@h */ -#define R_PPC64_TPREL16_HA 72 /* half16 (sym+add)@tprel@ha */ -#define R_PPC64_TPREL64 73 /* doubleword64 (sym+add)@tprel */ -#define R_PPC64_DTPREL16 74 /* half16* (sym+add)@dtprel */ -#define R_PPC64_DTPREL16_LO 75 /* half16 (sym+add)@dtprel@l */ -#define R_PPC64_DTPREL16_HI 76 /* half16 (sym+add)@dtprel@h */ -#define R_PPC64_DTPREL16_HA 77 /* half16 (sym+add)@dtprel@ha */ -#define R_PPC64_DTPREL64 78 /* doubleword64 (sym+add)@dtprel */ -#define R_PPC64_GOT_TLSGD16 79 /* half16* (sym+add)@got@tlsgd */ -#define R_PPC64_GOT_TLSGD16_LO 80 /* half16 (sym+add)@got@tlsgd@l */ -#define R_PPC64_GOT_TLSGD16_HI 81 /* half16 (sym+add)@got@tlsgd@h */ -#define R_PPC64_GOT_TLSGD16_HA 82 /* half16 (sym+add)@got@tlsgd@ha */ -#define R_PPC64_GOT_TLSLD16 83 /* half16* (sym+add)@got@tlsld */ -#define R_PPC64_GOT_TLSLD16_LO 84 /* half16 (sym+add)@got@tlsld@l */ -#define R_PPC64_GOT_TLSLD16_HI 85 /* half16 (sym+add)@got@tlsld@h */ -#define R_PPC64_GOT_TLSLD16_HA 86 /* half16 (sym+add)@got@tlsld@ha */ -#define R_PPC64_GOT_TPREL16_DS 87 /* half16ds* (sym+add)@got@tprel */ -#define R_PPC64_GOT_TPREL16_LO_DS 88 /* half16ds (sym+add)@got@tprel@l */ -#define R_PPC64_GOT_TPREL16_HI 89 /* half16 (sym+add)@got@tprel@h */ -#define R_PPC64_GOT_TPREL16_HA 90 /* half16 (sym+add)@got@tprel@ha */ -#define R_PPC64_GOT_DTPREL16_DS 91 /* half16ds* (sym+add)@got@dtprel */ -#define R_PPC64_GOT_DTPREL16_LO_DS 92 /* half16ds (sym+add)@got@dtprel@l */ -#define R_PPC64_GOT_DTPREL16_HI 93 /* half16 (sym+add)@got@dtprel@h */ -#define R_PPC64_GOT_DTPREL16_HA 94 /* half16 (sym+add)@got@dtprel@ha */ -#define R_PPC64_TPREL16_DS 95 /* half16ds* (sym+add)@tprel */ -#define R_PPC64_TPREL16_LO_DS 96 /* half16ds (sym+add)@tprel@l */ -#define R_PPC64_TPREL16_HIGHER 97 /* half16 (sym+add)@tprel@higher */ -#define R_PPC64_TPREL16_HIGHERA 98 /* half16 (sym+add)@tprel@highera */ -#define R_PPC64_TPREL16_HIGHEST 99 /* half16 (sym+add)@tprel@highest */ -#define R_PPC64_TPREL16_HIGHESTA 100 /* half16 (sym+add)@tprel@highesta */ -#define R_PPC64_DTPREL16_DS 101 /* half16ds* (sym+add)@dtprel */ -#define R_PPC64_DTPREL16_LO_DS 102 /* half16ds (sym+add)@dtprel@l */ -#define R_PPC64_DTPREL16_HIGHER 103 /* half16 (sym+add)@dtprel@higher */ -#define R_PPC64_DTPREL16_HIGHERA 104 /* half16 (sym+add)@dtprel@highera */ -#define R_PPC64_DTPREL16_HIGHEST 105 /* half16 (sym+add)@dtprel@highest */ -#define R_PPC64_DTPREL16_HIGHESTA 106 /* half16 (sym+add)@dtprel@highesta */ - -/* GNU extension to support local ifunc. */ -#define R_PPC64_JMP_IREL 247 -#define R_PPC64_IRELATIVE 248 -#define R_PPC64_REL16 249 /* half16 (sym+add-.) */ -#define R_PPC64_REL16_LO 250 /* half16 (sym+add-.)@l */ -#define R_PPC64_REL16_HI 251 /* half16 (sym+add-.)@h */ -#define R_PPC64_REL16_HA 252 /* half16 (sym+add-.)@ha */ - -/* PowerPC64 specific values for the Dyn d_tag field. */ -#define DT_PPC64_GLINK (DT_LOPROC + 0) -#define DT_PPC64_OPD (DT_LOPROC + 1) -#define DT_PPC64_OPDSZ (DT_LOPROC + 2) -#define DT_PPC64_NUM 3 - - -/* ARM specific declarations */ - -/* Processor specific flags for the ELF header e_flags field. */ -#define EF_ARM_RELEXEC 0x01 -#define EF_ARM_HASENTRY 0x02 -#define EF_ARM_INTERWORK 0x04 -#define EF_ARM_APCS_26 0x08 -#define EF_ARM_APCS_FLOAT 0x10 -#define EF_ARM_PIC 0x20 -#define EF_ARM_ALIGN8 0x40 /* 8-bit structure alignment is in use */ -#define EF_ARM_NEW_ABI 0x80 -#define EF_ARM_OLD_ABI 0x100 -#define EF_ARM_SOFT_FLOAT 0x200 -#define EF_ARM_VFP_FLOAT 0x400 -#define EF_ARM_MAVERICK_FLOAT 0x800 - -#define EF_ARM_ABI_FLOAT_SOFT 0x200 /* NB conflicts with EF_ARM_SOFT_FLOAT */ -#define EF_ARM_ABI_FLOAT_HARD 0x400 /* NB conflicts with EF_ARM_VFP_FLOAT */ - - -/* Other constants defined in the ARM ELF spec. version B-01. */ -/* NB. These conflict with values defined above. */ -#define EF_ARM_SYMSARESORTED 0x04 -#define EF_ARM_DYNSYMSUSESEGIDX 0x08 -#define EF_ARM_MAPSYMSFIRST 0x10 -#define EF_ARM_EABIMASK 0XFF000000 - -/* Constants defined in AAELF. */ -#define EF_ARM_BE8 0x00800000 -#define EF_ARM_LE8 0x00400000 - -#define EF_ARM_EABI_VERSION(flags) ((flags) & EF_ARM_EABIMASK) -#define EF_ARM_EABI_UNKNOWN 0x00000000 -#define EF_ARM_EABI_VER1 0x01000000 -#define EF_ARM_EABI_VER2 0x02000000 -#define EF_ARM_EABI_VER3 0x03000000 -#define EF_ARM_EABI_VER4 0x04000000 -#define EF_ARM_EABI_VER5 0x05000000 - -/* Additional symbol types for Thumb. */ -#define STT_ARM_TFUNC STT_LOPROC /* A Thumb function. */ -#define STT_ARM_16BIT STT_HIPROC /* A Thumb label. */ - -/* ARM-specific values for sh_flags */ -#define SHF_ARM_ENTRYSECT 0x10000000 /* Section contains an entry point */ -#define SHF_ARM_COMDEF 0x80000000 /* Section may be multiply defined - in the input to a link step. */ - -/* ARM-specific program header flags */ -#define PF_ARM_SB 0x10000000 /* Segment contains the location - addressed by the static base. */ -#define PF_ARM_PI 0x20000000 /* Position-independent segment. */ -#define PF_ARM_ABS 0x40000000 /* Absolute segment. */ - -/* Processor specific values for the Phdr p_type field. */ -#define PT_ARM_EXIDX (PT_LOPROC + 1) /* ARM unwind segment. */ - -/* Processor specific values for the Shdr sh_type field. */ -#define SHT_ARM_EXIDX (SHT_LOPROC + 1) /* ARM unwind section. */ -#define SHT_ARM_PREEMPTMAP (SHT_LOPROC + 2) /* Preemption details. */ -#define SHT_ARM_ATTRIBUTES (SHT_LOPROC + 3) /* ARM attributes section. */ - - -/* AArch64 relocs. */ - -#define R_AARCH64_NONE 0 /* No relocation. */ -#define R_AARCH64_ABS64 257 /* Direct 64 bit. */ -#define R_AARCH64_ABS32 258 /* Direct 32 bit. */ -#define R_AARCH64_ABS16 259 /* Direct 16-bit. */ -#define R_AARCH64_PREL64 260 /* PC-relative 64-bit. */ -#define R_AARCH64_PREL32 261 /* PC-relative 32-bit. */ -#define R_AARCH64_PREL16 262 /* PC-relative 16-bit. */ -#define R_AARCH64_MOVW_UABS_G0 263 /* Dir. MOVZ imm. from bits 15:0. */ -#define R_AARCH64_MOVW_UABS_G0_NC 264 /* Likewise for MOVK; no check. */ -#define R_AARCH64_MOVW_UABS_G1 265 /* Dir. MOVZ imm. from bits 31:16. */ -#define R_AARCH64_MOVW_UABS_G1_NC 266 /* Likewise for MOVK; no check. */ -#define R_AARCH64_MOVW_UABS_G2 267 /* Dir. MOVZ imm. from bits 47:32. */ -#define R_AARCH64_MOVW_UABS_G2_NC 268 /* Likewise for MOVK; no check. */ -#define R_AARCH64_MOVW_UABS_G3 269 /* Dir. MOV{K,Z} imm. from 63:48. */ -#define R_AARCH64_MOVW_SABS_G0 270 /* Dir. MOV{N,Z} imm. from 15:0. */ -#define R_AARCH64_MOVW_SABS_G1 271 /* Dir. MOV{N,Z} imm. from 31:16. */ -#define R_AARCH64_MOVW_SABS_G2 272 /* Dir. MOV{N,Z} imm. from 47:32. */ -#define R_AARCH64_LD_PREL_LO19 273 /* PC-rel. LD imm. from bits 20:2. */ -#define R_AARCH64_ADR_PREL_LO21 274 /* PC-rel. ADR imm. from bits 20:0. */ -#define R_AARCH64_ADR_PREL_PG_HI21 275 /* Page-rel. ADRP imm. from 32:12. */ -#define R_AARCH64_ADR_PREL_PG_HI21_NC 276 /* Likewise; no overflow check. */ -#define R_AARCH64_ADD_ABS_LO12_NC 277 /* Dir. ADD imm. from bits 11:0. */ -#define R_AARCH64_LDST8_ABS_LO12_NC 278 /* Likewise for LD/ST; no check. */ -#define R_AARCH64_TSTBR14 279 /* PC-rel. TBZ/TBNZ imm. from 15:2. */ -#define R_AARCH64_CONDBR19 280 /* PC-rel. cond. br. imm. from 20:2. */ -#define R_AARCH64_JUMP26 282 /* PC-rel. B imm. from bits 27:2. */ -#define R_AARCH64_CALL26 283 /* Likewise for CALL. */ -#define R_AARCH64_LDST16_ABS_LO12_NC 284 /* Dir. ADD imm. from bits 11:1. */ -#define R_AARCH64_LDST32_ABS_LO12_NC 285 /* Likewise for bits 11:2. */ -#define R_AARCH64_LDST64_ABS_LO12_NC 286 /* Likewise for bits 11:3. */ -#define R_AARCH64_MOVW_PREL_G0 287 /* PC-rel. MOV{N,Z} imm. from 15:0. */ -#define R_AARCH64_MOVW_PREL_G0_NC 288 /* Likewise for MOVK; no check. */ -#define R_AARCH64_MOVW_PREL_G1 289 /* PC-rel. MOV{N,Z} imm. from 31:16. */ -#define R_AARCH64_MOVW_PREL_G1_NC 290 /* Likewise for MOVK; no check. */ -#define R_AARCH64_MOVW_PREL_G2 291 /* PC-rel. MOV{N,Z} imm. from 47:32. */ -#define R_AARCH64_MOVW_PREL_G2_NC 292 /* Likewise for MOVK; no check. */ -#define R_AARCH64_MOVW_PREL_G3 293 /* PC-rel. MOV{N,Z} imm. from 63:48. */ -#define R_AARCH64_LDST128_ABS_LO12_NC 299 /* Dir. ADD imm. from bits 11:4. */ -#define R_AARCH64_MOVW_GOTOFF_G0 300 /* GOT-rel. off. MOV{N,Z} imm. 15:0. */ -#define R_AARCH64_MOVW_GOTOFF_G0_NC 301 /* Likewise for MOVK; no check. */ -#define R_AARCH64_MOVW_GOTOFF_G1 302 /* GOT-rel. o. MOV{N,Z} imm. 31:16. */ -#define R_AARCH64_MOVW_GOTOFF_G1_NC 303 /* Likewise for MOVK; no check. */ -#define R_AARCH64_MOVW_GOTOFF_G2 304 /* GOT-rel. o. MOV{N,Z} imm. 47:32. */ -#define R_AARCH64_MOVW_GOTOFF_G2_NC 305 /* Likewise for MOVK; no check. */ -#define R_AARCH64_MOVW_GOTOFF_G3 306 /* GOT-rel. o. MOV{N,Z} imm. 63:48. */ -#define R_AARCH64_GOTREL64 307 /* GOT-relative 64-bit. */ -#define R_AARCH64_GOTREL32 308 /* GOT-relative 32-bit. */ -#define R_AARCH64_GOT_LD_PREL19 309 /* PC-rel. GOT off. load imm. 20:2. */ -#define R_AARCH64_LD64_GOTOFF_LO15 310 /* GOT-rel. off. LD/ST imm. 14:3. */ -#define R_AARCH64_ADR_GOT_PAGE 311 /* P-page-rel. GOT off. ADRP 32:12. */ -#define R_AARCH64_LD64_GOT_LO12_NC 312 /* Dir. GOT off. LD/ST imm. 11:3. */ -#define R_AARCH64_LD64_GOTPAGE_LO15 313 /* GOT-page-rel. GOT off. LD/ST 14:3 */ -#define R_AARCH64_TLSGD_ADR_PREL21 512 /* PC-relative ADR imm. 20:0. */ -#define R_AARCH64_TLSGD_ADR_PAGE21 513 /* page-rel. ADRP imm. 32:12. */ -#define R_AARCH64_TLSGD_ADD_LO12_NC 514 /* direct ADD imm. from 11:0. */ -#define R_AARCH64_TLSGD_MOVW_G1 515 /* GOT-rel. MOV{N,Z} 31:16. */ -#define R_AARCH64_TLSGD_MOVW_G0_NC 516 /* GOT-rel. MOVK imm. 15:0. */ -#define R_AARCH64_TLSLD_ADR_PREL21 517 /* Like 512; local dynamic model. */ -#define R_AARCH64_TLSLD_ADR_PAGE21 518 /* Like 513; local dynamic model. */ -#define R_AARCH64_TLSLD_ADD_LO12_NC 519 /* Like 514; local dynamic model. */ -#define R_AARCH64_TLSLD_MOVW_G1 520 /* Like 515; local dynamic model. */ -#define R_AARCH64_TLSLD_MOVW_G0_NC 521 /* Like 516; local dynamic model. */ -#define R_AARCH64_TLSLD_LD_PREL19 522 /* TLS PC-rel. load imm. 20:2. */ -#define R_AARCH64_TLSLD_MOVW_DTPREL_G2 523 /* TLS DTP-rel. MOV{N,Z} 47:32. */ -#define R_AARCH64_TLSLD_MOVW_DTPREL_G1 524 /* TLS DTP-rel. MOV{N,Z} 31:16. */ -#define R_AARCH64_TLSLD_MOVW_DTPREL_G1_NC 525 /* Likewise; MOVK; no check. */ -#define R_AARCH64_TLSLD_MOVW_DTPREL_G0 526 /* TLS DTP-rel. MOV{N,Z} 15:0. */ -#define R_AARCH64_TLSLD_MOVW_DTPREL_G0_NC 527 /* Likewise; MOVK; no check. */ -#define R_AARCH64_TLSLD_ADD_DTPREL_HI12 528 /* DTP-rel. ADD imm. from 23:12. */ -#define R_AARCH64_TLSLD_ADD_DTPREL_LO12 529 /* DTP-rel. ADD imm. from 11:0. */ -#define R_AARCH64_TLSLD_ADD_DTPREL_LO12_NC 530 /* Likewise; no ovfl. check. */ -#define R_AARCH64_TLSLD_LDST8_DTPREL_LO12 531 /* DTP-rel. LD/ST imm. 11:0. */ -#define R_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC 532 /* Likewise; no check. */ -#define R_AARCH64_TLSLD_LDST16_DTPREL_LO12 533 /* DTP-rel. LD/ST imm. 11:1. */ -#define R_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC 534 /* Likewise; no check. */ -#define R_AARCH64_TLSLD_LDST32_DTPREL_LO12 535 /* DTP-rel. LD/ST imm. 11:2. */ -#define R_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC 536 /* Likewise; no check. */ -#define R_AARCH64_TLSLD_LDST64_DTPREL_LO12 537 /* DTP-rel. LD/ST imm. 11:3. */ -#define R_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC 538 /* Likewise; no check. */ -#define R_AARCH64_TLSIE_MOVW_GOTTPREL_G1 539 /* GOT-rel. MOV{N,Z} 31:16. */ -#define R_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC 540 /* GOT-rel. MOVK 15:0. */ -#define R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 541 /* Page-rel. ADRP 32:12. */ -#define R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC 542 /* Direct LD off. 11:3. */ -#define R_AARCH64_TLSIE_LD_GOTTPREL_PREL19 543 /* PC-rel. load imm. 20:2. */ -#define R_AARCH64_TLSLE_MOVW_TPREL_G2 544 /* TLS TP-rel. MOV{N,Z} 47:32. */ -#define R_AARCH64_TLSLE_MOVW_TPREL_G1 545 /* TLS TP-rel. MOV{N,Z} 31:16. */ -#define R_AARCH64_TLSLE_MOVW_TPREL_G1_NC 546 /* Likewise; MOVK; no check. */ -#define R_AARCH64_TLSLE_MOVW_TPREL_G0 547 /* TLS TP-rel. MOV{N,Z} 15:0. */ -#define R_AARCH64_TLSLE_MOVW_TPREL_G0_NC 548 /* Likewise; MOVK; no check. */ -#define R_AARCH64_TLSLE_ADD_TPREL_HI12 549 /* TP-rel. ADD imm. 23:12. */ -#define R_AARCH64_TLSLE_ADD_TPREL_LO12 550 /* TP-rel. ADD imm. 11:0. */ -#define R_AARCH64_TLSLE_ADD_TPREL_LO12_NC 551 /* Likewise; no ovfl. check. */ -#define R_AARCH64_TLSLE_LDST8_TPREL_LO12 552 /* TP-rel. LD/ST off. 11:0. */ -#define R_AARCH64_TLSLE_LDST8_TPREL_LO12_NC 553 /* Likewise; no ovfl. check. */ -#define R_AARCH64_TLSLE_LDST16_TPREL_LO12 554 /* TP-rel. LD/ST off. 11:1. */ -#define R_AARCH64_TLSLE_LDST16_TPREL_LO12_NC 555 /* Likewise; no check. */ -#define R_AARCH64_TLSLE_LDST32_TPREL_LO12 556 /* TP-rel. LD/ST off. 11:2. */ -#define R_AARCH64_TLSLE_LDST32_TPREL_LO12_NC 557 /* Likewise; no check. */ -#define R_AARCH64_TLSLE_LDST64_TPREL_LO12 558 /* TP-rel. LD/ST off. 11:3. */ -#define R_AARCH64_TLSLE_LDST64_TPREL_LO12_NC 559 /* Likewise; no check. */ -#define R_AARCH64_TLSDESC_LD_PREL19 560 /* PC-rel. load immediate 20:2. */ -#define R_AARCH64_TLSDESC_ADR_PREL21 561 /* PC-rel. ADR immediate 20:0. */ -#define R_AARCH64_TLSDESC_ADR_PAGE21 562 /* Page-rel. ADRP imm. 32:12. */ -#define R_AARCH64_TLSDESC_LD64_LO12 563 /* Direct LD off. from 11:3. */ -#define R_AARCH64_TLSDESC_ADD_LO12 564 /* Direct ADD imm. from 11:0. */ -#define R_AARCH64_TLSDESC_OFF_G1 565 /* GOT-rel. MOV{N,Z} imm. 31:16. */ -#define R_AARCH64_TLSDESC_OFF_G0_NC 566 /* GOT-rel. MOVK imm. 15:0; no ck. */ -#define R_AARCH64_TLSDESC_LDR 567 /* Relax LDR. */ -#define R_AARCH64_TLSDESC_ADD 568 /* Relax ADD. */ -#define R_AARCH64_TLSDESC_CALL 569 /* Relax BLR. */ -#define R_AARCH64_TLSLE_LDST128_TPREL_LO12 570 /* TP-rel. LD/ST off. 11:4. */ -#define R_AARCH64_TLSLE_LDST128_TPREL_LO12_NC 571 /* Likewise; no check. */ -#define R_AARCH64_TLSLD_LDST128_DTPREL_LO12 572 /* DTP-rel. LD/ST imm. 11:4. */ -#define R_AARCH64_TLSLD_LDST128_DTPREL_LO12_NC 573 /* Likewise; no check. */ -#define R_AARCH64_COPY 1024 /* Copy symbol at runtime. */ -#define R_AARCH64_GLOB_DAT 1025 /* Create GOT entry. */ -#define R_AARCH64_JUMP_SLOT 1026 /* Create PLT entry. */ -#define R_AARCH64_RELATIVE 1027 /* Adjust by program base. */ -#define R_AARCH64_TLS_DTPMOD64 1028 /* Module number, 64 bit. */ -#define R_AARCH64_TLS_DTPREL64 1029 /* Module-relative offset, 64 bit. */ -#define R_AARCH64_TLS_TPREL64 1030 /* TP-relative offset, 64 bit. */ -#define R_AARCH64_TLSDESC 1031 /* TLS Descriptor. */ -#define R_AARCH64_IRELATIVE 1032 /* STT_GNU_IFUNC relocation. */ -/* Keep this the last entry. */ -#define R_AARCH64_NUM 1033 - -/* ARM relocs. */ - -#define R_ARM_NONE 0 /* No reloc */ -#define R_ARM_PC24 1 /* PC relative 26 bit branch */ -#define R_ARM_ABS32 2 /* Direct 32 bit */ -#define R_ARM_REL32 3 /* PC relative 32 bit */ -#define R_ARM_PC13 4 -#define R_ARM_ABS16 5 /* Direct 16 bit */ -#define R_ARM_ABS12 6 /* Direct 12 bit */ -#define R_ARM_THM_ABS5 7 -#define R_ARM_ABS8 8 /* Direct 8 bit */ -#define R_ARM_SBREL32 9 -#define R_ARM_THM_PC22 10 -#define R_ARM_THM_PC8 11 -#define R_ARM_AMP_VCALL9 12 -#define R_ARM_SWI24 13 /* Obsolete static relocation. */ -#define R_ARM_TLS_DESC 13 /* Dynamic relocation. */ -#define R_ARM_THM_SWI8 14 -#define R_ARM_XPC25 15 -#define R_ARM_THM_XPC22 16 -#define R_ARM_TLS_DTPMOD32 17 /* ID of module containing symbol */ -#define R_ARM_TLS_DTPOFF32 18 /* Offset in TLS block */ -#define R_ARM_TLS_TPOFF32 19 /* Offset in static TLS block */ -#define R_ARM_COPY 20 /* Copy symbol at runtime */ -#define R_ARM_GLOB_DAT 21 /* Create GOT entry */ -#define R_ARM_JUMP_SLOT 22 /* Create PLT entry */ -#define R_ARM_RELATIVE 23 /* Adjust by program base */ -#define R_ARM_GOTOFF 24 /* 32 bit offset to GOT */ -#define R_ARM_GOTPC 25 /* 32 bit PC relative offset to GOT */ -#define R_ARM_GOT32 26 /* 32 bit GOT entry */ -#define R_ARM_PLT32 27 /* 32 bit PLT address */ -#define R_ARM_CALL 28 -#define R_ARM_JUMP24 29 -#define R_ARM_THM_JUMP24 30 -#define R_ARM_BASE_ABS 31 /* Adjust by program base. */ -#define R_ARM_ALU_PCREL_7_0 32 -#define R_ARM_ALU_PCREL_15_8 33 -#define R_ARM_ALU_PCREL_23_15 34 -#define R_ARM_LDR_SBREL_11_0 35 -#define R_ARM_ALU_SBREL_19_12 36 -#define R_ARM_ALU_SBREL_27_20 37 -#define R_ARM_TARGET1 38 -#define R_ARM_SBREL31 39 /* Program base relative. */ -#define R_ARM_V4BX 40 -#define R_ARM_TARGET2 41 -#define R_ARM_PREL31 42 -#define R_ARM_MOVW_ABS_NC 43 -#define R_ARM_MOVT_ABS 44 -#define R_ARM_MOVW_PREL_NC 45 /* PC relative 16-bit (MOVW). */ -#define R_ARM_MOVT_PREL 46 /* PC relative (MOVT). */ -#define R_ARM_THM_MOVW_ABS_NC 47 -#define R_ARM_THM_MOVT_ABS 48 -/* Values from 49 to 89 are not yet used/handled by tcc. */ -#define R_ARM_TLS_GOTDESC 90 -#define R_ARM_TLS_CALL 91 -#define R_ARM_TLS_DESCSEQ 92 -#define R_ARM_THM_TLS_CALL 93 -#define R_ARM_GOT_PREL 96 -#define R_ARM_GNU_VTENTRY 100 -#define R_ARM_GNU_VTINHERIT 101 -#define R_ARM_THM_PC11 102 /* thumb unconditional branch */ -#define R_ARM_THM_PC9 103 /* thumb conditional branch */ -#define R_ARM_TLS_GD32 104 /* PC-rel 32 bit for global dynamic - thread local data */ -#define R_ARM_TLS_LDM32 105 /* PC-rel 32 bit for local dynamic - thread local data */ -#define R_ARM_TLS_LDO32 106 /* 32 bit offset relative to TLS - block */ -#define R_ARM_TLS_IE32 107 /* PC-rel 32 bit for GOT entry of - static TLS block offset */ -#define R_ARM_TLS_LE32 108 /* 32 bit offset relative to static - TLS block */ -#define R_ARM_THM_TLS_DESCSEQ 129 -#define R_ARM_IRELATIVE 160 -#define R_ARM_RXPC25 249 -#define R_ARM_RSBREL32 250 -#define R_ARM_THM_RPC22 251 -#define R_ARM_RREL32 252 -#define R_ARM_RABS22 253 -#define R_ARM_RPC24 254 -#define R_ARM_RBASE 255 -/* Keep this the last entry. */ -#define R_ARM_NUM 256 - -/* TMS320C67xx specific declarations */ - -/* XXX: no ELF standard yet*/ - -/* TMS320C67xx relocs. */ -#define R_C60_32 1 -#define R_C60_GOT32 3 /* 32 bit GOT entry */ -#define R_C60_PLT32 4 /* 32 bit PLT address */ -#define R_C60_COPY 5 /* Copy symbol at runtime */ -#define R_C60_GLOB_DAT 6 /* Create GOT entry */ -#define R_C60_JMP_SLOT 7 /* Create PLT entry */ -#define R_C60_RELATIVE 8 /* Adjust by program base */ -#define R_C60_GOTOFF 9 /* 32 bit offset to GOT */ -#define R_C60_GOTPC 10 /* 32 bit PC relative offset to GOT */ - -#define R_C60LO16 0x54 /* low 16 bit MVKL embedded */ -#define R_C60HI16 0x55 /* high 16 bit MVKH embedded */ -/* Keep this the last entry. */ -#define R_C60_NUM 0x56 - -/* IA-64 specific declarations. */ - -/* Processor specific flags for the Ehdr e_flags field. */ -#define EF_IA_64_MASKOS 0x0000000f /* os-specific flags */ -#define EF_IA_64_ABI64 0x00000010 /* 64-bit ABI */ -#define EF_IA_64_ARCH 0xff000000 /* arch. version mask */ - -/* Processor specific values for the Phdr p_type field. */ -#define PT_IA_64_ARCHEXT (PT_LOPROC + 0) /* arch extension bits */ -#define PT_IA_64_UNWIND (PT_LOPROC + 1) /* ia64 unwind bits */ -#define PT_IA_64_HP_OPT_ANOT (PT_LOOS + 0x12) -#define PT_IA_64_HP_HSL_ANOT (PT_LOOS + 0x13) -#define PT_IA_64_HP_STACK (PT_LOOS + 0x14) - -/* Processor specific flags for the Phdr p_flags field. */ -#define PF_IA_64_NORECOV 0x80000000 /* spec insns w/o recovery */ - -/* Processor specific values for the Shdr sh_type field. */ -#define SHT_IA_64_EXT (SHT_LOPROC + 0) /* extension bits */ -#define SHT_IA_64_UNWIND (SHT_LOPROC + 1) /* unwind bits */ - -/* Processor specific flags for the Shdr sh_flags field. */ -#define SHF_IA_64_SHORT 0x10000000 /* section near gp */ -#define SHF_IA_64_NORECOV 0x20000000 /* spec insns w/o recovery */ - -/* Processor specific values for the Dyn d_tag field. */ -#define DT_IA_64_PLT_RESERVE (DT_LOPROC + 0) -#define DT_IA_64_NUM 1 - -/* IA-64 relocations. */ -#define R_IA64_NONE 0x00 /* none */ -#define R_IA64_IMM14 0x21 /* symbol + addend, add imm14 */ -#define R_IA64_IMM22 0x22 /* symbol + addend, add imm22 */ -#define R_IA64_IMM64 0x23 /* symbol + addend, mov imm64 */ -#define R_IA64_DIR32MSB 0x24 /* symbol + addend, data4 MSB */ -#define R_IA64_DIR32LSB 0x25 /* symbol + addend, data4 LSB */ -#define R_IA64_DIR64MSB 0x26 /* symbol + addend, data8 MSB */ -#define R_IA64_DIR64LSB 0x27 /* symbol + addend, data8 LSB */ -#define R_IA64_GPREL22 0x2a /* @gprel(sym + add), add imm22 */ -#define R_IA64_GPREL64I 0x2b /* @gprel(sym + add), mov imm64 */ -#define R_IA64_GPREL32MSB 0x2c /* @gprel(sym + add), data4 MSB */ -#define R_IA64_GPREL32LSB 0x2d /* @gprel(sym + add), data4 LSB */ -#define R_IA64_GPREL64MSB 0x2e /* @gprel(sym + add), data8 MSB */ -#define R_IA64_GPREL64LSB 0x2f /* @gprel(sym + add), data8 LSB */ -#define R_IA64_LTOFF22 0x32 /* @ltoff(sym + add), add imm22 */ -#define R_IA64_LTOFF64I 0x33 /* @ltoff(sym + add), mov imm64 */ -#define R_IA64_PLTOFF22 0x3a /* @pltoff(sym + add), add imm22 */ -#define R_IA64_PLTOFF64I 0x3b /* @pltoff(sym + add), mov imm64 */ -#define R_IA64_PLTOFF64MSB 0x3e /* @pltoff(sym + add), data8 MSB */ -#define R_IA64_PLTOFF64LSB 0x3f /* @pltoff(sym + add), data8 LSB */ -#define R_IA64_FPTR64I 0x43 /* @fptr(sym + add), mov imm64 */ -#define R_IA64_FPTR32MSB 0x44 /* @fptr(sym + add), data4 MSB */ -#define R_IA64_FPTR32LSB 0x45 /* @fptr(sym + add), data4 LSB */ -#define R_IA64_FPTR64MSB 0x46 /* @fptr(sym + add), data8 MSB */ -#define R_IA64_FPTR64LSB 0x47 /* @fptr(sym + add), data8 LSB */ -#define R_IA64_PCREL60B 0x48 /* @pcrel(sym + add), brl */ -#define R_IA64_PCREL21B 0x49 /* @pcrel(sym + add), ptb, call */ -#define R_IA64_PCREL21M 0x4a /* @pcrel(sym + add), chk.s */ -#define R_IA64_PCREL21F 0x4b /* @pcrel(sym + add), fchkf */ -#define R_IA64_PCREL32MSB 0x4c /* @pcrel(sym + add), data4 MSB */ -#define R_IA64_PCREL32LSB 0x4d /* @pcrel(sym + add), data4 LSB */ -#define R_IA64_PCREL64MSB 0x4e /* @pcrel(sym + add), data8 MSB */ -#define R_IA64_PCREL64LSB 0x4f /* @pcrel(sym + add), data8 LSB */ -#define R_IA64_LTOFF_FPTR22 0x52 /* @ltoff(@fptr(s+a)), imm22 */ -#define R_IA64_LTOFF_FPTR64I 0x53 /* @ltoff(@fptr(s+a)), imm64 */ -#define R_IA64_LTOFF_FPTR32MSB 0x54 /* @ltoff(@fptr(s+a)), data4 MSB */ -#define R_IA64_LTOFF_FPTR32LSB 0x55 /* @ltoff(@fptr(s+a)), data4 LSB */ -#define R_IA64_LTOFF_FPTR64MSB 0x56 /* @ltoff(@fptr(s+a)), data8 MSB */ -#define R_IA64_LTOFF_FPTR64LSB 0x57 /* @ltoff(@fptr(s+a)), data8 LSB */ -#define R_IA64_SEGREL32MSB 0x5c /* @segrel(sym + add), data4 MSB */ -#define R_IA64_SEGREL32LSB 0x5d /* @segrel(sym + add), data4 LSB */ -#define R_IA64_SEGREL64MSB 0x5e /* @segrel(sym + add), data8 MSB */ -#define R_IA64_SEGREL64LSB 0x5f /* @segrel(sym + add), data8 LSB */ -#define R_IA64_SECREL32MSB 0x64 /* @secrel(sym + add), data4 MSB */ -#define R_IA64_SECREL32LSB 0x65 /* @secrel(sym + add), data4 LSB */ -#define R_IA64_SECREL64MSB 0x66 /* @secrel(sym + add), data8 MSB */ -#define R_IA64_SECREL64LSB 0x67 /* @secrel(sym + add), data8 LSB */ -#define R_IA64_REL32MSB 0x6c /* data 4 + REL */ -#define R_IA64_REL32LSB 0x6d /* data 4 + REL */ -#define R_IA64_REL64MSB 0x6e /* data 8 + REL */ -#define R_IA64_REL64LSB 0x6f /* data 8 + REL */ -#define R_IA64_LTV32MSB 0x74 /* symbol + addend, data4 MSB */ -#define R_IA64_LTV32LSB 0x75 /* symbol + addend, data4 LSB */ -#define R_IA64_LTV64MSB 0x76 /* symbol + addend, data8 MSB */ -#define R_IA64_LTV64LSB 0x77 /* symbol + addend, data8 LSB */ -#define R_IA64_PCREL21BI 0x79 /* @pcrel(sym + add), 21bit inst */ -#define R_IA64_PCREL22 0x7a /* @pcrel(sym + add), 22bit inst */ -#define R_IA64_PCREL64I 0x7b /* @pcrel(sym + add), 64bit inst */ -#define R_IA64_IPLTMSB 0x80 /* dynamic reloc, imported PLT, MSB */ -#define R_IA64_IPLTLSB 0x81 /* dynamic reloc, imported PLT, LSB */ -#define R_IA64_COPY 0x84 /* copy relocation */ -#define R_IA64_SUB 0x85 /* Addend and symbol difference */ -#define R_IA64_LTOFF22X 0x86 /* LTOFF22, relaxable. */ -#define R_IA64_LDXMOV 0x87 /* Use of LTOFF22X. */ -#define R_IA64_TPREL14 0x91 /* @tprel(sym + add), imm14 */ -#define R_IA64_TPREL22 0x92 /* @tprel(sym + add), imm22 */ -#define R_IA64_TPREL64I 0x93 /* @tprel(sym + add), imm64 */ -#define R_IA64_TPREL64MSB 0x96 /* @tprel(sym + add), data8 MSB */ -#define R_IA64_TPREL64LSB 0x97 /* @tprel(sym + add), data8 LSB */ -#define R_IA64_LTOFF_TPREL22 0x9a /* @ltoff(@tprel(s+a)), imm2 */ -#define R_IA64_DTPMOD64MSB 0xa6 /* @dtpmod(sym + add), data8 MSB */ -#define R_IA64_DTPMOD64LSB 0xa7 /* @dtpmod(sym + add), data8 LSB */ -#define R_IA64_LTOFF_DTPMOD22 0xaa /* @ltoff(@dtpmod(sym + add)), imm22 */ -#define R_IA64_DTPREL14 0xb1 /* @dtprel(sym + add), imm14 */ -#define R_IA64_DTPREL22 0xb2 /* @dtprel(sym + add), imm22 */ -#define R_IA64_DTPREL64I 0xb3 /* @dtprel(sym + add), imm64 */ -#define R_IA64_DTPREL32MSB 0xb4 /* @dtprel(sym + add), data4 MSB */ -#define R_IA64_DTPREL32LSB 0xb5 /* @dtprel(sym + add), data4 LSB */ -#define R_IA64_DTPREL64MSB 0xb6 /* @dtprel(sym + add), data8 MSB */ -#define R_IA64_DTPREL64LSB 0xb7 /* @dtprel(sym + add), data8 LSB */ -#define R_IA64_LTOFF_DTPREL22 0xba /* @ltoff(@dtprel(s+a)), imm22 */ - -/* SH specific declarations */ - -/* Processor specific flags for the ELF header e_flags field. */ -#define EF_SH_MACH_MASK 0x1f -#define EF_SH_UNKNOWN 0x0 -#define EF_SH1 0x1 -#define EF_SH2 0x2 -#define EF_SH3 0x3 -#define EF_SH_DSP 0x4 -#define EF_SH3_DSP 0x5 -#define EF_SH4AL_DSP 0x6 -#define EF_SH3E 0x8 -#define EF_SH4 0x9 -#define EF_SH2E 0xb -#define EF_SH4A 0xc -#define EF_SH2A 0xd -#define EF_SH4_NOFPU 0x10 -#define EF_SH4A_NOFPU 0x11 -#define EF_SH4_NOMMU_NOFPU 0x12 -#define EF_SH2A_NOFPU 0x13 -#define EF_SH3_NOMMU 0x14 -#define EF_SH2A_SH4_NOFPU 0x15 -#define EF_SH2A_SH3_NOFPU 0x16 -#define EF_SH2A_SH4 0x17 -#define EF_SH2A_SH3E 0x18 - -/* SH relocs. */ -#define R_SH_NONE 0 -#define R_SH_DIR32 1 -#define R_SH_REL32 2 -#define R_SH_DIR8WPN 3 -#define R_SH_IND12W 4 -#define R_SH_DIR8WPL 5 -#define R_SH_DIR8WPZ 6 -#define R_SH_DIR8BP 7 -#define R_SH_DIR8W 8 -#define R_SH_DIR8L 9 -#define R_SH_SWITCH16 25 -#define R_SH_SWITCH32 26 -#define R_SH_USES 27 -#define R_SH_COUNT 28 -#define R_SH_ALIGN 29 -#define R_SH_CODE 30 -#define R_SH_DATA 31 -#define R_SH_LABEL 32 -#define R_SH_SWITCH8 33 -#define R_SH_GNU_VTINHERIT 34 -#define R_SH_GNU_VTENTRY 35 -#define R_SH_TLS_GD_32 144 -#define R_SH_TLS_LD_32 145 -#define R_SH_TLS_LDO_32 146 -#define R_SH_TLS_IE_32 147 -#define R_SH_TLS_LE_32 148 -#define R_SH_TLS_DTPMOD32 149 -#define R_SH_TLS_DTPOFF32 150 -#define R_SH_TLS_TPOFF32 151 -#define R_SH_GOT32 160 -#define R_SH_PLT32 161 -#define R_SH_COPY 162 -#define R_SH_GLOB_DAT 163 -#define R_SH_JMP_SLOT 164 -#define R_SH_RELATIVE 165 -#define R_SH_GOTOFF 166 -#define R_SH_GOTPC 167 -/* Keep this the last entry. */ -#define R_SH_NUM 256 - -/* S/390 specific definitions. */ - -/* Valid values for the e_flags field. */ - -#define EF_S390_HIGH_GPRS 0x00000001 /* High GPRs kernel facility needed. */ - -/* Additional s390 relocs */ - -#define R_390_NONE 0 /* No reloc. */ -#define R_390_8 1 /* Direct 8 bit. */ -#define R_390_12 2 /* Direct 12 bit. */ -#define R_390_16 3 /* Direct 16 bit. */ -#define R_390_32 4 /* Direct 32 bit. */ -#define R_390_PC32 5 /* PC relative 32 bit. */ -#define R_390_GOT12 6 /* 12 bit GOT offset. */ -#define R_390_GOT32 7 /* 32 bit GOT offset. */ -#define R_390_PLT32 8 /* 32 bit PC relative PLT address. */ -#define R_390_COPY 9 /* Copy symbol at runtime. */ -#define R_390_GLOB_DAT 10 /* Create GOT entry. */ -#define R_390_JMP_SLOT 11 /* Create PLT entry. */ -#define R_390_RELATIVE 12 /* Adjust by program base. */ -#define R_390_GOTOFF32 13 /* 32 bit offset to GOT. */ -#define R_390_GOTPC 14 /* 32 bit PC relative offset to GOT. */ -#define R_390_GOT16 15 /* 16 bit GOT offset. */ -#define R_390_PC16 16 /* PC relative 16 bit. */ -#define R_390_PC16DBL 17 /* PC relative 16 bit shifted by 1. */ -#define R_390_PLT16DBL 18 /* 16 bit PC rel. PLT shifted by 1. */ -#define R_390_PC32DBL 19 /* PC relative 32 bit shifted by 1. */ -#define R_390_PLT32DBL 20 /* 32 bit PC rel. PLT shifted by 1. */ -#define R_390_GOTPCDBL 21 /* 32 bit PC rel. GOT shifted by 1. */ -#define R_390_64 22 /* Direct 64 bit. */ -#define R_390_PC64 23 /* PC relative 64 bit. */ -#define R_390_GOT64 24 /* 64 bit GOT offset. */ -#define R_390_PLT64 25 /* 64 bit PC relative PLT address. */ -#define R_390_GOTENT 26 /* 32 bit PC rel. to GOT entry >> 1. */ -#define R_390_GOTOFF16 27 /* 16 bit offset to GOT. */ -#define R_390_GOTOFF64 28 /* 64 bit offset to GOT. */ -#define R_390_GOTPLT12 29 /* 12 bit offset to jump slot. */ -#define R_390_GOTPLT16 30 /* 16 bit offset to jump slot. */ -#define R_390_GOTPLT32 31 /* 32 bit offset to jump slot. */ -#define R_390_GOTPLT64 32 /* 64 bit offset to jump slot. */ -#define R_390_GOTPLTENT 33 /* 32 bit rel. offset to jump slot. */ -#define R_390_PLTOFF16 34 /* 16 bit offset from GOT to PLT. */ -#define R_390_PLTOFF32 35 /* 32 bit offset from GOT to PLT. */ -#define R_390_PLTOFF64 36 /* 16 bit offset from GOT to PLT. */ -#define R_390_TLS_LOAD 37 /* Tag for load insn in TLS code. */ -#define R_390_TLS_GDCALL 38 /* Tag for function call in general - dynamic TLS code. */ -#define R_390_TLS_LDCALL 39 /* Tag for function call in local - dynamic TLS code. */ -#define R_390_TLS_GD32 40 /* Direct 32 bit for general dynamic - thread local data. */ -#define R_390_TLS_GD64 41 /* Direct 64 bit for general dynamic - thread local data. */ -#define R_390_TLS_GOTIE12 42 /* 12 bit GOT offset for static TLS - block offset. */ -#define R_390_TLS_GOTIE32 43 /* 32 bit GOT offset for static TLS - block offset. */ -#define R_390_TLS_GOTIE64 44 /* 64 bit GOT offset for static TLS - block offset. */ -#define R_390_TLS_LDM32 45 /* Direct 32 bit for local dynamic - thread local data in LE code. */ -#define R_390_TLS_LDM64 46 /* Direct 64 bit for local dynamic - thread local data in LE code. */ -#define R_390_TLS_IE32 47 /* 32 bit address of GOT entry for - negated static TLS block offset. */ -#define R_390_TLS_IE64 48 /* 64 bit address of GOT entry for - negated static TLS block offset. */ -#define R_390_TLS_IEENT 49 /* 32 bit rel. offset to GOT entry for - negated static TLS block offset. */ -#define R_390_TLS_LE32 50 /* 32 bit negated offset relative to - static TLS block. */ -#define R_390_TLS_LE64 51 /* 64 bit negated offset relative to - static TLS block. */ -#define R_390_TLS_LDO32 52 /* 32 bit offset relative to TLS - block. */ -#define R_390_TLS_LDO64 53 /* 64 bit offset relative to TLS - block. */ -#define R_390_TLS_DTPMOD 54 /* ID of module containing symbol. */ -#define R_390_TLS_DTPOFF 55 /* Offset in TLS block. */ -#define R_390_TLS_TPOFF 56 /* Negated offset in static TLS - block. */ -#define R_390_20 57 /* Direct 20 bit. */ -#define R_390_GOT20 58 /* 20 bit GOT offset. */ -#define R_390_GOTPLT20 59 /* 20 bit offset to jump slot. */ -#define R_390_TLS_GOTIE20 60 /* 20 bit GOT offset for static TLS - block offset. */ -#define R_390_IRELATIVE 61 /* STT_GNU_IFUNC relocation. */ -/* Keep this the last entry. */ -#define R_390_NUM 62 - - -/* CRIS relocations. */ -#define R_CRIS_NONE 0 -#define R_CRIS_8 1 -#define R_CRIS_16 2 -#define R_CRIS_32 3 -#define R_CRIS_8_PCREL 4 -#define R_CRIS_16_PCREL 5 -#define R_CRIS_32_PCREL 6 -#define R_CRIS_GNU_VTINHERIT 7 -#define R_CRIS_GNU_VTENTRY 8 -#define R_CRIS_COPY 9 -#define R_CRIS_GLOB_DAT 10 -#define R_CRIS_JUMP_SLOT 11 -#define R_CRIS_RELATIVE 12 -#define R_CRIS_16_GOT 13 -#define R_CRIS_32_GOT 14 -#define R_CRIS_16_GOTPLT 15 -#define R_CRIS_32_GOTPLT 16 -#define R_CRIS_32_GOTREL 17 -#define R_CRIS_32_PLT_GOTREL 18 -#define R_CRIS_32_PLT_PCREL 19 - -#define R_CRIS_NUM 20 - - -/* AMD x86-64 relocations. */ -#define R_X86_64_NONE 0 /* No reloc */ -#define R_X86_64_64 1 /* Direct 64 bit */ -#define R_X86_64_PC32 2 /* PC relative 32 bit signed */ -#define R_X86_64_GOT32 3 /* 32 bit GOT entry */ -#define R_X86_64_PLT32 4 /* 32 bit PLT address */ -#define R_X86_64_COPY 5 /* Copy symbol at runtime */ -#define R_X86_64_GLOB_DAT 6 /* Create GOT entry */ -#define R_X86_64_JUMP_SLOT 7 /* Create PLT entry */ -#define R_X86_64_RELATIVE 8 /* Adjust by program base */ -#define R_X86_64_GOTPCREL 9 /* 32 bit signed PC relative - offset to GOT */ -#define R_X86_64_32 10 /* Direct 32 bit zero extended */ -#define R_X86_64_32S 11 /* Direct 32 bit sign extended */ -#define R_X86_64_16 12 /* Direct 16 bit zero extended */ -#define R_X86_64_PC16 13 /* 16 bit sign extended pc relative */ -#define R_X86_64_8 14 /* Direct 8 bit sign extended */ -#define R_X86_64_PC8 15 /* 8 bit sign extended pc relative */ -#define R_X86_64_DTPMOD64 16 /* ID of module containing symbol */ -#define R_X86_64_DTPOFF64 17 /* Offset in module's TLS block */ -#define R_X86_64_TPOFF64 18 /* Offset in initial TLS block */ -#define R_X86_64_TLSGD 19 /* 32 bit signed PC relative offset - to two GOT entries for GD symbol */ -#define R_X86_64_TLSLD 20 /* 32 bit signed PC relative offset - to two GOT entries for LD symbol */ -#define R_X86_64_DTPOFF32 21 /* Offset in TLS block */ -#define R_X86_64_GOTTPOFF 22 /* 32 bit signed PC relative offset - to GOT entry for IE symbol */ -#define R_X86_64_TPOFF32 23 /* Offset in initial TLS block */ -#define R_X86_64_PC64 24 /* PC relative 64 bit */ -#define R_X86_64_GOTOFF64 25 /* 64 bit offset to GOT */ -#define R_X86_64_GOTPC32 26 /* 32 bit signed pc relative - offset to GOT */ -#define R_X86_64_GOT64 27 /* 64-bit GOT entry offset */ -#define R_X86_64_GOTPCREL64 28 /* 64-bit PC relative offset - to GOT entry */ -#define R_X86_64_GOTPC64 29 /* 64-bit PC relative offset to GOT */ -#define R_X86_64_GOTPLT64 30 /* like GOT64, says PLT entry needed */ -#define R_X86_64_PLTOFF64 31 /* 64-bit GOT relative offset - to PLT entry */ -#define R_X86_64_SIZE32 32 /* Size of symbol plus 32-bit addend */ -#define R_X86_64_SIZE64 33 /* Size of symbol plus 64-bit addend */ -#define R_X86_64_GOTPC32_TLSDESC 34 /* GOT offset for TLS descriptor. */ -#define R_X86_64_TLSDESC_CALL 35 /* Marker for call through TLS - descriptor. */ -#define R_X86_64_TLSDESC 36 /* TLS descriptor. */ -#define R_X86_64_IRELATIVE 37 /* Adjust indirectly by program base */ -#define R_X86_64_RELATIVE64 38 /* 64-bit adjust by program base */ -#define R_X86_64_GOTPCRELX 41 /* like GOTPCREL, but optionally with - linker optimizations */ -#define R_X86_64_REX_GOTPCRELX 42 /* like GOTPCRELX, but a REX prefix - is present */ - -#define R_X86_64_NUM 43 - -/* x86-64 sh_type values. */ -#define SHT_X86_64_UNWIND 0x70000001 /* Unwind information. */ - -/* AM33 relocations. */ -#define R_MN10300_NONE 0 /* No reloc. */ -#define R_MN10300_32 1 /* Direct 32 bit. */ -#define R_MN10300_16 2 /* Direct 16 bit. */ -#define R_MN10300_8 3 /* Direct 8 bit. */ -#define R_MN10300_PCREL32 4 /* PC-relative 32-bit. */ -#define R_MN10300_PCREL16 5 /* PC-relative 16-bit signed. */ -#define R_MN10300_PCREL8 6 /* PC-relative 8-bit signed. */ -#define R_MN10300_GNU_VTINHERIT 7 /* Ancient C++ vtable garbage... */ -#define R_MN10300_GNU_VTENTRY 8 /* ... collection annotation. */ -#define R_MN10300_24 9 /* Direct 24 bit. */ -#define R_MN10300_GOTPC32 10 /* 32-bit PCrel offset to GOT. */ -#define R_MN10300_GOTPC16 11 /* 16-bit PCrel offset to GOT. */ -#define R_MN10300_GOTOFF32 12 /* 32-bit offset from GOT. */ -#define R_MN10300_GOTOFF24 13 /* 24-bit offset from GOT. */ -#define R_MN10300_GOTOFF16 14 /* 16-bit offset from GOT. */ -#define R_MN10300_PLT32 15 /* 32-bit PCrel to PLT entry. */ -#define R_MN10300_PLT16 16 /* 16-bit PCrel to PLT entry. */ -#define R_MN10300_GOT32 17 /* 32-bit offset to GOT entry. */ -#define R_MN10300_GOT24 18 /* 24-bit offset to GOT entry. */ -#define R_MN10300_GOT16 19 /* 16-bit offset to GOT entry. */ -#define R_MN10300_COPY 20 /* Copy symbol at runtime. */ -#define R_MN10300_GLOB_DAT 21 /* Create GOT entry. */ -#define R_MN10300_JMP_SLOT 22 /* Create PLT entry. */ -#define R_MN10300_RELATIVE 23 /* Adjust by program base. */ -#define R_MN10300_TLS_GD 24 /* 32-bit offset for global dynamic. */ -#define R_MN10300_TLS_LD 25 /* 32-bit offset for local dynamic. */ -#define R_MN10300_TLS_LDO 26 /* Module-relative offset. */ -#define R_MN10300_TLS_GOTIE 27 /* GOT offset for static TLS block - offset. */ -#define R_MN10300_TLS_IE 28 /* GOT address for static TLS block - offset. */ -#define R_MN10300_TLS_LE 29 /* Offset relative to static TLS - block. */ -#define R_MN10300_TLS_DTPMOD 30 /* ID of module containing symbol. */ -#define R_MN10300_TLS_DTPOFF 31 /* Offset in module TLS block. */ -#define R_MN10300_TLS_TPOFF 32 /* Offset in static TLS block. */ -#define R_MN10300_SYM_DIFF 33 /* Adjustment for next reloc as needed - by linker relaxation. */ -#define R_MN10300_ALIGN 34 /* Alignment requirement for linker - relaxation. */ -#define R_MN10300_NUM 35 - - -/* M32R relocs. */ -#define R_M32R_NONE 0 /* No reloc. */ -#define R_M32R_16 1 /* Direct 16 bit. */ -#define R_M32R_32 2 /* Direct 32 bit. */ -#define R_M32R_24 3 /* Direct 24 bit. */ -#define R_M32R_10_PCREL 4 /* PC relative 10 bit shifted. */ -#define R_M32R_18_PCREL 5 /* PC relative 18 bit shifted. */ -#define R_M32R_26_PCREL 6 /* PC relative 26 bit shifted. */ -#define R_M32R_HI16_ULO 7 /* High 16 bit with unsigned low. */ -#define R_M32R_HI16_SLO 8 /* High 16 bit with signed low. */ -#define R_M32R_LO16 9 /* Low 16 bit. */ -#define R_M32R_SDA16 10 /* 16 bit offset in SDA. */ -#define R_M32R_GNU_VTINHERIT 11 -#define R_M32R_GNU_VTENTRY 12 -/* M32R relocs use SHT_RELA. */ -#define R_M32R_16_RELA 33 /* Direct 16 bit. */ -#define R_M32R_32_RELA 34 /* Direct 32 bit. */ -#define R_M32R_24_RELA 35 /* Direct 24 bit. */ -#define R_M32R_10_PCREL_RELA 36 /* PC relative 10 bit shifted. */ -#define R_M32R_18_PCREL_RELA 37 /* PC relative 18 bit shifted. */ -#define R_M32R_26_PCREL_RELA 38 /* PC relative 26 bit shifted. */ -#define R_M32R_HI16_ULO_RELA 39 /* High 16 bit with unsigned low */ -#define R_M32R_HI16_SLO_RELA 40 /* High 16 bit with signed low */ -#define R_M32R_LO16_RELA 41 /* Low 16 bit */ -#define R_M32R_SDA16_RELA 42 /* 16 bit offset in SDA */ -#define R_M32R_RELA_GNU_VTINHERIT 43 -#define R_M32R_RELA_GNU_VTENTRY 44 -#define R_M32R_REL32 45 /* PC relative 32 bit. */ - -#define R_M32R_GOT24 48 /* 24 bit GOT entry */ -#define R_M32R_26_PLTREL 49 /* 26 bit PC relative to PLT shifted */ -#define R_M32R_COPY 50 /* Copy symbol at runtime */ -#define R_M32R_GLOB_DAT 51 /* Create GOT entry */ -#define R_M32R_JMP_SLOT 52 /* Create PLT entry */ -#define R_M32R_RELATIVE 53 /* Adjust by program base */ -#define R_M32R_GOTOFF 54 /* 24 bit offset to GOT */ -#define R_M32R_GOTPC24 55 /* 24 bit PC relative offset to GOT */ -#define R_M32R_GOT16_HI_ULO 56 /* High 16 bit GOT entry with unsigned - low */ -#define R_M32R_GOT16_HI_SLO 57 /* High 16 bit GOT entry with signed - low */ -#define R_M32R_GOT16_LO 58 /* Low 16 bit GOT entry */ -#define R_M32R_GOTPC_HI_ULO 59 /* High 16 bit PC relative offset to - GOT with unsigned low */ -#define R_M32R_GOTPC_HI_SLO 60 /* High 16 bit PC relative offset to - GOT with signed low */ -#define R_M32R_GOTPC_LO 61 /* Low 16 bit PC relative offset to - GOT */ -#define R_M32R_GOTOFF_HI_ULO 62 /* High 16 bit offset to GOT - with unsigned low */ -#define R_M32R_GOTOFF_HI_SLO 63 /* High 16 bit offset to GOT - with signed low */ -#define R_M32R_GOTOFF_LO 64 /* Low 16 bit offset to GOT */ -#define R_M32R_NUM 256 /* Keep this the last entry. */ - - -/* TILEPro relocations. */ -#define R_TILEPRO_NONE 0 /* No reloc */ -#define R_TILEPRO_32 1 /* Direct 32 bit */ -#define R_TILEPRO_16 2 /* Direct 16 bit */ -#define R_TILEPRO_8 3 /* Direct 8 bit */ -#define R_TILEPRO_32_PCREL 4 /* PC relative 32 bit */ -#define R_TILEPRO_16_PCREL 5 /* PC relative 16 bit */ -#define R_TILEPRO_8_PCREL 6 /* PC relative 8 bit */ -#define R_TILEPRO_LO16 7 /* Low 16 bit */ -#define R_TILEPRO_HI16 8 /* High 16 bit */ -#define R_TILEPRO_HA16 9 /* High 16 bit, adjusted */ -#define R_TILEPRO_COPY 10 /* Copy relocation */ -#define R_TILEPRO_GLOB_DAT 11 /* Create GOT entry */ -#define R_TILEPRO_JMP_SLOT 12 /* Create PLT entry */ -#define R_TILEPRO_RELATIVE 13 /* Adjust by program base */ -#define R_TILEPRO_BROFF_X1 14 /* X1 pipe branch offset */ -#define R_TILEPRO_JOFFLONG_X1 15 /* X1 pipe jump offset */ -#define R_TILEPRO_JOFFLONG_X1_PLT 16 /* X1 pipe jump offset to PLT */ -#define R_TILEPRO_IMM8_X0 17 /* X0 pipe 8-bit */ -#define R_TILEPRO_IMM8_Y0 18 /* Y0 pipe 8-bit */ -#define R_TILEPRO_IMM8_X1 19 /* X1 pipe 8-bit */ -#define R_TILEPRO_IMM8_Y1 20 /* Y1 pipe 8-bit */ -#define R_TILEPRO_MT_IMM15_X1 21 /* X1 pipe mtspr */ -#define R_TILEPRO_MF_IMM15_X1 22 /* X1 pipe mfspr */ -#define R_TILEPRO_IMM16_X0 23 /* X0 pipe 16-bit */ -#define R_TILEPRO_IMM16_X1 24 /* X1 pipe 16-bit */ -#define R_TILEPRO_IMM16_X0_LO 25 /* X0 pipe low 16-bit */ -#define R_TILEPRO_IMM16_X1_LO 26 /* X1 pipe low 16-bit */ -#define R_TILEPRO_IMM16_X0_HI 27 /* X0 pipe high 16-bit */ -#define R_TILEPRO_IMM16_X1_HI 28 /* X1 pipe high 16-bit */ -#define R_TILEPRO_IMM16_X0_HA 29 /* X0 pipe high 16-bit, adjusted */ -#define R_TILEPRO_IMM16_X1_HA 30 /* X1 pipe high 16-bit, adjusted */ -#define R_TILEPRO_IMM16_X0_PCREL 31 /* X0 pipe PC relative 16 bit */ -#define R_TILEPRO_IMM16_X1_PCREL 32 /* X1 pipe PC relative 16 bit */ -#define R_TILEPRO_IMM16_X0_LO_PCREL 33 /* X0 pipe PC relative low 16 bit */ -#define R_TILEPRO_IMM16_X1_LO_PCREL 34 /* X1 pipe PC relative low 16 bit */ -#define R_TILEPRO_IMM16_X0_HI_PCREL 35 /* X0 pipe PC relative high 16 bit */ -#define R_TILEPRO_IMM16_X1_HI_PCREL 36 /* X1 pipe PC relative high 16 bit */ -#define R_TILEPRO_IMM16_X0_HA_PCREL 37 /* X0 pipe PC relative ha() 16 bit */ -#define R_TILEPRO_IMM16_X1_HA_PCREL 38 /* X1 pipe PC relative ha() 16 bit */ -#define R_TILEPRO_IMM16_X0_GOT 39 /* X0 pipe 16-bit GOT offset */ -#define R_TILEPRO_IMM16_X1_GOT 40 /* X1 pipe 16-bit GOT offset */ -#define R_TILEPRO_IMM16_X0_GOT_LO 41 /* X0 pipe low 16-bit GOT offset */ -#define R_TILEPRO_IMM16_X1_GOT_LO 42 /* X1 pipe low 16-bit GOT offset */ -#define R_TILEPRO_IMM16_X0_GOT_HI 43 /* X0 pipe high 16-bit GOT offset */ -#define R_TILEPRO_IMM16_X1_GOT_HI 44 /* X1 pipe high 16-bit GOT offset */ -#define R_TILEPRO_IMM16_X0_GOT_HA 45 /* X0 pipe ha() 16-bit GOT offset */ -#define R_TILEPRO_IMM16_X1_GOT_HA 46 /* X1 pipe ha() 16-bit GOT offset */ -#define R_TILEPRO_MMSTART_X0 47 /* X0 pipe mm "start" */ -#define R_TILEPRO_MMEND_X0 48 /* X0 pipe mm "end" */ -#define R_TILEPRO_MMSTART_X1 49 /* X1 pipe mm "start" */ -#define R_TILEPRO_MMEND_X1 50 /* X1 pipe mm "end" */ -#define R_TILEPRO_SHAMT_X0 51 /* X0 pipe shift amount */ -#define R_TILEPRO_SHAMT_X1 52 /* X1 pipe shift amount */ -#define R_TILEPRO_SHAMT_Y0 53 /* Y0 pipe shift amount */ -#define R_TILEPRO_SHAMT_Y1 54 /* Y1 pipe shift amount */ -#define R_TILEPRO_DEST_IMM8_X1 55 /* X1 pipe destination 8-bit */ -/* Relocs 56-59 are currently not defined. */ -#define R_TILEPRO_TLS_GD_CALL 60 /* "jal" for TLS GD */ -#define R_TILEPRO_IMM8_X0_TLS_GD_ADD 61 /* X0 pipe "addi" for TLS GD */ -#define R_TILEPRO_IMM8_X1_TLS_GD_ADD 62 /* X1 pipe "addi" for TLS GD */ -#define R_TILEPRO_IMM8_Y0_TLS_GD_ADD 63 /* Y0 pipe "addi" for TLS GD */ -#define R_TILEPRO_IMM8_Y1_TLS_GD_ADD 64 /* Y1 pipe "addi" for TLS GD */ -#define R_TILEPRO_TLS_IE_LOAD 65 /* "lw_tls" for TLS IE */ -#define R_TILEPRO_IMM16_X0_TLS_GD 66 /* X0 pipe 16-bit TLS GD offset */ -#define R_TILEPRO_IMM16_X1_TLS_GD 67 /* X1 pipe 16-bit TLS GD offset */ -#define R_TILEPRO_IMM16_X0_TLS_GD_LO 68 /* X0 pipe low 16-bit TLS GD offset */ -#define R_TILEPRO_IMM16_X1_TLS_GD_LO 69 /* X1 pipe low 16-bit TLS GD offset */ -#define R_TILEPRO_IMM16_X0_TLS_GD_HI 70 /* X0 pipe high 16-bit TLS GD offset */ -#define R_TILEPRO_IMM16_X1_TLS_GD_HI 71 /* X1 pipe high 16-bit TLS GD offset */ -#define R_TILEPRO_IMM16_X0_TLS_GD_HA 72 /* X0 pipe ha() 16-bit TLS GD offset */ -#define R_TILEPRO_IMM16_X1_TLS_GD_HA 73 /* X1 pipe ha() 16-bit TLS GD offset */ -#define R_TILEPRO_IMM16_X0_TLS_IE 74 /* X0 pipe 16-bit TLS IE offset */ -#define R_TILEPRO_IMM16_X1_TLS_IE 75 /* X1 pipe 16-bit TLS IE offset */ -#define R_TILEPRO_IMM16_X0_TLS_IE_LO 76 /* X0 pipe low 16-bit TLS IE offset */ -#define R_TILEPRO_IMM16_X1_TLS_IE_LO 77 /* X1 pipe low 16-bit TLS IE offset */ -#define R_TILEPRO_IMM16_X0_TLS_IE_HI 78 /* X0 pipe high 16-bit TLS IE offset */ -#define R_TILEPRO_IMM16_X1_TLS_IE_HI 79 /* X1 pipe high 16-bit TLS IE offset */ -#define R_TILEPRO_IMM16_X0_TLS_IE_HA 80 /* X0 pipe ha() 16-bit TLS IE offset */ -#define R_TILEPRO_IMM16_X1_TLS_IE_HA 81 /* X1 pipe ha() 16-bit TLS IE offset */ -#define R_TILEPRO_TLS_DTPMOD32 82 /* ID of module containing symbol */ -#define R_TILEPRO_TLS_DTPOFF32 83 /* Offset in TLS block */ -#define R_TILEPRO_TLS_TPOFF32 84 /* Offset in static TLS block */ -#define R_TILEPRO_IMM16_X0_TLS_LE 85 /* X0 pipe 16-bit TLS LE offset */ -#define R_TILEPRO_IMM16_X1_TLS_LE 86 /* X1 pipe 16-bit TLS LE offset */ -#define R_TILEPRO_IMM16_X0_TLS_LE_LO 87 /* X0 pipe low 16-bit TLS LE offset */ -#define R_TILEPRO_IMM16_X1_TLS_LE_LO 88 /* X1 pipe low 16-bit TLS LE offset */ -#define R_TILEPRO_IMM16_X0_TLS_LE_HI 89 /* X0 pipe high 16-bit TLS LE offset */ -#define R_TILEPRO_IMM16_X1_TLS_LE_HI 90 /* X1 pipe high 16-bit TLS LE offset */ -#define R_TILEPRO_IMM16_X0_TLS_LE_HA 91 /* X0 pipe ha() 16-bit TLS LE offset */ -#define R_TILEPRO_IMM16_X1_TLS_LE_HA 92 /* X1 pipe ha() 16-bit TLS LE offset */ - -#define R_TILEPRO_GNU_VTINHERIT 128 /* GNU C++ vtable hierarchy */ -#define R_TILEPRO_GNU_VTENTRY 129 /* GNU C++ vtable member usage */ - -#define R_TILEPRO_NUM 130 - - -/* TILE-Gx relocations. */ -#define R_TILEGX_NONE 0 /* No reloc */ -#define R_TILEGX_64 1 /* Direct 64 bit */ -#define R_TILEGX_32 2 /* Direct 32 bit */ -#define R_TILEGX_16 3 /* Direct 16 bit */ -#define R_TILEGX_8 4 /* Direct 8 bit */ -#define R_TILEGX_64_PCREL 5 /* PC relative 64 bit */ -#define R_TILEGX_32_PCREL 6 /* PC relative 32 bit */ -#define R_TILEGX_16_PCREL 7 /* PC relative 16 bit */ -#define R_TILEGX_8_PCREL 8 /* PC relative 8 bit */ -#define R_TILEGX_HW0 9 /* hword 0 16-bit */ -#define R_TILEGX_HW1 10 /* hword 1 16-bit */ -#define R_TILEGX_HW2 11 /* hword 2 16-bit */ -#define R_TILEGX_HW3 12 /* hword 3 16-bit */ -#define R_TILEGX_HW0_LAST 13 /* last hword 0 16-bit */ -#define R_TILEGX_HW1_LAST 14 /* last hword 1 16-bit */ -#define R_TILEGX_HW2_LAST 15 /* last hword 2 16-bit */ -#define R_TILEGX_COPY 16 /* Copy relocation */ -#define R_TILEGX_GLOB_DAT 17 /* Create GOT entry */ -#define R_TILEGX_JMP_SLOT 18 /* Create PLT entry */ -#define R_TILEGX_RELATIVE 19 /* Adjust by program base */ -#define R_TILEGX_BROFF_X1 20 /* X1 pipe branch offset */ -#define R_TILEGX_JUMPOFF_X1 21 /* X1 pipe jump offset */ -#define R_TILEGX_JUMPOFF_X1_PLT 22 /* X1 pipe jump offset to PLT */ -#define R_TILEGX_IMM8_X0 23 /* X0 pipe 8-bit */ -#define R_TILEGX_IMM8_Y0 24 /* Y0 pipe 8-bit */ -#define R_TILEGX_IMM8_X1 25 /* X1 pipe 8-bit */ -#define R_TILEGX_IMM8_Y1 26 /* Y1 pipe 8-bit */ -#define R_TILEGX_DEST_IMM8_X1 27 /* X1 pipe destination 8-bit */ -#define R_TILEGX_MT_IMM14_X1 28 /* X1 pipe mtspr */ -#define R_TILEGX_MF_IMM14_X1 29 /* X1 pipe mfspr */ -#define R_TILEGX_MMSTART_X0 30 /* X0 pipe mm "start" */ -#define R_TILEGX_MMEND_X0 31 /* X0 pipe mm "end" */ -#define R_TILEGX_SHAMT_X0 32 /* X0 pipe shift amount */ -#define R_TILEGX_SHAMT_X1 33 /* X1 pipe shift amount */ -#define R_TILEGX_SHAMT_Y0 34 /* Y0 pipe shift amount */ -#define R_TILEGX_SHAMT_Y1 35 /* Y1 pipe shift amount */ -#define R_TILEGX_IMM16_X0_HW0 36 /* X0 pipe hword 0 */ -#define R_TILEGX_IMM16_X1_HW0 37 /* X1 pipe hword 0 */ -#define R_TILEGX_IMM16_X0_HW1 38 /* X0 pipe hword 1 */ -#define R_TILEGX_IMM16_X1_HW1 39 /* X1 pipe hword 1 */ -#define R_TILEGX_IMM16_X0_HW2 40 /* X0 pipe hword 2 */ -#define R_TILEGX_IMM16_X1_HW2 41 /* X1 pipe hword 2 */ -#define R_TILEGX_IMM16_X0_HW3 42 /* X0 pipe hword 3 */ -#define R_TILEGX_IMM16_X1_HW3 43 /* X1 pipe hword 3 */ -#define R_TILEGX_IMM16_X0_HW0_LAST 44 /* X0 pipe last hword 0 */ -#define R_TILEGX_IMM16_X1_HW0_LAST 45 /* X1 pipe last hword 0 */ -#define R_TILEGX_IMM16_X0_HW1_LAST 46 /* X0 pipe last hword 1 */ -#define R_TILEGX_IMM16_X1_HW1_LAST 47 /* X1 pipe last hword 1 */ -#define R_TILEGX_IMM16_X0_HW2_LAST 48 /* X0 pipe last hword 2 */ -#define R_TILEGX_IMM16_X1_HW2_LAST 49 /* X1 pipe last hword 2 */ -#define R_TILEGX_IMM16_X0_HW0_PCREL 50 /* X0 pipe PC relative hword 0 */ -#define R_TILEGX_IMM16_X1_HW0_PCREL 51 /* X1 pipe PC relative hword 0 */ -#define R_TILEGX_IMM16_X0_HW1_PCREL 52 /* X0 pipe PC relative hword 1 */ -#define R_TILEGX_IMM16_X1_HW1_PCREL 53 /* X1 pipe PC relative hword 1 */ -#define R_TILEGX_IMM16_X0_HW2_PCREL 54 /* X0 pipe PC relative hword 2 */ -#define R_TILEGX_IMM16_X1_HW2_PCREL 55 /* X1 pipe PC relative hword 2 */ -#define R_TILEGX_IMM16_X0_HW3_PCREL 56 /* X0 pipe PC relative hword 3 */ -#define R_TILEGX_IMM16_X1_HW3_PCREL 57 /* X1 pipe PC relative hword 3 */ -#define R_TILEGX_IMM16_X0_HW0_LAST_PCREL 58 /* X0 pipe PC-rel last hword 0 */ -#define R_TILEGX_IMM16_X1_HW0_LAST_PCREL 59 /* X1 pipe PC-rel last hword 0 */ -#define R_TILEGX_IMM16_X0_HW1_LAST_PCREL 60 /* X0 pipe PC-rel last hword 1 */ -#define R_TILEGX_IMM16_X1_HW1_LAST_PCREL 61 /* X1 pipe PC-rel last hword 1 */ -#define R_TILEGX_IMM16_X0_HW2_LAST_PCREL 62 /* X0 pipe PC-rel last hword 2 */ -#define R_TILEGX_IMM16_X1_HW2_LAST_PCREL 63 /* X1 pipe PC-rel last hword 2 */ -#define R_TILEGX_IMM16_X0_HW0_GOT 64 /* X0 pipe hword 0 GOT offset */ -#define R_TILEGX_IMM16_X1_HW0_GOT 65 /* X1 pipe hword 0 GOT offset */ -#define R_TILEGX_IMM16_X0_HW0_PLT_PCREL 66 /* X0 pipe PC-rel PLT hword 0 */ -#define R_TILEGX_IMM16_X1_HW0_PLT_PCREL 67 /* X1 pipe PC-rel PLT hword 0 */ -#define R_TILEGX_IMM16_X0_HW1_PLT_PCREL 68 /* X0 pipe PC-rel PLT hword 1 */ -#define R_TILEGX_IMM16_X1_HW1_PLT_PCREL 69 /* X1 pipe PC-rel PLT hword 1 */ -#define R_TILEGX_IMM16_X0_HW2_PLT_PCREL 70 /* X0 pipe PC-rel PLT hword 2 */ -#define R_TILEGX_IMM16_X1_HW2_PLT_PCREL 71 /* X1 pipe PC-rel PLT hword 2 */ -#define R_TILEGX_IMM16_X0_HW0_LAST_GOT 72 /* X0 pipe last hword 0 GOT offset */ -#define R_TILEGX_IMM16_X1_HW0_LAST_GOT 73 /* X1 pipe last hword 0 GOT offset */ -#define R_TILEGX_IMM16_X0_HW1_LAST_GOT 74 /* X0 pipe last hword 1 GOT offset */ -#define R_TILEGX_IMM16_X1_HW1_LAST_GOT 75 /* X1 pipe last hword 1 GOT offset */ -#define R_TILEGX_IMM16_X0_HW3_PLT_PCREL 76 /* X0 pipe PC-rel PLT hword 3 */ -#define R_TILEGX_IMM16_X1_HW3_PLT_PCREL 77 /* X1 pipe PC-rel PLT hword 3 */ -#define R_TILEGX_IMM16_X0_HW0_TLS_GD 78 /* X0 pipe hword 0 TLS GD offset */ -#define R_TILEGX_IMM16_X1_HW0_TLS_GD 79 /* X1 pipe hword 0 TLS GD offset */ -#define R_TILEGX_IMM16_X0_HW0_TLS_LE 80 /* X0 pipe hword 0 TLS LE offset */ -#define R_TILEGX_IMM16_X1_HW0_TLS_LE 81 /* X1 pipe hword 0 TLS LE offset */ -#define R_TILEGX_IMM16_X0_HW0_LAST_TLS_LE 82 /* X0 pipe last hword 0 LE off */ -#define R_TILEGX_IMM16_X1_HW0_LAST_TLS_LE 83 /* X1 pipe last hword 0 LE off */ -#define R_TILEGX_IMM16_X0_HW1_LAST_TLS_LE 84 /* X0 pipe last hword 1 LE off */ -#define R_TILEGX_IMM16_X1_HW1_LAST_TLS_LE 85 /* X1 pipe last hword 1 LE off */ -#define R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD 86 /* X0 pipe last hword 0 GD off */ -#define R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD 87 /* X1 pipe last hword 0 GD off */ -#define R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD 88 /* X0 pipe last hword 1 GD off */ -#define R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD 89 /* X1 pipe last hword 1 GD off */ -/* Relocs 90-91 are currently not defined. */ -#define R_TILEGX_IMM16_X0_HW0_TLS_IE 92 /* X0 pipe hword 0 TLS IE offset */ -#define R_TILEGX_IMM16_X1_HW0_TLS_IE 93 /* X1 pipe hword 0 TLS IE offset */ -#define R_TILEGX_IMM16_X0_HW0_LAST_PLT_PCREL 94 /* X0 pipe PC-rel PLT last hword 0 */ -#define R_TILEGX_IMM16_X1_HW0_LAST_PLT_PCREL 95 /* X1 pipe PC-rel PLT last hword 0 */ -#define R_TILEGX_IMM16_X0_HW1_LAST_PLT_PCREL 96 /* X0 pipe PC-rel PLT last hword 1 */ -#define R_TILEGX_IMM16_X1_HW1_LAST_PLT_PCREL 97 /* X1 pipe PC-rel PLT last hword 1 */ -#define R_TILEGX_IMM16_X0_HW2_LAST_PLT_PCREL 98 /* X0 pipe PC-rel PLT last hword 2 */ -#define R_TILEGX_IMM16_X1_HW2_LAST_PLT_PCREL 99 /* X1 pipe PC-rel PLT last hword 2 */ -#define R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE 100 /* X0 pipe last hword 0 IE off */ -#define R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE 101 /* X1 pipe last hword 0 IE off */ -#define R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE 102 /* X0 pipe last hword 1 IE off */ -#define R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE 103 /* X1 pipe last hword 1 IE off */ -/* Relocs 104-105 are currently not defined. */ -#define R_TILEGX_TLS_DTPMOD64 106 /* 64-bit ID of symbol's module */ -#define R_TILEGX_TLS_DTPOFF64 107 /* 64-bit offset in TLS block */ -#define R_TILEGX_TLS_TPOFF64 108 /* 64-bit offset in static TLS block */ -#define R_TILEGX_TLS_DTPMOD32 109 /* 32-bit ID of symbol's module */ -#define R_TILEGX_TLS_DTPOFF32 110 /* 32-bit offset in TLS block */ -#define R_TILEGX_TLS_TPOFF32 111 /* 32-bit offset in static TLS block */ -#define R_TILEGX_TLS_GD_CALL 112 /* "jal" for TLS GD */ -#define R_TILEGX_IMM8_X0_TLS_GD_ADD 113 /* X0 pipe "addi" for TLS GD */ -#define R_TILEGX_IMM8_X1_TLS_GD_ADD 114 /* X1 pipe "addi" for TLS GD */ -#define R_TILEGX_IMM8_Y0_TLS_GD_ADD 115 /* Y0 pipe "addi" for TLS GD */ -#define R_TILEGX_IMM8_Y1_TLS_GD_ADD 116 /* Y1 pipe "addi" for TLS GD */ -#define R_TILEGX_TLS_IE_LOAD 117 /* "ld_tls" for TLS IE */ -#define R_TILEGX_IMM8_X0_TLS_ADD 118 /* X0 pipe "addi" for TLS GD/IE */ -#define R_TILEGX_IMM8_X1_TLS_ADD 119 /* X1 pipe "addi" for TLS GD/IE */ -#define R_TILEGX_IMM8_Y0_TLS_ADD 120 /* Y0 pipe "addi" for TLS GD/IE */ -#define R_TILEGX_IMM8_Y1_TLS_ADD 121 /* Y1 pipe "addi" for TLS GD/IE */ - -#define R_TILEGX_GNU_VTINHERIT 128 /* GNU C++ vtable hierarchy */ -#define R_TILEGX_GNU_VTENTRY 129 /* GNU C++ vtable member usage */ - -#define R_TILEGX_NUM 130 - -/* RISC-V ELF Flags */ -#define EF_RISCV_RVC 0x0001 -#define EF_RISCV_FLOAT_ABI 0x0006 -#define EF_RISCV_FLOAT_ABI_SOFT 0x0000 -#define EF_RISCV_FLOAT_ABI_SINGLE 0x0002 -#define EF_RISCV_FLOAT_ABI_DOUBLE 0x0004 -#define EF_RISCV_FLOAT_ABI_QUAD 0x0006 - -/* RISC-V relocations. */ -#define R_RISCV_NONE 0 -#define R_RISCV_32 1 -#define R_RISCV_64 2 -#define R_RISCV_RELATIVE 3 -#define R_RISCV_COPY 4 -#define R_RISCV_JUMP_SLOT 5 -#define R_RISCV_TLS_DTPMOD32 6 -#define R_RISCV_TLS_DTPMOD64 7 -#define R_RISCV_TLS_DTPREL32 8 -#define R_RISCV_TLS_DTPREL64 9 -#define R_RISCV_TLS_TPREL32 10 -#define R_RISCV_TLS_TPREL64 11 -#define R_RISCV_BRANCH 16 -#define R_RISCV_JAL 17 -#define R_RISCV_CALL 18 -#define R_RISCV_CALL_PLT 19 -#define R_RISCV_GOT_HI20 20 -#define R_RISCV_TLS_GOT_HI20 21 -#define R_RISCV_TLS_GD_HI20 22 -#define R_RISCV_PCREL_HI20 23 -#define R_RISCV_PCREL_LO12_I 24 -#define R_RISCV_PCREL_LO12_S 25 -#define R_RISCV_HI20 26 -#define R_RISCV_LO12_I 27 -#define R_RISCV_LO12_S 28 -#define R_RISCV_TPREL_HI20 29 -#define R_RISCV_TPREL_LO12_I 30 -#define R_RISCV_TPREL_LO12_S 31 -#define R_RISCV_TPREL_ADD 32 -#define R_RISCV_ADD8 33 -#define R_RISCV_ADD16 34 -#define R_RISCV_ADD32 35 -#define R_RISCV_ADD64 36 -#define R_RISCV_SUB8 37 -#define R_RISCV_SUB16 38 -#define R_RISCV_SUB32 39 -#define R_RISCV_SUB64 40 -#define R_RISCV_GNU_VTINHERIT 41 -#define R_RISCV_GNU_VTENTRY 42 -#define R_RISCV_ALIGN 43 -#define R_RISCV_RVC_BRANCH 44 -#define R_RISCV_RVC_JUMP 45 -#define R_RISCV_RVC_LUI 46 -#define R_RISCV_GPREL_I 47 -#define R_RISCV_GPREL_S 48 -#define R_RISCV_TPREL_I 49 -#define R_RISCV_TPREL_S 50 -#define R_RISCV_RELAX 51 -#define R_RISCV_SUB6 52 -#define R_RISCV_SET6 53 -#define R_RISCV_SET8 54 -#define R_RISCV_SET16 55 -#define R_RISCV_SET32 56 -#define R_RISCV_32_PCREL 57 - -#define R_RISCV_NUM 58 - - -#endif /* elf.h */ diff --git a/05/tcc-final/examples/ex1.c b/05/tcc-final/examples/ex1.c deleted file mode 100755 index 3d2a3e1..0000000 --- a/05/tcc-final/examples/ex1.c +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/local/bin/tcc -run -#include - -int main() -{ - printf("Hello World\n"); - return 0; -} diff --git a/05/tcc-final/examples/ex2.c b/05/tcc-final/examples/ex2.c deleted file mode 100644 index d415e39..0000000 --- a/05/tcc-final/examples/ex2.c +++ /dev/null @@ -1,98 +0,0 @@ -#include -#include - -#define N 20 - -int nb_num; -int tab[N]; -int stack_ptr; -int stack_op[N]; -int stack_res[60]; -int result; - -int find(int n, int i1, int a, int b, int op) -{ - int i, j; - int c; - - if (stack_ptr >= 0) { - stack_res[3*stack_ptr] = a; - stack_op[stack_ptr] = op; - stack_res[3*stack_ptr+1] = b; - stack_res[3*stack_ptr+2] = n; - if (n == result) - return 1; - tab[i1] = n; - } - - for(i=0;i - -int fib(n) -{ - if (n <= 2) - return 1; - else - return fib(n-1) + fib(n-2); -} - -int main(int argc, char **argv) -{ - int n; - if (argc < 2) { - printf("usage: fib n\n" - "Compute nth Fibonacci number\n"); - return 1; - } - - n = atoi(argv[1]); - printf("fib(%d) = %d\n", n, fib(n, 2)); - return 0; -} diff --git a/05/tcc-final/examples/ex4.c b/05/tcc-final/examples/ex4.c deleted file mode 100755 index f92c0da..0000000 --- a/05/tcc-final/examples/ex4.c +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/local/bin/tcc -run -L/usr/X11R6/lib -lX11 -#include -#include -#include - -/* Yes, TCC can use X11 too ! */ - -int main(int argc, char **argv) -{ - Display *display; - Screen *screen; - - display = XOpenDisplay(""); - if (!display) { - fprintf(stderr, "Could not open X11 display\n"); - exit(1); - } - printf("X11 display opened.\n"); - screen = XScreenOfDisplay(display, 0); - printf("width = %d\nheight = %d\ndepth = %d\n", - screen->width, - screen->height, - screen->root_depth); - XCloseDisplay(display); - return 0; -} diff --git a/05/tcc-final/examples/ex5.c b/05/tcc-final/examples/ex5.c deleted file mode 100644 index 156425e..0000000 --- a/05/tcc-final/examples/ex5.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include - -int main() -{ - printf("Hello World\n"); - return 0; -} diff --git a/05/tcc-final/i386-asm.c b/05/tcc-final/i386-asm.c deleted file mode 100644 index ebdfe03..0000000 --- a/05/tcc-final/i386-asm.c +++ /dev/null @@ -1,1727 +0,0 @@ -/* - * i386 specific functions for TCC assembler - * - * Copyright (c) 2001, 2002 Fabrice Bellard - * Copyright (c) 2009 Frédéric Feret (x86_64 support) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#define USING_GLOBALS -#include "tcc.h" - -#define MAX_OPERANDS 3 - -#define TOK_ASM_first TOK_ASM_clc -#define TOK_ASM_last TOK_ASM_emms -#define TOK_ASM_alllast TOK_ASM_subps - -#define OPC_B 0x01 /* only used with OPC_WL */ -#define OPC_WL 0x02 /* accepts w, l or no suffix */ -#define OPC_BWL (OPC_B | OPC_WL) /* accepts b, w, l or no suffix */ -#define OPC_REG 0x04 /* register is added to opcode */ -#define OPC_MODRM 0x08 /* modrm encoding */ - -#define OPCT_MASK 0x70 -#define OPC_FWAIT 0x10 /* add fwait opcode */ -#define OPC_SHIFT 0x20 /* shift opcodes */ -#define OPC_ARITH 0x30 /* arithmetic opcodes */ -#define OPC_FARITH 0x40 /* FPU arithmetic opcodes */ -#define OPC_TEST 0x50 /* test opcodes */ -#define OPCT_IS(v,i) (((v) & OPCT_MASK) == (i)) - -#define OPC_0F 0x100 /* Is secondary map (0x0f prefix) */ -#define OPC_48 0x200 /* Always has REX prefix */ -#ifdef TCC_TARGET_X86_64 -# define OPC_WLQ 0x1000 /* accepts w, l, q or no suffix */ -# define OPC_BWLQ (OPC_B | OPC_WLQ) /* accepts b, w, l, q or no suffix */ -# define OPC_WLX OPC_WLQ -# define OPC_BWLX OPC_BWLQ -#else -# define OPC_WLX OPC_WL -# define OPC_BWLX OPC_BWL -#endif - -#define OPC_GROUP_SHIFT 13 - -/* in order to compress the operand type, we use specific operands and - we or only with EA */ -enum { - OPT_REG8=0, /* warning: value is hardcoded from TOK_ASM_xxx */ - OPT_REG16, /* warning: value is hardcoded from TOK_ASM_xxx */ - OPT_REG32, /* warning: value is hardcoded from TOK_ASM_xxx */ -#ifdef TCC_TARGET_X86_64 - OPT_REG64, /* warning: value is hardcoded from TOK_ASM_xxx */ -#endif - OPT_MMX, /* warning: value is hardcoded from TOK_ASM_xxx */ - OPT_SSE, /* warning: value is hardcoded from TOK_ASM_xxx */ - OPT_CR, /* warning: value is hardcoded from TOK_ASM_xxx */ - OPT_TR, /* warning: value is hardcoded from TOK_ASM_xxx */ - OPT_DB, /* warning: value is hardcoded from TOK_ASM_xxx */ - OPT_SEG, - OPT_ST, -#ifdef TCC_TARGET_X86_64 - OPT_REG8_LOW, /* %spl,%bpl,%sil,%dil, encoded like ah,ch,dh,bh, but - with REX prefix, not used in insn templates */ -#endif - OPT_IM8, - OPT_IM8S, - OPT_IM16, - OPT_IM32, -#ifdef TCC_TARGET_X86_64 - OPT_IM64, -#endif - OPT_EAX, /* %al, %ax, %eax or %rax register */ - OPT_ST0, /* %st(0) register */ - OPT_CL, /* %cl register */ - OPT_DX, /* %dx register */ - OPT_ADDR, /* OP_EA with only offset */ - OPT_INDIR, /* *(expr) */ - /* composite types */ - OPT_COMPOSITE_FIRST, - OPT_IM, /* IM8 | IM16 | IM32 */ - OPT_REG, /* REG8 | REG16 | REG32 | REG64 */ - OPT_REGW, /* REG16 | REG32 | REG64 */ - OPT_IMW, /* IM16 | IM32 */ - OPT_MMXSSE, /* MMX | SSE */ - OPT_DISP, /* Like OPT_ADDR, but emitted as displacement (for jumps) */ - OPT_DISP8, /* Like OPT_ADDR, but only 8bit (short jumps) */ - /* can be ored with any OPT_xxx */ - OPT_EA = 0x80 -}; - -#define OP_REG8 (1 << OPT_REG8) -#define OP_REG16 (1 << OPT_REG16) -#define OP_REG32 (1 << OPT_REG32) -#define OP_MMX (1 << OPT_MMX) -#define OP_SSE (1 << OPT_SSE) -#define OP_CR (1 << OPT_CR) -#define OP_TR (1 << OPT_TR) -#define OP_DB (1 << OPT_DB) -#define OP_SEG (1 << OPT_SEG) -#define OP_ST (1 << OPT_ST) -#define OP_IM8 (1 << OPT_IM8) -#define OP_IM8S (1 << OPT_IM8S) -#define OP_IM16 (1 << OPT_IM16) -#define OP_IM32 (1 << OPT_IM32) -#define OP_EAX (1 << OPT_EAX) -#define OP_ST0 (1 << OPT_ST0) -#define OP_CL (1 << OPT_CL) -#define OP_DX (1 << OPT_DX) -#define OP_ADDR (1 << OPT_ADDR) -#define OP_INDIR (1 << OPT_INDIR) -#ifdef TCC_TARGET_X86_64 -# define OP_REG64 (1 << OPT_REG64) -# define OP_REG8_LOW (1 << OPT_REG8_LOW) -# define OP_IM64 (1 << OPT_IM64) -# define OP_EA32 (OP_EA << 1) -#else -# define OP_REG64 0 -# define OP_REG8_LOW 0 -# define OP_IM64 0 -# define OP_EA32 0 -#endif - -#define OP_EA 0x40000000 -#define OP_REG (OP_REG8 | OP_REG16 | OP_REG32 | OP_REG64) - -#ifdef TCC_TARGET_X86_64 -# define TREG_XAX TREG_RAX -# define TREG_XCX TREG_RCX -# define TREG_XDX TREG_RDX -#else -# define TREG_XAX TREG_EAX -# define TREG_XCX TREG_ECX -# define TREG_XDX TREG_EDX -#endif - -typedef struct ASMInstr { - uint16_t sym; - uint16_t opcode; - uint16_t instr_type; - uint8_t nb_ops; - uint8_t op_type[MAX_OPERANDS]; /* see OP_xxx */ -} ASMInstr; - -typedef struct Operand { - uint32_t type; - int8_t reg; /* register, -1 if none */ - int8_t reg2; /* second register, -1 if none */ - uint8_t shift; - ExprValue e; -} Operand; - -static const uint8_t reg_to_size[9] = { -/* - [OP_REG8] = 0, - [OP_REG16] = 1, - [OP_REG32] = 2, -#ifdef TCC_TARGET_X86_64 - [OP_REG64] = 3, -#endif -*/ - 0, 0, 1, 0, 2, 0, 0, 0, 3 -}; - -#define NB_TEST_OPCODES 30 - -static const uint8_t test_bits[NB_TEST_OPCODES] = { - 0x00, /* o */ - 0x01, /* no */ - 0x02, /* b */ - 0x02, /* c */ - 0x02, /* nae */ - 0x03, /* nb */ - 0x03, /* nc */ - 0x03, /* ae */ - 0x04, /* e */ - 0x04, /* z */ - 0x05, /* ne */ - 0x05, /* nz */ - 0x06, /* be */ - 0x06, /* na */ - 0x07, /* nbe */ - 0x07, /* a */ - 0x08, /* s */ - 0x09, /* ns */ - 0x0a, /* p */ - 0x0a, /* pe */ - 0x0b, /* np */ - 0x0b, /* po */ - 0x0c, /* l */ - 0x0c, /* nge */ - 0x0d, /* nl */ - 0x0d, /* ge */ - 0x0e, /* le */ - 0x0e, /* ng */ - 0x0f, /* nle */ - 0x0f, /* g */ -}; - -static const uint8_t segment_prefixes[] = { - 0x26, /* es */ - 0x2e, /* cs */ - 0x36, /* ss */ - 0x3e, /* ds */ - 0x64, /* fs */ - 0x65 /* gs */ -}; - -static const ASMInstr asm_instrs[] = { -#define ALT(x) x -/* This removes a 0x0f in the second byte */ -#define O(o) ((uint64_t) ((((o) & 0xff00) == 0x0f00) ? ((((o) >> 8) & ~0xff) | ((o) & 0xff)) : (o))) -/* This constructs instr_type from opcode, type and group. */ -#define T(o,i,g) ((i) | ((g) << OPC_GROUP_SHIFT) | ((((o) & 0xff00) == 0x0f00) ? OPC_0F : 0)) -#define DEF_ASM_OP0(name, opcode) -#define DEF_ASM_OP0L(name, opcode, group, instr_type) { TOK_ASM_ ## name, O(opcode), T(opcode, instr_type, group), 0, { 0 } }, -#define DEF_ASM_OP1(name, opcode, group, instr_type, op0) { TOK_ASM_ ## name, O(opcode), T(opcode, instr_type, group), 1, { op0 }}, -#define DEF_ASM_OP2(name, opcode, group, instr_type, op0, op1) { TOK_ASM_ ## name, O(opcode), T(opcode, instr_type, group), 2, { op0, op1 }}, -#define DEF_ASM_OP3(name, opcode, group, instr_type, op0, op1, op2) { TOK_ASM_ ## name, O(opcode), T(opcode, instr_type, group), 3, { op0, op1, op2 }}, -#ifdef TCC_TARGET_X86_64 -# include "x86_64-asm.h" -#else -# include "i386-asm.h" -#endif - /* last operation */ - { 0, }, -}; - -static const uint16_t op0_codes[] = { -#define ALT(x) -#define DEF_ASM_OP0(x, opcode) opcode, -#define DEF_ASM_OP0L(name, opcode, group, instr_type) -#define DEF_ASM_OP1(name, opcode, group, instr_type, op0) -#define DEF_ASM_OP2(name, opcode, group, instr_type, op0, op1) -#define DEF_ASM_OP3(name, opcode, group, instr_type, op0, op1, op2) -#ifdef TCC_TARGET_X86_64 -# include "x86_64-asm.h" -#else -# include "i386-asm.h" -#endif -}; - -static inline int get_reg_shift(TCCState *s1) -{ - int shift, v; - v = asm_int_expr(s1); - switch(v) { - case 1: - shift = 0; - break; - case 2: - shift = 1; - break; - case 4: - shift = 2; - break; - case 8: - shift = 3; - break; - default: - expect("1, 2, 4 or 8 constant"); - shift = 0; - break; - } - return shift; -} - -#ifdef TCC_TARGET_X86_64 -static int asm_parse_numeric_reg(int t, unsigned int *type) -{ - int reg = -1; - if (t >= TOK_IDENT && t < tok_ident) { - const char *s = table_ident[t - TOK_IDENT]->str; - char c; - *type = OP_REG64; - if (*s == 'c') { - s++; - *type = OP_CR; - } - if (*s++ != 'r') - return -1; - /* Don't allow leading '0'. */ - if ((c = *s++) >= '1' && c <= '9') - reg = c - '0'; - else - return -1; - if ((c = *s) >= '0' && c <= '5') - s++, reg = reg * 10 + c - '0'; - if (reg > 15) - return -1; - if ((c = *s) == 0) - ; - else if (*type != OP_REG64) - return -1; - else if (c == 'b' && !s[1]) - *type = OP_REG8; - else if (c == 'w' && !s[1]) - *type = OP_REG16; - else if (c == 'd' && !s[1]) - *type = OP_REG32; - else - return -1; - } - return reg; -} -#endif - -static int asm_parse_reg(unsigned int *type) -{ - int reg = 0; - *type = 0; - if (tok != '%') - goto error_32; - next(); - if (tok >= TOK_ASM_eax && tok <= TOK_ASM_edi) { - reg = tok - TOK_ASM_eax; - *type = OP_REG32; -#ifdef TCC_TARGET_X86_64 - } else if (tok >= TOK_ASM_rax && tok <= TOK_ASM_rdi) { - reg = tok - TOK_ASM_rax; - *type = OP_REG64; - } else if (tok == TOK_ASM_rip) { - reg = -2; /* Probably should use different escape code. */ - *type = OP_REG64; - } else if ((reg = asm_parse_numeric_reg(tok, type)) >= 0 - && (*type == OP_REG32 || *type == OP_REG64)) { - ; -#endif - } else { - error_32: - expect("register"); - } - next(); - return reg; -} - -static void parse_operand(TCCState *s1, Operand *op) -{ - ExprValue e; - int reg, indir; - const char *p; - - indir = 0; - if (tok == '*') { - next(); - indir = OP_INDIR; - } - - if (tok == '%') { - next(); - if (tok >= TOK_ASM_al && tok <= TOK_ASM_db7) { - reg = tok - TOK_ASM_al; - op->type = 1 << (reg >> 3); /* WARNING: do not change constant order */ - op->reg = reg & 7; - if ((op->type & OP_REG) && op->reg == TREG_XAX) - op->type |= OP_EAX; - else if (op->type == OP_REG8 && op->reg == TREG_XCX) - op->type |= OP_CL; - else if (op->type == OP_REG16 && op->reg == TREG_XDX) - op->type |= OP_DX; - } else if (tok >= TOK_ASM_dr0 && tok <= TOK_ASM_dr7) { - op->type = OP_DB; - op->reg = tok - TOK_ASM_dr0; - } else if (tok >= TOK_ASM_es && tok <= TOK_ASM_gs) { - op->type = OP_SEG; - op->reg = tok - TOK_ASM_es; - } else if (tok == TOK_ASM_st) { - op->type = OP_ST; - op->reg = 0; - next(); - if (tok == '(') { - next(); - if (tok != TOK_PPNUM) - goto reg_error; - p = tokc.str.data; - reg = p[0] - '0'; - if ((unsigned)reg >= 8 || p[1] != '\0') - goto reg_error; - op->reg = reg; - next(); - skip(')'); - } - if (op->reg == 0) - op->type |= OP_ST0; - goto no_skip; -#ifdef TCC_TARGET_X86_64 - } else if (tok >= TOK_ASM_spl && tok <= TOK_ASM_dil) { - op->type = OP_REG8 | OP_REG8_LOW; - op->reg = 4 + tok - TOK_ASM_spl; - } else if ((op->reg = asm_parse_numeric_reg(tok, &op->type)) >= 0) { - ; -#endif - } else { - reg_error: - tcc_error("unknown register %%%s", get_tok_str(tok, &tokc)); - } - next(); - no_skip: ; - } else if (tok == '$') { - /* constant value */ - next(); - asm_expr(s1, &e); - op->type = OP_IM32; - op->e = e; - if (!op->e.sym) { - if (op->e.v == (uint8_t)op->e.v) - op->type |= OP_IM8; - if (op->e.v == (int8_t)op->e.v) - op->type |= OP_IM8S; - if (op->e.v == (uint16_t)op->e.v) - op->type |= OP_IM16; -#ifdef TCC_TARGET_X86_64 - if (op->e.v != (int32_t)op->e.v && op->e.v != (uint32_t)op->e.v) - op->type = OP_IM64; -#endif - } - } else { - /* address(reg,reg2,shift) with all variants */ - op->type = OP_EA; - op->reg = -1; - op->reg2 = -1; - op->shift = 0; - if (tok != '(') { - asm_expr(s1, &e); - op->e = e; - } else { - next(); - if (tok == '%') { - unget_tok('('); - op->e.v = 0; - op->e.sym = NULL; - } else { - /* bracketed offset expression */ - asm_expr(s1, &e); - if (tok != ')') - expect(")"); - next(); - op->e.v = e.v; - op->e.sym = e.sym; - } - op->e.pcrel = 0; - } - if (tok == '(') { - unsigned int type = 0; - next(); - if (tok != ',') { - op->reg = asm_parse_reg(&type); - } - if (tok == ',') { - next(); - if (tok != ',') { - op->reg2 = asm_parse_reg(&type); - } - if (tok == ',') { - next(); - op->shift = get_reg_shift(s1); - } - } - if (type & OP_REG32) - op->type |= OP_EA32; - skip(')'); - } - if (op->reg == -1 && op->reg2 == -1) - op->type |= OP_ADDR; - } - op->type |= indir; -} - -/* XXX: unify with C code output ? */ -ST_FUNC void gen_expr32(ExprValue *pe) -{ - if (pe->pcrel) - /* If PC-relative, always set VT_SYM, even without symbol, - so as to force a relocation to be emitted. */ - gen_addrpc32(VT_SYM, pe->sym, pe->v); - else - gen_addr32(pe->sym ? VT_SYM : 0, pe->sym, pe->v); -} - -#ifdef TCC_TARGET_X86_64 -ST_FUNC void gen_expr64(ExprValue *pe) -{ - gen_addr64(pe->sym ? VT_SYM : 0, pe->sym, pe->v); -} -#endif - -/* XXX: unify with C code output ? */ -static void gen_disp32(ExprValue *pe) -{ - Sym *sym = pe->sym; - ElfSym *esym = elfsym(sym); - if (esym && esym->st_shndx == cur_text_section->sh_num) { - /* same section: we can output an absolute value. Note - that the TCC compiler behaves differently here because - it always outputs a relocation to ease (future) code - elimination in the linker */ - gen_le32(pe->v + esym->st_value - ind - 4); - } else { - if (sym && sym->type.t == VT_VOID) { - sym->type.t = VT_FUNC; - sym->type.ref = NULL; - } - gen_addrpc32(VT_SYM, sym, pe->v); - } -} - -/* generate the modrm operand */ -static inline int asm_modrm(int reg, Operand *op) -{ - int mod, reg1, reg2, sib_reg1; - - if (op->type & (OP_REG | OP_MMX | OP_SSE)) { - g(0xc0 + (reg << 3) + op->reg); - } else if (op->reg == -1 && op->reg2 == -1) { - /* displacement only */ -#ifdef TCC_TARGET_X86_64 - g(0x04 + (reg << 3)); - g(0x25); -#else - g(0x05 + (reg << 3)); -#endif - gen_expr32(&op->e); -#ifdef TCC_TARGET_X86_64 - } else if (op->reg == -2) { - ExprValue *pe = &op->e; - g(0x05 + (reg << 3)); - gen_addrpc32(pe->sym ? VT_SYM : 0, pe->sym, pe->v); - return ind; -#endif - } else { - sib_reg1 = op->reg; - /* fist compute displacement encoding */ - if (sib_reg1 == -1) { - sib_reg1 = 5; - mod = 0x00; - } else if (op->e.v == 0 && !op->e.sym && op->reg != 5) { - mod = 0x00; - } else if (op->e.v == (int8_t)op->e.v && !op->e.sym) { - mod = 0x40; - } else { - mod = 0x80; - } - /* compute if sib byte needed */ - reg1 = op->reg; - if (op->reg2 != -1) - reg1 = 4; - g(mod + (reg << 3) + reg1); - if (reg1 == 4) { - /* add sib byte */ - reg2 = op->reg2; - if (reg2 == -1) - reg2 = 4; /* indicate no index */ - g((op->shift << 6) + (reg2 << 3) + sib_reg1); - } - /* add offset */ - if (mod == 0x40) { - g(op->e.v); - } else if (mod == 0x80 || op->reg == -1) { - gen_expr32(&op->e); - } - } - return 0; -} - -#ifdef TCC_TARGET_X86_64 -#define REX_W 0x48 -#define REX_R 0x44 -#define REX_X 0x42 -#define REX_B 0x41 - -static void asm_rex(int width64, Operand *ops, int nb_ops, int *op_type, - int regi, int rmi) -{ - unsigned char rex = width64 ? 0x48 : 0; - int saw_high_8bit = 0; - int i; - if (rmi == -1) { - /* No mod/rm byte, but we might have a register op nevertheless - (we will add it to the opcode later). */ - for(i = 0; i < nb_ops; i++) { - if (op_type[i] & (OP_REG | OP_ST)) { - if (ops[i].reg >= 8) { - rex |= REX_B; - ops[i].reg -= 8; - } else if (ops[i].type & OP_REG8_LOW) - rex |= 0x40; - else if (ops[i].type & OP_REG8 && ops[i].reg >= 4) - /* An 8 bit reg >= 4 without REG8 is ah/ch/dh/bh */ - saw_high_8bit = ops[i].reg; - break; - } - } - } else { - if (regi != -1) { - if (ops[regi].reg >= 8) { - rex |= REX_R; - ops[regi].reg -= 8; - } else if (ops[regi].type & OP_REG8_LOW) - rex |= 0x40; - else if (ops[regi].type & OP_REG8 && ops[regi].reg >= 4) - /* An 8 bit reg >= 4 without REG8 is ah/ch/dh/bh */ - saw_high_8bit = ops[regi].reg; - } - if (ops[rmi].type & (OP_REG | OP_MMX | OP_SSE | OP_CR | OP_EA)) { - if (ops[rmi].reg >= 8) { - rex |= REX_B; - ops[rmi].reg -= 8; - } else if (ops[rmi].type & OP_REG8_LOW) - rex |= 0x40; - else if (ops[rmi].type & OP_REG8 && ops[rmi].reg >= 4) - /* An 8 bit reg >= 4 without REG8 is ah/ch/dh/bh */ - saw_high_8bit = ops[rmi].reg; - } - if (ops[rmi].type & OP_EA && ops[rmi].reg2 >= 8) { - rex |= REX_X; - ops[rmi].reg2 -= 8; - } - } - if (rex) { - if (saw_high_8bit) - tcc_error("can't encode register %%%ch when REX prefix is required", - "acdb"[saw_high_8bit-4]); - g(rex); - } -} -#endif - - -static void maybe_print_stats (void) -{ - static int already; - - if (0 && !already) - /* print stats about opcodes */ - { - const struct ASMInstr *pa; - int freq[4]; - int op_vals[500]; - int nb_op_vals, i, j; - - already = 1; - nb_op_vals = 0; - memset(freq, 0, sizeof(freq)); - for(pa = asm_instrs; pa->sym != 0; pa++) { - freq[pa->nb_ops]++; - //for(i=0;inb_ops;i++) { - for(j=0;jop_type[i] == op_vals[j]) - if (pa->instr_type == op_vals[j]) - goto found; - } - //op_vals[nb_op_vals++] = pa->op_type[i]; - op_vals[nb_op_vals++] = pa->instr_type; - found: ; - //} - } - for(i=0;i= TOK_ASM_wait && opcode <= TOK_ASM_repnz) - unget_tok(';'); - - /* get operands */ - pop = ops; - nb_ops = 0; - seg_prefix = 0; - alltypes = 0; - for(;;) { - if (tok == ';' || tok == TOK_LINEFEED) - break; - if (nb_ops >= MAX_OPERANDS) { - tcc_error("incorrect number of operands"); - } - parse_operand(s1, pop); - if (tok == ':') { - if (pop->type != OP_SEG || seg_prefix) - tcc_error("incorrect prefix"); - seg_prefix = segment_prefixes[pop->reg]; - next(); - parse_operand(s1, pop); - if (!(pop->type & OP_EA)) { - tcc_error("segment prefix must be followed by memory reference"); - } - } - pop++; - nb_ops++; - if (tok != ',') - break; - next(); - } - - s = 0; /* avoid warning */ - -again: - /* optimize matching by using a lookup table (no hashing is needed - !) */ - for(pa = asm_instrs; pa->sym != 0; pa++) { - int it = pa->instr_type & OPCT_MASK; - s = 0; - if (it == OPC_FARITH) { - v = opcode - pa->sym; - if (!((unsigned)v < 8 * 6 && (v % 6) == 0)) - continue; - } else if (it == OPC_ARITH) { - if (!(opcode >= pa->sym && opcode < pa->sym + 8*NBWLX)) - continue; - s = (opcode - pa->sym) % NBWLX; - if ((pa->instr_type & OPC_BWLX) == OPC_WLX) - { - /* We need to reject the xxxb opcodes that we accepted above. - Note that pa->sym for WLX opcodes is the 'w' token, - to get the 'b' token subtract one. */ - if (((opcode - pa->sym + 1) % NBWLX) == 0) - continue; - s++; - } - } else if (it == OPC_SHIFT) { - if (!(opcode >= pa->sym && opcode < pa->sym + 7*NBWLX)) - continue; - s = (opcode - pa->sym) % NBWLX; - } else if (it == OPC_TEST) { - if (!(opcode >= pa->sym && opcode < pa->sym + NB_TEST_OPCODES)) - continue; - /* cmovxx is a test opcode but accepts multiple sizes. - The suffixes aren't encoded in the table, instead we - simply force size autodetection always and deal with suffixed - variants below when we don't find e.g. "cmovzl". */ - if (pa->instr_type & OPC_WLX) - s = NBWLX - 1; - } else if (pa->instr_type & OPC_B) { -#ifdef TCC_TARGET_X86_64 - /* Some instructions don't have the full size but only - bwl form. insb e.g. */ - if ((pa->instr_type & OPC_WLQ) != OPC_WLQ - && !(opcode >= pa->sym && opcode < pa->sym + NBWLX-1)) - continue; -#endif - if (!(opcode >= pa->sym && opcode < pa->sym + NBWLX)) - continue; - s = opcode - pa->sym; - } else if (pa->instr_type & OPC_WLX) { - if (!(opcode >= pa->sym && opcode < pa->sym + NBWLX-1)) - continue; - s = opcode - pa->sym + 1; - } else { - if (pa->sym != opcode) - continue; - } - if (pa->nb_ops != nb_ops) - continue; -#ifdef TCC_TARGET_X86_64 - /* Special case for moves. Selecting the IM64->REG64 form - should only be done if we really have an >32bit imm64, and that - is hardcoded. Ignore it here. */ - if (pa->opcode == 0xb0 && ops[0].type != OP_IM64 - && (ops[1].type & OP_REG) == OP_REG64 - && !(pa->instr_type & OPC_0F)) - continue; -#endif - /* now decode and check each operand */ - alltypes = 0; - for(i = 0; i < nb_ops; i++) { - int op1, op2; - op1 = pa->op_type[i]; - op2 = op1 & 0x1f; - switch(op2) { - case OPT_IM: - v = OP_IM8 | OP_IM16 | OP_IM32; - break; - case OPT_REG: - v = OP_REG8 | OP_REG16 | OP_REG32 | OP_REG64; - break; - case OPT_REGW: - v = OP_REG16 | OP_REG32 | OP_REG64; - break; - case OPT_IMW: - v = OP_IM16 | OP_IM32; - break; - case OPT_MMXSSE: - v = OP_MMX | OP_SSE; - break; - case OPT_DISP: - case OPT_DISP8: - v = OP_ADDR; - break; - default: - v = 1 << op2; - break; - } - if (op1 & OPT_EA) - v |= OP_EA; - op_type[i] = v; - if ((ops[i].type & v) == 0) - goto next; - alltypes |= ops[i].type; - } - (void)alltypes; /* maybe unused */ - /* all is matching ! */ - break; - next: ; - } - if (pa->sym == 0) { - if (opcode >= TOK_ASM_first && opcode <= TOK_ASM_last) { - int b; - b = op0_codes[opcode - TOK_ASM_first]; - if (b & 0xff00) - g(b >> 8); - g(b); - return; - } else if (opcode <= TOK_ASM_alllast) { - tcc_error("bad operand with opcode '%s'", - get_tok_str(opcode, NULL)); - } else { - /* Special case for cmovcc, we accept size suffixes but ignore - them, but we don't want them to blow up our tables. */ - TokenSym *ts = table_ident[opcode - TOK_IDENT]; - if (ts->len >= 6 - && strchr("wlq", ts->str[ts->len-1]) - && !memcmp(ts->str, "cmov", 4)) { - opcode = tok_alloc(ts->str, ts->len-1)->tok; - goto again; - } - tcc_error("unknown opcode '%s'", ts->str); - } - } - /* if the size is unknown, then evaluate it (OPC_B or OPC_WL case) */ - autosize = NBWLX-1; -#ifdef TCC_TARGET_X86_64 - /* XXX the autosize should rather be zero, to not have to adjust this - all the time. */ - if ((pa->instr_type & OPC_BWLQ) == OPC_B) - autosize = NBWLX-2; -#endif - if (s == autosize) { - /* Check for register operands providing hints about the size. - Start from the end, i.e. destination operands. This matters - only for opcodes accepting different sized registers, lar and lsl - are such opcodes. */ - for(i = nb_ops - 1; s == autosize && i >= 0; i--) { - if ((ops[i].type & OP_REG) && !(op_type[i] & (OP_CL | OP_DX))) - s = reg_to_size[ops[i].type & OP_REG]; - } - if (s == autosize) { - if ((opcode == TOK_ASM_push || opcode == TOK_ASM_pop) && - (ops[0].type & (OP_SEG | OP_IM8S | OP_IM32))) - s = 2; - else if ((opcode == TOK_ASM_push || opcode == TOK_ASM_pop) && - (ops[0].type & OP_EA)) - s = NBWLX - 2; - else - tcc_error("cannot infer opcode suffix"); - } - } - -#ifdef TCC_TARGET_X86_64 - /* Generate addr32 prefix if needed */ - for(i = 0; i < nb_ops; i++) { - if (ops[i].type & OP_EA32) { - g(0x67); - break; - } - } -#endif - /* generate data16 prefix if needed */ - p66 = 0; - if (s == 1) - p66 = 1; - else { - /* accepting mmx+sse in all operands --> needs 0x66 to - switch to sse mode. Accepting only sse in an operand --> is - already SSE insn and needs 0x66/f2/f3 handling. */ - for (i = 0; i < nb_ops; i++) - if ((op_type[i] & (OP_MMX | OP_SSE)) == (OP_MMX | OP_SSE) - && ops[i].type & OP_SSE) - p66 = 1; - } - if (p66) - g(0x66); -#ifdef TCC_TARGET_X86_64 - rex64 = 0; - if (pa->instr_type & OPC_48) - rex64 = 1; - else if (s == 3 || (alltypes & OP_REG64)) { - /* generate REX prefix */ - int default64 = 0; - for(i = 0; i < nb_ops; i++) { - if (op_type[i] == OP_REG64 && pa->opcode != 0xb8) { - /* If only 64bit regs are accepted in one operand - this is a default64 instruction without need for - REX prefixes, except for movabs(0xb8). */ - default64 = 1; - break; - } - } - /* XXX find better encoding for the default64 instructions. */ - if (((opcode != TOK_ASM_push && opcode != TOK_ASM_pop - && opcode != TOK_ASM_pushw && opcode != TOK_ASM_pushl - && opcode != TOK_ASM_pushq && opcode != TOK_ASM_popw - && opcode != TOK_ASM_popl && opcode != TOK_ASM_popq - && opcode != TOK_ASM_call && opcode != TOK_ASM_jmp)) - && !default64) - rex64 = 1; - } -#endif - - /* now generates the operation */ - if (OPCT_IS(pa->instr_type, OPC_FWAIT)) - g(0x9b); - if (seg_prefix) - g(seg_prefix); - - v = pa->opcode; - if (pa->instr_type & OPC_0F) - v = ((v & ~0xff) << 8) | 0x0f00 | (v & 0xff); - if ((v == 0x69 || v == 0x6b) && nb_ops == 2) { - /* kludge for imul $im, %reg */ - nb_ops = 3; - ops[2] = ops[1]; - op_type[2] = op_type[1]; - } else if (v == 0xcd && ops[0].e.v == 3 && !ops[0].e.sym) { - v--; /* int $3 case */ - nb_ops = 0; - } else if ((v == 0x06 || v == 0x07)) { - if (ops[0].reg >= 4) { - /* push/pop %fs or %gs */ - v = 0x0fa0 + (v - 0x06) + ((ops[0].reg - 4) << 3); - } else { - v += ops[0].reg << 3; - } - nb_ops = 0; - } else if (v <= 0x05) { - /* arith case */ - v += ((opcode - TOK_ASM_addb) / NBWLX) << 3; - } else if ((pa->instr_type & (OPCT_MASK | OPC_MODRM)) == OPC_FARITH) { - /* fpu arith case */ - v += ((opcode - pa->sym) / 6) << 3; - } - - /* search which operand will be used for modrm */ - modrm_index = -1; - modreg_index = -1; - if (pa->instr_type & OPC_MODRM) { - if (!nb_ops) { - /* A modrm opcode without operands is a special case (e.g. mfence). - It has a group and acts as if there's an register operand 0 - (ax). */ - i = 0; - ops[i].type = OP_REG; - ops[i].reg = 0; - goto modrm_found; - } - /* first look for an ea operand */ - for(i = 0;i < nb_ops; i++) { - if (op_type[i] & OP_EA) - goto modrm_found; - } - /* then if not found, a register or indirection (shift instructions) */ - for(i = 0;i < nb_ops; i++) { - if (op_type[i] & (OP_REG | OP_MMX | OP_SSE | OP_INDIR)) - goto modrm_found; - } -#ifdef ASM_DEBUG - tcc_error("bad op table"); -#endif - modrm_found: - modrm_index = i; - /* if a register is used in another operand then it is - used instead of group */ - for(i = 0;i < nb_ops; i++) { - int t = op_type[i]; - if (i != modrm_index && - (t & (OP_REG | OP_MMX | OP_SSE | OP_CR | OP_TR | OP_DB | OP_SEG))) { - modreg_index = i; - break; - } - } - } -#ifdef TCC_TARGET_X86_64 - asm_rex (rex64, ops, nb_ops, op_type, modreg_index, modrm_index); -#endif - - if (pa->instr_type & OPC_REG) { - /* mov $im, %reg case */ - if (v == 0xb0 && s >= 1) - v += 7; - for(i = 0; i < nb_ops; i++) { - if (op_type[i] & (OP_REG | OP_ST)) { - v += ops[i].reg; - break; - } - } - } - if (pa->instr_type & OPC_B) - v += s >= 1; - if (nb_ops == 1 && pa->op_type[0] == OPT_DISP8) { - ElfSym *esym; - int jmp_disp; - - /* see if we can really generate the jump with a byte offset */ - esym = elfsym(ops[0].e.sym); - if (!esym || esym->st_shndx != cur_text_section->sh_num) - goto no_short_jump; - jmp_disp = ops[0].e.v + esym->st_value - ind - 2 - (v >= 0xff); - if (jmp_disp == (int8_t)jmp_disp) { - /* OK to generate jump */ - ops[0].e.sym = 0; - ops[0].e.v = jmp_disp; - op_type[0] = OP_IM8S; - } else { - no_short_jump: - /* long jump will be allowed. need to modify the - opcode slightly */ - if (v == 0xeb) /* jmp */ - v = 0xe9; - else if (v == 0x70) /* jcc */ - v += 0x0f10; - else - tcc_error("invalid displacement"); - } - } - if (OPCT_IS(pa->instr_type, OPC_TEST)) - v += test_bits[opcode - pa->sym]; - op1 = v >> 16; - if (op1) - g(op1); - op1 = (v >> 8) & 0xff; - if (op1) - g(op1); - g(v); - - if (OPCT_IS(pa->instr_type, OPC_SHIFT)) { - reg = (opcode - pa->sym) / NBWLX; - if (reg == 6) - reg = 7; - } else if (OPCT_IS(pa->instr_type, OPC_ARITH)) { - reg = (opcode - pa->sym) / NBWLX; - } else if (OPCT_IS(pa->instr_type, OPC_FARITH)) { - reg = (opcode - pa->sym) / 6; - } else { - reg = (pa->instr_type >> OPC_GROUP_SHIFT) & 7; - } - - pc = 0; - if (pa->instr_type & OPC_MODRM) { - /* if a register is used in another operand then it is - used instead of group */ - if (modreg_index >= 0) - reg = ops[modreg_index].reg; - pc = asm_modrm(reg, &ops[modrm_index]); - } - - /* emit constants */ -#ifndef TCC_TARGET_X86_64 - if (!(pa->instr_type & OPC_0F) - && (pa->opcode == 0x9a || pa->opcode == 0xea)) { - /* ljmp or lcall kludge */ - gen_expr32(&ops[1].e); - if (ops[0].e.sym) - tcc_error("cannot relocate"); - gen_le16(ops[0].e.v); - return; - } -#endif - for(i = 0;i < nb_ops; i++) { - v = op_type[i]; - if (v & (OP_IM8 | OP_IM16 | OP_IM32 | OP_IM64 | OP_IM8S | OP_ADDR)) { - /* if multiple sizes are given it means we must look - at the op size */ - if ((v | OP_IM8 | OP_IM64) == (OP_IM8 | OP_IM16 | OP_IM32 | OP_IM64)) { - if (s == 0) - v = OP_IM8; - else if (s == 1) - v = OP_IM16; - else if (s == 2 || (v & OP_IM64) == 0) - v = OP_IM32; - else - v = OP_IM64; - } - - if ((v & (OP_IM8 | OP_IM8S | OP_IM16)) && ops[i].e.sym) - tcc_error("cannot relocate"); - - if (v & (OP_IM8 | OP_IM8S)) { - g(ops[i].e.v); - } else if (v & OP_IM16) { - gen_le16(ops[i].e.v); -#ifdef TCC_TARGET_X86_64 - } else if (v & OP_IM64) { - gen_expr64(&ops[i].e); -#endif - } else if (pa->op_type[i] == OPT_DISP || pa->op_type[i] == OPT_DISP8) { - gen_disp32(&ops[i].e); - } else { - gen_expr32(&ops[i].e); - } - } - } - - /* after immediate operands, adjust pc-relative address */ - if (pc) - add32le(cur_text_section->data + pc - 4, pc - ind); -} - -/* return the constraint priority (we allocate first the lowest - numbered constraints) */ -static inline int constraint_priority(const char *str) -{ - int priority, c, pr; - - /* we take the lowest priority */ - priority = 0; - for(;;) { - c = *str; - if (c == '\0') - break; - str++; - switch(c) { - case 'A': - pr = 0; - break; - case 'a': - case 'b': - case 'c': - case 'd': - case 'S': - case 'D': - pr = 1; - break; - case 'q': - pr = 2; - break; - case 'r': - case 'R': - case 'p': - pr = 3; - break; - case 'N': - case 'M': - case 'I': - case 'e': - case 'i': - case 'm': - case 'g': - pr = 4; - break; - default: - tcc_error("unknown constraint '%c'", c); - pr = 0; - } - if (pr > priority) - priority = pr; - } - return priority; -} - -static const char *skip_constraint_modifiers(const char *p) -{ - while (*p == '=' || *p == '&' || *p == '+' || *p == '%') - p++; - return p; -} - -/* If T (a token) is of the form "%reg" returns the register - number and type, otherwise return -1. */ -ST_FUNC int asm_parse_regvar (int t) -{ - const char *s; - Operand op; - if (t < TOK_IDENT || (t & SYM_FIELD)) - return -1; - s = table_ident[t - TOK_IDENT]->str; - if (s[0] != '%') - return -1; - t = tok_alloc_const(s + 1); - unget_tok(t); - unget_tok('%'); - parse_operand(tcc_state, &op); - /* Accept only integer regs for now. */ - if (op.type & OP_REG) - return op.reg; - else - return -1; -} - -#define REG_OUT_MASK 0x01 -#define REG_IN_MASK 0x02 - -#define is_reg_allocated(reg) (regs_allocated[reg] & reg_mask) - -ST_FUNC void asm_compute_constraints(ASMOperand *operands, - int nb_operands, int nb_outputs, - const uint8_t *clobber_regs, - int *pout_reg) -{ - ASMOperand *op; - int sorted_op[MAX_ASM_OPERANDS]; - int i, j, k, p1, p2, tmp, reg, c, reg_mask; - const char *str; - uint8_t regs_allocated[NB_ASM_REGS]; - - /* init fields */ - for(i=0;iinput_index = -1; - op->ref_index = -1; - op->reg = -1; - op->is_memory = 0; - op->is_rw = 0; - } - /* compute constraint priority and evaluate references to output - constraints if input constraints */ - for(i=0;iconstraint; - str = skip_constraint_modifiers(str); - if (isnum(*str) || *str == '[') { - /* this is a reference to another constraint */ - k = find_constraint(operands, nb_operands, str, NULL); - if ((unsigned)k >= i || i < nb_outputs) - tcc_error("invalid reference in constraint %d ('%s')", - i, str); - op->ref_index = k; - if (operands[k].input_index >= 0) - tcc_error("cannot reference twice the same operand"); - operands[k].input_index = i; - op->priority = 5; - } else if ((op->vt->r & VT_VALMASK) == VT_LOCAL - && op->vt->sym - && (reg = op->vt->sym->r & VT_VALMASK) < VT_CONST) { - op->priority = 1; - op->reg = reg; - } else { - op->priority = constraint_priority(str); - } - } - - /* sort operands according to their priority */ - for(i=0;iconstraint; - /* no need to allocate references */ - if (op->ref_index >= 0) - continue; - /* select if register is used for output, input or both */ - if (op->input_index >= 0) { - reg_mask = REG_IN_MASK | REG_OUT_MASK; - } else if (j < nb_outputs) { - reg_mask = REG_OUT_MASK; - } else { - reg_mask = REG_IN_MASK; - } - if (op->reg >= 0) { - if (is_reg_allocated(op->reg)) - tcc_error("asm regvar requests register that's taken already"); - reg = op->reg; - goto reg_found; - } - try_next: - c = *str++; - switch(c) { - case '=': - goto try_next; - case '+': - op->is_rw = 1; - /* FALL THRU */ - case '&': - if (j >= nb_outputs) - tcc_error("'%c' modifier can only be applied to outputs", c); - reg_mask = REG_IN_MASK | REG_OUT_MASK; - goto try_next; - case 'A': - /* allocate both eax and edx */ - if (is_reg_allocated(TREG_XAX) || - is_reg_allocated(TREG_XDX)) - goto try_next; - op->is_llong = 1; - op->reg = TREG_XAX; - regs_allocated[TREG_XAX] |= reg_mask; - regs_allocated[TREG_XDX] |= reg_mask; - break; - case 'a': - reg = TREG_XAX; - goto alloc_reg; - case 'b': - reg = 3; - goto alloc_reg; - case 'c': - reg = TREG_XCX; - goto alloc_reg; - case 'd': - reg = TREG_XDX; - goto alloc_reg; - case 'S': - reg = 6; - goto alloc_reg; - case 'D': - reg = 7; - alloc_reg: - if (is_reg_allocated(reg)) - goto try_next; - goto reg_found; - case 'q': - /* eax, ebx, ecx or edx */ - for(reg = 0; reg < 4; reg++) { - if (!is_reg_allocated(reg)) - goto reg_found; - } - goto try_next; - case 'r': - case 'R': - case 'p': /* A general address, for x86(64) any register is acceptable*/ - /* any general register */ - for(reg = 0; reg < 8; reg++) { - if (!is_reg_allocated(reg)) - goto reg_found; - } - goto try_next; - reg_found: - /* now we can reload in the register */ - op->is_llong = 0; - op->reg = reg; - regs_allocated[reg] |= reg_mask; - break; - case 'e': - case 'i': - if (!((op->vt->r & (VT_VALMASK | VT_LVAL)) == VT_CONST)) - goto try_next; - break; - case 'I': - case 'N': - case 'M': - if (!((op->vt->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST)) - goto try_next; - break; - case 'm': - case 'g': - /* nothing special to do because the operand is already in - memory, except if the pointer itself is stored in a - memory variable (VT_LLOCAL case) */ - /* XXX: fix constant case */ - /* if it is a reference to a memory zone, it must lie - in a register, so we reserve the register in the - input registers and a load will be generated - later */ - if (j < nb_outputs || c == 'm') { - if ((op->vt->r & VT_VALMASK) == VT_LLOCAL) { - /* any general register */ - for(reg = 0; reg < 8; reg++) { - if (!(regs_allocated[reg] & REG_IN_MASK)) - goto reg_found1; - } - goto try_next; - reg_found1: - /* now we can reload in the register */ - regs_allocated[reg] |= REG_IN_MASK; - op->reg = reg; - op->is_memory = 1; - } - } - break; - default: - tcc_error("asm constraint %d ('%s') could not be satisfied", - j, op->constraint); - break; - } - /* if a reference is present for that operand, we assign it too */ - if (op->input_index >= 0) { - operands[op->input_index].reg = op->reg; - operands[op->input_index].is_llong = op->is_llong; - } - } - - /* compute out_reg. It is used to store outputs registers to memory - locations references by pointers (VT_LLOCAL case) */ - *pout_reg = -1; - for(i=0;ireg >= 0 && - (op->vt->r & VT_VALMASK) == VT_LLOCAL && - !op->is_memory) { - for(reg = 0; reg < 8; reg++) { - if (!(regs_allocated[reg] & REG_OUT_MASK)) - goto reg_found2; - } - tcc_error("could not find free output register for reloading"); - reg_found2: - *pout_reg = reg; - break; - } - } - - /* print sorted constraints */ -#ifdef ASM_DEBUG - for(i=0;iid ? get_tok_str(op->id, NULL) : "", - op->constraint, - op->vt->r, - op->reg); - } - if (*pout_reg >= 0) - printf("out_reg=%d\n", *pout_reg); -#endif -} - -ST_FUNC void subst_asm_operand(CString *add_str, - SValue *sv, int modifier) -{ - int r, reg, size, val; - char buf[64]; - - r = sv->r; - if ((r & VT_VALMASK) == VT_CONST) { - if (!(r & VT_LVAL) && modifier != 'c' && modifier != 'n' && - modifier != 'P') - cstr_ccat(add_str, '$'); - if (r & VT_SYM) { - const char *name = get_tok_str(sv->sym->v, NULL); - if (sv->sym->v >= SYM_FIRST_ANOM) { - /* In case of anonymous symbols ("L.42", used - for static data labels) we can't find them - in the C symbol table when later looking up - this name. So enter them now into the asm label - list when we still know the symbol. */ - get_asm_sym(tok_alloc_const(name), sv->sym); - } - if (tcc_state->leading_underscore) - cstr_ccat(add_str, '_'); - cstr_cat(add_str, name, -1); - if ((uint32_t)sv->c.i == 0) - goto no_offset; - cstr_ccat(add_str, '+'); - } - val = sv->c.i; - if (modifier == 'n') - val = -val; - snprintf(buf, sizeof(buf), "%d", (int)sv->c.i); - cstr_cat(add_str, buf, -1); - no_offset:; -#ifdef TCC_TARGET_X86_64 - if (r & VT_LVAL) - cstr_cat(add_str, "(%rip)", -1); -#endif - } else if ((r & VT_VALMASK) == VT_LOCAL) { -#ifdef TCC_TARGET_X86_64 - snprintf(buf, sizeof(buf), "%d(%%rbp)", (int)sv->c.i); -#else - snprintf(buf, sizeof(buf), "%d(%%ebp)", (int)sv->c.i); -#endif - cstr_cat(add_str, buf, -1); - } else if (r & VT_LVAL) { - reg = r & VT_VALMASK; - if (reg >= VT_CONST) - tcc_internal_error(""); - snprintf(buf, sizeof(buf), "(%%%s)", -#ifdef TCC_TARGET_X86_64 - get_tok_str(TOK_ASM_rax + reg, NULL) -#else - get_tok_str(TOK_ASM_eax + reg, NULL) -#endif - ); - cstr_cat(add_str, buf, -1); - } else { - /* register case */ - reg = r & VT_VALMASK; - if (reg >= VT_CONST) - tcc_internal_error(""); - - /* choose register operand size */ - if ((sv->type.t & VT_BTYPE) == VT_BYTE || - (sv->type.t & VT_BTYPE) == VT_BOOL) - size = 1; - else if ((sv->type.t & VT_BTYPE) == VT_SHORT) - size = 2; -#ifdef TCC_TARGET_X86_64 - else if ((sv->type.t & VT_BTYPE) == VT_LLONG || - (sv->type.t & VT_BTYPE) == VT_PTR) - size = 8; -#endif - else - size = 4; - if (size == 1 && reg >= 4) - size = 4; - - if (modifier == 'b') { - if (reg >= 4) - tcc_error("cannot use byte register"); - size = 1; - } else if (modifier == 'h') { - if (reg >= 4) - tcc_error("cannot use byte register"); - size = -1; - } else if (modifier == 'w') { - size = 2; - } else if (modifier == 'k') { - size = 4; -#ifdef TCC_TARGET_X86_64 - } else if (modifier == 'q') { - size = 8; -#endif - } - - switch(size) { - case -1: - reg = TOK_ASM_ah + reg; - break; - case 1: - reg = TOK_ASM_al + reg; - break; - case 2: - reg = TOK_ASM_ax + reg; - break; - default: - reg = TOK_ASM_eax + reg; - break; -#ifdef TCC_TARGET_X86_64 - case 8: - reg = TOK_ASM_rax + reg; - break; -#endif - } - snprintf(buf, sizeof(buf), "%%%s", get_tok_str(reg, NULL)); - cstr_cat(add_str, buf, -1); - } -} - -/* generate prolog and epilog code for asm statement */ -ST_FUNC void asm_gen_code(ASMOperand *operands, int nb_operands, - int nb_outputs, int is_output, - uint8_t *clobber_regs, - int out_reg) -{ - uint8_t regs_allocated[NB_ASM_REGS]; - ASMOperand *op; - int i, reg; - - /* Strictly speaking %Xbp and %Xsp should be included in the - call-preserved registers, but currently it doesn't matter. */ -#ifdef TCC_TARGET_X86_64 -#ifdef TCC_TARGET_PE - static const uint8_t reg_saved[] = { 3, 6, 7, 12, 13, 14, 15 }; -#else - static const uint8_t reg_saved[] = { 3, 12, 13, 14, 15 }; -#endif -#else - static const uint8_t reg_saved[] = { 3, 6, 7 }; -#endif - - /* mark all used registers */ - memcpy(regs_allocated, clobber_regs, sizeof(regs_allocated)); - for(i = 0; i < nb_operands;i++) { - op = &operands[i]; - if (op->reg >= 0) - regs_allocated[op->reg] = 1; - } - if (!is_output) { - /* generate reg save code */ - for(i = 0; i < sizeof(reg_saved)/sizeof(reg_saved[0]); i++) { - reg = reg_saved[i]; - if (regs_allocated[reg]) { - if (reg >= 8) - g(0x41), reg-=8; - g(0x50 + reg); - } - } - - /* generate load code */ - for(i = 0; i < nb_operands; i++) { - op = &operands[i]; - if (op->reg >= 0) { - if ((op->vt->r & VT_VALMASK) == VT_LLOCAL && - op->is_memory) { - /* memory reference case (for both input and - output cases) */ - SValue sv; - sv = *op->vt; - sv.r = (sv.r & ~VT_VALMASK) | VT_LOCAL | VT_LVAL; - sv.type.t = VT_PTR; - load(op->reg, &sv); - } else if (i >= nb_outputs || op->is_rw) { - /* load value in register */ - load(op->reg, op->vt); - if (op->is_llong) { - SValue sv; - sv = *op->vt; - sv.c.i += 4; - load(TREG_XDX, &sv); - } - } - } - } - } else { - /* generate save code */ - for(i = 0 ; i < nb_outputs; i++) { - op = &operands[i]; - if (op->reg >= 0) { - if ((op->vt->r & VT_VALMASK) == VT_LLOCAL) { - if (!op->is_memory) { - SValue sv; - sv = *op->vt; - sv.r = (sv.r & ~VT_VALMASK) | VT_LOCAL; - sv.type.t = VT_PTR; - load(out_reg, &sv); - - sv = *op->vt; - sv.r = (sv.r & ~VT_VALMASK) | out_reg; - store(op->reg, &sv); - } - } else { - store(op->reg, op->vt); - if (op->is_llong) { - SValue sv; - sv = *op->vt; - sv.c.i += 4; - store(TREG_XDX, &sv); - } - } - } - } - /* generate reg restore code */ - for(i = sizeof(reg_saved)/sizeof(reg_saved[0]) - 1; i >= 0; i--) { - reg = reg_saved[i]; - if (regs_allocated[reg]) { - if (reg >= 8) - g(0x41), reg-=8; - g(0x58 + reg); - } - } - } -} - -ST_FUNC void asm_clobber(uint8_t *clobber_regs, const char *str) -{ - int reg; -#ifdef TCC_TARGET_X86_64 - unsigned int type; -#endif - - if (!strcmp(str, "memory") || - !strcmp(str, "cc") || - !strcmp(str, "flags")) - return; - reg = tok_alloc_const(str); - if (reg >= TOK_ASM_eax && reg <= TOK_ASM_edi) { - reg -= TOK_ASM_eax; - } else if (reg >= TOK_ASM_ax && reg <= TOK_ASM_di) { - reg -= TOK_ASM_ax; -#ifdef TCC_TARGET_X86_64 - } else if (reg >= TOK_ASM_rax && reg <= TOK_ASM_rdi) { - reg -= TOK_ASM_rax; - } else if ((reg = asm_parse_numeric_reg(reg, &type)) >= 0) { - ; -#endif - } else { - tcc_error("invalid clobber register '%s'", str); - } - clobber_regs[reg] = 1; -} diff --git a/05/tcc-final/i386-asm.h b/05/tcc-final/i386-asm.h deleted file mode 100644 index dfc5183..0000000 --- a/05/tcc-final/i386-asm.h +++ /dev/null @@ -1,482 +0,0 @@ - DEF_ASM_OP0(clc, 0xf8) /* must be first OP0 */ - DEF_ASM_OP0(cld, 0xfc) - DEF_ASM_OP0(cli, 0xfa) - DEF_ASM_OP0(clts, 0x0f06) - DEF_ASM_OP0(cmc, 0xf5) - DEF_ASM_OP0(lahf, 0x9f) - DEF_ASM_OP0(sahf, 0x9e) - DEF_ASM_OP0(pusha, 0x60) - DEF_ASM_OP0(popa, 0x61) - DEF_ASM_OP0(pushfl, 0x9c) - DEF_ASM_OP0(popfl, 0x9d) - DEF_ASM_OP0(pushf, 0x9c) - DEF_ASM_OP0(popf, 0x9d) - DEF_ASM_OP0(stc, 0xf9) - DEF_ASM_OP0(std, 0xfd) - DEF_ASM_OP0(sti, 0xfb) - DEF_ASM_OP0(aaa, 0x37) - DEF_ASM_OP0(aas, 0x3f) - DEF_ASM_OP0(daa, 0x27) - DEF_ASM_OP0(das, 0x2f) - DEF_ASM_OP0(aad, 0xd50a) - DEF_ASM_OP0(aam, 0xd40a) - DEF_ASM_OP0(cbw, 0x6698) - DEF_ASM_OP0(cwd, 0x6699) - DEF_ASM_OP0(cwde, 0x98) - DEF_ASM_OP0(cdq, 0x99) - DEF_ASM_OP0(cbtw, 0x6698) - DEF_ASM_OP0(cwtl, 0x98) - DEF_ASM_OP0(cwtd, 0x6699) - DEF_ASM_OP0(cltd, 0x99) - DEF_ASM_OP0(int3, 0xcc) - DEF_ASM_OP0(into, 0xce) - DEF_ASM_OP0(iret, 0xcf) - DEF_ASM_OP0(rsm, 0x0faa) - DEF_ASM_OP0(hlt, 0xf4) - DEF_ASM_OP0(nop, 0x90) - DEF_ASM_OP0(pause, 0xf390) - DEF_ASM_OP0(xlat, 0xd7) - - /* strings */ -ALT(DEF_ASM_OP0L(cmpsb, 0xa6, 0, OPC_BWLX)) -ALT(DEF_ASM_OP0L(scmpb, 0xa6, 0, OPC_BWLX)) - -ALT(DEF_ASM_OP0L(insb, 0x6c, 0, OPC_BWL)) -ALT(DEF_ASM_OP0L(outsb, 0x6e, 0, OPC_BWL)) - -ALT(DEF_ASM_OP0L(lodsb, 0xac, 0, OPC_BWLX)) -ALT(DEF_ASM_OP0L(slodb, 0xac, 0, OPC_BWLX)) - -ALT(DEF_ASM_OP0L(movsb, 0xa4, 0, OPC_BWLX)) -ALT(DEF_ASM_OP0L(smovb, 0xa4, 0, OPC_BWLX)) - -ALT(DEF_ASM_OP0L(scasb, 0xae, 0, OPC_BWLX)) -ALT(DEF_ASM_OP0L(sscab, 0xae, 0, OPC_BWLX)) - -ALT(DEF_ASM_OP0L(stosb, 0xaa, 0, OPC_BWLX)) -ALT(DEF_ASM_OP0L(sstob, 0xaa, 0, OPC_BWLX)) - - /* bits */ - -ALT(DEF_ASM_OP2(bsfw, 0x0fbc, 0, OPC_MODRM | OPC_WLX, OPT_REGW | OPT_EA, OPT_REGW)) -ALT(DEF_ASM_OP2(bsrw, 0x0fbd, 0, OPC_MODRM | OPC_WLX, OPT_REGW | OPT_EA, OPT_REGW)) - -ALT(DEF_ASM_OP2(btw, 0x0fa3, 0, OPC_MODRM | OPC_WLX, OPT_REGW, OPT_REGW | OPT_EA)) -ALT(DEF_ASM_OP2(btw, 0x0fba, 4, OPC_MODRM | OPC_WLX, OPT_IM8, OPT_REGW | OPT_EA)) - -ALT(DEF_ASM_OP2(btsw, 0x0fab, 0, OPC_MODRM | OPC_WLX, OPT_REGW, OPT_REGW | OPT_EA)) -ALT(DEF_ASM_OP2(btsw, 0x0fba, 5, OPC_MODRM | OPC_WLX, OPT_IM8, OPT_REGW | OPT_EA)) - -ALT(DEF_ASM_OP2(btrw, 0x0fb3, 0, OPC_MODRM | OPC_WLX, OPT_REGW, OPT_REGW | OPT_EA)) -ALT(DEF_ASM_OP2(btrw, 0x0fba, 6, OPC_MODRM | OPC_WLX, OPT_IM8, OPT_REGW | OPT_EA)) - -ALT(DEF_ASM_OP2(btcw, 0x0fbb, 0, OPC_MODRM | OPC_WLX, OPT_REGW, OPT_REGW | OPT_EA)) -ALT(DEF_ASM_OP2(btcw, 0x0fba, 7, OPC_MODRM | OPC_WLX, OPT_IM8, OPT_REGW | OPT_EA)) - - /* prefixes */ - DEF_ASM_OP0(wait, 0x9b) - DEF_ASM_OP0(fwait, 0x9b) - DEF_ASM_OP0(aword, 0x67) - DEF_ASM_OP0(addr16, 0x67) - ALT(DEF_ASM_OP0(word, 0x66)) - DEF_ASM_OP0(data16, 0x66) - DEF_ASM_OP0(lock, 0xf0) - DEF_ASM_OP0(rep, 0xf3) - DEF_ASM_OP0(repe, 0xf3) - DEF_ASM_OP0(repz, 0xf3) - DEF_ASM_OP0(repne, 0xf2) - DEF_ASM_OP0(repnz, 0xf2) - - DEF_ASM_OP0(invd, 0x0f08) - DEF_ASM_OP0(wbinvd, 0x0f09) - DEF_ASM_OP0(cpuid, 0x0fa2) - DEF_ASM_OP0(wrmsr, 0x0f30) - DEF_ASM_OP0(rdtsc, 0x0f31) - DEF_ASM_OP0(rdmsr, 0x0f32) - DEF_ASM_OP0(rdpmc, 0x0f33) - DEF_ASM_OP0(ud2, 0x0f0b) - - /* NOTE: we took the same order as gas opcode definition order */ -ALT(DEF_ASM_OP2(movb, 0xa0, 0, OPC_BWLX, OPT_ADDR, OPT_EAX)) -ALT(DEF_ASM_OP2(movb, 0xa2, 0, OPC_BWLX, OPT_EAX, OPT_ADDR)) -ALT(DEF_ASM_OP2(movb, 0x88, 0, OPC_MODRM | OPC_BWLX, OPT_REG, OPT_EA | OPT_REG)) -ALT(DEF_ASM_OP2(movb, 0x8a, 0, OPC_MODRM | OPC_BWLX, OPT_EA | OPT_REG, OPT_REG)) -ALT(DEF_ASM_OP2(movb, 0xb0, 0, OPC_REG | OPC_BWLX, OPT_IM, OPT_REG)) -ALT(DEF_ASM_OP2(movb, 0xc6, 0, OPC_MODRM | OPC_BWLX, OPT_IM, OPT_REG | OPT_EA)) - -ALT(DEF_ASM_OP2(movw, 0x8c, 0, OPC_MODRM | OPC_WLX, OPT_SEG, OPT_EA | OPT_REG)) -ALT(DEF_ASM_OP2(movw, 0x8e, 0, OPC_MODRM | OPC_WLX, OPT_EA | OPT_REG, OPT_SEG)) - -ALT(DEF_ASM_OP2(movw, 0x0f20, 0, OPC_MODRM | OPC_WLX, OPT_CR, OPT_REG32)) -ALT(DEF_ASM_OP2(movw, 0x0f21, 0, OPC_MODRM | OPC_WLX, OPT_DB, OPT_REG32)) -ALT(DEF_ASM_OP2(movw, 0x0f24, 0, OPC_MODRM | OPC_WLX, OPT_TR, OPT_REG32)) -ALT(DEF_ASM_OP2(movw, 0x0f22, 0, OPC_MODRM | OPC_WLX, OPT_REG32, OPT_CR)) -ALT(DEF_ASM_OP2(movw, 0x0f23, 0, OPC_MODRM | OPC_WLX, OPT_REG32, OPT_DB)) -ALT(DEF_ASM_OP2(movw, 0x0f26, 0, OPC_MODRM | OPC_WLX, OPT_REG32, OPT_TR)) - -ALT(DEF_ASM_OP2(movsbl, 0x0fbe, 0, OPC_MODRM, OPT_REG8 | OPT_EA, OPT_REG32)) -ALT(DEF_ASM_OP2(movsbw, 0x660fbe, 0, OPC_MODRM, OPT_REG8 | OPT_EA, OPT_REG16)) -ALT(DEF_ASM_OP2(movswl, 0x0fbf, 0, OPC_MODRM, OPT_REG16 | OPT_EA, OPT_REG32)) -ALT(DEF_ASM_OP2(movzbw, 0x0fb6, 0, OPC_MODRM | OPC_WLX, OPT_REG8 | OPT_EA, OPT_REGW)) -ALT(DEF_ASM_OP2(movzwl, 0x0fb7, 0, OPC_MODRM, OPT_REG16 | OPT_EA, OPT_REG32)) - -ALT(DEF_ASM_OP1(pushw, 0x50, 0, OPC_REG | OPC_WLX, OPT_REGW)) -ALT(DEF_ASM_OP1(pushw, 0xff, 6, OPC_MODRM | OPC_WLX, OPT_REGW | OPT_EA)) -ALT(DEF_ASM_OP1(pushw, 0x6a, 0, OPC_WLX, OPT_IM8S)) -ALT(DEF_ASM_OP1(pushw, 0x68, 0, OPC_WLX, OPT_IM32)) -ALT(DEF_ASM_OP1(pushw, 0x06, 0, OPC_WLX, OPT_SEG)) - -ALT(DEF_ASM_OP1(popw, 0x58, 0, OPC_REG | OPC_WLX, OPT_REGW)) -ALT(DEF_ASM_OP1(popw, 0x8f, 0, OPC_MODRM | OPC_WLX, OPT_REGW | OPT_EA)) -ALT(DEF_ASM_OP1(popw, 0x07, 0, OPC_WLX, OPT_SEG)) - -ALT(DEF_ASM_OP2(xchgw, 0x90, 0, OPC_REG | OPC_WLX, OPT_REGW, OPT_EAX)) -ALT(DEF_ASM_OP2(xchgw, 0x90, 0, OPC_REG | OPC_WLX, OPT_EAX, OPT_REGW)) -ALT(DEF_ASM_OP2(xchgb, 0x86, 0, OPC_MODRM | OPC_BWLX, OPT_REG, OPT_EA | OPT_REG)) -ALT(DEF_ASM_OP2(xchgb, 0x86, 0, OPC_MODRM | OPC_BWLX, OPT_EA | OPT_REG, OPT_REG)) - -ALT(DEF_ASM_OP2(inb, 0xe4, 0, OPC_BWL, OPT_IM8, OPT_EAX)) -ALT(DEF_ASM_OP1(inb, 0xe4, 0, OPC_BWL, OPT_IM8)) -ALT(DEF_ASM_OP2(inb, 0xec, 0, OPC_BWL, OPT_DX, OPT_EAX)) -ALT(DEF_ASM_OP1(inb, 0xec, 0, OPC_BWL, OPT_DX)) - -ALT(DEF_ASM_OP2(outb, 0xe6, 0, OPC_BWL, OPT_EAX, OPT_IM8)) -ALT(DEF_ASM_OP1(outb, 0xe6, 0, OPC_BWL, OPT_IM8)) -ALT(DEF_ASM_OP2(outb, 0xee, 0, OPC_BWL, OPT_EAX, OPT_DX)) -ALT(DEF_ASM_OP1(outb, 0xee, 0, OPC_BWL, OPT_DX)) - -ALT(DEF_ASM_OP2(leaw, 0x8d, 0, OPC_MODRM | OPC_WLX, OPT_EA, OPT_REG)) - -ALT(DEF_ASM_OP2(les, 0xc4, 0, OPC_MODRM, OPT_EA, OPT_REG32)) -ALT(DEF_ASM_OP2(lds, 0xc5, 0, OPC_MODRM, OPT_EA, OPT_REG32)) -ALT(DEF_ASM_OP2(lss, 0x0fb2, 0, OPC_MODRM, OPT_EA, OPT_REG32)) -ALT(DEF_ASM_OP2(lfs, 0x0fb4, 0, OPC_MODRM, OPT_EA, OPT_REG32)) -ALT(DEF_ASM_OP2(lgs, 0x0fb5, 0, OPC_MODRM, OPT_EA, OPT_REG32)) - - /* arith */ -ALT(DEF_ASM_OP2(addb, 0x00, 0, OPC_ARITH | OPC_MODRM | OPC_BWLX, OPT_REG, OPT_EA | OPT_REG)) /* XXX: use D bit ? */ -ALT(DEF_ASM_OP2(addb, 0x02, 0, OPC_ARITH | OPC_MODRM | OPC_BWLX, OPT_EA | OPT_REG, OPT_REG)) -ALT(DEF_ASM_OP2(addb, 0x04, 0, OPC_ARITH | OPC_BWLX, OPT_IM, OPT_EAX)) -ALT(DEF_ASM_OP2(addw, 0x83, 0, OPC_ARITH | OPC_MODRM | OPC_WLX, OPT_IM8S, OPT_EA | OPT_REGW)) -ALT(DEF_ASM_OP2(addb, 0x80, 0, OPC_ARITH | OPC_MODRM | OPC_BWLX, OPT_IM, OPT_EA | OPT_REG)) - -ALT(DEF_ASM_OP2(testb, 0x84, 0, OPC_MODRM | OPC_BWLX, OPT_REG, OPT_EA | OPT_REG)) -ALT(DEF_ASM_OP2(testb, 0x84, 0, OPC_MODRM | OPC_BWLX, OPT_EA | OPT_REG, OPT_REG)) -ALT(DEF_ASM_OP2(testb, 0xa8, 0, OPC_BWLX, OPT_IM, OPT_EAX)) -ALT(DEF_ASM_OP2(testb, 0xf6, 0, OPC_MODRM | OPC_BWLX, OPT_IM, OPT_EA | OPT_REG)) - -ALT(DEF_ASM_OP1(incw, 0x40, 0, OPC_REG | OPC_WLX, OPT_REGW)) -ALT(DEF_ASM_OP1(incb, 0xfe, 0, OPC_MODRM | OPC_BWLX, OPT_REG | OPT_EA)) -ALT(DEF_ASM_OP1(decw, 0x48, 0, OPC_REG | OPC_WLX, OPT_REGW)) -ALT(DEF_ASM_OP1(decb, 0xfe, 1, OPC_MODRM | OPC_BWLX, OPT_REG | OPT_EA)) - -ALT(DEF_ASM_OP1(notb, 0xf6, 2, OPC_MODRM | OPC_BWLX, OPT_REG | OPT_EA)) -ALT(DEF_ASM_OP1(negb, 0xf6, 3, OPC_MODRM | OPC_BWLX, OPT_REG | OPT_EA)) - -ALT(DEF_ASM_OP1(mulb, 0xf6, 4, OPC_MODRM | OPC_BWLX, OPT_REG | OPT_EA)) -ALT(DEF_ASM_OP1(imulb, 0xf6, 5, OPC_MODRM | OPC_BWLX, OPT_REG | OPT_EA)) - -ALT(DEF_ASM_OP2(imulw, 0x0faf, 0, OPC_MODRM | OPC_WLX, OPT_REG | OPT_EA, OPT_REG)) -ALT(DEF_ASM_OP3(imulw, 0x6b, 0, OPC_MODRM | OPC_WLX, OPT_IM8S, OPT_REGW | OPT_EA, OPT_REGW)) -ALT(DEF_ASM_OP2(imulw, 0x6b, 0, OPC_MODRM | OPC_WLX, OPT_IM8S, OPT_REGW)) -ALT(DEF_ASM_OP3(imulw, 0x69, 0, OPC_MODRM | OPC_WLX, OPT_IMW, OPT_REGW | OPT_EA, OPT_REGW)) -ALT(DEF_ASM_OP2(imulw, 0x69, 0, OPC_MODRM | OPC_WLX, OPT_IMW, OPT_REGW)) - -ALT(DEF_ASM_OP1(divb, 0xf6, 6, OPC_MODRM | OPC_BWLX, OPT_REG | OPT_EA)) -ALT(DEF_ASM_OP2(divb, 0xf6, 6, OPC_MODRM | OPC_BWLX, OPT_REG | OPT_EA, OPT_EAX)) -ALT(DEF_ASM_OP1(idivb, 0xf6, 7, OPC_MODRM | OPC_BWLX, OPT_REG | OPT_EA)) -ALT(DEF_ASM_OP2(idivb, 0xf6, 7, OPC_MODRM | OPC_BWLX, OPT_REG | OPT_EA, OPT_EAX)) - - /* shifts */ -ALT(DEF_ASM_OP2(rolb, 0xc0, 0, OPC_MODRM | OPC_BWLX | OPC_SHIFT, OPT_IM8, OPT_EA | OPT_REG)) -ALT(DEF_ASM_OP2(rolb, 0xd2, 0, OPC_MODRM | OPC_BWLX | OPC_SHIFT, OPT_CL, OPT_EA | OPT_REG)) -ALT(DEF_ASM_OP1(rolb, 0xd0, 0, OPC_MODRM | OPC_BWLX | OPC_SHIFT, OPT_EA | OPT_REG)) - -ALT(DEF_ASM_OP3(shldw, 0x0fa4, 0, OPC_MODRM | OPC_WLX, OPT_IM8, OPT_REGW, OPT_EA | OPT_REGW)) -ALT(DEF_ASM_OP3(shldw, 0x0fa5, 0, OPC_MODRM | OPC_WLX, OPT_CL, OPT_REGW, OPT_EA | OPT_REGW)) -ALT(DEF_ASM_OP2(shldw, 0x0fa5, 0, OPC_MODRM | OPC_WLX, OPT_REGW, OPT_EA | OPT_REGW)) -ALT(DEF_ASM_OP3(shrdw, 0x0fac, 0, OPC_MODRM | OPC_WLX, OPT_IM8, OPT_REGW, OPT_EA | OPT_REGW)) -ALT(DEF_ASM_OP3(shrdw, 0x0fad, 0, OPC_MODRM | OPC_WLX, OPT_CL, OPT_REGW, OPT_EA | OPT_REGW)) -ALT(DEF_ASM_OP2(shrdw, 0x0fad, 0, OPC_MODRM | OPC_WLX, OPT_REGW, OPT_EA | OPT_REGW)) - -ALT(DEF_ASM_OP1(call, 0xff, 2, OPC_MODRM, OPT_INDIR)) -ALT(DEF_ASM_OP1(call, 0xe8, 0, 0, OPT_DISP)) -ALT(DEF_ASM_OP1(jmp, 0xff, 4, OPC_MODRM, OPT_INDIR)) -ALT(DEF_ASM_OP1(jmp, 0xeb, 0, 0, OPT_DISP8)) - -ALT(DEF_ASM_OP2(lcall, 0x9a, 0, 0, OPT_IM16, OPT_IM32)) -ALT(DEF_ASM_OP1(lcall, 0xff, 3, OPC_MODRM, OPT_EA)) -ALT(DEF_ASM_OP2(ljmp, 0xea, 0, 0, OPT_IM16, OPT_IM32)) -ALT(DEF_ASM_OP1(ljmp, 0xff, 5, OPC_MODRM, OPT_EA)) - -ALT(DEF_ASM_OP1(int, 0xcd, 0, 0, OPT_IM8)) -ALT(DEF_ASM_OP1(seto, 0x0f90, 0, OPC_MODRM | OPC_TEST, OPT_REG8 | OPT_EA)) -ALT(DEF_ASM_OP1(setob, 0x0f90, 0, OPC_MODRM | OPC_TEST, OPT_REG8 | OPT_EA)) - DEF_ASM_OP2(enter, 0xc8, 0, 0, OPT_IM16, OPT_IM8) - DEF_ASM_OP0(leave, 0xc9) - DEF_ASM_OP0(ret, 0xc3) - DEF_ASM_OP0(retl,0xc3) -ALT(DEF_ASM_OP1(retl,0xc2, 0, 0, OPT_IM16)) -ALT(DEF_ASM_OP1(ret, 0xc2, 0, 0, OPT_IM16)) - DEF_ASM_OP0(lret, 0xcb) -ALT(DEF_ASM_OP1(lret, 0xca, 0, 0, OPT_IM16)) - -ALT(DEF_ASM_OP1(jo, 0x70, 0, OPC_TEST, OPT_DISP8)) - DEF_ASM_OP1(loopne, 0xe0, 0, 0, OPT_DISP8) - DEF_ASM_OP1(loopnz, 0xe0, 0, 0, OPT_DISP8) - DEF_ASM_OP1(loope, 0xe1, 0, 0, OPT_DISP8) - DEF_ASM_OP1(loopz, 0xe1, 0, 0, OPT_DISP8) - DEF_ASM_OP1(loop, 0xe2, 0, 0, OPT_DISP8) - DEF_ASM_OP1(jecxz, 0xe3, 0, 0, OPT_DISP8) - - /* float */ - /* specific fcomp handling */ -ALT(DEF_ASM_OP0L(fcomp, 0xd8d9, 0, 0)) - -ALT(DEF_ASM_OP1(fadd, 0xd8c0, 0, OPC_FARITH | OPC_REG, OPT_ST)) -ALT(DEF_ASM_OP2(fadd, 0xd8c0, 0, OPC_FARITH | OPC_REG, OPT_ST, OPT_ST0)) -ALT(DEF_ASM_OP2(fadd, 0xdcc0, 0, OPC_FARITH | OPC_REG, OPT_ST0, OPT_ST)) -ALT(DEF_ASM_OP2(fmul, 0xdcc8, 0, OPC_FARITH | OPC_REG, OPT_ST0, OPT_ST)) -ALT(DEF_ASM_OP0L(fadd, 0xdec1, 0, OPC_FARITH)) -ALT(DEF_ASM_OP1(faddp, 0xdec0, 0, OPC_FARITH | OPC_REG, OPT_ST)) -ALT(DEF_ASM_OP2(faddp, 0xdec0, 0, OPC_FARITH | OPC_REG, OPT_ST, OPT_ST0)) -ALT(DEF_ASM_OP2(faddp, 0xdec0, 0, OPC_FARITH | OPC_REG, OPT_ST0, OPT_ST)) -ALT(DEF_ASM_OP0L(faddp, 0xdec1, 0, OPC_FARITH)) -ALT(DEF_ASM_OP1(fadds, 0xd8, 0, OPC_FARITH | OPC_MODRM, OPT_EA)) -ALT(DEF_ASM_OP1(fiaddl, 0xda, 0, OPC_FARITH | OPC_MODRM, OPT_EA)) -ALT(DEF_ASM_OP1(faddl, 0xdc, 0, OPC_FARITH | OPC_MODRM, OPT_EA)) -ALT(DEF_ASM_OP1(fiadds, 0xde, 0, OPC_FARITH | OPC_MODRM, OPT_EA)) - - DEF_ASM_OP0(fucompp, 0xdae9) - DEF_ASM_OP0(ftst, 0xd9e4) - DEF_ASM_OP0(fxam, 0xd9e5) - DEF_ASM_OP0(fld1, 0xd9e8) - DEF_ASM_OP0(fldl2t, 0xd9e9) - DEF_ASM_OP0(fldl2e, 0xd9ea) - DEF_ASM_OP0(fldpi, 0xd9eb) - DEF_ASM_OP0(fldlg2, 0xd9ec) - DEF_ASM_OP0(fldln2, 0xd9ed) - DEF_ASM_OP0(fldz, 0xd9ee) - - DEF_ASM_OP0(f2xm1, 0xd9f0) - DEF_ASM_OP0(fyl2x, 0xd9f1) - DEF_ASM_OP0(fptan, 0xd9f2) - DEF_ASM_OP0(fpatan, 0xd9f3) - DEF_ASM_OP0(fxtract, 0xd9f4) - DEF_ASM_OP0(fprem1, 0xd9f5) - DEF_ASM_OP0(fdecstp, 0xd9f6) - DEF_ASM_OP0(fincstp, 0xd9f7) - DEF_ASM_OP0(fprem, 0xd9f8) - DEF_ASM_OP0(fyl2xp1, 0xd9f9) - DEF_ASM_OP0(fsqrt, 0xd9fa) - DEF_ASM_OP0(fsincos, 0xd9fb) - DEF_ASM_OP0(frndint, 0xd9fc) - DEF_ASM_OP0(fscale, 0xd9fd) - DEF_ASM_OP0(fsin, 0xd9fe) - DEF_ASM_OP0(fcos, 0xd9ff) - DEF_ASM_OP0(fchs, 0xd9e0) - DEF_ASM_OP0(fabs, 0xd9e1) - DEF_ASM_OP0(fninit, 0xdbe3) - DEF_ASM_OP0(fnclex, 0xdbe2) - DEF_ASM_OP0(fnop, 0xd9d0) - - /* fp load */ - DEF_ASM_OP1(fld, 0xd9c0, 0, OPC_REG, OPT_ST) - DEF_ASM_OP1(fldl, 0xd9c0, 0, OPC_REG, OPT_ST) - DEF_ASM_OP1(flds, 0xd9, 0, OPC_MODRM, OPT_EA) -ALT(DEF_ASM_OP1(fldl, 0xdd, 0, OPC_MODRM, OPT_EA)) - DEF_ASM_OP1(fildl, 0xdb, 0, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(fildq, 0xdf, 5, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(fildll, 0xdf, 5, OPC_MODRM,OPT_EA) - DEF_ASM_OP1(fldt, 0xdb, 5, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(fbld, 0xdf, 4, OPC_MODRM, OPT_EA) - - /* fp store */ - DEF_ASM_OP1(fst, 0xddd0, 0, OPC_REG, OPT_ST) - DEF_ASM_OP1(fstl, 0xddd0, 0, OPC_REG, OPT_ST) - DEF_ASM_OP1(fsts, 0xd9, 2, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(fstps, 0xd9, 3, OPC_MODRM, OPT_EA) -ALT(DEF_ASM_OP1(fstl, 0xdd, 2, OPC_MODRM, OPT_EA)) - DEF_ASM_OP1(fstpl, 0xdd, 3, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(fist, 0xdf, 2, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(fistp, 0xdf, 3, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(fistl, 0xdb, 2, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(fistpl, 0xdb, 3, OPC_MODRM, OPT_EA) - - DEF_ASM_OP1(fstp, 0xddd8, 0, OPC_REG, OPT_ST) - DEF_ASM_OP1(fistpq, 0xdf, 7, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(fistpll, 0xdf, 7, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(fstpt, 0xdb, 7, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(fbstp, 0xdf, 6, OPC_MODRM, OPT_EA) - - /* exchange */ - DEF_ASM_OP0(fxch, 0xd9c9) -ALT(DEF_ASM_OP1(fxch, 0xd9c8, 0, OPC_REG, OPT_ST)) - - /* misc FPU */ - DEF_ASM_OP1(fucom, 0xdde0, 0, OPC_REG, OPT_ST ) - DEF_ASM_OP1(fucomp, 0xdde8, 0, OPC_REG, OPT_ST ) - - DEF_ASM_OP0L(finit, 0xdbe3, 0, OPC_FWAIT) - DEF_ASM_OP1(fldcw, 0xd9, 5, OPC_MODRM, OPT_EA ) - DEF_ASM_OP1(fnstcw, 0xd9, 7, OPC_MODRM, OPT_EA ) - DEF_ASM_OP1(fstcw, 0xd9, 7, OPC_MODRM | OPC_FWAIT, OPT_EA ) - DEF_ASM_OP0(fnstsw, 0xdfe0) -ALT(DEF_ASM_OP1(fnstsw, 0xdfe0, 0, 0, OPT_EAX )) -ALT(DEF_ASM_OP1(fnstsw, 0xdd, 7, OPC_MODRM, OPT_EA )) - DEF_ASM_OP1(fstsw, 0xdfe0, 0, OPC_FWAIT, OPT_EAX ) -ALT(DEF_ASM_OP0L(fstsw, 0xdfe0, 0, OPC_FWAIT)) -ALT(DEF_ASM_OP1(fstsw, 0xdd, 7, OPC_MODRM | OPC_FWAIT, OPT_EA )) - DEF_ASM_OP0L(fclex, 0xdbe2, 0, OPC_FWAIT) - DEF_ASM_OP1(fnstenv, 0xd9, 6, OPC_MODRM, OPT_EA ) - DEF_ASM_OP1(fstenv, 0xd9, 6, OPC_MODRM | OPC_FWAIT, OPT_EA ) - DEF_ASM_OP1(fldenv, 0xd9, 4, OPC_MODRM, OPT_EA ) - DEF_ASM_OP1(fnsave, 0xdd, 6, OPC_MODRM, OPT_EA ) - DEF_ASM_OP1(fsave, 0xdd, 6, OPC_MODRM | OPC_FWAIT, OPT_EA ) - DEF_ASM_OP1(frstor, 0xdd, 4, OPC_MODRM, OPT_EA ) - DEF_ASM_OP1(ffree, 0xddc0, 4, OPC_REG, OPT_ST ) - DEF_ASM_OP1(ffreep, 0xdfc0, 4, OPC_REG, OPT_ST ) - DEF_ASM_OP1(fxsave, 0x0fae, 0, OPC_MODRM, OPT_EA ) - DEF_ASM_OP1(fxrstor, 0x0fae, 1, OPC_MODRM, OPT_EA ) - - /* segments */ - DEF_ASM_OP2(arpl, 0x63, 0, OPC_MODRM, OPT_REG16, OPT_REG16 | OPT_EA) -ALT(DEF_ASM_OP2(larw, 0x0f02, 0, OPC_MODRM | OPC_WLX, OPT_REG | OPT_EA, OPT_REG)) - DEF_ASM_OP1(lgdt, 0x0f01, 2, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(lidt, 0x0f01, 3, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(lldt, 0x0f00, 2, OPC_MODRM, OPT_EA | OPT_REG) - DEF_ASM_OP1(lmsw, 0x0f01, 6, OPC_MODRM, OPT_EA | OPT_REG) -ALT(DEF_ASM_OP2(lslw, 0x0f03, 0, OPC_MODRM | OPC_WLX, OPT_EA | OPT_REG, OPT_REG)) - DEF_ASM_OP1(ltr, 0x0f00, 3, OPC_MODRM, OPT_EA | OPT_REG) - DEF_ASM_OP1(sgdt, 0x0f01, 0, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(sidt, 0x0f01, 1, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(sldt, 0x0f00, 0, OPC_MODRM, OPT_REG | OPT_EA) - DEF_ASM_OP1(smsw, 0x0f01, 4, OPC_MODRM, OPT_REG | OPT_EA) - DEF_ASM_OP1(str, 0x0f00, 1, OPC_MODRM, OPT_REG16| OPT_EA) - DEF_ASM_OP1(verr, 0x0f00, 4, OPC_MODRM, OPT_REG | OPT_EA) - DEF_ASM_OP1(verw, 0x0f00, 5, OPC_MODRM, OPT_REG | OPT_EA) - - /* 486 */ - DEF_ASM_OP1(bswap, 0x0fc8, 0, OPC_REG, OPT_REG32 ) -ALT(DEF_ASM_OP2(xaddb, 0x0fc0, 0, OPC_MODRM | OPC_BWLX, OPT_REG, OPT_REG | OPT_EA )) -ALT(DEF_ASM_OP2(cmpxchgb, 0x0fb0, 0, OPC_MODRM | OPC_BWLX, OPT_REG, OPT_REG | OPT_EA )) - DEF_ASM_OP1(invlpg, 0x0f01, 7, OPC_MODRM, OPT_EA ) - - DEF_ASM_OP2(boundl, 0x62, 0, OPC_MODRM, OPT_REG32, OPT_EA) - DEF_ASM_OP2(boundw, 0x6662, 0, OPC_MODRM, OPT_REG16, OPT_EA) - - /* pentium */ - DEF_ASM_OP1(cmpxchg8b, 0x0fc7, 1, OPC_MODRM, OPT_EA ) - - /* pentium pro */ -ALT(DEF_ASM_OP2(cmovo, 0x0f40, 0, OPC_MODRM | OPC_TEST | OPC_WLX, OPT_REGW | OPT_EA, OPT_REGW)) - DEF_ASM_OP2(fcmovb, 0xdac0, 0, OPC_REG, OPT_ST, OPT_ST0 ) - DEF_ASM_OP2(fcmove, 0xdac8, 0, OPC_REG, OPT_ST, OPT_ST0 ) - DEF_ASM_OP2(fcmovbe, 0xdad0, 0, OPC_REG, OPT_ST, OPT_ST0 ) - DEF_ASM_OP2(fcmovu, 0xdad8, 0, OPC_REG, OPT_ST, OPT_ST0 ) - DEF_ASM_OP2(fcmovnb, 0xdbc0, 0, OPC_REG, OPT_ST, OPT_ST0 ) - DEF_ASM_OP2(fcmovne, 0xdbc8, 0, OPC_REG, OPT_ST, OPT_ST0 ) - DEF_ASM_OP2(fcmovnbe, 0xdbd0, 0, OPC_REG, OPT_ST, OPT_ST0 ) - DEF_ASM_OP2(fcmovnu, 0xdbd8, 0, OPC_REG, OPT_ST, OPT_ST0 ) - - DEF_ASM_OP2(fucomi, 0xdbe8, 0, OPC_REG, OPT_ST, OPT_ST0 ) - DEF_ASM_OP2(fcomi, 0xdbf0, 0, OPC_REG, OPT_ST, OPT_ST0 ) - DEF_ASM_OP2(fucomip, 0xdfe8, 0, OPC_REG, OPT_ST, OPT_ST0 ) - DEF_ASM_OP2(fcomip, 0xdff0, 0, OPC_REG, OPT_ST, OPT_ST0 ) - - /* mmx */ - DEF_ASM_OP0(emms, 0x0f77) /* must be last OP0 */ - DEF_ASM_OP2(movd, 0x0f6e, 0, OPC_MODRM, OPT_EA | OPT_REG32, OPT_MMXSSE ) - DEF_ASM_OP2(movq, 0x0f6f, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX ) -ALT(DEF_ASM_OP2(movd, 0x0f7e, 0, OPC_MODRM, OPT_MMXSSE, OPT_EA | OPT_REG32 )) -ALT(DEF_ASM_OP2(movq, 0x0f7f, 0, OPC_MODRM, OPT_MMX, OPT_EA | OPT_MMX )) -ALT(DEF_ASM_OP2(movq, 0x660fd6, 0, OPC_MODRM, OPT_SSE, OPT_EA | OPT_SSE )) -ALT(DEF_ASM_OP2(movq, 0xf30f7e, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE )) - - DEF_ASM_OP2(packssdw, 0x0f6b, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(packsswb, 0x0f63, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(packuswb, 0x0f67, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(paddb, 0x0ffc, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(paddw, 0x0ffd, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(paddd, 0x0ffe, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(paddsb, 0x0fec, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(paddsw, 0x0fed, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(paddusb, 0x0fdc, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(paddusw, 0x0fdd, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pand, 0x0fdb, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pandn, 0x0fdf, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pcmpeqb, 0x0f74, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pcmpeqw, 0x0f75, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pcmpeqd, 0x0f76, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pcmpgtb, 0x0f64, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pcmpgtw, 0x0f65, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pcmpgtd, 0x0f66, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pmaddwd, 0x0ff5, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pmulhw, 0x0fe5, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pmullw, 0x0fd5, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(por, 0x0feb, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(psllw, 0x0ff1, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) -ALT(DEF_ASM_OP2(psllw, 0x0f71, 6, OPC_MODRM, OPT_IM8, OPT_MMXSSE )) - DEF_ASM_OP2(pslld, 0x0ff2, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) -ALT(DEF_ASM_OP2(pslld, 0x0f72, 6, OPC_MODRM, OPT_IM8, OPT_MMXSSE )) - DEF_ASM_OP2(psllq, 0x0ff3, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) -ALT(DEF_ASM_OP2(psllq, 0x0f73, 6, OPC_MODRM, OPT_IM8, OPT_MMXSSE )) - DEF_ASM_OP2(psraw, 0x0fe1, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) -ALT(DEF_ASM_OP2(psraw, 0x0f71, 4, OPC_MODRM, OPT_IM8, OPT_MMXSSE )) - DEF_ASM_OP2(psrad, 0x0fe2, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) -ALT(DEF_ASM_OP2(psrad, 0x0f72, 4, OPC_MODRM, OPT_IM8, OPT_MMXSSE )) - DEF_ASM_OP2(psrlw, 0x0fd1, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) -ALT(DEF_ASM_OP2(psrlw, 0x0f71, 2, OPC_MODRM, OPT_IM8, OPT_MMXSSE )) - DEF_ASM_OP2(psrld, 0x0fd2, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) -ALT(DEF_ASM_OP2(psrld, 0x0f72, 2, OPC_MODRM, OPT_IM8, OPT_MMXSSE )) - DEF_ASM_OP2(psrlq, 0x0fd3, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) -ALT(DEF_ASM_OP2(psrlq, 0x0f73, 2, OPC_MODRM, OPT_IM8, OPT_MMXSSE )) - DEF_ASM_OP2(psubb, 0x0ff8, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(psubw, 0x0ff9, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(psubd, 0x0ffa, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(psubsb, 0x0fe8, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(psubsw, 0x0fe9, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(psubusb, 0x0fd8, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(psubusw, 0x0fd9, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(punpckhbw, 0x0f68, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(punpckhwd, 0x0f69, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(punpckhdq, 0x0f6a, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(punpcklbw, 0x0f60, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(punpcklwd, 0x0f61, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(punpckldq, 0x0f62, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pxor, 0x0fef, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - - /* sse */ - DEF_ASM_OP1(ldmxcsr, 0x0fae, 2, OPC_MODRM, OPT_EA) - DEF_ASM_OP1(stmxcsr, 0x0fae, 3, OPC_MODRM, OPT_EA) - DEF_ASM_OP2(movups, 0x0f10, 0, OPC_MODRM, OPT_EA | OPT_REG32, OPT_SSE ) -ALT(DEF_ASM_OP2(movups, 0x0f11, 0, OPC_MODRM, OPT_SSE, OPT_EA | OPT_REG32 )) - DEF_ASM_OP2(movaps, 0x0f28, 0, OPC_MODRM, OPT_EA | OPT_REG32, OPT_SSE ) -ALT(DEF_ASM_OP2(movaps, 0x0f29, 0, OPC_MODRM, OPT_SSE, OPT_EA | OPT_REG32 )) - DEF_ASM_OP2(movhps, 0x0f16, 0, OPC_MODRM, OPT_EA | OPT_REG32, OPT_SSE ) -ALT(DEF_ASM_OP2(movhps, 0x0f17, 0, OPC_MODRM, OPT_SSE, OPT_EA | OPT_REG32 )) - DEF_ASM_OP2(addps, 0x0f58, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE ) - DEF_ASM_OP2(cvtpi2ps, 0x0f2a, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_SSE ) - DEF_ASM_OP2(cvtps2pi, 0x0f2d, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_MMX ) - DEF_ASM_OP2(cvttps2pi, 0x0f2c, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_MMX ) - DEF_ASM_OP2(divps, 0x0f5e, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE ) - DEF_ASM_OP2(maxps, 0x0f5f, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE ) - DEF_ASM_OP2(minps, 0x0f5d, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE ) - DEF_ASM_OP2(mulps, 0x0f59, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE ) - DEF_ASM_OP2(pavgb, 0x0fe0, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE ) - DEF_ASM_OP2(pavgw, 0x0fe3, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE ) - DEF_ASM_OP2(pmaxsw, 0x0fee, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pmaxub, 0x0fde, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pminsw, 0x0fea, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(pminub, 0x0fda, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE ) - DEF_ASM_OP2(rcpss, 0x0f53, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE ) - DEF_ASM_OP2(rsqrtps, 0x0f52, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE ) - DEF_ASM_OP2(sqrtps, 0x0f51, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE ) - DEF_ASM_OP2(subps, 0x0f5c, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE ) - -#undef ALT -#undef DEF_ASM_OP0 -#undef DEF_ASM_OP0L -#undef DEF_ASM_OP1 -#undef DEF_ASM_OP2 -#undef DEF_ASM_OP3 diff --git a/05/tcc-final/i386-gen.c b/05/tcc-final/i386-gen.c deleted file mode 100644 index 62bc2ad..0000000 --- a/05/tcc-final/i386-gen.c +++ /dev/null @@ -1,1140 +0,0 @@ -/* - * X86 code generator for TCC - * - * Copyright (c) 2001-2004 Fabrice Bellard - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifdef TARGET_DEFS_ONLY - -/* number of available registers */ -#define NB_REGS 5 -#define NB_ASM_REGS 8 -#define CONFIG_TCC_ASM - -/* a register can belong to several classes. The classes must be - sorted from more general to more precise (see gv2() code which does - assumptions on it). */ -#define RC_INT 0x0001 /* generic integer register */ -#define RC_FLOAT 0x0002 /* generic float register */ -#define RC_EAX 0x0004 -#define RC_ST0 0x0008 -#define RC_ECX 0x0010 -#define RC_EDX 0x0020 -#define RC_EBX 0x0040 - -#define RC_IRET RC_EAX /* function return: integer register */ -#define RC_IRE2 RC_EDX /* function return: second integer register */ -#define RC_FRET RC_ST0 /* function return: float register */ - -/* pretty names for the registers */ -enum { - TREG_EAX = 0, - TREG_ECX, - TREG_EDX, - TREG_EBX, - TREG_ST0, - TREG_ESP = 4 -}; - -/* return registers for function */ -#define REG_IRET TREG_EAX /* single word int return register */ -#define REG_IRE2 TREG_EDX /* second word return register (for long long) */ -#define REG_FRET TREG_ST0 /* float return register */ - -/* defined if function parameters must be evaluated in reverse order */ -#define INVERT_FUNC_PARAMS - -/* defined if structures are passed as pointers. Otherwise structures - are directly pushed on stack. */ -/* #define FUNC_STRUCT_PARAM_AS_PTR */ - -/* pointer size, in bytes */ -#define PTR_SIZE 4 - -/* long double size and alignment, in bytes */ -#define LDOUBLE_SIZE 12 -#define LDOUBLE_ALIGN 4 -/* maximum alignment (for aligned attribute support) */ -#define MAX_ALIGN 8 - -/* define if return values need to be extended explicitely - at caller side (for interfacing with non-TCC compilers) */ -#define PROMOTE_RET - -/******************************************************/ -#else /* ! TARGET_DEFS_ONLY */ -/******************************************************/ -#define USING_GLOBALS -#include "tcc.h" - -ST_DATA const char * const target_machine_defs = - "__i386__\0" - "__i386\0" - ; - -/* define to 1/0 to [not] have EBX as 4th register */ -#define USE_EBX 0 - -ST_DATA const int reg_classes[NB_REGS] = { - /* eax */ RC_INT | RC_EAX, - /* ecx */ RC_INT | RC_ECX, - /* edx */ RC_INT | RC_EDX, - /* ebx */ (RC_INT | RC_EBX) * USE_EBX, - /* st0 */ RC_FLOAT | RC_ST0, -}; - -static unsigned long func_sub_sp_offset; -static int func_ret_sub; -#ifdef CONFIG_TCC_BCHECK -static addr_t func_bound_offset; -static unsigned long func_bound_ind; -ST_DATA int func_bound_add_epilog; -static void gen_bounds_prolog(void); -static void gen_bounds_epilog(void); -#endif - -/* XXX: make it faster ? */ -ST_FUNC void g(int c) -{ - int ind1; - if (nocode_wanted) - return; - ind1 = ind + 1; - if (ind1 > cur_text_section->data_allocated) - section_realloc(cur_text_section, ind1); - cur_text_section->data[ind] = c; - ind = ind1; -} - -ST_FUNC void o(unsigned int c) -{ - while (c) { - g(c); - c = c >> 8; - } -} - -ST_FUNC void gen_le16(int v) -{ - g(v); - g(v >> 8); -} - -ST_FUNC void gen_le32(int c) -{ - g(c); - g(c >> 8); - g(c >> 16); - g(c >> 24); -} - -/* output a symbol and patch all calls to it */ -ST_FUNC void gsym_addr(int t, int a) -{ - while (t) { - unsigned char *ptr = cur_text_section->data + t; - uint32_t n = read32le(ptr); /* next value */ - write32le(ptr, a - t - 4); - t = n; - } -} - -/* instruction + 4 bytes data. Return the address of the data */ -static int oad(int c, int s) -{ - int t; - if (nocode_wanted) - return s; - o(c); - t = ind; - gen_le32(s); - return t; -} - -ST_FUNC void gen_fill_nops(int bytes) -{ - while (bytes--) - g(0x90); -} - -/* generate jmp to a label */ -#define gjmp2(instr,lbl) oad(instr,lbl) - -/* output constant with relocation if 'r & VT_SYM' is true */ -ST_FUNC void gen_addr32(int r, Sym *sym, int c) -{ - if (r & VT_SYM) - greloc(cur_text_section, sym, ind, R_386_32); - gen_le32(c); -} - -ST_FUNC void gen_addrpc32(int r, Sym *sym, int c) -{ - if (r & VT_SYM) - greloc(cur_text_section, sym, ind, R_386_PC32); - gen_le32(c - 4); -} - -/* generate a modrm reference. 'op_reg' contains the additional 3 - opcode bits */ -static void gen_modrm(int op_reg, int r, Sym *sym, int c) -{ - op_reg = op_reg << 3; - if ((r & VT_VALMASK) == VT_CONST) { - /* constant memory reference */ - o(0x05 | op_reg); - gen_addr32(r, sym, c); - } else if ((r & VT_VALMASK) == VT_LOCAL) { - /* currently, we use only ebp as base */ - if (c == (char)c) { - /* short reference */ - o(0x45 | op_reg); - g(c); - } else { - oad(0x85 | op_reg, c); - } - } else { - g(0x00 | op_reg | (r & VT_VALMASK)); - } -} - -/* load 'r' from value 'sv' */ -ST_FUNC void load(int r, SValue *sv) -{ - int v, t, ft, fc, fr; - SValue v1; - -#ifdef TCC_TARGET_PE - SValue v2; - sv = pe_getimport(sv, &v2); -#endif - - fr = sv->r; - ft = sv->type.t & ~VT_DEFSIGN; - fc = sv->c.i; - - ft &= ~(VT_VOLATILE | VT_CONSTANT); - - v = fr & VT_VALMASK; - if (fr & VT_LVAL) { - if (v == VT_LLOCAL) { - v1.type.t = VT_INT; - v1.r = VT_LOCAL | VT_LVAL; - v1.c.i = fc; - v1.sym = NULL; - fr = r; - if (!(reg_classes[fr] & RC_INT)) - fr = get_reg(RC_INT); - load(fr, &v1); - } - if ((ft & VT_BTYPE) == VT_FLOAT) { - o(0xd9); /* flds */ - r = 0; - } else if ((ft & VT_BTYPE) == VT_DOUBLE) { - o(0xdd); /* fldl */ - r = 0; - } else if ((ft & VT_BTYPE) == VT_LDOUBLE) { - o(0xdb); /* fldt */ - r = 5; - } else if ((ft & VT_TYPE) == VT_BYTE || (ft & VT_TYPE) == VT_BOOL) { - o(0xbe0f); /* movsbl */ - } else if ((ft & VT_TYPE) == (VT_BYTE | VT_UNSIGNED)) { - o(0xb60f); /* movzbl */ - } else if ((ft & VT_TYPE) == VT_SHORT) { - o(0xbf0f); /* movswl */ - } else if ((ft & VT_TYPE) == (VT_SHORT | VT_UNSIGNED)) { - o(0xb70f); /* movzwl */ - } else { - o(0x8b); /* movl */ - } - gen_modrm(r, fr, sv->sym, fc); - } else { - if (v == VT_CONST) { - o(0xb8 + r); /* mov $xx, r */ - gen_addr32(fr, sv->sym, fc); - } else if (v == VT_LOCAL) { - if (fc) { - o(0x8d); /* lea xxx(%ebp), r */ - gen_modrm(r, VT_LOCAL, sv->sym, fc); - } else { - o(0x89); - o(0xe8 + r); /* mov %ebp, r */ - } - } else if (v == VT_CMP) { - o(0x0f); /* setxx %br */ - o(fc); - o(0xc0 + r); - o(0xc0b60f + r * 0x90000); /* movzbl %al, %eax */ - } else if (v == VT_JMP || v == VT_JMPI) { - t = v & 1; - oad(0xb8 + r, t); /* mov $1, r */ - o(0x05eb); /* jmp after */ - gsym(fc); - oad(0xb8 + r, t ^ 1); /* mov $0, r */ - } else if (v != r) { - o(0x89); - o(0xc0 + r + v * 8); /* mov v, r */ - } - } -} - -/* store register 'r' in lvalue 'v' */ -ST_FUNC void store(int r, SValue *v) -{ - int fr, bt, ft, fc; - -#ifdef TCC_TARGET_PE - SValue v2; - v = pe_getimport(v, &v2); -#endif - - ft = v->type.t; - fc = v->c.i; - fr = v->r & VT_VALMASK; - ft &= ~(VT_VOLATILE | VT_CONSTANT); - bt = ft & VT_BTYPE; - /* XXX: incorrect if float reg to reg */ - if (bt == VT_FLOAT) { - o(0xd9); /* fsts */ - r = 2; - } else if (bt == VT_DOUBLE) { - o(0xdd); /* fstpl */ - r = 2; - } else if (bt == VT_LDOUBLE) { - o(0xc0d9); /* fld %st(0) */ - o(0xdb); /* fstpt */ - r = 7; - } else { - if (bt == VT_SHORT) - o(0x66); - if (bt == VT_BYTE || bt == VT_BOOL) - o(0x88); - else - o(0x89); - } - if (fr == VT_CONST || - fr == VT_LOCAL || - (v->r & VT_LVAL)) { - gen_modrm(r, v->r, v->sym, fc); - } else if (fr != r) { - o(0xc0 + fr + r * 8); /* mov r, fr */ - } -} - -static void gadd_sp(int val) -{ - if (val == (char)val) { - o(0xc483); - g(val); - } else { - oad(0xc481, val); /* add $xxx, %esp */ - } -} - -#if defined CONFIG_TCC_BCHECK || defined TCC_TARGET_PE -static void gen_static_call(int v) -{ - Sym *sym; - - sym = external_helper_sym(v); - oad(0xe8, -4); - greloc(cur_text_section, sym, ind-4, R_386_PC32); -} -#endif - -/* 'is_jmp' is '1' if it is a jump */ -static void gcall_or_jmp(int is_jmp) -{ - int r; - if ((vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST && (vtop->r & VT_SYM)) { - /* constant and relocation case */ - greloc(cur_text_section, vtop->sym, ind + 1, R_386_PC32); - oad(0xe8 + is_jmp, vtop->c.i - 4); /* call/jmp im */ - } else { - /* otherwise, indirect call */ - r = gv(RC_INT); - o(0xff); /* call/jmp *r */ - o(0xd0 + r + (is_jmp << 4)); - } -} - -static const uint8_t fastcall_regs[3] = { TREG_EAX, TREG_EDX, TREG_ECX }; -static const uint8_t fastcallw_regs[2] = { TREG_ECX, TREG_EDX }; - -/* Return the number of registers needed to return the struct, or 0 if - returning via struct pointer. */ -ST_FUNC int gfunc_sret(CType *vt, int variadic, CType *ret, int *ret_align, int *regsize) -{ -#if defined(TCC_TARGET_PE) || TARGETOS_FreeBSD || TARGETOS_OpenBSD - int size, align; - *ret_align = 1; // Never have to re-align return values for x86 - *regsize = 4; - size = type_size(vt, &align); - if (size > 8 || (size & (size - 1))) - return 0; - if (size == 8) - ret->t = VT_LLONG; - else if (size == 4) - ret->t = VT_INT; - else if (size == 2) - ret->t = VT_SHORT; - else - ret->t = VT_BYTE; - ret->ref = NULL; - return 1; -#else - *ret_align = 1; // Never have to re-align return values for x86 - return 0; -#endif -} - -/* Generate function call. The function address is pushed first, then - all the parameters in call order. This functions pops all the - parameters and the function address. */ -ST_FUNC void gfunc_call(int nb_args) -{ - int size, align, r, args_size, i, func_call; - Sym *func_sym; - -#ifdef CONFIG_TCC_BCHECK - if (tcc_state->do_bounds_check) - gbound_args(nb_args); -#endif - - args_size = 0; - for(i = 0;i < nb_args; i++) { - if ((vtop->type.t & VT_BTYPE) == VT_STRUCT) { - size = type_size(&vtop->type, &align); - /* align to stack align size */ - size = (size + 3) & ~3; - /* allocate the necessary size on stack */ -#ifdef TCC_TARGET_PE - if (size >= 4096) { - r = get_reg(RC_EAX); - oad(0x68, size); // push size - /* cannot call normal 'alloca' with bound checking */ - gen_static_call(tok_alloc_const("__alloca")); - gadd_sp(4); - } else -#endif - { - oad(0xec81, size); /* sub $xxx, %esp */ - /* generate structure store */ - r = get_reg(RC_INT); - o(0xe089 + (r << 8)); /* mov %esp, r */ - } - vset(&vtop->type, r | VT_LVAL, 0); - vswap(); - vstore(); - args_size += size; - } else if (is_float(vtop->type.t)) { - gv(RC_FLOAT); /* only one float register */ - if ((vtop->type.t & VT_BTYPE) == VT_FLOAT) - size = 4; - else if ((vtop->type.t & VT_BTYPE) == VT_DOUBLE) - size = 8; - else - size = 12; - oad(0xec81, size); /* sub $xxx, %esp */ - if (size == 12) - o(0x7cdb); - else - o(0x5cd9 + size - 4); /* fstp[s|l] 0(%esp) */ - g(0x24); - g(0x00); - args_size += size; - } else { - /* simple type (currently always same size) */ - /* XXX: implicit cast ? */ - r = gv(RC_INT); - if ((vtop->type.t & VT_BTYPE) == VT_LLONG) { - size = 8; - o(0x50 + vtop->r2); /* push r */ - } else { - size = 4; - } - o(0x50 + r); /* push r */ - args_size += size; - } - vtop--; - } - save_regs(0); /* save used temporary registers */ - func_sym = vtop->type.ref; - func_call = func_sym->f.func_call; - /* fast call case */ - if ((func_call >= FUNC_FASTCALL1 && func_call <= FUNC_FASTCALL3) || - func_call == FUNC_FASTCALLW) { - int fastcall_nb_regs; - const uint8_t *fastcall_regs_ptr; - if (func_call == FUNC_FASTCALLW) { - fastcall_regs_ptr = fastcallw_regs; - fastcall_nb_regs = 2; - } else { - fastcall_regs_ptr = fastcall_regs; - fastcall_nb_regs = func_call - FUNC_FASTCALL1 + 1; - } - for(i = 0;i < fastcall_nb_regs; i++) { - if (args_size <= 0) - break; - o(0x58 + fastcall_regs_ptr[i]); /* pop r */ - /* XXX: incorrect for struct/floats */ - args_size -= 4; - } - } -#if !defined(TCC_TARGET_PE) && !TARGETOS_FreeBSD || TARGETOS_OpenBSD - else if ((vtop->type.ref->type.t & VT_BTYPE) == VT_STRUCT) - args_size -= 4; -#endif - - gcall_or_jmp(0); - - if (args_size && func_call != FUNC_STDCALL && func_call != FUNC_FASTCALLW) - gadd_sp(args_size); - vtop--; -} - -#ifdef TCC_TARGET_PE -#define FUNC_PROLOG_SIZE (10 + USE_EBX) -#else -#define FUNC_PROLOG_SIZE (9 + USE_EBX) -#endif - -/* generate function prolog of type 't' */ -ST_FUNC void gfunc_prolog(Sym *func_sym) -{ - CType *func_type = &func_sym->type; - int addr, align, size, func_call, fastcall_nb_regs; - int param_index, param_addr; - const uint8_t *fastcall_regs_ptr; - Sym *sym; - CType *type; - - sym = func_type->ref; - func_call = sym->f.func_call; - addr = 8; - loc = 0; - func_vc = 0; - - if (func_call >= FUNC_FASTCALL1 && func_call <= FUNC_FASTCALL3) { - fastcall_nb_regs = func_call - FUNC_FASTCALL1 + 1; - fastcall_regs_ptr = fastcall_regs; - } else if (func_call == FUNC_FASTCALLW) { - fastcall_nb_regs = 2; - fastcall_regs_ptr = fastcallw_regs; - } else { - fastcall_nb_regs = 0; - fastcall_regs_ptr = NULL; - } - param_index = 0; - - ind += FUNC_PROLOG_SIZE; - func_sub_sp_offset = ind; - /* if the function returns a structure, then add an - implicit pointer parameter */ -#if defined(TCC_TARGET_PE) || TARGETOS_FreeBSD || TARGETOS_OpenBSD - size = type_size(&func_vt,&align); - if (((func_vt.t & VT_BTYPE) == VT_STRUCT) - && (size > 8 || (size & (size - 1)))) { -#else - if ((func_vt.t & VT_BTYPE) == VT_STRUCT) { -#endif - /* XXX: fastcall case ? */ - func_vc = addr; - addr += 4; - param_index++; - } - /* define parameters */ - while ((sym = sym->next) != NULL) { - type = &sym->type; - size = type_size(type, &align); - size = (size + 3) & ~3; -#ifdef FUNC_STRUCT_PARAM_AS_PTR - /* structs are passed as pointer */ - if ((type->t & VT_BTYPE) == VT_STRUCT) { - size = 4; - } -#endif - if (param_index < fastcall_nb_regs) { - /* save FASTCALL register */ - loc -= 4; - o(0x89); /* movl */ - gen_modrm(fastcall_regs_ptr[param_index], VT_LOCAL, NULL, loc); - param_addr = loc; - } else { - param_addr = addr; - addr += size; - } - sym_push(sym->v & ~SYM_FIELD, type, - VT_LOCAL | VT_LVAL, param_addr); - param_index++; - } - func_ret_sub = 0; - /* pascal type call or fastcall ? */ - if (func_call == FUNC_STDCALL || func_call == FUNC_FASTCALLW) - func_ret_sub = addr - 8; -#if !defined(TCC_TARGET_PE) && !TARGETOS_FreeBSD || TARGETOS_OpenBSD - else if (func_vc) - func_ret_sub = 4; -#endif - -#ifdef CONFIG_TCC_BCHECK - if (tcc_state->do_bounds_check) - gen_bounds_prolog(); -#endif -} - -/* generate function epilog */ -ST_FUNC void gfunc_epilog(void) -{ - addr_t v, saved_ind; - -#ifdef CONFIG_TCC_BCHECK - if (tcc_state->do_bounds_check) - gen_bounds_epilog(); -#endif - - /* align local size to word & save local variables */ - v = (-loc + 3) & -4; - -#if USE_EBX - o(0x8b); - gen_modrm(TREG_EBX, VT_LOCAL, NULL, -(v+4)); -#endif - - o(0xc9); /* leave */ - if (func_ret_sub == 0) { - o(0xc3); /* ret */ - } else { - o(0xc2); /* ret n */ - g(func_ret_sub); - g(func_ret_sub >> 8); - } - saved_ind = ind; - ind = func_sub_sp_offset - FUNC_PROLOG_SIZE; -#ifdef TCC_TARGET_PE - if (v >= 4096) { - oad(0xb8, v); /* mov stacksize, %eax */ - gen_static_call(TOK___chkstk); /* call __chkstk, (does the stackframe too) */ - } else -#endif - { - o(0xe58955); /* push %ebp, mov %esp, %ebp */ - o(0xec81); /* sub esp, stacksize */ - gen_le32(v); -#ifdef TCC_TARGET_PE - o(0x90); /* adjust to FUNC_PROLOG_SIZE */ -#endif - } - o(0x53 * USE_EBX); /* push ebx */ - ind = saved_ind; -} - -/* generate a jump to a label */ -ST_FUNC int gjmp(int t) -{ - return gjmp2(0xe9, t); -} - -/* generate a jump to a fixed address */ -ST_FUNC void gjmp_addr(int a) -{ - int r; - r = a - ind - 2; - if (r == (char)r) { - g(0xeb); - g(r); - } else { - oad(0xe9, a - ind - 5); - } -} - -#if 0 -/* generate a jump to a fixed address */ -ST_FUNC void gjmp_cond_addr(int a, int op) -{ - int r = a - ind - 2; - if (r == (char)r) - g(op - 32), g(r); - else - g(0x0f), gjmp2(op - 16, r - 4); -} -#endif - -ST_FUNC int gjmp_append(int n, int t) -{ - void *p; - /* insert vtop->c jump list in t */ - if (n) { - uint32_t n1 = n, n2; - while ((n2 = read32le(p = cur_text_section->data + n1))) - n1 = n2; - write32le(p, t); - t = n; - } - return t; -} - -ST_FUNC int gjmp_cond(int op, int t) -{ - g(0x0f); - t = gjmp2(op - 16, t); - return t; -} - -ST_FUNC void gen_opi(int op) -{ - int r, fr, opc, c; - - switch(op) { - case '+': - case TOK_ADDC1: /* add with carry generation */ - opc = 0; - gen_op8: - if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) { - /* constant case */ - vswap(); - r = gv(RC_INT); - vswap(); - c = vtop->c.i; - if (c == (char)c) { - /* generate inc and dec for smaller code */ - if ((c == 1 || c == -1) && (op == '+' || op == '-')) { - opc = (c == 1) ^ (op == '+'); - o (0x40 | (opc << 3) | r); // inc,dec - } else { - o(0x83); - o(0xc0 | (opc << 3) | r); - g(c); - } - } else { - o(0x81); - oad(0xc0 | (opc << 3) | r, c); - } - } else { - gv2(RC_INT, RC_INT); - r = vtop[-1].r; - fr = vtop[0].r; - o((opc << 3) | 0x01); - o(0xc0 + r + fr * 8); - } - vtop--; - if (op >= TOK_ULT && op <= TOK_GT) - vset_VT_CMP(op); - break; - case '-': - case TOK_SUBC1: /* sub with carry generation */ - opc = 5; - goto gen_op8; - case TOK_ADDC2: /* add with carry use */ - opc = 2; - goto gen_op8; - case TOK_SUBC2: /* sub with carry use */ - opc = 3; - goto gen_op8; - case '&': - opc = 4; - goto gen_op8; - case '^': - opc = 6; - goto gen_op8; - case '|': - opc = 1; - goto gen_op8; - case '*': - gv2(RC_INT, RC_INT); - r = vtop[-1].r; - fr = vtop[0].r; - vtop--; - o(0xaf0f); /* imul fr, r */ - o(0xc0 + fr + r * 8); - break; - case TOK_SHL: - opc = 4; - goto gen_shift; - case TOK_SHR: - opc = 5; - goto gen_shift; - case TOK_SAR: - opc = 7; - gen_shift: - opc = 0xc0 | (opc << 3); - if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) { - /* constant case */ - vswap(); - r = gv(RC_INT); - vswap(); - c = vtop->c.i & 0x1f; - o(0xc1); /* shl/shr/sar $xxx, r */ - o(opc | r); - g(c); - } else { - /* we generate the shift in ecx */ - gv2(RC_INT, RC_ECX); - r = vtop[-1].r; - o(0xd3); /* shl/shr/sar %cl, r */ - o(opc | r); - } - vtop--; - break; - case '/': - case TOK_UDIV: - case TOK_PDIV: - case '%': - case TOK_UMOD: - case TOK_UMULL: - /* first operand must be in eax */ - /* XXX: need better constraint for second operand */ - gv2(RC_EAX, RC_ECX); - r = vtop[-1].r; - fr = vtop[0].r; - vtop--; - save_reg(TREG_EDX); - /* save EAX too if used otherwise */ - save_reg_upstack(TREG_EAX, 1); - if (op == TOK_UMULL) { - o(0xf7); /* mul fr */ - o(0xe0 + fr); - vtop->r2 = TREG_EDX; - r = TREG_EAX; - } else { - if (op == TOK_UDIV || op == TOK_UMOD) { - o(0xf7d231); /* xor %edx, %edx, div fr, %eax */ - o(0xf0 + fr); - } else { - o(0xf799); /* cltd, idiv fr, %eax */ - o(0xf8 + fr); - } - if (op == '%' || op == TOK_UMOD) - r = TREG_EDX; - else - r = TREG_EAX; - } - vtop->r = r; - break; - default: - opc = 7; - goto gen_op8; - } -} - -/* generate a floating point operation 'v = t1 op t2' instruction. The - two operands are guaranteed to have the same floating point type */ -/* XXX: need to use ST1 too */ -ST_FUNC void gen_opf(int op) -{ - int a, ft, fc, swapped, r; - - if (op == TOK_NEG) { /* unary minus */ - gv(RC_FLOAT); - o(0xe0d9); /* fchs */ - return; - } - - /* convert constants to memory references */ - if ((vtop[-1].r & (VT_VALMASK | VT_LVAL)) == VT_CONST) { - vswap(); - gv(RC_FLOAT); - vswap(); - } - if ((vtop[0].r & (VT_VALMASK | VT_LVAL)) == VT_CONST) - gv(RC_FLOAT); - - /* must put at least one value in the floating point register */ - if ((vtop[-1].r & VT_LVAL) && - (vtop[0].r & VT_LVAL)) { - vswap(); - gv(RC_FLOAT); - vswap(); - } - swapped = 0; - /* swap the stack if needed so that t1 is the register and t2 is - the memory reference */ - if (vtop[-1].r & VT_LVAL) { - vswap(); - swapped = 1; - } - if (op >= TOK_ULT && op <= TOK_GT) { - /* load on stack second operand */ - load(TREG_ST0, vtop); - save_reg(TREG_EAX); /* eax is used by FP comparison code */ - if (op == TOK_GE || op == TOK_GT) - swapped = !swapped; - else if (op == TOK_EQ || op == TOK_NE) - swapped = 0; - if (swapped) - o(0xc9d9); /* fxch %st(1) */ - if (op == TOK_EQ || op == TOK_NE) - o(0xe9da); /* fucompp */ - else - o(0xd9de); /* fcompp */ - o(0xe0df); /* fnstsw %ax */ - if (op == TOK_EQ) { - o(0x45e480); /* and $0x45, %ah */ - o(0x40fC80); /* cmp $0x40, %ah */ - } else if (op == TOK_NE) { - o(0x45e480); /* and $0x45, %ah */ - o(0x40f480); /* xor $0x40, %ah */ - op = TOK_NE; - } else if (op == TOK_GE || op == TOK_LE) { - o(0x05c4f6); /* test $0x05, %ah */ - op = TOK_EQ; - } else { - o(0x45c4f6); /* test $0x45, %ah */ - op = TOK_EQ; - } - vtop--; - vset_VT_CMP(op); - } else { - /* no memory reference possible for long double operations */ - if ((vtop->type.t & VT_BTYPE) == VT_LDOUBLE) { - load(TREG_ST0, vtop); - swapped = !swapped; - } - - switch(op) { - default: - case '+': - a = 0; - break; - case '-': - a = 4; - if (swapped) - a++; - break; - case '*': - a = 1; - break; - case '/': - a = 6; - if (swapped) - a++; - break; - } - ft = vtop->type.t; - fc = vtop->c.i; - if ((ft & VT_BTYPE) == VT_LDOUBLE) { - o(0xde); /* fxxxp %st, %st(1) */ - o(0xc1 + (a << 3)); - } else { - /* if saved lvalue, then we must reload it */ - r = vtop->r; - if ((r & VT_VALMASK) == VT_LLOCAL) { - SValue v1; - r = get_reg(RC_INT); - v1.type.t = VT_INT; - v1.r = VT_LOCAL | VT_LVAL; - v1.c.i = fc; - v1.sym = NULL; - load(r, &v1); - fc = 0; - } - - if ((ft & VT_BTYPE) == VT_DOUBLE) - o(0xdc); - else - o(0xd8); - gen_modrm(a, r, vtop->sym, fc); - } - vtop--; - } -} - -/* convert integers to fp 't' type. Must handle 'int', 'unsigned int' - and 'long long' cases. */ -ST_FUNC void gen_cvt_itof(int t) -{ - save_reg(TREG_ST0); - gv(RC_INT); - if ((vtop->type.t & VT_BTYPE) == VT_LLONG) { - /* signed long long to float/double/long double (unsigned case - is handled generically) */ - o(0x50 + vtop->r2); /* push r2 */ - o(0x50 + (vtop->r & VT_VALMASK)); /* push r */ - o(0x242cdf); /* fildll (%esp) */ - o(0x08c483); /* add $8, %esp */ - vtop->r2 = VT_CONST; - } else if ((vtop->type.t & (VT_BTYPE | VT_UNSIGNED)) == - (VT_INT | VT_UNSIGNED)) { - /* unsigned int to float/double/long double */ - o(0x6a); /* push $0 */ - g(0x00); - o(0x50 + (vtop->r & VT_VALMASK)); /* push r */ - o(0x242cdf); /* fildll (%esp) */ - o(0x08c483); /* add $8, %esp */ - } else { - /* int to float/double/long double */ - o(0x50 + (vtop->r & VT_VALMASK)); /* push r */ - o(0x2404db); /* fildl (%esp) */ - o(0x04c483); /* add $4, %esp */ - } - vtop->r2 = VT_CONST; - vtop->r = TREG_ST0; -} - -/* convert fp to int 't' type */ -ST_FUNC void gen_cvt_ftoi(int t) -{ - int bt = vtop->type.t & VT_BTYPE; - if (bt == VT_FLOAT) - vpush_helper_func(TOK___fixsfdi); - else if (bt == VT_LDOUBLE) - vpush_helper_func(TOK___fixxfdi); - else - vpush_helper_func(TOK___fixdfdi); - vswap(); - gfunc_call(1); - vpushi(0); - vtop->r = REG_IRET; - if ((t & VT_BTYPE) == VT_LLONG) - vtop->r2 = REG_IRE2; -} - -/* convert from one floating point type to another */ -ST_FUNC void gen_cvt_ftof(int t) -{ - /* all we have to do on i386 is to put the float in a register */ - gv(RC_FLOAT); -} - -/* char/short to int conversion */ -ST_FUNC void gen_cvt_csti(int t) -{ - int r, sz, xl; - r = gv(RC_INT); - sz = !(t & VT_UNSIGNED); - xl = (t & VT_BTYPE) == VT_SHORT; - o(0xc0b60f /* mov[sz] %a[xl], %eax */ - | (sz << 3 | xl) << 8 - | (r << 3 | r) << 16 - ); -} - -/* increment tcov counter */ -ST_FUNC void gen_increment_tcov (SValue *sv) -{ - o(0x0583); /* addl $1, xxx */ - greloc(cur_text_section, sv->sym, ind, R_386_32); - gen_le32(0); - o(1); - o(0x1583); /* addcl $0, xxx */ - greloc(cur_text_section, sv->sym, ind, R_386_32); - gen_le32(4); - g(0); -} - -/* computed goto support */ -ST_FUNC void ggoto(void) -{ - gcall_or_jmp(1); - vtop--; -} - -/* bound check support functions */ -#ifdef CONFIG_TCC_BCHECK - -static void gen_bounds_prolog(void) -{ - /* leave some room for bound checking code */ - func_bound_offset = lbounds_section->data_offset; - func_bound_ind = ind; - func_bound_add_epilog = 0; - oad(0xb8, 0); /* lbound section pointer */ - oad(0xb8, 0); /* call to function */ -} - -static void gen_bounds_epilog(void) -{ - addr_t saved_ind; - addr_t *bounds_ptr; - Sym *sym_data; - int offset_modified = func_bound_offset != lbounds_section->data_offset; - - if (!offset_modified && !func_bound_add_epilog) - return; - - /* add end of table info */ - bounds_ptr = section_ptr_add(lbounds_section, sizeof(addr_t)); - *bounds_ptr = 0; - - sym_data = get_sym_ref(&char_pointer_type, lbounds_section, - func_bound_offset, PTR_SIZE); - - /* generate bound local allocation */ - if (offset_modified) { - saved_ind = ind; - ind = func_bound_ind; - greloc(cur_text_section, sym_data, ind + 1, R_386_32); - ind = ind + 5; - gen_static_call(TOK___bound_local_new); - ind = saved_ind; - } - - /* generate bound check local freeing */ - o(0x5250); /* save returned value, if any */ - greloc(cur_text_section, sym_data, ind + 1, R_386_32); - oad(0xb8, 0); /* mov %eax, xxx */ - gen_static_call(TOK___bound_local_delete); - o(0x585a); /* restore returned value, if any */ -} -#endif - -/* Save the stack pointer onto the stack */ -ST_FUNC void gen_vla_sp_save(int addr) { - /* mov %esp,addr(%ebp)*/ - o(0x89); - gen_modrm(TREG_ESP, VT_LOCAL, NULL, addr); -} - -/* Restore the SP from a location on the stack */ -ST_FUNC void gen_vla_sp_restore(int addr) { - o(0x8b); - gen_modrm(TREG_ESP, VT_LOCAL, NULL, addr); -} - -/* Subtract from the stack pointer, and push the resulting value onto the stack */ -ST_FUNC void gen_vla_alloc(CType *type, int align) { - int use_call = 0; - -#if defined(CONFIG_TCC_BCHECK) - use_call = tcc_state->do_bounds_check; -#endif -#ifdef TCC_TARGET_PE /* alloca does more than just adjust %rsp on Windows */ - use_call = 1; -#endif - if (use_call) - { - vpush_helper_func(TOK_alloca); - vswap(); /* Move alloca ref past allocation size */ - gfunc_call(1); - } - else { - int r; - r = gv(RC_INT); /* allocation size */ - /* sub r,%rsp */ - o(0x2b); - o(0xe0 | r); - /* We align to 16 bytes rather than align */ - /* and ~15, %esp */ - o(0xf0e483); - vpop(); - } -} - -/* end of X86 code generator */ -/*************************************************************/ -#endif -/*************************************************************/ diff --git a/05/tcc-final/i386-link.c b/05/tcc-final/i386-link.c deleted file mode 100644 index 11581f5..0000000 --- a/05/tcc-final/i386-link.c +++ /dev/null @@ -1,325 +0,0 @@ -#ifdef TARGET_DEFS_ONLY - -#define EM_TCC_TARGET EM_386 - -/* relocation type for 32 bit data relocation */ -#define R_DATA_32 R_386_32 -#define R_DATA_PTR R_386_32 -#define R_JMP_SLOT R_386_JMP_SLOT -#define R_GLOB_DAT R_386_GLOB_DAT -#define R_COPY R_386_COPY -#define R_RELATIVE R_386_RELATIVE - -#define R_NUM R_386_NUM - -#define ELF_START_ADDR 0x08048000 -#define ELF_PAGE_SIZE 0x1000 - -#define PCRELATIVE_DLLPLT 0 -#define RELOCATE_DLLPLT 1 - -#else /* !TARGET_DEFS_ONLY */ - -#include "tcc.h" - -#ifdef NEED_RELOC_TYPE -/* Returns 1 for a code relocation, 0 for a data relocation. For unknown - relocations, returns -1. */ -int code_reloc (int reloc_type) -{ - switch (reloc_type) { - case R_386_RELATIVE: - case R_386_16: - case R_386_32: - case R_386_GOTPC: - case R_386_GOTOFF: - case R_386_GOT32: - case R_386_GOT32X: - case R_386_GLOB_DAT: - case R_386_COPY: - case R_386_TLS_GD: - case R_386_TLS_LDM: - case R_386_TLS_LDO_32: - case R_386_TLS_LE: - return 0; - - case R_386_PC16: - case R_386_PC32: - case R_386_PLT32: - case R_386_JMP_SLOT: - return 1; - } - return -1; -} - -/* Returns an enumerator to describe whether and when the relocation needs a - GOT and/or PLT entry to be created. See tcc.h for a description of the - different values. */ -int gotplt_entry_type (int reloc_type) -{ - switch (reloc_type) { - case R_386_RELATIVE: - case R_386_16: - case R_386_GLOB_DAT: - case R_386_JMP_SLOT: - case R_386_COPY: - return NO_GOTPLT_ENTRY; - - case R_386_32: - /* This relocations shouldn't normally need GOT or PLT - slots if it weren't for simplicity in the code generator. - See our caller for comments. */ - return AUTO_GOTPLT_ENTRY; - - case R_386_PC16: - case R_386_PC32: - return AUTO_GOTPLT_ENTRY; - - case R_386_GOTPC: - case R_386_GOTOFF: - return BUILD_GOT_ONLY; - - case R_386_GOT32: - case R_386_GOT32X: - case R_386_PLT32: - case R_386_TLS_GD: - case R_386_TLS_LDM: - case R_386_TLS_LDO_32: - case R_386_TLS_LE: - return ALWAYS_GOTPLT_ENTRY; - } - return -1; -} - -#ifdef NEED_BUILD_GOT -ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr) -{ - Section *plt = s1->plt; - uint8_t *p; - int modrm; - unsigned plt_offset, relofs; - - /* on i386 if we build a DLL, we add a %ebx offset */ - if (s1->output_type == TCC_OUTPUT_DLL) - modrm = 0xa3; - else - modrm = 0x25; - - /* empty PLT: create PLT0 entry that pushes the library identifier - (GOT + PTR_SIZE) and jumps to ld.so resolution routine - (GOT + 2 * PTR_SIZE) */ - if (plt->data_offset == 0) { - p = section_ptr_add(plt, 16); - p[0] = 0xff; /* pushl got + PTR_SIZE */ - p[1] = modrm + 0x10; - write32le(p + 2, PTR_SIZE); - p[6] = 0xff; /* jmp *(got + PTR_SIZE * 2) */ - p[7] = modrm; - write32le(p + 8, PTR_SIZE * 2); - } - plt_offset = plt->data_offset; - - /* The PLT slot refers to the relocation entry it needs via offset. - The reloc entry is created below, so its offset is the current - data_offset */ - relofs = s1->plt->reloc ? s1->plt->reloc->data_offset : 0; - - /* Jump to GOT entry where ld.so initially put the address of ip + 4 */ - p = section_ptr_add(plt, 16); - p[0] = 0xff; /* jmp *(got + x) */ - p[1] = modrm; - write32le(p + 2, got_offset); - p[6] = 0x68; /* push $xxx */ - write32le(p + 7, relofs - sizeof (ElfW_Rel)); - p[11] = 0xe9; /* jmp plt_start */ - write32le(p + 12, -(plt->data_offset)); - return plt_offset; -} - -/* relocate the PLT: compute addresses and offsets in the PLT now that final - address for PLT and GOT are known (see fill_program_header) */ -ST_FUNC void relocate_plt(TCCState *s1) -{ - uint8_t *p, *p_end; - - if (!s1->plt) - return; - - p = s1->plt->data; - p_end = p + s1->plt->data_offset; - - if (s1->output_type != TCC_OUTPUT_DLL && p < p_end) { - add32le(p + 2, s1->got->sh_addr); - add32le(p + 8, s1->got->sh_addr); - p += 16; - while (p < p_end) { - add32le(p + 2, s1->got->sh_addr); - p += 16; - } - } - - if (s1->plt->reloc) { - ElfW_Rel *rel; - int x = s1->plt->sh_addr + 16 + 6; - p = s1->got->data; - for_each_elem(s1->plt->reloc, 0, rel, ElfW_Rel) { - write32le(p + rel->r_offset, x); - x += 16; - } - } -} -#endif -#endif - -void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val) -{ - int sym_index, esym_index; - - sym_index = ELFW(R_SYM)(rel->r_info); - - switch (type) { - case R_386_32: - if (s1->output_type == TCC_OUTPUT_DLL) { - esym_index = get_sym_attr(s1, sym_index, 0)->dyn_index; - qrel->r_offset = rel->r_offset; - if (esym_index) { - qrel->r_info = ELFW(R_INFO)(esym_index, R_386_32); - qrel++; - return; - } else { - qrel->r_info = ELFW(R_INFO)(0, R_386_RELATIVE); - qrel++; - } - } - add32le(ptr, val); - return; - case R_386_PC32: - if (s1->output_type == TCC_OUTPUT_DLL) { - /* DLL relocation */ - esym_index = get_sym_attr(s1, sym_index, 0)->dyn_index; - if (esym_index) { - qrel->r_offset = rel->r_offset; - qrel->r_info = ELFW(R_INFO)(esym_index, R_386_PC32); - qrel++; - return; - } - } - add32le(ptr, val - addr); - return; - case R_386_PLT32: - add32le(ptr, val - addr); - return; - case R_386_GLOB_DAT: - case R_386_JMP_SLOT: - write32le(ptr, val); - return; - case R_386_GOTPC: - add32le(ptr, s1->got->sh_addr - addr); - return; - case R_386_GOTOFF: - add32le(ptr, val - s1->got->sh_addr); - return; - case R_386_GOT32: - case R_386_GOT32X: - /* we load the got offset */ - add32le(ptr, get_sym_attr(s1, sym_index, 0)->got_offset); - return; - case R_386_16: - if (s1->output_format != TCC_OUTPUT_FORMAT_BINARY) { - output_file: - tcc_error("can only produce 16-bit binary files"); - } - write16le(ptr, read16le(ptr) + val); - return; - case R_386_PC16: - if (s1->output_format != TCC_OUTPUT_FORMAT_BINARY) - goto output_file; - write16le(ptr, read16le(ptr) + val - addr); - return; - case R_386_RELATIVE: -#ifdef TCC_TARGET_PE - add32le(ptr, val - s1->pe_imagebase); -#endif - /* do nothing */ - return; - case R_386_COPY: - /* This relocation must copy initialized data from the library - to the program .bss segment. Currently made like for ARM - (to remove noise of default case). Is this true? - */ - return; - case R_386_TLS_GD: - { - static const unsigned char expect[] = { - /* lea 0(,%ebx,1),%eax */ - 0x8d, 0x04, 0x1d, 0x00, 0x00, 0x00, 0x00, - /* call __tls_get_addr@PLT */ - 0xe8, 0xfc, 0xff, 0xff, 0xff }; - static const unsigned char replace[] = { - /* mov %gs:0,%eax */ - 0x65, 0xa1, 0x00, 0x00, 0x00, 0x00, - /* sub 0,%eax */ - 0x81, 0xe8, 0x00, 0x00, 0x00, 0x00 }; - - if (memcmp (ptr-3, expect, sizeof(expect)) == 0) { - ElfW(Sym) *sym; - Section *sec; - int32_t x; - - memcpy(ptr-3, replace, sizeof(replace)); - rel[1].r_info = ELFW(R_INFO)(0, R_386_NONE); - sym = &((ElfW(Sym) *)symtab_section->data)[sym_index]; - sec = s1->sections[sym->st_shndx]; - x = sym->st_value - sec->sh_addr - sec->data_offset; - add32le(ptr + 5, -x); - } - else - tcc_error("unexpected R_386_TLS_GD pattern"); - } - return; - case R_386_TLS_LDM: - { - static const unsigned char expect[] = { - /* lea 0(%ebx),%eax */ - 0x8d, 0x83, 0x00, 0x00, 0x00, 0x00, - /* call __tls_get_addr@PLT */ - 0xe8, 0xfc, 0xff, 0xff, 0xff }; - static const unsigned char replace[] = { - /* mov %gs:0,%eax */ - 0x65, 0xa1, 0x00, 0x00, 0x00, 0x00, - /* nop */ - 0x90, - /* lea 0(%esi,%eiz,1),%esi */ - 0x8d, 0x74, 0x26, 0x00 }; - - if (memcmp (ptr-2, expect, sizeof(expect)) == 0) { - memcpy(ptr-2, replace, sizeof(replace)); - rel[1].r_info = ELFW(R_INFO)(0, R_386_NONE); - } - else - tcc_error("unexpected R_386_TLS_LDM pattern"); - } - return; - case R_386_TLS_LDO_32: - case R_386_TLS_LE: - { - ElfW(Sym) *sym; - Section *sec; - int32_t x; - - sym = &((ElfW(Sym) *)symtab_section->data)[sym_index]; - sec = s1->sections[sym->st_shndx]; - x = val - sec->sh_addr - sec->data_offset; - add32le(ptr, x); - } - return; - case R_386_NONE: - return; - default: - fprintf(stderr,"FIXME: handle reloc type %d at %x [%p] to %x\n", - type, (unsigned)addr, ptr, (unsigned)val); - return; - } -} - -#endif /* !TARGET_DEFS_ONLY */ diff --git a/05/tcc-final/i386-tok.h b/05/tcc-final/i386-tok.h deleted file mode 100644 index e3ef2c7..0000000 --- a/05/tcc-final/i386-tok.h +++ /dev/null @@ -1,329 +0,0 @@ -/* ------------------------------------------------------------------ */ -/* WARNING: relative order of tokens is important. */ - -#define DEF_BWL(x) \ - DEF(TOK_ASM_ ## x ## b, #x "b") \ - DEF(TOK_ASM_ ## x ## w, #x "w") \ - DEF(TOK_ASM_ ## x ## l, #x "l") \ - DEF(TOK_ASM_ ## x, #x) -#define DEF_WL(x) \ - DEF(TOK_ASM_ ## x ## w, #x "w") \ - DEF(TOK_ASM_ ## x ## l, #x "l") \ - DEF(TOK_ASM_ ## x, #x) -#ifdef TCC_TARGET_X86_64 -# define DEF_BWLQ(x) \ - DEF(TOK_ASM_ ## x ## b, #x "b") \ - DEF(TOK_ASM_ ## x ## w, #x "w") \ - DEF(TOK_ASM_ ## x ## l, #x "l") \ - DEF(TOK_ASM_ ## x ## q, #x "q") \ - DEF(TOK_ASM_ ## x, #x) -# define DEF_WLQ(x) \ - DEF(TOK_ASM_ ## x ## w, #x "w") \ - DEF(TOK_ASM_ ## x ## l, #x "l") \ - DEF(TOK_ASM_ ## x ## q, #x "q") \ - DEF(TOK_ASM_ ## x, #x) -# define DEF_BWLX DEF_BWLQ -# define DEF_WLX DEF_WLQ -/* number of sizes + 1 */ -# define NBWLX 5 -#else -# define DEF_BWLX DEF_BWL -# define DEF_WLX DEF_WL -/* number of sizes + 1 */ -# define NBWLX 4 -#endif - -#define DEF_FP1(x) \ - DEF(TOK_ASM_ ## f ## x ## s, "f" #x "s") \ - DEF(TOK_ASM_ ## fi ## x ## l, "fi" #x "l") \ - DEF(TOK_ASM_ ## f ## x ## l, "f" #x "l") \ - DEF(TOK_ASM_ ## fi ## x ## s, "fi" #x "s") - -#define DEF_FP(x) \ - DEF(TOK_ASM_ ## f ## x, "f" #x ) \ - DEF(TOK_ASM_ ## f ## x ## p, "f" #x "p") \ - DEF_FP1(x) - -#define DEF_ASMTEST(x,suffix) \ - DEF_ASM(x ## o ## suffix) \ - DEF_ASM(x ## no ## suffix) \ - DEF_ASM(x ## b ## suffix) \ - DEF_ASM(x ## c ## suffix) \ - DEF_ASM(x ## nae ## suffix) \ - DEF_ASM(x ## nb ## suffix) \ - DEF_ASM(x ## nc ## suffix) \ - DEF_ASM(x ## ae ## suffix) \ - DEF_ASM(x ## e ## suffix) \ - DEF_ASM(x ## z ## suffix) \ - DEF_ASM(x ## ne ## suffix) \ - DEF_ASM(x ## nz ## suffix) \ - DEF_ASM(x ## be ## suffix) \ - DEF_ASM(x ## na ## suffix) \ - DEF_ASM(x ## nbe ## suffix) \ - DEF_ASM(x ## a ## suffix) \ - DEF_ASM(x ## s ## suffix) \ - DEF_ASM(x ## ns ## suffix) \ - DEF_ASM(x ## p ## suffix) \ - DEF_ASM(x ## pe ## suffix) \ - DEF_ASM(x ## np ## suffix) \ - DEF_ASM(x ## po ## suffix) \ - DEF_ASM(x ## l ## suffix) \ - DEF_ASM(x ## nge ## suffix) \ - DEF_ASM(x ## nl ## suffix) \ - DEF_ASM(x ## ge ## suffix) \ - DEF_ASM(x ## le ## suffix) \ - DEF_ASM(x ## ng ## suffix) \ - DEF_ASM(x ## nle ## suffix) \ - DEF_ASM(x ## g ## suffix) - -/* ------------------------------------------------------------------ */ -/* register */ - DEF_ASM(al) - DEF_ASM(cl) - DEF_ASM(dl) - DEF_ASM(bl) - DEF_ASM(ah) - DEF_ASM(ch) - DEF_ASM(dh) - DEF_ASM(bh) - DEF_ASM(ax) - DEF_ASM(cx) - DEF_ASM(dx) - DEF_ASM(bx) - DEF_ASM(sp) - DEF_ASM(bp) - DEF_ASM(si) - DEF_ASM(di) - DEF_ASM(eax) - DEF_ASM(ecx) - DEF_ASM(edx) - DEF_ASM(ebx) - DEF_ASM(esp) - DEF_ASM(ebp) - DEF_ASM(esi) - DEF_ASM(edi) -#ifdef TCC_TARGET_X86_64 - DEF_ASM(rax) - DEF_ASM(rcx) - DEF_ASM(rdx) - DEF_ASM(rbx) - DEF_ASM(rsp) - DEF_ASM(rbp) - DEF_ASM(rsi) - DEF_ASM(rdi) -#endif - DEF_ASM(mm0) - DEF_ASM(mm1) - DEF_ASM(mm2) - DEF_ASM(mm3) - DEF_ASM(mm4) - DEF_ASM(mm5) - DEF_ASM(mm6) - DEF_ASM(mm7) - DEF_ASM(xmm0) - DEF_ASM(xmm1) - DEF_ASM(xmm2) - DEF_ASM(xmm3) - DEF_ASM(xmm4) - DEF_ASM(xmm5) - DEF_ASM(xmm6) - DEF_ASM(xmm7) - DEF_ASM(cr0) - DEF_ASM(cr1) - DEF_ASM(cr2) - DEF_ASM(cr3) - DEF_ASM(cr4) - DEF_ASM(cr5) - DEF_ASM(cr6) - DEF_ASM(cr7) - DEF_ASM(tr0) - DEF_ASM(tr1) - DEF_ASM(tr2) - DEF_ASM(tr3) - DEF_ASM(tr4) - DEF_ASM(tr5) - DEF_ASM(tr6) - DEF_ASM(tr7) - DEF_ASM(db0) - DEF_ASM(db1) - DEF_ASM(db2) - DEF_ASM(db3) - DEF_ASM(db4) - DEF_ASM(db5) - DEF_ASM(db6) - DEF_ASM(db7) - DEF_ASM(dr0) - DEF_ASM(dr1) - DEF_ASM(dr2) - DEF_ASM(dr3) - DEF_ASM(dr4) - DEF_ASM(dr5) - DEF_ASM(dr6) - DEF_ASM(dr7) - DEF_ASM(es) - DEF_ASM(cs) - DEF_ASM(ss) - DEF_ASM(ds) - DEF_ASM(fs) - DEF_ASM(gs) - DEF_ASM(st) - DEF_ASM(rip) - -#ifdef TCC_TARGET_X86_64 - /* The four low parts of sp/bp/si/di that exist only on - x86-64 (encoding aliased to ah,ch,dh,dh when not using REX). */ - DEF_ASM(spl) - DEF_ASM(bpl) - DEF_ASM(sil) - DEF_ASM(dil) -#endif - /* generic two operands */ - DEF_BWLX(mov) - - DEF_BWLX(add) - DEF_BWLX(or) - DEF_BWLX(adc) - DEF_BWLX(sbb) - DEF_BWLX(and) - DEF_BWLX(sub) - DEF_BWLX(xor) - DEF_BWLX(cmp) - - /* unary ops */ - DEF_BWLX(inc) - DEF_BWLX(dec) - DEF_BWLX(not) - DEF_BWLX(neg) - DEF_BWLX(mul) - DEF_BWLX(imul) - DEF_BWLX(div) - DEF_BWLX(idiv) - - DEF_BWLX(xchg) - DEF_BWLX(test) - - /* shifts */ - DEF_BWLX(rol) - DEF_BWLX(ror) - DEF_BWLX(rcl) - DEF_BWLX(rcr) - DEF_BWLX(shl) - DEF_BWLX(shr) - DEF_BWLX(sar) - - DEF_WLX(shld) - DEF_WLX(shrd) - - DEF_ASM(pushw) - DEF_ASM(pushl) -#ifdef TCC_TARGET_X86_64 - DEF_ASM(pushq) -#endif - DEF_ASM(push) - - DEF_ASM(popw) - DEF_ASM(popl) -#ifdef TCC_TARGET_X86_64 - DEF_ASM(popq) -#endif - DEF_ASM(pop) - - DEF_BWL(in) - DEF_BWL(out) - - DEF_WLX(movzb) - DEF_ASM(movzwl) - DEF_ASM(movsbw) - DEF_ASM(movsbl) - DEF_ASM(movswl) -#ifdef TCC_TARGET_X86_64 - DEF_ASM(movsbq) - DEF_ASM(movswq) - DEF_ASM(movzwq) - DEF_ASM(movslq) -#endif - - DEF_WLX(lea) - - DEF_ASM(les) - DEF_ASM(lds) - DEF_ASM(lss) - DEF_ASM(lfs) - DEF_ASM(lgs) - - DEF_ASM(call) - DEF_ASM(jmp) - DEF_ASM(lcall) - DEF_ASM(ljmp) - - DEF_ASMTEST(j,) - - DEF_ASMTEST(set,) - DEF_ASMTEST(set,b) - DEF_ASMTEST(cmov,) - - DEF_WLX(bsf) - DEF_WLX(bsr) - DEF_WLX(bt) - DEF_WLX(bts) - DEF_WLX(btr) - DEF_WLX(btc) - - DEF_WLX(lar) - DEF_WLX(lsl) - - /* generic FP ops */ - DEF_FP(add) - DEF_FP(mul) - - DEF_ASM(fcom) - DEF_ASM(fcom_1) /* non existent op, just to have a regular table */ - DEF_FP1(com) - - DEF_FP(comp) - DEF_FP(sub) - DEF_FP(subr) - DEF_FP(div) - DEF_FP(divr) - - DEF_BWLX(xadd) - DEF_BWLX(cmpxchg) - - /* string ops */ - DEF_BWLX(cmps) - DEF_BWLX(scmp) - DEF_BWL(ins) - DEF_BWL(outs) - DEF_BWLX(lods) - DEF_BWLX(slod) - DEF_BWLX(movs) - DEF_BWLX(smov) - DEF_BWLX(scas) - DEF_BWLX(ssca) - DEF_BWLX(stos) - DEF_BWLX(ssto) - - /* generic asm ops */ -#define ALT(x) -#define DEF_ASM_OP0(name, opcode) DEF_ASM(name) -#define DEF_ASM_OP0L(name, opcode, group, instr_type) -#define DEF_ASM_OP1(name, opcode, group, instr_type, op0) -#define DEF_ASM_OP2(name, opcode, group, instr_type, op0, op1) -#define DEF_ASM_OP3(name, opcode, group, instr_type, op0, op1, op2) -#ifdef TCC_TARGET_X86_64 -# include "x86_64-asm.h" -#else -# include "i386-asm.h" -#endif - -#define ALT(x) -#define DEF_ASM_OP0(name, opcode) -#define DEF_ASM_OP0L(name, opcode, group, instr_type) DEF_ASM(name) -#define DEF_ASM_OP1(name, opcode, group, instr_type, op0) DEF_ASM(name) -#define DEF_ASM_OP2(name, opcode, group, instr_type, op0, op1) DEF_ASM(name) -#define DEF_ASM_OP3(name, opcode, group, instr_type, op0, op1, op2) DEF_ASM(name) -#ifdef TCC_TARGET_X86_64 -# include "x86_64-asm.h" -#else -# include "i386-asm.h" -#endif diff --git a/05/tcc-final/il-gen.c b/05/tcc-final/il-gen.c deleted file mode 100644 index bb670cc..0000000 --- a/05/tcc-final/il-gen.c +++ /dev/null @@ -1,657 +0,0 @@ -/* - * CIL code generator for TCC - * - * Copyright (c) 2002 Fabrice Bellard - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#error this code has bit-rotted since 2003 - -/* number of available registers */ -#define NB_REGS 3 - -/* a register can belong to several classes. The classes must be - sorted from more general to more precise (see gv2() code which does - assumptions on it). */ -#define RC_ST 0x0001 /* any stack entry */ -#define RC_ST0 0x0002 /* top of stack */ -#define RC_ST1 0x0004 /* top - 1 */ - -#define RC_INT RC_ST -#define RC_FLOAT RC_ST -#define RC_IRET RC_ST0 /* function return: integer register */ -#define RC_LRET RC_ST0 /* function return: second integer register */ -#define RC_FRET RC_ST0 /* function return: float register */ - -/* pretty names for the registers */ -enum { - REG_ST0 = 0, - REG_ST1, - REG_ST2, -}; - -const int reg_classes[NB_REGS] = { - /* ST0 */ RC_ST | RC_ST0, - /* ST1 */ RC_ST | RC_ST1, - /* ST2 */ RC_ST, -}; - -/* return registers for function */ -#define REG_IRET REG_ST0 /* single word int return register */ -#define REG_LRET REG_ST0 /* second word return register (for long long) */ -#define REG_FRET REG_ST0 /* float return register */ - -/* defined if function parameters must be evaluated in reverse order */ -/* #define INVERT_FUNC_PARAMS */ - -/* defined if structures are passed as pointers. Otherwise structures - are directly pushed on stack. */ -/* #define FUNC_STRUCT_PARAM_AS_PTR */ - -/* pointer size, in bytes */ -#define PTR_SIZE 4 - -/* long double size and alignment, in bytes */ -#define LDOUBLE_SIZE 8 -#define LDOUBLE_ALIGN 8 - -/* function call context */ -typedef struct GFuncContext { - int func_call; /* func call type (FUNC_STDCALL or FUNC_CDECL) */ -} GFuncContext; - -/******************************************************/ -/* opcode definitions */ - -#define IL_OP_PREFIX 0xFE - -enum ILOPCodes { -#define OP(name, str, n) IL_OP_ ## name = n, -#include "il-opcodes.h" -#undef OP -}; - -char *il_opcodes_str[] = { -#define OP(name, str, n) [n] = str, -#include "il-opcodes.h" -#undef OP -}; - -/******************************************************/ - -/* arguments variable numbers start from there */ -#define ARG_BASE 0x70000000 - -static FILE *il_outfile; - -static void out_byte(int c) -{ - *(char *)ind++ = c; -} - -static void out_le32(int c) -{ - out_byte(c); - out_byte(c >> 8); - out_byte(c >> 16); - out_byte(c >> 24); -} - -static void init_outfile(void) -{ - if (!il_outfile) { - il_outfile = stdout; - fprintf(il_outfile, - ".assembly extern mscorlib\n" - "{\n" - ".ver 1:0:2411:0\n" - "}\n\n"); - } -} - -static void out_op1(int op) -{ - if (op & 0x100) - out_byte(IL_OP_PREFIX); - out_byte(op & 0xff); -} - -/* output an opcode with prefix */ -static void out_op(int op) -{ - out_op1(op); - fprintf(il_outfile, " %s\n", il_opcodes_str[op]); -} - -static void out_opb(int op, int c) -{ - out_op1(op); - out_byte(c); - fprintf(il_outfile, " %s %d\n", il_opcodes_str[op], c); -} - -static void out_opi(int op, int c) -{ - out_op1(op); - out_le32(c); - fprintf(il_outfile, " %s 0x%x\n", il_opcodes_str[op], c); -} - -/* XXX: not complete */ -static void il_type_to_str(char *buf, int buf_size, - int t, const char *varstr) -{ - int bt; - Sym *s, *sa; - char buf1[256]; - const char *tstr; - - t = t & VT_TYPE; - bt = t & VT_BTYPE; - buf[0] = '\0'; - if (t & VT_UNSIGNED) - pstrcat(buf, buf_size, "unsigned "); - switch(bt) { - case VT_VOID: - tstr = "void"; - goto add_tstr; - case VT_BOOL: - tstr = "bool"; - goto add_tstr; - case VT_BYTE: - tstr = "int8"; - goto add_tstr; - case VT_SHORT: - tstr = "int16"; - goto add_tstr; - case VT_ENUM: - case VT_INT: - case VT_LONG: - tstr = "int32"; - goto add_tstr; - case VT_LLONG: - tstr = "int64"; - goto add_tstr; - case VT_FLOAT: - tstr = "float32"; - goto add_tstr; - case VT_DOUBLE: - case VT_LDOUBLE: - tstr = "float64"; - add_tstr: - pstrcat(buf, buf_size, tstr); - break; - case VT_STRUCT: - tcc_error("structures not handled yet"); - break; - case VT_FUNC: - s = sym_find((unsigned)t >> VT_STRUCT_SHIFT); - il_type_to_str(buf, buf_size, s->t, varstr); - pstrcat(buf, buf_size, "("); - sa = s->next; - while (sa != NULL) { - il_type_to_str(buf1, sizeof(buf1), sa->t, NULL); - pstrcat(buf, buf_size, buf1); - sa = sa->next; - if (sa) - pstrcat(buf, buf_size, ", "); - } - pstrcat(buf, buf_size, ")"); - goto no_var; - case VT_PTR: - s = sym_find((unsigned)t >> VT_STRUCT_SHIFT); - pstrcpy(buf1, sizeof(buf1), "*"); - if (varstr) - pstrcat(buf1, sizeof(buf1), varstr); - il_type_to_str(buf, buf_size, s->t, buf1); - goto no_var; - } - if (varstr) { - pstrcat(buf, buf_size, " "); - pstrcat(buf, buf_size, varstr); - } - no_var: ; -} - - -/* patch relocation entry with value 'val' */ -void greloc_patch1(Reloc *p, int val) -{ -} - -/* output a symbol and patch all calls to it */ -void gsym_addr(t, a) -{ -} - -/* output jump and return symbol */ -static int out_opj(int op, int c) -{ - out_op1(op); - out_le32(0); - if (c == 0) { - c = ind - (int)cur_text_section->data; - } - fprintf(il_outfile, " %s L%d\n", il_opcodes_str[op], c); - return c; -} - -void gsym(int t) -{ - fprintf(il_outfile, "L%d:\n", t); -} - -/* load 'r' from value 'sv' */ -void load(int r, SValue *sv) -{ - int v, fc, ft; - - v = sv->r & VT_VALMASK; - fc = sv->c.i; - ft = sv->t; - - if (sv->r & VT_LVAL) { - if (v == VT_LOCAL) { - if (fc >= ARG_BASE) { - fc -= ARG_BASE; - if (fc >= 0 && fc <= 4) { - out_op(IL_OP_LDARG_0 + fc); - } else if (fc <= 0xff) { - out_opb(IL_OP_LDARG_S, fc); - } else { - out_opi(IL_OP_LDARG, fc); - } - } else { - if (fc >= 0 && fc <= 4) { - out_op(IL_OP_LDLOC_0 + fc); - } else if (fc <= 0xff) { - out_opb(IL_OP_LDLOC_S, fc); - } else { - out_opi(IL_OP_LDLOC, fc); - } - } - } else if (v == VT_CONST) { - /* XXX: handle globals */ - out_opi(IL_OP_LDSFLD, 0); - } else { - if ((ft & VT_BTYPE) == VT_FLOAT) { - out_op(IL_OP_LDIND_R4); - } else if ((ft & VT_BTYPE) == VT_DOUBLE) { - out_op(IL_OP_LDIND_R8); - } else if ((ft & VT_BTYPE) == VT_LDOUBLE) { - out_op(IL_OP_LDIND_R8); - } else if ((ft & VT_TYPE) == VT_BYTE) - out_op(IL_OP_LDIND_I1); - else if ((ft & VT_TYPE) == (VT_BYTE | VT_UNSIGNED)) - out_op(IL_OP_LDIND_U1); - else if ((ft & VT_TYPE) == VT_SHORT) - out_op(IL_OP_LDIND_I2); - else if ((ft & VT_TYPE) == (VT_SHORT | VT_UNSIGNED)) - out_op(IL_OP_LDIND_U2); - else - out_op(IL_OP_LDIND_I4); - } - } else { - if (v == VT_CONST) { - /* XXX: handle globals */ - if (fc >= -1 && fc <= 8) { - out_op(IL_OP_LDC_I4_M1 + fc + 1); - } else { - out_opi(IL_OP_LDC_I4, fc); - } - } else if (v == VT_LOCAL) { - if (fc >= ARG_BASE) { - fc -= ARG_BASE; - if (fc <= 0xff) { - out_opb(IL_OP_LDARGA_S, fc); - } else { - out_opi(IL_OP_LDARGA, fc); - } - } else { - if (fc <= 0xff) { - out_opb(IL_OP_LDLOCA_S, fc); - } else { - out_opi(IL_OP_LDLOCA, fc); - } - } - } else { - /* XXX: do it */ - } - } -} - -/* store register 'r' in lvalue 'v' */ -void store(int r, SValue *sv) -{ - int v, fc, ft; - - v = sv->r & VT_VALMASK; - fc = sv->c.i; - ft = sv->t; - if (v == VT_LOCAL) { - if (fc >= ARG_BASE) { - fc -= ARG_BASE; - /* XXX: check IL arg store semantics */ - if (fc <= 0xff) { - out_opb(IL_OP_STARG_S, fc); - } else { - out_opi(IL_OP_STARG, fc); - } - } else { - if (fc >= 0 && fc <= 4) { - out_op(IL_OP_STLOC_0 + fc); - } else if (fc <= 0xff) { - out_opb(IL_OP_STLOC_S, fc); - } else { - out_opi(IL_OP_STLOC, fc); - } - } - } else if (v == VT_CONST) { - /* XXX: handle globals */ - out_opi(IL_OP_STSFLD, 0); - } else { - if ((ft & VT_BTYPE) == VT_FLOAT) - out_op(IL_OP_STIND_R4); - else if ((ft & VT_BTYPE) == VT_DOUBLE) - out_op(IL_OP_STIND_R8); - else if ((ft & VT_BTYPE) == VT_LDOUBLE) - out_op(IL_OP_STIND_R8); - else if ((ft & VT_BTYPE) == VT_BYTE) - out_op(IL_OP_STIND_I1); - else if ((ft & VT_BTYPE) == VT_SHORT) - out_op(IL_OP_STIND_I2); - else - out_op(IL_OP_STIND_I4); - } -} - -/* start function call and return function call context */ -void gfunc_start(GFuncContext *c, int func_call) -{ - c->func_call = func_call; -} - -/* push function parameter which is in (vtop->t, vtop->c). Stack entry - is then popped. */ -void gfunc_param(GFuncContext *c) -{ - if ((vtop->t & VT_BTYPE) == VT_STRUCT) { - tcc_error("structures passed as value not handled yet"); - } else { - /* simply push on stack */ - gv(RC_ST0); - } - vtop--; -} - -/* generate function call with address in (vtop->t, vtop->c) and free function - context. Stack entry is popped */ -void gfunc_call(GFuncContext *c) -{ - char buf[1024]; - - if ((vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST) { - /* XXX: more info needed from tcc */ - il_type_to_str(buf, sizeof(buf), vtop->t, "xxx"); - fprintf(il_outfile, " call %s\n", buf); - } else { - /* indirect call */ - gv(RC_INT); - il_type_to_str(buf, sizeof(buf), vtop->t, NULL); - fprintf(il_outfile, " calli %s\n", buf); - } - vtop--; -} - -/* generate function prolog of type 't' */ -void gfunc_prolog(int t) -{ - int addr, u, func_call; - Sym *sym; - char buf[1024]; - - init_outfile(); - - /* XXX: pass function name to gfunc_prolog */ - il_type_to_str(buf, sizeof(buf), t, funcname); - fprintf(il_outfile, ".method static %s il managed\n", buf); - fprintf(il_outfile, "{\n"); - /* XXX: cannot do better now */ - fprintf(il_outfile, " .maxstack %d\n", NB_REGS); - fprintf(il_outfile, " .locals (int32, int32, int32, int32, int32, int32, int32, int32)\n"); - - if (!strcmp(funcname, "main")) - fprintf(il_outfile, " .entrypoint\n"); - - sym = sym_find((unsigned)t >> VT_STRUCT_SHIFT); - func_call = sym->r; - - addr = ARG_BASE; - /* if the function returns a structure, then add an - implicit pointer parameter */ - func_vt = sym->t; - func_var = (sym->c == FUNC_ELLIPSIS); - if ((func_vt & VT_BTYPE) == VT_STRUCT) { - func_vc = addr; - addr++; - } - /* define parameters */ - while ((sym = sym->next) != NULL) { - u = sym->t; - sym_push(sym->v & ~SYM_FIELD, u, - VT_LOCAL | lvalue_type(sym->type.t), addr); - addr++; - } -} - -/* generate function epilog */ -void gfunc_epilog(void) -{ - out_op(IL_OP_RET); - fprintf(il_outfile, "}\n\n"); -} - -/* generate a jump to a label */ -int gjmp(int t) -{ - return out_opj(IL_OP_BR, t); -} - -/* generate a jump to a fixed address */ -void gjmp_addr(int a) -{ - /* XXX: handle syms */ - out_opi(IL_OP_BR, a); -} - -/* generate a test. set 'inv' to invert test. Stack entry is popped */ -int gtst(int inv, int t) -{ - int v, *p, c; - - v = vtop->r & VT_VALMASK; - if (v == VT_CMP) { - c = vtop->c.i ^ inv; - switch(c) { - case TOK_EQ: - c = IL_OP_BEQ; - break; - case TOK_NE: - c = IL_OP_BNE_UN; - break; - case TOK_LT: - c = IL_OP_BLT; - break; - case TOK_LE: - c = IL_OP_BLE; - break; - case TOK_GT: - c = IL_OP_BGT; - break; - case TOK_GE: - c = IL_OP_BGE; - break; - case TOK_ULT: - c = IL_OP_BLT_UN; - break; - case TOK_ULE: - c = IL_OP_BLE_UN; - break; - case TOK_UGT: - c = IL_OP_BGT_UN; - break; - case TOK_UGE: - c = IL_OP_BGE_UN; - break; - } - t = out_opj(c, t); - } else if (v == VT_JMP || v == VT_JMPI) { - /* && or || optimization */ - if ((v & 1) == inv) { - /* insert vtop->c jump list in t */ - p = &vtop->c.i; - while (*p != 0) - p = (int *)*p; - *p = t; - t = vtop->c.i; - } else { - t = gjmp(t); - gsym(vtop->c.i); - } - } - vtop--; - return t; -} - -/* generate an integer binary operation */ -void gen_opi(int op) -{ - gv2(RC_ST1, RC_ST0); - switch(op) { - case '+': - out_op(IL_OP_ADD); - goto std_op; - case '-': - out_op(IL_OP_SUB); - goto std_op; - case '&': - out_op(IL_OP_AND); - goto std_op; - case '^': - out_op(IL_OP_XOR); - goto std_op; - case '|': - out_op(IL_OP_OR); - goto std_op; - case '*': - out_op(IL_OP_MUL); - goto std_op; - case TOK_SHL: - out_op(IL_OP_SHL); - goto std_op; - case TOK_SHR: - out_op(IL_OP_SHR_UN); - goto std_op; - case TOK_SAR: - out_op(IL_OP_SHR); - goto std_op; - case '/': - case TOK_PDIV: - out_op(IL_OP_DIV); - goto std_op; - case TOK_UDIV: - out_op(IL_OP_DIV_UN); - goto std_op; - case '%': - out_op(IL_OP_REM); - goto std_op; - case TOK_UMOD: - out_op(IL_OP_REM_UN); - std_op: - vtop--; - vtop[0].r = REG_ST0; - break; - case TOK_EQ: - case TOK_NE: - case TOK_LT: - case TOK_LE: - case TOK_GT: - case TOK_GE: - case TOK_ULT: - case TOK_ULE: - case TOK_UGT: - case TOK_UGE: - vtop--; - vtop[0].r = VT_CMP; - vtop[0].c.i = op; - break; - } -} - -/* generate a floating point operation 'v = t1 op t2' instruction. The - two operands are guaranteed to have the same floating point type */ -void gen_opf(int op) -{ - /* same as integer */ - gen_opi(op); -} - -/* convert integers to fp 't' type. Must handle 'int', 'unsigned int' - and 'long long' cases. */ -void gen_cvt_itof(int t) -{ - gv(RC_ST0); - if (t == VT_FLOAT) - out_op(IL_OP_CONV_R4); - else - out_op(IL_OP_CONV_R8); -} - -/* convert fp to int 't' type */ -/* XXX: handle long long case */ -void gen_cvt_ftoi(int t) -{ - gv(RC_ST0); - switch(t) { - case VT_INT | VT_UNSIGNED: - out_op(IL_OP_CONV_U4); - break; - case VT_LLONG: - out_op(IL_OP_CONV_I8); - break; - case VT_LLONG | VT_UNSIGNED: - out_op(IL_OP_CONV_U8); - break; - default: - out_op(IL_OP_CONV_I4); - break; - } -} - -/* convert from one floating point type to another */ -void gen_cvt_ftof(int t) -{ - gv(RC_ST0); - if (t == VT_FLOAT) { - out_op(IL_OP_CONV_R4); - } else { - out_op(IL_OP_CONV_R8); - } -} - -/* end of CIL code generator */ -/*************************************************************/ - diff --git a/05/tcc-final/il-opcodes.h b/05/tcc-final/il-opcodes.h deleted file mode 100644 index d53ffb2..0000000 --- a/05/tcc-final/il-opcodes.h +++ /dev/null @@ -1,251 +0,0 @@ -/* - * CIL opcode definition - * - * Copyright (c) 2002 Fabrice Bellard - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ -OP(NOP, "nop", 0x00) -OP(BREAK, "break", 0x01) -OP(LDARG_0, "ldarg.0", 0x02) -OP(LDARG_1, "ldarg.1", 0x03) -OP(LDARG_2, "ldarg.2", 0x04) -OP(LDARG_3, "ldarg.3", 0x05) -OP(LDLOC_0, "ldloc.0", 0x06) -OP(LDLOC_1, "ldloc.1", 0x07) -OP(LDLOC_2, "ldloc.2", 0x08) -OP(LDLOC_3, "ldloc.3", 0x09) -OP(STLOC_0, "stloc.0", 0x0a) -OP(STLOC_1, "stloc.1", 0x0b) -OP(STLOC_2, "stloc.2", 0x0c) -OP(STLOC_3, "stloc.3", 0x0d) -OP(LDARG_S, "ldarg.s", 0x0e) -OP(LDARGA_S, "ldarga.s", 0x0f) -OP(STARG_S, "starg.s", 0x10) -OP(LDLOC_S, "ldloc.s", 0x11) -OP(LDLOCA_S, "ldloca.s", 0x12) -OP(STLOC_S, "stloc.s", 0x13) -OP(LDNULL, "ldnull", 0x14) -OP(LDC_I4_M1, "ldc.i4.m1", 0x15) -OP(LDC_I4_0, "ldc.i4.0", 0x16) -OP(LDC_I4_1, "ldc.i4.1", 0x17) -OP(LDC_I4_2, "ldc.i4.2", 0x18) -OP(LDC_I4_3, "ldc.i4.3", 0x19) -OP(LDC_I4_4, "ldc.i4.4", 0x1a) -OP(LDC_I4_5, "ldc.i4.5", 0x1b) -OP(LDC_I4_6, "ldc.i4.6", 0x1c) -OP(LDC_I4_7, "ldc.i4.7", 0x1d) -OP(LDC_I4_8, "ldc.i4.8", 0x1e) -OP(LDC_I4_S, "ldc.i4.s", 0x1f) -OP(LDC_I4, "ldc.i4", 0x20) -OP(LDC_I8, "ldc.i8", 0x21) -OP(LDC_R4, "ldc.r4", 0x22) -OP(LDC_R8, "ldc.r8", 0x23) -OP(LDPTR, "ldptr", 0x24) -OP(DUP, "dup", 0x25) -OP(POP, "pop", 0x26) -OP(JMP, "jmp", 0x27) -OP(CALL, "call", 0x28) -OP(CALLI, "calli", 0x29) -OP(RET, "ret", 0x2a) -OP(BR_S, "br.s", 0x2b) -OP(BRFALSE_S, "brfalse.s", 0x2c) -OP(BRTRUE_S, "brtrue.s", 0x2d) -OP(BEQ_S, "beq.s", 0x2e) -OP(BGE_S, "bge.s", 0x2f) -OP(BGT_S, "bgt.s", 0x30) -OP(BLE_S, "ble.s", 0x31) -OP(BLT_S, "blt.s", 0x32) -OP(BNE_UN_S, "bne.un.s", 0x33) -OP(BGE_UN_S, "bge.un.s", 0x34) -OP(BGT_UN_S, "bgt.un.s", 0x35) -OP(BLE_UN_S, "ble.un.s", 0x36) -OP(BLT_UN_S, "blt.un.s", 0x37) -OP(BR, "br", 0x38) -OP(BRFALSE, "brfalse", 0x39) -OP(BRTRUE, "brtrue", 0x3a) -OP(BEQ, "beq", 0x3b) -OP(BGE, "bge", 0x3c) -OP(BGT, "bgt", 0x3d) -OP(BLE, "ble", 0x3e) -OP(BLT, "blt", 0x3f) -OP(BNE_UN, "bne.un", 0x40) -OP(BGE_UN, "bge.un", 0x41) -OP(BGT_UN, "bgt.un", 0x42) -OP(BLE_UN, "ble.un", 0x43) -OP(BLT_UN, "blt.un", 0x44) -OP(SWITCH, "switch", 0x45) -OP(LDIND_I1, "ldind.i1", 0x46) -OP(LDIND_U1, "ldind.u1", 0x47) -OP(LDIND_I2, "ldind.i2", 0x48) -OP(LDIND_U2, "ldind.u2", 0x49) -OP(LDIND_I4, "ldind.i4", 0x4a) -OP(LDIND_U4, "ldind.u4", 0x4b) -OP(LDIND_I8, "ldind.i8", 0x4c) -OP(LDIND_I, "ldind.i", 0x4d) -OP(LDIND_R4, "ldind.r4", 0x4e) -OP(LDIND_R8, "ldind.r8", 0x4f) -OP(LDIND_REF, "ldind.ref", 0x50) -OP(STIND_REF, "stind.ref", 0x51) -OP(STIND_I1, "stind.i1", 0x52) -OP(STIND_I2, "stind.i2", 0x53) -OP(STIND_I4, "stind.i4", 0x54) -OP(STIND_I8, "stind.i8", 0x55) -OP(STIND_R4, "stind.r4", 0x56) -OP(STIND_R8, "stind.r8", 0x57) -OP(ADD, "add", 0x58) -OP(SUB, "sub", 0x59) -OP(MUL, "mul", 0x5a) -OP(DIV, "div", 0x5b) -OP(DIV_UN, "div.un", 0x5c) -OP(REM, "rem", 0x5d) -OP(REM_UN, "rem.un", 0x5e) -OP(AND, "and", 0x5f) -OP(OR, "or", 0x60) -OP(XOR, "xor", 0x61) -OP(SHL, "shl", 0x62) -OP(SHR, "shr", 0x63) -OP(SHR_UN, "shr.un", 0x64) -OP(NEG, "neg", 0x65) -OP(NOT, "not", 0x66) -OP(CONV_I1, "conv.i1", 0x67) -OP(CONV_I2, "conv.i2", 0x68) -OP(CONV_I4, "conv.i4", 0x69) -OP(CONV_I8, "conv.i8", 0x6a) -OP(CONV_R4, "conv.r4", 0x6b) -OP(CONV_R8, "conv.r8", 0x6c) -OP(CONV_U4, "conv.u4", 0x6d) -OP(CONV_U8, "conv.u8", 0x6e) -OP(CALLVIRT, "callvirt", 0x6f) -OP(CPOBJ, "cpobj", 0x70) -OP(LDOBJ, "ldobj", 0x71) -OP(LDSTR, "ldstr", 0x72) -OP(NEWOBJ, "newobj", 0x73) -OP(CASTCLASS, "castclass", 0x74) -OP(ISINST, "isinst", 0x75) -OP(CONV_R_UN, "conv.r.un", 0x76) -OP(ANN_DATA_S, "ann.data.s", 0x77) -OP(UNBOX, "unbox", 0x79) -OP(THROW, "throw", 0x7a) -OP(LDFLD, "ldfld", 0x7b) -OP(LDFLDA, "ldflda", 0x7c) -OP(STFLD, "stfld", 0x7d) -OP(LDSFLD, "ldsfld", 0x7e) -OP(LDSFLDA, "ldsflda", 0x7f) -OP(STSFLD, "stsfld", 0x80) -OP(STOBJ, "stobj", 0x81) -OP(CONV_OVF_I1_UN, "conv.ovf.i1.un", 0x82) -OP(CONV_OVF_I2_UN, "conv.ovf.i2.un", 0x83) -OP(CONV_OVF_I4_UN, "conv.ovf.i4.un", 0x84) -OP(CONV_OVF_I8_UN, "conv.ovf.i8.un", 0x85) -OP(CONV_OVF_U1_UN, "conv.ovf.u1.un", 0x86) -OP(CONV_OVF_U2_UN, "conv.ovf.u2.un", 0x87) -OP(CONV_OVF_U4_UN, "conv.ovf.u4.un", 0x88) -OP(CONV_OVF_U8_UN, "conv.ovf.u8.un", 0x89) -OP(CONV_OVF_I_UN, "conv.ovf.i.un", 0x8a) -OP(CONV_OVF_U_UN, "conv.ovf.u.un", 0x8b) -OP(BOX, "box", 0x8c) -OP(NEWARR, "newarr", 0x8d) -OP(LDLEN, "ldlen", 0x8e) -OP(LDELEMA, "ldelema", 0x8f) -OP(LDELEM_I1, "ldelem.i1", 0x90) -OP(LDELEM_U1, "ldelem.u1", 0x91) -OP(LDELEM_I2, "ldelem.i2", 0x92) -OP(LDELEM_U2, "ldelem.u2", 0x93) -OP(LDELEM_I4, "ldelem.i4", 0x94) -OP(LDELEM_U4, "ldelem.u4", 0x95) -OP(LDELEM_I8, "ldelem.i8", 0x96) -OP(LDELEM_I, "ldelem.i", 0x97) -OP(LDELEM_R4, "ldelem.r4", 0x98) -OP(LDELEM_R8, "ldelem.r8", 0x99) -OP(LDELEM_REF, "ldelem.ref", 0x9a) -OP(STELEM_I, "stelem.i", 0x9b) -OP(STELEM_I1, "stelem.i1", 0x9c) -OP(STELEM_I2, "stelem.i2", 0x9d) -OP(STELEM_I4, "stelem.i4", 0x9e) -OP(STELEM_I8, "stelem.i8", 0x9f) -OP(STELEM_R4, "stelem.r4", 0xa0) -OP(STELEM_R8, "stelem.r8", 0xa1) -OP(STELEM_REF, "stelem.ref", 0xa2) -OP(CONV_OVF_I1, "conv.ovf.i1", 0xb3) -OP(CONV_OVF_U1, "conv.ovf.u1", 0xb4) -OP(CONV_OVF_I2, "conv.ovf.i2", 0xb5) -OP(CONV_OVF_U2, "conv.ovf.u2", 0xb6) -OP(CONV_OVF_I4, "conv.ovf.i4", 0xb7) -OP(CONV_OVF_U4, "conv.ovf.u4", 0xb8) -OP(CONV_OVF_I8, "conv.ovf.i8", 0xb9) -OP(CONV_OVF_U8, "conv.ovf.u8", 0xba) -OP(REFANYVAL, "refanyval", 0xc2) -OP(CKFINITE, "ckfinite", 0xc3) -OP(MKREFANY, "mkrefany", 0xc6) -OP(ANN_CALL, "ann.call", 0xc7) -OP(ANN_CATCH, "ann.catch", 0xc8) -OP(ANN_DEAD, "ann.dead", 0xc9) -OP(ANN_HOISTED, "ann.hoisted", 0xca) -OP(ANN_HOISTED_CALL, "ann.hoisted.call", 0xcb) -OP(ANN_LAB, "ann.lab", 0xcc) -OP(ANN_DEF, "ann.def", 0xcd) -OP(ANN_REF_S, "ann.ref.s", 0xce) -OP(ANN_PHI, "ann.phi", 0xcf) -OP(LDTOKEN, "ldtoken", 0xd0) -OP(CONV_U2, "conv.u2", 0xd1) -OP(CONV_U1, "conv.u1", 0xd2) -OP(CONV_I, "conv.i", 0xd3) -OP(CONV_OVF_I, "conv.ovf.i", 0xd4) -OP(CONV_OVF_U, "conv.ovf.u", 0xd5) -OP(ADD_OVF, "add.ovf", 0xd6) -OP(ADD_OVF_UN, "add.ovf.un", 0xd7) -OP(MUL_OVF, "mul.ovf", 0xd8) -OP(MUL_OVF_UN, "mul.ovf.un", 0xd9) -OP(SUB_OVF, "sub.ovf", 0xda) -OP(SUB_OVF_UN, "sub.ovf.un", 0xdb) -OP(ENDFINALLY, "endfinally", 0xdc) -OP(LEAVE, "leave", 0xdd) -OP(LEAVE_S, "leave.s", 0xde) -OP(STIND_I, "stind.i", 0xdf) -OP(CONV_U, "conv.u", 0xe0) - -/* prefix instructions. we use an opcode >= 256 to ease coding */ - -OP(ARGLIST, "arglist", 0x100) -OP(CEQ, "ceq", 0x101) -OP(CGT, "cgt", 0x102) -OP(CGT_UN, "cgt.un", 0x103) -OP(CLT, "clt", 0x104) -OP(CLT_UN, "clt.un", 0x105) -OP(LDFTN, "ldftn", 0x106) -OP(LDVIRTFTN, "ldvirtftn", 0x107) -OP(JMPI, "jmpi", 0x108) -OP(LDARG, "ldarg", 0x109) -OP(LDARGA, "ldarga", 0x10a) -OP(STARG, "starg", 0x10b) -OP(LDLOC, "ldloc", 0x10c) -OP(LDLOCA, "ldloca", 0x10d) -OP(STLOC, "stloc", 0x10e) -OP(LOCALLOC, "localloc", 0x10f) -OP(ENDFILTER, "endfilter", 0x111) -OP(UNALIGNED, "unaligned", 0x112) -OP(VOLATILE, "volatile", 0x113) -OP(TAIL, "tail", 0x114) -OP(INITOBJ, "initobj", 0x115) -OP(ANN_LIVE, "ann.live", 0x116) -OP(CPBLK, "cpblk", 0x117) -OP(INITBLK, "initblk", 0x118) -OP(ANN_REF, "ann.ref", 0x119) -OP(RETHROW, "rethrow", 0x11a) -OP(SIZEOF, "sizeof", 0x11c) -OP(REFANYTYPE, "refanytype", 0x11d) -OP(ANN_DATA, "ann.data", 0x122) -OP(ANN_ARG, "ann.arg", 0x123) diff --git a/05/tcc-final/include/float.h b/05/tcc-final/include/float.h deleted file mode 100644 index 24b7410..0000000 --- a/05/tcc-final/include/float.h +++ /dev/null @@ -1,75 +0,0 @@ -#ifndef _FLOAT_H_ -#define _FLOAT_H_ - -#define FLT_RADIX 2 - -/* IEEE float */ -#define FLT_MANT_DIG 24 -#define FLT_DIG 6 -#define FLT_ROUNDS 1 -#define FLT_EPSILON 1.19209290e-07F -#define FLT_MIN_EXP (-125) -#define FLT_MIN 1.17549435e-38F -#define FLT_MIN_10_EXP (-37) -#define FLT_MAX_EXP 128 -#define FLT_MAX 3.40282347e+38F -#define FLT_MAX_10_EXP 38 - -/* IEEE double */ -#define DBL_MANT_DIG 53 -#define DBL_DIG 15 -#define DBL_EPSILON 2.2204460492503131e-16 -#define DBL_MIN_EXP (-1021) -#define DBL_MIN 2.2250738585072014e-308 -#define DBL_MIN_10_EXP (-307) -#define DBL_MAX_EXP 1024 -#define DBL_MAX 1.7976931348623157e+308 -#define DBL_MAX_10_EXP 308 - -/* horrible intel long double */ -#if defined __i386__ || defined __x86_64__ - -#define LDBL_MANT_DIG 64 -#define LDBL_DIG 18 -#define LDBL_EPSILON 1.08420217248550443401e-19L -#define LDBL_MIN_EXP (-16381) -#define LDBL_MIN 3.36210314311209350626e-4932L -#define LDBL_MIN_10_EXP (-4931) -#define LDBL_MAX_EXP 16384 -#define LDBL_MAX 1.18973149535723176502e+4932L -#define LDBL_MAX_10_EXP 4932 -#define DECIMAL_DIG 21 - -#elif defined __aarch64__ || defined __riscv -/* - * Use values from: - * gcc -dM -E -xc /dev/null | grep LDBL | sed -e "s/__//g" - */ -#define LDBL_MANT_DIG 113 -#define LDBL_DIG 33 -#define LDBL_EPSILON 1.92592994438723585305597794258492732e-34L -#define LDBL_MIN_EXP (-16381) -#define LDBL_MIN 3.36210314311209350626267781732175260e-4932L -#define LDBL_MIN_10_EXP (-4931) -#define LDBL_MAX_EXP 16384 -#define LDBL_MAX 1.18973149535723176508575932662800702e+4932L -#define LDBL_MAX_EXP 16384 -#define DECIMAL_DIG 36 - -#else - -/* same as IEEE double */ -#define LDBL_MANT_DIG 53 -#define LDBL_DIG 15 -#define LDBL_EPSILON 2.2204460492503131e-16L -#define LDBL_MIN_EXP (-1021) -#define LDBL_MIN 2.2250738585072014e-308L -#define LDBL_MIN_10_EXP (-307) -#define LDBL_MAX_EXP 1024 -#define LDBL_MAX 1.7976931348623157e+308L -#define LDBL_MAX_10_EXP 308 -#define DECIMAL_DIG 17 - -#endif - -#endif /* _FLOAT_H_ */ diff --git a/05/tcc-final/include/stdalign.h b/05/tcc-final/include/stdalign.h deleted file mode 100644 index ae46c34..0000000 --- a/05/tcc-final/include/stdalign.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef _STDALIGN_H -#define _STDALIGN_H - -#if __STDC_VERSION__ < 201112L && (defined(__GNUC__) || defined(__TINYC__)) -# define _Alignas(t) __attribute__((__aligned__(t))) -# define _Alignof(t) __alignof__(t) -#endif - -#define alignas _Alignas -#define alignof _Alignof - -#define __alignas_is_defined 1 -#define __alignof_is_defined 1 - -#endif /* _STDALIGN_H */ - diff --git a/05/tcc-final/include/stdarg.h b/05/tcc-final/include/stdarg.h deleted file mode 100644 index aa784da..0000000 --- a/05/tcc-final/include/stdarg.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef _STDARG_H -#define _STDARG_H - -typedef __builtin_va_list va_list; -#define va_start __builtin_va_start -#define va_arg __builtin_va_arg -#define va_copy __builtin_va_copy -#define va_end __builtin_va_end - -/* fix a buggy dependency on GCC in libio.h */ -typedef va_list __gnuc_va_list; -#define _VA_LIST_DEFINED - -#endif /* _STDARG_H */ diff --git a/05/tcc-final/include/stdatomic.h b/05/tcc-final/include/stdatomic.h deleted file mode 100644 index f00c62f..0000000 --- a/05/tcc-final/include/stdatomic.h +++ /dev/null @@ -1,137 +0,0 @@ -/* This file is derived from clang's stdatomic.h */ - -/*===---- stdatomic.h - Standard header for atomic types and operations -----=== - * - * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. - * See https://llvm.org/LICENSE.txt for license information. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - * - *===-----------------------------------------------------------------------=== - */ - -#ifndef _STDATOMIC_H -#define _STDATOMIC_H - -#include -#include - -#define __ATOMIC_RELAXED 0 -#define __ATOMIC_CONSUME 1 -#define __ATOMIC_ACQUIRE 2 -#define __ATOMIC_RELEASE 3 -#define __ATOMIC_ACQ_REL 4 -#define __ATOMIC_SEQ_CST 5 - -/* Memory ordering */ -typedef enum { - memory_order_relaxed = __ATOMIC_RELAXED, - memory_order_consume = __ATOMIC_CONSUME, - memory_order_acquire = __ATOMIC_ACQUIRE, - memory_order_release = __ATOMIC_RELEASE, - memory_order_acq_rel = __ATOMIC_ACQ_REL, - memory_order_seq_cst = __ATOMIC_SEQ_CST, -} memory_order; - -/* Atomic typedefs */ -typedef _Atomic(_Bool) atomic_bool; -typedef _Atomic(char) atomic_char; -typedef _Atomic(signed char) atomic_schar; -typedef _Atomic(unsigned char) atomic_uchar; -typedef _Atomic(short) atomic_short; -typedef _Atomic(unsigned short) atomic_ushort; -typedef _Atomic(int) atomic_int; -typedef _Atomic(unsigned int) atomic_uint; -typedef _Atomic(long) atomic_long; -typedef _Atomic(unsigned long) atomic_ulong; -typedef _Atomic(long long) atomic_llong; -typedef _Atomic(unsigned long long) atomic_ullong; -typedef _Atomic(uint_least16_t) atomic_char16_t; -typedef _Atomic(uint_least32_t) atomic_char32_t; -typedef _Atomic(wchar_t) atomic_wchar_t; -typedef _Atomic(int_least8_t) atomic_int_least8_t; -typedef _Atomic(uint_least8_t) atomic_uint_least8_t; -typedef _Atomic(int_least16_t) atomic_int_least16_t; -typedef _Atomic(uint_least16_t) atomic_uint_least16_t; -typedef _Atomic(int_least32_t) atomic_int_least32_t; -typedef _Atomic(uint_least32_t) atomic_uint_least32_t; -typedef _Atomic(int_least64_t) atomic_int_least64_t; -typedef _Atomic(uint_least64_t) atomic_uint_least64_t; -typedef _Atomic(int_fast8_t) atomic_int_fast8_t; -typedef _Atomic(uint_fast8_t) atomic_uint_fast8_t; -typedef _Atomic(int_fast16_t) atomic_int_fast16_t; -typedef _Atomic(uint_fast16_t) atomic_uint_fast16_t; -typedef _Atomic(int_fast32_t) atomic_int_fast32_t; -typedef _Atomic(uint_fast32_t) atomic_uint_fast32_t; -typedef _Atomic(int_fast64_t) atomic_int_fast64_t; -typedef _Atomic(uint_fast64_t) atomic_uint_fast64_t; -typedef _Atomic(intptr_t) atomic_intptr_t; -typedef _Atomic(uintptr_t) atomic_uintptr_t; -typedef _Atomic(size_t) atomic_size_t; -typedef _Atomic(ptrdiff_t) atomic_ptrdiff_t; -typedef _Atomic(intmax_t) atomic_intmax_t; -typedef _Atomic(uintmax_t) atomic_uintmax_t; - -/* Atomic flag */ -typedef struct { - atomic_bool value; -} atomic_flag; - -#define ATOMIC_FLAG_INIT {0} - -#define atomic_flag_test_and_set(object) \ - __atomic_exchange(&(object)->value, 1, __ATOMIC_SEQ_CST) -#define atomic_flag_test_and_set_explicit(object, order) \ - __atomic_exchange(&(object)->value, 1, order) - -#define atomic_flag_clear(object) \ - __atomic_store(&(object)->value, 0, __ATOMIC_SEQ_CST) -#define atomic_flag_clear_explicit(object, order) \ - __atomic_store(&(object)->value, 0, order) - -/* Generic routines */ -#define atomic_init(object, desired) \ - __atomic_store(object, desired, __ATOMIC_RELAXED) - -#define atomic_store(object, desired) \ - __atomic_store(object, desired, __ATOMIC_SEQ_CST) -#define atomic_store_explicit __atomic_store - -#define atomic_load(object) \ - __atomic_load(object, __ATOMIC_SEQ_CST) -#define atomic_load_explicit __atomic_load - -#define atomic_exchange(object, desired) \ - __atomic_exchange(object, desired, __ATOMIC_SEQ_CST) -#define atomic_exchange_explicit __atomic_exchange - -#define atomic_compare_exchange_strong(object, expected, desired) \ - __atomic_compare_exchange(object, expected, desired, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) -#define atomic_compare_exchange_strong_explicit(object, expected, desired, success, failure) \ - __atomic_compare_exchange(object, expected, desired, 0, success, failure) - -#define atomic_compare_exchange_weak(object, expected, desired) \ - __atomic_compare_exchange(object, expected, desired, 1, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) -#define atomic_compare_exchange_weak_explicit(object, expected, desired, success, failure) \ - __atomic_compare_exchange(object, expected, desired, 1, success, failure) - -#define atomic_fetch_add(object, operand) \ - __atomic_fetch_add(object, operand, __ATOMIC_SEQ_CST) -#define atomic_fetch_add_explicit __atomic_fetch_add - -#define atomic_fetch_sub(object, operand) \ - __atomic_fetch_sub(object, operand, __ATOMIC_SEQ_CST) -#define atomic_fetch_sub_explicit __atomic_fetch_sub - -#define atomic_fetch_or(object, operand) \ - __atomic_fetch_or(object, operand, __ATOMIC_SEQ_CST) -#define atomic_fetch_or_explicit __atomic_fetch_or - -#define atomic_fetch_xor(object, operand) \ - __atomic_fetch_xor(object, operand, __ATOMIC_SEQ_CST) -#define atomic_fetch_xor_explicit __atomic_fetch_xor - -#define atomic_fetch_and(object, operand) \ - __atomic_fetch_and(object, operand, __ATOMIC_SEQ_CST) -#define atomic_fetch_and_explicit __atomic_fetch_and - -#endif /* _STDATOMIC_H */ diff --git a/05/tcc-final/include/stdbool.h b/05/tcc-final/include/stdbool.h deleted file mode 100644 index d2ee446..0000000 --- a/05/tcc-final/include/stdbool.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef _STDBOOL_H -#define _STDBOOL_H - -/* ISOC99 boolean */ - -#define bool _Bool -#define true 1 -#define false 0 -#define __bool_true_false_are_defined 1 - -#endif /* _STDBOOL_H */ diff --git a/05/tcc-final/include/stddef.h b/05/tcc-final/include/stddef.h deleted file mode 100644 index da9b9e0..0000000 --- a/05/tcc-final/include/stddef.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef _STDDEF_H -#define _STDDEF_H - -typedef __SIZE_TYPE__ size_t; -typedef __PTRDIFF_TYPE__ ssize_t; -typedef __WCHAR_TYPE__ wchar_t; -typedef __PTRDIFF_TYPE__ ptrdiff_t; -typedef __PTRDIFF_TYPE__ intptr_t; -typedef __SIZE_TYPE__ uintptr_t; - -#if __STDC_VERSION__ >= 201112L -typedef union { long long __ll; long double __ld; } max_align_t; -#endif - -#ifndef NULL -#define NULL ((void*)0) -#endif - -#undef offsetof -#define offsetof(type, field) ((size_t)&((type *)0)->field) - -#if defined __i386__ || defined __x86_64__ -void *alloca(size_t size); -#endif - -#endif - -/* Older glibc require a wint_t from (when requested - by __need_wint_t, as otherwise stddef.h isn't allowed to - define this type). Note that this must be outside the normal - _STDDEF_H guard, so that it works even when we've included the file - already (without requiring wint_t). Some other libs define _WINT_T - if they've already provided that type, so we can use that as guard. - TCC defines __WINT_TYPE__ for us. */ -#if defined (__need_wint_t) -#ifndef _WINT_T -#define _WINT_T -typedef __WINT_TYPE__ wint_t; -#endif -#undef __need_wint_t -#endif diff --git a/05/tcc-final/include/stdnoreturn.h b/05/tcc-final/include/stdnoreturn.h deleted file mode 100644 index 4d580ea..0000000 --- a/05/tcc-final/include/stdnoreturn.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef _STDNORETURN_H -#define _STDNORETURN_H - -/* ISOC11 noreturn */ -#define noreturn _Noreturn - -#endif /* _STDNORETURN_H */ diff --git a/05/tcc-final/include/tccdefs.h b/05/tcc-final/include/tccdefs.h deleted file mode 100644 index 83e3c38..0000000 --- a/05/tcc-final/include/tccdefs.h +++ /dev/null @@ -1,296 +0,0 @@ -/* tccdefs.h - - Nothing is defined before this file except target machine, target os - and the few things related to option settings in tccpp.c:tcc_predefs(). - - This file is either included at runtime as is, or converted and - included as C-strings at compile-time (depending on CONFIG_TCC_PREDEFS). - - Note that line indent matters: - - - in lines starting at column 1, platform macros are replaced by - corresponding TCC target compile-time macros. See conftest.c for - the list of platform macros supported in lines starting at column 1. - - - only lines indented >= 4 are actually included into the executable, - check tccdefs_.h. -*/ - -#if __SIZEOF_POINTER__ == 4 - /* 32bit systems. */ -#if defined TARGETOS_OpenBSD - #define __SIZE_TYPE__ unsigned long - #define __PTRDIFF_TYPE__ long -#else - #define __SIZE_TYPE__ unsigned int - #define __PTRDIFF_TYPE__ int -#endif - #define __ILP32__ 1 - #define __INT64_TYPE__ long long -#elif __SIZEOF_LONG__ == 4 - /* 64bit Windows. */ - #define __SIZE_TYPE__ unsigned long long - #define __PTRDIFF_TYPE__ long long - #define __LLP64__ 1 - #define __INT64_TYPE__ long long -#else - /* Other 64bit systems. */ - #define __SIZE_TYPE__ unsigned long - #define __PTRDIFF_TYPE__ long - #define __LP64__ 1 -# if defined __linux__ - #define __INT64_TYPE__ long -# else /* APPLE, BSD */ - #define __INT64_TYPE__ long long -# endif -#endif - #define __SIZEOF_INT__ 4 - #define __INT_MAX__ 0x7fffffff -#if __SIZEOF_LONG__ == 4 - #define __LONG_MAX__ 0x7fffffffL -#else - #define __LONG_MAX__ 0x7fffffffffffffffL -#endif - #define __SIZEOF_LONG_LONG__ 8 - #define __LONG_LONG_MAX__ 0x7fffffffffffffffLL - #define __CHAR_BIT__ 8 - #define __ORDER_LITTLE_ENDIAN__ 1234 - #define __ORDER_BIG_ENDIAN__ 4321 - #define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__ -#if defined _WIN32 - #define __WCHAR_TYPE__ unsigned short - #define __WINT_TYPE__ unsigned short -#elif defined __linux__ - #define __WCHAR_TYPE__ int - #define __WINT_TYPE__ unsigned int -#else - #define __WCHAR_TYPE__ int - #define __WINT_TYPE__ int -#endif - - #if __STDC_VERSION__ == 201112L - # define __STDC_NO_ATOMICS__ 1 - # define __STDC_NO_COMPLEX__ 1 - # define __STDC_NO_THREADS__ 1 -#if !defined _WIN32 - # define __STDC_UTF_16__ 1 - # define __STDC_UTF_32__ 1 -#endif - #endif - -#if defined _WIN32 - #define __declspec(x) __attribute__((x)) - #define __cdecl - -#elif defined __FreeBSD__ - #define __GNUC__ 9 - #define __GNUC_MINOR__ 3 - #define __GNUC_PATCHLEVEL__ 0 - #define __GNUC_STDC_INLINE__ 1 - #define __NO_TLS 1 - #define __RUNETYPE_INTERNAL 1 -# if __SIZEOF_POINTER__ == 8 - /* FIXME, __int128_t is used by setjump */ - #define __int128_t struct { unsigned char _dummy[16] __attribute((aligned(16))); } - #define __SIZEOF_SIZE_T__ 8 - #define __SIZEOF_PTRDIFF_T__ 8 -#else - #define __SIZEOF_SIZE_T__ 4 - #define __SIZEOF_PTRDIFF_T__ 4 -# endif - -#elif defined __FreeBSD_kernel__ - -#elif defined __NetBSD__ - #define __GNUC__ 4 - #define __GNUC_MINOR__ 1 - #define __GNUC_PATCHLEVEL__ 0 - #define _Pragma(x) - #define __ELF__ 1 -#if defined __aarch64__ - #define _LOCORE /* avoids usage of __asm */ -#endif - -#elif defined __OpenBSD__ - #define __GNUC__ 4 - #define _ANSI_LIBRARY 1 - -#elif defined __APPLE__ - /* emulate APPLE-GCC to make libc's headerfiles compile: */ - #define __GNUC__ 4 /* darwin emits warning on GCC<4 */ - #define __APPLE_CC__ 1 /* for */ - #define __LITTLE_ENDIAN__ 1 - #define _DONT_USE_CTYPE_INLINE_ 1 - /* avoids usage of GCC/clang specific builtins in libc-headerfiles: */ - #define __FINITE_MATH_ONLY__ 1 - #define _FORTIFY_SOURCE 0 - -#else - /* Linux */ - -#endif - /* Some derived integer types needed to get stdint.h to compile correctly on some platforms */ -#ifndef __NetBSD__ - #define __UINTPTR_TYPE__ unsigned __PTRDIFF_TYPE__ - #define __INTPTR_TYPE__ __PTRDIFF_TYPE__ -#endif - #define __INT32_TYPE__ int - -#if !defined _WIN32 - /* glibc defines */ - #define __REDIRECT(name, proto, alias) name proto __asm__ (#alias) - #define __REDIRECT_NTH(name, proto, alias) name proto __asm__ (#alias) __THROW -#endif - - /* skip __builtin... with -E */ - #ifndef __TCC_PP__ - - #define __builtin_offsetof(type, field) ((__SIZE_TYPE__)&((type*)0)->field) - #define __builtin_extract_return_addr(x) x -#if !defined __linux__ && !defined _WIN32 - /* used by math.h */ - #define __builtin_huge_val() 1e500 - #define __builtin_huge_valf() 1e50f - #define __builtin_huge_vall() 1e5000L -# if defined __APPLE__ - #define __builtin_nanf(ignored_string) __nan() - /* used by floats.h to implement FLT_ROUNDS C99 macro. 1 == to nearest */ - #define __builtin_flt_rounds() 1 - /* used by _fd_def.h */ - #define __builtin_bzero(p, ignored_size) bzero(p, sizeof(*(p))) -# else - #define __builtin_nanf(ignored_string) (0.0F/0.0F) -# endif -#endif - - /* __builtin_va_list */ -#if defined __x86_64__ -#if !defined _WIN32 - /* GCC compatible definition of va_list. */ - /* This should be in sync with the declaration in our lib/libtcc1.c */ - typedef struct { - unsigned gp_offset, fp_offset; - union { - unsigned overflow_offset; - char *overflow_arg_area; - }; - char *reg_save_area; - } __builtin_va_list[1]; - - void *__va_arg(__builtin_va_list ap, int arg_type, int size, int align); - #define __builtin_va_start(ap, last) \ - (*(ap) = *(__builtin_va_list)((char*)__builtin_frame_address(0) - 24)) - #define __builtin_va_arg(ap, t) \ - (*(t *)(__va_arg(ap, __builtin_va_arg_types(t), sizeof(t), __alignof__(t)))) - #define __builtin_va_copy(dest, src) (*(dest) = *(src)) - -#else /* _WIN64 */ - typedef char *__builtin_va_list; - #define __builtin_va_arg(ap, t) ((sizeof(t) > 8 || (sizeof(t) & (sizeof(t) - 1))) \ - ? **(t **)((ap += 8) - 8) : *(t *)((ap += 8) - 8)) -#endif - -#elif defined __arm__ - typedef char *__builtin_va_list; - #define _tcc_alignof(type) ((int)&((struct {char c;type x;} *)0)->x) - #define _tcc_align(addr,type) (((unsigned)addr + _tcc_alignof(type) - 1) \ - & ~(_tcc_alignof(type) - 1)) - #define __builtin_va_start(ap,last) (ap = ((char *)&(last)) + ((sizeof(last)+3)&~3)) - #define __builtin_va_arg(ap,type) (ap = (void *) ((_tcc_align(ap,type)+sizeof(type)+3) \ - &~3), *(type *)(ap - ((sizeof(type)+3)&~3))) - -#elif defined __aarch64__ - typedef struct { - void *__stack, *__gr_top, *__vr_top; - int __gr_offs, __vr_offs; - } __builtin_va_list; - -#elif defined __riscv - typedef char *__builtin_va_list; - #define __va_reg_size (__riscv_xlen >> 3) - #define _tcc_align(addr,type) (((unsigned long)addr + __alignof__(type) - 1) \ - & -(__alignof__(type))) - #define __builtin_va_arg(ap,type) (*(sizeof(type) > (2*__va_reg_size) ? *(type **)((ap += __va_reg_size) - __va_reg_size) : (ap = (va_list)(_tcc_align(ap,type) + (sizeof(type)+__va_reg_size - 1)& -__va_reg_size), (type *)(ap - ((sizeof(type)+ __va_reg_size - 1)& -__va_reg_size))))) - -#else /* __i386__ */ - typedef char *__builtin_va_list; - #define __builtin_va_start(ap,last) (ap = ((char *)&(last)) + ((sizeof(last)+3)&~3)) - #define __builtin_va_arg(ap,t) (*(t*)((ap+=(sizeof(t)+3)&~3)-((sizeof(t)+3)&~3))) - -#endif - #define __builtin_va_end(ap) (void)(ap) - #ifndef __builtin_va_copy - # define __builtin_va_copy(dest, src) (dest) = (src) - #endif - - /* TCC BBUILTIN AND BOUNDS ALIASES */ - #ifdef __leading_underscore - # define __RENAME(X) __asm__("_"X) - #else - # define __RENAME(X) __asm__(X) - #endif - - #ifdef __BOUNDS_CHECKING_ON - # define __BUILTINBC(ret,name,params) ret __builtin_##name params __RENAME("__bound_"#name); - # define __BOUND(ret,name,params) ret name params __RENAME("__bound_"#name); - #else - # define __BUILTINBC(ret,name,params) ret __builtin_##name params __RENAME(#name); - # define __BOUND(ret,name,params) - #endif -#ifdef _WIN32 - #define __BOTH __BOUND - #define __BUILTIN(ret,name,params) -#else - #define __BOTH(ret,name,params) __BUILTINBC(ret,name,params)__BOUND(ret,name,params) - #define __BUILTIN(ret,name,params) ret __builtin_##name params __RENAME(#name); -#endif - - __BOTH(void*, memcpy, (void *, const void*, __SIZE_TYPE__)) - __BOTH(void*, memmove, (void *, const void*, __SIZE_TYPE__)) - __BOTH(void*, memset, (void *, int, __SIZE_TYPE__)) - __BOTH(int, memcmp, (const void *, const void*, __SIZE_TYPE__)) - __BOTH(__SIZE_TYPE__, strlen, (const char *)) - __BOTH(char*, strcpy, (char *, const char *)) - __BOTH(char*, strncpy, (char *, const char*, __SIZE_TYPE__)) - __BOTH(int, strcmp, (const char*, const char*)) - __BOTH(int, strncmp, (const char*, const char*, __SIZE_TYPE__)) - __BOTH(char*, strcat, (char*, const char*)) - __BOTH(char*, strchr, (const char*, int)) - __BOTH(char*, strdup, (const char*)) -#if defined __ARM_EABI__ - __BOUND(void*,__aeabi_memcpy,(void*,const void*,__SIZE_TYPE__)) - __BOUND(void*,__aeabi_memmove,(void*,const void*,__SIZE_TYPE__)) - __BOUND(void*,__aeabi_memmove4,(void*,const void*,__SIZE_TYPE__)) - __BOUND(void*,__aeabi_memmove8,(void*,const void*,__SIZE_TYPE__)) - __BOUND(void*,__aeabi_memset,(void*,int,__SIZE_TYPE__)) -#endif - -#if defined __linux__ || defined __APPLE__ // HAVE MALLOC_REDIR - #define __MAYBE_REDIR __BUILTIN -#else - #define __MAYBE_REDIR __BOTH -#endif - __MAYBE_REDIR(void*, malloc, (__SIZE_TYPE__)) - __MAYBE_REDIR(void*, realloc, (void *, __SIZE_TYPE__)) - __MAYBE_REDIR(void*, calloc, (__SIZE_TYPE__, __SIZE_TYPE__)) - __MAYBE_REDIR(void*, memalign, (__SIZE_TYPE__, __SIZE_TYPE__)) - __MAYBE_REDIR(void, free, (void*)) -#if defined __i386__ || defined __x86_64__ - __BOTH(void*, alloca, (__SIZE_TYPE__)) -#else - __BUILTIN(void*, alloca, (__SIZE_TYPE__)) -#endif - __BUILTIN(void, abort, (void)) - __BOUND(void, longjmp, ()) -#if !defined _WIN32 - __BOUND(void*, mmap, ()) - __BOUND(int, munmap, ()) -#endif - #undef __BUILTINBC - #undef __BUILTIN - #undef __BOUND - #undef __BOTH - #undef __MAYBE_REDIR - #undef __RENAME - - #endif /* ndef __TCC_PP__ */ diff --git a/05/tcc-final/include/tgmath.h b/05/tcc-final/include/tgmath.h deleted file mode 100644 index 5d3e357..0000000 --- a/05/tcc-final/include/tgmath.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * ISO C Standard: 7.22 Type-generic math - */ - -#ifndef _TGMATH_H -#define _TGMATH_H - -#include - -#ifndef __cplusplus -#define __tgmath_real(x, F) \ - _Generic ((x), float: F##f, long double: F##l, default: F)(x) -#define __tgmath_real_2_1(x, y, F) \ - _Generic ((x), float: F##f, long double: F##l, default: F)(x, y) -#define __tgmath_real_2(x, y, F) \ - _Generic ((x)+(y), float: F##f, long double: F##l, default: F)(x, y) -#define __tgmath_real_3_2(x, y, z, F) \ - _Generic ((x)+(y), float: F##f, long double: F##l, default: F)(x, y, z) -#define __tgmath_real_3(x, y, z, F) \ - _Generic ((x)+(y)+(z), float: F##f, long double: F##l, default: F)(x, y, z) - -/* Functions defined in both and (7.22p4) */ -#define acos(z) __tgmath_real(z, acos) -#define asin(z) __tgmath_real(z, asin) -#define atan(z) __tgmath_real(z, atan) -#define acosh(z) __tgmath_real(z, acosh) -#define asinh(z) __tgmath_real(z, asinh) -#define atanh(z) __tgmath_real(z, atanh) -#define cos(z) __tgmath_real(z, cos) -#define sin(z) __tgmath_real(z, sin) -#define tan(z) __tgmath_real(z, tan) -#define cosh(z) __tgmath_real(z, cosh) -#define sinh(z) __tgmath_real(z, sinh) -#define tanh(z) __tgmath_real(z, tanh) -#define exp(z) __tgmath_real(z, exp) -#define log(z) __tgmath_real(z, log) -#define pow(z1,z2) __tgmath_real_2(z1, z2, pow) -#define sqrt(z) __tgmath_real(z, sqrt) -#define fabs(z) __tgmath_real(z, fabs) - -/* Functions defined in only (7.22p5) */ -#define atan2(x,y) __tgmath_real_2(x, y, atan2) -#define cbrt(x) __tgmath_real(x, cbrt) -#define ceil(x) __tgmath_real(x, ceil) -#define copysign(x,y) __tgmath_real_2(x, y, copysign) -#define erf(x) __tgmath_real(x, erf) -#define erfc(x) __tgmath_real(x, erfc) -#define exp2(x) __tgmath_real(x, exp2) -#define expm1(x) __tgmath_real(x, expm1) -#define fdim(x,y) __tgmath_real_2(x, y, fdim) -#define floor(x) __tgmath_real(x, floor) -#define fma(x,y,z) __tgmath_real_3(x, y, z, fma) -#define fmax(x,y) __tgmath_real_2(x, y, fmax) -#define fmin(x,y) __tgmath_real_2(x, y, fmin) -#define fmod(x,y) __tgmath_real_2(x, y, fmod) -#define frexp(x,y) __tgmath_real_2_1(x, y, frexp) -#define hypot(x,y) __tgmath_real_2(x, y, hypot) -#define ilogb(x) __tgmath_real(x, ilogb) -#define ldexp(x,y) __tgmath_real_2_1(x, y, ldexp) -#define lgamma(x) __tgmath_real(x, lgamma) -#define llrint(x) __tgmath_real(x, llrint) -#define llround(x) __tgmath_real(x, llround) -#define log10(x) __tgmath_real(x, log10) -#define log1p(x) __tgmath_real(x, log1p) -#define log2(x) __tgmath_real(x, log2) -#define logb(x) __tgmath_real(x, logb) -#define lrint(x) __tgmath_real(x, lrint) -#define lround(x) __tgmath_real(x, lround) -#define nearbyint(x) __tgmath_real(x, nearbyint) -#define nextafter(x,y) __tgmath_real_2(x, y, nextafter) -#define nexttoward(x,y) __tgmath_real_2(x, y, nexttoward) -#define remainder(x,y) __tgmath_real_2(x, y, remainder) -#define remquo(x,y,z) __tgmath_real_3_2(x, y, z, remquo) -#define rint(x) __tgmath_real(x, rint) -#define round(x) __tgmath_real(x, round) -#define scalbln(x,y) __tgmath_real_2_1(x, y, scalbln) -#define scalbn(x,y) __tgmath_real_2_1(x, y, scalbn) -#define tgamma(x) __tgmath_real(x, tgamma) -#define trunc(x) __tgmath_real(x, trunc) - -/* Functions defined in only (7.22p6) -#define carg(z) __tgmath_cplx_only(z, carg) -#define cimag(z) __tgmath_cplx_only(z, cimag) -#define conj(z) __tgmath_cplx_only(z, conj) -#define cproj(z) __tgmath_cplx_only(z, cproj) -#define creal(z) __tgmath_cplx_only(z, creal) -*/ -#endif /* __cplusplus */ -#endif /* _TGMATH_H */ diff --git a/05/tcc-final/include/varargs.h b/05/tcc-final/include/varargs.h deleted file mode 100644 index d614366..0000000 --- a/05/tcc-final/include/varargs.h +++ /dev/null @@ -1,12 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the w64 mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within this package. - */ -#ifndef _VARARGS_H -#define _VARARGS_H - -#error "TinyCC no longer implements ." -#error "Revise your code to use ." - -#endif diff --git a/05/tcc-final/lib/Makefile b/05/tcc-final/lib/Makefile deleted file mode 100644 index 74722b6..0000000 --- a/05/tcc-final/lib/Makefile +++ /dev/null @@ -1,94 +0,0 @@ -# -# Tiny C Compiler Makefile for libtcc1.a -# - -TOP = .. -include $(TOP)/Makefile -VPATH = $(TOPSRC)/lib $(TOPSRC)/win32/lib -T = $(or $(CROSS_TARGET),$(NATIVE_TARGET),unknown) -X = $(if $(CROSS_TARGET),$(CROSS_TARGET)-) - -XTCC ?= $(TOP)/$(X)tcc$(EXESUF) -XCC = $(XTCC) -XAR = $(XTCC) -ar -XFLAGS-unx = -B$(TOPSRC) -XFLAGS-win = -B$(TOPSRC)/win32 -I$(TOPSRC)/include -XFLAGS = $(XFLAGS$(XCFG)) -I$(TOP) -XCFG = $(or $(findstring -win,$T),-unx) -S = $(if $(findstring yes,$(SILENT)),@$(info * $@)) - -# in order to use gcc, type: make -libtcc1-usegcc=yes -arm-libtcc1-usegcc ?= no - -# This makes bounds checking 40%..60% faster. -#x86_64-libtcc1-usegcc=yes -#i386-libtcc1-usegcc=yes - -ifeq "$($(T)-libtcc1-usegcc)" "yes" - XCC = $(CC) - XAR = $(AR) - XFLAGS = $(CFLAGS) -fPIC -gdwarf -fno-omit-frame-pointer -Wno-unused-function -Wno-unused-variable -endif - -ifneq ($(CONFIG_backtrace),no) -# only for native compiler -ifneq ($(CONFIG_bcheck),no) -$(X)BCHECK_O = bcheck.o -endif -$(X)BT_O = bt-exe.o bt-log.o -$(X)B_O = $(BCHECK_O) bt-exe.o bt-log.o bt-dll.o -endif -$(X)BT_O += tcov.o - -DSO_O = dsohandle.o - -I386_O = libtcc1.o alloca.o alloca-bt.o $(BT_O) stdatomic.o -X86_64_O = libtcc1.o alloca.o alloca-bt.o $(BT_O) stdatomic.o -ARM_O = libtcc1.o armeabi.o alloca.o armflush.o fetch_and_add.o $(BT_O) -ARM64_O = lib-arm64.o fetch_and_add.o $(BT_O) -RISCV64_O = lib-arm64.o fetch_and_add.o $(BT_O) -WIN_O = crt1.o crt1w.o wincrt1.o wincrt1w.o dllcrt1.o dllmain.o - -OBJ-i386 = $(I386_O) $(BCHECK_O) $(DSO_O) -OBJ-x86_64 = $(X86_64_O) va_list.o $(BCHECK_O) $(DSO_O) -OBJ-x86_64-osx = $(X86_64_O) va_list.o $(BCHECK_O) -OBJ-i386-win32 = $(I386_O) chkstk.o $(B_O) $(WIN_O) -OBJ-x86_64-win32 = $(X86_64_O) chkstk.o $(B_O) $(WIN_O) -OBJ-arm64 = $(ARM64_O) $(BCHECK_O) $(DSO_O) -OBJ-arm64-osx = $(ARM64_O) va_list.o -OBJ-arm = $(ARM_O) $(BCHECK_O) $(DSO_O) -OBJ-arm-fpa = $(ARM_O) $(DSO_O) -OBJ-arm-fpa-ld = $(ARM_O) $(DSO_O) -OBJ-arm-vfp = $(ARM_O) $(DSO_O) -OBJ-arm-eabi = $(ARM_O) $(DSO_O) -OBJ-arm-eabihf = $(ARM_O) $(DSO_O) -OBJ-arm-wince = $(ARM_O) $(WIN_O) -OBJ-riscv64 = $(RISCV64_O) $(BCHECK_O) $(DSO_O) - -OBJ-extra = $(filter $(B_O),$(OBJ-$T)) -OBJ-libtcc1 = $(addprefix $(X),$(filter-out $(OBJ-extra),$(OBJ-$T))) - -ALL = $(addprefix $(TOP)/,$(X)libtcc1.a $(OBJ-extra)) - -all: $(ALL) - -$(TOP)/$(X)libtcc1.a : $(OBJ-libtcc1) - $S$(XAR) rcs $@ $^ - -$(X)%.o : %.c - $S$(XCC) -c $< -o $@ $(XFLAGS) - -$(X)%.o : %.S - $S$(XCC) -c $< -o $@ $(XFLAGS) - -$(TOP)/%.o : %.c - $S$(XCC) -c $< -o $@ $(XFLAGS) - -$(TOP)/bcheck.o : XFLAGS += -g $(if $(CONFIG_musl),-DTCC_MUSL) -$(TOP)/bt-exe.o : $(TOP)/tccrun.c - -$(X)crt1w.o : crt1.c -$(X)wincrt1w.o : wincrt1.c - -clean : - rm -f *.a *.o $(ALL) diff --git a/05/tcc-final/lib/alloca-bt.S b/05/tcc-final/lib/alloca-bt.S deleted file mode 100644 index c161488..0000000 --- a/05/tcc-final/lib/alloca-bt.S +++ /dev/null @@ -1,96 +0,0 @@ -/* ---------------------------------------------- */ -/* alloca-bt.S */ - -#ifdef __leading_underscore -# define _(s) _##s -#else -# define _(s) s -#endif - -/* ---------------------------------------------- */ -#if defined __i386__ - -.globl _(__bound_alloca) -_(__bound_alloca): - pop %edx - pop %eax - mov %eax, %ecx - add $3+1,%eax - and $-4,%eax - jz p6 - -#ifdef _WIN32 -p4: - cmp $4096,%eax - jbe p5 - test %eax,-4096(%esp) - sub $4096,%esp - sub $4096,%eax - jmp p4 - -p5: -#endif - - sub %eax,%esp - mov %esp,%eax - - push %edx - push %eax - push %ecx - push %eax - call _(__bound_new_region) - add $8, %esp - pop %eax - pop %edx - -p6: - push %edx - push %edx - ret - -/* ---------------------------------------------- */ -#elif defined __x86_64__ - -.globl _(__bound_alloca) -_(__bound_alloca): -#ifdef _WIN32 - inc %rcx # add one extra to separate regions - jmp _(alloca) -.globl _(__bound_alloca_nr) -_(__bound_alloca_nr): - dec %rcx - push %rax - mov %rcx,%rdx - mov %rax,%rcx - sub $32,%rsp - call _(__bound_new_region) - add $32,%rsp - pop %rax - ret -#else - pop %rdx - mov %rdi,%rax - mov %rax,%rsi # size, a second parm to the __bound_new_region - - add $15 + 1,%rax # add one extra to separate regions - and $-16,%rax - jz p3 - - - sub %rax,%rsp - mov %rsp,%rdi # pointer, a first parm to the __bound_new_region - mov %rsp,%rax - - push %rdx - push %rax - call _(__bound_new_region) - pop %rax - pop %rdx - -p3: - push %rdx - ret -#endif - -/* ---------------------------------------------- */ -#endif diff --git a/05/tcc-final/lib/alloca.S b/05/tcc-final/lib/alloca.S deleted file mode 100644 index 6ebafd7..0000000 --- a/05/tcc-final/lib/alloca.S +++ /dev/null @@ -1,85 +0,0 @@ -/* ---------------------------------------------- */ -/* alloca.S */ - -#ifdef __leading_underscore -# define _(s) _##s -#else -# define _(s) s -#endif - -/* ---------------------------------------------- */ -#if defined __i386__ - -.globl _(alloca), _(__alloca) -_(alloca): -_(__alloca): - push %ebp - mov %esp,%ebp - mov 8(%ebp),%eax - add $3,%eax - and $-4,%eax -#ifdef _WIN32 - jmp .+16 #p2 -p1: - sub $4096,%esp - sub $4096,%eax - test %eax,(%esp) -p2: - cmp $4096,%eax - jae p1 -#endif - sub %eax,%esp - mov 4(%ebp),%eax - mov 0(%ebp),%ebp - add $8,%esp - push %eax - lea 8(%esp),%eax - ret - -/* ---------------------------------------------- */ -#elif defined __x86_64__ - -.globl _(alloca) -_(alloca): - pop %rdx -#ifdef _WIN32 - mov %rcx,%rax -#else - mov %rdi,%rax -#endif - add $15,%rax - and $-16,%rax - jz p3 - -#ifdef _WIN32 -p1: - cmp $4096,%rax - jbe p2 - test %rax,-4096(%rsp) - sub $4096,%rsp - sub $4096,%rax - jmp p1 -p2: -#endif - sub %rax,%rsp - mov %rsp,%rax -p3: - push %rdx - ret - -/* ---------------------------------------------- */ -#elif defined __arm__ - - .text - .align 2 - .global alloca - .type alloca, %function -alloca: - rsb sp, r0, sp - bic sp, sp, #7 - mov r0, sp - mov pc, lr - .size alloca, .-alloca - -/* ---------------------------------------------- */ -#endif diff --git a/05/tcc-final/lib/armeabi.c b/05/tcc-final/lib/armeabi.c deleted file mode 100644 index 1bccbd3..0000000 --- a/05/tcc-final/lib/armeabi.c +++ /dev/null @@ -1,537 +0,0 @@ -/* TCC ARM runtime EABI - Copyright (C) 2013 Thomas Preud'homme - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE.*/ - -#ifdef __TINYC__ -#define INT_MIN (-2147483647 - 1) -#define INT_MAX 2147483647 -#define UINT_MAX 0xffffffff -#define LONG_MIN (-2147483647L - 1) -#define LONG_MAX 2147483647L -#define ULONG_MAX 0xffffffffUL -#define LLONG_MAX 9223372036854775807LL -#define LLONG_MIN (-9223372036854775807LL - 1) -#define ULLONG_MAX 0xffffffffffffffffULL -#else -#include -#endif - -/* We rely on the little endianness and EABI calling convention for this to - work */ - -typedef struct double_unsigned_struct { - unsigned low; - unsigned high; -} double_unsigned_struct; - -typedef struct unsigned_int_struct { - unsigned low; - int high; -} unsigned_int_struct; - -#define REGS_RETURN(name, type) \ - void name ## _return(type ret) {} - - -/* Float helper functions */ - -#define FLOAT_EXP_BITS 8 -#define FLOAT_FRAC_BITS 23 - -#define DOUBLE_EXP_BITS 11 -#define DOUBLE_FRAC_BITS 52 - -#define ONE_EXP(type) ((1 << (type ## _EXP_BITS - 1)) - 1) - -REGS_RETURN(unsigned_int_struct, unsigned_int_struct) -REGS_RETURN(double_unsigned_struct, double_unsigned_struct) - -/* float -> integer: (sign) 1.fraction x 2^(exponent - exp_for_one) */ - - -/* float to [unsigned] long long conversion */ -#define DEFINE__AEABI_F2XLZ(name, with_sign) \ -void __aeabi_ ## name(unsigned val) \ -{ \ - int exp, high_shift, sign; \ - double_unsigned_struct ret; \ - \ - /* compute sign */ \ - sign = val >> 31; \ - \ - /* compute real exponent */ \ - exp = val >> FLOAT_FRAC_BITS; \ - exp &= (1 << FLOAT_EXP_BITS) - 1; \ - exp -= ONE_EXP(FLOAT); \ - \ - /* undefined behavior if truncated value cannot be represented */ \ - if (with_sign) { \ - if (exp > 62) /* |val| too big, double cannot represent LLONG_MAX */ \ - return; \ - } else { \ - if ((sign && exp >= 0) || exp > 63) /* if val < 0 || val too big */ \ - return; \ - } \ - \ - val &= (1 << FLOAT_FRAC_BITS) - 1; \ - if (exp >= 32) { \ - ret.high = 1 << (exp - 32); \ - if (exp - 32 >= FLOAT_FRAC_BITS) { \ - ret.high |= val << (exp - 32 - FLOAT_FRAC_BITS); \ - ret.low = 0; \ - } else { \ - high_shift = FLOAT_FRAC_BITS - (exp - 32); \ - ret.high |= val >> high_shift; \ - ret.low = val << (32 - high_shift); \ - } \ - } else { \ - ret.high = 0; \ - ret.low = 1 << exp; \ - if (exp > FLOAT_FRAC_BITS) \ - ret.low |= val << (exp - FLOAT_FRAC_BITS); \ - else \ - ret.low |= val >> (FLOAT_FRAC_BITS - exp); \ - } \ - \ - /* encode negative integer using 2's complement */ \ - if (with_sign && sign) { \ - ret.low = ~ret.low; \ - ret.high = ~ret.high; \ - if (ret.low == UINT_MAX) { \ - ret.low = 0; \ - ret.high++; \ - } else \ - ret.low++; \ - } \ - \ - double_unsigned_struct_return(ret); \ -} - -/* float to unsigned long long conversion */ -DEFINE__AEABI_F2XLZ(f2ulz, 0) - -/* float to long long conversion */ -DEFINE__AEABI_F2XLZ(f2lz, 1) - -/* double to [unsigned] long long conversion */ -#define DEFINE__AEABI_D2XLZ(name, with_sign) \ -void __aeabi_ ## name(double_unsigned_struct val) \ -{ \ - int exp, high_shift, sign; \ - double_unsigned_struct ret; \ - \ - /* compute sign */ \ - sign = val.high >> 31; \ - \ - /* compute real exponent */ \ - exp = (val.high >> (DOUBLE_FRAC_BITS - 32)); \ - exp &= (1 << DOUBLE_EXP_BITS) - 1; \ - exp -= ONE_EXP(DOUBLE); \ - \ - /* undefined behavior if truncated value cannot be represented */ \ - if (with_sign) { \ - if (exp > 62) /* |val| too big, double cannot represent LLONG_MAX */ \ - return; \ - } else { \ - if ((sign && exp >= 0) || exp > 63) /* if val < 0 || val too big */ \ - return; \ - } \ - \ - val.high &= (1 << (DOUBLE_FRAC_BITS - 32)) - 1; \ - if (exp >= 32) { \ - ret.high = 1 << (exp - 32); \ - if (exp >= DOUBLE_FRAC_BITS) { \ - high_shift = exp - DOUBLE_FRAC_BITS; \ - ret.high |= val.high << high_shift; \ - ret.high |= val.low >> (32 - high_shift); \ - ret.low = val.low << high_shift; \ - } else { \ - high_shift = DOUBLE_FRAC_BITS - exp; \ - ret.high |= val.high >> high_shift; \ - ret.low = val.high << (32 - high_shift); \ - ret.low |= val.low >> high_shift; \ - } \ - } else { \ - ret.high = 0; \ - ret.low = 1 << exp; \ - if (exp > DOUBLE_FRAC_BITS - 32) { \ - high_shift = exp - DOUBLE_FRAC_BITS - 32; \ - ret.low |= val.high << high_shift; \ - ret.low |= val.low >> (32 - high_shift); \ - } else \ - ret.low |= val.high >> (DOUBLE_FRAC_BITS - 32 - exp); \ - } \ - \ - /* encode negative integer using 2's complement */ \ - if (with_sign && sign) { \ - ret.low = ~ret.low; \ - ret.high = ~ret.high; \ - if (ret.low == UINT_MAX) { \ - ret.low = 0; \ - ret.high++; \ - } else \ - ret.low++; \ - } \ - \ - double_unsigned_struct_return(ret); \ -} - -/* double to unsigned long long conversion */ -DEFINE__AEABI_D2XLZ(d2ulz, 0) - -/* double to long long conversion */ -DEFINE__AEABI_D2XLZ(d2lz, 1) - -/* long long to float conversion */ -#define DEFINE__AEABI_XL2F(name, with_sign) \ -unsigned __aeabi_ ## name(unsigned long long v) \ -{ \ - int s /* shift */, flb /* first lost bit */, sign = 0; \ - unsigned p = 0 /* power */, ret; \ - double_unsigned_struct val; \ - \ - /* fraction in negative float is encoded in 1's complement */ \ - if (with_sign && (v & (1ULL << 63))) { \ - sign = 1; \ - v = ~v + 1; \ - } \ - val.low = v; \ - val.high = v >> 32; \ - /* fill fraction bits */ \ - for (s = 31, p = 1 << 31; p && !(val.high & p); s--, p >>= 1); \ - if (p) { \ - ret = val.high & (p - 1); \ - if (s < FLOAT_FRAC_BITS) { \ - ret <<= FLOAT_FRAC_BITS - s; \ - ret |= val.low >> (32 - (FLOAT_FRAC_BITS - s)); \ - flb = (val.low >> (32 - (FLOAT_FRAC_BITS - s - 1))) & 1; \ - } else { \ - flb = (ret >> (s - FLOAT_FRAC_BITS - 1)) & 1; \ - ret >>= s - FLOAT_FRAC_BITS; \ - } \ - s += 32; \ - } else { \ - for (s = 31, p = 1 << 31; p && !(val.low & p); s--, p >>= 1); \ - if (p) { \ - ret = val.low & (p - 1); \ - if (s <= FLOAT_FRAC_BITS) { \ - ret <<= FLOAT_FRAC_BITS - s; \ - flb = 0; \ - } else { \ - flb = (ret >> (s - FLOAT_FRAC_BITS - 1)) & 1; \ - ret >>= s - FLOAT_FRAC_BITS; \ - } \ - } else \ - return 0; \ - } \ - if (flb) \ - ret++; \ - \ - /* fill exponent bits */ \ - ret |= (s + ONE_EXP(FLOAT)) << FLOAT_FRAC_BITS; \ - \ - /* fill sign bit */ \ - ret |= sign << 31; \ - \ - return ret; \ -} - -/* unsigned long long to float conversion */ -DEFINE__AEABI_XL2F(ul2f, 0) - -/* long long to float conversion */ -DEFINE__AEABI_XL2F(l2f, 1) - -/* long long to double conversion */ -#define __AEABI_XL2D(name, with_sign) \ -void __aeabi_ ## name(unsigned long long v) \ -{ \ - int s /* shift */, high_shift, sign = 0; \ - unsigned tmp, p = 0; \ - double_unsigned_struct val, ret; \ - \ - /* fraction in negative float is encoded in 1's complement */ \ - if (with_sign && (v & (1ULL << 63))) { \ - sign = 1; \ - v = ~v + 1; \ - } \ - val.low = v; \ - val.high = v >> 32; \ - \ - /* fill fraction bits */ \ - for (s = 31, p = 1 << 31; p && !(val.high & p); s--, p >>= 1); \ - if (p) { \ - tmp = val.high & (p - 1); \ - if (s < DOUBLE_FRAC_BITS - 32) { \ - high_shift = DOUBLE_FRAC_BITS - 32 - s; \ - ret.high = tmp << high_shift; \ - ret.high |= val.low >> (32 - high_shift); \ - ret.low = val.low << high_shift; \ - } else { \ - high_shift = s - (DOUBLE_FRAC_BITS - 32); \ - ret.high = tmp >> high_shift; \ - ret.low = tmp << (32 - high_shift); \ - ret.low |= val.low >> high_shift; \ - if ((val.low >> (high_shift - 1)) & 1) { \ - if (ret.low == UINT_MAX) { \ - ret.high++; \ - ret.low = 0; \ - } else \ - ret.low++; \ - } \ - } \ - s += 32; \ - } else { \ - for (s = 31, p = 1 << 31; p && !(val.low & p); s--, p >>= 1); \ - if (p) { \ - tmp = val.low & (p - 1); \ - if (s <= DOUBLE_FRAC_BITS - 32) { \ - high_shift = DOUBLE_FRAC_BITS - 32 - s; \ - ret.high = tmp << high_shift; \ - ret.low = 0; \ - } else { \ - high_shift = s - (DOUBLE_FRAC_BITS - 32); \ - ret.high = tmp >> high_shift; \ - ret.low = tmp << (32 - high_shift); \ - } \ - } else { \ - ret.high = ret.low = 0; \ - double_unsigned_struct_return(ret); \ - } \ - } \ - \ - /* fill exponent bits */ \ - ret.high |= (s + ONE_EXP(DOUBLE)) << (DOUBLE_FRAC_BITS - 32); \ - \ - /* fill sign bit */ \ - ret.high |= sign << 31; \ - \ - double_unsigned_struct_return(ret); \ -} - -/* unsigned long long to double conversion */ -__AEABI_XL2D(ul2d, 0) - -/* long long to double conversion */ -__AEABI_XL2D(l2d, 1) - - -/* Long long helper functions */ - -/* TODO: add error in case of den == 0 (see §4.3.1 and §4.3.2) */ - -#define define_aeabi_xdivmod_signed_type(basetype, type) \ -typedef struct type { \ - basetype quot; \ - unsigned basetype rem; \ -} type - -#define define_aeabi_xdivmod_unsigned_type(basetype, type) \ -typedef struct type { \ - basetype quot; \ - basetype rem; \ -} type - -#define AEABI_UXDIVMOD(name,type, rettype, typemacro) \ -static inline rettype aeabi_ ## name (type num, type den) \ -{ \ - rettype ret; \ - type quot = 0; \ - \ - /* Increase quotient while it is less than numerator */ \ - while (num >= den) { \ - type q = 1; \ - \ - /* Find closest power of two */ \ - while ((q << 1) * den <= num && q * den <= typemacro ## _MAX / 2) \ - q <<= 1; \ - \ - /* Compute difference between current quotient and numerator */ \ - num -= q * den; \ - quot += q; \ - } \ - ret.quot = quot; \ - ret.rem = num; \ - return ret; \ -} - -#define __AEABI_XDIVMOD(name, type, uiname, rettype, urettype, typemacro) \ -void __aeabi_ ## name(type numerator, type denominator) \ -{ \ - unsigned type num, den; \ - urettype uxdiv_ret; \ - rettype ret; \ - \ - if (numerator >= 0) \ - num = numerator; \ - else \ - num = 0 - numerator; \ - if (denominator >= 0) \ - den = denominator; \ - else \ - den = 0 - denominator; \ - uxdiv_ret = aeabi_ ## uiname(num, den); \ - /* signs differ */ \ - if ((numerator & typemacro ## _MIN) != (denominator & typemacro ## _MIN)) \ - ret.quot = 0 - uxdiv_ret.quot; \ - else \ - ret.quot = uxdiv_ret.quot; \ - if (numerator < 0) \ - ret.rem = 0 - uxdiv_ret.rem; \ - else \ - ret.rem = uxdiv_ret.rem; \ - \ - rettype ## _return(ret); \ -} - -define_aeabi_xdivmod_signed_type(long long, lldiv_t); -define_aeabi_xdivmod_unsigned_type(unsigned long long, ulldiv_t); -define_aeabi_xdivmod_signed_type(int, idiv_t); -define_aeabi_xdivmod_unsigned_type(unsigned, uidiv_t); - -REGS_RETURN(lldiv_t, lldiv_t) -REGS_RETURN(ulldiv_t, ulldiv_t) -REGS_RETURN(idiv_t, idiv_t) -REGS_RETURN(uidiv_t, uidiv_t) - -AEABI_UXDIVMOD(uldivmod, unsigned long long, ulldiv_t, ULLONG) - -__AEABI_XDIVMOD(ldivmod, long long, uldivmod, lldiv_t, ulldiv_t, LLONG) - -void __aeabi_uldivmod(unsigned long long num, unsigned long long den) -{ - ulldiv_t_return(aeabi_uldivmod(num, den)); -} - -void __aeabi_llsl(double_unsigned_struct val, int shift) -{ - double_unsigned_struct ret; - - if (shift >= 32) { - val.high = val.low; - val.low = 0; - shift -= 32; - } - if (shift > 0) { - ret.low = val.low << shift; - ret.high = (val.high << shift) | (val.low >> (32 - shift)); - double_unsigned_struct_return(ret); - return; - } - double_unsigned_struct_return(val); -} - -#define aeabi_lsr(val, shift, fill, type) \ - type ## _struct ret; \ - \ - if (shift >= 32) { \ - val.low = val.high; \ - val.high = fill; \ - shift -= 32; \ - } \ - if (shift > 0) { \ - ret.high = val.high >> shift; \ - ret.low = (val.high << (32 - shift)) | (val.low >> shift); \ - type ## _struct_return(ret); \ - return; \ - } \ - type ## _struct_return(val); - -void __aeabi_llsr(double_unsigned_struct val, int shift) -{ - aeabi_lsr(val, shift, 0, double_unsigned); -} - -void __aeabi_lasr(unsigned_int_struct val, int shift) -{ - aeabi_lsr(val, shift, val.high >> 31, unsigned_int); -} - - -/* Integer division functions */ - -AEABI_UXDIVMOD(uidivmod, unsigned, uidiv_t, UINT) - -int __aeabi_idiv(int numerator, int denominator) -{ - unsigned num, den; - uidiv_t ret; - - if (numerator >= 0) - num = numerator; - else - num = 0 - numerator; - if (denominator >= 0) - den = denominator; - else - den = 0 - denominator; - ret = aeabi_uidivmod(num, den); - if ((numerator & INT_MIN) != (denominator & INT_MIN)) /* signs differ */ - ret.quot *= -1; - return ret.quot; -} - -unsigned __aeabi_uidiv(unsigned num, unsigned den) -{ - return aeabi_uidivmod(num, den).quot; -} - -__AEABI_XDIVMOD(idivmod, int, uidivmod, idiv_t, uidiv_t, INT) - -void __aeabi_uidivmod(unsigned num, unsigned den) -{ - uidiv_t_return(aeabi_uidivmod(num, den)); -} - -/* Some targets do not have all eabi calls (OpenBSD) */ -typedef __SIZE_TYPE__ size_t; -extern void *memcpy(void *dest, const void *src, size_t n); -extern void *memmove(void *dest, const void *src, size_t n); -extern void *memset(void *s, int c, size_t n); - -void * -__aeabi_memcpy (void *dest, const void *src, size_t n) -{ - return memcpy (dest, src, n); -} - -void * -__aeabi_memmove (void *dest, const void *src, size_t n) -{ - return memmove (dest, src, n); -} - -void * -__aeabi_memmove4 (void *dest, const void *src, size_t n) -{ - return memmove (dest, src, n); -} - -void * -__aeabi_memmove8 (void *dest, const void *src, size_t n) -{ - return memmove (dest, src, n); -} - -void * -__aeabi_memset (void *s, size_t n, int c) -{ - return memset (s, c, n); -} diff --git a/05/tcc-final/lib/armflush.c b/05/tcc-final/lib/armflush.c deleted file mode 100644 index c379e43..0000000 --- a/05/tcc-final/lib/armflush.c +++ /dev/null @@ -1,51 +0,0 @@ -/* armflush.c - flush the instruction cache - - __clear_cache is used in tccrun.c, It is a built-in - intrinsic with gcc. However tcc in order to compile - itself needs this function */ - -#ifdef __TINYC__ - -/* syscall wrapper */ -unsigned _tccsyscall(unsigned syscall_nr, ...); - -/* arm-tcc supports only fake asm currently */ -__asm__( - ".global _tccsyscall\n" - "_tccsyscall:\n" - "push {r7, lr}\n\t" - "mov r7, r0\n\t" - "mov r0, r1\n\t" - "mov r1, r2\n\t" - "mov r2, r3\n\t" - "svc #0\n\t" - "pop {r7, pc}" - ); - -/* from unistd.h: */ -#if defined(__thumb__) || defined(__ARM_EABI__) -# define __NR_SYSCALL_BASE 0x0 -#else -# define __NR_SYSCALL_BASE 0x900000 -#endif -#define __ARM_NR_BASE (__NR_SYSCALL_BASE+0x0f0000) -#define __ARM_NR_cacheflush (__ARM_NR_BASE+2) - -#define syscall _tccsyscall - -#else - -#define _GNU_SOURCE -#include -#include -#include - -#endif - -/* Flushing for tccrun */ -void __clear_cache(void *beginning, void *end) -{ -/* __ARM_NR_cacheflush is kernel private and should not be used in user space. - * However, there is no ARM asm parser in tcc so we use it for now */ - syscall(__ARM_NR_cacheflush, beginning, end, 0); -} diff --git a/05/tcc-final/lib/bcheck.c b/05/tcc-final/lib/bcheck.c deleted file mode 100644 index 729f0b5..0000000 --- a/05/tcc-final/lib/bcheck.c +++ /dev/null @@ -1,2226 +0,0 @@ -/* - * Tiny C Memory and bounds checker - * - * Copyright (c) 2002 Fabrice Bellard - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#include -#include -#include -#include -#include - -#if !defined(__FreeBSD__) \ - && !defined(__FreeBSD_kernel__) \ - && !defined(__DragonFly__) \ - && !defined(__OpenBSD__) \ - && !defined(__APPLE__) \ - && !defined(__NetBSD__) -#include -#endif - -#if !defined(_WIN32) -#include -#include -#endif - -#define BOUND_DEBUG (1) -#define BOUND_STATISTIC (1) - -#if BOUND_DEBUG - #define dprintf(a...) if (print_calls) fprintf(a) -#else - #define dprintf(a...) -#endif - -#ifdef __attribute__ - /* an __attribute__ macro is defined in the system headers */ - #undef __attribute__ -#endif -#define FASTCALL __attribute__((regparm(3))) - -#ifdef _WIN32 -# define DLL_EXPORT __declspec(dllexport) -#else -# define DLL_EXPORT -#endif - -#if defined(__FreeBSD__) \ - || defined(__FreeBSD_kernel__) \ - || defined(__DragonFly__) \ - || defined(__OpenBSD__) \ - || defined(__NetBSD__) \ - || defined(__dietlibc__) - -#include -#define INIT_SEM() -#define EXIT_SEM() -#define WAIT_SEM() -#define POST_SEM() -#define TRY_SEM() -#define HAVE_MEMALIGN (0) -#define MALLOC_REDIR (0) -#define HAVE_PTHREAD_CREATE (0) -#define HAVE_CTYPE (0) -#define HAVE_ERRNO (0) -#define HAVE_SIGNAL (0) -#define HAVE_SIGACTION (0) -#define HAVE_FORK (0) -#define HAVE_TLS_FUNC (0) -#define HAVE_TLS_VAR (0) - -#elif defined(_WIN32) - -#include -#include -static CRITICAL_SECTION bounds_sem; -#define INIT_SEM() InitializeCriticalSection(&bounds_sem) -#define EXIT_SEM() DeleteCriticalSection(&bounds_sem) -#define WAIT_SEM() EnterCriticalSection(&bounds_sem) -#define POST_SEM() LeaveCriticalSection(&bounds_sem) -#define TRY_SEM() TryEnterCriticalSection(&bounds_sem) -#define HAVE_MEMALIGN (0) -#define MALLOC_REDIR (0) -#define HAVE_PTHREAD_CREATE (0) -#define HAVE_CTYPE (0) -#define HAVE_ERRNO (0) -#define HAVE_SIGNAL (1) -#define HAVE_SIGACTION (0) -#define HAVE_FORK (0) -#define HAVE_TLS_FUNC (1) -#define HAVE_TLS_VAR (0) - -#else - -#define __USE_GNU /* get RTLD_NEXT */ -#include -#include -#include -#include -#include -#include -#ifdef __APPLE__ -#include -static dispatch_semaphore_t bounds_sem; -#define INIT_SEM() bounds_sem = dispatch_semaphore_create(1) -#define EXIT_SEM() dispatch_release(*(dispatch_object_t*)&bounds_sem) -#define WAIT_SEM() if (use_sem) dispatch_semaphore_wait(bounds_sem, DISPATCH_TIME_FOREVER) -#define POST_SEM() if (use_sem) dispatch_semaphore_signal(bounds_sem) -#define TRY_SEM() if (use_sem) dispatch_semaphore_wait(bounds_sem, DISPATCH_TIME_NOW) -#elif 0 -#include -static sem_t bounds_sem; -#define INIT_SEM() sem_init (&bounds_sem, 0, 1) -#define EXIT_SEM() sem_destroy (&bounds_sem) -#define WAIT_SEM() if (use_sem) while (sem_wait (&bounds_sem) < 0 \ - && errno == EINTR) -#define POST_SEM() if (use_sem) sem_post (&bounds_sem) -#define TRY_SEM() if (use_sem) while (sem_trywait (&bounds_sem) < 0 \ - && errno == EINTR) -#elif 0 -static pthread_mutex_t bounds_mtx; -#define INIT_SEM() pthread_mutex_init (&bounds_mtx, NULL) -#define EXIT_SEM() pthread_mutex_destroy (&bounds_mtx) -#define WAIT_SEM() if (use_sem) pthread_mutex_lock (&bounds_mtx) -#define POST_SEM() if (use_sem) pthread_mutex_unlock (&bounds_mtx) -#define TRY_SEM() if (use_sem) pthread_mutex_trylock (&bounds_mtx) -#else -static pthread_spinlock_t bounds_spin; -/* about 25% faster then semaphore. */ -#define INIT_SEM() pthread_spin_init (&bounds_spin, 0) -#define EXIT_SEM() pthread_spin_destroy (&bounds_spin) -#define WAIT_SEM() if (use_sem) pthread_spin_lock (&bounds_spin) -#define POST_SEM() if (use_sem) pthread_spin_unlock (&bounds_spin) -#define TRY_SEM() if (use_sem) pthread_spin_trylock (&bounds_spin) -#endif -#define HAVE_MEMALIGN (1) -#define MALLOC_REDIR (1) -#define HAVE_PTHREAD_CREATE (1) -#define HAVE_CTYPE (1) -#define HAVE_ERRNO (1) -#define HAVE_SIGNAL (1) -#define HAVE_SIGACTION (1) -#define HAVE_FORK (1) -#if !defined(__APPLE__) && defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) -#define HAVE_TLS_FUNC (0) -#define HAVE_TLS_VAR (1) -#else -#define HAVE_TLS_FUNC (1) -#define HAVE_TLS_VAR (0) -#endif -#ifdef TCC_MUSL -# undef HAVE_CTYPE -#endif -#endif - -#if MALLOC_REDIR -static void *(*malloc_redir) (size_t); -static void *(*calloc_redir) (size_t, size_t); -static void (*free_redir) (void *); -static void *(*realloc_redir) (void *, size_t); -static unsigned int pool_index; -static unsigned char __attribute__((aligned(16))) initial_pool[256]; -#endif -#if HAVE_MEMALIGN -static void *(*memalign_redir) (size_t, size_t); -#endif -#if HAVE_PTHREAD_CREATE -static int (*pthread_create_redir) (pthread_t *thread, - const pthread_attr_t *attr, - void *(*start_routine)(void *), void *arg); -#endif -#if HAVE_SIGNAL -typedef void (*bound_sig)(int); -static bound_sig (*signal_redir) (int signum, bound_sig handler); -#endif -#if HAVE_SIGACTION -static int (*sigaction_redir) (int signum, const struct sigaction *act, - struct sigaction *oldact); -#endif -#if HAVE_FORK -static int (*fork_redir) (void); -#endif - -#define TCC_TYPE_NONE (0) -#define TCC_TYPE_MALLOC (1) -#define TCC_TYPE_CALLOC (2) -#define TCC_TYPE_REALLOC (3) -#define TCC_TYPE_MEMALIGN (4) -#define TCC_TYPE_STRDUP (5) - -/* this pointer is generated when bound check is incorrect */ -#define INVALID_POINTER ((void *)(-2)) - -typedef struct tree_node Tree; -struct tree_node { - Tree * left, * right; - size_t start; - size_t size; - unsigned char type; - unsigned char is_invalid; /* true if pointers outside region are invalid */ -}; - -typedef struct alloca_list_struct { - size_t fp; - void *p; - size_t size; - struct alloca_list_struct *next; -} alloca_list_type; - -#if defined(_WIN32) -#define BOUND_TID_TYPE DWORD -#define BOUND_GET_TID(id) id = GetCurrentThreadId() -#elif defined(__OpenBSD__) -#define BOUND_TID_TYPE pid_t -#define BOUND_GET_TID(id) id = syscall (SYS_getthrid) -#elif defined(__FreeBSD__) -#define BOUND_TID_TYPE pid_t -#define BOUND_GET_TID(id) syscall (SYS_thr_self, &id) -#elif defined(__NetBSD__) -#define BOUND_TID_TYPE pid_t -#define BOUND_GET_TID(id) id = syscall (SYS__lwp_self) -#elif defined(__linux__) -#define BOUND_TID_TYPE pid_t -#define BOUND_GET_TID(id) id = syscall (SYS_gettid) -#else -#define BOUND_TID_TYPE int -#define BOUND_GET_TID(id) id = 0 -#endif - -typedef struct jmp_list_struct { - void *penv; - size_t fp; - size_t end_fp; - BOUND_TID_TYPE tid; - struct jmp_list_struct *next; -} jmp_list_type; - -#define BOUND_STATISTIC_SPLAY (0) -static Tree * splay (size_t addr, Tree *t); -static Tree * splay_end (size_t addr, Tree *t); -static Tree * splay_insert(size_t addr, size_t size, Tree * t); -static Tree * splay_delete(size_t addr, Tree *t); -void splay_printtree(Tree * t, int d); - -/* external interface */ -void __bounds_checking (int no_check); -void __bound_checking_lock (void); -void __bound_checking_unlock (void); -void __bound_never_fatal (int no_check); -DLL_EXPORT void * __bound_ptr_add(void *p, size_t offset); -DLL_EXPORT void * __bound_ptr_indir1(void *p, size_t offset); -DLL_EXPORT void * __bound_ptr_indir2(void *p, size_t offset); -DLL_EXPORT void * __bound_ptr_indir4(void *p, size_t offset); -DLL_EXPORT void * __bound_ptr_indir8(void *p, size_t offset); -DLL_EXPORT void * __bound_ptr_indir12(void *p, size_t offset); -DLL_EXPORT void * __bound_ptr_indir16(void *p, size_t offset); -DLL_EXPORT void FASTCALL __bound_local_new(void *p1); -DLL_EXPORT void FASTCALL __bound_local_delete(void *p1); -void __bound_init(size_t *, int); -void __bound_main_arg(int argc, char **argv, char **envp); -void __bound_exit(void); -void __bound_exit_dll(size_t *); -#if !defined(_WIN32) -void *__bound_mmap (void *start, size_t size, int prot, int flags, int fd, - off_t offset); -int __bound_munmap (void *start, size_t size); -DLL_EXPORT void __bound_siglongjmp(jmp_buf env, int val); -#endif -DLL_EXPORT void __bound_new_region(void *p, size_t size); -DLL_EXPORT void __bound_setjmp(jmp_buf env); -DLL_EXPORT void __bound_longjmp(jmp_buf env, int val); -DLL_EXPORT void *__bound_memcpy(void *dst, const void *src, size_t size); -DLL_EXPORT int __bound_memcmp(const void *s1, const void *s2, size_t size); -DLL_EXPORT void *__bound_memmove(void *dst, const void *src, size_t size); -DLL_EXPORT void *__bound_memset(void *dst, int c, size_t size); -DLL_EXPORT int __bound_strlen(const char *s); -DLL_EXPORT char *__bound_strcpy(char *dst, const char *src); -DLL_EXPORT char *__bound_strncpy(char *dst, const char *src, size_t n); -DLL_EXPORT int __bound_strcmp(const char *s1, const char *s2); -DLL_EXPORT int __bound_strncmp(const char *s1, const char *s2, size_t n); -DLL_EXPORT char *__bound_strcat(char *dest, const char *src); -DLL_EXPORT char *__bound_strchr(const char *string, int ch); -DLL_EXPORT char *__bound_strdup(const char *s); - -#if defined(__arm__) && defined(__ARM_EABI__) -DLL_EXPORT void *__bound___aeabi_memcpy(void *dst, const void *src, size_t size); -DLL_EXPORT void *__bound___aeabi_memmove(void *dst, const void *src, size_t size); -DLL_EXPORT void *__bound___aeabi_memmove4(void *dst, const void *src, size_t size); -DLL_EXPORT void *__bound___aeabi_memmove8(void *dst, const void *src, size_t size); -DLL_EXPORT void *__bound___aeabi_memset(void *dst, int c, size_t size); -DLL_EXPORT void *__aeabi_memcpy(void *dst, const void *src, size_t size); -DLL_EXPORT void *__aeabi_memmove(void *dst, const void *src, size_t size); -DLL_EXPORT void *__aeabi_memmove4(void *dst, const void *src, size_t size); -DLL_EXPORT void *__aeabi_memmove8(void *dst, const void *src, size_t size); -DLL_EXPORT void *__aeabi_memset(void *dst, int c, size_t size); -#endif - -#if MALLOC_REDIR -#define BOUND_MALLOC(a) malloc_redir(a) -#define BOUND_MEMALIGN(a,b) memalign_redir(a,b) -#define BOUND_FREE(a) free_redir(a) -#define BOUND_REALLOC(a,b) realloc_redir(a,b) -#define BOUND_CALLOC(a,b) calloc_redir(a,b) -#else -#define BOUND_MALLOC(a) malloc(a) -#define BOUND_MEMALIGN(a,b) memalign(a,b) -#define BOUND_FREE(a) free(a) -#define BOUND_REALLOC(a,b) realloc(a,b) -#define BOUND_CALLOC(a,b) calloc(a,b) -DLL_EXPORT void *__bound_malloc(size_t size, const void *caller); -DLL_EXPORT void *__bound_memalign(size_t size, size_t align, const void *caller); -DLL_EXPORT void __bound_free(void *ptr, const void *caller); -DLL_EXPORT void *__bound_realloc(void *ptr, size_t size, const void *caller); -DLL_EXPORT void *__bound_calloc(size_t nmemb, size_t size); -#endif - -#define FREE_REUSE_SIZE (100) -static unsigned int free_reuse_index; -static void *free_reuse_list[FREE_REUSE_SIZE]; - -static Tree *tree = NULL; -#define TREE_REUSE (1) -#if TREE_REUSE -static Tree *tree_free_list; -#endif -static alloca_list_type *alloca_list; -static jmp_list_type *jmp_list; - -static unsigned char inited; -static unsigned char print_warn_ptr_add; -static unsigned char print_calls; -static unsigned char print_heap; -static unsigned char print_statistic; -static unsigned char no_strdup; -static unsigned char use_sem; -static int never_fatal; -#if HAVE_TLS_FUNC -#if defined(_WIN32) -static int no_checking = 0; -static DWORD no_checking_key; -#define NO_CHECKING_CHECK() if (!p) { \ - p = (int *) LocalAlloc(LPTR, sizeof(int)); \ - if (!p) bound_alloc_error("tls malloc"); \ - *p = 0; \ - TlsSetValue(no_checking_key, p); \ - } -#define NO_CHECKING_GET() ({ int *p = TlsGetValue(no_checking_key); \ - NO_CHECKING_CHECK(); \ - *p; \ - }) -#define NO_CHECKING_SET(v) { int *p = TlsGetValue(no_checking_key); \ - NO_CHECKING_CHECK(); \ - *p = v; \ - } -#else -static int no_checking = 0; -static pthread_key_t no_checking_key; -#define NO_CHECKING_CHECK() if (!p) { \ - p = (int *) BOUND_MALLOC(sizeof(int)); \ - if (!p) bound_alloc_error("tls malloc"); \ - *p = 0; \ - pthread_setspecific(no_checking_key, p); \ - } -#define NO_CHECKING_GET() ({ int *p = pthread_getspecific(no_checking_key); \ - NO_CHECKING_CHECK(); \ - *p; \ - }) -#define NO_CHECKING_SET(v) { int *p = pthread_getspecific(no_checking_key); \ - NO_CHECKING_CHECK(); \ - *p = v; \ - } -#endif -#elif HAVE_TLS_VAR -static __thread int no_checking = 0; -#define NO_CHECKING_GET() no_checking -#define NO_CHECKING_SET(v) no_checking = v -#else -static int no_checking = 0; -#define NO_CHECKING_GET() no_checking -#define NO_CHECKING_SET(v) no_checking = v -#endif -static char exec[100]; - -#if BOUND_STATISTIC -static unsigned long long bound_ptr_add_count; -static unsigned long long bound_ptr_indir1_count; -static unsigned long long bound_ptr_indir2_count; -static unsigned long long bound_ptr_indir4_count; -static unsigned long long bound_ptr_indir8_count; -static unsigned long long bound_ptr_indir12_count; -static unsigned long long bound_ptr_indir16_count; -static unsigned long long bound_local_new_count; -static unsigned long long bound_local_delete_count; -static unsigned long long bound_malloc_count; -static unsigned long long bound_calloc_count; -static unsigned long long bound_realloc_count; -static unsigned long long bound_free_count; -static unsigned long long bound_memalign_count; -static unsigned long long bound_mmap_count; -static unsigned long long bound_munmap_count; -static unsigned long long bound_alloca_count; -static unsigned long long bound_setjmp_count; -static unsigned long long bound_longjmp_count; -static unsigned long long bound_mempcy_count; -static unsigned long long bound_memcmp_count; -static unsigned long long bound_memmove_count; -static unsigned long long bound_memset_count; -static unsigned long long bound_strlen_count; -static unsigned long long bound_strcpy_count; -static unsigned long long bound_strncpy_count; -static unsigned long long bound_strcmp_count; -static unsigned long long bound_strncmp_count; -static unsigned long long bound_strcat_count; -static unsigned long long bound_strchr_count; -static unsigned long long bound_strdup_count; -static unsigned long long bound_not_found; -#define INCR_COUNT(x) ++x -#else -#define INCR_COUNT(x) -#endif -#if BOUND_STATISTIC_SPLAY -static unsigned long long bound_splay; -static unsigned long long bound_splay_end; -static unsigned long long bound_splay_insert; -static unsigned long long bound_splay_delete; -#define INCR_COUNT_SPLAY(x) ++x -#else -#define INCR_COUNT_SPLAY(x) -#endif - -int tcc_backtrace(const char *fmt, ...); - -/* print a bound error message */ -#define bound_warning(...) \ - do { \ - WAIT_SEM (); \ - tcc_backtrace("^bcheck.c^BCHECK: " __VA_ARGS__); \ - POST_SEM (); \ - } while (0) - -#define bound_error(...) \ - do { \ - bound_warning(__VA_ARGS__); \ - if (never_fatal == 0) \ - exit(255); \ - } while (0) - -static void bound_alloc_error(const char *s) -{ - fprintf(stderr,"FATAL: %s\n",s); - exit (1); -} - -static void bound_not_found_warning(const char *file, const char *function, - void *ptr) -{ - dprintf(stderr, "%s%s, %s(): Not found %p\n", exec, file, function, ptr); -} - -static void fetch_and_add(int* variable, int value) -{ -#if defined __i386__ || defined __x86_64__ - __asm__ volatile("lock; addl %0, %1" - : "+r" (value), "+m" (*variable) // input+output - : // No input-only - : "memory" - ); -#elif defined __arm__ - extern void fetch_and_add_arm(int* variable, int value); - fetch_and_add_arm(variable, value); -#elif defined __aarch64__ - extern void fetch_and_add_arm64(int* variable, int value); - fetch_and_add_arm64(variable, value); -#elif defined __riscv - extern void fetch_and_add_riscv64(int* variable, int value); - fetch_and_add_riscv64(variable, value); -#else - *variable += value; -#endif -} - -/* enable/disable checking. This can be used in signal handlers. */ -void __bounds_checking (int no_check) -{ -#if HAVE_TLS_FUNC || HAVE_TLS_VAR - NO_CHECKING_SET(NO_CHECKING_GET() + no_check); -#else - fetch_and_add (&no_checking, no_check); -#endif -} - -void __bound_checking_lock(void) -{ - WAIT_SEM (); -} - -void __bound_checking_unlock(void) -{ - POST_SEM (); -} - -/* enable/disable checking. This can be used in signal handlers. */ -void __bound_never_fatal (int neverfatal) -{ - fetch_and_add (&never_fatal, neverfatal); -} - -/* return '(p + offset)' for pointer arithmetic (a pointer can reach - the end of a region in this case */ -void * __bound_ptr_add(void *p, size_t offset) -{ - size_t addr = (size_t)p; - - if (NO_CHECKING_GET()) - return p + offset; - - dprintf(stderr, "%s, %s(): %p 0x%lx\n", - __FILE__, __FUNCTION__, p, (unsigned long)offset); - - WAIT_SEM (); - INCR_COUNT(bound_ptr_add_count); - if (tree) { - addr -= tree->start; - if (addr >= tree->size) { - addr = (size_t)p; - tree = splay (addr, tree); - addr -= tree->start; - } - if (addr >= tree->size) { - addr = (size_t)p; - tree = splay_end (addr, tree); - addr -= tree->start; - } - if (addr <= tree->size) { - if (tree->is_invalid || addr + offset > tree->size) { - POST_SEM (); - if (print_warn_ptr_add) - bound_warning("%p is outside of the region", p + offset); - if (never_fatal <= 0) - return INVALID_POINTER; /* return an invalid pointer */ - return p + offset; - } - } - else if (p) { /* Allow NULL + offset. offsetoff is using it. */ - INCR_COUNT(bound_not_found); - POST_SEM (); - bound_not_found_warning (__FILE__, __FUNCTION__, p); - return p + offset; - } - } - POST_SEM (); - return p + offset; -} - -/* return '(p + offset)' for pointer indirection (the resulting must - be strictly inside the region */ -#define BOUND_PTR_INDIR(dsize) \ -void * __bound_ptr_indir ## dsize (void *p, size_t offset) \ -{ \ - size_t addr = (size_t)p; \ - \ - if (NO_CHECKING_GET()) \ - return p + offset; \ - \ - dprintf(stderr, "%s, %s(): %p 0x%lx\n", \ - __FILE__, __FUNCTION__, p, (unsigned long)offset); \ - WAIT_SEM (); \ - INCR_COUNT(bound_ptr_indir ## dsize ## _count); \ - if (tree) { \ - addr -= tree->start; \ - if (addr >= tree->size) { \ - addr = (size_t)p; \ - tree = splay (addr, tree); \ - addr -= tree->start; \ - } \ - if (addr >= tree->size) { \ - addr = (size_t)p; \ - tree = splay_end (addr, tree); \ - addr -= tree->start; \ - } \ - if (addr <= tree->size) { \ - if (tree->is_invalid || addr + offset + dsize > tree->size) { \ - POST_SEM (); \ - bound_warning("%p is outside of the region", p + offset); \ - if (never_fatal <= 0) \ - return INVALID_POINTER; /* return an invalid pointer */ \ - return p + offset; \ - } \ - } \ - else { \ - INCR_COUNT(bound_not_found); \ - POST_SEM (); \ - bound_not_found_warning (__FILE__, __FUNCTION__, p); \ - return p + offset; \ - } \ - } \ - POST_SEM (); \ - return p + offset; \ -} - -BOUND_PTR_INDIR(1) -BOUND_PTR_INDIR(2) -BOUND_PTR_INDIR(4) -BOUND_PTR_INDIR(8) -BOUND_PTR_INDIR(12) -BOUND_PTR_INDIR(16) - -#if defined(__GNUC__) && (__GNUC__ >= 6) -/* - * At least gcc 6.2 complains when __builtin_frame_address is used with - * nonzero argument. - */ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wframe-address" -#endif - -/* return the frame pointer of the caller */ -#define GET_CALLER_FP(fp)\ -{\ - fp = (size_t)__builtin_frame_address(1);\ -} - -/* called when entering a function to add all the local regions */ -void FASTCALL __bound_local_new(void *p1) -{ - size_t addr, fp, *p = p1; - - if (NO_CHECKING_GET()) - return; - GET_CALLER_FP(fp); - dprintf(stderr, "%s, %s(): p1=%p fp=%p\n", - __FILE__, __FUNCTION__, p, (void *)fp); - WAIT_SEM (); - while ((addr = p[0])) { - INCR_COUNT(bound_local_new_count); - tree = splay_insert(addr + fp, p[1], tree); - p += 2; - } - POST_SEM (); -#if BOUND_DEBUG - if (print_calls) { - p = p1; - while ((addr = p[0])) { - dprintf(stderr, "%s, %s(): %p 0x%lx\n", - __FILE__, __FUNCTION__, - (void *) (addr + fp), (unsigned long) p[1]); - p += 2; - } - } -#endif -} - -/* called when leaving a function to delete all the local regions */ -void FASTCALL __bound_local_delete(void *p1) -{ - size_t addr, fp, *p = p1; - - if (NO_CHECKING_GET()) - return; - GET_CALLER_FP(fp); - dprintf(stderr, "%s, %s(): p1=%p fp=%p\n", - __FILE__, __FUNCTION__, p, (void *)fp); - WAIT_SEM (); - while ((addr = p[0])) { - INCR_COUNT(bound_local_delete_count); - tree = splay_delete(addr + fp, tree); - p += 2; - } - if (alloca_list) { - alloca_list_type *last = NULL; - alloca_list_type *cur = alloca_list; - - do { - if (cur->fp == fp) { - if (last) - last->next = cur->next; - else - alloca_list = cur->next; - tree = splay_delete ((size_t) cur->p, tree); - dprintf(stderr, "%s, %s(): remove alloca/vla %p\n", - __FILE__, __FUNCTION__, cur->p); - BOUND_FREE (cur); - cur = last ? last->next : alloca_list; - } - else { - last = cur; - cur = cur->next; - } - } while (cur); - } - if (jmp_list) { - jmp_list_type *last = NULL; - jmp_list_type *cur = jmp_list; - - do { - if (cur->fp == fp) { - if (last) - last->next = cur->next; - else - jmp_list = cur->next; - dprintf(stderr, "%s, %s(): remove setjmp %p\n", - __FILE__, __FUNCTION__, cur->penv); - BOUND_FREE (cur); - cur = last ? last->next : jmp_list; - } - else { - last = cur; - cur = cur->next; - } - } while (cur); - } - - POST_SEM (); -#if BOUND_DEBUG - if (print_calls) { - p = p1; - while ((addr = p[0])) { - if (addr != 1) { - dprintf(stderr, "%s, %s(): %p 0x%lx\n", - __FILE__, __FUNCTION__, - (void *) (addr + fp), (unsigned long) p[1]); - } - p+= 2; - } - } -#endif -} - -/* used by alloca */ -void __bound_new_region(void *p, size_t size) -{ - size_t fp; - alloca_list_type *last; - alloca_list_type *cur; - alloca_list_type *new; - - if (NO_CHECKING_GET()) - return; - - dprintf(stderr, "%s, %s(): %p, 0x%lx\n", - __FILE__, __FUNCTION__, p, (unsigned long)size); - GET_CALLER_FP (fp); - new = BOUND_MALLOC (sizeof (alloca_list_type)); - WAIT_SEM (); - INCR_COUNT(bound_alloca_count); - last = NULL; - cur = alloca_list; - while (cur) { -#if defined(__i386__) || (defined(__arm__) && !defined(__ARM_EABI__)) - int align = 4; -#elif defined(__arm__) - int align = 8; -#else - int align = 16; -#endif - void *cure = (void *)((char *)cur->p + ((cur->size + align) & -align)); - void *pe = (void *)((char *)p + ((size + align) & -align)); - if (cur->fp == fp && ((cur->p <= p && cure > p) || - (p <= cur->p && pe > cur->p))) { - if (last) - last->next = cur->next; - else - alloca_list = cur->next; - tree = splay_delete((size_t)cur->p, tree); - break; - } - last = cur; - cur = cur->next; - } - tree = splay_insert((size_t)p, size, tree); - if (new) { - new->fp = fp; - new->p = p; - new->size = size; - new->next = alloca_list; - alloca_list = new; - } - POST_SEM (); - if (cur) { - dprintf(stderr, "%s, %s(): remove alloca/vla %p\n", - __FILE__, __FUNCTION__, cur->p); - BOUND_FREE (cur); - } -} - -void __bound_setjmp(jmp_buf env) -{ - jmp_list_type *jl; - void *e = (void *) env; - - if (NO_CHECKING_GET() == 0) { - dprintf(stderr, "%s, %s(): %p\n", __FILE__, __FUNCTION__, e); - WAIT_SEM (); - INCR_COUNT(bound_setjmp_count); - jl = jmp_list; - while (jl) { - if (jl->penv == e) - break; - jl = jl->next; - } - if (jl == NULL) { - jl = BOUND_MALLOC (sizeof (jmp_list_type)); - if (jl) { - jl->penv = e; - jl->next = jmp_list; - jmp_list = jl; - } - } - if (jl) { - size_t fp; - - GET_CALLER_FP (fp); - jl->fp = fp; - jl->end_fp = (size_t)__builtin_frame_address(0); - BOUND_GET_TID(jl->tid); - } - POST_SEM (); - } -} - -static void __bound_long_jump(jmp_buf env, int val, int sig, const char *func) -{ - jmp_list_type *jl; - void *e; - BOUND_TID_TYPE tid; - - if (NO_CHECKING_GET() == 0) { - e = (void *)env; - BOUND_GET_TID(tid); - dprintf(stderr, "%s, %s(): %p\n", __FILE__, func, e); - WAIT_SEM(); - INCR_COUNT(bound_longjmp_count); - jl = jmp_list; - while (jl) { - if (jl->penv == e && jl->tid == tid) { - size_t start_fp = (size_t)__builtin_frame_address(0); - size_t end_fp = jl->end_fp; - jmp_list_type *cur = jmp_list; - jmp_list_type *last = NULL; - - while (cur->penv != e || cur->tid != tid) { - if (cur->tid == tid) { - dprintf(stderr, "%s, %s(): remove setjmp %p\n", - __FILE__, func, cur->penv); - if (last) - last->next = cur->next; - else - jmp_list = cur->next; - BOUND_FREE (cur); - cur = last ? last->next : jmp_list; - } - else { - last = cur; - cur = cur->next; - } - } - for (;;) { - Tree *t = tree; - alloca_list_type *last; - alloca_list_type *cur; - - while (t && (t->start < start_fp || t->start > end_fp)) - if (t->start < start_fp) - t = t->right; - else - t = t->left; - if (t == NULL) - break; - last = NULL; - cur = alloca_list; - while (cur) { - if ((size_t) cur->p == t->start) { - dprintf(stderr, "%s, %s(): remove alloca/vla %p\n", - __FILE__, func, cur->p); - if (last) - last->next = cur->next; - else - alloca_list = cur->next; - BOUND_FREE (cur); - break; - } - last = cur; - cur = cur->next; - } - dprintf(stderr, "%s, %s(): delete %p\n", - __FILE__, func, (void *) t->start); - tree = splay_delete(t->start, tree); - } - break; - } - jl = jl->next; - } - POST_SEM(); - } -#if !defined(_WIN32) - sig ? siglongjmp(env, val) : -#endif - longjmp (env, val); -} - -void __bound_longjmp(jmp_buf env, int val) -{ - __bound_long_jump(env,val, 0, __FUNCTION__); -} - -#if !defined(_WIN32) -void __bound_siglongjmp(jmp_buf env, int val) -{ - __bound_long_jump(env,val, 1, __FUNCTION__); -} -#endif - -#if defined(__GNUC__) && (__GNUC__ >= 6) -#pragma GCC diagnostic pop -#endif - -void __bound_init(size_t *p, int mode) -{ - dprintf(stderr, "%s, %s(): start %s\n", __FILE__, __FUNCTION__, - mode < 0 ? "lazy" : mode == 0 ? "normal use" : "for -run"); - - if (inited) { - WAIT_SEM(); - goto add_bounds; - } - inited = 1; - -#if HAVE_TLS_FUNC -#if defined(_WIN32) - no_checking_key = TlsAlloc(); - TlsSetValue(no_checking_key, &no_checking); -#else - pthread_key_create(&no_checking_key, NULL); - pthread_setspecific(no_checking_key, &no_checking); -#endif -#endif - NO_CHECKING_SET(1); - - print_warn_ptr_add = getenv ("TCC_BOUNDS_WARN_POINTER_ADD") != NULL; - print_calls = getenv ("TCC_BOUNDS_PRINT_CALLS") != NULL; - print_heap = getenv ("TCC_BOUNDS_PRINT_HEAP") != NULL; - print_statistic = getenv ("TCC_BOUNDS_PRINT_STATISTIC") != NULL; - never_fatal = getenv ("TCC_BOUNDS_NEVER_FATAL") != NULL; - - INIT_SEM (); - -#if MALLOC_REDIR - { - void *addr = mode > 0 ? RTLD_DEFAULT : RTLD_NEXT; - - /* tcc -run required RTLD_DEFAULT. Normal usage requires RTLD_NEXT, - but using RTLD_NEXT with -run segfaults on MacOS in dyld as the - generated code segment isn't registered with dyld and hence the - caller image of dlsym isn't known to it */ - *(void **) (&malloc_redir) = dlsym (addr, "malloc"); - if (malloc_redir == NULL) { - dprintf(stderr, "%s, %s(): use RTLD_DEFAULT\n", - __FILE__, __FUNCTION__); - addr = RTLD_DEFAULT; - *(void **) (&malloc_redir) = dlsym (addr, "malloc"); - } - *(void **) (&calloc_redir) = dlsym (addr, "calloc"); - *(void **) (&free_redir) = dlsym (addr, "free"); - *(void **) (&realloc_redir) = dlsym (addr, "realloc"); - *(void **) (&memalign_redir) = dlsym (addr, "memalign"); - dprintf(stderr, "%s, %s(): malloc_redir %p\n", - __FILE__, __FUNCTION__, malloc_redir); - dprintf(stderr, "%s, %s(): free_redir %p\n", - __FILE__, __FUNCTION__, free_redir); - dprintf(stderr, "%s, %s(): realloc_redir %p\n", - __FILE__, __FUNCTION__, realloc_redir); - dprintf(stderr, "%s, %s(): memalign_redir %p\n", - __FILE__, __FUNCTION__, memalign_redir); - if (malloc_redir == NULL || free_redir == NULL) - bound_alloc_error ("Cannot redirect malloc/free"); -#if HAVE_PTHREAD_CREATE - *(void **) (&pthread_create_redir) = dlsym (addr, "pthread_create"); - dprintf(stderr, "%s, %s(): pthread_create_redir %p\n", - __FILE__, __FUNCTION__, pthread_create_redir); - if (pthread_create_redir == NULL) - bound_alloc_error ("Cannot redirect pthread_create"); -#endif -#if HAVE_SIGNAL - *(void **) (&signal_redir) = dlsym (addr, "signal"); - dprintf(stderr, "%s, %s(): signal_redir %p\n", - __FILE__, __FUNCTION__, signal_redir); - if (signal_redir == NULL) - bound_alloc_error ("Cannot redirect signal"); -#endif -#if HAVE_SIGACTION - *(void **) (&sigaction_redir) = dlsym (addr, "sigaction"); - dprintf(stderr, "%s, %s(): sigaction_redir %p\n", - __FILE__, __FUNCTION__, sigaction_redir); - if (sigaction_redir == NULL) - bound_alloc_error ("Cannot redirect sigaction"); -#endif -#if HAVE_FORK - *(void **) (&fork_redir) = dlsym (addr, "fork"); - dprintf(stderr, "%s, %s(): fork_redir %p\n", - __FILE__, __FUNCTION__, fork_redir); - if (fork_redir == NULL) - bound_alloc_error ("Cannot redirect fork"); -#endif - } -#endif - -#ifdef __linux__ - { - FILE *fp; - unsigned char found; - unsigned long start; - unsigned long end; - unsigned long ad = - (unsigned long) __builtin_return_address(0); - char line[1000]; - - /* Display exec name. Usefull when a lot of code is compiled with tcc */ - fp = fopen ("/proc/self/comm", "r"); - if (fp) { - memset (exec, 0, sizeof(exec)); - fread (exec, 1, sizeof(exec) - 2, fp); - if (strchr(exec,'\n')) - *strchr(exec,'\n') = '\0'; - strcat (exec, ":"); - fclose (fp); - } - /* check if dlopen is used (is threre a better way?) */ - found = 0; - fp = fopen ("/proc/self/maps", "r"); - if (fp) { - while (fgets (line, sizeof(line), fp)) { - if (sscanf (line, "%lx-%lx", &start, &end) == 2 && - ad >= start && ad < end) { - found = 1; - break; - } - if (strstr (line,"[heap]")) - break; - } - fclose (fp); - } - if (found == 0) { - use_sem = 1; - no_strdup = 1; - } - } -#endif - - WAIT_SEM (); - -#if HAVE_CTYPE -#ifdef __APPLE__ - tree = splay_insert((size_t) &_DefaultRuneLocale, - sizeof (_DefaultRuneLocale), tree); -#else - /* XXX: Does not work if locale is changed */ - tree = splay_insert((size_t) __ctype_b_loc(), - sizeof (unsigned short *), tree); - tree = splay_insert((size_t) (*__ctype_b_loc() - 128), - 384 * sizeof (unsigned short), tree); - tree = splay_insert((size_t) __ctype_tolower_loc(), - sizeof (__int32_t *), tree); - tree = splay_insert((size_t) (*__ctype_tolower_loc() - 128), - 384 * sizeof (__int32_t), tree); - tree = splay_insert((size_t) __ctype_toupper_loc(), - sizeof (__int32_t *), tree); - tree = splay_insert((size_t) (*__ctype_toupper_loc() - 128), - 384 * sizeof (__int32_t), tree); -#endif -#endif -#if HAVE_ERRNO - tree = splay_insert((size_t) (&errno), sizeof (int), tree); -#endif - -add_bounds: - if (!p) - goto no_bounds; - - /* add all static bound check values */ - while (p[0] != 0) { - tree = splay_insert(p[0], p[1], tree); -#if BOUND_DEBUG - if (print_calls) { - dprintf(stderr, "%s, %s(): static var %p 0x%lx\n", - __FILE__, __FUNCTION__, - (void *) p[0], (unsigned long) p[1]); - } -#endif - p += 2; - } -no_bounds: - - POST_SEM (); - NO_CHECKING_SET(0); - dprintf(stderr, "%s, %s(): end\n\n", __FILE__, __FUNCTION__); -} - -void -#if (defined(__GLIBC__) && (__GLIBC_MINOR__ >= 4)) || defined(_WIN32) -__attribute__((constructor)) -#endif -__bound_main_arg(int argc, char **argv, char **envp) -{ - __bound_init (0, -1); - if (argc && argv) { - int i; - - WAIT_SEM (); - for (i = 0; i < argc; i++) - tree = splay_insert((size_t) argv[i], strlen (argv[i]) + 1, tree); - tree = splay_insert((size_t) argv, (argc + 1) * sizeof(char *), tree); - POST_SEM (); -#if BOUND_DEBUG - if (print_calls) { - for (i = 0; i < argc; i++) - dprintf(stderr, "%s, %s(): arg %p 0x%lx\n", - __FILE__, __FUNCTION__, - argv[i], (unsigned long)(strlen (argv[i]) + 1)); - dprintf(stderr, "%s, %s(): argv %p %d\n", - __FILE__, __FUNCTION__, argv, - (int)((argc + 1) * sizeof(char *))); - } -#endif - } - - if (envp && *envp) { - char **p = envp; - - WAIT_SEM (); - while (*p) { - tree = splay_insert((size_t) *p, strlen (*p) + 1, tree); - ++p; - } - tree = splay_insert((size_t) envp, (++p - envp) * sizeof(char *), tree); - POST_SEM (); -#if BOUND_DEBUG - if (print_calls) { - p = envp; - while (*p) { - dprintf(stderr, "%s, %s(): env %p 0x%lx\n", - __FILE__, __FUNCTION__, - *p, (unsigned long)(strlen (*p) + 1)); - ++p; - } - dprintf(stderr, "%s, %s(): environ %p %d\n", - __FILE__, __FUNCTION__, envp, - (int)((++p - envp) * sizeof(char *))); - } -#endif - } -} - -void __attribute__((destructor)) __bound_exit(void) -{ - int i; - static const char * const alloc_type[] = { - "", "malloc", "calloc", "realloc", "memalign", "strdup" - }; - - dprintf(stderr, "%s, %s():\n", __FILE__, __FUNCTION__); - - if (inited) { -#if !defined(_WIN32) && !defined(__APPLE__) && !defined TCC_MUSL && \ - !defined(__OpenBSD__) && !defined(__FreeBSD__) && !defined(__NetBSD__) - if (print_heap) { - extern void __libc_freeres (void); - __libc_freeres (); - } -#endif - - NO_CHECKING_SET(1); - - TRY_SEM (); - while (alloca_list) { - alloca_list_type *next = alloca_list->next; - - tree = splay_delete ((size_t) alloca_list->p, tree); - BOUND_FREE (alloca_list); - alloca_list = next; - } - while (jmp_list) { - jmp_list_type *next = jmp_list->next; - - BOUND_FREE (jmp_list); - jmp_list = next; - } - for (i = 0; i < FREE_REUSE_SIZE; i++) { - if (free_reuse_list[i]) { - tree = splay_delete ((size_t) free_reuse_list[i], tree); - BOUND_FREE (free_reuse_list[i]); - } - } - while (tree) { - if (print_heap && tree->type != 0) - fprintf (stderr, "%s, %s(): %s found size %lu\n", - __FILE__, __FUNCTION__, alloc_type[tree->type], - (unsigned long) tree->size); - tree = splay_delete (tree->start, tree); - } -#if TREE_REUSE - while (tree_free_list) { - Tree *next = tree_free_list->left; - BOUND_FREE (tree_free_list); - tree_free_list = next; - } -#endif - POST_SEM (); - EXIT_SEM (); -#if HAVE_TLS_FUNC -#if defined(_WIN32) - TlsFree(no_checking_key); -#else - pthread_key_delete(no_checking_key); -#endif -#endif - inited = 0; - if (print_statistic) { -#if BOUND_STATISTIC - fprintf (stderr, "bound_ptr_add_count %llu\n", bound_ptr_add_count); - fprintf (stderr, "bound_ptr_indir1_count %llu\n", bound_ptr_indir1_count); - fprintf (stderr, "bound_ptr_indir2_count %llu\n", bound_ptr_indir2_count); - fprintf (stderr, "bound_ptr_indir4_count %llu\n", bound_ptr_indir4_count); - fprintf (stderr, "bound_ptr_indir8_count %llu\n", bound_ptr_indir8_count); - fprintf (stderr, "bound_ptr_indir12_count %llu\n", bound_ptr_indir12_count); - fprintf (stderr, "bound_ptr_indir16_count %llu\n", bound_ptr_indir16_count); - fprintf (stderr, "bound_local_new_count %llu\n", bound_local_new_count); - fprintf (stderr, "bound_local_delete_count %llu\n", bound_local_delete_count); - fprintf (stderr, "bound_malloc_count %llu\n", bound_malloc_count); - fprintf (stderr, "bound_calloc_count %llu\n", bound_calloc_count); - fprintf (stderr, "bound_realloc_count %llu\n", bound_realloc_count); - fprintf (stderr, "bound_free_count %llu\n", bound_free_count); - fprintf (stderr, "bound_memalign_count %llu\n", bound_memalign_count); - fprintf (stderr, "bound_mmap_count %llu\n", bound_mmap_count); - fprintf (stderr, "bound_munmap_count %llu\n", bound_munmap_count); - fprintf (stderr, "bound_alloca_count %llu\n", bound_alloca_count); - fprintf (stderr, "bound_setjmp_count %llu\n", bound_setjmp_count); - fprintf (stderr, "bound_longjmp_count %llu\n", bound_longjmp_count); - fprintf (stderr, "bound_mempcy_count %llu\n", bound_mempcy_count); - fprintf (stderr, "bound_memcmp_count %llu\n", bound_memcmp_count); - fprintf (stderr, "bound_memmove_count %llu\n", bound_memmove_count); - fprintf (stderr, "bound_memset_count %llu\n", bound_memset_count); - fprintf (stderr, "bound_strlen_count %llu\n", bound_strlen_count); - fprintf (stderr, "bound_strcpy_count %llu\n", bound_strcpy_count); - fprintf (stderr, "bound_strncpy_count %llu\n", bound_strncpy_count); - fprintf (stderr, "bound_strcmp_count %llu\n", bound_strcmp_count); - fprintf (stderr, "bound_strncmp_count %llu\n", bound_strncmp_count); - fprintf (stderr, "bound_strcat_count %llu\n", bound_strcat_count); - fprintf (stderr, "bound_strchr_count %llu\n", bound_strchr_count); - fprintf (stderr, "bound_strdup_count %llu\n", bound_strdup_count); - fprintf (stderr, "bound_not_found %llu\n", bound_not_found); -#endif -#if BOUND_STATISTIC_SPLAY - fprintf (stderr, "bound_splay %llu\n", bound_splay); - fprintf (stderr, "bound_splay_end %llu\n", bound_splay_end); - fprintf (stderr, "bound_splay_insert %llu\n", bound_splay_insert); - fprintf (stderr, "bound_splay_delete %llu\n", bound_splay_delete); -#endif - } - } -} - -void __bound_exit_dll(size_t *p) -{ - dprintf(stderr, "%s, %s()\n", __FILE__, __FUNCTION__); - - if (p) { - WAIT_SEM (); - while (p[0] != 0) { - tree = splay_delete(p[0], tree); -#if BOUND_DEBUG - if (print_calls) { - dprintf(stderr, "%s, %s(): remove static var %p 0x%lx\n", - __FILE__, __FUNCTION__, - (void *) p[0], (unsigned long) p[1]); - } -#endif - p += 2; - } - POST_SEM (); - } -} - -#if HAVE_PTHREAD_CREATE -typedef struct { - void *(*start_routine) (void *); - void *arg; - sigset_t old_mask; -} bound_thread_create_type; - -static void *bound_thread_create(void *bdata) -{ - bound_thread_create_type *data = (bound_thread_create_type *) bdata; - void *retval; -#if HAVE_TLS_FUNC - int *p = (int *) BOUND_MALLOC(sizeof(int)); - - if (!p) bound_alloc_error("bound_thread_create malloc"); - *p = 0; - pthread_setspecific(no_checking_key, p); -#endif - pthread_sigmask(SIG_SETMASK, &data->old_mask, NULL); - retval = data->start_routine(data->arg); -#if HAVE_TLS_FUNC - pthread_setspecific(no_checking_key, NULL); - BOUND_FREE (p); -#endif - BOUND_FREE (data); - return retval; -} - -int pthread_create(pthread_t *thread, const pthread_attr_t *attr, - void *(*start_routine) (void *), void *arg) -{ - int retval; - bound_thread_create_type *data; - sigset_t mask; - sigset_t old_mask; - - use_sem = 1; - dprintf (stderr, "%s, %s()\n", __FILE__, __FUNCTION__); - sigfillset(&mask); - pthread_sigmask(SIG_SETMASK, &mask, &old_mask); - data = (bound_thread_create_type *) BOUND_MALLOC(sizeof(bound_thread_create_type)); - if (!data) bound_alloc_error("bound_thread_create malloc"); - data->start_routine = start_routine; - data->arg = arg; - data->old_mask = old_mask; - retval = pthread_create_redir(thread, attr, bound_thread_create, data); - pthread_sigmask(SIG_SETMASK, &old_mask, NULL); - return retval; -} -#endif - -#if HAVE_SIGNAL || HAVE_SIGACTION -typedef union { -#if HAVE_SIGNAL - bound_sig signal_handler; -#endif -#if HAVE_SIGACTION - void (*sig_handler)(int); - void (*sig_sigaction)(int, siginfo_t *, void *); -#endif -} bound_sig_type; - -static unsigned char bound_sig_used[NSIG]; -static bound_sig_type bound_sig_data[NSIG]; -#endif - -#if HAVE_SIGNAL -static void signal_handler(int sig) -{ - __bounds_checking(1); - bound_sig_data[sig].signal_handler(sig); - __bounds_checking(-1); -} - -bound_sig signal(int signum, bound_sig handler) -{ - bound_sig retval; - - dprintf (stderr, "%s, %s() %d %p\n", __FILE__, __FUNCTION__, - signum, handler); - retval = signal_redir(signum, handler ? signal_handler : handler); - if (retval != SIG_ERR) { - if (bound_sig_used[signum]) - retval = bound_sig_data[signum].signal_handler; - if (handler) { - bound_sig_used[signum] = 1; - bound_sig_data[signum].signal_handler = handler; - } - } - return retval; -} -#endif - -#if HAVE_SIGACTION -static void sig_handler(int sig) -{ - __bounds_checking(1); - bound_sig_data[sig].sig_handler(sig); - __bounds_checking(-1); -} - -static void sig_sigaction(int sig, siginfo_t *info, void *ucontext) -{ - __bounds_checking(1); - bound_sig_data[sig].sig_sigaction(sig, info, ucontext); - __bounds_checking(-1); -} - -int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact) -{ - int retval; - struct sigaction nact, oact; - - dprintf (stderr, "%s, %s() %d %p %p\n", __FILE__, __FUNCTION__, - signum, act, oldact); - - if (sigaction_redir == NULL) - __bound_init(0,-1); - - if (act) { - nact = *act; - if (nact.sa_flags & SA_SIGINFO) - nact.sa_sigaction = sig_sigaction; - else - nact.sa_handler = sig_handler; - retval = sigaction_redir(signum, &nact, &oact); - } - else - retval = sigaction_redir(signum, act, &oact); - if (retval >= 0) { - if (bound_sig_used[signum]) { - if (oact.sa_flags & SA_SIGINFO) - oact.sa_sigaction = bound_sig_data[signum].sig_sigaction; - else - oact.sa_handler = bound_sig_data[signum].sig_handler; - } - if (oldact) { - *oldact = oact; - } - if (act) { - bound_sig_used[signum] = 1; - if (act->sa_flags & SA_SIGINFO) - bound_sig_data[signum].sig_sigaction = act->sa_sigaction; - else - bound_sig_data[signum].sig_handler = act->sa_handler; - } - } - return retval; -} -#endif - -#if HAVE_FORK -pid_t fork(void) -{ - pid_t retval; - - WAIT_SEM(); - retval = (*fork_redir)(); - if (retval == 0) - INIT_SEM(); - else - POST_SEM(); - return retval; -} -#endif - -#if MALLOC_REDIR -void *malloc(size_t size) -#else -void *__bound_malloc(size_t size, const void *caller) -#endif -{ - void *ptr; - -#if MALLOC_REDIR - /* This will catch the first dlsym call from __bound_init */ - if (malloc_redir == NULL) { - __bound_init (0, -1); - if (malloc_redir == NULL) { - ptr = &initial_pool[pool_index]; - pool_index = (pool_index + size + 15) & ~15; - if (pool_index >= sizeof (initial_pool)) - bound_alloc_error ("initial memory pool too small"); - dprintf (stderr, "%s, %s(): initial %p, 0x%lx\n", - __FILE__, __FUNCTION__, ptr, (unsigned long)size); - return ptr; - } - } -#endif - /* we allocate one more byte to ensure the regions will be - separated by at least one byte. With the glibc malloc, it may - be in fact not necessary */ - ptr = BOUND_MALLOC (size + 1); - dprintf(stderr, "%s, %s(): %p, 0x%lx\n", - __FILE__, __FUNCTION__, ptr, (unsigned long)size); - - if (inited && NO_CHECKING_GET() == 0) { - WAIT_SEM (); - INCR_COUNT(bound_malloc_count); - - if (ptr) { - tree = splay_insert ((size_t) ptr, size ? size : size + 1, tree); - if (tree && tree->start == (size_t) ptr) - tree->type = TCC_TYPE_MALLOC; - } - POST_SEM (); - } - return ptr; -} - -#if MALLOC_REDIR -void *memalign(size_t size, size_t align) -#else -void *__bound_memalign(size_t size, size_t align, const void *caller) -#endif -{ - void *ptr; - -#if HAVE_MEMALIGN - /* we allocate one more byte to ensure the regions will be - separated by at least one byte. With the glibc malloc, it may - be in fact not necessary */ - ptr = BOUND_MEMALIGN(size + 1, align); -#else - if (align > 4) { - /* XXX: handle it ? */ - ptr = NULL; - } else { - /* we suppose that malloc aligns to at least four bytes */ - ptr = BOUND_MALLOC(size + 1); - } -#endif - dprintf(stderr, "%s, %s(): %p, 0x%lx\n", - __FILE__, __FUNCTION__, ptr, (unsigned long)size); - - if (NO_CHECKING_GET() == 0) { - WAIT_SEM (); - INCR_COUNT(bound_memalign_count); - - if (ptr) { - tree = splay_insert((size_t) ptr, size ? size : size + 1, tree); - if (tree && tree->start == (size_t) ptr) - tree->type = TCC_TYPE_MEMALIGN; - } - POST_SEM (); - } - return ptr; -} - -#if MALLOC_REDIR -void free(void *ptr) -#else -void __bound_free(void *ptr, const void *caller) -#endif -{ - size_t addr = (size_t) ptr; - void *p; - - if (ptr == NULL || tree == NULL -#if MALLOC_REDIR - || ((unsigned char *) ptr >= &initial_pool[0] && - (unsigned char *) ptr < &initial_pool[sizeof(initial_pool)]) -#endif - ) - return; - - dprintf(stderr, "%s, %s(): %p\n", __FILE__, __FUNCTION__, ptr); - - if (inited && NO_CHECKING_GET() == 0) { - WAIT_SEM (); - INCR_COUNT(bound_free_count); - tree = splay (addr, tree); - if (tree->start == addr) { - if (tree->is_invalid) { - POST_SEM (); - bound_error("freeing invalid region"); - return; - } - tree->is_invalid = 1; - memset (ptr, 0x5a, tree->size); - p = free_reuse_list[free_reuse_index]; - free_reuse_list[free_reuse_index] = ptr; - free_reuse_index = (free_reuse_index + 1) % FREE_REUSE_SIZE; - if (p) - tree = splay_delete((size_t)p, tree); - ptr = p; - } - POST_SEM (); - } - BOUND_FREE (ptr); -} - -#if MALLOC_REDIR -void *realloc(void *ptr, size_t size) -#else -void *__bound_realloc(void *ptr, size_t size, const void *caller) -#endif -{ - void *new_ptr; - - if (size == 0) { -#if MALLOC_REDIR - free(ptr); -#else - __bound_free(ptr, caller); -#endif - return NULL; - } - - new_ptr = BOUND_REALLOC (ptr, size + 1); - dprintf(stderr, "%s, %s(): %p, 0x%lx\n", - __FILE__, __FUNCTION__, new_ptr, (unsigned long)size); - - if (NO_CHECKING_GET() == 0) { - WAIT_SEM (); - INCR_COUNT(bound_realloc_count); - - if (ptr) - tree = splay_delete ((size_t) ptr, tree); - if (new_ptr) { - tree = splay_insert ((size_t) new_ptr, size ? size : size + 1, tree); - if (tree && tree->start == (size_t) new_ptr) - tree->type = TCC_TYPE_REALLOC; - } - POST_SEM (); - } - return new_ptr; -} - -#if MALLOC_REDIR -void *calloc(size_t nmemb, size_t size) -#else -void *__bound_calloc(size_t nmemb, size_t size) -#endif -{ - void *ptr; - - size *= nmemb; -#if MALLOC_REDIR - /* This will catch the first dlsym call from __bound_init */ - if (malloc_redir == NULL) { - __bound_init (0, -1); - if (malloc_redir == NULL) { - ptr = &initial_pool[pool_index]; - pool_index = (pool_index + size + 15) & ~15; - if (pool_index >= sizeof (initial_pool)) - bound_alloc_error ("initial memory pool too small"); - dprintf (stderr, "%s, %s(): initial %p, 0x%lx\n", - __FILE__, __FUNCTION__, ptr, (unsigned long)size); - memset (ptr, 0, size); - return ptr; - } - } -#endif - ptr = BOUND_MALLOC(size + 1); - dprintf (stderr, "%s, %s(): %p, 0x%lx\n", - __FILE__, __FUNCTION__, ptr, (unsigned long)size); - - if (ptr) { - memset (ptr, 0, size); - if (NO_CHECKING_GET() == 0) { - WAIT_SEM (); - INCR_COUNT(bound_calloc_count); - tree = splay_insert ((size_t) ptr, size ? size : size + 1, tree); - if (tree && tree->start == (size_t) ptr) - tree->type = TCC_TYPE_CALLOC; - POST_SEM (); - } - } - return ptr; -} - -#if !defined(_WIN32) -void *__bound_mmap (void *start, size_t size, int prot, - int flags, int fd, off_t offset) -{ - void *result; - - dprintf(stderr, "%s, %s(): %p, 0x%lx\n", - __FILE__, __FUNCTION__, start, (unsigned long)size); - result = mmap (start, size, prot, flags, fd, offset); - if (result && NO_CHECKING_GET() == 0) { - WAIT_SEM (); - INCR_COUNT(bound_mmap_count); - tree = splay_insert((size_t)result, size, tree); - POST_SEM (); - } - return result; -} - -int __bound_munmap (void *start, size_t size) -{ - int result; - - dprintf(stderr, "%s, %s(): %p, 0x%lx\n", - __FILE__, __FUNCTION__, start, (unsigned long)size); - if (start && NO_CHECKING_GET() == 0) { - WAIT_SEM (); - INCR_COUNT(bound_munmap_count); - tree = splay_delete ((size_t) start, tree); - POST_SEM (); - } - result = munmap (start, size); - return result; -} -#endif - -/* some useful checked functions */ - -/* check that (p ... p + size - 1) lies inside 'p' region, if any */ -static void __bound_check(const void *p, size_t size, const char *function) -{ - if (size != 0 && __bound_ptr_add((void *)p, size) == INVALID_POINTER) { - bound_error("invalid pointer %p, size 0x%lx in %s", - p, (unsigned long)size, function); - } -} - -static int check_overlap (const void *p1, size_t n1, - const void *p2, size_t n2, - const char *function) -{ - const void *p1e = (const void *) ((const char *) p1 + n1); - const void *p2e = (const void *) ((const char *) p2 + n2); - - if (NO_CHECKING_GET() == 0 && n1 != 0 && n2 !=0 && - ((p1 <= p2 && p1e > p2) || /* p1----p2====p1e----p2e */ - (p2 <= p1 && p2e > p1))) { /* p2----p1====p2e----p1e */ - bound_error("overlapping regions %p(0x%lx), %p(0x%lx) in %s", - p1, (unsigned long)n1, p2, (unsigned long)n2, function); - return never_fatal < 0; - } - return 0; -} - -void *__bound_memcpy(void *dest, const void *src, size_t n) -{ - dprintf(stderr, "%s, %s(): %p, %p, 0x%lx\n", - __FILE__, __FUNCTION__, dest, src, (unsigned long)n); - INCR_COUNT(bound_mempcy_count); - __bound_check(dest, n, "memcpy dest"); - __bound_check(src, n, "memcpy src"); - if (check_overlap(dest, n, src, n, "memcpy")) - return dest; - return memcpy(dest, src, n); -} - -int __bound_memcmp(const void *s1, const void *s2, size_t n) -{ - const unsigned char *u1 = (const unsigned char *) s1; - const unsigned char *u2 = (const unsigned char *) s2; - int retval = 0; - - dprintf(stderr, "%s, %s(): %p, %p, 0x%lx\n", - __FILE__, __FUNCTION__, s1, s2, (unsigned long)n); - INCR_COUNT(bound_memcmp_count); - for (;;) { - if ((ssize_t) --n == -1) - break; - else if (*u1 != *u2) { - retval = *u1++ - *u2++; - break; - } - ++u1; - ++u2; - } - __bound_check(s1, (const void *)u1 - s1, "memcmp s1"); - __bound_check(s2, (const void *)u2 - s2, "memcmp s2"); - return retval; -} - -void *__bound_memmove(void *dest, const void *src, size_t n) -{ - dprintf(stderr, "%s, %s(): %p, %p, 0x%lx\n", - __FILE__, __FUNCTION__, dest, src, (unsigned long)n); - INCR_COUNT(bound_memmove_count); - __bound_check(dest, n, "memmove dest"); - __bound_check(src, n, "memmove src"); - return memmove(dest, src, n); -} - -void *__bound_memset(void *s, int c, size_t n) -{ - dprintf(stderr, "%s, %s(): %p, %d, 0x%lx\n", - __FILE__, __FUNCTION__, s, c, (unsigned long)n); - INCR_COUNT(bound_memset_count); - __bound_check(s, n, "memset"); - return memset(s, c, n); -} - -#if defined(__arm__) && defined(__ARM_EABI__) -void *__bound___aeabi_memcpy(void *dest, const void *src, size_t n) -{ - dprintf(stderr, "%s, %s(): %p, %p, 0x%lx\n", - __FILE__, __FUNCTION__, dest, src, (unsigned long)n); - INCR_COUNT(bound_mempcy_count); - __bound_check(dest, n, "memcpy dest"); - __bound_check(src, n, "memcpy src"); - if (check_overlap(dest, n, src, n, "memcpy")) - return dest; - return __aeabi_memcpy(dest, src, n); -} - -void *__bound___aeabi_memmove(void *dest, const void *src, size_t n) -{ - dprintf(stderr, "%s, %s(): %p, %p, 0x%lx\n", - __FILE__, __FUNCTION__, dest, src, (unsigned long)n); - INCR_COUNT(bound_memmove_count); - __bound_check(dest, n, "memmove dest"); - __bound_check(src, n, "memmove src"); - return __aeabi_memmove(dest, src, n); -} - -void *__bound___aeabi_memmove4(void *dest, const void *src, size_t n) -{ - dprintf(stderr, "%s, %s(): %p, %p, 0x%lx\n", - __FILE__, __FUNCTION__, dest, src, (unsigned long)n); - INCR_COUNT(bound_memmove_count); - __bound_check(dest, n, "memmove dest"); - __bound_check(src, n, "memmove src"); - return __aeabi_memmove4(dest, src, n); -} - -void *__bound___aeabi_memmove8(void *dest, const void *src, size_t n) -{ - dprintf(stderr, "%s, %s(): %p, %p, 0x%lx\n", - __FILE__, __FUNCTION__, dest, src, (unsigned long)n); - INCR_COUNT(bound_memmove_count); - __bound_check(dest, n, "memmove dest"); - __bound_check(src, n, "memmove src"); - return __aeabi_memmove8(dest, src, n); -} - -void *__bound___aeabi_memset(void *s, int c, size_t n) -{ - dprintf(stderr, "%s, %s(): %p, %d, 0x%lx\n", - __FILE__, __FUNCTION__, s, c, (unsigned long)n); - INCR_COUNT(bound_memset_count); - __bound_check(s, n, "memset"); - return __aeabi_memset(s, c, n); -} -#endif - -int __bound_strlen(const char *s) -{ - const char *p = s; - - dprintf(stderr, "%s, %s(): %p\n", - __FILE__, __FUNCTION__, s); - INCR_COUNT(bound_strlen_count); - while (*p++); - __bound_check(s, p - s, "strlen"); - return (p - s) - 1; -} - -char *__bound_strcpy(char *dest, const char *src) -{ - size_t len; - const char *p = src; - - dprintf(stderr, "%s, %s(): %p, %p\n", - __FILE__, __FUNCTION__, dest, src); - INCR_COUNT(bound_strcpy_count); - while (*p++); - len = p - src; - __bound_check(dest, len, "strcpy dest"); - __bound_check(src, len, "strcpy src"); - if (check_overlap(dest, len, src, len, "strcpy")) - return dest; - return strcpy (dest, src); -} - -char *__bound_strncpy(char *dest, const char *src, size_t n) -{ - size_t len = n; - const char *p = src; - - dprintf(stderr, "%s, %s(): %p, %p, 0x%lx\n", - __FILE__, __FUNCTION__, dest, src, (unsigned long)n); - INCR_COUNT(bound_strncpy_count); - while (len-- && *p++); - len = p - src; - __bound_check(dest, len, "strncpy dest"); - __bound_check(src, len, "strncpy src"); - if (check_overlap(dest, len, src, len, "strncpy")) - return dest; - return strncpy(dest, src, n); -} - -int __bound_strcmp(const char *s1, const char *s2) -{ - const unsigned char *u1 = (const unsigned char *) s1; - const unsigned char *u2 = (const unsigned char *) s2; - - dprintf(stderr, "%s, %s(): %p, %p\n", - __FILE__, __FUNCTION__, s1, s2); - INCR_COUNT(bound_strcmp_count); - while (*u1 && *u1 == *u2) { - ++u1; - ++u2; - } - __bound_check(s1, ((const char *)u1 - s1) + 1, "strcmp s1"); - __bound_check(s2, ((const char *)u2 - s2) + 1, "strcmp s2"); - return *u1 - *u2; -} - -int __bound_strncmp(const char *s1, const char *s2, size_t n) -{ - const unsigned char *u1 = (const unsigned char *) s1; - const unsigned char *u2 = (const unsigned char *) s2; - int retval = 0; - - dprintf(stderr, "%s, %s(): %p, %p, 0x%lx\n", - __FILE__, __FUNCTION__, s1, s2, (unsigned long)n); - INCR_COUNT(bound_strncmp_count); - do { - if ((ssize_t) --n == -1) - break; - else if (*u1 != *u2) { - retval = *u1++ - *u2++; - break; - } - ++u2; - } while (*u1++); - __bound_check(s1, (const char *)u1 - s1, "strncmp s1"); - __bound_check(s2, (const char *)u2 - s2, "strncmp s2"); - return retval; -} - -char *__bound_strcat(char *dest, const char *src) -{ - char *r = dest; - const char *s = src; - - dprintf(stderr, "%s, %s(): %p, %p\n", - __FILE__, __FUNCTION__, dest, src); - INCR_COUNT(bound_strcat_count); - while (*dest++); - while (*src++); - __bound_check(r, (dest - r) + (src - s) - 1, "strcat dest"); - __bound_check(s, src - s, "strcat src"); - if (check_overlap(r, (dest - r) + (src - s) - 1, s, src - s, "strcat")) - return dest; - return strcat(r, s); -} - -char *__bound_strchr(const char *s, int c) -{ - const unsigned char *str = (const unsigned char *) s; - unsigned char ch = c; - - dprintf(stderr, "%s, %s(): %p, %d\n", - __FILE__, __FUNCTION__, s, ch); - INCR_COUNT(bound_strchr_count); - while (*str) { - if (*str == ch) - break; - ++str; - } - __bound_check(s, ((const char *)str - s) + 1, "strchr"); - return *str == ch ? (char *) str : NULL; -} - -char *__bound_strdup(const char *s) -{ - const char *p = s; - char *new; - - INCR_COUNT(bound_strdup_count); - while (*p++); - __bound_check(s, p - s, "strdup"); - new = BOUND_MALLOC ((p - s) + 1); - dprintf(stderr, "%s, %s(): %p, 0x%lx\n", - __FILE__, __FUNCTION__, new, (unsigned long)(p -s)); - if (new) { - if (NO_CHECKING_GET() == 0 && no_strdup == 0) { - WAIT_SEM (); - tree = splay_insert((size_t)new, p - s, tree); - if (tree && tree->start == (size_t) new) - tree->type = TCC_TYPE_STRDUP; - POST_SEM (); - } - memcpy (new, s, p - s); - } - return new; -} - -/* - An implementation of top-down splaying with sizes - D. Sleator , January 1994. - - This extends top-down-splay.c to maintain a size field in each node. - This is the number of nodes in the subtree rooted there. This makes - it possible to efficiently compute the rank of a key. (The rank is - the number of nodes to the left of the given key.) It it also - possible to quickly find the node of a given rank. Both of these - operations are illustrated in the code below. The remainder of this - introduction is taken from top-down-splay.c. - - "Splay trees", or "self-adjusting search trees" are a simple and - efficient data structure for storing an ordered set. The data - structure consists of a binary tree, with no additional fields. It - allows searching, insertion, deletion, deletemin, deletemax, - splitting, joining, and many other operations, all with amortized - logarithmic performance. Since the trees adapt to the sequence of - requests, their performance on real access patterns is typically even - better. Splay trees are described in a number of texts and papers - [1,2,3,4]. - - The code here is adapted from simple top-down splay, at the bottom of - page 669 of [2]. It can be obtained via anonymous ftp from - spade.pc.cs.cmu.edu in directory /usr/sleator/public. - - The chief modification here is that the splay operation works even if the - item being splayed is not in the tree, and even if the tree root of the - tree is NULL. So the line: - - t = splay(i, t); - - causes it to search for item with key i in the tree rooted at t. If it's - there, it is splayed to the root. If it isn't there, then the node put - at the root is the last one before NULL that would have been reached in a - normal binary search for i. (It's a neighbor of i in the tree.) This - allows many other operations to be easily implemented, as shown below. - - [1] "Data Structures and Their Algorithms", Lewis and Denenberg, - Harper Collins, 1991, pp 243-251. - [2] "Self-adjusting Binary Search Trees" Sleator and Tarjan, - JACM Volume 32, No 3, July 1985, pp 652-686. - [3] "Data Structure and Algorithm Analysis", Mark Weiss, - Benjamin Cummins, 1992, pp 119-130. - [4] "Data Structures, Algorithms, and Performance", Derick Wood, - Addison-Wesley, 1993, pp 367-375 -*/ - -/* Code adapted for tcc */ - -#define compare(start,tstart,tsize) (start < tstart ? -1 : \ - start >= tstart+tsize ? 1 : 0) - -static Tree * splay (size_t addr, Tree *t) -/* Splay using the key start (which may or may not be in the tree.) */ -/* The starting root is t, and the tree used is defined by rat */ -{ - Tree N, *l, *r, *y; - int comp; - - INCR_COUNT_SPLAY(bound_splay); - if (t == NULL) return t; - N.left = N.right = NULL; - l = r = &N; - - for (;;) { - comp = compare(addr, t->start, t->size); - if (comp < 0) { - y = t->left; - if (y == NULL) break; - if (compare(addr, y->start, y->size) < 0) { - t->left = y->right; /* rotate right */ - y->right = t; - t = y; - if (t->left == NULL) break; - } - r->left = t; /* link right */ - r = t; - t = t->left; - } else if (comp > 0) { - y = t->right; - if (y == NULL) break; - if (compare(addr, y->start, y->size) > 0) { - t->right = y->left; /* rotate left */ - y->left = t; - t = y; - if (t->right == NULL) break; - } - l->right = t; /* link left */ - l = t; - t = t->right; - } else { - break; - } - } - l->right = t->left; /* assemble */ - r->left = t->right; - t->left = N.right; - t->right = N.left; - - return t; -} - -#define compare_end(start,tend) (start < tend ? -1 : \ - start > tend ? 1 : 0) - -static Tree * splay_end (size_t addr, Tree *t) -/* Splay using the key start (which may or may not be in the tree.) */ -/* The starting root is t, and the tree used is defined by rat */ -{ - Tree N, *l, *r, *y; - int comp; - - INCR_COUNT_SPLAY(bound_splay_end); - if (t == NULL) return t; - N.left = N.right = NULL; - l = r = &N; - - for (;;) { - comp = compare_end(addr, t->start + t->size); - if (comp < 0) { - y = t->left; - if (y == NULL) break; - if (compare_end(addr, y->start + y->size) < 0) { - t->left = y->right; /* rotate right */ - y->right = t; - t = y; - if (t->left == NULL) break; - } - r->left = t; /* link right */ - r = t; - t = t->left; - } else if (comp > 0) { - y = t->right; - if (y == NULL) break; - if (compare_end(addr, y->start + y->size) > 0) { - t->right = y->left; /* rotate left */ - y->left = t; - t = y; - if (t->right == NULL) break; - } - l->right = t; /* link left */ - l = t; - t = t->right; - } else { - break; - } - } - l->right = t->left; /* assemble */ - r->left = t->right; - t->left = N.right; - t->right = N.left; - - return t; -} - -static Tree * splay_insert(size_t addr, size_t size, Tree * t) -/* Insert key start into the tree t, if it is not already there. */ -/* Return a pointer to the resulting tree. */ -{ - Tree * new; - - INCR_COUNT_SPLAY(bound_splay_insert); - if (t != NULL) { - t = splay(addr,t); - if (compare(addr, t->start, t->size)==0) { - return t; /* it's already there */ - } - } -#if TREE_REUSE - if (tree_free_list) { - new = tree_free_list; - tree_free_list = new->left; - } - else -#endif - { - new = (Tree *) BOUND_MALLOC (sizeof (Tree)); - } - if (new == NULL) { - bound_alloc_error("not enough memory for bound checking code"); - } - else { - if (t == NULL) { - new->left = new->right = NULL; - } else if (compare(addr, t->start, t->size) < 0) { - new->left = t->left; - new->right = t; - t->left = NULL; - } else { - new->right = t->right; - new->left = t; - t->right = NULL; - } - new->start = addr; - new->size = size; - new->type = TCC_TYPE_NONE; - new->is_invalid = 0; - } - return new; -} - -#define compare_destroy(start,tstart) (start < tstart ? -1 : \ - start > tstart ? 1 : 0) - -static Tree * splay_delete(size_t addr, Tree *t) -/* Deletes addr from the tree if it's there. */ -/* Return a pointer to the resulting tree. */ -{ - Tree * x; - - INCR_COUNT_SPLAY(bound_splay_delete); - if (t==NULL) return NULL; - t = splay(addr,t); - if (compare_destroy(addr, t->start) == 0) { /* found it */ - if (t->left == NULL) { - x = t->right; - } else { - x = splay(addr, t->left); - x->right = t->right; - } -#if TREE_REUSE - t->left = tree_free_list; - tree_free_list = t; -#else - BOUND_FREE(t); -#endif - return x; - } else { - return t; /* It wasn't there */ - } -} - -void splay_printtree(Tree * t, int d) -{ - int i; - if (t == NULL) return; - splay_printtree(t->right, d+1); - for (i=0; istart, (unsigned long) t->size, - (unsigned)t->type, (unsigned)t->is_invalid); - splay_printtree(t->left, d+1); -} diff --git a/05/tcc-final/lib/bt-dll.c b/05/tcc-final/lib/bt-dll.c deleted file mode 100644 index 7c62cef..0000000 --- a/05/tcc-final/lib/bt-dll.c +++ /dev/null @@ -1,74 +0,0 @@ -/* ------------------------------------------------------------- */ -/* stubs for calling bcheck functions from a dll. */ - -#include -#include - -#define REDIR_ALL \ - REDIR(__bt_init) \ - REDIR(__bt_exit) \ - REDIR(tcc_backtrace) \ - \ - REDIR(__bound_ptr_add) \ - REDIR(__bound_ptr_indir1) \ - REDIR(__bound_ptr_indir2) \ - REDIR(__bound_ptr_indir4) \ - REDIR(__bound_ptr_indir8) \ - REDIR(__bound_ptr_indir12) \ - REDIR(__bound_ptr_indir16) \ - REDIR(__bound_local_new) \ - REDIR(__bound_local_delete) \ - REDIR(__bound_new_region) \ - \ - REDIR(__bound_free) \ - REDIR(__bound_malloc) \ - REDIR(__bound_realloc) \ - REDIR(__bound_memcpy) \ - REDIR(__bound_memcmp) \ - REDIR(__bound_memmove) \ - REDIR(__bound_memset) \ - REDIR(__bound_strlen) \ - REDIR(__bound_strcpy) \ - REDIR(__bound_strncpy) \ - REDIR(__bound_strcmp) \ - REDIR(__bound_strncmp) \ - REDIR(__bound_strcat) \ - REDIR(__bound_strchr) \ - REDIR(__bound_strdup) - -#ifdef __leading_underscore -#define _(s) "_"#s -#else -#define _(s) #s -#endif - -#define REDIR(s) void *s; -static struct { REDIR_ALL } all_ptrs; -#undef REDIR -#define REDIR(s) #s"\0" -static const char all_names[] = REDIR_ALL; -#undef REDIR -#define REDIR(s) __asm__(".global " _(s) ";" _(s) ": jmp *%0" : : "m" (all_ptrs.s) ); -static void all_jmps() { REDIR_ALL } -#undef REDIR - -void __bt_init_dll(int bcheck) -{ - const char *s = all_names; - void **p = (void**)&all_ptrs; - do { - *p = (void*)GetProcAddress(GetModuleHandle(NULL), (char*)s); - if (NULL == *p) { - char buf[100]; - sprintf(buf, - "Error: function '%s()' not found in executable. " - "(Need -bt or -b for linking the exe.)", s); - if (GetStdHandle(STD_ERROR_HANDLE)) - fprintf(stderr, "TCC/BCHECK: %s\n", buf), fflush(stderr); - else - MessageBox(NULL, buf, "TCC/BCHECK", MB_ICONERROR); - ExitProcess(1); - } - s = strchr(s,'\0') + 1, ++p; - } while (*s && (bcheck || p < &all_ptrs.__bound_ptr_add)); -} diff --git a/05/tcc-final/lib/bt-exe.c b/05/tcc-final/lib/bt-exe.c deleted file mode 100644 index f758476..0000000 --- a/05/tcc-final/lib/bt-exe.c +++ /dev/null @@ -1,73 +0,0 @@ -/* ------------------------------------------------------------- */ -/* for linking rt_printline and the signal/exception handler - from tccrun.c into executables. */ - -#define CONFIG_TCC_BACKTRACE_ONLY -#define ONE_SOURCE 0 -#include "../tccrun.c" - -int (*__rt_error)(void*, void*, const char *, va_list); -__attribute__((weak)) void __bound_checking_lock(void); -__attribute__((weak)) void __bound_checking_unlock(void); - -#ifndef _WIN32 -# define __declspec(n) -#endif - -__declspec(dllexport) -void __bt_init(rt_context *p, int num_callers) -{ - __attribute__((weak)) int main(); - __attribute__((weak)) void __bound_init(void*, int); - struct rt_context *rc = &g_rtctxt; - //fprintf(stderr, "__bt_init %d %p %p\n", num_callers, p->stab_sym, p->bounds_start), fflush(stderr); - /* call __bound_init here due to redirection of sigaction */ - /* needed to add global symbols */ - if (p->bounds_start) { - __bound_init(p->bounds_start, -1); - __bound_checking_lock(); - } - if (num_callers) { - memcpy(rc, p, offsetof(rt_context, next)); - rc->num_callers = num_callers - 1; - rc->top_func = main; - __rt_error = _rt_error; - set_exception_handler(); - } else { - p->next = rc->next, rc->next = p; - } - if (p->bounds_start) - __bound_checking_unlock(); -} - -__declspec(dllexport) -void __bt_exit(rt_context *p) -{ - __attribute__((weak)) void __bound_exit_dll(void*); - struct rt_context *rc = &g_rtctxt; - - if (p->bounds_start) { - __bound_exit_dll(p->bounds_start); - __bound_checking_lock(); - } - while (rc) { - if (rc->next == p) { - rc->next = rc->next->next; - break; - } - rc = rc->next; - } - if (p->bounds_start) - __bound_checking_unlock(); -} - -/* copy a string and truncate it. */ -ST_FUNC char *pstrcpy(char *buf, size_t buf_size, const char *s) -{ - int l = strlen(s); - if (l >= buf_size) - l = buf_size - 1; - memcpy(buf, s, l); - buf[l] = 0; - return buf; -} diff --git a/05/tcc-final/lib/bt-log.c b/05/tcc-final/lib/bt-log.c deleted file mode 100644 index d767f08..0000000 --- a/05/tcc-final/lib/bt-log.c +++ /dev/null @@ -1,37 +0,0 @@ -/* ------------------------------------------------------------- */ -/* function to get a stack backtrace on demand with a message */ - -#include -#include -#include - -int (*__rt_error)(void*, void*, const char *, va_list); - -#ifdef _WIN32 -# define DLL_EXPORT __declspec(dllexport) -#else -# define DLL_EXPORT -#endif - -DLL_EXPORT int tcc_backtrace(const char *fmt, ...) -{ - va_list ap; - int ret; - - if (__rt_error) { - void *fp = __builtin_frame_address(1); - void *ip = __builtin_return_address(0); - va_start(ap, fmt); - ret = __rt_error(fp, ip, fmt, ap); - va_end(ap); - } else { - const char *p; - if (fmt[0] == '^' && (p = strchr(fmt + 1, fmt[0]))) - fmt = p + 1; - va_start(ap, fmt); - ret = vfprintf(stderr, fmt, ap); - va_end(ap); - fprintf(stderr, "\n"), fflush(stderr); - } - return ret; -} diff --git a/05/tcc-final/lib/dsohandle.c b/05/tcc-final/lib/dsohandle.c deleted file mode 100644 index 0993dbc..0000000 --- a/05/tcc-final/lib/dsohandle.c +++ /dev/null @@ -1 +0,0 @@ -void * __dso_handle __attribute((visibility("hidden"))) = &__dso_handle; diff --git a/05/tcc-final/lib/fetch_and_add.S b/05/tcc-final/lib/fetch_and_add.S deleted file mode 100644 index ec96a03..0000000 --- a/05/tcc-final/lib/fetch_and_add.S +++ /dev/null @@ -1,67 +0,0 @@ -/* ---------------------------------------------- */ -#if defined __arm__ - - .text - .align 2 - .global fetch_and_add_arm - .type fetch_and_add_arm, %function -fetch_and_add_arm: - mcr p15, #0, r0, c7, c10, #5 -.L0: - ldrex r3, [r0] - add r3, r3, r1 - strex r2, r3, [r0] - cmp r2, #0 - bne .L0 - mcr p15, #0, r0, c7, c10, #5 - bx lr - .size fetch_and_add_arm, .-fetch_and_add_arm - -/* ---------------------------------------------- */ -#elif defined __aarch64__ - - .text - .align 2 - .global fetch_and_add_arm64 - .type fetch_and_add_arm64, %function -fetch_and_add_arm64: -#ifdef __TINYC__ - .int 0x885f7c02 - .int 0x0b010042 - .int 0x8803fc02 - .int 0x35ffffa3 - .int 0xd5033bbf - .int 0xd65f03c0 -#else - ldxr w2, [x0] - add w2, w2, w1 - stlxr w3, w2, [x0] - cbnz w3, fetch_and_add_arm64 - dmb ish - ret -#endif - - .size fetch_and_add_arm64, .-fetch_and_add_arm64 - -/* ---------------------------------------------- */ -#elif defined __riscv - - .text - .align 2 - .global fetch_and_add_riscv64 - .type fetch_and_add_riscv64, %function -fetch_and_add_riscv64: -#ifdef __TINYC__ - .int 0x0f50000f - .int 0x004b5202f - .short 0x8082 -#else - fence iorw,ow - amoadd.w.aq zero,a1,0(a0) - ret -#endif - - .size fetch_and_add_riscv64, .-fetch_and_add_riscv64 - -/* ---------------------------------------------- */ -#endif diff --git a/05/tcc-final/lib/lib-arm64.c b/05/tcc-final/lib/lib-arm64.c deleted file mode 100644 index 33df509..0000000 --- a/05/tcc-final/lib/lib-arm64.c +++ /dev/null @@ -1,677 +0,0 @@ -/* - * TCC runtime library for arm64. - * - * Copyright (c) 2015 Edmund Grimley Evans - * - * Copying and distribution of this file, with or without modification, - * are permitted in any medium without royalty provided the copyright - * notice and this notice are preserved. This file is offered as-is, - * without any warranty. - */ - -#ifdef __TINYC__ -typedef signed char int8_t; -typedef unsigned char uint8_t; -typedef short int16_t; -typedef unsigned short uint16_t; -typedef int int32_t; -typedef unsigned uint32_t; -typedef long long int64_t; -typedef unsigned long long uint64_t; -void *memcpy(void*,void*,__SIZE_TYPE__); -#else -#include -#include -#endif - -#ifndef __riscv -void __clear_cache(void *beg, void *end) -{ - __arm64_clear_cache(beg, end); -} -#endif - -typedef struct { - uint64_t x0, x1; -} u128_t; - -static long double f3_zero(int sgn) -{ - long double f; - u128_t x = { 0, (uint64_t)sgn << 63 }; - memcpy(&f, &x, 16); - return f; -} - -static long double f3_infinity(int sgn) -{ - long double f; - u128_t x = { 0, (uint64_t)sgn << 63 | 0x7fff000000000000 }; - memcpy(&f, &x, 16); - return f; -} - -static long double f3_NaN(void) -{ - long double f; -#if 0 - // ARM's default NaN usually has just the top fraction bit set: - u128_t x = { 0, 0x7fff800000000000 }; -#else - // GCC's library sets all fraction bits: - u128_t x = { -1, 0x7fffffffffffffff }; -#endif - memcpy(&f, &x, 16); - return f; -} - -static int fp3_convert_NaN(long double *f, int sgn, u128_t mnt) -{ - u128_t x = { mnt.x0, - mnt.x1 | 0x7fff800000000000 | (uint64_t)sgn << 63 }; - memcpy(f, &x, 16); - return 1; -} - -static int fp3_detect_NaNs(long double *f, - int a_sgn, int a_exp, u128_t a, - int b_sgn, int b_exp, u128_t b) -{ - // Detect signalling NaNs: - if (a_exp == 32767 && (a.x0 | a.x1 << 16) && !(a.x1 >> 47 & 1)) - return fp3_convert_NaN(f, a_sgn, a); - if (b_exp == 32767 && (b.x0 | b.x1 << 16) && !(b.x1 >> 47 & 1)) - return fp3_convert_NaN(f, b_sgn, b); - - // Detect quiet NaNs: - if (a_exp == 32767 && (a.x0 | a.x1 << 16)) - return fp3_convert_NaN(f, a_sgn, a); - if (b_exp == 32767 && (b.x0 | b.x1 << 16)) - return fp3_convert_NaN(f, b_sgn, b); - - return 0; -} - -static void f3_unpack(int *sgn, int32_t *exp, u128_t *mnt, long double f) -{ - u128_t x; - memcpy(&x, &f, 16); - *sgn = x.x1 >> 63; - *exp = x.x1 >> 48 & 32767; - x.x1 = x.x1 << 16 >> 16; - if (*exp) - x.x1 |= (uint64_t)1 << 48; - else - *exp = 1; - *mnt = x; -} - -static u128_t f3_normalise(int32_t *exp, u128_t mnt) -{ - int sh; - if (!(mnt.x0 | mnt.x1)) - return mnt; - if (!mnt.x1) { - mnt.x1 = mnt.x0; - mnt.x0 = 0; - *exp -= 64; - } - for (sh = 32; sh; sh >>= 1) { - if (!(mnt.x1 >> (64 - sh))) { - mnt.x1 = mnt.x1 << sh | mnt.x0 >> (64 - sh); - mnt.x0 = mnt.x0 << sh; - *exp -= sh; - } - } - return mnt; -} - -static u128_t f3_sticky_shift(int32_t sh, u128_t x) -{ - if (sh >= 128) { - x.x0 = !!(x.x0 | x.x1); - x.x1 = 0; - return x; - } - if (sh >= 64) { - x.x0 = x.x1 | !!x.x0; - x.x1 = 0; - sh -= 64; - } - if (sh > 0) { - x.x0 = x.x0 >> sh | x.x1 << (64 - sh) | !!(x.x0 << (64 - sh)); - x.x1 = x.x1 >> sh; - } - return x; -} - -static long double f3_round(int sgn, int32_t exp, u128_t x) -{ - long double f; - int error; - - if (exp > 0) { - x = f3_sticky_shift(13, x); - } - else { - x = f3_sticky_shift(14 - exp, x); - exp = 0; - } - - error = x.x0 & 3; - x.x0 = x.x0 >> 2 | x.x1 << 62; - x.x1 = x.x1 >> 2; - - if (error == 3 || ((error == 2) & (x.x0 & 1))) { - if (!++x.x0) { - ++x.x1; - if (x.x1 == (uint64_t)1 << 48) - exp = 1; - else if (x.x1 == (uint64_t)1 << 49) { - ++exp; - x.x0 = x.x0 >> 1 | x.x1 << 63; - x.x1 = x.x1 >> 1; - } - } - } - - if (exp >= 32767) - return f3_infinity(sgn); - - x.x1 = x.x1 << 16 >> 16 | (uint64_t)exp << 48 | (uint64_t)sgn << 63; - memcpy(&f, &x, 16); - return f; -} - -static long double f3_add(long double fa, long double fb, int neg) -{ - u128_t a, b, x; - int32_t a_exp, b_exp, x_exp; - int a_sgn, b_sgn, x_sgn; - long double fx; - - f3_unpack(&a_sgn, &a_exp, &a, fa); - f3_unpack(&b_sgn, &b_exp, &b, fb); - - if (fp3_detect_NaNs(&fx, a_sgn, a_exp, a, b_sgn, b_exp, b)) - return fx; - - b_sgn ^= neg; - - // Handle infinities and zeroes: - if (a_exp == 32767 && b_exp == 32767 && a_sgn != b_sgn) - return f3_NaN(); - if (a_exp == 32767) - return f3_infinity(a_sgn); - if (b_exp == 32767) - return f3_infinity(b_sgn); - if (!(a.x0 | a.x1 | b.x0 | b.x1)) - return f3_zero(a_sgn & b_sgn); - - a.x1 = a.x1 << 3 | a.x0 >> 61; - a.x0 = a.x0 << 3; - b.x1 = b.x1 << 3 | b.x0 >> 61; - b.x0 = b.x0 << 3; - - if (a_exp <= b_exp) { - a = f3_sticky_shift(b_exp - a_exp, a); - a_exp = b_exp; - } - else { - b = f3_sticky_shift(a_exp - b_exp, b); - b_exp = a_exp; - } - - x_sgn = a_sgn; - x_exp = a_exp; - if (a_sgn == b_sgn) { - x.x0 = a.x0 + b.x0; - x.x1 = a.x1 + b.x1 + (x.x0 < a.x0); - } - else { - x.x0 = a.x0 - b.x0; - x.x1 = a.x1 - b.x1 - (x.x0 > a.x0); - if (x.x1 >> 63) { - x_sgn ^= 1; - x.x0 = -x.x0; - x.x1 = -x.x1 - !!x.x0; - } - } - - if (!(x.x0 | x.x1)) - return f3_zero(0); - - x = f3_normalise(&x_exp, x); - - return f3_round(x_sgn, x_exp + 12, x); -} - -long double __addtf3(long double a, long double b) -{ - return f3_add(a, b, 0); -} - -long double __subtf3(long double a, long double b) -{ - return f3_add(a, b, 1); -} - -long double __multf3(long double fa, long double fb) -{ - u128_t a, b, x; - int32_t a_exp, b_exp, x_exp; - int a_sgn, b_sgn, x_sgn; - long double fx; - - f3_unpack(&a_sgn, &a_exp, &a, fa); - f3_unpack(&b_sgn, &b_exp, &b, fb); - - if (fp3_detect_NaNs(&fx, a_sgn, a_exp, a, b_sgn, b_exp, b)) - return fx; - - // Handle infinities and zeroes: - if ((a_exp == 32767 && !(b.x0 | b.x1)) || - (b_exp == 32767 && !(a.x0 | a.x1))) - return f3_NaN(); - if (a_exp == 32767 || b_exp == 32767) - return f3_infinity(a_sgn ^ b_sgn); - if (!(a.x0 | a.x1) || !(b.x0 | b.x1)) - return f3_zero(a_sgn ^ b_sgn); - - a = f3_normalise(&a_exp, a); - b = f3_normalise(&b_exp, b); - - x_sgn = a_sgn ^ b_sgn; - x_exp = a_exp + b_exp - 16352; - - { - // Convert to base (1 << 30), discarding bottom 6 bits, which are zero, - // so there are (32, 30, 30, 30) bits in (a3, a2, a1, a0): - uint64_t a0 = a.x0 << 28 >> 34; - uint64_t b0 = b.x0 << 28 >> 34; - uint64_t a1 = a.x0 >> 36 | a.x1 << 62 >> 34; - uint64_t b1 = b.x0 >> 36 | b.x1 << 62 >> 34; - uint64_t a2 = a.x1 << 32 >> 34; - uint64_t b2 = b.x1 << 32 >> 34; - uint64_t a3 = a.x1 >> 32; - uint64_t b3 = b.x1 >> 32; - // Use 16 small multiplications and additions that do not overflow: - uint64_t x0 = a0 * b0; - uint64_t x1 = (x0 >> 30) + a0 * b1 + a1 * b0; - uint64_t x2 = (x1 >> 30) + a0 * b2 + a1 * b1 + a2 * b0; - uint64_t x3 = (x2 >> 30) + a0 * b3 + a1 * b2 + a2 * b1 + a3 * b0; - uint64_t x4 = (x3 >> 30) + a1 * b3 + a2 * b2 + a3 * b1; - uint64_t x5 = (x4 >> 30) + a2 * b3 + a3 * b2; - uint64_t x6 = (x5 >> 30) + a3 * b3; - // We now have (64, 30, 30, ...) bits in (x6, x5, x4, ...). - // Take the top 128 bits, setting bottom bit if any lower bits were set: - uint64_t y0 = (x5 << 34 | x4 << 34 >> 30 | x3 << 34 >> 60 | - !!(x3 << 38 | (x2 | x1 | x0) << 34)); - uint64_t y1 = x6; - // Top bit may be zero. Renormalise: - if (!(y1 >> 63)) { - y1 = y1 << 1 | y0 >> 63; - y0 = y0 << 1; - --x_exp; - } - x.x0 = y0; - x.x1 = y1; - } - - return f3_round(x_sgn, x_exp, x); -} - -long double __divtf3(long double fa, long double fb) -{ - u128_t a, b, x; - int32_t a_exp, b_exp, x_exp; - int a_sgn, b_sgn, x_sgn, i; - long double fx; - - f3_unpack(&a_sgn, &a_exp, &a, fa); - f3_unpack(&b_sgn, &b_exp, &b, fb); - - if (fp3_detect_NaNs(&fx, a_sgn, a_exp, a, b_sgn, b_exp, b)) - return fx; - - // Handle infinities and zeroes: - if ((a_exp == 32767 && b_exp == 32767) || - (!(a.x0 | a.x1) && !(b.x0 | b.x1))) - return f3_NaN(); - if (a_exp == 32767 || !(b.x0 | b.x1)) - return f3_infinity(a_sgn ^ b_sgn); - if (!(a.x0 | a.x1) || b_exp == 32767) - return f3_zero(a_sgn ^ b_sgn); - - a = f3_normalise(&a_exp, a); - b = f3_normalise(&b_exp, b); - - x_sgn = a_sgn ^ b_sgn; - x_exp = a_exp - b_exp + 16395; - - a.x0 = a.x0 >> 1 | a.x1 << 63; - a.x1 = a.x1 >> 1; - b.x0 = b.x0 >> 1 | b.x1 << 63; - b.x1 = b.x1 >> 1; - x.x0 = 0; - x.x1 = 0; - for (i = 0; i < 116; i++) { - x.x1 = x.x1 << 1 | x.x0 >> 63; - x.x0 = x.x0 << 1; - if (a.x1 > b.x1 || (a.x1 == b.x1 && a.x0 >= b.x0)) { - a.x1 = a.x1 - b.x1 - (a.x0 < b.x0); - a.x0 = a.x0 - b.x0; - x.x0 |= 1; - } - a.x1 = a.x1 << 1 | a.x0 >> 63; - a.x0 = a.x0 << 1; - } - x.x0 |= !!(a.x0 | a.x1); - - x = f3_normalise(&x_exp, x); - - return f3_round(x_sgn, x_exp, x); -} - -long double __extendsftf2(float f) -{ - long double fx; - u128_t x; - uint32_t a; - uint64_t aa; - memcpy(&a, &f, 4); - aa = a; - x.x0 = 0; - if (!(a << 1)) - x.x1 = aa << 32; - else if (a << 1 >> 24 == 255) - x.x1 = (0x7fff000000000000 | aa >> 31 << 63 | aa << 41 >> 16 | - (uint64_t)!!(a << 9) << 47); - else if (a << 1 >> 24 == 0) { - uint64_t adj = 0; - while (!(a << 1 >> 1 >> (23 - adj))) - adj++; - x.x1 = aa >> 31 << 63 | (16256 - adj + 1) << 48 | aa << adj << 41 >> 16; - } else - x.x1 = (aa >> 31 << 63 | ((aa >> 23 & 255) + 16256) << 48 | - aa << 41 >> 16); - memcpy(&fx, &x, 16); - return fx; -} - -long double __extenddftf2(double f) -{ - long double fx; - u128_t x; - uint64_t a; - memcpy(&a, &f, 8); - x.x0 = a << 60; - if (!(a << 1)) - x.x1 = a; - else if (a << 1 >> 53 == 2047) - x.x1 = (0x7fff000000000000 | a >> 63 << 63 | a << 12 >> 16 | - (uint64_t)!!(a << 12) << 47); - else if (a << 1 >> 53 == 0) { - uint64_t adj = 0; - while (!(a << 1 >> 1 >> (52 - adj))) - adj++; - x.x0 <<= adj; - x.x1 = a >> 63 << 63 | (15360 - adj + 1) << 48 | a << adj << 12 >> 16; - } else - x.x1 = a >> 63 << 63 | ((a >> 52 & 2047) + 15360) << 48 | a << 12 >> 16; - memcpy(&fx, &x, 16); - return fx; -} - -float __trunctfsf2(long double f) -{ - u128_t mnt; - int32_t exp; - int sgn; - uint32_t x; - float fx; - - f3_unpack(&sgn, &exp, &mnt, f); - - if (exp == 32767 && (mnt.x0 | mnt.x1 << 16)) - x = 0x7fc00000 | (uint32_t)sgn << 31 | (mnt.x1 >> 25 & 0x007fffff); - else if (exp > 16510) - x = 0x7f800000 | (uint32_t)sgn << 31; - else if (exp < 16233) - x = (uint32_t)sgn << 31; - else { - exp -= 16257; - x = mnt.x1 >> 23 | !!(mnt.x0 | mnt.x1 << 41); - if (exp < 0) { - x = x >> -exp | !!(x << (32 + exp)); - exp = 0; - } - if ((x & 3) == 3 || (x & 7) == 6) - x += 4; - x = ((x >> 2) + (exp << 23)) | (uint32_t)sgn << 31; - } - memcpy(&fx, &x, 4); - return fx; -} - -double __trunctfdf2(long double f) -{ - u128_t mnt; - int32_t exp; - int sgn; - uint64_t x; - double fx; - - f3_unpack(&sgn, &exp, &mnt, f); - - if (exp == 32767 && (mnt.x0 | mnt.x1 << 16)) - x = (0x7ff8000000000000 | (uint64_t)sgn << 63 | - mnt.x1 << 16 >> 12 | mnt.x0 >> 60); - else if (exp > 17406) - x = 0x7ff0000000000000 | (uint64_t)sgn << 63; - else if (exp < 15308) - x = (uint64_t)sgn << 63; - else { - exp -= 15361; - x = mnt.x1 << 6 | mnt.x0 >> 58 | !!(mnt.x0 << 6); - if (exp < 0) { - x = x >> -exp | !!(x << (64 + exp)); - exp = 0; - } - if ((x & 3) == 3 || (x & 7) == 6) - x += 4; - x = ((x >> 2) + ((uint64_t)exp << 52)) | (uint64_t)sgn << 63; - } - memcpy(&fx, &x, 8); - return fx; -} - -int32_t __fixtfsi(long double fa) -{ - u128_t a; - int32_t a_exp; - int a_sgn; - int32_t x; - f3_unpack(&a_sgn, &a_exp, &a, fa); - if (a_exp < 16369) - return 0; - if (a_exp > 16413) - return a_sgn ? -0x80000000 : 0x7fffffff; - x = a.x1 >> (16431 - a_exp); - return a_sgn ? -x : x; -} - -int64_t __fixtfdi(long double fa) -{ - u128_t a; - int32_t a_exp; - int a_sgn; - int64_t x; - f3_unpack(&a_sgn, &a_exp, &a, fa); - if (a_exp < 16383) - return 0; - if (a_exp > 16445) - return a_sgn ? -0x8000000000000000 : 0x7fffffffffffffff; - x = (a.x1 << 15 | a.x0 >> 49) >> (16446 - a_exp); - return a_sgn ? -x : x; -} - -uint32_t __fixunstfsi(long double fa) -{ - u128_t a; - int32_t a_exp; - int a_sgn; - f3_unpack(&a_sgn, &a_exp, &a, fa); - if (a_sgn || a_exp < 16369) - return 0; - if (a_exp > 16414) - return -1; - return a.x1 >> (16431 - a_exp); -} - -uint64_t __fixunstfdi(long double fa) -{ - u128_t a; - int32_t a_exp; - int a_sgn; - f3_unpack(&a_sgn, &a_exp, &a, fa); - if (a_sgn || a_exp < 16383) - return 0; - if (a_exp > 16446) - return -1; - return (a.x1 << 15 | a.x0 >> 49) >> (16446 - a_exp); -} - -long double __floatsitf(int32_t a) -{ - int sgn = 0; - int exp = 16414; - uint32_t mnt = a; - u128_t x = { 0, 0 }; - long double f; - int i; - if (a) { - if (a < 0) { - sgn = 1; - mnt = -mnt; - } - for (i = 16; i; i >>= 1) - if (!(mnt >> (32 - i))) { - mnt <<= i; - exp -= i; - } - x.x1 = ((uint64_t)sgn << 63 | (uint64_t)exp << 48 | - (uint64_t)(mnt << 1) << 16); - } - memcpy(&f, &x, 16); - return f; -} - -long double __floatditf(int64_t a) -{ - int sgn = 0; - int exp = 16446; - uint64_t mnt = a; - u128_t x = { 0, 0 }; - long double f; - int i; - if (a) { - if (a < 0) { - sgn = 1; - mnt = -mnt; - } - for (i = 32; i; i >>= 1) - if (!(mnt >> (64 - i))) { - mnt <<= i; - exp -= i; - } - x.x0 = mnt << 49; - x.x1 = (uint64_t)sgn << 63 | (uint64_t)exp << 48 | mnt << 1 >> 16; - } - memcpy(&f, &x, 16); - return f; -} - -long double __floatunsitf(uint32_t a) -{ - int exp = 16414; - uint32_t mnt = a; - u128_t x = { 0, 0 }; - long double f; - int i; - if (a) { - for (i = 16; i; i >>= 1) - if (!(mnt >> (32 - i))) { - mnt <<= i; - exp -= i; - } - x.x1 = (uint64_t)exp << 48 | (uint64_t)(mnt << 1) << 16; - } - memcpy(&f, &x, 16); - return f; -} - -long double __floatunditf(uint64_t a) -{ - int exp = 16446; - uint64_t mnt = a; - u128_t x = { 0, 0 }; - long double f; - int i; - if (a) { - for (i = 32; i; i >>= 1) - if (!(mnt >> (64 - i))) { - mnt <<= i; - exp -= i; - } - x.x0 = mnt << 49; - x.x1 = (uint64_t)exp << 48 | mnt << 1 >> 16; - } - memcpy(&f, &x, 16); - return f; -} - -static int f3_cmp(long double fa, long double fb) -{ - u128_t a, b; - memcpy(&a, &fa, 16); - memcpy(&b, &fb, 16); - return (!(a.x0 | a.x1 << 1 | b.x0 | b.x1 << 1) ? 0 : - ((a.x1 << 1 >> 49 == 0x7fff && (a.x0 | a.x1 << 16)) || - (b.x1 << 1 >> 49 == 0x7fff && (b.x0 | b.x1 << 16))) ? 2 : - a.x1 >> 63 != b.x1 >> 63 ? (int)(b.x1 >> 63) - (int)(a.x1 >> 63) : - a.x1 < b.x1 ? (int)(a.x1 >> 63 << 1) - 1 : - a.x1 > b.x1 ? 1 - (int)(a.x1 >> 63 << 1) : - a.x0 < b.x0 ? (int)(a.x1 >> 63 << 1) - 1 : - b.x0 < a.x0 ? 1 - (int)(a.x1 >> 63 << 1) : 0); -} - -int __eqtf2(long double a, long double b) -{ - return !!f3_cmp(a, b); -} - -int __netf2(long double a, long double b) -{ - return !!f3_cmp(a, b); -} - -int __lttf2(long double a, long double b) -{ - return f3_cmp(a, b); -} - -int __letf2(long double a, long double b) -{ - return f3_cmp(a, b); -} - -int __gttf2(long double a, long double b) -{ - return -f3_cmp(b, a); -} - -int __getf2(long double a, long double b) -{ - return -f3_cmp(b, a); -} diff --git a/05/tcc-final/lib/libtcc1.c b/05/tcc-final/lib/libtcc1.c deleted file mode 100644 index ae94af1..0000000 --- a/05/tcc-final/lib/libtcc1.c +++ /dev/null @@ -1,641 +0,0 @@ -/* TCC runtime library. - Parts of this code are (c) 2002 Fabrice Bellard - - Copyright (C) 1987, 1988, 1992, 1994, 1995 Free Software Foundation, Inc. - -This file is free software; you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 2, or (at your option) any -later version. - -In addition to the permissions in the GNU General Public License, the -Free Software Foundation gives you unlimited permission to link the -compiled version of this file into combinations with other programs, -and to distribute those combinations without any restriction coming -from the use of this file. (The General Public License restrictions -do apply in other respects; for example, they cover modification of -the file, and distribution when not linked into a combine -executable.) - -This file is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; see the file COPYING. If not, write to -the Free Software Foundation, 59 Temple Place - Suite 330, -Boston, MA 02111-1307, USA. -*/ - -#define W_TYPE_SIZE 32 -#define BITS_PER_UNIT 8 - -typedef int Wtype; -typedef unsigned int UWtype; -typedef unsigned int USItype; -typedef long long DWtype; -typedef unsigned long long UDWtype; - -struct DWstruct { - Wtype low, high; -}; - -typedef union -{ - struct DWstruct s; - DWtype ll; -} DWunion; - -typedef long double XFtype; -#define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT) -#define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE) - -/* the following deal with IEEE single-precision numbers */ -#define EXCESS 126 -#define SIGNBIT 0x80000000 -#define HIDDEN (1 << 23) -#define SIGN(fp) ((fp) & SIGNBIT) -#define EXP(fp) (((fp) >> 23) & 0xFF) -#define MANT(fp) (((fp) & 0x7FFFFF) | HIDDEN) -#define PACK(s,e,m) ((s) | ((e) << 23) | (m)) - -/* the following deal with IEEE double-precision numbers */ -#define EXCESSD 1022 -#define HIDDEND (1 << 20) -#define EXPD(fp) (((fp.l.upper) >> 20) & 0x7FF) -#define SIGND(fp) ((fp.l.upper) & SIGNBIT) -#define MANTD(fp) (((((fp.l.upper) & 0xFFFFF) | HIDDEND) << 10) | \ - (fp.l.lower >> 22)) -#define HIDDEND_LL ((long long)1 << 52) -#define MANTD_LL(fp) ((fp.ll & (HIDDEND_LL-1)) | HIDDEND_LL) -#define PACKD_LL(s,e,m) (((long long)((s)+((e)<<20))<<32)|(m)) - -/* the following deal with x86 long double-precision numbers */ -#define EXCESSLD 16382 -#define EXPLD(fp) (fp.l.upper & 0x7fff) -#define SIGNLD(fp) ((fp.l.upper) & 0x8000) - -/* only for x86 */ -union ldouble_long { - long double ld; - struct { - unsigned long long lower; - unsigned short upper; - } l; -}; - -union double_long { - double d; -#if 1 - struct { - unsigned int lower; - int upper; - } l; -#else - struct { - int upper; - unsigned int lower; - } l; -#endif - long long ll; -}; - -union float_long { - float f; - unsigned int l; -}; - -/* XXX: we don't support several builtin supports for now */ -#if !defined __x86_64__ && !defined __arm__ - -/* XXX: use gcc/tcc intrinsic ? */ -#if defined __i386__ -#define sub_ddmmss(sh, sl, ah, al, bh, bl) \ - __asm__ ("subl %5,%1\n\tsbbl %3,%0" \ - : "=r" ((USItype) (sh)), \ - "=&r" ((USItype) (sl)) \ - : "0" ((USItype) (ah)), \ - "g" ((USItype) (bh)), \ - "1" ((USItype) (al)), \ - "g" ((USItype) (bl))) -#define umul_ppmm(w1, w0, u, v) \ - __asm__ ("mull %3" \ - : "=a" ((USItype) (w0)), \ - "=d" ((USItype) (w1)) \ - : "%0" ((USItype) (u)), \ - "rm" ((USItype) (v))) -#define udiv_qrnnd(q, r, n1, n0, dv) \ - __asm__ ("divl %4" \ - : "=a" ((USItype) (q)), \ - "=d" ((USItype) (r)) \ - : "0" ((USItype) (n0)), \ - "1" ((USItype) (n1)), \ - "rm" ((USItype) (dv))) -#define count_leading_zeros(count, x) \ - do { \ - USItype __cbtmp; \ - __asm__ ("bsrl %1,%0" \ - : "=r" (__cbtmp) : "rm" ((USItype) (x))); \ - (count) = __cbtmp ^ 31; \ - } while (0) -#else -#error unsupported CPU type -#endif - -/* most of this code is taken from libgcc2.c from gcc */ - -static UDWtype __udivmoddi4 (UDWtype n, UDWtype d, UDWtype *rp) -{ - DWunion ww; - DWunion nn, dd; - DWunion rr; - UWtype d0, d1, n0, n1, n2; - UWtype q0, q1; - UWtype b, bm; - - nn.ll = n; - dd.ll = d; - - d0 = dd.s.low; - d1 = dd.s.high; - n0 = nn.s.low; - n1 = nn.s.high; - -#if !defined(UDIV_NEEDS_NORMALIZATION) - if (d1 == 0) - { - if (d0 > n1) - { - /* 0q = nn / 0D */ - - udiv_qrnnd (q0, n0, n1, n0, d0); - q1 = 0; - - /* Remainder in n0. */ - } - else - { - /* qq = NN / 0d */ - - if (d0 == 0) - d0 = 1 / d0; /* Divide intentionally by zero. */ - - udiv_qrnnd (q1, n1, 0, n1, d0); - udiv_qrnnd (q0, n0, n1, n0, d0); - - /* Remainder in n0. */ - } - - if (rp != 0) - { - rr.s.low = n0; - rr.s.high = 0; - *rp = rr.ll; - } - } - -#else /* UDIV_NEEDS_NORMALIZATION */ - - if (d1 == 0) - { - if (d0 > n1) - { - /* 0q = nn / 0D */ - - count_leading_zeros (bm, d0); - - if (bm != 0) - { - /* Normalize, i.e. make the most significant bit of the - denominator set. */ - - d0 = d0 << bm; - n1 = (n1 << bm) | (n0 >> (W_TYPE_SIZE - bm)); - n0 = n0 << bm; - } - - udiv_qrnnd (q0, n0, n1, n0, d0); - q1 = 0; - - /* Remainder in n0 >> bm. */ - } - else - { - /* qq = NN / 0d */ - - if (d0 == 0) - d0 = 1 / d0; /* Divide intentionally by zero. */ - - count_leading_zeros (bm, d0); - - if (bm == 0) - { - /* From (n1 >= d0) /\ (the most significant bit of d0 is set), - conclude (the most significant bit of n1 is set) /\ (the - leading quotient digit q1 = 1). - - This special case is necessary, not an optimization. - (Shifts counts of W_TYPE_SIZE are undefined.) */ - - n1 -= d0; - q1 = 1; - } - else - { - /* Normalize. */ - - b = W_TYPE_SIZE - bm; - - d0 = d0 << bm; - n2 = n1 >> b; - n1 = (n1 << bm) | (n0 >> b); - n0 = n0 << bm; - - udiv_qrnnd (q1, n1, n2, n1, d0); - } - - /* n1 != d0... */ - - udiv_qrnnd (q0, n0, n1, n0, d0); - - /* Remainder in n0 >> bm. */ - } - - if (rp != 0) - { - rr.s.low = n0 >> bm; - rr.s.high = 0; - *rp = rr.ll; - } - } -#endif /* UDIV_NEEDS_NORMALIZATION */ - - else - { - if (d1 > n1) - { - /* 00 = nn / DD */ - - q0 = 0; - q1 = 0; - - /* Remainder in n1n0. */ - if (rp != 0) - { - rr.s.low = n0; - rr.s.high = n1; - *rp = rr.ll; - } - } - else - { - /* 0q = NN / dd */ - - count_leading_zeros (bm, d1); - if (bm == 0) - { - /* From (n1 >= d1) /\ (the most significant bit of d1 is set), - conclude (the most significant bit of n1 is set) /\ (the - quotient digit q0 = 0 or 1). - - This special case is necessary, not an optimization. */ - - /* The condition on the next line takes advantage of that - n1 >= d1 (true due to program flow). */ - if (n1 > d1 || n0 >= d0) - { - q0 = 1; - sub_ddmmss (n1, n0, n1, n0, d1, d0); - } - else - q0 = 0; - - q1 = 0; - - if (rp != 0) - { - rr.s.low = n0; - rr.s.high = n1; - *rp = rr.ll; - } - } - else - { - UWtype m1, m0; - /* Normalize. */ - - b = W_TYPE_SIZE - bm; - - d1 = (d1 << bm) | (d0 >> b); - d0 = d0 << bm; - n2 = n1 >> b; - n1 = (n1 << bm) | (n0 >> b); - n0 = n0 << bm; - - udiv_qrnnd (q0, n1, n2, n1, d1); - umul_ppmm (m1, m0, q0, d0); - - if (m1 > n1 || (m1 == n1 && m0 > n0)) - { - q0--; - sub_ddmmss (m1, m0, m1, m0, d1, d0); - } - - q1 = 0; - - /* Remainder in (n1n0 - m1m0) >> bm. */ - if (rp != 0) - { - sub_ddmmss (n1, n0, n1, n0, m1, m0); - rr.s.low = (n1 << b) | (n0 >> bm); - rr.s.high = n1 >> bm; - *rp = rr.ll; - } - } - } - } - - ww.s.low = q0; - ww.s.high = q1; - return ww.ll; -} - -#define __negdi2(a) (-(a)) - -long long __divdi3(long long u, long long v) -{ - int c = 0; - DWunion uu, vv; - DWtype w; - - uu.ll = u; - vv.ll = v; - - if (uu.s.high < 0) { - c = ~c; - uu.ll = __negdi2 (uu.ll); - } - if (vv.s.high < 0) { - c = ~c; - vv.ll = __negdi2 (vv.ll); - } - w = __udivmoddi4 (uu.ll, vv.ll, (UDWtype *) 0); - if (c) - w = __negdi2 (w); - return w; -} - -long long __moddi3(long long u, long long v) -{ - int c = 0; - DWunion uu, vv; - DWtype w; - - uu.ll = u; - vv.ll = v; - - if (uu.s.high < 0) { - c = ~c; - uu.ll = __negdi2 (uu.ll); - } - if (vv.s.high < 0) - vv.ll = __negdi2 (vv.ll); - - __udivmoddi4 (uu.ll, vv.ll, (UDWtype *) &w); - if (c) - w = __negdi2 (w); - return w; -} - -unsigned long long __udivdi3(unsigned long long u, unsigned long long v) -{ - return __udivmoddi4 (u, v, (UDWtype *) 0); -} - -unsigned long long __umoddi3(unsigned long long u, unsigned long long v) -{ - UDWtype w; - - __udivmoddi4 (u, v, &w); - return w; -} - -/* XXX: fix tcc's code generator to do this instead */ -long long __ashrdi3(long long a, int b) -{ -#ifdef __TINYC__ - DWunion u; - u.ll = a; - if (b >= 32) { - u.s.low = u.s.high >> (b - 32); - u.s.high = u.s.high >> 31; - } else if (b != 0) { - u.s.low = ((unsigned)u.s.low >> b) | (u.s.high << (32 - b)); - u.s.high = u.s.high >> b; - } - return u.ll; -#else - return a >> b; -#endif -} - -/* XXX: fix tcc's code generator to do this instead */ -unsigned long long __lshrdi3(unsigned long long a, int b) -{ -#ifdef __TINYC__ - DWunion u; - u.ll = a; - if (b >= 32) { - u.s.low = (unsigned)u.s.high >> (b - 32); - u.s.high = 0; - } else if (b != 0) { - u.s.low = ((unsigned)u.s.low >> b) | (u.s.high << (32 - b)); - u.s.high = (unsigned)u.s.high >> b; - } - return u.ll; -#else - return a >> b; -#endif -} - -/* XXX: fix tcc's code generator to do this instead */ -long long __ashldi3(long long a, int b) -{ -#ifdef __TINYC__ - DWunion u; - u.ll = a; - if (b >= 32) { - u.s.high = (unsigned)u.s.low << (b - 32); - u.s.low = 0; - } else if (b != 0) { - u.s.high = ((unsigned)u.s.high << b) | ((unsigned)u.s.low >> (32 - b)); - u.s.low = (unsigned)u.s.low << b; - } - return u.ll; -#else - return a << b; -#endif -} - -#endif /* !__x86_64__ */ - -/* XXX: fix tcc's code generator to do this instead */ -float __floatundisf(unsigned long long a) -{ - DWunion uu; - XFtype r; - - uu.ll = a; - if (uu.s.high >= 0) { - return (float)uu.ll; - } else { - r = (XFtype)uu.ll; - r += 18446744073709551616.0; - return (float)r; - } -} - -double __floatundidf(unsigned long long a) -{ - DWunion uu; - XFtype r; - - uu.ll = a; - if (uu.s.high >= 0) { - return (double)uu.ll; - } else { - r = (XFtype)uu.ll; - r += 18446744073709551616.0; - return (double)r; - } -} - -long double __floatundixf(unsigned long long a) -{ - DWunion uu; - XFtype r; - - uu.ll = a; - if (uu.s.high >= 0) { - return (long double)uu.ll; - } else { - r = (XFtype)uu.ll; - r += 18446744073709551616.0; - return (long double)r; - } -} - -unsigned long long __fixunssfdi (float a1) -{ - register union float_long fl1; - register int exp; - register unsigned long long l; - - fl1.f = a1; - - if (fl1.l == 0) - return (0); - - exp = EXP (fl1.l) - EXCESS - 24; - l = MANT(fl1.l); - - if (exp >= 41) - return 1ULL << 63; - else if (exp >= 0) - l <<= exp; - else if (exp >= -23) - l >>= -exp; - else - return 0; - if (SIGN(fl1.l)) - l = (unsigned long long)-l; - return l; -} - -long long __fixsfdi (float a1) -{ - long long ret; int s; - ret = __fixunssfdi((s = a1 >= 0) ? a1 : -a1); - return s ? ret : -ret; -} - -unsigned long long __fixunsdfdi (double a1) -{ - register union double_long dl1; - register int exp; - register unsigned long long l; - - dl1.d = a1; - - if (dl1.ll == 0) - return (0); - - exp = EXPD (dl1) - EXCESSD - 53; - l = MANTD_LL(dl1); - - if (exp >= 12) - return 1ULL << 63; /* overflow result (like gcc, somewhat) */ - else if (exp >= 0) - l <<= exp; - else if (exp >= -52) - l >>= -exp; - else - return 0; - if (SIGND(dl1)) - l = (unsigned long long)-l; - return l; -} - -long long __fixdfdi (double a1) -{ - long long ret; int s; - ret = __fixunsdfdi((s = a1 >= 0) ? a1 : -a1); - return s ? ret : -ret; -} - -#ifndef __arm__ -unsigned long long __fixunsxfdi (long double a1) -{ - register union ldouble_long dl1; - register int exp; - register unsigned long long l; - - dl1.ld = a1; - - if (dl1.l.lower == 0 && dl1.l.upper == 0) - return (0); - - exp = EXPLD (dl1) - EXCESSLD - 64; - l = dl1.l.lower; - if (exp > 0) - return 1ULL << 63; - if (exp < -63) - return 0; - l >>= -exp; - if (SIGNLD(dl1)) - l = (unsigned long long)-l; - return l; -} - -long long __fixxfdi (long double a1) -{ - long long ret; int s; - ret = __fixunsxfdi((s = a1 >= 0) ? a1 : -a1); - return s ? ret : -ret; -} -#endif /* !ARM */ - -#if defined __x86_64__ -/* float constants used for unary minus operation */ -const float __mzerosf = -0.0; -const double __mzerodf = -0.0; -#endif - -#if defined _WIN64 -/* MSVC x64 intrinsic */ -void __faststorefence(void) -{ - __asm__("lock; orl $0,(%rsp)"); -} -#endif diff --git a/05/tcc-final/lib/stdatomic.c b/05/tcc-final/lib/stdatomic.c deleted file mode 100644 index eea7085..0000000 --- a/05/tcc-final/lib/stdatomic.c +++ /dev/null @@ -1,124 +0,0 @@ -// for libtcc1, avoid including files that are not part of tcc -// #include -#define uint8_t unsigned char -#define uint16_t unsigned short -#define uint32_t unsigned int -#define uint64_t unsigned long long -#define bool _Bool -#define true 1 -#define __ATOMIC_RELAXED 0 -#define __ATOMIC_CONSUME 1 -#define __ATOMIC_ACQUIRE 2 -#define __ATOMIC_RELEASE 3 -#define __ATOMIC_ACQ_REL 4 -#define __ATOMIC_SEQ_CST 5 - -#define ATOMIC_X86_COMPARE_EXCHANGE(TYPE, MODE, SUFFIX) \ - bool __atomic_compare_exchange_##MODE \ - (volatile void *atom, void *ref, TYPE xchg, \ - bool weak, int success_memorder, int failure_memorder) \ - { \ - TYPE rv; \ - TYPE cmp = *(TYPE *)ref; \ - asm volatile( \ - "lock cmpxchg" SUFFIX " %2,%1\n" \ - : "=a" (rv), "+m" (*(TYPE *)atom) \ - : "q" (xchg), "0" (cmp) \ - : "memory" \ - ); \ - *(TYPE *)ref = rv; \ - return (rv == cmp); \ - } - -#define ATOMIC_X86_LOAD(TYPE, MODE) \ - TYPE __atomic_load_##MODE(const volatile void *atom, int memorder) \ - { \ - return *(volatile TYPE *)atom; \ - } - -#define ATOMIC_X86_STORE(TYPE, MODE) \ - void __atomic_store_##MODE(volatile void *atom, TYPE value, int memorder) \ - { \ - *(volatile TYPE *)atom = value; \ - } - -/* Some tcc targets set __GNUC__ */ -#if defined(__GNUC__) && !defined(__TINYC__) -#define ATOMIC_LOAD(t,a,b,c) t b; __atomic_load((t *)a, (t *)&b, c) -#define COMPARE_EXCHANGE(t,a,b,c,d,e,f) __atomic_compare_exchange((t *)a,b,&c,d,e,f) -#else -#define ATOMIC_LOAD(t,a,b,c) t b = __atomic_load((t *)a, c) -#define COMPARE_EXCHANGE(t,a,b,c,d,e,f) __atomic_compare_exchange((t *)a,b,c,d,e,f) -#endif - -#define ATOMIC_GEN_OP(TYPE, MODE, NAME, OP) \ - TYPE __atomic_##NAME##_##MODE(volatile void *atom, TYPE value, int memorder) \ - { \ - TYPE xchg; \ - ATOMIC_LOAD(TYPE, atom, cmp, __ATOMIC_RELAXED); \ - do { \ - xchg = (OP); \ - } while (!COMPARE_EXCHANGE(TYPE, atom, &cmp, xchg, true, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)); \ - return cmp; \ - } - -#define ATOMIC_EXCHANGE(TYPE, MODE) \ - ATOMIC_GEN_OP(TYPE, MODE, exchange, value) -#define ATOMIC_FETCH_ADD(TYPE, MODE) \ - ATOMIC_GEN_OP(TYPE, MODE, fetch_add, (cmp + value)) -#define ATOMIC_FETCH_SUB(TYPE, MODE) \ - ATOMIC_GEN_OP(TYPE, MODE, fetch_sub, (cmp - value)) -#define ATOMIC_FETCH_AND(TYPE, MODE) \ - ATOMIC_GEN_OP(TYPE, MODE, fetch_and, (cmp & value)) -#define ATOMIC_FETCH_OR(TYPE, MODE) \ - ATOMIC_GEN_OP(TYPE, MODE, fetch_or, (cmp | value)) -#define ATOMIC_FETCH_XOR(TYPE, MODE) \ - ATOMIC_GEN_OP(TYPE, MODE, fetch_xor, (cmp ^ value)) - -ATOMIC_X86_STORE(uint8_t, 1) -ATOMIC_X86_STORE(uint16_t, 2) -ATOMIC_X86_STORE(uint32_t, 4) - -ATOMIC_X86_LOAD(uint8_t, 1) -ATOMIC_X86_LOAD(uint16_t, 2) -ATOMIC_X86_LOAD(uint32_t, 4) - -ATOMIC_X86_COMPARE_EXCHANGE(uint8_t, 1, "b") -ATOMIC_X86_COMPARE_EXCHANGE(uint16_t, 2, "w") -ATOMIC_X86_COMPARE_EXCHANGE(uint32_t, 4, "l") - -ATOMIC_EXCHANGE(uint8_t, 1) -ATOMIC_EXCHANGE(uint16_t, 2) -ATOMIC_EXCHANGE(uint32_t, 4) - -ATOMIC_FETCH_ADD(uint8_t, 1) -ATOMIC_FETCH_ADD(uint16_t, 2) -ATOMIC_FETCH_ADD(uint32_t, 4) - -ATOMIC_FETCH_SUB(uint8_t, 1) -ATOMIC_FETCH_SUB(uint16_t, 2) -ATOMIC_FETCH_SUB(uint32_t, 4) - -ATOMIC_FETCH_AND(uint8_t, 1) -ATOMIC_FETCH_AND(uint16_t, 2) -ATOMIC_FETCH_AND(uint32_t, 4) - -ATOMIC_FETCH_OR(uint8_t, 1) -ATOMIC_FETCH_OR(uint16_t, 2) -ATOMIC_FETCH_OR(uint32_t, 4) - -ATOMIC_FETCH_XOR(uint8_t, 1) -ATOMIC_FETCH_XOR(uint16_t, 2) -ATOMIC_FETCH_XOR(uint32_t, 4) - -#if defined __x86_64__ -ATOMIC_X86_STORE(uint64_t, 8) -ATOMIC_X86_LOAD(uint64_t, 8) -ATOMIC_X86_COMPARE_EXCHANGE(uint64_t, 8, "q") -ATOMIC_EXCHANGE(uint64_t, 8) -ATOMIC_FETCH_ADD(uint64_t, 8) -ATOMIC_FETCH_SUB(uint64_t, 8) -ATOMIC_FETCH_AND(uint64_t, 8) -ATOMIC_FETCH_OR(uint64_t, 8) -ATOMIC_FETCH_XOR(uint64_t, 8) -#endif diff --git a/05/tcc-final/lib/tcov.c b/05/tcc-final/lib/tcov.c deleted file mode 100644 index e5b9f22..0000000 --- a/05/tcc-final/lib/tcov.c +++ /dev/null @@ -1,428 +0,0 @@ -#include -#include -#include -#include -#ifndef _WIN32 -#include -#include -#else -#include -#include -#endif - -/* section layout (all little endian): - 32bit offset to executable/so file name - filename \0 - function name \0 - align to 64 bits - 64bit function start line - 64bits end_line(28bits) / start_line(28bits) / flag=0xff(8bits) - 64bits counter - \0 - \0 - \0 - executable/so file name \0 - */ - -typedef struct tcov_line { - unsigned int fline; - unsigned int lline; - unsigned long long count; -} tcov_line; - -typedef struct tcov_function { - char *function; - unsigned int first_line; - unsigned int n_line; - unsigned int m_line; - tcov_line *line; -} tcov_function; - -typedef struct tcov_file { - char *filename; - unsigned int n_func; - unsigned int m_func; - tcov_function *func; - struct tcov_file *next; -} tcov_file; - -static FILE *open_tcov_file (char *cov_filename) -{ - int fd; -#ifndef _WIN32 - struct flock lock; - - lock.l_type = F_WRLCK; - lock.l_whence = SEEK_SET; - lock.l_start = 0; - lock.l_len = 0; /* Until EOF. */ - lock.l_pid = getpid (); -#endif - fd = open (cov_filename, O_RDWR | O_CREAT, 0666); - if (fd < 0) - return NULL; - -#ifndef _WIN32 - while (fcntl (fd, F_SETLKW, &lock) && errno == EINTR) - continue; -#else - { - OVERLAPPED overlapped = { 0 }; - LockFileEx((HANDLE)_get_osfhandle(fd), LOCKFILE_EXCLUSIVE_LOCK, - 0, 1, 0, &overlapped); - } -#endif - - return fdopen (fd, "r+"); -} - -static unsigned long long get_value(unsigned char *p, int size) -{ - unsigned long long value = 0; - - p += size; - while (size--) - value = (value << 8) | *--p; - return value; -} - -static int sort_func (const void *p, const void *q) -{ - const tcov_function *pp = (const tcov_function *) p; - const tcov_function *pq = (const tcov_function *) q; - - return pp->first_line > pq->first_line ? 1 : - pp->first_line < pq->first_line ? -1 : 0; -} - -static int sort_line (const void *p, const void *q) -{ - const tcov_line *pp = (const tcov_line *) p; - const tcov_line *pq = (const tcov_line *) q; - - return pp->fline > pq->fline ? 1 : - pp->fline < pq->fline ? -1 : - pp->count < pq->count ? 1 : - pp->count > pq->count ? -1 : 0; -} - -/* sort to let inline functions work */ -static tcov_file *sort_test_coverage (unsigned char *p) -{ - int i, j, k; - unsigned char *start = p; - tcov_file *file = NULL; - tcov_file *nfile; - - p += 4; - while (*p) { - char *filename = (char *)p; - size_t len = strlen (filename); - - nfile = file; - while (nfile) { - if (strcmp (nfile->filename, filename) == 0) - break; - nfile = nfile->next; - } - if (nfile == NULL) { - nfile = malloc (sizeof(tcov_file)); - if (nfile == NULL) { - fprintf (stderr, "Malloc error test_coverage\n"); - return file; - } - nfile->filename = filename; - nfile->n_func = 0; - nfile->m_func = 0; - nfile->func = NULL; - nfile->next = NULL; - if (file == NULL) - file = nfile; - else { - tcov_file *lfile = file; - - while (lfile->next) - lfile = lfile->next; - lfile->next = nfile; - } - } - p += len + 1; - while (*p) { - int i; - char *function = (char *)p; - tcov_function *func; - - p += strlen (function) + 1; - p += -(p - start) & 7; - for (i = 0; i < nfile->n_func; i++) { - func = &nfile->func[i]; - if (strcmp (func->function, function) == 0) - break; - } - if (i == nfile->n_func) { - if (nfile->n_func >= nfile->m_func) { - nfile->m_func = nfile->m_func == 0 ? 4 : nfile->m_func * 2; - nfile->func = realloc (nfile->func, - nfile->m_func * - sizeof (tcov_function)); - if (nfile->func == NULL) { - fprintf (stderr, "Realloc error test_coverage\n"); - return file; - } - } - func = &nfile->func[nfile->n_func++]; - func->function = function; - func->first_line = get_value (p, 8); - func->n_line = 0; - func->m_line = 0; - func->line = NULL; - } - p += 8; - while (*p) { - tcov_line *line; - unsigned long long val; - - if (func->n_line >= func->m_line) { - func->m_line = func->m_line == 0 ? 4 : func->m_line * 2; - func->line = realloc (func->line, - func->m_line * sizeof (tcov_line)); - if (func->line == NULL) { - fprintf (stderr, "Realloc error test_coverage\n"); - return file; - } - } - line = &func->line[func->n_line++]; - val = get_value (p, 8); - line->fline = (val >> 8) & 0xfffffffULL; - line->lline = val >> 36; - line->count = get_value (p + 8, 8); - p += 16; - } - p++; - } - p++; - } - nfile = file; - while (nfile) { - qsort (nfile->func, nfile->n_func, sizeof (tcov_function), sort_func); - for (i = 0; i < nfile->n_func; i++) { - tcov_function *func = &nfile->func[i]; - qsort (func->line, func->n_line, sizeof (tcov_line), sort_line); - } - nfile = nfile->next; - } - return file; -} - -/* merge with previous tcov file */ -static void merge_test_coverage (tcov_file *file, FILE *fp, - unsigned int *pruns) -{ - unsigned int runs; - char *p; - char str[10000]; - - *pruns = 1; - if (fp == NULL) - return; - if (fgets(str, sizeof(str), fp) && - (p = strrchr (str, ':')) && - (sscanf (p + 1, "%u", &runs) == 1)) - *pruns = runs + 1; - while (file) { - int i; - size_t len = strlen (file->filename); - - while (fgets(str, sizeof(str), fp) && - (p = strstr(str, "0:File:")) == NULL); - if ((p = strstr(str, "0:File:")) == NULL || - strncmp (p + strlen("0:File:"), file->filename, len) != 0 || - p[strlen("0:File:") + len] != ' ') - break; - for (i = 0; i < file->n_func; i++) { - int j; - tcov_function *func = &file->func[i]; - unsigned int next_zero = 0; - unsigned int curline = 0; - - for (j = 0; j < func->n_line; j++) { - tcov_line *line = &func->line[j]; - unsigned int fline = line->fline; - unsigned long long count; - unsigned int tmp; - char c; - - while (curline < fline && - fgets(str, sizeof(str), fp)) - if ((p = strchr(str, ':')) && - sscanf (p + 1, "%u", &tmp) == 1) - curline = tmp; - if (sscanf (str, "%llu%c\n", &count, &c) == 2) { - if (next_zero == 0) - line->count += count; - next_zero = c == '*'; - } - } - } - file = file->next; - } -} - -/* store tcov data in file */ -void __store_test_coverage (unsigned char * p) -{ - int i, j; - unsigned int files; - unsigned int funcs; - unsigned int blocks; - unsigned int blocks_run; - unsigned int runs; - char *cov_filename = (char *)p + get_value (p, 4); - FILE *fp; - char *q; - tcov_file *file; - tcov_file *nfile; - tcov_function *func; - - fp = open_tcov_file (cov_filename); - if (fp == NULL) { - fprintf (stderr, "Cannot create coverage file: %s\n", cov_filename); - return; - } - file = sort_test_coverage (p); - merge_test_coverage (file, fp, &runs); - fseek (fp, 0, SEEK_SET); - fprintf (fp, " -: 0:Runs:%u\n", runs); - files = 0; - funcs = 0; - blocks = 0; - blocks_run = 0; - nfile = file; - while (nfile) { - files++; - for (i = 0; i < nfile->n_func; i++) { - func = &nfile->func[i]; - funcs++; - for (j = 0; j < func->n_line; j++) { - blocks++; - blocks_run += func->line[j].count != 0; - } - } - nfile = nfile->next; - } - if (blocks == 0) - blocks = 1; - fprintf (fp, " -: 0:All:%s Files:%u Functions:%u %.02f%%\n", - cov_filename, files, funcs, 100.0 * (double) blocks_run / blocks); - nfile = file; - while (nfile) { - FILE *src = fopen (nfile->filename, "r"); - unsigned int curline = 1; - char str[10000]; - - if (src == NULL) - goto next; - funcs = 0; - blocks = 0; - blocks_run = 0; - for (i = 0; i < nfile->n_func; i++) { - func = &nfile->func[i]; - funcs++; - for (j = 0; j < func->n_line; j++) { - blocks++; - blocks_run += func->line[j].count != 0; - } - } - if (blocks == 0) - blocks = 1; - fprintf (fp, " -: 0:File:%s Functions:%u %.02f%%\n", - nfile->filename, funcs, 100.0 * (double) blocks_run / blocks); - for (i = 0; i < nfile->n_func; i++) { - func = &nfile->func[i]; - - while (curline < func->first_line) - if (fgets(str, sizeof(str), src)) - fprintf (fp, " -:%5u:%s", curline++, str); - blocks = 0; - blocks_run = 0; - for (j = 0; j < func->n_line; j++) { - blocks++; - blocks_run += func->line[j].count != 0; - } - if (blocks == 0) - blocks = 1; - fprintf (fp, " -: 0:Function:%s %.02f%%\n", - func->function, 100.0 * (double) blocks_run / blocks); -#if 0 - for (j = 0; j < func->n_line; j++) { - unsigned int fline = func->line[j].fline; - unsigned int lline = func->line[j].lline; - unsigned long long count = func->line[j].count; - - fprintf (fp, "%u %u %llu\n", fline, lline, count); - } -#endif - for (j = 0; j < func->n_line;) { - unsigned int fline = func->line[j].fline; - unsigned int lline = func->line[j].lline; - unsigned long long count = func->line[j].count; - unsigned int has_zero = 0; - unsigned int same_line = fline == lline; - - j++; - while (j < func->n_line) { - unsigned int nfline = func->line[j].fline; - unsigned int nlline = func->line[j].lline; - unsigned long long ncount = func->line[j].count; - - if (fline == nfline) { - if (ncount == 0) - has_zero = 1; - else if (ncount > count) - count = ncount; - same_line = nfline == nlline; - lline = nlline; - j++; - } - else - break; - } - if (same_line) - lline++; - - while (curline < fline) - if (fgets(str, sizeof(str), src)) - fprintf (fp, " -:%5u:%s", curline++, str); - while (curline < lline && - fgets(str, sizeof(str), src)) { - if (count == 0) - fprintf (fp, " #####:%5u:%s", - curline, str); - else if (has_zero) - fprintf (fp, "%8llu*:%5u:%s", - count, curline, str); - else - fprintf (fp, "%9llu:%5u:%s", - count, curline, str); - curline++; - } - } - } - while (fgets(str, sizeof(str), src)) - fprintf (fp, " -:%5u:%s", curline++, str); - fclose (src); -next: - nfile = nfile->next; - } - while (file) { - for (i = 0; i < file->n_func; i++) { - func = &file->func[i]; - free (func->line); - } - free (file->func); - nfile = file; - file = file->next; - free (nfile); - } - fclose (fp); -} diff --git a/05/tcc-final/lib/va_list.c b/05/tcc-final/lib/va_list.c deleted file mode 100644 index 1fb5512..0000000 --- a/05/tcc-final/lib/va_list.c +++ /dev/null @@ -1,67 +0,0 @@ -/* va_list.c - tinycc support for va_list on X86_64 */ - -#if defined __x86_64__ - -/* Avoid include files, they may not be available when cross compiling */ -extern void abort(void); - -/* This should be in sync with our include/stdarg.h */ -enum __va_arg_type { - __va_gen_reg, __va_float_reg, __va_stack -}; - -/* GCC compatible definition of va_list. */ -/*predefined by TCC (tcc_predefs.h): -typedef struct { - unsigned int gp_offset; - unsigned int fp_offset; - union { - unsigned int overflow_offset; - char *overflow_arg_area; - }; - char *reg_save_area; -} __builtin_va_list[1]; -*/ - -extern void *memcpy(void *dest, const void *src, unsigned long n); - -void *__va_arg(__builtin_va_list ap, - int arg_type, - int size, int align) -{ - size = (size + 7) & ~7; - align = (align + 7) & ~7; - switch ((enum __va_arg_type)arg_type) { - case __va_gen_reg: - if (ap->gp_offset + size <= 48) { - ap->gp_offset += size; - return ap->reg_save_area + ap->gp_offset - size; - } - goto use_overflow_area; - - case __va_float_reg: - if (ap->fp_offset < 128 + 48) { - ap->fp_offset += 16; - if (size == 8) - return ap->reg_save_area + ap->fp_offset - 16; - if (ap->fp_offset < 128 + 48) { - memcpy(ap->reg_save_area + ap->fp_offset - 8, - ap->reg_save_area + ap->fp_offset, 8); - ap->fp_offset += 16; - return ap->reg_save_area + ap->fp_offset - 32; - } - } - goto use_overflow_area; - - case __va_stack: - use_overflow_area: - ap->overflow_arg_area += size; - ap->overflow_arg_area = (char*)((long long)(ap->overflow_arg_area + align - 1) & -align); - return ap->overflow_arg_area - size; - - default: /* should never happen */ - abort(); - return 0; - } -} -#endif diff --git a/05/tcc-final/libtcc.c b/05/tcc-final/libtcc.c deleted file mode 100644 index 59f846c..0000000 --- a/05/tcc-final/libtcc.c +++ /dev/null @@ -1,2049 +0,0 @@ -/* - * TCC - Tiny C Compiler - * - * Copyright (c) 2001-2004 Fabrice Bellard - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#if !defined ONE_SOURCE || ONE_SOURCE -#include "tccpp.c" -#include "tccgen.c" -#include "tccdbg.c" -#include "tccasm.c" -#include "tccelf.c" -#include "tccrun.c" -#ifdef TCC_TARGET_I386 -#include "i386-gen.c" -#include "i386-link.c" -#include "i386-asm.c" -#elif defined(TCC_TARGET_ARM) -#include "arm-gen.c" -#include "arm-link.c" -#include "arm-asm.c" -#elif defined(TCC_TARGET_ARM64) -#include "arm64-gen.c" -#include "arm64-link.c" -#include "arm-asm.c" -#elif defined(TCC_TARGET_C67) -#include "c67-gen.c" -#include "c67-link.c" -#include "tcccoff.c" -#elif defined(TCC_TARGET_X86_64) -#include "x86_64-gen.c" -#include "x86_64-link.c" -#include "i386-asm.c" -#elif defined(TCC_TARGET_RISCV64) -#include "riscv64-gen.c" -#include "riscv64-link.c" -#include "riscv64-asm.c" -#else -#error unknown target -#endif -#ifdef TCC_TARGET_PE -#include "tccpe.c" -#endif -#ifdef TCC_TARGET_MACHO -#include "tccmacho.c" -#endif -#endif /* ONE_SOURCE */ - -#include "tcc.h" - -/********************************************************/ -/* global variables */ - -/* XXX: get rid of this ASAP (or maybe not) */ -ST_DATA struct TCCState *tcc_state; -TCC_SEM(static tcc_compile_sem); - -#ifdef MEM_DEBUG -static int nb_states; -#endif - -/********************************************************/ -#ifdef _WIN32 -ST_FUNC char *normalize_slashes(char *path) -{ - char *p; - for (p = path; *p; ++p) - if (*p == '\\') - *p = '/'; - return path; -} - -#if defined LIBTCC_AS_DLL && !defined CONFIG_TCCDIR -static HMODULE tcc_module; -BOOL WINAPI DllMain (HINSTANCE hDll, DWORD dwReason, LPVOID lpReserved) -{ - if (DLL_PROCESS_ATTACH == dwReason) - tcc_module = hDll; - return TRUE; -} -#else -#define tcc_module NULL /* NULL means executable itself */ -#endif - -#ifndef CONFIG_TCCDIR -/* on win32, we suppose the lib and includes are at the location of 'tcc.exe' */ -static inline char *config_tccdir_w32(char *path) -{ - char *p; - GetModuleFileName(tcc_module, path, MAX_PATH); - p = tcc_basename(normalize_slashes(strlwr(path))); - if (p > path) - --p; - *p = 0; - return path; -} -#define CONFIG_TCCDIR config_tccdir_w32(alloca(MAX_PATH)) -#endif - -#ifdef TCC_TARGET_PE -static void tcc_add_systemdir(TCCState *s) -{ - char buf[1000]; - GetSystemDirectory(buf, sizeof buf); - tcc_add_library_path(s, normalize_slashes(buf)); -} -#endif -#endif - -/********************************************************/ -#if CONFIG_TCC_SEMLOCK -#if defined _WIN32 -ST_FUNC void wait_sem(TCCSem *p) -{ - if (!p->init) - InitializeCriticalSection(&p->cr), p->init = 1; - EnterCriticalSection(&p->cr); -} -ST_FUNC void post_sem(TCCSem *p) -{ - LeaveCriticalSection(&p->cr); -} -#elif defined __APPLE__ -/* Half-compatible MacOS doesn't have non-shared (process local) - semaphores. Use the dispatch framework for lightweight locks. */ -ST_FUNC void wait_sem(TCCSem *p) -{ - if (!p->init) - p->sem = dispatch_semaphore_create(1), p->init = 1; - dispatch_semaphore_wait(p->sem, DISPATCH_TIME_FOREVER); -} -ST_FUNC void post_sem(TCCSem *p) -{ - dispatch_semaphore_signal(p->sem); -} -#else -ST_FUNC void wait_sem(TCCSem *p) -{ - if (!p->init) - sem_init(&p->sem, 0, 1), p->init = 1; - while (sem_wait(&p->sem) < 0 && errno == EINTR); -} -ST_FUNC void post_sem(TCCSem *p) -{ - sem_post(&p->sem); -} -#endif -#endif - -PUB_FUNC void tcc_enter_state(TCCState *s1) -{ - if (s1->error_set_jmp_enabled) - return; - WAIT_SEM(&tcc_compile_sem); - tcc_state = s1; -} - -PUB_FUNC void tcc_exit_state(TCCState *s1) -{ - if (s1->error_set_jmp_enabled) - return; - tcc_state = NULL; - POST_SEM(&tcc_compile_sem); -} - -/********************************************************/ -/* copy a string and truncate it. */ -ST_FUNC char *pstrcpy(char *buf, size_t buf_size, const char *s) -{ - char *q, *q_end; - int c; - - if (buf_size > 0) { - q = buf; - q_end = buf + buf_size - 1; - while (q < q_end) { - c = *s++; - if (c == '\0') - break; - *q++ = c; - } - *q = '\0'; - } - return buf; -} - -/* strcat and truncate. */ -ST_FUNC char *pstrcat(char *buf, size_t buf_size, const char *s) -{ - size_t len; - len = strlen(buf); - if (len < buf_size) - pstrcpy(buf + len, buf_size - len, s); - return buf; -} - -ST_FUNC char *pstrncpy(char *out, const char *in, size_t num) -{ - memcpy(out, in, num); - out[num] = '\0'; - return out; -} - -/* extract the basename of a file */ -PUB_FUNC char *tcc_basename(const char *name) -{ - char *p = strchr(name, 0); - while (p > name && !IS_DIRSEP(p[-1])) - --p; - return p; -} - -/* extract extension part of a file - * - * (if no extension, return pointer to end-of-string) - */ -PUB_FUNC char *tcc_fileextension (const char *name) -{ - char *b = tcc_basename(name); - char *e = strrchr(b, '.'); - return e ? e : strchr(b, 0); -} - -ST_FUNC char *tcc_load_text(int fd) -{ - int len = lseek(fd, 0, SEEK_END); - char *buf = load_data(fd, 0, len + 1); - buf[len] = 0; - return buf; -} - -/********************************************************/ -/* memory management */ - -#undef free -#undef malloc -#undef realloc - -#ifndef MEM_DEBUG - -PUB_FUNC void tcc_free(void *ptr) -{ - free(ptr); -} - -PUB_FUNC void *tcc_malloc(unsigned long size) -{ - void *ptr; - ptr = malloc(size); - if (!ptr && size) - _tcc_error("memory full (malloc)"); - return ptr; -} - -PUB_FUNC void *tcc_mallocz(unsigned long size) -{ - void *ptr; - ptr = tcc_malloc(size); - if (size) - memset(ptr, 0, size); - return ptr; -} - -PUB_FUNC void *tcc_realloc(void *ptr, unsigned long size) -{ - void *ptr1; - ptr1 = realloc(ptr, size); - if (!ptr1 && size) - _tcc_error("memory full (realloc)"); - return ptr1; -} - -PUB_FUNC char *tcc_strdup(const char *str) -{ - char *ptr; - ptr = tcc_malloc(strlen(str) + 1); - strcpy(ptr, str); - return ptr; -} - -#else - -#define MEM_DEBUG_MAGIC1 0xFEEDDEB1 -#define MEM_DEBUG_MAGIC2 0xFEEDDEB2 -#define MEM_DEBUG_MAGIC3 0xFEEDDEB3 -#define MEM_DEBUG_FILE_LEN 40 -#define MEM_DEBUG_CHECK3(header) \ - ((mem_debug_header_t*)((char*)header + header->size))->magic3 -#define MEM_USER_PTR(header) \ - ((char *)header + offsetof(mem_debug_header_t, magic3)) -#define MEM_HEADER_PTR(ptr) \ - (mem_debug_header_t *)((char*)ptr - offsetof(mem_debug_header_t, magic3)) - -struct mem_debug_header { - unsigned magic1; - unsigned size; - struct mem_debug_header *prev; - struct mem_debug_header *next; - int line_num; - char file_name[MEM_DEBUG_FILE_LEN + 1]; - unsigned magic2; - ALIGNED(16) unsigned char magic3[4]; -}; - -typedef struct mem_debug_header mem_debug_header_t; - -static mem_debug_header_t *mem_debug_chain; -static unsigned mem_cur_size; -static unsigned mem_max_size; - -static mem_debug_header_t *malloc_check(void *ptr, const char *msg) -{ - mem_debug_header_t * header = MEM_HEADER_PTR(ptr); - if (header->magic1 != MEM_DEBUG_MAGIC1 || - header->magic2 != MEM_DEBUG_MAGIC2 || - read32le(MEM_DEBUG_CHECK3(header)) != MEM_DEBUG_MAGIC3 || - header->size == (unsigned)-1) { - fprintf(stderr, "%s check failed\n", msg); - if (header->magic1 == MEM_DEBUG_MAGIC1) - fprintf(stderr, "%s:%u: block allocated here.\n", - header->file_name, header->line_num); - exit(1); - } - return header; -} - -PUB_FUNC void *tcc_malloc_debug(unsigned long size, const char *file, int line) -{ - int ofs; - mem_debug_header_t *header; - - header = malloc(sizeof(mem_debug_header_t) + size); - if (!header) - _tcc_error("memory full (malloc)"); - - header->magic1 = MEM_DEBUG_MAGIC1; - header->magic2 = MEM_DEBUG_MAGIC2; - header->size = size; - write32le(MEM_DEBUG_CHECK3(header), MEM_DEBUG_MAGIC3); - header->line_num = line; - ofs = strlen(file) - MEM_DEBUG_FILE_LEN; - strncpy(header->file_name, file + (ofs > 0 ? ofs : 0), MEM_DEBUG_FILE_LEN); - header->file_name[MEM_DEBUG_FILE_LEN] = 0; - - header->next = mem_debug_chain; - header->prev = NULL; - if (header->next) - header->next->prev = header; - mem_debug_chain = header; - - mem_cur_size += size; - if (mem_cur_size > mem_max_size) - mem_max_size = mem_cur_size; - - return MEM_USER_PTR(header); -} - -PUB_FUNC void tcc_free_debug(void *ptr) -{ - mem_debug_header_t *header; - if (!ptr) - return; - header = malloc_check(ptr, "tcc_free"); - mem_cur_size -= header->size; - header->size = (unsigned)-1; - if (header->next) - header->next->prev = header->prev; - if (header->prev) - header->prev->next = header->next; - if (header == mem_debug_chain) - mem_debug_chain = header->next; - free(header); -} - -PUB_FUNC void *tcc_mallocz_debug(unsigned long size, const char *file, int line) -{ - void *ptr; - ptr = tcc_malloc_debug(size,file,line); - memset(ptr, 0, size); - return ptr; -} - -PUB_FUNC void *tcc_realloc_debug(void *ptr, unsigned long size, const char *file, int line) -{ - mem_debug_header_t *header; - int mem_debug_chain_update = 0; - if (!ptr) - return tcc_malloc_debug(size, file, line); - header = malloc_check(ptr, "tcc_realloc"); - mem_cur_size -= header->size; - mem_debug_chain_update = (header == mem_debug_chain); - header = realloc(header, sizeof(mem_debug_header_t) + size); - if (!header) - _tcc_error("memory full (realloc)"); - header->size = size; - write32le(MEM_DEBUG_CHECK3(header), MEM_DEBUG_MAGIC3); - if (header->next) - header->next->prev = header; - if (header->prev) - header->prev->next = header; - if (mem_debug_chain_update) - mem_debug_chain = header; - mem_cur_size += size; - if (mem_cur_size > mem_max_size) - mem_max_size = mem_cur_size; - return MEM_USER_PTR(header); -} - -PUB_FUNC char *tcc_strdup_debug(const char *str, const char *file, int line) -{ - char *ptr; - ptr = tcc_malloc_debug(strlen(str) + 1, file, line); - strcpy(ptr, str); - return ptr; -} - -PUB_FUNC void tcc_memcheck(void) -{ - if (mem_cur_size) { - mem_debug_header_t *header = mem_debug_chain; - fprintf(stderr, "MEM_DEBUG: mem_leak= %d bytes, mem_max_size= %d bytes\n", - mem_cur_size, mem_max_size); - while (header) { - fprintf(stderr, "%s:%u: error: %u bytes leaked\n", - header->file_name, header->line_num, header->size); - header = header->next; - } -#if MEM_DEBUG-0 == 2 - exit(2); -#endif - } -} -#endif /* MEM_DEBUG */ - -#define free(p) use_tcc_free(p) -#define malloc(s) use_tcc_malloc(s) -#define realloc(p, s) use_tcc_realloc(p, s) - -/********************************************************/ -/* dynarrays */ - -ST_FUNC void dynarray_add(void *ptab, int *nb_ptr, void *data) -{ - int nb, nb_alloc; - void **pp; - - nb = *nb_ptr; - pp = *(void ***)ptab; - /* every power of two we double array size */ - if ((nb & (nb - 1)) == 0) { - if (!nb) - nb_alloc = 1; - else - nb_alloc = nb * 2; - pp = tcc_realloc(pp, nb_alloc * sizeof(void *)); - *(void***)ptab = pp; - } - pp[nb++] = data; - *nb_ptr = nb; -} - -ST_FUNC void dynarray_reset(void *pp, int *n) -{ - void **p; - for (p = *(void***)pp; *n; ++p, --*n) - if (*p) - tcc_free(*p); - tcc_free(*(void**)pp); - *(void**)pp = NULL; -} - -static void tcc_split_path(TCCState *s, void *p_ary, int *p_nb_ary, const char *in) -{ - const char *p; - do { - int c; - CString str; - - cstr_new(&str); - for (p = in; c = *p, c != '\0' && c != PATHSEP[0]; ++p) { - if (c == '{' && p[1] && p[2] == '}') { - c = p[1], p += 2; - if (c == 'B') - cstr_cat(&str, s->tcc_lib_path, -1); - if (c == 'f' && file) { - /* substitute current file's dir */ - const char *f = file->true_filename; - const char *b = tcc_basename(f); - if (b > f) - cstr_cat(&str, f, b - f - 1); - else - cstr_cat(&str, ".", 1); - } - } else { - cstr_ccat(&str, c); - } - } - if (str.size) { - cstr_ccat(&str, '\0'); - dynarray_add(p_ary, p_nb_ary, tcc_strdup(str.data)); - } - cstr_free(&str); - in = p+1; - } while (*p); -} - -/********************************************************/ -/* warning / error */ - -/* warn_... option bits */ -#define WARN_ON 1 /* warning is on (-Woption) */ -#define WARN_ERR 2 /* warning is an error (-Werror=option) */ -#define WARN_NOE 4 /* warning is not an error (-Wno-error=option) */ - -/* error1() modes */ -enum { ERROR_WARN, ERROR_NOABORT, ERROR_ERROR }; - -static void error1(int mode, const char *fmt, va_list ap) -{ - BufferedFile **pf, *f; - TCCState *s1 = tcc_state; - CString cs; - - cstr_new(&cs); - - if (s1 == NULL) - /* can happen only if called from tcc_malloc(): 'out of memory' */ - goto no_file; - - tcc_exit_state(s1); - - if (mode == ERROR_WARN) { - if (s1->warn_error) - mode = ERROR_ERROR; - if (s1->warn_num) { - /* handle tcc_warning_c(warn_option)(fmt, ...) */ - int wopt = *(&s1->warn_none + s1->warn_num); - s1->warn_num = 0; - if (0 == (wopt & WARN_ON)) - return; - if (wopt & WARN_ERR) - mode = ERROR_ERROR; - if (wopt & WARN_NOE) - mode = ERROR_WARN; - } - if (s1->warn_none) - return; - } - - f = NULL; - if (s1->error_set_jmp_enabled) { /* we're called while parsing a file */ - /* use upper file if inline ":asm:" or token ":paste:" */ - for (f = file; f && f->filename[0] == ':'; f = f->prev) - ; - } - if (f) { - for(pf = s1->include_stack; pf < s1->include_stack_ptr; pf++) - cstr_printf(&cs, "In file included from %s:%d:\n", - (*pf)->filename, (*pf)->line_num); - cstr_printf(&cs, "%s:%d: ", - f->filename, f->line_num - !!(tok_flags & TOK_FLAG_BOL)); - } else if (s1->current_filename) { - cstr_printf(&cs, "%s: ", s1->current_filename); - } - -no_file: - if (0 == cs.size) - cstr_printf(&cs, "tcc: "); - cstr_printf(&cs, mode == ERROR_WARN ? "warning: " : "error: "); - cstr_vprintf(&cs, fmt, ap); - if (!s1 || !s1->error_func) { - /* default case: stderr */ - if (s1 && s1->output_type == TCC_OUTPUT_PREPROCESS && s1->ppfp == stdout) - printf("\n"); /* print a newline during tcc -E */ - fflush(stdout); /* flush -v output */ - fprintf(stderr, "%s\n", (char*)cs.data); - fflush(stderr); /* print error/warning now (win32) */ - } else { - s1->error_func(s1->error_opaque, (char*)cs.data); - } - cstr_free(&cs); - if (s1) { - if (mode != ERROR_WARN) - s1->nb_errors++; - if (mode != ERROR_ERROR) - return; - if (s1->error_set_jmp_enabled) - longjmp(s1->error_jmp_buf, 1); - } - exit(1); -} - -LIBTCCAPI void tcc_set_error_func(TCCState *s, void *error_opaque, TCCErrorFunc error_func) -{ - s->error_opaque = error_opaque; - s->error_func = error_func; -} - -LIBTCCAPI TCCErrorFunc tcc_get_error_func(TCCState *s) -{ - return s->error_func; -} - -LIBTCCAPI void *tcc_get_error_opaque(TCCState *s) -{ - return s->error_opaque; -} - -/* error without aborting current compilation */ -PUB_FUNC void _tcc_error_noabort(const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - error1(ERROR_NOABORT, fmt, ap); - va_end(ap); -} - -PUB_FUNC void _tcc_error(const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - for (;;) error1(ERROR_ERROR, fmt, ap); -} - -PUB_FUNC void _tcc_warning(const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - error1(ERROR_WARN, fmt, ap); - va_end(ap); -} - -/********************************************************/ -/* I/O layer */ - -ST_FUNC void tcc_open_bf(TCCState *s1, const char *filename, int initlen) -{ - BufferedFile *bf; - int buflen = initlen ? initlen : IO_BUF_SIZE; - - bf = tcc_mallocz(sizeof(BufferedFile) + buflen); - bf->buf_ptr = bf->buffer; - bf->buf_end = bf->buffer + initlen; - bf->buf_end[0] = CH_EOB; /* put eob symbol */ - pstrcpy(bf->filename, sizeof(bf->filename), filename); -#ifdef _WIN32 - normalize_slashes(bf->filename); -#endif - bf->true_filename = bf->filename; - bf->line_num = 1; - bf->ifdef_stack_ptr = s1->ifdef_stack_ptr; - bf->fd = -1; - bf->prev = file; - file = bf; - tok_flags = TOK_FLAG_BOL | TOK_FLAG_BOF; -} - -ST_FUNC void tcc_close(void) -{ - TCCState *s1 = tcc_state; - BufferedFile *bf = file; - if (bf->fd > 0) { - close(bf->fd); - total_lines += bf->line_num; - } - if (bf->true_filename != bf->filename) - tcc_free(bf->true_filename); - file = bf->prev; - tcc_free(bf); -} - -static int _tcc_open(TCCState *s1, const char *filename) -{ - int fd; - if (strcmp(filename, "-") == 0) - fd = 0, filename = ""; - else - fd = open(filename, O_RDONLY | O_BINARY); - if ((s1->verbose == 2 && fd >= 0) || s1->verbose == 3) - printf("%s %*s%s\n", fd < 0 ? "nf":"->", - (int)(s1->include_stack_ptr - s1->include_stack), "", filename); - return fd; -} - -ST_FUNC int tcc_open(TCCState *s1, const char *filename) -{ - int fd = _tcc_open(s1, filename); - if (fd < 0) - return -1; - tcc_open_bf(s1, filename, 0); - file->fd = fd; - return 0; -} - -/* compile the file opened in 'file'. Return non zero if errors. */ -static int tcc_compile(TCCState *s1, int filetype, const char *str, int fd) -{ - /* Here we enter the code section where we use the global variables for - parsing and code generation (tccpp.c, tccgen.c, -gen.c). - Other threads need to wait until we're done. - - Alternatively we could use thread local storage for those global - variables, which may or may not have advantages */ - - tcc_enter_state(s1); - s1->error_set_jmp_enabled = 1; - - if (setjmp(s1->error_jmp_buf) == 0) { - s1->nb_errors = 0; - - if (fd == -1) { - int len = strlen(str); - tcc_open_bf(s1, "", len); - memcpy(file->buffer, str, len); - } else { - tcc_open_bf(s1, str, 0); - file->fd = fd; - } - - tccelf_begin_file(s1); - preprocess_start(s1, filetype); - tccgen_init(s1); - if (s1->output_type == TCC_OUTPUT_PREPROCESS) { - tcc_preprocess(s1); - } else if (filetype & (AFF_TYPE_ASM | AFF_TYPE_ASMPP)) { - tcc_assemble(s1, !!(filetype & AFF_TYPE_ASMPP)); - } else { - tccgen_compile(s1); - } - } - tccgen_finish(s1); - preprocess_end(s1); - - s1->error_set_jmp_enabled = 0; - tcc_exit_state(s1); - - tccelf_end_file(s1); - return s1->nb_errors != 0 ? -1 : 0; -} - -LIBTCCAPI int tcc_compile_string(TCCState *s, const char *str) -{ - return tcc_compile(s, s->filetype, str, -1); -} - -/* define a preprocessor symbol. value can be NULL, sym can be "sym=val" */ -LIBTCCAPI void tcc_define_symbol(TCCState *s1, const char *sym, const char *value) -{ - const char *eq; - if (NULL == (eq = strchr(sym, '='))) - eq = strchr(sym, 0); - if (NULL == value) - value = *eq ? eq + 1 : "1"; - cstr_printf(&s1->cmdline_defs, "#define %.*s %s\n", (int)(eq-sym), sym, value); -} - -/* undefine a preprocessor symbol */ -LIBTCCAPI void tcc_undefine_symbol(TCCState *s1, const char *sym) -{ - cstr_printf(&s1->cmdline_defs, "#undef %s\n", sym); -} - - -LIBTCCAPI TCCState *tcc_new(void) -{ - TCCState *s; - - s = tcc_mallocz(sizeof(TCCState)); - if (!s) - return NULL; -#ifdef MEM_DEBUG - ++nb_states; -#endif - -#undef gnu_ext - - s->gnu_ext = 1; - s->tcc_ext = 1; - s->nocommon = 1; - s->dollars_in_identifiers = 1; /*on by default like in gcc/clang*/ - s->cversion = 199901; /* default unless -std=c11 is supplied */ - s->warn_implicit_function_declaration = 1; - s->warn_discarded_qualifiers = 1; - s->ms_extensions = 1; - -#ifdef CHAR_IS_UNSIGNED - s->char_is_unsigned = 1; -#endif -#ifdef TCC_TARGET_I386 - s->seg_size = 32; -#endif - /* enable this if you want symbols with leading underscore on windows: */ -#if defined TCC_TARGET_MACHO /* || defined TCC_TARGET_PE */ - s->leading_underscore = 1; -#endif -#ifdef TCC_TARGET_ARM - s->float_abi = ARM_FLOAT_ABI; -#endif - - s->ppfp = stdout; - /* might be used in error() before preprocess_start() */ - s->include_stack_ptr = s->include_stack; - - tccelf_new(s); - - tcc_set_lib_path(s, CONFIG_TCCDIR); - return s; -} - -LIBTCCAPI void tcc_delete(TCCState *s1) -{ - /* free sections */ - tccelf_delete(s1); - - /* free library paths */ - dynarray_reset(&s1->library_paths, &s1->nb_library_paths); - dynarray_reset(&s1->crt_paths, &s1->nb_crt_paths); - - /* free include paths */ - dynarray_reset(&s1->include_paths, &s1->nb_include_paths); - dynarray_reset(&s1->sysinclude_paths, &s1->nb_sysinclude_paths); - - tcc_free(s1->tcc_lib_path); - tcc_free(s1->soname); - tcc_free(s1->rpath); - tcc_free(s1->elf_entryname); - tcc_free(s1->init_symbol); - tcc_free(s1->fini_symbol); - tcc_free(s1->outfile); - tcc_free(s1->deps_outfile); - dynarray_reset(&s1->files, &s1->nb_files); - dynarray_reset(&s1->target_deps, &s1->nb_target_deps); - dynarray_reset(&s1->pragma_libs, &s1->nb_pragma_libs); - dynarray_reset(&s1->argv, &s1->argc); - cstr_free(&s1->cmdline_defs); - cstr_free(&s1->cmdline_incl); -#ifdef TCC_IS_NATIVE - /* free runtime memory */ - tcc_run_free(s1); -#endif - tcc_free(s1->dState); - tcc_free(s1); -#ifdef MEM_DEBUG - if (0 == --nb_states) - tcc_memcheck(); -#endif -} - -LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type) -{ - s->output_type = output_type; - - if (!s->nostdinc) { - /* default include paths */ - /* -isystem paths have already been handled */ - tcc_add_sysinclude_path(s, CONFIG_TCC_SYSINCLUDEPATHS); - } -#ifdef CONFIG_TCC_BCHECK - if (s->do_bounds_check) { - /* if bound checking, then add corresponding sections */ - tccelf_bounds_new(s); - } -#endif - if (s->do_debug) { - /* add debug sections */ - tcc_debug_new(s); - } - if (output_type == TCC_OUTPUT_OBJ) { - /* always elf for objects */ - s->output_format = TCC_OUTPUT_FORMAT_ELF; - return 0; - } - - tcc_add_library_path(s, CONFIG_TCC_LIBPATHS); - -#ifdef TCC_TARGET_PE -# ifdef _WIN32 - /* allow linking with system dll's directly */ - tcc_add_systemdir(s); -# endif - /* target PE has its own startup code in libtcc1.a */ - return 0; - -#elif defined TCC_TARGET_MACHO -# ifdef TCC_IS_NATIVE - tcc_add_macos_sdkpath(s); -# endif - /* Mach-O with LC_MAIN doesn't need any crt startup code. */ - return 0; - -#else - /* paths for crt objects */ - tcc_split_path(s, &s->crt_paths, &s->nb_crt_paths, CONFIG_TCC_CRTPREFIX); - /* add libc crt1/crti objects */ - if ((output_type == TCC_OUTPUT_EXE || output_type == TCC_OUTPUT_DLL) && - !s->nostdlib) { -#if TARGETOS_OpenBSD - if (output_type != TCC_OUTPUT_DLL) - tcc_add_crt(s, "crt0.o"); - if (output_type == TCC_OUTPUT_DLL) - tcc_add_crt(s, "crtbeginS.o"); - else - tcc_add_crt(s, "crtbegin.o"); -#elif TARGETOS_FreeBSD - if (output_type != TCC_OUTPUT_DLL) - tcc_add_crt(s, "crt1.o"); - tcc_add_crt(s, "crti.o"); - if (s->static_link) - tcc_add_crt(s, "crtbeginT.o"); - else if (output_type == TCC_OUTPUT_DLL) - tcc_add_crt(s, "crtbeginS.o"); - else - tcc_add_crt(s, "crtbegin.o"); -#elif TARGETOS_NetBSD - if (output_type != TCC_OUTPUT_DLL) - tcc_add_crt(s, "crt0.o"); - tcc_add_crt(s, "crti.o"); - if (s->static_link) - tcc_add_crt(s, "crtbeginT.o"); - else if (output_type == TCC_OUTPUT_DLL) - tcc_add_crt(s, "crtbeginS.o"); - else - tcc_add_crt(s, "crtbegin.o"); -#else - if (output_type != TCC_OUTPUT_DLL) - tcc_add_crt(s, "crt1.o"); - tcc_add_crt(s, "crti.o"); -#endif - } - return 0; -#endif -} - -LIBTCCAPI int tcc_add_include_path(TCCState *s, const char *pathname) -{ - tcc_split_path(s, &s->include_paths, &s->nb_include_paths, pathname); - return 0; -} - -LIBTCCAPI int tcc_add_sysinclude_path(TCCState *s, const char *pathname) -{ - tcc_split_path(s, &s->sysinclude_paths, &s->nb_sysinclude_paths, pathname); - return 0; -} - -ST_FUNC DLLReference *tcc_add_dllref(TCCState *s1, const char *dllname) -{ - DLLReference *ref = tcc_mallocz(sizeof(DLLReference) + strlen(dllname)); - strcpy(ref->name, dllname); - dynarray_add(&s1->loaded_dlls, &s1->nb_loaded_dlls, ref); - return ref; -} - -/* OpenBSD: choose latest from libxxx.so.x.y versions */ -#if defined TARGETOS_OpenBSD && !defined _WIN32 -#include -static int tcc_glob_so(TCCState *s1, const char *pattern, char *buf, int size) -{ - const char *star; - glob_t g; - char *p; - int i, v, v1, v2, v3; - - star = strchr(pattern, '*'); - if (!star || glob(pattern, 0, NULL, &g)) - return -1; - for (v = -1, i = 0; i < g.gl_pathc; ++i) { - p = g.gl_pathv[i]; - if (2 != sscanf(p + (star - pattern), "%d.%d.%d", &v1, &v2, &v3)) - continue; - if ((v1 = v1 * 1000 + v2) > v) - v = v1, pstrcpy(buf, size, p); - } - globfree(&g); - return v; -} -#endif - -ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags) -{ - int fd, ret = -1; - -#if defined TARGETOS_OpenBSD && !defined _WIN32 - char buf[1024]; - if (tcc_glob_so(s1, filename, buf, sizeof buf) >= 0) - filename = buf; -#endif - - /* open the file */ - fd = _tcc_open(s1, filename); - if (fd < 0) { - if (flags & AFF_PRINT_ERROR) - tcc_error_noabort("file '%s' not found", filename); - return ret; - } - - s1->current_filename = filename; - if (flags & AFF_TYPE_BIN) { - ElfW(Ehdr) ehdr; - int obj_type; - - obj_type = tcc_object_type(fd, &ehdr); - lseek(fd, 0, SEEK_SET); - - switch (obj_type) { - - case AFF_BINTYPE_REL: - ret = tcc_load_object_file(s1, fd, 0); - break; - - case AFF_BINTYPE_AR: - ret = tcc_load_archive(s1, fd, !(flags & AFF_WHOLE_ARCHIVE)); - break; - -#ifdef TCC_TARGET_PE - default: - ret = pe_load_file(s1, fd, filename); - goto check_success; - -#elif defined TCC_TARGET_MACHO - case AFF_BINTYPE_DYN: - case_dyn_or_tbd: - if (s1->output_type == TCC_OUTPUT_MEMORY) { -#ifdef TCC_IS_NATIVE - void* dl; - const char* soname = filename; - if (obj_type != AFF_BINTYPE_DYN) - soname = macho_tbd_soname(filename); - dl = dlopen(soname, RTLD_GLOBAL | RTLD_LAZY); - if (dl) - tcc_add_dllref(s1, soname)->handle = dl, ret = 0; - if (filename != soname) - tcc_free((void *)soname); -#endif - } else if (obj_type == AFF_BINTYPE_DYN) { - ret = macho_load_dll(s1, fd, filename, (flags & AFF_REFERENCED_DLL) != 0); - } else { - ret = macho_load_tbd(s1, fd, filename, (flags & AFF_REFERENCED_DLL) != 0); - } - break; - default: - { - const char *ext = tcc_fileextension(filename); - if (!strcmp(ext, ".tbd")) - goto case_dyn_or_tbd; - if (!strcmp(ext, ".dylib")) { - obj_type = AFF_BINTYPE_DYN; - goto case_dyn_or_tbd; - } - goto check_success; - } - -#else /* unix */ - case AFF_BINTYPE_DYN: - if (s1->output_type == TCC_OUTPUT_MEMORY) { -#ifdef TCC_IS_NATIVE - void* dl = dlopen(filename, RTLD_GLOBAL | RTLD_LAZY); - if (dl) - tcc_add_dllref(s1, filename)->handle = dl, ret = 0; -#endif - } else - ret = tcc_load_dll(s1, fd, filename, (flags & AFF_REFERENCED_DLL) != 0); - break; - - default: - /* as GNU ld, consider it is an ld script if not recognized */ - ret = tcc_load_ldscript(s1, fd); - goto check_success; - -#endif /* pe / macos / unix */ - -check_success: - if (ret < 0) - tcc_error_noabort("%s: unrecognized file type", filename); - break; - -#ifdef TCC_TARGET_COFF - case AFF_BINTYPE_C67: - ret = tcc_load_coff(s1, fd); - break; -#endif - } - close(fd); - } else { - /* update target deps */ - dynarray_add(&s1->target_deps, &s1->nb_target_deps, tcc_strdup(filename)); - ret = tcc_compile(s1, flags, filename, fd); - } - s1->current_filename = NULL; - return ret; -} - -LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename) -{ - int filetype = s->filetype; - if (0 == (filetype & AFF_TYPE_MASK)) { - /* use a file extension to detect a filetype */ - const char *ext = tcc_fileextension(filename); - if (ext[0]) { - ext++; - if (!strcmp(ext, "S")) - filetype = AFF_TYPE_ASMPP; - else if (!strcmp(ext, "s")) - filetype = AFF_TYPE_ASM; - else if (!PATHCMP(ext, "c") - || !PATHCMP(ext, "h") - || !PATHCMP(ext, "i")) - filetype = AFF_TYPE_C; - else - filetype |= AFF_TYPE_BIN; - } else { - filetype = AFF_TYPE_C; - } - } - return tcc_add_file_internal(s, filename, filetype | AFF_PRINT_ERROR); -} - -LIBTCCAPI int tcc_add_library_path(TCCState *s, const char *pathname) -{ - tcc_split_path(s, &s->library_paths, &s->nb_library_paths, pathname); - return 0; -} - -static int tcc_add_library_internal(TCCState *s, const char *fmt, - const char *filename, int flags, char **paths, int nb_paths) -{ - char buf[1024]; - int i; - - for(i = 0; i < nb_paths; i++) { - snprintf(buf, sizeof(buf), fmt, paths[i], filename); - if (tcc_add_file_internal(s, buf, flags | AFF_TYPE_BIN) == 0) - return 0; - } - return -1; -} - -#ifndef TCC_TARGET_MACHO -/* find and load a dll. Return non zero if not found */ -ST_FUNC int tcc_add_dll(TCCState *s, const char *filename, int flags) -{ - return tcc_add_library_internal(s, "%s/%s", filename, flags, - s->library_paths, s->nb_library_paths); -} -#endif - -#if !defined TCC_TARGET_PE && !defined TCC_TARGET_MACHO -ST_FUNC int tcc_add_crt(TCCState *s1, const char *filename) -{ - if (-1 == tcc_add_library_internal(s1, "%s/%s", - filename, 0, s1->crt_paths, s1->nb_crt_paths)) - tcc_error_noabort("file '%s' not found", filename); - return 0; -} -#endif - -/* the library name is the same as the argument of the '-l' option */ -LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname) -{ -#if defined TCC_TARGET_PE - static const char * const libs[] = { "%s/%s.def", "%s/lib%s.def", "%s/%s.dll", "%s/lib%s.dll", "%s/lib%s.a", NULL }; - const char * const *pp = s->static_link ? libs + 4 : libs; -#elif defined TCC_TARGET_MACHO - static const char * const libs[] = { "%s/lib%s.dylib", "%s/lib%s.tbd", "%s/lib%s.a", NULL }; - const char * const *pp = s->static_link ? libs + 2 : libs; -#elif defined TARGETOS_OpenBSD - static const char * const libs[] = { "%s/lib%s.so.*", "%s/lib%s.a", NULL }; - const char * const *pp = s->static_link ? libs + 1 : libs; -#else - static const char * const libs[] = { "%s/lib%s.so", "%s/lib%s.a", NULL }; - const char * const *pp = s->static_link ? libs + 1 : libs; -#endif - int flags = s->filetype & AFF_WHOLE_ARCHIVE; - while (*pp) { - if (0 == tcc_add_library_internal(s, *pp, - libraryname, flags, s->library_paths, s->nb_library_paths)) - return 0; - ++pp; - } - return -1; -} - -PUB_FUNC int tcc_add_library_err(TCCState *s1, const char *libname) -{ - int ret = tcc_add_library(s1, libname); - if (ret < 0) - tcc_error_noabort("library '%s' not found", libname); - return ret; -} - -/* handle #pragma comment(lib,) */ -ST_FUNC void tcc_add_pragma_libs(TCCState *s1) -{ - int i; - for (i = 0; i < s1->nb_pragma_libs; i++) - tcc_add_library_err(s1, s1->pragma_libs[i]); -} - -LIBTCCAPI int tcc_add_symbol(TCCState *s1, const char *name, const void *val) -{ -#ifdef TCC_TARGET_PE - /* On x86_64 'val' might not be reachable with a 32bit offset. - So it is handled here as if it were in a DLL. */ - pe_putimport(s1, 0, name, (uintptr_t)val); -#else - char buf[256]; - if (s1->leading_underscore) { - buf[0] = '_'; - pstrcpy(buf + 1, sizeof(buf) - 1, name); - name = buf; - } - set_global_sym(s1, name, NULL, (addr_t)(uintptr_t)val); /* NULL: SHN_ABS */ -#endif - return 0; -} - -LIBTCCAPI void tcc_set_lib_path(TCCState *s, const char *path) -{ - tcc_free(s->tcc_lib_path); - s->tcc_lib_path = tcc_strdup(path); -} - -/********************************************************/ -/* options parser */ - -static int strstart(const char *val, const char **str) -{ - const char *p, *q; - p = *str; - q = val; - while (*q) { - if (*p != *q) - return 0; - p++; - q++; - } - *str = p; - return 1; -} - -/* Like strstart, but automatically takes into account that ld options can - * - * - start with double or single dash (e.g. '--soname' or '-soname') - * - arguments can be given as separate or after '=' (e.g. '-Wl,-soname,x.so' - * or '-Wl,-soname=x.so') - * - * you provide `val` always in 'option[=]' form (no leading -) - */ -static int link_option(const char *str, const char *val, const char **ptr) -{ - const char *p, *q; - int ret; - - /* there should be 1 or 2 dashes */ - if (*str++ != '-') - return 0; - if (*str == '-') - str++; - - /* then str & val should match (potentially up to '=') */ - p = str; - q = val; - - ret = 1; - if (q[0] == '?') { - ++q; - if (strstart("no-", &p)) - ret = -1; - } - - while (*q != '\0' && *q != '=') { - if (*p != *q) - return 0; - p++; - q++; - } - - /* '=' near eos means ',' or '=' is ok */ - if (*q == '=') { - if (*p == 0) - *ptr = p; - if (*p != ',' && *p != '=') - return 0; - p++; - } else if (*p) { - return 0; - } - *ptr = p; - return ret; -} - -static const char *skip_linker_arg(const char **str) -{ - const char *s1 = *str; - const char *s2 = strchr(s1, ','); - *str = s2 ? s2++ : (s2 = s1 + strlen(s1)); - return s2; -} - -static void copy_linker_arg(char **pp, const char *s, int sep) -{ - const char *q = s; - char *p = *pp; - int l = 0; - if (p && sep) - p[l = strlen(p)] = sep, ++l; - skip_linker_arg(&q); - pstrncpy(l + (*pp = tcc_realloc(p, q - s + l + 1)), s, q - s); -} - -/* set linker options */ -static int tcc_set_linker(TCCState *s, const char *option) -{ - TCCState *s1 = s; - while (*option) { - - const char *p = NULL; - char *end = NULL; - int ignoring = 0; - int ret; - - if (link_option(option, "Bsymbolic", &p)) { - s->symbolic = 1; - } else if (link_option(option, "nostdlib", &p)) { - s->nostdlib = 1; - } else if (link_option(option, "e=", &p) - || link_option(option, "entry=", &p)) { - copy_linker_arg(&s->elf_entryname, p, 0); - } else if (link_option(option, "fini=", &p)) { - copy_linker_arg(&s->fini_symbol, p, 0); - ignoring = 1; - } else if (link_option(option, "image-base=", &p) - || link_option(option, "Ttext=", &p)) { - s->text_addr = strtoull(p, &end, 16); - s->has_text_addr = 1; - } else if (link_option(option, "init=", &p)) { - copy_linker_arg(&s->init_symbol, p, 0); - ignoring = 1; - } else if (link_option(option, "oformat=", &p)) { -#if defined(TCC_TARGET_PE) - if (strstart("pe-", &p)) { -#elif PTR_SIZE == 8 - if (strstart("elf64-", &p)) { -#else - if (strstart("elf32-", &p)) { -#endif - s->output_format = TCC_OUTPUT_FORMAT_ELF; - } else if (!strcmp(p, "binary")) { - s->output_format = TCC_OUTPUT_FORMAT_BINARY; -#ifdef TCC_TARGET_COFF - } else if (!strcmp(p, "coff")) { - s->output_format = TCC_OUTPUT_FORMAT_COFF; -#endif - } else - goto err; - - } else if (link_option(option, "as-needed", &p)) { - ignoring = 1; - } else if (link_option(option, "O", &p)) { - ignoring = 1; - } else if (link_option(option, "export-all-symbols", &p)) { - s->rdynamic = 1; - } else if (link_option(option, "export-dynamic", &p)) { - s->rdynamic = 1; - } else if (link_option(option, "rpath=", &p)) { - copy_linker_arg(&s->rpath, p, ':'); - } else if (link_option(option, "enable-new-dtags", &p)) { - s->enable_new_dtags = 1; - } else if (link_option(option, "section-alignment=", &p)) { - s->section_align = strtoul(p, &end, 16); - } else if (link_option(option, "soname=", &p)) { - copy_linker_arg(&s->soname, p, 0); -#ifdef TCC_TARGET_PE - } else if (link_option(option, "large-address-aware", &p)) { - s->pe_characteristics |= 0x20; - } else if (link_option(option, "file-alignment=", &p)) { - s->pe_file_align = strtoul(p, &end, 16); - } else if (link_option(option, "stack=", &p)) { - s->pe_stack_size = strtoul(p, &end, 10); - } else if (link_option(option, "subsystem=", &p)) { -#if defined(TCC_TARGET_I386) || defined(TCC_TARGET_X86_64) - if (!strcmp(p, "native")) { - s->pe_subsystem = 1; - } else if (!strcmp(p, "console")) { - s->pe_subsystem = 3; - } else if (!strcmp(p, "gui") || !strcmp(p, "windows")) { - s->pe_subsystem = 2; - } else if (!strcmp(p, "posix")) { - s->pe_subsystem = 7; - } else if (!strcmp(p, "efiapp")) { - s->pe_subsystem = 10; - } else if (!strcmp(p, "efiboot")) { - s->pe_subsystem = 11; - } else if (!strcmp(p, "efiruntime")) { - s->pe_subsystem = 12; - } else if (!strcmp(p, "efirom")) { - s->pe_subsystem = 13; -#elif defined(TCC_TARGET_ARM) - if (!strcmp(p, "wince")) { - s->pe_subsystem = 9; -#endif - } else - goto err; -#endif - } else if (ret = link_option(option, "?whole-archive", &p), ret) { - if (ret > 0) - s->filetype |= AFF_WHOLE_ARCHIVE; - else - s->filetype &= ~AFF_WHOLE_ARCHIVE; - } else if (link_option(option, "z=", &p)) { - ignoring = 1; - } else if (p) { - return 0; - } else { - err: - tcc_error("unsupported linker option '%s'", option); - } - if (ignoring) - tcc_warning_c(warn_unsupported)("unsupported linker option '%s'", option); - option = skip_linker_arg(&p); - } - return 1; -} - -typedef struct TCCOption { - const char *name; - uint16_t index; - uint16_t flags; -} TCCOption; - -enum { - TCC_OPTION_ignored = 0, - TCC_OPTION_HELP, - TCC_OPTION_HELP2, - TCC_OPTION_v, - TCC_OPTION_I, - TCC_OPTION_D, - TCC_OPTION_U, - TCC_OPTION_P, - TCC_OPTION_L, - TCC_OPTION_B, - TCC_OPTION_l, - TCC_OPTION_bench, - TCC_OPTION_bt, - TCC_OPTION_b, - TCC_OPTION_ba, - TCC_OPTION_g, - TCC_OPTION_c, - TCC_OPTION_dumpversion, - TCC_OPTION_d, - TCC_OPTION_static, - TCC_OPTION_std, - TCC_OPTION_shared, - TCC_OPTION_soname, - TCC_OPTION_o, - TCC_OPTION_r, - TCC_OPTION_Wl, - TCC_OPTION_Wp, - TCC_OPTION_W, - TCC_OPTION_O, - TCC_OPTION_mfloat_abi, - TCC_OPTION_m, - TCC_OPTION_f, - TCC_OPTION_isystem, - TCC_OPTION_iwithprefix, - TCC_OPTION_include, - TCC_OPTION_nostdinc, - TCC_OPTION_nostdlib, - TCC_OPTION_print_search_dirs, - TCC_OPTION_rdynamic, - TCC_OPTION_pthread, - TCC_OPTION_run, - TCC_OPTION_w, - TCC_OPTION_E, - TCC_OPTION_M, - TCC_OPTION_MD, - TCC_OPTION_MF, - TCC_OPTION_MM, - TCC_OPTION_MMD, - TCC_OPTION_x, - TCC_OPTION_ar, - TCC_OPTION_impdef, -}; - -#define TCC_OPTION_HAS_ARG 0x0001 -#define TCC_OPTION_NOSEP 0x0002 /* cannot have space before option and arg */ - -static const TCCOption tcc_options[] = { - { "h", TCC_OPTION_HELP, 0 }, - { "-help", TCC_OPTION_HELP, 0 }, - { "?", TCC_OPTION_HELP, 0 }, - { "hh", TCC_OPTION_HELP2, 0 }, - { "v", TCC_OPTION_v, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, - { "-version", TCC_OPTION_v, 0 }, /* handle as verbose, also prints version*/ - { "I", TCC_OPTION_I, TCC_OPTION_HAS_ARG }, - { "D", TCC_OPTION_D, TCC_OPTION_HAS_ARG }, - { "U", TCC_OPTION_U, TCC_OPTION_HAS_ARG }, - { "P", TCC_OPTION_P, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, - { "L", TCC_OPTION_L, TCC_OPTION_HAS_ARG }, - { "B", TCC_OPTION_B, TCC_OPTION_HAS_ARG }, - { "l", TCC_OPTION_l, TCC_OPTION_HAS_ARG }, - { "bench", TCC_OPTION_bench, 0 }, -#ifdef CONFIG_TCC_BACKTRACE - { "bt", TCC_OPTION_bt, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, -#endif -#ifdef CONFIG_TCC_BCHECK - { "b", TCC_OPTION_b, 0 }, -#endif - { "g", TCC_OPTION_g, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, - { "c", TCC_OPTION_c, 0 }, - { "dumpversion", TCC_OPTION_dumpversion, 0}, - { "d", TCC_OPTION_d, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, - { "static", TCC_OPTION_static, 0 }, - { "std", TCC_OPTION_std, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, - { "shared", TCC_OPTION_shared, 0 }, - { "soname", TCC_OPTION_soname, TCC_OPTION_HAS_ARG }, - { "o", TCC_OPTION_o, TCC_OPTION_HAS_ARG }, - { "pthread", TCC_OPTION_pthread, 0}, - { "run", TCC_OPTION_run, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, - { "rdynamic", TCC_OPTION_rdynamic, 0 }, - { "r", TCC_OPTION_r, 0 }, - { "Wl,", TCC_OPTION_Wl, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, - { "Wp,", TCC_OPTION_Wp, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, - { "W", TCC_OPTION_W, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, - { "O", TCC_OPTION_O, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, -#ifdef TCC_TARGET_ARM - { "mfloat-abi", TCC_OPTION_mfloat_abi, TCC_OPTION_HAS_ARG }, -#endif - { "m", TCC_OPTION_m, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, - { "f", TCC_OPTION_f, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, - { "isystem", TCC_OPTION_isystem, TCC_OPTION_HAS_ARG }, - { "include", TCC_OPTION_include, TCC_OPTION_HAS_ARG }, - { "nostdinc", TCC_OPTION_nostdinc, 0 }, - { "nostdlib", TCC_OPTION_nostdlib, 0 }, - { "print-search-dirs", TCC_OPTION_print_search_dirs, 0 }, - { "w", TCC_OPTION_w, 0 }, - { "E", TCC_OPTION_E, 0}, - { "M", TCC_OPTION_M, 0}, - { "MD", TCC_OPTION_MD, 0}, - { "MF", TCC_OPTION_MF, TCC_OPTION_HAS_ARG }, - { "MM", TCC_OPTION_MM, 0}, - { "MMD", TCC_OPTION_MMD, 0}, - { "x", TCC_OPTION_x, TCC_OPTION_HAS_ARG }, - { "ar", TCC_OPTION_ar, 0}, -#ifdef TCC_TARGET_PE - { "impdef", TCC_OPTION_impdef, 0}, -#endif - /* ignored (silently, except after -Wunsupported) */ - { "arch", 0, TCC_OPTION_HAS_ARG}, - { "C", 0, 0 }, - { "-param", 0, TCC_OPTION_HAS_ARG }, - { "pedantic", 0, 0 }, - { "pipe", 0, 0 }, - { "s", 0, 0 }, - { "traditional", 0, 0 }, - { NULL, 0, 0 }, -}; - -typedef struct FlagDef { - uint16_t offset; - uint16_t flags; - const char *name; -} FlagDef; - -#define WD_ALL 0x0001 /* warning is activated when using -Wall */ -#define FD_INVERT 0x0002 /* invert value before storing */ - -static const FlagDef options_W[] = { - { offsetof(TCCState, warn_all), WD_ALL, "all" }, - { offsetof(TCCState, warn_error), 0, "error" }, - { offsetof(TCCState, warn_write_strings), 0, "write-strings" }, - { offsetof(TCCState, warn_unsupported), 0, "unsupported" }, - { offsetof(TCCState, warn_implicit_function_declaration), WD_ALL, "implicit-function-declaration" }, - { offsetof(TCCState, warn_discarded_qualifiers), WD_ALL, "discarded-qualifiers" }, - { 0, 0, NULL } -}; - -static const FlagDef options_f[] = { - { offsetof(TCCState, char_is_unsigned), 0, "unsigned-char" }, - { offsetof(TCCState, char_is_unsigned), FD_INVERT, "signed-char" }, - { offsetof(TCCState, nocommon), FD_INVERT, "common" }, - { offsetof(TCCState, leading_underscore), 0, "leading-underscore" }, - { offsetof(TCCState, ms_extensions), 0, "ms-extensions" }, - { offsetof(TCCState, dollars_in_identifiers), 0, "dollars-in-identifiers" }, - { offsetof(TCCState, test_coverage), 0, "test-coverage" }, - { 0, 0, NULL } -}; - -static const FlagDef options_m[] = { - { offsetof(TCCState, ms_bitfields), 0, "ms-bitfields" }, -#ifdef TCC_TARGET_X86_64 - { offsetof(TCCState, nosse), FD_INVERT, "sse" }, -#endif - { 0, 0, NULL } -}; - -static int set_flag(TCCState *s, const FlagDef *flags, const char *name) -{ - int value, mask, ret; - const FlagDef *p; - const char *r; - unsigned char *f; - - r = name, value = !strstart("no-", &r), mask = 0; - - /* when called with options_W, look for -W[no-]error=