ref: 9cb02ecc484ffa07a0a6052cbd40794572c340e2
parent: b4587b6d4f1c365c7ecfe653264046bb49ca7478
author: mkf <mkf@cloud9p.org>
date: Fri Nov 17 12:56:13 IST 2023
lots of changes. fix backspace bug in shell clear cmd memory before first run add basic memory mangment add malloc() add lladd() and ll_t get rid of uneeded while in ps2.c add err.h enable some warnnings in CFLAG add fs.h add fs.c add user.c
--- a/Makefile
+++ b/Makefile
@@ -4,7 +4,7 @@
LD=i686-linux-gnu-ld.bfd
AS=i686-linux-gnu-as
-CFLAGS=-O0 -g -nostdinc -I./include/ -ffreestanding -fcommon -fno-pie -fno-stack-limit -fno-stack-check -fno-stack-protector
+CFLAGS=-O0 -g -nostdinc -I./include/ -ffreestanding -fcommon -fno-pie
ASFLAGS=-g
LDFLAGS=-T linker.ld
@@ -16,14 +16,16 @@
libc/strcmp.o\
libc/memcpy.o\
libc/memset.o\
+ libc/lladd.o \
K=\
+ pc/boot.o\
pc/x86.o\
pc/kern.o\
- pc/boot.o\
pc/vga.o\
pc/ps2.o\
pc/com.o\
+ pc/mem.o\
${L}all: teppich.elf
--- /dev/null
+++ b/include/err.h
@@ -1,0 +1,14 @@
+#pragma once
+enum
+{+ OK = 0,
+
+ /* you don't want these mass up with your values */
+ PERM_DENIED = -128,
+ NAME_TOO_LONG,
+ NO_FILE,
+ FS_NOT_READY,
+ DIR_NOT_EMPTY,
+ NO_MEM,
+ LL_ERR,
+}err;
--- /dev/null
+++ b/include/fs.h
@@ -1,0 +1,41 @@
+#include <u.h>
+
+#define NAME_MAX 16
+
+enum
+{+ DIR,
+ FILE,
+ VFILE, /* shell files */
+};
+
+typedef struct
+{+ uint32 inode;
+ uint32 size;
+
+ uint8 owner;
+ uint8 perms;
+
+ uint8 type;
+
+ char *name;
+ char **path; /* "/" "usr/" "local" */
+
+ char *content;
+
+}file_t;
+
+typedef struct
+{+ uint32 inode;
+
+ uint8 encryption;
+ uint8 compression;
+
+ uint8 type;
+ uint8 *start;
+
+ ll_t users;
+ ll_t files;
+}fs_t;
--- a/include/libc.h
+++ b/include/libc.h
@@ -4,3 +4,5 @@
int strcmp(char *s1, char *s2);
void* memset(void* src, char c, unsigned int len);
void* memcpy(void *a1, void *a2, unsigned int len);
+int lladd(ll_t*, void*);
+int lldel(ll_t*, void*);
--- a/include/u.h
+++ b/include/u.h
@@ -1,5 +1,4 @@
#pragma once
-
#define nil ((void*)0x0)
typedef int size_t;
@@ -11,4 +10,10 @@
typedef short int16;
typedef unsigned long uint32;
-typedef long int32;
\ No newline at end of file
+typedef long int32;
+
+typedef struct
+{+ void *val;
+ void *next;
+}ll_t;
--- /dev/null
+++ b/include/user.h
@@ -1,0 +1,8 @@
+typedef struct
+{+ uint8 id;
+ char *name;
+ char *pass;
+}user_t;
+
+user_t cuser;
--- /dev/null
+++ b/libc/lladd.c
@@ -1,0 +1,20 @@
+#include <u.h>
+#include <err.h>
+#include <mem.h>
+
+int
+lladd(ll_t *last, void *data)
+{+ ll_t *temp = malloc(sizeof(ll_t*));
+
+ temp->val = data;
+ temp->next = nil;
+
+ if(last->next != nil)
+ {+ return LL_ERR;
+ }
+
+ last->next = temp;
+ return OK;
+}
--- a/pc/kern.c
+++ b/pc/kern.c
@@ -1,6 +1,8 @@
+#include <u.h>
#include <vga.h>
#include <com.h>
#include <ps2.h>
+#include <mem.h>
#include <libc.h>
/* abandon hope, all ye who enter here */
@@ -9,14 +11,11 @@
{ vga_puts("panic: give up. it's over.\n"); com_puts("panic: give up. it's over.\n");-
}
int
run(char* cmd)
{- /* vga_puts(cmd); */
-
/* replace it with a proper table */
if(!strcmp(cmd, "clear"))
{@@ -29,9 +28,12 @@
else if(!strcmp(cmd, "reboot"))
return 0;
else
- vga_puts("no such command");+ {+ vga_puts("\nno such command\n");+ }
vga_putc('\n');+ vga_puts("> ");return 1;
}
@@ -40,12 +42,11 @@
repl(void)
{char c;
- char *cmd = "";
- int i = 0;
+ char *cmd;
- vga_puts("salam az Teppich\n");+ int i = 0;
+ memset(cmd, 0, 16);
vga_puts("> ");-
while(1)
{@@ -59,26 +60,35 @@
{if(!run(cmd))
return;
+
/* clear the mess */
+ cmd = malloc(16);
i = 0;
- memset(cmd, 0, 16);
-
- vga_puts("> ");-
+
}
- else
+ else if(c != '\b')
{- *(cmd+i) = c; /* heb */
+ *(cmd+i) = c;
i++;
}
+ else
+ {+ /* we don't want a negative i */
+ if(i)
+ i--;
+ *(cmd+i) = 0;
+
+ }
}
}
-
void
kernel_main(void)
{- vga_init(WHITE, BLUE);
+ memset(memap, FREE, MEM_MAX * (1024 / BLOCKSIZE));
+
+ vga_init(BLUE, LIGHT_GREY);
+ vga_puts("Teppich\n");repl();
}
--- a/pc/ps2.c
+++ b/pc/ps2.c
@@ -11,7 +11,7 @@
void
ps2_init()
{- int a = 256 - 3; // 2^8 - 1- 2
+ int a = 256 - 3; // 11111100
outb(0x64, SET_RATE);
outb(0x64, a);
}
@@ -20,15 +20,12 @@
ps2_getc()
{char c;
- while(1)
- {- if(!(ps2_read_status() & 1))
- return 0;
+ if(!(ps2_read_status() & 1))
+ return 0;
- c = inb(KB);
- if(c & 0x80)
- return 0;
- return keymap[c];
+ c = inb(KB);
+ if(c & 0x80)
+ return 0;
- }
+ return keymap[c];
}
--
⑨