aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--arch/i686/include/sys/cpuid.h35
-rw-r--r--meson.build8
-rw-r--r--src/kernel.c12
3 files changed, 54 insertions, 1 deletions
diff --git a/arch/i686/include/sys/cpuid.h b/arch/i686/include/sys/cpuid.h
new file mode 100644
index 0000000..f2ffe37
--- /dev/null
+++ b/arch/i686/include/sys/cpuid.h
@@ -0,0 +1,35 @@
+#pragma once
+
+#include <cpuid.h>
+
+struct CPUVersion {
+ unsigned int stepping : 4;
+ unsigned int model : 4;
+ unsigned int family : 4;
+ unsigned int type : 2;
+ unsigned int __unused_1 : 2;
+ unsigned int model_ex : 4;
+ unsigned int family_ex : 8;
+ unsigned int __unused_2 : 4;
+} __attribute__((packed, aligned(__alignof__(unsigned int))));
+_Static_assert(sizeof(struct CPUVersion) == sizeof(unsigned int));
+
+unsigned int
+family(const struct CPUVersion v)
+{
+ if (v.family == 0x0f) return v.family + v.family_ex;
+ else
+ return v.family;
+}
+
+unsigned int
+model(const struct CPUVersion v)
+{
+ switch (v.family) {
+ case 0x06:
+ case 0x0f:
+ return ((unsigned int)v.model_ex << 4) | v.model;
+ default:
+ return v.model;
+ }
+}
diff --git a/meson.build b/meson.build
index 8279212..9896e66 100644
--- a/meson.build
+++ b/meson.build
@@ -1,5 +1,11 @@
-project('glitch kernel', 'c', version: '0.1.0', default_options: ['c_std=gnu11', 'warning_level=2'])
+project('glitch kernel', 'c', version: '0.0.0', default_options: ['c_std=gnu11', 'warning_level=2'])
python3 = import('python').find_installation('python3')
+cc = meson.get_compiler('c')
+
+conf = configuration_data()
+conf.set_quoted('VERSION', run_command(['git', 'describe', '--long'], capture: true, check: true).stdout().strip())
+conf.set_quoted('CC', cc.get_id() + ' ' + cc.version())
+configure_file(output: 'conf.h', configuration: conf)
subdir('arch/i686')
subdir('devices')
diff --git a/src/kernel.c b/src/kernel.c
index ffa8814..b9a6bdf 100644
--- a/src/kernel.c
+++ b/src/kernel.c
@@ -8,6 +8,9 @@
#include "devices/uart_16550.h"
#include "devices/vga.h"
+#include <conf.h>
+#include <sys/cpuid.h>
+
void kmain() {
pic_init();
@@ -16,6 +19,15 @@ void kmain() {
if (uart_init(COM1) != 0) printf("UART self-test failed.\r\n");
+ printf("glitch [version " VERSION "] [" CC "]\n");
+
+ char vendor[13] = {'\0'};
+ unsigned int eax;
+ __get_cpuid(0, &eax, (unsigned int *)vendor, (unsigned int *)(vendor + 8), (unsigned int *)(vendor + 4));
+ struct CPUVersion v;
+ __get_cpuid(1, (unsigned int *)&v, &eax, &eax, &eax);
+ printf("CPU: %s family %u model %u stepping %u\n", vendor, family(v), model(v), v.stepping);
+
printf("hello %s world\n", "kernel");
printf("we are number %d\n", 1);
printf("a negative %d as hex %x\n", -1, -1);