From f1dee4bc58e4bfb97a1b41831c5d4fc327882991 Mon Sep 17 00:00:00 2001 From: Nic Gaffney Date: Mon, 5 Feb 2024 22:28:34 -0600 Subject: random shit --- bochs/dblog.txt | 46 +++++++++ bochs/log.txt | 254 ++++++++++++++++++++++++++++++++++++++++++++++ notes.txt | 23 +++++ src/boot/boot.s | 1 + src/include/idt.h | 5 +- src/include/kernel.h | 3 + src/kernel/idt.c | 29 +++--- src/kernel/kernel.c | 10 ++ src/kernel/stub_table.asm | 33 ++++++ 9 files changed, 383 insertions(+), 21 deletions(-) create mode 100644 bochs/dblog.txt create mode 100644 bochs/log.txt create mode 100644 notes.txt create mode 100644 src/include/kernel.h create mode 100644 src/kernel/stub_table.asm diff --git a/bochs/dblog.txt b/bochs/dblog.txt new file mode 100644 index 0000000..95f70d9 --- /dev/null +++ b/bochs/dblog.txt @@ -0,0 +1,46 @@ +Next at t=0 +(0) [0x0000fffffff0] f000:fff0 (unk. ctxt): jmpf 0xf000:e05b ; ea5be000f0 +c +(0) Magic breakpoint +Next at t=75345490 +(0) [0x0000001008af] 0008:00000000001008af (unk. ctxt): cli ; fa +info cpu +CPU0: +rax: 00000000_00000000 +rbx: 00000000_00010000 +rcx: 00000000_0000000f +rdx: 00000000_000b8f9e +rsp: 00000000_00107030 +rbp: 00000000_00000000 +rsi: 00000000_00000000 +rdi: 00000000_00000000 +r8 : 00000000_00000000 +r9 : 00000000_00000000 +r10: 00000000_00000000 +r11: 00000000_00000000 +r12: 00000000_00000000 +r13: 00000000_00000000 +r14: 00000000_00000000 +r15: 00000000_00000000 +rip: 00000000_001008af +eflags 0x00000002: id vip vif ac vm rf nt IOPL=0 of df if tf sf zf af pf cf +MM[0]: 00000000_00000000 +MM[1]: 00000000_00000000 +MM[2]: 00000000_00000000 +MM[3]: 00000000_00000000 +MM[4]: 00000000_00000000 +MM[5]: 00000000_00000000 +MM[6]: 00000000_00000000 +MM[7]: 00000000_00000000 +The CPU doesn't support AVX state ! +info gdt +Global Descriptor Table (base=0x0000000000000000, limit=23): +GDT[0x0000]=??? descriptor hi=0x00000000, lo=0x00000000 +GDT[0x0008]=Code segment, base=0x00000000, limit=0x3fffffff, Execute/Read, Non-Conforming, Accessed, 32-bit +GDT[0x0010]=Data segment, base=0x00000000, limit=0x3fffffff, Read/Write, Accessed +You can list individual entries with 'info gdt [NUM]' or groups with 'info gdt [NUM] [NUM]' +info idt +Interrupt Descriptor Table (base=0x000000000007fffe, limit=0): +You can list individual entries with 'info idt [NUM]' or groups with 'info idt [NUM] [NUM]' +exit +(0).[75345490] [0x0000001008af] 0008:00000000001008af (unk. ctxt): cli ; fa diff --git a/bochs/log.txt b/bochs/log.txt new file mode 100644 index 0000000..0d53794 --- /dev/null +++ b/bochs/log.txt @@ -0,0 +1,254 @@ +00000000000i[ ] Bochs x86 Emulator 2.7 +00000000000i[ ] Built from SVN snapshot on August 1, 2021 +00000000000i[ ] Timestamp: Sun Aug 1 10:07:00 CEST 2021 +00000000000i[ ] System configuration +00000000000i[ ] processors: 1 (cores=1, HT threads=1) +00000000000i[ ] A20 line support: yes +00000000000i[ ] IPS is set to 4000000 +00000000000i[ ] CPU configuration +00000000000i[ ] SMP support: yes, quantum=16 +00000000000i[ ] level: 6 +00000000000i[ ] APIC support: xapic +00000000000i[ ] FPU support: yes +00000000000i[ ] MMX support: yes +00000000000i[ ] 3dnow! support: no +00000000000i[ ] SEP support: yes +00000000000i[ ] SIMD support: sse2 +00000000000i[ ] XSAVE support: no +00000000000i[ ] AES support: no +00000000000i[ ] SHA support: no +00000000000i[ ] MOVBE support: no +00000000000i[ ] ADX support: no +00000000000i[ ] x86-64 support: yes +00000000000i[ ] 1G paging support: no +00000000000i[ ] MWAIT support: yes +00000000000i[ ] Optimization configuration +00000000000i[ ] RepeatSpeedups support: yes +00000000000i[ ] Fast function calls: yes +00000000000i[ ] Handlers Chaining speedups: no +00000000000i[ ] Devices configuration +00000000000i[ ] PCI support: i440FX i430FX i440BX +00000000000i[ ] Network devices support: E1000 +00000000000i[ ] Sound support: no +00000000000i[ ] USB support: UHCI OHCI EHCI xHCI +00000000000i[ ] VGA extension support: vbe +00000000000i[IMG ] Disk image modules +00000000000i[IMG ] flat concat sparse dll growing undoable volatile vmware3 +00000000000i[IMG ] vmware4 vbox vpc vvfat +00000000000i[NETCTL] Networking modules +00000000000i[NETCTL] null vnet linux slirp socket tuntap vde +00000000000i[USBCTL] Pluggable USB devices +00000000000i[USBCTL] floppy mouse tablet keypad keyboard hub disk cdrom +00000000000i[USBCTL] printer +00000000000i[MEM0 ] allocated memory at 0x7f2d9a15d010. after alignment, vector=0x7f2d9a15e000 +00000000000i[MEM0 ] 32.00MB +00000000000i[MEM0 ] mem block size = 0x00020000, blocks=256 +00000000000i[MEM0 ] rom at 0xfffe0000/131072 ('/usr/share/bochs/BIOS-bochs-latest') +00000000000i[DEV ] will paste characters every 100 iodev timer ticks +00000000000i[PLUGIN] init_dev of 'vga' plugin device by virtual method +00000000000i[MEM0 ] Register memory access handlers: 0x0000000a0000 - 0x0000000bffff +00000000000i[VGA ] interval=200000, mode=realtime +00000000000i[VGA ] VSYNC using standard mode +00000000000i[MEM0 ] rom at 0xc0000/38400 ('/usr/share/bochs/VGABIOS-lgpl-latest') +00000000000i[PLUGIN] init_dev of 'pci' plugin device by virtual method +00000000000i[DEV ] i440FX PMC present at device 0, function 0 +00000000000i[PLUGIN] init_dev of 'pci2isa' plugin device by virtual method +00000000000i[DEV ] PIIX3 PCI-to-ISA bridge present at device 1, function 0 +00000000000i[PLUGIN] init_dev of 'cmos' plugin device by virtual method +00000000000i[CMOS ] Using local time for initial clock +00000000000i[CMOS ] Setting initial clock to: Wed Jan 24 16:03:24 2024 (time0=1706133804) +00000000000i[PLUGIN] init_dev of 'dma' plugin device by virtual method +00000000000i[DMA ] channel 4 used by cascade +00000000000i[PLUGIN] init_dev of 'pic' plugin device by virtual method +00000000000i[PLUGIN] init_dev of 'pit' plugin device by virtual method +00000000000i[PLUGIN] init_dev of 'floppy' plugin device by virtual method +00000000000i[DMA ] channel 2 used by Floppy Drive +00000000000i[FLOPPY] Using boot sequence cdrom, none, none +00000000000i[FLOPPY] Floppy boot signature check is enabled +00000000000i[PLUGIN] init_dev of 'acpi' plugin device by virtual method +00000000000i[DEV ] ACPI Controller present at device 1, function 3 +00000000000i[PLUGIN] init_dev of 'hpet' plugin device by virtual method +00000000000i[HPET ] initializing HPET +00000000000i[MEM0 ] Register memory access handlers: 0x0000fed00000 - 0x0000fed003ff +00000000000i[PLUGIN] init_dev of 'ioapic' plugin device by virtual method +00000000000i[IOAPIC] initializing I/O APIC +00000000000i[MEM0 ] Register memory access handlers: 0x0000fec00000 - 0x0000fec00fff +00000000000i[IOAPIC] IOAPIC enabled (base address = 0xfec00000) +00000000000i[PLUGIN] init_dev of 'keyboard' plugin device by virtual method +00000000000i[PLUGIN] init_dev of 'harddrv' plugin device by virtual method +00000000000i[HD ] CD on ata0-1: 'out/gftos.iso' +00000000000i[CD1 ] load cdrom with path='out/gftos.iso' +00000000000i[CD1 ] Opening image file as a cd. +00000000000i[HD ] Media present in CD-ROM drive +00000000000i[HD ] Capacity is 10140 sectors (19.80 MB) +00000000000i[PLUGIN] init_dev of 'pci_ide' plugin device by virtual method +00000000000i[DEV ] PIIX3 PCI IDE controller present at device 1, function 1 +00000000000i[PLUGIN] init_dev of 'unmapped' plugin device by virtual method +00000000000i[PLUGIN] init_dev of 'biosdev' plugin device by virtual method +00000000000i[PLUGIN] init_dev of 'speaker' plugin device by virtual method +00000000000e[PCSPK ] Failed to open /dev/console: Permission denied +00000000000e[PCSPK ] Deactivating beep on console +00000000000i[PLUGIN] init_dev of 'extfpuirq' plugin device by virtual method +00000000000i[PLUGIN] init_dev of 'parallel' plugin device by virtual method +00000000000i[PAR ] parallel port 1 at 0x0378 irq 7 +00000000000i[PLUGIN] init_dev of 'serial' plugin device by virtual method +00000000000i[SER ] com1 at 0x03f8 irq 4 (mode: null) +00000000000i[PLUGIN] init_dev of 'iodebug' plugin device by virtual method +00000000000i[PLUGIN] init_dev of 'usb_uhci' plugin device by virtual method +00000000000i[DEV ] USB UHCI present at device 1, function 2 +00000000000i[UHCI ] USB UHCI initialized +00000000000i[PLUGIN] register state of 'vga' plugin device by virtual method +00000000000i[PLUGIN] register state of 'pci' plugin device by virtual method +00000000000i[PLUGIN] register state of 'pci2isa' plugin device by virtual method +00000000000i[PLUGIN] register state of 'cmos' plugin device by virtual method +00000000000i[PLUGIN] register state of 'dma' plugin device by virtual method +00000000000i[PLUGIN] register state of 'pic' plugin device by virtual method +00000000000i[PLUGIN] register state of 'pit' plugin device by virtual method +00000000000i[PLUGIN] register state of 'floppy' plugin device by virtual method +00000000000i[PLUGIN] register state of 'unmapped' plugin device by virtual method +00000000000i[PLUGIN] register state of 'biosdev' plugin device by virtual method +00000000000i[PLUGIN] register state of 'speaker' plugin device by virtual method +00000000000i[PLUGIN] register state of 'extfpuirq' plugin device by virtual method +00000000000i[PLUGIN] register state of 'parallel' plugin device by virtual method +00000000000i[PLUGIN] register state of 'serial' plugin device by virtual method +00000000000i[PLUGIN] register state of 'iodebug' plugin device by virtual method +00000000000i[PLUGIN] register state of 'usb_uhci' plugin device by virtual method +00000000000i[PLUGIN] register state of 'acpi' plugin device by virtual method +00000000000i[PLUGIN] register state of 'hpet' plugin device by virtual method +00000000000i[PLUGIN] register state of 'ioapic' plugin device by virtual method +00000000000i[PLUGIN] register state of 'keyboard' plugin device by virtual method +00000000000i[PLUGIN] register state of 'harddrv' plugin device by virtual method +00000000000i[PLUGIN] register state of 'pci_ide' plugin device by virtual method +00000000000i[SYS ] bx_pc_system_c::Reset(HARDWARE) called +00000000000i[CPU0 ] cpu hardware reset +00000000000i[APIC0 ] allocate APIC id=0 (MMIO enabled) to 0x0000fee00000 +00000000000i[CPU0 ] CPU[0] is the bootstrap processor +00000000000i[CPU0 ] CPUID[0x00000000]: 00000005 756e6547 6c65746e 49656e69 +00000000000i[CPU0 ] CPUID[0x00000001]: 00000633 00010800 00002008 1fcbfbff +00000000000i[CPU0 ] CPUID[0x00000002]: 00410601 00000000 00000000 00000000 +00000000000i[CPU0 ] CPUID[0x00000003]: 00000000 00000000 00000000 00000000 +00000000000i[CPU0 ] CPUID[0x00000004]: 00000000 00000000 00000000 00000000 +00000000000i[CPU0 ] CPUID[0x00000005]: 00000040 00000040 00000003 00000020 +00000000000i[CPU0 ] CPUID[0x80000000]: 80000008 00000000 00000000 00000000 +00000000000i[CPU0 ] CPUID[0x80000001]: 00000000 00000000 00000101 2a100000 +00000000000i[CPU0 ] CPUID[0x80000002]: 20202020 20202020 20202020 6e492020 +00000000000i[CPU0 ] CPUID[0x80000003]: 286c6574 50202952 69746e65 52286d75 +00000000000i[CPU0 ] CPUID[0x80000004]: 20342029 20555043 20202020 00202020 +00000000000i[CPU0 ] CPUID[0x80000005]: 01ff01ff 01ff01ff 40020140 40020140 +00000000000i[CPU0 ] CPUID[0x80000006]: 00000000 42004200 02008140 00000000 +00000000000i[CPU0 ] CPUID[0x80000007]: 00000000 00000000 00000000 00000000 +00000000000i[CPU0 ] CPUID[0x80000008]: 00003028 00000000 00000000 00000000 +00000000000i[CPU0 ] CPU Features supported: +00000000000i[CPU0 ] x87 +00000000000i[CPU0 ] 486ni +00000000000i[CPU0 ] pentium_ni +00000000000i[CPU0 ] p6ni +00000000000i[CPU0 ] mmx +00000000000i[CPU0 ] debugext +00000000000i[CPU0 ] vme +00000000000i[CPU0 ] pse +00000000000i[CPU0 ] pae +00000000000i[CPU0 ] pge +00000000000i[CPU0 ] pse36 +00000000000i[CPU0 ] mtrr +00000000000i[CPU0 ] pat +00000000000i[CPU0 ] sysenter_sysexit +00000000000i[CPU0 ] clflush +00000000000i[CPU0 ] sse +00000000000i[CPU0 ] sse2 +00000000000i[CPU0 ] mwait +00000000000i[CPU0 ] longmode +00000000000i[CPU0 ] lm_lahf_sahf +00000000000i[CPU0 ] nx +00000000000i[CPU0 ] cmpxhg16b +00000000000i[CPU0 ] rdtscp +00000000000i[CPU0 ] ffxsr +00000000000i[CPU0 ] xapic +00000000000i[PLUGIN] reset of 'vga' plugin device by virtual method +00000000000i[PLUGIN] reset of 'pci' plugin device by virtual method +00000000000i[PLUGIN] reset of 'pci2isa' plugin device by virtual method +00000000000i[PLUGIN] reset of 'cmos' plugin device by virtual method +00000000000i[PLUGIN] reset of 'dma' plugin device by virtual method +00000000000i[PLUGIN] reset of 'pic' plugin device by virtual method +00000000000i[PLUGIN] reset of 'pit' plugin device by virtual method +00000000000i[PLUGIN] reset of 'floppy' plugin device by virtual method +00000000000i[PLUGIN] reset of 'acpi' plugin device by virtual method +00000000000i[PLUGIN] reset of 'hpet' plugin device by virtual method +00000000000i[PLUGIN] reset of 'ioapic' plugin device by virtual method +00000000000i[PLUGIN] reset of 'keyboard' plugin device by virtual method +00000000000i[PLUGIN] reset of 'harddrv' plugin device by virtual method +00000000000i[PLUGIN] reset of 'pci_ide' plugin device by virtual method +00000000000i[PLUGIN] reset of 'unmapped' plugin device by virtual method +00000000000i[PLUGIN] reset of 'biosdev' plugin device by virtual method +00000000000i[PLUGIN] reset of 'speaker' plugin device by virtual method +00000000000i[PLUGIN] reset of 'extfpuirq' plugin device by virtual method +00000000000i[PLUGIN] reset of 'parallel' plugin device by virtual method +00000000000i[PLUGIN] reset of 'serial' plugin device by virtual method +00000000000i[PLUGIN] reset of 'iodebug' plugin device by virtual method +00000000000i[PLUGIN] reset of 'usb_uhci' plugin device by virtual method +00000000000i[ ] Using debugger log file bochs/dblog.txt +00000000000i[ ] set SIGINT handler to bx_debug_ctrlc_handler +00000004662i[BIOS ] $Revision: 14314 $ $Date: 2021-07-14 18:10:19 +0200 (Wed, 14 Jul 2021) $ +00000318056i[KBD ] reset-disable command received +00000320838i[BIOS ] Starting rombios32 +00000321276i[BIOS ] Shutdown flag 0 +00000321874i[BIOS ] ram_size=0x02000000 +00000322306i[BIOS ] ram_end=32MB +00000363087i[BIOS ] Found 1 cpu(s) +00000376740i[BIOS ] bios_table_addr: 0x000f9d98 end=0x000fcc00 +00000704556i[PCI ] i440FX PMC write to PAM register 59 (TLB Flush) +00001032491i[P2ISA ] PCI IRQ routing: PIRQA# set to 0x0b +00001032515i[P2ISA ] PCI IRQ routing: PIRQB# set to 0x09 +00001032539i[P2ISA ] PCI IRQ routing: PIRQC# set to 0x0b +00001032563i[P2ISA ] PCI IRQ routing: PIRQD# set to 0x09 +00001032573i[P2ISA ] write: ELCR2 = 0x0a +00001033342i[BIOS ] PIIX3/PIIX4 init: elcr=00 0a +00001047018i[BIOS ] PCI: bus=0 devfn=0x00: vendor_id=0x8086 device_id=0x1237 class=0x0600 +00001049362i[BIOS ] PCI: bus=0 devfn=0x08: vendor_id=0x8086 device_id=0x7000 class=0x0601 +00001051545i[BIOS ] PCI: bus=0 devfn=0x09: vendor_id=0x8086 device_id=0x7010 class=0x0101 +00001051780i[PIDE ] BAR #4: i/o base address = 0xc000 +00001052396i[BIOS ] region 4: 0x0000c000 +00001054431i[BIOS ] PCI: bus=0 devfn=0x0a: vendor_id=0x8086 device_id=0x7020 class=0x0c03 +00001054644i[UHCI ] BAR #4: i/o base address = 0xc020 +00001055260i[BIOS ] region 4: 0x0000c020 +00001055388i[UHCI ] new IRQ line = 9 +00001057310i[BIOS ] PCI: bus=0 devfn=0x0b: vendor_id=0x8086 device_id=0x7113 class=0x0680 +00001057586i[ACPI ] new IRQ line = 11 +00001057600i[ACPI ] new IRQ line = 9 +00001057628i[ACPI ] new PM base address: 0xb000 +00001057642i[ACPI ] new SM base address: 0xb100 +00001057670i[PCI ] setting SMRAM control register to 0x4a +00001221805i[CPU0 ] Enter to System Management Mode +00001221815i[CPU0 ] RSM: Resuming from System Management Mode +00001385871i[PCI ] setting SMRAM control register to 0x0a +00001412536i[BIOS ] MP table addr=0x000f9e70 MPC table addr=0x000f9da0 size=0xc8 +00001414243i[BIOS ] SMBIOS table addr=0x000f9e80 +00001416332i[BIOS ] ACPI tables: RSDP addr=0x000f9fa0 ACPI DATA addr=0x01ff0000 size=0xff8 +00001419316i[BIOS ] Firmware waking vector 0x1ff00cc +00001421570i[PCI ] i440FX PMC write to PAM register 59 (TLB Flush) +00001422300i[BIOS ] bios_table_cur_addr: 0x000f9fc4 +00001540420i[VBIOS ] VGABios $Id: vgabios.c 288 2021-05-28 19:05:28Z vruppert $ +00001543145i[VBIOS ] VBE Bios $Id: vbe.c 292 2021-06-03 12:24:22Z vruppert $ +00005159561i[BIOS ] IDE time out +00017586850i[BIOS ] Booting from 07c0:0000 +00075345490i[CPU0 ] [75345490] Stopped on MAGIC BREAKPOINT +00075345490i[ ] dbg: Quit +00075345490i[CPU0 ] CPU is in protected mode (active) +00075345490i[CPU0 ] CS.mode = 32 bit +00075345490i[CPU0 ] SS.mode = 32 bit +00075345490i[CPU0 ] EFER = 0x00000000 +00075345490i[CPU0 ] | EAX=00000000 EBX=00010000 ECX=0000000f EDX=000b8f9e +00075345490i[CPU0 ] | ESP=00107030 EBP=00000000 ESI=00000000 EDI=00000000 +00075345490i[CPU0 ] | IOPL=0 id vip vif ac vm rf nt of df if tf sf zf af pf cf +00075345490i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D +00075345490i[CPU0 ] | CS:0008( 0001| 0| 0) 00000000 3fffffff 1 1 +00075345490i[CPU0 ] | DS:0010( 0002| 0| 0) 00000000 3fffffff 1 1 +00075345490i[CPU0 ] | SS:0010( 0002| 0| 0) 00000000 3fffffff 1 1 +00075345490i[CPU0 ] | ES:0010( 0002| 0| 0) 00000000 3fffffff 1 1 +00075345490i[CPU0 ] | FS:0010( 0002| 0| 0) 00000000 3fffffff 1 1 +00075345490i[CPU0 ] | GS:0010( 0002| 0| 0) 00000000 3fffffff 1 1 +00075345490i[CPU0 ] | EIP=001008af (001008af) +00075345490i[CPU0 ] | CR0=0x60000011 CR2=0x00000000 +00075345490i[CPU0 ] | CR3=0x00000000 CR4=0x00000000 +00075345490i[CMOS ] Last time is 1706133822 (Wed Jan 24 16:03:42 2024) +00075345490i[SIM ] quit_sim called with exit code 0 diff --git a/notes.txt b/notes.txt new file mode 100644 index 0000000..9016799 --- /dev/null +++ b/notes.txt @@ -0,0 +1,23 @@ + /* Defenitions: + * Segment: + * A logically contiguous chunk of memory with consistent properties from the cpus perspective + * - Just a bunch of memory dedicated for a specific purpose + * Segment Register: + * A register of the CPU that refers to a segment for a particular purpose (CS, DS, SS, ES) + * or for general use. (FS, GS) + * - Code segment, Data segment, ... + * Segment Selector: + * A reference to a descriptor, which you can load into a segment register; the selector is an offset + * into a descriptor table pointing to one of its entries. + * These entries are typically 8 bytes long, therefore + * bits 3 and up only declare the descriptor table entry offset + * bit 2 specifies GDT or LDT + * bits 0-1 declare ring level that needs to correspond to the descriptor table entry's DPL field. + * GENERAL PROTECTION FAULT if it doesn't + * If it does correspond then the CPL level of the selector used is changed accordingly + * - A pointer to an entry in the DT + * Segment Descriptor: + * An entry in a descriptor table. + * These are a binary data structure that tells the CPU the attributes of a given segment + * - A binary number that describes a segment + */ diff --git a/src/boot/boot.s b/src/boot/boot.s index 22d32f3..8df5c6b 100644 --- a/src/boot/boot.s +++ b/src/boot/boot.s @@ -47,6 +47,7 @@ _start: extern get_idtr call get_idtr lidt [idtr] + sti [bits 32] extern kernel_main diff --git a/src/include/idt.h b/src/include/idt.h index b8413b8..78d736b 100644 --- a/src/include/idt.h +++ b/src/include/idt.h @@ -9,9 +9,6 @@ typedef struct Gate_Descriptor { uint16_t offset_high; } __attribute__((packed)) Gate_Descriptor_t; -typedef Gate_Descriptor_t *IDT_t; - -Gate_Descriptor_t make_gate(uint32_t offset, uint8_t segment_selector, - uint8_t attrs); +void make_gate(uint32_t offset, uint8_t attrs, uint8_t vec); void get_idtr(); diff --git a/src/include/kernel.h b/src/include/kernel.h new file mode 100644 index 0000000..2310647 --- /dev/null +++ b/src/include/kernel.h @@ -0,0 +1,3 @@ +#pragma once + +void kernel_panic(const char *); diff --git a/src/kernel/idt.c b/src/kernel/idt.c index f3fea4f..2805889 100644 --- a/src/kernel/idt.c +++ b/src/kernel/idt.c @@ -2,27 +2,22 @@ #include "gdt.h" #include -IDT_t idt = (IDT_t)0x7fffe; +static Gate_Descriptor_t idt[256]; extern GDTR_t idtr; void get_idtr() { - int base = 0x7fffe; - uint8_t code_seg = (0b1000 << 3) | 0b000; - - // idtr.size = sizeof(Gate_Descriptor_t) * n - 1; - idtr.size = 0; - idtr.offset = base; + idtr.offset = (uintptr_t)&idt[0]; + idtr.size = sizeof(Gate_Descriptor_t) * 256 - 1; + for (uint8_t vec = 0; vec < 32; vec++) { + make_gate(stub_table[vec], 0x8E, vec); + } } -Gate_Descriptor_t make_gate(uint32_t offset, uint8_t segment_selector, - uint8_t type) { - Gate_Descriptor_t ret = (Gate_Descriptor_t){ - .offset_low = offset, - .reserved = 0, - .attrs = (0b1000 << 4) | type, - .offset_high = offset >> 16, - .segment_selector = segment_selector, - }; +void make_gate(uint32_t offset, uint8_t attrs, uint8_t vec) { + Gate_Descriptor_t *descriptor = &idt[vec]; - return ret; + descriptor->offset_low = offset & 0xFFFF; + descriptor->attrs = (0b1000 << 4) | attrs; + descriptor->offset_high = offset >> 16, descriptor->segment_selector = 0x08; + descriptor->reserved = 0; } diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 1fca95b..b582e85 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -1,3 +1,4 @@ +#include "kernel.h" #include "print.h" #if defined(__linux__) @@ -40,9 +41,18 @@ void motd() { printf("%c", 188); } +void kernel_panic(const char *error) { + print_set_color(PRINT_COLOR_BLACK, PRINT_COLOR_RED); + print_clear(); + printf(" PANIC! ERROR: %s", error); + for (;;) + ; +} + void kernel_main(void) { print_clear(); motd(); + /* kernel_panic("test_panic."); */ // for (int r = 0; r < 24; r++) { // for (int c = 0; c < 80; c += 3) { // int color = (r + c) % 15 + 1; diff --git a/src/kernel/stub_table.asm b/src/kernel/stub_table.asm new file mode 100644 index 0000000..9901cea --- /dev/null +++ b/src/kernel/stub_table.asm @@ -0,0 +1,33 @@ +extern exception_handler +isr_no_err_stub 0 +isr_no_err_stub 0 +isr_no_err_stub 0 +isr_no_err_stub 0 +isr_no_err_stub 0 +isr_no_err_stub 0 +isr_no_err_stub 0 +isr_no_err_stub 0 +isr_err_stub 0 +isr_no_err_stub 0 +isr_err_stub 0 +isr_err_stub 0 +isr_err_stub 0 +isr_err_stub 0 +isr_err_stub 0 +isr_no_err_stub 0 +isr_no_err_stub 0 +isr_err_stub 0 +isr_no_err_stub 0 +isr_no_err_stub 0 +isr_no_err_stub 0 +isr_no_err_stub 0 +isr_no_err_stub 0 +isr_no_err_stub 0 +isr_no_err_stub 0 +isr_no_err_stub 0 +isr_no_err_stub 0 +isr_no_err_stub 0 +isr_no_err_stub 0 +isr_no_err_stub 0 +isr_err_stub 0 +isr_no_err_stub 0 -- cgit v1.2.3