os

Toy OS
git clone git://git.margiolis.net/os.git
Log | Files | Refs | README | LICENSE

commit 72ac8c1cf865751314262162c62c837cb5ae547e
parent b5af0b999e891e2c309b549c09263b9b12017f03
Author: Christos Margiolis <christos@FreeBSD.org>
Date:   Thu, 27 Jul 2023 00:31:49 +0300

wip

Diffstat:
MREADME | 2+-
Mkern/Makefile | 3+--
Rkern/io.h -> kern/cpufunc.h | 0
Mkern/idt.c | 5++---
Mkern/kbd.c | 6+++++-
Mkern/kern_main.c | 24++++++++++++++++--------
Mkern/libk.c | 5++---
Mkern/pic.c | 2+-
Mkern/pic.h | 10+++++-----
Mkern/timer.c | 2+-
Mkern/vga.c | 17++++++++++++-----
Dkern/vm_page.c | 8--------
Dkern/vm_page.h | 6------
Mmk/kern.mk | 2+-
14 files changed, 47 insertions(+), 45 deletions(-)

diff --git a/README b/README @@ -1,7 +1,7 @@ My OS ===== -Linux users are afraid of it. +Works on my machine. Build ----- diff --git a/kern/Makefile b/kern/Makefile @@ -13,7 +13,6 @@ OBJ= kern_main.o \ intr.o \ vga.o \ kbd.o \ - timer.o \ - vm_page.o + timer.o include ../mk/kern.mk diff --git a/kern/io.h b/kern/cpufunc.h diff --git a/kern/idt.c b/kern/idt.c @@ -2,7 +2,7 @@ #include "libk.h" #include "idt.h" #include "pic.h" -#include "io.h" +#include "cpufunc.h" static void idt_set_gate(struct gate_desc *, void *, u_int, u_int, u_int); @@ -20,8 +20,7 @@ idt_set_gate(struct gate_desc *gd, void *func, u_int sel, u_int dpl, u_int type) } /* - * u_char so `-pedantic` won't complain about taking the - * address of `void`. + * u_char so `-pedantic` won't complain about taking the address of `void`. */ extern u_char INTVEC(div), INTVEC(dbg), INTVEC(nmsk), INTVEC(bpt), INTVEC(ofl), INTVEC(bnd), INTVEC(ill), INTVEC(dna), INTVEC(dbl), INTVEC(fpusegm), diff --git a/kern/kbd.c b/kern/kbd.c @@ -2,7 +2,7 @@ #include "libk.h" #include "kbd.h" #include "idt.h" -#include "io.h" +#include "cpufunc.h" #include "vga.h" #define KBD_CMD 0x60 @@ -52,6 +52,10 @@ static u_char kbdus_upper[128] = { 0, /* The rest are undefined */ }; +/* + * XXX: is there a correlation so that we can do math instead of having 2 + * tables? + */ static u_char kbdus_lower[128] = { 0, /* Error */ 27, /* Escape */ diff --git a/kern/kern_main.c b/kern/kern_main.c @@ -1,21 +1,29 @@ -#include <libc.h> +#include "libk.h" + #include "kbd.h" #include "idt.h" -#include "io.h" +#include "cpufunc.h" #include "timer.h" -#include "vm_page.h" #include "vga.h" -/* TODO: make kset/unsetenv */ -/* TODO: make device framework */ -/* TODO: add a config */ -/* TODO: make sysctl */ +/* + * TODO + * + * CATCH UP! + * + * make kset/unsetenv + * make device driver framework + * add a config file (?) + * fix kbd + * Makefiles + * fix pending TODOs, XXXs and FIXMEs + * remove useless stuff + */ void kern_main(void) { vga_clear(VGA_BLACK, VGA_WHITE); idt_init(); - vm_page_init(); timer_init(); kbd_init(); diff --git a/kern/libk.c b/kern/libk.c @@ -1,5 +1,5 @@ #include "libk.h" -#include "io.h" +#include "cpufunc.h" #include "vga.h" #define ZEROPAD 0x01 @@ -368,13 +368,12 @@ panic(const char *fmt, ...) { char buf[BUFSIZ]; va_list ap; - int n; cli(); vga_set_color(VGA_RED, VGA_WHITE); printf("panic: "); va_start(ap, fmt); - n = vsprintf(buf, fmt, ap); + (void)vsprintf(buf, fmt, ap); va_end(ap); vga_puts(buf); vga_set_color(VGA_BLACK, VGA_WHITE); diff --git a/kern/pic.c b/kern/pic.c @@ -1,6 +1,6 @@ #include "pic.h" #include "idt.h" -#include "io.h" +#include "cpufunc.h" /* * BIOS reserves IRQ 0 to 15 for the PIC. We need to remap it to non-reserved diff --git a/kern/pic.h b/kern/pic.h @@ -25,10 +25,10 @@ #define ICW4_BUF_MASTER 0x0c /* Buffered master */ #define ICW4_SFNM 0x10 /* Special fully nested */ -void pic_remap(void); -void pic_eoi(u_int32_t); -void pic_mask(u_int8_t, int); -void pic_on(void); -void pic_off(void); +void pic_remap(void); +void pic_eoi(u_int32_t); +void pic_mask(u_int8_t, int); +void pic_on(void); +void pic_off(void); #endif /* _PIC_H_ */ diff --git a/kern/timer.c b/kern/timer.c @@ -1,7 +1,7 @@ #include <libc.h> #include "libk.h" #include "idt.h" -#include "io.h" +#include "cpufunc.h" #define TIMER_CMD 0x43 #define TIMER_DATA 0x40 diff --git a/kern/vga.c b/kern/vga.c @@ -1,5 +1,5 @@ #include "vga.h" -#include "io.h" +#include "cpufunc.h" #define VGA_MEM 0xb8000; #define VGA_COLS 80 @@ -11,7 +11,7 @@ struct vga { volatile u_int16_t *buf; - size_t row; /* XXX: signed? */ + size_t row; /* XXX: why signed? */ size_t col; u_int8_t color; }; @@ -40,6 +40,13 @@ vga_set_color(u_int8_t fg, u_int8_t bg) vga.color = fg | (bg << 4); } +/* + * TODO: page break + * https://en.wikipedia.org/wiki/Page_break + * https://en.wikipedia.org/wiki/Escape_sequences_in_C + * + * handle long lines (backspacing inside them as well) + */ void vga_putc(char c) { @@ -64,13 +71,13 @@ vga_putc(char c) vga.col++; } - if (vga.row > VGA_ROWS) { - /* FIXME: scroll */ + if (vga.row > VGA_ROWS - 1) { + /* XXX: change page completely or push everything down one line? */ vga_clear(VGA_BLACK, VGA_WHITE); vga.row = 0; vga.col = 0; } - if (vga.col > VGA_COLS) { + if (vga.col > VGA_COLS - 1) { vga.row++; vga.col = 0; } diff --git a/kern/vm_page.c b/kern/vm_page.c @@ -1,8 +0,0 @@ -#include "libk.h" -#include "idt.h" -#include "vm_page.h" - -void -vm_page_init(void) -{ -} diff --git a/kern/vm_page.h b/kern/vm_page.h @@ -1,6 +0,0 @@ -#ifndef _VM_PAGE_H_ -#define _VM_PAGE_H_ - -void vm_page_init(void); - -#endif /* _VM_PAGE_H_ */ diff --git a/mk/kern.mk b/mk/kern.mk @@ -1,7 +1,7 @@ CC= cc AS= nasm LD= ld -ARCH= i386 # FIXME: make this automatic +ARCH= i386 # FIXME: make this automatic (?) ARCHINCDIR+= ${PREFIX}/${ARCH} INCDIR+= ${PREFIX}/include CFLAGS+= -g -m32 -Wall -Wextra -Werror -pedantic -std=c99 -O2 \