-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentry.c_old
184 lines (146 loc) · 3.22 KB
/
entry.c_old
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#include "cpuid.h"
#include "utils.h"
// vendorid[s] = (res[e] >> (8*i)) & 0xff;
unsigned char *videomem = (unsigned char*) (0x00b8000 |0x20);
void write(const char *string)
{
while (*string != 0)
{
*videomem++=*string++;
*videomem++=6;
}
}
/*
int strlen(const char *str)
{
const char *s;
for (s = str; *s; ++s) ;
return (s - str);
}
*/
char *itoa(int val, int base)
{
static char buf[32] = {0};
int i=30;
for(; val && i ; i--, val /= base)
buf[i] ="0123456789abcdef"[val % base];
return &buf[i+1];
}
void cpuid(unsigned long idx, unsigned long reg[])
{
__asm__ volatile ("cpuid"
: "=a" (reg[0]),
"=b" (reg[1]),
"=c" (reg[2]),
"=d" (reg[3])
: "a" (idx));
}
const char *getbrandindex()
{
// 3 cpuid's * 4 registers * 4 bytes
static char brandindex[3*4*4];
unsigned long reg[4];
int r, s;
for (s = -1, r = 2; r <= 4; r++)
{
cpuid(0x80000000+r, reg);
for(int i = 0 ; i <= 0xf; i++)
brandindex[++s]= ((char*)reg)[i];
}
return brandindex;
}
const char *getvendorname()
{
// 1 cpuid * 3 registers * 4 bytes
static char vendorid[3*4];
unsigned long reg[4];
cpuid(0, reg);
unsigned int tmpreg = {reg[2]};
reg[2] = reg[3];
reg[3] = tmpreg;
int i ,s;
for( s = -1 , i=1 ; i <= 0xf; i++)
if (((char*)reg)[i] != 0 )
vendorid[++s]= ((char*)reg)[i];
return vendorid;
}
void getinfo()
{
unsigned long reg[4];
cpuid(1, reg);
int stepping = reg[0] & 0x000f;
int model = reg[0] & 0x00f0;
int family = ((( 1 << 12)-1) & (reg[0] >> (9 - 1)));
int cputype = ((( 1 << 14)-1) & (reg[0] >> (13 - 1)));
write(",stepping=");
write(itoa(stepping, 16));
write(",model=");
write(itoa(model, 16));
write(",family=");
write(itoa(family, 16));
write(",cputype=");
write(itoa(cputype, 16));
if (cputype == 0)
write("0");
for (int i = 0 ; i <= 31; i++){
write(check_bit(reg[3], i) ? CPU_featureS1Str[i] : "");
write(" ");
//write(check_bit(reg[2], i) ? CPU_featureS0Str[i]: "");
}
}
bool cpu_feature(unsigned long cpuidmode , unsigned char feature)
{
unsigned long reg[4];
switch (cpuidmode) {
case CPUID_0:
cpuid(CPUID_0, reg);
return check_bit(reg[3], feature);
case CPUID_EXT_0:
cpuid(CPUID_EXT_0, reg);
return check_bit(reg[3], feature);
default:
return false;
}
}
void kernel_noproceed(char *msg)
{
write("yolt:");
write(msg);
write("yolt: Cannot proceed. System halted.");
while(1);
}
void kernel_main()
{
// unsigned char *vm = (unsigned char*) (0xb8000);
__asm__ volatile ("nop\n\t");
//write("yolt: kernel PE enable.");
//write(getvendorname());
//getinfo();
// write(",brandindex=");
// write(getbrandindex());
//getbrandindex();
if (cpu_feature(CPUID_EXT_0, CPU_flag_lm))
longmode_entry();
//((unsigned long long*)0xb8000)= 0x1f6c1f6c1f651f48;
/*
const char* string = "HELLO";
while (*string != 0)
{
*vm++=*string++;
*vm++=8;
}
*/
/*
__asm__ ( ".code64\n\t"
" movl $0x1f6c1f6c1f651f48, 0xb8000\n\t"
);
*/
/*
__asm__ (
"mov $0xfe, %eax\n\t"
"out %eax, $0x64\n\t"
);
*/
//main64();
while(1);
}