Big stuff! Happy new year!

This commit is contained in:
Julian Barathieu 2019-01-01 13:09:57 +01:00
parent 529055e9fe
commit ec0045a566
36 changed files with 718 additions and 210 deletions

View File

@ -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

View File

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

View File

@ -7,7 +7,7 @@
// Desc: mem*() functions //
//----------------------------------------------------------------------------//
#include <kaleid/common/stdlib.h>
#include <kaleid.h>
//------------------------------------------//
// memset() family //

View File

@ -7,7 +7,7 @@
// Desc: mem*() functions, suboptimal edition //
//----------------------------------------------------------------------------//
#include <kaleid/common/stdlib.h>
#include <kaleid.h>
//
// Set "bytes"-many bytes starting from ptr to val

View File

@ -55,6 +55,10 @@
# define INITOK ((unsigned int)0xCAFEBABE)
#endif
#ifndef KALAPI
# define KALAPI
#endif
#ifdef _KALEID_KERNEL
# include <kaleid/kernel/config.h>
#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
//------------------------------------------//

View File

@ -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 <kaleid/common/common.h>
//------------------------------------------//
// 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

View File

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

View File

@ -7,7 +7,7 @@
// Desc: Implementation of describe_status() //
//----------------------------------------------------------------------------//
#include <kaleid/common/common.h>
#include <kaleid.h>
static const char *descriptions[] = {
[-SUCCESS] = "Success",

View File

@ -7,7 +7,7 @@
// Desc: String-related functions //
//----------------------------------------------------------------------------//
#include <kaleid/common/stdlib.h>
#include <kaleid.h>
//
// 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
//

View File

@ -10,8 +10,7 @@
#include <stdlib.h>
#include <stdio.h>
#define KEEP_KALCOMM_TYPES_MINIMAL
#include <kaleid/common/stdlib.h>
#include <kaleid.h>
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));

View File

@ -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 <kalassrt.h> //
//------------------------------------------//
#endif

102
src/kaleid/include/kalcrt.h Normal file
View File

@ -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 <kalcrt.h> //
//------------------------------------------//
#endif

View File

@ -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 <kaldefs.h> //
//------------------------------------------//
#endif

View File

@ -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 <kaldefs.h>
#endif
#ifndef _KALTYPES_H
#include <kaltypes.h>
#endif
#ifndef _KALASSRT_H
#include <kalassrt.h>
#endif
#if defined(_KALMASK_NEEDED) && !defined(_KALMASK_H)
#include <kalmask.h>
#endif
#ifndef _KALCRT_H
#include <kalcrt.h>
#endif
//------------------------------------------//
// End of <kaleid.h> //
//------------------------------------------//
#endif

1
src/kaleid/include/kalkern Symbolic link
View File

@ -0,0 +1 @@
../kernel

View File

@ -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 <kaleid.h>
#endif
#ifndef _KALKERN_CONFIG_H
#include <kalkern/config.h>
#endif
//------------------------------------------//
// Macros //
//------------------------------------------//
#define DisableInterrupts() asm volatile ("cli")
#define EnableInterrupts() asm volatile ("sti")
#define HaltCPU() asm volatile ("hlt")
//------------------------------------------//
// End of <kalkern.h> //
//------------------------------------------//
#endif

View File

@ -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 <kalmask.h> //
//------------------------------------------//
#endif
#endif

View File

@ -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 <kaltypes.h> //
//------------------------------------------//
#endif

View File

@ -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

View File

@ -7,26 +7,26 @@
// Desc: Kernel entry point //
//----------------------------------------------------------------------------//
#include <kaleid/kernel/init.h>
#include <kaleid/kernel/ke/state.h>
#include <kaleid/kernel/ke/panic.h>
#include <kaleid/kernel/io/terminal.h>
#include <kalkern/init.h>
#include <kalkern/ke/state.h>
#include <kalkern/ke/panic.h>
#include <kalkern/io/terminal.h>
//
// 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 :(");
}

View File

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

View File

@ -7,7 +7,7 @@
// Desc: Ports I/O //
//----------------------------------------------------------------------------//
#include <kaleid/kernel/io/ports.h>
#include <kalkern/io/ports.h>

View File

@ -10,14 +10,14 @@
#ifndef _KALKERN_IO_PORTS_H
#define _KALKERN_IO_PORTS_H
#ifndef _KALCOMM_COMMON_H
#include <kaleid/common/common.h>
#ifndef _KALKERN_H
#include <kalkern.h>
#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

View File

@ -8,7 +8,7 @@
//----------------------------------------------------------------------------//
#define _UNLOCKED_IO
#include <kaleid/kernel/io/terminal.h>
#include <kalkern/io/terminal.h>
//
// 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++);
}
}

View File

@ -10,7 +10,7 @@
#ifndef _KALKERN_IO_KTERM_H
#define _KALKERN_IO_KTERM_H
#include <kaleid/kernel/ke/lock.h>
#include <kalkern/ke/lock.h>
// 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

View File

@ -7,7 +7,7 @@
// Desc: Locks //
//----------------------------------------------------------------------------//
#include <kaleid/kernel/ke/lock.h>
#include <kalkern/ke/lock.h>
// nothing to do here

View File

@ -10,8 +10,8 @@
#ifndef _KALKERN_KE_LOCK_H
#define _KALKERN_KE_LOCK_H
#ifndef _KALCOMM_COMMON_H
#include <kaleid/common/common.h>
#ifndef _KALKERN_H
#include <kalkern.h>
#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

View File

@ -7,11 +7,11 @@
// Desc: How NOT to panic 101 //
//----------------------------------------------------------------------------//
#include <kaleid/kernel/ke/panic.h>
#include <kaleid/kernel/ke/state.h>
#include <kalkern/ke/panic.h>
#include <kalkern/ke/state.h>
#define _UNLOCKED_IO
#include <kaleid/kernel/io/terminal.h>
#include <kalkern/io/terminal.h>
//
// Panic message
@ -27,42 +27,42 @@ noreturn void _assert_handler(const char *msg,
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();
}
}

View File

@ -10,15 +10,15 @@
#ifndef _KALKERN_KE_PANIC_H
#define _KALKERN_KE_PANIC_H
#ifndef _KALCOMM_COMMON_H
#include <kaleid/common/common.h>
#ifndef _KALKERN_H
#include <kalkern.h>
#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

View File

@ -7,7 +7,7 @@
// Desc: Current kernel state //
//----------------------------------------------------------------------------//
#include <kaleid/kernel/ke/state.h>
#include <kalkern/ke/state.h>
//
// Current kernel state

View File

@ -10,8 +10,8 @@
#ifndef _KALKERN_KE_STATE_H
#define _KALKERN_KE_STATE_H
#ifndef _KALCOMM_COMMON_H
#include <kaleid/common/common.h>
#ifndef _KALKERN_H
#include <kalkern.h>
#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

View File

@ -1,12 +0,0 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
// Authors: spectral` //
// NeoX //
// //
// Desc: Memory allocation routines //
// Only exists to trigger Neox //
//----------------------------------------------------------------------------//
#include <kaleid/kernel/mm/malloc.h>

View File

@ -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 <kaleid/common/common.h>
#endif

View File

@ -1,4 +1,4 @@
ENTRY(DosStartKern)
ENTRY(StartKern)
SECTIONS
{
. = 0x4000; /* XXX 0x4000 is temporary */

View File

@ -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