Compare commits

..

2 Commits

Author SHA1 Message Date
5781f730d9 Implemented the basis for syscalls
A software interrupt with vector 0x50 will cause a syscall to start executing.
The EAX register will hold the syscall_num.
Other registers and the stack can be used to hold further arguments.
2023-02-27 00:34:30 +01:00
2d0bb16fad Fixed up ACPI Version 1.0 checksum validation code 2023-02-27 00:32:16 +01:00
12 changed files with 194 additions and 177 deletions

View File

@ -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;

View File

@ -1,5 +1,6 @@
#include "acpi.h" #include "acpi.h"
RSDPDescriptor* ACPI::rsd_ptr; RSDPDescriptor* ACPI::rsd_ptr;
RSCPDescriptor20* ACPI::rsd2_ptr;
RSDT* ACPI::rsd_table; RSDT* ACPI::rsd_table;
@ -8,19 +9,34 @@ 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 veriosn 1.0 of the ACPI specifiction
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");
// Get the Root System Description Table NOTE: might need memory mapping
//RSDT* rootSystemDescriptionTable = (RSDT*) (rsd_ptr->RsdtAddress + 0xC0000000);
} else{
// parse it as of version2.0
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 +47,5 @@ void ACPI::initialize(){
} }
if( sum != 0) if( sum != 0)
printf("Table invalid!"); printf("Table invalid!");*/
} }

View File

@ -7,7 +7,8 @@ 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;
}; };

View File

@ -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,7 +17,6 @@ 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(){
@ -31,10 +31,3 @@ RSDPDescriptor* FindRSD(){
} }
return (RSDPDescriptor*) memory_byte; return (RSDPDescriptor*) memory_byte;
} }
RSDT* getRSDT(RSDPDescriptor* rsd){
printf("rsdt Address: 0x%x\n", rsd->RsdtAddress);
return (RSDT*)rsd->RsdtAddress ;
}

View File

@ -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];
@ -28,6 +21,24 @@ 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;
RSDT* 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);

View File

@ -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:
@ -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);

View File

@ -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();

View File

@ -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

View File

@ -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

View File

@ -9,23 +9,37 @@
#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;
void initBootDrive(){
printf("Boot device: 0x%x\n", BIB->bootDeviceID);
unsigned int part3 = BIB->bootDeviceID & 0xFF;
unsigned int part2 = (BIB->bootDeviceID & 0xFF00) >> 8;
unsigned int part1 = (BIB->bootDeviceID & 0xFF0000) >> 16;
unsigned int drive = (BIB->bootDeviceID & 0xFF000000) >> 24;
if (drive == 0x80 )
printf("booted from disk!\n");
if(drive == 0x00)
printf("booted from floppy disk\n");
printf("Part1: %d, Part2: %d, Part3: %d\n", part1, part2 , part3);
ATAPIO::Identify(ATAPIO_PORT::Primary, DEVICE_DRIVE::MASTER);
}
extern "C" void kernel () extern "C" void kernel ()
{ {
init_serial(); init_serial();
kterm_init(); kterm_init();
@ -42,32 +56,21 @@ extern "C" void kernel ()
initHeap(); initHeap();
pit_initialise(); pit_initialise();
ACPI::initialize(); ACPI::initialize();
PCI::Scan(); PCI::Scan();
processor::initialize(); processor::initialize();
processor::enable_protectedMode(); processor::enable_protectedMode();
printf("Boot device: 0x%x\n", BIB->bootDeviceID); initBootDrive();
unsigned int part3 = BIB->bootDeviceID & 0xFF;
unsigned int part2 = (BIB->bootDeviceID & 0xFF00) >> 8;
unsigned int part1 = (BIB->bootDeviceID & 0xFF0000) >> 16;
unsigned int drive = (BIB->bootDeviceID & 0xFF000000) >> 24;
if (drive == 0x80 )
printf("booted from disk!\n");
if(drive == 0x00)
printf("booted from floppy disk\n");
printf("Part1: %d, Part2: %d, Part3: %d\n", part1, part2 , part3);
ATAPIO::Identify(ATAPIO_PORT::Primary, DEVICE_DRIVE::MASTER);
VirtualFileSystem::initialize(); VirtualFileSystem::initialize();
printf("Lets open hello.txt\n");
auto fontFile = VirtualFileSystem::open("/HELLO TXT", 0);
if(fontFile->flags == 0){
uint16_t* contents = (uint16_t*) malloc(sizeof(uint16_t) * 256);
fontFile->read(fontFile, contents, 512);
for(int i =0 ; i < fontFile->root->size; i++ ){
#ifdef VFS_EXAMPLE
auto fontFile = VirtualFileSystem::open("/FONT PSF", 0);
if(grubcfg->flags == 0){
uint16_t* contents = (uint16_t*) malloc(sizeof(uint16_t) * 256);
grubcfg->read(grubcfg, contents, 512);
for(int i =0 ; i < grubcfg->root->size; i++ ){
kterm_put(contents[i] & 0x00ff); kterm_put(contents[i] & 0x00ff);
kterm_put(contents[i] >> 8); kterm_put(contents[i] >> 8);
} }
@ -76,8 +79,7 @@ extern "C" void kernel ()
}else{ }else{
printf("Could not find file\n"); printf("Could not find file\n");
} }
#endif
#ifdef USERMODE_RELEASE #ifdef USERMODE_RELEASE
// Lets jump into user mode // Lets jump into user mode

View File

@ -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
View 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;
}
}