diff options
Diffstat (limited to 'arch')
-rw-r--r-- | arch/i386/include/kernel/asm.h | 51 | ||||
-rw-r--r-- | arch/i386/kernel/spinlock.s | 30 | ||||
-rw-r--r-- | arch/i386/make.config | 4 |
3 files changed, 75 insertions, 10 deletions
diff --git a/arch/i386/include/kernel/asm.h b/arch/i386/include/kernel/asm.h index cf394e1..3c7bc00 100644 --- a/arch/i386/include/kernel/asm.h +++ b/arch/i386/include/kernel/asm.h @@ -1,6 +1,7 @@ #ifndef I386_ASM_H #define I386_ASM_H +#include <kernel/gdt.h> #include <stdint.h> extern uintptr_t _kernel_start; @@ -8,19 +9,30 @@ extern uintptr_t _kernel_end; #define KSTART ((uintptr_t)&_kernel_start) #define KEND ((uintptr_t)&_kernel_end - 0xC0000000) -#define HIMEM_START 0x00100000 #define PAGE_SIZE 4096 -struct thread_block { +#define PCI_CONFIG_ADDR 0xCF8 +#define PCI_CONFIG_DATA 0xCFC + +#define COM_PORT 0x3F8 + +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; - unsigned int tid; - unsigned int tgid; - unsigned int state; - struct thread_block *next; + uint32_t cr4; }; -struct regs { +struct isr_frame { uint32_t cr4; uint32_t cr3; uint32_t cr2; @@ -92,16 +104,41 @@ void irq_stub_15(void); void syscall_stub(void); +void aquire_lock(int *lock); +void release_lock(int *lock); + +void enable_paging(uint32_t new_cr3); + 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"); } diff --git a/arch/i386/kernel/spinlock.s b/arch/i386/kernel/spinlock.s new file mode 100644 index 0000000..c8235ca --- /dev/null +++ b/arch/i386/kernel/spinlock.s @@ -0,0 +1,30 @@ +.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/make.config b/arch/i386/make.config index d4d98a7..82d0733 100644 --- a/arch/i386/make.config +++ b/arch/i386/make.config @@ -7,15 +7,13 @@ KERNEL_ARCH_OBJS=$(ARCHDIR)/boot/boot.o \ $(ARCHDIR)/kernel/idt.o \ $(ARCHDIR)/kernel/gdt.o \ $(ARCHDIR)/kernel/isr.o \ - $(ARCHDIR)/kernel/framebuffer.o \ $(ARCHDIR)/kernel/multiboot.o \ - $(ARCHDIR)/kernel/keyboard.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/jump_userspace.o \ $(ARCHDIR)/kernel/switch_thread.o \ |