├── .gitignore
├── LICENSE
├── Makefile
├── README.md
├── README_EN.md
├── i386-bootloader.ld
├── i386-kernel.ld
├── i386-module.ld
├── src
├── bootloader
│ ├── stage1
│ │ ├── include
│ │ │ ├── disk.asm
│ │ │ ├── gdt.asm
│ │ │ ├── hata.asm
│ │ │ └── protected_mode.asm
│ │ └── stage1.asm
│ └── stage2
│ │ ├── bootloader.cpp
│ │ ├── include
│ │ ├── ata.h
│ │ ├── fat12.h
│ │ ├── fs.h
│ │ ├── initialize.h
│ │ ├── ports.h
│ │ ├── stdio.h
│ │ └── string.h
│ │ └── stage2.asm
├── kernel
│ ├── include
│ │ ├── ata.h
│ │ ├── dt.h
│ │ ├── fat12.h
│ │ ├── fs.h
│ │ ├── initialize.h
│ │ ├── isr.h
│ │ ├── keyboard.h
│ │ ├── math.h
│ │ ├── memory.h
│ │ ├── mouse.h
│ │ ├── pic.h
│ │ ├── ports.h
│ │ ├── rtc.h
│ │ ├── sse.h
│ │ ├── stdio.h
│ │ ├── string.h
│ │ ├── system.h
│ │ ├── timer.h
│ │ └── vga.h
│ ├── kernel.asm
│ ├── kernel.cpp
│ ├── modules.asm
│ └── modules.cpp
└── shell
│ └── shell.c
└── tools
└── toolchain
/.gitignore:
--------------------------------------------------------------------------------
1 | bin/
2 | *.o
3 | *.out
4 | i386-bin/
5 | Mkfile.old
6 | .vscode/
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | #elfgcc=tools/i386-elf/bin/i386-elf-gcc # installation from toolchain dir
2 | #elfld=tools/i386-elf/bin/i386-elf-ld
3 |
4 | elfgcc=i386-elf-gcc # installation from `yay -S i386-elf-gcc`
5 | elfld=i386-elf-ld
6 |
7 | BUILD_DIR=i386-bin
8 |
9 | .PHONY: build
10 | build: $(clean)
11 | export PATH=$PATH:/usr/local/i386elfgcc/bin
12 | mkdir -pv $(BUILD_DIR)
13 | @printf "\n\e[0;32m==> $(BUILD_DIR) e derleniyor..."
14 | @nasm "src/bootloader/stage1/stage1.asm" -f bin -o "$(BUILD_DIR)/stage1.bin"
15 | @nasm "src/bootloader/stage2/stage2.asm" -f elf -o "$(BUILD_DIR)/stage2.o"
16 | @nasm "src/kernel/kernel.asm" -f elf -o "$(BUILD_DIR)/kernel_asm.o"
17 | @nasm "src/kernel/modules.asm" -f elf -o "$(BUILD_DIR)/moduleAsm.o"
18 | $(elfgcc) -ffreestanding -m32 -g -c -Wno-write-strings "src/bootloader/stage2/bootloader.cpp" -o "$(BUILD_DIR)/bootloader.o"
19 | $(elfgcc) -ffreestanding -m32 -g -c -Wno-write-strings "src/kernel/kernel.cpp" -o "$(BUILD_DIR)/kernel_c.o"
20 | $(elfgcc) -ffreestanding -m32 -g -c -Wno-write-strings "src/kernel/modules.cpp" -o "$(BUILD_DIR)/modulesC.o"
21 | $(elfld) -o "$(BUILD_DIR)/bootloader.bin" -T i386-bootloader.ld "$(BUILD_DIR)/stage2.o" "$(BUILD_DIR)/bootloader.o" --oformat binary
22 | $(elfld) -o "$(BUILD_DIR)/kernel.bin" -T i386-kernel.ld "$(BUILD_DIR)/kernel_asm.o" "$(BUILD_DIR)/kernel_c.o" --oformat binary
23 | $(elfld) -o "$(BUILD_DIR)/modules.bin" -T i386-module.ld "$(BUILD_DIR)/moduleAsm.o" "$(BUILD_DIR)/modulesC.o" --oformat binary
24 | cat "$(BUILD_DIR)/stage1.bin" "$(BUILD_DIR)/bootloader.bin" > "$(BUILD_DIR)/boot.bin"
25 | dd if=/dev/zero of=$(BUILD_DIR)/disk.bin bs=512 count=2880
26 | mkfs.fat -v -F 12 -n "DISK" $(BUILD_DIR)/disk.bin #kernel and module outputs are on disk
27 | dd if=$(BUILD_DIR)/boot.bin of=$(BUILD_DIR)/disk.bin conv=notrunc
28 | @mcopy -v -i $(BUILD_DIR)/disk.bin $(BUILD_DIR)/kernel.bin "::kernel.bin"
29 | @mcopy -v -i $(BUILD_DIR)/disk.bin $(BUILD_DIR)/modules.bin "::modules.bin"
30 |
31 | .PHONY: help
32 | help:
33 | @printf "clean: derlenmişi temizler\nbuild: derler\nrun: qemu da açar\noutput: $(BUILD_DIR)"
34 |
35 | .PHONY: clean
36 | clean:
37 | rm -rvf $(BUILD_DIR)/*
38 | .PHONY: setup
39 | setup:
40 | ./tools/toolchain
41 |
42 | .PHONY: run
43 | run:
44 | qemu-system-i386 -m 256M -device VGA,vgamem_mb=128 $(BUILD_DIR)/disk.bin
45 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # vimixOS
2 | i386 mimarili minimal işletim sistemi. (gerçi işletim sistemi denilebilirse)
3 |
[for english version](https://github.com/19atlas/vimixos/blob/main/README_EN.md)
4 | ## Derlemek için,
5 | ### küçük not: Fedora, Gentoo, Debian tabanlı ve Arch tabanlı sistemlerde denenmiştir.
6 | - `make setup` komutuyla derleyici kurulacaktır.
7 | - kurulduğunda `make clean build` komutunu çalıştırın.
8 |
9 | ## Sıra çalıştırmada!
10 | - öncelikle gereken paketleri kurmalısınız
`nasm`
`qemu-full`
`qemu-headless-arch-extra`
paketleri gibi [daha fazla bilgi için](https://github.com/nanobyte-dev/nanobyte_os#building)
11 | - `make run` komutu ile qemuyu açın.
12 |
13 | ## Vimixos hedefleri:
14 | - [ ] stabilite (cidden zor)
15 | - [ ] uygun bir shell
16 | - [ ] çok uzun zaman sonra uygulama geliştirme (DEler yazma programları vs.)
17 | - [ ] internet
18 | - [ ] akıllı saatlere portlama (imkansız)
19 |
20 | ## eklenmesi gerekenler:
21 | - [ ] FAT32 destegi
22 | - [ ] C++ desteği
23 | - [ ] UNIX-like
24 | - [ ] SHELL
25 |
26 | ## Vimixos dizinleri
27 | - `i386-bin` vimixos derlendikten sonra çıktıyı buraya atar
28 | - `src` vimixos kaynağı
29 | - `src/kernel` viniz kerneli burda bulunur
30 | - `src/bootloader` vimixos bootloader
31 | - `tools/toolchain` çalıştırılabilir dosyası vimixos'a uygun binutils ve derleyiciyi indirir.
32 |
33 | BU PROJE GPL LİSANSI İLE LİSANSLANMIŞTIR [daha fazla bilgi için](https://www.gnu.org/licenses/rms-why-gplv3.html)
34 |
35 |
36 | 
37 |
--------------------------------------------------------------------------------
/README_EN.md:
--------------------------------------------------------------------------------
1 | # vimixOS
2 | Minimal operating system with i386 architecture. (if it can even be called an operating system)
3 | ## For compiling
4 | ### footnote: tested in: Fedora, Gentoo, Debian and Arch based distros
5 | - `make setup` The toolchains will be compiled with the command
6 | - when finished run `make clean build`!
7 |
8 | ## Emulation (QEMU)
9 | - You should install required packages, such as
`qemu-full`
`qemu-headless-arch-extra` packages [for more information](https://github.com/nanobyte-dev/nanobyte_os#building)
10 | - run `make run` for qemu
11 |
12 | ## Vimixos goals:
13 | - [ ] stability (serius)
14 | - [ ] shell (but minimal for some reasons)
15 | - [ ] UI (ex. GUI)
16 | - [ ] internet
17 | - [ ] porting to smartwatch (impossible)
18 |
19 | ## Features to be added
20 | - [ ] FAT32 support
21 | - [ ] file system (from scratch)
22 | - [ ] C++ and compiler support
23 | - [ ] UNIX-like
24 | - [ ] SHELL
25 |
26 | ## Vimixos file locations
27 | - `i386-bin` vimixos after compiled files
28 | - `src/kernel` viniz kernel
29 | - `src/bootloader` vimixos bootloader
30 | - `tools/toolchain` file for vimixos'a suitable binutils and cross-compiler.
31 |
32 | this project under the GPL LICENSE [see](https://www.gnu.org/licenses/rms-why-gplv3.html)
33 |
34 |
35 | 
--------------------------------------------------------------------------------
/i386-bootloader.ld:
--------------------------------------------------------------------------------
1 | ENTRY(bootloader)
2 | OUTPUT_FORMAT("binary")
3 | phys = 0x00001000;
4 |
5 | SECTIONS
6 | {
7 | . = phys;
8 |
9 | .text : { __text_start = .; *(.text) }
10 | .data : { __data_start = .; *(.data) }
11 | .rodata : { __rodata_start = .; *(.rodata) }
12 | .bss : { __bss_start = .; *(.bss) }
13 |
14 | __end = .;
15 | }
--------------------------------------------------------------------------------
/i386-kernel.ld:
--------------------------------------------------------------------------------
1 | ENTRY(main)
2 | OUTPUT_FORMAT("binary")
3 | phys = 0x0100000;
4 |
5 | SECTIONS
6 | {
7 | . = phys;
8 |
9 | .text : { __text_start = .; *(.text) }
10 | .data : { __data_start = .; *(.data) }
11 | .rodata : { __rodata_start = .; *(.rodata) }
12 | .bss : { __bss_start = .; *(.bss) }
13 |
14 | __end = .;
15 | }
--------------------------------------------------------------------------------
/i386-module.ld:
--------------------------------------------------------------------------------
1 | ENTRY(main)
2 | OUTPUT_FORMAT("binary")
3 | phys = 0x150000;
4 |
5 | SECTIONS
6 | {
7 | . = phys;
8 |
9 | .text : { __text_start = .; *(.text) }
10 | .data : { __data_start = .; *(.data) }
11 | .rodata : { __rodata_start = .; *(.rodata) }
12 | .bss : { __bss_start = .; *(.bss) }
13 |
14 | __end = .;
15 | }
--------------------------------------------------------------------------------
/src/bootloader/stage1/include/disk.asm:
--------------------------------------------------------------------------------
1 | ;function of reading from disk.
2 | disk_read:
3 | ;read data from the disk with the given parameters at the specified memory address.
4 | mov ah, 0x02 ;function for reading from disk.
5 | mov ch, 0x00 ;disk cylinder number.
6 | mov dh, 0x00 ;disk head number.
7 | push 0x0000 ;es contains the memory segment.
8 | pop es
9 | ;calls switch 0x13 to read from disk with given parameters.
10 | int 0x13
11 | ;on a successful read the ah register equals zero.
12 | cmp ah, 0x00
13 | ;if not, jump to the disk_read_error label.
14 | jne disk_read_error
15 | ;returns to where the disk_read function was called.
16 | ret
17 |
18 | ;if unsuccessful print error
19 | disk_read_error:
20 | call hataYaz
21 | hlt
--------------------------------------------------------------------------------
/src/bootloader/stage1/include/gdt.asm:
--------------------------------------------------------------------------------
1 | ;https://wiki.osdev.org/Global_Descriptor_Table
2 | gdt_start:
3 |
4 | gdt_null:
5 |
6 | DD 0x00000000
7 | DD 0x00000000
8 |
9 | gdt_code:
10 |
11 | DW 0xFFFF
12 | DW 0x0000
13 | DB 0x00
14 | DB 0x9A
15 | DB 0xCF
16 | DB 0x00
17 |
18 | gdt_data:
19 |
20 | DW 0xFFFF
21 | DW 0x0000
22 | DB 0x00
23 | DB 0x92
24 | DB 0xCF
25 | DB 0x00
26 |
27 | gdt_end:
28 |
29 | gdt_descriptor:
30 |
31 | DW gdt_end - gdt_start - 1
32 | DD gdt_start
33 |
34 | CODE_SEG EQU gdt_code - gdt_start
35 | DATA_SEG EQU gdt_data - gdt_start
--------------------------------------------------------------------------------
/src/bootloader/stage1/include/hata.asm:
--------------------------------------------------------------------------------
1 | hataYaz:
2 | mov ebx, 0xb8000 ;Video Memory
3 | mov si, HataMsg ; load the address of the message into si
4 | jmp .print
5 | .print:
6 | mov ah, 0x0e ; set the video function to write a character with attribute
7 | mov bh, 0x00 ; page number
8 | mov bl, 0x07 ; attribute (white text on black background)
9 | .next_char:
10 | lodsb ; load the next character from si al = next chracter
11 | cmp al, 0 ; check if we have reached the end of the string
12 | je .finish ; if so, jump to finish
13 | int 0x10 ; otherwise, write the character to the screen
14 | jmp .next_char
15 | .finish:
16 | hlt
17 | jmp $
18 |
19 | HataMsg: db "VIMIZ DISK HATASI",0x0D, 0x0a,"disk okunamiyor...", 0
--------------------------------------------------------------------------------
/src/bootloader/stage1/include/protected_mode.asm:
--------------------------------------------------------------------------------
1 | ;function to enter protected mode.
2 | enter_protected:
3 | cli ;disable the switches.
4 | lgdt[gdt_descriptor] ;loads the global description table.
5 | ;enter protected mode.
6 | mov eax, cr0
7 | or eax, 0x00000001
8 | mov cr0, eax
9 | ret ;returns to where the function was called.
--------------------------------------------------------------------------------
/src/bootloader/stage1/stage1.asm:
--------------------------------------------------------------------------------
1 | [ORG 0x7C00]
2 | [BITS 16]
3 |
4 | ;the boot manager memory address.
5 | BOOTLOADER_ADDRESS EQU 0x1000
6 |
7 | ;jump short to the _bootloader
8 | jmp short _bootloader
9 | nop
10 |
11 | ;SIEB parameter block.
12 | BPB_OEM: db 'VIMIZ OS'
13 | BPB_BYTES_PER_SECTOR: dw 0x0200
14 | BPB_SECTORS_PER_CLUSTER: db 0x01
15 | BPB_RESERVED_SECTORS: dw 0x000A
16 | BPB_FAT_NUMBER: db 0x02
17 | BPB_DIR_ENTRIES_NUMBER: dw 0x00E0
18 | BPB_TOTAL_SECTORS: dw 0x0B40
19 | BPB_MEDIA_DESCRIPTOR_TYPE: db 0xF0
20 | BPB_SECTORS_PER_FAT: dw 0x0009
21 | BPB_SECTORS_PER_TRACK: dw 0x0012
22 | BPB_HEAD_NUMBER: dw 0x0002
23 | BPB_HIDDEN_SECTORS: dd 0x00000000
24 | BPB_LARGE_SECTOR_NUMBER: dd 0x00000000
25 |
26 | ;extended boot track.
27 | EBR_DRIVE_NUMBER: db 0x00
28 | EBR_RESERVED: db 0x00
29 | EBR_SIGNATURE: db 0x29
30 | EBR_VOLUME_ID: db 0x11, 0x11, 0x11, 0x11
31 | EBR_VOLUME_LABEL: db 'DISK '
32 | EBR_SYSTEM_ID: db 'FAT12 '
33 |
34 | _bootloader:
35 |
36 | ;move the boot disk number to EBR_DRIVE_NUMBER
37 | mov [EBR_DRIVE_NUMBER], dl
38 |
39 | ;clear the screen by resetting the graphics mode.
40 | mov ah, 0x00 ;function for switching the graphics mode.
41 | mov al, 0x03 ;graphics mode 0x03 text 80x25 characters.
42 | int 0x10 ;call the 0x10 switch to reset the graphics mode.
43 |
44 | ;loads the next sector at memory address 0x7E00.
45 | ;sets the parameters for the read from disk function.
46 | mov al, 0x01 ;number of sectors to read.
47 | mov bx, 0x7E00 ;memory address where to load the data.
48 | mov cl, 0x02 ;sector number to start from.
49 |
50 | call disk_read ;calls the read from disk function.
51 |
52 | jmp _bootloader16 ;jump to the _bootloader16
53 |
54 | %INCLUDE"src/bootloader/stage1/include/disk.asm"
55 | %INCLUDE"src/bootloader/stage1/include/gdt.asm"
56 | %INCLUDE"src/bootloader/stage1/include/protected_mode.asm"
57 | %INCLUDE"src/bootloader/stage1/include/hata.asm" ;for error screen
58 |
59 | ;fill the rest of the sector excluding the last two octets with 0s.
60 | TIMES 510-($-$$) DB 0x00
61 | ;the last two octets must be 0x55 and 0xAA for the disk to be bootable.
62 | DW 0xAA55
63 |
64 | _bootloader16:
65 | ;sets segment registers.
66 | cli ;disable the switches.
67 | mov ax, 0x0000
68 | mov ds, ax
69 | mov es, ax
70 | mov ss, ax
71 | mov sp, 0x7C00
72 | sti ;re-enable the switches.
73 |
74 | ;loads the boot manager at the memory address specified above.
75 | ;sets the parameters for the read from disk function.
76 | mov al, 0x20 ;number of sectors to read.
77 | mov bx, BOOTLOADER_ADDRESS ;memory address where to load the data.
78 | mov cl, 0x03 ;sector number to start from.
79 |
80 | call disk_read ;calls the read from disk function.
81 |
82 | call enter_protected ;enter protected mode.
83 |
84 | jmp CODE_SEG:_bootloader32 ;jump to the _bootloader32 label.
85 |
86 | [BITS 32]
87 | _bootloader32:
88 | mov ax, DATA_SEG
89 | mov ds, ax
90 | mov es, ax
91 | mov fs, ax
92 | mov gs, ax
93 | mov ss, ax
94 |
95 | ;enable line A20 to use all available memory.
96 | in al, 0x92
97 | or al, 0x02
98 | out 0x92, al
99 |
100 | ;sets up the boot manager and operating system stack.
101 | mov ebp, 0x10000
102 | mov esp, ebp
103 |
104 | ;jump to boot manager memory address.
105 | jmp BOOTLOADER_ADDRESS
106 |
107 | ;fill the rest of the sector with 0.
108 | TIMES 1024-($-$$) DB 0x00
109 |
--------------------------------------------------------------------------------
/src/bootloader/stage2/bootloader.cpp:
--------------------------------------------------------------------------------
1 | #include"include/initialize.h"
2 | #include"include/stdio.h"
3 | #include"include/ata.h"
4 | #include"include/fs.h"
5 | #include"include/fat12.h"
6 |
7 | //bootloader main global function.
8 | extern "C" void bootloader() {
9 | //initialize the components.
10 | initialize();
11 | //read the data kernel.bin ie the core of the operating system.
12 | fread("KERNEL BIN", 0x0100000);
13 | //jump to the address where the kernel was loaded and run it.
14 | void(*kernel)(void) = (void(*)())0x0100000;
15 | kernel();
16 | return;
17 | }
--------------------------------------------------------------------------------
/src/bootloader/stage2/include/ata.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include"ports.h"
4 | #include
5 |
6 | #define STATUS_BUSY 0x80
7 | #define STATUS_READY 0x40
8 | #define STATUS_DRQ 0x08
9 | #define STATUS_DF 0x20
10 | #define STATUS_ERR 0x01
11 |
12 | static void ATA_wait_BSY() {
13 | while(inb(0x01F7) & STATUS_BUSY);
14 | }
15 |
16 | static void ATA_wait_DRQ() {
17 | while(!inb(0x01F7) & STATUS_READY);
18 | }
19 |
20 | //disk reading function.
21 | void read_sectors(uint32_t address, uint32_t lba, uint8_t sector_count) {
22 | //wait for the disk to be ready and free to read.
23 | ATA_wait_BSY();
24 | //set the reading parameters.
25 | outb(0x01F6, 0xE0 | ((lba >> 0x18) & 0x0F));
26 | outb(0x01F2, sector_count);
27 | outb(0x01F3, (uint8_t)lba);
28 | outb(0x01F4, (uint8_t)(lba >> 8));
29 | outb(0x01F5, (uint8_t)(lba >> 16));
30 | //sends the read signal.
31 | outb(0x01F7, 0x20);
32 | uint16_t* target = (uint16_t*)address;
33 | for(uint32_t i = 0x00; i < sector_count; i++) {
34 | ATA_wait_BSY();
35 | ATA_wait_DRQ();
36 | for(uint32_t j = 0x00; j < 0x0100; j++)
37 | //copy data to MAC memory.
38 | target[j] = inw(0x01F0);
39 | target += 0x0100;
40 | }
41 | return;
42 | }
43 |
44 | //disk writing
45 | void write_sectors(uint32_t lba, uint8_t sector_count, uint32_t* bytes) {
46 | //wait for the disk to be ready and free to read.
47 | ATA_wait_BSY();
48 | //set the reading parameters.
49 | outb(0x01F6, 0xE0 | ((lba >> 0x18) & 0x0F));
50 | outb(0x01F2, sector_count);
51 | outb(0x01F3, (uint8_t)lba);
52 | outb(0x01F4, (uint8_t)(lba >> 8));
53 | outb(0x01F5, (uint8_t)(lba >> 16));
54 | //sends write signal.
55 | outb(0x01F7, 0x30);
56 | for(uint32_t i = 0x00; i < sector_count; i++) {
57 | ATA_wait_BSY();
58 | ATA_wait_DRQ();
59 | for(uint32_t j = 0x00; j < 0x0100; j++)
60 | //copy the data to the storage device.
61 | outd(0x01F0, bytes[i]);
62 | }
63 | return;
64 | }
65 |
--------------------------------------------------------------------------------
/src/bootloader/stage2/include/fat12.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include"fs.h"
4 | #include
5 | #include
6 |
7 | //data entry structure.
8 | struct file_entry {
9 | //data name.
10 | uint8_t name[11];
11 | //attributes.
12 | uint8_t attributes;
13 | //reserved.
14 | uint8_t reserved;
15 | //creation date.
16 | uint8_t created_time_tenths;
17 | uint16_t created_time;
18 | uint16_t created_date;
19 | //last access date.
20 | uint16_t accessed_time;
21 | //first group upper part.
22 | uint16_t first_cluster_high;
23 | //date of last modification.
24 | uint16_t modified_time;
25 | uint16_t modified_date;
26 | //lower first group.
27 | uint16_t first_cluster_low;
28 | //data size.
29 | uint32_t size;
30 | } __attribute((packed));
31 |
32 | //reads data from disk to the specified memory address.
33 | bool fread(const char* filename, uint32_t address) {
34 | file_entry* file;
35 | char* mem = (char*)0x30000;
36 | while ((char*)mem < (char*)0x50000) {
37 | if(compare_strings(filename, mem)==true) {
38 | file = (file_entry*)mem;
39 | break;
40 | }
41 | mem+=32;
42 | }
43 | //if the counter has arrived at the address 0x00050000 it means that the entry has not been found.
44 | if((uint8_t*)mem == (uint8_t*)0x00050000)
45 | return false;
46 | //calculates the block of logical address.
47 | uint32_t lba = ((bpb->BPB_RESERVED_SECTORS + bpb->BPB_FAT_NUMBER * bpb->BPB_SECTORS_PER_FAT + (bpb->BPB_DIR_ENTRIES_NUMBER * 32 + bpb-> BPB_BYTES_PER_SECTOR -1) / bpb->BPB_BYTES_PER_SECTOR)) + (file->first_cluster_low - 2) * bpb-> BPB_SECTORS_PER_CLUSTER;
48 | //read the sectors containing the requested data.
49 | read_sectors(address, lba, (file->size / bpb->BPB_BYTES_PER_SECTOR + 1));
50 | return true;
51 | }
--------------------------------------------------------------------------------
/src/bootloader/stage2/include/fs.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include"stdio.h"
4 | #include"string.h"
5 | #include"ata.h"
6 | #include
7 |
8 | //structure of the parameter block of the SIEB.
9 | struct bios_parameter_block {
10 | //short jump and nop.
11 | uint8_t NOP[0x03];
12 | //codice del produttore di apparecchiature originali.
13 | uint8_t BPB_OEM[0x08];
14 | //numero di octeti per settore.
15 | uint16_t BPB_BYTES_PER_SECTOR;
16 | //numero di settori per gruppo.
17 | uint8_t BPB_SECTORS_PER_CLUSTER;
18 | //numero di settori riservati.
19 | uint16_t BPB_RESERVED_SECTORS;
20 | //numero di tavole di allocazione dei dati.
21 | uint8_t BPB_FAT_NUMBER;
22 | //numero di entrate nel percorso radice.
23 | uint16_t BPB_DIR_ENTRIES_NUMBER;
24 | //numero di settori totale.
25 | uint16_t BPB_TOTAL_SECTORS;
26 | //codice del tipo di dispositivo di memoria.
27 | uint8_t BPB_MEDIA_DESCRIPTOR_TYPE;
28 | //numero di settori per tavola di allocazione dei dati.
29 | uint16_t BPB_SECTORS_PER_FAT;
30 | //numero di settori per traccia.
31 | uint16_t BPB_SECTORS_PER_TRACK;
32 | //numero di testine.
33 | uint16_t BPB_HEAD_NUMBER;
34 | //numero di settori nascosti.
35 | uint32_t BPB_HIDDEN_SECTORS;
36 | //numero di settori larghi.
37 | uint32_t BPB_LARGE_SECTOR_NUMBER;
38 | } __attribute((packed));
39 |
40 | //struttura della traccia d'avvio estesa.
41 | struct extended_boot_record {
42 | //numero di identificazione del dispositivo di memoria.
43 | uint8_t EBR_DRIVE_NUMBER;
44 | //riservato.
45 | uint8_t EBR_RESERVED;
46 | //firma.
47 | uint8_t EBR_SIGNATURE;
48 | //numero di identificazione del volume.
49 | uint32_t EBR_VOLUME_ID;
50 | //nome del volume.
51 | uint8_t EBR_VOLUME_LABEL[0x0B];
52 | //stringa di identificazione del tipo di struttura del disco.
53 | uint8_t EBR_SYSTEM_ID;
54 | } __attribute((packed));
55 |
56 | //dichiara un puntatore alla struttura del blocco dei parametri del SIEB.
57 | bios_parameter_block* bpb;
58 | //dichiara un puntatore alla struttura della traccia d'avvio estesa.
59 | extended_boot_record* ebr;
60 |
61 | //funzione della lettura della tavola di allocazione dei dati.
62 | void read_fat() {
63 | //leggi la tavola di allocazione dei dati.
64 | read_sectors(0x20000, bpb->BPB_RESERVED_SECTORS, bpb->BPB_FAT_NUMBER * bpb->BPB_SECTORS_PER_FAT);
65 | return;
66 | }
67 |
68 | //funzione della lettura del percorso radice.
69 | void read_root_dir() {
70 | //leggi il percorso radice.
71 | read_sectors(0x30000, bpb->BPB_RESERVED_SECTORS + bpb->BPB_FAT_NUMBER * bpb->BPB_SECTORS_PER_FAT,
72 | (bpb->BPB_DIR_ENTRIES_NUMBER * 32 + bpb-> BPB_BYTES_PER_SECTOR -1) / bpb->BPB_BYTES_PER_SECTOR);
73 | return;
74 | }
75 |
76 | //funzione di inizializzazione della struttura del disco.
77 | void initialize_fs() {
78 | bpb = (bios_parameter_block*)0x00007C00;
79 | ebr = (extended_boot_record*)0x00007C24;
80 | read_fat();
81 | read_root_dir();
82 | return;
83 | }
--------------------------------------------------------------------------------
/src/bootloader/stage2/include/initialize.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include"stdio.h"
4 | #include"fs.h"
5 |
6 | //init
7 | void initialize() {
8 | initialize_fs();
9 | return;
10 | }
--------------------------------------------------------------------------------
/src/bootloader/stage2/include/ports.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | //output function of an octet to an input and output port.
6 | static inline void outb(uint16_t port, uint8_t value) {
7 | asm("outb %0, %1" : : "a"(value), "Nd"(port));
8 | return;
9 | }
10 |
11 | //input function of an octet to an input and output port.
12 | static inline uint8_t inb(uint16_t port) {
13 | uint8_t value;
14 | asm("inb %1, %0" : "=a"(value) : "Nd"(port));
15 | return value;
16 | }
17 |
18 | //output function of two octets to one input and output port.
19 | static inline void outw(uint16_t port, uint16_t value) {
20 | asm("out %%ax, %%dx" : : "a"(value), "d"(port));
21 | return;
22 | }
23 |
24 | //input function of two octets to an input and output port.
25 | static inline uint16_t inw(uint16_t port) {
26 | uint16_t value;
27 | asm("in %%dx, %%ax" : "=a"(value) : "d"(port));
28 | return value;
29 | }
30 |
31 | //output function of four octets to one input and output port.
32 | static inline void outd(uint32_t port, uint32_t value) {
33 | asm("outl %%eax, %%dx" : : "a"(value), "d"(port));
34 | }
35 |
36 | //input function of four octets to an input and output port.
37 | static inline uint32_t ind(uint32_t port) {
38 | uint32_t value;
39 | asm("inl %%dx, %%eax" : "=a"(value) : "d"(port));
40 | return value;
41 | }
--------------------------------------------------------------------------------
/src/bootloader/stage2/include/stdio.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include"string.h"
4 | #include"ports.h"
5 | #include
6 | #include
7 |
8 | //imleç konumu.
9 | uint16_t x_pos = 0x0000, y_pos = 0x0000;
10 | //metin rengi.
11 | uint8_t color = 0x07;
12 | //metin arka plan rengi.
13 | uint8_t bg_color = 0x00;
14 |
15 | //metin modu bellek adresi 0x03.
16 | uint32_t* video_memory = (uint32_t*)0x000B8000;
17 |
18 | //metnin rengini ayarlayın.
19 | void set_color(uint8_t new_color) {
20 | color = new_color;
21 | return;
22 | }
23 |
24 | //metnin arka plan rengini ayarlar.
25 | void set_bg_color(uint8_t new_color) {
26 | bg_color = new_color;
27 | return;
28 | }
29 |
30 | //metni bir satır aşağı kaydırır.
31 | void scroll() {
32 | uint8_t attribute = (0x00 << 0x04) | (0x0F & 0x0F);
33 | uint16_t blank = 0x0020 | (attribute << 0x0008);
34 | if(y_pos >= 0x0019) {
35 | for(uint32_t i = 0x00000000 * 0x00000050; i < 0x00000018 * 0x00000050; i++)
36 | video_memory[i] = video_memory[i + 0x00000050];
37 | for(uint32_t i = 0x00000018 * 0x00000050; i < 0x00000019 * 0x00000050; i++)
38 | video_memory[i] = blank;
39 | y_pos = 0x0018;
40 | }
41 | return;
42 | }
43 |
44 | //imlecin ekrandaki konumunu günceller.
45 | void update_cursor_pos(uint16_t x, uint16_t y) {
46 | uint16_t cursor_pos = y * 0x0050 + x;
47 | outb(0x03D4, 0x0F);
48 | outb(0x03D5, (uint8_t)(cursor_pos & 0xFF));
49 | outb(0x03D4, 0x0E);
50 | outb(0x03D5, (uint8_t)((cursor_pos >> 0x08) & 0xFF));
51 | return;
52 | }
53 |
54 | //imleç konumunu ilerleterek ekrana bir karakter yazar.
55 | void putc(unsigned char c){
56 | uint16_t attrib = (0 << 4) | (color & 0x0F);
57 | volatile uint16_t* where;
58 | where = (volatile uint16_t *)0xB8000 + (y_pos * 80 + x_pos);
59 | *where = c | (attrib << 8);
60 | if(++x_pos >= 80){
61 | x_pos = 0;
62 | y_pos++;
63 | }
64 | update_cursor_pos(x_pos, y_pos);
65 | if(y_pos >= 25) {
66 | x_pos = 0;
67 | scroll();
68 | }
69 | return;
70 | }
71 |
72 | //imleci geri hareket ettirerek ekrandaki bir karakteri kaldırır.
73 | void putcback(){
74 | uint16_t attrib = (0 << 4) | (color & 0x0F);
75 | volatile uint16_t * where;
76 | x_pos--;
77 | if(x_pos < 0) {
78 | x_pos = 79;
79 | y_pos--;
80 | }
81 | where = (volatile uint16_t *)0xB8000 + (y_pos * 80 + x_pos);
82 | *where = ' ' | (attrib << 8);
83 | update_cursor_pos(x_pos, y_pos);
84 | if(y_pos >= 25) {
85 | x_pos = 0;
86 | scroll();
87 | }
88 | }
89 |
90 | //imleç konumunu ilerleterek ekrana bir dizi yazar.
91 | void puts(char* string){
92 | uint16_t i;
93 | while(*string){
94 | switch(*string){
95 | case 0x0A:
96 | x_pos = 0x0000;
97 | y_pos++;
98 | *string++;
99 | scroll();
100 | break;
101 | case 0x09:
102 | for(i = 0x0000; i <= 0x0008; i++) {
103 | putc(' ');
104 | }
105 | *string++;
106 | break;
107 | default:
108 | putc(*string);
109 | *string++;
110 | break;
111 | }
112 | }
113 | update_cursor_pos(x_pos, y_pos);
114 | return;
115 | }
116 |
117 | //imleç konumunu ilerleterek ekrana zengin bir dize yazar.
118 | void printf(char* format, ...) {
119 | va_list ap;
120 | va_start(ap, format);
121 | char* pointer;
122 | for (pointer = format; *pointer != 0x00; pointer++) {
123 | if (*pointer == '%') {
124 | ++pointer;
125 | switch (*pointer) {
126 | case 0x63:
127 | putc(va_arg(ap, int));
128 | break;
129 | case 0x73:
130 | puts(va_arg(ap, char*));
131 | break;
132 | case 0x64:
133 | puts(int_to_string(va_arg(ap, int), 10));
134 | break;
135 | case 0x78:
136 | puts(int_to_string(va_arg(ap, uint32_t), 16));
137 | break;
138 | }
139 | } else {
140 | putc(*pointer);
141 | }
142 | }
143 | return;
144 | }
--------------------------------------------------------------------------------
/src/bootloader/stage2/include/string.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 |
6 | //bir sayıyı bir diziye dönüştürür.
7 | char* int_to_string(unsigned int num, int base) {
8 | static char repr[]= "0123456789ABCDEF";
9 | static char buffer[50];
10 | char *ptr;
11 |
12 | ptr = &buffer[49];
13 | *ptr = '\0';
14 |
15 | do {
16 | *--ptr = repr[num%base];
17 | num /= base;
18 | }while(num != 0);
19 |
20 | return(ptr);
21 | }
22 |
23 | //iki diziyi karşılaştırın.
24 | bool compare_strings(const char* string1, const char* string2) {
25 | while(*string1!=0) {
26 | if(*string1 != *string2)
27 | return false;
28 | string1++;
29 | string2++;
30 | }
31 | return true;
32 | }
--------------------------------------------------------------------------------
/src/bootloader/stage2/stage2.asm:
--------------------------------------------------------------------------------
1 | [BITS 32]
2 | ;import the bootloader function from bootloader.cpp.
3 | [EXTERN bootloader]
4 | ;call the bootloader function.
5 | call bootloader
6 | ;creates an infinite loop by jumping to the current memory address.
7 | jmp $
--------------------------------------------------------------------------------
/src/kernel/include/ata.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include"ports.h"
4 | #include
5 |
6 | #define STATUS_BUSY 0x80
7 | #define STATUS_READY 0x40
8 | #define STATUS_DRQ 0x08
9 | #define STATUS_DF 0x20
10 | #define STATUS_ERR 0x01
11 |
12 | static void ATA_wait_BSY() {
13 | while(inb(0x01F7) & STATUS_BUSY);
14 | }
15 |
16 | static void ATA_wait_DRQ() {
17 | while(!inb(0x01F7) & STATUS_READY);
18 | }
19 |
20 | //disk reading function.
21 | void read_sectors(uint32_t address, uint32_t lba, uint8_t sector_count) {
22 | //wait for the disk to be ready and free to read.
23 | ATA_wait_BSY();
24 | //set the reading parameters.
25 | outb(0x01F6, 0xE0 | ((lba >> 0x18) & 0x0F));
26 | outb(0x01F2, sector_count);
27 | outb(0x01F3, (uint8_t)lba);
28 | outb(0x01F4, (uint8_t)(lba >> 8));
29 | outb(0x01F5, (uint8_t)(lba >> 16));
30 | //sends the read signal.
31 | outb(0x01F7, 0x20);
32 | uint16_t* target = (uint16_t*)address;
33 | for(uint32_t i = 0x00; i < sector_count; i++) {
34 | ATA_wait_BSY();
35 | ATA_wait_DRQ();
36 | for(uint32_t j = 0x00; j < 0x0100; j++)
37 | //copy data to MAC memory.
38 | target[j] = inw(0x01F0);
39 | target += 0x0100;
40 | }
41 | return;
42 | }
43 |
44 | //disk writing function.
45 | void write_sectors(uint32_t lba, uint8_t sector_count, uint32_t* bytes) {
46 | //wait for the disk to be ready and free to read.
47 | ATA_wait_BSY();
48 | //set the reading parameters.
49 | outb(0x01F6, 0xE0 | ((lba >> 0x18) & 0x0F));
50 | outb(0x01F2, sector_count);
51 | outb(0x01F3, (uint8_t)lba);
52 | outb(0x01F4, (uint8_t)(lba >> 8));
53 | outb(0x01F5, (uint8_t)(lba >> 16));
54 | //invia il segnale di scrittura.
55 | outb(0x01F7, 0x30);
56 | for(uint32_t i = 0x00; i < sector_count; i++) {
57 | ATA_wait_BSY();
58 | ATA_wait_DRQ();
59 | for(uint32_t j = 0x00; j < 0x0100; j++)
60 | //copy the data to the storage device.
61 | outd(0x01F0, bytes[i]);
62 | }
63 | return;
64 | }
--------------------------------------------------------------------------------
/src/kernel/include/dt.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include"memory.h"
4 | #include"ports.h"
5 | #include
6 | #include
7 |
8 | //global description table entry structure.
9 | struct gdt_entry_t {
10 | uint16_t limit_low;
11 | uint16_t base_low;
12 | uint8_t base_middle;
13 | uint8_t access;
14 | uint8_t granularity;
15 | uint8_t base_high;
16 | }__attribute__((packed));
17 |
18 | //pointer structure of the global description table.
19 | struct gdt_ptr_t {
20 | uint16_t limit;
21 | uint32_t base;
22 | }__attribute__((packed));
23 |
24 | //switches description table entry structure.
25 | struct idt_entry_t {
26 | uint16_t base_low;
27 | uint16_t kernel_cs;
28 | uint8_t zero;
29 | uint8_t flags;
30 | uint16_t base_high;
31 | }__attribute__((packed));
32 |
33 | //pointer structure of the switch description table.
34 | struct idt_ptr_t {
35 | uint16_t limit;
36 | uint32_t base;
37 | }__attribute__((packed));
38 |
39 | //declaration of the global variables of the description tables.
40 | gdt_entry_t gdt_entries[5];
41 | gdt_ptr_t gdt_ptr;
42 | idt_entry_t idt_entries[256];
43 | idt_ptr_t idt_ptr;
44 |
45 | //global description table unload function.
46 | extern "C" void gdt_flush(uint32_t);
47 |
48 | //function of setting the gates of the global description table.
49 | static void gdt_set_gate(int num, uint32_t base, uint32_t limit, uint8_t access, uint8_t gran){
50 | gdt_entries[num].base_low = (base & 0xFFFF);
51 | gdt_entries[num].base_middle = (base >> 16) & 0xFF;
52 | gdt_entries[num].base_high = (base >> 24) & 0xFF;
53 | gdt_entries[num].limit_low = (limit & 0xFFFF);
54 | gdt_entries[num].granularity = (limit >> 16) & 0x0F;
55 | gdt_entries[num].granularity |= gran & 0xF0;
56 | gdt_entries[num].access = access;
57 | }
58 |
59 | //global description table initialization function.
60 | static void initialize_gdt(){
61 | gdt_ptr.limit = (sizeof(gdt_entry_t) * 5) - 1;
62 | gdt_ptr.base = (uint32_t)&gdt_entries;
63 | gdt_set_gate(0, 0, 0, 0, 0);
64 | gdt_set_gate(1, 0, 0xFFFFFFFF, 0x9A, 0xCF);
65 | gdt_set_gate(2, 0, 0xFFFFFFFF, 0x92, 0xCF);
66 | gdt_set_gate(3, 0, 0xFFFFFFFF, 0xFA, 0xCF);
67 | gdt_set_gate(4, 0, 0xFFFFFFFF, 0xF2, 0xCF);
68 | gdt_flush((uint32_t)&gdt_ptr);
69 | }
70 |
71 | //switch service managers.
72 | extern "C" void isr0();
73 | extern "C" void isr1();
74 | extern "C" void isr2();
75 | extern "C" void isr3();
76 | extern "C" void isr4();
77 | extern "C" void isr5();
78 | extern "C" void isr6();
79 | extern "C" void isr7();
80 | extern "C" void isr8();
81 | extern "C" void isr9();
82 | extern "C" void isr10();
83 | extern "C" void isr11();
84 | extern "C" void isr12();
85 | extern "C" void isr13();
86 | extern "C" void isr14();
87 | extern "C" void isr15();
88 | extern "C" void isr16();
89 | extern "C" void isr17();
90 | extern "C" void isr18();
91 | extern "C" void isr19();
92 | extern "C" void isr20();
93 | extern "C" void isr21();
94 | extern "C" void isr22();
95 | extern "C" void isr23();
96 | extern "C" void isr24();
97 | extern "C" void isr25();
98 | extern "C" void isr26();
99 | extern "C" void isr27();
100 | extern "C" void isr28();
101 | extern "C" void isr29();
102 | extern "C" void isr30();
103 | extern "C" void isr31();
104 | extern "C" void irq0();
105 | extern "C" void irq1();
106 | extern "C" void irq2();
107 | extern "C" void irq3();
108 | extern "C" void irq4();
109 | extern "C" void irq5();
110 | extern "C" void irq6();
111 | extern "C" void irq7();
112 | extern "C" void irq8();
113 | extern "C" void irq9();
114 | extern "C" void irq10();
115 | extern "C" void irq11();
116 | extern "C" void irq12();
117 | extern "C" void irq13();
118 | extern "C" void irq14();
119 | extern "C" void irq15();
120 |
121 | //download function of the switch description table.
122 | extern "C" void idt_flush(uint32_t);
123 |
124 | //switch description table gate setting function.
125 | static void idt_set_gate(uint8_t num, uint32_t base, uint16_t sel, uint8_t flags){
126 | idt_entries[num].base_low = base & 0xFFFF;
127 | idt_entries[num].base_high = (base >> 16) & 0xFFFF;
128 | idt_entries[num].kernel_cs = sel;
129 | idt_entries[num].zero = 0;
130 | idt_entries[num].flags = flags;
131 | }
132 |
133 | //switch description table gate setting function.
134 | static void initialize_idt(){
135 | idt_ptr.limit = sizeof(idt_entry_t) * 256 - 1;
136 | idt_ptr.base = (uint32_t)&idt_entries;
137 | memset(&idt_entries, 0, sizeof(idt_entry_t)*256);
138 | outb(0x20, 0x11);
139 | outb(0xA0, 0x11);
140 | outb(0x21, 0x20);
141 | outb(0xA1, 0x28);
142 | outb(0x21, 0x04);
143 | outb(0xA1, 0x02);
144 | outb(0x21, 0x01);
145 | outb(0xA1, 0x01);
146 | outb(0x21, 0x0);
147 | outb(0xA1, 0x0);
148 | idt_set_gate(0, (uint32_t)isr0 , 0x08, 0x8E);
149 | idt_set_gate(1, (uint32_t)isr1 , 0x08, 0x8E);
150 | idt_set_gate(2, (uint32_t)isr2 , 0x08, 0x8E);
151 | idt_set_gate(3, (uint32_t)isr3 , 0x08, 0x8E);
152 | idt_set_gate(4, (uint32_t)isr4 , 0x08, 0x8E);
153 | idt_set_gate(5, (uint32_t)isr5 , 0x08, 0x8E);
154 | idt_set_gate(6, (uint32_t)isr6 , 0x08, 0x8E);
155 | idt_set_gate(7, (uint32_t)isr7 , 0x08, 0x8E);
156 | idt_set_gate(8, (uint32_t)isr8 , 0x08, 0x8E);
157 | idt_set_gate(9, (uint32_t)isr9 , 0x08, 0x8E);
158 | idt_set_gate(10, (uint32_t)isr10, 0x08, 0x8E);
159 | idt_set_gate(11, (uint32_t)isr11, 0x08, 0x8E);
160 | idt_set_gate(12, (uint32_t)isr12, 0x08, 0x8E);
161 | idt_set_gate(13, (uint32_t)isr13, 0x08, 0x8E);
162 | idt_set_gate(14, (uint32_t)isr14, 0x08, 0x8E);
163 | idt_set_gate(15, (uint32_t)isr15, 0x08, 0x8E);
164 | idt_set_gate(16, (uint32_t)isr16, 0x08, 0x8E);
165 | idt_set_gate(17, (uint32_t)isr17, 0x08, 0x8E);
166 | idt_set_gate(18, (uint32_t)isr18, 0x08, 0x8E);
167 | idt_set_gate(19, (uint32_t)isr19, 0x08, 0x8E);
168 | idt_set_gate(20, (uint32_t)isr20, 0x08, 0x8E);
169 | idt_set_gate(21, (uint32_t)isr21, 0x08, 0x8E);
170 | idt_set_gate(22, (uint32_t)isr22, 0x08, 0x8E);
171 | idt_set_gate(23, (uint32_t)isr23, 0x08, 0x8E);
172 | idt_set_gate(24, (uint32_t)isr24, 0x08, 0x8E);
173 | idt_set_gate(25, (uint32_t)isr25, 0x08, 0x8E);
174 | idt_set_gate(26, (uint32_t)isr26, 0x08, 0x8E);
175 | idt_set_gate(27, (uint32_t)isr27, 0x08, 0x8E);
176 | idt_set_gate(28, (uint32_t)isr28, 0x08, 0x8E);
177 | idt_set_gate(29, (uint32_t)isr29, 0x08, 0x8E);
178 | idt_set_gate(30, (uint32_t)isr30, 0x08, 0x8E);
179 | idt_set_gate(31, (uint32_t)isr31, 0x08, 0x8E);
180 | idt_set_gate(32, (uint32_t)irq0, 0x08, 0x8e);
181 | idt_set_gate(33, (uint32_t)irq1, 0x08, 0x8e);
182 | idt_set_gate(34, (uint32_t)irq2, 0x08, 0x8e);
183 | idt_set_gate(35, (uint32_t)irq3, 0x08, 0x8e);
184 | idt_set_gate(36, (uint32_t)irq4, 0x08, 0x8e);
185 | idt_set_gate(37, (uint32_t)irq5, 0x08, 0x8e);
186 | idt_set_gate(38, (uint32_t)irq6, 0x08, 0x8e);
187 | idt_set_gate(39, (uint32_t)irq7, 0x08, 0x8e);
188 | idt_set_gate(40, (uint32_t)irq8, 0x08, 0x8e);
189 | idt_set_gate(41, (uint32_t)irq9, 0x08, 0x8e);
190 | idt_set_gate(42, (uint32_t)irq10, 0x08, 0x8e);
191 | idt_set_gate(43, (uint32_t)irq11, 0x08, 0x8e);
192 | idt_set_gate(44, (uint32_t)irq12, 0x08, 0x8e);
193 | idt_set_gate(45, (uint32_t)irq13, 0x08, 0x8e);
194 | idt_set_gate(46, (uint32_t)irq14, 0x08, 0x8e);
195 | idt_set_gate(47, (uint32_t)irq15, 0x08, 0x8e);
196 | idt_flush((uint32_t)&idt_ptr);
197 | }
198 |
199 | //description table initialization function.
200 | void initialize_dt(){
201 | initialize_gdt();
202 | initialize_idt();
203 | }
--------------------------------------------------------------------------------
/src/kernel/include/fat12.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include"fs.h"
4 | #include
5 | #include
6 |
7 | //data entry structure.
8 | struct file_entry {
9 | //data name.
10 | uint8_t name[11];
11 | //attributes.
12 | uint8_t attributes;
13 | //reserved.
14 | uint8_t reserved;
15 | //creation date.
16 | uint8_t created_time_tenths;
17 | uint16_t created_time;
18 | uint16_t created_date;
19 | //last access date.
20 | uint16_t accessed_time;
21 | //first group upper part.
22 | uint16_t first_cluster_high;
23 | //date of last modification.
24 | uint16_t modified_time;
25 | uint16_t modified_date;
26 | //lower first group.
27 | uint16_t first_cluster_low;
28 | //data size.
29 | uint32_t size;
30 | } __attribute((packed));
31 |
32 | //reads data from disk to the specified memory address.
33 | bool fread(const char* filename, uint32_t address) {
34 | file_entry* file;
35 | char* mem = (char*)0x30000;
36 | while ((char*)mem < (char*)0x50000) {
37 | if(compare_strings(filename, mem)==true) {
38 | file = (file_entry*)mem;
39 | break;
40 | }
41 | mem+=32;
42 | }
43 | //if the counter has arrived at the address 0x00050000 it means that the entry has not been found.
44 | if((uint8_t*)mem == (uint8_t*)0x00050000)
45 | return false;
46 | //calculates the block of logical address.
47 | uint32_t lba = ((bpb->BPB_RESERVED_SECTORS + bpb->BPB_FAT_NUMBER * bpb->BPB_SECTORS_PER_FAT + (bpb->BPB_DIR_ENTRIES_NUMBER * 32 + bpb-> BPB_BYTES_PER_SECTOR -1) / bpb->BPB_BYTES_PER_SECTOR)) + (file->first_cluster_low - 2) * bpb-> BPB_SECTORS_PER_CLUSTER;
48 | //read the sectors containing the requested data.
49 | read_sectors(address, lba, (file->size / bpb->BPB_BYTES_PER_SECTOR + 1));
50 | return true;
51 | }
--------------------------------------------------------------------------------
/src/kernel/include/fs.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include"stdio.h"
4 | #include"string.h"
5 | #include"ata.h"
6 | #include
7 |
8 | //structure of the parameter block of the SIEB.
9 | struct bios_parameter_block {
10 | uint8_t NOP[0x03]; //short jump and nop.
11 | uint8_t BPB_OEM[0x08]; //original equipment manufacturer code.
12 | uint16_t BPB_BYTES_PER_SECTOR; //number of octets per sector.
13 | uint8_t BPB_SECTORS_PER_CLUSTER; //number of sectors per group.
14 | uint16_t BPB_RESERVED_SECTORS; //number of reserved sectors.
15 | uint8_t BPB_FAT_NUMBER; //number of data allocation tables.
16 | uint16_t BPB_DIR_ENTRIES_NUMBER; //number of entries in the root path.
17 | uint16_t BPB_TOTAL_SECTORS; //total number of sectors.
18 | uint8_t BPB_MEDIA_DESCRIPTOR_TYPE; //memory device type code.
19 | uint16_t BPB_SECTORS_PER_FAT; //number of sectors per data allocation table.
20 | uint16_t BPB_SECTORS_PER_TRACK; //number of sectors per track.
21 | uint16_t BPB_HEAD_NUMBER; //number of heads.
22 | uint32_t BPB_HIDDEN_SECTORS; //number of hidden sectors.
23 | uint32_t BPB_LARGE_SECTOR_NUMBER; //number of wide sectors.
24 | } __attribute((packed));
25 |
26 | //extended boot track structure.
27 | struct extended_boot_record {
28 | uint8_t EBR_DRIVE_NUMBER;//identification number of the storage device.
29 | uint8_t EBR_RESERVED;
30 | uint8_t EBR_SIGNATURE; //signature.
31 | uint32_t EBR_VOLUME_ID; //volume identification number
32 | uint8_t EBR_VOLUME_LABEL[0x0B]; //volume name
33 | uint8_t EBR_SYSTEM_ID; //disk structure type identification string.
34 | } __attribute((packed));
35 |
36 | //declares a pointer to the structure of the SIEB's parameter block.
37 | bios_parameter_block* bpb;
38 | //declares a pointer to the extended boot trace structure.
39 | extended_boot_record* ebr;
40 |
41 | //function of reading the data allocation table.
42 | void read_fat() {
43 | //read the data allocation table.
44 | read_sectors(0x20000, bpb->BPB_RESERVED_SECTORS, bpb->BPB_FAT_NUMBER * bpb->BPB_SECTORS_PER_FAT);
45 | return;
46 | }
47 |
48 | //function of reading the root path.
49 | void read_root_dir() {
50 | //read the root path.
51 | read_sectors(0x30000, bpb->BPB_RESERVED_SECTORS + bpb->BPB_FAT_NUMBER * bpb->BPB_SECTORS_PER_FAT,
52 | (bpb->BPB_DIR_ENTRIES_NUMBER * 32 + bpb-> BPB_BYTES_PER_SECTOR -1) / bpb->BPB_BYTES_PER_SECTOR);
53 | return;
54 | }
55 |
56 | //disk structure initialization function.
57 | void initialize_fs() {
58 | bpb = (bios_parameter_block*)0x00007C00;
59 | ebr = (extended_boot_record*)0x00007C24;
60 | read_fat();
61 | read_root_dir();
62 | return;
63 | }
--------------------------------------------------------------------------------
/src/kernel/include/initialize.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include"stdio.h"
4 | #include"fs.h"
5 | #include"dt.h"
6 | #include"keyboard.h"
7 | #include"timer.h"
8 | #include"rtc.h"
9 |
10 | //inizializza le componenti del gestore d'avvio.
11 | void initialize() {
12 | initialize_fs();
13 | initialize_dt();
14 | initialize_keyboard();
15 | initialize_timer(1.1931816666);
16 | initialize_rtc();
17 | //initialize_mouse();
18 | return;
19 | }
--------------------------------------------------------------------------------
/src/kernel/include/isr.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include"stdio.h"
4 | #include"ports.h"
5 |
6 | typedef struct regs {
7 | uint32_t ds;
8 | uint32_t edi, esi, ebp, esp, ebx, edx, ecx, eax;
9 | uint32_t int_no, err_code;
10 | uint32_t eip, cs, eflags, useresp, ss;
11 | } registers_t;
12 |
13 | typedef void (*isr_t)(registers_t);
14 | void register_interrupt_handler(uint8_t n, isr_t handler);
15 |
16 | #define IRQ0 32
17 | #define IRQ1 33
18 | #define IRQ2 34
19 | #define IRQ3 35
20 | #define IRQ4 36
21 | #define IRQ5 37
22 | #define IRQ6 38
23 | #define IRQ7 39
24 | #define IRQ8 40
25 | #define IRQ9 41
26 | #define IRQ10 42
27 | #define IRQ11 43
28 | #define IRQ12 44
29 | #define IRQ13 45
30 | #define IRQ14 46
31 | #define IRQ15 47
32 |
33 | #define DIVIDE_BY_ZERO 0
34 | #define DEBUG 1
35 | #define NON_MASKABLE_INTERRUPT 2
36 | #define BREAKPOINT 3
37 | #define OVERFLOW 4
38 | #define BOUND_RANGE_EXCEEDED 5
39 | #define INVALID_OPCODE 6
40 | #define DEVICE_NOT_AVAILABLE 7
41 | #define DOUBLE_FAULT 8
42 | #define COPROCESSOR_SEGMENT_OVERRUN 9
43 | #define INVALID_TSS 10
44 | #define SEGMENT_NOT_PRESENT 11
45 | #define STACK_SEGMENT_FAULT 12
46 | #define GENERAL_PROTECTION_FAULT 13
47 | #define PAGE_FAULT 14
48 | #define RESERVED1 15
49 | #define X87FLOATING_POINT_EXCEPTION 16
50 | #define ALIGMENT_CHECK 17
51 | #define MACHINE_CHECK 18
52 | #define SIMD_FLOATING_POINT_EXCEPTION 19
53 | #define VIRTUALIZATION_EXCEPTION 20
54 | #define CONTROL_PROTECTION_EXCEPTION 21
55 | #define RESERVED2 22
56 | #define RESERVED3 23
57 | #define RESERVED4 24
58 | #define RESERVED5 25
59 | #define RESERVED6 26
60 | #define RESERVED7 27
61 | #define HYPERVISOR_INJECTION_EXCEPTION 28
62 | #define VMM_COMUNICATION_EXCEPTION 29
63 | #define SECURITY_EXCEPTION 30
64 | #define RESERVED8 31
65 |
66 | isr_t interrupt_handlers[256];
67 |
68 | void register_interrupt_handler(uint8_t n, isr_t handler){ interrupt_handlers[n] = handler; }
69 |
70 | extern "C" void isr_handler(registers_t regs){
71 | set_color(0x4);
72 | switch(regs.int_no) {
73 | case DIVIDE_BY_ZERO:
74 | printf("Divide by zero.");
75 | break;
76 | case DEBUG:
77 | printf("Debug.");
78 | break;
79 | case NON_MASKABLE_INTERRUPT:
80 | printf("Non maskable interrupt.");
81 | break;
82 | case BREAKPOINT:
83 | printf("Breakpoint.");
84 | break;
85 | case OVERFLOW:
86 | printf("Overflow.");
87 | break;
88 | case BOUND_RANGE_EXCEEDED:
89 | printf("Bound range exceeded.");
90 | break;
91 | case INVALID_OPCODE:
92 | printf("Invalid opcode.");
93 | break;
94 | case DEVICE_NOT_AVAILABLE:
95 | printf("Device not available.");
96 | break;
97 | case DOUBLE_FAULT:
98 | printf("Double fault.");
99 | asm("cli; hlt");
100 | break;
101 | case COPROCESSOR_SEGMENT_OVERRUN:
102 | printf("Coprocessor segment overrun.");
103 | break;
104 | case INVALID_TSS:
105 | printf("Invalid TSS.");
106 | break;
107 | case SEGMENT_NOT_PRESENT:
108 | printf("Segment not present.");
109 | break;
110 | case STACK_SEGMENT_FAULT:
111 | printf("Stack segment fault.");
112 | break;
113 | case GENERAL_PROTECTION_FAULT:
114 | printf("General protection fault.");
115 | break;
116 | case PAGE_FAULT:
117 | printf("Page fault.");
118 | break;
119 | case X87FLOATING_POINT_EXCEPTION:
120 | printf("x87 floating point exception.");
121 | break;
122 | case ALIGMENT_CHECK:
123 | printf("Aligment check.");
124 | break;
125 | case MACHINE_CHECK:
126 | printf("Machine check.");
127 | asm("cli; hlt");
128 | break;
129 | case SIMD_FLOATING_POINT_EXCEPTION:
130 | printf("SIMD floating point exception.");
131 | break;
132 | case VIRTUALIZATION_EXCEPTION:
133 | printf("Virtualization exception.");
134 | break;
135 | case CONTROL_PROTECTION_EXCEPTION:
136 | printf("Control protection exception.");
137 | break;
138 | case HYPERVISOR_INJECTION_EXCEPTION:
139 | printf("Hypervisor injection exception.");
140 | break;
141 | case VMM_COMUNICATION_EXCEPTION:
142 | printf("VMM comunication exception.");
143 | break;
144 | case SECURITY_EXCEPTION:
145 | printf("Security exception.");
146 | break;
147 | default:
148 | printf("unhandled interrupt 0x%x\n", regs.int_no);
149 | break;
150 | }
151 | }
152 |
153 | extern "C" void irq_handler(registers_t r){
154 | if(r.int_no >= 40){
155 | outb(0xa0, 0x20);
156 | }
157 | outb(0x20, 0x20);
158 | if(interrupt_handlers[r.int_no] != 0){
159 | isr_t handler = interrupt_handlers[r.int_no];
160 | handler(r);
161 | }
162 | }
--------------------------------------------------------------------------------
/src/kernel/include/keyboard.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include"stdio.h"
4 | #include"isr.h"
5 | #include"system.h"
6 | #include"rtc.h"
7 | #include"fat12.h"
8 | #include
9 | //#include"vga.h"
10 |
11 | //lowercase key list. (trq)
12 | const char sc_table[] ={
13 | 0x00, 0x00, '1', '2',
14 | '3', '4', '5', '6',
15 | '7', '8', '9', '0',
16 | '-', '=', 0x00, 0x00,
17 | 'q', 'w', 'e', 'r',
18 | 't', 'y', 'u', 'i',
19 | 'o', 'p', 'g', 'u',
20 | 0x00, 0x00, 'a', 's',
21 | 'd', 'f', 'g', 'h',
22 | 'j', 'k', 'l', 's',
23 | 'i', ',', 0x00, '\\',
24 | 'z', 'x', 'c', 'v',
25 | 'b', 'n', 'm', 'o',
26 | 'c', '.', 0x00, '*',
27 | 0x00, ' '
28 | };
29 |
30 | //shift key list.
31 | const char sc_tableC[] ={
32 | 0x00, 0x00, '!', '@',
33 | '^', '+', '%', '&',
34 | '/', '(', ')', '=',
35 | '?', '_', 0x00, 0x00,
36 | 'Q', 'W', 'E', 'R',
37 | 'T', 'Y', 'U', 'I',
38 | 'O', 'P', '{', '}',
39 | 0x00, 0x00, 'A', 'S',
40 | 'D', 'F', 'G', 'H',
41 | 'J', 'K', 'L', ':',
42 | '"', '~', 0x00, '|',
43 | 'Z', 'X', 'C', 'V',
44 | 'B', 'N', 'M', '<',
45 | '>', '?', 0x00, '*',
46 | 0x00, ' '
47 | };
48 |
49 | int lshift = 0x00;
50 | int rshift = 0x00;
51 |
52 | void keyboard_handler(registers_t regs){
53 | //gets the key pressed.
54 | uint8_t k = inb(0x60);
55 | uint8_t c = 0x00;
56 | //translate the keyboard code into a letter character.
57 | if(k < 0x3A)
58 | c = sc_table[k];
59 | //if the pressed letter is a character.
60 | if(c != 0x00){
61 | //check if the shift keys are pressed.
62 | switch(lshift | rshift){
63 | case 0x01: //uppercase.
64 | buffer[_buf] = sc_tableC[k];
65 | putc(sc_tableC[k]);
66 | _buf++;
67 | buffer[_buf] = 0x00;
68 | break;
69 | case 0x00: //lowercase.
70 | buffer[_buf] = c;
71 | putc(c);
72 | _buf++;
73 | buffer[_buf] = 0x00;
74 | break;
75 | }
76 | } else {
77 | //if the key pressed has zero as a value check the code.
78 | switch(k){
79 | case 0x0E: //clear back key.
80 | if(_buf!=0x00) {
81 | _buf--;
82 | buffer[_buf] = 0x00;
83 | putcback();
84 | }
85 | break;
86 |
87 | case 0x2A: //left shift key pressed.
88 | lshift = 0x01;
89 | break;
90 |
91 | case 0xAA: //left shift key released.
92 | lshift = 0x00;
93 | rshift = 0x00;
94 | break;
95 |
96 | case 0x36: //right shift key pressed.
97 | rshift = 0x01;
98 | break;
99 |
100 | case 0xb6: //right shift key released.
101 | lshift = 0x00;
102 | rshift = 0x00;
103 | break;
104 |
105 | case 0x3A: //caps lock pressed.
106 | if(lshift == 0x00){
107 | lshift = 0x01;
108 | }
109 | else {
110 | lshift = 0x00;
111 | }
112 | break;
113 |
114 | case 0x1C: //enter pressed.
115 | printf("\n");
116 | if(compare_strings_ws("help", buffer) == true){
117 | printf("help - prints a list of available commands.\n");
118 | printf("dir - prints the contents of the root directory.\n");
119 | printf("time - prints the current time.\n");
120 | } else if(compare_strings_ws("dir", buffer) == true) {
121 | file_entry* file;
122 | char* mem = (char*)0x30000;
123 | while ((char*)mem < (char*)0x50000) {
124 | file = (file_entry*)mem;
125 | if(file->size == 0)
126 | break;
127 | printf("%s %d bytes\n", mem, file->size);
128 | mem += 32;
129 | }
130 | } else if(compare_strings_ws("time", buffer) == true) {
131 | printf("%d/%d/%d - %d:%d:%d\n", time.day_of_month, time.month, time.year, time.hour, time.minute, time.second);
132 | } else if(fread(buffer, 0x150000)){
133 | void (*app)(void) = (void (*)())0x150000;
134 | app();
135 | } else if(compare_strings_ws("echo", buffer) == true){
136 | printf("echo\n");
137 | } else if(compare_strings_ws("clear", buffer) == true){
138 | //clear function
139 | int i=0;
140 |
141 | // empty text with white text.
142 | signed char blankCell = string_size(" ");
143 |
144 | for (i = 0; i < 25; i++){
145 | for (int j = 0; j < 80; j++) {
146 | video_memory[2 * (80 * i + j)] = '\0';
147 | video_memory[2 * (80 * i + j) + 1] = 0x0B;
148 | }
149 | }
150 | //initialize_keyboard();
151 | //update_cursor_pos(0x00,0x00);
152 | }else if(compare_strings_ws("poweroff", buffer) == true){
153 | outw(0xB004, 0x2000);
154 | outw(0x604, 0x2000);
155 | outw(0x4004, 0x3400);
156 | } else {
157 | printf("'%s' komutu bulunamadi\n",buffer);
158 | }
159 | clear_string(buffer);
160 | _buf = 0;
161 | printf(">_");
162 | break;
163 | }
164 | }
165 | }
166 |
167 | //keyboard initialization function.
168 | void initialize_keyboard(){
169 | //initialize the keyboard switch.
170 | register_interrupt_handler(IRQ1, &keyboard_handler);
171 | *buffer = 0;
172 | }
--------------------------------------------------------------------------------
/src/kernel/include/math.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | // declaration of constants.
4 | const double PI = 3.141592653589793;
5 | const double HALF_PI = 1.570796326794897;
6 | const double DOUBLE_PI = 6.283185307179586;
7 | const double SIN_CURVE_A = 0.0415896;
8 | const double SIN_CURVE_B = 0.00129810625032;
9 |
10 | //structure of a two-dimensional vector of integers.
11 | struct vec2i {
12 | int x, y;
13 | };
14 |
15 | //structure of a three-dimensional vector of integers.
16 | struct vec3i {
17 | int x, y;
18 | };
19 |
20 | //structure of a two-dimensional vector of rational numbers.
21 | struct vec2f {
22 | float x, y;
23 | };
24 |
25 | //structure of a three-dimensional vector of rational numbers.
26 | struct vec3f {
27 | float x, y;
28 | };
29 |
30 | //function to find the absolute value of an integer.
31 | //#define abs(x) (if(x<0) -x; x)
32 | int abs(int x) {
33 | if(x < 0)
34 | return -x;
35 | return x;
36 | }
37 |
38 | int sgn(int x) { //function to find the sign of an integer.
39 | if(x < 0)
40 | return -1;
41 | return 1;
42 | }
43 |
44 | float sqrt(float number) { //function to find the square root of a rational number.
45 | int start = 0, end = number;
46 | int mid;
47 | float ans;
48 | while (start <= end) {
49 | mid = (start + end) / 2;
50 | if (mid * mid == number) {
51 | ans = mid;
52 | break;
53 | }
54 | if (mid * mid < number) {
55 | ans=start;
56 | start = mid + 1;
57 | }
58 | else {
59 | end = mid - 1;
60 | }
61 | }
62 | float increment = 0.1;
63 | int i;
64 | for (i = 0; i < 5; i++) {
65 | while (ans * ans <= number) {
66 | ans += increment;
67 | }
68 | ans = ans - increment;
69 | increment = increment / 10;
70 | }
71 | return ans;
72 | }
73 |
74 | //function to compute the power of a given base with a given exponent.
75 | int pow(int base, int exponent) {
76 | int result = 1;
77 | for (;;) {
78 | if (exponent & 1)
79 | result *= base;
80 | exponent >>= 1;
81 | if (!exponent)
82 | break;
83 | base *= base;
84 | }
85 | return result;
86 | }
87 |
88 | //function for calculating the cos.
89 | double cos(double x) {
90 | if (x < 0) {
91 | int q = -x / DOUBLE_PI;
92 | q += 1;
93 | double y = q * DOUBLE_PI;
94 | x = -(x - y);
95 | }
96 | if (x >= DOUBLE_PI) {
97 | int q = x / DOUBLE_PI;
98 | double y = q * DOUBLE_PI;
99 | x = x - y;
100 | }
101 | int s = 1;
102 | if (x >= PI) {
103 | s = -1;
104 | x -= PI;
105 | }
106 | if (x > HALF_PI) {
107 | x = PI - x;
108 | s = -s;
109 | }
110 | double z = x * x;
111 | double r = z * (z * (SIN_CURVE_A - SIN_CURVE_B * z) - 0.5) + 1.0;
112 | if (r > 1.0) r = r - 2.0;
113 | if (s > 0) return r;
114 | else return -r;
115 | }
116 |
117 | //sin calculation function.
118 | double sin(double x) {
119 | return cos(x - HALF_PI);
120 | }
--------------------------------------------------------------------------------
/src/kernel/include/memory.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | //function to set a given part of memory to a destination with a value for a given length.
4 | void* memset(void *dest, int val, unsigned int len) {
5 | char* ptr = (char*)dest;
6 | while (len-- > 0) *ptr++ = val;
7 | return dest;
8 | }
9 |
10 | //function to copy a given part of memory from a source to a destination for a given length.
11 | void* memcpy(void *dest, const void *src, int n) {
12 | char* d = (char*)dest;
13 | char* s = (char*)src;
14 | while(n--)
15 | *(d++) = *(s++);
16 | return dest;
17 | }
18 |
19 | //function to copy a given part of memory from a source to a destination for a given length with the SSE.
20 | extern "C" int memcpy_sse(void* dst, void* src, unsigned int count);
--------------------------------------------------------------------------------
/src/kernel/include/mouse.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include"stdio.h"
4 | #include"system.h"
5 | #include"pic.h"
6 | #include"ports.h"
7 |
8 | char mouse_cycle = 0;
9 | signed char mouse_byte[3];
10 |
11 | int mouse_x = 100;
12 | int mouse_y = 100;
13 |
14 | void mouse_wait(uint8_t a_type) {
15 | uint32_t _time_out=100000;
16 | if(a_type==0) {
17 | while(_time_out--) {
18 | if((inb(0x64) & 1)==1)
19 | {
20 | return;
21 | }
22 | }
23 | return;
24 | }
25 | else {
26 | while(_time_out--) {
27 | if((inb(0x64) & 2)==0) {
28 | return;
29 | }
30 | }
31 | return;
32 | }
33 | }
34 |
35 | void mouse_write(uint8_t a_write) {
36 | mouse_wait(1);
37 | outb(0x64, 0xD4);
38 | mouse_wait(1);
39 | outb(0x60, a_write);
40 | }
41 |
42 | uint8_t mouse_read() {
43 | mouse_wait(0);
44 | return inb(0x60);
45 | }
46 |
47 | void mouse_handler(registers_t regs) {
48 | switch(mouse_cycle) {
49 | case 0:
50 | mouse_byte[0]=inb(0x60);
51 | mouse_cycle++;
52 | break;
53 | case 1:
54 | mouse_byte[1]=inb(0x60);
55 | mouse_cycle++;
56 | break;
57 | case 2:
58 | mouse_byte[2]=inb(0x60);
59 | mouse_x += mouse_byte[1];
60 | mouse_y -= mouse_byte[2];
61 | mouse_cycle=0;
62 | break;
63 | }
64 | outb(0xA0, 0x20);
65 | }
66 |
67 | void initialize_mouse(){
68 | uint8_t _status;
69 | mouse_wait(1);
70 | outb(0x64, 0xA8);
71 | mouse_wait(1);
72 | outb(0x64, 0x20);
73 | mouse_wait(0);
74 | _status=(inb(0x60) | 2);
75 | mouse_wait(1);
76 | outb(0x64, 0x60);
77 | mouse_wait(1);
78 | outb(0x60, _status);
79 | mouse_write(0xF6);
80 | mouse_read();
81 | mouse_write(0xF4);
82 | mouse_read();
83 | IRQ_clear_mask(12);
84 | register_interrupt_handler(IRQ12, &mouse_handler);
85 | }
--------------------------------------------------------------------------------
/src/kernel/include/pic.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include"ports.h"
4 |
5 | #define PIC1 0x20 /* IO base address for master PIC */
6 | #define PIC2 0xA0 /* IO base address for slave PIC */
7 | #define PIC1_COMMAND PIC1
8 | #define PIC1_DATA (PIC1+1)
9 | #define PIC2_COMMAND PIC2
10 | #define PIC2_DATA (PIC2+1)
11 |
12 | void IRQ_set_mask(unsigned char IRQline) {
13 | uint16_t port;
14 | uint8_t value;
15 |
16 | if(IRQline < 8) {
17 | port = PIC1_DATA;
18 | } else {
19 | port = PIC2_DATA;
20 | IRQline -= 8;
21 | }
22 | value = inb(port) | (1 << IRQline);
23 | outb(port, value);
24 | return;
25 | }
26 |
27 | void IRQ_clear_mask(unsigned char IRQline) {
28 | uint16_t port;
29 | uint8_t value;
30 |
31 | if(IRQline < 8) {
32 | port = PIC1_DATA;
33 | } else {
34 | port = PIC2_DATA;
35 | IRQline -= 8;
36 | }
37 | value = inb(port) & ~(1 << IRQline);
38 | outb(port, value);
39 | return;
40 | }
--------------------------------------------------------------------------------
/src/kernel/include/ports.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | //output function of an octet to an input and output port.
6 | static inline void outb(uint16_t port, uint8_t value) {
7 | asm("outb %0, %1" : : "a"(value), "Nd"(port));
8 | return;
9 | }
10 |
11 | //input function of an octet to an input and output port.
12 | static inline uint8_t inb(uint16_t port) {
13 | uint8_t value;
14 | asm("inb %1, %0" : "=a"(value) : "Nd"(port));
15 | return value;
16 | }
17 |
18 | //output function of two octets to one input and output port.
19 | static inline void outw(uint16_t port, uint16_t value) {
20 | asm("out %%ax, %%dx" : : "a"(value), "d"(port));
21 | return;
22 | }
23 |
24 | //input function of two octets to an input and output port.
25 | static inline uint16_t inw(uint16_t port) {
26 | uint16_t value;
27 | asm("in %%dx, %%ax" : "=a"(value) : "d"(port));
28 | return value;
29 | }
30 |
31 | //output function of four octets to one input and output port.
32 | static inline void outd(uint32_t port, uint32_t value) {
33 | asm("outl %%eax, %%dx" : : "a"(value), "d"(port));
34 | }
35 |
36 | //input function of four octets to an input and output port.
37 | static inline uint32_t ind(uint32_t port) {
38 | uint32_t value;
39 | asm("inl %%dx, %%eax" : "=a"(value) : "d"(port));
40 | return value;
41 | }
--------------------------------------------------------------------------------
/src/kernel/include/rtc.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include"ports.h"
4 |
5 | typedef struct {
6 | char second;
7 | char minute;
8 | char hour;
9 | char day_of_week;
10 | char day_of_month;
11 | char month;
12 | char year;
13 | } time_t;
14 |
15 | time_t time;
16 | bool bcd;
17 |
18 | //function to write to real time clock registers.
19 | char read_register(unsigned char reg) {
20 | outb(0x70, reg);
21 | return inb(0x71);
22 | }
23 |
24 | //function to read from real time clock registers.
25 | void write_register(unsigned char reg, unsigned char value) {
26 | outb(0x70, reg);
27 | outb(0x71, value);
28 | }
29 |
30 | char bcd2bin(unsigned char bcd) {
31 | return ((bcd >> 4) * 10) + (bcd & 0x0F);
32 | }
33 |
34 | void gettime(time_t *time) {
35 | memcpy_sse(time, &time, sizeof(time_t));
36 | }
37 |
38 | //real time clock management function.
39 | void rtc_handler(registers_t regs) {
40 | if(read_register(0x0C) & 0x10){
41 | if(bcd){
42 | time.second = bcd2bin(read_register(0x00));
43 | time.minute = bcd2bin(read_register(0x02));
44 | time.hour = bcd2bin(read_register(0x04));
45 | time.month = bcd2bin(read_register(0x08));
46 | time.year = bcd2bin(read_register(0x09));
47 | time.day_of_week = bcd2bin(read_register(0x06));
48 | time.day_of_month = bcd2bin(read_register(0x07));
49 | }else {
50 | time.second = read_register(0x00);
51 | time.minute = read_register(0x02);
52 | time.hour = read_register(0x04);
53 | time.month = read_register(0x08);
54 | time.year = read_register(0x09);
55 | time.day_of_week = read_register(0x06);
56 | time.day_of_month = read_register(0x07);
57 | }
58 | }
59 | }
60 |
61 | //real time clock initialization function.
62 | void initialize_rtc() {
63 | unsigned char status;
64 | status = read_register(0x0B);
65 | status |= 0x02;
66 | status |= 0x10;
67 | status &= ~0x20;
68 | status &= ~0x40;
69 | bcd = !(status & 0x04);
70 | write_register(0x0B, status);
71 | read_register(0x0C);
72 | register_interrupt_handler(IRQ8, &rtc_handler);
73 | }
--------------------------------------------------------------------------------
/src/kernel/include/sse.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | //function to enable the SSE https://wiki.osdev.org/SSE
4 | extern "C" void enable_sse();
--------------------------------------------------------------------------------
/src/kernel/include/stdio.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include"string.h"
4 | #include"ports.h"
5 | #include
6 | #include
7 |
8 | uint16_t x_pos = 0x0000, y_pos = 0x0000; //cursor position.
9 | //text color.
10 | uint8_t color = 0x07;
11 | //color of test
12 | uint8_t bg_color = 0x00;
13 |
14 | //text mode memory address 0x03.
15 | uint32_t* video_memory = (uint32_t*)0x000B8000;
16 |
17 | //set the text color.
18 | void set_color(uint8_t new_color) {
19 | color = new_color;
20 | return;
21 | }
22 |
23 | //set the background color of the text.
24 | void set_bg_color(uint8_t new_color) {
25 | bg_color = new_color;
26 | return;
27 | }
28 |
29 | //scrolls text down one line.
30 | void scroll() {
31 | uint8_t attribute = (0x00 << 0x04) | (0x0F & 0x0F);
32 | uint16_t blank = 0x0020 | (attribute << 0x0008);
33 | if(y_pos >= 0x0019) {
34 | for(uint32_t i = 0x00000000 * 0x00000050; i < 0x00000018 * 0x00000050; i++)
35 | video_memory[i] = video_memory[i + 0x00000050];
36 | for(uint32_t i = 0x00000018 * 0x00000050; i < 0x00000019 * 0x00000050; i++)
37 | video_memory[i] = blank;
38 | y_pos = 0x0018;
39 | }
40 | return;
41 | }
42 |
43 | //updates the position of the cursor on the screen.
44 | void update_cursor_pos(uint16_t x, uint16_t y) {
45 | uint16_t cursor_pos = y * 0x0050 + x;
46 | outb(0x03D4, 0x0F);
47 | outb(0x03D5, (uint8_t)(cursor_pos & 0xFF));
48 | outb(0x03D4, 0x0E);
49 | outb(0x03D5, (uint8_t)((cursor_pos >> 0x08) & 0xFF));
50 | return;
51 | }
52 |
53 | //writes a character on the screen by advancing the cursor position.
54 | void putc(unsigned char c){
55 | uint16_t attrib = (0 << 4) | (color & 0x0F);
56 | volatile uint16_t* where;
57 | where = (volatile uint16_t *)0xB8000 + (y_pos * 80 + x_pos);
58 | *where = c | (attrib << 8);
59 | if(++x_pos >= 80){
60 | x_pos = 0;
61 | y_pos++;
62 | }
63 | update_cursor_pos(x_pos, y_pos);
64 | if(y_pos >= 25) {
65 | x_pos = 0;
66 | scroll();
67 | }
68 | return;
69 | }
70 |
71 | //removes a character on the screen by moving the cursor back.
72 | void putcback(){
73 | uint16_t attrib = (0 << 4) | (color & 0x0F);
74 | volatile uint16_t * where;
75 | x_pos--;
76 | if(x_pos < 0) {
77 | x_pos = 79;
78 | y_pos--;
79 | }
80 | where = (volatile uint16_t *)0xB8000 + (y_pos * 80 + x_pos);
81 | *where = ' ' | (attrib << 8);
82 | update_cursor_pos(x_pos, y_pos);
83 | if(y_pos >= 25) {
84 | x_pos = 0;
85 | scroll();
86 | }
87 | }
88 |
89 | //writes a string to the screen by advancing the cursor position.
90 | void puts(char* string){
91 | uint16_t i;
92 | while(*string){
93 | switch(*string){
94 | case 0x0A:
95 | x_pos = 0x0000;
96 | y_pos++;
97 | *string++;
98 | scroll();
99 | break;
100 | case 0x09:
101 | for(i = 0x0000; i <= 0x0008; i++) {
102 | putc(' ');
103 | }
104 | *string++;
105 | break;
106 | default:
107 | putc(*string);
108 | *string++;
109 | break;
110 | }
111 | }
112 | update_cursor_pos(x_pos, y_pos);
113 | return;
114 | }
115 |
116 | //writes a rich string to the screen by advancing the cursor position.
117 | void printf(char* format, ...) {
118 | va_list ap;
119 | va_start(ap, format);
120 | char* pointer;
121 | for (pointer = format; *pointer != 0x00; pointer++) {
122 | if (*pointer == '%') {
123 | ++pointer;
124 | switch (*pointer) {
125 | case 0x63:
126 | putc(va_arg(ap, int));
127 | break;
128 | case 0x73:
129 | puts(va_arg(ap, char*));
130 | break;
131 | case 0x64:
132 | puts(int_to_string(va_arg(ap, int), 10));
133 | break;
134 | case 0x78:
135 | puts(int_to_string(va_arg(ap, uint32_t), 16));
136 | break;
137 | }
138 | } else {
139 | char t[2] = {*pointer, 0};
140 | puts(t);
141 | }
142 | }
143 | return;
144 | }
--------------------------------------------------------------------------------
/src/kernel/include/string.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 |
6 | //converts a number to a string.
7 | char* int_to_string(unsigned int num, int base) {
8 | static char repr[]= "0123456789ABCDEF";
9 | static char buffer[50];
10 | char *ptr;
11 |
12 | ptr = &buffer[49];
13 | *ptr = '\0';
14 |
15 | do {
16 | *--ptr = repr[num%base];
17 | num /= base;
18 | }while(num != 0);
19 |
20 | return(ptr);
21 | }
22 |
23 | //compare two strings.
24 | bool compare_strings(const char* string1, const char* string2) {
25 | while(*string1!=0) {
26 | if(*string1 != *string2)
27 | return false;
28 | string1++;
29 | string2++;
30 | }
31 | return true;
32 | }
33 |
34 | //compares two strings and returns false if they are different.
35 | bool compare_strings_ws(const char* string1, const char* string2) {
36 | while(1) {
37 | if(*string1==0 && *string2!=0)
38 | return false;
39 | if(*string1==0)
40 | return true;
41 | if(*string1 != *string2)
42 | return false;
43 | string1++;
44 | string2++;
45 | }
46 | return true;
47 | }
48 |
49 | void clear_string(char* string) { //empties a string.
50 | while(*string != 0) {
51 | *string = 0;
52 | string++;
53 | }
54 | return;
55 | }
56 | /*
57 | void restore_memory(long unsigned int* a){
58 | while(a != 0x00){
59 | a == 0x00;
60 | }
61 | return;
62 | }
63 | */
64 | int string_size(char* string) { //returns the length of a string.
65 | int counter = 0;
66 | while(*string != 0) {
67 | string++;
68 | counter++;
69 | }
70 | return counter;
71 | }
--------------------------------------------------------------------------------
/src/kernel/include/system.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | //klavye girişi için bellek.
4 | char* buffer;
5 | int _buf = 0;
6 |
7 | //anahtarları devre dışı bırakma işlevi.
8 | extern "C" void disable_ints();
9 |
10 | //anahtarları etkinleştirme işlevi.
11 | extern "C" void enable_ints();
--------------------------------------------------------------------------------
/src/kernel/include/timer.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include"stdio.h"
4 | #include"isr.h"
5 | #include"ports.h"
6 |
7 | //moments past.
8 | uint32_t tick = 0;
9 |
10 | //function to obtain a random number given the maximum value.
11 | int random(int numLimit) {
12 | static int randSeed, needsInit = 1;
13 | if (needsInit) {
14 | randSeed = tick;
15 | needsInit = 0;
16 | }
17 | randSeed = (randSeed * 32719 + 3) % 32749;
18 | return (randSeed % numLimit) + 1;
19 | }
20 |
21 | //clock management function.
22 | static void timer_callback(registers_t regs) {
23 | tick++;
24 | }
25 |
26 | //clock initialization function.
27 | void initialize_timer(uint32_t frequency) {
28 | register_interrupt_handler(IRQ0, &timer_callback);
29 | uint32_t divisor = 1193180 / frequency;
30 | outb(0x43, 0x36);
31 | uint8_t l = (uint8_t)(divisor & 0xFF);
32 | uint8_t h = (uint8_t)((divisor>>8) & 0xff);
33 | outb(0x40, l);
34 | outb(0x40, h);
35 | return;
36 | }
--------------------------------------------------------------------------------
/src/kernel/include/vga.h:
--------------------------------------------------------------------------------
1 | #include"stdio.h"
2 | #define VIDEO_MEMORY_ADDRESS 0xb8000;
3 | #define WIDTH 80
4 | #define HEIGHT 25
5 |
6 |
7 | static short xx=0;
8 | static short yy=0;
9 |
10 | unsigned int strlen(char *str){
11 | unsigned int len=0;
12 | while(str[len]){
13 | len++;
14 | }
15 | return len;
16 | }
17 |
18 | void vga_init(){
19 | short *buffer=(short *)VIDEO_MEMORY_ADDRESS;
20 | for(short i=0;i<=80*25*2;i++){
21 | buffer[i]=0x4020;
22 | }
23 | }
24 | void term_put(char *str){
25 | short *buffer=(short *)VIDEO_MEMORY_ADDRESS;
26 | for(char i=0;i<=strlen(str);i++){
27 | if(str[i]=='\n'|| xx==WIDTH){
28 | yy++;
29 | xx=0;
30 | }else{
31 | if(str[i]!='\0'){
32 | buffer[yy*WIDTH+xx]=str[i]|0x40<<8;
33 | }
34 | xx++;
35 | }
36 | }
37 | }
38 | /*
39 | void clearKOD(){
40 | int i=0;
41 |
42 | // empty text with white text.
43 | signed int blankCell = string_size(" ");
44 |
45 | for (i = 0; i < HEIGHT; i++){
46 | for (int j = 0; j < WIDTH; j++) {
47 | video_memory[2 * (WIDTH * i + j)] = '\0';
48 | video_memory[2 * (WIDTH * i + j) + 1] = 0x0B;
49 | }
50 | }
51 | }
52 | */
--------------------------------------------------------------------------------
/src/kernel/kernel.asm:
--------------------------------------------------------------------------------
1 | [BITS 32]
2 | ;kernel.cpp yukle
3 | [EXTERN main]
4 | ;main fonction
5 | call main
6 | ;creates an infinite loop by jumping to the current memory address.
7 | jmp $
8 |
9 | [GLOBAL memcpy_sse]
10 | memcpy_sse:
11 | push ebp
12 | mov ebp, esp
13 | push esi
14 | push edi
15 | pushf
16 | cld
17 | mov edi, [ebp + 8]
18 | mov esi, [ebp + 12]
19 | mov eax, [ebp + 16]
20 | mov ecx, eax
21 | shr ecx, 6
22 | jz .endloop64
23 | .loop64:
24 | prefetchnta [esi + 64]
25 | prefetchnta [esi + 96]
26 | movq mm1, [esi + 0]
27 | movq mm2, [esi + 8]
28 | movq mm3, [esi + 16]
29 | movq mm4, [esi + 24]
30 | movq mm5, [esi + 32]
31 | movq mm6, [esi + 40]
32 | movq mm7, [esi + 48]
33 | movq mm0, [esi + 56]
34 | movntq [edi + 0], mm1
35 | movntq [edi + 8], mm2
36 | movntq [edi + 16], mm3
37 | movntq [edi + 24], mm4
38 | movntq [edi + 32], mm5
39 | movntq [edi + 40], mm6
40 | movntq [edi + 48], mm7
41 | movntq [edi + 56], mm0
42 | add esi, 64
43 | add edi, 64
44 | loop .loop64
45 | emms
46 | .endloop64:
47 | mov ecx, eax
48 | and ecx, 0x3F
49 | shr ecx, 3
50 | jz .endloop8
51 | .loop8:
52 | movq mm1, [esi]
53 | movq [edi], mm1
54 | add esi, 8
55 | add edi, 8
56 | loop .loop8
57 | emms
58 | .endloop8:
59 | mov ecx, eax
60 | and ecx, 7
61 | repe movsb
62 | .done:
63 | popf
64 | pop edi
65 | pop esi
66 | mov esp, ebp
67 | pop ebp
68 | ret
69 |
70 | [GLOBAL enable_sse]
71 | enable_sse:
72 | mov eax, cr0
73 | and ax, 0xFFFB
74 | or ax, 0x2
75 | mov cr0, eax
76 | mov eax, cr4
77 | or ax, 3 << 9
78 | mov cr4, eax
79 | ret
80 |
81 | [GLOBAL gdt_flush]
82 | gdt_flush:
83 | mov eax, [esp+4]
84 | lgdt [eax]
85 | mov eax, 0x10
86 | mov ds, ax
87 | mov es, ax
88 | mov fs, ax
89 | mov gs, ax
90 | mov ss, ax
91 | jmp 0x08:.flush
92 | .flush:
93 | ret
94 |
95 | [GLOBAL idt_flush]
96 | idt_flush:
97 | mov eax, [esp+4]
98 | lidt [eax]
99 | sti
100 | ret
101 |
102 | %MACRO ISR_NOERRCODE 1
103 | [GLOBAL isr%1]
104 | isr%1:
105 | cli
106 | push byte 0
107 | push byte %1
108 | jmp isr_common_stub
109 | %ENDMACRO
110 |
111 | %MACRO ISR_ERRCODE 1
112 | [GLOBAL isr%1]
113 | isr%1:
114 | cli
115 | push byte %1
116 | jmp isr_common_stub
117 | %ENDMACRO
118 |
119 | %MACRO IRQ 2
120 | [GLOBAL irq%1]
121 | irq%1:
122 | cli
123 | push byte 0
124 | push byte %2
125 | jmp irq_common_stub
126 | %ENDMACRO
127 |
128 | ISR_NOERRCODE 0
129 | ISR_NOERRCODE 1
130 | ISR_NOERRCODE 2
131 | ISR_NOERRCODE 3
132 | ISR_NOERRCODE 4
133 | ISR_NOERRCODE 5
134 | ISR_NOERRCODE 6
135 | ISR_NOERRCODE 7
136 | ISR_ERRCODE 8
137 | ISR_NOERRCODE 9
138 | ISR_ERRCODE 10
139 | ISR_ERRCODE 11
140 | ISR_ERRCODE 12
141 | ISR_ERRCODE 13
142 | ISR_ERRCODE 14
143 | ISR_NOERRCODE 15
144 | ISR_NOERRCODE 16
145 | ISR_NOERRCODE 17
146 | ISR_NOERRCODE 18
147 | ISR_NOERRCODE 19
148 | ISR_NOERRCODE 20
149 | ISR_NOERRCODE 21
150 | ISR_NOERRCODE 22
151 | ISR_NOERRCODE 23
152 | ISR_NOERRCODE 24
153 | ISR_NOERRCODE 25
154 | ISR_NOERRCODE 26
155 | ISR_NOERRCODE 27
156 | ISR_NOERRCODE 28
157 | ISR_NOERRCODE 29
158 | ISR_NOERRCODE 30
159 | ISR_NOERRCODE 31
160 |
161 | IRQ 0, 32
162 | IRQ 1, 33
163 | IRQ 2, 34
164 | IRQ 3, 35
165 | IRQ 4, 36
166 | IRQ 5, 37
167 | IRQ 6, 38
168 | IRQ 7, 39
169 | IRQ 8, 40
170 | IRQ 9, 41
171 | IRQ 10, 42
172 | IRQ 11, 43
173 | IRQ 12, 44
174 | IRQ 13, 45
175 | IRQ 14, 46
176 | IRQ 15, 47
177 |
178 | [EXTERN isr_handler]
179 |
180 | isr_common_stub:
181 | pusha
182 | mov ax, ds
183 | push eax
184 | mov ax, 0x10
185 | mov ds, ax
186 | mov es, ax
187 | mov fs, ax
188 | mov gs, ax
189 | call isr_handler
190 | pop eax
191 | mov ds, ax
192 | mov es, ax
193 | mov fs, ax
194 | mov gs, ax
195 | popa
196 | add esp, 8
197 | sti
198 | iret
199 |
200 | [EXTERN irq_handler]
201 | irq_common_stub:
202 | pusha
203 | mov ax, ds
204 | push eax
205 | mov ax, 0x10
206 | mov ds, ax
207 | mov es, ax
208 | mov fs, ax
209 | mov gs, ax
210 | call irq_handler
211 | pop ebx
212 | mov ds, bx
213 | mov es, bx
214 | mov fs, bx
215 | mov gs, bx
216 | popa
217 | add esp, 8
218 | sti
219 | iret
220 |
--------------------------------------------------------------------------------
/src/kernel/kernel.cpp:
--------------------------------------------------------------------------------
1 | #include"include/initialize.h"
2 | #include"include/stdio.h"
3 | #include"include/ata.h"
4 | #include"include/fs.h"
5 | #include"include/fat12.h"
6 | #include"include/memory.h"
7 | #include"include/dt.h"
8 | #include"include/isr.h"
9 | #include"include/vga.h"
10 | #include"include/keyboard.h"
11 | #include"include/mouse.h"
12 | #include"include/timer.h"
13 | #include"include/rtc.h"
14 | #include"include/math.h"
15 | #include"include/pic.h"
16 |
17 | #define GUI_MODE 0
18 |
19 | //main function
20 | extern "C" int main() {
21 | printf("vimixOS\n");
22 | //initalize system resources
23 | initialize();
24 | vga_init();
25 | printf(">_");
26 | return 0;
27 | }
--------------------------------------------------------------------------------
/src/kernel/modules.asm:
--------------------------------------------------------------------------------
1 | [BITS 32]
2 | ;import the main function from kernel.cpp.
3 | [EXTERN modules]
4 | ;call the function main.
5 | call modules
6 | ;creates an infinite loop by jumping to the current memory address.
7 | jmp $
8 |
9 | [GLOBAL memcpy_sse]
10 | memcpy_sse:
11 | push ebp
12 | mov ebp, esp
13 | push esi
14 | push edi
15 | pushf
16 | cld
17 | mov edi, [ebp + 8]
18 | mov esi, [ebp + 12]
19 | mov eax, [ebp + 16]
20 | mov ecx, eax
21 | shr ecx, 6
22 | jz .endloop64
23 | .loop64:
24 | prefetchnta [esi + 64]
25 | prefetchnta [esi + 96]
26 | movq mm1, [esi + 0]
27 | movq mm2, [esi + 8]
28 | movq mm3, [esi + 16]
29 | movq mm4, [esi + 24]
30 | movq mm5, [esi + 32]
31 | movq mm6, [esi + 40]
32 | movq mm7, [esi + 48]
33 | movq mm0, [esi + 56]
34 | movntq [edi + 0], mm1
35 | movntq [edi + 8], mm2
36 | movntq [edi + 16], mm3
37 | movntq [edi + 24], mm4
38 | movntq [edi + 32], mm5
39 | movntq [edi + 40], mm6
40 | movntq [edi + 48], mm7
41 | movntq [edi + 56], mm0
42 | add esi, 64
43 | add edi, 64
44 | loop .loop64
45 | emms
46 | .endloop64:
47 | mov ecx, eax
48 | and ecx, 0x3F
49 | shr ecx, 3
50 | jz .endloop8
51 | .loop8:
52 | movq mm1, [esi]
53 | movq [edi], mm1
54 | add esi, 8
55 | add edi, 8
56 | loop .loop8
57 | emms
58 | .endloop8:
59 | mov ecx, eax
60 | and ecx, 7
61 | repe movsb
62 | .done:
63 | popf
64 | pop edi
65 | pop esi
66 | mov esp, ebp
67 | pop ebp
68 | ret
69 |
70 | [GLOBAL enable_sse]
71 | enable_sse:
72 | mov eax, cr0
73 | and ax, 0xFFFB
74 | or ax, 0x2
75 | mov cr0, eax
76 | mov eax, cr4
77 | or ax, 3 << 9
78 | mov cr4, eax
79 | ret
80 |
81 | [GLOBAL gdt_flush]
82 | gdt_flush:
83 | mov eax, [esp+4]
84 | lgdt [eax]
85 | mov eax, 0x10
86 | mov ds, ax
87 | mov es, ax
88 | mov fs, ax
89 | mov gs, ax
90 | mov ss, ax
91 | jmp 0x08:.flush
92 | .flush:
93 | ret
94 |
95 | [GLOBAL idt_flush]
96 | idt_flush:
97 | mov eax, [esp+4]
98 | lidt [eax]
99 | sti
100 | ret
101 |
102 | %MACRO ISR_NOERRCODE 1
103 | [GLOBAL isr%1]
104 | isr%1:
105 | cli
106 | push byte 0
107 | push byte %1
108 | jmp isr_common_stub
109 | %ENDMACRO
110 |
111 | %MACRO ISR_ERRCODE 1
112 | [GLOBAL isr%1]
113 | isr%1:
114 | cli
115 | push byte %1
116 | jmp isr_common_stub
117 | %ENDMACRO
118 |
119 | %MACRO IRQ 2
120 | [GLOBAL irq%1]
121 | irq%1:
122 | cli
123 | push byte 0
124 | push byte %2
125 | jmp irq_common_stub
126 | %ENDMACRO
127 |
128 | ISR_NOERRCODE 0
129 | ISR_NOERRCODE 1
130 | ISR_NOERRCODE 2
131 | ISR_NOERRCODE 3
132 | ISR_NOERRCODE 4
133 | ISR_NOERRCODE 5
134 | ISR_NOERRCODE 6
135 | ISR_NOERRCODE 7
136 | ISR_ERRCODE 8
137 | ISR_NOERRCODE 9
138 | ISR_ERRCODE 10
139 | ISR_ERRCODE 11
140 | ISR_ERRCODE 12
141 | ISR_ERRCODE 13
142 | ISR_ERRCODE 14
143 | ISR_NOERRCODE 15
144 | ISR_NOERRCODE 16
145 | ISR_NOERRCODE 17
146 | ISR_NOERRCODE 18
147 | ISR_NOERRCODE 19
148 | ISR_NOERRCODE 20
149 | ISR_NOERRCODE 21
150 | ISR_NOERRCODE 22
151 | ISR_NOERRCODE 23
152 | ISR_NOERRCODE 24
153 | ISR_NOERRCODE 25
154 | ISR_NOERRCODE 26
155 | ISR_NOERRCODE 27
156 | ISR_NOERRCODE 28
157 | ISR_NOERRCODE 29
158 | ISR_NOERRCODE 30
159 | ISR_NOERRCODE 31
160 |
161 | IRQ 0, 32
162 | IRQ 1, 33
163 | IRQ 2, 34
164 | IRQ 3, 35
165 | IRQ 4, 36
166 | IRQ 5, 37
167 | IRQ 6, 38
168 | IRQ 7, 39
169 | IRQ 8, 40
170 | IRQ 9, 41
171 | IRQ 10, 42
172 | IRQ 11, 43
173 | IRQ 12, 44
174 | IRQ 13, 45
175 | IRQ 14, 46
176 | IRQ 15, 47
177 |
178 | [EXTERN isr_handler]
179 |
180 | isr_common_stub:
181 | pusha
182 | mov ax, ds
183 | push eax
184 | mov ax, 0x10
185 | mov ds, ax
186 | mov es, ax
187 | mov fs, ax
188 | mov gs, ax
189 | call isr_handler
190 | pop eax
191 | mov ds, ax
192 | mov es, ax
193 | mov fs, ax
194 | mov gs, ax
195 | popa
196 | add esp, 8
197 | sti
198 | iret
199 |
200 | [EXTERN irq_handler]
201 | irq_common_stub:
202 | pusha
203 | mov ax, ds
204 | push eax
205 | mov ax, 0x10
206 | mov ds, ax
207 | mov es, ax
208 | mov fs, ax
209 | mov gs, ax
210 | call irq_handler
211 | pop ebx
212 | mov ds, bx
213 | mov es, bx
214 | mov fs, bx
215 | mov gs, bx
216 | popa
217 | add esp, 8
218 | sti
219 | iret
--------------------------------------------------------------------------------
/src/kernel/modules.cpp:
--------------------------------------------------------------------------------
1 | #include"include/initialize.h"
2 | #include"include/stdio.h"
3 | #include"include/ata.h"
4 | #include"include/fs.h"
5 | #include"include/fat12.h"
6 | #include"include/memory.h"
7 | #include"include/dt.h"
8 | #include"include/isr.h"
9 | #include"include/keyboard.h"
10 | #include"include/mouse.h"
11 | #include"include/timer.h"
12 | #include"include/rtc.h"
13 | #include"include/math.h"
14 | #include"include/pic.h"
15 | #include"include/vga.h"
16 |
17 | extern "C" void modules(){
18 | initialize();
19 | }
--------------------------------------------------------------------------------
/src/shell/shell.c:
--------------------------------------------------------------------------------
1 | #include"shell.h"
2 |
3 | int shell(){
4 | while(true){
5 |
6 | }
7 | return 0;
8 | }
--------------------------------------------------------------------------------
/tools/toolchain:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | BINUTILS_VERSION="${BINUTILS_VERSION:-2.37}"
4 | GCC_VERSION="${GCC_VERSION:-11.2.0}"
5 |
6 | BINUTILS_URL="https://ftp.gnu.org/gnu/binutils/binutils-${BINUTILS_VERSION}.tar.xz"
7 | GCC_URL="https://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.xz"
8 |
9 | TARGET=i386-elf
10 |
11 | # ---------------------------
12 |
13 | set -e
14 |
15 | TOOLCHAINS_DIR=$PWD/tools # burayı değiştirebilirsiniz
16 | OPERATION='build'
17 |
18 | while test $# -gt 0
19 | do
20 | case "$1" in
21 | -c) OPERATION='clean'
22 | ;;
23 | *) TOOLCHAINS_DIR="$1"
24 | ;;
25 | esac
26 | shift
27 | done
28 |
29 | if [ -z "$TOOLCHAINS_DIR" ]; then
30 | echo "Missing arg: toolchains directory"
31 | exit 1
32 | fi
33 |
34 | pushd "$TOOLCHAINS_DIR"
35 | TOOLCHAIN_PREFIX="$TOOLCHAINS_DIR/$TARGET"
36 |
37 | if [ "$OPERATION" = "build" ]; then
38 |
39 | # Download and build binutils
40 | BINUTILS_SRC="binutils-${BINUTILS_VERSION}"
41 | BINUTILS_BUILD="binutils-build-${BINUTILS_VERSION}"
42 |
43 | wget ${BINUTILS_URL}
44 | tar -xf binutils-${BINUTILS_VERSION}.tar.xz
45 |
46 | mkdir -p ${BINUTILS_BUILD}
47 | pushd ${BINUTILS_BUILD}
48 | ../binutils-${BINUTILS_VERSION}/configure \
49 | --prefix="${TOOLCHAIN_PREFIX}" \
50 | --target=${TARGET} \
51 | --with-sysroot \
52 | --disable-nls \
53 | --disable-werror
54 | make -j$(nproc) # j sizin threads sayınızdır `nproc` ile bulabilirsiniz
55 | make install
56 | popd
57 |
58 | # Download and build GCC
59 | GCC_SRC="gcc-${GCC_VERSION}"
60 | GCC_BUILD="gcc-build-${GCC_VERSION}"
61 |
62 | wget ${GCC_URL}
63 | tar -xf gcc-${GCC_VERSION}.tar.xz
64 | mkdir -p ${GCC_BUILD}
65 | pushd ${GCC_BUILD}
66 | ../gcc-${GCC_VERSION}/configure \
67 | --prefix="${TOOLCHAIN_PREFIX}" \
68 | --target=${TARGET} \
69 | --disable-nls \
70 | --enable-languages=c,c++ \
71 | --without-headers
72 | make -j$(nproc) all-gcc all-target-libgcc
73 | make install-gcc install-target-libgcc
74 | popd
75 | rm *.tar.xz
76 | rm ./toolchain
77 |
78 | elif [ "$OPERATION" = "clean" ]; then
79 | rm -rf *
80 | fi
81 |
--------------------------------------------------------------------------------