1 | /* $Id: kCpuCompare.c 3585 2007-09-03 01:18:26Z bird $ */
|
---|
2 | /** @file
|
---|
3 | * kCpu - kCpuCompare.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (c) 2007 knut st. osmundsen <bird-src-spam@anduin.net>
|
---|
8 | *
|
---|
9 | * This file is part of kStuff.
|
---|
10 | *
|
---|
11 | * kStuff is free software; you can redistribute it and/or
|
---|
12 | * modify it under the terms of the GNU Lesser General Public
|
---|
13 | * License as published by the Free Software Foundation; either
|
---|
14 | * version 2.1 of the License, or (at your option) any later version.
|
---|
15 | *
|
---|
16 | * kStuff is distributed in the hope that it will be useful,
|
---|
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
19 | * Lesser General Public License for more details.
|
---|
20 | *
|
---|
21 | * You should have received a copy of the GNU Lesser General Public
|
---|
22 | * License along with kStuff; if not, write to the Free Software
|
---|
23 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
---|
24 | *
|
---|
25 | */
|
---|
26 |
|
---|
27 | /*******************************************************************************
|
---|
28 | * Header Files *
|
---|
29 | *******************************************************************************/
|
---|
30 | #include <k/kCpu.h>
|
---|
31 | #include <k/kErrors.h>
|
---|
32 |
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * Compares arch+cpu some code was generated for with a arch+cpu for executing it
|
---|
36 | * to see if it'll work out fine or not.
|
---|
37 | *
|
---|
38 | * @returns 0 if the code is compatible with the cpu.
|
---|
39 | * @returns KCPU_ERR_ARCH_CPU_NOT_COMPATIBLE if the arch+cpu isn't compatible with the code.
|
---|
40 | *
|
---|
41 | * @param enmCodeArch The architecture the code was generated for.
|
---|
42 | * @param enmCodeCpu The cpu the code was generated for.
|
---|
43 | * @param enmArch The architecture to run it on.
|
---|
44 | * @param enmCpu The cpu to run it on.
|
---|
45 | */
|
---|
46 | KCPU_DECL(KBOOL) kCpuCompare(KCPUARCH enmCodeArch, KCPU enmCodeCpu, KCPUARCH enmArch, KCPU enmCpu)
|
---|
47 | {
|
---|
48 | /*
|
---|
49 | * Compare arch and cpu.
|
---|
50 | */
|
---|
51 | if (enmCodeArch != enmArch)
|
---|
52 | return KCPU_ERR_ARCH_CPU_NOT_COMPATIBLE;
|
---|
53 |
|
---|
54 | /* exact match is nice. */
|
---|
55 | if (enmCodeCpu == enmCpu)
|
---|
56 | return 0;
|
---|
57 |
|
---|
58 | switch (enmArch)
|
---|
59 | {
|
---|
60 | case K_ARCH_X86_16:
|
---|
61 | if (enmCpu < KCPU_FIRST_X86_16 || enmCpu > KCPU_LAST_X86_16)
|
---|
62 | return KERR_INVALID_PARAMETER;
|
---|
63 |
|
---|
64 | /* intel? */
|
---|
65 | if (enmCodeCpu <= KCPU_CORE2_16)
|
---|
66 | {
|
---|
67 | /* also intel? */
|
---|
68 | if (enmCpu <= KCPU_CORE2_16)
|
---|
69 | return enmCodeCpu <= enmCpu ? 0 : KCPU_ERR_ARCH_CPU_NOT_COMPATIBLE;
|
---|
70 | switch (enmCpu)
|
---|
71 | {
|
---|
72 | case KCPU_K6_16:
|
---|
73 | return enmCodeCpu <= KCPU_I586 ? 0 : KCPU_ERR_ARCH_CPU_NOT_COMPATIBLE;
|
---|
74 | case KCPU_K7_16:
|
---|
75 | case KCPU_K8_16:
|
---|
76 | default:
|
---|
77 | return enmCodeCpu <= KCPU_I686 ? 0 : KCPU_ERR_ARCH_CPU_NOT_COMPATIBLE;
|
---|
78 | }
|
---|
79 | }
|
---|
80 | /* amd */
|
---|
81 | return enmCpu >= KCPU_K6_16 && enmCpu <= KCPU_K8_16
|
---|
82 | ? 0 : KCPU_ERR_ARCH_CPU_NOT_COMPATIBLE;
|
---|
83 |
|
---|
84 | case K_ARCH_X86_32:
|
---|
85 | if (enmCpu < KCPU_FIRST_X86_32 || enmCpu > KCPU_LAST_X86_32)
|
---|
86 | return KERR_INVALID_PARAMETER;
|
---|
87 |
|
---|
88 | /* blend? */
|
---|
89 | if (enmCodeCpu == KCPU_X86_32_BLEND)
|
---|
90 | return 0;
|
---|
91 |
|
---|
92 | /* intel? */
|
---|
93 | if (enmCodeCpu <= KCPU_CORE2_32)
|
---|
94 | {
|
---|
95 | /* also intel? */
|
---|
96 | if (enmCpu <= KCPU_CORE2_32)
|
---|
97 | return enmCodeCpu <= enmCpu ? 0 : KCPU_ERR_ARCH_CPU_NOT_COMPATIBLE;
|
---|
98 | switch (enmCpu)
|
---|
99 | {
|
---|
100 | case KCPU_K6:
|
---|
101 | return enmCodeCpu <= KCPU_I586 ? 0 : KCPU_ERR_ARCH_CPU_NOT_COMPATIBLE;
|
---|
102 | case KCPU_K7:
|
---|
103 | case KCPU_K8_32:
|
---|
104 | default:
|
---|
105 | return enmCodeCpu <= KCPU_I686 ? 0 : KCPU_ERR_ARCH_CPU_NOT_COMPATIBLE;
|
---|
106 | }
|
---|
107 | }
|
---|
108 | /* amd */
|
---|
109 | return enmCpu >= KCPU_K6 && enmCpu <= KCPU_K8_32
|
---|
110 | ? 0 : KCPU_ERR_ARCH_CPU_NOT_COMPATIBLE;
|
---|
111 |
|
---|
112 | case K_ARCH_AMD64:
|
---|
113 | if (enmCpu < KCPU_FIRST_AMD64 || enmCpu > KCPU_LAST_AMD64)
|
---|
114 | return KERR_INVALID_PARAMETER;
|
---|
115 |
|
---|
116 | /* blend? */
|
---|
117 | if (enmCodeCpu == KCPU_AMD64_BLEND)
|
---|
118 | return 0;
|
---|
119 | /* this is simple for now. */
|
---|
120 | return KCPU_ERR_ARCH_CPU_NOT_COMPATIBLE;
|
---|
121 |
|
---|
122 | default:
|
---|
123 | break;
|
---|
124 | }
|
---|
125 | return KCPU_ERR_ARCH_CPU_NOT_COMPATIBLE;
|
---|
126 | }
|
---|
127 |
|
---|