source: libcaca/trunk/kernel/drivers/processor.c @ 4157

Last change on this file since 4157 was 4157, checked in by Jean-Yves Lamoureux, 10 years ago
  • Fill CPU id correctly, you dumb fuck.
File size: 1.2 KB
Line 
1/*
2 *  processor.c
3 * 
4 *
5 *  Created by Jean-Yves Lamoureux on 12/19/09.
6 *  Copyright 2009 Frob. All rights reserved.
7 *
8 */
9#include "kernel.h"
10#include "klibc.h"
11#include "processor.h"
12
13
14int processor_get_info(struct processor_info *processor_info)
15{
16    processor_info->id = 0;
17   
18    /* Vendor String */
19    int code = CPUID_GETVENDORSTRING;
20    unsigned int where[5];
21    char *s;
22    asm volatile ("cpuid":"=a" (*where), "=b"(*(where + 1)),
23                  "=c"(*(where + 2)), "=d"(*(where + 3)):"0"(code));
24
25    s = (char *)where;
26
27    unsigned int a = 0;
28    unsigned int b = where[1];
29    unsigned int d = where[3];
30    unsigned int c = where[2];
31
32    where[0] = b;
33    where[1] = d;
34    where[2] = c;
35    where[3] = 0;
36
37    memcpy(processor_info->vendor, where, 13);
38
39    /* Features */
40    code = CPUID_GETFEATURES;
41    asm volatile ("cpuid":"=a" (a), "=d"(d):"0"(code):"ecx", "ebx");
42    processor_info->features = a;
43
44    return 0;
45}
46
47void processor_print_info(struct processor_info *processor_info)
48{
49    printf("CPU%d\n", processor_info->id);
50    printf("Vendor ID : %s\n", processor_info->vendor);
51    printf("Features : 0x%x\n", processor_info->features);
52}
Note: See TracBrowser for help on using the repository browser.