diff --git a/.gitignore b/.gitignore index c6127b3..3e8b80f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,15 @@ # Prerequisites *.d +# Test files +test-*.c + # Object files *.o *.ko *.obj *.elf +*.S # Linker output *.ilk diff --git a/src/COPYING b/COPYING similarity index 100% rename from src/COPYING rename to COPYING diff --git a/src/ChangeLog b/ChangeLog similarity index 91% rename from src/ChangeLog rename to ChangeLog index 27cc873..b019064 100644 --- a/src/ChangeLog +++ b/ChangeLog @@ -14,6 +14,6 @@ 2018/12/06 - Actually started project, began MBR, decided directories organization, created this file and others 2018/12/08 - MBR actually supports Long Mode Compatibility Verification - Added A20 line Enabling to MBR -2018/12/21 - Boot is now in two stages. First stage is 512 MBR code that loads second stage loader from FAT16. +2018/12/21 - Boot is now in two stages. First stage is 512B MBR code that loads second stage loader from FAT16. That second stage loader enables A20, switches into long mode and write colored text =D diff --git a/LICENSE b/LICENSE deleted file mode 100644 index f288702..0000000 --- a/LICENSE +++ /dev/null @@ -1,674 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, 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 -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If 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 convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU 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 -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "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 PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM 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 PROGRAM (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 PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state 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 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 3 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, see . - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - Copyright (C) - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. diff --git a/src/Makefile b/Makefile similarity index 92% rename from src/Makefile rename to Makefile index 5a4d5c5..71e74a6 100644 --- a/src/Makefile +++ b/Makefile @@ -9,19 +9,19 @@ kernel: cpp ./Makefile.in > Makefile.out - python ./idttool.py + python ./build/idttool.py make kernel -f Makefile.out.2 rm Makefile.out Makefile.out.2 kernel-asm: cpp -D_TO_ASM ./Makefile.in > Makefile.out - python ./idttool.py + python ./build/idttool.py make kernel -f Makefile.out.2 rm Makefile.out Makefile.out.2 tests: cpp -D_TESTS ./Makefile.in > Makefile.out - python ./idttool.py + python ./build/idttool.py make tests -f Makefile.out.2 rm Makefile.out Makefile.out.2 diff --git a/src/Makefile.in b/Makefile.in similarity index 68% rename from src/Makefile.in rename to Makefile.in index b728749..5c26235 100644 --- a/src/Makefile.in +++ b/Makefile.in @@ -8,48 +8,45 @@ //----------------------------------------------------------------------------// // The madman's Makefile -#include "preproc.h" +#include "build/preproc.h" CCNAME="/opt/cross-cc/bin/x86_64-elf-gcc" CC2NAME=gcc COPTIM=-O2 -CLDSCR=-T kernel.ld -CWARNS=-pedantic -Wall -Wextra -Werror +CWARNS=-Wall -Wextra -Wshadow -Wpedantic CINCLUDES=-isystem./kaleid/include -CDEFINES= -CFLAGS1=-nostdlib -ffreestanding -mcmodel=large -CFLAGS2=-mno-red-zone -mno-mmx -mno-sse -mno-sse2 +CFLAGS1=-std=gnu11 -nostdlib -ffreestanding -mcmodel=large +CFLAGS2=-m64 -masm=intel -mno-red-zone -mno-mmx -mno-sse -mno-sse2 CFLAGS=$(CFLAGS1) $(CFLAGS2) $(SFLAG) -CC=$(CCNAME) $(COPTIM) $(CWARNS) $(CFLAGS) $(CDEFINES) $(CINCLUDES) +CC=$(CCNAME) $(COPTIM) $(CWARNS) $(CFLAGS) $(CINCLUDES) ASM=nasm ASMFLAGS= BOOTFLAGS=-f bin -BINDIR=../bin -OBJDIR=../obj +BINDIR=./build/bin +OBJDIR=./build/obj BOOTDIR=boot COMMDIR=kaleid/common KERNDIR=kaleid/kernel SYSTDIR=kaleid/system LINXDIR=kaleid/common/test -INCDIR=kaleid/include all: bootloader kernel boot.mbr.s: $(BOOTDIR)/mbr.s $(BOOTDIR)/mbr.inc - $(ASM) $(BOOTFLAGS) $(BOOTDIR)/mbr.s -o $(OBJDIR)/boot/mbr.bin + $(ASM) $(BOOTFLAGS) $(BOOTDIR)/mbr.asm -o $(OBJDIR)/boot/mbr.bin boot.loader.s: $(BOOTDIR)/loader.s - $(ASM) $(BOOTFLAGS) $(BOOTDIR)/loader.s -o $(OBJDIR)/boot/loader.bin + $(ASM) $(BOOTFLAGS) $(BOOTDIR)/loader.asm -o $(OBJDIR)/boot/loader.bin bootloader: boot.mbr.s boot.loader.s cp $(OBJDIR)/boot/mbr.bin $(BINDIR)/mbr.bin cp $(OBJDIR)/boot/loader.bin $(BINDIR)/loader.bin - + //----------------------------------------------------------------------------# // TESTING MAKEFILE @@ -65,16 +62,20 @@ testing: bootloader pseudo_kern COBJDIR=$(OBJDIR)/$(COMMDIR) LOBJDIR=$(OBJDIR)/$(LINXDIR) -COMMOBJS=COBJ5(string,status,rand,memory,arith) COBJ4(itoa,ltoa,utoa,ultoa) +COMMOBJS=COBJ6(string, status, rand, memory, arith, strtol) COBJ4(itoa, ltoa, utoa, ultoa) COBJ4(atoi, atol, atou, atoul) TCC=$(CC2NAME) $(COPTIM) $(CWARNS) $(CINCLUDES) -KCC=$(CC) -D_OSK_SOURCE -D_KALEID_KERNEL +KCC=$(CC) -T ./build/kernel.ld -D_OSK_SOURCE -D_KALEID_KERNEL comm-convert: - COMPILE_CONVRT(itoa) -D_NEED_ITOA - COMPILE_CONVRT(ltoa) -D_NEED_LTOA - COMPILE_CONVRT(utoa) -D_NEED_UTOA - COMPILE_CONVRT(ultoa) -D_NEED_ULTOA + COMPILE_CONVRT1(itoa) -D_NEED_ITOA + COMPILE_CONVRT1(ltoa) -D_NEED_LTOA + COMPILE_CONVRT1(utoa) -D_NEED_UTOA + COMPILE_CONVRT1(ultoa) -D_NEED_ULTOA + COMPILE_CONVRT2(atoi) -D_NEED_ATOI + COMPILE_CONVRT2(atol) -D_NEED_ATOL + COMPILE_CONVRT2(atou) -D_NEED_ATOU + COMPILE_CONVRT2(atoul) -D_NEED_ATOUL common: comm-convert COMPILE_COMMON(rand) @@ -82,6 +83,7 @@ common: comm-convert COMPILE_COMMON(string) COMPILE_COMMON(status) COMPILE_COMMON(memory) + COMPILE_COMMON(strtol) tests: common $(TCC) -c $(LINXDIR)/test-common.c -o $(LOBJDIR)/test-common.o @@ -92,15 +94,13 @@ tests: common KOBJDIR=$(OBJDIR)/$(KERNDIR) -KERNOBJS=KOBJ5(init,ke/lock,ke/panic,ke/state,io/ports) KOBJ1(io/terminal) +KERNOBJS=KOBJ4(init/init, init/table, ke/panic, ke/terminal) kernel: common - COMPILE_KERNEL(init) - COMPILE_KERNEL(ke/lock) - COMPILE_KERNEL(ke/state) + COMPILE_KERNEL(init/init) + COMPILE_KERNEL(init/table) COMPILE_KERNEL(ke/panic) - COMPILE_KERNEL(io/ports) - COMPILE_KERNEL(io/terminal) + COMPILE_KERNEL(ke/terminal) LINK_KERNEL(kaleid-kernel.elf) //----------------------------------------------------------------------------# diff --git a/ProjectTree b/ProjectTree new file mode 100644 index 0000000..90c5627 --- /dev/null +++ b/ProjectTree @@ -0,0 +1,107 @@ +#------------------------------------------------------------------------------# +# GNU GPL OS/K # +# # +# Authors: spectral` # +# NeoX # +# # +# Desc: Project Tree # +#------------------------------------------------------------------------------# + +src/ + | + x COPYING + x README.md + x ChangeLog + | + - Makefile + - Makefile.in + | + + boot/ + | | + | x folder.desc + | | + | - mbr.asm + | - mbr.inc + | | + | - loader.asm + | - loader16.inc + | - loader64.inc + | | + | 0 + | + + kaleid/ + | | + | + include/ + | | | + | | - kaleid.h + | | - kalkern.h + | | | + | | + common/ + | | | | + | | | - kaldefs.h + | | | - kaltypes.h + | | | - kalerror.h + | | | - kalassrt.h + | | | - kallims.h + | | | - kalmask.h + | | | - kalcrt.h + | | | | + | | | 0 + | | | + | | + kernel/ + | | | | + | | | - kernbase.h + | | | - kernlocks.h + | | | - kernterm.h + | | | | + | | | 0 + | | 0 + | | + | | + | + kernel/ + | | | + | | - kernel.ld + | | | + | | + init/ + | | | | + | | | - init.c + | | | | + | | | 0 + | | | + | | + ke/ + | | | | + | | | - panic.c + | | | - table.c + | | | - terminal.c + | | | | + | | | 0 + | | 0 + | | + | + common/ + | | | + | | - status.c + | | | + | | - arith.c + | | - rand.c + | | | + | | - atoi.c + | | - itoa.c + | | - strtol.c + | | | + | | - memory.c + | | - string.c + | | - sprintf.c + | | | + | | 0 + | 0 + | + + build/ + | | + | - preproc.h + | - iddtool.h + | | + | + bin/ + | + obj/ + | | + | 0 + 0 diff --git a/README.md b/README.md index 41d9385..8be55fd 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,9 @@ Fully open-source operating system from scratch (WIP), released under the GNU GP Branch kaleid : Development focused on the Kaleid Kernel. -For changelog, see src/ChangeLog. +For changelog, see src/ChangeLog. -For structure of the sources, see src/project-tree.txt. +For structure of the sources, see src/project-tree.txt. -For code conventions, see src/project-style.txt. +Note that every file within OS/K is written using spaces for tabulation, with each +tabulation being 4 spaces long. diff --git a/src/boot/folder.desc b/boot/folder.desc similarity index 100% rename from src/boot/folder.desc rename to boot/folder.desc diff --git a/src/boot/loader.s b/boot/loader.asm similarity index 100% rename from src/boot/loader.s rename to boot/loader.asm diff --git a/src/boot/loader16.inc b/boot/loader16.inc similarity index 100% rename from src/boot/loader16.inc rename to boot/loader16.inc diff --git a/src/boot/loader64.inc b/boot/loader64.inc similarity index 100% rename from src/boot/loader64.inc rename to boot/loader64.inc diff --git a/src/boot/mbr.s b/boot/mbr.asm similarity index 100% rename from src/boot/mbr.s rename to boot/mbr.asm diff --git a/src/boot/mbr.inc b/boot/mbr.inc similarity index 100% rename from src/boot/mbr.inc rename to boot/mbr.inc diff --git a/bin/disk.img b/build/bin/disk.img similarity index 100% rename from bin/disk.img rename to build/bin/disk.img diff --git a/bin/loader.bin b/build/bin/loader.bin similarity index 100% rename from bin/loader.bin rename to build/bin/loader.bin diff --git a/bin/mbr.bin b/build/bin/mbr.bin similarity index 100% rename from bin/mbr.bin rename to build/bin/mbr.bin diff --git a/src/idttool.py b/build/idttool.py similarity index 100% rename from src/idttool.py rename to build/idttool.py diff --git a/src/kernel.ld b/build/kernel.ld similarity index 74% rename from src/kernel.ld rename to build/kernel.ld index 5768560..e96beb8 100644 --- a/src/kernel.ld +++ b/build/kernel.ld @@ -1,9 +1,9 @@ ENTRY(StartKern) SECTIONS { - . = 0x4000; /* XXX 0x4000 is temporary */ + . = 1M; - .text : AT(ADDR(.text) - 0x4000) + .text : AT(ADDR(.text) - 1M) { _code = .; *(.text) @@ -11,21 +11,21 @@ SECTIONS . = ALIGN(4096); } - .data : AT(ADDR(.data) - 0x4000) + .data : AT(ADDR(.data) - 1M) { _data = .; *(.data) . = ALIGN(4096); } - .eh_frame : AT(ADDR(.eh_frame) - 0x4000) + .eh_frame : AT(ADDR(.eh_frame) - 1M) { _ehframe = .; *(.eh_frame) . = ALIGN(4096); } - .bss : AT(ADDR(.bss) - 0x4000) + .bss : AT(ADDR(.bss) - 1M) { _bss = .; *(.bss) diff --git a/obj/boot/loader.bin b/build/obj/boot/loader.bin similarity index 100% rename from obj/boot/loader.bin rename to build/obj/boot/loader.bin diff --git a/obj/boot/mbr.bin b/build/obj/boot/mbr.bin similarity index 100% rename from obj/boot/mbr.bin rename to build/obj/boot/mbr.bin diff --git a/obj/kaleid/common/.placeholder b/build/obj/kaleid/common/.placeholder similarity index 100% rename from obj/kaleid/common/.placeholder rename to build/obj/kaleid/common/.placeholder diff --git a/obj/kaleid/common/test/.paceholder b/build/obj/kaleid/common/test/.paceholder similarity index 100% rename from obj/kaleid/common/test/.paceholder rename to build/obj/kaleid/common/test/.paceholder diff --git a/obj/kaleid/common/lib/.placeholder b/build/obj/kaleid/kernel/init/.placeholder similarity index 100% rename from obj/kaleid/common/lib/.placeholder rename to build/obj/kaleid/kernel/init/.placeholder diff --git a/obj/kaleid/kernel/io/.placeholder b/build/obj/kaleid/kernel/io/.placeholder similarity index 100% rename from obj/kaleid/kernel/io/.placeholder rename to build/obj/kaleid/kernel/io/.placeholder diff --git a/obj/kaleid/kernel/ke/.placeholder b/build/obj/kaleid/kernel/ke/.placeholder similarity index 100% rename from obj/kaleid/kernel/ke/.placeholder rename to build/obj/kaleid/kernel/ke/.placeholder diff --git a/build/preproc.h b/build/preproc.h new file mode 100644 index 0000000..f690c6e --- /dev/null +++ b/build/preproc.h @@ -0,0 +1,42 @@ +// be careful with this file + +#ifdef _TESTS +# define CCC TCC +#else +# define CCC KCC +#endif + +#ifdef _TO_ASM +# define _CSPREF -S +# define _OUTFIX S +# define LINK_KERNEL(out) +#else +# define _CSPREF -c +# define _OUTFIX o +# define LINK_KERNEL(out) $(KCC) $(CLDSCR) $(COMMOBJS) $(KERNOBJS) -o $(BINDIR)/out +#endif + +#define COMPILE_CONVRT1(file) $(CCC) _CSPREF $(COMMDIR)/itoa.c -o $(COBJDIR)/file._OUTFIX +#define COMPILE_CONVRT2(file) $(CCC) _CSPREF $(COMMDIR)/atoi.c -o $(COBJDIR)/file._OUTFIX + +#define COMPILE_COMMON(file) $(CCC) _CSPREF $(COMMDIR)/file.c -o $(COBJDIR)/file._OUTFIX +#define COMPILE_KERNEL(file) $(KCC) _CSPREF $(KERNDIR)/file.c -o $(KOBJDIR)/file._OUTFIX + +#define COBJ1(x1) $(COBJDIR)/x1.o +#define COBJ2(x1,x2) COBJ1(x1) $(COBJDIR)/x2.o +#define COBJ3(x1,x2,x3) COBJ2(x1,x2) $(COBJDIR)/x3.o +#define COBJ4(x1,x2,x3,x4) COBJ3(x1,x2,x3) $(COBJDIR)/x4.o +#define COBJ5(x1,x2,x3,x4,x5) COBJ4(x1,x2,x3,x4) $(COBJDIR)/x5.o +#define COBJ6(x1,x2,x3,x4,x5,x6) COBJ5(x1,x2,x3,x4,x5) $(COBJDIR)/x6.o +#define COBJ7(x1,x2,x3,x4,x5,x6,x7) COBJ6(x1,x2,x3,x4,x5,x6) $(COBJDIR)/x7.o +#define COBJ8(x1,x2,x3,x4,x5,x6,x7,x8) COBJ7(x1,x2,x3,x4,x5,x6,x7) $(COBJDIR)/x8.o + +#define KOBJ1(x1) $(KOBJDIR)/x1.o +#define KOBJ2(x1,x2) KOBJ1(x1) $(KOBJDIR)/x2.o +#define KOBJ3(x1,x2,x3) KOBJ2(x1,x2) $(KOBJDIR)/x3.o +#define KOBJ4(x1,x2,x3,x4) KOBJ3(x1,x2,x3) $(KOBJDIR)/x4.o +#define KOBJ5(x1,x2,x3,x4,x5) KOBJ4(x1,x2,x3,x4) $(KOBJDIR)/x5.o +#define KOBJ6(x1,x2,x3,x4,x5,x6) KOBJ5(x1,x2,x3,x4,x5) $(KOBJDIR)/x6.o +#define KOBJ7(x1,x2,x3,x4,x5,x6,x7) KOBJ6(x1,x2,x3,x4,x5,x6) $(KOBJDIR)/x7.o +#define KOBJ8(x1,x2,x3,x4,x5,x6,x7,x8) KOBJ7(x1,x2,x3,x4,x5,x6,x7) $(KOBJDIR)/x8.o + diff --git a/src/kaleid/common/arith.c b/kaleid/common/arith.c similarity index 80% rename from src/kaleid/common/arith.c rename to kaleid/common/arith.c index 1d3c740..5ac8338 100644 --- a/src/kaleid/common/arith.c +++ b/kaleid/common/arith.c @@ -21,26 +21,6 @@ long _osk_labs(long x) return labs(x); } -int _osk_min(int x, int y) -{ - return min(x, y); -} - -long _osk_lmin(long x, long y) -{ - return lmin(x, y); -} - -int _osk_max(int x, int y) -{ - return max(x, y); -} - -long _osk_lmax(long x, long y) -{ - return lmax(x, y); -} - div_t _osk_div(int x, int y) { return div(x, y); diff --git a/kaleid/common/atoi.c b/kaleid/common/atoi.c new file mode 100644 index 0000000..f5a22a6 --- /dev/null +++ b/kaleid/common/atoi.c @@ -0,0 +1,37 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Conversion utilities - atoi family // +//----------------------------------------------------------------------------// + +#include + +// +// String to integer +// Do not change errno +// +#define _ATOI_IMPL(_Name, _Type, _Func) \ + _Type _Name(const char *str) { \ + error_t old = errno; \ + _Type ret = (_Type)_Func(str, NULL, 0); \ + errno = old; \ + return ret; \ + } + + +// ISO C does not allow extra ‘;’ outside of a function +#if defined(_NEED_ATOI) +_ATOI_IMPL(atoi, int, strtol) +#elif defined(_NEED_ATOL) +_ATOI_IMPL(atol, long, strtol) +#elif defined(_NEED_ATOU) +_ATOI_IMPL(atou, uint, strtoul) +#elif defined(_NEED_ATOUL) +_ATOI_IMPL(atoul, ulong, strtoul) +#else +#error "What am I supposed to declare?" +#endif + diff --git a/src/kaleid/common/itoa.c b/kaleid/common/itoa.c similarity index 75% rename from src/kaleid/common/itoa.c rename to kaleid/common/itoa.c index a184e16..e24a41a 100644 --- a/src/kaleid/common/itoa.c +++ b/kaleid/common/itoa.c @@ -10,12 +10,12 @@ #include // -// Digits table for bases <=36 +// Digits table for bases <=36 // -static const char digits[36] = - "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; +static const char digits[] = + "0123456789abcdefghijklmnopqrstuvwxyz"; // -// Integer to string in any base between 2 and 36 (included) +// Integer to string in any base between 2 and 36 (included) // #if defined(_NEED_ITOA) char *itoa(int i, char *str, int base) @@ -26,7 +26,7 @@ char *utoa(uint i, char *str, int base) #elif defined(_NEED_ULTOA) char *ultoa(ulong i, char *str, int base) #else -#error "What am I supposed to declare?" +#error "What am I supposed to declare?" #endif { #if defined(_NEED_ITOA) || defined(_NEED_LTOA) @@ -35,23 +35,32 @@ char *ultoa(ulong i, char *str, int base) char *orig = str; + // + // Only handle base 2 -> 36 + // if (base < 2 || base > 36) return NULL; #if defined(_NEED_ITOA) || defined(_NEED_LTOA) - // deal with negatives + // + // Deal with negatives + // if (i < 0) { neg = 1; i = -i; } #endif - - // deal with zero separately + + // + // Deal with zero separately + // if (i == 0) { *str++ = '0'; } - - // compute digits... in reverse order + + // + // Compute digits... in reverse order + // while (i > 0) { *str++ = digits[i % base]; i /= base; @@ -63,7 +72,10 @@ char *ultoa(ulong i, char *str, int base) *str = '\0'; - return reverse(orig); + // + // Reverse the string + // + return strrev2(orig); } diff --git a/src/kaleid/common/memory.c b/kaleid/common/memory.c similarity index 78% rename from src/kaleid/common/memory.c rename to kaleid/common/memory.c index 59b6cb8..3497a38 100644 --- a/src/kaleid/common/memory.c +++ b/kaleid/common/memory.c @@ -8,25 +8,28 @@ //----------------------------------------------------------------------------// #include -#include //------------------------------------------// // memset() family // //------------------------------------------// // -// Set "bytes"-many bytes starting from ptr to val +// Set "bytes"-many bytes starting from ptr to val // void *memset(void *ptr, int val, size_t bytes) { uchar *uptr = (uchar *)ptr; - - // deal with bytes before start of the first aligned qword + + // + // Deal with bytes before start of the first aligned qword + // while (((ulong)uptr % QWORD_ALIGN) > 0 && bytes--) { *uptr++ = (uchar)val; } - // we're qword-aligned now + // + // At this point we're qword-aligned + // if (bytes > QWORD_SIZE) { const ulong uval = ((ulong)val << 56) | ((ulong)val << 48) | ((ulong)val << 40) | ((ulong)val << 32) @@ -34,19 +37,23 @@ void *memset(void *ptr, int val, size_t bytes) | ((ulong)val << 8) | ((ulong)val); ulong *uqptr = (ulong *)ptr; - - // move qword by qword + + // + // Moving fast, qword by qword + // while (bytes > QWORD_SIZE) { *uqptr++ = uval; bytes -= QWORD_SIZE; } - + uptr = (uchar *)(ulong)uqptr; } - - // deal with what's left + + // + // Deal with the few remaining bytes + // while (bytes--) *uptr++ = (uchar)val; - + return ptr; } @@ -56,37 +63,38 @@ void *memset(void *ptr, int val, size_t bytes) void *memsetw(void *ptr, int val, size_t words) { ushort *uptr = (ushort *)ptr; - - // can't we do this an aligned way? + + // + // Check whether we can we do this an aligned way + // if unlikely (((ulong)uptr % WORD_ALIGN) > 0) { + // + // We can't, so we write word by word all the way up + // while (words--) *uptr++ = (ushort)val; return uptr; } - - // deal with words before start of the first aligned qword + while (((ulong)uptr % QWORD_ALIGN) > 0 && words--) { *uptr++ = (ushort)val; } - // we're aligned for sure if (words > QWORDS_TO_WORDS(1)) { const ulong uval = ((ulong)val << 48) | ((ulong)val << 32) | ((ulong)val << 16) | ((ulong)val); ulong *uqptr = (ulong *)uptr; - // move qword by qword while (words > QWORDS_TO_WORDS(1)) { words -= QWORDS_TO_WORDS(1); *uqptr++ = uval; } - + uptr = (ushort *)(ulong)uqptr; } - - // deal with what's left + while (words--) *uptr++ = (ushort)val; - + return ptr; } @@ -108,18 +116,21 @@ void *memsetd(void *ptr, int val, size_t dwords) void *memsetq(void *ptr, long val, size_t qwords) { ulong *uptr = (ulong *)ptr; - + + // + // There's no need to check for alignment + // while (qwords--) *uptr++ = (ulong)val; - + return ptr; } +//------------------------------------------// +// Other mem*() functions // +//------------------------------------------// + // // Set "bytes"-many bytes starting from ptr to 0 -// -// WARNING -// Assume "bytes" is large, for small sizes -// use memset(ptr, 0, bytes) directly // void *memzero(void *ptr, size_t bytes) { @@ -130,19 +141,24 @@ void *memzero(void *ptr, size_t bytes) // Copy "bytes"-many bytes of src to dst // Does not deal with overlapping blocks (memmove's job) // -void *memcpy(void *dst, const void *src, size_t bytes) +void *memcpy(void *restrict dst, const void *restrict src, size_t bytes) { const ulong *usrc = (const ulong *)src; ulong *udst = (ulong *)dst; - + if unlikely (bytes == 0) return dst; - // can we align them both at once? + // + // Can align both src and dst at once at once? + // if unlikely ((ulong)src % WORD_ALIGN == 1 && (ulong)dst % WORD_ALIGN == 1) { const uchar *ubsrc = (const uchar *)usrc; uchar *ubdst = (uchar *)udst; + // + // Yes we can, we're guaranteed to be word-aligned now + // *ubdst++ = *ubsrc++; bytes--; @@ -153,7 +169,9 @@ void *memcpy(void *dst, const void *src, size_t bytes) const ushort *uwsrc = (const ushort *)usrc; ushort *uwdst = (ushort *)udst; - // align either dst or src for qword access + // + // Align either dst or src for qword access + // while ((ulong)dst % QWORD_ALIGN > 0 && (ulong)src % QWORD_ALIGN > 0 && bytes > WORD_SIZE) { @@ -165,7 +183,9 @@ void *memcpy(void *dst, const void *src, size_t bytes) udst = (ulong *)uwdst; usrc = (ulong *)uwsrc; - // should be most of the job + // + // This should be most of the job + // while (bytes > QWORD_SIZE) { *udst++ = *usrc++; bytes -= QWORD_SIZE; @@ -174,26 +194,32 @@ void *memcpy(void *dst, const void *src, size_t bytes) const uchar *ubsrc = (const uchar *)usrc; ushort *ubdst = (ushort *)udst; - // deal with what's left + // + // Deal with the few bytes left + // while (bytes--) *ubdst ++ = *ubsrc++; return dst; } // -// Move memory from src to dest -// To be made more efficient +// Move memory from src to dest, even if they overlap // void *memmove(void *dst, const void *src, size_t bytes) { const uchar *usrc = src; uchar *udst = dst; + // + // Can we use memcpy() safely? + // if (udst < usrc) { - while (bytes--) *udst++ = *usrc++; - return dst; + return memcpy(dst, src, bytes); } + // + // No, so we go backwards + // uchar *usrc_end = (uchar *)usrc + bytes - 1; uchar *udst_end = udst + bytes - 1; while (bytes--) *udst_end-- = *usrc_end--; diff --git a/src/kaleid/common/rand.c b/kaleid/common/rand.c similarity index 87% rename from src/kaleid/common/rand.c rename to kaleid/common/rand.c index 5569792..fe576ef 100644 --- a/src/kaleid/common/rand.c +++ b/kaleid/common/rand.c @@ -8,16 +8,15 @@ //----------------------------------------------------------------------------// #include -#include // -// Seed value +// Seed value // static ulong next = 7756; // -// Returns a pseudo-random integer -// To be improved +// Returns a pseudo-random integer +// To be improved // int rand(void) { @@ -26,7 +25,7 @@ int rand(void) } // -// (Re)Set the random seed +// (Re)Set the random seed // void srand(uint seed) { diff --git a/src/kaleid/common/sprintf.c b/kaleid/common/sprintf.c similarity index 78% rename from src/kaleid/common/sprintf.c rename to kaleid/common/sprintf.c index 8a4e1f5..a8dd3ba 100644 --- a/src/kaleid/common/sprintf.c +++ b/kaleid/common/sprintf.c @@ -10,17 +10,17 @@ #include // -// Format str according to fmt using ellipsed arguments +// Format str according to fmt using ellipsed arguments // int sprintf(char *str, const char *fmt, ...) { int ret; va_list ap; - + va_start(ap); ret = vsnprintf(str, SIZE_T_MAX, fmt, ap); va_end(ap); - + return ret; } @@ -30,39 +30,45 @@ int vsprintf(char *str, const char *fmt, va_list ap) } // -// (v)sprintf() but with a size limit: no more than n bytes are written in str -// XXX null termination behavior? +// (v)sprintf() but with a size limit: no more than n bytes are written in str // int snprintf(char *str, size_t n, const char *fmt, ...) { int ret; va_list ap; - + va_start(ap); ret = vsnprintf(str, n, fmt, ap) va_end(ap); - + return ret; } int vsnprintf(char *str, size_t n, const char *fmt, va_list ap) { int ret = 0; - - while (*fmt && ret < n) { + + // + // Go throught the format string + // + while (*fmt) { if (*fmt != '%') { - *str++ = *fmt++; - ret++; + // + // Even if we don't have any more room we still increase ret + // + if (ret++ < n) { + *str++ = *fmt++; + } continue; } - + switch (*fmt) { case 'd': default: break; } } - + return ret; } diff --git a/src/kaleid/common/status.c b/kaleid/common/status.c similarity index 97% rename from src/kaleid/common/status.c rename to kaleid/common/status.c index c5139fe..457e741 100644 --- a/src/kaleid/common/status.c +++ b/kaleid/common/status.c @@ -9,6 +9,9 @@ #include +error_t errno = 0; + +/* static const char *descriptions[] = { [-SUCCESS] = "Success", [-FAILED] = "Failed (no precision)", @@ -28,4 +31,4 @@ const char *describe_status(status_t status) // XXX return ""; } - +*/ diff --git a/kaleid/common/string.c b/kaleid/common/string.c new file mode 100644 index 0000000..fafaf89 --- /dev/null +++ b/kaleid/common/string.c @@ -0,0 +1,301 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: String-related functions // +//----------------------------------------------------------------------------// + + +#include + +// +// Compare two strings +// +int strcmp(const char *str1, const char *str2) +{ + while (*str1 == *str2 && *str2) str1++, str2++; + + return *(uchar *)str1 - *(uchar *)str2; +} + +// +// Compare at most n bytes of two strings +// +int strncmp(const char *str1, const char *str2, size_t n) +{ + size_t it = 0; + + while (*str1 == *str2 && *str2 && it < n) str1++, str2++, it++; + + return *(uchar *)str1 - *(uchar *)str2; +} + +// +// Return str's length +// +size_t strlen(const char *str) +{ + const char *base = str; + + while (*str) str++; + + return str - base; +} + +// +// Return a pointer to the first occurence of ch in str, +// or str's null-terminator if none is found +// +char *strchrnul(const char *str, int ch) +{ + while ((*str && *str != (char)ch)) str++; + + return (char *)str; +} + +// +// Return a pointer to the first occurence of ch in str, +// NULL if none is found +// +char *strchr(const char *str, int ch) +{ + while ((*str && *str != (char)ch)) str++; + + return *str ? (char *)str : NULL; +} + +// +// Return a point to the last occurence of ch in str, +// NULL if none is found +// +char *strrchr(const char *str, int ch) +{ + char *ptr = NULL; + + while (*str) { + if (*str == ch) { + ptr = (char *)str; + } + str++; + } + + return ptr; +} + +// +// Return the length of the longest inital segment of str +// that only contains characters in acc +// +size_t strspn(const char *str, const char *acc) +{ + const char *ptr = str; + + while (*ptr && strchr(acc, *ptr) != NULL) ptr++; + + return ptr - str; +} + +// +// Return the length of the longest initial segment of str +// that does not contain any character in rej +// +size_t strcspn(const char *str, const char *rej) +{ + const char *ptr = str; + + while (*ptr && strchr(rej, *ptr) == NULL) ptr++; + + return ptr - str; +} + +// +// Return the first occurence in str of any byte in acc +// +char *strpbrk(const char *str, const char *acc) +{ + str += strcspn(str, acc); + + return *str ? (char *)str : NULL; +} + +// +// Return the first occurence of the substring needle +// in the string haystack, NULL if none is found +// Null-terminators aren't compared +// +char *strstr(const char *haystack, const char *needle) +{ + const size_t needle_size = strlen(needle); + + // + // Moves haystack to first occurence of the needle's first byte + // + while ((haystack = strchr(haystack, *needle)) != NULL) { + if (strncmp(haystack, needle, needle_size) == 0) { + return (char *)haystack; + } + } + + return NULL; +} + +// +// Tokenize a string, using saveptr as a savestate +// We let a segmentation fault happen if *saveptr == NULL +// +char *strtok_r(char *restrict str, const char *restrict delim, char **restrict saveptr) +{ + assert(*saveptr != NULL); + + if (str == NULL) str = *saveptr; + + // + // Skip initial segments composed only of delimiters + // + str += strspn(str, delim); + + // + // If str is empty, store it in saveptr so that next call + // still finds an empty strings and returns NULL + // + if (*str == 0) { + *saveptr = str; + return NULL; + } + + char *ptr = str, *tok_end = strpbrk(str, delim); + + // + // If we found the last token, set *saveptr to a str's null-terminator + // Otherwise, null-terminate token and save next byte + // + + if (tok_end == NULL) { + while (*ptr) ptr++; + *saveptr = ptr; + } + + else { + *tok_end = 0; + *saveptr = tok_end + 1; + } + + return str; +} + +// +// Tokenize a string in a very thread-unsafe way +// +char *strtok(char *restrict str, const char *restrict delim) +{ + static char *saveptr = NULL; + + KalAssert(FALSE); + + if (str) saveptr = str; + + return strtok_r(str, delim, &saveptr); +} + +// +// Copy the string src into dest +// +char *strcpy(char *restrict dest, const char *restrict src) +{ + char *base = dest; + + while ((*dest++ = *src++)); + + return base; +} + +// +// strcpy() but always writes n bytes +// Will not null-terminate for strings longer than n bytes +// +char *strncpy(char *restrict dest, const char *restrict src, size_t n) +{ + size_t it; + + for (it = 0; it < n && src[it]; it++) { + dest[it] = src[it]; + } + + while (it < n) dest[it++] = 0; + + return dest; +} + +// +// Copies at most n-1 bytes from src to dest, then fills +// the rest with 0; dest[n] is guanranteed to be '\0' +// +// Returns TRUE if dest would have been null-terminated +// by ordinary strncpy(), and FALSE otherwise +// +int xstrncpy(char *restrict dest, const char *restrict src, size_t n) +{ + size_t it; + + for (it = 0; it < n - 1 && src[it]; it++) { + dest[it] = src[it]; + } + + // + // Was the copy complete? + // + if (it == n) { + if (dest[n] == 0) { + return TRUE; + } + + dest[n] = 0; + return FALSE; + } + + while (it < n) dest[it++] = 0; + + return TRUE; +} + +// +// XXX strcat family +// +char *strcat (char *restrict, const char *restrict); +char *strncat (char *restrict, const char *restrict, size_t); +int *xstrncat(char *restrict, const char *restrict, size_t); + +// +// Reverses the string src, putting the result into dest +// +char *strrev(char *restrict dest, const char *restrict src) +{ + char *orig = dest; + size_t n = strlen(src); + + dest[n--] = '\0'; + + while ((*dest++ = src[n--])); + + return orig; +} + +// +// Reverses a string, modifying it +// +char *strrev2(char *str) +{ + char ch, *orig = str; + size_t n = strlen(str); + char *temp = str + n - 1; + + while (temp > str) { + ch = *temp; + *temp-- = *str; + *str++ = ch; + } + + return orig; +} diff --git a/src/kaleid/kernel/io/ports.c b/kaleid/common/strtol.c similarity index 62% rename from src/kaleid/kernel/io/ports.c rename to kaleid/common/strtol.c index 3f44417..2e1aad6 100644 --- a/src/kaleid/kernel/io/ports.c +++ b/kaleid/common/strtol.c @@ -4,10 +4,24 @@ // Authors: spectral` // // NeoX // // // -// Desc: Ports I/O // +// Desc: strto(u)l functions // //----------------------------------------------------------------------------// -#include +#include +long strtol(const char *str, char **endp, int base) { + (void)str; + (void)endp; + (void)base; + errno = ENOSYS; + return 0; +} +ulong strtoul(const char *str, char **endp, int base) { + (void)str; + (void)endp; + (void)base; + errno = ENOSYS; + return 0; +} diff --git a/src/kaleid/include/kalassrt.h b/kaleid/include/common/kalassrt.h similarity index 70% rename from src/kaleid/include/kalassrt.h rename to kaleid/include/common/kalassrt.h index 3c99b2d..cf4ddbb 100644 --- a/src/kaleid/include/kalassrt.h +++ b/kaleid/include/common/kalassrt.h @@ -18,27 +18,57 @@ #define noreturn __attribute__((__noreturn__)) #endif -#ifndef unlikely(x) +#ifndef unlikely #define unlikely(x) (__builtin_expect((x), 0)) #endif +#ifndef static_assert +#define static_assert _Static_assert +#endif + +//------------------------------------------// +// API compatibility checks // +//------------------------------------------// + +#define _SA_MSG "Incompatible type sizes" +static_assert(sizeof(char) == 1, _SA_MSG); +static_assert(sizeof(short) == 2, _SA_MSG); +static_assert(sizeof(int) == 4, _SA_MSG); +static_assert(sizeof(long) == 8, _SA_MSG); +static_assert(sizeof(void *) == 8, _SA_MSG); +#undef _SA_MSG + //------------------------------------------// // When debugging // //------------------------------------------// #if !defined(_NO_DEBUG) && !defined(NDEBUG) && !defined(assert) +#ifdef _OSK_SOURCE + // -// Failed assert handler +// Failed assert handler // noreturn void _assert_handler(const char *, const char *, int, const char *); +// +// Checks whether (x) holds, if not call _assert_handler +// #define assert(x) \ do { \ - if unlikely(!(x)) \ + if unlikely (!(x)) \ _assert_handler(#x, __FILE__, __LINE__, __func__); \ } while (0); +#else + +// +// When not building for OS/K, use the system's assert +// +#include + +#endif + //------------------------------------------// // When not debugging // //------------------------------------------// @@ -54,7 +84,7 @@ noreturn void _assert_handler(const char *, const char *, int, const char *); #endif #ifndef assert -#define assert(x) +#define assert(x) ((void)0) #endif #endif @@ -72,7 +102,7 @@ noreturn void _assert_handler(const char *, const char *, int, const char *); #endif //------------------------------------------// -// End of // +// End of header // //------------------------------------------// #endif diff --git a/src/kaleid/include/kalcrt.h b/kaleid/include/common/kalcrt.h similarity index 61% rename from src/kaleid/include/kalcrt.h rename to kaleid/include/common/kalcrt.h index 534533b..75e34e1 100644 --- a/src/kaleid/include/kalcrt.h +++ b/kaleid/include/common/kalcrt.h @@ -14,31 +14,37 @@ // Typedefs // //------------------------------------------// -#ifndef __size_t -#define __size_t +#ifndef __error_t_defined +#define __error_t_defined +typedef int error_t; +#endif + +#ifndef __size_t_defined +#define __size_t_defined typedef unsigned long size_t; #endif -#ifndef __status_t -#define __status_t -typedef signed long status_t; -#endif - -#ifndef __va_list -#define __va_list +#ifndef __va_list_defined +#define __va_list_defined typedef __builtin_va_list va_list; #endif -#ifndef __div_t -#define __div_t +#ifndef __div_t_defined +#define __div_t_defined typedef struct { int quot, rem; } div_t; #endif -#ifndef __ldiv_t -#define __ldiv_t +#ifndef __ldiv_t_defined +#define __ldiv_t_defined typedef struct { long quot, rem; } ldiv_t; #endif +//------------------------------------------// +// Global variables // +//------------------------------------------// + +extern error_t errno; + //------------------------------------------// // Macros // //------------------------------------------// @@ -59,8 +65,8 @@ typedef struct { long quot, rem; } ldiv_t; #define va_arg __builtin_va_arg #endif -#ifndef va_next -#define va_next __builtin_va_next +#ifndef va_copy +#define va_copy __builtin_va_copy #endif #ifndef va_end @@ -89,7 +95,9 @@ void *memchrw(const void *, int, size_t); void *memchrd(const void *, int, size_t); void *memchrq(const void *, long, size_t); -void *memcpy(void *, const void *, size_t); +void *memrchr(const void *, int, size_t); + +void *memcpy(void *restrict, const void *restrict, size_t); void *memmove(void *, const void *, size_t); void *memzero(void *, size_t); @@ -99,11 +107,33 @@ int memcmp(const void *, const void *, size_t); // String manipulation utilities // //------------------------------------------// -size_t strlen(const char *); -char *strcpy(char *, const char *); -char *strncpy(char *, const char *, size_t); -char *strrev(char *, const char *); -char *reverse(char *); +size_t strlen(const char *); +size_t strspn(const char *, const char *); +size_t strcspn(const char *, const char *); + +int strcmp(const char *, const char *); +int strncmp(const char *, const char *, size_t); + +char *strchr(const char *, int); +char *strrchr(const char *, int); +char *strchrnul(const char *, int); + +char *strstr(const char *, const char *); +char *strpbrk(const char *, const char *); + +char *strtok(char *restrict, const char *restrict); +char *strtok_r(char *restrict, const char *restrict, char **restrict); + +char *strcpy (char *restrict, const char *restrict); +char *strncpy (char *restrict, const char *restrict, size_t); +int xstrncpy(char *restrict, const char *restrict, size_t); + +char *strcat (char *restrict, const char *restrict); +char *strncat (char *restrict, const char *restrict, size_t); +int *xstrncat(char *restrict, const char *restrict, size_t); + +char *strrev(char *restrict, const char *restrict); +char *strrev2(char *); int sprintf(char *, const char *, ...); int snprintf(char *, size_t, const char *, ...); @@ -111,20 +141,21 @@ int vsprintf(char *, const char *, va_list); int vsnprintf(char *, size_t, const char *, va_list); //------------------------------------------// -// Type conversion utilities // +// Type conversion utilities // //------------------------------------------// -int *atoi(const char *); -long *atol(const char *); - char *itoa(int, char *, int); char *ltoa(long, char *, int); - char *utoa(unsigned int, char *, int); char *ultoa(unsigned long, char *, int); -long strtol(const char *, char **, int); -unsigned long strtoul(const char *, char **, int); +int atoi(const char *); +long atol(const char *); +unsigned int atou(const char *); +unsigned long atoul(const char *); + +long strtol (const char *restrict, char **restrict, int); +unsigned long strtoul(const char *restrict, char **restrict, int); //------------------------------------------// // RNG utilities // @@ -133,38 +164,35 @@ unsigned long strtoul(const char *, char **, int); int rand(void); void srand(unsigned int); +//------------------------------------------// +// Time utilities // +//------------------------------------------// + //------------------------------------------// // Diverse utilities // //------------------------------------------// -const char *describe_status(status_t) _NO_MASK; +char *strerror(int); +char *strsignal(int); //------------------------------------------// // Arithmetical macros // //------------------------------------------// -#ifndef abs -#define abs(x) ((x) < 0 ? -x : x) +#ifndef __abs +#define __abs +static inline int abs(int x) +{ + return x < 0 ? -x : x; +} #endif -#ifndef labs -#define labs(x) ((x) < 0 ? -x : x) -#endif - -#ifndef min -#define min(x,y) ((x) < (y) ? (x) : (y)) -#endif - -#ifndef lmin -#define lmin(x,y) ((x) < (y) ? (x) : (y)) -#endif - -#ifndef max -#define max(x,y) ((x) < (y) ? (x) : (y)) -#endif - -#ifndef lmax -#define lmax(x,y) ((x) < (y) ? (x) : (y)) +#ifndef __labs +#define __labs +static inline long labs(long x) +{ + return x < 0 ? -x : x; +} #endif #ifndef __div @@ -190,7 +218,7 @@ static inline ldiv_t ldiv(long __x, long __y) #endif //------------------------------------------// -// End of // +// End of header // //------------------------------------------// #endif diff --git a/src/kaleid/include/kaldefs.h b/kaleid/include/common/kaldefs.h similarity index 71% rename from src/kaleid/include/kaldefs.h rename to kaleid/include/common/kaldefs.h index 7341804..9dbf1be 100644 --- a/src/kaleid/include/kaldefs.h +++ b/kaleid/include/common/kaldefs.h @@ -31,13 +31,36 @@ #endif //------------------------------------------// -// Keywords and attributes // +// Keywords // //------------------------------------------// -#ifndef alignof +#ifndef __alignof_is_defined +#define __alignof_is_defined #define alignof _Alignof #endif +#ifndef __alignas_is_defined +#define __alignas_is_defined +#define alignas _Alignas +#endif + +#ifndef __bool_true_false_are_defined +#define __bool_true_false_are_defined +# define bool _Bool +# define true 1 +# define false 0 +# ifndef TRUE +# define TRUE 1 +# endif +# ifndef FALSE +# define FALSE 0 +# endif +#endif + +//------------------------------------------// +// Attributes and macros // +//------------------------------------------// + #ifndef PACKED #define PACKED __attribute__((__packed__)) #endif @@ -50,7 +73,7 @@ #define likely(x) (__builtin_expect((x), 1)) #endif -#ifndef unlikely(x) +#ifndef unlikely #define unlikely(x) (__builtin_expect((x), 0)) #endif @@ -63,27 +86,7 @@ #endif //------------------------------------------// -// Values for status_t // -//------------------------------------------// - -#define STATUS_FAILED(x) ((x) < 0)) -#define STATUS_SUCCESS(x) (!STATUS_FAILED(x)) - -#define SUCCESS (0) // everything went fine - -#define FAILED (-1) -#define ERROR FAILED // something went wrong -#define NOT_PERMITTED (-2) -#define ACCESS_DENIED (-3) - -#define BAD_ARGUMENT (-4) // invalid arguments -#define BAD_ARG_RANGE (-5) // arguments out of range -#define BAD_ARG_NULL (-6) // unexpected NULL argument - -#define TRY_AGAIN (-7) // EAGAIN - -//------------------------------------------// -// End of // +// End of header // //------------------------------------------// #endif diff --git a/kaleid/include/common/kalerror.h b/kaleid/include/common/kalerror.h new file mode 100644 index 0000000..ce8b2c4 --- /dev/null +++ b/kaleid/include/common/kalerror.h @@ -0,0 +1,63 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Values for errno_t and errno // +//----------------------------------------------------------------------------// + +#ifndef _KALERROR_H +#define _KALERROR_H + +//------------------------------------------// +// Preprocessor constants // +//------------------------------------------// + +// Everything went fine +#define EOK 0 + +// Operation not permitted +#define EPERM 1 + +// No such file or directory +#define ENOENT 2 + +// No such process +#define ESRCH 3 + +// Syscall interrupted (e.g. by signal) +#define EINTR 4 + +// I/0 error +#define EIO 5 + +// No such device or address +#define ENXIO 6 + +// Argument list too long +#define E2BIG 7 + +// Not an executable format +#define ENOEXEC 8 + +// Bad file number +#define EBADF 9 + +// Invalid argument +#define EINVAL 22 + +// Functionality not implemented +#define ENOSYS 38 + +// Component crashed +#define ECRASH 500 + +// System is panicking +#define EPANIC 600 + +//------------------------------------------// +// End of header // +//------------------------------------------// + +#endif diff --git a/src/kaleid/include/kallims.h b/kaleid/include/common/kallims.h similarity index 95% rename from src/kaleid/include/kallims.h rename to kaleid/include/common/kallims.h index ac5b158..9afd35d 100644 --- a/src/kaleid/include/kallims.h +++ b/kaleid/include/common/kallims.h @@ -8,6 +8,7 @@ //----------------------------------------------------------------------------// #ifndef _KALLIMS_H +#define _KALLIMS_H //------------------------------------------// // Data sizes blocks // @@ -85,10 +86,10 @@ #define DATA_CHAR_LIMITS_BLOCK # ifdef __CHAR_UNSIGNED__ # define CHAR_MIN ((char)0) -# define CHAR_MAX UCHAR_MAX +# define CHAR_MAX ((char)UCHAR_MAX) # else -# define CHAR_MIN SCHAR_MIN -# define CHAR_MAX SCHAR_MAX +# define CHAR_MIN ((char)SCHAR_MIN) +# define CHAR_MAX ((char)SCHAR_MAX) # endif #endif @@ -110,7 +111,7 @@ #endif //------------------------------------------// -// End of // +// End of header // //------------------------------------------// #endif diff --git a/kaleid/include/common/kallist.h b/kaleid/include/common/kallist.h new file mode 100644 index 0000000..96c5f9d --- /dev/null +++ b/kaleid/include/common/kallist.h @@ -0,0 +1,271 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Doubly linked lists implementation // +//----------------------------------------------------------------------------// + +#ifndef _KALLIST_H +#define _KALLIST_H + +#ifdef _KALEID_KERNEL +#error "kallist.h - Not ready for kernel compilation" +#endif + +#ifndef _KALASSRT_H +#include +#endif + +#ifndef _KALKERN_LOCKS_H +#include +#endif + +// +// XXX ¯\_(ツ)_/¯ +// +void *malloc(long); +void free(void *); + +#define AllocMemory malloc +#define FreeMemory free + +//------------------------------------------// +// Data structures // +//------------------------------------------// + +typedef struct sListHead_t { + Lock_t *lock; + unsigned long length; + struct sListNode_t *first; + struct sListNode_t *last; +} ListHead_t; + +typedef struct sListNode_t { + void *data; + ListHead_t *head; + struct sListNode_t *prev; + struct sListNode_t *next; +} ListNode_t; + +//------------------------------------------// +// Functions // +//------------------------------------------// + +// +// Create a list head with an extern lock +// +static inline ListHead_t +*CreateListHeadWithLock(Lock_t *lock) +{ + ListHead_t *head = AllocMemory(sizeof(ListHead_t)); + + if (head == NULL) return NULL; + + head->first = head->last = NULL; + head->length = 0; + + head->lock = lock; + + return head; +} + +// +// Create a liste head +// +static inline ListHead_t +*CreateListHead(void) +{ + return CreateListHeadWithLock(NULL); +} + +// +// Create a node +// +static inline ListNode_t +*CreateNode(void *data) +{ + ListNode_t *node = AllocMemory(sizeof(ListNode_t)); + + if (node == NULL) return NULL; + + node->data = data; + node->head = NULL; + node->prev = node->next = NULL; + + return node; +} + +// +// Prepend node at beginning of list +// +static inline ListHead_t +*PrependNode(ListHead_t *head, ListNode_t *node) +{ + KalAssert(head && node); + + node->head = head; + node->prev = NULL; + + if (head->length > 0) { + node->next = head->first; + head->first->prev = node; + head->first = node; + } + + else { + head->first = node; + head->last = node; + node->next = NULL; + } + + head->length++; + + return head; +} + +// +// Append node at end of list +// +static inline ListHead_t +*AppendNode(ListHead_t *head, ListNode_t *node) +{ + KalAssert(head && node); + + node->head = head; + node->next = NULL; + + if (head->length > 0) { + node->prev = head->last; + head->last->next = node; + head->last = node; + } + + else { + head->first = node; + head->last = node; + node->prev = NULL; + } + + head->length++; + + return head; +} + +// +// Insert node2 before node1 +// +static inline ListHead_t +*AddNodeBefore(ListHead_t *head, ListNode_t *node1, ListNode_t *node2) +{ + KalAssert(head && node1 && node2 && node1->head == head); + + if (head->first == node1) { + return PrependNode(head, node2); + } + + node2->head = head; + node2->next = node1; + node2->prev = node1->prev; + + // node1->prev does exist + // or node1 would be first + node1->prev->next = node2; + node1->prev = node2; + + head->length++; + + return head; +} + +// +// Insert node2 after node1 +// +static inline ListHead_t +*AddNodeAfter(ListHead_t *head, ListNode_t *node1, ListNode_t *node2) +{ + KalAssert(head && node1 && node2 && node1->head == head); + + if (head->last == node1) { + return AppendNode(head, node2); + } + + node2->head = head; + node2->prev = node1; + node2->next = node1->next; + + node1->next->prev = node2; + node1->next = node2; + + head->length++; + + return head; +} + +// +// Remove node of list +// +static inline ListHead_t +*RemoveNode(ListHead_t *head, ListNode_t *node) +{ + KalAssert(head && node && head->length > 0 && node->head == head); + + if (head->length == 1) { + head->first = head->last = NULL; + goto leave; + } + + if (head->first == node) { + head->first = node->next; + node->next->prev = NULL; + } + + else if (head->last == node) { + head->last = node->prev; + node->prev->next = NULL; + } + + else { + node->prev->next = node->next; + node->next->prev = node->prev; + } + +leave: + head->length--; + FreeMemory(node); + + return head; +} + +// +// Free a node +// +static inline void +DestroyNode(ListNode_t *node) +{ + KalAssert(node); + FreeMemory(node); +} + +// +// Free a list head +// +static inline void +DestroyListHead(ListHead_t *head) +{ + KalAssert(head); + FreeMemory(head); +} + +// +// Access a node's data +// +#define GetNodeData(node, type) ((type)(node)->data) + +//------------------------------------------// +// End of header // +//------------------------------------------// + +#endif + diff --git a/src/kaleid/include/kalmask.h b/kaleid/include/common/kalmask.h similarity index 77% rename from src/kaleid/include/kalmask.h rename to kaleid/include/common/kalmask.h index 5c9870e..0295bd0 100644 --- a/src/kaleid/include/kalmask.h +++ b/kaleid/include/common/kalmask.h @@ -34,10 +34,31 @@ //------------------------------------------// #define strlen _osk_strlen +#define strspn _osk_strspn +#define strcspn _osk_strcspn + +#define strcmp _osk_strcmp +#define strncmp _osk_strncmp + +#define strchr _osk_strchr +#define strrchr _osk_strrchr + +#define strstr _osk_strstr +#define strpbrk _osk_strpbrk + +#define strtok _osk_strtok +#define strtok_r _osk_strtok_r + #define strcpy _osk_strcpy #define strncpy _osk_strncpy +#define xstrncpy _osk_xstrncpy + +#define strcat _osk_strcat +#define strncat _osk_strncat +#define xstrncat _osk_xstrncat + #define strrev _osk_strrev -#define reverse _osk_reverse +#define strrev2 _osk_strrev2 #define sprintf _osk_sprintf #define snprintf _osk_snprintf @@ -46,15 +67,17 @@ //------------------------------------------// -#define atoi _osk_atoi -#define atol _osk_atol #define itoa _osk_itoa #define ltoa _osk_ltoa - #define utoa _osk_utoa #define ultoa _osk_ultoa +#define atoi _osk_atoi +#define atol _osk_atol +#define atou _osk_atou +#define atoul _osk_atoul + #define strtol _osk_strtol #define strtoul _osk_strtoul @@ -81,7 +104,11 @@ #define ldiv _osk_ldiv //------------------------------------------// -// End of // + +#define strerror _osk_strerror + +//------------------------------------------// +// End of header // //------------------------------------------// #endif diff --git a/src/kaleid/include/kaltypes.h b/kaleid/include/common/kaltypes.h similarity index 59% rename from src/kaleid/include/kaltypes.h rename to kaleid/include/common/kaltypes.h index 6814644..6823ddb 100644 --- a/src/kaleid/include/kaltypes.h +++ b/kaleid/include/common/kaltypes.h @@ -27,45 +27,74 @@ typedef long double ldouble; #endif //------------------------------------------// -// Other standard integer types // +// Miscellaneous types // //------------------------------------------// -#ifndef __size_t -#define __size_t +#ifndef __size_t_defined +#define __size_t_defined typedef unsigned long size_t; #endif -#ifndef __ssize_t -#define __ssize_t +#ifndef __ssize_t_defined +#define __ssize_t_defined typedef signed long ssize_t; #endif -#ifndef __wchar_t -#define __wchar_t +#ifndef __wchar_t_defined +#define __wchar_t_defined typedef signed int wchar_t; #endif -#ifndef __off_t -#define __off_t +#ifndef __off_t_defined +#define __off_t_defined typedef unsigned long off_t; #endif +//------------------------------------------// +// Standard fixed-width integer types // +//------------------------------------------// + +#ifndef __ptrdiff_t_defined +#define __ptrdiff_t_defined +typedef signed long ptrdiff_t; +#endif + +#ifndef __intptr_t_defined +#define __intptr_t_defined +typedef signed long intptr_t; +#endif + +#ifndef __uintptr_t_defined +#define __uintptr_t_defined +typedef unsigned long uintptr_t; +#endif + +#ifndef __intmax_t_defined +#define __intmax_t_defined +typedef signed long intmax_t; +#endif + +#ifndef __uintmax_t_defined +#define __uintmax_t_defined +typedef unsigned long uintmax_t; +#endif + //------------------------------------------// // Special types // //------------------------------------------// -#ifndef __va_list -#define __va_list -typedef __builtin_va_list va_list; +#ifndef __va_list_defined +#define __va_list_defined +typedef __builtin_va_list va_list; #endif -#ifndef __div_t -#define __div_t +#ifndef __div_t_defined +#define __div_t_defined typedef struct { int quot, rem; } div_t; #endif -#ifndef __ldiv_t -#define __ldiv_t +#ifndef __ldiv_t_defined +#define __ldiv_t_defined typedef struct { long quot, rem; } ldiv_t; #endif @@ -74,13 +103,18 @@ typedef struct { long quot, rem; } ldiv_t; // Kaleid-specific types // //------------------------------------------// -#ifndef __status_t -#define __status_t -typedef signed long status_t; +#ifndef __error_t_defined +#define __error_t_defined +typedef int error_t; +#endif + +#ifndef __port_t_defined +#define __port_t_defined +typedef ushort port_t; #endif //------------------------------------------// -// End of // +// End of header // //------------------------------------------// #endif diff --git a/src/kaleid/include/kaleid.h b/kaleid/include/kaleid.h similarity index 59% rename from src/kaleid/include/kaleid.h rename to kaleid/include/kaleid.h index a46f317..da81fce 100644 --- a/src/kaleid/include/kaleid.h +++ b/kaleid/include/kaleid.h @@ -22,32 +22,74 @@ #if !defined(_OSK_SOURCE) # ifndef _KALMASK_H -# include +# include # endif #endif +//------------------------------------------// +// Building in C++ // +//------------------------------------------// + +#ifdef __cplusplus__ +extern "C" { +#endif + //------------------------------------------// // Include common part of API // //------------------------------------------// #ifndef _KALDEFS_H -#include +#include +#endif + +#ifndef _KALERROR_H +#include #endif #ifndef _KALTYPES_H -#include +#include +#endif + +#ifndef _KALLIMS_H +#include #endif #ifndef _KALASSRT_H -#include +#include #endif #ifndef _KALCRT_H -#include +#include #endif //------------------------------------------// -// End of // +// Include kernel headers // +//------------------------------------------// + +#ifdef _KALEID_KERNEL + +#ifndef _KALKERN_H +#include +#endif + +#else + +#ifndef _KALKERN_LOCKS_H +#include +#endif + +#endif + +//------------------------------------------// +// Building in C++ // +//------------------------------------------// + +#ifdef __cplusplus__ +} +#endif + +//------------------------------------------// +// End of header // //------------------------------------------// #endif diff --git a/src/kaleid/include/kalkern.h b/kaleid/include/kalkern.h similarity index 72% rename from src/kaleid/include/kalkern.h rename to kaleid/include/kalkern.h index 40f0625..df15c7d 100644 --- a/src/kaleid/include/kalkern.h +++ b/kaleid/include/kalkern.h @@ -7,9 +7,6 @@ // Desc: Kaleid Kernel main include file // //----------------------------------------------------------------------------// -#ifndef _KALKERN_H -#define _KALKERN_H - //------------------------------------------// // Dependencies // //------------------------------------------// @@ -18,20 +15,31 @@ #include #endif -#ifndef _KALKERN_CONFIG_H -#include +//------------------------------------------// +// Start of header // +//------------------------------------------// + +#ifndef _KALKERN_H +#define _KALKERN_H + +//------------------------------------------// +// Kernel headers // +//------------------------------------------// + +#ifndef _KALKERN_BASE_H +#include +#endif + +#ifndef _KALKERN_LOCKS_H +#include +#endif + +#ifndef _KALKERN_TERM_H +#include #endif //------------------------------------------// -// Macros // -//------------------------------------------// - -#define DisableInterrupts() asm volatile ("cli") -#define EnableInterrupts() asm volatile ("sti") -#define HaltCPU() asm volatile ("hlt") - -//------------------------------------------// -// End of // +// End of header // //------------------------------------------// #endif diff --git a/kaleid/include/kernel/kernbase.h b/kaleid/include/kernel/kernbase.h new file mode 100644 index 0000000..171c048 --- /dev/null +++ b/kaleid/include/kernel/kernbase.h @@ -0,0 +1,205 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Kaleid Kernel base types and functionalities // +//----------------------------------------------------------------------------// + +//------------------------------------------// +// Dependencies // +//------------------------------------------// + +#ifndef _KALEID_H +#include +#endif + +//------------------------------------------// +// Start of header // +//------------------------------------------// + +#ifndef _KALKERN_BASE_H +#define _KALKERN_BASE_H + +//------------------------------------------// +// Elementary types // +//------------------------------------------// + +typedef struct sLock_t volatile Lock_t; +typedef struct sThread_t Thread_t; +typedef struct sProcess_t Process_t; +typedef struct sTerminal_t Terminal_t; +typedef struct sListHead_t ListHead_t; +typedef struct sListNode_t ListNode_t; + +//------------------------------------------// +// Values for __kstate // +//------------------------------------------// + +// +// Current state of the kernel +// +typedef enum { + // the kernel is booting + KSTATE_INIT, + + // the kernel is not running a process + KSTATE_KERNEL, + + // a process is running in kernel mode + KSTATE_PROCESS, + + // the kernel is panicking + KSTATE_PANIC, + +} KernelState_t; + +//------------------------------------------// +// Multiprocessor misc. // +//------------------------------------------// + +#ifndef NCPU +#define NCPU 4 +#endif + +#define GetCurCPU() 0 + +// +// Declare an (extern) CPU-local variable +// +#define __DECLARE_PER_CPU(_X, _Tp, _Qual) \ + _Qual _Tp __ ## _X [NCPU]; \ + static inline _Tp Get ## _X (void) \ + { return __ ## _X [GetCurCPU()]; } \ + static inline void _Set ## _X (_Tp _Y) \ + { (__ ## _X [GetCurCPU()] = _Y); } + +#define DECLARE_PER_CPU(_X, _Tp) \ + __DECLARE_PER_CPU(_X, _Tp, extern) + +#define LOCAL_DEC_PER_CPU(_X, _Tp) \ + __DECLARE_PER_CPU(_X, _Tp, static) + +// +// Actually creates a CPU-local variable +// +#define CREATE_PER_CPU(_X, _Tp) \ + _Tp __ ## _X [NCPU] = { (_Tp) 0 } + + +//------------------------------------------// +// Global constants // +//------------------------------------------// + +// XXX +DECLARE_PER_CPU(PanicStr, const char *); + +DECLARE_PER_CPU(KernState, KernelState_t); + +DECLARE_PER_CPU(_StdOut, Terminal_t *); +DECLARE_PER_CPU(_StdDbg, Terminal_t *); + +DECLARE_PER_CPU(CurProc, Process_t *); +DECLARE_PER_CPU(CurThread, Thread_t *); + +//------------------------------------------// +// Macros for manipulating said // +// global constants // +//------------------------------------------// + +#define SetPanicStr(str) \ + do { \ + SetKernState(KSTATE_PANIC); \ + _SetPanicStr(str); \ + } while (0) + +#define SetKernState(x) \ + do { \ + _SetKernState(x); \ + } while (0) + +#define GetStdOut() (GetCurProc() == NULL ? Get_StdOut() : NULL) +#define SetStdOut(tm) \ + do { \ + if (GetCurProc() == NULL) \ + _Set_StdOut(tm); \ + } while (0); + +#define GetStdDbg() (GetCurProc() == NULL ? Get_StdDbg() : NULL) +#define SetStdDbg(tm) \ + do { \ + if (GetCurProc() == NULL) \ + _Set_StdDbg(tm); \ + } while (0) + +//------------------------------------------// +// Other Macros // +//------------------------------------------// + +// +// Size of a tabulation in spaces +// Default: 4 spaces/tab +// +#define KTABSIZE 4 + +// +// Disable IRQs +// +#define DisableIRQs() asm volatile ("cli") + +// +// Enable IRQs +// +#define EnableIRQs() asm volatile ("sti") + +// +// Pause CPU until next interuption +// !!! Enables IRQs !!! +// +#define PauseCPU() asm volatile("sti\n\thlt") + +// +// Halt the CPU indefinitely +// +#define HaltCPU() do { asm volatile ("hlt"); } while (1) + +//------------------------------------------// +// Some base functions // +//------------------------------------------// + +noreturn void StartPanic(const char *); +noreturn void CrashSystem(void); + +//------------------------------------------// +// Useful I/O inlines // +//------------------------------------------// + +static inline +void WriteByteOnPort(port_t port, port_t val) +{ + asm volatile ("out %0, %1" : : "dN" (port), "a" (val)); +} + +static inline +uchar ReadByteFromPort(port_t port) +{ + errno = ENOSYS; + (void)port; + return 0; +} + +static inline +ushort ReadWordFromPort(port_t port) +{ + errno = ENOSYS; + (void)port; + return 0; +} + +//------------------------------------------// +// End of header // +//------------------------------------------// + +#endif + diff --git a/kaleid/include/kernel/kernlocks.h b/kaleid/include/kernel/kernlocks.h new file mode 100644 index 0000000..f3dd7e2 --- /dev/null +++ b/kaleid/include/kernel/kernlocks.h @@ -0,0 +1,170 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Spinlocks and mutexes // +//----------------------------------------------------------------------------// + +//------------------------------------------// +// Dependencies // +//------------------------------------------// + +#ifdef _KALEID_KERNEL + +#ifndef _KALKERN_BASE_H +#include "kernbase.h" +#endif + +#else + +#ifndef _KALEID_H +#include +#endif + +#endif + +//------------------------------------------// +// Start of header // +//------------------------------------------// + +#ifndef _KALKERN_LOCKS_H +#define _KALKERN_LOCKS_H + +//------------------------------------------// +// Types // +//------------------------------------------// + +typedef enum eLockType_t { + // + // Mutex-type lock + // + // WARNING + // AquireLock() panics when used on a mutex while not running a process + // + KLOCK_MUTEX, + + // + // Spinlock-type lock + // + KLOCK_SPINLOCK, + +} LockType_t; + +// +// "volatile" may not be actually needed +// +typedef struct sLock_t { + unsigned int initDone; // initialized? + int locked; // is locked? + LockType_t type; // lock type? +#ifdef _KALEID_KERNEL + Process_t *ownerProc; // unused + Process_t *waitingProc; // unused +#endif +} volatile Lock_t; + +//------------------------------------------// +// Functions // +//------------------------------------------// + +// +// Linux syscall... +// +#ifndef _KALEID_KERNEL +int sched_yield(void); +#endif + +// +// Initialize a lock +// +static inline +void InitLock(Lock_t *lock, LockType_t type) +{ + lock->type = type; + lock->locked = FALSE; + lock->initDone = INITOK; +#ifdef _KALEID_KERNEL + lock->ownerProc = NULL; + lock->waitingProc = NULL; +#endif +} + +// +// Alternative way to initalize a lock +// +#ifdef _KALEID_KERNEL +# define INITLOCK(type) { INITOK, FALSE, (type), NULL, NULL } +#else +# define INITLOCK(type) { INITOK, FALSE, (type) } +#endif + +// +// Destroy a lock +// +static inline +void DestroyLock(Lock_t *lock) +{ + KalAssert(lock->initDone); + + __sync_synchronize(); + lock->initDone = 0; +} + +// +// Aquire the lock +// Panic on double aquisition since that should never happen +// until we have at least a basic scheduler +// +static inline +void AquireLock(Lock_t *lock) +{ + KalAssert(lock->initDone == INITOK); + + while (!__sync_bool_compare_and_swap(&lock->locked, 0, 1)) { +#ifdef _KALEID_KERNEL + StartPanic("AquireLock on an already locked object"); +#else + if likely (lock->type == KLOCK_SPINLOCK) continue; + else sched_yield(); +#endif + } + __sync_synchronize(); +} + +// +// Release an already aquired lock +// Panic if the lock was never aquired +// +static inline +void ReleaseLock(Lock_t *lock) +{ +#ifdef _KALEID_KERNEL + KalAssert(lock->ownerProc == GetCurProc()); +#endif + + __sync_synchronize(); + lock->locked = 0; +} + +// +// Tries to aquire lock +// +static inline +bool AttemptLock(Lock_t *lock) +{ + KalAssert(lock->initDone == INITOK); + + bool retval = __sync_bool_compare_and_swap(&lock->locked, 0, 1); + + __sync_synchronize(); + + return retval; +} + +//------------------------------------------// +// End of header // +//------------------------------------------// + +#endif diff --git a/kaleid/include/kernel/kernsched.h b/kaleid/include/kernel/kernsched.h new file mode 100644 index 0000000..1026d53 --- /dev/null +++ b/kaleid/include/kernel/kernsched.h @@ -0,0 +1,102 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Scheduler header // +//----------------------------------------------------------------------------// + +//------------------------------------------// +// Dependencies // +//------------------------------------------// + +#ifndef _KALKERN_BASE_H +#include "kernbase.h" +#endif + +#ifndef _KALLIST_H +#include +#endif + +//------------------------------------------// +// Start of header // +//------------------------------------------// + +#ifndef _KALKERN_SCHED_H +#define _KALKERN_SCHED_H + +//------------------------------------------// +// Preprocessor // +//------------------------------------------// + +#define printdbg printf +#define _STR(x) #x +#define _XSTR(x) _STR(x) + +// +// States for a process +// +#define STATE_RUNNING 0 +#define STATE_RUNNABLE 1 +#define STATE_BLOCKED 2 + +// +// Time in ticks a process should be run +// +#define DEF_PROC_TSLICE 5 // 20 ticks +#define TCR_PROC_TSLICE 20000 // 20000 ticks (time critical) + +//------------------------------------------// +// List heads // +//------------------------------------------// + +DECLARE_PER_CPU(IdlePrioProcs, ListHead_t *); +DECLARE_PER_CPU(ReglPrioProcs, ListHead_t *); +DECLARE_PER_CPU(ServPrioProcs, ListHead_t *); +DECLARE_PER_CPU(TimeCritProcs, ListHead_t *); + +//------------------------------------------// +// Data types // +//------------------------------------------// + +// +// A process +// +typedef struct sProcess_t{ + + // Identifier + int pid; + + // Current priority class + int prioClass; + + // Default priority class (without boosts) + int defPrioClass; + + // Current priority level + int prioLevel; + + // Default priority level + int defPrioLevel; + + // Current state + int procState; + + // Remaining time running + ulong timeSlice; + + // Default time-slice + ulong defTimeSlice; + + // Scheduler internals + ListNode_t *schedNode; + +} Process_t; + +//------------------------------------------// +// End of header // +//------------------------------------------// + +#endif + diff --git a/kaleid/include/kernel/kernterm.h b/kaleid/include/kernel/kernterm.h new file mode 100644 index 0000000..b5c32b6 --- /dev/null +++ b/kaleid/include/kernel/kernterm.h @@ -0,0 +1,95 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Terminal functions // +//----------------------------------------------------------------------------// + +//------------------------------------------// +// Dependencies // +//------------------------------------------// + +#ifndef _KALKERN_BASE_H +#include "kernbase.h" +#endif + +//------------------------------------------// +// Start of header // +//------------------------------------------// + +#ifndef _KALKERN_TERM_H +#define _KALKERN_TERM_H + +//------------------------------------------// +// Types // +//------------------------------------------// + +// +// The VGA colors +// +typedef enum { + KTERM_COLOR_BLACK, KTERM_COLOR_BLUE, + KTERM_COLOR_GREEN, KTERM_COLOR_CYAN, + KTERM_COLOR_RED, KTERM_COLOR_MAGENTA, + KTERM_COLOR_BROWN, KTERM_COLOR_LGREY, + KTERM_COLOR_DARK_GREY, KTERM_COLOR_LBLUE, + KTERM_COLOR_LGREEN, KTERM_COLOR_LCYAN, + KTERM_COLOR_LRED, KTERM_COLOR_LMAGENTA, + KTERM_COLOR_LBROWN, KTERM_COLOR_WHITE +} TermColor_t; + +// +// Terminal structure, right now VGA and output only +// +typedef struct sTerminal_t { + + uint initDone; + Lock_t lock; + + const char *name; + const char *type; + + void *data; + + size_t width; + size_t height; + off_t currentX; + off_t currentY; + + uint tabSize; + TermColor_t fgColor; + TermColor_t bgColor; + + error_t (*ClearTermUnlocked)(Terminal_t *); + error_t (*PutOnTermUnlocked)(Terminal_t *, char); + error_t (*PrintOnTermUnlocked)(Terminal_t *, const char *); + +} Terminal_t; + +//------------------------------------------// +// Functions // +//------------------------------------------// + +void InitTerms(void); +error_t ClearTerm(Terminal_t *); +error_t PutOnTerm(Terminal_t *, char); +error_t PrintOnTerm(Terminal_t *, const char *); +error_t ChTermColor(Terminal_t *, TermColor_t, TermColor_t); + +//------------------------------------------// +// Macros // +//------------------------------------------// + +#ifndef _NO_DEBUG +# define DebugLog(...) PrintOnTerm(GetStdDbg(), __VA_ARGS__) +#else +# define DebugLog(...) +#endif + +//------------------------------------------// +// End of header // +//------------------------------------------// + +#endif diff --git a/src/kaleid/kernel/init.c b/kaleid/kernel/init/init.c similarity index 80% rename from src/kaleid/kernel/init.c rename to kaleid/kernel/init/init.c index 3a7d1cd..0887f9c 100644 --- a/src/kaleid/kernel/init.c +++ b/kaleid/kernel/init/init.c @@ -7,25 +7,22 @@ // Desc: Kernel entry point // //----------------------------------------------------------------------------// -#include -#include -#include -#include +#include // -// Entry point of kaleid-kernel.elf +// Entry point of kaleid-kernel.elf // -void StartKern(void) +noreturn void StartKern(void) { // we're not ready to deal with interrupts - DisableInterrupts(); - + DisableIRQs(); + // booting! SetKernState(KSTATE_INIT); // kernel terminals InitTerms(); - + // we're out StartPanic("Goodbye World :("); } diff --git a/src/kaleid/kernel/io/ports.h b/kaleid/kernel/init/table.c similarity index 63% rename from src/kaleid/kernel/io/ports.h rename to kaleid/kernel/init/table.c index 10799a3..4b98d25 100644 --- a/src/kaleid/kernel/io/ports.h +++ b/kaleid/kernel/init/table.c @@ -4,20 +4,18 @@ // Authors: spectral` // // NeoX // // // -// Desc: Ports I/O // +// Desc: Global constants // //----------------------------------------------------------------------------// -#ifndef _KALKERN_IO_PORTS_H -#define _KALKERN_IO_PORTS_H +#include -#ifndef _KALKERN_H -#include -#endif +CREATE_PER_CPU(PanicStr, const char *); -#define WriteByteOnPort(port,val) asm volatile ("outb %1, %0" : : "dN" (port), "a" (value)) +CREATE_PER_CPU(KernState, KernelState_t); -uchar ReadByteFromPort(port_t); -ushort ReadWordFromPort(port_t); +CREATE_PER_CPU(_StdOut, Terminal_t *); +CREATE_PER_CPU(_StdDbg, Terminal_t *); -#endif +CREATE_PER_CPU(CurProc, Process_t *); +CREATE_PER_CPU(CurThread, Thread_t *); diff --git a/src/kaleid/kernel/ke/panic.c b/kaleid/kernel/ke/panic.c similarity index 65% rename from src/kaleid/kernel/ke/panic.c rename to kaleid/kernel/ke/panic.c index 72fa83e..72fe089 100644 --- a/src/kaleid/kernel/ke/panic.c +++ b/kaleid/kernel/ke/panic.c @@ -7,62 +7,63 @@ // Desc: How NOT to panic 101 // //----------------------------------------------------------------------------// -#include -#include - #define _UNLOCKED_IO -#include +#include // -// Panic message -// -const char *__panicmsg = NULL; - -// -// Failed assert() handler +// Failed assert() handler // noreturn void _assert_handler(const char *msg, const char *file, int line, const char *func) { - // not getting out of here - DisableInterrupts(); - + DisableIRQs(); + (void)file; (void)line; (void)func; - + // XXX sprintf() to create a proper panicstr StartPanic(msg); } // -// Your best boy panic() +// Your best boy panic() +// This is CPU local... // -void StartPanic(const char *str) +noreturn void StartPanic(const char *str) { - DisableInterrupts(); + DisableIRQs(); SetKernState(KSTATE_PANIC); - ClearTermUnlocked(stdout); - + if (GetCurProc()) __CurProc[GetCurCPU()] = NULL; + if (GetStdOut() == NULL) CrashSystem(); + + GetStdOut()->ClearTermUnlocked(GetStdOut()); + if (str == NULL) { str = "(no message given)"; } - + if (GetPanicStr()) { - PrintOnTermUnlocked(stdout, "double panic!\n"); + GetStdOut()->PrintOnTermUnlocked(GetStdOut(), "double panic!\n"); HaltCPU(); } SetPanicStr(str); - // we cannot lock anything when panicking - PrintOnTermUnlocked(stdout, "panic! - "); - PrintOnTermUnlocked(stdout, str); + GetStdOut()->PrintOnTermUnlocked(GetStdOut(), "PANIC! - "); + GetStdOut()->PrintOnTermUnlocked(GetStdOut(), str); - while (TRUE) { - HaltCPU(); - } + HaltCPU(); +} + +// +// Oh well +// +noreturn void CrashSystem(void) +{ + DisableIRQs(); + HaltCPU(); } diff --git a/kaleid/kernel/ke/terminal.c b/kaleid/kernel/ke/terminal.c new file mode 100644 index 0000000..1d7439b --- /dev/null +++ b/kaleid/kernel/ke/terminal.c @@ -0,0 +1,236 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Early terminal functions // +//----------------------------------------------------------------------------// + +#include + +static Terminal_t vgaTerm; + +// +// Initialize standard output +// +void InitTerms(void) +{ + KalAssert(!GetStdOut() && vgaTerm.initDone != INITOK); + + vgaTerm.initDone = INITOK; + + SetStdDbg(&vgaTerm); + SetStdOut(&vgaTerm); + + ClearTerm(GetStdOut()); +} + +// +// Fill terminal with spaces +// +error_t ClearTerm(Terminal_t *term) +{ + error_t retcode; + + if (term == NULL) return EINVAL; + KalAssert(term->initDone == INITOK); + + AquireLock(&term->lock); + retcode = term->ClearTermUnlocked(term); + ReleaseLock(&term->lock); + + return retcode; +} + +// +// Change the color code +// +error_t ChTermColor(Terminal_t *term, TermColor_t fgColor, TermColor_t bgColor) +{ + if (fgColor > KTERM_COLOR_WHITE || bgColor > KTERM_COLOR_WHITE) + return EINVAL; + + if (term == NULL) + return EINVAL; + + AquireLock(&term->lock); + + term->fgColor = fgColor; + term->bgColor = bgColor; + + ReleaseLock(&term->lock); + + return EOK; +} + +// +// Write a single character on the terminal +// +error_t PutOnTerm(Terminal_t *term, char ch) +{ + error_t retcode; + + if (term == NULL) return EINVAL; + KalAssert(term->initDone == INITOK); + + AquireLock(&term->lock); + retcode = term->PutOnTermUnlocked(term, ch); + ReleaseLock(&term->lock); + + return retcode; +} + +// +// Print string on terminal +// +error_t PrintOnTerm(Terminal_t *term, const char *str) +{ + error_t retcode = EOK; + + if (term == NULL) return EINVAL; + KalAssert(term->initDone == INITOK); + + AquireLock(&term->lock); + while (*str && retcode == EOK) { + retcode = term->PutOnTermUnlocked(term, *str++); + } + ReleaseLock(&term->lock); + + return retcode; +} + +//----------------------------------------------------------// +// Internal functions for VGA terminals // +// These DO NOT check input correctness // +//----------------------------------------------------------// + +// +// VGA-related macros +// +#define VGA_ComputeColorCode(fg, bg) ((fg) | (bg) << 4) +#define VGA_ComputeOffset(term, x, y) ((y) * (term)->width + (x)) +#define VGA_ComputeEntry(ch, cl) (((ushort)(ch)) | (ushort)(cl) << 8) + +// +// Fill terminal with '\0' +// +error_t VGA_ClearTermUnlocked(Terminal_t *term) +{ + const uchar color = VGA_ComputeColorCode(term->fgColor, term->bgColor); + const ushort filler = VGA_ComputeEntry('\0', color); + const size_t bufsize = term->width * term->height; + + // Fill the buffer + memsetw((ushort *)term->data, filler, bufsize); + + // XXX update cursor too + term->currentX = term->currentY = 0; + + return EOK; +} + +// +// Write a single character on the terminal +// +error_t VGA_PutOnTermUnlocked(Terminal_t *term, char ch) +{ + uint i; + size_t prevY; + + if (ch == '\r') { + term->currentX = 0; + return EOK; + } + + // + // Line feed first takes us to the very end of the line + // Later in this function we actually do the line feed + // + else if (ch == '\n') { + term->currentY = term->width - 1; + } + + // + // Tabulations account for "term->tabSize" spaces + // + else if (ch == '\t') { + prevY = term->currentY; + for (i = 0; i < term->tabSize; i++) { + // + // Make sure tabulations can't spread over two lines + // + if (term->currentY == prevY) { + VGA_PutOnTermUnlocked(term, ' '); + } + } + } + + else { + ushort *buffer = (ushort *)term->data; + const size_t offset = VGA_ComputeOffset(term, term->currentY, term->currentY); + buffer[offset] = VGA_ComputeEntry(ch, VGA_ComputeColorCode(term->fgColor, term->bgColor)); + } + + // + // Did we reach the end of line? + // + if (++term->currentX == term->width) { + term->currentX = 0; + + // + // Did we reach the buffer's end? + // + if (++term->currentY == term->height) { + // + // XXX scroll up + // + term->currentY = 0; + } + } + + // + // Nothing can go wrong + // + return EOK; +} + +// +// Print string on terminal +// +error_t VGA_PrintOnTermUnlocked(Terminal_t *term, const char *str) +{ + error_t retcode = EOK; + + while (*str && retcode == EOK) { + retcode = term->PutOnTermUnlocked(term, *str++); + } + + return retcode; +} + +// +// VGA output +// +static Terminal_t vgaTerm = { + .initDone = FALSE, + .lock = INITLOCK(KLOCK_MUTEX), + + .name = "VGA Output Terminal", + .type = "VGA", + + .data = (void *)0xB8000, + .width = 80, + .height = 25, + .currentX = 0, + .currentY = 0, + + .tabSize = KTABSIZE, + .fgColor = KTERM_COLOR_LGREY, + .bgColor = KTERM_COLOR_BLACK, + + .ClearTermUnlocked = VGA_ClearTermUnlocked, + .PutOnTermUnlocked = VGA_PutOnTermUnlocked, + .PrintOnTermUnlocked = VGA_PrintOnTermUnlocked, +}; + diff --git a/kaleid/kernel/proc/Makefile b/kaleid/kernel/proc/Makefile new file mode 100644 index 0000000..8001a5e --- /dev/null +++ b/kaleid/kernel/proc/Makefile @@ -0,0 +1,4 @@ + +sched-test: + gcc -O2 -masm=intel -I../../include ./sched.c + diff --git a/kaleid/kernel/proc/sched.c b/kaleid/kernel/proc/sched.c new file mode 100644 index 0000000..b81ec45 --- /dev/null +++ b/kaleid/kernel/proc/sched.c @@ -0,0 +1,409 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Scheduling algorithm // +//----------------------------------------------------------------------------// + +#include + +#ifndef _KALEID_KERNEL + +#include +CREATE_PER_CPU(CurProc, Process_t *); + +// +// For test purpose only +// +int procslen = 9; +Process_t procs[] = { + { 0, 0, 0, 12, 12, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL }, + { 1, 2, 2, 16, 16, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL }, + { 2, 3, 3, 31, 31, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL }, + { 3, 2, 2, 1, 1, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL }, + { 4, 0, 0, 5, 5, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL }, + { 5, 0, 0, 30, 30, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL }, + { 6, 1, 1, 19, 19, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL }, + { 7, 1, 1, 0, 0, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL }, + { 8, 3, 3, 12, 12, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL }, +}; + +#endif + +// +// Set current process +// TODO Select thread, context switch +// +static inline +void SetCurProc(Process_t *proc) +{ + _SetCurProc(proc); + if (GetCurProc() != NULL) { + GetCurProc()->procState = STATE_RUNNING; + } +} + +// +// (Un)Lock priority class list heads +// + +static inline +void SchedLock(void) { +#ifdef _KALEID_KERNEL + DisableIRQs(); +#endif +} + +static inline +void SchedUnlock(void) { +#ifdef _KALEID_KERNEL + EnableIRQs(); +#endif +} + +// +// The four priority classes of OS/2 +// +CREATE_PER_CPU(IdlePrioProcs, ListHead_t *); +CREATE_PER_CPU(ReglPrioProcs, ListHead_t *); +CREATE_PER_CPU(ServPrioProcs, ListHead_t *); +CREATE_PER_CPU(TimeCritProcs, ListHead_t *); + +char *PrioClassesNames[] = { + "Idle priority class", + "Regular priority class", + "Server priority class", + "Time-critical class", +}; + +enum { IDLE_PRIO_PROC = 0, + REGL_PRIO_PROC = 1, + SERV_PRIO_PROC = 2, + TIME_CRIT_PROC = 3, +}; + +// +// Get priority class list head +// +static inline +ListHead_t *GetPrioClassHead(int prioClass) +{ + switch (prioClass) { + case TIME_CRIT_PROC: return GetTimeCritProcs(); + case SERV_PRIO_PROC: return GetServPrioProcs(); + case REGL_PRIO_PROC: return GetReglPrioProcs(); + case IDLE_PRIO_PROC: return GetIdlePrioProcs(); + default: KalAssert(FALSE && "Unknown priority class"); + } + + return NULL; +} + +// +// Determine which process is going to run first +// Return NULL for "equal" processes +// +static inline +Process_t *CompareProcs(Process_t *proc1, Process_t *proc2) +{ + KalAssert(proc1 && proc2); + + if (proc1->prioClass > proc2->prioClass) return proc1; + if (proc1->prioClass < proc2->prioClass) return proc2; + + if (proc1->prioLevel > proc2->prioLevel) return proc1; + if (proc1->prioLevel < proc2->prioLevel) return proc2; + + return NULL; // same class and level +} + +// +// Add process to schedule lists (unlocked) +// +static inline +void SchedThisProcUnlocked(Process_t *proc) +{ + KalAssert(proc && proc->procState == STATE_RUNNABLE); + + bool found = false; + ListNode_t *iterNode = NULL; + ListNode_t *procNode = CreateNode(proc); + ListHead_t *head = GetPrioClassHead(proc->prioClass); + + KalAssert(procNode && head); + + proc->schedNode = procNode; + + //printdbg("Adding process %d to '%s'\n", proc->pid, PrioClassesNames[proc->prioClass]); + + // + // Find a process with lesser priority + // + for (iterNode = head->first; iterNode; iterNode = iterNode->next) { + if (proc->prioLevel > GetNodeData(iterNode, Process_t *)->prioLevel) { + AddNodeBefore(head, iterNode, procNode); + found = true; + break; + } + } + + // + // Didn't find any process with lesser priority + // + if (found == false) { + AppendNode(head, procNode); + } +} + +// +// Add process to schedule lists +// +void SchedThisProc(Process_t *proc) +{ + SchedLock(); + + SchedThisProcUnlocked(proc); + + SchedUnlock(); +} + +// +// Selects process to schedule next +// +// WARNING +// Does not call SchedLock()/SchedUnlock() +// +static inline +Process_t *SelectSchedNext(void) +{ + if (GetTimeCritProcs()->length > 0) return GetNodeData(GetTimeCritProcs()->first, Process_t *); + if (GetServPrioProcs()->length > 0) return GetNodeData(GetServPrioProcs()->first, Process_t *); + if (GetReglPrioProcs()->length > 0) return GetNodeData(GetReglPrioProcs()->first, Process_t *); + if (GetIdlePrioProcs()->length > 0) return GetNodeData(GetIdlePrioProcs()->first, Process_t *); + + return NULL; +} + +// +// Remove running process from schedule lists +// and schedule next runnable process +// +static inline +void BlockCurProc(void) +{ + KalAssert(GetCurProc() && GetCurProc()->procState == STATE_RUNNING); + + ListNode_t *procNode = GetCurProc()->schedNode; + + GetCurProc()->procState = STATE_BLOCKED; + RemoveNode(procNode->head, procNode); + + SetCurProc(SelectSchedNext()); +} + +// +// Should we schedule another process? +// Called at each tick +// +void SchedOnTick(void) +{ + Process_t *procNext; + Process_t *winner; + + SchedLock(); + + // + // We're either idle or running something + // + KalAssert(GetCurProc() == NULL || GetCurProc()->procState == STATE_RUNNING); + + // + // Has current process spent his timeslice? + // (To be handled in CPU decisions function) + // + if (GetCurProc() != NULL) { + if (GetCurProc()->timeSlice <= 1) { + + // Restore default attributes, cancelling boosts + GetCurProc()->prioClass = GetCurProc()->defPrioClass; + GetCurProc()->prioLevel = GetCurProc()->defPrioLevel; + GetCurProc()->timeSlice = GetCurProc()->defTimeSlice; + GetCurProc()->procState = STATE_RUNNABLE; + + // Remove from list + RemoveNode(GetCurProc()->schedNode->head, GetCurProc()->schedNode); + + // Schedule again, with default attributes now + SchedThisProcUnlocked(GetCurProc()); + + // Mark as idle + SetCurProc(NULL); + } + + // + // Otherwise, make him lose a tick + // + else { + GetCurProc()->timeSlice--; + } + } + + // + // Are we idle, or scheduling next process? + // + if (GetCurProc() == NULL) { + SetCurProc(SelectSchedNext()); + goto leave; + } + + // + // Is there a higher priority process that is runnable? + // + procNext = SelectSchedNext(); + winner = CompareProcs(GetCurProc(), procNext); + + // + // Yes, procNext should preempt current process + // + if (winner == procNext) { + GetCurProc()->procState = STATE_RUNNABLE; + SchedThisProcUnlocked(GetCurProc()); + SetCurProc(procNext); + } + + // + // Current process won't be preempted and has time remaining + // +leave: + SchedUnlock(); +} + +#define PrintProc(proc) printdbg("{ %d, '%s', %d , %d}\n", (proc)->pid, \ + PrioClassesNames[(proc)->prioClass], (proc)->prioLevel, (proc)->timeSlice); + +// +// Print out process list +// +void PrintList(ListHead_t *head) +{ + KalAssert(head); + + Process_t *proc; + ListNode_t *node = head->first; + + printdbg("len: %d\n", head->length); + + while (node) { + proc = GetNodeData(node, Process_t *); + + PrintProc(proc); + + node = node->next; + } + + puts(""); +} + +// +// Initialize scheduler +// +void InitSched(void) +{ + int pid; + Process_t *proc; + + SchedLock(); + + _SetTimeCritProcs(CreateListHead()); + _SetServPrioProcs(CreateListHead()); + _SetReglPrioProcs(CreateListHead()); + _SetIdlePrioProcs(CreateListHead()); + +#ifndef _KALEID_KERNEL + for (pid = 0; pid < procslen; pid++) { + if (procs[pid].procState == STATE_RUNNABLE) { + SchedThisProcUnlocked(&procs[pid]); + } + } +#endif + + SchedUnlock(); +} + +// +// Shutdown scheduler +// +void FiniSched(void) +{ + KalAssert(GetIdlePrioProcs() && GetReglPrioProcs() && GetServPrioProcs() && GetTimeCritProcs()); + + SchedLock(); + + while (GetIdlePrioProcs()->length > 0) RemoveNode(GetIdlePrioProcs(), GetIdlePrioProcs()->first); + while (GetReglPrioProcs()->length > 0) RemoveNode(GetReglPrioProcs(), GetReglPrioProcs()->first); + while (GetServPrioProcs()->length > 0) RemoveNode(GetServPrioProcs(), GetServPrioProcs()->first); + while (GetTimeCritProcs()->length > 0) RemoveNode(GetTimeCritProcs(), GetTimeCritProcs()->first); + + DestroyListHead(GetIdlePrioProcs()); _SetIdlePrioProcs(NULL); + DestroyListHead(GetReglPrioProcs()); _SetReglPrioProcs(NULL); + DestroyListHead(GetServPrioProcs()); _SetServPrioProcs(NULL); + DestroyListHead(GetTimeCritProcs()); _SetTimeCritProcs(NULL); + + SchedUnlock(); +} + +#ifndef _KALEID_KERNEL +int main(void) +{ + InitSched(); + + puts("---------------"); + + puts("Time Critical:"); + PrintList(GetTimeCritProcs()); + + puts("Server:"); + PrintList(GetServPrioProcs()); + + puts("Regular:"); + PrintList(GetReglPrioProcs()); + + puts("Idle:"); + PrintList(GetIdlePrioProcs()); + + puts("---------------"); + + getchar(); + + int tick = 0; + + while (tick < 20) { + printf("Tick %d - Running: ", tick); + + if (GetCurProc() == NULL) { + puts("IDLE"); + } + + else { + PrintProc(GetCurProc()); + } + + if (tick == 9 || tick == 14) { + puts("Blocking current process"); + BlockCurProc(); + } + + SchedOnTick(); + + //puts("\n---------------"); + tick++; + } + + FiniSched(); + + return 0; +} +#endif + diff --git a/obj/kaleid/common/arith.S b/obj/kaleid/common/arith.S deleted file mode 100644 index 5564d39..0000000 --- a/obj/kaleid/common/arith.S +++ /dev/null @@ -1,114 +0,0 @@ - .file "arith.c" - .text - .p2align 4,,15 - .globl _osk_abs - .type _osk_abs, @function -_osk_abs: -.LFB2: - .cfi_startproc - movl %edi, %edx - movl %edi, %eax - sarl $31, %edx - xorl %edx, %eax - subl %edx, %eax - ret - .cfi_endproc -.LFE2: - .size _osk_abs, .-_osk_abs - .p2align 4,,15 - .globl _osk_labs - .type _osk_labs, @function -_osk_labs: -.LFB3: - .cfi_startproc - movq %rdi, %rdx - movq %rdi, %rax - sarq $63, %rdx - xorq %rdx, %rax - subq %rdx, %rax - ret - .cfi_endproc -.LFE3: - .size _osk_labs, .-_osk_labs - .p2align 4,,15 - .globl _osk_min - .type _osk_min, @function -_osk_min: -.LFB4: - .cfi_startproc - cmpl %edi, %esi - movl %edi, %eax - cmovle %esi, %eax - ret - .cfi_endproc -.LFE4: - .size _osk_min, .-_osk_min - .p2align 4,,15 - .globl _osk_lmin - .type _osk_lmin, @function -_osk_lmin: -.LFB5: - .cfi_startproc - cmpq %rdi, %rsi - movq %rdi, %rax - cmovle %rsi, %rax - ret - .cfi_endproc -.LFE5: - .size _osk_lmin, .-_osk_lmin - .p2align 4,,15 - .globl _osk_max - .type _osk_max, @function -_osk_max: -.LFB11: - .cfi_startproc - cmpl %esi, %edi - movl %esi, %eax - cmovle %edi, %eax - ret - .cfi_endproc -.LFE11: - .size _osk_max, .-_osk_max - .p2align 4,,15 - .globl _osk_lmax - .type _osk_lmax, @function -_osk_lmax: -.LFB13: - .cfi_startproc - cmpq %rsi, %rdi - movq %rsi, %rax - cmovle %rdi, %rax - ret - .cfi_endproc -.LFE13: - .size _osk_lmax, .-_osk_lmax - .p2align 4,,15 - .globl _osk_div - .type _osk_div, @function -_osk_div: -.LFB8: - .cfi_startproc - movl %edi, %eax - cltd - idivl %esi - salq $32, %rdx - movl %eax, %eax - orq %rdx, %rax - ret - .cfi_endproc -.LFE8: - .size _osk_div, .-_osk_div - .p2align 4,,15 - .globl _osk_ldiv - .type _osk_ldiv, @function -_osk_ldiv: -.LFB9: - .cfi_startproc - movq %rdi, %rax - cqto - idivq %rsi - ret - .cfi_endproc -.LFE9: - .size _osk_ldiv, .-_osk_ldiv - .ident "GCC: (GNU) 7.3.0" diff --git a/obj/kaleid/common/itoa.S b/obj/kaleid/common/itoa.S deleted file mode 100644 index 1f55ec6..0000000 --- a/obj/kaleid/common/itoa.S +++ /dev/null @@ -1,77 +0,0 @@ - .file "convert.c" - .text - .p2align 4,,15 - .globl itoa - .type itoa, @function -itoa: -.LFB2: - .cfi_startproc - movl %edx, %r9d - leal -2(%rdx), %edx - movl %edi, %eax - cmpl $34, %edx - ja .L2 - testl %edi, %edi - js .L11 - jne .L7 - leaq 1(%rsi), %r8 - movb $48, (%rsi) -.L5: - movb $0, (%r8) - movq %rsi, %rdi - movabsq $reverse, %rax - jmp *%rax - .p2align 4,,10 - .p2align 3 -.L11: - negl %eax - movl $1, %edi -.L4: - movq %rsi, %r8 - movabsq $digits, %r10 - jmp .L6 - .p2align 4,,10 - .p2align 3 -.L8: - movq %rcx, %r8 -.L6: - cltd - leaq 1(%r8), %rcx - idivl %r9d - movslq %edx, %rdx - testl %eax, %eax - movzbl (%r10,%rdx), %edx - movb %dl, -1(%rcx) - jne .L8 - testl %edi, %edi - je .L9 - addq $2, %r8 - movb $45, (%rcx) - jmp .L5 - .p2align 4,,10 - .p2align 3 -.L7: - xorl %edi, %edi - jmp .L4 - .p2align 4,,10 - .p2align 3 -.L2: - xorl %eax, %eax - ret - .p2align 4,,10 - .p2align 3 -.L9: - movq %rcx, %r8 - jmp .L5 - .cfi_endproc -.LFE2: - .size itoa, .-itoa - .section .rodata - .align 32 - .type digits, @object - .size digits, 36 -digits: - .byte 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x41,0x42,0x43 - .byte 0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50 - .byte 0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a - .ident "GCC: (GNU) 7.3.0" diff --git a/obj/kaleid/common/ltoa.S b/obj/kaleid/common/ltoa.S deleted file mode 100644 index 2723118..0000000 --- a/obj/kaleid/common/ltoa.S +++ /dev/null @@ -1,76 +0,0 @@ - .file "convert.c" - .text - .p2align 4,,15 - .globl ltoa - .type ltoa, @function -ltoa: -.LFB2: - .cfi_startproc - leal -2(%rdx), %ecx - movq %rdi, %rax - cmpl $34, %ecx - ja .L2 - testq %rdi, %rdi - js .L11 - jne .L7 - leaq 1(%rsi), %r9 - movb $48, (%rsi) -.L5: - movb $0, (%r9) - movq %rsi, %rdi - movabsq $reverse, %rax - jmp *%rax - .p2align 4,,10 - .p2align 3 -.L11: - negq %rax - movl $1, %edi -.L4: - movslq %edx, %r8 - movq %rsi, %r9 - movabsq $digits, %r10 - jmp .L6 - .p2align 4,,10 - .p2align 3 -.L8: - movq %rcx, %r9 -.L6: - cqto - leaq 1(%r9), %rcx - idivq %r8 - movzbl (%r10,%rdx), %edx - testq %rax, %rax - movb %dl, -1(%rcx) - jne .L8 - testl %edi, %edi - je .L9 - addq $2, %r9 - movb $45, (%rcx) - jmp .L5 - .p2align 4,,10 - .p2align 3 -.L7: - xorl %edi, %edi - jmp .L4 - .p2align 4,,10 - .p2align 3 -.L2: - xorl %eax, %eax - ret - .p2align 4,,10 - .p2align 3 -.L9: - movq %rcx, %r9 - jmp .L5 - .cfi_endproc -.LFE2: - .size ltoa, .-ltoa - .section .rodata - .align 32 - .type digits, @object - .size digits, 36 -digits: - .byte 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x41,0x42,0x43 - .byte 0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50 - .byte 0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a - .ident "GCC: (GNU) 7.3.0" diff --git a/obj/kaleid/common/memory.S b/obj/kaleid/common/memory.S deleted file mode 100644 index 6db16a5..0000000 --- a/obj/kaleid/common/memory.S +++ /dev/null @@ -1,309 +0,0 @@ - .file "memory.c" - .text - .p2align 4,,15 - .globl memsetb - .type memsetb, @function -memsetb: -.LFB2: - .cfi_startproc - movq %rdi, %rax - testb $7, %al - je .L10 - testq %rdx, %rdx - leaq -1(%rdx), %r8 - je .L3 - movl %esi, %edx - movq %rdi, %rcx - jmp .L4 - .p2align 4,,10 - .p2align 3 -.L21: - subq $1, %r8 - cmpq $-1, %r8 - je .L3 -.L4: - addq $1, %rcx - movb %dl, -1(%rcx) - testb $7, %cl - jne .L21 -.L2: - cmpq $8, %r8 - ja .L5 - testq %r8, %r8 - je .L22 -.L6: - addq %rcx, %r8 - .p2align 4,,10 - .p2align 3 -.L9: - addq $1, %rcx - movb %sil, -1(%rcx) - cmpq %rcx, %r8 - jne .L9 - rep ret - .p2align 4,,10 - .p2align 3 -.L3: - movq $-1, %r8 -.L5: - movslq %esi, %rcx - movq %rcx, %rdx - movq %rcx, %rdi - salq $48, %rdi - salq $56, %rdx - orq %rdi, %rdx - movq %rcx, %rdi - orq %rcx, %rdx - salq $40, %rdi - orq %rdi, %rdx - movq %rcx, %rdi - salq $32, %rdi - orq %rdi, %rdx - movq %rcx, %rdi - salq $24, %rdi - orq %rdi, %rdx - movq %rcx, %rdi - salq $8, %rcx - salq $16, %rdi - orq %rdi, %rdx - orq %rcx, %rdx - movq %rax, %rcx - .p2align 4,,10 - .p2align 3 -.L8: - subq $8, %r8 - addq $8, %rcx - movq %rdx, -8(%rcx) - cmpq $8, %r8 - ja .L8 - jmp .L6 - .p2align 4,,10 - .p2align 3 -.L22: - rep ret - .p2align 4,,10 - .p2align 3 -.L10: - movq %rdi, %rcx - movq %rdx, %r8 - jmp .L2 - .cfi_endproc -.LFE2: - .size memsetb, .-memsetb - .p2align 4,,15 - .globl memsetw - .type memsetw, @function -memsetw: -.LFB3: - .cfi_startproc - testb $1, %dil - jne .L24 - testb $7, %dil - je .L35 - testq %rdx, %rdx - leaq -1(%rdx), %r8 - movl %esi, %eax - movq %rdi, %rcx - jne .L31 - jmp .L47 - .p2align 4,,10 - .p2align 3 -.L48: - subq $1, %r8 - cmpq $-1, %r8 - je .L27 -.L31: - addq $2, %rcx - movw %ax, -2(%rcx) - testb $7, %cl - jne .L48 -.L25: - cmpq $4, %r8 - ja .L27 - testq %r8, %r8 - je .L28 -.L32: - xorl %edx, %edx - .p2align 4,,10 - .p2align 3 -.L34: - movw %si, (%rcx,%rdx,2) - addq $1, %rdx - cmpq %r8, %rdx - jne .L34 -.L28: - movq %rdi, %rax - ret - .p2align 4,,10 - .p2align 3 -.L47: - movq $-1, %r8 - .p2align 4,,10 - .p2align 3 -.L27: - movslq %esi, %rdx - movq %rdx, %rax - movq %rdx, %r9 - salq $48, %rax - salq $32, %r9 - orq %r9, %rax - orq %rdx, %rax - salq $16, %rdx - orq %rdx, %rax - .p2align 4,,10 - .p2align 3 -.L33: - subq $4, %r8 - addq $8, %rcx - movq %rax, -8(%rcx) - cmpq $4, %r8 - ja .L33 - jmp .L32 - .p2align 4,,10 - .p2align 3 -.L24: - testq %rdx, %rdx - je .L28 - xorl %eax, %eax - .p2align 4,,10 - .p2align 3 -.L29: - movw %si, (%rdi,%rax,2) - addq $1, %rax - cmpq %rax, %rdx - jne .L29 - leaq (%rdi,%rdx,2), %rax - ret - .p2align 4,,10 - .p2align 3 -.L35: - movq %rdi, %rcx - movq %rdx, %r8 - jmp .L25 - .cfi_endproc -.LFE3: - .size memsetw, .-memsetw - .p2align 4,,15 - .globl memsetd - .type memsetd, @function -memsetd: -.LFB4: - .cfi_startproc - movq %rdi, %rax - ret - .cfi_endproc -.LFE4: - .size memsetd, .-memsetd - .p2align 4,,15 - .globl memsetq - .type memsetq, @function -memsetq: -.LFB5: - .cfi_startproc - testq %rdx, %rdx - movq %rdi, %rax - je .L51 - xorl %ecx, %ecx - .p2align 4,,10 - .p2align 3 -.L52: - movq %rsi, (%rax,%rcx,8) - addq $1, %rcx - cmpq %rdx, %rcx - jne .L52 -.L51: - rep ret - .cfi_endproc -.LFE5: - .size memsetq, .-memsetq - .p2align 4,,15 - .globl memzero - .type memzero, @function -memzero: -.LFB6: - .cfi_startproc - movq %rsi, %rdx - movabsq $memsetb, %rax - xorl %esi, %esi - jmp *%rax - .cfi_endproc -.LFE6: - .size memzero, .-memzero - .p2align 4,,15 - .globl memcpy - .type memcpy, @function -memcpy: -.LFB7: - .cfi_startproc - testq %rdx, %rdx - movq %rdi, %rax - je .L59 - testb $1, %sil - movq %rsi, %rcx - jne .L91 -.L60: - testb $7, %al - je .L61 - andl $7, %ecx - jne .L89 - jmp .L61 - .p2align 4,,10 - .p2align 3 -.L62: - movsw - subq $2, %rdx -.L89: - cmpq $2, %rdx - ja .L62 -.L61: - cmpq $8, %rdx - jbe .L63 - leaq -9(%rdx), %r10 - xorl %ecx, %ecx - shrq $3, %r10 - leaq 8(,%r10,8), %r9 - .p2align 4,,10 - .p2align 3 -.L64: - movq (%rsi,%rcx), %r8 - movq %r8, (%rdi,%rcx) - addq $8, %rcx - cmpq %rcx, %r9 - jne .L64 - negq %r10 - addq %r9, %rsi - addq %r9, %rdi - leaq -8(%rdx,%r10,8), %rdx -.L65: - xorl %ecx, %ecx - .p2align 4,,10 - .p2align 3 -.L66: - movzbl (%rsi,%rcx), %r8d - movw %r8w, (%rdi,%rcx,2) - addq $1, %rcx - cmpq %rdx, %rcx - jne .L66 -.L59: - rep ret - .p2align 4,,10 - .p2align 3 -.L63: - testq %rdx, %rdx - jne .L65 - rep ret - .p2align 4,,10 - .p2align 3 -.L91: - testb $1, %al - je .L60 - movzbl (%rsi), %r8d - leaq 1(%rdi), %rdi - subq $1, %rdx - addq $1, %rsi - movb %r8b, (%rax) - jmp .L60 - .cfi_endproc -.LFE7: - .size memcpy, .-memcpy - .ident "GCC: (GNU) 7.3.0" diff --git a/obj/kaleid/common/rand.S b/obj/kaleid/common/rand.S deleted file mode 100644 index b91186e..0000000 --- a/obj/kaleid/common/rand.S +++ /dev/null @@ -1,52 +0,0 @@ - .file "rand.c" - .text - .p2align 4,,15 - .globl rand - .type rand, @function -rand: -.LFB2: - .cfi_startproc - movabsq $next, %rax - imulq $1103515245, (%rax), %rdx - addq $12345, %rdx - movq %rdx, (%rax) - shrq $16, %rdx - movl %edx, %eax - movl %edx, %esi - leaq (%rax,%rax,2), %rax - shrq $32, %rax - movq %rax, %rcx - movl %edx, %eax - subl %ecx, %eax - shrl %eax - addl %ecx, %eax - shrl $30, %eax - movl %eax, %ecx - sall $31, %ecx - subl %eax, %ecx - subl %ecx, %esi - movl %esi, %eax - ret - .cfi_endproc -.LFE2: - .size rand, .-rand - .p2align 4,,15 - .globl srand - .type srand, @function -srand: -.LFB3: - .cfi_startproc - movabsq $next, %rax - movl %edi, %edx - movq %rdx, (%rax) - ret - .cfi_endproc -.LFE3: - .size srand, .-srand - .data - .align 8 - .type next, @object - .size next, 8 -next: - .quad 7756 - .ident "GCC: (GNU) 7.3.0" diff --git a/obj/kaleid/common/status.S b/obj/kaleid/common/status.S deleted file mode 100644 index 99dcf29..0000000 --- a/obj/kaleid/common/status.S +++ /dev/null @@ -1,18 +0,0 @@ - .file "status.c" - .text - .section .rodata.str1.1,"aMS",@progbits,1 -.LC0: - .string "" - .text - .p2align 4,,15 - .globl describe_status - .type describe_status, @function -describe_status: -.LFB2: - .cfi_startproc - movabsq $.LC0, %rax - ret - .cfi_endproc -.LFE2: - .size describe_status, .-describe_status - .ident "GCC: (GNU) 7.3.0" diff --git a/obj/kaleid/common/string.S b/obj/kaleid/common/string.S deleted file mode 100644 index 0ff4b9e..0000000 --- a/obj/kaleid/common/string.S +++ /dev/null @@ -1,192 +0,0 @@ - .file "string.c" - .text - .p2align 4,,15 - .globl strlen - .type strlen, @function -strlen: -.LFB2: - .cfi_startproc - movq %rdi, %rax - .p2align 4,,10 - .p2align 3 -.L2: - addq $1, %rax - cmpb $0, -1(%rax) - jne .L2 - subq %rdi, %rax - subq $1, %rax - ret - .cfi_endproc -.LFE2: - .size strlen, .-strlen - .p2align 4,,15 - .globl strcpy - .type strcpy, @function -strcpy: -.LFB3: - .cfi_startproc - movq %rdi, %rax - movq %rdi, %rdx - .p2align 4,,10 - .p2align 3 -.L6: - addq $1, %rsi - movzbl -1(%rsi), %ecx - addq $1, %rdx - testb %cl, %cl - movb %cl, -1(%rdx) - jne .L6 - rep ret - .cfi_endproc -.LFE3: - .size strcpy, .-strcpy - .p2align 4,,15 - .globl strncpy - .type strncpy, @function -strncpy: -.LFB4: - .cfi_startproc - testq %rdx, %rdx - movq %rdi, %rax - je .L9 - movzbl (%rsi), %r8d - xorl %ecx, %ecx - testb %r8b, %r8b - jne .L11 - jmp .L12 - .p2align 4,,10 - .p2align 3 -.L20: - movzbl (%rsi,%rcx), %r8d - testb %r8b, %r8b - je .L12 -.L11: - movb %r8b, (%rax,%rcx) - addq $1, %rcx - cmpq %rcx, %rdx - jne .L20 -.L9: - rep ret - .p2align 4,,10 - .p2align 3 -.L12: - addq $1, %rcx - cmpq %rcx, %rdx - movb $0, -1(%rax,%rcx) - jbe .L9 - addq $1, %rcx - cmpq %rcx, %rdx - movb $0, -1(%rax,%rcx) - ja .L12 - jmp .L9 - .cfi_endproc -.LFE4: - .size strncpy, .-strncpy - .p2align 4,,15 - .globl xstrcnpy - .type xstrcnpy, @function -xstrcnpy: -.LFB5: - .cfi_startproc - testq %rdx, %rdx - je .L22 - movzbl (%rsi), %ecx - xorl %eax, %eax - testb %cl, %cl - jne .L24 - jmp .L25 - .p2align 4,,10 - .p2align 3 -.L33: - movzbl (%rsi,%rax), %ecx - testb %cl, %cl - je .L25 -.L24: - movb %cl, (%rdi,%rax) - addq $1, %rax - cmpq %rax, %rdx - jne .L33 -.L22: - movl $1, %eax - ret - .p2align 4,,10 - .p2align 3 -.L25: - addq $1, %rax - cmpq %rax, %rdx - movb $0, -1(%rdi,%rax) - jbe .L22 - addq $1, %rax - cmpq %rax, %rdx - movb $0, -1(%rdi,%rax) - ja .L25 - jmp .L22 - .cfi_endproc -.LFE5: - .size xstrcnpy, .-xstrcnpy - .p2align 4,,15 - .globl strrev - .type strrev, @function -strrev: -.LFB6: - .cfi_startproc - movq %rdi, %rax - movq %rsi, %rdx - .p2align 4,,10 - .p2align 3 -.L35: - addq $1, %rdx - cmpb $0, -1(%rdx) - jne .L35 - subq %rsi, %rdx - movb $0, -1(%rax,%rdx) - leaq -2(%rsi,%rdx), %rcx - movq %rax, %rdx - .p2align 4,,10 - .p2align 3 -.L36: - movzbl (%rcx), %esi - addq $1, %rdx - subq $1, %rcx - testb %sil, %sil - movb %sil, -1(%rdx) - jne .L36 - rep ret - .cfi_endproc -.LFE6: - .size strrev, .-strrev - .p2align 4,,15 - .globl reverse - .type reverse, @function -reverse: -.LFB7: - .cfi_startproc - movq %rdi, %rax - movq %rdi, %rdx - .p2align 4,,10 - .p2align 3 -.L40: - addq $1, %rdx - cmpb $0, -1(%rdx) - jne .L40 - subq $2, %rdx - cmpq %rdx, %rax - jnb .L41 - movq %rax, %rcx - .p2align 4,,10 - .p2align 3 -.L42: - movzbl (%rdx), %esi - movzbl (%rcx), %r8d - subq $1, %rdx - addq $1, %rcx - cmpq %rcx, %rdx - movb %r8b, 1(%rdx) - movb %sil, -1(%rcx) - ja .L42 -.L41: - rep ret - .cfi_endproc -.LFE7: - .size reverse, .-reverse - .ident "GCC: (GNU) 7.3.0" diff --git a/obj/kaleid/common/ultoa.S b/obj/kaleid/common/ultoa.S deleted file mode 100644 index 9f381f4..0000000 --- a/obj/kaleid/common/ultoa.S +++ /dev/null @@ -1,55 +0,0 @@ - .file "convert.c" - .text - .p2align 4,,15 - .globl ultoa - .type ultoa, @function -ultoa: -.LFB2: - .cfi_startproc - leal -2(%rdx), %ecx - movq %rdi, %rax - cmpl $34, %ecx - ja .L2 - testq %rdi, %rdi - jne .L3 - leaq 1(%rsi), %rcx - movb $48, (%rsi) -.L4: - movb $0, (%rcx) - movq %rsi, %rdi - movabsq $reverse, %rax - jmp *%rax - .p2align 4,,10 - .p2align 3 -.L3: - movslq %edx, %r8 - movq %rsi, %rcx - movabsq $digits, %r9 - .p2align 4,,10 - .p2align 3 -.L5: - xorl %edx, %edx - addq $1, %rcx - divq %r8 - movzbl (%r9,%rdx), %edx - testq %rax, %rax - movb %dl, -1(%rcx) - jne .L5 - jmp .L4 - .p2align 4,,10 - .p2align 3 -.L2: - xorl %eax, %eax - ret - .cfi_endproc -.LFE2: - .size ultoa, .-ultoa - .section .rodata - .align 32 - .type digits, @object - .size digits, 36 -digits: - .byte 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x41,0x42,0x43 - .byte 0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50 - .byte 0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a - .ident "GCC: (GNU) 7.3.0" diff --git a/obj/kaleid/common/utoa.S b/obj/kaleid/common/utoa.S deleted file mode 100644 index dc4310c..0000000 --- a/obj/kaleid/common/utoa.S +++ /dev/null @@ -1,56 +0,0 @@ - .file "convert.c" - .text - .p2align 4,,15 - .globl utoa - .type utoa, @function -utoa: -.LFB2: - .cfi_startproc - movl %edx, %r8d - leal -2(%rdx), %edx - movl %edi, %eax - cmpl $34, %edx - ja .L2 - testl %edi, %edi - jne .L5 - leaq 1(%rsi), %rcx - movb $48, (%rsi) -.L4: - movb $0, (%rcx) - movq %rsi, %rdi - movabsq $reverse, %rax - jmp *%rax - .p2align 4,,10 - .p2align 3 -.L5: - movq %rsi, %rcx - movabsq $digits, %r9 - .p2align 4,,10 - .p2align 3 -.L3: - xorl %edx, %edx - addq $1, %rcx - divl %r8d - movl %edx, %edx - testl %eax, %eax - movzbl (%r9,%rdx), %edx - movb %dl, -1(%rcx) - jne .L3 - jmp .L4 - .p2align 4,,10 - .p2align 3 -.L2: - xorl %eax, %eax - ret - .cfi_endproc -.LFE2: - .size utoa, .-utoa - .section .rodata - .align 32 - .type digits, @object - .size digits, 36 -digits: - .byte 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x41,0x42,0x43 - .byte 0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50 - .byte 0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a - .ident "GCC: (GNU) 7.3.0" diff --git a/obj/kaleid/kernel/init.S b/obj/kaleid/kernel/init.S deleted file mode 100644 index c2fd44a..0000000 --- a/obj/kaleid/kernel/init.S +++ /dev/null @@ -1,30 +0,0 @@ - .file "init.c" - .text - .section .rodata.str1.1,"aMS",@progbits,1 -.LC0: - .string "Goodbye World :(" - .text - .p2align 4,,15 - .globl StartKern - .type StartKern, @function -StartKern: -.LFB2: - .cfi_startproc - subq $8, %rsp - .cfi_def_cfa_offset 16 -/APP -# 21 "kaleid/kernel/init.c" 1 - cli -# 0 "" 2 -/NO_APP - movabsq $__kstate, %rax - movb $3, (%rax) - movabsq $InitTerms, %rax - call *%rax - movabsq $.LC0, %rdi - movabsq $StartPanic, %rax - call *%rax - .cfi_endproc -.LFE2: - .size StartKern, .-StartKern - .ident "GCC: (GNU) 7.3.0" diff --git a/obj/kaleid/kernel/io/ports.S b/obj/kaleid/kernel/io/ports.S deleted file mode 100644 index 8a0517d..0000000 --- a/obj/kaleid/kernel/io/ports.S +++ /dev/null @@ -1,3 +0,0 @@ - .file "ports.c" - .text - .ident "GCC: (GNU) 7.3.0" diff --git a/obj/kaleid/kernel/io/terminal.S b/obj/kaleid/kernel/io/terminal.S deleted file mode 100644 index 42e0a6f..0000000 --- a/obj/kaleid/kernel/io/terminal.S +++ /dev/null @@ -1,846 +0,0 @@ - .file "terminal.c" - .text - .section .rodata.str1.1,"aMS",@progbits,1 -.LC0: - .string "kaleid/kernel/io/terminal.c" -.LC1: - .string "kt->kt_init == INITOK" - .section .rodata.str1.8,"aMS",@progbits,1 - .align 8 -.LC2: - .string "(&(kt)->kt_lock)->lk_init == INITOK" - .align 8 -.LC3: - .string "DosAquireLock on an already locked object" - .align 8 -.LC4: - .string "DosReleaseLock on an unlocked object" - .text - .p2align 4,,15 - .globl ClearTerm - .type ClearTerm, @function -ClearTerm: -.LFB3: - .cfi_startproc - testq %rdi, %rdi - je .L10 - pushq %rbx - .cfi_def_cfa_offset 16 - .cfi_offset 3, -16 - cmpl $-889275714, 80(%rdi) - movq %rdi, %rbx - jne .L26 -/APP -# 69 "kaleid/kernel/io/terminal.c" 1 - cli -# 0 "" 2 -/NO_APP - cmpl $-889275714, 24(%rdi) - jne .L27 - movl 4(%rdi), %eax - leal 1(%rax), %edx - testl %eax, %eax - movl %edx, 4(%rdi) - jne .L28 -.L5: -/APP -# 69 "kaleid/kernel/io/terminal.c" 1 - sti -# 0 "" 2 -/NO_APP - movq 48(%rbx), %rcx - movzbl 40(%rbx), %edx - imulq 56(%rbx), %rcx - sall $8, %edx - orl $32, %edx - testq %rcx, %rcx - je .L6 - movq 32(%rbx), %rax - leaq (%rax,%rcx,2), %rcx - .p2align 4,,10 - .p2align 3 -.L7: - movw %dx, (%rax) - addq $2, %rax - cmpq %rax, %rcx - jne .L7 -.L6: - movq $0, 72(%rbx) - movq $0, 64(%rbx) -/APP -# 71 "kaleid/kernel/io/terminal.c" 1 - cli -# 0 "" 2 -/NO_APP - cmpl $-889275714, 24(%rbx) - jne .L29 - movl 4(%rbx), %eax - leal 1(%rax), %edx - testl %eax, %eax - movl %edx, 4(%rbx) - jne .L30 -.L9: -/APP -# 71 "kaleid/kernel/io/terminal.c" 1 - sti -# 0 "" 2 -/NO_APP - xorl %eax, %eax - popq %rbx - .cfi_remember_state - .cfi_restore 3 - .cfi_def_cfa_offset 8 - ret - .p2align 4,,10 - .p2align 3 -.L30: - .cfi_restore_state - movabsq $.LC4, %rdi - xorl %eax, %eax - movabsq $StartPanic, %rdx - call *%rdx - jmp .L9 - .p2align 4,,10 - .p2align 3 -.L28: - movabsq $.LC3, %rdi - xorl %eax, %eax - movabsq $StartPanic, %rdx - call *%rdx - jmp .L5 - .p2align 4,,10 - .p2align 3 -.L26: - movabsq $__func__.1202, %rcx - movl $67, %edx - movabsq $.LC0, %rsi - movabsq $.LC1, %rdi - movabsq $_assert_handler, %rax - call *%rax - .p2align 4,,10 - .p2align 3 -.L27: - movabsq $__func__.1202, %rcx - movl $69, %edx - movabsq $.LC0, %rsi - movabsq $.LC2, %rdi - movabsq $_assert_handler, %rax - call *%rax - .p2align 4,,10 - .p2align 3 -.L29: - movabsq $__func__.1202, %rcx - movl $71, %edx - movabsq $.LC0, %rsi - movabsq $.LC2, %rdi - movabsq $_assert_handler, %rax - call *%rax -.L10: - .cfi_def_cfa_offset 8 - .cfi_restore 3 - movq $-6, %rax - ret - .cfi_endproc -.LFE3: - .size ClearTerm, .-ClearTerm - .section .rodata.str1.8 - .align 8 -.LC5: - .string "!stdout && _vga_term.kt_init != INITOK" - .text - .p2align 4,,15 - .globl InitTerms - .type InitTerms, @function -InitTerms: -.LFB2: - .cfi_startproc - movabsq $stdout, %rdx - cmpq $0, (%rdx) - jne .L32 - movabsq $_vga_term, %rdi - cmpl $-889275714, 80(%rdi) - je .L32 - movabsq $_vga_term+80, %rax - movq %rdi, (%rdx) - movl $-889275714, (%rax) - movq %rdi, %rax - movabsq %rax, stddbg - movabsq $ClearTerm, %rax - jmp *%rax - .p2align 4,,10 - .p2align 3 -.L32: - subq $8, %rsp - .cfi_def_cfa_offset 16 - movabsq $__func__.1198, %rcx - movl $49, %edx - movabsq $.LC0, %rsi - movabsq $.LC5, %rdi - movabsq $_assert_handler, %rax - call *%rax - .cfi_endproc -.LFE2: - .size InitTerms, .-InitTerms - .p2align 4,,15 - .globl ChTermColor - .type ChTermColor, @function -ChTermColor: -.LFB4: - .cfi_startproc - cmpb $15, %sil - ja .L42 - testq %rdi, %rdi - je .L43 - pushq %rbp - .cfi_def_cfa_offset 16 - .cfi_offset 6, -16 - pushq %rbx - .cfi_def_cfa_offset 24 - .cfi_offset 3, -24 - movl %esi, %ebp - movq %rdi, %rbx - subq $8, %rsp - .cfi_def_cfa_offset 32 -/APP -# 87 "kaleid/kernel/io/terminal.c" 1 - cli -# 0 "" 2 -/NO_APP - cmpl $-889275714, 24(%rdi) - jne .L54 - movl 4(%rdi), %eax - leal 1(%rax), %edx - testl %eax, %eax - movl %edx, 4(%rdi) - jne .L55 -.L39: -/APP -# 87 "kaleid/kernel/io/terminal.c" 1 - sti -# 0 "" 2 -/NO_APP - movb %bpl, 40(%rbx) -/APP -# 89 "kaleid/kernel/io/terminal.c" 1 - cli -# 0 "" 2 -/NO_APP - cmpl $-889275714, 24(%rbx) - jne .L56 - movl 4(%rbx), %eax - leal 1(%rax), %edx - testl %eax, %eax - movl %edx, 4(%rbx) - jne .L57 -.L41: -/APP -# 89 "kaleid/kernel/io/terminal.c" 1 - sti -# 0 "" 2 -/NO_APP - addq $8, %rsp - .cfi_remember_state - .cfi_def_cfa_offset 24 - xorl %eax, %eax - popq %rbx - .cfi_restore 3 - .cfi_def_cfa_offset 16 - popq %rbp - .cfi_restore 6 - .cfi_def_cfa_offset 8 - ret - .p2align 4,,10 - .p2align 3 -.L55: - .cfi_restore_state - movabsq $.LC3, %rdi - xorl %eax, %eax - movabsq $StartPanic, %rdx - call *%rdx - jmp .L39 - .p2align 4,,10 - .p2align 3 -.L57: - movabsq $.LC4, %rdi - xorl %eax, %eax - movabsq $StartPanic, %rdx - call *%rdx - jmp .L41 - .p2align 4,,10 - .p2align 3 -.L54: - movabsq $__func__.1210, %rcx - movl $87, %edx - movabsq $.LC0, %rsi - movabsq $.LC2, %rdi - movabsq $_assert_handler, %rax - call *%rax - .p2align 4,,10 - .p2align 3 -.L56: - movabsq $__func__.1210, %rcx - movl $89, %edx - movabsq $.LC0, %rsi - movabsq $.LC2, %rdi - movabsq $_assert_handler, %rax - call *%rax - .p2align 4,,10 - .p2align 3 -.L42: - .cfi_def_cfa_offset 8 - .cfi_restore 3 - .cfi_restore 6 - movq $-5, %rax - ret -.L43: - movq $-6, %rax - ret - .cfi_endproc -.LFE4: - .size ChTermColor, .-ChTermColor - .p2align 4,,15 - .globl ClearTermUnlocked - .type ClearTermUnlocked, @function -ClearTermUnlocked: -.LFB7: - .cfi_startproc - movq 48(%rdi), %rcx - movzbl 40(%rdi), %edx - imulq 56(%rdi), %rcx - sall $8, %edx - orl $32, %edx - testq %rcx, %rcx - je .L59 - movq 32(%rdi), %rax - leaq (%rax,%rcx,2), %rcx - .p2align 4,,10 - .p2align 3 -.L60: - movw %dx, (%rax) - addq $2, %rax - cmpq %rcx, %rax - jne .L60 -.L59: - movq $0, 72(%rdi) - movq $0, 64(%rdi) - ret - .cfi_endproc -.LFE7: - .size ClearTermUnlocked, .-ClearTermUnlocked - .p2align 4,,15 - .globl PutOnTermUnlocked - .type PutOnTermUnlocked, @function -PutOnTermUnlocked: -.LFB8: - .cfi_startproc - cmpb $13, %sil - je .L69 - movsbl %sil, %esi - movabsq $PutOnTermUnlocked.part.0, %rax - jmp *%rax - .p2align 4,,10 - .p2align 3 -.L69: - movq $0, 64(%rdi) - ret - .cfi_endproc -.LFE8: - .size PutOnTermUnlocked, .-PutOnTermUnlocked - .p2align 4,,15 - .type PutOnTermUnlocked.part.0, @function -PutOnTermUnlocked.part.0: -.LFB10: - .cfi_startproc - pushq %r13 - .cfi_def_cfa_offset 16 - .cfi_offset 13, -16 - pushq %r12 - .cfi_def_cfa_offset 24 - .cfi_offset 12, -24 - pushq %rbp - .cfi_def_cfa_offset 32 - .cfi_offset 6, -32 - pushq %rbx - .cfi_def_cfa_offset 40 - .cfi_offset 3, -40 - movq %rdi, %rbx - subq $8, %rsp - .cfi_def_cfa_offset 48 - cmpb $10, %sil - je .L81 - cmpb $9, %sil - movq 72(%rdi), %rbp - je .L82 - movq 48(%rdi), %rdx - movzbl 40(%rbx), %ecx - movsbw %sil, %si - movq 64(%rdi), %rax - movq 32(%rdi), %rdi - imulq %rdx, %rbp - sall $8, %ecx - orl %ecx, %esi - addq %rax, %rbp - movw %si, (%rdi,%rbp,2) -.L72: - addq $1, %rax - cmpq %rdx, %rax - je .L77 - movq %rax, 64(%rbx) -.L70: - addq $8, %rsp - .cfi_remember_state - .cfi_def_cfa_offset 40 - popq %rbx - .cfi_restore 3 - .cfi_def_cfa_offset 32 - popq %rbp - .cfi_restore 6 - .cfi_def_cfa_offset 24 - popq %r12 - .cfi_restore 12 - .cfi_def_cfa_offset 16 - popq %r13 - .cfi_restore 13 - .cfi_def_cfa_offset 8 - ret - .p2align 4,,10 - .p2align 3 -.L82: - .cfi_restore_state - movq %rbp, %rax - movl $4, %r12d - movabsq $PutOnTermUnlocked, %r13 - cmpq %rbp, %rax - je .L83 -.L74: - subl $1, %r12d - je .L84 - movq 72(%rbx), %rax - cmpq %rbp, %rax - jne .L74 -.L83: - movl $32, %esi - movq %rbx, %rdi - call *%r13 - jmp .L74 - .p2align 4,,10 - .p2align 3 -.L77: - movq 72(%rbx), %rax - movq $0, 64(%rbx) - addq $1, %rax - cmpq 56(%rbx), %rax - movq %rax, 72(%rbx) - jne .L70 - movq $0, 72(%rbx) - addq $8, %rsp - .cfi_remember_state - .cfi_def_cfa_offset 40 - popq %rbx - .cfi_restore 3 - .cfi_def_cfa_offset 32 - popq %rbp - .cfi_restore 6 - .cfi_def_cfa_offset 24 - popq %r12 - .cfi_restore 12 - .cfi_def_cfa_offset 16 - popq %r13 - .cfi_restore 13 - .cfi_def_cfa_offset 8 - ret - .p2align 4,,10 - .p2align 3 -.L81: - .cfi_restore_state - movq 48(%rdi), %rdx - leaq -1(%rdx), %rax - movq %rax, 72(%rdi) - movq 64(%rdi), %rax - jmp .L72 - .p2align 4,,10 - .p2align 3 -.L84: - movq 64(%rbx), %rax - movq 48(%rbx), %rdx - jmp .L72 - .cfi_endproc -.LFE10: - .size PutOnTermUnlocked.part.0, .-PutOnTermUnlocked.part.0 - .p2align 4,,15 - .globl PutOnTerm - .type PutOnTerm, @function -PutOnTerm: -.LFB5: - .cfi_startproc - testq %rdi, %rdi - je .L94 - pushq %rbp - .cfi_def_cfa_offset 16 - .cfi_offset 6, -16 - pushq %rbx - .cfi_def_cfa_offset 24 - .cfi_offset 3, -24 - movl %esi, %ebp - movq %rdi, %rbx - subq $8, %rsp - .cfi_def_cfa_offset 32 - cmpl $-889275714, 80(%rdi) - jne .L105 -/APP -# 104 "kaleid/kernel/io/terminal.c" 1 - cli -# 0 "" 2 -/NO_APP - cmpl $-889275714, 24(%rdi) - jne .L106 - movl 4(%rdi), %eax - leal 1(%rax), %edx - testl %eax, %eax - movl %edx, 4(%rdi) - jne .L107 -.L89: -/APP -# 104 "kaleid/kernel/io/terminal.c" 1 - sti -# 0 "" 2 -/NO_APP - cmpb $13, %bpl - jne .L90 - movq $0, 64(%rbx) -.L91: -/APP -# 106 "kaleid/kernel/io/terminal.c" 1 - cli -# 0 "" 2 -/NO_APP - cmpl $-889275714, 24(%rbx) - jne .L108 - movl 4(%rbx), %eax - leal 1(%rax), %edx - testl %eax, %eax - movl %edx, 4(%rbx) - jne .L109 -.L93: -/APP -# 106 "kaleid/kernel/io/terminal.c" 1 - sti -# 0 "" 2 -/NO_APP - addq $8, %rsp - .cfi_remember_state - .cfi_def_cfa_offset 24 - xorl %eax, %eax - popq %rbx - .cfi_restore 3 - .cfi_def_cfa_offset 16 - popq %rbp - .cfi_restore 6 - .cfi_def_cfa_offset 8 - ret - .p2align 4,,10 - .p2align 3 -.L90: - .cfi_restore_state - movsbl %bpl, %esi - movq %rbx, %rdi - movabsq $PutOnTermUnlocked.part.0, %rax - call *%rax - jmp .L91 - .p2align 4,,10 - .p2align 3 -.L107: - movabsq $.LC3, %rdi - xorl %eax, %eax - movabsq $StartPanic, %rdx - call *%rdx - jmp .L89 - .p2align 4,,10 - .p2align 3 -.L109: - movabsq $.LC4, %rdi - xorl %eax, %eax - movabsq $StartPanic, %rdx - call *%rdx - jmp .L93 - .p2align 4,,10 - .p2align 3 -.L105: - movabsq $__func__.1217, %rcx - movl $102, %edx - movabsq $.LC0, %rsi - movabsq $.LC1, %rdi - movabsq $_assert_handler, %rax - call *%rax - .p2align 4,,10 - .p2align 3 -.L106: - movabsq $__func__.1217, %rcx - movl $104, %edx - movabsq $.LC0, %rsi - movabsq $.LC2, %rdi - movabsq $_assert_handler, %rax - call *%rax - .p2align 4,,10 - .p2align 3 -.L108: - movabsq $__func__.1217, %rcx - movl $106, %edx - movabsq $.LC0, %rsi - movabsq $.LC2, %rdi - movabsq $_assert_handler, %rax - call *%rax -.L94: - .cfi_def_cfa_offset 8 - .cfi_restore 3 - .cfi_restore 6 - movq $-6, %rax - ret - .cfi_endproc -.LFE5: - .size PutOnTerm, .-PutOnTerm - .p2align 4,,15 - .globl PrintOnTerm - .type PrintOnTerm, @function -PrintOnTerm: -.LFB6: - .cfi_startproc - testq %rdi, %rdi - je .L121 - pushq %r12 - .cfi_def_cfa_offset 16 - .cfi_offset 12, -16 - pushq %rbp - .cfi_def_cfa_offset 24 - .cfi_offset 6, -24 - movq %rdi, %rbp - pushq %rbx - .cfi_def_cfa_offset 32 - .cfi_offset 3, -32 - cmpl $-889275714, 80(%rdi) - jne .L132 -/APP -# 121 "kaleid/kernel/io/terminal.c" 1 - cli -# 0 "" 2 -/NO_APP - cmpl $-889275714, 24(%rdi) - jne .L133 - movl 4(%rdi), %eax - movq %rsi, %rbx - leal 1(%rax), %edx - testl %eax, %eax - movl %edx, 4(%rdi) - jne .L134 -.L114: -/APP -# 121 "kaleid/kernel/io/terminal.c" 1 - sti -# 0 "" 2 -/NO_APP - movabsq $PutOnTermUnlocked.part.0, %r12 -.L115: - movsbl (%rbx), %esi - testb %sil, %sil - je .L135 -.L118: - addq $1, %rbx - cmpb $13, %sil - jne .L116 - movq $0, 64(%rbp) - movsbl (%rbx), %esi - testb %sil, %sil - jne .L118 -.L135: -/APP -# 125 "kaleid/kernel/io/terminal.c" 1 - cli -# 0 "" 2 -/NO_APP - cmpl $-889275714, 24(%rbp) - jne .L136 - movl 4(%rbp), %eax - leal 1(%rax), %edx - testl %eax, %eax - movl %edx, 4(%rbp) - jne .L137 -.L120: -/APP -# 125 "kaleid/kernel/io/terminal.c" 1 - sti -# 0 "" 2 -/NO_APP - xorl %eax, %eax - popq %rbx - .cfi_remember_state - .cfi_restore 3 - .cfi_def_cfa_offset 24 - popq %rbp - .cfi_restore 6 - .cfi_def_cfa_offset 16 - popq %r12 - .cfi_restore 12 - .cfi_def_cfa_offset 8 - ret - .p2align 4,,10 - .p2align 3 -.L116: - .cfi_restore_state - movq %rbp, %rdi - call *%r12 - jmp .L115 - .p2align 4,,10 - .p2align 3 -.L137: - movabsq $.LC4, %rdi - xorl %eax, %eax - movabsq $StartPanic, %rdx - call *%rdx - jmp .L120 - .p2align 4,,10 - .p2align 3 -.L134: - movabsq $.LC3, %rdi - xorl %eax, %eax - movabsq $StartPanic, %rdx - call *%rdx - jmp .L114 - .p2align 4,,10 - .p2align 3 -.L132: - movabsq $__func__.1224, %rcx - movl $119, %edx - movabsq $.LC0, %rsi - movabsq $.LC1, %rdi - movabsq $_assert_handler, %rax - call *%rax - .p2align 4,,10 - .p2align 3 -.L133: - movabsq $__func__.1224, %rcx - movl $121, %edx - movabsq $.LC0, %rsi - movabsq $.LC2, %rdi - movabsq $_assert_handler, %rax - call *%rax - .p2align 4,,10 - .p2align 3 -.L136: - movabsq $__func__.1224, %rcx - movl $125, %edx - movabsq $.LC0, %rsi - movabsq $.LC2, %rdi - movabsq $_assert_handler, %rax - call *%rax -.L121: - .cfi_def_cfa_offset 8 - .cfi_restore 3 - .cfi_restore 6 - .cfi_restore 12 - movq $-6, %rax - ret - .cfi_endproc -.LFE6: - .size PrintOnTerm, .-PrintOnTerm - .p2align 4,,15 - .globl PrintOnTermUnlocked - .type PrintOnTermUnlocked, @function -PrintOnTermUnlocked: -.LFB9: - .cfi_startproc - pushq %r12 - .cfi_def_cfa_offset 16 - .cfi_offset 12, -16 - movabsq $PutOnTermUnlocked.part.0, %r12 - pushq %rbp - .cfi_def_cfa_offset 24 - .cfi_offset 6, -24 - movq %rdi, %rbp - pushq %rbx - .cfi_def_cfa_offset 32 - .cfi_offset 3, -32 - movq %rsi, %rbx -.L139: - movsbl (%rbx), %esi - testb %sil, %sil - je .L144 -.L142: - addq $1, %rbx - cmpb $13, %sil - jne .L140 - movq $0, 64(%rbp) - movsbl (%rbx), %esi - testb %sil, %sil - jne .L142 -.L144: - popq %rbx - .cfi_remember_state - .cfi_restore 3 - .cfi_def_cfa_offset 24 - popq %rbp - .cfi_restore 6 - .cfi_def_cfa_offset 16 - popq %r12 - .cfi_restore 12 - .cfi_def_cfa_offset 8 - ret - .p2align 4,,10 - .p2align 3 -.L140: - .cfi_restore_state - movq %rbp, %rdi - call *%r12 - jmp .L139 - .cfi_endproc -.LFE9: - .size PrintOnTermUnlocked, .-PrintOnTermUnlocked - .section .rodata - .align 8 - .type __func__.1224, @object - .size __func__.1224, 12 -__func__.1224: - .string "PrintOnTerm" - .align 8 - .type __func__.1217, @object - .size __func__.1217, 10 -__func__.1217: - .string "PutOnTerm" - .align 8 - .type __func__.1210, @object - .size __func__.1210, 12 -__func__.1210: - .string "ChTermColor" - .align 8 - .type __func__.1202, @object - .size __func__.1202, 10 -__func__.1202: - .string "ClearTerm" - .align 8 - .type __func__.1198, @object - .size __func__.1198, 10 -__func__.1198: - .string "InitTerms" - .comm stddbg,8,8 - .comm stdout,8,8 - .data - .align 32 - .type _vga_term, @object - .size _vga_term, 88 -_vga_term: - .byte 0 - .zero 3 - .long 0 - .quad 0 - .quad 0 - .long -889275714 - .zero 4 - .quad 753664 - .byte 7 - .zero 7 - .quad 80 - .quad 25 - .quad 0 - .quad 0 - .long 0 - .zero 4 - .ident "GCC: (GNU) 7.3.0" diff --git a/obj/kaleid/kernel/ke/lock.S b/obj/kaleid/kernel/ke/lock.S deleted file mode 100644 index 77581ed..0000000 --- a/obj/kaleid/kernel/ke/lock.S +++ /dev/null @@ -1,3 +0,0 @@ - .file "lock.c" - .text - .ident "GCC: (GNU) 7.3.0" diff --git a/obj/kaleid/kernel/ke/panic.S b/obj/kaleid/kernel/ke/panic.S deleted file mode 100644 index 3191489..0000000 --- a/obj/kaleid/kernel/ke/panic.S +++ /dev/null @@ -1,103 +0,0 @@ - .file "panic.c" - .text - .section .rodata.str1.1,"aMS",@progbits,1 -.LC0: - .string "(no message given)" -.LC1: - .string "double panic!\n" -.LC2: - .string "panic! - " - .text - .p2align 4,,15 - .globl StartPanic - .type StartPanic, @function -StartPanic: -.LFB3: - .cfi_startproc - pushq %r13 - .cfi_def_cfa_offset 16 - .cfi_offset 13, -16 - pushq %r12 - .cfi_def_cfa_offset 24 - .cfi_offset 12, -24 - pushq %rbp - .cfi_def_cfa_offset 32 - .cfi_offset 6, -32 - pushq %rbx - .cfi_def_cfa_offset 40 - .cfi_offset 3, -40 - movq %rdi, %rbx - subq $8, %rsp - .cfi_def_cfa_offset 48 -/APP -# 43 "kaleid/kernel/ke/panic.c" 1 - cli -# 0 "" 2 -/NO_APP - movabsq $__kstate, %rax - movabsq $stdout, %rbp - movabsq $__panicmsg, %r13 - movb $2, (%rax) - movq 0(%rbp), %rdi - movabsq $ClearTermUnlocked, %rax - call *%rax - testq %rbx, %rbx - movabsq $.LC0, %rax - movq 0(%rbp), %rdi - cmove %rax, %rbx - cmpq $0, 0(%r13) - movabsq $PrintOnTermUnlocked, %r12 - je .L3 - movabsq $.LC1, %rsi - call *%r12 -/APP -# 55 "kaleid/kernel/ke/panic.c" 1 - hlt -# 0 "" 2 -/NO_APP -.L3: - movabsq $.LC2, %rsi - movq 0(%rbp), %rdi - movq %rbx, 0(%r13) - call *%r12 - movq %rbx, %rsi - movq 0(%rbp), %rdi - call *%r12 - .p2align 4,,10 - .p2align 3 -.L4: -/APP -# 65 "kaleid/kernel/ke/panic.c" 1 - hlt -# 0 "" 2 -/NO_APP - jmp .L4 - .cfi_endproc -.LFE3: - .size StartPanic, .-StartPanic - .p2align 4,,15 - .globl _assert_handler - .type _assert_handler, @function -_assert_handler: -.LFB2: - .cfi_startproc - subq $8, %rsp - .cfi_def_cfa_offset 16 -/APP -# 30 "kaleid/kernel/ke/panic.c" 1 - cli -# 0 "" 2 -/NO_APP - movabsq $StartPanic, %rax - call *%rax - .cfi_endproc -.LFE2: - .size _assert_handler, .-_assert_handler - .globl __panicmsg - .section .bss - .align 8 - .type __panicmsg, @object - .size __panicmsg, 8 -__panicmsg: - .zero 8 - .ident "GCC: (GNU) 7.3.0" diff --git a/obj/kaleid/kernel/ke/state.S b/obj/kaleid/kernel/ke/state.S deleted file mode 100644 index 11ea154..0000000 --- a/obj/kaleid/kernel/ke/state.S +++ /dev/null @@ -1,4 +0,0 @@ - .file "state.c" - .text - .comm __kstate,1,1 - .ident "GCC: (GNU) 7.3.0" diff --git a/src/CONTACT b/src/CONTACT deleted file mode 100644 index dd6d86a..0000000 --- a/src/CONTACT +++ /dev/null @@ -1 +0,0 @@ -XXX diff --git a/src/kaleid/common/old/common.h b/src/kaleid/common/old/common.h deleted file mode 100644 index 1c9c0d6..0000000 --- a/src/kaleid/common/old/common.h +++ /dev/null @@ -1,179 +0,0 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: Standard include file for both kernel/ and system/ // -//----------------------------------------------------------------------------// - -#ifndef _KALCOMM_COMMON_H -#define _KALCOMM_COMMON_H - -//------------------------------------------// -// PREPROCESSOR CONSTANTS // -//------------------------------------------// - -#if !defined(_OSK_SOURCE) -# if defined(_KALEID_KERNEL) || defined(_KALEID_SYSTEM) -# define _OSK_SOURCE 1 -# endif -#endif - -#if !defined(TRUE) && !defined(FALSE) -# define TRUE (1) -# define FALSE (0) -#endif - -#ifdef _OSK_SOURCE -# define YES (1) -# define NO (0) -#endif - -#ifndef NULL -# define NULL ((void *)0) -#endif - -#ifndef PACKED -# define PACKED __attribute__((packed)) -#endif - -#ifndef noreturn -# define noreturn __attribute__((noreturn)) -#endif - -#if !defined(likely) && !defined(unlikely) -# define likely(x) (__builtin_expect((x), 1)) -# define unlikely(x) (__builtin_expect((x), 0)) -#endif - -#ifndef alignof -# define alignof _Alignof -#endif - -#ifndef INITOK -# define INITOK ((unsigned int)0xCAFEBABE) -#endif - -#ifndef KALAPI -# define KALAPI -#endif - -#ifdef _KALEID_KERNEL -# include -#endif - -//------------------------------------------// -// COMMON TYPES // -//------------------------------------------// - -typedef unsigned char uchar; -typedef unsigned short ushort; -typedef unsigned int uint; -typedef unsigned long ulong; -typedef long long llong; -typedef unsigned long long ullong; -typedef long double ldouble; -typedef short port_t; -typedef short status_t; - -#ifndef KEEP_KALCOMM_TYPES_MINIMAL -typedef _Bool bool; -typedef uint wchar_t; -typedef ullong size_t; -typedef llong ssize_t; -typedef size_t off_t; -typedef int atomic_t; -typedef ulong pid_t; -typedef void *va_list; -#endif - -// XXX limits - - -//------------------------------------------// -// VALUES FOR "status_t" // -//------------------------------------------// - -#ifndef _OSK_SOURCE -# define describe_status _osk_describe_status -#endif - -// see in common/lib/status.c for status messages -const char *describe_status(status_t); - -#define STATUS_FAILED(x) ((x) < 0)) -#define STATUS_SUCCESS(x) (!STATUS_FAILED(x)) - -#define SUCCESS (0) // everything went fine - -#define FAILED (-1) -#define ERROR FAILED // something went wrong -#define NOT_PERMITTED (-2) -#define ACCESS_DENIED (-3) - -#define BAD_ARGUMENT (-4) // invalid arguments -#define BAD_ARG_RANGE (-5) // arguments out of range -#define BAD_ARG_NULL (-6) // unexpected NULL argument - -#define TRY_AGAIN (-7) // EAGAIN - -//------------------------------------------// -// INLINE ASM MACROS // -//------------------------------------------// - - -#ifdef _KALEID_KERNEL -# define DisableInterrupts() asm volatile ("cli") -# define EnableInterrupts() asm volatile ("sti") -# define HaltCPU() asm volatile ("hlt") -#endif - -//------------------------------------------// -// assert()/DosAssert() SUPPORT // -//------------------------------------------// - -#ifdef _OSK_SOURCE - -#if !defined(_NO_DEBUG) && !defined(NDEBUG) - -// uses panic() in kernel, abort() in system -noreturn void _assert_handler(const char *, const char *, int, const char *); - -#define DosAssert(x) \ - do { \ - if unlikely(!(x)) \ - _assert_handler(#x, __FILE__, __LINE__, __func__); \ - } while (FALSE); -#define assert DosAssert - -#else // not debugging - -#if !defined(NDEBUG) -# define NDEBUG 1 -#endif - -#if !defined(_NO_DEBUG) -# define _NO_DEBUG 1 -#endif - -#define assert(x) - -#endif - -#else // !defined(_OSK_SOURCE) - -#if defined(_NO_DEBUG) && !defined(NDEBUG) -# define NDEBUG 1 -#endif - -#include - -#endif - -//------------------------------------------// -// END OF "kaleid/common/common.h" // -//------------------------------------------// - -#endif - diff --git a/src/kaleid/common/old/folder.desc b/src/kaleid/common/old/folder.desc deleted file mode 100644 index eaf5c24..0000000 --- a/src/kaleid/common/old/folder.desc +++ /dev/null @@ -1,37 +0,0 @@ ---------------------------------------------------------------------- - GNU GPL OS/K - - Authors: spectral` - NeoX - - Desc: Folder description - "kaleid/common" ---------------------------------------------------------------------- - -This is the folder containing the sources for Kaleid's C runtime library, linked -both to the kernel and to the system processes that run outiside the kernel. -It can also be compiled for Linux as a very basic C library, for test purposes. - -This folder contains the following files: - - common.h - This file is to be included by every source file using the library. - It: - - Provides the elementary types (e.g. size_t) used through Kaleid. - - - Defines the different values of the "status_t" type used - throughout Kaleid and related utilitary functions. - - - Defines the macro "assert()". Currently any program wanting to - use this macro has to implement its own handler: - noreturn void _assert_handler(const char *cond, - const char *file, - int line, - const char *func) - but an overridable default handler will be furnished later. - - - stlib.h - The include file for most of functions of the common library, notably - - Memory management utilities (e.g. memset()) - - String manipulation utilities (e.g. strcpy()) - - Type conversion utilities (e.g. itoa()) - - diff --git a/src/kaleid/common/old/stdlib.h b/src/kaleid/common/old/stdlib.h deleted file mode 100644 index 5f8e96c..0000000 --- a/src/kaleid/common/old/stdlib.h +++ /dev/null @@ -1,90 +0,0 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: Kaleid C runtime library // -//----------------------------------------------------------------------------// - -#ifndef _KALCOMM_STDLIB_H -#define _KALCOMM_STDLIB_H - -//------------------------------------------// -// Typedefs // -//------------------------------------------// - -#ifndef __size_t -#define __size_t -typedef unsigned long size_t; -#endif - -#ifndef __va_list -#define __va_list -typedef __builtin_va_start va_list; -#endif - -//------------------------------------------// -// Memory management utilitaries // -//------------------------------------------// - -#ifndef _OSK_SOURCE -# define memcpy _osk_memcpy -# define memcmp _osk_memcmp -# define memzero _osk_memzero -#endif - -#ifndef memset -# define memset memsetb -#endif -void *memsetb(void *, int, size_t); -void *memsetw(void *, int, size_t); -void *memsetd(void *, int, size_t); -void *memsetq(void *, long, size_t); - -void *memzero(void *, size_t); - -//------------------------------------------// -// String manipulation utilitaries // -//------------------------------------------// - -#ifndef _OSK_SOURCE -# define strlen _osk_strlen -# define strcpy _osk_strcpy -# define strncpy _osk_strncpy -# define strrev _osk_strrev -# define reverse _osk_reverse -# define sprintf _osk_sprintf -# define snprintf _osk_snprintf -# define vsprintf _osk_vsprintf -# define vsnprintf _osk_vsnprintf -#endif - -size_t strlen(const char *); -char *strcpy(char *, const char *); -char *strncpy(char *, const char *, size_t); -char *strrev(char *dest, const char *src); -char *reverse(char *); - -int sprintf(char *, const char *, ...); -int snprintf(char *, size_t, const char *, ...); -int vsprintf(char *, const char *, va_list); -int vsnprintf(char *, size_t, const char *, va_list); - -//------------------------------------------// -// Type conversion utilities // -//------------------------------------------// - -#ifndef _OSK_SOURCE -# define itoa _osk_itoa -# define atoi _osk_atoi -#endif - -char *itoa(int, char *, int); - -//------------------------------------------// -// End of header file // -//------------------------------------------// - -#endif - diff --git a/src/kaleid/common/string.c b/src/kaleid/common/string.c deleted file mode 100644 index 81b4847..0000000 --- a/src/kaleid/common/string.c +++ /dev/null @@ -1,100 +0,0 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: String-related functions // -//----------------------------------------------------------------------------// - -#include - -// -// Returns str's length -// -size_t strlen(const char *str) -{ - const char *base = str; - - while (*str++); - - return (str - base - 1); -} - -// -// Copy the string src into dest -// -char *strcpy(char *dest, const char *src) -{ - char *base = dest; - while ((*dest++ = *src++)); - return base; -} - -// -// strcpy() but always writes n bytes -// -char *strncpy(char *dest, const char *src, size_t n) -{ - size_t it; - - for (it = 0; it < n && src[it]; it++) { - dest[it] = src[it]; - } - - while (it < n) dest[it++] = 0; - return dest; -} - -// -// strncpy() but safer - always null-terminate, -// returns boolean indicating whether copy was complete -// XXX find a better name -// XXX actually implement this -// -size_t xstrcnpy(char *dest, const char *src, size_t n) -{ - size_t it; - - for (it = 0; it < n && src[it]; it++) { - dest[it] = src[it]; - } - - while (it < n) dest[it++] = 0; - - return TRUE; -} - -// -// Reverses the string src, putting the result into dest -// -char *strrev(char *dest, const char *src) -{ - char *orig = dest; - size_t n = strlen(src); - - dest[n--] = '\0'; - - while ((*dest++ = src[n--])); - - return orig; -} - -// -// Reverses a string, modifying it -// Returns a point to said string -// -char *reverse(char *str) -{ - char ch, *orig = str; - size_t n = strlen(str); - char *temp = str + n - 1; - - while (temp > str) { - ch = *temp; - *temp-- = *str; - *str++ = ch; - } - - return orig; -} diff --git a/src/kaleid/common/test/test-common.c b/src/kaleid/common/test/test-common.c deleted file mode 100644 index e4df713..0000000 --- a/src/kaleid/common/test/test-common.c +++ /dev/null @@ -1,83 +0,0 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: Test file for common/ // -//----------------------------------------------------------------------------// - -#include -#include - -void *_osk_memsetw(void *, int, long); -char *_osk_itoa(int, char *, int); -char *_osk_ltoa(long, char *, int); -char *_osk_utoa(unsigned int, char *, int); -char *_osk_ultoa(unsigned long, char *, int); - -int main(int argc, char *argv[]) -{ - (void)argc; - (void)argv; - - // please don't mind how weird this file is - // I remove tests of "simple" functions after - // I'm done with testing that function - // so a lot of test variables remain in case - // I need them for a future test - - //const char *test1 = "test string\n"; - //const size_t size1 = strlen(test1); - //char *test2 = malloc(size1); - //char *test3 = malloc(size1); - -#if 0 - const size_t sizex = 130; - short *xxx = (short *)malloc(sizex * sizeof(short)); - //printf("%ld\n",(ulong)xxx%8); - //memzero(xxx, sizex); - _osk_memsetw(xxx, 300, sizex); - - size_t it; - for (it = 0; it < sizex; it++) { - short s = *(xxx + it); - printf("%hd", s); - } - free((void *)xxx); -#endif - - char buf[256]; - - puts(_osk_ultoa(5000000000, buf, 10)); - - puts(""); - - - //const char *str = "ceci est un string de test!"; - //char *str2 = malloc((strlen(str) + 3) * sizeof(char)); - //char *str3 = malloc((strlen(str) + 3) * sizeof(char)); - - //strcpy(str2, str); - - //size_t s = strlen(str2); - - //strrev(str3,str2); - //printf("%lu - %s\n", strlen(str3), str3); - - //str2[s] = '\n'; - //str2[s+1] = '\0'; - //strrev(str2,str3); - //printf("%lu - %s\n", strlen(str2), str2); - - //free(str2); - //free(str3); - - - - //free(test2); - //free(test3); - - return 0; -} - diff --git a/src/kaleid/common/test/test-file0.c b/src/kaleid/common/test/test-file0.c deleted file mode 100644 index 59ba1cc..0000000 --- a/src/kaleid/common/test/test-file0.c +++ /dev/null @@ -1,28 +0,0 @@ -// random test file - -#include -#include - -int main(int argc, char *argv[]) -{ - long x[4]; - long *ptr = &x[0]; - - printf("%d\n", CHAR_MIN); - - printf("%hhd\n", (1 << 7)); - - printf("%p\n", ptr); - - ptr++; - printf("%p\n", ptr); - - ptr = ptr + 1; - printf("%p\n", ptr); - - ptr = (long *)((long)ptr + 1); - printf("%p\n", ptr); - - return 0; -} - diff --git a/src/kaleid/include/kalkern b/src/kaleid/include/kalkern deleted file mode 120000 index 195d388..0000000 --- a/src/kaleid/include/kalkern +++ /dev/null @@ -1 +0,0 @@ -../kernel \ No newline at end of file diff --git a/src/kaleid/kernel/config.h b/src/kaleid/kernel/config.h deleted file mode 100644 index 6c43ff8..0000000 --- a/src/kaleid/kernel/config.h +++ /dev/null @@ -1,42 +0,0 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: Default configuration file // -//----------------------------------------------------------------------------// - -// XXX update the tree etc - -// This file is to be copied to "config.h" and edited before compilation -// We may do a script that generates "config.h" for the user, asking about -// the different configuration choices in the terminal. - -#ifndef _KALCOMM_CONFIG_H -#define _KALCOMM_CONFIG_H - -//------------------------------------------// -// General configuration choices // -//------------------------------------------// - -// -// Enable/disable multiprocessor support -// -#define MULTIPROCESSOR FALSE - -// -// Enable/disable preemptivity -// -#define PREEMPTIVE TRUE - -// -// Size of a tabulation in spaces -// Default: 4 spaces/tab -// -#define TABSIZE 4 - -// this file is to be progressively filled - -#endif - diff --git a/src/kaleid/kernel/config.h.in b/src/kaleid/kernel/config.h.in deleted file mode 100644 index 501be3d..0000000 --- a/src/kaleid/kernel/config.h.in +++ /dev/null @@ -1,42 +0,0 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: Default configuration file // -//----------------------------------------------------------------------------// - -// XXX update the tree etc - -// This file is to be copied to "config.h" and edited before compilation -// We may do a script that generates "config.h" for the user, asking about -// the different configuration choices in the terminal. - -#ifndef _KALCOMM_CONFIG_H -#define _KALCOMM_CONFIG_H - -//------------------------------------------// -// General configuration choices // -//------------------------------------------// - -// -// Enable/disable multiprocessor support -// -#define MULTIPROCESSOR NO - -// -// Enable/disable preemptivity -// -#define PREEMPTIVE YES - -// -// Size of a tabulation in spaces -// Default: 4 spaces/tab -// -#define TABSIZE 4 - -// this file is to be progressively filled - -#endif - diff --git a/src/kaleid/kernel/folder.desc b/src/kaleid/kernel/folder.desc deleted file mode 100644 index e85aabc..0000000 --- a/src/kaleid/kernel/folder.desc +++ /dev/null @@ -1,37 +0,0 @@ ---------------------------------------------------------------------- - GNU GPL OS/K - - Authors: spectral` - NeoX - - Desc: Folder description - "kaleid/kernel" ---------------------------------------------------------------------- - -This folder contains the source of Kaleid's kernel component. - -This contains the following files: - - init.c - The file containing the entry point of Kaleid, the kstart() function - called from the bootloader (see ../../boot). - -This folder also has the following subfolders: - - mm/ - This folder contains all files related to memory management. - - - fs/ - This folder will contain Kaleid's virtual filesystem, as well as one - subfolder for each FS supported by Kaleid (e.g. FAT filesystem). - - - io/ - I/O folder. (XXX) - - - ps/ - This folder will contain Kaleid's process manager and scheduler, as well - as the implementation of the related syscalls and functions. - - - ex/ - This folder contains the exec()-related functions and syscalls, as well - as one subfolder per executable format supported by Kaleid - (e.g. ELF executable) - - diff --git a/src/kaleid/kernel/init.h b/src/kaleid/kernel/init.h deleted file mode 100644 index db03c33..0000000 --- a/src/kaleid/kernel/init.h +++ /dev/null @@ -1,21 +0,0 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: Include file for init.c // -//----------------------------------------------------------------------------// - -#ifndef _KALKERN_INIT_H -#define _KALKERN_INIT_H - -#ifndef _KALKERN_H -#include -#endif - -// kernel entry point -void StartKern(void); - -#endif - diff --git a/src/kaleid/kernel/io/terminal.c b/src/kaleid/kernel/io/terminal.c deleted file mode 100644 index dbf5963..0000000 --- a/src/kaleid/kernel/io/terminal.c +++ /dev/null @@ -1,210 +0,0 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: Early terminal functions // -//----------------------------------------------------------------------------// - -#define _UNLOCKED_IO -#include - -// -// VGA-related macros -// -#define ComputeColorCode(fg, bg) ((fg) | (bg) << 4) -#define ComputeOffset(kt, x, y) ((y) * kt->kt_width + (x)) -#define ComputeEntry(ch, cl) (((ushort)(ch)) | (ushort)(cl) << 8) - -// -// VGA output -// -static terminal_t _vga_term = { - .kt_buffer = (ushort *)0xB8000, - .kt_width = 80, - .kt_height = 25, - .kt_curr_x = 0, - .kt_curr_y = 0, - .kt_color = ComputeColorCode(KTERM_COLOR_LGREY, KTERM_COLOR_BLACK), - .kt_lock = INITLOCK(KLOCK_MUTEX), - .kt_init = FALSE, -}; - -// -// Standard output terminal -// -terminal_t *stdout; - -// -// Debugging terminal -// -terminal_t *stddbg; - -// -// Initialize standard output -// -void InitTerms(void) -{ - Assert(!stdout && _vga_term.kt_init != INITOK); - - _vga_term.kt_init = INITOK; - stddbg = &_vga_term; - - // to be switched to VESA - stdout = &_vga_term; - ClearTerm(stdout); -} - -// -// Fill terminal with spaces -// -status_t ClearTerm(terminal_t *kt) -{ - if (kt == NULL) - return BAD_ARG_NULL; - - Assert(kt->kt_init == INITOK); - - LockTerm(kt); - ClearTermUnlocked(kt); - UnlockTerm(kt); - - return SUCCESS; -} - -// -// Change the color code -// -status_t ChTermColor(terminal_t *kt, uchar color) -{ - if (color > KTERM_COLOR_WHITE) - return BAD_ARG_RANGE; - - if (kt == NULL) - return BAD_ARG_NULL; - - LockTerm(kt); - kt->kt_color = color; - UnlockTerm(kt); - - return SUCCESS; -} - -// -// Write a single character on the terminal -// -status_t PutOnTerm(terminal_t *kt, char ch) -{ - if (kt == NULL) - return BAD_ARG_NULL; - - Assert(kt->kt_init == INITOK); - - LockTerm(kt); - PutOnTermUnlocked(kt, ch); - UnlockTerm(kt); - - return SUCCESS; -} - -// -// Print string on terminal -// -status_t PrintOnTerm(terminal_t *kt, const char *str) -{ - if (kt == NULL) - return BAD_ARG_NULL; - - Assert(kt->kt_init == INITOK); - - LockTerm(kt); - while (*str) { - PutOnTermUnlocked(kt, *str++); - } - UnlockTerm(kt); - - return SUCCESS; -} - -//----------------------------------------------------------// -// UNLOCKED VERSIONS // -// // -// Direct use is highly deprecated // -// Useful in rare instances // -//----------------------------------------------------------// - -// -// Fill terminal with spaces (UNLOCKED version) -// XXX would '\0' work too? -// -void ClearTermUnlocked(terminal_t *kt) -{ - size_t i; - - const ushort filler = ComputeEntry(' ', kt->kt_color); - const size_t bufsize = kt->kt_width * kt->kt_height; - - for (i = 0; i < bufsize; i++) { - // XXX implement memsetw() - kt->kt_buffer[i] = filler; - } - - kt->kt_curr_x = kt->kt_curr_y = 0; -} - -// -// Write a single character on the terminal (UNLOCKED version) -// -void PutOnTermUnlocked(terminal_t *kt, char ch) -{ - int i; - size_t prev_row; - - // carriage return takes us back to the beginning of the line - // no further test should be necessary - if (ch == '\r') { kt->kt_curr_x = 0; return; } - - // line feed first takes us to the very end of the line - // later in this function we actually do the line feed - else if (ch == '\n') { kt->kt_curr_y = kt->kt_width - 1; } - - // tabulations account for "TABSIZE" spaces - else if (ch == '\t') { - prev_row = kt->kt_curr_y; - // compiler will optimize this away - for (i = 0; i < TABSIZE; i++) { - // tabulations can't spread over two lines - if (kt->kt_curr_y == prev_row) { - PutOnTermUnlocked(kt, ' '); - } - } - } - - else { - // actually write on the buffer - const size_t offset = ComputeOffset(kt, kt->kt_curr_x, kt->kt_curr_y); - kt->kt_buffer[offset] = ComputeEntry(ch, kt->kt_color); - } - - // end of line? - if (++kt->kt_curr_x == kt->kt_width) { - kt->kt_curr_x = 0; - - // line feed + end of buffer? - if (++kt->kt_curr_y == kt->kt_height) { - kt->kt_curr_y = 0; - } - } -} - -// -// Print string on terminal (UNLOCKED version) -// -void PrintOnTermUnlocked(terminal_t *kt, const char *str) -{ - while (*str) { - PutOnTermUnlocked(kt, *str++); - } -} - diff --git a/src/kaleid/kernel/io/terminal.h b/src/kaleid/kernel/io/terminal.h deleted file mode 100644 index df42066..0000000 --- a/src/kaleid/kernel/io/terminal.h +++ /dev/null @@ -1,69 +0,0 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: Early terminal functions // -//----------------------------------------------------------------------------// - -#ifndef _KALKERN_IO_KTERM_H -#define _KALKERN_IO_KTERM_H - -#include - -// all available colors -enum terminal_colors { - KTERM_COLOR_BLACK, KTERM_COLOR_BLUE, - KTERM_COLOR_GREEN, KTERM_COLOR_CYAN, - KTERM_COLOR_RED, KTERM_COLOR_MAGENTA, - KTERM_COLOR_BROWN, KTERM_COLOR_LGREY, - KTERM_COLOR_DARK_GREY, KTERM_COLOR_LBLUE, - KTERM_COLOR_LGREEN, KTERM_COLOR_LCYAN, - KTERM_COLOR_LRED, KTERM_COLOR_LMAGENTA, - KTERM_COLOR_LBROWN, KTERM_COLOR_WHITE -}; - -typedef struct { - lock_t kt_lock; - ushort *kt_buffer; - uchar kt_color; - size_t kt_width; - size_t kt_height; - off_t kt_curr_x; - off_t kt_curr_y; - uint kt_init; - // XXX flags -} terminal_t; - -// current "standard" terminal -extern terminal_t *stdout; - -// current debugging terminal -extern terminal_t *stddbg; - -void InitTerms(void); -status_t ClearTerm(terminal_t *); -status_t PutOnTerm(terminal_t *, char); -status_t PrintOnTerm(terminal_t *, const char *); -status_t ChTermColor(terminal_t *, uchar); - -#if defined(_UNLOCKED_IO) -void ClearTermUnlocked(terminal_t *); -void PutOnTermUnlocked(terminal_t *, char); -void PrintOnTermUnlocked(terminal_t *, const char *); -#define ChTermColorUnlocked(kt, col) ((kt)->kt_color = (col)) -#endif - -#ifndef _NO_DEBUG -# define DebugLog(...) PrintOnTerm(stddbg, __VA_ARGS__) -#else -# define DebugLog(...) -#endif - -#define LockTerm(kt) AquireLock(&(kt)->kt_lock) -#define UnlockTerm(kt) ReleaseLock(&(kt)->kt_lock) -#define TryLockTerm(kt) AttemptLock(&(kt)->kt_lock) - -#endif - diff --git a/src/kaleid/kernel/ke/lock.c b/src/kaleid/kernel/ke/lock.c deleted file mode 100644 index 465b76f..0000000 --- a/src/kaleid/kernel/ke/lock.c +++ /dev/null @@ -1,13 +0,0 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: Locks // -//----------------------------------------------------------------------------// - -#include - -// nothing to do here - diff --git a/src/kaleid/kernel/ke/lock.h b/src/kaleid/kernel/ke/lock.h deleted file mode 100644 index 6841025..0000000 --- a/src/kaleid/kernel/ke/lock.h +++ /dev/null @@ -1,98 +0,0 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: Locks // -//----------------------------------------------------------------------------// - -#ifndef _KALKERN_KE_LOCK_H -#define _KALKERN_KE_LOCK_H - -#ifndef _KALKERN_H -#include -#endif - -enum lock_type { - // - // Mutex-type lock - // - // WARNING - // AquireLock() panics when used on a mutex while not running a process - // - KLOCK_MUTEX, - - // - // Spinlock-type lock - // Turns into a Mutex-type lock when MULTIPROCESSOR is off - // - KLOCK_SPINLOCK, - -}; - -typedef struct { - uchar lk_type; // lock type? - uint lk_lock; // is locked? - void *lk_owner; // unused - void *lk_waiting; // unused - uint lk_init; // unused if _NO_DEBUG -} lock_t; - -// -// Initialize a lock -// -#define InitLock(lk, type) \ - do { \ - (lk)->lk_type = (type); \ - (lk)->lk_lock = FALSE; \ - (lk)->lk_owner = NULL; \ - (lk)->lk_waiting = NULL; \ - (lk)->lk_init = INITOK; \ - } while (FALSE); - -// -// Alternative way to initalize a lock -// -#define INITLOCK(type) { (type), FALSE, NULL, NULL, INITOK } - -// -// Does nothing -// -#define DestroyLock(lk) ((lk)->lk_init = FALSE) - -// -// Aquires the lock -// Panics on double aquisition since that should never happen -// until we have at least a basic scheduler -// -#define AquireLock(lk) \ - do { \ - DisableInterrupts(); \ - Assert((lk)->lk_init == INITOK); \ - if ((lk)->lk_lock++) \ - StartPanic("DosAquireLock on an already locked object"); \ - EnableInterrupts(); \ - } while (FALSE); - -// -// Releases an already aquired lock -// Panics if the lock was never aquired (this will change) -// -#define ReleaseLock(lk) \ - do { \ - DisableInterrupts(); \ - Assert((lk)->lk_init == INITOK); \ - if ((lk)->lk_lock++) \ - StartPanic("DosReleaseLock on an unlocked object"); \ - EnableInterrupts(); \ - } while (FALSE); - -// -// Tries to aquire lock -// Doesn't work at all for obvious reasons -// -#define AttemptLock(lk) ((lk)->lk_lock++) - -#endif - diff --git a/src/kaleid/kernel/ke/panic.h b/src/kaleid/kernel/ke/panic.h deleted file mode 100644 index 372848e..0000000 --- a/src/kaleid/kernel/ke/panic.h +++ /dev/null @@ -1,24 +0,0 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: Looking to create some panic? Look no further! // -//----------------------------------------------------------------------------// - -#ifndef _KALKERN_KE_PANIC_H -#define _KALKERN_KE_PANIC_H - -#ifndef _KALKERN_H -#include -#endif - -noreturn void StartPanic(const char *); -noreturn void CrashSystem(void); - -extern const char *__panicmsg; -#define GetPanicStr() (__panicmsg) -#define SetPanicStr(str) (__panicmsg = (str)) - -#endif diff --git a/src/kaleid/kernel/ke/state.c b/src/kaleid/kernel/ke/state.c deleted file mode 100644 index 4d65f89..0000000 --- a/src/kaleid/kernel/ke/state.c +++ /dev/null @@ -1,16 +0,0 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: Current kernel state // -//----------------------------------------------------------------------------// - -#include - -// -// Current kernel state -// -uchar __kstate; - diff --git a/src/kaleid/kernel/ke/state.h b/src/kaleid/kernel/ke/state.h deleted file mode 100644 index 6f5de07..0000000 --- a/src/kaleid/kernel/ke/state.h +++ /dev/null @@ -1,37 +0,0 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: Current kernel state // -//----------------------------------------------------------------------------// - -#ifndef _KALKERN_KE_STATE_H -#define _KALKERN_KE_STATE_H - -#ifndef _KALKERN_H -#include -#endif - -// XXX improve this -enum kernel_states { - // a process is running in kernel mode - KSTATE_PROCESS, - - // the kernel is not running a process - KSTATE_KERNEL, - - // the kernel is panicking - KSTATE_PANIC, - - // the kernel is booting - KSTATE_INIT, -}; - -extern uchar __kstate; -#define GetKernState() (__kstate) -#define SetKernState(x) (__kstate = (x)) - -#endif - diff --git a/src/preproc.h b/src/preproc.h deleted file mode 100644 index b55004d..0000000 --- a/src/preproc.h +++ /dev/null @@ -1,33 +0,0 @@ -// be careful with this file - -#ifdef _TESTS -# define CCC TCC -#else -# define CCC KCC -#endif - -#ifdef _TO_ASM -# define _CSPREF -S -# define _OUTFIX S -# define LINK_KERNEL(out) -#else -# define _CSPREF -c -# define _OUTFIX o -# define LINK_KERNEL(out) $(KCC) $(CLDSCR) $(COMMOBJS) $(KERNOBJS) -o $(BINDIR)/out -#endif - -#define COMPILE_CONVRT(file) $(CCC) _CSPREF $(COMMDIR)/itoa.c -o $(COBJDIR)/file._OUTFIX -#define COMPILE_COMMON(file) $(CCC) _CSPREF $(COMMDIR)/file.c -o $(COBJDIR)/file._OUTFIX -#define COMPILE_KERNEL(file) $(KCC) _CSPREF $(KERNDIR)/file.c -o $(KOBJDIR)/file._OUTFIX - -#define COBJ1(x1) $(COBJDIR)/x1.o -#define COBJ2(x1,x2) $(COBJDIR)/x1.o $(COBJDIR)/x2.o -#define COBJ3(x1,x2,x3) $(COBJDIR)/x1.o $(COBJDIR)/x2.o $(COBJDIR)/x3 -#define COBJ4(x1,x2,x3,x4) $(COBJDIR)/x1.o $(COBJDIR)/x2.o $(COBJDIR)/x3.o $(COBJDIR)/x4.o -#define COBJ5(x1,x2,x3,x4,x5) $(COBJDIR)/x1.o $(COBJDIR)/x2.o $(COBJDIR)/x3.o $(COBJDIR)/x4.o $(COBJDIR)/x5.o - -#define KOBJ1(x1) $(KOBJDIR)/x1.o -#define KOBJ2(x1,x2) $(KOBJDIR)/x1.o $(KOBJDIR)/x2.o -#define KOBJ3(x1,x2,x3) $(KOBJDIR)/x1.o $(KOBJDIR)/x2.o $(KOBJDIR)/x3 -#define KOBJ4(x1,x2,x3,x4) $(KOBJDIR)/x1.o $(KOBJDIR)/x2.o $(KOBJDIR)/x3.o $(KOBJDIR)/x4.o -#define KOBJ5(x1,x2,x3,x4,x5) $(KOBJDIR)/x1.o $(KOBJDIR)/x2.o $(KOBJDIR)/x3.o $(KOBJDIR)/x4.o $(KOBJDIR)/x5.o diff --git a/src/project-style.txt b/src/project-style.txt deleted file mode 100644 index 4ed65ad..0000000 --- a/src/project-style.txt +++ /dev/null @@ -1,19 +0,0 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: Notes on the coding style and // -// conventions used throughout OS/K // -//----------------------------------------------------------------------------// - -To keep naming conventions and code style, we have decided to create this file. -How the code looks isn't the most important, so don't worry too much about this; -making the code conform to this file can be done later. - -Every file within OS/K is written using spaces for tabulation, with each -tabulation being 4 spaces long. - -(naming conventions here) - diff --git a/src/project-tree.txt b/src/project-tree.txt deleted file mode 100644 index e0e3f4d..0000000 --- a/src/project-tree.txt +++ /dev/null @@ -1,101 +0,0 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: Project Tree // -//----------------------------------------------------------------------------// - -src/ - | - x COPYING - x CONTACT - x ChangeLog - | - - Makefile - - kernel.ld - | - + boot/ - | | - | x folder.desc - | | - | - mbr.s - | - mbr.inc - | | - | - loader.s - | - loader16.inc - | - loader64.inc - | | - | 0 - | - + kaleid/ - | | - | + include/ - | | | - | | - kaleid.h - | | - kaldefs.h - | | - kaltypes.h - | | - kalassrt.h - | | - kalmask.h - | | - kalcrt.h - | | | - | | - kalkern.h - | | | - | | ~ kalkern/ -> ../kernel/ - | | | - | | 0 - | | - | | - | + kernel/ - | | | - | | x folder.desc - | | | - | | - config.h - | | - config.h.in - | | | - | | - init.c - | | - init.h - | | | - | | + io/ - | | | | - | | | - ports.c - | | | - ports.h - | | | | - | | | - terminal.c - | | | - terminal.h - | | | | - | | | 0 - | | | - | | + ke/ - | | | | - | | | - lock.c - | | | - lock.h - | | | | - | | | - panic.c - | | | - panic.h - | | | | - | | | - state.c - | | | - state.h - | | | | - | | | 0 - | | | - | | 0 - | | - | + common/ - | | | - | | - status.c - | | | - | | - string.c - | | - memory.c - | | - convert.c - | | - sprintf.c - | | | - | | + test/ - | | | | - | | | - test-common.c - | | | | - | | | 0 - | | 0 - | 0 - 0