├── .gitignore ├── .gitpod.yml ├── LICENSE ├── README.md ├── build.sh ├── clean.sh ├── config.sh ├── default-host.sh ├── headers.sh ├── iso.sh ├── kernel ├── .gitignore ├── Makefile ├── arch │ └── i386 │ │ ├── boot │ │ └── boot.S │ │ ├── crti.S │ │ ├── crtn.S │ │ ├── data_structures │ │ └── linkedlist.c │ │ ├── drivers │ │ └── generic │ │ │ └── drv.cpp │ │ ├── gdt │ │ ├── gdt.cpp │ │ └── gdt_flush.asm │ │ ├── idt │ │ └── idt.cpp │ │ ├── linker.ld │ │ ├── make.config │ │ ├── mem │ │ └── mem.cpp │ │ ├── text │ │ └── text.c │ │ ├── tty │ │ └── tty.c │ │ ├── ui │ │ └── window.c │ │ ├── vesa │ │ ├── colors.c │ │ ├── drvg.c │ │ ├── drvi.c │ │ └── drvs.c │ │ └── vtty │ │ ├── vtconsole.c │ │ └── vtty.c ├── include │ ├── 3rdparty │ │ └── vtc.h │ ├── data_structs │ │ └── linkedlist.h │ └── kernel │ │ ├── descriptor_tables │ │ ├── gdt.h │ │ └── idt.h │ │ ├── elf.h │ │ ├── font.h │ │ ├── fs │ │ ├── disk.h │ │ ├── impl │ │ │ └── ext2.h │ │ └── vfs.h │ │ ├── mem.h │ │ ├── text.h │ │ ├── tty.h │ │ ├── ui │ │ └── window.h │ │ ├── vesa.h │ │ ├── vga.h │ │ └── video-tty.h └── kernel │ └── kernel.cpp ├── libc ├── .gitignore ├── Makefile ├── arch │ └── i386 │ │ └── make.config ├── include │ ├── stdio.h │ ├── stdlib.h │ ├── string.h │ └── sys │ │ └── cdefs.h ├── stdio │ ├── printf.c │ ├── putchar.c │ ├── puts.c │ └── vtconsole.c ├── stdlib │ ├── abort.c │ └── memory.c └── string │ ├── memcmp.c │ ├── memcpy.c │ ├── memmove.c │ ├── memset.c │ └── strlen.c ├── qemu.sh ├── screenshots ├── v1.0.png └── v1.1.png └── target-triplet-to-arch.sh /.gitignore: -------------------------------------------------------------------------------- 1 | *.iso 2 | isodir 3 | sysroot 4 | -------------------------------------------------------------------------------- /.gitpod.yml: -------------------------------------------------------------------------------- 1 | tasks: 2 | - init: echo "Replace me with a build script for the project." 3 | command: echo "Replace me with omething that should run on every start, or just 4 | remove me entirely." 5 | image: 6 | file: .gitpod.Dockerfile 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/RMuskovets/Skeles) 2 | 3 | # What is Skeles? 4 | Skeles is a hobby OS with VESA/VBE support and GRUB booting. 5 | 6 | # Screenshots 7 | ![Screenshot of 1.0](screenshots/v1.0.png) 8 | ![Screenshot with new prompt](screenshots/v1.1.png) 9 | 10 | # License 11 | The license is GNU GPL 3.0, which means you can use the code in any purposes as long as you provide access to original sources. 12 | 13 | # I want to try it! 14 | Check the `Releases` tab. There is a release. Also, if you want to build it by yourself, run the `iso.sh` script. 15 | 16 | # How to contribute? 17 | Feel free to fork the repo and send PRs to me - I'll try to merge the most relevant ones. 18 | 19 | # Roadmap 20 | I plan to: 21 | * [x] To use 1024x768 video mode 22 | * [x] To do memory management 23 | * [ ] To setup GDT/IDT 24 | * [ ] To create FAT32 or Ext2 filesystem driver. 25 | * [ ] To create fancy GUIs 26 | * [ ] To write an application loader. -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | . ./headers.sh 4 | 5 | for PROJECT in $PROJECTS; do 6 | (cd $PROJECT && DESTDIR="$SYSROOT" $MAKE install) 7 | done 8 | -------------------------------------------------------------------------------- /clean.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | . ./config.sh 4 | 5 | for PROJECT in $PROJECTS; do 6 | (cd $PROJECT && $MAKE clean) 7 | done 8 | 9 | rm -rf sysroot 10 | rm -rf isodir 11 | rm -rf myos.iso 12 | -------------------------------------------------------------------------------- /config.sh: -------------------------------------------------------------------------------- 1 | SYSTEM_HEADER_PROJECTS="libc kernel" 2 | PROJECTS="libc kernel" 3 | 4 | export MAKE=${MAKE:-make} 5 | export HOST=${HOST:-$(./default-host.sh)} 6 | 7 | export AR=${HOST}-ar 8 | export AS=${HOST}-as 9 | export CC=${HOST}-gcc 10 | 11 | export PREFIX=/usr 12 | export EXEC_PREFIX=$PREFIX 13 | export BOOTDIR=/boot 14 | export LIBDIR=$EXEC_PREFIX/lib 15 | export INCLUDEDIR=$PREFIX/include 16 | 17 | export CFLAGS='-O2 -g' 18 | export CPPFLAGS='' 19 | 20 | # Configure the cross-compiler to use the desired system root. 21 | export SYSROOT="$(pwd)/sysroot" 22 | export CC="$CC --sysroot=$SYSROOT" 23 | 24 | # Work around that the -elf gcc targets doesn't have a system include directory 25 | # because it was configured with --without-headers rather than --with-sysroot. 26 | if echo "$HOST" | grep -Eq -- '-elf($|-)'; then 27 | export CC="$CC -isystem=$INCLUDEDIR" 28 | fi 29 | -------------------------------------------------------------------------------- /default-host.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | echo i686-elf 3 | -------------------------------------------------------------------------------- /headers.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | . ./config.sh 4 | 5 | mkdir -p "$SYSROOT" 6 | 7 | for PROJECT in $SYSTEM_HEADER_PROJECTS; do 8 | (cd $PROJECT && DESTDIR="$SYSROOT" $MAKE install-headers) 9 | done 10 | -------------------------------------------------------------------------------- /iso.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | . ./build.sh 4 | 5 | mkdir -p isodir 6 | mkdir -p isodir/boot 7 | mkdir -p isodir/boot/grub 8 | 9 | cp sysroot/boot/myos.kernel isodir/boot/myos.kernel 10 | cat > isodir/boot/grub/grub.cfg << EOF 11 | menuentry "myos" { 12 | multiboot /boot/myos.kernel 13 | } 14 | EOF 15 | grub-mkrescue -o myos.iso isodir 16 | -------------------------------------------------------------------------------- /kernel/.gitignore: -------------------------------------------------------------------------------- 1 | *.d 2 | *.kernel 3 | *.o 4 | -------------------------------------------------------------------------------- /kernel/Makefile: -------------------------------------------------------------------------------- 1 | DEFAULT_HOST!=../default-host.sh 2 | HOST?=DEFAULT_HOST 3 | HOSTARCH!=../target-triplet-to-arch.sh $(HOST) 4 | 5 | CFLAGS?=-O2 -g 6 | CPPFLAGS?= 7 | LDFLAGS?= 8 | LIBS?= 9 | 10 | DESTDIR?= 11 | PREFIX?=/usr/local 12 | EXEC_PREFIX?=$(PREFIX) 13 | BOOTDIR?=$(EXEC_PREFIX)/boot 14 | INCLUDEDIR?=$(PREFIX)/include 15 | 16 | CFLAGS:=$(CFLAGS) -ffreestanding -Wall -Wextra 17 | CPPFLAGS:=$(CPPFLAGS) -D__is_kernel -Iinclude 18 | LDFLAGS:=$(LDFLAGS) 19 | LIBS:=$(LIBS) -nostdlib -lk -lgcc 20 | 21 | ARCHDIR=arch/$(HOSTARCH) 22 | 23 | include $(ARCHDIR)/make.config 24 | 25 | CFLAGS:=$(CFLAGS) $(KERNEL_ARCH_CFLAGS) 26 | CPPFLAGS:=$(CPPFLAGS) $(KERNEL_ARCH_CPPFLAGS) 27 | LDFLAGS:=$(LDFLAGS) $(KERNEL_ARCH_LDFLAGS) 28 | LIBS:=$(LIBS) $(KERNEL_ARCH_LIBS) 29 | 30 | KERNEL_OBJS=\ 31 | $(KERNEL_ARCH_OBJS) \ 32 | kernel/kernel.o \ 33 | 34 | OBJS=\ 35 | $(ARCHDIR)/crti.o \ 36 | $(ARCHDIR)/crtbegin.o \ 37 | $(KERNEL_OBJS) \ 38 | $(ARCHDIR)/crtend.o \ 39 | $(ARCHDIR)/crtn.o \ 40 | 41 | LINK_LIST=\ 42 | $(LDFLAGS) \ 43 | $(ARCHDIR)/crti.o \ 44 | $(ARCHDIR)/crtbegin.o \ 45 | $(KERNEL_OBJS) \ 46 | $(LIBS) \ 47 | $(ARCHDIR)/crtend.o \ 48 | $(ARCHDIR)/crtn.o \ 49 | 50 | .PHONY: all clean install install-headers install-kernel 51 | .SUFFIXES: .o .c .S .cpp .asm 52 | 53 | all: myos.kernel 54 | 55 | myos.kernel: $(OBJS) $(ARCHDIR)/linker.ld 56 | $(CC) -T $(ARCHDIR)/linker.ld -o $@ $(CFLAGS) $(LINK_LIST) 57 | grub-file --is-x86-multiboot myos.kernel 58 | 59 | $(ARCHDIR)/crtbegin.o $(ARCHDIR)/crtend.o: 60 | OBJ=`$(CC) $(CFLAGS) $(LDFLAGS) -print-file-name=$(@F)` && cp "$$OBJ" $@ 61 | 62 | .c.o: 63 | $(CC) -MD -c $< -o $@ -std=gnu11 $(CFLAGS) $(CPPFLAGS) 64 | 65 | .cpp.o: 66 | $(CC) -MD -c $< -o $@ -std=c++11 $(CFLAGS) $(CPPFLAGS) 67 | 68 | .S.o: 69 | $(CC) -MD -c $< -o $@ $(CFLAGS) $(CPPFLAGS) 70 | 71 | .asm.o: 72 | nasm -O0 -felf32 $< -o $@ 73 | 74 | clean: 75 | rm -f myos.kernel 76 | rm -f $(OBJS) *.o */*.o */*/*.o 77 | rm -f $(OBJS:.o=.d) *.d */*.d */*/*.d 78 | 79 | install: install-headers install-kernel 80 | 81 | install-headers: 82 | mkdir -p $(DESTDIR)$(INCLUDEDIR) 83 | cp -R --preserve=timestamps include/. $(DESTDIR)$(INCLUDEDIR)/. 84 | 85 | install-kernel: myos.kernel 86 | mkdir -p $(DESTDIR)$(BOOTDIR) 87 | cp myos.kernel $(DESTDIR)$(BOOTDIR) 88 | 89 | -include $(OBJS:.o=.d) 90 | -------------------------------------------------------------------------------- /kernel/arch/i386/boot/boot.S: -------------------------------------------------------------------------------- 1 | # Declare constants for the multiboot header. 2 | .set ALIGN, 1<<0 # align loaded modules on page boundaries 3 | .set MEMINFO, 1<<1 # provide memory map 4 | .set VIDMODE, 1<<2 # set up video mode 5 | .set FLAGS, ALIGN | MEMINFO | VIDMODE # this is the Multiboot 'flag' field 6 | .set MAGIC, 0x1BADB002 # 'magic number' lets bootloader find the header 7 | .set CHECKSUM, -(MAGIC + FLAGS) # checksum of above, to prove we are multiboot 8 | 9 | .set WIDTH, 1024 10 | .set HEIGHT, 768 11 | .set BPP, 32 12 | .set TEXT, 0 13 | 14 | # Declare a header as in the Multiboot Standard. 15 | .section .multiboot 16 | .align 4 17 | .long MAGIC 18 | .long FLAGS 19 | .long CHECKSUM 20 | .long 0 21 | .long 0 22 | .long 0 23 | .long 0 24 | .long 0 25 | .long TEXT 26 | .long WIDTH 27 | .long HEIGHT 28 | .long BPP 29 | 30 | # Reserve a stack for the initial thread. 31 | .section .bss 32 | .align 16 33 | stack_bottom: 34 | .skip 16777216 # 16 MiB 35 | stack_top: 36 | 37 | # The kernel entry point. 38 | .section .text 39 | .global _start 40 | .type _start, @function 41 | _start: 42 | movl $stack_top, %esp 43 | 44 | # Call the global constructors. 45 | call _init 46 | 47 | # Provide the Multiboot structure into the main kernel. 48 | push %ebx 49 | 50 | # Transfer control to the main kernel. 51 | call kernel_main 52 | 53 | # Hang if kernel_main unexpectedly returns. 54 | cli 55 | 1: hlt 56 | jmp 1b 57 | .size _start, . - _start 58 | -------------------------------------------------------------------------------- /kernel/arch/i386/crti.S: -------------------------------------------------------------------------------- 1 | .section .init 2 | .global _init 3 | .type _init, @function 4 | _init: 5 | push %ebp 6 | movl %esp, %ebp 7 | /* gcc will nicely put the contents of crtbegin.o's .init section here. */ 8 | 9 | .section .fini 10 | .global _fini 11 | .type _fini, @function 12 | _fini: 13 | push %ebp 14 | movl %esp, %ebp 15 | /* gcc will nicely put the contents of crtbegin.o's .fini section here. */ 16 | -------------------------------------------------------------------------------- /kernel/arch/i386/crtn.S: -------------------------------------------------------------------------------- 1 | .section .init 2 | /* gcc will nicely put the contents of crtend.o's .init section here. */ 3 | popl %ebp 4 | ret 5 | 6 | .section .fini 7 | /* gcc will nicely put the contents of crtend.o's .fini section here. */ 8 | popl %ebp 9 | ret 10 | -------------------------------------------------------------------------------- /kernel/arch/i386/data_structures/linkedlist.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | linked_list_t *linked_list() { 5 | 6 | } 7 | 8 | void linked_list_free(linked_list_t *) { 9 | 10 | } 11 | 12 | 13 | void linked_list_add(linked_list_t *, void *) { 14 | 15 | } 16 | 17 | void linked_list_del(linked_list_t *, size_t) { 18 | 19 | } 20 | 21 | size_t linked_list_sz(linked_list_t*) { 22 | 23 | } 24 | 25 | void linked_list_add_after(linked_list_t *, int, void *) { 26 | 27 | } 28 | 29 | void linked_list_add_before(linked_list_t *, int, void *) { 30 | 31 | } 32 | 33 | lnode_t lnode(void *) { 34 | 35 | } 36 | 37 | void lnode_free(lnode_t *) { 38 | 39 | } 40 | -------------------------------------------------------------------------------- /kernel/arch/i386/drivers/generic/drv.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RMuskovets/Skeles/8fc551f7e26f7485a48f8e3a3710613e733f0757/kernel/arch/i386/drivers/generic/drv.cpp -------------------------------------------------------------------------------- /kernel/arch/i386/gdt/gdt.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | extern void gdt_flush(uint32_t); 4 | 5 | static void gdt_set_gate(int32_t, uint32_t, uint32_t, uint8_t, uint8_t); 6 | 7 | gdt_entry_t gdt_entries[5]; 8 | gdt_ptr_t gdt_ptr; 9 | 10 | void init_gdt() 11 | { 12 | gdt_ptr.limit = (sizeof(gdt_entry_t) * 5) - 1; 13 | gdt_ptr.base = (uint32_t)&gdt_entries; 14 | 15 | gdt_set_gate(0, 0, 0, 0, 0); // Null segment 16 | gdt_set_gate(1, 0, 0xFFFFFFFF, 0x9A, 0xCF); // Code segment 17 | gdt_set_gate(2, 0, 0xFFFFFFFF, 0x92, 0xCF); // Data segment 18 | gdt_set_gate(3, 0, 0xFFFFFFFF, 0xFA, 0xCF); // User mode code segment 19 | gdt_set_gate(4, 0, 0xFFFFFFFF, 0xF2, 0xCF); // User mode data segment 20 | 21 | gdt_flush((uint32_t)&gdt_ptr); 22 | } 23 | 24 | static void gdt_set_gate(int32_t num, uint32_t base, uint32_t limit, uint8_t acc, uint8_t gran) 25 | { 26 | gdt_entries[num].base_low = (base & 0xffff); 27 | gdt_entries[num].base_middle = (base >> 16) & 0xFF; 28 | gdt_entries[num].base_high = (base >> 24) & 0xFF; 29 | 30 | gdt_entries[num].limit_low = (limit & 0xffff); 31 | gdt_entries[num].granularity = (limit >> 16) & 0x0F; 32 | 33 | gdt_entries[num].granularity|= gran & 0xF0; 34 | gdt_entries[num].access = acc; 35 | } -------------------------------------------------------------------------------- /kernel/arch/i386/gdt/gdt_flush.asm: -------------------------------------------------------------------------------- 1 | [GLOBAL gdt_flush] 2 | gdt_flush: 3 | mov eax, [esp+4] ; Get the pointer to the GDT, passed as a parameter. 4 | lgdt [eax] ; Load the new GDT pointer 5 | 6 | mov ax, 0x10 ; 0x10 is the offset in the GDT to our data segment 7 | mov ds, ax ; Load all data segment selectors 8 | mov es, ax 9 | mov fs, ax 10 | mov gs, ax 11 | mov ss, ax 12 | jmp 0x08:.flush ; 0x08 is the offset to our code segment: Far jump! 13 | .flush: 14 | ret 15 | -------------------------------------------------------------------------------- /kernel/arch/i386/idt/idt.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | extern void idt_flush(uint32_t); 4 | 5 | void init_idt(); 6 | static void idt_set_gate(uint8_t, uint32_t, uint16_t, uint8_t); 7 | -------------------------------------------------------------------------------- /kernel/arch/i386/linker.ld: -------------------------------------------------------------------------------- 1 | /* The bootloader will look at this image and start execution at the symbol 2 | designated at the entry point. */ 3 | ENTRY(_start) 4 | 5 | /* Tell where the various sections of the object files will be put in the final 6 | kernel image. */ 7 | SECTIONS 8 | { 9 | /* Begin putting sections at 1 MiB, a conventional place for kernels to be 10 | loaded at by the bootloader. */ 11 | . = 1M; 12 | 13 | /* First put the multiboot header, as it is required to be put very early 14 | early in the image or the bootloader won't recognize the file format. 15 | Next we'll put the .text section. */ 16 | .text BLOCK(4K) : ALIGN(4K) 17 | { 18 | *(.multiboot) 19 | *(.text) 20 | } 21 | 22 | /* Read-only data. */ 23 | .rodata BLOCK(4K) : ALIGN(4K) 24 | { 25 | *(.rodata) 26 | } 27 | 28 | /* Read-write data (initialized) */ 29 | .data BLOCK(4K) : ALIGN(4K) 30 | { 31 | *(.data) 32 | } 33 | 34 | /* Read-write data (uninitialized) and stack */ 35 | .bss BLOCK(4K) : ALIGN(4K) 36 | { 37 | *(COMMON) 38 | *(.bss) 39 | } 40 | 41 | /* The compiler may produce other sections, put them in the proper place in 42 | in this file, if you'd like to include them in the final kernel. */ 43 | } 44 | -------------------------------------------------------------------------------- /kernel/arch/i386/make.config: -------------------------------------------------------------------------------- 1 | KERNEL_ARCH_CFLAGS= 2 | KERNEL_ARCH_CPPFLAGS= 3 | KERNEL_ARCH_LDFLAGS= 4 | KERNEL_ARCH_LIBS= 5 | 6 | KERNEL_ARCH_OBJS=\ 7 | $(ARCHDIR)/boot/boot.o \ 8 | $(ARCHDIR)/vesa/drvg.o \ 9 | $(ARCHDIR)/vesa/colors.o \ 10 | $(ARCHDIR)/vesa/drvs.o \ 11 | $(ARCHDIR)/vesa/drvi.o \ 12 | $(ARCHDIR)/mem/mem.o \ 13 | $(ARCHDIR)/text/text.o \ 14 | $(ARCHDIR)/vtty/vtconsole.o \ 15 | $(ARCHDIR)/ui/window.o \ 16 | -------------------------------------------------------------------------------- /kernel/arch/i386/mem/mem.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct mem_mgr* active = 0; 4 | 5 | struct mem_mgr *new_mem_mgr(size_t start, size_t sz) 6 | { 7 | mem_chunk_t *first = (sz < sizeof(mem_chunk_t) ? 0 : (mem_chunk_t*) start); 8 | mem_mgr_t self = { 9 | .first = first 10 | }; 11 | 12 | first->allocated = false; 13 | first->prev = 0; 14 | first->next = 0; 15 | first->size = sz - sizeof(mem_chunk_t); 16 | 17 | active = &self; 18 | return active; 19 | } 20 | 21 | struct mem_mgr *get_active_mem_mgr() 22 | { 23 | return active; 24 | } 25 | 26 | void* kalloc(size_t sz) 27 | { 28 | mem_chunk_t *res = 0; 29 | for (mem_chunk_t *c = active->first; c != 0 && res == 0; c = c->next) 30 | if (c->size > sz && !c->allocated) 31 | res = c; 32 | 33 | if (res == 0) 34 | return 0; 35 | 36 | if (res->size >= sz + sizeof(mem_chunk_t) + 1) 37 | { 38 | mem_chunk_t *temp = (mem_chunk_t*)((size_t)res + sizeof(mem_chunk_t) + sz); 39 | temp->allocated = false; 40 | temp->size = res->size - sz - sizeof(mem_chunk_t); 41 | temp->prev = res; 42 | temp->next = res->next; 43 | if (temp->next != 0) 44 | temp->next->prev = temp; 45 | res->size = sz; 46 | res->next = temp; 47 | } 48 | 49 | res->allocated = true; 50 | return (void*)(((size_t)res) + sizeof(mem_chunk_t)); 51 | } 52 | 53 | void kfree(void *ptr) 54 | { 55 | mem_chunk_t* chunk = (mem_chunk_t*)((size_t)ptr - sizeof(mem_chunk_t)); 56 | 57 | chunk -> allocated = false; 58 | 59 | if(chunk->prev != 0 && !chunk->prev->allocated) 60 | { 61 | chunk->prev->next = chunk->next; 62 | chunk->prev->size += chunk->size + sizeof(mem_chunk_t); 63 | if(chunk->next != 0) 64 | chunk->next->prev = chunk->prev; 65 | 66 | chunk = chunk->prev; 67 | } 68 | 69 | if(chunk->next != 0 && !chunk->next->allocated) 70 | { 71 | chunk->size += chunk->next->size + sizeof(mem_chunk_t); 72 | chunk->next = chunk->next->next; 73 | if(chunk->next != 0) 74 | chunk->next->prev = chunk; 75 | } 76 | } 77 | 78 | void* operator new(size_t size) 79 | { 80 | if(get_active_mem_mgr() == 0) 81 | return 0; 82 | return kalloc(size); 83 | } 84 | 85 | void* operator new[](size_t size) 86 | { 87 | if(get_active_mem_mgr() == 0) 88 | return 0; 89 | return kalloc(size); 90 | } 91 | void operator delete(void* ptr) 92 | { 93 | if(get_active_mem_mgr() != 0) 94 | kfree(ptr); 95 | } 96 | 97 | void operator delete[](void* ptr) 98 | { 99 | if(get_active_mem_mgr() != 0) 100 | kfree(ptr); 101 | } -------------------------------------------------------------------------------- /kernel/arch/i386/text/text.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int x = 0; 8 | int x2 = 0; 9 | int y = 0; 10 | 11 | uint32_t fg = 0xffffffff; 12 | uint32_t bg = 0xff000000; 13 | 14 | void set_printing_coords(int dx, int dy) 15 | { 16 | x = dx; 17 | x2 = x; 18 | y = dy; 19 | } 20 | 21 | void print_ch(char c) 22 | { 23 | int lx; int ly; 24 | uint8_t *bitmap = font8x8_basic[c % 128]; 25 | for (lx = 0; lx < GLYPH_WIDTH; lx++) { 26 | for (ly = 0; ly < GLYPH_HEIGHT; ly++) { 27 | uint8_t row = bitmap[ly]; 28 | if ((row >> lx) & 1) 29 | putpixeli(x+lx, y+ly, fg); 30 | else 31 | putpixeli(x+lx, y+ly, bg); 32 | } 33 | } 34 | } 35 | 36 | void put_char(char c) 37 | { 38 | if (c == '\n') 39 | { 40 | y += GLYPH_HEIGHT; 41 | x = x2; 42 | } else if (c == '\b') 43 | { 44 | x -= GLYPH_WIDTH; 45 | } else if (c == '\r') 46 | { 47 | x = x2; 48 | } else 49 | { 50 | print_ch(c); 51 | x += GLYPH_WIDTH; 52 | } 53 | } 54 | 55 | void set_fg_color(uint32_t fgc) 56 | { 57 | fg = fgc; 58 | } 59 | void set_bg_color(uint32_t bgc) 60 | { 61 | bg = bgc; 62 | } 63 | 64 | void put_string(char *s) 65 | { 66 | size_t l = strlen(s); 67 | for (size_t i = 0; i < l; i++) 68 | { 69 | char c = s[i]; 70 | put_char(c); 71 | } 72 | } -------------------------------------------------------------------------------- /kernel/arch/i386/tty/tty.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | static const size_t VGA_WIDTH = 80; 10 | static const size_t VGA_HEIGHT = 25; 11 | static uint16_t* const VGA_MEMORY = (uint16_t*) 0xB8000; 12 | 13 | static size_t terminal_row; 14 | static size_t terminal_column; 15 | static uint8_t terminal_color; 16 | static uint16_t* terminal_buffer; 17 | 18 | void terminal_initialize(void) { 19 | terminal_row = 0; 20 | terminal_column = 0; 21 | terminal_color = vga_entry_color(VGA_COLOR_LIGHT_GREY, VGA_COLOR_BLACK); 22 | terminal_buffer = VGA_MEMORY; 23 | for (size_t y = 0; y < VGA_HEIGHT; y++) { 24 | for (size_t x = 0; x < VGA_WIDTH; x++) { 25 | const size_t index = y * VGA_WIDTH + x; 26 | terminal_buffer[index] = vga_entry(' ', terminal_color); 27 | } 28 | } 29 | } 30 | 31 | void terminal_setcolor(uint8_t color) { 32 | terminal_color = color; 33 | } 34 | 35 | void terminal_putentryat(unsigned char c, uint8_t color, size_t x, size_t y) { 36 | const size_t index = y * VGA_WIDTH + x; 37 | terminal_buffer[index] = vga_entry(c, color); 38 | } 39 | 40 | void terminal_putchar(char c) { 41 | unsigned char uc = c; 42 | terminal_putentryat(uc, terminal_color, terminal_column, terminal_row); 43 | if (++terminal_column == VGA_WIDTH) { 44 | terminal_column = 0; 45 | if (++terminal_row == VGA_HEIGHT) 46 | terminal_row = 0; 47 | } 48 | } 49 | 50 | void terminal_write(const char* data, size_t size) { 51 | for (size_t i = 0; i < size; i++) 52 | terminal_putchar(data[i]); 53 | } 54 | 55 | void terminal_writestring(const char* data) { 56 | terminal_write(data, strlen(data)); 57 | } 58 | -------------------------------------------------------------------------------- /kernel/arch/i386/ui/window.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | // #include 5 | 6 | void draw_window(window_t * self) 7 | { 8 | putrectsfi(self->x, self->y, self->x + self->w, self->y + self->h, self->border_color, self->background_color); 9 | } 10 | 11 | void draw_button(window_t * self) 12 | { 13 | putrectsfi(self->x, self->y, self->x + self->w, self->y + self->h, self->border_color, self->background_color); 14 | } 15 | 16 | void draw_textfield(window_t * self) 17 | { 18 | putrectsfi(self->x, self->y, self->x + self->w, self->y + self->h, self->border_color, self->background_color); 19 | } 20 | 21 | void draw_label(window_t * self) 22 | { 23 | 24 | } 25 | 26 | window_t *window(window_t *parent, char * text, int x, int y, int w, int h) 27 | { 28 | window_t *self = (window_t *) kalloc(sizeof(window_t)); 29 | self->parent = parent; 30 | self->title = text; 31 | self->x = x; 32 | self->y = y; 33 | self->w = w; 34 | self->h = h; 35 | self->draw = draw_window; 36 | } 37 | 38 | window_t *button(window_t *parent, char * text, int x, int y, int w, int h) 39 | { 40 | 41 | } 42 | 43 | window_t *textfield(window_t *parent, char * text, int x, int y, int w, int h) 44 | { 45 | 46 | } 47 | 48 | window_t *label(window_t *parent, char * text, int x, int y, int w, int h) 49 | { 50 | 51 | } 52 | 53 | window_t *custom_window(window_t *parent, char * text, int x, int y, int w, int h, void (*draw)(window_t *)) 54 | { 55 | 56 | } 57 | -------------------------------------------------------------------------------- /kernel/arch/i386/vesa/colors.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | uint32_t argb_to_color(argb_t *c) 4 | { 5 | return ( \ 6 | c->a << 24 \ 7 | | c->r << 16 \ 8 | | c->g << 8 \ 9 | | c->b << 0 \ 10 | ); 11 | } 12 | 13 | uint32_t vga_to_color(uint8_t vga) 14 | { 15 | switch (vga) 16 | { 17 | case 0: return 0xff000000; 18 | case 1: return 0xff0000ff; 19 | case 2: return 0xff00ff00; 20 | case 3: return 0xff00ffff; 21 | case 4: return 0xffff0000; 22 | case 5: return 0xffff00ff; 23 | case 6: return 0xff8b4513; 24 | case 7: return 0xffd3d3d3; 25 | case 8: return 0xffa9a9a9; 26 | case 9: return 0xff00bfff; 27 | case 10:return 0xff7cfc00; 28 | case 11:return 0xffe0ffff; 29 | case 12:return 0xfff08080; 30 | case 13:return 0xffff80ff; 31 | case 14:return 0xffcd8032; 32 | case 15:return 0xffffffff; 33 | } 34 | } -------------------------------------------------------------------------------- /kernel/arch/i386/vesa/drvg.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | uint32_t *framebuffer; 4 | uint32_t fb_w, fb_h, fb_p, fb_bpp; 5 | 6 | void set_framebuffer(uint32_t *mb) { 7 | framebuffer = (uint32_t *) mb[22]; 8 | fb_p = mb[24]; 9 | fb_w = mb[25]; 10 | fb_h = mb[26]; 11 | fb_bpp = mb[27] >> 24; 12 | } 13 | 14 | inline uint32_t *get_framebuffer() 15 | { 16 | return framebuffer; 17 | } 18 | 19 | inline uint32_t get_width() 20 | { 21 | return fb_w; 22 | } 23 | 24 | inline uint32_t get_height() 25 | { 26 | return fb_h; 27 | } 28 | 29 | inline uint32_t get_pitch() 30 | { 31 | return fb_p; 32 | } 33 | 34 | inline uint32_t get_bpp() 35 | { 36 | return fb_bpp; 37 | } -------------------------------------------------------------------------------- /kernel/arch/i386/vesa/drvi.c: -------------------------------------------------------------------------------- 1 | #include 2 | void putpixeli(int x, int y, uint32_t c) { 3 | get_framebuffer()[x + (y * get_pitch() / 4)] = c; 4 | } 5 | void putlinehi(int x, int y, int w, uint32_t c) { 6 | int p = x + y * get_pitch() / 4; 7 | for (int i = 0; i < w; i++) 8 | get_framebuffer()[p++] = c; 9 | } 10 | void putlinevi(int x, int y, int h, uint32_t c) { 11 | int p = x + (y) * get_pitch() / 4; 12 | for (int i = 0; i < h; i++) 13 | get_framebuffer()[p += get_pitch() / 4] = c; 14 | } 15 | void putrectsi (int x1, int y1, int x2, int y2, uint32_t c) { 16 | putlinehi(x1, y1, x2 - x1, c); 17 | putlinehi(x1, y2, x2 - x1, c); 18 | putlinevi(x1, y1, y2 - y1, c); 19 | putlinevi(x2, y1, y2 - y1, c); 20 | } 21 | void putrectfi (int x1, int y1, int x2, int y2, uint32_t c) { 22 | for (int y = y1; y < y2; y++) 23 | putlinehi(x1, y, (x2-x1), c); 24 | } 25 | void putrectsfi(int x1, int y1, int x2, int y2, uint32_t sc, uint32_t fc) { 26 | putrectsi(x1, y1, x2, y2, sc); 27 | putrectfi(x1+1, y1+1, x2, y2, fc); 28 | } 29 | -------------------------------------------------------------------------------- /kernel/arch/i386/vesa/drvs.c: -------------------------------------------------------------------------------- 1 | #include 2 | void putpixels(int x, int y, argb_t *c) { 3 | get_framebuffer()[x + y * get_pitch()] = argb_to_color(c); 4 | } 5 | void putlinehs(int x, int y, int w, argb_t *c) { 6 | int p = x-1 + y * get_pitch(); 7 | for (int i = 0; i < w; i++) 8 | get_framebuffer()[p++] = argb_to_color(c); 9 | } 10 | void putlinevs(int x, int y, int h, argb_t *c) { 11 | int p = x + (y-1) * get_pitch(); 12 | for (int i = 0; i < h; i++) 13 | get_framebuffer()[p += get_pitch()] = argb_to_color(c); 14 | } 15 | void putrectss (int x1, int y1, int x2, int y2, argb_t *c) { 16 | putlinehs(x1, y1, x2 - x1, c); 17 | putlinehs(x1, y2, x2 - x1, c); 18 | putlinevs(x1, y1, y2 - y1, c); 19 | putlinevs(x2, y1, y2 - y1, c); 20 | } 21 | void putrectfs (int x1, int y1, int x2, int y2, argb_t *c) { 22 | for (int y = y1; y < y2; y++) 23 | putlinehs(x1, y, (x2-x1), c); 24 | } 25 | void putrectsfs(int x1, int y1, int x2, int y2, argb_t *sc, argb_t *fc) { 26 | putlinehs(x1+0, y1, x2 - x1, sc); 27 | putlinehs(x1-0, y2, x2 - x1, sc); 28 | putlinevs(x1+1, y1, y2 - y1, sc); 29 | putlinevs(x2-1, y1, y2 - y1, sc); 30 | int x = x1+1; 31 | int x3= x2; 32 | for (int y = y1+1; y < (y2); y++) 33 | putlinehs(x, y, x3-x, fc); 34 | } 35 | -------------------------------------------------------------------------------- /kernel/arch/i386/vtty/vtconsole.c: -------------------------------------------------------------------------------- 1 | #include <3rdparty/vtc.h> 2 | #include 3 | 4 | vtconsole_t *vtconsole(int width, int height, vtc_paint_handler_t on_paint, vtc_cursor_handler_t on_move) 5 | { 6 | vtconsole_t *vtc = malloc(sizeof(vtconsole_t)); 7 | 8 | vtc->width = width; 9 | vtc->height = height; 10 | 11 | vtc->ansiparser = (vtansi_parser_t){VTSTATE_ESC, {{0, 0}}, 0}; 12 | vtc->attr = VTC_DEFAULT_ATTR; 13 | 14 | vtc->buffer = malloc(width * height * sizeof(vtcell_t)); 15 | 16 | vtc->cursor = (vtcursor_t){0, 0}; 17 | 18 | vtc->on_paint = on_paint; 19 | vtc->on_move = on_move; 20 | 21 | vtconsole_clear(vtc, 0, 0, width, height - 1); 22 | 23 | return vtc; 24 | } 25 | 26 | void vtconsole_delete(vtconsole_t *vtc) 27 | { 28 | free(vtc->buffer); 29 | free(vtc); 30 | } 31 | 32 | /* --- Internal methodes ---------------------------------------------------- */ 33 | 34 | void vtconsole_clear(vtconsole_t *vtc, int fromx, int fromy, int tox, int toy) 35 | { 36 | for (int i = fromx + fromy * vtc->width; i < tox + toy * vtc->width; i++) 37 | { 38 | vtcell_t *cell = &vtc->buffer[i]; 39 | 40 | cell->attr = VTC_DEFAULT_ATTR; 41 | cell->c = ' '; 42 | 43 | if (vtc->on_paint) 44 | { 45 | vtc->on_paint(vtc, cell, i % vtc->width, i / vtc->width); 46 | } 47 | } 48 | } 49 | 50 | void vtconsole_scroll(vtconsole_t *vtc) 51 | { 52 | // Scroll the screen. 53 | for (int i = 0; i < ((vtc->width * vtc->height) - vtc->width); i++) 54 | { 55 | vtc->buffer[i] = vtc->buffer[i + vtc->width]; 56 | 57 | if (vtc->on_paint) 58 | { 59 | vtc->on_paint(vtc, &vtc->buffer[i], i % vtc->width, i / vtc->width); 60 | } 61 | } 62 | 63 | // Clear the last line. 64 | for (int i = ((vtc->width * vtc->height) - vtc->width); i < vtc->width * vtc->height; i++) 65 | { 66 | vtcell_t *cell = &vtc->buffer[i]; 67 | cell->attr = VTC_DEFAULT_ATTR; 68 | cell->c = ' '; 69 | 70 | if (vtc->on_paint) 71 | { 72 | vtc->on_paint(vtc, &vtc->buffer[i], i % vtc->width, i / vtc->width); 73 | } 74 | } 75 | 76 | // Move the cursor up a line. 77 | if (vtc->cursor.y > 0) 78 | { 79 | vtc->cursor.y--; 80 | 81 | if (vtc->on_move) 82 | { 83 | vtc->on_move(vtc, &vtc->cursor); 84 | } 85 | } 86 | } 87 | 88 | // Append a new line 89 | void vtconsole_newline(vtconsole_t *vtc) 90 | { 91 | vtc->cursor.x = 0; 92 | vtc->cursor.y++; 93 | 94 | if (vtc->cursor.y == vtc->height) 95 | { 96 | vtconsole_scroll(vtc); 97 | } 98 | 99 | if (vtc->on_move) 100 | { 101 | vtc->on_move(vtc, &vtc->cursor); 102 | } 103 | } 104 | 105 | // Append character to the console buffer. 106 | void vtconsole_append(vtconsole_t *vtc, char c) 107 | { 108 | if (c == '\n') 109 | { 110 | vtconsole_newline(vtc); 111 | } 112 | else if (c == '\r') 113 | { 114 | vtc->cursor.x = 0; 115 | 116 | if (vtc->on_move) 117 | { 118 | vtc->on_move(vtc, &vtc->cursor); 119 | } 120 | } 121 | else if (c == '\t') 122 | { 123 | int n = 8 - (vtc->cursor.x % 8); 124 | 125 | for (int i = 0; i < n; i++) 126 | { 127 | vtconsole_append(vtc, ' '); 128 | } 129 | } 130 | else if (c == '\b') 131 | { 132 | if (vtc->cursor.x > 0) 133 | { 134 | vtc->cursor.x--; 135 | } 136 | else 137 | { 138 | vtc->cursor.y--; 139 | vtc->cursor.x = vtc->width - 1; 140 | } 141 | 142 | if (vtc->on_move) 143 | { 144 | vtc->on_move(vtc, &vtc->cursor); 145 | } 146 | } 147 | else 148 | { 149 | if (vtc->cursor.x >= vtc->width) 150 | vtconsole_newline(vtc); 151 | 152 | vtcell_t *cell = &vtc->buffer[vtc->cursor.x + vtc->cursor.y * vtc->width]; 153 | cell->c = c; 154 | cell->attr = vtc->attr; 155 | 156 | if (vtc->on_paint) 157 | { 158 | vtc->on_paint(vtc, cell, vtc->cursor.x, vtc->cursor.y); 159 | } 160 | 161 | vtc->cursor.x++; 162 | 163 | if (vtc->on_move) 164 | { 165 | vtc->on_move(vtc, &vtc->cursor); 166 | } 167 | } 168 | } 169 | 170 | // Moves the cursor to row n, column m. The values are 1-based, 171 | void vtconsole_csi_cup(vtconsole_t *vtc, vtansi_arg_t *stack, int count) 172 | { 173 | if (count == 1 && stack[0].empty) 174 | { 175 | vtc->cursor.x = 0; 176 | vtc->cursor.y = 0; 177 | } 178 | else if (count == 2) 179 | { 180 | if (stack[0].empty) 181 | { 182 | vtc->cursor.y = 0; 183 | } 184 | else 185 | { 186 | vtc->cursor.y = min(stack[0].value - 1, vtc->height - 1); 187 | } 188 | 189 | if (stack[1].empty) 190 | { 191 | vtc->cursor.y = 0; 192 | } 193 | else 194 | { 195 | vtc->cursor.x = min(stack[1].value - 1, vtc->width - 1); 196 | } 197 | } 198 | 199 | if (vtc->on_move) 200 | { 201 | vtc->on_move(vtc, &vtc->cursor); 202 | } 203 | } 204 | 205 | // Clears part of the screen. 206 | void vtconsole_csi_ed(vtconsole_t *vtc, vtansi_arg_t *stack, int count) 207 | { 208 | (void)(count); 209 | 210 | vtcursor_t cursor = vtc->cursor; 211 | 212 | if (stack[0].empty) 213 | { 214 | vtconsole_clear(vtc, cursor.x, cursor.y, vtc->width, vtc->height - 1); 215 | } 216 | else 217 | { 218 | int attr = stack[0].value; 219 | 220 | if (attr == 0) 221 | vtconsole_clear(vtc, cursor.x, cursor.y, vtc->width, vtc->height - 1); 222 | else if (attr == 1) 223 | vtconsole_clear(vtc, 0, 0, cursor.x, cursor.y); 224 | else if (attr == 2) 225 | vtconsole_clear(vtc, 0, 0, vtc->width, vtc->height - 1); 226 | } 227 | } 228 | 229 | // Erases part of the line. 230 | void vtconsole_csi_el(vtconsole_t *vtc, vtansi_arg_t *stack, int count) 231 | { 232 | (void)(count); 233 | 234 | vtcursor_t cursor = vtc->cursor; 235 | 236 | if (stack[0].empty) 237 | { 238 | vtconsole_clear(vtc, cursor.x, cursor.y, vtc->width, cursor.y); 239 | } 240 | else 241 | { 242 | int attr = stack[0].value; 243 | 244 | if (attr == 0) 245 | vtconsole_clear(vtc, cursor.x, cursor.y, vtc->width, cursor.y); 246 | else if (attr == 1) 247 | vtconsole_clear(vtc, 0, cursor.y, cursor.x, cursor.y); 248 | else if (attr == 2) 249 | vtconsole_clear(vtc, 0, cursor.y, vtc->width, cursor.y); 250 | } 251 | } 252 | 253 | // Sets the appearance of the following characters 254 | void vtconsole_csi_sgr(vtconsole_t *vtc, vtansi_arg_t *stack, int count) 255 | { 256 | for (int i = 0; i < count; i++) 257 | { 258 | if (stack[i].empty || stack[i].value == 0) 259 | { 260 | vtc->attr = VTC_DEFAULT_ATTR; 261 | } 262 | else 263 | { 264 | int attr = stack[i].value; 265 | 266 | if (attr == 1) // Increased intensity 267 | { 268 | vtc->attr.bright = true; 269 | } 270 | else if (attr >= 30 && attr <= 37) // Set foreground color 271 | { 272 | vtc->attr.fg = attr - 30; 273 | } 274 | else if (attr >= 40 && attr <= 47) // Set background color 275 | { 276 | vtc->attr.bg = attr - 40; 277 | } 278 | } 279 | } 280 | } 281 | 282 | // Process ANSI escape sequences and append character to the console buffer. 283 | void vtconsole_process(vtconsole_t *vtc, char c) 284 | { 285 | vtansi_parser_t *parser = &vtc->ansiparser; 286 | 287 | switch (parser->state) 288 | { 289 | case VTSTATE_ESC: 290 | if (c == '\033') 291 | { 292 | parser->state = VTSTATE_BRACKET; 293 | 294 | parser->index = 0; 295 | 296 | parser->stack[parser->index].value = 0; 297 | parser->stack[parser->index].empty = true; 298 | } 299 | else 300 | { 301 | parser->state = VTSTATE_ESC; 302 | vtconsole_append(vtc, c); 303 | } 304 | break; 305 | 306 | case VTSTATE_BRACKET: 307 | if (c == '[') 308 | { 309 | parser->state = VTSTATE_ATTR; 310 | } 311 | else 312 | { 313 | parser->state = VTSTATE_ESC; 314 | vtconsole_append(vtc, c); 315 | } 316 | break; 317 | case VTSTATE_ATTR: 318 | if (isdigit(c)) 319 | { 320 | parser->stack[parser->index].value *= 10; 321 | parser->stack[parser->index].value += (c - '0'); 322 | parser->stack[parser->index].empty = false; 323 | } 324 | else 325 | { 326 | if ((parser->index) < VTC_ANSI_PARSER_STACK_SIZE) 327 | { 328 | parser->index++; 329 | } 330 | 331 | parser->stack[parser->index].value = 0; 332 | parser->stack[parser->index].empty = true; 333 | 334 | parser->state = VTSTATE_ENDVAL; 335 | } 336 | break; 337 | default: 338 | break; 339 | } 340 | 341 | if (parser->state == VTSTATE_ENDVAL) 342 | { 343 | if (c == ';') 344 | { 345 | parser->state = VTSTATE_ATTR; 346 | } 347 | else 348 | { 349 | switch (c) 350 | { 351 | case 'H': 352 | vtconsole_csi_cup(vtc, parser->stack, parser->index); 353 | break; 354 | case 'J': 355 | vtconsole_csi_ed(vtc, parser->stack, parser->index); 356 | break; 357 | case 'K': 358 | vtconsole_csi_el(vtc, parser->stack, parser->index); 359 | break; 360 | case 'm': 361 | vtconsole_csi_sgr(vtc, parser->stack, parser->index); 362 | break; 363 | } 364 | 365 | parser->state = VTSTATE_ESC; 366 | } 367 | } 368 | } 369 | 370 | /* --- Methodes ------------------------------------------------------------- */ 371 | 372 | void vtconsole_putchar(vtconsole_t *vtc, char c) 373 | { 374 | vtconsole_process(vtc, c); 375 | } 376 | 377 | void vtconsole_write(vtconsole_t *vtc, const char *buffer, int size) 378 | { 379 | for (int i = 0; i < size; i++) 380 | { 381 | vtconsole_process(vtc, buffer[i]); 382 | } 383 | } 384 | -------------------------------------------------------------------------------- /kernel/arch/i386/vtty/vtty.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | // #define __USE_VTC 12 | 13 | #ifdef __USE_VTC 14 | #include <3rdparty/vtc.h> 15 | #endif 16 | 17 | const uint32_t start_x = 10; 18 | const uint32_t start_y = 10; 19 | 20 | uint32_t col = 0; 21 | uint32_t row = 0; 22 | 23 | uint32_t max_col, max_row; 24 | 25 | uint32_t vga_color, bg_color; 26 | 27 | void print_ch(char); 28 | #ifdef __USE_VTC 29 | 30 | void print_ch_at(char c, int pos_x, int pos_y); 31 | 32 | static char colors[] = 33 | { 34 | [VTCOLOR_BLACK] = VGA_COLOR_BLACK, 35 | [VTCOLOR_RED] = VGA_COLOR_RED, 36 | [VTCOLOR_GREEN] = VGA_COLOR_GREEN, 37 | [VTCOLOR_YELLOW] = VGA_COLOR_BROWN, 38 | [VTCOLOR_BLUE] = VGA_COLOR_BLUE, 39 | [VTCOLOR_MAGENTA] = VGA_COLOR_MAGENTA, 40 | [VTCOLOR_CYAN] = VGA_COLOR_CYAN, 41 | [VTCOLOR_GREY] = VGA_COLOR_LIGHT_GREY, 42 | }; 43 | 44 | static char brightcolors[] = 45 | { 46 | [VTCOLOR_BLACK] = VGA_COLOR_DARK_GREY, 47 | [VTCOLOR_RED] = VGA_COLOR_LIGHT_RED, 48 | [VTCOLOR_GREEN] = VGA_COLOR_LIGHT_GREEN, 49 | [VTCOLOR_YELLOW] = VGA_COLOR_LIGHT_BROWN, 50 | [VTCOLOR_BLUE] = VGA_COLOR_LIGHT_BLUE, 51 | [VTCOLOR_MAGENTA] = VGA_COLOR_LIGHT_MAGENTA, 52 | [VTCOLOR_CYAN] = VGA_COLOR_LIGHT_CYAN, 53 | [VTCOLOR_GREY] = VGA_COLOR_WHITE, 54 | }; 55 | 56 | 57 | void vtc_paint_callback(vtconsole_t *vtc, vtcell_t *cell, int x, int y) 58 | { 59 | if (cell->attr.bright) 60 | { 61 | terminal_setcolor(brightcolors[cell->attr.fg]); 62 | } else 63 | { 64 | terminal_setcolor(colors[cell->attr.fg]); 65 | } 66 | 67 | terminal_setbgcolor(colors[cell->attr.bg]); 68 | print_ch_at(cell->c, x, y); 69 | } 70 | 71 | void vtc_move_callback(vtconsole_t *vtc, vtcursor_t *cur) 72 | { 73 | terminal_goto((uint32_t) cur->x, (uint32_t) cur->y); 74 | } 75 | 76 | vtconsole_t *vtc; 77 | #endif 78 | 79 | void terminal_setcolor(uint8_t vc) 80 | { 81 | set_fg_color(vga_to_color(vc)); 82 | } 83 | void terminal_setbgcolor(uint8_t vc) 84 | { 85 | set_bg_color(vga_to_color(vc)); 86 | } 87 | 88 | void terminal_goto(uint32_t c, uint32_t r) 89 | { 90 | set_printing_coords(start_x + c*GLYPH_WIDTH, start_y + r*GLYPH_HEIGHT); 91 | } 92 | 93 | void print_ch_at(char c, int pos_x, int pos_y) 94 | { 95 | int x = (start_x+pos_x*GLYPH_WIDTH); 96 | int y = (start_y+pos_y*GLYPH_HEIGHT); 97 | int lx; int ly; 98 | uint8_t *bitmap = font8x8_basic[c % 128]; 99 | for (lx = 0; lx < GLYPH_WIDTH; lx++) { 100 | for (ly = 0; ly < GLYPH_HEIGHT; ly++) { 101 | uint8_t row = bitmap[ly]; 102 | if ((row >> lx) & 1) 103 | putpixeli(x+lx, y+ly, vga_color); 104 | else 105 | putpixeli(x+lx,y+ly, bg_color); 106 | } 107 | } 108 | } 109 | 110 | void terminal_initialize() 111 | { 112 | set_printing_coords(start_x, start_y); 113 | max_col = (start_x * 2 - get_width()) / GLYPH_WIDTH; 114 | max_row = (start_y * 2 - get_height())/ GLYPH_HEIGHT; 115 | #ifdef __USE_VTC 116 | vtc = vtconsole(max_col, max_row, vtc_paint_callback, vtc_move_callback); 117 | #endif 118 | } 119 | 120 | void terminal_free() 121 | { 122 | #ifdef __USE_VTC 123 | vtconsole_delete(vtc); 124 | #endif 125 | vga_color = 0; 126 | max_col = 0; 127 | max_row = 0; 128 | } 129 | 130 | void terminal_putchar(char c) 131 | { 132 | #ifdef __USE_VTC 133 | vtconsole_putchar(vtc, c); 134 | #else 135 | put_char(c); 136 | #endif 137 | } 138 | 139 | void terminal_write(const char* data, size_t size) 140 | { 141 | #ifdef __USE_VTC 142 | vtconsole_write(vtc, data, size); 143 | #else 144 | for (int i = 0; i < size; ++i) 145 | { 146 | terminal_putchar(data[i]); 147 | } 148 | #endif 149 | } 150 | 151 | void terminal_writestring(const char* data) 152 | { 153 | // vtconsole_write(vtc, data, strlen(data)); 154 | terminal_write(data, strlen(data)); 155 | } 156 | -------------------------------------------------------------------------------- /kernel/include/3rdparty/vtc.h: -------------------------------------------------------------------------------- 1 | #ifndef _LIBC_VTCONSOLE 2 | #define _LIBC_VTCONSOLE 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #define VTC_DEFAULT_FOREGROUND VTCOLOR_GREY 9 | #define VTC_DEFAULT_BACKGROUND VTCOLOR_BLACK 10 | #define VTC_DEFAULT_ATTR (vtattr_t){ false, VTC_DEFAULT_FOREGROUND, VTC_DEFAULT_BACKGROUND } 11 | #define VTC_ANSI_PARSER_STACK_SIZE 8 12 | 13 | struct vtconsole; 14 | 15 | typedef enum 16 | { 17 | VTCOLOR_BLACK, 18 | VTCOLOR_RED, 19 | VTCOLOR_GREEN, 20 | VTCOLOR_YELLOW, 21 | VTCOLOR_BLUE, 22 | VTCOLOR_MAGENTA, 23 | VTCOLOR_CYAN, 24 | VTCOLOR_GREY, 25 | } vtcolor_t; 26 | 27 | typedef enum 28 | { 29 | VTSTATE_ESC, 30 | VTSTATE_BRACKET, 31 | VTSTATE_ATTR, 32 | VTSTATE_ENDVAL, 33 | } vtansi_parser_state_t; 34 | 35 | typedef struct 36 | { 37 | int value; 38 | bool empty; 39 | } vtansi_arg_t; 40 | 41 | typedef struct 42 | { 43 | vtansi_parser_state_t state; 44 | vtansi_arg_t stack[VTC_ANSI_PARSER_STACK_SIZE]; 45 | int index; 46 | } vtansi_parser_t; 47 | 48 | typedef struct 49 | { 50 | bool bright; 51 | vtcolor_t fg; 52 | vtcolor_t bg; 53 | } vtattr_t; 54 | 55 | typedef struct 56 | { 57 | char c; 58 | vtattr_t attr; 59 | } vtcell_t; 60 | 61 | typedef struct 62 | { 63 | int x; 64 | int y; 65 | } vtcursor_t; 66 | 67 | typedef void (*vtc_paint_handler_t)(struct vtconsole* vtc, vtcell_t* cell, int x, int y); 68 | typedef void (*vtc_cursor_handler_t)(struct vtconsole* vtc, vtcursor_t* cur); 69 | 70 | typedef struct vtconsole 71 | { 72 | 73 | int width; 74 | int height; 75 | 76 | vtattr_t attr; 77 | vtansi_parser_t ansiparser; 78 | 79 | vtcell_t *buffer; 80 | vtcursor_t cursor; 81 | 82 | vtc_paint_handler_t on_paint; 83 | vtc_cursor_handler_t on_move; 84 | } vtconsole_t; 85 | 86 | vtconsole_t* vtconsole(int width, int height, vtc_paint_handler_t on_paint, vtc_cursor_handler_t on_move); 87 | void vtconsole_delete(vtconsole_t *c); 88 | 89 | void vtconsole_clear(vtconsole_t *vtc, int fromx, int fromy, int tox, int toy); 90 | void vtconsole_scroll(vtconsole_t *vtc); 91 | void vtconsole_newline(vtconsole_t *vtc); 92 | 93 | void vtconsole_putchar(vtconsole_t *vtc, char c); 94 | void vtconsole_write(vtconsole_t *vtc, const char *buffer, int size); 95 | 96 | #endif -------------------------------------------------------------------------------- /kernel/include/data_structs/linkedlist.h: -------------------------------------------------------------------------------- 1 | #ifndef _LINKED_LIST 2 | #define _LINKED_LIST 3 | 4 | #include 5 | 6 | typedef struct lnode 7 | { 8 | void *data; 9 | struct lnode *next; 10 | } lnode_t; 11 | 12 | typedef struct llist 13 | { 14 | lnode_t *first; 15 | } linked_list_t; 16 | 17 | linked_list_t *linked_list(); 18 | void linked_list_free(linked_list_t *); 19 | 20 | void linked_list_add(linked_list_t *, void *); 21 | void linked_list_del(linked_list_t *, size_t); 22 | size_t linked_list_sz(linked_list_t*); 23 | void linked_list_add_after(linked_list_t *, int, void *); 24 | void linked_list_add_before(linked_list_t *, int, void *); 25 | 26 | lnode_t lnode(void *); 27 | void lnode_free(lnode_t *); 28 | 29 | #endif -------------------------------------------------------------------------------- /kernel/include/kernel/descriptor_tables/gdt.h: -------------------------------------------------------------------------------- 1 | #ifndef _KERNEL_GDT_H 2 | #define _KERNEL_GDT_H 3 | 4 | #include 5 | #include 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | struct gdt_entry_struct 12 | { 13 | uint16_t limit_low; // The lower 16 bits of the limit. 14 | uint16_t base_low; // The lower 16 bits of the base. 15 | uint8_t base_middle; // The next 8 bits of the base. 16 | uint8_t access; // Access flags, determine what ring this segment can be used in. 17 | uint8_t granularity; 18 | uint8_t base_high; // The last 8 bits of the base. 19 | } __attribute__((packed)); 20 | typedef struct gdt_entry_struct gdt_entry_t; 21 | 22 | struct gdt_ptr_struct 23 | { 24 | uint16_t limit; 25 | uint32_t base; 26 | } __attribute__((packed)); 27 | typedef struct gdt_ptr_struct gdt_ptr_t; 28 | 29 | void init_gdt(); 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | 35 | #endif -------------------------------------------------------------------------------- /kernel/include/kernel/descriptor_tables/idt.h: -------------------------------------------------------------------------------- 1 | #ifndef _KERNEL_IDT_H 2 | #define _KERNEL_IDT_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | struct idt_entry_struct 9 | { 10 | uint16_t base_lo; // The lower 16 bits of the address to jump to when this interrupt fires. 11 | uint16_t sel; // Kernel segment selector. 12 | uint8_t always0; // This must always be zero. 13 | uint8_t flags; // More flags. See documentation. 14 | uint16_t base_hi; // The upper 16 bits of the address to jump to. 15 | } __attribute__((packed)); 16 | typedef struct idt_entry_struct idt_entry_t; 17 | 18 | // A struct describing a pointer to an array of interrupt handlers. 19 | // This is in a format suitable for giving to 'lidt'. 20 | struct idt_ptr_struct 21 | { 22 | uint16_t limit; 23 | uint32_t base; // The address of the first element in our idt_entry_t array. 24 | } __attribute__((packed)); 25 | typedef struct idt_ptr_struct idt_ptr_t; 26 | 27 | // These extern directives let us access the addresses of our ASM ISR handlers. 28 | extern void isr0(); 29 | extern void isr1(); 30 | extern void isr2(); 31 | extern void isr3(); 32 | extern void isr4(); 33 | extern void isr5(); 34 | extern void isr6(); 35 | extern void isr7(); 36 | extern void isr8(); 37 | extern void isr9(); 38 | extern void isr10(); 39 | extern void isr11(); 40 | extern void isr12(); 41 | extern void isr13(); 42 | extern void isr14(); 43 | extern void isr15(); 44 | extern void isr16(); 45 | extern void isr17(); 46 | extern void isr18(); 47 | extern void isr19(); 48 | extern void isr20(); 49 | extern void isr21(); 50 | extern void isr22(); 51 | extern void isr23(); 52 | extern void isr24(); 53 | extern void isr25(); 54 | extern void isr26(); 55 | extern void isr27(); 56 | extern void isr28(); 57 | extern void isr29(); 58 | extern void isr30(); 59 | extern void isr31(); 60 | 61 | void init_idt(); 62 | 63 | #ifdef __cplusplus 64 | } 65 | #endif 66 | 67 | #endif -------------------------------------------------------------------------------- /kernel/include/kernel/elf.h: -------------------------------------------------------------------------------- 1 | #ifndef _KERNEL_ELF_LOADER 2 | #define _KERNEL_ELF_LOADER 3 | 4 | #include 5 | #include 6 | 7 | typedef uint16_t Elf32_Half; // Unsigned half int 8 | typedef uint32_t Elf32_Off; // Unsigned offset 9 | typedef uint32_t Elf32_Addr; // Unsigned address 10 | typedef uint32_t Elf32_Word; // Unsigned int 11 | typedef int32_t Elf32_Sword; // Signed int 12 | 13 | #define ELF_NIDENT 16 14 | 15 | enum Elf_Ident { 16 | EI_MAG0 = 0, // 0x7F 17 | EI_MAG1 = 1, // 'E' 18 | EI_MAG2 = 2, // 'L' 19 | EI_MAG3 = 3, // 'F' 20 | EI_CLASS = 4, // Architecture (32/64) 21 | EI_DATA = 5, // Byte Order 22 | EI_VERSION = 6, // ELF Version 23 | EI_OSABI = 7, // OS Specific 24 | EI_ABIVERSION = 8, // OS Specific 25 | EI_PAD = 9 // Padding 26 | }; 27 | 28 | typedef struct { 29 | uint8_t e_ident[ELF_NIDENT]; 30 | Elf32_Half e_type; 31 | Elf32_Half e_machine; 32 | Elf32_Word e_version; 33 | Elf32_Addr e_entry; 34 | Elf32_Off e_phoff; 35 | Elf32_Off e_shoff; 36 | Elf32_Word e_flags; 37 | Elf32_Half e_ehsize; 38 | Elf32_Half e_phentsize; 39 | Elf32_Half e_phnum; 40 | Elf32_Half e_shentsize; 41 | Elf32_Half e_shnum; 42 | Elf32_Half e_shstrndx; 43 | } Elf32_Ehdr; 44 | 45 | #define ELFMAG0 0x7F // e_ident[EI_MAG0] 46 | #define ELFMAG1 'E' // e_ident[EI_MAG1] 47 | #define ELFMAG2 'L' // e_ident[EI_MAG2] 48 | #define ELFMAG3 'F' // e_ident[EI_MAG3] 49 | 50 | #define ELFDATA2LSB (1) // Little Endian 51 | #define ELFCLASS32 (1) // 32-bit Architecture 52 | 53 | enum Elf_Type { 54 | ET_NONE = 0, // Unkown Type 55 | ET_REL = 1, // Relocatable File 56 | ET_EXEC = 2 // Executable File 57 | }; 58 | 59 | #define EM_386 (3) // x86 Machine Type 60 | #define EV_CURRENT (1) // ELF Current Version 61 | 62 | bool elf_load_hdr(void *data, Elf32_Ehdr *place); 63 | bool elf_load_app(void *data, void *place); 64 | 65 | #endif -------------------------------------------------------------------------------- /kernel/include/kernel/font.h: -------------------------------------------------------------------------------- 1 | #ifndef _KERNEL_FONT_H 2 | #define _KERNEL_FONT_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #define GLYPH_WIDTH 8 9 | #define GLYPH_HEIGHT 8 10 | char font8x8_basic[128][8] = { 11 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0000 (nul) 12 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0001 13 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0002 14 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0003 15 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0004 16 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0005 17 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0006 18 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0007 19 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0008 20 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0009 21 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000A 22 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000B 23 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000C 24 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000D 25 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000E 26 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000F 27 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0010 28 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0011 29 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0012 30 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0013 31 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0014 32 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0015 33 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0016 34 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0017 35 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0018 36 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0019 37 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001A 38 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001B 39 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001C 40 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001D 41 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001E 42 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001F 43 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0020 (space) 44 | { 0x18, 0x3C, 0x3C, 0x18, 0x18, 0x00, 0x18, 0x00}, // U+0021 (!) 45 | { 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0022 (") 46 | { 0x36, 0x36, 0x7F, 0x36, 0x7F, 0x36, 0x36, 0x00}, // U+0023 (#) 47 | { 0x0C, 0x3E, 0x03, 0x1E, 0x30, 0x1F, 0x0C, 0x00}, // U+0024 ($) 48 | { 0x00, 0x63, 0x33, 0x18, 0x0C, 0x66, 0x63, 0x00}, // U+0025 (%) 49 | { 0x1C, 0x36, 0x1C, 0x6E, 0x3B, 0x33, 0x6E, 0x00}, // U+0026 (&) 50 | { 0x06, 0x06, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0027 (') 51 | { 0x18, 0x0C, 0x06, 0x06, 0x06, 0x0C, 0x18, 0x00}, // U+0028 (() 52 | { 0x06, 0x0C, 0x18, 0x18, 0x18, 0x0C, 0x06, 0x00}, // U+0029 ()) 53 | { 0x00, 0x66, 0x3C, 0xFF, 0x3C, 0x66, 0x00, 0x00}, // U+002A (*) 54 | { 0x00, 0x0C, 0x0C, 0x3F, 0x0C, 0x0C, 0x00, 0x00}, // U+002B (+) 55 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0C, 0x06}, // U+002C (,) 56 | { 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00}, // U+002D (-) 57 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0C, 0x00}, // U+002E (.) 58 | { 0x60, 0x30, 0x18, 0x0C, 0x06, 0x03, 0x01, 0x00}, // U+002F (/) 59 | { 0x3E, 0x63, 0x73, 0x7B, 0x6F, 0x67, 0x3E, 0x00}, // U+0030 (0) 60 | { 0x0C, 0x0E, 0x0C, 0x0C, 0x0C, 0x0C, 0x3F, 0x00}, // U+0031 (1) 61 | { 0x1E, 0x33, 0x30, 0x1C, 0x06, 0x33, 0x3F, 0x00}, // U+0032 (2) 62 | { 0x1E, 0x33, 0x30, 0x1C, 0x30, 0x33, 0x1E, 0x00}, // U+0033 (3) 63 | { 0x38, 0x3C, 0x36, 0x33, 0x7F, 0x30, 0x78, 0x00}, // U+0034 (4) 64 | { 0x3F, 0x03, 0x1F, 0x30, 0x30, 0x33, 0x1E, 0x00}, // U+0035 (5) 65 | { 0x1C, 0x06, 0x03, 0x1F, 0x33, 0x33, 0x1E, 0x00}, // U+0036 (6) 66 | { 0x3F, 0x33, 0x30, 0x18, 0x0C, 0x0C, 0x0C, 0x00}, // U+0037 (7) 67 | { 0x1E, 0x33, 0x33, 0x1E, 0x33, 0x33, 0x1E, 0x00}, // U+0038 (8) 68 | { 0x1E, 0x33, 0x33, 0x3E, 0x30, 0x18, 0x0E, 0x00}, // U+0039 (9) 69 | { 0x00, 0x0C, 0x0C, 0x00, 0x00, 0x0C, 0x0C, 0x00}, // U+003A (:) 70 | { 0x00, 0x0C, 0x0C, 0x00, 0x00, 0x0C, 0x0C, 0x06}, // U+003B (;) 71 | { 0x18, 0x0C, 0x06, 0x03, 0x06, 0x0C, 0x18, 0x00}, // U+003C (<) 72 | { 0x00, 0x00, 0x3F, 0x00, 0x00, 0x3F, 0x00, 0x00}, // U+003D (=) 73 | { 0x06, 0x0C, 0x18, 0x30, 0x18, 0x0C, 0x06, 0x00}, // U+003E (>) 74 | { 0x1E, 0x33, 0x30, 0x18, 0x0C, 0x00, 0x0C, 0x00}, // U+003F (?) 75 | { 0x3E, 0x63, 0x7B, 0x7B, 0x7B, 0x03, 0x1E, 0x00}, // U+0040 (@) 76 | { 0x0C, 0x1E, 0x33, 0x33, 0x3F, 0x33, 0x33, 0x00}, // U+0041 (A) 77 | { 0x3F, 0x66, 0x66, 0x3E, 0x66, 0x66, 0x3F, 0x00}, // U+0042 (B) 78 | { 0x3C, 0x66, 0x03, 0x03, 0x03, 0x66, 0x3C, 0x00}, // U+0043 (C) 79 | { 0x1F, 0x36, 0x66, 0x66, 0x66, 0x36, 0x1F, 0x00}, // U+0044 (D) 80 | { 0x7F, 0x46, 0x16, 0x1E, 0x16, 0x46, 0x7F, 0x00}, // U+0045 (E) 81 | { 0x7F, 0x46, 0x16, 0x1E, 0x16, 0x06, 0x0F, 0x00}, // U+0046 (F) 82 | { 0x3C, 0x66, 0x03, 0x03, 0x73, 0x66, 0x7C, 0x00}, // U+0047 (G) 83 | { 0x33, 0x33, 0x33, 0x3F, 0x33, 0x33, 0x33, 0x00}, // U+0048 (H) 84 | { 0x1E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00}, // U+0049 (I) 85 | { 0x78, 0x30, 0x30, 0x30, 0x33, 0x33, 0x1E, 0x00}, // U+004A (J) 86 | { 0x67, 0x66, 0x36, 0x1E, 0x36, 0x66, 0x67, 0x00}, // U+004B (K) 87 | { 0x0F, 0x06, 0x06, 0x06, 0x46, 0x66, 0x7F, 0x00}, // U+004C (L) 88 | { 0x63, 0x77, 0x7F, 0x7F, 0x6B, 0x63, 0x63, 0x00}, // U+004D (M) 89 | { 0x63, 0x67, 0x6F, 0x7B, 0x73, 0x63, 0x63, 0x00}, // U+004E (N) 90 | { 0x1C, 0x36, 0x63, 0x63, 0x63, 0x36, 0x1C, 0x00}, // U+004F (O) 91 | { 0x3F, 0x66, 0x66, 0x3E, 0x06, 0x06, 0x0F, 0x00}, // U+0050 (P) 92 | { 0x1E, 0x33, 0x33, 0x33, 0x3B, 0x1E, 0x38, 0x00}, // U+0051 (Q) 93 | { 0x3F, 0x66, 0x66, 0x3E, 0x36, 0x66, 0x67, 0x00}, // U+0052 (R) 94 | { 0x1E, 0x33, 0x07, 0x0E, 0x38, 0x33, 0x1E, 0x00}, // U+0053 (S) 95 | { 0x3F, 0x2D, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00}, // U+0054 (T) 96 | { 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x3F, 0x00}, // U+0055 (U) 97 | { 0x33, 0x33, 0x33, 0x33, 0x33, 0x1E, 0x0C, 0x00}, // U+0056 (V) 98 | { 0x63, 0x63, 0x63, 0x6B, 0x7F, 0x77, 0x63, 0x00}, // U+0057 (W) 99 | { 0x63, 0x63, 0x36, 0x1C, 0x1C, 0x36, 0x63, 0x00}, // U+0058 (X) 100 | { 0x33, 0x33, 0x33, 0x1E, 0x0C, 0x0C, 0x1E, 0x00}, // U+0059 (Y) 101 | { 0x7F, 0x63, 0x31, 0x18, 0x4C, 0x66, 0x7F, 0x00}, // U+005A (Z) 102 | { 0x1E, 0x06, 0x06, 0x06, 0x06, 0x06, 0x1E, 0x00}, // U+005B ([) 103 | { 0x03, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x40, 0x00}, // U+005C (\) 104 | { 0x1E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1E, 0x00}, // U+005D (]) 105 | { 0x08, 0x1C, 0x36, 0x63, 0x00, 0x00, 0x00, 0x00}, // U+005E (^) 106 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF}, // U+005F (_) 107 | { 0x0C, 0x0C, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0060 (`) 108 | { 0x00, 0x00, 0x1E, 0x30, 0x3E, 0x33, 0x6E, 0x00}, // U+0061 (a) 109 | { 0x07, 0x06, 0x06, 0x3E, 0x66, 0x66, 0x3B, 0x00}, // U+0062 (b) 110 | { 0x00, 0x00, 0x1E, 0x33, 0x03, 0x33, 0x1E, 0x00}, // U+0063 (c) 111 | { 0x38, 0x30, 0x30, 0x3e, 0x33, 0x33, 0x6E, 0x00}, // U+0064 (d) 112 | { 0x00, 0x00, 0x1E, 0x33, 0x3f, 0x03, 0x1E, 0x00}, // U+0065 (e) 113 | { 0x1C, 0x36, 0x06, 0x0f, 0x06, 0x06, 0x0F, 0x00}, // U+0066 (f) 114 | { 0x00, 0x00, 0x6E, 0x33, 0x33, 0x3E, 0x30, 0x1F}, // U+0067 (g) 115 | { 0x07, 0x06, 0x36, 0x6E, 0x66, 0x66, 0x67, 0x00}, // U+0068 (h) 116 | { 0x0C, 0x00, 0x0E, 0x0C, 0x0C, 0x0C, 0x1E, 0x00}, // U+0069 (i) 117 | { 0x30, 0x00, 0x30, 0x30, 0x30, 0x33, 0x33, 0x1E}, // U+006A (j) 118 | { 0x07, 0x06, 0x66, 0x36, 0x1E, 0x36, 0x67, 0x00}, // U+006B (k) 119 | { 0x0E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00}, // U+006C (l) 120 | { 0x00, 0x00, 0x33, 0x7F, 0x7F, 0x6B, 0x63, 0x00}, // U+006D (m) 121 | { 0x00, 0x00, 0x1F, 0x33, 0x33, 0x33, 0x33, 0x00}, // U+006E (n) 122 | { 0x00, 0x00, 0x1E, 0x33, 0x33, 0x33, 0x1E, 0x00}, // U+006F (o) 123 | { 0x00, 0x00, 0x3B, 0x66, 0x66, 0x3E, 0x06, 0x0F}, // U+0070 (p) 124 | { 0x00, 0x00, 0x6E, 0x33, 0x33, 0x3E, 0x30, 0x78}, // U+0071 (q) 125 | { 0x00, 0x00, 0x3B, 0x6E, 0x66, 0x06, 0x0F, 0x00}, // U+0072 (r) 126 | { 0x00, 0x00, 0x3E, 0x03, 0x1E, 0x30, 0x1F, 0x00}, // U+0073 (s) 127 | { 0x08, 0x0C, 0x3E, 0x0C, 0x0C, 0x2C, 0x18, 0x00}, // U+0074 (t) 128 | { 0x00, 0x00, 0x33, 0x33, 0x33, 0x33, 0x6E, 0x00}, // U+0075 (u) 129 | { 0x00, 0x00, 0x33, 0x33, 0x33, 0x1E, 0x0C, 0x00}, // U+0076 (v) 130 | { 0x00, 0x00, 0x63, 0x6B, 0x7F, 0x7F, 0x36, 0x00}, // U+0077 (w) 131 | { 0x00, 0x00, 0x63, 0x36, 0x1C, 0x36, 0x63, 0x00}, // U+0078 (x) 132 | { 0x00, 0x00, 0x33, 0x33, 0x33, 0x3E, 0x30, 0x1F}, // U+0079 (y) 133 | { 0x00, 0x00, 0x3F, 0x19, 0x0C, 0x26, 0x3F, 0x00}, // U+007A (z) 134 | { 0x38, 0x0C, 0x0C, 0x07, 0x0C, 0x0C, 0x38, 0x00}, // U+007B ({) 135 | { 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x00}, // U+007C (|) 136 | { 0x07, 0x0C, 0x0C, 0x38, 0x0C, 0x0C, 0x07, 0x00}, // U+007D (}) 137 | { 0x6E, 0x3B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+007E (~) 138 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // U+007F 139 | }; 140 | 141 | #ifdef __cplusplus 142 | } 143 | #endif 144 | 145 | #endif 146 | -------------------------------------------------------------------------------- /kernel/include/kernel/fs/disk.h: -------------------------------------------------------------------------------- 1 | #ifndef _KERNEL_DISK_DRV 2 | #define _KERNEL_DISK_DRV 3 | 4 | uint8_t disk_read(uint64_t, uint16_t); 5 | uint8_t disk_write(uint8_t, uint64_t, uint16_t); 6 | 7 | #endif -------------------------------------------------------------------------------- /kernel/include/kernel/fs/impl/ext2.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RMuskovets/Skeles/8fc551f7e26f7485a48f8e3a3710613e733f0757/kernel/include/kernel/fs/impl/ext2.h -------------------------------------------------------------------------------- /kernel/include/kernel/fs/vfs.h: -------------------------------------------------------------------------------- 1 | #ifndef _KERNEL_VFS 2 | #define _KERNEL_VFS 3 | 4 | #include 5 | 6 | typedef struct file_data { 7 | uint8_t is_directory; 8 | uint16_t files_num; 9 | uint64_t ptr; 10 | } __attribute__((packed)); // 12b 11 | 12 | typedef struct file { 13 | uint32_t vfs_id; 14 | uint64_t file_id; 15 | uint64_t parent_id; 16 | uint32_t name_len; 17 | //char *name; 18 | uint64_t name_ptr; 19 | uint64_t data_ptr; 20 | } file_t __attribute__((packed)); // 40b 21 | 22 | typedef struct vfs { 23 | uint32_t vfs_id; 24 | uint16_t files_num; 25 | uint64_t ptr; 26 | } vfs_t __attribute__((packed)); // 14b 27 | 28 | vfs_t *vfs(disk_t *); 29 | void vfs_free(vfs_t *); 30 | file_t *vfs_newfile(); 31 | 32 | #endif -------------------------------------------------------------------------------- /kernel/include/kernel/mem.h: -------------------------------------------------------------------------------- 1 | #ifndef _KERNEL_MEM_H 2 | #define _KERNEL_MEM_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | typedef struct mem_chunk 13 | { 14 | struct mem_chunk *prev; 15 | struct mem_chunk *next; 16 | bool allocated; 17 | size_t size; 18 | } mem_chunk_t; 19 | 20 | typedef struct mem_mgr 21 | { 22 | mem_chunk_t *first; 23 | } mem_mgr_t; 24 | 25 | struct mem_mgr *new_mem_mgr(size_t start, size_t sz); 26 | 27 | struct mem_mgr *get_active_mem_mgr(); 28 | void *kalloc(size_t); 29 | void kfree(void*); 30 | 31 | #ifdef __cplusplus 32 | } 33 | 34 | void* operator new(size_t size); 35 | void* operator new[](size_t size); 36 | 37 | // placement new 38 | // void* operator new(size_t size, void* ptr); 39 | // void* operator new[](size_t size, void* ptr); 40 | 41 | void operator delete(void* ptr); 42 | void operator delete[](void* ptr); 43 | 44 | #endif 45 | 46 | #endif -------------------------------------------------------------------------------- /kernel/include/kernel/text.h: -------------------------------------------------------------------------------- 1 | #ifndef _KERNEL_TEXT 2 | #define _KERNEL_TEXT 3 | 4 | #include 5 | #include 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | void put_char(char); 12 | void set_fg_color(uint32_t); 13 | void set_bg_color(uint32_t); 14 | void put_string(char*); 15 | void set_printing_coords(int, int); 16 | 17 | #ifdef __cplusplus 18 | } 19 | #endif 20 | 21 | #endif -------------------------------------------------------------------------------- /kernel/include/kernel/tty.h: -------------------------------------------------------------------------------- 1 | #ifndef _KERNEL_TTY_H 2 | #define _KERNEL_TTY_H 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | void terminal_initialize(uint8_t); 11 | void terminal_putchar(char c); 12 | void terminal_write(const char* data, size_t size); 13 | void terminal_writestring(const char* data); 14 | 15 | #ifdef __cplusplus 16 | } 17 | #endif 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /kernel/include/kernel/ui/window.h: -------------------------------------------------------------------------------- 1 | #ifndef _KERNEL_UI_WINDOW 2 | #define _KERNEL_UI_WINDOW 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | struct window; 11 | 12 | enum window_type 13 | { 14 | WINDOW, 15 | BUTTON, 16 | TEXT, 17 | LABEL, 18 | CUSTOM_WINDOW 19 | }; 20 | 21 | typedef struct window 22 | { 23 | int x, y; 24 | int w, h; 25 | 26 | char *title; 27 | 28 | struct window *parent; 29 | 30 | int type; 31 | 32 | void (*draw)(struct window *); 33 | 34 | uint32_t border_color; 35 | uint32_t text_color; 36 | uint32_t background_color; 37 | } window_t; 38 | 39 | window_t *window (window_t *, char *, int, int, int, int); 40 | window_t *button (window_t *, char *, int, int, int, int); 41 | window_t *textfield (window_t *, char *, int, int, int, int); 42 | window_t *label (window_t *, char *, int, int, int, int); 43 | window_t *custom_window(window_t *, char *, int, int, int, int, void (*)(window_t *)); 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | 49 | #endif -------------------------------------------------------------------------------- /kernel/include/kernel/vesa.h: -------------------------------------------------------------------------------- 1 | #ifndef _KERNEL_VESA_DRIVER 2 | #define _KERNEL_VESA_DRIVER 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | typedef struct argb 11 | { 12 | uint8_t a, r, g, b; 13 | } argb_t __attribute__((packed)); 14 | 15 | uint32_t argb_to_color(argb_t *); 16 | uint32_t vga_to_color(uint8_t); 17 | 18 | void set_framebuffer(uint32_t *); 19 | uint32_t *get_framebuffer(); 20 | uint32_t get_width(); 21 | uint32_t get_height(); 22 | uint32_t get_pitch(); 23 | uint32_t get_bpp(); 24 | 25 | void putpixels (int, int, argb_t *); 26 | void putrectss (int, int, int, int, argb_t *); 27 | void putrectfs (int, int, int, int, argb_t *); 28 | void putrectsfs(int, int, int, int, argb_t *, argb_t *); 29 | 30 | void putpixeli (int, int, uint32_t); 31 | void putrectsi (int, int, int, int, uint32_t); 32 | void putrectfi (int, int, int, int, uint32_t); 33 | void putrectsfi(int, int, int, int, uint32_t, uint32_t); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #endif -------------------------------------------------------------------------------- /kernel/include/kernel/vga.h: -------------------------------------------------------------------------------- 1 | #ifndef ARCH_I386_VGA_H 2 | #define ARCH_I386_VGA_H 3 | 4 | #ifndef GLYPH_WIDTH 5 | #define GLYPH_WIDTH 8 6 | #endif 7 | 8 | #ifndef GLYPH_HEIGHT 9 | #define GLYPH_HEIGHT 8 10 | #endif 11 | 12 | #include 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | enum vga_color { 19 | VGA_COLOR_BLACK = 0, 20 | VGA_COLOR_BLUE = 1, 21 | VGA_COLOR_GREEN = 2, 22 | VGA_COLOR_CYAN = 3, 23 | VGA_COLOR_RED = 4, 24 | VGA_COLOR_MAGENTA = 5, 25 | VGA_COLOR_BROWN = 6, 26 | VGA_COLOR_LIGHT_GREY = 7, 27 | VGA_COLOR_DARK_GREY = 8, 28 | VGA_COLOR_LIGHT_BLUE = 9, 29 | VGA_COLOR_LIGHT_GREEN = 10, 30 | VGA_COLOR_LIGHT_CYAN = 11, 31 | VGA_COLOR_LIGHT_RED = 12, 32 | VGA_COLOR_LIGHT_MAGENTA = 13, 33 | VGA_COLOR_LIGHT_BROWN = 14, 34 | VGA_COLOR_WHITE = 15, 35 | }; 36 | 37 | static inline uint8_t vga_entry_color(enum vga_color fg, enum vga_color bg) { 38 | return fg | bg << 4; 39 | } 40 | 41 | static inline uint16_t vga_entry(unsigned char uc, uint8_t color) { 42 | return (uint16_t) uc | (uint16_t) color << 8; 43 | } 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /kernel/include/kernel/video-tty.h: -------------------------------------------------------------------------------- 1 | #ifndef _KERNEL_VIDEO_TTY_H 2 | #define _KERNEL_VIDEO_TTY_H 3 | 4 | #include 5 | #include 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | void terminal_setcolor(uint8_t); 12 | void terminal_setbgcolor(uint8_t); 13 | void terminal_goto(uint32_t, uint32_t); 14 | 15 | void terminal_initialize(); 16 | void terminal_free(); 17 | 18 | void terminal_putchar(char c); 19 | void terminal_write(const char* data, size_t size); 20 | void terminal_writestring(const char* data); 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /kernel/kernel/kernel.cpp: -------------------------------------------------------------------------------- 1 | #define GRAPHICS 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | // #include 9 | // #include 10 | 11 | #define SHELL_PROMPT "root@kernel$ " 12 | 13 | // void setup_terminal(uint32_t *multiboot) 14 | // { 15 | // set_framebuffer(multiboot); 16 | // terminal_initialize(); 17 | // } 18 | 19 | 20 | void setup_memmgr(uint32_t *multiboot) 21 | { 22 | uint32_t* memupper = (uint32_t*)multiboot[2]; 23 | new_mem_mgr(*memupper, 64*1048576); 24 | } 25 | 26 | void loading_screen(window_t *desktop) 27 | { 28 | desktop->draw(desktop); 29 | 30 | } 31 | 32 | extern "C" void kernel_main(uint32_t *multiboot) { 33 | //setup_terminal(multiboot); 34 | set_framebuffer(multiboot); 35 | setup_memmgr(multiboot); 36 | //puts("hello, world!"); 37 | 38 | //terminal_free(); 39 | 40 | window_t *desktop = window(nullptr, "", 0, 0, 1024, 768); 41 | desktop->border_color = 0xffffffff; 42 | desktop->background_color = 0xffffffff; 43 | desktop->draw(desktop); 44 | 45 | window_t *wnd = window(desktop, "", 10, 10, 128, 100); 46 | wnd->border_color = 0xff000000; 47 | wnd->background_color = 0xff00ffff; 48 | wnd->draw(wnd); 49 | 50 | // set_printing_coords(900, 10); 51 | // set_fg_color(0xff000000); 52 | // set_bg_color(0xff00ffff); 53 | // put_string("hello, world"); 54 | 55 | // set_printing_coords(300, 50); 56 | // put_string("hi"); 57 | } 58 | -------------------------------------------------------------------------------- /libc/.gitignore: -------------------------------------------------------------------------------- 1 | *.a 2 | *.d 3 | *.o 4 | -------------------------------------------------------------------------------- /libc/Makefile: -------------------------------------------------------------------------------- 1 | DEFAULT_HOST!=../default-host.sh 2 | HOST?=DEFAULT_HOST 3 | HOSTARCH!=../target-triplet-to-arch.sh $(HOST) 4 | 5 | CFLAGS?=-O2 -g 6 | CPPFLAGS?= 7 | LDFLAGS?= 8 | LIBS?= 9 | 10 | DESTDIR?= 11 | PREFIX?=/usr/local 12 | EXEC_PREFIX?=$(PREFIX) 13 | INCLUDEDIR?=$(PREFIX)/include 14 | LIBDIR?=$(EXEC_PREFIX)/lib 15 | 16 | CFLAGS:=$(CFLAGS) -ffreestanding -Wall -Wextra 17 | CPPFLAGS:=$(CPPFLAGS) -D__is_libc -Iinclude 18 | LIBK_CFLAGS:=$(CFLAGS) 19 | LIBK_CPPFLAGS:=$(CPPFLAGS) -D__is_libk 20 | 21 | ARCHDIR=arch/$(HOSTARCH) 22 | 23 | include $(ARCHDIR)/make.config 24 | 25 | CFLAGS:=$(CFLAGS) $(ARCH_CFLAGS) 26 | CPPFLAGS:=$(CPPFLAGS) $(ARCH_CPPFLAGS) 27 | LIBK_CFLAGS:=$(LIBK_CFLAGS) $(KERNEL_ARCH_CFLAGS) 28 | LIBK_CPPFLAGS:=$(LIBK_CPPFLAGS) $(KERNEL_ARCH_CPPFLAGS) 29 | 30 | FREEOBJS=\ 31 | $(ARCH_FREEOBJS) \ 32 | stdio/printf.o \ 33 | stdio/putchar.o \ 34 | stdio/puts.o \ 35 | stdlib/abort.o \ 36 | stdlib/memory.o \ 37 | string/memcmp.o \ 38 | string/memcpy.o \ 39 | string/memmove.o \ 40 | string/memset.o \ 41 | string/strlen.o \ 42 | 43 | HOSTEDOBJS=\ 44 | $(ARCH_HOSTEDOBJS) \ 45 | 46 | OBJS=\ 47 | $(FREEOBJS) \ 48 | $(HOSTEDOBJS) \ 49 | 50 | LIBK_OBJS=$(FREEOBJS:.o=.libk.o) 51 | 52 | #BINARIES=libc.a libk.a # Not ready for libc yet. 53 | BINARIES=libk.a 54 | 55 | .PHONY: all clean install install-headers install-libs 56 | .SUFFIXES: .o .libk.o .c .S 57 | 58 | all: $(BINARIES) 59 | 60 | libc.a: $(OBJS) 61 | $(AR) rcs $@ $(OBJS) 62 | 63 | libk.a: $(LIBK_OBJS) 64 | $(AR) rcs $@ $(LIBK_OBJS) 65 | 66 | .c.o: 67 | $(CC) -MD -c $< -o $@ -std=gnu11 $(CFLAGS) $(CPPFLAGS) 68 | 69 | .c.S: 70 | $(CC) -MD -c $< -o $@ $(CFLAGS) $(CPPFLAGS) 71 | 72 | .c.libk.o: 73 | $(CC) -MD -c $< -o $@ -std=gnu11 $(LIBK_CFLAGS) $(LIBK_CPPFLAGS) 74 | 75 | .S.libk.o: 76 | $(CC) -MD -c $< -o $@ $(LIBK_CFLAGS) $(LIBK_CPPFLAGS) 77 | 78 | clean: 79 | rm -f $(BINARIES) *.a 80 | rm -f $(OBJS) $(LIBK_OBJS) *.o */*.o */*/*.o 81 | rm -f $(OBJS:.o=.d) $(LIBK_OBJS:.o=.d) *.d */*.d */*/*.d 82 | 83 | install: install-headers install-libs 84 | 85 | install-headers: 86 | mkdir -p $(DESTDIR)$(INCLUDEDIR) 87 | cp -R --preserve=timestamps include/. $(DESTDIR)$(INCLUDEDIR)/. 88 | 89 | install-libs: $(BINARIES) 90 | mkdir -p $(DESTDIR)$(LIBDIR) 91 | cp $(BINARIES) $(DESTDIR)$(LIBDIR) 92 | 93 | -include $(OBJS:.o=.d) 94 | -include $(LIBK_OBJS:.o=.d) 95 | -------------------------------------------------------------------------------- /libc/arch/i386/make.config: -------------------------------------------------------------------------------- 1 | ARCH_CFLAGS= 2 | ARCH_CPPFLAGS= 3 | KERNEL_ARCH_CFLAGS= 4 | KERNEL_ARCH_CPPFLAGS= 5 | 6 | ARCH_FREEOBJS=\ 7 | 8 | ARCH_HOSTEDOBJS=\ 9 | -------------------------------------------------------------------------------- /libc/include/stdio.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDIO_H 2 | #define _STDIO_H 1 3 | 4 | #include 5 | 6 | #define EOF (-1) 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | int printf(const char* __restrict, ...); 13 | int putchar(int); 14 | int puts(const char*); 15 | 16 | #ifdef __cplusplus 17 | } 18 | #endif 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /libc/include/stdlib.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDLIB_H 2 | #define _STDLIB_H 1 3 | 4 | #include 5 | #include 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | __attribute__((__noreturn__)) 12 | void abort(void); 13 | 14 | void* malloc(size_t); 15 | void free(void*); 16 | 17 | inline bool isdigit(char c) { 18 | return c <= '0' && c <= '9'; 19 | } 20 | 21 | inline int min(int a, int b) { 22 | return a < b ? a : b; 23 | } 24 | 25 | inline int max(int a, int b) { 26 | return a > b ? a : b; 27 | } 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /libc/include/string.h: -------------------------------------------------------------------------------- 1 | #ifndef _STRING_H 2 | #define _STRING_H 1 3 | 4 | #include 5 | 6 | #include 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | int memcmp(const void*, const void*, size_t); 13 | void* memcpy(void* __restrict, const void* __restrict, size_t); 14 | void* memmove(void*, const void*, size_t); 15 | void* memset(void*, int, size_t); 16 | size_t strlen(const char*); 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /libc/include/sys/cdefs.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_CDEFS_H 2 | #define _SYS_CDEFS_H 1 3 | 4 | #define __myos_libc 1 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /libc/stdio/printf.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | static bool print(const char* data, size_t length) { 8 | const unsigned char* bytes = (const unsigned char*) data; 9 | for (size_t i = 0; i < length; i++) 10 | if (putchar(bytes[i]) == EOF) 11 | return false; 12 | return true; 13 | } 14 | 15 | int printf(const char* restrict format, ...) { 16 | va_list parameters; 17 | va_start(parameters, format); 18 | 19 | int written = 0; 20 | 21 | while (*format != '\0') { 22 | size_t maxrem = INT_MAX - written; 23 | 24 | if (format[0] != '%' || format[1] == '%') { 25 | if (format[0] == '%') 26 | format++; 27 | size_t amount = 1; 28 | while (format[amount] && format[amount] != '%') 29 | amount++; 30 | if (maxrem < amount) { 31 | // TODO: Set errno to EOVERFLOW. 32 | return -1; 33 | } 34 | if (!print(format, amount)) 35 | return -1; 36 | format += amount; 37 | written += amount; 38 | continue; 39 | } 40 | 41 | const char* format_begun_at = format++; 42 | 43 | if (*format == 'c') { 44 | format++; 45 | char c = (char) va_arg(parameters, int /* char promotes to int */); 46 | if (!maxrem) { 47 | // TODO: Set errno to EOVERFLOW. 48 | return -1; 49 | } 50 | if (!print(&c, sizeof(c))) 51 | return -1; 52 | written++; 53 | } else if (*format == 's') { 54 | format++; 55 | const char* str = va_arg(parameters, const char*); 56 | size_t len = strlen(str); 57 | if (maxrem < len) { 58 | // TODO: Set errno to EOVERFLOW. 59 | return -1; 60 | } 61 | if (!print(str, len)) 62 | return -1; 63 | written += len; 64 | } else { 65 | format = format_begun_at; 66 | size_t len = strlen(format); 67 | if (maxrem < len) { 68 | // TODO: Set errno to EOVERFLOW. 69 | return -1; 70 | } 71 | if (!print(format, len)) 72 | return -1; 73 | written += len; 74 | format += len; 75 | } 76 | } 77 | 78 | va_end(parameters); 79 | return written; 80 | } 81 | -------------------------------------------------------------------------------- /libc/stdio/putchar.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #if defined(__is_libk) 4 | #include 5 | #endif 6 | 7 | int putchar(int ic) { 8 | #if defined(__is_libk) 9 | char c = (char) ic; 10 | terminal_write(&c, sizeof(c)); 11 | #else 12 | // TODO: Implement stdio and the write system call. 13 | #endif 14 | return ic; 15 | } 16 | -------------------------------------------------------------------------------- /libc/stdio/puts.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifdef __is_libk 4 | #include 5 | #endif 6 | 7 | int puts(const char* string) { 8 | //eturn printf("%s\n", string); 9 | terminal_writestring(string); 10 | } 11 | -------------------------------------------------------------------------------- /libc/stdio/vtconsole.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | vtconsole_t *vtconsole(int width, int height, vtc_paint_handler_t on_paint, vtc_cursor_handler_t on_move) 5 | { 6 | vtconsole_t *vtc = kalloc(sizeof(vtconsole_t)); 7 | 8 | vtc->width = width; 9 | vtc->height = height; 10 | 11 | vtc->ansiparser = (vtansi_parser_t){VTSTATE_ESC, {{0, 0}}, 0}; 12 | vtc->attr = VTC_DEFAULT_ATTR; 13 | 14 | vtc->buffer = kalloc(width * height * sizeof(vtcell_t)); 15 | 16 | vtc->cursor = (vtcursor_t){0, 0}; 17 | 18 | vtc->on_paint = on_paint; 19 | vtc->on_move = on_move; 20 | 21 | vtconsole_clear(vtc, 0, 0, width, height - 1); 22 | 23 | return vtc; 24 | } 25 | 26 | void vtconsole_delete(vtconsole_t *vtc) 27 | { 28 | kfree(vtc->buffer); 29 | kfree(vtc); 30 | } 31 | 32 | /* --- Internal methodes ---------------------------------------------------- */ 33 | 34 | void vtconsole_clear(vtconsole_t *vtc, int fromx, int fromy, int tox, int toy) 35 | { 36 | for (int i = fromx + fromy * vtc->width; i < tox + toy * vtc->width; i++) 37 | { 38 | vtcell_t *cell = &vtc->buffer[i]; 39 | 40 | cell->attr = VTC_DEFAULT_ATTR; 41 | cell->c = ' '; 42 | 43 | if (vtc->on_paint) 44 | { 45 | vtc->on_paint(vtc, cell, i % vtc->width, i / vtc->width); 46 | } 47 | } 48 | } 49 | 50 | void vtconsole_scroll(vtconsole_t *vtc) 51 | { 52 | // Scroll the screen. 53 | for (int i = 0; i < ((vtc->width * vtc->height) - vtc->width); i++) 54 | { 55 | vtc->buffer[i] = vtc->buffer[i + vtc->width]; 56 | 57 | if (vtc->on_paint) 58 | { 59 | vtc->on_paint(vtc, &vtc->buffer[i], i % vtc->width, i / vtc->width); 60 | } 61 | } 62 | 63 | // Clear the last line. 64 | for (int i = ((vtc->width * vtc->height) - vtc->width); i < vtc->width * vtc->height; i++) 65 | { 66 | vtcell_t *cell = &vtc->buffer[i]; 67 | cell->attr = VTC_DEFAULT_ATTR; 68 | cell->c = ' '; 69 | 70 | if (vtc->on_paint) 71 | { 72 | vtc->on_paint(vtc, &vtc->buffer[i], i % vtc->width, i / vtc->width); 73 | } 74 | } 75 | 76 | // Move the cursor up a line. 77 | if (vtc->cursor.y > 0) 78 | { 79 | vtc->cursor.y--; 80 | 81 | if (vtc->on_move) 82 | { 83 | vtc->on_move(vtc, &vtc->cursor); 84 | } 85 | } 86 | } 87 | 88 | // Append a new line 89 | void vtconsole_newline(vtconsole_t *vtc) 90 | { 91 | vtc->cursor.x = 0; 92 | vtc->cursor.y++; 93 | 94 | if (vtc->cursor.y == vtc->height) 95 | { 96 | vtconsole_scroll(vtc); 97 | } 98 | 99 | if (vtc->on_move) 100 | { 101 | vtc->on_move(vtc, &vtc->cursor); 102 | } 103 | } 104 | 105 | // Append character to the console buffer. 106 | void vtconsole_append(vtconsole_t *vtc, char c) 107 | { 108 | if (c == '\n') 109 | { 110 | vtconsole_newline(vtc); 111 | } 112 | else if (c == '\r') 113 | { 114 | vtc->cursor.x = 0; 115 | 116 | if (vtc->on_move) 117 | { 118 | vtc->on_move(vtc, &vtc->cursor); 119 | } 120 | } 121 | else if (c == '\t') 122 | { 123 | int n = 8 - (vtc->cursor.x % 8); 124 | 125 | for (int i = 0; i < n; i++) 126 | { 127 | vtconsole_append(vtc, ' '); 128 | } 129 | } 130 | else if (c == '\b') 131 | { 132 | if (vtc->cursor.x > 0) 133 | { 134 | vtc->cursor.x--; 135 | } 136 | else 137 | { 138 | vtc->cursor.y--; 139 | vtc->cursor.x = vtc->width - 1; 140 | } 141 | 142 | if (vtc->on_move) 143 | { 144 | vtc->on_move(vtc, &vtc->cursor); 145 | } 146 | } 147 | else 148 | { 149 | if (vtc->cursor.x >= vtc->width) 150 | vtconsole_newline(vtc); 151 | 152 | vtcell_t *cell = &vtc->buffer[vtc->cursor.x + vtc->cursor.y * vtc->width]; 153 | cell->c = c; 154 | cell->attr = vtc->attr; 155 | 156 | if (vtc->on_paint) 157 | { 158 | vtc->on_paint(vtc, cell, vtc->cursor.x, vtc->cursor.y); 159 | } 160 | 161 | vtc->cursor.x++; 162 | 163 | if (vtc->on_move) 164 | { 165 | vtc->on_move(vtc, &vtc->cursor); 166 | } 167 | } 168 | } 169 | 170 | // Moves the cursor to row n, column m. The values are 1-based, 171 | void vtconsole_csi_cup(vtconsole_t *vtc, vtansi_arg_t *stack, int count) 172 | { 173 | if (count == 1 && stack[0].empty) 174 | { 175 | vtc->cursor.x = 0; 176 | vtc->cursor.y = 0; 177 | } 178 | else if (count == 2) 179 | { 180 | if (stack[0].empty) 181 | { 182 | vtc->cursor.y = 0; 183 | } 184 | else 185 | { 186 | vtc->cursor.y = min(stack[0].value - 1, vtc->height - 1); 187 | } 188 | 189 | if (stack[1].empty) 190 | { 191 | vtc->cursor.y = 0; 192 | } 193 | else 194 | { 195 | vtc->cursor.x = min(stack[1].value - 1, vtc->width - 1); 196 | } 197 | } 198 | 199 | if (vtc->on_move) 200 | { 201 | vtc->on_move(vtc, &vtc->cursor); 202 | } 203 | } 204 | 205 | // Clears part of the screen. 206 | void vtconsole_csi_ed(vtconsole_t *vtc, vtansi_arg_t *stack, int count) 207 | { 208 | (void)(count); 209 | 210 | vtcursor_t cursor = vtc->cursor; 211 | 212 | if (stack[0].empty) 213 | { 214 | vtconsole_clear(vtc, cursor.x, cursor.y, vtc->width, vtc->height - 1); 215 | } 216 | else 217 | { 218 | int attr = stack[0].value; 219 | 220 | if (attr == 0) 221 | vtconsole_clear(vtc, cursor.x, cursor.y, vtc->width, vtc->height - 1); 222 | else if (attr == 1) 223 | vtconsole_clear(vtc, 0, 0, cursor.x, cursor.y); 224 | else if (attr == 2) 225 | vtconsole_clear(vtc, 0, 0, vtc->width, vtc->height - 1); 226 | } 227 | } 228 | 229 | // Erases part of the line. 230 | void vtconsole_csi_el(vtconsole_t *vtc, vtansi_arg_t *stack, int count) 231 | { 232 | (void)(count); 233 | 234 | vtcursor_t cursor = vtc->cursor; 235 | 236 | if (stack[0].empty) 237 | { 238 | vtconsole_clear(vtc, cursor.x, cursor.y, vtc->width, cursor.y); 239 | } 240 | else 241 | { 242 | int attr = stack[0].value; 243 | 244 | if (attr == 0) 245 | vtconsole_clear(vtc, cursor.x, cursor.y, vtc->width, cursor.y); 246 | else if (attr == 1) 247 | vtconsole_clear(vtc, 0, cursor.y, cursor.x, cursor.y); 248 | else if (attr == 2) 249 | vtconsole_clear(vtc, 0, cursor.y, vtc->width, cursor.y); 250 | } 251 | } 252 | 253 | // Sets the appearance of the following characters 254 | void vtconsole_csi_sgr(vtconsole_t *vtc, vtansi_arg_t *stack, int count) 255 | { 256 | for (int i = 0; i < count; i++) 257 | { 258 | if (stack[i].empty || stack[i].value == 0) 259 | { 260 | vtc->attr = VTC_DEFAULT_ATTR; 261 | } 262 | else 263 | { 264 | int attr = stack[i].value; 265 | 266 | if (attr == 1) // Increased intensity 267 | { 268 | vtc->attr.bright = true; 269 | } 270 | else if (attr >= 30 && attr <= 37) // Set foreground color 271 | { 272 | vtc->attr.fg = attr - 30; 273 | } 274 | else if (attr >= 40 && attr <= 47) // Set background color 275 | { 276 | vtc->attr.bg = attr - 40; 277 | } 278 | } 279 | } 280 | } 281 | 282 | // Process ANSI escape sequences and append character to the console buffer. 283 | void vtconsole_process(vtconsole_t *vtc, char c) 284 | { 285 | vtansi_parser_t *parser = &vtc->ansiparser; 286 | 287 | switch (parser->state) 288 | { 289 | case VTSTATE_ESC: 290 | if (c == '\033') 291 | { 292 | parser->state = VTSTATE_BRACKET; 293 | 294 | parser->index = 0; 295 | 296 | parser->stack[parser->index].value = 0; 297 | parser->stack[parser->index].empty = true; 298 | } 299 | else 300 | { 301 | parser->state = VTSTATE_ESC; 302 | vtconsole_append(vtc, c); 303 | } 304 | break; 305 | 306 | case VTSTATE_BRACKET: 307 | if (c == '[') 308 | { 309 | parser->state = VTSTATE_ATTR; 310 | } 311 | else 312 | { 313 | parser->state = VTSTATE_ESC; 314 | vtconsole_append(vtc, c); 315 | } 316 | break; 317 | case VTSTATE_ATTR: 318 | if (isdigit(c)) 319 | { 320 | parser->stack[parser->index].value *= 10; 321 | parser->stack[parser->index].value += (c - '0'); 322 | parser->stack[parser->index].empty = false; 323 | } 324 | else 325 | { 326 | if ((parser->index) < VTC_ANSI_PARSER_STACK_SIZE) 327 | { 328 | parser->index++; 329 | } 330 | 331 | parser->stack[parser->index].value = 0; 332 | parser->stack[parser->index].empty = true; 333 | 334 | parser->state = VTSTATE_ENDVAL; 335 | } 336 | break; 337 | default: 338 | break; 339 | } 340 | 341 | if (parser->state == VTSTATE_ENDVAL) 342 | { 343 | if (c == ';') 344 | { 345 | parser->state = VTSTATE_ATTR; 346 | } 347 | else 348 | { 349 | switch (c) 350 | { 351 | case 'H': 352 | vtconsole_csi_cup(vtc, parser->stack, parser->index); 353 | break; 354 | case 'J': 355 | vtconsole_csi_ed(vtc, parser->stack, parser->index); 356 | break; 357 | case 'K': 358 | vtconsole_csi_el(vtc, parser->stack, parser->index); 359 | break; 360 | case 'm': 361 | vtconsole_csi_sgr(vtc, parser->stack, parser->index); 362 | break; 363 | } 364 | 365 | parser->state = VTSTATE_ESC; 366 | } 367 | } 368 | } 369 | 370 | /* --- Methodes ------------------------------------------------------------- */ 371 | 372 | void vtconsole_putchar(vtconsole_t *vtc, char c) 373 | { 374 | vtconsole_process(vtc, c); 375 | } 376 | 377 | void vtconsole_write(vtconsole_t *vtc, const char *buffer, uint size) 378 | { 379 | for (uint i = 0; i < size; i++) 380 | { 381 | vtconsole_process(vtc, buffer[i]); 382 | } 383 | } 384 | -------------------------------------------------------------------------------- /libc/stdlib/abort.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | __attribute__((__noreturn__)) 5 | void abort(void) { 6 | #if defined(__is_libk) 7 | // TODO: Add proper kernel panic. 8 | printf("kernel: panic: abort()\n"); 9 | #else 10 | // TODO: Abnormally terminate the process as if by SIGABRT. 11 | printf("abort()\n"); 12 | #endif 13 | while (1) { } 14 | __builtin_unreachable(); 15 | } 16 | -------------------------------------------------------------------------------- /libc/stdlib/memory.c: -------------------------------------------------------------------------------- 1 | #include 2 | #if defined(__is_libk) 3 | #include 4 | #endif 5 | 6 | void* malloc(size_t sz) { 7 | #if defined(__is_libk) 8 | return kalloc(sz); 9 | #else 10 | return 0; 11 | #endif 12 | } 13 | 14 | void free(void* ptr) { 15 | #if defined(__is_libk) 16 | kfree(ptr); 17 | #endif 18 | } 19 | -------------------------------------------------------------------------------- /libc/string/memcmp.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int memcmp(const void* aptr, const void* bptr, size_t size) { 4 | const unsigned char* a = (const unsigned char*) aptr; 5 | const unsigned char* b = (const unsigned char*) bptr; 6 | for (size_t i = 0; i < size; i++) { 7 | if (a[i] < b[i]) 8 | return -1; 9 | else if (b[i] < a[i]) 10 | return 1; 11 | } 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /libc/string/memcpy.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void* memcpy(void* restrict dstptr, const void* restrict srcptr, size_t size) { 4 | unsigned char* dst = (unsigned char*) dstptr; 5 | const unsigned char* src = (const unsigned char*) srcptr; 6 | for (size_t i = 0; i < size; i++) 7 | dst[i] = src[i]; 8 | return dstptr; 9 | } 10 | -------------------------------------------------------------------------------- /libc/string/memmove.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void* memmove(void* dstptr, const void* srcptr, size_t size) { 4 | unsigned char* dst = (unsigned char*) dstptr; 5 | const unsigned char* src = (const unsigned char*) srcptr; 6 | if (dst < src) { 7 | for (size_t i = 0; i < size; i++) 8 | dst[i] = src[i]; 9 | } else { 10 | for (size_t i = size; i != 0; i--) 11 | dst[i-1] = src[i-1]; 12 | } 13 | return dstptr; 14 | } 15 | -------------------------------------------------------------------------------- /libc/string/memset.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void* memset(void* bufptr, int value, size_t size) { 4 | unsigned char* buf = (unsigned char*) bufptr; 5 | for (size_t i = 0; i < size; i++) 6 | buf[i] = (unsigned char) value; 7 | return bufptr; 8 | } 9 | -------------------------------------------------------------------------------- /libc/string/strlen.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | size_t strlen(const char* str) { 4 | size_t len = 0; 5 | while (str[len]) 6 | len++; 7 | return len; 8 | } 9 | -------------------------------------------------------------------------------- /qemu.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | . ./iso.sh 4 | 5 | qemu-system-$(./target-triplet-to-arch.sh $HOST) -cdrom myos.iso 6 | -------------------------------------------------------------------------------- /screenshots/v1.0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RMuskovets/Skeles/8fc551f7e26f7485a48f8e3a3710613e733f0757/screenshots/v1.0.png -------------------------------------------------------------------------------- /screenshots/v1.1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RMuskovets/Skeles/8fc551f7e26f7485a48f8e3a3710613e733f0757/screenshots/v1.1.png -------------------------------------------------------------------------------- /target-triplet-to-arch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | if echo "$1" | grep -Eq 'i[[:digit:]]86-'; then 3 | echo i386 4 | else 5 | echo "$1" | grep -Eo '^[[:alnum:]_]*' 6 | fi 7 | --------------------------------------------------------------------------------