From 8cd22309667cf3da9c357e5b7dca43e8b6a2f9c0 Mon Sep 17 00:00:00 2001 From: Danny Holman Date: Fri, 21 Jan 2022 12:10:05 -0600 Subject: arch: i386: move non-critial files out of boot Move all files not needed for the bootstrap process out of boot and into the main x86 source directory. Signed-off-by: Danny Holman --- arch/i386/boot/pic.c | 67 ------------------------------------- arch/i386/boot/syscall.c | 21 ------------ arch/i386/boot/syscall.h | 9 ----- arch/i386/boot/tss.c | 26 --------------- arch/i386/boot/tss.h | 39 ---------------------- arch/i386/boot/tty.c | 87 ------------------------------------------------ arch/i386/boot/vga.h | 33 ------------------ 7 files changed, 282 deletions(-) delete mode 100644 arch/i386/boot/pic.c delete mode 100644 arch/i386/boot/syscall.c delete mode 100644 arch/i386/boot/syscall.h delete mode 100644 arch/i386/boot/tss.c delete mode 100644 arch/i386/boot/tss.h delete mode 100644 arch/i386/boot/tty.c delete mode 100644 arch/i386/boot/vga.h (limited to 'arch/i386/boot') diff --git a/arch/i386/boot/pic.c b/arch/i386/boot/pic.c deleted file mode 100644 index 69a0785..0000000 --- a/arch/i386/boot/pic.c +++ /dev/null @@ -1,67 +0,0 @@ -#include - -void pic_eoi(unsigned char irq) { - if (irq >= 8) - outb(PIC2_COMMAND, 0x20); - outb(PIC1_COMMAND, 0x20); -} - -void pic_remap(void) { - unsigned char a1 = inb(PIC1_DATA); - unsigned char a2 = inb(PIC2_DATA); - - outb(PIC1_COMMAND, ICW1_INIT | ICW1_ICW4); - outb(PIC2_COMMAND, ICW1_INIT | ICW1_ICW4); - outb(PIC1_DATA, PIC1); - outb(PIC2_DATA, PIC2); - outb(PIC1_DATA, 4); - outb(PIC2_DATA, 2); - outb(PIC1_DATA, ICW4_8086); - outb(PIC2_DATA, ICW4_8086); - outb(PIC1_DATA, a1); - outb(PIC2_DATA, a2); -} - -static uint16_t __pic_get_irq_reg(int ocw3) { - outb(PIC1_COMMAND, ocw3); - outb(PIC2_COMMAND, ocw3); - return (inb(PIC2_COMMAND) << 8) | inb(PIC1_COMMAND); -} - -uint16_t pic_get_irr(void) { - return __pic_get_irq_reg(PIC_READ_IRR); -} - -uint16_t pic_get_isr(void) { - return __pic_get_irq_reg(PIC_READ_ISR); -} - -void irq_set_mask(uint8_t irq) { - uint16_t port; - uint8_t data; - - if (irq < 8) { - port = PIC1_DATA; - } else { - port = PIC2_DATA; - irq -= 8; - } - - data = inb(port) | (1 << irq); - outb(port, data); -} - -void irq_clear_mask(uint8_t irq) { - uint16_t port; - uint8_t data; - - if (irq < 8) { - port = PIC1_DATA; - } else { - port = PIC2_DATA; - irq -= 8; - } - - data = inb(port) & ~(1 << irq); - outb(port, data); -} diff --git a/arch/i386/boot/syscall.c b/arch/i386/boot/syscall.c deleted file mode 100644 index fb613b3..0000000 --- a/arch/i386/boot/syscall.c +++ /dev/null @@ -1,21 +0,0 @@ -#include "syscall.h" -#include -#include - -void *(*syscall_handlers[30])(struct isr_frame *frame); - -void syscall_dispatch(struct isr_frame *frame) { - if (syscall_handlers[frame->eax] != NULL) - syscall_handlers[frame->eax](frame); - else - kprintf("Error: Invalid system call number: %d\n", frame->eax); - __asm__ volatile("cli;hlt"); -} - -void register_syscall(void *handler(struct isr_frame*), int num) { - syscall_handlers[num] = handler; -} - -void print_hello(struct isr_frame *frame) { - kprintf("Hello syscall\n"); -} diff --git a/arch/i386/boot/syscall.h b/arch/i386/boot/syscall.h deleted file mode 100644 index 376fb7c..0000000 --- a/arch/i386/boot/syscall.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef I386_SYSCALL_H -#define I386_SYSCALL_H - -#include - -void syscall_dispatch(struct isr_frame *frame); -void register_syscall(void *handler(struct isr_frame*), int num); - -#endif diff --git a/arch/i386/boot/tss.c b/arch/i386/boot/tss.c deleted file mode 100644 index 2edfa76..0000000 --- a/arch/i386/boot/tss.c +++ /dev/null @@ -1,26 +0,0 @@ -#include "tss.h" -#include - -struct tss tss_entry; - -uint64_t create_tss_entry(uint16_t ss0, uint32_t esp0) { - uint32_t base = (uint32_t)&tss_entry; - uint32_t limit = base + sizeof(&tss_entry); - uint64_t ret = create_gdt_entry(base, limit, 0xE9); - - memset(&tss_entry, 0, sizeof(struct tss)); - tss_entry.ss0 = ss0; - tss_entry.esp0 = esp0; - tss_entry.cs = 0x08; - tss_entry.ss = 0x13; - tss_entry.ds = 0x13; - tss_entry.es = 0x13; - tss_entry.fs = 0x13; - tss_entry.gs = 0x13; - tss_entry.io_offset = sizeof(struct tss) & 0xFFFF; - return ret; -} - -void set_kernel_stack(uint32_t stack) { - tss_entry.esp0 = stack; -} diff --git a/arch/i386/boot/tss.h b/arch/i386/boot/tss.h deleted file mode 100644 index 28bae6e..0000000 --- a/arch/i386/boot/tss.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef I386_TSS_H -#define I386_TSS_H - -#include - -struct tss { - 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; - uint32_t io_offset; -}__attribute__((packed)); - -void flush_tss(void); - -uint64_t create_gdt_entry(uint32_t base, uint32_t limit, uint16_t flag); -uint64_t create_tss_entry(uint16_t ss0, uint32_t esp0); -void set_kernel_stack(uint32_t stack); - -#endif diff --git a/arch/i386/boot/tty.c b/arch/i386/boot/tty.c deleted file mode 100644 index aa77736..0000000 --- a/arch/i386/boot/tty.c +++ /dev/null @@ -1,87 +0,0 @@ -#include "vga.h" -#include -#include -#include -#include - -static const size_t VGA_WIDTH = 80; -static const size_t VGA_HEIGHT = 25; -static uint16_t *const VGA_MEMORY = (uint16_t*)0xC03FF000; - -static size_t terminal_row; -static size_t terminal_column; -static uint8_t terminal_color; -static uint16_t *terminal_buffer; - -void tty_init(void) { - terminal_row = 0; - terminal_column = 0; - terminal_color = vga_entry_color(VGA_COLOR_LIGHT_GREY, VGA_COLOR_BLACK); - terminal_buffer = VGA_MEMORY; - for (size_t y = 0; y < VGA_HEIGHT; y++) { - for (size_t x = 0; x < VGA_WIDTH; x++) { - const size_t index = y * VGA_WIDTH + x; - terminal_buffer[index] = vga_entry(' ', terminal_color); - } - } -} - -void tty_setcolor(uint8_t color) { - terminal_color = color; -} - -void tty_putentryat(unsigned char c, uint8_t color, size_t x, size_t y) { - const size_t index = y * VGA_WIDTH + x; - terminal_buffer[index] = vga_entry(c, color); -} - -void terminal_scroll(void) { - for (size_t i = 0; i < VGA_HEIGHT; i++) { - for (size_t j = 0; j < VGA_WIDTH; j++) - terminal_buffer[i * VGA_WIDTH + j] = terminal_buffer[(i+1) * VGA_WIDTH + j]; - } -} - -void tty_putchar(char c) { - unsigned char uc; - - uc = c; - switch (uc) { - case '\n': - terminal_column = 0; - if (++terminal_row == VGA_HEIGHT) { - terminal_row--; - terminal_scroll(); - } - break; - case '\t': - terminal_column += 4; - if (++terminal_column == VGA_WIDTH) { - terminal_column = 4; - if (++terminal_row == VGA_HEIGHT) { - terminal_row--; - terminal_scroll(); - } - } - break; - default: - tty_putentryat(uc, terminal_color, terminal_column, terminal_row); - if (++terminal_column == VGA_WIDTH) { - terminal_column = 0; - if (++terminal_row == VGA_HEIGHT) { - terminal_row--; - terminal_scroll(); - } - } - break; - } -} - -void tty_write(const char *data, size_t size) { - for (size_t i = 0; i < size; i++) - tty_putchar(data[i]); -} - -void tty_writestring(const char *data) { - tty_write(data, strlen(data)); -} diff --git a/arch/i386/boot/vga.h b/arch/i386/boot/vga.h deleted file mode 100644 index e89f202..0000000 --- a/arch/i386/boot/vga.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef I386_VGA_H -#define I386_VGA_H - -#include - -enum vga_color { - VGA_COLOR_BLACK = 0, - VGA_COLOR_BLUE = 1, - VGA_COLOR_GREEN = 2, - VGA_COLOR_CYAN = 3, - VGA_COLOR_RED = 4, - VGA_COLOR_MAGENTA = 5, - VGA_COLOR_BROWN = 6, - VGA_COLOR_LIGHT_GREY = 7, - VGA_COLOR_DARK_GREY = 8, - VGA_COLOR_LIGHT_BLUE = 9, - VGA_COLOR_LIGHT_GREEN = 10, - VGA_COLOR_LIGHT_CYAN = 11, - VGA_COLOR_LIGHT_RED = 12, - VGA_COLOR_LIGHT_MAGENTA = 13, - VGA_COLOR_LIGHT_BROWN = 14, - VGA_COLOR_LIGHT_WHITE = 15, -}; - -static inline uint8_t vga_entry_color(enum vga_color fg, enum vga_color bg) { - return fg | bg << 4; -} - -static inline uint16_t vga_entry(unsigned char uc, uint8_t color) { - return (uint16_t)uc | (uint16_t)color << 8; -} - -#endif -- cgit v1.2.3