Compare commits
2 Commits
0d10e698da
...
627150b170
| Author | SHA1 | Date |
|---|---|---|
|
|
627150b170 | |
|
|
062917d75b |
|
|
@ -0,0 +1 @@
|
|||
usingnamespace @import("../x86/x86.zig");
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
const std = @import("std");
|
||||
const cpuid_c = @cImport(@cInclude("cpuid.h"));
|
||||
|
||||
const cpuid_ret = struct {
|
||||
eax: u32,
|
||||
ebx: u32,
|
||||
ecx: u32,
|
||||
edx: u32,
|
||||
};
|
||||
|
||||
// static inline int cpuid_string(int code, uint32_t where[4]) {
|
||||
// asm volatile("cpuid":"=a"(*where),"=b"(*(where+1)),
|
||||
// "=c"(*(where+2)),"=d"(*(where+3)):"a"(code));
|
||||
// return (int)where[0];
|
||||
// }
|
||||
|
||||
fn getcpuid(leaf: u32) [4]u32 {
|
||||
// cpuid_c.__cpuid(leaf, &ret.eax, &ret.ebx, &ret.ecx, &ret.edx);
|
||||
var eax: u32 = undefined;
|
||||
var ebx: u32 = undefined;
|
||||
var ecx: u32 = undefined;
|
||||
var edx: u32 = undefined;
|
||||
asm volatile("cpuid"
|
||||
: [eax] "={eax}" (eax),
|
||||
[ebx] "={ebx}" (ebx),
|
||||
[ecx] "={ecx}" (ecx),
|
||||
[edx] "={edx}" (edx),
|
||||
: [leaf] "{eax}" (leaf)
|
||||
:
|
||||
);
|
||||
std.log.info("cpuid {x}: {x} {x} {x} {x}", .{leaf, eax, ebx, ecx, edx});
|
||||
return .{eax, ebx, ecx, edx};
|
||||
}
|
||||
|
||||
var vendor: [12]u8 = undefined;
|
||||
pub fn getVendor() [12]u8 {
|
||||
const v = getcpuid(0);
|
||||
@memcpy(@ptrCast([*]u8, &vendor[0]), @ptrCast([*]const u8, &v[1]), 4);
|
||||
@memcpy(@ptrCast([*]u8, &vendor[4]), @ptrCast([*]const u8, &v[3]), 4);
|
||||
@memcpy(@ptrCast([*]u8, &vendor[8]), @ptrCast([*]const u8, &v[2]), 4);
|
||||
std.log.notice("CPU vendor: {}", .{std.mem.span(&vendor)});
|
||||
return vendor;
|
||||
}
|
||||
|
||||
var name: [48]u8 = undefined;
|
||||
pub fn getName() []u8 {
|
||||
var i: u32 = 0x80000002;
|
||||
while(i <= 0x80000004) : (i+=1) {
|
||||
const v = getcpuid(i);
|
||||
@memcpy(@ptrCast([*]u8, &name[(i-0x80000002)*16]), @ptrCast([*]const u8, &v), 16);
|
||||
}
|
||||
std.log.notice("CPU model name: {}", .{std.mem.span(&name)});
|
||||
return std.mem.span(&name);
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
pub const cpuid = @import("cpuid.zig");
|
||||
|
|
@ -5,20 +5,21 @@ const c_idt = @cImport(@cInclude("arch/x86_64/idt.h"));
|
|||
export const int_msg = "INTERRUPTED!\n";
|
||||
|
||||
comptime {
|
||||
@setEvalBranchQuota(2560000);
|
||||
comptime var i = 0;
|
||||
var buf: [512]u8 = undefined;
|
||||
inline while (i < 256) : (i += 1) {
|
||||
const code = std.fmt.bufPrint(buf[0..512],
|
||||
\\.global isr_wrapper{}
|
||||
\\.type isr_wrapper{}, @function
|
||||
\\isr_wrapper{}:
|
||||
\\ mov ${}, %rdi
|
||||
\\ call interrupt_handler
|
||||
\\ iretq
|
||||
, .{i,i,i,i}) catch unreachable;
|
||||
asm (code);
|
||||
}
|
||||
asm(
|
||||
\\.macro isr_wrapperX number
|
||||
\\ isr_wrapper\number:
|
||||
\\ mov $\number, %rdi
|
||||
\\ call interrupt_handler
|
||||
\\ iretq
|
||||
\\.endm
|
||||
\\
|
||||
\\.altmacro
|
||||
\\.set i,0
|
||||
\\.rept 256
|
||||
\\ isr_wrapperX %i
|
||||
\\ .set i,i+1
|
||||
\\.endr
|
||||
);
|
||||
}
|
||||
|
||||
export fn interrupt_handler(int_type: u64) void {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
const x86 = @import("src/arch/x86/x86.zig");
|
||||
usingnamespace @import("../x86/x86.zig");
|
||||
pub const paging = @import("paging.zig");
|
||||
pub const interrupt = @import("interrupt.zig");
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue