Skip to content

Commit 30f8a2c

Browse files
committed
* Formatted some files
* Added errno functions * Added functions to configure GDT and IDT * Implemented interrupt handling * Added PIC driver * Added bochsrc
1 parent 9e7be1d commit 30f8a2c

33 files changed

+2239
-769
lines changed

Makefile

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ OBJCOPY=$(SYSROOT)/bin/i686-elf-objcopy
2222
OBJDUMP=$(SYSROOT)/bin/i686-elf-objdump
2323

2424
QEMU=qemu-system-i386
25-
QEMUFLAGS=-cdrom $(ISOFILE) -m 512M -boot d
26-
QEMUDFLAGS=-s -S -daemonize
25+
QEMUFLAGS=-cdrom $(ISOFILE) -m 512M -boot d -enable-kvm
26+
QEMUDFLAGS=-s -S -daemonize -no-reboot -d int
2727

2828
KERNEL_NAME=arthur
2929
OS_NAME=SectorOS
@@ -36,6 +36,17 @@ OBJECTS= $(SRCDIR)/boot/multiboot2.o \
3636
$(SRCDIR)/kernel/kernel.o \
3737
$(SRCDIR)/common/debug.o \
3838
$(SRCDIR)/common/printf.o \
39+
$(SRCDIR)/common/string.o \
40+
$(SRCDIR)/common/errno.o \
41+
$(SRCDIR)/descriptors/gdt.o \
42+
$(SRCDIR)/descriptors/gdt_helper.o \
43+
$(SRCDIR)/descriptors/idt.o \
44+
$(SRCDIR)/descriptors/idt_helper.o \
45+
$(SRCDIR)/drivers/cpu/pic.o \
46+
$(SRCDIR)/interrupts/exception.o \
47+
$(SRCDIR)/interrupts/exception_helper.o \
48+
$(SRCDIR)/interrupts/interrupt.o \
49+
$(SRCDIR)/interrupts/interrupt_helper.o \
3950
$(SRCDIR)/drivers/io/ports.o \
4051
$(SRCDIR)/drivers/video/textmode.o
4152

@@ -70,6 +81,10 @@ run : $(ISOFILE)
7081
@echo '[QEMU] Running OS...'
7182
@$(QEMU) $(QEMUFLAGS) -serial stdio
7283

84+
rund : $(ISOFILE)
85+
@echo '[QEMU] Debugging OS...'
86+
@$(QEMU) $(QEMUFLAGS) $(QEMUDFLAGS)
87+
7388
PHONY: clean
7489
clean:
7590
@echo 'Cleaning the source directory...'

docs/README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
11
# SectorOS Project
22

3-
SectorOS is a 32bit operating system.
3+
SectorOS is a 32bit operating system.
4+
5+
## Goals
6+
7+
- [ ] Paging implementation
8+
- [ ] Shared memory and swap memory
9+
- [ ] Fully completed network stack
10+
- [ ] Preemptive multitasking
11+
- [ ] GUI
12+
- [ ] VFS
13+
- [ ] SORFS
14+
- [ ] ATA-DMA driver
15+
- [ ] Modules
16+
- [ ] Memory mapping
17+
- [X] Interrupt handling
18+
- [ ] Processes
19+
- [ ] Shell

docs/bochsrc

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# configuration file generated by Bochs
2+
plugin_ctrl: unmapped=1, biosdev=1, speaker=0, extfpuirq=1, parallel=0, serial=1, iodebug=0
3+
config_interface: textconfig
4+
display_library: x
5+
memory: host=32, guest=32
6+
romimage: file="/usr/share/bochs/BIOS-bochs-latest"
7+
vgaromimage: file="/usr/share/bochs/VGABIOS-lgpl-latest"
8+
boot: cdrom
9+
#boot: cdrom, disk
10+
floppy_bootsig_check: disabled=1
11+
# no floppya
12+
# no floppyb
13+
ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
14+
ata0-master: type=cdrom, path="SectorOS.iso", status=inserted, model="Generic 1234", biosdetect=auto, translation=auto
15+
#ata0-slave: type=cdrom, path="disk-x86.img", status=inserted
16+
ata0-slave: type=none
17+
ata1: enabled=0
18+
ata2: enabled=0
19+
ata3: enabled=0
20+
#optromimage1: file="../dist/bootboot.bin", address=0xCB000
21+
#optromimage2: file="initrd.rom", address=0xCF000
22+
pci: enabled=1, chipset=i440fx
23+
vga: extension=vbe, update_freq=10, realtime=1
24+
# cpu: count=4, ips=4000000, model=corei7_ivy_bridge_3770k, reset_on_triple_fault=0, cpuid_limit_winnt=0, ignore_bad_msrs=1, mwait_is_nop=0
25+
# cpuid: level=6, apic=x2apic, simd=avx, aes=1
26+
cpu: ips=400000000, reset_on_triple_fault=0
27+
print_timestamps: enabled=0
28+
debugger_log: -
29+
magic_break: enabled=1
30+
port_e9_hack: enabled=1
31+
private_colormap: enabled=0
32+
clock: sync=realtime, time0=local, rtc_sync=1
33+
# no cmosimage
34+
# no loader
35+
log: -
36+
logprefix: %t%e%d
37+
debug: action=ignore
38+
info: action=report
39+
error: action=report
40+
panic: action=ask
41+
keyboard: type=mf, serial_delay=250, paste_delay=100000, user_shortcut=none
42+
mouse: type=imps2, enabled=0, toggle=ctrl+mbutton
43+
com1: enabled=1, mode=file, dev=/dev/stdout

src/boot/boot.asm

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
section .initial_stack, nobits
22
align 4
33
__KERNEL_STACK_BOTTOM:
4-
resb 104856
4+
resb 104856
55
__KERNEL_STACK_TOP:
66

77

88
section .text
99
global __KERNEL_BOOTSTRAP
1010
extern kernelMain
11+
extern kernel_panic
12+
13+
__KERNEL_ERR_MSG:
14+
db "Reached end of kernel image", 0x00
15+
1116
__KERNEL_BOOTSTRAP:
12-
mov esp,__KERNEL_STACK_TOP
13-
push eax
14-
push ebx
15-
call kernelMain
17+
mov esp,__KERNEL_STACK_TOP
18+
push eax
19+
push ebx
20+
call kernelMain
1621

1722
__KERNEL_EXECUTION_STOP:
18-
cli
19-
hlt
20-
jmp __KERNEL_EXECUTION_STOP
23+
push __KERNEL_ERR_MSG
24+
call kernel_panic
25+
cli
26+
hlt

src/boot/link.ld

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,34 @@ ENTRY(__KERNEL_BOOTSTRAP)
22

33
SECTIONS
44
{
5-
. = 2M;
5+
. = 2M;
66

7-
.multiboot2 BLOCK(4K) : ALIGN(4K)
8-
{
9-
*(.multiboot2)
10-
}
7+
.multiboot2 BLOCK(4K) : ALIGN(4K)
8+
{
9+
*(.multiboot2)
10+
}
1111

12-
.text BLOCK(4K) : ALIGN(4K)
13-
{
14-
*(.text)
15-
}
12+
.text BLOCK(4K) : ALIGN(4K)
13+
{
14+
*(.text)
15+
}
1616

17-
.rodata BLOCK(4K) : ALIGN(4K)
18-
{
19-
*(.rodata)
20-
}
17+
.rodata BLOCK(4K) : ALIGN(4K)
18+
{
19+
*(.rodata)
20+
}
2121

22-
.data BLOCK(4K) : ALIGN(4K)
23-
{
24-
*(.data)
25-
}
22+
.data BLOCK(4K) : ALIGN(4K)
23+
{
24+
*(.data)
25+
}
2626

27-
.bss BLOCK(4K) : ALIGN(4K)
28-
{
29-
*(.initial_stack)
30-
*(COMMON)
31-
*(.bss)
32-
}
27+
.bss BLOCK(4K) : ALIGN(4K)
28+
{
29+
*(.initial_stack)
30+
*(COMMON)
31+
*(.bss)
32+
}
3333

34-
__KERNEL_IMAGE_END = .;
35-
}
34+
__KERNEL_IMAGE_END = .;
35+
}

src/boot/multiboot2.s

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,23 @@
55

66
.section .multiboot2
77
__MULTIBOOT2_HEADER_START:
8-
.long MULTIBOOT2_MAGIC
9-
.long MULTIBOOT2_ARCH
10-
.long __MULTIBOOT2_HEADER_END - __MULTIBOOT2_HEADER_START
11-
.long -(MULTIBOOT2_MAGIC+MULTIBOOT2_ARCH+(__MULTIBOOT2_HEADER_END-__MULTIBOOT2_HEADER_START))
12-
.align 8
8+
.long MULTIBOOT2_MAGIC
9+
.long MULTIBOOT2_ARCH
10+
.long __MULTIBOOT2_HEADER_END - __MULTIBOOT2_HEADER_START
11+
.long -(MULTIBOOT2_MAGIC+MULTIBOOT2_ARCH+(__MULTIBOOT2_HEADER_END-__MULTIBOOT2_HEADER_START))
12+
.align 8
1313

1414
__MULTIBOOT2_TAG_ALIGN_MODULE:
15-
.short 0x06
16-
.short 0x00
17-
.long 8
18-
.align 8
15+
.short 0x06
16+
.short 0x00
17+
.long 8
18+
.align 8
1919

2020
__MULTIBOOT2_TAG_END:
21-
.short 0
22-
.short 0
23-
.long 8
24-
.align 8
21+
.short 0
22+
.short 0
23+
.long 8
24+
.align 8
2525

2626
__MULTIBOOT2_HEADER_END:
27-
28-
// MULTIBOOT2 HEADER END
29-
30-
27+

src/common/debug.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "debug.h"
22
#include "printf.h"
33
#include "textmode.h"
4+
#include "errno.h"
45

56
//TODO: Add support for register printing
67
void kernel_panic(char* message)
@@ -11,6 +12,11 @@ void kernel_panic(char* message)
1112
textmode_puts("\"KERNEL HAS POPPED\"\n\nAn unrecoverable error has been occurred in the kernel. The kernel will be halting...\n\nMessage: ");
1213
textmode_puts(message);
1314
textmode_puts("\n");
15+
int save = get_errno();
16+
const char* errstr = errno_to_str(save);
17+
const char* errfile = get_last_errno_file();
18+
const char* errfunc = get_last_errno_function();
19+
printf("Last occurred error [errno]: %s[%d] \n\t-at %s:%s()\n", errstr, save, errfile, errfunc);
1420

1521
__KERNEL_ASM("cli; hlt");
1622
}
@@ -23,7 +29,13 @@ void kernel_assert(const char* file, int line, const char* statement, bool state
2329
textmode_chattr(15, 4);
2430
textmode_clear();
2531

26-
printf("\"TACTICAL NUKE INCOMING...\"\n\nAn assertion has failed in the kernel. Kernel cannot verify its stability. Therefore, kernel will be halting...\n\nKernel: %s\nFile: %s:%d\nStatement: %s\n", __KERNEL_NAME" v"__KERNEL_VERSION, file, line, statement);
32+
int save = get_errno();
33+
const char * msg = errno_to_str(save);
34+
35+
const char* errfile = get_last_errno_file();
36+
const char* errfunc = get_last_errno_function();
37+
38+
printf("\"TACTICAL NUKE INCOMING...\"\n\nAn assertion has failed in the kernel. Kernel cannot verify its stability. Therefore, kernel will be halting...\n\nKernel: %s\nFile: %s:%d\nStatement: %s\nLast occurred error [errno]: %s[%d] \n\t-at %s:%s()\n", __KERNEL_NAME" v"__KERNEL_VERSION, file, line, statement, msg, save, errfile, errfunc);
2739

2840
__KERNEL_ASM("cli; hlt");
2941
}

src/common/errno.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include "errno.h"
2+
3+
static int errno = 0;
4+
5+
static char errno_file[1024];
6+
static char errno_func[512];
7+
8+
static const char* errno_str[] = {
9+
"No error",
10+
"Invalid arguments",
11+
"Requested data not available",
12+
"Unknown error occurred",
13+
NULL
14+
};
15+
16+
void set_errno(int f_errno, const char* function, const char* file)
17+
{
18+
errno = f_errno;
19+
20+
int i = 0;
21+
22+
for(i = 0; (i < 1024) && (file[i] != 0); i++)
23+
errno_file[i] = file[i];
24+
25+
errno_file[i] = '\0';
26+
27+
i = 0;
28+
29+
for(i = 0; (i < 512) && (function[i] != 0); i++)
30+
errno_func[i] = function[i];
31+
32+
errno_func[i] = '\0';
33+
}
34+
35+
int get_errno()
36+
{
37+
return errno;
38+
}
39+
40+
const char* errno_to_str(int f_errno)
41+
{
42+
return errno_str[f_errno];
43+
}
44+
45+
const char* get_last_errno_file()
46+
{
47+
return errno_file;
48+
}
49+
50+
const char* get_last_errno_function()
51+
{
52+
return errno_func;
53+
}

0 commit comments

Comments
 (0)