Compare commits
8 Commits
e6901f0526
...
dev
Author | SHA1 | Date | |
---|---|---|---|
2522492835 | |||
e82392e9d9 | |||
64c87a2a58 | |||
04470edcc6 | |||
2970806705 | |||
e8df6ec628 | |||
5781f730d9 | |||
2d0bb16fad |
7
.gdbinit
Normal file
7
.gdbinit
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
target remote localhost:1234
|
||||||
|
|
||||||
|
file root/boot/myos.bin
|
||||||
|
symbol-file kernel.sym
|
||||||
|
|
||||||
|
break prekernel/prekernel.cpp:18
|
||||||
|
continue
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -11,3 +11,5 @@ root/
|
|||||||
*.a
|
*.a
|
||||||
|
|
||||||
|
|
||||||
|
/CoreLib/warnings.log
|
||||||
|
/kernel/warnings.log
|
||||||
|
@ -15,8 +15,6 @@ $(OUTPUTFILE): $(OFILES)
|
|||||||
pwd
|
pwd
|
||||||
ar -rc $(OUTPUTFILE) $(OFILES)
|
ar -rc $(OUTPUTFILE) $(OFILES)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$(OBJ_FOLDER)/ctype.o: ctype.cpp
|
$(OBJ_FOLDER)/ctype.o: ctype.cpp
|
||||||
$(CPP) -c ctype.cpp -o $(OBJ_FOLDER)/ctype.o $(CFLAGS)
|
$(CPP) -c ctype.cpp -o $(OBJ_FOLDER)/ctype.o $(CFLAGS)
|
||||||
|
|
||||||
|
@ -16,16 +16,14 @@ void* memset (void* ptr, int value, size_t num)
|
|||||||
|
|
||||||
int memcmp( const void* ptr1, const void* ptr2, size_t num)
|
int memcmp( const void* ptr1, const void* ptr2, size_t num)
|
||||||
{
|
{
|
||||||
const unsigned char * cs = (const unsigned char*) ptr1;
|
auto* cs = (const unsigned char*) ptr1;
|
||||||
const unsigned char * ct = (const unsigned char*) ptr2;
|
auto* ct = (const unsigned char*) ptr2;
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0 ; i < num ; i++, cs++, ct++ ){
|
for (int i = 0 ; i < num ; i++, cs++, ct++ ){
|
||||||
if( *cs < *ct){
|
if( *cs != *ct)
|
||||||
return -1;
|
return *cs - *ct;
|
||||||
} else if( *cs > *ct){
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -108,7 +108,7 @@ int isprint (int ch){
|
|||||||
return 1;
|
return 1;
|
||||||
if(isspace(ch))
|
if(isspace(ch))
|
||||||
return 1;
|
return 1;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ OFILES = $(OBJ_DIR)/boot.o \
|
|||||||
OBJ_LINK_LIST = $(CRTI_OBJ) $(CRTBEGIN_OBJ) $(OFILES) $(CRTEND_OBJ) $(CRTN_OBJ)
|
OBJ_LINK_LIST = $(CRTI_OBJ) $(CRTBEGIN_OBJ) $(OFILES) $(CRTEND_OBJ) $(CRTN_OBJ)
|
||||||
INTERNAL_OBJS = $(CRTI_OBJ) $(OFILES) $(CRTN_OBJ)
|
INTERNAL_OBJS = $(CRTI_OBJ) $(OFILES) $(CRTN_OBJ)
|
||||||
|
|
||||||
all: build
|
all: clean build
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm $(OBJ_DIR)/* -r
|
rm $(OBJ_DIR)/* -r
|
||||||
@ -49,7 +49,7 @@ build: $(OBJ_LINK_LIST)
|
|||||||
$(CPP) -T linker.ld -o $(BUILD_DIR)/myos.bin -ffreestanding -ggdb -Og -nostdlib $(OBJ_LINK_LIST) -lgcc -L ../build/CoreLib -lCoreLib
|
$(CPP) -T linker.ld -o $(BUILD_DIR)/myos.bin -ffreestanding -ggdb -Og -nostdlib $(OBJ_LINK_LIST) -lgcc -L ../build/CoreLib -lCoreLib
|
||||||
|
|
||||||
# C++ definition -> Object files
|
# C++ definition -> Object files
|
||||||
$(OBJ_DIR)/kernel.o:
|
$(OBJ_DIR)/kernel.o: kernel.cpp
|
||||||
$(CPP) -c kernel.cpp -o $(OBJ_DIR)/kernel.o $(CFLAGS) -fno-exceptions -fno-rtti
|
$(CPP) -c kernel.cpp -o $(OBJ_DIR)/kernel.o $(CFLAGS) -fno-exceptions -fno-rtti
|
||||||
|
|
||||||
$(OBJ_DIR)/kterm.o:
|
$(OBJ_DIR)/kterm.o:
|
||||||
|
@ -1,26 +1,67 @@
|
|||||||
#include "acpi.h"
|
#include "acpi.h"
|
||||||
|
#include "../../CoreLib/Memory.h"
|
||||||
|
#include "../memory/VirtualMemoryManager.h"
|
||||||
|
|
||||||
RSDPDescriptor* ACPI::rsd_ptr;
|
RSDPDescriptor* ACPI::rsd_ptr;
|
||||||
|
RSCPDescriptor20* ACPI::rsd2_ptr;
|
||||||
RSDT* ACPI::rsd_table;
|
RSDT* ACPI::rsd_table;
|
||||||
|
|
||||||
|
const int KERNEL_OFFSET = 0xC0000000;
|
||||||
|
|
||||||
void ACPI::initialize(){
|
void ACPI::initialize(){
|
||||||
|
|
||||||
// Find the Root System Description Pointer
|
// Find the Root System Description Pointer
|
||||||
ACPI::rsd_ptr = FindRSD();
|
ACPI::rsd_ptr = FindRSD();
|
||||||
|
printf("RSD address: 0x%x\n", ACPI::rsd_ptr);
|
||||||
|
printRSD(rsd_ptr);
|
||||||
|
|
||||||
// is it valid
|
|
||||||
int sum = 0;
|
if( rsd_ptr->Revision == 0 ){
|
||||||
for (int i =0; i < 20 ; i++) {
|
// Using version 1.0 of the ACPI specification
|
||||||
sum += ((char*)rsd_ptr)[i];
|
int sum = rsd_ptr->Checksum;
|
||||||
|
for (int i =0; i < sizeof(RSDPDescriptor) ; i++) {
|
||||||
|
sum += ((char*)rsd_ptr)[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
printf(" 0x%x sum\n", sum);
|
||||||
|
if(sum & 0xfff0)
|
||||||
|
printf("valid rsd!\n");
|
||||||
|
else
|
||||||
|
printf("invalid rsd\n");
|
||||||
|
|
||||||
|
printf("rsdp: 0x%x\n", rsd_ptr);
|
||||||
|
|
||||||
|
printf("0x%x address\n", (rsd_ptr->RsdtAddress));
|
||||||
|
Immediate_Map(rsd_ptr->RsdtAddress + KERNEL_OFFSET, rsd_ptr->RsdtAddress);
|
||||||
|
|
||||||
|
RSDT* rootSystemDescriptionTable = (RSDT*)(rsd_ptr->RsdtAddress + KERNEL_OFFSET);
|
||||||
|
//printf("0x%x Root System Descriptor address\n", rootSystemDescriptionTable);
|
||||||
|
// checksum it, but we'll ignore it for now
|
||||||
|
printf("signature ");
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
kterm_put( rootSystemDescriptionTable->h.Signature[i]);
|
||||||
|
}
|
||||||
|
kterm_put('\n');
|
||||||
|
|
||||||
|
|
||||||
|
int entries = (rootSystemDescriptionTable->h.Length - sizeof (rootSystemDescriptionTable->h)) /4;
|
||||||
|
printf("%d num entries\n", entries);
|
||||||
|
for( int i = 0; i < entries; i++){
|
||||||
|
ACPISDTHeader* h = (ACPISDTHeader*) rootSystemDescriptionTable->PointerToSDT + i ;
|
||||||
|
if(strncmp(h->Signature, "FACP", 4)){
|
||||||
|
printf("Found FACP Entry!\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} else{
|
||||||
|
// parse it as of version2.0
|
||||||
|
printf("rsd2_ptr\n");
|
||||||
|
ACPI::rsd2_ptr = (RSCPDescriptor20*)rsd_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf(" 0x%x sum\n", sum);
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Get the Root System Description Table
|
|
||||||
RSDT* rootSystemDescriptionTable = getRSDT((RSDPDescriptor *) rsd_ptr);
|
|
||||||
|
|
||||||
|
/*
|
||||||
auto tableHeader = &rootSystemDescriptionTable->h;
|
auto tableHeader = &rootSystemDescriptionTable->h;
|
||||||
|
|
||||||
// do checksum
|
// do checksum
|
||||||
@ -31,5 +72,5 @@ void ACPI::initialize(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
if( sum != 0)
|
if( sum != 0)
|
||||||
printf("Table invalid!");
|
printf("Table invalid!");*/
|
||||||
}
|
}
|
@ -6,8 +6,9 @@ class ACPI {
|
|||||||
|
|
||||||
// In the future ACPI might start
|
// In the future ACPI might start
|
||||||
// doing more systems initialization
|
// doing more systems initialization
|
||||||
|
|
||||||
|
static RSDPDescriptor* rsd_ptr;
|
||||||
|
static RSCPDescriptor20* rsd2_ptr;
|
||||||
|
static RSDT* rsd_table;
|
||||||
private:
|
private:
|
||||||
static RSDPDescriptor* rsd_ptr;
|
|
||||||
static RSDT* rsd_table;
|
|
||||||
};
|
};
|
@ -1,5 +1,6 @@
|
|||||||
#include "rsdp.h"
|
#include "rsdp.h"
|
||||||
#include "../memory/VirtualMemoryManager.h"
|
#include "../memory/VirtualMemoryManager.h"
|
||||||
|
#include "../../CoreLib/Memory.h"
|
||||||
|
|
||||||
|
|
||||||
void printRSD(RSDPDescriptor* rsd){
|
void printRSD(RSDPDescriptor* rsd){
|
||||||
@ -16,25 +17,28 @@ void printRSD(RSDPDescriptor* rsd){
|
|||||||
kterm_put('\n');
|
kterm_put('\n');
|
||||||
|
|
||||||
printf("Revision: %d\n", rsd->Revision);
|
printf("Revision: %d\n", rsd->Revision);
|
||||||
printf("RSDT Address: 0x%x\n", rsd->RsdtAddress );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RSDPDescriptor* FindRSD(){
|
RSDPDescriptor* FindRSD(){
|
||||||
char* memory_byte = (char*) 0x000f2e14;
|
char* memory_byte = (char*) 0x000f2e14;
|
||||||
const void* string = "RSD PTR ";
|
const void* string = "RSD PTR ";
|
||||||
|
|
||||||
for( ; (uint32_t) memory_byte < 0x00100000; memory_byte+=10){
|
|
||||||
|
for( ; (uint32_t) memory_byte < 0x0100000; memory_byte+=10){
|
||||||
if( memcmp(memory_byte , string , 8 ) == 0 ) {
|
if( memcmp(memory_byte , string , 8 ) == 0 ) {
|
||||||
printf("RSD PTR found at 0x%x !\n", memory_byte);
|
printf("RSD PTR found at 0x%x !\n", memory_byte);
|
||||||
|
return (RSDPDescriptor*) memory_byte;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (RSDPDescriptor*) memory_byte;
|
|
||||||
|
memory_byte = (char*) 0x000E0000;
|
||||||
|
for ( ;(uint32_t) memory_byte < 0x000FFFFF; memory_byte += 1)
|
||||||
|
{
|
||||||
|
if( memcmp(memory_byte , string , 8 ) == 0 ) {
|
||||||
|
printf("RSD PTR found at 0x%x !\n", memory_byte);
|
||||||
|
return (RSDPDescriptor*) memory_byte;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
RSDT* getRSDT(RSDPDescriptor* rsd){
|
|
||||||
printf("rsdt Address: 0x%x\n", rsd->RsdtAddress);
|
|
||||||
return (RSDT*)rsd->RsdtAddress ;
|
|
||||||
|
|
||||||
}
|
|
@ -3,13 +3,6 @@
|
|||||||
#include <CoreLib/Memory.h>
|
#include <CoreLib/Memory.h>
|
||||||
#include <stdint-gcc.h>
|
#include <stdint-gcc.h>
|
||||||
|
|
||||||
struct RSDPDescriptor {
|
|
||||||
char signature[8];
|
|
||||||
uint8_t Checksum ;
|
|
||||||
char OEMID [6];
|
|
||||||
uint8_t Revision;
|
|
||||||
uint32_t RsdtAddress;
|
|
||||||
}__attribute__((packed));
|
|
||||||
|
|
||||||
struct ACPISDTHeader{
|
struct ACPISDTHeader{
|
||||||
char Signature[4];
|
char Signature[4];
|
||||||
@ -23,11 +16,28 @@ struct ACPISDTHeader{
|
|||||||
uint32_t CreatorRevision;
|
uint32_t CreatorRevision;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct RSDT{
|
struct RSDT{
|
||||||
struct ACPISDTHeader h;
|
struct ACPISDTHeader h;
|
||||||
uint32_t PointerToSDT[]; // Length of array : (header.Length - sizeof(header))/ 4
|
uint32_t *PointerToSDT; // Length of array : (header.Length - sizeof(header))/ 4
|
||||||
}__attribute__((packed));
|
}__attribute__((packed));
|
||||||
|
|
||||||
|
|
||||||
|
struct RSDPDescriptor {
|
||||||
|
char signature[8];
|
||||||
|
uint8_t Checksum ;
|
||||||
|
char OEMID [6];
|
||||||
|
uint8_t Revision;
|
||||||
|
uint32_t RsdtAddress;
|
||||||
|
}__attribute__((packed));
|
||||||
|
|
||||||
|
struct RSCPDescriptor20{
|
||||||
|
RSDPDescriptor base;
|
||||||
|
uint32_t Length;
|
||||||
|
uint64_t XsdtAddress;
|
||||||
|
uint8_t ExtendedChecksum;
|
||||||
|
uint8_t reserved[3];
|
||||||
|
}__attribute__((packed));
|
||||||
|
|
||||||
RSDPDescriptor* FindRSD();
|
RSDPDescriptor* FindRSD();
|
||||||
|
|
||||||
void printRSD(RSDPDescriptor* rsd);
|
void printRSD(RSDPDescriptor* rsd);
|
||||||
|
@ -3,6 +3,9 @@
|
|||||||
#include "../drivers/ps-2/keyboard.h"
|
#include "../drivers/ps-2/keyboard.h"
|
||||||
#include "../i386/processor.h"
|
#include "../i386/processor.h"
|
||||||
#include "../memory/VirtualMemoryManager.h"
|
#include "../memory/VirtualMemoryManager.h"
|
||||||
|
#include "../syscalls.h"
|
||||||
|
|
||||||
|
|
||||||
IDT_entry idt_table[256];
|
IDT_entry idt_table[256];
|
||||||
IDT_ptr idt_ptr;
|
IDT_ptr idt_ptr;
|
||||||
|
|
||||||
@ -18,7 +21,7 @@ void set_id_entry (uint8_t num , uint32_t base, uint16_t sel, uint8_t flags){
|
|||||||
|
|
||||||
void irs_handler (registers* regs) {
|
void irs_handler (registers* regs) {
|
||||||
uint32_t FaultingAddress;
|
uint32_t FaultingAddress;
|
||||||
//printf("(IRS) Interrupt number: %d \r", regs.int_no);
|
printf("(IRS) Interrupt number: %d \n EAX: ", regs->int_no, regs->eax);
|
||||||
switch (regs->int_no)
|
switch (regs->int_no)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
@ -188,7 +191,7 @@ void irs_handler (registers* regs) {
|
|||||||
printf("* Page protection violation!\n");
|
printf("* Page protection violation!\n");
|
||||||
} else{
|
} else{
|
||||||
printf("* Page not-present!\n");
|
printf("* Page not-present!\n");
|
||||||
Immediate_Map(FaultingAddress, FaultingAddress - 0xC0000000);
|
//Immediate_Map(FaultingAddress, FaultingAddress);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -259,6 +262,29 @@ void irs_handler (registers* regs) {
|
|||||||
printf("EBP: 0x%x\n", regs->ebp);
|
printf("EBP: 0x%x\n", regs->ebp);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 50:
|
||||||
|
printf("SYSTEMCALL\n");
|
||||||
|
printf("EAX 0x%x\n", regs->eax);
|
||||||
|
|
||||||
|
switch (regs->eax) {
|
||||||
|
case 0x0:
|
||||||
|
printf("test!\n");
|
||||||
|
break;
|
||||||
|
case 0x5:
|
||||||
|
sys_open();
|
||||||
|
break;
|
||||||
|
case 0x10:
|
||||||
|
sys_read((FILE*)regs->ebx, (char*)regs->ecx);
|
||||||
|
break;
|
||||||
|
case 0x20:
|
||||||
|
sys_write((FILE*)regs->ebx, (const char*)regs->ecx, regs->edx);
|
||||||
|
break;
|
||||||
|
case 0x666:
|
||||||
|
sys_version();
|
||||||
|
break;
|
||||||
|
|
||||||
|
};
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
// PANIC!!!
|
// PANIC!!!
|
||||||
break;
|
break;
|
||||||
@ -269,9 +295,6 @@ void irs_handler (registers* regs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void irq_handler (registers regs) {
|
void irq_handler (registers regs) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
switch (regs.int_no) {
|
switch (regs.int_no) {
|
||||||
case 0:
|
case 0:
|
||||||
pit_tick++;
|
pit_tick++;
|
||||||
@ -328,7 +351,7 @@ void irq_handler (registers regs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void initidt(){
|
void initidt(){
|
||||||
// Initialise the IDT pointer
|
// Initialize the IDT pointer
|
||||||
idt_ptr.length = sizeof(IDT_entry) * 255;
|
idt_ptr.length = sizeof(IDT_entry) * 255;
|
||||||
idt_ptr.base = (uint32_t)&idt_table;
|
idt_ptr.base = (uint32_t)&idt_table;
|
||||||
|
|
||||||
@ -371,7 +394,7 @@ void initidt(){
|
|||||||
set_id_entry(30, (uint32_t) irs30 , 0x08, 0x8E);
|
set_id_entry(30, (uint32_t) irs30 , 0x08, 0x8E);
|
||||||
set_id_entry(31, (uint32_t) irs31 , 0x08, 0x8E);
|
set_id_entry(31, (uint32_t) irs31 , 0x08, 0x8E);
|
||||||
|
|
||||||
|
set_id_entry(0x50, (uint32_t) irs50, 0x08, 0x8E);
|
||||||
//print_serial("Remapping PIC\n");
|
//print_serial("Remapping PIC\n");
|
||||||
PIC_remap(0x20, 0x28);
|
PIC_remap(0x20, 0x28);
|
||||||
|
|
||||||
|
@ -70,6 +70,7 @@ extern "C" {
|
|||||||
extern void irs29 ();
|
extern void irs29 ();
|
||||||
extern void irs30 ();
|
extern void irs30 ();
|
||||||
extern void irs31 ();
|
extern void irs31 ();
|
||||||
|
extern void irs50();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,115 +1,32 @@
|
|||||||
.globl irq0
|
.globl irq0
|
||||||
irq0:
|
|
||||||
cli
|
|
||||||
push $0
|
|
||||||
push $0
|
|
||||||
jmp irq_common
|
|
||||||
|
|
||||||
.globl irq1
|
.macro IRQ NAME, VECTOR
|
||||||
irq1:
|
.globl irq\NAME
|
||||||
cli
|
irq\NAME:
|
||||||
push $0
|
cli
|
||||||
push $1
|
push $0
|
||||||
jmp irq_common
|
push \VECTOR
|
||||||
|
jmp irq_common
|
||||||
|
.endm
|
||||||
|
|
||||||
.globl irq2
|
IRQ 0 $0
|
||||||
irq2:
|
IRQ 1 $1
|
||||||
cli
|
IRQ 2 $2
|
||||||
push $0
|
IRQ 3 $3
|
||||||
push $2
|
IRQ 4 $4
|
||||||
jmp irq_common
|
IRQ 5 $5
|
||||||
|
IRQ 6 $6
|
||||||
.globl irq3
|
IRQ 7 $7
|
||||||
irq3:
|
IRQ 8 $8
|
||||||
cli
|
IRQ 9 $9
|
||||||
push $0
|
IRQ 10 $10
|
||||||
push $3
|
IRQ 11 $11
|
||||||
jmp irq_common
|
IRQ 12 $12
|
||||||
|
IRQ 13 $13
|
||||||
.globl irq4
|
IRQ 14 $14
|
||||||
irq4:
|
IRQ 15 $15
|
||||||
cli
|
|
||||||
push $0
|
|
||||||
push $4
|
|
||||||
jmp irq_common
|
|
||||||
|
|
||||||
.globl irq5
|
|
||||||
irq5:
|
|
||||||
cli
|
|
||||||
push $0
|
|
||||||
push $5
|
|
||||||
jmp irq_common
|
|
||||||
|
|
||||||
.globl irq6
|
|
||||||
irq6:
|
|
||||||
cli
|
|
||||||
push $0
|
|
||||||
push $6
|
|
||||||
jmp irq_common
|
|
||||||
|
|
||||||
.globl irq7
|
|
||||||
irq7:
|
|
||||||
cli
|
|
||||||
push $0
|
|
||||||
push $7
|
|
||||||
jmp irq_common
|
|
||||||
|
|
||||||
.globl irq8
|
|
||||||
irq8:
|
|
||||||
cli
|
|
||||||
push $0
|
|
||||||
push $8
|
|
||||||
jmp irq_common
|
|
||||||
|
|
||||||
.globl irq9
|
|
||||||
irq9:
|
|
||||||
cli
|
|
||||||
push $0
|
|
||||||
push $9
|
|
||||||
jmp irq_common
|
|
||||||
|
|
||||||
.globl irq10
|
|
||||||
irq10:
|
|
||||||
cli
|
|
||||||
push $0
|
|
||||||
push $10
|
|
||||||
jmp irq_common
|
|
||||||
|
|
||||||
.globl irq11
|
|
||||||
irq11:
|
|
||||||
cli
|
|
||||||
push $0
|
|
||||||
push $11
|
|
||||||
jmp irq_common
|
|
||||||
|
|
||||||
|
|
||||||
.globl irq12
|
|
||||||
irq12:
|
|
||||||
cli
|
|
||||||
push $0
|
|
||||||
push $12
|
|
||||||
jmp irq_common
|
|
||||||
|
|
||||||
.globl irq13
|
|
||||||
irq13:
|
|
||||||
cli
|
|
||||||
push $0
|
|
||||||
push $13
|
|
||||||
jmp irq_common
|
|
||||||
|
|
||||||
.globl irq14
|
|
||||||
irq14:
|
|
||||||
cli
|
|
||||||
push $0
|
|
||||||
push $14
|
|
||||||
jmp irq_common
|
|
||||||
|
|
||||||
.globl irq15
|
|
||||||
irq15:
|
|
||||||
cli
|
|
||||||
push $0
|
|
||||||
push $15
|
|
||||||
jmp irq_common
|
|
||||||
|
|
||||||
irq_common:
|
irq_common:
|
||||||
pusha
|
pusha
|
||||||
|
@ -53,7 +53,7 @@ ISR_NOERRORCODE 28 $28
|
|||||||
ISR_NOERRORCODE 29 $29
|
ISR_NOERRORCODE 29 $29
|
||||||
ISR_NOERRORCODE 30 $30
|
ISR_NOERRORCODE 30 $30
|
||||||
ISR_NOERRORCODE 31 $31
|
ISR_NOERRORCODE 31 $31
|
||||||
|
ISR_NOERRORCODE 50 $50
|
||||||
|
|
||||||
irs_common:
|
irs_common:
|
||||||
pusha # Pushes edi,esi,ebp,esp,ebx,edx,ecx,eax
|
pusha # Pushes edi,esi,ebp,esp,ebx,edx,ecx,eax
|
||||||
@ -74,7 +74,7 @@ irs_common:
|
|||||||
|
|
||||||
call irs_handler
|
call irs_handler
|
||||||
|
|
||||||
pop %eax
|
pop %eax // pop stack pointer
|
||||||
pop %ebx // reload ther orignal data segment descriptor
|
pop %ebx // reload ther orignal data segment descriptor
|
||||||
mov %bx, %ds
|
mov %bx, %ds
|
||||||
mov %bx, %es
|
mov %bx, %es
|
||||||
@ -82,6 +82,6 @@ irs_common:
|
|||||||
mov %bx, %gs
|
mov %bx, %gs
|
||||||
|
|
||||||
popa
|
popa
|
||||||
add $12, %esp # cleans push error and irs code
|
add $8, %esp # cleans push error and irs code
|
||||||
|
|
||||||
iret # pops 5 things at once: CS, EIP, EFLAGS, SS, and ESP
|
iret # pops 5 things at once: CS, EIP, EFLAGS, SS, and ESP
|
||||||
|
@ -9,43 +9,21 @@
|
|||||||
#include "drivers/vga/VBE.h"
|
#include "drivers/vga/VBE.h"
|
||||||
#include "pci/pci.h"
|
#include "pci/pci.h"
|
||||||
#include "drivers/pit/pit.h"
|
#include "drivers/pit/pit.h"
|
||||||
#include "acpi/acpi.h"
|
|
||||||
#include "i386/processor.h"
|
#include "i386/processor.h"
|
||||||
#include "terminal/kterm.h"
|
#include "terminal/kterm.h"
|
||||||
#include "interrupts/idt.h"
|
#include "interrupts/idt.h"
|
||||||
#include "serial.h"
|
#include "serial.h"
|
||||||
#include "storage/vfs/vfs.h"
|
#include "storage/vfs/vfs.h"
|
||||||
#include "storage/filesystems/FAT/FAT.h"
|
#include "storage/filesystems/FAT/FAT.h"
|
||||||
#include "../CoreLib/Memory.h"
|
#include "acpi/acpi.h"
|
||||||
|
#include "memory/VirtualMemoryManager.h"
|
||||||
|
|
||||||
|
|
||||||
|
extern BootInfoBlock* BIB;
|
||||||
extern "C" void LoadGlobalDescriptorTable();
|
extern "C" void LoadGlobalDescriptorTable();
|
||||||
extern "C" void jump_usermode();
|
extern "C" void jump_usermode();
|
||||||
extern BootInfoBlock* BIB;
|
|
||||||
|
|
||||||
extern "C" void kernel ()
|
void initBootDrive(){
|
||||||
{
|
|
||||||
|
|
||||||
init_serial();
|
|
||||||
kterm_init();
|
|
||||||
|
|
||||||
setup_tss();
|
|
||||||
initGDT();
|
|
||||||
initidt();
|
|
||||||
LoadGlobalDescriptorTable();
|
|
||||||
flush_tss();
|
|
||||||
printf("Memory setup complete!\n");
|
|
||||||
|
|
||||||
// Enable interrupts
|
|
||||||
asm volatile("STI");
|
|
||||||
|
|
||||||
initHeap();
|
|
||||||
pit_initialise();
|
|
||||||
ACPI::initialize();
|
|
||||||
|
|
||||||
PCI::Scan();
|
|
||||||
processor::initialize();
|
|
||||||
processor::enable_protectedMode();
|
|
||||||
printf("Boot device: 0x%x\n", BIB->bootDeviceID);
|
printf("Boot device: 0x%x\n", BIB->bootDeviceID);
|
||||||
unsigned int part3 = BIB->bootDeviceID & 0xFF;
|
unsigned int part3 = BIB->bootDeviceID & 0xFF;
|
||||||
unsigned int part2 = (BIB->bootDeviceID & 0xFF00) >> 8;
|
unsigned int part2 = (BIB->bootDeviceID & 0xFF00) >> 8;
|
||||||
@ -58,32 +36,47 @@ extern "C" void kernel ()
|
|||||||
|
|
||||||
printf("Part1: %d, Part2: %d, Part3: %d\n", part1, part2 , part3);
|
printf("Part1: %d, Part2: %d, Part3: %d\n", part1, part2 , part3);
|
||||||
ATAPIO::Identify(ATAPIO_PORT::Primary, DEVICE_DRIVE::MASTER);
|
ATAPIO::Identify(ATAPIO_PORT::Primary, DEVICE_DRIVE::MASTER);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" void kernel ()
|
||||||
|
{
|
||||||
|
init_serial();
|
||||||
|
kterm_init();
|
||||||
|
print_serial("kterm initialized...\n");
|
||||||
|
setup_tss();
|
||||||
|
initGDT();
|
||||||
|
initidt();
|
||||||
|
LoadGlobalDescriptorTable();
|
||||||
|
flush_tss();
|
||||||
|
printf("Memory setup complete!\n");
|
||||||
|
print_serial("Memory initialized....\n");
|
||||||
|
// Enable interrupts
|
||||||
|
asm volatile("STI");
|
||||||
|
initHeap();
|
||||||
|
print_serial("Heap initialized...\n");
|
||||||
|
//pit_initialise();
|
||||||
|
|
||||||
|
|
||||||
|
//ACPI::initialize();
|
||||||
|
//PCI::Scan();
|
||||||
|
processor::initialize();
|
||||||
|
processor::enable_protectedMode();
|
||||||
|
initBootDrive();
|
||||||
VirtualFileSystem::initialize();
|
VirtualFileSystem::initialize();
|
||||||
|
|
||||||
printf("Lets open hello.txt\n");
|
print_serial("Run test!");
|
||||||
auto fontFile = VirtualFileSystem::open("/HELLO TXT", 0);
|
#define VFS_EXAMPLE
|
||||||
if(fontFile->flags == 0){
|
#ifdef VFS_EXAMPLE
|
||||||
uint16_t* contents = (uint16_t*) malloc(sizeof(uint16_t) * 256);
|
auto fontFile = VirtualFileSystem::open("/FONT PSF", 0);
|
||||||
fontFile->read(fontFile, contents, 512);
|
printf("Size of font file: %d bytes", fontFile->root->size); // COOL This Works like a charm
|
||||||
|
#endif
|
||||||
for(int i =0 ; i < fontFile->root->size; i++ ){
|
|
||||||
kterm_put(contents[i] & 0x00ff);
|
|
||||||
kterm_put(contents[i] >> 8);
|
|
||||||
}
|
|
||||||
kterm_put('\n');
|
|
||||||
free((void*)contents);
|
|
||||||
}else{
|
|
||||||
printf("Could not find file\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef USERMODE_RELEASE
|
#ifdef USERMODE_RELEASE
|
||||||
// Lets jump into user mode
|
// Lets jump into user mode
|
||||||
jump_usermode();
|
jump_usermode();
|
||||||
#else
|
#else
|
||||||
startSuperVisorTerminal();
|
startSuperVisorTerminal();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
@ -1,4 +1,6 @@
|
|||||||
#include "VirtualMemoryManager.h"
|
#include "VirtualMemoryManager.h"
|
||||||
|
#include "../../CoreLib/Memory.h"
|
||||||
|
|
||||||
#define ALIGN(addr, align) (((addr) & ~((align) - 1 )) + (align))
|
#define ALIGN(addr, align) (((addr) & ~((align) - 1 )) + (align))
|
||||||
|
|
||||||
extern uint32_t boot_page_directory[1024] ; // points to the wrong location
|
extern uint32_t boot_page_directory[1024] ; // points to the wrong location
|
||||||
@ -14,7 +16,7 @@ void flush_cr3(){
|
|||||||
|
|
||||||
void AllocatePage(uint32_t vaddr)
|
void AllocatePage(uint32_t vaddr)
|
||||||
{
|
{
|
||||||
uint32_t page_aligned_address = ALIGN(vaddr, 4096);
|
//uint32_t page_aligned_address = ALIGN(vaddr, 4096);
|
||||||
|
|
||||||
// allocate a page at virtual address
|
// allocate a page at virtual address
|
||||||
int PageDirectoryEntryIndex = vaddr >> 22;
|
int PageDirectoryEntryIndex = vaddr >> 22;
|
||||||
@ -54,16 +56,16 @@ void AllocatePage(uint32_t vaddr)
|
|||||||
|
|
||||||
void FreePage(uint32_t vaddr )
|
void FreePage(uint32_t vaddr )
|
||||||
{
|
{
|
||||||
uint32_t page_aligned_address = ALIGN(vaddr, 4096);
|
// uint32_t page_aligned_address = ALIGN(vaddr, 4096);
|
||||||
|
|
||||||
// allocate a page at virtual address
|
// allocate a page at virtual address
|
||||||
int PageDirectoryEntryIndex = vaddr >> 22;
|
int PageDirectoryEntryIndex = vaddr >> 22;
|
||||||
int PageTableEntryIndex = (vaddr >> 12) & 0x1FFF;
|
int PageTableEntryIndex = (vaddr >> 12) & 0x1FFF;
|
||||||
|
|
||||||
uint32_t* pageTable = (uint32_t*)(boot_page_directory[PageDirectoryEntryIndex] & 0xFFFFE000 + 0xC0000000);
|
uint32_t* pageTable = (uint32_t*)(boot_page_directory[PageDirectoryEntryIndex] & (0xFFFFE000 + 0xC0000000));
|
||||||
|
|
||||||
|
|
||||||
void* physicalAddressToFree = (void*)(pageTable[PageTableEntryIndex] & 0xFFFFE000 + 0xC0000000);
|
void* physicalAddressToFree = (void*)(pageTable[PageTableEntryIndex] & (0xFFFFE000 + 0xC0000000));
|
||||||
free_block(physicalAddressToFree);
|
free_block(physicalAddressToFree);
|
||||||
|
|
||||||
pageTable[PageTableEntryIndex] = 0x0;
|
pageTable[PageTableEntryIndex] = 0x0;
|
||||||
@ -80,9 +82,9 @@ void Immediate_Map ( uint32_t vaddr, uint32_t paddr)
|
|||||||
int PageTableEntryIndex = (vaddr >> 12) & 0x1FFF;
|
int PageTableEntryIndex = (vaddr >> 12) & 0x1FFF;
|
||||||
|
|
||||||
printf("Map address at PDE 0x%x PTE 0x%x\n", PageDirectoryEntryIndex, PageTableEntryIndex);
|
printf("Map address at PDE 0x%x PTE 0x%x\n", PageDirectoryEntryIndex, PageTableEntryIndex);
|
||||||
|
printf("boot pagedirectoy address: 0x%x\n", &boot_page_directory);
|
||||||
if ((boot_page_directory - 0xC0000000)[PageDirectoryEntryIndex] & 0x1 )
|
printf("PDE : 0x%x\n", boot_page_directory[PageTableEntryIndex]);
|
||||||
{
|
if (boot_page_directory[PageDirectoryEntryIndex] & 0x1 ) {
|
||||||
printf("Directory entry is marked as present\n");
|
printf("Directory entry is marked as present\n");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -90,37 +92,39 @@ void Immediate_Map ( uint32_t vaddr, uint32_t paddr)
|
|||||||
// mark the page table as present and allocate a physical block for it
|
// mark the page table as present and allocate a physical block for it
|
||||||
|
|
||||||
void* new_page_dir = allocate_block();
|
void* new_page_dir = allocate_block();
|
||||||
printf("New page directory address 0x%x\n", new_page_dir);
|
memset(new_page_dir, 0 , 1024 * sizeof (uint32_t));
|
||||||
|
printf("New page directory address 0x%x\n", &new_page_dir);
|
||||||
boot_page_directory[PageDirectoryEntryIndex] = (uint32_t)new_page_dir | 0x3;
|
boot_page_directory[PageDirectoryEntryIndex] = (uint32_t)new_page_dir | 0x3;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("PDE found at : 0x%x\n", (uint32_t) &boot_page_directory[PageDirectoryEntryIndex]);
|
printf("PDE found at : 0x%x\n", (uint32_t) &boot_page_directory[PageDirectoryEntryIndex]);
|
||||||
uint32_t* page_table = (uint32_t*)(boot_page_directory[PageDirectoryEntryIndex] & 0xFFFFE000) ;
|
uint32_t* page_table = (uint32_t*)(boot_page_directory[PageDirectoryEntryIndex] & 0xFFFFE000) ;
|
||||||
//page_table = (uint32_t*) ((uint32_t)page_table - 0xC0000000); // remove kernel offset
|
printf("Page table address: 0x%x\n", (uint32_t)page_table);
|
||||||
printf("Page table address: 0x%x\n", (uint32_t)page_table);
|
|
||||||
|
|
||||||
// check if the page table entry is marked as present
|
// check if the page table entry is marked as present
|
||||||
if ( page_table[PageTableEntryIndex] & 0x1 )
|
if ( page_table[PageTableEntryIndex] & 0x1 )
|
||||||
{
|
{
|
||||||
printf("page already present!\n");
|
printf("page already present!\n");
|
||||||
printf("Entry found at addr: 0x%x\n", &(page_table[PageTableEntryIndex]));
|
printf("Entry found at addr: 0x%x\n", &(page_table[PageTableEntryIndex]));
|
||||||
} else{
|
} else{
|
||||||
printf("Mapping a physical page.\n");
|
printf("Mapping a physical page.\n");
|
||||||
// Map the entry to a physical page
|
// Map the entry to a physical page
|
||||||
page_table[PageTableEntryIndex] = (uint32_t)(paddr | 0x3);
|
page_table[PageTableEntryIndex] = (uint32_t)(paddr | 0x3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
asm ("cli; invlpg (%0); sti" :: "r" (vaddr) : "memory" );
|
asm ("invlpg (%0)" :: "r" (vaddr) : "memory" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// NOT IMPLEMENTED
|
||||||
void Immediate_Unmap(uint32_t vaddr)
|
void Immediate_Unmap(uint32_t vaddr)
|
||||||
{
|
{
|
||||||
// NOTE: I will implement lazy unmapping for now
|
// NOTE: I will implement lazy unmapping for now
|
||||||
uint32_t page_aligned_address = ALIGN(vaddr, 4096);
|
//uint32_t page_aligned_address = ALIGN(vaddr, 4096);
|
||||||
|
|
||||||
// allocate a page at virtual address
|
// allocate a page at virtual address
|
||||||
int PageDirectoryEntryIndex = vaddr >> 22;
|
//int PageDirectoryEntryIndex = vaddr >> 22;
|
||||||
int PageTableEntryIndex = (vaddr >> 12) & 0x1FFF;
|
//int PageTableEntryIndex = (vaddr >> 12) & 0x1FFF;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include "multiboot.h"
|
#include "multiboot.h"
|
||||||
#include "../memory/PhysicalMemoryManager.h"
|
#include "../memory/PhysicalMemoryManager.h"
|
||||||
|
#include "../memory/VirtualMemoryManager.h"
|
||||||
|
#include "../acpi/acpi.h"
|
||||||
|
|
||||||
#define CHECK_FLAG(flags, bit) ((flags) & (1 <<(bit)))
|
#define CHECK_FLAG(flags, bit) ((flags) & (1 <<(bit)))
|
||||||
#define VADDR_TO_PADDR(vaddr) (vaddr - 0xC0000000)
|
#define VADDR_TO_PADDR(vaddr) (vaddr - 0xC0000000)
|
||||||
@ -10,7 +12,6 @@ BootInfoBlock* BIB;
|
|||||||
|
|
||||||
extern "C" void prekernelSetup ( unsigned long magic, multiboot_info_t* mbi)
|
extern "C" void prekernelSetup ( unsigned long magic, multiboot_info_t* mbi)
|
||||||
{
|
{
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check Multiboot magic number
|
* Check Multiboot magic number
|
||||||
*/
|
*/
|
||||||
@ -21,18 +22,13 @@ extern "C" void prekernelSetup ( unsigned long magic, multiboot_info_t* mbi)
|
|||||||
}
|
}
|
||||||
|
|
||||||
mbi = PADDR_TO_VADDR(mbi);
|
mbi = PADDR_TO_VADDR(mbi);
|
||||||
|
|
||||||
// Setup the physical memory manager immmediatly
|
|
||||||
// Doing so saves the complications of doing it later when
|
|
||||||
// paging is enabled
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
If we got a memory map from our bootloader we
|
If we got a memory map from our bootloader we
|
||||||
should be parsing it to find out the memory regions available.
|
should be parsing it to find out the memory regions available.
|
||||||
*/
|
*/
|
||||||
if (CHECK_FLAG(mbi->flags, 6))
|
if (CHECK_FLAG(mbi->flags, 6))
|
||||||
{
|
{
|
||||||
|
|
||||||
// Calculate total memory size
|
// Calculate total memory size
|
||||||
uint32_t RAM_size = 0;
|
uint32_t RAM_size = 0;
|
||||||
for(
|
for(
|
||||||
@ -56,6 +52,8 @@ extern "C" void prekernelSetup ( unsigned long magic, multiboot_info_t* mbi)
|
|||||||
deallocate_region(mmap->addr, mmap->len);
|
deallocate_region(mmap->addr, mmap->len);
|
||||||
if(mmap->type == MULTIBOOT_MEMORY_ACPI_RECLAIMABLE)
|
if(mmap->type == MULTIBOOT_MEMORY_ACPI_RECLAIMABLE)
|
||||||
allocate_region(mmap->addr, mmap->len);
|
allocate_region(mmap->addr, mmap->len);
|
||||||
|
// memory map
|
||||||
|
Immediate_Map(mmap->addr , mmap->addr);
|
||||||
if(mmap->type == MULTIBOOT_MEMORY_RESERVED)
|
if(mmap->type == MULTIBOOT_MEMORY_RESERVED)
|
||||||
allocate_region(mmap->addr, mmap->len);
|
allocate_region(mmap->addr, mmap->len);
|
||||||
if(mmap->type == MULTIBOOT_MEMORY_NVS)
|
if(mmap->type == MULTIBOOT_MEMORY_NVS)
|
||||||
@ -99,8 +97,6 @@ extern "C" void prekernelSetup ( unsigned long magic, multiboot_info_t* mbi)
|
|||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
BIB->GrubModuleCount = mbi->mods_count;
|
BIB->GrubModuleCount = mbi->mods_count;
|
||||||
|
|
||||||
|
|
||||||
for(i = 0, mod = (multiboot_module_t *) mbi->mods_addr; i < mbi->mods_count; i++ , mod++){
|
for(i = 0, mod = (multiboot_module_t *) mbi->mods_addr; i < mbi->mods_count; i++ , mod++){
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -135,6 +131,6 @@ extern "C" void prekernelSetup ( unsigned long magic, multiboot_info_t* mbi)
|
|||||||
|
|
||||||
// NOTE: Do something with it.. (Store it , process it etc...)
|
// NOTE: Do something with it.. (Store it , process it etc...)
|
||||||
} else{
|
} else{
|
||||||
BIB->EnabledVBE;
|
BIB->EnabledVBE = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,10 +107,10 @@ DirectoryNode* FAT::Lookup (inode* currentDir , DirectoryNode* dir)
|
|||||||
for(int i = 0; i < sizeof(data) / sizeof (DIR); i++)
|
for(int i = 0; i < sizeof(data) / sizeof (DIR); i++)
|
||||||
{
|
{
|
||||||
DIR* entry = (DIR*)((uint32_t)directory + (i * sizeof(DIR)));
|
DIR* entry = (DIR*)((uint32_t)directory + (i * sizeof(DIR)));
|
||||||
|
|
||||||
|
|
||||||
if(
|
if(
|
||||||
entry->Name[0] == FAT::FREE_DIR ||
|
entry->Name[0] == FAT::FREE_DIR ||
|
||||||
entry->Name[0] == FAT::FREE_DIR_2 ||
|
|
||||||
entry->Name[0] == 0xE5 ||
|
|
||||||
entry->ATTR & FAT::ATTRIBUTES::ATTR_VOLUME_ID ||
|
entry->ATTR & FAT::ATTRIBUTES::ATTR_VOLUME_ID ||
|
||||||
entry->ATTR & FAT::ATTRIBUTES::ATTR_SYSTEM ||
|
entry->ATTR & FAT::ATTRIBUTES::ATTR_SYSTEM ||
|
||||||
entry->ATTR & FAT::ATTRIBUTES::ATTR_HIDDEN
|
entry->ATTR & FAT::ATTRIBUTES::ATTR_HIDDEN
|
||||||
@ -118,6 +118,20 @@ DirectoryNode* FAT::Lookup (inode* currentDir , DirectoryNode* dir)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if( entry->ATTR & FAT::ATTRIBUTES::ATTR_DIRECTORY){
|
||||||
|
printf("entry in directory\n");
|
||||||
|
for(int i = 0; i < 11 ;i ++)
|
||||||
|
kterm_put(entry->Name[i]);
|
||||||
|
kterm_put('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if( entry->Name[0] == FAT::FREE_DIR_2 )
|
||||||
|
break;
|
||||||
|
|
||||||
auto* dirNode = (DirectoryNode*) malloc(sizeof (DirectoryNode));
|
auto* dirNode = (DirectoryNode*) malloc(sizeof (DirectoryNode));
|
||||||
|
|
||||||
char* name = (char*)malloc(sizeof(char[11]));
|
char* name = (char*)malloc(sizeof(char[11]));
|
||||||
|
@ -22,22 +22,22 @@ inline MBR* GetPartitions(bool DEBUG = false){
|
|||||||
int S =1;
|
int S =1;
|
||||||
uint32_t LBA = (C*HPC+H) * SPT + (S-1);
|
uint32_t LBA = (C*HPC+H) * SPT + (S-1);
|
||||||
|
|
||||||
MBR* mbr =(MBR*) malloc(sizeof (MBR));
|
uint16_t* mbr =(uint16_t*) malloc(sizeof (MBR));
|
||||||
|
|
||||||
ATAPIO::Read(ATAPIO_PORT::Primary, DEVICE_DRIVE::MASTER, LBA, (uint16_t*)mbr);
|
ATAPIO::Read(ATAPIO_PORT::Primary, DEVICE_DRIVE::MASTER, LBA, mbr );
|
||||||
|
auto bootRecord = (MBR*)(mbr);
|
||||||
|
|
||||||
|
printf("MBR (In Memory) Address 0x%x, Size = %d\n", bootRecord, sizeof (MBR));
|
||||||
printf("MBR (In Memory) Address 0x%x, Size = %d\n", mbr, sizeof (MBR));
|
|
||||||
if(DEBUG){
|
if(DEBUG){
|
||||||
printf("BootSector: 0x%x\n", mbr->ValidBootsector );
|
printf("BootSector: 0x%x\n", bootRecord->ValidBootsector );
|
||||||
for( int i = 0 ; i < 4 ; i ++){
|
for( int i = 0 ; i < 4 ; i ++){
|
||||||
PartitionTableEntry PT = mbr->TableEntries[i];
|
PartitionTableEntry PT = bootRecord->TableEntries[i];
|
||||||
|
|
||||||
printf("Partition %d [ %d sectors, PartitionType: 0x%x, 0x%x, \nLBA Start: 0x%x ]\n" ,
|
printf("Partition %d [ %d sectors, PartitionType: 0x%x, 0x%x, \nLBA Start: 0x%x ]\n" ,
|
||||||
i, PT.Number_sectors_inPartition, PT.PartitionType, mbr->uniqueID, PT.LBA_partition_start );
|
i, PT.Number_sectors_inPartition, PT.PartitionType, bootRecord->uniqueID, PT.LBA_partition_start );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return mbr;
|
return bootRecord;
|
||||||
}
|
}
|
||||||
|
@ -80,20 +80,37 @@ FILE* VirtualFileSystem::open(const char* pathname, int flags){
|
|||||||
}
|
}
|
||||||
|
|
||||||
// let's just loop through the folder first
|
// let's just loop through the folder first
|
||||||
|
printf("looking for: ");
|
||||||
|
for(int i = 0; i < 5; i++)
|
||||||
|
kterm_put(nextdir[i]);
|
||||||
|
kterm_put('\n');
|
||||||
auto* child = rootentry->children;
|
auto* child = rootentry->children;
|
||||||
while(child->next != nullptr){
|
while(child->next != nullptr){
|
||||||
|
|
||||||
auto* directory = (DirectoryNode*)child->data;
|
auto* directory = (DirectoryNode*)child->data;
|
||||||
|
|
||||||
|
for(int i = 0; i < 11 ; i++)
|
||||||
|
kterm_put(directory->name[i]);
|
||||||
|
kterm_put('\n');
|
||||||
|
|
||||||
if( directory->compare(directory, directory->name, nextdir) == 0){
|
if( directory->compare(directory, directory->name, nextdir) == 0){
|
||||||
nextdir = strtok(nullptr, "/", &tokstate);
|
nextdir = strtok(nullptr, "/", &tokstate);
|
||||||
|
printf("Found dir!\n");
|
||||||
if(nextdir == NULL){
|
if(nextdir == NULL){
|
||||||
file->root = directory->node;
|
file->root = directory->node;
|
||||||
file->flags =0;
|
file->flags =0;
|
||||||
file->read = FAT::Read;
|
file->read = FAT::Read;
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
printf("continue searching next directory!\n");
|
||||||
|
if(directory->children == nullptr)
|
||||||
|
directory->node->lookup(directory->node, directory);
|
||||||
|
|
||||||
|
|
||||||
|
child = directory->children;
|
||||||
|
|
||||||
|
}else{
|
||||||
|
child = child->next;
|
||||||
}
|
}
|
||||||
child = child->next;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
bool isRunning = true;
|
bool isRunning = true;
|
||||||
extern "C" void startSuperVisorTerminal()
|
extern "C" void startSuperVisorTerminal()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Show a little banner for cuteness
|
* Show a little banner for cuteness
|
||||||
*/
|
*/
|
||||||
@ -62,7 +64,8 @@ extern "C" void startSuperVisorTerminal()
|
|||||||
{
|
{
|
||||||
// Show version information
|
// Show version information
|
||||||
printf("========= Version ========\n");
|
printf("========= Version ========\n");
|
||||||
printf("Kernel v%d\n", 0);
|
|
||||||
|
asm volatile ("movl $0x666, %eax; int $0x50");
|
||||||
|
|
||||||
}
|
}
|
||||||
if(strncmp("CLEAR", command, characterCount) == 0)
|
if(strncmp("CLEAR", command, characterCount) == 0)
|
||||||
|
52
kernel/syscalls.h
Normal file
52
kernel/syscalls.h
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
//
|
||||||
|
// Created by nigel on 26/02/23.
|
||||||
|
//
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
|
#include "terminal/kterm.h"
|
||||||
|
#include "storage/vfs/vfs_types.h"
|
||||||
|
|
||||||
|
|
||||||
|
void sys_version (){
|
||||||
|
printf("KERNEL VERSION v0.4\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void sys_open(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void sys_read(FILE* file, char* data){
|
||||||
|
file->read(file, data, 512);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sys_write(FILE* path, const char* data, size_t size){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: this should become our standard!
|
||||||
|
void syscall_handler(int syscall_no , uint32_t* args... ){
|
||||||
|
switch(syscall_no){
|
||||||
|
case 0x0:
|
||||||
|
printf("test!\n");
|
||||||
|
break;
|
||||||
|
case 0x5:
|
||||||
|
// SYS_OPEN
|
||||||
|
// sys_open();
|
||||||
|
break;
|
||||||
|
case 0x10:
|
||||||
|
// SYS_READ
|
||||||
|
// sys_read((FILE*)args[1], (char*) args[2] );
|
||||||
|
break;
|
||||||
|
case 0x20:
|
||||||
|
// SYS_WRITE
|
||||||
|
//sys_write((FILE*)args[1], (const char*) args[2], (size_t)args[3]);
|
||||||
|
break;
|
||||||
|
case 0x666:
|
||||||
|
// SYS_VERSION
|
||||||
|
sys_version();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -21,7 +21,14 @@ void kterm_init () {
|
|||||||
kterm_row = 0;
|
kterm_row = 0;
|
||||||
kterm_column = 0;
|
kterm_column = 0;
|
||||||
kterm_color = vga_entry_color ( VGA_COLOR_LIGHT_GREY , VGA_COLOR_BLACK);
|
kterm_color = vga_entry_color ( VGA_COLOR_LIGHT_GREY , VGA_COLOR_BLACK);
|
||||||
kterm_buffer = (uint16_t*) 0xC03FF000;
|
|
||||||
|
//Physical address
|
||||||
|
// 0xB8000
|
||||||
|
// Virtual address
|
||||||
|
// 0xC03FF000
|
||||||
|
|
||||||
|
//kterm_buffer = ((uint16_t*) 0xB8000);
|
||||||
|
kterm_buffer = ((uint16_t*) 0xC03FF000 );
|
||||||
|
|
||||||
for (size_t y = 0; y < VGA_HEIGHT; y++ ){
|
for (size_t y = 0; y < VGA_HEIGHT; y++ ){
|
||||||
for( size_t x = 0; x < VGA_WIDTH; x++){
|
for( size_t x = 0; x < VGA_WIDTH; x++){
|
||||||
@ -59,7 +66,6 @@ void disable_cursor()
|
|||||||
outb(0x3D5, 0x20);
|
outb(0x3D5, 0x20);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void update_cursor(int x, int y){
|
void update_cursor(int x, int y){
|
||||||
uint16_t pos = y * VGA_WIDTH + x;
|
uint16_t pos = y * VGA_WIDTH + x;
|
||||||
|
|
||||||
@ -86,8 +92,6 @@ int get_cursor_y (uint16_t cursor_pos ) {
|
|||||||
return cursor_pos / VGA_WIDTH;
|
return cursor_pos / VGA_WIDTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* With the help from:
|
* With the help from:
|
||||||
* https://whiteheadsoftware.dev/operating-systems-development-for-dummies/
|
* https://whiteheadsoftware.dev/operating-systems-development-for-dummies/
|
||||||
@ -134,7 +138,6 @@ void kterm_writestring(const char* data ){
|
|||||||
kterm_write(data, strlen(data));
|
kterm_write(data, strlen(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void itoa (char *buf, int base, int d) {
|
static void itoa (char *buf, int base, int d) {
|
||||||
char *p = buf;
|
char *p = buf;
|
||||||
char *p1, *p2;
|
char *p1, *p2;
|
||||||
@ -173,28 +176,28 @@ static void itoa (char *buf, int base, int d) {
|
|||||||
|
|
||||||
void printf ( const char *format, ...) {
|
void printf ( const char *format, ...) {
|
||||||
|
|
||||||
char **arg = (char **)&format;
|
auto **arg = (unsigned char **)&format;
|
||||||
int c;
|
int c;
|
||||||
char buf[20];
|
char buf[20];
|
||||||
|
|
||||||
arg++;
|
arg++;
|
||||||
|
|
||||||
while ((c = *format++) != 0){
|
while ((c = *(const unsigned char*)format++) != 0){
|
||||||
if( c != '%')
|
if( c != '%')
|
||||||
kterm_put(c);
|
kterm_put(c);
|
||||||
else{
|
else{
|
||||||
char *p, *p2;
|
char const *p, *p2;
|
||||||
int pad0 = 0, pad = 0;
|
int pad0 = 0, pad = 0;
|
||||||
|
|
||||||
c = *format++;
|
c = *(const unsigned char*)format++;
|
||||||
if(c =='0'){
|
if(c =='0'){
|
||||||
pad0 = 1;
|
pad0 = 1;
|
||||||
c = *format++;
|
c = *(const unsigned char*)format++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( c >= '0' && c <= '9'){
|
if ( c >= '0' && c <= '9'){
|
||||||
pad = c - '0';
|
pad = c - '0';
|
||||||
c = *format++;
|
c = *(const unsigned char*)format++;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (c)
|
switch (c)
|
||||||
@ -210,7 +213,7 @@ void printf ( const char *format, ...) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 's':
|
case 's':
|
||||||
p = *arg++;
|
p = (char const *)*arg++;
|
||||||
if(!p)
|
if(!p)
|
||||||
p = "(null)";
|
p = "(null)";
|
||||||
|
|
||||||
@ -224,7 +227,7 @@ void printf ( const char *format, ...) {
|
|||||||
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
kterm_put(*((int *)arg++));
|
kterm_put(*(int *) arg++); // NOLINT(cppcoreguidelines-narrowing-conversions)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
22
run.sh
22
run.sh
@ -3,23 +3,25 @@ PROC=$$
|
|||||||
|
|
||||||
# Build the Corelib static library
|
# Build the Corelib static library
|
||||||
(cd CoreLib
|
(cd CoreLib
|
||||||
if ! make; then
|
if ! make 2> warnings.log 1> /dev/null ; then
|
||||||
echo "Build failed!"
|
echo "Build Corelib failed!"
|
||||||
kill -10 $PROC
|
kill -10 $PROC
|
||||||
fi)
|
fi)
|
||||||
|
|
||||||
# Build the kernel image
|
# Build the kernel image
|
||||||
(cd kernel
|
(cd kernel
|
||||||
make clean
|
# make clean
|
||||||
make
|
if ! make 2> warnings.log 1> /dev/null ; then
|
||||||
if ! make; then
|
echo "Build kernel failed!"
|
||||||
echo "Build failed!"
|
|
||||||
kill -10 $PROC
|
kill -10 $PROC
|
||||||
fi)
|
fi)
|
||||||
|
|
||||||
./scripts/update_harddrive.sh
|
./scripts/update_harddrive.sh
|
||||||
|
./scripts/create_symbol_lookup.sh
|
||||||
|
|
||||||
|
args="";
|
||||||
|
if [[ $1 == "-d" ]]
|
||||||
./scripts/run_qemu.sh
|
then
|
||||||
|
args="debug"
|
||||||
|
fi
|
||||||
|
./scripts/run_qemu.sh $args
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
echo "creating symbols file"
|
||||||
objcopy --only-keep-debug build/kernel/myos.bin kernel.sym
|
echo $(pwd)
|
||||||
|
objcopy --only-keep-debug root/boot/myos.bin kernel.sym
|
@ -1,7 +1,13 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [[ $1 == "debug" ]]
|
||||||
|
then
|
||||||
|
qemu-system-i386 -s -boot d -drive format=raw,file=disk.img -serial stdio -vga std -display gtk -m 2G -cpu core2duo -d int -no-shutdown -no-reboot
|
||||||
|
else
|
||||||
|
qemu-system-i386 -s -boot d -drive format=raw,file=disk.img -serial stdio -vga std -display gtk -m 2G -cpu core2duo
|
||||||
|
fi
|
||||||
# Run from harddisk
|
# Run from harddisk
|
||||||
qemu-system-i386 -boot d -drive format=raw,file=disk.img -serial stdio -vga std -display gtk -m 2G -cpu core2duo
|
#qemu-system-i386 -boot d -drive format=raw,file=disk.img -serial stdio -vga std -display gtk -m 2G -cpu core2duo -d int -no-shutdown -no-reboot
|
||||||
|
|
||||||
# Run disk version
|
# Run disk version
|
||||||
# qemu-system-i386 -cdrom barinkOS.iso -serial stdio -vga std -display gtk -m 2G -cpu core2duo -s -d int -no-shutdown -no-reboot
|
# qemu-system-i386 -cdrom barinkOS.iso -serial stdio -vga std -display gtk -m 2G -cpu core2duo -s -d int -no-shutdown -no-reboot
|
||||||
|
Reference in New Issue
Block a user