Compare commits

10 Commits

Author SHA1 Message Date
6086b04054 Added klog as a new logging system
* The logging system sends the message to both VGA and serial
* The serial print uses color to indicate the category of the message

Message Categories  |  Colours
Debug			Green
Info			Blue
Error			Red
2023-10-28 22:28:21 +02:00
9c5667c454 Created a proper driver for the serial bus
* The driver can write to any of the pre-defined serial COM ports
* The driver can read from any of the pre-defined serial COM ports (Untested)
2023-10-28 21:51:04 +02:00
2522492835 Couple of small changes
* Commented out the map page function call to handle page not present
* Mapped the ACPI_RECLAIMABLE_MEMORY
* Set VBE to false when VBE is not initialized by the bootloader
2023-10-28 20:42:28 +02:00
e82392e9d9 FAT Filesystem implementation additions 2023-10-27 18:07:11 +02:00
64c87a2a58 Fixing an issue in the CoreLib 2023-10-27 18:04:09 +02:00
04470edcc6 Adding gdb init and adjusting some of the build automation steps 2023-10-27 18:03:45 +02:00
2970806705 ACPI reading memory when mapped to higher half 2023-09-11 23:23:38 +02:00
e8df6ec628 Updating Build scripts 2023-09-11 23:21:43 +02:00
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
31 changed files with 522 additions and 360 deletions

7
.gdbinit Normal file
View 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
View File

@ -11,3 +11,5 @@ root/
*.a *.a
/CoreLib/warnings.log
/kernel/warnings.log

View File

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

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

@ -108,7 +108,7 @@ int isprint (int ch){
return 1; return 1;
if(isspace(ch)) if(isspace(ch))
return 1; return 1;
return 0;
} }

View File

@ -34,12 +34,14 @@ OFILES = $(OBJ_DIR)/boot.o \
$(OBJ_DIR)/ataDevice.o \ $(OBJ_DIR)/ataDevice.o \
$(OBJ_DIR)/rsdp.o \ $(OBJ_DIR)/rsdp.o \
$(OBJ_DIR)/acpi.o \ $(OBJ_DIR)/acpi.o \
$(OBJ_DIR)/fat.o $(OBJ_DIR)/fat.o \
$(OBJ_DIR)/serial.o \
$(OBJ_DIR)/klog.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 +51,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:
@ -121,6 +123,12 @@ $(OBJ_DIR)/processor.o:
$(OBJ_DIR)/fat.o: $(OBJ_DIR)/fat.o:
$(CPP) -c storage/filesystems/FAT/FAT.cpp -o $(OBJ_DIR)/fat.o $(CFLAGS) -fno-exceptions -fno-rtti $(CPP) -c storage/filesystems/FAT/FAT.cpp -o $(OBJ_DIR)/fat.o $(CFLAGS) -fno-exceptions -fno-rtti
$(OBJ_DIR)/serial.o:
$(CPP) -c drivers/serial/serial.cpp -o $(OBJ_DIR)/serial.o $(CFLAGS) -fno-exceptions -fno-rtti
$(OBJ_DIR)/klog.o:
$(CPP) -c klog.cpp -o $(OBJ_DIR)/klog.o $(CFLAGS) -fno-exceptions -fno-rtti
# Assembly -> Object files # Assembly -> Object files
$(OBJ_DIR)/boot.o: $(OBJ_DIR)/boot.o:
$(AS) boot/boot.s -o $(OBJ_DIR)/boot.o $(AS) boot/boot.s -o $(OBJ_DIR)/boot.o

View File

@ -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
int sum = rsd_ptr->Checksum;
for (int i =0; i < sizeof(RSDPDescriptor) ; i++) {
sum += ((char*)rsd_ptr)[i]; sum += ((char*)rsd_ptr)[i];
} }
printf(" 0x%x sum\n", sum); printf(" 0x%x sum\n", sum);
return; if(sum & 0xfff0)
printf("valid rsd!\n");
else
printf("invalid rsd\n");
// Get the Root System Description Table printf("rsdp: 0x%x\n", rsd_ptr);
RSDT* rootSystemDescriptionTable = getRSDT((RSDPDescriptor *) 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;
}
/*
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!");*/
} }

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
private:
static RSDPDescriptor* rsd_ptr; static RSDPDescriptor* rsd_ptr;
static RSCPDescriptor20* rsd2_ptr;
static RSDT* rsd_table; static RSDT* rsd_table;
private:
}; };

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,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;
} }
} }
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; return (RSDPDescriptor*) memory_byte;
} break;
}
}
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];
@ -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);

View File

@ -1,19 +1,52 @@
#include "serial.h" #include "serial.h"
#include "../../io/io.h"
Serial Serial::init() { // Initializes communication according to the spec given
// No clue what to setup yet! Serial::Serial(SerialConfig config) {
port = config.port;
// Disable interrupts
outb(config.port + 1, 0x00);
return Serial(); // Enable DLAB
outb(config.port + 3, 0x80);
// set the baudrate
outb(config.port + 0, 0x03);
outb(config.port + 1, 0x00);
// configure for 8bits, no parity, one stop bit
outb(config.port + 3, 0x03);
// Enable FIFO, clear them, with 14-byte threshhold
outb(config.port + 2, 0xC7);
// Enable IRQ's, RTS/DSR set
outb(config.port + 4, 0x0B );
// Set in loopback mode, test the serial chip.
outb(config.port + 4, 0x1E);
// TEST
outb(config.port + 0 , 0xAE);
if(inb(config.port + 0) != 0xAE)
return ; // FAIL
outb(config.port + 4, 0x0F);
return ;
} }
void Serial::print(){ void Serial::write(void* data, int len) {
// Do nothing! while (is_transmit_empty() == 0); // Wait for transmit queue to be free
for (int i = 0; i < len ; i++){
outb(port, ((uint8_t*)data)[i]);
}
} }
Serial::Serial(){ char Serial::read() {
// Do nothing! return inb(port);
} }
Serial::~Serial(){ int Serial::is_transmit_empty() {
// Do nothing! return inb(port + 5) & 0x20;
} }

View File

@ -1,19 +1,29 @@
#pragma once #pragma once
// For now these are the standard
// serial ports we can talk to
enum SERIALPORT {
COM1 = 0x3F8,
COM2 = 0x2F8,
COM3 = 0x3E8,
COM4 = 0x2E8
};
struct SerialConfig {
SERIALPORT port;
char baud_rate_lo ;
char baud_rate_hi;
};
class Serial { class Serial {
public: public:
static Serial init(); Serial (SerialConfig config );
void print(); char read();
void write(void* data, int length);
private: private:
const int COM1 = 0x3F8; SERIALPORT port;
const int COM2 = 0x2F8; int is_transmit_empty();
const int COM3 = 0x3E8;
const int COM4 = 0x2E8;
Serial();
~Serial();
}; };

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

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:
.macro IRQ NAME, VECTOR
.globl irq\NAME
irq\NAME:
cli cli
push $0 push $0
push $0 push \VECTOR
jmp irq_common jmp irq_common
.endm
.globl irq1 IRQ 0 $0
irq1: IRQ 1 $1
cli IRQ 2 $2
push $0 IRQ 3 $3
push $1 IRQ 4 $4
jmp irq_common IRQ 5 $5
IRQ 6 $6
.globl irq2 IRQ 7 $7
irq2: IRQ 8 $8
cli IRQ 9 $9
push $0 IRQ 10 $10
push $2 IRQ 11 $11
jmp irq_common IRQ 12 $12
IRQ 13 $13
.globl irq3 IRQ 14 $14
irq3: IRQ 15 $15
cli
push $0
push $3
jmp irq_common
.globl irq4
irq4:
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,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 "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"
#include "klog.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,53 @@ 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 ()
{
kterm_init();
setup_tss();
initGDT();
initidt();
LoadGlobalDescriptorTable();
flush_tss();
print_info("Memory setup complete!\n");
// Enable interrupts
asm volatile("STI");
initHeap();
//pit_initialise();
//ACPI::initialize();
//PCI::Scan();
processor::initialize();
processor::enable_protectedMode();
initBootDrive();
VirtualFileSystem::initialize(); VirtualFileSystem::initialize();
printf("Lets open hello.txt\n"); print_dbg("Hello debug!\n");
auto fontFile = VirtualFileSystem::open("/HELLO TXT", 0); print_info("Hello info!\n");
if(fontFile->flags == 0){ print_err("Hello error!\n");
uint16_t* contents = (uint16_t*) malloc(sizeof(uint16_t) * 256);
fontFile->read(fontFile, contents, 512);
for(int i =0 ; i < fontFile->root->size; i++ ){ #define VFS_EXAMPLE
kterm_put(contents[i] & 0x00ff); #ifdef VFS_EXAMPLE
kterm_put(contents[i] >> 8); auto fontFile = VirtualFileSystem::open("/FONT PSF", 0);
} printf("Size of font file: %d bytes\n", fontFile->root->size); // COOL This Works like a charm
kterm_put('\n');
free((void*)contents);
}else{
printf("Could not find file\n");
}
#endif
#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
} }

58
kernel/klog.cpp Normal file
View File

@ -0,0 +1,58 @@
//
// Created by nigel on 10/28/23.
//
#include "klog.h"
#include "terminal/kterm.h"
#include <CoreLib/Memory.h>
const char* ForeGroundColourReset = "\e[39m";
void print_dbg(const char* message, ...){
auto **arg = (unsigned char**)&message;
// Send it to the VGA
printf(message, arg);
// Now send the message to the serial
Serial com1= Serial({
COM1,
0x03,
0x00
});
const char* ForeGroundColour = "\e[32m";
com1.write((void*)ForeGroundColour, strlen(ForeGroundColour));
com1.write((void*)message, strlen(message));
com1.write((void*)ForeGroundColourReset, strlen(ForeGroundColourReset));
}
void print_info(const char* message, ...){
auto **arg = (unsigned char**)&message;
// Send it to the VGA
printf(message, arg);
Serial com1 = Serial({
COM1,
0x03,
0x00
});
const char* ForeGroundColour = "\e[34m";
com1.write((void*)ForeGroundColour, strlen(ForeGroundColour));
com1.write((void*)message, strlen(message));
com1.write((void*)ForeGroundColourReset, strlen(ForeGroundColourReset));
}
void print_err(const char* message, ...){
auto **arg = (unsigned char**)&message;
// Send it to the VGA
printf(message, arg);
Serial com1 = Serial({
COM1,
0x03,
0x00
});
const char* ForeGroundColour = "\e[31m";
com1.write((void*)ForeGroundColour, strlen(ForeGroundColour));
com1.write((void*)message, strlen(message));
com1.write((void*)ForeGroundColourReset, strlen(ForeGroundColourReset));
}

12
kernel/klog.h Normal file
View File

@ -0,0 +1,12 @@
//
// Created by nigel on 10/28/23.
//
#pragma once
#include "drivers/serial/serial.h"
void print_dbg(const char* message, ...);
void print_info(const char* message, ...);
void print_err(const char* message, ...);

View File

@ -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,14 +92,13 @@ 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
@ -112,15 +113,18 @@ void Immediate_Map ( uint32_t vaddr, uint32_t paddr)
} }
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;
} }

View File

@ -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,11 +22,6 @@ 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.
@ -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;
} }
} }

View File

@ -1,58 +0,0 @@
#pragma once
#include "terminal/kterm.h"
#include "io/io.h"
#define PORT 0x3f8
static int init_serial() {
#ifdef __VERBOSE__
printf("Init Serial\n");
#endif
outb(PORT + 1, 0x00); // Disable all interrupts
outb(PORT + 3, 0x80); // Enable DLAB (set baud rate divisor)
outb(PORT + 0, 0x03); // Set divisor to 3 (lo byte) 38400 baud
outb(PORT + 1, 0x00); // (hi byte)
outb(PORT + 3, 0x03); // 8 bits, no parity, one stop bit
outb(PORT + 2, 0xC7); // Enable FIFO, clear them, with 14-byte threshold
outb(PORT + 4, 0x0B); // IRQs enabled, RTS/DSR set
outb(PORT + 4, 0x1E); // Set in loopback mode, test the serial chip
outb(PORT + 0, 0xAE); // Test serial chip (send byte 0xAE and check if serial returns same byte)
// Check if serial is faulty (i.e: not same byte as sent)
if(inb(PORT + 0) != 0xAE) {
return 1;
}
// If serial is not faulty set it in normal operation mode
// (not-loopback with IRQs enabled and OUT#1 and OUT#2 bits enabled)
outb(PORT + 4, 0x0F);
return 0;
}
inline int is_transmit_empty() {
return inb(PORT + 5) & 0x20;
}
inline void write_serial(char a) {
while (is_transmit_empty() == 0);
outb(PORT,a);
}
inline int serial_received() {
return inb(PORT + 5) & 1;
}
inline char read_serial() {
while (serial_received() == 0);
return inb(PORT);
}
inline void print_serial(const char* string ){
for(size_t i = 0; i < strlen(string); i ++){
write_serial(string[i]);
}
}

View File

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

View File

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

View File

@ -80,21 +80,38 @@ 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;
} }
}

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

View File

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

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

View File

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

View File

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