From d98d2d4292b357c04380a9001b6211986e8459b4 Mon Sep 17 00:00:00 2001 From: Greg Bowne Date: Fri, 14 Jul 2023 20:10:20 -0700 Subject: [PATCH] Fixing the memory, adding a shell, and other minor bugs to gdt and idt and the types, also adds .github files for bug reports and feature requests. --- .github/ISSUE_TEMPLATE/bug_report.md | 15 +++++++ .github/ISSUE_TEMPLATE/feature_request.md | 14 ++++++ kernel | Bin 0 -> 8956 bytes src/drivers/io/io.c | 51 ++++++++++++++++++++++ src/drivers/io/io.h | 19 ++++++++ src/kernel/arch/x86/gdt.c | 4 +- src/kernel/arch/x86/idt.c | 11 ++++- src/kernel/arch/x86/include/memory.h | 2 + src/kernel/arch/x86/include/types.h | 17 +++++--- src/kernel/arch/x86/memory/memory.c | 50 +++++++++++++++++++-- src/shell/shell.c | 32 ++++++++++++++ src/shell/shell.h | 13 ++++++ 12 files changed, 214 insertions(+), 14 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100755 kernel create mode 100644 src/drivers/io/io.c create mode 100644 src/drivers/io/io.h create mode 100644 src/shell/shell.c create mode 100644 src/shell/shell.h diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..baf9618 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,15 @@ +--- +name: Bug report +about: Create a bug report to help us improve 88os +title: '' +labels: '' +assignees: '' + +--- + +If you found a bug in 88os, please provide: + +1) A clear and concise description of what the bug is: what happened and what you expected to happen. +2) Steps to reproduce the bug. Ideally, you would provide a small code example triggering the bug and the exact command line used to run KLEE. Please make sure the bug is still present in the mainline. +3) The warnings and error messages issued by KLEE +4) Any relevant information about your platform: the output of `klee --version`, OS version, environment variables, directory in which KLEE is run, etc. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..de16c2b --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,14 @@ +--- +name: Feature request +about: Suggest a feature in 88os +title: '' +labels: '' +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. E.g., I find it difficult to use KLEE when [...]; I would find it very useful for 88os to [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. diff --git a/kernel b/kernel new file mode 100755 index 0000000000000000000000000000000000000000..0be1a9a80b8be76655d84ea30edf40b6a13f1fe2 GIT binary patch literal 8956 zcmeHN%}x_h6h5UzM!LZmNfQW7x5pOlh@E>`!Kf1uNwZ`Ud(a zK0;rD7a+ir`hEA#!KN7#7w$YK`Eu_0nRCy4_wLU9dhq_RR4R$el9WZQ2Ar);A8ANk z9>`0n$||%7V~uZ>fcS|uQOQw;z9tYO9%D@~&e~dE5OY|A6JVU0@yS!*dnF*ounF$V z_!88g;;eCenRSZdy8rfBnrwgRw~5m*9fhwJ`a%uu^S)R33I#O=tns=qYEEOo7%&Em z0b{@zFb0ePW55_N28;n?z!)$Fi~(c77%&Em0b{@zFb0ePW55_N28@CKlmVSPb5kGDDL_x*U=P4Hcx z-e%X3iRQZrzMJdQU6vI;>&J|rb_q8BOMZBJ4fdl2dxLf^{O@(H=kg_LoqTw6^lo3G zZYR!Ss9{He6KJN;79}Dt+ E0R+ZtnE(I) literal 0 HcmV?d00001 diff --git a/src/drivers/io/io.c b/src/drivers/io/io.c new file mode 100644 index 0000000..ceb05b8 --- /dev/null +++ b/src/drivers/io/io.c @@ -0,0 +1,51 @@ +#include "io.h" + +/* + Common Ports + COM1: 0x3F8 + COM2: 0x2F8 + COM3: 0x3E8 + COM4: 0x2E8 + LPT1: 0x378 + LPT2: 0x278 + LPT3: 0x3BC +*/ + +// Function to initialize the COM and LPT ports +void io_init() +{ + // TODO: Initialize the COM and LPT ports + // Set up any necessary configuration or control operations +} + +// Function to read from the COM port +char io_read_com() +{ + // TODO: Read from the COM port + // Use the appropriate memory or I/O address to read from the port + // Return the read data +} + +// Function to write to the COM port +void io_write_com(char data) +{ + // TODO: Write to the COM port + // Use the appropriate memory or I/O address to write to the port + // Write the provided data to the port +} + +// Function to read from the LPT port +char io_read_lpt() +{ + // TODO: Read from the LPT port + // Use the appropriate memory or I/O address to read from the port + // Return the read data +} + +// Function to write to the LPT port +void io_write_lpt(char data) +{ + // TODO: Write to the LPT port + // Use the appropriate memory or I/O address to write to the port + // Write the provided data to the port +} \ No newline at end of file diff --git a/src/drivers/io/io.h b/src/drivers/io/io.h new file mode 100644 index 0000000..4ab373f --- /dev/null +++ b/src/drivers/io/io.h @@ -0,0 +1,19 @@ +#ifndef IO_H +#define IO_H + +// Function to initialize the COM and LPT ports +void io_init(); + +// Function to read from the COM port +char io_read_com(); + +// Function to write to the COM port +void io_write_com(char data); + +// Function to read from the LPT port +char io_read_lpt(); + +// Function to write to the LPT port +void io_write_lpt(char data); + +#endif /* IO_H */ \ No newline at end of file diff --git a/src/kernel/arch/x86/gdt.c b/src/kernel/arch/x86/gdt.c index 7ab0623..fb79722 100644 --- a/src/kernel/arch/x86/gdt.c +++ b/src/kernel/arch/x86/gdt.c @@ -1,5 +1,5 @@ #include "gdt.h" - +#include // GDT table struct gdt_entry gdt[3]; @@ -36,7 +36,7 @@ void gdt_init() gdt_set_gate(2, 0, 0xFFFFFFFF, 0x92, 0xCF); // Load GDT - asm volatile("lgdt %0" : : "m"(gp)); + _asm volatile("lgdt %0" : : "m"(gp)); } // Exception handlers diff --git a/src/kernel/arch/x86/idt.c b/src/kernel/arch/x86/idt.c index e316ac4..d151950 100644 --- a/src/kernel/arch/x86/idt.c +++ b/src/kernel/arch/x86/idt.c @@ -1,9 +1,16 @@ #include "idt.h" +#include // IDT table struct idt_entry idt[256]; // IDT pointer +struct idt_ptr +{ + uint16_t limit; // Size of IDT in bytes - 1 + struct idt_entry *base; // Address of IDT +} __attribute__((packed)); + struct idt_ptr idtp; // Exception handlers @@ -33,7 +40,7 @@ void idt_init() { // Set up IDT pointer idtp.limit = sizeof(idt) - 1; - idtp.base = (uint32_t)&idt; + idtp.base = idt; // Clear IDT memset(&idt, 0, sizeof(idt)); @@ -51,5 +58,5 @@ void idt_init() idt_set_gate(0x30, (uint32_t)device_handler, 0x08, 0x8E); // Load IDT - asm volatile("lidt %0" : : "m"(idtp)); + _asm volatile("lidt %0" : : "m"(idtp)); } \ No newline at end of file diff --git a/src/kernel/arch/x86/include/memory.h b/src/kernel/arch/x86/include/memory.h index 498a312..49001f5 100644 --- a/src/kernel/arch/x86/include/memory.h +++ b/src/kernel/arch/x86/include/memory.h @@ -1,8 +1,10 @@ #ifndef MEMORY_H #define MEMORY_H +#include #include +void init_heap(void *start, size_t size); void *kmalloc(size_t size); void kfree(void *ptr); diff --git a/src/kernel/arch/x86/include/types.h b/src/kernel/arch/x86/include/types.h index ee2974c..44207c2 100644 --- a/src/kernel/arch/x86/include/types.h +++ b/src/kernel/arch/x86/include/types.h @@ -1,19 +1,24 @@ #ifndef TYPES_H #define TYPES_H -typedef unsigned char uint8_t; +typedef unsigned char uint8_t; typedef unsigned short uint16_t; -typedef unsigned int uint32_t; +typedef unsigned int uint32_t; -typedef struct { +typedef struct +{ uint32_t base; uint32_t limit; uint16_t flags; } gdt_entry_t; -typedef struct { - uint16_t limit; - uint32_t base; +typedef struct +{ + uint16_t base_lo; // Lower 16 bits of handler function address + uint16_t selector; // Kernel segment selector + uint8_t always0; // Always 0 + uint8_t flags; // Flags + uint16_t base_hi; // Upper 16 bits of handler function address } idt_entry_t; #endif /* TYPES_H */ \ No newline at end of file diff --git a/src/kernel/arch/x86/memory/memory.c b/src/kernel/arch/x86/memory/memory.c index f1efc9d..f762a96 100644 --- a/src/kernel/arch/x86/memory/memory.c +++ b/src/kernel/arch/x86/memory/memory.c @@ -1,12 +1,54 @@ #include "../include/memory.h" +#include +#include + +/* The start of the kernel heap */ +static uint8_t *heap_start = NULL; + +/* The end of the kernel heap */ +static uint8_t *heap_end = NULL; + +/* The current position of the heap */ +static uint8_t *heap_pos = NULL; + +/* The size of the heap */ +static size_t heap_size = 0; + +void init_heap(void *start, size_t size) +{ + heap_start = (uint8_t *)start; + heap_end = heap_start + size; + heap_pos = heap_start; + heap_size = size; +} void *kmalloc(size_t size) { - /* TODO: Implement memory allocation */ - return NULL; + /* Round up the size to a multiple of 4 bytes */ + size = (size + 3) & ~3; + + /* Check if there is enough space in the heap */ + if (heap_pos + size > heap_end) + { + return NULL; + } + + /* Allocate memory from the heap */ + void *ptr = heap_pos; + heap_pos += size; + + return ptr; } void kfree(void *ptr) { - /* TODO: Implement memory deallocation */ -} + /* Check if the pointer is within the heap */ + if ((uint8_t *)ptr >= heap_start && ptr < (void *)heap_end) + { + /* Zero out the memory */ + memset(ptr, 0, (uint8_t *)heap_pos - (uint8_t *)ptr); + + /* Free the memory by moving the heap position */ + heap_pos = (uint8_t *)ptr; + } +} \ No newline at end of file diff --git a/src/shell/shell.c b/src/shell/shell.c new file mode 100644 index 0000000..69660b0 --- /dev/null +++ b/src/shell/shell.c @@ -0,0 +1,32 @@ +#include "shell.h" +#include +#include + +void shell_loop() +{ + char input[256]; + + while (1) + { + printf("> "); + fgets(input, sizeof(input), stdin); + + // Remove newline character from input + input[strcspn(input, "\n")] = '\0'; + + // Parse input and execute commands + // ... + + // Exit the shell if the user enters "exit" + if (strcmp(input, "exit") == 0) + { + break; + } + } +} + +int main() +{ + shell_loop(); + return 0; +} \ No newline at end of file diff --git a/src/shell/shell.h b/src/shell/shell.h new file mode 100644 index 0000000..71e1753 --- /dev/null +++ b/src/shell/shell.h @@ -0,0 +1,13 @@ +#ifndef SHELL_H +#define SHELL_H + +// Function to read user input +char *read_input(); + +// Function to parse user input +char **parse_input(char *input); + +// Function to execute a command +int execute_command(char **args); + +#endif \ No newline at end of file