From 35c71e4b24a206dba4b582376b19b716b7435dfe Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Tue, 15 Jan 2019 00:23:27 +0100 Subject: [PATCH] minor stuff with the A20 line '-' --- boot/elf/elf.c | 10 ++++++ boot/loader.asm | 70 ++++++++++++++++++++++---------------- build/bin/disk.img | Bin 18944000 -> 18944000 bytes build/bin/loader.bin | Bin 1171 -> 1221 bytes build/obj/boot/loader.bin | Bin 1171 -> 1221 bytes 5 files changed, 50 insertions(+), 30 deletions(-) create mode 100644 boot/elf/elf.c diff --git a/boot/elf/elf.c b/boot/elf/elf.c new file mode 100644 index 0000000..5ce83ac --- /dev/null +++ b/boot/elf/elf.c @@ -0,0 +1,10 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: ELF64 Parser and Loader // +//----------------------------------------------------------------------------// + + diff --git a/boot/loader.asm b/boot/loader.asm index 5ec173a..7d7b9df 100644 --- a/boot/loader.asm +++ b/boot/loader.asm @@ -33,13 +33,6 @@ %define volumeLabel bp+0x2b ; Volume Label %define fatTypeLabel bp+0x36 ; File system type -;; DISK BUFFER "SEGMENT" -%define BUFFER_SEG 0x07c0 ; (BUFFER_SEG << 4) + BUFFER_OFF = 0x07C00 -%define BUFFER_OFF 0x0000 - -;; SECOND STAGE LOADER "SEGMENT" -%define LOAD_SEG LONG_SELECTOR-GDT64 ; (LOAD_SEG << 4) + LOAD_OFF = 0x070000 -%define LOAD_OFF Kernel [BITS 16] @@ -56,13 +49,13 @@ jmp 0x0000:main ;; GDT WITH DOC GDT64: NULL_SELECTOR: ;; null selector within 64 bits - dw GDT_LENGTH ; limit of GDT - dw GDT64 ; linear address of GDT - dd 0x0 ; + dw GDT_LENGTH ; limit of GDT + dw GDT64 ; linear address of GDT + dd 0x0 ; CODE_SELECTOR: ;; 32-bit code selector (ring 0) - dw 0x0FFFF ; Segment Limit - db 0x0, 0x0, 0x0 ; Base Address + dw 0x0000FFFF ; Segment Limit + db 0x0, 0x0, 0x0 ; Base Address db 10011010b ; |7|6|5|4|3|2|1|0| ; | | | | | | | `----- 1 when segment used. ; | | | | | | `------ 1 when writable. @@ -72,7 +65,7 @@ GDT64: ; | | `---------- DPL !!! 0 for ring 0 ; | `----------- DPL (2/2) ; `------------ 1 if in physical memory, 0 if page fault - db 11001111b ; |7|6|5|4|3|2|1|0| + db 11001111b ; |7|6|5|4|3|2|1|0| ; | | | | | | | `----- Limit 16 ; | | | | | | `------ Limit 17 ; | | | | | `------- Limit 18 @@ -81,11 +74,11 @@ GDT64: ; | | `---------- 0 always ; | `----------- size of data. 1 for 32bits ; `------------ 0 if limit is in Bytes, 1 if it's in pages (4ko) - db 0x0 ; Base Address + db 0x0 ; Base Address DATA_SELECTOR: ;; flat data selector (ring 0) - dw 0x0FFFF ; Segment Limit - db 0x0, 0x0, 0x0 ; Base Address + dw 0x0000FFFF ; Segment Limit + db 0x0, 0x0, 0x0 ; Base Address db 10010010b ; |7|6|5|4|3|2|1|0| ; | | | | | | | `----- 1 when segment used. ; | | | | | | `------ 1 when writable. @@ -95,7 +88,7 @@ GDT64: ; | | `---------- DPL !!! 0 for ring 0 ; | `----------- DPL (2/2) ; `------------ 1 if in physical memory, 0 if page fault - db 10001111b ; |7|6|5|4|3|2|1|0| + db 10001111b ; |7|6|5|4|3|2|1|0| ; | | | | | | | `----- Limit 16 ; | | | | | | `------ Limit 17 ; | | | | | `------- Limit 18 @@ -104,11 +97,11 @@ GDT64: ; | | `---------- 0 always ; | `----------- size of data. 1 for 32bits ; `------------ 0 if limit is in Bytes, 1 if it's in pages (4ko) - db 0x0 ; Base Address + db 0x0 ; Base Address LONG_SELECTOR: ;; 64-bit code selector (ring 0) - dw 0x0FFFF ; Segment Limit - db 0x0, 0x0, 0x0 ; Base Address + dw 0x0000FFFF ; Segment Limit + db 0x0, 0x0, 0x0 ; Base Address db 10011010b ; |7|6|5|4|3|2|1|0| ; | | | | | | | `----- 1 when segment used. ; | | | | | | `------ 1 when writable. @@ -118,7 +111,7 @@ GDT64: ; | | `---------- DPL !!! 0 for ring 0 ; | `----------- DPL (2/2) ; `------------ 1 if in physical memory, 0 if page fault - db 10101111b ; |7|6|5|4|3|2|1|0| + db 10101111b ; |7|6|5|4|3|2|1|0| ; | | | | | | | `----- Limit 16 ; | | | | | | `------ Limit 17 ; | | | | | `------- Limit 18 @@ -127,7 +120,7 @@ GDT64: ; | | `---------- 0 always ; | `----------- size of data. 1 for 32bits ; `------------ 0 if limit is in Bytes, 1 if it's in pages (4ko) - db 0x0 ; Base Address + db 0x0 ; Base Address GDT_LENGTH: %include "boot/loader16.inc" @@ -195,6 +188,21 @@ main32: pop dword [VGA_HEIGHT32] pop dword [VIDEO_MODE32] + ;; VERIFY A20 + pushad + mov edi,0x112345 ;odd megabyte address. + mov esi,0x012345 ;even megabyte address. + mov [esi],esi ;making sure that both addresses contain diffrent values. + mov [edi],edi ;(if A20 line is cleared the two pointers would point to the address 0x012345 that would contain 0x112345 (edi)) + cmpsd ;compare addresses to see if the're equivalent. + popad + jne .A20_on ;if not equivalent , A20 line is set. + mov WORD [A20_OK], 0 + jmp .A20_end +.A20_on: + mov BYTE [A20_OK], 1 +.A20_end: + ;; INITIALIZE PROTECTED MODE SEGMENT REGISTERS mov ax, DATA_SELECTOR-GDT64 mov ds, ax @@ -260,6 +268,7 @@ KernSearch db 0x09, " Loading the Kernel in RAM...", 0 txt db 0x09, " Switching to Long Mode... ", 0 Reinit db "Booting OS/K !", 0x0D, 0x0A, 0x0D, 0x0A, 0 Pass db " OK", 0x0A, 0x0D, 0 +Fail db " FAIL!", 0x0A, 0x0D, 0 msg db "The system is now in x64 mode. Is this not beautiful ?", 0x0A, 0x0D, 0 NoLongMode db 0x0A, 0x0D, "ERROR : Your computer is not designed for x64 OS", 0 @@ -278,6 +287,7 @@ NextTRAM dq 0x0B8000 ; Last position of cursor VIDEO_MODE64 dq 0 VGA_HEIGHT64 dq 0 VGA_X dq 0 +A20_OK db 0 main64: pop qword [VGA_HEIGHT64] @@ -304,18 +314,17 @@ main64: mov esi, EnA20 call write + cmp BYTE [A20_OK], 1 + je .A20Success + mov bl, 0x0C + mov esi, Fail + call write + jmp Die +.A20Success: mov bl, 0x0A mov esi, Pass call write - mov bl, 0x0F - mov esi, KernSearch - call write - - mov bl, 0x0A - mov esi, Pass - call write - mov bl, 0x0F mov esi, txt call write @@ -328,6 +337,7 @@ main64: mov esi, msg call write + jmp Die ; times 1024 nop diff --git a/build/bin/disk.img b/build/bin/disk.img index 10b049d2fd39dbb9423802f166b70d3f1f7e671e..b2b0af2bb481b656002f06cf81335c46f3e9258e 100644 GIT binary patch delta 5122 zcmeI#c~sO@6u|NKh8bo+aDc%?a)A)dk}(lYaUo5DR1i|h%phCTv{F$EwSv?#)54(m zRZ5GM(qd^-(K=)s*~Mi-W`hW zS{zh_^)WWrt+uJ7OT$bBCAOGD{R(H?8dI;#UYSa*rVUdso0Y1)L?x(nm8d2tySinR z$|=pR7;JA|CoSt-X)nqk8IaP)l#$1|8QngMsR^_WnYBss3GdA0Fbi0gUX)#K*yrfm7@SYb1 z{_Z_n{D16^^TB%#(}^Me+%@IMh<)7TaILq^v6e;Ygzy0gC-qL~oisMFPjcV>$$b)o z`9m*Q%VuilkyA-Bwb5GAVACHMK^{|@WvgR#jiWTTA=hwuOqp>tj>*1$TOIY$;Wp(? zc6e^~?cH79;8P97mRg5W#g?xe#;j?2aa0Y@rYT?Ft+e&lNTs4wdbK&e&UoHyI!@P> z*6fTPQOBGqeUUldC!Ot|I!mTyae9x&=^h`-MSTvV zc#GZ;7<1at(?`Wt4oxzJ=t8+lu{r*GnrBr*kn*fL;PbiKxW9-{%JZ1??d}5US4cnD zy-WK3HFo!M>91h?%$#v!$DEO!Rh1eSuH30{T1{EnZ_3h?wd2p4aQ4J=a`WbfyF%Q1 zWcehPdspmlzLrgSvSg&Na>Z`bjDXgRHf7XXMT-7GS|>^pmq}VfoAzj=jLes`PHRo; zkzZ7AC8_!w-`3W&9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hjzr{Z6#{v8fFW?|v#7p=+UdA8r3jT;c;mVM^f?Gm{giHw@30V@n z60#+)gGKDGW| D>UsL} diff --git a/build/bin/loader.bin b/build/bin/loader.bin index 011e0e70288552f87e806199803801943cf0647e..02ebbd014ecf745f40d4f102cbf108e83a42c596 100644 GIT binary patch delta 449 zcmbQtd6bj0=S1I)z5^X%zbA6Kv;Gra#3nK^G(ojo=*8RraWCflFY*oBCocTr!T-3h zeH(>d-1r~&WD*b4vq>P)iMQ0f*hJF)oBb1hB_+tgurFTt#gzZQzP$SIpW#D4E0+iZ zLq97AkWAR`sw~K`&sCX`q0_9>etBXkciM4Q9iR*Y!)x|qU>4(KHO3}MHlSD*!++C% z!VCBsI@&E3G$GQO*FiR^h)i~8+Q_Eh=IH68 zxcMs+Cu2QBKg1j$B?45xhv5S!!;9H}|Nr02y^jUx&KH|OZ2o<7g@EkkAT}2;aDZ&E z8h&7~0onaP@dg`Jke?Y#1UK{SlLe`$1d6_F{)5nx0Ws=1NJ|XFC@HX60U!?VJ~fao K7mzMLpe_J^N2oRc delta 401 zcmX@gIhm8Q=S1I)z5^X%XD4#HvtAHhbVGPzXo6~x(2KYK<6g}9U*sFM?~~Ar2mj;3 z_Voz8xbZ*k$s``8XOlpp6K|=j-VjdvZ+1cWm6RX{!#+dd7gPTK`ts_-e})hJtapSN z82VXn0m;eUj7^d^fQ&4L|E3p!^s9eBLW05LIE(5%;mOY!6;tm41;WDD*f5kR*l?A| z+whiHuIjk4%A*;if`Nev#P|kcyuKYDci5wwMfDw!=fMb(hS7}28IQl-6#$Y3DfZBW zNNZjP+4N0#at_nR&1%eSjP?Bx{Xps&P~9Ge51b4ymj33;K`$7y1FZP1i{QD|E z?2RBc7tp^zHdqZmFeHHNnMmTj5cP{e;*Ch+r4aE$An{CuxY&zW5Qlf)50FG4ko~gZ H&;S1bb#k&3 diff --git a/build/obj/boot/loader.bin b/build/obj/boot/loader.bin index 011e0e70288552f87e806199803801943cf0647e..02ebbd014ecf745f40d4f102cbf108e83a42c596 100644 GIT binary patch delta 449 zcmbQtd6bj0=S1I)z5^X%zbA6Kv;Gra#3nK^G(ojo=*8RraWCflFY*oBCocTr!T-3h zeH(>d-1r~&WD*b4vq>P)iMQ0f*hJF)oBb1hB_+tgurFTt#gzZQzP$SIpW#D4E0+iZ zLq97AkWAR`sw~K`&sCX`q0_9>etBXkciM4Q9iR*Y!)x|qU>4(KHO3}MHlSD*!++C% z!VCBsI@&E3G$GQO*FiR^h)i~8+Q_Eh=IH68 zxcMs+Cu2QBKg1j$B?45xhv5S!!;9H}|Nr02y^jUx&KH|OZ2o<7g@EkkAT}2;aDZ&E z8h&7~0onaP@dg`Jke?Y#1UK{SlLe`$1d6_F{)5nx0Ws=1NJ|XFC@HX60U!?VJ~fao K7mzMLpe_J^N2oRc delta 401 zcmX@gIhm8Q=S1I)z5^X%XD4#HvtAHhbVGPzXo6~x(2KYK<6g}9U*sFM?~~Ar2mj;3 z_Voz8xbZ*k$s``8XOlpp6K|=j-VjdvZ+1cWm6RX{!#+dd7gPTK`ts_-e})hJtapSN z82VXn0m;eUj7^d^fQ&4L|E3p!^s9eBLW05LIE(5%;mOY!6;tm41;WDD*f5kR*l?A| z+whiHuIjk4%A*;if`Nev#P|kcyuKYDci5wwMfDw!=fMb(hS7}28IQl-6#$Y3DfZBW zNNZjP+4N0#at_nR&1%eSjP?Bx{Xps&P~9Ge51b4ymj33;K`$7y1FZP1i{QD|E z?2RBc7tp^zHdqZmFeHHNnMmTj5cP{e;*Ch+r4aE$An{CuxY&zW5Qlf)50FG4ko~gZ H&;S1bb#k&3