Merge into main the new state of the operating system/kernel #1

Open
Nigel wants to merge 120 commits from dev into main
7 changed files with 53 additions and 36 deletions
Showing only changes of commit 2621399349 - Show all commits

View File

@ -18,8 +18,9 @@ $(BUILD_DIR)/pci.o \
$(BUILD_DIR)/pic.o \ $(BUILD_DIR)/pic.o \
$(BUILD_DIR)/string.o \ $(BUILD_DIR)/string.o \
$(BUILD_DIR)/pcidevice.o \ $(BUILD_DIR)/pcidevice.o \
$(BUILD_DIR)/atapiDevice.o $(BUILD_DIR)/atapiDevice.o \
$(BUILD_DIR)/ataDevice.o \
$(BUILD_DIR)/rsdp.o \
SRC_DIR = src SRC_DIR = src
@ -54,7 +55,7 @@ test:
$(EMULATOR) -kernel $(BUILD_DIR)/myos.bin -serial stdio -vga std -display gtk -m 2G -cpu core2duo $(EMULATOR) -kernel $(BUILD_DIR)/myos.bin -serial stdio -vga std -display gtk -m 2G -cpu core2duo
test_iso: test_iso:
$(EMULATOR) -cdrom $(BUILD_DIR)/barinkOS.iso -serial stdio -vga std -display gtk -m 2G -cpu core2duo $(EMULATOR) -boot d -cdrom $(BUILD_DIR)/barinkOS.iso -serial stdio -vga std -display gtk -m 2G -cpu core2duo
build_kernel: $(OBJ_LINK_LIST) build_kernel: $(OBJ_LINK_LIST)
$(CC) -T $(SRC_DIR)/kernel//linker.ld -o $(BUILD_DIR)/myos.bin \ $(CC) -T $(SRC_DIR)/kernel//linker.ld -o $(BUILD_DIR)/myos.bin \
@ -112,3 +113,10 @@ $(BUILD_DIR)/pcidevice.o:
$(BUILD_DIR)/atapiDevice.o: $(BUILD_DIR)/atapiDevice.o:
$(CPP) -c $(SRC_DIR)/kernel/drivers/atapi/atapiDevice.cpp -o $(BUILD_DIR)/atapiDevice.o $(CFLAGS) -fno-exceptions -fno-rtti $(CPP) -c $(SRC_DIR)/kernel/drivers/atapi/atapiDevice.cpp -o $(BUILD_DIR)/atapiDevice.o $(CFLAGS) -fno-exceptions -fno-rtti
$(BUILD_DIR)/ataDevice.o:
$(CPP) -c $(SRC_DIR)/kernel/drivers/ata/ataDevice.cpp -o $(BUILD_DIR)/ataDevice.o $(CFLAGS) -fno-exceptions -fno-rtti
$(BUILD_DIR)/rsdp.o:
$(CPP) -c $(SRC_DIR)/kernel/drivers/rsdp/rsdp.cpp -o $(BUILD_DIR)/rsdp.o $(CFLAGS) -fno-exceptions -fno-rtti

View File

@ -180,7 +180,8 @@ void ATA_DEVICE::Read(uint16_t DEVICE_CHANNEL, DEVICE_DRIVE drive, uint32_t LBA
for ( int i = 0; i < 256; i++){ for ( int i = 0; i < 256; i++){
uint16_t data; uint16_t data;
asm volatile ("inw %1, %0" : "=a"(data): "Nd"(DEVICE_CHANNEL)); asm volatile ("inw %1, %0" : "=a"(data): "Nd"(DEVICE_CHANNEL));
printf (" %x ", data); // printf (" %x ", data);
buffer[i] = data; buffer[i] = data;
} }

View File

@ -2,7 +2,6 @@
#define GB4 524288 #define GB4 524288
#define GB2 262144 #define GB2 262144
int memcmp( const void* ptr1, const void* ptr2, size_t num);
extern "C" void kernel_main (void); extern "C" void kernel_main (void);
@ -34,27 +33,10 @@ extern "C" void kernel_main (void);
initGDT(); initGDT();
kernel_main(); kernel_main();
} }
int memcmp( const void* ptr1, const void* ptr2, size_t num)
{
const unsigned char * cs = (const unsigned char*) ptr1;
const unsigned char * ct = (const unsigned char*) ptr2;
for (int i = 0 ; i < num ; i++, cs++, ct++ ){
if( *cs < *ct){
return -1;
} else if( *cs > *ct){
return 1;
}
}
return 0;
}
extern "C" void kernel_main (void) { extern "C" void kernel_main (void) {
@ -105,9 +87,5 @@ extern "C" void kernel_main (void);
printf( "UTC time: %02d-%02d-%02d %02d:%02d:%02d [ Formatted as YY-MM-DD h:mm:ss]\r" ,year, month, day, hour, minute, second); printf( "UTC time: %02d-%02d-%02d %02d:%02d:%02d [ Formatted as YY-MM-DD h:mm:ss]\r" ,year, month, day, hour, minute, second);
delay(1000); delay(1000);
} }
} }

View File

@ -3,7 +3,7 @@
#include "tty/kterm.h" #include "tty/kterm.h"
#include "io.h" #include "io.h"
#define PORT 0x3f8 #define PORT 0x3f8
static int init_serial() { inline static int init_serial() {
outb(PORT + 1, 0x00); // Disable all interrupts outb(PORT + 1, 0x00); // Disable all interrupts
outb(PORT + 3, 0x80); // Enable DLAB (set baud rate divisor) outb(PORT + 3, 0x80); // Enable DLAB (set baud rate divisor)
outb(PORT + 0, 0x03); // Set divisor to 3 (lo byte) 38400 baud outb(PORT + 0, 0x03); // Set divisor to 3 (lo byte) 38400 baud
@ -25,33 +25,33 @@ static int init_serial() {
return 0; return 0;
} }
int is_transmit_empty() { inline int is_transmit_empty() {
return inb(PORT + 5) & 0x20; return inb(PORT + 5) & 0x20;
} }
void write_serial(char a) { inline void write_serial(char a) {
while (is_transmit_empty() == 0); while (is_transmit_empty() == 0);
outb(PORT,a); outb(PORT,a);
} }
int serial_received() { inline int serial_received() {
return inb(PORT + 5) & 1; return inb(PORT + 5) & 1;
} }
char read_serial() { inline char read_serial() {
while (serial_received() == 0); while (serial_received() == 0);
return inb(PORT); return inb(PORT);
} }
void print_serial(const char* string ){ inline void print_serial(const char* string ){
for(size_t i = 0; i < strlen(string); i ++){ for(size_t i = 0; i < strlen(string); i ++){
write_serial(string[i]); write_serial(string[i]);
} }
} }
void test_serial(){ inline void test_serial(){
/** Serial test **/ /** Serial test **/
kterm_writestring("Writing to COM1 serial port:"); kterm_writestring("Writing to COM1 serial port:");
init_serial(); init_serial();

View File

@ -1,5 +1,4 @@
#include "kterm.h" #include "kterm.h"
static const size_t VGA_WIDTH = 80; static const size_t VGA_WIDTH = 80;
static const size_t VGA_HEIGHT = 25; static const size_t VGA_HEIGHT = 25;
@ -173,6 +172,13 @@ static void itoa (char *buf, int base, int d) {
} }
/**
* @brief For now this will not only write to VGA memory but also write to serial
*
* @param format
* @param ...
*/
void printf ( const char *format, ...) { void printf ( const char *format, ...) {
char **arg = (char **)&format; char **arg = (char **)&format;

View File

@ -1,3 +1,5 @@
#pragma once
// NOTE: These should not be inline
inline void* memset (void* ptr, int value, size_t num){ inline void* memset (void* ptr, int value, size_t num){
for( int i = 0; i < num; i++ ) for( int i = 0; i < num; i++ )
{ {
@ -6,3 +8,23 @@ inline void* memset (void* ptr, int value, size_t num){
} }
return ptr; return ptr;
} }
inline int memcmp( const void* ptr1, const void* ptr2, size_t num)
{
const unsigned char * cs = (const unsigned char*) ptr1;
const unsigned char * ct = (const unsigned char*) ptr2;
for (int i = 0 ; i < num ; i++, cs++, ct++ ){
if( *cs < *ct){
return -1;
} else if( *cs > *ct){
return 1;
}
}
return 0;
}

View File

@ -6,4 +6,6 @@ size_t strlen(const char* str) {
len++; len++;
} }
return len; return len;
} }