minor stuff with the A20 line '-'

This commit is contained in:
Adrien Bourmault 2019-01-15 00:23:27 +01:00
parent d3ba9640fc
commit 35c71e4b24
5 changed files with 50 additions and 30 deletions

10
boot/elf/elf.c Normal file
View File

@ -0,0 +1,10 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
// Authors: spectral` //
// NeoX //
// //
// Desc: ELF64 Parser and Loader //
//----------------------------------------------------------------------------//

View File

@ -33,13 +33,6 @@
%define volumeLabel bp+0x2b ; Volume Label %define volumeLabel bp+0x2b ; Volume Label
%define fatTypeLabel bp+0x36 ; File system type %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] [BITS 16]
@ -56,13 +49,13 @@ jmp 0x0000:main
;; GDT WITH DOC ;; GDT WITH DOC
GDT64: GDT64:
NULL_SELECTOR: ;; null selector within 64 bits NULL_SELECTOR: ;; null selector within 64 bits
dw GDT_LENGTH ; limit of GDT dw GDT_LENGTH ; limit of GDT
dw GDT64 ; linear address of GDT dw GDT64 ; linear address of GDT
dd 0x0 ; dd 0x0 ;
CODE_SELECTOR: ;; 32-bit code selector (ring 0) CODE_SELECTOR: ;; 32-bit code selector (ring 0)
dw 0x0FFFF ; Segment Limit dw 0x0000FFFF ; Segment Limit
db 0x0, 0x0, 0x0 ; Base Address db 0x0, 0x0, 0x0 ; Base Address
db 10011010b ; |7|6|5|4|3|2|1|0| db 10011010b ; |7|6|5|4|3|2|1|0|
; | | | | | | | `----- 1 when segment used. ; | | | | | | | `----- 1 when segment used.
; | | | | | | `------ 1 when writable. ; | | | | | | `------ 1 when writable.
@ -72,7 +65,7 @@ GDT64:
; | | `---------- DPL !!! 0 for ring 0 ; | | `---------- DPL !!! 0 for ring 0
; | `----------- DPL (2/2) ; | `----------- DPL (2/2)
; `------------ 1 if in physical memory, 0 if page fault ; `------------ 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 16
; | | | | | | `------ Limit 17 ; | | | | | | `------ Limit 17
; | | | | | `------- Limit 18 ; | | | | | `------- Limit 18
@ -81,11 +74,11 @@ GDT64:
; | | `---------- 0 always ; | | `---------- 0 always
; | `----------- size of data. 1 for 32bits ; | `----------- size of data. 1 for 32bits
; `------------ 0 if limit is in Bytes, 1 if it's in pages (4ko) ; `------------ 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) DATA_SELECTOR: ;; flat data selector (ring 0)
dw 0x0FFFF ; Segment Limit dw 0x0000FFFF ; Segment Limit
db 0x0, 0x0, 0x0 ; Base Address db 0x0, 0x0, 0x0 ; Base Address
db 10010010b ; |7|6|5|4|3|2|1|0| db 10010010b ; |7|6|5|4|3|2|1|0|
; | | | | | | | `----- 1 when segment used. ; | | | | | | | `----- 1 when segment used.
; | | | | | | `------ 1 when writable. ; | | | | | | `------ 1 when writable.
@ -95,7 +88,7 @@ GDT64:
; | | `---------- DPL !!! 0 for ring 0 ; | | `---------- DPL !!! 0 for ring 0
; | `----------- DPL (2/2) ; | `----------- DPL (2/2)
; `------------ 1 if in physical memory, 0 if page fault ; `------------ 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 16
; | | | | | | `------ Limit 17 ; | | | | | | `------ Limit 17
; | | | | | `------- Limit 18 ; | | | | | `------- Limit 18
@ -104,11 +97,11 @@ GDT64:
; | | `---------- 0 always ; | | `---------- 0 always
; | `----------- size of data. 1 for 32bits ; | `----------- size of data. 1 for 32bits
; `------------ 0 if limit is in Bytes, 1 if it's in pages (4ko) ; `------------ 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) LONG_SELECTOR: ;; 64-bit code selector (ring 0)
dw 0x0FFFF ; Segment Limit dw 0x0000FFFF ; Segment Limit
db 0x0, 0x0, 0x0 ; Base Address db 0x0, 0x0, 0x0 ; Base Address
db 10011010b ; |7|6|5|4|3|2|1|0| db 10011010b ; |7|6|5|4|3|2|1|0|
; | | | | | | | `----- 1 when segment used. ; | | | | | | | `----- 1 when segment used.
; | | | | | | `------ 1 when writable. ; | | | | | | `------ 1 when writable.
@ -118,7 +111,7 @@ GDT64:
; | | `---------- DPL !!! 0 for ring 0 ; | | `---------- DPL !!! 0 for ring 0
; | `----------- DPL (2/2) ; | `----------- DPL (2/2)
; `------------ 1 if in physical memory, 0 if page fault ; `------------ 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 16
; | | | | | | `------ Limit 17 ; | | | | | | `------ Limit 17
; | | | | | `------- Limit 18 ; | | | | | `------- Limit 18
@ -127,7 +120,7 @@ GDT64:
; | | `---------- 0 always ; | | `---------- 0 always
; | `----------- size of data. 1 for 32bits ; | `----------- size of data. 1 for 32bits
; `------------ 0 if limit is in Bytes, 1 if it's in pages (4ko) ; `------------ 0 if limit is in Bytes, 1 if it's in pages (4ko)
db 0x0 ; Base Address db 0x0 ; Base Address
GDT_LENGTH: GDT_LENGTH:
%include "boot/loader16.inc" %include "boot/loader16.inc"
@ -195,6 +188,21 @@ main32:
pop dword [VGA_HEIGHT32] pop dword [VGA_HEIGHT32]
pop dword [VIDEO_MODE32] 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 ;; INITIALIZE PROTECTED MODE SEGMENT REGISTERS
mov ax, DATA_SELECTOR-GDT64 mov ax, DATA_SELECTOR-GDT64
mov ds, ax mov ds, ax
@ -260,6 +268,7 @@ KernSearch db 0x09, " Loading the Kernel in RAM...", 0
txt db 0x09, " Switching to Long Mode... ", 0 txt db 0x09, " Switching to Long Mode... ", 0
Reinit db "Booting OS/K !", 0x0D, 0x0A, 0x0D, 0x0A, 0 Reinit db "Booting OS/K !", 0x0D, 0x0A, 0x0D, 0x0A, 0
Pass db " OK", 0x0A, 0x0D, 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 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 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 VIDEO_MODE64 dq 0
VGA_HEIGHT64 dq 0 VGA_HEIGHT64 dq 0
VGA_X dq 0 VGA_X dq 0
A20_OK db 0
main64: main64:
pop qword [VGA_HEIGHT64] pop qword [VGA_HEIGHT64]
@ -304,18 +314,17 @@ main64:
mov esi, EnA20 mov esi, EnA20
call write call write
cmp BYTE [A20_OK], 1
je .A20Success
mov bl, 0x0C
mov esi, Fail
call write
jmp Die
.A20Success:
mov bl, 0x0A mov bl, 0x0A
mov esi, Pass mov esi, Pass
call write call write
mov bl, 0x0F
mov esi, KernSearch
call write
mov bl, 0x0A
mov esi, Pass
call write
mov bl, 0x0F mov bl, 0x0F
mov esi, txt mov esi, txt
call write call write
@ -328,6 +337,7 @@ main64:
mov esi, msg mov esi, msg
call write call write
jmp Die jmp Die
; times 1024 nop ; times 1024 nop

Binary file not shown.

Binary file not shown.

Binary file not shown.