Lua support in the process of being added.

Lua still doesn't compile, but I'm in the process of adding some
stubs (some really silly ones), in order to at least get it to
build properly.
alentours-dev
q3k 2012-08-23 13:58:23 +02:00
parent 72e99fb192
commit 5c922d933e
41 changed files with 2371 additions and 50 deletions

View File

@ -22,7 +22,7 @@ LD:=$(ENV)/$(TARGET)-ld
# -O2 sets -foptimize-sibling-calls which breaks code...
CFLAGS:=-m64 -mcmodel=large -Wall -Werror -nostdlib -nostartfiles -nodefaultlibs -std=c99 -g
CFLAGS+=-I ./include -Wno-packed-bitfield-compat -O2 -fno-optimize-sibling-calls -mcmodel=kernel
CFLAGS+= -mno-red-zone -ffreestanding
CXFLAGS:= -Wall -Werror -nostdlib -fno-builtin -nostartfiles -I ./include
CXFLAGS+= -nodefaultlibs -fno-exceptions -fno-rtti -fno-stack-protector

View File

@ -0,0 +1,6 @@
#ifndef __TIER0_ANSI_ERRNO_H__
#define __TIER0_ANSI_ERRNO_H__
#define E2BIG 7
#endif

View File

@ -0,0 +1,9 @@
#ifndef __TIER0_ANSI_LOCALE_H__
#define __TIER0_ANSI_LOCALE_H__
#include "Tier0/panic.h"
// for Lua
#define getlocaledecpoint() '.'
#endif

View File

@ -0,0 +1,8 @@
#ifndef __TIER0_ANSI_MATH_H__
#define __TIER0_ANSI_MATH_H__
//double floor(double X);
//double pow(double X);
//double ldexp(double A, int B);
#endif

View File

@ -0,0 +1,11 @@
#ifndef __TIER0_ANSI_SETJMP_H__
#define __TIER0_ANSI_SETJMP_H__
#include "Tier0/panic.h"
typedef u32 jmp_buf;
int setjmp(jmp_buf env);
void longjmp(jmp_buf env, int value);
#endif

View File

@ -0,0 +1,12 @@
#ifndef __TIER0_ANSI_STDIO_H__
#define __TIER0_ANSI_STDIO_H__
#include <stdarg.h>
#include "Tier0/kstdlib.h"
//int printf(char *format, va_list args);
#define BUFSIZ 1024
#define FILE int
int sprintf(char *str, const char *format, ...);
#endif

View File

@ -0,0 +1,9 @@
#ifndef __TIER0_ANSI_STDLIB_H__
#define __TIER0_ANSI_STDLIB_H__
void *malloc(unsigned long long int size);
int abs(int X);
void abort(void);
long int strtol(const char *nptr, char **endptr, int base);
#endif

View File

@ -0,0 +1,38 @@
#ifndef __TIER0_ANSI_STRING_H__
#define __TIER0_ANSI_STRING_H__
#include "Tier0/kstdio.h"
#include "Tier0/kstdlib.h"
const char *strchr (const char *str, int character);
inline int strcmp(const char *s1, const char *s2);
char *strpbrk(const char *s1, const char *s2);
const char *strchr (const char *str, int character)
{
while (*str != 0)
{
if (*str == character)
return str;
str++;
}
return 0;
}
inline int strcmp(const char *s1, const char *s2)
{
while((*s1 && *s2) && (*s1++ == *s2++));
return *(--s1) - *(--s2);
}
char *strpbrk(const char *s1, const char *s2)
{
while(*s1)
if(strchr(s2, *s1++))
return (char*)--s1;
return 0;
}
#define strlen(A) kstrlen(A)
#define memcpy(A, B, C) kmemcpy(A, B, C)
#define memcmp(A, B, C) kmemcmp((const u8*)A, (const u8*)B, C)
#endif

View File

@ -0,0 +1,9 @@
#ifndef __TIER0_ANSI_TIME_H__
#define __TIER0_ANSI_TIME_H__
typedef unsigned long long int time_t;
#warning time() stub!
#define time(x) (0)
#endif

View File

@ -20,6 +20,6 @@ void kprintf(const s8 *Format, ...);
void kdump(u8 *bData, u32 Length);
void kprint_hex(u64 Number);
void kstdio_set_globals(u8 line, u8 cur_x, u8 cur_y);
s32 kmemcmp(u8 *MemA, u8 *MemB, u32 Length);
s32 kmemcmp(const u8 *MemA, const u8 *MemB, u32 Length);
#endif

View File

@ -31,7 +31,7 @@ PLATS= aix ansi bsd cucumber-kernel freebsd generic linux macosx mingw posix sol
LUA_A= liblua.a
CORE_O= lapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o \
lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o \
ltm.o lundump.o lvm.o lzio.o
ltm.o lundump.o lvm.o lzio.o snprintf.o glue.o
LIB_O= lauxlib.o lbaselib.o lbitlib.o lcorolib.o ldblib.o liolib.o \
lmathlib.o loslib.o lstrlib.o ltablib.o loadlib.o linit.o
BASE_O= $(CORE_O) $(LIB_O) $(MYOBJS)
@ -98,7 +98,7 @@ bsd:
$(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" SYSLIBS="-Wl,-E"
cucumber-kernel:
$(MAKE) $(ALL) SYSCFLAGS="-DLUA_ANSI -I\"../../include/Tier0-ANSI/\" -I\"../../include/\""
$(MAKE) $(ALL) SYSCFLAGS="-DLUA_ANSI -I\"../../include/Lua/\" -I\"../../include/\""
freebsd:
$(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX" SYSLIBS="-Wl,-E -lreadline"

96
Kernel/src/Lua/glue.c Normal file
View File

@ -0,0 +1,96 @@
// Glue code for Lua <-> Tier0
#include <stdarg.h>
#include "setjmp.h"
#include "Tier0/panic.h"
#include "Tier0/kstdio.h"
int errno;
// math.h implementation
//double floor(double X)
//{
// return (double)((int) X);
//}
//double pow(double B, double E)
//{
// PANIC("pow() stub.");
// return 0;
//}
//double ldexp(double A, int B)
//{
// PANIC("ldexp() stub.");
// return 0;
//}
// setjmp.h implementation
int setjmp(jmp_buf env)
{
PANIC("setjmp() stub.");
return 0;
}
void longjmp(jmp_buf env, int value)
{
PANIC("longjmp() stub.");
}
// stdio.h implementation
//int printf(char *format, va_list args)
//{
// kprintf("lua :");
//
// va_list duplicate_args;
// va_copy(duplicate_args, args);
// int result = kprintf(format, duplicate_args);
// va_end(duplicate_args);
//
// return result;
//}
// stdlib.h implementation
void *malloc(unsigned long long int i)
{
PANIC("malloc() stub.");
return 0;
}
int abs(int X)
{
return (X > 0) ? X : (X * -1);
}
void abort(void)
{
PANIC("abort() stub.");
}
// string.h implementation
const char *strchr (const char *str, int character)
{
while (*str != 0)
{
if (*str == character)
return str;
str++;
}
return 0;
}
int strcmp(const char *s1, const char *s2)
{
while((*s1 && *s2) && (*s1++ == *s2++));
return *(--s1) - *(--s2);
}
char *strpbrk(const char *s1, const char *s2)
{
while(*s1)
if(strchr(s2, *s1++))
return (char*)--s1;
return 0;
}

BIN
Kernel/src/Lua/glue.o Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -47,7 +47,7 @@ typedef unsigned char lu_byte;
/* type to ensure maximum alignment */
#if !defined(LUAI_USER_ALIGNMENT_T)
#define LUAI_USER_ALIGNMENT_T union { double u; void *s; long l; }
#define LUAI_USER_ALIGNMENT_T union { long long int u; void *s; long l; }
#endif
typedef LUAI_USER_ALIGNMENT_T L_Umaxalign;
@ -271,20 +271,19 @@ union luai_Cast { double l_d; LUA_INT32 l_p[2]; };
/* on several machines, coercion from unsigned to double is slow,
so it may be worth to avoid */
#define lua_unsigned2number(u) \
(((u) <= (lua_Unsigned)INT_MAX) ? (lua_Number)(int)(u) : (lua_Number)(u))
(u)
#endif
#if defined(ltable_c) && !defined(luai_hashnum)
#include <float.h>
#include <math.h>
#define luai_hashnum(i,n) { int e; \
n = frexp(n, &e) * (lua_Number)(INT_MAX - DBL_MAX_EXP); \
lua_number2int(i, n); i += e; }
// not sure whether this is a good idea - q3k
#define luai_hashnum(i,n) { \
((i)=(int)(n)); \
}
#endif

Binary file not shown.

View File

@ -114,42 +114,45 @@ static lua_Number readhexa (const char **s, lua_Number r, int *count) {
/*
** convert an hexadecimal numeric string to a number, following
** C99 specification for 'strtod'
**
** modified by q3k to ignore floating point crap
*/
static lua_Number lua_strx2number (const char *s, char **endptr) {
lua_Number r = 0.0;
int e = 0, i = 0;
lua_Number r = 0;
int i = 0;
int neg = 0; /* 1 if number is negative */
*endptr = cast(char *, s); /* nothing is valid yet */
while (lisspace(cast_uchar(*s))) s++; /* skip initial spaces */
neg = isneg(&s); /* check signal */
if (!(*s == '0' && (*(s + 1) == 'x' || *(s + 1) == 'X'))) /* check '0x' */
return 0.0; /* invalid format (no '0x') */
return 0; /* invalid format (no '0x') */
s += 2; /* skip '0x' */
r = readhexa(&s, r, &i); /* read integer part */
if (*s == '.') {
s++; /* skip dot */
r = readhexa(&s, r, &e); /* read fractional part */
}
if (i == 0 && e == 0)
return 0.0; /* invalid format (no digit) */
e *= -4; /* each fractional digit divides value by 2^-4 */
// if (*s == '.') {
// s++; /* skip dot */
// r = readhexa(&s, r, &e); /* read fractional part */
// }
if (i == 0)
return 0; /* invalid format (no digit) */
// e *= -4; /* each fractional digit divides value by 2^-4 */
*endptr = cast(char *, s); /* valid up to here */
if (*s == 'p' || *s == 'P') { /* exponent part? */
int exp1 = 0;
int neg1;
s++; /* skip 'p' */
neg1 = isneg(&s); /* signal */
if (!lisdigit(cast_uchar(*s)))
goto ret; /* must have at least one digit */
while (lisdigit(cast_uchar(*s))) /* read exponent */
exp1 = exp1 * 10 + *(s++) - '0';
if (neg1) exp1 = -exp1;
e += exp1;
}
*endptr = cast(char *, s); /* valid up to here */
ret:
// if (*s == 'p' || *s == 'P') { /* exponent part? */
// int exp1 = 0;
// int neg1;
// s++; /* skip 'p' */
// neg1 = isneg(&s); /* signal */
// if (!lisdigit(cast_uchar(*s)))
// goto ret; /* must have at least one digit */
// while (lisdigit(cast_uchar(*s))) /* read exponent */
// exp1 = exp1 * 10 + *(s++) - '0';
// if (neg1) exp1 = -exp1;
// e += exp1;
// }
// *endptr = cast(char *, s); /* valid up to here */
// ret:
if (neg) r = -r;
return ldexp(r, e);
// return ldexp(r, e);
return r;
}
#endif

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -7,6 +7,7 @@
#include <stddef.h>
#include <string.h>
#include <stdlib.h>
#define lstate_c
#define LUA_CORE

BIN
Kernel/src/Lua/lstate.o Normal file

Binary file not shown.

BIN
Kernel/src/Lua/lstring.o Normal file

Binary file not shown.

BIN
Kernel/src/Lua/ltable.o Normal file

Binary file not shown.

BIN
Kernel/src/Lua/ltm.o Normal file

Binary file not shown.

View File

@ -383,14 +383,14 @@
** ===================================================================
*/
#define LUA_NUMBER_DOUBLE
#define LUA_NUMBER double
//#define LUA_NUMBER_DOUBLE
#define LUA_NUMBER int
/*
@@ LUAI_UACNUMBER is the result of an 'usual argument conversion'
@* over a number.
*/
#define LUAI_UACNUMBER double
#define LUAI_UACNUMBER int
/*
@ -399,10 +399,10 @@
@@ lua_number2str converts a number to a string.
@@ LUAI_MAXNUMBER2STR is maximum size of previous conversion.
*/
#define LUA_NUMBER_SCAN "%lf"
#define LUA_NUMBER_FMT "%.14g"
#define LUA_NUMBER_SCAN "%i"
#define LUA_NUMBER_FMT "%i"
#define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n))
#define LUAI_MAXNUMBER2STR 32 /* 16 digits, sign, point, and \0 */
#define LUAI_MAXNUMBER2STR 32 /* 16 digits, sign, point, and \0 */ // not sure - q3k
/*
@ -413,10 +413,10 @@
** systems, you can leave 'lua_strx2number' undefined and Lua will
** provide its own implementation.
*/
#define lua_str2number(s,p) strtod((s), (p))
#define lua_str2number(s,p) strtol((s), (p), 10)
#if defined(LUA_USE_STRTODHEX)
#define lua_strx2number(s,p) strtod((s), (p))
#define lua_strx2number(s,p) strtol((s), (p))
#endif
@ -426,9 +426,11 @@
/* the following operations need the math library */
#if defined(lobject_c) || defined(lvm_c)
#include <math.h>
#define luai_nummod(L,a,b) ((a) - floor((a)/(b))*(b))
#define luai_numpow(L,a,b) (pow(a,b))
//#include <math.h>
//#define luai_nummod(L,a,b) ((a) - floor((a)/(b))*(b))
//#define luai_numpow(L,a,b) (pow(a,b))
LUA_NUMBER luai_nummod(void *L, LUA_NUMBER a, LUA_NUMBER b);
LUA_NUMBER luai_numpow(void *L, LUA_NUMBER a, LUA_NUMBER b);
#endif
/* these are quite standard operations */
@ -451,8 +453,7 @@
** CHANGE that if ptrdiff_t is not adequate on your machine. (On most
** machines, ptrdiff_t gives a good choice between int or long.)
*/
#define LUA_INTEGER long long int
#define ptrdiff_t long long int
#define LUA_INTEGER long int
/*
@@ LUA_UNSIGNED is the integral type used by lua_pushunsigned/lua_tounsigned.

BIN
Kernel/src/Lua/lundump.o Normal file

Binary file not shown.

BIN
Kernel/src/Lua/lvm.o Normal file

Binary file not shown.

BIN
Kernel/src/Lua/lzio.o Normal file

Binary file not shown.

2105
Kernel/src/Lua/snprintf.c Normal file

File diff suppressed because it is too large Load Diff

BIN
Kernel/src/Lua/snprintf.o Normal file

Binary file not shown.

View File

@ -107,6 +107,14 @@ void kmain_newstack(void)
"orq $0x600, %rax;"
"movq %rax, %cr4;");
double wat2 = 13.37;
wat2 *= 6.66;
kprintf("%x\n", wat2);
u64 wat;
__asm__ volatile("movq %%xmm0, %0;" : "=r" (wat));
kprintf("%x\n", wat);
for (;;) {}
/*pic_init(0, 0);

View File

@ -103,6 +103,12 @@ void kprintf(const s8 *szFormat, ...)
; u8 *szString = va_arg(ap, u8*); //stupid gcc bug
kdump(szString, kstrlen((s8 *)szString));
break;
case 'f':
{
double Data = va_arg(ap, double);
kprint_hex((u64)Data);
break;
}
case 'X':
case 'x':
; u64 bData = va_arg(ap, u64);
@ -252,7 +258,7 @@ void kclear(void)
kmove_cursor(0, 0);
}
s32 kmemcmp(u8 *MemA, u8 *MemB, u32 Length)
s32 kmemcmp(const u8 *MemA, const u8 *MemB, u32 Length)
{
u32 Result = -1;
for (u32 Search = 0; Search < Length; Search++)