mirror of
https://gitlab.os-k.eu/os-k-team/os-k.git
synced 2023-08-25 14:03:10 +02:00
Common stuff
This commit is contained in:
parent
680ca2a52c
commit
15a7ad873f
24
src/Makefile
24
src/Makefile
@ -12,10 +12,13 @@ CC2NAME=gcc
|
|||||||
COPTIM=-O2
|
COPTIM=-O2
|
||||||
CLDSCR=-T kernel.ld
|
CLDSCR=-T kernel.ld
|
||||||
CWARNS=-pedantic -Wall -Wextra -Werror
|
CWARNS=-pedantic -Wall -Wextra -Werror
|
||||||
CFLAGS=-nostdlib -ffreestanding -mcmodel=large -mno-red-zone -mno-mmx -mno-sse -mno-sse2
|
|
||||||
CINCLUDES=-isystem.
|
CINCLUDES=-isystem.
|
||||||
CDEFINES=
|
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)
|
CC=$(CCNAME) $(COPTIM) $(CWARNS) $(CFLAGS) $(CDEFINES) $(CINCLUDES)
|
||||||
KCC=$(CC) -D_KALEID_KERNEL
|
KCC=$(CC) -D_KALEID_KERNEL
|
||||||
|
|
||||||
@ -32,7 +35,7 @@ KERNDIR=kaleid/kernel
|
|||||||
SYSTDIR=kaleid/system
|
SYSTDIR=kaleid/system
|
||||||
LINXDIR=kaleid/linux
|
LINXDIR=kaleid/linux
|
||||||
|
|
||||||
all: bootloader
|
all: bootloader kernel
|
||||||
|
|
||||||
boot.mbr.s: $(BOOTDIR)/mbr.s $(BOOTDIR)/mbr.inc
|
boot.mbr.s: $(BOOTDIR)/mbr.s $(BOOTDIR)/mbr.inc
|
||||||
$(ASM) $(BOOTFLAGS) $(BOOTDIR)/mbr.s -o $(OBJDIR)/boot/mbr.bin
|
$(ASM) $(BOOTFLAGS) $(BOOTDIR)/mbr.s -o $(OBJDIR)/boot/mbr.bin
|
||||||
@ -59,10 +62,10 @@ testing: bootloader pseudo_kern
|
|||||||
COBJDIR=$(OBJDIR)/$(COMMDIR)
|
COBJDIR=$(OBJDIR)/$(COMMDIR)
|
||||||
LOBJDIR=$(OBJDIR)/$(LINXDIR)
|
LOBJDIR=$(OBJDIR)/$(LINXDIR)
|
||||||
|
|
||||||
COMMDEPS=$(COMMDIR)/common.h $(COMMDIR)/assert.h $(COMMDIR)/atomic.h $(KERNDIR)/config.h \
|
COMMDEPS=$(COMMDIR)/common.h $(COMMDIR)/stdlib.h $(KERNDIR)/config.h
|
||||||
$(COMMDIR)/status.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
|
common: $(COMMDEPS) $(COMMDIR)/lib/string.c $(COMMDIR)/lib/status.c
|
||||||
$(KCC) -c $(COMMDIR)/lib/string.c -o $(COBJDIR)/lib/string.o
|
$(KCC) -c $(COMMDIR)/lib/string.c -o $(COBJDIR)/lib/string.o
|
||||||
@ -85,9 +88,14 @@ test-common:
|
|||||||
|
|
||||||
KOBJDIR=$(OBJDIR)/$(KERNDIR)
|
KOBJDIR=$(OBJDIR)/$(KERNDIR)
|
||||||
|
|
||||||
KERNDEPS=common $(KERNDIR)/init.h $(KERNDIR)/io/terminal.h $(KERNDIR)/io/ports.h $(KERNDIR)/ke/panic.h
|
KERNDEPS=common $(KERNDIR)/init.h $(KERNDIR)/io/terminal.h \
|
||||||
KERNSRCS=$(KERNDIR)/init.c $(KERNDIR)/ke/state.c $(KERNDIR)/ke/panic.c $(KERNDIR)/io/ports.c $(KERNDIR)/io/terminal.c
|
$(KERNDIR)/io/ports.h $(KERNDIR)/ke/panic.h
|
||||||
KERNOBJS=$(KOBJDIR)/init.o $(KOBJDIR)/ke/state.o $(KOBJDIR)/ke/panic.o $(KOBJDIR)/io/ports.o $(KOBJDIR)/io/terminal.o
|
|
||||||
|
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)
|
kernel: common $(KERNSRCS)
|
||||||
$(KCC) -c $(KERNDIR)/init.c -o $(KOBJDIR)/init.o
|
$(KCC) -c $(KERNDIR)/init.c -o $(KOBJDIR)/init.o
|
||||||
|
@ -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
|
|
||||||
|
|
@ -10,8 +10,14 @@
|
|||||||
#ifndef _KALCOMM_COMMON_H
|
#ifndef _KALCOMM_COMMON_H
|
||||||
#define _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
|
#endif
|
||||||
|
|
||||||
#if !defined(TRUE) && !defined(FALSE)
|
#if !defined(TRUE) && !defined(FALSE)
|
||||||
@ -37,8 +43,8 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(likely) && !defined(unlikely)
|
#if !defined(likely) && !defined(unlikely)
|
||||||
# define likely(x) __builtin_expect((x), 1)
|
# define likely(x) (__builtin_expect((x), 1))
|
||||||
# define unlikely(x) __builtin_expect((x), 0)
|
# define unlikely(x) (__builtin_expect((x), 0))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef INITOK
|
#ifndef INITOK
|
||||||
@ -49,10 +55,116 @@
|
|||||||
# include <kaleid/kernel/config.h>
|
# include <kaleid/kernel/config.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <kaleid/common/types.h>
|
//------------------------------------------//
|
||||||
#include <kaleid/common/atomic.h>
|
// COMMON TYPES //
|
||||||
#include <kaleid/common/status.h>
|
//------------------------------------------//
|
||||||
#include <kaleid/common/assert.h>
|
|
||||||
|
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
|
#endif
|
||||||
|
|
||||||
|
@ -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
|
|
@ -7,35 +7,31 @@
|
|||||||
Desc: Folder description - "kaleid/common"
|
Desc: Folder description - "kaleid/common"
|
||||||
---------------------------------------------------------------------
|
---------------------------------------------------------------------
|
||||||
|
|
||||||
This is the folder containing the sources for Kaleid's C runtime library, linked both to the kernel
|
This is the folder containing the sources for Kaleid's C runtime library, linked
|
||||||
and to the system processes that run outiside the kernel. It can also be compiled for Linux as
|
both to the kernel and to the system processes that run outiside the kernel.
|
||||||
(very basic) C library, for test purposes.
|
It can also be compiled for Linux as a very basic C library, for test purposes.
|
||||||
|
|
||||||
This folder contains the following files:
|
This folder contains the following files:
|
||||||
- common.h
|
- common.h
|
||||||
This file is to be included by every source file using the library, and it includes in turn
|
This file is to be included by every source file using the library.
|
||||||
the following files:
|
It:
|
||||||
- assert.h
|
- Provides the elementary types (e.g. size_t) used through Kaleid.
|
||||||
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)"
|
- Defines the different values of the "status_t" type used
|
||||||
but an (overridable) default handler will be furnished in the future.
|
throughout Kaleid and related utilitary functions.
|
||||||
- atomic.h
|
|
||||||
Support for atomic operations. When compiled by the kernel, also furnishes macros for
|
- Defines the macro "assert()". Currently any program wanting to
|
||||||
enabling/disabling interrupts. This will change in the future.
|
use this macro has to implement its own handler:
|
||||||
- status.h
|
noreturn void ___assert_handler(const char *cond,
|
||||||
Defines the different values of the "status_t" type used throughout Kaleid and related
|
const char *file,
|
||||||
utilitary functions.
|
int line,
|
||||||
- types.h
|
const char *func)
|
||||||
Provides the elementary types (size_t, etc) used throught Kaleid.
|
but an overridable default handler will be furnished later.
|
||||||
|
|
||||||
- convert.h
|
- stlib.h
|
||||||
Contains the declaration of conversion utilities (e.g. itoa())
|
The include file for most of functions of the common library, notably
|
||||||
It is included by string.h
|
- Memory management utilities (e.g. memset())
|
||||||
|
- String manipulation utilities (e.g. strcpy())
|
||||||
- memory.h
|
- Type conversion utilities (e.g. itoa())
|
||||||
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
|
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
// Desc: Conversion utilities //
|
// Desc: Conversion utilities //
|
||||||
//----------------------------------------------------------------------------//
|
//----------------------------------------------------------------------------//
|
||||||
|
|
||||||
#include <kaleid/common/string.h>
|
#include <kaleid/common/stdlib.h>
|
||||||
|
|
||||||
//
|
//
|
||||||
// Digits table for bases <=36
|
// Digits table for bases <=36
|
||||||
|
@ -7,17 +7,64 @@
|
|||||||
// Desc: mem*() functions //
|
// 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
|
// Set "bytes"-many bytes starting from ptr to val
|
||||||
//
|
//
|
||||||
void *memset(void *ptr, int val, size_t bytes)
|
void *memset(void *ptr, int val, size_t bytes)
|
||||||
{
|
{
|
||||||
uchar uval = val & 0xFF;
|
|
||||||
uchar *uptr = (uchar *)ptr;
|
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;
|
return ptr;
|
||||||
}
|
}
|
||||||
@ -27,11 +74,6 @@ void *memset(void *ptr, int val, size_t bytes)
|
|||||||
//
|
//
|
||||||
void *memzero(void *ptr, size_t bytes)
|
void *memzero(void *ptr, size_t bytes)
|
||||||
{
|
{
|
||||||
uchar *uptr = (uchar *)ptr;
|
return memset(ptr, 0, bytes);
|
||||||
|
|
||||||
while (bytes--) *uptr++ = 0;
|
|
||||||
|
|
||||||
return ptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,26 +4,34 @@
|
|||||||
// Authors: spectral` //
|
// Authors: spectral` //
|
||||||
// NeoX //
|
// NeoX //
|
||||||
// //
|
// //
|
||||||
// Desc: Atomic stuff //
|
// Desc: mem*() functions, suboptimal edition //
|
||||||
//----------------------------------------------------------------------------//
|
//----------------------------------------------------------------------------//
|
||||||
|
|
||||||
#ifndef _KALCOMM_ATOMIC_H
|
#include <kaleid/common/stdlib.h>
|
||||||
#define _KALCOMM_ATOMIC_H
|
|
||||||
|
|
||||||
#ifndef _KALCOMM_COMMON_H
|
//
|
||||||
# error "don't include kaleid/common/types.h without kaleid/common/common.h"
|
// Set "bytes"-many bytes starting from ptr to val
|
||||||
#endif
|
//
|
||||||
|
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
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
|||||||
// Desc: sprintf()-related functions //
|
// Desc: sprintf()-related functions //
|
||||||
//----------------------------------------------------------------------------//
|
//----------------------------------------------------------------------------//
|
||||||
|
|
||||||
#include <kaleid/common/string.h>
|
#include <kaleid/common/stdlib.h>
|
||||||
|
|
||||||
//
|
//
|
||||||
// Format str according to fmt using ellipsed arguments
|
// Format str according to fmt using ellipsed arguments
|
||||||
|
@ -7,9 +7,7 @@
|
|||||||
// Desc: String-related functions //
|
// Desc: String-related functions //
|
||||||
//----------------------------------------------------------------------------//
|
//----------------------------------------------------------------------------//
|
||||||
|
|
||||||
#include <kaleid/common/string.h>
|
#include <kaleid/common/stdlib.h>
|
||||||
|
|
||||||
// TODO multibyte, assembly
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Returns str's length
|
// Returns str's length
|
||||||
|
@ -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
|
|
||||||
|
|
@ -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
|
|
||||||
|
|
75
src/kaleid/common/stdlib.h
Normal file
75
src/kaleid/common/stdlib.h
Normal 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
|
||||||
|
|
@ -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
|
|
||||||
|
|
@ -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);
|
|
||||||
}
|
|
||||||
|
|
@ -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
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -26,11 +26,12 @@ This folder also has the following subfolders:
|
|||||||
I/O folder. (XXX)
|
I/O folder. (XXX)
|
||||||
|
|
||||||
- ps/
|
- ps/
|
||||||
This folder will contain Kaleid's process manager and scheduler, as well as the
|
This folder will contain Kaleid's process manager and scheduler, as well
|
||||||
implementation of the related syscalls and functions.
|
as the implementation of the related syscalls and functions.
|
||||||
|
|
||||||
- ex/
|
- ex/
|
||||||
This folder contains the exec()-related functions and syscalls, as well
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
//----------------------------------------------------------------------------//
|
//----------------------------------------------------------------------------//
|
||||||
|
|
||||||
#include <kaleid/kernel/init.h>
|
#include <kaleid/kernel/init.h>
|
||||||
|
#include <kaleid/kernel/ke/state.h>
|
||||||
#include <kaleid/kernel/ke/panic.h>
|
#include <kaleid/kernel/ke/panic.h>
|
||||||
#include <kaleid/kernel/io/terminal.h>
|
#include <kaleid/kernel/io/terminal.h>
|
||||||
|
|
||||||
|
@ -10,7 +10,9 @@
|
|||||||
#ifndef _KALKERN_INIT_H
|
#ifndef _KALKERN_INIT_H
|
||||||
#define _KALKERN_INIT_H
|
#define _KALKERN_INIT_H
|
||||||
|
|
||||||
|
#ifndef _KALCOMM_COMMON_H
|
||||||
#include <kaleid/common/common.h>
|
#include <kaleid/common/common.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
// kernel entry point
|
// kernel entry point
|
||||||
void DosStartKern(void);
|
void DosStartKern(void);
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
// VGA-related macros
|
// VGA-related macros
|
||||||
//
|
//
|
||||||
#define ComputeColorCode(fg, bg) ((fg) | (bg) << 4)
|
#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)
|
#define ComputeEntry(ch, cl) (((ushort)(ch)) | (ushort)(cl) << 8)
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -46,7 +46,7 @@ terminal_t *stddbg;
|
|||||||
//
|
//
|
||||||
void DosInitTerms(void)
|
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;
|
_vga_term.kt_init = INITOK;
|
||||||
stddbg = &_vga_term;
|
stddbg = &_vga_term;
|
||||||
@ -57,7 +57,7 @@ void DosInitTerms(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Fills terminal with spaces
|
// Fill terminal with spaces
|
||||||
//
|
//
|
||||||
status_t DosClearTerm(terminal_t *kt)
|
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)
|
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?
|
// XXX would '\0' work too?
|
||||||
//
|
//
|
||||||
void DosClearTerm_Unlocked(terminal_t *kt)
|
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)
|
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 {
|
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);
|
kt->kt_buffer[offset] = ComputeEntry(ch, kt->kt_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,5 +207,3 @@ void DosPrintOnTerm_Unlocked(terminal_t *kt, const char *str)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,6 +39,9 @@ typedef struct {
|
|||||||
// current "standard" terminal
|
// current "standard" terminal
|
||||||
extern terminal_t *stdout;
|
extern terminal_t *stdout;
|
||||||
|
|
||||||
|
// current debugging terminal
|
||||||
|
extern terminal_t *stddbg;
|
||||||
|
|
||||||
void DosInitTerms(void);
|
void DosInitTerms(void);
|
||||||
status_t DosClearTerm(terminal_t *);
|
status_t DosClearTerm(terminal_t *);
|
||||||
status_t DosPutOnTerm(terminal_t *, char);
|
status_t DosPutOnTerm(terminal_t *, char);
|
||||||
@ -48,12 +51,11 @@ status_t DosChTermColor(terminal_t *, uchar);
|
|||||||
#ifdef _UNLOCKED_IO
|
#ifdef _UNLOCKED_IO
|
||||||
void DosClearTerm_Unlocked(terminal_t *);
|
void DosClearTerm_Unlocked(terminal_t *);
|
||||||
void DosPutOnTerm_Unlocked(terminal_t *, char);
|
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)
|
#define DosChTermColor_Unlocked(kt, col) ((kt)->kt_color = col)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef _NO_DEBUG
|
#ifndef _NO_DEBUG
|
||||||
extern terminal_t *stddbg;
|
|
||||||
# define DebugLog(...) DosPutOnTerm(stddbg, __VA_ARGS__)
|
# define DebugLog(...) DosPutOnTerm(stddbg, __VA_ARGS__)
|
||||||
#else
|
#else
|
||||||
# define DebugLog(...)
|
# define DebugLog(...)
|
||||||
|
@ -17,7 +17,9 @@
|
|||||||
enum lock_type {
|
enum lock_type {
|
||||||
//
|
//
|
||||||
// Mutex-type lock
|
// 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,
|
KLOCK_MUTEX,
|
||||||
|
|
||||||
@ -57,7 +59,7 @@ typedef struct {
|
|||||||
//
|
//
|
||||||
// Does nothing
|
// Does nothing
|
||||||
//
|
//
|
||||||
#define DosDestroyLock(lk)
|
#define DosDestroyLock(lk) ((lk)->lk_init = FALSE)
|
||||||
|
|
||||||
//
|
//
|
||||||
// Aquires the lock
|
// Aquires the lock
|
||||||
@ -82,7 +84,7 @@ typedef struct {
|
|||||||
DosDisableInterrupts(); \
|
DosDisableInterrupts(); \
|
||||||
DosAssert((lk)->lk_init == INITOK); \
|
DosAssert((lk)->lk_init == INITOK); \
|
||||||
if ((lk)->lk_lock++) \
|
if ((lk)->lk_lock++) \
|
||||||
DosPanic("DosReleased on an unlocked object"); \
|
DosPanic("DosReleaseLock on an unlocked object"); \
|
||||||
DosEnableInterrupts(); \
|
DosEnableInterrupts(); \
|
||||||
} while (FALSE);
|
} while (FALSE);
|
||||||
|
|
||||||
|
@ -21,7 +21,10 @@ const char *__panicmsg = NULL;
|
|||||||
//
|
//
|
||||||
// Failed assert() handler
|
// 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
|
// not getting out of here
|
||||||
DosDisableInterrupts();
|
DosDisableInterrupts();
|
||||||
|
@ -10,9 +10,12 @@
|
|||||||
#ifndef _KALKERN_KE_PANIC_H
|
#ifndef _KALKERN_KE_PANIC_H
|
||||||
#define _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 DosPanic(const char *);
|
||||||
|
noreturn void DosCrashSystem(void);
|
||||||
|
|
||||||
extern const char *__panicmsg;
|
extern const char *__panicmsg;
|
||||||
#define DosGetPanicStr() (__panicmsg)
|
#define DosGetPanicStr() (__panicmsg)
|
||||||
|
@ -30,7 +30,6 @@ enum kernel_states {
|
|||||||
};
|
};
|
||||||
|
|
||||||
extern uchar __kstate;
|
extern uchar __kstate;
|
||||||
|
|
||||||
#define DosGetKernState() (__kstate)
|
#define DosGetKernState() (__kstate)
|
||||||
#define DosSetKernState(x) (__kstate = (x))
|
#define DosSetKernState(x) (__kstate = (x))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user