Skip to content

Commit 77326a4

Browse files
committed
Fix
1 parent 8f5910c commit 77326a4

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

scripts/image.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
#
1010

1111
image() {
12-
local arch=$(uname -m)
12+
local arch
13+
arch="$(uname -m)"
1314
local kernel_arch="$3"
1415
local kernel_file="$1"
1516
local image_file="$2"
@@ -20,7 +21,7 @@ image() {
2021
# Create a folder whose structure mirrors that of the desired disk image
2122
mkdir -p "${boot_files_dir}"
2223
sudo mkdir -p "${boot_files_dir}/boot/grub"
23-
sudo cp -r ./src/arch/${kernel_arch}/grub.cfg "${boot_files_dir}/boot/grub/"
24+
sudo cp -r ./src/arch/"${kernel_arch}"/grub.cfg "${boot_files_dir}/boot/grub/"
2425
sudo cp -r "${kernel_file}" "${boot_files_dir}/boot/kiwirtos.bin"
2526
# Create a zeroed out disk image file
2627
dd if=/dev/zero of="${image_file}" bs=512 count=32768
@@ -82,7 +83,7 @@ image() {
8283
}
8384

8485
# Main script logic
85-
set -e # Exit on error
86+
set -euo pipefail # Exit on error, print the error message
8687
if [ $# -eq 3 ]; then
8788
image "$1" "$2" "$3"
8889
else

src/arch/x86_64/idt.zig

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@
33
const std = @import("std");
44
const arch = @import("arch.zig");
55

6-
// IDT entry types
7-
pub const IDT_TASK_GATE = 0x5;
8-
pub const IDT_INTERRUPT_GATE_16 = 0x6;
9-
pub const IDT_TRAP_GATE_16 = 0x7;
10-
pub const IDT_INTERRUPT_GATE_32 = 0xE;
11-
pub const IDT_TRAP_GATE_32 = 0xF;
12-
136
extern const isr_stub_table: []void;
147

158
// Number of entries in the IDT
@@ -54,6 +47,8 @@ pub const DPL = enum(u2) {
5447

5548
// The type of gate the IDT entry represents
5649
pub const GateType = enum(u4) {
50+
/// Task gate (system call)
51+
GATE_TASK = 0b0101,
5752
/// Interrupt gate (system call)
5853
GATE_INTERRUPT = 0b1110,
5954
/// Trap gate (exception)
@@ -108,7 +103,8 @@ pub const Idt = struct {
108103
/// Set the IDT entries
109104
pub fn setEntries(self: *Idt) void {
110105
for (0..IDT_ENTRIES) |vector| {
111-
self.setDescriptor(vector, @intFromPtr(isr_stub_table[vector]), IdtAttributes{
106+
const addr = @intFromPtr(isr_stub_table[vector]);
107+
self.setDescriptor(vector, addr, IdtAttributes{
112108
.present = 1,
113109
.dpl = DPL.KERNEL,
114110
.gate_type = GateType.GATE_INTERRUPT,

src/drivers/vga.zig

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,4 +325,25 @@ pub const VgaTextDriver = struct {
325325
pub fn println(self: *VgaTextDriver, comptime format: []const u8, args: anytype) void {
326326
self.writer().print(format ++ "\n", args) catch unreachable;
327327
}
328+
329+
/// Put a character to the VGA buffer with race condition protection
330+
pub fn setCharSafe(self: *VgaTextDriver, ch: u8) void {
331+
arch.cli(); // Disable interrupts
332+
self.setChar(ch);
333+
arch.sti(); // Re-enable interrupts
334+
}
335+
336+
/// Update cursor position with race condition protection
337+
pub fn updateCursorSafe(self: *const VgaTextDriver) void {
338+
arch.cli(); // Disable interrupts
339+
self.updateCursor();
340+
arch.sti(); // Re-enable interrupts
341+
}
342+
343+
/// Scroll the VGA buffer with race condition protection
344+
pub fn scrollSafe(self: *VgaTextDriver) void {
345+
arch.cli(); // Disable interrupts
346+
self.scroll();
347+
arch.sti(); // Re-enable interrupts
348+
}
328349
};

0 commit comments

Comments
 (0)