Skip to content

Commit

Permalink
Rename to Ubik and start keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Ratakor committed Oct 1, 2023
1 parent c40641d commit d19fa9e
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 7 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Système 9
an operating system made with zig using Ubik as its kernel
# Ubik
a kernel made with zig

# TODO
- use flanterm
Expand All @@ -9,7 +9,7 @@ an operating system made with zig using Ubik as its kernel

### clone

git clone https://github.com/ratakor/os --recursive
git clone https://github.com/ratakor/ubik --recursive

### build
Make sure to have `xorriso` and run
Expand Down
2 changes: 1 addition & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub fn build(b: *std.Build) void {
b.installArtifact(kernel);

const image_name = std.mem.concat(b.allocator, u8, &.{
"système-9-", @tagName(kernel.target.cpu_arch.?), ".iso"
"ubik-", @tagName(kernel.target.cpu_arch.?), ".iso"
}) catch unreachable;
const image_step = b.step("image", "Build the image");
const image_cmd = buildImage(b, image_name);
Expand Down
2 changes: 1 addition & 1 deletion build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.{
.name = "système-9",
.name = "ubik",
.version = "0.1.0",
.dependencies = .{
.limine = .{
Expand Down
2 changes: 1 addition & 1 deletion kernel/Terminal.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1531,7 +1531,7 @@ fn putChar(self: *Context, c: u8) void {
return;
},
control_code.bs => {
self.setCursorPos(x - 1, y);
self.setCursorPos(x -| 1, y);
return;
},
control_code.cr => {
Expand Down
94 changes: 94 additions & 0 deletions kernel/keyboard.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// TODO: ugly and doesn't work well

const ps2 = @import("ps2.zig");

const Key = enum {
bad,
escape,
@"1",
@"2",
@"3",
@"4",
@"5",
@"6",
@"7",
@"8",
@"9",
@"0",
@"-",
@"=",
backspace,
tab,
q,
w,
e,
r,
t,
y,
u,
i,
o,
p,
@"[",
@"]",
enter,
left_ctrl,
a,
s,
d,
f,
g,
h,
j,
k,
l,
@";",
@"'",
@"`",
left_shift,
@"\\",
z,
x,
c,
v,
@".",
@"/",
right_shift,
keypad_star,
left_alt,
space,
caps_lock,
F1,
F2,
F3,
F4,
F5,
F6,
F7,
F8,
F9,
F10,
nums_lock,
scroll_lock,
keypad_7,
keypad_8,
keypad_9,
keypad_minus,
keypad_4,
keypad_5,
keypad_6,
keypad_plus,
keypad_1,
keypad_2,
keypad_3,
keypad_0,
keypad_dot,
F11,
F12,
};

pub fn readKey() Key {
const key = ps2.read();
if (key > @intFromEnum(Key.F12)) return .bad;
return @enumFromInt(key);
}
17 changes: 17 additions & 0 deletions kernel/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const pmm = @import("pmm.zig");
const vmm = @import("vmm.zig");
const mem = @import("mem.zig");
const time = @import("time.zig");
const keyboard = @import("keyboard.zig");

pub const std_options = struct {
pub const logFn = debug.log;
Expand Down Expand Up @@ -102,6 +103,22 @@ fn main() !void {
defer pmm.free(buf);
tty.print("allocated a buffer of size {} and address = {*}\n", .{ buf.len, buf.ptr });

while (true) {
const key = keyboard.readKey();
switch (key) {
.bad => {},
.escape => break,
.backspace => {
tty.write(&[1]u8{std.ascii.control_code.bs});
tty.clearFromCursorToLineEnd();
},
.tab => tty.write(&[1]u8{std.ascii.control_code.ht}),
.enter => tty.write(&[1]u8{std.ascii.control_code.lf}),
.space => tty.write(" "),
else => tty.write(@tagName(key)),
}
}

asm volatile ("sti");
@breakpoint();
}
2 changes: 1 addition & 1 deletion limine.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
TIMEOUT=0

:Système 9 ${ARCH}
:Ubik ${ARCH}
PROTOCOL=limine
KERNEL_PATH=boot:///kernel.elf
KASLR=no

0 comments on commit d19fa9e

Please sign in to comment.