diff --git a/Drivers/include/syscalls.h b/Drivers/include/syscalls.h index d477af33..72a89c7d 100644 --- a/Drivers/include/syscalls.h +++ b/Drivers/include/syscalls.h @@ -624,6 +624,14 @@ typedef struct FramebufferScreenInfo */ #define FBIOGET_SCREEN_INFO 0xf0 +struct kutsname +{ + char sysname[65]; + char release[65]; + char version[65]; + char machine[65]; +}; + /** * @brief List of syscalls * @@ -1601,6 +1609,22 @@ typedef enum * - #EACCES if permission is denied */ SYS_RENAME, + /** + * @brief Get unix name information + * + * @code + * int uname(struct kutsname *buf); + * @endcode + * + * @details Retrieves information about the operating system. + * + * @param buf Pointer to `kutsname` structure to store information + * + * @return + * - #EOK on success + * - #EFAULT if `buf` is outside accessible address space + */ + SYS_UNAME, /** * @brief Max number of syscalls @@ -1782,4 +1806,7 @@ typedef enum /** @copydoc SYS_RENAME */ #define call_rename(oldpath, newpath) syscall2(SYS_RENAME, (scarg)oldpath, (scarg)newpath) +/** @copydoc SYS_UNAME */ +#define call_uname(buf) syscall1(SYS_UNAME, (scarg)buf) + #endif // !__FENNIX_API_SYSCALLS_LIST_H__ diff --git a/Kernel/.vscode/preinclude.h b/Kernel/.vscode/preinclude.h index 5f59e590..b2f2758c 100644 --- a/Kernel/.vscode/preinclude.h +++ b/Kernel/.vscode/preinclude.h @@ -9,6 +9,6 @@ #define __kernel__ 1 #define KERNEL_NAME "Fennix" #define KERNEL_ARCH "amd64" -#define KERNEL_VERSION "1.0" +#define KERNEL_VERSION "1.0.0" #define GIT_COMMIT "0000000000000000000000000000000000000000" #define GIT_COMMIT_SHORT "0000000" diff --git a/Kernel/include/interface/syscalls.h b/Kernel/include/interface/syscalls.h index d477af33..72a89c7d 100644 --- a/Kernel/include/interface/syscalls.h +++ b/Kernel/include/interface/syscalls.h @@ -624,6 +624,14 @@ typedef struct FramebufferScreenInfo */ #define FBIOGET_SCREEN_INFO 0xf0 +struct kutsname +{ + char sysname[65]; + char release[65]; + char version[65]; + char machine[65]; +}; + /** * @brief List of syscalls * @@ -1601,6 +1609,22 @@ typedef enum * - #EACCES if permission is denied */ SYS_RENAME, + /** + * @brief Get unix name information + * + * @code + * int uname(struct kutsname *buf); + * @endcode + * + * @details Retrieves information about the operating system. + * + * @param buf Pointer to `kutsname` structure to store information + * + * @return + * - #EOK on success + * - #EFAULT if `buf` is outside accessible address space + */ + SYS_UNAME, /** * @brief Max number of syscalls @@ -1782,4 +1806,7 @@ typedef enum /** @copydoc SYS_RENAME */ #define call_rename(oldpath, newpath) syscall2(SYS_RENAME, (scarg)oldpath, (scarg)newpath) +/** @copydoc SYS_UNAME */ +#define call_uname(buf) syscall1(SYS_UNAME, (scarg)buf) + #endif // !__FENNIX_API_SYSCALLS_LIST_H__ diff --git a/Kernel/syscalls/native.cpp b/Kernel/syscalls/native.cpp index bea35162..b7ab94c7 100644 --- a/Kernel/syscalls/native.cpp +++ b/Kernel/syscalls/native.cpp @@ -212,6 +212,54 @@ static int sys_rmdir(SysFrm *Frame, const char *path) { return -ENOSYS; } static int sys_unlink(SysFrm *Frame, const char *pathname) { return -ENOSYS; } static int sys_rename(SysFrm *Frame, const char *oldpath, const char *newpath) { return -ENOSYS; } +static int sys_uname(SysFrm *Frame, struct kutsname *buf) +{ + PCB *pcb = thisProcess; + Memory::VirtualMemoryArea *vma = pcb->vma; + + struct kutsname *pBuf = vma->UserCheckAndGetAddress(buf, sizeof(struct kutsname)); + if (pBuf == nullptr) + return -EFAULT; + + strncpy(pBuf->sysname, KERNEL_NAME, sizeof(pBuf->sysname)); + + char release[sizeof(pBuf->release)]; + sprintf(release, "%s", KERNEL_VERSION); + strncpy(pBuf->release, release, sizeof(pBuf->release)); + + char version[sizeof(pBuf->version)]; + + bool isDebug = false; +#ifdef DEBUG + isDebug = true; +#endif + + sprintf(version, "FNX-v%s-%s %s %s %s %s", + KERNEL_VERSION, GIT_COMMIT_SHORT, + isDebug ? "DEBUG" : "RELEASE", + __DATE__, __TIME__, __VERSION__); + strncpy(pBuf->version, version, sizeof(pBuf->version)); + +#if defined(__amd64__) + const char *osarch = "x86_64"; +#elif defined(__i386__) + const char *osarch = "i386"; +#elif defined(__aarch64__) + const char *osarch = "aarch64"; +#elif defined(__arm__) + const char *osarch = "arm"; +#else + const char *osarch = "unknown"; +#endif + + strncpy(pBuf->machine, osarch, sizeof(pBuf->machine)); + + debug("%s %s %s %s", pBuf->sysname, pBuf->release, + pBuf->version, pBuf->machine); + + return 0; +} + static SyscallData scTbl[SYS_MAX] = {}; __constructor void __init_native_syscalls(void) { @@ -281,6 +329,7 @@ __constructor void __init_native_syscalls(void) scTbl[SYS_RMDIR] = {"SYS_RMDIR", (void *)sys_rmdir}; scTbl[SYS_UNLINK] = {"SYS_UNLINK", (void *)sys_unlink}; scTbl[SYS_RENAME] = {"SYS_RENAME", (void *)sys_rename}; + scTbl[SYS_UNAME] = {"SYS_UNAME", (void *)sys_uname}; } uintptr_t HandleNativeSyscalls(SysFrm *Frame) diff --git a/Userspace/libc/include/fennix/syscalls.h b/Userspace/libc/include/fennix/syscalls.h index d477af33..72a89c7d 100644 --- a/Userspace/libc/include/fennix/syscalls.h +++ b/Userspace/libc/include/fennix/syscalls.h @@ -624,6 +624,14 @@ typedef struct FramebufferScreenInfo */ #define FBIOGET_SCREEN_INFO 0xf0 +struct kutsname +{ + char sysname[65]; + char release[65]; + char version[65]; + char machine[65]; +}; + /** * @brief List of syscalls * @@ -1601,6 +1609,22 @@ typedef enum * - #EACCES if permission is denied */ SYS_RENAME, + /** + * @brief Get unix name information + * + * @code + * int uname(struct kutsname *buf); + * @endcode + * + * @details Retrieves information about the operating system. + * + * @param buf Pointer to `kutsname` structure to store information + * + * @return + * - #EOK on success + * - #EFAULT if `buf` is outside accessible address space + */ + SYS_UNAME, /** * @brief Max number of syscalls @@ -1782,4 +1806,7 @@ typedef enum /** @copydoc SYS_RENAME */ #define call_rename(oldpath, newpath) syscall2(SYS_RENAME, (scarg)oldpath, (scarg)newpath) +/** @copydoc SYS_UNAME */ +#define call_uname(buf) syscall1(SYS_UNAME, (scarg)buf) + #endif // !__FENNIX_API_SYSCALLS_LIST_H__ diff --git a/config.mk b/config.mk index 38f252d5..1702ba87 100644 --- a/config.mk +++ b/config.mk @@ -17,7 +17,7 @@ OSARCH = amd64 BOARD_TYPE := raspi4 # Kernel version. -KERNEL_VERSION = dev +KERNEL_VERSION = 0.0.1 # Which bootloader to use. # Available bootloaders: