From 95cd78840f0891e60f5ebecc8a8eb4fbaf3c2ebf Mon Sep 17 00:00:00 2001 From: Danny Holman Date: Sun, 12 Jan 2025 01:17:36 -0600 Subject: PROJECT RESTRUCTURING Move the entire kernel into its own directory. Create new directories for system commands, libraries and other required essentials for a complete Unix-like operating system. Signed-off-by: Danny Holman --- arch/i386/include/kernel/asm.h | 158 ----------------------------------- arch/i386/include/kernel/gdt.h | 53 ------------ arch/i386/include/kernel/idt.h | 31 ------- arch/i386/include/kernel/multiboot.h | 102 ---------------------- arch/i386/include/kernel/paging.h | 46 ---------- arch/i386/include/kernel/pic.h | 44 ---------- arch/i386/include/kernel/pmem.h | 17 ---- arch/i386/include/kernel/syscall.h | 34 -------- arch/i386/include/kernel/timer.h | 9 -- arch/i386/include/kernel/vmem.h | 17 ---- 10 files changed, 511 deletions(-) delete mode 100644 arch/i386/include/kernel/asm.h delete mode 100644 arch/i386/include/kernel/gdt.h delete mode 100644 arch/i386/include/kernel/idt.h delete mode 100644 arch/i386/include/kernel/multiboot.h delete mode 100644 arch/i386/include/kernel/paging.h delete mode 100644 arch/i386/include/kernel/pic.h delete mode 100644 arch/i386/include/kernel/pmem.h delete mode 100644 arch/i386/include/kernel/syscall.h delete mode 100644 arch/i386/include/kernel/timer.h delete mode 100644 arch/i386/include/kernel/vmem.h (limited to 'arch/i386/include') diff --git a/arch/i386/include/kernel/asm.h b/arch/i386/include/kernel/asm.h deleted file mode 100644 index cc570c5..0000000 --- a/arch/i386/include/kernel/asm.h +++ /dev/null @@ -1,158 +0,0 @@ -#ifndef I386_ASM_H -#define I386_ASM_H - -#include -#include - -#define PCI_CONFIG_ADDR 0xCF8 -#define PCI_CONFIG_DATA 0xCFC - -#define COM_PORT 0x3F8 - -#define MAX_ISR 256 - -struct regs { - uint32_t eax; - uint32_t ebx; - uint32_t ecx; - uint32_t edx; - uint32_t esi; - uint32_t edi; - uint32_t ebp; - uint32_t esp; - - uint32_t cr0; - uint32_t cr2; - uint32_t cr3; - uint32_t cr4; -}; - -struct isr_frame { - uint32_t cr4; - uint32_t cr3; - uint32_t cr2; - uint32_t cr0; - - uint32_t edi; - uint32_t esi; - uint32_t edx; - uint32_t ecx; - uint32_t ebx; - uint32_t eax; - - uint32_t isr_vector; - uint32_t isr_err; - uint32_t eip; - uint32_t cs; - uint32_t eflags; -} __attribute__((packed)); - -void isr_stub_0(void); -void isr_stub_1(void); -void isr_stub_2(void); -void isr_stub_3(void); -void isr_stub_4(void); -void isr_stub_5(void); -void isr_stub_6(void); -void isr_stub_7(void); -void isr_stub_8(void); -void isr_stub_9(void); -void isr_stub_10(void); -void isr_stub_11(void); -void isr_stub_12(void); -void isr_stub_13(void); -void isr_stub_14(void); -void isr_stub_15(void); -void isr_stub_16(void); -void isr_stub_17(void); -void isr_stub_18(void); -void isr_stub_19(void); -void isr_stub_20(void); -void isr_stub_21(void); -void isr_stub_22(void); -void isr_stub_23(void); -void isr_stub_24(void); -void isr_stub_25(void); -void isr_stub_26(void); -void isr_stub_27(void); -void isr_stub_28(void); -void isr_stub_29(void); -void isr_stub_30(void); -void isr_stub_31(void); - -void irq_stub_0(void); -void irq_stub_1(void); -void irq_stub_2(void); -void irq_stub_3(void); -void irq_stub_4(void); -void irq_stub_5(void); -void irq_stub_6(void); -void irq_stub_7(void); -void irq_stub_8(void); -void irq_stub_9(void); -void irq_stub_10(void); -void irq_stub_11(void); -void irq_stub_12(void); -void irq_stub_13(void); -void irq_stub_14(void); -void irq_stub_15(void); - -void isr_stub_128(void); - -void aquire_lock(int *lock); -void release_lock(int *lock); - -void enable_paging(uint32_t new_cr3); -void flush_gdt(void); - -static inline void outb(uint16_t port, uint8_t value) { - __asm__ volatile("outb %0, %1" : : "a"(value), "Nd"(port)); -} - -static inline void outw(uint16_t port, uint16_t value) { - __asm__ volatile("outw %0, %1" : : "a"(value), "Nd"(port)); -} - -static inline void outl(uint16_t port, uint32_t value) { - __asm__ volatile("outl %0, %1" : : "a"(value), "Nd"(port)); -} - -static inline uint8_t inb(uint16_t port) { - uint8_t ret; - __asm__ volatile("inb %1, %0" : "=a"(ret) : "Nd"(port)); - return ret; -} - -static inline uint16_t inw(uint16_t port) { - uint16_t ret; - __asm__ volatile("inw %1, %0" : "=a"(ret) : "Nd"(port)); - return ret; -} - -static inline uint32_t inl(uint16_t port) { - uint32_t ret; - __asm__ volatile("inl %1, %0" : "=a"(ret) : "Nd"(port)); - return ret; -} - -static inline void enable_ints(void) { - __asm__ volatile("sti"); -} - -static inline void disable_ints(void) { - __asm__ volatile("cli"); -} - -static inline void flush_tss(void) { - __asm__ volatile("movw $0x28, %ax; ltr %ax"); -} - -static inline void flush_tlb(void) { - __asm__ volatile("movl %cr3, %eax; movl %eax, %cr3"); -} - -static inline void invlpg(void *addr) { - __asm__ volatile("invlpg (%0)" : : "b"(addr) : "memory"); -} - -#endif diff --git a/arch/i386/include/kernel/gdt.h b/arch/i386/include/kernel/gdt.h deleted file mode 100644 index ec02719..0000000 --- a/arch/i386/include/kernel/gdt.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef I386_GDT_H -#define I386_GDT_H - -#include - -struct gdt_entry { - uint16_t limit_low; - uint16_t base_low; - uint8_t base_middle; - uint8_t access; - uint8_t gran; - uint8_t base_high; -} __attribute__((packed)); - -struct gdt_ptr { - uint16_t limit; - uint32_t base; -} __attribute__((packed)); - -struct tss_entry { - uint32_t link; - uint32_t esp0; - uint32_t ss0; - uint32_t esp1; - uint32_t ss2; - uint32_t cr3; - uint32_t eip; - uint32_t eflags; - uint32_t eax; - uint32_t ecx; - uint32_t edx; - uint32_t ebx; - uint32_t esp; - uint32_t ebp; - uint32_t esi; - uint32_t edi; - uint32_t es; - uint32_t cs; - uint32_t ss; - uint32_t ds; - uint32_t fs; - uint32_t gs; - uint32_t ldtr; - uint16_t trap; - uint16_t iomap_base; -} __attribute__((packed)); - -void gdt_set_gate(int num, uint32_t base, uint32_t limit, uint8_t access, uint8_t gran); -void write_tss(int num, uint32_t ss0, uint32_t esp0); -void set_kernel_esp(uint32_t esp); -void gdt_install(void); - -#endif diff --git a/arch/i386/include/kernel/idt.h b/arch/i386/include/kernel/idt.h deleted file mode 100644 index 29ec39f..0000000 --- a/arch/i386/include/kernel/idt.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef I386_IDT_H -#define I386_IDT_H - -#include - -#define SEGMENT_PRESENT 0x80 -#define SEGMENT_RING0 0x00 -#define SEGMENT_RING3 0x60 -#define SEGMENT_STORAGE 0x00 -#define SEGMENT_INTERRUPT 0x0E -#define IDT_EXCEPTION (SEGMENT_PRESENT | SEGMENT_INTERRUPT) -#define IDT_INTERRUPT (SEGMENT_PRESENT | SEGMENT_INTERRUPT) - -#define IDT_MAX_DESCRIPTORS 256 - -struct idt_entry { - uint16_t isr_low; - uint16_t kernel_cs; - uint8_t reserved; - uint8_t flags; - uint16_t isr_high; -} __attribute__((packed)); - -struct idt_ptr { - uint16_t limit; - uint32_t base; -} __attribute__((packed)); - -void idt_install(void); - -#endif diff --git a/arch/i386/include/kernel/multiboot.h b/arch/i386/include/kernel/multiboot.h deleted file mode 100644 index abbd8a9..0000000 --- a/arch/i386/include/kernel/multiboot.h +++ /dev/null @@ -1,102 +0,0 @@ -#ifndef I386_MULTIBOOT_H -#define I386_MULTIBOOT_H - -#include - -#define MBOOT_HEADER_MAGIC 0x1BADB002 -#define MBOOT_LOADER_MAGIC 0x2BADB002 - -// Multiboot flags -#define MBOOT_INFO_MMAP 0x00000001 -#define MBOOT_INFO_BOOTDEV 0x00000002 -#define MBOOT_INFO_CMDLINE 0x00000004 -#define MBOOT_INFO_MODS 0x00000008 -#define MBOOT_INFO_AOUT_SYMS 0x00000010 -#define MBOOT_INFO_ELF_HEADER 0x00000020 -#define MBOOT_INFO_MEM_MAP 0x00000040 -#define MBOOT_INFO_DRIVE_INFO 0x00000080 -#define MBOOT_INFO_CONFIG_TBL 0x00000100 -#define MBOOT_INFO_BL_NAME 0x00000200 -#define MBOOT_INFO_APM_TBL 0x00000400 -#define MBOOT_INFO_VBE 0x00000800 -#define MBOOT_INFO_FRAMEBUFFER 0x00001000 - -// Memory types -#define MBOOT_MEM_AVAILABLE 1 -#define MBOOT_MEM_RESERVED 2 -#define MBOOT_MEM_ACPI_REC 3 -#define MBOOT_MEM_NVS 4 -#define MBOOT_MEM_BADRAM 5 - -struct aout_symbol_table { - uint32_t tabsize; - uint32_t strsize; - uint32_t addr; - uint32_t reserved; -}; - -struct elf_section_header { - uint32_t num; - uint32_t size; - uint32_t addr; - uint32_t shndx; -}; - -struct mboot_header { - uint32_t magic; - uint32_t flags; - uint32_t checksum; - uint32_t header_addr; - uint32_t load_addr; - uint32_t load_end_addr; - uint32_t bss_end_addr; - uint32_t entry_addr; - uint32_t mode_type; - uint32_t width; - uint32_t height; - uint32_t depth; -}; - -struct mboot_info { - uint32_t flags; - uint32_t mem_lower; - uint32_t mem_upper; - uint32_t boot_device; - uint32_t cmdline; - uint32_t mods_count; - uint32_t mods_addr; - union { - struct aout_symbol_table aout_sym; - struct elf_section_header elf_sec; - } u; - uint32_t mmap_length; - uint32_t mmap_addr; - uint32_t drives_length; - uint32_t drives_addr; - uint32_t config_table; - uint32_t boot_loader_name; - uint32_t apm_table; - uint32_t vbe_control_info; - uint32_t vbe_mode_info; - uint16_t vbe_mode; - uint16_t vbe_interface_seg; - uint16_t vbe_interface_off; - uint16_t vbe_interface_len; - uint64_t framebuffer_addr; - uint32_t framebuffer_pitch; - uint32_t framebuffer_width; - uint32_t framebuffer_height; - uint8_t framebuffer_bpp; - uint8_t framebuffer_type; -}; - -struct mboot_mmap_entry { - uint32_t size; - uint32_t addr_low; - uint32_t addr_high; - uint32_t len_low; - uint32_t len_high; - uint32_t type; -} __attribute__((packed)); - -#endif diff --git a/arch/i386/include/kernel/paging.h b/arch/i386/include/kernel/paging.h deleted file mode 100644 index d8bb8f3..0000000 --- a/arch/i386/include/kernel/paging.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef I386_PAGING_H -#define I386_PAGING_H - -#include -#include -#include - -#define PAGE_SIZE 4096 - -#define PD_PRES 0x0001 -#define PD_RW 0x0002 -#define PD_USR 0x0004 -#define PD_PWT 0x0008 -#define PD_PCD 0x0010 -#define PD_ACC 0x0020 -#define PD_DIRTY 0x0040 -#define PD_PS 0x0080 -#define PD_GLOB 0x0100 -#define PD_PAT 0x1000 - -#define ERR_PRESENT 0x1 -#define ERR_RW 0x2 -#define ERR_USER 0x4 -#define ERR_RESERVED 0x8 -#define ERR_INST 0x10 - -#define PGROUNDUP(size) (((size)+PAGE_SIZE-1) & ~(PAGE_SIZE-1)) -#define PGROUNDDN(size) (((size)) & ~(PAGE_SIZE-1)) - -#define GET_PADDR(x) (((uint32_t)(x)) - 0xC0000000) -#define GET_VADDR(x) (((uint32_t)(x)) + 0xC0000000) - -#define GET_PDX(x) ((uintptr_t)(x) >> 22) -#define GET_PTX(x) (((uintptr_t)(x) >> 12) & 0x03FF) - -uintptr_t get_physaddr(void *vaddr); - -void paging_init(void); - -uintptr_t init_page_directory(void); -void map_page(uintptr_t paddr, uintptr_t vaddr, uint32_t flags); -void unmap_page(uintptr_t vaddr); - -void page_fault_handler(struct isr_frame *frame); - -#endif diff --git a/arch/i386/include/kernel/pic.h b/arch/i386/include/kernel/pic.h deleted file mode 100644 index 187d553..0000000 --- a/arch/i386/include/kernel/pic.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef I386_PIC_H -#define I386_PIC_H - -#include -#include - -#define PIC1 0x20 -#define PIC2 0x28 -#define PIC1_COMMAND PIC1 -#define PIC1_DATA (PIC1+1) -#define PIC2_COMMAND PIC2 -#define PIC2_DATA (PIC2+1) - -#define ICW1_ICW4 0x01 -#define ICW1_SINGLE 0x02 -#define ICW1_INTERVAL4 0x04 -#define ICW1_LEVEL 0x08 -#define ICW1_INIT 0x10 - -#define ICW4_8086 0x01 -#define ICW4_AUTO 0x02 -#define ICW4_BUF_SLAVE 0x08 -#define ICW4_BUF_MASTER 0x0C -#define ICW4_SFNM 0x10 - -#define PIC_READ_IRR 0x0A -#define PIC_READ_ISR 0x0B - -static inline void io_wait(void) { - outb(0x80, 0); -} - -void pic_eoi(uint8_t irq); -void pic_remap(void); -uint16_t pic_get_irr(void); -uint16_t pic_get_isr(void); - -void register_irq_handler(uint8_t irq, void (*handler)(struct isr_frame *frame)); -void irq_dispatch(struct isr_frame *frame); - -void irq_set_mask(uint8_t irq); -void irq_clear_mask(uint8_t irq); - -#endif diff --git a/arch/i386/include/kernel/pmem.h b/arch/i386/include/kernel/pmem.h deleted file mode 100644 index e6e4f57..0000000 --- a/arch/i386/include/kernel/pmem.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef I386_PMEM_H -#define I386_PMEM_H - -#include -#include -#include - -struct pfa_page { - struct pfa_page *next; -}; - -void pfa_init(struct mboot_info *header); - -void pfa_free_dma(uintptr_t paddr, size_t num_pages); -void pfa_free(uintptr_t paddr, size_t num_pages); - -#endif diff --git a/arch/i386/include/kernel/syscall.h b/arch/i386/include/kernel/syscall.h deleted file mode 100644 index a657527..0000000 --- a/arch/i386/include/kernel/syscall.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef I386_SYSCALL_H -#define I386_SYSCALL_H - -#include -#include -#include - -// Unix standard calls -#define SYS_FORK 1 -#define SYS_EXIT 2 -#define SYS_WAIT 3 -#define SYS_PIPE 4 -#define SYS_READ 5 -#define SYS_WRITE 6 -#define SYS_KILL 7 -#define SYS_FSTAT 8 -#define SYS_CHDIR 9 -#define SYS_DUP 10 -#define SYS_GETPID 11 -#define SYS_SLEEP 12 -#define SYS_OPEN 13 -#define SYS_MKNOD 14 -#define SYS_UNLINK 15 -#define SYS_LINK 16 -#define SYS_MKDIR 17 -#define SYS_CLOSE 18 -#define SYS_EXEC 19 - -#define SYS_HALT 87 -#define SYS_REBOOT 88 - -void handle_syscall(struct isr_frame *frame); - -#endif diff --git a/arch/i386/include/kernel/timer.h b/arch/i386/include/kernel/timer.h deleted file mode 100644 index c0b3a73..0000000 --- a/arch/i386/include/kernel/timer.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef I386_TIMER_H -#define I386_TIMER_H - -#include - -void timer_handler(struct isr_frame *frame); -void timer_init(void); - -#endif diff --git a/arch/i386/include/kernel/vmem.h b/arch/i386/include/kernel/vmem.h deleted file mode 100644 index 94aa32d..0000000 --- a/arch/i386/include/kernel/vmem.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef I386_VMEM_H -#define I386_VMEM_H - -extern uintptr_t _kernel_start; -extern uintptr_t _kernel_end; - -#define KSTART ((uintptr_t)&_kernel_start) -#define KEND ((uintptr_t)&_kernel_end - 0xC0000000) - -#define KHEAP_START (GET_VADDR(KEND) + 0x2000) -#define KHEAP_STOP 0xFF7FF000 - -#define PAGE_DIR_MAP 0xFFFFF000 -#define PAGE_TAB_MAP 0xFFC00000 -#define PAGE_TMP_MAP 0xFFBFF000 - -#endif -- cgit v1.2.3