diff --git a/Makefile b/Makefile
index d5b7de2..627c730 100644
--- a/Makefile
+++ b/Makefile
@@ -78,13 +78,12 @@ NC='\033[1;37m'
# Lib C sources + libbuf source
LibCSources = libc/mem.c libc/ctype.c \
libc/rand.c libc/sprintf.c \
- libc/status.c libc/string.c \
+ libc/errno.c libc/string.c \
libc/strtol.c extras/argv.c \
libbuf/bopen.c libbuf/bputc.c libbuf/bscroll.c \
libbuf/bprint.c libbuf/bgetc.c libbuf/bscan.c \
libbuf/bflush.c libbuf/bwrite.c libbuf/bread.c \
libbuf/bmisc.c libbuf/bclose.c \
- extras/prog.c \
LibCObj=$(patsubst %.c,$(KOBJDIR)/%.o,$(LibCSources))
LibCDep=$(patsubst %.c,$(KOBJDIR)/%.d,$(LibCSources))
@@ -125,7 +124,7 @@ $(KOBJDIR):
## LIB C MAKEFILE ------------------------------------------------------------ #
-include $(LibCDep)
-$(KOBJDIR)/libc/atoi.o: $(KALEIDDIR)/libc/atoi.c $(INCLUDEDIR)/kalbase.h | $(KOBJDIR)
+$(KOBJDIR)/libc/atoi.o: $(KALEIDDIR)/libc/atoi.c | $(KOBJDIR)
@mkdir -p $(shell dirname $@)
@$(KCC) -D_NEED_ATOI $< -o $@.1
@$(KCC) -D_NEED_ATOL $< -o $@.2
@@ -135,7 +134,7 @@ $(KOBJDIR)/libc/atoi.o: $(KALEIDDIR)/libc/atoi.c $(INCLUDEDIR)/kalbase.h | $(KOB
@rm -f $@.1 $@.2 $@.3 $@.4
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
-$(KOBJDIR)/libc/itoa.o: $(KALEIDDIR)/libc/itoa.c $(INCLUDEDIR)/kalbase.h | $(KOBJDIR)
+$(KOBJDIR)/libc/itoa.o: $(KALEIDDIR)/libc/itoa.c | $(KOBJDIR)
@mkdir -p $(shell dirname $@)
@$(KCC) -D_NEED_ITOA $< -o $@.1
@$(KCC) -D_NEED_LTOA $< -o $@.2
diff --git a/ProjectTree b/ProjectTree
index 331ca77..371195c 100644
--- a/ProjectTree
+++ b/ProjectTree
@@ -58,8 +58,7 @@
│ │ ├── extras
│ │ │ ├── argv.d
│ │ │ ├── argv.o
-│ │ │ ├── prog.d
-│ │ │ └── prog.o
+│ │ │ └── prog.d
│ │ ├── kernel
│ │ │ ├── cpu
│ │ │ │ ├── cpuid.d
@@ -138,6 +137,8 @@
│ │ ├── atoi.o
│ │ ├── ctype.d
│ │ ├── ctype.o
+│ │ ├── errno.d
+│ │ ├── errno.o
│ │ ├── itoa.o
│ │ ├── mem.d
│ │ ├── mem.o
@@ -145,55 +146,48 @@
│ │ ├── rand.o
│ │ ├── sprintf.d
│ │ ├── sprintf.o
-│ │ ├── status.d
-│ │ ├── status.o
│ │ ├── string.d
│ │ ├── string.o
│ │ ├── strtol.d
│ │ └── strtol.o
│ ├── grub.log
-│ ├── kaleid32_disasm.asm
-│ ├── kaleid64_disasm.asm
│ └── kernel.ld
├── include
-│ ├── base
-│ │ ├── assert.h
-│ │ ├── bdefs.h
-│ │ ├── crtlib.h
-│ │ ├── errno.h
-│ │ ├── limits.h
-│ │ ├── masks.h
-│ │ └── types.h
-│ ├── extras
+│ ├── ex
│ │ ├── argv.h
-│ │ ├── buf.h
-│ │ ├── list.h
-│ │ ├── locks.h
-│ │ ├── malloc.h
-│ │ └── prog.h
-│ ├── kernel
-│ │ ├── base.h
+│ │ ├── lock.h
+│ │ └── malloc.h
+│ ├── init
│ │ ├── boot.h
-│ │ ├── cpuid.h
+│ │ └── mboot.h
+│ ├── io
│ │ ├── cursor.h
-│ │ ├── heap.h
+│ │ ├── keyb.h
+│ │ └── spkr.h
+│ ├── ke
+│ │ ├── cpuid.h
│ │ ├── idt.h
-│ │ ├── iomisc.h
-│ │ ├── keyboard.h
-│ │ ├── mboot.h
-│ │ ├── mm.h
│ │ ├── proc.h
-│ │ ├── pwmgnt.h
│ │ ├── sched.h
-│ │ ├── speaker.h
+│ │ ├── spinlock.h
│ │ └── time.h
-│ ├── kalbase.h
-│ ├── kaleid.h
-│ └── kalext.h
+│ ├── lib
+│ │ ├── buf.h
+│ │ └── list.h
+│ ├── mm
+│ │ ├── heap.h
+│ │ └── mm.h
+│ ├── po
+│ │ └── shtdwn.h
+│ ├── ps
+│ ├── rtl
+│ ├── asm.h
+│ ├── errno.h
+│ ├── kernel.h
+│ └── libc.h
├── kaleid
│ ├── extras
-│ │ ├── argv.c
-│ │ └── prog.c
+│ │ └── argv.c
│ ├── kernel
│ │ ├── cpu
│ │ │ ├── cpuf.asm
@@ -218,6 +212,7 @@
│ │ │ ├── log.c
│ │ │ └── panic.c
│ │ ├── mm
+│ │ │ ├── gdt.asm
│ │ │ ├── gdt.c
│ │ │ ├── heap.c
│ │ │ ├── malloc.c
@@ -245,20 +240,18 @@
│ └── libc
│ ├── atoi.c
│ ├── ctype.c
+│ ├── errno.c
│ ├── itoa.c
│ ├── mem.c
│ ├── rand.c
│ ├── sprintf.c
-│ ├── status.c
│ ├── string.c
│ └── strtol.c
├── AUTHORS
├── ChangeLog
├── COPYING
-├── kaleid32_disasm.asm
-├── kaleid64_disasm.asm
├── Makefile
├── ProjectTree
└── README.md
-41 directories, 195 files
+47 directories, 182 files
diff --git a/include/kernel/iomisc.h b/include/asm.h
similarity index 87%
rename from include/kernel/iomisc.h
rename to include/asm.h
index 28f639a..9e6c4d1 100644
--- a/include/kernel/iomisc.h
+++ b/include/asm.h
@@ -1,7 +1,7 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
-// Desc: Miscenalleous I/O functions and inlines //
+// Desc: Inline assembly functions //
// //
// //
// Copyright © 2018-2019 The OS/K Team //
@@ -22,12 +22,12 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#ifndef _KALKERN_BASE_H
-#include
+#ifndef _LIBC_H
+#include
#endif
-#ifndef _KALKERN_IOMISC_H
-#define _KALKERN_IOMISC_H
+#ifndef _ASM_H
+#define _ASM_H
//------------------------------------------//
// IRQ-related stuff //
@@ -64,7 +64,6 @@ static inline ulong KePauseIRQs(void) {
extern void IoSendEOItoPIC(uchar isr);
extern void IoEnableNMI(void);
extern void IoDisableNMI(void);
-error_t IdtRegisterIsr(void (*isr)(ISRFrame_t *regs), uchar isrNo);
//
// Restore IRQ flag to its state before KePauseIRQs
@@ -75,6 +74,11 @@ error_t IdtRegisterIsr(void (*isr)(ISRFrame_t *regs), uchar isrNo);
// 101 ways to hang the system //
//------------------------------------------//
+//
+// Just relaxes the CPU a few cycles
+//
+#define KeRelaxCPU() asm volatile("pause\n": : : "memory")
+
//
// Pauses CPU until next interuption
//
@@ -94,28 +98,28 @@ error_t IdtRegisterIsr(void (*isr)(ISRFrame_t *regs), uchar isrNo);
// Ports I/O //
//------------------------------------------//
-static inline void IoWriteByteOnPort(port_t port, uchar val)
+static inline void IoWriteByteOnPort(ushort port, uchar val)
{ asm volatile ("outb %1, %0" : : "dN" (port), "a" (val)); }
-static inline void IoWriteWordOnPort(port_t port, ushort val)
+static inline void IoWriteWordOnPort(ushort port, ushort val)
{ asm volatile ("outw %1, %0" : : "dN" (port), "a" (val)); }
-static inline void IoWriteDWordOnPort(port_t port, uint val)
+static inline void IoWriteDWordOnPort(ushort port, uint val)
{ asm volatile ("outl %1, %0" : : "dN" (port), "a" (val)); }
-static inline uchar IoReadByteFromPort(port_t port) {
+static inline uchar IoReadByteFromPort(ushort port) {
uchar ret;
asm volatile ("inb %1, %0" : "=a"(ret) : "Nd"(port));
return ret;
}
-static inline ushort IoReadWordFromPort(port_t port) {
+static inline ushort IoReadWordFromPort(ushort port) {
ushort ret;
asm volatile ("inw %1, %0" : "=a"(ret) : "Nd"(port));
return ret;
}
-static inline ushort IoReadDWordFromPort(port_t port) {
+static inline ushort IoReadDWordFromPort(ushort port) {
uint ret;
asm volatile ("inl %1, %0" : "=a"(ret) : "Nd"(port));
return ret;
diff --git a/include/base/assert.h b/include/base/assert.h
deleted file mode 100644
index 3f962bd..0000000
--- a/include/base/assert.h
+++ /dev/null
@@ -1,112 +0,0 @@
-//----------------------------------------------------------------------------//
-// GNU GPL OS/K //
-// //
-// Desc: assert() support //
-// //
-// //
-// 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 . //
-//----------------------------------------------------------------------------//
-
-#ifndef _KALBASE_ASSERT_H
-#define _KALBASE_ASSERT_H
-
-//------------------------------------------//
-
-#ifndef noreturn
-#define noreturn __attribute__((__noreturn__))
-#endif
-
-#ifndef unlikely
-#define unlikely(x) (__builtin_expect((x), 0))
-#endif
-
-#ifndef static_assert
-#define static_assert _Static_assert
-#endif
-
-//------------------------------------------//
-// API compatibility checks //
-//------------------------------------------//
-
-#define _SA_MSG "Incompatible type sizes"
-static_assert(sizeof(char) == 1, _SA_MSG);
-static_assert(sizeof(short) == 2, _SA_MSG);
-static_assert(sizeof(int) == 4, _SA_MSG);
-static_assert(sizeof(long) == 8, _SA_MSG);
-static_assert(sizeof(void *) == 8, _SA_MSG);
-#undef _SA_MSG
-
-//------------------------------------------//
-// Assert core //
-//------------------------------------------//
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-// Failed assert handler
-noreturn void __assert_handler(const char *, const char *, int, const char *);
-
-#ifdef __cplusplus
-}
-#endif
-
-// Unconditional assert
-#define KalAlwaysAssert(x) \
- do { \
- if unlikely (!(x)) \
- __assert_handler(#x, __FILE__, __LINE__, __func__); \
- } while (0)
-
-//------------------------------------------//
-// When debugging //
-//------------------------------------------//
-
-#if /*!defined(_NO_DEBUG) && !defined(NDEBUG) &&*/ !defined(KalAssert)
-
-//
-// Check whether (x) holds, if not call __assert_handler
-//
-#define KalAssert KalAlwaysAssert
-
-//------------------------------------------//
-// When not debugging //
-//------------------------------------------//
-
-#else
-
-#ifndef KalAssert
-#define KalAssert(x) ((void)0)
-#endif
-
-#endif
-
-//------------------------------------------//
-// Aliases and extensions //
-//------------------------------------------//
-
-#ifndef assert
-#define assert KalAssert
-#endif
-
-#define KalAssertEx(x,m) KalAssert(x && m)
-#define KalAlwaysAssertEx(x,m) KalAlwaysAssert(x && m)
-
-//------------------------------------------//
-
-#endif
diff --git a/include/base/bdefs.h b/include/base/bdefs.h
deleted file mode 100644
index a8f06f3..0000000
--- a/include/base/bdefs.h
+++ /dev/null
@@ -1,148 +0,0 @@
-//----------------------------------------------------------------------------//
-// GNU GPL OS/K //
-// //
-// Desc: Basic preprocessor definitions //
-// //
-// //
-// 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 . //
-//----------------------------------------------------------------------------//
-
-#ifndef _KALBASE_BDEFS_H
-#define _KALDEFS_BDEFS_H
-
-//------------------------------------------//
-
-#ifndef TRUE
-#define TRUE 1
-#endif
-
-#ifndef FALSE
-#define FALSE 0
-#endif
-
-#ifndef NULL
-#define NULL 0L
-#endif
-
-#ifndef RAND_MAX
-#define RAND_MAX (1 << 30)
-#endif
-
-#ifndef INITOK
-#define INITOK ((unsigned int)0xCAFEBABE)
-#endif
-
-//------------------------------------------//
-
-#ifndef _NO_UNITS
-#define KB (1UL << 10)
-#define MB (1UL << 20)
-#define GB (1UL << 30)
-#define TB (1UL << 40)
-#endif
-
-#ifndef _ALIGN_UP
-#define _ALIGN_UP(x, s) (((x) + (s) - 1) & (~((s) - 1)))
-#endif
-
-//------------------------------------------//
-
-#ifndef __BEGIN_DECLS
-#ifdef __cpluplus
-# define __EXTERN_C extern "C"
-# define __BEGIN_DECLS extern "C" {
-# define __END_DECLS }
-#else
-# define __EXTERN_C
-# define __BEGIN_DECLS
-# define __END_DECLS
-#endif
-#endif
-
-//------------------------------------------//
-
-#if defined(_NO_DEBUG) || defined(NDEBUG)
-#ifndef NDEBUG
-#define NDEBUG 1
-#endif
-#ifndef _NO_DEBUG
-#define _NO_DEBUG 1
-#endif
-#endif
-
-//------------------------------------------//
-
-#ifndef __alignof_is_defined
-#define __alignof_is_defined
-#define alignof _Alignof
-#endif
-
-#ifndef __alignas_is_defined
-#define __alignas_is_defined
-#define alignas _Alignas
-#endif
-
-#ifndef TRUE
-#define TRUE 1
-#endif
-
-#ifndef FALSE
-#define FALSE 0
-#endif
-
-#ifndef __bool_true_false_are_defined
-#define __bool_true_false_are_defined
-#ifndef __cplusplus
-# define bool _Bool
-# define true 1
-# define false 0
-#else
-# define bool bool
-# define true true
-# define false false
-#endif
-#endif
-//------------------------------------------//
-
-#ifndef _PACKED
-#define _PACKED __attribute__((__packed__))
-#endif
-
-#ifndef noreturn
-#define noreturn __attribute__((__noreturn__))
-#endif
-
-#ifndef likely
-#define likely(x) (__builtin_expect((x), 1))
-#endif
-
-#ifndef unlikely
-#define unlikely(x) (__builtin_expect((x), 0))
-#endif
-
-#ifndef _STR
-#define _STR(x) #x
-#endif
-
-#ifndef _XSTR
-#define _XSTR(x) _STR(x)
-#endif
-
-//------------------------------------------//
-
-#endif
diff --git a/include/base/crtlib.h b/include/base/crtlib.h
deleted file mode 100644
index b6f6f28..0000000
--- a/include/base/crtlib.h
+++ /dev/null
@@ -1,314 +0,0 @@
-//----------------------------------------------------------------------------//
-// GNU GPL OS/K //
-// //
-// Desc: C Runtime Library //
-// //
-// //
-// 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 . //
-//----------------------------------------------------------------------------//
-
-#ifndef _KALBASE_CRTLIB_H
-#define _KALBASE_CRTLIB_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-//------------------------------------------//
-
-#ifndef __error_t_defined
-#define __error_t_defined
-typedef unsigned int error_t;
-#endif
-
-#ifndef __size_t_defined
-#define __size_t_defined
-typedef unsigned long size_t;
-#endif
-
-#ifndef __va_list_defined
-#define __va_list_defined
-typedef __builtin_va_list va_list;
-#endif
-
-#ifndef __osk_div_t_defined
-#define __osk_div_t_defined
-typedef struct { int quot, rem; } div_t;
-#endif
-
-#ifndef __osk_ldiv_t_defined
-#define __osk_ldiv_t_defined
-typedef struct { long quot, rem; } ldiv_t;
-#endif
-
-//------------------------------------------//
-
-#ifndef _KALEID_KERNEL
-
-extern error_t __errno;
-
-#ifndef errno
-#define errno __errno
-#endif
-
-#define geterrno(x) ((x) = errno)
-#define seterrno(x) (errno = (x))
-
-#else
-
-#define errno
-#define geterrno(x) ((void)x)
-#define seterrno(x) ((void)x)
-
-#endif
-
-//------------------------------------------//
-
-#ifndef _NO_MASK
-#define _NO_MASK
-#endif
-
-//------------------------------------------//
-
-#ifndef va_start
-#define va_start __builtin_va_start
-#endif
-
-#ifndef va_arg
-#define va_arg __builtin_va_arg
-#endif
-
-#ifndef va_copy
-#define va_copy __builtin_va_copy
-#endif
-
-#ifndef va_end
-#define va_end __builtin_va_end
-#endif
-
-//------------------------------------------//
-
-#ifndef memsetb
-#define memsetb memset
-#endif
-
-#ifndef memchrb
-#define memchrb memchr
-#endif
-
-void *memset(void *, int, size_t);
-void *memsetw(void *, int, size_t);
-void *memsetd(void *, int, size_t);
-void *memsetq(void *, long, size_t);
-
-/*
-void *memchr(const void *, int, size_t);
-void *memchrw(const void *, int, size_t);
-void *memchrd(const void *, int, size_t);
-void *memchrq(const void *, long, size_t);
-*/
-
-void *memrchr(const void *, int, size_t);
-
-void *memcpy(void *restrict, const void *restrict, size_t);
-void *memmove(void *, const void *, size_t);
-
-void *memzero(void *, size_t);
-int memcmp(const void *, const void *, size_t);
-
-//------------------------------------------//
-
-size_t strlen(const char *);
-size_t strspn(const char *, const char *);
-size_t strcspn(const char *, const char *);
-
-int strcmp(const char *, const char *);
-int strncmp(const char *, const char *, size_t);
-
-char *strchr(const char *, int);
-char *strrchr(const char *, int);
-char *strchrnul(const char *, int);
-
-char *strstr(const char *, const char *);
-char *strpbrk(const char *, const char *);
-
-char *strtok(char *restrict, const char *restrict);
-char *strtok_r(char *restrict, const char *restrict, char **restrict);
-
-char *strcpy(char *restrict, const char *restrict);
-char *strncpy(char *restrict, const char *restrict, size_t);
-char *strnzcpy(char *restrict, const char *restrict, size_t);
-
-char *strcat(char *restrict, const char *restrict);
-char *strncat(char *restrict, const char *restrict, size_t);
-char *strnzcat(char *restrict, const char *restrict, size_t);
-
-char *strrev(char *restrict, const char *restrict);
-char *strrev2(char *);
-
-size_t sprintf(char *, const char *, ...);
-size_t snprintf(char *, size_t, const char *, ...);
-size_t vsprintf(char *, const char *, va_list);
-size_t vsnprintf(char *, size_t, const char *, va_list);
-
-//------------------------------------------//
-
-char *itoa(int, char *, int);
-char *ltoa(long, char *, int);
-char *utoa(unsigned int, char *, int);
-char *ultoa(unsigned long, char *, int);
-
-int atoi(const char *);
-long atol(const char *);
-long strtol(const char *restrict, char **restrict, int);
-
-unsigned int atou(const char *);
-unsigned long atoul(const char *);
-unsigned long strtoul(const char *restrict, char **restrict, int);
-
-//------------------------------------------//
-
-void *calloc(size_t, size_t) __attribute__((__malloc__));
-void *malloc(size_t) __attribute__((__malloc__));
-void free(void *);
-
-//------------------------------------------//
-
-int rand(void);
-void srand(unsigned long);
-
-//------------------------------------------//
-
-char *strerror(int);
-char *strsignal(int);
-
-//------------------------------------------//
-
-int toupper(int);
-int tolower(int);
-
-static inline int isascii(int __c)
-{ return !(__c & ~0xff); }
-
-//------------------------------------------//
-
-extern int __ctype[];
-
-#define _SH(x) (1 << (x))
-
-enum
-{
- _CT = _SH(0), // control
- _PR = _SH(1), // printing
- _GR = _SH(2), // graphical
- _DX = _SH(3), // hex digit
- _DG = _SH(4), // decimal digit
- _SP = _SH(5), // space
- _BK = _SH(6), // blank
- _PT = _SH(7), // punctuation
- _AL = _SH(8), // alpha
- _UP = _SH(9), // upper alpha
- _LW = _SH(10), // lower alpha
-};
-
-#define _DECF(name, flag) \
-static inline bool name(int __c) \
-{ return isascii(__c) ? !!(__ctype[__c] & flag) : 0; }
-
-_DECF(iscntrl, _CT);
-_DECF(isprint, _PR);
-_DECF(isgraph, _GR);
-_DECF(isdigit, _DG);
-_DECF(isspace, _SP);
-_DECF(isblank, _BK);
-_DECF(ispunct, _PT);
-_DECF(isalpha, _AL);
-_DECF(isupper, _UP);
-_DECF(islower, _LW);
-_DECF(isxdigit, _DX);
-_DECF(isalnum, (_AL|_DG));
-
-#undef _SH
-#undef _DECF
-
-//------------------------------------------//
-
-#ifndef __min_defined
-#define __min_defined
-static inline int min(int __x, int __y)
-{ return __x < __y ? __x : __y; }
-#endif
-
-#ifndef __lmin_defined
-#define __lmin_defined
-static inline long lmin(long __x, long __y)
-{ return __x < __y ? __x : __y; }
-#endif
-
-#ifndef __max_defined
-#define __max_defined
-static inline int max(int __x, int __y)
-{ return __x > __y ? __x : __y; }
-#endif
-
-#ifndef __lmax_defined
-#define __lmax_defined
-static inline long lmax(long __x, long __y)
-{ return __x > __y ? __x : __y; }
-#endif
-
-#ifndef __abs_defined
-#define __abs_defined
-static inline int abs(int __x)
-{ return __x < 0 ? -__x : __x; }
-#endif
-
-#ifndef __labs_defined
-#define __labs_defined
-static inline long labs(long __x)
-{ return __x < 0 ? -__x : __x; }
-#endif
-
-#ifndef __div_defined
-#define __div_defined
-static inline div_t div(int __x, int __y) {
- div_t __res;
- __res.quot = __x/__y;
- __res.rem = __x%__y;
- return __res;
-}
-#endif
-
-#ifndef __ldiv_defined
-#define __ldiv_defined
-static inline ldiv_t ldiv(long __x, long __y) {
- ldiv_t __res;
- __res.quot = __x/__y;
- __res.rem = __x%__y;
- return __res;
-}
-#endif
-
-//------------------------------------------//
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
diff --git a/include/base/limits.h b/include/base/limits.h
deleted file mode 100644
index 57a5a35..0000000
--- a/include/base/limits.h
+++ /dev/null
@@ -1,97 +0,0 @@
-//----------------------------------------------------------------------------//
-// GNU GPL OS/K //
-// //
-// Desc: Integer types limits and utilities //
-// //
-// //
-// 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 . //
-//----------------------------------------------------------------------------//
-
-#ifndef _KALBASE_LIMITS_H
-#define _KALBASE_LIMITS_H
-
-//------------------------------------------//
-
-#define BYTE unsigned char
-#define WORD unsigned short
-#define DWORD unsigned int
-#define QWORD unsigned long
-
-#define CHAR_BIT 8
-#define BITS_IN(T) (sizeof(T) * CHAR_BIT)
-
-#define _ADDR_TO_MB(x) ((x)>>20)
-#define _ADDR_TO_KB(x) (((x)>>10)&(KB-1))
-#define _ADDR_TO_B(x) ((x)&(KB-1))
-
-/* XXX find a generic way */
-#define BYTES_TO_WORDS(B) ((B) >> 1)
-#define BYTES_TO_DWORDS(B) ((B) >> 2)
-#define BYTES_TO_QWORDS(B) ((B) >> 3)
-#define WORDS_TO_BYTES(W) ((W) << 1)
-#define WORDS_TO_DWORDS(W) ((W) >> 1)
-#define WORDS_TO_QWORDS(W) ((W) >> 2)
-#define DWORDS_TO_BYTES(D) ((D) << 2)
-#define DWORDS_TO_WORDS(D) ((D) << 1)
-#define DWORDS_TO_QWORDS(D) ((D) >> 1)
-#define QWORDS_TO_BYTES(Q) ((Q) << 3)
-#define QWORDS_TO_WORDS(Q) ((Q) << 2)
-#define QWORDS_TO_DWORDS(Q) ((Q) << 1)
-
-//------------------------------------------//
-
-/* U/L suffixes on hex numbers look odd */
-#define SCHAR_MAX ((signed char) 0x7F)
-#define SHRT_MAX ((short) 0x7FFF)
-#define INT_MAX ((int) 0x7FFFFFFF)
-#define LONG_MAX ((long) 0x7FFFFFFFFFFFFFFFL)
-#define UCHAR_MAX ((unsigned char) 0xFFU)
-#define USHRT_MAX ((unsigned short) 0xFFFFU)
-#define UINT_MAX ((unsigned int) 0xFFFFFFFFU)
-#define ULONG_MAX ((unsigned long) 0xFFFFFFFFFFFFFFFFUL)
-
-#define SCHAR_MIN ((signed char) -SCHAR_MAX - 1)
-#define SHRT_MIN ((short) -SHRT_MAX - 1)
-#define INT_MIN ((int) -INT_MAX - 1)
-#define LONG_MIN ((long) -LONG_MAX - 1L)
-
-#ifdef __CHAR_UNSIGNED__
-# define CHAR_MIN ((char)0)
-# define CHAR_MAX ((char)UCHAR_MAX)
-#else
-# define CHAR_MIN ((char)SCHAR_MIN)
-# define CHAR_MAX ((char)SCHAR_MAX)
-#endif
-
-#define SSIZE_T_MIN LONG_MIN
-#define SSIZE_T_MAX LONG_MAX
-#define SIZE_T_MAX ULONG_MAX
-
-#ifdef NEED_MORE_USELESS_DATA
-# define UCHAR_MIN ((unsigned char)0)
-# define USHRT_MIN ((unsigned short)0)
-# define UINT_MIN ((unsigned int)0)
-# define ULONG_MIN ((unsigned long)0)
-# ifdef STILL_NEED_MORE_USELESS_DATA
-# error "Not enough useless data!"
-# endif
-#endif
-
-//------------------------------------------//
-
-#endif
diff --git a/include/base/masks.h b/include/base/masks.h
deleted file mode 100644
index 38d3ae7..0000000
--- a/include/base/masks.h
+++ /dev/null
@@ -1,168 +0,0 @@
-//----------------------------------------------------------------------------//
-// GNU GPL OS/K //
-// //
-// Desc: Function name masks for compiling the Kaleid CRT on Linux //
-// //
-// //
-// 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 . //
-//----------------------------------------------------------------------------//
-
-#ifndef _KALBASE_MASKS_H
-#define _KALBASE_MASKS_H
-
-//
-// This file is only used for testing purposes
-// It will be deleted at some point
-//
-
-//------------------------------------------//
-
-#define div_t _osk_div_t
-#define ldiv_t _osk_ldiv_t
-
-//------------------------------------------//
-
-#define memset _osk_memsetb
-#define memchr _osk_memchrb
-
-#define memsetb _osk_memsetb
-#define memsetw _osk_memsetw
-#define memsetd _osk_memsetd
-#define memsetq _osk_memsetq
-
-#define memchr _osk_memchrb
-#define memchrw _osk_memchrw
-#define memchrd _osk_memchrd
-#define memchrq _osk_memchrq
-
-#define memcpy _osk_memcpy
-#define memmove _osk_memmove
-
-#define memcmp _osk_memcmp
-#define memzero _osk_memzero
-
-//------------------------------------------//
-
-#undef strspn
-#undef strcspn
-#define strlen _osk_strlen
-#define strspn _osk_strspn
-#define strcspn _osk_strcspn
-
-#undef strcmp
-#undef strncmp
-#define strcmp _osk_strcmp
-#define strncmp _osk_strncmp
-
-#undef strchr
-#undef strrchr
-#define strchr _osk_strchr
-#define strrchr _osk_strrchr
-
-#undef strstr
-#undef strpbrk
-#define strstr _osk_strstr
-#define strpbrk _osk_strpbrk
-
-#undef strtok
-#undef strtok_r
-#define strtok _osk_strtok
-#define strtok_r _osk_strtok_r
-
-#undef strcpy
-#undef strncpy
-#define strcpy _osk_strcpy
-#define strncpy _osk_strncpy
-#define strnzcpy _osk_strnzcpy
-
-#undef strcat
-#undef strncat
-#define strcat _osk_strcat
-#define strncat _osk_strncat
-#define strnzcat _osk_strnzcat
-
-#define strrev _osk_strrev
-#define strrev2 _osk_strrev2
-
-#define sprintf _osk_sprintf
-#define snprintf _osk_snprintf
-#define vsprintf _osk_vsprintf
-#define vsnprintf _osk_vsnprintf
-
-//------------------------------------------//
-
-#define itoa _osk_itoa
-#define ltoa _osk_ltoa
-#define utoa _osk_utoa
-#define ultoa _osk_ultoa
-
-#define atoi _osk_atoi
-#define atol _osk_atol
-#define atou _osk_atou
-#define atoul _osk_atoul
-
-#define strtol _osk_strtol
-#define strtoul _osk_strtoul
-
-//------------------------------------------//
-
-#define rand _osk_rand
-#define srand _osk_srand
-
-//------------------------------------------//
-
-#define toupper _osk_toupper
-#define tolower _osk_tolower
-
-#define isascii _osk_isascii
-#define iscntrl _osk_iscntrl
-#define isprint _osk_isprint
-#define isgraph _osk_isgraph
-#define isdigit _osk_isdigit
-#define isspace _osk_isspace
-#define isblank _osk_isblank
-#define ispunct _osk_ispunct
-#define isalpha _osk_isalpha
-#define isupper _osk_isupper
-#define islower _osk_islower
-#define isalnum _osk_isalnum
-#define isxdigit _osk_isxdigit
-
-#define __ctype __osk_ctype
-
-//------------------------------------------//
-
-#define abs _osk_abs
-#define labs _osk_labs
-
-#define min _osk_min
-#define lmin _osk_lmin
-
-#define max _osk_max
-#define lmax _osk_lmax
-
-#define div _osk_div
-#define ldiv _osk_ldiv
-
-//------------------------------------------//
-
-#define strerror _osk_strerror
-
-//------------------------------------------//
-
-#endif
diff --git a/include/base/types.h b/include/base/types.h
deleted file mode 100644
index ab3b547..0000000
--- a/include/base/types.h
+++ /dev/null
@@ -1,136 +0,0 @@
-//----------------------------------------------------------------------------//
-// GNU GPL OS/K //
-// //
-// Desc: Common C types used throughout OS/K //
-// //
-// //
-// 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 . //
-//----------------------------------------------------------------------------//
-
-#ifndef _KALBASE_TYPES_H
-#define _KALBASE_TYPES_H
-
-#ifdef __cpluplus
-extern "C" {
-#endif
-
-//------------------------------------------//
-
-#ifndef __base_types_aliases
-#define __base_types_aliases
-typedef unsigned char uchar;
-typedef signed char schar;
-typedef unsigned short ushort;
-typedef unsigned int uint;
-typedef unsigned long ulong;
-typedef signed long long llong;
-typedef unsigned long long ullong;
-typedef long double ldouble;
-#endif
-
-//------------------------------------------//
-
-#ifndef __size_t_defined
-#define __size_t_defined
-typedef unsigned long size_t;
-#endif
-
-#ifndef __ssize_t_defined
-#define __ssize_t_defined
-typedef signed long ssize_t;
-#endif
-
-#ifndef __wchar_t_defined
-#define __wchar_t_defined
-typedef signed int wchar_t;
-#endif
-
-#ifndef __off_t_defined
-#define __off_t_defined
-typedef unsigned long off_t;
-#endif
-
-#ifndef __time_t_defined
-#define __time_t_defined
-typedef unsigned long time_t;
-#endif
-
-//------------------------------------------//
-
-#ifndef __ptrdiff_t_defined
-#define __ptrdiff_t_defined
-typedef signed long ptrdiff_t;
-#endif
-
-#ifndef __intptr_t_defined
-#define __intptr_t_defined
-typedef signed long intptr_t;
-#endif
-
-#ifndef __uintptr_t_defined
-#define __uintptr_t_defined
-typedef unsigned long uintptr_t;
-#endif
-
-#ifndef __intmax_t_defined
-#define __intmax_t_defined
-typedef signed long intmax_t;
-#endif
-
-#ifndef __uintmax_t_defined
-#define __uintmax_t_defined
-typedef unsigned long uintmax_t;
-#endif
-
-//------------------------------------------//
-
-#ifndef __va_list_defined
-#define __va_list_defined
-typedef __builtin_va_list va_list;
-#endif
-
-#ifndef __osk_div_t_defined
-#define __osk_div_t_defined
-typedef struct { int quot, rem; } div_t;
-#endif
-
-#ifndef __osk_ldiv_t_defined
-#define __osk_ldiv_t_defined
-typedef struct { long quot, rem; } ldiv_t;
-#endif
-
-
-//------------------------------------------//
-
-#ifndef __error_t_defined
-#define __error_t_defined
-typedef uint error_t;
-#endif
-
-#ifndef __port_t_defined
-#define __port_t_defined
-typedef ushort port_t;
-#endif
-
-//------------------------------------------//
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/include/base/errno.h b/include/errno.h
similarity index 60%
rename from include/base/errno.h
rename to include/errno.h
index 1ecfe37..9d3c83c 100644
--- a/include/base/errno.h
+++ b/include/errno.h
@@ -22,65 +22,41 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#ifndef _KALBASE_ERRNO_H
-#define _KALBASE_ERRNO_H
+#ifndef _ERRNO_H
+#define _ERRNO_H
-//------------------------------------------//
+//----------------------------------------------------------------------------//
-// Everything went fine
-#define EOK 0
+#ifndef _eentry
+#define _estart enum {
+#define _eentry(code, desc) code,
+#define _eentry(code, desc) code,
+#define _eend _EMAX };
+#endif
-// Operation not permitted
-#define EPERM 1
+_estart
+_eentry(EOK, "No error")
+_eentry(EPERM, "Operation not permitted")
+_eentry(ENOENT, "No such entry, file, or directory")
+_eentry(ESRCH, "No such process or thread")
+_eentry(EINTR, "Operation interrupted")
+_eentry(EIO, "I/O error")
+_eentry(ENXIO, "No such device or address")
+_eentry(E2BIG, "List too long")
+_eentry(ENOEXEC, "Not an executable format")
+_eentry(EBADF, "Bad file, fd, or stream")
+_eentry(EAGAIN, "Try again")
+_eentry(ENOMEM, "Not enough memory")
+_eentry(EINVAL, "Invalid argument value")
+_eentry(ENOSYS, "Functionality not implemented")
+_eentry(EADDRINUSE, "Address in use")
+_eentry(EFAILED, "Failure (unspecified reason)")
+_eentry(EALIGN, "Alignment error or fault")
+_eentry(EENDF, "End of file or stream")
+_eend
-// No such file or directory
-#define ENOENT 2
-
-// No such process
-#define ESRCH 3
-
-// Syscall interrupted (e.g. by signal)
-#define EINTR 4
-
-// I/0 error
-#define EIO 5
-
-// No such device or address
-#define ENXIO 6
-
-// Argument list too long
-#define E2BIG 7
-
-// Not an executable format
-#define ENOEXEC 8
-
-// Bad file
-#define EBADF 9
-
-// Try again
-#define EAGAIN 11
-
-// Out of memory
-#define ENOMEM 12
-
-// Invalid argument
-#define EINVAL 22
-
-// Functionality not implemented
-#define ENOSYS 38
-
-// Address already in use
-#define EADDRINUSE 98
-
-// Failure (unspecified reason)
-#define EFAILED 256
-
-// Alignment error
-#define EALIGN 257
-
-// End of file/stream
-#define EENDF 258
-
-//------------------------------------------//
+#undef _estart
+#undef _eentry
+#undef _eend
#endif
diff --git a/include/extras/argv.h b/include/ex/argv.h
similarity index 99%
rename from include/extras/argv.h
rename to include/ex/argv.h
index 6a6f78b..14541b7 100644
--- a/include/extras/argv.h
+++ b/include/ex/argv.h
@@ -22,8 +22,8 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#ifndef _KALBASE_H
-#include
+#ifndef _LIBC_H
+#include
#endif
#ifndef _KALEXTRAS_ARGV_H
diff --git a/include/ex/lock.h b/include/ex/lock.h
new file mode 100644
index 0000000..f61f09f
--- /dev/null
+++ b/include/ex/lock.h
@@ -0,0 +1,13 @@
+#ifndef _LIBC_H
+#include
+#endif
+
+// Temporary fix
+
+#include
+
+typedef Spinlock_t Lock_t;
+#define ExInitLock KeInitSpinlock
+#define ExAcquireLock KeAcquireSpinlock
+#define ExReleaseLock KeReleaseSpinlock
+
diff --git a/include/extras/malloc.h b/include/ex/malloc.h
similarity index 96%
rename from include/extras/malloc.h
rename to include/ex/malloc.h
index 9d69f35..f63ea44 100644
--- a/include/extras/malloc.h
+++ b/include/ex/malloc.h
@@ -22,12 +22,12 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#ifndef _KALBASE_H
-#include
+#ifndef _LIBC_H
+#include
#endif
-#ifndef _KALEXTRAS_MALLOC_H
-#define _KALEXTRAS_MALLOC_H
+#ifndef _EX_MALLOC_H
+#define _EX_MALLOC_H
#ifdef __cplusplus
extern "C" {
diff --git a/include/extras/locks.h b/include/extras/locks.h
deleted file mode 100644
index e319b85..0000000
--- a/include/extras/locks.h
+++ /dev/null
@@ -1,186 +0,0 @@
-//----------------------------------------------------------------------------//
-// GNU GPL OS/K //
-// //
-// Desc: Locks and synchronization //
-// //
-// //
-// 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 . //
-//----------------------------------------------------------------------------//
-
-#ifndef _KALBASE_H
-#include
-#endif
-
-#ifdef _KALEID_KERNEL
-
-#ifndef _KALKERN_SCHED_H
-#include
-#endif
-
-#endif
-
-#ifndef _KALEXTRAS_LOCKS_H
-#define _KALEXTRAS_LOCKS_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef enum LockType_t LockType_t;
-typedef struct Lock_t Lock_t;
-
-//------------------------------------------//
-
-enum LockType_t
-{
- // Mutex-type lock
- //
- // WARNING
- // AcquireLock() panics when used on a mutex while not running a process
- KLOCK_MUTEX,
-
- // Spinlock-type lock
- KLOCK_SPINLOCK,
-
-};
-
-struct Lock_t
-{
- unsigned int initDone;
- volatile int locked;
- LockType_t type;
-
-/* #ifdef _KALEID_KERNEL
- Thread_t *ownerThread; // unused
- Thread_t *waitingThread; // unused
-#endif */
-};
-
-//------------------------------------------//
-
-#ifndef _KALEID_KERNEL
-int KalYieldCPU(void),
-#endif
-
-//
-// Initialize a lock
-//
-static inline
-void ExInitLock(Lock_t *lock, LockType_t type)
-{
- lock->locked = 0;
- lock->type = type;
- lock->initDone = INITOK;
-/* #ifdef _KALEID_KERNEL
- lock->ownerThread = NULL;
- lock->waitingThread = NULL;
-#endif */
-}
-
-//
-// Alternative way to initalize a lock
-//
-#ifdef _KALEID_KERNEL
-# define ExINITLOCK(type) { INITOK, 0, (type), /* NULL, NULL */ }
-#else
-# define ExINITLOCK(type) { INITOK, 0, (type) }
-#endif
-
-//
-// Destroy a lock
-//
-static inline
-void ExDestroyLock(Lock_t *lock)
-{
- KalAssert(lock->initDone);
-
- __sync_synchronize();
- lock->initDone = 0;
-}
-
-//
-// Acquire the lock
-// Panic on double acquisition since that should never happen
-// until we have at least a basic scheduler
-//
-static inline
-#if defined(_KALEID_KERNEL) && !defined(_NO_DEBUG)
-#define ExAcquireLock(lock) \
- _ExAcquireLock(lock,__FILE__, __LINE__, __func__,#lock)
-void _ExAcquireLock(Lock_t *lock, const char *file, int line,
- const char *func, const char *obj)
-#else
-void ExAcquireLock(Lock_t *lock)
-#endif
-{
- KalAssert(lock->initDone == INITOK);
-
- while (!__sync_bool_compare_and_swap(&lock->locked, 0, 1)) {
-#if defined(_KALEID_KERNEL) && !defined(_NO_DEBUG)
- KeStartPanic(
- "In function '%s', from '%s' line %d\n"
- "Double ExAcquireLock on object: '%s'",
- func, file, line, obj);
-#endif
- /*if likely (lock->type == KLOCK_SPINLOCK)*/
- continue;
- //else (void)KalYieldCPU();
- }
- PsDisablePreemption();
- __sync_synchronize();
-}
-
-//
-// Release an already acquired lock
-// Panic if the lock was never acquired
-//
-static inline
-void ExReleaseLock(Lock_t *lock)
-{
-/*#ifdef _KALEID_KERNEL
- KalAssert(lock->ownerThread == GetCurThread());
-#endif*/
-
- __sync_synchronize();
-
- lock->locked = 0;
- PsEnablePreemption();
-}
-
-//
-// Tries to acquire lock
-//
-static inline
-bool ExAttemptLock(Lock_t *lock)
-{
- KalAssert(lock->initDone == INITOK);
-
- bool retval = __sync_bool_compare_and_swap(&lock->locked, 0, 1);
-
- __sync_synchronize();
-
- return retval;
-}
-
-//------------------------------------------//
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/include/kernel/boot.h b/include/init/boot.h
similarity index 97%
rename from include/kernel/boot.h
rename to include/init/boot.h
index b4e4bf9..931f996 100644
--- a/include/kernel/boot.h
+++ b/include/init/boot.h
@@ -22,12 +22,12 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#ifndef _KALKERN_BASE_H
-#include
+#ifndef _KERNEL_H
+#include
#endif
-#ifndef _KALKERN_BOOT_H
-#define _KALKERN_BOOT_H
+#ifndef _INIT_BOOT_H
+#define _INIT_BOOT_H
//----------------------------------------------------------------------------//
diff --git a/include/kernel/mboot.h b/include/init/mboot.h
similarity index 99%
rename from include/kernel/mboot.h
rename to include/init/mboot.h
index b9edb93..a68cb0a 100644
--- a/include/kernel/mboot.h
+++ b/include/init/mboot.h
@@ -23,8 +23,8 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#ifndef _KALKERN_BASE_H
-#include
+#ifndef _KERNEL_H
+#include
#endif
#ifndef MULTIBOOT_HEADER
diff --git a/include/kernel/cursor.h b/include/io/cursor.h
similarity index 93%
rename from include/kernel/cursor.h
rename to include/io/cursor.h
index f154a5b..5222910 100644
--- a/include/kernel/cursor.h
+++ b/include/io/cursor.h
@@ -22,18 +22,18 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#ifndef _KALKERN_BASE_H
-#include
+#ifndef _KERNEL_H
+#include
#endif
-#ifndef _KALKERN_CURSOR_H
-#define _KALKERN_CURSOR_H
+#ifndef _IO_CURSOR_H
+#define _IO_CURSOR_H
//----------------------------------------------------------------------------//
void IoEnableCursor(void);
void IoDisableCursor(void);
-void IoUpdateCursor(int x, int y);
+void IoUpdateCursor(int, int);
//----------------------------------------------------------------------------//
diff --git a/include/kernel/keyboard.h b/include/io/keyb.h
similarity index 94%
rename from include/kernel/keyboard.h
rename to include/io/keyb.h
index 8fd6f58..f76befb 100644
--- a/include/kernel/keyboard.h
+++ b/include/io/keyb.h
@@ -22,18 +22,17 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#ifndef _KALKERN_BASE_H
-#include
+#ifndef _KERNEL_H
+#include
#endif
-#ifndef _KALKERN_KEYB_H
-#define _KALKERN_KEYB_H
+#ifndef _IO_KEYB_H
+#define _IO_KEYB_H
//----------------------------------------------------------------------------//
void IoEnableKeyb();
-void IoChangeCodePage(char *CodePage);
-
+void IoChangeCodePage(char *);
//----------------------------------------------------------------------------//
@@ -45,7 +44,6 @@ void IoChangeCodePage(char *CodePage);
#define KEY_DC3 19
#define KEY_DC4 20
-
//----------------------------------------------------------------------------//
#endif
diff --git a/include/kernel/speaker.h b/include/io/spkr.h
similarity index 94%
rename from include/kernel/speaker.h
rename to include/io/spkr.h
index 4b5cd1e..85737a8 100644
--- a/include/kernel/speaker.h
+++ b/include/io/spkr.h
@@ -22,16 +22,16 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#ifndef _KALKERN_BASE_H
-#include
+#ifndef _KERNEL_H
+#include
#endif
-#ifndef _KALKERN_SPEAKER_H
-#define _KALKERN_SPEAKER_H
+#ifndef _IO_SPKR_H
+#define _IO_SPKR_H
//----------------------------------------------------------------------------//
-void IoStartSpeaker(int freq);
+void IoStartSpeaker(int);
void IoQuietSpeaker(void);
void IoDoBeep(void);
void IoDoTone(uint tone, uint time);
diff --git a/include/kalbase.h b/include/kalbase.h
deleted file mode 100644
index 504bd6d..0000000
--- a/include/kalbase.h
+++ /dev/null
@@ -1,64 +0,0 @@
-//----------------------------------------------------------------------------//
-// GNU GPL OS/K //
-// //
-// Desc: Base include file for OS/K //
-// //
-// //
-// 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 . //
-//----------------------------------------------------------------------------//
-
-#ifndef _KALBASE_H
-#define _KALBASE_H
-
-//------------------------------------------//
-
-#ifndef _OSK_SOURCE
-#ifdef _KALEID_KERNEL
-#define _OSK_SOURCE 1
-#endif
-#endif
-
-//------------------------------------------//
-
-#ifndef _KALBASE_BDEFS_H
-#include
-#endif
-
-#ifndef _KALBASE_ERRNO_H
-#include
-#endif
-
-#ifndef _KALBASE_TYPES_H
-#include
-#endif
-
-#ifndef _KALBASE_LIMITS_H
-#include
-#endif
-
-#ifndef _KALBASE_ASSERT_H
-#include
-#endif
-
-#ifndef _KALBASE_CRTLIB_H
-#include
-#endif
-
-//------------------------------------------//
-
-#endif
diff --git a/include/kalext.h b/include/kalext.h
deleted file mode 100644
index ccd1011..0000000
--- a/include/kalext.h
+++ /dev/null
@@ -1,55 +0,0 @@
-//----------------------------------------------------------------------------//
-// GNU GPL OS/K //
-// //
-// Desc: Kaleid "extra" API main include file //
-// //
-// //
-// 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 . //
-//----------------------------------------------------------------------------//
-
-#ifndef _KALBASE_H
-#include
-#endif
-
-#ifndef _KALEXT_H
-#define _KALEXT_H
-
-//------------------------------------------//
-
-#ifndef _KALEXTRAS_LOCKS_H
-#include
-#endif
-
-#ifndef _KALEXTRAS_PROG_H
-#include
-#endif
-
-#ifndef _KALEXTRAS_ARGV_H
-#include
-#endif
-
-#ifndef _KALEID_KERNEL
-#ifndef _KALEXTRAS_LIST_H
-#include
-#endif
-#endif
-
-//------------------------------------------//
-
-#endif
-
diff --git a/include/kernel/cpuid.h b/include/ke/cpuid.h
similarity index 99%
rename from include/kernel/cpuid.h
rename to include/ke/cpuid.h
index 4876a5c..e1c9c6f 100644
--- a/include/kernel/cpuid.h
+++ b/include/ke/cpuid.h
@@ -22,8 +22,8 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#ifndef _KALKERN_BASE_H
-#include
+#ifndef _KERNEL_H
+#include
#endif
#ifndef _KALKERN_CPUID_H
diff --git a/include/kernel/idt.h b/include/ke/idt.h
similarity index 98%
rename from include/kernel/idt.h
rename to include/ke/idt.h
index ec4c071..80d13ad 100644
--- a/include/kernel/idt.h
+++ b/include/ke/idt.h
@@ -22,8 +22,8 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#ifndef _KALKERN_BASE_H
-#include
+#ifndef _KERNEL_H
+#include
#endif
#ifndef _KALKERN_IDT_H
diff --git a/include/kernel/proc.h b/include/ke/proc.h
similarity index 89%
rename from include/kernel/proc.h
rename to include/ke/proc.h
index 11fbfde..c10e4ac 100644
--- a/include/kernel/proc.h
+++ b/include/ke/proc.h
@@ -22,8 +22,8 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#ifndef _KALKERN_BASE_H
-#include
+#ifndef _KERNEL_H
+#include
#endif
#ifndef _KALKERN_PROC_H
@@ -74,13 +74,5 @@ struct Process_t
//----------------------------------------------------------------------------//
-#define PsCurProc (KeCurCPU->process)
-#define PsCurThread (KeCurCPU->thread)
-
-//DEC_PER_CPU(Ps, CurProc, process, Process_t *);
-//DEC_PER_CPU(Ps, CurThread, thread, Thread_t *);
-
-//----------------------------------------------------------------------------//
-
#endif
diff --git a/include/kernel/sched.h b/include/ke/sched.h
similarity index 98%
rename from include/kernel/sched.h
rename to include/ke/sched.h
index ad63802..9005de2 100644
--- a/include/kernel/sched.h
+++ b/include/ke/sched.h
@@ -22,8 +22,8 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#ifndef _KALKERN_BASE_H
-#include
+#ifndef _KERNEL_H
+#include
#endif
#ifndef _KALKERN_SCHED_H
diff --git a/include/extras/prog.h b/include/ke/spinlock.h
similarity index 68%
rename from include/extras/prog.h
rename to include/ke/spinlock.h
index 3af6461..f1e09b1 100644
--- a/include/extras/prog.h
+++ b/include/ke/spinlock.h
@@ -1,7 +1,7 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
-// Desc: Program utilities //
+// Desc: Spinlocks //
// //
// //
// Copyright © 2018-2019 The OS/K Team //
@@ -22,29 +22,48 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#ifndef _KALBASE_H
-#include
+#ifndef _KERNEL_H
+#include
#endif
-#ifndef _KALEXTRAS_PROG_H
-#define _KALEXTRAS_PROG_H
+#ifndef _KALKERN_SPINLOCK_H
+#define _KALKERN_SPINLOCK_H
#ifdef __cplusplus
extern "C" {
#endif
-//------------------------------------------//
+//----------------------------------------------------------------------------//
-extern const char *__progname;
-extern const char *__progvers;
+static inline void KeInitSpinlock(Spinlock_t *lock) { *lock = 0; }
-//------------------------------------------//
+static inline void KeAcquireSpinlockIRQ(Spinlock_t *lock)
+{
+ while (1) {
+ if (!atomic_xchg_64(lock, (void *)1)) return;
+ while (*lock) __relax_cpu();
+ }
+}
-const char *KalGetProgName(void);
-const char *KalGetProgVersion(void);
+static inline void KeAcquireSpinlock(Spinlock_t *lock)
+{
+ while (1) {
+ if (!atomic_xchg_64(lock, KeCurThread)) return;
+ while (*lock) __relax_cpu();
+ }
+}
-error_t KalSetProgVers(const char *);
-error_t KalSetProgName(const char *);
+static inline void KeReleaseSpinlock(Spinlock_t *lock)
+{
+ atomic_barrier();
+ assert(*lock == (ulong)KeCurThread);
+ *lock = 0;
+}
+
+static inline ulong KeTestSpinLock(Spinlock_t *lock)
+{
+ return (ulong)atomic_xchg_64(lock, KeCurThread);
+}
//------------------------------------------//
diff --git a/include/kernel/time.h b/include/ke/time.h
similarity index 98%
rename from include/kernel/time.h
rename to include/ke/time.h
index bd29043..cc3e312 100644
--- a/include/kernel/time.h
+++ b/include/ke/time.h
@@ -22,8 +22,8 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#ifndef _KALKERN_BASE_H
-#include
+#ifndef _KERNEL_H
+#include
#endif
#ifndef _KALKERN_TIME_H
diff --git a/include/kernel/base.h b/include/kernel.h
similarity index 92%
rename from include/kernel/base.h
rename to include/kernel.h
index 2fe40ac..dd2d43b 100644
--- a/include/kernel/base.h
+++ b/include/kernel.h
@@ -22,20 +22,20 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#ifndef _KALBASE_H
-#include
+#ifndef _LIBC_H
+#include
#endif
-#ifdef __cplusplus
-#error "Kaleid's kernel won't compile in C++"
-#endif
-
-#ifndef _KALKERN_BASE_H
-#define _KALKERN_BASE_H
+#ifndef _KERNEL_H
+#define _KERNEL_H
//----------------------------------------------------------------------------//
-typedef struct Lock_t Lock_t;
+typedef volatile ulong Spinlock_t;
+
+typedef Spinlock_t Lock_t;
+//typedef struct Lock_t Lock_t;
+
typedef struct Buffer_t Buffer_t;
typedef struct ListHead_t ListHead_t;
typedef struct ListNode_t ListNode_t;
@@ -124,6 +124,7 @@ struct ISRFrame_t {
ulong ss;
} __attribute__((__packed__));
+error_t IdtRegisterIsr(void (*isr)(ISRFrame_t *regs), uchar isrNo);
//----------------------------------------------------------------------------//
@@ -140,17 +141,20 @@ extern CpuCore_t _KeCPUTable[NCPUS];
//----------------------------------------------------------------------------//
+#define KeCurProc (KeCurCPU->process)
+#define KeCurThread (KeCurCPU->thread)
+
+//----------------------------------------------------------------------------//
+
+#include
+
+//----------------------------------------------------------------------------//
+
#define DEC_PER_CPU(pref, name, field, type) \
static inline type pref##Get##name() { return KeGetCurCPU()->field; } \
static inline void _##pref##Set##name(type __val) \
{ KeGetCurCPU()->field = __val; }
-#define BARRIER() \
- do { \
- asm volatile("": : :"memory"); \
- __sync_synchronize(); \
- } while(0)
-
//----------------------------------------------------------------------------//
#ifdef NDEBUG
diff --git a/include/extras/buf.h b/include/lib/buf.h
similarity index 96%
rename from include/extras/buf.h
rename to include/lib/buf.h
index 3c85537..07311dc 100644
--- a/include/extras/buf.h
+++ b/include/lib/buf.h
@@ -22,12 +22,12 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#ifndef _KALEXTRAS_LOCKS_H
-#include
+#ifndef _EX_LOCK_H
+#include
#endif
-#ifndef _KALEXTRAS_BUF_H
-#define _KALEXTRAS_BUF_H
+#ifndef _LIB_BUF_H
+#define _LIB_BUF_H
//
// Buffer flags
@@ -77,7 +77,6 @@ typedef error_t (*BFlusher_t)(Buffer_t *);
struct Buffer_t
{
- uint initDone;
Lock_t lock;
int flags; // Buffer flags
@@ -139,7 +138,7 @@ int BGetState(Buffer_t *);
error_t BFlushBuf(Buffer_t *);
error_t BPutOnBuf(Buffer_t *, uchar);
-error_t BWriteOnBuf(Buffer_t *, uchar *, size_t); // TODO
+error_t BWriteOnBuf(Buffer_t *, uchar *, size_t);
error_t BPrintOnBuf(Buffer_t *, const char *, ...);
error_t BPrintOnBufV(Buffer_t *, const char *, va_list);
diff --git a/include/extras/list.h b/include/lib/list.h
similarity index 92%
rename from include/extras/list.h
rename to include/lib/list.h
index 7c51556..a3eb619 100644
--- a/include/extras/list.h
+++ b/include/lib/list.h
@@ -22,20 +22,12 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#ifndef _KALBASE_H
-#include
+#ifndef _LIBC_H
+#include
#endif
-#ifndef _KALEXTRAS_MALLOC_H
-#include
-#endif
-
-#ifndef _KALEXTRAS_LOCKS_H
-#include
-#endif
-
-#ifndef _KALEXTRAS_LIST_H
-#define _KALEXTRAS_LIST_H
+#ifndef _LIB_LIST_H
+#define _LIB_LIST_H
#ifdef __cplusplus
extern "C" {
@@ -48,7 +40,6 @@ typedef struct ListNode_t ListNode_t;
struct ListHead_t
{
- Lock_t *lock;
ulong length;
ListNode_t *first;
ListNode_t *last;
@@ -68,7 +59,7 @@ struct ListNode_t
// Create a list head with an extern lock
//
static inline ListHead_t
-*ExCreateListHeadWithLock(Lock_t *lock)
+*ExCreateListHead(Lock_t *lock)
{
ListHead_t *head = malloc(sizeof(ListHead_t));
@@ -77,21 +68,9 @@ static inline ListHead_t
head->first = head->last = NULL;
head->length = 0;
- head->lock = lock;
-
return head;
}
-//
-// Create a list head
-//
-static inline ListHead_t
-*ExCreateListHead(void)
-{
- return ExCreateListHeadWithLock(NULL);
-}
-
-//
// Create a node
//
static inline ListNode_t
@@ -244,7 +223,7 @@ static inline ListHead_t
leave:
head->length--;
- KalFreeMemory(node);
+ free(node);
return head;
}
diff --git a/include/libc.h b/include/libc.h
new file mode 100644
index 0000000..bf96d63
--- /dev/null
+++ b/include/libc.h
@@ -0,0 +1,396 @@
+//----------------------------------------------------------------------------//
+// GNU GPL OS/K //
+// //
+// Desc: C Runtime Library //
+// //
+// //
+// 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 . //
+//----------------------------------------------------------------------------//
+
+#ifndef _LIBC_H
+#define _LIBC_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+//----------------------------------------------------------------------------//
+
+typedef unsigned char uchar;
+typedef signed char schar;
+typedef unsigned short ushort;
+typedef unsigned int uint;
+typedef unsigned long ulong;
+typedef signed long long llong;
+typedef unsigned long long ullong;
+typedef long double ldouble;
+
+typedef unsigned long size_t;
+typedef signed long ssize_t;
+typedef signed int wchar_t;
+typedef unsigned long off_t;
+typedef unsigned long time_t;
+typedef signed long ptrdiff_t;
+typedef signed long intptr_t;
+typedef unsigned long uintptr_t;
+typedef signed long intmax_t;
+typedef unsigned long uintmax_t;
+
+typedef uint error_t;
+typedef __builtin_va_list va_list;
+
+//----------------------------------------------------------------------------//
+
+#ifndef _KALEID_KERNEL
+
+extern error_t __errno;
+#define errno __errno
+#define geterrno(x) ((x) = errno)
+#define seterrno(x) (errno = (x))
+
+#else
+
+#define errno
+#define geterrno(x) ((void)x)
+#define seterrno(x) ((void)x)
+
+#endif
+
+#include
+
+//----------------------------------------------------------------------------//
+
+#if defined(_NO_DEBUG) || defined(NDEBUG)
+#ifndef NDEBUG
+#define NDEBUG 1
+#endif
+#ifndef _NO_DEBUG
+#define _NO_DEBUG 1
+#endif
+#endif
+
+//----------------------------------------------------------------------------//
+
+#define alignof _Alignof
+#define alignas _Alignas
+
+#define static_assert _Static_assert
+#define noreturn __attribute__((__noreturn__))
+
+#define likely(x) (__builtin_expect((x), 1))
+#define unlikely(x) (__builtin_expect((x), 0))
+
+#define va_start __builtin_va_start
+#define va_arg __builtin_va_arg
+#define va_copy __builtin_va_copy
+#define va_end __builtin_va_end
+
+//----------------------------------------------------------------------------//
+
+void *memset(void *, int, size_t);
+void *memsetw(void *, int, size_t);
+void *memsetd(void *, int, size_t);
+void *memsetq(void *, long, size_t);
+
+void *memrchr(const void *, int, size_t);
+
+void *memcpy(void *restrict, const void *restrict, size_t);
+void *memmove(void *, const void *, size_t);
+
+void *memzero(void *, size_t);
+int memcmp(const void *, const void *, size_t);
+
+//----------------------------------------------------------------------------//
+
+size_t strlen(const char *);
+size_t strspn(const char *, const char *);
+size_t strcspn(const char *, const char *);
+
+int strcmp(const char *, const char *);
+int strncmp(const char *, const char *, size_t);
+
+char *strchr(const char *, int);
+char *strrchr(const char *, int);
+char *strchrnul(const char *, int);
+
+char *strstr(const char *, const char *);
+char *strpbrk(const char *, const char *);
+
+char *strtok(char *restrict, const char *restrict);
+char *strtok_r(char *restrict, const char *restrict, char **restrict);
+
+char *strcpy(char *restrict, const char *restrict);
+char *strncpy(char *restrict, const char *restrict, size_t);
+char *strnzcpy(char *restrict, const char *restrict, size_t);
+
+char *strcat(char *restrict, const char *restrict);
+char *strncat(char *restrict, const char *restrict, size_t);
+char *strnzcat(char *restrict, const char *restrict, size_t);
+
+char *strrev(char *restrict, const char *restrict);
+char *strrev2(char *);
+
+size_t sprintf(char *, const char *, ...);
+size_t snprintf(char *, size_t, const char *, ...);
+size_t vsprintf(char *, const char *, va_list);
+size_t vsnprintf(char *, size_t, const char *, va_list);
+
+//----------------------------------------------------------------------------//
+
+char *itoa(int, char *, int);
+char *ltoa(long, char *, int);
+char *utoa(unsigned int, char *, int);
+char *ultoa(unsigned long, char *, int);
+
+int atoi(const char *);
+long atol(const char *);
+long strtol(const char *restrict, char **restrict, int);
+
+unsigned int atou(const char *);
+unsigned long atoul(const char *);
+unsigned long strtoul(const char *restrict, char **restrict, int);
+
+//----------------------------------------------------------------------------//
+
+void *calloc(size_t, size_t) __attribute__((__malloc__));
+void *malloc(size_t) __attribute__((__malloc__));
+void free(void *);
+
+//----------------------------------------------------------------------------//
+
+int rand(void);
+void srand(unsigned long);
+
+//----------------------------------------------------------------------------//
+
+const char *strerror(error_t);
+const char *strsignal(int);
+
+//----------------------------------------------------------------------------//
+
+int toupper(int);
+int tolower(int);
+
+static inline int isascii(int __c)
+{ return !(__c & ~0xff); }
+
+//----------------------------------------------------------------------------//
+
+extern int __ctype[];
+
+#define _SH(x) (1 << (x))
+
+enum
+{
+ _CT = _SH(0), // control
+ _PR = _SH(1), // printing
+ _GR = _SH(2), // graphical
+ _DX = _SH(3), // hex digit
+ _DG = _SH(4), // decimal digit
+ _SP = _SH(5), // space
+ _BK = _SH(6), // blank
+ _PT = _SH(7), // punctuation
+ _AL = _SH(8), // alpha
+ _UP = _SH(9), // upper alpha
+ _LW = _SH(10), // lower alpha
+};
+
+#define _DECF(name, flag) \
+static inline int name(int __c) \
+{ return isascii(__c) ? !!(__ctype[__c] & flag) : 0; }
+
+_DECF(iscntrl, _CT);
+_DECF(isprint, _PR);
+_DECF(isgraph, _GR);
+_DECF(isdigit, _DG);
+_DECF(isspace, _SP);
+_DECF(isblank, _BK);
+_DECF(ispunct, _PT);
+_DECF(isalpha, _AL);
+_DECF(isupper, _UP);
+_DECF(islower, _LW);
+_DECF(isxdigit, _DX);
+_DECF(isalnum, (_AL|_DG));
+
+#undef _SH
+#undef _DECF
+
+//----------------------------------------------------------------------------//
+
+static inline int min(int __x, int __y) { return __x < __y ? __x : __y; }
+static inline int max(int __x, int __y) { return __x > __y ? __x : __y; }
+static inline int abs(int __x) { return __x < 0 ? -__x : __x; }
+
+static inline long lmin(long __x, long __y) { return __x < __y ? __x : __y; }
+static inline long lmax(long __x, long __y) { return __x > __y ? __x : __y; }
+static inline long labs(long __x) { return __x < 0 ? -__x : __x; }
+
+//----------------------------------------------------------------------------//
+
+noreturn void __assert_handler(const char *, const char *, int, const char *);
+
+#define assert_always(x) do { if unlikely (!(x)) \
+ __assert_handler(#x, __FILE__, __LINE__, __func__); } while (0)
+
+#ifndef NDEBUG
+#define assert(x) assert_always(x)
+#else
+#define assert(x) ((void)0)
+#endif
+
+//----------------------------------------------------------------------------//
+
+
+#define _SA_MSG "Incompatible type sizes"
+static_assert(sizeof(char) == 1, _SA_MSG);
+static_assert(sizeof(short) == 2, _SA_MSG);
+static_assert(sizeof(int) == 4, _SA_MSG);
+static_assert(sizeof(long) == 8, _SA_MSG);
+static_assert(sizeof(void *) == 8, _SA_MSG);
+#undef _SA_MSG
+
+//----------------------------------------------------------------------------//
+
+#define KB (1UL << 10)
+#define MB (1UL << 20)
+#define GB (1UL << 30)
+#define TB (1UL << 40)
+
+#define TRUE 1
+#define FALSE 0
+#define NULL 0L
+#define BOOL int
+
+#ifndef __cplusplus
+#define bool int
+#define true 1
+#define false 0
+#endif
+
+#define RAND_MAX (1 << 30)
+#define INITOK ((unsigned int)0xCAFEBABE)
+
+#define _STR(x) #x
+#define _XSTR(x) _STR(x)
+
+#define _ALIGN_UP(x, s) (((x) + (s) - 1) & (~((s) - 1)))
+
+//----------------------------------------------------------------------------//
+
+#define BYTE unsigned char
+#define WORD unsigned short
+#define DWORD unsigned int
+#define QWORD unsigned long
+
+#define CHAR_BIT 8
+#define BITS_IN(T) (sizeof(T) * CHAR_BIT)
+
+#define _ADDR_TO_MB(x) ((x)>>20)
+#define _ADDR_TO_KB(x) (((x)>>10)&(KB-1))
+#define _ADDR_TO_B(x) ((x)&(KB-1))
+
+#define SCHAR_MAX 0x7F
+#define SHRT_MAX 0x7FFF
+#define INT_MAX 0x7FFFFFFF
+#define LONG_MAX 0x7FFFFFFFFFFFFFFFL
+#define UCHAR_MAX 0xFFU
+#define USHRT_MAX 0xFFFFU
+#define UINT_MAX 0xFFFFFFFFU
+#define ULONG_MAX 0xFFFFFFFFFFFFFFFFUL
+
+#define SCHAR_MIN (-SCHAR_MAX - 1)
+#define SHRT_MIN (-SHRT_MAX - 1)
+#define INT_MIN (-INT_MAX - 1)
+#define LONG_MIN (-LONG_MAX - 1L)
+
+#ifdef __CHAR_UNSIGNED__
+# define CHAR_MIN ((char)0)
+# define CHAR_MAX ((char)UCHAR_MAX)
+#else
+# define CHAR_MIN ((char)SCHAR_MIN)
+# define CHAR_MAX ((char)SCHAR_MAX)
+#endif
+
+#define SSIZE_T_MIN LONG_MIN
+#define SSIZE_T_MAX LONG_MAX
+#define SIZE_T_MAX ULONG_MAX
+
+//----------------------------------------------------------------------------//
+
+#define atomic_xadd(P, V) __sync_fetch_and_add((P), (V))
+#define atomic_cmpxchg(P, O, N) __sync_val_compare_and_swap((P), (O), (N))
+#define atomic_inc(P) __sync_add_and_fetch((P), 1)
+#define atomic_dec(P) __sync_add_and_fetch((P), -1)
+#define atomic_add(P, V) __sync_add_and_fetch((P), (V))
+#define atomic_set_bit(P, V) __sync_or_and_fetch((P), 1<<(V))
+#define atomic_clear_bit(P, V) __sync_and_and_fetch((P), ~(1<<(V)))
+
+#define atomic_barrier() __sync_synchronize()
+
+#define __relax_cpu() asm volatile("pause\n": : : "memory")
+
+static inline void *atomic_xchg_64(volatile void *ptr, void *x)
+{
+ asm volatile ("xchgq %0,%1"
+ :"=r" ((ulong) x)
+ :"m" (*(volatile long *)ptr), "0" ((ulong) x)
+ :"memory");
+
+ return x;
+}
+
+static inline unsigned atomic_xchg_32(volatile void *ptr, uint x)
+{
+ asm volatile ("xchgl %0,%1"
+ :"=r" ((uint) x)
+ :"m" (*(volatile uint *)ptr), "0" (x)
+ :"memory");
+
+ return x;
+}
+
+static inline unsigned short atomic_xchg_16(volatile void *ptr, ushort x)
+{
+ asm volatile ("xchgw %0,%1"
+ :"=r" ((unsigned short) x)
+ :"m" (*(volatile ushort *)ptr), "0" (x)
+ :"memory");
+
+ return x;
+}
+
+static inline char atomic_bitsetandtest(volatile void *ptr, int x)
+{
+ char out;
+ asm volatile ("lock; bts %2,%1\n"
+ "sbb %0,%0\n"
+ :"=r" (out), "=m" (*(volatile long *)ptr)
+ :"Ir" (x)
+ :"memory");
+
+ return out;
+}
+
+//----------------------------------------------------------------------------//
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/include/kernel/heap.h b/include/mm/heap.h
similarity index 93%
rename from include/kernel/heap.h
rename to include/mm/heap.h
index eccce67..9342ffa 100644
--- a/include/kernel/heap.h
+++ b/include/mm/heap.h
@@ -1,7 +1,7 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
-// Desc: Memory related functions //
+// Desc: Heap management functions //
// //
// //
// Copyright © 2018-2019 The OS/K Team //
@@ -22,12 +22,12 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#ifndef _KALKERN_BASE_H
-#include
+#ifndef _KERNEL_H
+#include
#endif
-#ifndef _KALKERN_HEAP_H
-#define _KALKERN_HEAP_H
+#ifndef _MM_HEAP_H
+#define _MM_HEAP_H
//----------------------------------------------------------------------------//
@@ -57,6 +57,7 @@ error_t MmGrowHeap(size_t);
error_t MmShrinkHeap(size_t);
void MmIsHeapSmashed(void);
+
//----------------------------------------------------------------------------//
#endif
diff --git a/include/kernel/mm.h b/include/mm/mm.h
similarity index 96%
rename from include/kernel/mm.h
rename to include/mm/mm.h
index cc2949c..ac51f36 100644
--- a/include/kernel/mm.h
+++ b/include/mm/mm.h
@@ -1,7 +1,7 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
-// Desc: Memory related functions //
+// Desc: Memory manager functions //
// //
// //
// Copyright © 2018-2019 The OS/K Team //
@@ -22,12 +22,12 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#ifndef _KALKERN_BASE_H
-#include
+#ifndef _KERNEL_H
+#include
#endif
-#ifndef _KALKERN_MM_H
-#define _KALKERN_MM_H
+#ifndef _MM_MM_H
+#define _MM_MM_H
//----------------------------------------------------------------------------//
diff --git a/include/kernel/pwmgnt.h b/include/po/shtdwn.h
similarity index 92%
rename from include/kernel/pwmgnt.h
rename to include/po/shtdwn.h
index a212866..f7dbf81 100644
--- a/include/kernel/pwmgnt.h
+++ b/include/po/shtdwn.h
@@ -1,7 +1,7 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
-// Desc: Power Management related functions //
+// Desc: Shutdown facilities //
// //
// //
// Copyright © 2018-2019 The OS/K Team //
@@ -22,12 +22,12 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#ifndef _KALKERN_BASE_H
-#include
+#ifndef _KERNEL_H
+#include
#endif
-#ifndef _KALKERN_PWMGNT_H
-#define _KALKERN_PWMGNT_H
+#ifndef _PO_SHTDWN_H
+#define _PO_SHTDWN_H
//----------------------------------------------------------------------------//
diff --git a/kaleid/extras/argv.c b/kaleid/extras/argv.c
index 9af8ff2..1227a03 100644
--- a/kaleid/extras/argv.c
+++ b/kaleid/extras/argv.c
@@ -22,10 +22,8 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
-#include
-#include
-#include
+#include
+#include
//
// Computes argument count, the least N such
@@ -84,7 +82,7 @@ error_t KalCmdLineToArgVecEx(const char *cmdLine,
size_t written = 0;
error_t retcode = EOK;
- KalAlwaysAssert(argv && *argv && cmdLine);
+ assert_always(argv && *argv && cmdLine);
// An ARG_MAX-wide buffer
char *buffer = *argv;
@@ -113,7 +111,7 @@ error_t KalCmdLineToArgVecEx(const char *cmdLine,
// Make sure we don't go beyond ARG_MAX bytes
if (written >= ARG_MAX - (1 + sizeof(char *))) {
// Sanity check
- KalAssert(written == ARG_MAX - (1 + sizeof(char *)));
+ assert(written == ARG_MAX - (1 + sizeof(char *)));
// All we have left is one byte for the null-terminator of the current slot
// and sizeof(char *) bytes for the NULL at the end of argv
diff --git a/kaleid/extras/prog.c b/kaleid/extras/prog.c
deleted file mode 100644
index fb467f8..0000000
--- a/kaleid/extras/prog.c
+++ /dev/null
@@ -1,61 +0,0 @@
-//----------------------------------------------------------------------------//
-// GNU GPL OS/K //
-// //
-// Desc: Program utilities //
-// //
-// //
-// 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 . //
-//----------------------------------------------------------------------------//
-
-#include
-#include
-
-#ifdef _KALEID_KERNEL
-
-const char *__progname = "kaleid-kernel";
-const char *__progvers = "pre-pre-alpha-0.0.1";
-
-#else
-
-const char *__progname = "kaleid-test";
-const char *__progvers = "(n/a)";
-
-#endif
-
-const char *KalGetProgName(void)
-{
- return __progname;
-}
-
-const char *KalGetProgVersion(void)
-{
- return __progvers;
-}
-
-error_t KalSetProgVers(const char *vers)
-{
- (void)vers;
- return ENOSYS;
-}
-
-error_t KalSetProgName(const char *name)
-{
- (void)name;
- return ENOSYS;
-}
-
diff --git a/kaleid/kernel/cpu/cpuid.c b/kaleid/kernel/cpu/cpuid.c
index b012664..1bb3af0 100644
--- a/kaleid/kernel/cpu/cpuid.c
+++ b/kaleid/kernel/cpu/cpuid.c
@@ -22,7 +22,7 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
+#include
/* void CpuGetInfos(void) */
diff --git a/kaleid/kernel/cpu/idt.c b/kaleid/kernel/cpu/idt.c
index 229c911..ce34d50 100644
--- a/kaleid/kernel/cpu/idt.c
+++ b/kaleid/kernel/cpu/idt.c
@@ -22,11 +22,9 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
-#include
-#include
-#include
-#include
+#include
+#include
+#include
IdtEntry_t idt[256] = { 0 };
IdtPtr_t idtPtr;
@@ -80,7 +78,7 @@ error_t IdtRegisterIsr(void (*isr)(ISRFrame_t *regs), uchar isrNo)
uchar n = isrList.n;
int OverWriting = 0;
- KalAssert(idt[0].flags!=0); // IDT initialized
+ assert(idt[0].flags!=0); // IDT initialized
if (n == 0) goto settingUp;
diff --git a/kaleid/kernel/init/info.c b/kaleid/kernel/init/info.c
index 9f80b29..9ea858e 100644
--- a/kaleid/kernel/init/info.c
+++ b/kaleid/kernel/init/info.c
@@ -22,8 +22,8 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
-#include
+#include
+#include
//
// BootInfo_t initialization. It is necessary because grub will potentially be
@@ -36,7 +36,7 @@ void BtInitBootInfo(multiboot_info_t *mbi, void *codeSeg)
extern ulong newStackEnd;
// We need the multiboot structure
- KalAlwaysAssert(mbi);
+ assert_always(mbi);
// Retrieves the bootloader flags to ensure infos are valid
BtLoaderInfo.grubFlags = mbi->flags;
diff --git a/kaleid/kernel/init/init.c b/kaleid/kernel/init/init.c
index 7b2a540..beb1af1 100644
--- a/kaleid/kernel/init/init.c
+++ b/kaleid/kernel/init/init.c
@@ -53,7 +53,6 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic, void *codeSeg)
// Several inits
MmInitHeap();
- PsInitSched();
// Start drivers
IoEnableRtc();
diff --git a/kaleid/kernel/init/init.h b/kaleid/kernel/init/init.h
index fa90d51..3781ecd 100644
--- a/kaleid/kernel/init/init.h
+++ b/kaleid/kernel/init/init.h
@@ -22,15 +22,14 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
// info.c
extern void BtDoSanityChecks(uint mbMagic);
diff --git a/kaleid/kernel/init/ssp.c b/kaleid/kernel/init/ssp.c
index cb6f41c..510d42e 100644
--- a/kaleid/kernel/init/ssp.c
+++ b/kaleid/kernel/init/ssp.c
@@ -22,7 +22,7 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
+#include
ulong __stack_chk_guard = 0x447c0ffe4dbf9e55;
diff --git a/kaleid/kernel/init/table.c b/kaleid/kernel/init/table.c
index 4067e5b..795ebb7 100644
--- a/kaleid/kernel/init/table.c
+++ b/kaleid/kernel/init/table.c
@@ -22,7 +22,7 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
+#include
int KeCPUCount = 1;
CpuCore_t _KeCPUTable[NCPUS] = {0};
diff --git a/kaleid/kernel/io/cursor.c b/kaleid/kernel/io/cursor.c
index 1c402be..24a8693 100644
--- a/kaleid/kernel/io/cursor.c
+++ b/kaleid/kernel/io/cursor.c
@@ -22,9 +22,8 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
-#include
-#include
+#include
+#include
void IoEnableCursor(void)
{
diff --git a/kaleid/kernel/io/keyb.c b/kaleid/kernel/io/keyb.c
index 3ac2884..190edfd 100644
--- a/kaleid/kernel/io/keyb.c
+++ b/kaleid/kernel/io/keyb.c
@@ -22,10 +22,8 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
-#include
-#include
-#include
+#include
+#include
static char EarlyScanCodes[100] = { 0 };
static char Invisible[100] = { 0 };
diff --git a/kaleid/kernel/io/rtc.c b/kaleid/kernel/io/rtc.c
index bed3dd4..1bc000f 100644
--- a/kaleid/kernel/io/rtc.c
+++ b/kaleid/kernel/io/rtc.c
@@ -22,10 +22,8 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
-#include
-#include
-#include
+#include
+#include
static ulong IoRtcTicks = 0;
static char IoTimeChar[22] = { 0 };
diff --git a/kaleid/kernel/io/spkr.c b/kaleid/kernel/io/spkr.c
index 983047a..adbc24c 100644
--- a/kaleid/kernel/io/spkr.c
+++ b/kaleid/kernel/io/spkr.c
@@ -22,9 +22,8 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
-#include
-#include
+#include
+#include
void IoStartSpeaker(int freq)
{
diff --git a/kaleid/kernel/io/vga.c b/kaleid/kernel/io/vga.c
index 91c772c..2edb9cc 100644
--- a/kaleid/kernel/io/vga.c
+++ b/kaleid/kernel/io/vga.c
@@ -22,9 +22,9 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
-#include
-#include
+#include
+#include
+#include
//
// VGA-related macros
diff --git a/kaleid/kernel/ke/log.c b/kaleid/kernel/ke/log.c
index 0058911..b160a47 100644
--- a/kaleid/kernel/ke/log.c
+++ b/kaleid/kernel/ke/log.c
@@ -22,8 +22,8 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
-#include
+#include
+#include
//
// Prints formatted string on standard output
diff --git a/kaleid/kernel/ke/panic.c b/kaleid/kernel/ke/panic.c
index 046b847..1f55c62 100644
--- a/kaleid/kernel/ke/panic.c
+++ b/kaleid/kernel/ke/panic.c
@@ -22,9 +22,8 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
-#include
-#include
+#include
+#include
error_t vbprintf(Buffer_t *buf, const char *fmt, va_list ap);
@@ -52,10 +51,11 @@ noreturn void KeStartPanic(const char *fmt, ...)
KeDisableIRQs();
- PsCurProc = NULL;
+ KeCurProc = NULL;
if (BStdOut == NULL) KeCrashSystem();
- ExAttemptLock(&BStdOut->lock);
+ // XXX
+ // ExAttemptLock(&BStdOut->lock);
if (fmt == NULL) {
fmt = "(no message given)";
diff --git a/kaleid/kernel/mm/gdt.c b/kaleid/kernel/mm/gdt.c
index aeb752c..d576873 100644
--- a/kaleid/kernel/mm/gdt.c
+++ b/kaleid/kernel/mm/gdt.c
@@ -22,7 +22,7 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
+#include
GdtEntry_t gdtEntries[5] = { 0 };
TssEntry_t tssEntry = { 0 };
diff --git a/kaleid/kernel/mm/heap.c b/kaleid/kernel/mm/heap.c
index d29d284..a43f1ac 100644
--- a/kaleid/kernel/mm/heap.c
+++ b/kaleid/kernel/mm/heap.c
@@ -22,10 +22,10 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
-#include
-#include
-#include
+#include
+#include
+#include
+#include
// Start address of the heap
void *_heap_start;
@@ -37,7 +37,7 @@ void *_heap_start;
/*static*/ size_t _heap_max;
// Lock NOT used internally, but used by KalAllocMemory() & co.
-static Lock_t _heap_lock = ExINITLOCK(KLOCK_SPINLOCK);
+static Lock_t _heap_lock = 0;
//
// Initializes heap managment
diff --git a/kaleid/kernel/mm/malloc.c b/kaleid/kernel/mm/malloc.c
index cddcace..cfd25e2 100644
--- a/kaleid/kernel/mm/malloc.c
+++ b/kaleid/kernel/mm/malloc.c
@@ -22,8 +22,8 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
-#include
+#include
+#include
error_t KalAllocMemory(void **ptr, size_t req)
{
diff --git a/kaleid/kernel/mm/map.c b/kaleid/kernel/mm/map.c
index 5bc4c74..2768b5f 100644
--- a/kaleid/kernel/mm/map.c
+++ b/kaleid/kernel/mm/map.c
@@ -22,14 +22,13 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
-#include
-#include
+#include
+#include
+#include
// Initializes globally the memory map
MemoryMap_t memoryMap = { 0 };
-
static error_t InitMemoryMap(void);
//
diff --git a/kaleid/kernel/po/shtdwn.c b/kaleid/kernel/po/shtdwn.c
index a5bc5e5..34354e6 100644
--- a/kaleid/kernel/po/shtdwn.c
+++ b/kaleid/kernel/po/shtdwn.c
@@ -22,9 +22,8 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
-#include
-#include
+#include
+#include
noreturn void PoShutdownQemu(void)
{
diff --git a/kaleid/kernel/ps/sched.c b/kaleid/kernel/ps/sched.c
index 047c728..b6d3957 100644
--- a/kaleid/kernel/ps/sched.c
+++ b/kaleid/kernel/ps/sched.c
@@ -22,10 +22,14 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
-#include
-#include
-#include
+#include
+#include
+#include
+#include
+
+// XXX not ready
+
+#if 0
//
// For test purpose only
@@ -419,3 +423,5 @@ void pstest(void)
}
}
+#endif
+
diff --git a/kaleid/kernel/sh/shcmds.c b/kaleid/kernel/sh/shcmds.c
index c02bdb8..5763f79 100644
--- a/kaleid/kernel/sh/shcmds.c
+++ b/kaleid/kernel/sh/shcmds.c
@@ -197,7 +197,7 @@ extern void pstest(void);
error_t CmdPsTest(int argc, char **argv, char *cmdline)
{
- pstest();
+ // pstest();
return EOK;
}
diff --git a/kaleid/kernel/sh/shell.h b/kaleid/kernel/sh/shell.h
index 1c39878..c0f1151 100644
--- a/kaleid/kernel/sh/shell.h
+++ b/kaleid/kernel/sh/shell.h
@@ -22,17 +22,16 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
-#include
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
extern void IoScrollDown(void);
extern void IoScrollUp(void);
diff --git a/kaleid/libbuf/bclose.c b/kaleid/libbuf/bclose.c
index eedbe0d..21255bd 100644
--- a/kaleid/libbuf/bclose.c
+++ b/kaleid/libbuf/bclose.c
@@ -22,15 +22,14 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
-#include
+#include
//
// Closes a buffer, not flushing unless the proper flag is set
//
error_t BCloseBuf(Buffer_t *buf)
{
- assert(buf && buf->initDone == INITOK);
+ assert_always(buf);
ExAcquireLock(&buf->lock);
if (buf->flags & BF_FONCLOSE) {
@@ -42,7 +41,7 @@ error_t BCloseBuf(Buffer_t *buf)
}
buf->buf = buf->rp = buf->wp = NULL;
- buf->initDone = buf->flags = buf->state = buf->size = 0;
+ buf->flags = buf->state = buf->size = 0;
ExReleaseLock(&buf->lock);
diff --git a/kaleid/libbuf/bflush.c b/kaleid/libbuf/bflush.c
index dd6158f..08c7495 100644
--- a/kaleid/libbuf/bflush.c
+++ b/kaleid/libbuf/bflush.c
@@ -22,8 +22,7 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
-#include
+#include
//
// Erases buf's content
@@ -44,8 +43,6 @@ error_t BFlushBuf(Buffer_t *buf)
{
error_t rc;
- assert(buf && buf->initDone == INITOK);
-
if (!buf) return EINVAL;
if (buf->flags & (BF_EOF|BF_ERR)) {
return EENDF;
diff --git a/kaleid/libbuf/bgetc.c b/kaleid/libbuf/bgetc.c
index 9602b2c..7a3542d 100644
--- a/kaleid/libbuf/bgetc.c
+++ b/kaleid/libbuf/bgetc.c
@@ -22,17 +22,15 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
-#include
+#include
#ifdef _KALEID_KERNEL
-#include
+#include
#endif
error_t BGetFromBuf(Buffer_t *buf, uchar *ch)
{
error_t rc;
- assert(buf && buf->initDone == INITOK);
if (!buf) return EINVAL;
if (buf->flags & BF_TERM) return EBADF;
diff --git a/kaleid/libbuf/bmisc.c b/kaleid/libbuf/bmisc.c
index a05fddb..96f9fa9 100644
--- a/kaleid/libbuf/bmisc.c
+++ b/kaleid/libbuf/bmisc.c
@@ -22,8 +22,7 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
-#include
+#include
// Straightforward functions
int BGetFlags(Buffer_t *buf) { return buf->flags; }
@@ -43,10 +42,10 @@ void BDisaleLineBuffering(Buffer_t *buf)
void BLockBuf(Buffer_t *buf)
{
- assert(buf && buf->initDone == INITOK);
+ assert(buf);
ExAcquireLock(&buf->lock);
}
void BUnlockBuf(Buffer_t *buf) { ExReleaseLock(&buf->lock); }
-bool BTrylockBuf(Buffer_t *buf) { return ExAttemptLock(&buf->lock); }
+//bool BTrylockBuf(Buffer_t *buf) { return ExAttemptLock(&buf->lock); }
diff --git a/kaleid/libbuf/bopen.c b/kaleid/libbuf/bopen.c
index 7c533df..8fa6397 100644
--- a/kaleid/libbuf/bopen.c
+++ b/kaleid/libbuf/bopen.c
@@ -22,9 +22,8 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
-#include
-#include
+#include
+#include
Buffer_t *BStdIn, *BStdOut, *BStdDbg;
@@ -59,7 +58,7 @@ error_t BOpenPureBufEx(Buffer_t **pbuf, char *source, int mode, size_t size,
buf->flags = 0;
}
- ExInitLock(&buf->lock, KLOCK_MUTEX);
+ ExInitLock(&buf->lock);
ExAcquireLock(&buf->lock);
buf->size = size;
@@ -75,7 +74,6 @@ error_t BOpenPureBufEx(Buffer_t **pbuf, char *source, int mode, size_t size,
buf->wp = buf->rp = buf->buf;
buf->flusher = flusher;
- buf->initDone = INITOK;
ExReleaseLock(&buf->lock);
diff --git a/kaleid/libbuf/bprint.c b/kaleid/libbuf/bprint.c
index 1127de2..bd8c9ac 100644
--- a/kaleid/libbuf/bprint.c
+++ b/kaleid/libbuf/bprint.c
@@ -22,8 +22,7 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
-#include
+#include
//
// Prints formatted string on buf according to fmt
@@ -131,8 +130,6 @@ error_t vbprintf(Buffer_t *buf, const char *fmt, va_list ap)
// Base
int base;
- assert(buf && buf->initDone == INITOK);
-
if (!buf || !fmt) return EINVAL;
if (buf->flags & (BF_EOF|BF_ERR)) return EENDF;
if (buf->state != BS_RDWR && buf->state != BS_WRONLY) {
diff --git a/kaleid/libbuf/bputc.c b/kaleid/libbuf/bputc.c
index 344b6bb..059e9f0 100644
--- a/kaleid/libbuf/bputc.c
+++ b/kaleid/libbuf/bputc.c
@@ -22,8 +22,7 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
-#include
+#include
//
// Writes a character on a buffer
@@ -31,7 +30,6 @@
error_t BPutOnBuf(Buffer_t *buf, uchar ch)
{
error_t rc;
- assert(buf && buf->initDone == INITOK);
if (!buf) return EINVAL;
if (buf->state != BS_RDWR && buf->state != BS_WRONLY) {
diff --git a/kaleid/libbuf/bread.c b/kaleid/libbuf/bread.c
index 32299e2..9c383cd 100644
--- a/kaleid/libbuf/bread.c
+++ b/kaleid/libbuf/bread.c
@@ -22,8 +22,8 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
-#include
+#include
+
#if 0
error_t BReadBuf(Buffer_t *buf, uchar *out, size_t n)
{
diff --git a/kaleid/libbuf/bscan.c b/kaleid/libbuf/bscan.c
index 3e17873..e6df43c 100644
--- a/kaleid/libbuf/bscan.c
+++ b/kaleid/libbuf/bscan.c
@@ -22,6 +22,5 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
-#include
+#include
diff --git a/kaleid/libbuf/bscroll.c b/kaleid/libbuf/bscroll.c
index 083bc49..0a50ae8 100644
--- a/kaleid/libbuf/bscroll.c
+++ b/kaleid/libbuf/bscroll.c
@@ -22,8 +22,7 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
-#include
+#include
void BEnableAutoScroll(Buffer_t *buf) { buf->flags |= BF_AUTOSCROLL; }
void BDisableAutoScroll(Buffer_t *buf) { buf->flags &= ~BF_AUTOSCROLL; }
@@ -31,7 +30,6 @@ void BDisableAutoScroll(Buffer_t *buf) { buf->flags &= ~BF_AUTOSCROLL; }
error_t BScrollDownBuf(Buffer_t *buf)
{
error_t rc;
- assert(buf && buf->initDone == INITOK);
if (!buf) return EINVAL;
if (!(buf->flags & BF_TERM)) return EBADF;
diff --git a/kaleid/libbuf/bwrite.c b/kaleid/libbuf/bwrite.c
index 3e17873..e6df43c 100644
--- a/kaleid/libbuf/bwrite.c
+++ b/kaleid/libbuf/bwrite.c
@@ -22,6 +22,5 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
-#include
+#include
diff --git a/kaleid/libc/atoi.c b/kaleid/libc/atoi.c
index 3b1b737..1455d2e 100644
--- a/kaleid/libc/atoi.c
+++ b/kaleid/libc/atoi.c
@@ -22,7 +22,7 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
+#include
// String to integer
// Do not change errno
@@ -34,8 +34,6 @@
return ret; \
}
-
-// ISO C does not allow extra ‘;’ outside of a function
#if defined(_NEED_ATOI)
_ATOI_IMPL(atoi, int, strtol)
#elif defined(_NEED_ATOL)
diff --git a/kaleid/libc/ctype.c b/kaleid/libc/ctype.c
index f35fcc3..4dcf7b2 100644
--- a/kaleid/libc/ctype.c
+++ b/kaleid/libc/ctype.c
@@ -22,7 +22,7 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
+#include
#define SH(x) (1 << x)
diff --git a/include/kaleid.h b/kaleid/libc/errno.c
similarity index 86%
rename from include/kaleid.h
rename to kaleid/libc/errno.c
index 0d953f0..e35315a 100644
--- a/include/kaleid.h
+++ b/kaleid/libc/errno.c
@@ -1,7 +1,7 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
-// Desc: Kaleid main project include file //
+// Desc: strerror() & co. //
// //
// //
// Copyright © 2018-2019 The OS/K Team //
@@ -22,19 +22,21 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#ifndef _KALEID_H
-#define _KALEID_H
+#include
+#undef _ERRNO_H
-//------------------------------------------//
+#define _estart
+#define _eentry(code, desc) [code] = desc,
+#define _eend
-#ifndef _KALBASE_H
-#include
-#endif
+char *__strerror[_EMAX] = {
-#ifndef _KALEXT_H
-#include
-#endif
+#include
-//------------------------------------------//
+};
+
+const char *strerror(error_t code)
+{
+ return __strerror[code];
+}
-#endif
diff --git a/kaleid/libc/itoa.c b/kaleid/libc/itoa.c
index 52d45a8..eb7b3e5 100644
--- a/kaleid/libc/itoa.c
+++ b/kaleid/libc/itoa.c
@@ -7,7 +7,7 @@
// Desc: Conversion utilities - itoa family //
//----------------------------------------------------------------------------//
-#include
+#include
// Digits table for bases <=36 (unused)
#if 0
diff --git a/kaleid/libc/mem.c b/kaleid/libc/mem.c
index 2995dd2..ae8f2d5 100644
--- a/kaleid/libc/mem.c
+++ b/kaleid/libc/mem.c
@@ -22,8 +22,8 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
-#include
+#include
+#include
/* DO NOT compile with strict aliasing on */
@@ -99,6 +99,7 @@ void *memset(void *ptr, int val, size_t bytes)
return ptr;
}
+#if 0
//
// Set "words"-many words starting from ptr to val
//
@@ -135,6 +136,7 @@ void *memsetw(void *ptr, int val, size_t words)
return ptr;
}
+#endif
// Set "dwords"-many dwords starting from ptr to val
// XXX unimplemented
@@ -166,7 +168,7 @@ void *memsetq(void *ptr, long val, size_t qwords)
//
void *memzero(void *ptr, size_t bytes)
{
- return memsetb(ptr, 0, bytes);
+ return memset(ptr, 0, bytes);
}
//
diff --git a/kaleid/libc/rand.c b/kaleid/libc/rand.c
index eb87ceb..4eb2ea3 100644
--- a/kaleid/libc/rand.c
+++ b/kaleid/libc/rand.c
@@ -22,7 +22,7 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
+#include
//
// Seed value
diff --git a/kaleid/libc/sprintf.c b/kaleid/libc/sprintf.c
index 14e111b..3e0f306 100644
--- a/kaleid/libc/sprintf.c
+++ b/kaleid/libc/sprintf.c
@@ -22,7 +22,7 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
+#include
//
// XXX
diff --git a/kaleid/libc/status.c b/kaleid/libc/status.c
deleted file mode 100644
index aa0326d..0000000
--- a/kaleid/libc/status.c
+++ /dev/null
@@ -1,49 +0,0 @@
-//----------------------------------------------------------------------------//
-// GNU GPL OS/K //
-// //
-// Desc: strerror() & co. //
-// //
-// //
-// 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 . //
-//----------------------------------------------------------------------------//
-
-#include
-
-error_t __errno = 0;
-
-/*
-static const char *descriptions[] = {
- [-SUCCESS] = "Success",
- [-FAILED] = "Failed (no precision)",
- [-NOT_PERMITTED] = "Operation not permitted",
- [-ACCESS_DENIED] = "Access denied",
-
- [-BAD_ARGUMENT] = "Bad argument",
- [-BAD_ARG_RANGE] = "Bad argument (not in range)",
- [-BAD_ARG_NULL] = "Bad argument (null pointer)",
-};
-
-const char *describe_status(status_t status)
-{
- (void)descriptions;
- (void)status;
-
- // XXX
- return "";
-}
-*/
diff --git a/kaleid/libc/string.c b/kaleid/libc/string.c
index 71768c7..3d1c340 100644
--- a/kaleid/libc/string.c
+++ b/kaleid/libc/string.c
@@ -22,7 +22,7 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
+#include
//
// Compare two strings
@@ -201,7 +201,7 @@ char *strtok(char *restrict str, const char *restrict delim)
static char *saveptr = NULL;
// Avoid this function if possible
- KalAssert(FALSE);
+ assert(!"Don't use strtok()!");
if (str) saveptr = str;
diff --git a/kaleid/libc/strtol.c b/kaleid/libc/strtol.c
index 91c943d..c98782e 100644
--- a/kaleid/libc/strtol.c
+++ b/kaleid/libc/strtol.c
@@ -22,7 +22,7 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
+#include
long strtol(const char *str, char **endp, int base) {
(void)str;