From dacf0315f3a54838d803f9d7af0c24ef04112f1b Mon Sep 17 00:00:00 2001 From: c0repwn3r Date: Mon, 9 May 2022 09:45:06 -0400 Subject: [PATCH] Interrupts dont work and I dont know why --- Makefile | 56 +++++ bin/boot.bin | Bin 0 -> 512 bytes bin/kernel.bin | Bin 0 -> 4256 bytes getinblocks.py | 4 + obj/kernel/entry.o | Bin 0 -> 480 bytes obj/kernel/kernel.o | Bin 0 -> 5140 bytes obj/kernel/platform/drivers/ports.o | Bin 0 -> 2680 bytes obj/kernel/platform/interrupts/idt.o | Bin 0 -> 3084 bytes obj/kernel/platform/interrupts/int.o | Bin 0 -> 1536 bytes obj/kernel/platform/interrupts/isr.o | Bin 0 -> 7312 bytes obj/kernel/print.o | Bin 0 -> 6632 bytes obj/kernel/strings.o | Bin 0 -> 3652 bytes obj/kernel/util.o | Bin 0 -> 2792 bytes old_src/16bit/boot.asm | 28 +++ old_src/16bit/disk.asm | 40 ++++ old_src/16bit/disk_boot.asm | 28 +++ old_src/16bit/segmentation.asm | 26 +++ old_src/32bit_gdt.asm | 31 +++ old_src/32bit_jump.asm | 22 ++ old_src/32bit_main.asm | 27 +++ old_src/32bit_print.asm | 26 +++ old_src/function.c | 3 + old_src/functioncalls.c | 7 + old_src/old-16b/basic_boot.asm | 5 + old_src/old-16b/boot_hello.asm | 18 ++ old_src/old-16b/boot_memory.asm | 27 +++ old_src/old-16b/boot_org.asm | 0 old_src/old-16b/boot_stack.asm | 38 ++++ old_src/old_bin/boot_hello.bin | Bin 0 -> 512 bytes old_src/old_bin/boot_memory.bin | Bin 0 -> 512 bytes old_src/old_bin/boot_simple.bin | Bin 0 -> 512 bytes old_src/old_bin/boot_stack.bin | Bin 0 -> 512 bytes old_src/print.asm | 33 +++ old_src/print_hex.asm | 38 ++++ os-image.bin | Bin 0 -> 4768 bytes src/boot/boot.asm | 39 ++++ src/boot/disk/disk.asm | 40 ++++ src/boot/kernel.asm | 11 + src/boot/output/print.asm | 33 +++ src/boot/output/print_hex.asm | 38 ++++ src/boot/output/vga-print.asm | 26 +++ src/boot/protected/gdt.asm | 31 +++ src/boot/protected/protected-switch.asm | 24 ++ src/kernel/entry.asm | 4 + src/kernel/kernel.c | 65 ++++++ src/kernel/platform/drivers/ports.c | 26 +++ src/kernel/platform/drivers/ports.h | 4 + src/kernel/platform/interrupts/idt.c | 20 ++ src/kernel/platform/interrupts/idt.h | 27 +++ src/kernel/platform/interrupts/int.asm | 286 ++++++++++++++++++++++++ src/kernel/platform/interrupts/isr.c | 89 ++++++++ src/kernel/platform/interrupts/isr.h | 48 ++++ src/kernel/platform/types.h | 18 ++ src/kernel/print.c | 110 +++++++++ src/kernel/print.h | 44 ++++ src/kernel/strings.c | 48 ++++ src/kernel/strings.h | 10 + src/kernel/util.c | 25 +++ src/kernel/util.h | 8 + 59 files changed, 1531 insertions(+) create mode 100644 Makefile create mode 100644 bin/boot.bin create mode 100755 bin/kernel.bin create mode 100755 getinblocks.py create mode 100644 obj/kernel/entry.o create mode 100644 obj/kernel/kernel.o create mode 100644 obj/kernel/platform/drivers/ports.o create mode 100644 obj/kernel/platform/interrupts/idt.o create mode 100644 obj/kernel/platform/interrupts/int.o create mode 100644 obj/kernel/platform/interrupts/isr.o create mode 100644 obj/kernel/print.o create mode 100644 obj/kernel/strings.o create mode 100644 obj/kernel/util.o create mode 100644 old_src/16bit/boot.asm create mode 100644 old_src/16bit/disk.asm create mode 100644 old_src/16bit/disk_boot.asm create mode 100644 old_src/16bit/segmentation.asm create mode 100644 old_src/32bit_gdt.asm create mode 100644 old_src/32bit_jump.asm create mode 100644 old_src/32bit_main.asm create mode 100644 old_src/32bit_print.asm create mode 100644 old_src/function.c create mode 100644 old_src/functioncalls.c create mode 100644 old_src/old-16b/basic_boot.asm create mode 100644 old_src/old-16b/boot_hello.asm create mode 100644 old_src/old-16b/boot_memory.asm create mode 100644 old_src/old-16b/boot_org.asm create mode 100644 old_src/old-16b/boot_stack.asm create mode 100644 old_src/old_bin/boot_hello.bin create mode 100644 old_src/old_bin/boot_memory.bin create mode 100644 old_src/old_bin/boot_simple.bin create mode 100644 old_src/old_bin/boot_stack.bin create mode 100644 old_src/print.asm create mode 100644 old_src/print_hex.asm create mode 100644 os-image.bin create mode 100644 src/boot/boot.asm create mode 100644 src/boot/disk/disk.asm create mode 100644 src/boot/kernel.asm create mode 100644 src/boot/output/print.asm create mode 100644 src/boot/output/print_hex.asm create mode 100644 src/boot/output/vga-print.asm create mode 100644 src/boot/protected/gdt.asm create mode 100644 src/boot/protected/protected-switch.asm create mode 100644 src/kernel/entry.asm create mode 100644 src/kernel/kernel.c create mode 100644 src/kernel/platform/drivers/ports.c create mode 100644 src/kernel/platform/drivers/ports.h create mode 100644 src/kernel/platform/interrupts/idt.c create mode 100644 src/kernel/platform/interrupts/idt.h create mode 100644 src/kernel/platform/interrupts/int.asm create mode 100644 src/kernel/platform/interrupts/isr.c create mode 100644 src/kernel/platform/interrupts/isr.h create mode 100644 src/kernel/platform/types.h create mode 100644 src/kernel/print.c create mode 100644 src/kernel/print.h create mode 100644 src/kernel/strings.c create mode 100644 src/kernel/strings.h create mode 100644 src/kernel/util.c create mode 100644 src/kernel/util.h diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c4564c7 --- /dev/null +++ b/Makefile @@ -0,0 +1,56 @@ +# $@ = target file +# $< = first dependency +# $^ = all dependencies + +GDB = gdb + +C_FILES = $(shell find src/ -type f -name '*.c') +CO_FILES = $(patsubst src/%.c, obj/%.o, $(C_FILES)) +ASM_FILES = $(shell find src/kernel/ -type f -name '*.asm') +AO_FILES = $(patsubst src/kernel/%.asm, obj/kernel/%.o, $(ASM_FILES)) +ABIN_FILES = $(patsubst src/%.asm, bin/%.bin, $(ASM_FILES)) + +os-image.bin: bin/boot.bin bin/kernel.bin + cat $^ > $@ + +bin/boot.bin: src/boot/boot.asm bin/kernel.bin .FORCE + sed -i.orig "s@CH_REPLACE_BOOTSECTORCOUNT@$(shell ./getinblocks.py $(shell du -b "bin/kernel.bin" | cut -f 1))@g" src/boot/kernel.asm + nasm -Isrc/boot/ $< -f bin -o $@ + mv src/boot/kernel.asm.orig src/boot/kernel.asm + +.FORCE: + +bin/kernel.bin: obj/kernel/entry.o ${CO_FILES} ${AO_FILES} + i386-elf-ld -o $@ -Ttext 0x1000 $^ --oformat binary + +kernel.elf: obj/kernel/entry.o ${CO_FILES} ${AO_FILES} + i386-elf-ld -o $@ -Ttext 0x1000 $^ + +run: clean os-image.bin + qemu-system-x86_64 -hdd os-image.bin + +debug: clean os-image.bin kernel.elf + qemu-system-x86_64 -s -S -hdd os-image.bin & + ${GDB} os-image.bin -ex "symbol-file kernel.elf" -ex "target remote localhost:1234" + + + +obj/%.o: src/%.c + mkdir -p "$(@D)" + i386-elf-gcc -g -ffreestanding -c $< -o $@ + +obj/%.o: src/%.asm + mkdir -p "$(@D)" + nasm -f elf $< -o $@ + +bin/%.bin: src/%.asm + mkdir -p "$(@D)" + nasm -f bin $< -o $@ + +clean: + find obj -type f -name '*.o' -exec rm {} + + find obj -type f -name '*.bin' -exec rm {} + + find bin -type f -name '*.o' -exec rm {} + + find bin -type f -name '*.bin' -exec rm {} + + find . -type f -name '*.dis' -exec rm {} + + rm -f kernel.elf \ No newline at end of file diff --git a/bin/boot.bin b/bin/boot.bin new file mode 100644 index 0000000000000000000000000000000000000000..1a008f37cd371778e54af15a710ac9f0c04af6dc GIT binary patch literal 512 zcmZ8eKWGzC82|1J#2D-y2q}ulLvRo}L?@MwE?otey5u$YPR`uj3-8`RD|bb_CCPBq z4h~%$l};66P>(|DEz%O&(ank=4=+L-b;$FjA_afT_y70(>(rLxUD)W3vj?%Lg17|Y ziYCTTOdGxOBJfIoZe%98R{X?yqd&KEZe;G9ADPN{2axfIwAGFbAPlrhre$Pc|0!VtAlpiIhwlQj4TDV4T$2q$v$5a!_^ z0%*L4CspX3=^JXRs@>JqQppFs_<{4^hF1F;8E9xHA2s9Z@cYI1EZA>NNI#`V=`cM` z#V$Yvx?@pO)Y*P4zD&hrnt?f}^wa^xHJNA6VgT`6N-17#N;N;Y?#dk$aLhQd7Eqg! zHfE0hP-&E_xrv25Y7yl44tKEYJjUFi{@*H>VoSyU%M8M1lLUbsy6)NndK7x?86Brc ib-H<4ICHiL^NFjtRn#LMWorm?RA0R@d&4R2Z~p=8>(a6S literal 0 HcmV?d00001 diff --git a/bin/kernel.bin b/bin/kernel.bin new file mode 100755 index 0000000000000000000000000000000000000000..287711404c2652281636f916fc59be1473700b78 GIT binary patch literal 4256 zcmcgveQZ6swiwKw;w{pe4t?TkixzF#)12Z_qpWrSR+;2ES*5m_a?qh_IOvzJCd)O>EDRbI4aQ2iFlL&%K-E6xf-3npaPjX|o ztJq7tCkJy%DIb`CSY5?@YdIfqyUz8JY|S(lC}n+BrCeOtYBh5jNJzKBjyRkQrD;@|AcyCW5oMenA(W7;a#d8o{#?Ni z$9ms^OM=3eT}9U*5)-cBa9$Y?=V~B5uCiV!AAJAyUxIa}1n0Q@tfA&Ji)uIWvXV!ca%+@g)4=wtfEU>u9)s_>hki8;&Aty$TAD z3HTuPw=hd2o{=f>UYd|8m0ZPeo`iGC$Gl~#LaT_$imXdK>yLTX6C&%0gYVAF;HMnk z3Mu;8Yj?2dzE9;e4p9Iu?szp^U{)E!f)6Ss7o%Xq@xcZytFhFa#KUV~6Myx}O;>r;`0?ui8YzS z_oQ;2=d^A5((FsJf85ac@Sw7RN>-WdRVIfn*JX!$m5QtQ27yzhT9d512RjJ-=ae$^ zN_<}QgIYq^n@+nx@rNee-ro&^$RE9klDs29U9Y3tJ*|6>;{N+OEZbYK}I)Gw9spj!5O$$FwcL$M)w6noh#lJ!L2K(YTW|0ePq zB#-LzSWL2>=m`|Bl)U5Z>ki9~RiHT`pi`)G`!?@XC-Zsi5ozLyzK7z!&lG!EgK!ZC z7m#A#_RrU4#wMySRN&+JT&A>8v@)ybN8qu9P2KC_v}8TeF+5?raQQy&5S4p5fRVdO zUqyb;U48)hXYcY?k$=+R8HM+bPUbue;57%lP=m-)L@qnX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JAApVO#|NsAg{SU~30=<&diV_CB;*8>wqLRcUAgeMLLPPmQsW}ie zFdZl~%zls{3&Y3%$daI#5JM6Ghf#4+vVL}IQC@0}erjGxQKepDaV|q{VrCvhA;>%? HqyPi}v*{*n literal 0 HcmV?d00001 diff --git a/obj/kernel/kernel.o b/obj/kernel/kernel.o new file mode 100644 index 0000000000000000000000000000000000000000..101664c069d1872da047e1ee29b5559a4ac9f537 GIT binary patch literal 5140 zcma)AZ)_Y#6`$R^J)eF4mp>(On$~OMBu=Z`C2rcLX-IQ98^^@4Q^z57NPC>`*1m1- z_T1e)Cys&$bt~GSLJ$;D2tt*hLJ{Nxq7niLRZ5~#Dd7XEgo@x3xbPuDK{j6?lKK61 zXU}_fB^deUz2AFp-pst2c{A%T4-9`+Q4|prMMT6365@8dui5L7Uh#m~C{DhY6v- z3AU^+9U+??)I^LfK@rmCgVToY_Em6>mOC{Y?Il65)hCOQ(l58Tzi>9N`*p+D;wmv&+7SKs|&e>%; z-FnU{=vGBH&d;EsqgQO*EYFloSe(n*cFuC=!p%IV<3&T~p!AZNH!R1{^EpeOgsf79 zvz)7^oH-{oJd_z2$qaDHE(ZabYn0hRvZgbsGjyj?weyIlZ5ZgF777N;v|Pist23^X zOhRWmw(b~ibw)2#ECbkb^*)T>)u(c1$tY0Z+v~33xH{HprewHAp-KD>i>e7F%BVDb z9~BP^PNZLc1uaXWA^IkW8jF!AXDC(xW4s z)d99aL>~cpbSEm6m1t!9XdKo%GZbPsjcO@gMM0uKol9tqVOV+uF#hRaZ3LhN}ISG;NHVrYZ98J?saMO`u9r~z^jZ=t2%ylH5|KJ?PqCK6pycGR>^+19!t5$SxebDgq2 z*1ic#990e`67cGKXJ^fFI7sm=+r0s{ZcrkviNuOYTd4a4T^-td(Hm%cQh4L{h8ie@ zShrSuff;Eleh3eWx4k_s*wF;v!B2zk04Q#(|FpJ{AjG_{z;s4>!Bflpt}2~sTeL{+ zORO%idYKCCVWD~bY}PstXqygd+VtXrrY>q4>Z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v{_-0xN7IPPWkOL@?58GO(Nthfe$-y?B14kfubLFmjVFF z`LZxSh39b>^WYdb55^~m3;l+MEpEc!7a?Td*ovMV?ddDnQ(#38ls_aR3;nRH!!K;N N6^*ZZ8ovtc{tL^_$*2GT literal 0 HcmV?d00001 diff --git a/obj/kernel/platform/drivers/ports.o b/obj/kernel/platform/drivers/ports.o new file mode 100644 index 0000000000000000000000000000000000000000..1b5320217a559a9d7af6fbc0aecf97c25a302be2 GIT binary patch literal 2680 zcmb7GO>7%Q6rQoYi7Pv9Vh2bl5C;kgqOp@wXlO}V5}7DadNZH`iq`fzHjV9Qcbzt< z5=a#yAr~SFLLwIs7b_q9N~fj2u_g*4c|AOaW<9^@T8gVeecbC^Y?b_ zS99l{lu`;KQiR1m6XLb*mgj_mQIQf!kzfDm>URG|E?QpCZExhZ*FWE0%k8~&;|t}8 z!m*K$!?(M3b1k>?W^QLAzx%6kABZdef?>DH8@XHU;5_0HoZp3KXG6u7e?#zJSb!yD zgzK;_pu4-Ds+Ok4&^agr&!QVblUvWRpP}tOs-aC^&XG;F*s=(Rx_e;gdIX(J_R>6w zb`R;+JM0;qJk}atilo6({Vld4LT`h{2hp{r`wE&0h##0Pev*#RCZ?0o5vb}=W#ll; z6lRcHDl+m=a4IX+io68BCBlhQ!}4_OvDkbnG=PK|d1lbqhPy@v`((1~?7%C7G9^U# zsEEa;W8s7lkrSPfR-e2-k&1K? zbx^;EX2F*MqSF3M^blBMXi$biJaFDy2>Rhrg`Q=0)`YNB=G!dm8%u6lQ`43eea4ba z>o~Npt@tOFeA=2Ghjq%5S3@XWx!iF5g~F=uEL7{ltAM4Ob+5WucS`AM-50LoHJ5zR zwiPS3D^$>>hFf9~i745=9WXbVzL-0oPtQ)AOixT?j%UWxV>Q27cc!WjPd*CWc8e9Q zFQ&)JW!G^$->#Rc^~F{iwIrs=RvI-YTWq*a)~nbhXRP4~&n;#zI&R%r$}TV2e!1b+ zvL&~=;<#Rx%keVB{~M=fWt@o@bF;Ij(xceLgL(@%W6_JY2a!TviN+(5HCzgB)Ceo{ ziA41E&`gh&{}Kbhjo;M0@xRdFHy@JmU+D0g&(!!$yqViz@I8u%-}j82c<{9%-><@! zzbiN#{zDx+*1_W)JkgHeev_!$+ks~9e#i!^ek8VmnD9o)E5scqb7b%DqHO2)-~JcTC$)Yd)`$uP6Nr8eb+NepT}~G`_3x zeeJ)l`KKChX#7^=_eA9RQS(1E@&;tMRcq~aV%-nW4jk90-eB-ED% zP;i};UxPgBui#ytfdoVSDn;+$+KrS`lwbQ1$r6p*h$MT_yh z1Rl)iBi|@&%tyP~M-4h-#?dI>A>RirRrU0-shR|uaV`#=HX~--8VuCUxSuf&zv68% zf}3D{XlB2Rp>Apgswm-p X`JEbJ9tz`v<9@)rA1Y6)GvodSxejOv literal 0 HcmV?d00001 diff --git a/obj/kernel/platform/interrupts/idt.o b/obj/kernel/platform/interrupts/idt.o new file mode 100644 index 0000000000000000000000000000000000000000..3237090596397b9a30c956ef82e2dc15c0aee6e2 GIT binary patch literal 3084 zcma)8U2IfE6rOu`XS?mTyW1|%R?u#hpZdct1%y(C77Jn(NHk)=gsivSyFYP%>buao0|H4b7#6+V$_q&eCM1w zbLO0L&&=*~yZ7F2S(Y$liHK-PLi`dBS2imc5z9nI960gg$=%(b|CBy?AYM8V{gz87 zcgIVYqnB*3aSC5XFGaN;tOR=sd-R4F#8(f00Y9J6<~(|H=K-t_^%zJMvQ1CxmRZcRkGJ1N*Ucl11lDQXX5PLh=jUZiLc6Y^6)x{fIt z%X|m0w_#eQT-lF<~gk>014Z&5LvMoF#JB9YjUh$OMxBO=N1 z;mAFSZNr_@nXv?lv_eGUOdab@# zx*uOcpMgG#qa5 znjAQW50cDTE%my=)vgjY-`9)MNe_{bxvM2`G#LDH{4>D4PL4_WnZ9K3Uh%cYRyJDyJWpq ztyhC^y$O5QD+HqAG>SEFPO<2T8OL{p=lZU9#4U~1M{^r<8?x)`!F40i()5C*Auh(N ze1rx}O}h}jH=BRb^%`z1KUZ^tQq!yFRVv>6T;S(nmYWs%O0(|fXPcgz_bX1(UElQo zQTOl8{_CtvgYMU#l=SmZ6~KEK%DCW)m`@+>OBQHyqueSgIn~L;CH=$B zXDzKxAy#VSLrHm~#+@4XYJ8Z8bPj6d^Gz9{sb3UkVj;*rBFeBr<4r_72DcJXu1!SP zJ*4pwjWZhgPH=r*<0~59)OcRwhZ;ZA_?5=18h_U)Q4;3WMTFmeBH~`9<=cpeFQ?_Z zwY*Qu*di?aXsCLbJdod7>VbD?<_ojeSdbOv~ymge-FY z(R$#_00S??is3xBmJ8fx0+A~^fg^G=zAtiA7TuZoa-rHNHL;|4XJ*E8kF>8kp3^A1 zOE%Q14cBbI8HT00pyb(Rz3$@qXgj3jIdvCd{$EnRv@m8JNvspUu_2UM5&ICINlYq9 zi1)F9ecg*e8~&28*Z6ORvicndzJt+D#^0S#(%#se1s|hAQ&yw;Zbk__i*eXE0dLq1 z;M?Q7j`*%Y$N13Ji}6i@H+#T}zaS*q6oyrOPXkSH1e!Gh(Aez<-+t~l=qdIh&t*EM zF8n5D4_Gk*f6tQ9WY!$W?f!m%ze(um57%PR-&5eZhk27Oz~7%Ct7fio9M@><&LN=p zltnlhyO(dUdk{r4Zy7C(-CLTcj`RfV9t~MFGhfmh80~qiMlrI`F^?36sSEw`S{eEn p{=SC5cZ&OI$9j@Cy#iLefbTm(Mic#z=)c`=7tXz)R>H~H{S6TAekA|^ literal 0 HcmV?d00001 diff --git a/obj/kernel/platform/interrupts/int.o b/obj/kernel/platform/interrupts/int.o new file mode 100644 index 0000000000000000000000000000000000000000..d09d14e2411dd2580acaa7067df44906ed456286 GIT binary patch literal 1536 zcmb7^OGs2v7{|{zBw3ns)4z0ktFL6nH1aO;0{I+I3;PBlXk#*O0odMSETGqq0KuF>!?Qi*Hk zlU#+gVZ?Af9CT(4hI!r$7GvQdSPQWZT#gaemtrBxAe5y&bS8Oc&&YIJ&tzQWr}Gc< zGx^!s-}CeHM?y;tKPmh5DsY4&)D*RddO@v7J*5^^52(e|B(-97hgyl6pjN8J1E)-l z5tplLfwM@B2F_x2IdGP!OMz3Nh687*JcHZOmSys!rno$=sZzFUs*;B^EtmT=t&rO_ zt(2{rR>?+9)v`|0YFVwRMpkHABcqyX<)^A7kAW{3eiMAf@Con@!*7Gf4ZjP%W%zyYJ;NV^9~u4({M_)D z;5UX(f!`bc7Ay^)0e?6ABlwTupTMR1BcS*34PI&Z4|uKNbMSh@h39rBPNdyjI+Ga4 zr2L+KH=F3o`Dxc39PmBDrj(ZzeV*IVo5~%_q+RCj{%p2C*WvktUF6NpJX<{5JSTZ> z;klLPO+0Vrc?-{5X|_0Pan|Cj#aWB97H2KaTAZ~wYjM`*tj$@Qvo>dK&f1){Icsy) W=B&-xBxjQr-pE2#0gLF*OxItr1wo|% literal 0 HcmV?d00001 diff --git a/obj/kernel/platform/interrupts/isr.o b/obj/kernel/platform/interrupts/isr.o new file mode 100644 index 0000000000000000000000000000000000000000..925c5263eca8acef91eb2536c3e5679116e3a19e GIT binary patch literal 7312 zcmbtYdyHIF89#SsXLh!;ce{^vyW7{^?Q;w5?98_GMUm~crBwT(+iE4?b~<}^XV}@9 z_1@Xi#v))L;U$89AQ%$CL{vl*5fU&8gqMYQlDi&77!>anQDiKySgjLhRs$^Kz7*^R~Ra00sJ*;XD zt6IXU*08EAteO#4%?zvB!>UtLB7NbHl26Vb%Pws>`S}-t^RCdbM>N zJJFcmjD=}(uivu#+DEbazPaW7-Fu7@M&wmA|M}C)Twix}uxuMY)(TbXwH_o10JlIF z;%dZ=i2D&o5GN6@LcAIAr-=6>K85%q;@=SeiI_zF^AJ}cp8Y?>-SENsHx~{S{6e|p z3>>ivPRXd^Ck@d&22aB$=tyFP6Z*rod20S-AHc>8=DhkT7v)Qe^kInBgOKiYS(1NDUUb<<;l{p52HibVgcC`x$>|Jug<3OgjdeFzF+p#=JF)npO>91 zR#a7nGw6P?o^Kz7*KJ2dx)lw2oZdr+}=$Q@P~hV_n` zre2LI6;oCnhEpY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#bfzkMfW^!FMEHhF`* z1#Iz)QzMop=6+3+SE9fe@RGrcSCj)uTi&QO_yisaS;Z%Ce`Xb*z}=ixe4;3e<9K*S zWECHt@7cvC%ES~S;P_>TVm#2sL!OT@7Uo$7j}tZLJ(S8Jy&SxqOY(ed+O;RY5WHP$ z^2@>7wI#n6yj@H35%6~H$nzt`7VgLGsCI3r&+KTPclwyi9DIB$j-GDk{klhg$=-2q zk4=x$zgmyvJz%KJL6m!6M6S-uGg&og|h;a3~v z?w0xJM=Uh+h%Jt;cyJ4G5fQ#85%EL%g0bVvi}pkaB} zGw^pB{%(WY4eIYk=pQir9)tWer=K4Zk;@B)f5Y%^8(yy??2a1#v_XEHb6qOTyjKxn zH-(7#o^JSNgEtynW^g4D^Kysbw;FuF;IjtbGB`wp{ilWxg64STMATZt*Bfj!s6Tu_ z>wN%BQ;tQu%joYjxSNQ&&+tzh95Q&Ah}6=Lh{yB4R&XW^lT}*#_qtY&6(xQ12)7$48TpIBIzp(jU(}@(qS> zGdzFy)Ne98fB)q77=Ewe4;cOzhJWAie>D7A!=E#}s7r3{ONBdtsf35!mP$l=>r#Qjbhx7<5!nckg z0F|W;XW<+u`8h`$-e){prWhXELYIfQKMYN<^cA3KZ|(MgAa4u(vCKeaA1tXZpJ&$q zt@TaAeen09b)Kc013Ej8UARcv;GB7I58FHzW%U6mZo`@RVAcSZyyZN*Q%ItQ9Za!y zUk0B&?ngN5`CH+*l-qH8K-)ebMH!U11~SF!^tqXl3Na0Kzq3lnEx8#q{VzaeIg4=@ z068vSGIrb@pxKA>&GK)Y3E#An4xT#J2Mt=gZ{SS*8f3OuyYE4e?JtPCkYn0n?S29Q zXncivXW=o4EplLxzIg)L^|Z08@ZNL$}|^v8LpudMAMUWITs VWVYB4=sVl)0LFdE8Ud}{e*ljAh{^x} literal 0 HcmV?d00001 diff --git a/obj/kernel/strings.o b/obj/kernel/strings.o new file mode 100644 index 0000000000000000000000000000000000000000..107b607753276b035cc96d50478c217b59fc605e GIT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2AB|jYkL+oJ0|G~8wA7{jEd6H2Q?O;UQ zE@gjP>F+CCR9Iz1-p5K`R=A?@7v=w5>Gu@=t&mqs;GO1uulJAfY-b%ftnfL7hg2M1 zHWFAU-h0mDKY;avN}o{rTS}*7WxnWIQ$V-uV_r+Hea5BawB=fqoT^kPS+-}A)ArPC zZnEHHOK^FzH8oYX=Ni3M*>ZBYehmpT1;^G2{JW@JHcxtbrc^B2_)HpdvSq7iW1Rn& zdJ)KHl-G`l|NmQ_2y9y9GsCC; zFdEYs2Kot*_n2=BH}22dE1;%5*vHSc0@U?RG|23}iMRv{igeuT&>Q>x1O0NJ+;EiY z{aTQ94n&feczc6Eiznf0tal&v24UlRY}fNBLgt)dG^Q&9KO>!>9~(noOawtoU0WeRFAHJH_l_Lx>r08{LS@wa9u2Io$`1GzJb<` irsu2YuFnbw4`N*gSWv`um^iO7ZVdf?=6QUke+;8w*oQ#qDgZvd4e|g0 literal 0 HcmV?d00001 diff --git a/old_src/old_bin/boot_memory.bin b/old_src/old_bin/boot_memory.bin new file mode 100644 index 0000000000000000000000000000000000000000..6c2eb3219136823d967a83d250fea5c2eb4ca64d GIT binary patch literal 512 ycmdnOx54nNzy=i{HaaV?K!pLwFg`1=TZN(VFhflj`&oh4{~{Ph!SD=$&{Y5;Oc0*{ literal 0 HcmV?d00001 diff --git a/old_src/old_bin/boot_simple.bin b/old_src/old_bin/boot_simple.bin new file mode 100644 index 0000000000000000000000000000000000000000..980ee558a5c4d1d8da7286686b6e92025d0869e8 GIT binary patch literal 512 RcmaF;k6{#y*boR^1pw580_gw% literal 0 HcmV?d00001 diff --git a/old_src/old_bin/boot_stack.bin b/old_src/old_bin/boot_stack.bin new file mode 100644 index 0000000000000000000000000000000000000000..0385d5be3a00775b3bf9df3d47ed9cba1f945227 GIT binary patch literal 512 wcmdnOx0j)z^G%jxmQ$AVf`9dA1r{(goE3=fxPeT7#a{no7zM*C1VUE<07Hfs9RL6T literal 0 HcmV?d00001 diff --git a/old_src/print.asm b/old_src/print.asm new file mode 100644 index 0000000..5fd8309 --- /dev/null +++ b/old_src/print.asm @@ -0,0 +1,33 @@ +print: + pusha + +; logic being implemented here: +; while ( string[i] != 0 ) { print string[i]; i++ } + +start: + mov al, [bx] + cmp al, 0 ; check if al (byte we are printing) is a 0 (null byte) + je done ; if so, jump to done + + ; print with BIOS help + mov ah, 0x0e + int 0x10 ; char already in al + + add bx, 1 ; increment pointer + jmp start ; repeat + +done: + popa + ret + +print_nl: + pusha + + mov ah, 0x0e + mov al, 0x0a ; newline char + int 0x10 + mov al, 0x0d ; carriage return + int 0x10 + + popa + ret \ No newline at end of file diff --git a/old_src/print_hex.asm b/old_src/print_hex.asm new file mode 100644 index 0000000..e6df82b --- /dev/null +++ b/old_src/print_hex.asm @@ -0,0 +1,38 @@ +; data in dx +print_hex: + pusha + + mov cx, 0 ; index var + +hex_loop: + cmp cx, 4 ; loop 4 times + je end + + ; 1) convert last char of 'dx' to ascii + mov ax, dx ; ax is working register + and ax, 0x000f ; 0x1234 -> 0x0004 + add al, 0x30 ; add 0x30 to N to convert it to ascii "n" + cmp al, 0x39 ; if > 9, add extra 8 to represent a-f + jle step2 + add al, 7 ; A is ascii 64 instead of 58, 65-58 = 7 + +step2: + ; 2) get correct pos of string to place char + ; bx <- base address + string length - index + mov bx, HEX_OUT + 5 + sub bx, cx ; cx: index + mov [bx], al ; copy ascii char on al to pos pointed by bx + ror dx, 4 ; 1234 - 4123 - 3412 - 2341 - 1234 + + add cx, 1 + jmp hex_loop + +end: + mov bx, HEX_OUT + call print + + popa + ret + +HEX_OUT: + db '0x0000', 0 ; reserve memory for string \ No newline at end of file diff --git a/os-image.bin b/os-image.bin new file mode 100644 index 0000000000000000000000000000000000000000..de78a72c2d7239f4a4746ffe17fee39fd01867bc GIT binary patch literal 4768 zcmcgweQaCR6~A_p#%qEMs_&^8JkY^ny7sq0*#vV4@37NU9rCeWl&v@%`uOlxRR)69)`&U^Q! zX+fH{KlYTXd(Q8id+s^+o_l>y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 0x30 ; add 0x30 to N to convert it to ascii "n" + cmp al, 0x39 ; if > 9, add extra 8 to represent a-f + jle step2 + add al, 7 ; A is ascii 64 instead of 58, 65-58 = 7 + +step2: + ; 2) get correct pos of string to place char + ; bx <- base address + string length - index + mov bx, HEX_OUT + 5 + sub bx, cx ; cx: index + mov [bx], al ; copy ascii char on al to pos pointed by bx + ror dx, 4 ; 1234 - 4123 - 3412 - 2341 - 1234 + + add cx, 1 + jmp hex_loop + +end: + mov bx, HEX_OUT + call print + + popa + ret + +HEX_OUT: + db '0x0000', 0 ; reserve memory for string \ No newline at end of file diff --git a/src/boot/output/vga-print.asm b/src/boot/output/vga-print.asm new file mode 100644 index 0000000..a9055e3 --- /dev/null +++ b/src/boot/output/vga-print.asm @@ -0,0 +1,26 @@ +[bits 32] + +; defining constants +VIDEO_MEMORY equ 0xb8000 +WHITE_ON_BLACK equ 0x0f ; color byte + +print_string_pm: + pusha + mov edx, VIDEO_MEMORY + +print_string_pm_loop: + mov al, [ebx] ; [ebx] is address of char + mov ah, WHITE_ON_BLACK + + cmp al, 0 ; is end of string? + je print_string_pm_done + + mov [edx], ax ; store char + attribute in video memory + add ebx, 1 ; next char + add edx, 2 ; next video memory position + + jmp print_string_pm_loop + +print_string_pm_done: + popa + ret \ No newline at end of file diff --git a/src/boot/protected/gdt.asm b/src/boot/protected/gdt.asm new file mode 100644 index 0000000..2618221 --- /dev/null +++ b/src/boot/protected/gdt.asm @@ -0,0 +1,31 @@ +gdt_start: ; use labels to compute sizes and jumps + ; gdt starts with 8 byte null + dd 0x0 + dd 0x0 + +; GDT for code segment, base = 0x00000000, length = 0xfffff +gdt_code: + dw 0xffff ; segment length + dw 0x0 ; segment base + db 0x0 ; segment base + db 10011010b ; flags + db 11001111b ; flags + segment length + db 0x0 ; segment base + +; GDT for data segment +gdt_data: + dw 0xffff + dw 0x0 + db 0x0 + db 10010010b + db 11001111b + db 0x0 + +gdt_end: + +gdt_descriptor: + dw gdt_end - gdt_start - 1 ; size, always 1 less than what it actually is + dd gdt_start ; address + +CODE_SEG equ gdt_code - gdt_start +DATA_SEG equ gdt_data - gdt_start \ No newline at end of file diff --git a/src/boot/protected/protected-switch.asm b/src/boot/protected/protected-switch.asm new file mode 100644 index 0000000..53708d7 --- /dev/null +++ b/src/boot/protected/protected-switch.asm @@ -0,0 +1,24 @@ +[bits 16] +enable_protected: + cli ; Disable interrupts + lgdt [gdt_descriptor] ; load the GDT + mov eax, cr0 + or eax, 0x1 ; set 32-bit mode bit + mov cr0, eax + jmp CODE_SEG:init_protected ; far jump into a different segment + +[bits 32] +init_protected: ; now in 32bit + mov ax, DATA_SEG ; update segment registers + mov ds, ax + mov ss, ax + mov es, ax + mov fs, ax + mov gs, ax + + ; wipe registers clean + + mov ebp, 0x90000 ; update stack to top of free space + mov esp, ebp + + call BEGIN_PROTECTED ; call known label with useful code \ No newline at end of file diff --git a/src/kernel/entry.asm b/src/kernel/entry.asm new file mode 100644 index 0000000..a8d38ec --- /dev/null +++ b/src/kernel/entry.asm @@ -0,0 +1,4 @@ +[bits 32] +[extern main] ; define callpoint, must have same name as kernel.c entrypoint +call main ; jump to fun, linker will figure out where it is +jmp $ \ No newline at end of file diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c new file mode 100644 index 0000000..a176882 --- /dev/null +++ b/src/kernel/kernel.c @@ -0,0 +1,65 @@ +#include "./platform/drivers/ports.h" +#include "print.h" +#include "./platform/types.h" +#include "./platform/interrupts/idt.h" +#include "./platform/interrupts/isr.h" + +void dummy_test_entrypoint() {} + +void kernel_welcome() { + print_str("Welcome to "); + print_set_color(PRINT_COLOR_CYAN, PRINT_COLOR_BLACK); + print_str("Shade"); + print_set_color(PRINT_COLOR_WHITE, PRINT_COLOR_BLACK); + print_str("!\n"); + + print_str("shadeOS kernel version "); + + print_set_color(PRINT_COLOR_YELLOW, PRINT_COLOR_BLACK); + print_str("0.2.2"); + + print_set_color(PRINT_COLOR_WHITE, PRINT_COLOR_BLACK); + print_newline(); + + print_str("Running on "); + + print_set_color(PRINT_COLOR_YELLOW, PRINT_COLOR_BLACK); + print_str("shade-development"); + + print_set_color(PRINT_COLOR_WHITE, PRINT_COLOR_BLACK); + + print_newline(); +} + +// kMain +void main() { + // Initialize screen buffer + struct Char* buffer = (struct Char*) 0xb8000; + + clear_all(); // Clear screen + set_cursor_pos(0, 0); // Set cursor position + print_set_color(PRINT_COLOR_WHITE, PRINT_COLOR_BLACK); // Set print color + + // welcome messages + kernel_msg_ok("Initialized display successfully\n"); + kernel_welcome(); + + print_str("Copyright (c) e3team 2022. All rights reserved.\n"); + print_str("This program is provided \"as-is\" and no express or implied warranty is provided.\n"); + print_str("The full license can be found at /sys/LICENCE on this system or ./LICENCE in the source tree.\n"); + + print_str("Initializing interrupts...\n"); + isr_setup(); + kernel_msg_ok("isr setup done\n"); + + // Test interrupts + __asm__ __volatile__("int $2"); + kernel_msg_ok("int 2 not failed"); + __asm__ __volatile__("int $3"); + __asm__ __volatile__("int $2"); + __asm__ __volatile__("int $3"); + __asm__ __volatile__("int $2"); + __asm__ __volatile__("int $3"); + + kernel_msg_ok("interrupt test completed\n"); +} \ No newline at end of file diff --git a/src/kernel/platform/drivers/ports.c b/src/kernel/platform/drivers/ports.c new file mode 100644 index 0000000..34a48db --- /dev/null +++ b/src/kernel/platform/drivers/ports.c @@ -0,0 +1,26 @@ +/* + * Read 1 byte from specified port + */ +unsigned char port_byte_in(unsigned short port) { + unsigned char result; + // source and dest are backwards. + // "=a (result)" set the C variable to the value of register e'a'x + // '"d" (port) map the C variable port into e'd'x register + __asm__("in %%dx, %%al" : "=a" (result) : "d" (port)); +} + +void port_byte_out(unsigned short port, unsigned char data) { + // both regs are C vars, nothing is returned, so no '=' in asm syntax + // comma because two vars in input area and none in return area + __asm__("out %%al, %%dx" : : "a" (data), "d" (port)); +} + +unsigned short port_word_in(unsigned short port) { + unsigned short result; + __asm__("in %%dx, %%ax" : "=a" (result) : "d" (port)); + return result; +} + +void port_word_out(unsigned short port, unsigned short data) { + __asm__("out %%ax, %%dx" : : "a" (data), "d" (port)); +} \ No newline at end of file diff --git a/src/kernel/platform/drivers/ports.h b/src/kernel/platform/drivers/ports.h new file mode 100644 index 0000000..d616f0e --- /dev/null +++ b/src/kernel/platform/drivers/ports.h @@ -0,0 +1,4 @@ +unsigned char port_byte_in(unsigned short port); +void port_byte_out(unsigned short port, unsigned char data); +unsigned short port_word_in(unsigned short port); +void port_word_out(unsigned short port, unsigned short data); \ No newline at end of file diff --git a/src/kernel/platform/interrupts/idt.c b/src/kernel/platform/interrupts/idt.c new file mode 100644 index 0000000..7c3f48d --- /dev/null +++ b/src/kernel/platform/interrupts/idt.c @@ -0,0 +1,20 @@ +#include "idt.h" +#include "../../util.h" + +idt_gate_t idt[IDT_ENTRIES]; +idt_pointer_t idt_ptr; + +void idt_set_gate(int n, u32 handler_addr) { + idt[n].low_offset = low16(handler_addr); + idt[n].sel = KERNEL_CS; + idt[n].reserved = 0; + idt[n].flags = 0x8E; + idt[n].high_offset = high16(handler_addr); +} + +void idt_set() { + idt_ptr.base = (u32) &idt; + idt_ptr.limit = IDT_ENTRIES * sizeof(idt_gate_t) - 1; + /* Don't make the mistake of loading &idt -- always load &idt_reg */ + __asm__ __volatile__("lidtl (%0)" : : "r" (&idt_ptr)); +} \ No newline at end of file diff --git a/src/kernel/platform/interrupts/idt.h b/src/kernel/platform/interrupts/idt.h new file mode 100644 index 0000000..93c723e --- /dev/null +++ b/src/kernel/platform/interrupts/idt.h @@ -0,0 +1,27 @@ +#ifndef IDT_H +#define IDT_H + +#include "../types.h" + +#define KERNEL_CS 0x08 +#define IDT_ENTRIES 256 + +// An entry in the IDT +typedef struct { + u16 low_offset; // Low 16 bits of handler address + u16 sel; // Kernel code segment selector + u8 reserved; // Always zero + u8 flags; // x xx x xxxx, Present, ring, type, 1110 = "32bit int gate" + u16 high_offset; // High 16 bits of handler address +} __attribute__((packed)) idt_gate_t; + +// The IDT itself +typedef struct { + u16 limit; + u32 base; +} __attribute__((packed)) idt_pointer_t; + +void idt_set_gate(int n, u32 handler_addr); +void idt_set(); + +#endif \ No newline at end of file diff --git a/src/kernel/platform/interrupts/int.asm b/src/kernel/platform/interrupts/int.asm new file mode 100644 index 0000000..9edc58e --- /dev/null +++ b/src/kernel/platform/interrupts/int.asm @@ -0,0 +1,286 @@ +; in isr.c +[extern isr_handler] + +isr_common_stub: + ; Save CPU state + pusha ; Pushes edi,esi,ebp,esp,ebx,edx,ecx,eax + mov ax, ds ; Lower 16-bits of eax = ds. + push eax ; save the data segment descriptor + mov ax, 0x10 ; kernel data segment descriptor + mov ds, ax + mov es, ax + mov fs, ax + mov gs, ax + + ; Call C handler + call isr_handler + + ; Restore CPU state + pop eax + mov ds, ax + mov es, ax + mov fs, ax + mov gs, ax + popa + add esp, 8 ; Cleans up the pushed error code and pushed ISR number + sti + iret ; pops 5 things at once: CS, EIP, EFLAGS, SS, and ESP + +; We don't get information about which interrupt was caller +; when the handler is run, so we will need to have a different handler +; for every interrupt. +; Furthermore, some interrupts push an error code onto the stack but others +; don't, so we will push a dummy error code for those which don't, so that +; we have a consistent stack for all of them. + +; First make the ISRs global +global isr00 +global isr01 +global isr02 +global isr03 +global isr04 +global isr05 +global isr06 +global isr07 +global isr08 +global isr09 +global isr10 +global isr11 +global isr12 +global isr13 +global isr14 +global isr15 +global isr16 +global isr17 +global isr18 +global isr19 +global isr20 +global isr21 +global isr22 +global isr23 +global isr24 +global isr25 +global isr26 +global isr27 +global isr28 +global isr29 +global isr30 +global isr31 + +; 0: Divide By Zero Exception +isr00: + cli + push byte 0 + push byte 0 + jmp isr_common_stub + +; 1: Debug Exception +isr01: + cli + push byte 0 + push byte 1 + jmp isr_common_stub + +; 2: Non Maskable Interrupt Exception +isr02: + cli + push byte 0 + push byte 2 + jmp isr_common_stub + +; 3: Int 3 Exception +isr03: + cli + push byte 0 + push byte 3 + jmp isr_common_stub + +; 4: INTO Exception +isr04: + cli + push byte 0 + push byte 4 + jmp isr_common_stub + +; 5: Out of Bounds Exception +isr05: + cli + push byte 0 + push byte 5 + jmp isr_common_stub + +; 6: Invalid Opcode Exception +isr06: + cli + push byte 0 + push byte 6 + jmp isr_common_stub + +; 7: Coprocessor Not Available Exception +isr07: + cli + push byte 0 + push byte 7 + jmp isr_common_stub + +; 8: Double Fault Exception (With Error Code!) +isr08: + cli + push byte 8 + jmp isr_common_stub + +; 9: Coprocessor Segment Overrun Exception +isr09: + cli + push byte 0 + push byte 9 + jmp isr_common_stub + +; 10: Bad TSS Exception (With Error Code!) +isr10: + cli + push byte 10 + jmp isr_common_stub + +; 11: Segment Not Present Exception (With Error Code!) +isr11: + cli + push byte 11 + jmp isr_common_stub + +; 12: Stack Fault Exception (With Error Code!) +isr12: + cli + push byte 12 + jmp isr_common_stub + +; 13: General Protection Fault Exception (With Error Code!) +isr13: + cli + push byte 13 + jmp isr_common_stub + +; 14: Page Fault Exception (With Error Code!) +isr14: + cli + push byte 14 + jmp isr_common_stub + +; 15: Reserved Exception +isr15: + cli + push byte 0 + push byte 15 + jmp isr_common_stub + +; 16: Floating Point Exception +isr16: + cli + push byte 0 + push byte 16 + jmp isr_common_stub + +; 17: Alignment Check Exception +isr17: + cli + push byte 0 + push byte 17 + jmp isr_common_stub + +; 18: Machine Check Exception +isr18: + cli + push byte 0 + push byte 18 + jmp isr_common_stub + +; 19: Reserved +isr19: + cli + push byte 0 + push byte 19 + jmp isr_common_stub + +; 20: Reserved +isr20: + cli + push byte 0 + push byte 20 + jmp isr_common_stub + +; 21: Reserved +isr21: + cli + push byte 0 + push byte 21 + jmp isr_common_stub + +; 22: Reserved +isr22: + cli + push byte 0 + push byte 22 + jmp isr_common_stub + +; 23: Reserved +isr23: + cli + push byte 0 + push byte 23 + jmp isr_common_stub + +; 24: Reserved +isr24: + cli + push byte 0 + push byte 24 + jmp isr_common_stub + +; 25: Reserved +isr25: + cli + push byte 0 + push byte 25 + jmp isr_common_stub + +; 26: Reserved +isr26: + cli + push byte 0 + push byte 26 + jmp isr_common_stub + +; 27: Reserved +isr27: + cli + push byte 0 + push byte 27 + jmp isr_common_stub + +; 28: Reserved +isr28: + cli + push byte 0 + push byte 28 + jmp isr_common_stub + +; 29: Reserved +isr29: + cli + push byte 0 + push byte 29 + jmp isr_common_stub + +; 30: Reserved +isr30: + cli + push byte 0 + push byte 30 + jmp isr_common_stub + +; 31: Reserved +isr31: + cli + push byte 0 + push byte 31 + jmp isr_common_stub diff --git a/src/kernel/platform/interrupts/isr.c b/src/kernel/platform/interrupts/isr.c new file mode 100644 index 0000000..89ec4ea --- /dev/null +++ b/src/kernel/platform/interrupts/isr.c @@ -0,0 +1,89 @@ +#include "isr.h" +#include "idt.h" +#include "../../print.h" +#include "../../util.h" + +void isr_setup() { + idt_set_gate(0, (u32)isr00); + idt_set_gate(1, (u32)isr01); + idt_set_gate(2, (u32)isr02); + idt_set_gate(3, (u32)isr03); + idt_set_gate(4, (u32)isr04); + idt_set_gate(5, (u32)isr05); + idt_set_gate(6, (u32)isr06); + idt_set_gate(7, (u32)isr07); + idt_set_gate(8, (u32)isr08); + idt_set_gate(9, (u32)isr09); + idt_set_gate(10, (u32)isr10); + idt_set_gate(11, (u32)isr11); + idt_set_gate(12, (u32)isr12); + idt_set_gate(13, (u32)isr13); + idt_set_gate(14, (u32)isr14); + idt_set_gate(15, (u32)isr15); + idt_set_gate(16, (u32)isr16); + idt_set_gate(17, (u32)isr17); + idt_set_gate(18, (u32)isr18); + idt_set_gate(19, (u32)isr19); + idt_set_gate(20, (u32)isr20); + idt_set_gate(21, (u32)isr21); + idt_set_gate(22, (u32)isr22); + idt_set_gate(23, (u32)isr23); + idt_set_gate(24, (u32)isr24); + idt_set_gate(25, (u32)isr25); + idt_set_gate(26, (u32)isr26); + idt_set_gate(27, (u32)isr27); + idt_set_gate(28, (u32)isr28); + idt_set_gate(29, (u32)isr29); + idt_set_gate(30, (u32)isr30); + idt_set_gate(31, (u32)isr31); + + idt_set(); +} + +char *exception_messages[] = { + "Division By Zero", + "Debug", + "Non Maskable Interrupt", + "Breakpoint", + "Into Detected Overflow", + "Out of Bounds", + "Invalid Opcode", + "No Coprocessor", + + "Double Fault", + "Coprocessor Segment Overrun", + "Bad TSS", + "Segment Not Present", + "Stack Fault", + "General Protection Fault", + "Page Fault", + "Unknown Interrupt", + + "Coprocessor Fault", + "Alignment Check", + "Machine Check", + "Reserved", + "Reserved", + "Reserved", + "Reserved", + "Reserved", + + "Reserved", + "Reserved", + "Reserved", + "Reserved", + "Reserved", + "Reserved", + "Reserved", + "Reserved" +}; + +void isr_handler(registers_t r) { + print_str("int: "); + char s[3]; + int_to_ascii(r.int_no, s); + print_str(s); + print_str("\n"); + print_str(exception_messages[r.int_no]); + print_str("\n"); +} \ No newline at end of file diff --git a/src/kernel/platform/interrupts/isr.h b/src/kernel/platform/interrupts/isr.h new file mode 100644 index 0000000..3d00a26 --- /dev/null +++ b/src/kernel/platform/interrupts/isr.h @@ -0,0 +1,48 @@ +#pragma once + +#include "../types.h" + +typedef struct { + u32 ds; // Data segment selector + u32 edi, esi, ebp, esp, ebx, edx, ecx, eax; // Pushed by pusha + u32 int_no, err_code; // Interrupt number and error code (if present) + u32 eip, cs, eflags, useresp, ss; // Pushed automatically by the CPU +} registers_t; + +// CPU exception interrupts +// ^ - pushes error code +extern void isr00(); // Division by Zero +extern void isr01(); // Debug Exception +extern void isr02(); // Non Maskable Interrupt +extern void isr03(); // Breakpoint +extern void isr04(); // Into detected overflow? +extern void isr05(); // Out of Bounds +extern void isr06(); // Invalid opcode +extern void isr07(); // No coprocessor +extern void isr08(); //^ Double fault +extern void isr09(); // Coprocessor segment overrun +extern void isr10(); //^ Bad TSS +extern void isr11(); //^ Segment not present +extern void isr12(); //^ Stack fault +extern void isr13(); //^ General Protection Fault +extern void isr14(); //^ Page Fault +extern void isr15(); // Unknown Interrupt +extern void isr16(); // Coprocessor Fault +extern void isr17(); // Alignment check exception +extern void isr18(); // Machine check exception +extern void isr19(); // Reserved +extern void isr20(); // Reserved +extern void isr21(); // Reserved +extern void isr22(); // Reserved +extern void isr23(); // Reserved +extern void isr24(); // Reserved +extern void isr25(); // Reserved +extern void isr26(); // Reserved +extern void isr27(); // Reserved +extern void isr28(); // Reserved +extern void isr29(); // Reserved +extern void isr30(); // Reserved +extern void isr31(); // Reserved + +void isr_setup(); +void isr_handler(registers_t r); \ No newline at end of file diff --git a/src/kernel/platform/types.h b/src/kernel/platform/types.h new file mode 100644 index 0000000..e18f414 --- /dev/null +++ b/src/kernel/platform/types.h @@ -0,0 +1,18 @@ +#ifndef TYPES_H +#define TYPES_H + +typedef unsigned int u32; +typedef int i32; +typedef unsigned short u16; +typedef short i16; +typedef unsigned char u8; +typedef char i8; + +#define high16(i32) (i32 & 0xffff) +#define low16(i32) ((i32>>16) & 0xffff) + +#define TRUE 1 +#define FALSE 0 +#define NULL 0 + +#endif \ No newline at end of file diff --git a/src/kernel/print.c b/src/kernel/print.c new file mode 100644 index 0000000..014de03 --- /dev/null +++ b/src/kernel/print.c @@ -0,0 +1,110 @@ +#include "print.h" +#include "./platform/drivers/ports.h" + +int row = 0; +int col = 0; +char color = PRINT_COLOR_WHITE | PRINT_COLOR_BLACK << 4; + +void clear_row(int row) { + struct Char* buffer = (struct Char*) 0xb8000; + + struct Char empty = (struct Char) { + character: ' ', + color: color, + }; + + for (int x = 0; x < NUM_COLS; x++) { + buffer[x + NUM_COLS * row] = empty; + } + set_cursor_pos(col, row); +} + +void clear_all() { + for (int i = 0; i < NUM_ROWS; i++) { + clear_row(i); + } + set_cursor_pos(col, row); +} + +void print_newline() { + struct Char* buffer = (struct Char*) 0xb8000; + + col = 0; + + if (row < NUM_ROWS - 1) { + row++; + return; + } + + for (int row = 1; row < NUM_ROWS; row++) { + for (int col = 0; col < NUM_COLS; col++) { + struct Char character = buffer[col + NUM_COLS * row]; + buffer[col + NUM_COLS * (row - 1)] = character; + } + } + + clear_row(NUM_COLS - 1); + set_cursor_pos(col, row); +} + +void print_char(char character) { + struct Char* buffer = (struct Char*) 0xb8000; + + if (character == '\n') { + print_newline(); + return; + } + + if (col > NUM_COLS) { + print_newline(); + } + + struct Char cr = (struct Char) { + character: character, + color: color, + }; + buffer[col + NUM_COLS * row] = cr; + + col++; + set_cursor_pos(col, row); +} + +void print_str(char* str) { + for (int i = 0; 1; i++) { + char character = (char) str[i]; + + if (character == '\0') { + return; + } + + print_char(character); + } +} + +void print_set_color(char foreground, char background) { + color = foreground + (background << 4); +} + +void set_cursor_pos(int col, int row) { + int offset = col + NUM_COLS * row; + port_byte_out(REG_SCREEN_CTRL, 14); + port_byte_out(REG_SCREEN_DATA, (unsigned char)(offset >> 8)); + port_byte_out(REG_SCREEN_CTRL, 15); + port_byte_out(REG_SCREEN_DATA, (unsigned char)(offset & 0xff)); +} + +void kernel_msg_ok(char* msg) { + char ok_p1[] = "[ "; + char ok_p2[] = "OK "; + char ok_p3[] = "] "; + + print_set_color(PRINT_COLOR_WHITE, PRINT_COLOR_BLACK); + print_str(ok_p1); + + print_set_color(PRINT_COLOR_GREEN, PRINT_COLOR_BLACK); + print_str(ok_p2); + + print_set_color(PRINT_COLOR_WHITE, PRINT_COLOR_BLACK); + print_str(ok_p3); + print_str(msg); +} \ No newline at end of file diff --git a/src/kernel/print.h b/src/kernel/print.h new file mode 100644 index 0000000..edd8a9e --- /dev/null +++ b/src/kernel/print.h @@ -0,0 +1,44 @@ +#ifndef PRINT_H +#define PRINT_H +#define REG_SCREEN_CTRL 0x3d4 +#define REG_SCREEN_DATA 0x3d5 + +enum { + PRINT_COLOR_BLACK = 0, + PRINT_COLOR_BLUE = 1, + PRINT_COLOR_GREEN = 2, + PRINT_COLOR_CYAN = 3, + PRINT_COLOR_RED = 4, + PRINT_COLOR_MAGENTA = 5, + PRINT_COLOR_BROWN = 6, + PRINT_COLOR_LIGHT_GRAY = 7, + PRINT_COLOR_DARK_GRAY = 8, + PRINT_COLOR_LIGHT_BLUE = 9, + PRINT_COLOR_LIGHT_GREEN = 10, + PRINT_COLOR_LIGHT_CYAN = 11, + PRINT_COLOR_LIGHT_RED = 12, + PRINT_COLOR_PINK = 13, + PRINT_COLOR_YELLOW = 14, + PRINT_COLOR_WHITE = 15, +}; + +const static int NUM_COLS = 80; +const static int NUM_ROWS = 25; + +struct Char { + char character; + char color; +}; + +void clear_row(int row); +void clear_all(); + +void print_newline(); +void print_char(char character); +void print_set_color(char foreground, char background); +void print_str(char* str); + +void set_cursor_pos(int col, int row); + +void kernel_msg_ok(char* msg); +#endif \ No newline at end of file diff --git a/src/kernel/strings.c b/src/kernel/strings.c new file mode 100644 index 0000000..79897f8 --- /dev/null +++ b/src/kernel/strings.c @@ -0,0 +1,48 @@ +#include "strings.h" +#include "./platform/types.h" + +void itoa(int n, char str[]) { + int i, sign; + if ((sign = n) < 0) n = -n; + i = 0; + do { + str[i++] = n % 10 + '0'; + } while ((n /= 10) > 0); + + if (sign < 0) str[i++] = '-'; + str[i] = '\0'; + + strrev(str); +} + +/* K&R */ +void strrev(char s[]) { + int c, i, j; + for (i = 0, j = strlen(s)-1; i < j; i++, j--) { + c = s[i]; + s[i] = s[j]; + s[j] = c; + } +} + +/* K&R */ +int strlen(char s[]) { + int i = 0; + while (s[i] != '\0') ++i; + return i; +} + +char* strcpy(char* strDest, const char* strSrc) { + if ( (strDest == NULL) || (strSrc == NULL) ) { + return NULL; + } + char* strDestCopy = strDest; + while ((*strDest++=*strSrc++)!='\0'); + return strDestCopy; +} + +char* strcnc(char* str1, char* str2) { + char* str_dest; + strcpy(str_dest, str1); + strcpy(str_dest, str2); +} \ No newline at end of file diff --git a/src/kernel/strings.h b/src/kernel/strings.h new file mode 100644 index 0000000..ee4402a --- /dev/null +++ b/src/kernel/strings.h @@ -0,0 +1,10 @@ +#ifndef STRINGS_H +#define STRINGS_H + +void itoa(int n, char str[]); +void strrev(char s[]); +int strlen(char s[]); +char* strcpy(char* strDest, const char* strSrc); +char* strcnc(char* str1, char* str2); + +#endif \ No newline at end of file diff --git a/src/kernel/util.c b/src/kernel/util.c new file mode 100644 index 0000000..e945d94 --- /dev/null +++ b/src/kernel/util.c @@ -0,0 +1,25 @@ +#include "util.h" + +void memcpy(char *source, char *dest, int nbytes) { + int i; + for (i = 0; i < nbytes; i++) { + *(dest + i) = *(source + i); + } +} + +void memset(char *dest, char val, int len) { + char *temp = (char *)dest; + for(; len !=0; len--) *temp++ = val; +} + +void int_to_ascii(int n, char str[]) { + int i, sign; + if ((sign = n) < 0) n = -n; + i = 0; + do { + str[i++] = n % 10 + '0'; + } while ((n /= 10) > 0); + + if (sign < 0) str[i++] = '-'; + str[i] = '\0'; +} \ No newline at end of file diff --git a/src/kernel/util.h b/src/kernel/util.h new file mode 100644 index 0000000..889ccb0 --- /dev/null +++ b/src/kernel/util.h @@ -0,0 +1,8 @@ +#ifndef UTIL_H +#define UTIL_H + +void memcpy(char *source, char *dest, int nbytes); +void memset(char *dest, char val, int len); +void int_to_ascii(int n, char str[]); + +#endif \ No newline at end of file