diff --git a/.gitignore b/.gitignore index cbeff78..e5415bd 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ web/anket/anket *.db fatura.pdf fatura.xlsx +*.elf diff --git a/README.md b/README.md index ef9239d..cccd9c6 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # KabaLang Örnekleri Türkçe sözdizimli, derlenen programlama dili **KabaLang** ile yazılmış dokuz -çalışan proje: terminalde, masaüstünde ve tarayıcıda. Her biri tek dosyadır ve -tek komutla derlenip çalışır. +çalışan proje (terminalde, masaüstünde ve tarayıcıda) ve işletim sistemi olmadan +açılan bir çekirdek. Projelerin her biri tek dosyadır ve tek komutla derlenip çalışır. ```bash kabalang calistir konsol/fraktal/fraktal.kbl @@ -42,6 +42,14 @@ kabalang calistir konsol/fraktal/fraktal.kbl Web uygulamaları yalnız `127.0.0.1`'i dinler. Kullanıcıdan gelen her değer SQL'e **parametre olarak** bağlanır, HTML'e girerken `web.kacir` ile kaçırılır. +## Çekirdek + +| | Proje | Ne gösteriyor | +|---|---|---| +| ![](medya/minimal-kernel.png) | [**Minimal Kernel**](cekirdek/minimal-kernel) | KabaLang ile yazılmış açık kaynak x86-64 çekirdeği: kesmeler, Türkçe Q klavye, Türkçe karakterli ekran, sayfa ayırıcı, komut satırı (MPL-2.0) | + +Küçük çekirdek örnekleri (merhaba, asal sayılar, VGA renkleri): [cekirdek/](cekirdek). + --- ## Çalıştırmak @@ -61,6 +69,10 @@ kabalang calistir arayuz/parola-atolyesi/parola-atolyesi.kbl cd web/pano && kabalang calistir pano.kbl # http://127.0.0.1:8471 cd web/kisalt && kabalang calistir kisalt.kbl # http://127.0.0.1:8472 cd web/anket && kabalang calistir anket.kbl # http://127.0.0.1:8473 + +# Çekirdek (QEMU'da açılır) +cd cekirdek/minimal-kernel && kabalang derle --yalin ana.kbl -o cekirdek.elf +qemu-system-x86_64 -kernel cekirdek.elf -serial stdio ``` Yalnız derlemek için: `kabalang derle -o `. diff --git a/cekirdek/README.md b/cekirdek/README.md new file mode 100644 index 0000000..d00cecb --- /dev/null +++ b/cekirdek/README.md @@ -0,0 +1,21 @@ +# Çekirdek örnekleri + +KabaLang'ın `--yalin` (çıplak donanım) kipiyle yazılmış programlar. İşletim +sistemi olmadan, doğrudan öykünülmüş ya da gerçek bir x86-64 makinede açılırlar. + +```bash +kabalang derle --yalin merhaba/merhaba_cekirdek.kbl -o merhaba.elf +qemu-system-x86_64 -kernel merhaba.elf -serial stdio +``` + +| | Örnek | Ne gösteriyor | +|---|---|---| +| ![](../medya/minimal-kernel.png) | [**Minimal Kernel**](minimal-kernel) | Kesmeler, zamanlayıcı, Türkçe Q klavye, Türkçe karakterli ekran, sayfa ayırıcı, komut satırı | +| ![](../medya/cekirdek-merhaba.png) | [**Merhaba**](merhaba) | En küçük çekirdek: seri porta ve VGA ekranına yazar | +| ![](../medya/cekirdek-asal.png) | [**Asal sayılar**](asal-sayilar) | 2–1000 arasındaki asalları bulur, tablo olarak çizer | +| ![](../medya/cekirdek-renkler.png) | [**VGA renkleri**](renkler) | Metin kipinin renk baytı: zemin ve yazı renkleri | + +Tek dosyalı örnekler tarayıcıda da denenebilir: +[dev.kabaforce.com/kabalang/cekirdek](https://dev.kabaforce.com/kabalang/cekirdek/) + +Hepsi [MPL-2.0](minimal-kernel/LICENSE) ile yayınlanır. diff --git a/cekirdek/asal-sayilar/asal_sayilar.kbl b/cekirdek/asal-sayilar/asal_sayilar.kbl new file mode 100644 index 0000000..ea7ad8d --- /dev/null +++ b/cekirdek/asal-sayilar/asal_sayilar.kbl @@ -0,0 +1,84 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at https://mozilla.org/MPL/2.0/. +# +# Asal sayılar: çekirdek 2..1000 arasındaki asalları bulur, ekrana bir +# tablo olarak, seri porta da toplam olarak yazar. + +VGA = 0xB8000 +SERI = 0x3F8 + +fonksiyon seri_bayt(b): + iken bit_ve(port_oku8(SERI + 5), 0x20) == 0: + devam + port_yaz8(SERI, b) + +fonksiyon seri_yaz(m): + i = 0 + iken bayt(m, i) != 0: + seri_bayt(bayt(m, i)) + i = i + 1 + +fonksiyon hucre(satir, sutun, karakter, renk): + bellek_yaz16(VGA + (satir * 80 + sutun) * 2, renk * 256 + karakter) + +fonksiyon yaz(m, satir, sutun, renk): + i = 0 + iken bayt(m, i) != 0: + hucre(satir, sutun + i, bayt(m, i), renk) + i = i + 1 + +fonksiyon basamak_sayisi(n): + b = 1 + iken n >= 10: + n = n // 10 + b = b + 1 + don b + +fonksiyon sayi(n, satir, sutun, renk): + # Sağa yaslı değil, soldan yazar; kaç basamak yazıldığını döner. + b = basamak_sayisi(n) + k = b - 1 + iken k >= 0: + hucre(satir, sutun + k, 0x30 + n % 10, renk) + n = n // 10 + k = k - 1 + don b + +fonksiyon seri_sayi(n): + eger n >= 10: + seri_sayi(n // 10) + seri_bayt(0x30 + n % 10) + +fonksiyon asal_mi(n): + eger n < 2: + don yanlis + d = 2 + iken d * d <= n: + eger n % d == 0: + don yanlis + d = d + 1 + don dogru + +dongu i icinde 0..80 * 25 - 1: + bellek_yaz16(VGA + i * 2, 0x0F20) +yaz("Asal sayilar (2..1000) -- KabaLang cekirdegi", 0, 2, 0x0E) + +satir = 2 +sutun = 2 +adet = 0 +dongu n icinde 2..1000: + eger asal_mi(n): + adet = adet + 1 + sayi(n, satir, sutun, 0x0A) + sutun = sutun + 5 + eger sutun > 74: + sutun = 2 + satir = satir + 1 + +yaz("Toplam:", satir + 2, 2, 0x0F) +sayi(adet, satir + 2, 10, 0x0E) +seri_yaz("2..1000 arasinda asal sayi adedi: ") +seri_sayi(adet) +seri_bayt(10) +dur() diff --git a/cekirdek/merhaba/merhaba_cekirdek.kbl b/cekirdek/merhaba/merhaba_cekirdek.kbl new file mode 100644 index 0000000..ebf009f --- /dev/null +++ b/cekirdek/merhaba/merhaba_cekirdek.kbl @@ -0,0 +1,112 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at https://mozilla.org/MPL/2.0/. +# +# KabaLang ile yazılmış en küçük çekirdek: seri porta ve VGA metin ekranına yazar. +# +# Derle: kabalang derle --yalin merhaba_cekirdek.kbl -o cekirdek.elf +# Çalıştır: qemu-system-x86_64 -kernel cekirdek.elf -serial stdio +# +# Yalın kipte çalışma zamanı YOKTUR: metin sabitleri ham bayt dizisidir, +# donanıma `port_yaz8` (x86 out) ve `bellek_yaz16` (volatile yazma) ile +# erişilir. Önyükleme parçası (calisma/yalin/boot.S) yalnız uzun kipe geçip +# `kaba_cekirdek_ana`yı çağırır; mantığın tamamı bu dosyadadır. + +SERI = 1016 # COM1 (0x3F8) +VGA = 753664 # VGA metin belleği (0xB8000) +GENISLIK = 80 + +fonksiyon seri_hazirla(): + port_yaz8(SERI + 1, 0) # kesmeler kapalı + port_yaz8(SERI + 3, 128) # DLAB + port_yaz8(SERI + 0, 3) # 38400 baud + port_yaz8(SERI + 1, 0) + port_yaz8(SERI + 3, 3) # 8 bit, eşliksiz, 1 dur biti + port_yaz8(SERI + 2, 199) # FIFO + port_yaz8(SERI + 4, 11) + +fonksiyon seri_bayt(b): + iken port_oku8(SERI + 5) % 64 < 32: + devam + port_yaz8(SERI, b) + +fonksiyon seri_yaz(m): + i = 0 + iken bayt(m, i) != 0: + seri_bayt(bayt(m, i)) + i = i + 1 + seri_bayt(10) + +fonksiyon ekran_temizle(renk): + dongu i icinde 0..80 * 25 - 1: + bellek_yaz16(VGA + i * 2, renk * 256 + 32) + +fonksiyon ekrana_yaz_konum(m, satir, sutun, renk): + i = 0 + iken bayt(m, i) != 0: + bellek_yaz16(VGA + (satir * GENISLIK + sutun + i) * 2, renk * 256 + bayt(m, i)) + i = i + 1 + +fonksiyon ekrana_yaz(m, satir, renk): + ekrana_yaz_konum(m, satir, 0, renk) + +fonksiyon sayi_yaz(n, satir, sutun, renk): + # Ondalık yazım: `//` ve `%` yalın kipte IR içinde tanımlıdır. + basamaklar = 1 + b = n + iken b >= 10: + b = b // 10 + basamaklar = basamaklar + 1 + dongu k icinde 0..basamaklar - 1: + rakam = (n // us10(basamaklar - 1 - k)) % 10 + bellek_yaz16(VGA + (satir * GENISLIK + sutun + k) * 2, renk * 256 + 48 + rakam) + +fonksiyon us10(k): + s = 1 + dongu j icinde 1..k: + s = s * 10 + don s + +seri_hazirla() +seri_yaz("Merhaba, KabaLang! (cekirdek uzun kipte, seri port)") + +# Mavi arka plan ve çerçeve +MAVI_ZEMIN = 0x10 +ekran_temizle(MAVI_ZEMIN) + +# Çerçeve ve Başlık +ekrana_yaz_konum("+----------------------------------------------------------------------------+", 1, 1, 0x1B) +ekrana_yaz_konum("| KabaLang Minimal Kernel -- x86-64, KabaLang ile yazildi |", 2, 1, 0x1F) +ekrana_yaz_konum("+----------------------------------------------------------------------------+", 3, 1, 0x1B) + +# Durum Maddeleri +ekrana_yaz_konum("[OK]", 5, 3, 0x1A) +ekrana_yaz_konum("x86-64 Uzun Kip (64-bit Long Mode) Aktif", 5, 8, 0x1F) + +ekrana_yaz_konum("[OK]", 7, 3, 0x1A) +ekrana_yaz_konum("Calisma zamani yok: libc yok, yalniz KabaLang + LLVM", 7, 8, 0x1F) + +ekrana_yaz_konum("[OK]", 9, 3, 0x1A) +ekrana_yaz_konum("Multiboot ile acilis, ilk 1 GB birebir eslenmis sayfalar", 9, 8, 0x1F) + +ekrana_yaz_konum("[OK]", 11, 3, 0x1A) +ekrana_yaz_konum("Hesap: 1..10 kare toplami =", 11, 8, 0x1F) +toplam = 0 +dongu i icinde 1..10: + toplam = toplam + i * i +sayi_yaz(toplam, 11, 36, 0x1E) + +ekrana_yaz_konum("[OK]", 13, 3, 0x1A) +ekrana_yaz_konum("COM1 seri port (0x3F8) ve VGA 80x25 metin ekrani", 13, 8, 0x1F) + +# Alt Bilgi Çerçevesi +ekrana_yaz_konum("+----------------------------------------------------------------------------+", 16, 1, 0x1B) +ekrana_yaz_konum("| DURUM: cekirdek hazir; seri porta ve VGA metin ekranina yaziyor. |", 17, 1, 0x1E) +ekrana_yaz_konum("| NOT : Cekirdek mantiginin tamami KabaLang ile yazilmis, LLVM ile yerel |", 18, 1, 0x17) +ekrana_yaz_konum("| 64-bit ELF makine ikilisine derlenmistir. |", 19, 1, 0x17) +ekrana_yaz_konum("+----------------------------------------------------------------------------+", 20, 1, 0x1B) + +ekrana_yaz_konum(">> Cekirdek isini bitirdi, islemci durduruldu.", 22, 3, 0x1E) + +seri_yaz("VGA yazildi; cekirdek durduruluyor.") +dur() diff --git a/cekirdek/minimal-kernel/LICENSE b/cekirdek/minimal-kernel/LICENSE new file mode 100644 index 0000000..ee6256c --- /dev/null +++ b/cekirdek/minimal-kernel/LICENSE @@ -0,0 +1,373 @@ +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at https://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. diff --git a/cekirdek/minimal-kernel/README.md b/cekirdek/minimal-kernel/README.md new file mode 100644 index 0000000..72409d0 --- /dev/null +++ b/cekirdek/minimal-kernel/README.md @@ -0,0 +1,42 @@ +# KabaLang Minimal Kernel + +KabaLang ile yazılmış, LLVM ile derlenen küçük bir x86-64 çekirdeği. +Assembly yalnız açılış parçasındadır (`calisma/boot.S`); çekirdeğin mantığı KabaLang'dir. + +![KabaLang Minimal Kernel](../../medya/minimal-kernel.png) + +## İçindekiler + +| Modül | Görevi | +|---|---| +| `ana.kbl` | Giriş noktası: donanımı sırayla hazırlar, ana döngü | +| `durum.kbl` | Sabit adresli durum alanı (modüller durum tutmaz) | +| `seri.kbl` | COM1 seri port, açılış günlüğü | +| `ekran.kbl` | VGA metin ekranı, imleç, kaydırma, Türkçe yazı tipi (CP857 yerleşimi) | +| `kesme.kbl` | Kesme tablosu (IDT), PIC, 100 Hz zamanlayıcı | +| `klavye.kbl` | PS/2 klavye: Türkçe Q ve ABD düzeni, shift | +| `bellek.kbl` | Önyükleyici bellek haritası, 4 KB fiziksel sayfa ayırıcı | +| `kabuk.kbl` | Komut satırı (UTF-8 tampon), yerleşik komutlar | +| `arayuz.kbl` | Açılış paneli, Türkçe karakter vitrini | +| `calisma/` | Açılış parçası, bağlayıcı betiği ve yalın çalışma zamanı (derleyiciyle gelir; başvuru için burada) | + +Kabuk komutları Türkçe ya da ASCII yazılabilir: `yardım`, `panel`, `türkçe`, +`hakkında`, `zaman`, `yaz METİN`, `uzunluk METİN`, `klavye tr|us`, `bellek`, +`ayır`, `yığın`, `temizle`, `kapat`. + +## Derleyip çalıştırmak + +```bash +kabalang derle --yalin ana.kbl -o cekirdek.elf +qemu-system-x86_64 -kernel cekirdek.elf -serial stdio +``` + +`--yalin` kipinde işletim sistemi ve libc yoktur: donanıma `port_yaz8`, +`bellek_yaz16` gibi yerleşiklerle doğrudan erişilir. Ayrıntı: +[dev.kabaforce.com/kabalang/cekirdek](https://dev.kabaforce.com/kabalang/cekirdek/) + +## Lisans + +[Mozilla Public License 2.0](LICENSE). Bu çekirdeği temel alıp kendi çekirdeğinizi +geliştirebilirsiniz; dağıttığınızda bu dosyalarda yaptığınız değişiklikleri +açık tutarsınız. Yeni dosyalarınız için lisansı siz seçersiniz. diff --git a/cekirdek/minimal-kernel/ana.kbl b/cekirdek/minimal-kernel/ana.kbl new file mode 100644 index 0000000..89af9b8 --- /dev/null +++ b/cekirdek/minimal-kernel/ana.kbl @@ -0,0 +1,110 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at https://mozilla.org/MPL/2.0/. +# +# KabaLang mini çekirdek — giriş noktası. +# +# Derle: kabalang derle --yalin ana.kbl -o cekirdek.elf +# Çalıştır: qemu-system-x86_64 -kernel cekirdek.elf -serial stdio + +kullan "durum.kbl" +kullan "seri.kbl" +kullan "ekran.kbl" +kullan "kesme.kbl" +kullan "klavye.kbl" +kullan "bellek.kbl" +kullan "kabuk.kbl" +kullan "arayuz.kbl" + +KESME_ZAMANLAYICI = 32 +KESME_KLAVYE = 33 + +TUS_F1 = 0x3B +TUS_F2 = 0x3C +TUS_F3 = 0x3D +TUS_F4 = 0x3E +TUS_F5 = 0x3F +TUS_F10 = 0x44 + +fonksiyon kesme(vektor, kod): + eger vektor < 32: + ekran.renk(0x4F) + ekran.yaz(" ISTISNA ") + ekran.sayi(vektor) + ekran.yaz(" hata kodu ") + ekran.sayi(kod) + seri.satir("cekirdek: islemci istisnasi") + dur() + eger vektor == KESME_ZAMANLAYICI: + bellek_yaz64(durum.TIK, bellek_oku64(durum.TIK) + 1) + eger vektor == KESME_KLAVYE: + klavye.kesmede_al() + kesme.bitti(vektor) + +# ── Kurulum ────────────────────────────────────────────────────────────── +bellek_yaz64(durum.TIK, 0) +bellek_yaz64(durum.KB_YAZ, 0) +bellek_yaz64(durum.KB_OKU, 0) +bellek_yaz64(durum.KB_SHIFT, 0) +bellek_yaz64(durum.KB_DUZEN, 0) + +seri.hazirla() +seri.satir("KabaLang mini cekirdek basliyor") + +# Donanımsal Türkçe Yazı Tipi Kurulumu (VGA Plane 2) +ekran.turkce_font_kur() +seri.satir("turkce font kuruldu") + +bellek.hazirla() +seri.satir("bellek haritasi okundu") + +# Yığın: 256 sayfa (1 MB); metin işlemleri (birleştirme, f-string…) buradan ayırır. +YIGIN_SAYFA = 256 +calisma_zamani.yigin_kur(bellek.bolge_ayir(YIGIN_SAYFA), YIGIN_SAYFA * bellek.SAYFA) + +# Ön arayüz: bellek haritası ve yığın hazır olduktan sonra (f-string yığından ayırır). +arayuz.panel_ciz() +seri.satir("on arayuz cizildi") + +kesme.tabloyu_kur() +kesme.pic_hazirla() +kesme.zamanlayici_hazirla(100) +kesmeleri_ac() +seri.satir("kesmeler acik") + +kabuk.istem() + +# ── Ana döngü: kesme gelene dek uyu, gelen tuşları kabuğa ver ───────────── +iken dogru: + kesme_bekle() + iken klavye.bekleyen_var_mi(): + ham = klavye.kod_al() # bit 7 = shift + kod = klavye.tarama_kodu(ham) + eger kod == TUS_F1: + arayuz.panel_ciz() + kabuk.istem() + degilse eger kod == TUS_F2: + t = bellek_oku64(durum.TIK) + ekran.yaz("Acilistan beri: ") + ekran.sayi(t // 100) + ekran.yaz(".") + ekran.sayi((t % 100) // 10) + ekran.satir(" sn") + kabuk.istem() + degilse eger kod == TUS_F3: + bellek.haritayi_yaz() + kabuk.istem() + degilse eger kod == TUS_F4: + arayuz.turkce_vitrin() + kabuk.istem() + degilse eger kod == TUS_F5: + arayuz.panel_ciz() + kabuk.istem() + degilse eger kod == TUS_F10: + ekran.satir("Kapatılıyor...") + seri.satir("kabuk: kapat") + port_yaz16(0x604, 0x2000) + degilse: + c = klavye.karakter(ham) + eger c != 0: + kabuk.tus(c) diff --git a/cekirdek/minimal-kernel/arayuz.kbl b/cekirdek/minimal-kernel/arayuz.kbl new file mode 100644 index 0000000..68c7cb3 --- /dev/null +++ b/cekirdek/minimal-kernel/arayuz.kbl @@ -0,0 +1,71 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at https://mozilla.org/MPL/2.0/. +# +# KabaLang Minimal Kernel — açılış paneli. + +BAR_RENGI = 0x3F # Camgöbeği zemin, beyaz yazı +KART_CERCEVE = 0x1B # Mavi zemin, açık mavi çerçeve +KART_ETIKET = 0x17 # Mavi zemin, açık gri etiket +KART_DEGER = 0x1E # Mavi zemin, sarı değer +ALT_BAR_RENGI = 0x71 # Gri zemin, lacivert yazı + +fonksiyon panel_ciz(): + ekran.temizle(kabuk.YAZI_RENGI) + + # 1. Üst Sistem Durum Çubuğu (Satır 0) + ekran.satir_doldur(0, 0x20, BAR_RENGI) + mb = bellek_oku64(durum.BELLEK_TOPLAM) // 1048576 + ekran.yaz_konum(0, 2, "KabaLang Minimal Kernel - açık kaynak (MPL-2.0)", BAR_RENGI) + ekran.yaz_konum(0, 52, f"│ RAM: {mb} MB │ x86-64", BAR_RENGI) + + # 2. Sistem Bilgi Kartı (Satır 1..5) - Çift çizgili çerçeve ve dikey bölme + ekran.cerceve(1, 1, 78, 5, KART_CERCEVE) + ekran.dikey_ayrac(1, 5, 40, KART_CERCEVE) + ekran.yaz_konum(1, 28, " [ SİSTEM BİLGİSİ ] ", 0x1F) + + # Sol sütun (Sistem) + ekran.yaz_konum(2, 4, "Mimari :", KART_ETIKET) + ekran.yaz_konum(2, 14, "x86-64 Ring 0 Kip", KART_DEGER) + + ekran.yaz_konum(3, 4, "Dil :", KART_ETIKET) + ekran.yaz_konum(3, 14, "KabaLang (Natif LLVM)", KART_DEGER) + + ekran.yaz_konum(4, 4, "Durum :", KART_ETIKET) + ekran.yaz_konum(4, 14, "Kesmeler Açık (100 Hz)", KART_DEGER) + + # Sağ sütun (Kaynaklar & Font) + ekran.yaz_konum(2, 43, "Bellek :", KART_ETIKET) + ekran.yaz_konum(2, 53, f"{mb} MB kullanılabilir", KART_DEGER) + + ekran.yaz_konum(3, 43, "Yazı :", KART_ETIKET) + ekran.yaz_konum(3, 53, "UTF-8 & Donanım Fontu", KART_DEGER) + + ekran.yaz_konum(4, 43, "Seri :", KART_ETIKET) + ekran.yaz_konum(4, 53, "COM1 günlük çıkışı", KART_DEGER) + + # 3. Bölüm Ayracı (Satır 6) + ekran.yatay_cizgi(6, 0, 80, 0x13) + ekran.yaz_konum(6, 3, " [ KABUK ('yardım' yazın) ] ", 0x1E) + + # 4. Alt Kısayol Tuşları Barı (Satır 24) + ekran.satir_doldur(24, 0x20, ALT_BAR_RENGI) + ekran.yaz_konum(24, 2, "F1:Panel F2:Zaman F3:Bellek F4:Türkçe F5:Temizle F10:Kapat", ALT_BAR_RENGI) + + # İmleci kabuk başlangıç satırına (Satır 7) al + ekran.konumlandir(7, 0) + +fonksiyon turkce_vitrin(): + ekran.alt_satir() + ekran.renk(0x1F) + ekran.satir(" ╔══════════════════════════════════════════════════════════════════════════╗") + ekran.satir(" ║ Türkçe karakter vitrini (VGA yazı tipi, CP857 yerleşimi) ║") + ekran.satir(" ╚══════════════════════════════════════════════════════════════════════════╝") + ekran.renk(0x1E) + ekran.satir(" Büyük Harfler: Ç, Ğ, İ, Ö, Ş, Ü") + ekran.satir(" Küçük Harfler: ç, ğ, ı, ö, ş, ü") + ekran.renk(0x1A) + ekran.satir(" Pangram Testi: Şık ve özgün çağlayanlarda ılık göller parıldar.") + ekran.satir(" Sayılar & İmler: 0123456789 • “Tırnak” – — 'Tek'") + ekran.renk(kabuk.YAZI_RENGI) + ekran.alt_satir() diff --git a/cekirdek/minimal-kernel/bellek.kbl b/cekirdek/minimal-kernel/bellek.kbl new file mode 100644 index 0000000..647e433 --- /dev/null +++ b/cekirdek/minimal-kernel/bellek.kbl @@ -0,0 +1,133 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at https://mozilla.org/MPL/2.0/. +# +# Fiziksel bellek: önyükleyicinin bellek haritası ve 4 KB'lık sayfa ayırıcı. +# +# Ayırıcı en büyük kullanılabilir bölgeyi seçer; geri verilen sayfalar +# kendi ilk 8 baytlarında bağlı bir liste oluşturur (ek yapı gerekmez). +# Birebir eşleme ilk 1 GB'ı kapsadığı için bölge 1 GB ile sınırlanır. + +SAYFA = 4096 +ALT_SINIR = 0x400000 # çekirdek ve durum alanının üstü (4 MB) +UST_SINIR = 0x40000000 # birebir eşlenen bölgenin sonu (1 GB) +KULLANILABILIR = 1 + +# Multiboot1 bilgi yapısı (yalnız gereken alanlar, paketli). +yapi OnyuklemeBilgisi: + bayraklar: u32 = 0 + bellek_alt: u32 = 0 + bellek_ust: u32 = 0 + onyukleme_aygiti: u32 = 0 + komut_satiri: u32 = 0 + modul_sayisi: u32 = 0 + modul_adresi: u32 = 0 + simge0: u32 = 0 + simge1: u32 = 0 + simge2: u32 = 0 + simge3: u32 = 0 + harita_uzunlugu: u32 = 0 + harita_adresi: u32 = 0 + +# Bellek haritası girdisi; `boyut` kendisinden sonraki bayt sayısıdır. +yapi HaritaGirdisi: + boyut: u32 = 0 + taban: u64 = 0 + uzunluk: u64 = 0 + tur: u32 = 0 + +fonksiyon bilgi(): + don OnyuklemeBilgisi.adreste(onyukleme_bilgisi()) + +fonksiyon harita_var_mi(): + don bit_ve(bilgi().bayraklar, 0x40) != 0 + +fonksiyon hazirla(): + bellek_yaz64(durum.SAYFA_SONRAKI, 0) + bellek_yaz64(durum.SAYFA_SON, 0) + bellek_yaz64(durum.SAYFA_BOS, 0) + bellek_yaz64(durum.SAYFA_AYRILAN, 0) + bellek_yaz64(durum.BELLEK_TOPLAM, 0) + eger degil harita_var_mi(): + don 0 + b = bilgi() + adres = b.harita_adresi + son = adres + b.harita_uzunlugu + en_buyuk = 0 + iken adres < son: + g = HaritaGirdisi.adreste(adres) + eger g.tur == KULLANILABILIR: + bellek_yaz64(durum.BELLEK_TOPLAM, bellek_oku64(durum.BELLEK_TOPLAM) + g.uzunluk) + bas = g.taban + bit = g.taban + g.uzunluk + eger bas < ALT_SINIR: + bas = ALT_SINIR + eger bit > UST_SINIR: + bit = UST_SINIR + eger bit > bas ve bit - bas > en_buyuk: + en_buyuk = bit - bas + bellek_yaz64(durum.SAYFA_SONRAKI, bas) + bellek_yaz64(durum.SAYFA_SON, bit) + adres = adres + g.boyut + 4 + don 0 + +fonksiyon sayfa_ayir(): + # Boşta sayfa yoksa 0 döner. + bos = bellek_oku64(durum.SAYFA_BOS) + eger bos != 0: + bellek_yaz64(durum.SAYFA_BOS, bellek_oku64(bos)) + bellek_yaz64(durum.SAYFA_AYRILAN, bellek_oku64(durum.SAYFA_AYRILAN) + 1) + don bos + sonraki = bellek_oku64(durum.SAYFA_SONRAKI) + eger sonraki == 0 veya sonraki + SAYFA > bellek_oku64(durum.SAYFA_SON): + don 0 + bellek_yaz64(durum.SAYFA_SONRAKI, sonraki + SAYFA) + bellek_yaz64(durum.SAYFA_AYRILAN, bellek_oku64(durum.SAYFA_AYRILAN) + 1) + don sonraki + +fonksiyon bolge_ayir(sayfa_sayisi): + # Bitişik sayfalar (yığın gibi büyük bölgeler için); yer yoksa 0. + sonraki = bellek_oku64(durum.SAYFA_SONRAKI) + boyut = sayfa_sayisi * SAYFA + eger sonraki == 0 veya sonraki + boyut > bellek_oku64(durum.SAYFA_SON): + don 0 + bellek_yaz64(durum.SAYFA_SONRAKI, sonraki + boyut) + bellek_yaz64(durum.SAYFA_AYRILAN, bellek_oku64(durum.SAYFA_AYRILAN) + sayfa_sayisi) + don sonraki + +fonksiyon sayfa_birak(adres): + bellek_yaz64(adres, bellek_oku64(durum.SAYFA_BOS)) + bellek_yaz64(durum.SAYFA_BOS, adres) + bellek_yaz64(durum.SAYFA_AYRILAN, bellek_oku64(durum.SAYFA_AYRILAN) - 1) + +fonksiyon bos_sayfa_sayisi(): + don (bellek_oku64(durum.SAYFA_SON) - bellek_oku64(durum.SAYFA_SONRAKI)) // SAYFA + +fonksiyon haritayi_yaz(): + eger degil harita_var_mi(): + ekran.satir("Bellek haritasi yok.") + don 0 + b = bilgi() + adres = b.harita_adresi + son = adres + b.harita_uzunlugu + iken adres < son: + g = HaritaGirdisi.adreste(adres) + ekran.yaz(" ") + ekran.onaltilik(g.taban) + ekran.yaz(" ") + ekran.sayi(g.uzunluk // 1024) + ekran.yaz(" KB ") + eger g.tur == KULLANILABILIR: + ekran.satir("kullanilabilir") + degilse: + ekran.satir("ayrilmis") + adres = adres + g.boyut + 4 + ekran.yaz("Kullanilabilir toplam: ") + ekran.sayi(bellek_oku64(durum.BELLEK_TOPLAM) // 1048576) + ekran.satir(" MB") + ekran.yaz("Sayfa ayirici: ") + ekran.sayi(bellek_oku64(durum.SAYFA_AYRILAN)) + ekran.yaz(" sayfa dagitildi, ") + ekran.sayi(bos_sayfa_sayisi()) + ekran.satir(" sayfa bos") + don 0 diff --git a/cekirdek/minimal-kernel/calisma/boot.S b/cekirdek/minimal-kernel/calisma/boot.S new file mode 100644 index 0000000..7919a68 --- /dev/null +++ b/cekirdek/minimal-kernel/calisma/boot.S @@ -0,0 +1,149 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ +/* KabaLang yalın (çıplak donanım) çekirdek önyükleme parçası. + * + * Görevi YALNIZ: Multiboot1 başlığı (QEMU `-kernel` ve GRUB yükler), + * 32 bit korumalı kipten 64 bit uzun kipe geçiş, yığın, ve KabaLang + * programının giriş işlevine (`kaba_cekirdek_ana`) atlamak. Çekirdeğin + * MANTIĞI bu dosyada değil, `.kbl` kaynağındadır. + * + * Bellek: ilk 1 GB, 2 MB'lık sayfalarla birebir (identity) eşlenir. + */ + .set MB_SIHIR, 0x1BADB002 + .set MB_BAYRAK, 0x00000003 /* sayfa hizalı modüller + bellek bilgisi */ + .set MB_SAGLAMA, -(MB_SIHIR + MB_BAYRAK) + + .section .multiboot, "a" + .align 4 + .long MB_SIHIR, MB_BAYRAK, MB_SAGLAMA + + .section .bss + .align 4096 + .global kaba_yigin_durumu +kaba_yigin_durumu: /* yalın çalışma zamanının yığın durumu */ + .skip 64 + .align 4096 +pml4: .skip 4096 +pdpt: .skip 4096 +pd: .skip 4096 +yigin_alt: + .skip 65536 +yigin_ust: + + .section .data + .align 8 + .global kaba_onyukleme_bilgisi +kaba_onyukleme_bilgisi: + .quad 0 + + .section .rodata + .align 8 +gdt64: + .quad 0 /* boş tanımlayıcı */ + .quad 0x00AF9A000000FFFF /* 64 bit kod kesimi */ + .quad 0x00CF92000000FFFF /* veri kesimi */ +gdt64_son: +gdt64_gosterge: + .word gdt64_son - gdt64 - 1 + .quad gdt64 + + .section .text + .code32 + .global _start +_start: + cli + mov $yigin_ust, %esp + mov %ebx, kaba_onyukleme_bilgisi /* Multiboot bilgi yapısının adresi */ + + /* PML4[0] → PDPT, PDPT[0] → PD, PD[i] → i*2MB (büyük sayfa) */ + mov $pdpt, %eax + or $0x3, %eax + mov %eax, pml4 + mov $pd, %eax + or $0x3, %eax + mov %eax, pdpt + xor %ecx, %ecx +1: mov %ecx, %eax + shl $21, %eax + or $0x83, %eax /* var + yazılabilir + büyük sayfa */ + mov %eax, pd(,%ecx,8) + inc %ecx + cmp $512, %ecx + jne 1b + + mov $pml4, %eax /* CR3 = PML4 */ + mov %eax, %cr3 + mov %cr4, %eax /* PAE */ + or $0x20, %eax + mov %eax, %cr4 + mov $0xC0000080, %ecx /* EFER.LME */ + rdmsr + or $0x100, %eax + wrmsr + mov %cr0, %eax /* sayfalama + korumalı kip */ + or $0x80000001, %eax + mov %eax, %cr0 + + lgdt gdt64_gosterge + ljmp $0x08, $uzun_kip + + .code64 +uzun_kip: + mov $0x10, %ax + mov %ax, %ds + mov %ax, %es + mov %ax, %ss + xor %ax, %ax + mov %ax, %fs + mov %ax, %gs + mov $yigin_ust, %rsp + xor %rbp, %rbp + call kaba_cekirdek_ana +2: cli + hlt + jmp 2b + +/* ── Kesme girişleri ──────────────────────────────────────────────────── + * 0–31 işlemci istisnaları, 32–47 PIC donanım kesmeleri (yeniden eşlenmiş). + * Her giriş: (hata kodu yoksa 0) + vektör yığına → ortak giriş → KabaLang + * `kesme(vektor, kod)` (dışa `kaba_kesme`). Yazmaçlar saklanır; yığın + * `call` anında 16 bayt hizalıdır (5 CPU + 2 giriş + 15 yazmaç = 22×8 = 176). + * Çekirdek `-mgeneral-regs-only` derlendiği için SSE durumu saklanmaz. */ + /* CPU'nun hata kodu ittiği istisnalar: 8, 10–14, 17, 21, 29, 30. */ + .irp n, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47 +kesme_giris_\n: + .if (\n == 8) || (\n >= 10 && \n <= 14) || (\n == 17) || (\n == 21) || (\n == 29) || (\n == 30) + .else + push $0 + .endif + push $\n + jmp kesme_ortak + .endr + +kesme_ortak: + .irp r, rax,rbx,rcx,rdx,rsi,rdi,rbp,r8,r9,r10,r11,r12,r13,r14,r15 + push %\r + .endr + mov 120(%rsp), %rdi /* vektör */ + mov 128(%rsp), %rsi /* hata kodu */ + cld + call kaba_kesme + .irp r, r15,r14,r13,r12,r11,r10,r9,r8,rbp,rdi,rsi,rdx,rcx,rbx,rax + pop %\r + .endr + add $16, %rsp /* vektör + hata kodu */ + iretq + +/* Program `kesme` işlevi tanımlamadıysa: hiçbir şey yapma. */ + .weak kaba_kesme +kaba_kesme: + ret + + .section .rodata + .align 8 + .global kaba_kesme_girisleri +kaba_kesme_girisleri: + .irp n, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47 + .quad kesme_giris_\n + .endr diff --git a/cekirdek/minimal-kernel/calisma/calisma_zamani.kbl b/cekirdek/minimal-kernel/calisma/calisma_zamani.kbl new file mode 100644 index 0000000..e948fc6 --- /dev/null +++ b/cekirdek/minimal-kernel/calisma/calisma_zamani.kbl @@ -0,0 +1,318 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at https://mozilla.org/MPL/2.0/. +# +# KabaLang yalın çalışma zamanı — KabaLang ile yazılmıştır. +# +# Yalın (çıplak donanım) derlemelere kendiliğinden eklenir. Buradaki +# `kaba_*` adlı işlevler, normal LLVM yolunda C++ çalışma zamanının verdiği +# C ABI işlevlerinin karşılığıdır; üreteç onları aynı adla dışa açar +# (işaretçiler burada 64 bit sayı olarak görünür). Böylece metin işlemleri +# (birleştirme, karşılaştırma, uzunluk, parça…) çekirdekte de normal +# KabaLang yazımıyla kullanılabilir. +# +# Yığın: `yigin_kur(adres, boyut)` ile çekirdeğin verdiği bölge. İlk uyan +# boş blok kullanılır, büyük blok bölünür; boş blok yoksa bölgenin +# sonundan ilerlenir. Bellek biterse işlemci durdurulur. +# +# Metin düzeni: [sayaç: 8][uzunluk (bayt): 8][baytlar][0] +# sayaç < 0 → ölümsüz (derleme zamanında gömülen sabit metin). +# Uzunluk ve indeks KOD NOKTASI üzerinden çalışır (UTF-8). + +BASLIK = 16 # blok başlığı: [boyut][sonraki] +METIN_BASLIK = 16 # metin başlığı: [sayaç][uzunluk] + +# Yığın durumu `yigin_durumu()` adresindedir (önyükleme parçasında 64 bayt). +BOS_LISTE = 0 +KULLANILAN = 8 +SINIR = 16 +SON = 24 + +# ── yığın ──────────────────────────────────────────────────────────────── +fonksiyon yigin_kur(adres, boyut): + d = yigin_durumu() + bellek_yaz64(d + BOS_LISTE, 0) + bellek_yaz64(d + KULLANILAN, 0) + bellek_yaz64(d + SINIR, adres) + bellek_yaz64(d + SON, adres + boyut) + +fonksiyon yigin_kullanilan(): + don bellek_oku64(yigin_durumu() + KULLANILAN) + +fonksiyon kaba_ayir(n): + d = yigin_durumu() + boyut = bit_ve(n + 15, bit_degil(15)) + BASLIK + onceki = 0 + blok = bellek_oku64(d + BOS_LISTE) + iken blok != 0: + bb = bellek_oku64(blok) + eger bb >= boyut: + eger bb - boyut >= 64: + # Bloğun SONUNDAN kes; kalan parça listede kalır. + bellek_yaz64(blok, bb - boyut) + yeni = blok + bb - boyut + bellek_yaz64(yeni, boyut) + bellek_yaz64(d + KULLANILAN, bellek_oku64(d + KULLANILAN) + boyut) + don yeni + BASLIK + sonraki = bellek_oku64(blok + 8) + eger onceki == 0: + bellek_yaz64(d + BOS_LISTE, sonraki) + degilse: + bellek_yaz64(onceki + 8, sonraki) + bellek_yaz64(d + KULLANILAN, bellek_oku64(d + KULLANILAN) + bb) + don blok + BASLIK + onceki = blok + blok = bellek_oku64(blok + 8) + sinir = bellek_oku64(d + SINIR) + eger sinir == 0 veya sinir + boyut > bellek_oku64(d + SON): + dur() + bellek_yaz64(d + SINIR, sinir + boyut) + bellek_yaz64(sinir, boyut) + bellek_yaz64(d + KULLANILAN, bellek_oku64(d + KULLANILAN) + boyut) + don sinir + BASLIK + +fonksiyon kaba_serbest(p): + eger p == 0: + don 0 + d = yigin_durumu() + blok = p - BASLIK + bellek_yaz64(d + KULLANILAN, bellek_oku64(d + KULLANILAN) - bellek_oku64(blok)) + bellek_yaz64(blok + 8, bellek_oku64(d + BOS_LISTE)) + bellek_yaz64(d + BOS_LISTE, blok) + don 0 + +# ── metin yardımcıları ─────────────────────────────────────────────────── +fonksiyon bayt_uzunluk(m): + don bellek_oku64(m + 8) + +fonksiyon veri(m): + don m + METIN_BASLIK + +fonksiyon yeni_metin(n): + m = kaba_ayir(METIN_BASLIK + n + 1) + bellek_yaz64(m, 1) + bellek_yaz64(m + 8, n) + bellek_yaz8(m + METIN_BASLIK + n, 0) + don m + +fonksiyon kopyala(hedef, kaynak, n): + dongu i icinde 0..n - 1: + bellek_yaz8(hedef + i, bellek_oku8(kaynak + i)) + +fonksiyon devam_bayti_mi(b): + don bit_ve(b, 0xC0) == 0x80 + +fonksiyon kod_noktasi_ofseti(m, k): + # k. kod noktasının bayt ofseti; k uzunluğa eşitse bayt uzunluğu. + n = bayt_uzunluk(m) + i = 0 + sayac = 0 + iken i < n: + eger degil devam_bayti_mi(bellek_oku8(veri(m) + i)): + eger sayac == k: + don i + sayac = sayac + 1 + i = i + 1 + don n + +fonksiyon alt_metin(m, bas, son): + # [bas, son) bayt aralığından yeni metin. + r = yeni_metin(son - bas) + kopyala(veri(r), veri(m) + bas, son - bas) + don r + +# ── C ABI karşılıkları (normal yolda kaba_rt.cpp) ──────────────────────── +fonksiyon kaba_m_tut(m): + eger m != 0 ve bellek_oku64(m) >= 0: + bellek_yaz64(m, bellek_oku64(m) + 1) + +fonksiyon kaba_m_birak(m): + eger m == 0: + don 0 + s = bellek_oku64(m) + eger s > 0: + eger s == 1: + kaba_serbest(m) + degilse: + bellek_yaz64(m, s - 1) + don 0 + +fonksiyon kaba_m_sabit(p, n): + r = yeni_metin(n) + kopyala(veri(r), p, n) + don r + +fonksiyon kaba_m_cden(p): + n = 0 + iken bellek_oku8(p + n) != 0: + n = n + 1 + don kaba_m_sabit(p, n) + +fonksiyon kaba_m_birlestir(a, b): + la = bayt_uzunluk(a) + lb = bayt_uzunluk(b) + r = yeni_metin(la + lb) + kopyala(veri(r), veri(a), la) + kopyala(veri(r) + la, veri(b), lb) + don r + +fonksiyon kaba_m_birlestir_tasi(a, b): + # Sol taraf geçicidir: sonuç üretilir, sol bırakılır. + r = kaba_m_birlestir(a, b) + kaba_m_birak(a) + don r + +fonksiyon kaba_m_karsilastir(a, b): + la = bayt_uzunluk(a) + lb = bayt_uzunluk(b) + n = la + eger lb < n: + n = lb + dongu i icinde 0..n - 1: + x = bellek_oku8(veri(a) + i) + y = bellek_oku8(veri(b) + i) + eger x < y: + don 0 - 1 + eger x > y: + don 1 + eger la < lb: + don 0 - 1 + eger la > lb: + don 1 + don 0 + +fonksiyon kaba_m_esit(a, b): + eger bayt_uzunluk(a) != bayt_uzunluk(b): + don 0 + eger kaba_m_karsilastir(a, b) == 0: + don 1 + don 0 + +fonksiyon kaba_m_uzunluk(m): + n = bayt_uzunluk(m) + sayac = 0 + dongu i icinde 0..n - 1: + eger degil devam_bayti_mi(bellek_oku8(veri(m) + i)): + sayac = sayac + 1 + don sayac + +fonksiyon kaba_m_bos_mu(m): + eger bayt_uzunluk(m) == 0: + don 1 + don 0 + +fonksiyon kaba_m_sayidan(n): + eksi = n < 0 + eger eksi: + n = 0 - n + basamak = 1 + b = n + iken b >= 10: + b = b // 10 + basamak = basamak + 1 + uzun = basamak + eger eksi: + uzun = uzun + 1 + r = yeni_metin(uzun) + eger eksi: + bellek_yaz8(veri(r), 0x2D) + k = uzun - 1 + dongu j icinde 1..basamak: + bellek_yaz8(veri(r) + k, 0x30 + n % 10) + n = n // 10 + k = k - 1 + don r + +fonksiyon kaba_m_sayiya(m): + n = bayt_uzunluk(m) + i = 0 + eksi = yanlis + eger n > 0 ve bellek_oku8(veri(m)) == 0x2D: + eksi = dogru + i = 1 + sonuc = 0 + iken i < n: + c = bellek_oku8(veri(m) + i) + eger c < 0x30 veya c > 0x39: + don 0 + sonuc = sonuc * 10 + (c - 0x30) + i = i + 1 + eger eksi: + don 0 - sonuc + don sonuc + +fonksiyon kaba_m_mantiktan(b): + eger b != 0: + don kaba_m_cden(veri_adresi("doğru")) + don kaba_m_cden(veri_adresi("yanlış")) + +fonksiyon kaba_m_oge(m, i, satir): + n = kaba_m_uzunluk(m) + eger i < 0: + i = i + n + eger i < 0 veya i >= n: + dur() + don alt_metin(m, kod_noktasi_ofseti(m, i), kod_noktasi_ofseti(m, i + 1)) + +fonksiyon kaba_m_parca(m, bas, uzunluk): + n = kaba_m_uzunluk(m) + eger bas < 0: + bas = 0 + eger bas > n: + bas = n + son = n + eger uzunluk >= 0 ve bas + uzunluk < n: + son = bas + uzunluk + don alt_metin(m, kod_noktasi_ofseti(m, bas), kod_noktasi_ofseti(m, son)) + +fonksiyon kaba_m_ile_baslar(m, onek): + lo = bayt_uzunluk(onek) + eger lo > bayt_uzunluk(m): + don 0 + dongu i icinde 0..lo - 1: + eger bellek_oku8(veri(m) + i) != bellek_oku8(veri(onek) + i): + don 0 + don 1 + +fonksiyon bayt_bul(m, parca): + lm = bayt_uzunluk(m) + lp = bayt_uzunluk(parca) + eger lp == 0: + don 0 + i = 0 + iken i + lp <= lm: + tutar = dogru + j = 0 + iken tutar ve j < lp: + eger bellek_oku8(veri(m) + i + j) != bellek_oku8(veri(parca) + j): + tutar = yanlis + j = j + 1 + eger tutar: + don i + i = i + 1 + don 0 - 1 + +fonksiyon kaba_m_icerir(m, parca): + eger bayt_bul(m, parca) >= 0: + don 1 + don 0 + +fonksiyon kaba_m_bul(m, parca): + b = bayt_bul(m, parca) + eger b < 0: + don 0 - 1 + # bayt ofsetinden kod noktası dizinine + sayac = 0 + dongu i icinde 0..b - 1: + eger degil devam_bayti_mi(bellek_oku8(veri(m) + i)): + sayac = sayac + 1 + don sayac + +fonksiyon kaba_m_tekrarla(m, n): + l = bayt_uzunluk(m) + eger n < 0: + n = 0 + r = yeni_metin(l * n) + dongu k icinde 0..n - 1: + kopyala(veri(r) + k * l, veri(m), l) + don r diff --git a/cekirdek/minimal-kernel/calisma/cekirdek.ld b/cekirdek/minimal-kernel/calisma/cekirdek.ld new file mode 100644 index 0000000..0668247 --- /dev/null +++ b/cekirdek/minimal-kernel/calisma/cekirdek.ld @@ -0,0 +1,17 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ +/* KabaLang yalın çekirdek bağlayıcı betiği — 1 MB'tan başlar (Multiboot1). */ +ENTRY(_start) +SECTIONS +{ + . = 1M; + .text : ALIGN(4K) { + KEEP(*(.multiboot)) + *(.text .text.*) + } + .rodata : ALIGN(4K) { *(.rodata .rodata.*) } + .data : ALIGN(4K) { *(.data .data.*) } + .bss : ALIGN(4K) { *(COMMON) *(.bss .bss.*) } + /DISCARD/ : { *(.comment) *(.note*) *(.eh_frame*) } +} diff --git a/cekirdek/minimal-kernel/durum.kbl b/cekirdek/minimal-kernel/durum.kbl new file mode 100644 index 0000000..62bbfae --- /dev/null +++ b/cekirdek/minimal-kernel/durum.kbl @@ -0,0 +1,29 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at https://mozilla.org/MPL/2.0/. +# +# Çekirdeğin sabit adresli durum alanı (statik veri bölgesi). +# +# Yalın kipte yığın (heap) yoktur; değişen durum bu adreslerde tutulur. +# İlk 1 GB birebir eşlendiği için (boot.S) adresler fiziksel adrestir. + +ALAN = 0x300000 + +TIK = ALAN + 0x00 # zamanlayıcı kesmesi sayacı (100 Hz) +KB_YAZ = ALAN + 0x08 # klavye kuyruğu: yazma konumu +KB_OKU = ALAN + 0x10 # klavye kuyruğu: okuma konumu +SATIR = ALAN + 0x18 # ekran imleci satırı +SUTUN = ALAN + 0x20 # ekran imleci sütunu +RENK = ALAN + 0x28 # geçerli yazı rengi +SATIR_UZUNLUK = ALAN + 0x30 # kabuk satırındaki karakter sayısı +SAYFA_SONRAKI = ALAN + 0x38 # sayfa ayırıcı: henüz dağıtılmamış ilk adres +SAYFA_SON = ALAN + 0x40 # sayfa ayırıcı: bölgenin sonu +SAYFA_BOS = ALAN + 0x48 # sayfa ayırıcı: geri verilen sayfaların listesi +SAYFA_AYRILAN = ALAN + 0x50 # şu an dağıtılmış sayfa sayısı +BELLEK_TOPLAM = ALAN + 0x58 # kullanılabilir RAM (bayt) +KB_SHIFT = ALAN + 0x60 # klavye: shift basılı mı (1/0) +KB_DUZEN = ALAN + 0x68 # klavye düzeni: 0 Türkçe Q, 1 ABD + +KB_TAMPON = ALAN + 0x100 # 256 baytlık klavye kuyruğu +KABUK_TAMPON = ALAN + 0x200 # 128 baytlık komut satırı +IDT = ALAN + 0x1000 # kesme tanımlayıcı tablosu (48 × 16 bayt) diff --git a/cekirdek/minimal-kernel/ekran.kbl b/cekirdek/minimal-kernel/ekran.kbl new file mode 100644 index 0000000..199a9ce --- /dev/null +++ b/cekirdek/minimal-kernel/ekran.kbl @@ -0,0 +1,428 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at https://mozilla.org/MPL/2.0/. +# +# VGA metin kipi sürücüsü: 80×25, imleç, kaydırma, sayı yazımı, UTF-8 & Türkçe font. + +VGA = 0xB8000 +GENISLIK = 80 +YUKSEKLIK = 25 + +fonksiyon font_cizgi(kod, satir, bayt): + bellek_yaz8(0xA0000 + kod * 32 + satir, bayt) + +fonksiyon glif_temizle(kod): + dongu s icinde 0..31: + font_cizgi(kod, s, 0) + +fonksiyon turkce_font_kur(): + # VGA Plane 2 (yazı tipi belleği) erişimini aç + port_yaz8(0x3C4, 0x02) + port_yaz8(0x3C5, 0x04) + port_yaz8(0x3C4, 0x04) + port_yaz8(0x3C5, 0x07) + + port_yaz8(0x3CE, 0x05) + port_yaz8(0x3CF, 0x00) + port_yaz8(0x3CE, 0x06) + port_yaz8(0x3CF, 0x00) + + # 1. ı (0x8D - küçük noktasız ı, otantik IBM CP857) + glif_temizle(0x8D) + font_cizgi(0x8D, 5, 0x38) + font_cizgi(0x8D, 6, 0x18) + font_cizgi(0x8D, 7, 0x18) + font_cizgi(0x8D, 8, 0x18) + font_cizgi(0x8D, 9, 0x18) + font_cizgi(0x8D, 10, 0x18) + font_cizgi(0x8D, 11, 0x3C) + + # 2. İ (0x98 - büyük noktalı İ, otantik IBM CP857) + glif_temizle(0x98) + font_cizgi(0x98, 1, 0x18) + font_cizgi(0x98, 3, 0x3C) + font_cizgi(0x98, 4, 0x18) + font_cizgi(0x98, 5, 0x18) + font_cizgi(0x98, 6, 0x18) + font_cizgi(0x98, 7, 0x18) + font_cizgi(0x98, 8, 0x18) + font_cizgi(0x98, 9, 0x18) + font_cizgi(0x98, 10, 0x18) + font_cizgi(0x98, 11, 0x3C) + + # 3. ş (0x9F - küçük ş, otantik IBM CP857) + glif_temizle(0x9F) + font_cizgi(0x9F, 5, 0x7C) + font_cizgi(0x9F, 6, 0xC6) + font_cizgi(0x9F, 7, 0x60) + font_cizgi(0x9F, 8, 0x38) + font_cizgi(0x9F, 9, 0x0C) + font_cizgi(0x9F, 10, 0xC6) + font_cizgi(0x9F, 11, 0x7C) + font_cizgi(0x9F, 12, 0x18) + font_cizgi(0x9F, 13, 0x30) + + # 4. Ş (0x9E - büyük Ş, otantik IBM CP857) + glif_temizle(0x9E) + font_cizgi(0x9E, 2, 0x7C) + font_cizgi(0x9E, 3, 0xC6) + font_cizgi(0x9E, 4, 0xC6) + font_cizgi(0x9E, 5, 0x60) + font_cizgi(0x9E, 6, 0x38) + font_cizgi(0x9E, 7, 0x0C) + font_cizgi(0x9E, 8, 0x06) + font_cizgi(0x9E, 9, 0xC6) + font_cizgi(0x9E, 10, 0xC6) + font_cizgi(0x9E, 11, 0x7C) + font_cizgi(0x9E, 12, 0x18) + font_cizgi(0x9E, 13, 0x30) + + # 5. ğ (0xA7 - küçük yumuşak ğ, otantik IBM CP857) + glif_temizle(0xA7) + font_cizgi(0xA7, 2, 0xCC) + font_cizgi(0xA7, 3, 0x78) + font_cizgi(0xA7, 5, 0x76) + font_cizgi(0xA7, 6, 0xCC) + font_cizgi(0xA7, 7, 0xCC) + font_cizgi(0xA7, 8, 0xCC) + font_cizgi(0xA7, 9, 0xCC) + font_cizgi(0xA7, 10, 0xCC) + font_cizgi(0xA7, 11, 0x7C) + font_cizgi(0xA7, 12, 0x0C) + font_cizgi(0xA7, 13, 0xCC) + font_cizgi(0xA7, 14, 0x78) + + # 6. Ğ (0xA6 - büyük yumuşak Ğ, otantik IBM CP857) + glif_temizle(0xA6) + font_cizgi(0xA6, 1, 0x66) + font_cizgi(0xA6, 2, 0x7E) + font_cizgi(0xA6, 3, 0x3C) + font_cizgi(0xA6, 4, 0x66) + font_cizgi(0xA6, 5, 0xC2) + font_cizgi(0xA6, 6, 0xC0) + font_cizgi(0xA6, 7, 0xC0) + font_cizgi(0xA6, 8, 0xDE) + font_cizgi(0xA6, 9, 0xC6) + font_cizgi(0xA6, 10, 0x6E) + font_cizgi(0xA6, 11, 0x3A) + + # 7. ç (0x87 - küçük ç, otantik IBM CP857) + glif_temizle(0x87) + font_cizgi(0x87, 5, 0x7C) + font_cizgi(0x87, 6, 0xC6) + font_cizgi(0x87, 7, 0xC0) + font_cizgi(0x87, 8, 0xC0) + font_cizgi(0x87, 9, 0xC0) + font_cizgi(0x87, 10, 0xC6) + font_cizgi(0x87, 11, 0x7C) + font_cizgi(0x87, 12, 0x18) + font_cizgi(0x87, 13, 0x30) + + # 8. Ç (0x80 - büyük Ç, otantik IBM CP857) + glif_temizle(0x80) + font_cizgi(0x80, 2, 0x3C) + font_cizgi(0x80, 3, 0x66) + font_cizgi(0x80, 4, 0xC2) + font_cizgi(0x80, 5, 0xC0) + font_cizgi(0x80, 6, 0xC0) + font_cizgi(0x80, 7, 0xC0) + font_cizgi(0x80, 8, 0xC0) + font_cizgi(0x80, 9, 0xC2) + font_cizgi(0x80, 10, 0x66) + font_cizgi(0x80, 11, 0x3C) + font_cizgi(0x80, 12, 0x18) + font_cizgi(0x80, 13, 0x30) + + # 9. ö (0x94 - küçük ö, otantik IBM CP857) + glif_temizle(0x94) + font_cizgi(0x94, 2, 0xC6) + font_cizgi(0x94, 5, 0x7C) + font_cizgi(0x94, 6, 0xC6) + font_cizgi(0x94, 7, 0xC6) + font_cizgi(0x94, 8, 0xC6) + font_cizgi(0x94, 9, 0xC6) + font_cizgi(0x94, 10, 0xC6) + font_cizgi(0x94, 11, 0x7C) + + # 10. Ö (0x99 - büyük Ö, otantik IBM CP857) + glif_temizle(0x99) + font_cizgi(0x99, 1, 0xC6) + font_cizgi(0x99, 3, 0x7C) + font_cizgi(0x99, 4, 0xC6) + font_cizgi(0x99, 5, 0xC6) + font_cizgi(0x99, 6, 0xC6) + font_cizgi(0x99, 7, 0xC6) + font_cizgi(0x99, 8, 0xC6) + font_cizgi(0x99, 9, 0xC6) + font_cizgi(0x99, 10, 0xC6) + font_cizgi(0x99, 11, 0x7C) + + # 11. ü (0x81 - küçük ü, otantik IBM CP857) + glif_temizle(0x81) + font_cizgi(0x81, 2, 0xCC) + font_cizgi(0x81, 5, 0xCC) + font_cizgi(0x81, 6, 0xCC) + font_cizgi(0x81, 7, 0xCC) + font_cizgi(0x81, 8, 0xCC) + font_cizgi(0x81, 9, 0xCC) + font_cizgi(0x81, 10, 0xCC) + font_cizgi(0x81, 11, 0x76) + + # 12. Ü (0x9A - büyük Ü, otantik IBM CP857) + glif_temizle(0x9A) + font_cizgi(0x9A, 1, 0xC6) + font_cizgi(0x9A, 3, 0xC6) + font_cizgi(0x9A, 4, 0xC6) + font_cizgi(0x9A, 5, 0xC6) + font_cizgi(0x9A, 6, 0xC6) + font_cizgi(0x9A, 7, 0xC6) + font_cizgi(0x9A, 8, 0xC6) + font_cizgi(0x9A, 9, 0xC6) + font_cizgi(0x9A, 10, 0xC6) + font_cizgi(0x9A, 11, 0x7C) + + # Standart metin kipine geri dön + port_yaz8(0x3C4, 0x02) + port_yaz8(0x3C5, 0x03) + port_yaz8(0x3C4, 0x04) + port_yaz8(0x3C5, 0x03) + + port_yaz8(0x3CE, 0x04) + port_yaz8(0x3CF, 0x00) + port_yaz8(0x3CE, 0x05) + port_yaz8(0x3CF, 0x10) + port_yaz8(0x3CE, 0x06) + port_yaz8(0x3CF, 0x0E) + +fonksiyon hucre(satir, sutun, karakter, renk): + bellek_yaz16(VGA + (satir * GENISLIK + sutun) * 2, renk * 256 + karakter) + +fonksiyon imleci_tasi(satir, sutun): + konum = satir * GENISLIK + sutun + port_yaz8(0x3D4, 0x0F) + port_yaz8(0x3D5, bit_ve(konum, 0xFF)) + port_yaz8(0x3D4, 0x0E) + port_yaz8(0x3D5, bit_ve(saga_kaydir(konum, 8), 0xFF)) + +fonksiyon konumlandir(satir, sutun): + bellek_yaz64(durum.SATIR, satir) + bellek_yaz64(durum.SUTUN, sutun) + imleci_tasi(satir, sutun) + +fonksiyon temizle(renk): + dongu i icinde 0..GENISLIK * YUKSEKLIK - 1: + bellek_yaz16(VGA + i * 2, renk * 256 + 0x20) + konumlandir(0, 0) + bellek_yaz64(durum.RENK, renk) + +fonksiyon renk(r): + bellek_yaz64(durum.RENK, r) + +fonksiyon kaydir(): + dongu i icinde 0..GENISLIK * (YUKSEKLIK - 1) - 1: + bellek_yaz16(VGA + i * 2, bellek_oku16(VGA + (i + GENISLIK) * 2)) + r = bellek_oku64(durum.RENK) + dongu s icinde 0..GENISLIK - 1: + hucre(YUKSEKLIK - 1, s, 0x20, r) + +fonksiyon alt_satir(): + bellek_yaz64(durum.SUTUN, 0) + satir = bellek_oku64(durum.SATIR) + 1 + eger satir >= YUKSEKLIK: + kaydir() + satir = YUKSEKLIK - 1 + bellek_yaz64(durum.SATIR, satir) + +fonksiyon karakter(c): + eger c == 0x0A: + alt_satir() + degilse: + hucre(bellek_oku64(durum.SATIR), bellek_oku64(durum.SUTUN), c, bellek_oku64(durum.RENK)) + sutun = bellek_oku64(durum.SUTUN) + 1 + bellek_yaz64(durum.SUTUN, sutun) + eger sutun >= GENISLIK: + alt_satir() + imleci_tasi(bellek_oku64(durum.SATIR), bellek_oku64(durum.SUTUN)) + +fonksiyon geri_sil(): + sutun = bellek_oku64(durum.SUTUN) + eger sutun > 0: + bellek_yaz64(durum.SUTUN, sutun - 1) + hucre(bellek_oku64(durum.SATIR), sutun - 1, 0x20, bellek_oku64(durum.RENK)) + imleci_tasi(bellek_oku64(durum.SATIR), sutun - 1) + +fonksiyon turkce_kod(b, b2): + eger b == 0xC3: + eger b2 == 0xA7: don 0x87 # ç + eger b2 == 0x87: don 0x80 # Ç + eger b2 == 0xB6: don 0x94 # ö + eger b2 == 0x96: don 0x99 # Ö + eger b2 == 0xBC: don 0x81 # ü + eger b2 == 0x9C: don 0x9A # Ü + degilse eger b == 0xC4: + eger b2 == 0x9F: don 0xA7 # ğ + eger b2 == 0x9E: don 0xA6 # Ğ + eger b2 == 0xB1: don 0x8D # ı + eger b2 == 0xB0: don 0x98 # İ + degilse eger b == 0xC5: + eger b2 == 0x9F: don 0x9F # ş + eger b2 == 0x9E: don 0x9E # Ş + don 0 + +fonksiyon utf8_uc_bayt(b1, b2, b3): + eger b1 == 0xE2: + eger b2 == 0x94: + eger b3 == 0x80: don 0xC4 # ─ (tek yatay çizgi) + eger b3 == 0x82: don 0xB3 # │ (tek dikey çizgi) + eger b3 == 0x8C: don 0xDA # ┌ + eger b3 == 0x90: don 0xBF # ┐ + eger b3 == 0x94: don 0xC0 # └ + eger b3 == 0x98: don 0xD9 # ┘ + eger b3 == 0x9C: don 0xC3 # ├ + eger b3 == 0xA4: don 0xB4 # ┤ + eger b3 == 0xAC: don 0xC2 # ┬ + eger b3 == 0xB4: don 0xC1 # ┴ + eger b3 == 0xBC: don 0xC5 # ┼ + degilse eger b2 == 0x95: + eger b3 == 0x90: don 0xCD # ═ (çift yatay çizgi) + eger b3 == 0x91: don 0xBA # ║ (çift dikey çizgi) + eger b3 == 0x94: don 0xC9 # ╔ (çift sol üst köşe) + eger b3 == 0x97: don 0xBB # ╗ (çift sağ üst köşe) + eger b3 == 0x9A: don 0xC8 # ╚ (çift sol alt köşe) + eger b3 == 0x9D: don 0xBC # ╝ (çift sağ alt köşe) + eger b3 == 0xA6: don 0xCB # ╦ (çift üst birleşim) + eger b3 == 0xA9: don 0xCA # ╩ (çift alt birleşim) + eger b3 == 0xAC: don 0xCE # ╬ (çift artı) + degilse eger b2 == 0x96: + eger b3 == 0x88: don 0xDB # █ (dolu blok) + eger b3 == 0x91: don 0xB0 # ░ (açık gölge) + eger b3 == 0x92: don 0xB1 # ▒ (orta gölge) + eger b3 == 0x93: don 0xB2 # ▓ (koyu gölge) + degilse eger b2 == 0x80: + eger b3 == 0x93: don 0x2D # – (en dash) + eger b3 == 0x94: don 0xC4 # — (em dash) + eger b3 == 0x98 veya b3 == 0x99: don 0x27 # ’ ' + eger b3 == 0x9C veya b3 == 0x9D: don 0x22 # “ ” + eger b3 == 0xA2: don 0x07 # • (madde imi) + don 0 + +fonksiyon glif(cp): + # Unicode kod noktası → VGA glif kodu (ASCII + Türkçe harfler, CP857 yerleşimi). + eger cp < 0x80: + don cp + eger cp == 0xE7: don 0x87 # ç + eger cp == 0xC7: don 0x80 # Ç + eger cp == 0xF6: don 0x94 # ö + eger cp == 0xD6: don 0x99 # Ö + eger cp == 0xFC: don 0x81 # ü + eger cp == 0xDC: don 0x9A # Ü + eger cp == 0x11F: don 0xA7 # ğ + eger cp == 0x11E: don 0xA6 # Ğ + eger cp == 0x131: don 0x8D # ı + eger cp == 0x130: don 0x98 # İ + eger cp == 0x15F: don 0x9F # ş + eger cp == 0x15E: don 0x9E # Ş + don 0x3F # ? + +fonksiyon kod_noktasi(cp): + # Klavyeden gelen kod noktasını ekrana yazar. + karakter(glif(cp)) + +fonksiyon yaz(m): + i = 0 + iken bayt(m, i) != 0: + b = bayt(m, i) + eger b < 0x80: + karakter(b) + i = i + 1 + degilse eger b >= 0xC0 ve b < 0xE0: + b2 = bayt(m, i + 1) + eger b2 == 0: + don 0 + k = turkce_kod(b, b2) + eger k != 0: + karakter(k) + degilse: + karakter(0x3F) + i = i + 2 + degilse eger b >= 0xE0 ve b < 0xF0: + b2 = bayt(m, i + 1) + eger b2 == 0: + don 0 + b3 = bayt(m, i + 2) + eger b3 == 0: + don 0 + k = utf8_uc_bayt(b, b2, b3) + eger k != 0: + karakter(k) + degilse: + karakter(0x3F) + i = i + 3 + degilse: + # 4 baytlık UTF-8 veya bilinmeyen sekans + karakter(0x3F) + i = i + 1 + +fonksiyon satir(m): + yaz(m) + karakter(0x0A) + +fonksiyon yaz_konum(satir, sutun, m, r): + eski_satir = bellek_oku64(durum.SATIR) + eski_sutun = bellek_oku64(durum.SUTUN) + eski_renk = bellek_oku64(durum.RENK) + konumlandir(satir, sutun) + renk(r) + yaz(m) + konumlandir(eski_satir, eski_sutun) + renk(eski_renk) + +fonksiyon satir_doldur(satir, ch, r): + dongu col icinde 0..GENISLIK - 1: + hucre(satir, col, ch, r) + +fonksiyon yatay_cizgi(satir, sol, gen, r): + dongu c icinde sol..sol + gen - 1: + hucre(satir, c, 0xC4, r) + +fonksiyon cerceve(ust, sol, gen, yuk, r): + # Çift çizgili donanımsal VGA çerçeve (0xC9, 0xCD, 0xBB, 0xBA, 0xC8, 0xBC) + hucre(ust, sol, 0xC9, r) + hucre(ust, sol + gen - 1, 0xBB, r) + hucre(ust + yuk - 1, sol, 0xC8, r) + hucre(ust + yuk - 1, sol + gen - 1, 0xBC, r) + dongu c icinde sol + 1..sol + gen - 2: + hucre(ust, c, 0xCD, r) + hucre(ust + yuk - 1, c, 0xCD, r) + dongu s icinde ust + 1..ust + yuk - 2: + hucre(s, sol, 0xBA, r) + hucre(s, sol + gen - 1, 0xBA, r) + +fonksiyon dikey_ayrac(ust, alt, sutun, r): + hucre(ust, sutun, 0xCB, r) + dongu s icinde ust + 1..alt - 1: + hucre(s, sutun, 0xBA, r) + hucre(alt, sutun, 0xCA, r) + +fonksiyon sayi(n): + eger n < 0: + karakter(0x2D) + n = 0 - n + bolen = 1 + iken n // bolen >= 10: + bolen = bolen * 10 + iken bolen > 0: + karakter(0x30 + (n // bolen) % 10) + bolen = bolen // 10 + +fonksiyon onaltilik(n): + yaz("0x") + basladi = yanlis + dongu i icinde 0..15: + rakam = bit_ve(saga_kaydir(n, (15 - i) * 4), 0xF) + eger rakam != 0 veya basladi veya i == 15: + basladi = dogru + eger rakam < 10: + karakter(0x30 + rakam) + degilse: + karakter(0x61 + rakam - 10) diff --git a/cekirdek/minimal-kernel/kabuk.kbl b/cekirdek/minimal-kernel/kabuk.kbl new file mode 100644 index 0000000..c6dd8f9 --- /dev/null +++ b/cekirdek/minimal-kernel/kabuk.kbl @@ -0,0 +1,133 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at https://mozilla.org/MPL/2.0/. +# +# Basit komut satırı: satır düzenleme, yerleşik komutlar ve UTF-8 tamponu. + +kullan "arayuz.kbl" +kullan "bellek.kbl" + +AZAMI = 120 +ISTEM_RENGI = 0x1E # mavi zemin, sarı yazı +YAZI_RENGI = 0x17 # mavi zemin, gri yazı + +fonksiyon istem(): + ekran.renk(ISTEM_RENGI) + ekran.yaz("kaba> ") + ekran.renk(YAZI_RENGI) + bellek_yaz64(durum.SATIR_UZUNLUK, 0) + +fonksiyon uzunluk(): + don bellek_oku64(durum.SATIR_UZUNLUK) + +fonksiyon satir_metni(): + # Komut satırı tamponundan metin (yığından ayrılır, iş bitince bırakılır). + don metin_oku(durum.KABUK_TAMPON, uzunluk()) + +fonksiyon komut_mu(satir, tr, ascii): + # Komutlar Türkçe yazımıyla ve ASCII karşılığıyla kabul edilir (yardım = yardim). + don satir == tr veya satir == ascii + +fonksiyon yardim(): + ekran.satir("Komutlar (Türkçe ya da ASCII yazılabilir):") + ekran.satir(" yardım bu liste") + ekran.satir(" panel sistem gösterge panelini çizer") + ekran.satir(" türkçe Türkçe karakter vitrini") + ekran.satir(" hakkında çekirdek bilgisi") + ekran.satir(" zaman açılıştan beri geçen süre") + ekran.satir(" yaz METİN metni ekrana yazar") + ekran.satir(" uzunluk METİN metnin harf sayısı (UTF-8)") + ekran.satir(" klavye tr|us klavye düzeni") + ekran.satir(" bellek bellek haritası ve sayfa ayırıcı") + ekran.satir(" ayır sayfa ayırıcıyı dener") + ekran.satir(" yığın yığın kullanımı") + ekran.satir(" temizle ekranı temizler") + ekran.satir(" kapat makineyi kapatır") + +fonksiyon calistir(): + eger uzunluk() == 0: + don 0 + satir = satir_metni() + eger komut_mu(satir, "yardım", "yardim"): + yardim() + degilse eger satir == "panel": + arayuz.panel_ciz() + degilse eger komut_mu(satir, "türkçe", "turkce"): + arayuz.turkce_vitrin() + degilse eger komut_mu(satir, "hakkında", "hakkinda"): + ekran.satir("KabaLang mini çekirdek — KabaLang ile yazıldı, LLVM ile derlendi.") + ekran.satir("x86-64 uzun kip, 100 Hz zamanlayıcı, PS/2 klavye (Türkçe Q), VGA metin kipi.") + degilse eger satir == "zaman": + t = bellek_oku64(durum.TIK) + ekran.satir(f"Açılıştan beri: {t // 100}.{(t % 100) // 10} sn") + degilse eger satir == "temizle": + ekran.temizle(YAZI_RENGI) + degilse eger satir == "bellek": + bellek.haritayi_yaz() + degilse eger komut_mu(satir, "yığın", "yigin"): + ekran.satir(f"Yığın: {calisma_zamani.yigin_kullanilan()} bayt kullanılıyor") + degilse eger satir.ile_baslar("uzunluk "): + m = satir.parca(8, satir.uzunluk() - 8) + ekran.satir(f"\"{m}\": {m.uzunluk()} harf") + degilse eger satir == "klavye tr": + klavye.duzen(0) + ekran.satir("Klavye: Türkçe Q") + degilse eger satir == "klavye us": + klavye.duzen(1) + ekran.satir("Klavye: ABD") + degilse eger komut_mu(satir, "ayır", "ayir"): + a = bellek.sayfa_ayir() + b = bellek.sayfa_ayir() + ekran.yaz("ayrıldı: ") + ekran.onaltilik(a) + ekran.yaz(" ") + ekran.onaltilik(b) + ekran.karakter(0x0A) + bellek.sayfa_birak(a) + c = bellek.sayfa_ayir() + ekran.yaz("bırakılıp yeniden ayrılan: ") + ekran.onaltilik(c) + eger c == a: + ekran.satir(" (geri verilen sayfa yeniden kullanıldı)") + degilse: + ekran.karakter(0x0A) + degilse eger satir.ile_baslar("yaz "): + ekran.satir(satir.parca(4, satir.uzunluk() - 4)) + degilse eger satir == "kapat": + ekran.satir("Kapatılıyor...") + seri.satir("kabuk: kapat") + port_yaz16(0x604, 0x2000) + degilse: + ekran.satir("Bilinmeyen komut: " + satir) + don 0 + +fonksiyon tampona_ekle(b): + bellek_yaz8(durum.KABUK_TAMPON + uzunluk(), b) + bellek_yaz64(durum.SATIR_UZUNLUK, uzunluk() + 1) + +fonksiyon son_harfi_sil(): + # UTF-8: devam baytlarını (10xxxxxx) ve baş baytı birlikte siler. + n = uzunluk() + iken n > 0 ve bit_ve(bellek_oku8(durum.KABUK_TAMPON + n - 1), 0xC0) == 0x80: + n = n - 1 + eger n > 0: + n = n - 1 + bellek_yaz64(durum.SATIR_UZUNLUK, n) + +fonksiyon tus(cp): + # Klavyeden gelen bir kod noktasını işler; tampon UTF-8 tutar. + eger cp == 0x0A: + ekran.karakter(0x0A) + calistir() + istem() + degilse eger cp == 0x08: + eger uzunluk() > 0: + son_harfi_sil() + ekran.geri_sil() + degilse eger cp != 0 ve uzunluk() < AZAMI - 1: + eger cp < 0x80: + tampona_ekle(cp) + degilse: + tampona_ekle(bit_veya(0xC0, saga_kaydir(cp, 6))) + tampona_ekle(bit_veya(0x80, bit_ve(cp, 0x3F))) + ekran.kod_noktasi(cp) diff --git a/cekirdek/minimal-kernel/kesme.kbl b/cekirdek/minimal-kernel/kesme.kbl new file mode 100644 index 0000000..218b01a --- /dev/null +++ b/cekirdek/minimal-kernel/kesme.kbl @@ -0,0 +1,62 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at https://mozilla.org/MPL/2.0/. +# +# Kesme altyapısı: IDT, 8259 PIC yeniden eşleme, 8253 PIT zamanlayıcı. +# +# Kesme girişleri önyükleme parçasında (calisma/yalin/boot.S); her giriş +# yazmaçları saklayıp ana dosyadaki `kesme(vektor, kod)` işlevini çağırır. + +GIRIS_SAYISI = 48 +KOD_SECICI = 0x08 +KESME_KAPISI = 0x8E # var, halka 0, 64 bit kesme kapısı + +# IDT girdisi — x86-64 kesme kapısı tanımlayıcısı (16 bayt, paketli). +yapi IdtGirisi: + ofset_alt: u16 = 0 + secici: u16 = 0 + ist: u8 = 0 + tur: u8 = 0 + ofset_orta: u16 = 0 + ofset_ust: u32 = 0 + ayrilmis: u32 = 0 + +fonksiyon kapi_kur(v, adres): + g = IdtGirisi.adreste(durum.IDT + v * IdtGirisi.boyut()) + g.ofset_alt = bit_ve(adres, 0xFFFF) + g.secici = KOD_SECICI + g.ist = 0 + g.tur = KESME_KAPISI + g.ofset_orta = bit_ve(saga_kaydir(adres, 16), 0xFFFF) + g.ofset_ust = saga_kaydir(adres, 32) + g.ayrilmis = 0 + +fonksiyon tabloyu_kur(): + dongu v icinde 0..GIRIS_SAYISI - 1: + kapi_kur(v, kesme_girisi(v)) + kesme_tablosu_yukle(durum.IDT, GIRIS_SAYISI * IdtGirisi.boyut()) + +fonksiyon pic_hazirla(): + # Donanım kesmelerini 32–47'ye taşı (0–31 işlemci istisnalarına ait). + port_yaz8(0x20, 0x11) + port_yaz8(0xA0, 0x11) + port_yaz8(0x21, 0x20) + port_yaz8(0xA1, 0x28) + port_yaz8(0x21, 0x04) + port_yaz8(0xA1, 0x02) + port_yaz8(0x21, 0x01) + port_yaz8(0xA1, 0x01) + port_yaz8(0x21, 0b11111100) # yalnız IRQ0 (zamanlayıcı) ve IRQ1 (klavye) + port_yaz8(0xA1, 0xFF) + +fonksiyon zamanlayici_hazirla(hz): + bolen = 1193182 // hz + port_yaz8(0x43, 0x36) + port_yaz8(0x40, bit_ve(bolen, 0xFF)) + port_yaz8(0x40, bit_ve(saga_kaydir(bolen, 8), 0xFF)) + +fonksiyon bitti(v): + # Kesme sonu bildirimi (EOI). + eger v >= 40: + port_yaz8(0xA0, 0x20) + port_yaz8(0x20, 0x20) diff --git a/cekirdek/minimal-kernel/klavye.kbl b/cekirdek/minimal-kernel/klavye.kbl new file mode 100644 index 0000000..716cf1e --- /dev/null +++ b/cekirdek/minimal-kernel/klavye.kbl @@ -0,0 +1,117 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at https://mozilla.org/MPL/2.0/. +# +# PS/2 klavye: tarama kodu kümesi 1 → Unicode kod noktası, kesme kuyruğu. +# +# Varsayılan düzen Türkçe Q; `klavye us` ile ABD düzenine geçilir. Shift +# kesme anında izlenir ve tuşla birlikte kuyruğa yazılır (bit 7), böylece +# ana döngü geç işlese de doğru harf çıkar. İ/ı ayrımı Türkçe kuralıyla: +# ı tuşu shift ile I, i tuşu shift ile İ verir. + +# Dizin = tarama kodu. `~` = Türkçe harf (aşağıda ayrıca) ya da karşılıksız. +# `\0` KULLANILMAZ: dil C kuralını izler, `\0`dan sonraki rakamlar sekizli kaçıştır. +TR_KUCUK = "~~1234567890*-~~qwertyu~op~~~~asdfghjkl~~\"~,zxcvbnm~~." +TR_BUYUK = "~~!'^+%&/()=?_~~QWERTYU~OP~~~~ASDFGHJKL~~~~;ZXCVBNM~~:" +US_KUCUK = "~~1234567890-=~~qwertyuiop[]~~asdfghjkl;'`~\\zxcvbnm,./" +US_BUYUK = "~~!@#$%^&*()_+~~QWERTYUIOP{}~~ASDFGHJKL:\"~~|ZXCVBNM<>?" +YOK = 0x7E +UZUNLUK = 0x36 + +ENTER = 0x1C +GERI = 0x0E +BOSLUK = 0x39 +SOL_SHIFT = 0x2A +SAG_SHIFT = 0x36 +BIRAKMA = 0x80 + +fonksiyon kesmede_al(): + # Kesme işleyicisinden çağrılır: basılan tuşu (shift durumuyla) kuyruğa yazar. + kod = port_oku8(0x60) + eger kod == SOL_SHIFT veya kod == SAG_SHIFT: + bellek_yaz64(durum.KB_SHIFT, 1) + degilse eger kod == SOL_SHIFT + BIRAKMA veya kod == SAG_SHIFT + BIRAKMA: + bellek_yaz64(durum.KB_SHIFT, 0) + degilse eger kod < BIRAKMA: + eger bellek_oku64(durum.KB_SHIFT) == 1: + kod = kod + BIRAKMA + y = bellek_oku64(durum.KB_YAZ) + bellek_yaz8(durum.KB_TAMPON + bit_ve(y, 0xFF), kod) + bellek_yaz64(durum.KB_YAZ, y + 1) + +fonksiyon bekleyen_var_mi(): + don bellek_oku64(durum.KB_OKU) != bellek_oku64(durum.KB_YAZ) + +fonksiyon kod_al(): + # Kuyruktaki sıradaki tuş: bit 7 = shift, alt 7 bit = tarama kodu. + o = bellek_oku64(durum.KB_OKU) + kod = bellek_oku8(durum.KB_TAMPON + bit_ve(o, 0xFF)) + bellek_yaz64(durum.KB_OKU, o + 1) + don kod + +fonksiyon tarama_kodu(kod): + don bit_ve(kod, 0x7F) + +fonksiyon duzen(d): + bellek_yaz64(durum.KB_DUZEN, d) + +fonksiyon turkce_harf(t, buyuk): + # Türkçe Q'daki Türkçe harf tuşları; değilse 0. + eger t == 0x17: + eger buyuk: + don 0x49 # I + don 0x131 # ı + eger t == 0x28: + eger buyuk: + don 0x130 # İ + don 0x69 # i + eger t == 0x1A: + eger buyuk: + don 0x11E # Ğ + don 0x11F # ğ + eger t == 0x1B: + eger buyuk: + don 0xDC # Ü + don 0xFC # ü + eger t == 0x27: + eger buyuk: + don 0x15E # Ş + don 0x15F # ş + eger t == 0x33: + eger buyuk: + don 0xD6 # Ö + don 0xF6 # ö + eger t == 0x34: + eger buyuk: + don 0xC7 # Ç + don 0xE7 # ç + don 0 + +fonksiyon karakter(kod): + # Tuşun Unicode kod noktası; Enter 0x0A, geri silme 0x08, karşılıksızsa 0. + t = tarama_kodu(kod) + buyuk = kod >= BIRAKMA + eger t == ENTER: + don 0x0A + eger t == GERI: + don 0x08 + eger t == BOSLUK: + don 0x20 + eger t >= UZUNLUK: + don 0 + eger bellek_oku64(durum.KB_DUZEN) == 0: + h = turkce_harf(t, buyuk) + eger h != 0: + don h + eger buyuk: + c = bayt(TR_BUYUK, t) + degilse: + c = bayt(TR_KUCUK, t) + degilse: + eger buyuk: + c = bayt(US_BUYUK, t) + degilse: + c = bayt(US_KUCUK, t) + eger c == YOK: + don 0 + don c diff --git a/cekirdek/minimal-kernel/seri.kbl b/cekirdek/minimal-kernel/seri.kbl new file mode 100644 index 0000000..c82699b --- /dev/null +++ b/cekirdek/minimal-kernel/seri.kbl @@ -0,0 +1,31 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at https://mozilla.org/MPL/2.0/. +# +# COM1 seri port sürücüsü (16550 UART). + +PORT = 0x3F8 + +fonksiyon hazirla(): + port_yaz8(PORT + 1, 0x00) # UART kesmeleri kapalı + port_yaz8(PORT + 3, 0x80) # bölen ayarı (DLAB) + port_yaz8(PORT + 0, 0x03) # 38400 baud + port_yaz8(PORT + 1, 0x00) + port_yaz8(PORT + 3, 0x03) # 8 bit, eşliksiz, 1 dur biti + port_yaz8(PORT + 2, 0xC7) # FIFO açık + port_yaz8(PORT + 4, 0x0B) + +fonksiyon bayt_yaz(b): + iken bit_ve(port_oku8(PORT + 5), 0x20) == 0: + devam + port_yaz8(PORT, b) + +fonksiyon yaz(m): + i = 0 + iken bayt(m, i) != 0: + bayt_yaz(bayt(m, i)) + i = i + 1 + +fonksiyon satir(m): + yaz(m) + bayt_yaz(0x0A) diff --git a/cekirdek/renkler/renkler.kbl b/cekirdek/renkler/renkler.kbl new file mode 100644 index 0000000..c157eaa --- /dev/null +++ b/cekirdek/renkler/renkler.kbl @@ -0,0 +1,34 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at https://mozilla.org/MPL/2.0/. +# +# VGA renkleri: metin kipinde her hücre iki bayttır (karakter + renk). +# Renk baytının üst 4 biti zemin, alt 4 biti yazı rengidir. + +VGA = 0xB8000 + +fonksiyon hucre(satir, sutun, karakter, renk): + bellek_yaz16(VGA + (satir * 80 + sutun) * 2, renk * 256 + karakter) + +fonksiyon yaz(m, satir, sutun, renk): + i = 0 + iken bayt(m, i) != 0: + hucre(satir, sutun + i, bayt(m, i), renk) + i = i + 1 + +fonksiyon onaltilik(n, satir, sutun, renk): + RAKAM = "0123456789ABCDEF" + hucre(satir, sutun, bayt(RAKAM, saga_kaydir(n, 4)), renk) + hucre(satir, sutun + 1, bayt(RAKAM, bit_ve(n, 15)), renk) + +dongu i icinde 0..80 * 25 - 1: + bellek_yaz16(VGA + i * 2, 0x0720) +yaz("VGA renk tablosu: satir = zemin, sutun = yazi rengi", 0, 2, 0x0F) + +dongu zemin icinde 0..7: + dongu yazi icinde 0..15: + renk = zemin * 16 + yazi + onaltilik(renk, 2 + zemin * 2, 2 + yazi * 4, renk) + +yaz("Kendi renginizi deneyin: renk baytini degistirip yeniden calistirin.", 19, 2, 0x0B) +dur() diff --git a/medya/cekirdek-asal.png b/medya/cekirdek-asal.png new file mode 100644 index 0000000..76d7ea6 Binary files /dev/null and b/medya/cekirdek-asal.png differ diff --git a/medya/cekirdek-merhaba.png b/medya/cekirdek-merhaba.png new file mode 100644 index 0000000..91fc97f Binary files /dev/null and b/medya/cekirdek-merhaba.png differ diff --git a/medya/cekirdek-renkler.png b/medya/cekirdek-renkler.png new file mode 100644 index 0000000..cd689f0 Binary files /dev/null and b/medya/cekirdek-renkler.png differ diff --git a/medya/minimal-kernel.png b/medya/minimal-kernel.png new file mode 100644 index 0000000..f277af3 Binary files /dev/null and b/medya/minimal-kernel.png differ