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