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

Last change on this file since 4158 was 4158, checked in by Jean-Yves Lamoureux, 10 years ago
  • Fix indentation and add licensing and copyright headers to kernel
File size: 1.6 KB
Line 
1/*
2 *  libcaca       
3 *  libcaca       Colour ASCII-Art library
4 *  Copyright (c) 2006 Sam Hocevar <sam@hocevar.net>
5 *                2009 Jean-Yves Lamoureux <jylam@lnxscene.org>
6 *                All Rights Reserved
7 *
8 *  $Id: kernel.h 4154 2009-12-20 13:33:11Z jylam $
9 *
10 *  This library is free software. It comes without any warranty, to
11 *  the extent permitted by applicable law. You can redistribute it
12 *  and/or modify it under the terms of the Do What The Fuck You Want
13 *  To Public License, Version 2, as published by Sam Hocevar. See
14 *  http://sam.zoy.org/wtfpl/COPYING for more details.
15 */
16
17#include "kernel.h"
18#include "klibc.h"
19#include "processor.h"
20
21
22int processor_get_info(struct processor_info *processor_info)
23{
24    processor_info->id = 0;
25
26    /* Vendor String */
27    int code = CPUID_GETVENDORSTRING;
28    unsigned int where[5];
29    char *s;
30    asm volatile ("cpuid":"=a" (*where), "=b"(*(where + 1)),
31                  "=c"(*(where + 2)), "=d"(*(where + 3)):"0"(code));
32
33    s = (char *)where;
34
35    unsigned int a = 0;
36    unsigned int b = where[1];
37    unsigned int d = where[3];
38    unsigned int c = where[2];
39
40    where[0] = b;
41    where[1] = d;
42    where[2] = c;
43    where[3] = 0;
44
45    memcpy(processor_info->vendor, where, 13);
46
47    /* Features */
48    code = CPUID_GETFEATURES;
49    asm volatile ("cpuid":"=a" (a), "=d"(d):"0"(code):"ecx", "ebx");
50    processor_info->features = a;
51
52    return 0;
53}
54
55void processor_print_info(struct processor_info *processor_info)
56{
57    printf("CPU%d\n", processor_info->id);
58    printf("Vendor ID : %s\n", processor_info->vendor);
59    printf("Features : 0x%x\n", processor_info->features);
60}
Note: See TracBrowser for help on using the repository browser.