From f557fc6b9ef6712f74388b534ec9565e1caac8f8 Mon Sep 17 00:00:00 2001 From: Albert Ariel Widiaatmaja Date: Sun, 10 Sep 2023 02:17:14 +0800 Subject: [PATCH] feat: adds basic process management --- .DS_Store | Bin 6148 -> 8196 bytes Makefile | 138 ++------- asset/.DS_Store | Bin 6148 -> 0 bytes git_logs.txt | 451 +++++++++++++++++++++++++++ heap.c | 19 ++ heap.elf | Bin 0 -> 772 bytes heap.h | 5 + idt.asm | 752 +++++++++++++++++++++++----------------------- kernel.elf | Bin 1744 -> 1796 bytes kernel.img | Bin 1052160 -> 1052160 bytes main.c | 13 +- minios.bin | Bin minios.elf | Bin minos.bin | Bin 0 -> 2950 bytes minos.elf | Bin 0 -> 11228 bytes notes/v4_notes.md | 9 + paging.c | 52 ++++ paging.elf | Bin 0 -> 1244 bytes paging.h | 15 + process.c | 3 +- process.elf | Bin 1024 -> 1084 bytes process.h | 2 +- scheduler.elf | Bin 1608 -> 1604 bytes screen.elf | Bin 1624 -> 1620 bytes starter.asm | 302 ++++++++++--------- starter.o | Bin 4432 -> 4560 bytes 26 files changed, 1119 insertions(+), 642 deletions(-) delete mode 100644 asset/.DS_Store create mode 100644 git_logs.txt create mode 100644 heap.c create mode 100644 heap.elf create mode 100644 heap.h mode change 100755 => 100644 minios.bin mode change 100755 => 100644 minios.elf create mode 100755 minos.bin create mode 100755 minos.elf create mode 100644 paging.c create mode 100644 paging.elf create mode 100644 paging.h diff --git a/.DS_Store b/.DS_Store index ac1416df0cfc217c2acbea2e80722d9163218451..acadee77aa3860d990caa0be0303040a9cf51d5d 100644 GIT binary patch literal 8196 zcmeHM&5ja55Uyrn86;~+)P#eFNxYJk{bNJC5L^#l#ppo|GBCSL9A?POAP0istnc6> z=+y@?K8rW~s(W@be;hU@{=_cQT{AuPb#;AHJwpKziT+}8K-4561C4c~j;=uXI=7sZ z;*nd>0(g4t`eV!WEu1%U)_OoQpc&8%Xa+O`nt{K80lc$Wj4khdbyfG80nNaF$pAke zOf=TLSZ|b;j}COQ1b{AMSPG8iSAS@e2cUbg-YAU`h)_^y1r>3LA>ztGC^)Y7V*8EK z3Qj_L#yqiS5mzW8E*1cvxGmvM1Yxgqk(*-#cW$O3O*j_h(NRhw_jVQ#& zrpQ``^SILgV$EGAjN0vQqO?=4>{gAcQ8!)6 zVdM5g--||$X9p7COl+9EeC~J?f7$mJ-XxURfx2MSjM}i#T&)hfotAmj?W|kos(aXO zna4++^}1%(Um^mY(aY5PhRT0yZfvx3n>Mk$`q*h=oN!$RE(ephfV+uljm_j6YG|%&bUsAzcui z2|I5xUw8N5c5eX4==r(=dH}jyilRnA)Ljg1<>YOmSdRtn@Q7P9cq%mdjV`_SeM~XO z0~Y*!-G9OWhg?TEARbd!I6=Y{pDod@(8rKb)kAtNFrj_V4man^WUP0CnjY#kY)h?f$*RPu-+UQU0?d3DCt(aRxu_>g?%&*4Sv z>g=B^9a1}n4hDjORR(nSrS$atKjSM?9P%wCR4@<>{8a{|GoFq|e7bzL{&-G3YZKQc smx|`KYEWped<5{1?jw5^^mtO6d3DCtQM;($%8BtIV1$GU1~$OJ2k;I#>;M1& diff --git a/git_logs.txt b/git_logs.txt new file mode 100644 index 0000000..c8091f2 --- /dev/null +++ b/git_logs.txt @@ -0,0 +1,451 @@ +commit f929627cab69620f2ae9b39fd6edaf839daee4a1 +Author: Albert Ariel Widiaatmaja +Date: Sun Aug 20 12:06:01 2023 +0800 + + feat: add content about memory management + +commit ff0a5e5465bb5aabc27a9350a38778a09d6939ef +Author: Albert Ariel Widiaatmaja +Date: Sun Aug 20 01:25:46 2023 +0800 + + fix: add correct screenshot for v3 + +commit b606e5c9e2a01b4ca0e0dd2d7900094e43756299 +Author: Albert Ariel Widiaatmaja +Date: Sun Aug 20 00:26:10 2023 +0800 + + feat: add missing files + +commit 7d36caaa51c0695cdd1dd9013d7b8267ffe0f353 +Merge: 47d071f f2a8179 +Author: Albert Ariel Widiaatmaja +Date: Sun Aug 20 00:24:59 2023 +0800 + + merge: v3 + +commit 47d071fecd9f7b05bbfeba6c7923abb37925cfe0 +Author: Albert Ariel Widiaatmaja +Date: Sun Aug 20 00:21:51 2023 +0800 + + chore: remove old file + +commit f2a8179f244be4fc0d406ed2a7d04f02462e1eb5 +Author: Albert Ariel Widiaatmaja +Date: Sat Aug 19 23:59:18 2023 +0800 + + chore: remove useless files + +commit 84cd6af038601991f0a515c1346da1d205523b0e +Author: Albert Ariel Widiaatmaja +Date: Sat Aug 19 23:55:10 2023 +0800 + + fix: printed char not printing to screen + +commit 8f3f3060276bdc525f3291dbf831ed4e7bcd0265 +Author: Albert Ariel Widiaatmaja +Date: Sat Aug 19 22:37:12 2023 +0800 + + fix: linker multiple definition error + +commit ec150ddfd21d2784d227a0e7fd5cef2c28ef18a5 +Author: Albert Ariel Widiaatmaja +Date: Sat Aug 19 22:07:21 2023 +0800 + + feat: update makefile + +commit f67420109a692e9e5b749e01141970701a677a17 +Author: Albert Ariel Widiaatmaja +Date: Sat Aug 19 22:06:31 2023 +0800 + + feat: add dummy processes, move screen related functions from main.c to screen.c + +commit 278b8bd72dc47e1e44999b8d536ace0a21305fc6 +Author: Albert Ariel Widiaatmaja +Date: Sat Aug 19 22:02:02 2023 +0800 + + feat: interrupt for process scheduling + +commit 50522bc12359c6f48151c89061dc7e447f2a1998 +Author: Albert Ariel Widiaatmaja +Date: Sat Aug 19 21:21:26 2023 +0800 + + feat: add scheduler and run_next_process to starter.asm + +commit 9adc08718e5d395bbdd6baf1c2e33e978b067d75 +Author: Albert Ariel Widiaatmaja +Date: Sat Aug 19 21:13:41 2023 +0800 + + feat: add process scheduler implementation + +commit 4656a3f1dbda60656b55410e4943b75e5c62f0e6 +Author: Albert Ariel Widiaatmaja +Date: Sat Aug 19 19:34:03 2023 +0800 + + feat: adds abstaction for processes + +commit 4b852836a3d1bffaba0c7a8c30eaa8a56d72f19e +Author: Albert Ariel Widiaatmaja +Date: Sat Aug 19 15:52:27 2023 +0800 + + feat: separate screen initialization logic + +commit b07140eb137fd9a1b199432691c3958cedf0ce2c +Author: Albert Ariel Widiaatmaja +Date: Sat Aug 19 15:50:18 2023 +0800 + + feat: add notes on how to implement process management + +commit 3165109ea675205d63916e0cfc47ac5089a4abcf +Author: Albert Ariel Widiaatmaja +Date: Sat Aug 19 15:43:59 2023 +0800 + + feat: add notes on how to implement process management + +commit 21e81d539c6ea886fc1871f1971f5c06afdd3140 +Author: Albert Ariel Widiaatmaja +Date: Sat Aug 19 00:38:48 2023 +0800 + + feat: separate build and run from makefile, add screenshot for v2 + +commit 3dd54ec631e5bf08bfa3ba8f7117cbd4af4b8174 +Author: Albert Ariel Widiaatmaja +Date: Sat Aug 19 00:26:00 2023 +0800 + + feat: separate makefile processes into smaller parts + +commit fd7e984fd675677884d77bed2c990b68d8b57887 +Merge: 9f8bbe9 9721f24 +Author: Albert Ariel W <101498658+albertarielw@users.noreply.github.com> +Date: Sun Jul 9 19:06:20 2023 +0800 + + Merge pull request #10 from albertarielw/v2 + + V2 + +commit 9721f24fdd2c4e8513b5b169cb8c620203fe999e +Author: Albert Ariel Widiaatmaja +Date: Sun Jul 9 19:05:43 2023 +0800 + + fix: makefile wrong folder for run + +commit 8e1d8d0cf3301483937ca664647faf35073cac2b +Author: albertarielw +Date: Sun Jul 9 19:04:55 2023 +0800 + + feat: tidy up folder, update makefile + +commit 3eb3cd847fad20228cf995e5c050e79b816d110c +Author: Albert Ariel Widiaatmaja +Date: Sun Jul 9 18:54:03 2023 +0800 + + feat: update make file + +commit 3726e3b214a40b199bd90c00cb53fd3eef14b4a1 +Author: albertarielw +Date: Sun Jul 9 15:42:19 2023 +0800 + + test: separate build + +commit ed10fc0116ad2a413ff997aed4d75e38e500b983 +Author: Albert Ariel Widiaatmaja +Date: Sun Jul 9 15:40:20 2023 +0800 + + test: compile + +commit b4939a8d24b3a289c7a5c4da0e7df1bad874bea2 +Author: Albert Ariel Widiaatmaja +Date: Sun Jul 9 15:39:13 2023 +0800 + + test: separate build into compile link run + +commit 41250207c475a98eda7ab0aa918a8b1837075d6e +Author: Albert Ariel Widiaatmaja +Date: Sun Jul 9 15:31:20 2023 +0800 + + refactor: change string values + +commit 46358ea757fe008476c4b47a9389a611a8192181 +Author: Albert Ariel Widiaatmaja +Date: Sun Jul 9 01:32:14 2023 +0800 + + feat: adds screenshot of v2 + +commit 9f8bbe9249662bd5646e2ad75935743293b9a117 +Merge: 922e4ac b6e83ff +Author: Albert Ariel W <101498658+albertarielw@users.noreply.github.com> +Date: Sun Jul 9 01:29:58 2023 +0800 + + Merge pull request #9 from albertarielw/v2 + + V2 + +commit b6e83ff882753e5454ac75bc2cc959456bb92248 +Author: Albert Ariel Widiaatmaja +Date: Sun Jul 9 01:29:39 2023 +0800 + + fix: find out build issue, it is due to linker issue on mac, need to do linker on WSL + +commit 7afa4a005ea9125d7cdb529b98111ec6ca28b2c6 +Merge: 148dcd6 922e4ac +Author: Albert Ariel W <101498658+albertarielw@users.noreply.github.com> +Date: Sun Jul 2 15:51:02 2023 +0800 + + Merge pull request #8 from albertarielw/main + + Synch with main + +commit 922e4acea2d36ec2b8db720e788bae763fafca5e +Merge: 7471da3 148dcd6 +Author: Albert Ariel W <101498658+albertarielw@users.noreply.github.com> +Date: Sun Jul 2 15:43:02 2023 +0800 + + Merge pull request #7 from albertarielw/v2 + + V2 + +commit 148dcd6b5a286d48c6412a9604902800f58e8d66 +Author: Albert Ariel Widiaatmaja +Date: Sun Jul 2 14:51:33 2023 +0800 + + chore: tidy up folder + +commit 8b64bf491cd2fa5e0ba2dc4d2c231bd1b5d89d0c +Author: Albert Ariel Widiaatmaja +Date: Sun Jul 2 14:51:00 2023 +0800 + + chore: remove build file + +commit e3a97faeaa613254e4da023f7a456db3f1f8996c +Author: Albert Ariel Widiaatmaja +Date: Sun Jul 2 14:50:29 2023 +0800 + + update gitignore + +commit 74d3fef6e7d6879d4243b991a3e53c13249d6ab1 +Author: Albert Ariel Widiaatmaja +Date: Sun Jul 2 14:41:47 2023 +0800 + + fix: merge start_kernel.asm to starter.asm + +commit c607fb44c3317b82ad241c687cea4891dd4ec777 +Author: Albert Ariel Widiaatmaja +Date: Sun Jul 2 14:37:50 2023 +0800 + + fix: check main.c + +commit e9e52403be365a8a4041eaab18048c76e1a5bafe +Author: Albert Ariel Widiaatmaja +Date: Sun Jul 2 14:35:45 2023 +0800 + + fix: check gdt.asm + +commit 65c15dbccb1ef44f53406354af9c902783d282be +Author: Albert Ariel Widiaatmaja +Date: Sun Jul 2 14:34:49 2023 +0800 + + fix: check bootstrap logic + +commit c9b34442267c6e05845d2fdfe4dc42f282217c48 +Author: Albert Ariel Widiaatmaja +Date: Sun Jul 2 14:28:52 2023 +0800 + + chore: tidy up makefile + +commit 22b21d4e5e52d188201a9c2f24e9bb0f6b53cf46 +Author: Albert Ariel Widiaatmaja +Date: Sun Jul 2 14:26:27 2023 +0800 + + feat: setup interrupt handler + +commit b5d71721c10304dbda785b592efedd87dfe81e24 +Author: Albert Ariel Widiaatmaja +Date: Sun Jul 2 03:16:06 2023 +0800 + + feat: adds basic main_kernel in C which prints text to string + +commit 187d670f033d952a1f791d8e1346c35c83e8b066 +Author: Albert Ariel Widiaatmaja +Date: Sun Jul 2 02:16:50 2023 +0800 + + feat: adds start_kernel to intialize segment registers and call main kernel, include start_kernel and gdt in starter + +commit e3bae2ede2d5fa32392dbe68cf8d8bfd6199913f +Author: Albert Ariel Widiaatmaja +Date: Sun Jul 2 02:13:05 2023 +0800 + + chore: adds comments for gdt + +commit ad96d5341fdab7f0f6f52c084f8e8f7320a9b36e +Author: Albert Ariel Widiaatmaja +Date: Sun Jul 2 02:06:06 2023 +0800 + + feat: adds init video mode + +commit b11462ff057d3225f16e05d5375d9b501b8fed33 +Author: Albert Ariel Widiaatmaja +Date: Sun Jul 2 01:05:16 2023 +0800 + + feat: adds gdt descriptor and routine to enter protected mode + +commit a6bbb423969c1411c9a8f4fda17ac4aa01fb04ac +Author: Albert Ariel Widiaatmaja +Date: Sun Jul 2 00:38:24 2023 +0800 + + feat: adds load_gdt + +commit 9653820e92593d1444e4f6b29e8e7ce8ff2da44f +Author: Albert Ariel Widiaatmaja +Date: Sat Jul 1 21:10:00 2023 +0800 + + feat: update bootstrap to load >1 sector from the disk to memory + +commit 79aa6194efa87964d3ebea276432b306f48c0b4b +Author: Albert Ariel Widiaatmaja +Date: Sat Jul 1 20:43:35 2023 +0800 + + feat: update makefile + +commit ab0a08d3d4e3771970175d238ee8c3f12b1f1a50 +Author: Albert Ariel Widiaatmaja +Date: Sat Jul 1 20:34:15 2023 +0800 + + feat: updates makefile and adds linker file + +commit c75fc70400d51009cced1d15c1a65d41ff8a31b7 +Author: Albert Ariel Widiaatmaja +Date: Sat Jul 1 19:48:29 2023 +0800 + + feat: adds note about intro to progenitor os + +commit 7471da301439f0a2eeb24ee6114251d3e5e618bf +Merge: 8d7bca7 1fa3b34 +Author: Albert Ariel W <101498658+albertarielw@users.noreply.github.com> +Date: Sat Jul 1 12:55:48 2023 +0800 + + Merge pull request #6 from albertarielw/v2 + + V2 + +commit 8d7bca76f1a6fe2437df27f6cd9a2deb3e19e248 +Merge: c072de5 5cb3f13 +Author: Albert Ariel W <101498658+albertarielw@users.noreply.github.com> +Date: Sat Jul 1 12:54:57 2023 +0800 + + Merge pull request #5 from albertarielw/revert-4-v2 + + Revert "V2.1" + +commit 5cb3f13f9744ed6657171256ef3cbeb82401a76c +Author: Albert Ariel W <101498658+albertarielw@users.noreply.github.com> +Date: Sat Jul 1 12:54:45 2023 +0800 + + Revert "V2.1 (#4)" + + This reverts commit c072de50f3afe779d439a172d938dcb32493a0ff. + +commit c072de50f3afe779d439a172d938dcb32493a0ff +Author: Albert Ariel W <101498658+albertarielw@users.noreply.github.com> +Date: Sat Jul 1 12:54:13 2023 +0800 + + V2.1 (#4) + + * feat: adds notes until page 54 + + * feat: adds notes until x86 segmentation + + * feat: adds notes about run-time stack and interrupts + + * feat: adds more content to x86 run time stack and interrupt, finish summary of x86 architecture + + --------- + + Co-authored-by: Albert Ariel Widiaatmaja + +commit 1fa3b34c1f3a98c3670c3b0f44f810b1204e3a5f +Author: Albert Ariel Widiaatmaja +Date: Sat Jul 1 12:52:47 2023 +0800 + + feat: adds more content to x86 run time stack and interrupt, finish summary of x86 architecture + +commit bf4674a7ec906d45df27d2f82a8b11a029dae2b3 +Author: Albert Ariel Widiaatmaja +Date: Sat Jul 1 01:51:15 2023 +0800 + + feat: adds notes about run-time stack and interrupts + +commit 9a4d101282bb1d2f92b6ee7a029069554afab3e7 +Author: Albert Ariel Widiaatmaja +Date: Fri Jun 30 01:50:11 2023 +0800 + + feat: adds notes until x86 segmentation + +commit 504e58eb9fd725be07f4732c711b5495c4a06d8d +Author: Albert Ariel Widiaatmaja +Date: Fri Jun 30 01:13:13 2023 +0800 + + feat: adds notes until page 54 + +commit 1001dd4667167f1b3953b4c8b998f3fa91c6a032 +Author: Albert Ariel W <101498658+albertarielw@users.noreply.github.com> +Date: Sun Jun 25 22:57:02 2023 +0800 + + feat: added learning notes related to v1 (#3) + + Co-authored-by: Albert Ariel Widiaatmaja + +commit d3bde8cecdb8c35a0f00874a4d97009252ba6689 +Merge: 984352e 0e43e6c +Author: Albert Ariel W <101498658+albertarielw@users.noreply.github.com> +Date: Sun Jun 25 11:31:39 2023 +0800 + + Merge pull request #1 from albertarielw/v1 + + V1 + +commit 0e43e6caa0d2f455b6455dc0a95cfe5281c01ad3 +Author: Albert Ariel Widiaatmaja +Date: Sun Jun 25 11:30:27 2023 +0800 + + update: change makefile to clean files in build directory instead of current directory + +commit b91b4e77b2dbd547a0fd2f18dee5218b26cb17ff +Author: Albert Ariel Widiaatmaja +Date: Sun Jun 25 11:25:16 2023 +0800 + + enhancement: update gitignore to ignore build folder and everything in it including subdirectories + +commit 842c47954540deeaa358f94c91dd573eee969aa8 +Author: Albert Ariel Widiaatmaja +Date: Sun Jun 25 11:22:28 2023 +0800 + + feat: adds gitignore to ignore build files + +commit d21d70666691c2b81179d3fdfec437729b05eafa +Author: Albert Ariel Widiaatmaja +Date: Sun Jun 25 11:21:25 2023 +0800 + + chore: remove build up from repo + +commit a681eed83c6d885bf9d4afed4210bab240a6142e +Author: Albert Ariel Widiaatmaja +Date: Sun Jun 25 11:20:42 2023 +0800 + + enhancement: tody up make file to separate src and build + +commit 67cef3a1046c54127c3179310239353b37316c63 +Author: Albert Ariel Widiaatmaja +Date: Sat Jun 24 22:07:51 2023 +0800 + + feat: basic os which says hello world + +commit 984352e4d83c8f6994f36326482993ecbe5d8ba6 +Author: Albert Ariel W <101498658+albertarielw@users.noreply.github.com> +Date: Sat Jun 24 18:12:04 2023 +0800 + + Update README.md + +commit 0f6d74fe39474c8fab489520171fe8731c59cae2 +Author: Albert Ariel W <101498658+albertarielw@users.noreply.github.com> +Date: Fri Jun 23 19:03:13 2023 +0800 + + Initial commit diff --git a/heap.c b/heap.c new file mode 100644 index 0000000..21f55dc --- /dev/null +++ b/heap.c @@ -0,0 +1,19 @@ +#include "heap.h" + +unsigned int heap_base; + +void heap_init() +{ + heap_base = 0x100000; +} + +// memory allocator, similar to malloc +// currently very simple but cannot free memory -> we need a way to know how to free memory +int kalloc(int bytes) +{ + unsigned int new_object_address = heap_base; + + heap_base += bytes; + + return new_object_address; +} \ No newline at end of file diff --git a/heap.elf b/heap.elf new file mode 100644 index 0000000000000000000000000000000000000000..77ec09e6082f24173e1363613f1e0e5bb75b20e6 GIT binary patch literal 772 zcma)(y-EW?6ov1asEJh)5DNttf)IZ)WMdkwgb;%uVv|y2c3n(JvXSfrw9&#Uq_OY? z#79XXc0Po5HueF%XLlyX&I@Ru7nR6Rpe0IEWBBnh zA5X~8!`YbY`_If1I>Xvzvx*B}uqpNW$xNyMDmEpr?FMKWP+0 zCA~H;_wQI|C(gd0XW$KXwFb<+tg=pX9&jR3JYX{yIpM)Q;m$U6onRs^V@$thy>0Hm zZ+uPGSi^+TC2n92h=6Y=Qt=04$UV)tOY~@jrui?(PcRMmPC2m`^zmQ3E6!^6#**GS V^AI}BdReY#eFYvkGA5?+{Q!G?OPBxv literal 0 HcmV?d00001 diff --git a/heap.h b/heap.h new file mode 100644 index 0000000..3531fd7 --- /dev/null +++ b/heap.h @@ -0,0 +1,5 @@ +// base of heap from which we will allocate some memory for functions +extern unsigned int heap_base; + +void heap_init(); +int kalloc( int ); \ No newline at end of file diff --git a/idt.asm b/idt.asm index 5ad1b16..e7a18a8 100644 --- a/idt.asm +++ b/idt.asm @@ -1,376 +1,376 @@ -isr_0: - cli - push 0 - jmp isr_basic - -isr_1: - cli - push 1 - jmp isr_basic - -isr_2: - cli - push 2 - jmp isr_basic - -isr_3: - cli - push 3 - jmp isr_basic - -isr_4: - cli - push 4 - jmp isr_basic - -isr_5: - cli - push 5 - jmp isr_basic - -isr_6: - cli - push 6 - jmp isr_basic - -isr_7: - cli - push 7 - jmp isr_basic - -isr_8: - cli - push 8 - jmp isr_basic - -isr_9: - cli - push 9 - jmp isr_basic - -isr_10: - cli - push 10 - jmp isr_basic - -isr_11: - cli - push 11 - jmp isr_basic - -isr_12: - cli - push 12 - jmp isr_basic - -isr_13: - cli - push 13 - jmp isr_basic - -isr_14: - cli - push 14 - jmp isr_basic - -isr_15: - cli - push 15 - jmp isr_basic - -isr_16: - cli - push 16 - jmp isr_basic - -isr_17: - cli - push 17 - jmp isr_basic - -isr_18: - cli - push 18 - jmp isr_basic - -isr_19: - cli - push 19 - jmp isr_basic - -isr_20: - cli - push 20 - jmp isr_basic - -isr_21: - cli - push 21 - jmp isr_basic - -isr_22: - cli - push 22 - jmp isr_basic - -isr_23: - cli - push 23 - jmp isr_basic - -isr_24: - cli - push 24 - jmp isr_basic - -isr_25: - cli - push 25 - jmp isr_basic - -isr_26: - cli - push 26 - jmp isr_basic - -isr_27: - cli - push 27 - jmp isr_basic - -isr_28: - cli - push 28 - jmp isr_basic - -isr_29: - cli - push 29 - jmp isr_basic - -isr_30: - cli - push 30 - jmp isr_basic - -isr_31: - cli - push 31 - jmp isr_basic - -; System Timer -isr_32: - ; part 1 - - cli ; step 1 disable interrupt (when handling interrupt, btetter to not receive any other interrupt) - - ; step 2 and 3 - ; when this interrupt handler is called, context of the processor is the context of suspended process - ; we define ISRs gate descriptors as interrupt gates in IDT - ; -> if we define as task gates, the context of the suspended gates in the IDT table will not be available directly on processor's registers - - ; since context is reachable, we store in the stack (useful when scheduler needs to copy the context of the suspended process to the memory) - ; push into the stack also provides 2 benefits - ; 1. we can use register in current code as we wont lose the suspended process context - ; 2. method of passing parameters - - pusha ; step 2 pusha pushes values of all general registers in the order: EAX, ECX, EDX, EBX, ESP, EBP, ESI and EDI - - - ; step 3 to push EIP - - ; Curr EIP is a pointer to curr instruction, not the one we want to suspend - - ; Suppose A is running - ; We want to suspend A, so ISR32 is called - ; Return address to where A suspended is stored at the top of the stack (based on calling convention) - ; Then we run ISR32 - ; At this point, ISR32 has put 8 registers to the stack (because of pusha) - ; ESP points to top of stack, to find return address of A (EIP of A) simply use esp + 32 - mov eax, [esp + 32] - push eax - - call scheduler ; step 4 - - ; ... ; - - ; part 2 - - ; step 5 - - ; after scheduler, tell PIC we finish handling IRQ by send end of interrupt command to PIC - mov al, 0x20 - out 0x20, al - - ; step 6 - - ; jump to memory address in which the selected process were suspended - ; exploit calling convention again - - ; remove all values added to stack by adding 40 (8 general register + EIP + 4 to get to the start of return address added) - add esp, 40d - push run_next_process - - iret ; step 7 - -isr_33: - cli - push 33 - jmp irq_basic - -isr_34: - cli - push 34 - jmp irq_basic - -isr_35: - cli - push 35 - jmp irq_basic - -isr_36: - cli - push 36 - jmp irq_basic - -isr_37: - cli - push 37 - jmp irq_basic - -isr_38: - cli - push 38 - jmp irq_basic - -isr_39: - cli - push 39 - jmp irq_basic - -isr_40: - cli - push 40 - jmp irq_basic - -isr_41: - cli - push 41 - jmp irq_basic - -isr_42: - cli - push 42 - jmp irq_basic - -isr_43: - cli - push 43 - jmp irq_basic - -isr_44: - cli - push 44 - jmp irq_basic - -isr_45: - cli - push 45 - jmp irq_basic - -isr_46: - cli - push 46 - jmp irq_basic - -isr_47: - cli - push 47 - jmp irq_basic - -isr_48: - cli - push 48 - jmp irq_basic - -isr_basic: -; cli - call interrupt_handler - - pop eax - sti - iret - -irq_basic: -; cli - call interrupt_handler - - mov al, 0x20 - out 0x20, al - - cmp byte [esp], 40d ; Interrupt number - jnge irq_basic_end - - mov al, 0xa0 - out 0x20, al - - irq_basic_end: - pop eax - sti - iret - -; The value of the flags from Basekernel (kernelcode.S) (https://github.com/dthain/basekernel) -idt: - dw isr_0, 8, 0x8e00, 0x0000 - dw isr_1, 8, 0x8e00, 0x0000 - dw isr_2, 8, 0x8e00, 0x0000 - dw isr_3, 8, 0x8e00, 0x0000 - dw isr_4, 8, 0x8e00, 0x0000 - dw isr_5, 8, 0x8e00, 0x0000 - dw isr_6, 8, 0x8e00, 0x0000 - dw isr_7, 8, 0x8e00, 0x0000 - dw isr_8, 8, 0x8e00, 0x0000 - dw isr_9, 8, 0x8e00, 0x0000 - dw isr_10, 8, 0x8e00, 0x0000 - dw isr_11, 8, 0x8e00, 0x0000 - dw isr_12, 8, 0x8e00, 0x0000 - dw isr_13, 8, 0x8e00, 0x0000 - dw isr_14, 8, 0x8e00, 0x0000 - dw isr_15, 8, 0x8e00, 0x0000 - dw isr_16, 8, 0x8e00, 0x0000 - dw isr_17, 8, 0x8e00, 0x0000 - dw isr_18, 8, 0x8e00, 0x0000 - dw isr_19, 8, 0x8e00, 0x0000 - dw isr_20, 8, 0x8e00, 0x0000 - dw isr_21, 8, 0x8e00, 0x0000 - dw isr_22, 8, 0x8e00, 0x0000 - dw isr_23, 8, 0x8e00, 0x0000 - dw isr_24, 8, 0x8e00, 0x0000 - dw isr_25, 8, 0x8e00, 0x0000 - dw isr_26, 8, 0x8e00, 0x0000 - dw isr_27, 8, 0x8e00, 0x0000 - dw isr_28, 8, 0x8e00, 0x0000 - dw isr_29, 8, 0x8e00, 0x0000 - dw isr_30, 8, 0x8e00, 0x0000 - dw isr_31, 8, 0x8e00, 0x0000 - dw isr_32, 8, 0x8e00, 0x0000 - dw isr_33, 8, 0x8e00, 0x0000 - dw isr_34, 8, 0x8e00, 0x0000 - dw isr_35, 8, 0x8e00, 0x0000 - dw isr_36, 8, 0x8e00, 0x0000 - dw isr_37, 8, 0x8e00, 0x0000 - dw isr_38, 8, 0x8e00, 0x0000 - dw isr_39, 8, 0x8e00, 0x0000 - dw isr_40, 8, 0x8e00, 0x0000 - dw isr_41, 8, 0x8e00, 0x0000 - dw isr_42, 8, 0x8e00, 0x0000 - dw isr_43, 8, 0x8e00, 0x0000 - dw isr_44, 8, 0x8e00, 0x0000 - dw isr_45, 8, 0x8e00, 0x0000 - dw isr_46, 8, 0x8e00, 0x0000 - dw isr_47, 8, 0x8e00, 0x0000 - dw isr_48, 8, 0x8e00, 0x0000 - -idtr: - idt_size_in_bytes : dw idtr - idt - idt_base_address : dd idt +isr_0: + cli + push 0 + jmp isr_basic + +isr_1: + cli + push 1 + jmp isr_basic + +isr_2: + cli + push 2 + jmp isr_basic + +isr_3: + cli + push 3 + jmp isr_basic + +isr_4: + cli + push 4 + jmp isr_basic + +isr_5: + cli + push 5 + jmp isr_basic + +isr_6: + cli + push 6 + jmp isr_basic + +isr_7: + cli + push 7 + jmp isr_basic + +isr_8: + cli + push 8 + jmp isr_basic + +isr_9: + cli + push 9 + jmp isr_basic + +isr_10: + cli + push 10 + jmp isr_basic + +isr_11: + cli + push 11 + jmp isr_basic + +isr_12: + cli + push 12 + jmp isr_basic + +isr_13: + cli + push 13 + jmp isr_basic + +isr_14: + cli + push 14 + jmp isr_basic + +isr_15: + cli + push 15 + jmp isr_basic + +isr_16: + cli + push 16 + jmp isr_basic + +isr_17: + cli + push 17 + jmp isr_basic + +isr_18: + cli + push 18 + jmp isr_basic + +isr_19: + cli + push 19 + jmp isr_basic + +isr_20: + cli + push 20 + jmp isr_basic + +isr_21: + cli + push 21 + jmp isr_basic + +isr_22: + cli + push 22 + jmp isr_basic + +isr_23: + cli + push 23 + jmp isr_basic + +isr_24: + cli + push 24 + jmp isr_basic + +isr_25: + cli + push 25 + jmp isr_basic + +isr_26: + cli + push 26 + jmp isr_basic + +isr_27: + cli + push 27 + jmp isr_basic + +isr_28: + cli + push 28 + jmp isr_basic + +isr_29: + cli + push 29 + jmp isr_basic + +isr_30: + cli + push 30 + jmp isr_basic + +isr_31: + cli + push 31 + jmp isr_basic + +; System Timer +isr_32: + ; part 1 + + cli ; step 1 disable interrupt (when handling interrupt, btetter to not receive any other interrupt) + + ; step 2 and 3 + ; when this interrupt handler is called, context of the processor is the context of suspended process + ; we define ISRs gate descriptors as interrupt gates in IDT + ; -> if we define as task gates, the context of the suspended gates in the IDT table will not be available directly on processor's registers + + ; since context is reachable, we store in the stack (useful when scheduler needs to copy the context of the suspended process to the memory) + ; push into the stack also provides 2 benefits + ; 1. we can use register in current code as we wont lose the suspended process context + ; 2. method of passing parameters + + pusha ; step 2 pusha pushes values of all general registers in the order: EAX, ECX, EDX, EBX, ESP, EBP, ESI and EDI + + + ; step 3 to push EIP + + ; Curr EIP is a pointer to curr instruction, not the one we want to suspend + + ; Suppose A is running + ; We want to suspend A, so ISR32 is called + ; Return address to where A suspended is stored at the top of the stack (based on calling convention) + ; Then we run ISR32 + ; At this point, ISR32 has put 8 registers to the stack (because of pusha) + ; ESP points to top of stack, to find return address of A (EIP of A) simply use esp + 32 + mov eax, [esp + 32] + push eax + + call scheduler ; step 4 + + ; ... ; + + ; part 2 + + ; step 5 + + ; after scheduler, tell PIC we finish handling IRQ by send end of interrupt command to PIC + mov al, 0x20 + out 0x20, al + + ; step 6 + + ; jump to memory address in which the selected process were suspended + ; exploit calling convention again + + ; remove all values added to stack by adding 40 (8 general register + EIP + 4 to get to the start of return address added) + add esp, 40d + push run_next_process + + iret ; step 7 + +isr_33: + cli + push 33 + jmp irq_basic + +isr_34: + cli + push 34 + jmp irq_basic + +isr_35: + cli + push 35 + jmp irq_basic + +isr_36: + cli + push 36 + jmp irq_basic + +isr_37: + cli + push 37 + jmp irq_basic + +isr_38: + cli + push 38 + jmp irq_basic + +isr_39: + cli + push 39 + jmp irq_basic + +isr_40: + cli + push 40 + jmp irq_basic + +isr_41: + cli + push 41 + jmp irq_basic + +isr_42: + cli + push 42 + jmp irq_basic + +isr_43: + cli + push 43 + jmp irq_basic + +isr_44: + cli + push 44 + jmp irq_basic + +isr_45: + cli + push 45 + jmp irq_basic + +isr_46: + cli + push 46 + jmp irq_basic + +isr_47: + cli + push 47 + jmp irq_basic + +isr_48: + cli + push 48 + jmp irq_basic + +isr_basic: +; cli + call interrupt_handler + + pop eax + sti + iret + +irq_basic: +; cli + call interrupt_handler + + mov al, 0x20 + out 0x20, al + + cmp byte [esp], 40d ; Interrupt number + jnge irq_basic_end + + mov al, 0xa0 + out 0x20, al + + irq_basic_end: + pop eax + sti + iret + +; The value of the flags from Basekernel (kernelcode.S) (https://github.com/dthain/basekernel) +idt: + dw isr_0, 8, 0x8e00, 0x0000 + dw isr_1, 8, 0x8e00, 0x0000 + dw isr_2, 8, 0x8e00, 0x0000 + dw isr_3, 8, 0x8e00, 0x0000 + dw isr_4, 8, 0x8e00, 0x0000 + dw isr_5, 8, 0x8e00, 0x0000 + dw isr_6, 8, 0x8e00, 0x0000 + dw isr_7, 8, 0x8e00, 0x0000 + dw isr_8, 8, 0x8e00, 0x0000 + dw isr_9, 8, 0x8e00, 0x0000 + dw isr_10, 8, 0x8e00, 0x0000 + dw isr_11, 8, 0x8e00, 0x0000 + dw isr_12, 8, 0x8e00, 0x0000 + dw isr_13, 8, 0x8e00, 0x0000 + dw isr_14, 8, 0x8e00, 0x0000 + dw isr_15, 8, 0x8e00, 0x0000 + dw isr_16, 8, 0x8e00, 0x0000 + dw isr_17, 8, 0x8e00, 0x0000 + dw isr_18, 8, 0x8e00, 0x0000 + dw isr_19, 8, 0x8e00, 0x0000 + dw isr_20, 8, 0x8e00, 0x0000 + dw isr_21, 8, 0x8e00, 0x0000 + dw isr_22, 8, 0x8e00, 0x0000 + dw isr_23, 8, 0x8e00, 0x0000 + dw isr_24, 8, 0x8e00, 0x0000 + dw isr_25, 8, 0x8e00, 0x0000 + dw isr_26, 8, 0x8e00, 0x0000 + dw isr_27, 8, 0x8e00, 0x0000 + dw isr_28, 8, 0x8e00, 0x0000 + dw isr_29, 8, 0x8e00, 0x0000 + dw isr_30, 8, 0x8e00, 0x0000 + dw isr_31, 8, 0x8e00, 0x0000 + dw isr_32, 8, 0x8e00, 0x0000 + dw isr_33, 8, 0x8e00, 0x0000 + dw isr_34, 8, 0x8e00, 0x0000 + dw isr_35, 8, 0x8e00, 0x0000 + dw isr_36, 8, 0x8e00, 0x0000 + dw isr_37, 8, 0x8e00, 0x0000 + dw isr_38, 8, 0x8e00, 0x0000 + dw isr_39, 8, 0x8e00, 0x0000 + dw isr_40, 8, 0x8e00, 0x0000 + dw isr_41, 8, 0x8e00, 0x0000 + dw isr_42, 8, 0x8e00, 0x0000 + dw isr_43, 8, 0x8e00, 0x0000 + dw isr_44, 8, 0x8e00, 0x0000 + dw isr_45, 8, 0x8e00, 0x0000 + dw isr_46, 8, 0x8e00, 0x0000 + dw isr_47, 8, 0x8e00, 0x0000 + dw isr_48, 8, 0x8e00, 0x0000 + +idtr: + idt_size_in_bytes : dw idtr - idt + idt_base_address : dd idt diff --git a/kernel.elf b/kernel.elf index 3e71ce538b2bbd298ca14cb94a44e31bc146c1db..2770f50ab92dfdda10f16dbe8f2143be7f8ace65 100644 GIT binary patch delta 693 zcmaiwJxD@P6vxkf&udv~_F-C3s1K6T#8+ZbOC>==Lj^)h^Z}v{iGxy0Sy)R;*`=W+ zXlQc@+6scGr77Bjwi;T3hK9h-u`9(}I&j|q{Ql?ObKZLowjKL{hfSBffzm`&x26E& z^{Y~;6mK2Hw}1KkdXjZULg9Wrzmm`7^7`h$KqwsP_2_yCZQ)Z!*uGd$T!n6$EW?4? zR|8bysDWb!o-^>gftQdkF@2aVz#xrU3!Faz>qt+SwFBE&SN`xG)?W787s&gVK};HW zCY-9~OeL1Hi|I@{2ifIhI+Lu{Vn{8DE7e`-z_Usn0DY`d572|k6o3G+1z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-`uw zGrqcQK|PX3<>RJI#YHM72iwKq1v%OwhZAzJOQw=(UKaCdzGR%^xil{UE~NRQShdo; zD5`0`AWCUIFN$eiaCsFcV0_8TExZa?(sI5i!E^8xyorFX7U6aHY9U_^`KpjFH~DHl zUv35kbB^$;UFaEj_8>j(c9*ZfD3}y8yrS8BMVlC{)ZsUEY|`dc%^t1l#)(5PV{h~?C?=qox@0FJZzdudm<|>I3xb8f cn!uXD!eA|6tzZ}%1&e{*0cL!fh?vdVf9R0KZU6uP delta 1486 zcmZvbT}TvB6vyw(e(S6*dji)O?n?*S(v!@-%Lk_sn$ z^sOx}?-U6+yf|Ui1KCLX)=>D2eRyyt2<{^&O?n6!Lq12oM!rMNAU`3$A%7vAy@fhu z$V%j@Ub!%^4vqE5I%GX^C$a%~5ZR18f;@_BL!L!;B72Zmko_`>LF66eUF1Dv8u<+Q z0{I3xh5Ue=LCzvSBj=Dmka8Y{y{~W*9%LDE8L~^L>m&S&s~^wh(jcwv0yHaZ&`dz1 z8uf3b$Z(w6p!n43~*Yf7NAq7C9ah@NF@1x>y2X(*I6e>QbglcU@6TdkeK6&SPRHE=`9Is_GnE0T`^? z9TQYP6IxtSMJ+0s5j#ug3Z4imsi=HKRZ&z`gvgi}D4Id8;%=y<#zMSa7zeeuTaDF% zrSWMiIg;{73(#ucl?G74#4R#gAK zpk}xUSIrOS&_TGE0DH7|U0>J}%Pwobuo9I9nrbXtpq zm3exyq@|S`5xeH+VxL>{agyBC! zlHILe8=G7BQ{}!E2`%Qc$tGn%I=>(Z5F&&P!Vckpa6-5s+z=j!5{Oa=mhXiqgD8J6 I=*^110pKF%6#xJL diff --git a/main.c b/main.c index b424644..bbd4a6f 100644 --- a/main.c +++ b/main.c @@ -1,5 +1,8 @@ +#include "heap.h" +#include "paging.h" #include "screen.h" #include "scheduler.h" + /* There are two VGA modes: text and grapics To show on screen, entities (pixel or char) should be loaded to video memory (a part of main memory) @@ -18,6 +21,8 @@ void kernel_main() // ... // + heap_init(); + paging_init(); screen_init(); process_init(); scheduler_init(); @@ -34,10 +39,10 @@ void kernel_main() // ... // - process_create( &processA, &p1 ); - process_create( &processB, &p2 ); - process_create( &processC, &p3 ); - process_create( &processD, &p4 ); + process_create( &processA ); + process_create( &processB ); + process_create( &processC ); + process_create( &processD ); asm( "sti" ); diff --git a/minios.bin b/minios.bin old mode 100755 new mode 100644 diff --git a/minios.elf b/minios.elf old mode 100755 new mode 100644 diff --git a/minos.bin b/minos.bin new file mode 100755 index 0000000000000000000000000000000000000000..4b387ab4c7f3ef27590e8dd5f9860ae359015e32 GIT binary patch literal 2950 zcmZvee{3AZ702J6?~+S$=GMU`1}@3^N5dsCt(%aNrcG-gBQ>DFHR&}-kxP+tDc*vO z96Ll5holSDO_x|EX{8c=C|CCn1pk-{kQ<@)jx(%D9pzf`$F+5(YZ}~L_Wrn1w{g~P zu5aFsZA4j1^ZCx3H*aR&yxH?}6GKJ24(u4%w}Bl6I|*l=84iONRc^Wfd3!C`J0brj zjMiLG-&B4B+66Tq)v||-2_@Q`&5zbiYtv^(wdtnO_;hA8hzuZ==_YJJwE3vA?!%h= zSRA5I%xCIf0*E#jMT}YiI4**Wsi=mELxnLU3}uH(L$=*fBRc+5ts>7{1mY=4Px6zC zFm?J*r-1{s!^^_}o(|4lMNo0>B?g?ki8am+V$j(_3^|*K%baH7a_1Ie*jY_n;jARC zbOOXxj)xoZ^oa8bvDW#Rc!P797zwn%)y})b8=Z5+dgs@~2In>6P0lZg zYn(I0M&}gqX6L8GTbv&gZ*>PfJ?0+u^tJ9`PhaQuc=~#`+xxz`t5r+b2bKZgQE0|^ z{E@a704{oZle^E;o89|8y~W+_>86+-;s7ciTOEqr2JDH@O=; zeY4x->1}Sz({Fdzc={LJ)t>$(x7O3!-LSnQ0Px`4MSBZUtaSYAt?{RVqi3fzw0?+X z1496Rk^H-)EBPDPja8+0m&}OA4(pU{E?&~ zX-b}!d{J^l@^#5k$+slWN&Zf9T=K7ymnHupS(f~#gQ#$WsljeoMx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Or6(80KMHj-4R#AXZ_mx)i*tBs4maiSbvbN+m*87)B~CH} z<6Q@CllQ9+yctaUGwL=S|6k*781!m3OZwjjrVZjnvi&jeTZs1;+5RMWgA(rr@H?2_ z-Lkz8Os{foykT(JgJ?wY;e7kRum6&<)4(*ox51}?pOt($UN&hrPKEqG%;`S@uD%af z0@sE5XTkI;>7H+CPXBx`z2d-)&$k#%8*rB^!SoVK#fSf;QVRb37Zc-~mD4^OOs`vR z|38Ci59soIa0|vW7x8F(mx0y!ECV0He7`H(E5PdcuLsY$-}dNu#Aj>8an?Y{U&-!Q1snLJzgYVtkLu#+^mmgs&L9k-B1(gZ(jYS;qBMvo4I)Z|h|(aU zAiKC7>6Xf|u-d{5YbQ>JoXbKrU%D)~npljHSPky%P~0%cz`ai|UA(H<2zRvLNfKhs zMzEb4gKHzPwcHE0uUMa`!)lAfaig`xZ*u!%y@%TH!sYTMu7Tyz9!KX06YE|VG2OLG z!*N{~V^neoSX+_tSUScUOd3q*lO6YQyIsmc9r5`0BQb*;cqD|~CJ{#0X<4(Fu_1Xi zK8lVK>Xn#O`Y9*6jwX{j7&Hdyl_0Phu2PdHMUXKrb lFVYxKz=zK1mSiPkBlzxgi#tC0o>l$AbFlw)ouIDYe*squnE?O* literal 0 HcmV?d00001 diff --git a/notes/v4_notes.md b/notes/v4_notes.md index dcf4923..90886bb 100644 --- a/notes/v4_notes.md +++ b/notes/v4_notes.md @@ -112,3 +112,12 @@ Entry of page table -> exactly the same as entry of page directory, its size is Some diff: - Bit 7: ignored (used to decide page size in page directory) - Bit 6: dirty bit (ignored in page directory) -> indicate we need to change, this is old entry -> because we don't delete old entry just set dirty bit to 1 (1: is dirty 0: is not dirty) + +## Implementing Memory Management + +We need memory managemetn so we can allocate memory dynammically + +Paging: +- valid page directory should be initialized, its address should be loaded in the register CR3 +- paging should be enabled by modfying the value of CR0 -> tell processor to start using paging and translate linear address (instead of interpreting linear address as physical address) +- We need to implement paging for each process, but here we only implement paging for kernel \ No newline at end of file diff --git a/paging.c b/paging.c new file mode 100644 index 0000000..e091d73 --- /dev/null +++ b/paging.c @@ -0,0 +1,52 @@ +#include "paging.h" + +unsigned int *page_directory; + +int create_page_entry( int base_address, char present, char writable, char privilege_level, char cache_enabled, char +write_through_cache, char accessed, char page_size, char dirty ) +{ + // each parameter is a field in PTE + // other than base address, they values are binary (0 or 1) + // + + int entry = 0; + + entry |= present; + entry |= writable << 1; + entry |= privilege_level << 2; + entry |= write_through_cache << 3; + entry |= cache_enabled << 4; + entry |= accessed << 5; + entry |= dirty << 6; + entry |= page_size << 7; + + return base_address | entry; +} + +void paging_init() +{ + // PART 1 + + // First we allocate 4 * 1024 from the kernel's heap for the page directory + // that's because the size of each entry is 4 bytes + // note: while we need 3 entries, we are allocating 1024 + // -> because base memory address of a page table and page frame both should be page-aligned + + unsigned int curr_page_frame = 0; + page_directory = kalloc(4 * 1024); + + for (int currPDE = 0; currPDE < PDE_NUM; currPDE++) { + unsigned int *pagetable = kalloc(4 * PTE_NUM); + + for (int currPTE = 0; currPTE < PTE_NUM; currPTE++, curr_page_frame++) { + pagetable[currPTE] = create_page_entry(curr_page_frame * 4096, 1, 0, 0, 1, 1, 0, 0, 0); + + page_directory[currPDE] = create_page_entry(pagetable, 1, 0, 0, 1, 1, 0, 0, 0); + } + } + + // PART 2 + + load_page_directory(); + enable_paging(); +} \ No newline at end of file diff --git a/paging.elf b/paging.elf new file mode 100644 index 0000000000000000000000000000000000000000..f6df2d7da517ab9f5a973e31e1b01f5a77d5539c GIT binary patch literal 1244 zcma)4&ui2`6n;s6*Oj&+Sg>FZ3M<;UTY9LTgfbSPN=2dvS(j`Y+HJSHvYQ2aXjO7a z3>88A3;Yi}cq(N>7rIIhd+1>gJp@76Vh#~{@E~m8OJ=l+h%d~1-}mOro0pk9V{^A8 zNdgfPbipqLFxM5YOhu4{K^Oql`SS3=eJhxDS;D0mR^MeIl^@z>{s0RR4y0O4TAnY* ztm*k(G28e2?wIX)eoxHmp5Gg@hUfPob6Ni>7FzY`M~}0a9qiZ&Mt9i}ZDR$AB^U;1 z|LAl&R(<##C3y>nZ~kI%SbLWRFJoHM(hNEqw>Gj7Qd~w9RjE@}9flTPMC_fNpe+;5^9P?-9@7UonPA zyv21AQ3ReRToVG3^voX`o@k5t;-aF1UN$t-$f7o~M$s&<@uh6Om^WcXD-=pP6iV7c zY+1;c4c#oE%_wTQLi8dQqVf$Kat}ZgQIY`;xju&pid = curr_pid++; // initialize context diff --git a/process.elf b/process.elf index e1c3efbb46ccd01fb49b57bd83fb9281bea36a45..6d7ee4fa99763f768afa166dc2336dbb56ae13ac 100644 GIT binary patch delta 434 zcmZqR*uybFfpN`5MT7e0HxkWnc(M#${Q3X?fAbN6PS-CB8GxWSfU#2)#OMzF(#h2A z`sKI-3z!RHallzTaFzg^B?4zjz*#bImI9a+$^kU8GeE@%Y_bMawmX!gGe8F@)D5;) zq!lC%c24sF#>F7cgp-FS7c$9fxjQ>sDQJWymFAU{Di|8-ndlkl8kT~&hIK|pdIlz% zP~pk?jG5wFfLetZ7#X}kWI? z)mar785ndX`!Xvt`T%9rS$%-~hRJi8m08aKS%H&}GAm0Y0Cjr;O@#rV1Q-AS^jT&j delta 377 zcmdnP(ZDf5fw5qsqCx#a1|aASVC)nHF}g!}I+?m%d5$}VrB5;-j zoFxNiDS%m_96%#G1605UYd|HtLpeGFbmV|y-C%1)T0s(E=QJN+Tnyq&h@H&HD6He| z>};i=5t>w*S5m5AXsBnbXP|3X3g#Nt85!vrnCKa5LM0||WD=en!x+I1GDwJlaq?+K zZ({}qRv?d&nSp^HL<7Ah2c^}a^l}i*#K5oyL<7}rnHJ^I?8_)V*@szxkzsNyvpOpSP)2WZCs0Oj@>(F@0LU+xe3Mz3bpep&HJOn` MnN for modulo in round robin extern int curr_pid; void process_init(); -void process_create( int *, process_t * ); // params: pointer to base address of process, pointer to PCB \ No newline at end of file +process_t *process_create( int * ); // params: pointer to base address of process, pointer to PCB \ No newline at end of file diff --git a/scheduler.elf b/scheduler.elf index a8192cccc9d3113a8de0c0f6294024ad50ae61f6..c72895ca002001b75f6095f457d113247fdadbc7 100644 GIT binary patch delta 80 zcmX@XbA)Gt0%Olc#RZH~CVB?ChNVfRc_pQWbw);d1}2&chK71T;m!9M1(_KWCVymE h%&0SYDyuT%oyj{{)q&(gAbDmoC!0E>#biS^aRBTJ7(@U7 delta 102 zcmX@YbAo4r0^@{@iVGNJjP(q34NH?s^GZq$>x_)_3{3P4H5CjE^?(wSC$b1He#6Mj zm@@e-%VI{o$rD+XneH)8zQ-sw`3$Q7NU}_pWK(DKnC!?V4gj4A6@~x+ delta 104 zcmcb@bAxAs0^@>>iV{px#(D<2hNVfRc_pQWbw);d1}1ujnhJ)7dd8CjnS>{Mv2ktA zVVc0i7&7@U%VI{o$qQMPS;LqZ7#JoyvI$SV!z#cSG5Ia4Ix7b=1A`Y>OovT?(Py$P Gn>YaH0veY9 diff --git a/starter.asm b/starter.asm index 04ffeef..4f74cf1 100644 --- a/starter.asm +++ b/starter.asm @@ -1,148 +1,154 @@ -; runs in 16 bits -; to prepare proper environment for main kernel by: -; - init and load GDT -; - set interrupts -; - set video mode -; - change 16 bit real mode to 32 bit protected mode - -; tell NASM to generate 16 bit code since we will be using 16 bit real mode -; in the bootloader don't need to do this because: for flat binary the default is 16 bit but we use ELF32 -bits 16 -; extern tells NASM that there is a function/ variable define outside this code, it will be figured out by the linker - -extern kernel_main -extern interrupt_handler -extern scheduler -extern run_next_process - -start: - mov ax, cs - mov ds, ax - - ; --- ; - - call load_gdt - call init_video_mode - call enter_protected_mode - call setup_interrupts - call load_task_register - - ; --- ; - - call 08h:start_kernel - -load_gdt: - cli - lgdt [gdtr - start] - - ret - -setup_interrupts: - call remap_pic - call load_idt - - ret - -init_video_mode: - ;; Set Video Mode - mov ah, 0h - mov al, 03h ; 03h For Text Mode. 13h For Graphics Mode. - int 10h - - ;; Disable Text Cursor - mov ah, 01h - mov cx, 2000h - int 10h - - ret - -enter_protected_mode: - mov eax, cr0 - or eax, 1 - mov cr0, eax - - ret - -remap_pic: - mov al, 11h - - send_init_cmd_to_pic_master: - out 0x20, al - - send_init_cmd_to_pic_slave: - out 0xa0, al - - ; ... ; - - make_irq_starts_from_intr_32_in_pic_master: - mov al, 32d - out 0x21, al - - make_irq_starts_from_intr_40_in_pic_slave: - mov al, 40d - out 0xa1, al - - ; ... ; - - tell_pic_master_where_pic_slave_is_connected: - mov al, 04h - out 0x21, al - - tell_pic_slave_where_pic_master_is_connected: - mov al, 02h - out 0xa1, al - - ; ... ; - - mov al, 01h - - tell_pic_master_the_arch_is_x86: - out 0x21, al - - tell_pic_slave_the_arch_is_x86: - out 0xa1, al - - ; ... ; - - mov al, 0h - - make_pic_master_enables_all_irqs: - out 0x21, al - - make_pic_slave_enables_all_irqs: - out 0xa1, al - - ; ... ; - - ret - -load_idt: - lidt [idtr - start] - ret - -load_task_register: - mov ax, 40d - ltr ax - - ret - -bits 32 -start_kernel: - mov eax, 10h - mov ds, eax - mov ss, eax - - mov eax, 0h - mov es, eax - mov fs, eax - mov gs, eax - - ;sti - - call kernel_main - -%include "gdt.asm" -%include "idt.asm" - -tss: - dd 0 \ No newline at end of file +bits 16 +extern kernel_main +extern interrupt_handler +extern scheduler +extern run_next_process +extern page_directory + +global load_page_directory +global enable_paging + +start: + mov ax, cs + mov ds, ax + + ; --- ; + + call load_gdt + call init_video_mode + call enter_protected_mode + call setup_interrupts + call load_task_register + + ; --- ; + + call 08h:start_kernel + +load_gdt: + cli + lgdt [gdtr - start] + + ret + +setup_interrupts: + call remap_pic + call load_idt + + ret + +init_video_mode: + ;; Set Video Mode + mov ah, 0h + mov al, 03h ; 03h For Text Mode. 13h For Graphics Mode. + int 10h + + ;; Disable Text Cursor + mov ah, 01h + mov cx, 2000h + int 10h + + ret + +enter_protected_mode: + mov eax, cr0 + or eax, 1 + mov cr0, eax + + ret + +remap_pic: + mov al, 11h + + send_init_cmd_to_pic_master: + out 0x20, al + + send_init_cmd_to_pic_slave: + out 0xa0, al + + ; ... ; + + make_irq_starts_from_intr_32_in_pic_master: + mov al, 32d + out 0x21, al + + make_irq_starts_from_intr_40_in_pic_slave: + mov al, 40d + out 0xa1, al + + ; ... ; + + tell_pic_master_where_pic_slave_is_connected: + mov al, 04h + out 0x21, al + + tell_pic_slave_where_pic_master_is_connected: + mov al, 02h + out 0xa1, al + + ; ... ; + + mov al, 01h + + tell_pic_master_the_arch_is_x86: + out 0x21, al + + tell_pic_slave_the_arch_is_x86: + out 0xa1, al + + ; ... ; + + mov al, 0h + + make_pic_master_enables_all_irqs: + out 0x21, al + + make_pic_slave_enables_all_irqs: + out 0xa1, al + + ; ... ; + + ret + +load_idt: + lidt [idtr - start] + ret + +load_task_register: + mov ax, 40d + ltr ax + + ret + +bits 32 +load_page_directory: + mov eax, [page_directory] + mov cr3, eax + + ret + +enable_paging: + mov eax, cr0 + or eax, 80000000h + mov cr0, eax + + ret + +start_kernel: + mov eax, 10h + mov ds, eax + mov ss, eax + + mov eax, 0h + mov es, eax + mov fs, eax + mov gs, eax + + ;sti + + call kernel_main + +%include "gdt.asm" +%include "idt.asm" + +tss: + dd 0 diff --git a/starter.o b/starter.o index bad2e69c28015f3b981f337da3eecf8c6e53715a..f11e2d4f57b910e0e1fd9becba3b50d5a348bb25 100644 GIT binary patch literal 4560 zcmb7`YitzP8HUg78Unav4R%Ag#IZ4P+?crD3zS0JkP@P#q*n_y#Equo-3i{Yy}Owi zQwWWUYAUsHizl{zwtU1Fh#Rfqmxl$r9kkY@El zF2&~~ny7jc$eKmd0wKERht<}$3~hWRTQN?CHvqfvla!e&@#A@08-+M7J87#PYdd^# zwGsSRLWmF0Dd);Da>^q7o_=#;rm{>_)`-fTqLL7mo#Mzr^h62cmJ6a>xlL5QF3PWo z$@qn)*NoqZwhK+=MBCZN#@;j%YtNP^m(8}#9-C~NZJ+F#JwDk0#z14X9i@c8 zF(Q64CH@irdtCfVh+gp=Mn{eaet=_)93%LaVl4QkVm#Qa*bt-?7X)`HE)3Qx-W04-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