diff --git a/.gdbinit b/.gdbinit new file mode 100644 index 0000000..cb7b385 --- /dev/null +++ b/.gdbinit @@ -0,0 +1,3 @@ +set osabi none +target remote 127.0.0.1:1234 +symbol-file ./src/kitty.elf \ No newline at end of file diff --git a/src/Makefile b/src/Makefile index ac921a6..f65e89e 100644 --- a/src/Makefile +++ b/src/Makefile @@ -7,11 +7,21 @@ OBJ = ${C_SOURCES:.c=.o} ${ASM_SOURCES:.asm=.o} CFLAGS = -ffreestanding -fno-stack-protector -z execstack -no-pie -fno-pic ifeq ($(OS),Windows_NT) - host_os = windows - SHELL = cmd - CC = x86_64-elf-gcc - GDB = x86_64-elf-gdb - LD = x86_64-elf-ld + UNAME_S := $(shell uname -s) + ifeq ($(UNAME_S),MSYS_NT-10.0-22631) + $(info MSYS2 detected) + host_os = linux + CC = gcc + GDB = gdb + LD = ld + else + $(info Windows detected) + host_os = windows + SHELL = cmd + CC = x86_64-elf-gcc + GDB = x86_64-elf-gdb + LD = x86_64-elf-ld + endif else UNAME_S := $(shell uname -s) ifeq ($(UNAME_S),Linux) @@ -84,7 +94,7 @@ endif debug: os-image.bin kitty.elf # TODO needs work, change it so that a variable is added for break points #ifeq ($(host_os),windows) - qemu-system-x86_64 -s -S -fda os-image.bin + qemu-system-x86_64 -s -S -d int -fda os-image.bin #else ifeq ($(host_os),linux) # qemu-system-x86_64 -s -S -fda os-image.bin & #endif diff --git a/src/cpu/cpu_options.h b/src/cpu/cpu_options.h index 4412373..4e88591 100644 --- a/src/cpu/cpu_options.h +++ b/src/cpu/cpu_options.h @@ -11,7 +11,7 @@ * * Other defined variables in this file are for use with processor-specific compilation. * - * All other CPU preprocessor definitions (for use in cpu cpu code) should be put in its corresponding header file. + * All other CPU preprocessor definitions (for use in cpu code) should be put in its corresponding header file. */ #if CPU == 1 // x86_64 Processors diff --git a/src/cpu/x86_64/gdt.asm b/src/cpu/x86_64/gdt.asm new file mode 100644 index 0000000..b29e7ee --- /dev/null +++ b/src/cpu/x86_64/gdt.asm @@ -0,0 +1,47 @@ +; Access bits +PRESENT equ 1 << 7 +USER equ 3 << 5 +NOT_SYS equ 1 << 4 +EXEC equ 1 << 3 +DC equ 1 << 2 +RW equ 1 << 1 +ACCESSED equ 1 << 0 + +; Flags bits +GRAN_4K equ 1 << 7 +SZ_32 equ 1 << 6 +LONG_MODE equ 1 << 5 +global GDT +GDT: ; 64 bit GDT, taken from https://wiki.osdev.org/Setting_Up_Long_Mode ; CC0 Licensing (Public Domain) + .Null: equ $ - GDT + dq 0 + .Code: equ $ - GDT + dd 0xFFFF ; Limit & Base (low, bits 0-15) + db 0 ; Base (mid, bits 16-23) + db PRESENT | NOT_SYS | EXEC | RW ; Access + db GRAN_4K | LONG_MODE | 0xF ; Flags & Limit (high, bits 16-19) + db 0 ; Base (high, bits 24-31) + .Data: equ $ - GDT + dd 0xFFFF ; Limit & Base (low, bits 0-15) + db 0 ; Base (mid, bits 16-23) + db PRESENT | NOT_SYS | RW ; Access + db GRAN_4K | SZ_32 | 0xF ; Flags & Limit (high, bits 16-19) + db 0 ; Base (high, bits 24-31) + .UserCode: equ $ - GDT + dd 0xFFFF ; Limit & Base (low, bits 0-15) + db 0 ; Base (mid, bits 16-23) + db PRESENT | USER | NOT_SYS | EXEC | RW ; 0xFA ; Access + db GRAN_4K | LONG_MODE | 0xF ; Flags & Limit (high, bits 16-19) + db 0 ; Base (high, bits 24-31) + .UserData: equ $ - GDT + dd 0xFFFF ; Limit & Base (low, bits 0-15) + db 0 ; Base (mid, bits 16-23) + db PRESENT | USER | NOT_SYS | RW ;0xF2 ; ; Access + db GRAN_4K | SZ_32 | 0xF ; Flags & Limit (high, bits 16-19) + db 0 ; Base (high, bits 24-31) + .TSS: equ $ - GDT + dq 0x0000000000000000 + dq 0x0000000000000000 + .Pointer: + dw $ - GDT - 1 + dq GDT diff --git a/src/cpu/x86_64/gdt.h b/src/cpu/x86_64/gdt.h new file mode 100644 index 0000000..9583ab5 --- /dev/null +++ b/src/cpu/x86_64/gdt.h @@ -0,0 +1,26 @@ +// +// Created by AIDAN on 9/26/2024. +// + +#ifndef KITTY_GDT_H +#define KITTY_GDT_H + +#include "stdint.h" + +struct global_descriptor_table { + uint64_t null; + uint64_t code; + uint64_t data; + uint64_t user_code; + uint64_t user_data; + uint32_t tss_0; + uint32_t tss_1; + uint32_t tss_2; + uint32_t tss_3; + uint16_t size; + uint64_t offset; +}__attribute__ ((packed)); + +extern struct global_descriptor_table GDT; + +#endif //KITTY_GDT_H diff --git a/src/cpu/x86_64/idt.c b/src/cpu/x86_64/idt.c index d662175..b7e4495 100644 --- a/src/cpu/x86_64/idt.c +++ b/src/cpu/x86_64/idt.c @@ -2,288 +2,36 @@ // Created by AIDAN on 2/23/2024. // +#include #include "idt.h" #include "../../driver/video/vga.h" #include "../../util/ascii.h" #include "port.h" +#include "../../kernel/memory.h" -static struct { - uint16_t size; // One less than the size (max entry number, entries start at 0) - uint64_t offset; // address of the IDT -}__attribute__((packed)) idt_descriptor; -/* - * IDT is of a fixed length with 256 entries. sowwy :3; - */ -static struct { - interrupt_gate_descriptor entry_0; - interrupt_gate_descriptor entry_1; - interrupt_gate_descriptor entry_2; - interrupt_gate_descriptor entry_3; - interrupt_gate_descriptor entry_4; - interrupt_gate_descriptor entry_5; - interrupt_gate_descriptor entry_6; - interrupt_gate_descriptor entry_7; - interrupt_gate_descriptor entry_8; - interrupt_gate_descriptor entry_9; - interrupt_gate_descriptor entry_10; - interrupt_gate_descriptor entry_11; - interrupt_gate_descriptor entry_12; - interrupt_gate_descriptor entry_13; - interrupt_gate_descriptor entry_14; - interrupt_gate_descriptor entry_15; - interrupt_gate_descriptor entry_16; - interrupt_gate_descriptor entry_17; - interrupt_gate_descriptor entry_18; - interrupt_gate_descriptor entry_19; - interrupt_gate_descriptor entry_20; - interrupt_gate_descriptor entry_21; - interrupt_gate_descriptor entry_22; - interrupt_gate_descriptor entry_23; - interrupt_gate_descriptor entry_24; - interrupt_gate_descriptor entry_25; - interrupt_gate_descriptor entry_26; - interrupt_gate_descriptor entry_27; - interrupt_gate_descriptor entry_28; - interrupt_gate_descriptor entry_29; - interrupt_gate_descriptor entry_30; - interrupt_gate_descriptor entry_31; - interrupt_gate_descriptor entry_32; - interrupt_gate_descriptor entry_33; - interrupt_gate_descriptor entry_34; - interrupt_gate_descriptor entry_35; - interrupt_gate_descriptor entry_36; - interrupt_gate_descriptor entry_37; - interrupt_gate_descriptor entry_38; - interrupt_gate_descriptor entry_39; - interrupt_gate_descriptor entry_40; - interrupt_gate_descriptor entry_41; - interrupt_gate_descriptor entry_42; - interrupt_gate_descriptor entry_43; - interrupt_gate_descriptor entry_44; - interrupt_gate_descriptor entry_45; - interrupt_gate_descriptor entry_46; - interrupt_gate_descriptor entry_47; - interrupt_gate_descriptor entry_48; - interrupt_gate_descriptor entry_49; - interrupt_gate_descriptor entry_50; - interrupt_gate_descriptor entry_51; - interrupt_gate_descriptor entry_52; - interrupt_gate_descriptor entry_53; - interrupt_gate_descriptor entry_54; - interrupt_gate_descriptor entry_55; - interrupt_gate_descriptor entry_56; - interrupt_gate_descriptor entry_57; - interrupt_gate_descriptor entry_58; - interrupt_gate_descriptor entry_59; - interrupt_gate_descriptor entry_60; - interrupt_gate_descriptor entry_61; - interrupt_gate_descriptor entry_62; - interrupt_gate_descriptor entry_63; - interrupt_gate_descriptor entry_64; - interrupt_gate_descriptor entry_65; - interrupt_gate_descriptor entry_66; - interrupt_gate_descriptor entry_67; - interrupt_gate_descriptor entry_68; - interrupt_gate_descriptor entry_69; - interrupt_gate_descriptor entry_70; - interrupt_gate_descriptor entry_71; - interrupt_gate_descriptor entry_72; - interrupt_gate_descriptor entry_73; - interrupt_gate_descriptor entry_74; - interrupt_gate_descriptor entry_75; - interrupt_gate_descriptor entry_76; - interrupt_gate_descriptor entry_77; - interrupt_gate_descriptor entry_78; - interrupt_gate_descriptor entry_79; - interrupt_gate_descriptor entry_80; - interrupt_gate_descriptor entry_81; - interrupt_gate_descriptor entry_82; - interrupt_gate_descriptor entry_83; - interrupt_gate_descriptor entry_84; - interrupt_gate_descriptor entry_85; - interrupt_gate_descriptor entry_86; - interrupt_gate_descriptor entry_87; - interrupt_gate_descriptor entry_88; - interrupt_gate_descriptor entry_89; - interrupt_gate_descriptor entry_90; - interrupt_gate_descriptor entry_91; - interrupt_gate_descriptor entry_92; - interrupt_gate_descriptor entry_93; - interrupt_gate_descriptor entry_94; - interrupt_gate_descriptor entry_95; - interrupt_gate_descriptor entry_96; - interrupt_gate_descriptor entry_97; - interrupt_gate_descriptor entry_98; - interrupt_gate_descriptor entry_99; - interrupt_gate_descriptor entry_100; - interrupt_gate_descriptor entry_101; - interrupt_gate_descriptor entry_102; - interrupt_gate_descriptor entry_103; - interrupt_gate_descriptor entry_104; - interrupt_gate_descriptor entry_105; - interrupt_gate_descriptor entry_106; - interrupt_gate_descriptor entry_107; - interrupt_gate_descriptor entry_108; - interrupt_gate_descriptor entry_109; - interrupt_gate_descriptor entry_110; - interrupt_gate_descriptor entry_111; - interrupt_gate_descriptor entry_112; - interrupt_gate_descriptor entry_113; - interrupt_gate_descriptor entry_114; - interrupt_gate_descriptor entry_115; - interrupt_gate_descriptor entry_116; - interrupt_gate_descriptor entry_117; - interrupt_gate_descriptor entry_118; - interrupt_gate_descriptor entry_119; - interrupt_gate_descriptor entry_120; - interrupt_gate_descriptor entry_121; - interrupt_gate_descriptor entry_122; - interrupt_gate_descriptor entry_123; - interrupt_gate_descriptor entry_124; - interrupt_gate_descriptor entry_125; - interrupt_gate_descriptor entry_126; - interrupt_gate_descriptor entry_127; - interrupt_gate_descriptor entry_128; - interrupt_gate_descriptor entry_129; - interrupt_gate_descriptor entry_130; - interrupt_gate_descriptor entry_131; - interrupt_gate_descriptor entry_132; - interrupt_gate_descriptor entry_133; - interrupt_gate_descriptor entry_134; - interrupt_gate_descriptor entry_135; - interrupt_gate_descriptor entry_136; - interrupt_gate_descriptor entry_137; - interrupt_gate_descriptor entry_138; - interrupt_gate_descriptor entry_139; - interrupt_gate_descriptor entry_140; - interrupt_gate_descriptor entry_141; - interrupt_gate_descriptor entry_142; - interrupt_gate_descriptor entry_143; - interrupt_gate_descriptor entry_144; - interrupt_gate_descriptor entry_145; - interrupt_gate_descriptor entry_146; - interrupt_gate_descriptor entry_147; - interrupt_gate_descriptor entry_148; - interrupt_gate_descriptor entry_149; - interrupt_gate_descriptor entry_150; - interrupt_gate_descriptor entry_151; - interrupt_gate_descriptor entry_152; - interrupt_gate_descriptor entry_153; - interrupt_gate_descriptor entry_154; - interrupt_gate_descriptor entry_155; - interrupt_gate_descriptor entry_156; - interrupt_gate_descriptor entry_157; - interrupt_gate_descriptor entry_158; - interrupt_gate_descriptor entry_159; - interrupt_gate_descriptor entry_160; - interrupt_gate_descriptor entry_161; - interrupt_gate_descriptor entry_162; - interrupt_gate_descriptor entry_163; - interrupt_gate_descriptor entry_164; - interrupt_gate_descriptor entry_165; - interrupt_gate_descriptor entry_166; - interrupt_gate_descriptor entry_167; - interrupt_gate_descriptor entry_168; - interrupt_gate_descriptor entry_169; - interrupt_gate_descriptor entry_170; - interrupt_gate_descriptor entry_171; - interrupt_gate_descriptor entry_172; - interrupt_gate_descriptor entry_173; - interrupt_gate_descriptor entry_174; - interrupt_gate_descriptor entry_175; - interrupt_gate_descriptor entry_176; - interrupt_gate_descriptor entry_177; - interrupt_gate_descriptor entry_178; - interrupt_gate_descriptor entry_179; - interrupt_gate_descriptor entry_180; - interrupt_gate_descriptor entry_181; - interrupt_gate_descriptor entry_182; - interrupt_gate_descriptor entry_183; - interrupt_gate_descriptor entry_184; - interrupt_gate_descriptor entry_185; - interrupt_gate_descriptor entry_186; - interrupt_gate_descriptor entry_187; - interrupt_gate_descriptor entry_188; - interrupt_gate_descriptor entry_189; - interrupt_gate_descriptor entry_190; - interrupt_gate_descriptor entry_191; - interrupt_gate_descriptor entry_192; - interrupt_gate_descriptor entry_193; - interrupt_gate_descriptor entry_194; - interrupt_gate_descriptor entry_195; - interrupt_gate_descriptor entry_196; - interrupt_gate_descriptor entry_197; - interrupt_gate_descriptor entry_198; - interrupt_gate_descriptor entry_199; - interrupt_gate_descriptor entry_200; - interrupt_gate_descriptor entry_201; - interrupt_gate_descriptor entry_202; - interrupt_gate_descriptor entry_203; - interrupt_gate_descriptor entry_204; - interrupt_gate_descriptor entry_205; - interrupt_gate_descriptor entry_206; - interrupt_gate_descriptor entry_207; - interrupt_gate_descriptor entry_208; - interrupt_gate_descriptor entry_209; - interrupt_gate_descriptor entry_210; - interrupt_gate_descriptor entry_211; - interrupt_gate_descriptor entry_212; - interrupt_gate_descriptor entry_213; - interrupt_gate_descriptor entry_214; - interrupt_gate_descriptor entry_215; - interrupt_gate_descriptor entry_216; - interrupt_gate_descriptor entry_217; - interrupt_gate_descriptor entry_218; - interrupt_gate_descriptor entry_219; - interrupt_gate_descriptor entry_220; - interrupt_gate_descriptor entry_221; - interrupt_gate_descriptor entry_222; - interrupt_gate_descriptor entry_223; - interrupt_gate_descriptor entry_224; - interrupt_gate_descriptor entry_225; - interrupt_gate_descriptor entry_226; - interrupt_gate_descriptor entry_227; - interrupt_gate_descriptor entry_228; - interrupt_gate_descriptor entry_229; - interrupt_gate_descriptor entry_230; - interrupt_gate_descriptor entry_231; - interrupt_gate_descriptor entry_232; - interrupt_gate_descriptor entry_233; - interrupt_gate_descriptor entry_234; - interrupt_gate_descriptor entry_235; - interrupt_gate_descriptor entry_236; - interrupt_gate_descriptor entry_237; - interrupt_gate_descriptor entry_238; - interrupt_gate_descriptor entry_239; - interrupt_gate_descriptor entry_240; - interrupt_gate_descriptor entry_241; - interrupt_gate_descriptor entry_242; - interrupt_gate_descriptor entry_243; - interrupt_gate_descriptor entry_244; - interrupt_gate_descriptor entry_245; - interrupt_gate_descriptor entry_246; - interrupt_gate_descriptor entry_247; - interrupt_gate_descriptor entry_248; - interrupt_gate_descriptor entry_249; - interrupt_gate_descriptor entry_250; - interrupt_gate_descriptor entry_251; - interrupt_gate_descriptor entry_252; - interrupt_gate_descriptor entry_253; - interrupt_gate_descriptor entry_254; - interrupt_gate_descriptor entry_255; -}__attribute((aligned(0x10))) __attribute__((packed)) idt; // if you complain about the IDT code, you will be banned from contributing to the kitty kernel project. - /* * Map a given IDT gate descriptor entry to its corresponding function (Interrupt vector to interrupt function) */ -void modify_descriptor_entry(interrupt_gate_descriptor* gate_descriptor, void* function) { +void modify_descriptor_entry(interrupt_gate_descriptor* gate_descriptor, void* function, bool callable_from_userspace) { (*gate_descriptor).offset_bits_0_15 = ((uint64_t) (function)) & 0xFFFF; (*gate_descriptor).selector = (uint16_t) 0x08; // code is the 2nd GDT entry, see boot sector (*gate_descriptor).ist_offset = 0x00; - (*gate_descriptor).type_dpl_present = 0x8E; + uint8_t type_dpl_present = 0x00; + if (callable_from_userspace) { + type_dpl_present = 0xE0; + } else { + type_dpl_present = 0x80; + } + bool trap_gate = false; // may be a parameter in the future + if (trap_gate) { + type_dpl_present |= 0x0F; + } else { + type_dpl_present |= 0x0E; + } + (*gate_descriptor).type_dpl_present = type_dpl_present; (*gate_descriptor).offset_bits_16_31 = ( (uint64_t) (function) >> 16) & 0xFFFF; (*gate_descriptor).offset_bits_32_63 = ( (uint64_t) (function) >> 32) & 0xFFFFFFFF; (*gate_descriptor).zeroes = 0; @@ -336,263 +84,263 @@ void set_pic_offset() { void init_idt() { // Volume 3 Chapter 6.10 idt_descriptor.offset = (uint64_t) &idt; - idt_descriptor.size = 255 * 8 - 1; - modify_descriptor_entry(&idt.entry_0, isr_0); - modify_descriptor_entry(&idt.entry_1, isr_1); - modify_descriptor_entry(&idt.entry_2, isr_2); - modify_descriptor_entry(&idt.entry_3, isr_3); - modify_descriptor_entry(&idt.entry_4, isr_4); - modify_descriptor_entry(&idt.entry_5, isr_5); - modify_descriptor_entry(&idt.entry_6, isr_6); - modify_descriptor_entry(&idt.entry_7, isr_7); - modify_descriptor_entry(&idt.entry_8, isr_8); - modify_descriptor_entry(&idt.entry_9, isr_9); - modify_descriptor_entry(&idt.entry_10, isr_10); - modify_descriptor_entry(&idt.entry_11, isr_11); - modify_descriptor_entry(&idt.entry_12, isr_12); - modify_descriptor_entry(&idt.entry_13, isr_13); - modify_descriptor_entry(&idt.entry_14, isr_14); - modify_descriptor_entry(&idt.entry_15, isr_15); - modify_descriptor_entry(&idt.entry_16, isr_16); - modify_descriptor_entry(&idt.entry_17, isr_17); - modify_descriptor_entry(&idt.entry_18, isr_18); - modify_descriptor_entry(&idt.entry_19, isr_19); - modify_descriptor_entry(&idt.entry_20, isr_20); - modify_descriptor_entry(&idt.entry_21, isr_21); - modify_descriptor_entry(&idt.entry_22, isr_22); - modify_descriptor_entry(&idt.entry_23, isr_23); - modify_descriptor_entry(&idt.entry_24, isr_24); - modify_descriptor_entry(&idt.entry_25, isr_25); - modify_descriptor_entry(&idt.entry_26, isr_26); - modify_descriptor_entry(&idt.entry_27, isr_27); - modify_descriptor_entry(&idt.entry_28, isr_28); - modify_descriptor_entry(&idt.entry_29, isr_29); - modify_descriptor_entry(&idt.entry_30, isr_30); - modify_descriptor_entry(&idt.entry_31, isr_31); - modify_descriptor_entry(&idt.entry_32, isr_32); - modify_descriptor_entry(&idt.entry_33, isr_33); - modify_descriptor_entry(&idt.entry_34, isr_34); - modify_descriptor_entry(&idt.entry_35, isr_35); - modify_descriptor_entry(&idt.entry_36, isr_36); - modify_descriptor_entry(&idt.entry_37, isr_37); - modify_descriptor_entry(&idt.entry_38, isr_38); - modify_descriptor_entry(&idt.entry_39, isr_39); - modify_descriptor_entry(&idt.entry_40, isr_40); - modify_descriptor_entry(&idt.entry_41, isr_41); - modify_descriptor_entry(&idt.entry_42, isr_42); - modify_descriptor_entry(&idt.entry_43, isr_43); - modify_descriptor_entry(&idt.entry_44, isr_44); - modify_descriptor_entry(&idt.entry_45, isr_45); - modify_descriptor_entry(&idt.entry_46, isr_46); - modify_descriptor_entry(&idt.entry_47, isr_47); - modify_descriptor_entry(&idt.entry_48, isr_48); - modify_descriptor_entry(&idt.entry_49, isr_49); - modify_descriptor_entry(&idt.entry_50, isr_50); - modify_descriptor_entry(&idt.entry_51, isr_51); - modify_descriptor_entry(&idt.entry_52, isr_52); - modify_descriptor_entry(&idt.entry_53, isr_53); - modify_descriptor_entry(&idt.entry_54, isr_54); - modify_descriptor_entry(&idt.entry_55, isr_55); - modify_descriptor_entry(&idt.entry_56, isr_56); - modify_descriptor_entry(&idt.entry_57, isr_57); - modify_descriptor_entry(&idt.entry_58, isr_58); - modify_descriptor_entry(&idt.entry_59, isr_59); - modify_descriptor_entry(&idt.entry_60, isr_60); - modify_descriptor_entry(&idt.entry_61, isr_61); - modify_descriptor_entry(&idt.entry_62, isr_62); - modify_descriptor_entry(&idt.entry_63, isr_63); - modify_descriptor_entry(&idt.entry_64, isr_64); - modify_descriptor_entry(&idt.entry_65, isr_65); - modify_descriptor_entry(&idt.entry_66, isr_66); - modify_descriptor_entry(&idt.entry_67, isr_67); - modify_descriptor_entry(&idt.entry_68, isr_68); - modify_descriptor_entry(&idt.entry_69, isr_69); - modify_descriptor_entry(&idt.entry_70, isr_70); - modify_descriptor_entry(&idt.entry_71, isr_71); - modify_descriptor_entry(&idt.entry_72, isr_72); - modify_descriptor_entry(&idt.entry_73, isr_73); - modify_descriptor_entry(&idt.entry_74, isr_74); - modify_descriptor_entry(&idt.entry_75, isr_75); - modify_descriptor_entry(&idt.entry_76, isr_76); - modify_descriptor_entry(&idt.entry_77, isr_77); - modify_descriptor_entry(&idt.entry_78, isr_78); - modify_descriptor_entry(&idt.entry_79, isr_79); - modify_descriptor_entry(&idt.entry_80, isr_80); - modify_descriptor_entry(&idt.entry_81, isr_81); - modify_descriptor_entry(&idt.entry_82, isr_82); - modify_descriptor_entry(&idt.entry_83, isr_83); - modify_descriptor_entry(&idt.entry_84, isr_84); - modify_descriptor_entry(&idt.entry_85, isr_85); - modify_descriptor_entry(&idt.entry_86, isr_86); - modify_descriptor_entry(&idt.entry_87, isr_87); - modify_descriptor_entry(&idt.entry_88, isr_88); - modify_descriptor_entry(&idt.entry_89, isr_89); - modify_descriptor_entry(&idt.entry_90, isr_90); - modify_descriptor_entry(&idt.entry_91, isr_91); - modify_descriptor_entry(&idt.entry_92, isr_92); - modify_descriptor_entry(&idt.entry_93, isr_93); - modify_descriptor_entry(&idt.entry_94, isr_94); - modify_descriptor_entry(&idt.entry_95, isr_95); - modify_descriptor_entry(&idt.entry_96, isr_96); - modify_descriptor_entry(&idt.entry_97, isr_97); - modify_descriptor_entry(&idt.entry_98, isr_98); - modify_descriptor_entry(&idt.entry_99, isr_99); - modify_descriptor_entry(&idt.entry_100, isr_100); - modify_descriptor_entry(&idt.entry_101, isr_101); - modify_descriptor_entry(&idt.entry_102, isr_102); - modify_descriptor_entry(&idt.entry_103, isr_103); - modify_descriptor_entry(&idt.entry_104, isr_104); - modify_descriptor_entry(&idt.entry_105, isr_105); - modify_descriptor_entry(&idt.entry_106, isr_106); - modify_descriptor_entry(&idt.entry_107, isr_107); - modify_descriptor_entry(&idt.entry_108, isr_108); - modify_descriptor_entry(&idt.entry_109, isr_109); - modify_descriptor_entry(&idt.entry_110, isr_110); - modify_descriptor_entry(&idt.entry_111, isr_111); - modify_descriptor_entry(&idt.entry_112, isr_112); - modify_descriptor_entry(&idt.entry_113, isr_113); - modify_descriptor_entry(&idt.entry_114, isr_114); - modify_descriptor_entry(&idt.entry_115, isr_115); - modify_descriptor_entry(&idt.entry_116, isr_116); - modify_descriptor_entry(&idt.entry_117, isr_117); - modify_descriptor_entry(&idt.entry_118, isr_118); - modify_descriptor_entry(&idt.entry_119, isr_119); - modify_descriptor_entry(&idt.entry_120, isr_120); - modify_descriptor_entry(&idt.entry_121, isr_121); - modify_descriptor_entry(&idt.entry_122, isr_122); - modify_descriptor_entry(&idt.entry_123, isr_123); - modify_descriptor_entry(&idt.entry_124, isr_124); - modify_descriptor_entry(&idt.entry_125, isr_125); - modify_descriptor_entry(&idt.entry_126, isr_126); - modify_descriptor_entry(&idt.entry_127, isr_127); - modify_descriptor_entry(&idt.entry_128, isr_128); - modify_descriptor_entry(&idt.entry_129, isr_129); - modify_descriptor_entry(&idt.entry_130, isr_130); - modify_descriptor_entry(&idt.entry_131, isr_131); - modify_descriptor_entry(&idt.entry_132, isr_132); - modify_descriptor_entry(&idt.entry_133, isr_133); - modify_descriptor_entry(&idt.entry_134, isr_134); - modify_descriptor_entry(&idt.entry_135, isr_135); - modify_descriptor_entry(&idt.entry_136, isr_136); - modify_descriptor_entry(&idt.entry_137, isr_137); - modify_descriptor_entry(&idt.entry_138, isr_138); - modify_descriptor_entry(&idt.entry_139, isr_139); - modify_descriptor_entry(&idt.entry_140, isr_140); - modify_descriptor_entry(&idt.entry_141, isr_141); - modify_descriptor_entry(&idt.entry_142, isr_142); - modify_descriptor_entry(&idt.entry_143, isr_143); - modify_descriptor_entry(&idt.entry_144, isr_144); - modify_descriptor_entry(&idt.entry_145, isr_145); - modify_descriptor_entry(&idt.entry_146, isr_146); - modify_descriptor_entry(&idt.entry_147, isr_147); - modify_descriptor_entry(&idt.entry_148, isr_148); - modify_descriptor_entry(&idt.entry_149, isr_149); - modify_descriptor_entry(&idt.entry_150, isr_150); - modify_descriptor_entry(&idt.entry_151, isr_151); - modify_descriptor_entry(&idt.entry_152, isr_152); - modify_descriptor_entry(&idt.entry_153, isr_153); - modify_descriptor_entry(&idt.entry_154, isr_154); - modify_descriptor_entry(&idt.entry_155, isr_155); - modify_descriptor_entry(&idt.entry_156, isr_156); - modify_descriptor_entry(&idt.entry_157, isr_157); - modify_descriptor_entry(&idt.entry_158, isr_158); - modify_descriptor_entry(&idt.entry_159, isr_159); - modify_descriptor_entry(&idt.entry_160, isr_160); - modify_descriptor_entry(&idt.entry_161, isr_161); - modify_descriptor_entry(&idt.entry_162, isr_162); - modify_descriptor_entry(&idt.entry_163, isr_163); - modify_descriptor_entry(&idt.entry_164, isr_164); - modify_descriptor_entry(&idt.entry_165, isr_165); - modify_descriptor_entry(&idt.entry_166, isr_166); - modify_descriptor_entry(&idt.entry_167, isr_167); - modify_descriptor_entry(&idt.entry_168, isr_168); - modify_descriptor_entry(&idt.entry_169, isr_169); - modify_descriptor_entry(&idt.entry_170, isr_170); - modify_descriptor_entry(&idt.entry_171, isr_171); - modify_descriptor_entry(&idt.entry_172, isr_172); - modify_descriptor_entry(&idt.entry_173, isr_173); - modify_descriptor_entry(&idt.entry_174, isr_174); - modify_descriptor_entry(&idt.entry_175, isr_175); - modify_descriptor_entry(&idt.entry_176, isr_176); - modify_descriptor_entry(&idt.entry_177, isr_177); - modify_descriptor_entry(&idt.entry_178, isr_178); - modify_descriptor_entry(&idt.entry_179, isr_179); - modify_descriptor_entry(&idt.entry_180, isr_180); - modify_descriptor_entry(&idt.entry_181, isr_181); - modify_descriptor_entry(&idt.entry_182, isr_182); - modify_descriptor_entry(&idt.entry_183, isr_183); - modify_descriptor_entry(&idt.entry_184, isr_184); - modify_descriptor_entry(&idt.entry_185, isr_185); - modify_descriptor_entry(&idt.entry_186, isr_186); - modify_descriptor_entry(&idt.entry_187, isr_187); - modify_descriptor_entry(&idt.entry_188, isr_188); - modify_descriptor_entry(&idt.entry_189, isr_189); - modify_descriptor_entry(&idt.entry_190, isr_190); - modify_descriptor_entry(&idt.entry_191, isr_191); - modify_descriptor_entry(&idt.entry_192, isr_192); - modify_descriptor_entry(&idt.entry_193, isr_193); - modify_descriptor_entry(&idt.entry_194, isr_194); - modify_descriptor_entry(&idt.entry_195, isr_195); - modify_descriptor_entry(&idt.entry_196, isr_196); - modify_descriptor_entry(&idt.entry_197, isr_197); - modify_descriptor_entry(&idt.entry_198, isr_198); - modify_descriptor_entry(&idt.entry_199, isr_199); - modify_descriptor_entry(&idt.entry_200, isr_200); - modify_descriptor_entry(&idt.entry_201, isr_201); - modify_descriptor_entry(&idt.entry_202, isr_202); - modify_descriptor_entry(&idt.entry_203, isr_203); - modify_descriptor_entry(&idt.entry_204, isr_204); - modify_descriptor_entry(&idt.entry_205, isr_205); - modify_descriptor_entry(&idt.entry_206, isr_206); - modify_descriptor_entry(&idt.entry_207, isr_207); - modify_descriptor_entry(&idt.entry_208, isr_208); - modify_descriptor_entry(&idt.entry_209, isr_209); - modify_descriptor_entry(&idt.entry_210, isr_210); - modify_descriptor_entry(&idt.entry_211, isr_211); - modify_descriptor_entry(&idt.entry_212, isr_212); - modify_descriptor_entry(&idt.entry_213, isr_213); - modify_descriptor_entry(&idt.entry_214, isr_214); - modify_descriptor_entry(&idt.entry_215, isr_215); - modify_descriptor_entry(&idt.entry_216, isr_216); - modify_descriptor_entry(&idt.entry_217, isr_217); - modify_descriptor_entry(&idt.entry_218, isr_218); - modify_descriptor_entry(&idt.entry_219, isr_219); - modify_descriptor_entry(&idt.entry_220, isr_220); - modify_descriptor_entry(&idt.entry_221, isr_221); - modify_descriptor_entry(&idt.entry_222, isr_222); - modify_descriptor_entry(&idt.entry_223, isr_223); - modify_descriptor_entry(&idt.entry_224, isr_224); - modify_descriptor_entry(&idt.entry_225, isr_225); - modify_descriptor_entry(&idt.entry_226, isr_226); - modify_descriptor_entry(&idt.entry_227, isr_227); - modify_descriptor_entry(&idt.entry_228, isr_228); - modify_descriptor_entry(&idt.entry_229, isr_229); - modify_descriptor_entry(&idt.entry_230, isr_230); - modify_descriptor_entry(&idt.entry_231, isr_231); - modify_descriptor_entry(&idt.entry_232, isr_232); - modify_descriptor_entry(&idt.entry_233, isr_233); - modify_descriptor_entry(&idt.entry_234, isr_234); - modify_descriptor_entry(&idt.entry_235, isr_235); - modify_descriptor_entry(&idt.entry_236, isr_236); - modify_descriptor_entry(&idt.entry_237, isr_237); - modify_descriptor_entry(&idt.entry_238, isr_238); - modify_descriptor_entry(&idt.entry_239, isr_239); - modify_descriptor_entry(&idt.entry_240, isr_240); - modify_descriptor_entry(&idt.entry_241, isr_241); - modify_descriptor_entry(&idt.entry_242, isr_242); - modify_descriptor_entry(&idt.entry_243, isr_243); - modify_descriptor_entry(&idt.entry_244, isr_244); - modify_descriptor_entry(&idt.entry_245, isr_245); - modify_descriptor_entry(&idt.entry_246, isr_246); - modify_descriptor_entry(&idt.entry_247, isr_247); - modify_descriptor_entry(&idt.entry_248, isr_248); - modify_descriptor_entry(&idt.entry_249, isr_249); - modify_descriptor_entry(&idt.entry_250, isr_250); - modify_descriptor_entry(&idt.entry_251, isr_251); - modify_descriptor_entry(&idt.entry_252, isr_252); - modify_descriptor_entry(&idt.entry_253, isr_253); - modify_descriptor_entry(&idt.entry_254, isr_254); - modify_descriptor_entry(&idt.entry_255, isr_255); + idt_descriptor.size = 255 * 16 - 1; + modify_descriptor_entry(&idt.entry_0, isr_0, false); + modify_descriptor_entry(&idt.entry_1, isr_1, false); + modify_descriptor_entry(&idt.entry_2, isr_2, false); + modify_descriptor_entry(&idt.entry_3, isr_3, false); + modify_descriptor_entry(&idt.entry_4, isr_4, false); + modify_descriptor_entry(&idt.entry_5, isr_5, false); + modify_descriptor_entry(&idt.entry_6, isr_6, false); + modify_descriptor_entry(&idt.entry_7, isr_7, false); + modify_descriptor_entry(&idt.entry_8, isr_8, false); + modify_descriptor_entry(&idt.entry_9, isr_9, false); + modify_descriptor_entry(&idt.entry_10, isr_10, false); + modify_descriptor_entry(&idt.entry_11, isr_11, false); + modify_descriptor_entry(&idt.entry_12, isr_12, false); + modify_descriptor_entry(&idt.entry_13, isr_13, false); + modify_descriptor_entry(&idt.entry_14, isr_14, false); + modify_descriptor_entry(&idt.entry_15, isr_15, false); + modify_descriptor_entry(&idt.entry_16, isr_16, false); + modify_descriptor_entry(&idt.entry_17, isr_17, false); + modify_descriptor_entry(&idt.entry_18, isr_18, false); + modify_descriptor_entry(&idt.entry_19, isr_19, false); + modify_descriptor_entry(&idt.entry_20, isr_20, false); + modify_descriptor_entry(&idt.entry_21, isr_21, false); + modify_descriptor_entry(&idt.entry_22, isr_22, false); + modify_descriptor_entry(&idt.entry_23, isr_23, false); + modify_descriptor_entry(&idt.entry_24, isr_24, false); + modify_descriptor_entry(&idt.entry_25, isr_25, false); + modify_descriptor_entry(&idt.entry_26, isr_26, false); + modify_descriptor_entry(&idt.entry_27, isr_27, false); + modify_descriptor_entry(&idt.entry_28, isr_28, false); + modify_descriptor_entry(&idt.entry_29, isr_29, false); + modify_descriptor_entry(&idt.entry_30, isr_30, false); + modify_descriptor_entry(&idt.entry_31, isr_31, false); + modify_descriptor_entry(&idt.entry_32, isr_32, false); + modify_descriptor_entry(&idt.entry_33, isr_33, false); + modify_descriptor_entry(&idt.entry_34, isr_34, false); + modify_descriptor_entry(&idt.entry_35, isr_35, false); + modify_descriptor_entry(&idt.entry_36, isr_36, false); + modify_descriptor_entry(&idt.entry_37, isr_37, false); + modify_descriptor_entry(&idt.entry_38, isr_38, false); + modify_descriptor_entry(&idt.entry_39, isr_39, false); + modify_descriptor_entry(&idt.entry_40, isr_40, false); + modify_descriptor_entry(&idt.entry_41, isr_41, false); + modify_descriptor_entry(&idt.entry_42, isr_42, false); + modify_descriptor_entry(&idt.entry_43, isr_43, false); + modify_descriptor_entry(&idt.entry_44, isr_44, false); + modify_descriptor_entry(&idt.entry_45, isr_45, false); + modify_descriptor_entry(&idt.entry_46, isr_46, false); + modify_descriptor_entry(&idt.entry_47, isr_47, false); + modify_descriptor_entry(&idt.entry_48, isr_48, false); + modify_descriptor_entry(&idt.entry_49, isr_49, false); + modify_descriptor_entry(&idt.entry_50, isr_50, false); + modify_descriptor_entry(&idt.entry_51, isr_51, false); + modify_descriptor_entry(&idt.entry_52, isr_52, false); + modify_descriptor_entry(&idt.entry_53, isr_53, false); + modify_descriptor_entry(&idt.entry_54, isr_54, false); + modify_descriptor_entry(&idt.entry_55, isr_55, false); + modify_descriptor_entry(&idt.entry_56, isr_56, false); + modify_descriptor_entry(&idt.entry_57, isr_57, false); + modify_descriptor_entry(&idt.entry_58, isr_58, false); + modify_descriptor_entry(&idt.entry_59, isr_59, false); + modify_descriptor_entry(&idt.entry_60, isr_60, false); + modify_descriptor_entry(&idt.entry_61, isr_61, false); + modify_descriptor_entry(&idt.entry_62, isr_62, false); + modify_descriptor_entry(&idt.entry_63, isr_63, false); + modify_descriptor_entry(&idt.entry_64, isr_64, false); + modify_descriptor_entry(&idt.entry_65, isr_65, false); + modify_descriptor_entry(&idt.entry_66, isr_66, false); + modify_descriptor_entry(&idt.entry_67, isr_67, false); + modify_descriptor_entry(&idt.entry_68, isr_68, false); + modify_descriptor_entry(&idt.entry_69, isr_69, false); + modify_descriptor_entry(&idt.entry_70, isr_70, false); + modify_descriptor_entry(&idt.entry_71, isr_71, false); + modify_descriptor_entry(&idt.entry_72, isr_72, false); + modify_descriptor_entry(&idt.entry_73, isr_73, false); + modify_descriptor_entry(&idt.entry_74, isr_74, false); + modify_descriptor_entry(&idt.entry_75, isr_75, false); + modify_descriptor_entry(&idt.entry_76, isr_76, false); + modify_descriptor_entry(&idt.entry_77, isr_77, false); + modify_descriptor_entry(&idt.entry_78, isr_78, false); + modify_descriptor_entry(&idt.entry_79, isr_79, false); + modify_descriptor_entry(&idt.entry_80, isr_80, false); + modify_descriptor_entry(&idt.entry_81, isr_81, false); + modify_descriptor_entry(&idt.entry_82, isr_82, false); + modify_descriptor_entry(&idt.entry_83, isr_83, false); + modify_descriptor_entry(&idt.entry_84, isr_84, false); + modify_descriptor_entry(&idt.entry_85, isr_85, false); + modify_descriptor_entry(&idt.entry_86, isr_86, false); + modify_descriptor_entry(&idt.entry_87, isr_87, false); + modify_descriptor_entry(&idt.entry_88, isr_88, false); + modify_descriptor_entry(&idt.entry_89, isr_89, false); + modify_descriptor_entry(&idt.entry_90, isr_90, false); + modify_descriptor_entry(&idt.entry_91, isr_91, false); + modify_descriptor_entry(&idt.entry_92, isr_92, false); + modify_descriptor_entry(&idt.entry_93, isr_93, false); + modify_descriptor_entry(&idt.entry_94, isr_94, false); + modify_descriptor_entry(&idt.entry_95, isr_95, false); + modify_descriptor_entry(&idt.entry_96, isr_96, false); + modify_descriptor_entry(&idt.entry_97, isr_97, false); + modify_descriptor_entry(&idt.entry_98, isr_98, false); + modify_descriptor_entry(&idt.entry_99, isr_99, false); + modify_descriptor_entry(&idt.entry_100, isr_100, false); + modify_descriptor_entry(&idt.entry_101, isr_101, false); + modify_descriptor_entry(&idt.entry_102, isr_102, false); + modify_descriptor_entry(&idt.entry_103, isr_103, false); + modify_descriptor_entry(&idt.entry_104, isr_104, false); + modify_descriptor_entry(&idt.entry_105, isr_105, false); + modify_descriptor_entry(&idt.entry_106, isr_106, false); + modify_descriptor_entry(&idt.entry_107, isr_107, false); + modify_descriptor_entry(&idt.entry_108, isr_108, false); + modify_descriptor_entry(&idt.entry_109, isr_109, false); + modify_descriptor_entry(&idt.entry_110, isr_110, false); + modify_descriptor_entry(&idt.entry_111, isr_111, false); + modify_descriptor_entry(&idt.entry_112, isr_112, false); + modify_descriptor_entry(&idt.entry_113, isr_113, false); + modify_descriptor_entry(&idt.entry_114, isr_114, false); + modify_descriptor_entry(&idt.entry_115, isr_115, false); + modify_descriptor_entry(&idt.entry_116, isr_116, false); + modify_descriptor_entry(&idt.entry_117, isr_117, false); + modify_descriptor_entry(&idt.entry_118, isr_118, false); + modify_descriptor_entry(&idt.entry_119, isr_119, false); + modify_descriptor_entry(&idt.entry_120, isr_120, false); + modify_descriptor_entry(&idt.entry_121, isr_121, false); + modify_descriptor_entry(&idt.entry_122, isr_122, false); + modify_descriptor_entry(&idt.entry_123, isr_123, false); + modify_descriptor_entry(&idt.entry_124, isr_124, false); + modify_descriptor_entry(&idt.entry_125, isr_125, false); + modify_descriptor_entry(&idt.entry_126, isr_126, false); + modify_descriptor_entry(&idt.entry_127, isr_127, false); + modify_descriptor_entry(&idt.entry_128, isr_128, true); + modify_descriptor_entry(&idt.entry_129, isr_129, false); + modify_descriptor_entry(&idt.entry_130, isr_130, false); + modify_descriptor_entry(&idt.entry_131, isr_131, false); + modify_descriptor_entry(&idt.entry_132, isr_132, false); + modify_descriptor_entry(&idt.entry_133, isr_133, false); + modify_descriptor_entry(&idt.entry_134, isr_134, false); + modify_descriptor_entry(&idt.entry_135, isr_135, false); + modify_descriptor_entry(&idt.entry_136, isr_136, false); + modify_descriptor_entry(&idt.entry_137, isr_137, false); + modify_descriptor_entry(&idt.entry_138, isr_138, false); + modify_descriptor_entry(&idt.entry_139, isr_139, false); + modify_descriptor_entry(&idt.entry_140, isr_140, false); + modify_descriptor_entry(&idt.entry_141, isr_141, false); + modify_descriptor_entry(&idt.entry_142, isr_142, false); + modify_descriptor_entry(&idt.entry_143, isr_143, false); + modify_descriptor_entry(&idt.entry_144, isr_144, false); + modify_descriptor_entry(&idt.entry_145, isr_145, false); + modify_descriptor_entry(&idt.entry_146, isr_146, false); + modify_descriptor_entry(&idt.entry_147, isr_147, false); + modify_descriptor_entry(&idt.entry_148, isr_148, false); + modify_descriptor_entry(&idt.entry_149, isr_149, false); + modify_descriptor_entry(&idt.entry_150, isr_150, false); + modify_descriptor_entry(&idt.entry_151, isr_151, false); + modify_descriptor_entry(&idt.entry_152, isr_152, false); + modify_descriptor_entry(&idt.entry_153, isr_153, false); + modify_descriptor_entry(&idt.entry_154, isr_154, false); + modify_descriptor_entry(&idt.entry_155, isr_155, false); + modify_descriptor_entry(&idt.entry_156, isr_156, false); + modify_descriptor_entry(&idt.entry_157, isr_157, false); + modify_descriptor_entry(&idt.entry_158, isr_158, false); + modify_descriptor_entry(&idt.entry_159, isr_159, false); + modify_descriptor_entry(&idt.entry_160, isr_160, false); + modify_descriptor_entry(&idt.entry_161, isr_161, false); + modify_descriptor_entry(&idt.entry_162, isr_162, false); + modify_descriptor_entry(&idt.entry_163, isr_163, false); + modify_descriptor_entry(&idt.entry_164, isr_164, false); + modify_descriptor_entry(&idt.entry_165, isr_165, false); + modify_descriptor_entry(&idt.entry_166, isr_166, false); + modify_descriptor_entry(&idt.entry_167, isr_167, false); + modify_descriptor_entry(&idt.entry_168, isr_168, false); + modify_descriptor_entry(&idt.entry_169, isr_169, false); + modify_descriptor_entry(&idt.entry_170, isr_170, false); + modify_descriptor_entry(&idt.entry_171, isr_171, false); + modify_descriptor_entry(&idt.entry_172, isr_172, false); + modify_descriptor_entry(&idt.entry_173, isr_173, false); + modify_descriptor_entry(&idt.entry_174, isr_174, false); + modify_descriptor_entry(&idt.entry_175, isr_175, false); + modify_descriptor_entry(&idt.entry_176, isr_176, false); + modify_descriptor_entry(&idt.entry_177, isr_177, false); + modify_descriptor_entry(&idt.entry_178, isr_178, false); + modify_descriptor_entry(&idt.entry_179, isr_179, false); + modify_descriptor_entry(&idt.entry_180, isr_180, false); + modify_descriptor_entry(&idt.entry_181, isr_181, false); + modify_descriptor_entry(&idt.entry_182, isr_182, false); + modify_descriptor_entry(&idt.entry_183, isr_183, false); + modify_descriptor_entry(&idt.entry_184, isr_184, false); + modify_descriptor_entry(&idt.entry_185, isr_185, false); + modify_descriptor_entry(&idt.entry_186, isr_186, false); + modify_descriptor_entry(&idt.entry_187, isr_187, false); + modify_descriptor_entry(&idt.entry_188, isr_188, false); + modify_descriptor_entry(&idt.entry_189, isr_189, false); + modify_descriptor_entry(&idt.entry_190, isr_190, false); + modify_descriptor_entry(&idt.entry_191, isr_191, false); + modify_descriptor_entry(&idt.entry_192, isr_192, false); + modify_descriptor_entry(&idt.entry_193, isr_193, false); + modify_descriptor_entry(&idt.entry_194, isr_194, false); + modify_descriptor_entry(&idt.entry_195, isr_195, false); + modify_descriptor_entry(&idt.entry_196, isr_196, false); + modify_descriptor_entry(&idt.entry_197, isr_197, false); + modify_descriptor_entry(&idt.entry_198, isr_198, false); + modify_descriptor_entry(&idt.entry_199, isr_199, false); + modify_descriptor_entry(&idt.entry_200, isr_200, false); + modify_descriptor_entry(&idt.entry_201, isr_201, false); + modify_descriptor_entry(&idt.entry_202, isr_202, false); + modify_descriptor_entry(&idt.entry_203, isr_203, false); + modify_descriptor_entry(&idt.entry_204, isr_204, false); + modify_descriptor_entry(&idt.entry_205, isr_205, false); + modify_descriptor_entry(&idt.entry_206, isr_206, false); + modify_descriptor_entry(&idt.entry_207, isr_207, false); + modify_descriptor_entry(&idt.entry_208, isr_208, false); + modify_descriptor_entry(&idt.entry_209, isr_209, false); + modify_descriptor_entry(&idt.entry_210, isr_210, false); + modify_descriptor_entry(&idt.entry_211, isr_211, false); + modify_descriptor_entry(&idt.entry_212, isr_212, false); + modify_descriptor_entry(&idt.entry_213, isr_213, false); + modify_descriptor_entry(&idt.entry_214, isr_214, false); + modify_descriptor_entry(&idt.entry_215, isr_215, false); + modify_descriptor_entry(&idt.entry_216, isr_216, false); + modify_descriptor_entry(&idt.entry_217, isr_217, false); + modify_descriptor_entry(&idt.entry_218, isr_218, false); + modify_descriptor_entry(&idt.entry_219, isr_219, false); + modify_descriptor_entry(&idt.entry_220, isr_220, false); + modify_descriptor_entry(&idt.entry_221, isr_221, false); + modify_descriptor_entry(&idt.entry_222, isr_222, false); + modify_descriptor_entry(&idt.entry_223, isr_223, false); + modify_descriptor_entry(&idt.entry_224, isr_224, false); + modify_descriptor_entry(&idt.entry_225, isr_225, false); + modify_descriptor_entry(&idt.entry_226, isr_226, false); + modify_descriptor_entry(&idt.entry_227, isr_227, false); + modify_descriptor_entry(&idt.entry_228, isr_228, false); + modify_descriptor_entry(&idt.entry_229, isr_229, false); + modify_descriptor_entry(&idt.entry_230, isr_230, false); + modify_descriptor_entry(&idt.entry_231, isr_231, false); + modify_descriptor_entry(&idt.entry_232, isr_232, false); + modify_descriptor_entry(&idt.entry_233, isr_233, false); + modify_descriptor_entry(&idt.entry_234, isr_234, false); + modify_descriptor_entry(&idt.entry_235, isr_235, false); + modify_descriptor_entry(&idt.entry_236, isr_236, false); + modify_descriptor_entry(&idt.entry_237, isr_237, false); + modify_descriptor_entry(&idt.entry_238, isr_238, false); + modify_descriptor_entry(&idt.entry_239, isr_239, false); + modify_descriptor_entry(&idt.entry_240, isr_240, false); + modify_descriptor_entry(&idt.entry_241, isr_241, false); + modify_descriptor_entry(&idt.entry_242, isr_242, false); + modify_descriptor_entry(&idt.entry_243, isr_243, false); + modify_descriptor_entry(&idt.entry_244, isr_244, false); + modify_descriptor_entry(&idt.entry_245, isr_245, false); + modify_descriptor_entry(&idt.entry_246, isr_246, false); + modify_descriptor_entry(&idt.entry_247, isr_247, false); + modify_descriptor_entry(&idt.entry_248, isr_248, false); + modify_descriptor_entry(&idt.entry_249, isr_249, false); + modify_descriptor_entry(&idt.entry_250, isr_250, false); + modify_descriptor_entry(&idt.entry_251, isr_251, false); + modify_descriptor_entry(&idt.entry_252, isr_252, false); + modify_descriptor_entry(&idt.entry_253, isr_253, false); + modify_descriptor_entry(&idt.entry_254, isr_254, false); + modify_descriptor_entry(&idt.entry_255, isr_255, false); set_pic_offset(); asm volatile("lidt %0" : : "m" (idt_descriptor)); asm volatile("sti"); @@ -714,11 +462,17 @@ void control_protection_exception_interrupt() { int count_interrupts; void timer_interrupt() { - char number[12]; + char* number = kmalloc(sizeof(char) * 12); count_interrupts += 1; - from_int(count_interrupts, number); + decimal_from_int32(count_interrupts, number); write_string_at(vga3_color(VGA3_GREEN, VGA3_BLACK), "Timer", 15, 17); write_string_at(vga3_color(VGA3_WHITE, VGA3_BLACK), number, 30, 17); + free(number); +} + +// 128 +void system_call() { + write_string_at(vga3_color(VGA3_GREEN, VGA3_BLACK), "System Call", 18, 18); } @@ -727,8 +481,9 @@ void timer_interrupt() { */ void unmapped_or_reserved_interrupt(uint64_t interrupt_vector) { - char number[12]; - from_int((int) interrupt_vector, number); + char* number = kmalloc(sizeof(char[12])); + decimal_from_int32((int) interrupt_vector, number); write_string_at(vga3_color(VGA3_GREEN, VGA3_BLACK), "Unmapped", 15, 17); write_string_at(vga3_color(VGA3_WHITE, VGA3_BLACK), number, 30, 17); + free(number); } \ No newline at end of file diff --git a/src/cpu/x86_64/idt.h b/src/cpu/x86_64/idt.h index c2d184d..77a54e8 100644 --- a/src/cpu/x86_64/idt.h +++ b/src/cpu/x86_64/idt.h @@ -15,7 +15,6 @@ void init_idt(); - /* * The descriptor structure for an interrupt gate, used in the IDT. Intel Manual Volume 3 Chapter 6.11 */ @@ -29,6 +28,275 @@ struct interrupt_gate_descriptor { uint32_t zeroes; }__attribute__((packed)); +typedef struct interrupt_gate_descriptor interrupt_gate_descriptor; + +/* + * IDT is of a fixed length with 256 entries. sowwy :3; + */ +static struct { + interrupt_gate_descriptor entry_0; + interrupt_gate_descriptor entry_1; + interrupt_gate_descriptor entry_2; + interrupt_gate_descriptor entry_3; + interrupt_gate_descriptor entry_4; + interrupt_gate_descriptor entry_5; + interrupt_gate_descriptor entry_6; + interrupt_gate_descriptor entry_7; + interrupt_gate_descriptor entry_8; + interrupt_gate_descriptor entry_9; + interrupt_gate_descriptor entry_10; + interrupt_gate_descriptor entry_11; + interrupt_gate_descriptor entry_12; + interrupt_gate_descriptor entry_13; + interrupt_gate_descriptor entry_14; + interrupt_gate_descriptor entry_15; + interrupt_gate_descriptor entry_16; + interrupt_gate_descriptor entry_17; + interrupt_gate_descriptor entry_18; + interrupt_gate_descriptor entry_19; + interrupt_gate_descriptor entry_20; + interrupt_gate_descriptor entry_21; + interrupt_gate_descriptor entry_22; + interrupt_gate_descriptor entry_23; + interrupt_gate_descriptor entry_24; + interrupt_gate_descriptor entry_25; + interrupt_gate_descriptor entry_26; + interrupt_gate_descriptor entry_27; + interrupt_gate_descriptor entry_28; + interrupt_gate_descriptor entry_29; + interrupt_gate_descriptor entry_30; + interrupt_gate_descriptor entry_31; + interrupt_gate_descriptor entry_32; + interrupt_gate_descriptor entry_33; + interrupt_gate_descriptor entry_34; + interrupt_gate_descriptor entry_35; + interrupt_gate_descriptor entry_36; + interrupt_gate_descriptor entry_37; + interrupt_gate_descriptor entry_38; + interrupt_gate_descriptor entry_39; + interrupt_gate_descriptor entry_40; + interrupt_gate_descriptor entry_41; + interrupt_gate_descriptor entry_42; + interrupt_gate_descriptor entry_43; + interrupt_gate_descriptor entry_44; + interrupt_gate_descriptor entry_45; + interrupt_gate_descriptor entry_46; + interrupt_gate_descriptor entry_47; + interrupt_gate_descriptor entry_48; + interrupt_gate_descriptor entry_49; + interrupt_gate_descriptor entry_50; + interrupt_gate_descriptor entry_51; + interrupt_gate_descriptor entry_52; + interrupt_gate_descriptor entry_53; + interrupt_gate_descriptor entry_54; + interrupt_gate_descriptor entry_55; + interrupt_gate_descriptor entry_56; + interrupt_gate_descriptor entry_57; + interrupt_gate_descriptor entry_58; + interrupt_gate_descriptor entry_59; + interrupt_gate_descriptor entry_60; + interrupt_gate_descriptor entry_61; + interrupt_gate_descriptor entry_62; + interrupt_gate_descriptor entry_63; + interrupt_gate_descriptor entry_64; + interrupt_gate_descriptor entry_65; + interrupt_gate_descriptor entry_66; + interrupt_gate_descriptor entry_67; + interrupt_gate_descriptor entry_68; + interrupt_gate_descriptor entry_69; + interrupt_gate_descriptor entry_70; + interrupt_gate_descriptor entry_71; + interrupt_gate_descriptor entry_72; + interrupt_gate_descriptor entry_73; + interrupt_gate_descriptor entry_74; + interrupt_gate_descriptor entry_75; + interrupt_gate_descriptor entry_76; + interrupt_gate_descriptor entry_77; + interrupt_gate_descriptor entry_78; + interrupt_gate_descriptor entry_79; + interrupt_gate_descriptor entry_80; + interrupt_gate_descriptor entry_81; + interrupt_gate_descriptor entry_82; + interrupt_gate_descriptor entry_83; + interrupt_gate_descriptor entry_84; + interrupt_gate_descriptor entry_85; + interrupt_gate_descriptor entry_86; + interrupt_gate_descriptor entry_87; + interrupt_gate_descriptor entry_88; + interrupt_gate_descriptor entry_89; + interrupt_gate_descriptor entry_90; + interrupt_gate_descriptor entry_91; + interrupt_gate_descriptor entry_92; + interrupt_gate_descriptor entry_93; + interrupt_gate_descriptor entry_94; + interrupt_gate_descriptor entry_95; + interrupt_gate_descriptor entry_96; + interrupt_gate_descriptor entry_97; + interrupt_gate_descriptor entry_98; + interrupt_gate_descriptor entry_99; + interrupt_gate_descriptor entry_100; + interrupt_gate_descriptor entry_101; + interrupt_gate_descriptor entry_102; + interrupt_gate_descriptor entry_103; + interrupt_gate_descriptor entry_104; + interrupt_gate_descriptor entry_105; + interrupt_gate_descriptor entry_106; + interrupt_gate_descriptor entry_107; + interrupt_gate_descriptor entry_108; + interrupt_gate_descriptor entry_109; + interrupt_gate_descriptor entry_110; + interrupt_gate_descriptor entry_111; + interrupt_gate_descriptor entry_112; + interrupt_gate_descriptor entry_113; + interrupt_gate_descriptor entry_114; + interrupt_gate_descriptor entry_115; + interrupt_gate_descriptor entry_116; + interrupt_gate_descriptor entry_117; + interrupt_gate_descriptor entry_118; + interrupt_gate_descriptor entry_119; + interrupt_gate_descriptor entry_120; + interrupt_gate_descriptor entry_121; + interrupt_gate_descriptor entry_122; + interrupt_gate_descriptor entry_123; + interrupt_gate_descriptor entry_124; + interrupt_gate_descriptor entry_125; + interrupt_gate_descriptor entry_126; + interrupt_gate_descriptor entry_127; + interrupt_gate_descriptor entry_128; + interrupt_gate_descriptor entry_129; + interrupt_gate_descriptor entry_130; + interrupt_gate_descriptor entry_131; + interrupt_gate_descriptor entry_132; + interrupt_gate_descriptor entry_133; + interrupt_gate_descriptor entry_134; + interrupt_gate_descriptor entry_135; + interrupt_gate_descriptor entry_136; + interrupt_gate_descriptor entry_137; + interrupt_gate_descriptor entry_138; + interrupt_gate_descriptor entry_139; + interrupt_gate_descriptor entry_140; + interrupt_gate_descriptor entry_141; + interrupt_gate_descriptor entry_142; + interrupt_gate_descriptor entry_143; + interrupt_gate_descriptor entry_144; + interrupt_gate_descriptor entry_145; + interrupt_gate_descriptor entry_146; + interrupt_gate_descriptor entry_147; + interrupt_gate_descriptor entry_148; + interrupt_gate_descriptor entry_149; + interrupt_gate_descriptor entry_150; + interrupt_gate_descriptor entry_151; + interrupt_gate_descriptor entry_152; + interrupt_gate_descriptor entry_153; + interrupt_gate_descriptor entry_154; + interrupt_gate_descriptor entry_155; + interrupt_gate_descriptor entry_156; + interrupt_gate_descriptor entry_157; + interrupt_gate_descriptor entry_158; + interrupt_gate_descriptor entry_159; + interrupt_gate_descriptor entry_160; + interrupt_gate_descriptor entry_161; + interrupt_gate_descriptor entry_162; + interrupt_gate_descriptor entry_163; + interrupt_gate_descriptor entry_164; + interrupt_gate_descriptor entry_165; + interrupt_gate_descriptor entry_166; + interrupt_gate_descriptor entry_167; + interrupt_gate_descriptor entry_168; + interrupt_gate_descriptor entry_169; + interrupt_gate_descriptor entry_170; + interrupt_gate_descriptor entry_171; + interrupt_gate_descriptor entry_172; + interrupt_gate_descriptor entry_173; + interrupt_gate_descriptor entry_174; + interrupt_gate_descriptor entry_175; + interrupt_gate_descriptor entry_176; + interrupt_gate_descriptor entry_177; + interrupt_gate_descriptor entry_178; + interrupt_gate_descriptor entry_179; + interrupt_gate_descriptor entry_180; + interrupt_gate_descriptor entry_181; + interrupt_gate_descriptor entry_182; + interrupt_gate_descriptor entry_183; + interrupt_gate_descriptor entry_184; + interrupt_gate_descriptor entry_185; + interrupt_gate_descriptor entry_186; + interrupt_gate_descriptor entry_187; + interrupt_gate_descriptor entry_188; + interrupt_gate_descriptor entry_189; + interrupt_gate_descriptor entry_190; + interrupt_gate_descriptor entry_191; + interrupt_gate_descriptor entry_192; + interrupt_gate_descriptor entry_193; + interrupt_gate_descriptor entry_194; + interrupt_gate_descriptor entry_195; + interrupt_gate_descriptor entry_196; + interrupt_gate_descriptor entry_197; + interrupt_gate_descriptor entry_198; + interrupt_gate_descriptor entry_199; + interrupt_gate_descriptor entry_200; + interrupt_gate_descriptor entry_201; + interrupt_gate_descriptor entry_202; + interrupt_gate_descriptor entry_203; + interrupt_gate_descriptor entry_204; + interrupt_gate_descriptor entry_205; + interrupt_gate_descriptor entry_206; + interrupt_gate_descriptor entry_207; + interrupt_gate_descriptor entry_208; + interrupt_gate_descriptor entry_209; + interrupt_gate_descriptor entry_210; + interrupt_gate_descriptor entry_211; + interrupt_gate_descriptor entry_212; + interrupt_gate_descriptor entry_213; + interrupt_gate_descriptor entry_214; + interrupt_gate_descriptor entry_215; + interrupt_gate_descriptor entry_216; + interrupt_gate_descriptor entry_217; + interrupt_gate_descriptor entry_218; + interrupt_gate_descriptor entry_219; + interrupt_gate_descriptor entry_220; + interrupt_gate_descriptor entry_221; + interrupt_gate_descriptor entry_222; + interrupt_gate_descriptor entry_223; + interrupt_gate_descriptor entry_224; + interrupt_gate_descriptor entry_225; + interrupt_gate_descriptor entry_226; + interrupt_gate_descriptor entry_227; + interrupt_gate_descriptor entry_228; + interrupt_gate_descriptor entry_229; + interrupt_gate_descriptor entry_230; + interrupt_gate_descriptor entry_231; + interrupt_gate_descriptor entry_232; + interrupt_gate_descriptor entry_233; + interrupt_gate_descriptor entry_234; + interrupt_gate_descriptor entry_235; + interrupt_gate_descriptor entry_236; + interrupt_gate_descriptor entry_237; + interrupt_gate_descriptor entry_238; + interrupt_gate_descriptor entry_239; + interrupt_gate_descriptor entry_240; + interrupt_gate_descriptor entry_241; + interrupt_gate_descriptor entry_242; + interrupt_gate_descriptor entry_243; + interrupt_gate_descriptor entry_244; + interrupt_gate_descriptor entry_245; + interrupt_gate_descriptor entry_246; + interrupt_gate_descriptor entry_247; + interrupt_gate_descriptor entry_248; + interrupt_gate_descriptor entry_249; + interrupt_gate_descriptor entry_250; + interrupt_gate_descriptor entry_251; + interrupt_gate_descriptor entry_252; + interrupt_gate_descriptor entry_253; + interrupt_gate_descriptor entry_254; + interrupt_gate_descriptor entry_255; +}__attribute((aligned(0x10))) __attribute__((packed)) idt; // if you complain about the IDT code, you will be banned from contributing to the kitty kernel project. + +static struct { + uint16_t size; // One less than the size (max entry number, entries start at 0) + uint64_t offset; // address of the IDT +}__attribute__((packed)) idt_descriptor; + /* * The Interrupt Service Routines (ISRs) defined in the interrupts.asm file. * Each corresponds to the Interrupt Descriptor Table (IDT) entry in idt.c @@ -290,6 +558,4 @@ extern void isr_253(); extern void isr_254(); extern void isr_255(); -typedef struct interrupt_gate_descriptor interrupt_gate_descriptor; - #endif //KITTY_IDT_H diff --git a/src/cpu/x86_64/interrupts.asm b/src/cpu/x86_64/interrupts.asm index 961adf0..245e1c6 100644 --- a/src/cpu/x86_64/interrupts.asm +++ b/src/cpu/x86_64/interrupts.asm @@ -172,7 +172,7 @@ isr_unmapped 124 isr_unmapped 125 isr_unmapped 126 isr_unmapped 127 -isr_unmapped 128 +isr_complete 128, system_call isr_unmapped 129 isr_unmapped 130 isr_unmapped 131 diff --git a/src/cpu/x86_64/tss.c b/src/cpu/x86_64/tss.c new file mode 100644 index 0000000..4e64411 --- /dev/null +++ b/src/cpu/x86_64/tss.c @@ -0,0 +1,33 @@ +// +// Created by AIDAN on 9/17/2024. +// + +#include "tss.h" +#include "../../kernel/memory.h" +#include "gdt.h" + +void setup_tss(task_state_segment* tss) { + tss->io_map_base_address = (uint16_t) sizeof (task_state_segment); + uint64_t address = (uint64_t) tss; + GDT.tss_0 = ((uint32_t) sizeof (task_state_segment) & 0xFFFF) | ((address & 0xFFFF) << 16); + GDT.tss_1 = (((address) >> 16) & 0xFF) | 0x8000 | 0x0900 | ((uint32_t)sizeof (task_state_segment) & 0x000F0000) | (address & 0xFF000000); + GDT.tss_2 = address >> 32; + GDT.tss_3 = 0; + asm volatile("lgdt %0" : : "m" (GDT.size)); + asm inline volatile ("mov $0x28, %ax"); + asm inline volatile ("ltr %ax"); +} + +void set_kernel_stack(task_state_segment* tss, uint64_t stack_address) { + tss->ist7 = stack_address; + tss->ist6 = stack_address; + tss->ist5 = stack_address; + tss->ist4 = stack_address; + tss->ist3 = stack_address; + tss->ist2 = stack_address; + tss->ist1 = stack_address; + tss->rsp0 = stack_address; + tss->rsp1 = stack_address; + tss->rsp2 = stack_address; + +} \ No newline at end of file diff --git a/src/cpu/x86_64/tss.h b/src/cpu/x86_64/tss.h new file mode 100644 index 0000000..919b06f --- /dev/null +++ b/src/cpu/x86_64/tss.h @@ -0,0 +1,50 @@ +// +// Created by AIDAN on 9/17/2024. +// + +#ifndef KITTY_TSS_H +#define KITTY_TSS_H + +#include "stdint.h" + +/* + * Task State Segment (TSS) Setup + * + * The kitty kernel uses software multitasking and a single TSS to + * switch between ring 3 and ring 0. Since scheduling can (although it might not now) + * run during a system call (the current process can switch) and a second + * system call from a different process can switch back to ring 0, the kernel + * stack pointer in this TSS must be updated when switching processes. + * + */ + + +struct task_state_segment { + uint32_t reserved_0; + uint64_t rsp0; + uint64_t rsp1; + uint64_t rsp2; + uint64_t reserved_1; + uint64_t ist1; + uint64_t ist2; + uint64_t ist3; + uint64_t ist4; + uint64_t ist5; + uint64_t ist6; + uint64_t ist7; + uint64_t reserved_2; + uint16_t reserved_3; + uint16_t io_map_base_address; +} __attribute__ ((packed)); + +typedef struct task_state_segment task_state_segment; + +//const tss_base_address = &tss; +// +//const tss_limit = sizeof(tss) - 1; + +void setup_tss(task_state_segment* tss); + +void set_kernel_stack(task_state_segment* tss, uint64_t stack_address); + +#endif //KITTY_TSS_H diff --git a/src/cpu/x86_64/usermode.asm b/src/cpu/x86_64/usermode.asm new file mode 100644 index 0000000..853c22e --- /dev/null +++ b/src/cpu/x86_64/usermode.asm @@ -0,0 +1,25 @@ +[bits 64] +function: + int 0x80 + ;mov [0x8000], byte 15 + jmp $ +; returning from this causes a page fault??? what is even happening... +extern set_kernel_stack +global enter_usermode +enter_usermode: + mov ax, 0x20 | 3 + mov ds, ax + mov es, ax + mov fs, ax + mov gs, ax + + mov rax, rsp + push 0x20 | 3 + push rax + pushfq + push 0x18 | 3 + push function + ;mov rsi, rsp + ;call set_kernel_stack + ;jmp set_kernel_stack + iretq \ No newline at end of file diff --git a/src/cpu/x86_64/usermode.h b/src/cpu/x86_64/usermode.h new file mode 100644 index 0000000..5adfcd8 --- /dev/null +++ b/src/cpu/x86_64/usermode.h @@ -0,0 +1,10 @@ +// +// Created by AIDAN on 9/26/2024. +// + +#ifndef KITTY_USERMODE_H +#define KITTY_USERMODE_H + +extern void enter_usermode(task_state_segment* tss); + +#endif //KITTY_USERMODE_H diff --git a/src/kernel/kitty.c b/src/kernel/kitty.c index 6f62a71..5b6f861 100644 --- a/src/kernel/kitty.c +++ b/src/kernel/kitty.c @@ -6,16 +6,26 @@ #include "kitty.h" #include "../driver/video/vga.h" #include "../cpu/cpu_options.h" +#include "memory.h" #ifdef x86_64 #include "../cpu/x86_64/idt.h" +#include "../cpu/x86_64/tss.h" +#include "../cpu/x86_64/usermode.h" #endif void kitty() { // Perform initial setup for CPUs #ifdef Intel_CPU - write_string(vga3_color(VGA3_CYAN, VGA3_RED),"Starting the Kitty Kernel..."); + write_string(vga3_color(VGA3_CYAN, VGA3_RED),"Welcome to the Kitty Kernel"); + task_state_segment *tss = (task_state_segment*) kmalloc(sizeof (task_state_segment)); + void* stack_bottom = kmalloc(8096); + void* stack_top = stack_bottom + 8096; + set_kernel_stack(tss, (uint64_t) stack_top); + setup_tss(tss); init_idt(); write_string_at(VGA3_WHITE, "idt loaded", 0,15); + free(kmalloc(1)); + enter_usermode(tss); #endif #ifdef ARM_CPU diff --git a/src/kernel/memory.c b/src/kernel/memory.c new file mode 100644 index 0000000..083325f --- /dev/null +++ b/src/kernel/memory.c @@ -0,0 +1,38 @@ +// +// Created by AIDAN on 8/19/2024. +// + +#include "memory.h" + +char * free_base_address = (char *) 0x10000; +char * kmalloc(uint64_t type_size) { + char * address = free_base_address; + free_base_address += type_size; + return address; +} + +char * kzmalloc(uint64_t type_size) { + char * address = free_base_address; + free_base_address += type_size; + return address; +} + + +char * kamalloc(uint64_t type_size, uint64_t array_size) { + char * address = free_base_address; + free_base_address += type_size * array_size; + return address; +} + +char * kzamalloc(uint64_t type_size, uint64_t array_size) { + char * address = free_base_address; + // zero the memory TODO verify that this actually works... + for (uint64_t i = 0; i < (type_size * array_size); i++) { + *(free_base_address + i) = 0; + } + free_base_address += type_size * array_size; + return address; +} + +void free(char* mem_address) { +} \ No newline at end of file diff --git a/src/kernel/memory.h b/src/kernel/memory.h new file mode 100644 index 0000000..65435af --- /dev/null +++ b/src/kernel/memory.h @@ -0,0 +1,29 @@ +// +// Created by AIDAN on 8/19/2024. +// + +#ifndef KITTY_MEMORY_H +#define KITTY_MEMORY_H +#include "stdint.h" + +/* + * Kernel Memory Allocation Functions: + * + * All kernel memory allocation functions have the suffix "malloc", which stands for memory allocate. + * The following prefix characters (added in the order they appear here) determines the type of allocation to take place: + * + * "k" - Allocate kernel memory. + * "z" - Zero the memory to be allocated. + * "a" - Allocate an array. + * + * Parameters: + * + * "type_size" determines the size of the type in bytes. + * "array_size" determines the size of the array. Memory to be allocated is multiplied by type_size. + */ + +char * kmalloc(uint64_t type_size); +char * kamalloc(uint64_t type_size, uint64_t array_size); +char * kzamalloc(uint64_t type_size, uint64_t array_size); +void free(char* mem_address); +#endif //KITTY_MEMORY_H diff --git a/src/util/ascii.c b/src/util/ascii.c index a580584..ed3bb5a 100644 --- a/src/util/ascii.c +++ b/src/util/ascii.c @@ -3,9 +3,10 @@ // #include "ascii.h" +#include -void from_int(int n, char dest[12]) { +void decimal_from_int32(int32_t n, char dest[12]) { char str[12]; int i, sign; if ((sign = n) < 0) n = -n; @@ -19,6 +20,23 @@ void from_int(int n, char dest[12]) { dest[i] = '\0'; + int j; + for(j = 0; j < i; j++) { + dest[j] = str[i - 1 - j]; + } +} + +void decimal_from_uint64(uint64_t n, char dest[20]) { + char str[20]; + int i; + i = 0; + do { + str[i++] = n % 10 + '0'; + } while ((n /= 10) > 0); + str[i] = '\0'; + + dest[i] = '\0'; + int j; for(j = 0; j < i; j++) { dest[j] = str[i - 1 - j]; diff --git a/src/util/ascii.h b/src/util/ascii.h index 2b1dc62..cd7ee92 100644 --- a/src/util/ascii.h +++ b/src/util/ascii.h @@ -4,11 +4,12 @@ #ifndef KITTY_ASCII_H #define KITTY_ASCII_H - +#include /* * From int takes an int argument n, destination array which must be at least length 12. */ -void from_int(int n, char dest[12]); +void decimal_from_int32(int32_t n, char dest[12]); +void decimal_from_uint64(uint64_t n, char dest[20]); #endif //KITTY_ASCII_H diff --git a/src/x86-boot/boot-sect.asm b/src/x86-boot/boot-sect.asm index 2f80b33..d91a452 100644 --- a/src/x86-boot/boot-sect.asm +++ b/src/x86-boot/boot-sect.asm @@ -208,33 +208,36 @@ jump_to_long_mode: mov ecx, 4096 rep stosd mov edi, cr3 - mov dword [edi], 0x2003 + mov dword [edi], 0x2007 add edi, 0x1000 - mov dword [edi], 0x3003 + mov dword [edi], 0x3007 add edi, 0x1000 - mov dword [edi], 0x4003 + mov dword [edi], 0x4007 add edi, 0x1000 - mov ebx, 0x00000003 + mov ebx, 0x000000007 mov ecx, 512 + map_first_two_MB: mov DWORD [edi], ebx add ebx, 0x1000 add edi, 8 loop map_first_two_MB -enable_PAE_paging: ;PAE specifically - mov eax, cr4 +enable_PAE_paging: + mov eax, cr4 ; CR4 5th bit is PAE or eax, 1 << 5 mov cr4, eax enable_paging: - mov ecx, 0xC0000080 + mov ecx, 0xC0000080 ; This is the IA32_EFER MSR rdmsr - or eax, 1 << 8 + or eax, 1 << 8 ; Enable LME (IA-32e Mode), enabling 4-level paging wrmsr - mov eax, cr0 + mov eax, cr0 ; CR0 31st bit is PG (enable paging) or eax, 1 << 31 + ; write protection disable + and eax, 0b11111111111111101111111111111111 mov cr0, eax lgdt [GDT.Pointer] jmp GDT.Code:kernel_64 @@ -251,6 +254,11 @@ GRAN_4K equ 1 << 7 SZ_32 equ 1 << 6 LONG_MODE equ 1 << 5 +; the following code populates the first 512 bytes of the drive +times 510-($-$$) db 0 ; for 510 bytes minus the beginning of file, write 0 +dw 0xAA55 ; magix number +SECTOR_TWO_BEGINS: + GDT: ; 64 bit GDT, taken from https://wiki.osdev.org/Setting_Up_Long_Mode ; CC0 Licensing (Public Domain) .Null: equ $ - GDT dq 0 @@ -273,9 +281,6 @@ GDT: ; 64 bit GDT, taken from https://wiki.osdev.org/Setting_Up_Long_Mode ; CC0 dw $ - GDT - 1 dq GDT -; the following code populates the first 512 bytes of the drive -times 510-($-$$) db 0 ; for 510 bytes minus the beginning of file, write 0 -dw 0xAA55 ; magix number LOAD_TEXT: db 0xA, 0xD,0xA, 0xD,' [ ] Default Drive',0xA, 0xD,' [ ] Floppy Drive',0xA, 0xD,' [ ] Hard Drive',0xA, 0xD db ' _ ',0xA, 0xD @@ -287,7 +292,7 @@ LOAD_TEXT: jump_to_kernel: call 0x8000 ; jump to our kernel :), this probably isn't right -[BITS 64] +[BITS 64] ; might have to modify this in the future to perform a far return. kernel_64: cli mov ax, GDT.Data @@ -301,4 +306,4 @@ kernel_64: CODE_SEG equ gdt_code - gdt_start DATA_SEG equ gdt_data - gdt_start -times 512-($-LOAD_TEXT) db 0 \ No newline at end of file +times 512-($-SECTOR_TWO_BEGINS) db 0 \ No newline at end of file