summaryrefslogtreecommitdiff
path: root/tools/win32build/cpucaps/cpucaps_main.c
blob: 1c52749a85177fffcdd3fa12e857eeaf5f5cc828 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include <stdio.h>

#include <windows.h>
#include "cpucaps_main.h"

#include "cpuid.h"

HINSTANCE g_hInstance;

HWND g_hwndParent;

#define CPUID_FAILED "Unknown"

/*
 * if val is true, str is the "Y" string, otherwise the "N" string
 */
static int _set_bool_str(int val, char* str)
{
	if (val) {
		str[0] = 'Y';
  	} else {
		str[0] = 'N';
  	}
  	str[1] = '\0';

	return 0;
}

void __declspec(dllexport) hasSSE3(HWND hwndParent, int string_size, 
                                   char *variables, stack_t **stacktop,
                                   extra_parameters *extra)
{
  cpu_caps_t *cpu;
  char has_sse3[2];

  //g_hwndParent=hwndParent;

  EXDLL_INIT();


  // note if you want parameters from the stack, pop them off in order.
  // i.e. if you are called via exdll::myFunction file.dat poop.dat
  // calling popstring() the first time would give you file.dat,
  // and the second time would give you poop.dat. 
  // you should empty the stack of your parameters, and ONLY your
  // parameters.

  // do your stuff here
  cpu = malloc(sizeof(*cpu));
  if (cpu == NULL) {
	  fprintf(stderr, "malloc call failed\n");
  	  _set_bool_str(0, has_sse3);
	  goto push_vars;
  }
  cpuid_get_caps(cpu);
  _set_bool_str(cpu->has_sse3, has_sse3);


push_vars:
  pushstring(has_sse3);
  
  return ;
}


void __declspec(dllexport) hasSSE2(HWND hwndParent, int string_size, 
                                   char *variables, stack_t **stacktop,
                                   extra_parameters *extra)
{
  cpu_caps_t *cpu;
  char has_sse2[2];

  //g_hwndParent=hwndParent;

  EXDLL_INIT();


  // note if you want parameters from the stack, pop them off in order.
  // i.e. if you are called via exdll::myFunction file.dat poop.dat
  // calling popstring() the first time would give you file.dat,
  // and the second time would give you poop.dat. 
  // you should empty the stack of your parameters, and ONLY your
  // parameters.

  // do your stuff here
  cpu = malloc(sizeof(*cpu));
  if (cpu == NULL) {
	  fprintf(stderr, "malloc call failed\n");
  	  _set_bool_str(0, has_sse2);
	  goto push_vars;
  }
  cpuid_get_caps(cpu);
  _set_bool_str(cpu->has_sse2, has_sse2);


push_vars:
  pushstring(has_sse2);
  
  return ;
}



BOOL WINAPI DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
{
  g_hInstance=hInst;
	return TRUE;
}