]> git.dujemihanovic.xyz Git - nameless-os.git/commitdiff
Merge branch 'ps2-driver' into mm origin/mm
authorDuje Mihanović <duje.mihanovic@skole.hr>
Mon, 22 Aug 2022 20:11:21 +0000 (22:11 +0200)
committerDuje Mihanović <duje.mihanovic@skole.hr>
Mon, 22 Aug 2022 20:11:21 +0000 (22:11 +0200)
1  2 
boot/x86/stage3/Makefile
kernel/Makefile
kernel/drivers/Makefile
kernel/drivers/input/Makefile
kernel/include/arch/x86/bitflags.h
kernel/include/arch/x86/input/ps2.h
kernel/kernel/kernel.c

index cfe2189dbef18e5152972d6b01d4e354fa759d31,0000000000000000000000000000000000000000..25b026536ea4baf52c26b68a6ee9413f33fc85f6
mode 100644,000000..100644
--- /dev/null
@@@ -1,26 -1,0 +1,26 @@@
- LDFLAGS_BASE = -ffreestanding -nostdlib -g -lgcc -T stage3.ld -flto
 +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
 +
 +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 b510e802636d9de0a49ce5ce27d0d10dd85f6948,0000000000000000000000000000000000000000..8bb12d83f070c44c38e33bdaf5001336f6844c46
mode 100644,000000..100644
--- /dev/null
@@@ -1,27 -1,0 +1,27 @@@
- LDFLAGS_BASE = -ffreestanding -nostdlib -lgcc -g -flto -T arch/x86/linker.ld
 +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 -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
index 76d86aafc1e4d8bd2975fed141cb7c34d08cdcac,0000000000000000000000000000000000000000..c7a361936c166a7416490209c77811a908cb6ca8
mode 100644,000000..100644
--- /dev/null
@@@ -1,1 -1,0 +1,2 @@@
++include drivers/input/Makefile
 +include drivers/irq/Makefile
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..7577b5270e181fd28256c47f1baba242b51c178c
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,1 @@@
++KERNEL_OBJ += drivers/input/ps2.o
index 0000000000000000000000000000000000000000,377f730126428f706873722f2a8c3c10a1241cf0..377f730126428f706873722f2a8c3c10a1241cf0
mode 000000,100644..100644
--- /dev/null
index 0000000000000000000000000000000000000000,55858bfd2ff6413e73dbc0f008ac1dd0b250c47e..55858bfd2ff6413e73dbc0f008ac1dd0b250c47e
mode 000000,100644..100644
--- /dev/null
index 64e64ae45b01f0c805018aa51bac6bb868439a39,0000000000000000000000000000000000000000..b198fcf49e4fc6b034c5d7e987bd8e1729680b6a
mode 100644,000000..100644
--- /dev/null
@@@ -1,97 -1,0 +1,110 @@@
 +#include <kprint.h>
 +#include <io.h>
 +#include <irq/idt.h>
 +#include <irq/interrupt.h>
 +#include <irq/i8259a.h>
++#include <input/ps2.h>
 +#include <stdint.h>
 +#include <mm/paging.h>
 +#include <panic.h>
 +
 +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; i<mmap_size; i++) {
 +              kprintq(mmap[i].base, 1);
 +              kprintc('|', VGA_LIGHT_GRAY, VGA_BLACK);
 +              kprintq(mmap[i].length, 1);
 +              kprintc('|', VGA_LIGHT_GRAY, VGA_BLACK);
 +              kprintd(mmap[i].type, 1);
 +              kprintc('|', VGA_LIGHT_GRAY, VGA_BLACK);
 +              kprintd(mmap[i].attrib, 1);
 +              kprintc('|', VGA_LIGHT_GRAY, VGA_BLACK);
 +              kprintc('\n', VGA_LIGHT_GRAY, VGA_BLACK);
 +      }
 +}
 +
 +/* Small handler for double faults. Will be put elsewhere eventually. */
 +int double_fault_handler(struct interrupt_frame *frame)
 +{
 +      kprint("Double fault occurred!\n", VGA_BRIGHT_RED, VGA_BLACK);
 +      kprint("EAX: ", VGA_LIGHT_GRAY, VGA_BLACK);
 +      kprintd(frame->eax, 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);
 +}