From ec1e4d08130414c86e9a0693b956969b67c9552a Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Sun, 18 Aug 2024 05:18:29 +0300 Subject: [PATCH] hacky video/serial console choice works --- kern/kern.ld | 1 - kern/src/boot.asm | 5 +++-- kern/src/con.c | 10 ++++++++-- kern/src/config.h | 2 +- kern/src/dbg.c | 10 ++++++++++ kern/src/dbg.h | 4 ++++ kern/src/dev.c | 6 +----- kern/src/ser.c | 5 ++--- kern/src/startup.asm | 10 ++++++---- 9 files changed, 35 insertions(+), 18 deletions(-) diff --git a/kern/kern.ld b/kern/kern.ld index c851a6d..fddd365 100644 --- a/kern/kern.ld +++ b/kern/kern.ld @@ -23,7 +23,6 @@ SECTIONS { } .bss ALIGN(4): { _bss_start = .; - _bss_start_off = _bss_start - _kern_start; * (.bss*); * (COMMON); . = ALIGN(4); diff --git a/kern/src/boot.asm b/kern/src/boot.asm index 25486e6..b8966d4 100644 --- a/kern/src/boot.asm +++ b/kern/src/boot.asm @@ -5,6 +5,7 @@ extern _bootsect_start extern _kern_start_seg +extern _kern_start extern _kern_size boot_driveno equ 0500h @@ -179,11 +180,11 @@ start: jnz .rdloop ; loaded sucessfully, load segment registers and jump -.done: mov ax, _kern_start_seg +.done: xor ax, ax mov ds, ax mov es, ax push ax - xor ax, ax + mov ax, _kern_start push ax retf diff --git a/kern/src/con.c b/kern/src/con.c index b9b91a4..b64cfb5 100644 --- a/kern/src/con.c +++ b/kern/src/con.c @@ -7,18 +7,24 @@ static struct file *devfile; +extern int in_panic; + void con_init(void) { +#if CONDEV != DEV_VID if(!(devfile = dev_open(CONDEV, 0, O_RDWR))) { panic("can't open console device %d,%d\n", CONDEV, 0); } +#endif } void con_putchar(int c) { if(devfile) { - vid_putchar(c); /* XXX dbg */ - //devfile->dev->fop->write(devfile, &c, 1); + if(in_panic) { + vid_putchar(c); + } + devfile->dev->fop->write(devfile, &c, 1); } else { vid_putchar(c); } diff --git a/kern/src/config.h b/kern/src/config.h index 45bf49f..d46832b 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_SER +#define CONDEV DEV_VID #endif /* CONFIG_H_ */ diff --git a/kern/src/dbg.c b/kern/src/dbg.c index 5dcab9f..40d2fc5 100644 --- a/kern/src/dbg.c +++ b/kern/src/dbg.c @@ -3,6 +3,8 @@ #include "dbg.h" #include "asmutil.h" +int in_panic; + __attribute__((noreturn)) void panic(const char *fmt, ...) { @@ -10,6 +12,8 @@ void panic(const char *fmt, ...) struct wordregs regs; struct segregs sregs; + in_panic = 1; + getregs(®s); regs.ip = getip(); /* replace ip with the caller's */ getsregs(&sregs); @@ -27,3 +31,9 @@ void panic(const char *fmt, ...) for(;;) halt(); } + +void dbgping(int c) +{ + unsigned short __far *vmem = MK_FP(0xb800, 0); + vmem[79] = c | 0xc00; +} diff --git a/kern/src/dbg.h b/kern/src/dbg.h index 55896dc..607ffc6 100644 --- a/kern/src/dbg.h +++ b/kern/src/dbg.h @@ -4,4 +4,8 @@ __attribute__((noreturn)) void panic(const char *fmt, ...); +void dbgping(int c); + +#define dbgbreak() asm volatile("int $3") + #endif /* DBG_H_ */ diff --git a/kern/src/dev.c b/kern/src/dev.c index 312b821..9cc5aea 100644 --- a/kern/src/dev.c +++ b/kern/src/dev.c @@ -7,7 +7,7 @@ struct device devices[MAX_DEVICES]; struct file *dev_open(int major, int minor, unsigned int flags) { /* XXX temporary hack */ - struct inode fakenode; + static struct inode fakenode; static struct file file; fakenode.dev_major = major; @@ -16,12 +16,8 @@ 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/ser.c b/kern/src/ser.c index b30af46..e454e67 100644 --- a/kern/src/ser.c +++ b/kern/src/ser.c @@ -88,8 +88,6 @@ 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; } @@ -126,7 +124,8 @@ static int ser_write(struct file *file, void *buf, int sz) { int port = file->inode->dev_minor; unsigned char *ptr = buf; - while(sz > 0) { + + while(sz-- > 0) { serput(port, *ptr++); } return ptr - (unsigned char*)buf; diff --git a/kern/src/startup.asm b/kern/src/startup.asm index 2cd9250..db24bae 100644 --- a/kern/src/startup.asm +++ b/kern/src/startup.asm @@ -7,7 +7,7 @@ STACKSZ equ 4096 extern kmain -extern _bss_start_off +extern _bss_start extern _bss_size global _start @@ -18,13 +18,15 @@ _start: xor ax, ax mov sp, ax + mov ds, ax + mov es, ax + mov ss, ax + ; zero .bss - mov di, _bss_start_off + mov di, _bss_start mov cx, _bss_size shr cx, 1 rep stosw - xor ax, ax - mov es, ax call kmain -- 1.7.10.4