Skip to content

Commit

Permalink
Major update
Browse files Browse the repository at this point in the history
* Implemented VFS
* Implemented SORFS
* Implemented tree structure
* Implemented slow ata driver
* Implemented mbr partition probing
* Implemented ramdisk
* Implemented devfs
* Implemented kernelfs
* Implemented filesystem detection function
* Created tools for making and extracting sorfs disk image
* Can access sorfs disk image loaded using module command in grub
* Implemented PCI driver
* Fixed some bugs in vga_text driver
* Fixed a bug in strstr function in string.c
* Implemented random motd printing
* Implemented zalloc to allocate memory initialized with 0
* Updated Makefile
* Updated kernelmain.c
* Incremented kernel version
  • Loading branch information
Arun007coder committed Apr 8, 2023
1 parent 3a9accc commit 40e3beb
Show file tree
Hide file tree
Showing 38 changed files with 3,096 additions and 35 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
**/*.o
src/kernel/kernel.o
*.sym
*.log
*.log
*.img
sorfs
sorhd
36 changes: 29 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ INCLUDEDIR=$(SRCDIR)/include/
BACKUPDIR=$(SRCDIR)/../../BACKUP/
GRUBDIR=
SCRIPTSDIR=$(SRCDIR)/scripts/
FILESDIR=files

CC=$(TOOLDIR)/i686-elf-gcc
CFLAGS= -I$(INCLUDEDIR) -I/usr/include -nostdlib -lgcc -fno-builtin -fno-exceptions -fno-leading-underscore -Wall -m32 -g
Expand All @@ -27,17 +28,19 @@ OBJDUMP = i686-elf-objdump
OBJCOPYFLAGS = --strip-debug --strip-unneeded

QEMU=qemu-system-i386
QEMUFLAGS=-cdrom SEOS.iso -m 1024M
QEMUDFLAGS=-serial file:serial.log -s -S -daemonize -m 32M
QEMUFLAGS=-cdrom $(ISOFILE) -m 1024M -boot d
QEMUDFLAGS=-serial file:serial.log -s -S -daemonize -m 64M

PROJECT=SEOS
PROJECT=SectorOS-RW4

EXECUTABLE=$(PROJECT).elf
ISOFILE=$(PROJECT).iso
IMAGEFILE=sorhd

OBJECTS= $(SRCDIR)/boot/multiboot.o \
$(SRCDIR)/boot/boot.o \
$(SRCDIR)/drivers/io/ports.o \
$(SRCDIR)/drivers/io/pci.o \
$(SRCDIR)/drivers/power/reboot.o \
$(SRCDIR)/drivers/cpu/gdt.o \
$(SRCDIR)/drivers/cpu/gdt_helper.o \
Expand All @@ -47,6 +50,9 @@ OBJECTS= $(SRCDIR)/boot/multiboot.o \
$(SRCDIR)/drivers/cpu/pit.o \
$(SRCDIR)/drivers/cpu/rdtsc.o \
$(SRCDIR)/drivers/cpu/cpuinfo.o \
$(SRCDIR)/drivers/storage/atapio.o \
$(SRCDIR)/drivers/storage/mbr.o \
$(SRCDIR)/drivers/storage/ramdisk.o \
$(SRCDIR)/interrupts/interrupt.o \
$(SRCDIR)/interrupts/interrupt_helper.o \
$(SRCDIR)/interrupts/exception.o \
Expand All @@ -58,6 +64,12 @@ OBJECTS= $(SRCDIR)/boot/multiboot.o \
$(SRCDIR)/common/libs/math.o \
$(SRCDIR)/common/libs/rng.o \
$(SRCDIR)/common/libs/list.o \
$(SRCDIR)/common/libs/tree.o \
$(SRCDIR)/fs/vfs.o \
$(SRCDIR)/fs/devfs.o \
$(SRCDIR)/fs/mount.o \
$(SRCDIR)/fs/sorfs.o \
$(SRCDIR)/fs/kernelfs.o \
$(SRCDIR)/drivers/video/vga_text.o \
$(SRCDIR)/drivers/io/serial.o \
$(SRCDIR)/drivers/input/keyboard.o \
Expand All @@ -78,19 +90,21 @@ $(EXECUTABLE): $(OBJECTS)

compile_objs: $(OBJECTS)

$(ISOFILE): $(EXECUTABLE)
$(ISOFILE): $(IMAGEFILE) $(EXECUTABLE)
@echo '[GRUB] $@'
@mkdir -p $(PROJECT)/boot/grub
@cp $(EXECUTABLE) $(PROJECT)/boot/
@cp sorhd $(PROJECT)/boot/
@echo 'set timeout=3' >> $(PROJECT)/boot/grub/grub.cfg
@echo 'set default=0' >> $(PROJECT)/boot/grub/grub.cfg
@echo 'set root=(cd)' >> $(PROJECT)/boot/grub/grub.cfg
@echo '' >> $(PROJECT)/boot/grub/grub.cfg
@echo 'menuentry "$(PROJECT)" { '>> $(PROJECT)/boot/grub/grub.cfg
@echo 'multiboot /boot/$(EXECUTABLE)' >> $(PROJECT)/boot/grub/grub.cfg
@echo 'module /boot/sorhd' >> $(PROJECT)/boot/grub/grub.cfg
@echo 'boot' >> $(PROJECT)/boot/grub/grub.cfg
@echo '}' >> $(PROJECT)/boot/grub/grub.cfg
@$(GRUBDIR)grub-mkrescue -o $(ISOFILE) $(PROJECT)
@$(GRUBDIR)grub-mkrescue -o $(ISOFILE) $(PROJECT) --product-name=$(PROJECT)
@rm -rf $(PROJECT)/


Expand All @@ -106,8 +120,16 @@ $(ISOFILE): $(EXECUTABLE)
@echo '[NASM] $@'
@$(NASM) $(NASMFLAGS) -o $@ $<

sorfs_compile:
@echo '[CC] $(SRCDIR)/tools/sorfs.c => sorfs'
@gcc $(SRCDIR)/tools/sorfs.c -o sorfs

$(IMAGEFILE): sorfs_compile
@echo '[SORFS] $@'
./sorfs -c $@ $(wildcard $(FILESDIR)/*)

run: $(ISOFILE)
$(QEMU) $(QEMUFLAGS)
$(QEMU) $(QEMUFLAGS) -enable-kvm -cpu host

rund: $(ISOFILE)
$(QEMU) $(QEMUFLAGS) $(QEMUDFLAGS)
Expand All @@ -122,7 +144,7 @@ forcerund: clean iso rund
PHONY: clean kernel
clean:
@echo 'Cleaning the source directory...'
@rm -f $(OBJECTS) $(EXECUTABLE) $(ISOFILE)
@rm -f $(OBJECTS) $(EXECUTABLE) $(ISOFILE) sorfs $(IMAGEFILE)

clean_objs:
@rm -f $(OBJECTS)
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Kernel Version


## 🧱 Kernel
The current kernel version for SectorOS-RW4 is v3.23.03.8NR.<br>
The current kernel version for SectorOS-RW4 is v4.23.04.2NR.<br>

## ⚙️ Build Steps

Expand Down
26 changes: 24 additions & 2 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
* Incremented kernel version
* Updated README.md

03-04-2023: 02:23 PM IST v3.23.03.8NR
03-04-2023: 02:23 PM IST v3.23.04.1NR
* Major update
* Fixed a bug in PMM
* Implemented function to retrieve cpuinfo
Expand All @@ -100,4 +100,26 @@
* Updated textmode driver
* Updated Makefile
* Incremented kernel version
* Implemented a function to dump contents of a memory address to screen or serial port
* Implemented a function to dump contents of a memory address to screen or serial port

08-04-2023: 09:30 PM IST v4.23.04.2NR
* Major update
* Implemented VFS
* Implemented SORFS
* Implemented tree structure
* Implemented slow ata driver
* Implemented mbr partition probing
* Implemented ramdisk
* Implemented devfs
* Implemented kernelfs
* Implemented filesystem detection function
* Created tools for making and extracting sorfs disk image
* Can access sorfs disk image loaded using module command in grub
* Implemented PCI driver
* Fixed some bugs in vga_text driver
* Fixed a bug in strstr function in string.c
* Implemented random motd printing
* Implemented zalloc to allocate memory initialized with 0
* Updated Makefile
* Updated kernelmain.c
* Incremented kernel version
1 change: 1 addition & 0 deletions files/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello World!
1 change: 1 addition & 0 deletions src/common/libs/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ void stack_trace(uint32_t maxframes)
for(uint32_t frame = 0; stk && frame < maxframes; frame++)
{
printf("\t[0x%06x]: 0x%06x\n", ((uint32_t)stk), stk->eip);
serialprintf("\t[0x%06x]: 0x%06x\n", ((uint32_t)stk), stk->eip);
stk = stk->ebp;
}
}
Expand Down
45 changes: 39 additions & 6 deletions src/common/libs/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ int memcmp(uint8_t* data1, uint8_t* data2, int n)
return 1;
}

int memzero(uint8_t* data, size_t size)
{
for(int i = 0; i < size; i++)
{
if(data[i] != 0)
{
return 1;
}
}
return 0;
}

void* memcpy(void* dst, const void* src, int n)
{
char* ret = (char*)dst;
Expand Down Expand Up @@ -126,17 +138,17 @@ int strncmp(const char *s1, const char *s2, int c)
char* strstr(const char* in, const char* str)
{
char c;
size_t len;
uint32_t len;

c = *str;
if(!c)
return (char*)in;
c = *str++;
if (!c)
return (char *)in;

len = strlen(str);

do
{
char sc;

do
{
sc = *in++;
Expand Down Expand Up @@ -226,7 +238,28 @@ int atoi(char *string)

char* itoa_r(unsigned long int n, int base)
{
return NULL;
unsigned long int tmp;
int i, j;
char* buf = (char*)kmalloc(sizeof(char) * 32);

tmp = n;
i = 0;

do
{
tmp = n % base;
buf[i++] = (tmp < 10) ? (tmp + '0') : (tmp + 'a' - 10);
} while (n /= base);
buf[i--] = 0;

for (j = 0; j < i; j++, i--)
{
tmp = buf[j];
buf[j] = buf[i];
buf[i] = tmp;
}

return buf;
}

int isspace(char c)
Expand Down
103 changes: 103 additions & 0 deletions src/common/libs/tree.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#include "tree.h"


tree_t* tree_create()
{
return (tree_t *)kcalloc(sizeof(tree_t), 1);
}

treenode_t *tree_node_create(void *data)
{
treenode_t *n = (treenode_t*)kcalloc(sizeof(treenode_t), 1);
n->data = data;
n->children = list_create();
return n;
}

treenode_t *tree_insert(tree_t *tree, treenode_t *subroot, void *data)
{
treenode_t *treenode = (treenode_t*)kcalloc(sizeof(treenode_t), 1);
treenode->children = list_create();
treenode->data = data;

if (!tree->root)
{
tree->root = treenode;
return treenode;
}
list_insert_front(subroot->children, treenode);
return treenode;
}

treenode_t *tree_findParent(tree_t *tree, treenode_t *remove_node, int *child_index)
{
if (remove_node == tree->root)
return NULL;
return tree_findParent_recur(tree, remove_node, tree->root, child_index);
}

treenode_t *tree_findParent_recur(tree_t *tree, treenode_t *remove_node, treenode_t *subroot, int *child_index)
{
int idx;
if ((idx = list_contain(subroot->children, remove_node)) != -1)
{
*child_index = idx;
return subroot;
}
foreach (child, subroot->children)
{
treenode_t *ret = tree_findParent_recur(tree, remove_node, (treenode_t*)child->val, child_index);
if (ret != NULL)
{
return ret;
}
}
return NULL;
}

void tree_remove(tree_t *tree, treenode_t *remove_node)
{
int child_index = -1;
treenode_t *parent = tree_findParent(tree, remove_node, &child_index);
if (parent != NULL)
{
treenode_t *freethis = (treenode_t*)list_remove_by_index(parent->children, child_index);
kfree(freethis);
}
}

void tree2list_recur(treenode_t *subroot, list_t *list)
{
if (subroot == NULL)
return;
foreach (child, subroot->children)
{
treenode_t *curr_treenode = (treenode_t *)child->val;
void *curr_val = curr_treenode->data;
list_insert_back(list, curr_val);
tree2list_recur((treenode_t*)child->val, list);
}
}

void tree2list(tree_t *tree, list_t *list)
{
tree2list_recur(tree->root, list);
}

void tree2array(tree_t *tree, void **array, int *size)
{
tree2array_recur(tree->root, array, size);
}

void tree2array_recur(treenode_t *subroot, void **array, int *size)
{
if (subroot == NULL)
return;
void *curr_val = (void *)subroot->data;
array[*size] = curr_val;
*size = *size + 1;
foreach (child, subroot->children)
{
tree2array_recur((treenode_t*)child->val, array, size);
}
}
8 changes: 8 additions & 0 deletions src/drivers/input/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,5 +389,13 @@ char kcodeTochar(uint8_t scancode)
break;
}
}
else if(scancode == 0xaa || scancode == 0xb6)
{
isShift = 0;
}
else
{
serialprintf("[KBD] GOT KEYPRESS: 0x%02x\n", scancode);
}
return key;
}
Loading

0 comments on commit 40e3beb

Please sign in to comment.