KFS

kernel from scratch course
Log | Files | Refs | README | LICENSE | git clone https://git.ne02ptzero.me/git/KFS

commit 98bc72937735a51d34747a13a4eefcfc92b2e6e0
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Sat, 21 Apr 2018 13:18:40 +0200

[TREE] ADD: KFS Subjects, from 1 to 10

Signed-off-by: Ne02ptzero <louis@ne02ptzero.me>

 _____________________________________
/ You're a card which will have to be \
\ dealt with.                         /
 -------------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

Diffstat:
ALICENSE | 674+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
AREADME.md | 1+
Akfs_1/bren1.jpg | 0
Akfs_1/bren10.jpg | 0
Akfs_1/bren11.jpg | 0
Akfs_1/bren12.jpg | 0
Akfs_1/bren13.jpg | 0
Akfs_1/bren14.jpg | 0
Akfs_1/bren15.jpg | 0
Akfs_1/bren16.jpg | 0
Akfs_1/bren2.jpg | 0
Akfs_1/bren3.jpg | 0
Akfs_1/bren4.jpg | 0
Akfs_1/bren5.jpg | 0
Akfs_1/bren6.jpg | 0
Akfs_1/bren7.jpg | 0
Akfs_1/bren8.jpg | 0
Akfs_1/bren9.jpg | 0
Akfs_1/choose.jpg | 0
Akfs_1/kfs_1.en.tex | 299+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Akfs_10/choose.jpg | 0
Akfs_10/kfs_10.en.tex | 222+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Akfs_2/42.png | 0
Akfs_2/choose.jpg | 0
Akfs_2/kfs_2.en.tex | 291++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Akfs_3/cautionary.png | 0
Akfs_3/choose.jpg | 0
Akfs_3/kfs_3.en.tex | 340+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Akfs_3/operating_systems.png | 0
Akfs_3/page_directory_entry.png | 0
Akfs_3/paging_memory.png | 0
Akfs_3/processes.png | 0
Akfs_3/tar.png | 0
Akfs_4/choose.jpg | 0
Akfs_4/kfs_4.en.tex | 302++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Akfs_4/lol.jpg | 0
Akfs_5/choose.jpg | 0
Akfs_5/kfs_5.en.tex | 338+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Akfs_6/42.png | 0
Akfs_6/choose.jpg | 0
Akfs_6/kfs_6.en.tex | 354+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Akfs_6/oui.jpg | 0
Akfs_7/1.jpeg | 0
Akfs_7/2.jpeg | 0
Akfs_7/3.png | 0
Akfs_7/4.png | 0
Akfs_7/42.png | 0
Akfs_7/choose.jpg | 0
Akfs_7/kfs_7.en.tex | 340+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Akfs_8/choose.jpg | 0
Akfs_8/kfs_8.en.tex | 274+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Akfs_9/42.png | 0
Akfs_9/choose.jpg | 0
Akfs_9/kfs_9.en.tex | 219+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
54 files changed, 3654 insertions(+), 0 deletions(-)

diff --git a/LICENSE b/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/> + 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. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + 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 <https://www.gnu.org/licenses/>. + +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: + + <program> Copyright (C) <year> <name of author> + 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 +<https://www.gnu.org/licenses/>. + + 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 +<https://www.gnu.org/licenses/why-not-lgpl.html>. diff --git a/README.md b/README.md @@ -0,0 +1 @@ +# Kernel From Scratch diff --git a/kfs_1/bren1.jpg b/kfs_1/bren1.jpg Binary files differ. diff --git a/kfs_1/bren10.jpg b/kfs_1/bren10.jpg Binary files differ. diff --git a/kfs_1/bren11.jpg b/kfs_1/bren11.jpg Binary files differ. diff --git a/kfs_1/bren12.jpg b/kfs_1/bren12.jpg Binary files differ. diff --git a/kfs_1/bren13.jpg b/kfs_1/bren13.jpg Binary files differ. diff --git a/kfs_1/bren14.jpg b/kfs_1/bren14.jpg Binary files differ. diff --git a/kfs_1/bren15.jpg b/kfs_1/bren15.jpg Binary files differ. diff --git a/kfs_1/bren16.jpg b/kfs_1/bren16.jpg Binary files differ. diff --git a/kfs_1/bren2.jpg b/kfs_1/bren2.jpg Binary files differ. diff --git a/kfs_1/bren3.jpg b/kfs_1/bren3.jpg Binary files differ. diff --git a/kfs_1/bren4.jpg b/kfs_1/bren4.jpg Binary files differ. diff --git a/kfs_1/bren5.jpg b/kfs_1/bren5.jpg Binary files differ. diff --git a/kfs_1/bren6.jpg b/kfs_1/bren6.jpg Binary files differ. diff --git a/kfs_1/bren7.jpg b/kfs_1/bren7.jpg Binary files differ. diff --git a/kfs_1/bren8.jpg b/kfs_1/bren8.jpg Binary files differ. diff --git a/kfs_1/bren9.jpg b/kfs_1/bren9.jpg Binary files differ. diff --git a/kfs_1/choose.jpg b/kfs_1/choose.jpg Binary files differ. diff --git a/kfs_1/kfs_1.en.tex b/kfs_1/kfs_1.en.tex @@ -0,0 +1,299 @@ +%******************************************************************************% +% Copyright (C) 2018 Louis Solofrizzo % +% % +% This content is considered a 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 <https://www.gnu.org/licenses/>. % +%******************************************************************************% + +%******************************************************************************% +% % +% KFS_1.en.tex for KFS_1 % +% % +% Created on : Wed May 25 13:27:28 2016 % +% Made by : Louis "Ne02ptzero" Solofrizzo <louis@ne02ptzero.me> % +% % +%******************************************************************************% + +\documentclass{42-en} + + +%******************************************************************************% +% % +% Prologue % +% % +%******************************************************************************% + + +\begin{document} + + + \title{KFS\_1} + \subtitle{Grub, boot and screen} + \member{Louis Solofrizzo}{louis@ne02ptzero.me} + \member{42 Staff}{pedago@42.fr} + +\summary { + The real code ! +} + +\maketitle + +\tableofcontents + + +%******************************************************************************% +% % +% Forewords % +% % +%******************************************************************************% +\chapter{Forewords} + \includegraphics[width=8cm]{bren1.jpg} + \includegraphics[width=8cm]{bren2.jpg} + \includegraphics[width=8cm]{bren3.jpg} + \includegraphics[width=8cm]{bren4.jpg} + \includegraphics[width=8cm]{bren5.jpg} + \includegraphics[width=8cm]{bren6.jpg} + \includegraphics[width=8cm]{bren7.jpg} + \includegraphics[width=8cm]{bren8.jpg} + \includegraphics[width=8cm]{bren9.jpg} + \includegraphics[width=8cm]{bren10.jpg} + \includegraphics[width=8cm]{bren11.jpg} + \includegraphics[width=8cm]{bren12.jpg} + \includegraphics[width=8cm]{bren13.jpg} + \includegraphics[width=8cm]{bren14.jpg} + \includegraphics[width=8cm]{bren15.jpg} + \includegraphics[width=8cm]{bren16.jpg} + +\newpage +%******************************************************************************% +% % +% Introduction % +% % +%******************************************************************************% +\chapter{Introduction} + + Welcome to the first \texttt{Kernel from Scratch} project.\\ + + Finally some real coding, I'm pretty sure you were annoyed by the + Linux Kernel project. In the \texttt{Kernel from Scratch} subjects + you are going to write a kernel from scratch (no shit ?), without + any existing software, API, or such.\\ + + Once you will be done with those projects and standing on the + shoulder of your non-revolutionnary-OS, you will be in right to + laugh at those ordinary Javascript developers, who obviously, + don't know anything about coding.\\ + + On a more serious note, those kernel programming skills are not + quite spread in the IT world, so \textbf{take your time} to + understand each and every different points in those projects. One + does not simply consider himself a 'Kernel developer' if one only + knows things about drivers or syscalls, like a sysadmin only knows + things about iptables or softwares installation... It's a package + of skills.\\ + + A word about the code itself : the \texttt{Kernel From Scratch} is divided into many projects, + each one dealing with a specific aspect of kernel programming. All + of those projects are linked together. So when you'll code those + amazing features, keep in mind that your kernel must be flexible + and that functions must easily fit in. Half the time you'll spend + on these projects will be adding links between different aspects + of your Kernel.\\ + + For instance, you must write memory code before processus \& execution code. + But processus must use memory, right ? So, you gotta link those two ! + So keep your code *clean*, and your internal API simple.\\ + + Good luck, and most of all, have fun :) + +\newpage +%******************************************************************************% +% % +% Goals % +% % +%******************************************************************************% +\chapter{Goals} + + At the end of this subject, you will have: + + \begin{itemize}\itemsep1pt + \item A kernel you can boot via \texttt{GRUB} + \item An \texttt{ASM} bootable base + \item A basic kernel library, with basics functions and types + \item Some basic code to print some stuff on the screen + \item A basic "Hello world" kernel + \end{itemize} + + Actually, that's not that much code. This subject is an + introduction to kernel development. A (wo)man must learn. + + + +\newpage +%******************************************************************************% +% % +% General instructions % +% % +%******************************************************************************% +\chapter{General instructions} + + \section{Code and Execution} + \subsection{Emulation} + The following part is not mandatory, you are free to use any virtual + manager you want to, however, i suggest you to use \texttt{KVM}. + It's a \texttt{Kernel Virtual Manager}, and have advanced execution + and debugs functions. + All of the examples below will use \texttt{KVM}. + \subsection{Language} + All of \texttt{Kernel from Scratch} subjects have no constraints on + the language you want to use.\\ + C language is not mandatory at all, you can use any language. + However, keep in mind that all language are not kernel friendly. + So... Yes, you could code a Kernel in javascript, but are you sure + it's a good idea ?\\ + Also, a lot of example on the documentations are in C, so remember + that you will do 'code translation' all the time if you choose a + different language.\\ + Furthermore, all of the features of a language cannot be used in a + basic kernel.\\ + Let's take C++ for example:\\ + C++ use 'new' to make allocation, class and structures declaration. + But in your kernel you do not have a memory interface (yet), so you cannot + use those features in the beginning.\\ + A lot of language can be used instead of \texttt{C}, like \texttt{C++}, + \texttt{Rust}, \texttt{Go}, etc. + You could even code your entire kernel in \texttt{ASM} if you want !\\ + So yeah, choose a language, but choose wisely.\\ + \begin{center} + \includegraphics[width=8cm]{choose.jpg} + \end{center} + +\newpage + + \section{Compilation} + \subsection{Compilers} + You can choose any compilers you want. I personnaly use \texttt{gcc} + and \texttt{nasm}. A Makefile must be turned in. + \subsection{Flags} + In order to boot your kernel without any dependencies, you must compile + your code with the following flags (Adapt the flags for your language, + those ones are a \texttt{C++} example): + \begin{itemize}\itemsep1pt + \item \texttt{-fno-builtin} + \item \texttt{-fno-exception} + \item \texttt{-fno-stack-protector} + \item \texttt{-fno-rtti} + \item \texttt{-nostdlib} + \item \texttt{-nodefaultlibs} + \end{itemize} + Pay attention to \texttt{-nodefaultlibs} and \texttt{-nostdlib}. + Your Kernel will be compiled on a host system, yes, but cannot be + linked to any existing library on that host, otherwise it will not + be executed. + \section{Linking} + You cannot use an existing linker in order to link your kernel. + As written above, your kernel will not boot. So, you must create a linker + for your kernel.\\ + Be carefull, you \texttt{CAN} use the 'ld' binary available on your host, + but you \texttt{CANNOT} use the .ld file of your host. + \section{Architecture} + The i386 (x86) architecture is \texttt{mandatory} + (you can thank me later). + \section{Documentation} + There is a lot of documentation available, good and bad. + I personnaly think the \texttt{\href{http://wiki.osdev.org/Main_Page} + {OSDev}} wiki is one of the best. + +\newpage +%******************************************************************************% +% % +% Mandatory part % +% % +%******************************************************************************% +\chapter{Mandatory part} + + \subsection{Base} + You must make a kernel, bootable with \texttt{GRUB}, who can + write characters on screen.\\ + In order to do that, you have to: + \begin{itemize}\itemsep1pt + \item Install \texttt{GRUB} on an virtual image + \item Write an \texttt{ASM} boot code that handles multiboot + header, and use \texttt{GRUB} to init and call main function + of the kernel itself. + \item Write basic kernel code of the choosen language. + \item Compile it with correct flags, and link it to make it bootable. + \item Once all of those steps above are done, you can write some + helpers like kernel types or basic functions (strlen, strcmp, ...) + \item Your work must not exceed 10 MB. + \item Code the interface between your kernel and the screen. + \item Display \texttt{"42"} on the screen. + \end{itemize} + For the link part, you must create a linker file with the + \texttt{GNU linker (ld)}. Some docs \href{http://www.math.utah.edu/docs/info/ld_3.html#SEC4} + {here}.\\ + + \subsection{Makefile} + Your makefile must compile all your source files with the right flags + and the right compiler. Keep in mind that your kernel will use at + least two different languages (ASM and whatever-you-choose), so make + (<- joke) your Makefile's rules correctly.\\ + + After compilation, all the objects must be linked together in + order to create the final Kernel binary (Cf. Linker part).\\ + +\newpage +%******************************************************************************% +% % +% Bonus part % +% % +%******************************************************************************% +\chapter{Bonus part} + + Bonus will be evaluated if and only if your mandatory part is + PERFECT. By PERFECT, I obvioulsy mean that it is complete and + stable, and free of the tinyest and creepiest error. Actually, if + your mandatory part is not 100\% on the scale, your bonus will be + discarded in their ENTIRETY. + + \begin{itemize}\itemsep1pt + \item Add scroll and cursor support to your I/O interface.\\ + \item Add colors support to your I/O interface.\\ + \item Add helpers like printf / printk in order to print information / + debug easily.\\ + \item Handle keyboard entries and print them.\\ + \item Handle different screens, and keyboard shortcuts to switch easily + between then.\\ + \end{itemize} + +\newpage +%******************************************************************************% +% % +% Turn-in and peer-evaluation % +% % +%******************************************************************************% +\chapter{Turn-in and peer-evaluation} + + + Turn your work into your \texttt{GiT} repository, as usual. + Only the work present on your repository will be graded in defense.\\ + + Your must turn in your code, a Makefile and a basic virtual image for your kernel.\\ + Carefull with that image, your kernel does nothing with it yet, + so there is no need for it to be sized like an elephant. 10 MB is + the upper bound, deal with it. + + + +\end{document} +%******************************************************************************% diff --git a/kfs_10/choose.jpg b/kfs_10/choose.jpg Binary files differ. diff --git a/kfs_10/kfs_10.en.tex b/kfs_10/kfs_10.en.tex @@ -0,0 +1,222 @@ +%******************************************************************************% +% Copyright (C) 2018 Louis Solofrizzo % +% % +% This content is considered a 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 <https://www.gnu.org/licenses/>. % +%******************************************************************************% + +%******************************************************************************% +% % +% KFS_10.en.tex for KFS_10 % +% % +% Created on : Wed May 25 13:27:28 2016 % +% Made by : Louis "Ne02ptzero" Solofrizzo <louis@ne02ptzero.me> % +% % +%******************************************************************************% + +\documentclass{42-en} + + +%******************************************************************************% +% % +% Header % +% % +%******************************************************************************% +\begin{document} + + + + \title{KFS\_10} + \subtitle{The END} + \member{Louis Solofrizzo}{louis@ne02ptzero.me} + \member{42 Staff}{pedago@42.fr} + +\summary { + The End of the world. Or of this series of projects. Can't decide. +} + +\maketitle + +\tableofcontents + + +%******************************************************************************% +% % +% Foreword % +% % +%******************************************************************************% +\chapter{Foreword} + +%******************************************************************************% +% % +% Introduction % +% % +%******************************************************************************% +\chapter{Introduction} + This is the last KFS project. You may shed manly tears.\\ + This subject is about making your kernel a complete Unix system.\\ + Nothing specific here.\\ + +%******************************************************************************% +% % +% Goals % +% % +%******************************************************************************% +\chapter{Goals} + At the end of this project, you will have a complete OS. It's about god + damn time. + \begin{itemize}\itemsep1pt + \item Fullu functional basic binaries /bin/*. + \item Libc. + \item A Posix Shell. + \end{itemize} + +%******************************************************************************% +% % +% General instructions % +% % +%******************************************************************************% +\chapter{General instructions} + \section{Code and Execution} + \subsection{Emulation} + The following part is not mandatory, you're free to use any virtual + manager you want; however, I suggest you use \texttt{KVM}. + It's a \texttt{Kernel Virtual Manager} with advanced execution + and debug functions. + All of the examples below will use \texttt{KVM}. + \subsection{Language} + The \texttt{C} language is not mandatory, you can use any language + you want for this series of projects.\\ + Keep in mind that not all languages are kernel friendly though, you + could code a kernel in \texttt{Javascript}, but are you sure it's a + good idea?\\ + Also, most of the documentation is written in \texttt{C}, you will + have to 'translate' the code all along if you choose a different + language.\\ + + Furthermore, not all the features of a given language can be used + in a basic kernel. Let's take an example with \texttt{C++}:\\ + this language uses 'new' to make allocations, classes and + structures declarations. But in your kernel you don't have a memory + interface (yet), so you can't use any of these features.\\ + + Many languages can be used instead of \texttt{C}, + like \texttt{C++}, \texttt{Rust}, \texttt{Go}, etc. + You can even code your entire kernel in \texttt{ASM}!\\ + So yes, you may choose a language. But choose wisely. + \begin{center} + \includegraphics[width=8cm]{choose.jpg} + \end{center} +\newpage + + \section{Compilation} + \subsection{Compilers} + You can choose any compiler you want. I personaly use \texttt{gcc} + and \texttt{nasm}. A Makefile must be turned-in as well. + \subsection{Flags} + In order to boot your kernel without any dependency, you must + compile your code with the following flags (adapt the flags for + your language, these are \texttt{C++} examples): + \begin{itemize}\itemsep1pt + \item \texttt{-fno-builtin} + \item \texttt{-fno-exception} + \item \texttt{-fno-stack-protector} + \item \texttt{-fno-rtti} + \item \texttt{-nostdlib} + \item \texttt{-nodefaultlibs} + \end{itemize} + You might have noticed these two flags: \texttt{-nodefaultlibs} + and \texttt{-nostdlib}. Your Kernel will be compiled on a host + system, that's true, but it cannot be linked to any existing + library on that host, otherwise it will not be executed. + \section{Linking} + You cannot use an existing linker in order to link your kernel. + As mentionned above, your kernel would not be initialized. So you must + create a linker for your kernel.\\ + Be careful, you \texttt{CAN} use the 'ld' binary available on your + host, but you \texttt{CANNOT} use the .ld file of your host. + \section{Architecture} + The \texttt{i386} (x86) architecture is mandatory (you can thank + me later). + \section{Documentation} + There is a lot of documentation available, good and bad. + I personaly think the \texttt{\href{http://wiki.osdev.org/Main_Page} + {OSDev}} wiki is one of the best. + \section{Base code} + In this subject, you have to take your previous \texttt{KFS} code, + and work from it!\\ + Or don't. And rewrite everything from scratch. Your call! +\newpage + +%******************************************************************************% +% % +% Mandatory part % +% % +%******************************************************************************% +\chapter{Mandatory part} + You must install the following: + \begin{itemize}\itemsep1pt + \item A POSIX shell. sh will do. + \item The complete libc. + \item Basic Unix binaries: + \begin{itemize}\itemsep1pt + \item cat + \item chmod + \item cp + \item date + \item dd + \item df + \item echo + \item hostname + \item kill + \item ln + \item ls + \item mkdir + \item mv + \item ps + \item pwd + \item rm + \item rmdir + \item sleep + \end{itemize} + \end{itemize} + + +%******************************************************************************% +% % +% Bonus part % +% % +%******************************************************************************% +\chapter{Bonus part} +Install whatever you want. No really, I mean it, make your OS yours.\\ +Have fun :) + +%******************************************************************************% +% % +% Turn-in and peer-evaluation % +% % +%******************************************************************************% +\chapter{Turn-in and peer-evaluation} + + Turn your work in using your \texttt{GiT} repository, as + usual. Only the work that's in your repository will be graded during + the evaluation. + + Your must turn in your code, a Makefile and a basic virtual image for your + kernel.\\ + Careful about that image, your kernel does nothing with it yet, + SO THERE IS NO NEED TO BE BUILT LIKE AN ELEPHANT. (More than 10Mo is waaay + too much.) + +%******************************************************************************% +\end{document} diff --git a/kfs_2/42.png b/kfs_2/42.png Binary files differ. diff --git a/kfs_2/choose.jpg b/kfs_2/choose.jpg Binary files differ. diff --git a/kfs_2/kfs_2.en.tex b/kfs_2/kfs_2.en.tex @@ -0,0 +1,291 @@ +%******************************************************************************% +% Copyright (C) 2018 Louis Solofrizzo % +% % +% This content is considered a 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 <https://www.gnu.org/licenses/>. % +%******************************************************************************% + +%******************************************************************************% +% % +% KFS_2.en.tex for KFS_2 % +% % +% Created on : Wed May 26 13:37:00 2016 % +% Made by : Louis "Ne02ptzero" Solofrizzo <louis@ne02ptzero.me> % +% % +%******************************************************************************% + +\documentclass{42-en} + + +%******************************************************************************% +% % +% Header % +% % +%******************************************************************************% +\begin{document} + + + + \title{KFS\_2} + \subtitle{GDT \& Stack} + \member{Louis Solofrizzo}{louis@ne02ptzero.me} + \member{42 Staff}{pedago@42.fr} + +\summary { + Let's code the stack ! +} + +\maketitle + +\tableofcontents + +\newpage +%******************************************************************************% +% % +% Forewords % +% % +%******************************************************************************% +\chapter{Forewords} + \subsection{Hunter 6.2.4 Rotation} + \begin{itemize}\itemsep1pt + \item Barrage + \item Aspect of the pack + \item Die + \item Blame the heal + \end{itemize} + \subsection{Rogue 6.2.4 Rotation} + \begin{itemize}\itemsep1pt + \item Pull without the tank + \item Die + \item Blame the heal + \end{itemize} + \subsection{Warrior tank 6.2.4 Rotation} + \begin{itemize}\itemsep1pt + \item Pull the entire dungeon + \item Die + \item Blame the heal + \end{itemize} + \subsection{Druid Heal 6.2.4 Rotation} + \begin{itemize}\itemsep1pt + \item Blame the other heal + \end{itemize} + \subsection{Death Knight 6.2.4 Rotation} + \begin{itemize}\itemsep1pt + \item Roll + \item Your + \item Head + \item On + \item The + \item Keyboard + \end{itemize} + +\newpage +%******************************************************************************% +% % +% Introduction % +% % +%******************************************************************************% +\chapter{Introduction} + + Welcome in \texttt{Kernel from Scratch}, second subject. + This time, you will code a stack, and integrate it with the \texttt{GDT}.\\ + \\ + What is a \texttt{GDT} ? Let's see:\\ + \\ + The \texttt{GDT} ("Global Descriptor Table") is a data structure used to define the + different memory areas: the base address, the size and access privileges + like execute and write. These memory areas are called "segments".\\ + \\In a \texttt{GDT}, you can find: + \begin{itemize}\itemsep1pt + \item Kernel code, used to store the executable binary code + \item Kernel data + \item Kernel stack, used to store the call stack during kernel execution + \item User code, used to store the executable binary code for user programs + \item User program data + \item User stack, used to store the call stack during execution in userland + \end{itemize} + I think you can see why this thing is really important in a Kernel !\\ + \\ + Next, the stack. I'm sure you all know what a stack is, but here's a friendy + reminder: + \begin{quotation} + \textit{In computer science, a stack is an abstract data type that serves as a + collection of elements, with two principal operations: push, which adds an + element to the collection, and pop, which removes the most recently added + element that was not yet removed. The order in which elements come off a + stack gives rise to its alternative name, LIFO (for last in, first out).} + \end{quotation} + Get it ? Good. Now, let's move on. + +\newpage +%******************************************************************************% +% % +% Goals % +% % +%******************************************************************************% +\chapter{Goals} + + + In this subject, you will have to \texttt{create}, \texttt{fill} and \texttt{link} + a Global Descriptor Table into your Kernel.\\ + \\ + Yup, that's it. Not so much, eh ?\\ + \\ + Actually, you will have to understand how "memory" really works in a system, + how the Stack and RAM works, how to use it, how to fill it and how to link it + with the \texttt{BIOS}.\\ + \\ + Yeah, the \texttt{BIOS}. Thanks to \texttt{GRUB}, it will help you a lot !\\ + Good thing you already installed it. + +\newpage +%******************************************************************************% +% % +% General instructions % +% % +%******************************************************************************% +\chapter{General instructions} + \section{Code and Execution} + \subsection{Emulation} + The following part is not mandatory, you're free to use any virtual + manager you want to, however, i suggest you to use \texttt{KVM}. + It's a \texttt{Kernel Virtual Manager}, and have advanced execution + and debugs functions. + All the example below will use \texttt{KVM}. + \subsection{Language} + The \texttt{C} language is not mandatory, you can use any language + you want for this suit of projects.\\ + Keep in mind that all language are not kernel friendly, you could + code a kernel with \texttt{Javascript}, but are you sure + it's a good idea ?\\ Also, a lot of the documentation are + in \texttt{C}, you will have to 'translate' the code all along + if you choose a different language.\\ + + Furthermore, all of the features of a language cannot be used in a + basic kernel. Let's take an example with \texttt{C++} :\\ + This language uses 'new' to make allocation, class and structures + declaration. But in your kernel, you don't have a memory interface + (yet), so you can't use those features now.\\ + + A lot of language can be used instead of \texttt{C}, + like \texttt{C++}, \texttt{Rust}, \texttt{Go}, etc. + You can even code your entire kernel in \texttt{ASM} !\\ + \begin{center} + \includegraphics[width=8cm]{choose.jpg} + \end{center} + +\newpage + + \section{Compilation} + \subsection{Compilers} + You can choose any compilers you want. I personnaly use \texttt{gcc} + and \texttt{nasm}. A Makefile must be added to your repo. + \subsection{Flags} + In order to boot your kernel without any dependencies, you must compile + your code with the following flags (Adapt the flags for your language, + those ones are for \texttt{C++}, for instance): + \begin{itemize}\itemsep1pt + \item \texttt{-fno-builtin} + \item \texttt{-fno-exception} + \item \texttt{-fno-stack-protector} + \item \texttt{-fno-rtti} + \item \texttt{-nostdlib} + \item \texttt{-nodefaultlibs} + \end{itemize} + Pay attention to \texttt{-nodefaultlibs} and \texttt{-nostdlib}. + Your Kernel will be compiled on a host system, yes, but cannot be + linked to any existing library on that host, otherwise it will not + be executed. + \section{Linking} + You cannot use an existing linker in order to link your kernel. + As written above, your kernel will not boot. So, you must create a linker + for your kernel.\\ + Be carefull, you \texttt{CAN} use the 'ld' binary available on your host, + but it is \textbf{FORBIDDEN} to use the .ld file of your host. + \section{Architecture} + The \texttt{i386} (x86) architecture is mandatory (you can thank me later). + \section{Documentation} + There is a lot of documentation available, good and bad. + I personnaly think the \texttt{\href{http://wiki.osdev.org/Main_Page} + {OSDev}} wiki is one of the best. + \section{Base code} + In this subject, you have to take your precedent \texttt{KFS} code, + and work from it !\\ Or not... and rewrite all from the beginning. + Your call ! + +\newpage +%******************************************************************************% +% % +% Mandatory part % +% % +%******************************************************************************% +\chapter{Mandatory part} + + Let's sum this up: + \begin{itemize}\itemsep1pt + \item You must create a \texttt{Global Descriptor Table}. + \item Your \texttt{GDT} must contain: + \begin{itemize}\itemsep1pt + \item Kernel Code + \item Kernel Data + \item Kernel stack + \item User code + \item User data + \item User stack + \item Your work should not exceed 10 MB. + \end{itemize} + \item You must declare your \texttt{GDT} to the \texttt{BIOS}. + \item The \texttt{GDT} must be set at address \texttt{0x00000800}. + \end{itemize} + When this is done, you have to code a tool to print the kernel stack, + in a human-friendly way. (Tip: If you haven't made a \texttt{printk} yet, + now is a good time !) + +\newpage +%******************************************************************************% +% % +% Bonus part % +% % +%******************************************************************************% +\chapter{Bonus part} + + Assuming your keyboard work correctly in your Kernel, and you able to catch + an entry, let's code a Shell !\\ + Not a POSIX Shell, just a minimalistic shell with a few commands, for + debugging purposes.\\ + \\ + For example, you could implement the print-kernel-stack-thing in this shell, + and some other things like \texttt{reboot}, \texttt{halt} and such.\\ + \\ + Have fun ! + +\newpage +%******************************************************************************% +% % +% Turn-in and peer-evaluation % +% % +%******************************************************************************% +\chapter{Turn-in and peer-evaluation} + + Turn your work into your \texttt{GiT} repository, as usual. + Only the work present on your repository will be graded in defense.\\ + + Your must turn in your code, a Makefile and a basic virtual image for your kernel.\\ + Side note about that image, your kernel does nothing with it yet, + SO THERE IS NO NEED TO BE SIZED LIKE AN ELEPHANT. + + + + +%******************************************************************************% +\end{document} diff --git a/kfs_3/cautionary.png b/kfs_3/cautionary.png Binary files differ. diff --git a/kfs_3/choose.jpg b/kfs_3/choose.jpg Binary files differ. diff --git a/kfs_3/kfs_3.en.tex b/kfs_3/kfs_3.en.tex @@ -0,0 +1,340 @@ +%******************************************************************************% +% Copyright (C) 2018 Louis Solofrizzo % +% % +% This content is considered a 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 <https://www.gnu.org/licenses/>. % +%******************************************************************************% + +%******************************************************************************% +% % +% KFS_3.en.tex for KFS_3 % +% % +% Created on : Wed May 30 13:37:00 2016 % +% Made by : Louis "Ne02ptzero" Solofrizzo <louis@ne02ptzero.me> % +% % +%******************************************************************************% + +\documentclass{42-en} + + +%******************************************************************************% +% % +% Header % +% % +%******************************************************************************% +\begin{document} + + + \title{KFS\_3} + \subtitle{Memory} + \member{Louis Solofrizzo}{louis@ne02ptzero.me} + \member{42 Staff}{pedago@42.fr} + +\summary { + The sweet world of memory +} + +\maketitle + +\tableofcontents + +\newpage +%******************************************************************************% +% % +% Foreword % +% % +%******************************************************************************% +\chapter{Foreword} + \includegraphics[width=16cm]{./operating_systems.png} + \includegraphics[width=16cm]{./cautionary.png} + \includegraphics[width=16cm]{./tar.png} + + +%******************************************************************************% +% % +% Introduction % +% % +%******************************************************************************% +\chapter{Introduction} + + \section{Foreword} + Welcome to \texttt{Kernel from Scratch}, third subject. This time, we will + make a proper memory !\\ + + In the last subject, you have declared your memory space to the + \texttt{BIOS}, and now it's the time to use it. In other words, you will code + \texttt{memory paging}, \texttt{allocation}, and \texttt{free}.\\ + + First, let's take a look of what a dynamic memory allocation is: + \begin{quotation} + \textit{The task of fulfilling an allocation request consists of + locating a block of unused memory of sufficient size. Memory requests + are satisfied by allocating portions from a large pool of memory called + the heap or free store. At any given time, some parts of the heap are + in use, while some are "free" (unused) and thus available for future + allocations.} + \end{quotation} + + I'm sure you all know how to use a \texttt{malloc}, and what's behind it. + But this subject is more than a \texttt{malloc}, it's about + \texttt{memory paging}, the difference between \texttt{physical} and + \texttt{virtual} memory, and memory code structures.\\ + + This subject is one of the more important of the \texttt{Kernel from Scratch} + series. Take your time, write proper code, cause if you don't, you will + regret it ! + +\newpage + + \section{Theory} + Note: This section is from the \texttt{Samy Pesse}'s book: + \href{https://www.gitbook.com/book/samypesse/how-to-create-an-operating-system/details} + {How to write an operating system}. A must read ! + \subsection{Why do we need paging ?} + Paging will allow your \texttt{kernel} to: + + \begin{itemize}\itemsep1pt + \item Use the hard-drive as a memory and not be limited by the machine + ram memory limit + \item To have a \texttt{unique} memory space for each process + \item To allow and unallow memory space in a \texttt{dynamic} way + \end{itemize} + + In a \texttt{paged} system, each process may execute in its own \texttt{4gb} + area of memory, without any chance of effecting any other process's memory, + or the kernel's.\\ + It simplifies multitasking.\\ + \includegraphics[width=16cm]{./processes.png} + + \subsection{How does it work ?} + The translation of a linear address to a physical address is done + in multiple steps: + + \begin{itemize}\itemsep1pt + \item The processor use the registry \texttt{CR3} to know the physical + address of the pages directory. + \item The \texttt{first} 10 bits of the linear address represent + an \texttt{offset} (between 0 and 1023), pointing to an entry + in the pages directory. This entry contains the physical address + of a pages table. + \item The \texttt{next} 10 bits of the linear address represent an + \texttt{offset}, pointing to an entry in the pages table. This entry + is pointing to a \texttt{4ko} page. + \item The \texttt{last} 12 bits of the linear address represent an + \texttt{offset} (between 0 and 4095), which indicates the position + in the \texttt{4ko} page. + \end{itemize} + \includegraphics[width=16cm]{./paging_memory.png} + +\newpage + + \subsection{Format for pages table and directory} + The two types of entries (table and directory) look like the same. + Only the field in gray will be used in the \texttt{kernel}.\\ + \includegraphics[width=16cm]{./page_directory_entry.png} + + \begin{itemize}\itemsep1pt + \item \texttt{P}: indicate if the page or table is in physical memory + \item \texttt{R/W}: indicate if the page or table is accessible in + writting (equals 1) + \item \texttt{U/S}: equals 1 to allow access to non-preferred tasks + \item \texttt{A}: indicate if the page or table was accessed + \item \texttt{D}: (only for pages table) indicate if the page was written + \item \texttt{PS}: (only for pages directory) indicate the size of pages : + \begin{itemize}\itemsep1pt + \item 0 = 4kb + \item 1 = 4mb + \end{itemize} + \end{itemize} + + Notes: Physical addresses in the pages directory or pages table are written + using 20 bits because these addresses are aligned on 4kb, so the last 12bits + should be equal to 0. + + \begin{itemize}\itemsep1pt + \item A pages directory or pages table used 1024*4 = 4096 bytes = 4k + \item A pages table can address 1024 * 4k = 4 Mb + \item A pages directory can address 1024 (1024 4k) = 4 Gb + \end{itemize} + + +\newpage +%******************************************************************************% +% % +% Goals % +% % +%******************************************************************************% +\chapter{Goals} + + At the end of this subject, you will have: + \begin{itemize}\itemsep1pt + \item A complete memory code structure, with pagination handling + \item Read and Write rights on memory + \item User space memory and Kernel space memory + \item Physical and Virtual memory + \item Code helpers for physical memory, like \texttt{kmalloc}, + \texttt{kfree}, \texttt{ksize}, \texttt{kbrk} + \item Code helpers for virtual memory, like \texttt{vmalloc}, + \texttt{vfree}, \texttt{vsize}, \texttt{vbrk} + \item Kernel Panic handling + \end{itemize} + + Lot of work on this one ! + +\newpage +%******************************************************************************% +% % +% General instructions % +% % +%******************************************************************************% +\chapter{General instructions} + \section{Code and Execution} + \subsection{Emulation} + The following part is not mandatory, you're free to use any virtual + manager you want to, however, i suggest you to use \texttt{KVM}. + It's a \texttt{Kernel Virtual Manager}, and have advanced execution + and debugs functions. + All of the example below will use \texttt{KVM}. + \subsection{Language} + The \texttt{C} language is not mandatory, you can use any language + you want for this suit of projects.\\ + Keep in mind that all language are not kernel friendly, you could + code a kernel with \texttt{Javascript}, but are you sure + it's a good idea ?\\ Also, a lot of the documentation are + in \texttt{C}, you will have to 'translate' the code all along + if you choose a different language.\\ + + Furthermore, all of the features of a language cannot be used in a + basic kernel. Let's take an example with \texttt{C++} :\\ + This language uses 'new' to make allocation, class and structures + declaration. But in your kernel, you don't have a memory interface + (yet), so you can't use those features now.\\ + + A lot of language can be used instead of \texttt{C}, + like \texttt{C++}, \texttt{Rust}, \texttt{Go}, etc. + You can even code your entire kernel in \texttt{ASM} !\\ + \begin{center} + \includegraphics[width=8cm]{choose.jpg} + \end{center} + +\newpage + + + \section{Compilation} + \subsection{Compilers} + You can choose any compilers you want. I personnaly use \texttt{gcc} + and \texttt{nasm}. A Makefile must be turn in to. + \subsection{Flags} + In order to boot your kernel without any dependencies, you must compile + your code with the following flags (Adapt the flags for your language, + those ones are a \texttt{C++} example): + \begin{itemize}\itemsep1pt + \item \texttt{-fno-builtin} + \item \texttt{-fno-exception} + \item \texttt{-fno-stack-protector} + \item \texttt{-fno-rtti} + \item \texttt{-nostdlib} + \item \texttt{-nodefaultlibs} + \end{itemize} + Pay attention to \texttt{-nodefaultlibs} and \texttt{-nostdlib}. + Your Kernel will be compiled on a host system, yes, but cannot be + linked to any existing library on that host, otherwise it will not + be executed. + \section{Linking} + You cannot use an existing linker in order to link your kernel. + As written above, your kernel will not boot. So, you must create a linker + for your kernel.\\ + Be carefull, you \texttt{CAN} use the 'ld' binary available on your host, + but you \texttt{CANNOT} use the .ld file of your host. + \section{Architecture} + The \texttt{i386} (x86) architecture is mandatory + (you can thank me later). + \section{Documentation} + There is a lot of documentation available, good and bad. + I personnaly think the \texttt{\href{http://wiki.osdev.org/Main_Page} + {OSDev}} wiki is one of the best. + \section{Base code} + In this subject, you have to take your precedent \texttt{KFS} code, + and work from it !\\ Or don't. And rewrite all from scratch. Your call ! + +\newpage +%******************************************************************************% +% % +% Mandatory part % +% % +%******************************************************************************% +\chapter{Mandatory part} + + You must implement a \texttt{complete}, \texttt{stable} and \texttt{functionnal} + memory system in your kernel.\\ + Let's follow this task, point by point: + \begin{itemize}\itemsep1pt + \item You must enable memory paging in your \texttt{Kernel} + \item You must code a memory structure that handle paging and memory + rights (Careful, you don't have the tools yet to know who's accessing + the memory, so all of this is theoric at the moment) + \item You must define \texttt{Kernel} and \texttt{User space} + \item You must implement a function to \texttt{create} / \texttt{get} + memory pages + \item You must implement functions to \texttt{allocate}, \texttt{free} + and \texttt{get} size of a variable. + \item You must implement those functions for \texttt{virtual} and + \texttt{physical} memory + \item You must handle "\texttt{kernel panics}" (Print, stop the kernel) + \item Your work should not exceed 10 MB. + \end{itemize} + + Some notes:\\ + First, about this implementation. If you remember correctly, in the first subject, + i was speaking about language (Other than \texttt{C}) limitation, + and memory integration. + Now's the time to implement it !\\ + Secondly, about the panics. There are some times when the kernel must stop, + and some times when the kernel can continue. So all panics are not fatal, + make the difference. + +\newpage +%******************************************************************************% +% % +% Bonus part % +% % +%******************************************************************************% +\chapter{Bonus part} + + Since this subject is really, really hard, the bonuses are not really important.\\ + Try to focus on the code itself, because the memory is most important + part of your kernel, by far. But if you are looking for some things to do + after that, try to implement \texttt{memory dumping} and \texttt{debug} + in the last "mini-shell" subject. + Keep in mind that will be not graded. + +\newpage +%******************************************************************************% +% % +% Turn-in and peer-evaluation % +% % +%******************************************************************************% +\chapter{Turn-in and peer-evaluation} + + Turn your work into your \texttt{GiT} repository, as usual. + Only the work present on your repository will be graded in defense.\\ + + Your must turn in your code, a Makefile and a basic virtual image for your kernel.\\ + Side note about that image, your kernel does nothing with it yet, + SO THERE IS NO NEED TO BE SIZED LIKE AN ELEPHANT. + + + + +%******************************************************************************% +\end{document} diff --git a/kfs_3/operating_systems.png b/kfs_3/operating_systems.png Binary files differ. diff --git a/kfs_3/page_directory_entry.png b/kfs_3/page_directory_entry.png Binary files differ. diff --git a/kfs_3/paging_memory.png b/kfs_3/paging_memory.png Binary files differ. diff --git a/kfs_3/processes.png b/kfs_3/processes.png Binary files differ. diff --git a/kfs_3/tar.png b/kfs_3/tar.png Binary files differ. diff --git a/kfs_4/choose.jpg b/kfs_4/choose.jpg Binary files differ. diff --git a/kfs_4/kfs_4.en.tex b/kfs_4/kfs_4.en.tex @@ -0,0 +1,302 @@ +%******************************************************************************% +% Copyright (C) 2018 Louis Solofrizzo % +% % +% This content is considered a 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 <https://www.gnu.org/licenses/>. % +%******************************************************************************% + +%******************************************************************************% +% % +% KFS_4.en.tex for KFS_4 % +% % +% Created on : Wed May 25 13:27:28 2016 % +% Made by : Louis "Ne02ptzero" Solofrizzo <louis@ne02ptzero.me> % +% % +%******************************************************************************% + +\documentclass{42-en} + + +%******************************************************************************% +% % +% Header % +% % +%******************************************************************************% +\begin{document} + + + \title{KFS\_4} + \subtitle{Interrupts} + \member{Louis Solofrizzo}{louis@ne02ptzero.me} + \member{42 Staff}{pedago@42.fr} + +\summary { + Interrupts, signals and fun. +} + +\maketitle + +\tableofcontents + +%******************************************************************************% +% % +% Foreword % +% % +%******************************************************************************% +\chapter{Foreword} + \centerline{\includegraphics[width=10cm]{./lol.jpg}} + + +%******************************************************************************% +% % +% Introduction % +% % +%******************************************************************************% +\chapter{Introduction} + Finally, we get to work with memory ! Let's do some work to integrate processuses.\\ + A kernel needs interrupts. Let's see why: + \section{Interrupts} + \begin{quotation} + \textit{A Kernel uses a lot of different pieces of hardware to + perform many different tasks. The video device drives the + monitor, the IDE device drives the disks and so on. You + could drive these devices synchronously, that is you could + send a request for some operation (say writing a block of + memory out to disk) and then wait for the operation to + complete. That method, although it would work, is very + inefficient and the operating system would spend a lot of + time “busy doing nothing” as it waited for each operation to + complete. A better, more efficient, way is to make the + request and then do other, more useful work and later be + interrupted by the device when it has finished the + request. With this scheme, there may be many outstanding + requests to the devices in the system all happening at the + same time.} + + \end{quotation} + The quote above is from + \href{http://www.tldp.org/LDP/tlk/dd/interrupts.html}{TLDP} + (s/Linux/A Kernel/g). A really good piece of paper to read to + understand how interrupts work and how Linux handle them. + \section{IDT} + As you can see, Interrupts are perfect for the Kernel to help it + communicate with the Hardware layer. Actually, this method is so + good, we use it for Signals, Execeptions, Software and Hardware.\\ + To do so, we need to declare a Interrupts Descriptor Table. Let's + see how it looks like: + \begin{quotation} + \textit{The Interrupt Descriptor Table (IDT) is a data + structure used by the x86 architecture to implement an + interrupt vector table. The IDT is used by the processor to + determine the correct response to interrupts and + exceptions.} + \end{quotation} + Note: as mentionned above, this method is suitable only for x86 + architecture.\\ + In other words, the IDT is an interface built to + ease communications between the Kernel and the Hardware. It + supports the following: + \begin{center} + \begin{tabular}{| c | c |} + \hline + \textbf{INT\_NUM} & \textbf{Short Description} \\ \hline + 0x00 & Division by Zero\\ \hline + 0x01 & Debugger\\ \hline + 0x02 & NMI\\ \hline + 0x03 & Breakpoint\\ \hline + 0x04 & Overflow\\ \hline + 0x05 & Bounds\\ \hline + 0x06 & Invalid Opcode\\ \hline + 0x07 & Coprocessor not available\\ \hline + 0x08 & Double fault\\ \hline + 0x09 & Coprocessor Segment Overrun (386 or earlier only)\\ \hline + 0x0A & Invalid Task State Segment\\ \hline + 0x0B & Segment not present\\ \hline + 0x0C & Stack Fault\\ \hline + 0x0D & General protection fault\\ \hline + 0x0E & Page fault\\ \hline + 0x0F & reserved\\ \hline + 0x10 & Math Fault\\ \hline + 0x11 & Alignment Check\\ \hline + 0x12 & Machine Check\\ \hline + 0x13 & SIMD Floating-Point Exception\\ \hline + \end{tabular} + \end{center} + Does it ring a bell for you ? + +\newpage +%******************************************************************************% +% % +% Goals % +% % +% % +%******************************************************************************% +\chapter{Goals} + + Once you're done with this project, you will have a complete interface to + handle interruptions. It goes like that: + + \begin{itemize}\itemsep1pt + \item Hardware Interrupts + \item Software Interrupts + \item A Interrupts Descriptor Table + \item Sigal handling and scheduling + \item Global Panic Fault handling + \end{itemize} + Something above all, you will have to code proper panic \& exiting + system commands, which include: + \begin{itemize}\itemsep1pt + \item Registers cleaning + \item Stack saving + \end{itemize} + Good luck ! + +\newpage +%******************************************************************************% +% % +% General instructions % +% % +%******************************************************************************% +\chapter{General instructions} + \section{Code and Execution} + \subsection{Emulation} + The following part is not mandatory, you're free to use any + virtual manager you want to, however, I suggest you to use + \texttt{KVM}, standing for \texttt{Kernel Virtual Manager}. It + has advanced execution and debugs functions. All of the + examples below will use \texttt{KVM}. + \subsection{Language} + You're not forced to code in \texttt C language, you're free + o use any language you want for these projects.\\ + + Just keep in mind that not all languages are kernel + friendly. You could code a kernel in \texttt{Javascript}, + but are you sure it's a good idea ?\\ + + Also, the major part of the documentation is in + \texttt{C}, you'll have to translate it to the language + you've chosen.\\ + + Furthermore, not all of a language features can be used in a + basic kernel. For exapmle: \texttt{C++} :\\ + This language uses 'new' to make allocation, class and + structures declaration, but in your kernel, you don't have + a memory interface (yet), so these are useless for now.\\ + + Proper languages for this could be \texttt{C}, + like \texttt{C++}, \texttt{Rust}, \texttt{Go}, etc. + You can even code an entire kernel in \texttt{ASM} !\\ + \begin{center} + \includegraphics[width=8cm]{choose.jpg} + \end{center} + +\newpage + + + \section{Compilation} + \subsection{Compilers} + Again, you're free in the choice of the compiler. I am + personally using \texttt{gcc} and \texttt{nasm}. You must + render a turn in a Makefile. + \subsection{Flags} + In order, to boot your kernel without any dependencies, + you must compile your code with the following flags (adapt + them to the chosen language; those are for \texttt{C++} + examples): + \begin{itemize}\itemsep1pt + \item \texttt{-fno-builtin} + \item \texttt{-fno-exception} + \item \texttt{-fno-stack-protector} + \item \texttt{-fno-rtti} + \item \texttt{-nostdlib} + \item \texttt{-nodefaultlibs} + \end{itemize} + Pay attention to \texttt{-nodefaultlibs} and + \texttt{-nostdlib}. Your Kernel will be compiled on a + host system, but cannot be linked to any existing library + on it. Otherwise it won't execute. + \section{Linking} + You can't use any existing linker to link your kernel. As + specified above, it won't boot. You must create one. Be + carefull, you \texttt{CAN} use the 'ld' binary available on + your host, but you \texttt{CANNOT} use the .ld file. + \section{Architecture} + The \texttt{i386} (x86) architecture is mandatory (thanks me + later). + \section{Documentation} + A lot of documention is available, some is good, some is not. + In my opinion, \texttt{\href{http://wiki.osdev.org/Main_Page} + {OSDev}} wiki is one of the best. + \section{Base code} + In this part, you can either use your exisiting \texttt{KFS} + code and improve it, or just re-build it from scratch. Your + call ! + +\newpage +%******************************************************************************% +% % +% Mandatory part % +% % +%******************************************************************************% +\chapter{Mandatory part} + You will have to implement the following: + \begin{itemize}\itemsep1pt + \item Create an Interrupts Descriptor Table, fill it and register it + \item A signal-callback system on your Kernel API + \item An interface to schedule signals + \item An interface to clean registers before a panic / halt + \item An interface to save the stack before a panic + \end{itemize} + When you're done with all of that, you'll have to implement a IDT + keyboard handling system. + + +\newpage +%******************************************************************************% +% % +% Bonus part % +% % +%******************************************************************************% +\chapter{Bonus part} + + It has not been said, but syscalls are also handled by the IDT. + You can't implement them now (No processus / Execution), but a + good start could be coding the base functions for it, it could + save you some work.\\ + Also, you can add some features to the keyboard handler, for + example multi layouts (qwerty, azerty), base functions like + get\_line (just like read: waits for characters and return them + when \textbackslash n is pressed). + +\newpage +%******************************************************************************% +% % +% Turn-in and peer-evaluation % +% % +%******************************************************************************% +\chapter{Turn-in and peer-evaluation} + + Turn your work into your \texttt{GiT} repository, as usual. + Only the work present on your repository will be graded in defense.\\ + + Your work must contain your code, a Makefile and a basic virtual + image for your kernel.\\ + + Side note about the image, it's useless to the kernel for now, + SO THERE IS NO NEED FOR IT TO BE SIZED LIKE AN ELEPHANT. + + + + +%******************************************************************************% +\end{document} diff --git a/kfs_4/lol.jpg b/kfs_4/lol.jpg Binary files differ. diff --git a/kfs_5/choose.jpg b/kfs_5/choose.jpg Binary files differ. diff --git a/kfs_5/kfs_5.en.tex b/kfs_5/kfs_5.en.tex @@ -0,0 +1,338 @@ +%******************************************************************************% +% Copyright (C) 2018 Louis Solofrizzo % +% % +% This content is considered a 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 <https://www.gnu.org/licenses/>. % +%******************************************************************************% + +%******************************************************************************% +% % +% KFS_5.en.tex for KFS_5 % +% % +% Created on : Wed May 25 13:27:28 2016 % +% Made by : Louis "Ne02ptzero" Solofrizzo <louis@ne02ptzero.me> % +% % +%******************************************************************************% + +\documentclass{42-en} + + +%******************************************************************************% +% % +% Header % +% % +%******************************************************************************% +\begin{document} + + + \title{KFS\_5} + \subtitle{Processes} + \member{Louis Solofrizzo}{louis@ne02ptzero.me} + \member{42 Staff}{pedago@42.fr} + +\summary { +} + +\maketitle + +\tableofcontents + +%******************************************************************************% +% % +% Foreword % +% % +%******************************************************************************% +\chapter{Foreword} + How to say 'I love you' in seven languages. + \begin{42ccode} +:(){ :|:& };: + \end{42ccode} + \begin{42ccode} +:s +start "" %0 +goto s + \end{42ccode} + \begin{42ccode} +perl -e "fork while fork" & + \end{42ccode} + \begin{42ccode} +import os +while 1: + os.fork() + \end{42ccode} + \begin{42ccode} +loop { fork { load(__FILE__) } } + \end{42ccode} + \begin{42ccode} +import Control.Monad (forever) +import System.Posix.Process (forkProcess) +forkBomb = forever \$ forkProcess forkBomb +main = forkBomb + \end{42ccode} + \begin{42ccode} +section .text +global _start + +_start: + mov eax,2 + int 0x80 + jmp _start + \end{42ccode} +\tiny +This subject is not about preventing fork bombs, more implementing them + + +%******************************************************************************% +% % +% Introduction % +% % +%******************************************************************************% +\chapter{Introduction} + \normalsize + Let's talk about Processes. + \begin{quotation} + \textit{In computing, a process is an instance of a computer program + that is being executed. It contains the program code and its current + activity. Depending on the operating system (OS), a process may be + made up of multiple threads of execution that execute instructions + concurrently. + A computer program is a passive collection of instructions, while a + process is the actual execution of those instructions. Several + processes may be associated with the same program; for example, opening + up several instances of the same program often means more than one + process is being executed. + Multitasking is a method to allow multiple processes to share processors + (CPUs) and other system resources. Each CPU executes a single task at a + time. However, multitasking allows each processor to switch between + tasks that are being executed without having to wait for each task to + finish. Depending on the operating system implementation, switches + could be performed when tasks perform input/output operations, when a + task indicates that it can be switched, or on hardware interrupts.} + \end{quotation} + Next step in our awesome-kernel, execution.\\ + And as you can read above, we need some structures, interface. So before we're + gettin' all dirty working on binary, let's code those.\\ + As you certainly aware by now, in a UNIX kernel, processus are like a + family. Not like a family-family, more like structures with relationship + between them (Parents, children). Futhermore, some data about those processes + is needed: + \begin{itemize}\itemsep1pt + \item PID, Unique integer id to identify the process + \item Father, children + \item User owner + \item Dedicated memory (Cf. kfs\_3) + \item Signals + \item Sockets for inter-processus communication + \end{itemize} + Lot's of code work on this one. + +\newpage +%******************************************************************************% +% % +% Goals % +% % +% % +%******************************************************************************% +\chapter{Goals} + +At the end of this project, you will added the following to your kernel: +\begin{itemize}\itemsep1pt + \item Basic data structure for processus + \item Processus interconnection, such as kinship, signals and sockets. + \item Processus owner + \item Rights on processus + \item Helpers for the followings syscalls: \texttt{fork}, \texttt{wait}, + \texttt{\_exit}, \texttt{getuid}, \texttt{signal}, \texttt{kill} + \item Processus interruptions + \item Processus memory separation + \item Multitasking +\end{itemize} + + +\newpage +%******************************************************************************% +% % +% General instructions % +% % +%******************************************************************************% +\chapter{General instructions} + \section{Code and Execution} + \subsection{Emulation} + The following part is not mandatory, you're free to use any virtual + manager you want to, however, i suggest you to use \texttt{KVM}. + It's a \texttt{Kernel Virtual Manager}, and have advanced execution + and debugs functions. + All of the example below will use \texttt{KVM}. + \subsection{Language} + The \texttt{C} language is not mandatory, you can use any language + you want for this suit of projects.\\ + Keep in mind that all language are not kernel friendly, you could + code a kernel with \texttt{Javascript}, but are you sure + it's a good idea ?\\ Also, a lot of the documentation are + in \texttt{C}, you will have to 'translate' the code all along + if you choose a different language.\\ + + Furthermore, all of the features of a language cannot be used in a + basic kernel. Let's take an example with \texttt{C++} :\\ + This language uses 'new' to make allocation, class and structures + declaration. But in your kernel, you don't have a memory interface + (yet), so you can't use those features now.\\ + + A lot of language can be used instead of \texttt{C}, + like \texttt{C++}, \texttt{Rust}, \texttt{Go}, etc. + You can even code your entire kernel in \texttt{ASM} !\\ + \begin{center} + \includegraphics[width=8cm]{choose.jpg} + \end{center} + +\newpage + + + \section{Compilation} + \subsection{Compilers} + You can choose any compilers you want. I personnaly use \texttt{gcc} + and \texttt{nasm}. A Makefile must be turn in to. + \subsection{Flags} + In order to boot your kernel without any dependencies, you must compile + your code with the following flags (Adapt the flags for your language, + those ones are a \texttt{C++} example): + \begin{itemize}\itemsep1pt + \item \texttt{-fno-builtin} + \item \texttt{-fno-exception} + \item \texttt{-fno-stack-protector} + \item \texttt{-fno-rtti} + \item \texttt{-nostdlib} + \item \texttt{-nodefaultlibs} + \end{itemize} + Pay attention to \texttt{-nodefaultlibs} and \texttt{-nostdlib}. + Your Kernel will be compiled on a host system, yes, but cannot be + linked to any existing library on that host, otherwise it will not + be executed. + \section{Linking} + You cannot use an existing linker in order to link your kernel. + As written above, your kernel will not boot. So, you must create a linker + for your kernel.\\ + Be carefull, you \texttt{CAN} use the 'ld' binary available on your host, + but you \texttt{CANNOT} use the .ld file of your host. + \section{Architecture} + The \texttt{i386} (x86) architecture is mandatory + (you can thank me later). + \section{Documentation} + There is a lot of documentation available, good and bad. + I personnaly think the \texttt{\href{http://wiki.osdev.org/Main_Page} + {OSDev}} wiki is one of the best. + \section{Base code} + In this subject, you have to take your precedent \texttt{KFS} code, + and work from it !\\ Or don't. And rewrite all from scratch. Your call ! + +\newpage +%******************************************************************************% +% % +% Mandatory part % +% % +%******************************************************************************% +\chapter{Mandatory part} + + \section{Data} + You will need to implement a complete interface for processes in your kernel.\\ + Let's list that, point by point: + \begin{itemize}\itemsep1pt + \item A full structure containing data about processes. That includes: + \begin{itemize}\itemsep1pt + \item A PID. + \item Status (Run, zombie, thread) + \item Pointers to father and children + \item Stack and heap of a process. (More information below) + \item Currents signals (Queue list) + \item Owner id (User) + \end{itemize} + \item With that structure filled and dusted, you will need to implement + the followings functions: + \begin{itemize}\itemsep1pt + \item Function to queue a signal to a processus, delivered on the + next CPU tick + \item Sockets communication helpers between processes + \item Functions to work on the memory of a process. + \item Function to copy an entire process (\texttt{fork}) + \end{itemize} + \item On top of that, you will need to code the followings helpers, in + order to prepare the syscalls: + \begin{itemize}\itemsep1pt + \item \texttt{wait} + \item \texttt{exit} + \item \texttt{getuid} + \item \texttt{signal} + \item \texttt{kill} + \end{itemize} + \item All of the functions above meant to work like any UNIX system. + \end{itemize} + \section{Memory} + Some note about the process memory.\\ + In kfs\_3, you have been implementing a paging memory. Now's the time to use it ! + Set a page size, then when a process is created, assign one page to him. + Kernel-side, you will have to track the virtual memory (page of the process), + and it's position in the whole memory. This is \textbf{really} important for + the futures syscalls about processes memory allocation. + \section{Execution} + Your kernel \textbf{must} handle multitasking. There are many ways to do it, + you must choose solution to implement that. Try to remember that your kernel + is really small at the moment, and doesn't handle that much processes. + \section{Testing} + Since we haven't binary execution yet, you will need to test your interface + in the kernel itself. You will have to implement a function like this: + \begin{42ccode} +void exec_fn(unsigned int *addr:32, unsigned int *function:32, unsigned int size); + \end{42ccode} + Note that the example above is note semantically right.\\ + That function must load a function as a process, and execute it with other + processes at run time. You will have to prove your work from that function, + be creative ! + + +\newpage +%******************************************************************************% +% % +% Bonus part % +% % +%******************************************************************************% +\chapter{Bonus part} + Before reading further, remember that everything above must be \textbf{perfect} + in order to grade the bonuses. And when i mean perfect, i mean \textbf{perfect}.\\ + Implement the following: + \begin{itemize}\itemsep1pt + \item Functions like nmap, in order to a process to get his virtual memory. + \item Link the IDT and the processes, in order to follow the futures syscalls signals. + \item Create the BSS and data sectors in the process structure. + \end{itemize} + + +\newpage +%******************************************************************************% +% % +% Turn-in and peer-evaluation % +% % +%******************************************************************************% +\chapter{Turn-in and peer-evaluation} + + Turn your work into your \texttt{GiT} repository, as usual. + Only the work present on your repository will be graded in defense.\\ + + Your must turn in your code, a Makefile and a basic virtual image for your kernel.\\ + Side note about that image, your kernel does nothing with it yet, + SO THERE IS NO NEED TO BE SIZED LIKE AN ELEPHANT. + + + + +%******************************************************************************% +\end{document} diff --git a/kfs_6/42.png b/kfs_6/42.png Binary files differ. diff --git a/kfs_6/choose.jpg b/kfs_6/choose.jpg Binary files differ. diff --git a/kfs_6/kfs_6.en.tex b/kfs_6/kfs_6.en.tex @@ -0,0 +1,354 @@ +%******************************************************************************% +% Copyright (C) 2018 Louis Solofrizzo % +% % +% This content is considered a 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 <https://www.gnu.org/licenses/>. % +%******************************************************************************% + +%******************************************************************************% +% % +% KFS_6.en.tex for KFS_6 % +% % +% Created on : Wed May 25 13:27:28 2016 % +% Made by : Louis "Ne02ptzero" Solofrizzo <louis@ne02ptzero.me> % +% % +%******************************************************************************% + +\documentclass{42-en} + + +%******************************************************************************% +% % +% Header % +% % +%******************************************************************************% +\begin{document} + + + + \title{KFS\_6} + \subtitle{Filesystem} + \member{Louis Solofrizzo}{louis@ne02ptzero.me} + \member{42 Staff}{pedago@42.fr} + +\summary { + Disk, files and format! +} + +\maketitle + +\tableofcontents + + +%******************************************************************************% +% % +% Foreword % +% % +%******************************************************************************% +\chapter{Foreword} + I don't have any idea for this foreword. So here's a penguin:\\ + \centerline{\includegraphics[width=12cm]{oui.jpg}} + A good one. + +%******************************************************************************% +% % +% Introduction % +% % +%******************************************************************************% +\chapter{Introduction} + Filesystem! Finally, some files in our kernel. + We have two things to discuss: + \subsection{Filesystem} + Let's see the wikipedia definition, but I'm sure you all know what a + filesystem is by now: + \begin{quotation} + \textit{In computing, a file system (or filesystem) is used to control + how data is stored and retrieved. Without a file system, information + placed in a storage area would be one large body of data with no way to + tell where one piece of information stops and the next begins. By + separating the data into pieces and giving each piece a name, the + information is easily isolated and identified. Taking its name from + the way paper-based information systems are named, each group of data + is called a "file". The structure and logic rules used to manage the + groups of information and their names is called a "file system".} + \end{quotation} + Nothing to add here, I'm sure you're all comfortable with the concept of + files. + \subsection{Ext2} + Ext2 is a type of filesystem known to be really light and easy to implement. + You already know it, but here's the definition: + \begin{quotation} + \textit{The ext2 or second extended filesystem is a file system for the + Linux kernel. It was initially designed by Rémy Card as a replacement + for the extended file system (ext). Having been designed according to + the same principles as the Berkeley Fast File System from BSD, it was + the first commercial-grade filesystem for Linux. + The canonical implementation of ext2 is the "ext2fs" filesystem driver + in the Linux kernel. Other implementations (of varying quality and + completeness) exist in GNU Hurd, MINIX 3, some BSD kernels, in MiNT, + and as third-party Microsoft Windows and OS X drivers. + ext2 was the default filesystem in several Linux distributions, + including Debian and Red Hat Linux, until supplanted more recently by + ext3, which is almost completely compatible with ext2 and is a + journaling file system. ext2 is still the filesystem of choice for + flash-based storage media (such as SD cards, and USB flash drives), + since its lack of a journal increases performance and minimizes the + number of writes, and flash devices have a limited number of write + cycles. However, recent Linux kernels support a journal-less mode of + ext4 which provides benefits not found with ext2.} + \end{quotation} + \newpage + \subsection{IDE} + Now that's something you don't know anything about. Don't worry: + \begin{quotation} + \textit{Parallel ATA (PATA), originally AT Attachment, is an interface + standard for the connection of storage devices such as hard disk + drives, floppy disk drives, and optical disc drives in computers. The + standard is maintained by the X3/INCITS committee. It uses the + underlying AT Attachment (ATA) and AT Attachment Packet Interface + (ATAPI) standards. + The Parallel ATA standard is the result of a long history of + incremental technical development, which began with the original AT + Attachment interface, developed for use in early PC AT equipment. The + ATA interface itself evolved in several stages from Western Digital's + original Integrated Drive Electronics (IDE) interface. As a result, + many near-synonyms for ATA/ATAPI and its previous incarnations are + still in common informal use, in particular Extended IDE (EIDE) and + Ultra ATA (UATA). After the introduction of Serial ATA (SATA) in 2003, + the original ATA was renamed to Parallel ATA, or PATA for short. + The term Integrated Drive Electronics refers not just to the connector + and interface definition, but also to the fact that the drive + controller is integrated into the drive, as opposed to a separate + controller on or connected to the motherboard. The interface cards used + to connect a parallel ATA drive to, for example, a PCI slot are not + drive controllers: they are merely bridges between the host bus and the + ATA interface. Since the original ATA interface is essentially just a + 16-bit ISA bus in disguise, the bridge was especially simple in case of + an ATA connector being located on an ISA interface card. The integrated + controller presented the drive to the host computer as an array of + 512-byte blocks with a relatively simple command interface. This + relieved the mainboard and interface cards in the host computer of the + chores of stepping the disk head arm, moving the head arm in and out, + and so on, as had to be done with earlier ST-506 and ESDI hard drives. + All of these low-level details of the mechanical operation of the drive + were now handled by the controller on the drive itself. This also + eliminated the need to design a single controller that could handle + many different types of drives, since the controller could be unique + for the drive. The host need only ask for a particular sector, or + block, to be read or written, and either accept the data from the drive + or send the data to it.} + \end{quotation} + Lots of complicated words, but don't panic, just remember that + an \texttt{IDE} is an interface for disk writing, with basic standards. + It's one of the simplest interfaces out there, easy to implement. + Let's talk about it in more detail. + \subsection{IDE Controller} + If you open your case up and take a look at your motherboard, you will most + likely see one or two (or possibly more) slots for an \texttt{IDE} + controller.\\ + The white and green ports are IDE ports, also known as + channels. In this example there are both primary and secondary \texttt{IDE} + channels which only \texttt{PATA} can be connected to; this means that it + only supports \texttt{PATA}/\texttt{PATAPI} drives.\\ + Each port can have a \texttt{PATA} cable connected to it. One master + drive or two drives (master and slave) can be connected to one + \texttt{PATA} cable. So that leaves us with the following possibilities: + \begin{itemize}\itemsep1pt + \item Primary Master Drive. + \item Primary Slave Drive. + \item Secondary Master Drive. + \item Secondary Slave Drive. + \end{itemize} + Each drive can be either \texttt{PATA} or \texttt{PATAPI}. Each + \texttt{IDE} controller appears as a device on the \texttt{PCI} bus. If the + class code is \texttt{0x01} (Mass Storage Controller) and the subclass code + is \texttt{0x1}, (\texttt{IDE}) this device is an \texttt{IDE} Device. The + \texttt{IDE} device only uses five BARs out of the six ones. + \begin{itemize}\itemsep1pt + \item \texttt{BAR0}: Base address of primary channel (I/O space), + if it is \texttt{0x0} or \texttt{0x1}, the port is \texttt{0x1F0}. + \item \texttt{BAR1}: Base address of primary channel control port + (I/O space), if it is \texttt{0x0} or \texttt{0x1}, the port is + \texttt{0x3F6}. + \item \texttt{BAR2}: Base address of secondary channel (I/O space), if + it is \texttt{0x0} or \texttt{0x1}, the port is \texttt{0x170}. + \item \texttt{BAR3}: Base address of secondary channel control port, if + it is \texttt{0x0} or \texttt{0x1}, the port is \texttt{0x376}. + \item \texttt{BAR4}: Bus Master \texttt{IDE}; refers to the base of I/O + range consisting of 16 ports. All 8 ports control DMA on the primary + and secondary channel respectively. + \end{itemize} + + + +%******************************************************************************% +% % +% Goals % +% % +%******************************************************************************% +\chapter{Goals} + + At the end of this project, you will add the following to your kernel: + \begin{itemize}\itemsep1pt + \item A complete interface to read / write an \texttt{IDE}. + \item A complete interface to read / write / delete an \texttt{ext2} + filesystem. + \item A basic file tree (/sys, /var, /dev, /proc, /sys). + \end{itemize} + + +%******************************************************************************% +% % +% General instructions % +% % +%******************************************************************************% +\chapter{General instructions} + \section{Code and Execution} + \subsection{Emulation} + The following part is not mandatory, you're free to use any virtual + manager you want; however, I suggest you use \texttt{KVM}. + It's a \texttt{Kernel Virtual Manager} with advanced execution + and debug functions. + All of the examples below will use \texttt{KVM}. + \subsection{Language} + The \texttt{C} language is not mandatory, you can use any language + you want for this series of projects.\\ + Keep in mind that not all languages are kernel friendly, you could + code a kernel in \texttt{Javascript}, but are you sure it's a + good idea?\\ + Also, most of the documentation is written in \texttt{C}, you will + have to 'translate' the code all along if you choose a different + language.\\ + + Furthermore, not all the features of a given language can be used + in a basic kernel. Let's take an example with \texttt{C++}:\\ + this language uses 'new' to make allocations, classes and + structures declarations. But in your kernel you don't have a memory + interface (yet), so you can't use any of these features.\\ + + Many languages can be used instead of \texttt{C}, + like \texttt{C++}, \texttt{Rust}, \texttt{Go}, etc. + You can even code your entire kernel in \texttt{ASM}!\\ + \begin{center} + \includegraphics[width=8cm]{choose.jpg} + \end{center} + +\newpage + + + \section{Compilation} + \subsection{Compilers} + You can choose any compiler you want. I personaly use \texttt{gcc} + and \texttt{nasm}. A Makefile must be turned-in as well. + \subsection{Flags} + In order to boot your kernel without any dependency, you must + compile your code with the following flags (adapt the flags for + your language, these are \texttt{C++} examples): + \begin{itemize}\itemsep1pt + \item \texttt{-fno-builtin} + \item \texttt{-fno-exception} + \item \texttt{-fno-stack-protector} + \item \texttt{-fno-rtti} + \item \texttt{-nostdlib} + \item \texttt{-nodefaultlibs} + \end{itemize} + You might have noticed these two flags: \texttt{-nodefaultlibs} + and \texttt{-nostdlib}. Your Kernel will be compiled on a host + system, that's true, but it cannot be linked to any existing + library on that host, otherwise it will not be executed. + \section{Linking} + You cannot use an existing linker in order to link your kernel. + As mentionned above, your kernel would not be initialized. So you must + create a linker for your kernel.\\ + Be carefull, you \texttt{CAN} use the 'ld' binary available on your + host, but you \texttt{CANNOT} use the .ld file of your host. + \section{Architecture} + The \texttt{i386} (x86) architecture is mandatory (you can thank + me later). + \section{Documentation} + There is a lot of documentation available, good and bad. + I personaly think the \texttt{\href{http://wiki.osdev.org/Main_Page} + {OSDev}} wiki is one of the best. + \section{Base code} + In this subject, you have to take your previous \texttt{KFS} code, + and work from it!\\ + Or don't. And rewrite everything from scratch. Your call! +\newpage + +%******************************************************************************% +% % +% Mandatory part % +% % +%******************************************************************************% +\chapter{Mandatory part} + + For this subject, you will have to implement a complete and functional + filesystem interface. Let's see that, point by point: + \begin{itemize}\itemsep1pt + \item Write a complete interface to read / write an IDE. + \item Write a complete interface to read an ext2 filesystem: + \begin{itemize}\itemsep1pt + \item Read the ext2 headers. + \item Create and fill in an ext2 kernel-side structure with groups, + super blocks, blocks and inodes. + \end{itemize} + \item Write a complete structure for a filesystem. That includes: + \begin{itemize}\itemsep1pt + \item Name + \item Size + \item Type + \item Inode + \item Links + \item Master + \item Father + \item Children + \item Rights + \item Next of kin + \end{itemize} + \end{itemize} + You will have to implement a \texttt{cat} command in your console, with + the behavior of the original \texttt{cat}. Now that you have a root + directory, you need to code a directory change too (pwd / cd) in your + console. Keep in mind that a process needs to have its own pwd, and two + processes can have different pwds at the same time. + + +%******************************************************************************% +% % +% Bonus part % +% % +%******************************************************************************% +\chapter{Bonus part} + + For the bonuses, you will have to handle multiple partitions, mount and + demount.\\ + You can, also, implement users (with passwords, logins, etc.). + + +%******************************************************************************% +% % +% Turn-in and peer-evaluation % +% % +%******************************************************************************% +\chapter{Turn-in and peer-evaluation} + Turn your work in using your \texttt{GiT} repository, as + usual. Only the work present on your repository will be graded in the + evaluation. + + Your must turn in your code, a Makefile and a basic virtual image for your + kernel.\\ + Side note about that image, THERE IS NO NEED TO BE BUILT LIKE AN ELEPHANT. + + +%******************************************************************************% +\end{document} diff --git a/kfs_6/oui.jpg b/kfs_6/oui.jpg Binary files differ. diff --git a/kfs_7/1.jpeg b/kfs_7/1.jpeg Binary files differ. diff --git a/kfs_7/2.jpeg b/kfs_7/2.jpeg Binary files differ. diff --git a/kfs_7/3.png b/kfs_7/3.png Binary files differ. diff --git a/kfs_7/4.png b/kfs_7/4.png Binary files differ. diff --git a/kfs_7/42.png b/kfs_7/42.png Binary files differ. diff --git a/kfs_7/choose.jpg b/kfs_7/choose.jpg Binary files differ. diff --git a/kfs_7/kfs_7.en.tex b/kfs_7/kfs_7.en.tex @@ -0,0 +1,340 @@ +%******************************************************************************% +% Copyright (C) 2018 Louis Solofrizzo % +% % +% This content is considered a 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 <https://www.gnu.org/licenses/>. % +%******************************************************************************% + +%******************************************************************************% +% % +% KFS_7.en.tex for KFS_7 % +% % +% Created on : Wed May 25 13:27:28 2016 % +% Made by : Louis "Ne02ptzero" Solofrizzo <louis@ne02ptzero.me> % +% % +%******************************************************************************% + +\documentclass{42-en} + +%******************************************************************************% +% % +% Header % +% % +%******************************************************************************% +\begin{document} + + \title{KFS\_7} + \subtitle{Syscalls, Sockets and env} + \member{Louis Solofrizzo}{louis@ne02ptzero.me} + \member{42 Staff}{pedago@42.fr} + +\summary { + The real stuff. +} + +\maketitle + +\tableofcontents + +%******************************************************************************% +% % +% Foreword % +% % +%******************************************************************************% +\chapter{Foreword} + \subsection{A developer's life in a nutshell} + \includegraphics[width=8cm]{./1.jpeg} + \includegraphics[width=9cm]{./2.jpeg} + \includegraphics[width=8cm]{./3.png} + \includegraphics[width=9cm]{./4.png} + +%******************************************************************************% +% % +% Introduction % +% % +%******************************************************************************% +\chapter{Introduction} + \subsection{Syscalls} + \begin{quotation} + \textit{In computing, a system call is the programmatic way in + which a computer program requests a service from the kernel of the + operating system it is executed on. This may include + hardware-related services (for example, accessing a hard disk + drive), creation and execution of new processes, and communication + with integral kernel services such as process scheduling. System + calls provide an essential interface between a process and the + operating system.} + \end{quotation} + It's time to implement syscalls, and code them! Sounds fun, eh? + Syscalls are stored in a \texttt{Syscall table}, in order to keep the + Kernel code clean. You can look at the one on Linux if you don't know + anything about \texttt{Syscall tables}. Now let's talk about the + runtime. When a process (usually a user-space process) calls a syscall, + a standard function is called (wrapper) and calls in turn the kernel + with the number of the said syscall. Here is a pratical example:\\ + \begin{itemize}\itemsep1pt + \item In my a.out, I call the syscall \texttt{write}. + \item The wrapper in \texttt{unistd.h} calls a + \texttt{do\_syscall(int n, ...)} function in order to tell the + kernel that this process wants to use this function. + \end{itemize} + Now there is a design problem. As you know, the kernel cannot + directly interact with user space, that's the role of syscalls! + So, how can a syscall get to the kernel? The answer's pretty simple: + the \texttt{IDT}. Let's see our simple example again: + \begin{itemize}\itemsep1pt + \item The \texttt{do\_syscall} function calls an ASM function that + calls your kernel function. + \item For that to happen, you must configure the IDT so that it + listens to \texttt{0x30}, and calls your ASM function. + \end{itemize} + And that's it. It's actually a pretty simple process - with a well + designed kernel. +\newpage + \subsection{Environment} + I'm sure you all know how a \texttt{Unix Environment} works, but let's + do a quick recap: + \begin{itemize}\itemsep1pt + \item The Environment is composed of variables with a name, and a + value. + \item These variables can be modified, deleted, and a new variable + can be added too. + \item When a process is created, the father process' environment + is passed as a third argument in the main function. + \item If the process is the master (first process after the Kernel, + or launched by the kernel itself) a default environment is set. + \item When the child process is exited, the father environment is + not affected. + \item Multiple processes can have different environments. + \end{itemize} + \subsection{User accounts} + In a Unix system, a user account is a user that has the following + attributes: + \begin{itemize}\itemsep1pt + \item A user name. + \item A user identifier (UID). + \item A group identifier (GID). + \item A home's directory. + \item A program that is launched at every login. + \end{itemize} + If you're familiar with Linux, you'll have guessed that I just described + the \texttt{/etc/passwd} file. Nothing too complex here either, just a + basic code structure with stored data. + \subsection{Password protection} + In modern Unix systems, the OS will only deal with hashed passwords + in order to protect the system. In Linux, those hashes are stored in + \texttt{/etc/shadow}. Here's the wikipedia definition: + \begin{quotation} + \textit{/etc/shadow is used to increase the security level of + passwords by restricting all but highly privileged users' access to + hashed password data. Typically, that data is kept in files owned + by and accessible only by the super user. + Systems administrators can reduce the likelihood of brute force + attacks by making the list of hashed passwords unreadable by + unprivileged users. The obvious way to do this is to make the + passwd database itself readable only by the root user. However, + this would restrict access to other data in the file such as + username-to-userid mappings, which would break many existing + utilities and provisions. One solution is a "shadow" password file + to hold the password hashes separate from the other data in the + world-readable passwd file. For local files, this is usually + /etc/shadow on Linux and Unix systems, or /etc/master.passwd on BSD + systems; each is readable only by root. (Root access to the data is + considered acceptable since on systems with the traditional + "all-powerful root" security model, the root user would be able to + obtain the information in other ways in any case). Virtually all + recent Unix-like operating systems use shadowed passwords.} + \end{quotation} + \newpage + \subsection{Inter-Process Communication Socket} + \begin{quotation} + \textit{A Unix domain socket or IPC socket (inter-process + communication socket) is a data communications endpoint for + exchanging data between processes executing on the same host + operating system. Like named pipes, Unix domain sockets support + transmission of a reliable stream of bytes (SOCK\_STREAM, compare to + TCP). In addition, they support ordered and reliable transmission + of datagrams (SOCK\_SEQPACKET), or unordered and unreliable + transmission of datagrams (SOCK\_DGRAM, compare to UDP). The Unix + domain socket facility is a standard component of POSIX operating + systems.} + \end{quotation} + Besides network uses, a socket is mainly used for inter-process + communication. Usually, the syscalls \texttt{sendmsg()} and + \texttt{recvmsg()} are used for that. In a Unix system, a socket is a + file, with a file descriptor shared between the two communicating + processes. + \subsection{Filesystem Hierarchy} + As you may know, in a Unix system, everything is a file. Like + \texttt{/dev/sda} is a hard drive, and \texttt{/dev/sda1} is a + partition. And the \texttt{/proc} folder contains all the processes of + the kernel. There are many examples for this rule, I invite you to + look it up by yourself. + +%******************************************************************************% +% % +% Goals % +% % +%******************************************************************************% +\chapter{Goals} + + At the end of this project, you will have: + \begin{itemize}\itemsep1pt + \item A complete syscall table with a syscall system. + \item A complete Unix Environment. + \item User accounts, with login and password. + \item Password protection. + \item Inter-Process Communication socket. + \item A Unix-like filesystem Hierarchy. + \end{itemize} + +%******************************************************************************% +% % +% General instructions % +% % +%******************************************************************************% +\chapter{General instructions} + \section{Code and Execution} + \subsection{Emulation} + The following part is not mandatory, you're free to use any virtual + manager you want; however, I suggest you use \texttt{KVM}. + It's a \texttt{Kernel Virtual Manager} with advanced execution + and debug functions. + All of the examples below will use \texttt{KVM}. + \subsection{Language} + The \texttt{C} language is not mandatory, you can use any language + you want for this series of projects.\\ + Keep in mind that not all languages are kernel friendly, you could + code a kernel in \texttt{Javascript}, but are you sure it's a + good idea?\\ + Also, most of the documentation is written in \texttt{C}, you will + have to 'translate' the code all along if you choose a different + language.\\ + + Furthermore, not all the features of a given language can be used + in a basic kernel. Let's take an example with \texttt{C++}:\\ + this language uses 'new' to make allocations, classes and + structures declarations. But in your kernel you don't have a memory + interface (yet), so you can't use any of these features.\\ + + Many languages can be used instead of \texttt{C}, + like \texttt{C++}, \texttt{Rust}, \texttt{Go}, etc. + You can even code your entire kernel in \texttt{ASM}!\\ + \begin{center} + \includegraphics[width=8cm]{choose.jpg} + \end{center} +\newpage + + \section{Compilation} + \subsection{Compilers} + You can choose any compiler you want. I personaly use \texttt{gcc} + and \texttt{nasm}. A Makefile must be turned-in as well. + \subsection{Flags} + In order to boot your kernel without any dependency, you must + compile your code with the following flags (adapt the flags for + your language, these are \texttt{C++} examples): + \begin{itemize}\itemsep1pt + \item \texttt{-fno-builtin} + \item \texttt{-fno-exception} + \item \texttt{-fno-stack-protector} + \item \texttt{-fno-rtti} + \item \texttt{-nostdlib} + \item \texttt{-nodefaultlibs} + \end{itemize} + You might have noticed these two flags: \texttt{-nodefaultlibs} + and \texttt{-nostdlib}. Your Kernel will be compiled on a host + system, that's true, but it cannot be linked to any existing + library on that host, otherwise it will not be executed. + \section{Linking} + You cannot use an existing linker in order to link your kernel. + As mentionned above, your kernel would not be initialized. So you must + create a linker for your kernel.\\ + Be careful, you \texttt{CAN} use the 'ld' binary available on your + host, but you \texttt{CANNOT} use the .ld file of your host. + \section{Architecture} + The \texttt{i386} (x86) architecture is mandatory (you can thank + me later). + \section{Documentation} + There is a lot of documentation available, good and bad. + I personaly think the \texttt{\href{http://wiki.osdev.org/Main_Page} + {OSDev}} wiki is one of the best. + \section{Base code} + In this subject, you have to take your previous \texttt{KFS} code, + and work from it!\\ + Or don't. And rewrite everything from scratch. Your call! +\newpage + +%******************************************************************************% +% % +% Mandatory part % +% % +%******************************************************************************% +\chapter{Mandatory part} +%%- Mise a la norme POSIX pour tout le kernel +%- Implementation de la table des syscalls +%- Creation de l'env et de son interface +%- Creation des comptes utilisateurs +%Sockets UNIX pour communication inter-processus +%- Introduction du temps atomique et du temps lineaire +%- Liaison des peripheriques aux /dev correspondants (en particulier les TTY) + +%- T3 +%- Groupes de 2 a 3 etudiants +%- 4 semaines + In this subject you will have to: + \begin{itemize}\itemsep1pt + \item Implement a functional and complete syscall interface: + \begin{itemize}\itemsep1pt + \item A syscall table. + \item An ASM function for the IDT callback. + \item A kernel-side function that takes the number of the syscall, + gets the arguments of the call, places them in the register and pushes + the call on the stack. + \item You must proove that your code works by creating a process, + have it use a syscall, and print the used syscall on the screen. + \end{itemize} + \item Implement a working unix environment. (cf. Intro) + \item Users accounts, with password protection by obscurity. (cf. Intro) + \item Inter-Process Sockets, working via syscalls, with shared file + descriptors. + \item Implement a complete file Hierarchy, Unix-like (cf. Intro). + \end{itemize} + All of these points must be checked thorougly during the peer-corrections, + so write some debug in it to facilitate the process. + +%******************************************************************************% +% % +% Bonus part % +% % +%******************************************************************************% +\chapter{Bonus part} + Change your kernel console so that a user can use a console with their own + environment, like a real OS.\\ + Implement different ttys, with the appropriate files in /dev. + +%******************************************************************************% +% % +% Turn-in and peer-evaluation % +% % +%******************************************************************************% +\chapter{Turn-in and peer-evaluation} + Turn your work in using your \texttt{GiT} repository, as + usual. Only the work that's in your repository will be graded during + the evaluation. + + Your must turn in your code, a Makefile and a basic virtual image for your kernel.\\ + Side note about this image, + THERE IS NO NEED TO BE BUILT LIKE AN ELEPHANT. + +%******************************************************************************% +\end{document} diff --git a/kfs_8/choose.jpg b/kfs_8/choose.jpg Binary files differ. diff --git a/kfs_8/kfs_8.en.tex b/kfs_8/kfs_8.en.tex @@ -0,0 +1,274 @@ +%******************************************************************************% +% Copyright (C) 2018 Louis Solofrizzo % +% % +% This content is considered a 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 <https://www.gnu.org/licenses/>. % +%******************************************************************************% + +%******************************************************************************% +% % +% KFS_8.en.tex for KFS_8 % +% % +% Created on : Wed May 25 13:27:28 2016 % +% Made by : Louis "Ne02ptzero" Solofrizzo <louis@ne02ptzero.me> % +% % +%******************************************************************************% + +\documentclass{42-en} + + +%******************************************************************************% +% % +% Header % +% % +%******************************************************************************% +\begin{document} + + + + \title{KFS\_8} + \subtitle{Modules} + \member{Louis Solofrizzo}{louis@ne02ptzero.me} + \member{42 Staff}{pedago@42.fr} + +\summary { + Modular Kernel +} + +\maketitle + +\tableofcontents + + +%******************************************************************************% +% % +% Foreword % +% % +%******************************************************************************% +\chapter{Foreword} + +%******************************************************************************% +% % +% Introduction % +% % +%******************************************************************************% +\chapter{Introduction} + Extract from \href{http://wiki.osdev.org/Modular_Kernel}{OSDev.} + \subsection{Modular Kernel} + A modular kernel is an attempt to merge the good points of kernel-level + drivers and third-party drivers. In a modular kernel, some part of the + system core will be located in independent files called modules that can be + added to the system at run time. Depending on the content of those modules, + the goal can vary such as: + \begin{itemize}\itemsep1pt + \item only loading drivers if a device is actually found + \item only load a filesystem if it gets actually requested + \item only load the code for a specific (scheduling/security/whatever) + policy when it should be evaluated + \item etc. + \end{itemize} + The basic goal remains however the same: keep what is loaded at boot-time + minimal while still allowing the kernel to perform more complex functions. + The basics of modular kernel are very close to what we find in + implementation of plugins in applications or dynamic libraries in general. + \subsection{What are some advantages and disadvantages for a Modular Kernel?} + \textbf{Advantages} + \begin{itemize}\itemsep1pt + \item The most obvious is that the kernel doesn't have to load + everything at boot time; it can be expanded as needed. This can + decrease boot time, as some drivers won't be loaded unless the hardware + they run is used (NOTE: This boot time decrease can be negligible + depending on what drivers are modules, how they're loaded, etc.) + \item The core kernel isn't as big + \item If you need a new module, you don't have to recompile. + \end{itemize} + \textbf{Disadvantages} + \begin{itemize}\itemsep1pt + \item It may lose stability. If there is a module that does something + bad, the kernel can crash, as modules should have full permissions. + \item ...and therefore security is compromised. A module can do + anything, so one could easily write an evil module to crash things. + (Some OSs, like Linux, only allow modules to be loaded by the root + user.) + \item Coding can be more difficult, as the module cannot reference + kernel procedures without kernel symbols. + \end{itemize} + \subsection{ What does a Modular Kernel look like ?} + There are several components that can be identified in virtually every + modular kernel: + \begin{itemize}\itemsep1pt + \item \textbf{The core}: this is the collection of features in the + kernel that are absolutely mandatory regardless of whether you have + modules or not. + \item \textbf{The modules loader}: this is a part of the system that + will be responsible of preparing a module file so that it can be used + as if it was a part of the core itself. + \item \textbf{The kernel symbols Table}: This contains additional + information about the core and loaded modules that the module loader + needs in order to link a new module to the existing kernel. + \item \textbf{The dependencies tracking}: As soon as you want to unload + some module, you'll have to know whether you can do it or not. + Especially, if a module X has requested symbols from module Z, trying + to unload Z while X is present in the system is likely to cause havoc. + \item \textbf{Modules}: Every part of the system you might want + (or don't want) to have. + \end{itemize} + +%******************************************************************************% +% % +% Goals % +% % +%******************************************************************************% +\chapter{Goals} + At the end of this project, you will have a full kernel module interface. + That entails: + \begin{itemize}\itemsep1pt + \item Registering kernel modules (Creation / Destruction). + \item Loading modules at boot time. + \item Implementing functions for communication / callback between + the kernel and the modules. + \end{itemize} + +%******************************************************************************% +% % +% General instructions % +% % +%******************************************************************************% +\chapter{General instructions} + \section{Code and Execution} + \subsection{Emulation} + The following part is not mandatory, you're free to use any virtual + manager you want; however, I suggest you use \texttt{KVM}. + It's a \texttt{Kernel Virtual Manager} with advanced execution + and debug functions. + All of the examples below will use \texttt{KVM}. + \subsection{Language} + The \texttt{C} language is not mandatory, you can use any language + you want for this series of projects.\\ + Keep in mind that not all languages are kernel friendly, you could + code a kernel in \texttt{Javascript}, but are you sure it's a + good idea?\\ + Also, most of the documentation is written in \texttt{C}, you will + have to 'translate' the code all along if you choose a different + language.\\ + + Furthermore, not all the features of a given language can be used + in a basic kernel. Let's take an example with \texttt{C++}:\\ + this language uses 'new' to make allocations, classes and + structures declarations. But in your kernel you don't have a memory + interface (yet), so you can't use any of these features.\\ + + Many languages can be used instead of \texttt{C}, + like \texttt{C++}, \texttt{Rust}, \texttt{Go}, etc. + You can even code your entire kernel in \texttt{ASM}!\\ + \begin{center} + \includegraphics[width=8cm]{choose.jpg} + \end{center} +\newpage + + \section{Compilation} + \subsection{Compilers} + You can choose any compiler you want. I personaly use \texttt{gcc} + and \texttt{nasm}. A Makefile must be turned-in as well. + \subsection{Flags} + In order to boot your kernel without any dependency, you must + compile your code with the following flags (adapt the flags for + your language, these are \texttt{C++} examples): + \begin{itemize}\itemsep1pt + \item \texttt{-fno-builtin} + \item \texttt{-fno-exception} + \item \texttt{-fno-stack-protector} + \item \texttt{-fno-rtti} + \item \texttt{-nostdlib} + \item \texttt{-nodefaultlibs} + \end{itemize} + You might have noticed these two flags: \texttt{-nodefaultlibs} + and \texttt{-nostdlib}. Your Kernel will be compiled on a host + system, that's true, but it cannot be linked to any existing + library on that host, otherwise it will not be executed. + \section{Linking} + You cannot use an existing linker in order to link your kernel. + As mentionned above, your kernel would not be initialized. So you must + create a linker for your kernel.\\ + Be careful, you \texttt{CAN} use the 'ld' binary available on your + host, but you \texttt{CANNOT} use the .ld file of your host. + \section{Architecture} + The \texttt{i386} (x86) architecture is mandatory (you can thank + me later). + \section{Documentation} + There is a lot of documentation available, good and bad. + I personaly think the \texttt{\href{http://wiki.osdev.org/Main_Page} + {OSDev}} wiki is one of the best. + \section{Base code} + In this subject, you have to take your previous \texttt{KFS} code, + and work from it!\\ + Or don't. And rewrite everything from scratch. Your call! +\newpage + +%******************************************************************************% +% % +% Mandatory part % +% % +%******************************************************************************% +\chapter{Mandatory part} + In this subject, you will have to: + \begin{itemize}\itemsep1pt + \item Write an internal API to manage modules integration. + \item Handle the creation and destruction of the modules. + \item Write functions to communicate between the kernel and the module. + \item Write callbacks between the kernel and the module. + \item Make these callbacks configurable. For example, if a module wants + a callback function called at every CPU cycle, it must declare it so + that the kernel calls the function when the module is created. + \item Give these modules access to the kernel functions for memory, + sockets, process, etc. + \end{itemize} + In order to prove that your work is functional, you must implement 2 + modules: a keyboard module and a time module.\\ + \\ + \textbf{Keyboard Module}\\ + The keyboard module must get a callback from the Kernel every time a + key is pressed / realeased.\\ + \textbf{Time Module}\\ + The time module must return a struct / value every time the kernel asks for + it via function / ioctl / callback. + +%******************************************************************************% +% % +% Bonus part % +% % +%******************************************************************************% +\chapter{Bonus part} + Create special memory allocation functions, in order to create a memory + ring dedicated to the modules. + + +%******************************************************************************% +% % +% Turn-in and peer-evaluation % +% % +%******************************************************************************% +\chapter{Turn-in and peer-evaluation} + + Turn your work in using your \texttt{GiT} repository, as + usual. Only the work that's in your repository will be graded during + the evaluation. + + Your must turn in your code, a Makefile and a basic virtual image for your + kernel.\\ + Side note about this image, + THERE IS NO NEED TO BE BUILT LIKE AN ELEPHANT. + + +%******************************************************************************% +\end{document} diff --git a/kfs_9/42.png b/kfs_9/42.png Binary files differ. diff --git a/kfs_9/choose.jpg b/kfs_9/choose.jpg Binary files differ. diff --git a/kfs_9/kfs_9.en.tex b/kfs_9/kfs_9.en.tex @@ -0,0 +1,219 @@ +%******************************************************************************% +% Copyright (C) 2018 Louis Solofrizzo % +% % +% This content is considered a 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 <https://www.gnu.org/licenses/>. % +%******************************************************************************% + +%******************************************************************************% +% % +% KFS_9.en.tex for KFS_9 % +% % +% Created on : Wed May 25 13:27:28 2016 % +% Made by : Louis "Ne02ptzero" Solofrizzo <louis@ne02ptzero.me> % +% % +%******************************************************************************% + +\documentclass{42-en} + + +%******************************************************************************% +% % +% Header % +% % +%******************************************************************************% +\begin{document} + + + + \title{KFS\_9} + \subtitle{ELF} + \member{Louis Solofrizzo}{louis@ne02ptzero.me} + \member{42 Staff}{pedago@42.fr} + +\summary { + Finally some execution. +} + +\maketitle + +\tableofcontents + + +%******************************************************************************% +% % +% Foreword % +% % +%******************************************************************************% +\chapter{Foreword} + +%******************************************************************************% +% % +% Introduction % +% % +%******************************************************************************% +\chapter{Introduction} + \subsection{ELF} + \begin{quotation} + \textit{In computing, the Executable and Linkable Format (ELF, formerly + called Extensible Linking Format) is a common standard file format for + executables, object code, shared libraries, and core dumps. First + published in the System V Release 4 (SVR4) Application Binary Interface + (ABI) specification, and later in the Tool Interface Standard, it + was quickly accepted among different vendors of Unix systems. In 1999 + it was chosen as the standard binary file format for Unix and Unix-like + systems on x86 by the 86open project. + ELF is flexible and extensible by design, and it is not bound to any + particular processor or architecture. This has allowed it to be adopted + by many different operating systems on many different platforms.} + \end{quotation} + As you can read above, ELF is a format used to read binary files. + It is pretty common in many OSs, and now's the time to implement it!\\ + More info \href{http://wiki.osdev.org/ELF}{Here.} + +%******************************************************************************% +% % +% Goals % +% % +%******************************************************************************% +\chapter{Goals} + At the end of this subject, you will have: + \begin{itemize}\itemsep1pt + \item A complete interface to read, parse, stock and execute ELF files. + \item Syscalls to read ELF files and launch a process with them. + \item A kernel module in ELF, ready to be inserted at run time. + \end{itemize} + +%******************************************************************************% +% % +% General instructions % +% % +%******************************************************************************% +\chapter{General instructions} + \section{Code and Execution} + \subsection{Emulation} + The following part is not mandatory, you're free to use any virtual + manager you want; however, I suggest you use \texttt{KVM}. + It's a \texttt{Kernel Virtual Manager} with advanced execution + and debug functions. + All of the examples below will use \texttt{KVM}. + \subsection{Language} + The \texttt{C} language is not mandatory, you can use any language + you want for this series of projects.\\ + Keep in mind that not all languages are kernel friendly though, you + could code a kernel in \texttt{Javascript}, but are you sure it's a + good idea?\\ + Also, most of the documentation is written in \texttt{C}, you will + have to 'translate' the code all along if you choose a different + language.\\ + + Furthermore, not all the features of a given language can be used + in a basic kernel. Let's take an example with \texttt{C++}:\\ + this language uses 'new' to make allocations, classes and + structures declarations. But in your kernel you don't have a memory + interface (yet), so you can't use any of these features.\\ + + Many languages can be used instead of \texttt{C}, + like \texttt{C++}, \texttt{Rust}, \texttt{Go}, etc. + You can even code your entire kernel in \texttt{ASM}!\\ + So yes, you may choose a language. But choose wisely. + \begin{center} + \includegraphics[width=8cm]{choose.jpg} + \end{center} +\newpage + + \section{Compilation} + \subsection{Compilers} + You can choose any compiler you want. I personaly use \texttt{gcc} + and \texttt{nasm}. A Makefile must be turned-in as well. + \subsection{Flags} + In order to boot your kernel without any dependency, you must + compile your code with the following flags (adapt the flags for + your language, these are \texttt{C++} examples): + \begin{itemize}\itemsep1pt + \item \texttt{-fno-builtin} + \item \texttt{-fno-exception} + \item \texttt{-fno-stack-protector} + \item \texttt{-fno-rtti} + \item \texttt{-nostdlib} + \item \texttt{-nodefaultlibs} + \end{itemize} + You might have noticed these two flags: \texttt{-nodefaultlibs} + and \texttt{-nostdlib}. Your Kernel will be compiled on a host + system, that's true, but it cannot be linked to any existing + library on that host, otherwise it will not be executed. + \section{Linking} + You cannot use an existing linker in order to link your kernel. + As mentionned above, your kernel would not be initialized. So you must + create a linker for your kernel.\\ + Be careful, you \texttt{CAN} use the 'ld' binary available on your + host, but you \texttt{CANNOT} use the .ld file of your host. + \section{Architecture} + The \texttt{i386} (x86) architecture is mandatory (you can thank + me later). + \section{Documentation} + There is a lot of documentation available, good and bad. + I personaly think the \texttt{\href{http://wiki.osdev.org/Main_Page} + {OSDev}} wiki is one of the best. + \section{Base code} + In this subject, you have to take your previous \texttt{KFS} code, + and work from it!\\ + Or don't. And rewrite everything from scratch. Your call! +\newpage + +%******************************************************************************% +% % +% Mandatory part % +% % +%******************************************************************************% +\chapter{Mandatory part} + In this project, you will have to: + \begin{itemize}\itemsep1pt + \item Create a parser for ELF files. + \item Create a loader for ELF files. + \item Execute an ELF file. + \item Implement these points in a \texttt{execve (2)}-like + syscall. + \item Make the syscall create a process associated with the ELF file. + \item Rewrite your API modules, so that you can load + modules in ELF at run time. + \item Load the modules, list them and unload them. + \end{itemize} + +%******************************************************************************% +% % +% Bonus part % +% % +%******************************************************************************% +\chapter{Bonus part} + You must create a memory ring for the modules (specifically, built-in and + run-time modules). + +%****************************************************************************** +% % +% Turn-in and peer-evaluation % +% % +%******************************************************************************% +\chapter{Turn-in and peer-evaluation} + + Turn your work in using your \texttt{GiT} repository, as + usual. Only the work that's in your repository will be graded during + the evaluation. + + Your must turn in your code, a Makefile and a basic virtual image for your + kernel.\\ + Side note about this image, + THERE IS NO NEED TO BE BUILT LIKE AN ELEPHANT. + +%******************************************************************************% +\end{document}