-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: TalonFloof <105325988+TalonFloof@users.noreply.github.com>
- Loading branch information
1 parent
c0882cb
commit 8594d76
Showing
9 changed files
with
111 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const limine = @import("limine"); | ||
const std = @import("std"); | ||
const hal = @import("../hal.zig"); | ||
const physmem = @import("root").physmem; | ||
|
||
export var smp_request: limine.SmpRequest = .{ .flags = 0 }; | ||
pub var hartData: usize = 0; | ||
|
||
pub fn startSMP() void { | ||
if (smp_request.response) |response| { | ||
hal.hiList = @as([*]*hal.HartInfo, @ptrCast(@alignCast(physmem.AllocateC(response.cpu_count * @sizeOf(usize)))))[0..response.cpu_count]; | ||
hal.hiList.?[0] = hal.arch.getHart(); | ||
var hartCount: i32 = 1; | ||
std.log.info("{} Hart System (MultiHart Kernel)", .{hal.hiList.?.len}); | ||
for (response.cpus()) |hart| { | ||
if (hart.lapic_id != response.bsp_lapic_id) { | ||
var hi: *hal.HartInfo = @ptrCast(@alignCast(physmem.AllocateC(@sizeOf(hal.HartInfo)))); | ||
hal.hiList.?[@as(usize, @intCast(hartCount))] = hi; | ||
hi.hartID = @intCast(hartCount); | ||
hi.archData.apicID = hart.lapic_id; | ||
hartData = @intFromPtr(hi); | ||
@as(*align(1) u64, @ptrFromInt(@intFromPtr(hart) + @offsetOf(limine.SmpInfo, "goto_address"))).* = @intFromPtr(&hal.archData._hartstart); | ||
var cycles: usize = 0; | ||
while (hartData != 0) { | ||
cycles += 1; | ||
if (cycles >= 50000000) { | ||
std.log.err("Hart #{} took too long (potential triple fault on hart!)", .{hartCount}); | ||
hal.HALOops("X86_64 HAL Initialization Failure"); | ||
} | ||
std.atomic.spinLoopHint(); | ||
} | ||
hartCount += 1; | ||
} | ||
} | ||
} else { | ||
std.log.info("1 Hart System (MultiHart Kernel)", .{}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters