Subversion Repositories HelenOS

Rev

Rev 2131 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright (c) 2007 Michal Kebrt
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  *
  9.  * - Redistributions of source code must retain the above copyright
  10.  *   notice, this list of conditions and the following disclaimer.
  11.  * - Redistributions in binary form must reproduce the above copyright
  12.  *   notice, this list of conditions and the following disclaimer in the
  13.  *   documentation and/or other materials provided with the distribution.
  14.  * - The name of the author may not be used to endorse or promote products
  15.  *   derived from this software without specific prior written permission.
  16.  *
  17.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  18.  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  20.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  21.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26.  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27.  */
  28.  
  29. /** @addtogroup arm32
  30.  * @{
  31.  */
  32. /** @file
  33.  */
  34.  
  35. #include <arch/cpu.h>
  36. #include <cpu.h>
  37. #include <arch.h>
  38. #include <print.h> 
  39.  
  40.  
  41. /** Implementators (vendor) names */
  42. static char * imp_data[] = {
  43.     "?",
  44.     "ARM Ltd",                           /* 0x41 */
  45.     "",                                  /* 0x42 */
  46.     "",                                  /* 0x43 */
  47.     "Digital Equipment Corporation",     /* 0x44 */
  48.     "", "", "", "", "", "", "", "", "", "", "",                     /* 0x4f */
  49.     "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", /* 0x5f */
  50.     "", "", "", "", "", "", "", "", "",  /* 0x68 */
  51.     "Intel Corporation"                  /* 0x69 */
  52. };
  53.  
  54. /** Length of imp_data array */
  55. static int imp_data_length = sizeof(imp_data)/sizeof(char *);
  56.  
  57. /** Architecture names */
  58. static char * arch_data[] = {
  59.     "?",       /* 0x0 */
  60.     "4",       /* 0x1 */
  61.     "4T",      /* 0x2 */
  62.     "5",       /* 0x3 */
  63.     "5T",      /* 0x4 */
  64.     "5TE",     /* 0x5 */
  65.     "5TEJ",    /* 0x6 */
  66.     "6"        /* 0x7 */
  67. };
  68.  
  69. /** Length of arch_data array */
  70. static int arch_data_length = sizeof(arch_data)/sizeof(char *);
  71.  
  72.  
  73.  
  74. void cpu_arch_init(void)
  75. {
  76.     /* TODO */
  77. }
  78.  
  79. /**
  80.  * Retrieves processor identification from CP15 register 0.
  81.  *
  82.  * @param cpu   structure for storing identification
  83.  */
  84. static void arch_cpu_identify(cpu_arch_t * cpu)
  85. {
  86.     uint32_t ident;
  87.     asm volatile (
  88.         "mrc p15, 0, %0, c0, c0, 0  \n"
  89.         : "=r" (ident)
  90.     );
  91.  
  92.     cpu->imp_num = ident >> 24;
  93.     cpu->variant_num = (ident << 8) >> 28;
  94.     cpu->arch_num = (ident << 12) >> 28;
  95.     cpu->prim_part_num = (ident << 16) >> 20;
  96.     cpu->rev_num = (ident << 28) >> 28;
  97. }
  98.  
  99.  
  100. void cpu_identify(void)
  101. {
  102.     arch_cpu_identify(&CPU->arch);
  103. }
  104.  
  105.  
  106. void cpu_print_report(cpu_t *m)
  107. {
  108.     char * vendor = imp_data[0];
  109.     char * architecture = arch_data[0];
  110.     cpu_arch_t * cpu_arch = &m->arch;
  111.  
  112.     if ( (cpu_arch->imp_num) > 0 && (cpu_arch->imp_num < (imp_data_length + 0x40)) ) {
  113.         vendor = imp_data[cpu_arch->imp_num - 0x40];
  114.     }
  115.  
  116.     if ( (cpu_arch->arch_num) > 0 && (cpu_arch->arch_num < arch_data_length) ) {
  117.         architecture = arch_data[cpu_arch->arch_num];
  118.     }
  119.  
  120.     printf("vendor: %s, architecture: ARM %s, part number: %x, variant: %x, revision: %x",
  121.         vendor, architecture, cpu_arch->prim_part_num, cpu_arch->variant_num, cpu_arch->rev_num);
  122.  
  123. }
  124.  
  125. /** @}
  126.  */
  127.