From: Duje Mihanović Date: Mon, 22 Aug 2022 20:11:21 +0000 (+0200) Subject: Merge branch 'ps2-driver' into mm X-Git-Url: http://git.dujemihanovic.xyz/img/static/git-favicon.png?a=commitdiff_plain;h=refs%2Fremotes%2Forigin%2Fmm;p=nameless-os.git Merge branch 'ps2-driver' into mm --- 96b81920dce6c169f32fc4d5b724b4046ea9bfcd diff --cc boot/x86/stage3/Makefile index cfe2189,0000000..25b0265 mode 100644,000000..100644 --- a/boot/x86/stage3/Makefile +++ b/boot/x86/stage3/Makefile @@@ -1,26 -1,0 +1,26 @@@ +STAGE3_OBJ = loader.o elf.o paging.o prekernel.o + +ASFLAGS_BASE = -f elf -g dwarf2 -DGIT_REVISION=\"$(GIT_REV)\" +CFLAGS_BASE = -ffreestanding -nostdlib -DGIT_REVISION=\"$(GIT_REV)\" -g \ + -Og - LDFLAGS_BASE = -ffreestanding -nostdlib -g -lgcc -T stage3.ld -flto ++LDFLAGS_BASE = -ffreestanding -nostdlib -g -lgcc -T stage3.ld + +default: LOADER.BIN loader.elf + +loader.elf: $(STAGE3_OBJ) + $(REAL_CC) $(LDFLAGS_BASE) $(LDFLAGS) -Wl,--oformat=elf32-i386 $^ -o $@ + +LOADER.BIN: $(STAGE3_OBJ) + $(REAL_CC) $(LDFLAGS_BASE) $(LDFLAGS) $^ -o $@ + +# Implicit rules +%.o: %.c + $(REAL_CC) $(CFLAGS_BASE) $(CFLAGS) -c $< -o $@ + +%.o: %.s + $(AS) $(ASFLAGS_BASE) $(ASFLAGS) $< -o $@ + +clean: + -rm -f $(STAGE3_OBJ) LOADER.BIN loader.elf + +.PHONY: default clean diff --cc kernel/Makefile index b510e80,0000000..8bb12d8 mode 100644,000000..100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@@ -1,27 -1,0 +1,27 @@@ +include arch/x86/Makefile +include drivers/Makefile +include kernel/Makefile + +ASFLAGS_BASE = -f elf -g dwarf2 +CFLAGS_BASE = -fgnu89-inline -ffreestanding -nostdlib -Iinclude \ + -Iinclude/arch/x86 -g -DGIT_COMMIT=\"$(GIT_REV)\" \ + -Og - LDFLAGS_BASE = -ffreestanding -nostdlib -lgcc -g -flto -T arch/x86/linker.ld ++LDFLAGS_BASE = -ffreestanding -nostdlib -lgcc -g -T arch/x86/linker.ld + +kernel.elf kernel.dbg: $(KERNEL_OBJ) + $(REAL_CC) $(LDFLAGS_BASE) $(LDFLAGS) $^ -o $@ + $(CROSS_COMPILE)objcopy --only-keep-debug kernel.elf kernel.dbg + $(CROSS_COMPILE)objcopy --add-gnu-debuglink=kernel.dbg kernel.elf + $(CROSS_COMPILE)strip --strip-unneeded kernel.elf + +clean: + -rm $(KERNEL_OBJ) kernel.elf kernel.dbg + +# Implicit rules +%.o: %.c + $(REAL_CC) $(CFLAGS_BASE) $(CFLAGS) -c $< -o $@ + +%.o: %.s + $(AS) $(ASFLAGS_BASE) $(ASFLAGS) $< -o $@ + +.PHONY: clean diff --cc kernel/drivers/Makefile index 76d86aa,0000000..c7a3619 mode 100644,000000..100644 --- a/kernel/drivers/Makefile +++ b/kernel/drivers/Makefile @@@ -1,1 -1,0 +1,2 @@@ ++include drivers/input/Makefile +include drivers/irq/Makefile diff --cc kernel/drivers/input/Makefile index 0000000,0000000..7577b52 new file mode 100644 --- /dev/null +++ b/kernel/drivers/input/Makefile @@@ -1,0 -1,0 +1,1 @@@ ++KERNEL_OBJ += drivers/input/ps2.o diff --cc kernel/include/arch/x86/bitflags.h index 0000000,377f730..377f730 mode 000000,100644..100644 --- a/kernel/include/arch/x86/bitflags.h +++ b/kernel/include/arch/x86/bitflags.h diff --cc kernel/include/arch/x86/input/ps2.h index 0000000,55858bf..55858bf mode 000000,100644..100644 --- a/kernel/include/arch/x86/input/ps2.h +++ b/kernel/include/arch/x86/input/ps2.h diff --cc kernel/kernel/kernel.c index 64e64ae,0000000..b198fcf mode 100644,000000..100644 --- a/kernel/kernel/kernel.c +++ b/kernel/kernel/kernel.c @@@ -1,97 -1,0 +1,110 @@@ +#include +#include +#include +#include +#include ++#include +#include +#include +#include + +struct idt_descriptor idt[256] __attribute__((aligned(0x10))); +struct idtr idtr __attribute__((aligned(0x10))); +extern void (*_int_handler_table[48])(void); + +struct e820_map { + uint64_t base; + uint64_t length; + uint32_t type; + uint32_t attrib; +}; + +void print_e820(struct e820_map *mmap, int mmap_size) +{ + kprint(" Base | Length | Type | Attrib |\n", VGA_LIGHT_GRAY, VGA_BLACK); + kprint("------------------------------------------------------------\n", VGA_LIGHT_GRAY, VGA_BLACK); + for (int i=0; ieax, 1); + kprintc(' ', VGA_LIGHT_GRAY, VGA_BLACK); + kprint("EBX: ", VGA_LIGHT_GRAY, VGA_BLACK); + kprintd(frame->ebx, 1); + kprintc(' ', VGA_LIGHT_GRAY, VGA_BLACK); + kprint("ECX: ", VGA_LIGHT_GRAY, VGA_BLACK); + kprintd(frame->ecx, 1); + kprintc(' ', VGA_LIGHT_GRAY, VGA_BLACK); + kprint("EDX: ", VGA_LIGHT_GRAY, VGA_BLACK); + kprintd(frame->edx, 1); + kprintc('\n', VGA_LIGHT_GRAY, VGA_BLACK); + kprint("EBP: ", VGA_LIGHT_GRAY, VGA_BLACK); + kprintd(frame->ebp, 1); + kprintc(' ', VGA_LIGHT_GRAY, VGA_BLACK); + kprint("ESP: ", VGA_LIGHT_GRAY, VGA_BLACK); + kprintd(frame->esp, 1); + kprintc('\n', VGA_LIGHT_GRAY, VGA_BLACK); + kprint("ESI: ", VGA_LIGHT_GRAY, VGA_BLACK); + kprintd(frame->esi, 1); + kprintc(' ', VGA_LIGHT_GRAY, VGA_BLACK); + kprint("EDI: ", VGA_LIGHT_GRAY, VGA_BLACK); + kprintd(frame->edi, 1); + kprintc('\n', VGA_LIGHT_GRAY, VGA_BLACK); + kprint("EIP: ", VGA_LIGHT_GRAY, VGA_BLACK); + kprintd(frame->eip, 1); + kprintc(' ', VGA_LIGHT_GRAY, VGA_BLACK); + kprint("EFLAGS: ", VGA_LIGHT_GRAY, VGA_BLACK); + kprintd(frame->eflags, 1); + kprintc('\n', VGA_LIGHT_GRAY, VGA_BLACK); + PANIC("double fault"); +} + +void kmain(struct e820_map *mmap, int mmap_size) +{ + vga_initialize(); + kprint("Welcome to Nameless OS!\nRunning revision: ", VGA_LIGHT_GRAY, VGA_BLACK); + kprint(GIT_COMMIT, VGA_LIGHT_GRAY, VGA_BLACK); + kprint("\n", VGA_LIGHT_GRAY, VGA_BLACK); + kprint("BIOS memory map:\n", VGA_LIGHT_GRAY, VGA_BLACK); + print_e820(mmap, mmap_size); + kprint("Preparing IDT...\n", VGA_LIGHT_GRAY, VGA_BLACK); + for (int i=0; i<48; i++) { + idt_set_descriptor(idt, i, 0x8, _int_handler_table[i], IDT_INTERRUPT_GATE, 0); + } + kprint("IDT prepared, loading...\n", VGA_LIGHT_GRAY, VGA_BLACK); + populate_idtr(&idtr, idt); + load_idt(idtr); + kprint("Setting up interrupts...\n", VGA_LIGHT_GRAY, VGA_BLACK); + register_interrupt(8, &double_fault_handler); + pic_init(0x20, 0x28); + pic_mask_all(); + asm volatile ("sti"); ++ kprint("Initializing PS/2...\n", VGA_LIGHT_GRAY, VGA_BLACK); ++ int ret = ps2_initialize(); ++ switch (ret) { ++ case -1: ++ kprint("No PS/2 devices found or something is faulty\n", VGA_LIGHT_GRAY, VGA_BLACK); ++ break; ++ case 0: ++ kprint("One PS/2 device found\n", VGA_LIGHT_GRAY, VGA_BLACK); ++ break; ++ case 1: ++ kprint("Two PS/2 devices found\n", VGA_LIGHT_GRAY, VGA_BLACK); ++ } + kprint("All done\n", VGA_LIGHT_GRAY, VGA_BLACK); + while(1); +}