diff --git a/src/Makefile b/src/Makefile index d4e80b8..91253d1 100644 --- a/src/Makefile +++ b/src/Makefile @@ -12,7 +12,7 @@ CC2NAME=gcc COPTIM=-O2 CLDSCR=-T kernel.ld CWARNS=-pedantic -Wall -Wextra -Werror -CINCLUDES=-isystem. +CINCLUDES=-isystem./kaleid/include CDEFINES= CFLAGS1=-nostdlib -ffreestanding -mcmodel=large @@ -20,7 +20,7 @@ CFLAGS2=-mno-red-zone -mno-mmx -mno-sse -mno-sse2 CFLAGS=$(CFLAGS1) $(CFLAGS2) CC=$(CCNAME) $(COPTIM) $(CWARNS) $(CFLAGS) $(CDEFINES) $(CINCLUDES) -KCC=$(CC) -D_KALEID_KERNEL +KCC=$(CC) -D_OSK_SOURCE -D_KALEID_KERNEL ASM=nasm ASMFLAGS= @@ -33,7 +33,8 @@ BOOTDIR=boot COMMDIR=kaleid/common KERNDIR=kaleid/kernel SYSTDIR=kaleid/system -LINXDIR=kaleid/linux +LINXDIR=kaleid/common/test +INCDIR=kaleid/include all: bootloader kernel @@ -62,24 +63,29 @@ testing: bootloader pseudo_kern COBJDIR=$(OBJDIR)/$(COMMDIR) LOBJDIR=$(OBJDIR)/$(LINXDIR) -COMMDEPS=$(COMMDIR)/common.h $(COMMDIR)/stdlib.h $(KERNDIR)/config.h +#COMMDEPS=$(COMMDIR)/common.h $(COMMDIR)/stdlib.h $(KERNDIR)/config.h +COMMDEPS=$(INCDIR)/kaleid.h $(INCDIR)/kaldefs.h $(INCDIR)/kaltypes.h \ + $(INCDIR)/kalmask.h $(INCDIR)/kalmask.h $(INCDIR)/kalassrt.h -COMMOBJS=$(COBJDIR)/lib/string.o $(COBJDIR)/lib/status.o \ - $(COBJDIR)/lib/convert.o $(COBJDIR)/lib/memory.o +COMMSRCS=$(COMMDIR)/string.c $(COMMDIR)/status.c \ + $(COMMDIR)/convert.c $(COMMDIR)/memory.c -common: $(COMMDEPS) $(COMMDIR)/lib/string.c $(COMMDIR)/lib/status.c - $(KCC) -c $(COMMDIR)/lib/string.c -o $(COBJDIR)/lib/string.o - $(KCC) -c $(COMMDIR)/lib/status.c -o $(COBJDIR)/lib/status.o - $(KCC) -c $(COMMDIR)/lib/memory.c -o $(COBJDIR)/lib/memory.o - $(KCC) -c $(COMMDIR)/lib/convert.c -o $(COBJDIR)/lib/convert.o +COMMOBJS=$(COBJDIR)/string.o $(COBJDIR)/status.o \ + $(COBJDIR)/convert.o $(COBJDIR)/memory.o + +common: $(COMMDEPS) $(COMMSRCS) + $(KCC) -c $(COMMDIR)/string.c -o $(COBJDIR)/string.o + $(KCC) -c $(COMMDIR)/status.c -o $(COBJDIR)/status.o + $(KCC) -c $(COMMDIR)/memory.c -o $(COBJDIR)/memory.o + $(KCC) -c $(COMMDIR)/convert.c -o $(COBJDIR)/convert.o CCC=$(CC2NAME) $(COPTIM) $(CWARNS) $(CINCLUDES) -test-common: - $(CCC) -c $(COMMDIR)/lib/string.c -o $(COBJDIR)/lib/string.o - $(CCC) -c $(COMMDIR)/lib/status.c -o $(COBJDIR)/lib/status.o - $(CCC) -c $(COMMDIR)/lib/memory.c -o $(COBJDIR)/lib/memory.o - $(CCC) -c $(COMMDIR)/lib/convert.c -o $(COBJDIR)/lib/convert.o +test-common: $(COMMSRCS) + $(CCC) -c $(COMMDIR)/string.c -o $(COBJDIR)/string.o + $(CCC) -c $(COMMDIR)/status.c -o $(COBJDIR)/status.o + $(CCC) -c $(COMMDIR)/memory.c -o $(COBJDIR)/memory.o + $(CCC) -c $(COMMDIR)/convert.c -o $(COBJDIR)/convert.o $(CCC) -c $(LINXDIR)/test-common.c -o $(LOBJDIR)/test-common.o $(CCC) $(COMMOBJS) $(LOBJDIR)/test-common.o -o $(BINDIR)/kaleid-common.elf @@ -88,17 +94,18 @@ test-common: KOBJDIR=$(OBJDIR)/$(KERNDIR) -KERNDEPS=common $(KERNDIR)/init.h $(KERNDIR)/io/terminal.h \ - $(KERNDIR)/io/ports.h $(KERNDIR)/ke/panic.h +KERNDEPS=common $(KERNDIR)/init.h $(KERNDIR)/io/terminal.h $(KERNDIR)/ke/lock.h \ + $(KERNDIR)/io/ports.h $(KERNDIR)/ke/panic.h $(KERNDIR)/ke/state.h -KERNSRCS=$(KERNDIR)/init.c $(KERNDIR)/ke/state.c $(KERNDIR)/ke/panic.c \ - $(KERNDIR)/io/ports.c $(KERNDIR)/io/terminal.c +KERNSRCS=$(KERNDIR)/init.c $(KERNDIR)/io/terminal.c $(KERNDIR)/ke/lock.c \ + $(KERNDIR)/io/ports.c $(KERNDIR)/ke/panic.c $(KERNDIR)/ke/state.c -KERNOBJS=$(KOBJDIR)/init.o $(KOBJDIR)/ke/state.o $(KOBJDIR)/ke/panic.o \ - $(KOBJDIR)/io/ports.o $(KOBJDIR)/io/terminal.o +KERNOBJS=$(KOBJDIR)/init.o $(KOBJDIR)/io/terminal.o $(KOBJDIR)/ke/lock.o \ + $(KOBJDIR)/io/ports.o $(KOBJDIR)/ke/panic.o $(KOBJDIR)/ke/state.o kernel: common $(KERNSRCS) $(KCC) -c $(KERNDIR)/init.c -o $(KOBJDIR)/init.o + $(KCC) -c $(KERNDIR)/ke/lock.c -o $(KOBJDIR)/ke/lock.o $(KCC) -c $(KERNDIR)/ke/state.c -o $(KOBJDIR)/ke/state.o $(KCC) -c $(KERNDIR)/ke/panic.c -o $(KOBJDIR)/ke/panic.o $(KCC) -c $(KERNDIR)/io/ports.c -o $(KOBJDIR)/io/ports.o diff --git a/src/kaleid/common/lib/convert.c b/src/kaleid/common/convert.c similarity index 97% rename from src/kaleid/common/lib/convert.c rename to src/kaleid/common/convert.c index 9a9f037..61e63bf 100644 --- a/src/kaleid/common/lib/convert.c +++ b/src/kaleid/common/convert.c @@ -7,7 +7,7 @@ // Desc: Conversion utilities // //----------------------------------------------------------------------------// -#include +#include // // Digits table for bases <=36 diff --git a/src/kaleid/common/lib/memory.c b/src/kaleid/common/memory.c similarity index 99% rename from src/kaleid/common/lib/memory.c rename to src/kaleid/common/memory.c index 196cdcc..d9097eb 100644 --- a/src/kaleid/common/lib/memory.c +++ b/src/kaleid/common/memory.c @@ -7,7 +7,7 @@ // Desc: mem*() functions // //----------------------------------------------------------------------------// -#include +#include //------------------------------------------// // memset() family // diff --git a/src/kaleid/common/lib/memsub.c b/src/kaleid/common/memsub.c similarity index 96% rename from src/kaleid/common/lib/memsub.c rename to src/kaleid/common/memsub.c index 8b25667..247c4d3 100644 --- a/src/kaleid/common/lib/memsub.c +++ b/src/kaleid/common/memsub.c @@ -7,7 +7,7 @@ // Desc: mem*() functions, suboptimal edition // //----------------------------------------------------------------------------// -#include +#include // // Set "bytes"-many bytes starting from ptr to val diff --git a/src/kaleid/common/common.h b/src/kaleid/common/old/common.h similarity index 92% rename from src/kaleid/common/common.h rename to src/kaleid/common/old/common.h index db57a20..1c9c0d6 100644 --- a/src/kaleid/common/common.h +++ b/src/kaleid/common/old/common.h @@ -55,6 +55,10 @@ # define INITOK ((unsigned int)0xCAFEBABE) #endif +#ifndef KALAPI +# define KALAPI +#endif + #ifdef _KALEID_KERNEL # include #endif @@ -86,13 +90,6 @@ typedef void *va_list; // XXX limits -#define WORD_SIZE sizeof(ushort) -#define DWORD_SIZE sizeof(uint) -#define QWORD_SIZE sizeof(ulong) - -#define WORD_ALIGN alignof(ushort) -#define DWORD_ALIGN alignof(uint) -#define QWORD_ALIGN alignof(ulong) //------------------------------------------// // VALUES FOR "status_t" // @@ -127,9 +124,9 @@ const char *describe_status(status_t); #ifdef _KALEID_KERNEL -# define DosDisableInterrupts() asm volatile ("cli") -# define DosEnableInterrupts() asm volatile ("sti") -# define DosHaltCPU() asm volatile ("hlt") +# define DisableInterrupts() asm volatile ("cli") +# define EnableInterrupts() asm volatile ("sti") +# define HaltCPU() asm volatile ("hlt") #endif //------------------------------------------// diff --git a/src/kaleid/common/folder.desc b/src/kaleid/common/old/folder.desc similarity index 100% rename from src/kaleid/common/folder.desc rename to src/kaleid/common/old/folder.desc diff --git a/src/kaleid/common/stdlib.h b/src/kaleid/common/old/stdlib.h similarity index 83% rename from src/kaleid/common/stdlib.h rename to src/kaleid/common/old/stdlib.h index b4af1f3..5f8e96c 100644 --- a/src/kaleid/common/stdlib.h +++ b/src/kaleid/common/old/stdlib.h @@ -4,15 +4,24 @@ // Authors: spectral` // // NeoX // // // -// Desc: Kaleid string library // +// Desc: Kaleid C runtime library // //----------------------------------------------------------------------------// - #ifndef _KALCOMM_STDLIB_H #define _KALCOMM_STDLIB_H -#ifndef _KALCOMM_COMMON_H -# include +//------------------------------------------// +// Typedefs // +//------------------------------------------// + +#ifndef __size_t +#define __size_t +typedef unsigned long size_t; +#endif + +#ifndef __va_list +#define __va_list +typedef __builtin_va_start va_list; #endif //------------------------------------------// @@ -25,8 +34,10 @@ # define memzero _osk_memzero #endif -#define memsetb memset -void *memset(void *, int, size_t); +#ifndef memset +# define memset memsetb +#endif +void *memsetb(void *, int, size_t); void *memsetw(void *, int, size_t); void *memsetd(void *, int, size_t); void *memsetq(void *, long, size_t); @@ -72,7 +83,7 @@ int vsnprintf(char *, size_t, const char *, va_list); char *itoa(int, char *, int); //------------------------------------------// -// End of kaleid/common/stdlib.h // +// End of header file // //------------------------------------------// #endif diff --git a/src/kaleid/common/lib/sprintf.c b/src/kaleid/common/sprintf.c similarity index 98% rename from src/kaleid/common/lib/sprintf.c rename to src/kaleid/common/sprintf.c index c8cbfa8..8a4e1f5 100644 --- a/src/kaleid/common/lib/sprintf.c +++ b/src/kaleid/common/sprintf.c @@ -7,7 +7,7 @@ // Desc: sprintf()-related functions // //----------------------------------------------------------------------------// -#include +#include // // Format str according to fmt using ellipsed arguments diff --git a/src/kaleid/common/lib/status.c b/src/kaleid/common/status.c similarity index 97% rename from src/kaleid/common/lib/status.c rename to src/kaleid/common/status.c index 254e1aa..c5139fe 100644 --- a/src/kaleid/common/lib/status.c +++ b/src/kaleid/common/status.c @@ -7,7 +7,7 @@ // Desc: Implementation of describe_status() // //----------------------------------------------------------------------------// -#include +#include static const char *descriptions[] = { [-SUCCESS] = "Success", diff --git a/src/kaleid/common/lib/string.c b/src/kaleid/common/string.c similarity index 79% rename from src/kaleid/common/lib/string.c rename to src/kaleid/common/string.c index 4bab621..81b4847 100644 --- a/src/kaleid/common/lib/string.c +++ b/src/kaleid/common/string.c @@ -7,7 +7,7 @@ // Desc: String-related functions // //----------------------------------------------------------------------------// -#include +#include // // Returns str's length @@ -32,7 +32,7 @@ char *strcpy(char *dest, const char *src) } // -// strcpy() but safer +// strcpy() but always writes n bytes // char *strncpy(char *dest, const char *src, size_t n) { @@ -46,6 +46,25 @@ char *strncpy(char *dest, const char *src, size_t n) return dest; } +// +// strncpy() but safer - always null-terminate, +// returns boolean indicating whether copy was complete +// XXX find a better name +// XXX actually implement this +// +size_t xstrcnpy(char *dest, const char *src, size_t n) +{ + size_t it; + + for (it = 0; it < n && src[it]; it++) { + dest[it] = src[it]; + } + + while (it < n) dest[it++] = 0; + + return TRUE; +} + // // Reverses the string src, putting the result into dest // diff --git a/src/kaleid/linux/test-common.c b/src/kaleid/common/test/test-common.c similarity index 95% rename from src/kaleid/linux/test-common.c rename to src/kaleid/common/test/test-common.c index cbce8cb..c63735b 100644 --- a/src/kaleid/linux/test-common.c +++ b/src/kaleid/common/test/test-common.c @@ -10,8 +10,7 @@ #include #include -#define KEEP_KALCOMM_TYPES_MINIMAL -#include +#include int main(int argc, char *argv[]) { @@ -43,7 +42,7 @@ int main(int argc, char *argv[]) puts(""); - //free((void *)xxx); + free((void *)xxx); //const char *str = "ceci est un string de test!"; //char *str2 = malloc((strlen(str) + 3) * sizeof(char)); diff --git a/src/kaleid/include/kalassrt.h b/src/kaleid/include/kalassrt.h new file mode 100644 index 0000000..3a345f4 --- /dev/null +++ b/src/kaleid/include/kalassrt.h @@ -0,0 +1,82 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Kaleid assert() support // +//----------------------------------------------------------------------------// + +#ifndef _KALASSRT_H +#define _KALASSRT_H + +//------------------------------------------// +// Useful macros // +//------------------------------------------// + +#ifndef noreturn +#define noreturn __attribute__((noreturn)) +#endif + +#ifndef unlikely(x) +#define unlikely(x) (__builtin_expect((x), 0)) +#endif + +//------------------------------------------// +// When debugging // +//------------------------------------------// + +#if !defined(_NO_DEBUG) && !defined(NDEBUG) && !defined(assert) + +// +// Failed assert handler +// +noreturn void _assert_handler(const char *, const char *, int, const char *); + +#define assert(x) \ + do { \ + if unlikely(!(x)) \ + _assert_handler(#x, __FILE__, __LINE__, __func__); \ + } while (0); + +// +// Aliases +// + +#ifndef Assert +#define Assert assert +#endif + +#ifndef DosAssert +#define DosAssert assert +#endif + +#ifndef KalAssert +#define KalAssert assert +#endif + +//------------------------------------------// +// When not debugging // +//------------------------------------------// + +#else + +#if !defined(NDEBUG) +# define NDEBUG 1 +#endif + +#if !defined(_NO_DEBUG) +# define _NO_DEBUG 1 +#endif + +#ifndef assert +#define assert(x) +#endif + +#endif + +//------------------------------------------// +// End of // +//------------------------------------------// + +#endif diff --git a/src/kaleid/include/kalcrt.h b/src/kaleid/include/kalcrt.h new file mode 100644 index 0000000..6c1fcd6 --- /dev/null +++ b/src/kaleid/include/kalcrt.h @@ -0,0 +1,102 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Kaleid C runtime library // +//----------------------------------------------------------------------------// + +#ifndef _KALCRT_H +#define _KALCRT_H + +//------------------------------------------// +// Typedefs // +//------------------------------------------// + +#ifndef __size_t +#define __size_t +typedef unsigned long size_t; +#endif + +#ifndef __va_list +#define __va_list +typedef __builtin_va_list va_list; +#endif + +#ifndef __status_t +#define __status_t +typedef signed long status_t; +#endif + +//------------------------------------------// +// Macros // +//------------------------------------------// + +#ifndef _NO_MASK +#define _NO_MASK +#endif + +//------------------------------------------// +// va_list utilities // +//------------------------------------------// + +#ifndef va_start +#define va_start __builtin_va_start +#endif + +#ifndef va_next +#define va_next __builtin_va_next +#endif + +#ifndef va_end +#define va_end __builtin_va_end +#endif + +//------------------------------------------// +// Memory management utilities // +//------------------------------------------// + +#if !defined(memset) && !defined(_KALMASK_H) +# define memset memsetb +#endif +void *memsetb(void *, int, size_t); +void *memsetw(void *, int, size_t); +void *memsetd(void *, int, size_t); +void *memsetq(void *, long, size_t); + +void *memzero(void *, size_t); + +//------------------------------------------// +// String manipulation utilities // +//------------------------------------------// + +size_t strlen(const char *); +char *strcpy(char *, const char *); +char *strncpy(char *, const char *, size_t); +char *strrev(char *, const char *); +char *reverse(char *); + +int sprintf(char *, const char *, ...); +int snprintf(char *, size_t, const char *, ...); +int vsprintf(char *, const char *, va_list); +int vsnprintf(char *, size_t, const char *, va_list); + +//------------------------------------------// +// Type conversion utilities // +//------------------------------------------// + +char *itoa(int, char *, int); + +//------------------------------------------// +// Diverse utilities // +//------------------------------------------// + +const char *describe_status(status_t) _NO_MASK; + +//------------------------------------------// +// End of // +//------------------------------------------// + +#endif + diff --git a/src/kaleid/include/kaldefs.h b/src/kaleid/include/kaldefs.h new file mode 100644 index 0000000..d8dedb3 --- /dev/null +++ b/src/kaleid/include/kaldefs.h @@ -0,0 +1,105 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Kaleid general preprocessor constants // +//----------------------------------------------------------------------------// + +#ifndef _KALDEFS_H +#define _KALDEFS_H + +//------------------------------------------// +// Actual constants // +//------------------------------------------// + +#ifndef TRUE +#define TRUE 1 +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + +#ifndef NULL +#define NULL ((void *)0) +#endif + +#ifndef INITOK +#define INITOK ((unsigned int)0xCAFEBABE) +#endif + +#ifndef DATA_SIZE_BLOCK +#define DATA_SIZE_BLOCK +# define BYTE_SIZE sizeof(char) +# define WORD_SIZE sizeof(short) +# define DWORD_SIZE sizeof(int) +# define QWORD_SIZE sizeof(long) +#endif + +#ifndef DATA_ALIGN_BLOCK +#define DATA_ALIGN_BLOCK +# define BYTE_ALIGN alignof(char) +# define WORD_ALIGN alignof(short) +# define DWORD_ALIGN alignof(int) +# define QWORD_ALIGN alignof(long) +#endif + +//------------------------------------------// +// Keywords and attributes // +//------------------------------------------// + +#ifndef PACKED +#define PACKED __attribute__((packed)) +#endif + +#ifndef noreturn +#define noreturn __attribute__((noreturn)) +#endif + +#ifndef alignof +#define alignof _Alignof +#endif + +#ifndef likely +#define likely(x) (__builtin_expect((x), 1)) +#endif + +#ifndef unlikely(x) +#define unlikely(x) (__builtin_expect((x), 0)) +#endif + +//------------------------------------------// +// API specific macros // +//------------------------------------------// + +#ifndef KALAPI +# define KALAPI +#endif + +//------------------------------------------// +// Values for APIRET // +//------------------------------------------// + +#define STATUS_FAILED(x) ((x) < 0)) +#define STATUS_SUCCESS(x) (!STATUS_FAILED(x)) + +#define SUCCESS (0) // everything went fine + +#define FAILED (-1) +#define ERROR FAILED // something went wrong +#define NOT_PERMITTED (-2) +#define ACCESS_DENIED (-3) + +#define BAD_ARGUMENT (-4) // invalid arguments +#define BAD_ARG_RANGE (-5) // arguments out of range +#define BAD_ARG_NULL (-6) // unexpected NULL argument + +#define TRY_AGAIN (-7) // EAGAIN + +//------------------------------------------// +// End of // +//------------------------------------------// + +#endif diff --git a/src/kaleid/include/kaleid.h b/src/kaleid/include/kaleid.h new file mode 100644 index 0000000..80f9b7e --- /dev/null +++ b/src/kaleid/include/kaleid.h @@ -0,0 +1,51 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Kaleid API main include file // +//----------------------------------------------------------------------------// + +#ifndef _KALEID_H +#define _KALEID_H + +//------------------------------------------// +// Building for OS/K // +//------------------------------------------// + +#if !defined(_OSK_SOURCE) +# if defined(_KALEID_KERNEL) || defined(_KALEID_SYSTEM) +# define _OSK_SOURCE 1 +# endif +#endif + +//------------------------------------------// +// Include common part of API // +//------------------------------------------// + +#ifndef _KALDEFS_H +#include +#endif + +#ifndef _KALTYPES_H +#include +#endif + +#ifndef _KALASSRT_H +#include +#endif + +#if defined(_KALMASK_NEEDED) && !defined(_KALMASK_H) +#include +#endif + +#ifndef _KALCRT_H +#include +#endif + +//------------------------------------------// +// End of // +//------------------------------------------// + +#endif diff --git a/src/kaleid/include/kalkern b/src/kaleid/include/kalkern new file mode 120000 index 0000000..195d388 --- /dev/null +++ b/src/kaleid/include/kalkern @@ -0,0 +1 @@ +../kernel \ No newline at end of file diff --git a/src/kaleid/include/kalkern.h b/src/kaleid/include/kalkern.h new file mode 100644 index 0000000..40f0625 --- /dev/null +++ b/src/kaleid/include/kalkern.h @@ -0,0 +1,37 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Kaleid Kernel main include file // +//----------------------------------------------------------------------------// + +#ifndef _KALKERN_H +#define _KALKERN_H + +//------------------------------------------// +// Dependencies // +//------------------------------------------// + +#ifndef _KALEID_H +#include +#endif + +#ifndef _KALKERN_CONFIG_H +#include +#endif + +//------------------------------------------// +// Macros // +//------------------------------------------// + +#define DisableInterrupts() asm volatile ("cli") +#define EnableInterrupts() asm volatile ("sti") +#define HaltCPU() asm volatile ("hlt") + +//------------------------------------------// +// End of // +//------------------------------------------// + +#endif diff --git a/src/kaleid/include/kalmask.h b/src/kaleid/include/kalmask.h new file mode 100644 index 0000000..d54d761 --- /dev/null +++ b/src/kaleid/include/kalmask.h @@ -0,0 +1,46 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Masks for the functions in the KCRL // +//----------------------------------------------------------------------------// + +#ifndef _KALMASK_H +#define _KALMASK_H + +//------------------------------------------// +// Not building for OS/K // +//------------------------------------------// +#ifndef _OSK_SOURCE + +//------------------------------------------// + +# define memcpy _osk_memcpy +# define memcmp _osk_memcmp +# define memzero _osk_memzero + +//------------------------------------------// + +# define strlen _osk_strlen +# define strcpy _osk_strcpy +# define strncpy _osk_strncpy +# define strrev _osk_strrev +# define reverse _osk_reverse +# define sprintf _osk_sprintf +# define snprintf _osk_snprintf +# define vsprintf _osk_vsprintf +# define vsnprintf _osk_vsnprintf + +//------------------------------------------// + +# define itoa _osk_itoa +# define atoi _osk_atoi + +//------------------------------------------// +// End of // +//------------------------------------------// + +#endif +#endif diff --git a/src/kaleid/include/kaltypes.h b/src/kaleid/include/kaltypes.h new file mode 100644 index 0000000..8f8294a --- /dev/null +++ b/src/kaleid/include/kaltypes.h @@ -0,0 +1,74 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Kaleid C common types // +//----------------------------------------------------------------------------// + +#ifndef _KALTYPES_H +#define _KALTYPES_H + +//------------------------------------------// +// Basic integer types aliases // +//------------------------------------------// + +#ifndef __base_types_aliases +#define __base_types_aliases +typedef unsigned char uchar; +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 + +//------------------------------------------// +// Other standard integer types // +//------------------------------------------// + +#ifndef __size_t +#define __size_t +typedef unsigned long size_t; +#endif + +#ifndef __ssize_t +#define __ssize_t +typedef signed long ssize_t; +#endif + +#ifndef __wchar_t +#define __wchar_t +typedef signed int wchar_t; +#endif + +#ifndef __off_t +#define __off_t +typedef unsigned long off_t; +#endif + +//------------------------------------------// +// Special types // +//------------------------------------------// + +#ifndef __va_list +#define __va_list +typedef __builtin_va_list va_list; +#endif + +#ifndef __status_t +#define __status_t +typedef signed long status_t; +#endif + +//------------------------------------------// +// Kaleid system types // +//------------------------------------------// + +//------------------------------------------// +// End of // +//------------------------------------------// + +#endif diff --git a/src/kaleid/kernel/config.h b/src/kaleid/kernel/config.h index 501be3d..6c43ff8 100644 --- a/src/kaleid/kernel/config.h +++ b/src/kaleid/kernel/config.h @@ -23,12 +23,12 @@ // // Enable/disable multiprocessor support // -#define MULTIPROCESSOR NO +#define MULTIPROCESSOR FALSE // // Enable/disable preemptivity // -#define PREEMPTIVE YES +#define PREEMPTIVE TRUE // // Size of a tabulation in spaces diff --git a/src/kaleid/kernel/init.c b/src/kaleid/kernel/init.c index e4d0450..3a7d1cd 100644 --- a/src/kaleid/kernel/init.c +++ b/src/kaleid/kernel/init.c @@ -7,26 +7,26 @@ // Desc: Kernel entry point // //----------------------------------------------------------------------------// -#include -#include -#include -#include +#include +#include +#include +#include // // Entry point of kaleid-kernel.elf // -void DosStartKern(void) +void StartKern(void) { // we're not ready to deal with interrupts - DosDisableInterrupts(); + DisableInterrupts(); // booting! - DosSetKernState(KSTATE_INIT); + SetKernState(KSTATE_INIT); // kernel terminals - DosInitTerms(); + InitTerms(); // we're out - DosPanic("Goodbye World :("); + StartPanic("Goodbye World :("); } diff --git a/src/kaleid/kernel/init.h b/src/kaleid/kernel/init.h index 40351c2..db03c33 100644 --- a/src/kaleid/kernel/init.h +++ b/src/kaleid/kernel/init.h @@ -10,12 +10,12 @@ #ifndef _KALKERN_INIT_H #define _KALKERN_INIT_H -#ifndef _KALCOMM_COMMON_H -#include +#ifndef _KALKERN_H +#include #endif // kernel entry point -void DosStartKern(void); +void StartKern(void); #endif diff --git a/src/kaleid/kernel/io/ports.c b/src/kaleid/kernel/io/ports.c index 4f5c8fe..3f44417 100644 --- a/src/kaleid/kernel/io/ports.c +++ b/src/kaleid/kernel/io/ports.c @@ -7,7 +7,7 @@ // Desc: Ports I/O // //----------------------------------------------------------------------------// -#include +#include diff --git a/src/kaleid/kernel/io/ports.h b/src/kaleid/kernel/io/ports.h index a92ddb6..10799a3 100644 --- a/src/kaleid/kernel/io/ports.h +++ b/src/kaleid/kernel/io/ports.h @@ -10,14 +10,14 @@ #ifndef _KALKERN_IO_PORTS_H #define _KALKERN_IO_PORTS_H -#ifndef _KALCOMM_COMMON_H -#include +#ifndef _KALKERN_H +#include #endif -#define DosWriteByteOnPort(port,val) asm volatile ("outb %1, %0" : : "dN" (port), "a" (value)) +#define WriteByteOnPort(port,val) asm volatile ("outb %1, %0" : : "dN" (port), "a" (value)) -uchar DosReadByteFromPort(port_t); -ushort DosReadWordFromPort(port_t); +uchar ReadByteFromPort(port_t); +ushort ReadWordFromPort(port_t); #endif diff --git a/src/kaleid/kernel/io/terminal.c b/src/kaleid/kernel/io/terminal.c index ce3ebd8..fe09e25 100644 --- a/src/kaleid/kernel/io/terminal.c +++ b/src/kaleid/kernel/io/terminal.c @@ -8,7 +8,7 @@ //----------------------------------------------------------------------------// #define _UNLOCKED_IO -#include +#include // // VGA-related macros @@ -44,31 +44,31 @@ terminal_t *stddbg; // // Initialize standard output // -void DosInitTerms(void) +void InitTerms(void) { - DosAssert(!stdout && _vga_term.kt_init != INITOK); + Assert(!stdout && _vga_term.kt_init != INITOK); _vga_term.kt_init = INITOK; stddbg = &_vga_term; // to be switched to VESA stdout = &_vga_term; - DosClearTerm(stdout); + ClearTerm(stdout); } // // Fill terminal with spaces // -status_t DosClearTerm(terminal_t *kt) +status_t ClearTerm(terminal_t *kt) { if (kt == NULL) return BAD_ARG_NULL; - DosAssert(kt->kt_init == INITOK); + Assert(kt->kt_init == INITOK); - DosLockTerm(kt); - DosClearTerm_Unlocked(kt); - DosUnlockTerm(kt); + LockTerm(kt); + ClearTerm_Unlocked(kt); + UnlockTerm(kt); return SUCCESS; } @@ -76,7 +76,7 @@ status_t DosClearTerm(terminal_t *kt) // // Change the color code // -status_t DosChTermColor(terminal_t *kt, uchar color) +status_t ChTermColor(terminal_t *kt, uchar color) { if (color > KTERM_COLOR_WHITE) return BAD_ARG_RANGE; @@ -84,9 +84,9 @@ status_t DosChTermColor(terminal_t *kt, uchar color) if (kt == NULL) return BAD_ARG_NULL; - DosLockTerm(kt); + LockTerm(kt); kt->kt_color = color; - DosUnlockTerm(kt); + UnlockTerm(kt); return SUCCESS; } @@ -94,16 +94,16 @@ status_t DosChTermColor(terminal_t *kt, uchar color) // // Write a single character on the terminal // -status_t DosPutOnTerm(terminal_t *kt, char ch) +status_t PutOnTerm(terminal_t *kt, char ch) { if (kt == NULL) return BAD_ARG_NULL; - DosAssert(kt->kt_init == INITOK); + Assert(kt->kt_init == INITOK); - DosLockTerm(kt); - DosPutOnTerm_Unlocked(kt, ch); - DosUnlockTerm(kt); + LockTerm(kt); + PutOnTerm_Unlocked(kt, ch); + UnlockTerm(kt); return SUCCESS; } @@ -111,18 +111,18 @@ status_t DosPutOnTerm(terminal_t *kt, char ch) // // Print string on terminal // -status_t DosPrintOnTerm(terminal_t *kt, const char *str) +status_t PrintOnTerm(terminal_t *kt, const char *str) { if (kt == NULL) return BAD_ARG_NULL; - DosAssert(kt->kt_init == INITOK); + Assert(kt->kt_init == INITOK); - DosLockTerm(kt); + LockTerm(kt); while (*str) { - DosPutOnTerm_Unlocked(kt, *str++); + PutOnTerm_Unlocked(kt, *str++); } - DosUnlockTerm(kt); + UnlockTerm(kt); return SUCCESS; } @@ -138,7 +138,7 @@ status_t DosPrintOnTerm(terminal_t *kt, const char *str) // Fill terminal with spaces (UNLOCKED version) // XXX would '\0' work too? // -void DosClearTerm_Unlocked(terminal_t *kt) +void ClearTerm_Unlocked(terminal_t *kt) { size_t i; @@ -156,7 +156,7 @@ void DosClearTerm_Unlocked(terminal_t *kt) // // Write a single character on the terminal (UNLOCKED version) // -void DosPutOnTerm_Unlocked(terminal_t *kt, char ch) +void PutOnTerm_Unlocked(terminal_t *kt, char ch) { int i; size_t prev_row; @@ -176,7 +176,7 @@ void DosPutOnTerm_Unlocked(terminal_t *kt, char ch) for (i = 0; i < TABSIZE; i++) { // tabulations can't spread over two lines if (kt->kt_curr_y == prev_row) { - DosPutOnTerm_Unlocked(kt, ' '); + PutOnTerm_Unlocked(kt, ' '); } } } @@ -200,10 +200,10 @@ void DosPutOnTerm_Unlocked(terminal_t *kt, char ch) // // Print string on terminal (UNLOCKED version) // -void DosPrintOnTerm_Unlocked(terminal_t *kt, const char *str) +void PrintOnTerm_Unlocked(terminal_t *kt, const char *str) { while (*str) { - DosPutOnTerm_Unlocked(kt, *str++); + PutOnTerm_Unlocked(kt, *str++); } } diff --git a/src/kaleid/kernel/io/terminal.h b/src/kaleid/kernel/io/terminal.h index 0826453..d7cc988 100644 --- a/src/kaleid/kernel/io/terminal.h +++ b/src/kaleid/kernel/io/terminal.h @@ -10,7 +10,7 @@ #ifndef _KALKERN_IO_KTERM_H #define _KALKERN_IO_KTERM_H -#include +#include // all available colors enum terminal_colors { @@ -42,28 +42,28 @@ extern terminal_t *stdout; // current debugging terminal extern terminal_t *stddbg; -void DosInitTerms(void); -status_t DosClearTerm(terminal_t *); -status_t DosPutOnTerm(terminal_t *, char); -status_t DosPrintOnTerm(terminal_t *, const char *); -status_t DosChTermColor(terminal_t *, uchar); +void InitTerms(void); +status_t ClearTerm(terminal_t *); +status_t PutOnTerm(terminal_t *, char); +status_t PrintOnTerm(terminal_t *, const char *); +status_t ChTermColor(terminal_t *, uchar); -#ifdef _UNLOCKED_IO -void DosClearTerm_Unlocked(terminal_t *); -void DosPutOnTerm_Unlocked(terminal_t *, char); -void DosPrintOnTerm_Unlocked(terminal_t *, const char *); -#define DosChTermColor_Unlocked(kt, col) ((kt)->kt_color = col) +#if defined(_UNLOCKED_IO) +void ClearTerm_Unlocked(terminal_t *); +void PutOnTerm_Unlocked(terminal_t *, char); +void PrintOnTerm_Unlocked(terminal_t *, const char *); +#define ChTermColor_Unlocked(kt, col) ((kt)->kt_color = col) #endif #ifndef _NO_DEBUG -# define DebugLog(...) DosPutOnTerm(stddbg, __VA_ARGS__) +# define DebugLog(...) PrintOnTerm(stddbg, __VA_ARGS__) #else # define DebugLog(...) #endif -#define DosLockTerm(kt) DosAquireLock(&kt->kt_lock) -#define DosUnlockTerm(kt) DosReleaseLock(&kt->kt_lock) -#define DosTryLockTerm(kt) DosAttemptLock(&kt->kt_lock) +#define LockTerm(kt) AquireLock(&kt->kt_lock) +#define UnlockTerm(kt) ReleaseLock(&kt->kt_lock) +#define TryLockTerm(kt) AttemptLock(&kt->kt_lock) #endif diff --git a/src/kaleid/kernel/ke/lock.c b/src/kaleid/kernel/ke/lock.c index 544bf93..465b76f 100644 --- a/src/kaleid/kernel/ke/lock.c +++ b/src/kaleid/kernel/ke/lock.c @@ -7,7 +7,7 @@ // Desc: Locks // //----------------------------------------------------------------------------// -#include +#include // nothing to do here diff --git a/src/kaleid/kernel/ke/lock.h b/src/kaleid/kernel/ke/lock.h index 1174c26..40482ec 100644 --- a/src/kaleid/kernel/ke/lock.h +++ b/src/kaleid/kernel/ke/lock.h @@ -10,8 +10,8 @@ #ifndef _KALKERN_KE_LOCK_H #define _KALKERN_KE_LOCK_H -#ifndef _KALCOMM_COMMON_H -#include +#ifndef _KALKERN_H +#include #endif enum lock_type { @@ -42,7 +42,7 @@ typedef struct { // // Initialize a lock // -#define DosInitLock(lk, type) \ +#define InitLock(lk, type) \ do { \ (lk)->lk_type = (type); \ (lk)->lk_lock = FALSE; \ @@ -59,40 +59,40 @@ typedef struct { // // Does nothing // -#define DosDestroyLock(lk) ((lk)->lk_init = FALSE) +#define DestroyLock(lk) ((lk)->lk_init = FALSE) // // Aquires the lock // Panics on double aquisition since that should never happen // until we have at least a basic scheduler // -#define DosAquireLock(lk) \ +#define AquireLock(lk) \ do { \ - DosDisableInterrupts(); \ - DosAssert((lk)->lk_init == INITOK); \ + DisableInterrupts(); \ + Assert((lk)->lk_init == INITOK); \ if ((lk)->lk_lock++) \ - DosPanic("DosAquireLock on an already locked object"); \ - DosEnableInterrupts(); \ + StartPanic("DosAquireLock on an already locked object"); \ + EnableInterrupts(); \ } while (FALSE); // // Releases an already aquired lock // Panics if the lock was never aquired (this will change) // -#define DosReleaseLock(lk) \ +#define ReleaseLock(lk) \ do { \ - DosDisableInterrupts(); \ - DosAssert((lk)->lk_init == INITOK); \ + DisableInterrupts(); \ + Assert((lk)->lk_init == INITOK); \ if ((lk)->lk_lock++) \ - DosPanic("DosReleaseLock on an unlocked object"); \ - DosEnableInterrupts(); \ + StartPanic("DosReleaseLock on an unlocked object"); \ + EnableInterrupts(); \ } while (FALSE); // // Tries to aquire lock // Doesn't work at all for obvious reasons // -#define DosAttemptLock(lk) ((lk)->lk_lock++) +#define AttemptLock(lk) ((lk)->lk_lock++) #endif diff --git a/src/kaleid/kernel/ke/panic.c b/src/kaleid/kernel/ke/panic.c index aaad786..888ac7b 100644 --- a/src/kaleid/kernel/ke/panic.c +++ b/src/kaleid/kernel/ke/panic.c @@ -7,11 +7,11 @@ // Desc: How NOT to panic 101 // //----------------------------------------------------------------------------// -#include -#include +#include +#include #define _UNLOCKED_IO -#include +#include // // Panic message @@ -22,47 +22,47 @@ const char *__panicmsg = NULL; // Failed assert() handler // noreturn void _assert_handler(const char *msg, - const char *file, - int line, - const char *func) + const char *file, + int line, + const char *func) { // not getting out of here - DosDisableInterrupts(); + DisableInterrupts(); (void)file; (void)line; (void)func; // XXX sprintf() to create a proper panicstr - DosPanic(msg); + StartPanic(msg); } // // Your best boy panic() // -void DosPanic(const char *str) +void StartPanic(const char *str) { - DosDisableInterrupts(); + DisableInterrupts(); - DosSetKernState(KSTATE_PANIC); + SetKernState(KSTATE_PANIC); - DosClearTerm_Unlocked(stdout); + ClearTerm_Unlocked(stdout); if (str == NULL) { str = "(no message given)"; } - if (DosGetPanicStr()) { - DosPrintOnTerm_Unlocked(stdout, "double panic!\n"); - DosHaltCPU(); + if (GetPanicStr()) { + PrintOnTerm_Unlocked(stdout, "double panic!\n"); + HaltCPU(); } - DosSetPanicStr(str); + SetPanicStr(str); // we cannot lock anything when panicking - DosPrintOnTerm_Unlocked(stdout, "panic! - "); - DosPrintOnTerm_Unlocked(stdout, str); + PrintOnTerm_Unlocked(stdout, "panic! - "); + PrintOnTerm_Unlocked(stdout, str); while (TRUE) { - DosHaltCPU(); + HaltCPU(); } } diff --git a/src/kaleid/kernel/ke/panic.h b/src/kaleid/kernel/ke/panic.h index 27a7753..372848e 100644 --- a/src/kaleid/kernel/ke/panic.h +++ b/src/kaleid/kernel/ke/panic.h @@ -10,15 +10,15 @@ #ifndef _KALKERN_KE_PANIC_H #define _KALKERN_KE_PANIC_H -#ifndef _KALCOMM_COMMON_H -#include +#ifndef _KALKERN_H +#include #endif -noreturn void DosPanic(const char *); -noreturn void DosCrashSystem(void); +noreturn void StartPanic(const char *); +noreturn void CrashSystem(void); extern const char *__panicmsg; -#define DosGetPanicStr() (__panicmsg) -#define DosSetPanicStr(str) (__panicmsg = (str)) +#define GetPanicStr() (__panicmsg) +#define SetPanicStr(str) (__panicmsg = (str)) #endif diff --git a/src/kaleid/kernel/ke/state.c b/src/kaleid/kernel/ke/state.c index fae844d..4d65f89 100644 --- a/src/kaleid/kernel/ke/state.c +++ b/src/kaleid/kernel/ke/state.c @@ -7,7 +7,7 @@ // Desc: Current kernel state // //----------------------------------------------------------------------------// -#include +#include // // Current kernel state diff --git a/src/kaleid/kernel/ke/state.h b/src/kaleid/kernel/ke/state.h index fe8e6b9..6f5de07 100644 --- a/src/kaleid/kernel/ke/state.h +++ b/src/kaleid/kernel/ke/state.h @@ -10,8 +10,8 @@ #ifndef _KALKERN_KE_STATE_H #define _KALKERN_KE_STATE_H -#ifndef _KALCOMM_COMMON_H -#include +#ifndef _KALKERN_H +#include #endif // XXX improve this @@ -30,8 +30,8 @@ enum kernel_states { }; extern uchar __kstate; -#define DosGetKernState() (__kstate) -#define DosSetKernState(x) (__kstate = (x)) +#define GetKernState() (__kstate) +#define SetKernState(x) (__kstate = (x)) #endif diff --git a/src/kaleid/kernel/mm/malloc.c b/src/kaleid/kernel/mm/malloc.c deleted file mode 100644 index 1ffa3c1..0000000 --- a/src/kaleid/kernel/mm/malloc.c +++ /dev/null @@ -1,12 +0,0 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: Memory allocation routines // -// Only exists to trigger Neox // -//----------------------------------------------------------------------------// - -#include - diff --git a/src/kaleid/kernel/mm/malloc.h b/src/kaleid/kernel/mm/malloc.h deleted file mode 100644 index 7d27929..0000000 --- a/src/kaleid/kernel/mm/malloc.h +++ /dev/null @@ -1,17 +0,0 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: Memory allocation routines // -// Only exists to trigger Neox // -//----------------------------------------------------------------------------// - -#ifndef _KALKERN_MM_MALLOC_H -#define _KALKERN_MM_MALLOC_H - -#include - -#endif - diff --git a/src/kernel.ld b/src/kernel.ld index d8fa35a..5768560 100644 --- a/src/kernel.ld +++ b/src/kernel.ld @@ -1,4 +1,4 @@ -ENTRY(DosStartKern) +ENTRY(StartKern) SECTIONS { . = 0x4000; /* XXX 0x4000 is temporary */ diff --git a/src/project-tree.txt b/src/project-tree.txt index f102785..e0e3f4d 100644 --- a/src/project-tree.txt +++ b/src/project-tree.txt @@ -31,6 +31,22 @@ src/ | + kaleid/ | | + | + include/ + | | | + | | - kaleid.h + | | - kaldefs.h + | | - kaltypes.h + | | - kalassrt.h + | | - kalmask.h + | | - kalcrt.h + | | | + | | - kalkern.h + | | | + | | ~ kalkern/ -> ../kernel/ + | | | + | | 0 + | | + | | | + kernel/ | | | | | x folder.desc @@ -53,43 +69,33 @@ src/ | | | | | + ke/ | | | | + | | | - lock.c + | | | - lock.h + | | | | | | | - panic.c | | | - panic.h | | | | + | | | - state.c + | | | - state.h + | | | | | | | 0 | | | | | 0 | | | + common/ | | | - | | x folder.desc + | | - status.c | | | - | | - common.h - | | - assert.h - | | - atomic.h - | | - status.h - | | - types.h + | | - string.c + | | - memory.c + | | - convert.c + | | - sprintf.c | | | - | | - string.h - | | - memory.h - | | - convert.h - | | | - | | + lib/ + | | + test/ | | | | - | | | - status.c - | | | | - | | | - string.c - | | | - memory.c - | | | - convert.c - | | | - sprintf.c + | | | - test-common.c | | | | | | | 0 | | 0 - | | - | + linux/ - | | | - | | - test-common.c - | | | - | | 0 | 0 0