summaryrefslogtreecommitdiffhomepage
path: root/dev
diff options
context:
space:
mode:
Diffstat (limited to 'dev')
-rw-r--r--dev/user/Macros.h34
-rw-r--r--dev/user/src/SystemCalls.cc48
2 files changed, 80 insertions, 2 deletions
diff --git a/dev/user/Macros.h b/dev/user/Macros.h
index 98beeb0d..556833ea 100644
--- a/dev/user/Macros.h
+++ b/dev/user/Macros.h
@@ -90,4 +90,36 @@ IMPORT_C void _rtl_assert(Bool expr, const Char* origin);
#define ARRAY_SIZE(X) \
(((sizeof(X) / sizeof(*(X))) / \
(static_cast<SizeT>(!(sizeof(X) % sizeof(*(X)))))))
-#endif \ No newline at end of file
+#endif
+
+#ifndef KIB
+#define KIB(X) (UInt64)((X) / 1024)
+#endif
+
+#ifndef kib_cast
+#define kib_cast(X) (UInt64)((X)*1024)
+#endif
+
+#ifndef MIB
+#define MIB(X) (UInt64)((UInt64)KIB(X) / 1024)
+#endif
+
+#ifndef mib_cast
+#define mib_cast(X) (UInt64)((UInt64)kib_cast(X) * 1024)
+#endif
+
+#ifndef GIB
+#define GIB(X) (UInt64)((UInt64)MIB(X) / 1024)
+#endif
+
+#ifndef gib_cast
+#define gib_cast(X) (UInt64)((UInt64)mib_cast(X) * 1024)
+#endif
+
+#ifndef TIB
+#define TIB(X) (UInt64)((UInt64)GIB(X) / 1024)
+#endif
+
+#ifndef tib_cast
+#define tib_cast(X) ((UInt64)gib_cast(X) * 1024)
+#endif
diff --git a/dev/user/src/SystemCalls.cc b/dev/user/src/SystemCalls.cc
index 2dd27dc0..7ad0fe6f 100644
--- a/dev/user/src/SystemCalls.cc
+++ b/dev/user/src/SystemCalls.cc
@@ -6,9 +6,14 @@
#include <user/SystemCalls.h>
-/// @file libsci.cc
+/// @file SystemCalls.cc
/// @brief Source file for the memory functions of the libsci.
+IMPORT_C VoidPtr sci_syscall_arg_1(SizeT id);
+IMPORT_C VoidPtr sci_syscall_arg_2(SizeT id, VoidPtr arg1);
+IMPORT_C VoidPtr sci_syscall_arg_3(SizeT id, VoidPtr arg1, VoidPtr arg3);
+IMPORT_C VoidPtr sci_syscall_arg_4(SizeT id, VoidPtr arg1, VoidPtr arg3, VoidPtr arg4);
+
/// @brief Copy memory region.
IMPORT_C VoidPtr MmCopyMemory(_Input VoidPtr dest, _Input VoidPtr src, _Input SizeT len)
{
@@ -27,6 +32,21 @@ IMPORT_C VoidPtr MmCopyMemory(_Input VoidPtr dest, _Input VoidPtr src, _Input Si
return dest;
}
+IMPORT_C SInt64 MmStrLen(const Char* in)
+{
+ if (!in)
+ return 0;
+
+ SizeT len{0};
+
+ do
+ {
+ ++len;
+ } while (in[len] != '\0');
+
+ return len;
+}
+
/// @brief Fill memory region **dest** with **value**.
IMPORT_C VoidPtr MmFillMemory(_Input VoidPtr dest, _Input SizeT len, _Input UInt8 value)
{
@@ -43,3 +63,29 @@ IMPORT_C VoidPtr MmFillMemory(_Input VoidPtr dest, _Input SizeT len, _Input UInt
return dest;
}
+
+IMPORT_C Ref IoOpenFile(_Input const Char* path, _Input const Char* drv_letter)
+{
+ return sci_syscall_arg_3(1, reinterpret_cast<VoidPtr>(const_cast<Char*>(path)),
+ reinterpret_cast<VoidPtr>(const_cast<Char*>(drv_letter)));
+}
+
+IMPORT_C Void IoCloseFile(_Input Ref desc)
+{
+ sci_syscall_arg_2(2, desc);
+}
+
+IMPORT_C UInt64 IoSeekFile(_Input Ref desc, _Input UInt64 off)
+{
+ auto ret = (UInt64*)sci_syscall_arg_3(3, reinterpret_cast<VoidPtr>(desc),
+ reinterpret_cast<VoidPtr>(&off));
+
+ MUST_PASS((*ret) != ~0UL);
+ return *ret;
+}
+
+IMPORT_C UInt64 IoTellFile(_Input Ref desc)
+{
+ auto ret = (UInt64*)sci_syscall_arg_2(4, reinterpret_cast<VoidPtr>(desc));
+ return *ret;
+}