Skip to content

Commit

Permalink
many a change
Browse files Browse the repository at this point in the history
  • Loading branch information
werdl committed Oct 1, 2023
1 parent 695283b commit 672243b
Show file tree
Hide file tree
Showing 14 changed files with 148 additions and 188 deletions.
16 changes: 0 additions & 16 deletions .github/ISSUE_TEMPLATE/bug-report.md

This file was deleted.

13 changes: 0 additions & 13 deletions .github/ISSUE_TEMPLATE/enhancement.md

This file was deleted.

12 changes: 0 additions & 12 deletions .github/dependabot.yml

This file was deleted.

79 changes: 0 additions & 79 deletions .github/workflows/codeql.yml

This file was deleted.

4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions boot/boot.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -42,6 +43,7 @@ keyboard_handler:
start:
cli ;block interrupts
mov esp, stack_space
call kinit
call kmain
hlt ;halt the CPU

Expand Down
112 changes: 53 additions & 59 deletions kernel/kernel.c
Original file line number Diff line number Diff line change
@@ -1,86 +1,80 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <kernel/idt.h>
#include <stdio.h>
#include <util.h>
#include <stdbool.h> // compiler
#include <stddef.h> // compiler
#include <stdint.h> // compiler
#include <kernel/idt.h> // more keyboard
#include <stdio.h> // vkprintf kprintf putchar
#include <util.h> // various (itoa etc)
#include <mem/alloc.h> // kmalloc
#include <mem/memcmp.h> // memcmp
#include <mem/memcpy.h>
#include <io/clr.h>
#include "keyboard.h"
#include <time.h>
#include <io/util.h>
#include <mem/memcpy.h> // memcpy
#include <io/clr.h> // colors
#include "keyboard.h" // keyboard map
#include <sys/time.h> // timing
#include <io/util.h> // comparison functions
#include <sys/ssp.h> // stack smash protector
#include <kernel/io/cmds.h> // 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';
}
}
}
6 changes: 6 additions & 0 deletions kernel/kinit.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
int kinit(void) {
term_init();
idt_init();
kb_init();
setclr(defcol(),0);
}
2 changes: 1 addition & 1 deletion libc/blueberry.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
#define __blueberry__ true
#define blueberry true

#define _BLUEBERRY_H
#ifndef __i386__
#error "Oh no. Debug time!"
#endif
18 changes: 17 additions & 1 deletion libc/io/util.h
Original file line number Diff line number Diff line change
@@ -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;
}
Expand Down
6 changes: 6 additions & 0 deletions libc/kernel/io/cmds.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
void hello() {
kprintf("And to you!\n");
}
void hi() {
kprintf("mom!\n");
}
Loading

0 comments on commit 672243b

Please sign in to comment.