commit f01c70d6731b11269e4e5b6560deae5dfde9e0f4
parent 82084d59718d0cded62a753110d82b3c05f289fc
Author: evenfri <evenfri256@gmail.com>
Date: Mon, 3 Aug 2026 21:23:10 +0800
fixes, add warnings, add tty scroll
Diffstat:
9 files changed, 32 insertions(+), 7 deletions(-)
diff --git a/build/cc b/build/cc
@@ -5,5 +5,7 @@ exec i686-elf-gcc -c \
-nostdlib \
-ffreestanding \
-fno-builtin \
+ -Wall \
+ -Wextra \
-I"$kernel" \
"$@"
diff --git a/dat.h b/dat.h
@@ -61,6 +61,7 @@ typedef void (*int_handler)();
/* vfs */
#define stdin 0
#define stdout 1
+#define EOF (-1)
/* syscalls */
#define sys_read 0
diff --git a/printk.c b/printk.c
@@ -4,8 +4,6 @@
#include <dat.h>
#include <fns.h>
-#define EOF (-1)
-
static char *utoa_hex(unsigned int num, char *buf, size_t bufsize) {
char *p = buf + bufsize - 1;
*p = '\0';
@@ -42,7 +40,7 @@ static char *itoa_dec(int num, char *buf, size_t bufsize) {
}
static bool print(const char* data, size_t length) {
- if (vfs_write(stdout, (void*) data, length) == EOF)
+ if (vfs_write(stdout, (void*) data, length) == (size_t)EOF)
return false;
return true;
}
diff --git a/qemu-iso.sh b/qemu-iso.sh
@@ -2,7 +2,7 @@
set -e
iso="./user/os.iso"
-mem="4M"
+mem="16M"
./iso.sh
diff --git a/qemu.sh b/qemu.sh
@@ -2,7 +2,7 @@
set -e
kernel_bin="o.kernel"
-mem="4M"
+mem="16M"
exec qemu-system-i386 \
-m "$mem" \
diff --git a/syscall.c b/syscall.c
@@ -9,6 +9,8 @@ void syscall_init() {
int syscall_handler(int num, int arg1, int arg2,
int arg3, int arg4, int arg5) {
+ (void)arg4;
+ (void)arg5;
switch (num) {
case sys_read:
return vfs_read(arg1, (void*) arg2, arg3);
diff --git a/tty.c b/tty.c
@@ -34,13 +34,31 @@ void tty_init(void) {
tty_clear();
}
+void tty_scroll(void) {
+ /* move lines to line-1 */
+ for (int row = 1; row < vga_height; row++) {
+ for (int col = 0; col < vga_width; col++) {
+ size_t src_index = row * vga_width + col;
+ size_t dst_index = (row - 1) * vga_width + col;
+ tty_buffer[dst_index] = tty_buffer[src_index];
+ }
+ }
+ /* clear last line*/
+ uint16_t blank = ' ' | (tty_color << 8);
+ for (int col = 0; col < vga_width; col++) {
+ size_t index = (vga_height - 1) * vga_width + col;
+ tty_buffer[index] = blank;
+ }
+}
+
void tty_putchar(char c) {
if(c == '\n') {
tty_row++;
tty_column = 0;
if (tty_row >= vga_height) {
- tty_row = 0;
+ tty_scroll();
+ tty_row = vga_height - 1;
}
} else if(c == '\b') {
if (tty_column > 0) {
@@ -52,7 +70,8 @@ void tty_putchar(char c) {
if (++tty_column == vga_width) {
tty_column = 0;
if (++tty_row == vga_height) {
- tty_row = 0;
+ tty_scroll();
+ tty_row = vga_height - 1;
}
}
}
diff --git a/user/isodir/boot/kernel b/user/isodir/boot/kernel
Binary files differ.
diff --git a/vfs.c b/vfs.c
@@ -9,6 +9,9 @@ size_t vfs_read(unsigned int fd, void *buf, size_t size) {
for (size_t i = 0; i < size; i++) {
ptr[i] = keyboard_read();
+ if (ptr[i] == '\n') {
+ return EOF;
+ }
bytes_read++;
}
return bytes_read;