Skip to content

Commit 7aeb32b

Browse files
committed
Major update
* Implemented Process manager with input support. * Implemented a ELF loader which loads static linked * Implemented a syscall handler * Added a sample program. * Added new command to the shell * Added new function to fetch bg and fg color * Implemented a function to get arguments from grub * Updated kernel.c * Updated Makefile * Updated README.md * Fixed some warnings the compiler outputted * Incremented kernel version
1 parent f5159c3 commit 7aeb32b

File tree

22 files changed

+922
-11
lines changed

22 files changed

+922
-11
lines changed

Makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ OBJECTS= $(SRCDIR)/boot/multiboot.o \
5959
$(SRCDIR)/interrupts/interrupt_helper.o \
6060
$(SRCDIR)/interrupts/exception.o \
6161
$(SRCDIR)/interrupts/exception_helper.o \
62+
$(SRCDIR)/interrupts/syscall.o \
6263
$(SRCDIR)/common/libs/debug.o \
6364
$(SRCDIR)/common/libs/string.o \
6465
$(SRCDIR)/common/libs/printf.o \
@@ -79,6 +80,9 @@ OBJECTS= $(SRCDIR)/boot/multiboot.o \
7980
$(SRCDIR)/memory/paging.o \
8081
$(SRCDIR)/memory/pmm.o \
8182
$(SRCDIR)/process/usermode.o \
83+
$(SRCDIR)/process/process.o \
84+
$(SRCDIR)/process/context_switch.o \
85+
$(SRCDIR)/process/elf_loader.o \
8286
$(SRCDIR)/kernel/shell.o \
8387
$(SRCDIR)/kernel/kernel.o
8488

@@ -103,7 +107,7 @@ $(ISOFILE): $(IMAGEFILE) $(EXECUTABLE)
103107
@echo 'set root=(cd)' >> $(PROJECT)/boot/grub/grub.cfg
104108
@echo '' >> $(PROJECT)/boot/grub/grub.cfg
105109
@echo 'menuentry "$(PROJECT)" { '>> $(PROJECT)/boot/grub/grub.cfg
106-
@echo 'multiboot /boot/$(EXECUTABLE)' >> $(PROJECT)/boot/grub/grub.cfg
110+
@echo 'multiboot /boot/$(EXECUTABLE) --root /dev/rdisk0' >> $(PROJECT)/boot/grub/grub.cfg
107111
@echo 'module /boot/sorhd' >> $(PROJECT)/boot/grub/grub.cfg
108112
@echo 'boot' >> $(PROJECT)/boot/grub/grub.cfg
109113
@echo '}' >> $(PROJECT)/boot/grub/grub.cfg
@@ -127,7 +131,7 @@ sorfs_compile:
127131
@echo '[CC] $(SRCDIR)/tools/sorfs.c => sorfs'
128132
@gcc $(SRCDIR)/tools/sorfs.c -o sorfs
129133

130-
$(IMAGEFILE): sorfs_compile
134+
$(IMAGEFILE): sorfs_compile create_test_program
131135
@echo '[SORFS] $@'
132136
./sorfs -c $@ $(wildcard $(FILESDIR)/*)
133137

@@ -144,6 +148,9 @@ stripd: $(EXECUTABLE)
144148
@$(TOOLDIR)$(OBJCOPY) --only-keep-debug $(EXECUTABLE) debug.sym
145149
@$(TOOLDIR)$(OBJCOPY) $(OBJCOPYFLAGS) $(EXECUTABLE)
146150

151+
create_test_program:
152+
$(CC) -nostdlib $(SRCDIR)/tools/user.c -o files/app.elf
153+
147154
forcerun: clean iso run
148155
forcerund: clean iso rund
149156

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Kernel Version
1414

1515

1616
## 🧱 Kernel
17-
The current kernel version for SectorOS-RW4 is v4.23.04.3NR.<br>
17+
The current kernel version for SectorOS-RW4 is v5.23.04.4NR.<br>
1818

1919
## ⚙️ Build Steps
2020

docs/changelog.txt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,19 @@
134134
* Updated kernel.c
135135
* Incremented kernel version
136136
* Updated Makefile
137-
* Updated README.md
137+
* Updated README.md
138+
139+
09-04-2023: 10:48 PM IST v5.23.04.4NR
140+
* Major update
141+
* Implemented Process manager with input support.
142+
* Implemented a ELF loader which loads static linked
143+
* Implemented a syscall handler
144+
* Added a sample program.
145+
* Added new command to the shell
146+
* Added new function to fetch bg and fg color
147+
* Implemented a function to get arguments from grub
148+
* Updated kernel.c
149+
* Updated Makefile
150+
* Updated README.md
151+
* Fixed some warnings the compiler outputted
152+
* Incremented kernel version

src/common/libs/bit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ uint8_t hibyte(uint16_t data)
1212

1313
void set_hibyte(uint16_t* data, uint8_t num)
1414
{
15-
data = (num << 8);
15+
*data = (uint16_t)(num << 8);
1616
}
1717

1818
void set_lobyte(uint16_t* data, uint8_t num)
1919
{
20-
data = num;
20+
*data = (uint16_t)num;
2121
}
2222

2323
int get_bit(uint32_t data, int num)

src/common/libs/debug.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
void kernel_panic(const char* message)
55
{
6-
text_chcolor(VGA_LIGHT_RED, VGA_BLACK);
6+
text_chcolor(VGA_LIGHT_RED, text_getBG());
77
printf("kernel panic: - %s\n", message);
88
while(1);
99
}

src/common/libs/list.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,18 @@ int list_contain(list_t * list, void * val)
122122
return -1;
123123
}
124124

125+
int list_contain_str(list_t* list, char* str)
126+
{
127+
int index = 0;
128+
foreach(listnode, list)
129+
{
130+
if(strcmp(listnode->val, str) == 0)
131+
return index;
132+
index++;
133+
}
134+
return -1;
135+
}
136+
125137
listnode_t * list_get_node_by_index(list_t * list, int index)
126138
{
127139
if(index < 0 || index >= list_size(list))

src/drivers/cpu/gdt.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "gdt.h"
22
#include "bit.h"
3+
#include "debug.h"
34
#include "isr.h"
45

56
gdt_entry_t entries[GDT_MAX_ENTRIES];

src/drivers/video/vga_text.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,16 @@ void text_chcolor(uint8_t fg, uint8_t bg)
116116
textmode.fg = fg;
117117
}
118118

119+
uint8_t text_getBG()
120+
{
121+
return textmode.bg;
122+
}
123+
124+
uint8_t text_getFG()
125+
{
126+
return textmode.fg;
127+
}
128+
119129
void text_puts(char* str)
120130
{
121131
while(*str)

src/include/elf_loader.h

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#ifndef __ELF_LOADER_H__
2+
#define __ELF_LOADER_H__
3+
4+
#include "system.h"
5+
#include "syscall.h"
6+
#include "string.h"
7+
#include "kheap.h"
8+
#include "vfs.h"
9+
#include "paging.h"
10+
#include "printf.h"
11+
12+
#define DEFAULT_ELF_LOAD_ADDR (void*)0x08048000
13+
14+
#define ELF_NIDENT 16
15+
16+
#define ELFMAG0 0x7F
17+
#define ELFMAG1 'E'
18+
#define ELFMAG2 'L'
19+
#define ELFMAG3 'F'
20+
#define ELFDATA2LSB (1)
21+
#define ELFCLASS32 (1)
22+
#define EM_386 (3)
23+
#define EV_CURRENT (1)
24+
25+
#define SHN_UNDEF (0x00)
26+
27+
#define PT_NULL 0
28+
#define PT_LOAD 1
29+
#define PT_DYNAMIC 2
30+
#define PT_INTERP 3
31+
#define PT_NOTE 4
32+
#define PT_SHLIB 5
33+
#define PT_PHDR 6
34+
#define PT_LOPROC 0x70000000
35+
#define PT_HIPROC 0x7fffffff
36+
37+
#define PF_X 0x1
38+
#define PF_W 0x2
39+
#define PF_R 0x4
40+
41+
typedef uint16_t Elf32_Half;
42+
typedef uint32_t Elf32_Off;
43+
typedef uint32_t Elf32_Addr;
44+
typedef uint32_t Elf32_Word;
45+
typedef int Elf32_Sword;
46+
47+
enum Elf_Ident
48+
{
49+
EI_MAG1 = 1,
50+
EI_MAG0 = 0,
51+
EI_MAG3 = 3,
52+
EI_MAG2 = 2,
53+
EI_DATA = 5,
54+
EI_CLASS = 4,
55+
EI_OSABI = 7,
56+
EI_VERSION = 6,
57+
EI_ABIVERSION = 8,
58+
EI_PAD = 9
59+
};
60+
61+
enum Elf_Type
62+
{
63+
ET_NONE = 0,
64+
ET_REL = 1,
65+
ET_EXEC = 2
66+
};
67+
68+
enum ShT_Types
69+
{
70+
SHT_NULL = 0,
71+
SHT_PROGBITS= 1,
72+
SHT_SYMTAB = 2,
73+
SHT_STRTAB = 3,
74+
SHT_RELA = 4,
75+
SHT_NOBITS = 8,
76+
SHT_REL = 9,
77+
};
78+
79+
enum ShT_Attributes
80+
{
81+
SHF_WRITE = 0x01,
82+
SHF_ALLOC = 0x02
83+
};
84+
85+
86+
typedef struct elf_header
87+
{
88+
uint8_t e_ident[ELF_NIDENT];
89+
Elf32_Half e_type;
90+
Elf32_Half e_machine;
91+
Elf32_Word e_version;
92+
Elf32_Addr e_entry;
93+
Elf32_Off e_phoff;
94+
Elf32_Off e_shoff;
95+
Elf32_Word e_flags;
96+
Elf32_Half e_ehsize;
97+
Elf32_Half e_phentsize;
98+
Elf32_Half e_phnum;
99+
Elf32_Half e_shentsize;
100+
Elf32_Half e_shnum;
101+
Elf32_Half e_shstrndx;
102+
}elf_header_t;
103+
104+
typedef struct elf_section_header
105+
{
106+
Elf32_Word sh_name;
107+
Elf32_Word sh_type;
108+
Elf32_Word sh_flags;
109+
Elf32_Addr sh_addr;
110+
Elf32_Off sh_offset;
111+
Elf32_Word sh_size;
112+
Elf32_Word sh_link;
113+
Elf32_Word sh_info;
114+
Elf32_Word sh_addralign;
115+
Elf32_Word sh_entsize;
116+
}elf_section_header_t;
117+
118+
typedef struct elf_program_header
119+
{
120+
Elf32_Word p_type;
121+
Elf32_Off p_offset;
122+
Elf32_Addr p_vaddr;
123+
Elf32_Addr p_paddr;
124+
Elf32_Word p_filesz;
125+
Elf32_Word p_memsz;
126+
Elf32_Word p_flags;
127+
Elf32_Word p_align;
128+
}elf_program_header_t;
129+
130+
void load_elf();
131+
132+
#endif /*__ELF_LOADER_H__*/

src/include/list.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ void list_destroy(list_t * list);
4242
void listnode_destroy(listnode_t * node);
4343

4444
int list_contain(list_t * list, void * val);
45+
int list_contain_str(list_t* list, char* str);
4546

4647
listnode_t * list_get_node_by_index(list_t * list, int index);
4748
void * list_remove_by_index(list_t * list, int index);

0 commit comments

Comments
 (0)