Browse Source

put something in cpuinfo

K. Lange 3 years ago
parent
commit
527661b03e
1 changed files with 34 additions and 1 deletions
  1. 34 1
      modules/procfs.c

+ 34 - 1
modules/procfs.c

@@ -219,8 +219,41 @@ static fs_node_t * procfs_procdir_create(process_t * process) {
 	return fnode;
 }
 
+#define cpuid(in,a,b,c,d) do { asm volatile ("cpuid" : "=a"(a),"=b"(b),"=c"(c),"=d"(d) : "a"(in)); } while(0)
+
 static uint32_t cpuinfo_func(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer) {
-	return 0;
+	char buf[1024];
+
+	unsigned long a, b, unused;;
+	cpuid(0,unused,b,unused,unused);
+
+	char * _manu = "Unknown";
+	int _model = 0, _family = 0;
+
+	if (b == 0x756e6547) {
+		cpuid(1, a, b, unused, unused);
+		_manu   = "Intel";
+		_model  = (a >> 4) & 0x0F;
+		_family = (a >> 8) & 0x0F;
+	} else if (b == 0x68747541) {
+		cpuid(1, a, unused, unused, unused);
+		_manu   = "AMD";
+		_model  = (a >> 4) & 0x0F;
+		_family = (a >> 8) & 0x0F;
+	}
+
+	sprintf(buf,
+		"Manufacturer: %s\n"
+		"Family: %d\n"
+		"Model: %d\n"
+		, _manu, _family, _model);
+
+	size_t _bsize = strlen(buf);
+	if (offset > _bsize) return 0;
+	if (size > _bsize - offset) size = _bsize - offset;
+
+	memcpy(buffer, buf + offset, size);
+	return size;
 }
 
 extern uintptr_t heap_end;