Header overhaul

This commit is contained in:
Julian Barathieu 2019-05-13 23:22:27 +02:00
parent de2dcafc6c
commit 409e74f934
79 changed files with 727 additions and 1769 deletions

View File

@ -78,13 +78,12 @@ NC='\033[1;37m'
# Lib C sources + libbuf source # Lib C sources + libbuf source
LibCSources = libc/mem.c libc/ctype.c \ LibCSources = libc/mem.c libc/ctype.c \
libc/rand.c libc/sprintf.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 \ libc/strtol.c extras/argv.c \
libbuf/bopen.c libbuf/bputc.c libbuf/bscroll.c \ libbuf/bopen.c libbuf/bputc.c libbuf/bscroll.c \
libbuf/bprint.c libbuf/bgetc.c libbuf/bscan.c \ libbuf/bprint.c libbuf/bgetc.c libbuf/bscan.c \
libbuf/bflush.c libbuf/bwrite.c libbuf/bread.c \ libbuf/bflush.c libbuf/bwrite.c libbuf/bread.c \
libbuf/bmisc.c libbuf/bclose.c \ libbuf/bmisc.c libbuf/bclose.c \
extras/prog.c \
LibCObj=$(patsubst %.c,$(KOBJDIR)/%.o,$(LibCSources)) LibCObj=$(patsubst %.c,$(KOBJDIR)/%.o,$(LibCSources))
LibCDep=$(patsubst %.c,$(KOBJDIR)/%.d,$(LibCSources)) LibCDep=$(patsubst %.c,$(KOBJDIR)/%.d,$(LibCSources))
@ -125,7 +124,7 @@ $(KOBJDIR):
## LIB C MAKEFILE ------------------------------------------------------------ # ## LIB C MAKEFILE ------------------------------------------------------------ #
-include $(LibCDep) -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 $@) @mkdir -p $(shell dirname $@)
@$(KCC) -D_NEED_ATOI $< -o $@.1 @$(KCC) -D_NEED_ATOI $< -o $@.1
@$(KCC) -D_NEED_ATOL $< -o $@.2 @$(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 @rm -f $@.1 $@.2 $@.3 $@.4
@echo ${CL2}[$@] ${CL}Compiled.${CL3} @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 $@) @mkdir -p $(shell dirname $@)
@$(KCC) -D_NEED_ITOA $< -o $@.1 @$(KCC) -D_NEED_ITOA $< -o $@.1
@$(KCC) -D_NEED_LTOA $< -o $@.2 @$(KCC) -D_NEED_LTOA $< -o $@.2

View File

@ -58,8 +58,7 @@
│   │   ├── extras │   │   ├── extras
│   │   │   ├── argv.d │   │   │   ├── argv.d
│   │   │   ├── argv.o │   │   │   ├── argv.o
│   │   │   ├── prog.d │   │   │   └── prog.d
│   │   │   └── prog.o
│   │   ├── kernel │   │   ├── kernel
│   │   │   ├── cpu │   │   │   ├── cpu
│   │   │   │   ├── cpuid.d │   │   │   │   ├── cpuid.d
@ -138,6 +137,8 @@
│   │   ├── atoi.o │   │   ├── atoi.o
│   │   ├── ctype.d │   │   ├── ctype.d
│   │   ├── ctype.o │   │   ├── ctype.o
│   │   ├── errno.d
│   │   ├── errno.o
│   │   ├── itoa.o │   │   ├── itoa.o
│   │   ├── mem.d │   │   ├── mem.d
│   │   ├── mem.o │   │   ├── mem.o
@ -145,55 +146,48 @@
│   │   ├── rand.o │   │   ├── rand.o
│   │   ├── sprintf.d │   │   ├── sprintf.d
│   │   ├── sprintf.o │   │   ├── sprintf.o
│   │   ├── status.d
│   │   ├── status.o
│   │   ├── string.d │   │   ├── string.d
│   │   ├── string.o │   │   ├── string.o
│   │   ├── strtol.d │   │   ├── strtol.d
│   │   └── strtol.o │   │   └── strtol.o
│   ├── grub.log │   ├── grub.log
│   ├── kaleid32_disasm.asm
│   ├── kaleid64_disasm.asm
│   └── kernel.ld │   └── kernel.ld
├── include ├── include
│   ├── base │   ├── ex
│   │   ├── assert.h
│   │   ├── bdefs.h
│   │   ├── crtlib.h
│   │   ├── errno.h
│   │   ├── limits.h
│   │   ├── masks.h
│   │   └── types.h
│   ├── extras
│   │   ├── argv.h │   │   ├── argv.h
│   │   ├── buf.h │   │   ├── lock.h
│   │   ├── list.h │   │   └── malloc.h
│   │   ├── locks.h │   ├── init
│   │   ├── malloc.h
│   │   └── prog.h
│   ├── kernel
│   │   ├── base.h
│   │   ├── boot.h │   │   ├── boot.h
│   │   ├── cpuid.h │   │   └── mboot.h
│   ├── io
│   │   ├── cursor.h │   │   ├── cursor.h
│   │   ├── heap.h │   │   ├── keyb.h
│   │   └── spkr.h
│   ├── ke
│   │   ├── cpuid.h
│   │   ├── idt.h │   │   ├── idt.h
│   │   ├── iomisc.h
│   │   ├── keyboard.h
│   │   ├── mboot.h
│   │   ├── mm.h
│   │   ├── proc.h │   │   ├── proc.h
│   │   ├── pwmgnt.h
│   │   ├── sched.h │   │   ├── sched.h
│   │   ├── speaker.h │   │   ├── spinlock.h
│   │   └── time.h │   │   └── time.h
│   ├── kalbase.h │   ├── lib
│   ├── kaleid.h │   │   ├── buf.h
│   └── kalext.h │   │   └── list.h
│   ├── mm
│   │   ├── heap.h
│   │   └── mm.h
│   ├── po
│   │   └── shtdwn.h
│   ├── ps
│   ├── rtl
│   ├── asm.h
│   ├── errno.h
│   ├── kernel.h
│   └── libc.h
├── kaleid ├── kaleid
│   ├── extras │   ├── extras
│   │   ├── argv.c │   │   └── argv.c
│   │   └── prog.c
│   ├── kernel │   ├── kernel
│   │   ├── cpu │   │   ├── cpu
│   │   │   ├── cpuf.asm │   │   │   ├── cpuf.asm
@ -218,6 +212,7 @@
│   │   │   ├── log.c │   │   │   ├── log.c
│   │   │   └── panic.c │   │   │   └── panic.c
│   │   ├── mm │   │   ├── mm
│   │   │   ├── gdt.asm
│   │   │   ├── gdt.c │   │   │   ├── gdt.c
│   │   │   ├── heap.c │   │   │   ├── heap.c
│   │   │   ├── malloc.c │   │   │   ├── malloc.c
@ -245,20 +240,18 @@
│   └── libc │   └── libc
│   ├── atoi.c │   ├── atoi.c
│   ├── ctype.c │   ├── ctype.c
│   ├── errno.c
│   ├── itoa.c │   ├── itoa.c
│   ├── mem.c │   ├── mem.c
│   ├── rand.c │   ├── rand.c
│   ├── sprintf.c │   ├── sprintf.c
│   ├── status.c
│   ├── string.c │   ├── string.c
│   └── strtol.c │   └── strtol.c
├── AUTHORS ├── AUTHORS
├── ChangeLog ├── ChangeLog
├── COPYING ├── COPYING
├── kaleid32_disasm.asm
├── kaleid64_disasm.asm
├── Makefile ├── Makefile
├── ProjectTree ├── ProjectTree
└── README.md └── README.md
41 directories, 195 files 47 directories, 182 files

View File

@ -1,7 +1,7 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// GNU GPL OS/K // // GNU GPL OS/K //
// // // //
// Desc: Miscenalleous I/O functions and inlines // // Desc: Inline assembly functions //
// // // //
// // // //
// Copyright © 2018-2019 The OS/K Team // // Copyright © 2018-2019 The OS/K Team //
@ -22,12 +22,12 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#ifndef _KALKERN_BASE_H #ifndef _LIBC_H
#include <kernel/base.h> #include <libc.h>
#endif #endif
#ifndef _KALKERN_IOMISC_H #ifndef _ASM_H
#define _KALKERN_IOMISC_H #define _ASM_H
//------------------------------------------// //------------------------------------------//
// IRQ-related stuff // // IRQ-related stuff //
@ -64,7 +64,6 @@ static inline ulong KePauseIRQs(void) {
extern void IoSendEOItoPIC(uchar isr); extern void IoSendEOItoPIC(uchar isr);
extern void IoEnableNMI(void); extern void IoEnableNMI(void);
extern void IoDisableNMI(void); extern void IoDisableNMI(void);
error_t IdtRegisterIsr(void (*isr)(ISRFrame_t *regs), uchar isrNo);
// //
// Restore IRQ flag to its state before KePauseIRQs // 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 // // 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 // Pauses CPU until next interuption
// //
@ -94,28 +98,28 @@ error_t IdtRegisterIsr(void (*isr)(ISRFrame_t *regs), uchar isrNo);
// Ports I/O // // 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)); } { 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)); } { 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)); } { asm volatile ("outl %1, %0" : : "dN" (port), "a" (val)); }
static inline uchar IoReadByteFromPort(port_t port) { static inline uchar IoReadByteFromPort(ushort port) {
uchar ret; uchar ret;
asm volatile ("inb %1, %0" : "=a"(ret) : "Nd"(port)); asm volatile ("inb %1, %0" : "=a"(ret) : "Nd"(port));
return ret; return ret;
} }
static inline ushort IoReadWordFromPort(port_t port) { static inline ushort IoReadWordFromPort(ushort port) {
ushort ret; ushort ret;
asm volatile ("inw %1, %0" : "=a"(ret) : "Nd"(port)); asm volatile ("inw %1, %0" : "=a"(ret) : "Nd"(port));
return ret; return ret;
} }
static inline ushort IoReadDWordFromPort(port_t port) { static inline ushort IoReadDWordFromPort(ushort port) {
uint ret; uint ret;
asm volatile ("inl %1, %0" : "=a"(ret) : "Nd"(port)); asm volatile ("inl %1, %0" : "=a"(ret) : "Nd"(port));
return ret; return ret;

View File

@ -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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//
#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

View File

@ -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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//
#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

View File

@ -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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//
#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

View File

@ -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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//
#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

View File

@ -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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//
#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

View File

@ -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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//
#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

View File

@ -22,65 +22,41 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#ifndef _KALBASE_ERRNO_H #ifndef _ERRNO_H
#define _KALBASE_ERRNO_H #define _ERRNO_H
//------------------------------------------// //----------------------------------------------------------------------------//
// Everything went fine #ifndef _eentry
#define EOK 0 #define _estart enum {
#define _eentry(code, desc) code,
#define _eentry(code, desc) code,
#define _eend _EMAX };
#endif
// Operation not permitted _estart
#define EPERM 1 _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 #undef _estart
#define ENOENT 2 #undef _eentry
#undef _eend
// 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
//------------------------------------------//
#endif #endif

View File

@ -22,8 +22,8 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#ifndef _KALBASE_H #ifndef _LIBC_H
#include <kalbase.h> #include <libc.h>
#endif #endif
#ifndef _KALEXTRAS_ARGV_H #ifndef _KALEXTRAS_ARGV_H

13
include/ex/lock.h Normal file
View File

@ -0,0 +1,13 @@
#ifndef _LIBC_H
#include <libc.h>
#endif
// Temporary fix
#include <ke/spinlock.h>
typedef Spinlock_t Lock_t;
#define ExInitLock KeInitSpinlock
#define ExAcquireLock KeAcquireSpinlock
#define ExReleaseLock KeReleaseSpinlock

View File

@ -22,12 +22,12 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#ifndef _KALBASE_H #ifndef _LIBC_H
#include <kalbase.h> #include <libc.h>
#endif #endif
#ifndef _KALEXTRAS_MALLOC_H #ifndef _EX_MALLOC_H
#define _KALEXTRAS_MALLOC_H #define _EX_MALLOC_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

View File

@ -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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//
#ifndef _KALBASE_H
#include <kalbase.h>
#endif
#ifdef _KALEID_KERNEL
#ifndef _KALKERN_SCHED_H
#include <kernel/sched.h>
#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

View File

@ -22,12 +22,12 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#ifndef _KALKERN_BASE_H #ifndef _KERNEL_H
#include <kernel/base.h> #include <kernel.h>
#endif #endif
#ifndef _KALKERN_BOOT_H #ifndef _INIT_BOOT_H
#define _KALKERN_BOOT_H #define _INIT_BOOT_H
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//

View File

@ -23,8 +23,8 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#ifndef _KALKERN_BASE_H #ifndef _KERNEL_H
#include <kernel/base.h> #include <kernel.h>
#endif #endif
#ifndef MULTIBOOT_HEADER #ifndef MULTIBOOT_HEADER

View File

@ -22,18 +22,18 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#ifndef _KALKERN_BASE_H #ifndef _KERNEL_H
#include <kernel/base.h> #include <kernel.h>
#endif #endif
#ifndef _KALKERN_CURSOR_H #ifndef _IO_CURSOR_H
#define _KALKERN_CURSOR_H #define _IO_CURSOR_H
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
void IoEnableCursor(void); void IoEnableCursor(void);
void IoDisableCursor(void); void IoDisableCursor(void);
void IoUpdateCursor(int x, int y); void IoUpdateCursor(int, int);
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//

View File

@ -22,18 +22,17 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#ifndef _KALKERN_BASE_H #ifndef _KERNEL_H
#include <kernel/base.h> #include <kernel.h>
#endif #endif
#ifndef _KALKERN_KEYB_H #ifndef _IO_KEYB_H
#define _KALKERN_KEYB_H #define _IO_KEYB_H
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
void IoEnableKeyb(); void IoEnableKeyb();
void IoChangeCodePage(char *CodePage); void IoChangeCodePage(char *);
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
@ -45,7 +44,6 @@ void IoChangeCodePage(char *CodePage);
#define KEY_DC3 19 #define KEY_DC3 19
#define KEY_DC4 20 #define KEY_DC4 20
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#endif #endif

View File

@ -22,16 +22,16 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#ifndef _KALKERN_BASE_H #ifndef _KERNEL_H
#include <kernel/base.h> #include <kernel.h>
#endif #endif
#ifndef _KALKERN_SPEAKER_H #ifndef _IO_SPKR_H
#define _KALKERN_SPEAKER_H #define _IO_SPKR_H
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
void IoStartSpeaker(int freq); void IoStartSpeaker(int);
void IoQuietSpeaker(void); void IoQuietSpeaker(void);
void IoDoBeep(void); void IoDoBeep(void);
void IoDoTone(uint tone, uint time); void IoDoTone(uint tone, uint time);

View File

@ -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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//
#ifndef _KALBASE_H
#define _KALBASE_H
//------------------------------------------//
#ifndef _OSK_SOURCE
#ifdef _KALEID_KERNEL
#define _OSK_SOURCE 1
#endif
#endif
//------------------------------------------//
#ifndef _KALBASE_BDEFS_H
#include <base/bdefs.h>
#endif
#ifndef _KALBASE_ERRNO_H
#include <base/errno.h>
#endif
#ifndef _KALBASE_TYPES_H
#include <base/types.h>
#endif
#ifndef _KALBASE_LIMITS_H
#include <base/limits.h>
#endif
#ifndef _KALBASE_ASSERT_H
#include <base/assert.h>
#endif
#ifndef _KALBASE_CRTLIB_H
#include <base/crtlib.h>
#endif
//------------------------------------------//
#endif

View File

@ -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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//
#ifndef _KALBASE_H
#include <kalbase.h>
#endif
#ifndef _KALEXT_H
#define _KALEXT_H
//------------------------------------------//
#ifndef _KALEXTRAS_LOCKS_H
#include <extras/locks.h>
#endif
#ifndef _KALEXTRAS_PROG_H
#include <extras/prog.h>
#endif
#ifndef _KALEXTRAS_ARGV_H
#include <extras/argv.h>
#endif
#ifndef _KALEID_KERNEL
#ifndef _KALEXTRAS_LIST_H
#include <extras/list.h>
#endif
#endif
//------------------------------------------//
#endif

View File

@ -22,8 +22,8 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#ifndef _KALKERN_BASE_H #ifndef _KERNEL_H
#include <kernel/base.h> #include <kernel.h>
#endif #endif
#ifndef _KALKERN_CPUID_H #ifndef _KALKERN_CPUID_H

View File

@ -22,8 +22,8 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#ifndef _KALKERN_BASE_H #ifndef _KERNEL_H
#include <kernel/base.h> #include <kernel.h>
#endif #endif
#ifndef _KALKERN_IDT_H #ifndef _KALKERN_IDT_H

View File

@ -22,8 +22,8 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#ifndef _KALKERN_BASE_H #ifndef _KERNEL_H
#include <kernel/base.h> #include <kernel.h>
#endif #endif
#ifndef _KALKERN_PROC_H #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 #endif

View File

@ -22,8 +22,8 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#ifndef _KALKERN_BASE_H #ifndef _KERNEL_H
#include <kernel/base.h> #include <kernel.h>
#endif #endif
#ifndef _KALKERN_SCHED_H #ifndef _KALKERN_SCHED_H

View File

@ -1,7 +1,7 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// GNU GPL OS/K // // GNU GPL OS/K //
// // // //
// Desc: Program utilities // // Desc: Spinlocks //
// // // //
// // // //
// Copyright © 2018-2019 The OS/K Team // // Copyright © 2018-2019 The OS/K Team //
@ -22,29 +22,48 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#ifndef _KALBASE_H #ifndef _KERNEL_H
#include <kalbase.h> #include <kernel.h>
#endif #endif
#ifndef _KALEXTRAS_PROG_H #ifndef _KALKERN_SPINLOCK_H
#define _KALEXTRAS_PROG_H #define _KALKERN_SPINLOCK_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
//------------------------------------------// //----------------------------------------------------------------------------//
extern const char *__progname; static inline void KeInitSpinlock(Spinlock_t *lock) { *lock = 0; }
extern const char *__progvers;
//------------------------------------------// 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); static inline void KeAcquireSpinlock(Spinlock_t *lock)
const char *KalGetProgVersion(void); {
while (1) {
if (!atomic_xchg_64(lock, KeCurThread)) return;
while (*lock) __relax_cpu();
}
}
error_t KalSetProgVers(const char *); static inline void KeReleaseSpinlock(Spinlock_t *lock)
error_t KalSetProgName(const char *); {
atomic_barrier();
assert(*lock == (ulong)KeCurThread);
*lock = 0;
}
static inline ulong KeTestSpinLock(Spinlock_t *lock)
{
return (ulong)atomic_xchg_64(lock, KeCurThread);
}
//------------------------------------------// //------------------------------------------//

View File

@ -22,8 +22,8 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#ifndef _KALKERN_BASE_H #ifndef _KERNEL_H
#include <kernel/base.h> #include <kernel.h>
#endif #endif
#ifndef _KALKERN_TIME_H #ifndef _KALKERN_TIME_H

View File

@ -22,20 +22,20 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#ifndef _KALBASE_H #ifndef _LIBC_H
#include <kalbase.h> #include <libc.h>
#endif #endif
#ifdef __cplusplus #ifndef _KERNEL_H
#error "Kaleid's kernel won't compile in C++" #define _KERNEL_H
#endif
#ifndef _KALKERN_BASE_H
#define _KALKERN_BASE_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 Buffer_t Buffer_t;
typedef struct ListHead_t ListHead_t; typedef struct ListHead_t ListHead_t;
typedef struct ListNode_t ListNode_t; typedef struct ListNode_t ListNode_t;
@ -124,6 +124,7 @@ struct ISRFrame_t {
ulong ss; ulong ss;
} __attribute__((__packed__)); } __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 <asm.h>
//----------------------------------------------------------------------------//
#define DEC_PER_CPU(pref, name, field, type) \ #define DEC_PER_CPU(pref, name, field, type) \
static inline type pref##Get##name() { return KeGetCurCPU()->field; } \ static inline type pref##Get##name() { return KeGetCurCPU()->field; } \
static inline void _##pref##Set##name(type __val) \ static inline void _##pref##Set##name(type __val) \
{ KeGetCurCPU()->field = __val; } { KeGetCurCPU()->field = __val; }
#define BARRIER() \
do { \
asm volatile("": : :"memory"); \
__sync_synchronize(); \
} while(0)
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#ifdef NDEBUG #ifdef NDEBUG

View File

@ -22,12 +22,12 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#ifndef _KALEXTRAS_LOCKS_H #ifndef _EX_LOCK_H
#include <extras/locks.h> #include <ex/lock.h>
#endif #endif
#ifndef _KALEXTRAS_BUF_H #ifndef _LIB_BUF_H
#define _KALEXTRAS_BUF_H #define _LIB_BUF_H
// //
// Buffer flags // Buffer flags
@ -77,7 +77,6 @@ typedef error_t (*BFlusher_t)(Buffer_t *);
struct Buffer_t struct Buffer_t
{ {
uint initDone;
Lock_t lock; Lock_t lock;
int flags; // Buffer flags int flags; // Buffer flags
@ -139,7 +138,7 @@ int BGetState(Buffer_t *);
error_t BFlushBuf(Buffer_t *); error_t BFlushBuf(Buffer_t *);
error_t BPutOnBuf(Buffer_t *, uchar); 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 BPrintOnBuf(Buffer_t *, const char *, ...);
error_t BPrintOnBufV(Buffer_t *, const char *, va_list); error_t BPrintOnBufV(Buffer_t *, const char *, va_list);

View File

@ -22,20 +22,12 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#ifndef _KALBASE_H #ifndef _LIBC_H
#include <kalbase.h> #include <libc.h>
#endif #endif
#ifndef _KALEXTRAS_MALLOC_H #ifndef _LIB_LIST_H
#include <extras/malloc.h> #define _LIB_LIST_H
#endif
#ifndef _KALEXTRAS_LOCKS_H
#include <extras/locks.h>
#endif
#ifndef _KALEXTRAS_LIST_H
#define _KALEXTRAS_LIST_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -48,7 +40,6 @@ typedef struct ListNode_t ListNode_t;
struct ListHead_t struct ListHead_t
{ {
Lock_t *lock;
ulong length; ulong length;
ListNode_t *first; ListNode_t *first;
ListNode_t *last; ListNode_t *last;
@ -68,7 +59,7 @@ struct ListNode_t
// Create a list head with an extern lock // Create a list head with an extern lock
// //
static inline ListHead_t static inline ListHead_t
*ExCreateListHeadWithLock(Lock_t *lock) *ExCreateListHead(Lock_t *lock)
{ {
ListHead_t *head = malloc(sizeof(ListHead_t)); ListHead_t *head = malloc(sizeof(ListHead_t));
@ -77,21 +68,9 @@ static inline ListHead_t
head->first = head->last = NULL; head->first = head->last = NULL;
head->length = 0; head->length = 0;
head->lock = lock;
return head; return head;
} }
//
// Create a list head
//
static inline ListHead_t
*ExCreateListHead(void)
{
return ExCreateListHeadWithLock(NULL);
}
//
// Create a node // Create a node
// //
static inline ListNode_t static inline ListNode_t
@ -244,7 +223,7 @@ static inline ListHead_t
leave: leave:
head->length--; head->length--;
KalFreeMemory(node); free(node);
return head; return head;
} }

396
include/libc.h Normal file
View File

@ -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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//
#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 <errno.h>
//----------------------------------------------------------------------------//
#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

View File

@ -1,7 +1,7 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// GNU GPL OS/K // // GNU GPL OS/K //
// // // //
// Desc: Memory related functions // // Desc: Heap management functions //
// // // //
// // // //
// Copyright © 2018-2019 The OS/K Team // // Copyright © 2018-2019 The OS/K Team //
@ -22,12 +22,12 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#ifndef _KALKERN_BASE_H #ifndef _KERNEL_H
#include <kernel/base.h> #include <kernel.h>
#endif #endif
#ifndef _KALKERN_HEAP_H #ifndef _MM_HEAP_H
#define _KALKERN_HEAP_H #define _MM_HEAP_H
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
@ -57,6 +57,7 @@ error_t MmGrowHeap(size_t);
error_t MmShrinkHeap(size_t); error_t MmShrinkHeap(size_t);
void MmIsHeapSmashed(void); void MmIsHeapSmashed(void);
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#endif #endif

View File

@ -1,7 +1,7 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// GNU GPL OS/K // // GNU GPL OS/K //
// // // //
// Desc: Memory related functions // // Desc: Memory manager functions //
// // // //
// // // //
// Copyright © 2018-2019 The OS/K Team // // Copyright © 2018-2019 The OS/K Team //
@ -22,12 +22,12 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#ifndef _KALKERN_BASE_H #ifndef _KERNEL_H
#include <kernel/base.h> #include <kernel.h>
#endif #endif
#ifndef _KALKERN_MM_H #ifndef _MM_MM_H
#define _KALKERN_MM_H #define _MM_MM_H
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//

View File

@ -1,7 +1,7 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// GNU GPL OS/K // // GNU GPL OS/K //
// // // //
// Desc: Power Management related functions // // Desc: Shutdown facilities //
// // // //
// // // //
// Copyright © 2018-2019 The OS/K Team // // Copyright © 2018-2019 The OS/K Team //
@ -22,12 +22,12 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#ifndef _KALKERN_BASE_H #ifndef _KERNEL_H
#include <kernel/base.h> #include <kernel.h>
#endif #endif
#ifndef _KALKERN_PWMGNT_H #ifndef _PO_SHTDWN_H
#define _KALKERN_PWMGNT_H #define _PO_SHTDWN_H
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//

View File

@ -22,10 +22,8 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kalbase.h> #include <ex/argv.h>
#include <extras/prog.h> #include <ex/malloc.h>
#include <extras/argv.h>
#include <extras/malloc.h>
// //
// Computes argument count, the least N such // Computes argument count, the least N such
@ -84,7 +82,7 @@ error_t KalCmdLineToArgVecEx(const char *cmdLine,
size_t written = 0; size_t written = 0;
error_t retcode = EOK; error_t retcode = EOK;
KalAlwaysAssert(argv && *argv && cmdLine); assert_always(argv && *argv && cmdLine);
// An ARG_MAX-wide buffer // An ARG_MAX-wide buffer
char *buffer = *argv; char *buffer = *argv;
@ -113,7 +111,7 @@ error_t KalCmdLineToArgVecEx(const char *cmdLine,
// Make sure we don't go beyond ARG_MAX bytes // Make sure we don't go beyond ARG_MAX bytes
if (written >= ARG_MAX - (1 + sizeof(char *))) { if (written >= ARG_MAX - (1 + sizeof(char *))) {
// Sanity check // 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 // 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 // and sizeof(char *) bytes for the NULL at the end of argv

View File

@ -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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//
#include <kalbase.h>
#include <extras/prog.h>
#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;
}

View File

@ -22,7 +22,7 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kernel/cpuid.h> #include <ke/cpuid.h>
/* void CpuGetInfos(void) */ /* void CpuGetInfos(void) */

View File

@ -22,11 +22,9 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kernel/base.h> #include <lib/buf.h>
#include <kernel/idt.h> #include <init/boot.h>
#include <kernel/boot.h> #include <ke/idt.h>
#include <kernel/iomisc.h>
#include <extras/buf.h>
IdtEntry_t idt[256] = { 0 }; IdtEntry_t idt[256] = { 0 };
IdtPtr_t idtPtr; IdtPtr_t idtPtr;
@ -80,7 +78,7 @@ error_t IdtRegisterIsr(void (*isr)(ISRFrame_t *regs), uchar isrNo)
uchar n = isrList.n; uchar n = isrList.n;
int OverWriting = 0; int OverWriting = 0;
KalAssert(idt[0].flags!=0); // IDT initialized assert(idt[0].flags!=0); // IDT initialized
if (n == 0) goto settingUp; if (n == 0) goto settingUp;

View File

@ -22,8 +22,8 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kernel/boot.h> #include <init/boot.h>
#include <kernel/mboot.h> #include <init/mboot.h>
// //
// BootInfo_t initialization. It is necessary because grub will potentially be // 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; extern ulong newStackEnd;
// We need the multiboot structure // We need the multiboot structure
KalAlwaysAssert(mbi); assert_always(mbi);
// Retrieves the bootloader flags to ensure infos are valid // Retrieves the bootloader flags to ensure infos are valid
BtLoaderInfo.grubFlags = mbi->flags; BtLoaderInfo.grubFlags = mbi->flags;

View File

@ -53,7 +53,6 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic, void *codeSeg)
// Several inits // Several inits
MmInitHeap(); MmInitHeap();
PsInitSched();
// Start drivers // Start drivers
IoEnableRtc(); IoEnableRtc();

View File

@ -22,15 +22,14 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <extras/buf.h> #include <lib/buf.h>
#include <kernel/iomisc.h> #include <io/cursor.h>
#include <kernel/cursor.h> #include <init/mboot.h>
#include <kernel/mboot.h> #include <mm/heap.h>
#include <kernel/heap.h> #include <mm/mm.h>
#include <kernel/mm.h> #include <ke/time.h>
#include <kernel/time.h> #include <io/spkr.h>
#include <kernel/speaker.h> #include <po/shtdwn.h>
#include <kernel/pwmgnt.h>
// info.c // info.c
extern void BtDoSanityChecks(uint mbMagic); extern void BtDoSanityChecks(uint mbMagic);

View File

@ -22,7 +22,7 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kernel/base.h> #include <kernel.h>
ulong __stack_chk_guard = 0x447c0ffe4dbf9e55; ulong __stack_chk_guard = 0x447c0ffe4dbf9e55;

View File

@ -22,7 +22,7 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kernel/boot.h> #include <init/boot.h>
int KeCPUCount = 1; int KeCPUCount = 1;
CpuCore_t _KeCPUTable[NCPUS] = {0}; CpuCore_t _KeCPUTable[NCPUS] = {0};

View File

@ -22,9 +22,8 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kernel/boot.h> #include <init/boot.h>
#include <kernel/cursor.h> #include <io/cursor.h>
#include <kernel/iomisc.h>
void IoEnableCursor(void) void IoEnableCursor(void)
{ {

View File

@ -22,10 +22,8 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kernel/base.h> #include <lib/buf.h>
#include <kernel/iomisc.h> #include <io/keyb.h>
#include <extras/buf.h>
#include <kernel/keyboard.h>
static char EarlyScanCodes[100] = { 0 }; static char EarlyScanCodes[100] = { 0 };
static char Invisible[100] = { 0 }; static char Invisible[100] = { 0 };

View File

@ -22,10 +22,8 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kernel/base.h> #include <lib/buf.h>
#include <kernel/iomisc.h> #include <ke/time.h>
#include <extras/buf.h>
#include <kernel/time.h>
static ulong IoRtcTicks = 0; static ulong IoRtcTicks = 0;
static char IoTimeChar[22] = { 0 }; static char IoTimeChar[22] = { 0 };

View File

@ -22,9 +22,8 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kernel/speaker.h> #include <io/spkr.h>
#include <kernel/iomisc.h> #include <ke/time.h>
#include <kernel/time.h>
void IoStartSpeaker(int freq) void IoStartSpeaker(int freq)
{ {

View File

@ -22,9 +22,9 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <extras/buf.h> #include <lib/buf.h>
#include <kernel/boot.h> #include <init/boot.h>
#include <kernel/cursor.h> #include <io/cursor.h>
// //
// VGA-related macros // VGA-related macros

View File

@ -22,8 +22,8 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <extras/buf.h> #include <lib/buf.h>
#include <kernel/base.h> #include <kernel.h>
// //
// Prints formatted string on standard output // Prints formatted string on standard output

View File

@ -22,9 +22,8 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <extras/buf.h> #include <lib/buf.h>
#include <kernel/proc.h> #include <ke/proc.h>
#include <kernel/iomisc.h>
error_t vbprintf(Buffer_t *buf, const char *fmt, va_list ap); error_t vbprintf(Buffer_t *buf, const char *fmt, va_list ap);
@ -52,10 +51,11 @@ noreturn void KeStartPanic(const char *fmt, ...)
KeDisableIRQs(); KeDisableIRQs();
PsCurProc = NULL; KeCurProc = NULL;
if (BStdOut == NULL) KeCrashSystem(); if (BStdOut == NULL) KeCrashSystem();
ExAttemptLock(&BStdOut->lock); // XXX
// ExAttemptLock(&BStdOut->lock);
if (fmt == NULL) { if (fmt == NULL) {
fmt = "(no message given)"; fmt = "(no message given)";

View File

@ -22,7 +22,7 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kernel/mm.h> #include <mm/mm.h>
GdtEntry_t gdtEntries[5] = { 0 }; GdtEntry_t gdtEntries[5] = { 0 };
TssEntry_t tssEntry = { 0 }; TssEntry_t tssEntry = { 0 };

View File

@ -22,10 +22,10 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kernel/mm.h> #include <mm/mm.h>
#include <kernel/heap.h> #include <mm/heap.h>
#include <extras/locks.h> #include <ex/lock.h>
#include <kernel/boot.h> #include <init/boot.h>
// Start address of the heap // Start address of the heap
void *_heap_start; void *_heap_start;
@ -37,7 +37,7 @@ void *_heap_start;
/*static*/ size_t _heap_max; /*static*/ size_t _heap_max;
// Lock NOT used internally, but used by KalAllocMemory() & co. // 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 // Initializes heap managment

View File

@ -22,8 +22,8 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kernel/heap.h> #include <mm/heap.h>
#include <extras/malloc.h> #include <ex/malloc.h>
error_t KalAllocMemory(void **ptr, size_t req) error_t KalAllocMemory(void **ptr, size_t req)
{ {

View File

@ -22,14 +22,13 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kernel/mm.h> #include <mm/mm.h>
#include <kernel/boot.h> #include <init/boot.h>
#include <kernel/mboot.h> #include <init/mboot.h>
// Initializes globally the memory map // Initializes globally the memory map
MemoryMap_t memoryMap = { 0 }; MemoryMap_t memoryMap = { 0 };
static error_t InitMemoryMap(void); static error_t InitMemoryMap(void);
// //

View File

@ -22,9 +22,8 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kernel/base.h> #include <ke/time.h>
#include <kernel/iomisc.h> #include <po/shtdwn.h>
#include <kernel/time.h>
noreturn void PoShutdownQemu(void) noreturn void PoShutdownQemu(void)
{ {

View File

@ -22,10 +22,14 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <extras/list.h> #include <asm.h>
#include <kernel/proc.h> #include <ke/proc.h>
#include <kernel/sched.h> #include <ke/sched.h>
#include <kernel/iomisc.h> #include <lib/list.h>
// XXX not ready
#if 0
// //
// For test purpose only // For test purpose only
@ -419,3 +423,5 @@ void pstest(void)
} }
} }
#endif

View File

@ -197,7 +197,7 @@ extern void pstest(void);
error_t CmdPsTest(int argc, char **argv, char *cmdline) error_t CmdPsTest(int argc, char **argv, char *cmdline)
{ {
pstest(); // pstest();
return EOK; return EOK;
} }

View File

@ -22,17 +22,16 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <extras/buf.h> #include <asm.h>
#include <extras/argv.h> #include <lib/buf.h>
#include <ex/argv.h>
#include <kernel/mm.h> #include <init/boot.h>
#include <kernel/boot.h> #include <ke/time.h>
#include <kernel/heap.h> #include <mm/mm.h>
#include <kernel/time.h> #include <mm/heap.h>
#include <kernel/speaker.h> #include <io/spkr.h>
#include <kernel/iomisc.h> #include <io/keyb.h>
#include <kernel/pwmgnt.h> #include <po/shtdwn.h>
#include <kernel/keyboard.h>
extern void IoScrollDown(void); extern void IoScrollDown(void);
extern void IoScrollUp(void); extern void IoScrollUp(void);

View File

@ -22,15 +22,14 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <extras/buf.h> #include <lib/buf.h>
#include <extras/locks.h>
// //
// Closes a buffer, not flushing unless the proper flag is set // Closes a buffer, not flushing unless the proper flag is set
// //
error_t BCloseBuf(Buffer_t *buf) error_t BCloseBuf(Buffer_t *buf)
{ {
assert(buf && buf->initDone == INITOK); assert_always(buf);
ExAcquireLock(&buf->lock); ExAcquireLock(&buf->lock);
if (buf->flags & BF_FONCLOSE) { if (buf->flags & BF_FONCLOSE) {
@ -42,7 +41,7 @@ error_t BCloseBuf(Buffer_t *buf)
} }
buf->buf = buf->rp = buf->wp = NULL; 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); ExReleaseLock(&buf->lock);

View File

@ -22,8 +22,7 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <extras/buf.h> #include <lib/buf.h>
#include <extras/locks.h>
// //
// Erases buf's content // Erases buf's content
@ -44,8 +43,6 @@ error_t BFlushBuf(Buffer_t *buf)
{ {
error_t rc; error_t rc;
assert(buf && buf->initDone == INITOK);
if (!buf) return EINVAL; if (!buf) return EINVAL;
if (buf->flags & (BF_EOF|BF_ERR)) { if (buf->flags & (BF_EOF|BF_ERR)) {
return EENDF; return EENDF;

View File

@ -22,17 +22,15 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <extras/buf.h> #include <lib/buf.h>
#include <extras/locks.h>
#ifdef _KALEID_KERNEL #ifdef _KALEID_KERNEL
#include <kernel/time.h> #include <ke/time.h>
#endif #endif
error_t BGetFromBuf(Buffer_t *buf, uchar *ch) error_t BGetFromBuf(Buffer_t *buf, uchar *ch)
{ {
error_t rc; error_t rc;
assert(buf && buf->initDone == INITOK);
if (!buf) return EINVAL; if (!buf) return EINVAL;
if (buf->flags & BF_TERM) return EBADF; if (buf->flags & BF_TERM) return EBADF;

View File

@ -22,8 +22,7 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <extras/buf.h> #include <lib/buf.h>
#include <extras/locks.h>
// Straightforward functions // Straightforward functions
int BGetFlags(Buffer_t *buf) { return buf->flags; } int BGetFlags(Buffer_t *buf) { return buf->flags; }
@ -43,10 +42,10 @@ void BDisaleLineBuffering(Buffer_t *buf)
void BLockBuf(Buffer_t *buf) void BLockBuf(Buffer_t *buf)
{ {
assert(buf && buf->initDone == INITOK); assert(buf);
ExAcquireLock(&buf->lock); ExAcquireLock(&buf->lock);
} }
void BUnlockBuf(Buffer_t *buf) { ExReleaseLock(&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); }

View File

@ -22,9 +22,8 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <extras/buf.h> #include <lib/buf.h>
#include <extras/locks.h> #include <ex/malloc.h>
#include <extras/malloc.h>
Buffer_t *BStdIn, *BStdOut, *BStdDbg; 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; buf->flags = 0;
} }
ExInitLock(&buf->lock, KLOCK_MUTEX); ExInitLock(&buf->lock);
ExAcquireLock(&buf->lock); ExAcquireLock(&buf->lock);
buf->size = size; 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->wp = buf->rp = buf->buf;
buf->flusher = flusher; buf->flusher = flusher;
buf->initDone = INITOK;
ExReleaseLock(&buf->lock); ExReleaseLock(&buf->lock);

View File

@ -22,8 +22,7 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <extras/buf.h> #include <lib/buf.h>
#include <extras/locks.h>
// //
// Prints formatted string on buf according to fmt // 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 // Base
int base; int base;
assert(buf && buf->initDone == INITOK);
if (!buf || !fmt) return EINVAL; if (!buf || !fmt) return EINVAL;
if (buf->flags & (BF_EOF|BF_ERR)) return EENDF; if (buf->flags & (BF_EOF|BF_ERR)) return EENDF;
if (buf->state != BS_RDWR && buf->state != BS_WRONLY) { if (buf->state != BS_RDWR && buf->state != BS_WRONLY) {

View File

@ -22,8 +22,7 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <extras/buf.h> #include <lib/buf.h>
#include <extras/locks.h>
// //
// Writes a character on a buffer // Writes a character on a buffer
@ -31,7 +30,6 @@
error_t BPutOnBuf(Buffer_t *buf, uchar ch) error_t BPutOnBuf(Buffer_t *buf, uchar ch)
{ {
error_t rc; error_t rc;
assert(buf && buf->initDone == INITOK);
if (!buf) return EINVAL; if (!buf) return EINVAL;
if (buf->state != BS_RDWR && buf->state != BS_WRONLY) { if (buf->state != BS_RDWR && buf->state != BS_WRONLY) {

View File

@ -22,8 +22,8 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <extras/buf.h> #include <lib/buf.h>
#include <extras/locks.h>
#if 0 #if 0
error_t BReadBuf(Buffer_t *buf, uchar *out, size_t n) error_t BReadBuf(Buffer_t *buf, uchar *out, size_t n)
{ {

View File

@ -22,6 +22,5 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <extras/buf.h> #include <lib/buf.h>
#include <extras/locks.h>

View File

@ -22,8 +22,7 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <extras/buf.h> #include <lib/buf.h>
#include <extras/locks.h>
void BEnableAutoScroll(Buffer_t *buf) { buf->flags |= BF_AUTOSCROLL; } void BEnableAutoScroll(Buffer_t *buf) { buf->flags |= BF_AUTOSCROLL; }
void BDisableAutoScroll(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 BScrollDownBuf(Buffer_t *buf)
{ {
error_t rc; error_t rc;
assert(buf && buf->initDone == INITOK);
if (!buf) return EINVAL; if (!buf) return EINVAL;
if (!(buf->flags & BF_TERM)) return EBADF; if (!(buf->flags & BF_TERM)) return EBADF;

View File

@ -22,6 +22,5 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <extras/buf.h> #include <lib/buf.h>
#include <extras/locks.h>

View File

@ -22,7 +22,7 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kalbase.h> #include <libc.h>
// String to integer // String to integer
// Do not change errno // Do not change errno
@ -34,8 +34,6 @@
return ret; \ return ret; \
} }
// ISO C does not allow extra ; outside of a function
#if defined(_NEED_ATOI) #if defined(_NEED_ATOI)
_ATOI_IMPL(atoi, int, strtol) _ATOI_IMPL(atoi, int, strtol)
#elif defined(_NEED_ATOL) #elif defined(_NEED_ATOL)

View File

@ -22,7 +22,7 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kalbase.h> #include <libc.h>
#define SH(x) (1 << x) #define SH(x) (1 << x)

View File

@ -1,7 +1,7 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// GNU GPL OS/K // // GNU GPL OS/K //
// // // //
// Desc: Kaleid main project include file // // Desc: strerror() & co. //
// // // //
// // // //
// Copyright © 2018-2019 The OS/K Team // // Copyright © 2018-2019 The OS/K Team //
@ -22,19 +22,21 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#ifndef _KALEID_H #include <libc.h>
#define _KALEID_H #undef _ERRNO_H
//------------------------------------------// #define _estart
#define _eentry(code, desc) [code] = desc,
#define _eend
#ifndef _KALBASE_H char *__strerror[_EMAX] = {
#include <kalbase.h>
#endif
#ifndef _KALEXT_H #include <errno.h>
#include <kalext.h>
#endif
//------------------------------------------// };
const char *strerror(error_t code)
{
return __strerror[code];
}
#endif

View File

@ -7,7 +7,7 @@
// Desc: Conversion utilities - itoa family // // Desc: Conversion utilities - itoa family //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kalbase.h> #include <libc.h>
// Digits table for bases <=36 (unused) // Digits table for bases <=36 (unused)
#if 0 #if 0

View File

@ -22,8 +22,8 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kalbase.h> #include <libc.h>
#include <extras/malloc.h> #include <ex/malloc.h>
/* DO NOT compile with strict aliasing on */ /* DO NOT compile with strict aliasing on */
@ -99,6 +99,7 @@ void *memset(void *ptr, int val, size_t bytes)
return ptr; return ptr;
} }
#if 0
// //
// Set "words"-many words starting from ptr to val // Set "words"-many words starting from ptr to val
// //
@ -135,6 +136,7 @@ void *memsetw(void *ptr, int val, size_t words)
return ptr; return ptr;
} }
#endif
// Set "dwords"-many dwords starting from ptr to val // Set "dwords"-many dwords starting from ptr to val
// XXX unimplemented // XXX unimplemented
@ -166,7 +168,7 @@ void *memsetq(void *ptr, long val, size_t qwords)
// //
void *memzero(void *ptr, size_t bytes) void *memzero(void *ptr, size_t bytes)
{ {
return memsetb(ptr, 0, bytes); return memset(ptr, 0, bytes);
} }
// //

View File

@ -22,7 +22,7 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kalbase.h> #include <libc.h>
// //
// Seed value // Seed value

View File

@ -22,7 +22,7 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <extras/buf.h> #include <lib/buf.h>
// //
// XXX // XXX

View File

@ -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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//
#include <kalbase.h>
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 "";
}
*/

View File

@ -22,7 +22,7 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kalbase.h> #include <libc.h>
// //
// Compare two strings // Compare two strings
@ -201,7 +201,7 @@ char *strtok(char *restrict str, const char *restrict delim)
static char *saveptr = NULL; static char *saveptr = NULL;
// Avoid this function if possible // Avoid this function if possible
KalAssert(FALSE); assert(!"Don't use strtok()!");
if (str) saveptr = str; if (str) saveptr = str;

View File

@ -22,7 +22,7 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kalbase.h> #include <libc.h>
long strtol(const char *str, char **endp, int base) { long strtol(const char *str, char **endp, int base) {
(void)str; (void)str;