Common stuff

This commit is contained in:
Julian Barathieu 2018-12-31 10:49:08 +01:00
parent 680ca2a52c
commit 15a7ad873f
25 changed files with 346 additions and 414 deletions

View File

@ -12,10 +12,13 @@ CC2NAME=gcc
COPTIM=-O2
CLDSCR=-T kernel.ld
CWARNS=-pedantic -Wall -Wextra -Werror
CFLAGS=-nostdlib -ffreestanding -mcmodel=large -mno-red-zone -mno-mmx -mno-sse -mno-sse2
CINCLUDES=-isystem.
CDEFINES=
CFLAGS1=-nostdlib -ffreestanding -mcmodel=large
CFLAGS2=-mno-red-zone -mno-mmx -mno-sse -mno-sse2
CFLAGS=$(CFLAGS1) $(CFLAGS2)
CC=$(CCNAME) $(COPTIM) $(CWARNS) $(CFLAGS) $(CDEFINES) $(CINCLUDES)
KCC=$(CC) -D_KALEID_KERNEL
@ -32,7 +35,7 @@ KERNDIR=kaleid/kernel
SYSTDIR=kaleid/system
LINXDIR=kaleid/linux
all: bootloader
all: bootloader kernel
boot.mbr.s: $(BOOTDIR)/mbr.s $(BOOTDIR)/mbr.inc
$(ASM) $(BOOTFLAGS) $(BOOTDIR)/mbr.s -o $(OBJDIR)/boot/mbr.bin
@ -59,10 +62,10 @@ testing: bootloader pseudo_kern
COBJDIR=$(OBJDIR)/$(COMMDIR)
LOBJDIR=$(OBJDIR)/$(LINXDIR)
COMMDEPS=$(COMMDIR)/common.h $(COMMDIR)/assert.h $(COMMDIR)/atomic.h $(KERNDIR)/config.h \
$(COMMDIR)/status.h
COMMDEPS=$(COMMDIR)/common.h $(COMMDIR)/stdlib.h $(KERNDIR)/config.h
COMMOBJS=$(COBJDIR)/lib/string.o $(COBJDIR)/lib/status.o $(COBJDIR)/lib/convert.o $(COBJDIR)/lib/memory.o
COMMOBJS=$(COBJDIR)/lib/string.o $(COBJDIR)/lib/status.o \
$(COBJDIR)/lib/convert.o $(COBJDIR)/lib/memory.o
common: $(COMMDEPS) $(COMMDIR)/lib/string.c $(COMMDIR)/lib/status.c
$(KCC) -c $(COMMDIR)/lib/string.c -o $(COBJDIR)/lib/string.o
@ -85,9 +88,14 @@ test-common:
KOBJDIR=$(OBJDIR)/$(KERNDIR)
KERNDEPS=common $(KERNDIR)/init.h $(KERNDIR)/io/terminal.h $(KERNDIR)/io/ports.h $(KERNDIR)/ke/panic.h
KERNSRCS=$(KERNDIR)/init.c $(KERNDIR)/ke/state.c $(KERNDIR)/ke/panic.c $(KERNDIR)/io/ports.c $(KERNDIR)/io/terminal.c
KERNOBJS=$(KOBJDIR)/init.o $(KOBJDIR)/ke/state.o $(KOBJDIR)/ke/panic.o $(KOBJDIR)/io/ports.o $(KOBJDIR)/io/terminal.o
KERNDEPS=common $(KERNDIR)/init.h $(KERNDIR)/io/terminal.h \
$(KERNDIR)/io/ports.h $(KERNDIR)/ke/panic.h
KERNSRCS=$(KERNDIR)/init.c $(KERNDIR)/ke/state.c $(KERNDIR)/ke/panic.c \
$(KERNDIR)/io/ports.c $(KERNDIR)/io/terminal.c
KERNOBJS=$(KOBJDIR)/init.o $(KOBJDIR)/ke/state.o $(KOBJDIR)/ke/panic.o \
$(KOBJDIR)/io/ports.o $(KOBJDIR)/io/terminal.o
kernel: common $(KERNSRCS)
$(KCC) -c $(KERNDIR)/init.c -o $(KOBJDIR)/init.o

View File

@ -1,52 +0,0 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
// Authors: spectral` //
// NeoX //
// //
// Desc: Assertions //
//----------------------------------------------------------------------------//
#ifndef _KALCOMM_ASSERT_H
#define _KALCOMM_ASSERT_H
#ifndef _KALCOMM_COMMON_H
# error "don't include kaleid/common/types.h without kaleid/common/common.h"
#endif
#ifdef _OSK_SOURCE
#if !defined(_NO_DEBUG) && !defined(NDEBUG)
// uses panic() in kernel, abort() in system
noreturn void ___assert_handler(const char *, const char *, int, const char *);
#define DosAssert(x) do{if(unlikely(!(x)))___assert_handler(#x, __FILE__, __LINE__, __func__);}while(0);
#define assert DosAssert
#else // not debugging
#if !defined(NDEBUG)
# define NDEBUG 1
#endif
#if !defined(_NO_DEBUG)
# define _NO_DEBUG 1
#endif
#define assert(x)
#endif
#else // !defined(_OSK_SOURCE)
#if defined(_NO_DEBUG) && !defined(NDEBUG)
# define NDEBUG 1
#endif
#include <assert.h>
#endif
#endif

View File

@ -10,8 +10,14 @@
#ifndef _KALCOMM_COMMON_H
#define _KALCOMM_COMMON_H
#if !defined(_OSK_SOURCE) && (defined(_KALEID_KERNEL) || defined(_KALEID_SYSTEM))
# define _OSK_SOURCE 1
//------------------------------------------//
// PREPROCESSOR CONSTANTS //
//------------------------------------------//
#if !defined(_OSK_SOURCE)
# if defined(_KALEID_KERNEL) || defined(_KALEID_SYSTEM)
# define _OSK_SOURCE 1
# endif
#endif
#if !defined(TRUE) && !defined(FALSE)
@ -37,8 +43,8 @@
#endif
#if !defined(likely) && !defined(unlikely)
# define likely(x) __builtin_expect((x), 1)
# define unlikely(x) __builtin_expect((x), 0)
# define likely(x) (__builtin_expect((x), 1))
# define unlikely(x) (__builtin_expect((x), 0))
#endif
#ifndef INITOK
@ -49,10 +55,116 @@
# include <kaleid/kernel/config.h>
#endif
#include <kaleid/common/types.h>
#include <kaleid/common/atomic.h>
#include <kaleid/common/status.h>
#include <kaleid/common/assert.h>
//------------------------------------------//
// COMMON TYPES //
//------------------------------------------//
typedef unsigned char uchar;
typedef unsigned short ushort;
typedef unsigned int uint;
typedef unsigned long ulong;
typedef long long llong;
typedef unsigned long long ullong;
typedef long double ldouble;
typedef short port_t;
typedef short status_t;
#ifndef KEEP_KALCOMM_TYPES_MINIMAL
typedef _Bool bool;
typedef uint wchar_t;
typedef ullong size_t;
typedef llong ssize_t;
typedef size_t off_t;
typedef int atomic_t;
typedef ulong pid_t;
typedef void *va_list;
#endif
// XXX limits
//------------------------------------------//
// VALUES FOR "status_t" //
//------------------------------------------//
#ifndef _OSK_SOURCE
# define describe_status _osk_describe_status
#endif
// see in common/lib/status.c for status messages
const char *describe_status(status_t);
#define STATUS_FAILED(x) ((x) < 0))
#define STATUS_SUCCESS(x) (!STATUS_FAILED(x))
#define SUCCESS (0) // everything went fine
#define FAILED (-1)
#define ERROR FAILED // something went wrong
#define NOT_PERMITTED (-2)
#define ACCESS_DENIED (-3)
#define BAD_ARGUMENT (-4) // invalid arguments
#define BAD_ARG_RANGE (-5) // arguments out of range
#define BAD_ARG_NULL (-6) // unexpected NULL argument
#define TRY_AGAIN (-7) // EAGAIN
//------------------------------------------//
// INLINE ASM MACROS //
//------------------------------------------//
#ifdef _KALEID_KERNEL
# define DosDisableInterrupts() asm volatile ("cli")
# define DosEnableInterrupts() asm volatile ("sti")
# define DosHaltCPU() asm volatile ("hlt")
#endif
//------------------------------------------//
// assert()/DosAssert() SUPPORT //
//------------------------------------------//
#ifdef _OSK_SOURCE
#if !defined(_NO_DEBUG) && !defined(NDEBUG)
// uses panic() in kernel, abort() in system
noreturn void ___assert_handler(const char *, const char *, int, const char *);
#define DosAssert(x) \
do { \
if unlikely(!(x)) \
___assert_handler(#x, __FILE__, __LINE__, __func__); \
} while (FALSE);
#define assert DosAssert
#else // not debugging
#if !defined(NDEBUG)
# define NDEBUG 1
#endif
#if !defined(_NO_DEBUG)
# define _NO_DEBUG 1
#endif
#define assert(x)
#endif
#else // !defined(_OSK_SOURCE)
#if defined(_NO_DEBUG) && !defined(NDEBUG)
# define NDEBUG 1
#endif
#include <assert.h>
#endif
//------------------------------------------//
// END OF "kaleid/common/common.h" //
//------------------------------------------//
#endif

View File

@ -1,24 +0,0 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
// Authors: spectral` //
// NeoX //
// //
// Desc: Conversion utilities //
//----------------------------------------------------------------------------//
#ifndef _KALCOMM_CONVERT_H
#define _KALCOMM_CONVERT_H
#ifndef _KALCOMM_COMMON_H
#include <kaleid/common/common.h>
#endif
#ifndef _OSK_SOURCE
# define itoa _osk_itoa
# define atoi _osk_atoi
#endif
char *itoa(int, char *, int);
#endif

View File

@ -7,35 +7,31 @@
Desc: Folder description - "kaleid/common"
---------------------------------------------------------------------
This is the folder containing the sources for Kaleid's C runtime library, linked both to the kernel
and to the system processes that run outiside the kernel. It can also be compiled for Linux as
(very basic) C library, for test purposes.
This is the folder containing the sources for Kaleid's C runtime library, linked
both to the kernel and to the system processes that run outiside the kernel.
It can also be compiled for Linux as a very basic C library, for test purposes.
This folder contains the following files:
- common.h
This file is to be included by every source file using the library, and it includes in turn
the following files:
- assert.h
Defines the macro "assert()". Currently any program wanting to use this macro has to
implement its own "___assert_handler(const char *cond, const char *file, int line, const char *func)"
but an (overridable) default handler will be furnished in the future.
- atomic.h
Support for atomic operations. When compiled by the kernel, also furnishes macros for
enabling/disabling interrupts. This will change in the future.
- status.h
Defines the different values of the "status_t" type used throughout Kaleid and related
utilitary functions.
- types.h
Provides the elementary types (size_t, etc) used throught Kaleid.
- convert.h
Contains the declaration of conversion utilities (e.g. itoa())
It is included by string.h
- memory.h
Contains the declaration of the mem*() family of utilities (e.g. memcpy())
- string.h
Contains the declaration of various string-related utilities (including the sprintf() family)
Includes convert.h
This file is to be included by every source file using the library.
It:
- Provides the elementary types (e.g. size_t) used through Kaleid.
- Defines the different values of the "status_t" type used
throughout Kaleid and related utilitary functions.
- Defines the macro "assert()". Currently any program wanting to
use this macro has to implement its own handler:
noreturn void ___assert_handler(const char *cond,
const char *file,
int line,
const char *func)
but an overridable default handler will be furnished later.
- stlib.h
The include file for most of functions of the common library, notably
- Memory management utilities (e.g. memset())
- String manipulation utilities (e.g. strcpy())
- Type conversion utilities (e.g. itoa())

View File

@ -7,7 +7,7 @@
// Desc: Conversion utilities //
//----------------------------------------------------------------------------//
#include <kaleid/common/string.h>
#include <kaleid/common/stdlib.h>
//
// Digits table for bases <=36

View File

@ -7,17 +7,64 @@
// Desc: mem*() functions //
//----------------------------------------------------------------------------//
#include <kaleid/common/memory.h>
// XXX to be improved before being brought back
// to be tested with more alignment sizes
#include <kaleid/common/stdlib.h>
// to be moved
#define QWORD_SIZE 8
#define QWORD_ALIGN 8
//
// Set "qwords"-many aligned qwords starting from ptr to val
//
static inline void *memsetq(void *ptr, ullong uval, size_t qwords)
{
size_t n;
ullong *uptr = (ullong *)ptr;
// aligned memory write
for (n = 0; n < qwords; n++) {
*(uptr + n) = uval;
}
return ptr;
}
//
// Set "bytes"-many bytes starting from ptr to val
//
void *memset(void *ptr, int val, size_t bytes)
{
uchar uval = val & 0xFF;
uchar *uptr = (uchar *)ptr;
const size_t qwords = bytes/QWORD_SIZE;
while (bytes--) *uptr++ = uval;
// get rid of everything after the first byte
val = val & 0xFF;
// deal with bytes before start of the first aligned qword
while (((ullong)uptr % QWORD_ALIGN) > 0 && bytes--) {
*uptr++ = (uchar)val;
}
// move qword by qword
if (qwords) {
const ullong uval = ((ullong)val << 56) | ((ullong)val << 48)
| ((ullong)val << 40) | ((ullong)val << 32)
| ((ullong)val << 24) | ((ullong)val << 16)
| ((ullong)val << 8) | ((ullong)val);
memsetq(uptr, uval, qwords);
uptr += qwords * QWORD_SIZE;
bytes %= QWORD_SIZE;
}
// deal with what's left
while (bytes--) {
*uptr++ = (uchar)val;
}
return ptr;
}
@ -27,11 +74,6 @@ void *memset(void *ptr, int val, size_t bytes)
//
void *memzero(void *ptr, size_t bytes)
{
uchar *uptr = (uchar *)ptr;
while (bytes--) *uptr++ = 0;
return ptr;
return memset(ptr, 0, bytes);
}

View File

@ -4,26 +4,34 @@
// Authors: spectral` //
// NeoX //
// //
// Desc: Atomic stuff //
// Desc: mem*() functions, suboptimal edition //
//----------------------------------------------------------------------------//
#ifndef _KALCOMM_ATOMIC_H
#define _KALCOMM_ATOMIC_H
#include <kaleid/common/stdlib.h>
#ifndef _KALCOMM_COMMON_H
# error "don't include kaleid/common/types.h without kaleid/common/common.h"
#endif
//
// Set "bytes"-many bytes starting from ptr to val
//
void *memset(void *ptr, int val, size_t bytes)
{
uchar uval = val & 0xFF;
uchar *uptr = (uchar *)ptr;
while (bytes--) *uptr++ = uval;
return ptr;
}
// atomic_t defined in common/types.h
//
// Set "bytes"-many bytes starting from ptr to 0
//
void *memzero(void *ptr, size_t bytes)
{
uchar *uptr = (uchar *)ptr;
while (bytes--) *uptr++ = 0;
return ptr;
}
#ifdef _KALEID_KERNEL
// only available in the kernel
#define DosDisableInterrupts() asm volatile ("cli")
#define DosEnableInterrupts() asm volatile ("sti")
#define DosHaltCPU() asm volatile ("hlt")
#endif
#endif

View File

@ -7,7 +7,7 @@
// Desc: sprintf()-related functions //
//----------------------------------------------------------------------------//
#include <kaleid/common/string.h>
#include <kaleid/common/stdlib.h>
//
// Format str according to fmt using ellipsed arguments

View File

@ -7,9 +7,7 @@
// Desc: String-related functions //
//----------------------------------------------------------------------------//
#include <kaleid/common/string.h>
// TODO multibyte, assembly
#include <kaleid/common/stdlib.h>
//
// Returns str's length

View File

@ -1,28 +0,0 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
// Authors: spectral` //
// NeoX //
// //
// Desc: mem*() functions //
//----------------------------------------------------------------------------//
#ifndef _KALCOMM_MEMORY_H
#define _KALCOMM_MEMORY_H
#ifndef _KALCOMM_COMMON_H
# include <kaleid/common/common.h>
#endif
#ifndef _OSK_SOURCE
# define memcpy _osk_memcpy
# define memset _osk_memset
# define memcmp _osk_memcmp
# define memzero _osk_memzero
#endif
void *memset(void *, int, size_t);
void *memzero(void *, size_t);
#endif

View File

@ -1,41 +0,0 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
// Authors: spectral` //
// NeoX //
// //
// Desc: Values for status_t //
//----------------------------------------------------------------------------//
#ifndef _KALCOMM_STATUS_H
#define _KALCOMM_STATUS_H
#ifndef _KALCOMM_COMMON_H
# error "don't include kaleid/common/types.h without kaleid/common/common.h"
#endif
#ifndef _OSK_SOURCE
# define describe_status _osk_describe_status
#endif
// see in common/lib/status.c for status messages
const char *describe_status(status_t);
#define STATUS_FAILED(x) ((x) < 0))
#define STATUS_SUCCESS(x) (!STATUS_FAILED(x))
#define SUCCESS (0) // everything went fine
#define FAILED (-1)
#define ERROR FAILED // something went wrong, can't be more precise
#define NOT_PERMITTED (-2)
#define ACCESS_DENIED (-3)
#define BAD_ARGUMENT (-4) // invalid arguments, can't be more precise
#define BAD_ARG_RANGE (-5) // arguments out of range
#define BAD_ARG_NULL (-6) // unexpected NULL argument
#define TRY_AGAIN (-7) // EAGAIN
#endif

View File

@ -0,0 +1,75 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
// Authors: spectral` //
// NeoX //
// //
// Desc: Kaleid string library //
//----------------------------------------------------------------------------//
#ifndef _KALCOMM_STRING_H
#define _KALCOMM_STRING_H
#ifndef _KALCOMM_COMMON_H
# include <kaleid/common/common.h>
#endif
//------------------------------------------//
// Memory management utilitaries //
//------------------------------------------//
#ifndef _OSK_SOURCE
# define memcpy _osk_memcpy
# define memset _osk_memset
# define memcmp _osk_memcmp
# define memzero _osk_memzero
#endif
void *memset(void *, int, size_t);
void *memzero(void *, size_t);
//------------------------------------------//
// String manipulation utilitaries //
//------------------------------------------//
#ifndef _OSK_SOURCE
# define strlen _osk_strlen
# define strcpy _osk_strcpy
# define strncpy _osk_strncpy
# define strrev _osk_strrev
# define reverse _osk_reverse
# define sprintf _osk_sprintf
# define snprintf _osk_snprintf
# define vsprintf _osk_vsprintf
# define vsnprintf _osk_vsnprintf
#endif
size_t strlen(const char *);
char *strcpy(char *, const char *);
char *strncpy(char *, const char *, size_t);
char *strrev(char *dest, const char *src);
char *reverse(char *);
int sprintf(char *, const char *, ...);
int snprintf(char *, size_t, const char *, ...);
int vsprintf(char *, const char *, va_list);
int vsnprintf(char *, size_t, const char *, va_list);
//------------------------------------------//
// Type conversion utilities //
//------------------------------------------//
#ifndef _OSK_SOURCE
# define itoa _osk_itoa
# define atoi _osk_atoi
#endif
char *itoa(int, char *, int);
//------------------------------------------//
// End of kaleid/common/stdlib.h //
//------------------------------------------//
#endif

View File

@ -1,49 +0,0 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
// Authors: spectral` //
// NeoX //
// //
// Desc: Kaleid string library //
//----------------------------------------------------------------------------//
#ifndef _KALCOMM_STRING_H
#define _KALCOMM_STRING_H
#ifndef _KALCOMM_COMMON_H
# include <kaleid/common/common.h>
#endif
#ifndef _KALCOMM_CONVERT_H
# include <kaleid/common/convert.h>
#endif
#ifndef _OSK_SOURCE
# define strlen _osk_strlen
# define strcpy _osk_strcpy
# define strncpy _osk_strncpy
# define strrev _osk_strrev
# define reverse _osk_reverse
# define sprintf _osk_sprintf
# define snprintf _osk_snprintf
# define vsprintf _osk_vsprintf
# define vsnprintf _osk_vsnprintf
#endif
size_t strlen(const char *);
char *strcpy(char *, const char *);
char *strncpy(char *, const char *, size_t);
char *strrev(char *dest, const char *src);
char *reverse(char *);
int sprintf(char *, const char *, ...);
int snprintf(char *, size_t, const char *, ...);
int vsprintf(char *, const char *, va_list);
int vsnprintf(char *, size_t, const char *, va_list);
#endif

View File

@ -1,79 +0,0 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
// Authors: spectral` //
// NeoX //
// //
// Desc: mem*() functions //
//----------------------------------------------------------------------------//
// XXX to be improved before being brought back
// to be tested with more alignment sizes
#include <kaleid/common/memory.h>
// to be moved
#define QWORD_SIZE 8
#define QWORD_ALIGN 8
//
// Set "qwords"-many aligned qwords starting from ptr to val
//
static inline void *memsetq(void *ptr, ullong uval, size_t qwords)
{
size_t n;
ullong *uptr = (ullong *)ptr;
// aligned memory write
for (n = 0; n < qwords; n++) {
*(uptr + n) = uval;
}
return ptr;
}
//
// Set "bytes"-many bytes starting from ptr to val
//
void *memset(void *ptr, int val, size_t bytes)
{
uchar *uptr = (uchar *)ptr;
const size_t qwords = bytes/QWORD_SIZE;
// get rid of everything after the first byte
val = val & 0xFF;
// deal with bytes before start of the first aligned qword
while (((ullong)uptr % QWORD_ALIGN) > 0 && bytes--) {
*uptr++ = (uchar)val;
}
// move qword by qword
if (qwords) {
const ullong uval = ((ullong)val << 56) | ((ullong)val << 48)
| ((ullong)val << 40) | ((ullong)val << 32)
| ((ullong)val << 24) | ((ullong)val << 16)
| ((ullong)val << 8) | ((ullong)val);
memsetq(uptr, uval, qwords);
uptr += qwords * QWORD_SIZE;
bytes %= QWORD_SIZE;
}
// deal with what's left
while (bytes--) {
*uptr++ = (uchar)val;
}
return ptr;
}
//
// Set "bytes"-many bytes starting from ptr to 0
//
void *memzero(void *ptr, size_t bytes)
{
return memset(ptr, 0, bytes);
}

View File

@ -1,44 +0,0 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
// Authors: spectral` //
// NeoX //
// //
// Desc: Essential types for Kaleid //
//----------------------------------------------------------------------------//
#ifndef _KALCOMM_TYPES_H
#define _KALCOMM_TYPES_H
#ifndef _KALCOMM_COMMON_H
# error "don't include kaleid/common/types.h without kaleid/common/common.h"
#endif
typedef unsigned char uchar;
typedef unsigned short ushort;
typedef unsigned int uint;
typedef unsigned long ulong;
typedef long long llong;
typedef unsigned long long ullong;
typedef long double ldouble;
typedef short port_t;
typedef short status_t;
#ifndef KEEP_KALCOMM_TYPES_MINIMAL
typedef _Bool bool;
typedef uint wchar_t;
typedef ullong size_t;
typedef llong ssize_t;
typedef size_t off_t;
typedef int atomic_t;
typedef ulong pid_t;
typedef void *va_list;
#endif
// XXX limits
#endif

View File

@ -26,11 +26,12 @@ This folder also has the following subfolders:
I/O folder. (XXX)
- ps/
This folder will contain Kaleid's process manager and scheduler, as well as the
implementation of the related syscalls and functions.
This folder will contain Kaleid's process manager and scheduler, as well
as the implementation of the related syscalls and functions.
- ex/
This folder contains the exec()-related functions and syscalls, as well
as one subfolder per executable format supported by Kaleid (e.g. ELF executable)
as one subfolder per executable format supported by Kaleid
(e.g. ELF executable)

View File

@ -8,6 +8,7 @@
//----------------------------------------------------------------------------//
#include <kaleid/kernel/init.h>
#include <kaleid/kernel/ke/state.h>
#include <kaleid/kernel/ke/panic.h>
#include <kaleid/kernel/io/terminal.h>

View File

@ -10,7 +10,9 @@
#ifndef _KALKERN_INIT_H
#define _KALKERN_INIT_H
#ifndef _KALCOMM_COMMON_H
#include <kaleid/common/common.h>
#endif
// kernel entry point
void DosStartKern(void);

View File

@ -14,7 +14,7 @@
// VGA-related macros
//
#define ComputeColorCode(fg, bg) ((fg) | (bg) << 4)
#define ComputeEntryOffset(kt, x, y) ((y) * kt->kt_width + (x))
#define ComputeOffset(kt, x, y) ((y) * kt->kt_width + (x))
#define ComputeEntry(ch, cl) (((ushort)(ch)) | (ushort)(cl) << 8)
//
@ -46,7 +46,7 @@ terminal_t *stddbg;
//
void DosInitTerms(void)
{
DosAssert(!stdout && _vga_term.kt_init != INITOK && "DosInitTerms() called twice");
DosAssert(!stdout && _vga_term.kt_init != INITOK);
_vga_term.kt_init = INITOK;
stddbg = &_vga_term;
@ -57,7 +57,7 @@ void DosInitTerms(void)
}
//
// Fills terminal with spaces
// Fill terminal with spaces
//
status_t DosClearTerm(terminal_t *kt)
{
@ -92,7 +92,7 @@ status_t DosChTermColor(terminal_t *kt, uchar color)
}
//
// Writes a single character on the terminal
// Write a single character on the terminal
//
status_t DosPutOnTerm(terminal_t *kt, char ch)
{
@ -135,7 +135,7 @@ status_t DosPrintOnTerm(terminal_t *kt, const char *str)
//----------------------------------------------------------//
//
// Fills terminal with spaces
// Fill terminal with spaces (UNLOCKED version)
// XXX would '\0' work too?
//
void DosClearTerm_Unlocked(terminal_t *kt)
@ -154,7 +154,7 @@ void DosClearTerm_Unlocked(terminal_t *kt)
}
//
// Writes a single character on the terminal (UNLOCKED version)
// Write a single character on the terminal (UNLOCKED version)
//
void DosPutOnTerm_Unlocked(terminal_t *kt, char ch)
{
@ -180,10 +180,9 @@ void DosPutOnTerm_Unlocked(terminal_t *kt, char ch)
}
}
}
// XXX check whether we were given a writable character
else {
const size_t offset = ComputeEntryOffset(kt, kt->kt_curr_x, kt->kt_curr_y);
const size_t offset = ComputeOffset(kt, kt->kt_curr_x, kt->kt_curr_y);
kt->kt_buffer[offset] = ComputeEntry(ch, kt->kt_color);
}
@ -208,5 +207,3 @@ void DosPrintOnTerm_Unlocked(terminal_t *kt, const char *str)
}
}

View File

@ -39,6 +39,9 @@ typedef struct {
// current "standard" terminal
extern terminal_t *stdout;
// current debugging terminal
extern terminal_t *stddbg;
void DosInitTerms(void);
status_t DosClearTerm(terminal_t *);
status_t DosPutOnTerm(terminal_t *, char);
@ -48,12 +51,11 @@ status_t DosChTermColor(terminal_t *, uchar);
#ifdef _UNLOCKED_IO
void DosClearTerm_Unlocked(terminal_t *);
void DosPutOnTerm_Unlocked(terminal_t *, char);
void DosPrintOnTerm_Unlocked(terminal_t *kt, const char *str);
void DosPrintOnTerm_Unlocked(terminal_t *, const char *);
#define DosChTermColor_Unlocked(kt, col) ((kt)->kt_color = col)
#endif
#ifndef _NO_DEBUG
extern terminal_t *stddbg;
# define DebugLog(...) DosPutOnTerm(stddbg, __VA_ARGS__)
#else
# define DebugLog(...)

View File

@ -17,7 +17,9 @@
enum lock_type {
//
// Mutex-type lock
// WARNING: DosLock() panics when used on a mutex while not running a process
//
// WARNING
// DosLock() panics when used on a mutex while not running a process
//
KLOCK_MUTEX,
@ -57,7 +59,7 @@ typedef struct {
//
// Does nothing
//
#define DosDestroyLock(lk)
#define DosDestroyLock(lk) ((lk)->lk_init = FALSE)
//
// Aquires the lock
@ -82,7 +84,7 @@ typedef struct {
DosDisableInterrupts(); \
DosAssert((lk)->lk_init == INITOK); \
if ((lk)->lk_lock++) \
DosPanic("DosReleased on an unlocked object"); \
DosPanic("DosReleaseLock on an unlocked object"); \
DosEnableInterrupts(); \
} while (FALSE);

View File

@ -21,7 +21,10 @@ const char *__panicmsg = NULL;
//
// Failed assert() handler
//
noreturn void ___assert_handler(const char *msg, const char *file, int line, const char *func)
noreturn void ___assert_handler(const char *msg,
const char *file,
int line,
const char *func)
{
// not getting out of here
DosDisableInterrupts();

View File

@ -10,9 +10,12 @@
#ifndef _KALKERN_KE_PANIC_H
#define _KALKERN_KE_PANIC_H
#include <kaleid/kernel/ke/state.h>
#ifndef _KALCOMM_COMMON_H
#include <kaleid/common/common.h>
#endif
noreturn void DosPanic(const char *);
noreturn void DosCrashSystem(void);
extern const char *__panicmsg;
#define DosGetPanicStr() (__panicmsg)

View File

@ -30,7 +30,6 @@ enum kernel_states {
};
extern uchar __kstate;
#define DosGetKernState() (__kstate)
#define DosSetKernState(x) (__kstate = (x))