CeDOS - Commit 488c3c36

Some code restructuring
Celina Sophie Kalus
Sun, 31 Dec 2017 18:51:52 +0100
23 files changed, 94 insertions(+), 49 deletions(-)
M boot/boot.sboot/boot.s

@@ -107,7 +107,7 @@ mov %eax, %gs

mov %eax, %ss # jump to second stage code - ljmp $0x08, $_ss_start + ljmp $0x08, $__SS_START .code16 error:
M boot/makefileboot/makefile

@@ -3,8 +3,3 @@

.PHONY: build build: boot.s > $(GCC_PREFIX)as -o $(GLOBAL_BUILD)/boot.o boot.s - -.PHONY: rebuild -rebuild: -> $(MAKE) clear -> $(MAKE) build
M kernel/driv_keyboard.ckernel/drivers/keyboard.c

@@ -1,6 +1,6 @@

-#include "driv_keyboard.h" -#include "os_interrupts.h" -#include "driv_pic.h" +#include "keyboard.h" +#include "../os_interrupts.h" +#include "pic.h" #include "assembly.h"
M kernel/driv_pic.ckernel/drivers/pic.c

@@ -1,4 +1,4 @@

-#include "driv_pic.h" +#include "pic.h" #include "assembly.h" #include "common.h"
A kernel/drivers/makefile

@@ -0,0 +1,27 @@

+.RECIPEPREFIX = > + +S_OBJECTS = $(patsubst %.s,$(LOCAL_BUILD)/%.s.o,$(wildcard *.s)) +C_OBJECTS = $(patsubst %.c,$(LOCAL_BUILD)/%.c.o,$(wildcard *.c)) +OBJECTS = $(S_OBJECTS) $(C_OBJECTS) + +LOCAL_BUILD = $(GLOBAL_BUILD)/drivers + +SUBDIRS = $(wildcard */.) + +.PHONY: build +build: folder $(SUBDIRS) $(OBJECTS) +> $(GCC_PREFIX)ld $(wildcard $(LOCAL_BUILD)/*.o) -r -o $(GLOBAL_BUILD)/drivers.o --oformat elf32-i386 + +.PHONY: folder +folder: +> @mkdir $(LOCAL_BUILD) 2> /dev/null; true + +.PHONY: $(SUBDIRS) +$(SUBDIRS): +> make -C $@ GLOBAL_BUILD=$(LOCAL_BUILD) build + +$(LOCAL_BUILD)/%.s.o: %.s +> $(GCC_PREFIX)as -o $@ $< + +$(LOCAL_BUILD)/%.c.o: %.c $(wildcard *.h) +> $(GCC_PREFIX)gcc -c -I$(INCLUDE_DIR) --prefix=$(GCC_PREFIX) $(GCC_OPTIONS) -o $@ $<
M kernel/makefilekernel/makefile

@@ -4,14 +4,21 @@ S_OBJECTS = $(patsubst %.s,$(LOCAL_BUILD)/%.s.o,$(wildcard *.s))

C_OBJECTS = $(patsubst %.c,$(LOCAL_BUILD)/%.c.o,$(wildcard *.c)) OBJECTS = $(S_OBJECTS) $(C_OBJECTS) +LOCAL_BUILD = $(GLOBAL_BUILD)/kernel + +SUBDIRS = $(wildcard */.) + .PHONY: build -build: $(OBJECTS) -> $(GCC_PREFIX)ld $^ -r -T link.txt -o $(GLOBAL_BUILD)/kernel.o --oformat elf32-i386 +build: folder $(SUBDIRS) $(OBJECTS) +> $(GCC_PREFIX)ld $(LOCAL_BUILD)/*.o -r -e _kernel_start -Map=$(DEBUG_DIR)/kernel_map.txt -o $(GLOBAL_BUILD)/kernel.o --oformat elf32-i386 + +.PHONY: folder +folder: +> @mkdir $(LOCAL_BUILD) 2> /dev/null; true -.PHONY: rebuild -rebuild: -> $(MAKE) clear -> $(MAKE) build +.PHONY: $(SUBDIRS) +$(SUBDIRS): +> make -C $@ GLOBAL_BUILD=$(LOCAL_BUILD) build $(LOCAL_BUILD)/%.s.o: %.s > $(GCC_PREFIX)as -o $@ $<
M kernel/os_entry.skernel/os_entry.s

@@ -1,6 +1,6 @@

.section .text -.global _kernel_start -_kernel_start: +.global __KERNEL_START +__KERNEL_START: # move stack to kernel space mov $__KERNEL_STACK_ADDR, %eax mov %eax, %esp
M kernel/os_interrupts.ckernel/os_interrupts.c

@@ -1,5 +1,5 @@

#include "os_interrupts.h" -#include "driv_text.h" +#include "drivers/text.h" #define HARDWARE_INTERRUPT (0b10001110) #define SYSCALL_INTERRUPT (0b11101110)

@@ -47,7 +47,7 @@ sizeof(IDT),

IDT }; -void interrupts_init(void) { +int interrupts_init(void) { for (uint32_t i = 0; i < array_sizeof(IDT); i++) { switch (i) { case 0x03:

@@ -60,6 +60,8 @@ default:

install_interrupt(i, default_isr, 0x08, HARDWARE_INTERRUPT); break; } + + return 1; } __asm__ volatile (
M kernel/os_interrupts.hkernel/os_interrupts.h

@@ -22,6 +22,6 @@ typedef struct {

} INTERRUPT_FRAME; -void interrupts_init(void); +int interrupts_init(void); #endif
M kernel/os_main.ckernel/os_main.c

@@ -1,22 +1,29 @@

-#include "driv_text.h" +#include "drivers/text.h" #include "os_interrupts.h" -#include "driv_pic.h" +#include "drivers/pic.h" #include "os_scheduler.h" int os_init(void) { + text_init(); + text_write("TTY output initialized.\n"); + + text_write("Initializing PIC..."); pic_init(); + text_write("done.\n"); + text_write("Initializing interrupts..."); interrupts_init(); - - text_init(); + text_write("done.\n"); + + text_write("Initialization finished.\n--------------\n"); } int os_main(void) { - const char* string[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }; + //const char* string[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }; - text_write("Hallo! :)"); - + text_write("Starting scheduler.\n"); sched_exec(); + text_write("Main procedure terminating.\n"); return 0; }
M kernel/os_scheduler.ckernel/os_scheduler.c

@@ -1,6 +1,6 @@

#include "os_scheduler.h" #include "os_paging.h" -#include "driv_text.h" +#include "drivers/text.h" /*! * Executes a task.

@@ -12,7 +12,11 @@

map_range_to(page_dir, (VIRT_ADDR)0x00000000, (PHYS_ADDR)0x00000000, PAGE_ENTRY_COUNT, 0b000000000011); // will not work because lower memory not mapped - text_write("i did it :)\n"); - while(1) {} + text_write("Successfully switched to new page directory.\n"); + + return 0; +} +int sched_init(void) { + return 1; }
M kernel/os_scheduler.hkernel/os_scheduler.h

@@ -13,4 +13,6 @@ * Executes a task.

*/ ProcessID sched_exec(void); +int sched_init(void); + #endif
M makefilemakefile

@@ -14,21 +14,17 @@ GLOBAL_BUILD = $(CURRENT_DIR)/build/release

GCC_OPTIONS = -O1 -Wno-write-strings -Qn -Wall -Wextra -fno-exceptions -nostdlib -nostartfiles -ffreestanding -mgeneral-regs-only endif -export GLOBAL_BUILD export GCC_OPTIONS -export LOCAL_BUILD = $(GLOBAL_BUILD) +LOCAL_BUILD = $(GLOBAL_BUILD) .PHONY: build build: > @mkdir $(GLOBAL_BUILD) 2> /dev/null; true -> @mkdir $(GLOBAL_BUILD)/boot 2> /dev/null; true -> @mkdir $(GLOBAL_BUILD)/second_stage 2> /dev/null; true -> @mkdir $(GLOBAL_BUILD)/kernel 2> /dev/null; true -> $(MAKE) LOCAL_BUILD=$(GLOBAL_BUILD)/boot -C boot build -> $(MAKE) LOCAL_BUILD=$(GLOBAL_BUILD)/second_stage -C second_stage build -> $(MAKE) LOCAL_BUILD=$(GLOBAL_BUILD)/kernel -C kernel build -> $(GCC_PREFIX)ld $(wildcard $(GLOBAL_BUILD)/*.o) -T link.txt -Map=$(DEBUG_DIR)/mapfile.txt -o build/base.o +> $(MAKE) GLOBAL_BUILD=$(LOCAL_BUILD) -C boot build +> $(MAKE) GLOBAL_BUILD=$(LOCAL_BUILD) -C second_stage build +> $(MAKE) GLOBAL_BUILD=$(LOCAL_BUILD) -C kernel build +> $(GCC_PREFIX)ld $(GLOBAL_BUILD)/*.o -T link.txt -Map=$(DEBUG_DIR)/mapfile.txt -o build/base.o > $(GCC_PREFIX)objcopy --only-keep-debug build/base.o $(DEBUG_DIR)/base.sym > $(GCC_PREFIX)objcopy -O binary build/base.o build/base.img
M second_stage/entry.ssecond_stage/entry.s

@@ -1,6 +1,6 @@

.section .text -.global _ss_start -_ss_start: +.global __SS_START +__SS_START: # copy the kernel code to 0x00100000 call copy_kernel

@@ -17,7 +17,7 @@ or $0x80000010, %eax

movl %eax, %cr0 # jump to kernel code - ljmp $8, $__KERNEL_VMA + ljmp $8, $__KERNEL_START # loop until the heat death of the universe loop:
M second_stage/makefilesecond_stage/makefile

@@ -4,14 +4,19 @@ S_OBJECTS = $(patsubst %.s,$(LOCAL_BUILD)/%.s.o,$(wildcard *.s))

C_OBJECTS = $(patsubst %.c,$(LOCAL_BUILD)/%.c.o,$(wildcard *.c)) OBJECTS = $(S_OBJECTS) $(C_OBJECTS) +LOCAL_BUILD = $(GLOBAL_BUILD)/second_stage + .PHONY: build -build: $(OBJECTS) -> $(GCC_PREFIX)ld $^ -r -T link.txt -o $(GLOBAL_BUILD)/second_stage.o --oformat elf32-i386 +build: folder $(SUBDIRS) $(OBJECTS) +> $(GCC_PREFIX)ld $(wildcard $(LOCAL_BUILD)/*.o) -r -T link.txt -o $(GLOBAL_BUILD)/second_stage.o --oformat elf32-i386 + +.PHONY: folder +folder: +> @mkdir $(LOCAL_BUILD) 2> /dev/null; true -.PHONY: rebuild -rebuild: -> $(MAKE) clear -> $(MAKE) build +.PHONY: $(SUBDIRS) +$(SUBDIRS): +> make -C $@ GLOBAL_BUILD=$(LOCAL_BUILD) build $(LOCAL_BUILD)/%.s.o: %.s > $(GCC_PREFIX)as -o $@ $<