Compare commits
16 Commits
2d52c45915
...
archive-le
| Author | SHA1 | Date | |
|---|---|---|---|
| 3f0b94d2fc | |||
| f483a34d3c | |||
| af5d8c709b | |||
| b7f619b8c3 | |||
| 12c109a120 | |||
| c222cae16f | |||
| e2184bdc27 | |||
| 5b8804621c | |||
| aea99102cc | |||
| 1775af99b0 | |||
| 6f303bf656 | |||
| 4bf79e358a | |||
| 29a5cacdea | |||
| 34fc6e8d3a | |||
| 304dda0adf | |||
| 18092face9 |
9
.gitignore
vendored
9
.gitignore
vendored
@@ -1,5 +1,4 @@
|
||||
_o/
|
||||
build/
|
||||
picolibc/
|
||||
picolibc-install/
|
||||
/lib/
|
||||
old/
|
||||
out/
|
||||
*.iso
|
||||
*.img
|
||||
29
core/compat/math.h
Normal file
29
core/compat/math.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef COMPAT_MATH_H
|
||||
#define COMPAT_MATH_H
|
||||
|
||||
#define HUGE_VAL (__builtin_huge_val())
|
||||
#define NAN (__builtin_nan(""))
|
||||
#define INFINITY (__builtin_inf())
|
||||
|
||||
double fabs(double x);
|
||||
double floor(double x);
|
||||
double ceil(double x);
|
||||
double fmod(double x, double y);
|
||||
double pow(double x, double y);
|
||||
double sqrt(double x);
|
||||
double sin(double x);
|
||||
double cos(double x);
|
||||
double tan(double x);
|
||||
double asin(double x);
|
||||
double acos(double x);
|
||||
double atan(double x);
|
||||
double atan2(double y, double x);
|
||||
double exp(double x);
|
||||
double log(double x);
|
||||
double log10(double x);
|
||||
double cbrt(double x);
|
||||
double log2(double x);
|
||||
double trunc(double x);
|
||||
|
||||
|
||||
#endif
|
||||
9
core/compat/setjmp.h
Normal file
9
core/compat/setjmp.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef COMPAT_SETJMP_H
|
||||
#define COMPAT_SETJMP_H
|
||||
|
||||
typedef void *jmp_buf[5];
|
||||
|
||||
#define setjmp(env) __builtin_setjmp(env)
|
||||
#define longjmp(env, val) __builtin_longjmp(env, val)
|
||||
|
||||
#endif
|
||||
14
core/compat/stdarg.h
Normal file
14
core/compat/stdarg.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef COMPAT_STDARG_H
|
||||
#define COMPAT_STDARG_H
|
||||
|
||||
#ifndef MDE_CPU_X64
|
||||
#define MDE_CPU_X64
|
||||
#endif
|
||||
#include <Base.h>
|
||||
#include_next <stdarg.h>
|
||||
|
||||
#ifndef va_copy
|
||||
#define va_copy(dest, src) VA_COPY(dest, src)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
31
core/compat/stdint.h
Normal file
31
core/compat/stdint.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef COMPAT_STDINT_H
|
||||
#define COMPAT_STDINT_H
|
||||
|
||||
#ifndef MDE_CPU_X64
|
||||
#define MDE_CPU_X64
|
||||
#endif
|
||||
#include <Base.h>
|
||||
#include_next <stdint.h>
|
||||
|
||||
typedef int8_t int_least8_t;
|
||||
typedef uint8_t uint_least8_t;
|
||||
typedef int16_t int_least16_t;
|
||||
typedef uint16_t uint_least16_t;
|
||||
typedef int32_t int_least32_t;
|
||||
typedef uint32_t uint_least32_t;
|
||||
typedef int64_t int_least64_t;
|
||||
typedef uint64_t uint_least64_t;
|
||||
|
||||
typedef int8_t int_fast8_t;
|
||||
typedef uint8_t uint_fast8_t;
|
||||
typedef int16_t int_fast16_t;
|
||||
typedef uint16_t uint_fast16_t;
|
||||
typedef int32_t int_fast32_t;
|
||||
typedef uint32_t uint_fast32_t;
|
||||
typedef int64_t int_fast64_t;
|
||||
typedef uint64_t uint_fast64_t;
|
||||
|
||||
typedef int64_t intmax_t;
|
||||
typedef uint64_t uintmax_t;
|
||||
|
||||
#endif
|
||||
14
core/compat/stdio.h
Normal file
14
core/compat/stdio.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef COMPAT_STDIO_H
|
||||
#define COMPAT_STDIO_H
|
||||
|
||||
#ifndef MDE_CPU_X64
|
||||
#define MDE_CPU_X64
|
||||
#endif
|
||||
#include <Base.h>
|
||||
#include_next <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
int vsnprintf(char *str, size_t size, const char *format, va_list ap);
|
||||
int snprintf(char *str, size_t size, const char *format, ...);
|
||||
|
||||
#endif
|
||||
13
core/compat/time.h
Normal file
13
core/compat/time.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef COMPAT_TIME_H
|
||||
#define COMPAT_TIME_H
|
||||
|
||||
#ifndef MDE_CPU_X64
|
||||
#define MDE_CPU_X64
|
||||
#endif
|
||||
#include <Base.h>
|
||||
#include_next <time.h>
|
||||
|
||||
double difftime(time_t time1, time_t time0);
|
||||
|
||||
|
||||
#endif
|
||||
12
core/compat/windows.h
Normal file
12
core/compat/windows.h
Normal file
@@ -0,0 +1,12 @@
|
||||
/* Dummy windows.h for Duktape compatibility in EFI */
|
||||
#ifndef WINDOWS_H
|
||||
#define WINDOWS_H
|
||||
|
||||
#ifndef MDE_CPU_X64
|
||||
#define MDE_CPU_X64
|
||||
#endif
|
||||
|
||||
#include <Uefi.h>
|
||||
|
||||
#endif
|
||||
|
||||
3256
core/lib/duktape/src/duk_config.h
Normal file
3256
core/lib/duktape/src/duk_config.h
Normal file
File diff suppressed because it is too large
Load Diff
996
core/lib/duktape/src/duk_source_meta.json
Normal file
996
core/lib/duktape/src/duk_source_meta.json
Normal file
@@ -0,0 +1,996 @@
|
||||
{
|
||||
"type": "duk_source_meta",
|
||||
"comment": "Metadata for prepared Duktape sources and configuration",
|
||||
"git_commit": "b5d069a96ba0989c444dad8e6f002a0a057b4df0",
|
||||
"git_branch": "master",
|
||||
"git_describe": "v2.5.0-393-gb5d069a9",
|
||||
"duk_version": 29999,
|
||||
"duk_version_string": "2.99.99",
|
||||
"line_map": [
|
||||
{
|
||||
"original_file": "duk_unicode_tables.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 159
|
||||
},
|
||||
{
|
||||
"original_file": "duk_internal.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 164
|
||||
},
|
||||
{
|
||||
"original_file": "duk_dblunion.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 201
|
||||
},
|
||||
{
|
||||
"original_file": "duk_fltunion.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 621
|
||||
},
|
||||
{
|
||||
"original_file": "duk_replacements.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 661
|
||||
},
|
||||
{
|
||||
"original_file": "duk_jmpbuf.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 691
|
||||
},
|
||||
{
|
||||
"original_file": "duk_exception.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 716
|
||||
},
|
||||
{
|
||||
"original_file": "duk_forwdecl.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 748
|
||||
},
|
||||
{
|
||||
"original_file": "duk_tval.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 881
|
||||
},
|
||||
{
|
||||
"original_file": "duk_builtins.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 1582
|
||||
},
|
||||
{
|
||||
"original_file": "duk_internal.h",
|
||||
"original_line": 45,
|
||||
"combined_line": 3156
|
||||
},
|
||||
{
|
||||
"original_file": "duk_util.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 3158
|
||||
},
|
||||
{
|
||||
"original_file": "duk_strings.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 3954
|
||||
},
|
||||
{
|
||||
"original_file": "duk_js_bytecode.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 4130
|
||||
},
|
||||
{
|
||||
"original_file": "duk_lexer.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 4604
|
||||
},
|
||||
{
|
||||
"original_file": "duk_js_compiler.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 5040
|
||||
},
|
||||
{
|
||||
"original_file": "duk_regexp.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 5273
|
||||
},
|
||||
{
|
||||
"original_file": "duk_heaphdr.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 5362
|
||||
},
|
||||
{
|
||||
"original_file": "duk_refcount.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 5848
|
||||
},
|
||||
{
|
||||
"original_file": "duk_api_internal.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 6897
|
||||
},
|
||||
{
|
||||
"original_file": "duk_hstring.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 7337
|
||||
},
|
||||
{
|
||||
"original_file": "duk_hobject.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 7536
|
||||
},
|
||||
{
|
||||
"original_file": "duk_hcompfunc.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 8163
|
||||
},
|
||||
{
|
||||
"original_file": "duk_hnatfunc.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 8423
|
||||
},
|
||||
{
|
||||
"original_file": "duk_hboundfunc.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 8468
|
||||
},
|
||||
{
|
||||
"original_file": "duk_hbufobj.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 8511
|
||||
},
|
||||
{
|
||||
"original_file": "duk_hthread.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 8657
|
||||
},
|
||||
{
|
||||
"original_file": "duk_harray.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 9075
|
||||
},
|
||||
{
|
||||
"original_file": "duk_henv.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 9187
|
||||
},
|
||||
{
|
||||
"original_file": "duk_hbuffer.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 9243
|
||||
},
|
||||
{
|
||||
"original_file": "duk_hproxy.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 9591
|
||||
},
|
||||
{
|
||||
"original_file": "duk_heap.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 9623
|
||||
},
|
||||
{
|
||||
"original_file": "duk_debugger.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 10385
|
||||
},
|
||||
{
|
||||
"original_file": "duk_debug.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 10537
|
||||
},
|
||||
{
|
||||
"original_file": "duk_error.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 10734
|
||||
},
|
||||
{
|
||||
"original_file": "duk_unicode.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 11456
|
||||
},
|
||||
{
|
||||
"original_file": "duk_unicode_ids_noa.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 11640
|
||||
},
|
||||
{
|
||||
"original_file": "duk_unicode.h",
|
||||
"original_line": 185,
|
||||
"combined_line": 11643
|
||||
},
|
||||
{
|
||||
"original_file": "duk_unicode_ids_noabmp.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 11645
|
||||
},
|
||||
{
|
||||
"original_file": "duk_unicode.h",
|
||||
"original_line": 187,
|
||||
"combined_line": 11648
|
||||
},
|
||||
{
|
||||
"original_file": "duk_unicode_ids_m_let_noa.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 11652
|
||||
},
|
||||
{
|
||||
"original_file": "duk_unicode.h",
|
||||
"original_line": 191,
|
||||
"combined_line": 11655
|
||||
},
|
||||
{
|
||||
"original_file": "duk_unicode_ids_m_let_noabmp.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 11657
|
||||
},
|
||||
{
|
||||
"original_file": "duk_unicode.h",
|
||||
"original_line": 193,
|
||||
"combined_line": 11660
|
||||
},
|
||||
{
|
||||
"original_file": "duk_unicode_idp_m_ids_noa.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 11664
|
||||
},
|
||||
{
|
||||
"original_file": "duk_unicode.h",
|
||||
"original_line": 197,
|
||||
"combined_line": 11667
|
||||
},
|
||||
{
|
||||
"original_file": "duk_unicode_idp_m_ids_noabmp.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 11669
|
||||
},
|
||||
{
|
||||
"original_file": "duk_unicode.h",
|
||||
"original_line": 199,
|
||||
"combined_line": 11672
|
||||
},
|
||||
{
|
||||
"original_file": "duk_unicode_caseconv.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 11675
|
||||
},
|
||||
{
|
||||
"original_file": "duk_unicode.h",
|
||||
"original_line": 202,
|
||||
"combined_line": 11679
|
||||
},
|
||||
{
|
||||
"original_file": "duk_unicode_re_canon_lookup.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 11682
|
||||
},
|
||||
{
|
||||
"original_file": "duk_unicode.h",
|
||||
"original_line": 205,
|
||||
"combined_line": 11685
|
||||
},
|
||||
{
|
||||
"original_file": "duk_unicode_re_canon_bitmap.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 11689
|
||||
},
|
||||
{
|
||||
"original_file": "duk_unicode.h",
|
||||
"original_line": 209,
|
||||
"combined_line": 11695
|
||||
},
|
||||
{
|
||||
"original_file": "duk_json.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 11783
|
||||
},
|
||||
{
|
||||
"original_file": "duk_js.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 11852
|
||||
},
|
||||
{
|
||||
"original_file": "duk_numconv.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 11999
|
||||
},
|
||||
{
|
||||
"original_file": "duk_bi_protos.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 12107
|
||||
},
|
||||
{
|
||||
"original_file": "duk_selftest.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 12185
|
||||
},
|
||||
{
|
||||
"original_file": "duk_prop.h",
|
||||
"original_line": 1,
|
||||
"combined_line": 12201
|
||||
},
|
||||
{
|
||||
"original_file": "duk_internal.h",
|
||||
"original_line": 77,
|
||||
"combined_line": 12298
|
||||
},
|
||||
{
|
||||
"original_file": "duk_unicode_tables.c",
|
||||
"original_line": 6,
|
||||
"combined_line": 12300
|
||||
},
|
||||
{
|
||||
"original_file": "duk_unicode_ids_noa.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 12317
|
||||
},
|
||||
{
|
||||
"original_file": "duk_unicode_tables.c",
|
||||
"original_line": 23,
|
||||
"combined_line": 12369
|
||||
},
|
||||
{
|
||||
"original_file": "duk_unicode_ids_noabmp.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 12373
|
||||
},
|
||||
{
|
||||
"original_file": "duk_unicode_tables.c",
|
||||
"original_line": 27,
|
||||
"combined_line": 12403
|
||||
},
|
||||
{
|
||||
"original_file": "duk_unicode_ids_m_let_noa.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 12409
|
||||
},
|
||||
{
|
||||
"original_file": "duk_unicode_tables.c",
|
||||
"original_line": 33,
|
||||
"combined_line": 12413
|
||||
},
|
||||
{
|
||||
"original_file": "duk_unicode_ids_m_let_noabmp.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 12417
|
||||
},
|
||||
{
|
||||
"original_file": "duk_unicode_tables.c",
|
||||
"original_line": 37,
|
||||
"combined_line": 12421
|
||||
},
|
||||
{
|
||||
"original_file": "duk_unicode_idp_m_ids_noa.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 12427
|
||||
},
|
||||
{
|
||||
"original_file": "duk_unicode_tables.c",
|
||||
"original_line": 43,
|
||||
"combined_line": 12457
|
||||
},
|
||||
{
|
||||
"original_file": "duk_unicode_idp_m_ids_noabmp.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 12461
|
||||
},
|
||||
{
|
||||
"original_file": "duk_unicode_tables.c",
|
||||
"original_line": 47,
|
||||
"combined_line": 12480
|
||||
},
|
||||
{
|
||||
"original_file": "duk_unicode_caseconv.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 12490
|
||||
},
|
||||
{
|
||||
"original_file": "duk_unicode_tables.c",
|
||||
"original_line": 57,
|
||||
"combined_line": 12595
|
||||
},
|
||||
{
|
||||
"original_file": "duk_unicode_re_canon_lookup.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 12598
|
||||
},
|
||||
{
|
||||
"original_file": "duk_unicode_tables.c",
|
||||
"original_line": 60,
|
||||
"combined_line": 18426
|
||||
},
|
||||
{
|
||||
"original_file": "duk_unicode_re_canon_bitmap.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 18430
|
||||
},
|
||||
{
|
||||
"original_file": "duk_unicode_tables.c",
|
||||
"original_line": 64,
|
||||
"combined_line": 18446
|
||||
},
|
||||
{
|
||||
"original_file": "duk_replacements.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 18447
|
||||
},
|
||||
{
|
||||
"original_file": "duk_debug_macros.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 18529
|
||||
},
|
||||
{
|
||||
"original_file": "duk_builtins.c",
|
||||
"original_line": 2,
|
||||
"combined_line": 18621
|
||||
},
|
||||
{
|
||||
"original_file": "duk_error_macros.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 23804
|
||||
},
|
||||
{
|
||||
"original_file": "duk_unicode_support.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 24000
|
||||
},
|
||||
{
|
||||
"original_file": "duk_util_memrw.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 25219
|
||||
},
|
||||
{
|
||||
"original_file": "duk_util_misc.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 25367
|
||||
},
|
||||
{
|
||||
"original_file": "duk_hobject_class.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 25532
|
||||
},
|
||||
{
|
||||
"original_file": "duk_alloc_default.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 25661
|
||||
},
|
||||
{
|
||||
"original_file": "duk_api_buffer.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 25693
|
||||
},
|
||||
{
|
||||
"original_file": "duk_api_bytecode.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 25766
|
||||
},
|
||||
{
|
||||
"original_file": "duk_api_call.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 26546
|
||||
},
|
||||
{
|
||||
"original_file": "duk_api_codec.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 27072
|
||||
},
|
||||
{
|
||||
"original_file": "duk_api_compile.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 28010
|
||||
},
|
||||
{
|
||||
"original_file": "duk_api_debug.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 28185
|
||||
},
|
||||
{
|
||||
"original_file": "duk_api_heap.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 28446
|
||||
},
|
||||
{
|
||||
"original_file": "duk_api_inspect.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 28655
|
||||
},
|
||||
{
|
||||
"original_file": "duk_api_memory.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 28958
|
||||
},
|
||||
{
|
||||
"original_file": "duk_api_object.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 29038
|
||||
},
|
||||
{
|
||||
"original_file": "duk_api_random.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 30159
|
||||
},
|
||||
{
|
||||
"original_file": "duk_api_readable.c",
|
||||
"original_line": 2,
|
||||
"combined_line": 30169
|
||||
},
|
||||
{
|
||||
"original_file": "duk_api_stack.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 30525
|
||||
},
|
||||
{
|
||||
"original_file": "duk_api_string.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 37426
|
||||
},
|
||||
{
|
||||
"original_file": "duk_api_time.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 37817
|
||||
},
|
||||
{
|
||||
"original_file": "duk_bi_array.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 37927
|
||||
},
|
||||
{
|
||||
"original_file": "duk_bi_boolean.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 39581
|
||||
},
|
||||
{
|
||||
"original_file": "duk_bi_buffer.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 39650
|
||||
},
|
||||
{
|
||||
"original_file": "duk_bi_cbor.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 42576
|
||||
},
|
||||
{
|
||||
"original_file": "duk_bi_date.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 44504
|
||||
},
|
||||
{
|
||||
"original_file": "duk_bi_date_unix.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 46402
|
||||
},
|
||||
{
|
||||
"original_file": "duk_bi_date_windows.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 46750
|
||||
},
|
||||
{
|
||||
"original_file": "duk_bi_duktape.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 46945
|
||||
},
|
||||
{
|
||||
"original_file": "duk_bi_encoding.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 47095
|
||||
},
|
||||
{
|
||||
"original_file": "duk_bi_error.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 47646
|
||||
},
|
||||
{
|
||||
"original_file": "duk_bi_function.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 48046
|
||||
},
|
||||
{
|
||||
"original_file": "duk_bi_global.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 48500
|
||||
},
|
||||
{
|
||||
"original_file": "duk_bi_json.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 49221
|
||||
},
|
||||
{
|
||||
"original_file": "duk_bi_math.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 52561
|
||||
},
|
||||
{
|
||||
"original_file": "duk_bi_number.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 53052
|
||||
},
|
||||
{
|
||||
"original_file": "duk_bi_object.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 53316
|
||||
},
|
||||
{
|
||||
"original_file": "duk_bi_performance.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 54033
|
||||
},
|
||||
{
|
||||
"original_file": "duk_bi_pointer.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 54064
|
||||
},
|
||||
{
|
||||
"original_file": "duk_bi_promise.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 54138
|
||||
},
|
||||
{
|
||||
"original_file": "duk_bi_proxy.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 54182
|
||||
},
|
||||
{
|
||||
"original_file": "duk_bi_reflect.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 54233
|
||||
},
|
||||
{
|
||||
"original_file": "duk_bi_regexp.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 54321
|
||||
},
|
||||
{
|
||||
"original_file": "duk_bi_string.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 54549
|
||||
},
|
||||
{
|
||||
"original_file": "duk_bi_symbol.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 56036
|
||||
},
|
||||
{
|
||||
"original_file": "duk_bi_thread.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 56208
|
||||
},
|
||||
{
|
||||
"original_file": "duk_bi_thrower.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 56532
|
||||
},
|
||||
{
|
||||
"original_file": "duk_debug_fixedbuffer.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 56541
|
||||
},
|
||||
{
|
||||
"original_file": "duk_debug_vsnprintf.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 56610
|
||||
},
|
||||
{
|
||||
"original_file": "duk_debugger.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 57855
|
||||
},
|
||||
{
|
||||
"original_file": "duk_error_augment.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 60927
|
||||
},
|
||||
{
|
||||
"original_file": "duk_error_longjmp.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 61528
|
||||
},
|
||||
{
|
||||
"original_file": "duk_error_misc.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 61635
|
||||
},
|
||||
{
|
||||
"original_file": "duk_error_throw.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 61813
|
||||
},
|
||||
{
|
||||
"original_file": "duk_hbuffer_alloc.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 61972
|
||||
},
|
||||
{
|
||||
"original_file": "duk_hbuffer_assert.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 62106
|
||||
},
|
||||
{
|
||||
"original_file": "duk_hbuffer_ops.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 62119
|
||||
},
|
||||
{
|
||||
"original_file": "duk_hbufobj_misc.c",
|
||||
"original_line": 2,
|
||||
"combined_line": 62197
|
||||
},
|
||||
{
|
||||
"original_file": "duk_heap_alloc.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 62319
|
||||
},
|
||||
{
|
||||
"original_file": "duk_heap_finalize.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 63595
|
||||
},
|
||||
{
|
||||
"original_file": "duk_heap_hashstring.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 64044
|
||||
},
|
||||
{
|
||||
"original_file": "duk_heap_markandsweep.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 64165
|
||||
},
|
||||
{
|
||||
"original_file": "duk_heap_memory.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 65771
|
||||
},
|
||||
{
|
||||
"original_file": "duk_heap_misc.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 66205
|
||||
},
|
||||
{
|
||||
"original_file": "duk_heap_refcount.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 66392
|
||||
},
|
||||
{
|
||||
"original_file": "duk_heap_stringcache.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 67364
|
||||
},
|
||||
{
|
||||
"original_file": "duk_heap_stringtable.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 67865
|
||||
},
|
||||
{
|
||||
"original_file": "duk_heaphdr_assert.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 69108
|
||||
},
|
||||
{
|
||||
"original_file": "duk_hobject_alloc.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 69199
|
||||
},
|
||||
{
|
||||
"original_file": "duk_hobject_array.c",
|
||||
"original_line": 2,
|
||||
"combined_line": 69479
|
||||
},
|
||||
{
|
||||
"original_file": "duk_hobject_assert.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 69758
|
||||
},
|
||||
{
|
||||
"original_file": "duk_hobject_lookup.c",
|
||||
"original_line": 2,
|
||||
"combined_line": 69998
|
||||
},
|
||||
{
|
||||
"original_file": "duk_hobject_misc.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 70556
|
||||
},
|
||||
{
|
||||
"original_file": "duk_hobject_pc2line.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 71019
|
||||
},
|
||||
{
|
||||
"original_file": "duk_hobject_props.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 71265
|
||||
},
|
||||
{
|
||||
"original_file": "duk_hobject_proxy.c",
|
||||
"original_line": 2,
|
||||
"combined_line": 71721
|
||||
},
|
||||
{
|
||||
"original_file": "duk_hobject_resize.c",
|
||||
"original_line": 2,
|
||||
"combined_line": 71885
|
||||
},
|
||||
{
|
||||
"original_file": "duk_hstring_assert.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 73228
|
||||
},
|
||||
{
|
||||
"original_file": "duk_hstring_misc.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 73250
|
||||
},
|
||||
{
|
||||
"original_file": "duk_hthread_alloc.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 73479
|
||||
},
|
||||
{
|
||||
"original_file": "duk_hthread_builtins.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 73538
|
||||
},
|
||||
{
|
||||
"original_file": "duk_hthread_misc.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 74438
|
||||
},
|
||||
{
|
||||
"original_file": "duk_hthread_stacks.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 74535
|
||||
},
|
||||
{
|
||||
"original_file": "duk_js_arith.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 74898
|
||||
},
|
||||
{
|
||||
"original_file": "duk_js_call.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 75039
|
||||
},
|
||||
{
|
||||
"original_file": "duk_js_compiler.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 77862
|
||||
},
|
||||
{
|
||||
"original_file": "duk_js_executor.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 86010
|
||||
},
|
||||
{
|
||||
"original_file": "duk_js_ops.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 91409
|
||||
},
|
||||
{
|
||||
"original_file": "duk_js_prop.c",
|
||||
"original_line": 2,
|
||||
"combined_line": 92848
|
||||
},
|
||||
{
|
||||
"original_file": "duk_js_var.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 93095
|
||||
},
|
||||
{
|
||||
"original_file": "duk_lexer.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 94829
|
||||
},
|
||||
{
|
||||
"original_file": "duk_numconv.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 97281
|
||||
},
|
||||
{
|
||||
"original_file": "duk_prop_defown.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 99623
|
||||
},
|
||||
{
|
||||
"original_file": "duk_prop_delete.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 101144
|
||||
},
|
||||
{
|
||||
"original_file": "duk_prop_enum.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 102280
|
||||
},
|
||||
{
|
||||
"original_file": "duk_prop_get.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 102538
|
||||
},
|
||||
{
|
||||
"original_file": "duk_prop_getown.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 104476
|
||||
},
|
||||
{
|
||||
"original_file": "duk_prop_has.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 105079
|
||||
},
|
||||
{
|
||||
"original_file": "duk_prop_ownpropkeys.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 105712
|
||||
},
|
||||
{
|
||||
"original_file": "duk_prop_set.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 106347
|
||||
},
|
||||
{
|
||||
"original_file": "duk_prop_util.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 109579
|
||||
},
|
||||
{
|
||||
"original_file": "duk_regexp_compiler.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 109893
|
||||
},
|
||||
{
|
||||
"original_file": "duk_regexp_executor.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 111194
|
||||
},
|
||||
{
|
||||
"original_file": "duk_selftest.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 112187
|
||||
},
|
||||
{
|
||||
"original_file": "duk_tval.c",
|
||||
"original_line": 2,
|
||||
"combined_line": 112934
|
||||
},
|
||||
{
|
||||
"original_file": "duk_unicode_wtf8.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 113085
|
||||
},
|
||||
{
|
||||
"original_file": "duk_util_bitdecoder.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 114166
|
||||
},
|
||||
{
|
||||
"original_file": "duk_util_bitencoder.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 114330
|
||||
},
|
||||
{
|
||||
"original_file": "duk_util_bufwriter.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 114373
|
||||
},
|
||||
{
|
||||
"original_file": "duk_util_cast.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 114659
|
||||
},
|
||||
{
|
||||
"original_file": "duk_util_double.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 114831
|
||||
},
|
||||
{
|
||||
"original_file": "duk_util_hashbytes.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 115174
|
||||
},
|
||||
{
|
||||
"original_file": "duk_util_memory.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 115236
|
||||
},
|
||||
{
|
||||
"original_file": "duk_util_tinyrandom.c",
|
||||
"original_line": 1,
|
||||
"combined_line": 115272
|
||||
}
|
||||
]
|
||||
}
|
||||
115403
core/lib/duktape/src/duktape.c
Normal file
115403
core/lib/duktape/src/duktape.c
Normal file
File diff suppressed because it is too large
Load Diff
1469
core/lib/duktape/src/duktape.h
Normal file
1469
core/lib/duktape/src/duktape.h
Normal file
File diff suppressed because it is too large
Load Diff
392
core/src/compat.c
Normal file
392
core/src/compat.c
Normal file
@@ -0,0 +1,392 @@
|
||||
#include <Uefi.h>
|
||||
#include <Library/BaseLib.h>
|
||||
#include <Library/BaseMemoryLib.h>
|
||||
#include <Library/MemoryAllocationLib.h>
|
||||
#include <Library/PrintLib.h>
|
||||
#include <Library/UefiBootServicesTableLib.h>
|
||||
|
||||
// EDK2 CRT Support Header
|
||||
#include <CrtLibSupport.h>
|
||||
|
||||
// Global variables required by CrtLibSupport.h
|
||||
int errno = 0;
|
||||
FILE *stderr = NULL;
|
||||
|
||||
// Better malloc/free with size tracking
|
||||
typedef struct {
|
||||
size_t size;
|
||||
char data[];
|
||||
} AllocHeader;
|
||||
|
||||
void *my_malloc(size_t size) {
|
||||
AllocHeader *hdr;
|
||||
if (gBS->AllocatePool(EfiLoaderData, size + sizeof(AllocHeader), (void**)&hdr) != EFI_SUCCESS) {
|
||||
return NULL;
|
||||
}
|
||||
hdr->size = size;
|
||||
return hdr->data;
|
||||
}
|
||||
|
||||
void my_free(void *ptr) {
|
||||
if (ptr) {
|
||||
AllocHeader *hdr = (AllocHeader*)((char*)ptr - sizeof(AllocHeader));
|
||||
gBS->FreePool(hdr);
|
||||
}
|
||||
}
|
||||
|
||||
void *my_realloc(void *ptr, size_t size) {
|
||||
if (!ptr) return my_malloc(size);
|
||||
if (size == 0) {
|
||||
my_free(ptr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
AllocHeader *old_hdr = (AllocHeader*)((char*)ptr - sizeof(AllocHeader));
|
||||
size_t old_size = old_hdr->size;
|
||||
|
||||
void *new_ptr = my_malloc(size);
|
||||
if (!new_ptr) return NULL;
|
||||
|
||||
CopyMem(new_ptr, ptr, old_size < size ? old_size : size);
|
||||
my_free(ptr);
|
||||
return new_ptr;
|
||||
}
|
||||
|
||||
// Redirect standard malloc/free/realloc to our versions
|
||||
#undef malloc
|
||||
#undef free
|
||||
#undef realloc
|
||||
|
||||
void *malloc(size_t size) { return my_malloc(size); }
|
||||
void free(void *ptr) { my_free(ptr); }
|
||||
void *realloc(void *ptr, size_t size) { return my_realloc(ptr, size); }
|
||||
|
||||
void *calloc(size_t nmemb, size_t size) {
|
||||
size_t total = nmemb * size;
|
||||
void *ptr = malloc(total);
|
||||
if (ptr) {
|
||||
SetMem(ptr, total, 0);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
// IO
|
||||
int printf(const char *format, ...) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int vsnprintf(char *str, size_t size, const char *format, va_list ap) {
|
||||
return (int)AsciiVSPrint(str, size, format, ap);
|
||||
}
|
||||
|
||||
int snprintf(char *str, size_t size, const char *format, ...) {
|
||||
VA_LIST Marker;
|
||||
VA_START(Marker, format);
|
||||
UINTN Return = AsciiVSPrint(str, size, format, Marker);
|
||||
VA_END(Marker);
|
||||
return (int)Return;
|
||||
}
|
||||
|
||||
// sprintf is a macro in CrtLibSupport.h, so we don't define it.
|
||||
|
||||
|
||||
// Math functions
|
||||
// Duktape needs math functions for proper numeric conversions and bitwise operations.
|
||||
// EDK2 doesn't provide a standard math library, so we implement basic versions here.
|
||||
|
||||
double fabs(double x) {
|
||||
return x < 0.0 ? -x : x;
|
||||
}
|
||||
|
||||
double floor(double x) {
|
||||
if (x >= 0.0) {
|
||||
return (double)(INT64)x;
|
||||
} else {
|
||||
INT64 i = (INT64)x;
|
||||
return (double)((x == (double)i) ? i : i - 1);
|
||||
}
|
||||
}
|
||||
|
||||
double ceil(double x) {
|
||||
if (x >= 0.0) {
|
||||
INT64 i = (INT64)x;
|
||||
return (double)((x == (double)i) ? i : i + 1);
|
||||
} else {
|
||||
return (double)(INT64)x;
|
||||
}
|
||||
}
|
||||
|
||||
double trunc(double x) {
|
||||
return (double)(INT64)x;
|
||||
}
|
||||
|
||||
double fmod(double x, double y) {
|
||||
if (y == 0.0) return 0.0;
|
||||
INT64 quotient = (INT64)(x / y);
|
||||
return x - quotient * y;
|
||||
}
|
||||
|
||||
// Newton-Raphson square root implementation
|
||||
double sqrt(double x) {
|
||||
if (x < 0.0) return 0.0; // Return 0 for negative (should be NaN)
|
||||
if (x == 0.0) return 0.0;
|
||||
|
||||
double guess = x;
|
||||
double epsilon = 0.00001;
|
||||
|
||||
// Newton-Raphson: x_new = (x_old + n/x_old) / 2
|
||||
for (int i = 0; i < 50; i++) {
|
||||
double next = (guess + x / guess) / 2.0;
|
||||
if (fabs(next - guess) < epsilon) break;
|
||||
guess = next;
|
||||
}
|
||||
|
||||
return guess;
|
||||
}
|
||||
|
||||
// Power function using binary exponentiation for integer exponents
|
||||
double pow(double base, double exponent) {
|
||||
// Handle special cases
|
||||
if (exponent == 0.0) return 1.0;
|
||||
if (base == 0.0) return 0.0;
|
||||
if (base == 1.0) return 1.0;
|
||||
if (exponent == 1.0) return base;
|
||||
|
||||
// Check if exponent is an integer
|
||||
INT64 exp_int = (INT64)exponent;
|
||||
if ((double)exp_int == exponent) {
|
||||
// Integer exponent - use binary exponentiation
|
||||
double result = 1.0;
|
||||
double current = base;
|
||||
UINT64 n = (exp_int < 0) ? -exp_int : exp_int;
|
||||
|
||||
while (n > 0) {
|
||||
if (n & 1) result *= current;
|
||||
current *= current;
|
||||
n >>= 1;
|
||||
}
|
||||
|
||||
return (exp_int < 0) ? (1.0 / result) : result;
|
||||
}
|
||||
|
||||
// For non-integer exponents, return 0 (would need exp/log)
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
// Trigonometric functions - stubs (not needed for bitwise ops)
|
||||
double sin(double x) { return 0.0; }
|
||||
double cos(double x) { return 0.0; }
|
||||
double tan(double x) { return 0.0; }
|
||||
double asin(double x) { return 0.0; }
|
||||
double acos(double x) { return 0.0; }
|
||||
double atan(double x) { return 0.0; }
|
||||
double atan2(double y, double x) { return 0.0; }
|
||||
double exp(double x) { return 0.0; }
|
||||
double log(double x) { return 0.0; }
|
||||
double log10(double x) { return 0.0; }
|
||||
double cbrt(double x) { return 0.0; }
|
||||
double log2(double x) { return 0.0; }
|
||||
|
||||
// Other
|
||||
void abort(void) {
|
||||
// CpuDeadLoop();
|
||||
while(1);
|
||||
}
|
||||
|
||||
void exit(int status) {
|
||||
// CpuDeadLoop();
|
||||
while(1);
|
||||
}
|
||||
|
||||
// Global gBS
|
||||
EFI_BOOT_SERVICES *gBS = NULL;
|
||||
int _fltused = 0;
|
||||
|
||||
// Stack probe (needed for MSVC ABI)
|
||||
void __chkstk(void) { return; }
|
||||
|
||||
// Memory functions
|
||||
#undef memset
|
||||
#undef memcpy
|
||||
#undef memcmp
|
||||
|
||||
void *memset(void *s, int c, size_t n) {
|
||||
unsigned char *p = s;
|
||||
while (n--) {
|
||||
*p++ = (unsigned char)c;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
void *memcpy(void *dest, const void *src, size_t n) {
|
||||
char *d = dest;
|
||||
const char *s = src;
|
||||
while (n--) {
|
||||
*d++ = *s++;
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
|
||||
int memcmp(const void *s1, const void *s2, size_t n) {
|
||||
const unsigned char *p1 = s1, *p2 = s2;
|
||||
while (n--) {
|
||||
if (*p1 != *p2) {
|
||||
return *p1 - *p2;
|
||||
}
|
||||
p1++;
|
||||
p2++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *SetMem(void *Buffer, UINTN Length, UINT8 Value) {
|
||||
return memset(Buffer, Value, Length);
|
||||
}
|
||||
|
||||
void *CopyMem(void *Destination, const void *Source, UINTN Length) {
|
||||
return memcpy(Destination, Source, Length);
|
||||
}
|
||||
|
||||
INTN CompareMem(const void *Destination, const void *Source, UINTN Length) {
|
||||
return (INTN)memcmp(Destination, Source, Length);
|
||||
}
|
||||
|
||||
// String functions
|
||||
UINTN AsciiStrnLenS(const CHAR8 *String, UINTN MaxSize) {
|
||||
UINTN len = 0;
|
||||
while (len < MaxSize && String[len] != 0) {
|
||||
len++;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
INTN AsciiStrnCmp(const CHAR8 *FirstString, const CHAR8 *SecondString, UINTN Length) {
|
||||
if (Length == 0) return 0;
|
||||
while (Length > 0 && *FirstString && *SecondString) {
|
||||
if (*FirstString != *SecondString) break;
|
||||
FirstString++;
|
||||
SecondString++;
|
||||
Length--;
|
||||
}
|
||||
if (Length == 0) return 0;
|
||||
return *FirstString - *SecondString;
|
||||
}
|
||||
|
||||
int strcmp(const char *s1, const char *s2) {
|
||||
while (*s1 && (*s1 == *s2)) {
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
return *(const unsigned char *)s1 - *(const unsigned char *)s2;
|
||||
}
|
||||
|
||||
// Print functions
|
||||
// Minimal vsnprintf implementation
|
||||
#include <stdarg.h>
|
||||
static void simple_append(char **str, size_t *size, char c) {
|
||||
if (*size > 1) {
|
||||
**str = c;
|
||||
(*str)++;
|
||||
(*size)--;
|
||||
}
|
||||
}
|
||||
|
||||
static void simple_append_str(char **str, size_t *size, const char *s) {
|
||||
while (*s) {
|
||||
simple_append(str, size, *s++);
|
||||
}
|
||||
}
|
||||
|
||||
static void simple_append_hex(char **str, size_t *size, UINT64 num) {
|
||||
char buf[17];
|
||||
const char *digits = "0123456789ABCDEF";
|
||||
int i = 0;
|
||||
if (num == 0) {
|
||||
simple_append(str, size, '0');
|
||||
return;
|
||||
}
|
||||
while (num > 0) {
|
||||
buf[i++] = digits[num % 16];
|
||||
num /= 16;
|
||||
}
|
||||
while (i > 0) {
|
||||
simple_append(str, size, buf[--i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void simple_append_dec(char **str, size_t *size, INT64 num) {
|
||||
char buf[21];
|
||||
int i = 0;
|
||||
int neg = 0;
|
||||
if (num < 0) {
|
||||
neg = 1;
|
||||
num = -num;
|
||||
}
|
||||
if (num == 0) {
|
||||
simple_append(str, size, '0');
|
||||
return;
|
||||
}
|
||||
while (num > 0) {
|
||||
buf[i++] = (num % 10) + '0';
|
||||
num /= 10;
|
||||
}
|
||||
if (neg) simple_append(str, size, '-');
|
||||
while (i > 0) {
|
||||
simple_append(str, size, buf[--i]);
|
||||
}
|
||||
}
|
||||
|
||||
UINTN AsciiVSPrint(CHAR8 *StartOfBuffer, UINTN BufferSize, CONST CHAR8 *FormatString, VA_LIST Marker) {
|
||||
char *str = StartOfBuffer;
|
||||
size_t size = BufferSize;
|
||||
const char *fmt = FormatString;
|
||||
|
||||
while (*fmt) {
|
||||
if (*fmt == '%') {
|
||||
fmt++;
|
||||
if (*fmt == 's') {
|
||||
char *s = VA_ARG(Marker, char*);
|
||||
simple_append_str(&str, &size, s ? s : "(null)");
|
||||
} else if (*fmt == 'd') {
|
||||
int d = VA_ARG(Marker, int);
|
||||
simple_append_dec(&str, &size, d);
|
||||
} else if (*fmt == 'x' || *fmt == 'X') {
|
||||
unsigned int x = VA_ARG(Marker, unsigned int);
|
||||
simple_append_hex(&str, &size, x);
|
||||
} else if (*fmt == 'p') {
|
||||
void *p = VA_ARG(Marker, void*);
|
||||
simple_append_hex(&str, &size, (UINT64)p);
|
||||
} else if (*fmt == '%') {
|
||||
simple_append(&str, &size, '%');
|
||||
} else {
|
||||
simple_append(&str, &size, '%');
|
||||
simple_append(&str, &size, *fmt);
|
||||
}
|
||||
} else {
|
||||
simple_append(&str, &size, *fmt);
|
||||
}
|
||||
fmt++;
|
||||
}
|
||||
*str = 0;
|
||||
return (UINTN)(str - StartOfBuffer);
|
||||
}
|
||||
|
||||
UINTN AsciiSPrint(CHAR8 *StartOfBuffer, UINTN BufferSize, CONST CHAR8 *FormatString, ...) {
|
||||
VA_LIST Marker;
|
||||
VA_START(Marker, FormatString);
|
||||
UINTN ret = AsciiVSPrint(StartOfBuffer, BufferSize, FormatString, Marker);
|
||||
VA_END(Marker);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Time functions
|
||||
struct tm *gmtime(const time_t *timep) { return NULL; }
|
||||
time_t mktime(struct tm *tm) { return 0; }
|
||||
int sscanf(const char *str, const char *format, ...) { return 0; }
|
||||
|
||||
time_t time(time_t *tloc) { return 0; }
|
||||
double difftime(time_t time1, time_t time0) { return (double)(time1 - time0); }
|
||||
|
||||
|
||||
// Needed for CrtLibSupport headers to work?
|
||||
// They use VA_LIST etc which are in Base.h
|
||||
12
core/src/efi.c
Normal file
12
core/src/efi.c
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "efi.h"
|
||||
#include "main.h"
|
||||
|
||||
extern EFI_BOOT_SERVICES *gBS;
|
||||
|
||||
EFI_STATUS EFIAPI efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) {
|
||||
gBS = SystemTable->BootServices;
|
||||
|
||||
// Initialize standard library (if needed)
|
||||
// ...
|
||||
return kernel_main(SystemTable);
|
||||
}
|
||||
13
core/src/efi.h
Normal file
13
core/src/efi.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef EFI_H
|
||||
#define EFI_H
|
||||
|
||||
#ifndef MDE_CPU_X64
|
||||
#define MDE_CPU_X64
|
||||
#endif
|
||||
|
||||
#include <Uefi.h>
|
||||
|
||||
// Map legacy names if needed, or update main.c
|
||||
typedef EFI_SYSTEM_TABLE EfiSystemTable;
|
||||
|
||||
#endif
|
||||
147
core/src/main.c
Normal file
147
core/src/main.c
Normal file
@@ -0,0 +1,147 @@
|
||||
#include "main.h"
|
||||
#include "efi.h"
|
||||
#include "efi.h"
|
||||
#include <Protocol/CpuIo2.h>
|
||||
#include <Protocol/PciRootBridgeIo.h>
|
||||
#include "duktape.h"
|
||||
#include "embedded_js.h"
|
||||
|
||||
duk_context *ctx;
|
||||
EFI_SYSTEM_TABLE* systemTable;
|
||||
|
||||
void halt() {
|
||||
for (;;) {}
|
||||
}
|
||||
|
||||
void ascii_to_utf16(const char *ascii, CHAR16 *utf16) {
|
||||
while (*ascii) {
|
||||
*utf16++ = (CHAR16)*ascii++;
|
||||
}
|
||||
*utf16 = 0;
|
||||
}
|
||||
|
||||
duk_ret_t native_systable_conout_output_string(duk_context *ctx) {
|
||||
CHAR16 buffer[256];
|
||||
ascii_to_utf16(duk_safe_to_string(ctx, 0), buffer);
|
||||
systemTable->ConOut->OutputString(systemTable->ConOut, buffer);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
duk_ret_t native_systable_conout_clear_screen(duk_context *ctx) {
|
||||
systemTable->ConOut->ClearScreen(systemTable->ConOut);
|
||||
return 0;
|
||||
}
|
||||
|
||||
duk_ret_t native_systable_conout_set_attribute(duk_context *ctx) {
|
||||
systemTable->ConOut->SetAttribute(systemTable->ConOut, duk_to_uint(ctx, 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
duk_ret_t native_systable_io_dword_in(duk_context *ctx) {
|
||||
EFI_CPU_IO2_PROTOCOL* cpuIo;
|
||||
EFI_GUID cpuIoGuid = EFI_CPU_IO2_PROTOCOL_GUID;
|
||||
systemTable->BootServices->LocateProtocol(&cpuIoGuid, NULL, (void**)&cpuIo);
|
||||
|
||||
UINT32 data;
|
||||
cpuIo->Io.Read(cpuIo, EfiCpuIoWidthUint32, duk_to_uint(ctx, 0), 1, &data);
|
||||
duk_push_uint(ctx, data);
|
||||
return 1;
|
||||
}
|
||||
|
||||
duk_ret_t native_systable_io_dword_out(duk_context *ctx) {
|
||||
EFI_CPU_IO2_PROTOCOL* cpuIo;
|
||||
EFI_GUID cpuIoGuid = EFI_CPU_IO2_PROTOCOL_GUID;
|
||||
systemTable->BootServices->LocateProtocol(&cpuIoGuid, NULL, (void**)&cpuIo);
|
||||
|
||||
UINT32 data = duk_to_uint(ctx, 1);
|
||||
cpuIo->Io.Write(cpuIo, EfiCpuIoWidthUint32, duk_to_uint(ctx, 0), 1, &data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
duk_ret_t native_systable_pci_read_config(duk_context *ctx) {
|
||||
EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL* pci;
|
||||
EFI_GUID pciGuid = EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_GUID;
|
||||
systemTable->BootServices->LocateProtocol(&pciGuid, NULL, (void**)&pci);
|
||||
|
||||
UINT64 bus = duk_to_uint(ctx, 0);
|
||||
UINT64 device = duk_to_uint(ctx, 1);
|
||||
UINT64 func = duk_to_uint(ctx, 2);
|
||||
UINT64 offset = duk_to_uint(ctx, 3);
|
||||
UINT64 address = (bus << 24) | (device << 16) | (func << 8) | (offset & 0xff);
|
||||
UINT32 data = 0;
|
||||
|
||||
pci->Pci.Read(pci, EfiPciWidthUint32, address, 1, &data);
|
||||
|
||||
duk_push_uint(ctx, data);
|
||||
return 1;
|
||||
}
|
||||
|
||||
duk_ret_t native_systable_pci_write_config(duk_context *ctx) {
|
||||
EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL* pci;
|
||||
EFI_GUID pciGuid = EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_GUID;
|
||||
systemTable->BootServices->LocateProtocol(&pciGuid, NULL, (void**)&pci);
|
||||
|
||||
UINT64 bus = duk_to_uint(ctx, 0);
|
||||
UINT64 device = duk_to_uint(ctx, 1);
|
||||
UINT64 func = duk_to_uint(ctx, 2);
|
||||
UINT64 offset = duk_to_uint(ctx, 3);
|
||||
UINT64 address = (bus << 24) | (device << 16) | (func << 8) | (offset & 0xff);
|
||||
UINT32 data = duk_to_uint(ctx, 4);
|
||||
|
||||
pci->Pci.Write(pci, EfiPciWidthUint32, address, 1, &data);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int kernel_main(EFI_SYSTEM_TABLE *st) {
|
||||
systemTable = st;
|
||||
systemTable->ConOut->ClearScreen(systemTable->ConOut);
|
||||
systemTable->ConOut->OutputString(systemTable->ConOut, L"START\r\n");
|
||||
|
||||
ctx = duk_create_heap_default();
|
||||
|
||||
duk_push_c_function(ctx, native_systable_conout_output_string, 1);
|
||||
duk_put_global_string(ctx, "$___native_systable_conout_outputString");
|
||||
|
||||
duk_push_c_function(ctx, native_systable_conout_clear_screen, 0);
|
||||
duk_put_global_string(ctx, "$___native_systable_conout_clearScreen");
|
||||
|
||||
duk_push_c_function(ctx, native_systable_conout_set_attribute, 1);
|
||||
duk_put_global_string(ctx, "$___native_systable_conout_setAttribute");
|
||||
|
||||
duk_push_c_function(ctx, native_systable_io_dword_in, 1);
|
||||
duk_put_global_string(ctx, "$___native_systable_io_dword_in");
|
||||
|
||||
duk_push_c_function(ctx, native_systable_io_dword_out, 2);
|
||||
duk_put_global_string(ctx, "$___native_systable_io_dword_out");
|
||||
|
||||
duk_push_c_function(ctx, native_systable_pci_read_config, 4);
|
||||
duk_put_global_string(ctx, "$___native_systable_pci_read_config");
|
||||
|
||||
duk_push_c_function(ctx, native_systable_pci_write_config, 5);
|
||||
duk_put_global_string(ctx, "$___native_systable_pci_write_config");
|
||||
|
||||
systemTable->ConOut->OutputString(systemTable->ConOut, L"RUN\r\n");
|
||||
|
||||
duk_push_string(ctx, EMBEDDED_JS);
|
||||
duk_int_t returnCode = duk_peval(ctx);
|
||||
|
||||
/*if (returnCode != 0)
|
||||
{
|
||||
duk_safe_to_stacktrace(ctx, -1);
|
||||
|
||||
CHAR16 buffer[256];
|
||||
ascii_to_utf16(duk_safe_to_string(ctx, -1), buffer);
|
||||
systemTable->ConOut->OutputString(systemTable->ConOut, buffer);
|
||||
}
|
||||
|
||||
duk_pop(ctx);*/
|
||||
|
||||
systemTable->ConOut->OutputString(systemTable->ConOut, L"!!! KERNEL EXITED UNEXPECTEDLY !!!\r\n");
|
||||
|
||||
halt();
|
||||
|
||||
return 0;
|
||||
}
|
||||
8
core/src/main.h
Normal file
8
core/src/main.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#include "efi.h"
|
||||
|
||||
#ifndef MAIN_H
|
||||
#define MAIN_H
|
||||
|
||||
int kernel_main(EFI_SYSTEM_TABLE* systemTable);
|
||||
|
||||
#endif
|
||||
@@ -1,21 +0,0 @@
|
||||
FROM fedora:41
|
||||
|
||||
RUN dnf install -y \
|
||||
gcc \
|
||||
gcc-c++ \
|
||||
make \
|
||||
nasm \
|
||||
python3 \
|
||||
git \
|
||||
qemu-system-x86 \
|
||||
wget \
|
||||
meson \
|
||||
unzip \
|
||||
&& dnf clean all
|
||||
|
||||
RUN curl -fsSL https://bun.sh/install | bash
|
||||
ENV PATH="/root/.bun/bin:${PATH}"
|
||||
|
||||
WORKDIR /workspace
|
||||
|
||||
CMD ["bash", "-c", "/workspace/scripts/build-picolibc.sh && /workspace/scripts/build-kernel.sh"]
|
||||
1
edk2
Submodule
1
edk2
Submodule
Submodule edk2 added at aacfbe667e
0
src/os/.gitignore → os/.gitignore
vendored
0
src/os/.gitignore → os/.gitignore
vendored
15
os/README.md
Normal file
15
os/README.md
Normal file
@@ -0,0 +1,15 @@
|
||||
# os
|
||||
|
||||
To install dependencies:
|
||||
|
||||
```bash
|
||||
bun install
|
||||
```
|
||||
|
||||
To run:
|
||||
|
||||
```bash
|
||||
bun run index.ts
|
||||
```
|
||||
|
||||
This project was created using `bun init` in bun v1.2.20. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime.
|
||||
@@ -12,15 +12,11 @@
|
||||
},
|
||||
},
|
||||
"packages": {
|
||||
"@types/bun": ["@types/bun@1.3.2", "", { "dependencies": { "bun-types": "1.3.2" } }, "sha512-t15P7k5UIgHKkxwnMNkJbWlh/617rkDGEdSsDbu+qNHTaz9SKf7aC8fiIlUdD5RPpH6GEkP0cK7WlvmrEBRtWg=="],
|
||||
"@types/bun": ["@types/bun@1.3.3", "", { "dependencies": { "bun-types": "1.3.3" } }, "sha512-ogrKbJ2X5N0kWLLFKeytG0eHDleBYtngtlbu9cyBKFtNL3cnpDZkNdQj8flVf6WTZUX5ulI9AY1oa7ljhSrp+g=="],
|
||||
|
||||
"@types/node": ["@types/node@24.10.1", "", { "dependencies": { "undici-types": "~7.16.0" } }, "sha512-GNWcUTRBgIRJD5zj+Tq0fKOJ5XZajIiBroOF0yvj2bSU1WvNdYS/dn9UxwsujGW4JX06dnHyjV2y9rRaybH0iQ=="],
|
||||
|
||||
"@types/react": ["@types/react@19.2.6", "", { "dependencies": { "csstype": "^3.2.2" } }, "sha512-p/jUvulfgU7oKtj6Xpk8cA2Y1xKTtICGpJYeJXz2YVO2UcvjQgeRMLDGfDeqeRW2Ta+0QNFwcc8X3GH8SxZz6w=="],
|
||||
|
||||
"bun-types": ["bun-types@1.3.2", "", { "dependencies": { "@types/node": "*" }, "peerDependencies": { "@types/react": "^19" } }, "sha512-i/Gln4tbzKNuxP70OWhJRZz1MRfvqExowP7U6JKoI8cntFrtxg7RJK3jvz7wQW54UuvNC8tbKHHri5fy74FVqg=="],
|
||||
|
||||
"csstype": ["csstype@3.2.3", "", {}, "sha512-z1HGKcYy2xA8AGQfwrn0PAy+PB7X/GSj3UVJW9qKyn43xWa+gl5nXmU4qqLMRzWVLFC8KusUX8T/0kCiOYpAIQ=="],
|
||||
"bun-types": ["bun-types@1.3.3", "", { "dependencies": { "@types/node": "*" } }, "sha512-z3Xwlg7j2l9JY27x5Qn3Wlyos8YAp0kKRlrePAOjgjMGS5IG6E7Jnlx736vH9UVI4wUICwwhC9anYL++XeOgTQ=="],
|
||||
|
||||
"typescript": ["typescript@5.9.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw=="],
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "os",
|
||||
"module": "index.ts",
|
||||
"module": "src/index.ts",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
"devDependencies": {
|
||||
@@ -2,7 +2,11 @@ import { kmain } from "./kernel";
|
||||
import { kpanic } from "./kernel/panic";
|
||||
|
||||
try {
|
||||
kmain();
|
||||
const res = kmain();
|
||||
|
||||
if (res != 0) {
|
||||
kpanic("Kernel returned non-zero exit code");
|
||||
}
|
||||
} catch (e) {
|
||||
kpanic(e instanceof Error ? e.message : String(e));
|
||||
}
|
||||
@@ -1,13 +1,10 @@
|
||||
import { dwordin, dwordout } from "../../../lib/libts/dword";
|
||||
import { portin, portout } from "../../../lib/libts/port";
|
||||
import { Logger } from "../../../lib/libstd/logger/logger.kmod";
|
||||
import { sysfs_mkdir, sysfs_writeFile } from "../../filesystem/sysfs";
|
||||
import { Path } from "../../../lib/libstd/path";
|
||||
import { Logger } from "../../../libs/logger";
|
||||
import { Path } from "../../../libs/path";
|
||||
import { sysfs, sysfs_mkdir, sysfs_writeFile } from "../../filesystem/sysfs";
|
||||
|
||||
const KDRIVER_PCI_CONFIG_ADDR = 0xcf8;
|
||||
const KDRIVER_PCI_CONFIG_DATA = 0xcfc;
|
||||
|
||||
export function kdriver_dev_pci_init() {}
|
||||
export function kdriver_dev_pci_init() {
|
||||
sysfs_mkdir("/pci");
|
||||
}
|
||||
|
||||
export function kdriver_dev_pci_detectDevices() {
|
||||
Logger.log("[PCI] Scanning...");
|
||||
@@ -31,11 +28,15 @@ export function kdriver_dev_pci_checkDevice(
|
||||
device: number,
|
||||
func: number
|
||||
) {
|
||||
const vendorId = kdriver_dev_pci_getVendorId(bus, device, func);
|
||||
const data = kdriver_dev_pci_readConfigDword(bus, device, func, 0);
|
||||
|
||||
if (vendorId === 0xffff) return;
|
||||
if (data === 0 || data === -1) return;
|
||||
|
||||
const vendorId = data & 0xffff;
|
||||
const deviceId = data >>> 16;
|
||||
|
||||
if (vendorId === 0 || vendorId === 0xffff) return;
|
||||
|
||||
const deviceId = kdriver_dev_pci_getDeviceId(bus, device, func);
|
||||
const classCode = kdriver_dev_pci_getClassCode(bus, device, func);
|
||||
const subclass = kdriver_dev_pci_getSubclass(bus, device, func);
|
||||
|
||||
@@ -58,10 +59,11 @@ export function kdriver_dev_pci_checkDevice(
|
||||
const dirname = Path.join("/pci", filename);
|
||||
|
||||
sysfs_mkdir(dirname);
|
||||
sysfs_writeFile(Path.join(dirname, "vendor"), vendorId);
|
||||
sysfs_writeFile(Path.join(dirname, "device"), deviceId);
|
||||
sysfs_writeFile(Path.join(dirname, "class"), classCode);
|
||||
sysfs_writeFile(Path.join(dirname, "subclass"), subclass);
|
||||
sysfs_writeFile(Path.join(dirname, "vendor"), "Intel");
|
||||
/*sysfs_writeFile(Path.join(dirname, "vendor"), vendorId.toString(16));
|
||||
sysfs_writeFile(Path.join(dirname, "device"), deviceId.toString(16));
|
||||
sysfs_writeFile(Path.join(dirname, "class"), classCode.toString(16));
|
||||
sysfs_writeFile(Path.join(dirname, "subclass"), subclass.toString(16));*/
|
||||
}
|
||||
|
||||
export function kdriver_dev_pci_getDeviceId(
|
||||
@@ -71,7 +73,7 @@ export function kdriver_dev_pci_getDeviceId(
|
||||
) {
|
||||
const data = kdriver_dev_pci_readConfigDword(bus, device, func, 0);
|
||||
|
||||
return data >> 16;
|
||||
return data >>> 16;
|
||||
}
|
||||
|
||||
export function kdriver_dev_pci_getVendorId(
|
||||
@@ -120,11 +122,5 @@ export function kdriver_dev_pci_readConfigDword(
|
||||
func: number,
|
||||
offset: number
|
||||
) {
|
||||
const address =
|
||||
(1 << 31) | (bus << 16) | (device << 11) | (func << 8) | (offset & 0xfc);
|
||||
|
||||
dwordout(KDRIVER_PCI_CONFIG_ADDR, address);
|
||||
const data = dwordin(KDRIVER_PCI_CONFIG_DATA);
|
||||
|
||||
return data;
|
||||
return $___native_systable_pci_read_config(bus, device, func, offset);
|
||||
}
|
||||
106
os/src/kernel/filesystem/sysfs.ts
Normal file
106
os/src/kernel/filesystem/sysfs.ts
Normal file
@@ -0,0 +1,106 @@
|
||||
import { Logger } from "../../libs/logger";
|
||||
import { Path } from "../../libs/path";
|
||||
import {
|
||||
FilesystemType,
|
||||
type Filesystem,
|
||||
type FilesystemEntity,
|
||||
} from "../../types/kernel/filesystem";
|
||||
|
||||
const sysfs_data: FilesystemEntity[] = [];
|
||||
|
||||
export function sysfs(): Filesystem {
|
||||
return {
|
||||
type: FilesystemType.SYSFS,
|
||||
mkdir: sysfs_mkdir,
|
||||
ls: sysfs_ls,
|
||||
writeFile(path, content) {
|
||||
throw new Error("Cannot write to sysfs");
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function sysfs_root(): FilesystemEntity {
|
||||
/*return {
|
||||
name: "$root",
|
||||
path: "/",
|
||||
size: 0,
|
||||
isDirectory: true,
|
||||
contents: null,
|
||||
};*/
|
||||
}
|
||||
|
||||
export function sysfs_get(path: string): FilesystemEntity | null {
|
||||
if (path == "" || path == "/") return sysfs_root();
|
||||
|
||||
for (let i = 0; i < sysfs_data.length; i++) {
|
||||
Logger.log(sysfs_data[i]);
|
||||
|
||||
if (sysfs_data[i]!.path === path) {
|
||||
return sysfs_data[i]!;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function sysfs_mkdir(path: string) {
|
||||
if (sysfs_get(path)) return;
|
||||
|
||||
const parent = sysfs_get(Path.dirname(path));
|
||||
if (!parent || !parent.isDirectory) return;
|
||||
|
||||
Logger.log(path);
|
||||
|
||||
/*sysfs_data.push({
|
||||
name: Path.filename(path),
|
||||
path: path,
|
||||
size: 0,
|
||||
isDirectory: true,
|
||||
contents: 0,
|
||||
});*/
|
||||
}
|
||||
|
||||
export function sysfs_ls(path: string): FilesystemEntity[] | null {
|
||||
/*const entity = sysfs_get(path);
|
||||
if (!entity || !entity.isDirectory) return null;
|
||||
|
||||
const result: FilesystemEntity[] = [];
|
||||
const prefix = path + "/";
|
||||
|
||||
for (let i = 0; i < globalThis.sysfs_data.length; i++) {
|
||||
const itemPath = globalThis.sysfs_data[i]!.path;
|
||||
|
||||
// Only include direct children (no additional slashes after the prefix)
|
||||
if (
|
||||
itemPath.startsWith(prefix) &&
|
||||
!itemPath.substring(prefix.length).includes("/")
|
||||
) {
|
||||
result.push(globalThis.sysfs_data[i]!);
|
||||
}
|
||||
}
|
||||
|
||||
return result;*/
|
||||
}
|
||||
|
||||
export function sysfs_createFile(path: string, content: string) {
|
||||
if (sysfs_get(path)) return;
|
||||
|
||||
/*const parent = sysfs_getParent(path);
|
||||
if (!parent || !parent.isDirectory) return;
|
||||
|
||||
globalThis.sysfs_data.push({
|
||||
name: Path.filename(path),
|
||||
path: path,
|
||||
size: content.length,
|
||||
isDirectory: false,
|
||||
contents: content,
|
||||
});*/
|
||||
}
|
||||
|
||||
export function sysfs_writeFile(path: string, content: string) {
|
||||
const entity = sysfs_get(path);
|
||||
/*if (!entity) return sysfs_createFile(path, content);
|
||||
if (entity.isDirectory) return;
|
||||
|
||||
entity.contents = content;*/
|
||||
}
|
||||
26
os/src/kernel/index.ts
Normal file
26
os/src/kernel/index.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { Logger } from "../libs/logger";
|
||||
import { kdriver_dev_pci_detectDevices } from "./drivers/dev/pci.kdriver";
|
||||
import { sysfs_ls } from "./filesystem/sysfs";
|
||||
import {
|
||||
kmod_console_clearScreen,
|
||||
kmod_console_outputString,
|
||||
} from "./modules/console/console.kmod";
|
||||
import { kmod_drivers_init } from "./modules/drivers.kmod";
|
||||
|
||||
export function kmain() {
|
||||
kmod_console_clearScreen();
|
||||
|
||||
Logger.log("[Kernel] Starting kernel...");
|
||||
|
||||
kmod_drivers_init();
|
||||
|
||||
kdriver_dev_pci_detectDevices();
|
||||
|
||||
/*const files = sysfs_ls("/");
|
||||
|
||||
files!.forEach(function (file) {
|
||||
Logger.log(file.name);
|
||||
});*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
11
os/src/kernel/modules/console/console.kmod.ts
Normal file
11
os/src/kernel/modules/console/console.kmod.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
export function kmod_console_clearScreen() {
|
||||
$___native_systable_conout_clearScreen();
|
||||
}
|
||||
|
||||
export function kmod_console_setAttribute(attribute: number) {
|
||||
$___native_systable_conout_setAttribute(attribute);
|
||||
}
|
||||
|
||||
export function kmod_console_outputString(string: string) {
|
||||
$___native_systable_conout_outputString(string);
|
||||
}
|
||||
12
os/src/kernel/modules/drivers.kmod.ts
Normal file
12
os/src/kernel/modules/drivers.kmod.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { Logger } from "../../libs/logger";
|
||||
import { kdriver_dev_pci_init } from "../drivers/dev/pci.kdriver";
|
||||
|
||||
const drivers = [kdriver_dev_pci_init];
|
||||
|
||||
export function kmod_drivers_init() {
|
||||
Logger.log("[Kernel] Initializing drivers...");
|
||||
|
||||
for (let i = 0; i < drivers.length; i++) {
|
||||
drivers[i]!();
|
||||
}
|
||||
}
|
||||
12
os/src/kernel/panic.ts
Normal file
12
os/src/kernel/panic.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import {
|
||||
kmod_console_clearScreen,
|
||||
kmod_console_outputString,
|
||||
kmod_console_setAttribute,
|
||||
} from "./modules/console/console.kmod";
|
||||
|
||||
export function kpanic(message: string) {
|
||||
kmod_console_clearScreen();
|
||||
kmod_console_setAttribute(0x0c);
|
||||
kmod_console_outputString("Kernel panic: \\r\\n");
|
||||
kmod_console_outputString(message);
|
||||
}
|
||||
7
os/src/libs/io.ts
Normal file
7
os/src/libs/io.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export function dwordin(port: number): number {
|
||||
return $___native_systable_io_dwordin(port);
|
||||
}
|
||||
|
||||
export function dwordout(port: number, value: number) {
|
||||
$___native_systable_io_dwordout(port, value);
|
||||
}
|
||||
7
os/src/libs/logger.ts
Normal file
7
os/src/libs/logger.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { kmod_console_outputString } from "../kernel/modules/console/console.kmod";
|
||||
|
||||
export const Logger = {
|
||||
log: function (message: string) {
|
||||
kmod_console_outputString(message + "\\r\\n");
|
||||
},
|
||||
};
|
||||
12
os/src/libs/path.ts
Normal file
12
os/src/libs/path.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
export const Path = {
|
||||
join(p1: string, p2: string): string {
|
||||
if (p1.endsWith("/")) return p1 + p2;
|
||||
else return p1 + "/" + p2;
|
||||
},
|
||||
filename(path: string): string {
|
||||
return path.split("/").pop()!;
|
||||
},
|
||||
dirname(path: string): string {
|
||||
return path.split("/").slice(0, -1).join("/");
|
||||
},
|
||||
};
|
||||
26
os/src/types/global_c_bindings.d.ts
vendored
Normal file
26
os/src/types/global_c_bindings.d.ts
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
declare function $___native_systable_conout_outputString(string: string): void;
|
||||
declare function $___native_systable_conout_clearScreen(): void;
|
||||
declare function $___native_systable_conout_setAttribute(
|
||||
attribute: number
|
||||
): void;
|
||||
|
||||
declare function $___native_systable_io_dwordin(port: number): number;
|
||||
declare function $___native_systable_io_dwordout(
|
||||
port: number,
|
||||
value: number
|
||||
): void;
|
||||
|
||||
declare function $___native_systable_pci_read_config(
|
||||
bus: number,
|
||||
device: number,
|
||||
func: number,
|
||||
offset: number
|
||||
): number;
|
||||
|
||||
declare function $___native_systable_pci_write_config(
|
||||
bus: number,
|
||||
device: number,
|
||||
func: number,
|
||||
offset: number,
|
||||
value: number
|
||||
): void;
|
||||
18
os/src/types/kernel/filesystem.ts
Normal file
18
os/src/types/kernel/filesystem.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
export enum FilesystemType {
|
||||
SYSFS,
|
||||
}
|
||||
|
||||
export interface Filesystem {
|
||||
type: FilesystemType;
|
||||
mkdir(path: string): void;
|
||||
ls(path: string): FilesystemEntity[] | null;
|
||||
writeFile(path: string, content: string): void;
|
||||
}
|
||||
|
||||
export type FilesystemEntity = {
|
||||
name: string;
|
||||
path: string;
|
||||
size: number;
|
||||
isDirectory: boolean;
|
||||
contents: string | number | number[] | null;
|
||||
};
|
||||
@@ -1,18 +0,0 @@
|
||||
# Meson cross-compilation file for i686-elf with picolibc
|
||||
[binaries]
|
||||
c = 'gcc'
|
||||
ar = 'ar'
|
||||
as = 'as'
|
||||
ld = 'ld'
|
||||
strip = 'strip'
|
||||
|
||||
[host_machine]
|
||||
system = 'none'
|
||||
cpu_family = 'x86'
|
||||
cpu = 'i686'
|
||||
endian = 'little'
|
||||
|
||||
[properties]
|
||||
c_args = ['-m32', '-march=i686']
|
||||
c_link_args = ['-m32']
|
||||
skip_sanity_check = true
|
||||
@@ -1,85 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Build and run kernel with picolibc
|
||||
|
||||
set -e
|
||||
|
||||
mkdir -p lib
|
||||
|
||||
./scripts/get_duktape.sh
|
||||
|
||||
# Paths
|
||||
PICOLIBC_INSTALL="$(pwd)/picolibc-install"
|
||||
BUILD_DIR="build"
|
||||
OUT_DIR="$BUILD_DIR/out"
|
||||
|
||||
# Check if picolibc is installed
|
||||
if [ ! -d "$PICOLIBC_INSTALL" ]; then
|
||||
echo "Error: Picolibc not found at $PICOLIBC_INSTALL"
|
||||
echo "Please run: make picolibc"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create build directories
|
||||
mkdir -p "$BUILD_DIR"
|
||||
mkdir -p "$OUT_DIR"
|
||||
|
||||
# Build TypeScript to JavaScript
|
||||
cd src/os
|
||||
echo "Compiling TypeScript to JavaScript..."
|
||||
bun build --outdir ../../build --target node --bundle src/index.ts
|
||||
cd ../../
|
||||
|
||||
# Generate embedded JavaScript header
|
||||
echo "Generating embedded JavaScript..."
|
||||
bun scripts/build_js.js
|
||||
python3 scripts/embed_js.py build/index.js > "$BUILD_DIR/embedded_js.h"
|
||||
|
||||
|
||||
# Compiler flags
|
||||
CFLAGS="-m32 -march=i686 -ffreestanding -nostdlib -fno-builtin"
|
||||
CFLAGS="$CFLAGS -I$PICOLIBC_INSTALL/include"
|
||||
CFLAGS="$CFLAGS -I./lib/duktape/src"
|
||||
CFLAGS="$CFLAGS -I./src/lib"
|
||||
CFLAGS="$CFLAGS -I./src"
|
||||
CFLAGS="$CFLAGS -I$BUILD_DIR"
|
||||
CFLAGS="$CFLAGS -Wall -Wextra"
|
||||
|
||||
LDFLAGS="-m elf_i386 -nostdlib"
|
||||
LDFLAGS="$LDFLAGS -L$PICOLIBC_INSTALL/lib"
|
||||
|
||||
# Get libgcc path
|
||||
LIBGCC=$(gcc -m32 -print-libgcc-file-name)
|
||||
|
||||
echo "=== Building kernel with picolibc ==="
|
||||
|
||||
# Build boot assembly
|
||||
echo "Assembling boot code..."
|
||||
nasm -f elf32 src/boot/kernel.asm -o "$BUILD_DIR/kasm.o"
|
||||
|
||||
# Build duktape
|
||||
echo "Building Duktape..."
|
||||
gcc $CFLAGS -c lib/duktape/src/duktape.c -o "$BUILD_DIR/duktape.o"
|
||||
|
||||
# Build kernel
|
||||
echo "Building kernel..."
|
||||
gcc $CFLAGS -c src/kernel/kernel.c -o "$BUILD_DIR/kc.o"
|
||||
|
||||
# Build syscalls
|
||||
echo "Building syscalls..."
|
||||
gcc $CFLAGS -c src/lib/syscalls.c -o "$BUILD_DIR/syscalls.o"
|
||||
|
||||
# Link everything together
|
||||
echo "Linking kernel..."
|
||||
ld $LDFLAGS -T src/link.ld -o "$OUT_DIR/kernel" \
|
||||
"$BUILD_DIR/kasm.o" \
|
||||
"$BUILD_DIR/kc.o" \
|
||||
"$BUILD_DIR/duktape.o" \
|
||||
"$BUILD_DIR/syscalls.o" \
|
||||
-lc "$LIBGCC"
|
||||
|
||||
echo ""
|
||||
echo "=== Build complete! ==="
|
||||
echo ""
|
||||
echo "Running kernel in QEMU..."
|
||||
echo "(Press Ctrl+A then X to exit)"
|
||||
echo ""
|
||||
@@ -1,55 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Script to build picolibc for i686 freestanding environment
|
||||
|
||||
set -e
|
||||
|
||||
PICOLIBC_DIR="picolibc"
|
||||
BUILD_DIR="build/picolibc"
|
||||
INSTALL_DIR="$(pwd)/picolibc-install"
|
||||
|
||||
echo "=== Building Picolibc for i686 freestanding ==="
|
||||
|
||||
# Check if picolibc exists
|
||||
if [ ! -d "$PICOLIBC_DIR" ]; then
|
||||
echo "Error: Picolibc source not found at $PICOLIBC_DIR"
|
||||
echo "Cloning..."
|
||||
git clone --branch 1.8.10 https://github.com/picolibc/picolibc.git "$PICOLIBC_DIR"
|
||||
fi
|
||||
|
||||
# Get current version
|
||||
cd "$PICOLIBC_DIR"
|
||||
CURRENT_VERSION=$(git describe --tags 2>/dev/null || echo "unknown")
|
||||
echo "Using picolibc version: $CURRENT_VERSION"
|
||||
cd ..
|
||||
|
||||
# Create build directory
|
||||
mkdir -p "$BUILD_DIR"
|
||||
|
||||
echo "Configuring picolibc with meson..."
|
||||
meson setup "$BUILD_DIR" "$PICOLIBC_DIR" \
|
||||
--cross-file picolibc-i686.txt \
|
||||
--prefix="$INSTALL_DIR" \
|
||||
--wipe \
|
||||
-Dmultilib=false \
|
||||
-Dpicocrt=false \
|
||||
-Dsemihost=false \
|
||||
-Dspecsdir=none \
|
||||
-Dtinystdio=true \
|
||||
-Dio-long-long=true \
|
||||
-Dformat-default=double \
|
||||
-Dtests=false
|
||||
|
||||
echo "Building picolibc..."
|
||||
meson compile -C "$BUILD_DIR"
|
||||
|
||||
echo "Installing picolibc..."
|
||||
meson install -C "$BUILD_DIR"
|
||||
|
||||
echo ""
|
||||
echo "=== Picolibc build complete! ==="
|
||||
echo "Installation directory: $INSTALL_DIR"
|
||||
echo ""
|
||||
echo "To use picolibc in your kernel:"
|
||||
echo " Include path: -I$INSTALL_DIR/include"
|
||||
echo " Library path: -L$INSTALL_DIR/lib"
|
||||
echo " Link with: -lc"
|
||||
@@ -1,2 +0,0 @@
|
||||
docker build -t lints-dev -f docker/Dockerfile .
|
||||
docker run -it --rm -v "$(pwd)":/workspace -w /workspace lints-dev
|
||||
11
scripts/build_c.sh
Executable file
11
scripts/build_c.sh
Executable file
@@ -0,0 +1,11 @@
|
||||
mkdir -p out
|
||||
mkdir -p out/core
|
||||
mkdir -p out/img/EFI/BOOT
|
||||
mkdir -p out/lib
|
||||
|
||||
clang -target x86_64-pc-win32-coff -fno-stack-protector -fshort-wchar -mno-red-zone -Iedk2/MdePkg/Include -Iedk2/MdePkg/Include/X64 -c core/src/efi.c -o out/core/efi.o
|
||||
clang -target x86_64-pc-win32-coff -fno-stack-protector -fshort-wchar -mno-red-zone -Icore/compat -Icore/lib/duktape/src -Iedk2/MdePkg/Include -Iedk2/MdePkg/Include/X64 -Iedk2/CryptoPkg/Library/Include -Iout -c core/src/main.c -o out/core/main.o
|
||||
clang -target x86_64-pc-win32-coff -fno-stack-protector -fshort-wchar -mno-red-zone -DDUK_F_GENERIC -U_WIN32 -UWIN32 -U_WIN64 -UWIN64 -Icore/compat -Iedk2/MdePkg/Include -Iedk2/MdePkg/Include/X64 -Iedk2/CryptoPkg/Library/Include -c core/lib/duktape/src/duktape.c -o out/lib/duktape.o
|
||||
clang -target x86_64-pc-win32-coff -fno-stack-protector -fshort-wchar -mno-red-zone -Icore/compat -Iedk2/MdePkg/Include -Iedk2/MdePkg/Include/X64 -Iedk2/CryptoPkg/Library/Include -c core/src/compat.c -o out/core/compat.o
|
||||
|
||||
lld-link -filealign:16 -subsystem:efi_application -nodefaultlib -dll -entry:efi_main out/core/main.o out/core/efi.o out/lib/duktape.o out/core/compat.o -out:out/img/EFI/BOOT/BOOTX64.EFI
|
||||
@@ -1,11 +0,0 @@
|
||||
#! /usr/bin/env bun
|
||||
import { readFileSync, writeFileSync } from "fs";
|
||||
|
||||
writeFileSync(
|
||||
"build/index.js",
|
||||
readFileSync("build/index.js", "utf-8")
|
||||
.replaceAll("let ", "var ")
|
||||
.replaceAll("const ", "var ")
|
||||
.replaceAll("\n`", "\\n`")
|
||||
.replaceAll("`", "'")
|
||||
);
|
||||
7
scripts/build_ts.sh
Executable file
7
scripts/build_ts.sh
Executable file
@@ -0,0 +1,7 @@
|
||||
# Build TypeScript to JavaScript
|
||||
cd os
|
||||
echo "Compiling TypeScript to JavaScript..."
|
||||
bun build --outdir ../out/os --target node --bundle src/index.ts
|
||||
cd ..
|
||||
|
||||
./scripts/process_js.js
|
||||
@@ -1,58 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Embed JavaScript file as a C string constant
|
||||
"""
|
||||
|
||||
import sys
|
||||
|
||||
|
||||
def escape_c_string(s):
|
||||
"""Escape a string for use in C source code"""
|
||||
result = []
|
||||
for char in s:
|
||||
if char == "\n":
|
||||
result.append("\\n")
|
||||
elif char == "\r":
|
||||
result.append("\\r")
|
||||
elif char == "\t":
|
||||
result.append("\\t")
|
||||
elif char == "\\":
|
||||
result.append("\\\\")
|
||||
elif char == '"':
|
||||
result.append('\\"')
|
||||
elif ord(char) < 32 or ord(char) > 126:
|
||||
result.append(f"\\x{ord(char):02x}")
|
||||
else:
|
||||
result.append(char)
|
||||
return "".join(result)
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) != 2:
|
||||
print("Usage: embed_js.py <input.js>", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
input_file = sys.argv[1]
|
||||
|
||||
try:
|
||||
with open(input_file, "r") as f:
|
||||
js_code = f.read()
|
||||
except FileNotFoundError:
|
||||
print(f"Error: File not found: {input_file}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
# Generate C header file
|
||||
print("/* Auto-generated file - do not edit */")
|
||||
print("#ifndef EMBEDDED_JS_H")
|
||||
print("#define EMBEDDED_JS_H")
|
||||
print()
|
||||
|
||||
escaped = escape_c_string(js_code)
|
||||
print(f'const char *embedded_js_code = "{escaped}";')
|
||||
|
||||
print()
|
||||
print("#endif /* EMBEDDED_JS_H */")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,28 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Script to download Duktape library if not present
|
||||
|
||||
set -e
|
||||
|
||||
DUKTAPE_DIR="lib/duktape"
|
||||
DUKTAPE_REPO="https://github.com/joeqread/arduino-duktape.git"
|
||||
TEMP_DIR="lib/temp_duktape"
|
||||
|
||||
echo "=== Checking for Duktape library ==="
|
||||
|
||||
if [ -d "$DUKTAPE_DIR" ]; then
|
||||
echo "Duktape already exists at $DUKTAPE_DIR"
|
||||
else
|
||||
echo "Duktape not found. Cloning from $DUKTAPE_REPO..."
|
||||
git clone "$DUKTAPE_REPO" "$TEMP_DIR"
|
||||
|
||||
echo "Extracting src folder..."
|
||||
mkdir -p "$DUKTAPE_DIR"
|
||||
mv "$TEMP_DIR/src" "$DUKTAPE_DIR/"
|
||||
|
||||
echo "Cleaning up temporary directory..."
|
||||
rm -rf "$TEMP_DIR"
|
||||
|
||||
echo "Duktape cloned successfully!"
|
||||
fi
|
||||
|
||||
echo "Done."
|
||||
19
scripts/out_to_iso.sh
Executable file
19
scripts/out_to_iso.sh
Executable file
@@ -0,0 +1,19 @@
|
||||
# Create a FAT12 image
|
||||
dd if=/dev/zero of=out/fat.img bs=1k count=1440
|
||||
mformat -i out/fat.img -f 1440 ::
|
||||
|
||||
# Create EFI directory structure
|
||||
mmd -i out/fat.img ::/EFI
|
||||
mmd -i out/fat.img ::/EFI/BOOT
|
||||
|
||||
# Copy the EFI application
|
||||
mcopy -i out/fat.img out/img/EFI/BOOT/BOOTX64.EFI ::/EFI/BOOT
|
||||
|
||||
# Verify content
|
||||
echo "Verifying FAT image content:"
|
||||
mdir -i out/fat.img -/ ::
|
||||
|
||||
# Create the ISO
|
||||
# -e specifies the boot image (the FAT image)
|
||||
# -no-emul-boot is required for UEFI
|
||||
xorriso -as mkisofs -R -f -e /fat.img -no-emul-boot -volid LintsEFI -o out/lints.iso out/img out/fat.img
|
||||
20
scripts/process_js.js
Executable file
20
scripts/process_js.js
Executable file
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env node
|
||||
const fs = require("fs");
|
||||
|
||||
const script = fs.readFileSync("out/os/index.js", "utf-8");
|
||||
const processed = script
|
||||
.replaceAll("let ", "var ")
|
||||
.replaceAll("const ", "var ")
|
||||
.replaceAll("\n`", "\\n`")
|
||||
.replaceAll("`", "'");
|
||||
|
||||
fs.writeFileSync(
|
||||
"out/embedded_js.h",
|
||||
`
|
||||
#ifndef EMBEDDED_JS_H
|
||||
#define EMBEDDED_JS_H
|
||||
const char *EMBEDDED_JS = "${processed
|
||||
.replaceAll('"', '\\"')
|
||||
.replaceAll("\n", "\\n")}";
|
||||
#endif`
|
||||
);
|
||||
@@ -1,3 +0,0 @@
|
||||
./scripts/build.sh
|
||||
|
||||
qemu-system-i386 -serial stdio -kernel "build/out/kernel"
|
||||
1
scripts/run.sh
Executable file
1
scripts/run.sh
Executable file
@@ -0,0 +1 @@
|
||||
./scripts/build_ts.sh && ./scripts/build_c.sh && ./scripts/out_to_iso.sh && ./scripts/run_vbox.sh
|
||||
22
scripts/run_vbox.sh
Executable file
22
scripts/run_vbox.sh
Executable file
@@ -0,0 +1,22 @@
|
||||
#!/bin/bash
|
||||
VM_NAME="LintsEFI"
|
||||
ISO_PATH="$(pwd)/out/lints.iso"
|
||||
|
||||
# Check if VM exists
|
||||
if VBoxManage list vms | grep -q "\"$VM_NAME\""; then
|
||||
echo "VM '$VM_NAME' already exists."
|
||||
else
|
||||
echo "Creating VM '$VM_NAME'..."
|
||||
VBoxManage createvm --name "$VM_NAME" --ostype "Other_64" --register
|
||||
VBoxManage modifyvm "$VM_NAME" --memory 128 --firmware efi --graphicscontroller vmsvga
|
||||
VBoxManage storagectl "$VM_NAME" --name "IDE Controller" --add ide
|
||||
fi
|
||||
|
||||
# Attach ISO (force unmount first just in case)
|
||||
echo "Attaching ISO..."
|
||||
VBoxManage storageattach "$VM_NAME" --storagectl "IDE Controller" --port 0 --device 0 --type dvddrive --medium emptydrive --forceunmount
|
||||
VBoxManage storageattach "$VM_NAME" --storagectl "IDE Controller" --port 0 --device 0 --type dvddrive --medium "$ISO_PATH"
|
||||
|
||||
# Start VM
|
||||
echo "Starting VM..."
|
||||
VBoxManage startvm "$VM_NAME"
|
||||
@@ -1,17 +0,0 @@
|
||||
bits 32 ;nasm directive
|
||||
section .text
|
||||
;multiboot spec
|
||||
align 4
|
||||
dd 0x1BADB002 ;magic
|
||||
dd 0x00 ;flags
|
||||
dd - (0x1BADB002 + 0x00) ;checksum. m+f+c should be zero
|
||||
|
||||
global start
|
||||
extern kmain ;kmain is defined in the kernel.c file
|
||||
|
||||
start:
|
||||
cli ; stop interrupts
|
||||
|
||||
call kmain
|
||||
|
||||
hlt ; halt the CPU
|
||||
@@ -1,153 +0,0 @@
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <duktape.h>
|
||||
#include "embedded_js.h"
|
||||
|
||||
#define WHITE_TXT 0x0F
|
||||
|
||||
// Forward declaration
|
||||
unsigned int k_printf(char *message, unsigned int line);
|
||||
|
||||
duk_context *ctx;
|
||||
|
||||
duk_ret_t native_addrw(duk_context *ctx)
|
||||
{
|
||||
// Get the address (first argument)
|
||||
uint32_t address = (uint32_t)duk_to_uint32(ctx, 0);
|
||||
|
||||
// Get the value to write (second argument)
|
||||
uint8_t value = (uint8_t)duk_to_uint32(ctx, 1);
|
||||
|
||||
// Write the value to the address
|
||||
uint8_t *ptr = (uint8_t *)address;
|
||||
*ptr = value;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Port byte in
|
||||
duk_ret_t native_ptin(duk_context *ctx)
|
||||
{
|
||||
// Get the port (first argument)
|
||||
uint16_t port = (uint16_t)duk_to_uint32(ctx, 0);
|
||||
|
||||
uint8_t result;
|
||||
__asm__ volatile("inb %1, %0"
|
||||
: "=a"(result)
|
||||
: "Nd"(port));
|
||||
|
||||
duk_push_uint(ctx, (duk_uint_t)result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Port byte out
|
||||
duk_ret_t native_ptout(duk_context *ctx)
|
||||
{
|
||||
// Get the port (first argument)
|
||||
uint16_t port = (uint16_t)duk_to_uint32(ctx, 0);
|
||||
|
||||
// Get the value to write (second argument)
|
||||
uint8_t value = (uint8_t)duk_to_uint32(ctx, 1);
|
||||
|
||||
__asm__ volatile("outb %0, %1"
|
||||
:
|
||||
: "a"(value), "Nd"(port));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
duk_ret_t native_dword_in(duk_context *ctx)
|
||||
{
|
||||
// Get the port (first argument)
|
||||
uint16_t port = (uint16_t)duk_to_uint32(ctx, 0);
|
||||
|
||||
uint32_t result;
|
||||
__asm__ volatile("inl %1, %0"
|
||||
: "=a"(result)
|
||||
: "Nd"(port));
|
||||
|
||||
duk_push_uint(ctx, (duk_uint_t)result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
duk_ret_t native_dword_out(duk_context *ctx)
|
||||
{
|
||||
// Get the port (first argument)
|
||||
uint16_t port = (uint16_t)duk_to_uint32(ctx, 0);
|
||||
|
||||
// Get the value to write (second argument)
|
||||
uint32_t value = (uint32_t)duk_to_uint32(ctx, 1);
|
||||
|
||||
__asm__ volatile("outl %0, %1"
|
||||
:
|
||||
: "a"(value), "Nd"(port));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void kmain()
|
||||
{
|
||||
// Initialize Duktape heap
|
||||
ctx = duk_create_heap_default();
|
||||
|
||||
// Register native memory write function
|
||||
duk_push_c_function(ctx, native_addrw, 2);
|
||||
duk_put_global_string(ctx, "$addrw");
|
||||
|
||||
// Register native port in function
|
||||
duk_push_c_function(ctx, native_ptin, 1);
|
||||
duk_put_global_string(ctx, "$ptin");
|
||||
|
||||
// Register native port out function
|
||||
duk_push_c_function(ctx, native_ptout, 2);
|
||||
duk_put_global_string(ctx, "$ptout");
|
||||
|
||||
// Register native dword in function
|
||||
duk_push_c_function(ctx, native_dword_in, 1);
|
||||
duk_put_global_string(ctx, "$dwordin");
|
||||
|
||||
// Register native dword out function
|
||||
duk_push_c_function(ctx, native_dword_out, 2);
|
||||
duk_put_global_string(ctx, "$dwordout");
|
||||
|
||||
// Execute embedded JavaScript code from build/index.js
|
||||
duk_push_string(ctx, embedded_js_code);
|
||||
duk_int_t returnCode = duk_peval(ctx);
|
||||
|
||||
if (returnCode != 0)
|
||||
{
|
||||
// Error occurred - display stack trace
|
||||
duk_safe_to_stacktrace(ctx, -1);
|
||||
k_printf((char *)duk_safe_to_string(ctx, -1), 1);
|
||||
}
|
||||
|
||||
duk_pop(ctx);
|
||||
}
|
||||
|
||||
unsigned int k_printf(char *message, unsigned int line)
|
||||
{
|
||||
char *vidmem = (char *)0xb8000;
|
||||
unsigned int i = 0;
|
||||
|
||||
i = (line * 80 * 2);
|
||||
|
||||
while (*message != 0)
|
||||
{
|
||||
if (*message == '\n') // check for a new line
|
||||
{
|
||||
line++;
|
||||
i = (line * 80 * 2);
|
||||
*message++;
|
||||
}
|
||||
else
|
||||
{
|
||||
vidmem[i] = *message;
|
||||
*message++;
|
||||
i++;
|
||||
vidmem[i] = WHITE_TXT;
|
||||
i++;
|
||||
};
|
||||
};
|
||||
|
||||
return (1);
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Minimal system stubs for freestanding picolibc
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <errno.h>
|
||||
|
||||
/* Exit function - halt the system */
|
||||
void _exit(int status)
|
||||
{
|
||||
(void)status;
|
||||
/* Halt the CPU */
|
||||
while (1)
|
||||
{
|
||||
__asm__ volatile("hlt");
|
||||
}
|
||||
}
|
||||
|
||||
/* Get time of day - not supported in freestanding */
|
||||
int gettimeofday(struct timeval *tv, void *tz)
|
||||
{
|
||||
(void)tz;
|
||||
if (tv)
|
||||
{
|
||||
tv->tv_sec = 0;
|
||||
tv->tv_usec = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Sbrk - memory allocation (picolibc uses __heap_start and __heap_end from linker script) */
|
||||
/* No need to implement sbrk as picolibc uses the linker symbols directly */
|
||||
40
src/link.ld
40
src/link.ld
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* link.ld
|
||||
*/
|
||||
|
||||
OUTPUT_FORMAT(elf32-i386)
|
||||
ENTRY(start)
|
||||
SECTIONS
|
||||
{
|
||||
. = 0x100000;
|
||||
|
||||
.text : {
|
||||
*(.text)
|
||||
*(.text.*)
|
||||
*(.rodata)
|
||||
*(.rodata.*)
|
||||
}
|
||||
|
||||
.data : {
|
||||
*(.data)
|
||||
*(.data.*)
|
||||
}
|
||||
|
||||
.bss : {
|
||||
*(.bss)
|
||||
*(.bss.*)
|
||||
*(COMMON)
|
||||
}
|
||||
|
||||
/* Heap for malloc */
|
||||
. = ALIGN(4096);
|
||||
__heap_start = .;
|
||||
. = . + 0x100000; /* 1MB heap */
|
||||
__heap_end = .;
|
||||
|
||||
/* Stack grows downward from high memory */
|
||||
. = ALIGN(4096);
|
||||
__stack_bottom = .;
|
||||
. = . + 0x10000; /* 64KB stack */
|
||||
__stack_top = .;
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
import { portin, portout } from "../../../lib/libts/port";
|
||||
|
||||
const SERIAL_PORT_COM1 = 0x3f8;
|
||||
|
||||
export function kdriver_etc_serial_init() {
|
||||
portout(SERIAL_PORT_COM1 + 1, 0x00); // Disable all interrupts
|
||||
portout(SERIAL_PORT_COM1 + 3, 0x80); // Enable DLAB
|
||||
portout(SERIAL_PORT_COM1 + 0, 0x03); // 38400 baud
|
||||
portout(SERIAL_PORT_COM1 + 1, 0x00);
|
||||
portout(SERIAL_PORT_COM1 + 3, 0x03); // 8 bits, no parity, one stop bit
|
||||
portout(SERIAL_PORT_COM1 + 2, 0xc7); // Enable FIFO, clear them, with 14-byte threshold
|
||||
portout(SERIAL_PORT_COM1 + 4, 0x0b);
|
||||
}
|
||||
|
||||
export function kdriver_etc_serial_isTransmitBufferEmpty(): boolean {
|
||||
return (portin(SERIAL_PORT_COM1 + 5) & 0x20) !== 0;
|
||||
}
|
||||
|
||||
export function kdriver_etc_serial_transmit(byte: number): void {
|
||||
while (!kdriver_etc_serial_isTransmitBufferEmpty()) {}
|
||||
|
||||
portout(SERIAL_PORT_COM1, byte);
|
||||
}
|
||||
|
||||
export function kdriver_etc_serial_read(): number {
|
||||
return portin(SERIAL_PORT_COM1);
|
||||
}
|
||||
@@ -1,138 +0,0 @@
|
||||
import { Logger } from "../../lib/libstd/logger/logger.kmod";
|
||||
import { Path } from "../../lib/libstd/path";
|
||||
import type {
|
||||
KFilesystemDriver,
|
||||
KFilesystemEntity,
|
||||
KFilesystemMemdata,
|
||||
KFilesystemStat,
|
||||
} from "../../types/filesystem/fs";
|
||||
|
||||
const sysfs_data: KFilesystemMemdata = [];
|
||||
|
||||
export function sysfs_driver(): KFilesystemDriver {
|
||||
return {
|
||||
id: "sysfs",
|
||||
init: sysfs_init,
|
||||
listDir(path: string): KFilesystemEntity[] | null {
|
||||
return sysfs_listDir(path);
|
||||
},
|
||||
readFile(path: string): unknown {
|
||||
return sysfs_readFile(path);
|
||||
},
|
||||
writeFile(path: string, content: unknown): void {
|
||||
throw new Error("Cannot write to sysfs files.");
|
||||
},
|
||||
createFile(path: string, content: unknown): void {
|
||||
throw new Error("Cannot create files in sysfs.");
|
||||
},
|
||||
mkdir(path: string): void {
|
||||
throw new Error("Cannot create directories in sysfs.");
|
||||
},
|
||||
stat(path: string): KFilesystemStat | null {
|
||||
return sysfs_statEntity(path);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function sysfs_init(): void {
|
||||
sysfs_data.push({
|
||||
name: "root",
|
||||
path: "/",
|
||||
type: "folder",
|
||||
size: 0,
|
||||
contents: null,
|
||||
});
|
||||
|
||||
sysfs_mkdir("/pci");
|
||||
}
|
||||
|
||||
export function sysfs_getEntity(path: string): KFilesystemEntity | null {
|
||||
for (let i = 0; i < sysfs_data.length; i++) {
|
||||
const entity = sysfs_data[i]!;
|
||||
|
||||
if (entity.path === path) return entity;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function sysfs_statEntity(path: string): KFilesystemStat | null {
|
||||
const entity = sysfs_getEntity(path);
|
||||
if (!entity) return null;
|
||||
|
||||
return {
|
||||
name: entity.name,
|
||||
type: entity.type,
|
||||
size: entity.size,
|
||||
};
|
||||
}
|
||||
|
||||
export function sysfs_mkdir(path: string): void {
|
||||
if (sysfs_getEntity(path)) return;
|
||||
|
||||
const parent = Path.dirname(path);
|
||||
if (!sysfs_getEntity(parent)) return;
|
||||
|
||||
sysfs_data.push({
|
||||
name: Path.filename(path),
|
||||
path,
|
||||
type: "folder",
|
||||
size: 0,
|
||||
contents: null,
|
||||
});
|
||||
}
|
||||
|
||||
export function sysfs_createFile(path: string, content: unknown): void {
|
||||
if (sysfs_getEntity(path)) return;
|
||||
|
||||
const parent = Path.dirname(path);
|
||||
if (!sysfs_getEntity(parent)) return;
|
||||
|
||||
const size = String(content).length;
|
||||
|
||||
sysfs_data.push({
|
||||
name: Path.filename(path),
|
||||
path,
|
||||
type: "file",
|
||||
size,
|
||||
contents: content,
|
||||
});
|
||||
}
|
||||
|
||||
export function sysfs_writeFile(path: string, content: unknown): void {
|
||||
const entity = sysfs_getEntity(path);
|
||||
if (!entity) return sysfs_createFile(path, content);
|
||||
|
||||
if (entity.type !== "file") return;
|
||||
|
||||
entity.contents = content;
|
||||
entity.size = String(content).length;
|
||||
}
|
||||
|
||||
export function sysfs_readFile(path: string): unknown {
|
||||
const entity = sysfs_getEntity(path);
|
||||
if (!entity) return null;
|
||||
|
||||
if (entity.type !== "file") return null;
|
||||
|
||||
return entity.contents;
|
||||
}
|
||||
|
||||
export function sysfs_listDir(path: string): KFilesystemEntity[] | null {
|
||||
const entity = sysfs_getEntity(path);
|
||||
if (!entity) return null;
|
||||
|
||||
if (entity.type !== "folder") return null;
|
||||
|
||||
const contents: KFilesystemEntity[] = [];
|
||||
|
||||
for (let i = 0; i < sysfs_data.length; i++) {
|
||||
const e = sysfs_data[i]!;
|
||||
|
||||
if (Path.dirname(e.path) === path) {
|
||||
contents.push(e);
|
||||
}
|
||||
}
|
||||
|
||||
return contents;
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
import { Logger } from "../lib/libstd/logger/logger.kmod";
|
||||
import { charc } from "../lib/libts/byte";
|
||||
import { padStart } from "../lib/libts/string";
|
||||
import { getDate } from "../lib/sys/date";
|
||||
import { kdriver_dev_pci_detectDevices } from "./drivers/dev/pci";
|
||||
import {
|
||||
kdriver_etc_serial_read,
|
||||
kdriver_etc_serial_transmit,
|
||||
} from "./drivers/etc/serial";
|
||||
import { sysfs_driver, sysfs_readFile } from "./filesystem/sysfs";
|
||||
import {
|
||||
kmod_drivers_init,
|
||||
kmod_drivers_register,
|
||||
} from "./modules/drivers/drivers.kmod";
|
||||
import {
|
||||
kmod_filesystem_init,
|
||||
kmod_filesystem_mount,
|
||||
kmod_filesystem_readFile,
|
||||
} from "./modules/filesystem/filesystem.kmod";
|
||||
import {
|
||||
kmod_graphics_vga_clear,
|
||||
kmod_graphics_vga_init,
|
||||
kmod_graphics_vga_pushLine,
|
||||
} from "./modules/graphics/graphics.kmod";
|
||||
|
||||
export function kmain() {
|
||||
kmod_drivers_init();
|
||||
|
||||
kmod_drivers_register();
|
||||
Logger.log("[Kernel] Drivers initialized.");
|
||||
|
||||
Logger.log("[Kernel] Initializing filesystem module...");
|
||||
kmod_filesystem_init();
|
||||
kmod_filesystem_mount("/sys", sysfs_driver);
|
||||
|
||||
Logger.log("[Kernel] Initializing PCI devices...");
|
||||
kdriver_dev_pci_detectDevices();
|
||||
|
||||
Logger.log("[Kernel] Initializing VGA module...");
|
||||
kmod_graphics_vga_init();
|
||||
kmod_graphics_vga_pushLine("[Kernel] Kernel initialized successfully.");
|
||||
kmod_graphics_vga_pushLine("Current date: " + getDate().toDateString());
|
||||
kmod_graphics_vga_pushLine(
|
||||
Number(kmod_filesystem_readFile("/sys/pci/0:1:0/vendor")).toString(16)
|
||||
);
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
export * from "./time"
|
||||
@@ -1,2 +0,0 @@
|
||||
export const CFG_KMOD_BIOS_TIME_CMOS_ADDR = 0x70;
|
||||
export const CFG_KMOD_BIOS_TIME_CMOS_DATA_ADDR = 0x71;
|
||||
@@ -1,96 +0,0 @@
|
||||
import { portin, portout } from "../../../lib/libts/port";
|
||||
import { padStart } from "../../../lib/libts/string";
|
||||
import {
|
||||
CFG_KMOD_BIOS_TIME_CMOS_ADDR,
|
||||
CFG_KMOD_BIOS_TIME_CMOS_DATA_ADDR,
|
||||
} from "./config";
|
||||
|
||||
export function kmod_bios_time_getCentury(): number {
|
||||
const val = 0x32;
|
||||
|
||||
portout(CFG_KMOD_BIOS_TIME_CMOS_ADDR, val);
|
||||
const data = portin(CFG_KMOD_BIOS_TIME_CMOS_DATA_ADDR);
|
||||
|
||||
return (data & 0x0f) + ((data >> 4) & 0x0f) * 10;
|
||||
}
|
||||
|
||||
export function kmod_bios_time_getYear(): number {
|
||||
const val = 0x09;
|
||||
|
||||
portout(CFG_KMOD_BIOS_TIME_CMOS_ADDR, val);
|
||||
const data = portin(CFG_KMOD_BIOS_TIME_CMOS_DATA_ADDR);
|
||||
|
||||
return (data & 0x0f) + ((data >> 4) & 0x0f) * 10;
|
||||
}
|
||||
|
||||
export function kmod_bios_time_getMonth(): number {
|
||||
const val = 0x08;
|
||||
|
||||
portout(CFG_KMOD_BIOS_TIME_CMOS_ADDR, val);
|
||||
const data = portin(CFG_KMOD_BIOS_TIME_CMOS_DATA_ADDR);
|
||||
|
||||
return (data & 0x0f) + ((data >> 4) & 0x0f) * 10;
|
||||
}
|
||||
|
||||
export function kmod_bios_time_getDay(): number {
|
||||
const val = 0x07;
|
||||
|
||||
portout(CFG_KMOD_BIOS_TIME_CMOS_ADDR, val);
|
||||
const data = portin(CFG_KMOD_BIOS_TIME_CMOS_DATA_ADDR);
|
||||
|
||||
return (data & 0x0f) + ((data >> 4) & 0x0f) * 10;
|
||||
}
|
||||
|
||||
export function kmod_bios_time_getHours(): number {
|
||||
const val = 0x04;
|
||||
|
||||
portout(CFG_KMOD_BIOS_TIME_CMOS_ADDR, val);
|
||||
const data = portin(CFG_KMOD_BIOS_TIME_CMOS_DATA_ADDR);
|
||||
|
||||
return (data & 0x0f) + ((data >> 4) & 0x0f) * 10;
|
||||
}
|
||||
|
||||
export function kmod_bios_time_getMinutes(): number {
|
||||
const val = 0x02;
|
||||
|
||||
portout(CFG_KMOD_BIOS_TIME_CMOS_ADDR, val);
|
||||
const data = portin(CFG_KMOD_BIOS_TIME_CMOS_DATA_ADDR);
|
||||
|
||||
return (data & 0x0f) + ((data >> 4) & 0x0f) * 10;
|
||||
}
|
||||
|
||||
export function kmod_bios_time_getSeconds(): number {
|
||||
const val = 0x00;
|
||||
|
||||
portout(CFG_KMOD_BIOS_TIME_CMOS_ADDR, val);
|
||||
const data = portin(CFG_KMOD_BIOS_TIME_CMOS_DATA_ADDR);
|
||||
|
||||
return (data & 0x0f) + ((data >> 4) & 0x0f) * 10;
|
||||
}
|
||||
|
||||
export function kmod_bios_time_getTimestamp(): string {
|
||||
const century = kmod_bios_time_getCentury();
|
||||
const year = kmod_bios_time_getYear();
|
||||
const month = kmod_bios_time_getMonth();
|
||||
const day = kmod_bios_time_getDay();
|
||||
const hours = kmod_bios_time_getHours();
|
||||
const minutes = kmod_bios_time_getMinutes();
|
||||
const seconds = kmod_bios_time_getSeconds();
|
||||
|
||||
return (
|
||||
century.toString() +
|
||||
year.toString() +
|
||||
"-" +
|
||||
padStart(month.toString(), 2, "0") +
|
||||
"-" +
|
||||
padStart(day.toString(), 2, "0") +
|
||||
"T" +
|
||||
padStart(hours.toString(), 2, "0") +
|
||||
":" +
|
||||
padStart(minutes.toString(), 2, "0") +
|
||||
":" +
|
||||
padStart(seconds.toString(), 2, "0") +
|
||||
+".000" +
|
||||
"Z"
|
||||
);
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import { kdriver_dev_pci_init } from "../../drivers/dev/pci";
|
||||
import { kdriver_etc_serial_init } from "../../drivers/etc/serial";
|
||||
|
||||
const drivers = [kdriver_etc_serial_init, kdriver_dev_pci_init];
|
||||
|
||||
export function kmod_drivers_init(): void {}
|
||||
|
||||
export function kmod_drivers_register(): void {
|
||||
for (let i = 0; i < drivers.length; i++) {
|
||||
drivers[i]!();
|
||||
}
|
||||
}
|
||||
@@ -1,111 +0,0 @@
|
||||
import { Logger } from "../../../lib/libstd/logger/logger.kmod";
|
||||
import type {
|
||||
KFilesystemDriver,
|
||||
KFilesystemEntity,
|
||||
KFilesystemMount,
|
||||
KFilesystemMountdata,
|
||||
KFilesystemStat,
|
||||
} from "../../../types/filesystem/fs";
|
||||
|
||||
const kmod_filesystem_data: KFilesystemMountdata = [];
|
||||
|
||||
export function kmod_filesystem_init(): void {}
|
||||
|
||||
export function kmod_filesystem_mount(
|
||||
mpoint: string,
|
||||
drv: () => KFilesystemDriver
|
||||
): void {
|
||||
const driver = drv();
|
||||
|
||||
driver.init();
|
||||
|
||||
kmod_filesystem_data.push({
|
||||
mountpoint: mpoint,
|
||||
driver: driver,
|
||||
});
|
||||
|
||||
Logger.log("[Filesystem] Mounted " + driver.id + " at " + mpoint);
|
||||
}
|
||||
|
||||
export function kmod_filesystem_findMount(p: string): KFilesystemMount | null {
|
||||
for (let i = 0; i < kmod_filesystem_data.length; i++) {
|
||||
const mount = kmod_filesystem_data[i]!;
|
||||
|
||||
if (p.startsWith(mount.mountpoint)) {
|
||||
return mount;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function kmod_filesystem_stripMountpoint(
|
||||
mount: KFilesystemMount,
|
||||
p: string
|
||||
): string {
|
||||
if (mount.mountpoint === "/") return p;
|
||||
|
||||
return p.slice(mount.mountpoint.length) || "/";
|
||||
}
|
||||
|
||||
export function kmod_filesystem_listDir(
|
||||
path: string
|
||||
): KFilesystemEntity[] | null {
|
||||
const mount = kmod_filesystem_findMount(path);
|
||||
if (!mount) return null;
|
||||
|
||||
const strippedPath = kmod_filesystem_stripMountpoint(mount, path);
|
||||
|
||||
return mount.driver.listDir(strippedPath);
|
||||
}
|
||||
|
||||
export function kmod_filesystem_readFile(path: string): unknown {
|
||||
const mount = kmod_filesystem_findMount(path);
|
||||
if (!mount) return null;
|
||||
|
||||
const strippedPath = kmod_filesystem_stripMountpoint(mount, path);
|
||||
|
||||
return mount.driver.readFile(strippedPath);
|
||||
}
|
||||
|
||||
export function kmod_filesystem_writeFile(
|
||||
path: string,
|
||||
content: unknown
|
||||
): void {
|
||||
const mount = kmod_filesystem_findMount(path);
|
||||
if (!mount) return;
|
||||
|
||||
const strippedPath = kmod_filesystem_stripMountpoint(mount, path);
|
||||
|
||||
mount.driver.writeFile(strippedPath, content);
|
||||
}
|
||||
|
||||
export function kmod_filesystem_createFile(
|
||||
path: string,
|
||||
content: unknown
|
||||
): void {
|
||||
const mount = kmod_filesystem_findMount(path);
|
||||
if (!mount) return;
|
||||
|
||||
const strippedPath = kmod_filesystem_stripMountpoint(mount, path);
|
||||
|
||||
mount.driver.createFile(strippedPath, content);
|
||||
}
|
||||
|
||||
export function kmod_filesystem_mkdir(path: string): void {
|
||||
const mount = kmod_filesystem_findMount(path);
|
||||
if (!mount) return;
|
||||
|
||||
const strippedPath = kmod_filesystem_stripMountpoint(mount, path);
|
||||
|
||||
mount.driver.mkdir(strippedPath);
|
||||
}
|
||||
|
||||
export function kmod_filesystem_stat(path: string): KFilesystemStat | null {
|
||||
const mount = kmod_filesystem_findMount(path);
|
||||
if (!mount) return null;
|
||||
|
||||
const strippedPath = kmod_filesystem_stripMountpoint(mount, path);
|
||||
|
||||
return mount.driver.stat(strippedPath);
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
export const CFG_KMOD_GRAPHICS_VGA_WIDTH = 80;
|
||||
export const CFG_KMOD_GRAPHICS_VGA_HEIGHT = 25;
|
||||
export const CFG_KMOD_GRAPGICS_VGA_MEM_ADDR = 0xb8000;
|
||||
@@ -1 +0,0 @@
|
||||
export * from "./vga";
|
||||
@@ -1,72 +0,0 @@
|
||||
import { charc } from "../../../lib/libts/byte";
|
||||
import {
|
||||
CFG_KMOD_GRAPGICS_VGA_MEM_ADDR,
|
||||
CFG_KMOD_GRAPHICS_VGA_HEIGHT,
|
||||
CFG_KMOD_GRAPHICS_VGA_WIDTH,
|
||||
} from "./config";
|
||||
|
||||
let kmod_graphics_vga_lineBuf: string[] = [];
|
||||
|
||||
export function kmod_graphics_vga_init() {
|
||||
kmod_graphics_vga_clear();
|
||||
}
|
||||
|
||||
export function kmod_graphics_vga_pushLine(line: string) {
|
||||
kmod_graphics_vga_lineBuf.push(line);
|
||||
|
||||
if (kmod_graphics_vga_lineBuf.length > CFG_KMOD_GRAPHICS_VGA_HEIGHT) {
|
||||
kmod_graphics_vga_lineBuf.shift();
|
||||
}
|
||||
|
||||
kmod_graphics_vga_printLines();
|
||||
}
|
||||
|
||||
export function kmod_graphics_vga_printLines() {
|
||||
for (let y = 0; y < CFG_KMOD_GRAPHICS_VGA_HEIGHT; y++) {
|
||||
const line = kmod_graphics_vga_lineBuf[y] || "";
|
||||
|
||||
for (let x = 0; x < CFG_KMOD_GRAPHICS_VGA_WIDTH; x++) {
|
||||
let char = line[x];
|
||||
if (!char) char = " ";
|
||||
|
||||
kmod_graphics_vga_writeChar(x, y, char, 0x0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function kmod_graphics_vga_getCharAddr(x: number, y: number): number {
|
||||
return (
|
||||
CFG_KMOD_GRAPGICS_VGA_MEM_ADDR + (y * CFG_KMOD_GRAPHICS_VGA_WIDTH + x) * 2
|
||||
);
|
||||
}
|
||||
|
||||
export function kmod_graphics_vga_getColorAddr(x: number, y: number): number {
|
||||
return (
|
||||
CFG_KMOD_GRAPGICS_VGA_MEM_ADDR +
|
||||
(y * CFG_KMOD_GRAPHICS_VGA_WIDTH + x) * 2 +
|
||||
1
|
||||
);
|
||||
}
|
||||
|
||||
export function kmod_graphics_vga_clear() {
|
||||
kmod_graphics_vga_lineBuf = [];
|
||||
|
||||
for (let y = 0; y < CFG_KMOD_GRAPHICS_VGA_HEIGHT; y++) {
|
||||
for (let x = 0; x < CFG_KMOD_GRAPHICS_VGA_WIDTH; x++) {
|
||||
kmod_graphics_vga_writeChar(x, y, " ", 0x07);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function kmod_graphics_vga_writeChar(
|
||||
x: number,
|
||||
y: number,
|
||||
char: string,
|
||||
color: number
|
||||
) {
|
||||
const charAddr = kmod_graphics_vga_getCharAddr(x, y);
|
||||
const colorAddr = kmod_graphics_vga_getColorAddr(x, y);
|
||||
|
||||
$addrw(charAddr, charc(char));
|
||||
$addrw(colorAddr, color);
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
import {
|
||||
kmod_graphics_vga_clear,
|
||||
kmod_graphics_vga_writeChar,
|
||||
} from "./modules/graphics/graphics.kmod";
|
||||
|
||||
export function kpanic(reason?: string) {
|
||||
kmod_graphics_vga_clear();
|
||||
|
||||
const l1 = "KERNEL PANIC!";
|
||||
let l2 = "Unknown: Kernel crashed.";
|
||||
|
||||
if (reason) l2 = "Reason: " + reason;
|
||||
|
||||
for (let i = 0; i < l1.length; i++) {
|
||||
kmod_graphics_vga_writeChar(i, 0, l1[i]!, 0x0c);
|
||||
}
|
||||
|
||||
for (let i = 0; i < l2.length; i++) {
|
||||
kmod_graphics_vga_writeChar(i, 1, l2[i]!, 0x0c);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import { charc } from "../../libts/byte";
|
||||
import { kdriver_etc_serial_transmit } from "../../../kernel/drivers/etc/serial";
|
||||
|
||||
export const Logger = {
|
||||
log(message: string) {
|
||||
for (let i = 0; i < message.length; i++) {
|
||||
kdriver_etc_serial_transmit(charc(message[i]!));
|
||||
}
|
||||
|
||||
kdriver_etc_serial_transmit(charc("\n"));
|
||||
},
|
||||
};
|
||||
@@ -1,30 +0,0 @@
|
||||
export const Path = {
|
||||
dirname(p: string): string {
|
||||
const parts = p.split("/");
|
||||
|
||||
parts.pop();
|
||||
|
||||
if (parts.length <= 1) return "/";
|
||||
|
||||
return parts.join("/");
|
||||
},
|
||||
filename(p: string): string {
|
||||
const parts = p.split("/");
|
||||
|
||||
const n = parts.pop();
|
||||
|
||||
if (!n) return "";
|
||||
return n;
|
||||
},
|
||||
join(p1: string, p2: string): string {
|
||||
if (p1.endsWith("/")) {
|
||||
p1 = p1.slice(0, -1);
|
||||
}
|
||||
|
||||
if (p2.startsWith("/")) {
|
||||
p2 = p2.slice(1);
|
||||
}
|
||||
|
||||
return p1 + "/" + p2;
|
||||
},
|
||||
};
|
||||
@@ -1,3 +0,0 @@
|
||||
export function charc(char: string): number {
|
||||
return char.charCodeAt(0);
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
export function dwordin(dw: number): number {
|
||||
return $dwordin(dw);
|
||||
}
|
||||
|
||||
export function dwordout(dw: number, value: number): void {
|
||||
$dwordout(dw, value);
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
export function portin(port: number): number {
|
||||
return $ptin(port);
|
||||
}
|
||||
|
||||
export function portout(port: number, value: number): void {
|
||||
$ptout(port, value);
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
export function padStart(
|
||||
str: string,
|
||||
targetLength: number,
|
||||
padString: string
|
||||
): string {
|
||||
while (str.length < targetLength) {
|
||||
str = padString + str;
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
import { kmod_bios_time_getTimestamp } from "../../kernel/modules/bios/time";
|
||||
|
||||
export function getDate(): Date {
|
||||
return new Date(kmod_bios_time_getTimestamp());
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
import { KDriverPCIClass } from "../../../types/dev/pci/class";
|
||||
|
||||
const sysPCIClassNames = {
|
||||
[KDriverPCIClass.MassStorageController]: "Mass Storage Controller",
|
||||
[KDriverPCIClass.NetworkController]: "Network Controller",
|
||||
[KDriverPCIClass.DisplayController]: "Display Controller",
|
||||
[KDriverPCIClass.MultimediaController]: "Multimedia Controller",
|
||||
[KDriverPCIClass.MemoryController]: "Memory Controller",
|
||||
[KDriverPCIClass.BridgeDevice]: "Bridge Device",
|
||||
[KDriverPCIClass.SimpleCommunicationsController]:
|
||||
"Simple Communications Controller",
|
||||
[KDriverPCIClass.BaseSystemPeripheral]: "Base System Peripheral",
|
||||
[KDriverPCIClass.InputDevice]: "Input Device",
|
||||
[KDriverPCIClass.DockingStation]: "Docking Station",
|
||||
[KDriverPCIClass.Processors]: "Processors",
|
||||
[KDriverPCIClass.SerialBusController]: "Serial Bus Controller",
|
||||
[KDriverPCIClass.WirelessController]: "Wireless Controller",
|
||||
[KDriverPCIClass.IntelligentIOController]: "Intelligent I/O Controller",
|
||||
[KDriverPCIClass.SatelliteCommunicationController]:
|
||||
"Satellite Communication Controller",
|
||||
[KDriverPCIClass.EncryptionDecryptionController]:
|
||||
"Encryption/Decryption Controller",
|
||||
[KDriverPCIClass.DataAcquisitionAndSignalProcessingController]:
|
||||
"Data Acquisition and Signal Processing Controller",
|
||||
};
|
||||
|
||||
export function sys_pci_class_name(classId: KDriverPCIClass): string {
|
||||
return sysPCIClassNames[classId] || "Unknown";
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
console.log("TS-DOS Program Started");
|
||||
5
src/os/src/types/c/bindings.d.ts
vendored
5
src/os/src/types/c/bindings.d.ts
vendored
@@ -1,5 +0,0 @@
|
||||
declare function $addrw(address: number, value: number): void;
|
||||
declare function $ptin(port: number): number;
|
||||
declare function $ptout(port: number, value: number): void;
|
||||
declare function $dwordin(port: number): number;
|
||||
declare function $dwordout(port: number, value: number): void;
|
||||
@@ -1,19 +0,0 @@
|
||||
export enum KDriverPCIClass {
|
||||
MassStorageController = 1,
|
||||
NetworkController = 2,
|
||||
DisplayController = 3,
|
||||
MultimediaController = 4,
|
||||
MemoryController = 5,
|
||||
BridgeDevice = 6,
|
||||
SimpleCommunicationsController = 7,
|
||||
BaseSystemPeripheral = 8,
|
||||
InputDevice = 9,
|
||||
DockingStation = 10,
|
||||
Processors = 11,
|
||||
SerialBusController = 12,
|
||||
WirelessController = 13,
|
||||
IntelligentIOController = 14,
|
||||
SatelliteCommunicationController = 15,
|
||||
EncryptionDecryptionController = 16,
|
||||
DataAcquisitionAndSignalProcessingController = 17,
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
export type KFilesystemMountdata = KFilesystemMount[];
|
||||
|
||||
export type KFilesystemMount = {
|
||||
mountpoint: string;
|
||||
driver: KFilesystemDriver;
|
||||
};
|
||||
|
||||
export type KFilesystemDriver = {
|
||||
id: string;
|
||||
init: () => void;
|
||||
listDir(path: string): KFilesystemEntity[] | null;
|
||||
readFile(path: string): unknown;
|
||||
writeFile(path: string, content: unknown): void;
|
||||
createFile(path: string, content: unknown): void;
|
||||
mkdir(path: string): void;
|
||||
stat(path: string): KFilesystemStat | null;
|
||||
};
|
||||
|
||||
export type KFilesystemMemdata = KFilesystemEntity[];
|
||||
|
||||
export type KFilesystemEntity = {
|
||||
name: string;
|
||||
path: string;
|
||||
size: number;
|
||||
contents: unknown;
|
||||
type: "file" | "folder";
|
||||
};
|
||||
|
||||
export type KFilesystemStat = {
|
||||
name: string;
|
||||
type: "file" | "folder";
|
||||
size: number;
|
||||
};
|
||||
Reference in New Issue
Block a user