KernLog reimplemented in term of buffer stuff. Finally scrolls down!

This commit is contained in:
Julian Barathieu 2019-03-29 14:19:29 +01:00
parent f233cc1066
commit a6f615d792
21 changed files with 1265231 additions and 481 deletions

View File

@ -124,14 +124,14 @@ $(KOBJDIR)/prog.o: $(KERNELDIR)/extras/prog.c $(KERNELDIR)/include/*/*.h
@echo ${CL2}[$@] ${CL}Compiled.${CL3} @echo ${CL2}[$@] ${CL}Compiled.${CL3}
# Kernel objects # Kernel objects
kal_kern_obj= $(KOBJDIR)/kernel/cpuid.o $(KOBJDIR)/kernel/init.o \ kal_kern_obj= $(KOBJDIR)/kernel/cpuid.o $(KOBJDIR)/kernel/init.o \
$(KOBJDIR)/kernel/table.o $(KOBJDIR)/kernel/cursor.o \ $(KOBJDIR)/kernel/table.o $(KOBJDIR)/kernel/cursor.o \
$(KOBJDIR)/kernel/term.o $(KOBJDIR)/kernel/vga.o \ $(KOBJDIR)/kernel/log.o $(KOBJDIR)/kernel/vga.o \
$(KOBJDIR)/kernel/panic.o $(KOBJDIR)/kernel/map.o \ $(KOBJDIR)/kernel/panic.o $(KOBJDIR)/kernel/map.o \
$(KOBJDIR)/kernel/heap.o $(KOBJDIR)/kernel/malloc.o \ $(KOBJDIR)/kernel/heap.o $(KOBJDIR)/kernel/malloc.o \
$(KOBJDIR)/kernel/buf.o $(KOBJDIR)/kernel/sched.o \ $(KOBJDIR)/kernel/buf.o $(KOBJDIR)/kernel/sched.o \
$(KOBJDIR)/kernel/bput.o $(KOBJDIR)/kernel/bprint.o \ $(KOBJDIR)/kernel/bput.o $(KOBJDIR)/kernel/bprint.o \
$(KOBJDIR)/kernel/gdt.o $(KOBJDIR)/kernel/gdt.o $(KOBJDIR)/kernel/gdt.o
$(KOBJDIR)/kernel/cpuid.o: $(KERNELDIR)/kernel/cpu/cpuid.c $(KERNELDIR)/include/*/*.h $(KOBJDIR)/kernel/cpuid.o: $(KERNELDIR)/kernel/cpu/cpuid.c $(KERNELDIR)/include/*/*.h
@$(KCC) $< -o $@ @$(KCC) $< -o $@
@ -148,7 +148,7 @@ $(KOBJDIR)/kernel/table.o: $(KERNELDIR)/kernel/init/table.c $(KERNELDIR)/include
$(KOBJDIR)/kernel/cursor.o: $(KERNELDIR)/kernel/io/cursor.c $(KERNELDIR)/include/*/*.h $(KOBJDIR)/kernel/cursor.o: $(KERNELDIR)/kernel/io/cursor.c $(KERNELDIR)/include/*/*.h
@$(KCC) $< -o $@ @$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3} @echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/kernel/term.o: $(KERNELDIR)/kernel/io/term.c $(KERNELDIR)/include/*/*.h $(KOBJDIR)/kernel/log.o: $(KERNELDIR)/kernel/ke/log.c $(KERNELDIR)/include/*/*.h
@$(KCC) $< -o $@ @$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3} @echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/kernel/vga.o: $(KERNELDIR)/kernel/io/vga.c $(KERNELDIR)/include/*/*.h $(KOBJDIR)/kernel/vga.o: $(KERNELDIR)/kernel/io/vga.c $(KERNELDIR)/include/*/*.h
@ -216,10 +216,6 @@ gdb: all
-ex "target remote localhost:1234" \ -ex "target remote localhost:1234" \
-ex "symbol-file $(BINDIR)/kaleid" \ -ex "symbol-file $(BINDIR)/kaleid" \
-ex "break BtStartKern" \ -ex "break BtStartKern" \
-ex "def reload64"
-ex "set arch i386:x86-64" \
-ex "target remote localhost:1234" \
-ex "end" \
.PHONY: install_mbr .PHONY: install_mbr
install_mbr: $(BINDIR)/disk.img $(MBRDIR)/grub.cfg install_mbr: $(BINDIR)/disk.img $(MBRDIR)/grub.cfg

View File

@ -64,12 +64,12 @@
│   │   │   ├── gdt.o │   │   │   ├── gdt.o
│   │   │   ├── heap.o │   │   │   ├── heap.o
│   │   │   ├── init.o │   │   │   ├── init.o
│   │   │   ├── log.o
│   │   │   ├── malloc.o │   │   │   ├── malloc.o
│   │   │   ├── map.o │   │   │   ├── map.o
│   │   │   ├── panic.o │   │   │   ├── panic.o
│   │   │   ├── sched.o │   │   │   ├── sched.o
│   │   │   ├── table.o │   │   │   ├── table.o
│   │   │   ├── term.o
│   │   │   └── vga.o │   │   │   └── vga.o
│   │   ├── argv.o │   │   ├── argv.o
│   │   ├── atoi.o │   │   ├── atoi.o
@ -124,12 +124,15 @@
│   │   │   ├── cpu.h │   │   │   ├── cpu.h
│   │   │   ├── heap.h │   │   │   ├── heap.h
│   │   │   ├── iomisc.h │   │   │   ├── iomisc.h
<<<<<<< Updated upstream
│   │   │   ├── mboot.h │   │   │   ├── mboot.h
=======
│   │   │   ├── log.h
>>>>>>> Stashed changes
│   │   │   ├── mm.h │   │   │   ├── mm.h
│   │   │   ├── panic.h │   │   │   ├── panic.h
│   │   │   ├── proc.h │   │   │   ├── proc.h
│   │   │   ├── sched.h │   │   │   └── sched.h
│   │   │   └── term.h
│   │   ├── kalbase.h │   │   ├── kalbase.h
│   │   ├── kaleid.h │   │   ├── kaleid.h
│   │   └── kalext.h │   │   └── kalext.h
@ -147,9 +150,9 @@
│   ├── io │   ├── io
│   │   ├── ata.inc │   │   ├── ata.inc
│   │   ├── cursor.c │   │   ├── cursor.c
│   │   ├── term.c
│   │   └── vga.c │   │   └── vga.c
│   ├── ke │   ├── ke
│   │   ├── log.c
│   │   └── panic.c │   │   └── panic.c
│   ├── mm │   ├── mm
│   │   ├── gdt.c │   │   ├── gdt.c

View File

@ -253,7 +253,7 @@ static inline int min(int __x, int __y)
#ifndef __lmin_defined #ifndef __lmin_defined
#define __lmin_defined #define __lmin_defined
static inline int lmin(long __x, long __y) static inline long lmin(long __x, long __y)
{ return __x < __y ? __x : __y; } { return __x < __y ? __x : __y; }
#endif #endif
@ -265,7 +265,7 @@ static inline int max(int __x, int __y)
#ifndef __lmax_defined #ifndef __lmax_defined
#define __lmax_defined #define __lmax_defined
static inline int lmax(long __x, long __y) static inline long lmax(long __x, long __y)
{ return __x > __y ? __x : __y; } { return __x > __y ? __x : __y; }
#endif #endif

View File

@ -36,6 +36,7 @@
//------------------------------------------// //------------------------------------------//
typedef struct Lock_t Lock_t; typedef struct Lock_t Lock_t;
typedef struct Buffer_t Buffer_t;
typedef struct Thread_t Thread_t; typedef struct Thread_t Thread_t;
typedef struct Process_t Process_t; typedef struct Process_t Process_t;
typedef struct Terminal_t Terminal_t; typedef struct Terminal_t Terminal_t;
@ -175,9 +176,9 @@ struct BootInfo_t
//------------------------------------------// //------------------------------------------//
extern int cpuCount; extern volatile int cpuCount;
extern BootInfo_t bootTab; extern volatile BootInfo_t bootTab;
extern Processor_t cpuTable[NCPUS]; extern volatile Processor_t cpuTable[NCPUS];
//------------------------------------------// //------------------------------------------//

View File

@ -29,8 +29,6 @@
#ifndef _KALKERN_BUF_H #ifndef _KALKERN_BUF_H
#define _KALKERN_BUF_H #define _KALKERN_BUF_H
typedef struct Buffer_t Buffer_t;
// //
// Buffer flags // Buffer flags
// //
@ -83,7 +81,7 @@ struct Buffer_t
// size/(lineLen*nLines) - 1 playback buffers // size/(lineLen*nLines) - 1 playback buffers
}; };
extern Buffer_t BStdOut, BStdErr; extern Buffer_t *BStdOut, *BStdDbg;
error_t BCloseBuf(Buffer_t *buf); error_t BCloseBuf(Buffer_t *buf);
void BFlushOnClose(Buffer_t *buf); void BFlushOnClose(Buffer_t *buf);
@ -96,18 +94,18 @@ Buffer_t *BOpenPureBuf(char *source, size_t size);
Buffer_t *BOpenLineBuf(char *source, int mode, int lineLen, Buffer_t *BOpenLineBuf(char *source, int mode, int lineLen,
int nLines, int pbCount, BFlusher_t flusher); int nLines, int pbCount, BFlusher_t flusher);
int BGetFlags(Buffer_t *buf); int BGetFlags(Buffer_t *);
int BGetState(Buffer_t *buf); int BGetState(Buffer_t *);
int BGetLineLen(Buffer_t *buf); int BGetLineLen(Buffer_t *);
void BSetLineLen(Buffer_t *buf, int len); void BSetLineLen(Buffer_t *, int);
void BLockBuf(Buffer_t *buf); void BLockBuf(Buffer_t *);
void BUnlockBuf(Buffer_t *buf); void BUnlockBuf(Buffer_t *);
bool BTrylockBuf(Buffer_t *buf); bool BTrylockBuf(Buffer_t *);
error_t BFlushBuf(Buffer_t *buf); error_t BFlushBuf(Buffer_t *);
error_t BPutOnBuf(Buffer_t *buf, uchar ch); error_t BPutOnBuf(Buffer_t *, uchar);
error_t BPrintOnBuf(Buffer_t *buf, const char *fmt, ...); error_t BPrintOnBuf(Buffer_t *, const char *fmt, ...);
error_t BPrintOnBufV(Buffer_t *buf, const char *fmt, va_list ap); error_t BPrintOnBufV(Buffer_t *, const char *fmt, va_list);
#endif #endif

View File

@ -0,0 +1,40 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
// Desc: KernLog() and DebugLog() //
// //
// //
// Copyright © 2018-2019 The OS/K Team //
// //
// This file is part of OS/K. //
// //
// OS/K is free software: you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or //
// any later version. //
// //
// OS/K is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY//without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//
#ifndef _KALKERN_BASE_H
#include <kernel/base.h>
#endif
#ifndef _KALKERN_LOG_H
#define _KALKERN_LOG_H
error_t KernLog(const char *, ...);
#ifndef _NO_DEBUG
void DebugLog(const char *, ...);
#else // _NO_DEBUG
#define DebugLog(fmt, ...)
#endif
#endif

View File

@ -1,116 +0,0 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
// Desc: Terminal-related functions //
// //
// //
// Copyright © 2018-2019 The OS/K Team //
// //
// This file is part of OS/K. //
// //
// OS/K is free software: you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or //
// any later version. //
// //
// OS/K is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY//without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//
#ifndef _KALKERN_PROC_H
#include <kernel/proc.h> // for GetCurProc() and Process_t
#endif
#ifndef _KALKERN_TERM_H
#define _KALKERN_TERM_H
//------------------------------------------//
//
// Size of a tabulation in spaces
// Default: 4 spaces/tab
//
enum { KTABSIZE = 4 };
//
// Upper bound on what a single KernLog() can write
//
enum { KLOG_MAX_BUFSIZE = 4096 };
//
// The VGA colors
//
enum TermColor_t
{
KTERM_COLOR_BLACK, KTERM_COLOR_BLUE,
KTERM_COLOR_GREEN, KTERM_COLOR_CYAN,
KTERM_COLOR_RED, KTERM_COLOR_MAGENTA,
KTERM_COLOR_BROWN, KTERM_COLOR_LGREY,
KTERM_COLOR_DARK_GREY, KTERM_COLOR_LBLUE,
KTERM_COLOR_LGREEN, KTERM_COLOR_LCYAN,
KTERM_COLOR_LRED, KTERM_COLOR_LMAGENTA,
KTERM_COLOR_LBROWN, KTERM_COLOR_WHITE
};
//
// Terminal structure, right now VGA and output only
//
struct Terminal_t
{
uint initDone;
Lock_t lock;
const char *name;
const char *type;
void *data;
size_t width;
size_t height;
off_t currentX;
off_t currentY;
uint tabSize;
TermColor_t fgColor;
TermColor_t bgColor;
// Defined in driver
error_t (*clear)(Terminal_t *);
error_t (*putchar)(Terminal_t *, char);
};
//------------------------------------------//
void InitTerms(void);
error_t ClearTerm(Terminal_t *);
error_t ChTermColor(Terminal_t *, TermColor_t, TermColor_t);
error_t PutOnTerm(Terminal_t *, char);
error_t PutOnTermUnlocked(Terminal_t *, char);
error_t PrintOnTerm(Terminal_t *, const char *);
error_t PrintOnTermUnlocked(Terminal_t *, const char *);
error_t KernLog(const char *, ...);
//------------------------------------------//
extern Terminal_t *StdOut;
extern Terminal_t *StdDbg;
//------------------------------------------//
#ifndef _NO_DEBUG
error_t DebugLog(const char *, ...);
#else // _NO_DEBUG
#define DebugLog(fmt, ...) EOK
#endif
//------------------------------------------//
#endif

View File

@ -24,9 +24,7 @@
#include <kernel/buf.h> #include <kernel/buf.h>
#include <kernel/term.h> //XXX extern error_t bputc(Buffer_t *buf, uchar ch);
error_t bputc(Buffer_t *buf, uchar ch);
// //
// Prints formatted string on buf according to fmt // Prints formatted string on buf according to fmt
@ -74,6 +72,10 @@ static error_t bdopadding(Buffer_t *buf, size_t width, size_t len,
return rc; return rc;
} }
#define bdoconvrt(pref, type, vtype) do { \
type i_##type = (type)va_arg(ap, vtype); \
pref##toa(i_##type, s, base); \
} while (0)
// Increase fmt while parsing a modifier // Increase fmt while parsing a modifier
#define fmtnext() do{fmt++;if(*fmt==0){rc=EINVAL;goto leave;}}while(0) #define fmtnext() do{fmt++;if(*fmt==0){rc=EINVAL;goto leave;}}while(0)
@ -89,11 +91,11 @@ error_t BPrintOnBufV(Buffer_t *buf, const char *fmt, va_list ap)
size_t width; size_t width;
char type; char type;
uchar *s;
uchar uch; uchar uch;
char *s;
// Conversion buffer // Conversion buffer
uchar convbuf[100] = {0}; char convbuf[100];
size_t len; size_t len;
// Flags // Flags
@ -126,7 +128,7 @@ error_t BPrintOnBufV(Buffer_t *buf, const char *fmt, va_list ap)
loop: loop:
// Deal with all non-'%' characters // Deal with all non-'%' characters
for (; !rc && *fmt && *fmt != '%' ; fmt++) { for (; *fmt && *fmt != '%' ; fmt++) {
rc = bputc(buf, *fmt); rc = bputc(buf, *fmt);
continue; continue;
} }
@ -213,6 +215,7 @@ loop:
// //
// Precision field // Precision field
// Ignored until floats are implemented // Ignored until floats are implemented
// TODO before floats: %.XXXs
// //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
@ -234,7 +237,7 @@ loop:
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// //
// The type field, finally! // The type field
// //
type = *fmt++; type = *fmt++;
@ -248,10 +251,12 @@ loop:
// Strings // Strings
else if (type == 's') { else if (type == 's') {
s = (uchar *)va_arg(ap, char *); s = va_arg(ap, char *);
if (s == NULL) s = "(null)";
for (; !rc && *s ; s++) { for (; !rc && *s ; s++) {
rc = bputc(buf, *s); rc = bputc(buf, (uchar)*s);
} }
if (rc > 0) goto leave; if (rc > 0) goto leave;
@ -288,26 +293,27 @@ loop:
// We re-use s to iterate convbuf // We re-use s to iterate convbuf
s = convbuf; s = convbuf;
// Deal with signed conversions if (!l) {
if (sgn) { if (sgn) {
if (l) ltoa(va_arg(ap, long), (char *)s, base); if (h == 0) bdoconvrt(i, int, int);
else if (h == 0) itoa(va_arg(ap, int), (char *)s, base); if (h == 1) bdoconvrt(i, short, int);
else if (h == 1) itoa((short)va_arg(ap, int), (char *)s, base); if (h == 2) bdoconvrt(i, char, int);
else /* h == 2 */ itoa((char)va_arg(ap, int), (char *)s, base); } else {
if (h == 0) bdoconvrt(u, uint, uint);
if (h == 1) bdoconvrt(u, ushort, uint);
if (h == 2) bdoconvrt(u, uchar, uint);
}
} }
// Deal with unsigned conversions
else { else {
if (l) ultoa((ulong)va_arg(ap, long), (char *)s, base); if (sgn) bdoconvrt(l, long, long);
else if (h == 0) utoa((uint)va_arg(ap, int), (char *)s, base); else bdoconvrt(ul, ulong, ulong);
else if (h == 1) utoa((ushort)va_arg(ap, int), (char *)s, base);
else /* h == 2 */ utoa((uchar)va_arg(ap, int), (char *)s, base);
} }
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// //
// Implement flags and %X // Implement flags and %X, and prints
// //
// Capital letter digits // Capital letter digits
@ -321,7 +327,7 @@ loop:
// Reset s // Reset s
s = convbuf; s = convbuf;
} }
else len = strlen((char *)s); else len = strlen(s);
// Adjust width // Adjust width
if (sgn && (plus || space)) width--; if (sgn && (plus || space)) width--;
@ -346,7 +352,7 @@ loop:
// Output the actual number // Output the actual number
// //
for (; !rc && *s ; s++) { for (; !rc && *s ; s++) {
rc = bputc(buf, *s); rc = bputc(buf, (uchar)*s);
} }
// 'minus' padding, only with spaces // 'minus' padding, only with spaces
@ -355,12 +361,6 @@ loop:
if (rc > 0) goto leave; if (rc > 0) goto leave;
//----------------------------------------------------------------------------//
// Make sure we leave convbuf filled with NULs
memzero(convbuf, sizeof(convbuf));
// Continue parsing fmt // Continue parsing fmt
goto loop; goto loop;

View File

@ -50,7 +50,7 @@ error_t BPutOnBuf(Buffer_t *buf, uchar ch)
// //
error_t bputc(Buffer_t *buf, uchar ch) error_t bputc(Buffer_t *buf, uchar ch)
{ {
error_t rc; error_t rc = EOK;
size_t bufSize, pbCount; size_t bufSize, pbCount;
// Implements playback / scrolling up when line buffering // Implements playback / scrolling up when line buffering
@ -84,6 +84,7 @@ error_t bputc(Buffer_t *buf, uchar ch)
rc = bputc(buf, ' '); rc = bputc(buf, ' ');
} }
if (rc > 0) return rc; if (rc > 0) return rc;
if (buf->flusher) buf->flusher(buf);
} }
// Just a regular character // Just a regular character
@ -116,7 +117,7 @@ error_t bputc(Buffer_t *buf, uchar ch)
} }
} }
// Write the damn thing // Write it
*buf->wp++ = ch; *buf->wp++ = ch;
// Did we reach the end of line? // Did we reach the end of line?

View File

@ -25,6 +25,8 @@
#include <kernel/buf.h> #include <kernel/buf.h>
#include <extras/malloc.h> #include <extras/malloc.h>
Buffer_t *BStdOut, *BStdDbg;
// Straightforward functions // Straightforward functions
int BGetFlags(Buffer_t *buf) { return buf->flags; } int BGetFlags(Buffer_t *buf) { return buf->flags; }
int BGetState(Buffer_t *buf) { return buf->state; } int BGetState(Buffer_t *buf) { return buf->state; }
@ -82,8 +84,6 @@ Buffer_t *BOpenPureBuf(char *source, size_t size)
} }
#endif #endif
extern BFlusher_t _VGA_BFlusher;
// //
// Creates a lined buffer of (nLines + pbCount*nLines) lines each // Creates a lined buffer of (nLines + pbCount*nLines) lines each
// of lineLen length (pb = playback buffer, for scrolling up) // of lineLen length (pb = playback buffer, for scrolling up)
@ -94,7 +94,10 @@ Buffer_t *BOpenLineBuf(char *source, int mode,
assert(lineLen > 0 && nLines > 0 && pbCount >= 0); assert(lineLen > 0 && nLines > 0 && pbCount >= 0);
assert(mode == BS_RDWR || mode == BS_RDONLY || mode == BS_WRONLY); assert(mode == BS_RDWR || mode == BS_RDONLY || mode == BS_WRONLY);
Buffer_t *buf = malloc(sizeof *buf); //Buffer_t *buf = malloc(sizeof *buf);
static Buffer_t __buf;
Buffer_t *buf = &__buf;
ExInitLock(&buf->lock, KLOCK_MUTEX); ExInitLock(&buf->lock, KLOCK_MUTEX);
ExAcquireLock(&buf->lock); ExAcquireLock(&buf->lock);

View File

@ -25,9 +25,9 @@
#include <kernel/mboot.h> #include <kernel/mboot.h>
#include <kernel/panic.h> #include <kernel/panic.h>
#include <kernel/sched.h> #include <kernel/sched.h>
#include <kernel/term.h>
#include <kernel/heap.h> #include <kernel/heap.h>
#include <kernel/buf.h> #include <kernel/buf.h>
#include <kernel/log.h>
#include <kernel/mm.h> #include <kernel/mm.h>
@ -111,6 +111,10 @@ void BtInitBootInfo(multiboot_info_t *mbi)
} }
extern void pstest(void); extern void pstest(void);
extern error_t IoInitVGABuffer(void);
#define BARRIER() do{\
asm volatile("": : :"memory");__sync_synchronize();}while(0)
// //
// Entry point of the Kaleid kernel // Entry point of the Kaleid kernel
@ -120,13 +124,16 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, int mbMagic)
// We're not ready to deal with interrupts // We're not ready to deal with interrupts
KeDisableIRQs(); KeDisableIRQs();
//Initialize the BootInfo_t structure // Initialize the BootInfo_t structure
BtInitBootInfo(mbInfo); BtInitBootInfo(mbInfo);
// Kernel terminals
InitTerms();
//Hello world because why not // Get ready to print things
IoInitVGABuffer();
BARRIER();
// Hello world
KernLog("%c%c%c OS/K\n\n", 219, 219, 219); KernLog("%c%c%c OS/K\n\n", 219, 219, 219);
KalAlwaysAssert(mbMagic == MULTIBOOT_BOOTLOADER_MAGIC); KalAlwaysAssert(mbMagic == MULTIBOOT_BOOTLOADER_MAGIC);
@ -145,10 +152,8 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, int mbMagic)
MmInitHeap(); MmInitHeap();
PsInitSched(); PsInitSched();
//Buffer_t *buf = BOpenLineBuf(NULL, BS_WRONLY, 80, 24, 1, NULL); int i = 0;
//error_t rc = BPrintOnBuf(buf, "%+#05x", 0xcafeb00b); while (i < 57) KernLog("YOHOHO! %d\n", i++);
//if(rc)KernLog("error\n");
//KernLog((char*)buf->buf);
// We're out // We're out
PsFiniSched(); PsFiniSched();

View File

@ -24,11 +24,11 @@
#include <kernel/base.h> #include <kernel/base.h>
int cpuCount = 1; volatile int cpuCount = 1;
Processor_t cpuTable[NCPUS] = {0}; volatile Processor_t cpuTable[NCPUS] = {0};
BootInfo_t bootTab = {0}; volatile BootInfo_t bootTab = {0};
Terminal_t *StdOut = 0, *StdDbg = 0; Terminal_t *StdOut = 0, *StdDbg = 0;
volatile char KePanicStr[PANICSTR_SIZE] = {0}; volatile char KePanicStr[PANICSTR_SIZE] = {0};

View File

@ -1,214 +0,0 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
// Desc: Terminal-related functions //
// //
// //
// Copyright © 2018-2019 The OS/K Team //
// //
// This file is part of OS/K. //
// //
// OS/K is free software: you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or //
// any later version. //
// //
// OS/K is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY//without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//
#include <kernel/term.h>
extern void VGA_Init(void);
extern Terminal_t VGA_Terminal;
//
// Initializes standard output
//
void InitTerms(void)
{
KalAssert(!StdOut && !StdDbg);
VGA_Init();
StdDbg = &VGA_Terminal;
StdOut = &VGA_Terminal;
ClearTerm(StdOut);
}
//
// Fills terminal with spaces
//
error_t ClearTerm(Terminal_t *term)
{
error_t retcode;
if (term == NULL) return EINVAL;
KalAssert(term->initDone == INITOK);
ExAcquireLock(&term->lock);
retcode = term->clear(term);
ExReleaseLock(&term->lock);
return retcode;
}
//
// Changes the color code
//
error_t ChTermColor(Terminal_t *term, TermColor_t fgColor, TermColor_t bgColor)
{
if (fgColor > KTERM_COLOR_WHITE || bgColor > KTERM_COLOR_WHITE)
return EINVAL;
if (term == NULL)
return EINVAL;
ExAcquireLock(&term->lock);
term->fgColor = fgColor;
term->bgColor = bgColor;
ExReleaseLock(&term->lock);
return EOK;
}
//
// Writes a single character on the terminal (UNLOCKED version)
//
error_t PutOnTermUnlocked(Terminal_t *term, char ch)
{
uint i;
size_t prevY;
error_t rc = EOK;
if (ch == '\r') {
term->currentX = 0;
return EOK;
}
// Line feed first takes us to the very end of the line
// Later in this function we actually do the line feed
else if (ch == '\n') {
term->currentX = term->width - 1;
}
// Tabulations account for "term->tabSize" spaces
else if (ch == '\t') {
prevY = term->currentX;
for (i = 0; i < term->tabSize; i++) {
// Make sure tabulations can't spread over two lines
if (term->currentX == prevY) {
rc = term->putchar(term, ' ');
if (rc) return rc;
}
}
}
else rc = term->putchar(term, ch);
// Did we reach the end of line?
if (!rc && ++term->currentX == term->width) {
term->currentX = 0;
// Did we reach the buffer's end?
if (++term->currentY == term->height) {
term->currentY = 0;
}
}
return rc;
}
//
// Writes a single character on the terminal (LOCKED version)
//
error_t PutOnTerm(Terminal_t *term, char ch)
{
error_t rc;
if (term == NULL) return EINVAL;
KalAssert(term->initDone == INITOK);
ExAcquireLock(&term->lock);
rc = PutOnTermUnlocked(term, ch);
ExReleaseLock(&term->lock);
return rc;
}
//
// Prints string on terminal (UNLOCKED version)
//
error_t PrintOnTermUnlocked(Terminal_t *term, const char *str)
{
error_t rc = EOK;
while (*str && rc == EOK) {
rc = PutOnTermUnlocked(term, *str++);
}
return rc;
}
//
// Prints string on terminal (LOCKED version)
//
error_t PrintOnTerm(Terminal_t *term, const char *str)
{
error_t rc = EOK;
if (term == NULL) return EINVAL;
KalAssert(term->initDone == INITOK);
ExAcquireLock(&term->lock);
rc = PrintOnTermUnlocked(term, str);
ExReleaseLock(&term->lock);
return rc;
}
//
// Prints formatted string on standard output
// Prints at most KLOG_MAX_BUFSIZE characters
//
error_t KernLog(const char *fmt, ...)
{
va_list ap;
char logbuf[KLOG_MAX_BUFSIZE];
va_start(ap, fmt);
vsnprintf(logbuf, KLOG_MAX_BUFSIZE, fmt, ap);
va_end(ap);
return PrintOnTerm(StdOut, logbuf);
}
#ifndef _NO_DEBUG
//
// Prints formatted string on debug output
// Prints at most KLOG_MAX_BUFSIZE characters
//
error_t DebugLog(const char *fmt, ...)
{
va_list ap;
char logbuf[KLOG_MAX_BUFSIZE];
va_start(ap, fmt);
vsnprintf(logbuf, KLOG_MAX_BUFSIZE, fmt, ap);
va_end(ap);
return PrintOnTerm(StdDbg, logbuf);
}
#endif

View File

@ -22,7 +22,7 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kernel/term.h> #include <kernel/buf.h>
//----------------------------------------------------------// //----------------------------------------------------------//
// Internal functions for VGA terminals // // Internal functions for VGA terminals //
@ -37,73 +37,48 @@
#define VGA_ComputeEntry(ch, cl) (((ushort)(ch)) | (ushort)(cl) << 8) #define VGA_ComputeEntry(ch, cl) (((ushort)(ch)) | (ushort)(cl) << 8)
// //
// Clears terminal // VGA Buffer Flusher
// //
error_t VGA_ClearTermUnlocked(Terminal_t *term) error_t bvgaflusher(Buffer_t *buf)
{ {
const uchar color = VGA_ComputeColorCode(term->fgColor, term->bgColor); ushort *fbp = BtGetBootInfo(video).framebufferAddr;
const ushort filler = VGA_ComputeEntry(' ', color); const uchar color = 0xf;
const size_t bufsize = term->width * term->height;
// Fill the buffer uchar *currentLine = buf->wp - buf->lineLen;
memsetw((ushort *)term->data, filler, bufsize); uchar *ptr = (uchar *)lmax((size_t)buf->buf,
(size_t)currentLine
- (buf->nLines - 1) * buf->lineLen);
// XXX update cursor too for (; ptr < buf->wp ; ptr++) {
term->currentX = term->currentY = 0; *fbp++ = VGA_ComputeEntry(*ptr, color);
}
const size_t bufSize = buf->nLines * buf->lineLen;
ushort *fbe = BtGetBootInfo(video).framebufferAddr
+ (bufSize * sizeof(ushort));
if (fbp < fbe) {
const ushort filler = VGA_ComputeEntry(' ', color);
while (fbp < fbe) *fbp++ = filler;
}
return EOK; return EOK;
} }
// //
// Writes a single character on the terminal // Initialize VGA buffer
// //
error_t VGA_PutOnTermUnlocked(Terminal_t *term, char ch) error_t IoInitVGABuffer(void)
{ {
ushort *buffer = (ushort *)term->data; static char bvgabuffer[1 * MB];
const size_t offset =
VGA_ComputeOffset(term, term->currentX, term->currentY); BStdOut = BOpenLineBuf(bvgabuffer, BS_WRONLY,
buffer[offset] = VGA_ComputeEntry(ch, BtGetBootInfo(video).framebufferWidth,
VGA_ComputeColorCode(term->fgColor, term->bgColor)); BtGetBootInfo(video).framebufferHeight,
8, bvgaflusher);
BStdDbg = BStdOut;
return EOK; return EOK;
} }
//
// VGA output
//
Terminal_t VGA_Terminal = {
.initDone = FALSE,
.lock = ExINITLOCK(KLOCK_MUTEX),
.name = "VGA Output Terminal",
.type = "VGA",
.data = (void *)0,
.width = 0,
.height = 0,
.currentX = 0,
.currentY = 0,
.tabSize = KTABSIZE,
.fgColor = KTERM_COLOR_LGREY,
.bgColor = KTERM_COLOR_BLACK,
.clear = VGA_ClearTermUnlocked,
.putchar = VGA_PutOnTermUnlocked,
};
//
// Initialize VGA output
//
void VGA_Init(void)
{
KalAssert(VGA_Terminal.initDone != INITOK);
//Use the infos provided in the BootInfo_t structure
VGA_Terminal.data = BtGetBootInfo(video).framebufferAddr;
VGA_Terminal.width = BtGetBootInfo(video).framebufferWidth;
VGA_Terminal.height = BtGetBootInfo(video).framebufferHeight;
VGA_Terminal.initDone = INITOK;
}

55
kaleid/kernel/ke/log.c Normal file
View File

@ -0,0 +1,55 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
// Desc: KernLog() and DebugLog() //
// //
// //
// Copyright © 2018-2019 The OS/K Team //
// //
// This file is part of OS/K. //
// //
// OS/K is free software: you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or //
// any later version. //
// //
// OS/K is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY//without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//
#include <kernel/buf.h>
//
// Prints formatted string on standard output
//
error_t KernLog(const char *fmt, ...)
{
error_t rc;
va_list ap;
va_start(ap, fmt);
rc = BPrintOnBufV(BStdOut, fmt, ap);
va_end(ap);
return rc;
}
#ifndef _NO_DEBUG
//
// Prints formatted string on debug output
//
void DebugLog(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
BPrintOnBufV(BStdDbg, fmt, ap);
va_end(ap);
}
#endif

View File

@ -22,7 +22,10 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kernel/term.h> #include <kernel/log.h>
#include <kernel/buf.h>
#include <kernel/proc.h>
#include <kernel/sched.h>
#include <kernel/panic.h> #include <kernel/panic.h>
// //
@ -50,14 +53,14 @@ noreturn void KeStartPanic(const char *fmt, ...)
KeDisableIRQs(); KeDisableIRQs();
PsCurProc = NULL; PsCurProc = NULL;
if (StdOut == NULL) KeCrashSystem(); if (BStdOut == NULL) KeCrashSystem();
if (fmt == NULL) { if (fmt == NULL) {
fmt = "(no message given)"; fmt = "(no message given)";
} }
if (KePanicStr[0] != 0) { if (KePanicStr[0] != 0) {
PrintOnTermUnlocked(StdOut, "\nDouble panic!"); KernLog("\nDouble panic!");
KeHaltCPU(); KeHaltCPU();
} }
@ -65,8 +68,8 @@ noreturn void KeStartPanic(const char *fmt, ...)
vsnprintf((char *)KePanicStr, PANICSTR_SIZE, fmt, ap); vsnprintf((char *)KePanicStr, PANICSTR_SIZE, fmt, ap);
va_end(ap); va_end(ap);
PrintOnTermUnlocked(StdOut, "\nPanic!\n\n"); KernLog("\nPanic!\n\n");
PrintOnTermUnlocked(StdOut, (char *)KePanicStr); KernLog((char *)KePanicStr);
KeHaltCPU(); KeHaltCPU();
} }

View File

@ -22,9 +22,9 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kernel/heap.h>
#include <kernel/mm.h> #include <kernel/mm.h>
#include <kernel/term.h> #include <kernel/log.h>
#include <kernel/heap.h>
// Least address out of the heap // Least address out of the heap
static void *_heap_end; static void *_heap_end;

View File

@ -23,7 +23,7 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kernel/mm.h> #include <kernel/mm.h>
#include <kernel/term.h> #include <kernel/log.h>
#include <kernel/mboot.h> #include <kernel/mboot.h>
// Initializes globally the memory map // Initializes globally the memory map

View File

@ -25,7 +25,7 @@
#include <extras/list.h> #include <extras/list.h>
#include <kernel/proc.h> #include <kernel/proc.h>
#include <kernel/sched.h> #include <kernel/sched.h>
#include <kernel/term.h> #include <kernel/log.h>
// //
// For test purpose only // For test purpose only
@ -379,7 +379,7 @@ void PrintList(ListHead_t *head)
void pstest(void) void pstest(void)
{ {
ClearTerm(StdOut); //ClearTerm(StdOut);
KernLog("\nTime Critical: "); KernLog("\nTime Critical: ");
PrintList(TimeCritProcs); PrintList(TimeCritProcs);
@ -396,7 +396,7 @@ void pstest(void)
int tick = 0; int tick = 0;
while (tick < 24) { while (tick < 24) {
if (tick%25==0)ClearTerm(StdOut); //if (tick%25==0)ClearTerm(StdOut);
if (tick > 0 && tick != 50 && tick % 10 == 0) { if (tick > 0 && tick != 50 && tick % 10 == 0) {
KernLog("Blocking current process\n"); KernLog("Blocking current process\n");
PsBlockCurProc(); PsBlockCurProc();

634184
kaleid32_disasm.asm Normal file

File diff suppressed because it is too large Load Diff

630816
kaleid64_disasm.asm Normal file

File diff suppressed because it is too large Load Diff