From 7f9c5703ff21011affcb59505da248e9e85e6fd9 Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Sat, 17 Aug 2024 17:56:16 +0300 Subject: [PATCH] debugging --- kern/src/con.c | 13 +++---------- kern/src/config.h | 2 +- kern/src/dbg.c | 2 +- kern/src/dev.c | 6 ++++++ kern/src/intr.c | 5 +---- kern/src/libc/string.c | 11 +++++++++++ kern/src/ser.c | 8 ++++++-- 7 files changed, 29 insertions(+), 18 deletions(-) diff --git a/kern/src/con.c b/kern/src/con.c index 2c2965d..b9b91a4 100644 --- a/kern/src/con.c +++ b/kern/src/con.c @@ -10,22 +10,15 @@ static struct file *devfile; void con_init(void) { if(!(devfile = dev_open(CONDEV, 0, O_RDWR))) { - //panic("can't open console device %d,%d\n", CONDEV, 0); - } -} - -void con_printf(const char *fmt, ...) -{ - /* TODO */ - while(*fmt) { - con_putchar(*fmt++); + panic("can't open console device %d,%d\n", CONDEV, 0); } } void con_putchar(int c) { if(devfile) { - devfile->dev->fop->write(devfile, &c, 1); + vid_putchar(c); /* XXX dbg */ + //devfile->dev->fop->write(devfile, &c, 1); } else { vid_putchar(c); } diff --git a/kern/src/config.h b/kern/src/config.h index d46832b..45bf49f 100644 --- a/kern/src/config.h +++ b/kern/src/config.h @@ -4,6 +4,6 @@ #define VERSTR "v0.0" /* CONDEV: which device to use for the kernel console (DEV_VID or DEV_SER) */ -#define CONDEV DEV_VID +#define CONDEV DEV_SER #endif /* CONFIG_H_ */ diff --git a/kern/src/dbg.c b/kern/src/dbg.c index 7daf689..5dcab9f 100644 --- a/kern/src/dbg.c +++ b/kern/src/dbg.c @@ -20,7 +20,7 @@ void panic(const char *fmt, ...) vprintf(fmt, ap); va_end(ap); - printf("ax:%04x bx:%04x cx:%04x dx:%04x\n", regs.ax, regs.bx, regs.cx, regs.dx); + printf("\nax:%04x bx:%04x cx:%04x dx:%04x\n", regs.ax, regs.bx, regs.cx, regs.dx); printf("bp:%04x si:%04x di:%04x flags:%04x\n", regs.bp, regs.si, regs.di, regs.flags); printf("ss:sp %04x:%04x cs:ip %04x:%04x ds:%04x es:%04x\n", sregs.ss, regs.sp, sregs.cs, regs.ip, sregs.ds, sregs.es); diff --git a/kern/src/dev.c b/kern/src/dev.c index 0648a36..312b821 100644 --- a/kern/src/dev.c +++ b/kern/src/dev.c @@ -1,4 +1,6 @@ +#include #include "dev.h" +#include "dbg.h" struct device devices[MAX_DEVICES]; @@ -14,8 +16,12 @@ struct file *dev_open(int major, int minor, unsigned int flags) if(!devices[major].fop) { return 0; } + printf("dev_open(%x, %x, %x)\n", major, minor, flags); if(devices[major].fop->open(&file, &fakenode, flags) < 0) { + panic("open failed"); return 0; } + panic("WTF"); + return &file; } diff --git a/kern/src/intr.c b/kern/src/intr.c index e682b30..a76a72f 100644 --- a/kern/src/intr.c +++ b/kern/src/intr.c @@ -43,9 +43,6 @@ void intr_entry_irq5(); void intr_entry_irq6(); void intr_entry_irq7(); -extern int _kern_start_seg; -#define KERN_CS ((uint16_t)(&_kern_start_seg)) - void init_intr(void) { @@ -55,7 +52,7 @@ void init_intr(void) intrfunc[i] = 0; } - set_intr_vect(0, KERN_CS, (uint16_t)intr_entry_div); + set_intr_vect(0, 0, (uint16_t)intr_entry_div); } void dispatch_intr(struct intr_frame frm) diff --git a/kern/src/libc/string.c b/kern/src/libc/string.c index 8b5325a..36c1d53 100644 --- a/kern/src/libc/string.c +++ b/kern/src/libc/string.c @@ -6,3 +6,14 @@ int strlen(const char *s) while(*end) end++; return end - s; } + +/* +void *memset(void *s, int c, unsigned int n) +{ + unsigned char *ptr = s; + while(n-- > 0) { + *ptr++ = c; + } + return s; +} +*/ diff --git a/kern/src/ser.c b/kern/src/ser.c index db948e9..b30af46 100644 --- a/kern/src/ser.c +++ b/kern/src/ser.c @@ -1,9 +1,11 @@ +#include #include #include #include "ser.h" #include "file.h" #include "dev.h" #include "asmutil.h" +#include "dbg.h" #define UART1_BASE 0x3f8 #define UART2_BASE 0x2f8 @@ -25,7 +27,7 @@ static void setuart(int portidx, int baud); static void serput(int portidx, int c); -static int ser_open(struct file *file, struct inode *inode, unsigned int flags); +int ser_open(struct file *file, struct inode *inode, unsigned int flags); static int ser_close(struct file *file); static int ser_read(struct file *file, void *buf, int sz); static int ser_write(struct file *file, void *buf, int sz); @@ -82,10 +84,12 @@ static void serput(int portidx, int c) outp(iobase | UART_DATA, c); } -static int ser_open(struct file *file, struct inode *inode, unsigned int flags) +int ser_open(struct file *file, struct inode *inode, unsigned int flags) { int port = inode->dev_minor; + panic("ser_open"); + if(port < 0 || port >= 2) { return -ENXIO; } -- 1.7.10.4