Skip to content

Commit cf5b24f

Browse files
committed
Auto merge of #2360 - devnexen:haiku_cpuid_info, r=Amanieu
haiku adding cpuid_info data.
2 parents 72fdbd8 + 3b10fd5 commit cf5b24f

File tree

2 files changed

+91
-1
lines changed

2 files changed

+91
-1
lines changed

libc-test/build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3315,6 +3315,9 @@ fn test_haiku(target: &str) {
33153315
}
33163316

33173317
cfg.skip_struct(move |ty| {
3318+
if ty.starts_with("__c_anonymous_") {
3319+
return true;
3320+
}
33183321
match ty {
33193322
// FIXME: actually a union
33203323
"sigval" => true,

src/unix/haiku/native.rs

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,93 @@ s! {
259259
pub api_version: i32,
260260
pub abi: i32
261261
}
262+
263+
pub struct __c_anonymous_eax_0 {
264+
pub max_eax: u32,
265+
pub vendor_id: [::c_char; 12],
266+
}
267+
268+
pub struct __c_anonymous_eax_1 {
269+
pub stepping: u32,
270+
pub model: u32,
271+
pub family: u32,
272+
pub tpe: u32,
273+
__reserved_0: u32,
274+
pub extended_model: u32,
275+
pub extended_family: u32,
276+
__reserved_1: u32,
277+
pub brand_index: u32,
278+
pub clflush: u32,
279+
pub logical_cpus: u32,
280+
pub apic_id: u32,
281+
pub features: u32,
282+
pub extended_features: u32,
283+
}
284+
285+
pub struct __c_anonymous_eax_2 {
286+
pub call_num: u8,
287+
pub cache_descriptors: [u8; 15],
288+
}
289+
290+
pub struct __c_anonymous_eax_3 {
291+
__reserved: [u32; 2],
292+
pub serial_number_high: u32,
293+
pub serial_number_low: u32,
294+
}
295+
296+
pub struct __c_anonymous_regs {
297+
pub eax: u32,
298+
pub ebx: u32,
299+
pub edx: u32,
300+
pub ecx: u32,
301+
}
302+
}
303+
304+
s_no_extra_traits! {
305+
#[cfg(libc_union)]
306+
pub union cpuid_info {
307+
pub eax_0: __c_anonymous_eax_0,
308+
pub eax_1: __c_anonymous_eax_1,
309+
pub eax_2: __c_anonymous_eax_2,
310+
pub eax_3: __c_anonymous_eax_3,
311+
pub as_chars: [::c_char; 16],
312+
pub regs: __c_anonymous_regs,
313+
}
314+
}
315+
316+
cfg_if! {
317+
if #[cfg(feature = "extra_traits")] {
318+
#[cfg(libc_union)]
319+
impl PartialEq for cpuid_info {
320+
fn eq(&self, other: &cpuid_info) -> bool {
321+
unsafe {
322+
self.eax_0 == other.eax_0
323+
|| self.eax_1 == other.eax_1
324+
|| self.eax_2 == other.eax_2
325+
|| self.eax_3 == other.eax_3
326+
|| self.as_chars == other.as_chars
327+
|| self.regs == other.regs
328+
}
329+
}
330+
}
331+
#[cfg(libc_union)]
332+
impl Eq for cpuid_info {}
333+
#[cfg(libc_union)]
334+
impl ::fmt::Debug for cpuid_info {
335+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
336+
unsafe {
337+
f.debug_struct("cpuid_info")
338+
.field("eax_0", &self.eax_0)
339+
.field("eax_1", &self.eax_1)
340+
.field("eax_2", &self.eax_2)
341+
.field("eax_3", &self.eax_3)
342+
.field("as_chars", &self.as_chars)
343+
.field("regs", &self.regs)
344+
.finish()
345+
}
346+
}
347+
}
348+
}
262349
}
263350

264351
// kernel/OS.h
@@ -825,7 +912,7 @@ extern "C" {
825912
pub fn debugger(message: *const ::c_char);
826913
pub fn disable_debugger(state: ::c_int) -> ::c_int;
827914

828-
// TODO: cpuid_info struct and the get_cpuid() function
915+
pub fn get_cpuid(info: *mut cpuid_info, eaxRegister: u32, cpuNum: u32) -> status_t;
829916

830917
pub fn get_system_info(info: *mut system_info) -> status_t;
831918
pub fn get_cpu_info(firstCPU: u32, cpuCount: u32, info: *mut cpu_info) -> status_t;

0 commit comments

Comments
 (0)