diff --git a/.github/ISSUE_TEMPLATE/bug-report.md b/.github/ISSUE_TEMPLATE/bug-report.md deleted file mode 100755 index 8724123..0000000 --- a/.github/ISSUE_TEMPLATE/bug-report.md +++ /dev/null @@ -1,16 +0,0 @@ ---- -name: Bug report -about: File something going wrong here -title: "[BUG]" -labels: bug -assignees: '' - ---- - -### Expected behaviour -<-- What you expected to happen --> -### Current behaviour -<-- What happened --> -### Steps to reproduce -<-- How to see it --> -![screenshot](path/to/screenshot.png) diff --git a/.github/ISSUE_TEMPLATE/enhancement.md b/.github/ISSUE_TEMPLATE/enhancement.md deleted file mode 100755 index 2e16396..0000000 --- a/.github/ISSUE_TEMPLATE/enhancement.md +++ /dev/null @@ -1,13 +0,0 @@ ---- -name: Enhancement -about: You want something more from BlueberryOS -title: "[XTRA]" -labels: enhancement -assignees: '' - ---- - -### What I want -<-- self explanatory --> -### Why I want it -<-- ... --> diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100755 index d82a4d5..0000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,12 +0,0 @@ -# To get started with Dependabot version updates, you'll need to specify which -# package ecosystems to update and where the package manifests are located. -# Please see the documentation for all configuration options: -# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates - -version: 2 -updates: - - package-ecosystem: "" # See documentation for possible values - directory: "/" # Location of package manifests - schedule: - interval: "weekly" - diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml deleted file mode 100644 index 4d52929..0000000 --- a/.github/workflows/codeql.yml +++ /dev/null @@ -1,79 +0,0 @@ -# For most projects, this workflow file will not need changing; you simply need -# to commit it to your repository. -# -# You may wish to alter this file to override the set of languages analyzed, -# or to provide custom queries or build logic. -# -# ******** NOTE ******** -# We have attempted to detect the languages in your repository. Please check -# the `language` matrix defined below to confirm you have the correct set of -# supported CodeQL languages. -# -name: "CodeQL" - -on: - push: - branches: [ "master" ] - pull_request: - # The branches below must be a subset of the branches above - branches: [ "master" ] - schedule: - - cron: '20 11 * * 3' - -jobs: - analyze: - name: Analyze - runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }} - permissions: - actions: read - contents: read - security-events: write - - strategy: - fail-fast: false - matrix: - language: [ 'cpp' ] - # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] - # Use only 'java' to analyze code written in Java, Kotlin or both - # Use only 'javascript' to analyze code written in JavaScript, TypeScript or both - # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v2 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - - # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs - # queries: security-extended,security-and-quality - - - # Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java). - # If this step fails, then you should remove it and run the build manually (see below) -# - name: Autobuild -# uses: github/codeql-action/autobuild@v2 - - # ℹī¸ Command-line programs to run using the OS shell. - # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun - - # If the Autobuild fails above, remove it and uncomment the following three lines. - # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. - - - run: | - echo "Run, Build Application using script" - sudo apt update - sudo apt install nasm qemu - make normalgcc - qemu-system-i386 -rtc base=localtime -curses -kernel kernel.bin - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 - with: - category: "/language:${{matrix.language}}" diff --git a/Makefile b/Makefile index b2c19f8..447a370 100755 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ -CFLAGS=-Wno-stringop-overflow -Wno-discarded-qualifiers +CFLAGS=-Wno-stringop-overflow -Wno-discarded-qualifiers -fstack-protector -go: | prep elfgcc run +go: | prep elfgcc run clean prep: nasm -f elf32 boot/boot.asm -o boot/boot.o diff --git a/boot/boot.asm b/boot/boot.asm index b4306f8..a1c5832 100755 --- a/boot/boot.asm +++ b/boot/boot.asm @@ -17,6 +17,7 @@ global load_idt extern kmain ;this is defined in the c file extern keyboard_handler_main +extern kinit read_port: mov edx, [esp + 4] ;al is the lower 8 bits of eax @@ -42,6 +43,7 @@ keyboard_handler: start: cli ;block interrupts mov esp, stack_space + call kinit call kmain hlt ;halt the CPU diff --git a/kernel/kernel.c b/kernel/kernel.c index 60c366c..f5bac91 100755 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -1,86 +1,80 @@ -#include -#include -#include -#include -#include -#include +#include // compiler +#include // compiler +#include // compiler +#include // more keyboard +#include // vkprintf kprintf putchar +#include // various (itoa etc) #include // kmalloc #include // memcmp -#include -#include -#include "keyboard.h" -#include -#include +#include // memcpy +#include // colors +#include "keyboard.h" // keyboard map +#include // timing +#include // comparison functions +#include // stack smash protector +#include // cmd callbacks +#include "kinit.c" // kernel init, called before kmain int counter=0; // counts how many keys have been pressed char typed[1024]; // holds current line of keyboard input char just_typed[1024]; // holds input that was typed before enter was pressed void dellast(void) { // deletes last character from working keyboard memory - typed[counter]='\0'; - counter--; + typed[counter]='\0'; + counter--; } -void keyboard_handler_main(void) -{ +void keyboard_handler_main(void) { // handles keyboard input, called by boot.asm - unsigned char status; - char keycode; - write_port(0x20, 0x20); + unsigned char status; + char keycode; + write_port(0x20, 0x20); - status = read_port(KEYBOARD_STATUS_PORT); - if (status & 0x01) { - keycode = read_port(KEYBOARD_DATA_PORT); - if(keycode<0) - return; - else if(keycode == ENTER_KEY_CODE) { - kprintf("\n"); // checktype(); + status = read_port(KEYBOARD_STATUS_PORT); + if (status & 0x01) { + keycode = read_port(KEYBOARD_DATA_PORT); + if(keycode<0) + return; + else if(keycode==ENTER_KEY_CODE) { + kprintf("\n"); // checktype(); + terminal_column--; + for (int it=0;it<1024;it++) { + just_typed[it]='\0'; + } memcpy(just_typed,typed,1024); - for (int it=0;it<1024;it++) { - typed[it]='\0'; - } - counter=0; + for (int it=0;it<1024;it++) { + typed[it]='\0'; + } + counter=0; + return; + } else if (keys(keycode)=='`') { + dellast(); terminal_column--; - return; - } else if (keys(keycode)=='`') { - dellast(); - terminal_column--; - write_to(' ', terminal_color, terminal_column, terminal_row); - return; - } else { - typed[counter]=keys(keycode); - counter++; - const char key=keys(keycode); - } - setclr(deftype(),0); + write_to(' ', terminal_color, terminal_column, terminal_row); + return; + } else { + typed[counter]=keys(keycode); + counter++; + const char key=keys(keycode); + } + setclr(deftype(),0); const char key=keys(keycode); - putchar(key); + raw_putchar(key); // terminal_column-=3; // kprintf(" "); // terminal_column-=3; // kprinth(key); - setclr(defcol(),0); - } -} -void hello() { - kprintf("And to you!\n"); -} -void hi() { - kprintf("mom!\n"); + setclr(defcol(),0); + } } -int kmain() { - term_init(); - idt_init(); - kb_init(); - kprintf("Hello World!\nhi\n"); - kprintn(3); - +int kmain(void) { + vkprintf("s","Hello World!\n"); while (true){ while ( !cmp(just_typed,"hello",hello) && !cmp(just_typed,"hi",hi) ) {} // while neither of these have just been typed, do nothing. once they have been, erase them to avoid an infinite loop for (int it=0;it<1024;it++) { - just_typed[it]='\0'; - } + just_typed[it]='\0'; + } } } diff --git a/kernel/kinit.c b/kernel/kinit.c new file mode 100644 index 0000000..43506ab --- /dev/null +++ b/kernel/kinit.c @@ -0,0 +1,6 @@ +int kinit(void) { + term_init(); + idt_init(); + kb_init(); + setclr(defcol(),0); +} \ No newline at end of file diff --git a/libc/blueberry.h b/libc/blueberry.h index c7cabb3..d5f92c7 100755 --- a/libc/blueberry.h +++ b/libc/blueberry.h @@ -6,7 +6,7 @@ */ #define __blueberry__ true #define blueberry true - +#define _BLUEBERRY_H #ifndef __i386__ #error "Oh no. Debug time!" #endif \ No newline at end of file diff --git a/libc/io/util.h b/libc/io/util.h index e9903a7..51f129c 100644 --- a/libc/io/util.h +++ b/libc/io/util.h @@ -1,6 +1,22 @@ +int strcmp(char *first, char *second) { + while(*first==*second) { + if (*first=='\0'||*second=='\0') + break; + first++; + second++; + } + if (*first=='\0'&&*second=='\0') + return 0; + else + return -1; +} int cmp(char * typed, char * target, void (*call_back)()) { // if typed==target, call call_back() then return 1 - if (!memcmp(typed,target,strlen(target))) { + if ((!strcmp(typed,target) && !strcmp(typed,target)) || (!memcmp(typed,target,1024) && !memcmp(typed,target,1024))) { + // why are we checking this 3 times? + // it seems to be liable to a bug where the return is wrong + // happens about once every 10/12 times + // with 2 it happens every ~(11^2)==121 times call_back(); return 1; } diff --git a/libc/kernel/io/cmds.h b/libc/kernel/io/cmds.h new file mode 100644 index 0000000..e2aac64 --- /dev/null +++ b/libc/kernel/io/cmds.h @@ -0,0 +1,6 @@ +void hello() { + kprintf("And to you!\n"); +} +void hi() { + kprintf("mom!\n"); +} \ No newline at end of file diff --git a/libc/stdio.h b/libc/stdio.h index ad85d0b..a04a63e 100755 --- a/libc/stdio.h +++ b/libc/stdio.h @@ -7,22 +7,33 @@ #include #include #include +#include #include #if !defined(__i386__) #error "Enjoy your debugging :)" #endif - void kprintf(const char * data); - +void kprintf(const char * data); +bool just_nl=false; void write_to(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 raw_putchar(char c) { + write_to(c, terminal_color, terminal_column, terminal_row); + if (++terminal_column == VGA_WIDTH) { + terminal_column = 0; + if (++terminal_row == VGA_HEIGHT) + terminal_row = 0; + } +} void putchar(char c) { - + if (just_nl) { + terminal_column++; + just_nl=false; + } write_to(c, terminal_color, terminal_column, terminal_row); if (++terminal_column == VGA_WIDTH) { terminal_column = 0; @@ -37,7 +48,8 @@ void write(const char * data, size_t size, bool magic) for (size_t i = 0; i < size; i++) { while (data[i]=='\n') { terminal_row = terminal_row + 1; - terminal_column = -magic; + terminal_column = -1; + just_nl=true; i++; } @@ -63,6 +75,31 @@ void kprintf(const char * data) } write(data, strlen(data),0); } +void kprintn(int num); +void vkprintf(const char * fmt, ...) { + va_list arg; + int done; + va_start(arg,fmt); + while(*fmt!='\0') { + // string + if(*fmt=='s') { + char* s=va_arg(arg, char *); + kprintf(s); + } + // character + else if(*fmt=='c') { + char c=(char)va_arg(arg, int); + putchar(c); + break; + } + // integer || boolean + else if(*fmt=='d' || *fmt=='b') { + int d=va_arg(arg, int ); + kprintn(d); + } + *fmt++; + } +} void nprintf(const char * data) { if (terminal_row>=VGA_HEIGHT) { for(int i = 0; i < VGA_HEIGHT; i++){ diff --git a/libc/sys/ssp.h b/libc/sys/ssp.h new file mode 100644 index 0000000..44b3ebe --- /dev/null +++ b/libc/sys/ssp.h @@ -0,0 +1,19 @@ +#ifndef _STDINT_H +#include +#endif + +#if UINT32_MAX == UINTPTR_MAX +#define STACK_CHK_GUARD 0xe2dee396 +#else +#define STACK_CHK_GUARD 0x595e9fbd94fda766 +#endif + +uintptr_t __stack_chk_guard = STACK_CHK_GUARD; + +__attribute__((noreturn)) void __stack_chk_fail(void) { + #if __STDC_HOSTED__ + abort(); + #elif __blueberry__ + panic("__stack_chk_fail called","Stack smashing detected",1); + #endif +} \ No newline at end of file diff --git a/libc/time.h b/libc/sys/time.h similarity index 100% rename from libc/time.h rename to libc/sys/time.h