diff options
Diffstat (limited to '')
-rw-r--r-- | arch/i386/boot/boot.s | 149 | ||||
-rw-r--r-- | arch/i386/boot/crti.s | 15 | ||||
-rw-r--r-- | arch/i386/boot/crtn.s | 7 | ||||
-rw-r--r-- | arch/i386/include/kernel/multiboot.h | 102 | ||||
-rw-r--r-- | arch/i386/kernel/isr.s | 129 | ||||
-rw-r--r-- | arch/i386/kernel/jump_userspace.s | 21 | ||||
-rw-r--r-- | arch/i386/kernel/spinlock.s | 30 | ||||
-rw-r--r-- | arch/i386/kernel/stack_trace.s | 31 | ||||
-rw-r--r-- | arch/i386/kernel/switch_thread.s | 28 | ||||
-rw-r--r-- | arch/i386/linker.ld | 30 | ||||
-rw-r--r-- | arch/i386/make.config | 20 | ||||
-rw-r--r-- | kernel/arch/x86/include/kernel/asm.h (renamed from arch/i386/include/kernel/asm.h) | 15 | ||||
-rw-r--r-- | kernel/arch/x86/include/kernel/gdt.h (renamed from arch/i386/include/kernel/gdt.h) | 2 | ||||
-rw-r--r-- | kernel/arch/x86/include/kernel/idt.h (renamed from arch/i386/include/kernel/idt.h) | 0 | ||||
-rw-r--r-- | kernel/arch/x86/include/kernel/paging.h (renamed from arch/i386/include/kernel/paging.h) | 1 | ||||
-rw-r--r-- | kernel/arch/x86/include/kernel/pic.h (renamed from arch/i386/include/kernel/pic.h) | 0 | ||||
-rw-r--r-- | kernel/arch/x86/include/kernel/pmem.h (renamed from arch/i386/include/kernel/pmem.h) | 4 | ||||
-rw-r--r-- | kernel/arch/x86/include/kernel/syscall.h (renamed from arch/i386/include/kernel/syscall.h) | 0 | ||||
-rw-r--r-- | kernel/arch/x86/include/kernel/timer.h (renamed from arch/i386/include/kernel/timer.h) | 0 | ||||
-rw-r--r-- | kernel/arch/x86/include/kernel/vmem.h (renamed from arch/i386/include/kernel/vmem.h) | 0 | ||||
-rw-r--r-- | kernel/arch/x86/kernel/gdt.c (renamed from arch/i386/kernel/gdt.c) | 14 | ||||
-rw-r--r-- | kernel/arch/x86/kernel/idt.c (renamed from arch/i386/kernel/idt.c) | 0 | ||||
-rw-r--r-- | kernel/arch/x86/kernel/kmalloc.c (renamed from arch/i386/kernel/kmalloc.c) | 2 | ||||
-rw-r--r-- | kernel/arch/x86/kernel/multiboot.c (renamed from arch/i386/kernel/multiboot.c) | 0 | ||||
-rw-r--r-- | kernel/arch/x86/kernel/paging.c (renamed from arch/i386/kernel/paging.c) | 0 | ||||
-rw-r--r-- | kernel/arch/x86/kernel/pic.c (renamed from arch/i386/kernel/pic.c) | 0 | ||||
-rw-r--r-- | kernel/arch/x86/kernel/pmem.c (renamed from arch/i386/kernel/pmem.c) | 21 | ||||
-rw-r--r-- | kernel/arch/x86/kernel/serial.c (renamed from arch/i386/kernel/serial.c) | 0 | ||||
-rw-r--r-- | kernel/arch/x86/kernel/syscall.c (renamed from arch/i386/kernel/syscall.c) | 4 | ||||
-rw-r--r-- | kernel/arch/x86/kernel/timer.c (renamed from arch/i386/kernel/timer.c) | 5 |
30 files changed, 49 insertions, 581 deletions
diff --git a/arch/i386/boot/boot.s b/arch/i386/boot/boot.s deleted file mode 100644 index 5357910..0000000 --- a/arch/i386/boot/boot.s +++ /dev/null @@ -1,149 +0,0 @@ -.set ALIGN, 1<<0 -.set MEMINFO, 1<<1 -.set FLAGS, ALIGN | MEMINFO -.set MAGIC, 0x1BADB002 -.set CHECKSUM, -(MAGIC + FLAGS) - -.section .multiboot.data, "aw" -.align 4 -.long MAGIC -.long FLAGS -.long CHECKSUM - -.section .bootstrap_stack, "aw", @nobits -stack_bottom: -.skip 16384 -stack_top: - -.section .bss, "aw", @nobits - .align 4096 -boot_page_directory: - .skip 4096 -boot_page_table0: - .skip 4096 -boot_page_table1: - .skip 4096 - -.section .multiboot.text, "a" -.global _start -.type _start, @function -_start: - movl $(boot_page_table0 - 0xC0000000), %edi - movl $0, %esi - movl $1023, %ecx - -1: cmpl $_kernel_start, %esi - jl 2f - cmpl $(_kernel_end - 0xC0000000), %esi - jge 3f - - movl %esi, %edx - orl $0x003, %edx - movl %edx, (%edi) - -2: addl $4096, %esi - addl $4, %edi - loop 1b - - -3: movl $boot_page_directory, %ecx - subl $0xC0000000, %ecx - orl $0x003, %ecx - movl %ecx, boot_page_directory - 0xC0000000 + 1023 * 4 - - movl $boot_page_table0, %ecx - subl $0xC0000000, %ecx - orl $0x003, %ecx - movl %ecx, boot_page_directory - 0xC0000000 - movl %ecx, boot_page_directory - 0xC0000000 + 768 * 4 - - movl $boot_page_table1, %ecx - subl $0xC0000000, %ecx - orl $0x003, %ecx - movl %ecx, boot_page_directory - 0xC0000000 + 1022 * 4 - - movl $boot_page_directory, %ecx - subl $0xC0000000, %ecx - movl %ecx, %cr3 - - movl %cr0, %ecx - orl $0x80000000, %ecx - movl %ecx, %cr0 - - lea 4f, %ecx - jmp *%ecx - -.section .text - -4: movl $stack_top, %esp - and $-16, %esp - - call setup_stack_guard - - xorl %ebp, %ebp - pushl %ebx - pushl %eax - call i386_entry - - cli -1: hlt - jmp 1b - -.global setup_stack_guard -.type setup_stack_guard, @function -setup_stack_guard: - pushl %eax - pushl %ebx - pushl %ecx - - movl $1, %eax - movl $0, %ecx - cpuid - shrl $30, %ecx - andl $1, %ecx - jnz start_loop - jmp fail -start_loop: - rdrand %eax - jc done - loop start_loop -fail: - movl $-1, %eax -done: - movl %eax, __stack_chk_guard - popl %ecx - popl %ebx - popl %eax - ret - -.global enable_paging -.type enable_paging, @function -enable_paging: - pushl %ebp - movl %esp, %ebp - - movl 8(%esp), %eax - movl %eax, %cr3 - - movl %cr0, %eax - orl $0x80000001, %eax - movl %eax, %cr0 - - movl $0, %eax - popl %ebp - ret - -.global flush_gdt -.type flush_gdt, @function -flush_gdt: - cli - lgdt (gp) - movw $0x10, %ax - movw %ax, %ds - movw %ax, %es - movw %ax, %fs - movw %ax, %gs - movw %ax, %ss - jmp $0x08, $.flush -.flush: - ret diff --git a/arch/i386/boot/crti.s b/arch/i386/boot/crti.s deleted file mode 100644 index 8386b77..0000000 --- a/arch/i386/boot/crti.s +++ /dev/null @@ -1,15 +0,0 @@ -.section .init - -.global _init -.type _init, @function -_init: - pushl %ebp - movl %esp, %ebp - -.section .fini - -.global _fini -.type _fini, @function -_fini: - pushl %ebp - movl %esp, %ebp diff --git a/arch/i386/boot/crtn.s b/arch/i386/boot/crtn.s deleted file mode 100644 index 447afb1..0000000 --- a/arch/i386/boot/crtn.s +++ /dev/null @@ -1,7 +0,0 @@ -.section .init - popl %ebp - ret - -.section .fini - popl %ebp - ret 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 <stdint.h> - -#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/kernel/isr.s b/arch/i386/kernel/isr.s deleted file mode 100644 index 55db35e..0000000 --- a/arch/i386/kernel/isr.s +++ /dev/null @@ -1,129 +0,0 @@ -.section .text - -.macro isr_err_stub num -.global isr_stub_\num -.type isr_stub_\num, @function -isr_stub_\num: - cli - pushl $\num - jmp isr_frame_asm -.endm -.macro isr_no_err_stub num -.global isr_stub_\num -.type isr_stub_\num, @function -isr_stub_\num: - cli - pushl $0 - pushl $\num - jmp isr_frame_asm -.endm - -.macro irq_stub num -.global irq_stub_\num -.type irq_stub_\num, @function -irq_stub_\num: - cli - pushl $0 - pushl $\num+32 - jmp isr_frame_asm -.endm - -.global syscall_stub -syscall_stub: - cli - pushl $0 - pushl $0x80 - jmp isr_frame_asm - -isr_frame_asm: - pushl %eax - pushl %ebx - pushl %ecx - pushl %edx - pushl %esi - pushl %edi - - movl %cr0, %eax - pushl %eax - movl %cr2, %eax - pushl %eax - movl %cr3, %eax - pushl %eax - movl %cr4, %eax - pushl %eax - - pushl %esp - call set_kernel_esp - addl $4, %esp - - cld - call interrupt_handler - - popl %eax - movl %eax, %cr4 - popl %eax - movl %eax, %cr3 - popl %eax - movl %eax, %cr2 - popl %eax - movl %eax, %cr0 - - popl %edi - popl %esi - popl %edx - popl %ecx - popl %ebx - popl %eax - addl $8, %esp - - iret - -isr_no_err_stub 0 -isr_no_err_stub 1 -isr_no_err_stub 2 -isr_no_err_stub 3 -isr_no_err_stub 4 -isr_no_err_stub 5 -isr_no_err_stub 6 -isr_no_err_stub 7 -isr_err_stub 8 -isr_no_err_stub 9 -isr_err_stub 10 -isr_err_stub 11 -isr_err_stub 12 -isr_err_stub 13 -isr_err_stub 14 -isr_no_err_stub 15 -isr_no_err_stub 16 -isr_err_stub 17 -isr_no_err_stub 18 -isr_no_err_stub 19 -isr_no_err_stub 20 -isr_err_stub 21 -isr_no_err_stub 22 -isr_no_err_stub 23 -isr_no_err_stub 24 -isr_no_err_stub 25 -isr_no_err_stub 26 -isr_no_err_stub 27 -isr_no_err_stub 28 -isr_err_stub 29 -isr_err_stub 30 -isr_no_err_stub 31 - -irq_stub 0 -irq_stub 1 -irq_stub 2 -irq_stub 3 -irq_stub 4 -irq_stub 5 -irq_stub 6 -irq_stub 7 -irq_stub 8 -irq_stub 9 -irq_stub 10 -irq_stub 11 -irq_stub 12 -irq_stub 13 -irq_stub 14 -irq_stub 15 diff --git a/arch/i386/kernel/jump_userspace.s b/arch/i386/kernel/jump_userspace.s deleted file mode 100644 index add144a..0000000 --- a/arch/i386/kernel/jump_userspace.s +++ /dev/null @@ -1,21 +0,0 @@ -.global jump_userspace -.type jump_userspace, @function -jump_userspace: - movw $0x23, %ax - movw %ax, %ds - movw %ax, %es - movw %ax, %fs - movw %ax, %gs - - movl %esp, %eax - pushl $0x23 - pushl %eax - pushf - push $0x1B - pushl $start_init - - pushl %esp - call set_kernel_esp - addl $4, %esp - - iret diff --git a/arch/i386/kernel/spinlock.s b/arch/i386/kernel/spinlock.s deleted file mode 100644 index c8235ca..0000000 --- a/arch/i386/kernel/spinlock.s +++ /dev/null @@ -1,30 +0,0 @@ -.section .text - -.global aquire_lock -.type aquire_lock, @function -aquire_lock: - pushl %ebp - movl %esp, %ebp -locked: - movl 8(%esp), %eax - lock incl (%eax) - jc spin_wait - - popl %ebp - ret -spin_wait: - test %eax, 1 - jnz spin_wait - jmp locked - -.global release_lock -.type release_lock, @function -release_lock: - pushl %ebp - movl %esp, %ebp - - movl 8(%ebp), %eax - lock decl (%eax) - - popl %ebp - ret diff --git a/arch/i386/kernel/stack_trace.s b/arch/i386/kernel/stack_trace.s deleted file mode 100644 index fbd77ed..0000000 --- a/arch/i386/kernel/stack_trace.s +++ /dev/null @@ -1,31 +0,0 @@ -.section .text - -.global walk_stack -.type walk_stack, @function -walk_stack: - pushl %ebp - movl %esp, %ebp - - pushl %edi - movl -4(%ebp), %edi - pushl %ebx - movl -8(%ebp), %ebx - - xorl %eax, %eax - movl 8(%esp), %ebx - movl 16(%esp), %edi - movl 20(%esp), %ecx -walk: - testl %ebx, %ebx - jz done - movl 4(%ebx), %edx - movl 0(%ebx), %ebx - movl %edx, (%edi) - addl $4, %edi - inc %eax - loop walk -done: - popl %ebx - popl %edi - popl %ebp - ret diff --git a/arch/i386/kernel/switch_thread.s b/arch/i386/kernel/switch_thread.s deleted file mode 100644 index f1168d5..0000000 --- a/arch/i386/kernel/switch_thread.s +++ /dev/null @@ -1,28 +0,0 @@ -.global switch_thread -.type switch_thread, @function -switch_thread: - pushl %ebp - movl %esp, %ebp - - pushl %ebx - pushl %esi - pushl %edi - pushl %ebp - - movl 8(%ebp), %esi - movl 12(%ebp), %edi - - movl %esp, (%edi); - movl %cr3, %ecx - movl %ecx, 4(%edi) - - movl (%esi), %esp - movl 4(%esi), %ecx - movl %ecx, %cr3 - - popl %ebp - popl %edi - popl %esi - popl %ebx - popl %ebp - ret diff --git a/arch/i386/linker.ld b/arch/i386/linker.ld deleted file mode 100644 index 734310f..0000000 --- a/arch/i386/linker.ld +++ /dev/null @@ -1,30 +0,0 @@ -ENTRY(_start) - -SECTIONS { - . = 0x00100000; - _kernel_start = .; - .multiboot.data : { - *(.multiboot.data) - } - .multiboot.text : { - *(.multiboot.text) - } - - . += 0xC0000000; - .text ALIGN(4K) : AT(ADDR(.text) - 0xC0000000) { - *(.text) - } - .rodata ALIGN(4K) : AT(ADDR(.rodata) - 0xC0000000) { - *(.rodata) - } - .data ALIGN(4K) : AT(ADDR(.data) - 0xC0000000) { - *(.data) - } - .bss ALIGN(4K) : AT(ADDR(.bss) - 0xC0000000) { - *(COMMON) - *(.bss) - *(.bootstrap_stack) - } - - _kernel_end = .; -} diff --git a/arch/i386/make.config b/arch/i386/make.config deleted file mode 100644 index 557f01a..0000000 --- a/arch/i386/make.config +++ /dev/null @@ -1,20 +0,0 @@ -KERNEL_ARCH_INCLUDE=$(ARCHDIR)/include -KERNEL_ARCH_CFLAGS=-I$(KERNEL_ARCH_INCLUDE) -KERNEL_ARCH_LDFLAGS= -KERNEL_ARCH_LIBS= - -KERNEL_ARCH_OBJS=$(ARCHDIR)/boot/boot.o \ - $(ARCHDIR)/kernel/idt.o \ - $(ARCHDIR)/kernel/gdt.o \ - $(ARCHDIR)/kernel/isr.o \ - $(ARCHDIR)/kernel/stack_trace.o \ - $(ARCHDIR)/kernel/multiboot.o \ - $(ARCHDIR)/kernel/serial.o \ - $(ARCHDIR)/kernel/pic.o \ - $(ARCHDIR)/kernel/timer.o \ - $(ARCHDIR)/kernel/spinlock.o \ - $(ARCHDIR)/kernel/syscall.o \ - $(ARCHDIR)/kernel/paging.o \ - $(ARCHDIR)/kernel/pmem.o \ - $(ARCHDIR)/kernel/kmalloc.o \ - $(ARCHDIR)/kernel/switch_thread.o \ diff --git a/arch/i386/include/kernel/asm.h b/kernel/arch/x86/include/kernel/asm.h index cc570c5..18f53c4 100644 --- a/arch/i386/include/kernel/asm.h +++ b/kernel/arch/x86/include/kernel/asm.h @@ -3,6 +3,7 @@ #include <kernel/gdt.h> #include <stdint.h> +#include <cpuid.h> #define PCI_CONFIG_ADDR 0xCF8 #define PCI_CONFIG_DATA 0xCFC @@ -47,6 +48,12 @@ struct isr_frame { uint32_t eflags; } __attribute__((packed)); +struct cpuid_info { + char vendorID[12]; + uint32_t feat_ecx; + uint32_t feat_edx; +}; + void isr_stub_0(void); void isr_stub_1(void); void isr_stub_2(void); @@ -99,12 +106,14 @@ 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); +int cpuid_check(void); void flush_gdt(void); +static inline void cpuid(int code, uint32_t *ecx, uint32_t *ebx) { + __asm__ volatile("cpuid" : "=a"(*ecx), "=d"(*ebx) : "a"(code) : "ecx","ebx"); +} + static inline void outb(uint16_t port, uint8_t value) { __asm__ volatile("outb %0, %1" : : "a"(value), "Nd"(port)); } diff --git a/arch/i386/include/kernel/gdt.h b/kernel/arch/x86/include/kernel/gdt.h index ec02719..aa05408 100644 --- a/arch/i386/include/kernel/gdt.h +++ b/kernel/arch/x86/include/kernel/gdt.h @@ -14,7 +14,7 @@ struct gdt_entry { struct gdt_ptr { uint16_t limit; - uint32_t base; + uint64_t base; } __attribute__((packed)); struct tss_entry { diff --git a/arch/i386/include/kernel/idt.h b/kernel/arch/x86/include/kernel/idt.h index 29ec39f..29ec39f 100644 --- a/arch/i386/include/kernel/idt.h +++ b/kernel/arch/x86/include/kernel/idt.h diff --git a/arch/i386/include/kernel/paging.h b/kernel/arch/x86/include/kernel/paging.h index d8bb8f3..3a3c298 100644 --- a/arch/i386/include/kernel/paging.h +++ b/kernel/arch/x86/include/kernel/paging.h @@ -2,7 +2,6 @@ #define I386_PAGING_H #include <kernel/asm.h> -#include <kernel/multiboot.h> #include <stdint.h> #define PAGE_SIZE 4096 diff --git a/arch/i386/include/kernel/pic.h b/kernel/arch/x86/include/kernel/pic.h index 187d553..187d553 100644 --- a/arch/i386/include/kernel/pic.h +++ b/kernel/arch/x86/include/kernel/pic.h diff --git a/arch/i386/include/kernel/pmem.h b/kernel/arch/x86/include/kernel/pmem.h index e6e4f57..ea4fe29 100644 --- a/arch/i386/include/kernel/pmem.h +++ b/kernel/arch/x86/include/kernel/pmem.h @@ -1,7 +1,6 @@ #ifndef I386_PMEM_H #define I386_PMEM_H -#include <kernel/multiboot.h> #include <stdint.h> #include <stddef.h> @@ -11,6 +10,9 @@ struct pfa_page { void pfa_init(struct mboot_info *header); +uintptr_t pfa_alloc_dma(size_t num_pages); +uintptr_t pfa_alloc(size_t num_pages); + void pfa_free_dma(uintptr_t paddr, size_t num_pages); void pfa_free(uintptr_t paddr, size_t num_pages); diff --git a/arch/i386/include/kernel/syscall.h b/kernel/arch/x86/include/kernel/syscall.h index a657527..a657527 100644 --- a/arch/i386/include/kernel/syscall.h +++ b/kernel/arch/x86/include/kernel/syscall.h diff --git a/arch/i386/include/kernel/timer.h b/kernel/arch/x86/include/kernel/timer.h index c0b3a73..c0b3a73 100644 --- a/arch/i386/include/kernel/timer.h +++ b/kernel/arch/x86/include/kernel/timer.h diff --git a/arch/i386/include/kernel/vmem.h b/kernel/arch/x86/include/kernel/vmem.h index 94aa32d..94aa32d 100644 --- a/arch/i386/include/kernel/vmem.h +++ b/kernel/arch/x86/include/kernel/vmem.h diff --git a/arch/i386/kernel/gdt.c b/kernel/arch/x86/kernel/gdt.c index 0d9e1d2..57424aa 100644 --- a/arch/i386/kernel/gdt.c +++ b/kernel/arch/x86/kernel/gdt.c @@ -18,7 +18,7 @@ void gdt_set_gate(int num, uint32_t base, uint32_t limit, uint8_t access, uint8_ } void write_tss(int num, uint32_t ss0, uint32_t esp0) { - uint32_t base = (uint32_t)&tss_entry; + uint64_t base = (uint64_t)&tss_entry; uint32_t limit = base + sizeof(struct tss_entry); gdt_set_gate(num, base, limit, 0x89, 0x00); @@ -35,13 +35,9 @@ void write_tss(int num, uint32_t ss0, uint32_t esp0) { tss_entry.iomap_base = sizeof(tss_entry); } -void set_kernel_esp(uint32_t esp) { - tss_entry.esp0 = esp; -} - void gdt_install(void) { gp.limit = (sizeof(struct gdt_entry) * 6) - 1; - gp.base = (uint32_t)&desc; + gp.base = (uint64_t)&desc; gdt_set_gate(0, 0, 0, 0, 0); gdt_set_gate(1, 0, 0xFFFFF, 0x9A, 0xCF); @@ -49,9 +45,9 @@ void gdt_install(void) { gdt_set_gate(3, 0, 0xFFFFF, 0xFA, 0xCF); gdt_set_gate(4, 0, 0xFFFFF, 0xF2, 0xCF); - uint32_t esp; - __asm__ volatile("movl %%esp, %0" : "=r"(esp)); - write_tss(5, 0x10, esp); + uint64_t rsp; + __asm__ volatile("movq %%rsp, %0" : "=r"(rsp)); + write_tss(5, 0x10, rsp); flush_gdt(); flush_tss(); diff --git a/arch/i386/kernel/idt.c b/kernel/arch/x86/kernel/idt.c index a178801..a178801 100644 --- a/arch/i386/kernel/idt.c +++ b/kernel/arch/x86/kernel/idt.c diff --git a/arch/i386/kernel/kmalloc.c b/kernel/arch/x86/kernel/kmalloc.c index ea77428..9e5254c 100644 --- a/arch/i386/kernel/kmalloc.c +++ b/kernel/arch/x86/kernel/kmalloc.c @@ -56,6 +56,8 @@ void* kmalloc(size_t sz) { } void kfree(void *ptr) { + if (ptr == NULL) + return; struct mem_block *temp = first; while (temp != NULL) { if (temp->start == (uintptr_t)ptr) { diff --git a/arch/i386/kernel/multiboot.c b/kernel/arch/x86/kernel/multiboot.c index dedf163..dedf163 100644 --- a/arch/i386/kernel/multiboot.c +++ b/kernel/arch/x86/kernel/multiboot.c diff --git a/arch/i386/kernel/paging.c b/kernel/arch/x86/kernel/paging.c index a0bbb92..a0bbb92 100644 --- a/arch/i386/kernel/paging.c +++ b/kernel/arch/x86/kernel/paging.c diff --git a/arch/i386/kernel/pic.c b/kernel/arch/x86/kernel/pic.c index 0d29473..0d29473 100644 --- a/arch/i386/kernel/pic.c +++ b/kernel/arch/x86/kernel/pic.c diff --git a/arch/i386/kernel/pmem.c b/kernel/arch/x86/kernel/pmem.c index 40e3400..edf71d9 100644 --- a/arch/i386/kernel/pmem.c +++ b/kernel/arch/x86/kernel/pmem.c @@ -6,6 +6,7 @@ #include <libk/io.h> #include <libk/string.h> +static uintptr_t bitmap[5]; static struct pfa_page freelist; void pfa_init(struct mboot_info *header) { @@ -17,6 +18,9 @@ void pfa_init(struct mboot_info *header) { } } +uintptr_t pfa_alloc_dma(size_t num_pages) { +} + uintptr_t pfa_alloc(size_t num_pages) { struct pfa_page *temp = (struct pfa_page*)PAGE_TMP_MAP; map_page(freelist.next, PAGE_TMP_MAP, PD_PRES | PD_RW); @@ -27,6 +31,23 @@ uintptr_t pfa_alloc(size_t num_pages) { return ret; } +void pfa_free_dma(uintptr_t paddr, size_t num_pages) { + if (paddr % PAGE_SIZE != 0) + panic("Task attempted to free non-aligned memory"); + if (paddr >= KSTART && paddr < KEND) + return; + if (paddr >= 0x00080000 && paddr < 0x00100000) + return; + + int index = 0; + int bit = 0; + for (uintptr_t i = paddr; i < paddr + (num_pages * PAGE_SIZE); i += PAGE_SIZE) { + index = i / PAGE_SIZE / 32; + bit = i / PAGE_SIZE % 32; + bitmap[index] |= 1 << bit; + } +} + void pfa_free(uintptr_t paddr, size_t num_pages) { uintptr_t addr; struct pfa_page *temp = (struct pfa_page*)PAGE_TMP_MAP; diff --git a/arch/i386/kernel/serial.c b/kernel/arch/x86/kernel/serial.c index dc2a8bd..dc2a8bd 100644 --- a/arch/i386/kernel/serial.c +++ b/kernel/arch/x86/kernel/serial.c diff --git a/arch/i386/kernel/syscall.c b/kernel/arch/x86/kernel/syscall.c index 200af4f..1fa73e9 100644 --- a/arch/i386/kernel/syscall.c +++ b/kernel/arch/x86/kernel/syscall.c @@ -19,7 +19,7 @@ void handle_syscall(struct isr_frame *frame) { sys_write(frame); break; default: - panic("Invalid system call number"); + kprintf("Invalid system call number %d\n", frame->eax); + break; } - return 0; } diff --git a/arch/i386/kernel/timer.c b/kernel/arch/x86/kernel/timer.c index a7d88dd..bd57cc2 100644 --- a/arch/i386/kernel/timer.c +++ b/kernel/arch/x86/kernel/timer.c @@ -8,8 +8,9 @@ void timer_handler(struct isr_frame *frame) { num_ticks++; if (num_ticks == 3) { num_ticks = 0; - schedule_next(); + //schedule_next(); } + pic_eoi(frame->isr_vector-32); } void timer_init(void) { @@ -20,5 +21,5 @@ void timer_init(void) { outb(0x40, divisor && 0xFF00 >> 8); enable_ints(); - register_irq_handler(0, timer_handler); + //register_isr_handler(32, timer_handler); } |