Skip to content

Commit a648544

Browse files
committed
Major update
* Made the kernel higher half * Implemented PMM * Implemented Paging * Implemented dynamic memory allocator * Implemented stack tracing with symbol lookup * Split boot.s to boot.asm and multiboot.s * Added serialprintf() to print formatted string to serial port * Updated link.ld * Updated exception handler to print stack trace after an exception occurs * Added new script get_symbols.sh to get symbols from the kernel and put them into symbols.c * Updated kernel.c * Incremented kernel version * Updated README.md
1 parent e580440 commit a648544

File tree

28 files changed

+1608
-93
lines changed

28 files changed

+1608
-93
lines changed

Makefile

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ SRCDIR=src/
33
INCLUDEDIR=$(SRCDIR)/include/
44
BACKUPDIR=$(SRCDIR)/../../BACKUP/
55
GRUBDIR=
6+
SCRIPTSDIR=$(SRCDIR)/scripts/
67

78
CC=$(TOOLDIR)/i686-elf-gcc
89
CFLAGS= -I$(INCLUDEDIR) -I/usr/include -nostdlib -lgcc -fno-builtin -fno-exceptions -fno-leading-underscore -Wno-write-strings -m32 -g
@@ -34,7 +35,8 @@ PROJECT=SEOS
3435
EXECUTABLE=$(PROJECT).elf
3536
ISOFILE=$(PROJECT).iso
3637

37-
OBJECTS= $(SRCDIR)/boot/boot.o \
38+
OBJECTS= $(SRCDIR)/boot/multiboot.o \
39+
$(SRCDIR)/boot/boot.o \
3840
$(SRCDIR)/drivers/io/ports.o \
3941
$(SRCDIR)/drivers/power/reboot.o \
4042
$(SRCDIR)/drivers/cpu/gdt.o \
@@ -51,19 +53,35 @@ OBJECTS= $(SRCDIR)/boot/boot.o \
5153
$(SRCDIR)/common/libs/string.o \
5254
$(SRCDIR)/common/libs/printf.o \
5355
$(SRCDIR)/common/libs/bit.o \
56+
$(SRCDIR)/common/libs/symbols.o \
57+
$(SRCDIR)/common/libs/sym.o \
5458
$(SRCDIR)/drivers/video/vga_text.o \
5559
$(SRCDIR)/drivers/io/serial.o \
60+
$(SRCDIR)/memory/kheap.o \
61+
$(SRCDIR)/memory/paging.o \
62+
$(SRCDIR)/memory/pmm.o \
5663
$(SRCDIR)/kernel/kernel.o
5764

5865
all: kernel iso
5966

6067
kernel: $(EXECUTABLE)
6168
iso: $(ISOFILE)
6269

63-
$(EXECUTABLE): $(OBJECTS)
70+
$(EXECUTABLE): get_symboltable $(OBJECTS)
6471
@echo '[LD] $@'
6572
@$(LD) $(LDFLAGS) -o $@ $(OBJECTS)
6673

74+
compile_objs: $(OBJECTS)
75+
76+
kernel2:
77+
@make get_symboltable
78+
@make compile_objs
79+
@echo '[LD] $(EXECUTABLE)'
80+
@$(LD) $(LDFLAGS) -o $(EXECUTABLE) $(OBJECTS)
81+
82+
83+
truecompile: clean kernel2 clean_objs kernel2 iso
84+
6785
$(ISOFILE): $(EXECUTABLE)
6886
@echo '[GRUB] $@'
6987
@mkdir -p $(PROJECT)/boot/grub
@@ -92,20 +110,26 @@ $(ISOFILE): $(EXECUTABLE)
92110
@echo '[NASM] $@'
93111
@$(NASM) $(NASMFLAGS) -o $@ $<
94112

95-
run: iso
113+
run: truecompile
96114
$(QEMU) $(QEMUFLAGS)
97115

98-
rund: iso
116+
rund: truecompile
99117
$(QEMU) $(QEMUFLAGS) $(QEMUDFLAGS)
100118

101119
stripd: $(EXECUTABLE)
102120
@$(TOOLDIR)$(OBJCOPY) --only-keep-debug $(EXECUTABLE) debug.sym
103121
@$(TOOLDIR)$(OBJCOPY) $(OBJCOPYFLAGS) $(EXECUTABLE)
104122

105123
forcerun: clean iso run
106-
forcerund: clean iso rund stripd
124+
forcerund: clean iso rund
125+
126+
get_symboltable:
127+
$(SCRIPTSDIR)/get_symbols.sh $(EXECUTABLE) > $(SRCDIR)/common/libs/symbols.c
107128

108-
PHONY: clean
129+
PHONY: clean kernel
109130
clean:
110131
@echo 'Cleaning the source directory...'
111-
@rm $(OBJECTS) $(EXECUTABLE) $(ISOFILE)
132+
@rm -f $(OBJECTS) $(EXECUTABLE) $(ISOFILE)
133+
134+
clean_objs:
135+
@rm -f $(OBJECTS)

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 v2.23.03.6NR.<br>
17+
The current kernel version for SectorOS-RW4 is v2.23.03.7NR.<br>
1818

1919
## ⚙️ Build Steps
2020

docs/changelog.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,23 @@
6262
* Updated system.h
6363
* Incremented kernel version
6464
* Updated Makefile
65+
* Updated README.md
66+
67+
29-03-2023: ??:?? ?? IST v1.23.03.6NR
68+
* New README.md from @harry260 [Thanks]
69+
70+
30-03-2023: 08:01 PM IST v2.23.03.7NR
71+
* Major update
72+
* Made the kernel higher half
73+
* Implemented PMM
74+
* Implemented Paging
75+
* Implemented dynamic memory allocator
76+
* Implemented stack tracing with symbol lookup
77+
* Split boot.s to boot.asm and multiboot.s
78+
* Added serialprintf() to print formatted string to serial port
79+
* Updated link.ld
80+
* Updated exception handler to print stack trace after an exception occurs
81+
* Added new script get_symbols.sh to get symbols from the kernel and put them into symbols.c
82+
* Updated kernel.c
83+
* Incremented kernel version
6584
* Updated README.md

src/backup/symbols.c

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
#include "symbols.h"
2+
3+
symbol_t* get_symDB()
4+
{
5+
static const symbol_t symbols[] = {
6+
"stoc_r", 0xc01017cb, 6,
7+
"init_serial", 0xc01021ba, 360,
8+
"strcpy", 0xc010121c, 69,
9+
"write_serial", 0xc010239a, 55,
10+
"inb", 0xc01000ba, 33,
11+
"krealloc", 0xc01025f7, 25,
12+
"pic_eoi", 0xc0100946, 54,
13+
"kmalloc_p", 0xc0102590, 27,
14+
"register_interru[...]", 0xc0100ae3, 50,
15+
"printf", 0xc0101c9a, 37,
16+
"vsprintf", 0xc0101868, 1074,
17+
"init_paging", 0xc01036bd, 261,
18+
"init_symDB", 0xc0101d18, 24,
19+
"strndup", 0xc0101660, 6,
20+
"kmalloc_a", 0xc0102576, 26,
21+
"stack_trace", 0xc010105b, 92,
22+
"getRealSize", 0xc0102660, 11,
23+
"doesItFit", 0xc010267e, 63,
24+
"stoc", 0xc01016e8, 227,
25+
"init_pit", 0xc010097c, 98,
26+
"is_fmt_letter", 0xc01017f4, 116,
27+
"memcpy", 0xc01011a2, 63,
28+
"kfree", 0xc01025e0, 23,
29+
"free_page", 0xc01035f3, 202,
30+
"init_pic", 0xc0100878, 206,
31+
"setFree", 0xc01026bd, 43,
32+
"malloc", 0xc0102891, 726,
33+
"get_nsyms", 0xc0101d30, 65,
34+
"sleep", 0xc0100a93, 80,
35+
"init_pmm", 0xc0103ccc, 138,
36+
"addToList", 0xc0102760, 65,
37+
"itoa", 0xc010144a, 198,
38+
"isspace", 0xc01015b2, 62,
39+
"pit_callback", 0xc01009de, 32,
40+
"printsym", 0xc0101e32, 91,
41+
"switch_page_dir", 0xc01037c2, 60,
42+
"chbc", 0xc01015f0, 68,
43+
"get_symbol", 0xc0101db6, 124,
44+
"gdt_setGate", 0xc010022e, 193,
45+
"read_serial", 0xc0102349, 42,
46+
"init_text", 0xc0101e8d, 60,
47+
"isFree", 0xc01026e8, 27,
48+
"kmalloc_c", 0xc0102433, 100,
49+
"enable_paging", 0xc01037fe, 54,
50+
"kmalloc_ap", 0xc01025ab, 27,
51+
"kernelmain", 0xc0103fdb, 275,
52+
"virt2phys", 0xc0103289, 198,
53+
"inw", 0xc01000db, 37,
54+
"get_offset", 0xc0101d71, 69,
55+
"set_idtGate", 0xc0100800, 106,
56+
"calloc", 0xc0103237, 57,
57+
"backtrace", 0xc01010b7, 133,
58+
"text_clear", 0xc0102106, 94,
59+
"text_puts", 0xc010218b, 47,
60+
"pit_chfrequency", 0xc01009fe, 149,
61+
"free_region", 0xc01033f8, 68,
62+
"strcat", 0xc01013fe, 76,
63+
"reboot", 0xc0100123, 29,
64+
"lobyte", 0xc0101ce4, 19,
65+
"kmalloc_int", 0xc0102497, 223,
66+
"text_putc", 0xc0101ff3, 275,
67+
"strstr", 0xc0101393, 107,
68+
"serial_putc", 0xc01023d1, 51,
69+
"free_block", 0xc0103da5, 68,
70+
"strncmp", 0xc0101340, 83,
71+
"cal_tsc", 0xc0103e48, 229,
72+
"inl", 0xc0100100, 35,
73+
"strncpy", 0xc0101261, 145,
74+
"get_symDB", 0xc0101d0e, 10,
75+
"realloc", 0xc0102dbe, 1145,
76+
"init_idt", 0xc0100312, 1262,
77+
"calc_cpu_frequ", 0xc0103f2d, 174,
78+
"scroll", 0xc0101f45, 174,
79+
"memcmp", 0xc010116a, 56,
80+
"init_gdt", 0xc0100140, 238,
81+
"text_chcolor", 0xc0102164, 39,
82+
"ksbrk", 0xc0103834, 189,
83+
"outb", 0xc0100062, 31,
84+
"isEnd", 0xc010266b, 19,
85+
"is_transmit_empty", 0xc0102373, 39,
86+
"strdup", 0xc010165a, 6,
87+
"page_fault_handler", 0xc0103ba8, 292,
88+
"copy_page_table", 0xc0103a1c, 396,
89+
"memset", 0xc01011e1, 59,
90+
"serialprintf", 0xc0101cbf, 37,
91+
"isprint", 0xc0101634, 38,
92+
"move_cursor", 0xc0101ec9, 124,
93+
"isr_handler", 0xc0100b15, 91,
94+
"strcmp", 0xc01012f2, 78,
95+
"sprintf", 0xc01017d1, 35,
96+
"serial_puts", 0xc0102404, 47,
97+
"strsep", 0xc0101666, 130,
98+
"first_free_block", 0xc0103de9, 95,
99+
"disable_interrupts", 0xc0100b8a, 26,
100+
"serial_received", 0xc0102322, 39,
101+
"outw", 0xc0100081, 33,
102+
"alloc_page", 0xc010343c, 439,
103+
"itoa_r", 0xc01015ac, 6,
104+
"bestFit", 0xc01027a1, 107,
105+
"outl", 0xc01000a2, 24,
106+
"getNextBlock", 0xc010285a, 55,
107+
"d_kmalloc", 0xc010334f, 57,
108+
"kmalloc", 0xc01025c6, 26,
109+
"getPrevBlock", 0xc010280c, 78,
110+
"atoi", 0xc0101510, 156,
111+
"init_kheap", 0xc0102610, 80,
112+
"strlen", 0xc010113c, 46,
113+
"alloc_region", 0xc0103388, 112,
114+
"hibyte", 0xc0101cf7, 23,
115+
"enable_interrupts", 0xc0100b70, 26,
116+
"copy_page_dir", 0xc01038f1, 299,
117+
"kcalloc", 0xc0103270, 25,
118+
"kernel_panic", 0xc0101031, 42,
119+
"alloc_block", 0xc0103d56, 79,
120+
"removeFromList", 0xc0102703, 93,
121+
"exception_handler", 0xc0100c80, 474,
122+
"free", 0xc0102b67, 599,
123+
"EOS", 0x0, 0x00
124+
};
125+
return symbols;
126+
}

src/boot/boot.asm

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
VM_START equ 0xC0000000
2+
PDE_IDX equ (VM_START >> 22)
3+
PSE_BIT equ 0x00000010
4+
PG_BIT equ 0x80000000
5+
6+
section .data
7+
align 4096
8+
global TEMP_PAGE_DIR
9+
TEMP_PAGE_DIR:
10+
dd 0x00000083
11+
times (PDE_IDX - 1) dd 0x00000000
12+
dd 0x00000083
13+
times(1024 - PDE_IDX - 1) dd 0x00000000
14+
15+
section .initial_stack, nobits
16+
align 4
17+
stack_bottom:
18+
resb 104856
19+
stack_top:
20+
21+
section .text
22+
global kernel_entry
23+
global low_kernel_entry
24+
low_kernel_entry equ (kernel_entry - VM_START)
25+
kernel_entry:
26+
mov ecx, (TEMP_PAGE_DIR - VM_START)
27+
mov cr3, ecx
28+
29+
mov ecx, cr4
30+
or ecx, PSE_BIT
31+
mov cr4, ecx
32+
33+
mov ecx, cr0
34+
or ecx, PG_BIT
35+
mov cr0, ecx
36+
37+
lea ecx, [high_kernel_entry]
38+
jmp ecx
39+
high_kernel_entry:
40+
mov dword[TEMP_PAGE_DIR], 0
41+
invlpg[0]
42+
43+
mov esp, stack_top
44+
extern kernelmain
45+
46+
xor ebp, ebp
47+
48+
push eax
49+
add ebx, VM_START
50+
push ebx
51+
52+
call kernelmain
53+
54+
loop:
55+
jmp loop

src/boot/boot.s

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/boot/link.ld

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
1-
ENTRY(_start)
1+
ENTRY(kernel_entry)
2+
3+
paddr = 0x100000;
4+
off = 0xC0000000;
5+
vaddr = off + paddr;
26

37
SECTIONS
48
{
5-
. = 1M;
6-
7-
.text BLOCK(4K) : ALIGN(4K)
8-
{
9-
*(.multiboot)
10-
*(.text)
11-
}
12-
.rodata BLOCK(4K) : ALIGN(4K)
13-
{
14-
*(.rodata)
15-
}
16-
.data BLOCK(4K) : ALIGN(4K)
17-
{
18-
*(.data)
19-
}
20-
.bss BLOCK(4K) : ALIGN(4K)
21-
{
22-
*(COMMON)
23-
*(.bss)
24-
}
9+
. = 0xC0100000;
10+
.text ALIGN(4K) : AT(ADDR(.text)-0xC0000000)
11+
{
12+
*(.multiboot)
13+
*(.text)
14+
}
15+
.rodata ALIGN (4K) : AT(ADDR(.rodata)-0xC0000000)
16+
{
17+
*(.rodata)
18+
}
19+
.bss ALIGN(4K) : AT(ADDR(.bss)-0xC0000000)
20+
{
21+
*(.bss)
22+
*(.initial_stack)
23+
}
24+
.data ALIGN(4K) : AT(ADDR(.data)-0xC0000000)
25+
{
26+
*(.data)
27+
}
2528

26-
k_end = .;
27-
}
29+
k_end = .;
30+
/DISCARD/ : { *(.fini_array*) *(.comment) }
31+
}

0 commit comments

Comments
 (0)