diff --git a/Makefile b/Makefile
index 6984e4b4..9f764043 100644
--- a/Makefile
+++ b/Makefile
@@ -40,6 +40,8 @@ ISOFILE:=builds/$(DEBNAME).iso
INITRDDIR:=initrd
INITRD=sortix/sortix.initrd
+MFLAGS:=$(MFLAGS) VERSION=$(VERSION)
+
all: $(INITRD)
suball:
diff --git a/libmaxsi/Makefile b/libmaxsi/Makefile
index 16dce0ee..c99cfee7 100644
--- a/libmaxsi/Makefile
+++ b/libmaxsi/Makefile
@@ -41,6 +41,7 @@ process.o \
thread.o \
io.o \
terminal.o \
+kernelinfo.o \
init.o \
signal.o \
$(CPU)/signal.o \
diff --git a/libmaxsi/include/sys/kernelinfo.h b/libmaxsi/include/sys/kernelinfo.h
new file mode 100644
index 00000000..2a780cc2
--- /dev/null
+++ b/libmaxsi/include/sys/kernelinfo.h
@@ -0,0 +1,40 @@
+/*******************************************************************************
+
+ COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2012.
+
+ This file is part of LibMaxsi.
+
+ LibMaxsi is free software: you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the Free
+ Software Foundation, either version 3 of the License, or (at your option)
+ any later version.
+
+ LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with LibMaxsi. If not, see .
+
+ sys/kernelinfo.h
+ Queries information about the kernel.
+
+*******************************************************************************/
+
+#ifndef _SYS_KERNELINFO_H
+#define _SYS_KERNELINFO_H 1
+
+#include
+
+__BEGIN_DECLS
+
+@include(size_t.h)
+@include(ssize_t.h)
+
+ssize_t kernelinfo(const char* req, char* resp, size_t resplen);
+
+__END_DECLS
+
+#endif
+
diff --git a/libmaxsi/kernelinfo.cpp b/libmaxsi/kernelinfo.cpp
new file mode 100644
index 00000000..163dc1bd
--- /dev/null
+++ b/libmaxsi/kernelinfo.cpp
@@ -0,0 +1,39 @@
+/*******************************************************************************
+
+ COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2012.
+
+ This file is part of LibMaxsi.
+
+ LibMaxsi is free software: you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the Free
+ Software Foundation, either version 3 of the License, or (at your option)
+ any later version.
+
+ LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with LibMaxsi. If not, see .
+
+ kernelinfo.cpp
+ Queries information about the kernel.
+
+*******************************************************************************/
+
+#include
+#include
+#include
+
+namespace Maxsi {
+
+DEFN_SYSCALL3(ssize_t, SysKernelInfo, SYSCALL_KERNELINFO, const char*, char*, size_t);
+
+extern "C" ssize_t kernelinfo(const char* req, char* resp, size_t resplen)
+{
+ return SysKernelInfo(req, resp, resplen);
+}
+
+} // namespace Maxsi
+
diff --git a/sortix/Makefile b/sortix/Makefile
index 28250c4c..00af442c 100644
--- a/sortix/Makefile
+++ b/sortix/Makefile
@@ -65,6 +65,9 @@ ifeq ($(CALLTRACE),1)
else
DEFINES:=$(DEFINES) -DENABLE_CALLTRACE=0
endif
+ifdef VERSION
+ DEFINES:=$(DEFINES) -DVERSIONSTR=\"$(VERSION)\"
+endif
INCLUDES=-I../libmaxsi/preproc -I.. -I.
CPPFLAGS=$(INCLUDES) $(DEFINES)
@@ -118,6 +121,7 @@ descriptors.o \
device.o \
refcount.o \
vga.o \
+kernelinfo.o \
elf.o \
process.o \
initrd.o \
diff --git a/sortix/kernel.cpp b/sortix/kernel.cpp
index 8272ad5f..f7a3adf3 100644
--- a/sortix/kernel.cpp
+++ b/sortix/kernel.cpp
@@ -29,6 +29,7 @@
#include
#include "log.h"
#include "panic.h"
+#include "kernelinfo.h"
#include "x86-family/gdt.h"
#include "time.h"
#include "keyboard.h"
@@ -256,6 +257,9 @@ namespace Sortix
// Initialize the scheduler.
Scheduler::Init();
+ // Initialize the kernel information query syscall.
+ Info::Init();
+
// Set up the initial ram disk.
InitRD::Init(initrd, initrdsize);
diff --git a/sortix/kernelinfo.cpp b/sortix/kernelinfo.cpp
new file mode 100644
index 00000000..858bcff6
--- /dev/null
+++ b/sortix/kernelinfo.cpp
@@ -0,0 +1,70 @@
+/*******************************************************************************
+
+ COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2012.
+
+ This file is part of Sortix.
+
+ Sortix is free software: you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation, either version 3 of the License, or (at your option) any later
+ version.
+
+ Sortix is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ details.
+
+ You should have received a copy of the GNU General Public License along with
+ Sortix. If not, see .
+
+ kernelinfo.cpp
+ Lets user-space query information about the kernel.
+
+*******************************************************************************/
+
+#include "platform.h"
+#include
+#include
+#include "syscall.h"
+#include "kernelinfo.h"
+
+#ifndef VERSIONSTR
+#define VERSIONSTR "unknown"
+#endif
+
+using namespace Maxsi;
+
+namespace Sortix {
+namespace Info {
+
+const char* KernelInfo(const char* req)
+{
+ if ( String::Compare(req, "name") == 0 ) { return "Sortix"; }
+ if ( String::Compare(req, "version") == 0 ) { return VERSIONSTR; }
+ if ( String::Compare(req, "builddate") == 0 ) { return __DATE__; }
+ if ( String::Compare(req, "buildtime") == 0 ) { return __TIME__; }
+ return NULL;
+}
+
+ssize_t SysKernelInfo(const char* req, char* resp, size_t resplen)
+{
+ const char* str = KernelInfo(req);
+ if ( !str ) { Error::Set(EINVAL); return -1; }
+ size_t stringlen = String::Length(str);
+ if ( resplen < stringlen + 1 )
+ {
+ Error::Set(ERANGE);
+ return (ssize_t) stringlen;
+ }
+ String::Copy(resp, str);
+ return 0;
+}
+
+void Init()
+{
+ Syscall::Register(SYSCALL_KERNELINFO, (void*) SysKernelInfo);
+}
+
+} // namespace Info
+} // namespace Sortix
+
diff --git a/sortix/kernelinfo.h b/sortix/kernelinfo.h
new file mode 100644
index 00000000..78f1741c
--- /dev/null
+++ b/sortix/kernelinfo.h
@@ -0,0 +1,38 @@
+/*******************************************************************************
+
+ COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2012.
+
+ This file is part of Sortix.
+
+ Sortix is free software: you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation, either version 3 of the License, or (at your option) any later
+ version.
+
+ Sortix is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ details.
+
+ You should have received a copy of the GNU General Public License along with
+ Sortix. If not, see .
+
+ kernelinfo.h
+ Lets user-space query information about the kernel.
+
+*******************************************************************************/
+
+#ifndef SORTIX_KERNELINFO_H
+#define SORTIX_KERNELINFO_H
+
+namespace Sortix {
+namespace Info {
+
+const char* KernelInfo(const char* req);
+void Init();
+
+} // namespace Version
+} // namespace Sortix
+
+#endif
+
diff --git a/sortix/syscallnum.h b/sortix/syscallnum.h
index c0472716..ccd1c4ba 100644
--- a/sortix/syscallnum.h
+++ b/sortix/syscallnum.h
@@ -72,7 +72,8 @@
#define SYSCALL_FSTAT 45
#define SYSCALL_FCNTL 46
#define SYSCALL_ACCESS 47
-#define SYSCALL_MAX_NUM 48 /* index of highest constant + 1 */
+#define SYSCALL_KERNELINFO 48
+#define SYSCALL_MAX_NUM 49 /* index of highest constant + 1 */
#endif