Merge into main the new state of the operating system/kernel #1
							
								
								
									
										4
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								Makefile
									
									
									
									
									
								
							@ -5,7 +5,7 @@ CC = ${HOME}/opt/cross/bin/i686-elf-gcc
 | 
			
		||||
CPP = ${HOME}/opt/cross/bin/i686-elf-g++ 
 | 
			
		||||
CFLAGS =  -ffreestanding -Og -ggdb  -Wall -Wextra
 | 
			
		||||
 | 
			
		||||
OFILES =$(BUILD_DIR)/boot.o $(BUILD_DIR)/kterm.o $(BUILD_DIR)/kernel.o $(BUILD_DIR)/memory.o  $(BUILD_DIR)/paging.o	$(BUILD_DIR)/VFS.o $(BUILD_DIR)/pit.o 	$(BUILD_DIR)/time.o	$(BUILD_DIR)/keyboard.o	 $(BUILD_DIR)/io.o 	$(BUILD_DIR)/processor.o $(BUILD_DIR)/gdtc.o $(BUILD_DIR)/idt.o $(BUILD_DIR)/pic.o $(BUILD_DIR)/sv-terminal.o $(BUILD_DIR)/string.o  $(BUILD_DIR)/prekernel.o $(BUILD_DIR)/cpu.o $(BUILD_DIR)/KHeap.o $(BUILD_DIR)/pci.o $(BUILD_DIR)/pcidevice.o $(BUILD_DIR)/atapiDevice.o $(BUILD_DIR)/ataDevice.o $(BUILD_DIR)/rsdp.o $(BUILD_DIR)/acpi.o
 | 
			
		||||
OFILES =$(BUILD_DIR)/boot.o $(BUILD_DIR)/kterm.o $(BUILD_DIR)/kernel.o $(BUILD_DIR)/memory.o  $(BUILD_DIR)/paging.o	$(BUILD_DIR)/VFS.o $(BUILD_DIR)/pit.o 	$(BUILD_DIR)/time.o	$(BUILD_DIR)/keyboard.o	 $(BUILD_DIR)/io.o 	$(BUILD_DIR)/processor.o $(BUILD_DIR)/gdtc.o $(BUILD_DIR)/idt.o $(BUILD_DIR)/pic.o $(BUILD_DIR)/sv-terminal.o $(BUILD_DIR)/string.o  $(BUILD_DIR)/prekernel.o $(BUILD_DIR)/KHeap.o $(BUILD_DIR)/pci.o $(BUILD_DIR)/pcidevice.o $(BUILD_DIR)/atapiDevice.o $(BUILD_DIR)/ataDevice.o $(BUILD_DIR)/rsdp.o $(BUILD_DIR)/acpi.o
 | 
			
		||||
 | 
			
		||||
SRC_DIR = source
 | 
			
		||||
BUILD_DIR = build
 | 
			
		||||
@ -133,8 +133,6 @@ $(BUILD_DIR)/KHeap.o:
 | 
			
		||||
$(BUILD_DIR)/prekernel.o:
 | 
			
		||||
	$(CPP) -c $(SRC_DIR)/kernel/prekernel/prekernel.cpp -o $(BUILD_DIR)/prekernel.o $(CFLAGS) -fno-exceptions -fno-rtti
 | 
			
		||||
 | 
			
		||||
$(BUILD_DIR)/cpu.o:
 | 
			
		||||
	$(CPP) -c $(SRC_DIR)/kernel/cpu.cpp -o $(BUILD_DIR)/cpu.o $(CFLAGS) -fno-exceptions -fno-rtti
 | 
			
		||||
 | 
			
		||||
$(BUILD_DIR)/processor.o:
 | 
			
		||||
	$(CPP) -c $(SRC_DIR)/kernel/i386/processor.cpp -o $(BUILD_DIR)/processor.o $(CFLAGS) -fno-exceptions -fno-rtti
 | 
			
		||||
 | 
			
		||||
@ -1,39 +0,0 @@
 | 
			
		||||
#include "cpu.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
uint32_t GetEFLAGS()
 | 
			
		||||
{
 | 
			
		||||
    uint32_t EFLAGS = 0;
 | 
			
		||||
    asm volatile ("pushfl;" "movl 4(%%esp), %%edx" : "=d"(EFLAGS));
 | 
			
		||||
    return EFLAGS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
uint32_t GetCR0()
 | 
			
		||||
{   
 | 
			
		||||
    uint32_t cr0_value;
 | 
			
		||||
    asm volatile ("movl %%cr0, %%edx" : "=d"(cr0_value));
 | 
			
		||||
    return cr0_value;
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
uint32_t GetCR2(){
 | 
			
		||||
    uint32_t cr2_value;
 | 
			
		||||
    __asm__ volatile("movl %%cr2, %%edx": "=d"(cr2_value));
 | 
			
		||||
    return cr2_value;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
uint32_t GetCR3(){
 | 
			
		||||
    uint32_t cr3_value;
 | 
			
		||||
    __asm__ volatile("movl %%cr3, %%edx": "=d"(cr3_value));
 | 
			
		||||
    return cr3_value;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
uint32_t GetCR4(){
 | 
			
		||||
    uint32_t cr4_value;
 | 
			
		||||
    __asm__ volatile("movl %%cr4, %%edx": "=d"(cr4_value));
 | 
			
		||||
    return cr4_value;
 | 
			
		||||
}
 | 
			
		||||
@ -1,16 +0,0 @@
 | 
			
		||||
#pragma once 
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
 | 
			
		||||
uint32_t GetEFLAGS();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
uint32_t GetCR0();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
uint32_t GetCR2();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
uint32_t GetCR3();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
uint32_t GetCR4();
 | 
			
		||||
@ -70,4 +70,58 @@ bool processor::hasPageSupport(){
 | 
			
		||||
 */
 | 
			
		||||
bool processor::gigabytePages() {
 | 
			
		||||
    return cap_page & (0x1 << 26);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void processor::enable_protectedMode()
 | 
			
		||||
{
 | 
			
		||||
    // Set the protected bit of control register 0
 | 
			
		||||
    // this will put the CPU into protected mode
 | 
			
		||||
    // NOTE: This should really be an assembly procedure
 | 
			
		||||
    // We cant directly write to control register 0
 | 
			
		||||
    // therefor we copy the value of control register 0 into eax
 | 
			
		||||
    // once we are done manipulating the value we write the value in
 | 
			
		||||
    // eax back to control register 0
 | 
			
		||||
 | 
			
		||||
    asm volatile("mov %cr0, %eax ");
 | 
			
		||||
    asm volatile("or $1, %eax");
 | 
			
		||||
    asm volatile("mov %eax, %cr0");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
uint32_t processor::GetEFLAGS()
 | 
			
		||||
{
 | 
			
		||||
    uint32_t EFLAGS = 0;
 | 
			
		||||
    asm volatile ("pushfl;" "movl 4(%%esp), %%edx" : "=d"(EFLAGS));
 | 
			
		||||
    return EFLAGS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
uint32_t processor::GetCR0()
 | 
			
		||||
{
 | 
			
		||||
    uint32_t cr0_value;
 | 
			
		||||
    asm volatile ("movl %%cr0, %%edx" : "=d"(cr0_value));
 | 
			
		||||
    return cr0_value;
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
uint32_t processor::GetCR2(){
 | 
			
		||||
    uint32_t cr2_value;
 | 
			
		||||
    __asm__ volatile("movl %%cr2, %%edx": "=d"(cr2_value));
 | 
			
		||||
    return cr2_value;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
uint32_t processor::GetCR3(){
 | 
			
		||||
    uint32_t cr3_value;
 | 
			
		||||
    __asm__ volatile("movl %%cr3, %%edx": "=d"(cr3_value));
 | 
			
		||||
    return cr3_value;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
uint32_t processor::GetCR4(){
 | 
			
		||||
    uint32_t cr4_value;
 | 
			
		||||
    __asm__ volatile("movl %%cr4, %%edx": "=d"(cr4_value));
 | 
			
		||||
    return cr4_value;
 | 
			
		||||
}
 | 
			
		||||
@ -19,6 +19,13 @@ public:
 | 
			
		||||
    static bool gigabytePages();
 | 
			
		||||
 | 
			
		||||
    static bool hasPAEExtension();
 | 
			
		||||
    static void enable_protectedMode();
 | 
			
		||||
 | 
			
		||||
    static uint32_t GetEFLAGS();
 | 
			
		||||
    static uint32_t GetCR0();
 | 
			
		||||
    static uint32_t GetCR2();
 | 
			
		||||
    static uint32_t GetCR3();
 | 
			
		||||
    static uint32_t GetCR4();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    static uint32_t cap_page;
 | 
			
		||||
 | 
			
		||||
@ -1,7 +1,7 @@
 | 
			
		||||
#include "idt.h"
 | 
			
		||||
#include "../drivers/pit/pit.h"
 | 
			
		||||
#include "../drivers/ps-2/keyboard.h"
 | 
			
		||||
#include "../cpu.h"
 | 
			
		||||
#include "../i386/processor.h"
 | 
			
		||||
#include "../memory/VirtualMemoryManager.h"
 | 
			
		||||
IDT_entry idt_table[256];
 | 
			
		||||
IDT_ptr idt_ptr;
 | 
			
		||||
@ -165,7 +165,7 @@ void irs_handler (registers* regs) {
 | 
			
		||||
            // Page Fault Exception #PF
 | 
			
		||||
            printf("#PF\n");
 | 
			
		||||
            #define ALIGN(addr, align) (((addr) & ~((align) - 1)) + (align))
 | 
			
		||||
            FaultingAddress = GetCR2();
 | 
			
		||||
            FaultingAddress = processor::GetCR2();
 | 
			
		||||
            
 | 
			
		||||
            printf("Accessing the linear address 0x%x resulted in a page fault!\n\n", FaultingAddress);
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
@ -23,22 +23,6 @@ extern "C"{
 | 
			
		||||
extern "C"  void LoadGlobalDescriptorTable();
 | 
			
		||||
extern "C" void jump_usermode();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void set_protected_bit()
 | 
			
		||||
{
 | 
			
		||||
    // Set the protected bit of control register 0
 | 
			
		||||
    // this will put the CPU into protected mode
 | 
			
		||||
    // NOTE: This should really be a assembly procedure
 | 
			
		||||
    // We cant directly write to control register 0
 | 
			
		||||
    // therefor we copy the value of control register 0 into eax
 | 
			
		||||
    // once we are done manipulating the value we write the value in
 | 
			
		||||
    // eax back to control register 0
 | 
			
		||||
 | 
			
		||||
    asm volatile("mov %cr0, %eax ");
 | 
			
		||||
    asm volatile("or $1, %eax");
 | 
			
		||||
    asm volatile("mov %eax, %cr0");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
extern "C" void kernel ()
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
@ -60,11 +44,10 @@ extern "C" void kernel ()
 | 
			
		||||
    // ACPI::initialize(); // FIXME: improper reading of bios memory
 | 
			
		||||
    PCI::Scan();
 | 
			
		||||
    processor::initialize();
 | 
			
		||||
    processor::enable_protectedMode();
 | 
			
		||||
 | 
			
		||||
    FileSystem::initialize();
 | 
			
		||||
 | 
			
		||||
    printf("Enable Protected mode and jump to kernel main\n");
 | 
			
		||||
 | 
			
		||||
    set_protected_bit();
 | 
			
		||||
 | 
			
		||||
#ifdef USERMODE_RELEASE
 | 
			
		||||
    // Lets jump into user mode
 | 
			
		||||
 | 
			
		||||
@ -1,6 +1,6 @@
 | 
			
		||||
#pragma once 
 | 
			
		||||
#include "../terminal/kterm.h"
 | 
			
		||||
#include "../cpu.h"
 | 
			
		||||
#include "../i386/processor.h"
 | 
			
		||||
#include "PhysicalMemoryManager.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user